three.js 1.1 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (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 = '101dev';
  101. var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  102. var CullFaceNone = 0;
  103. var CullFaceBack = 1;
  104. var CullFaceFront = 2;
  105. var CullFaceFrontBack = 3;
  106. var FrontFaceDirectionCW = 0;
  107. var FrontFaceDirectionCCW = 1;
  108. var BasicShadowMap = 0;
  109. var PCFShadowMap = 1;
  110. var PCFSoftShadowMap = 2;
  111. var FrontSide = 0;
  112. var BackSide = 1;
  113. var DoubleSide = 2;
  114. var FlatShading = 1;
  115. var SmoothShading = 2;
  116. var NoColors = 0;
  117. var FaceColors = 1;
  118. var VertexColors = 2;
  119. var NoBlending = 0;
  120. var NormalBlending = 1;
  121. var AdditiveBlending = 2;
  122. var SubtractiveBlending = 3;
  123. var MultiplyBlending = 4;
  124. var CustomBlending = 5;
  125. var AddEquation = 100;
  126. var SubtractEquation = 101;
  127. var ReverseSubtractEquation = 102;
  128. var MinEquation = 103;
  129. var MaxEquation = 104;
  130. var ZeroFactor = 200;
  131. var OneFactor = 201;
  132. var SrcColorFactor = 202;
  133. var OneMinusSrcColorFactor = 203;
  134. var SrcAlphaFactor = 204;
  135. var OneMinusSrcAlphaFactor = 205;
  136. var DstAlphaFactor = 206;
  137. var OneMinusDstAlphaFactor = 207;
  138. var DstColorFactor = 208;
  139. var OneMinusDstColorFactor = 209;
  140. var SrcAlphaSaturateFactor = 210;
  141. var NeverDepth = 0;
  142. var AlwaysDepth = 1;
  143. var LessDepth = 2;
  144. var LessEqualDepth = 3;
  145. var EqualDepth = 4;
  146. var GreaterEqualDepth = 5;
  147. var GreaterDepth = 6;
  148. var NotEqualDepth = 7;
  149. var MultiplyOperation = 0;
  150. var MixOperation = 1;
  151. var AddOperation = 2;
  152. var NoToneMapping = 0;
  153. var LinearToneMapping = 1;
  154. var ReinhardToneMapping = 2;
  155. var Uncharted2ToneMapping = 3;
  156. var CineonToneMapping = 4;
  157. var ACESFilmicToneMapping = 5;
  158. var UVMapping = 300;
  159. var CubeReflectionMapping = 301;
  160. var CubeRefractionMapping = 302;
  161. var EquirectangularReflectionMapping = 303;
  162. var EquirectangularRefractionMapping = 304;
  163. var SphericalReflectionMapping = 305;
  164. var CubeUVReflectionMapping = 306;
  165. var CubeUVRefractionMapping = 307;
  166. var RepeatWrapping = 1000;
  167. var ClampToEdgeWrapping = 1001;
  168. var MirroredRepeatWrapping = 1002;
  169. var NearestFilter = 1003;
  170. var NearestMipMapNearestFilter = 1004;
  171. var NearestMipMapLinearFilter = 1005;
  172. var LinearFilter = 1006;
  173. var LinearMipMapNearestFilter = 1007;
  174. var LinearMipMapLinearFilter = 1008;
  175. var UnsignedByteType = 1009;
  176. var ByteType = 1010;
  177. var ShortType = 1011;
  178. var UnsignedShortType = 1012;
  179. var IntType = 1013;
  180. var UnsignedIntType = 1014;
  181. var FloatType = 1015;
  182. var HalfFloatType = 1016;
  183. var UnsignedShort4444Type = 1017;
  184. var UnsignedShort5551Type = 1018;
  185. var UnsignedShort565Type = 1019;
  186. var UnsignedInt248Type = 1020;
  187. var AlphaFormat = 1021;
  188. var RGBFormat = 1022;
  189. var RGBAFormat = 1023;
  190. var LuminanceFormat = 1024;
  191. var LuminanceAlphaFormat = 1025;
  192. var RGBEFormat = RGBAFormat;
  193. var DepthFormat = 1026;
  194. var DepthStencilFormat = 1027;
  195. var RedFormat = 1028;
  196. var RGB_S3TC_DXT1_Format = 33776;
  197. var RGBA_S3TC_DXT1_Format = 33777;
  198. var RGBA_S3TC_DXT3_Format = 33778;
  199. var RGBA_S3TC_DXT5_Format = 33779;
  200. var RGB_PVRTC_4BPPV1_Format = 35840;
  201. var RGB_PVRTC_2BPPV1_Format = 35841;
  202. var RGBA_PVRTC_4BPPV1_Format = 35842;
  203. var RGBA_PVRTC_2BPPV1_Format = 35843;
  204. var RGB_ETC1_Format = 36196;
  205. var RGBA_ASTC_4x4_Format = 37808;
  206. var RGBA_ASTC_5x4_Format = 37809;
  207. var RGBA_ASTC_5x5_Format = 37810;
  208. var RGBA_ASTC_6x5_Format = 37811;
  209. var RGBA_ASTC_6x6_Format = 37812;
  210. var RGBA_ASTC_8x5_Format = 37813;
  211. var RGBA_ASTC_8x6_Format = 37814;
  212. var RGBA_ASTC_8x8_Format = 37815;
  213. var RGBA_ASTC_10x5_Format = 37816;
  214. var RGBA_ASTC_10x6_Format = 37817;
  215. var RGBA_ASTC_10x8_Format = 37818;
  216. var RGBA_ASTC_10x10_Format = 37819;
  217. var RGBA_ASTC_12x10_Format = 37820;
  218. var RGBA_ASTC_12x12_Format = 37821;
  219. var LoopOnce = 2200;
  220. var LoopRepeat = 2201;
  221. var LoopPingPong = 2202;
  222. var InterpolateDiscrete = 2300;
  223. var InterpolateLinear = 2301;
  224. var InterpolateSmooth = 2302;
  225. var ZeroCurvatureEnding = 2400;
  226. var ZeroSlopeEnding = 2401;
  227. var WrapAroundEnding = 2402;
  228. var TrianglesDrawMode = 0;
  229. var TriangleStripDrawMode = 1;
  230. var TriangleFanDrawMode = 2;
  231. var LinearEncoding = 3000;
  232. var sRGBEncoding = 3001;
  233. var GammaEncoding = 3007;
  234. var RGBEEncoding = 3002;
  235. var LogLuvEncoding = 3003;
  236. var RGBM7Encoding = 3004;
  237. var RGBM16Encoding = 3005;
  238. var RGBDEncoding = 3006;
  239. var BasicDepthPacking = 3200;
  240. var RGBADepthPacking = 3201;
  241. var TangentSpaceNormalMap = 0;
  242. var ObjectSpaceNormalMap = 1;
  243. /**
  244. * @author alteredq / http://alteredqualia.com/
  245. * @author mrdoob / http://mrdoob.com/
  246. */
  247. var _Math = {
  248. DEG2RAD: Math.PI / 180,
  249. RAD2DEG: 180 / Math.PI,
  250. generateUUID: ( function () {
  251. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  252. var lut = [];
  253. for ( var i = 0; i < 256; i ++ ) {
  254. lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
  255. }
  256. return function generateUUID() {
  257. var d0 = Math.random() * 0xffffffff | 0;
  258. var d1 = Math.random() * 0xffffffff | 0;
  259. var d2 = Math.random() * 0xffffffff | 0;
  260. var d3 = Math.random() * 0xffffffff | 0;
  261. var uuid = lut[ d0 & 0xff ] + lut[ d0 >> 8 & 0xff ] + lut[ d0 >> 16 & 0xff ] + lut[ d0 >> 24 & 0xff ] + '-' +
  262. lut[ d1 & 0xff ] + lut[ d1 >> 8 & 0xff ] + '-' + lut[ d1 >> 16 & 0x0f | 0x40 ] + lut[ d1 >> 24 & 0xff ] + '-' +
  263. lut[ d2 & 0x3f | 0x80 ] + lut[ d2 >> 8 & 0xff ] + '-' + lut[ d2 >> 16 & 0xff ] + lut[ d2 >> 24 & 0xff ] +
  264. lut[ d3 & 0xff ] + lut[ d3 >> 8 & 0xff ] + lut[ d3 >> 16 & 0xff ] + lut[ d3 >> 24 & 0xff ];
  265. // .toUpperCase() here flattens concatenated strings to save heap memory space.
  266. return uuid.toUpperCase();
  267. };
  268. } )(),
  269. clamp: function ( value, min, max ) {
  270. return Math.max( min, Math.min( max, value ) );
  271. },
  272. // compute euclidian modulo of m % n
  273. // https://en.wikipedia.org/wiki/Modulo_operation
  274. euclideanModulo: function ( n, m ) {
  275. return ( ( n % m ) + m ) % m;
  276. },
  277. // Linear mapping from range <a1, a2> to range <b1, b2>
  278. mapLinear: function ( x, a1, a2, b1, b2 ) {
  279. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  280. },
  281. // https://en.wikipedia.org/wiki/Linear_interpolation
  282. lerp: function ( x, y, t ) {
  283. return ( 1 - t ) * x + t * y;
  284. },
  285. // http://en.wikipedia.org/wiki/Smoothstep
  286. smoothstep: function ( x, min, max ) {
  287. if ( x <= min ) return 0;
  288. if ( x >= max ) return 1;
  289. x = ( x - min ) / ( max - min );
  290. return x * x * ( 3 - 2 * x );
  291. },
  292. smootherstep: function ( x, min, max ) {
  293. if ( x <= min ) return 0;
  294. if ( x >= max ) return 1;
  295. x = ( x - min ) / ( max - min );
  296. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  297. },
  298. // Random integer from <low, high> interval
  299. randInt: function ( low, high ) {
  300. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  301. },
  302. // Random float from <low, high> interval
  303. randFloat: function ( low, high ) {
  304. return low + Math.random() * ( high - low );
  305. },
  306. // Random float from <-range/2, range/2> interval
  307. randFloatSpread: function ( range ) {
  308. return range * ( 0.5 - Math.random() );
  309. },
  310. degToRad: function ( degrees ) {
  311. return degrees * _Math.DEG2RAD;
  312. },
  313. radToDeg: function ( radians ) {
  314. return radians * _Math.RAD2DEG;
  315. },
  316. isPowerOfTwo: function ( value ) {
  317. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  318. },
  319. ceilPowerOfTwo: function ( value ) {
  320. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  321. },
  322. floorPowerOfTwo: function ( value ) {
  323. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  324. }
  325. };
  326. /**
  327. * @author mrdoob / http://mrdoob.com/
  328. * @author philogb / http://blog.thejit.org/
  329. * @author egraether / http://egraether.com/
  330. * @author zz85 / http://www.lab4games.net/zz85/blog
  331. */
  332. function Vector2( x, y ) {
  333. this.x = x || 0;
  334. this.y = y || 0;
  335. }
  336. Object.defineProperties( Vector2.prototype, {
  337. "width": {
  338. get: function () {
  339. return this.x;
  340. },
  341. set: function ( value ) {
  342. this.x = value;
  343. }
  344. },
  345. "height": {
  346. get: function () {
  347. return this.y;
  348. },
  349. set: function ( value ) {
  350. this.y = value;
  351. }
  352. }
  353. } );
  354. Object.assign( Vector2.prototype, {
  355. isVector2: true,
  356. set: function ( x, y ) {
  357. this.x = x;
  358. this.y = y;
  359. return this;
  360. },
  361. setScalar: function ( scalar ) {
  362. this.x = scalar;
  363. this.y = scalar;
  364. return this;
  365. },
  366. setX: function ( x ) {
  367. this.x = x;
  368. return this;
  369. },
  370. setY: function ( y ) {
  371. this.y = y;
  372. return this;
  373. },
  374. setComponent: function ( index, value ) {
  375. switch ( index ) {
  376. case 0: this.x = value; break;
  377. case 1: this.y = value; break;
  378. default: throw new Error( 'index is out of range: ' + index );
  379. }
  380. return this;
  381. },
  382. getComponent: function ( index ) {
  383. switch ( index ) {
  384. case 0: return this.x;
  385. case 1: return this.y;
  386. default: throw new Error( 'index is out of range: ' + index );
  387. }
  388. },
  389. clone: function () {
  390. return new this.constructor( this.x, this.y );
  391. },
  392. copy: function ( v ) {
  393. this.x = v.x;
  394. this.y = v.y;
  395. return this;
  396. },
  397. add: function ( v, w ) {
  398. if ( w !== undefined ) {
  399. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  400. return this.addVectors( v, w );
  401. }
  402. this.x += v.x;
  403. this.y += v.y;
  404. return this;
  405. },
  406. addScalar: function ( s ) {
  407. this.x += s;
  408. this.y += s;
  409. return this;
  410. },
  411. addVectors: function ( a, b ) {
  412. this.x = a.x + b.x;
  413. this.y = a.y + b.y;
  414. return this;
  415. },
  416. addScaledVector: function ( v, s ) {
  417. this.x += v.x * s;
  418. this.y += v.y * s;
  419. return this;
  420. },
  421. sub: function ( v, w ) {
  422. if ( w !== undefined ) {
  423. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  424. return this.subVectors( v, w );
  425. }
  426. this.x -= v.x;
  427. this.y -= v.y;
  428. return this;
  429. },
  430. subScalar: function ( s ) {
  431. this.x -= s;
  432. this.y -= s;
  433. return this;
  434. },
  435. subVectors: function ( a, b ) {
  436. this.x = a.x - b.x;
  437. this.y = a.y - b.y;
  438. return this;
  439. },
  440. multiply: function ( v ) {
  441. this.x *= v.x;
  442. this.y *= v.y;
  443. return this;
  444. },
  445. multiplyScalar: function ( scalar ) {
  446. this.x *= scalar;
  447. this.y *= scalar;
  448. return this;
  449. },
  450. divide: function ( v ) {
  451. this.x /= v.x;
  452. this.y /= v.y;
  453. return this;
  454. },
  455. divideScalar: function ( scalar ) {
  456. return this.multiplyScalar( 1 / scalar );
  457. },
  458. applyMatrix3: function ( m ) {
  459. var x = this.x, y = this.y;
  460. var e = m.elements;
  461. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  462. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  463. return this;
  464. },
  465. min: function ( v ) {
  466. this.x = Math.min( this.x, v.x );
  467. this.y = Math.min( this.y, v.y );
  468. return this;
  469. },
  470. max: function ( v ) {
  471. this.x = Math.max( this.x, v.x );
  472. this.y = Math.max( this.y, v.y );
  473. return this;
  474. },
  475. clamp: function ( min, max ) {
  476. // assumes min < max, componentwise
  477. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  478. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  479. return this;
  480. },
  481. clampScalar: function () {
  482. var min = new Vector2();
  483. var max = new Vector2();
  484. return function clampScalar( minVal, maxVal ) {
  485. min.set( minVal, minVal );
  486. max.set( maxVal, maxVal );
  487. return this.clamp( min, max );
  488. };
  489. }(),
  490. clampLength: function ( min, max ) {
  491. var length = this.length();
  492. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  493. },
  494. floor: function () {
  495. this.x = Math.floor( this.x );
  496. this.y = Math.floor( this.y );
  497. return this;
  498. },
  499. ceil: function () {
  500. this.x = Math.ceil( this.x );
  501. this.y = Math.ceil( this.y );
  502. return this;
  503. },
  504. round: function () {
  505. this.x = Math.round( this.x );
  506. this.y = Math.round( this.y );
  507. return this;
  508. },
  509. roundToZero: function () {
  510. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  511. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  512. return this;
  513. },
  514. negate: function () {
  515. this.x = - this.x;
  516. this.y = - this.y;
  517. return this;
  518. },
  519. dot: function ( v ) {
  520. return this.x * v.x + this.y * v.y;
  521. },
  522. cross: function ( v ) {
  523. return this.x * v.y - this.y * v.x;
  524. },
  525. lengthSq: function () {
  526. return this.x * this.x + this.y * this.y;
  527. },
  528. length: function () {
  529. return Math.sqrt( this.x * this.x + this.y * this.y );
  530. },
  531. manhattanLength: function () {
  532. return Math.abs( this.x ) + Math.abs( this.y );
  533. },
  534. normalize: function () {
  535. return this.divideScalar( this.length() || 1 );
  536. },
  537. angle: function () {
  538. // computes the angle in radians with respect to the positive x-axis
  539. var angle = Math.atan2( this.y, this.x );
  540. if ( angle < 0 ) angle += 2 * Math.PI;
  541. return angle;
  542. },
  543. distanceTo: function ( v ) {
  544. return Math.sqrt( this.distanceToSquared( v ) );
  545. },
  546. distanceToSquared: function ( v ) {
  547. var dx = this.x - v.x, dy = this.y - v.y;
  548. return dx * dx + dy * dy;
  549. },
  550. manhattanDistanceTo: function ( v ) {
  551. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  552. },
  553. setLength: function ( length ) {
  554. return this.normalize().multiplyScalar( length );
  555. },
  556. lerp: function ( v, alpha ) {
  557. this.x += ( v.x - this.x ) * alpha;
  558. this.y += ( v.y - this.y ) * alpha;
  559. return this;
  560. },
  561. lerpVectors: function ( v1, v2, alpha ) {
  562. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  563. },
  564. equals: function ( v ) {
  565. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  566. },
  567. fromArray: function ( array, offset ) {
  568. if ( offset === undefined ) offset = 0;
  569. this.x = array[ offset ];
  570. this.y = array[ offset + 1 ];
  571. return this;
  572. },
  573. toArray: function ( array, offset ) {
  574. if ( array === undefined ) array = [];
  575. if ( offset === undefined ) offset = 0;
  576. array[ offset ] = this.x;
  577. array[ offset + 1 ] = this.y;
  578. return array;
  579. },
  580. fromBufferAttribute: function ( attribute, index, offset ) {
  581. if ( offset !== undefined ) {
  582. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  583. }
  584. this.x = attribute.getX( index );
  585. this.y = attribute.getY( index );
  586. return this;
  587. },
  588. rotateAround: function ( center, angle ) {
  589. var c = Math.cos( angle ), s = Math.sin( angle );
  590. var x = this.x - center.x;
  591. var y = this.y - center.y;
  592. this.x = x * c - y * s + center.x;
  593. this.y = x * s + y * c + center.y;
  594. return this;
  595. }
  596. } );
  597. /**
  598. * @author mrdoob / http://mrdoob.com/
  599. * @author supereggbert / http://www.paulbrunt.co.uk/
  600. * @author philogb / http://blog.thejit.org/
  601. * @author jordi_ros / http://plattsoft.com
  602. * @author D1plo1d / http://github.com/D1plo1d
  603. * @author alteredq / http://alteredqualia.com/
  604. * @author mikael emtinger / http://gomo.se/
  605. * @author timknip / http://www.floorplanner.com/
  606. * @author bhouston / http://clara.io
  607. * @author WestLangley / http://github.com/WestLangley
  608. */
  609. function Matrix4() {
  610. this.elements = [
  611. 1, 0, 0, 0,
  612. 0, 1, 0, 0,
  613. 0, 0, 1, 0,
  614. 0, 0, 0, 1
  615. ];
  616. if ( arguments.length > 0 ) {
  617. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  618. }
  619. }
  620. Object.assign( Matrix4.prototype, {
  621. isMatrix4: true,
  622. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  623. var te = this.elements;
  624. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  625. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  626. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  627. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  628. return this;
  629. },
  630. identity: function () {
  631. this.set(
  632. 1, 0, 0, 0,
  633. 0, 1, 0, 0,
  634. 0, 0, 1, 0,
  635. 0, 0, 0, 1
  636. );
  637. return this;
  638. },
  639. clone: function () {
  640. return new Matrix4().fromArray( this.elements );
  641. },
  642. copy: function ( m ) {
  643. var te = this.elements;
  644. var me = m.elements;
  645. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  646. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  647. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  648. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  649. return this;
  650. },
  651. copyPosition: function ( m ) {
  652. var te = this.elements, me = m.elements;
  653. te[ 12 ] = me[ 12 ];
  654. te[ 13 ] = me[ 13 ];
  655. te[ 14 ] = me[ 14 ];
  656. return this;
  657. },
  658. extractBasis: function ( xAxis, yAxis, zAxis ) {
  659. xAxis.setFromMatrixColumn( this, 0 );
  660. yAxis.setFromMatrixColumn( this, 1 );
  661. zAxis.setFromMatrixColumn( this, 2 );
  662. return this;
  663. },
  664. makeBasis: function ( xAxis, yAxis, zAxis ) {
  665. this.set(
  666. xAxis.x, yAxis.x, zAxis.x, 0,
  667. xAxis.y, yAxis.y, zAxis.y, 0,
  668. xAxis.z, yAxis.z, zAxis.z, 0,
  669. 0, 0, 0, 1
  670. );
  671. return this;
  672. },
  673. extractRotation: function () {
  674. var v1 = new Vector3();
  675. return function extractRotation( m ) {
  676. // this method does not support reflection matrices
  677. var te = this.elements;
  678. var me = m.elements;
  679. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  680. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  681. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  682. te[ 0 ] = me[ 0 ] * scaleX;
  683. te[ 1 ] = me[ 1 ] * scaleX;
  684. te[ 2 ] = me[ 2 ] * scaleX;
  685. te[ 3 ] = 0;
  686. te[ 4 ] = me[ 4 ] * scaleY;
  687. te[ 5 ] = me[ 5 ] * scaleY;
  688. te[ 6 ] = me[ 6 ] * scaleY;
  689. te[ 7 ] = 0;
  690. te[ 8 ] = me[ 8 ] * scaleZ;
  691. te[ 9 ] = me[ 9 ] * scaleZ;
  692. te[ 10 ] = me[ 10 ] * scaleZ;
  693. te[ 11 ] = 0;
  694. te[ 12 ] = 0;
  695. te[ 13 ] = 0;
  696. te[ 14 ] = 0;
  697. te[ 15 ] = 1;
  698. return this;
  699. };
  700. }(),
  701. makeRotationFromEuler: function ( euler ) {
  702. if ( ! ( euler && euler.isEuler ) ) {
  703. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  704. }
  705. var te = this.elements;
  706. var x = euler.x, y = euler.y, z = euler.z;
  707. var a = Math.cos( x ), b = Math.sin( x );
  708. var c = Math.cos( y ), d = Math.sin( y );
  709. var e = Math.cos( z ), f = Math.sin( z );
  710. if ( euler.order === 'XYZ' ) {
  711. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  712. te[ 0 ] = c * e;
  713. te[ 4 ] = - c * f;
  714. te[ 8 ] = d;
  715. te[ 1 ] = af + be * d;
  716. te[ 5 ] = ae - bf * d;
  717. te[ 9 ] = - b * c;
  718. te[ 2 ] = bf - ae * d;
  719. te[ 6 ] = be + af * d;
  720. te[ 10 ] = a * c;
  721. } else if ( euler.order === 'YXZ' ) {
  722. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  723. te[ 0 ] = ce + df * b;
  724. te[ 4 ] = de * b - cf;
  725. te[ 8 ] = a * d;
  726. te[ 1 ] = a * f;
  727. te[ 5 ] = a * e;
  728. te[ 9 ] = - b;
  729. te[ 2 ] = cf * b - de;
  730. te[ 6 ] = df + ce * b;
  731. te[ 10 ] = a * c;
  732. } else if ( euler.order === 'ZXY' ) {
  733. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  734. te[ 0 ] = ce - df * b;
  735. te[ 4 ] = - a * f;
  736. te[ 8 ] = de + cf * b;
  737. te[ 1 ] = cf + de * b;
  738. te[ 5 ] = a * e;
  739. te[ 9 ] = df - ce * b;
  740. te[ 2 ] = - a * d;
  741. te[ 6 ] = b;
  742. te[ 10 ] = a * c;
  743. } else if ( euler.order === 'ZYX' ) {
  744. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  745. te[ 0 ] = c * e;
  746. te[ 4 ] = be * d - af;
  747. te[ 8 ] = ae * d + bf;
  748. te[ 1 ] = c * f;
  749. te[ 5 ] = bf * d + ae;
  750. te[ 9 ] = af * d - be;
  751. te[ 2 ] = - d;
  752. te[ 6 ] = b * c;
  753. te[ 10 ] = a * c;
  754. } else if ( euler.order === 'YZX' ) {
  755. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  756. te[ 0 ] = c * e;
  757. te[ 4 ] = bd - ac * f;
  758. te[ 8 ] = bc * f + ad;
  759. te[ 1 ] = f;
  760. te[ 5 ] = a * e;
  761. te[ 9 ] = - b * e;
  762. te[ 2 ] = - d * e;
  763. te[ 6 ] = ad * f + bc;
  764. te[ 10 ] = ac - bd * f;
  765. } else if ( euler.order === 'XZY' ) {
  766. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  767. te[ 0 ] = c * e;
  768. te[ 4 ] = - f;
  769. te[ 8 ] = d * e;
  770. te[ 1 ] = ac * f + bd;
  771. te[ 5 ] = a * e;
  772. te[ 9 ] = ad * f - bc;
  773. te[ 2 ] = bc * f - ad;
  774. te[ 6 ] = b * e;
  775. te[ 10 ] = bd * f + ac;
  776. }
  777. // bottom row
  778. te[ 3 ] = 0;
  779. te[ 7 ] = 0;
  780. te[ 11 ] = 0;
  781. // last column
  782. te[ 12 ] = 0;
  783. te[ 13 ] = 0;
  784. te[ 14 ] = 0;
  785. te[ 15 ] = 1;
  786. return this;
  787. },
  788. makeRotationFromQuaternion: function () {
  789. var zero = new Vector3( 0, 0, 0 );
  790. var one = new Vector3( 1, 1, 1 );
  791. return function makeRotationFromQuaternion( q ) {
  792. return this.compose( zero, q, one );
  793. };
  794. }(),
  795. lookAt: function () {
  796. var x = new Vector3();
  797. var y = new Vector3();
  798. var z = new Vector3();
  799. return function lookAt( eye, target, up ) {
  800. var te = this.elements;
  801. z.subVectors( eye, target );
  802. if ( z.lengthSq() === 0 ) {
  803. // eye and target are in the same position
  804. z.z = 1;
  805. }
  806. z.normalize();
  807. x.crossVectors( up, z );
  808. if ( x.lengthSq() === 0 ) {
  809. // up and z are parallel
  810. if ( Math.abs( up.z ) === 1 ) {
  811. z.x += 0.0001;
  812. } else {
  813. z.z += 0.0001;
  814. }
  815. z.normalize();
  816. x.crossVectors( up, z );
  817. }
  818. x.normalize();
  819. y.crossVectors( z, x );
  820. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  821. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  822. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  823. return this;
  824. };
  825. }(),
  826. multiply: function ( m, n ) {
  827. if ( n !== undefined ) {
  828. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  829. return this.multiplyMatrices( m, n );
  830. }
  831. return this.multiplyMatrices( this, m );
  832. },
  833. premultiply: function ( m ) {
  834. return this.multiplyMatrices( m, this );
  835. },
  836. multiplyMatrices: function ( a, b ) {
  837. var ae = a.elements;
  838. var be = b.elements;
  839. var te = this.elements;
  840. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  841. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  842. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  843. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  844. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  845. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  846. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  847. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  848. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  849. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  850. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  851. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  852. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  853. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  854. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  855. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  856. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  857. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  858. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  859. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  860. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  861. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  862. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  863. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  864. return this;
  865. },
  866. multiplyScalar: function ( s ) {
  867. var te = this.elements;
  868. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  869. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  870. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  871. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  872. return this;
  873. },
  874. applyToBufferAttribute: function () {
  875. var v1 = new Vector3();
  876. return function applyToBufferAttribute( attribute ) {
  877. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  878. v1.x = attribute.getX( i );
  879. v1.y = attribute.getY( i );
  880. v1.z = attribute.getZ( i );
  881. v1.applyMatrix4( this );
  882. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  883. }
  884. return attribute;
  885. };
  886. }(),
  887. determinant: function () {
  888. var te = this.elements;
  889. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  890. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  891. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  892. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  893. //TODO: make this more efficient
  894. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  895. return (
  896. n41 * (
  897. + n14 * n23 * n32
  898. - n13 * n24 * n32
  899. - n14 * n22 * n33
  900. + n12 * n24 * n33
  901. + n13 * n22 * n34
  902. - n12 * n23 * n34
  903. ) +
  904. n42 * (
  905. + n11 * n23 * n34
  906. - n11 * n24 * n33
  907. + n14 * n21 * n33
  908. - n13 * n21 * n34
  909. + n13 * n24 * n31
  910. - n14 * n23 * n31
  911. ) +
  912. n43 * (
  913. + n11 * n24 * n32
  914. - n11 * n22 * n34
  915. - n14 * n21 * n32
  916. + n12 * n21 * n34
  917. + n14 * n22 * n31
  918. - n12 * n24 * n31
  919. ) +
  920. n44 * (
  921. - n13 * n22 * n31
  922. - n11 * n23 * n32
  923. + n11 * n22 * n33
  924. + n13 * n21 * n32
  925. - n12 * n21 * n33
  926. + n12 * n23 * n31
  927. )
  928. );
  929. },
  930. transpose: function () {
  931. var te = this.elements;
  932. var tmp;
  933. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  934. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  935. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  936. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  937. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  938. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  939. return this;
  940. },
  941. setPosition: function ( v ) {
  942. var te = this.elements;
  943. te[ 12 ] = v.x;
  944. te[ 13 ] = v.y;
  945. te[ 14 ] = v.z;
  946. return this;
  947. },
  948. getInverse: function ( m, throwOnDegenerate ) {
  949. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  950. var te = this.elements,
  951. me = m.elements,
  952. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  953. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  954. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  955. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  956. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  957. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  958. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  959. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  960. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  961. if ( det === 0 ) {
  962. var msg = "THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0";
  963. if ( throwOnDegenerate === true ) {
  964. throw new Error( msg );
  965. } else {
  966. console.warn( msg );
  967. }
  968. return this.identity();
  969. }
  970. var detInv = 1 / det;
  971. te[ 0 ] = t11 * detInv;
  972. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  973. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  974. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  975. te[ 4 ] = t12 * detInv;
  976. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  977. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  978. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  979. te[ 8 ] = t13 * detInv;
  980. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  981. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  982. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  983. te[ 12 ] = t14 * detInv;
  984. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  985. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  986. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  987. return this;
  988. },
  989. scale: function ( v ) {
  990. var te = this.elements;
  991. var x = v.x, y = v.y, z = v.z;
  992. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  993. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  994. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  995. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  996. return this;
  997. },
  998. getMaxScaleOnAxis: function () {
  999. var te = this.elements;
  1000. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  1001. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  1002. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  1003. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  1004. },
  1005. makeTranslation: function ( x, y, z ) {
  1006. this.set(
  1007. 1, 0, 0, x,
  1008. 0, 1, 0, y,
  1009. 0, 0, 1, z,
  1010. 0, 0, 0, 1
  1011. );
  1012. return this;
  1013. },
  1014. makeRotationX: function ( theta ) {
  1015. var c = Math.cos( theta ), s = Math.sin( theta );
  1016. this.set(
  1017. 1, 0, 0, 0,
  1018. 0, c, - s, 0,
  1019. 0, s, c, 0,
  1020. 0, 0, 0, 1
  1021. );
  1022. return this;
  1023. },
  1024. makeRotationY: function ( theta ) {
  1025. var c = Math.cos( theta ), s = Math.sin( theta );
  1026. this.set(
  1027. c, 0, s, 0,
  1028. 0, 1, 0, 0,
  1029. - s, 0, c, 0,
  1030. 0, 0, 0, 1
  1031. );
  1032. return this;
  1033. },
  1034. makeRotationZ: function ( theta ) {
  1035. var c = Math.cos( theta ), s = Math.sin( theta );
  1036. this.set(
  1037. c, - s, 0, 0,
  1038. s, c, 0, 0,
  1039. 0, 0, 1, 0,
  1040. 0, 0, 0, 1
  1041. );
  1042. return this;
  1043. },
  1044. makeRotationAxis: function ( axis, angle ) {
  1045. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  1046. var c = Math.cos( angle );
  1047. var s = Math.sin( angle );
  1048. var t = 1 - c;
  1049. var x = axis.x, y = axis.y, z = axis.z;
  1050. var tx = t * x, ty = t * y;
  1051. this.set(
  1052. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  1053. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  1054. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  1055. 0, 0, 0, 1
  1056. );
  1057. return this;
  1058. },
  1059. makeScale: function ( x, y, z ) {
  1060. this.set(
  1061. x, 0, 0, 0,
  1062. 0, y, 0, 0,
  1063. 0, 0, z, 0,
  1064. 0, 0, 0, 1
  1065. );
  1066. return this;
  1067. },
  1068. makeShear: function ( x, y, z ) {
  1069. this.set(
  1070. 1, y, z, 0,
  1071. x, 1, z, 0,
  1072. x, y, 1, 0,
  1073. 0, 0, 0, 1
  1074. );
  1075. return this;
  1076. },
  1077. compose: function ( position, quaternion, scale ) {
  1078. var te = this.elements;
  1079. var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  1080. var x2 = x + x, y2 = y + y, z2 = z + z;
  1081. var xx = x * x2, xy = x * y2, xz = x * z2;
  1082. var yy = y * y2, yz = y * z2, zz = z * z2;
  1083. var wx = w * x2, wy = w * y2, wz = w * z2;
  1084. var sx = scale.x, sy = scale.y, sz = scale.z;
  1085. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  1086. te[ 1 ] = ( xy + wz ) * sx;
  1087. te[ 2 ] = ( xz - wy ) * sx;
  1088. te[ 3 ] = 0;
  1089. te[ 4 ] = ( xy - wz ) * sy;
  1090. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  1091. te[ 6 ] = ( yz + wx ) * sy;
  1092. te[ 7 ] = 0;
  1093. te[ 8 ] = ( xz + wy ) * sz;
  1094. te[ 9 ] = ( yz - wx ) * sz;
  1095. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  1096. te[ 11 ] = 0;
  1097. te[ 12 ] = position.x;
  1098. te[ 13 ] = position.y;
  1099. te[ 14 ] = position.z;
  1100. te[ 15 ] = 1;
  1101. return this;
  1102. },
  1103. decompose: function () {
  1104. var vector = new Vector3();
  1105. var matrix = new Matrix4();
  1106. return function decompose( position, quaternion, scale ) {
  1107. var te = this.elements;
  1108. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  1109. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  1110. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  1111. // if determine is negative, we need to invert one scale
  1112. var det = this.determinant();
  1113. if ( det < 0 ) sx = - sx;
  1114. position.x = te[ 12 ];
  1115. position.y = te[ 13 ];
  1116. position.z = te[ 14 ];
  1117. // scale the rotation part
  1118. matrix.copy( this );
  1119. var invSX = 1 / sx;
  1120. var invSY = 1 / sy;
  1121. var invSZ = 1 / sz;
  1122. matrix.elements[ 0 ] *= invSX;
  1123. matrix.elements[ 1 ] *= invSX;
  1124. matrix.elements[ 2 ] *= invSX;
  1125. matrix.elements[ 4 ] *= invSY;
  1126. matrix.elements[ 5 ] *= invSY;
  1127. matrix.elements[ 6 ] *= invSY;
  1128. matrix.elements[ 8 ] *= invSZ;
  1129. matrix.elements[ 9 ] *= invSZ;
  1130. matrix.elements[ 10 ] *= invSZ;
  1131. quaternion.setFromRotationMatrix( matrix );
  1132. scale.x = sx;
  1133. scale.y = sy;
  1134. scale.z = sz;
  1135. return this;
  1136. };
  1137. }(),
  1138. makePerspective: function ( left, right, top, bottom, near, far ) {
  1139. if ( far === undefined ) {
  1140. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  1141. }
  1142. var te = this.elements;
  1143. var x = 2 * near / ( right - left );
  1144. var y = 2 * near / ( top - bottom );
  1145. var a = ( right + left ) / ( right - left );
  1146. var b = ( top + bottom ) / ( top - bottom );
  1147. var c = - ( far + near ) / ( far - near );
  1148. var d = - 2 * far * near / ( far - near );
  1149. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  1150. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  1151. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  1152. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  1153. return this;
  1154. },
  1155. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  1156. var te = this.elements;
  1157. var w = 1.0 / ( right - left );
  1158. var h = 1.0 / ( top - bottom );
  1159. var p = 1.0 / ( far - near );
  1160. var x = ( right + left ) * w;
  1161. var y = ( top + bottom ) * h;
  1162. var z = ( far + near ) * p;
  1163. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  1164. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  1165. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  1166. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  1167. return this;
  1168. },
  1169. equals: function ( matrix ) {
  1170. var te = this.elements;
  1171. var me = matrix.elements;
  1172. for ( var i = 0; i < 16; i ++ ) {
  1173. if ( te[ i ] !== me[ i ] ) return false;
  1174. }
  1175. return true;
  1176. },
  1177. fromArray: function ( array, offset ) {
  1178. if ( offset === undefined ) offset = 0;
  1179. for ( var i = 0; i < 16; i ++ ) {
  1180. this.elements[ i ] = array[ i + offset ];
  1181. }
  1182. return this;
  1183. },
  1184. toArray: function ( array, offset ) {
  1185. if ( array === undefined ) array = [];
  1186. if ( offset === undefined ) offset = 0;
  1187. var te = this.elements;
  1188. array[ offset ] = te[ 0 ];
  1189. array[ offset + 1 ] = te[ 1 ];
  1190. array[ offset + 2 ] = te[ 2 ];
  1191. array[ offset + 3 ] = te[ 3 ];
  1192. array[ offset + 4 ] = te[ 4 ];
  1193. array[ offset + 5 ] = te[ 5 ];
  1194. array[ offset + 6 ] = te[ 6 ];
  1195. array[ offset + 7 ] = te[ 7 ];
  1196. array[ offset + 8 ] = te[ 8 ];
  1197. array[ offset + 9 ] = te[ 9 ];
  1198. array[ offset + 10 ] = te[ 10 ];
  1199. array[ offset + 11 ] = te[ 11 ];
  1200. array[ offset + 12 ] = te[ 12 ];
  1201. array[ offset + 13 ] = te[ 13 ];
  1202. array[ offset + 14 ] = te[ 14 ];
  1203. array[ offset + 15 ] = te[ 15 ];
  1204. return array;
  1205. }
  1206. } );
  1207. /**
  1208. * @author mikael emtinger / http://gomo.se/
  1209. * @author alteredq / http://alteredqualia.com/
  1210. * @author WestLangley / http://github.com/WestLangley
  1211. * @author bhouston / http://clara.io
  1212. */
  1213. function Quaternion( x, y, z, w ) {
  1214. this._x = x || 0;
  1215. this._y = y || 0;
  1216. this._z = z || 0;
  1217. this._w = ( w !== undefined ) ? w : 1;
  1218. }
  1219. Object.assign( Quaternion, {
  1220. slerp: function ( qa, qb, qm, t ) {
  1221. return qm.copy( qa ).slerp( qb, t );
  1222. },
  1223. slerpFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  1224. // fuzz-free, array-based Quaternion SLERP operation
  1225. var x0 = src0[ srcOffset0 + 0 ],
  1226. y0 = src0[ srcOffset0 + 1 ],
  1227. z0 = src0[ srcOffset0 + 2 ],
  1228. w0 = src0[ srcOffset0 + 3 ],
  1229. x1 = src1[ srcOffset1 + 0 ],
  1230. y1 = src1[ srcOffset1 + 1 ],
  1231. z1 = src1[ srcOffset1 + 2 ],
  1232. w1 = src1[ srcOffset1 + 3 ];
  1233. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  1234. var s = 1 - t,
  1235. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1236. dir = ( cos >= 0 ? 1 : - 1 ),
  1237. sqrSin = 1 - cos * cos;
  1238. // Skip the Slerp for tiny steps to avoid numeric problems:
  1239. if ( sqrSin > Number.EPSILON ) {
  1240. var sin = Math.sqrt( sqrSin ),
  1241. len = Math.atan2( sin, cos * dir );
  1242. s = Math.sin( s * len ) / sin;
  1243. t = Math.sin( t * len ) / sin;
  1244. }
  1245. var tDir = t * dir;
  1246. x0 = x0 * s + x1 * tDir;
  1247. y0 = y0 * s + y1 * tDir;
  1248. z0 = z0 * s + z1 * tDir;
  1249. w0 = w0 * s + w1 * tDir;
  1250. // Normalize in case we just did a lerp:
  1251. if ( s === 1 - t ) {
  1252. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  1253. x0 *= f;
  1254. y0 *= f;
  1255. z0 *= f;
  1256. w0 *= f;
  1257. }
  1258. }
  1259. dst[ dstOffset ] = x0;
  1260. dst[ dstOffset + 1 ] = y0;
  1261. dst[ dstOffset + 2 ] = z0;
  1262. dst[ dstOffset + 3 ] = w0;
  1263. }
  1264. } );
  1265. Object.defineProperties( Quaternion.prototype, {
  1266. x: {
  1267. get: function () {
  1268. return this._x;
  1269. },
  1270. set: function ( value ) {
  1271. this._x = value;
  1272. this.onChangeCallback();
  1273. }
  1274. },
  1275. y: {
  1276. get: function () {
  1277. return this._y;
  1278. },
  1279. set: function ( value ) {
  1280. this._y = value;
  1281. this.onChangeCallback();
  1282. }
  1283. },
  1284. z: {
  1285. get: function () {
  1286. return this._z;
  1287. },
  1288. set: function ( value ) {
  1289. this._z = value;
  1290. this.onChangeCallback();
  1291. }
  1292. },
  1293. w: {
  1294. get: function () {
  1295. return this._w;
  1296. },
  1297. set: function ( value ) {
  1298. this._w = value;
  1299. this.onChangeCallback();
  1300. }
  1301. }
  1302. } );
  1303. Object.assign( Quaternion.prototype, {
  1304. isQuaternion: true,
  1305. set: function ( x, y, z, w ) {
  1306. this._x = x;
  1307. this._y = y;
  1308. this._z = z;
  1309. this._w = w;
  1310. this.onChangeCallback();
  1311. return this;
  1312. },
  1313. clone: function () {
  1314. return new this.constructor( this._x, this._y, this._z, this._w );
  1315. },
  1316. copy: function ( quaternion ) {
  1317. this._x = quaternion.x;
  1318. this._y = quaternion.y;
  1319. this._z = quaternion.z;
  1320. this._w = quaternion.w;
  1321. this.onChangeCallback();
  1322. return this;
  1323. },
  1324. setFromEuler: function ( euler, update ) {
  1325. if ( ! ( euler && euler.isEuler ) ) {
  1326. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1327. }
  1328. var x = euler._x, y = euler._y, z = euler._z, order = euler.order;
  1329. // http://www.mathworks.com/matlabcentral/fileexchange/
  1330. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1331. // content/SpinCalc.m
  1332. var cos = Math.cos;
  1333. var sin = Math.sin;
  1334. var c1 = cos( x / 2 );
  1335. var c2 = cos( y / 2 );
  1336. var c3 = cos( z / 2 );
  1337. var s1 = sin( x / 2 );
  1338. var s2 = sin( y / 2 );
  1339. var s3 = sin( z / 2 );
  1340. if ( order === 'XYZ' ) {
  1341. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1342. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1343. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1344. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1345. } else if ( order === 'YXZ' ) {
  1346. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1347. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1348. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1349. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1350. } else if ( order === 'ZXY' ) {
  1351. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1352. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1353. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1354. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1355. } else if ( order === 'ZYX' ) {
  1356. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1357. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1358. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1359. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1360. } else if ( order === 'YZX' ) {
  1361. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1362. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1363. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1364. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1365. } else if ( order === 'XZY' ) {
  1366. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1367. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1368. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1369. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1370. }
  1371. if ( update !== false ) this.onChangeCallback();
  1372. return this;
  1373. },
  1374. setFromAxisAngle: function ( axis, angle ) {
  1375. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1376. // assumes axis is normalized
  1377. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  1378. this._x = axis.x * s;
  1379. this._y = axis.y * s;
  1380. this._z = axis.z * s;
  1381. this._w = Math.cos( halfAngle );
  1382. this.onChangeCallback();
  1383. return this;
  1384. },
  1385. setFromRotationMatrix: function ( m ) {
  1386. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1387. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1388. var te = m.elements,
  1389. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1390. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1391. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  1392. trace = m11 + m22 + m33,
  1393. s;
  1394. if ( trace > 0 ) {
  1395. s = 0.5 / Math.sqrt( trace + 1.0 );
  1396. this._w = 0.25 / s;
  1397. this._x = ( m32 - m23 ) * s;
  1398. this._y = ( m13 - m31 ) * s;
  1399. this._z = ( m21 - m12 ) * s;
  1400. } else if ( m11 > m22 && m11 > m33 ) {
  1401. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  1402. this._w = ( m32 - m23 ) / s;
  1403. this._x = 0.25 * s;
  1404. this._y = ( m12 + m21 ) / s;
  1405. this._z = ( m13 + m31 ) / s;
  1406. } else if ( m22 > m33 ) {
  1407. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  1408. this._w = ( m13 - m31 ) / s;
  1409. this._x = ( m12 + m21 ) / s;
  1410. this._y = 0.25 * s;
  1411. this._z = ( m23 + m32 ) / s;
  1412. } else {
  1413. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  1414. this._w = ( m21 - m12 ) / s;
  1415. this._x = ( m13 + m31 ) / s;
  1416. this._y = ( m23 + m32 ) / s;
  1417. this._z = 0.25 * s;
  1418. }
  1419. this.onChangeCallback();
  1420. return this;
  1421. },
  1422. setFromUnitVectors: function () {
  1423. // assumes direction vectors vFrom and vTo are normalized
  1424. var v1 = new Vector3();
  1425. var r;
  1426. var EPS = 0.000001;
  1427. return function setFromUnitVectors( vFrom, vTo ) {
  1428. if ( v1 === undefined ) v1 = new Vector3();
  1429. r = vFrom.dot( vTo ) + 1;
  1430. if ( r < EPS ) {
  1431. r = 0;
  1432. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  1433. v1.set( - vFrom.y, vFrom.x, 0 );
  1434. } else {
  1435. v1.set( 0, - vFrom.z, vFrom.y );
  1436. }
  1437. } else {
  1438. v1.crossVectors( vFrom, vTo );
  1439. }
  1440. this._x = v1.x;
  1441. this._y = v1.y;
  1442. this._z = v1.z;
  1443. this._w = r;
  1444. return this.normalize();
  1445. };
  1446. }(),
  1447. angleTo: function ( q ) {
  1448. return 2 * Math.acos( Math.abs( _Math.clamp( this.dot( q ), - 1, 1 ) ) );
  1449. },
  1450. rotateTowards: function ( q, step ) {
  1451. var angle = this.angleTo( q );
  1452. if ( angle === 0 ) return this;
  1453. var t = Math.min( 1, step / angle );
  1454. this.slerp( q, t );
  1455. return this;
  1456. },
  1457. inverse: function () {
  1458. // quaternion is assumed to have unit length
  1459. return this.conjugate();
  1460. },
  1461. conjugate: function () {
  1462. this._x *= - 1;
  1463. this._y *= - 1;
  1464. this._z *= - 1;
  1465. this.onChangeCallback();
  1466. return this;
  1467. },
  1468. dot: function ( v ) {
  1469. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1470. },
  1471. lengthSq: function () {
  1472. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1473. },
  1474. length: function () {
  1475. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  1476. },
  1477. normalize: function () {
  1478. var l = this.length();
  1479. if ( l === 0 ) {
  1480. this._x = 0;
  1481. this._y = 0;
  1482. this._z = 0;
  1483. this._w = 1;
  1484. } else {
  1485. l = 1 / l;
  1486. this._x = this._x * l;
  1487. this._y = this._y * l;
  1488. this._z = this._z * l;
  1489. this._w = this._w * l;
  1490. }
  1491. this.onChangeCallback();
  1492. return this;
  1493. },
  1494. multiply: function ( q, p ) {
  1495. if ( p !== undefined ) {
  1496. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  1497. return this.multiplyQuaternions( q, p );
  1498. }
  1499. return this.multiplyQuaternions( this, q );
  1500. },
  1501. premultiply: function ( q ) {
  1502. return this.multiplyQuaternions( q, this );
  1503. },
  1504. multiplyQuaternions: function ( a, b ) {
  1505. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  1506. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  1507. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  1508. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  1509. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  1510. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  1511. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  1512. this.onChangeCallback();
  1513. return this;
  1514. },
  1515. slerp: function ( qb, t ) {
  1516. if ( t === 0 ) return this;
  1517. if ( t === 1 ) return this.copy( qb );
  1518. var x = this._x, y = this._y, z = this._z, w = this._w;
  1519. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  1520. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  1521. if ( cosHalfTheta < 0 ) {
  1522. this._w = - qb._w;
  1523. this._x = - qb._x;
  1524. this._y = - qb._y;
  1525. this._z = - qb._z;
  1526. cosHalfTheta = - cosHalfTheta;
  1527. } else {
  1528. this.copy( qb );
  1529. }
  1530. if ( cosHalfTheta >= 1.0 ) {
  1531. this._w = w;
  1532. this._x = x;
  1533. this._y = y;
  1534. this._z = z;
  1535. return this;
  1536. }
  1537. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  1538. if ( sqrSinHalfTheta <= Number.EPSILON ) {
  1539. var s = 1 - t;
  1540. this._w = s * w + t * this._w;
  1541. this._x = s * x + t * this._x;
  1542. this._y = s * y + t * this._y;
  1543. this._z = s * z + t * this._z;
  1544. return this.normalize();
  1545. }
  1546. var sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
  1547. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  1548. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  1549. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  1550. this._w = ( w * ratioA + this._w * ratioB );
  1551. this._x = ( x * ratioA + this._x * ratioB );
  1552. this._y = ( y * ratioA + this._y * ratioB );
  1553. this._z = ( z * ratioA + this._z * ratioB );
  1554. this.onChangeCallback();
  1555. return this;
  1556. },
  1557. equals: function ( quaternion ) {
  1558. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  1559. },
  1560. fromArray: function ( array, offset ) {
  1561. if ( offset === undefined ) offset = 0;
  1562. this._x = array[ offset ];
  1563. this._y = array[ offset + 1 ];
  1564. this._z = array[ offset + 2 ];
  1565. this._w = array[ offset + 3 ];
  1566. this.onChangeCallback();
  1567. return this;
  1568. },
  1569. toArray: function ( array, offset ) {
  1570. if ( array === undefined ) array = [];
  1571. if ( offset === undefined ) offset = 0;
  1572. array[ offset ] = this._x;
  1573. array[ offset + 1 ] = this._y;
  1574. array[ offset + 2 ] = this._z;
  1575. array[ offset + 3 ] = this._w;
  1576. return array;
  1577. },
  1578. onChange: function ( callback ) {
  1579. this.onChangeCallback = callback;
  1580. return this;
  1581. },
  1582. onChangeCallback: function () {}
  1583. } );
  1584. /**
  1585. * @author mrdoob / http://mrdoob.com/
  1586. * @author kile / http://kile.stravaganza.org/
  1587. * @author philogb / http://blog.thejit.org/
  1588. * @author mikael emtinger / http://gomo.se/
  1589. * @author egraether / http://egraether.com/
  1590. * @author WestLangley / http://github.com/WestLangley
  1591. */
  1592. function Vector3( x, y, z ) {
  1593. this.x = x || 0;
  1594. this.y = y || 0;
  1595. this.z = z || 0;
  1596. }
  1597. Object.assign( Vector3.prototype, {
  1598. isVector3: true,
  1599. set: function ( x, y, z ) {
  1600. this.x = x;
  1601. this.y = y;
  1602. this.z = z;
  1603. return this;
  1604. },
  1605. setScalar: function ( scalar ) {
  1606. this.x = scalar;
  1607. this.y = scalar;
  1608. this.z = scalar;
  1609. return this;
  1610. },
  1611. setX: function ( x ) {
  1612. this.x = x;
  1613. return this;
  1614. },
  1615. setY: function ( y ) {
  1616. this.y = y;
  1617. return this;
  1618. },
  1619. setZ: function ( z ) {
  1620. this.z = z;
  1621. return this;
  1622. },
  1623. setComponent: function ( index, value ) {
  1624. switch ( index ) {
  1625. case 0: this.x = value; break;
  1626. case 1: this.y = value; break;
  1627. case 2: this.z = value; break;
  1628. default: throw new Error( 'index is out of range: ' + index );
  1629. }
  1630. return this;
  1631. },
  1632. getComponent: function ( index ) {
  1633. switch ( index ) {
  1634. case 0: return this.x;
  1635. case 1: return this.y;
  1636. case 2: return this.z;
  1637. default: throw new Error( 'index is out of range: ' + index );
  1638. }
  1639. },
  1640. clone: function () {
  1641. return new this.constructor( this.x, this.y, this.z );
  1642. },
  1643. copy: function ( v ) {
  1644. this.x = v.x;
  1645. this.y = v.y;
  1646. this.z = v.z;
  1647. return this;
  1648. },
  1649. add: function ( v, w ) {
  1650. if ( w !== undefined ) {
  1651. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1652. return this.addVectors( v, w );
  1653. }
  1654. this.x += v.x;
  1655. this.y += v.y;
  1656. this.z += v.z;
  1657. return this;
  1658. },
  1659. addScalar: function ( s ) {
  1660. this.x += s;
  1661. this.y += s;
  1662. this.z += s;
  1663. return this;
  1664. },
  1665. addVectors: function ( a, b ) {
  1666. this.x = a.x + b.x;
  1667. this.y = a.y + b.y;
  1668. this.z = a.z + b.z;
  1669. return this;
  1670. },
  1671. addScaledVector: function ( v, s ) {
  1672. this.x += v.x * s;
  1673. this.y += v.y * s;
  1674. this.z += v.z * s;
  1675. return this;
  1676. },
  1677. sub: function ( v, w ) {
  1678. if ( w !== undefined ) {
  1679. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1680. return this.subVectors( v, w );
  1681. }
  1682. this.x -= v.x;
  1683. this.y -= v.y;
  1684. this.z -= v.z;
  1685. return this;
  1686. },
  1687. subScalar: function ( s ) {
  1688. this.x -= s;
  1689. this.y -= s;
  1690. this.z -= s;
  1691. return this;
  1692. },
  1693. subVectors: function ( a, b ) {
  1694. this.x = a.x - b.x;
  1695. this.y = a.y - b.y;
  1696. this.z = a.z - b.z;
  1697. return this;
  1698. },
  1699. multiply: function ( v, w ) {
  1700. if ( w !== undefined ) {
  1701. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1702. return this.multiplyVectors( v, w );
  1703. }
  1704. this.x *= v.x;
  1705. this.y *= v.y;
  1706. this.z *= v.z;
  1707. return this;
  1708. },
  1709. multiplyScalar: function ( scalar ) {
  1710. this.x *= scalar;
  1711. this.y *= scalar;
  1712. this.z *= scalar;
  1713. return this;
  1714. },
  1715. multiplyVectors: function ( a, b ) {
  1716. this.x = a.x * b.x;
  1717. this.y = a.y * b.y;
  1718. this.z = a.z * b.z;
  1719. return this;
  1720. },
  1721. applyEuler: function () {
  1722. var quaternion = new Quaternion();
  1723. return function applyEuler( euler ) {
  1724. if ( ! ( euler && euler.isEuler ) ) {
  1725. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1726. }
  1727. return this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1728. };
  1729. }(),
  1730. applyAxisAngle: function () {
  1731. var quaternion = new Quaternion();
  1732. return function applyAxisAngle( axis, angle ) {
  1733. return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1734. };
  1735. }(),
  1736. applyMatrix3: function ( m ) {
  1737. var x = this.x, y = this.y, z = this.z;
  1738. var e = m.elements;
  1739. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1740. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1741. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1742. return this;
  1743. },
  1744. applyMatrix4: function ( m ) {
  1745. var x = this.x, y = this.y, z = this.z;
  1746. var e = m.elements;
  1747. var w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  1748. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  1749. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  1750. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  1751. return this;
  1752. },
  1753. applyQuaternion: function ( q ) {
  1754. var x = this.x, y = this.y, z = this.z;
  1755. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1756. // calculate quat * vector
  1757. var ix = qw * x + qy * z - qz * y;
  1758. var iy = qw * y + qz * x - qx * z;
  1759. var iz = qw * z + qx * y - qy * x;
  1760. var iw = - qx * x - qy * y - qz * z;
  1761. // calculate result * inverse quat
  1762. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1763. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1764. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1765. return this;
  1766. },
  1767. project: function ( camera ) {
  1768. return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
  1769. },
  1770. unproject: function () {
  1771. var matrix = new Matrix4();
  1772. return function unproject( camera ) {
  1773. return this.applyMatrix4( matrix.getInverse( camera.projectionMatrix ) ).applyMatrix4( camera.matrixWorld );
  1774. };
  1775. }(),
  1776. transformDirection: function ( m ) {
  1777. // input: THREE.Matrix4 affine matrix
  1778. // vector interpreted as a direction
  1779. var x = this.x, y = this.y, z = this.z;
  1780. var e = m.elements;
  1781. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1782. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1783. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1784. return this.normalize();
  1785. },
  1786. divide: function ( v ) {
  1787. this.x /= v.x;
  1788. this.y /= v.y;
  1789. this.z /= v.z;
  1790. return this;
  1791. },
  1792. divideScalar: function ( scalar ) {
  1793. return this.multiplyScalar( 1 / scalar );
  1794. },
  1795. min: function ( v ) {
  1796. this.x = Math.min( this.x, v.x );
  1797. this.y = Math.min( this.y, v.y );
  1798. this.z = Math.min( this.z, v.z );
  1799. return this;
  1800. },
  1801. max: function ( v ) {
  1802. this.x = Math.max( this.x, v.x );
  1803. this.y = Math.max( this.y, v.y );
  1804. this.z = Math.max( this.z, v.z );
  1805. return this;
  1806. },
  1807. clamp: function ( min, max ) {
  1808. // assumes min < max, componentwise
  1809. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1810. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1811. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1812. return this;
  1813. },
  1814. clampScalar: function () {
  1815. var min = new Vector3();
  1816. var max = new Vector3();
  1817. return function clampScalar( minVal, maxVal ) {
  1818. min.set( minVal, minVal, minVal );
  1819. max.set( maxVal, maxVal, maxVal );
  1820. return this.clamp( min, max );
  1821. };
  1822. }(),
  1823. clampLength: function ( min, max ) {
  1824. var length = this.length();
  1825. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1826. },
  1827. floor: function () {
  1828. this.x = Math.floor( this.x );
  1829. this.y = Math.floor( this.y );
  1830. this.z = Math.floor( this.z );
  1831. return this;
  1832. },
  1833. ceil: function () {
  1834. this.x = Math.ceil( this.x );
  1835. this.y = Math.ceil( this.y );
  1836. this.z = Math.ceil( this.z );
  1837. return this;
  1838. },
  1839. round: function () {
  1840. this.x = Math.round( this.x );
  1841. this.y = Math.round( this.y );
  1842. this.z = Math.round( this.z );
  1843. return this;
  1844. },
  1845. roundToZero: function () {
  1846. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1847. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1848. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1849. return this;
  1850. },
  1851. negate: function () {
  1852. this.x = - this.x;
  1853. this.y = - this.y;
  1854. this.z = - this.z;
  1855. return this;
  1856. },
  1857. dot: function ( v ) {
  1858. return this.x * v.x + this.y * v.y + this.z * v.z;
  1859. },
  1860. // TODO lengthSquared?
  1861. lengthSq: function () {
  1862. return this.x * this.x + this.y * this.y + this.z * this.z;
  1863. },
  1864. length: function () {
  1865. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1866. },
  1867. manhattanLength: function () {
  1868. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1869. },
  1870. normalize: function () {
  1871. return this.divideScalar( this.length() || 1 );
  1872. },
  1873. setLength: function ( length ) {
  1874. return this.normalize().multiplyScalar( length );
  1875. },
  1876. lerp: function ( v, alpha ) {
  1877. this.x += ( v.x - this.x ) * alpha;
  1878. this.y += ( v.y - this.y ) * alpha;
  1879. this.z += ( v.z - this.z ) * alpha;
  1880. return this;
  1881. },
  1882. lerpVectors: function ( v1, v2, alpha ) {
  1883. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1884. },
  1885. cross: function ( v, w ) {
  1886. if ( w !== undefined ) {
  1887. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1888. return this.crossVectors( v, w );
  1889. }
  1890. return this.crossVectors( this, v );
  1891. },
  1892. crossVectors: function ( a, b ) {
  1893. var ax = a.x, ay = a.y, az = a.z;
  1894. var bx = b.x, by = b.y, bz = b.z;
  1895. this.x = ay * bz - az * by;
  1896. this.y = az * bx - ax * bz;
  1897. this.z = ax * by - ay * bx;
  1898. return this;
  1899. },
  1900. projectOnVector: function ( vector ) {
  1901. var scalar = vector.dot( this ) / vector.lengthSq();
  1902. return this.copy( vector ).multiplyScalar( scalar );
  1903. },
  1904. projectOnPlane: function () {
  1905. var v1 = new Vector3();
  1906. return function projectOnPlane( planeNormal ) {
  1907. v1.copy( this ).projectOnVector( planeNormal );
  1908. return this.sub( v1 );
  1909. };
  1910. }(),
  1911. reflect: function () {
  1912. // reflect incident vector off plane orthogonal to normal
  1913. // normal is assumed to have unit length
  1914. var v1 = new Vector3();
  1915. return function reflect( normal ) {
  1916. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1917. };
  1918. }(),
  1919. angleTo: function ( v ) {
  1920. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1921. // clamp, to handle numerical problems
  1922. return Math.acos( _Math.clamp( theta, - 1, 1 ) );
  1923. },
  1924. distanceTo: function ( v ) {
  1925. return Math.sqrt( this.distanceToSquared( v ) );
  1926. },
  1927. distanceToSquared: function ( v ) {
  1928. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1929. return dx * dx + dy * dy + dz * dz;
  1930. },
  1931. manhattanDistanceTo: function ( v ) {
  1932. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  1933. },
  1934. setFromSpherical: function ( s ) {
  1935. return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
  1936. },
  1937. setFromSphericalCoords: function ( radius, phi, theta ) {
  1938. var sinPhiRadius = Math.sin( phi ) * radius;
  1939. this.x = sinPhiRadius * Math.sin( theta );
  1940. this.y = Math.cos( phi ) * radius;
  1941. this.z = sinPhiRadius * Math.cos( theta );
  1942. return this;
  1943. },
  1944. setFromCylindrical: function ( c ) {
  1945. return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
  1946. },
  1947. setFromCylindricalCoords: function ( radius, theta, y ) {
  1948. this.x = radius * Math.sin( theta );
  1949. this.y = y;
  1950. this.z = radius * Math.cos( theta );
  1951. return this;
  1952. },
  1953. setFromMatrixPosition: function ( m ) {
  1954. var e = m.elements;
  1955. this.x = e[ 12 ];
  1956. this.y = e[ 13 ];
  1957. this.z = e[ 14 ];
  1958. return this;
  1959. },
  1960. setFromMatrixScale: function ( m ) {
  1961. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1962. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1963. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1964. this.x = sx;
  1965. this.y = sy;
  1966. this.z = sz;
  1967. return this;
  1968. },
  1969. setFromMatrixColumn: function ( m, index ) {
  1970. return this.fromArray( m.elements, index * 4 );
  1971. },
  1972. equals: function ( v ) {
  1973. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1974. },
  1975. fromArray: function ( array, offset ) {
  1976. if ( offset === undefined ) offset = 0;
  1977. this.x = array[ offset ];
  1978. this.y = array[ offset + 1 ];
  1979. this.z = array[ offset + 2 ];
  1980. return this;
  1981. },
  1982. toArray: function ( array, offset ) {
  1983. if ( array === undefined ) array = [];
  1984. if ( offset === undefined ) offset = 0;
  1985. array[ offset ] = this.x;
  1986. array[ offset + 1 ] = this.y;
  1987. array[ offset + 2 ] = this.z;
  1988. return array;
  1989. },
  1990. fromBufferAttribute: function ( attribute, index, offset ) {
  1991. if ( offset !== undefined ) {
  1992. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  1993. }
  1994. this.x = attribute.getX( index );
  1995. this.y = attribute.getY( index );
  1996. this.z = attribute.getZ( index );
  1997. return this;
  1998. }
  1999. } );
  2000. /**
  2001. * @author alteredq / http://alteredqualia.com/
  2002. * @author WestLangley / http://github.com/WestLangley
  2003. * @author bhouston / http://clara.io
  2004. * @author tschw
  2005. */
  2006. function Matrix3() {
  2007. this.elements = [
  2008. 1, 0, 0,
  2009. 0, 1, 0,
  2010. 0, 0, 1
  2011. ];
  2012. if ( arguments.length > 0 ) {
  2013. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2014. }
  2015. }
  2016. Object.assign( Matrix3.prototype, {
  2017. isMatrix3: true,
  2018. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2019. var te = this.elements;
  2020. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  2021. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  2022. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  2023. return this;
  2024. },
  2025. identity: function () {
  2026. this.set(
  2027. 1, 0, 0,
  2028. 0, 1, 0,
  2029. 0, 0, 1
  2030. );
  2031. return this;
  2032. },
  2033. clone: function () {
  2034. return new this.constructor().fromArray( this.elements );
  2035. },
  2036. copy: function ( m ) {
  2037. var te = this.elements;
  2038. var me = m.elements;
  2039. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  2040. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  2041. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  2042. return this;
  2043. },
  2044. setFromMatrix4: function ( m ) {
  2045. var me = m.elements;
  2046. this.set(
  2047. me[ 0 ], me[ 4 ], me[ 8 ],
  2048. me[ 1 ], me[ 5 ], me[ 9 ],
  2049. me[ 2 ], me[ 6 ], me[ 10 ]
  2050. );
  2051. return this;
  2052. },
  2053. applyToBufferAttribute: function () {
  2054. var v1 = new Vector3();
  2055. return function applyToBufferAttribute( attribute ) {
  2056. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2057. v1.x = attribute.getX( i );
  2058. v1.y = attribute.getY( i );
  2059. v1.z = attribute.getZ( i );
  2060. v1.applyMatrix3( this );
  2061. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  2062. }
  2063. return attribute;
  2064. };
  2065. }(),
  2066. multiply: function ( m ) {
  2067. return this.multiplyMatrices( this, m );
  2068. },
  2069. premultiply: function ( m ) {
  2070. return this.multiplyMatrices( m, this );
  2071. },
  2072. multiplyMatrices: function ( a, b ) {
  2073. var ae = a.elements;
  2074. var be = b.elements;
  2075. var te = this.elements;
  2076. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  2077. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  2078. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  2079. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  2080. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  2081. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  2082. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  2083. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  2084. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  2085. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  2086. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  2087. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  2088. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  2089. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  2090. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  2091. return this;
  2092. },
  2093. multiplyScalar: function ( s ) {
  2094. var te = this.elements;
  2095. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2096. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2097. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2098. return this;
  2099. },
  2100. determinant: function () {
  2101. var te = this.elements;
  2102. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2103. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2104. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2105. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2106. },
  2107. getInverse: function ( matrix, throwOnDegenerate ) {
  2108. if ( matrix && matrix.isMatrix4 ) {
  2109. console.error( "THREE.Matrix3: .getInverse() no longer takes a Matrix4 argument." );
  2110. }
  2111. var me = matrix.elements,
  2112. te = this.elements,
  2113. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  2114. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  2115. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  2116. t11 = n33 * n22 - n32 * n23,
  2117. t12 = n32 * n13 - n33 * n12,
  2118. t13 = n23 * n12 - n22 * n13,
  2119. det = n11 * t11 + n21 * t12 + n31 * t13;
  2120. if ( det === 0 ) {
  2121. var msg = "THREE.Matrix3: .getInverse() can't invert matrix, determinant is 0";
  2122. if ( throwOnDegenerate === true ) {
  2123. throw new Error( msg );
  2124. } else {
  2125. console.warn( msg );
  2126. }
  2127. return this.identity();
  2128. }
  2129. var detInv = 1 / det;
  2130. te[ 0 ] = t11 * detInv;
  2131. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  2132. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  2133. te[ 3 ] = t12 * detInv;
  2134. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  2135. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  2136. te[ 6 ] = t13 * detInv;
  2137. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  2138. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  2139. return this;
  2140. },
  2141. transpose: function () {
  2142. var tmp, m = this.elements;
  2143. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2144. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2145. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2146. return this;
  2147. },
  2148. getNormalMatrix: function ( matrix4 ) {
  2149. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  2150. },
  2151. transposeIntoArray: function ( r ) {
  2152. var m = this.elements;
  2153. r[ 0 ] = m[ 0 ];
  2154. r[ 1 ] = m[ 3 ];
  2155. r[ 2 ] = m[ 6 ];
  2156. r[ 3 ] = m[ 1 ];
  2157. r[ 4 ] = m[ 4 ];
  2158. r[ 5 ] = m[ 7 ];
  2159. r[ 6 ] = m[ 2 ];
  2160. r[ 7 ] = m[ 5 ];
  2161. r[ 8 ] = m[ 8 ];
  2162. return this;
  2163. },
  2164. setUvTransform: function ( tx, ty, sx, sy, rotation, cx, cy ) {
  2165. var c = Math.cos( rotation );
  2166. var s = Math.sin( rotation );
  2167. this.set(
  2168. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  2169. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  2170. 0, 0, 1
  2171. );
  2172. },
  2173. scale: function ( sx, sy ) {
  2174. var te = this.elements;
  2175. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  2176. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  2177. return this;
  2178. },
  2179. rotate: function ( theta ) {
  2180. var c = Math.cos( theta );
  2181. var s = Math.sin( theta );
  2182. var te = this.elements;
  2183. var a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  2184. var a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  2185. te[ 0 ] = c * a11 + s * a21;
  2186. te[ 3 ] = c * a12 + s * a22;
  2187. te[ 6 ] = c * a13 + s * a23;
  2188. te[ 1 ] = - s * a11 + c * a21;
  2189. te[ 4 ] = - s * a12 + c * a22;
  2190. te[ 7 ] = - s * a13 + c * a23;
  2191. return this;
  2192. },
  2193. translate: function ( tx, ty ) {
  2194. var te = this.elements;
  2195. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  2196. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  2197. return this;
  2198. },
  2199. equals: function ( matrix ) {
  2200. var te = this.elements;
  2201. var me = matrix.elements;
  2202. for ( var i = 0; i < 9; i ++ ) {
  2203. if ( te[ i ] !== me[ i ] ) return false;
  2204. }
  2205. return true;
  2206. },
  2207. fromArray: function ( array, offset ) {
  2208. if ( offset === undefined ) offset = 0;
  2209. for ( var i = 0; i < 9; i ++ ) {
  2210. this.elements[ i ] = array[ i + offset ];
  2211. }
  2212. return this;
  2213. },
  2214. toArray: function ( array, offset ) {
  2215. if ( array === undefined ) array = [];
  2216. if ( offset === undefined ) offset = 0;
  2217. var te = this.elements;
  2218. array[ offset ] = te[ 0 ];
  2219. array[ offset + 1 ] = te[ 1 ];
  2220. array[ offset + 2 ] = te[ 2 ];
  2221. array[ offset + 3 ] = te[ 3 ];
  2222. array[ offset + 4 ] = te[ 4 ];
  2223. array[ offset + 5 ] = te[ 5 ];
  2224. array[ offset + 6 ] = te[ 6 ];
  2225. array[ offset + 7 ] = te[ 7 ];
  2226. array[ offset + 8 ] = te[ 8 ];
  2227. return array;
  2228. }
  2229. } );
  2230. /**
  2231. * @author mrdoob / http://mrdoob.com/
  2232. * @author alteredq / http://alteredqualia.com/
  2233. * @author szimek / https://github.com/szimek/
  2234. */
  2235. var _canvas;
  2236. var ImageUtils = {
  2237. getDataURL: function ( image ) {
  2238. var canvas;
  2239. if ( typeof HTMLCanvasElement == 'undefined' ) {
  2240. return image.src;
  2241. } else if ( image instanceof HTMLCanvasElement ) {
  2242. canvas = image;
  2243. } else {
  2244. if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  2245. _canvas.width = image.width;
  2246. _canvas.height = image.height;
  2247. var context = _canvas.getContext( '2d' );
  2248. if ( image instanceof ImageData ) {
  2249. context.putImageData( image, 0, 0 );
  2250. } else {
  2251. context.drawImage( image, 0, 0, image.width, image.height );
  2252. }
  2253. canvas = _canvas;
  2254. }
  2255. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  2256. return canvas.toDataURL( 'image/jpeg', 0.6 );
  2257. } else {
  2258. return canvas.toDataURL( 'image/png' );
  2259. }
  2260. }
  2261. };
  2262. /**
  2263. * @author mrdoob / http://mrdoob.com/
  2264. * @author alteredq / http://alteredqualia.com/
  2265. * @author szimek / https://github.com/szimek/
  2266. */
  2267. var textureId = 0;
  2268. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  2269. Object.defineProperty( this, 'id', { value: textureId ++ } );
  2270. this.uuid = _Math.generateUUID();
  2271. this.name = '';
  2272. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  2273. this.mipmaps = [];
  2274. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  2275. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  2276. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  2277. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  2278. this.minFilter = minFilter !== undefined ? minFilter : LinearMipMapLinearFilter;
  2279. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  2280. this.format = format !== undefined ? format : RGBAFormat;
  2281. this.type = type !== undefined ? type : UnsignedByteType;
  2282. this.offset = new Vector2( 0, 0 );
  2283. this.repeat = new Vector2( 1, 1 );
  2284. this.center = new Vector2( 0, 0 );
  2285. this.rotation = 0;
  2286. this.matrixAutoUpdate = true;
  2287. this.matrix = new Matrix3();
  2288. this.generateMipmaps = true;
  2289. this.premultiplyAlpha = false;
  2290. this.flipY = true;
  2291. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  2292. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  2293. //
  2294. // Also changing the encoding after already used by a Material will not automatically make the Material
  2295. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  2296. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  2297. this.version = 0;
  2298. this.onUpdate = null;
  2299. }
  2300. Texture.DEFAULT_IMAGE = undefined;
  2301. Texture.DEFAULT_MAPPING = UVMapping;
  2302. Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2303. constructor: Texture,
  2304. isTexture: true,
  2305. updateMatrix: function () {
  2306. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  2307. },
  2308. clone: function () {
  2309. return new this.constructor().copy( this );
  2310. },
  2311. copy: function ( source ) {
  2312. this.name = source.name;
  2313. this.image = source.image;
  2314. this.mipmaps = source.mipmaps.slice( 0 );
  2315. this.mapping = source.mapping;
  2316. this.wrapS = source.wrapS;
  2317. this.wrapT = source.wrapT;
  2318. this.magFilter = source.magFilter;
  2319. this.minFilter = source.minFilter;
  2320. this.anisotropy = source.anisotropy;
  2321. this.format = source.format;
  2322. this.type = source.type;
  2323. this.offset.copy( source.offset );
  2324. this.repeat.copy( source.repeat );
  2325. this.center.copy( source.center );
  2326. this.rotation = source.rotation;
  2327. this.matrixAutoUpdate = source.matrixAutoUpdate;
  2328. this.matrix.copy( source.matrix );
  2329. this.generateMipmaps = source.generateMipmaps;
  2330. this.premultiplyAlpha = source.premultiplyAlpha;
  2331. this.flipY = source.flipY;
  2332. this.unpackAlignment = source.unpackAlignment;
  2333. this.encoding = source.encoding;
  2334. return this;
  2335. },
  2336. toJSON: function ( meta ) {
  2337. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  2338. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  2339. return meta.textures[ this.uuid ];
  2340. }
  2341. var output = {
  2342. metadata: {
  2343. version: 4.5,
  2344. type: 'Texture',
  2345. generator: 'Texture.toJSON'
  2346. },
  2347. uuid: this.uuid,
  2348. name: this.name,
  2349. mapping: this.mapping,
  2350. repeat: [ this.repeat.x, this.repeat.y ],
  2351. offset: [ this.offset.x, this.offset.y ],
  2352. center: [ this.center.x, this.center.y ],
  2353. rotation: this.rotation,
  2354. wrap: [ this.wrapS, this.wrapT ],
  2355. format: this.format,
  2356. type: this.type,
  2357. encoding: this.encoding,
  2358. minFilter: this.minFilter,
  2359. magFilter: this.magFilter,
  2360. anisotropy: this.anisotropy,
  2361. flipY: this.flipY,
  2362. premultiplyAlpha: this.premultiplyAlpha,
  2363. unpackAlignment: this.unpackAlignment
  2364. };
  2365. if ( this.image !== undefined ) {
  2366. // TODO: Move to THREE.Image
  2367. var image = this.image;
  2368. if ( image.uuid === undefined ) {
  2369. image.uuid = _Math.generateUUID(); // UGH
  2370. }
  2371. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  2372. var url;
  2373. if ( Array.isArray( image ) ) {
  2374. // process array of images e.g. CubeTexture
  2375. url = [];
  2376. for ( var i = 0, l = image.length; i < l; i ++ ) {
  2377. url.push( ImageUtils.getDataURL( image[ i ] ) );
  2378. }
  2379. } else {
  2380. // process single image
  2381. url = ImageUtils.getDataURL( image );
  2382. }
  2383. meta.images[ image.uuid ] = {
  2384. uuid: image.uuid,
  2385. url: url
  2386. };
  2387. }
  2388. output.image = image.uuid;
  2389. }
  2390. if ( ! isRootObject ) {
  2391. meta.textures[ this.uuid ] = output;
  2392. }
  2393. return output;
  2394. },
  2395. dispose: function () {
  2396. this.dispatchEvent( { type: 'dispose' } );
  2397. },
  2398. transformUv: function ( uv ) {
  2399. if ( this.mapping !== UVMapping ) return uv;
  2400. uv.applyMatrix3( this.matrix );
  2401. if ( uv.x < 0 || uv.x > 1 ) {
  2402. switch ( this.wrapS ) {
  2403. case RepeatWrapping:
  2404. uv.x = uv.x - Math.floor( uv.x );
  2405. break;
  2406. case ClampToEdgeWrapping:
  2407. uv.x = uv.x < 0 ? 0 : 1;
  2408. break;
  2409. case MirroredRepeatWrapping:
  2410. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  2411. uv.x = Math.ceil( uv.x ) - uv.x;
  2412. } else {
  2413. uv.x = uv.x - Math.floor( uv.x );
  2414. }
  2415. break;
  2416. }
  2417. }
  2418. if ( uv.y < 0 || uv.y > 1 ) {
  2419. switch ( this.wrapT ) {
  2420. case RepeatWrapping:
  2421. uv.y = uv.y - Math.floor( uv.y );
  2422. break;
  2423. case ClampToEdgeWrapping:
  2424. uv.y = uv.y < 0 ? 0 : 1;
  2425. break;
  2426. case MirroredRepeatWrapping:
  2427. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  2428. uv.y = Math.ceil( uv.y ) - uv.y;
  2429. } else {
  2430. uv.y = uv.y - Math.floor( uv.y );
  2431. }
  2432. break;
  2433. }
  2434. }
  2435. if ( this.flipY ) {
  2436. uv.y = 1 - uv.y;
  2437. }
  2438. return uv;
  2439. }
  2440. } );
  2441. Object.defineProperty( Texture.prototype, "needsUpdate", {
  2442. set: function ( value ) {
  2443. if ( value === true ) this.version ++;
  2444. }
  2445. } );
  2446. /**
  2447. * @author supereggbert / http://www.paulbrunt.co.uk/
  2448. * @author philogb / http://blog.thejit.org/
  2449. * @author mikael emtinger / http://gomo.se/
  2450. * @author egraether / http://egraether.com/
  2451. * @author WestLangley / http://github.com/WestLangley
  2452. */
  2453. function Vector4( x, y, z, w ) {
  2454. this.x = x || 0;
  2455. this.y = y || 0;
  2456. this.z = z || 0;
  2457. this.w = ( w !== undefined ) ? w : 1;
  2458. }
  2459. Object.assign( Vector4.prototype, {
  2460. isVector4: true,
  2461. set: function ( x, y, z, w ) {
  2462. this.x = x;
  2463. this.y = y;
  2464. this.z = z;
  2465. this.w = w;
  2466. return this;
  2467. },
  2468. setScalar: function ( scalar ) {
  2469. this.x = scalar;
  2470. this.y = scalar;
  2471. this.z = scalar;
  2472. this.w = scalar;
  2473. return this;
  2474. },
  2475. setX: function ( x ) {
  2476. this.x = x;
  2477. return this;
  2478. },
  2479. setY: function ( y ) {
  2480. this.y = y;
  2481. return this;
  2482. },
  2483. setZ: function ( z ) {
  2484. this.z = z;
  2485. return this;
  2486. },
  2487. setW: function ( w ) {
  2488. this.w = w;
  2489. return this;
  2490. },
  2491. setComponent: function ( index, value ) {
  2492. switch ( index ) {
  2493. case 0: this.x = value; break;
  2494. case 1: this.y = value; break;
  2495. case 2: this.z = value; break;
  2496. case 3: this.w = value; break;
  2497. default: throw new Error( 'index is out of range: ' + index );
  2498. }
  2499. return this;
  2500. },
  2501. getComponent: function ( index ) {
  2502. switch ( index ) {
  2503. case 0: return this.x;
  2504. case 1: return this.y;
  2505. case 2: return this.z;
  2506. case 3: return this.w;
  2507. default: throw new Error( 'index is out of range: ' + index );
  2508. }
  2509. },
  2510. clone: function () {
  2511. return new this.constructor( this.x, this.y, this.z, this.w );
  2512. },
  2513. copy: function ( v ) {
  2514. this.x = v.x;
  2515. this.y = v.y;
  2516. this.z = v.z;
  2517. this.w = ( v.w !== undefined ) ? v.w : 1;
  2518. return this;
  2519. },
  2520. add: function ( v, w ) {
  2521. if ( w !== undefined ) {
  2522. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  2523. return this.addVectors( v, w );
  2524. }
  2525. this.x += v.x;
  2526. this.y += v.y;
  2527. this.z += v.z;
  2528. this.w += v.w;
  2529. return this;
  2530. },
  2531. addScalar: function ( s ) {
  2532. this.x += s;
  2533. this.y += s;
  2534. this.z += s;
  2535. this.w += s;
  2536. return this;
  2537. },
  2538. addVectors: function ( a, b ) {
  2539. this.x = a.x + b.x;
  2540. this.y = a.y + b.y;
  2541. this.z = a.z + b.z;
  2542. this.w = a.w + b.w;
  2543. return this;
  2544. },
  2545. addScaledVector: function ( v, s ) {
  2546. this.x += v.x * s;
  2547. this.y += v.y * s;
  2548. this.z += v.z * s;
  2549. this.w += v.w * s;
  2550. return this;
  2551. },
  2552. sub: function ( v, w ) {
  2553. if ( w !== undefined ) {
  2554. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  2555. return this.subVectors( v, w );
  2556. }
  2557. this.x -= v.x;
  2558. this.y -= v.y;
  2559. this.z -= v.z;
  2560. this.w -= v.w;
  2561. return this;
  2562. },
  2563. subScalar: function ( s ) {
  2564. this.x -= s;
  2565. this.y -= s;
  2566. this.z -= s;
  2567. this.w -= s;
  2568. return this;
  2569. },
  2570. subVectors: function ( a, b ) {
  2571. this.x = a.x - b.x;
  2572. this.y = a.y - b.y;
  2573. this.z = a.z - b.z;
  2574. this.w = a.w - b.w;
  2575. return this;
  2576. },
  2577. multiplyScalar: function ( scalar ) {
  2578. this.x *= scalar;
  2579. this.y *= scalar;
  2580. this.z *= scalar;
  2581. this.w *= scalar;
  2582. return this;
  2583. },
  2584. applyMatrix4: function ( m ) {
  2585. var x = this.x, y = this.y, z = this.z, w = this.w;
  2586. var e = m.elements;
  2587. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  2588. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  2589. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  2590. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  2591. return this;
  2592. },
  2593. divideScalar: function ( scalar ) {
  2594. return this.multiplyScalar( 1 / scalar );
  2595. },
  2596. setAxisAngleFromQuaternion: function ( q ) {
  2597. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  2598. // q is assumed to be normalized
  2599. this.w = 2 * Math.acos( q.w );
  2600. var s = Math.sqrt( 1 - q.w * q.w );
  2601. if ( s < 0.0001 ) {
  2602. this.x = 1;
  2603. this.y = 0;
  2604. this.z = 0;
  2605. } else {
  2606. this.x = q.x / s;
  2607. this.y = q.y / s;
  2608. this.z = q.z / s;
  2609. }
  2610. return this;
  2611. },
  2612. setAxisAngleFromRotationMatrix: function ( m ) {
  2613. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2614. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2615. var angle, x, y, z, // variables for result
  2616. epsilon = 0.01, // margin to allow for rounding errors
  2617. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  2618. te = m.elements,
  2619. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  2620. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  2621. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2622. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  2623. ( Math.abs( m13 - m31 ) < epsilon ) &&
  2624. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  2625. // singularity found
  2626. // first check for identity matrix which must have +1 for all terms
  2627. // in leading diagonal and zero in other terms
  2628. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  2629. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  2630. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  2631. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  2632. // this singularity is identity matrix so angle = 0
  2633. this.set( 1, 0, 0, 0 );
  2634. return this; // zero angle, arbitrary axis
  2635. }
  2636. // otherwise this singularity is angle = 180
  2637. angle = Math.PI;
  2638. var xx = ( m11 + 1 ) / 2;
  2639. var yy = ( m22 + 1 ) / 2;
  2640. var zz = ( m33 + 1 ) / 2;
  2641. var xy = ( m12 + m21 ) / 4;
  2642. var xz = ( m13 + m31 ) / 4;
  2643. var yz = ( m23 + m32 ) / 4;
  2644. if ( ( xx > yy ) && ( xx > zz ) ) {
  2645. // m11 is the largest diagonal term
  2646. if ( xx < epsilon ) {
  2647. x = 0;
  2648. y = 0.707106781;
  2649. z = 0.707106781;
  2650. } else {
  2651. x = Math.sqrt( xx );
  2652. y = xy / x;
  2653. z = xz / x;
  2654. }
  2655. } else if ( yy > zz ) {
  2656. // m22 is the largest diagonal term
  2657. if ( yy < epsilon ) {
  2658. x = 0.707106781;
  2659. y = 0;
  2660. z = 0.707106781;
  2661. } else {
  2662. y = Math.sqrt( yy );
  2663. x = xy / y;
  2664. z = yz / y;
  2665. }
  2666. } else {
  2667. // m33 is the largest diagonal term so base result on this
  2668. if ( zz < epsilon ) {
  2669. x = 0.707106781;
  2670. y = 0.707106781;
  2671. z = 0;
  2672. } else {
  2673. z = Math.sqrt( zz );
  2674. x = xz / z;
  2675. y = yz / z;
  2676. }
  2677. }
  2678. this.set( x, y, z, angle );
  2679. return this; // return 180 deg rotation
  2680. }
  2681. // as we have reached here there are no singularities so we can handle normally
  2682. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  2683. ( m13 - m31 ) * ( m13 - m31 ) +
  2684. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  2685. if ( Math.abs( s ) < 0.001 ) s = 1;
  2686. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2687. // caught by singularity test above, but I've left it in just in case
  2688. this.x = ( m32 - m23 ) / s;
  2689. this.y = ( m13 - m31 ) / s;
  2690. this.z = ( m21 - m12 ) / s;
  2691. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  2692. return this;
  2693. },
  2694. min: function ( v ) {
  2695. this.x = Math.min( this.x, v.x );
  2696. this.y = Math.min( this.y, v.y );
  2697. this.z = Math.min( this.z, v.z );
  2698. this.w = Math.min( this.w, v.w );
  2699. return this;
  2700. },
  2701. max: function ( v ) {
  2702. this.x = Math.max( this.x, v.x );
  2703. this.y = Math.max( this.y, v.y );
  2704. this.z = Math.max( this.z, v.z );
  2705. this.w = Math.max( this.w, v.w );
  2706. return this;
  2707. },
  2708. clamp: function ( min, max ) {
  2709. // assumes min < max, componentwise
  2710. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2711. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2712. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2713. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  2714. return this;
  2715. },
  2716. clampScalar: function () {
  2717. var min, max;
  2718. return function clampScalar( minVal, maxVal ) {
  2719. if ( min === undefined ) {
  2720. min = new Vector4();
  2721. max = new Vector4();
  2722. }
  2723. min.set( minVal, minVal, minVal, minVal );
  2724. max.set( maxVal, maxVal, maxVal, maxVal );
  2725. return this.clamp( min, max );
  2726. };
  2727. }(),
  2728. clampLength: function ( min, max ) {
  2729. var length = this.length();
  2730. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2731. },
  2732. floor: function () {
  2733. this.x = Math.floor( this.x );
  2734. this.y = Math.floor( this.y );
  2735. this.z = Math.floor( this.z );
  2736. this.w = Math.floor( this.w );
  2737. return this;
  2738. },
  2739. ceil: function () {
  2740. this.x = Math.ceil( this.x );
  2741. this.y = Math.ceil( this.y );
  2742. this.z = Math.ceil( this.z );
  2743. this.w = Math.ceil( this.w );
  2744. return this;
  2745. },
  2746. round: function () {
  2747. this.x = Math.round( this.x );
  2748. this.y = Math.round( this.y );
  2749. this.z = Math.round( this.z );
  2750. this.w = Math.round( this.w );
  2751. return this;
  2752. },
  2753. roundToZero: function () {
  2754. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2755. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2756. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2757. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  2758. return this;
  2759. },
  2760. negate: function () {
  2761. this.x = - this.x;
  2762. this.y = - this.y;
  2763. this.z = - this.z;
  2764. this.w = - this.w;
  2765. return this;
  2766. },
  2767. dot: function ( v ) {
  2768. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2769. },
  2770. lengthSq: function () {
  2771. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2772. },
  2773. length: function () {
  2774. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  2775. },
  2776. manhattanLength: function () {
  2777. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  2778. },
  2779. normalize: function () {
  2780. return this.divideScalar( this.length() || 1 );
  2781. },
  2782. setLength: function ( length ) {
  2783. return this.normalize().multiplyScalar( length );
  2784. },
  2785. lerp: function ( v, alpha ) {
  2786. this.x += ( v.x - this.x ) * alpha;
  2787. this.y += ( v.y - this.y ) * alpha;
  2788. this.z += ( v.z - this.z ) * alpha;
  2789. this.w += ( v.w - this.w ) * alpha;
  2790. return this;
  2791. },
  2792. lerpVectors: function ( v1, v2, alpha ) {
  2793. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  2794. },
  2795. equals: function ( v ) {
  2796. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  2797. },
  2798. fromArray: function ( array, offset ) {
  2799. if ( offset === undefined ) offset = 0;
  2800. this.x = array[ offset ];
  2801. this.y = array[ offset + 1 ];
  2802. this.z = array[ offset + 2 ];
  2803. this.w = array[ offset + 3 ];
  2804. return this;
  2805. },
  2806. toArray: function ( array, offset ) {
  2807. if ( array === undefined ) array = [];
  2808. if ( offset === undefined ) offset = 0;
  2809. array[ offset ] = this.x;
  2810. array[ offset + 1 ] = this.y;
  2811. array[ offset + 2 ] = this.z;
  2812. array[ offset + 3 ] = this.w;
  2813. return array;
  2814. },
  2815. fromBufferAttribute: function ( attribute, index, offset ) {
  2816. if ( offset !== undefined ) {
  2817. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  2818. }
  2819. this.x = attribute.getX( index );
  2820. this.y = attribute.getY( index );
  2821. this.z = attribute.getZ( index );
  2822. this.w = attribute.getW( index );
  2823. return this;
  2824. }
  2825. } );
  2826. /**
  2827. * @author szimek / https://github.com/szimek/
  2828. * @author alteredq / http://alteredqualia.com/
  2829. * @author Marius Kintel / https://github.com/kintel
  2830. */
  2831. /*
  2832. In options, we can specify:
  2833. * Texture parameters for an auto-generated target texture
  2834. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2835. */
  2836. function WebGLRenderTarget( width, height, options ) {
  2837. this.width = width;
  2838. this.height = height;
  2839. this.scissor = new Vector4( 0, 0, width, height );
  2840. this.scissorTest = false;
  2841. this.viewport = new Vector4( 0, 0, width, height );
  2842. options = options || {};
  2843. this.texture = new Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  2844. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  2845. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  2846. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2847. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  2848. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2849. }
  2850. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2851. constructor: WebGLRenderTarget,
  2852. isWebGLRenderTarget: true,
  2853. setSize: function ( width, height ) {
  2854. if ( this.width !== width || this.height !== height ) {
  2855. this.width = width;
  2856. this.height = height;
  2857. this.dispose();
  2858. }
  2859. this.viewport.set( 0, 0, width, height );
  2860. this.scissor.set( 0, 0, width, height );
  2861. },
  2862. clone: function () {
  2863. return new this.constructor().copy( this );
  2864. },
  2865. copy: function ( source ) {
  2866. this.width = source.width;
  2867. this.height = source.height;
  2868. this.viewport.copy( source.viewport );
  2869. this.texture = source.texture.clone();
  2870. this.depthBuffer = source.depthBuffer;
  2871. this.stencilBuffer = source.stencilBuffer;
  2872. this.depthTexture = source.depthTexture;
  2873. return this;
  2874. },
  2875. dispose: function () {
  2876. this.dispatchEvent( { type: 'dispose' } );
  2877. }
  2878. } );
  2879. /**
  2880. * @author Mugen87 / https://github.com/Mugen87
  2881. * @author Matt DesLauriers / @mattdesl
  2882. */
  2883. function WebGLMultisampleRenderTarget( width, height, options ) {
  2884. WebGLRenderTarget.call( this, width, height, options );
  2885. this.samples = 4;
  2886. }
  2887. WebGLMultisampleRenderTarget.prototype = Object.assign( Object.create( WebGLRenderTarget.prototype ), {
  2888. constructor: WebGLMultisampleRenderTarget,
  2889. isWebGLMultisampleRenderTarget: true,
  2890. copy: function ( source ) {
  2891. WebGLRenderTarget.prototype.copy.call( this, source );
  2892. this.samples = source.samples;
  2893. return this;
  2894. }
  2895. } );
  2896. /**
  2897. * @author alteredq / http://alteredqualia.com
  2898. */
  2899. function WebGLRenderTargetCube( width, height, options ) {
  2900. WebGLRenderTarget.call( this, width, height, options );
  2901. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  2902. this.activeMipMapLevel = 0;
  2903. }
  2904. WebGLRenderTargetCube.prototype = Object.create( WebGLRenderTarget.prototype );
  2905. WebGLRenderTargetCube.prototype.constructor = WebGLRenderTargetCube;
  2906. WebGLRenderTargetCube.prototype.isWebGLRenderTargetCube = true;
  2907. /**
  2908. * @author alteredq / http://alteredqualia.com/
  2909. */
  2910. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  2911. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  2912. this.image = { data: data, width: width, height: height };
  2913. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  2914. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  2915. this.generateMipmaps = false;
  2916. this.flipY = false;
  2917. this.unpackAlignment = 1;
  2918. }
  2919. DataTexture.prototype = Object.create( Texture.prototype );
  2920. DataTexture.prototype.constructor = DataTexture;
  2921. DataTexture.prototype.isDataTexture = true;
  2922. /**
  2923. * @author bhouston / http://clara.io
  2924. * @author WestLangley / http://github.com/WestLangley
  2925. */
  2926. function Box3( min, max ) {
  2927. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  2928. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  2929. }
  2930. Object.assign( Box3.prototype, {
  2931. isBox3: true,
  2932. set: function ( min, max ) {
  2933. this.min.copy( min );
  2934. this.max.copy( max );
  2935. return this;
  2936. },
  2937. setFromArray: function ( array ) {
  2938. var minX = + Infinity;
  2939. var minY = + Infinity;
  2940. var minZ = + Infinity;
  2941. var maxX = - Infinity;
  2942. var maxY = - Infinity;
  2943. var maxZ = - Infinity;
  2944. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  2945. var x = array[ i ];
  2946. var y = array[ i + 1 ];
  2947. var z = array[ i + 2 ];
  2948. if ( x < minX ) minX = x;
  2949. if ( y < minY ) minY = y;
  2950. if ( z < minZ ) minZ = z;
  2951. if ( x > maxX ) maxX = x;
  2952. if ( y > maxY ) maxY = y;
  2953. if ( z > maxZ ) maxZ = z;
  2954. }
  2955. this.min.set( minX, minY, minZ );
  2956. this.max.set( maxX, maxY, maxZ );
  2957. return this;
  2958. },
  2959. setFromBufferAttribute: function ( attribute ) {
  2960. var minX = + Infinity;
  2961. var minY = + Infinity;
  2962. var minZ = + Infinity;
  2963. var maxX = - Infinity;
  2964. var maxY = - Infinity;
  2965. var maxZ = - Infinity;
  2966. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2967. var x = attribute.getX( i );
  2968. var y = attribute.getY( i );
  2969. var z = attribute.getZ( i );
  2970. if ( x < minX ) minX = x;
  2971. if ( y < minY ) minY = y;
  2972. if ( z < minZ ) minZ = z;
  2973. if ( x > maxX ) maxX = x;
  2974. if ( y > maxY ) maxY = y;
  2975. if ( z > maxZ ) maxZ = z;
  2976. }
  2977. this.min.set( minX, minY, minZ );
  2978. this.max.set( maxX, maxY, maxZ );
  2979. return this;
  2980. },
  2981. setFromPoints: function ( points ) {
  2982. this.makeEmpty();
  2983. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2984. this.expandByPoint( points[ i ] );
  2985. }
  2986. return this;
  2987. },
  2988. setFromCenterAndSize: function () {
  2989. var v1 = new Vector3();
  2990. return function setFromCenterAndSize( center, size ) {
  2991. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2992. this.min.copy( center ).sub( halfSize );
  2993. this.max.copy( center ).add( halfSize );
  2994. return this;
  2995. };
  2996. }(),
  2997. setFromObject: function ( object ) {
  2998. this.makeEmpty();
  2999. return this.expandByObject( object );
  3000. },
  3001. clone: function () {
  3002. return new this.constructor().copy( this );
  3003. },
  3004. copy: function ( box ) {
  3005. this.min.copy( box.min );
  3006. this.max.copy( box.max );
  3007. return this;
  3008. },
  3009. makeEmpty: function () {
  3010. this.min.x = this.min.y = this.min.z = + Infinity;
  3011. this.max.x = this.max.y = this.max.z = - Infinity;
  3012. return this;
  3013. },
  3014. isEmpty: function () {
  3015. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3016. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  3017. },
  3018. getCenter: function ( target ) {
  3019. if ( target === undefined ) {
  3020. console.warn( 'THREE.Box3: .getCenter() target is now required' );
  3021. target = new Vector3();
  3022. }
  3023. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  3024. },
  3025. getSize: function ( target ) {
  3026. if ( target === undefined ) {
  3027. console.warn( 'THREE.Box3: .getSize() target is now required' );
  3028. target = new Vector3();
  3029. }
  3030. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  3031. },
  3032. expandByPoint: function ( point ) {
  3033. this.min.min( point );
  3034. this.max.max( point );
  3035. return this;
  3036. },
  3037. expandByVector: function ( vector ) {
  3038. this.min.sub( vector );
  3039. this.max.add( vector );
  3040. return this;
  3041. },
  3042. expandByScalar: function ( scalar ) {
  3043. this.min.addScalar( - scalar );
  3044. this.max.addScalar( scalar );
  3045. return this;
  3046. },
  3047. expandByObject: function () {
  3048. // Computes the world-axis-aligned bounding box of an object (including its children),
  3049. // accounting for both the object's, and children's, world transforms
  3050. var scope, i, l;
  3051. var v1 = new Vector3();
  3052. function traverse( node ) {
  3053. var geometry = node.geometry;
  3054. if ( geometry !== undefined ) {
  3055. if ( geometry.isGeometry ) {
  3056. var vertices = geometry.vertices;
  3057. for ( i = 0, l = vertices.length; i < l; i ++ ) {
  3058. v1.copy( vertices[ i ] );
  3059. v1.applyMatrix4( node.matrixWorld );
  3060. scope.expandByPoint( v1 );
  3061. }
  3062. } else if ( geometry.isBufferGeometry ) {
  3063. var attribute = geometry.attributes.position;
  3064. if ( attribute !== undefined ) {
  3065. for ( i = 0, l = attribute.count; i < l; i ++ ) {
  3066. v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
  3067. scope.expandByPoint( v1 );
  3068. }
  3069. }
  3070. }
  3071. }
  3072. }
  3073. return function expandByObject( object ) {
  3074. scope = this;
  3075. object.updateMatrixWorld( true );
  3076. object.traverse( traverse );
  3077. return this;
  3078. };
  3079. }(),
  3080. containsPoint: function ( point ) {
  3081. return point.x < this.min.x || point.x > this.max.x ||
  3082. point.y < this.min.y || point.y > this.max.y ||
  3083. point.z < this.min.z || point.z > this.max.z ? false : true;
  3084. },
  3085. containsBox: function ( box ) {
  3086. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  3087. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  3088. this.min.z <= box.min.z && box.max.z <= this.max.z;
  3089. },
  3090. getParameter: function ( point, target ) {
  3091. // This can potentially have a divide by zero if the box
  3092. // has a size dimension of 0.
  3093. if ( target === undefined ) {
  3094. console.warn( 'THREE.Box3: .getParameter() target is now required' );
  3095. target = new Vector3();
  3096. }
  3097. return target.set(
  3098. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  3099. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  3100. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  3101. );
  3102. },
  3103. intersectsBox: function ( box ) {
  3104. // using 6 splitting planes to rule out intersections.
  3105. return box.max.x < this.min.x || box.min.x > this.max.x ||
  3106. box.max.y < this.min.y || box.min.y > this.max.y ||
  3107. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  3108. },
  3109. intersectsSphere: ( function () {
  3110. var closestPoint = new Vector3();
  3111. return function intersectsSphere( sphere ) {
  3112. // Find the point on the AABB closest to the sphere center.
  3113. this.clampPoint( sphere.center, closestPoint );
  3114. // If that point is inside the sphere, the AABB and sphere intersect.
  3115. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  3116. };
  3117. } )(),
  3118. intersectsPlane: function ( plane ) {
  3119. // We compute the minimum and maximum dot product values. If those values
  3120. // are on the same side (back or front) of the plane, then there is no intersection.
  3121. var min, max;
  3122. if ( plane.normal.x > 0 ) {
  3123. min = plane.normal.x * this.min.x;
  3124. max = plane.normal.x * this.max.x;
  3125. } else {
  3126. min = plane.normal.x * this.max.x;
  3127. max = plane.normal.x * this.min.x;
  3128. }
  3129. if ( plane.normal.y > 0 ) {
  3130. min += plane.normal.y * this.min.y;
  3131. max += plane.normal.y * this.max.y;
  3132. } else {
  3133. min += plane.normal.y * this.max.y;
  3134. max += plane.normal.y * this.min.y;
  3135. }
  3136. if ( plane.normal.z > 0 ) {
  3137. min += plane.normal.z * this.min.z;
  3138. max += plane.normal.z * this.max.z;
  3139. } else {
  3140. min += plane.normal.z * this.max.z;
  3141. max += plane.normal.z * this.min.z;
  3142. }
  3143. return ( min <= - plane.constant && max >= - plane.constant );
  3144. },
  3145. intersectsTriangle: ( function () {
  3146. // triangle centered vertices
  3147. var v0 = new Vector3();
  3148. var v1 = new Vector3();
  3149. var v2 = new Vector3();
  3150. // triangle edge vectors
  3151. var f0 = new Vector3();
  3152. var f1 = new Vector3();
  3153. var f2 = new Vector3();
  3154. var testAxis = new Vector3();
  3155. var center = new Vector3();
  3156. var extents = new Vector3();
  3157. var triangleNormal = new Vector3();
  3158. function satForAxes( axes ) {
  3159. var i, j;
  3160. for ( i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  3161. testAxis.fromArray( axes, i );
  3162. // project the aabb onto the seperating axis
  3163. var r = extents.x * Math.abs( testAxis.x ) + extents.y * Math.abs( testAxis.y ) + extents.z * Math.abs( testAxis.z );
  3164. // project all 3 vertices of the triangle onto the seperating axis
  3165. var p0 = v0.dot( testAxis );
  3166. var p1 = v1.dot( testAxis );
  3167. var p2 = v2.dot( testAxis );
  3168. // actual test, basically see if either of the most extreme of the triangle points intersects r
  3169. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  3170. // points of the projected triangle are outside the projected half-length of the aabb
  3171. // the axis is seperating and we can exit
  3172. return false;
  3173. }
  3174. }
  3175. return true;
  3176. }
  3177. return function intersectsTriangle( triangle ) {
  3178. if ( this.isEmpty() ) {
  3179. return false;
  3180. }
  3181. // compute box center and extents
  3182. this.getCenter( center );
  3183. extents.subVectors( this.max, center );
  3184. // translate triangle to aabb origin
  3185. v0.subVectors( triangle.a, center );
  3186. v1.subVectors( triangle.b, center );
  3187. v2.subVectors( triangle.c, center );
  3188. // compute edge vectors for triangle
  3189. f0.subVectors( v1, v0 );
  3190. f1.subVectors( v2, v1 );
  3191. f2.subVectors( v0, v2 );
  3192. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  3193. // 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
  3194. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3195. var axes = [
  3196. 0, - f0.z, f0.y, 0, - f1.z, f1.y, 0, - f2.z, f2.y,
  3197. f0.z, 0, - f0.x, f1.z, 0, - f1.x, f2.z, 0, - f2.x,
  3198. - f0.y, f0.x, 0, - f1.y, f1.x, 0, - f2.y, f2.x, 0
  3199. ];
  3200. if ( ! satForAxes( axes ) ) {
  3201. return false;
  3202. }
  3203. // test 3 face normals from the aabb
  3204. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  3205. if ( ! satForAxes( axes ) ) {
  3206. return false;
  3207. }
  3208. // finally testing the face normal of the triangle
  3209. // use already existing triangle edge vectors here
  3210. triangleNormal.crossVectors( f0, f1 );
  3211. axes = [ triangleNormal.x, triangleNormal.y, triangleNormal.z ];
  3212. return satForAxes( axes );
  3213. };
  3214. } )(),
  3215. clampPoint: function ( point, target ) {
  3216. if ( target === undefined ) {
  3217. console.warn( 'THREE.Box3: .clampPoint() target is now required' );
  3218. target = new Vector3();
  3219. }
  3220. return target.copy( point ).clamp( this.min, this.max );
  3221. },
  3222. distanceToPoint: function () {
  3223. var v1 = new Vector3();
  3224. return function distanceToPoint( point ) {
  3225. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  3226. return clampedPoint.sub( point ).length();
  3227. };
  3228. }(),
  3229. getBoundingSphere: function () {
  3230. var v1 = new Vector3();
  3231. return function getBoundingSphere( target ) {
  3232. if ( target === undefined ) {
  3233. console.warn( 'THREE.Box3: .getBoundingSphere() target is now required' );
  3234. target = new Sphere();
  3235. }
  3236. this.getCenter( target.center );
  3237. target.radius = this.getSize( v1 ).length() * 0.5;
  3238. return target;
  3239. };
  3240. }(),
  3241. intersect: function ( box ) {
  3242. this.min.max( box.min );
  3243. this.max.min( box.max );
  3244. // 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.
  3245. if ( this.isEmpty() ) this.makeEmpty();
  3246. return this;
  3247. },
  3248. union: function ( box ) {
  3249. this.min.min( box.min );
  3250. this.max.max( box.max );
  3251. return this;
  3252. },
  3253. applyMatrix4: function () {
  3254. var points = [
  3255. new Vector3(),
  3256. new Vector3(),
  3257. new Vector3(),
  3258. new Vector3(),
  3259. new Vector3(),
  3260. new Vector3(),
  3261. new Vector3(),
  3262. new Vector3()
  3263. ];
  3264. return function applyMatrix4( matrix ) {
  3265. // transform of empty box is an empty box.
  3266. if ( this.isEmpty() ) return this;
  3267. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  3268. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  3269. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  3270. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  3271. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  3272. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  3273. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  3274. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  3275. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  3276. this.setFromPoints( points );
  3277. return this;
  3278. };
  3279. }(),
  3280. translate: function ( offset ) {
  3281. this.min.add( offset );
  3282. this.max.add( offset );
  3283. return this;
  3284. },
  3285. equals: function ( box ) {
  3286. return box.min.equals( this.min ) && box.max.equals( this.max );
  3287. }
  3288. } );
  3289. /**
  3290. * @author bhouston / http://clara.io
  3291. * @author mrdoob / http://mrdoob.com/
  3292. */
  3293. function Sphere( center, radius ) {
  3294. this.center = ( center !== undefined ) ? center : new Vector3();
  3295. this.radius = ( radius !== undefined ) ? radius : 0;
  3296. }
  3297. Object.assign( Sphere.prototype, {
  3298. set: function ( center, radius ) {
  3299. this.center.copy( center );
  3300. this.radius = radius;
  3301. return this;
  3302. },
  3303. setFromPoints: function () {
  3304. var box = new Box3();
  3305. return function setFromPoints( points, optionalCenter ) {
  3306. var center = this.center;
  3307. if ( optionalCenter !== undefined ) {
  3308. center.copy( optionalCenter );
  3309. } else {
  3310. box.setFromPoints( points ).getCenter( center );
  3311. }
  3312. var maxRadiusSq = 0;
  3313. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3314. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3315. }
  3316. this.radius = Math.sqrt( maxRadiusSq );
  3317. return this;
  3318. };
  3319. }(),
  3320. clone: function () {
  3321. return new this.constructor().copy( this );
  3322. },
  3323. copy: function ( sphere ) {
  3324. this.center.copy( sphere.center );
  3325. this.radius = sphere.radius;
  3326. return this;
  3327. },
  3328. empty: function () {
  3329. return ( this.radius <= 0 );
  3330. },
  3331. containsPoint: function ( point ) {
  3332. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3333. },
  3334. distanceToPoint: function ( point ) {
  3335. return ( point.distanceTo( this.center ) - this.radius );
  3336. },
  3337. intersectsSphere: function ( sphere ) {
  3338. var radiusSum = this.radius + sphere.radius;
  3339. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3340. },
  3341. intersectsBox: function ( box ) {
  3342. return box.intersectsSphere( this );
  3343. },
  3344. intersectsPlane: function ( plane ) {
  3345. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  3346. },
  3347. clampPoint: function ( point, target ) {
  3348. var deltaLengthSq = this.center.distanceToSquared( point );
  3349. if ( target === undefined ) {
  3350. console.warn( 'THREE.Sphere: .clampPoint() target is now required' );
  3351. target = new Vector3();
  3352. }
  3353. target.copy( point );
  3354. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3355. target.sub( this.center ).normalize();
  3356. target.multiplyScalar( this.radius ).add( this.center );
  3357. }
  3358. return target;
  3359. },
  3360. getBoundingBox: function ( target ) {
  3361. if ( target === undefined ) {
  3362. console.warn( 'THREE.Sphere: .getBoundingBox() target is now required' );
  3363. target = new Box3();
  3364. }
  3365. target.set( this.center, this.center );
  3366. target.expandByScalar( this.radius );
  3367. return target;
  3368. },
  3369. applyMatrix4: function ( matrix ) {
  3370. this.center.applyMatrix4( matrix );
  3371. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3372. return this;
  3373. },
  3374. translate: function ( offset ) {
  3375. this.center.add( offset );
  3376. return this;
  3377. },
  3378. equals: function ( sphere ) {
  3379. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3380. }
  3381. } );
  3382. /**
  3383. * @author bhouston / http://clara.io
  3384. */
  3385. function Plane( normal, constant ) {
  3386. // normal is assumed to be normalized
  3387. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  3388. this.constant = ( constant !== undefined ) ? constant : 0;
  3389. }
  3390. Object.assign( Plane.prototype, {
  3391. set: function ( normal, constant ) {
  3392. this.normal.copy( normal );
  3393. this.constant = constant;
  3394. return this;
  3395. },
  3396. setComponents: function ( x, y, z, w ) {
  3397. this.normal.set( x, y, z );
  3398. this.constant = w;
  3399. return this;
  3400. },
  3401. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3402. this.normal.copy( normal );
  3403. this.constant = - point.dot( this.normal );
  3404. return this;
  3405. },
  3406. setFromCoplanarPoints: function () {
  3407. var v1 = new Vector3();
  3408. var v2 = new Vector3();
  3409. return function setFromCoplanarPoints( a, b, c ) {
  3410. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3411. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3412. this.setFromNormalAndCoplanarPoint( normal, a );
  3413. return this;
  3414. };
  3415. }(),
  3416. clone: function () {
  3417. return new this.constructor().copy( this );
  3418. },
  3419. copy: function ( plane ) {
  3420. this.normal.copy( plane.normal );
  3421. this.constant = plane.constant;
  3422. return this;
  3423. },
  3424. normalize: function () {
  3425. // Note: will lead to a divide by zero if the plane is invalid.
  3426. var inverseNormalLength = 1.0 / this.normal.length();
  3427. this.normal.multiplyScalar( inverseNormalLength );
  3428. this.constant *= inverseNormalLength;
  3429. return this;
  3430. },
  3431. negate: function () {
  3432. this.constant *= - 1;
  3433. this.normal.negate();
  3434. return this;
  3435. },
  3436. distanceToPoint: function ( point ) {
  3437. return this.normal.dot( point ) + this.constant;
  3438. },
  3439. distanceToSphere: function ( sphere ) {
  3440. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3441. },
  3442. projectPoint: function ( point, target ) {
  3443. if ( target === undefined ) {
  3444. console.warn( 'THREE.Plane: .projectPoint() target is now required' );
  3445. target = new Vector3();
  3446. }
  3447. return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  3448. },
  3449. intersectLine: function () {
  3450. var v1 = new Vector3();
  3451. return function intersectLine( line, target ) {
  3452. if ( target === undefined ) {
  3453. console.warn( 'THREE.Plane: .intersectLine() target is now required' );
  3454. target = new Vector3();
  3455. }
  3456. var direction = line.delta( v1 );
  3457. var denominator = this.normal.dot( direction );
  3458. if ( denominator === 0 ) {
  3459. // line is coplanar, return origin
  3460. if ( this.distanceToPoint( line.start ) === 0 ) {
  3461. return target.copy( line.start );
  3462. }
  3463. // Unsure if this is the correct method to handle this case.
  3464. return undefined;
  3465. }
  3466. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  3467. if ( t < 0 || t > 1 ) {
  3468. return undefined;
  3469. }
  3470. return target.copy( direction ).multiplyScalar( t ).add( line.start );
  3471. };
  3472. }(),
  3473. intersectsLine: function ( line ) {
  3474. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  3475. var startSign = this.distanceToPoint( line.start );
  3476. var endSign = this.distanceToPoint( line.end );
  3477. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  3478. },
  3479. intersectsBox: function ( box ) {
  3480. return box.intersectsPlane( this );
  3481. },
  3482. intersectsSphere: function ( sphere ) {
  3483. return sphere.intersectsPlane( this );
  3484. },
  3485. coplanarPoint: function ( target ) {
  3486. if ( target === undefined ) {
  3487. console.warn( 'THREE.Plane: .coplanarPoint() target is now required' );
  3488. target = new Vector3();
  3489. }
  3490. return target.copy( this.normal ).multiplyScalar( - this.constant );
  3491. },
  3492. applyMatrix4: function () {
  3493. var v1 = new Vector3();
  3494. var m1 = new Matrix3();
  3495. return function applyMatrix4( matrix, optionalNormalMatrix ) {
  3496. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  3497. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  3498. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  3499. this.constant = - referencePoint.dot( normal );
  3500. return this;
  3501. };
  3502. }(),
  3503. translate: function ( offset ) {
  3504. this.constant -= offset.dot( this.normal );
  3505. return this;
  3506. },
  3507. equals: function ( plane ) {
  3508. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  3509. }
  3510. } );
  3511. /**
  3512. * @author mrdoob / http://mrdoob.com/
  3513. * @author alteredq / http://alteredqualia.com/
  3514. * @author bhouston / http://clara.io
  3515. */
  3516. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  3517. this.planes = [
  3518. ( p0 !== undefined ) ? p0 : new Plane(),
  3519. ( p1 !== undefined ) ? p1 : new Plane(),
  3520. ( p2 !== undefined ) ? p2 : new Plane(),
  3521. ( p3 !== undefined ) ? p3 : new Plane(),
  3522. ( p4 !== undefined ) ? p4 : new Plane(),
  3523. ( p5 !== undefined ) ? p5 : new Plane()
  3524. ];
  3525. }
  3526. Object.assign( Frustum.prototype, {
  3527. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3528. var planes = this.planes;
  3529. planes[ 0 ].copy( p0 );
  3530. planes[ 1 ].copy( p1 );
  3531. planes[ 2 ].copy( p2 );
  3532. planes[ 3 ].copy( p3 );
  3533. planes[ 4 ].copy( p4 );
  3534. planes[ 5 ].copy( p5 );
  3535. return this;
  3536. },
  3537. clone: function () {
  3538. return new this.constructor().copy( this );
  3539. },
  3540. copy: function ( frustum ) {
  3541. var planes = this.planes;
  3542. for ( var i = 0; i < 6; i ++ ) {
  3543. planes[ i ].copy( frustum.planes[ i ] );
  3544. }
  3545. return this;
  3546. },
  3547. setFromMatrix: function ( m ) {
  3548. var planes = this.planes;
  3549. var me = m.elements;
  3550. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3551. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3552. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3553. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3554. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3555. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3556. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3557. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3558. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3559. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3560. return this;
  3561. },
  3562. intersectsObject: function () {
  3563. var sphere = new Sphere();
  3564. return function intersectsObject( object ) {
  3565. var geometry = object.geometry;
  3566. if ( geometry.boundingSphere === null )
  3567. geometry.computeBoundingSphere();
  3568. sphere.copy( geometry.boundingSphere )
  3569. .applyMatrix4( object.matrixWorld );
  3570. return this.intersectsSphere( sphere );
  3571. };
  3572. }(),
  3573. intersectsSprite: function () {
  3574. var sphere = new Sphere();
  3575. return function intersectsSprite( sprite ) {
  3576. sphere.center.set( 0, 0, 0 );
  3577. sphere.radius = 0.7071067811865476;
  3578. sphere.applyMatrix4( sprite.matrixWorld );
  3579. return this.intersectsSphere( sphere );
  3580. };
  3581. }(),
  3582. intersectsSphere: function ( sphere ) {
  3583. var planes = this.planes;
  3584. var center = sphere.center;
  3585. var negRadius = - sphere.radius;
  3586. for ( var i = 0; i < 6; i ++ ) {
  3587. var distance = planes[ i ].distanceToPoint( center );
  3588. if ( distance < negRadius ) {
  3589. return false;
  3590. }
  3591. }
  3592. return true;
  3593. },
  3594. intersectsBox: function () {
  3595. var p = new Vector3();
  3596. return function intersectsBox( box ) {
  3597. var planes = this.planes;
  3598. for ( var i = 0; i < 6; i ++ ) {
  3599. var plane = planes[ i ];
  3600. // corner at max distance
  3601. p.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3602. p.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3603. p.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3604. if ( plane.distanceToPoint( p ) < 0 ) {
  3605. return false;
  3606. }
  3607. }
  3608. return true;
  3609. };
  3610. }(),
  3611. containsPoint: function ( point ) {
  3612. var planes = this.planes;
  3613. for ( var i = 0; i < 6; i ++ ) {
  3614. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3615. return false;
  3616. }
  3617. }
  3618. return true;
  3619. }
  3620. } );
  3621. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  3622. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  3623. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  3624. 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";
  3625. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  3626. var begin_vertex = "vec3 transformed = vec3( position );";
  3627. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );";
  3628. var bsdfs = "float punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n#else\n\tif( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t}\n\treturn 1.0;\n#endif\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\tfloat gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\treturn 1.0 / ( gl * gv );\n}\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\tfloat D = D_GGX( alpha, dotNH );\n\treturn F * ( G * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\nvec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\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\tvec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n\treturn specularColor * AB.x + AB.y;\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}";
  3629. 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";
  3630. 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";
  3631. 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";
  3632. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvarying vec3 vViewPosition;\n#endif";
  3633. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif";
  3634. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  3635. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  3636. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  3637. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  3638. 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}";
  3639. 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";
  3640. var defaultnormal_vertex = "vec3 transformedNormal = normalMatrix * objectNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif";
  3641. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  3642. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif";
  3643. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  3644. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  3645. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  3646. 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 = value.rgb * cLogLuvM;\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 = Xp_Y_XYZp.rgb * cLogLuvInverseM;\n\treturn vec4( max( vRGB, 0.0 ), 1.0 );\n}";
  3647. 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";
  3648. 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";
  3649. 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";
  3650. 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";
  3651. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = -mvPosition.z;\n#endif";
  3652. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  3653. 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";
  3654. 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";
  3655. 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";
  3656. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\treflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif";
  3657. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  3658. 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 );\n#ifdef DOUBLE_SIDED\n\tvLightBack = 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\tvLightFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );\n\t\t#endif\n\t}\n#endif";
  3659. var lights_pars_begin = "uniform vec3 ambientLightColor;\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treturn irradiance;\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tint shadow;\n\t\tfloat shadowBias;\n\t\tfloat shadowRadius;\n\t\tvec2 shadowMapSize;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tdirectLight.color = directionalLight.color;\n\t\tdirectLight.direction = directionalLight.direction;\n\t\tdirectLight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tint shadow;\n\t\tfloat shadowBias;\n\t\tfloat shadowRadius;\n\t\tvec2 shadowMapSize;\n\t\tfloat shadowCameraNear;\n\t\tfloat shadowCameraFar;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = pointLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tdirectLight.color = pointLight.color;\n\t\tdirectLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );\n\t\tdirectLight.visible = ( directLight.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t\tint shadow;\n\t\tfloat shadowBias;\n\t\tfloat shadowRadius;\n\t\tvec2 shadowMapSize;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = spotLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tfloat angleCos = dot( directLight.direction, spotLight.direction );\n\t\tif ( angleCos > spotLight.coneCos ) {\n\t\t\tfloat spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\t\tdirectLight.color = spotLight.color;\n\t\t\tdirectLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tdirectLight.visible = true;\n\t\t} else {\n\t\t\tdirectLight.color = vec3( 0.0 );\n\t\t\tdirectLight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {\n\t\tfloat dotNL = dot( geometry.normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tirradiance *= PI;\n\t\t#endif\n\t\treturn irradiance;\n\t}\n#endif";
  3660. 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";
  3661. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  3662. 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)";
  3663. 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";
  3664. 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\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 clearCoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\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\treflectedLight.indirectSpecular += ( 1.0 - clearCoatDHR ) * radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );\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}";
  3665. var lights_fragment_begin = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = normalize( vViewPosition );\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointDirectLightIrradiance( pointLight, geometry, directLight );\n\t\t#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( pointLight.shadow, directLight.visible ) ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotDirectLightIrradiance( spotLight, geometry, directLight );\n\t\t#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( spotLight.shadow, directLight.visible ) ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalDirectLightIrradiance( directionalLight, geometry, directLight );\n\t\t#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( directionalLight.shadow, directLight.visible ) ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t}\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearCoatRadiance = vec3( 0.0 );\n#endif";
  3666. 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";
  3667. 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, clearCoatRadiance, geometry, material, reflectedLight );\n#endif";
  3668. var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";
  3669. var logdepthbuf_pars_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n#endif";
  3670. 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";
  3671. 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";
  3672. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  3673. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  3674. 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";
  3675. var map_particle_pars_fragment = "#ifdef USE_MAP\n\tuniform mat3 uvTransform;\n\tuniform sampler2D map;\n#endif";
  3676. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  3677. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  3678. 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";
  3679. 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";
  3680. 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";
  3681. 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#endif";
  3682. 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\tnormal = perturbNormal2Arb( -vViewPosition, normal );\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif";
  3683. 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";
  3684. 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}";
  3685. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  3686. var project_vertex = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = projectionMatrix * mvPosition;";
  3687. var dithering_fragment = "#if defined( DITHERING )\n gl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  3688. 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";
  3689. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  3690. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  3691. var shadowmap_pars_fragment = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHTS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHTS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHTS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n\t}\n\tfloat texture2DShadowLerp( sampler2D depths, vec2 size, vec2 uv, float compare ) {\n\t\tconst vec2 offset = vec2( 0.0, 1.0 );\n\t\tvec2 texelSize = vec2( 1.0 ) / size;\n\t\tvec2 centroidUV = floor( uv * size + 0.5 ) / size;\n\t\tfloat lb = texture2DCompare( depths, centroidUV + texelSize * offset.xx, compare );\n\t\tfloat lt = texture2DCompare( depths, centroidUV + texelSize * offset.xy, compare );\n\t\tfloat rb = texture2DCompare( depths, centroidUV + texelSize * offset.yx, compare );\n\t\tfloat rt = texture2DCompare( depths, centroidUV + texelSize * offset.yy, compare );\n\t\tvec2 f = fract( uv * size + 0.5 );\n\t\tfloat a = mix( lb, lt, f.y );\n\t\tfloat b = mix( rb, rt, f.y );\n\t\tfloat c = mix( a, b, f.x );\n\t\treturn c;\n\t}\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\tfloat shadow = 1.0;\n\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\tshadowCoord.z += shadowBias;\n\t\tbvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n\t\tbool inFrustum = all( inFrustumVec );\n\t\tbvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\t\tbool frustumTest = all( frustumTestVec );\n\t\tif ( frustumTest ) {\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tshadow = (\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#endif\n\t\t}\n\t\treturn shadow;\n\t}\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\n\t\tvec3 absV = abs( v );\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n\t\tabsV *= scaleToCube;\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\t\tvec2 planar = v.xy;\n\t\tfloat almostATexel = 1.5 * texelSizeY;\n\t\tfloat almostOne = 1.0 - almostATexel;\n\t\tif ( absV.z >= almostOne ) {\n\t\t\tif ( v.z > 0.0 )\n\t\t\t\tplanar.x = 4.0 - v.x;\n\t\t} else if ( absV.x >= almostOne ) {\n\t\t\tfloat signX = sign( v.x );\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\n\t\t} else if ( absV.y >= almostOne ) {\n\t\t\tfloat signY = sign( v.y );\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\n\t\t\tplanar.y = v.z * signY - 2.0;\n\t\t}\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\t}\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tfloat dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\t\tdp += shadowBias;\n\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\treturn (\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\treturn texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t#endif\n\t}\n#endif";
  3692. 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";
  3693. 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";
  3694. 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}";
  3695. 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";
  3696. var skinning_pars_vertex = "#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform sampler2D boneTexture;\n\t\tuniform int boneTextureSize;\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tfloat j = i * 4.0;\n\t\t\tfloat x = mod( j, float( boneTextureSize ) );\n\t\t\tfloat y = floor( j / float( boneTextureSize ) );\n\t\t\tfloat dx = 1.0 / float( boneTextureSize );\n\t\t\tfloat dy = 1.0 / float( boneTextureSize );\n\t\t\ty = dy * ( y + 0.5 );\n\t\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\t\t\treturn bone;\n\t\t}\n\t#else\n\t\tuniform mat4 boneMatrices[ MAX_BONES ];\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tmat4 bone = boneMatrices[ int(i) ];\n\t\t\treturn bone;\n\t\t}\n\t#endif\n#endif";
  3697. 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";
  3698. 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#endif";
  3699. 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";
  3700. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  3701. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  3702. 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}";
  3703. 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";
  3704. 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";
  3705. 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";
  3706. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  3707. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n#endif";
  3708. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = uv2;\n#endif";
  3709. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n#endif";
  3710. 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}";
  3711. 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}";
  3712. 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}";
  3713. 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}";
  3714. 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}";
  3715. 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}";
  3716. 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}";
  3717. 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}";
  3718. 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}";
  3719. 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}";
  3720. 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}";
  3721. 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}";
  3722. 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}";
  3723. 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}";
  3724. var meshlambert_frag = "uniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\nvarying vec3 vLightFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\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#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}";
  3725. var meshlambert_vert = "#define LAMBERT\nvarying vec3 vLightFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <bsdfs>\n#include <lights_pars_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}";
  3726. 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}";
  3727. 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}";
  3728. 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}";
  3729. 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}";
  3730. 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#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}";
  3731. var meshphysical_vert = "#define PHYSICAL\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 <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 <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  3732. 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#endif\n#include <packing>\n#include <uv_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n}";
  3733. 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#endif\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}";
  3734. 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}";
  3735. 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}";
  3736. 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}";
  3737. 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}";
  3738. 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}";
  3739. 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}";
  3740. var ShaderChunk = {
  3741. alphamap_fragment: alphamap_fragment,
  3742. alphamap_pars_fragment: alphamap_pars_fragment,
  3743. alphatest_fragment: alphatest_fragment,
  3744. aomap_fragment: aomap_fragment,
  3745. aomap_pars_fragment: aomap_pars_fragment,
  3746. begin_vertex: begin_vertex,
  3747. beginnormal_vertex: beginnormal_vertex,
  3748. bsdfs: bsdfs,
  3749. bumpmap_pars_fragment: bumpmap_pars_fragment,
  3750. clipping_planes_fragment: clipping_planes_fragment,
  3751. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  3752. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  3753. clipping_planes_vertex: clipping_planes_vertex,
  3754. color_fragment: color_fragment,
  3755. color_pars_fragment: color_pars_fragment,
  3756. color_pars_vertex: color_pars_vertex,
  3757. color_vertex: color_vertex,
  3758. common: common,
  3759. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  3760. defaultnormal_vertex: defaultnormal_vertex,
  3761. displacementmap_pars_vertex: displacementmap_pars_vertex,
  3762. displacementmap_vertex: displacementmap_vertex,
  3763. emissivemap_fragment: emissivemap_fragment,
  3764. emissivemap_pars_fragment: emissivemap_pars_fragment,
  3765. encodings_fragment: encodings_fragment,
  3766. encodings_pars_fragment: encodings_pars_fragment,
  3767. envmap_fragment: envmap_fragment,
  3768. envmap_pars_fragment: envmap_pars_fragment,
  3769. envmap_pars_vertex: envmap_pars_vertex,
  3770. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  3771. envmap_vertex: envmap_vertex,
  3772. fog_vertex: fog_vertex,
  3773. fog_pars_vertex: fog_pars_vertex,
  3774. fog_fragment: fog_fragment,
  3775. fog_pars_fragment: fog_pars_fragment,
  3776. gradientmap_pars_fragment: gradientmap_pars_fragment,
  3777. lightmap_fragment: lightmap_fragment,
  3778. lightmap_pars_fragment: lightmap_pars_fragment,
  3779. lights_lambert_vertex: lights_lambert_vertex,
  3780. lights_pars_begin: lights_pars_begin,
  3781. lights_phong_fragment: lights_phong_fragment,
  3782. lights_phong_pars_fragment: lights_phong_pars_fragment,
  3783. lights_physical_fragment: lights_physical_fragment,
  3784. lights_physical_pars_fragment: lights_physical_pars_fragment,
  3785. lights_fragment_begin: lights_fragment_begin,
  3786. lights_fragment_maps: lights_fragment_maps,
  3787. lights_fragment_end: lights_fragment_end,
  3788. logdepthbuf_fragment: logdepthbuf_fragment,
  3789. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  3790. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  3791. logdepthbuf_vertex: logdepthbuf_vertex,
  3792. map_fragment: map_fragment,
  3793. map_pars_fragment: map_pars_fragment,
  3794. map_particle_fragment: map_particle_fragment,
  3795. map_particle_pars_fragment: map_particle_pars_fragment,
  3796. metalnessmap_fragment: metalnessmap_fragment,
  3797. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  3798. morphnormal_vertex: morphnormal_vertex,
  3799. morphtarget_pars_vertex: morphtarget_pars_vertex,
  3800. morphtarget_vertex: morphtarget_vertex,
  3801. normal_fragment_begin: normal_fragment_begin,
  3802. normal_fragment_maps: normal_fragment_maps,
  3803. normalmap_pars_fragment: normalmap_pars_fragment,
  3804. packing: packing,
  3805. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  3806. project_vertex: project_vertex,
  3807. dithering_fragment: dithering_fragment,
  3808. dithering_pars_fragment: dithering_pars_fragment,
  3809. roughnessmap_fragment: roughnessmap_fragment,
  3810. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  3811. shadowmap_pars_fragment: shadowmap_pars_fragment,
  3812. shadowmap_pars_vertex: shadowmap_pars_vertex,
  3813. shadowmap_vertex: shadowmap_vertex,
  3814. shadowmask_pars_fragment: shadowmask_pars_fragment,
  3815. skinbase_vertex: skinbase_vertex,
  3816. skinning_pars_vertex: skinning_pars_vertex,
  3817. skinning_vertex: skinning_vertex,
  3818. skinnormal_vertex: skinnormal_vertex,
  3819. specularmap_fragment: specularmap_fragment,
  3820. specularmap_pars_fragment: specularmap_pars_fragment,
  3821. tonemapping_fragment: tonemapping_fragment,
  3822. tonemapping_pars_fragment: tonemapping_pars_fragment,
  3823. uv_pars_fragment: uv_pars_fragment,
  3824. uv_pars_vertex: uv_pars_vertex,
  3825. uv_vertex: uv_vertex,
  3826. uv2_pars_fragment: uv2_pars_fragment,
  3827. uv2_pars_vertex: uv2_pars_vertex,
  3828. uv2_vertex: uv2_vertex,
  3829. worldpos_vertex: worldpos_vertex,
  3830. background_frag: background_frag,
  3831. background_vert: background_vert,
  3832. cube_frag: cube_frag,
  3833. cube_vert: cube_vert,
  3834. depth_frag: depth_frag,
  3835. depth_vert: depth_vert,
  3836. distanceRGBA_frag: distanceRGBA_frag,
  3837. distanceRGBA_vert: distanceRGBA_vert,
  3838. equirect_frag: equirect_frag,
  3839. equirect_vert: equirect_vert,
  3840. linedashed_frag: linedashed_frag,
  3841. linedashed_vert: linedashed_vert,
  3842. meshbasic_frag: meshbasic_frag,
  3843. meshbasic_vert: meshbasic_vert,
  3844. meshlambert_frag: meshlambert_frag,
  3845. meshlambert_vert: meshlambert_vert,
  3846. meshmatcap_frag: meshmatcap_frag,
  3847. meshmatcap_vert: meshmatcap_vert,
  3848. meshphong_frag: meshphong_frag,
  3849. meshphong_vert: meshphong_vert,
  3850. meshphysical_frag: meshphysical_frag,
  3851. meshphysical_vert: meshphysical_vert,
  3852. normal_frag: normal_frag,
  3853. normal_vert: normal_vert,
  3854. points_frag: points_frag,
  3855. points_vert: points_vert,
  3856. shadow_frag: shadow_frag,
  3857. shadow_vert: shadow_vert,
  3858. sprite_frag: sprite_frag,
  3859. sprite_vert: sprite_vert
  3860. };
  3861. /**
  3862. * Uniform Utilities
  3863. */
  3864. function cloneUniforms( src ) {
  3865. var dst = {};
  3866. for ( var u in src ) {
  3867. dst[ u ] = {};
  3868. for ( var p in src[ u ] ) {
  3869. var property = src[ u ][ p ];
  3870. if ( property && ( property.isColor ||
  3871. property.isMatrix3 || property.isMatrix4 ||
  3872. property.isVector2 || property.isVector3 || property.isVector4 ||
  3873. property.isTexture ) ) {
  3874. dst[ u ][ p ] = property.clone();
  3875. } else if ( Array.isArray( property ) ) {
  3876. dst[ u ][ p ] = property.slice();
  3877. } else {
  3878. dst[ u ][ p ] = property;
  3879. }
  3880. }
  3881. }
  3882. return dst;
  3883. }
  3884. function mergeUniforms( uniforms ) {
  3885. var merged = {};
  3886. for ( var u = 0; u < uniforms.length; u ++ ) {
  3887. var tmp = cloneUniforms( uniforms[ u ] );
  3888. for ( var p in tmp ) {
  3889. merged[ p ] = tmp[ p ];
  3890. }
  3891. }
  3892. return merged;
  3893. }
  3894. // Legacy
  3895. var UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  3896. /**
  3897. * @author mrdoob / http://mrdoob.com/
  3898. */
  3899. var ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  3900. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  3901. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  3902. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  3903. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  3904. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  3905. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  3906. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  3907. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  3908. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  3909. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  3910. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  3911. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  3912. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  3913. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  3914. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  3915. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  3916. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  3917. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  3918. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  3919. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  3920. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  3921. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  3922. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  3923. function Color( r, g, b ) {
  3924. if ( g === undefined && b === undefined ) {
  3925. // r is THREE.Color, hex or string
  3926. return this.set( r );
  3927. }
  3928. return this.setRGB( r, g, b );
  3929. }
  3930. Object.assign( Color.prototype, {
  3931. isColor: true,
  3932. r: 1, g: 1, b: 1,
  3933. set: function ( value ) {
  3934. if ( value && value.isColor ) {
  3935. this.copy( value );
  3936. } else if ( typeof value === 'number' ) {
  3937. this.setHex( value );
  3938. } else if ( typeof value === 'string' ) {
  3939. this.setStyle( value );
  3940. }
  3941. return this;
  3942. },
  3943. setScalar: function ( scalar ) {
  3944. this.r = scalar;
  3945. this.g = scalar;
  3946. this.b = scalar;
  3947. return this;
  3948. },
  3949. setHex: function ( hex ) {
  3950. hex = Math.floor( hex );
  3951. this.r = ( hex >> 16 & 255 ) / 255;
  3952. this.g = ( hex >> 8 & 255 ) / 255;
  3953. this.b = ( hex & 255 ) / 255;
  3954. return this;
  3955. },
  3956. setRGB: function ( r, g, b ) {
  3957. this.r = r;
  3958. this.g = g;
  3959. this.b = b;
  3960. return this;
  3961. },
  3962. setHSL: function () {
  3963. function hue2rgb( p, q, t ) {
  3964. if ( t < 0 ) t += 1;
  3965. if ( t > 1 ) t -= 1;
  3966. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  3967. if ( t < 1 / 2 ) return q;
  3968. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  3969. return p;
  3970. }
  3971. return function setHSL( h, s, l ) {
  3972. // h,s,l ranges are in 0.0 - 1.0
  3973. h = _Math.euclideanModulo( h, 1 );
  3974. s = _Math.clamp( s, 0, 1 );
  3975. l = _Math.clamp( l, 0, 1 );
  3976. if ( s === 0 ) {
  3977. this.r = this.g = this.b = l;
  3978. } else {
  3979. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  3980. var q = ( 2 * l ) - p;
  3981. this.r = hue2rgb( q, p, h + 1 / 3 );
  3982. this.g = hue2rgb( q, p, h );
  3983. this.b = hue2rgb( q, p, h - 1 / 3 );
  3984. }
  3985. return this;
  3986. };
  3987. }(),
  3988. setStyle: function ( style ) {
  3989. function handleAlpha( string ) {
  3990. if ( string === undefined ) return;
  3991. if ( parseFloat( string ) < 1 ) {
  3992. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  3993. }
  3994. }
  3995. var m;
  3996. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  3997. // rgb / hsl
  3998. var color;
  3999. var name = m[ 1 ];
  4000. var components = m[ 2 ];
  4001. switch ( name ) {
  4002. case 'rgb':
  4003. case 'rgba':
  4004. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4005. // rgb(255,0,0) rgba(255,0,0,0.5)
  4006. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  4007. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  4008. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  4009. handleAlpha( color[ 5 ] );
  4010. return this;
  4011. }
  4012. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4013. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  4014. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  4015. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  4016. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  4017. handleAlpha( color[ 5 ] );
  4018. return this;
  4019. }
  4020. break;
  4021. case 'hsl':
  4022. case 'hsla':
  4023. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4024. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  4025. var h = parseFloat( color[ 1 ] ) / 360;
  4026. var s = parseInt( color[ 2 ], 10 ) / 100;
  4027. var l = parseInt( color[ 3 ], 10 ) / 100;
  4028. handleAlpha( color[ 5 ] );
  4029. return this.setHSL( h, s, l );
  4030. }
  4031. break;
  4032. }
  4033. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  4034. // hex color
  4035. var hex = m[ 1 ];
  4036. var size = hex.length;
  4037. if ( size === 3 ) {
  4038. // #ff0
  4039. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  4040. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  4041. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  4042. return this;
  4043. } else if ( size === 6 ) {
  4044. // #ff0000
  4045. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  4046. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  4047. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  4048. return this;
  4049. }
  4050. }
  4051. if ( style && style.length > 0 ) {
  4052. // color keywords
  4053. var hex = ColorKeywords[ style ];
  4054. if ( hex !== undefined ) {
  4055. // red
  4056. this.setHex( hex );
  4057. } else {
  4058. // unknown color
  4059. console.warn( 'THREE.Color: Unknown color ' + style );
  4060. }
  4061. }
  4062. return this;
  4063. },
  4064. clone: function () {
  4065. return new this.constructor( this.r, this.g, this.b );
  4066. },
  4067. copy: function ( color ) {
  4068. this.r = color.r;
  4069. this.g = color.g;
  4070. this.b = color.b;
  4071. return this;
  4072. },
  4073. copyGammaToLinear: function ( color, gammaFactor ) {
  4074. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4075. this.r = Math.pow( color.r, gammaFactor );
  4076. this.g = Math.pow( color.g, gammaFactor );
  4077. this.b = Math.pow( color.b, gammaFactor );
  4078. return this;
  4079. },
  4080. copyLinearToGamma: function ( color, gammaFactor ) {
  4081. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4082. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  4083. this.r = Math.pow( color.r, safeInverse );
  4084. this.g = Math.pow( color.g, safeInverse );
  4085. this.b = Math.pow( color.b, safeInverse );
  4086. return this;
  4087. },
  4088. convertGammaToLinear: function ( gammaFactor ) {
  4089. this.copyGammaToLinear( this, gammaFactor );
  4090. return this;
  4091. },
  4092. convertLinearToGamma: function ( gammaFactor ) {
  4093. this.copyLinearToGamma( this, gammaFactor );
  4094. return this;
  4095. },
  4096. copySRGBToLinear: function () {
  4097. function SRGBToLinear( c ) {
  4098. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  4099. }
  4100. return function copySRGBToLinear( color ) {
  4101. this.r = SRGBToLinear( color.r );
  4102. this.g = SRGBToLinear( color.g );
  4103. this.b = SRGBToLinear( color.b );
  4104. return this;
  4105. };
  4106. }(),
  4107. copyLinearToSRGB: function () {
  4108. function LinearToSRGB( c ) {
  4109. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  4110. }
  4111. return function copyLinearToSRGB( color ) {
  4112. this.r = LinearToSRGB( color.r );
  4113. this.g = LinearToSRGB( color.g );
  4114. this.b = LinearToSRGB( color.b );
  4115. return this;
  4116. };
  4117. }(),
  4118. convertSRGBToLinear: function () {
  4119. this.copySRGBToLinear( this );
  4120. return this;
  4121. },
  4122. convertLinearToSRGB: function () {
  4123. this.copyLinearToSRGB( this );
  4124. return this;
  4125. },
  4126. getHex: function () {
  4127. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  4128. },
  4129. getHexString: function () {
  4130. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  4131. },
  4132. getHSL: function ( target ) {
  4133. // h,s,l ranges are in 0.0 - 1.0
  4134. if ( target === undefined ) {
  4135. console.warn( 'THREE.Color: .getHSL() target is now required' );
  4136. target = { h: 0, s: 0, l: 0 };
  4137. }
  4138. var r = this.r, g = this.g, b = this.b;
  4139. var max = Math.max( r, g, b );
  4140. var min = Math.min( r, g, b );
  4141. var hue, saturation;
  4142. var lightness = ( min + max ) / 2.0;
  4143. if ( min === max ) {
  4144. hue = 0;
  4145. saturation = 0;
  4146. } else {
  4147. var delta = max - min;
  4148. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  4149. switch ( max ) {
  4150. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  4151. case g: hue = ( b - r ) / delta + 2; break;
  4152. case b: hue = ( r - g ) / delta + 4; break;
  4153. }
  4154. hue /= 6;
  4155. }
  4156. target.h = hue;
  4157. target.s = saturation;
  4158. target.l = lightness;
  4159. return target;
  4160. },
  4161. getStyle: function () {
  4162. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  4163. },
  4164. offsetHSL: function () {
  4165. var hsl = {};
  4166. return function ( h, s, l ) {
  4167. this.getHSL( hsl );
  4168. hsl.h += h; hsl.s += s; hsl.l += l;
  4169. this.setHSL( hsl.h, hsl.s, hsl.l );
  4170. return this;
  4171. };
  4172. }(),
  4173. add: function ( color ) {
  4174. this.r += color.r;
  4175. this.g += color.g;
  4176. this.b += color.b;
  4177. return this;
  4178. },
  4179. addColors: function ( color1, color2 ) {
  4180. this.r = color1.r + color2.r;
  4181. this.g = color1.g + color2.g;
  4182. this.b = color1.b + color2.b;
  4183. return this;
  4184. },
  4185. addScalar: function ( s ) {
  4186. this.r += s;
  4187. this.g += s;
  4188. this.b += s;
  4189. return this;
  4190. },
  4191. sub: function ( color ) {
  4192. this.r = Math.max( 0, this.r - color.r );
  4193. this.g = Math.max( 0, this.g - color.g );
  4194. this.b = Math.max( 0, this.b - color.b );
  4195. return this;
  4196. },
  4197. multiply: function ( color ) {
  4198. this.r *= color.r;
  4199. this.g *= color.g;
  4200. this.b *= color.b;
  4201. return this;
  4202. },
  4203. multiplyScalar: function ( s ) {
  4204. this.r *= s;
  4205. this.g *= s;
  4206. this.b *= s;
  4207. return this;
  4208. },
  4209. lerp: function ( color, alpha ) {
  4210. this.r += ( color.r - this.r ) * alpha;
  4211. this.g += ( color.g - this.g ) * alpha;
  4212. this.b += ( color.b - this.b ) * alpha;
  4213. return this;
  4214. },
  4215. lerpHSL: function () {
  4216. var hslA = { h: 0, s: 0, l: 0 };
  4217. var hslB = { h: 0, s: 0, l: 0 };
  4218. return function lerpHSL( color, alpha ) {
  4219. this.getHSL( hslA );
  4220. color.getHSL( hslB );
  4221. var h = _Math.lerp( hslA.h, hslB.h, alpha );
  4222. var s = _Math.lerp( hslA.s, hslB.s, alpha );
  4223. var l = _Math.lerp( hslA.l, hslB.l, alpha );
  4224. this.setHSL( h, s, l );
  4225. return this;
  4226. };
  4227. }(),
  4228. equals: function ( c ) {
  4229. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  4230. },
  4231. fromArray: function ( array, offset ) {
  4232. if ( offset === undefined ) offset = 0;
  4233. this.r = array[ offset ];
  4234. this.g = array[ offset + 1 ];
  4235. this.b = array[ offset + 2 ];
  4236. return this;
  4237. },
  4238. toArray: function ( array, offset ) {
  4239. if ( array === undefined ) array = [];
  4240. if ( offset === undefined ) offset = 0;
  4241. array[ offset ] = this.r;
  4242. array[ offset + 1 ] = this.g;
  4243. array[ offset + 2 ] = this.b;
  4244. return array;
  4245. },
  4246. toJSON: function () {
  4247. return this.getHex();
  4248. }
  4249. } );
  4250. /**
  4251. * Uniforms library for shared webgl shaders
  4252. */
  4253. var UniformsLib = {
  4254. common: {
  4255. diffuse: { value: new Color( 0xeeeeee ) },
  4256. opacity: { value: 1.0 },
  4257. map: { value: null },
  4258. uvTransform: { value: new Matrix3() },
  4259. alphaMap: { value: null },
  4260. },
  4261. specularmap: {
  4262. specularMap: { value: null },
  4263. },
  4264. envmap: {
  4265. envMap: { value: null },
  4266. flipEnvMap: { value: - 1 },
  4267. reflectivity: { value: 1.0 },
  4268. refractionRatio: { value: 0.98 },
  4269. maxMipLevel: { value: 0 }
  4270. },
  4271. aomap: {
  4272. aoMap: { value: null },
  4273. aoMapIntensity: { value: 1 }
  4274. },
  4275. lightmap: {
  4276. lightMap: { value: null },
  4277. lightMapIntensity: { value: 1 }
  4278. },
  4279. emissivemap: {
  4280. emissiveMap: { value: null }
  4281. },
  4282. bumpmap: {
  4283. bumpMap: { value: null },
  4284. bumpScale: { value: 1 }
  4285. },
  4286. normalmap: {
  4287. normalMap: { value: null },
  4288. normalScale: { value: new Vector2( 1, 1 ) }
  4289. },
  4290. displacementmap: {
  4291. displacementMap: { value: null },
  4292. displacementScale: { value: 1 },
  4293. displacementBias: { value: 0 }
  4294. },
  4295. roughnessmap: {
  4296. roughnessMap: { value: null }
  4297. },
  4298. metalnessmap: {
  4299. metalnessMap: { value: null }
  4300. },
  4301. gradientmap: {
  4302. gradientMap: { value: null }
  4303. },
  4304. fog: {
  4305. fogDensity: { value: 0.00025 },
  4306. fogNear: { value: 1 },
  4307. fogFar: { value: 2000 },
  4308. fogColor: { value: new Color( 0xffffff ) }
  4309. },
  4310. lights: {
  4311. ambientLightColor: { value: [] },
  4312. directionalLights: { value: [], properties: {
  4313. direction: {},
  4314. color: {},
  4315. shadow: {},
  4316. shadowBias: {},
  4317. shadowRadius: {},
  4318. shadowMapSize: {}
  4319. } },
  4320. directionalShadowMap: { value: [] },
  4321. directionalShadowMatrix: { value: [] },
  4322. spotLights: { value: [], properties: {
  4323. color: {},
  4324. position: {},
  4325. direction: {},
  4326. distance: {},
  4327. coneCos: {},
  4328. penumbraCos: {},
  4329. decay: {},
  4330. shadow: {},
  4331. shadowBias: {},
  4332. shadowRadius: {},
  4333. shadowMapSize: {}
  4334. } },
  4335. spotShadowMap: { value: [] },
  4336. spotShadowMatrix: { value: [] },
  4337. pointLights: { value: [], properties: {
  4338. color: {},
  4339. position: {},
  4340. decay: {},
  4341. distance: {},
  4342. shadow: {},
  4343. shadowBias: {},
  4344. shadowRadius: {},
  4345. shadowMapSize: {},
  4346. shadowCameraNear: {},
  4347. shadowCameraFar: {}
  4348. } },
  4349. pointShadowMap: { value: [] },
  4350. pointShadowMatrix: { value: [] },
  4351. hemisphereLights: { value: [], properties: {
  4352. direction: {},
  4353. skyColor: {},
  4354. groundColor: {}
  4355. } },
  4356. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  4357. rectAreaLights: { value: [], properties: {
  4358. color: {},
  4359. position: {},
  4360. width: {},
  4361. height: {}
  4362. } }
  4363. },
  4364. points: {
  4365. diffuse: { value: new Color( 0xeeeeee ) },
  4366. opacity: { value: 1.0 },
  4367. size: { value: 1.0 },
  4368. scale: { value: 1.0 },
  4369. map: { value: null },
  4370. uvTransform: { value: new Matrix3() }
  4371. },
  4372. sprite: {
  4373. diffuse: { value: new Color( 0xeeeeee ) },
  4374. opacity: { value: 1.0 },
  4375. center: { value: new Vector2( 0.5, 0.5 ) },
  4376. rotation: { value: 0.0 },
  4377. map: { value: null },
  4378. uvTransform: { value: new Matrix3() }
  4379. }
  4380. };
  4381. /**
  4382. * @author alteredq / http://alteredqualia.com/
  4383. * @author mrdoob / http://mrdoob.com/
  4384. * @author mikael emtinger / http://gomo.se/
  4385. */
  4386. var ShaderLib = {
  4387. basic: {
  4388. uniforms: mergeUniforms( [
  4389. UniformsLib.common,
  4390. UniformsLib.specularmap,
  4391. UniformsLib.envmap,
  4392. UniformsLib.aomap,
  4393. UniformsLib.lightmap,
  4394. UniformsLib.fog
  4395. ] ),
  4396. vertexShader: ShaderChunk.meshbasic_vert,
  4397. fragmentShader: ShaderChunk.meshbasic_frag
  4398. },
  4399. lambert: {
  4400. uniforms: mergeUniforms( [
  4401. UniformsLib.common,
  4402. UniformsLib.specularmap,
  4403. UniformsLib.envmap,
  4404. UniformsLib.aomap,
  4405. UniformsLib.lightmap,
  4406. UniformsLib.emissivemap,
  4407. UniformsLib.fog,
  4408. UniformsLib.lights,
  4409. {
  4410. emissive: { value: new Color( 0x000000 ) }
  4411. }
  4412. ] ),
  4413. vertexShader: ShaderChunk.meshlambert_vert,
  4414. fragmentShader: ShaderChunk.meshlambert_frag
  4415. },
  4416. phong: {
  4417. uniforms: mergeUniforms( [
  4418. UniformsLib.common,
  4419. UniformsLib.specularmap,
  4420. UniformsLib.envmap,
  4421. UniformsLib.aomap,
  4422. UniformsLib.lightmap,
  4423. UniformsLib.emissivemap,
  4424. UniformsLib.bumpmap,
  4425. UniformsLib.normalmap,
  4426. UniformsLib.displacementmap,
  4427. UniformsLib.gradientmap,
  4428. UniformsLib.fog,
  4429. UniformsLib.lights,
  4430. {
  4431. emissive: { value: new Color( 0x000000 ) },
  4432. specular: { value: new Color( 0x111111 ) },
  4433. shininess: { value: 30 }
  4434. }
  4435. ] ),
  4436. vertexShader: ShaderChunk.meshphong_vert,
  4437. fragmentShader: ShaderChunk.meshphong_frag
  4438. },
  4439. standard: {
  4440. uniforms: mergeUniforms( [
  4441. UniformsLib.common,
  4442. UniformsLib.envmap,
  4443. UniformsLib.aomap,
  4444. UniformsLib.lightmap,
  4445. UniformsLib.emissivemap,
  4446. UniformsLib.bumpmap,
  4447. UniformsLib.normalmap,
  4448. UniformsLib.displacementmap,
  4449. UniformsLib.roughnessmap,
  4450. UniformsLib.metalnessmap,
  4451. UniformsLib.fog,
  4452. UniformsLib.lights,
  4453. {
  4454. emissive: { value: new Color( 0x000000 ) },
  4455. roughness: { value: 0.5 },
  4456. metalness: { value: 0.5 },
  4457. envMapIntensity: { value: 1 } // temporary
  4458. }
  4459. ] ),
  4460. vertexShader: ShaderChunk.meshphysical_vert,
  4461. fragmentShader: ShaderChunk.meshphysical_frag
  4462. },
  4463. matcap: {
  4464. uniforms: mergeUniforms( [
  4465. UniformsLib.common,
  4466. UniformsLib.bumpmap,
  4467. UniformsLib.normalmap,
  4468. UniformsLib.displacementmap,
  4469. UniformsLib.fog,
  4470. {
  4471. matcap: { value: null }
  4472. }
  4473. ] ),
  4474. vertexShader: ShaderChunk.meshmatcap_vert,
  4475. fragmentShader: ShaderChunk.meshmatcap_frag
  4476. },
  4477. points: {
  4478. uniforms: mergeUniforms( [
  4479. UniformsLib.points,
  4480. UniformsLib.fog
  4481. ] ),
  4482. vertexShader: ShaderChunk.points_vert,
  4483. fragmentShader: ShaderChunk.points_frag
  4484. },
  4485. dashed: {
  4486. uniforms: mergeUniforms( [
  4487. UniformsLib.common,
  4488. UniformsLib.fog,
  4489. {
  4490. scale: { value: 1 },
  4491. dashSize: { value: 1 },
  4492. totalSize: { value: 2 }
  4493. }
  4494. ] ),
  4495. vertexShader: ShaderChunk.linedashed_vert,
  4496. fragmentShader: ShaderChunk.linedashed_frag
  4497. },
  4498. depth: {
  4499. uniforms: mergeUniforms( [
  4500. UniformsLib.common,
  4501. UniformsLib.displacementmap
  4502. ] ),
  4503. vertexShader: ShaderChunk.depth_vert,
  4504. fragmentShader: ShaderChunk.depth_frag
  4505. },
  4506. normal: {
  4507. uniforms: mergeUniforms( [
  4508. UniformsLib.common,
  4509. UniformsLib.bumpmap,
  4510. UniformsLib.normalmap,
  4511. UniformsLib.displacementmap,
  4512. {
  4513. opacity: { value: 1.0 }
  4514. }
  4515. ] ),
  4516. vertexShader: ShaderChunk.normal_vert,
  4517. fragmentShader: ShaderChunk.normal_frag
  4518. },
  4519. sprite: {
  4520. uniforms: mergeUniforms( [
  4521. UniformsLib.sprite,
  4522. UniformsLib.fog
  4523. ] ),
  4524. vertexShader: ShaderChunk.sprite_vert,
  4525. fragmentShader: ShaderChunk.sprite_frag
  4526. },
  4527. background: {
  4528. uniforms: {
  4529. uvTransform: { value: new Matrix3() },
  4530. t2D: { value: null },
  4531. },
  4532. vertexShader: ShaderChunk.background_vert,
  4533. fragmentShader: ShaderChunk.background_frag
  4534. },
  4535. /* -------------------------------------------------------------------------
  4536. // Cube map shader
  4537. ------------------------------------------------------------------------- */
  4538. cube: {
  4539. uniforms: {
  4540. tCube: { value: null },
  4541. tFlip: { value: - 1 },
  4542. opacity: { value: 1.0 }
  4543. },
  4544. vertexShader: ShaderChunk.cube_vert,
  4545. fragmentShader: ShaderChunk.cube_frag
  4546. },
  4547. equirect: {
  4548. uniforms: {
  4549. tEquirect: { value: null },
  4550. },
  4551. vertexShader: ShaderChunk.equirect_vert,
  4552. fragmentShader: ShaderChunk.equirect_frag
  4553. },
  4554. distanceRGBA: {
  4555. uniforms: mergeUniforms( [
  4556. UniformsLib.common,
  4557. UniformsLib.displacementmap,
  4558. {
  4559. referencePosition: { value: new Vector3() },
  4560. nearDistance: { value: 1 },
  4561. farDistance: { value: 1000 }
  4562. }
  4563. ] ),
  4564. vertexShader: ShaderChunk.distanceRGBA_vert,
  4565. fragmentShader: ShaderChunk.distanceRGBA_frag
  4566. },
  4567. shadow: {
  4568. uniforms: mergeUniforms( [
  4569. UniformsLib.lights,
  4570. UniformsLib.fog,
  4571. {
  4572. color: { value: new Color( 0x00000 ) },
  4573. opacity: { value: 1.0 }
  4574. },
  4575. ] ),
  4576. vertexShader: ShaderChunk.shadow_vert,
  4577. fragmentShader: ShaderChunk.shadow_frag
  4578. }
  4579. };
  4580. ShaderLib.physical = {
  4581. uniforms: mergeUniforms( [
  4582. ShaderLib.standard.uniforms,
  4583. {
  4584. clearCoat: { value: 0 },
  4585. clearCoatRoughness: { value: 0 }
  4586. }
  4587. ] ),
  4588. vertexShader: ShaderChunk.meshphysical_vert,
  4589. fragmentShader: ShaderChunk.meshphysical_frag
  4590. };
  4591. /**
  4592. * @author mrdoob / http://mrdoob.com/
  4593. */
  4594. function WebGLAnimation() {
  4595. var context = null;
  4596. var isAnimating = false;
  4597. var animationLoop = null;
  4598. function onAnimationFrame( time, frame ) {
  4599. if ( isAnimating === false ) return;
  4600. animationLoop( time, frame );
  4601. context.requestAnimationFrame( onAnimationFrame );
  4602. }
  4603. return {
  4604. start: function () {
  4605. if ( isAnimating === true ) return;
  4606. if ( animationLoop === null ) return;
  4607. context.requestAnimationFrame( onAnimationFrame );
  4608. isAnimating = true;
  4609. },
  4610. stop: function () {
  4611. isAnimating = false;
  4612. },
  4613. setAnimationLoop: function ( callback ) {
  4614. animationLoop = callback;
  4615. },
  4616. setContext: function ( value ) {
  4617. context = value;
  4618. }
  4619. };
  4620. }
  4621. /**
  4622. * @author mrdoob / http://mrdoob.com/
  4623. */
  4624. function WebGLAttributes( gl ) {
  4625. var buffers = new WeakMap();
  4626. function createBuffer( attribute, bufferType ) {
  4627. var array = attribute.array;
  4628. var usage = attribute.dynamic ? 35048 : 35044;
  4629. var buffer = gl.createBuffer();
  4630. gl.bindBuffer( bufferType, buffer );
  4631. gl.bufferData( bufferType, array, usage );
  4632. attribute.onUploadCallback();
  4633. var type = 5126;
  4634. if ( array instanceof Float32Array ) {
  4635. type = 5126;
  4636. } else if ( array instanceof Float64Array ) {
  4637. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  4638. } else if ( array instanceof Uint16Array ) {
  4639. type = 5123;
  4640. } else if ( array instanceof Int16Array ) {
  4641. type = 5122;
  4642. } else if ( array instanceof Uint32Array ) {
  4643. type = 5125;
  4644. } else if ( array instanceof Int32Array ) {
  4645. type = 5124;
  4646. } else if ( array instanceof Int8Array ) {
  4647. type = 5120;
  4648. } else if ( array instanceof Uint8Array ) {
  4649. type = 5121;
  4650. }
  4651. return {
  4652. buffer: buffer,
  4653. type: type,
  4654. bytesPerElement: array.BYTES_PER_ELEMENT,
  4655. version: attribute.version
  4656. };
  4657. }
  4658. function updateBuffer( buffer, attribute, bufferType ) {
  4659. var array = attribute.array;
  4660. var updateRange = attribute.updateRange;
  4661. gl.bindBuffer( bufferType, buffer );
  4662. if ( attribute.dynamic === false ) {
  4663. gl.bufferData( bufferType, array, 35044 );
  4664. } else if ( updateRange.count === - 1 ) {
  4665. // Not using update ranges
  4666. gl.bufferSubData( bufferType, 0, array );
  4667. } else if ( updateRange.count === 0 ) {
  4668. 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.' );
  4669. } else {
  4670. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  4671. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  4672. updateRange.count = - 1; // reset range
  4673. }
  4674. }
  4675. //
  4676. function get( attribute ) {
  4677. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4678. return buffers.get( attribute );
  4679. }
  4680. function remove( attribute ) {
  4681. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4682. var data = buffers.get( attribute );
  4683. if ( data ) {
  4684. gl.deleteBuffer( data.buffer );
  4685. buffers.delete( attribute );
  4686. }
  4687. }
  4688. function update( attribute, bufferType ) {
  4689. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4690. var data = buffers.get( attribute );
  4691. if ( data === undefined ) {
  4692. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  4693. } else if ( data.version < attribute.version ) {
  4694. updateBuffer( data.buffer, attribute, bufferType );
  4695. data.version = attribute.version;
  4696. }
  4697. }
  4698. return {
  4699. get: get,
  4700. remove: remove,
  4701. update: update
  4702. };
  4703. }
  4704. /**
  4705. * @author mrdoob / http://mrdoob.com/
  4706. * @author alteredq / http://alteredqualia.com/
  4707. */
  4708. function Face3( a, b, c, normal, color, materialIndex ) {
  4709. this.a = a;
  4710. this.b = b;
  4711. this.c = c;
  4712. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  4713. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  4714. this.color = ( color && color.isColor ) ? color : new Color();
  4715. this.vertexColors = Array.isArray( color ) ? color : [];
  4716. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  4717. }
  4718. Object.assign( Face3.prototype, {
  4719. clone: function () {
  4720. return new this.constructor().copy( this );
  4721. },
  4722. copy: function ( source ) {
  4723. this.a = source.a;
  4724. this.b = source.b;
  4725. this.c = source.c;
  4726. this.normal.copy( source.normal );
  4727. this.color.copy( source.color );
  4728. this.materialIndex = source.materialIndex;
  4729. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  4730. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  4731. }
  4732. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  4733. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  4734. }
  4735. return this;
  4736. }
  4737. } );
  4738. /**
  4739. * @author mrdoob / http://mrdoob.com/
  4740. * @author WestLangley / http://github.com/WestLangley
  4741. * @author bhouston / http://clara.io
  4742. */
  4743. function Euler( x, y, z, order ) {
  4744. this._x = x || 0;
  4745. this._y = y || 0;
  4746. this._z = z || 0;
  4747. this._order = order || Euler.DefaultOrder;
  4748. }
  4749. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  4750. Euler.DefaultOrder = 'XYZ';
  4751. Object.defineProperties( Euler.prototype, {
  4752. x: {
  4753. get: function () {
  4754. return this._x;
  4755. },
  4756. set: function ( value ) {
  4757. this._x = value;
  4758. this.onChangeCallback();
  4759. }
  4760. },
  4761. y: {
  4762. get: function () {
  4763. return this._y;
  4764. },
  4765. set: function ( value ) {
  4766. this._y = value;
  4767. this.onChangeCallback();
  4768. }
  4769. },
  4770. z: {
  4771. get: function () {
  4772. return this._z;
  4773. },
  4774. set: function ( value ) {
  4775. this._z = value;
  4776. this.onChangeCallback();
  4777. }
  4778. },
  4779. order: {
  4780. get: function () {
  4781. return this._order;
  4782. },
  4783. set: function ( value ) {
  4784. this._order = value;
  4785. this.onChangeCallback();
  4786. }
  4787. }
  4788. } );
  4789. Object.assign( Euler.prototype, {
  4790. isEuler: true,
  4791. set: function ( x, y, z, order ) {
  4792. this._x = x;
  4793. this._y = y;
  4794. this._z = z;
  4795. this._order = order || this._order;
  4796. this.onChangeCallback();
  4797. return this;
  4798. },
  4799. clone: function () {
  4800. return new this.constructor( this._x, this._y, this._z, this._order );
  4801. },
  4802. copy: function ( euler ) {
  4803. this._x = euler._x;
  4804. this._y = euler._y;
  4805. this._z = euler._z;
  4806. this._order = euler._order;
  4807. this.onChangeCallback();
  4808. return this;
  4809. },
  4810. setFromRotationMatrix: function ( m, order, update ) {
  4811. var clamp = _Math.clamp;
  4812. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4813. var te = m.elements;
  4814. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  4815. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  4816. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  4817. order = order || this._order;
  4818. if ( order === 'XYZ' ) {
  4819. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  4820. if ( Math.abs( m13 ) < 0.99999 ) {
  4821. this._x = Math.atan2( - m23, m33 );
  4822. this._z = Math.atan2( - m12, m11 );
  4823. } else {
  4824. this._x = Math.atan2( m32, m22 );
  4825. this._z = 0;
  4826. }
  4827. } else if ( order === 'YXZ' ) {
  4828. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  4829. if ( Math.abs( m23 ) < 0.99999 ) {
  4830. this._y = Math.atan2( m13, m33 );
  4831. this._z = Math.atan2( m21, m22 );
  4832. } else {
  4833. this._y = Math.atan2( - m31, m11 );
  4834. this._z = 0;
  4835. }
  4836. } else if ( order === 'ZXY' ) {
  4837. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  4838. if ( Math.abs( m32 ) < 0.99999 ) {
  4839. this._y = Math.atan2( - m31, m33 );
  4840. this._z = Math.atan2( - m12, m22 );
  4841. } else {
  4842. this._y = 0;
  4843. this._z = Math.atan2( m21, m11 );
  4844. }
  4845. } else if ( order === 'ZYX' ) {
  4846. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  4847. if ( Math.abs( m31 ) < 0.99999 ) {
  4848. this._x = Math.atan2( m32, m33 );
  4849. this._z = Math.atan2( m21, m11 );
  4850. } else {
  4851. this._x = 0;
  4852. this._z = Math.atan2( - m12, m22 );
  4853. }
  4854. } else if ( order === 'YZX' ) {
  4855. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  4856. if ( Math.abs( m21 ) < 0.99999 ) {
  4857. this._x = Math.atan2( - m23, m22 );
  4858. this._y = Math.atan2( - m31, m11 );
  4859. } else {
  4860. this._x = 0;
  4861. this._y = Math.atan2( m13, m33 );
  4862. }
  4863. } else if ( order === 'XZY' ) {
  4864. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  4865. if ( Math.abs( m12 ) < 0.99999 ) {
  4866. this._x = Math.atan2( m32, m22 );
  4867. this._y = Math.atan2( m13, m11 );
  4868. } else {
  4869. this._x = Math.atan2( - m23, m33 );
  4870. this._y = 0;
  4871. }
  4872. } else {
  4873. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  4874. }
  4875. this._order = order;
  4876. if ( update !== false ) this.onChangeCallback();
  4877. return this;
  4878. },
  4879. setFromQuaternion: function () {
  4880. var matrix = new Matrix4();
  4881. return function setFromQuaternion( q, order, update ) {
  4882. matrix.makeRotationFromQuaternion( q );
  4883. return this.setFromRotationMatrix( matrix, order, update );
  4884. };
  4885. }(),
  4886. setFromVector3: function ( v, order ) {
  4887. return this.set( v.x, v.y, v.z, order || this._order );
  4888. },
  4889. reorder: function () {
  4890. // WARNING: this discards revolution information -bhouston
  4891. var q = new Quaternion();
  4892. return function reorder( newOrder ) {
  4893. q.setFromEuler( this );
  4894. return this.setFromQuaternion( q, newOrder );
  4895. };
  4896. }(),
  4897. equals: function ( euler ) {
  4898. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  4899. },
  4900. fromArray: function ( array ) {
  4901. this._x = array[ 0 ];
  4902. this._y = array[ 1 ];
  4903. this._z = array[ 2 ];
  4904. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  4905. this.onChangeCallback();
  4906. return this;
  4907. },
  4908. toArray: function ( array, offset ) {
  4909. if ( array === undefined ) array = [];
  4910. if ( offset === undefined ) offset = 0;
  4911. array[ offset ] = this._x;
  4912. array[ offset + 1 ] = this._y;
  4913. array[ offset + 2 ] = this._z;
  4914. array[ offset + 3 ] = this._order;
  4915. return array;
  4916. },
  4917. toVector3: function ( optionalResult ) {
  4918. if ( optionalResult ) {
  4919. return optionalResult.set( this._x, this._y, this._z );
  4920. } else {
  4921. return new Vector3( this._x, this._y, this._z );
  4922. }
  4923. },
  4924. onChange: function ( callback ) {
  4925. this.onChangeCallback = callback;
  4926. return this;
  4927. },
  4928. onChangeCallback: function () {}
  4929. } );
  4930. /**
  4931. * @author mrdoob / http://mrdoob.com/
  4932. */
  4933. function Layers() {
  4934. this.mask = 1 | 0;
  4935. }
  4936. Object.assign( Layers.prototype, {
  4937. set: function ( channel ) {
  4938. this.mask = 1 << channel | 0;
  4939. },
  4940. enable: function ( channel ) {
  4941. this.mask |= 1 << channel | 0;
  4942. },
  4943. toggle: function ( channel ) {
  4944. this.mask ^= 1 << channel | 0;
  4945. },
  4946. disable: function ( channel ) {
  4947. this.mask &= ~ ( 1 << channel | 0 );
  4948. },
  4949. test: function ( layers ) {
  4950. return ( this.mask & layers.mask ) !== 0;
  4951. }
  4952. } );
  4953. /**
  4954. * @author mrdoob / http://mrdoob.com/
  4955. * @author mikael emtinger / http://gomo.se/
  4956. * @author alteredq / http://alteredqualia.com/
  4957. * @author WestLangley / http://github.com/WestLangley
  4958. * @author elephantatwork / www.elephantatwork.ch
  4959. */
  4960. var object3DId = 0;
  4961. function Object3D() {
  4962. Object.defineProperty( this, 'id', { value: object3DId ++ } );
  4963. this.uuid = _Math.generateUUID();
  4964. this.name = '';
  4965. this.type = 'Object3D';
  4966. this.parent = null;
  4967. this.children = [];
  4968. this.up = Object3D.DefaultUp.clone();
  4969. var position = new Vector3();
  4970. var rotation = new Euler();
  4971. var quaternion = new Quaternion();
  4972. var scale = new Vector3( 1, 1, 1 );
  4973. function onRotationChange() {
  4974. quaternion.setFromEuler( rotation, false );
  4975. }
  4976. function onQuaternionChange() {
  4977. rotation.setFromQuaternion( quaternion, undefined, false );
  4978. }
  4979. rotation.onChange( onRotationChange );
  4980. quaternion.onChange( onQuaternionChange );
  4981. Object.defineProperties( this, {
  4982. position: {
  4983. configurable: true,
  4984. enumerable: true,
  4985. value: position
  4986. },
  4987. rotation: {
  4988. configurable: true,
  4989. enumerable: true,
  4990. value: rotation
  4991. },
  4992. quaternion: {
  4993. configurable: true,
  4994. enumerable: true,
  4995. value: quaternion
  4996. },
  4997. scale: {
  4998. configurable: true,
  4999. enumerable: true,
  5000. value: scale
  5001. },
  5002. modelViewMatrix: {
  5003. value: new Matrix4()
  5004. },
  5005. normalMatrix: {
  5006. value: new Matrix3()
  5007. }
  5008. } );
  5009. this.matrix = new Matrix4();
  5010. this.matrixWorld = new Matrix4();
  5011. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  5012. this.matrixWorldNeedsUpdate = false;
  5013. this.layers = new Layers();
  5014. this.visible = true;
  5015. this.castShadow = false;
  5016. this.receiveShadow = false;
  5017. this.frustumCulled = true;
  5018. this.renderOrder = 0;
  5019. this.userData = {};
  5020. }
  5021. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  5022. Object3D.DefaultMatrixAutoUpdate = true;
  5023. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5024. constructor: Object3D,
  5025. isObject3D: true,
  5026. onBeforeRender: function () {},
  5027. onAfterRender: function () {},
  5028. applyMatrix: function ( matrix ) {
  5029. this.matrix.multiplyMatrices( matrix, this.matrix );
  5030. this.matrix.decompose( this.position, this.quaternion, this.scale );
  5031. },
  5032. applyQuaternion: function ( q ) {
  5033. this.quaternion.premultiply( q );
  5034. return this;
  5035. },
  5036. setRotationFromAxisAngle: function ( axis, angle ) {
  5037. // assumes axis is normalized
  5038. this.quaternion.setFromAxisAngle( axis, angle );
  5039. },
  5040. setRotationFromEuler: function ( euler ) {
  5041. this.quaternion.setFromEuler( euler, true );
  5042. },
  5043. setRotationFromMatrix: function ( m ) {
  5044. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5045. this.quaternion.setFromRotationMatrix( m );
  5046. },
  5047. setRotationFromQuaternion: function ( q ) {
  5048. // assumes q is normalized
  5049. this.quaternion.copy( q );
  5050. },
  5051. rotateOnAxis: function () {
  5052. // rotate object on axis in object space
  5053. // axis is assumed to be normalized
  5054. var q1 = new Quaternion();
  5055. return function rotateOnAxis( axis, angle ) {
  5056. q1.setFromAxisAngle( axis, angle );
  5057. this.quaternion.multiply( q1 );
  5058. return this;
  5059. };
  5060. }(),
  5061. rotateOnWorldAxis: function () {
  5062. // rotate object on axis in world space
  5063. // axis is assumed to be normalized
  5064. // method assumes no rotated parent
  5065. var q1 = new Quaternion();
  5066. return function rotateOnWorldAxis( axis, angle ) {
  5067. q1.setFromAxisAngle( axis, angle );
  5068. this.quaternion.premultiply( q1 );
  5069. return this;
  5070. };
  5071. }(),
  5072. rotateX: function () {
  5073. var v1 = new Vector3( 1, 0, 0 );
  5074. return function rotateX( angle ) {
  5075. return this.rotateOnAxis( v1, angle );
  5076. };
  5077. }(),
  5078. rotateY: function () {
  5079. var v1 = new Vector3( 0, 1, 0 );
  5080. return function rotateY( angle ) {
  5081. return this.rotateOnAxis( v1, angle );
  5082. };
  5083. }(),
  5084. rotateZ: function () {
  5085. var v1 = new Vector3( 0, 0, 1 );
  5086. return function rotateZ( angle ) {
  5087. return this.rotateOnAxis( v1, angle );
  5088. };
  5089. }(),
  5090. translateOnAxis: function () {
  5091. // translate object by distance along axis in object space
  5092. // axis is assumed to be normalized
  5093. var v1 = new Vector3();
  5094. return function translateOnAxis( axis, distance ) {
  5095. v1.copy( axis ).applyQuaternion( this.quaternion );
  5096. this.position.add( v1.multiplyScalar( distance ) );
  5097. return this;
  5098. };
  5099. }(),
  5100. translateX: function () {
  5101. var v1 = new Vector3( 1, 0, 0 );
  5102. return function translateX( distance ) {
  5103. return this.translateOnAxis( v1, distance );
  5104. };
  5105. }(),
  5106. translateY: function () {
  5107. var v1 = new Vector3( 0, 1, 0 );
  5108. return function translateY( distance ) {
  5109. return this.translateOnAxis( v1, distance );
  5110. };
  5111. }(),
  5112. translateZ: function () {
  5113. var v1 = new Vector3( 0, 0, 1 );
  5114. return function translateZ( distance ) {
  5115. return this.translateOnAxis( v1, distance );
  5116. };
  5117. }(),
  5118. localToWorld: function ( vector ) {
  5119. return vector.applyMatrix4( this.matrixWorld );
  5120. },
  5121. worldToLocal: function () {
  5122. var m1 = new Matrix4();
  5123. return function worldToLocal( vector ) {
  5124. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5125. };
  5126. }(),
  5127. lookAt: function () {
  5128. // This method does not support objects having non-uniformly-scaled parent(s)
  5129. var q1 = new Quaternion();
  5130. var m1 = new Matrix4();
  5131. var target = new Vector3();
  5132. var position = new Vector3();
  5133. return function lookAt( x, y, z ) {
  5134. if ( x.isVector3 ) {
  5135. target.copy( x );
  5136. } else {
  5137. target.set( x, y, z );
  5138. }
  5139. var parent = this.parent;
  5140. this.updateWorldMatrix( true, false );
  5141. position.setFromMatrixPosition( this.matrixWorld );
  5142. if ( this.isCamera || this.isLight ) {
  5143. m1.lookAt( position, target, this.up );
  5144. } else {
  5145. m1.lookAt( target, position, this.up );
  5146. }
  5147. this.quaternion.setFromRotationMatrix( m1 );
  5148. if ( parent ) {
  5149. m1.extractRotation( parent.matrixWorld );
  5150. q1.setFromRotationMatrix( m1 );
  5151. this.quaternion.premultiply( q1.inverse() );
  5152. }
  5153. };
  5154. }(),
  5155. add: function ( object ) {
  5156. if ( arguments.length > 1 ) {
  5157. for ( var i = 0; i < arguments.length; i ++ ) {
  5158. this.add( arguments[ i ] );
  5159. }
  5160. return this;
  5161. }
  5162. if ( object === this ) {
  5163. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5164. return this;
  5165. }
  5166. if ( ( object && object.isObject3D ) ) {
  5167. if ( object.parent !== null ) {
  5168. object.parent.remove( object );
  5169. }
  5170. object.parent = this;
  5171. object.dispatchEvent( { type: 'added' } );
  5172. this.children.push( object );
  5173. } else {
  5174. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5175. }
  5176. return this;
  5177. },
  5178. remove: function ( object ) {
  5179. if ( arguments.length > 1 ) {
  5180. for ( var i = 0; i < arguments.length; i ++ ) {
  5181. this.remove( arguments[ i ] );
  5182. }
  5183. return this;
  5184. }
  5185. var index = this.children.indexOf( object );
  5186. if ( index !== - 1 ) {
  5187. object.parent = null;
  5188. object.dispatchEvent( { type: 'removed' } );
  5189. this.children.splice( index, 1 );
  5190. }
  5191. return this;
  5192. },
  5193. getObjectById: function ( id ) {
  5194. return this.getObjectByProperty( 'id', id );
  5195. },
  5196. getObjectByName: function ( name ) {
  5197. return this.getObjectByProperty( 'name', name );
  5198. },
  5199. getObjectByProperty: function ( name, value ) {
  5200. if ( this[ name ] === value ) return this;
  5201. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5202. var child = this.children[ i ];
  5203. var object = child.getObjectByProperty( name, value );
  5204. if ( object !== undefined ) {
  5205. return object;
  5206. }
  5207. }
  5208. return undefined;
  5209. },
  5210. getWorldPosition: function ( target ) {
  5211. if ( target === undefined ) {
  5212. console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
  5213. target = new Vector3();
  5214. }
  5215. this.updateMatrixWorld( true );
  5216. return target.setFromMatrixPosition( this.matrixWorld );
  5217. },
  5218. getWorldQuaternion: function () {
  5219. var position = new Vector3();
  5220. var scale = new Vector3();
  5221. return function getWorldQuaternion( target ) {
  5222. if ( target === undefined ) {
  5223. console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
  5224. target = new Quaternion();
  5225. }
  5226. this.updateMatrixWorld( true );
  5227. this.matrixWorld.decompose( position, target, scale );
  5228. return target;
  5229. };
  5230. }(),
  5231. getWorldScale: function () {
  5232. var position = new Vector3();
  5233. var quaternion = new Quaternion();
  5234. return function getWorldScale( target ) {
  5235. if ( target === undefined ) {
  5236. console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
  5237. target = new Vector3();
  5238. }
  5239. this.updateMatrixWorld( true );
  5240. this.matrixWorld.decompose( position, quaternion, target );
  5241. return target;
  5242. };
  5243. }(),
  5244. getWorldDirection: function ( target ) {
  5245. if ( target === undefined ) {
  5246. console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
  5247. target = new Vector3();
  5248. }
  5249. this.updateMatrixWorld( true );
  5250. var e = this.matrixWorld.elements;
  5251. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  5252. },
  5253. raycast: function () {},
  5254. traverse: function ( callback ) {
  5255. callback( this );
  5256. var children = this.children;
  5257. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5258. children[ i ].traverse( callback );
  5259. }
  5260. },
  5261. traverseVisible: function ( callback ) {
  5262. if ( this.visible === false ) return;
  5263. callback( this );
  5264. var children = this.children;
  5265. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5266. children[ i ].traverseVisible( callback );
  5267. }
  5268. },
  5269. traverseAncestors: function ( callback ) {
  5270. var parent = this.parent;
  5271. if ( parent !== null ) {
  5272. callback( parent );
  5273. parent.traverseAncestors( callback );
  5274. }
  5275. },
  5276. updateMatrix: function () {
  5277. this.matrix.compose( this.position, this.quaternion, this.scale );
  5278. this.matrixWorldNeedsUpdate = true;
  5279. },
  5280. updateMatrixWorld: function ( force ) {
  5281. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5282. if ( this.matrixWorldNeedsUpdate || force ) {
  5283. if ( this.parent === null ) {
  5284. this.matrixWorld.copy( this.matrix );
  5285. } else {
  5286. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5287. }
  5288. this.matrixWorldNeedsUpdate = false;
  5289. force = true;
  5290. }
  5291. // update children
  5292. var children = this.children;
  5293. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5294. children[ i ].updateMatrixWorld( force );
  5295. }
  5296. },
  5297. updateWorldMatrix: function ( updateParents, updateChildren ) {
  5298. var parent = this.parent;
  5299. if ( updateParents === true && parent !== null ) {
  5300. parent.updateWorldMatrix( true, false );
  5301. }
  5302. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5303. if ( this.parent === null ) {
  5304. this.matrixWorld.copy( this.matrix );
  5305. } else {
  5306. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5307. }
  5308. // update children
  5309. if ( updateChildren === true ) {
  5310. var children = this.children;
  5311. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5312. children[ i ].updateWorldMatrix( false, true );
  5313. }
  5314. }
  5315. },
  5316. toJSON: function ( meta ) {
  5317. // meta is a string when called from JSON.stringify
  5318. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  5319. var output = {};
  5320. // meta is a hash used to collect geometries, materials.
  5321. // not providing it implies that this is the root object
  5322. // being serialized.
  5323. if ( isRootObject ) {
  5324. // initialize meta obj
  5325. meta = {
  5326. geometries: {},
  5327. materials: {},
  5328. textures: {},
  5329. images: {},
  5330. shapes: {}
  5331. };
  5332. output.metadata = {
  5333. version: 4.5,
  5334. type: 'Object',
  5335. generator: 'Object3D.toJSON'
  5336. };
  5337. }
  5338. // standard Object3D serialization
  5339. var object = {};
  5340. object.uuid = this.uuid;
  5341. object.type = this.type;
  5342. if ( this.name !== '' ) object.name = this.name;
  5343. if ( this.castShadow === true ) object.castShadow = true;
  5344. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5345. if ( this.visible === false ) object.visible = false;
  5346. if ( this.frustumCulled === false ) object.frustumCulled = false;
  5347. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  5348. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5349. object.layers = this.layers.mask;
  5350. object.matrix = this.matrix.toArray();
  5351. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  5352. //
  5353. function serialize( library, element ) {
  5354. if ( library[ element.uuid ] === undefined ) {
  5355. library[ element.uuid ] = element.toJSON( meta );
  5356. }
  5357. return element.uuid;
  5358. }
  5359. if ( this.isMesh || this.isLine || this.isPoints ) {
  5360. object.geometry = serialize( meta.geometries, this.geometry );
  5361. var parameters = this.geometry.parameters;
  5362. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  5363. var shapes = parameters.shapes;
  5364. if ( Array.isArray( shapes ) ) {
  5365. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  5366. var shape = shapes[ i ];
  5367. serialize( meta.shapes, shape );
  5368. }
  5369. } else {
  5370. serialize( meta.shapes, shapes );
  5371. }
  5372. }
  5373. }
  5374. if ( this.material !== undefined ) {
  5375. if ( Array.isArray( this.material ) ) {
  5376. var uuids = [];
  5377. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  5378. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  5379. }
  5380. object.material = uuids;
  5381. } else {
  5382. object.material = serialize( meta.materials, this.material );
  5383. }
  5384. }
  5385. //
  5386. if ( this.children.length > 0 ) {
  5387. object.children = [];
  5388. for ( var i = 0; i < this.children.length; i ++ ) {
  5389. object.children.push( this.children[ i ].toJSON( meta ).object );
  5390. }
  5391. }
  5392. if ( isRootObject ) {
  5393. var geometries = extractFromCache( meta.geometries );
  5394. var materials = extractFromCache( meta.materials );
  5395. var textures = extractFromCache( meta.textures );
  5396. var images = extractFromCache( meta.images );
  5397. var shapes = extractFromCache( meta.shapes );
  5398. if ( geometries.length > 0 ) output.geometries = geometries;
  5399. if ( materials.length > 0 ) output.materials = materials;
  5400. if ( textures.length > 0 ) output.textures = textures;
  5401. if ( images.length > 0 ) output.images = images;
  5402. if ( shapes.length > 0 ) output.shapes = shapes;
  5403. }
  5404. output.object = object;
  5405. return output;
  5406. // extract data from the cache hash
  5407. // remove metadata on each item
  5408. // and return as array
  5409. function extractFromCache( cache ) {
  5410. var values = [];
  5411. for ( var key in cache ) {
  5412. var data = cache[ key ];
  5413. delete data.metadata;
  5414. values.push( data );
  5415. }
  5416. return values;
  5417. }
  5418. },
  5419. clone: function ( recursive ) {
  5420. return new this.constructor().copy( this, recursive );
  5421. },
  5422. copy: function ( source, recursive ) {
  5423. if ( recursive === undefined ) recursive = true;
  5424. this.name = source.name;
  5425. this.up.copy( source.up );
  5426. this.position.copy( source.position );
  5427. this.quaternion.copy( source.quaternion );
  5428. this.scale.copy( source.scale );
  5429. this.matrix.copy( source.matrix );
  5430. this.matrixWorld.copy( source.matrixWorld );
  5431. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5432. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5433. this.layers.mask = source.layers.mask;
  5434. this.visible = source.visible;
  5435. this.castShadow = source.castShadow;
  5436. this.receiveShadow = source.receiveShadow;
  5437. this.frustumCulled = source.frustumCulled;
  5438. this.renderOrder = source.renderOrder;
  5439. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5440. if ( recursive === true ) {
  5441. for ( var i = 0; i < source.children.length; i ++ ) {
  5442. var child = source.children[ i ];
  5443. this.add( child.clone() );
  5444. }
  5445. }
  5446. return this;
  5447. }
  5448. } );
  5449. /**
  5450. * @author mrdoob / http://mrdoob.com/
  5451. * @author kile / http://kile.stravaganza.org/
  5452. * @author alteredq / http://alteredqualia.com/
  5453. * @author mikael emtinger / http://gomo.se/
  5454. * @author zz85 / http://www.lab4games.net/zz85/blog
  5455. * @author bhouston / http://clara.io
  5456. */
  5457. var geometryId = 0; // Geometry uses even numbers as Id
  5458. function Geometry() {
  5459. Object.defineProperty( this, 'id', { value: geometryId += 2 } );
  5460. this.uuid = _Math.generateUUID();
  5461. this.name = '';
  5462. this.type = 'Geometry';
  5463. this.vertices = [];
  5464. this.colors = [];
  5465. this.faces = [];
  5466. this.faceVertexUvs = [[]];
  5467. this.morphTargets = [];
  5468. this.morphNormals = [];
  5469. this.skinWeights = [];
  5470. this.skinIndices = [];
  5471. this.lineDistances = [];
  5472. this.boundingBox = null;
  5473. this.boundingSphere = null;
  5474. // update flags
  5475. this.elementsNeedUpdate = false;
  5476. this.verticesNeedUpdate = false;
  5477. this.uvsNeedUpdate = false;
  5478. this.normalsNeedUpdate = false;
  5479. this.colorsNeedUpdate = false;
  5480. this.lineDistancesNeedUpdate = false;
  5481. this.groupsNeedUpdate = false;
  5482. }
  5483. Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5484. constructor: Geometry,
  5485. isGeometry: true,
  5486. applyMatrix: function ( matrix ) {
  5487. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5488. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5489. var vertex = this.vertices[ i ];
  5490. vertex.applyMatrix4( matrix );
  5491. }
  5492. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5493. var face = this.faces[ i ];
  5494. face.normal.applyMatrix3( normalMatrix ).normalize();
  5495. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5496. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5497. }
  5498. }
  5499. if ( this.boundingBox !== null ) {
  5500. this.computeBoundingBox();
  5501. }
  5502. if ( this.boundingSphere !== null ) {
  5503. this.computeBoundingSphere();
  5504. }
  5505. this.verticesNeedUpdate = true;
  5506. this.normalsNeedUpdate = true;
  5507. return this;
  5508. },
  5509. rotateX: function () {
  5510. // rotate geometry around world x-axis
  5511. var m1 = new Matrix4();
  5512. return function rotateX( angle ) {
  5513. m1.makeRotationX( angle );
  5514. this.applyMatrix( m1 );
  5515. return this;
  5516. };
  5517. }(),
  5518. rotateY: function () {
  5519. // rotate geometry around world y-axis
  5520. var m1 = new Matrix4();
  5521. return function rotateY( angle ) {
  5522. m1.makeRotationY( angle );
  5523. this.applyMatrix( m1 );
  5524. return this;
  5525. };
  5526. }(),
  5527. rotateZ: function () {
  5528. // rotate geometry around world z-axis
  5529. var m1 = new Matrix4();
  5530. return function rotateZ( angle ) {
  5531. m1.makeRotationZ( angle );
  5532. this.applyMatrix( m1 );
  5533. return this;
  5534. };
  5535. }(),
  5536. translate: function () {
  5537. // translate geometry
  5538. var m1 = new Matrix4();
  5539. return function translate( x, y, z ) {
  5540. m1.makeTranslation( x, y, z );
  5541. this.applyMatrix( m1 );
  5542. return this;
  5543. };
  5544. }(),
  5545. scale: function () {
  5546. // scale geometry
  5547. var m1 = new Matrix4();
  5548. return function scale( x, y, z ) {
  5549. m1.makeScale( x, y, z );
  5550. this.applyMatrix( m1 );
  5551. return this;
  5552. };
  5553. }(),
  5554. lookAt: function () {
  5555. var obj = new Object3D();
  5556. return function lookAt( vector ) {
  5557. obj.lookAt( vector );
  5558. obj.updateMatrix();
  5559. this.applyMatrix( obj.matrix );
  5560. };
  5561. }(),
  5562. fromBufferGeometry: function ( geometry ) {
  5563. var scope = this;
  5564. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5565. var attributes = geometry.attributes;
  5566. var positions = attributes.position.array;
  5567. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5568. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5569. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5570. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5571. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5572. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  5573. scope.vertices.push( new Vector3().fromArray( positions, i ) );
  5574. if ( colors !== undefined ) {
  5575. scope.colors.push( new Color().fromArray( colors, i ) );
  5576. }
  5577. }
  5578. function addFace( a, b, c, materialIndex ) {
  5579. var vertexColors = ( colors === undefined ) ? [] : [
  5580. scope.colors[ a ].clone(),
  5581. scope.colors[ b ].clone(),
  5582. scope.colors[ c ].clone() ];
  5583. var vertexNormals = ( normals === undefined ) ? [] : [
  5584. new Vector3().fromArray( normals, a * 3 ),
  5585. new Vector3().fromArray( normals, b * 3 ),
  5586. new Vector3().fromArray( normals, c * 3 )
  5587. ];
  5588. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  5589. scope.faces.push( face );
  5590. if ( uvs !== undefined ) {
  5591. scope.faceVertexUvs[ 0 ].push( [
  5592. new Vector2().fromArray( uvs, a * 2 ),
  5593. new Vector2().fromArray( uvs, b * 2 ),
  5594. new Vector2().fromArray( uvs, c * 2 )
  5595. ] );
  5596. }
  5597. if ( uvs2 !== undefined ) {
  5598. scope.faceVertexUvs[ 1 ].push( [
  5599. new Vector2().fromArray( uvs2, a * 2 ),
  5600. new Vector2().fromArray( uvs2, b * 2 ),
  5601. new Vector2().fromArray( uvs2, c * 2 )
  5602. ] );
  5603. }
  5604. }
  5605. var groups = geometry.groups;
  5606. if ( groups.length > 0 ) {
  5607. for ( var i = 0; i < groups.length; i ++ ) {
  5608. var group = groups[ i ];
  5609. var start = group.start;
  5610. var count = group.count;
  5611. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5612. if ( indices !== undefined ) {
  5613. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  5614. } else {
  5615. addFace( j, j + 1, j + 2, group.materialIndex );
  5616. }
  5617. }
  5618. }
  5619. } else {
  5620. if ( indices !== undefined ) {
  5621. for ( var i = 0; i < indices.length; i += 3 ) {
  5622. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5623. }
  5624. } else {
  5625. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  5626. addFace( i, i + 1, i + 2 );
  5627. }
  5628. }
  5629. }
  5630. this.computeFaceNormals();
  5631. if ( geometry.boundingBox !== null ) {
  5632. this.boundingBox = geometry.boundingBox.clone();
  5633. }
  5634. if ( geometry.boundingSphere !== null ) {
  5635. this.boundingSphere = geometry.boundingSphere.clone();
  5636. }
  5637. return this;
  5638. },
  5639. center: function () {
  5640. var offset = new Vector3();
  5641. return function center() {
  5642. this.computeBoundingBox();
  5643. this.boundingBox.getCenter( offset ).negate();
  5644. this.translate( offset.x, offset.y, offset.z );
  5645. return this;
  5646. };
  5647. }(),
  5648. normalize: function () {
  5649. this.computeBoundingSphere();
  5650. var center = this.boundingSphere.center;
  5651. var radius = this.boundingSphere.radius;
  5652. var s = radius === 0 ? 1 : 1.0 / radius;
  5653. var matrix = new Matrix4();
  5654. matrix.set(
  5655. s, 0, 0, - s * center.x,
  5656. 0, s, 0, - s * center.y,
  5657. 0, 0, s, - s * center.z,
  5658. 0, 0, 0, 1
  5659. );
  5660. this.applyMatrix( matrix );
  5661. return this;
  5662. },
  5663. computeFaceNormals: function () {
  5664. var cb = new Vector3(), ab = new Vector3();
  5665. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5666. var face = this.faces[ f ];
  5667. var vA = this.vertices[ face.a ];
  5668. var vB = this.vertices[ face.b ];
  5669. var vC = this.vertices[ face.c ];
  5670. cb.subVectors( vC, vB );
  5671. ab.subVectors( vA, vB );
  5672. cb.cross( ab );
  5673. cb.normalize();
  5674. face.normal.copy( cb );
  5675. }
  5676. },
  5677. computeVertexNormals: function ( areaWeighted ) {
  5678. if ( areaWeighted === undefined ) areaWeighted = true;
  5679. var v, vl, f, fl, face, vertices;
  5680. vertices = new Array( this.vertices.length );
  5681. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5682. vertices[ v ] = new Vector3();
  5683. }
  5684. if ( areaWeighted ) {
  5685. // vertex normals weighted by triangle areas
  5686. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5687. var vA, vB, vC;
  5688. var cb = new Vector3(), ab = new Vector3();
  5689. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5690. face = this.faces[ f ];
  5691. vA = this.vertices[ face.a ];
  5692. vB = this.vertices[ face.b ];
  5693. vC = this.vertices[ face.c ];
  5694. cb.subVectors( vC, vB );
  5695. ab.subVectors( vA, vB );
  5696. cb.cross( ab );
  5697. vertices[ face.a ].add( cb );
  5698. vertices[ face.b ].add( cb );
  5699. vertices[ face.c ].add( cb );
  5700. }
  5701. } else {
  5702. this.computeFaceNormals();
  5703. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5704. face = this.faces[ f ];
  5705. vertices[ face.a ].add( face.normal );
  5706. vertices[ face.b ].add( face.normal );
  5707. vertices[ face.c ].add( face.normal );
  5708. }
  5709. }
  5710. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5711. vertices[ v ].normalize();
  5712. }
  5713. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5714. face = this.faces[ f ];
  5715. var vertexNormals = face.vertexNormals;
  5716. if ( vertexNormals.length === 3 ) {
  5717. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5718. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5719. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5720. } else {
  5721. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5722. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5723. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5724. }
  5725. }
  5726. if ( this.faces.length > 0 ) {
  5727. this.normalsNeedUpdate = true;
  5728. }
  5729. },
  5730. computeFlatVertexNormals: function () {
  5731. var f, fl, face;
  5732. this.computeFaceNormals();
  5733. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5734. face = this.faces[ f ];
  5735. var vertexNormals = face.vertexNormals;
  5736. if ( vertexNormals.length === 3 ) {
  5737. vertexNormals[ 0 ].copy( face.normal );
  5738. vertexNormals[ 1 ].copy( face.normal );
  5739. vertexNormals[ 2 ].copy( face.normal );
  5740. } else {
  5741. vertexNormals[ 0 ] = face.normal.clone();
  5742. vertexNormals[ 1 ] = face.normal.clone();
  5743. vertexNormals[ 2 ] = face.normal.clone();
  5744. }
  5745. }
  5746. if ( this.faces.length > 0 ) {
  5747. this.normalsNeedUpdate = true;
  5748. }
  5749. },
  5750. computeMorphNormals: function () {
  5751. var i, il, f, fl, face;
  5752. // save original normals
  5753. // - create temp variables on first access
  5754. // otherwise just copy (for faster repeated calls)
  5755. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5756. face = this.faces[ f ];
  5757. if ( ! face.__originalFaceNormal ) {
  5758. face.__originalFaceNormal = face.normal.clone();
  5759. } else {
  5760. face.__originalFaceNormal.copy( face.normal );
  5761. }
  5762. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5763. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5764. if ( ! face.__originalVertexNormals[ i ] ) {
  5765. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5766. } else {
  5767. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5768. }
  5769. }
  5770. }
  5771. // use temp geometry to compute face and vertex normals for each morph
  5772. var tmpGeo = new Geometry();
  5773. tmpGeo.faces = this.faces;
  5774. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5775. // create on first access
  5776. if ( ! this.morphNormals[ i ] ) {
  5777. this.morphNormals[ i ] = {};
  5778. this.morphNormals[ i ].faceNormals = [];
  5779. this.morphNormals[ i ].vertexNormals = [];
  5780. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5781. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5782. var faceNormal, vertexNormals;
  5783. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5784. faceNormal = new Vector3();
  5785. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  5786. dstNormalsFace.push( faceNormal );
  5787. dstNormalsVertex.push( vertexNormals );
  5788. }
  5789. }
  5790. var morphNormals = this.morphNormals[ i ];
  5791. // set vertices to morph target
  5792. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5793. // compute morph normals
  5794. tmpGeo.computeFaceNormals();
  5795. tmpGeo.computeVertexNormals();
  5796. // store morph normals
  5797. var faceNormal, vertexNormals;
  5798. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5799. face = this.faces[ f ];
  5800. faceNormal = morphNormals.faceNormals[ f ];
  5801. vertexNormals = morphNormals.vertexNormals[ f ];
  5802. faceNormal.copy( face.normal );
  5803. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5804. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5805. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5806. }
  5807. }
  5808. // restore original normals
  5809. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5810. face = this.faces[ f ];
  5811. face.normal = face.__originalFaceNormal;
  5812. face.vertexNormals = face.__originalVertexNormals;
  5813. }
  5814. },
  5815. computeBoundingBox: function () {
  5816. if ( this.boundingBox === null ) {
  5817. this.boundingBox = new Box3();
  5818. }
  5819. this.boundingBox.setFromPoints( this.vertices );
  5820. },
  5821. computeBoundingSphere: function () {
  5822. if ( this.boundingSphere === null ) {
  5823. this.boundingSphere = new Sphere();
  5824. }
  5825. this.boundingSphere.setFromPoints( this.vertices );
  5826. },
  5827. merge: function ( geometry, matrix, materialIndexOffset ) {
  5828. if ( ! ( geometry && geometry.isGeometry ) ) {
  5829. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  5830. return;
  5831. }
  5832. var normalMatrix,
  5833. vertexOffset = this.vertices.length,
  5834. vertices1 = this.vertices,
  5835. vertices2 = geometry.vertices,
  5836. faces1 = this.faces,
  5837. faces2 = geometry.faces,
  5838. uvs1 = this.faceVertexUvs[ 0 ],
  5839. uvs2 = geometry.faceVertexUvs[ 0 ],
  5840. colors1 = this.colors,
  5841. colors2 = geometry.colors;
  5842. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  5843. if ( matrix !== undefined ) {
  5844. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5845. }
  5846. // vertices
  5847. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  5848. var vertex = vertices2[ i ];
  5849. var vertexCopy = vertex.clone();
  5850. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  5851. vertices1.push( vertexCopy );
  5852. }
  5853. // colors
  5854. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  5855. colors1.push( colors2[ i ].clone() );
  5856. }
  5857. // faces
  5858. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  5859. var face = faces2[ i ], faceCopy, normal, color,
  5860. faceVertexNormals = face.vertexNormals,
  5861. faceVertexColors = face.vertexColors;
  5862. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  5863. faceCopy.normal.copy( face.normal );
  5864. if ( normalMatrix !== undefined ) {
  5865. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  5866. }
  5867. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  5868. normal = faceVertexNormals[ j ].clone();
  5869. if ( normalMatrix !== undefined ) {
  5870. normal.applyMatrix3( normalMatrix ).normalize();
  5871. }
  5872. faceCopy.vertexNormals.push( normal );
  5873. }
  5874. faceCopy.color.copy( face.color );
  5875. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  5876. color = faceVertexColors[ j ];
  5877. faceCopy.vertexColors.push( color.clone() );
  5878. }
  5879. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  5880. faces1.push( faceCopy );
  5881. }
  5882. // uvs
  5883. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  5884. var uv = uvs2[ i ], uvCopy = [];
  5885. if ( uv === undefined ) {
  5886. continue;
  5887. }
  5888. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  5889. uvCopy.push( uv[ j ].clone() );
  5890. }
  5891. uvs1.push( uvCopy );
  5892. }
  5893. },
  5894. mergeMesh: function ( mesh ) {
  5895. if ( ! ( mesh && mesh.isMesh ) ) {
  5896. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  5897. return;
  5898. }
  5899. if ( mesh.matrixAutoUpdate ) mesh.updateMatrix();
  5900. this.merge( mesh.geometry, mesh.matrix );
  5901. },
  5902. /*
  5903. * Checks for duplicate vertices with hashmap.
  5904. * Duplicated vertices are removed
  5905. * and faces' vertices are updated.
  5906. */
  5907. mergeVertices: function () {
  5908. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  5909. var unique = [], changes = [];
  5910. var v, key;
  5911. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  5912. var precision = Math.pow( 10, precisionPoints );
  5913. var i, il, face;
  5914. var indices, j, jl;
  5915. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  5916. v = this.vertices[ i ];
  5917. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  5918. if ( verticesMap[ key ] === undefined ) {
  5919. verticesMap[ key ] = i;
  5920. unique.push( this.vertices[ i ] );
  5921. changes[ i ] = unique.length - 1;
  5922. } else {
  5923. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  5924. changes[ i ] = changes[ verticesMap[ key ] ];
  5925. }
  5926. }
  5927. // if faces are completely degenerate after merging vertices, we
  5928. // have to remove them from the geometry.
  5929. var faceIndicesToRemove = [];
  5930. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  5931. face = this.faces[ i ];
  5932. face.a = changes[ face.a ];
  5933. face.b = changes[ face.b ];
  5934. face.c = changes[ face.c ];
  5935. indices = [ face.a, face.b, face.c ];
  5936. // if any duplicate vertices are found in a Face3
  5937. // we have to remove the face as nothing can be saved
  5938. for ( var n = 0; n < 3; n ++ ) {
  5939. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  5940. faceIndicesToRemove.push( i );
  5941. break;
  5942. }
  5943. }
  5944. }
  5945. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  5946. var idx = faceIndicesToRemove[ i ];
  5947. this.faces.splice( idx, 1 );
  5948. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  5949. this.faceVertexUvs[ j ].splice( idx, 1 );
  5950. }
  5951. }
  5952. // Use unique set of vertices
  5953. var diff = this.vertices.length - unique.length;
  5954. this.vertices = unique;
  5955. return diff;
  5956. },
  5957. setFromPoints: function ( points ) {
  5958. this.vertices = [];
  5959. for ( var i = 0, l = points.length; i < l; i ++ ) {
  5960. var point = points[ i ];
  5961. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  5962. }
  5963. return this;
  5964. },
  5965. sortFacesByMaterialIndex: function () {
  5966. var faces = this.faces;
  5967. var length = faces.length;
  5968. // tag faces
  5969. for ( var i = 0; i < length; i ++ ) {
  5970. faces[ i ]._id = i;
  5971. }
  5972. // sort faces
  5973. function materialIndexSort( a, b ) {
  5974. return a.materialIndex - b.materialIndex;
  5975. }
  5976. faces.sort( materialIndexSort );
  5977. // sort uvs
  5978. var uvs1 = this.faceVertexUvs[ 0 ];
  5979. var uvs2 = this.faceVertexUvs[ 1 ];
  5980. var newUvs1, newUvs2;
  5981. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  5982. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  5983. for ( var i = 0; i < length; i ++ ) {
  5984. var id = faces[ i ]._id;
  5985. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  5986. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  5987. }
  5988. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  5989. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  5990. },
  5991. toJSON: function () {
  5992. var data = {
  5993. metadata: {
  5994. version: 4.5,
  5995. type: 'Geometry',
  5996. generator: 'Geometry.toJSON'
  5997. }
  5998. };
  5999. // standard Geometry serialization
  6000. data.uuid = this.uuid;
  6001. data.type = this.type;
  6002. if ( this.name !== '' ) data.name = this.name;
  6003. if ( this.parameters !== undefined ) {
  6004. var parameters = this.parameters;
  6005. for ( var key in parameters ) {
  6006. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6007. }
  6008. return data;
  6009. }
  6010. var vertices = [];
  6011. for ( var i = 0; i < this.vertices.length; i ++ ) {
  6012. var vertex = this.vertices[ i ];
  6013. vertices.push( vertex.x, vertex.y, vertex.z );
  6014. }
  6015. var faces = [];
  6016. var normals = [];
  6017. var normalsHash = {};
  6018. var colors = [];
  6019. var colorsHash = {};
  6020. var uvs = [];
  6021. var uvsHash = {};
  6022. for ( var i = 0; i < this.faces.length; i ++ ) {
  6023. var face = this.faces[ i ];
  6024. var hasMaterial = true;
  6025. var hasFaceUv = false; // deprecated
  6026. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  6027. var hasFaceNormal = face.normal.length() > 0;
  6028. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  6029. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  6030. var hasFaceVertexColor = face.vertexColors.length > 0;
  6031. var faceType = 0;
  6032. faceType = setBit( faceType, 0, 0 ); // isQuad
  6033. faceType = setBit( faceType, 1, hasMaterial );
  6034. faceType = setBit( faceType, 2, hasFaceUv );
  6035. faceType = setBit( faceType, 3, hasFaceVertexUv );
  6036. faceType = setBit( faceType, 4, hasFaceNormal );
  6037. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  6038. faceType = setBit( faceType, 6, hasFaceColor );
  6039. faceType = setBit( faceType, 7, hasFaceVertexColor );
  6040. faces.push( faceType );
  6041. faces.push( face.a, face.b, face.c );
  6042. faces.push( face.materialIndex );
  6043. if ( hasFaceVertexUv ) {
  6044. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  6045. faces.push(
  6046. getUvIndex( faceVertexUvs[ 0 ] ),
  6047. getUvIndex( faceVertexUvs[ 1 ] ),
  6048. getUvIndex( faceVertexUvs[ 2 ] )
  6049. );
  6050. }
  6051. if ( hasFaceNormal ) {
  6052. faces.push( getNormalIndex( face.normal ) );
  6053. }
  6054. if ( hasFaceVertexNormal ) {
  6055. var vertexNormals = face.vertexNormals;
  6056. faces.push(
  6057. getNormalIndex( vertexNormals[ 0 ] ),
  6058. getNormalIndex( vertexNormals[ 1 ] ),
  6059. getNormalIndex( vertexNormals[ 2 ] )
  6060. );
  6061. }
  6062. if ( hasFaceColor ) {
  6063. faces.push( getColorIndex( face.color ) );
  6064. }
  6065. if ( hasFaceVertexColor ) {
  6066. var vertexColors = face.vertexColors;
  6067. faces.push(
  6068. getColorIndex( vertexColors[ 0 ] ),
  6069. getColorIndex( vertexColors[ 1 ] ),
  6070. getColorIndex( vertexColors[ 2 ] )
  6071. );
  6072. }
  6073. }
  6074. function setBit( value, position, enabled ) {
  6075. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  6076. }
  6077. function getNormalIndex( normal ) {
  6078. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  6079. if ( normalsHash[ hash ] !== undefined ) {
  6080. return normalsHash[ hash ];
  6081. }
  6082. normalsHash[ hash ] = normals.length / 3;
  6083. normals.push( normal.x, normal.y, normal.z );
  6084. return normalsHash[ hash ];
  6085. }
  6086. function getColorIndex( color ) {
  6087. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6088. if ( colorsHash[ hash ] !== undefined ) {
  6089. return colorsHash[ hash ];
  6090. }
  6091. colorsHash[ hash ] = colors.length;
  6092. colors.push( color.getHex() );
  6093. return colorsHash[ hash ];
  6094. }
  6095. function getUvIndex( uv ) {
  6096. var hash = uv.x.toString() + uv.y.toString();
  6097. if ( uvsHash[ hash ] !== undefined ) {
  6098. return uvsHash[ hash ];
  6099. }
  6100. uvsHash[ hash ] = uvs.length / 2;
  6101. uvs.push( uv.x, uv.y );
  6102. return uvsHash[ hash ];
  6103. }
  6104. data.data = {};
  6105. data.data.vertices = vertices;
  6106. data.data.normals = normals;
  6107. if ( colors.length > 0 ) data.data.colors = colors;
  6108. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6109. data.data.faces = faces;
  6110. return data;
  6111. },
  6112. clone: function () {
  6113. /*
  6114. // Handle primitives
  6115. var parameters = this.parameters;
  6116. if ( parameters !== undefined ) {
  6117. var values = [];
  6118. for ( var key in parameters ) {
  6119. values.push( parameters[ key ] );
  6120. }
  6121. var geometry = Object.create( this.constructor.prototype );
  6122. this.constructor.apply( geometry, values );
  6123. return geometry;
  6124. }
  6125. return new this.constructor().copy( this );
  6126. */
  6127. return new Geometry().copy( this );
  6128. },
  6129. copy: function ( source ) {
  6130. var i, il, j, jl, k, kl;
  6131. // reset
  6132. this.vertices = [];
  6133. this.colors = [];
  6134. this.faces = [];
  6135. this.faceVertexUvs = [[]];
  6136. this.morphTargets = [];
  6137. this.morphNormals = [];
  6138. this.skinWeights = [];
  6139. this.skinIndices = [];
  6140. this.lineDistances = [];
  6141. this.boundingBox = null;
  6142. this.boundingSphere = null;
  6143. // name
  6144. this.name = source.name;
  6145. // vertices
  6146. var vertices = source.vertices;
  6147. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  6148. this.vertices.push( vertices[ i ].clone() );
  6149. }
  6150. // colors
  6151. var colors = source.colors;
  6152. for ( i = 0, il = colors.length; i < il; i ++ ) {
  6153. this.colors.push( colors[ i ].clone() );
  6154. }
  6155. // faces
  6156. var faces = source.faces;
  6157. for ( i = 0, il = faces.length; i < il; i ++ ) {
  6158. this.faces.push( faces[ i ].clone() );
  6159. }
  6160. // face vertex uvs
  6161. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6162. var faceVertexUvs = source.faceVertexUvs[ i ];
  6163. if ( this.faceVertexUvs[ i ] === undefined ) {
  6164. this.faceVertexUvs[ i ] = [];
  6165. }
  6166. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6167. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6168. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  6169. var uv = uvs[ k ];
  6170. uvsCopy.push( uv.clone() );
  6171. }
  6172. this.faceVertexUvs[ i ].push( uvsCopy );
  6173. }
  6174. }
  6175. // morph targets
  6176. var morphTargets = source.morphTargets;
  6177. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  6178. var morphTarget = {};
  6179. morphTarget.name = morphTargets[ i ].name;
  6180. // vertices
  6181. if ( morphTargets[ i ].vertices !== undefined ) {
  6182. morphTarget.vertices = [];
  6183. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  6184. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  6185. }
  6186. }
  6187. // normals
  6188. if ( morphTargets[ i ].normals !== undefined ) {
  6189. morphTarget.normals = [];
  6190. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  6191. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  6192. }
  6193. }
  6194. this.morphTargets.push( morphTarget );
  6195. }
  6196. // morph normals
  6197. var morphNormals = source.morphNormals;
  6198. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  6199. var morphNormal = {};
  6200. // vertex normals
  6201. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  6202. morphNormal.vertexNormals = [];
  6203. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  6204. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  6205. var destVertexNormal = {};
  6206. destVertexNormal.a = srcVertexNormal.a.clone();
  6207. destVertexNormal.b = srcVertexNormal.b.clone();
  6208. destVertexNormal.c = srcVertexNormal.c.clone();
  6209. morphNormal.vertexNormals.push( destVertexNormal );
  6210. }
  6211. }
  6212. // face normals
  6213. if ( morphNormals[ i ].faceNormals !== undefined ) {
  6214. morphNormal.faceNormals = [];
  6215. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  6216. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  6217. }
  6218. }
  6219. this.morphNormals.push( morphNormal );
  6220. }
  6221. // skin weights
  6222. var skinWeights = source.skinWeights;
  6223. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  6224. this.skinWeights.push( skinWeights[ i ].clone() );
  6225. }
  6226. // skin indices
  6227. var skinIndices = source.skinIndices;
  6228. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  6229. this.skinIndices.push( skinIndices[ i ].clone() );
  6230. }
  6231. // line distances
  6232. var lineDistances = source.lineDistances;
  6233. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  6234. this.lineDistances.push( lineDistances[ i ] );
  6235. }
  6236. // bounding box
  6237. var boundingBox = source.boundingBox;
  6238. if ( boundingBox !== null ) {
  6239. this.boundingBox = boundingBox.clone();
  6240. }
  6241. // bounding sphere
  6242. var boundingSphere = source.boundingSphere;
  6243. if ( boundingSphere !== null ) {
  6244. this.boundingSphere = boundingSphere.clone();
  6245. }
  6246. // update flags
  6247. this.elementsNeedUpdate = source.elementsNeedUpdate;
  6248. this.verticesNeedUpdate = source.verticesNeedUpdate;
  6249. this.uvsNeedUpdate = source.uvsNeedUpdate;
  6250. this.normalsNeedUpdate = source.normalsNeedUpdate;
  6251. this.colorsNeedUpdate = source.colorsNeedUpdate;
  6252. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  6253. this.groupsNeedUpdate = source.groupsNeedUpdate;
  6254. return this;
  6255. },
  6256. dispose: function () {
  6257. this.dispatchEvent( { type: 'dispose' } );
  6258. }
  6259. } );
  6260. /**
  6261. * @author mrdoob / http://mrdoob.com/
  6262. */
  6263. function BufferAttribute( array, itemSize, normalized ) {
  6264. if ( Array.isArray( array ) ) {
  6265. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6266. }
  6267. this.name = '';
  6268. this.array = array;
  6269. this.itemSize = itemSize;
  6270. this.count = array !== undefined ? array.length / itemSize : 0;
  6271. this.normalized = normalized === true;
  6272. this.dynamic = false;
  6273. this.updateRange = { offset: 0, count: - 1 };
  6274. this.version = 0;
  6275. }
  6276. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  6277. set: function ( value ) {
  6278. if ( value === true ) this.version ++;
  6279. }
  6280. } );
  6281. Object.assign( BufferAttribute.prototype, {
  6282. isBufferAttribute: true,
  6283. onUploadCallback: function () {},
  6284. setArray: function ( array ) {
  6285. if ( Array.isArray( array ) ) {
  6286. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6287. }
  6288. this.count = array !== undefined ? array.length / this.itemSize : 0;
  6289. this.array = array;
  6290. return this;
  6291. },
  6292. setDynamic: function ( value ) {
  6293. this.dynamic = value;
  6294. return this;
  6295. },
  6296. copy: function ( source ) {
  6297. this.name = source.name;
  6298. this.array = new source.array.constructor( source.array );
  6299. this.itemSize = source.itemSize;
  6300. this.count = source.count;
  6301. this.normalized = source.normalized;
  6302. this.dynamic = source.dynamic;
  6303. return this;
  6304. },
  6305. copyAt: function ( index1, attribute, index2 ) {
  6306. index1 *= this.itemSize;
  6307. index2 *= attribute.itemSize;
  6308. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  6309. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  6310. }
  6311. return this;
  6312. },
  6313. copyArray: function ( array ) {
  6314. this.array.set( array );
  6315. return this;
  6316. },
  6317. copyColorsArray: function ( colors ) {
  6318. var array = this.array, offset = 0;
  6319. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  6320. var color = colors[ i ];
  6321. if ( color === undefined ) {
  6322. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  6323. color = new Color();
  6324. }
  6325. array[ offset ++ ] = color.r;
  6326. array[ offset ++ ] = color.g;
  6327. array[ offset ++ ] = color.b;
  6328. }
  6329. return this;
  6330. },
  6331. copyVector2sArray: function ( vectors ) {
  6332. var array = this.array, offset = 0;
  6333. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6334. var vector = vectors[ i ];
  6335. if ( vector === undefined ) {
  6336. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  6337. vector = new Vector2();
  6338. }
  6339. array[ offset ++ ] = vector.x;
  6340. array[ offset ++ ] = vector.y;
  6341. }
  6342. return this;
  6343. },
  6344. copyVector3sArray: function ( vectors ) {
  6345. var array = this.array, offset = 0;
  6346. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6347. var vector = vectors[ i ];
  6348. if ( vector === undefined ) {
  6349. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  6350. vector = new Vector3();
  6351. }
  6352. array[ offset ++ ] = vector.x;
  6353. array[ offset ++ ] = vector.y;
  6354. array[ offset ++ ] = vector.z;
  6355. }
  6356. return this;
  6357. },
  6358. copyVector4sArray: function ( vectors ) {
  6359. var array = this.array, offset = 0;
  6360. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6361. var vector = vectors[ i ];
  6362. if ( vector === undefined ) {
  6363. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  6364. vector = new Vector4();
  6365. }
  6366. array[ offset ++ ] = vector.x;
  6367. array[ offset ++ ] = vector.y;
  6368. array[ offset ++ ] = vector.z;
  6369. array[ offset ++ ] = vector.w;
  6370. }
  6371. return this;
  6372. },
  6373. set: function ( value, offset ) {
  6374. if ( offset === undefined ) offset = 0;
  6375. this.array.set( value, offset );
  6376. return this;
  6377. },
  6378. getX: function ( index ) {
  6379. return this.array[ index * this.itemSize ];
  6380. },
  6381. setX: function ( index, x ) {
  6382. this.array[ index * this.itemSize ] = x;
  6383. return this;
  6384. },
  6385. getY: function ( index ) {
  6386. return this.array[ index * this.itemSize + 1 ];
  6387. },
  6388. setY: function ( index, y ) {
  6389. this.array[ index * this.itemSize + 1 ] = y;
  6390. return this;
  6391. },
  6392. getZ: function ( index ) {
  6393. return this.array[ index * this.itemSize + 2 ];
  6394. },
  6395. setZ: function ( index, z ) {
  6396. this.array[ index * this.itemSize + 2 ] = z;
  6397. return this;
  6398. },
  6399. getW: function ( index ) {
  6400. return this.array[ index * this.itemSize + 3 ];
  6401. },
  6402. setW: function ( index, w ) {
  6403. this.array[ index * this.itemSize + 3 ] = w;
  6404. return this;
  6405. },
  6406. setXY: function ( index, x, y ) {
  6407. index *= this.itemSize;
  6408. this.array[ index + 0 ] = x;
  6409. this.array[ index + 1 ] = y;
  6410. return this;
  6411. },
  6412. setXYZ: function ( index, x, y, z ) {
  6413. index *= this.itemSize;
  6414. this.array[ index + 0 ] = x;
  6415. this.array[ index + 1 ] = y;
  6416. this.array[ index + 2 ] = z;
  6417. return this;
  6418. },
  6419. setXYZW: function ( index, x, y, z, w ) {
  6420. index *= this.itemSize;
  6421. this.array[ index + 0 ] = x;
  6422. this.array[ index + 1 ] = y;
  6423. this.array[ index + 2 ] = z;
  6424. this.array[ index + 3 ] = w;
  6425. return this;
  6426. },
  6427. onUpload: function ( callback ) {
  6428. this.onUploadCallback = callback;
  6429. return this;
  6430. },
  6431. clone: function () {
  6432. return new this.constructor( this.array, this.itemSize ).copy( this );
  6433. }
  6434. } );
  6435. //
  6436. function Int8BufferAttribute( array, itemSize, normalized ) {
  6437. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  6438. }
  6439. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6440. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6441. function Uint8BufferAttribute( array, itemSize, normalized ) {
  6442. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  6443. }
  6444. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6445. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6446. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  6447. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  6448. }
  6449. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6450. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6451. function Int16BufferAttribute( array, itemSize, normalized ) {
  6452. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  6453. }
  6454. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6455. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6456. function Uint16BufferAttribute( array, itemSize, normalized ) {
  6457. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  6458. }
  6459. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6460. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6461. function Int32BufferAttribute( array, itemSize, normalized ) {
  6462. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  6463. }
  6464. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6465. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6466. function Uint32BufferAttribute( array, itemSize, normalized ) {
  6467. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  6468. }
  6469. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6470. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6471. function Float32BufferAttribute( array, itemSize, normalized ) {
  6472. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  6473. }
  6474. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6475. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6476. function Float64BufferAttribute( array, itemSize, normalized ) {
  6477. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  6478. }
  6479. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6480. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  6481. /**
  6482. * @author mrdoob / http://mrdoob.com/
  6483. */
  6484. function DirectGeometry() {
  6485. this.vertices = [];
  6486. this.normals = [];
  6487. this.colors = [];
  6488. this.uvs = [];
  6489. this.uvs2 = [];
  6490. this.groups = [];
  6491. this.morphTargets = {};
  6492. this.skinWeights = [];
  6493. this.skinIndices = [];
  6494. // this.lineDistances = [];
  6495. this.boundingBox = null;
  6496. this.boundingSphere = null;
  6497. // update flags
  6498. this.verticesNeedUpdate = false;
  6499. this.normalsNeedUpdate = false;
  6500. this.colorsNeedUpdate = false;
  6501. this.uvsNeedUpdate = false;
  6502. this.groupsNeedUpdate = false;
  6503. }
  6504. Object.assign( DirectGeometry.prototype, {
  6505. computeGroups: function ( geometry ) {
  6506. var group;
  6507. var groups = [];
  6508. var materialIndex = undefined;
  6509. var faces = geometry.faces;
  6510. for ( var i = 0; i < faces.length; i ++ ) {
  6511. var face = faces[ i ];
  6512. // materials
  6513. if ( face.materialIndex !== materialIndex ) {
  6514. materialIndex = face.materialIndex;
  6515. if ( group !== undefined ) {
  6516. group.count = ( i * 3 ) - group.start;
  6517. groups.push( group );
  6518. }
  6519. group = {
  6520. start: i * 3,
  6521. materialIndex: materialIndex
  6522. };
  6523. }
  6524. }
  6525. if ( group !== undefined ) {
  6526. group.count = ( i * 3 ) - group.start;
  6527. groups.push( group );
  6528. }
  6529. this.groups = groups;
  6530. },
  6531. fromGeometry: function ( geometry ) {
  6532. var faces = geometry.faces;
  6533. var vertices = geometry.vertices;
  6534. var faceVertexUvs = geometry.faceVertexUvs;
  6535. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6536. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6537. // morphs
  6538. var morphTargets = geometry.morphTargets;
  6539. var morphTargetsLength = morphTargets.length;
  6540. var morphTargetsPosition;
  6541. if ( morphTargetsLength > 0 ) {
  6542. morphTargetsPosition = [];
  6543. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6544. morphTargetsPosition[ i ] = {
  6545. name: morphTargets[ i ].name,
  6546. data: []
  6547. };
  6548. }
  6549. this.morphTargets.position = morphTargetsPosition;
  6550. }
  6551. var morphNormals = geometry.morphNormals;
  6552. var morphNormalsLength = morphNormals.length;
  6553. var morphTargetsNormal;
  6554. if ( morphNormalsLength > 0 ) {
  6555. morphTargetsNormal = [];
  6556. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6557. morphTargetsNormal[ i ] = {
  6558. name: morphNormals[ i ].name,
  6559. data: []
  6560. };
  6561. }
  6562. this.morphTargets.normal = morphTargetsNormal;
  6563. }
  6564. // skins
  6565. var skinIndices = geometry.skinIndices;
  6566. var skinWeights = geometry.skinWeights;
  6567. var hasSkinIndices = skinIndices.length === vertices.length;
  6568. var hasSkinWeights = skinWeights.length === vertices.length;
  6569. //
  6570. if ( vertices.length > 0 && faces.length === 0 ) {
  6571. console.error( 'THREE.DirectGeometry: Faceless geometries are not supported.' );
  6572. }
  6573. for ( var i = 0; i < faces.length; i ++ ) {
  6574. var face = faces[ i ];
  6575. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6576. var vertexNormals = face.vertexNormals;
  6577. if ( vertexNormals.length === 3 ) {
  6578. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6579. } else {
  6580. var normal = face.normal;
  6581. this.normals.push( normal, normal, normal );
  6582. }
  6583. var vertexColors = face.vertexColors;
  6584. if ( vertexColors.length === 3 ) {
  6585. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6586. } else {
  6587. var color = face.color;
  6588. this.colors.push( color, color, color );
  6589. }
  6590. if ( hasFaceVertexUv === true ) {
  6591. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6592. if ( vertexUvs !== undefined ) {
  6593. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6594. } else {
  6595. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6596. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  6597. }
  6598. }
  6599. if ( hasFaceVertexUv2 === true ) {
  6600. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6601. if ( vertexUvs !== undefined ) {
  6602. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6603. } else {
  6604. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6605. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  6606. }
  6607. }
  6608. // morphs
  6609. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6610. var morphTarget = morphTargets[ j ].vertices;
  6611. morphTargetsPosition[ j ].data.push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6612. }
  6613. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6614. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6615. morphTargetsNormal[ j ].data.push( morphNormal.a, morphNormal.b, morphNormal.c );
  6616. }
  6617. // skins
  6618. if ( hasSkinIndices ) {
  6619. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6620. }
  6621. if ( hasSkinWeights ) {
  6622. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6623. }
  6624. }
  6625. this.computeGroups( geometry );
  6626. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6627. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6628. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6629. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6630. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6631. return this;
  6632. }
  6633. } );
  6634. /**
  6635. * @author mrdoob / http://mrdoob.com/
  6636. */
  6637. function arrayMax( array ) {
  6638. if ( array.length === 0 ) return - Infinity;
  6639. var max = array[ 0 ];
  6640. for ( var i = 1, l = array.length; i < l; ++ i ) {
  6641. if ( array[ i ] > max ) max = array[ i ];
  6642. }
  6643. return max;
  6644. }
  6645. /**
  6646. * @author alteredq / http://alteredqualia.com/
  6647. * @author mrdoob / http://mrdoob.com/
  6648. */
  6649. var bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6650. function BufferGeometry() {
  6651. Object.defineProperty( this, 'id', { value: bufferGeometryId += 2 } );
  6652. this.uuid = _Math.generateUUID();
  6653. this.name = '';
  6654. this.type = 'BufferGeometry';
  6655. this.index = null;
  6656. this.attributes = {};
  6657. this.morphAttributes = {};
  6658. this.groups = [];
  6659. this.boundingBox = null;
  6660. this.boundingSphere = null;
  6661. this.drawRange = { start: 0, count: Infinity };
  6662. this.userData = {};
  6663. }
  6664. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  6665. constructor: BufferGeometry,
  6666. isBufferGeometry: true,
  6667. getIndex: function () {
  6668. return this.index;
  6669. },
  6670. setIndex: function ( index ) {
  6671. if ( Array.isArray( index ) ) {
  6672. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  6673. } else {
  6674. this.index = index;
  6675. }
  6676. },
  6677. addAttribute: function ( name, attribute ) {
  6678. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  6679. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6680. return this.addAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6681. }
  6682. if ( name === 'index' ) {
  6683. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6684. this.setIndex( attribute );
  6685. return this;
  6686. }
  6687. this.attributes[ name ] = attribute;
  6688. return this;
  6689. },
  6690. getAttribute: function ( name ) {
  6691. return this.attributes[ name ];
  6692. },
  6693. removeAttribute: function ( name ) {
  6694. delete this.attributes[ name ];
  6695. return this;
  6696. },
  6697. addGroup: function ( start, count, materialIndex ) {
  6698. this.groups.push( {
  6699. start: start,
  6700. count: count,
  6701. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6702. } );
  6703. },
  6704. clearGroups: function () {
  6705. this.groups = [];
  6706. },
  6707. setDrawRange: function ( start, count ) {
  6708. this.drawRange.start = start;
  6709. this.drawRange.count = count;
  6710. },
  6711. applyMatrix: function ( matrix ) {
  6712. var position = this.attributes.position;
  6713. if ( position !== undefined ) {
  6714. matrix.applyToBufferAttribute( position );
  6715. position.needsUpdate = true;
  6716. }
  6717. var normal = this.attributes.normal;
  6718. if ( normal !== undefined ) {
  6719. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6720. normalMatrix.applyToBufferAttribute( normal );
  6721. normal.needsUpdate = true;
  6722. }
  6723. if ( this.boundingBox !== null ) {
  6724. this.computeBoundingBox();
  6725. }
  6726. if ( this.boundingSphere !== null ) {
  6727. this.computeBoundingSphere();
  6728. }
  6729. return this;
  6730. },
  6731. rotateX: function () {
  6732. // rotate geometry around world x-axis
  6733. var m1 = new Matrix4();
  6734. return function rotateX( angle ) {
  6735. m1.makeRotationX( angle );
  6736. this.applyMatrix( m1 );
  6737. return this;
  6738. };
  6739. }(),
  6740. rotateY: function () {
  6741. // rotate geometry around world y-axis
  6742. var m1 = new Matrix4();
  6743. return function rotateY( angle ) {
  6744. m1.makeRotationY( angle );
  6745. this.applyMatrix( m1 );
  6746. return this;
  6747. };
  6748. }(),
  6749. rotateZ: function () {
  6750. // rotate geometry around world z-axis
  6751. var m1 = new Matrix4();
  6752. return function rotateZ( angle ) {
  6753. m1.makeRotationZ( angle );
  6754. this.applyMatrix( m1 );
  6755. return this;
  6756. };
  6757. }(),
  6758. translate: function () {
  6759. // translate geometry
  6760. var m1 = new Matrix4();
  6761. return function translate( x, y, z ) {
  6762. m1.makeTranslation( x, y, z );
  6763. this.applyMatrix( m1 );
  6764. return this;
  6765. };
  6766. }(),
  6767. scale: function () {
  6768. // scale geometry
  6769. var m1 = new Matrix4();
  6770. return function scale( x, y, z ) {
  6771. m1.makeScale( x, y, z );
  6772. this.applyMatrix( m1 );
  6773. return this;
  6774. };
  6775. }(),
  6776. lookAt: function () {
  6777. var obj = new Object3D();
  6778. return function lookAt( vector ) {
  6779. obj.lookAt( vector );
  6780. obj.updateMatrix();
  6781. this.applyMatrix( obj.matrix );
  6782. };
  6783. }(),
  6784. center: function () {
  6785. var offset = new Vector3();
  6786. return function center() {
  6787. this.computeBoundingBox();
  6788. this.boundingBox.getCenter( offset ).negate();
  6789. this.translate( offset.x, offset.y, offset.z );
  6790. return this;
  6791. };
  6792. }(),
  6793. setFromObject: function ( object ) {
  6794. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6795. var geometry = object.geometry;
  6796. if ( object.isPoints || object.isLine ) {
  6797. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  6798. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  6799. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6800. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6801. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6802. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  6803. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6804. }
  6805. if ( geometry.boundingSphere !== null ) {
  6806. this.boundingSphere = geometry.boundingSphere.clone();
  6807. }
  6808. if ( geometry.boundingBox !== null ) {
  6809. this.boundingBox = geometry.boundingBox.clone();
  6810. }
  6811. } else if ( object.isMesh ) {
  6812. if ( geometry && geometry.isGeometry ) {
  6813. this.fromGeometry( geometry );
  6814. }
  6815. }
  6816. return this;
  6817. },
  6818. setFromPoints: function ( points ) {
  6819. var position = [];
  6820. for ( var i = 0, l = points.length; i < l; i ++ ) {
  6821. var point = points[ i ];
  6822. position.push( point.x, point.y, point.z || 0 );
  6823. }
  6824. this.addAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  6825. return this;
  6826. },
  6827. updateFromObject: function ( object ) {
  6828. var geometry = object.geometry;
  6829. if ( object.isMesh ) {
  6830. var direct = geometry.__directGeometry;
  6831. if ( geometry.elementsNeedUpdate === true ) {
  6832. direct = undefined;
  6833. geometry.elementsNeedUpdate = false;
  6834. }
  6835. if ( direct === undefined ) {
  6836. return this.fromGeometry( geometry );
  6837. }
  6838. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6839. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6840. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6841. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6842. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6843. geometry.verticesNeedUpdate = false;
  6844. geometry.normalsNeedUpdate = false;
  6845. geometry.colorsNeedUpdate = false;
  6846. geometry.uvsNeedUpdate = false;
  6847. geometry.groupsNeedUpdate = false;
  6848. geometry = direct;
  6849. }
  6850. var attribute;
  6851. if ( geometry.verticesNeedUpdate === true ) {
  6852. attribute = this.attributes.position;
  6853. if ( attribute !== undefined ) {
  6854. attribute.copyVector3sArray( geometry.vertices );
  6855. attribute.needsUpdate = true;
  6856. }
  6857. geometry.verticesNeedUpdate = false;
  6858. }
  6859. if ( geometry.normalsNeedUpdate === true ) {
  6860. attribute = this.attributes.normal;
  6861. if ( attribute !== undefined ) {
  6862. attribute.copyVector3sArray( geometry.normals );
  6863. attribute.needsUpdate = true;
  6864. }
  6865. geometry.normalsNeedUpdate = false;
  6866. }
  6867. if ( geometry.colorsNeedUpdate === true ) {
  6868. attribute = this.attributes.color;
  6869. if ( attribute !== undefined ) {
  6870. attribute.copyColorsArray( geometry.colors );
  6871. attribute.needsUpdate = true;
  6872. }
  6873. geometry.colorsNeedUpdate = false;
  6874. }
  6875. if ( geometry.uvsNeedUpdate ) {
  6876. attribute = this.attributes.uv;
  6877. if ( attribute !== undefined ) {
  6878. attribute.copyVector2sArray( geometry.uvs );
  6879. attribute.needsUpdate = true;
  6880. }
  6881. geometry.uvsNeedUpdate = false;
  6882. }
  6883. if ( geometry.lineDistancesNeedUpdate ) {
  6884. attribute = this.attributes.lineDistance;
  6885. if ( attribute !== undefined ) {
  6886. attribute.copyArray( geometry.lineDistances );
  6887. attribute.needsUpdate = true;
  6888. }
  6889. geometry.lineDistancesNeedUpdate = false;
  6890. }
  6891. if ( geometry.groupsNeedUpdate ) {
  6892. geometry.computeGroups( object.geometry );
  6893. this.groups = geometry.groups;
  6894. geometry.groupsNeedUpdate = false;
  6895. }
  6896. return this;
  6897. },
  6898. fromGeometry: function ( geometry ) {
  6899. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  6900. return this.fromDirectGeometry( geometry.__directGeometry );
  6901. },
  6902. fromDirectGeometry: function ( geometry ) {
  6903. var positions = new Float32Array( geometry.vertices.length * 3 );
  6904. this.addAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6905. if ( geometry.normals.length > 0 ) {
  6906. var normals = new Float32Array( geometry.normals.length * 3 );
  6907. this.addAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6908. }
  6909. if ( geometry.colors.length > 0 ) {
  6910. var colors = new Float32Array( geometry.colors.length * 3 );
  6911. this.addAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6912. }
  6913. if ( geometry.uvs.length > 0 ) {
  6914. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6915. this.addAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6916. }
  6917. if ( geometry.uvs2.length > 0 ) {
  6918. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6919. this.addAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6920. }
  6921. // groups
  6922. this.groups = geometry.groups;
  6923. // morphs
  6924. for ( var name in geometry.morphTargets ) {
  6925. var array = [];
  6926. var morphTargets = geometry.morphTargets[ name ];
  6927. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6928. var morphTarget = morphTargets[ i ];
  6929. var attribute = new Float32BufferAttribute( morphTarget.data.length * 3, 3 );
  6930. attribute.name = morphTarget.name;
  6931. array.push( attribute.copyVector3sArray( morphTarget.data ) );
  6932. }
  6933. this.morphAttributes[ name ] = array;
  6934. }
  6935. // skinning
  6936. if ( geometry.skinIndices.length > 0 ) {
  6937. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  6938. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6939. }
  6940. if ( geometry.skinWeights.length > 0 ) {
  6941. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  6942. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6943. }
  6944. //
  6945. if ( geometry.boundingSphere !== null ) {
  6946. this.boundingSphere = geometry.boundingSphere.clone();
  6947. }
  6948. if ( geometry.boundingBox !== null ) {
  6949. this.boundingBox = geometry.boundingBox.clone();
  6950. }
  6951. return this;
  6952. },
  6953. computeBoundingBox: function () {
  6954. if ( this.boundingBox === null ) {
  6955. this.boundingBox = new Box3();
  6956. }
  6957. var position = this.attributes.position;
  6958. if ( position !== undefined ) {
  6959. this.boundingBox.setFromBufferAttribute( position );
  6960. } else {
  6961. this.boundingBox.makeEmpty();
  6962. }
  6963. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6964. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6965. }
  6966. },
  6967. computeBoundingSphere: function () {
  6968. var box = new Box3();
  6969. var vector = new Vector3();
  6970. return function computeBoundingSphere() {
  6971. if ( this.boundingSphere === null ) {
  6972. this.boundingSphere = new Sphere();
  6973. }
  6974. var position = this.attributes.position;
  6975. if ( position ) {
  6976. var center = this.boundingSphere.center;
  6977. box.setFromBufferAttribute( position );
  6978. box.getCenter( center );
  6979. // hoping to find a boundingSphere with a radius smaller than the
  6980. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6981. var maxRadiusSq = 0;
  6982. for ( var i = 0, il = position.count; i < il; i ++ ) {
  6983. vector.x = position.getX( i );
  6984. vector.y = position.getY( i );
  6985. vector.z = position.getZ( i );
  6986. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6987. }
  6988. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6989. if ( isNaN( this.boundingSphere.radius ) ) {
  6990. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6991. }
  6992. }
  6993. };
  6994. }(),
  6995. computeFaceNormals: function () {
  6996. // backwards compatibility
  6997. },
  6998. computeVertexNormals: function () {
  6999. var index = this.index;
  7000. var attributes = this.attributes;
  7001. if ( attributes.position ) {
  7002. var positions = attributes.position.array;
  7003. if ( attributes.normal === undefined ) {
  7004. this.addAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  7005. } else {
  7006. // reset existing normals to zero
  7007. var array = attributes.normal.array;
  7008. for ( var i = 0, il = array.length; i < il; i ++ ) {
  7009. array[ i ] = 0;
  7010. }
  7011. }
  7012. var normals = attributes.normal.array;
  7013. var vA, vB, vC;
  7014. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  7015. var cb = new Vector3(), ab = new Vector3();
  7016. // indexed elements
  7017. if ( index ) {
  7018. var indices = index.array;
  7019. for ( var i = 0, il = index.count; i < il; i += 3 ) {
  7020. vA = indices[ i + 0 ] * 3;
  7021. vB = indices[ i + 1 ] * 3;
  7022. vC = indices[ i + 2 ] * 3;
  7023. pA.fromArray( positions, vA );
  7024. pB.fromArray( positions, vB );
  7025. pC.fromArray( positions, vC );
  7026. cb.subVectors( pC, pB );
  7027. ab.subVectors( pA, pB );
  7028. cb.cross( ab );
  7029. normals[ vA ] += cb.x;
  7030. normals[ vA + 1 ] += cb.y;
  7031. normals[ vA + 2 ] += cb.z;
  7032. normals[ vB ] += cb.x;
  7033. normals[ vB + 1 ] += cb.y;
  7034. normals[ vB + 2 ] += cb.z;
  7035. normals[ vC ] += cb.x;
  7036. normals[ vC + 1 ] += cb.y;
  7037. normals[ vC + 2 ] += cb.z;
  7038. }
  7039. } else {
  7040. // non-indexed elements (unconnected triangle soup)
  7041. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  7042. pA.fromArray( positions, i );
  7043. pB.fromArray( positions, i + 3 );
  7044. pC.fromArray( positions, i + 6 );
  7045. cb.subVectors( pC, pB );
  7046. ab.subVectors( pA, pB );
  7047. cb.cross( ab );
  7048. normals[ i ] = cb.x;
  7049. normals[ i + 1 ] = cb.y;
  7050. normals[ i + 2 ] = cb.z;
  7051. normals[ i + 3 ] = cb.x;
  7052. normals[ i + 4 ] = cb.y;
  7053. normals[ i + 5 ] = cb.z;
  7054. normals[ i + 6 ] = cb.x;
  7055. normals[ i + 7 ] = cb.y;
  7056. normals[ i + 8 ] = cb.z;
  7057. }
  7058. }
  7059. this.normalizeNormals();
  7060. attributes.normal.needsUpdate = true;
  7061. }
  7062. },
  7063. merge: function ( geometry, offset ) {
  7064. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  7065. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  7066. return;
  7067. }
  7068. if ( offset === undefined ) {
  7069. offset = 0;
  7070. console.warn(
  7071. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  7072. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  7073. );
  7074. }
  7075. var attributes = this.attributes;
  7076. for ( var key in attributes ) {
  7077. if ( geometry.attributes[ key ] === undefined ) continue;
  7078. var attribute1 = attributes[ key ];
  7079. var attributeArray1 = attribute1.array;
  7080. var attribute2 = geometry.attributes[ key ];
  7081. var attributeArray2 = attribute2.array;
  7082. var attributeSize = attribute2.itemSize;
  7083. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  7084. attributeArray1[ j ] = attributeArray2[ i ];
  7085. }
  7086. }
  7087. return this;
  7088. },
  7089. normalizeNormals: function () {
  7090. var vector = new Vector3();
  7091. return function normalizeNormals() {
  7092. var normals = this.attributes.normal;
  7093. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  7094. vector.x = normals.getX( i );
  7095. vector.y = normals.getY( i );
  7096. vector.z = normals.getZ( i );
  7097. vector.normalize();
  7098. normals.setXYZ( i, vector.x, vector.y, vector.z );
  7099. }
  7100. };
  7101. }(),
  7102. toNonIndexed: function () {
  7103. if ( this.index === null ) {
  7104. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  7105. return this;
  7106. }
  7107. var geometry2 = new BufferGeometry();
  7108. var indices = this.index.array;
  7109. var attributes = this.attributes;
  7110. for ( var name in attributes ) {
  7111. var attribute = attributes[ name ];
  7112. var array = attribute.array;
  7113. var itemSize = attribute.itemSize;
  7114. var array2 = new array.constructor( indices.length * itemSize );
  7115. var index = 0, index2 = 0;
  7116. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  7117. index = indices[ i ] * itemSize;
  7118. for ( var j = 0; j < itemSize; j ++ ) {
  7119. array2[ index2 ++ ] = array[ index ++ ];
  7120. }
  7121. }
  7122. geometry2.addAttribute( name, new BufferAttribute( array2, itemSize ) );
  7123. }
  7124. var groups = this.groups;
  7125. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7126. var group = groups[ i ];
  7127. geometry2.addGroup( group.start, group.count, group.materialIndex );
  7128. }
  7129. return geometry2;
  7130. },
  7131. toJSON: function () {
  7132. var data = {
  7133. metadata: {
  7134. version: 4.5,
  7135. type: 'BufferGeometry',
  7136. generator: 'BufferGeometry.toJSON'
  7137. }
  7138. };
  7139. // standard BufferGeometry serialization
  7140. data.uuid = this.uuid;
  7141. data.type = this.type;
  7142. if ( this.name !== '' ) data.name = this.name;
  7143. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  7144. if ( this.parameters !== undefined ) {
  7145. var parameters = this.parameters;
  7146. for ( var key in parameters ) {
  7147. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7148. }
  7149. return data;
  7150. }
  7151. data.data = { attributes: {} };
  7152. var index = this.index;
  7153. if ( index !== null ) {
  7154. var array = Array.prototype.slice.call( index.array );
  7155. data.data.index = {
  7156. type: index.array.constructor.name,
  7157. array: array
  7158. };
  7159. }
  7160. var attributes = this.attributes;
  7161. for ( var key in attributes ) {
  7162. var attribute = attributes[ key ];
  7163. var array = Array.prototype.slice.call( attribute.array );
  7164. data.data.attributes[ key ] = {
  7165. itemSize: attribute.itemSize,
  7166. type: attribute.array.constructor.name,
  7167. array: array,
  7168. normalized: attribute.normalized
  7169. };
  7170. }
  7171. var groups = this.groups;
  7172. if ( groups.length > 0 ) {
  7173. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7174. }
  7175. var boundingSphere = this.boundingSphere;
  7176. if ( boundingSphere !== null ) {
  7177. data.data.boundingSphere = {
  7178. center: boundingSphere.center.toArray(),
  7179. radius: boundingSphere.radius
  7180. };
  7181. }
  7182. return data;
  7183. },
  7184. clone: function () {
  7185. /*
  7186. // Handle primitives
  7187. var parameters = this.parameters;
  7188. if ( parameters !== undefined ) {
  7189. var values = [];
  7190. for ( var key in parameters ) {
  7191. values.push( parameters[ key ] );
  7192. }
  7193. var geometry = Object.create( this.constructor.prototype );
  7194. this.constructor.apply( geometry, values );
  7195. return geometry;
  7196. }
  7197. return new this.constructor().copy( this );
  7198. */
  7199. return new BufferGeometry().copy( this );
  7200. },
  7201. copy: function ( source ) {
  7202. var name, i, l;
  7203. // reset
  7204. this.index = null;
  7205. this.attributes = {};
  7206. this.morphAttributes = {};
  7207. this.groups = [];
  7208. this.boundingBox = null;
  7209. this.boundingSphere = null;
  7210. // name
  7211. this.name = source.name;
  7212. // index
  7213. var index = source.index;
  7214. if ( index !== null ) {
  7215. this.setIndex( index.clone() );
  7216. }
  7217. // attributes
  7218. var attributes = source.attributes;
  7219. for ( name in attributes ) {
  7220. var attribute = attributes[ name ];
  7221. this.addAttribute( name, attribute.clone() );
  7222. }
  7223. // morph attributes
  7224. var morphAttributes = source.morphAttributes;
  7225. for ( name in morphAttributes ) {
  7226. var array = [];
  7227. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  7228. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  7229. array.push( morphAttribute[ i ].clone() );
  7230. }
  7231. this.morphAttributes[ name ] = array;
  7232. }
  7233. // groups
  7234. var groups = source.groups;
  7235. for ( i = 0, l = groups.length; i < l; i ++ ) {
  7236. var group = groups[ i ];
  7237. this.addGroup( group.start, group.count, group.materialIndex );
  7238. }
  7239. // bounding box
  7240. var boundingBox = source.boundingBox;
  7241. if ( boundingBox !== null ) {
  7242. this.boundingBox = boundingBox.clone();
  7243. }
  7244. // bounding sphere
  7245. var boundingSphere = source.boundingSphere;
  7246. if ( boundingSphere !== null ) {
  7247. this.boundingSphere = boundingSphere.clone();
  7248. }
  7249. // draw range
  7250. this.drawRange.start = source.drawRange.start;
  7251. this.drawRange.count = source.drawRange.count;
  7252. // user data
  7253. this.userData = source.userData;
  7254. return this;
  7255. },
  7256. dispose: function () {
  7257. this.dispatchEvent( { type: 'dispose' } );
  7258. }
  7259. } );
  7260. /**
  7261. * @author mrdoob / http://mrdoob.com/
  7262. * @author Mugen87 / https://github.com/Mugen87
  7263. */
  7264. // BoxGeometry
  7265. function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7266. Geometry.call( this );
  7267. this.type = 'BoxGeometry';
  7268. this.parameters = {
  7269. width: width,
  7270. height: height,
  7271. depth: depth,
  7272. widthSegments: widthSegments,
  7273. heightSegments: heightSegments,
  7274. depthSegments: depthSegments
  7275. };
  7276. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  7277. this.mergeVertices();
  7278. }
  7279. BoxGeometry.prototype = Object.create( Geometry.prototype );
  7280. BoxGeometry.prototype.constructor = BoxGeometry;
  7281. // BoxBufferGeometry
  7282. function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7283. BufferGeometry.call( this );
  7284. this.type = 'BoxBufferGeometry';
  7285. this.parameters = {
  7286. width: width,
  7287. height: height,
  7288. depth: depth,
  7289. widthSegments: widthSegments,
  7290. heightSegments: heightSegments,
  7291. depthSegments: depthSegments
  7292. };
  7293. var scope = this;
  7294. width = width || 1;
  7295. height = height || 1;
  7296. depth = depth || 1;
  7297. // segments
  7298. widthSegments = Math.floor( widthSegments ) || 1;
  7299. heightSegments = Math.floor( heightSegments ) || 1;
  7300. depthSegments = Math.floor( depthSegments ) || 1;
  7301. // buffers
  7302. var indices = [];
  7303. var vertices = [];
  7304. var normals = [];
  7305. var uvs = [];
  7306. // helper variables
  7307. var numberOfVertices = 0;
  7308. var groupStart = 0;
  7309. // build each side of the box geometry
  7310. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7311. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7312. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7313. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7314. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7315. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7316. // build geometry
  7317. this.setIndex( indices );
  7318. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7319. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7320. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7321. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7322. var segmentWidth = width / gridX;
  7323. var segmentHeight = height / gridY;
  7324. var widthHalf = width / 2;
  7325. var heightHalf = height / 2;
  7326. var depthHalf = depth / 2;
  7327. var gridX1 = gridX + 1;
  7328. var gridY1 = gridY + 1;
  7329. var vertexCounter = 0;
  7330. var groupCount = 0;
  7331. var ix, iy;
  7332. var vector = new Vector3();
  7333. // generate vertices, normals and uvs
  7334. for ( iy = 0; iy < gridY1; iy ++ ) {
  7335. var y = iy * segmentHeight - heightHalf;
  7336. for ( ix = 0; ix < gridX1; ix ++ ) {
  7337. var x = ix * segmentWidth - widthHalf;
  7338. // set values to correct vector component
  7339. vector[ u ] = x * udir;
  7340. vector[ v ] = y * vdir;
  7341. vector[ w ] = depthHalf;
  7342. // now apply vector to vertex buffer
  7343. vertices.push( vector.x, vector.y, vector.z );
  7344. // set values to correct vector component
  7345. vector[ u ] = 0;
  7346. vector[ v ] = 0;
  7347. vector[ w ] = depth > 0 ? 1 : - 1;
  7348. // now apply vector to normal buffer
  7349. normals.push( vector.x, vector.y, vector.z );
  7350. // uvs
  7351. uvs.push( ix / gridX );
  7352. uvs.push( 1 - ( iy / gridY ) );
  7353. // counters
  7354. vertexCounter += 1;
  7355. }
  7356. }
  7357. // indices
  7358. // 1. you need three indices to draw a single face
  7359. // 2. a single segment consists of two faces
  7360. // 3. so we need to generate six (2*3) indices per segment
  7361. for ( iy = 0; iy < gridY; iy ++ ) {
  7362. for ( ix = 0; ix < gridX; ix ++ ) {
  7363. var a = numberOfVertices + ix + gridX1 * iy;
  7364. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7365. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7366. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7367. // faces
  7368. indices.push( a, b, d );
  7369. indices.push( b, c, d );
  7370. // increase counter
  7371. groupCount += 6;
  7372. }
  7373. }
  7374. // add a group to the geometry. this will ensure multi material support
  7375. scope.addGroup( groupStart, groupCount, materialIndex );
  7376. // calculate new start value for groups
  7377. groupStart += groupCount;
  7378. // update total number of vertices
  7379. numberOfVertices += vertexCounter;
  7380. }
  7381. }
  7382. BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7383. BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
  7384. /**
  7385. * @author mrdoob / http://mrdoob.com/
  7386. * @author Mugen87 / https://github.com/Mugen87
  7387. */
  7388. // PlaneGeometry
  7389. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  7390. Geometry.call( this );
  7391. this.type = 'PlaneGeometry';
  7392. this.parameters = {
  7393. width: width,
  7394. height: height,
  7395. widthSegments: widthSegments,
  7396. heightSegments: heightSegments
  7397. };
  7398. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  7399. this.mergeVertices();
  7400. }
  7401. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  7402. PlaneGeometry.prototype.constructor = PlaneGeometry;
  7403. // PlaneBufferGeometry
  7404. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  7405. BufferGeometry.call( this );
  7406. this.type = 'PlaneBufferGeometry';
  7407. this.parameters = {
  7408. width: width,
  7409. height: height,
  7410. widthSegments: widthSegments,
  7411. heightSegments: heightSegments
  7412. };
  7413. width = width || 1;
  7414. height = height || 1;
  7415. var width_half = width / 2;
  7416. var height_half = height / 2;
  7417. var gridX = Math.floor( widthSegments ) || 1;
  7418. var gridY = Math.floor( heightSegments ) || 1;
  7419. var gridX1 = gridX + 1;
  7420. var gridY1 = gridY + 1;
  7421. var segment_width = width / gridX;
  7422. var segment_height = height / gridY;
  7423. var ix, iy;
  7424. // buffers
  7425. var indices = [];
  7426. var vertices = [];
  7427. var normals = [];
  7428. var uvs = [];
  7429. // generate vertices, normals and uvs
  7430. for ( iy = 0; iy < gridY1; iy ++ ) {
  7431. var y = iy * segment_height - height_half;
  7432. for ( ix = 0; ix < gridX1; ix ++ ) {
  7433. var x = ix * segment_width - width_half;
  7434. vertices.push( x, - y, 0 );
  7435. normals.push( 0, 0, 1 );
  7436. uvs.push( ix / gridX );
  7437. uvs.push( 1 - ( iy / gridY ) );
  7438. }
  7439. }
  7440. // indices
  7441. for ( iy = 0; iy < gridY; iy ++ ) {
  7442. for ( ix = 0; ix < gridX; ix ++ ) {
  7443. var a = ix + gridX1 * iy;
  7444. var b = ix + gridX1 * ( iy + 1 );
  7445. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  7446. var d = ( ix + 1 ) + gridX1 * iy;
  7447. // faces
  7448. indices.push( a, b, d );
  7449. indices.push( b, c, d );
  7450. }
  7451. }
  7452. // build geometry
  7453. this.setIndex( indices );
  7454. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7455. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7456. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7457. }
  7458. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7459. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  7460. /**
  7461. * @author mrdoob / http://mrdoob.com/
  7462. * @author alteredq / http://alteredqualia.com/
  7463. */
  7464. var materialId = 0;
  7465. function Material() {
  7466. Object.defineProperty( this, 'id', { value: materialId ++ } );
  7467. this.uuid = _Math.generateUUID();
  7468. this.name = '';
  7469. this.type = 'Material';
  7470. this.fog = true;
  7471. this.lights = true;
  7472. this.blending = NormalBlending;
  7473. this.side = FrontSide;
  7474. this.flatShading = false;
  7475. this.vertexColors = NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  7476. this.opacity = 1;
  7477. this.transparent = false;
  7478. this.blendSrc = SrcAlphaFactor;
  7479. this.blendDst = OneMinusSrcAlphaFactor;
  7480. this.blendEquation = AddEquation;
  7481. this.blendSrcAlpha = null;
  7482. this.blendDstAlpha = null;
  7483. this.blendEquationAlpha = null;
  7484. this.depthFunc = LessEqualDepth;
  7485. this.depthTest = true;
  7486. this.depthWrite = true;
  7487. this.clippingPlanes = null;
  7488. this.clipIntersection = false;
  7489. this.clipShadows = false;
  7490. this.shadowSide = null;
  7491. this.colorWrite = true;
  7492. this.precision = null; // override the renderer's default precision for this material
  7493. this.polygonOffset = false;
  7494. this.polygonOffsetFactor = 0;
  7495. this.polygonOffsetUnits = 0;
  7496. this.dithering = false;
  7497. this.alphaTest = 0;
  7498. this.premultipliedAlpha = false;
  7499. this.visible = true;
  7500. this.userData = {};
  7501. this.needsUpdate = true;
  7502. }
  7503. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  7504. constructor: Material,
  7505. isMaterial: true,
  7506. onBeforeCompile: function () {},
  7507. setValues: function ( values ) {
  7508. if ( values === undefined ) return;
  7509. for ( var key in values ) {
  7510. var newValue = values[ key ];
  7511. if ( newValue === undefined ) {
  7512. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  7513. continue;
  7514. }
  7515. // for backward compatability if shading is set in the constructor
  7516. if ( key === 'shading' ) {
  7517. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  7518. this.flatShading = ( newValue === FlatShading ) ? true : false;
  7519. continue;
  7520. }
  7521. var currentValue = this[ key ];
  7522. if ( currentValue === undefined ) {
  7523. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  7524. continue;
  7525. }
  7526. if ( currentValue && currentValue.isColor ) {
  7527. currentValue.set( newValue );
  7528. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  7529. currentValue.copy( newValue );
  7530. } else {
  7531. this[ key ] = newValue;
  7532. }
  7533. }
  7534. },
  7535. toJSON: function ( meta ) {
  7536. var isRoot = ( meta === undefined || typeof meta === 'string' );
  7537. if ( isRoot ) {
  7538. meta = {
  7539. textures: {},
  7540. images: {}
  7541. };
  7542. }
  7543. var data = {
  7544. metadata: {
  7545. version: 4.5,
  7546. type: 'Material',
  7547. generator: 'Material.toJSON'
  7548. }
  7549. };
  7550. // standard Material serialization
  7551. data.uuid = this.uuid;
  7552. data.type = this.type;
  7553. if ( this.name !== '' ) data.name = this.name;
  7554. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  7555. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  7556. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  7557. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  7558. if ( this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  7559. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  7560. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  7561. if ( this.clearCoat !== undefined ) data.clearCoat = this.clearCoat;
  7562. if ( this.clearCoatRoughness !== undefined ) data.clearCoatRoughness = this.clearCoatRoughness;
  7563. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  7564. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  7565. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  7566. if ( this.aoMap && this.aoMap.isTexture ) {
  7567. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  7568. data.aoMapIntensity = this.aoMapIntensity;
  7569. }
  7570. if ( this.bumpMap && this.bumpMap.isTexture ) {
  7571. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  7572. data.bumpScale = this.bumpScale;
  7573. }
  7574. if ( this.normalMap && this.normalMap.isTexture ) {
  7575. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  7576. data.normalMapType = this.normalMapType;
  7577. data.normalScale = this.normalScale.toArray();
  7578. }
  7579. if ( this.displacementMap && this.displacementMap.isTexture ) {
  7580. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  7581. data.displacementScale = this.displacementScale;
  7582. data.displacementBias = this.displacementBias;
  7583. }
  7584. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  7585. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  7586. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  7587. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  7588. if ( this.envMap && this.envMap.isTexture ) {
  7589. data.envMap = this.envMap.toJSON( meta ).uuid;
  7590. data.reflectivity = this.reflectivity; // Scale behind envMap
  7591. if ( this.combine !== undefined ) data.combine = this.combine;
  7592. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  7593. }
  7594. if ( this.gradientMap && this.gradientMap.isTexture ) {
  7595. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  7596. }
  7597. if ( this.size !== undefined ) data.size = this.size;
  7598. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  7599. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  7600. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  7601. if ( this.side !== FrontSide ) data.side = this.side;
  7602. if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
  7603. if ( this.opacity < 1 ) data.opacity = this.opacity;
  7604. if ( this.transparent === true ) data.transparent = this.transparent;
  7605. data.depthFunc = this.depthFunc;
  7606. data.depthTest = this.depthTest;
  7607. data.depthWrite = this.depthWrite;
  7608. // rotation (SpriteMaterial)
  7609. if ( this.rotation !== 0 ) data.rotation = this.rotation;
  7610. if ( this.polygonOffset === true ) data.polygonOffset = true;
  7611. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  7612. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  7613. if ( this.linewidth !== 1 ) data.linewidth = this.linewidth;
  7614. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  7615. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  7616. if ( this.scale !== undefined ) data.scale = this.scale;
  7617. if ( this.dithering === true ) data.dithering = true;
  7618. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  7619. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  7620. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  7621. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  7622. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  7623. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  7624. if ( this.morphTargets === true ) data.morphTargets = true;
  7625. if ( this.skinning === true ) data.skinning = true;
  7626. if ( this.visible === false ) data.visible = false;
  7627. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  7628. // TODO: Copied from Object3D.toJSON
  7629. function extractFromCache( cache ) {
  7630. var values = [];
  7631. for ( var key in cache ) {
  7632. var data = cache[ key ];
  7633. delete data.metadata;
  7634. values.push( data );
  7635. }
  7636. return values;
  7637. }
  7638. if ( isRoot ) {
  7639. var textures = extractFromCache( meta.textures );
  7640. var images = extractFromCache( meta.images );
  7641. if ( textures.length > 0 ) data.textures = textures;
  7642. if ( images.length > 0 ) data.images = images;
  7643. }
  7644. return data;
  7645. },
  7646. clone: function () {
  7647. return new this.constructor().copy( this );
  7648. },
  7649. copy: function ( source ) {
  7650. this.name = source.name;
  7651. this.fog = source.fog;
  7652. this.lights = source.lights;
  7653. this.blending = source.blending;
  7654. this.side = source.side;
  7655. this.flatShading = source.flatShading;
  7656. this.vertexColors = source.vertexColors;
  7657. this.opacity = source.opacity;
  7658. this.transparent = source.transparent;
  7659. this.blendSrc = source.blendSrc;
  7660. this.blendDst = source.blendDst;
  7661. this.blendEquation = source.blendEquation;
  7662. this.blendSrcAlpha = source.blendSrcAlpha;
  7663. this.blendDstAlpha = source.blendDstAlpha;
  7664. this.blendEquationAlpha = source.blendEquationAlpha;
  7665. this.depthFunc = source.depthFunc;
  7666. this.depthTest = source.depthTest;
  7667. this.depthWrite = source.depthWrite;
  7668. this.colorWrite = source.colorWrite;
  7669. this.precision = source.precision;
  7670. this.polygonOffset = source.polygonOffset;
  7671. this.polygonOffsetFactor = source.polygonOffsetFactor;
  7672. this.polygonOffsetUnits = source.polygonOffsetUnits;
  7673. this.dithering = source.dithering;
  7674. this.alphaTest = source.alphaTest;
  7675. this.premultipliedAlpha = source.premultipliedAlpha;
  7676. this.visible = source.visible;
  7677. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  7678. this.clipShadows = source.clipShadows;
  7679. this.clipIntersection = source.clipIntersection;
  7680. var srcPlanes = source.clippingPlanes,
  7681. dstPlanes = null;
  7682. if ( srcPlanes !== null ) {
  7683. var n = srcPlanes.length;
  7684. dstPlanes = new Array( n );
  7685. for ( var i = 0; i !== n; ++ i )
  7686. dstPlanes[ i ] = srcPlanes[ i ].clone();
  7687. }
  7688. this.clippingPlanes = dstPlanes;
  7689. this.shadowSide = source.shadowSide;
  7690. return this;
  7691. },
  7692. dispose: function () {
  7693. this.dispatchEvent( { type: 'dispose' } );
  7694. }
  7695. } );
  7696. /**
  7697. * @author alteredq / http://alteredqualia.com/
  7698. *
  7699. * parameters = {
  7700. * defines: { "label" : "value" },
  7701. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7702. *
  7703. * fragmentShader: <string>,
  7704. * vertexShader: <string>,
  7705. *
  7706. * wireframe: <boolean>,
  7707. * wireframeLinewidth: <float>,
  7708. *
  7709. * lights: <bool>,
  7710. *
  7711. * skinning: <bool>,
  7712. * morphTargets: <bool>,
  7713. * morphNormals: <bool>
  7714. * }
  7715. */
  7716. function ShaderMaterial( parameters ) {
  7717. Material.call( this );
  7718. this.type = 'ShaderMaterial';
  7719. this.defines = {};
  7720. this.uniforms = {};
  7721. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  7722. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  7723. this.linewidth = 1;
  7724. this.wireframe = false;
  7725. this.wireframeLinewidth = 1;
  7726. this.fog = false; // set to use scene fog
  7727. this.lights = false; // set to use scene lights
  7728. this.clipping = false; // set to use user-defined clipping planes
  7729. this.skinning = false; // set to use skinning attribute streams
  7730. this.morphTargets = false; // set to use morph targets
  7731. this.morphNormals = false; // set to use morph normals
  7732. this.extensions = {
  7733. derivatives: false, // set to use derivatives
  7734. fragDepth: false, // set to use fragment depth values
  7735. drawBuffers: false, // set to use draw buffers
  7736. shaderTextureLOD: false // set to use shader texture LOD
  7737. };
  7738. // When rendered geometry doesn't include these attributes but the material does,
  7739. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7740. this.defaultAttributeValues = {
  7741. 'color': [ 1, 1, 1 ],
  7742. 'uv': [ 0, 0 ],
  7743. 'uv2': [ 0, 0 ]
  7744. };
  7745. this.index0AttributeName = undefined;
  7746. this.uniformsNeedUpdate = false;
  7747. if ( parameters !== undefined ) {
  7748. if ( parameters.attributes !== undefined ) {
  7749. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  7750. }
  7751. this.setValues( parameters );
  7752. }
  7753. }
  7754. ShaderMaterial.prototype = Object.create( Material.prototype );
  7755. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7756. ShaderMaterial.prototype.isShaderMaterial = true;
  7757. ShaderMaterial.prototype.copy = function ( source ) {
  7758. Material.prototype.copy.call( this, source );
  7759. this.fragmentShader = source.fragmentShader;
  7760. this.vertexShader = source.vertexShader;
  7761. this.uniforms = cloneUniforms( source.uniforms );
  7762. this.defines = Object.assign( {}, source.defines );
  7763. this.wireframe = source.wireframe;
  7764. this.wireframeLinewidth = source.wireframeLinewidth;
  7765. this.lights = source.lights;
  7766. this.clipping = source.clipping;
  7767. this.skinning = source.skinning;
  7768. this.morphTargets = source.morphTargets;
  7769. this.morphNormals = source.morphNormals;
  7770. this.extensions = source.extensions;
  7771. return this;
  7772. };
  7773. ShaderMaterial.prototype.toJSON = function ( meta ) {
  7774. var data = Material.prototype.toJSON.call( this, meta );
  7775. data.uniforms = {};
  7776. for ( var name in this.uniforms ) {
  7777. var uniform = this.uniforms[ name ];
  7778. var value = uniform.value;
  7779. if ( value && value.isTexture ) {
  7780. data.uniforms[ name ] = {
  7781. type: 't',
  7782. value: value.toJSON( meta ).uuid
  7783. };
  7784. } else if ( value && value.isColor ) {
  7785. data.uniforms[ name ] = {
  7786. type: 'c',
  7787. value: value.getHex()
  7788. };
  7789. } else if ( value && value.isVector2 ) {
  7790. data.uniforms[ name ] = {
  7791. type: 'v2',
  7792. value: value.toArray()
  7793. };
  7794. } else if ( value && value.isVector3 ) {
  7795. data.uniforms[ name ] = {
  7796. type: 'v3',
  7797. value: value.toArray()
  7798. };
  7799. } else if ( value && value.isVector4 ) {
  7800. data.uniforms[ name ] = {
  7801. type: 'v4',
  7802. value: value.toArray()
  7803. };
  7804. } else if ( value && value.isMatrix3 ) {
  7805. data.uniforms[ name ] = {
  7806. type: 'm3',
  7807. value: value.toArray()
  7808. };
  7809. } else if ( value && value.isMatrix4 ) {
  7810. data.uniforms[ name ] = {
  7811. type: 'm4',
  7812. value: value.toArray()
  7813. };
  7814. } else {
  7815. data.uniforms[ name ] = {
  7816. value: value
  7817. };
  7818. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7819. }
  7820. }
  7821. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  7822. data.vertexShader = this.vertexShader;
  7823. data.fragmentShader = this.fragmentShader;
  7824. var extensions = {};
  7825. for ( var key in this.extensions ) {
  7826. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  7827. }
  7828. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  7829. return data;
  7830. };
  7831. /**
  7832. * @author bhouston / http://clara.io
  7833. */
  7834. function Ray( origin, direction ) {
  7835. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  7836. this.direction = ( direction !== undefined ) ? direction : new Vector3();
  7837. }
  7838. Object.assign( Ray.prototype, {
  7839. set: function ( origin, direction ) {
  7840. this.origin.copy( origin );
  7841. this.direction.copy( direction );
  7842. return this;
  7843. },
  7844. clone: function () {
  7845. return new this.constructor().copy( this );
  7846. },
  7847. copy: function ( ray ) {
  7848. this.origin.copy( ray.origin );
  7849. this.direction.copy( ray.direction );
  7850. return this;
  7851. },
  7852. at: function ( t, target ) {
  7853. if ( target === undefined ) {
  7854. console.warn( 'THREE.Ray: .at() target is now required' );
  7855. target = new Vector3();
  7856. }
  7857. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  7858. },
  7859. lookAt: function ( v ) {
  7860. this.direction.copy( v ).sub( this.origin ).normalize();
  7861. return this;
  7862. },
  7863. recast: function () {
  7864. var v1 = new Vector3();
  7865. return function recast( t ) {
  7866. this.origin.copy( this.at( t, v1 ) );
  7867. return this;
  7868. };
  7869. }(),
  7870. closestPointToPoint: function ( point, target ) {
  7871. if ( target === undefined ) {
  7872. console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
  7873. target = new Vector3();
  7874. }
  7875. target.subVectors( point, this.origin );
  7876. var directionDistance = target.dot( this.direction );
  7877. if ( directionDistance < 0 ) {
  7878. return target.copy( this.origin );
  7879. }
  7880. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  7881. },
  7882. distanceToPoint: function ( point ) {
  7883. return Math.sqrt( this.distanceSqToPoint( point ) );
  7884. },
  7885. distanceSqToPoint: function () {
  7886. var v1 = new Vector3();
  7887. return function distanceSqToPoint( point ) {
  7888. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  7889. // point behind the ray
  7890. if ( directionDistance < 0 ) {
  7891. return this.origin.distanceToSquared( point );
  7892. }
  7893. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  7894. return v1.distanceToSquared( point );
  7895. };
  7896. }(),
  7897. distanceSqToSegment: function () {
  7898. var segCenter = new Vector3();
  7899. var segDir = new Vector3();
  7900. var diff = new Vector3();
  7901. return function distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  7902. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  7903. // It returns the min distance between the ray and the segment
  7904. // defined by v0 and v1
  7905. // It can also set two optional targets :
  7906. // - The closest point on the ray
  7907. // - The closest point on the segment
  7908. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  7909. segDir.copy( v1 ).sub( v0 ).normalize();
  7910. diff.copy( this.origin ).sub( segCenter );
  7911. var segExtent = v0.distanceTo( v1 ) * 0.5;
  7912. var a01 = - this.direction.dot( segDir );
  7913. var b0 = diff.dot( this.direction );
  7914. var b1 = - diff.dot( segDir );
  7915. var c = diff.lengthSq();
  7916. var det = Math.abs( 1 - a01 * a01 );
  7917. var s0, s1, sqrDist, extDet;
  7918. if ( det > 0 ) {
  7919. // The ray and segment are not parallel.
  7920. s0 = a01 * b1 - b0;
  7921. s1 = a01 * b0 - b1;
  7922. extDet = segExtent * det;
  7923. if ( s0 >= 0 ) {
  7924. if ( s1 >= - extDet ) {
  7925. if ( s1 <= extDet ) {
  7926. // region 0
  7927. // Minimum at interior points of ray and segment.
  7928. var invDet = 1 / det;
  7929. s0 *= invDet;
  7930. s1 *= invDet;
  7931. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  7932. } else {
  7933. // region 1
  7934. s1 = segExtent;
  7935. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  7936. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7937. }
  7938. } else {
  7939. // region 5
  7940. s1 = - segExtent;
  7941. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  7942. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7943. }
  7944. } else {
  7945. if ( s1 <= - extDet ) {
  7946. // region 4
  7947. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  7948. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  7949. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7950. } else if ( s1 <= extDet ) {
  7951. // region 3
  7952. s0 = 0;
  7953. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  7954. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  7955. } else {
  7956. // region 2
  7957. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  7958. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  7959. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7960. }
  7961. }
  7962. } else {
  7963. // Ray and segment are parallel.
  7964. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  7965. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  7966. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7967. }
  7968. if ( optionalPointOnRay ) {
  7969. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  7970. }
  7971. if ( optionalPointOnSegment ) {
  7972. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  7973. }
  7974. return sqrDist;
  7975. };
  7976. }(),
  7977. intersectSphere: function () {
  7978. var v1 = new Vector3();
  7979. return function intersectSphere( sphere, target ) {
  7980. v1.subVectors( sphere.center, this.origin );
  7981. var tca = v1.dot( this.direction );
  7982. var d2 = v1.dot( v1 ) - tca * tca;
  7983. var radius2 = sphere.radius * sphere.radius;
  7984. if ( d2 > radius2 ) return null;
  7985. var thc = Math.sqrt( radius2 - d2 );
  7986. // t0 = first intersect point - entrance on front of sphere
  7987. var t0 = tca - thc;
  7988. // t1 = second intersect point - exit point on back of sphere
  7989. var t1 = tca + thc;
  7990. // test to see if both t0 and t1 are behind the ray - if so, return null
  7991. if ( t0 < 0 && t1 < 0 ) return null;
  7992. // test to see if t0 is behind the ray:
  7993. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  7994. // in order to always return an intersect point that is in front of the ray.
  7995. if ( t0 < 0 ) return this.at( t1, target );
  7996. // else t0 is in front of the ray, so return the first collision point scaled by t0
  7997. return this.at( t0, target );
  7998. };
  7999. }(),
  8000. intersectsSphere: function ( sphere ) {
  8001. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  8002. },
  8003. distanceToPlane: function ( plane ) {
  8004. var denominator = plane.normal.dot( this.direction );
  8005. if ( denominator === 0 ) {
  8006. // line is coplanar, return origin
  8007. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  8008. return 0;
  8009. }
  8010. // Null is preferable to undefined since undefined means.... it is undefined
  8011. return null;
  8012. }
  8013. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  8014. // Return if the ray never intersects the plane
  8015. return t >= 0 ? t : null;
  8016. },
  8017. intersectPlane: function ( plane, target ) {
  8018. var t = this.distanceToPlane( plane );
  8019. if ( t === null ) {
  8020. return null;
  8021. }
  8022. return this.at( t, target );
  8023. },
  8024. intersectsPlane: function ( plane ) {
  8025. // check if the ray lies on the plane first
  8026. var distToPoint = plane.distanceToPoint( this.origin );
  8027. if ( distToPoint === 0 ) {
  8028. return true;
  8029. }
  8030. var denominator = plane.normal.dot( this.direction );
  8031. if ( denominator * distToPoint < 0 ) {
  8032. return true;
  8033. }
  8034. // ray origin is behind the plane (and is pointing behind it)
  8035. return false;
  8036. },
  8037. intersectBox: function ( box, target ) {
  8038. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  8039. var invdirx = 1 / this.direction.x,
  8040. invdiry = 1 / this.direction.y,
  8041. invdirz = 1 / this.direction.z;
  8042. var origin = this.origin;
  8043. if ( invdirx >= 0 ) {
  8044. tmin = ( box.min.x - origin.x ) * invdirx;
  8045. tmax = ( box.max.x - origin.x ) * invdirx;
  8046. } else {
  8047. tmin = ( box.max.x - origin.x ) * invdirx;
  8048. tmax = ( box.min.x - origin.x ) * invdirx;
  8049. }
  8050. if ( invdiry >= 0 ) {
  8051. tymin = ( box.min.y - origin.y ) * invdiry;
  8052. tymax = ( box.max.y - origin.y ) * invdiry;
  8053. } else {
  8054. tymin = ( box.max.y - origin.y ) * invdiry;
  8055. tymax = ( box.min.y - origin.y ) * invdiry;
  8056. }
  8057. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  8058. // These lines also handle the case where tmin or tmax is NaN
  8059. // (result of 0 * Infinity). x !== x returns true if x is NaN
  8060. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  8061. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  8062. if ( invdirz >= 0 ) {
  8063. tzmin = ( box.min.z - origin.z ) * invdirz;
  8064. tzmax = ( box.max.z - origin.z ) * invdirz;
  8065. } else {
  8066. tzmin = ( box.max.z - origin.z ) * invdirz;
  8067. tzmax = ( box.min.z - origin.z ) * invdirz;
  8068. }
  8069. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  8070. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  8071. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  8072. //return point closest to the ray (positive side)
  8073. if ( tmax < 0 ) return null;
  8074. return this.at( tmin >= 0 ? tmin : tmax, target );
  8075. },
  8076. intersectsBox: ( function () {
  8077. var v = new Vector3();
  8078. return function intersectsBox( box ) {
  8079. return this.intersectBox( box, v ) !== null;
  8080. };
  8081. } )(),
  8082. intersectTriangle: function () {
  8083. // Compute the offset origin, edges, and normal.
  8084. var diff = new Vector3();
  8085. var edge1 = new Vector3();
  8086. var edge2 = new Vector3();
  8087. var normal = new Vector3();
  8088. return function intersectTriangle( a, b, c, backfaceCulling, target ) {
  8089. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  8090. edge1.subVectors( b, a );
  8091. edge2.subVectors( c, a );
  8092. normal.crossVectors( edge1, edge2 );
  8093. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  8094. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  8095. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  8096. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  8097. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  8098. var DdN = this.direction.dot( normal );
  8099. var sign;
  8100. if ( DdN > 0 ) {
  8101. if ( backfaceCulling ) return null;
  8102. sign = 1;
  8103. } else if ( DdN < 0 ) {
  8104. sign = - 1;
  8105. DdN = - DdN;
  8106. } else {
  8107. return null;
  8108. }
  8109. diff.subVectors( this.origin, a );
  8110. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  8111. // b1 < 0, no intersection
  8112. if ( DdQxE2 < 0 ) {
  8113. return null;
  8114. }
  8115. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  8116. // b2 < 0, no intersection
  8117. if ( DdE1xQ < 0 ) {
  8118. return null;
  8119. }
  8120. // b1+b2 > 1, no intersection
  8121. if ( DdQxE2 + DdE1xQ > DdN ) {
  8122. return null;
  8123. }
  8124. // Line intersects triangle, check if ray does.
  8125. var QdN = - sign * diff.dot( normal );
  8126. // t < 0, no intersection
  8127. if ( QdN < 0 ) {
  8128. return null;
  8129. }
  8130. // Ray intersects triangle.
  8131. return this.at( QdN / DdN, target );
  8132. };
  8133. }(),
  8134. applyMatrix4: function ( matrix4 ) {
  8135. this.origin.applyMatrix4( matrix4 );
  8136. this.direction.transformDirection( matrix4 );
  8137. return this;
  8138. },
  8139. equals: function ( ray ) {
  8140. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  8141. }
  8142. } );
  8143. /**
  8144. * @author bhouston / http://clara.io
  8145. * @author mrdoob / http://mrdoob.com/
  8146. */
  8147. function Triangle( a, b, c ) {
  8148. this.a = ( a !== undefined ) ? a : new Vector3();
  8149. this.b = ( b !== undefined ) ? b : new Vector3();
  8150. this.c = ( c !== undefined ) ? c : new Vector3();
  8151. }
  8152. Object.assign( Triangle, {
  8153. getNormal: function () {
  8154. var v0 = new Vector3();
  8155. return function getNormal( a, b, c, target ) {
  8156. if ( target === undefined ) {
  8157. console.warn( 'THREE.Triangle: .getNormal() target is now required' );
  8158. target = new Vector3();
  8159. }
  8160. target.subVectors( c, b );
  8161. v0.subVectors( a, b );
  8162. target.cross( v0 );
  8163. var targetLengthSq = target.lengthSq();
  8164. if ( targetLengthSq > 0 ) {
  8165. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  8166. }
  8167. return target.set( 0, 0, 0 );
  8168. };
  8169. }(),
  8170. // static/instance method to calculate barycentric coordinates
  8171. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  8172. getBarycoord: function () {
  8173. var v0 = new Vector3();
  8174. var v1 = new Vector3();
  8175. var v2 = new Vector3();
  8176. return function getBarycoord( point, a, b, c, target ) {
  8177. v0.subVectors( c, a );
  8178. v1.subVectors( b, a );
  8179. v2.subVectors( point, a );
  8180. var dot00 = v0.dot( v0 );
  8181. var dot01 = v0.dot( v1 );
  8182. var dot02 = v0.dot( v2 );
  8183. var dot11 = v1.dot( v1 );
  8184. var dot12 = v1.dot( v2 );
  8185. var denom = ( dot00 * dot11 - dot01 * dot01 );
  8186. if ( target === undefined ) {
  8187. console.warn( 'THREE.Triangle: .getBarycoord() target is now required' );
  8188. target = new Vector3();
  8189. }
  8190. // collinear or singular triangle
  8191. if ( denom === 0 ) {
  8192. // arbitrary location outside of triangle?
  8193. // not sure if this is the best idea, maybe should be returning undefined
  8194. return target.set( - 2, - 1, - 1 );
  8195. }
  8196. var invDenom = 1 / denom;
  8197. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  8198. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  8199. // barycentric coordinates must always sum to 1
  8200. return target.set( 1 - u - v, v, u );
  8201. };
  8202. }(),
  8203. containsPoint: function () {
  8204. var v1 = new Vector3();
  8205. return function containsPoint( point, a, b, c ) {
  8206. Triangle.getBarycoord( point, a, b, c, v1 );
  8207. return ( v1.x >= 0 ) && ( v1.y >= 0 ) && ( ( v1.x + v1.y ) <= 1 );
  8208. };
  8209. }(),
  8210. getUV: function () {
  8211. var barycoord = new Vector3();
  8212. return function getUV( point, p1, p2, p3, uv1, uv2, uv3, target ) {
  8213. this.getBarycoord( point, p1, p2, p3, barycoord );
  8214. target.set( 0, 0 );
  8215. target.addScaledVector( uv1, barycoord.x );
  8216. target.addScaledVector( uv2, barycoord.y );
  8217. target.addScaledVector( uv3, barycoord.z );
  8218. return target;
  8219. };
  8220. }()
  8221. } );
  8222. Object.assign( Triangle.prototype, {
  8223. set: function ( a, b, c ) {
  8224. this.a.copy( a );
  8225. this.b.copy( b );
  8226. this.c.copy( c );
  8227. return this;
  8228. },
  8229. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  8230. this.a.copy( points[ i0 ] );
  8231. this.b.copy( points[ i1 ] );
  8232. this.c.copy( points[ i2 ] );
  8233. return this;
  8234. },
  8235. clone: function () {
  8236. return new this.constructor().copy( this );
  8237. },
  8238. copy: function ( triangle ) {
  8239. this.a.copy( triangle.a );
  8240. this.b.copy( triangle.b );
  8241. this.c.copy( triangle.c );
  8242. return this;
  8243. },
  8244. getArea: function () {
  8245. var v0 = new Vector3();
  8246. var v1 = new Vector3();
  8247. return function getArea() {
  8248. v0.subVectors( this.c, this.b );
  8249. v1.subVectors( this.a, this.b );
  8250. return v0.cross( v1 ).length() * 0.5;
  8251. };
  8252. }(),
  8253. getMidpoint: function ( target ) {
  8254. if ( target === undefined ) {
  8255. console.warn( 'THREE.Triangle: .getMidpoint() target is now required' );
  8256. target = new Vector3();
  8257. }
  8258. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  8259. },
  8260. getNormal: function ( target ) {
  8261. return Triangle.getNormal( this.a, this.b, this.c, target );
  8262. },
  8263. getPlane: function ( target ) {
  8264. if ( target === undefined ) {
  8265. console.warn( 'THREE.Triangle: .getPlane() target is now required' );
  8266. target = new Vector3();
  8267. }
  8268. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  8269. },
  8270. getBarycoord: function ( point, target ) {
  8271. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  8272. },
  8273. containsPoint: function ( point ) {
  8274. return Triangle.containsPoint( point, this.a, this.b, this.c );
  8275. },
  8276. getUV: function ( point, uv1, uv2, uv3, result ) {
  8277. return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, result );
  8278. },
  8279. intersectsBox: function ( box ) {
  8280. return box.intersectsTriangle( this );
  8281. },
  8282. closestPointToPoint: function () {
  8283. var vab = new Vector3();
  8284. var vac = new Vector3();
  8285. var vbc = new Vector3();
  8286. var vap = new Vector3();
  8287. var vbp = new Vector3();
  8288. var vcp = new Vector3();
  8289. return function closestPointToPoint( p, target ) {
  8290. if ( target === undefined ) {
  8291. console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
  8292. target = new Vector3();
  8293. }
  8294. var a = this.a, b = this.b, c = this.c;
  8295. var v, w;
  8296. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  8297. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  8298. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  8299. // basically, we're distinguishing which of the voronoi regions of the triangle
  8300. // the point lies in with the minimum amount of redundant computation.
  8301. vab.subVectors( b, a );
  8302. vac.subVectors( c, a );
  8303. vap.subVectors( p, a );
  8304. var d1 = vab.dot( vap );
  8305. var d2 = vac.dot( vap );
  8306. if ( d1 <= 0 && d2 <= 0 ) {
  8307. // vertex region of A; barycentric coords (1, 0, 0)
  8308. return target.copy( a );
  8309. }
  8310. vbp.subVectors( p, b );
  8311. var d3 = vab.dot( vbp );
  8312. var d4 = vac.dot( vbp );
  8313. if ( d3 >= 0 && d4 <= d3 ) {
  8314. // vertex region of B; barycentric coords (0, 1, 0)
  8315. return target.copy( b );
  8316. }
  8317. var vc = d1 * d4 - d3 * d2;
  8318. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  8319. v = d1 / ( d1 - d3 );
  8320. // edge region of AB; barycentric coords (1-v, v, 0)
  8321. return target.copy( a ).addScaledVector( vab, v );
  8322. }
  8323. vcp.subVectors( p, c );
  8324. var d5 = vab.dot( vcp );
  8325. var d6 = vac.dot( vcp );
  8326. if ( d6 >= 0 && d5 <= d6 ) {
  8327. // vertex region of C; barycentric coords (0, 0, 1)
  8328. return target.copy( c );
  8329. }
  8330. var vb = d5 * d2 - d1 * d6;
  8331. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  8332. w = d2 / ( d2 - d6 );
  8333. // edge region of AC; barycentric coords (1-w, 0, w)
  8334. return target.copy( a ).addScaledVector( vac, w );
  8335. }
  8336. var va = d3 * d6 - d5 * d4;
  8337. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  8338. vbc.subVectors( c, b );
  8339. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  8340. // edge region of BC; barycentric coords (0, 1-w, w)
  8341. return target.copy( b ).addScaledVector( vbc, w ); // edge region of BC
  8342. }
  8343. // face region
  8344. var denom = 1 / ( va + vb + vc );
  8345. // u = va * denom
  8346. v = vb * denom;
  8347. w = vc * denom;
  8348. return target.copy( a ).addScaledVector( vab, v ).addScaledVector( vac, w );
  8349. };
  8350. }(),
  8351. equals: function ( triangle ) {
  8352. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  8353. }
  8354. } );
  8355. /**
  8356. * @author mrdoob / http://mrdoob.com/
  8357. * @author alteredq / http://alteredqualia.com/
  8358. *
  8359. * parameters = {
  8360. * color: <hex>,
  8361. * opacity: <float>,
  8362. * map: new THREE.Texture( <Image> ),
  8363. *
  8364. * lightMap: new THREE.Texture( <Image> ),
  8365. * lightMapIntensity: <float>
  8366. *
  8367. * aoMap: new THREE.Texture( <Image> ),
  8368. * aoMapIntensity: <float>
  8369. *
  8370. * specularMap: new THREE.Texture( <Image> ),
  8371. *
  8372. * alphaMap: new THREE.Texture( <Image> ),
  8373. *
  8374. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  8375. * combine: THREE.Multiply,
  8376. * reflectivity: <float>,
  8377. * refractionRatio: <float>,
  8378. *
  8379. * depthTest: <bool>,
  8380. * depthWrite: <bool>,
  8381. *
  8382. * wireframe: <boolean>,
  8383. * wireframeLinewidth: <float>,
  8384. *
  8385. * skinning: <bool>,
  8386. * morphTargets: <bool>
  8387. * }
  8388. */
  8389. function MeshBasicMaterial( parameters ) {
  8390. Material.call( this );
  8391. this.type = 'MeshBasicMaterial';
  8392. this.color = new Color( 0xffffff ); // emissive
  8393. this.map = null;
  8394. this.lightMap = null;
  8395. this.lightMapIntensity = 1.0;
  8396. this.aoMap = null;
  8397. this.aoMapIntensity = 1.0;
  8398. this.specularMap = null;
  8399. this.alphaMap = null;
  8400. this.envMap = null;
  8401. this.combine = MultiplyOperation;
  8402. this.reflectivity = 1;
  8403. this.refractionRatio = 0.98;
  8404. this.wireframe = false;
  8405. this.wireframeLinewidth = 1;
  8406. this.wireframeLinecap = 'round';
  8407. this.wireframeLinejoin = 'round';
  8408. this.skinning = false;
  8409. this.morphTargets = false;
  8410. this.lights = false;
  8411. this.setValues( parameters );
  8412. }
  8413. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  8414. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  8415. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  8416. MeshBasicMaterial.prototype.copy = function ( source ) {
  8417. Material.prototype.copy.call( this, source );
  8418. this.color.copy( source.color );
  8419. this.map = source.map;
  8420. this.lightMap = source.lightMap;
  8421. this.lightMapIntensity = source.lightMapIntensity;
  8422. this.aoMap = source.aoMap;
  8423. this.aoMapIntensity = source.aoMapIntensity;
  8424. this.specularMap = source.specularMap;
  8425. this.alphaMap = source.alphaMap;
  8426. this.envMap = source.envMap;
  8427. this.combine = source.combine;
  8428. this.reflectivity = source.reflectivity;
  8429. this.refractionRatio = source.refractionRatio;
  8430. this.wireframe = source.wireframe;
  8431. this.wireframeLinewidth = source.wireframeLinewidth;
  8432. this.wireframeLinecap = source.wireframeLinecap;
  8433. this.wireframeLinejoin = source.wireframeLinejoin;
  8434. this.skinning = source.skinning;
  8435. this.morphTargets = source.morphTargets;
  8436. return this;
  8437. };
  8438. /**
  8439. * @author mrdoob / http://mrdoob.com/
  8440. * @author alteredq / http://alteredqualia.com/
  8441. * @author mikael emtinger / http://gomo.se/
  8442. * @author jonobr1 / http://jonobr1.com/
  8443. */
  8444. function Mesh( geometry, material ) {
  8445. Object3D.call( this );
  8446. this.type = 'Mesh';
  8447. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  8448. this.material = material !== undefined ? material : new MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  8449. this.drawMode = TrianglesDrawMode;
  8450. this.updateMorphTargets();
  8451. }
  8452. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  8453. constructor: Mesh,
  8454. isMesh: true,
  8455. setDrawMode: function ( value ) {
  8456. this.drawMode = value;
  8457. },
  8458. copy: function ( source ) {
  8459. Object3D.prototype.copy.call( this, source );
  8460. this.drawMode = source.drawMode;
  8461. if ( source.morphTargetInfluences !== undefined ) {
  8462. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  8463. }
  8464. if ( source.morphTargetDictionary !== undefined ) {
  8465. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  8466. }
  8467. return this;
  8468. },
  8469. updateMorphTargets: function () {
  8470. var geometry = this.geometry;
  8471. var m, ml, name;
  8472. if ( geometry.isBufferGeometry ) {
  8473. var morphAttributes = geometry.morphAttributes;
  8474. var keys = Object.keys( morphAttributes );
  8475. if ( keys.length > 0 ) {
  8476. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  8477. if ( morphAttribute !== undefined ) {
  8478. this.morphTargetInfluences = [];
  8479. this.morphTargetDictionary = {};
  8480. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  8481. name = morphAttribute[ m ].name || String( m );
  8482. this.morphTargetInfluences.push( 0 );
  8483. this.morphTargetDictionary[ name ] = m;
  8484. }
  8485. }
  8486. }
  8487. } else {
  8488. var morphTargets = geometry.morphTargets;
  8489. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  8490. console.error( 'THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  8491. }
  8492. }
  8493. },
  8494. raycast: ( function () {
  8495. var inverseMatrix = new Matrix4();
  8496. var ray = new Ray();
  8497. var sphere = new Sphere();
  8498. var vA = new Vector3();
  8499. var vB = new Vector3();
  8500. var vC = new Vector3();
  8501. var tempA = new Vector3();
  8502. var tempB = new Vector3();
  8503. var tempC = new Vector3();
  8504. var uvA = new Vector2();
  8505. var uvB = new Vector2();
  8506. var uvC = new Vector2();
  8507. var intersectionPoint = new Vector3();
  8508. var intersectionPointWorld = new Vector3();
  8509. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  8510. var intersect;
  8511. if ( material.side === BackSide ) {
  8512. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  8513. } else {
  8514. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  8515. }
  8516. if ( intersect === null ) return null;
  8517. intersectionPointWorld.copy( point );
  8518. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  8519. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  8520. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  8521. return {
  8522. distance: distance,
  8523. point: intersectionPointWorld.clone(),
  8524. object: object
  8525. };
  8526. }
  8527. function checkBufferGeometryIntersection( object, material, raycaster, ray, position, uv, a, b, c ) {
  8528. vA.fromBufferAttribute( position, a );
  8529. vB.fromBufferAttribute( position, b );
  8530. vC.fromBufferAttribute( position, c );
  8531. var intersection = checkIntersection( object, material, raycaster, ray, vA, vB, vC, intersectionPoint );
  8532. if ( intersection ) {
  8533. if ( uv ) {
  8534. uvA.fromBufferAttribute( uv, a );
  8535. uvB.fromBufferAttribute( uv, b );
  8536. uvC.fromBufferAttribute( uv, c );
  8537. intersection.uv = Triangle.getUV( intersectionPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() );
  8538. }
  8539. var face = new Face3( a, b, c );
  8540. Triangle.getNormal( vA, vB, vC, face.normal );
  8541. intersection.face = face;
  8542. }
  8543. return intersection;
  8544. }
  8545. return function raycast( raycaster, intersects ) {
  8546. var geometry = this.geometry;
  8547. var material = this.material;
  8548. var matrixWorld = this.matrixWorld;
  8549. if ( material === undefined ) return;
  8550. // Checking boundingSphere distance to ray
  8551. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  8552. sphere.copy( geometry.boundingSphere );
  8553. sphere.applyMatrix4( matrixWorld );
  8554. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  8555. //
  8556. inverseMatrix.getInverse( matrixWorld );
  8557. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  8558. // Check boundingBox before continuing
  8559. if ( geometry.boundingBox !== null ) {
  8560. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  8561. }
  8562. var intersection;
  8563. if ( geometry.isBufferGeometry ) {
  8564. var a, b, c;
  8565. var index = geometry.index;
  8566. var position = geometry.attributes.position;
  8567. var uv = geometry.attributes.uv;
  8568. var groups = geometry.groups;
  8569. var drawRange = geometry.drawRange;
  8570. var i, j, il, jl;
  8571. var group, groupMaterial;
  8572. var start, end;
  8573. if ( index !== null ) {
  8574. // indexed buffer geometry
  8575. if ( Array.isArray( material ) ) {
  8576. for ( i = 0, il = groups.length; i < il; i ++ ) {
  8577. group = groups[ i ];
  8578. groupMaterial = material[ group.materialIndex ];
  8579. start = Math.max( group.start, drawRange.start );
  8580. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  8581. for ( j = start, jl = end; j < jl; j += 3 ) {
  8582. a = index.getX( j );
  8583. b = index.getX( j + 1 );
  8584. c = index.getX( j + 2 );
  8585. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, ray, position, uv, a, b, c );
  8586. if ( intersection ) {
  8587. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  8588. intersects.push( intersection );
  8589. }
  8590. }
  8591. }
  8592. } else {
  8593. start = Math.max( 0, drawRange.start );
  8594. end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  8595. for ( i = start, il = end; i < il; i += 3 ) {
  8596. a = index.getX( i );
  8597. b = index.getX( i + 1 );
  8598. c = index.getX( i + 2 );
  8599. intersection = checkBufferGeometryIntersection( this, material, raycaster, ray, position, uv, a, b, c );
  8600. if ( intersection ) {
  8601. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  8602. intersects.push( intersection );
  8603. }
  8604. }
  8605. }
  8606. } else if ( position !== undefined ) {
  8607. // non-indexed buffer geometry
  8608. if ( Array.isArray( material ) ) {
  8609. for ( i = 0, il = groups.length; i < il; i ++ ) {
  8610. group = groups[ i ];
  8611. groupMaterial = material[ group.materialIndex ];
  8612. start = Math.max( group.start, drawRange.start );
  8613. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  8614. for ( j = start, jl = end; j < jl; j += 3 ) {
  8615. a = j;
  8616. b = j + 1;
  8617. c = j + 2;
  8618. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, ray, position, uv, a, b, c );
  8619. if ( intersection ) {
  8620. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  8621. intersects.push( intersection );
  8622. }
  8623. }
  8624. }
  8625. } else {
  8626. start = Math.max( 0, drawRange.start );
  8627. end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  8628. for ( i = start, il = end; i < il; i += 3 ) {
  8629. a = i;
  8630. b = i + 1;
  8631. c = i + 2;
  8632. intersection = checkBufferGeometryIntersection( this, material, raycaster, ray, position, uv, a, b, c );
  8633. if ( intersection ) {
  8634. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  8635. intersects.push( intersection );
  8636. }
  8637. }
  8638. }
  8639. }
  8640. } else if ( geometry.isGeometry ) {
  8641. var fvA, fvB, fvC;
  8642. var isMultiMaterial = Array.isArray( material );
  8643. var vertices = geometry.vertices;
  8644. var faces = geometry.faces;
  8645. var uvs;
  8646. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  8647. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  8648. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  8649. var face = faces[ f ];
  8650. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  8651. if ( faceMaterial === undefined ) continue;
  8652. fvA = vertices[ face.a ];
  8653. fvB = vertices[ face.b ];
  8654. fvC = vertices[ face.c ];
  8655. if ( faceMaterial.morphTargets === true ) {
  8656. var morphTargets = geometry.morphTargets;
  8657. var morphInfluences = this.morphTargetInfluences;
  8658. vA.set( 0, 0, 0 );
  8659. vB.set( 0, 0, 0 );
  8660. vC.set( 0, 0, 0 );
  8661. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  8662. var influence = morphInfluences[ t ];
  8663. if ( influence === 0 ) continue;
  8664. var targets = morphTargets[ t ].vertices;
  8665. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  8666. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  8667. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  8668. }
  8669. vA.add( fvA );
  8670. vB.add( fvB );
  8671. vC.add( fvC );
  8672. fvA = vA;
  8673. fvB = vB;
  8674. fvC = vC;
  8675. }
  8676. intersection = checkIntersection( this, faceMaterial, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  8677. if ( intersection ) {
  8678. if ( uvs && uvs[ f ] ) {
  8679. var uvs_f = uvs[ f ];
  8680. uvA.copy( uvs_f[ 0 ] );
  8681. uvB.copy( uvs_f[ 1 ] );
  8682. uvC.copy( uvs_f[ 2 ] );
  8683. intersection.uv = Triangle.getUV( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC, new Vector2() );
  8684. }
  8685. intersection.face = face;
  8686. intersection.faceIndex = f;
  8687. intersects.push( intersection );
  8688. }
  8689. }
  8690. }
  8691. };
  8692. }() ),
  8693. clone: function () {
  8694. return new this.constructor( this.geometry, this.material ).copy( this );
  8695. }
  8696. } );
  8697. /**
  8698. * @author mrdoob / http://mrdoob.com/
  8699. */
  8700. function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
  8701. var clearColor = new Color( 0x000000 );
  8702. var clearAlpha = 0;
  8703. var planeMesh;
  8704. var boxMesh;
  8705. // Store the current background texture and its `version`
  8706. // so we can recompile the material accordingly.
  8707. var currentBackground = null;
  8708. var currentBackgroundVersion = 0;
  8709. function render( renderList, scene, camera, forceClear ) {
  8710. var background = scene.background;
  8711. if ( background === null ) {
  8712. setClear( clearColor, clearAlpha );
  8713. currentBackground = null;
  8714. currentBackgroundVersion = 0;
  8715. } else if ( background && background.isColor ) {
  8716. setClear( background, 1 );
  8717. forceClear = true;
  8718. currentBackground = null;
  8719. currentBackgroundVersion = 0;
  8720. }
  8721. if ( renderer.autoClear || forceClear ) {
  8722. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  8723. }
  8724. if ( background && ( background.isCubeTexture || background.isWebGLRenderTargetCube ) ) {
  8725. if ( boxMesh === undefined ) {
  8726. boxMesh = new Mesh(
  8727. new BoxBufferGeometry( 1, 1, 1 ),
  8728. new ShaderMaterial( {
  8729. type: 'BackgroundCubeMaterial',
  8730. uniforms: cloneUniforms( ShaderLib.cube.uniforms ),
  8731. vertexShader: ShaderLib.cube.vertexShader,
  8732. fragmentShader: ShaderLib.cube.fragmentShader,
  8733. side: BackSide,
  8734. depthTest: true,
  8735. depthWrite: false,
  8736. fog: false
  8737. } )
  8738. );
  8739. boxMesh.geometry.removeAttribute( 'normal' );
  8740. boxMesh.geometry.removeAttribute( 'uv' );
  8741. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  8742. this.matrixWorld.copyPosition( camera.matrixWorld );
  8743. };
  8744. // enable code injection for non-built-in material
  8745. Object.defineProperty( boxMesh.material, 'map', {
  8746. get: function () {
  8747. return this.uniforms.tCube.value;
  8748. }
  8749. } );
  8750. objects.update( boxMesh );
  8751. }
  8752. var texture = background.isWebGLRenderTargetCube ? background.texture : background;
  8753. boxMesh.material.uniforms.tCube.value = texture;
  8754. boxMesh.material.uniforms.tFlip.value = ( background.isWebGLRenderTargetCube ) ? 1 : - 1;
  8755. if ( currentBackground !== background ||
  8756. currentBackgroundVersion !== texture.version ) {
  8757. boxMesh.material.needsUpdate = true;
  8758. currentBackground = background;
  8759. currentBackgroundVersion = texture.version;
  8760. }
  8761. // push to the pre-sorted opaque render list
  8762. renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null );
  8763. } else if ( background && background.isTexture ) {
  8764. if ( planeMesh === undefined ) {
  8765. planeMesh = new Mesh(
  8766. new PlaneBufferGeometry( 2, 2 ),
  8767. new ShaderMaterial( {
  8768. type: 'BackgroundMaterial',
  8769. uniforms: cloneUniforms( ShaderLib.background.uniforms ),
  8770. vertexShader: ShaderLib.background.vertexShader,
  8771. fragmentShader: ShaderLib.background.fragmentShader,
  8772. side: FrontSide,
  8773. depthTest: false,
  8774. depthWrite: false,
  8775. fog: false
  8776. } )
  8777. );
  8778. planeMesh.geometry.removeAttribute( 'normal' );
  8779. // enable code injection for non-built-in material
  8780. Object.defineProperty( planeMesh.material, 'map', {
  8781. get: function () {
  8782. return this.uniforms.t2D.value;
  8783. }
  8784. } );
  8785. objects.update( planeMesh );
  8786. }
  8787. planeMesh.material.uniforms.t2D.value = background;
  8788. if ( background.matrixAutoUpdate === true ) {
  8789. background.updateMatrix();
  8790. }
  8791. planeMesh.material.uniforms.uvTransform.value.copy( background.matrix );
  8792. if ( currentBackground !== background ||
  8793. currentBackgroundVersion !== background.version ) {
  8794. planeMesh.material.needsUpdate = true;
  8795. currentBackground = background;
  8796. currentBackgroundVersion = background.version;
  8797. }
  8798. // push to the pre-sorted opaque render list
  8799. renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null );
  8800. }
  8801. }
  8802. function setClear( color, alpha ) {
  8803. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  8804. }
  8805. return {
  8806. getClearColor: function () {
  8807. return clearColor;
  8808. },
  8809. setClearColor: function ( color, alpha ) {
  8810. clearColor.set( color );
  8811. clearAlpha = alpha !== undefined ? alpha : 1;
  8812. setClear( clearColor, clearAlpha );
  8813. },
  8814. getClearAlpha: function () {
  8815. return clearAlpha;
  8816. },
  8817. setClearAlpha: function ( alpha ) {
  8818. clearAlpha = alpha;
  8819. setClear( clearColor, clearAlpha );
  8820. },
  8821. render: render
  8822. };
  8823. }
  8824. /**
  8825. * @author mrdoob / http://mrdoob.com/
  8826. */
  8827. function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
  8828. var mode;
  8829. function setMode( value ) {
  8830. mode = value;
  8831. }
  8832. function render( start, count ) {
  8833. gl.drawArrays( mode, start, count );
  8834. info.update( count, mode );
  8835. }
  8836. function renderInstances( geometry, start, count ) {
  8837. var extension;
  8838. if ( capabilities.isWebGL2 ) {
  8839. extension = gl;
  8840. } else {
  8841. extension = extensions.get( 'ANGLE_instanced_arrays' );
  8842. if ( extension === null ) {
  8843. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  8844. return;
  8845. }
  8846. }
  8847. extension[ capabilities.isWebGL2 ? 'drawArraysInstanced' : 'drawArraysInstancedANGLE' ]( mode, start, count, geometry.maxInstancedCount );
  8848. info.update( count, mode, geometry.maxInstancedCount );
  8849. }
  8850. //
  8851. this.setMode = setMode;
  8852. this.render = render;
  8853. this.renderInstances = renderInstances;
  8854. }
  8855. /**
  8856. * @author mrdoob / http://mrdoob.com/
  8857. */
  8858. function WebGLCapabilities( gl, extensions, parameters ) {
  8859. var maxAnisotropy;
  8860. function getMaxAnisotropy() {
  8861. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  8862. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  8863. if ( extension !== null ) {
  8864. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  8865. } else {
  8866. maxAnisotropy = 0;
  8867. }
  8868. return maxAnisotropy;
  8869. }
  8870. function getMaxPrecision( precision ) {
  8871. if ( precision === 'highp' ) {
  8872. if ( gl.getShaderPrecisionFormat( 35633, 36338 ).precision > 0 &&
  8873. gl.getShaderPrecisionFormat( 35632, 36338 ).precision > 0 ) {
  8874. return 'highp';
  8875. }
  8876. precision = 'mediump';
  8877. }
  8878. if ( precision === 'mediump' ) {
  8879. if ( gl.getShaderPrecisionFormat( 35633, 36337 ).precision > 0 &&
  8880. gl.getShaderPrecisionFormat( 35632, 36337 ).precision > 0 ) {
  8881. return 'mediump';
  8882. }
  8883. }
  8884. return 'lowp';
  8885. }
  8886. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext;
  8887. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  8888. var maxPrecision = getMaxPrecision( precision );
  8889. if ( maxPrecision !== precision ) {
  8890. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  8891. precision = maxPrecision;
  8892. }
  8893. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  8894. var maxTextures = gl.getParameter( 34930 );
  8895. var maxVertexTextures = gl.getParameter( 35660 );
  8896. var maxTextureSize = gl.getParameter( 3379 );
  8897. var maxCubemapSize = gl.getParameter( 34076 );
  8898. var maxAttributes = gl.getParameter( 34921 );
  8899. var maxVertexUniforms = gl.getParameter( 36347 );
  8900. var maxVaryings = gl.getParameter( 36348 );
  8901. var maxFragmentUniforms = gl.getParameter( 36349 );
  8902. var vertexTextures = maxVertexTextures > 0;
  8903. var floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' );
  8904. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  8905. var maxSamples = isWebGL2 ? gl.getParameter( 36183 ) : 0;
  8906. return {
  8907. isWebGL2: isWebGL2,
  8908. getMaxAnisotropy: getMaxAnisotropy,
  8909. getMaxPrecision: getMaxPrecision,
  8910. precision: precision,
  8911. logarithmicDepthBuffer: logarithmicDepthBuffer,
  8912. maxTextures: maxTextures,
  8913. maxVertexTextures: maxVertexTextures,
  8914. maxTextureSize: maxTextureSize,
  8915. maxCubemapSize: maxCubemapSize,
  8916. maxAttributes: maxAttributes,
  8917. maxVertexUniforms: maxVertexUniforms,
  8918. maxVaryings: maxVaryings,
  8919. maxFragmentUniforms: maxFragmentUniforms,
  8920. vertexTextures: vertexTextures,
  8921. floatFragmentTextures: floatFragmentTextures,
  8922. floatVertexTextures: floatVertexTextures,
  8923. maxSamples: maxSamples
  8924. };
  8925. }
  8926. /**
  8927. * @author tschw
  8928. */
  8929. function WebGLClipping() {
  8930. var scope = this,
  8931. globalState = null,
  8932. numGlobalPlanes = 0,
  8933. localClippingEnabled = false,
  8934. renderingShadows = false,
  8935. plane = new Plane(),
  8936. viewNormalMatrix = new Matrix3(),
  8937. uniform = { value: null, needsUpdate: false };
  8938. this.uniform = uniform;
  8939. this.numPlanes = 0;
  8940. this.numIntersection = 0;
  8941. this.init = function ( planes, enableLocalClipping, camera ) {
  8942. var enabled =
  8943. planes.length !== 0 ||
  8944. enableLocalClipping ||
  8945. // enable state of previous frame - the clipping code has to
  8946. // run another frame in order to reset the state:
  8947. numGlobalPlanes !== 0 ||
  8948. localClippingEnabled;
  8949. localClippingEnabled = enableLocalClipping;
  8950. globalState = projectPlanes( planes, camera, 0 );
  8951. numGlobalPlanes = planes.length;
  8952. return enabled;
  8953. };
  8954. this.beginShadows = function () {
  8955. renderingShadows = true;
  8956. projectPlanes( null );
  8957. };
  8958. this.endShadows = function () {
  8959. renderingShadows = false;
  8960. resetGlobalState();
  8961. };
  8962. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  8963. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  8964. // there's no local clipping
  8965. if ( renderingShadows ) {
  8966. // there's no global clipping
  8967. projectPlanes( null );
  8968. } else {
  8969. resetGlobalState();
  8970. }
  8971. } else {
  8972. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  8973. lGlobal = nGlobal * 4,
  8974. dstArray = cache.clippingState || null;
  8975. uniform.value = dstArray; // ensure unique state
  8976. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  8977. for ( var i = 0; i !== lGlobal; ++ i ) {
  8978. dstArray[ i ] = globalState[ i ];
  8979. }
  8980. cache.clippingState = dstArray;
  8981. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  8982. this.numPlanes += nGlobal;
  8983. }
  8984. };
  8985. function resetGlobalState() {
  8986. if ( uniform.value !== globalState ) {
  8987. uniform.value = globalState;
  8988. uniform.needsUpdate = numGlobalPlanes > 0;
  8989. }
  8990. scope.numPlanes = numGlobalPlanes;
  8991. scope.numIntersection = 0;
  8992. }
  8993. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  8994. var nPlanes = planes !== null ? planes.length : 0,
  8995. dstArray = null;
  8996. if ( nPlanes !== 0 ) {
  8997. dstArray = uniform.value;
  8998. if ( skipTransform !== true || dstArray === null ) {
  8999. var flatSize = dstOffset + nPlanes * 4,
  9000. viewMatrix = camera.matrixWorldInverse;
  9001. viewNormalMatrix.getNormalMatrix( viewMatrix );
  9002. if ( dstArray === null || dstArray.length < flatSize ) {
  9003. dstArray = new Float32Array( flatSize );
  9004. }
  9005. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  9006. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  9007. plane.normal.toArray( dstArray, i4 );
  9008. dstArray[ i4 + 3 ] = plane.constant;
  9009. }
  9010. }
  9011. uniform.value = dstArray;
  9012. uniform.needsUpdate = true;
  9013. }
  9014. scope.numPlanes = nPlanes;
  9015. return dstArray;
  9016. }
  9017. }
  9018. /**
  9019. * @author mrdoob / http://mrdoob.com/
  9020. */
  9021. function WebGLExtensions( gl ) {
  9022. var extensions = {};
  9023. return {
  9024. get: function ( name ) {
  9025. if ( extensions[ name ] !== undefined ) {
  9026. return extensions[ name ];
  9027. }
  9028. var extension;
  9029. switch ( name ) {
  9030. case 'WEBGL_depth_texture':
  9031. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  9032. break;
  9033. case 'EXT_texture_filter_anisotropic':
  9034. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  9035. break;
  9036. case 'WEBGL_compressed_texture_s3tc':
  9037. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  9038. break;
  9039. case 'WEBGL_compressed_texture_pvrtc':
  9040. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  9041. break;
  9042. default:
  9043. extension = gl.getExtension( name );
  9044. }
  9045. if ( extension === null ) {
  9046. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  9047. }
  9048. extensions[ name ] = extension;
  9049. return extension;
  9050. }
  9051. };
  9052. }
  9053. /**
  9054. * @author mrdoob / http://mrdoob.com/
  9055. */
  9056. function WebGLGeometries( gl, attributes, info ) {
  9057. var geometries = {};
  9058. var wireframeAttributes = {};
  9059. function onGeometryDispose( event ) {
  9060. var geometry = event.target;
  9061. var buffergeometry = geometries[ geometry.id ];
  9062. if ( buffergeometry.index !== null ) {
  9063. attributes.remove( buffergeometry.index );
  9064. }
  9065. for ( var name in buffergeometry.attributes ) {
  9066. attributes.remove( buffergeometry.attributes[ name ] );
  9067. }
  9068. geometry.removeEventListener( 'dispose', onGeometryDispose );
  9069. delete geometries[ geometry.id ];
  9070. var attribute = wireframeAttributes[ buffergeometry.id ];
  9071. if ( attribute ) {
  9072. attributes.remove( attribute );
  9073. delete wireframeAttributes[ buffergeometry.id ];
  9074. }
  9075. //
  9076. info.memory.geometries --;
  9077. }
  9078. function get( object, geometry ) {
  9079. var buffergeometry = geometries[ geometry.id ];
  9080. if ( buffergeometry ) return buffergeometry;
  9081. geometry.addEventListener( 'dispose', onGeometryDispose );
  9082. if ( geometry.isBufferGeometry ) {
  9083. buffergeometry = geometry;
  9084. } else if ( geometry.isGeometry ) {
  9085. if ( geometry._bufferGeometry === undefined ) {
  9086. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  9087. }
  9088. buffergeometry = geometry._bufferGeometry;
  9089. }
  9090. geometries[ geometry.id ] = buffergeometry;
  9091. info.memory.geometries ++;
  9092. return buffergeometry;
  9093. }
  9094. function update( geometry ) {
  9095. var index = geometry.index;
  9096. var geometryAttributes = geometry.attributes;
  9097. if ( index !== null ) {
  9098. attributes.update( index, 34963 );
  9099. }
  9100. for ( var name in geometryAttributes ) {
  9101. attributes.update( geometryAttributes[ name ], 34962 );
  9102. }
  9103. // morph targets
  9104. var morphAttributes = geometry.morphAttributes;
  9105. for ( var name in morphAttributes ) {
  9106. var array = morphAttributes[ name ];
  9107. for ( var i = 0, l = array.length; i < l; i ++ ) {
  9108. attributes.update( array[ i ], 34962 );
  9109. }
  9110. }
  9111. }
  9112. function getWireframeAttribute( geometry ) {
  9113. var attribute = wireframeAttributes[ geometry.id ];
  9114. if ( attribute ) return attribute;
  9115. var indices = [];
  9116. var geometryIndex = geometry.index;
  9117. var geometryAttributes = geometry.attributes;
  9118. // console.time( 'wireframe' );
  9119. if ( geometryIndex !== null ) {
  9120. var array = geometryIndex.array;
  9121. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  9122. var a = array[ i + 0 ];
  9123. var b = array[ i + 1 ];
  9124. var c = array[ i + 2 ];
  9125. indices.push( a, b, b, c, c, a );
  9126. }
  9127. } else {
  9128. var array = geometryAttributes.position.array;
  9129. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  9130. var a = i + 0;
  9131. var b = i + 1;
  9132. var c = i + 2;
  9133. indices.push( a, b, b, c, c, a );
  9134. }
  9135. }
  9136. // console.timeEnd( 'wireframe' );
  9137. attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  9138. attributes.update( attribute, 34963 );
  9139. wireframeAttributes[ geometry.id ] = attribute;
  9140. return attribute;
  9141. }
  9142. return {
  9143. get: get,
  9144. update: update,
  9145. getWireframeAttribute: getWireframeAttribute
  9146. };
  9147. }
  9148. /**
  9149. * @author mrdoob / http://mrdoob.com/
  9150. */
  9151. function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
  9152. var mode;
  9153. function setMode( value ) {
  9154. mode = value;
  9155. }
  9156. var type, bytesPerElement;
  9157. function setIndex( value ) {
  9158. type = value.type;
  9159. bytesPerElement = value.bytesPerElement;
  9160. }
  9161. function render( start, count ) {
  9162. gl.drawElements( mode, count, type, start * bytesPerElement );
  9163. info.update( count, mode );
  9164. }
  9165. function renderInstances( geometry, start, count ) {
  9166. var extension;
  9167. if ( capabilities.isWebGL2 ) {
  9168. extension = gl;
  9169. } else {
  9170. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  9171. if ( extension === null ) {
  9172. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9173. return;
  9174. }
  9175. }
  9176. extension[ capabilities.isWebGL2 ? 'drawElementsInstanced' : 'drawElementsInstancedANGLE' ]( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
  9177. info.update( count, mode, geometry.maxInstancedCount );
  9178. }
  9179. //
  9180. this.setMode = setMode;
  9181. this.setIndex = setIndex;
  9182. this.render = render;
  9183. this.renderInstances = renderInstances;
  9184. }
  9185. /**
  9186. * @author Mugen87 / https://github.com/Mugen87
  9187. */
  9188. function WebGLInfo( gl ) {
  9189. var memory = {
  9190. geometries: 0,
  9191. textures: 0
  9192. };
  9193. var render = {
  9194. frame: 0,
  9195. calls: 0,
  9196. triangles: 0,
  9197. points: 0,
  9198. lines: 0
  9199. };
  9200. function update( count, mode, instanceCount ) {
  9201. instanceCount = instanceCount || 1;
  9202. render.calls ++;
  9203. switch ( mode ) {
  9204. case 4:
  9205. render.triangles += instanceCount * ( count / 3 );
  9206. break;
  9207. case 5:
  9208. case 6:
  9209. render.triangles += instanceCount * ( count - 2 );
  9210. break;
  9211. case 1:
  9212. render.lines += instanceCount * ( count / 2 );
  9213. break;
  9214. case 3:
  9215. render.lines += instanceCount * ( count - 1 );
  9216. break;
  9217. case 2:
  9218. render.lines += instanceCount * count;
  9219. break;
  9220. case 0:
  9221. render.points += instanceCount * count;
  9222. break;
  9223. default:
  9224. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  9225. break;
  9226. }
  9227. }
  9228. function reset() {
  9229. render.frame ++;
  9230. render.calls = 0;
  9231. render.triangles = 0;
  9232. render.points = 0;
  9233. render.lines = 0;
  9234. }
  9235. return {
  9236. memory: memory,
  9237. render: render,
  9238. programs: null,
  9239. autoReset: true,
  9240. reset: reset,
  9241. update: update
  9242. };
  9243. }
  9244. /**
  9245. * @author mrdoob / http://mrdoob.com/
  9246. */
  9247. function absNumericalSort( a, b ) {
  9248. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  9249. }
  9250. function WebGLMorphtargets( gl ) {
  9251. var influencesList = {};
  9252. var morphInfluences = new Float32Array( 8 );
  9253. function update( object, geometry, material, program ) {
  9254. var objectInfluences = object.morphTargetInfluences;
  9255. var length = objectInfluences.length;
  9256. var influences = influencesList[ geometry.id ];
  9257. if ( influences === undefined ) {
  9258. // initialise list
  9259. influences = [];
  9260. for ( var i = 0; i < length; i ++ ) {
  9261. influences[ i ] = [ i, 0 ];
  9262. }
  9263. influencesList[ geometry.id ] = influences;
  9264. }
  9265. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9266. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9267. // Remove current morphAttributes
  9268. for ( var i = 0; i < length; i ++ ) {
  9269. var influence = influences[ i ];
  9270. if ( influence[ 1 ] !== 0 ) {
  9271. if ( morphTargets ) geometry.removeAttribute( 'morphTarget' + i );
  9272. if ( morphNormals ) geometry.removeAttribute( 'morphNormal' + i );
  9273. }
  9274. }
  9275. // Collect influences
  9276. for ( var i = 0; i < length; i ++ ) {
  9277. var influence = influences[ i ];
  9278. influence[ 0 ] = i;
  9279. influence[ 1 ] = objectInfluences[ i ];
  9280. }
  9281. influences.sort( absNumericalSort );
  9282. // Add morphAttributes
  9283. for ( var i = 0; i < 8; i ++ ) {
  9284. var influence = influences[ i ];
  9285. if ( influence ) {
  9286. var index = influence[ 0 ];
  9287. var value = influence[ 1 ];
  9288. if ( value ) {
  9289. if ( morphTargets ) geometry.addAttribute( 'morphTarget' + i, morphTargets[ index ] );
  9290. if ( morphNormals ) geometry.addAttribute( 'morphNormal' + i, morphNormals[ index ] );
  9291. morphInfluences[ i ] = value;
  9292. continue;
  9293. }
  9294. }
  9295. morphInfluences[ i ] = 0;
  9296. }
  9297. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  9298. }
  9299. return {
  9300. update: update
  9301. };
  9302. }
  9303. /**
  9304. * @author mrdoob / http://mrdoob.com/
  9305. */
  9306. function WebGLObjects( geometries, info ) {
  9307. var updateList = {};
  9308. function update( object ) {
  9309. var frame = info.render.frame;
  9310. var geometry = object.geometry;
  9311. var buffergeometry = geometries.get( object, geometry );
  9312. // Update once per frame
  9313. if ( updateList[ buffergeometry.id ] !== frame ) {
  9314. if ( geometry.isGeometry ) {
  9315. buffergeometry.updateFromObject( object );
  9316. }
  9317. geometries.update( buffergeometry );
  9318. updateList[ buffergeometry.id ] = frame;
  9319. }
  9320. return buffergeometry;
  9321. }
  9322. function dispose() {
  9323. updateList = {};
  9324. }
  9325. return {
  9326. update: update,
  9327. dispose: dispose
  9328. };
  9329. }
  9330. /**
  9331. * @author mrdoob / http://mrdoob.com/
  9332. */
  9333. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  9334. images = images !== undefined ? images : [];
  9335. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  9336. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  9337. this.flipY = false;
  9338. }
  9339. CubeTexture.prototype = Object.create( Texture.prototype );
  9340. CubeTexture.prototype.constructor = CubeTexture;
  9341. CubeTexture.prototype.isCubeTexture = true;
  9342. Object.defineProperty( CubeTexture.prototype, 'images', {
  9343. get: function () {
  9344. return this.image;
  9345. },
  9346. set: function ( value ) {
  9347. this.image = value;
  9348. }
  9349. } );
  9350. /**
  9351. * @author Artur Trzesiok
  9352. */
  9353. function DataTexture3D( data, width, height, depth ) {
  9354. // We're going to add .setXXX() methods for setting properties later.
  9355. // Users can still set in DataTexture3D directly.
  9356. //
  9357. // var texture = new THREE.DataTexture3D( data, width, height, depth );
  9358. // texture.anisotropy = 16;
  9359. //
  9360. // See #14839
  9361. Texture.call( this, null );
  9362. this.image = { data: data, width: width, height: height, depth: depth };
  9363. this.magFilter = NearestFilter;
  9364. this.minFilter = NearestFilter;
  9365. this.generateMipmaps = false;
  9366. this.flipY = false;
  9367. }
  9368. DataTexture3D.prototype = Object.create( Texture.prototype );
  9369. DataTexture3D.prototype.constructor = DataTexture3D;
  9370. DataTexture3D.prototype.isDataTexture3D = true;
  9371. /**
  9372. * @author tschw
  9373. * @author Mugen87 / https://github.com/Mugen87
  9374. * @author mrdoob / http://mrdoob.com/
  9375. *
  9376. * Uniforms of a program.
  9377. * Those form a tree structure with a special top-level container for the root,
  9378. * which you get by calling 'new WebGLUniforms( gl, program, renderer )'.
  9379. *
  9380. *
  9381. * Properties of inner nodes including the top-level container:
  9382. *
  9383. * .seq - array of nested uniforms
  9384. * .map - nested uniforms by name
  9385. *
  9386. *
  9387. * Methods of all nodes except the top-level container:
  9388. *
  9389. * .setValue( gl, value, [renderer] )
  9390. *
  9391. * uploads a uniform value(s)
  9392. * the 'renderer' parameter is needed for sampler uniforms
  9393. *
  9394. *
  9395. * Static methods of the top-level container (renderer factorizations):
  9396. *
  9397. * .upload( gl, seq, values, renderer )
  9398. *
  9399. * sets uniforms in 'seq' to 'values[id].value'
  9400. *
  9401. * .seqWithValue( seq, values ) : filteredSeq
  9402. *
  9403. * filters 'seq' entries with corresponding entry in values
  9404. *
  9405. *
  9406. * Methods of the top-level container (renderer factorizations):
  9407. *
  9408. * .setValue( gl, name, value )
  9409. *
  9410. * sets uniform with name 'name' to 'value'
  9411. *
  9412. * .set( gl, obj, prop )
  9413. *
  9414. * sets uniform from object and property with same name than uniform
  9415. *
  9416. * .setOptional( gl, obj, prop )
  9417. *
  9418. * like .set for an optional property of the object
  9419. *
  9420. */
  9421. var emptyTexture = new Texture();
  9422. var emptyTexture3d = new DataTexture3D();
  9423. var emptyCubeTexture = new CubeTexture();
  9424. // --- Base for inner nodes (including the root) ---
  9425. function UniformContainer() {
  9426. this.seq = [];
  9427. this.map = {};
  9428. }
  9429. // --- Utilities ---
  9430. // Array Caches (provide typed arrays for temporary by size)
  9431. var arrayCacheF32 = [];
  9432. var arrayCacheI32 = [];
  9433. // Float32Array caches used for uploading Matrix uniforms
  9434. var mat4array = new Float32Array( 16 );
  9435. var mat3array = new Float32Array( 9 );
  9436. var mat2array = new Float32Array( 4 );
  9437. // Flattening for arrays of vectors and matrices
  9438. function flatten( array, nBlocks, blockSize ) {
  9439. var firstElem = array[ 0 ];
  9440. if ( firstElem <= 0 || firstElem > 0 ) return array;
  9441. // unoptimized: ! isNaN( firstElem )
  9442. // see http://jacksondunstan.com/articles/983
  9443. var n = nBlocks * blockSize,
  9444. r = arrayCacheF32[ n ];
  9445. if ( r === undefined ) {
  9446. r = new Float32Array( n );
  9447. arrayCacheF32[ n ] = r;
  9448. }
  9449. if ( nBlocks !== 0 ) {
  9450. firstElem.toArray( r, 0 );
  9451. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  9452. offset += blockSize;
  9453. array[ i ].toArray( r, offset );
  9454. }
  9455. }
  9456. return r;
  9457. }
  9458. function arraysEqual( a, b ) {
  9459. if ( a.length !== b.length ) return false;
  9460. for ( var i = 0, l = a.length; i < l; i ++ ) {
  9461. if ( a[ i ] !== b[ i ] ) return false;
  9462. }
  9463. return true;
  9464. }
  9465. function copyArray( a, b ) {
  9466. for ( var i = 0, l = b.length; i < l; i ++ ) {
  9467. a[ i ] = b[ i ];
  9468. }
  9469. }
  9470. // Texture unit allocation
  9471. function allocTexUnits( renderer, n ) {
  9472. var r = arrayCacheI32[ n ];
  9473. if ( r === undefined ) {
  9474. r = new Int32Array( n );
  9475. arrayCacheI32[ n ] = r;
  9476. }
  9477. for ( var i = 0; i !== n; ++ i )
  9478. r[ i ] = renderer.allocTextureUnit();
  9479. return r;
  9480. }
  9481. // --- Setters ---
  9482. // Note: Defining these methods externally, because they come in a bunch
  9483. // and this way their names minify.
  9484. // Single scalar
  9485. function setValue1f( gl, v ) {
  9486. var cache = this.cache;
  9487. if ( cache[ 0 ] === v ) return;
  9488. gl.uniform1f( this.addr, v );
  9489. cache[ 0 ] = v;
  9490. }
  9491. function setValue1i( gl, v ) {
  9492. var cache = this.cache;
  9493. if ( cache[ 0 ] === v ) return;
  9494. gl.uniform1i( this.addr, v );
  9495. cache[ 0 ] = v;
  9496. }
  9497. // Single float vector (from flat array or THREE.VectorN)
  9498. function setValue2fv( gl, v ) {
  9499. var cache = this.cache;
  9500. if ( v.x !== undefined ) {
  9501. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {
  9502. gl.uniform2f( this.addr, v.x, v.y );
  9503. cache[ 0 ] = v.x;
  9504. cache[ 1 ] = v.y;
  9505. }
  9506. } else {
  9507. if ( arraysEqual( cache, v ) ) return;
  9508. gl.uniform2fv( this.addr, v );
  9509. copyArray( cache, v );
  9510. }
  9511. }
  9512. function setValue3fv( gl, v ) {
  9513. var cache = this.cache;
  9514. if ( v.x !== undefined ) {
  9515. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
  9516. gl.uniform3f( this.addr, v.x, v.y, v.z );
  9517. cache[ 0 ] = v.x;
  9518. cache[ 1 ] = v.y;
  9519. cache[ 2 ] = v.z;
  9520. }
  9521. } else if ( v.r !== undefined ) {
  9522. if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
  9523. gl.uniform3f( this.addr, v.r, v.g, v.b );
  9524. cache[ 0 ] = v.r;
  9525. cache[ 1 ] = v.g;
  9526. cache[ 2 ] = v.b;
  9527. }
  9528. } else {
  9529. if ( arraysEqual( cache, v ) ) return;
  9530. gl.uniform3fv( this.addr, v );
  9531. copyArray( cache, v );
  9532. }
  9533. }
  9534. function setValue4fv( gl, v ) {
  9535. var cache = this.cache;
  9536. if ( v.x !== undefined ) {
  9537. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {
  9538. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  9539. cache[ 0 ] = v.x;
  9540. cache[ 1 ] = v.y;
  9541. cache[ 2 ] = v.z;
  9542. cache[ 3 ] = v.w;
  9543. }
  9544. } else {
  9545. if ( arraysEqual( cache, v ) ) return;
  9546. gl.uniform4fv( this.addr, v );
  9547. copyArray( cache, v );
  9548. }
  9549. }
  9550. // Single matrix (from flat array or MatrixN)
  9551. function setValue2fm( gl, v ) {
  9552. var cache = this.cache;
  9553. var elements = v.elements;
  9554. if ( elements === undefined ) {
  9555. if ( arraysEqual( cache, v ) ) return;
  9556. gl.uniformMatrix2fv( this.addr, false, v );
  9557. copyArray( cache, v );
  9558. } else {
  9559. if ( arraysEqual( cache, elements ) ) return;
  9560. mat2array.set( elements );
  9561. gl.uniformMatrix2fv( this.addr, false, mat2array );
  9562. copyArray( cache, elements );
  9563. }
  9564. }
  9565. function setValue3fm( gl, v ) {
  9566. var cache = this.cache;
  9567. var elements = v.elements;
  9568. if ( elements === undefined ) {
  9569. if ( arraysEqual( cache, v ) ) return;
  9570. gl.uniformMatrix3fv( this.addr, false, v );
  9571. copyArray( cache, v );
  9572. } else {
  9573. if ( arraysEqual( cache, elements ) ) return;
  9574. mat3array.set( elements );
  9575. gl.uniformMatrix3fv( this.addr, false, mat3array );
  9576. copyArray( cache, elements );
  9577. }
  9578. }
  9579. function setValue4fm( gl, v ) {
  9580. var cache = this.cache;
  9581. var elements = v.elements;
  9582. if ( elements === undefined ) {
  9583. if ( arraysEqual( cache, v ) ) return;
  9584. gl.uniformMatrix4fv( this.addr, false, v );
  9585. copyArray( cache, v );
  9586. } else {
  9587. if ( arraysEqual( cache, elements ) ) return;
  9588. mat4array.set( elements );
  9589. gl.uniformMatrix4fv( this.addr, false, mat4array );
  9590. copyArray( cache, elements );
  9591. }
  9592. }
  9593. // Single texture (2D / Cube)
  9594. function setValueT1( gl, v, renderer ) {
  9595. var cache = this.cache;
  9596. var unit = renderer.allocTextureUnit();
  9597. if ( cache[ 0 ] !== unit ) {
  9598. gl.uniform1i( this.addr, unit );
  9599. cache[ 0 ] = unit;
  9600. }
  9601. renderer.setTexture2D( v || emptyTexture, unit );
  9602. }
  9603. function setValueT3D1( gl, v, renderer ) {
  9604. var cache = this.cache;
  9605. var unit = renderer.allocTextureUnit();
  9606. if ( cache[ 0 ] !== unit ) {
  9607. gl.uniform1i( this.addr, unit );
  9608. cache[ 0 ] = unit;
  9609. }
  9610. renderer.setTexture3D( v || emptyTexture3d, unit );
  9611. }
  9612. function setValueT6( gl, v, renderer ) {
  9613. var cache = this.cache;
  9614. var unit = renderer.allocTextureUnit();
  9615. if ( cache[ 0 ] !== unit ) {
  9616. gl.uniform1i( this.addr, unit );
  9617. cache[ 0 ] = unit;
  9618. }
  9619. renderer.setTextureCube( v || emptyCubeTexture, unit );
  9620. }
  9621. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  9622. function setValue2iv( gl, v ) {
  9623. var cache = this.cache;
  9624. if ( arraysEqual( cache, v ) ) return;
  9625. gl.uniform2iv( this.addr, v );
  9626. copyArray( cache, v );
  9627. }
  9628. function setValue3iv( gl, v ) {
  9629. var cache = this.cache;
  9630. if ( arraysEqual( cache, v ) ) return;
  9631. gl.uniform3iv( this.addr, v );
  9632. copyArray( cache, v );
  9633. }
  9634. function setValue4iv( gl, v ) {
  9635. var cache = this.cache;
  9636. if ( arraysEqual( cache, v ) ) return;
  9637. gl.uniform4iv( this.addr, v );
  9638. copyArray( cache, v );
  9639. }
  9640. // Helper to pick the right setter for the singular case
  9641. function getSingularSetter( type ) {
  9642. switch ( type ) {
  9643. case 0x1406: return setValue1f; // FLOAT
  9644. case 0x8b50: return setValue2fv; // _VEC2
  9645. case 0x8b51: return setValue3fv; // _VEC3
  9646. case 0x8b52: return setValue4fv; // _VEC4
  9647. case 0x8b5a: return setValue2fm; // _MAT2
  9648. case 0x8b5b: return setValue3fm; // _MAT3
  9649. case 0x8b5c: return setValue4fm; // _MAT4
  9650. case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
  9651. case 0x8B5F: return setValueT3D1; // SAMPLER_3D
  9652. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  9653. case 0x1404: case 0x8b56: return setValue1i; // INT, BOOL
  9654. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  9655. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  9656. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  9657. }
  9658. }
  9659. // Array of scalars
  9660. function setValue1fv( gl, v ) {
  9661. var cache = this.cache;
  9662. if ( arraysEqual( cache, v ) ) return;
  9663. gl.uniform1fv( this.addr, v );
  9664. copyArray( cache, v );
  9665. }
  9666. function setValue1iv( gl, v ) {
  9667. var cache = this.cache;
  9668. if ( arraysEqual( cache, v ) ) return;
  9669. gl.uniform1iv( this.addr, v );
  9670. copyArray( cache, v );
  9671. }
  9672. // Array of vectors (flat or from THREE classes)
  9673. function setValueV2a( gl, v ) {
  9674. var cache = this.cache;
  9675. var data = flatten( v, this.size, 2 );
  9676. if ( arraysEqual( cache, data ) ) return;
  9677. gl.uniform2fv( this.addr, data );
  9678. this.updateCache( data );
  9679. }
  9680. function setValueV3a( gl, v ) {
  9681. var cache = this.cache;
  9682. var data = flatten( v, this.size, 3 );
  9683. if ( arraysEqual( cache, data ) ) return;
  9684. gl.uniform3fv( this.addr, data );
  9685. this.updateCache( data );
  9686. }
  9687. function setValueV4a( gl, v ) {
  9688. var cache = this.cache;
  9689. var data = flatten( v, this.size, 4 );
  9690. if ( arraysEqual( cache, data ) ) return;
  9691. gl.uniform4fv( this.addr, data );
  9692. this.updateCache( data );
  9693. }
  9694. // Array of matrices (flat or from THREE clases)
  9695. function setValueM2a( gl, v ) {
  9696. var cache = this.cache;
  9697. var data = flatten( v, this.size, 4 );
  9698. if ( arraysEqual( cache, data ) ) return;
  9699. gl.uniformMatrix2fv( this.addr, false, data );
  9700. this.updateCache( data );
  9701. }
  9702. function setValueM3a( gl, v ) {
  9703. var cache = this.cache;
  9704. var data = flatten( v, this.size, 9 );
  9705. if ( arraysEqual( cache, data ) ) return;
  9706. gl.uniformMatrix3fv( this.addr, false, data );
  9707. this.updateCache( data );
  9708. }
  9709. function setValueM4a( gl, v ) {
  9710. var cache = this.cache;
  9711. var data = flatten( v, this.size, 16 );
  9712. if ( arraysEqual( cache, data ) ) return;
  9713. gl.uniformMatrix4fv( this.addr, false, data );
  9714. this.updateCache( data );
  9715. }
  9716. // Array of textures (2D / Cube)
  9717. function setValueT1a( gl, v, renderer ) {
  9718. var cache = this.cache;
  9719. var n = v.length;
  9720. var units = allocTexUnits( renderer, n );
  9721. if ( arraysEqual( cache, units ) === false ) {
  9722. gl.uniform1iv( this.addr, units );
  9723. copyArray( cache, units );
  9724. }
  9725. for ( var i = 0; i !== n; ++ i ) {
  9726. renderer.setTexture2D( v[ i ] || emptyTexture, units[ i ] );
  9727. }
  9728. }
  9729. function setValueT6a( gl, v, renderer ) {
  9730. var cache = this.cache;
  9731. var n = v.length;
  9732. var units = allocTexUnits( renderer, n );
  9733. if ( arraysEqual( cache, units ) === false ) {
  9734. gl.uniform1iv( this.addr, units );
  9735. copyArray( cache, units );
  9736. }
  9737. for ( var i = 0; i !== n; ++ i ) {
  9738. renderer.setTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  9739. }
  9740. }
  9741. // Helper to pick the right setter for a pure (bottom-level) array
  9742. function getPureArraySetter( type ) {
  9743. switch ( type ) {
  9744. case 0x1406: return setValue1fv; // FLOAT
  9745. case 0x8b50: return setValueV2a; // _VEC2
  9746. case 0x8b51: return setValueV3a; // _VEC3
  9747. case 0x8b52: return setValueV4a; // _VEC4
  9748. case 0x8b5a: return setValueM2a; // _MAT2
  9749. case 0x8b5b: return setValueM3a; // _MAT3
  9750. case 0x8b5c: return setValueM4a; // _MAT4
  9751. case 0x8b5e: return setValueT1a; // SAMPLER_2D
  9752. case 0x8b60: return setValueT6a; // SAMPLER_CUBE
  9753. case 0x1404: case 0x8b56: return setValue1iv; // INT, BOOL
  9754. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  9755. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  9756. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  9757. }
  9758. }
  9759. // --- Uniform Classes ---
  9760. function SingleUniform( id, activeInfo, addr ) {
  9761. this.id = id;
  9762. this.addr = addr;
  9763. this.cache = [];
  9764. this.setValue = getSingularSetter( activeInfo.type );
  9765. // this.path = activeInfo.name; // DEBUG
  9766. }
  9767. function PureArrayUniform( id, activeInfo, addr ) {
  9768. this.id = id;
  9769. this.addr = addr;
  9770. this.cache = [];
  9771. this.size = activeInfo.size;
  9772. this.setValue = getPureArraySetter( activeInfo.type );
  9773. // this.path = activeInfo.name; // DEBUG
  9774. }
  9775. PureArrayUniform.prototype.updateCache = function ( data ) {
  9776. var cache = this.cache;
  9777. if ( data instanceof Float32Array && cache.length !== data.length ) {
  9778. this.cache = new Float32Array( data.length );
  9779. }
  9780. copyArray( cache, data );
  9781. };
  9782. function StructuredUniform( id ) {
  9783. this.id = id;
  9784. UniformContainer.call( this ); // mix-in
  9785. }
  9786. StructuredUniform.prototype.setValue = function ( gl, value, renderer ) {
  9787. var seq = this.seq;
  9788. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9789. var u = seq[ i ];
  9790. u.setValue( gl, value[ u.id ], renderer );
  9791. }
  9792. };
  9793. // --- Top-level ---
  9794. // Parser - builds up the property tree from the path strings
  9795. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  9796. // extracts
  9797. // - the identifier (member name or array index)
  9798. // - followed by an optional right bracket (found when array index)
  9799. // - followed by an optional left bracket or dot (type of subscript)
  9800. //
  9801. // Note: These portions can be read in a non-overlapping fashion and
  9802. // allow straightforward parsing of the hierarchy that WebGL encodes
  9803. // in the uniform names.
  9804. function addUniform( container, uniformObject ) {
  9805. container.seq.push( uniformObject );
  9806. container.map[ uniformObject.id ] = uniformObject;
  9807. }
  9808. function parseUniform( activeInfo, addr, container ) {
  9809. var path = activeInfo.name,
  9810. pathLength = path.length;
  9811. // reset RegExp object, because of the early exit of a previous run
  9812. RePathPart.lastIndex = 0;
  9813. while ( true ) {
  9814. var match = RePathPart.exec( path ),
  9815. matchEnd = RePathPart.lastIndex,
  9816. id = match[ 1 ],
  9817. idIsIndex = match[ 2 ] === ']',
  9818. subscript = match[ 3 ];
  9819. if ( idIsIndex ) id = id | 0; // convert to integer
  9820. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  9821. // bare name or "pure" bottom-level array "[0]" suffix
  9822. addUniform( container, subscript === undefined ?
  9823. new SingleUniform( id, activeInfo, addr ) :
  9824. new PureArrayUniform( id, activeInfo, addr ) );
  9825. break;
  9826. } else {
  9827. // step into inner node / create it in case it doesn't exist
  9828. var map = container.map, next = map[ id ];
  9829. if ( next === undefined ) {
  9830. next = new StructuredUniform( id );
  9831. addUniform( container, next );
  9832. }
  9833. container = next;
  9834. }
  9835. }
  9836. }
  9837. // Root Container
  9838. function WebGLUniforms( gl, program, renderer ) {
  9839. UniformContainer.call( this );
  9840. this.renderer = renderer;
  9841. var n = gl.getProgramParameter( program, 35718 );
  9842. for ( var i = 0; i < n; ++ i ) {
  9843. var info = gl.getActiveUniform( program, i ),
  9844. addr = gl.getUniformLocation( program, info.name );
  9845. parseUniform( info, addr, this );
  9846. }
  9847. }
  9848. WebGLUniforms.prototype.setValue = function ( gl, name, value ) {
  9849. var u = this.map[ name ];
  9850. if ( u !== undefined ) u.setValue( gl, value, this.renderer );
  9851. };
  9852. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  9853. var v = object[ name ];
  9854. if ( v !== undefined ) this.setValue( gl, name, v );
  9855. };
  9856. // Static interface
  9857. WebGLUniforms.upload = function ( gl, seq, values, renderer ) {
  9858. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9859. var u = seq[ i ],
  9860. v = values[ u.id ];
  9861. if ( v.needsUpdate !== false ) {
  9862. // note: always updating when .needsUpdate is undefined
  9863. u.setValue( gl, v.value, renderer );
  9864. }
  9865. }
  9866. };
  9867. WebGLUniforms.seqWithValue = function ( seq, values ) {
  9868. var r = [];
  9869. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9870. var u = seq[ i ];
  9871. if ( u.id in values ) r.push( u );
  9872. }
  9873. return r;
  9874. };
  9875. /**
  9876. * @author mrdoob / http://mrdoob.com/
  9877. */
  9878. function addLineNumbers( string ) {
  9879. var lines = string.split( '\n' );
  9880. for ( var i = 0; i < lines.length; i ++ ) {
  9881. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  9882. }
  9883. return lines.join( '\n' );
  9884. }
  9885. function WebGLShader( gl, type, string ) {
  9886. var shader = gl.createShader( type );
  9887. gl.shaderSource( shader, string );
  9888. gl.compileShader( shader );
  9889. if ( gl.getShaderParameter( shader, 35713 ) === false ) {
  9890. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  9891. }
  9892. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  9893. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === 35633 ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  9894. }
  9895. // --enable-privileged-webgl-extension
  9896. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  9897. return shader;
  9898. }
  9899. /**
  9900. * @author mrdoob / http://mrdoob.com/
  9901. */
  9902. var programIdCount = 0;
  9903. function getEncodingComponents( encoding ) {
  9904. switch ( encoding ) {
  9905. case LinearEncoding:
  9906. return [ 'Linear', '( value )' ];
  9907. case sRGBEncoding:
  9908. return [ 'sRGB', '( value )' ];
  9909. case RGBEEncoding:
  9910. return [ 'RGBE', '( value )' ];
  9911. case RGBM7Encoding:
  9912. return [ 'RGBM', '( value, 7.0 )' ];
  9913. case RGBM16Encoding:
  9914. return [ 'RGBM', '( value, 16.0 )' ];
  9915. case RGBDEncoding:
  9916. return [ 'RGBD', '( value, 256.0 )' ];
  9917. case GammaEncoding:
  9918. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  9919. default:
  9920. throw new Error( 'unsupported encoding: ' + encoding );
  9921. }
  9922. }
  9923. function getTexelDecodingFunction( functionName, encoding ) {
  9924. var components = getEncodingComponents( encoding );
  9925. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  9926. }
  9927. function getTexelEncodingFunction( functionName, encoding ) {
  9928. var components = getEncodingComponents( encoding );
  9929. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  9930. }
  9931. function getToneMappingFunction( functionName, toneMapping ) {
  9932. var toneMappingName;
  9933. switch ( toneMapping ) {
  9934. case LinearToneMapping:
  9935. toneMappingName = 'Linear';
  9936. break;
  9937. case ReinhardToneMapping:
  9938. toneMappingName = 'Reinhard';
  9939. break;
  9940. case Uncharted2ToneMapping:
  9941. toneMappingName = 'Uncharted2';
  9942. break;
  9943. case CineonToneMapping:
  9944. toneMappingName = 'OptimizedCineon';
  9945. break;
  9946. case ACESFilmicToneMapping:
  9947. toneMappingName = 'ACESFilmic';
  9948. break;
  9949. default:
  9950. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  9951. }
  9952. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  9953. }
  9954. function generateExtensions( extensions, parameters, rendererExtensions ) {
  9955. extensions = extensions || {};
  9956. var chunks = [
  9957. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || ( parameters.normalMap && ! parameters.objectSpaceNormalMap ) || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  9958. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  9959. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  9960. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  9961. ];
  9962. return chunks.filter( filterEmptyLine ).join( '\n' );
  9963. }
  9964. function generateDefines( defines ) {
  9965. var chunks = [];
  9966. for ( var name in defines ) {
  9967. var value = defines[ name ];
  9968. if ( value === false ) continue;
  9969. chunks.push( '#define ' + name + ' ' + value );
  9970. }
  9971. return chunks.join( '\n' );
  9972. }
  9973. function fetchAttributeLocations( gl, program ) {
  9974. var attributes = {};
  9975. var n = gl.getProgramParameter( program, 35721 );
  9976. for ( var i = 0; i < n; i ++ ) {
  9977. var info = gl.getActiveAttrib( program, i );
  9978. var name = info.name;
  9979. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  9980. attributes[ name ] = gl.getAttribLocation( program, name );
  9981. }
  9982. return attributes;
  9983. }
  9984. function filterEmptyLine( string ) {
  9985. return string !== '';
  9986. }
  9987. function replaceLightNums( string, parameters ) {
  9988. return string
  9989. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  9990. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  9991. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  9992. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  9993. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  9994. }
  9995. function replaceClippingPlaneNums( string, parameters ) {
  9996. return string
  9997. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  9998. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  9999. }
  10000. function parseIncludes( string ) {
  10001. var pattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10002. function replace( match, include ) {
  10003. var replace = ShaderChunk[ include ];
  10004. if ( replace === undefined ) {
  10005. throw new Error( 'Can not resolve #include <' + include + '>' );
  10006. }
  10007. return parseIncludes( replace );
  10008. }
  10009. return string.replace( pattern, replace );
  10010. }
  10011. function unrollLoops( string ) {
  10012. var pattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10013. function replace( match, start, end, snippet ) {
  10014. var unroll = '';
  10015. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  10016. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  10017. }
  10018. return unroll;
  10019. }
  10020. return string.replace( pattern, replace );
  10021. }
  10022. function WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities ) {
  10023. var gl = renderer.context;
  10024. var defines = material.defines;
  10025. var vertexShader = shader.vertexShader;
  10026. var fragmentShader = shader.fragmentShader;
  10027. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10028. if ( parameters.shadowMapType === PCFShadowMap ) {
  10029. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10030. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  10031. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10032. }
  10033. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10034. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10035. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10036. if ( parameters.envMap ) {
  10037. switch ( material.envMap.mapping ) {
  10038. case CubeReflectionMapping:
  10039. case CubeRefractionMapping:
  10040. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10041. break;
  10042. case CubeUVReflectionMapping:
  10043. case CubeUVRefractionMapping:
  10044. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10045. break;
  10046. case EquirectangularReflectionMapping:
  10047. case EquirectangularRefractionMapping:
  10048. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  10049. break;
  10050. case SphericalReflectionMapping:
  10051. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  10052. break;
  10053. }
  10054. switch ( material.envMap.mapping ) {
  10055. case CubeRefractionMapping:
  10056. case EquirectangularRefractionMapping:
  10057. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10058. break;
  10059. }
  10060. switch ( material.combine ) {
  10061. case MultiplyOperation:
  10062. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10063. break;
  10064. case MixOperation:
  10065. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10066. break;
  10067. case AddOperation:
  10068. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10069. break;
  10070. }
  10071. }
  10072. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  10073. // console.log( 'building new program ' );
  10074. //
  10075. var customExtensions = capabilities.isWebGL2 ? '' : generateExtensions( material.extensions, parameters, extensions );
  10076. var customDefines = generateDefines( defines );
  10077. //
  10078. var program = gl.createProgram();
  10079. var prefixVertex, prefixFragment;
  10080. if ( material.isRawShaderMaterial ) {
  10081. prefixVertex = [
  10082. customDefines
  10083. ].filter( filterEmptyLine ).join( '\n' );
  10084. if ( prefixVertex.length > 0 ) {
  10085. prefixVertex += '\n';
  10086. }
  10087. prefixFragment = [
  10088. customExtensions,
  10089. customDefines
  10090. ].filter( filterEmptyLine ).join( '\n' );
  10091. if ( prefixFragment.length > 0 ) {
  10092. prefixFragment += '\n';
  10093. }
  10094. } else {
  10095. prefixVertex = [
  10096. 'precision ' + parameters.precision + ' float;',
  10097. 'precision ' + parameters.precision + ' int;',
  10098. '#define SHADER_NAME ' + shader.name,
  10099. customDefines,
  10100. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  10101. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10102. '#define MAX_BONES ' + parameters.maxBones,
  10103. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10104. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10105. parameters.map ? '#define USE_MAP' : '',
  10106. parameters.envMap ? '#define USE_ENVMAP' : '',
  10107. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10108. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10109. parameters.aoMap ? '#define USE_AOMAP' : '',
  10110. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10111. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10112. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10113. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10114. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  10115. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10116. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10117. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10118. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10119. parameters.vertexColors ? '#define USE_COLOR' : '',
  10120. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10121. parameters.skinning ? '#define USE_SKINNING' : '',
  10122. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  10123. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  10124. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  10125. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10126. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10127. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10128. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10129. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  10130. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10131. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10132. 'uniform mat4 modelMatrix;',
  10133. 'uniform mat4 modelViewMatrix;',
  10134. 'uniform mat4 projectionMatrix;',
  10135. 'uniform mat4 viewMatrix;',
  10136. 'uniform mat3 normalMatrix;',
  10137. 'uniform vec3 cameraPosition;',
  10138. 'attribute vec3 position;',
  10139. 'attribute vec3 normal;',
  10140. 'attribute vec2 uv;',
  10141. '#ifdef USE_COLOR',
  10142. ' attribute vec3 color;',
  10143. '#endif',
  10144. '#ifdef USE_MORPHTARGETS',
  10145. ' attribute vec3 morphTarget0;',
  10146. ' attribute vec3 morphTarget1;',
  10147. ' attribute vec3 morphTarget2;',
  10148. ' attribute vec3 morphTarget3;',
  10149. ' #ifdef USE_MORPHNORMALS',
  10150. ' attribute vec3 morphNormal0;',
  10151. ' attribute vec3 morphNormal1;',
  10152. ' attribute vec3 morphNormal2;',
  10153. ' attribute vec3 morphNormal3;',
  10154. ' #else',
  10155. ' attribute vec3 morphTarget4;',
  10156. ' attribute vec3 morphTarget5;',
  10157. ' attribute vec3 morphTarget6;',
  10158. ' attribute vec3 morphTarget7;',
  10159. ' #endif',
  10160. '#endif',
  10161. '#ifdef USE_SKINNING',
  10162. ' attribute vec4 skinIndex;',
  10163. ' attribute vec4 skinWeight;',
  10164. '#endif',
  10165. '\n'
  10166. ].filter( filterEmptyLine ).join( '\n' );
  10167. prefixFragment = [
  10168. customExtensions,
  10169. 'precision ' + parameters.precision + ' float;',
  10170. 'precision ' + parameters.precision + ' int;',
  10171. '#define SHADER_NAME ' + shader.name,
  10172. customDefines,
  10173. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + ( parameters.alphaTest % 1 ? '' : '.0' ) : '', // add '.0' if integer
  10174. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10175. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10176. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10177. parameters.map ? '#define USE_MAP' : '',
  10178. parameters.matcap ? '#define USE_MATCAP' : '',
  10179. parameters.envMap ? '#define USE_ENVMAP' : '',
  10180. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  10181. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10182. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  10183. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10184. parameters.aoMap ? '#define USE_AOMAP' : '',
  10185. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10186. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10187. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10188. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10189. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10190. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10191. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10192. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10193. parameters.vertexColors ? '#define USE_COLOR' : '',
  10194. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  10195. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10196. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10197. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10198. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10199. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10200. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  10201. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  10202. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10203. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10204. parameters.envMap && ( capabilities.isWebGL2 || extensions.get( 'EXT_shader_texture_lod' ) ) ? '#define TEXTURE_LOD_EXT' : '',
  10205. 'uniform mat4 viewMatrix;',
  10206. 'uniform vec3 cameraPosition;',
  10207. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  10208. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  10209. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  10210. parameters.dithering ? '#define DITHERING' : '',
  10211. ( parameters.outputEncoding || parameters.mapEncoding || parameters.matcapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding ) ?
  10212. ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
  10213. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  10214. parameters.matcapEncoding ? getTexelDecodingFunction( 'matcapTexelToLinear', parameters.matcapEncoding ) : '',
  10215. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  10216. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  10217. parameters.outputEncoding ? getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ) : '',
  10218. parameters.depthPacking ? '#define DEPTH_PACKING ' + material.depthPacking : '',
  10219. '\n'
  10220. ].filter( filterEmptyLine ).join( '\n' );
  10221. }
  10222. vertexShader = parseIncludes( vertexShader );
  10223. vertexShader = replaceLightNums( vertexShader, parameters );
  10224. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  10225. fragmentShader = parseIncludes( fragmentShader );
  10226. fragmentShader = replaceLightNums( fragmentShader, parameters );
  10227. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  10228. vertexShader = unrollLoops( vertexShader );
  10229. fragmentShader = unrollLoops( fragmentShader );
  10230. if ( capabilities.isWebGL2 && ! material.isRawShaderMaterial ) {
  10231. var isGLSL3ShaderMaterial = false;
  10232. var versionRegex = /^\s*#version\s+300\s+es\s*\n/;
  10233. if ( material.isShaderMaterial &&
  10234. vertexShader.match( versionRegex ) !== null &&
  10235. fragmentShader.match( versionRegex ) !== null ) {
  10236. isGLSL3ShaderMaterial = true;
  10237. vertexShader = vertexShader.replace( versionRegex, '' );
  10238. fragmentShader = fragmentShader.replace( versionRegex, '' );
  10239. }
  10240. // GLSL 3.0 conversion
  10241. prefixVertex = [
  10242. '#version 300 es\n',
  10243. '#define attribute in',
  10244. '#define varying out',
  10245. '#define texture2D texture'
  10246. ].join( '\n' ) + '\n' + prefixVertex;
  10247. prefixFragment = [
  10248. '#version 300 es\n',
  10249. '#define varying in',
  10250. isGLSL3ShaderMaterial ? '' : 'out highp vec4 pc_fragColor;',
  10251. isGLSL3ShaderMaterial ? '' : '#define gl_FragColor pc_fragColor',
  10252. '#define gl_FragDepthEXT gl_FragDepth',
  10253. '#define texture2D texture',
  10254. '#define textureCube texture',
  10255. '#define texture2DProj textureProj',
  10256. '#define texture2DLodEXT textureLod',
  10257. '#define texture2DProjLodEXT textureProjLod',
  10258. '#define textureCubeLodEXT textureLod',
  10259. '#define texture2DGradEXT textureGrad',
  10260. '#define texture2DProjGradEXT textureProjGrad',
  10261. '#define textureCubeGradEXT textureGrad'
  10262. ].join( '\n' ) + '\n' + prefixFragment;
  10263. }
  10264. var vertexGlsl = prefixVertex + vertexShader;
  10265. var fragmentGlsl = prefixFragment + fragmentShader;
  10266. // console.log( '*VERTEX*', vertexGlsl );
  10267. // console.log( '*FRAGMENT*', fragmentGlsl );
  10268. var glVertexShader = WebGLShader( gl, 35633, vertexGlsl );
  10269. var glFragmentShader = WebGLShader( gl, 35632, fragmentGlsl );
  10270. gl.attachShader( program, glVertexShader );
  10271. gl.attachShader( program, glFragmentShader );
  10272. // Force a particular attribute to index 0.
  10273. if ( material.index0AttributeName !== undefined ) {
  10274. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  10275. } else if ( parameters.morphTargets === true ) {
  10276. // programs with morphTargets displace position out of attribute 0
  10277. gl.bindAttribLocation( program, 0, 'position' );
  10278. }
  10279. gl.linkProgram( program );
  10280. var programLog = gl.getProgramInfoLog( program ).trim();
  10281. var vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  10282. var fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  10283. var runnable = true;
  10284. var haveDiagnostics = true;
  10285. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  10286. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  10287. if ( gl.getProgramParameter( program, 35714 ) === false ) {
  10288. runnable = false;
  10289. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter( program, 35715 ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  10290. } else if ( programLog !== '' ) {
  10291. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  10292. } else if ( vertexLog === '' || fragmentLog === '' ) {
  10293. haveDiagnostics = false;
  10294. }
  10295. if ( haveDiagnostics ) {
  10296. this.diagnostics = {
  10297. runnable: runnable,
  10298. material: material,
  10299. programLog: programLog,
  10300. vertexShader: {
  10301. log: vertexLog,
  10302. prefix: prefixVertex
  10303. },
  10304. fragmentShader: {
  10305. log: fragmentLog,
  10306. prefix: prefixFragment
  10307. }
  10308. };
  10309. }
  10310. // clean up
  10311. gl.deleteShader( glVertexShader );
  10312. gl.deleteShader( glFragmentShader );
  10313. // set up caching for uniform locations
  10314. var cachedUniforms;
  10315. this.getUniforms = function () {
  10316. if ( cachedUniforms === undefined ) {
  10317. cachedUniforms = new WebGLUniforms( gl, program, renderer );
  10318. }
  10319. return cachedUniforms;
  10320. };
  10321. // set up caching for attribute locations
  10322. var cachedAttributes;
  10323. this.getAttributes = function () {
  10324. if ( cachedAttributes === undefined ) {
  10325. cachedAttributes = fetchAttributeLocations( gl, program );
  10326. }
  10327. return cachedAttributes;
  10328. };
  10329. // free resource
  10330. this.destroy = function () {
  10331. gl.deleteProgram( program );
  10332. this.program = undefined;
  10333. };
  10334. // DEPRECATED
  10335. Object.defineProperties( this, {
  10336. uniforms: {
  10337. get: function () {
  10338. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  10339. return this.getUniforms();
  10340. }
  10341. },
  10342. attributes: {
  10343. get: function () {
  10344. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  10345. return this.getAttributes();
  10346. }
  10347. }
  10348. } );
  10349. //
  10350. this.name = shader.name;
  10351. this.id = programIdCount ++;
  10352. this.code = code;
  10353. this.usedTimes = 1;
  10354. this.program = program;
  10355. this.vertexShader = glVertexShader;
  10356. this.fragmentShader = glFragmentShader;
  10357. return this;
  10358. }
  10359. /**
  10360. * @author mrdoob / http://mrdoob.com/
  10361. */
  10362. function WebGLPrograms( renderer, extensions, capabilities ) {
  10363. var programs = [];
  10364. var shaderIDs = {
  10365. MeshDepthMaterial: 'depth',
  10366. MeshDistanceMaterial: 'distanceRGBA',
  10367. MeshNormalMaterial: 'normal',
  10368. MeshBasicMaterial: 'basic',
  10369. MeshLambertMaterial: 'lambert',
  10370. MeshPhongMaterial: 'phong',
  10371. MeshToonMaterial: 'phong',
  10372. MeshStandardMaterial: 'physical',
  10373. MeshPhysicalMaterial: 'physical',
  10374. MeshMatcapMaterial: 'matcap',
  10375. LineBasicMaterial: 'basic',
  10376. LineDashedMaterial: 'dashed',
  10377. PointsMaterial: 'points',
  10378. ShadowMaterial: 'shadow',
  10379. SpriteMaterial: 'sprite'
  10380. };
  10381. var parameterNames = [
  10382. "precision", "supportsVertexTextures", "map", "mapEncoding", "matcap", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding",
  10383. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "displacementMap", "specularMap",
  10384. "roughnessMap", "metalnessMap", "gradientMap",
  10385. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  10386. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  10387. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  10388. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  10389. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  10390. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  10391. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering"
  10392. ];
  10393. function allocateBones( object ) {
  10394. var skeleton = object.skeleton;
  10395. var bones = skeleton.bones;
  10396. if ( capabilities.floatVertexTextures ) {
  10397. return 1024;
  10398. } else {
  10399. // default for when object is not specified
  10400. // ( for example when prebuilding shader to be used with multiple objects )
  10401. //
  10402. // - leave some extra space for other uniforms
  10403. // - limit here is ANGLE's 254 max uniform vectors
  10404. // (up to 54 should be safe)
  10405. var nVertexUniforms = capabilities.maxVertexUniforms;
  10406. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  10407. var maxBones = Math.min( nVertexMatrices, bones.length );
  10408. if ( maxBones < bones.length ) {
  10409. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  10410. return 0;
  10411. }
  10412. return maxBones;
  10413. }
  10414. }
  10415. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  10416. var encoding;
  10417. if ( ! map ) {
  10418. encoding = LinearEncoding;
  10419. } else if ( map.isTexture ) {
  10420. encoding = map.encoding;
  10421. } else if ( map.isWebGLRenderTarget ) {
  10422. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  10423. encoding = map.texture.encoding;
  10424. }
  10425. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  10426. if ( encoding === LinearEncoding && gammaOverrideLinear ) {
  10427. encoding = GammaEncoding;
  10428. }
  10429. return encoding;
  10430. }
  10431. this.getParameters = function ( material, lights, shadows, fog, nClipPlanes, nClipIntersection, object ) {
  10432. var shaderID = shaderIDs[ material.type ];
  10433. // heuristics to create shader parameters according to lights in the scene
  10434. // (not to blow over maxLights budget)
  10435. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  10436. var precision = capabilities.precision;
  10437. if ( material.precision !== null ) {
  10438. precision = capabilities.getMaxPrecision( material.precision );
  10439. if ( precision !== material.precision ) {
  10440. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  10441. }
  10442. }
  10443. var currentRenderTarget = renderer.getRenderTarget();
  10444. var parameters = {
  10445. shaderID: shaderID,
  10446. precision: precision,
  10447. supportsVertexTextures: capabilities.vertexTextures,
  10448. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  10449. map: !! material.map,
  10450. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  10451. matcap: !! material.matcap,
  10452. matcapEncoding: getTextureEncodingFromMap( material.matcap, renderer.gammaInput ),
  10453. envMap: !! material.envMap,
  10454. envMapMode: material.envMap && material.envMap.mapping,
  10455. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  10456. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
  10457. lightMap: !! material.lightMap,
  10458. aoMap: !! material.aoMap,
  10459. emissiveMap: !! material.emissiveMap,
  10460. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  10461. bumpMap: !! material.bumpMap,
  10462. normalMap: !! material.normalMap,
  10463. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  10464. displacementMap: !! material.displacementMap,
  10465. roughnessMap: !! material.roughnessMap,
  10466. metalnessMap: !! material.metalnessMap,
  10467. specularMap: !! material.specularMap,
  10468. alphaMap: !! material.alphaMap,
  10469. gradientMap: !! material.gradientMap,
  10470. combine: material.combine,
  10471. vertexColors: material.vertexColors,
  10472. fog: !! fog,
  10473. useFog: material.fog,
  10474. fogExp: ( fog && fog.isFogExp2 ),
  10475. flatShading: material.flatShading,
  10476. sizeAttenuation: material.sizeAttenuation,
  10477. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  10478. skinning: material.skinning && maxBones > 0,
  10479. maxBones: maxBones,
  10480. useVertexTexture: capabilities.floatVertexTextures,
  10481. morphTargets: material.morphTargets,
  10482. morphNormals: material.morphNormals,
  10483. maxMorphTargets: renderer.maxMorphTargets,
  10484. maxMorphNormals: renderer.maxMorphNormals,
  10485. numDirLights: lights.directional.length,
  10486. numPointLights: lights.point.length,
  10487. numSpotLights: lights.spot.length,
  10488. numRectAreaLights: lights.rectArea.length,
  10489. numHemiLights: lights.hemi.length,
  10490. numClippingPlanes: nClipPlanes,
  10491. numClipIntersection: nClipIntersection,
  10492. dithering: material.dithering,
  10493. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && shadows.length > 0,
  10494. shadowMapType: renderer.shadowMap.type,
  10495. toneMapping: renderer.toneMapping,
  10496. physicallyCorrectLights: renderer.physicallyCorrectLights,
  10497. premultipliedAlpha: material.premultipliedAlpha,
  10498. alphaTest: material.alphaTest,
  10499. doubleSided: material.side === DoubleSide,
  10500. flipSided: material.side === BackSide,
  10501. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  10502. };
  10503. return parameters;
  10504. };
  10505. this.getProgramCode = function ( material, parameters ) {
  10506. var array = [];
  10507. if ( parameters.shaderID ) {
  10508. array.push( parameters.shaderID );
  10509. } else {
  10510. array.push( material.fragmentShader );
  10511. array.push( material.vertexShader );
  10512. }
  10513. if ( material.defines !== undefined ) {
  10514. for ( var name in material.defines ) {
  10515. array.push( name );
  10516. array.push( material.defines[ name ] );
  10517. }
  10518. }
  10519. for ( var i = 0; i < parameterNames.length; i ++ ) {
  10520. array.push( parameters[ parameterNames[ i ] ] );
  10521. }
  10522. array.push( material.onBeforeCompile.toString() );
  10523. array.push( renderer.gammaOutput );
  10524. array.push( renderer.gammaFactor );
  10525. return array.join();
  10526. };
  10527. this.acquireProgram = function ( material, shader, parameters, code ) {
  10528. var program;
  10529. // Check if code has been already compiled
  10530. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  10531. var programInfo = programs[ p ];
  10532. if ( programInfo.code === code ) {
  10533. program = programInfo;
  10534. ++ program.usedTimes;
  10535. break;
  10536. }
  10537. }
  10538. if ( program === undefined ) {
  10539. program = new WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities );
  10540. programs.push( program );
  10541. }
  10542. return program;
  10543. };
  10544. this.releaseProgram = function ( program ) {
  10545. if ( -- program.usedTimes === 0 ) {
  10546. // Remove from unordered set
  10547. var i = programs.indexOf( program );
  10548. programs[ i ] = programs[ programs.length - 1 ];
  10549. programs.pop();
  10550. // Free WebGL resources
  10551. program.destroy();
  10552. }
  10553. };
  10554. // Exposed for resource monitoring & error feedback via renderer.info:
  10555. this.programs = programs;
  10556. }
  10557. /**
  10558. * @author fordacious / fordacious.github.io
  10559. */
  10560. function WebGLProperties() {
  10561. var properties = new WeakMap();
  10562. function get( object ) {
  10563. var map = properties.get( object );
  10564. if ( map === undefined ) {
  10565. map = {};
  10566. properties.set( object, map );
  10567. }
  10568. return map;
  10569. }
  10570. function remove( object ) {
  10571. properties.delete( object );
  10572. }
  10573. function update( object, key, value ) {
  10574. properties.get( object )[ key ] = value;
  10575. }
  10576. function dispose() {
  10577. properties = new WeakMap();
  10578. }
  10579. return {
  10580. get: get,
  10581. remove: remove,
  10582. update: update,
  10583. dispose: dispose
  10584. };
  10585. }
  10586. /**
  10587. * @author mrdoob / http://mrdoob.com/
  10588. */
  10589. function painterSortStable( a, b ) {
  10590. if ( a.groupOrder !== b.groupOrder ) {
  10591. return a.groupOrder - b.groupOrder;
  10592. } else if ( a.renderOrder !== b.renderOrder ) {
  10593. return a.renderOrder - b.renderOrder;
  10594. } else if ( a.program && b.program && a.program !== b.program ) {
  10595. return a.program.id - b.program.id;
  10596. } else if ( a.material.id !== b.material.id ) {
  10597. return a.material.id - b.material.id;
  10598. } else if ( a.z !== b.z ) {
  10599. return a.z - b.z;
  10600. } else {
  10601. return a.id - b.id;
  10602. }
  10603. }
  10604. function reversePainterSortStable( a, b ) {
  10605. if ( a.groupOrder !== b.groupOrder ) {
  10606. return a.groupOrder - b.groupOrder;
  10607. } else if ( a.renderOrder !== b.renderOrder ) {
  10608. return a.renderOrder - b.renderOrder;
  10609. } if ( a.z !== b.z ) {
  10610. return b.z - a.z;
  10611. } else {
  10612. return a.id - b.id;
  10613. }
  10614. }
  10615. function WebGLRenderList() {
  10616. var renderItems = [];
  10617. var renderItemsIndex = 0;
  10618. var opaque = [];
  10619. var transparent = [];
  10620. function init() {
  10621. renderItemsIndex = 0;
  10622. opaque.length = 0;
  10623. transparent.length = 0;
  10624. }
  10625. function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
  10626. var renderItem = renderItems[ renderItemsIndex ];
  10627. if ( renderItem === undefined ) {
  10628. renderItem = {
  10629. id: object.id,
  10630. object: object,
  10631. geometry: geometry,
  10632. material: material,
  10633. program: material.program,
  10634. groupOrder: groupOrder,
  10635. renderOrder: object.renderOrder,
  10636. z: z,
  10637. group: group
  10638. };
  10639. renderItems[ renderItemsIndex ] = renderItem;
  10640. } else {
  10641. renderItem.id = object.id;
  10642. renderItem.object = object;
  10643. renderItem.geometry = geometry;
  10644. renderItem.material = material;
  10645. renderItem.program = material.program;
  10646. renderItem.groupOrder = groupOrder;
  10647. renderItem.renderOrder = object.renderOrder;
  10648. renderItem.z = z;
  10649. renderItem.group = group;
  10650. }
  10651. renderItemsIndex ++;
  10652. return renderItem;
  10653. }
  10654. function push( object, geometry, material, groupOrder, z, group ) {
  10655. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  10656. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  10657. }
  10658. function unshift( object, geometry, material, groupOrder, z, group ) {
  10659. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  10660. ( material.transparent === true ? transparent : opaque ).unshift( renderItem );
  10661. }
  10662. function sort() {
  10663. if ( opaque.length > 1 ) opaque.sort( painterSortStable );
  10664. if ( transparent.length > 1 ) transparent.sort( reversePainterSortStable );
  10665. }
  10666. return {
  10667. opaque: opaque,
  10668. transparent: transparent,
  10669. init: init,
  10670. push: push,
  10671. unshift: unshift,
  10672. sort: sort
  10673. };
  10674. }
  10675. function WebGLRenderLists() {
  10676. var lists = {};
  10677. function onSceneDispose( event ) {
  10678. var scene = event.target;
  10679. scene.removeEventListener( 'dispose', onSceneDispose );
  10680. delete lists[ scene.id ];
  10681. }
  10682. function get( scene, camera ) {
  10683. var cameras = lists[ scene.id ];
  10684. var list;
  10685. if ( cameras === undefined ) {
  10686. list = new WebGLRenderList();
  10687. lists[ scene.id ] = {};
  10688. lists[ scene.id ][ camera.id ] = list;
  10689. scene.addEventListener( 'dispose', onSceneDispose );
  10690. } else {
  10691. list = cameras[ camera.id ];
  10692. if ( list === undefined ) {
  10693. list = new WebGLRenderList();
  10694. cameras[ camera.id ] = list;
  10695. }
  10696. }
  10697. return list;
  10698. }
  10699. function dispose() {
  10700. lists = {};
  10701. }
  10702. return {
  10703. get: get,
  10704. dispose: dispose
  10705. };
  10706. }
  10707. /**
  10708. * @author mrdoob / http://mrdoob.com/
  10709. */
  10710. function UniformsCache() {
  10711. var lights = {};
  10712. return {
  10713. get: function ( light ) {
  10714. if ( lights[ light.id ] !== undefined ) {
  10715. return lights[ light.id ];
  10716. }
  10717. var uniforms;
  10718. switch ( light.type ) {
  10719. case 'DirectionalLight':
  10720. uniforms = {
  10721. direction: new Vector3(),
  10722. color: new Color(),
  10723. shadow: false,
  10724. shadowBias: 0,
  10725. shadowRadius: 1,
  10726. shadowMapSize: new Vector2()
  10727. };
  10728. break;
  10729. case 'SpotLight':
  10730. uniforms = {
  10731. position: new Vector3(),
  10732. direction: new Vector3(),
  10733. color: new Color(),
  10734. distance: 0,
  10735. coneCos: 0,
  10736. penumbraCos: 0,
  10737. decay: 0,
  10738. shadow: false,
  10739. shadowBias: 0,
  10740. shadowRadius: 1,
  10741. shadowMapSize: new Vector2()
  10742. };
  10743. break;
  10744. case 'PointLight':
  10745. uniforms = {
  10746. position: new Vector3(),
  10747. color: new Color(),
  10748. distance: 0,
  10749. decay: 0,
  10750. shadow: false,
  10751. shadowBias: 0,
  10752. shadowRadius: 1,
  10753. shadowMapSize: new Vector2(),
  10754. shadowCameraNear: 1,
  10755. shadowCameraFar: 1000
  10756. };
  10757. break;
  10758. case 'HemisphereLight':
  10759. uniforms = {
  10760. direction: new Vector3(),
  10761. skyColor: new Color(),
  10762. groundColor: new Color()
  10763. };
  10764. break;
  10765. case 'RectAreaLight':
  10766. uniforms = {
  10767. color: new Color(),
  10768. position: new Vector3(),
  10769. halfWidth: new Vector3(),
  10770. halfHeight: new Vector3()
  10771. // TODO (abelnation): set RectAreaLight shadow uniforms
  10772. };
  10773. break;
  10774. }
  10775. lights[ light.id ] = uniforms;
  10776. return uniforms;
  10777. }
  10778. };
  10779. }
  10780. var count = 0;
  10781. function WebGLLights() {
  10782. var cache = new UniformsCache();
  10783. var state = {
  10784. id: count ++,
  10785. hash: {
  10786. stateID: - 1,
  10787. directionalLength: - 1,
  10788. pointLength: - 1,
  10789. spotLength: - 1,
  10790. rectAreaLength: - 1,
  10791. hemiLength: - 1,
  10792. shadowsLength: - 1
  10793. },
  10794. ambient: [ 0, 0, 0 ],
  10795. directional: [],
  10796. directionalShadowMap: [],
  10797. directionalShadowMatrix: [],
  10798. spot: [],
  10799. spotShadowMap: [],
  10800. spotShadowMatrix: [],
  10801. rectArea: [],
  10802. point: [],
  10803. pointShadowMap: [],
  10804. pointShadowMatrix: [],
  10805. hemi: []
  10806. };
  10807. var vector3 = new Vector3();
  10808. var matrix4 = new Matrix4();
  10809. var matrix42 = new Matrix4();
  10810. function setup( lights, shadows, camera ) {
  10811. var r = 0, g = 0, b = 0;
  10812. var directionalLength = 0;
  10813. var pointLength = 0;
  10814. var spotLength = 0;
  10815. var rectAreaLength = 0;
  10816. var hemiLength = 0;
  10817. var viewMatrix = camera.matrixWorldInverse;
  10818. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  10819. var light = lights[ i ];
  10820. var color = light.color;
  10821. var intensity = light.intensity;
  10822. var distance = light.distance;
  10823. var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  10824. if ( light.isAmbientLight ) {
  10825. r += color.r * intensity;
  10826. g += color.g * intensity;
  10827. b += color.b * intensity;
  10828. } else if ( light.isDirectionalLight ) {
  10829. var uniforms = cache.get( light );
  10830. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  10831. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10832. vector3.setFromMatrixPosition( light.target.matrixWorld );
  10833. uniforms.direction.sub( vector3 );
  10834. uniforms.direction.transformDirection( viewMatrix );
  10835. uniforms.shadow = light.castShadow;
  10836. if ( light.castShadow ) {
  10837. var shadow = light.shadow;
  10838. uniforms.shadowBias = shadow.bias;
  10839. uniforms.shadowRadius = shadow.radius;
  10840. uniforms.shadowMapSize = shadow.mapSize;
  10841. }
  10842. state.directionalShadowMap[ directionalLength ] = shadowMap;
  10843. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  10844. state.directional[ directionalLength ] = uniforms;
  10845. directionalLength ++;
  10846. } else if ( light.isSpotLight ) {
  10847. var uniforms = cache.get( light );
  10848. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10849. uniforms.position.applyMatrix4( viewMatrix );
  10850. uniforms.color.copy( color ).multiplyScalar( intensity );
  10851. uniforms.distance = distance;
  10852. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10853. vector3.setFromMatrixPosition( light.target.matrixWorld );
  10854. uniforms.direction.sub( vector3 );
  10855. uniforms.direction.transformDirection( viewMatrix );
  10856. uniforms.coneCos = Math.cos( light.angle );
  10857. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  10858. uniforms.decay = light.decay;
  10859. uniforms.shadow = light.castShadow;
  10860. if ( light.castShadow ) {
  10861. var shadow = light.shadow;
  10862. uniforms.shadowBias = shadow.bias;
  10863. uniforms.shadowRadius = shadow.radius;
  10864. uniforms.shadowMapSize = shadow.mapSize;
  10865. }
  10866. state.spotShadowMap[ spotLength ] = shadowMap;
  10867. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  10868. state.spot[ spotLength ] = uniforms;
  10869. spotLength ++;
  10870. } else if ( light.isRectAreaLight ) {
  10871. var uniforms = cache.get( light );
  10872. // (a) intensity is the total visible light emitted
  10873. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  10874. // (b) intensity is the brightness of the light
  10875. uniforms.color.copy( color ).multiplyScalar( intensity );
  10876. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10877. uniforms.position.applyMatrix4( viewMatrix );
  10878. // extract local rotation of light to derive width/height half vectors
  10879. matrix42.identity();
  10880. matrix4.copy( light.matrixWorld );
  10881. matrix4.premultiply( viewMatrix );
  10882. matrix42.extractRotation( matrix4 );
  10883. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  10884. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  10885. uniforms.halfWidth.applyMatrix4( matrix42 );
  10886. uniforms.halfHeight.applyMatrix4( matrix42 );
  10887. // TODO (abelnation): RectAreaLight distance?
  10888. // uniforms.distance = distance;
  10889. state.rectArea[ rectAreaLength ] = uniforms;
  10890. rectAreaLength ++;
  10891. } else if ( light.isPointLight ) {
  10892. var uniforms = cache.get( light );
  10893. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10894. uniforms.position.applyMatrix4( viewMatrix );
  10895. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  10896. uniforms.distance = light.distance;
  10897. uniforms.decay = light.decay;
  10898. uniforms.shadow = light.castShadow;
  10899. if ( light.castShadow ) {
  10900. var shadow = light.shadow;
  10901. uniforms.shadowBias = shadow.bias;
  10902. uniforms.shadowRadius = shadow.radius;
  10903. uniforms.shadowMapSize = shadow.mapSize;
  10904. uniforms.shadowCameraNear = shadow.camera.near;
  10905. uniforms.shadowCameraFar = shadow.camera.far;
  10906. }
  10907. state.pointShadowMap[ pointLength ] = shadowMap;
  10908. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  10909. state.point[ pointLength ] = uniforms;
  10910. pointLength ++;
  10911. } else if ( light.isHemisphereLight ) {
  10912. var uniforms = cache.get( light );
  10913. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10914. uniforms.direction.transformDirection( viewMatrix );
  10915. uniforms.direction.normalize();
  10916. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  10917. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  10918. state.hemi[ hemiLength ] = uniforms;
  10919. hemiLength ++;
  10920. }
  10921. }
  10922. state.ambient[ 0 ] = r;
  10923. state.ambient[ 1 ] = g;
  10924. state.ambient[ 2 ] = b;
  10925. state.directional.length = directionalLength;
  10926. state.spot.length = spotLength;
  10927. state.rectArea.length = rectAreaLength;
  10928. state.point.length = pointLength;
  10929. state.hemi.length = hemiLength;
  10930. state.hash.stateID = state.id;
  10931. state.hash.directionalLength = directionalLength;
  10932. state.hash.pointLength = pointLength;
  10933. state.hash.spotLength = spotLength;
  10934. state.hash.rectAreaLength = rectAreaLength;
  10935. state.hash.hemiLength = hemiLength;
  10936. state.hash.shadowsLength = shadows.length;
  10937. }
  10938. return {
  10939. setup: setup,
  10940. state: state
  10941. };
  10942. }
  10943. /**
  10944. * @author Mugen87 / https://github.com/Mugen87
  10945. */
  10946. function WebGLRenderState() {
  10947. var lights = new WebGLLights();
  10948. var lightsArray = [];
  10949. var shadowsArray = [];
  10950. function init() {
  10951. lightsArray.length = 0;
  10952. shadowsArray.length = 0;
  10953. }
  10954. function pushLight( light ) {
  10955. lightsArray.push( light );
  10956. }
  10957. function pushShadow( shadowLight ) {
  10958. shadowsArray.push( shadowLight );
  10959. }
  10960. function setupLights( camera ) {
  10961. lights.setup( lightsArray, shadowsArray, camera );
  10962. }
  10963. var state = {
  10964. lightsArray: lightsArray,
  10965. shadowsArray: shadowsArray,
  10966. lights: lights
  10967. };
  10968. return {
  10969. init: init,
  10970. state: state,
  10971. setupLights: setupLights,
  10972. pushLight: pushLight,
  10973. pushShadow: pushShadow
  10974. };
  10975. }
  10976. function WebGLRenderStates() {
  10977. var renderStates = {};
  10978. function onSceneDispose( event ) {
  10979. var scene = event.target;
  10980. scene.removeEventListener( 'dispose', onSceneDispose );
  10981. delete renderStates[ scene.id ];
  10982. }
  10983. function get( scene, camera ) {
  10984. var renderState;
  10985. if ( renderStates[ scene.id ] === undefined ) {
  10986. renderState = new WebGLRenderState();
  10987. renderStates[ scene.id ] = {};
  10988. renderStates[ scene.id ][ camera.id ] = renderState;
  10989. scene.addEventListener( 'dispose', onSceneDispose );
  10990. } else {
  10991. if ( renderStates[ scene.id ][ camera.id ] === undefined ) {
  10992. renderState = new WebGLRenderState();
  10993. renderStates[ scene.id ][ camera.id ] = renderState;
  10994. } else {
  10995. renderState = renderStates[ scene.id ][ camera.id ];
  10996. }
  10997. }
  10998. return renderState;
  10999. }
  11000. function dispose() {
  11001. renderStates = {};
  11002. }
  11003. return {
  11004. get: get,
  11005. dispose: dispose
  11006. };
  11007. }
  11008. /**
  11009. * @author mrdoob / http://mrdoob.com/
  11010. * @author alteredq / http://alteredqualia.com/
  11011. * @author bhouston / https://clara.io
  11012. * @author WestLangley / http://github.com/WestLangley
  11013. *
  11014. * parameters = {
  11015. *
  11016. * opacity: <float>,
  11017. *
  11018. * map: new THREE.Texture( <Image> ),
  11019. *
  11020. * alphaMap: new THREE.Texture( <Image> ),
  11021. *
  11022. * displacementMap: new THREE.Texture( <Image> ),
  11023. * displacementScale: <float>,
  11024. * displacementBias: <float>,
  11025. *
  11026. * wireframe: <boolean>,
  11027. * wireframeLinewidth: <float>
  11028. * }
  11029. */
  11030. function MeshDepthMaterial( parameters ) {
  11031. Material.call( this );
  11032. this.type = 'MeshDepthMaterial';
  11033. this.depthPacking = BasicDepthPacking;
  11034. this.skinning = false;
  11035. this.morphTargets = false;
  11036. this.map = null;
  11037. this.alphaMap = null;
  11038. this.displacementMap = null;
  11039. this.displacementScale = 1;
  11040. this.displacementBias = 0;
  11041. this.wireframe = false;
  11042. this.wireframeLinewidth = 1;
  11043. this.fog = false;
  11044. this.lights = false;
  11045. this.setValues( parameters );
  11046. }
  11047. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  11048. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11049. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11050. MeshDepthMaterial.prototype.copy = function ( source ) {
  11051. Material.prototype.copy.call( this, source );
  11052. this.depthPacking = source.depthPacking;
  11053. this.skinning = source.skinning;
  11054. this.morphTargets = source.morphTargets;
  11055. this.map = source.map;
  11056. this.alphaMap = source.alphaMap;
  11057. this.displacementMap = source.displacementMap;
  11058. this.displacementScale = source.displacementScale;
  11059. this.displacementBias = source.displacementBias;
  11060. this.wireframe = source.wireframe;
  11061. this.wireframeLinewidth = source.wireframeLinewidth;
  11062. return this;
  11063. };
  11064. /**
  11065. * @author WestLangley / http://github.com/WestLangley
  11066. *
  11067. * parameters = {
  11068. *
  11069. * referencePosition: <float>,
  11070. * nearDistance: <float>,
  11071. * farDistance: <float>,
  11072. *
  11073. * skinning: <bool>,
  11074. * morphTargets: <bool>,
  11075. *
  11076. * map: new THREE.Texture( <Image> ),
  11077. *
  11078. * alphaMap: new THREE.Texture( <Image> ),
  11079. *
  11080. * displacementMap: new THREE.Texture( <Image> ),
  11081. * displacementScale: <float>,
  11082. * displacementBias: <float>
  11083. *
  11084. * }
  11085. */
  11086. function MeshDistanceMaterial( parameters ) {
  11087. Material.call( this );
  11088. this.type = 'MeshDistanceMaterial';
  11089. this.referencePosition = new Vector3();
  11090. this.nearDistance = 1;
  11091. this.farDistance = 1000;
  11092. this.skinning = false;
  11093. this.morphTargets = false;
  11094. this.map = null;
  11095. this.alphaMap = null;
  11096. this.displacementMap = null;
  11097. this.displacementScale = 1;
  11098. this.displacementBias = 0;
  11099. this.fog = false;
  11100. this.lights = false;
  11101. this.setValues( parameters );
  11102. }
  11103. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  11104. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11105. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11106. MeshDistanceMaterial.prototype.copy = function ( source ) {
  11107. Material.prototype.copy.call( this, source );
  11108. this.referencePosition.copy( source.referencePosition );
  11109. this.nearDistance = source.nearDistance;
  11110. this.farDistance = source.farDistance;
  11111. this.skinning = source.skinning;
  11112. this.morphTargets = source.morphTargets;
  11113. this.map = source.map;
  11114. this.alphaMap = source.alphaMap;
  11115. this.displacementMap = source.displacementMap;
  11116. this.displacementScale = source.displacementScale;
  11117. this.displacementBias = source.displacementBias;
  11118. return this;
  11119. };
  11120. /**
  11121. * @author alteredq / http://alteredqualia.com/
  11122. * @author mrdoob / http://mrdoob.com/
  11123. */
  11124. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  11125. var _frustum = new Frustum(),
  11126. _projScreenMatrix = new Matrix4(),
  11127. _shadowMapSize = new Vector2(),
  11128. _maxShadowMapSize = new Vector2( maxTextureSize, maxTextureSize ),
  11129. _lookTarget = new Vector3(),
  11130. _lightPositionWorld = new Vector3(),
  11131. _MorphingFlag = 1,
  11132. _SkinningFlag = 2,
  11133. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  11134. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  11135. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  11136. _materialCache = {};
  11137. var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  11138. var cubeDirections = [
  11139. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  11140. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  11141. ];
  11142. var cubeUps = [
  11143. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  11144. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  11145. ];
  11146. var cube2DViewPorts = [
  11147. new Vector4(), new Vector4(), new Vector4(),
  11148. new Vector4(), new Vector4(), new Vector4()
  11149. ];
  11150. // init
  11151. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  11152. var useMorphing = ( i & _MorphingFlag ) !== 0;
  11153. var useSkinning = ( i & _SkinningFlag ) !== 0;
  11154. var depthMaterial = new MeshDepthMaterial( {
  11155. depthPacking: RGBADepthPacking,
  11156. morphTargets: useMorphing,
  11157. skinning: useSkinning
  11158. } );
  11159. _depthMaterials[ i ] = depthMaterial;
  11160. //
  11161. var distanceMaterial = new MeshDistanceMaterial( {
  11162. morphTargets: useMorphing,
  11163. skinning: useSkinning
  11164. } );
  11165. _distanceMaterials[ i ] = distanceMaterial;
  11166. }
  11167. //
  11168. var scope = this;
  11169. this.enabled = false;
  11170. this.autoUpdate = true;
  11171. this.needsUpdate = false;
  11172. this.type = PCFShadowMap;
  11173. this.render = function ( lights, scene, camera ) {
  11174. if ( scope.enabled === false ) return;
  11175. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  11176. if ( lights.length === 0 ) return;
  11177. // TODO Clean up (needed in case of contextlost)
  11178. var _gl = _renderer.context;
  11179. var _state = _renderer.state;
  11180. // Set GL state for depth map.
  11181. _state.disable( 3042 );
  11182. _state.buffers.color.setClear( 1, 1, 1, 1 );
  11183. _state.buffers.depth.setTest( true );
  11184. _state.setScissorTest( false );
  11185. // render depth map
  11186. var faceCount;
  11187. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  11188. var light = lights[ i ];
  11189. var shadow = light.shadow;
  11190. var isPointLight = light && light.isPointLight;
  11191. if ( shadow === undefined ) {
  11192. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  11193. continue;
  11194. }
  11195. var shadowCamera = shadow.camera;
  11196. _shadowMapSize.copy( shadow.mapSize );
  11197. _shadowMapSize.min( _maxShadowMapSize );
  11198. if ( isPointLight ) {
  11199. var vpWidth = _shadowMapSize.x;
  11200. var vpHeight = _shadowMapSize.y;
  11201. // These viewports map a cube-map onto a 2D texture with the
  11202. // following orientation:
  11203. //
  11204. // xzXZ
  11205. // y Y
  11206. //
  11207. // X - Positive x direction
  11208. // x - Negative x direction
  11209. // Y - Positive y direction
  11210. // y - Negative y direction
  11211. // Z - Positive z direction
  11212. // z - Negative z direction
  11213. // positive X
  11214. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  11215. // negative X
  11216. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  11217. // positive Z
  11218. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  11219. // negative Z
  11220. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  11221. // positive Y
  11222. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  11223. // negative Y
  11224. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  11225. _shadowMapSize.x *= 4.0;
  11226. _shadowMapSize.y *= 2.0;
  11227. }
  11228. if ( shadow.map === null ) {
  11229. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  11230. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11231. shadow.map.texture.name = light.name + ".shadowMap";
  11232. shadowCamera.updateProjectionMatrix();
  11233. }
  11234. if ( shadow.isSpotLightShadow ) {
  11235. shadow.update( light );
  11236. }
  11237. var shadowMap = shadow.map;
  11238. var shadowMatrix = shadow.matrix;
  11239. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  11240. shadowCamera.position.copy( _lightPositionWorld );
  11241. if ( isPointLight ) {
  11242. faceCount = 6;
  11243. // for point lights we set the shadow matrix to be a translation-only matrix
  11244. // equal to inverse of the light's position
  11245. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  11246. } else {
  11247. faceCount = 1;
  11248. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  11249. shadowCamera.lookAt( _lookTarget );
  11250. shadowCamera.updateMatrixWorld();
  11251. // compute shadow matrix
  11252. shadowMatrix.set(
  11253. 0.5, 0.0, 0.0, 0.5,
  11254. 0.0, 0.5, 0.0, 0.5,
  11255. 0.0, 0.0, 0.5, 0.5,
  11256. 0.0, 0.0, 0.0, 1.0
  11257. );
  11258. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  11259. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  11260. }
  11261. _renderer.setRenderTarget( shadowMap );
  11262. _renderer.clear();
  11263. // render shadow map for each cube face (if omni-directional) or
  11264. // run a single pass if not
  11265. for ( var face = 0; face < faceCount; face ++ ) {
  11266. if ( isPointLight ) {
  11267. _lookTarget.copy( shadowCamera.position );
  11268. _lookTarget.add( cubeDirections[ face ] );
  11269. shadowCamera.up.copy( cubeUps[ face ] );
  11270. shadowCamera.lookAt( _lookTarget );
  11271. shadowCamera.updateMatrixWorld();
  11272. var vpDimensions = cube2DViewPorts[ face ];
  11273. _state.viewport( vpDimensions );
  11274. }
  11275. // update camera matrices and frustum
  11276. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  11277. _frustum.setFromMatrix( _projScreenMatrix );
  11278. // set object matrices & frustum culling
  11279. renderObject( scene, camera, shadowCamera, isPointLight );
  11280. }
  11281. }
  11282. scope.needsUpdate = false;
  11283. };
  11284. function getDepthMaterial( object, material, isPointLight, lightPositionWorld, shadowCameraNear, shadowCameraFar ) {
  11285. var geometry = object.geometry;
  11286. var result = null;
  11287. var materialVariants = _depthMaterials;
  11288. var customMaterial = object.customDepthMaterial;
  11289. if ( isPointLight ) {
  11290. materialVariants = _distanceMaterials;
  11291. customMaterial = object.customDistanceMaterial;
  11292. }
  11293. if ( ! customMaterial ) {
  11294. var useMorphing = false;
  11295. if ( material.morphTargets ) {
  11296. if ( geometry && geometry.isBufferGeometry ) {
  11297. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  11298. } else if ( geometry && geometry.isGeometry ) {
  11299. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  11300. }
  11301. }
  11302. if ( object.isSkinnedMesh && material.skinning === false ) {
  11303. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  11304. }
  11305. var useSkinning = object.isSkinnedMesh && material.skinning;
  11306. var variantIndex = 0;
  11307. if ( useMorphing ) variantIndex |= _MorphingFlag;
  11308. if ( useSkinning ) variantIndex |= _SkinningFlag;
  11309. result = materialVariants[ variantIndex ];
  11310. } else {
  11311. result = customMaterial;
  11312. }
  11313. if ( _renderer.localClippingEnabled &&
  11314. material.clipShadows === true &&
  11315. material.clippingPlanes.length !== 0 ) {
  11316. // in this case we need a unique material instance reflecting the
  11317. // appropriate state
  11318. var keyA = result.uuid, keyB = material.uuid;
  11319. var materialsForVariant = _materialCache[ keyA ];
  11320. if ( materialsForVariant === undefined ) {
  11321. materialsForVariant = {};
  11322. _materialCache[ keyA ] = materialsForVariant;
  11323. }
  11324. var cachedMaterial = materialsForVariant[ keyB ];
  11325. if ( cachedMaterial === undefined ) {
  11326. cachedMaterial = result.clone();
  11327. materialsForVariant[ keyB ] = cachedMaterial;
  11328. }
  11329. result = cachedMaterial;
  11330. }
  11331. result.visible = material.visible;
  11332. result.wireframe = material.wireframe;
  11333. result.side = ( material.shadowSide != null ) ? material.shadowSide : shadowSide[ material.side ];
  11334. result.clipShadows = material.clipShadows;
  11335. result.clippingPlanes = material.clippingPlanes;
  11336. result.clipIntersection = material.clipIntersection;
  11337. result.wireframeLinewidth = material.wireframeLinewidth;
  11338. result.linewidth = material.linewidth;
  11339. if ( isPointLight && result.isMeshDistanceMaterial ) {
  11340. result.referencePosition.copy( lightPositionWorld );
  11341. result.nearDistance = shadowCameraNear;
  11342. result.farDistance = shadowCameraFar;
  11343. }
  11344. return result;
  11345. }
  11346. function renderObject( object, camera, shadowCamera, isPointLight ) {
  11347. if ( object.visible === false ) return;
  11348. var visible = object.layers.test( camera.layers );
  11349. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  11350. if ( object.castShadow && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  11351. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  11352. var geometry = _objects.update( object );
  11353. var material = object.material;
  11354. if ( Array.isArray( material ) ) {
  11355. var groups = geometry.groups;
  11356. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  11357. var group = groups[ k ];
  11358. var groupMaterial = material[ group.materialIndex ];
  11359. if ( groupMaterial && groupMaterial.visible ) {
  11360. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11361. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  11362. }
  11363. }
  11364. } else if ( material.visible ) {
  11365. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11366. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  11367. }
  11368. }
  11369. }
  11370. var children = object.children;
  11371. for ( var i = 0, l = children.length; i < l; i ++ ) {
  11372. renderObject( children[ i ], camera, shadowCamera, isPointLight );
  11373. }
  11374. }
  11375. }
  11376. /**
  11377. * @author mrdoob / http://mrdoob.com/
  11378. */
  11379. function WebGLState( gl, extensions, utils, capabilities ) {
  11380. function ColorBuffer() {
  11381. var locked = false;
  11382. var color = new Vector4();
  11383. var currentColorMask = null;
  11384. var currentColorClear = new Vector4( 0, 0, 0, 0 );
  11385. return {
  11386. setMask: function ( colorMask ) {
  11387. if ( currentColorMask !== colorMask && ! locked ) {
  11388. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  11389. currentColorMask = colorMask;
  11390. }
  11391. },
  11392. setLocked: function ( lock ) {
  11393. locked = lock;
  11394. },
  11395. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  11396. if ( premultipliedAlpha === true ) {
  11397. r *= a; g *= a; b *= a;
  11398. }
  11399. color.set( r, g, b, a );
  11400. if ( currentColorClear.equals( color ) === false ) {
  11401. gl.clearColor( r, g, b, a );
  11402. currentColorClear.copy( color );
  11403. }
  11404. },
  11405. reset: function () {
  11406. locked = false;
  11407. currentColorMask = null;
  11408. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  11409. }
  11410. };
  11411. }
  11412. function DepthBuffer() {
  11413. var locked = false;
  11414. var currentDepthMask = null;
  11415. var currentDepthFunc = null;
  11416. var currentDepthClear = null;
  11417. return {
  11418. setTest: function ( depthTest ) {
  11419. if ( depthTest ) {
  11420. enable( 2929 );
  11421. } else {
  11422. disable( 2929 );
  11423. }
  11424. },
  11425. setMask: function ( depthMask ) {
  11426. if ( currentDepthMask !== depthMask && ! locked ) {
  11427. gl.depthMask( depthMask );
  11428. currentDepthMask = depthMask;
  11429. }
  11430. },
  11431. setFunc: function ( depthFunc ) {
  11432. if ( currentDepthFunc !== depthFunc ) {
  11433. if ( depthFunc ) {
  11434. switch ( depthFunc ) {
  11435. case NeverDepth:
  11436. gl.depthFunc( 512 );
  11437. break;
  11438. case AlwaysDepth:
  11439. gl.depthFunc( 519 );
  11440. break;
  11441. case LessDepth:
  11442. gl.depthFunc( 513 );
  11443. break;
  11444. case LessEqualDepth:
  11445. gl.depthFunc( 515 );
  11446. break;
  11447. case EqualDepth:
  11448. gl.depthFunc( 514 );
  11449. break;
  11450. case GreaterEqualDepth:
  11451. gl.depthFunc( 518 );
  11452. break;
  11453. case GreaterDepth:
  11454. gl.depthFunc( 516 );
  11455. break;
  11456. case NotEqualDepth:
  11457. gl.depthFunc( 517 );
  11458. break;
  11459. default:
  11460. gl.depthFunc( 515 );
  11461. }
  11462. } else {
  11463. gl.depthFunc( 515 );
  11464. }
  11465. currentDepthFunc = depthFunc;
  11466. }
  11467. },
  11468. setLocked: function ( lock ) {
  11469. locked = lock;
  11470. },
  11471. setClear: function ( depth ) {
  11472. if ( currentDepthClear !== depth ) {
  11473. gl.clearDepth( depth );
  11474. currentDepthClear = depth;
  11475. }
  11476. },
  11477. reset: function () {
  11478. locked = false;
  11479. currentDepthMask = null;
  11480. currentDepthFunc = null;
  11481. currentDepthClear = null;
  11482. }
  11483. };
  11484. }
  11485. function StencilBuffer() {
  11486. var locked = false;
  11487. var currentStencilMask = null;
  11488. var currentStencilFunc = null;
  11489. var currentStencilRef = null;
  11490. var currentStencilFuncMask = null;
  11491. var currentStencilFail = null;
  11492. var currentStencilZFail = null;
  11493. var currentStencilZPass = null;
  11494. var currentStencilClear = null;
  11495. return {
  11496. setTest: function ( stencilTest ) {
  11497. if ( stencilTest ) {
  11498. enable( 2960 );
  11499. } else {
  11500. disable( 2960 );
  11501. }
  11502. },
  11503. setMask: function ( stencilMask ) {
  11504. if ( currentStencilMask !== stencilMask && ! locked ) {
  11505. gl.stencilMask( stencilMask );
  11506. currentStencilMask = stencilMask;
  11507. }
  11508. },
  11509. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  11510. if ( currentStencilFunc !== stencilFunc ||
  11511. currentStencilRef !== stencilRef ||
  11512. currentStencilFuncMask !== stencilMask ) {
  11513. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  11514. currentStencilFunc = stencilFunc;
  11515. currentStencilRef = stencilRef;
  11516. currentStencilFuncMask = stencilMask;
  11517. }
  11518. },
  11519. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  11520. if ( currentStencilFail !== stencilFail ||
  11521. currentStencilZFail !== stencilZFail ||
  11522. currentStencilZPass !== stencilZPass ) {
  11523. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  11524. currentStencilFail = stencilFail;
  11525. currentStencilZFail = stencilZFail;
  11526. currentStencilZPass = stencilZPass;
  11527. }
  11528. },
  11529. setLocked: function ( lock ) {
  11530. locked = lock;
  11531. },
  11532. setClear: function ( stencil ) {
  11533. if ( currentStencilClear !== stencil ) {
  11534. gl.clearStencil( stencil );
  11535. currentStencilClear = stencil;
  11536. }
  11537. },
  11538. reset: function () {
  11539. locked = false;
  11540. currentStencilMask = null;
  11541. currentStencilFunc = null;
  11542. currentStencilRef = null;
  11543. currentStencilFuncMask = null;
  11544. currentStencilFail = null;
  11545. currentStencilZFail = null;
  11546. currentStencilZPass = null;
  11547. currentStencilClear = null;
  11548. }
  11549. };
  11550. }
  11551. //
  11552. var colorBuffer = new ColorBuffer();
  11553. var depthBuffer = new DepthBuffer();
  11554. var stencilBuffer = new StencilBuffer();
  11555. var maxVertexAttributes = gl.getParameter( 34921 );
  11556. var newAttributes = new Uint8Array( maxVertexAttributes );
  11557. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  11558. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  11559. var enabledCapabilities = {};
  11560. var compressedTextureFormats = null;
  11561. var currentProgram = null;
  11562. var currentBlendingEnabled = null;
  11563. var currentBlending = null;
  11564. var currentBlendEquation = null;
  11565. var currentBlendSrc = null;
  11566. var currentBlendDst = null;
  11567. var currentBlendEquationAlpha = null;
  11568. var currentBlendSrcAlpha = null;
  11569. var currentBlendDstAlpha = null;
  11570. var currentPremultipledAlpha = false;
  11571. var currentFlipSided = null;
  11572. var currentCullFace = null;
  11573. var currentLineWidth = null;
  11574. var currentPolygonOffsetFactor = null;
  11575. var currentPolygonOffsetUnits = null;
  11576. var maxTextures = gl.getParameter( 35661 );
  11577. var lineWidthAvailable = false;
  11578. var version = 0;
  11579. var glVersion = gl.getParameter( 7938 );
  11580. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  11581. version = parseFloat( /^WebGL\ ([0-9])/.exec( glVersion )[ 1 ] );
  11582. lineWidthAvailable = ( version >= 1.0 );
  11583. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  11584. version = parseFloat( /^OpenGL\ ES\ ([0-9])/.exec( glVersion )[ 1 ] );
  11585. lineWidthAvailable = ( version >= 2.0 );
  11586. }
  11587. var currentTextureSlot = null;
  11588. var currentBoundTextures = {};
  11589. var currentScissor = new Vector4();
  11590. var currentViewport = new Vector4();
  11591. function createTexture( type, target, count ) {
  11592. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  11593. var texture = gl.createTexture();
  11594. gl.bindTexture( type, texture );
  11595. gl.texParameteri( type, 10241, 9728 );
  11596. gl.texParameteri( type, 10240, 9728 );
  11597. for ( var i = 0; i < count; i ++ ) {
  11598. gl.texImage2D( target + i, 0, 6408, 1, 1, 0, 6408, 5121, data );
  11599. }
  11600. return texture;
  11601. }
  11602. var emptyTextures = {};
  11603. emptyTextures[ 3553 ] = createTexture( 3553, 3553, 1 );
  11604. emptyTextures[ 34067 ] = createTexture( 34067, 34069, 6 );
  11605. // init
  11606. colorBuffer.setClear( 0, 0, 0, 1 );
  11607. depthBuffer.setClear( 1 );
  11608. stencilBuffer.setClear( 0 );
  11609. enable( 2929 );
  11610. depthBuffer.setFunc( LessEqualDepth );
  11611. setFlipSided( false );
  11612. setCullFace( CullFaceBack );
  11613. enable( 2884 );
  11614. setBlending( NoBlending );
  11615. //
  11616. function initAttributes() {
  11617. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  11618. newAttributes[ i ] = 0;
  11619. }
  11620. }
  11621. function enableAttribute( attribute ) {
  11622. enableAttributeAndDivisor( attribute, 0 );
  11623. }
  11624. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  11625. newAttributes[ attribute ] = 1;
  11626. if ( enabledAttributes[ attribute ] === 0 ) {
  11627. gl.enableVertexAttribArray( attribute );
  11628. enabledAttributes[ attribute ] = 1;
  11629. }
  11630. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  11631. var extension = capabilities.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
  11632. extension[ capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
  11633. attributeDivisors[ attribute ] = meshPerAttribute;
  11634. }
  11635. }
  11636. function disableUnusedAttributes() {
  11637. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  11638. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  11639. gl.disableVertexAttribArray( i );
  11640. enabledAttributes[ i ] = 0;
  11641. }
  11642. }
  11643. }
  11644. function enable( id ) {
  11645. if ( enabledCapabilities[ id ] !== true ) {
  11646. gl.enable( id );
  11647. enabledCapabilities[ id ] = true;
  11648. }
  11649. }
  11650. function disable( id ) {
  11651. if ( enabledCapabilities[ id ] !== false ) {
  11652. gl.disable( id );
  11653. enabledCapabilities[ id ] = false;
  11654. }
  11655. }
  11656. function getCompressedTextureFormats() {
  11657. if ( compressedTextureFormats === null ) {
  11658. compressedTextureFormats = [];
  11659. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  11660. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  11661. extensions.get( 'WEBGL_compressed_texture_etc1' ) ||
  11662. extensions.get( 'WEBGL_compressed_texture_astc' ) ) {
  11663. var formats = gl.getParameter( 34467 );
  11664. for ( var i = 0; i < formats.length; i ++ ) {
  11665. compressedTextureFormats.push( formats[ i ] );
  11666. }
  11667. }
  11668. }
  11669. return compressedTextureFormats;
  11670. }
  11671. function useProgram( program ) {
  11672. if ( currentProgram !== program ) {
  11673. gl.useProgram( program );
  11674. currentProgram = program;
  11675. return true;
  11676. }
  11677. return false;
  11678. }
  11679. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  11680. if ( blending === NoBlending ) {
  11681. if ( currentBlendingEnabled ) {
  11682. disable( 3042 );
  11683. currentBlendingEnabled = false;
  11684. }
  11685. return;
  11686. }
  11687. if ( ! currentBlendingEnabled ) {
  11688. enable( 3042 );
  11689. currentBlendingEnabled = true;
  11690. }
  11691. if ( blending !== CustomBlending ) {
  11692. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  11693. if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) {
  11694. gl.blendEquation( 32774 );
  11695. currentBlendEquation = AddEquation;
  11696. currentBlendEquationAlpha = AddEquation;
  11697. }
  11698. if ( premultipliedAlpha ) {
  11699. switch ( blending ) {
  11700. case NormalBlending:
  11701. gl.blendFuncSeparate( 1, 771, 1, 771 );
  11702. break;
  11703. case AdditiveBlending:
  11704. gl.blendFunc( 1, 1 );
  11705. break;
  11706. case SubtractiveBlending:
  11707. gl.blendFuncSeparate( 0, 0, 769, 771 );
  11708. break;
  11709. case MultiplyBlending:
  11710. gl.blendFuncSeparate( 0, 768, 0, 770 );
  11711. break;
  11712. default:
  11713. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  11714. break;
  11715. }
  11716. } else {
  11717. switch ( blending ) {
  11718. case NormalBlending:
  11719. gl.blendFuncSeparate( 770, 771, 1, 771 );
  11720. break;
  11721. case AdditiveBlending:
  11722. gl.blendFunc( 770, 1 );
  11723. break;
  11724. case SubtractiveBlending:
  11725. gl.blendFunc( 0, 769 );
  11726. break;
  11727. case MultiplyBlending:
  11728. gl.blendFunc( 0, 768 );
  11729. break;
  11730. default:
  11731. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  11732. break;
  11733. }
  11734. }
  11735. currentBlendSrc = null;
  11736. currentBlendDst = null;
  11737. currentBlendSrcAlpha = null;
  11738. currentBlendDstAlpha = null;
  11739. currentBlending = blending;
  11740. currentPremultipledAlpha = premultipliedAlpha;
  11741. }
  11742. return;
  11743. }
  11744. // custom blending
  11745. blendEquationAlpha = blendEquationAlpha || blendEquation;
  11746. blendSrcAlpha = blendSrcAlpha || blendSrc;
  11747. blendDstAlpha = blendDstAlpha || blendDst;
  11748. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  11749. gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
  11750. currentBlendEquation = blendEquation;
  11751. currentBlendEquationAlpha = blendEquationAlpha;
  11752. }
  11753. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  11754. gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) );
  11755. currentBlendSrc = blendSrc;
  11756. currentBlendDst = blendDst;
  11757. currentBlendSrcAlpha = blendSrcAlpha;
  11758. currentBlendDstAlpha = blendDstAlpha;
  11759. }
  11760. currentBlending = blending;
  11761. currentPremultipledAlpha = null;
  11762. }
  11763. function setMaterial( material, frontFaceCW ) {
  11764. material.side === DoubleSide
  11765. ? disable( 2884 )
  11766. : enable( 2884 );
  11767. var flipSided = ( material.side === BackSide );
  11768. if ( frontFaceCW ) flipSided = ! flipSided;
  11769. setFlipSided( flipSided );
  11770. ( material.blending === NormalBlending && material.transparent === false )
  11771. ? setBlending( NoBlending )
  11772. : setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  11773. depthBuffer.setFunc( material.depthFunc );
  11774. depthBuffer.setTest( material.depthTest );
  11775. depthBuffer.setMask( material.depthWrite );
  11776. colorBuffer.setMask( material.colorWrite );
  11777. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  11778. }
  11779. //
  11780. function setFlipSided( flipSided ) {
  11781. if ( currentFlipSided !== flipSided ) {
  11782. if ( flipSided ) {
  11783. gl.frontFace( 2304 );
  11784. } else {
  11785. gl.frontFace( 2305 );
  11786. }
  11787. currentFlipSided = flipSided;
  11788. }
  11789. }
  11790. function setCullFace( cullFace ) {
  11791. if ( cullFace !== CullFaceNone ) {
  11792. enable( 2884 );
  11793. if ( cullFace !== currentCullFace ) {
  11794. if ( cullFace === CullFaceBack ) {
  11795. gl.cullFace( 1029 );
  11796. } else if ( cullFace === CullFaceFront ) {
  11797. gl.cullFace( 1028 );
  11798. } else {
  11799. gl.cullFace( 1032 );
  11800. }
  11801. }
  11802. } else {
  11803. disable( 2884 );
  11804. }
  11805. currentCullFace = cullFace;
  11806. }
  11807. function setLineWidth( width ) {
  11808. if ( width !== currentLineWidth ) {
  11809. if ( lineWidthAvailable ) gl.lineWidth( width );
  11810. currentLineWidth = width;
  11811. }
  11812. }
  11813. function setPolygonOffset( polygonOffset, factor, units ) {
  11814. if ( polygonOffset ) {
  11815. enable( 32823 );
  11816. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  11817. gl.polygonOffset( factor, units );
  11818. currentPolygonOffsetFactor = factor;
  11819. currentPolygonOffsetUnits = units;
  11820. }
  11821. } else {
  11822. disable( 32823 );
  11823. }
  11824. }
  11825. function setScissorTest( scissorTest ) {
  11826. if ( scissorTest ) {
  11827. enable( 3089 );
  11828. } else {
  11829. disable( 3089 );
  11830. }
  11831. }
  11832. // texture
  11833. function activeTexture( webglSlot ) {
  11834. if ( webglSlot === undefined ) webglSlot = 33984 + maxTextures - 1;
  11835. if ( currentTextureSlot !== webglSlot ) {
  11836. gl.activeTexture( webglSlot );
  11837. currentTextureSlot = webglSlot;
  11838. }
  11839. }
  11840. function bindTexture( webglType, webglTexture ) {
  11841. if ( currentTextureSlot === null ) {
  11842. activeTexture();
  11843. }
  11844. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  11845. if ( boundTexture === undefined ) {
  11846. boundTexture = { type: undefined, texture: undefined };
  11847. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  11848. }
  11849. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  11850. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  11851. boundTexture.type = webglType;
  11852. boundTexture.texture = webglTexture;
  11853. }
  11854. }
  11855. function compressedTexImage2D() {
  11856. try {
  11857. gl.compressedTexImage2D.apply( gl, arguments );
  11858. } catch ( error ) {
  11859. console.error( 'THREE.WebGLState:', error );
  11860. }
  11861. }
  11862. function texImage2D() {
  11863. try {
  11864. gl.texImage2D.apply( gl, arguments );
  11865. } catch ( error ) {
  11866. console.error( 'THREE.WebGLState:', error );
  11867. }
  11868. }
  11869. function texImage3D() {
  11870. try {
  11871. gl.texImage3D.apply( gl, arguments );
  11872. } catch ( error ) {
  11873. console.error( 'THREE.WebGLState:', error );
  11874. }
  11875. }
  11876. //
  11877. function scissor( scissor ) {
  11878. if ( currentScissor.equals( scissor ) === false ) {
  11879. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  11880. currentScissor.copy( scissor );
  11881. }
  11882. }
  11883. function viewport( viewport ) {
  11884. if ( currentViewport.equals( viewport ) === false ) {
  11885. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  11886. currentViewport.copy( viewport );
  11887. }
  11888. }
  11889. //
  11890. function reset() {
  11891. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  11892. if ( enabledAttributes[ i ] === 1 ) {
  11893. gl.disableVertexAttribArray( i );
  11894. enabledAttributes[ i ] = 0;
  11895. }
  11896. }
  11897. enabledCapabilities = {};
  11898. compressedTextureFormats = null;
  11899. currentTextureSlot = null;
  11900. currentBoundTextures = {};
  11901. currentProgram = null;
  11902. currentBlending = null;
  11903. currentFlipSided = null;
  11904. currentCullFace = null;
  11905. colorBuffer.reset();
  11906. depthBuffer.reset();
  11907. stencilBuffer.reset();
  11908. }
  11909. return {
  11910. buffers: {
  11911. color: colorBuffer,
  11912. depth: depthBuffer,
  11913. stencil: stencilBuffer
  11914. },
  11915. initAttributes: initAttributes,
  11916. enableAttribute: enableAttribute,
  11917. enableAttributeAndDivisor: enableAttributeAndDivisor,
  11918. disableUnusedAttributes: disableUnusedAttributes,
  11919. enable: enable,
  11920. disable: disable,
  11921. getCompressedTextureFormats: getCompressedTextureFormats,
  11922. useProgram: useProgram,
  11923. setBlending: setBlending,
  11924. setMaterial: setMaterial,
  11925. setFlipSided: setFlipSided,
  11926. setCullFace: setCullFace,
  11927. setLineWidth: setLineWidth,
  11928. setPolygonOffset: setPolygonOffset,
  11929. setScissorTest: setScissorTest,
  11930. activeTexture: activeTexture,
  11931. bindTexture: bindTexture,
  11932. compressedTexImage2D: compressedTexImage2D,
  11933. texImage2D: texImage2D,
  11934. texImage3D: texImage3D,
  11935. scissor: scissor,
  11936. viewport: viewport,
  11937. reset: reset
  11938. };
  11939. }
  11940. /**
  11941. * @author mrdoob / http://mrdoob.com/
  11942. */
  11943. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  11944. var _videoTextures = {};
  11945. var _canvas;
  11946. //
  11947. function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
  11948. var scale = 1;
  11949. // handle case if texture exceeds max size
  11950. if ( image.width > maxSize || image.height > maxSize ) {
  11951. scale = maxSize / Math.max( image.width, image.height );
  11952. }
  11953. // only perform resize if necessary
  11954. if ( scale < 1 || needsPowerOfTwo === true ) {
  11955. // only perform resize for certain image types
  11956. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof ImageBitmap ) {
  11957. if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  11958. // cube textures can't reuse the same canvas
  11959. var canvas = needsNewCanvas ? document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ) : _canvas;
  11960. var floor = needsPowerOfTwo ? _Math.floorPowerOfTwo : Math.floor;
  11961. canvas.width = floor( scale * image.width );
  11962. canvas.height = floor( scale * image.height );
  11963. var context = canvas.getContext( '2d' );
  11964. context.drawImage( image, 0, 0, canvas.width, canvas.height );
  11965. console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + canvas.width + 'x' + canvas.height + ').' );
  11966. return canvas;
  11967. } else {
  11968. if ( 'data' in image ) {
  11969. console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  11970. }
  11971. return image;
  11972. }
  11973. }
  11974. return image;
  11975. }
  11976. function isPowerOfTwo( image ) {
  11977. return _Math.isPowerOfTwo( image.width ) && _Math.isPowerOfTwo( image.height );
  11978. }
  11979. function textureNeedsPowerOfTwo( texture ) {
  11980. if ( capabilities.isWebGL2 ) return false;
  11981. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  11982. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  11983. }
  11984. function textureNeedsGenerateMipmaps( texture, isPowerOfTwo ) {
  11985. return texture.generateMipmaps && isPowerOfTwo &&
  11986. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  11987. }
  11988. function generateMipmap( target, texture, width, height ) {
  11989. _gl.generateMipmap( target );
  11990. var textureProperties = properties.get( texture );
  11991. // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  11992. textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
  11993. }
  11994. function getInternalFormat( glFormat, glType ) {
  11995. if ( ! capabilities.isWebGL2 ) return glFormat;
  11996. var internalFormat = glFormat;
  11997. if ( glFormat === 6403 ) {
  11998. if ( glType === 5126 ) internalFormat = 33326;
  11999. if ( glType === 5131 ) internalFormat = 33325;
  12000. if ( glType === 5121 ) internalFormat = 33321;
  12001. }
  12002. if ( glFormat === 6407 ) {
  12003. if ( glType === 5126 ) internalFormat = 34837;
  12004. if ( glType === 5131 ) internalFormat = 34843;
  12005. if ( glType === 5121 ) internalFormat = 32849;
  12006. }
  12007. if ( glFormat === 6408 ) {
  12008. if ( glType === 5126 ) internalFormat = 34836;
  12009. if ( glType === 5131 ) internalFormat = 34842;
  12010. if ( glType === 5121 ) internalFormat = 32856;
  12011. }
  12012. if ( internalFormat === 33325 || internalFormat === 33326 ||
  12013. internalFormat === 34842 || internalFormat === 34836 ) {
  12014. extensions.get( 'EXT_color_buffer_float' );
  12015. } else if ( internalFormat === 34843 || internalFormat === 34837 ) {
  12016. console.warn( 'THREE.WebGLRenderer: Floating point textures with RGB format not supported. Please use RGBA instead.' );
  12017. }
  12018. return internalFormat;
  12019. }
  12020. // Fallback filters for non-power-of-2 textures
  12021. function filterFallback( f ) {
  12022. if ( f === NearestFilter || f === NearestMipMapNearestFilter || f === NearestMipMapLinearFilter ) {
  12023. return 9728;
  12024. }
  12025. return 9729;
  12026. }
  12027. //
  12028. function onTextureDispose( event ) {
  12029. var texture = event.target;
  12030. texture.removeEventListener( 'dispose', onTextureDispose );
  12031. deallocateTexture( texture );
  12032. if ( texture.isVideoTexture ) {
  12033. delete _videoTextures[ texture.id ];
  12034. }
  12035. info.memory.textures --;
  12036. }
  12037. function onRenderTargetDispose( event ) {
  12038. var renderTarget = event.target;
  12039. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  12040. deallocateRenderTarget( renderTarget );
  12041. info.memory.textures --;
  12042. }
  12043. //
  12044. function deallocateTexture( texture ) {
  12045. var textureProperties = properties.get( texture );
  12046. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  12047. // cube texture
  12048. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  12049. } else {
  12050. // 2D texture
  12051. if ( textureProperties.__webglInit === undefined ) return;
  12052. _gl.deleteTexture( textureProperties.__webglTexture );
  12053. }
  12054. // remove all webgl properties
  12055. properties.remove( texture );
  12056. }
  12057. function deallocateRenderTarget( renderTarget ) {
  12058. var renderTargetProperties = properties.get( renderTarget );
  12059. var textureProperties = properties.get( renderTarget.texture );
  12060. if ( ! renderTarget ) return;
  12061. if ( textureProperties.__webglTexture !== undefined ) {
  12062. _gl.deleteTexture( textureProperties.__webglTexture );
  12063. }
  12064. if ( renderTarget.depthTexture ) {
  12065. renderTarget.depthTexture.dispose();
  12066. }
  12067. if ( renderTarget.isWebGLRenderTargetCube ) {
  12068. for ( var i = 0; i < 6; i ++ ) {
  12069. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  12070. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  12071. }
  12072. } else {
  12073. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  12074. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  12075. }
  12076. properties.remove( renderTarget.texture );
  12077. properties.remove( renderTarget );
  12078. }
  12079. //
  12080. function setTexture2D( texture, slot ) {
  12081. var textureProperties = properties.get( texture );
  12082. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  12083. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12084. var image = texture.image;
  12085. if ( image === undefined ) {
  12086. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined' );
  12087. } else if ( image.complete === false ) {
  12088. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete' );
  12089. } else {
  12090. uploadTexture( textureProperties, texture, slot );
  12091. return;
  12092. }
  12093. }
  12094. state.activeTexture( 33984 + slot );
  12095. state.bindTexture( 3553, textureProperties.__webglTexture );
  12096. }
  12097. function setTexture3D( texture, slot ) {
  12098. var textureProperties = properties.get( texture );
  12099. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12100. uploadTexture( textureProperties, texture, slot );
  12101. return;
  12102. }
  12103. state.activeTexture( 33984 + slot );
  12104. state.bindTexture( 32879, textureProperties.__webglTexture );
  12105. }
  12106. function setTextureCube( texture, slot ) {
  12107. var textureProperties = properties.get( texture );
  12108. if ( texture.image.length === 6 ) {
  12109. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12110. if ( ! textureProperties.__image__webglTextureCube ) {
  12111. texture.addEventListener( 'dispose', onTextureDispose );
  12112. textureProperties.__image__webglTextureCube = _gl.createTexture();
  12113. info.memory.textures ++;
  12114. }
  12115. state.activeTexture( 33984 + slot );
  12116. state.bindTexture( 34067, textureProperties.__image__webglTextureCube );
  12117. _gl.pixelStorei( 37440, texture.flipY );
  12118. var isCompressed = ( texture && texture.isCompressedTexture );
  12119. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  12120. var cubeImage = [];
  12121. for ( var i = 0; i < 6; i ++ ) {
  12122. if ( ! isCompressed && ! isDataTexture ) {
  12123. cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, capabilities.maxCubemapSize );
  12124. } else {
  12125. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  12126. }
  12127. }
  12128. var image = cubeImage[ 0 ],
  12129. isPowerOfTwoImage = isPowerOfTwo( image ),
  12130. glFormat = utils.convert( texture.format ),
  12131. glType = utils.convert( texture.type ),
  12132. glInternalFormat = getInternalFormat( glFormat, glType );
  12133. setTextureParameters( 34067, texture, isPowerOfTwoImage );
  12134. for ( var i = 0; i < 6; i ++ ) {
  12135. if ( ! isCompressed ) {
  12136. if ( isDataTexture ) {
  12137. state.texImage2D( 34069 + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  12138. } else {
  12139. state.texImage2D( 34069 + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
  12140. }
  12141. } else {
  12142. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  12143. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  12144. mipmap = mipmaps[ j ];
  12145. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12146. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12147. state.compressedTexImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12148. } else {
  12149. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  12150. }
  12151. } else {
  12152. state.texImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12153. }
  12154. }
  12155. }
  12156. }
  12157. if ( ! isCompressed ) {
  12158. textureProperties.__maxMipLevel = 0;
  12159. } else {
  12160. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12161. }
  12162. if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) {
  12163. // We assume images for cube map have the same size.
  12164. generateMipmap( 34067, texture, image.width, image.height );
  12165. }
  12166. textureProperties.__version = texture.version;
  12167. if ( texture.onUpdate ) texture.onUpdate( texture );
  12168. } else {
  12169. state.activeTexture( 33984 + slot );
  12170. state.bindTexture( 34067, textureProperties.__image__webglTextureCube );
  12171. }
  12172. }
  12173. }
  12174. function setTextureCubeDynamic( texture, slot ) {
  12175. state.activeTexture( 33984 + slot );
  12176. state.bindTexture( 34067, properties.get( texture ).__webglTexture );
  12177. }
  12178. function setTextureParameters( textureType, texture, isPowerOfTwoImage ) {
  12179. var extension;
  12180. if ( isPowerOfTwoImage ) {
  12181. _gl.texParameteri( textureType, 10242, utils.convert( texture.wrapS ) );
  12182. _gl.texParameteri( textureType, 10243, utils.convert( texture.wrapT ) );
  12183. _gl.texParameteri( textureType, 10240, utils.convert( texture.magFilter ) );
  12184. _gl.texParameteri( textureType, 10241, utils.convert( texture.minFilter ) );
  12185. } else {
  12186. _gl.texParameteri( textureType, 10242, 33071 );
  12187. _gl.texParameteri( textureType, 10243, 33071 );
  12188. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  12189. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.' );
  12190. }
  12191. _gl.texParameteri( textureType, 10240, filterFallback( texture.magFilter ) );
  12192. _gl.texParameteri( textureType, 10241, filterFallback( texture.minFilter ) );
  12193. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  12194. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.' );
  12195. }
  12196. }
  12197. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  12198. if ( extension ) {
  12199. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  12200. if ( texture.type === HalfFloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) return;
  12201. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  12202. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  12203. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  12204. }
  12205. }
  12206. }
  12207. function uploadTexture( textureProperties, texture, slot ) {
  12208. var textureType;
  12209. if ( texture.isDataTexture3D ) {
  12210. textureType = 32879;
  12211. } else {
  12212. textureType = 3553;
  12213. }
  12214. if ( textureProperties.__webglInit === undefined ) {
  12215. textureProperties.__webglInit = true;
  12216. texture.addEventListener( 'dispose', onTextureDispose );
  12217. textureProperties.__webglTexture = _gl.createTexture();
  12218. info.memory.textures ++;
  12219. }
  12220. state.activeTexture( 33984 + slot );
  12221. state.bindTexture( textureType, textureProperties.__webglTexture );
  12222. _gl.pixelStorei( 37440, texture.flipY );
  12223. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  12224. _gl.pixelStorei( 3317, texture.unpackAlignment );
  12225. var needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
  12226. var image = resizeImage( texture.image, needsPowerOfTwo, false, capabilities.maxTextureSize );
  12227. var isPowerOfTwoImage = isPowerOfTwo( image ),
  12228. glFormat = utils.convert( texture.format ),
  12229. glType = utils.convert( texture.type ),
  12230. glInternalFormat = getInternalFormat( glFormat, glType );
  12231. setTextureParameters( textureType, texture, isPowerOfTwoImage );
  12232. var mipmap, mipmaps = texture.mipmaps;
  12233. if ( texture.isDepthTexture ) {
  12234. // populate depth texture with dummy data
  12235. glInternalFormat = 6402;
  12236. if ( texture.type === FloatType ) {
  12237. if ( ! capabilities.isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
  12238. glInternalFormat = 36012;
  12239. } else if ( capabilities.isWebGL2 ) {
  12240. // WebGL 2.0 requires signed internalformat for glTexImage2D
  12241. glInternalFormat = 33189;
  12242. }
  12243. if ( texture.format === DepthFormat && glInternalFormat === 6402 ) {
  12244. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12245. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12246. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12247. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  12248. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  12249. texture.type = UnsignedShortType;
  12250. glType = utils.convert( texture.type );
  12251. }
  12252. }
  12253. // Depth stencil textures need the DEPTH_STENCIL internal format
  12254. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12255. if ( texture.format === DepthStencilFormat ) {
  12256. glInternalFormat = 34041;
  12257. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12258. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12259. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12260. if ( texture.type !== UnsignedInt248Type ) {
  12261. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  12262. texture.type = UnsignedInt248Type;
  12263. glType = utils.convert( texture.type );
  12264. }
  12265. }
  12266. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
  12267. } else if ( texture.isDataTexture ) {
  12268. // use manually created mipmaps if available
  12269. // if there are no manual mipmaps
  12270. // set 0 level mipmap and then use GL to generate other mipmap levels
  12271. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  12272. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12273. mipmap = mipmaps[ i ];
  12274. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12275. }
  12276. texture.generateMipmaps = false;
  12277. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12278. } else {
  12279. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
  12280. textureProperties.__maxMipLevel = 0;
  12281. }
  12282. } else if ( texture.isCompressedTexture ) {
  12283. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12284. mipmap = mipmaps[ i ];
  12285. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12286. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12287. state.compressedTexImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12288. } else {
  12289. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  12290. }
  12291. } else {
  12292. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12293. }
  12294. }
  12295. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12296. } else if ( texture.isDataTexture3D ) {
  12297. state.texImage3D( 32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12298. textureProperties.__maxMipLevel = 0;
  12299. } else {
  12300. // regular Texture (image, video, canvas)
  12301. // use manually created mipmaps if available
  12302. // if there are no manual mipmaps
  12303. // set 0 level mipmap and then use GL to generate other mipmap levels
  12304. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  12305. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12306. mipmap = mipmaps[ i ];
  12307. state.texImage2D( 3553, i, glInternalFormat, glFormat, glType, mipmap );
  12308. }
  12309. texture.generateMipmaps = false;
  12310. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12311. } else {
  12312. state.texImage2D( 3553, 0, glInternalFormat, glFormat, glType, image );
  12313. textureProperties.__maxMipLevel = 0;
  12314. }
  12315. }
  12316. if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) {
  12317. generateMipmap( 3553, texture, image.width, image.height );
  12318. }
  12319. textureProperties.__version = texture.version;
  12320. if ( texture.onUpdate ) texture.onUpdate( texture );
  12321. }
  12322. // Render targets
  12323. // Setup storage for target texture and bind it to correct framebuffer
  12324. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  12325. var glFormat = utils.convert( renderTarget.texture.format );
  12326. var glType = utils.convert( renderTarget.texture.type );
  12327. var glInternalFormat = getInternalFormat( glFormat, glType );
  12328. state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  12329. _gl.bindFramebuffer( 36160, framebuffer );
  12330. _gl.framebufferTexture2D( 36160, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  12331. _gl.bindFramebuffer( 36160, null );
  12332. }
  12333. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  12334. function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
  12335. _gl.bindRenderbuffer( 36161, renderbuffer );
  12336. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  12337. if ( isMultisample ) {
  12338. var samples = getRenderTargetSamples( renderTarget );
  12339. _gl.renderbufferStorageMultisample( 36161, samples, 33189, renderTarget.width, renderTarget.height );
  12340. } else {
  12341. _gl.renderbufferStorage( 36161, 33189, renderTarget.width, renderTarget.height );
  12342. }
  12343. _gl.framebufferRenderbuffer( 36160, 36096, 36161, renderbuffer );
  12344. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  12345. if ( isMultisample ) {
  12346. var samples = getRenderTargetSamples( renderTarget );
  12347. _gl.renderbufferStorageMultisample( 36161, samples, 34041, renderTarget.width, renderTarget.height );
  12348. } else {
  12349. _gl.renderbufferStorage( 36161, 34041, renderTarget.width, renderTarget.height );
  12350. }
  12351. _gl.framebufferRenderbuffer( 36160, 33306, 36161, renderbuffer );
  12352. } else {
  12353. var glFormat = utils.convert( renderTarget.texture.format );
  12354. var glType = utils.convert( renderTarget.texture.type );
  12355. var glInternalFormat = getInternalFormat( glFormat, glType );
  12356. if ( isMultisample ) {
  12357. var samples = getRenderTargetSamples( renderTarget );
  12358. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12359. } else {
  12360. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  12361. }
  12362. }
  12363. _gl.bindRenderbuffer( 36161, null );
  12364. }
  12365. // Setup resources for a Depth Texture for a FBO (needs an extension)
  12366. function setupDepthTexture( framebuffer, renderTarget ) {
  12367. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  12368. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  12369. _gl.bindFramebuffer( 36160, framebuffer );
  12370. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  12371. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  12372. }
  12373. // upload an empty depth texture with framebuffer size
  12374. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  12375. renderTarget.depthTexture.image.width !== renderTarget.width ||
  12376. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  12377. renderTarget.depthTexture.image.width = renderTarget.width;
  12378. renderTarget.depthTexture.image.height = renderTarget.height;
  12379. renderTarget.depthTexture.needsUpdate = true;
  12380. }
  12381. setTexture2D( renderTarget.depthTexture, 0 );
  12382. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  12383. if ( renderTarget.depthTexture.format === DepthFormat ) {
  12384. _gl.framebufferTexture2D( 36160, 36096, 3553, webglDepthTexture, 0 );
  12385. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  12386. _gl.framebufferTexture2D( 36160, 33306, 3553, webglDepthTexture, 0 );
  12387. } else {
  12388. throw new Error( 'Unknown depthTexture format' );
  12389. }
  12390. }
  12391. // Setup GL resources for a non-texture depth buffer
  12392. function setupDepthRenderbuffer( renderTarget ) {
  12393. var renderTargetProperties = properties.get( renderTarget );
  12394. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  12395. if ( renderTarget.depthTexture ) {
  12396. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  12397. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  12398. } else {
  12399. if ( isCube ) {
  12400. renderTargetProperties.__webglDepthbuffer = [];
  12401. for ( var i = 0; i < 6; i ++ ) {
  12402. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer[ i ] );
  12403. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  12404. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  12405. }
  12406. } else {
  12407. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer );
  12408. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  12409. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  12410. }
  12411. }
  12412. _gl.bindFramebuffer( 36160, null );
  12413. }
  12414. // Set up GL resources for the render target
  12415. function setupRenderTarget( renderTarget ) {
  12416. var renderTargetProperties = properties.get( renderTarget );
  12417. var textureProperties = properties.get( renderTarget.texture );
  12418. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  12419. textureProperties.__webglTexture = _gl.createTexture();
  12420. info.memory.textures ++;
  12421. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  12422. var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
  12423. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  12424. // Setup framebuffer
  12425. if ( isCube ) {
  12426. renderTargetProperties.__webglFramebuffer = [];
  12427. for ( var i = 0; i < 6; i ++ ) {
  12428. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  12429. }
  12430. } else {
  12431. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  12432. if ( isMultisample ) {
  12433. if ( capabilities.isWebGL2 ) {
  12434. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  12435. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  12436. _gl.bindRenderbuffer( 36161, renderTargetProperties.__webglColorRenderbuffer );
  12437. var glFormat = utils.convert( renderTarget.texture.format );
  12438. var glType = utils.convert( renderTarget.texture.type );
  12439. var glInternalFormat = getInternalFormat( glFormat, glType );
  12440. var samples = getRenderTargetSamples( renderTarget );
  12441. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12442. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer );
  12443. _gl.framebufferRenderbuffer( 36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer );
  12444. _gl.bindRenderbuffer( 36161, null );
  12445. if ( renderTarget.depthBuffer ) {
  12446. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  12447. setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );
  12448. }
  12449. _gl.bindFramebuffer( 36160, null );
  12450. } else {
  12451. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  12452. }
  12453. }
  12454. }
  12455. // Setup color buffer
  12456. if ( isCube ) {
  12457. state.bindTexture( 34067, textureProperties.__webglTexture );
  12458. setTextureParameters( 34067, renderTarget.texture, isTargetPowerOfTwo );
  12459. for ( var i = 0; i < 6; i ++ ) {
  12460. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, 36064, 34069 + i );
  12461. }
  12462. if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) {
  12463. generateMipmap( 34067, renderTarget.texture, renderTarget.width, renderTarget.height );
  12464. }
  12465. state.bindTexture( 34067, null );
  12466. } else {
  12467. state.bindTexture( 3553, textureProperties.__webglTexture );
  12468. setTextureParameters( 3553, renderTarget.texture, isTargetPowerOfTwo );
  12469. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553 );
  12470. if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) {
  12471. generateMipmap( 3553, renderTarget.texture, renderTarget.width, renderTarget.height );
  12472. }
  12473. state.bindTexture( 3553, null );
  12474. }
  12475. // Setup depth and stencil buffers
  12476. if ( renderTarget.depthBuffer ) {
  12477. setupDepthRenderbuffer( renderTarget );
  12478. }
  12479. }
  12480. function updateRenderTargetMipmap( renderTarget ) {
  12481. var texture = renderTarget.texture;
  12482. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  12483. if ( textureNeedsGenerateMipmaps( texture, isTargetPowerOfTwo ) ) {
  12484. var target = renderTarget.isWebGLRenderTargetCube ? 34067 : 3553;
  12485. var webglTexture = properties.get( texture ).__webglTexture;
  12486. state.bindTexture( target, webglTexture );
  12487. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  12488. state.bindTexture( target, null );
  12489. }
  12490. }
  12491. function updateMultisampleRenderTarget( renderTarget ) {
  12492. if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  12493. if ( capabilities.isWebGL2 ) {
  12494. var renderTargetProperties = properties.get( renderTarget );
  12495. _gl.bindFramebuffer( 36008, renderTargetProperties.__webglMultisampledFramebuffer );
  12496. _gl.bindFramebuffer( 36009, renderTargetProperties.__webglFramebuffer );
  12497. var width = renderTarget.width;
  12498. var height = renderTarget.height;
  12499. var mask = 16384;
  12500. if ( renderTarget.depthBuffer ) mask |= 256;
  12501. if ( renderTarget.stencilBuffer ) mask |= 1024;
  12502. _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, 9728 );
  12503. } else {
  12504. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  12505. }
  12506. }
  12507. }
  12508. function getRenderTargetSamples( renderTarget ) {
  12509. return ( capabilities.isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
  12510. Math.min( capabilities.maxSamples, renderTarget.samples ) : 0;
  12511. }
  12512. function updateVideoTexture( texture ) {
  12513. var id = texture.id;
  12514. var frame = info.render.frame;
  12515. // Check the last frame we updated the VideoTexture
  12516. if ( _videoTextures[ id ] !== frame ) {
  12517. _videoTextures[ id ] = frame;
  12518. texture.update();
  12519. }
  12520. }
  12521. this.setTexture2D = setTexture2D;
  12522. this.setTexture3D = setTexture3D;
  12523. this.setTextureCube = setTextureCube;
  12524. this.setTextureCubeDynamic = setTextureCubeDynamic;
  12525. this.setupRenderTarget = setupRenderTarget;
  12526. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  12527. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  12528. }
  12529. /**
  12530. * @author thespite / http://www.twitter.com/thespite
  12531. */
  12532. function WebGLUtils( gl, extensions, capabilities ) {
  12533. function convert( p ) {
  12534. var extension;
  12535. if ( p === RepeatWrapping ) return 10497;
  12536. if ( p === ClampToEdgeWrapping ) return 33071;
  12537. if ( p === MirroredRepeatWrapping ) return 33648;
  12538. if ( p === NearestFilter ) return 9728;
  12539. if ( p === NearestMipMapNearestFilter ) return 9984;
  12540. if ( p === NearestMipMapLinearFilter ) return 9986;
  12541. if ( p === LinearFilter ) return 9729;
  12542. if ( p === LinearMipMapNearestFilter ) return 9985;
  12543. if ( p === LinearMipMapLinearFilter ) return 9987;
  12544. if ( p === UnsignedByteType ) return 5121;
  12545. if ( p === UnsignedShort4444Type ) return 32819;
  12546. if ( p === UnsignedShort5551Type ) return 32820;
  12547. if ( p === UnsignedShort565Type ) return 33635;
  12548. if ( p === ByteType ) return 5120;
  12549. if ( p === ShortType ) return 5122;
  12550. if ( p === UnsignedShortType ) return 5123;
  12551. if ( p === IntType ) return 5124;
  12552. if ( p === UnsignedIntType ) return 5125;
  12553. if ( p === FloatType ) return 5126;
  12554. if ( p === HalfFloatType ) {
  12555. if ( capabilities.isWebGL2 ) return 5131;
  12556. extension = extensions.get( 'OES_texture_half_float' );
  12557. if ( extension !== null ) return extension.HALF_FLOAT_OES;
  12558. }
  12559. if ( p === AlphaFormat ) return 6406;
  12560. if ( p === RGBFormat ) return 6407;
  12561. if ( p === RGBAFormat ) return 6408;
  12562. if ( p === LuminanceFormat ) return 6409;
  12563. if ( p === LuminanceAlphaFormat ) return 6410;
  12564. if ( p === DepthFormat ) return 6402;
  12565. if ( p === DepthStencilFormat ) return 34041;
  12566. if ( p === RedFormat ) return 6403;
  12567. if ( p === AddEquation ) return 32774;
  12568. if ( p === SubtractEquation ) return 32778;
  12569. if ( p === ReverseSubtractEquation ) return 32779;
  12570. if ( p === ZeroFactor ) return 0;
  12571. if ( p === OneFactor ) return 1;
  12572. if ( p === SrcColorFactor ) return 768;
  12573. if ( p === OneMinusSrcColorFactor ) return 769;
  12574. if ( p === SrcAlphaFactor ) return 770;
  12575. if ( p === OneMinusSrcAlphaFactor ) return 771;
  12576. if ( p === DstAlphaFactor ) return 772;
  12577. if ( p === OneMinusDstAlphaFactor ) return 773;
  12578. if ( p === DstColorFactor ) return 774;
  12579. if ( p === OneMinusDstColorFactor ) return 775;
  12580. if ( p === SrcAlphaSaturateFactor ) return 776;
  12581. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  12582. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  12583. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  12584. if ( extension !== null ) {
  12585. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  12586. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  12587. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  12588. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  12589. }
  12590. }
  12591. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  12592. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  12593. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  12594. if ( extension !== null ) {
  12595. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  12596. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  12597. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  12598. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  12599. }
  12600. }
  12601. if ( p === RGB_ETC1_Format ) {
  12602. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  12603. if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  12604. }
  12605. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  12606. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  12607. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  12608. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  12609. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ) {
  12610. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  12611. if ( extension !== null ) {
  12612. return p;
  12613. }
  12614. }
  12615. if ( p === MinEquation || p === MaxEquation ) {
  12616. if ( capabilities.isWebGL2 ) {
  12617. if ( p === MinEquation ) return 32775;
  12618. if ( p === MaxEquation ) return 32776;
  12619. }
  12620. extension = extensions.get( 'EXT_blend_minmax' );
  12621. if ( extension !== null ) {
  12622. if ( p === MinEquation ) return extension.MIN_EXT;
  12623. if ( p === MaxEquation ) return extension.MAX_EXT;
  12624. }
  12625. }
  12626. if ( p === UnsignedInt248Type ) {
  12627. if ( capabilities.isWebGL2 ) return 34042;
  12628. extension = extensions.get( 'WEBGL_depth_texture' );
  12629. if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
  12630. }
  12631. return 0;
  12632. }
  12633. return { convert: convert };
  12634. }
  12635. /**
  12636. * @author mrdoob / http://mrdoob.com/
  12637. */
  12638. function Group() {
  12639. Object3D.call( this );
  12640. this.type = 'Group';
  12641. }
  12642. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  12643. constructor: Group,
  12644. isGroup: true
  12645. } );
  12646. /**
  12647. * @author mrdoob / http://mrdoob.com/
  12648. * @author mikael emtinger / http://gomo.se/
  12649. * @author WestLangley / http://github.com/WestLangley
  12650. */
  12651. function Camera() {
  12652. Object3D.call( this );
  12653. this.type = 'Camera';
  12654. this.matrixWorldInverse = new Matrix4();
  12655. this.projectionMatrix = new Matrix4();
  12656. this.projectionMatrixInverse = new Matrix4();
  12657. }
  12658. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  12659. constructor: Camera,
  12660. isCamera: true,
  12661. copy: function ( source, recursive ) {
  12662. Object3D.prototype.copy.call( this, source, recursive );
  12663. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  12664. this.projectionMatrix.copy( source.projectionMatrix );
  12665. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  12666. return this;
  12667. },
  12668. getWorldDirection: function ( target ) {
  12669. if ( target === undefined ) {
  12670. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  12671. target = new Vector3();
  12672. }
  12673. this.updateMatrixWorld( true );
  12674. var e = this.matrixWorld.elements;
  12675. return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
  12676. },
  12677. updateMatrixWorld: function ( force ) {
  12678. Object3D.prototype.updateMatrixWorld.call( this, force );
  12679. this.matrixWorldInverse.getInverse( this.matrixWorld );
  12680. },
  12681. clone: function () {
  12682. return new this.constructor().copy( this );
  12683. }
  12684. } );
  12685. /**
  12686. * @author mrdoob / http://mrdoob.com/
  12687. * @author greggman / http://games.greggman.com/
  12688. * @author zz85 / http://www.lab4games.net/zz85/blog
  12689. * @author tschw
  12690. */
  12691. function PerspectiveCamera( fov, aspect, near, far ) {
  12692. Camera.call( this );
  12693. this.type = 'PerspectiveCamera';
  12694. this.fov = fov !== undefined ? fov : 50;
  12695. this.zoom = 1;
  12696. this.near = near !== undefined ? near : 0.1;
  12697. this.far = far !== undefined ? far : 2000;
  12698. this.focus = 10;
  12699. this.aspect = aspect !== undefined ? aspect : 1;
  12700. this.view = null;
  12701. this.filmGauge = 35; // width of the film (default in millimeters)
  12702. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  12703. this.updateProjectionMatrix();
  12704. }
  12705. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  12706. constructor: PerspectiveCamera,
  12707. isPerspectiveCamera: true,
  12708. copy: function ( source, recursive ) {
  12709. Camera.prototype.copy.call( this, source, recursive );
  12710. this.fov = source.fov;
  12711. this.zoom = source.zoom;
  12712. this.near = source.near;
  12713. this.far = source.far;
  12714. this.focus = source.focus;
  12715. this.aspect = source.aspect;
  12716. this.view = source.view === null ? null : Object.assign( {}, source.view );
  12717. this.filmGauge = source.filmGauge;
  12718. this.filmOffset = source.filmOffset;
  12719. return this;
  12720. },
  12721. /**
  12722. * Sets the FOV by focal length in respect to the current .filmGauge.
  12723. *
  12724. * The default film gauge is 35, so that the focal length can be specified for
  12725. * a 35mm (full frame) camera.
  12726. *
  12727. * Values for focal length and film gauge must have the same unit.
  12728. */
  12729. setFocalLength: function ( focalLength ) {
  12730. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  12731. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  12732. this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  12733. this.updateProjectionMatrix();
  12734. },
  12735. /**
  12736. * Calculates the focal length from the current .fov and .filmGauge.
  12737. */
  12738. getFocalLength: function () {
  12739. var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
  12740. return 0.5 * this.getFilmHeight() / vExtentSlope;
  12741. },
  12742. getEffectiveFOV: function () {
  12743. return _Math.RAD2DEG * 2 * Math.atan(
  12744. Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  12745. },
  12746. getFilmWidth: function () {
  12747. // film not completely covered in portrait format (aspect < 1)
  12748. return this.filmGauge * Math.min( this.aspect, 1 );
  12749. },
  12750. getFilmHeight: function () {
  12751. // film not completely covered in landscape format (aspect > 1)
  12752. return this.filmGauge / Math.max( this.aspect, 1 );
  12753. },
  12754. /**
  12755. * Sets an offset in a larger frustum. This is useful for multi-window or
  12756. * multi-monitor/multi-machine setups.
  12757. *
  12758. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  12759. * the monitors are in grid like this
  12760. *
  12761. * +---+---+---+
  12762. * | A | B | C |
  12763. * +---+---+---+
  12764. * | D | E | F |
  12765. * +---+---+---+
  12766. *
  12767. * then for each monitor you would call it like this
  12768. *
  12769. * var w = 1920;
  12770. * var h = 1080;
  12771. * var fullWidth = w * 3;
  12772. * var fullHeight = h * 2;
  12773. *
  12774. * --A--
  12775. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  12776. * --B--
  12777. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  12778. * --C--
  12779. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  12780. * --D--
  12781. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  12782. * --E--
  12783. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  12784. * --F--
  12785. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  12786. *
  12787. * Note there is no reason monitors have to be the same size or in a grid.
  12788. */
  12789. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  12790. this.aspect = fullWidth / fullHeight;
  12791. if ( this.view === null ) {
  12792. this.view = {
  12793. enabled: true,
  12794. fullWidth: 1,
  12795. fullHeight: 1,
  12796. offsetX: 0,
  12797. offsetY: 0,
  12798. width: 1,
  12799. height: 1
  12800. };
  12801. }
  12802. this.view.enabled = true;
  12803. this.view.fullWidth = fullWidth;
  12804. this.view.fullHeight = fullHeight;
  12805. this.view.offsetX = x;
  12806. this.view.offsetY = y;
  12807. this.view.width = width;
  12808. this.view.height = height;
  12809. this.updateProjectionMatrix();
  12810. },
  12811. clearViewOffset: function () {
  12812. if ( this.view !== null ) {
  12813. this.view.enabled = false;
  12814. }
  12815. this.updateProjectionMatrix();
  12816. },
  12817. updateProjectionMatrix: function () {
  12818. var near = this.near,
  12819. top = near * Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  12820. height = 2 * top,
  12821. width = this.aspect * height,
  12822. left = - 0.5 * width,
  12823. view = this.view;
  12824. if ( this.view !== null && this.view.enabled ) {
  12825. var fullWidth = view.fullWidth,
  12826. fullHeight = view.fullHeight;
  12827. left += view.offsetX * width / fullWidth;
  12828. top -= view.offsetY * height / fullHeight;
  12829. width *= view.width / fullWidth;
  12830. height *= view.height / fullHeight;
  12831. }
  12832. var skew = this.filmOffset;
  12833. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  12834. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  12835. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  12836. },
  12837. toJSON: function ( meta ) {
  12838. var data = Object3D.prototype.toJSON.call( this, meta );
  12839. data.object.fov = this.fov;
  12840. data.object.zoom = this.zoom;
  12841. data.object.near = this.near;
  12842. data.object.far = this.far;
  12843. data.object.focus = this.focus;
  12844. data.object.aspect = this.aspect;
  12845. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  12846. data.object.filmGauge = this.filmGauge;
  12847. data.object.filmOffset = this.filmOffset;
  12848. return data;
  12849. }
  12850. } );
  12851. /**
  12852. * @author mrdoob / http://mrdoob.com/
  12853. */
  12854. function ArrayCamera( array ) {
  12855. PerspectiveCamera.call( this );
  12856. this.cameras = array || [];
  12857. }
  12858. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  12859. constructor: ArrayCamera,
  12860. isArrayCamera: true
  12861. } );
  12862. /**
  12863. * @author jsantell / https://www.jsantell.com/
  12864. * @author mrdoob / http://mrdoob.com/
  12865. */
  12866. var cameraLPos = new Vector3();
  12867. var cameraRPos = new Vector3();
  12868. /**
  12869. * Assumes 2 cameras that are parallel and share an X-axis, and that
  12870. * the cameras' projection and world matrices have already been set.
  12871. * And that near and far planes are identical for both cameras.
  12872. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  12873. */
  12874. function setProjectionFromUnion( camera, cameraL, cameraR ) {
  12875. cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
  12876. cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
  12877. var ipd = cameraLPos.distanceTo( cameraRPos );
  12878. var projL = cameraL.projectionMatrix.elements;
  12879. var projR = cameraR.projectionMatrix.elements;
  12880. // VR systems will have identical far and near planes, and
  12881. // most likely identical top and bottom frustum extents.
  12882. // Use the left camera for these values.
  12883. var near = projL[ 14 ] / ( projL[ 10 ] - 1 );
  12884. var far = projL[ 14 ] / ( projL[ 10 ] + 1 );
  12885. var topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
  12886. var bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
  12887. var leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
  12888. var rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
  12889. var left = near * leftFov;
  12890. var right = near * rightFov;
  12891. // Calculate the new camera's position offset from the
  12892. // left camera. xOffset should be roughly half `ipd`.
  12893. var zOffset = ipd / ( - leftFov + rightFov );
  12894. var xOffset = zOffset * - leftFov;
  12895. // TODO: Better way to apply this offset?
  12896. cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
  12897. camera.translateX( xOffset );
  12898. camera.translateZ( zOffset );
  12899. camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
  12900. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  12901. // Find the union of the frustum values of the cameras and scale
  12902. // the values so that the near plane's position does not change in world space,
  12903. // although must now be relative to the new union camera.
  12904. var near2 = near + zOffset;
  12905. var far2 = far + zOffset;
  12906. var left2 = left - xOffset;
  12907. var right2 = right + ( ipd - xOffset );
  12908. var top2 = topFov * far / far2 * near2;
  12909. var bottom2 = bottomFov * far / far2 * near2;
  12910. camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
  12911. }
  12912. /**
  12913. * @author mrdoob / http://mrdoob.com/
  12914. */
  12915. function WebVRManager( renderer ) {
  12916. var scope = this;
  12917. var device = null;
  12918. var frameData = null;
  12919. var poseTarget = null;
  12920. var controllers = [];
  12921. var standingMatrix = new Matrix4();
  12922. var standingMatrixInverse = new Matrix4();
  12923. var framebufferScaleFactor = 1.0;
  12924. var frameOfReferenceType = 'stage';
  12925. if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
  12926. frameData = new window.VRFrameData();
  12927. window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
  12928. }
  12929. var matrixWorldInverse = new Matrix4();
  12930. var tempQuaternion = new Quaternion();
  12931. var tempPosition = new Vector3();
  12932. var cameraL = new PerspectiveCamera();
  12933. cameraL.bounds = new Vector4( 0.0, 0.0, 0.5, 1.0 );
  12934. cameraL.layers.enable( 1 );
  12935. var cameraR = new PerspectiveCamera();
  12936. cameraR.bounds = new Vector4( 0.5, 0.0, 0.5, 1.0 );
  12937. cameraR.layers.enable( 2 );
  12938. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  12939. cameraVR.layers.enable( 1 );
  12940. cameraVR.layers.enable( 2 );
  12941. //
  12942. function isPresenting() {
  12943. return device !== null && device.isPresenting === true;
  12944. }
  12945. var currentSize, currentPixelRatio;
  12946. function onVRDisplayPresentChange() {
  12947. if ( isPresenting() ) {
  12948. var eyeParameters = device.getEyeParameters( 'left' );
  12949. var renderWidth = eyeParameters.renderWidth * framebufferScaleFactor;
  12950. var renderHeight = eyeParameters.renderHeight * framebufferScaleFactor;
  12951. currentPixelRatio = renderer.getPixelRatio();
  12952. currentSize = renderer.getSize();
  12953. renderer.setDrawingBufferSize( renderWidth * 2, renderHeight, 1 );
  12954. animation.start();
  12955. } else {
  12956. if ( scope.enabled ) {
  12957. renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
  12958. }
  12959. animation.stop();
  12960. }
  12961. }
  12962. //
  12963. var triggers = [];
  12964. function findGamepad( id ) {
  12965. var gamepads = navigator.getGamepads && navigator.getGamepads();
  12966. for ( var i = 0, j = 0, l = gamepads.length; i < l; i ++ ) {
  12967. var gamepad = gamepads[ i ];
  12968. if ( gamepad && ( gamepad.id === 'Daydream Controller' ||
  12969. gamepad.id === 'Gear VR Controller' || gamepad.id === 'Oculus Go Controller' ||
  12970. gamepad.id === 'OpenVR Gamepad' || gamepad.id.startsWith( 'Oculus Touch' ) ||
  12971. gamepad.id.startsWith( 'Spatial Controller' ) ) ) {
  12972. if ( j === id ) return gamepad;
  12973. j ++;
  12974. }
  12975. }
  12976. }
  12977. function updateControllers() {
  12978. for ( var i = 0; i < controllers.length; i ++ ) {
  12979. var controller = controllers[ i ];
  12980. var gamepad = findGamepad( i );
  12981. if ( gamepad !== undefined && gamepad.pose !== undefined ) {
  12982. if ( gamepad.pose === null ) return;
  12983. // Pose
  12984. var pose = gamepad.pose;
  12985. if ( pose.hasPosition === false ) controller.position.set( 0.2, - 0.6, - 0.05 );
  12986. if ( pose.position !== null ) controller.position.fromArray( pose.position );
  12987. if ( pose.orientation !== null ) controller.quaternion.fromArray( pose.orientation );
  12988. controller.matrix.compose( controller.position, controller.quaternion, controller.scale );
  12989. controller.matrix.premultiply( standingMatrix );
  12990. controller.matrix.decompose( controller.position, controller.quaternion, controller.scale );
  12991. controller.matrixWorldNeedsUpdate = true;
  12992. controller.visible = true;
  12993. // Trigger
  12994. var buttonId = gamepad.id === 'Daydream Controller' ? 0 : 1;
  12995. if ( triggers[ i ] !== gamepad.buttons[ buttonId ].pressed ) {
  12996. triggers[ i ] = gamepad.buttons[ buttonId ].pressed;
  12997. if ( triggers[ i ] === true ) {
  12998. controller.dispatchEvent( { type: 'selectstart' } );
  12999. } else {
  13000. controller.dispatchEvent( { type: 'selectend' } );
  13001. controller.dispatchEvent( { type: 'select' } );
  13002. }
  13003. }
  13004. } else {
  13005. controller.visible = false;
  13006. }
  13007. }
  13008. }
  13009. //
  13010. this.enabled = false;
  13011. this.getController = function ( id ) {
  13012. var controller = controllers[ id ];
  13013. if ( controller === undefined ) {
  13014. controller = new Group();
  13015. controller.matrixAutoUpdate = false;
  13016. controller.visible = false;
  13017. controllers[ id ] = controller;
  13018. }
  13019. return controller;
  13020. };
  13021. this.getDevice = function () {
  13022. return device;
  13023. };
  13024. this.setDevice = function ( value ) {
  13025. if ( value !== undefined ) device = value;
  13026. animation.setContext( value );
  13027. };
  13028. this.setFramebufferScaleFactor = function ( value ) {
  13029. framebufferScaleFactor = value;
  13030. };
  13031. this.setFrameOfReferenceType = function ( value ) {
  13032. frameOfReferenceType = value;
  13033. };
  13034. this.setPoseTarget = function ( object ) {
  13035. if ( object !== undefined ) poseTarget = object;
  13036. };
  13037. this.getCamera = function ( camera ) {
  13038. var userHeight = frameOfReferenceType === 'stage' ? 1.6 : 0;
  13039. if ( device === null ) {
  13040. camera.position.set( 0, userHeight, 0 );
  13041. return camera;
  13042. }
  13043. device.depthNear = camera.near;
  13044. device.depthFar = camera.far;
  13045. device.getFrameData( frameData );
  13046. //
  13047. if ( frameOfReferenceType === 'stage' ) {
  13048. var stageParameters = device.stageParameters;
  13049. if ( stageParameters ) {
  13050. standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
  13051. } else {
  13052. standingMatrix.makeTranslation( 0, userHeight, 0 );
  13053. }
  13054. }
  13055. var pose = frameData.pose;
  13056. var poseObject = poseTarget !== null ? poseTarget : camera;
  13057. // We want to manipulate poseObject by its position and quaternion components since users may rely on them.
  13058. poseObject.matrix.copy( standingMatrix );
  13059. poseObject.matrix.decompose( poseObject.position, poseObject.quaternion, poseObject.scale );
  13060. if ( pose.orientation !== null ) {
  13061. tempQuaternion.fromArray( pose.orientation );
  13062. poseObject.quaternion.multiply( tempQuaternion );
  13063. }
  13064. if ( pose.position !== null ) {
  13065. tempQuaternion.setFromRotationMatrix( standingMatrix );
  13066. tempPosition.fromArray( pose.position );
  13067. tempPosition.applyQuaternion( tempQuaternion );
  13068. poseObject.position.add( tempPosition );
  13069. }
  13070. poseObject.updateMatrixWorld();
  13071. if ( device.isPresenting === false ) return camera;
  13072. //
  13073. cameraL.near = camera.near;
  13074. cameraR.near = camera.near;
  13075. cameraL.far = camera.far;
  13076. cameraR.far = camera.far;
  13077. cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
  13078. cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
  13079. // TODO (mrdoob) Double check this code
  13080. standingMatrixInverse.getInverse( standingMatrix );
  13081. if ( frameOfReferenceType === 'stage' ) {
  13082. cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
  13083. cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
  13084. }
  13085. var parent = poseObject.parent;
  13086. if ( parent !== null ) {
  13087. matrixWorldInverse.getInverse( parent.matrixWorld );
  13088. cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
  13089. cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
  13090. }
  13091. // envMap and Mirror needs camera.matrixWorld
  13092. cameraL.matrixWorld.getInverse( cameraL.matrixWorldInverse );
  13093. cameraR.matrixWorld.getInverse( cameraR.matrixWorldInverse );
  13094. cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
  13095. cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
  13096. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13097. //
  13098. var layers = device.getLayers();
  13099. if ( layers.length ) {
  13100. var layer = layers[ 0 ];
  13101. if ( layer.leftBounds !== null && layer.leftBounds.length === 4 ) {
  13102. cameraL.bounds.fromArray( layer.leftBounds );
  13103. }
  13104. if ( layer.rightBounds !== null && layer.rightBounds.length === 4 ) {
  13105. cameraR.bounds.fromArray( layer.rightBounds );
  13106. }
  13107. }
  13108. updateControllers();
  13109. return cameraVR;
  13110. };
  13111. this.getStandingMatrix = function () {
  13112. return standingMatrix;
  13113. };
  13114. this.isPresenting = isPresenting;
  13115. // Animation Loop
  13116. var animation = new WebGLAnimation();
  13117. this.setAnimationLoop = function ( callback ) {
  13118. animation.setAnimationLoop( callback );
  13119. };
  13120. this.submitFrame = function () {
  13121. if ( isPresenting() ) device.submitFrame();
  13122. };
  13123. this.dispose = function () {
  13124. if ( typeof window !== 'undefined' ) {
  13125. window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
  13126. }
  13127. };
  13128. }
  13129. /**
  13130. * @author mrdoob / http://mrdoob.com/
  13131. */
  13132. function WebXRManager( renderer ) {
  13133. var gl = renderer.context;
  13134. var device = null;
  13135. var session = null;
  13136. var framebufferScaleFactor = 1.0;
  13137. var frameOfReference = null;
  13138. var frameOfReferenceType = 'stage';
  13139. var pose = null;
  13140. var controllers = [];
  13141. var inputSources = [];
  13142. function isPresenting() {
  13143. return session !== null && frameOfReference !== null;
  13144. }
  13145. //
  13146. var cameraL = new PerspectiveCamera();
  13147. cameraL.layers.enable( 1 );
  13148. cameraL.viewport = new Vector4();
  13149. var cameraR = new PerspectiveCamera();
  13150. cameraR.layers.enable( 2 );
  13151. cameraR.viewport = new Vector4();
  13152. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  13153. cameraVR.layers.enable( 1 );
  13154. cameraVR.layers.enable( 2 );
  13155. //
  13156. this.enabled = false;
  13157. this.getController = function ( id ) {
  13158. var controller = controllers[ id ];
  13159. if ( controller === undefined ) {
  13160. controller = new Group();
  13161. controller.matrixAutoUpdate = false;
  13162. controller.visible = false;
  13163. controllers[ id ] = controller;
  13164. }
  13165. return controller;
  13166. };
  13167. this.getDevice = function () {
  13168. return device;
  13169. };
  13170. this.setDevice = function ( value ) {
  13171. if ( value !== undefined ) device = value;
  13172. if ( value instanceof XRDevice ) gl.setCompatibleXRDevice( value );
  13173. };
  13174. //
  13175. function onSessionEvent( event ) {
  13176. var controller = controllers[ inputSources.indexOf( event.inputSource ) ];
  13177. if ( controller ) controller.dispatchEvent( { type: event.type } );
  13178. }
  13179. function onSessionEnd() {
  13180. renderer.setFramebuffer( null );
  13181. animation.stop();
  13182. }
  13183. this.setFramebufferScaleFactor = function ( value ) {
  13184. framebufferScaleFactor = value;
  13185. };
  13186. this.setFrameOfReferenceType = function ( value ) {
  13187. frameOfReferenceType = value;
  13188. };
  13189. this.setSession = function ( value ) {
  13190. session = value;
  13191. if ( session !== null ) {
  13192. session.addEventListener( 'select', onSessionEvent );
  13193. session.addEventListener( 'selectstart', onSessionEvent );
  13194. session.addEventListener( 'selectend', onSessionEvent );
  13195. session.addEventListener( 'end', onSessionEnd );
  13196. session.baseLayer = new XRWebGLLayer( session, gl, { framebufferScaleFactor: framebufferScaleFactor } );
  13197. session.requestFrameOfReference( frameOfReferenceType ).then( function ( value ) {
  13198. frameOfReference = value;
  13199. renderer.setFramebuffer( session.baseLayer.framebuffer );
  13200. animation.setContext( session );
  13201. animation.start();
  13202. } );
  13203. //
  13204. inputSources = session.getInputSources();
  13205. session.addEventListener( 'inputsourceschange', function () {
  13206. inputSources = session.getInputSources();
  13207. console.log( inputSources );
  13208. for ( var i = 0; i < controllers.length; i ++ ) {
  13209. var controller = controllers[ i ];
  13210. controller.userData.inputSource = inputSources[ i ];
  13211. }
  13212. } );
  13213. }
  13214. };
  13215. function updateCamera( camera, parent ) {
  13216. if ( parent === null ) {
  13217. camera.matrixWorld.copy( camera.matrix );
  13218. } else {
  13219. camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );
  13220. }
  13221. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13222. }
  13223. this.getCamera = function ( camera ) {
  13224. if ( isPresenting() ) {
  13225. var parent = camera.parent;
  13226. var cameras = cameraVR.cameras;
  13227. updateCamera( cameraVR, parent );
  13228. for ( var i = 0; i < cameras.length; i ++ ) {
  13229. updateCamera( cameras[ i ], parent );
  13230. }
  13231. // update camera and its children
  13232. camera.matrixWorld.copy( cameraVR.matrixWorld );
  13233. var children = camera.children;
  13234. for ( var i = 0, l = children.length; i < l; i ++ ) {
  13235. children[ i ].updateMatrixWorld( true );
  13236. }
  13237. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13238. return cameraVR;
  13239. }
  13240. return camera;
  13241. };
  13242. this.isPresenting = isPresenting;
  13243. // Animation Loop
  13244. var onAnimationFrameCallback = null;
  13245. function onAnimationFrame( time, frame ) {
  13246. pose = frame.getDevicePose( frameOfReference );
  13247. if ( pose !== null ) {
  13248. var layer = session.baseLayer;
  13249. var views = frame.views;
  13250. for ( var i = 0; i < views.length; i ++ ) {
  13251. var view = views[ i ];
  13252. var viewport = layer.getViewport( view );
  13253. var viewMatrix = pose.getViewMatrix( view );
  13254. var camera = cameraVR.cameras[ i ];
  13255. camera.matrix.fromArray( viewMatrix ).getInverse( camera.matrix );
  13256. camera.projectionMatrix.fromArray( view.projectionMatrix );
  13257. camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
  13258. if ( i === 0 ) {
  13259. cameraVR.matrix.copy( camera.matrix );
  13260. }
  13261. }
  13262. }
  13263. //
  13264. for ( var i = 0; i < controllers.length; i ++ ) {
  13265. var controller = controllers[ i ];
  13266. var inputSource = inputSources[ i ];
  13267. if ( inputSource ) {
  13268. var inputPose = frame.getInputPose( inputSource, frameOfReference );
  13269. if ( inputPose !== null ) {
  13270. if ( 'targetRay' in inputPose ) {
  13271. controller.matrix.elements = inputPose.targetRay.transformMatrix;
  13272. } else if ( 'pointerMatrix' in inputPose ) {
  13273. // DEPRECATED
  13274. controller.matrix.elements = inputPose.pointerMatrix;
  13275. }
  13276. controller.matrix.decompose( controller.position, controller.rotation, controller.scale );
  13277. controller.visible = true;
  13278. continue;
  13279. }
  13280. }
  13281. controller.visible = false;
  13282. }
  13283. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  13284. }
  13285. var animation = new WebGLAnimation();
  13286. animation.setAnimationLoop( onAnimationFrame );
  13287. this.setAnimationLoop = function ( callback ) {
  13288. onAnimationFrameCallback = callback;
  13289. };
  13290. this.dispose = function () {};
  13291. // DEPRECATED
  13292. this.getStandingMatrix = function () {
  13293. console.warn( 'THREE.WebXRManager: getStandingMatrix() is no longer needed.' );
  13294. return new THREE.Matrix4();
  13295. };
  13296. this.submitFrame = function () {};
  13297. }
  13298. /**
  13299. * @author supereggbert / http://www.paulbrunt.co.uk/
  13300. * @author mrdoob / http://mrdoob.com/
  13301. * @author alteredq / http://alteredqualia.com/
  13302. * @author szimek / https://github.com/szimek/
  13303. * @author tschw
  13304. */
  13305. function WebGLRenderer( parameters ) {
  13306. console.log( 'THREE.WebGLRenderer', REVISION );
  13307. parameters = parameters || {};
  13308. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  13309. _context = parameters.context !== undefined ? parameters.context : null,
  13310. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  13311. _depth = parameters.depth !== undefined ? parameters.depth : true,
  13312. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  13313. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  13314. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  13315. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  13316. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default';
  13317. var currentRenderList = null;
  13318. var currentRenderState = null;
  13319. // public properties
  13320. this.domElement = _canvas;
  13321. this.context = null;
  13322. // clearing
  13323. this.autoClear = true;
  13324. this.autoClearColor = true;
  13325. this.autoClearDepth = true;
  13326. this.autoClearStencil = true;
  13327. // scene graph
  13328. this.sortObjects = true;
  13329. // user-defined clipping
  13330. this.clippingPlanes = [];
  13331. this.localClippingEnabled = false;
  13332. // physically based shading
  13333. this.gammaFactor = 2.0; // for backwards compatibility
  13334. this.gammaInput = false;
  13335. this.gammaOutput = false;
  13336. // physical lights
  13337. this.physicallyCorrectLights = false;
  13338. // tone mapping
  13339. this.toneMapping = LinearToneMapping;
  13340. this.toneMappingExposure = 1.0;
  13341. this.toneMappingWhitePoint = 1.0;
  13342. // morphs
  13343. this.maxMorphTargets = 8;
  13344. this.maxMorphNormals = 4;
  13345. // internal properties
  13346. var _this = this,
  13347. _isContextLost = false,
  13348. // internal state cache
  13349. _framebuffer = null,
  13350. _currentRenderTarget = null,
  13351. _currentFramebuffer = null,
  13352. _currentMaterialId = - 1,
  13353. // geometry and program caching
  13354. _currentGeometryProgram = {
  13355. geometry: null,
  13356. program: null,
  13357. wireframe: false
  13358. },
  13359. _currentCamera = null,
  13360. _currentArrayCamera = null,
  13361. _currentViewport = new Vector4(),
  13362. _currentScissor = new Vector4(),
  13363. _currentScissorTest = null,
  13364. //
  13365. _usedTextureUnits = 0,
  13366. //
  13367. _width = _canvas.width,
  13368. _height = _canvas.height,
  13369. _pixelRatio = 1,
  13370. _viewport = new Vector4( 0, 0, _width, _height ),
  13371. _scissor = new Vector4( 0, 0, _width, _height ),
  13372. _scissorTest = false,
  13373. // frustum
  13374. _frustum = new Frustum(),
  13375. // clipping
  13376. _clipping = new WebGLClipping(),
  13377. _clippingEnabled = false,
  13378. _localClippingEnabled = false,
  13379. // camera matrices cache
  13380. _projScreenMatrix = new Matrix4(),
  13381. _vector3 = new Vector3();
  13382. function getTargetPixelRatio() {
  13383. return _currentRenderTarget === null ? _pixelRatio : 1;
  13384. }
  13385. // initialize
  13386. var _gl;
  13387. try {
  13388. var contextAttributes = {
  13389. alpha: _alpha,
  13390. depth: _depth,
  13391. stencil: _stencil,
  13392. antialias: _antialias,
  13393. premultipliedAlpha: _premultipliedAlpha,
  13394. preserveDrawingBuffer: _preserveDrawingBuffer,
  13395. powerPreference: _powerPreference
  13396. };
  13397. // event listeners must be registered before WebGL context is created, see #12753
  13398. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  13399. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  13400. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  13401. if ( _gl === null ) {
  13402. if ( _canvas.getContext( 'webgl' ) !== null ) {
  13403. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  13404. } else {
  13405. throw new Error( 'Error creating WebGL context.' );
  13406. }
  13407. }
  13408. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  13409. if ( _gl.getShaderPrecisionFormat === undefined ) {
  13410. _gl.getShaderPrecisionFormat = function () {
  13411. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  13412. };
  13413. }
  13414. } catch ( error ) {
  13415. console.error( 'THREE.WebGLRenderer: ' + error.message );
  13416. }
  13417. var extensions, capabilities, state, info;
  13418. var properties, textures, attributes, geometries, objects;
  13419. var programCache, renderLists, renderStates;
  13420. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  13421. var utils;
  13422. function initGLContext() {
  13423. extensions = new WebGLExtensions( _gl );
  13424. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  13425. if ( ! capabilities.isWebGL2 ) {
  13426. extensions.get( 'WEBGL_depth_texture' );
  13427. extensions.get( 'OES_texture_float' );
  13428. extensions.get( 'OES_texture_half_float' );
  13429. extensions.get( 'OES_texture_half_float_linear' );
  13430. extensions.get( 'OES_standard_derivatives' );
  13431. extensions.get( 'OES_element_index_uint' );
  13432. extensions.get( 'ANGLE_instanced_arrays' );
  13433. }
  13434. extensions.get( 'OES_texture_float_linear' );
  13435. utils = new WebGLUtils( _gl, extensions, capabilities );
  13436. state = new WebGLState( _gl, extensions, utils, capabilities );
  13437. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  13438. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  13439. info = new WebGLInfo( _gl );
  13440. properties = new WebGLProperties();
  13441. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  13442. attributes = new WebGLAttributes( _gl );
  13443. geometries = new WebGLGeometries( _gl, attributes, info );
  13444. objects = new WebGLObjects( geometries, info );
  13445. morphtargets = new WebGLMorphtargets( _gl );
  13446. programCache = new WebGLPrograms( _this, extensions, capabilities );
  13447. renderLists = new WebGLRenderLists();
  13448. renderStates = new WebGLRenderStates();
  13449. background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
  13450. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
  13451. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
  13452. info.programs = programCache.programs;
  13453. _this.context = _gl;
  13454. _this.capabilities = capabilities;
  13455. _this.extensions = extensions;
  13456. _this.properties = properties;
  13457. _this.renderLists = renderLists;
  13458. _this.state = state;
  13459. _this.info = info;
  13460. }
  13461. initGLContext();
  13462. // vr
  13463. var vr = null;
  13464. if ( typeof navigator !== 'undefined' ) {
  13465. vr = ( 'xr' in navigator ) ? new WebXRManager( _this ) : new WebVRManager( _this );
  13466. }
  13467. this.vr = vr;
  13468. // shadow map
  13469. var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  13470. this.shadowMap = shadowMap;
  13471. // API
  13472. this.getContext = function () {
  13473. return _gl;
  13474. };
  13475. this.getContextAttributes = function () {
  13476. return _gl.getContextAttributes();
  13477. };
  13478. this.forceContextLoss = function () {
  13479. var extension = extensions.get( 'WEBGL_lose_context' );
  13480. if ( extension ) extension.loseContext();
  13481. };
  13482. this.forceContextRestore = function () {
  13483. var extension = extensions.get( 'WEBGL_lose_context' );
  13484. if ( extension ) extension.restoreContext();
  13485. };
  13486. this.getPixelRatio = function () {
  13487. return _pixelRatio;
  13488. };
  13489. this.setPixelRatio = function ( value ) {
  13490. if ( value === undefined ) return;
  13491. _pixelRatio = value;
  13492. this.setSize( _width, _height, false );
  13493. };
  13494. this.getSize = function () {
  13495. return {
  13496. width: _width,
  13497. height: _height
  13498. };
  13499. };
  13500. this.setSize = function ( width, height, updateStyle ) {
  13501. if ( vr.isPresenting() ) {
  13502. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  13503. return;
  13504. }
  13505. _width = width;
  13506. _height = height;
  13507. _canvas.width = width * _pixelRatio;
  13508. _canvas.height = height * _pixelRatio;
  13509. if ( updateStyle !== false ) {
  13510. _canvas.style.width = width + 'px';
  13511. _canvas.style.height = height + 'px';
  13512. }
  13513. this.setViewport( 0, 0, width, height );
  13514. };
  13515. this.getDrawingBufferSize = function () {
  13516. return {
  13517. width: _width * _pixelRatio,
  13518. height: _height * _pixelRatio
  13519. };
  13520. };
  13521. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  13522. _width = width;
  13523. _height = height;
  13524. _pixelRatio = pixelRatio;
  13525. _canvas.width = width * pixelRatio;
  13526. _canvas.height = height * pixelRatio;
  13527. this.setViewport( 0, 0, width, height );
  13528. };
  13529. this.getCurrentViewport = function () {
  13530. return _currentViewport;
  13531. };
  13532. this.setViewport = function ( x, y, width, height ) {
  13533. _viewport.set( x, _height - y - height, width, height );
  13534. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  13535. };
  13536. this.setScissor = function ( x, y, width, height ) {
  13537. _scissor.set( x, _height - y - height, width, height );
  13538. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  13539. };
  13540. this.setScissorTest = function ( boolean ) {
  13541. state.setScissorTest( _scissorTest = boolean );
  13542. };
  13543. // Clearing
  13544. this.getClearColor = function () {
  13545. return background.getClearColor();
  13546. };
  13547. this.setClearColor = function () {
  13548. background.setClearColor.apply( background, arguments );
  13549. };
  13550. this.getClearAlpha = function () {
  13551. return background.getClearAlpha();
  13552. };
  13553. this.setClearAlpha = function () {
  13554. background.setClearAlpha.apply( background, arguments );
  13555. };
  13556. this.clear = function ( color, depth, stencil ) {
  13557. var bits = 0;
  13558. if ( color === undefined || color ) bits |= 16384;
  13559. if ( depth === undefined || depth ) bits |= 256;
  13560. if ( stencil === undefined || stencil ) bits |= 1024;
  13561. _gl.clear( bits );
  13562. };
  13563. this.clearColor = function () {
  13564. this.clear( true, false, false );
  13565. };
  13566. this.clearDepth = function () {
  13567. this.clear( false, true, false );
  13568. };
  13569. this.clearStencil = function () {
  13570. this.clear( false, false, true );
  13571. };
  13572. //
  13573. this.dispose = function () {
  13574. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  13575. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  13576. renderLists.dispose();
  13577. renderStates.dispose();
  13578. properties.dispose();
  13579. objects.dispose();
  13580. vr.dispose();
  13581. animation.stop();
  13582. };
  13583. // Events
  13584. function onContextLost( event ) {
  13585. event.preventDefault();
  13586. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  13587. _isContextLost = true;
  13588. }
  13589. function onContextRestore( /* event */ ) {
  13590. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  13591. _isContextLost = false;
  13592. initGLContext();
  13593. }
  13594. function onMaterialDispose( event ) {
  13595. var material = event.target;
  13596. material.removeEventListener( 'dispose', onMaterialDispose );
  13597. deallocateMaterial( material );
  13598. }
  13599. // Buffer deallocation
  13600. function deallocateMaterial( material ) {
  13601. releaseMaterialProgramReference( material );
  13602. properties.remove( material );
  13603. }
  13604. function releaseMaterialProgramReference( material ) {
  13605. var programInfo = properties.get( material ).program;
  13606. material.program = undefined;
  13607. if ( programInfo !== undefined ) {
  13608. programCache.releaseProgram( programInfo );
  13609. }
  13610. }
  13611. // Buffer rendering
  13612. function renderObjectImmediate( object, program ) {
  13613. object.render( function ( object ) {
  13614. _this.renderBufferImmediate( object, program );
  13615. } );
  13616. }
  13617. this.renderBufferImmediate = function ( object, program ) {
  13618. state.initAttributes();
  13619. var buffers = properties.get( object );
  13620. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  13621. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  13622. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  13623. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  13624. var programAttributes = program.getAttributes();
  13625. if ( object.hasPositions ) {
  13626. _gl.bindBuffer( 34962, buffers.position );
  13627. _gl.bufferData( 34962, object.positionArray, 35048 );
  13628. state.enableAttribute( programAttributes.position );
  13629. _gl.vertexAttribPointer( programAttributes.position, 3, 5126, false, 0, 0 );
  13630. }
  13631. if ( object.hasNormals ) {
  13632. _gl.bindBuffer( 34962, buffers.normal );
  13633. _gl.bufferData( 34962, object.normalArray, 35048 );
  13634. state.enableAttribute( programAttributes.normal );
  13635. _gl.vertexAttribPointer( programAttributes.normal, 3, 5126, false, 0, 0 );
  13636. }
  13637. if ( object.hasUvs ) {
  13638. _gl.bindBuffer( 34962, buffers.uv );
  13639. _gl.bufferData( 34962, object.uvArray, 35048 );
  13640. state.enableAttribute( programAttributes.uv );
  13641. _gl.vertexAttribPointer( programAttributes.uv, 2, 5126, false, 0, 0 );
  13642. }
  13643. if ( object.hasColors ) {
  13644. _gl.bindBuffer( 34962, buffers.color );
  13645. _gl.bufferData( 34962, object.colorArray, 35048 );
  13646. state.enableAttribute( programAttributes.color );
  13647. _gl.vertexAttribPointer( programAttributes.color, 3, 5126, false, 0, 0 );
  13648. }
  13649. state.disableUnusedAttributes();
  13650. _gl.drawArrays( 4, 0, object.count );
  13651. object.count = 0;
  13652. };
  13653. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  13654. var frontFaceCW = ( object.isMesh && object.normalMatrix.determinant() < 0 );
  13655. state.setMaterial( material, frontFaceCW );
  13656. var program = setProgram( camera, fog, material, object );
  13657. var updateBuffers = false;
  13658. if ( _currentGeometryProgram.geometry !== geometry.id ||
  13659. _currentGeometryProgram.program !== program.id ||
  13660. _currentGeometryProgram.wireframe !== ( material.wireframe === true ) ) {
  13661. _currentGeometryProgram.geometry = geometry.id;
  13662. _currentGeometryProgram.program = program.id;
  13663. _currentGeometryProgram.wireframe = material.wireframe === true;
  13664. updateBuffers = true;
  13665. }
  13666. if ( object.morphTargetInfluences ) {
  13667. morphtargets.update( object, geometry, material, program );
  13668. updateBuffers = true;
  13669. }
  13670. //
  13671. var index = geometry.index;
  13672. var position = geometry.attributes.position;
  13673. var rangeFactor = 1;
  13674. if ( material.wireframe === true ) {
  13675. index = geometries.getWireframeAttribute( geometry );
  13676. rangeFactor = 2;
  13677. }
  13678. var attribute;
  13679. var renderer = bufferRenderer;
  13680. if ( index !== null ) {
  13681. attribute = attributes.get( index );
  13682. renderer = indexedBufferRenderer;
  13683. renderer.setIndex( attribute );
  13684. }
  13685. if ( updateBuffers ) {
  13686. setupVertexAttributes( material, program, geometry );
  13687. if ( index !== null ) {
  13688. _gl.bindBuffer( 34963, attribute.buffer );
  13689. }
  13690. }
  13691. //
  13692. var dataCount = Infinity;
  13693. if ( index !== null ) {
  13694. dataCount = index.count;
  13695. } else if ( position !== undefined ) {
  13696. dataCount = position.count;
  13697. }
  13698. var rangeStart = geometry.drawRange.start * rangeFactor;
  13699. var rangeCount = geometry.drawRange.count * rangeFactor;
  13700. var groupStart = group !== null ? group.start * rangeFactor : 0;
  13701. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  13702. var drawStart = Math.max( rangeStart, groupStart );
  13703. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  13704. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  13705. if ( drawCount === 0 ) return;
  13706. //
  13707. if ( object.isMesh ) {
  13708. if ( material.wireframe === true ) {
  13709. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  13710. renderer.setMode( 1 );
  13711. } else {
  13712. switch ( object.drawMode ) {
  13713. case TrianglesDrawMode:
  13714. renderer.setMode( 4 );
  13715. break;
  13716. case TriangleStripDrawMode:
  13717. renderer.setMode( 5 );
  13718. break;
  13719. case TriangleFanDrawMode:
  13720. renderer.setMode( 6 );
  13721. break;
  13722. }
  13723. }
  13724. } else if ( object.isLine ) {
  13725. var lineWidth = material.linewidth;
  13726. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  13727. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  13728. if ( object.isLineSegments ) {
  13729. renderer.setMode( 1 );
  13730. } else if ( object.isLineLoop ) {
  13731. renderer.setMode( 2 );
  13732. } else {
  13733. renderer.setMode( 3 );
  13734. }
  13735. } else if ( object.isPoints ) {
  13736. renderer.setMode( 0 );
  13737. } else if ( object.isSprite ) {
  13738. renderer.setMode( 4 );
  13739. }
  13740. if ( geometry && geometry.isInstancedBufferGeometry ) {
  13741. if ( geometry.maxInstancedCount > 0 ) {
  13742. renderer.renderInstances( geometry, drawStart, drawCount );
  13743. }
  13744. } else {
  13745. renderer.render( drawStart, drawCount );
  13746. }
  13747. };
  13748. function setupVertexAttributes( material, program, geometry ) {
  13749. if ( geometry && geometry.isInstancedBufferGeometry & ! capabilities.isWebGL2 ) {
  13750. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
  13751. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  13752. return;
  13753. }
  13754. }
  13755. state.initAttributes();
  13756. var geometryAttributes = geometry.attributes;
  13757. var programAttributes = program.getAttributes();
  13758. var materialDefaultAttributeValues = material.defaultAttributeValues;
  13759. for ( var name in programAttributes ) {
  13760. var programAttribute = programAttributes[ name ];
  13761. if ( programAttribute >= 0 ) {
  13762. var geometryAttribute = geometryAttributes[ name ];
  13763. if ( geometryAttribute !== undefined ) {
  13764. var normalized = geometryAttribute.normalized;
  13765. var size = geometryAttribute.itemSize;
  13766. var attribute = attributes.get( geometryAttribute );
  13767. // TODO Attribute may not be available on context restore
  13768. if ( attribute === undefined ) continue;
  13769. var buffer = attribute.buffer;
  13770. var type = attribute.type;
  13771. var bytesPerElement = attribute.bytesPerElement;
  13772. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  13773. var data = geometryAttribute.data;
  13774. var stride = data.stride;
  13775. var offset = geometryAttribute.offset;
  13776. if ( data && data.isInstancedInterleavedBuffer ) {
  13777. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  13778. if ( geometry.maxInstancedCount === undefined ) {
  13779. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  13780. }
  13781. } else {
  13782. state.enableAttribute( programAttribute );
  13783. }
  13784. _gl.bindBuffer( 34962, buffer );
  13785. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
  13786. } else {
  13787. if ( geometryAttribute.isInstancedBufferAttribute ) {
  13788. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  13789. if ( geometry.maxInstancedCount === undefined ) {
  13790. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  13791. }
  13792. } else {
  13793. state.enableAttribute( programAttribute );
  13794. }
  13795. _gl.bindBuffer( 34962, buffer );
  13796. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
  13797. }
  13798. } else if ( materialDefaultAttributeValues !== undefined ) {
  13799. var value = materialDefaultAttributeValues[ name ];
  13800. if ( value !== undefined ) {
  13801. switch ( value.length ) {
  13802. case 2:
  13803. _gl.vertexAttrib2fv( programAttribute, value );
  13804. break;
  13805. case 3:
  13806. _gl.vertexAttrib3fv( programAttribute, value );
  13807. break;
  13808. case 4:
  13809. _gl.vertexAttrib4fv( programAttribute, value );
  13810. break;
  13811. default:
  13812. _gl.vertexAttrib1fv( programAttribute, value );
  13813. }
  13814. }
  13815. }
  13816. }
  13817. }
  13818. state.disableUnusedAttributes();
  13819. }
  13820. // Compile
  13821. this.compile = function ( scene, camera ) {
  13822. currentRenderState = renderStates.get( scene, camera );
  13823. currentRenderState.init();
  13824. scene.traverse( function ( object ) {
  13825. if ( object.isLight ) {
  13826. currentRenderState.pushLight( object );
  13827. if ( object.castShadow ) {
  13828. currentRenderState.pushShadow( object );
  13829. }
  13830. }
  13831. } );
  13832. currentRenderState.setupLights( camera );
  13833. scene.traverse( function ( object ) {
  13834. if ( object.material ) {
  13835. if ( Array.isArray( object.material ) ) {
  13836. for ( var i = 0; i < object.material.length; i ++ ) {
  13837. initMaterial( object.material[ i ], scene.fog, object );
  13838. }
  13839. } else {
  13840. initMaterial( object.material, scene.fog, object );
  13841. }
  13842. }
  13843. } );
  13844. };
  13845. // Animation Loop
  13846. var onAnimationFrameCallback = null;
  13847. function onAnimationFrame( time ) {
  13848. if ( vr.isPresenting() ) return;
  13849. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  13850. }
  13851. var animation = new WebGLAnimation();
  13852. animation.setAnimationLoop( onAnimationFrame );
  13853. if ( typeof window !== 'undefined' ) animation.setContext( window );
  13854. this.setAnimationLoop = function ( callback ) {
  13855. onAnimationFrameCallback = callback;
  13856. vr.setAnimationLoop( callback );
  13857. animation.start();
  13858. };
  13859. // Rendering
  13860. this.render = function ( scene, camera, renderTarget, forceClear ) {
  13861. if ( ! ( camera && camera.isCamera ) ) {
  13862. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  13863. return;
  13864. }
  13865. if ( _isContextLost ) return;
  13866. // reset caching for this frame
  13867. _currentGeometryProgram.geometry = null;
  13868. _currentGeometryProgram.program = null;
  13869. _currentGeometryProgram.wireframe = false;
  13870. _currentMaterialId = - 1;
  13871. _currentCamera = null;
  13872. // update scene graph
  13873. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  13874. // update camera matrices and frustum
  13875. if ( camera.parent === null ) camera.updateMatrixWorld();
  13876. if ( vr.enabled ) {
  13877. camera = vr.getCamera( camera );
  13878. }
  13879. //
  13880. currentRenderState = renderStates.get( scene, camera );
  13881. currentRenderState.init();
  13882. scene.onBeforeRender( _this, scene, camera, renderTarget );
  13883. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  13884. _frustum.setFromMatrix( _projScreenMatrix );
  13885. _localClippingEnabled = this.localClippingEnabled;
  13886. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  13887. currentRenderList = renderLists.get( scene, camera );
  13888. currentRenderList.init();
  13889. projectObject( scene, camera, 0, _this.sortObjects );
  13890. if ( _this.sortObjects === true ) {
  13891. currentRenderList.sort();
  13892. }
  13893. //
  13894. if ( _clippingEnabled ) _clipping.beginShadows();
  13895. var shadowsArray = currentRenderState.state.shadowsArray;
  13896. shadowMap.render( shadowsArray, scene, camera );
  13897. currentRenderState.setupLights( camera );
  13898. if ( _clippingEnabled ) _clipping.endShadows();
  13899. //
  13900. if ( this.info.autoReset ) this.info.reset();
  13901. if ( renderTarget === undefined ) {
  13902. renderTarget = null;
  13903. }
  13904. this.setRenderTarget( renderTarget );
  13905. //
  13906. background.render( currentRenderList, scene, camera, forceClear );
  13907. // render scene
  13908. var opaqueObjects = currentRenderList.opaque;
  13909. var transparentObjects = currentRenderList.transparent;
  13910. if ( scene.overrideMaterial ) {
  13911. var overrideMaterial = scene.overrideMaterial;
  13912. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  13913. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  13914. } else {
  13915. // opaque pass (front-to-back order)
  13916. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  13917. // transparent pass (back-to-front order)
  13918. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  13919. }
  13920. //
  13921. if ( renderTarget ) {
  13922. // Generate mipmap if we're using any kind of mipmap filtering
  13923. textures.updateRenderTargetMipmap( renderTarget );
  13924. // resolve multisample renderbuffers to a single-sample texture if necessary
  13925. textures.updateMultisampleRenderTarget( renderTarget );
  13926. }
  13927. // Ensure depth buffer writing is enabled so it can be cleared on next render
  13928. state.buffers.depth.setTest( true );
  13929. state.buffers.depth.setMask( true );
  13930. state.buffers.color.setMask( true );
  13931. state.setPolygonOffset( false );
  13932. scene.onAfterRender( _this, scene, camera );
  13933. if ( vr.enabled ) {
  13934. vr.submitFrame();
  13935. }
  13936. // _gl.finish();
  13937. currentRenderList = null;
  13938. currentRenderState = null;
  13939. };
  13940. function projectObject( object, camera, groupOrder, sortObjects ) {
  13941. if ( object.visible === false ) return;
  13942. var visible = object.layers.test( camera.layers );
  13943. if ( visible ) {
  13944. if ( object.isGroup ) {
  13945. groupOrder = object.renderOrder;
  13946. } else if ( object.isLight ) {
  13947. currentRenderState.pushLight( object );
  13948. if ( object.castShadow ) {
  13949. currentRenderState.pushShadow( object );
  13950. }
  13951. } else if ( object.isSprite ) {
  13952. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  13953. if ( sortObjects ) {
  13954. _vector3.setFromMatrixPosition( object.matrixWorld )
  13955. .applyMatrix4( _projScreenMatrix );
  13956. }
  13957. var geometry = objects.update( object );
  13958. var material = object.material;
  13959. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  13960. }
  13961. } else if ( object.isImmediateRenderObject ) {
  13962. if ( sortObjects ) {
  13963. _vector3.setFromMatrixPosition( object.matrixWorld )
  13964. .applyMatrix4( _projScreenMatrix );
  13965. }
  13966. currentRenderList.push( object, null, object.material, groupOrder, _vector3.z, null );
  13967. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  13968. if ( object.isSkinnedMesh ) {
  13969. object.skeleton.update();
  13970. }
  13971. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  13972. if ( sortObjects ) {
  13973. _vector3.setFromMatrixPosition( object.matrixWorld )
  13974. .applyMatrix4( _projScreenMatrix );
  13975. }
  13976. var geometry = objects.update( object );
  13977. var material = object.material;
  13978. if ( Array.isArray( material ) ) {
  13979. var groups = geometry.groups;
  13980. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  13981. var group = groups[ i ];
  13982. var groupMaterial = material[ group.materialIndex ];
  13983. if ( groupMaterial && groupMaterial.visible ) {
  13984. currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
  13985. }
  13986. }
  13987. } else if ( material.visible ) {
  13988. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  13989. }
  13990. }
  13991. }
  13992. }
  13993. var children = object.children;
  13994. for ( var i = 0, l = children.length; i < l; i ++ ) {
  13995. projectObject( children[ i ], camera, groupOrder, sortObjects );
  13996. }
  13997. }
  13998. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  13999. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  14000. var renderItem = renderList[ i ];
  14001. var object = renderItem.object;
  14002. var geometry = renderItem.geometry;
  14003. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  14004. var group = renderItem.group;
  14005. if ( camera.isArrayCamera ) {
  14006. _currentArrayCamera = camera;
  14007. var cameras = camera.cameras;
  14008. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  14009. var camera2 = cameras[ j ];
  14010. if ( object.layers.test( camera2.layers ) ) {
  14011. if ( 'viewport' in camera2 ) { // XR
  14012. state.viewport( _currentViewport.copy( camera2.viewport ) );
  14013. } else {
  14014. var bounds = camera2.bounds;
  14015. var x = bounds.x * _width;
  14016. var y = bounds.y * _height;
  14017. var width = bounds.z * _width;
  14018. var height = bounds.w * _height;
  14019. state.viewport( _currentViewport.set( x, y, width, height ).multiplyScalar( _pixelRatio ) );
  14020. }
  14021. currentRenderState.setupLights( camera2 );
  14022. renderObject( object, scene, camera2, geometry, material, group );
  14023. }
  14024. }
  14025. } else {
  14026. _currentArrayCamera = null;
  14027. renderObject( object, scene, camera, geometry, material, group );
  14028. }
  14029. }
  14030. }
  14031. function renderObject( object, scene, camera, geometry, material, group ) {
  14032. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  14033. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14034. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  14035. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  14036. if ( object.isImmediateRenderObject ) {
  14037. state.setMaterial( material );
  14038. var program = setProgram( camera, scene.fog, material, object );
  14039. _currentGeometryProgram.geometry = null;
  14040. _currentGeometryProgram.program = null;
  14041. _currentGeometryProgram.wireframe = false;
  14042. renderObjectImmediate( object, program );
  14043. } else {
  14044. _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
  14045. }
  14046. object.onAfterRender( _this, scene, camera, geometry, material, group );
  14047. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14048. }
  14049. function initMaterial( material, fog, object ) {
  14050. var materialProperties = properties.get( material );
  14051. var lights = currentRenderState.state.lights;
  14052. var shadowsArray = currentRenderState.state.shadowsArray;
  14053. var lightsHash = materialProperties.lightsHash;
  14054. var lightsStateHash = lights.state.hash;
  14055. var parameters = programCache.getParameters(
  14056. material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );
  14057. var code = programCache.getProgramCode( material, parameters );
  14058. var program = materialProperties.program;
  14059. var programChange = true;
  14060. if ( program === undefined ) {
  14061. // new material
  14062. material.addEventListener( 'dispose', onMaterialDispose );
  14063. } else if ( program.code !== code ) {
  14064. // changed glsl or parameters
  14065. releaseMaterialProgramReference( material );
  14066. } else if ( lightsHash.stateID !== lightsStateHash.stateID ||
  14067. lightsHash.directionalLength !== lightsStateHash.directionalLength ||
  14068. lightsHash.pointLength !== lightsStateHash.pointLength ||
  14069. lightsHash.spotLength !== lightsStateHash.spotLength ||
  14070. lightsHash.rectAreaLength !== lightsStateHash.rectAreaLength ||
  14071. lightsHash.hemiLength !== lightsStateHash.hemiLength ||
  14072. lightsHash.shadowsLength !== lightsStateHash.shadowsLength ) {
  14073. lightsHash.stateID = lightsStateHash.stateID;
  14074. lightsHash.directionalLength = lightsStateHash.directionalLength;
  14075. lightsHash.pointLength = lightsStateHash.pointLength;
  14076. lightsHash.spotLength = lightsStateHash.spotLength;
  14077. lightsHash.rectAreaLength = lightsStateHash.rectAreaLength;
  14078. lightsHash.hemiLength = lightsStateHash.hemiLength;
  14079. lightsHash.shadowsLength = lightsStateHash.shadowsLength;
  14080. programChange = false;
  14081. } else if ( parameters.shaderID !== undefined ) {
  14082. // same glsl and uniform list
  14083. return;
  14084. } else {
  14085. // only rebuild uniform list
  14086. programChange = false;
  14087. }
  14088. if ( programChange ) {
  14089. if ( parameters.shaderID ) {
  14090. var shader = ShaderLib[ parameters.shaderID ];
  14091. materialProperties.shader = {
  14092. name: material.type,
  14093. uniforms: cloneUniforms( shader.uniforms ),
  14094. vertexShader: shader.vertexShader,
  14095. fragmentShader: shader.fragmentShader
  14096. };
  14097. } else {
  14098. materialProperties.shader = {
  14099. name: material.type,
  14100. uniforms: material.uniforms,
  14101. vertexShader: material.vertexShader,
  14102. fragmentShader: material.fragmentShader
  14103. };
  14104. }
  14105. material.onBeforeCompile( materialProperties.shader, _this );
  14106. // Computing code again as onBeforeCompile may have changed the shaders
  14107. code = programCache.getProgramCode( material, parameters );
  14108. program = programCache.acquireProgram( material, materialProperties.shader, parameters, code );
  14109. materialProperties.program = program;
  14110. material.program = program;
  14111. }
  14112. var programAttributes = program.getAttributes();
  14113. if ( material.morphTargets ) {
  14114. material.numSupportedMorphTargets = 0;
  14115. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  14116. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  14117. material.numSupportedMorphTargets ++;
  14118. }
  14119. }
  14120. }
  14121. if ( material.morphNormals ) {
  14122. material.numSupportedMorphNormals = 0;
  14123. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  14124. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  14125. material.numSupportedMorphNormals ++;
  14126. }
  14127. }
  14128. }
  14129. var uniforms = materialProperties.shader.uniforms;
  14130. if ( ! material.isShaderMaterial &&
  14131. ! material.isRawShaderMaterial ||
  14132. material.clipping === true ) {
  14133. materialProperties.numClippingPlanes = _clipping.numPlanes;
  14134. materialProperties.numIntersection = _clipping.numIntersection;
  14135. uniforms.clippingPlanes = _clipping.uniform;
  14136. }
  14137. materialProperties.fog = fog;
  14138. // store the light setup it was created for
  14139. if ( lightsHash === undefined ) {
  14140. materialProperties.lightsHash = lightsHash = {};
  14141. }
  14142. lightsHash.stateID = lightsStateHash.stateID;
  14143. lightsHash.directionalLength = lightsStateHash.directionalLength;
  14144. lightsHash.pointLength = lightsStateHash.pointLength;
  14145. lightsHash.spotLength = lightsStateHash.spotLength;
  14146. lightsHash.rectAreaLength = lightsStateHash.rectAreaLength;
  14147. lightsHash.hemiLength = lightsStateHash.hemiLength;
  14148. lightsHash.shadowsLength = lightsStateHash.shadowsLength;
  14149. if ( material.lights ) {
  14150. // wire up the material to this renderer's lighting state
  14151. uniforms.ambientLightColor.value = lights.state.ambient;
  14152. uniforms.directionalLights.value = lights.state.directional;
  14153. uniforms.spotLights.value = lights.state.spot;
  14154. uniforms.rectAreaLights.value = lights.state.rectArea;
  14155. uniforms.pointLights.value = lights.state.point;
  14156. uniforms.hemisphereLights.value = lights.state.hemi;
  14157. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  14158. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  14159. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  14160. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  14161. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  14162. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  14163. // TODO (abelnation): add area lights shadow info to uniforms
  14164. }
  14165. var progUniforms = materialProperties.program.getUniforms(),
  14166. uniformsList =
  14167. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  14168. materialProperties.uniformsList = uniformsList;
  14169. }
  14170. function setProgram( camera, fog, material, object ) {
  14171. _usedTextureUnits = 0;
  14172. var materialProperties = properties.get( material );
  14173. var lights = currentRenderState.state.lights;
  14174. var lightsHash = materialProperties.lightsHash;
  14175. var lightsStateHash = lights.state.hash;
  14176. if ( _clippingEnabled ) {
  14177. if ( _localClippingEnabled || camera !== _currentCamera ) {
  14178. var useCache =
  14179. camera === _currentCamera &&
  14180. material.id === _currentMaterialId;
  14181. // we might want to call this function with some ClippingGroup
  14182. // object instead of the material, once it becomes feasible
  14183. // (#8465, #8379)
  14184. _clipping.setState(
  14185. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  14186. camera, materialProperties, useCache );
  14187. }
  14188. }
  14189. if ( material.needsUpdate === false ) {
  14190. if ( materialProperties.program === undefined ) {
  14191. material.needsUpdate = true;
  14192. } else if ( material.fog && materialProperties.fog !== fog ) {
  14193. material.needsUpdate = true;
  14194. } else if ( material.lights && ( lightsHash.stateID !== lightsStateHash.stateID ||
  14195. lightsHash.directionalLength !== lightsStateHash.directionalLength ||
  14196. lightsHash.pointLength !== lightsStateHash.pointLength ||
  14197. lightsHash.spotLength !== lightsStateHash.spotLength ||
  14198. lightsHash.rectAreaLength !== lightsStateHash.rectAreaLength ||
  14199. lightsHash.hemiLength !== lightsStateHash.hemiLength ||
  14200. lightsHash.shadowsLength !== lightsStateHash.shadowsLength ) ) {
  14201. material.needsUpdate = true;
  14202. } else if ( materialProperties.numClippingPlanes !== undefined &&
  14203. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  14204. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  14205. material.needsUpdate = true;
  14206. }
  14207. }
  14208. if ( material.needsUpdate ) {
  14209. initMaterial( material, fog, object );
  14210. material.needsUpdate = false;
  14211. }
  14212. var refreshProgram = false;
  14213. var refreshMaterial = false;
  14214. var refreshLights = false;
  14215. var program = materialProperties.program,
  14216. p_uniforms = program.getUniforms(),
  14217. m_uniforms = materialProperties.shader.uniforms;
  14218. if ( state.useProgram( program.program ) ) {
  14219. refreshProgram = true;
  14220. refreshMaterial = true;
  14221. refreshLights = true;
  14222. }
  14223. if ( material.id !== _currentMaterialId ) {
  14224. _currentMaterialId = material.id;
  14225. refreshMaterial = true;
  14226. }
  14227. if ( refreshProgram || _currentCamera !== camera ) {
  14228. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  14229. if ( capabilities.logarithmicDepthBuffer ) {
  14230. p_uniforms.setValue( _gl, 'logDepthBufFC',
  14231. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  14232. }
  14233. if ( _currentCamera !== camera ) {
  14234. _currentCamera = camera;
  14235. // lighting uniforms depend on the camera so enforce an update
  14236. // now, in case this material supports lights - or later, when
  14237. // the next material that does gets activated:
  14238. refreshMaterial = true; // set to true on material change
  14239. refreshLights = true; // remains set until update done
  14240. }
  14241. // load material specific uniforms
  14242. // (shader material also gets them for the sake of genericity)
  14243. if ( material.isShaderMaterial ||
  14244. material.isMeshPhongMaterial ||
  14245. material.isMeshStandardMaterial ||
  14246. material.envMap ) {
  14247. var uCamPos = p_uniforms.map.cameraPosition;
  14248. if ( uCamPos !== undefined ) {
  14249. uCamPos.setValue( _gl,
  14250. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  14251. }
  14252. }
  14253. if ( material.isMeshPhongMaterial ||
  14254. material.isMeshLambertMaterial ||
  14255. material.isMeshBasicMaterial ||
  14256. material.isMeshStandardMaterial ||
  14257. material.isShaderMaterial ||
  14258. material.skinning ) {
  14259. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  14260. }
  14261. }
  14262. // skinning uniforms must be set even if material didn't change
  14263. // auto-setting of texture unit for bone texture must go before other textures
  14264. // not sure why, but otherwise weird things happen
  14265. if ( material.skinning ) {
  14266. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  14267. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  14268. var skeleton = object.skeleton;
  14269. if ( skeleton ) {
  14270. var bones = skeleton.bones;
  14271. if ( capabilities.floatVertexTextures ) {
  14272. if ( skeleton.boneTexture === undefined ) {
  14273. // layout (1 matrix = 4 pixels)
  14274. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  14275. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  14276. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  14277. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  14278. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  14279. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  14280. size = _Math.ceilPowerOfTwo( size );
  14281. size = Math.max( size, 4 );
  14282. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  14283. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  14284. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  14285. boneTexture.needsUpdate = true;
  14286. skeleton.boneMatrices = boneMatrices;
  14287. skeleton.boneTexture = boneTexture;
  14288. skeleton.boneTextureSize = size;
  14289. }
  14290. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture );
  14291. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  14292. } else {
  14293. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  14294. }
  14295. }
  14296. }
  14297. if ( refreshMaterial ) {
  14298. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  14299. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  14300. if ( material.lights ) {
  14301. // the current material requires lighting info
  14302. // note: all lighting uniforms are always set correctly
  14303. // they simply reference the renderer's state for their
  14304. // values
  14305. //
  14306. // use the current material's .needsUpdate flags to set
  14307. // the GL state when required
  14308. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  14309. }
  14310. // refresh uniforms common to several materials
  14311. if ( fog && material.fog ) {
  14312. refreshUniformsFog( m_uniforms, fog );
  14313. }
  14314. if ( material.isMeshBasicMaterial ) {
  14315. refreshUniformsCommon( m_uniforms, material );
  14316. } else if ( material.isMeshLambertMaterial ) {
  14317. refreshUniformsCommon( m_uniforms, material );
  14318. refreshUniformsLambert( m_uniforms, material );
  14319. } else if ( material.isMeshPhongMaterial ) {
  14320. refreshUniformsCommon( m_uniforms, material );
  14321. if ( material.isMeshToonMaterial ) {
  14322. refreshUniformsToon( m_uniforms, material );
  14323. } else {
  14324. refreshUniformsPhong( m_uniforms, material );
  14325. }
  14326. } else if ( material.isMeshStandardMaterial ) {
  14327. refreshUniformsCommon( m_uniforms, material );
  14328. if ( material.isMeshPhysicalMaterial ) {
  14329. refreshUniformsPhysical( m_uniforms, material );
  14330. } else {
  14331. refreshUniformsStandard( m_uniforms, material );
  14332. }
  14333. } else if ( material.isMeshMatcapMaterial ) {
  14334. refreshUniformsCommon( m_uniforms, material );
  14335. refreshUniformsMatcap( m_uniforms, material );
  14336. } else if ( material.isMeshDepthMaterial ) {
  14337. refreshUniformsCommon( m_uniforms, material );
  14338. refreshUniformsDepth( m_uniforms, material );
  14339. } else if ( material.isMeshDistanceMaterial ) {
  14340. refreshUniformsCommon( m_uniforms, material );
  14341. refreshUniformsDistance( m_uniforms, material );
  14342. } else if ( material.isMeshNormalMaterial ) {
  14343. refreshUniformsCommon( m_uniforms, material );
  14344. refreshUniformsNormal( m_uniforms, material );
  14345. } else if ( material.isLineBasicMaterial ) {
  14346. refreshUniformsLine( m_uniforms, material );
  14347. if ( material.isLineDashedMaterial ) {
  14348. refreshUniformsDash( m_uniforms, material );
  14349. }
  14350. } else if ( material.isPointsMaterial ) {
  14351. refreshUniformsPoints( m_uniforms, material );
  14352. } else if ( material.isSpriteMaterial ) {
  14353. refreshUniformsSprites( m_uniforms, material );
  14354. } else if ( material.isShadowMaterial ) {
  14355. m_uniforms.color.value = material.color;
  14356. m_uniforms.opacity.value = material.opacity;
  14357. }
  14358. // RectAreaLight Texture
  14359. // TODO (mrdoob): Find a nicer implementation
  14360. if ( m_uniforms.ltc_1 !== undefined ) m_uniforms.ltc_1.value = UniformsLib.LTC_1;
  14361. if ( m_uniforms.ltc_2 !== undefined ) m_uniforms.ltc_2.value = UniformsLib.LTC_2;
  14362. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, _this );
  14363. }
  14364. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  14365. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, _this );
  14366. material.uniformsNeedUpdate = false;
  14367. }
  14368. if ( material.isSpriteMaterial ) {
  14369. p_uniforms.setValue( _gl, 'center', object.center );
  14370. }
  14371. // common matrices
  14372. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  14373. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  14374. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  14375. return program;
  14376. }
  14377. // Uniforms (refresh uniforms objects)
  14378. function refreshUniformsCommon( uniforms, material ) {
  14379. uniforms.opacity.value = material.opacity;
  14380. if ( material.color ) {
  14381. uniforms.diffuse.value = material.color;
  14382. }
  14383. if ( material.emissive ) {
  14384. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  14385. }
  14386. if ( material.map ) {
  14387. uniforms.map.value = material.map;
  14388. }
  14389. if ( material.alphaMap ) {
  14390. uniforms.alphaMap.value = material.alphaMap;
  14391. }
  14392. if ( material.specularMap ) {
  14393. uniforms.specularMap.value = material.specularMap;
  14394. }
  14395. if ( material.envMap ) {
  14396. uniforms.envMap.value = material.envMap;
  14397. // don't flip CubeTexture envMaps, flip everything else:
  14398. // WebGLRenderTargetCube will be flipped for backwards compatibility
  14399. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  14400. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  14401. uniforms.flipEnvMap.value = material.envMap.isCubeTexture ? - 1 : 1;
  14402. uniforms.reflectivity.value = material.reflectivity;
  14403. uniforms.refractionRatio.value = material.refractionRatio;
  14404. uniforms.maxMipLevel.value = properties.get( material.envMap ).__maxMipLevel;
  14405. }
  14406. if ( material.lightMap ) {
  14407. uniforms.lightMap.value = material.lightMap;
  14408. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14409. }
  14410. if ( material.aoMap ) {
  14411. uniforms.aoMap.value = material.aoMap;
  14412. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14413. }
  14414. // uv repeat and offset setting priorities
  14415. // 1. color map
  14416. // 2. specular map
  14417. // 3. normal map
  14418. // 4. bump map
  14419. // 5. alpha map
  14420. // 6. emissive map
  14421. var uvScaleMap;
  14422. if ( material.map ) {
  14423. uvScaleMap = material.map;
  14424. } else if ( material.specularMap ) {
  14425. uvScaleMap = material.specularMap;
  14426. } else if ( material.displacementMap ) {
  14427. uvScaleMap = material.displacementMap;
  14428. } else if ( material.normalMap ) {
  14429. uvScaleMap = material.normalMap;
  14430. } else if ( material.bumpMap ) {
  14431. uvScaleMap = material.bumpMap;
  14432. } else if ( material.roughnessMap ) {
  14433. uvScaleMap = material.roughnessMap;
  14434. } else if ( material.metalnessMap ) {
  14435. uvScaleMap = material.metalnessMap;
  14436. } else if ( material.alphaMap ) {
  14437. uvScaleMap = material.alphaMap;
  14438. } else if ( material.emissiveMap ) {
  14439. uvScaleMap = material.emissiveMap;
  14440. }
  14441. if ( uvScaleMap !== undefined ) {
  14442. // backwards compatibility
  14443. if ( uvScaleMap.isWebGLRenderTarget ) {
  14444. uvScaleMap = uvScaleMap.texture;
  14445. }
  14446. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14447. uvScaleMap.updateMatrix();
  14448. }
  14449. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14450. }
  14451. }
  14452. function refreshUniformsLine( uniforms, material ) {
  14453. uniforms.diffuse.value = material.color;
  14454. uniforms.opacity.value = material.opacity;
  14455. }
  14456. function refreshUniformsDash( uniforms, material ) {
  14457. uniforms.dashSize.value = material.dashSize;
  14458. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14459. uniforms.scale.value = material.scale;
  14460. }
  14461. function refreshUniformsPoints( uniforms, material ) {
  14462. uniforms.diffuse.value = material.color;
  14463. uniforms.opacity.value = material.opacity;
  14464. uniforms.size.value = material.size * _pixelRatio;
  14465. uniforms.scale.value = _height * 0.5;
  14466. uniforms.map.value = material.map;
  14467. if ( material.map !== null ) {
  14468. if ( material.map.matrixAutoUpdate === true ) {
  14469. material.map.updateMatrix();
  14470. }
  14471. uniforms.uvTransform.value.copy( material.map.matrix );
  14472. }
  14473. }
  14474. function refreshUniformsSprites( uniforms, material ) {
  14475. uniforms.diffuse.value = material.color;
  14476. uniforms.opacity.value = material.opacity;
  14477. uniforms.rotation.value = material.rotation;
  14478. uniforms.map.value = material.map;
  14479. if ( material.map !== null ) {
  14480. if ( material.map.matrixAutoUpdate === true ) {
  14481. material.map.updateMatrix();
  14482. }
  14483. uniforms.uvTransform.value.copy( material.map.matrix );
  14484. }
  14485. }
  14486. function refreshUniformsFog( uniforms, fog ) {
  14487. uniforms.fogColor.value = fog.color;
  14488. if ( fog.isFog ) {
  14489. uniforms.fogNear.value = fog.near;
  14490. uniforms.fogFar.value = fog.far;
  14491. } else if ( fog.isFogExp2 ) {
  14492. uniforms.fogDensity.value = fog.density;
  14493. }
  14494. }
  14495. function refreshUniformsLambert( uniforms, material ) {
  14496. if ( material.emissiveMap ) {
  14497. uniforms.emissiveMap.value = material.emissiveMap;
  14498. }
  14499. }
  14500. function refreshUniformsPhong( uniforms, material ) {
  14501. uniforms.specular.value = material.specular;
  14502. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  14503. if ( material.emissiveMap ) {
  14504. uniforms.emissiveMap.value = material.emissiveMap;
  14505. }
  14506. if ( material.bumpMap ) {
  14507. uniforms.bumpMap.value = material.bumpMap;
  14508. uniforms.bumpScale.value = material.bumpScale;
  14509. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14510. }
  14511. if ( material.normalMap ) {
  14512. uniforms.normalMap.value = material.normalMap;
  14513. uniforms.normalScale.value.copy( material.normalScale );
  14514. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14515. }
  14516. if ( material.displacementMap ) {
  14517. uniforms.displacementMap.value = material.displacementMap;
  14518. uniforms.displacementScale.value = material.displacementScale;
  14519. uniforms.displacementBias.value = material.displacementBias;
  14520. }
  14521. }
  14522. function refreshUniformsToon( uniforms, material ) {
  14523. refreshUniformsPhong( uniforms, material );
  14524. if ( material.gradientMap ) {
  14525. uniforms.gradientMap.value = material.gradientMap;
  14526. }
  14527. }
  14528. function refreshUniformsStandard( uniforms, material ) {
  14529. uniforms.roughness.value = material.roughness;
  14530. uniforms.metalness.value = material.metalness;
  14531. if ( material.roughnessMap ) {
  14532. uniforms.roughnessMap.value = material.roughnessMap;
  14533. }
  14534. if ( material.metalnessMap ) {
  14535. uniforms.metalnessMap.value = material.metalnessMap;
  14536. }
  14537. if ( material.emissiveMap ) {
  14538. uniforms.emissiveMap.value = material.emissiveMap;
  14539. }
  14540. if ( material.bumpMap ) {
  14541. uniforms.bumpMap.value = material.bumpMap;
  14542. uniforms.bumpScale.value = material.bumpScale;
  14543. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14544. }
  14545. if ( material.normalMap ) {
  14546. uniforms.normalMap.value = material.normalMap;
  14547. uniforms.normalScale.value.copy( material.normalScale );
  14548. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14549. }
  14550. if ( material.displacementMap ) {
  14551. uniforms.displacementMap.value = material.displacementMap;
  14552. uniforms.displacementScale.value = material.displacementScale;
  14553. uniforms.displacementBias.value = material.displacementBias;
  14554. }
  14555. if ( material.envMap ) {
  14556. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14557. uniforms.envMapIntensity.value = material.envMapIntensity;
  14558. }
  14559. }
  14560. function refreshUniformsPhysical( uniforms, material ) {
  14561. refreshUniformsStandard( uniforms, material );
  14562. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14563. uniforms.clearCoat.value = material.clearCoat;
  14564. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  14565. }
  14566. function refreshUniformsMatcap( uniforms, material ) {
  14567. if ( material.matcap ) {
  14568. uniforms.matcap.value = material.matcap;
  14569. }
  14570. if ( material.bumpMap ) {
  14571. uniforms.bumpMap.value = material.bumpMap;
  14572. uniforms.bumpScale.value = material.bumpScale;
  14573. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14574. }
  14575. if ( material.normalMap ) {
  14576. uniforms.normalMap.value = material.normalMap;
  14577. uniforms.normalScale.value.copy( material.normalScale );
  14578. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14579. }
  14580. if ( material.displacementMap ) {
  14581. uniforms.displacementMap.value = material.displacementMap;
  14582. uniforms.displacementScale.value = material.displacementScale;
  14583. uniforms.displacementBias.value = material.displacementBias;
  14584. }
  14585. }
  14586. function refreshUniformsDepth( uniforms, material ) {
  14587. if ( material.displacementMap ) {
  14588. uniforms.displacementMap.value = material.displacementMap;
  14589. uniforms.displacementScale.value = material.displacementScale;
  14590. uniforms.displacementBias.value = material.displacementBias;
  14591. }
  14592. }
  14593. function refreshUniformsDistance( uniforms, material ) {
  14594. if ( material.displacementMap ) {
  14595. uniforms.displacementMap.value = material.displacementMap;
  14596. uniforms.displacementScale.value = material.displacementScale;
  14597. uniforms.displacementBias.value = material.displacementBias;
  14598. }
  14599. uniforms.referencePosition.value.copy( material.referencePosition );
  14600. uniforms.nearDistance.value = material.nearDistance;
  14601. uniforms.farDistance.value = material.farDistance;
  14602. }
  14603. function refreshUniformsNormal( uniforms, material ) {
  14604. if ( material.bumpMap ) {
  14605. uniforms.bumpMap.value = material.bumpMap;
  14606. uniforms.bumpScale.value = material.bumpScale;
  14607. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14608. }
  14609. if ( material.normalMap ) {
  14610. uniforms.normalMap.value = material.normalMap;
  14611. uniforms.normalScale.value.copy( material.normalScale );
  14612. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14613. }
  14614. if ( material.displacementMap ) {
  14615. uniforms.displacementMap.value = material.displacementMap;
  14616. uniforms.displacementScale.value = material.displacementScale;
  14617. uniforms.displacementBias.value = material.displacementBias;
  14618. }
  14619. }
  14620. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  14621. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  14622. uniforms.ambientLightColor.needsUpdate = value;
  14623. uniforms.directionalLights.needsUpdate = value;
  14624. uniforms.pointLights.needsUpdate = value;
  14625. uniforms.spotLights.needsUpdate = value;
  14626. uniforms.rectAreaLights.needsUpdate = value;
  14627. uniforms.hemisphereLights.needsUpdate = value;
  14628. }
  14629. // Textures
  14630. function allocTextureUnit() {
  14631. var textureUnit = _usedTextureUnits;
  14632. if ( textureUnit >= capabilities.maxTextures ) {
  14633. console.warn( 'THREE.WebGLRenderer: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  14634. }
  14635. _usedTextureUnits += 1;
  14636. return textureUnit;
  14637. }
  14638. this.allocTextureUnit = allocTextureUnit;
  14639. // this.setTexture2D = setTexture2D;
  14640. this.setTexture2D = ( function () {
  14641. var warned = false;
  14642. // backwards compatibility: peel texture.texture
  14643. return function setTexture2D( texture, slot ) {
  14644. if ( texture && texture.isWebGLRenderTarget ) {
  14645. if ( ! warned ) {
  14646. console.warn( "THREE.WebGLRenderer.setTexture2D: don't use render targets as textures. Use their .texture property instead." );
  14647. warned = true;
  14648. }
  14649. texture = texture.texture;
  14650. }
  14651. textures.setTexture2D( texture, slot );
  14652. };
  14653. }() );
  14654. this.setTexture3D = ( function () {
  14655. // backwards compatibility: peel texture.texture
  14656. return function setTexture3D( texture, slot ) {
  14657. textures.setTexture3D( texture, slot );
  14658. };
  14659. }() );
  14660. this.setTexture = ( function () {
  14661. var warned = false;
  14662. return function setTexture( texture, slot ) {
  14663. if ( ! warned ) {
  14664. console.warn( "THREE.WebGLRenderer: .setTexture is deprecated, use setTexture2D instead." );
  14665. warned = true;
  14666. }
  14667. textures.setTexture2D( texture, slot );
  14668. };
  14669. }() );
  14670. this.setTextureCube = ( function () {
  14671. var warned = false;
  14672. return function setTextureCube( texture, slot ) {
  14673. // backwards compatibility: peel texture.texture
  14674. if ( texture && texture.isWebGLRenderTargetCube ) {
  14675. if ( ! warned ) {
  14676. console.warn( "THREE.WebGLRenderer.setTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  14677. warned = true;
  14678. }
  14679. texture = texture.texture;
  14680. }
  14681. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  14682. // TODO: unify these code paths
  14683. if ( ( texture && texture.isCubeTexture ) ||
  14684. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  14685. // CompressedTexture can have Array in image :/
  14686. // this function alone should take care of cube textures
  14687. textures.setTextureCube( texture, slot );
  14688. } else {
  14689. // assumed: texture property of THREE.WebGLRenderTargetCube
  14690. textures.setTextureCubeDynamic( texture, slot );
  14691. }
  14692. };
  14693. }() );
  14694. //
  14695. this.setFramebuffer = function ( value ) {
  14696. _framebuffer = value;
  14697. };
  14698. this.getRenderTarget = function () {
  14699. return _currentRenderTarget;
  14700. };
  14701. this.setRenderTarget = function ( renderTarget ) {
  14702. _currentRenderTarget = renderTarget;
  14703. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  14704. textures.setupRenderTarget( renderTarget );
  14705. }
  14706. var framebuffer = _framebuffer;
  14707. var isCube = false;
  14708. if ( renderTarget ) {
  14709. var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14710. if ( renderTarget.isWebGLRenderTargetCube ) {
  14711. framebuffer = __webglFramebuffer[ renderTarget.activeCubeFace ];
  14712. isCube = true;
  14713. } else if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  14714. framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
  14715. } else {
  14716. framebuffer = __webglFramebuffer;
  14717. }
  14718. _currentViewport.copy( renderTarget.viewport );
  14719. _currentScissor.copy( renderTarget.scissor );
  14720. _currentScissorTest = renderTarget.scissorTest;
  14721. } else {
  14722. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  14723. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  14724. _currentScissorTest = _scissorTest;
  14725. }
  14726. if ( _currentFramebuffer !== framebuffer ) {
  14727. _gl.bindFramebuffer( 36160, framebuffer );
  14728. _currentFramebuffer = framebuffer;
  14729. }
  14730. state.viewport( _currentViewport );
  14731. state.scissor( _currentScissor );
  14732. state.setScissorTest( _currentScissorTest );
  14733. if ( isCube ) {
  14734. var textureProperties = properties.get( renderTarget.texture );
  14735. _gl.framebufferTexture2D( 36160, 36064, 34069 + renderTarget.activeCubeFace, textureProperties.__webglTexture, renderTarget.activeMipMapLevel );
  14736. }
  14737. };
  14738. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  14739. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  14740. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  14741. return;
  14742. }
  14743. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14744. if ( framebuffer ) {
  14745. var restore = false;
  14746. if ( framebuffer !== _currentFramebuffer ) {
  14747. _gl.bindFramebuffer( 36160, framebuffer );
  14748. restore = true;
  14749. }
  14750. try {
  14751. var texture = renderTarget.texture;
  14752. var textureFormat = texture.format;
  14753. var textureType = texture.type;
  14754. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( 35739 ) ) {
  14755. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  14756. return;
  14757. }
  14758. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( 35738 ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  14759. ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  14760. ! ( textureType === HalfFloatType && ( capabilities.isWebGL2 ? extensions.get( 'EXT_color_buffer_float' ) : extensions.get( 'EXT_color_buffer_half_float' ) ) ) ) {
  14761. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  14762. return;
  14763. }
  14764. if ( _gl.checkFramebufferStatus( 36160 ) === 36053 ) {
  14765. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  14766. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  14767. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  14768. }
  14769. } else {
  14770. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  14771. }
  14772. } finally {
  14773. if ( restore ) {
  14774. _gl.bindFramebuffer( 36160, _currentFramebuffer );
  14775. }
  14776. }
  14777. }
  14778. };
  14779. this.copyFramebufferToTexture = function ( position, texture, level ) {
  14780. var width = texture.image.width;
  14781. var height = texture.image.height;
  14782. var glFormat = utils.convert( texture.format );
  14783. this.setTexture2D( texture, 0 );
  14784. _gl.copyTexImage2D( 3553, level || 0, glFormat, position.x, position.y, width, height, 0 );
  14785. };
  14786. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level ) {
  14787. var width = srcTexture.image.width;
  14788. var height = srcTexture.image.height;
  14789. var glFormat = utils.convert( dstTexture.format );
  14790. var glType = utils.convert( dstTexture.type );
  14791. this.setTexture2D( dstTexture, 0 );
  14792. if ( srcTexture.isDataTexture ) {
  14793. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
  14794. } else {
  14795. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, glFormat, glType, srcTexture.image );
  14796. }
  14797. };
  14798. }
  14799. /**
  14800. * @author mrdoob / http://mrdoob.com/
  14801. * @author alteredq / http://alteredqualia.com/
  14802. */
  14803. function FogExp2( color, density ) {
  14804. this.name = '';
  14805. this.color = new Color( color );
  14806. this.density = ( density !== undefined ) ? density : 0.00025;
  14807. }
  14808. FogExp2.prototype.isFogExp2 = true;
  14809. FogExp2.prototype.clone = function () {
  14810. return new FogExp2( this.color, this.density );
  14811. };
  14812. FogExp2.prototype.toJSON = function ( /* meta */ ) {
  14813. return {
  14814. type: 'FogExp2',
  14815. color: this.color.getHex(),
  14816. density: this.density
  14817. };
  14818. };
  14819. /**
  14820. * @author mrdoob / http://mrdoob.com/
  14821. * @author alteredq / http://alteredqualia.com/
  14822. */
  14823. function Fog( color, near, far ) {
  14824. this.name = '';
  14825. this.color = new Color( color );
  14826. this.near = ( near !== undefined ) ? near : 1;
  14827. this.far = ( far !== undefined ) ? far : 1000;
  14828. }
  14829. Fog.prototype.isFog = true;
  14830. Fog.prototype.clone = function () {
  14831. return new Fog( this.color, this.near, this.far );
  14832. };
  14833. Fog.prototype.toJSON = function ( /* meta */ ) {
  14834. return {
  14835. type: 'Fog',
  14836. color: this.color.getHex(),
  14837. near: this.near,
  14838. far: this.far
  14839. };
  14840. };
  14841. /**
  14842. * @author mrdoob / http://mrdoob.com/
  14843. */
  14844. function Scene() {
  14845. Object3D.call( this );
  14846. this.type = 'Scene';
  14847. this.background = null;
  14848. this.fog = null;
  14849. this.overrideMaterial = null;
  14850. this.autoUpdate = true; // checked by the renderer
  14851. }
  14852. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14853. constructor: Scene,
  14854. copy: function ( source, recursive ) {
  14855. Object3D.prototype.copy.call( this, source, recursive );
  14856. if ( source.background !== null ) this.background = source.background.clone();
  14857. if ( source.fog !== null ) this.fog = source.fog.clone();
  14858. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  14859. this.autoUpdate = source.autoUpdate;
  14860. this.matrixAutoUpdate = source.matrixAutoUpdate;
  14861. return this;
  14862. },
  14863. toJSON: function ( meta ) {
  14864. var data = Object3D.prototype.toJSON.call( this, meta );
  14865. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  14866. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  14867. return data;
  14868. },
  14869. dispose: function () {
  14870. this.dispatchEvent( { type: 'dispose' } );
  14871. }
  14872. } );
  14873. /**
  14874. * @author benaadams / https://twitter.com/ben_a_adams
  14875. */
  14876. function InterleavedBuffer( array, stride ) {
  14877. this.array = array;
  14878. this.stride = stride;
  14879. this.count = array !== undefined ? array.length / stride : 0;
  14880. this.dynamic = false;
  14881. this.updateRange = { offset: 0, count: - 1 };
  14882. this.version = 0;
  14883. }
  14884. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  14885. set: function ( value ) {
  14886. if ( value === true ) this.version ++;
  14887. }
  14888. } );
  14889. Object.assign( InterleavedBuffer.prototype, {
  14890. isInterleavedBuffer: true,
  14891. onUploadCallback: function () {},
  14892. setArray: function ( array ) {
  14893. if ( Array.isArray( array ) ) {
  14894. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  14895. }
  14896. this.count = array !== undefined ? array.length / this.stride : 0;
  14897. this.array = array;
  14898. return this;
  14899. },
  14900. setDynamic: function ( value ) {
  14901. this.dynamic = value;
  14902. return this;
  14903. },
  14904. copy: function ( source ) {
  14905. this.array = new source.array.constructor( source.array );
  14906. this.count = source.count;
  14907. this.stride = source.stride;
  14908. this.dynamic = source.dynamic;
  14909. return this;
  14910. },
  14911. copyAt: function ( index1, attribute, index2 ) {
  14912. index1 *= this.stride;
  14913. index2 *= attribute.stride;
  14914. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  14915. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  14916. }
  14917. return this;
  14918. },
  14919. set: function ( value, offset ) {
  14920. if ( offset === undefined ) offset = 0;
  14921. this.array.set( value, offset );
  14922. return this;
  14923. },
  14924. clone: function () {
  14925. return new this.constructor().copy( this );
  14926. },
  14927. onUpload: function ( callback ) {
  14928. this.onUploadCallback = callback;
  14929. return this;
  14930. }
  14931. } );
  14932. /**
  14933. * @author benaadams / https://twitter.com/ben_a_adams
  14934. */
  14935. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  14936. this.data = interleavedBuffer;
  14937. this.itemSize = itemSize;
  14938. this.offset = offset;
  14939. this.normalized = normalized === true;
  14940. }
  14941. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  14942. count: {
  14943. get: function () {
  14944. return this.data.count;
  14945. }
  14946. },
  14947. array: {
  14948. get: function () {
  14949. return this.data.array;
  14950. }
  14951. }
  14952. } );
  14953. Object.assign( InterleavedBufferAttribute.prototype, {
  14954. isInterleavedBufferAttribute: true,
  14955. setX: function ( index, x ) {
  14956. this.data.array[ index * this.data.stride + this.offset ] = x;
  14957. return this;
  14958. },
  14959. setY: function ( index, y ) {
  14960. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  14961. return this;
  14962. },
  14963. setZ: function ( index, z ) {
  14964. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  14965. return this;
  14966. },
  14967. setW: function ( index, w ) {
  14968. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  14969. return this;
  14970. },
  14971. getX: function ( index ) {
  14972. return this.data.array[ index * this.data.stride + this.offset ];
  14973. },
  14974. getY: function ( index ) {
  14975. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  14976. },
  14977. getZ: function ( index ) {
  14978. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  14979. },
  14980. getW: function ( index ) {
  14981. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  14982. },
  14983. setXY: function ( index, x, y ) {
  14984. index = index * this.data.stride + this.offset;
  14985. this.data.array[ index + 0 ] = x;
  14986. this.data.array[ index + 1 ] = y;
  14987. return this;
  14988. },
  14989. setXYZ: function ( index, x, y, z ) {
  14990. index = index * this.data.stride + this.offset;
  14991. this.data.array[ index + 0 ] = x;
  14992. this.data.array[ index + 1 ] = y;
  14993. this.data.array[ index + 2 ] = z;
  14994. return this;
  14995. },
  14996. setXYZW: function ( index, x, y, z, w ) {
  14997. index = index * this.data.stride + this.offset;
  14998. this.data.array[ index + 0 ] = x;
  14999. this.data.array[ index + 1 ] = y;
  15000. this.data.array[ index + 2 ] = z;
  15001. this.data.array[ index + 3 ] = w;
  15002. return this;
  15003. }
  15004. } );
  15005. /**
  15006. * @author alteredq / http://alteredqualia.com/
  15007. *
  15008. * parameters = {
  15009. * color: <hex>,
  15010. * map: new THREE.Texture( <Image> ),
  15011. * rotation: <float>,
  15012. * sizeAttenuation: <bool>
  15013. * }
  15014. */
  15015. function SpriteMaterial( parameters ) {
  15016. Material.call( this );
  15017. this.type = 'SpriteMaterial';
  15018. this.color = new Color( 0xffffff );
  15019. this.map = null;
  15020. this.rotation = 0;
  15021. this.sizeAttenuation = true;
  15022. this.lights = false;
  15023. this.transparent = true;
  15024. this.setValues( parameters );
  15025. }
  15026. SpriteMaterial.prototype = Object.create( Material.prototype );
  15027. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15028. SpriteMaterial.prototype.isSpriteMaterial = true;
  15029. SpriteMaterial.prototype.copy = function ( source ) {
  15030. Material.prototype.copy.call( this, source );
  15031. this.color.copy( source.color );
  15032. this.map = source.map;
  15033. this.rotation = source.rotation;
  15034. this.sizeAttenuation = source.sizeAttenuation;
  15035. return this;
  15036. };
  15037. /**
  15038. * @author mikael emtinger / http://gomo.se/
  15039. * @author alteredq / http://alteredqualia.com/
  15040. */
  15041. var geometry;
  15042. function Sprite( material ) {
  15043. Object3D.call( this );
  15044. this.type = 'Sprite';
  15045. if ( geometry === undefined ) {
  15046. geometry = new BufferGeometry();
  15047. var float32Array = new Float32Array( [
  15048. - 0.5, - 0.5, 0, 0, 0,
  15049. 0.5, - 0.5, 0, 1, 0,
  15050. 0.5, 0.5, 0, 1, 1,
  15051. - 0.5, 0.5, 0, 0, 1
  15052. ] );
  15053. var interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  15054. geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  15055. geometry.addAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  15056. geometry.addAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  15057. }
  15058. this.geometry = geometry;
  15059. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  15060. this.center = new Vector2( 0.5, 0.5 );
  15061. }
  15062. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15063. constructor: Sprite,
  15064. isSprite: true,
  15065. raycast: ( function () {
  15066. var intersectPoint = new Vector3();
  15067. var worldScale = new Vector3();
  15068. var mvPosition = new Vector3();
  15069. var alignedPosition = new Vector2();
  15070. var rotatedPosition = new Vector2();
  15071. var viewWorldMatrix = new Matrix4();
  15072. var vA = new Vector3();
  15073. var vB = new Vector3();
  15074. var vC = new Vector3();
  15075. var uvA = new Vector2();
  15076. var uvB = new Vector2();
  15077. var uvC = new Vector2();
  15078. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  15079. // compute position in camera space
  15080. alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  15081. // to check if rotation is not zero
  15082. if ( sin !== undefined ) {
  15083. rotatedPosition.x = ( cos * alignedPosition.x ) - ( sin * alignedPosition.y );
  15084. rotatedPosition.y = ( sin * alignedPosition.x ) + ( cos * alignedPosition.y );
  15085. } else {
  15086. rotatedPosition.copy( alignedPosition );
  15087. }
  15088. vertexPosition.copy( mvPosition );
  15089. vertexPosition.x += rotatedPosition.x;
  15090. vertexPosition.y += rotatedPosition.y;
  15091. // transform to world space
  15092. vertexPosition.applyMatrix4( viewWorldMatrix );
  15093. }
  15094. return function raycast( raycaster, intersects ) {
  15095. worldScale.setFromMatrixScale( this.matrixWorld );
  15096. viewWorldMatrix.getInverse( this.modelViewMatrix ).premultiply( this.matrixWorld );
  15097. mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  15098. var rotation = this.material.rotation;
  15099. var sin, cos;
  15100. if ( rotation !== 0 ) {
  15101. cos = Math.cos( rotation );
  15102. sin = Math.sin( rotation );
  15103. }
  15104. var center = this.center;
  15105. transformVertex( vA.set( - 0.5, - 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15106. transformVertex( vB.set( 0.5, - 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15107. transformVertex( vC.set( 0.5, 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15108. uvA.set( 0, 0 );
  15109. uvB.set( 1, 0 );
  15110. uvC.set( 1, 1 );
  15111. // check first triangle
  15112. var intersect = raycaster.ray.intersectTriangle( vA, vB, vC, false, intersectPoint );
  15113. if ( intersect === null ) {
  15114. // check second triangle
  15115. transformVertex( vB.set( - 0.5, 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15116. uvB.set( 0, 1 );
  15117. intersect = raycaster.ray.intersectTriangle( vA, vC, vB, false, intersectPoint );
  15118. if ( intersect === null ) {
  15119. return;
  15120. }
  15121. }
  15122. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  15123. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15124. intersects.push( {
  15125. distance: distance,
  15126. point: intersectPoint.clone(),
  15127. uv: Triangle.getUV( intersectPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() ),
  15128. face: null,
  15129. object: this
  15130. } );
  15131. };
  15132. }() ),
  15133. clone: function () {
  15134. return new this.constructor( this.material ).copy( this );
  15135. },
  15136. copy: function ( source ) {
  15137. Object3D.prototype.copy.call( this, source );
  15138. if ( source.center !== undefined ) this.center.copy( source.center );
  15139. return this;
  15140. }
  15141. } );
  15142. /**
  15143. * @author mikael emtinger / http://gomo.se/
  15144. * @author alteredq / http://alteredqualia.com/
  15145. * @author mrdoob / http://mrdoob.com/
  15146. */
  15147. function LOD() {
  15148. Object3D.call( this );
  15149. this.type = 'LOD';
  15150. Object.defineProperties( this, {
  15151. levels: {
  15152. enumerable: true,
  15153. value: []
  15154. }
  15155. } );
  15156. }
  15157. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15158. constructor: LOD,
  15159. copy: function ( source ) {
  15160. Object3D.prototype.copy.call( this, source, false );
  15161. var levels = source.levels;
  15162. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15163. var level = levels[ i ];
  15164. this.addLevel( level.object.clone(), level.distance );
  15165. }
  15166. return this;
  15167. },
  15168. addLevel: function ( object, distance ) {
  15169. if ( distance === undefined ) distance = 0;
  15170. distance = Math.abs( distance );
  15171. var levels = this.levels;
  15172. for ( var l = 0; l < levels.length; l ++ ) {
  15173. if ( distance < levels[ l ].distance ) {
  15174. break;
  15175. }
  15176. }
  15177. levels.splice( l, 0, { distance: distance, object: object } );
  15178. this.add( object );
  15179. },
  15180. getObjectForDistance: function ( distance ) {
  15181. var levels = this.levels;
  15182. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15183. if ( distance < levels[ i ].distance ) {
  15184. break;
  15185. }
  15186. }
  15187. return levels[ i - 1 ].object;
  15188. },
  15189. raycast: ( function () {
  15190. var matrixPosition = new Vector3();
  15191. return function raycast( raycaster, intersects ) {
  15192. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  15193. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  15194. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  15195. };
  15196. }() ),
  15197. update: function () {
  15198. var v1 = new Vector3();
  15199. var v2 = new Vector3();
  15200. return function update( camera ) {
  15201. var levels = this.levels;
  15202. if ( levels.length > 1 ) {
  15203. v1.setFromMatrixPosition( camera.matrixWorld );
  15204. v2.setFromMatrixPosition( this.matrixWorld );
  15205. var distance = v1.distanceTo( v2 );
  15206. levels[ 0 ].object.visible = true;
  15207. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15208. if ( distance >= levels[ i ].distance ) {
  15209. levels[ i - 1 ].object.visible = false;
  15210. levels[ i ].object.visible = true;
  15211. } else {
  15212. break;
  15213. }
  15214. }
  15215. for ( ; i < l; i ++ ) {
  15216. levels[ i ].object.visible = false;
  15217. }
  15218. }
  15219. };
  15220. }(),
  15221. toJSON: function ( meta ) {
  15222. var data = Object3D.prototype.toJSON.call( this, meta );
  15223. data.object.levels = [];
  15224. var levels = this.levels;
  15225. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15226. var level = levels[ i ];
  15227. data.object.levels.push( {
  15228. object: level.object.uuid,
  15229. distance: level.distance
  15230. } );
  15231. }
  15232. return data;
  15233. }
  15234. } );
  15235. /**
  15236. * @author mikael emtinger / http://gomo.se/
  15237. * @author alteredq / http://alteredqualia.com/
  15238. * @author ikerr / http://verold.com
  15239. */
  15240. function SkinnedMesh( geometry, material ) {
  15241. if ( geometry && geometry.isGeometry ) {
  15242. console.error( 'THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  15243. }
  15244. Mesh.call( this, geometry, material );
  15245. this.type = 'SkinnedMesh';
  15246. this.bindMode = 'attached';
  15247. this.bindMatrix = new Matrix4();
  15248. this.bindMatrixInverse = new Matrix4();
  15249. }
  15250. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  15251. constructor: SkinnedMesh,
  15252. isSkinnedMesh: true,
  15253. bind: function ( skeleton, bindMatrix ) {
  15254. this.skeleton = skeleton;
  15255. if ( bindMatrix === undefined ) {
  15256. this.updateMatrixWorld( true );
  15257. this.skeleton.calculateInverses();
  15258. bindMatrix = this.matrixWorld;
  15259. }
  15260. this.bindMatrix.copy( bindMatrix );
  15261. this.bindMatrixInverse.getInverse( bindMatrix );
  15262. },
  15263. pose: function () {
  15264. this.skeleton.pose();
  15265. },
  15266. normalizeSkinWeights: function () {
  15267. var vector = new Vector4();
  15268. var skinWeight = this.geometry.attributes.skinWeight;
  15269. for ( var i = 0, l = skinWeight.count; i < l; i ++ ) {
  15270. vector.x = skinWeight.getX( i );
  15271. vector.y = skinWeight.getY( i );
  15272. vector.z = skinWeight.getZ( i );
  15273. vector.w = skinWeight.getW( i );
  15274. var scale = 1.0 / vector.manhattanLength();
  15275. if ( scale !== Infinity ) {
  15276. vector.multiplyScalar( scale );
  15277. } else {
  15278. vector.set( 1, 0, 0, 0 ); // do something reasonable
  15279. }
  15280. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  15281. }
  15282. },
  15283. updateMatrixWorld: function ( force ) {
  15284. Mesh.prototype.updateMatrixWorld.call( this, force );
  15285. if ( this.bindMode === 'attached' ) {
  15286. this.bindMatrixInverse.getInverse( this.matrixWorld );
  15287. } else if ( this.bindMode === 'detached' ) {
  15288. this.bindMatrixInverse.getInverse( this.bindMatrix );
  15289. } else {
  15290. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  15291. }
  15292. },
  15293. clone: function () {
  15294. return new this.constructor( this.geometry, this.material ).copy( this );
  15295. }
  15296. } );
  15297. /**
  15298. * @author mikael emtinger / http://gomo.se/
  15299. * @author alteredq / http://alteredqualia.com/
  15300. * @author michael guerrero / http://realitymeltdown.com
  15301. * @author ikerr / http://verold.com
  15302. */
  15303. function Skeleton( bones, boneInverses ) {
  15304. // copy the bone array
  15305. bones = bones || [];
  15306. this.bones = bones.slice( 0 );
  15307. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  15308. // use the supplied bone inverses or calculate the inverses
  15309. if ( boneInverses === undefined ) {
  15310. this.calculateInverses();
  15311. } else {
  15312. if ( this.bones.length === boneInverses.length ) {
  15313. this.boneInverses = boneInverses.slice( 0 );
  15314. } else {
  15315. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  15316. this.boneInverses = [];
  15317. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15318. this.boneInverses.push( new Matrix4() );
  15319. }
  15320. }
  15321. }
  15322. }
  15323. Object.assign( Skeleton.prototype, {
  15324. calculateInverses: function () {
  15325. this.boneInverses = [];
  15326. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15327. var inverse = new Matrix4();
  15328. if ( this.bones[ i ] ) {
  15329. inverse.getInverse( this.bones[ i ].matrixWorld );
  15330. }
  15331. this.boneInverses.push( inverse );
  15332. }
  15333. },
  15334. pose: function () {
  15335. var bone, i, il;
  15336. // recover the bind-time world matrices
  15337. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  15338. bone = this.bones[ i ];
  15339. if ( bone ) {
  15340. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  15341. }
  15342. }
  15343. // compute the local matrices, positions, rotations and scales
  15344. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  15345. bone = this.bones[ i ];
  15346. if ( bone ) {
  15347. if ( bone.parent && bone.parent.isBone ) {
  15348. bone.matrix.getInverse( bone.parent.matrixWorld );
  15349. bone.matrix.multiply( bone.matrixWorld );
  15350. } else {
  15351. bone.matrix.copy( bone.matrixWorld );
  15352. }
  15353. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  15354. }
  15355. }
  15356. },
  15357. update: ( function () {
  15358. var offsetMatrix = new Matrix4();
  15359. var identityMatrix = new Matrix4();
  15360. return function update() {
  15361. var bones = this.bones;
  15362. var boneInverses = this.boneInverses;
  15363. var boneMatrices = this.boneMatrices;
  15364. var boneTexture = this.boneTexture;
  15365. // flatten bone matrices to array
  15366. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  15367. // compute the offset between the current and the original transform
  15368. var matrix = bones[ i ] ? bones[ i ].matrixWorld : identityMatrix;
  15369. offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  15370. offsetMatrix.toArray( boneMatrices, i * 16 );
  15371. }
  15372. if ( boneTexture !== undefined ) {
  15373. boneTexture.needsUpdate = true;
  15374. }
  15375. };
  15376. } )(),
  15377. clone: function () {
  15378. return new Skeleton( this.bones, this.boneInverses );
  15379. },
  15380. getBoneByName: function ( name ) {
  15381. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15382. var bone = this.bones[ i ];
  15383. if ( bone.name === name ) {
  15384. return bone;
  15385. }
  15386. }
  15387. return undefined;
  15388. }
  15389. } );
  15390. /**
  15391. * @author mikael emtinger / http://gomo.se/
  15392. * @author alteredq / http://alteredqualia.com/
  15393. * @author ikerr / http://verold.com
  15394. */
  15395. function Bone() {
  15396. Object3D.call( this );
  15397. this.type = 'Bone';
  15398. }
  15399. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15400. constructor: Bone,
  15401. isBone: true
  15402. } );
  15403. /**
  15404. * @author mrdoob / http://mrdoob.com/
  15405. * @author alteredq / http://alteredqualia.com/
  15406. *
  15407. * parameters = {
  15408. * color: <hex>,
  15409. * opacity: <float>,
  15410. *
  15411. * linewidth: <float>,
  15412. * linecap: "round",
  15413. * linejoin: "round"
  15414. * }
  15415. */
  15416. function LineBasicMaterial( parameters ) {
  15417. Material.call( this );
  15418. this.type = 'LineBasicMaterial';
  15419. this.color = new Color( 0xffffff );
  15420. this.linewidth = 1;
  15421. this.linecap = 'round';
  15422. this.linejoin = 'round';
  15423. this.lights = false;
  15424. this.setValues( parameters );
  15425. }
  15426. LineBasicMaterial.prototype = Object.create( Material.prototype );
  15427. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  15428. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  15429. LineBasicMaterial.prototype.copy = function ( source ) {
  15430. Material.prototype.copy.call( this, source );
  15431. this.color.copy( source.color );
  15432. this.linewidth = source.linewidth;
  15433. this.linecap = source.linecap;
  15434. this.linejoin = source.linejoin;
  15435. return this;
  15436. };
  15437. /**
  15438. * @author mrdoob / http://mrdoob.com/
  15439. */
  15440. function Line( geometry, material, mode ) {
  15441. if ( mode === 1 ) {
  15442. console.error( 'THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.' );
  15443. }
  15444. Object3D.call( this );
  15445. this.type = 'Line';
  15446. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15447. this.material = material !== undefined ? material : new LineBasicMaterial( { color: Math.random() * 0xffffff } );
  15448. }
  15449. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15450. constructor: Line,
  15451. isLine: true,
  15452. computeLineDistances: ( function () {
  15453. var start = new Vector3();
  15454. var end = new Vector3();
  15455. return function computeLineDistances() {
  15456. var geometry = this.geometry;
  15457. if ( geometry.isBufferGeometry ) {
  15458. // we assume non-indexed geometry
  15459. if ( geometry.index === null ) {
  15460. var positionAttribute = geometry.attributes.position;
  15461. var lineDistances = [ 0 ];
  15462. for ( var i = 1, l = positionAttribute.count; i < l; i ++ ) {
  15463. start.fromBufferAttribute( positionAttribute, i - 1 );
  15464. end.fromBufferAttribute( positionAttribute, i );
  15465. lineDistances[ i ] = lineDistances[ i - 1 ];
  15466. lineDistances[ i ] += start.distanceTo( end );
  15467. }
  15468. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  15469. } else {
  15470. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  15471. }
  15472. } else if ( geometry.isGeometry ) {
  15473. var vertices = geometry.vertices;
  15474. var lineDistances = geometry.lineDistances;
  15475. lineDistances[ 0 ] = 0;
  15476. for ( var i = 1, l = vertices.length; i < l; i ++ ) {
  15477. lineDistances[ i ] = lineDistances[ i - 1 ];
  15478. lineDistances[ i ] += vertices[ i - 1 ].distanceTo( vertices[ i ] );
  15479. }
  15480. }
  15481. return this;
  15482. };
  15483. }() ),
  15484. raycast: ( function () {
  15485. var inverseMatrix = new Matrix4();
  15486. var ray = new Ray();
  15487. var sphere = new Sphere();
  15488. return function raycast( raycaster, intersects ) {
  15489. var precision = raycaster.linePrecision;
  15490. var geometry = this.geometry;
  15491. var matrixWorld = this.matrixWorld;
  15492. // Checking boundingSphere distance to ray
  15493. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15494. sphere.copy( geometry.boundingSphere );
  15495. sphere.applyMatrix4( matrixWorld );
  15496. sphere.radius += precision;
  15497. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  15498. //
  15499. inverseMatrix.getInverse( matrixWorld );
  15500. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  15501. var localPrecision = precision / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15502. var localPrecisionSq = localPrecision * localPrecision;
  15503. var vStart = new Vector3();
  15504. var vEnd = new Vector3();
  15505. var interSegment = new Vector3();
  15506. var interRay = new Vector3();
  15507. var step = ( this && this.isLineSegments ) ? 2 : 1;
  15508. if ( geometry.isBufferGeometry ) {
  15509. var index = geometry.index;
  15510. var attributes = geometry.attributes;
  15511. var positions = attributes.position.array;
  15512. if ( index !== null ) {
  15513. var indices = index.array;
  15514. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  15515. var a = indices[ i ];
  15516. var b = indices[ i + 1 ];
  15517. vStart.fromArray( positions, a * 3 );
  15518. vEnd.fromArray( positions, b * 3 );
  15519. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15520. if ( distSq > localPrecisionSq ) continue;
  15521. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15522. var distance = raycaster.ray.origin.distanceTo( interRay );
  15523. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15524. intersects.push( {
  15525. distance: distance,
  15526. // What do we want? intersection point on the ray or on the segment??
  15527. // point: raycaster.ray.at( distance ),
  15528. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15529. index: i,
  15530. face: null,
  15531. faceIndex: null,
  15532. object: this
  15533. } );
  15534. }
  15535. } else {
  15536. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  15537. vStart.fromArray( positions, 3 * i );
  15538. vEnd.fromArray( positions, 3 * i + 3 );
  15539. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15540. if ( distSq > localPrecisionSq ) continue;
  15541. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15542. var distance = raycaster.ray.origin.distanceTo( interRay );
  15543. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15544. intersects.push( {
  15545. distance: distance,
  15546. // What do we want? intersection point on the ray or on the segment??
  15547. // point: raycaster.ray.at( distance ),
  15548. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15549. index: i,
  15550. face: null,
  15551. faceIndex: null,
  15552. object: this
  15553. } );
  15554. }
  15555. }
  15556. } else if ( geometry.isGeometry ) {
  15557. var vertices = geometry.vertices;
  15558. var nbVertices = vertices.length;
  15559. for ( var i = 0; i < nbVertices - 1; i += step ) {
  15560. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  15561. if ( distSq > localPrecisionSq ) continue;
  15562. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15563. var distance = raycaster.ray.origin.distanceTo( interRay );
  15564. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15565. intersects.push( {
  15566. distance: distance,
  15567. // What do we want? intersection point on the ray or on the segment??
  15568. // point: raycaster.ray.at( distance ),
  15569. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15570. index: i,
  15571. face: null,
  15572. faceIndex: null,
  15573. object: this
  15574. } );
  15575. }
  15576. }
  15577. };
  15578. }() ),
  15579. copy: function ( source ) {
  15580. Object3D.prototype.copy.call( this, source );
  15581. this.geometry.copy( source.geometry );
  15582. this.material.copy( source.material );
  15583. return this;
  15584. },
  15585. clone: function () {
  15586. return new this.constructor().copy( this );
  15587. }
  15588. } );
  15589. /**
  15590. * @author mrdoob / http://mrdoob.com/
  15591. */
  15592. function LineSegments( geometry, material ) {
  15593. Line.call( this, geometry, material );
  15594. this.type = 'LineSegments';
  15595. }
  15596. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  15597. constructor: LineSegments,
  15598. isLineSegments: true,
  15599. computeLineDistances: ( function () {
  15600. var start = new Vector3();
  15601. var end = new Vector3();
  15602. return function computeLineDistances() {
  15603. var geometry = this.geometry;
  15604. if ( geometry.isBufferGeometry ) {
  15605. // we assume non-indexed geometry
  15606. if ( geometry.index === null ) {
  15607. var positionAttribute = geometry.attributes.position;
  15608. var lineDistances = [];
  15609. for ( var i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  15610. start.fromBufferAttribute( positionAttribute, i );
  15611. end.fromBufferAttribute( positionAttribute, i + 1 );
  15612. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  15613. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  15614. }
  15615. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  15616. } else {
  15617. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  15618. }
  15619. } else if ( geometry.isGeometry ) {
  15620. var vertices = geometry.vertices;
  15621. var lineDistances = geometry.lineDistances;
  15622. for ( var i = 0, l = vertices.length; i < l; i += 2 ) {
  15623. start.copy( vertices[ i ] );
  15624. end.copy( vertices[ i + 1 ] );
  15625. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  15626. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  15627. }
  15628. }
  15629. return this;
  15630. };
  15631. }() )
  15632. } );
  15633. /**
  15634. * @author mgreter / http://github.com/mgreter
  15635. */
  15636. function LineLoop( geometry, material ) {
  15637. Line.call( this, geometry, material );
  15638. this.type = 'LineLoop';
  15639. }
  15640. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  15641. constructor: LineLoop,
  15642. isLineLoop: true,
  15643. } );
  15644. /**
  15645. * @author mrdoob / http://mrdoob.com/
  15646. * @author alteredq / http://alteredqualia.com/
  15647. *
  15648. * parameters = {
  15649. * color: <hex>,
  15650. * opacity: <float>,
  15651. * map: new THREE.Texture( <Image> ),
  15652. *
  15653. * size: <float>,
  15654. * sizeAttenuation: <bool>
  15655. *
  15656. * morphTargets: <bool>
  15657. * }
  15658. */
  15659. function PointsMaterial( parameters ) {
  15660. Material.call( this );
  15661. this.type = 'PointsMaterial';
  15662. this.color = new Color( 0xffffff );
  15663. this.map = null;
  15664. this.size = 1;
  15665. this.sizeAttenuation = true;
  15666. this.morphTargets = false;
  15667. this.lights = false;
  15668. this.setValues( parameters );
  15669. }
  15670. PointsMaterial.prototype = Object.create( Material.prototype );
  15671. PointsMaterial.prototype.constructor = PointsMaterial;
  15672. PointsMaterial.prototype.isPointsMaterial = true;
  15673. PointsMaterial.prototype.copy = function ( source ) {
  15674. Material.prototype.copy.call( this, source );
  15675. this.color.copy( source.color );
  15676. this.map = source.map;
  15677. this.size = source.size;
  15678. this.sizeAttenuation = source.sizeAttenuation;
  15679. this.morphTargets = source.morphTargets;
  15680. return this;
  15681. };
  15682. /**
  15683. * @author alteredq / http://alteredqualia.com/
  15684. */
  15685. function Points( geometry, material ) {
  15686. Object3D.call( this );
  15687. this.type = 'Points';
  15688. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15689. this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
  15690. }
  15691. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15692. constructor: Points,
  15693. isPoints: true,
  15694. raycast: ( function () {
  15695. var inverseMatrix = new Matrix4();
  15696. var ray = new Ray();
  15697. var sphere = new Sphere();
  15698. return function raycast( raycaster, intersects ) {
  15699. var object = this;
  15700. var geometry = this.geometry;
  15701. var matrixWorld = this.matrixWorld;
  15702. var threshold = raycaster.params.Points.threshold;
  15703. // Checking boundingSphere distance to ray
  15704. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15705. sphere.copy( geometry.boundingSphere );
  15706. sphere.applyMatrix4( matrixWorld );
  15707. sphere.radius += threshold;
  15708. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  15709. //
  15710. inverseMatrix.getInverse( matrixWorld );
  15711. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  15712. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15713. var localThresholdSq = localThreshold * localThreshold;
  15714. var position = new Vector3();
  15715. var intersectPoint = new Vector3();
  15716. function testPoint( point, index ) {
  15717. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  15718. if ( rayPointDistanceSq < localThresholdSq ) {
  15719. ray.closestPointToPoint( point, intersectPoint );
  15720. intersectPoint.applyMatrix4( matrixWorld );
  15721. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  15722. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15723. intersects.push( {
  15724. distance: distance,
  15725. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  15726. point: intersectPoint.clone(),
  15727. index: index,
  15728. face: null,
  15729. object: object
  15730. } );
  15731. }
  15732. }
  15733. if ( geometry.isBufferGeometry ) {
  15734. var index = geometry.index;
  15735. var attributes = geometry.attributes;
  15736. var positions = attributes.position.array;
  15737. if ( index !== null ) {
  15738. var indices = index.array;
  15739. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  15740. var a = indices[ i ];
  15741. position.fromArray( positions, a * 3 );
  15742. testPoint( position, a );
  15743. }
  15744. } else {
  15745. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  15746. position.fromArray( positions, i * 3 );
  15747. testPoint( position, i );
  15748. }
  15749. }
  15750. } else {
  15751. var vertices = geometry.vertices;
  15752. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  15753. testPoint( vertices[ i ], i );
  15754. }
  15755. }
  15756. };
  15757. }() ),
  15758. clone: function () {
  15759. return new this.constructor( this.geometry, this.material ).copy( this );
  15760. }
  15761. } );
  15762. /**
  15763. * @author mrdoob / http://mrdoob.com/
  15764. */
  15765. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  15766. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15767. this.format = format !== undefined ? format : RGBFormat;
  15768. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  15769. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  15770. this.generateMipmaps = false;
  15771. }
  15772. VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
  15773. constructor: VideoTexture,
  15774. isVideoTexture: true,
  15775. update: function () {
  15776. var video = this.image;
  15777. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  15778. this.needsUpdate = true;
  15779. }
  15780. }
  15781. } );
  15782. /**
  15783. * @author alteredq / http://alteredqualia.com/
  15784. */
  15785. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  15786. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  15787. this.image = { width: width, height: height };
  15788. this.mipmaps = mipmaps;
  15789. // no flipping for cube textures
  15790. // (also flipping doesn't work for compressed textures )
  15791. this.flipY = false;
  15792. // can't generate mipmaps for compressed textures
  15793. // mips must be embedded in DDS files
  15794. this.generateMipmaps = false;
  15795. }
  15796. CompressedTexture.prototype = Object.create( Texture.prototype );
  15797. CompressedTexture.prototype.constructor = CompressedTexture;
  15798. CompressedTexture.prototype.isCompressedTexture = true;
  15799. /**
  15800. * @author mrdoob / http://mrdoob.com/
  15801. */
  15802. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  15803. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15804. this.needsUpdate = true;
  15805. }
  15806. CanvasTexture.prototype = Object.create( Texture.prototype );
  15807. CanvasTexture.prototype.constructor = CanvasTexture;
  15808. CanvasTexture.prototype.isCanvasTexture = true;
  15809. /**
  15810. * @author Matt DesLauriers / @mattdesl
  15811. * @author atix / arthursilber.de
  15812. */
  15813. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  15814. format = format !== undefined ? format : DepthFormat;
  15815. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  15816. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  15817. }
  15818. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  15819. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  15820. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15821. this.image = { width: width, height: height };
  15822. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  15823. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  15824. this.flipY = false;
  15825. this.generateMipmaps = false;
  15826. }
  15827. DepthTexture.prototype = Object.create( Texture.prototype );
  15828. DepthTexture.prototype.constructor = DepthTexture;
  15829. DepthTexture.prototype.isDepthTexture = true;
  15830. /**
  15831. * @author mrdoob / http://mrdoob.com/
  15832. * @author Mugen87 / https://github.com/Mugen87
  15833. */
  15834. function WireframeGeometry( geometry ) {
  15835. BufferGeometry.call( this );
  15836. this.type = 'WireframeGeometry';
  15837. // buffer
  15838. var vertices = [];
  15839. // helper variables
  15840. var i, j, l, o, ol;
  15841. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  15842. var key, keys = [ 'a', 'b', 'c' ];
  15843. var vertex;
  15844. // different logic for Geometry and BufferGeometry
  15845. if ( geometry && geometry.isGeometry ) {
  15846. // create a data structure that contains all edges without duplicates
  15847. var faces = geometry.faces;
  15848. for ( i = 0, l = faces.length; i < l; i ++ ) {
  15849. var face = faces[ i ];
  15850. for ( j = 0; j < 3; j ++ ) {
  15851. edge1 = face[ keys[ j ] ];
  15852. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  15853. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  15854. edge[ 1 ] = Math.max( edge1, edge2 );
  15855. key = edge[ 0 ] + ',' + edge[ 1 ];
  15856. if ( edges[ key ] === undefined ) {
  15857. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  15858. }
  15859. }
  15860. }
  15861. // generate vertices
  15862. for ( key in edges ) {
  15863. e = edges[ key ];
  15864. vertex = geometry.vertices[ e.index1 ];
  15865. vertices.push( vertex.x, vertex.y, vertex.z );
  15866. vertex = geometry.vertices[ e.index2 ];
  15867. vertices.push( vertex.x, vertex.y, vertex.z );
  15868. }
  15869. } else if ( geometry && geometry.isBufferGeometry ) {
  15870. var position, indices, groups;
  15871. var group, start, count;
  15872. var index1, index2;
  15873. vertex = new Vector3();
  15874. if ( geometry.index !== null ) {
  15875. // indexed BufferGeometry
  15876. position = geometry.attributes.position;
  15877. indices = geometry.index;
  15878. groups = geometry.groups;
  15879. if ( groups.length === 0 ) {
  15880. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  15881. }
  15882. // create a data structure that contains all eges without duplicates
  15883. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  15884. group = groups[ o ];
  15885. start = group.start;
  15886. count = group.count;
  15887. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  15888. for ( j = 0; j < 3; j ++ ) {
  15889. edge1 = indices.getX( i + j );
  15890. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  15891. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  15892. edge[ 1 ] = Math.max( edge1, edge2 );
  15893. key = edge[ 0 ] + ',' + edge[ 1 ];
  15894. if ( edges[ key ] === undefined ) {
  15895. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  15896. }
  15897. }
  15898. }
  15899. }
  15900. // generate vertices
  15901. for ( key in edges ) {
  15902. e = edges[ key ];
  15903. vertex.fromBufferAttribute( position, e.index1 );
  15904. vertices.push( vertex.x, vertex.y, vertex.z );
  15905. vertex.fromBufferAttribute( position, e.index2 );
  15906. vertices.push( vertex.x, vertex.y, vertex.z );
  15907. }
  15908. } else {
  15909. // non-indexed BufferGeometry
  15910. position = geometry.attributes.position;
  15911. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  15912. for ( j = 0; j < 3; j ++ ) {
  15913. // three edges per triangle, an edge is represented as (index1, index2)
  15914. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  15915. index1 = 3 * i + j;
  15916. vertex.fromBufferAttribute( position, index1 );
  15917. vertices.push( vertex.x, vertex.y, vertex.z );
  15918. index2 = 3 * i + ( ( j + 1 ) % 3 );
  15919. vertex.fromBufferAttribute( position, index2 );
  15920. vertices.push( vertex.x, vertex.y, vertex.z );
  15921. }
  15922. }
  15923. }
  15924. }
  15925. // build geometry
  15926. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  15927. }
  15928. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  15929. WireframeGeometry.prototype.constructor = WireframeGeometry;
  15930. /**
  15931. * @author zz85 / https://github.com/zz85
  15932. * @author Mugen87 / https://github.com/Mugen87
  15933. *
  15934. * Parametric Surfaces Geometry
  15935. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  15936. */
  15937. // ParametricGeometry
  15938. function ParametricGeometry( func, slices, stacks ) {
  15939. Geometry.call( this );
  15940. this.type = 'ParametricGeometry';
  15941. this.parameters = {
  15942. func: func,
  15943. slices: slices,
  15944. stacks: stacks
  15945. };
  15946. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  15947. this.mergeVertices();
  15948. }
  15949. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  15950. ParametricGeometry.prototype.constructor = ParametricGeometry;
  15951. // ParametricBufferGeometry
  15952. function ParametricBufferGeometry( func, slices, stacks ) {
  15953. BufferGeometry.call( this );
  15954. this.type = 'ParametricBufferGeometry';
  15955. this.parameters = {
  15956. func: func,
  15957. slices: slices,
  15958. stacks: stacks
  15959. };
  15960. // buffers
  15961. var indices = [];
  15962. var vertices = [];
  15963. var normals = [];
  15964. var uvs = [];
  15965. var EPS = 0.00001;
  15966. var normal = new Vector3();
  15967. var p0 = new Vector3(), p1 = new Vector3();
  15968. var pu = new Vector3(), pv = new Vector3();
  15969. var i, j;
  15970. if ( func.length < 3 ) {
  15971. console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' );
  15972. }
  15973. // generate vertices, normals and uvs
  15974. var sliceCount = slices + 1;
  15975. for ( i = 0; i <= stacks; i ++ ) {
  15976. var v = i / stacks;
  15977. for ( j = 0; j <= slices; j ++ ) {
  15978. var u = j / slices;
  15979. // vertex
  15980. func( u, v, p0 );
  15981. vertices.push( p0.x, p0.y, p0.z );
  15982. // normal
  15983. // approximate tangent vectors via finite differences
  15984. if ( u - EPS >= 0 ) {
  15985. func( u - EPS, v, p1 );
  15986. pu.subVectors( p0, p1 );
  15987. } else {
  15988. func( u + EPS, v, p1 );
  15989. pu.subVectors( p1, p0 );
  15990. }
  15991. if ( v - EPS >= 0 ) {
  15992. func( u, v - EPS, p1 );
  15993. pv.subVectors( p0, p1 );
  15994. } else {
  15995. func( u, v + EPS, p1 );
  15996. pv.subVectors( p1, p0 );
  15997. }
  15998. // cross product of tangent vectors returns surface normal
  15999. normal.crossVectors( pu, pv ).normalize();
  16000. normals.push( normal.x, normal.y, normal.z );
  16001. // uv
  16002. uvs.push( u, v );
  16003. }
  16004. }
  16005. // generate indices
  16006. for ( i = 0; i < stacks; i ++ ) {
  16007. for ( j = 0; j < slices; j ++ ) {
  16008. var a = i * sliceCount + j;
  16009. var b = i * sliceCount + j + 1;
  16010. var c = ( i + 1 ) * sliceCount + j + 1;
  16011. var d = ( i + 1 ) * sliceCount + j;
  16012. // faces one and two
  16013. indices.push( a, b, d );
  16014. indices.push( b, c, d );
  16015. }
  16016. }
  16017. // build geometry
  16018. this.setIndex( indices );
  16019. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16020. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16021. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16022. }
  16023. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16024. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  16025. /**
  16026. * @author clockworkgeek / https://github.com/clockworkgeek
  16027. * @author timothypratley / https://github.com/timothypratley
  16028. * @author WestLangley / http://github.com/WestLangley
  16029. * @author Mugen87 / https://github.com/Mugen87
  16030. */
  16031. // PolyhedronGeometry
  16032. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  16033. Geometry.call( this );
  16034. this.type = 'PolyhedronGeometry';
  16035. this.parameters = {
  16036. vertices: vertices,
  16037. indices: indices,
  16038. radius: radius,
  16039. detail: detail
  16040. };
  16041. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  16042. this.mergeVertices();
  16043. }
  16044. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  16045. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  16046. // PolyhedronBufferGeometry
  16047. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  16048. BufferGeometry.call( this );
  16049. this.type = 'PolyhedronBufferGeometry';
  16050. this.parameters = {
  16051. vertices: vertices,
  16052. indices: indices,
  16053. radius: radius,
  16054. detail: detail
  16055. };
  16056. radius = radius || 1;
  16057. detail = detail || 0;
  16058. // default buffer data
  16059. var vertexBuffer = [];
  16060. var uvBuffer = [];
  16061. // the subdivision creates the vertex buffer data
  16062. subdivide( detail );
  16063. // all vertices should lie on a conceptual sphere with a given radius
  16064. appplyRadius( radius );
  16065. // finally, create the uv data
  16066. generateUVs();
  16067. // build non-indexed geometry
  16068. this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  16069. this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  16070. this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  16071. if ( detail === 0 ) {
  16072. this.computeVertexNormals(); // flat normals
  16073. } else {
  16074. this.normalizeNormals(); // smooth normals
  16075. }
  16076. // helper functions
  16077. function subdivide( detail ) {
  16078. var a = new Vector3();
  16079. var b = new Vector3();
  16080. var c = new Vector3();
  16081. // iterate over all faces and apply a subdivison with the given detail value
  16082. for ( var i = 0; i < indices.length; i += 3 ) {
  16083. // get the vertices of the face
  16084. getVertexByIndex( indices[ i + 0 ], a );
  16085. getVertexByIndex( indices[ i + 1 ], b );
  16086. getVertexByIndex( indices[ i + 2 ], c );
  16087. // perform subdivision
  16088. subdivideFace( a, b, c, detail );
  16089. }
  16090. }
  16091. function subdivideFace( a, b, c, detail ) {
  16092. var cols = Math.pow( 2, detail );
  16093. // we use this multidimensional array as a data structure for creating the subdivision
  16094. var v = [];
  16095. var i, j;
  16096. // construct all of the vertices for this subdivision
  16097. for ( i = 0; i <= cols; i ++ ) {
  16098. v[ i ] = [];
  16099. var aj = a.clone().lerp( c, i / cols );
  16100. var bj = b.clone().lerp( c, i / cols );
  16101. var rows = cols - i;
  16102. for ( j = 0; j <= rows; j ++ ) {
  16103. if ( j === 0 && i === cols ) {
  16104. v[ i ][ j ] = aj;
  16105. } else {
  16106. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  16107. }
  16108. }
  16109. }
  16110. // construct all of the faces
  16111. for ( i = 0; i < cols; i ++ ) {
  16112. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  16113. var k = Math.floor( j / 2 );
  16114. if ( j % 2 === 0 ) {
  16115. pushVertex( v[ i ][ k + 1 ] );
  16116. pushVertex( v[ i + 1 ][ k ] );
  16117. pushVertex( v[ i ][ k ] );
  16118. } else {
  16119. pushVertex( v[ i ][ k + 1 ] );
  16120. pushVertex( v[ i + 1 ][ k + 1 ] );
  16121. pushVertex( v[ i + 1 ][ k ] );
  16122. }
  16123. }
  16124. }
  16125. }
  16126. function appplyRadius( radius ) {
  16127. var vertex = new Vector3();
  16128. // iterate over the entire buffer and apply the radius to each vertex
  16129. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16130. vertex.x = vertexBuffer[ i + 0 ];
  16131. vertex.y = vertexBuffer[ i + 1 ];
  16132. vertex.z = vertexBuffer[ i + 2 ];
  16133. vertex.normalize().multiplyScalar( radius );
  16134. vertexBuffer[ i + 0 ] = vertex.x;
  16135. vertexBuffer[ i + 1 ] = vertex.y;
  16136. vertexBuffer[ i + 2 ] = vertex.z;
  16137. }
  16138. }
  16139. function generateUVs() {
  16140. var vertex = new Vector3();
  16141. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16142. vertex.x = vertexBuffer[ i + 0 ];
  16143. vertex.y = vertexBuffer[ i + 1 ];
  16144. vertex.z = vertexBuffer[ i + 2 ];
  16145. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  16146. var v = inclination( vertex ) / Math.PI + 0.5;
  16147. uvBuffer.push( u, 1 - v );
  16148. }
  16149. correctUVs();
  16150. correctSeam();
  16151. }
  16152. function correctSeam() {
  16153. // handle case when face straddles the seam, see #3269
  16154. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  16155. // uv data of a single face
  16156. var x0 = uvBuffer[ i + 0 ];
  16157. var x1 = uvBuffer[ i + 2 ];
  16158. var x2 = uvBuffer[ i + 4 ];
  16159. var max = Math.max( x0, x1, x2 );
  16160. var min = Math.min( x0, x1, x2 );
  16161. // 0.9 is somewhat arbitrary
  16162. if ( max > 0.9 && min < 0.1 ) {
  16163. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  16164. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  16165. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  16166. }
  16167. }
  16168. }
  16169. function pushVertex( vertex ) {
  16170. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  16171. }
  16172. function getVertexByIndex( index, vertex ) {
  16173. var stride = index * 3;
  16174. vertex.x = vertices[ stride + 0 ];
  16175. vertex.y = vertices[ stride + 1 ];
  16176. vertex.z = vertices[ stride + 2 ];
  16177. }
  16178. function correctUVs() {
  16179. var a = new Vector3();
  16180. var b = new Vector3();
  16181. var c = new Vector3();
  16182. var centroid = new Vector3();
  16183. var uvA = new Vector2();
  16184. var uvB = new Vector2();
  16185. var uvC = new Vector2();
  16186. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  16187. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  16188. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  16189. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  16190. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  16191. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  16192. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  16193. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  16194. var azi = azimuth( centroid );
  16195. correctUV( uvA, j + 0, a, azi );
  16196. correctUV( uvB, j + 2, b, azi );
  16197. correctUV( uvC, j + 4, c, azi );
  16198. }
  16199. }
  16200. function correctUV( uv, stride, vector, azimuth ) {
  16201. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  16202. uvBuffer[ stride ] = uv.x - 1;
  16203. }
  16204. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  16205. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  16206. }
  16207. }
  16208. // Angle around the Y axis, counter-clockwise when looking from above.
  16209. function azimuth( vector ) {
  16210. return Math.atan2( vector.z, - vector.x );
  16211. }
  16212. // Angle above the XZ plane.
  16213. function inclination( vector ) {
  16214. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  16215. }
  16216. }
  16217. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16218. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  16219. /**
  16220. * @author timothypratley / https://github.com/timothypratley
  16221. * @author Mugen87 / https://github.com/Mugen87
  16222. */
  16223. // TetrahedronGeometry
  16224. function TetrahedronGeometry( radius, detail ) {
  16225. Geometry.call( this );
  16226. this.type = 'TetrahedronGeometry';
  16227. this.parameters = {
  16228. radius: radius,
  16229. detail: detail
  16230. };
  16231. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  16232. this.mergeVertices();
  16233. }
  16234. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  16235. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  16236. // TetrahedronBufferGeometry
  16237. function TetrahedronBufferGeometry( radius, detail ) {
  16238. var vertices = [
  16239. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  16240. ];
  16241. var indices = [
  16242. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  16243. ];
  16244. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16245. this.type = 'TetrahedronBufferGeometry';
  16246. this.parameters = {
  16247. radius: radius,
  16248. detail: detail
  16249. };
  16250. }
  16251. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16252. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  16253. /**
  16254. * @author timothypratley / https://github.com/timothypratley
  16255. * @author Mugen87 / https://github.com/Mugen87
  16256. */
  16257. // OctahedronGeometry
  16258. function OctahedronGeometry( radius, detail ) {
  16259. Geometry.call( this );
  16260. this.type = 'OctahedronGeometry';
  16261. this.parameters = {
  16262. radius: radius,
  16263. detail: detail
  16264. };
  16265. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  16266. this.mergeVertices();
  16267. }
  16268. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  16269. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  16270. // OctahedronBufferGeometry
  16271. function OctahedronBufferGeometry( radius, detail ) {
  16272. var vertices = [
  16273. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  16274. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  16275. ];
  16276. var indices = [
  16277. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  16278. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  16279. 1, 3, 4, 1, 4, 2
  16280. ];
  16281. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16282. this.type = 'OctahedronBufferGeometry';
  16283. this.parameters = {
  16284. radius: radius,
  16285. detail: detail
  16286. };
  16287. }
  16288. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16289. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  16290. /**
  16291. * @author timothypratley / https://github.com/timothypratley
  16292. * @author Mugen87 / https://github.com/Mugen87
  16293. */
  16294. // IcosahedronGeometry
  16295. function IcosahedronGeometry( radius, detail ) {
  16296. Geometry.call( this );
  16297. this.type = 'IcosahedronGeometry';
  16298. this.parameters = {
  16299. radius: radius,
  16300. detail: detail
  16301. };
  16302. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  16303. this.mergeVertices();
  16304. }
  16305. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  16306. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  16307. // IcosahedronBufferGeometry
  16308. function IcosahedronBufferGeometry( radius, detail ) {
  16309. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16310. var vertices = [
  16311. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  16312. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  16313. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  16314. ];
  16315. var indices = [
  16316. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  16317. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  16318. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  16319. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  16320. ];
  16321. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16322. this.type = 'IcosahedronBufferGeometry';
  16323. this.parameters = {
  16324. radius: radius,
  16325. detail: detail
  16326. };
  16327. }
  16328. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16329. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  16330. /**
  16331. * @author Abe Pazos / https://hamoid.com
  16332. * @author Mugen87 / https://github.com/Mugen87
  16333. */
  16334. // DodecahedronGeometry
  16335. function DodecahedronGeometry( radius, detail ) {
  16336. Geometry.call( this );
  16337. this.type = 'DodecahedronGeometry';
  16338. this.parameters = {
  16339. radius: radius,
  16340. detail: detail
  16341. };
  16342. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  16343. this.mergeVertices();
  16344. }
  16345. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  16346. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  16347. // DodecahedronBufferGeometry
  16348. function DodecahedronBufferGeometry( radius, detail ) {
  16349. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16350. var r = 1 / t;
  16351. var vertices = [
  16352. // (±1, ±1, ±1)
  16353. - 1, - 1, - 1, - 1, - 1, 1,
  16354. - 1, 1, - 1, - 1, 1, 1,
  16355. 1, - 1, - 1, 1, - 1, 1,
  16356. 1, 1, - 1, 1, 1, 1,
  16357. // (0, ±1/φ, ±φ)
  16358. 0, - r, - t, 0, - r, t,
  16359. 0, r, - t, 0, r, t,
  16360. // (±1/φ, ±φ, 0)
  16361. - r, - t, 0, - r, t, 0,
  16362. r, - t, 0, r, t, 0,
  16363. // (±φ, 0, ±1/φ)
  16364. - t, 0, - r, t, 0, - r,
  16365. - t, 0, r, t, 0, r
  16366. ];
  16367. var indices = [
  16368. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  16369. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  16370. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  16371. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  16372. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  16373. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  16374. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  16375. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  16376. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  16377. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  16378. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  16379. 1, 12, 14, 1, 14, 5, 1, 5, 9
  16380. ];
  16381. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16382. this.type = 'DodecahedronBufferGeometry';
  16383. this.parameters = {
  16384. radius: radius,
  16385. detail: detail
  16386. };
  16387. }
  16388. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16389. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  16390. /**
  16391. * @author oosmoxiecode / https://github.com/oosmoxiecode
  16392. * @author WestLangley / https://github.com/WestLangley
  16393. * @author zz85 / https://github.com/zz85
  16394. * @author miningold / https://github.com/miningold
  16395. * @author jonobr1 / https://github.com/jonobr1
  16396. * @author Mugen87 / https://github.com/Mugen87
  16397. *
  16398. */
  16399. // TubeGeometry
  16400. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  16401. Geometry.call( this );
  16402. this.type = 'TubeGeometry';
  16403. this.parameters = {
  16404. path: path,
  16405. tubularSegments: tubularSegments,
  16406. radius: radius,
  16407. radialSegments: radialSegments,
  16408. closed: closed
  16409. };
  16410. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  16411. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  16412. // expose internals
  16413. this.tangents = bufferGeometry.tangents;
  16414. this.normals = bufferGeometry.normals;
  16415. this.binormals = bufferGeometry.binormals;
  16416. // create geometry
  16417. this.fromBufferGeometry( bufferGeometry );
  16418. this.mergeVertices();
  16419. }
  16420. TubeGeometry.prototype = Object.create( Geometry.prototype );
  16421. TubeGeometry.prototype.constructor = TubeGeometry;
  16422. // TubeBufferGeometry
  16423. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  16424. BufferGeometry.call( this );
  16425. this.type = 'TubeBufferGeometry';
  16426. this.parameters = {
  16427. path: path,
  16428. tubularSegments: tubularSegments,
  16429. radius: radius,
  16430. radialSegments: radialSegments,
  16431. closed: closed
  16432. };
  16433. tubularSegments = tubularSegments || 64;
  16434. radius = radius || 1;
  16435. radialSegments = radialSegments || 8;
  16436. closed = closed || false;
  16437. var frames = path.computeFrenetFrames( tubularSegments, closed );
  16438. // expose internals
  16439. this.tangents = frames.tangents;
  16440. this.normals = frames.normals;
  16441. this.binormals = frames.binormals;
  16442. // helper variables
  16443. var vertex = new Vector3();
  16444. var normal = new Vector3();
  16445. var uv = new Vector2();
  16446. var P = new Vector3();
  16447. var i, j;
  16448. // buffer
  16449. var vertices = [];
  16450. var normals = [];
  16451. var uvs = [];
  16452. var indices = [];
  16453. // create buffer data
  16454. generateBufferData();
  16455. // build geometry
  16456. this.setIndex( indices );
  16457. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16458. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16459. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16460. // functions
  16461. function generateBufferData() {
  16462. for ( i = 0; i < tubularSegments; i ++ ) {
  16463. generateSegment( i );
  16464. }
  16465. // if the geometry is not closed, generate the last row of vertices and normals
  16466. // at the regular position on the given path
  16467. //
  16468. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  16469. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  16470. // uvs are generated in a separate function.
  16471. // this makes it easy compute correct values for closed geometries
  16472. generateUVs();
  16473. // finally create faces
  16474. generateIndices();
  16475. }
  16476. function generateSegment( i ) {
  16477. // we use getPointAt to sample evenly distributed points from the given path
  16478. P = path.getPointAt( i / tubularSegments, P );
  16479. // retrieve corresponding normal and binormal
  16480. var N = frames.normals[ i ];
  16481. var B = frames.binormals[ i ];
  16482. // generate normals and vertices for the current segment
  16483. for ( j = 0; j <= radialSegments; j ++ ) {
  16484. var v = j / radialSegments * Math.PI * 2;
  16485. var sin = Math.sin( v );
  16486. var cos = - Math.cos( v );
  16487. // normal
  16488. normal.x = ( cos * N.x + sin * B.x );
  16489. normal.y = ( cos * N.y + sin * B.y );
  16490. normal.z = ( cos * N.z + sin * B.z );
  16491. normal.normalize();
  16492. normals.push( normal.x, normal.y, normal.z );
  16493. // vertex
  16494. vertex.x = P.x + radius * normal.x;
  16495. vertex.y = P.y + radius * normal.y;
  16496. vertex.z = P.z + radius * normal.z;
  16497. vertices.push( vertex.x, vertex.y, vertex.z );
  16498. }
  16499. }
  16500. function generateIndices() {
  16501. for ( j = 1; j <= tubularSegments; j ++ ) {
  16502. for ( i = 1; i <= radialSegments; i ++ ) {
  16503. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  16504. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  16505. var c = ( radialSegments + 1 ) * j + i;
  16506. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  16507. // faces
  16508. indices.push( a, b, d );
  16509. indices.push( b, c, d );
  16510. }
  16511. }
  16512. }
  16513. function generateUVs() {
  16514. for ( i = 0; i <= tubularSegments; i ++ ) {
  16515. for ( j = 0; j <= radialSegments; j ++ ) {
  16516. uv.x = i / tubularSegments;
  16517. uv.y = j / radialSegments;
  16518. uvs.push( uv.x, uv.y );
  16519. }
  16520. }
  16521. }
  16522. }
  16523. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16524. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  16525. /**
  16526. * @author oosmoxiecode
  16527. * @author Mugen87 / https://github.com/Mugen87
  16528. *
  16529. * based on http://www.blackpawn.com/texts/pqtorus/
  16530. */
  16531. // TorusKnotGeometry
  16532. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  16533. Geometry.call( this );
  16534. this.type = 'TorusKnotGeometry';
  16535. this.parameters = {
  16536. radius: radius,
  16537. tube: tube,
  16538. tubularSegments: tubularSegments,
  16539. radialSegments: radialSegments,
  16540. p: p,
  16541. q: q
  16542. };
  16543. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  16544. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  16545. this.mergeVertices();
  16546. }
  16547. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  16548. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  16549. // TorusKnotBufferGeometry
  16550. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  16551. BufferGeometry.call( this );
  16552. this.type = 'TorusKnotBufferGeometry';
  16553. this.parameters = {
  16554. radius: radius,
  16555. tube: tube,
  16556. tubularSegments: tubularSegments,
  16557. radialSegments: radialSegments,
  16558. p: p,
  16559. q: q
  16560. };
  16561. radius = radius || 1;
  16562. tube = tube || 0.4;
  16563. tubularSegments = Math.floor( tubularSegments ) || 64;
  16564. radialSegments = Math.floor( radialSegments ) || 8;
  16565. p = p || 2;
  16566. q = q || 3;
  16567. // buffers
  16568. var indices = [];
  16569. var vertices = [];
  16570. var normals = [];
  16571. var uvs = [];
  16572. // helper variables
  16573. var i, j;
  16574. var vertex = new Vector3();
  16575. var normal = new Vector3();
  16576. var P1 = new Vector3();
  16577. var P2 = new Vector3();
  16578. var B = new Vector3();
  16579. var T = new Vector3();
  16580. var N = new Vector3();
  16581. // generate vertices, normals and uvs
  16582. for ( i = 0; i <= tubularSegments; ++ i ) {
  16583. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  16584. var u = i / tubularSegments * p * Math.PI * 2;
  16585. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  16586. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  16587. calculatePositionOnCurve( u, p, q, radius, P1 );
  16588. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  16589. // calculate orthonormal basis
  16590. T.subVectors( P2, P1 );
  16591. N.addVectors( P2, P1 );
  16592. B.crossVectors( T, N );
  16593. N.crossVectors( B, T );
  16594. // normalize B, N. T can be ignored, we don't use it
  16595. B.normalize();
  16596. N.normalize();
  16597. for ( j = 0; j <= radialSegments; ++ j ) {
  16598. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  16599. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  16600. var v = j / radialSegments * Math.PI * 2;
  16601. var cx = - tube * Math.cos( v );
  16602. var cy = tube * Math.sin( v );
  16603. // now calculate the final vertex position.
  16604. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  16605. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  16606. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  16607. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  16608. vertices.push( vertex.x, vertex.y, vertex.z );
  16609. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  16610. normal.subVectors( vertex, P1 ).normalize();
  16611. normals.push( normal.x, normal.y, normal.z );
  16612. // uv
  16613. uvs.push( i / tubularSegments );
  16614. uvs.push( j / radialSegments );
  16615. }
  16616. }
  16617. // generate indices
  16618. for ( j = 1; j <= tubularSegments; j ++ ) {
  16619. for ( i = 1; i <= radialSegments; i ++ ) {
  16620. // indices
  16621. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  16622. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  16623. var c = ( radialSegments + 1 ) * j + i;
  16624. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  16625. // faces
  16626. indices.push( a, b, d );
  16627. indices.push( b, c, d );
  16628. }
  16629. }
  16630. // build geometry
  16631. this.setIndex( indices );
  16632. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16633. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16634. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16635. // this function calculates the current position on the torus curve
  16636. function calculatePositionOnCurve( u, p, q, radius, position ) {
  16637. var cu = Math.cos( u );
  16638. var su = Math.sin( u );
  16639. var quOverP = q / p * u;
  16640. var cs = Math.cos( quOverP );
  16641. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  16642. position.y = radius * ( 2 + cs ) * su * 0.5;
  16643. position.z = radius * Math.sin( quOverP ) * 0.5;
  16644. }
  16645. }
  16646. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16647. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  16648. /**
  16649. * @author oosmoxiecode
  16650. * @author mrdoob / http://mrdoob.com/
  16651. * @author Mugen87 / https://github.com/Mugen87
  16652. */
  16653. // TorusGeometry
  16654. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  16655. Geometry.call( this );
  16656. this.type = 'TorusGeometry';
  16657. this.parameters = {
  16658. radius: radius,
  16659. tube: tube,
  16660. radialSegments: radialSegments,
  16661. tubularSegments: tubularSegments,
  16662. arc: arc
  16663. };
  16664. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  16665. this.mergeVertices();
  16666. }
  16667. TorusGeometry.prototype = Object.create( Geometry.prototype );
  16668. TorusGeometry.prototype.constructor = TorusGeometry;
  16669. // TorusBufferGeometry
  16670. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  16671. BufferGeometry.call( this );
  16672. this.type = 'TorusBufferGeometry';
  16673. this.parameters = {
  16674. radius: radius,
  16675. tube: tube,
  16676. radialSegments: radialSegments,
  16677. tubularSegments: tubularSegments,
  16678. arc: arc
  16679. };
  16680. radius = radius || 1;
  16681. tube = tube || 0.4;
  16682. radialSegments = Math.floor( radialSegments ) || 8;
  16683. tubularSegments = Math.floor( tubularSegments ) || 6;
  16684. arc = arc || Math.PI * 2;
  16685. // buffers
  16686. var indices = [];
  16687. var vertices = [];
  16688. var normals = [];
  16689. var uvs = [];
  16690. // helper variables
  16691. var center = new Vector3();
  16692. var vertex = new Vector3();
  16693. var normal = new Vector3();
  16694. var j, i;
  16695. // generate vertices, normals and uvs
  16696. for ( j = 0; j <= radialSegments; j ++ ) {
  16697. for ( i = 0; i <= tubularSegments; i ++ ) {
  16698. var u = i / tubularSegments * arc;
  16699. var v = j / radialSegments * Math.PI * 2;
  16700. // vertex
  16701. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  16702. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  16703. vertex.z = tube * Math.sin( v );
  16704. vertices.push( vertex.x, vertex.y, vertex.z );
  16705. // normal
  16706. center.x = radius * Math.cos( u );
  16707. center.y = radius * Math.sin( u );
  16708. normal.subVectors( vertex, center ).normalize();
  16709. normals.push( normal.x, normal.y, normal.z );
  16710. // uv
  16711. uvs.push( i / tubularSegments );
  16712. uvs.push( j / radialSegments );
  16713. }
  16714. }
  16715. // generate indices
  16716. for ( j = 1; j <= radialSegments; j ++ ) {
  16717. for ( i = 1; i <= tubularSegments; i ++ ) {
  16718. // indices
  16719. var a = ( tubularSegments + 1 ) * j + i - 1;
  16720. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  16721. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  16722. var d = ( tubularSegments + 1 ) * j + i;
  16723. // faces
  16724. indices.push( a, b, d );
  16725. indices.push( b, c, d );
  16726. }
  16727. }
  16728. // build geometry
  16729. this.setIndex( indices );
  16730. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16731. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16732. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16733. }
  16734. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16735. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  16736. /**
  16737. * @author Mugen87 / https://github.com/Mugen87
  16738. * Port from https://github.com/mapbox/earcut (v2.1.2)
  16739. */
  16740. var Earcut = {
  16741. triangulate: function ( data, holeIndices, dim ) {
  16742. dim = dim || 2;
  16743. var hasHoles = holeIndices && holeIndices.length,
  16744. outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length,
  16745. outerNode = linkedList( data, 0, outerLen, dim, true ),
  16746. triangles = [];
  16747. if ( ! outerNode ) return triangles;
  16748. var minX, minY, maxX, maxY, x, y, invSize;
  16749. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  16750. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  16751. if ( data.length > 80 * dim ) {
  16752. minX = maxX = data[ 0 ];
  16753. minY = maxY = data[ 1 ];
  16754. for ( var i = dim; i < outerLen; i += dim ) {
  16755. x = data[ i ];
  16756. y = data[ i + 1 ];
  16757. if ( x < minX ) minX = x;
  16758. if ( y < minY ) minY = y;
  16759. if ( x > maxX ) maxX = x;
  16760. if ( y > maxY ) maxY = y;
  16761. }
  16762. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  16763. invSize = Math.max( maxX - minX, maxY - minY );
  16764. invSize = invSize !== 0 ? 1 / invSize : 0;
  16765. }
  16766. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  16767. return triangles;
  16768. }
  16769. };
  16770. // create a circular doubly linked list from polygon points in the specified winding order
  16771. function linkedList( data, start, end, dim, clockwise ) {
  16772. var i, last;
  16773. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  16774. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  16775. } else {
  16776. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  16777. }
  16778. if ( last && equals( last, last.next ) ) {
  16779. removeNode( last );
  16780. last = last.next;
  16781. }
  16782. return last;
  16783. }
  16784. // eliminate colinear or duplicate points
  16785. function filterPoints( start, end ) {
  16786. if ( ! start ) return start;
  16787. if ( ! end ) end = start;
  16788. var p = start, again;
  16789. do {
  16790. again = false;
  16791. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  16792. removeNode( p );
  16793. p = end = p.prev;
  16794. if ( p === p.next ) break;
  16795. again = true;
  16796. } else {
  16797. p = p.next;
  16798. }
  16799. } while ( again || p !== end );
  16800. return end;
  16801. }
  16802. // main ear slicing loop which triangulates a polygon (given as a linked list)
  16803. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  16804. if ( ! ear ) return;
  16805. // interlink polygon nodes in z-order
  16806. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  16807. var stop = ear, prev, next;
  16808. // iterate through ears, slicing them one by one
  16809. while ( ear.prev !== ear.next ) {
  16810. prev = ear.prev;
  16811. next = ear.next;
  16812. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  16813. // cut off the triangle
  16814. triangles.push( prev.i / dim );
  16815. triangles.push( ear.i / dim );
  16816. triangles.push( next.i / dim );
  16817. removeNode( ear );
  16818. // skipping the next vertice leads to less sliver triangles
  16819. ear = next.next;
  16820. stop = next.next;
  16821. continue;
  16822. }
  16823. ear = next;
  16824. // if we looped through the whole remaining polygon and can't find any more ears
  16825. if ( ear === stop ) {
  16826. // try filtering points and slicing again
  16827. if ( ! pass ) {
  16828. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  16829. // if this didn't work, try curing all small self-intersections locally
  16830. } else if ( pass === 1 ) {
  16831. ear = cureLocalIntersections( ear, triangles, dim );
  16832. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  16833. // as a last resort, try splitting the remaining polygon into two
  16834. } else if ( pass === 2 ) {
  16835. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  16836. }
  16837. break;
  16838. }
  16839. }
  16840. }
  16841. // check whether a polygon node forms a valid ear with adjacent nodes
  16842. function isEar( ear ) {
  16843. var a = ear.prev,
  16844. b = ear,
  16845. c = ear.next;
  16846. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  16847. // now make sure we don't have other points inside the potential ear
  16848. var p = ear.next.next;
  16849. while ( p !== ear.prev ) {
  16850. if ( pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) && area( p.prev, p, p.next ) >= 0 ) {
  16851. return false;
  16852. }
  16853. p = p.next;
  16854. }
  16855. return true;
  16856. }
  16857. function isEarHashed( ear, minX, minY, invSize ) {
  16858. var a = ear.prev,
  16859. b = ear,
  16860. c = ear.next;
  16861. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  16862. // triangle bbox; min & max are calculated like this for speed
  16863. var minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  16864. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  16865. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  16866. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  16867. // z-order range for the current triangle bbox;
  16868. var minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  16869. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  16870. // first look for points inside the triangle in increasing z-order
  16871. var p = ear.nextZ;
  16872. while ( p && p.z <= maxZ ) {
  16873. if ( p !== ear.prev && p !== ear.next &&
  16874. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  16875. area( p.prev, p, p.next ) >= 0 ) return false;
  16876. p = p.nextZ;
  16877. }
  16878. // then look for points in decreasing z-order
  16879. p = ear.prevZ;
  16880. while ( p && p.z >= minZ ) {
  16881. if ( p !== ear.prev && p !== ear.next &&
  16882. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  16883. area( p.prev, p, p.next ) >= 0 ) return false;
  16884. p = p.prevZ;
  16885. }
  16886. return true;
  16887. }
  16888. // go through all polygon nodes and cure small local self-intersections
  16889. function cureLocalIntersections( start, triangles, dim ) {
  16890. var p = start;
  16891. do {
  16892. var a = p.prev, b = p.next.next;
  16893. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  16894. triangles.push( a.i / dim );
  16895. triangles.push( p.i / dim );
  16896. triangles.push( b.i / dim );
  16897. // remove two nodes involved
  16898. removeNode( p );
  16899. removeNode( p.next );
  16900. p = start = b;
  16901. }
  16902. p = p.next;
  16903. } while ( p !== start );
  16904. return p;
  16905. }
  16906. // try splitting polygon into two and triangulate them independently
  16907. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  16908. // look for a valid diagonal that divides the polygon into two
  16909. var a = start;
  16910. do {
  16911. var b = a.next.next;
  16912. while ( b !== a.prev ) {
  16913. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  16914. // split the polygon in two by the diagonal
  16915. var c = splitPolygon( a, b );
  16916. // filter colinear points around the cuts
  16917. a = filterPoints( a, a.next );
  16918. c = filterPoints( c, c.next );
  16919. // run earcut on each half
  16920. earcutLinked( a, triangles, dim, minX, minY, invSize );
  16921. earcutLinked( c, triangles, dim, minX, minY, invSize );
  16922. return;
  16923. }
  16924. b = b.next;
  16925. }
  16926. a = a.next;
  16927. } while ( a !== start );
  16928. }
  16929. // link every hole into the outer loop, producing a single-ring polygon without holes
  16930. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  16931. var queue = [], i, len, start, end, list;
  16932. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  16933. start = holeIndices[ i ] * dim;
  16934. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  16935. list = linkedList( data, start, end, dim, false );
  16936. if ( list === list.next ) list.steiner = true;
  16937. queue.push( getLeftmost( list ) );
  16938. }
  16939. queue.sort( compareX );
  16940. // process holes from left to right
  16941. for ( i = 0; i < queue.length; i ++ ) {
  16942. eliminateHole( queue[ i ], outerNode );
  16943. outerNode = filterPoints( outerNode, outerNode.next );
  16944. }
  16945. return outerNode;
  16946. }
  16947. function compareX( a, b ) {
  16948. return a.x - b.x;
  16949. }
  16950. // find a bridge between vertices that connects hole with an outer ring and and link it
  16951. function eliminateHole( hole, outerNode ) {
  16952. outerNode = findHoleBridge( hole, outerNode );
  16953. if ( outerNode ) {
  16954. var b = splitPolygon( outerNode, hole );
  16955. filterPoints( b, b.next );
  16956. }
  16957. }
  16958. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  16959. function findHoleBridge( hole, outerNode ) {
  16960. var p = outerNode,
  16961. hx = hole.x,
  16962. hy = hole.y,
  16963. qx = - Infinity,
  16964. m;
  16965. // find a segment intersected by a ray from the hole's leftmost point to the left;
  16966. // segment's endpoint with lesser x will be potential connection point
  16967. do {
  16968. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  16969. var x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  16970. if ( x <= hx && x > qx ) {
  16971. qx = x;
  16972. if ( x === hx ) {
  16973. if ( hy === p.y ) return p;
  16974. if ( hy === p.next.y ) return p.next;
  16975. }
  16976. m = p.x < p.next.x ? p : p.next;
  16977. }
  16978. }
  16979. p = p.next;
  16980. } while ( p !== outerNode );
  16981. if ( ! m ) return null;
  16982. if ( hx === qx ) return m.prev; // hole touches outer segment; pick lower endpoint
  16983. // look for points inside the triangle of hole point, segment intersection and endpoint;
  16984. // if there are no points found, we have a valid connection;
  16985. // otherwise choose the point of the minimum angle with the ray as connection point
  16986. var stop = m,
  16987. mx = m.x,
  16988. my = m.y,
  16989. tanMin = Infinity,
  16990. tan;
  16991. p = m.next;
  16992. while ( p !== stop ) {
  16993. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  16994. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  16995. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  16996. if ( ( tan < tanMin || ( tan === tanMin && p.x > m.x ) ) && locallyInside( p, hole ) ) {
  16997. m = p;
  16998. tanMin = tan;
  16999. }
  17000. }
  17001. p = p.next;
  17002. }
  17003. return m;
  17004. }
  17005. // interlink polygon nodes in z-order
  17006. function indexCurve( start, minX, minY, invSize ) {
  17007. var p = start;
  17008. do {
  17009. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  17010. p.prevZ = p.prev;
  17011. p.nextZ = p.next;
  17012. p = p.next;
  17013. } while ( p !== start );
  17014. p.prevZ.nextZ = null;
  17015. p.prevZ = null;
  17016. sortLinked( p );
  17017. }
  17018. // Simon Tatham's linked list merge sort algorithm
  17019. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  17020. function sortLinked( list ) {
  17021. var i, p, q, e, tail, numMerges, pSize, qSize, inSize = 1;
  17022. do {
  17023. p = list;
  17024. list = null;
  17025. tail = null;
  17026. numMerges = 0;
  17027. while ( p ) {
  17028. numMerges ++;
  17029. q = p;
  17030. pSize = 0;
  17031. for ( i = 0; i < inSize; i ++ ) {
  17032. pSize ++;
  17033. q = q.nextZ;
  17034. if ( ! q ) break;
  17035. }
  17036. qSize = inSize;
  17037. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  17038. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  17039. e = p;
  17040. p = p.nextZ;
  17041. pSize --;
  17042. } else {
  17043. e = q;
  17044. q = q.nextZ;
  17045. qSize --;
  17046. }
  17047. if ( tail ) tail.nextZ = e;
  17048. else list = e;
  17049. e.prevZ = tail;
  17050. tail = e;
  17051. }
  17052. p = q;
  17053. }
  17054. tail.nextZ = null;
  17055. inSize *= 2;
  17056. } while ( numMerges > 1 );
  17057. return list;
  17058. }
  17059. // z-order of a point given coords and inverse of the longer side of data bbox
  17060. function zOrder( x, y, minX, minY, invSize ) {
  17061. // coords are transformed into non-negative 15-bit integer range
  17062. x = 32767 * ( x - minX ) * invSize;
  17063. y = 32767 * ( y - minY ) * invSize;
  17064. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  17065. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  17066. x = ( x | ( x << 2 ) ) & 0x33333333;
  17067. x = ( x | ( x << 1 ) ) & 0x55555555;
  17068. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  17069. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  17070. y = ( y | ( y << 2 ) ) & 0x33333333;
  17071. y = ( y | ( y << 1 ) ) & 0x55555555;
  17072. return x | ( y << 1 );
  17073. }
  17074. // find the leftmost node of a polygon ring
  17075. function getLeftmost( start ) {
  17076. var p = start, leftmost = start;
  17077. do {
  17078. if ( p.x < leftmost.x ) leftmost = p;
  17079. p = p.next;
  17080. } while ( p !== start );
  17081. return leftmost;
  17082. }
  17083. // check if a point lies within a convex triangle
  17084. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  17085. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  17086. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  17087. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  17088. }
  17089. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  17090. function isValidDiagonal( a, b ) {
  17091. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) &&
  17092. locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b );
  17093. }
  17094. // signed area of a triangle
  17095. function area( p, q, r ) {
  17096. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  17097. }
  17098. // check if two points are equal
  17099. function equals( p1, p2 ) {
  17100. return p1.x === p2.x && p1.y === p2.y;
  17101. }
  17102. // check if two segments intersect
  17103. function intersects( p1, q1, p2, q2 ) {
  17104. if ( ( equals( p1, q1 ) && equals( p2, q2 ) ) ||
  17105. ( equals( p1, q2 ) && equals( p2, q1 ) ) ) return true;
  17106. return area( p1, q1, p2 ) > 0 !== area( p1, q1, q2 ) > 0 &&
  17107. area( p2, q2, p1 ) > 0 !== area( p2, q2, q1 ) > 0;
  17108. }
  17109. // check if a polygon diagonal intersects any polygon segments
  17110. function intersectsPolygon( a, b ) {
  17111. var p = a;
  17112. do {
  17113. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  17114. intersects( p, p.next, a, b ) ) {
  17115. return true;
  17116. }
  17117. p = p.next;
  17118. } while ( p !== a );
  17119. return false;
  17120. }
  17121. // check if a polygon diagonal is locally inside the polygon
  17122. function locallyInside( a, b ) {
  17123. return area( a.prev, a, a.next ) < 0 ?
  17124. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  17125. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  17126. }
  17127. // check if the middle point of a polygon diagonal is inside the polygon
  17128. function middleInside( a, b ) {
  17129. var p = a,
  17130. inside = false,
  17131. px = ( a.x + b.x ) / 2,
  17132. py = ( a.y + b.y ) / 2;
  17133. do {
  17134. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  17135. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) ) {
  17136. inside = ! inside;
  17137. }
  17138. p = p.next;
  17139. } while ( p !== a );
  17140. return inside;
  17141. }
  17142. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  17143. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  17144. function splitPolygon( a, b ) {
  17145. var a2 = new Node( a.i, a.x, a.y ),
  17146. b2 = new Node( b.i, b.x, b.y ),
  17147. an = a.next,
  17148. bp = b.prev;
  17149. a.next = b;
  17150. b.prev = a;
  17151. a2.next = an;
  17152. an.prev = a2;
  17153. b2.next = a2;
  17154. a2.prev = b2;
  17155. bp.next = b2;
  17156. b2.prev = bp;
  17157. return b2;
  17158. }
  17159. // create a node and optionally link it with previous one (in a circular doubly linked list)
  17160. function insertNode( i, x, y, last ) {
  17161. var p = new Node( i, x, y );
  17162. if ( ! last ) {
  17163. p.prev = p;
  17164. p.next = p;
  17165. } else {
  17166. p.next = last.next;
  17167. p.prev = last;
  17168. last.next.prev = p;
  17169. last.next = p;
  17170. }
  17171. return p;
  17172. }
  17173. function removeNode( p ) {
  17174. p.next.prev = p.prev;
  17175. p.prev.next = p.next;
  17176. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  17177. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  17178. }
  17179. function Node( i, x, y ) {
  17180. // vertice index in coordinates array
  17181. this.i = i;
  17182. // vertex coordinates
  17183. this.x = x;
  17184. this.y = y;
  17185. // previous and next vertice nodes in a polygon ring
  17186. this.prev = null;
  17187. this.next = null;
  17188. // z-order curve value
  17189. this.z = null;
  17190. // previous and next nodes in z-order
  17191. this.prevZ = null;
  17192. this.nextZ = null;
  17193. // indicates whether this is a steiner point
  17194. this.steiner = false;
  17195. }
  17196. function signedArea( data, start, end, dim ) {
  17197. var sum = 0;
  17198. for ( var i = start, j = end - dim; i < end; i += dim ) {
  17199. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  17200. j = i;
  17201. }
  17202. return sum;
  17203. }
  17204. /**
  17205. * @author zz85 / http://www.lab4games.net/zz85/blog
  17206. */
  17207. var ShapeUtils = {
  17208. // calculate area of the contour polygon
  17209. area: function ( contour ) {
  17210. var n = contour.length;
  17211. var a = 0.0;
  17212. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  17213. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  17214. }
  17215. return a * 0.5;
  17216. },
  17217. isClockWise: function ( pts ) {
  17218. return ShapeUtils.area( pts ) < 0;
  17219. },
  17220. triangulateShape: function ( contour, holes ) {
  17221. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  17222. var holeIndices = []; // array of hole indices
  17223. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  17224. removeDupEndPts( contour );
  17225. addContour( vertices, contour );
  17226. //
  17227. var holeIndex = contour.length;
  17228. holes.forEach( removeDupEndPts );
  17229. for ( var i = 0; i < holes.length; i ++ ) {
  17230. holeIndices.push( holeIndex );
  17231. holeIndex += holes[ i ].length;
  17232. addContour( vertices, holes[ i ] );
  17233. }
  17234. //
  17235. var triangles = Earcut.triangulate( vertices, holeIndices );
  17236. //
  17237. for ( var i = 0; i < triangles.length; i += 3 ) {
  17238. faces.push( triangles.slice( i, i + 3 ) );
  17239. }
  17240. return faces;
  17241. }
  17242. };
  17243. function removeDupEndPts( points ) {
  17244. var l = points.length;
  17245. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  17246. points.pop();
  17247. }
  17248. }
  17249. function addContour( vertices, contour ) {
  17250. for ( var i = 0; i < contour.length; i ++ ) {
  17251. vertices.push( contour[ i ].x );
  17252. vertices.push( contour[ i ].y );
  17253. }
  17254. }
  17255. /**
  17256. * @author zz85 / http://www.lab4games.net/zz85/blog
  17257. *
  17258. * Creates extruded geometry from a path shape.
  17259. *
  17260. * parameters = {
  17261. *
  17262. * curveSegments: <int>, // number of points on the curves
  17263. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  17264. * depth: <float>, // Depth to extrude the shape
  17265. *
  17266. * bevelEnabled: <bool>, // turn on bevel
  17267. * bevelThickness: <float>, // how deep into the original shape bevel goes
  17268. * bevelSize: <float>, // how far from shape outline is bevel
  17269. * bevelSegments: <int>, // number of bevel layers
  17270. *
  17271. * extrudePath: <THREE.Curve> // curve to extrude shape along
  17272. *
  17273. * UVGenerator: <Object> // object that provides UV generator functions
  17274. *
  17275. * }
  17276. */
  17277. // ExtrudeGeometry
  17278. function ExtrudeGeometry( shapes, options ) {
  17279. Geometry.call( this );
  17280. this.type = 'ExtrudeGeometry';
  17281. this.parameters = {
  17282. shapes: shapes,
  17283. options: options
  17284. };
  17285. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  17286. this.mergeVertices();
  17287. }
  17288. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  17289. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  17290. ExtrudeGeometry.prototype.toJSON = function () {
  17291. var data = Geometry.prototype.toJSON.call( this );
  17292. var shapes = this.parameters.shapes;
  17293. var options = this.parameters.options;
  17294. return toJSON( shapes, options, data );
  17295. };
  17296. // ExtrudeBufferGeometry
  17297. function ExtrudeBufferGeometry( shapes, options ) {
  17298. BufferGeometry.call( this );
  17299. this.type = 'ExtrudeBufferGeometry';
  17300. this.parameters = {
  17301. shapes: shapes,
  17302. options: options
  17303. };
  17304. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  17305. var scope = this;
  17306. var verticesArray = [];
  17307. var uvArray = [];
  17308. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  17309. var shape = shapes[ i ];
  17310. addShape( shape );
  17311. }
  17312. // build geometry
  17313. this.addAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  17314. this.addAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  17315. this.computeVertexNormals();
  17316. // functions
  17317. function addShape( shape ) {
  17318. var placeholder = [];
  17319. // options
  17320. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  17321. var steps = options.steps !== undefined ? options.steps : 1;
  17322. var depth = options.depth !== undefined ? options.depth : 100;
  17323. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  17324. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  17325. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  17326. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  17327. var extrudePath = options.extrudePath;
  17328. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  17329. // deprecated options
  17330. if ( options.amount !== undefined ) {
  17331. console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' );
  17332. depth = options.amount;
  17333. }
  17334. //
  17335. var extrudePts, extrudeByPath = false;
  17336. var splineTube, binormal, normal, position2;
  17337. if ( extrudePath ) {
  17338. extrudePts = extrudePath.getSpacedPoints( steps );
  17339. extrudeByPath = true;
  17340. bevelEnabled = false; // bevels not supported for path extrusion
  17341. // SETUP TNB variables
  17342. // TODO1 - have a .isClosed in spline?
  17343. splineTube = extrudePath.computeFrenetFrames( steps, false );
  17344. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  17345. binormal = new Vector3();
  17346. normal = new Vector3();
  17347. position2 = new Vector3();
  17348. }
  17349. // Safeguards if bevels are not enabled
  17350. if ( ! bevelEnabled ) {
  17351. bevelSegments = 0;
  17352. bevelThickness = 0;
  17353. bevelSize = 0;
  17354. }
  17355. // Variables initialization
  17356. var ahole, h, hl; // looping of holes
  17357. var shapePoints = shape.extractPoints( curveSegments );
  17358. var vertices = shapePoints.shape;
  17359. var holes = shapePoints.holes;
  17360. var reverse = ! ShapeUtils.isClockWise( vertices );
  17361. if ( reverse ) {
  17362. vertices = vertices.reverse();
  17363. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  17364. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17365. ahole = holes[ h ];
  17366. if ( ShapeUtils.isClockWise( ahole ) ) {
  17367. holes[ h ] = ahole.reverse();
  17368. }
  17369. }
  17370. }
  17371. var faces = ShapeUtils.triangulateShape( vertices, holes );
  17372. /* Vertices */
  17373. var contour = vertices; // vertices has all points but contour has only points of circumference
  17374. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17375. ahole = holes[ h ];
  17376. vertices = vertices.concat( ahole );
  17377. }
  17378. function scalePt2( pt, vec, size ) {
  17379. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  17380. return vec.clone().multiplyScalar( size ).add( pt );
  17381. }
  17382. var b, bs, t, z,
  17383. vert, vlen = vertices.length,
  17384. face, flen = faces.length;
  17385. // Find directions for point movement
  17386. function getBevelVec( inPt, inPrev, inNext ) {
  17387. // computes for inPt the corresponding point inPt' on a new contour
  17388. // shifted by 1 unit (length of normalized vector) to the left
  17389. // if we walk along contour clockwise, this new contour is outside the old one
  17390. //
  17391. // inPt' is the intersection of the two lines parallel to the two
  17392. // adjacent edges of inPt at a distance of 1 unit on the left side.
  17393. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  17394. // good reading for geometry algorithms (here: line-line intersection)
  17395. // http://geomalgorithms.com/a05-_intersect-1.html
  17396. var v_prev_x = inPt.x - inPrev.x,
  17397. v_prev_y = inPt.y - inPrev.y;
  17398. var v_next_x = inNext.x - inPt.x,
  17399. v_next_y = inNext.y - inPt.y;
  17400. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  17401. // check for collinear edges
  17402. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17403. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  17404. // not collinear
  17405. // length of vectors for normalizing
  17406. var v_prev_len = Math.sqrt( v_prev_lensq );
  17407. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  17408. // shift adjacent points by unit vectors to the left
  17409. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  17410. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  17411. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  17412. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  17413. // scaling factor for v_prev to intersection point
  17414. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  17415. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  17416. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17417. // vector from inPt to intersection point
  17418. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  17419. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  17420. // Don't normalize!, otherwise sharp corners become ugly
  17421. // but prevent crazy spikes
  17422. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  17423. if ( v_trans_lensq <= 2 ) {
  17424. return new Vector2( v_trans_x, v_trans_y );
  17425. } else {
  17426. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  17427. }
  17428. } else {
  17429. // handle special case of collinear edges
  17430. var direction_eq = false; // assumes: opposite
  17431. if ( v_prev_x > Number.EPSILON ) {
  17432. if ( v_next_x > Number.EPSILON ) {
  17433. direction_eq = true;
  17434. }
  17435. } else {
  17436. if ( v_prev_x < - Number.EPSILON ) {
  17437. if ( v_next_x < - Number.EPSILON ) {
  17438. direction_eq = true;
  17439. }
  17440. } else {
  17441. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  17442. direction_eq = true;
  17443. }
  17444. }
  17445. }
  17446. if ( direction_eq ) {
  17447. // console.log("Warning: lines are a straight sequence");
  17448. v_trans_x = - v_prev_y;
  17449. v_trans_y = v_prev_x;
  17450. shrink_by = Math.sqrt( v_prev_lensq );
  17451. } else {
  17452. // console.log("Warning: lines are a straight spike");
  17453. v_trans_x = v_prev_x;
  17454. v_trans_y = v_prev_y;
  17455. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  17456. }
  17457. }
  17458. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  17459. }
  17460. var contourMovements = [];
  17461. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17462. if ( j === il ) j = 0;
  17463. if ( k === il ) k = 0;
  17464. // (j)---(i)---(k)
  17465. // console.log('i,j,k', i, j , k)
  17466. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  17467. }
  17468. var holesMovements = [],
  17469. oneHoleMovements, verticesMovements = contourMovements.concat();
  17470. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17471. ahole = holes[ h ];
  17472. oneHoleMovements = [];
  17473. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17474. if ( j === il ) j = 0;
  17475. if ( k === il ) k = 0;
  17476. // (j)---(i)---(k)
  17477. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  17478. }
  17479. holesMovements.push( oneHoleMovements );
  17480. verticesMovements = verticesMovements.concat( oneHoleMovements );
  17481. }
  17482. // Loop bevelSegments, 1 for the front, 1 for the back
  17483. for ( b = 0; b < bevelSegments; b ++ ) {
  17484. //for ( b = bevelSegments; b > 0; b -- ) {
  17485. t = b / bevelSegments;
  17486. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17487. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  17488. // contract shape
  17489. for ( i = 0, il = contour.length; i < il; i ++ ) {
  17490. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17491. v( vert.x, vert.y, - z );
  17492. }
  17493. // expand holes
  17494. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17495. ahole = holes[ h ];
  17496. oneHoleMovements = holesMovements[ h ];
  17497. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  17498. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17499. v( vert.x, vert.y, - z );
  17500. }
  17501. }
  17502. }
  17503. bs = bevelSize;
  17504. // Back facing vertices
  17505. for ( i = 0; i < vlen; i ++ ) {
  17506. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17507. if ( ! extrudeByPath ) {
  17508. v( vert.x, vert.y, 0 );
  17509. } else {
  17510. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  17511. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  17512. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  17513. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  17514. v( position2.x, position2.y, position2.z );
  17515. }
  17516. }
  17517. // Add stepped vertices...
  17518. // Including front facing vertices
  17519. var s;
  17520. for ( s = 1; s <= steps; s ++ ) {
  17521. for ( i = 0; i < vlen; i ++ ) {
  17522. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17523. if ( ! extrudeByPath ) {
  17524. v( vert.x, vert.y, depth / steps * s );
  17525. } else {
  17526. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  17527. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  17528. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  17529. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  17530. v( position2.x, position2.y, position2.z );
  17531. }
  17532. }
  17533. }
  17534. // Add bevel segments planes
  17535. //for ( b = 1; b <= bevelSegments; b ++ ) {
  17536. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  17537. t = b / bevelSegments;
  17538. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17539. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  17540. // contract shape
  17541. for ( i = 0, il = contour.length; i < il; i ++ ) {
  17542. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17543. v( vert.x, vert.y, depth + z );
  17544. }
  17545. // expand holes
  17546. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17547. ahole = holes[ h ];
  17548. oneHoleMovements = holesMovements[ h ];
  17549. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  17550. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17551. if ( ! extrudeByPath ) {
  17552. v( vert.x, vert.y, depth + z );
  17553. } else {
  17554. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  17555. }
  17556. }
  17557. }
  17558. }
  17559. /* Faces */
  17560. // Top and bottom faces
  17561. buildLidFaces();
  17562. // Sides faces
  17563. buildSideFaces();
  17564. ///// Internal functions
  17565. function buildLidFaces() {
  17566. var start = verticesArray.length / 3;
  17567. if ( bevelEnabled ) {
  17568. var layer = 0; // steps + 1
  17569. var offset = vlen * layer;
  17570. // Bottom faces
  17571. for ( i = 0; i < flen; i ++ ) {
  17572. face = faces[ i ];
  17573. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  17574. }
  17575. layer = steps + bevelSegments * 2;
  17576. offset = vlen * layer;
  17577. // Top faces
  17578. for ( i = 0; i < flen; i ++ ) {
  17579. face = faces[ i ];
  17580. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  17581. }
  17582. } else {
  17583. // Bottom faces
  17584. for ( i = 0; i < flen; i ++ ) {
  17585. face = faces[ i ];
  17586. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  17587. }
  17588. // Top faces
  17589. for ( i = 0; i < flen; i ++ ) {
  17590. face = faces[ i ];
  17591. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  17592. }
  17593. }
  17594. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  17595. }
  17596. // Create faces for the z-sides of the shape
  17597. function buildSideFaces() {
  17598. var start = verticesArray.length / 3;
  17599. var layeroffset = 0;
  17600. sidewalls( contour, layeroffset );
  17601. layeroffset += contour.length;
  17602. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17603. ahole = holes[ h ];
  17604. sidewalls( ahole, layeroffset );
  17605. //, true
  17606. layeroffset += ahole.length;
  17607. }
  17608. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  17609. }
  17610. function sidewalls( contour, layeroffset ) {
  17611. var j, k;
  17612. i = contour.length;
  17613. while ( -- i >= 0 ) {
  17614. j = i;
  17615. k = i - 1;
  17616. if ( k < 0 ) k = contour.length - 1;
  17617. //console.log('b', i,j, i-1, k,vertices.length);
  17618. var s = 0,
  17619. sl = steps + bevelSegments * 2;
  17620. for ( s = 0; s < sl; s ++ ) {
  17621. var slen1 = vlen * s;
  17622. var slen2 = vlen * ( s + 1 );
  17623. var a = layeroffset + j + slen1,
  17624. b = layeroffset + k + slen1,
  17625. c = layeroffset + k + slen2,
  17626. d = layeroffset + j + slen2;
  17627. f4( a, b, c, d );
  17628. }
  17629. }
  17630. }
  17631. function v( x, y, z ) {
  17632. placeholder.push( x );
  17633. placeholder.push( y );
  17634. placeholder.push( z );
  17635. }
  17636. function f3( a, b, c ) {
  17637. addVertex( a );
  17638. addVertex( b );
  17639. addVertex( c );
  17640. var nextIndex = verticesArray.length / 3;
  17641. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  17642. addUV( uvs[ 0 ] );
  17643. addUV( uvs[ 1 ] );
  17644. addUV( uvs[ 2 ] );
  17645. }
  17646. function f4( a, b, c, d ) {
  17647. addVertex( a );
  17648. addVertex( b );
  17649. addVertex( d );
  17650. addVertex( b );
  17651. addVertex( c );
  17652. addVertex( d );
  17653. var nextIndex = verticesArray.length / 3;
  17654. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  17655. addUV( uvs[ 0 ] );
  17656. addUV( uvs[ 1 ] );
  17657. addUV( uvs[ 3 ] );
  17658. addUV( uvs[ 1 ] );
  17659. addUV( uvs[ 2 ] );
  17660. addUV( uvs[ 3 ] );
  17661. }
  17662. function addVertex( index ) {
  17663. verticesArray.push( placeholder[ index * 3 + 0 ] );
  17664. verticesArray.push( placeholder[ index * 3 + 1 ] );
  17665. verticesArray.push( placeholder[ index * 3 + 2 ] );
  17666. }
  17667. function addUV( vector2 ) {
  17668. uvArray.push( vector2.x );
  17669. uvArray.push( vector2.y );
  17670. }
  17671. }
  17672. }
  17673. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17674. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  17675. ExtrudeBufferGeometry.prototype.toJSON = function () {
  17676. var data = BufferGeometry.prototype.toJSON.call( this );
  17677. var shapes = this.parameters.shapes;
  17678. var options = this.parameters.options;
  17679. return toJSON( shapes, options, data );
  17680. };
  17681. //
  17682. var WorldUVGenerator = {
  17683. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  17684. var a_x = vertices[ indexA * 3 ];
  17685. var a_y = vertices[ indexA * 3 + 1 ];
  17686. var b_x = vertices[ indexB * 3 ];
  17687. var b_y = vertices[ indexB * 3 + 1 ];
  17688. var c_x = vertices[ indexC * 3 ];
  17689. var c_y = vertices[ indexC * 3 + 1 ];
  17690. return [
  17691. new Vector2( a_x, a_y ),
  17692. new Vector2( b_x, b_y ),
  17693. new Vector2( c_x, c_y )
  17694. ];
  17695. },
  17696. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  17697. var a_x = vertices[ indexA * 3 ];
  17698. var a_y = vertices[ indexA * 3 + 1 ];
  17699. var a_z = vertices[ indexA * 3 + 2 ];
  17700. var b_x = vertices[ indexB * 3 ];
  17701. var b_y = vertices[ indexB * 3 + 1 ];
  17702. var b_z = vertices[ indexB * 3 + 2 ];
  17703. var c_x = vertices[ indexC * 3 ];
  17704. var c_y = vertices[ indexC * 3 + 1 ];
  17705. var c_z = vertices[ indexC * 3 + 2 ];
  17706. var d_x = vertices[ indexD * 3 ];
  17707. var d_y = vertices[ indexD * 3 + 1 ];
  17708. var d_z = vertices[ indexD * 3 + 2 ];
  17709. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  17710. return [
  17711. new Vector2( a_x, 1 - a_z ),
  17712. new Vector2( b_x, 1 - b_z ),
  17713. new Vector2( c_x, 1 - c_z ),
  17714. new Vector2( d_x, 1 - d_z )
  17715. ];
  17716. } else {
  17717. return [
  17718. new Vector2( a_y, 1 - a_z ),
  17719. new Vector2( b_y, 1 - b_z ),
  17720. new Vector2( c_y, 1 - c_z ),
  17721. new Vector2( d_y, 1 - d_z )
  17722. ];
  17723. }
  17724. }
  17725. };
  17726. function toJSON( shapes, options, data ) {
  17727. //
  17728. data.shapes = [];
  17729. if ( Array.isArray( shapes ) ) {
  17730. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  17731. var shape = shapes[ i ];
  17732. data.shapes.push( shape.uuid );
  17733. }
  17734. } else {
  17735. data.shapes.push( shapes.uuid );
  17736. }
  17737. //
  17738. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  17739. return data;
  17740. }
  17741. /**
  17742. * @author zz85 / http://www.lab4games.net/zz85/blog
  17743. * @author alteredq / http://alteredqualia.com/
  17744. *
  17745. * Text = 3D Text
  17746. *
  17747. * parameters = {
  17748. * font: <THREE.Font>, // font
  17749. *
  17750. * size: <float>, // size of the text
  17751. * height: <float>, // thickness to extrude text
  17752. * curveSegments: <int>, // number of points on the curves
  17753. *
  17754. * bevelEnabled: <bool>, // turn on bevel
  17755. * bevelThickness: <float>, // how deep into text bevel goes
  17756. * bevelSize: <float> // how far from text outline is bevel
  17757. * }
  17758. */
  17759. // TextGeometry
  17760. function TextGeometry( text, parameters ) {
  17761. Geometry.call( this );
  17762. this.type = 'TextGeometry';
  17763. this.parameters = {
  17764. text: text,
  17765. parameters: parameters
  17766. };
  17767. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  17768. this.mergeVertices();
  17769. }
  17770. TextGeometry.prototype = Object.create( Geometry.prototype );
  17771. TextGeometry.prototype.constructor = TextGeometry;
  17772. // TextBufferGeometry
  17773. function TextBufferGeometry( text, parameters ) {
  17774. parameters = parameters || {};
  17775. var font = parameters.font;
  17776. if ( ! ( font && font.isFont ) ) {
  17777. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  17778. return new Geometry();
  17779. }
  17780. var shapes = font.generateShapes( text, parameters.size );
  17781. // translate parameters to ExtrudeGeometry API
  17782. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  17783. // defaults
  17784. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  17785. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  17786. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  17787. ExtrudeBufferGeometry.call( this, shapes, parameters );
  17788. this.type = 'TextBufferGeometry';
  17789. }
  17790. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  17791. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  17792. /**
  17793. * @author mrdoob / http://mrdoob.com/
  17794. * @author benaadams / https://twitter.com/ben_a_adams
  17795. * @author Mugen87 / https://github.com/Mugen87
  17796. */
  17797. // SphereGeometry
  17798. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  17799. Geometry.call( this );
  17800. this.type = 'SphereGeometry';
  17801. this.parameters = {
  17802. radius: radius,
  17803. widthSegments: widthSegments,
  17804. heightSegments: heightSegments,
  17805. phiStart: phiStart,
  17806. phiLength: phiLength,
  17807. thetaStart: thetaStart,
  17808. thetaLength: thetaLength
  17809. };
  17810. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  17811. this.mergeVertices();
  17812. }
  17813. SphereGeometry.prototype = Object.create( Geometry.prototype );
  17814. SphereGeometry.prototype.constructor = SphereGeometry;
  17815. // SphereBufferGeometry
  17816. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  17817. BufferGeometry.call( this );
  17818. this.type = 'SphereBufferGeometry';
  17819. this.parameters = {
  17820. radius: radius,
  17821. widthSegments: widthSegments,
  17822. heightSegments: heightSegments,
  17823. phiStart: phiStart,
  17824. phiLength: phiLength,
  17825. thetaStart: thetaStart,
  17826. thetaLength: thetaLength
  17827. };
  17828. radius = radius || 1;
  17829. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  17830. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  17831. phiStart = phiStart !== undefined ? phiStart : 0;
  17832. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  17833. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  17834. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  17835. var thetaEnd = thetaStart + thetaLength;
  17836. var ix, iy;
  17837. var index = 0;
  17838. var grid = [];
  17839. var vertex = new Vector3();
  17840. var normal = new Vector3();
  17841. // buffers
  17842. var indices = [];
  17843. var vertices = [];
  17844. var normals = [];
  17845. var uvs = [];
  17846. // generate vertices, normals and uvs
  17847. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  17848. var verticesRow = [];
  17849. var v = iy / heightSegments;
  17850. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  17851. var u = ix / widthSegments;
  17852. // vertex
  17853. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  17854. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  17855. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  17856. vertices.push( vertex.x, vertex.y, vertex.z );
  17857. // normal
  17858. normal.set( vertex.x, vertex.y, vertex.z ).normalize();
  17859. normals.push( normal.x, normal.y, normal.z );
  17860. // uv
  17861. uvs.push( u, 1 - v );
  17862. verticesRow.push( index ++ );
  17863. }
  17864. grid.push( verticesRow );
  17865. }
  17866. // indices
  17867. for ( iy = 0; iy < heightSegments; iy ++ ) {
  17868. for ( ix = 0; ix < widthSegments; ix ++ ) {
  17869. var a = grid[ iy ][ ix + 1 ];
  17870. var b = grid[ iy ][ ix ];
  17871. var c = grid[ iy + 1 ][ ix ];
  17872. var d = grid[ iy + 1 ][ ix + 1 ];
  17873. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  17874. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  17875. }
  17876. }
  17877. // build geometry
  17878. this.setIndex( indices );
  17879. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17880. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17881. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17882. }
  17883. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17884. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  17885. /**
  17886. * @author Kaleb Murphy
  17887. * @author Mugen87 / https://github.com/Mugen87
  17888. */
  17889. // RingGeometry
  17890. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  17891. Geometry.call( this );
  17892. this.type = 'RingGeometry';
  17893. this.parameters = {
  17894. innerRadius: innerRadius,
  17895. outerRadius: outerRadius,
  17896. thetaSegments: thetaSegments,
  17897. phiSegments: phiSegments,
  17898. thetaStart: thetaStart,
  17899. thetaLength: thetaLength
  17900. };
  17901. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  17902. this.mergeVertices();
  17903. }
  17904. RingGeometry.prototype = Object.create( Geometry.prototype );
  17905. RingGeometry.prototype.constructor = RingGeometry;
  17906. // RingBufferGeometry
  17907. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  17908. BufferGeometry.call( this );
  17909. this.type = 'RingBufferGeometry';
  17910. this.parameters = {
  17911. innerRadius: innerRadius,
  17912. outerRadius: outerRadius,
  17913. thetaSegments: thetaSegments,
  17914. phiSegments: phiSegments,
  17915. thetaStart: thetaStart,
  17916. thetaLength: thetaLength
  17917. };
  17918. innerRadius = innerRadius || 0.5;
  17919. outerRadius = outerRadius || 1;
  17920. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  17921. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  17922. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  17923. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  17924. // buffers
  17925. var indices = [];
  17926. var vertices = [];
  17927. var normals = [];
  17928. var uvs = [];
  17929. // some helper variables
  17930. var segment;
  17931. var radius = innerRadius;
  17932. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  17933. var vertex = new Vector3();
  17934. var uv = new Vector2();
  17935. var j, i;
  17936. // generate vertices, normals and uvs
  17937. for ( j = 0; j <= phiSegments; j ++ ) {
  17938. for ( i = 0; i <= thetaSegments; i ++ ) {
  17939. // values are generate from the inside of the ring to the outside
  17940. segment = thetaStart + i / thetaSegments * thetaLength;
  17941. // vertex
  17942. vertex.x = radius * Math.cos( segment );
  17943. vertex.y = radius * Math.sin( segment );
  17944. vertices.push( vertex.x, vertex.y, vertex.z );
  17945. // normal
  17946. normals.push( 0, 0, 1 );
  17947. // uv
  17948. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  17949. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  17950. uvs.push( uv.x, uv.y );
  17951. }
  17952. // increase the radius for next row of vertices
  17953. radius += radiusStep;
  17954. }
  17955. // indices
  17956. for ( j = 0; j < phiSegments; j ++ ) {
  17957. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  17958. for ( i = 0; i < thetaSegments; i ++ ) {
  17959. segment = i + thetaSegmentLevel;
  17960. var a = segment;
  17961. var b = segment + thetaSegments + 1;
  17962. var c = segment + thetaSegments + 2;
  17963. var d = segment + 1;
  17964. // faces
  17965. indices.push( a, b, d );
  17966. indices.push( b, c, d );
  17967. }
  17968. }
  17969. // build geometry
  17970. this.setIndex( indices );
  17971. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17972. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17973. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17974. }
  17975. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17976. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  17977. /**
  17978. * @author zz85 / https://github.com/zz85
  17979. * @author bhouston / http://clara.io
  17980. * @author Mugen87 / https://github.com/Mugen87
  17981. */
  17982. // LatheGeometry
  17983. function LatheGeometry( points, segments, phiStart, phiLength ) {
  17984. Geometry.call( this );
  17985. this.type = 'LatheGeometry';
  17986. this.parameters = {
  17987. points: points,
  17988. segments: segments,
  17989. phiStart: phiStart,
  17990. phiLength: phiLength
  17991. };
  17992. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  17993. this.mergeVertices();
  17994. }
  17995. LatheGeometry.prototype = Object.create( Geometry.prototype );
  17996. LatheGeometry.prototype.constructor = LatheGeometry;
  17997. // LatheBufferGeometry
  17998. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  17999. BufferGeometry.call( this );
  18000. this.type = 'LatheBufferGeometry';
  18001. this.parameters = {
  18002. points: points,
  18003. segments: segments,
  18004. phiStart: phiStart,
  18005. phiLength: phiLength
  18006. };
  18007. segments = Math.floor( segments ) || 12;
  18008. phiStart = phiStart || 0;
  18009. phiLength = phiLength || Math.PI * 2;
  18010. // clamp phiLength so it's in range of [ 0, 2PI ]
  18011. phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
  18012. // buffers
  18013. var indices = [];
  18014. var vertices = [];
  18015. var uvs = [];
  18016. // helper variables
  18017. var base;
  18018. var inverseSegments = 1.0 / segments;
  18019. var vertex = new Vector3();
  18020. var uv = new Vector2();
  18021. var i, j;
  18022. // generate vertices and uvs
  18023. for ( i = 0; i <= segments; i ++ ) {
  18024. var phi = phiStart + i * inverseSegments * phiLength;
  18025. var sin = Math.sin( phi );
  18026. var cos = Math.cos( phi );
  18027. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  18028. // vertex
  18029. vertex.x = points[ j ].x * sin;
  18030. vertex.y = points[ j ].y;
  18031. vertex.z = points[ j ].x * cos;
  18032. vertices.push( vertex.x, vertex.y, vertex.z );
  18033. // uv
  18034. uv.x = i / segments;
  18035. uv.y = j / ( points.length - 1 );
  18036. uvs.push( uv.x, uv.y );
  18037. }
  18038. }
  18039. // indices
  18040. for ( i = 0; i < segments; i ++ ) {
  18041. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  18042. base = j + i * points.length;
  18043. var a = base;
  18044. var b = base + points.length;
  18045. var c = base + points.length + 1;
  18046. var d = base + 1;
  18047. // faces
  18048. indices.push( a, b, d );
  18049. indices.push( b, c, d );
  18050. }
  18051. }
  18052. // build geometry
  18053. this.setIndex( indices );
  18054. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18055. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18056. // generate normals
  18057. this.computeVertexNormals();
  18058. // if the geometry is closed, we need to average the normals along the seam.
  18059. // because the corresponding vertices are identical (but still have different UVs).
  18060. if ( phiLength === Math.PI * 2 ) {
  18061. var normals = this.attributes.normal.array;
  18062. var n1 = new Vector3();
  18063. var n2 = new Vector3();
  18064. var n = new Vector3();
  18065. // this is the buffer offset for the last line of vertices
  18066. base = segments * points.length * 3;
  18067. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  18068. // select the normal of the vertex in the first line
  18069. n1.x = normals[ j + 0 ];
  18070. n1.y = normals[ j + 1 ];
  18071. n1.z = normals[ j + 2 ];
  18072. // select the normal of the vertex in the last line
  18073. n2.x = normals[ base + j + 0 ];
  18074. n2.y = normals[ base + j + 1 ];
  18075. n2.z = normals[ base + j + 2 ];
  18076. // average normals
  18077. n.addVectors( n1, n2 ).normalize();
  18078. // assign the new values to both normals
  18079. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  18080. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  18081. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  18082. }
  18083. }
  18084. }
  18085. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18086. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  18087. /**
  18088. * @author jonobr1 / http://jonobr1.com
  18089. * @author Mugen87 / https://github.com/Mugen87
  18090. */
  18091. // ShapeGeometry
  18092. function ShapeGeometry( shapes, curveSegments ) {
  18093. Geometry.call( this );
  18094. this.type = 'ShapeGeometry';
  18095. if ( typeof curveSegments === 'object' ) {
  18096. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  18097. curveSegments = curveSegments.curveSegments;
  18098. }
  18099. this.parameters = {
  18100. shapes: shapes,
  18101. curveSegments: curveSegments
  18102. };
  18103. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  18104. this.mergeVertices();
  18105. }
  18106. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  18107. ShapeGeometry.prototype.constructor = ShapeGeometry;
  18108. ShapeGeometry.prototype.toJSON = function () {
  18109. var data = Geometry.prototype.toJSON.call( this );
  18110. var shapes = this.parameters.shapes;
  18111. return toJSON$1( shapes, data );
  18112. };
  18113. // ShapeBufferGeometry
  18114. function ShapeBufferGeometry( shapes, curveSegments ) {
  18115. BufferGeometry.call( this );
  18116. this.type = 'ShapeBufferGeometry';
  18117. this.parameters = {
  18118. shapes: shapes,
  18119. curveSegments: curveSegments
  18120. };
  18121. curveSegments = curveSegments || 12;
  18122. // buffers
  18123. var indices = [];
  18124. var vertices = [];
  18125. var normals = [];
  18126. var uvs = [];
  18127. // helper variables
  18128. var groupStart = 0;
  18129. var groupCount = 0;
  18130. // allow single and array values for "shapes" parameter
  18131. if ( Array.isArray( shapes ) === false ) {
  18132. addShape( shapes );
  18133. } else {
  18134. for ( var i = 0; i < shapes.length; i ++ ) {
  18135. addShape( shapes[ i ] );
  18136. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  18137. groupStart += groupCount;
  18138. groupCount = 0;
  18139. }
  18140. }
  18141. // build geometry
  18142. this.setIndex( indices );
  18143. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18144. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18145. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18146. // helper functions
  18147. function addShape( shape ) {
  18148. var i, l, shapeHole;
  18149. var indexOffset = vertices.length / 3;
  18150. var points = shape.extractPoints( curveSegments );
  18151. var shapeVertices = points.shape;
  18152. var shapeHoles = points.holes;
  18153. // check direction of vertices
  18154. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  18155. shapeVertices = shapeVertices.reverse();
  18156. }
  18157. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18158. shapeHole = shapeHoles[ i ];
  18159. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  18160. shapeHoles[ i ] = shapeHole.reverse();
  18161. }
  18162. }
  18163. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  18164. // join vertices of inner and outer paths to a single array
  18165. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18166. shapeHole = shapeHoles[ i ];
  18167. shapeVertices = shapeVertices.concat( shapeHole );
  18168. }
  18169. // vertices, normals, uvs
  18170. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  18171. var vertex = shapeVertices[ i ];
  18172. vertices.push( vertex.x, vertex.y, 0 );
  18173. normals.push( 0, 0, 1 );
  18174. uvs.push( vertex.x, vertex.y ); // world uvs
  18175. }
  18176. // incides
  18177. for ( i = 0, l = faces.length; i < l; i ++ ) {
  18178. var face = faces[ i ];
  18179. var a = face[ 0 ] + indexOffset;
  18180. var b = face[ 1 ] + indexOffset;
  18181. var c = face[ 2 ] + indexOffset;
  18182. indices.push( a, b, c );
  18183. groupCount += 3;
  18184. }
  18185. }
  18186. }
  18187. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18188. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  18189. ShapeBufferGeometry.prototype.toJSON = function () {
  18190. var data = BufferGeometry.prototype.toJSON.call( this );
  18191. var shapes = this.parameters.shapes;
  18192. return toJSON$1( shapes, data );
  18193. };
  18194. //
  18195. function toJSON$1( shapes, data ) {
  18196. data.shapes = [];
  18197. if ( Array.isArray( shapes ) ) {
  18198. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  18199. var shape = shapes[ i ];
  18200. data.shapes.push( shape.uuid );
  18201. }
  18202. } else {
  18203. data.shapes.push( shapes.uuid );
  18204. }
  18205. return data;
  18206. }
  18207. /**
  18208. * @author WestLangley / http://github.com/WestLangley
  18209. * @author Mugen87 / https://github.com/Mugen87
  18210. */
  18211. function EdgesGeometry( geometry, thresholdAngle ) {
  18212. BufferGeometry.call( this );
  18213. this.type = 'EdgesGeometry';
  18214. this.parameters = {
  18215. thresholdAngle: thresholdAngle
  18216. };
  18217. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  18218. // buffer
  18219. var vertices = [];
  18220. // helper variables
  18221. var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
  18222. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  18223. var key, keys = [ 'a', 'b', 'c' ];
  18224. // prepare source geometry
  18225. var geometry2;
  18226. if ( geometry.isBufferGeometry ) {
  18227. geometry2 = new Geometry();
  18228. geometry2.fromBufferGeometry( geometry );
  18229. } else {
  18230. geometry2 = geometry.clone();
  18231. }
  18232. geometry2.mergeVertices();
  18233. geometry2.computeFaceNormals();
  18234. var sourceVertices = geometry2.vertices;
  18235. var faces = geometry2.faces;
  18236. // now create a data structure where each entry represents an edge with its adjoining faces
  18237. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  18238. var face = faces[ i ];
  18239. for ( var j = 0; j < 3; j ++ ) {
  18240. edge1 = face[ keys[ j ] ];
  18241. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  18242. edge[ 0 ] = Math.min( edge1, edge2 );
  18243. edge[ 1 ] = Math.max( edge1, edge2 );
  18244. key = edge[ 0 ] + ',' + edge[ 1 ];
  18245. if ( edges[ key ] === undefined ) {
  18246. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  18247. } else {
  18248. edges[ key ].face2 = i;
  18249. }
  18250. }
  18251. }
  18252. // generate vertices
  18253. for ( key in edges ) {
  18254. var e = edges[ key ];
  18255. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  18256. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  18257. var vertex = sourceVertices[ e.index1 ];
  18258. vertices.push( vertex.x, vertex.y, vertex.z );
  18259. vertex = sourceVertices[ e.index2 ];
  18260. vertices.push( vertex.x, vertex.y, vertex.z );
  18261. }
  18262. }
  18263. // build geometry
  18264. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18265. }
  18266. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  18267. EdgesGeometry.prototype.constructor = EdgesGeometry;
  18268. /**
  18269. * @author mrdoob / http://mrdoob.com/
  18270. * @author Mugen87 / https://github.com/Mugen87
  18271. */
  18272. // CylinderGeometry
  18273. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18274. Geometry.call( this );
  18275. this.type = 'CylinderGeometry';
  18276. this.parameters = {
  18277. radiusTop: radiusTop,
  18278. radiusBottom: radiusBottom,
  18279. height: height,
  18280. radialSegments: radialSegments,
  18281. heightSegments: heightSegments,
  18282. openEnded: openEnded,
  18283. thetaStart: thetaStart,
  18284. thetaLength: thetaLength
  18285. };
  18286. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  18287. this.mergeVertices();
  18288. }
  18289. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  18290. CylinderGeometry.prototype.constructor = CylinderGeometry;
  18291. // CylinderBufferGeometry
  18292. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18293. BufferGeometry.call( this );
  18294. this.type = 'CylinderBufferGeometry';
  18295. this.parameters = {
  18296. radiusTop: radiusTop,
  18297. radiusBottom: radiusBottom,
  18298. height: height,
  18299. radialSegments: radialSegments,
  18300. heightSegments: heightSegments,
  18301. openEnded: openEnded,
  18302. thetaStart: thetaStart,
  18303. thetaLength: thetaLength
  18304. };
  18305. var scope = this;
  18306. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  18307. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  18308. height = height || 1;
  18309. radialSegments = Math.floor( radialSegments ) || 8;
  18310. heightSegments = Math.floor( heightSegments ) || 1;
  18311. openEnded = openEnded !== undefined ? openEnded : false;
  18312. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  18313. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18314. // buffers
  18315. var indices = [];
  18316. var vertices = [];
  18317. var normals = [];
  18318. var uvs = [];
  18319. // helper variables
  18320. var index = 0;
  18321. var indexArray = [];
  18322. var halfHeight = height / 2;
  18323. var groupStart = 0;
  18324. // generate geometry
  18325. generateTorso();
  18326. if ( openEnded === false ) {
  18327. if ( radiusTop > 0 ) generateCap( true );
  18328. if ( radiusBottom > 0 ) generateCap( false );
  18329. }
  18330. // build geometry
  18331. this.setIndex( indices );
  18332. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18333. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18334. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18335. function generateTorso() {
  18336. var x, y;
  18337. var normal = new Vector3();
  18338. var vertex = new Vector3();
  18339. var groupCount = 0;
  18340. // this will be used to calculate the normal
  18341. var slope = ( radiusBottom - radiusTop ) / height;
  18342. // generate vertices, normals and uvs
  18343. for ( y = 0; y <= heightSegments; y ++ ) {
  18344. var indexRow = [];
  18345. var v = y / heightSegments;
  18346. // calculate the radius of the current row
  18347. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  18348. for ( x = 0; x <= radialSegments; x ++ ) {
  18349. var u = x / radialSegments;
  18350. var theta = u * thetaLength + thetaStart;
  18351. var sinTheta = Math.sin( theta );
  18352. var cosTheta = Math.cos( theta );
  18353. // vertex
  18354. vertex.x = radius * sinTheta;
  18355. vertex.y = - v * height + halfHeight;
  18356. vertex.z = radius * cosTheta;
  18357. vertices.push( vertex.x, vertex.y, vertex.z );
  18358. // normal
  18359. normal.set( sinTheta, slope, cosTheta ).normalize();
  18360. normals.push( normal.x, normal.y, normal.z );
  18361. // uv
  18362. uvs.push( u, 1 - v );
  18363. // save index of vertex in respective row
  18364. indexRow.push( index ++ );
  18365. }
  18366. // now save vertices of the row in our index array
  18367. indexArray.push( indexRow );
  18368. }
  18369. // generate indices
  18370. for ( x = 0; x < radialSegments; x ++ ) {
  18371. for ( y = 0; y < heightSegments; y ++ ) {
  18372. // we use the index array to access the correct indices
  18373. var a = indexArray[ y ][ x ];
  18374. var b = indexArray[ y + 1 ][ x ];
  18375. var c = indexArray[ y + 1 ][ x + 1 ];
  18376. var d = indexArray[ y ][ x + 1 ];
  18377. // faces
  18378. indices.push( a, b, d );
  18379. indices.push( b, c, d );
  18380. // update group counter
  18381. groupCount += 6;
  18382. }
  18383. }
  18384. // add a group to the geometry. this will ensure multi material support
  18385. scope.addGroup( groupStart, groupCount, 0 );
  18386. // calculate new start value for groups
  18387. groupStart += groupCount;
  18388. }
  18389. function generateCap( top ) {
  18390. var x, centerIndexStart, centerIndexEnd;
  18391. var uv = new Vector2();
  18392. var vertex = new Vector3();
  18393. var groupCount = 0;
  18394. var radius = ( top === true ) ? radiusTop : radiusBottom;
  18395. var sign = ( top === true ) ? 1 : - 1;
  18396. // save the index of the first center vertex
  18397. centerIndexStart = index;
  18398. // first we generate the center vertex data of the cap.
  18399. // because the geometry needs one set of uvs per face,
  18400. // we must generate a center vertex per face/segment
  18401. for ( x = 1; x <= radialSegments; x ++ ) {
  18402. // vertex
  18403. vertices.push( 0, halfHeight * sign, 0 );
  18404. // normal
  18405. normals.push( 0, sign, 0 );
  18406. // uv
  18407. uvs.push( 0.5, 0.5 );
  18408. // increase index
  18409. index ++;
  18410. }
  18411. // save the index of the last center vertex
  18412. centerIndexEnd = index;
  18413. // now we generate the surrounding vertices, normals and uvs
  18414. for ( x = 0; x <= radialSegments; x ++ ) {
  18415. var u = x / radialSegments;
  18416. var theta = u * thetaLength + thetaStart;
  18417. var cosTheta = Math.cos( theta );
  18418. var sinTheta = Math.sin( theta );
  18419. // vertex
  18420. vertex.x = radius * sinTheta;
  18421. vertex.y = halfHeight * sign;
  18422. vertex.z = radius * cosTheta;
  18423. vertices.push( vertex.x, vertex.y, vertex.z );
  18424. // normal
  18425. normals.push( 0, sign, 0 );
  18426. // uv
  18427. uv.x = ( cosTheta * 0.5 ) + 0.5;
  18428. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  18429. uvs.push( uv.x, uv.y );
  18430. // increase index
  18431. index ++;
  18432. }
  18433. // generate indices
  18434. for ( x = 0; x < radialSegments; x ++ ) {
  18435. var c = centerIndexStart + x;
  18436. var i = centerIndexEnd + x;
  18437. if ( top === true ) {
  18438. // face top
  18439. indices.push( i, i + 1, c );
  18440. } else {
  18441. // face bottom
  18442. indices.push( i + 1, i, c );
  18443. }
  18444. groupCount += 3;
  18445. }
  18446. // add a group to the geometry. this will ensure multi material support
  18447. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  18448. // calculate new start value for groups
  18449. groupStart += groupCount;
  18450. }
  18451. }
  18452. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18453. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  18454. /**
  18455. * @author abelnation / http://github.com/abelnation
  18456. */
  18457. // ConeGeometry
  18458. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18459. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  18460. this.type = 'ConeGeometry';
  18461. this.parameters = {
  18462. radius: radius,
  18463. height: height,
  18464. radialSegments: radialSegments,
  18465. heightSegments: heightSegments,
  18466. openEnded: openEnded,
  18467. thetaStart: thetaStart,
  18468. thetaLength: thetaLength
  18469. };
  18470. }
  18471. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  18472. ConeGeometry.prototype.constructor = ConeGeometry;
  18473. // ConeBufferGeometry
  18474. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18475. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  18476. this.type = 'ConeBufferGeometry';
  18477. this.parameters = {
  18478. radius: radius,
  18479. height: height,
  18480. radialSegments: radialSegments,
  18481. heightSegments: heightSegments,
  18482. openEnded: openEnded,
  18483. thetaStart: thetaStart,
  18484. thetaLength: thetaLength
  18485. };
  18486. }
  18487. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  18488. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  18489. /**
  18490. * @author benaadams / https://twitter.com/ben_a_adams
  18491. * @author Mugen87 / https://github.com/Mugen87
  18492. * @author hughes
  18493. */
  18494. // CircleGeometry
  18495. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  18496. Geometry.call( this );
  18497. this.type = 'CircleGeometry';
  18498. this.parameters = {
  18499. radius: radius,
  18500. segments: segments,
  18501. thetaStart: thetaStart,
  18502. thetaLength: thetaLength
  18503. };
  18504. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  18505. this.mergeVertices();
  18506. }
  18507. CircleGeometry.prototype = Object.create( Geometry.prototype );
  18508. CircleGeometry.prototype.constructor = CircleGeometry;
  18509. // CircleBufferGeometry
  18510. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  18511. BufferGeometry.call( this );
  18512. this.type = 'CircleBufferGeometry';
  18513. this.parameters = {
  18514. radius: radius,
  18515. segments: segments,
  18516. thetaStart: thetaStart,
  18517. thetaLength: thetaLength
  18518. };
  18519. radius = radius || 1;
  18520. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18521. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18522. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18523. // buffers
  18524. var indices = [];
  18525. var vertices = [];
  18526. var normals = [];
  18527. var uvs = [];
  18528. // helper variables
  18529. var i, s;
  18530. var vertex = new Vector3();
  18531. var uv = new Vector2();
  18532. // center point
  18533. vertices.push( 0, 0, 0 );
  18534. normals.push( 0, 0, 1 );
  18535. uvs.push( 0.5, 0.5 );
  18536. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  18537. var segment = thetaStart + s / segments * thetaLength;
  18538. // vertex
  18539. vertex.x = radius * Math.cos( segment );
  18540. vertex.y = radius * Math.sin( segment );
  18541. vertices.push( vertex.x, vertex.y, vertex.z );
  18542. // normal
  18543. normals.push( 0, 0, 1 );
  18544. // uvs
  18545. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  18546. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  18547. uvs.push( uv.x, uv.y );
  18548. }
  18549. // indices
  18550. for ( i = 1; i <= segments; i ++ ) {
  18551. indices.push( i, i + 1, 0 );
  18552. }
  18553. // build geometry
  18554. this.setIndex( indices );
  18555. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18556. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18557. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18558. }
  18559. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18560. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  18561. var Geometries = /*#__PURE__*/Object.freeze({
  18562. WireframeGeometry: WireframeGeometry,
  18563. ParametricGeometry: ParametricGeometry,
  18564. ParametricBufferGeometry: ParametricBufferGeometry,
  18565. TetrahedronGeometry: TetrahedronGeometry,
  18566. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  18567. OctahedronGeometry: OctahedronGeometry,
  18568. OctahedronBufferGeometry: OctahedronBufferGeometry,
  18569. IcosahedronGeometry: IcosahedronGeometry,
  18570. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  18571. DodecahedronGeometry: DodecahedronGeometry,
  18572. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  18573. PolyhedronGeometry: PolyhedronGeometry,
  18574. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  18575. TubeGeometry: TubeGeometry,
  18576. TubeBufferGeometry: TubeBufferGeometry,
  18577. TorusKnotGeometry: TorusKnotGeometry,
  18578. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  18579. TorusGeometry: TorusGeometry,
  18580. TorusBufferGeometry: TorusBufferGeometry,
  18581. TextGeometry: TextGeometry,
  18582. TextBufferGeometry: TextBufferGeometry,
  18583. SphereGeometry: SphereGeometry,
  18584. SphereBufferGeometry: SphereBufferGeometry,
  18585. RingGeometry: RingGeometry,
  18586. RingBufferGeometry: RingBufferGeometry,
  18587. PlaneGeometry: PlaneGeometry,
  18588. PlaneBufferGeometry: PlaneBufferGeometry,
  18589. LatheGeometry: LatheGeometry,
  18590. LatheBufferGeometry: LatheBufferGeometry,
  18591. ShapeGeometry: ShapeGeometry,
  18592. ShapeBufferGeometry: ShapeBufferGeometry,
  18593. ExtrudeGeometry: ExtrudeGeometry,
  18594. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  18595. EdgesGeometry: EdgesGeometry,
  18596. ConeGeometry: ConeGeometry,
  18597. ConeBufferGeometry: ConeBufferGeometry,
  18598. CylinderGeometry: CylinderGeometry,
  18599. CylinderBufferGeometry: CylinderBufferGeometry,
  18600. CircleGeometry: CircleGeometry,
  18601. CircleBufferGeometry: CircleBufferGeometry,
  18602. BoxGeometry: BoxGeometry,
  18603. BoxBufferGeometry: BoxBufferGeometry
  18604. });
  18605. /**
  18606. * @author mrdoob / http://mrdoob.com/
  18607. *
  18608. * parameters = {
  18609. * color: <THREE.Color>
  18610. * }
  18611. */
  18612. function ShadowMaterial( parameters ) {
  18613. Material.call( this );
  18614. this.type = 'ShadowMaterial';
  18615. this.color = new Color( 0x000000 );
  18616. this.transparent = true;
  18617. this.setValues( parameters );
  18618. }
  18619. ShadowMaterial.prototype = Object.create( Material.prototype );
  18620. ShadowMaterial.prototype.constructor = ShadowMaterial;
  18621. ShadowMaterial.prototype.isShadowMaterial = true;
  18622. ShadowMaterial.prototype.copy = function ( source ) {
  18623. Material.prototype.copy.call( this, source );
  18624. this.color.copy( source.color );
  18625. return this;
  18626. };
  18627. /**
  18628. * @author mrdoob / http://mrdoob.com/
  18629. */
  18630. function RawShaderMaterial( parameters ) {
  18631. ShaderMaterial.call( this, parameters );
  18632. this.type = 'RawShaderMaterial';
  18633. }
  18634. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  18635. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  18636. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  18637. /**
  18638. * @author WestLangley / http://github.com/WestLangley
  18639. *
  18640. * parameters = {
  18641. * color: <hex>,
  18642. * roughness: <float>,
  18643. * metalness: <float>,
  18644. * opacity: <float>,
  18645. *
  18646. * map: new THREE.Texture( <Image> ),
  18647. *
  18648. * lightMap: new THREE.Texture( <Image> ),
  18649. * lightMapIntensity: <float>
  18650. *
  18651. * aoMap: new THREE.Texture( <Image> ),
  18652. * aoMapIntensity: <float>
  18653. *
  18654. * emissive: <hex>,
  18655. * emissiveIntensity: <float>
  18656. * emissiveMap: new THREE.Texture( <Image> ),
  18657. *
  18658. * bumpMap: new THREE.Texture( <Image> ),
  18659. * bumpScale: <float>,
  18660. *
  18661. * normalMap: new THREE.Texture( <Image> ),
  18662. * normalMapType: THREE.TangentSpaceNormalMap,
  18663. * normalScale: <Vector2>,
  18664. *
  18665. * displacementMap: new THREE.Texture( <Image> ),
  18666. * displacementScale: <float>,
  18667. * displacementBias: <float>,
  18668. *
  18669. * roughnessMap: new THREE.Texture( <Image> ),
  18670. *
  18671. * metalnessMap: new THREE.Texture( <Image> ),
  18672. *
  18673. * alphaMap: new THREE.Texture( <Image> ),
  18674. *
  18675. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  18676. * envMapIntensity: <float>
  18677. *
  18678. * refractionRatio: <float>,
  18679. *
  18680. * wireframe: <boolean>,
  18681. * wireframeLinewidth: <float>,
  18682. *
  18683. * skinning: <bool>,
  18684. * morphTargets: <bool>,
  18685. * morphNormals: <bool>
  18686. * }
  18687. */
  18688. function MeshStandardMaterial( parameters ) {
  18689. Material.call( this );
  18690. this.defines = { 'STANDARD': '' };
  18691. this.type = 'MeshStandardMaterial';
  18692. this.color = new Color( 0xffffff ); // diffuse
  18693. this.roughness = 0.5;
  18694. this.metalness = 0.5;
  18695. this.map = null;
  18696. this.lightMap = null;
  18697. this.lightMapIntensity = 1.0;
  18698. this.aoMap = null;
  18699. this.aoMapIntensity = 1.0;
  18700. this.emissive = new Color( 0x000000 );
  18701. this.emissiveIntensity = 1.0;
  18702. this.emissiveMap = null;
  18703. this.bumpMap = null;
  18704. this.bumpScale = 1;
  18705. this.normalMap = null;
  18706. this.normalMapType = TangentSpaceNormalMap;
  18707. this.normalScale = new Vector2( 1, 1 );
  18708. this.displacementMap = null;
  18709. this.displacementScale = 1;
  18710. this.displacementBias = 0;
  18711. this.roughnessMap = null;
  18712. this.metalnessMap = null;
  18713. this.alphaMap = null;
  18714. this.envMap = null;
  18715. this.envMapIntensity = 1.0;
  18716. this.refractionRatio = 0.98;
  18717. this.wireframe = false;
  18718. this.wireframeLinewidth = 1;
  18719. this.wireframeLinecap = 'round';
  18720. this.wireframeLinejoin = 'round';
  18721. this.skinning = false;
  18722. this.morphTargets = false;
  18723. this.morphNormals = false;
  18724. this.setValues( parameters );
  18725. }
  18726. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  18727. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  18728. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  18729. MeshStandardMaterial.prototype.copy = function ( source ) {
  18730. Material.prototype.copy.call( this, source );
  18731. this.defines = { 'STANDARD': '' };
  18732. this.color.copy( source.color );
  18733. this.roughness = source.roughness;
  18734. this.metalness = source.metalness;
  18735. this.map = source.map;
  18736. this.lightMap = source.lightMap;
  18737. this.lightMapIntensity = source.lightMapIntensity;
  18738. this.aoMap = source.aoMap;
  18739. this.aoMapIntensity = source.aoMapIntensity;
  18740. this.emissive.copy( source.emissive );
  18741. this.emissiveMap = source.emissiveMap;
  18742. this.emissiveIntensity = source.emissiveIntensity;
  18743. this.bumpMap = source.bumpMap;
  18744. this.bumpScale = source.bumpScale;
  18745. this.normalMap = source.normalMap;
  18746. this.normalMapType = source.normalMapType;
  18747. this.normalScale.copy( source.normalScale );
  18748. this.displacementMap = source.displacementMap;
  18749. this.displacementScale = source.displacementScale;
  18750. this.displacementBias = source.displacementBias;
  18751. this.roughnessMap = source.roughnessMap;
  18752. this.metalnessMap = source.metalnessMap;
  18753. this.alphaMap = source.alphaMap;
  18754. this.envMap = source.envMap;
  18755. this.envMapIntensity = source.envMapIntensity;
  18756. this.refractionRatio = source.refractionRatio;
  18757. this.wireframe = source.wireframe;
  18758. this.wireframeLinewidth = source.wireframeLinewidth;
  18759. this.wireframeLinecap = source.wireframeLinecap;
  18760. this.wireframeLinejoin = source.wireframeLinejoin;
  18761. this.skinning = source.skinning;
  18762. this.morphTargets = source.morphTargets;
  18763. this.morphNormals = source.morphNormals;
  18764. return this;
  18765. };
  18766. /**
  18767. * @author WestLangley / http://github.com/WestLangley
  18768. *
  18769. * parameters = {
  18770. * reflectivity: <float>
  18771. * }
  18772. */
  18773. function MeshPhysicalMaterial( parameters ) {
  18774. MeshStandardMaterial.call( this );
  18775. this.defines = { 'PHYSICAL': '' };
  18776. this.type = 'MeshPhysicalMaterial';
  18777. this.reflectivity = 0.5; // maps to F0 = 0.04
  18778. this.clearCoat = 0.0;
  18779. this.clearCoatRoughness = 0.0;
  18780. this.setValues( parameters );
  18781. }
  18782. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  18783. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  18784. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  18785. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  18786. MeshStandardMaterial.prototype.copy.call( this, source );
  18787. this.defines = { 'PHYSICAL': '' };
  18788. this.reflectivity = source.reflectivity;
  18789. this.clearCoat = source.clearCoat;
  18790. this.clearCoatRoughness = source.clearCoatRoughness;
  18791. return this;
  18792. };
  18793. /**
  18794. * @author mrdoob / http://mrdoob.com/
  18795. * @author alteredq / http://alteredqualia.com/
  18796. *
  18797. * parameters = {
  18798. * color: <hex>,
  18799. * specular: <hex>,
  18800. * shininess: <float>,
  18801. * opacity: <float>,
  18802. *
  18803. * map: new THREE.Texture( <Image> ),
  18804. *
  18805. * lightMap: new THREE.Texture( <Image> ),
  18806. * lightMapIntensity: <float>
  18807. *
  18808. * aoMap: new THREE.Texture( <Image> ),
  18809. * aoMapIntensity: <float>
  18810. *
  18811. * emissive: <hex>,
  18812. * emissiveIntensity: <float>
  18813. * emissiveMap: new THREE.Texture( <Image> ),
  18814. *
  18815. * bumpMap: new THREE.Texture( <Image> ),
  18816. * bumpScale: <float>,
  18817. *
  18818. * normalMap: new THREE.Texture( <Image> ),
  18819. * normalMapType: THREE.TangentSpaceNormalMap,
  18820. * normalScale: <Vector2>,
  18821. *
  18822. * displacementMap: new THREE.Texture( <Image> ),
  18823. * displacementScale: <float>,
  18824. * displacementBias: <float>,
  18825. *
  18826. * specularMap: new THREE.Texture( <Image> ),
  18827. *
  18828. * alphaMap: new THREE.Texture( <Image> ),
  18829. *
  18830. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  18831. * combine: THREE.Multiply,
  18832. * reflectivity: <float>,
  18833. * refractionRatio: <float>,
  18834. *
  18835. * wireframe: <boolean>,
  18836. * wireframeLinewidth: <float>,
  18837. *
  18838. * skinning: <bool>,
  18839. * morphTargets: <bool>,
  18840. * morphNormals: <bool>
  18841. * }
  18842. */
  18843. function MeshPhongMaterial( parameters ) {
  18844. Material.call( this );
  18845. this.type = 'MeshPhongMaterial';
  18846. this.color = new Color( 0xffffff ); // diffuse
  18847. this.specular = new Color( 0x111111 );
  18848. this.shininess = 30;
  18849. this.map = null;
  18850. this.lightMap = null;
  18851. this.lightMapIntensity = 1.0;
  18852. this.aoMap = null;
  18853. this.aoMapIntensity = 1.0;
  18854. this.emissive = new Color( 0x000000 );
  18855. this.emissiveIntensity = 1.0;
  18856. this.emissiveMap = null;
  18857. this.bumpMap = null;
  18858. this.bumpScale = 1;
  18859. this.normalMap = null;
  18860. this.normalMapType = TangentSpaceNormalMap;
  18861. this.normalScale = new Vector2( 1, 1 );
  18862. this.displacementMap = null;
  18863. this.displacementScale = 1;
  18864. this.displacementBias = 0;
  18865. this.specularMap = null;
  18866. this.alphaMap = null;
  18867. this.envMap = null;
  18868. this.combine = MultiplyOperation;
  18869. this.reflectivity = 1;
  18870. this.refractionRatio = 0.98;
  18871. this.wireframe = false;
  18872. this.wireframeLinewidth = 1;
  18873. this.wireframeLinecap = 'round';
  18874. this.wireframeLinejoin = 'round';
  18875. this.skinning = false;
  18876. this.morphTargets = false;
  18877. this.morphNormals = false;
  18878. this.setValues( parameters );
  18879. }
  18880. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  18881. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  18882. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  18883. MeshPhongMaterial.prototype.copy = function ( source ) {
  18884. Material.prototype.copy.call( this, source );
  18885. this.color.copy( source.color );
  18886. this.specular.copy( source.specular );
  18887. this.shininess = source.shininess;
  18888. this.map = source.map;
  18889. this.lightMap = source.lightMap;
  18890. this.lightMapIntensity = source.lightMapIntensity;
  18891. this.aoMap = source.aoMap;
  18892. this.aoMapIntensity = source.aoMapIntensity;
  18893. this.emissive.copy( source.emissive );
  18894. this.emissiveMap = source.emissiveMap;
  18895. this.emissiveIntensity = source.emissiveIntensity;
  18896. this.bumpMap = source.bumpMap;
  18897. this.bumpScale = source.bumpScale;
  18898. this.normalMap = source.normalMap;
  18899. this.normalMapType = source.normalMapType;
  18900. this.normalScale.copy( source.normalScale );
  18901. this.displacementMap = source.displacementMap;
  18902. this.displacementScale = source.displacementScale;
  18903. this.displacementBias = source.displacementBias;
  18904. this.specularMap = source.specularMap;
  18905. this.alphaMap = source.alphaMap;
  18906. this.envMap = source.envMap;
  18907. this.combine = source.combine;
  18908. this.reflectivity = source.reflectivity;
  18909. this.refractionRatio = source.refractionRatio;
  18910. this.wireframe = source.wireframe;
  18911. this.wireframeLinewidth = source.wireframeLinewidth;
  18912. this.wireframeLinecap = source.wireframeLinecap;
  18913. this.wireframeLinejoin = source.wireframeLinejoin;
  18914. this.skinning = source.skinning;
  18915. this.morphTargets = source.morphTargets;
  18916. this.morphNormals = source.morphNormals;
  18917. return this;
  18918. };
  18919. /**
  18920. * @author takahirox / http://github.com/takahirox
  18921. *
  18922. * parameters = {
  18923. * gradientMap: new THREE.Texture( <Image> )
  18924. * }
  18925. */
  18926. function MeshToonMaterial( parameters ) {
  18927. MeshPhongMaterial.call( this );
  18928. this.defines = { 'TOON': '' };
  18929. this.type = 'MeshToonMaterial';
  18930. this.gradientMap = null;
  18931. this.setValues( parameters );
  18932. }
  18933. MeshToonMaterial.prototype = Object.create( MeshPhongMaterial.prototype );
  18934. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  18935. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  18936. MeshToonMaterial.prototype.copy = function ( source ) {
  18937. MeshPhongMaterial.prototype.copy.call( this, source );
  18938. this.gradientMap = source.gradientMap;
  18939. return this;
  18940. };
  18941. /**
  18942. * @author mrdoob / http://mrdoob.com/
  18943. * @author WestLangley / http://github.com/WestLangley
  18944. *
  18945. * parameters = {
  18946. * opacity: <float>,
  18947. *
  18948. * bumpMap: new THREE.Texture( <Image> ),
  18949. * bumpScale: <float>,
  18950. *
  18951. * normalMap: new THREE.Texture( <Image> ),
  18952. * normalMapType: THREE.TangentSpaceNormalMap,
  18953. * normalScale: <Vector2>,
  18954. *
  18955. * displacementMap: new THREE.Texture( <Image> ),
  18956. * displacementScale: <float>,
  18957. * displacementBias: <float>,
  18958. *
  18959. * wireframe: <boolean>,
  18960. * wireframeLinewidth: <float>
  18961. *
  18962. * skinning: <bool>,
  18963. * morphTargets: <bool>,
  18964. * morphNormals: <bool>
  18965. * }
  18966. */
  18967. function MeshNormalMaterial( parameters ) {
  18968. Material.call( this );
  18969. this.type = 'MeshNormalMaterial';
  18970. this.bumpMap = null;
  18971. this.bumpScale = 1;
  18972. this.normalMap = null;
  18973. this.normalMapType = TangentSpaceNormalMap;
  18974. this.normalScale = new Vector2( 1, 1 );
  18975. this.displacementMap = null;
  18976. this.displacementScale = 1;
  18977. this.displacementBias = 0;
  18978. this.wireframe = false;
  18979. this.wireframeLinewidth = 1;
  18980. this.fog = false;
  18981. this.lights = false;
  18982. this.skinning = false;
  18983. this.morphTargets = false;
  18984. this.morphNormals = false;
  18985. this.setValues( parameters );
  18986. }
  18987. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  18988. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  18989. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  18990. MeshNormalMaterial.prototype.copy = function ( source ) {
  18991. Material.prototype.copy.call( this, source );
  18992. this.bumpMap = source.bumpMap;
  18993. this.bumpScale = source.bumpScale;
  18994. this.normalMap = source.normalMap;
  18995. this.normalMapType = source.normalMapType;
  18996. this.normalScale.copy( source.normalScale );
  18997. this.displacementMap = source.displacementMap;
  18998. this.displacementScale = source.displacementScale;
  18999. this.displacementBias = source.displacementBias;
  19000. this.wireframe = source.wireframe;
  19001. this.wireframeLinewidth = source.wireframeLinewidth;
  19002. this.skinning = source.skinning;
  19003. this.morphTargets = source.morphTargets;
  19004. this.morphNormals = source.morphNormals;
  19005. return this;
  19006. };
  19007. /**
  19008. * @author mrdoob / http://mrdoob.com/
  19009. * @author alteredq / http://alteredqualia.com/
  19010. *
  19011. * parameters = {
  19012. * color: <hex>,
  19013. * opacity: <float>,
  19014. *
  19015. * map: new THREE.Texture( <Image> ),
  19016. *
  19017. * lightMap: new THREE.Texture( <Image> ),
  19018. * lightMapIntensity: <float>
  19019. *
  19020. * aoMap: new THREE.Texture( <Image> ),
  19021. * aoMapIntensity: <float>
  19022. *
  19023. * emissive: <hex>,
  19024. * emissiveIntensity: <float>
  19025. * emissiveMap: new THREE.Texture( <Image> ),
  19026. *
  19027. * specularMap: new THREE.Texture( <Image> ),
  19028. *
  19029. * alphaMap: new THREE.Texture( <Image> ),
  19030. *
  19031. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19032. * combine: THREE.Multiply,
  19033. * reflectivity: <float>,
  19034. * refractionRatio: <float>,
  19035. *
  19036. * wireframe: <boolean>,
  19037. * wireframeLinewidth: <float>,
  19038. *
  19039. * skinning: <bool>,
  19040. * morphTargets: <bool>,
  19041. * morphNormals: <bool>
  19042. * }
  19043. */
  19044. function MeshLambertMaterial( parameters ) {
  19045. Material.call( this );
  19046. this.type = 'MeshLambertMaterial';
  19047. this.color = new Color( 0xffffff ); // diffuse
  19048. this.map = null;
  19049. this.lightMap = null;
  19050. this.lightMapIntensity = 1.0;
  19051. this.aoMap = null;
  19052. this.aoMapIntensity = 1.0;
  19053. this.emissive = new Color( 0x000000 );
  19054. this.emissiveIntensity = 1.0;
  19055. this.emissiveMap = null;
  19056. this.specularMap = null;
  19057. this.alphaMap = null;
  19058. this.envMap = null;
  19059. this.combine = MultiplyOperation;
  19060. this.reflectivity = 1;
  19061. this.refractionRatio = 0.98;
  19062. this.wireframe = false;
  19063. this.wireframeLinewidth = 1;
  19064. this.wireframeLinecap = 'round';
  19065. this.wireframeLinejoin = 'round';
  19066. this.skinning = false;
  19067. this.morphTargets = false;
  19068. this.morphNormals = false;
  19069. this.setValues( parameters );
  19070. }
  19071. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  19072. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  19073. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  19074. MeshLambertMaterial.prototype.copy = function ( source ) {
  19075. Material.prototype.copy.call( this, source );
  19076. this.color.copy( source.color );
  19077. this.map = source.map;
  19078. this.lightMap = source.lightMap;
  19079. this.lightMapIntensity = source.lightMapIntensity;
  19080. this.aoMap = source.aoMap;
  19081. this.aoMapIntensity = source.aoMapIntensity;
  19082. this.emissive.copy( source.emissive );
  19083. this.emissiveMap = source.emissiveMap;
  19084. this.emissiveIntensity = source.emissiveIntensity;
  19085. this.specularMap = source.specularMap;
  19086. this.alphaMap = source.alphaMap;
  19087. this.envMap = source.envMap;
  19088. this.combine = source.combine;
  19089. this.reflectivity = source.reflectivity;
  19090. this.refractionRatio = source.refractionRatio;
  19091. this.wireframe = source.wireframe;
  19092. this.wireframeLinewidth = source.wireframeLinewidth;
  19093. this.wireframeLinecap = source.wireframeLinecap;
  19094. this.wireframeLinejoin = source.wireframeLinejoin;
  19095. this.skinning = source.skinning;
  19096. this.morphTargets = source.morphTargets;
  19097. this.morphNormals = source.morphNormals;
  19098. return this;
  19099. };
  19100. /**
  19101. * @author WestLangley / http://github.com/WestLangley
  19102. *
  19103. * parameters = {
  19104. * color: <hex>,
  19105. * opacity: <float>,
  19106. *
  19107. * matcap: new THREE.Texture( <Image> ),
  19108. *
  19109. * map: new THREE.Texture( <Image> ),
  19110. *
  19111. * bumpMap: new THREE.Texture( <Image> ),
  19112. * bumpScale: <float>,
  19113. *
  19114. * normalMap: new THREE.Texture( <Image> ),
  19115. * normalMapType: THREE.TangentSpaceNormalMap,
  19116. * normalScale: <Vector2>,
  19117. *
  19118. * displacementMap: new THREE.Texture( <Image> ),
  19119. * displacementScale: <float>,
  19120. * displacementBias: <float>,
  19121. *
  19122. * alphaMap: new THREE.Texture( <Image> ),
  19123. *
  19124. * skinning: <bool>,
  19125. * morphTargets: <bool>,
  19126. * morphNormals: <bool>
  19127. * }
  19128. */
  19129. function MeshMatcapMaterial( parameters ) {
  19130. Material.call( this );
  19131. this.defines = { 'MATCAP': '' };
  19132. this.type = 'MeshMatcapMaterial';
  19133. this.color = new Color( 0xffffff ); // diffuse
  19134. this.matcap = null;
  19135. this.map = null;
  19136. this.bumpMap = null;
  19137. this.bumpScale = 1;
  19138. this.normalMap = null;
  19139. this.normalMapType = TangentSpaceNormalMap;
  19140. this.normalScale = new Vector2( 1, 1 );
  19141. this.displacementMap = null;
  19142. this.displacementScale = 1;
  19143. this.displacementBias = 0;
  19144. this.alphaMap = null;
  19145. this.skinning = false;
  19146. this.morphTargets = false;
  19147. this.morphNormals = false;
  19148. this.lights = false;
  19149. this.setValues( parameters );
  19150. }
  19151. MeshMatcapMaterial.prototype = Object.create( Material.prototype );
  19152. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  19153. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  19154. MeshMatcapMaterial.prototype.copy = function ( source ) {
  19155. Material.prototype.copy.call( this, source );
  19156. this.defines = { 'MATCAP': '' };
  19157. this.color.copy( source.color );
  19158. this.matcap = source.matcap;
  19159. this.map = source.map;
  19160. this.bumpMap = source.bumpMap;
  19161. this.bumpScale = source.bumpScale;
  19162. this.normalMap = source.normalMap;
  19163. this.normalMapType = source.normalMapType;
  19164. this.normalScale.copy( source.normalScale );
  19165. this.displacementMap = source.displacementMap;
  19166. this.displacementScale = source.displacementScale;
  19167. this.displacementBias = source.displacementBias;
  19168. this.alphaMap = source.alphaMap;
  19169. this.skinning = source.skinning;
  19170. this.morphTargets = source.morphTargets;
  19171. this.morphNormals = source.morphNormals;
  19172. return this;
  19173. };
  19174. /**
  19175. * @author alteredq / http://alteredqualia.com/
  19176. *
  19177. * parameters = {
  19178. * color: <hex>,
  19179. * opacity: <float>,
  19180. *
  19181. * linewidth: <float>,
  19182. *
  19183. * scale: <float>,
  19184. * dashSize: <float>,
  19185. * gapSize: <float>
  19186. * }
  19187. */
  19188. function LineDashedMaterial( parameters ) {
  19189. LineBasicMaterial.call( this );
  19190. this.type = 'LineDashedMaterial';
  19191. this.scale = 1;
  19192. this.dashSize = 3;
  19193. this.gapSize = 1;
  19194. this.setValues( parameters );
  19195. }
  19196. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  19197. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  19198. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  19199. LineDashedMaterial.prototype.copy = function ( source ) {
  19200. LineBasicMaterial.prototype.copy.call( this, source );
  19201. this.scale = source.scale;
  19202. this.dashSize = source.dashSize;
  19203. this.gapSize = source.gapSize;
  19204. return this;
  19205. };
  19206. var Materials = /*#__PURE__*/Object.freeze({
  19207. ShadowMaterial: ShadowMaterial,
  19208. SpriteMaterial: SpriteMaterial,
  19209. RawShaderMaterial: RawShaderMaterial,
  19210. ShaderMaterial: ShaderMaterial,
  19211. PointsMaterial: PointsMaterial,
  19212. MeshPhysicalMaterial: MeshPhysicalMaterial,
  19213. MeshStandardMaterial: MeshStandardMaterial,
  19214. MeshPhongMaterial: MeshPhongMaterial,
  19215. MeshToonMaterial: MeshToonMaterial,
  19216. MeshNormalMaterial: MeshNormalMaterial,
  19217. MeshLambertMaterial: MeshLambertMaterial,
  19218. MeshDepthMaterial: MeshDepthMaterial,
  19219. MeshDistanceMaterial: MeshDistanceMaterial,
  19220. MeshBasicMaterial: MeshBasicMaterial,
  19221. MeshMatcapMaterial: MeshMatcapMaterial,
  19222. LineDashedMaterial: LineDashedMaterial,
  19223. LineBasicMaterial: LineBasicMaterial,
  19224. Material: Material
  19225. });
  19226. /**
  19227. * @author tschw
  19228. * @author Ben Houston / http://clara.io/
  19229. * @author David Sarno / http://lighthaus.us/
  19230. */
  19231. var AnimationUtils = {
  19232. // same as Array.prototype.slice, but also works on typed arrays
  19233. arraySlice: function ( array, from, to ) {
  19234. if ( AnimationUtils.isTypedArray( array ) ) {
  19235. // in ios9 array.subarray(from, undefined) will return empty array
  19236. // but array.subarray(from) or array.subarray(from, len) is correct
  19237. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  19238. }
  19239. return array.slice( from, to );
  19240. },
  19241. // converts an array to a specific type
  19242. convertArray: function ( array, type, forceClone ) {
  19243. if ( ! array || // let 'undefined' and 'null' pass
  19244. ! forceClone && array.constructor === type ) return array;
  19245. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  19246. return new type( array ); // create typed array
  19247. }
  19248. return Array.prototype.slice.call( array ); // create Array
  19249. },
  19250. isTypedArray: function ( object ) {
  19251. return ArrayBuffer.isView( object ) &&
  19252. ! ( object instanceof DataView );
  19253. },
  19254. // returns an array by which times and values can be sorted
  19255. getKeyframeOrder: function ( times ) {
  19256. function compareTime( i, j ) {
  19257. return times[ i ] - times[ j ];
  19258. }
  19259. var n = times.length;
  19260. var result = new Array( n );
  19261. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  19262. result.sort( compareTime );
  19263. return result;
  19264. },
  19265. // uses the array previously returned by 'getKeyframeOrder' to sort data
  19266. sortedArray: function ( values, stride, order ) {
  19267. var nValues = values.length;
  19268. var result = new values.constructor( nValues );
  19269. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  19270. var srcOffset = order[ i ] * stride;
  19271. for ( var j = 0; j !== stride; ++ j ) {
  19272. result[ dstOffset ++ ] = values[ srcOffset + j ];
  19273. }
  19274. }
  19275. return result;
  19276. },
  19277. // function for parsing AOS keyframe formats
  19278. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  19279. var i = 1, key = jsonKeys[ 0 ];
  19280. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  19281. key = jsonKeys[ i ++ ];
  19282. }
  19283. if ( key === undefined ) return; // no data
  19284. var value = key[ valuePropertyName ];
  19285. if ( value === undefined ) return; // no data
  19286. if ( Array.isArray( value ) ) {
  19287. do {
  19288. value = key[ valuePropertyName ];
  19289. if ( value !== undefined ) {
  19290. times.push( key.time );
  19291. values.push.apply( values, value ); // push all elements
  19292. }
  19293. key = jsonKeys[ i ++ ];
  19294. } while ( key !== undefined );
  19295. } else if ( value.toArray !== undefined ) {
  19296. // ...assume THREE.Math-ish
  19297. do {
  19298. value = key[ valuePropertyName ];
  19299. if ( value !== undefined ) {
  19300. times.push( key.time );
  19301. value.toArray( values, values.length );
  19302. }
  19303. key = jsonKeys[ i ++ ];
  19304. } while ( key !== undefined );
  19305. } else {
  19306. // otherwise push as-is
  19307. do {
  19308. value = key[ valuePropertyName ];
  19309. if ( value !== undefined ) {
  19310. times.push( key.time );
  19311. values.push( value );
  19312. }
  19313. key = jsonKeys[ i ++ ];
  19314. } while ( key !== undefined );
  19315. }
  19316. }
  19317. };
  19318. /**
  19319. * Abstract base class of interpolants over parametric samples.
  19320. *
  19321. * The parameter domain is one dimensional, typically the time or a path
  19322. * along a curve defined by the data.
  19323. *
  19324. * The sample values can have any dimensionality and derived classes may
  19325. * apply special interpretations to the data.
  19326. *
  19327. * This class provides the interval seek in a Template Method, deferring
  19328. * the actual interpolation to derived classes.
  19329. *
  19330. * Time complexity is O(1) for linear access crossing at most two points
  19331. * and O(log N) for random access, where N is the number of positions.
  19332. *
  19333. * References:
  19334. *
  19335. * http://www.oodesign.com/template-method-pattern.html
  19336. *
  19337. * @author tschw
  19338. */
  19339. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19340. this.parameterPositions = parameterPositions;
  19341. this._cachedIndex = 0;
  19342. this.resultBuffer = resultBuffer !== undefined ?
  19343. resultBuffer : new sampleValues.constructor( sampleSize );
  19344. this.sampleValues = sampleValues;
  19345. this.valueSize = sampleSize;
  19346. }
  19347. Object.assign( Interpolant.prototype, {
  19348. evaluate: function ( t ) {
  19349. var pp = this.parameterPositions,
  19350. i1 = this._cachedIndex,
  19351. t1 = pp[ i1 ],
  19352. t0 = pp[ i1 - 1 ];
  19353. validate_interval: {
  19354. seek: {
  19355. var right;
  19356. linear_scan: {
  19357. //- See http://jsperf.com/comparison-to-undefined/3
  19358. //- slower code:
  19359. //-
  19360. //- if ( t >= t1 || t1 === undefined ) {
  19361. forward_scan: if ( ! ( t < t1 ) ) {
  19362. for ( var giveUpAt = i1 + 2; ; ) {
  19363. if ( t1 === undefined ) {
  19364. if ( t < t0 ) break forward_scan;
  19365. // after end
  19366. i1 = pp.length;
  19367. this._cachedIndex = i1;
  19368. return this.afterEnd_( i1 - 1, t, t0 );
  19369. }
  19370. if ( i1 === giveUpAt ) break; // this loop
  19371. t0 = t1;
  19372. t1 = pp[ ++ i1 ];
  19373. if ( t < t1 ) {
  19374. // we have arrived at the sought interval
  19375. break seek;
  19376. }
  19377. }
  19378. // prepare binary search on the right side of the index
  19379. right = pp.length;
  19380. break linear_scan;
  19381. }
  19382. //- slower code:
  19383. //- if ( t < t0 || t0 === undefined ) {
  19384. if ( ! ( t >= t0 ) ) {
  19385. // looping?
  19386. var t1global = pp[ 1 ];
  19387. if ( t < t1global ) {
  19388. i1 = 2; // + 1, using the scan for the details
  19389. t0 = t1global;
  19390. }
  19391. // linear reverse scan
  19392. for ( var giveUpAt = i1 - 2; ; ) {
  19393. if ( t0 === undefined ) {
  19394. // before start
  19395. this._cachedIndex = 0;
  19396. return this.beforeStart_( 0, t, t1 );
  19397. }
  19398. if ( i1 === giveUpAt ) break; // this loop
  19399. t1 = t0;
  19400. t0 = pp[ -- i1 - 1 ];
  19401. if ( t >= t0 ) {
  19402. // we have arrived at the sought interval
  19403. break seek;
  19404. }
  19405. }
  19406. // prepare binary search on the left side of the index
  19407. right = i1;
  19408. i1 = 0;
  19409. break linear_scan;
  19410. }
  19411. // the interval is valid
  19412. break validate_interval;
  19413. } // linear scan
  19414. // binary search
  19415. while ( i1 < right ) {
  19416. var mid = ( i1 + right ) >>> 1;
  19417. if ( t < pp[ mid ] ) {
  19418. right = mid;
  19419. } else {
  19420. i1 = mid + 1;
  19421. }
  19422. }
  19423. t1 = pp[ i1 ];
  19424. t0 = pp[ i1 - 1 ];
  19425. // check boundary cases, again
  19426. if ( t0 === undefined ) {
  19427. this._cachedIndex = 0;
  19428. return this.beforeStart_( 0, t, t1 );
  19429. }
  19430. if ( t1 === undefined ) {
  19431. i1 = pp.length;
  19432. this._cachedIndex = i1;
  19433. return this.afterEnd_( i1 - 1, t0, t );
  19434. }
  19435. } // seek
  19436. this._cachedIndex = i1;
  19437. this.intervalChanged_( i1, t0, t1 );
  19438. } // validate_interval
  19439. return this.interpolate_( i1, t0, t, t1 );
  19440. },
  19441. settings: null, // optional, subclass-specific settings structure
  19442. // Note: The indirection allows central control of many interpolants.
  19443. // --- Protected interface
  19444. DefaultSettings_: {},
  19445. getSettings_: function () {
  19446. return this.settings || this.DefaultSettings_;
  19447. },
  19448. copySampleValue_: function ( index ) {
  19449. // copies a sample value to the result buffer
  19450. var result = this.resultBuffer,
  19451. values = this.sampleValues,
  19452. stride = this.valueSize,
  19453. offset = index * stride;
  19454. for ( var i = 0; i !== stride; ++ i ) {
  19455. result[ i ] = values[ offset + i ];
  19456. }
  19457. return result;
  19458. },
  19459. // Template methods for derived classes:
  19460. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  19461. throw new Error( 'call to abstract method' );
  19462. // implementations shall return this.resultBuffer
  19463. },
  19464. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  19465. // empty
  19466. }
  19467. } );
  19468. //!\ DECLARE ALIAS AFTER assign prototype !
  19469. Object.assign( Interpolant.prototype, {
  19470. //( 0, t, t0 ), returns this.resultBuffer
  19471. beforeStart_: Interpolant.prototype.copySampleValue_,
  19472. //( N-1, tN-1, t ), returns this.resultBuffer
  19473. afterEnd_: Interpolant.prototype.copySampleValue_,
  19474. } );
  19475. /**
  19476. * Fast and simple cubic spline interpolant.
  19477. *
  19478. * It was derived from a Hermitian construction setting the first derivative
  19479. * at each sample position to the linear slope between neighboring positions
  19480. * over their parameter interval.
  19481. *
  19482. * @author tschw
  19483. */
  19484. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19485. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19486. this._weightPrev = - 0;
  19487. this._offsetPrev = - 0;
  19488. this._weightNext = - 0;
  19489. this._offsetNext = - 0;
  19490. }
  19491. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19492. constructor: CubicInterpolant,
  19493. DefaultSettings_: {
  19494. endingStart: ZeroCurvatureEnding,
  19495. endingEnd: ZeroCurvatureEnding
  19496. },
  19497. intervalChanged_: function ( i1, t0, t1 ) {
  19498. var pp = this.parameterPositions,
  19499. iPrev = i1 - 2,
  19500. iNext = i1 + 1,
  19501. tPrev = pp[ iPrev ],
  19502. tNext = pp[ iNext ];
  19503. if ( tPrev === undefined ) {
  19504. switch ( this.getSettings_().endingStart ) {
  19505. case ZeroSlopeEnding:
  19506. // f'(t0) = 0
  19507. iPrev = i1;
  19508. tPrev = 2 * t0 - t1;
  19509. break;
  19510. case WrapAroundEnding:
  19511. // use the other end of the curve
  19512. iPrev = pp.length - 2;
  19513. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  19514. break;
  19515. default: // ZeroCurvatureEnding
  19516. // f''(t0) = 0 a.k.a. Natural Spline
  19517. iPrev = i1;
  19518. tPrev = t1;
  19519. }
  19520. }
  19521. if ( tNext === undefined ) {
  19522. switch ( this.getSettings_().endingEnd ) {
  19523. case ZeroSlopeEnding:
  19524. // f'(tN) = 0
  19525. iNext = i1;
  19526. tNext = 2 * t1 - t0;
  19527. break;
  19528. case WrapAroundEnding:
  19529. // use the other end of the curve
  19530. iNext = 1;
  19531. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  19532. break;
  19533. default: // ZeroCurvatureEnding
  19534. // f''(tN) = 0, a.k.a. Natural Spline
  19535. iNext = i1 - 1;
  19536. tNext = t0;
  19537. }
  19538. }
  19539. var halfDt = ( t1 - t0 ) * 0.5,
  19540. stride = this.valueSize;
  19541. this._weightPrev = halfDt / ( t0 - tPrev );
  19542. this._weightNext = halfDt / ( tNext - t1 );
  19543. this._offsetPrev = iPrev * stride;
  19544. this._offsetNext = iNext * stride;
  19545. },
  19546. interpolate_: function ( i1, t0, t, t1 ) {
  19547. var result = this.resultBuffer,
  19548. values = this.sampleValues,
  19549. stride = this.valueSize,
  19550. o1 = i1 * stride, o0 = o1 - stride,
  19551. oP = this._offsetPrev, oN = this._offsetNext,
  19552. wP = this._weightPrev, wN = this._weightNext,
  19553. p = ( t - t0 ) / ( t1 - t0 ),
  19554. pp = p * p,
  19555. ppp = pp * p;
  19556. // evaluate polynomials
  19557. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  19558. var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  19559. var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  19560. var sN = wN * ppp - wN * pp;
  19561. // combine data linearly
  19562. for ( var i = 0; i !== stride; ++ i ) {
  19563. result[ i ] =
  19564. sP * values[ oP + i ] +
  19565. s0 * values[ o0 + i ] +
  19566. s1 * values[ o1 + i ] +
  19567. sN * values[ oN + i ];
  19568. }
  19569. return result;
  19570. }
  19571. } );
  19572. /**
  19573. * @author tschw
  19574. */
  19575. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19576. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19577. }
  19578. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19579. constructor: LinearInterpolant,
  19580. interpolate_: function ( i1, t0, t, t1 ) {
  19581. var result = this.resultBuffer,
  19582. values = this.sampleValues,
  19583. stride = this.valueSize,
  19584. offset1 = i1 * stride,
  19585. offset0 = offset1 - stride,
  19586. weight1 = ( t - t0 ) / ( t1 - t0 ),
  19587. weight0 = 1 - weight1;
  19588. for ( var i = 0; i !== stride; ++ i ) {
  19589. result[ i ] =
  19590. values[ offset0 + i ] * weight0 +
  19591. values[ offset1 + i ] * weight1;
  19592. }
  19593. return result;
  19594. }
  19595. } );
  19596. /**
  19597. *
  19598. * Interpolant that evaluates to the sample value at the position preceeding
  19599. * the parameter.
  19600. *
  19601. * @author tschw
  19602. */
  19603. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19604. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19605. }
  19606. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19607. constructor: DiscreteInterpolant,
  19608. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  19609. return this.copySampleValue_( i1 - 1 );
  19610. }
  19611. } );
  19612. /**
  19613. *
  19614. * A timed sequence of keyframes for a specific property.
  19615. *
  19616. *
  19617. * @author Ben Houston / http://clara.io/
  19618. * @author David Sarno / http://lighthaus.us/
  19619. * @author tschw
  19620. */
  19621. function KeyframeTrack( name, times, values, interpolation ) {
  19622. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  19623. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  19624. this.name = name;
  19625. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  19626. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  19627. this.setInterpolation( interpolation || this.DefaultInterpolation );
  19628. }
  19629. // Static methods
  19630. Object.assign( KeyframeTrack, {
  19631. // Serialization (in static context, because of constructor invocation
  19632. // and automatic invocation of .toJSON):
  19633. toJSON: function ( track ) {
  19634. var trackType = track.constructor;
  19635. var json;
  19636. // derived classes can define a static toJSON method
  19637. if ( trackType.toJSON !== undefined ) {
  19638. json = trackType.toJSON( track );
  19639. } else {
  19640. // by default, we assume the data can be serialized as-is
  19641. json = {
  19642. 'name': track.name,
  19643. 'times': AnimationUtils.convertArray( track.times, Array ),
  19644. 'values': AnimationUtils.convertArray( track.values, Array )
  19645. };
  19646. var interpolation = track.getInterpolation();
  19647. if ( interpolation !== track.DefaultInterpolation ) {
  19648. json.interpolation = interpolation;
  19649. }
  19650. }
  19651. json.type = track.ValueTypeName; // mandatory
  19652. return json;
  19653. }
  19654. } );
  19655. Object.assign( KeyframeTrack.prototype, {
  19656. constructor: KeyframeTrack,
  19657. TimeBufferType: Float32Array,
  19658. ValueBufferType: Float32Array,
  19659. DefaultInterpolation: InterpolateLinear,
  19660. InterpolantFactoryMethodDiscrete: function ( result ) {
  19661. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  19662. },
  19663. InterpolantFactoryMethodLinear: function ( result ) {
  19664. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  19665. },
  19666. InterpolantFactoryMethodSmooth: function ( result ) {
  19667. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  19668. },
  19669. setInterpolation: function ( interpolation ) {
  19670. var factoryMethod;
  19671. switch ( interpolation ) {
  19672. case InterpolateDiscrete:
  19673. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  19674. break;
  19675. case InterpolateLinear:
  19676. factoryMethod = this.InterpolantFactoryMethodLinear;
  19677. break;
  19678. case InterpolateSmooth:
  19679. factoryMethod = this.InterpolantFactoryMethodSmooth;
  19680. break;
  19681. }
  19682. if ( factoryMethod === undefined ) {
  19683. var message = "unsupported interpolation for " +
  19684. this.ValueTypeName + " keyframe track named " + this.name;
  19685. if ( this.createInterpolant === undefined ) {
  19686. // fall back to default, unless the default itself is messed up
  19687. if ( interpolation !== this.DefaultInterpolation ) {
  19688. this.setInterpolation( this.DefaultInterpolation );
  19689. } else {
  19690. throw new Error( message ); // fatal, in this case
  19691. }
  19692. }
  19693. console.warn( 'THREE.KeyframeTrack:', message );
  19694. return this;
  19695. }
  19696. this.createInterpolant = factoryMethod;
  19697. return this;
  19698. },
  19699. getInterpolation: function () {
  19700. switch ( this.createInterpolant ) {
  19701. case this.InterpolantFactoryMethodDiscrete:
  19702. return InterpolateDiscrete;
  19703. case this.InterpolantFactoryMethodLinear:
  19704. return InterpolateLinear;
  19705. case this.InterpolantFactoryMethodSmooth:
  19706. return InterpolateSmooth;
  19707. }
  19708. },
  19709. getValueSize: function () {
  19710. return this.values.length / this.times.length;
  19711. },
  19712. // move all keyframes either forwards or backwards in time
  19713. shift: function ( timeOffset ) {
  19714. if ( timeOffset !== 0.0 ) {
  19715. var times = this.times;
  19716. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  19717. times[ i ] += timeOffset;
  19718. }
  19719. }
  19720. return this;
  19721. },
  19722. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  19723. scale: function ( timeScale ) {
  19724. if ( timeScale !== 1.0 ) {
  19725. var times = this.times;
  19726. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  19727. times[ i ] *= timeScale;
  19728. }
  19729. }
  19730. return this;
  19731. },
  19732. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  19733. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  19734. trim: function ( startTime, endTime ) {
  19735. var times = this.times,
  19736. nKeys = times.length,
  19737. from = 0,
  19738. to = nKeys - 1;
  19739. while ( from !== nKeys && times[ from ] < startTime ) {
  19740. ++ from;
  19741. }
  19742. while ( to !== - 1 && times[ to ] > endTime ) {
  19743. -- to;
  19744. }
  19745. ++ to; // inclusive -> exclusive bound
  19746. if ( from !== 0 || to !== nKeys ) {
  19747. // empty tracks are forbidden, so keep at least one keyframe
  19748. if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
  19749. var stride = this.getValueSize();
  19750. this.times = AnimationUtils.arraySlice( times, from, to );
  19751. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  19752. }
  19753. return this;
  19754. },
  19755. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  19756. validate: function () {
  19757. var valid = true;
  19758. var valueSize = this.getValueSize();
  19759. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  19760. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  19761. valid = false;
  19762. }
  19763. var times = this.times,
  19764. values = this.values,
  19765. nKeys = times.length;
  19766. if ( nKeys === 0 ) {
  19767. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  19768. valid = false;
  19769. }
  19770. var prevTime = null;
  19771. for ( var i = 0; i !== nKeys; i ++ ) {
  19772. var currTime = times[ i ];
  19773. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  19774. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  19775. valid = false;
  19776. break;
  19777. }
  19778. if ( prevTime !== null && prevTime > currTime ) {
  19779. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  19780. valid = false;
  19781. break;
  19782. }
  19783. prevTime = currTime;
  19784. }
  19785. if ( values !== undefined ) {
  19786. if ( AnimationUtils.isTypedArray( values ) ) {
  19787. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  19788. var value = values[ i ];
  19789. if ( isNaN( value ) ) {
  19790. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  19791. valid = false;
  19792. break;
  19793. }
  19794. }
  19795. }
  19796. }
  19797. return valid;
  19798. },
  19799. // removes equivalent sequential keys as common in morph target sequences
  19800. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  19801. optimize: function () {
  19802. var times = this.times,
  19803. values = this.values,
  19804. stride = this.getValueSize(),
  19805. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  19806. writeIndex = 1,
  19807. lastIndex = times.length - 1;
  19808. for ( var i = 1; i < lastIndex; ++ i ) {
  19809. var keep = false;
  19810. var time = times[ i ];
  19811. var timeNext = times[ i + 1 ];
  19812. // remove adjacent keyframes scheduled at the same time
  19813. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  19814. if ( ! smoothInterpolation ) {
  19815. // remove unnecessary keyframes same as their neighbors
  19816. var offset = i * stride,
  19817. offsetP = offset - stride,
  19818. offsetN = offset + stride;
  19819. for ( var j = 0; j !== stride; ++ j ) {
  19820. var value = values[ offset + j ];
  19821. if ( value !== values[ offsetP + j ] ||
  19822. value !== values[ offsetN + j ] ) {
  19823. keep = true;
  19824. break;
  19825. }
  19826. }
  19827. } else {
  19828. keep = true;
  19829. }
  19830. }
  19831. // in-place compaction
  19832. if ( keep ) {
  19833. if ( i !== writeIndex ) {
  19834. times[ writeIndex ] = times[ i ];
  19835. var readOffset = i * stride,
  19836. writeOffset = writeIndex * stride;
  19837. for ( var j = 0; j !== stride; ++ j ) {
  19838. values[ writeOffset + j ] = values[ readOffset + j ];
  19839. }
  19840. }
  19841. ++ writeIndex;
  19842. }
  19843. }
  19844. // flush last keyframe (compaction looks ahead)
  19845. if ( lastIndex > 0 ) {
  19846. times[ writeIndex ] = times[ lastIndex ];
  19847. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  19848. values[ writeOffset + j ] = values[ readOffset + j ];
  19849. }
  19850. ++ writeIndex;
  19851. }
  19852. if ( writeIndex !== times.length ) {
  19853. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  19854. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  19855. }
  19856. return this;
  19857. }
  19858. } );
  19859. /**
  19860. *
  19861. * A Track of Boolean keyframe values.
  19862. *
  19863. *
  19864. * @author Ben Houston / http://clara.io/
  19865. * @author David Sarno / http://lighthaus.us/
  19866. * @author tschw
  19867. */
  19868. function BooleanKeyframeTrack( name, times, values ) {
  19869. KeyframeTrack.call( this, name, times, values );
  19870. }
  19871. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  19872. constructor: BooleanKeyframeTrack,
  19873. ValueTypeName: 'bool',
  19874. ValueBufferType: Array,
  19875. DefaultInterpolation: InterpolateDiscrete,
  19876. InterpolantFactoryMethodLinear: undefined,
  19877. InterpolantFactoryMethodSmooth: undefined
  19878. // Note: Actually this track could have a optimized / compressed
  19879. // representation of a single value and a custom interpolant that
  19880. // computes "firstValue ^ isOdd( index )".
  19881. } );
  19882. /**
  19883. *
  19884. * A Track of keyframe values that represent color.
  19885. *
  19886. *
  19887. * @author Ben Houston / http://clara.io/
  19888. * @author David Sarno / http://lighthaus.us/
  19889. * @author tschw
  19890. */
  19891. function ColorKeyframeTrack( name, times, values, interpolation ) {
  19892. KeyframeTrack.call( this, name, times, values, interpolation );
  19893. }
  19894. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  19895. constructor: ColorKeyframeTrack,
  19896. ValueTypeName: 'color'
  19897. // ValueBufferType is inherited
  19898. // DefaultInterpolation is inherited
  19899. // Note: Very basic implementation and nothing special yet.
  19900. // However, this is the place for color space parameterization.
  19901. } );
  19902. /**
  19903. *
  19904. * A Track of numeric keyframe values.
  19905. *
  19906. * @author Ben Houston / http://clara.io/
  19907. * @author David Sarno / http://lighthaus.us/
  19908. * @author tschw
  19909. */
  19910. function NumberKeyframeTrack( name, times, values, interpolation ) {
  19911. KeyframeTrack.call( this, name, times, values, interpolation );
  19912. }
  19913. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  19914. constructor: NumberKeyframeTrack,
  19915. ValueTypeName: 'number'
  19916. // ValueBufferType is inherited
  19917. // DefaultInterpolation is inherited
  19918. } );
  19919. /**
  19920. * Spherical linear unit quaternion interpolant.
  19921. *
  19922. * @author tschw
  19923. */
  19924. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19925. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19926. }
  19927. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19928. constructor: QuaternionLinearInterpolant,
  19929. interpolate_: function ( i1, t0, t, t1 ) {
  19930. var result = this.resultBuffer,
  19931. values = this.sampleValues,
  19932. stride = this.valueSize,
  19933. offset = i1 * stride,
  19934. alpha = ( t - t0 ) / ( t1 - t0 );
  19935. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  19936. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  19937. }
  19938. return result;
  19939. }
  19940. } );
  19941. /**
  19942. *
  19943. * A Track of quaternion keyframe values.
  19944. *
  19945. * @author Ben Houston / http://clara.io/
  19946. * @author David Sarno / http://lighthaus.us/
  19947. * @author tschw
  19948. */
  19949. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  19950. KeyframeTrack.call( this, name, times, values, interpolation );
  19951. }
  19952. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  19953. constructor: QuaternionKeyframeTrack,
  19954. ValueTypeName: 'quaternion',
  19955. // ValueBufferType is inherited
  19956. DefaultInterpolation: InterpolateLinear,
  19957. InterpolantFactoryMethodLinear: function ( result ) {
  19958. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  19959. },
  19960. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  19961. } );
  19962. /**
  19963. *
  19964. * A Track that interpolates Strings
  19965. *
  19966. *
  19967. * @author Ben Houston / http://clara.io/
  19968. * @author David Sarno / http://lighthaus.us/
  19969. * @author tschw
  19970. */
  19971. function StringKeyframeTrack( name, times, values, interpolation ) {
  19972. KeyframeTrack.call( this, name, times, values, interpolation );
  19973. }
  19974. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  19975. constructor: StringKeyframeTrack,
  19976. ValueTypeName: 'string',
  19977. ValueBufferType: Array,
  19978. DefaultInterpolation: InterpolateDiscrete,
  19979. InterpolantFactoryMethodLinear: undefined,
  19980. InterpolantFactoryMethodSmooth: undefined
  19981. } );
  19982. /**
  19983. *
  19984. * A Track of vectored keyframe values.
  19985. *
  19986. *
  19987. * @author Ben Houston / http://clara.io/
  19988. * @author David Sarno / http://lighthaus.us/
  19989. * @author tschw
  19990. */
  19991. function VectorKeyframeTrack( name, times, values, interpolation ) {
  19992. KeyframeTrack.call( this, name, times, values, interpolation );
  19993. }
  19994. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  19995. constructor: VectorKeyframeTrack,
  19996. ValueTypeName: 'vector'
  19997. // ValueBufferType is inherited
  19998. // DefaultInterpolation is inherited
  19999. } );
  20000. /**
  20001. *
  20002. * Reusable set of Tracks that represent an animation.
  20003. *
  20004. * @author Ben Houston / http://clara.io/
  20005. * @author David Sarno / http://lighthaus.us/
  20006. */
  20007. function AnimationClip( name, duration, tracks ) {
  20008. this.name = name;
  20009. this.tracks = tracks;
  20010. this.duration = ( duration !== undefined ) ? duration : - 1;
  20011. this.uuid = _Math.generateUUID();
  20012. // this means it should figure out its duration by scanning the tracks
  20013. if ( this.duration < 0 ) {
  20014. this.resetDuration();
  20015. }
  20016. }
  20017. function getTrackTypeForValueTypeName( typeName ) {
  20018. switch ( typeName.toLowerCase() ) {
  20019. case 'scalar':
  20020. case 'double':
  20021. case 'float':
  20022. case 'number':
  20023. case 'integer':
  20024. return NumberKeyframeTrack;
  20025. case 'vector':
  20026. case 'vector2':
  20027. case 'vector3':
  20028. case 'vector4':
  20029. return VectorKeyframeTrack;
  20030. case 'color':
  20031. return ColorKeyframeTrack;
  20032. case 'quaternion':
  20033. return QuaternionKeyframeTrack;
  20034. case 'bool':
  20035. case 'boolean':
  20036. return BooleanKeyframeTrack;
  20037. case 'string':
  20038. return StringKeyframeTrack;
  20039. }
  20040. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  20041. }
  20042. function parseKeyframeTrack( json ) {
  20043. if ( json.type === undefined ) {
  20044. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  20045. }
  20046. var trackType = getTrackTypeForValueTypeName( json.type );
  20047. if ( json.times === undefined ) {
  20048. var times = [], values = [];
  20049. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  20050. json.times = times;
  20051. json.values = values;
  20052. }
  20053. // derived classes can define a static parse method
  20054. if ( trackType.parse !== undefined ) {
  20055. return trackType.parse( json );
  20056. } else {
  20057. // by default, we assume a constructor compatible with the base
  20058. return new trackType( json.name, json.times, json.values, json.interpolation );
  20059. }
  20060. }
  20061. Object.assign( AnimationClip, {
  20062. parse: function ( json ) {
  20063. var tracks = [],
  20064. jsonTracks = json.tracks,
  20065. frameTime = 1.0 / ( json.fps || 1.0 );
  20066. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  20067. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  20068. }
  20069. return new AnimationClip( json.name, json.duration, tracks );
  20070. },
  20071. toJSON: function ( clip ) {
  20072. var tracks = [],
  20073. clipTracks = clip.tracks;
  20074. var json = {
  20075. 'name': clip.name,
  20076. 'duration': clip.duration,
  20077. 'tracks': tracks,
  20078. 'uuid': clip.uuid
  20079. };
  20080. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  20081. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  20082. }
  20083. return json;
  20084. },
  20085. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  20086. var numMorphTargets = morphTargetSequence.length;
  20087. var tracks = [];
  20088. for ( var i = 0; i < numMorphTargets; i ++ ) {
  20089. var times = [];
  20090. var values = [];
  20091. times.push(
  20092. ( i + numMorphTargets - 1 ) % numMorphTargets,
  20093. i,
  20094. ( i + 1 ) % numMorphTargets );
  20095. values.push( 0, 1, 0 );
  20096. var order = AnimationUtils.getKeyframeOrder( times );
  20097. times = AnimationUtils.sortedArray( times, 1, order );
  20098. values = AnimationUtils.sortedArray( values, 1, order );
  20099. // if there is a key at the first frame, duplicate it as the
  20100. // last frame as well for perfect loop.
  20101. if ( ! noLoop && times[ 0 ] === 0 ) {
  20102. times.push( numMorphTargets );
  20103. values.push( values[ 0 ] );
  20104. }
  20105. tracks.push(
  20106. new NumberKeyframeTrack(
  20107. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  20108. times, values
  20109. ).scale( 1.0 / fps ) );
  20110. }
  20111. return new AnimationClip( name, - 1, tracks );
  20112. },
  20113. findByName: function ( objectOrClipArray, name ) {
  20114. var clipArray = objectOrClipArray;
  20115. if ( ! Array.isArray( objectOrClipArray ) ) {
  20116. var o = objectOrClipArray;
  20117. clipArray = o.geometry && o.geometry.animations || o.animations;
  20118. }
  20119. for ( var i = 0; i < clipArray.length; i ++ ) {
  20120. if ( clipArray[ i ].name === name ) {
  20121. return clipArray[ i ];
  20122. }
  20123. }
  20124. return null;
  20125. },
  20126. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  20127. var animationToMorphTargets = {};
  20128. // tested with https://regex101.com/ on trick sequences
  20129. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  20130. var pattern = /^([\w-]*?)([\d]+)$/;
  20131. // sort morph target names into animation groups based
  20132. // patterns like Walk_001, Walk_002, Run_001, Run_002
  20133. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  20134. var morphTarget = morphTargets[ i ];
  20135. var parts = morphTarget.name.match( pattern );
  20136. if ( parts && parts.length > 1 ) {
  20137. var name = parts[ 1 ];
  20138. var animationMorphTargets = animationToMorphTargets[ name ];
  20139. if ( ! animationMorphTargets ) {
  20140. animationToMorphTargets[ name ] = animationMorphTargets = [];
  20141. }
  20142. animationMorphTargets.push( morphTarget );
  20143. }
  20144. }
  20145. var clips = [];
  20146. for ( var name in animationToMorphTargets ) {
  20147. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  20148. }
  20149. return clips;
  20150. },
  20151. // parse the animation.hierarchy format
  20152. parseAnimation: function ( animation, bones ) {
  20153. if ( ! animation ) {
  20154. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  20155. return null;
  20156. }
  20157. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  20158. // only return track if there are actually keys.
  20159. if ( animationKeys.length !== 0 ) {
  20160. var times = [];
  20161. var values = [];
  20162. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  20163. // empty keys are filtered out, so check again
  20164. if ( times.length !== 0 ) {
  20165. destTracks.push( new trackType( trackName, times, values ) );
  20166. }
  20167. }
  20168. };
  20169. var tracks = [];
  20170. var clipName = animation.name || 'default';
  20171. // automatic length determination in AnimationClip.
  20172. var duration = animation.length || - 1;
  20173. var fps = animation.fps || 30;
  20174. var hierarchyTracks = animation.hierarchy || [];
  20175. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  20176. var animationKeys = hierarchyTracks[ h ].keys;
  20177. // skip empty tracks
  20178. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  20179. // process morph targets
  20180. if ( animationKeys[ 0 ].morphTargets ) {
  20181. // figure out all morph targets used in this track
  20182. var morphTargetNames = {};
  20183. for ( var k = 0; k < animationKeys.length; k ++ ) {
  20184. if ( animationKeys[ k ].morphTargets ) {
  20185. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  20186. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  20187. }
  20188. }
  20189. }
  20190. // create a track for each morph target with all zero
  20191. // morphTargetInfluences except for the keys in which
  20192. // the morphTarget is named.
  20193. for ( var morphTargetName in morphTargetNames ) {
  20194. var times = [];
  20195. var values = [];
  20196. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  20197. var animationKey = animationKeys[ k ];
  20198. times.push( animationKey.time );
  20199. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  20200. }
  20201. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  20202. }
  20203. duration = morphTargetNames.length * ( fps || 1.0 );
  20204. } else {
  20205. // ...assume skeletal animation
  20206. var boneName = '.bones[' + bones[ h ].name + ']';
  20207. addNonemptyTrack(
  20208. VectorKeyframeTrack, boneName + '.position',
  20209. animationKeys, 'pos', tracks );
  20210. addNonemptyTrack(
  20211. QuaternionKeyframeTrack, boneName + '.quaternion',
  20212. animationKeys, 'rot', tracks );
  20213. addNonemptyTrack(
  20214. VectorKeyframeTrack, boneName + '.scale',
  20215. animationKeys, 'scl', tracks );
  20216. }
  20217. }
  20218. if ( tracks.length === 0 ) {
  20219. return null;
  20220. }
  20221. var clip = new AnimationClip( clipName, duration, tracks );
  20222. return clip;
  20223. }
  20224. } );
  20225. Object.assign( AnimationClip.prototype, {
  20226. resetDuration: function () {
  20227. var tracks = this.tracks, duration = 0;
  20228. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  20229. var track = this.tracks[ i ];
  20230. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  20231. }
  20232. this.duration = duration;
  20233. return this;
  20234. },
  20235. trim: function () {
  20236. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20237. this.tracks[ i ].trim( 0, this.duration );
  20238. }
  20239. return this;
  20240. },
  20241. validate: function () {
  20242. var valid = true;
  20243. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20244. valid = valid && this.tracks[ i ].validate();
  20245. }
  20246. return valid;
  20247. },
  20248. optimize: function () {
  20249. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20250. this.tracks[ i ].optimize();
  20251. }
  20252. return this;
  20253. }
  20254. } );
  20255. /**
  20256. * @author mrdoob / http://mrdoob.com/
  20257. */
  20258. var Cache = {
  20259. enabled: false,
  20260. files: {},
  20261. add: function ( key, file ) {
  20262. if ( this.enabled === false ) return;
  20263. // console.log( 'THREE.Cache', 'Adding key:', key );
  20264. this.files[ key ] = file;
  20265. },
  20266. get: function ( key ) {
  20267. if ( this.enabled === false ) return;
  20268. // console.log( 'THREE.Cache', 'Checking key:', key );
  20269. return this.files[ key ];
  20270. },
  20271. remove: function ( key ) {
  20272. delete this.files[ key ];
  20273. },
  20274. clear: function () {
  20275. this.files = {};
  20276. }
  20277. };
  20278. /**
  20279. * @author mrdoob / http://mrdoob.com/
  20280. */
  20281. function LoadingManager( onLoad, onProgress, onError ) {
  20282. var scope = this;
  20283. var isLoading = false;
  20284. var itemsLoaded = 0;
  20285. var itemsTotal = 0;
  20286. var urlModifier = undefined;
  20287. // Refer to #5689 for the reason why we don't set .onStart
  20288. // in the constructor
  20289. this.onStart = undefined;
  20290. this.onLoad = onLoad;
  20291. this.onProgress = onProgress;
  20292. this.onError = onError;
  20293. this.itemStart = function ( url ) {
  20294. itemsTotal ++;
  20295. if ( isLoading === false ) {
  20296. if ( scope.onStart !== undefined ) {
  20297. scope.onStart( url, itemsLoaded, itemsTotal );
  20298. }
  20299. }
  20300. isLoading = true;
  20301. };
  20302. this.itemEnd = function ( url ) {
  20303. itemsLoaded ++;
  20304. if ( scope.onProgress !== undefined ) {
  20305. scope.onProgress( url, itemsLoaded, itemsTotal );
  20306. }
  20307. if ( itemsLoaded === itemsTotal ) {
  20308. isLoading = false;
  20309. if ( scope.onLoad !== undefined ) {
  20310. scope.onLoad();
  20311. }
  20312. }
  20313. };
  20314. this.itemError = function ( url ) {
  20315. if ( scope.onError !== undefined ) {
  20316. scope.onError( url );
  20317. }
  20318. };
  20319. this.resolveURL = function ( url ) {
  20320. if ( urlModifier ) {
  20321. return urlModifier( url );
  20322. }
  20323. return url;
  20324. };
  20325. this.setURLModifier = function ( transform ) {
  20326. urlModifier = transform;
  20327. return this;
  20328. };
  20329. }
  20330. var DefaultLoadingManager = new LoadingManager();
  20331. /**
  20332. * @author mrdoob / http://mrdoob.com/
  20333. */
  20334. var loading = {};
  20335. function FileLoader( manager ) {
  20336. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20337. }
  20338. Object.assign( FileLoader.prototype, {
  20339. load: function ( url, onLoad, onProgress, onError ) {
  20340. if ( url === undefined ) url = '';
  20341. if ( this.path !== undefined ) url = this.path + url;
  20342. url = this.manager.resolveURL( url );
  20343. var scope = this;
  20344. var cached = Cache.get( url );
  20345. if ( cached !== undefined ) {
  20346. scope.manager.itemStart( url );
  20347. setTimeout( function () {
  20348. if ( onLoad ) onLoad( cached );
  20349. scope.manager.itemEnd( url );
  20350. }, 0 );
  20351. return cached;
  20352. }
  20353. // Check if request is duplicate
  20354. if ( loading[ url ] !== undefined ) {
  20355. loading[ url ].push( {
  20356. onLoad: onLoad,
  20357. onProgress: onProgress,
  20358. onError: onError
  20359. } );
  20360. return;
  20361. }
  20362. // Check for data: URI
  20363. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  20364. var dataUriRegexResult = url.match( dataUriRegex );
  20365. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  20366. if ( dataUriRegexResult ) {
  20367. var mimeType = dataUriRegexResult[ 1 ];
  20368. var isBase64 = !! dataUriRegexResult[ 2 ];
  20369. var data = dataUriRegexResult[ 3 ];
  20370. data = decodeURIComponent( data );
  20371. if ( isBase64 ) data = atob( data );
  20372. try {
  20373. var response;
  20374. var responseType = ( this.responseType || '' ).toLowerCase();
  20375. switch ( responseType ) {
  20376. case 'arraybuffer':
  20377. case 'blob':
  20378. var view = new Uint8Array( data.length );
  20379. for ( var i = 0; i < data.length; i ++ ) {
  20380. view[ i ] = data.charCodeAt( i );
  20381. }
  20382. if ( responseType === 'blob' ) {
  20383. response = new Blob( [ view.buffer ], { type: mimeType } );
  20384. } else {
  20385. response = view.buffer;
  20386. }
  20387. break;
  20388. case 'document':
  20389. var parser = new DOMParser();
  20390. response = parser.parseFromString( data, mimeType );
  20391. break;
  20392. case 'json':
  20393. response = JSON.parse( data );
  20394. break;
  20395. default: // 'text' or other
  20396. response = data;
  20397. break;
  20398. }
  20399. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20400. setTimeout( function () {
  20401. if ( onLoad ) onLoad( response );
  20402. scope.manager.itemEnd( url );
  20403. }, 0 );
  20404. } catch ( error ) {
  20405. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20406. setTimeout( function () {
  20407. if ( onError ) onError( error );
  20408. scope.manager.itemError( url );
  20409. scope.manager.itemEnd( url );
  20410. }, 0 );
  20411. }
  20412. } else {
  20413. // Initialise array for duplicate requests
  20414. loading[ url ] = [];
  20415. loading[ url ].push( {
  20416. onLoad: onLoad,
  20417. onProgress: onProgress,
  20418. onError: onError
  20419. } );
  20420. var request = new XMLHttpRequest();
  20421. request.open( 'GET', url, true );
  20422. request.addEventListener( 'load', function ( event ) {
  20423. var response = this.response;
  20424. Cache.add( url, response );
  20425. var callbacks = loading[ url ];
  20426. delete loading[ url ];
  20427. if ( this.status === 200 || this.status === 0 ) {
  20428. // Some browsers return HTTP Status 0 when using non-http protocol
  20429. // e.g. 'file://' or 'data://'. Handle as success.
  20430. if ( this.status === 0 ) console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  20431. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20432. var callback = callbacks[ i ];
  20433. if ( callback.onLoad ) callback.onLoad( response );
  20434. }
  20435. scope.manager.itemEnd( url );
  20436. } else {
  20437. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20438. var callback = callbacks[ i ];
  20439. if ( callback.onError ) callback.onError( event );
  20440. }
  20441. scope.manager.itemError( url );
  20442. scope.manager.itemEnd( url );
  20443. }
  20444. }, false );
  20445. request.addEventListener( 'progress', function ( event ) {
  20446. var callbacks = loading[ url ];
  20447. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20448. var callback = callbacks[ i ];
  20449. if ( callback.onProgress ) callback.onProgress( event );
  20450. }
  20451. }, false );
  20452. request.addEventListener( 'error', function ( event ) {
  20453. var callbacks = loading[ url ];
  20454. delete loading[ url ];
  20455. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20456. var callback = callbacks[ i ];
  20457. if ( callback.onError ) callback.onError( event );
  20458. }
  20459. scope.manager.itemError( url );
  20460. scope.manager.itemEnd( url );
  20461. }, false );
  20462. request.addEventListener( 'abort', function ( event ) {
  20463. var callbacks = loading[ url ];
  20464. delete loading[ url ];
  20465. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20466. var callback = callbacks[ i ];
  20467. if ( callback.onError ) callback.onError( event );
  20468. }
  20469. scope.manager.itemError( url );
  20470. scope.manager.itemEnd( url );
  20471. }, false );
  20472. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  20473. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  20474. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  20475. for ( var header in this.requestHeader ) {
  20476. request.setRequestHeader( header, this.requestHeader[ header ] );
  20477. }
  20478. request.send( null );
  20479. }
  20480. scope.manager.itemStart( url );
  20481. return request;
  20482. },
  20483. setPath: function ( value ) {
  20484. this.path = value;
  20485. return this;
  20486. },
  20487. setResponseType: function ( value ) {
  20488. this.responseType = value;
  20489. return this;
  20490. },
  20491. setWithCredentials: function ( value ) {
  20492. this.withCredentials = value;
  20493. return this;
  20494. },
  20495. setMimeType: function ( value ) {
  20496. this.mimeType = value;
  20497. return this;
  20498. },
  20499. setRequestHeader: function ( value ) {
  20500. this.requestHeader = value;
  20501. return this;
  20502. }
  20503. } );
  20504. /**
  20505. * @author bhouston / http://clara.io/
  20506. */
  20507. function AnimationLoader( manager ) {
  20508. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20509. }
  20510. Object.assign( AnimationLoader.prototype, {
  20511. load: function ( url, onLoad, onProgress, onError ) {
  20512. var scope = this;
  20513. var loader = new FileLoader( scope.manager );
  20514. loader.setPath( scope.path );
  20515. loader.load( url, function ( text ) {
  20516. onLoad( scope.parse( JSON.parse( text ) ) );
  20517. }, onProgress, onError );
  20518. },
  20519. parse: function ( json, onLoad ) {
  20520. var animations = [];
  20521. for ( var i = 0; i < json.length; i ++ ) {
  20522. var clip = AnimationClip.parse( json[ i ] );
  20523. animations.push( clip );
  20524. }
  20525. onLoad( animations );
  20526. },
  20527. setPath: function ( value ) {
  20528. this.path = value;
  20529. return this;
  20530. }
  20531. } );
  20532. /**
  20533. * @author mrdoob / http://mrdoob.com/
  20534. *
  20535. * Abstract Base class to block based textures loader (dds, pvr, ...)
  20536. */
  20537. function CompressedTextureLoader( manager ) {
  20538. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20539. // override in sub classes
  20540. this._parser = null;
  20541. }
  20542. Object.assign( CompressedTextureLoader.prototype, {
  20543. load: function ( url, onLoad, onProgress, onError ) {
  20544. var scope = this;
  20545. var images = [];
  20546. var texture = new CompressedTexture();
  20547. texture.image = images;
  20548. var loader = new FileLoader( this.manager );
  20549. loader.setPath( this.path );
  20550. loader.setResponseType( 'arraybuffer' );
  20551. function loadTexture( i ) {
  20552. loader.load( url[ i ], function ( buffer ) {
  20553. var texDatas = scope._parser( buffer, true );
  20554. images[ i ] = {
  20555. width: texDatas.width,
  20556. height: texDatas.height,
  20557. format: texDatas.format,
  20558. mipmaps: texDatas.mipmaps
  20559. };
  20560. loaded += 1;
  20561. if ( loaded === 6 ) {
  20562. if ( texDatas.mipmapCount === 1 )
  20563. texture.minFilter = LinearFilter;
  20564. texture.format = texDatas.format;
  20565. texture.needsUpdate = true;
  20566. if ( onLoad ) onLoad( texture );
  20567. }
  20568. }, onProgress, onError );
  20569. }
  20570. if ( Array.isArray( url ) ) {
  20571. var loaded = 0;
  20572. for ( var i = 0, il = url.length; i < il; ++ i ) {
  20573. loadTexture( i );
  20574. }
  20575. } else {
  20576. // compressed cubemap texture stored in a single DDS file
  20577. loader.load( url, function ( buffer ) {
  20578. var texDatas = scope._parser( buffer, true );
  20579. if ( texDatas.isCubemap ) {
  20580. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  20581. for ( var f = 0; f < faces; f ++ ) {
  20582. images[ f ] = { mipmaps: [] };
  20583. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  20584. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  20585. images[ f ].format = texDatas.format;
  20586. images[ f ].width = texDatas.width;
  20587. images[ f ].height = texDatas.height;
  20588. }
  20589. }
  20590. } else {
  20591. texture.image.width = texDatas.width;
  20592. texture.image.height = texDatas.height;
  20593. texture.mipmaps = texDatas.mipmaps;
  20594. }
  20595. if ( texDatas.mipmapCount === 1 ) {
  20596. texture.minFilter = LinearFilter;
  20597. }
  20598. texture.format = texDatas.format;
  20599. texture.needsUpdate = true;
  20600. if ( onLoad ) onLoad( texture );
  20601. }, onProgress, onError );
  20602. }
  20603. return texture;
  20604. },
  20605. setPath: function ( value ) {
  20606. this.path = value;
  20607. return this;
  20608. }
  20609. } );
  20610. /**
  20611. * @author Nikos M. / https://github.com/foo123/
  20612. *
  20613. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  20614. */
  20615. function DataTextureLoader( manager ) {
  20616. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20617. // override in sub classes
  20618. this._parser = null;
  20619. }
  20620. Object.assign( DataTextureLoader.prototype, {
  20621. load: function ( url, onLoad, onProgress, onError ) {
  20622. var scope = this;
  20623. var texture = new DataTexture();
  20624. var loader = new FileLoader( this.manager );
  20625. loader.setResponseType( 'arraybuffer' );
  20626. loader.setPath( this.path );
  20627. loader.load( url, function ( buffer ) {
  20628. var texData = scope._parser( buffer );
  20629. if ( ! texData ) return;
  20630. if ( texData.image !== undefined ) {
  20631. texture.image = texData.image;
  20632. } else if ( texData.data !== undefined ) {
  20633. texture.image.width = texData.width;
  20634. texture.image.height = texData.height;
  20635. texture.image.data = texData.data;
  20636. }
  20637. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  20638. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  20639. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  20640. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearMipMapLinearFilter;
  20641. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  20642. if ( texData.format !== undefined ) {
  20643. texture.format = texData.format;
  20644. }
  20645. if ( texData.type !== undefined ) {
  20646. texture.type = texData.type;
  20647. }
  20648. if ( texData.mipmaps !== undefined ) {
  20649. texture.mipmaps = texData.mipmaps;
  20650. }
  20651. if ( texData.mipmapCount === 1 ) {
  20652. texture.minFilter = LinearFilter;
  20653. }
  20654. texture.needsUpdate = true;
  20655. if ( onLoad ) onLoad( texture, texData );
  20656. }, onProgress, onError );
  20657. return texture;
  20658. },
  20659. setPath: function ( value ) {
  20660. this.path = value;
  20661. return this;
  20662. }
  20663. } );
  20664. /**
  20665. * @author mrdoob / http://mrdoob.com/
  20666. */
  20667. function ImageLoader( manager ) {
  20668. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20669. }
  20670. Object.assign( ImageLoader.prototype, {
  20671. crossOrigin: 'anonymous',
  20672. load: function ( url, onLoad, onProgress, onError ) {
  20673. if ( url === undefined ) url = '';
  20674. if ( this.path !== undefined ) url = this.path + url;
  20675. url = this.manager.resolveURL( url );
  20676. var scope = this;
  20677. var cached = Cache.get( url );
  20678. if ( cached !== undefined ) {
  20679. scope.manager.itemStart( url );
  20680. setTimeout( function () {
  20681. if ( onLoad ) onLoad( cached );
  20682. scope.manager.itemEnd( url );
  20683. }, 0 );
  20684. return cached;
  20685. }
  20686. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  20687. function onImageLoad() {
  20688. image.removeEventListener( 'load', onImageLoad, false );
  20689. image.removeEventListener( 'error', onImageError, false );
  20690. Cache.add( url, this );
  20691. if ( onLoad ) onLoad( this );
  20692. scope.manager.itemEnd( url );
  20693. }
  20694. function onImageError( event ) {
  20695. image.removeEventListener( 'load', onImageLoad, false );
  20696. image.removeEventListener( 'error', onImageError, false );
  20697. if ( onError ) onError( event );
  20698. scope.manager.itemError( url );
  20699. scope.manager.itemEnd( url );
  20700. }
  20701. image.addEventListener( 'load', onImageLoad, false );
  20702. image.addEventListener( 'error', onImageError, false );
  20703. if ( url.substr( 0, 5 ) !== 'data:' ) {
  20704. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  20705. }
  20706. scope.manager.itemStart( url );
  20707. image.src = url;
  20708. return image;
  20709. },
  20710. setCrossOrigin: function ( value ) {
  20711. this.crossOrigin = value;
  20712. return this;
  20713. },
  20714. setPath: function ( value ) {
  20715. this.path = value;
  20716. return this;
  20717. }
  20718. } );
  20719. /**
  20720. * @author mrdoob / http://mrdoob.com/
  20721. */
  20722. function CubeTextureLoader( manager ) {
  20723. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20724. }
  20725. Object.assign( CubeTextureLoader.prototype, {
  20726. crossOrigin: 'anonymous',
  20727. load: function ( urls, onLoad, onProgress, onError ) {
  20728. var texture = new CubeTexture();
  20729. var loader = new ImageLoader( this.manager );
  20730. loader.setCrossOrigin( this.crossOrigin );
  20731. loader.setPath( this.path );
  20732. var loaded = 0;
  20733. function loadTexture( i ) {
  20734. loader.load( urls[ i ], function ( image ) {
  20735. texture.images[ i ] = image;
  20736. loaded ++;
  20737. if ( loaded === 6 ) {
  20738. texture.needsUpdate = true;
  20739. if ( onLoad ) onLoad( texture );
  20740. }
  20741. }, undefined, onError );
  20742. }
  20743. for ( var i = 0; i < urls.length; ++ i ) {
  20744. loadTexture( i );
  20745. }
  20746. return texture;
  20747. },
  20748. setCrossOrigin: function ( value ) {
  20749. this.crossOrigin = value;
  20750. return this;
  20751. },
  20752. setPath: function ( value ) {
  20753. this.path = value;
  20754. return this;
  20755. }
  20756. } );
  20757. /**
  20758. * @author mrdoob / http://mrdoob.com/
  20759. */
  20760. function TextureLoader( manager ) {
  20761. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20762. }
  20763. Object.assign( TextureLoader.prototype, {
  20764. crossOrigin: 'anonymous',
  20765. load: function ( url, onLoad, onProgress, onError ) {
  20766. var texture = new Texture();
  20767. var loader = new ImageLoader( this.manager );
  20768. loader.setCrossOrigin( this.crossOrigin );
  20769. loader.setPath( this.path );
  20770. loader.load( url, function ( image ) {
  20771. texture.image = image;
  20772. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  20773. var isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  20774. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  20775. texture.needsUpdate = true;
  20776. if ( onLoad !== undefined ) {
  20777. onLoad( texture );
  20778. }
  20779. }, onProgress, onError );
  20780. return texture;
  20781. },
  20782. setCrossOrigin: function ( value ) {
  20783. this.crossOrigin = value;
  20784. return this;
  20785. },
  20786. setPath: function ( value ) {
  20787. this.path = value;
  20788. return this;
  20789. }
  20790. } );
  20791. /**
  20792. * @author zz85 / http://www.lab4games.net/zz85/blog
  20793. * Extensible curve object
  20794. *
  20795. * Some common of curve methods:
  20796. * .getPoint( t, optionalTarget ), .getTangent( t )
  20797. * .getPointAt( u, optionalTarget ), .getTangentAt( u )
  20798. * .getPoints(), .getSpacedPoints()
  20799. * .getLength()
  20800. * .updateArcLengths()
  20801. *
  20802. * This following curves inherit from THREE.Curve:
  20803. *
  20804. * -- 2D curves --
  20805. * THREE.ArcCurve
  20806. * THREE.CubicBezierCurve
  20807. * THREE.EllipseCurve
  20808. * THREE.LineCurve
  20809. * THREE.QuadraticBezierCurve
  20810. * THREE.SplineCurve
  20811. *
  20812. * -- 3D curves --
  20813. * THREE.CatmullRomCurve3
  20814. * THREE.CubicBezierCurve3
  20815. * THREE.LineCurve3
  20816. * THREE.QuadraticBezierCurve3
  20817. *
  20818. * A series of curves can be represented as a THREE.CurvePath.
  20819. *
  20820. **/
  20821. /**************************************************************
  20822. * Abstract Curve base class
  20823. **************************************************************/
  20824. function Curve() {
  20825. this.type = 'Curve';
  20826. this.arcLengthDivisions = 200;
  20827. }
  20828. Object.assign( Curve.prototype, {
  20829. // Virtual base class method to overwrite and implement in subclasses
  20830. // - t [0 .. 1]
  20831. getPoint: function ( /* t, optionalTarget */ ) {
  20832. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  20833. return null;
  20834. },
  20835. // Get point at relative position in curve according to arc length
  20836. // - u [0 .. 1]
  20837. getPointAt: function ( u, optionalTarget ) {
  20838. var t = this.getUtoTmapping( u );
  20839. return this.getPoint( t, optionalTarget );
  20840. },
  20841. // Get sequence of points using getPoint( t )
  20842. getPoints: function ( divisions ) {
  20843. if ( divisions === undefined ) divisions = 5;
  20844. var points = [];
  20845. for ( var d = 0; d <= divisions; d ++ ) {
  20846. points.push( this.getPoint( d / divisions ) );
  20847. }
  20848. return points;
  20849. },
  20850. // Get sequence of points using getPointAt( u )
  20851. getSpacedPoints: function ( divisions ) {
  20852. if ( divisions === undefined ) divisions = 5;
  20853. var points = [];
  20854. for ( var d = 0; d <= divisions; d ++ ) {
  20855. points.push( this.getPointAt( d / divisions ) );
  20856. }
  20857. return points;
  20858. },
  20859. // Get total curve arc length
  20860. getLength: function () {
  20861. var lengths = this.getLengths();
  20862. return lengths[ lengths.length - 1 ];
  20863. },
  20864. // Get list of cumulative segment lengths
  20865. getLengths: function ( divisions ) {
  20866. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  20867. if ( this.cacheArcLengths &&
  20868. ( this.cacheArcLengths.length === divisions + 1 ) &&
  20869. ! this.needsUpdate ) {
  20870. return this.cacheArcLengths;
  20871. }
  20872. this.needsUpdate = false;
  20873. var cache = [];
  20874. var current, last = this.getPoint( 0 );
  20875. var p, sum = 0;
  20876. cache.push( 0 );
  20877. for ( p = 1; p <= divisions; p ++ ) {
  20878. current = this.getPoint( p / divisions );
  20879. sum += current.distanceTo( last );
  20880. cache.push( sum );
  20881. last = current;
  20882. }
  20883. this.cacheArcLengths = cache;
  20884. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  20885. },
  20886. updateArcLengths: function () {
  20887. this.needsUpdate = true;
  20888. this.getLengths();
  20889. },
  20890. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  20891. getUtoTmapping: function ( u, distance ) {
  20892. var arcLengths = this.getLengths();
  20893. var i = 0, il = arcLengths.length;
  20894. var targetArcLength; // The targeted u distance value to get
  20895. if ( distance ) {
  20896. targetArcLength = distance;
  20897. } else {
  20898. targetArcLength = u * arcLengths[ il - 1 ];
  20899. }
  20900. // binary search for the index with largest value smaller than target u distance
  20901. var low = 0, high = il - 1, comparison;
  20902. while ( low <= high ) {
  20903. 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
  20904. comparison = arcLengths[ i ] - targetArcLength;
  20905. if ( comparison < 0 ) {
  20906. low = i + 1;
  20907. } else if ( comparison > 0 ) {
  20908. high = i - 1;
  20909. } else {
  20910. high = i;
  20911. break;
  20912. // DONE
  20913. }
  20914. }
  20915. i = high;
  20916. if ( arcLengths[ i ] === targetArcLength ) {
  20917. return i / ( il - 1 );
  20918. }
  20919. // we could get finer grain at lengths, or use simple interpolation between two points
  20920. var lengthBefore = arcLengths[ i ];
  20921. var lengthAfter = arcLengths[ i + 1 ];
  20922. var segmentLength = lengthAfter - lengthBefore;
  20923. // determine where we are between the 'before' and 'after' points
  20924. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  20925. // add that fractional amount to t
  20926. var t = ( i + segmentFraction ) / ( il - 1 );
  20927. return t;
  20928. },
  20929. // Returns a unit vector tangent at t
  20930. // In case any sub curve does not implement its tangent derivation,
  20931. // 2 points a small delta apart will be used to find its gradient
  20932. // which seems to give a reasonable approximation
  20933. getTangent: function ( t ) {
  20934. var delta = 0.0001;
  20935. var t1 = t - delta;
  20936. var t2 = t + delta;
  20937. // Capping in case of danger
  20938. if ( t1 < 0 ) t1 = 0;
  20939. if ( t2 > 1 ) t2 = 1;
  20940. var pt1 = this.getPoint( t1 );
  20941. var pt2 = this.getPoint( t2 );
  20942. var vec = pt2.clone().sub( pt1 );
  20943. return vec.normalize();
  20944. },
  20945. getTangentAt: function ( u ) {
  20946. var t = this.getUtoTmapping( u );
  20947. return this.getTangent( t );
  20948. },
  20949. computeFrenetFrames: function ( segments, closed ) {
  20950. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  20951. var normal = new Vector3();
  20952. var tangents = [];
  20953. var normals = [];
  20954. var binormals = [];
  20955. var vec = new Vector3();
  20956. var mat = new Matrix4();
  20957. var i, u, theta;
  20958. // compute the tangent vectors for each segment on the curve
  20959. for ( i = 0; i <= segments; i ++ ) {
  20960. u = i / segments;
  20961. tangents[ i ] = this.getTangentAt( u );
  20962. tangents[ i ].normalize();
  20963. }
  20964. // select an initial normal vector perpendicular to the first tangent vector,
  20965. // and in the direction of the minimum tangent xyz component
  20966. normals[ 0 ] = new Vector3();
  20967. binormals[ 0 ] = new Vector3();
  20968. var min = Number.MAX_VALUE;
  20969. var tx = Math.abs( tangents[ 0 ].x );
  20970. var ty = Math.abs( tangents[ 0 ].y );
  20971. var tz = Math.abs( tangents[ 0 ].z );
  20972. if ( tx <= min ) {
  20973. min = tx;
  20974. normal.set( 1, 0, 0 );
  20975. }
  20976. if ( ty <= min ) {
  20977. min = ty;
  20978. normal.set( 0, 1, 0 );
  20979. }
  20980. if ( tz <= min ) {
  20981. normal.set( 0, 0, 1 );
  20982. }
  20983. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  20984. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  20985. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  20986. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  20987. for ( i = 1; i <= segments; i ++ ) {
  20988. normals[ i ] = normals[ i - 1 ].clone();
  20989. binormals[ i ] = binormals[ i - 1 ].clone();
  20990. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  20991. if ( vec.length() > Number.EPSILON ) {
  20992. vec.normalize();
  20993. theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  20994. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  20995. }
  20996. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20997. }
  20998. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  20999. if ( closed === true ) {
  21000. theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  21001. theta /= segments;
  21002. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  21003. theta = - theta;
  21004. }
  21005. for ( i = 1; i <= segments; i ++ ) {
  21006. // twist a little...
  21007. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  21008. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21009. }
  21010. }
  21011. return {
  21012. tangents: tangents,
  21013. normals: normals,
  21014. binormals: binormals
  21015. };
  21016. },
  21017. clone: function () {
  21018. return new this.constructor().copy( this );
  21019. },
  21020. copy: function ( source ) {
  21021. this.arcLengthDivisions = source.arcLengthDivisions;
  21022. return this;
  21023. },
  21024. toJSON: function () {
  21025. var data = {
  21026. metadata: {
  21027. version: 4.5,
  21028. type: 'Curve',
  21029. generator: 'Curve.toJSON'
  21030. }
  21031. };
  21032. data.arcLengthDivisions = this.arcLengthDivisions;
  21033. data.type = this.type;
  21034. return data;
  21035. },
  21036. fromJSON: function ( json ) {
  21037. this.arcLengthDivisions = json.arcLengthDivisions;
  21038. return this;
  21039. }
  21040. } );
  21041. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21042. Curve.call( this );
  21043. this.type = 'EllipseCurve';
  21044. this.aX = aX || 0;
  21045. this.aY = aY || 0;
  21046. this.xRadius = xRadius || 1;
  21047. this.yRadius = yRadius || 1;
  21048. this.aStartAngle = aStartAngle || 0;
  21049. this.aEndAngle = aEndAngle || 2 * Math.PI;
  21050. this.aClockwise = aClockwise || false;
  21051. this.aRotation = aRotation || 0;
  21052. }
  21053. EllipseCurve.prototype = Object.create( Curve.prototype );
  21054. EllipseCurve.prototype.constructor = EllipseCurve;
  21055. EllipseCurve.prototype.isEllipseCurve = true;
  21056. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21057. var point = optionalTarget || new Vector2();
  21058. var twoPi = Math.PI * 2;
  21059. var deltaAngle = this.aEndAngle - this.aStartAngle;
  21060. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  21061. // ensures that deltaAngle is 0 .. 2 PI
  21062. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  21063. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  21064. if ( deltaAngle < Number.EPSILON ) {
  21065. if ( samePoints ) {
  21066. deltaAngle = 0;
  21067. } else {
  21068. deltaAngle = twoPi;
  21069. }
  21070. }
  21071. if ( this.aClockwise === true && ! samePoints ) {
  21072. if ( deltaAngle === twoPi ) {
  21073. deltaAngle = - twoPi;
  21074. } else {
  21075. deltaAngle = deltaAngle - twoPi;
  21076. }
  21077. }
  21078. var angle = this.aStartAngle + t * deltaAngle;
  21079. var x = this.aX + this.xRadius * Math.cos( angle );
  21080. var y = this.aY + this.yRadius * Math.sin( angle );
  21081. if ( this.aRotation !== 0 ) {
  21082. var cos = Math.cos( this.aRotation );
  21083. var sin = Math.sin( this.aRotation );
  21084. var tx = x - this.aX;
  21085. var ty = y - this.aY;
  21086. // Rotate the point about the center of the ellipse.
  21087. x = tx * cos - ty * sin + this.aX;
  21088. y = tx * sin + ty * cos + this.aY;
  21089. }
  21090. return point.set( x, y );
  21091. };
  21092. EllipseCurve.prototype.copy = function ( source ) {
  21093. Curve.prototype.copy.call( this, source );
  21094. this.aX = source.aX;
  21095. this.aY = source.aY;
  21096. this.xRadius = source.xRadius;
  21097. this.yRadius = source.yRadius;
  21098. this.aStartAngle = source.aStartAngle;
  21099. this.aEndAngle = source.aEndAngle;
  21100. this.aClockwise = source.aClockwise;
  21101. this.aRotation = source.aRotation;
  21102. return this;
  21103. };
  21104. EllipseCurve.prototype.toJSON = function () {
  21105. var data = Curve.prototype.toJSON.call( this );
  21106. data.aX = this.aX;
  21107. data.aY = this.aY;
  21108. data.xRadius = this.xRadius;
  21109. data.yRadius = this.yRadius;
  21110. data.aStartAngle = this.aStartAngle;
  21111. data.aEndAngle = this.aEndAngle;
  21112. data.aClockwise = this.aClockwise;
  21113. data.aRotation = this.aRotation;
  21114. return data;
  21115. };
  21116. EllipseCurve.prototype.fromJSON = function ( json ) {
  21117. Curve.prototype.fromJSON.call( this, json );
  21118. this.aX = json.aX;
  21119. this.aY = json.aY;
  21120. this.xRadius = json.xRadius;
  21121. this.yRadius = json.yRadius;
  21122. this.aStartAngle = json.aStartAngle;
  21123. this.aEndAngle = json.aEndAngle;
  21124. this.aClockwise = json.aClockwise;
  21125. this.aRotation = json.aRotation;
  21126. return this;
  21127. };
  21128. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21129. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21130. this.type = 'ArcCurve';
  21131. }
  21132. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  21133. ArcCurve.prototype.constructor = ArcCurve;
  21134. ArcCurve.prototype.isArcCurve = true;
  21135. /**
  21136. * @author zz85 https://github.com/zz85
  21137. *
  21138. * Centripetal CatmullRom Curve - which is useful for avoiding
  21139. * cusps and self-intersections in non-uniform catmull rom curves.
  21140. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21141. *
  21142. * curve.type accepts centripetal(default), chordal and catmullrom
  21143. * curve.tension is used for catmullrom which defaults to 0.5
  21144. */
  21145. /*
  21146. Based on an optimized c++ solution in
  21147. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21148. - http://ideone.com/NoEbVM
  21149. This CubicPoly class could be used for reusing some variables and calculations,
  21150. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21151. which can be placed in CurveUtils.
  21152. */
  21153. function CubicPoly() {
  21154. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  21155. /*
  21156. * Compute coefficients for a cubic polynomial
  21157. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21158. * such that
  21159. * p(0) = x0, p(1) = x1
  21160. * and
  21161. * p'(0) = t0, p'(1) = t1.
  21162. */
  21163. function init( x0, x1, t0, t1 ) {
  21164. c0 = x0;
  21165. c1 = t0;
  21166. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21167. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21168. }
  21169. return {
  21170. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  21171. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21172. },
  21173. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21174. // compute tangents when parameterized in [t1,t2]
  21175. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21176. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21177. // rescale tangents for parametrization in [0,1]
  21178. t1 *= dt1;
  21179. t2 *= dt1;
  21180. init( x1, x2, t1, t2 );
  21181. },
  21182. calc: function ( t ) {
  21183. var t2 = t * t;
  21184. var t3 = t2 * t;
  21185. return c0 + c1 * t + c2 * t2 + c3 * t3;
  21186. }
  21187. };
  21188. }
  21189. //
  21190. var tmp = new Vector3();
  21191. var px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
  21192. function CatmullRomCurve3( points, closed, curveType, tension ) {
  21193. Curve.call( this );
  21194. this.type = 'CatmullRomCurve3';
  21195. this.points = points || [];
  21196. this.closed = closed || false;
  21197. this.curveType = curveType || 'centripetal';
  21198. this.tension = tension || 0.5;
  21199. }
  21200. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  21201. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  21202. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  21203. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21204. var point = optionalTarget || new Vector3();
  21205. var points = this.points;
  21206. var l = points.length;
  21207. var p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21208. var intPoint = Math.floor( p );
  21209. var weight = p - intPoint;
  21210. if ( this.closed ) {
  21211. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  21212. } else if ( weight === 0 && intPoint === l - 1 ) {
  21213. intPoint = l - 2;
  21214. weight = 1;
  21215. }
  21216. var p0, p1, p2, p3; // 4 points
  21217. if ( this.closed || intPoint > 0 ) {
  21218. p0 = points[ ( intPoint - 1 ) % l ];
  21219. } else {
  21220. // extrapolate first point
  21221. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21222. p0 = tmp;
  21223. }
  21224. p1 = points[ intPoint % l ];
  21225. p2 = points[ ( intPoint + 1 ) % l ];
  21226. if ( this.closed || intPoint + 2 < l ) {
  21227. p3 = points[ ( intPoint + 2 ) % l ];
  21228. } else {
  21229. // extrapolate last point
  21230. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21231. p3 = tmp;
  21232. }
  21233. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  21234. // init Centripetal / Chordal Catmull-Rom
  21235. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  21236. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21237. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21238. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21239. // safety check for repeated points
  21240. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21241. if ( dt0 < 1e-4 ) dt0 = dt1;
  21242. if ( dt2 < 1e-4 ) dt2 = dt1;
  21243. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21244. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21245. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21246. } else if ( this.curveType === 'catmullrom' ) {
  21247. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  21248. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  21249. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  21250. }
  21251. point.set(
  21252. px.calc( weight ),
  21253. py.calc( weight ),
  21254. pz.calc( weight )
  21255. );
  21256. return point;
  21257. };
  21258. CatmullRomCurve3.prototype.copy = function ( source ) {
  21259. Curve.prototype.copy.call( this, source );
  21260. this.points = [];
  21261. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  21262. var point = source.points[ i ];
  21263. this.points.push( point.clone() );
  21264. }
  21265. this.closed = source.closed;
  21266. this.curveType = source.curveType;
  21267. this.tension = source.tension;
  21268. return this;
  21269. };
  21270. CatmullRomCurve3.prototype.toJSON = function () {
  21271. var data = Curve.prototype.toJSON.call( this );
  21272. data.points = [];
  21273. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  21274. var point = this.points[ i ];
  21275. data.points.push( point.toArray() );
  21276. }
  21277. data.closed = this.closed;
  21278. data.curveType = this.curveType;
  21279. data.tension = this.tension;
  21280. return data;
  21281. };
  21282. CatmullRomCurve3.prototype.fromJSON = function ( json ) {
  21283. Curve.prototype.fromJSON.call( this, json );
  21284. this.points = [];
  21285. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  21286. var point = json.points[ i ];
  21287. this.points.push( new Vector3().fromArray( point ) );
  21288. }
  21289. this.closed = json.closed;
  21290. this.curveType = json.curveType;
  21291. this.tension = json.tension;
  21292. return this;
  21293. };
  21294. /**
  21295. * @author zz85 / http://www.lab4games.net/zz85/blog
  21296. *
  21297. * Bezier Curves formulas obtained from
  21298. * http://en.wikipedia.org/wiki/Bézier_curve
  21299. */
  21300. function CatmullRom( t, p0, p1, p2, p3 ) {
  21301. var v0 = ( p2 - p0 ) * 0.5;
  21302. var v1 = ( p3 - p1 ) * 0.5;
  21303. var t2 = t * t;
  21304. var t3 = t * t2;
  21305. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  21306. }
  21307. //
  21308. function QuadraticBezierP0( t, p ) {
  21309. var k = 1 - t;
  21310. return k * k * p;
  21311. }
  21312. function QuadraticBezierP1( t, p ) {
  21313. return 2 * ( 1 - t ) * t * p;
  21314. }
  21315. function QuadraticBezierP2( t, p ) {
  21316. return t * t * p;
  21317. }
  21318. function QuadraticBezier( t, p0, p1, p2 ) {
  21319. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  21320. QuadraticBezierP2( t, p2 );
  21321. }
  21322. //
  21323. function CubicBezierP0( t, p ) {
  21324. var k = 1 - t;
  21325. return k * k * k * p;
  21326. }
  21327. function CubicBezierP1( t, p ) {
  21328. var k = 1 - t;
  21329. return 3 * k * k * t * p;
  21330. }
  21331. function CubicBezierP2( t, p ) {
  21332. return 3 * ( 1 - t ) * t * t * p;
  21333. }
  21334. function CubicBezierP3( t, p ) {
  21335. return t * t * t * p;
  21336. }
  21337. function CubicBezier( t, p0, p1, p2, p3 ) {
  21338. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  21339. CubicBezierP3( t, p3 );
  21340. }
  21341. function CubicBezierCurve( v0, v1, v2, v3 ) {
  21342. Curve.call( this );
  21343. this.type = 'CubicBezierCurve';
  21344. this.v0 = v0 || new Vector2();
  21345. this.v1 = v1 || new Vector2();
  21346. this.v2 = v2 || new Vector2();
  21347. this.v3 = v3 || new Vector2();
  21348. }
  21349. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  21350. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  21351. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  21352. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21353. var point = optionalTarget || new Vector2();
  21354. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21355. point.set(
  21356. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21357. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  21358. );
  21359. return point;
  21360. };
  21361. CubicBezierCurve.prototype.copy = function ( source ) {
  21362. Curve.prototype.copy.call( this, source );
  21363. this.v0.copy( source.v0 );
  21364. this.v1.copy( source.v1 );
  21365. this.v2.copy( source.v2 );
  21366. this.v3.copy( source.v3 );
  21367. return this;
  21368. };
  21369. CubicBezierCurve.prototype.toJSON = function () {
  21370. var data = Curve.prototype.toJSON.call( this );
  21371. data.v0 = this.v0.toArray();
  21372. data.v1 = this.v1.toArray();
  21373. data.v2 = this.v2.toArray();
  21374. data.v3 = this.v3.toArray();
  21375. return data;
  21376. };
  21377. CubicBezierCurve.prototype.fromJSON = function ( json ) {
  21378. Curve.prototype.fromJSON.call( this, json );
  21379. this.v0.fromArray( json.v0 );
  21380. this.v1.fromArray( json.v1 );
  21381. this.v2.fromArray( json.v2 );
  21382. this.v3.fromArray( json.v3 );
  21383. return this;
  21384. };
  21385. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  21386. Curve.call( this );
  21387. this.type = 'CubicBezierCurve3';
  21388. this.v0 = v0 || new Vector3();
  21389. this.v1 = v1 || new Vector3();
  21390. this.v2 = v2 || new Vector3();
  21391. this.v3 = v3 || new Vector3();
  21392. }
  21393. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  21394. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  21395. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  21396. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21397. var point = optionalTarget || new Vector3();
  21398. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21399. point.set(
  21400. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21401. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  21402. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  21403. );
  21404. return point;
  21405. };
  21406. CubicBezierCurve3.prototype.copy = function ( source ) {
  21407. Curve.prototype.copy.call( this, source );
  21408. this.v0.copy( source.v0 );
  21409. this.v1.copy( source.v1 );
  21410. this.v2.copy( source.v2 );
  21411. this.v3.copy( source.v3 );
  21412. return this;
  21413. };
  21414. CubicBezierCurve3.prototype.toJSON = function () {
  21415. var data = Curve.prototype.toJSON.call( this );
  21416. data.v0 = this.v0.toArray();
  21417. data.v1 = this.v1.toArray();
  21418. data.v2 = this.v2.toArray();
  21419. data.v3 = this.v3.toArray();
  21420. return data;
  21421. };
  21422. CubicBezierCurve3.prototype.fromJSON = function ( json ) {
  21423. Curve.prototype.fromJSON.call( this, json );
  21424. this.v0.fromArray( json.v0 );
  21425. this.v1.fromArray( json.v1 );
  21426. this.v2.fromArray( json.v2 );
  21427. this.v3.fromArray( json.v3 );
  21428. return this;
  21429. };
  21430. function LineCurve( v1, v2 ) {
  21431. Curve.call( this );
  21432. this.type = 'LineCurve';
  21433. this.v1 = v1 || new Vector2();
  21434. this.v2 = v2 || new Vector2();
  21435. }
  21436. LineCurve.prototype = Object.create( Curve.prototype );
  21437. LineCurve.prototype.constructor = LineCurve;
  21438. LineCurve.prototype.isLineCurve = true;
  21439. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21440. var point = optionalTarget || new Vector2();
  21441. if ( t === 1 ) {
  21442. point.copy( this.v2 );
  21443. } else {
  21444. point.copy( this.v2 ).sub( this.v1 );
  21445. point.multiplyScalar( t ).add( this.v1 );
  21446. }
  21447. return point;
  21448. };
  21449. // Line curve is linear, so we can overwrite default getPointAt
  21450. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  21451. return this.getPoint( u, optionalTarget );
  21452. };
  21453. LineCurve.prototype.getTangent = function ( /* t */ ) {
  21454. var tangent = this.v2.clone().sub( this.v1 );
  21455. return tangent.normalize();
  21456. };
  21457. LineCurve.prototype.copy = function ( source ) {
  21458. Curve.prototype.copy.call( this, source );
  21459. this.v1.copy( source.v1 );
  21460. this.v2.copy( source.v2 );
  21461. return this;
  21462. };
  21463. LineCurve.prototype.toJSON = function () {
  21464. var data = Curve.prototype.toJSON.call( this );
  21465. data.v1 = this.v1.toArray();
  21466. data.v2 = this.v2.toArray();
  21467. return data;
  21468. };
  21469. LineCurve.prototype.fromJSON = function ( json ) {
  21470. Curve.prototype.fromJSON.call( this, json );
  21471. this.v1.fromArray( json.v1 );
  21472. this.v2.fromArray( json.v2 );
  21473. return this;
  21474. };
  21475. function LineCurve3( v1, v2 ) {
  21476. Curve.call( this );
  21477. this.type = 'LineCurve3';
  21478. this.v1 = v1 || new Vector3();
  21479. this.v2 = v2 || new Vector3();
  21480. }
  21481. LineCurve3.prototype = Object.create( Curve.prototype );
  21482. LineCurve3.prototype.constructor = LineCurve3;
  21483. LineCurve3.prototype.isLineCurve3 = true;
  21484. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21485. var point = optionalTarget || new Vector3();
  21486. if ( t === 1 ) {
  21487. point.copy( this.v2 );
  21488. } else {
  21489. point.copy( this.v2 ).sub( this.v1 );
  21490. point.multiplyScalar( t ).add( this.v1 );
  21491. }
  21492. return point;
  21493. };
  21494. // Line curve is linear, so we can overwrite default getPointAt
  21495. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  21496. return this.getPoint( u, optionalTarget );
  21497. };
  21498. LineCurve3.prototype.copy = function ( source ) {
  21499. Curve.prototype.copy.call( this, source );
  21500. this.v1.copy( source.v1 );
  21501. this.v2.copy( source.v2 );
  21502. return this;
  21503. };
  21504. LineCurve3.prototype.toJSON = function () {
  21505. var data = Curve.prototype.toJSON.call( this );
  21506. data.v1 = this.v1.toArray();
  21507. data.v2 = this.v2.toArray();
  21508. return data;
  21509. };
  21510. LineCurve3.prototype.fromJSON = function ( json ) {
  21511. Curve.prototype.fromJSON.call( this, json );
  21512. this.v1.fromArray( json.v1 );
  21513. this.v2.fromArray( json.v2 );
  21514. return this;
  21515. };
  21516. function QuadraticBezierCurve( v0, v1, v2 ) {
  21517. Curve.call( this );
  21518. this.type = 'QuadraticBezierCurve';
  21519. this.v0 = v0 || new Vector2();
  21520. this.v1 = v1 || new Vector2();
  21521. this.v2 = v2 || new Vector2();
  21522. }
  21523. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  21524. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  21525. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  21526. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21527. var point = optionalTarget || new Vector2();
  21528. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  21529. point.set(
  21530. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  21531. QuadraticBezier( t, v0.y, v1.y, v2.y )
  21532. );
  21533. return point;
  21534. };
  21535. QuadraticBezierCurve.prototype.copy = function ( source ) {
  21536. Curve.prototype.copy.call( this, source );
  21537. this.v0.copy( source.v0 );
  21538. this.v1.copy( source.v1 );
  21539. this.v2.copy( source.v2 );
  21540. return this;
  21541. };
  21542. QuadraticBezierCurve.prototype.toJSON = function () {
  21543. var data = Curve.prototype.toJSON.call( this );
  21544. data.v0 = this.v0.toArray();
  21545. data.v1 = this.v1.toArray();
  21546. data.v2 = this.v2.toArray();
  21547. return data;
  21548. };
  21549. QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
  21550. Curve.prototype.fromJSON.call( this, json );
  21551. this.v0.fromArray( json.v0 );
  21552. this.v1.fromArray( json.v1 );
  21553. this.v2.fromArray( json.v2 );
  21554. return this;
  21555. };
  21556. function QuadraticBezierCurve3( v0, v1, v2 ) {
  21557. Curve.call( this );
  21558. this.type = 'QuadraticBezierCurve3';
  21559. this.v0 = v0 || new Vector3();
  21560. this.v1 = v1 || new Vector3();
  21561. this.v2 = v2 || new Vector3();
  21562. }
  21563. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  21564. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  21565. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  21566. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21567. var point = optionalTarget || new Vector3();
  21568. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  21569. point.set(
  21570. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  21571. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  21572. QuadraticBezier( t, v0.z, v1.z, v2.z )
  21573. );
  21574. return point;
  21575. };
  21576. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  21577. Curve.prototype.copy.call( this, source );
  21578. this.v0.copy( source.v0 );
  21579. this.v1.copy( source.v1 );
  21580. this.v2.copy( source.v2 );
  21581. return this;
  21582. };
  21583. QuadraticBezierCurve3.prototype.toJSON = function () {
  21584. var data = Curve.prototype.toJSON.call( this );
  21585. data.v0 = this.v0.toArray();
  21586. data.v1 = this.v1.toArray();
  21587. data.v2 = this.v2.toArray();
  21588. return data;
  21589. };
  21590. QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
  21591. Curve.prototype.fromJSON.call( this, json );
  21592. this.v0.fromArray( json.v0 );
  21593. this.v1.fromArray( json.v1 );
  21594. this.v2.fromArray( json.v2 );
  21595. return this;
  21596. };
  21597. function SplineCurve( points /* array of Vector2 */ ) {
  21598. Curve.call( this );
  21599. this.type = 'SplineCurve';
  21600. this.points = points || [];
  21601. }
  21602. SplineCurve.prototype = Object.create( Curve.prototype );
  21603. SplineCurve.prototype.constructor = SplineCurve;
  21604. SplineCurve.prototype.isSplineCurve = true;
  21605. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21606. var point = optionalTarget || new Vector2();
  21607. var points = this.points;
  21608. var p = ( points.length - 1 ) * t;
  21609. var intPoint = Math.floor( p );
  21610. var weight = p - intPoint;
  21611. var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  21612. var p1 = points[ intPoint ];
  21613. var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21614. var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21615. point.set(
  21616. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  21617. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  21618. );
  21619. return point;
  21620. };
  21621. SplineCurve.prototype.copy = function ( source ) {
  21622. Curve.prototype.copy.call( this, source );
  21623. this.points = [];
  21624. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  21625. var point = source.points[ i ];
  21626. this.points.push( point.clone() );
  21627. }
  21628. return this;
  21629. };
  21630. SplineCurve.prototype.toJSON = function () {
  21631. var data = Curve.prototype.toJSON.call( this );
  21632. data.points = [];
  21633. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  21634. var point = this.points[ i ];
  21635. data.points.push( point.toArray() );
  21636. }
  21637. return data;
  21638. };
  21639. SplineCurve.prototype.fromJSON = function ( json ) {
  21640. Curve.prototype.fromJSON.call( this, json );
  21641. this.points = [];
  21642. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  21643. var point = json.points[ i ];
  21644. this.points.push( new Vector2().fromArray( point ) );
  21645. }
  21646. return this;
  21647. };
  21648. var Curves = /*#__PURE__*/Object.freeze({
  21649. ArcCurve: ArcCurve,
  21650. CatmullRomCurve3: CatmullRomCurve3,
  21651. CubicBezierCurve: CubicBezierCurve,
  21652. CubicBezierCurve3: CubicBezierCurve3,
  21653. EllipseCurve: EllipseCurve,
  21654. LineCurve: LineCurve,
  21655. LineCurve3: LineCurve3,
  21656. QuadraticBezierCurve: QuadraticBezierCurve,
  21657. QuadraticBezierCurve3: QuadraticBezierCurve3,
  21658. SplineCurve: SplineCurve
  21659. });
  21660. /**
  21661. * @author zz85 / http://www.lab4games.net/zz85/blog
  21662. *
  21663. **/
  21664. /**************************************************************
  21665. * Curved Path - a curve path is simply a array of connected
  21666. * curves, but retains the api of a curve
  21667. **************************************************************/
  21668. function CurvePath() {
  21669. Curve.call( this );
  21670. this.type = 'CurvePath';
  21671. this.curves = [];
  21672. this.autoClose = false; // Automatically closes the path
  21673. }
  21674. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  21675. constructor: CurvePath,
  21676. add: function ( curve ) {
  21677. this.curves.push( curve );
  21678. },
  21679. closePath: function () {
  21680. // Add a line curve if start and end of lines are not connected
  21681. var startPoint = this.curves[ 0 ].getPoint( 0 );
  21682. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  21683. if ( ! startPoint.equals( endPoint ) ) {
  21684. this.curves.push( new LineCurve( endPoint, startPoint ) );
  21685. }
  21686. },
  21687. // To get accurate point with reference to
  21688. // entire path distance at time t,
  21689. // following has to be done:
  21690. // 1. Length of each sub path have to be known
  21691. // 2. Locate and identify type of curve
  21692. // 3. Get t for the curve
  21693. // 4. Return curve.getPointAt(t')
  21694. getPoint: function ( t ) {
  21695. var d = t * this.getLength();
  21696. var curveLengths = this.getCurveLengths();
  21697. var i = 0;
  21698. // To think about boundaries points.
  21699. while ( i < curveLengths.length ) {
  21700. if ( curveLengths[ i ] >= d ) {
  21701. var diff = curveLengths[ i ] - d;
  21702. var curve = this.curves[ i ];
  21703. var segmentLength = curve.getLength();
  21704. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  21705. return curve.getPointAt( u );
  21706. }
  21707. i ++;
  21708. }
  21709. return null;
  21710. // loop where sum != 0, sum > d , sum+1 <d
  21711. },
  21712. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  21713. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  21714. // getPoint() depends on getLength
  21715. getLength: function () {
  21716. var lens = this.getCurveLengths();
  21717. return lens[ lens.length - 1 ];
  21718. },
  21719. // cacheLengths must be recalculated.
  21720. updateArcLengths: function () {
  21721. this.needsUpdate = true;
  21722. this.cacheLengths = null;
  21723. this.getCurveLengths();
  21724. },
  21725. // Compute lengths and cache them
  21726. // We cannot overwrite getLengths() because UtoT mapping uses it.
  21727. getCurveLengths: function () {
  21728. // We use cache values if curves and cache array are same length
  21729. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  21730. return this.cacheLengths;
  21731. }
  21732. // Get length of sub-curve
  21733. // Push sums into cached array
  21734. var lengths = [], sums = 0;
  21735. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  21736. sums += this.curves[ i ].getLength();
  21737. lengths.push( sums );
  21738. }
  21739. this.cacheLengths = lengths;
  21740. return lengths;
  21741. },
  21742. getSpacedPoints: function ( divisions ) {
  21743. if ( divisions === undefined ) divisions = 40;
  21744. var points = [];
  21745. for ( var i = 0; i <= divisions; i ++ ) {
  21746. points.push( this.getPoint( i / divisions ) );
  21747. }
  21748. if ( this.autoClose ) {
  21749. points.push( points[ 0 ] );
  21750. }
  21751. return points;
  21752. },
  21753. getPoints: function ( divisions ) {
  21754. divisions = divisions || 12;
  21755. var points = [], last;
  21756. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  21757. var curve = curves[ i ];
  21758. var resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  21759. : ( curve && ( curve.isLineCurve || curve.isLineCurve3 ) ) ? 1
  21760. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  21761. : divisions;
  21762. var pts = curve.getPoints( resolution );
  21763. for ( var j = 0; j < pts.length; j ++ ) {
  21764. var point = pts[ j ];
  21765. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  21766. points.push( point );
  21767. last = point;
  21768. }
  21769. }
  21770. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  21771. points.push( points[ 0 ] );
  21772. }
  21773. return points;
  21774. },
  21775. copy: function ( source ) {
  21776. Curve.prototype.copy.call( this, source );
  21777. this.curves = [];
  21778. for ( var i = 0, l = source.curves.length; i < l; i ++ ) {
  21779. var curve = source.curves[ i ];
  21780. this.curves.push( curve.clone() );
  21781. }
  21782. this.autoClose = source.autoClose;
  21783. return this;
  21784. },
  21785. toJSON: function () {
  21786. var data = Curve.prototype.toJSON.call( this );
  21787. data.autoClose = this.autoClose;
  21788. data.curves = [];
  21789. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  21790. var curve = this.curves[ i ];
  21791. data.curves.push( curve.toJSON() );
  21792. }
  21793. return data;
  21794. },
  21795. fromJSON: function ( json ) {
  21796. Curve.prototype.fromJSON.call( this, json );
  21797. this.autoClose = json.autoClose;
  21798. this.curves = [];
  21799. for ( var i = 0, l = json.curves.length; i < l; i ++ ) {
  21800. var curve = json.curves[ i ];
  21801. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  21802. }
  21803. return this;
  21804. }
  21805. } );
  21806. /**
  21807. * @author zz85 / http://www.lab4games.net/zz85/blog
  21808. * Creates free form 2d path using series of points, lines or curves.
  21809. **/
  21810. function Path( points ) {
  21811. CurvePath.call( this );
  21812. this.type = 'Path';
  21813. this.currentPoint = new Vector2();
  21814. if ( points ) {
  21815. this.setFromPoints( points );
  21816. }
  21817. }
  21818. Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
  21819. constructor: Path,
  21820. setFromPoints: function ( points ) {
  21821. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  21822. for ( var i = 1, l = points.length; i < l; i ++ ) {
  21823. this.lineTo( points[ i ].x, points[ i ].y );
  21824. }
  21825. },
  21826. moveTo: function ( x, y ) {
  21827. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  21828. },
  21829. lineTo: function ( x, y ) {
  21830. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  21831. this.curves.push( curve );
  21832. this.currentPoint.set( x, y );
  21833. },
  21834. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  21835. var curve = new QuadraticBezierCurve(
  21836. this.currentPoint.clone(),
  21837. new Vector2( aCPx, aCPy ),
  21838. new Vector2( aX, aY )
  21839. );
  21840. this.curves.push( curve );
  21841. this.currentPoint.set( aX, aY );
  21842. },
  21843. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  21844. var curve = new CubicBezierCurve(
  21845. this.currentPoint.clone(),
  21846. new Vector2( aCP1x, aCP1y ),
  21847. new Vector2( aCP2x, aCP2y ),
  21848. new Vector2( aX, aY )
  21849. );
  21850. this.curves.push( curve );
  21851. this.currentPoint.set( aX, aY );
  21852. },
  21853. splineThru: function ( pts /*Array of Vector*/ ) {
  21854. var npts = [ this.currentPoint.clone() ].concat( pts );
  21855. var curve = new SplineCurve( npts );
  21856. this.curves.push( curve );
  21857. this.currentPoint.copy( pts[ pts.length - 1 ] );
  21858. },
  21859. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21860. var x0 = this.currentPoint.x;
  21861. var y0 = this.currentPoint.y;
  21862. this.absarc( aX + x0, aY + y0, aRadius,
  21863. aStartAngle, aEndAngle, aClockwise );
  21864. },
  21865. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21866. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21867. },
  21868. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21869. var x0 = this.currentPoint.x;
  21870. var y0 = this.currentPoint.y;
  21871. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  21872. },
  21873. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21874. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  21875. if ( this.curves.length > 0 ) {
  21876. // if a previous curve is present, attempt to join
  21877. var firstPoint = curve.getPoint( 0 );
  21878. if ( ! firstPoint.equals( this.currentPoint ) ) {
  21879. this.lineTo( firstPoint.x, firstPoint.y );
  21880. }
  21881. }
  21882. this.curves.push( curve );
  21883. var lastPoint = curve.getPoint( 1 );
  21884. this.currentPoint.copy( lastPoint );
  21885. },
  21886. copy: function ( source ) {
  21887. CurvePath.prototype.copy.call( this, source );
  21888. this.currentPoint.copy( source.currentPoint );
  21889. return this;
  21890. },
  21891. toJSON: function () {
  21892. var data = CurvePath.prototype.toJSON.call( this );
  21893. data.currentPoint = this.currentPoint.toArray();
  21894. return data;
  21895. },
  21896. fromJSON: function ( json ) {
  21897. CurvePath.prototype.fromJSON.call( this, json );
  21898. this.currentPoint.fromArray( json.currentPoint );
  21899. return this;
  21900. }
  21901. } );
  21902. /**
  21903. * @author zz85 / http://www.lab4games.net/zz85/blog
  21904. * Defines a 2d shape plane using paths.
  21905. **/
  21906. // STEP 1 Create a path.
  21907. // STEP 2 Turn path into shape.
  21908. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  21909. // STEP 3a - Extract points from each shape, turn to vertices
  21910. // STEP 3b - Triangulate each shape, add faces.
  21911. function Shape( points ) {
  21912. Path.call( this, points );
  21913. this.uuid = _Math.generateUUID();
  21914. this.type = 'Shape';
  21915. this.holes = [];
  21916. }
  21917. Shape.prototype = Object.assign( Object.create( Path.prototype ), {
  21918. constructor: Shape,
  21919. getPointsHoles: function ( divisions ) {
  21920. var holesPts = [];
  21921. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  21922. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  21923. }
  21924. return holesPts;
  21925. },
  21926. // get points of shape and holes (keypoints based on segments parameter)
  21927. extractPoints: function ( divisions ) {
  21928. return {
  21929. shape: this.getPoints( divisions ),
  21930. holes: this.getPointsHoles( divisions )
  21931. };
  21932. },
  21933. copy: function ( source ) {
  21934. Path.prototype.copy.call( this, source );
  21935. this.holes = [];
  21936. for ( var i = 0, l = source.holes.length; i < l; i ++ ) {
  21937. var hole = source.holes[ i ];
  21938. this.holes.push( hole.clone() );
  21939. }
  21940. return this;
  21941. },
  21942. toJSON: function () {
  21943. var data = Path.prototype.toJSON.call( this );
  21944. data.uuid = this.uuid;
  21945. data.holes = [];
  21946. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  21947. var hole = this.holes[ i ];
  21948. data.holes.push( hole.toJSON() );
  21949. }
  21950. return data;
  21951. },
  21952. fromJSON: function ( json ) {
  21953. Path.prototype.fromJSON.call( this, json );
  21954. this.uuid = json.uuid;
  21955. this.holes = [];
  21956. for ( var i = 0, l = json.holes.length; i < l; i ++ ) {
  21957. var hole = json.holes[ i ];
  21958. this.holes.push( new Path().fromJSON( hole ) );
  21959. }
  21960. return this;
  21961. }
  21962. } );
  21963. /**
  21964. * @author mrdoob / http://mrdoob.com/
  21965. * @author alteredq / http://alteredqualia.com/
  21966. */
  21967. function Light( color, intensity ) {
  21968. Object3D.call( this );
  21969. this.type = 'Light';
  21970. this.color = new Color( color );
  21971. this.intensity = intensity !== undefined ? intensity : 1;
  21972. this.receiveShadow = undefined;
  21973. }
  21974. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  21975. constructor: Light,
  21976. isLight: true,
  21977. copy: function ( source ) {
  21978. Object3D.prototype.copy.call( this, source );
  21979. this.color.copy( source.color );
  21980. this.intensity = source.intensity;
  21981. return this;
  21982. },
  21983. toJSON: function ( meta ) {
  21984. var data = Object3D.prototype.toJSON.call( this, meta );
  21985. data.object.color = this.color.getHex();
  21986. data.object.intensity = this.intensity;
  21987. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  21988. if ( this.distance !== undefined ) data.object.distance = this.distance;
  21989. if ( this.angle !== undefined ) data.object.angle = this.angle;
  21990. if ( this.decay !== undefined ) data.object.decay = this.decay;
  21991. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  21992. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  21993. return data;
  21994. }
  21995. } );
  21996. /**
  21997. * @author alteredq / http://alteredqualia.com/
  21998. */
  21999. function HemisphereLight( skyColor, groundColor, intensity ) {
  22000. Light.call( this, skyColor, intensity );
  22001. this.type = 'HemisphereLight';
  22002. this.castShadow = undefined;
  22003. this.position.copy( Object3D.DefaultUp );
  22004. this.updateMatrix();
  22005. this.groundColor = new Color( groundColor );
  22006. }
  22007. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22008. constructor: HemisphereLight,
  22009. isHemisphereLight: true,
  22010. copy: function ( source ) {
  22011. Light.prototype.copy.call( this, source );
  22012. this.groundColor.copy( source.groundColor );
  22013. return this;
  22014. }
  22015. } );
  22016. /**
  22017. * @author mrdoob / http://mrdoob.com/
  22018. */
  22019. function LightShadow( camera ) {
  22020. this.camera = camera;
  22021. this.bias = 0;
  22022. this.radius = 1;
  22023. this.mapSize = new Vector2( 512, 512 );
  22024. this.map = null;
  22025. this.matrix = new Matrix4();
  22026. }
  22027. Object.assign( LightShadow.prototype, {
  22028. copy: function ( source ) {
  22029. this.camera = source.camera.clone();
  22030. this.bias = source.bias;
  22031. this.radius = source.radius;
  22032. this.mapSize.copy( source.mapSize );
  22033. return this;
  22034. },
  22035. clone: function () {
  22036. return new this.constructor().copy( this );
  22037. },
  22038. toJSON: function () {
  22039. var object = {};
  22040. if ( this.bias !== 0 ) object.bias = this.bias;
  22041. if ( this.radius !== 1 ) object.radius = this.radius;
  22042. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  22043. object.camera = this.camera.toJSON( false ).object;
  22044. delete object.camera.matrix;
  22045. return object;
  22046. }
  22047. } );
  22048. /**
  22049. * @author mrdoob / http://mrdoob.com/
  22050. */
  22051. function SpotLightShadow() {
  22052. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  22053. }
  22054. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22055. constructor: SpotLightShadow,
  22056. isSpotLightShadow: true,
  22057. update: function ( light ) {
  22058. var camera = this.camera;
  22059. var fov = _Math.RAD2DEG * 2 * light.angle;
  22060. var aspect = this.mapSize.width / this.mapSize.height;
  22061. var far = light.distance || camera.far;
  22062. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  22063. camera.fov = fov;
  22064. camera.aspect = aspect;
  22065. camera.far = far;
  22066. camera.updateProjectionMatrix();
  22067. }
  22068. }
  22069. } );
  22070. /**
  22071. * @author alteredq / http://alteredqualia.com/
  22072. */
  22073. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  22074. Light.call( this, color, intensity );
  22075. this.type = 'SpotLight';
  22076. this.position.copy( Object3D.DefaultUp );
  22077. this.updateMatrix();
  22078. this.target = new Object3D();
  22079. Object.defineProperty( this, 'power', {
  22080. get: function () {
  22081. // intensity = power per solid angle.
  22082. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22083. return this.intensity * Math.PI;
  22084. },
  22085. set: function ( power ) {
  22086. // intensity = power per solid angle.
  22087. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22088. this.intensity = power / Math.PI;
  22089. }
  22090. } );
  22091. this.distance = ( distance !== undefined ) ? distance : 0;
  22092. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  22093. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  22094. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22095. this.shadow = new SpotLightShadow();
  22096. }
  22097. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22098. constructor: SpotLight,
  22099. isSpotLight: true,
  22100. copy: function ( source ) {
  22101. Light.prototype.copy.call( this, source );
  22102. this.distance = source.distance;
  22103. this.angle = source.angle;
  22104. this.penumbra = source.penumbra;
  22105. this.decay = source.decay;
  22106. this.target = source.target.clone();
  22107. this.shadow = source.shadow.clone();
  22108. return this;
  22109. }
  22110. } );
  22111. /**
  22112. * @author mrdoob / http://mrdoob.com/
  22113. */
  22114. function PointLight( color, intensity, distance, decay ) {
  22115. Light.call( this, color, intensity );
  22116. this.type = 'PointLight';
  22117. Object.defineProperty( this, 'power', {
  22118. get: function () {
  22119. // intensity = power per solid angle.
  22120. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22121. return this.intensity * 4 * Math.PI;
  22122. },
  22123. set: function ( power ) {
  22124. // intensity = power per solid angle.
  22125. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22126. this.intensity = power / ( 4 * Math.PI );
  22127. }
  22128. } );
  22129. this.distance = ( distance !== undefined ) ? distance : 0;
  22130. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22131. this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  22132. }
  22133. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22134. constructor: PointLight,
  22135. isPointLight: true,
  22136. copy: function ( source ) {
  22137. Light.prototype.copy.call( this, source );
  22138. this.distance = source.distance;
  22139. this.decay = source.decay;
  22140. this.shadow = source.shadow.clone();
  22141. return this;
  22142. }
  22143. } );
  22144. /**
  22145. * @author alteredq / http://alteredqualia.com/
  22146. * @author arose / http://github.com/arose
  22147. */
  22148. function OrthographicCamera( left, right, top, bottom, near, far ) {
  22149. Camera.call( this );
  22150. this.type = 'OrthographicCamera';
  22151. this.zoom = 1;
  22152. this.view = null;
  22153. this.left = ( left !== undefined ) ? left : - 1;
  22154. this.right = ( right !== undefined ) ? right : 1;
  22155. this.top = ( top !== undefined ) ? top : 1;
  22156. this.bottom = ( bottom !== undefined ) ? bottom : - 1;
  22157. this.near = ( near !== undefined ) ? near : 0.1;
  22158. this.far = ( far !== undefined ) ? far : 2000;
  22159. this.updateProjectionMatrix();
  22160. }
  22161. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  22162. constructor: OrthographicCamera,
  22163. isOrthographicCamera: true,
  22164. copy: function ( source, recursive ) {
  22165. Camera.prototype.copy.call( this, source, recursive );
  22166. this.left = source.left;
  22167. this.right = source.right;
  22168. this.top = source.top;
  22169. this.bottom = source.bottom;
  22170. this.near = source.near;
  22171. this.far = source.far;
  22172. this.zoom = source.zoom;
  22173. this.view = source.view === null ? null : Object.assign( {}, source.view );
  22174. return this;
  22175. },
  22176. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  22177. if ( this.view === null ) {
  22178. this.view = {
  22179. enabled: true,
  22180. fullWidth: 1,
  22181. fullHeight: 1,
  22182. offsetX: 0,
  22183. offsetY: 0,
  22184. width: 1,
  22185. height: 1
  22186. };
  22187. }
  22188. this.view.enabled = true;
  22189. this.view.fullWidth = fullWidth;
  22190. this.view.fullHeight = fullHeight;
  22191. this.view.offsetX = x;
  22192. this.view.offsetY = y;
  22193. this.view.width = width;
  22194. this.view.height = height;
  22195. this.updateProjectionMatrix();
  22196. },
  22197. clearViewOffset: function () {
  22198. if ( this.view !== null ) {
  22199. this.view.enabled = false;
  22200. }
  22201. this.updateProjectionMatrix();
  22202. },
  22203. updateProjectionMatrix: function () {
  22204. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  22205. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  22206. var cx = ( this.right + this.left ) / 2;
  22207. var cy = ( this.top + this.bottom ) / 2;
  22208. var left = cx - dx;
  22209. var right = cx + dx;
  22210. var top = cy + dy;
  22211. var bottom = cy - dy;
  22212. if ( this.view !== null && this.view.enabled ) {
  22213. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  22214. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  22215. var scaleW = ( this.right - this.left ) / this.view.width;
  22216. var scaleH = ( this.top - this.bottom ) / this.view.height;
  22217. left += scaleW * ( this.view.offsetX / zoomW );
  22218. right = left + scaleW * ( this.view.width / zoomW );
  22219. top -= scaleH * ( this.view.offsetY / zoomH );
  22220. bottom = top - scaleH * ( this.view.height / zoomH );
  22221. }
  22222. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  22223. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  22224. },
  22225. toJSON: function ( meta ) {
  22226. var data = Object3D.prototype.toJSON.call( this, meta );
  22227. data.object.zoom = this.zoom;
  22228. data.object.left = this.left;
  22229. data.object.right = this.right;
  22230. data.object.top = this.top;
  22231. data.object.bottom = this.bottom;
  22232. data.object.near = this.near;
  22233. data.object.far = this.far;
  22234. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  22235. return data;
  22236. }
  22237. } );
  22238. /**
  22239. * @author mrdoob / http://mrdoob.com/
  22240. */
  22241. function DirectionalLightShadow( ) {
  22242. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  22243. }
  22244. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22245. constructor: DirectionalLightShadow
  22246. } );
  22247. /**
  22248. * @author mrdoob / http://mrdoob.com/
  22249. * @author alteredq / http://alteredqualia.com/
  22250. */
  22251. function DirectionalLight( color, intensity ) {
  22252. Light.call( this, color, intensity );
  22253. this.type = 'DirectionalLight';
  22254. this.position.copy( Object3D.DefaultUp );
  22255. this.updateMatrix();
  22256. this.target = new Object3D();
  22257. this.shadow = new DirectionalLightShadow();
  22258. }
  22259. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22260. constructor: DirectionalLight,
  22261. isDirectionalLight: true,
  22262. copy: function ( source ) {
  22263. Light.prototype.copy.call( this, source );
  22264. this.target = source.target.clone();
  22265. this.shadow = source.shadow.clone();
  22266. return this;
  22267. }
  22268. } );
  22269. /**
  22270. * @author mrdoob / http://mrdoob.com/
  22271. */
  22272. function AmbientLight( color, intensity ) {
  22273. Light.call( this, color, intensity );
  22274. this.type = 'AmbientLight';
  22275. this.castShadow = undefined;
  22276. }
  22277. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22278. constructor: AmbientLight,
  22279. isAmbientLight: true
  22280. } );
  22281. /**
  22282. * @author abelnation / http://github.com/abelnation
  22283. */
  22284. function RectAreaLight( color, intensity, width, height ) {
  22285. Light.call( this, color, intensity );
  22286. this.type = 'RectAreaLight';
  22287. this.width = ( width !== undefined ) ? width : 10;
  22288. this.height = ( height !== undefined ) ? height : 10;
  22289. }
  22290. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22291. constructor: RectAreaLight,
  22292. isRectAreaLight: true,
  22293. copy: function ( source ) {
  22294. Light.prototype.copy.call( this, source );
  22295. this.width = source.width;
  22296. this.height = source.height;
  22297. return this;
  22298. },
  22299. toJSON: function ( meta ) {
  22300. var data = Light.prototype.toJSON.call( this, meta );
  22301. data.object.width = this.width;
  22302. data.object.height = this.height;
  22303. return data;
  22304. }
  22305. } );
  22306. /**
  22307. * @author mrdoob / http://mrdoob.com/
  22308. */
  22309. function MaterialLoader( manager ) {
  22310. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22311. this.textures = {};
  22312. }
  22313. Object.assign( MaterialLoader.prototype, {
  22314. load: function ( url, onLoad, onProgress, onError ) {
  22315. var scope = this;
  22316. var loader = new FileLoader( scope.manager );
  22317. loader.setPath( scope.path );
  22318. loader.load( url, function ( text ) {
  22319. onLoad( scope.parse( JSON.parse( text ) ) );
  22320. }, onProgress, onError );
  22321. },
  22322. parse: function ( json ) {
  22323. var textures = this.textures;
  22324. function getTexture( name ) {
  22325. if ( textures[ name ] === undefined ) {
  22326. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  22327. }
  22328. return textures[ name ];
  22329. }
  22330. var material = new Materials[ json.type ]();
  22331. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  22332. if ( json.name !== undefined ) material.name = json.name;
  22333. if ( json.color !== undefined ) material.color.setHex( json.color );
  22334. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  22335. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  22336. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  22337. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  22338. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  22339. if ( json.clearCoat !== undefined ) material.clearCoat = json.clearCoat;
  22340. if ( json.clearCoatRoughness !== undefined ) material.clearCoatRoughness = json.clearCoatRoughness;
  22341. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  22342. if ( json.fog !== undefined ) material.fog = json.fog;
  22343. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  22344. if ( json.blending !== undefined ) material.blending = json.blending;
  22345. if ( json.combine !== undefined ) material.combine = json.combine;
  22346. if ( json.side !== undefined ) material.side = json.side;
  22347. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  22348. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  22349. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  22350. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  22351. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  22352. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  22353. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  22354. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  22355. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  22356. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  22357. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  22358. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  22359. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  22360. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  22361. if ( json.scale !== undefined ) material.scale = json.scale;
  22362. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  22363. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  22364. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  22365. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  22366. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  22367. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  22368. if ( json.visible !== undefined ) material.visible = json.visible;
  22369. if ( json.userData !== undefined ) material.userData = json.userData;
  22370. // Shader Material
  22371. if ( json.uniforms !== undefined ) {
  22372. for ( var name in json.uniforms ) {
  22373. var uniform = json.uniforms[ name ];
  22374. material.uniforms[ name ] = {};
  22375. switch ( uniform.type ) {
  22376. case 't':
  22377. material.uniforms[ name ].value = getTexture( uniform.value );
  22378. break;
  22379. case 'c':
  22380. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  22381. break;
  22382. case 'v2':
  22383. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  22384. break;
  22385. case 'v3':
  22386. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  22387. break;
  22388. case 'v4':
  22389. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  22390. break;
  22391. case 'm3':
  22392. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  22393. case 'm4':
  22394. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  22395. break;
  22396. default:
  22397. material.uniforms[ name ].value = uniform.value;
  22398. }
  22399. }
  22400. }
  22401. if ( json.defines !== undefined ) material.defines = json.defines;
  22402. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  22403. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  22404. if ( json.extensions !== undefined ) {
  22405. for ( var key in json.extensions ) {
  22406. material.extensions[ key ] = json.extensions[ key ];
  22407. }
  22408. }
  22409. // Deprecated
  22410. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  22411. // for PointsMaterial
  22412. if ( json.size !== undefined ) material.size = json.size;
  22413. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  22414. // maps
  22415. if ( json.map !== undefined ) material.map = getTexture( json.map );
  22416. if ( json.alphaMap !== undefined ) {
  22417. material.alphaMap = getTexture( json.alphaMap );
  22418. material.transparent = true;
  22419. }
  22420. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  22421. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  22422. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  22423. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  22424. if ( json.normalScale !== undefined ) {
  22425. var normalScale = json.normalScale;
  22426. if ( Array.isArray( normalScale ) === false ) {
  22427. // Blender exporter used to export a scalar. See #7459
  22428. normalScale = [ normalScale, normalScale ];
  22429. }
  22430. material.normalScale = new Vector2().fromArray( normalScale );
  22431. }
  22432. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  22433. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  22434. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  22435. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  22436. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  22437. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  22438. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  22439. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  22440. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  22441. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  22442. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  22443. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  22444. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  22445. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  22446. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  22447. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  22448. return material;
  22449. },
  22450. setPath: function ( value ) {
  22451. this.path = value;
  22452. return this;
  22453. },
  22454. setTextures: function ( value ) {
  22455. this.textures = value;
  22456. return this;
  22457. }
  22458. } );
  22459. /**
  22460. * @author Don McCurdy / https://www.donmccurdy.com
  22461. */
  22462. var LoaderUtils = {
  22463. decodeText: function ( array ) {
  22464. if ( typeof TextDecoder !== 'undefined' ) {
  22465. return new TextDecoder().decode( array );
  22466. }
  22467. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  22468. // throws a "maximum call stack size exceeded" error for large arrays.
  22469. var s = '';
  22470. for ( var i = 0, il = array.length; i < il; i ++ ) {
  22471. // Implicitly assumes little-endian.
  22472. s += String.fromCharCode( array[ i ] );
  22473. }
  22474. // Merges multi-byte utf-8 characters.
  22475. return decodeURIComponent( escape( s ) );
  22476. },
  22477. extractUrlBase: function ( url ) {
  22478. var index = url.lastIndexOf( '/' );
  22479. if ( index === - 1 ) return './';
  22480. return url.substr( 0, index + 1 );
  22481. }
  22482. };
  22483. /**
  22484. * @author mrdoob / http://mrdoob.com/
  22485. */
  22486. function BufferGeometryLoader( manager ) {
  22487. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22488. }
  22489. Object.assign( BufferGeometryLoader.prototype, {
  22490. load: function ( url, onLoad, onProgress, onError ) {
  22491. var scope = this;
  22492. var loader = new FileLoader( scope.manager );
  22493. loader.setPath( scope.path );
  22494. loader.load( url, function ( text ) {
  22495. onLoad( scope.parse( JSON.parse( text ) ) );
  22496. }, onProgress, onError );
  22497. },
  22498. parse: function ( json ) {
  22499. var geometry = new BufferGeometry();
  22500. var index = json.data.index;
  22501. if ( index !== undefined ) {
  22502. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  22503. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  22504. }
  22505. var attributes = json.data.attributes;
  22506. for ( var key in attributes ) {
  22507. var attribute = attributes[ key ];
  22508. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  22509. geometry.addAttribute( key, new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized ) );
  22510. }
  22511. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  22512. if ( groups !== undefined ) {
  22513. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  22514. var group = groups[ i ];
  22515. geometry.addGroup( group.start, group.count, group.materialIndex );
  22516. }
  22517. }
  22518. var boundingSphere = json.data.boundingSphere;
  22519. if ( boundingSphere !== undefined ) {
  22520. var center = new Vector3();
  22521. if ( boundingSphere.center !== undefined ) {
  22522. center.fromArray( boundingSphere.center );
  22523. }
  22524. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  22525. }
  22526. if ( json.name ) geometry.name = json.name;
  22527. if ( json.userData ) geometry.userData = json.userData;
  22528. return geometry;
  22529. },
  22530. setPath: function ( value ) {
  22531. this.path = value;
  22532. return this;
  22533. }
  22534. } );
  22535. var TYPED_ARRAYS = {
  22536. Int8Array: Int8Array,
  22537. Uint8Array: Uint8Array,
  22538. // Workaround for IE11 pre KB2929437. See #11440
  22539. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  22540. Int16Array: Int16Array,
  22541. Uint16Array: Uint16Array,
  22542. Int32Array: Int32Array,
  22543. Uint32Array: Uint32Array,
  22544. Float32Array: Float32Array,
  22545. Float64Array: Float64Array
  22546. };
  22547. /**
  22548. * @author mrdoob / http://mrdoob.com/
  22549. */
  22550. function ObjectLoader( manager ) {
  22551. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22552. this.resourcePath = '';
  22553. }
  22554. Object.assign( ObjectLoader.prototype, {
  22555. crossOrigin: 'anonymous',
  22556. load: function ( url, onLoad, onProgress, onError ) {
  22557. var scope = this;
  22558. var path = ( this.path === undefined ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  22559. this.resourcePath = this.resourcePath || path;
  22560. var loader = new FileLoader( scope.manager );
  22561. loader.setPath( this.path );
  22562. loader.load( url, function ( text ) {
  22563. var json = null;
  22564. try {
  22565. json = JSON.parse( text );
  22566. } catch ( error ) {
  22567. if ( onError !== undefined ) onError( error );
  22568. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  22569. return;
  22570. }
  22571. var metadata = json.metadata;
  22572. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  22573. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  22574. return;
  22575. }
  22576. scope.parse( json, onLoad );
  22577. }, onProgress, onError );
  22578. },
  22579. setPath: function ( value ) {
  22580. this.path = value;
  22581. return this;
  22582. },
  22583. setResourcePath: function ( value ) {
  22584. this.resourcePath = value;
  22585. return this;
  22586. },
  22587. setCrossOrigin: function ( value ) {
  22588. this.crossOrigin = value;
  22589. return this;
  22590. },
  22591. parse: function ( json, onLoad ) {
  22592. var shapes = this.parseShape( json.shapes );
  22593. var geometries = this.parseGeometries( json.geometries, shapes );
  22594. var images = this.parseImages( json.images, function () {
  22595. if ( onLoad !== undefined ) onLoad( object );
  22596. } );
  22597. var textures = this.parseTextures( json.textures, images );
  22598. var materials = this.parseMaterials( json.materials, textures );
  22599. var object = this.parseObject( json.object, geometries, materials );
  22600. if ( json.animations ) {
  22601. object.animations = this.parseAnimations( json.animations );
  22602. }
  22603. if ( json.images === undefined || json.images.length === 0 ) {
  22604. if ( onLoad !== undefined ) onLoad( object );
  22605. }
  22606. return object;
  22607. },
  22608. parseShape: function ( json ) {
  22609. var shapes = {};
  22610. if ( json !== undefined ) {
  22611. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22612. var shape = new Shape().fromJSON( json[ i ] );
  22613. shapes[ shape.uuid ] = shape;
  22614. }
  22615. }
  22616. return shapes;
  22617. },
  22618. parseGeometries: function ( json, shapes ) {
  22619. var geometries = {};
  22620. if ( json !== undefined ) {
  22621. var bufferGeometryLoader = new BufferGeometryLoader();
  22622. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22623. var geometry;
  22624. var data = json[ i ];
  22625. switch ( data.type ) {
  22626. case 'PlaneGeometry':
  22627. case 'PlaneBufferGeometry':
  22628. geometry = new Geometries[ data.type ](
  22629. data.width,
  22630. data.height,
  22631. data.widthSegments,
  22632. data.heightSegments
  22633. );
  22634. break;
  22635. case 'BoxGeometry':
  22636. case 'BoxBufferGeometry':
  22637. case 'CubeGeometry': // backwards compatible
  22638. geometry = new Geometries[ data.type ](
  22639. data.width,
  22640. data.height,
  22641. data.depth,
  22642. data.widthSegments,
  22643. data.heightSegments,
  22644. data.depthSegments
  22645. );
  22646. break;
  22647. case 'CircleGeometry':
  22648. case 'CircleBufferGeometry':
  22649. geometry = new Geometries[ data.type ](
  22650. data.radius,
  22651. data.segments,
  22652. data.thetaStart,
  22653. data.thetaLength
  22654. );
  22655. break;
  22656. case 'CylinderGeometry':
  22657. case 'CylinderBufferGeometry':
  22658. geometry = new Geometries[ data.type ](
  22659. data.radiusTop,
  22660. data.radiusBottom,
  22661. data.height,
  22662. data.radialSegments,
  22663. data.heightSegments,
  22664. data.openEnded,
  22665. data.thetaStart,
  22666. data.thetaLength
  22667. );
  22668. break;
  22669. case 'ConeGeometry':
  22670. case 'ConeBufferGeometry':
  22671. geometry = new Geometries[ data.type ](
  22672. data.radius,
  22673. data.height,
  22674. data.radialSegments,
  22675. data.heightSegments,
  22676. data.openEnded,
  22677. data.thetaStart,
  22678. data.thetaLength
  22679. );
  22680. break;
  22681. case 'SphereGeometry':
  22682. case 'SphereBufferGeometry':
  22683. geometry = new Geometries[ data.type ](
  22684. data.radius,
  22685. data.widthSegments,
  22686. data.heightSegments,
  22687. data.phiStart,
  22688. data.phiLength,
  22689. data.thetaStart,
  22690. data.thetaLength
  22691. );
  22692. break;
  22693. case 'DodecahedronGeometry':
  22694. case 'DodecahedronBufferGeometry':
  22695. case 'IcosahedronGeometry':
  22696. case 'IcosahedronBufferGeometry':
  22697. case 'OctahedronGeometry':
  22698. case 'OctahedronBufferGeometry':
  22699. case 'TetrahedronGeometry':
  22700. case 'TetrahedronBufferGeometry':
  22701. geometry = new Geometries[ data.type ](
  22702. data.radius,
  22703. data.detail
  22704. );
  22705. break;
  22706. case 'RingGeometry':
  22707. case 'RingBufferGeometry':
  22708. geometry = new Geometries[ data.type ](
  22709. data.innerRadius,
  22710. data.outerRadius,
  22711. data.thetaSegments,
  22712. data.phiSegments,
  22713. data.thetaStart,
  22714. data.thetaLength
  22715. );
  22716. break;
  22717. case 'TorusGeometry':
  22718. case 'TorusBufferGeometry':
  22719. geometry = new Geometries[ data.type ](
  22720. data.radius,
  22721. data.tube,
  22722. data.radialSegments,
  22723. data.tubularSegments,
  22724. data.arc
  22725. );
  22726. break;
  22727. case 'TorusKnotGeometry':
  22728. case 'TorusKnotBufferGeometry':
  22729. geometry = new Geometries[ data.type ](
  22730. data.radius,
  22731. data.tube,
  22732. data.tubularSegments,
  22733. data.radialSegments,
  22734. data.p,
  22735. data.q
  22736. );
  22737. break;
  22738. case 'LatheGeometry':
  22739. case 'LatheBufferGeometry':
  22740. geometry = new Geometries[ data.type ](
  22741. data.points,
  22742. data.segments,
  22743. data.phiStart,
  22744. data.phiLength
  22745. );
  22746. break;
  22747. case 'PolyhedronGeometry':
  22748. case 'PolyhedronBufferGeometry':
  22749. geometry = new Geometries[ data.type ](
  22750. data.vertices,
  22751. data.indices,
  22752. data.radius,
  22753. data.details
  22754. );
  22755. break;
  22756. case 'ShapeGeometry':
  22757. case 'ShapeBufferGeometry':
  22758. var geometryShapes = [];
  22759. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  22760. var shape = shapes[ data.shapes[ j ] ];
  22761. geometryShapes.push( shape );
  22762. }
  22763. geometry = new Geometries[ data.type ](
  22764. geometryShapes,
  22765. data.curveSegments
  22766. );
  22767. break;
  22768. case 'ExtrudeGeometry':
  22769. case 'ExtrudeBufferGeometry':
  22770. var geometryShapes = [];
  22771. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  22772. var shape = shapes[ data.shapes[ j ] ];
  22773. geometryShapes.push( shape );
  22774. }
  22775. var extrudePath = data.options.extrudePath;
  22776. if ( extrudePath !== undefined ) {
  22777. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  22778. }
  22779. geometry = new Geometries[ data.type ](
  22780. geometryShapes,
  22781. data.options
  22782. );
  22783. break;
  22784. case 'BufferGeometry':
  22785. geometry = bufferGeometryLoader.parse( data );
  22786. break;
  22787. case 'Geometry':
  22788. if ( 'THREE' in window && 'LegacyJSONLoader' in THREE ) {
  22789. var geometryLoader = new THREE.LegacyJSONLoader();
  22790. geometry = geometryLoader.parse( data, this.resourcePath ).geometry;
  22791. } else {
  22792. console.error( 'THREE.ObjectLoader: You have to import LegacyJSONLoader in order load geometry data of type "Geometry".' );
  22793. }
  22794. break;
  22795. default:
  22796. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  22797. continue;
  22798. }
  22799. geometry.uuid = data.uuid;
  22800. if ( data.name !== undefined ) geometry.name = data.name;
  22801. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
  22802. geometries[ data.uuid ] = geometry;
  22803. }
  22804. }
  22805. return geometries;
  22806. },
  22807. parseMaterials: function ( json, textures ) {
  22808. var cache = {}; // MultiMaterial
  22809. var materials = {};
  22810. if ( json !== undefined ) {
  22811. var loader = new MaterialLoader();
  22812. loader.setTextures( textures );
  22813. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22814. var data = json[ i ];
  22815. if ( data.type === 'MultiMaterial' ) {
  22816. // Deprecated
  22817. var array = [];
  22818. for ( var j = 0; j < data.materials.length; j ++ ) {
  22819. var material = data.materials[ j ];
  22820. if ( cache[ material.uuid ] === undefined ) {
  22821. cache[ material.uuid ] = loader.parse( material );
  22822. }
  22823. array.push( cache[ material.uuid ] );
  22824. }
  22825. materials[ data.uuid ] = array;
  22826. } else {
  22827. materials[ data.uuid ] = loader.parse( data );
  22828. cache[ data.uuid ] = materials[ data.uuid ];
  22829. }
  22830. }
  22831. }
  22832. return materials;
  22833. },
  22834. parseAnimations: function ( json ) {
  22835. var animations = [];
  22836. for ( var i = 0; i < json.length; i ++ ) {
  22837. var data = json[ i ];
  22838. var clip = AnimationClip.parse( data );
  22839. if ( data.uuid !== undefined ) clip.uuid = data.uuid;
  22840. animations.push( clip );
  22841. }
  22842. return animations;
  22843. },
  22844. parseImages: function ( json, onLoad ) {
  22845. var scope = this;
  22846. var images = {};
  22847. function loadImage( url ) {
  22848. scope.manager.itemStart( url );
  22849. return loader.load( url, function () {
  22850. scope.manager.itemEnd( url );
  22851. }, undefined, function () {
  22852. scope.manager.itemError( url );
  22853. scope.manager.itemEnd( url );
  22854. } );
  22855. }
  22856. if ( json !== undefined && json.length > 0 ) {
  22857. var manager = new LoadingManager( onLoad );
  22858. var loader = new ImageLoader( manager );
  22859. loader.setCrossOrigin( this.crossOrigin );
  22860. for ( var i = 0, il = json.length; i < il; i ++ ) {
  22861. var image = json[ i ];
  22862. var url = image.url;
  22863. if ( Array.isArray( url ) ) {
  22864. // load array of images e.g CubeTexture
  22865. images[ image.uuid ] = [];
  22866. for ( var j = 0, jl = url.length; j < jl; j ++ ) {
  22867. var currentUrl = url[ j ];
  22868. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl;
  22869. images[ image.uuid ].push( loadImage( path ) );
  22870. }
  22871. } else {
  22872. // load single image
  22873. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url;
  22874. images[ image.uuid ] = loadImage( path );
  22875. }
  22876. }
  22877. }
  22878. return images;
  22879. },
  22880. parseTextures: function ( json, images ) {
  22881. function parseConstant( value, type ) {
  22882. if ( typeof value === 'number' ) return value;
  22883. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  22884. return type[ value ];
  22885. }
  22886. var textures = {};
  22887. if ( json !== undefined ) {
  22888. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22889. var data = json[ i ];
  22890. if ( data.image === undefined ) {
  22891. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  22892. }
  22893. if ( images[ data.image ] === undefined ) {
  22894. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  22895. }
  22896. var texture;
  22897. if ( Array.isArray( images[ data.image ] ) ) {
  22898. texture = new CubeTexture( images[ data.image ] );
  22899. } else {
  22900. texture = new Texture( images[ data.image ] );
  22901. }
  22902. texture.needsUpdate = true;
  22903. texture.uuid = data.uuid;
  22904. if ( data.name !== undefined ) texture.name = data.name;
  22905. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  22906. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  22907. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  22908. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  22909. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  22910. if ( data.wrap !== undefined ) {
  22911. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  22912. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  22913. }
  22914. if ( data.format !== undefined ) texture.format = data.format;
  22915. if ( data.type !== undefined ) texture.type = data.type;
  22916. if ( data.encoding !== undefined ) texture.encoding = data.encoding;
  22917. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  22918. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  22919. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  22920. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  22921. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  22922. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  22923. textures[ data.uuid ] = texture;
  22924. }
  22925. }
  22926. return textures;
  22927. },
  22928. parseObject: function ( data, geometries, materials ) {
  22929. var object;
  22930. function getGeometry( name ) {
  22931. if ( geometries[ name ] === undefined ) {
  22932. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  22933. }
  22934. return geometries[ name ];
  22935. }
  22936. function getMaterial( name ) {
  22937. if ( name === undefined ) return undefined;
  22938. if ( Array.isArray( name ) ) {
  22939. var array = [];
  22940. for ( var i = 0, l = name.length; i < l; i ++ ) {
  22941. var uuid = name[ i ];
  22942. if ( materials[ uuid ] === undefined ) {
  22943. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  22944. }
  22945. array.push( materials[ uuid ] );
  22946. }
  22947. return array;
  22948. }
  22949. if ( materials[ name ] === undefined ) {
  22950. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  22951. }
  22952. return materials[ name ];
  22953. }
  22954. switch ( data.type ) {
  22955. case 'Scene':
  22956. object = new Scene();
  22957. if ( data.background !== undefined ) {
  22958. if ( Number.isInteger( data.background ) ) {
  22959. object.background = new Color( data.background );
  22960. }
  22961. }
  22962. if ( data.fog !== undefined ) {
  22963. if ( data.fog.type === 'Fog' ) {
  22964. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  22965. } else if ( data.fog.type === 'FogExp2' ) {
  22966. object.fog = new FogExp2( data.fog.color, data.fog.density );
  22967. }
  22968. }
  22969. break;
  22970. case 'PerspectiveCamera':
  22971. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  22972. if ( data.focus !== undefined ) object.focus = data.focus;
  22973. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  22974. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  22975. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  22976. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  22977. break;
  22978. case 'OrthographicCamera':
  22979. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  22980. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  22981. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  22982. break;
  22983. case 'AmbientLight':
  22984. object = new AmbientLight( data.color, data.intensity );
  22985. break;
  22986. case 'DirectionalLight':
  22987. object = new DirectionalLight( data.color, data.intensity );
  22988. break;
  22989. case 'PointLight':
  22990. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  22991. break;
  22992. case 'RectAreaLight':
  22993. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  22994. break;
  22995. case 'SpotLight':
  22996. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  22997. break;
  22998. case 'HemisphereLight':
  22999. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  23000. break;
  23001. case 'SkinnedMesh':
  23002. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  23003. case 'Mesh':
  23004. var geometry = getGeometry( data.geometry );
  23005. var material = getMaterial( data.material );
  23006. if ( geometry.bones && geometry.bones.length > 0 ) {
  23007. object = new SkinnedMesh( geometry, material );
  23008. } else {
  23009. object = new Mesh( geometry, material );
  23010. }
  23011. break;
  23012. case 'LOD':
  23013. object = new LOD();
  23014. break;
  23015. case 'Line':
  23016. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  23017. break;
  23018. case 'LineLoop':
  23019. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  23020. break;
  23021. case 'LineSegments':
  23022. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  23023. break;
  23024. case 'PointCloud':
  23025. case 'Points':
  23026. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  23027. break;
  23028. case 'Sprite':
  23029. object = new Sprite( getMaterial( data.material ) );
  23030. break;
  23031. case 'Group':
  23032. object = new Group();
  23033. break;
  23034. default:
  23035. object = new Object3D();
  23036. }
  23037. object.uuid = data.uuid;
  23038. if ( data.name !== undefined ) object.name = data.name;
  23039. if ( data.matrix !== undefined ) {
  23040. object.matrix.fromArray( data.matrix );
  23041. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  23042. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  23043. } else {
  23044. if ( data.position !== undefined ) object.position.fromArray( data.position );
  23045. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  23046. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  23047. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  23048. }
  23049. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  23050. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  23051. if ( data.shadow ) {
  23052. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  23053. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  23054. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  23055. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  23056. }
  23057. if ( data.visible !== undefined ) object.visible = data.visible;
  23058. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  23059. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  23060. if ( data.userData !== undefined ) object.userData = data.userData;
  23061. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  23062. if ( data.children !== undefined ) {
  23063. var children = data.children;
  23064. for ( var i = 0; i < children.length; i ++ ) {
  23065. object.add( this.parseObject( children[ i ], geometries, materials ) );
  23066. }
  23067. }
  23068. if ( data.type === 'LOD' ) {
  23069. var levels = data.levels;
  23070. for ( var l = 0; l < levels.length; l ++ ) {
  23071. var level = levels[ l ];
  23072. var child = object.getObjectByProperty( 'uuid', level.object );
  23073. if ( child !== undefined ) {
  23074. object.addLevel( child, level.distance );
  23075. }
  23076. }
  23077. }
  23078. return object;
  23079. }
  23080. } );
  23081. var TEXTURE_MAPPING = {
  23082. UVMapping: UVMapping,
  23083. CubeReflectionMapping: CubeReflectionMapping,
  23084. CubeRefractionMapping: CubeRefractionMapping,
  23085. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  23086. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  23087. SphericalReflectionMapping: SphericalReflectionMapping,
  23088. CubeUVReflectionMapping: CubeUVReflectionMapping,
  23089. CubeUVRefractionMapping: CubeUVRefractionMapping
  23090. };
  23091. var TEXTURE_WRAPPING = {
  23092. RepeatWrapping: RepeatWrapping,
  23093. ClampToEdgeWrapping: ClampToEdgeWrapping,
  23094. MirroredRepeatWrapping: MirroredRepeatWrapping
  23095. };
  23096. var TEXTURE_FILTER = {
  23097. NearestFilter: NearestFilter,
  23098. NearestMipMapNearestFilter: NearestMipMapNearestFilter,
  23099. NearestMipMapLinearFilter: NearestMipMapLinearFilter,
  23100. LinearFilter: LinearFilter,
  23101. LinearMipMapNearestFilter: LinearMipMapNearestFilter,
  23102. LinearMipMapLinearFilter: LinearMipMapLinearFilter
  23103. };
  23104. /**
  23105. * @author thespite / http://clicktorelease.com/
  23106. */
  23107. function ImageBitmapLoader( manager ) {
  23108. if ( typeof createImageBitmap === 'undefined' ) {
  23109. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  23110. }
  23111. if ( typeof fetch === 'undefined' ) {
  23112. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  23113. }
  23114. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  23115. this.options = undefined;
  23116. }
  23117. ImageBitmapLoader.prototype = {
  23118. constructor: ImageBitmapLoader,
  23119. setOptions: function setOptions( options ) {
  23120. this.options = options;
  23121. return this;
  23122. },
  23123. load: function ( url, onLoad, onProgress, onError ) {
  23124. if ( url === undefined ) url = '';
  23125. if ( this.path !== undefined ) url = this.path + url;
  23126. url = this.manager.resolveURL( url );
  23127. var scope = this;
  23128. var cached = Cache.get( url );
  23129. if ( cached !== undefined ) {
  23130. scope.manager.itemStart( url );
  23131. setTimeout( function () {
  23132. if ( onLoad ) onLoad( cached );
  23133. scope.manager.itemEnd( url );
  23134. }, 0 );
  23135. return cached;
  23136. }
  23137. fetch( url ).then( function ( res ) {
  23138. return res.blob();
  23139. } ).then( function ( blob ) {
  23140. return createImageBitmap( blob, scope.options );
  23141. } ).then( function ( imageBitmap ) {
  23142. Cache.add( url, imageBitmap );
  23143. if ( onLoad ) onLoad( imageBitmap );
  23144. scope.manager.itemEnd( url );
  23145. } ).catch( function ( e ) {
  23146. if ( onError ) onError( e );
  23147. scope.manager.itemError( url );
  23148. scope.manager.itemEnd( url );
  23149. } );
  23150. },
  23151. setCrossOrigin: function ( /* value */ ) {
  23152. return this;
  23153. },
  23154. setPath: function ( value ) {
  23155. this.path = value;
  23156. return this;
  23157. }
  23158. };
  23159. /**
  23160. * @author zz85 / http://www.lab4games.net/zz85/blog
  23161. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  23162. **/
  23163. function ShapePath() {
  23164. this.type = 'ShapePath';
  23165. this.color = new Color();
  23166. this.subPaths = [];
  23167. this.currentPath = null;
  23168. }
  23169. Object.assign( ShapePath.prototype, {
  23170. moveTo: function ( x, y ) {
  23171. this.currentPath = new Path();
  23172. this.subPaths.push( this.currentPath );
  23173. this.currentPath.moveTo( x, y );
  23174. },
  23175. lineTo: function ( x, y ) {
  23176. this.currentPath.lineTo( x, y );
  23177. },
  23178. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  23179. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  23180. },
  23181. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  23182. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  23183. },
  23184. splineThru: function ( pts ) {
  23185. this.currentPath.splineThru( pts );
  23186. },
  23187. toShapes: function ( isCCW, noHoles ) {
  23188. function toShapesNoHoles( inSubpaths ) {
  23189. var shapes = [];
  23190. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  23191. var tmpPath = inSubpaths[ i ];
  23192. var tmpShape = new Shape();
  23193. tmpShape.curves = tmpPath.curves;
  23194. shapes.push( tmpShape );
  23195. }
  23196. return shapes;
  23197. }
  23198. function isPointInsidePolygon( inPt, inPolygon ) {
  23199. var polyLen = inPolygon.length;
  23200. // inPt on polygon contour => immediate success or
  23201. // toggling of inside/outside at every single! intersection point of an edge
  23202. // with the horizontal line through inPt, left of inPt
  23203. // not counting lowerY endpoints of edges and whole edges on that line
  23204. var inside = false;
  23205. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  23206. var edgeLowPt = inPolygon[ p ];
  23207. var edgeHighPt = inPolygon[ q ];
  23208. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  23209. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  23210. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  23211. // not parallel
  23212. if ( edgeDy < 0 ) {
  23213. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  23214. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  23215. }
  23216. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  23217. if ( inPt.y === edgeLowPt.y ) {
  23218. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  23219. // continue; // no intersection or edgeLowPt => doesn't count !!!
  23220. } else {
  23221. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  23222. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  23223. if ( perpEdge < 0 ) continue;
  23224. inside = ! inside; // true intersection left of inPt
  23225. }
  23226. } else {
  23227. // parallel or collinear
  23228. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  23229. // edge lies on the same horizontal line as inPt
  23230. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  23231. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  23232. // continue;
  23233. }
  23234. }
  23235. return inside;
  23236. }
  23237. var isClockWise = ShapeUtils.isClockWise;
  23238. var subPaths = this.subPaths;
  23239. if ( subPaths.length === 0 ) return [];
  23240. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  23241. var solid, tmpPath, tmpShape, shapes = [];
  23242. if ( subPaths.length === 1 ) {
  23243. tmpPath = subPaths[ 0 ];
  23244. tmpShape = new Shape();
  23245. tmpShape.curves = tmpPath.curves;
  23246. shapes.push( tmpShape );
  23247. return shapes;
  23248. }
  23249. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  23250. holesFirst = isCCW ? ! holesFirst : holesFirst;
  23251. // console.log("Holes first", holesFirst);
  23252. var betterShapeHoles = [];
  23253. var newShapes = [];
  23254. var newShapeHoles = [];
  23255. var mainIdx = 0;
  23256. var tmpPoints;
  23257. newShapes[ mainIdx ] = undefined;
  23258. newShapeHoles[ mainIdx ] = [];
  23259. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  23260. tmpPath = subPaths[ i ];
  23261. tmpPoints = tmpPath.getPoints();
  23262. solid = isClockWise( tmpPoints );
  23263. solid = isCCW ? ! solid : solid;
  23264. if ( solid ) {
  23265. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  23266. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  23267. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  23268. if ( holesFirst ) mainIdx ++;
  23269. newShapeHoles[ mainIdx ] = [];
  23270. //console.log('cw', i);
  23271. } else {
  23272. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  23273. //console.log('ccw', i);
  23274. }
  23275. }
  23276. // only Holes? -> probably all Shapes with wrong orientation
  23277. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  23278. if ( newShapes.length > 1 ) {
  23279. var ambiguous = false;
  23280. var toChange = [];
  23281. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23282. betterShapeHoles[ sIdx ] = [];
  23283. }
  23284. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23285. var sho = newShapeHoles[ sIdx ];
  23286. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  23287. var ho = sho[ hIdx ];
  23288. var hole_unassigned = true;
  23289. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  23290. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  23291. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  23292. if ( hole_unassigned ) {
  23293. hole_unassigned = false;
  23294. betterShapeHoles[ s2Idx ].push( ho );
  23295. } else {
  23296. ambiguous = true;
  23297. }
  23298. }
  23299. }
  23300. if ( hole_unassigned ) {
  23301. betterShapeHoles[ sIdx ].push( ho );
  23302. }
  23303. }
  23304. }
  23305. // console.log("ambiguous: ", ambiguous);
  23306. if ( toChange.length > 0 ) {
  23307. // console.log("to change: ", toChange);
  23308. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  23309. }
  23310. }
  23311. var tmpHoles;
  23312. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  23313. tmpShape = newShapes[ i ].s;
  23314. shapes.push( tmpShape );
  23315. tmpHoles = newShapeHoles[ i ];
  23316. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  23317. tmpShape.holes.push( tmpHoles[ j ].h );
  23318. }
  23319. }
  23320. //console.log("shape", shapes);
  23321. return shapes;
  23322. }
  23323. } );
  23324. /**
  23325. * @author zz85 / http://www.lab4games.net/zz85/blog
  23326. * @author mrdoob / http://mrdoob.com/
  23327. */
  23328. function Font( data ) {
  23329. this.type = 'Font';
  23330. this.data = data;
  23331. }
  23332. Object.assign( Font.prototype, {
  23333. isFont: true,
  23334. generateShapes: function ( text, size ) {
  23335. if ( size === undefined ) size = 100;
  23336. var shapes = [];
  23337. var paths = createPaths( text, size, this.data );
  23338. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  23339. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  23340. }
  23341. return shapes;
  23342. }
  23343. } );
  23344. function createPaths( text, size, data ) {
  23345. var chars = Array.from ? Array.from( text ) : String( text ).split( '' ); // see #13988
  23346. var scale = size / data.resolution;
  23347. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  23348. var paths = [];
  23349. var offsetX = 0, offsetY = 0;
  23350. for ( var i = 0; i < chars.length; i ++ ) {
  23351. var char = chars[ i ];
  23352. if ( char === '\n' ) {
  23353. offsetX = 0;
  23354. offsetY -= line_height;
  23355. } else {
  23356. var ret = createPath( char, scale, offsetX, offsetY, data );
  23357. offsetX += ret.offsetX;
  23358. paths.push( ret.path );
  23359. }
  23360. }
  23361. return paths;
  23362. }
  23363. function createPath( char, scale, offsetX, offsetY, data ) {
  23364. var glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  23365. if ( ! glyph ) return;
  23366. var path = new ShapePath();
  23367. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  23368. if ( glyph.o ) {
  23369. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  23370. for ( var i = 0, l = outline.length; i < l; ) {
  23371. var action = outline[ i ++ ];
  23372. switch ( action ) {
  23373. case 'm': // moveTo
  23374. x = outline[ i ++ ] * scale + offsetX;
  23375. y = outline[ i ++ ] * scale + offsetY;
  23376. path.moveTo( x, y );
  23377. break;
  23378. case 'l': // lineTo
  23379. x = outline[ i ++ ] * scale + offsetX;
  23380. y = outline[ i ++ ] * scale + offsetY;
  23381. path.lineTo( x, y );
  23382. break;
  23383. case 'q': // quadraticCurveTo
  23384. cpx = outline[ i ++ ] * scale + offsetX;
  23385. cpy = outline[ i ++ ] * scale + offsetY;
  23386. cpx1 = outline[ i ++ ] * scale + offsetX;
  23387. cpy1 = outline[ i ++ ] * scale + offsetY;
  23388. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  23389. break;
  23390. case 'b': // bezierCurveTo
  23391. cpx = outline[ i ++ ] * scale + offsetX;
  23392. cpy = outline[ i ++ ] * scale + offsetY;
  23393. cpx1 = outline[ i ++ ] * scale + offsetX;
  23394. cpy1 = outline[ i ++ ] * scale + offsetY;
  23395. cpx2 = outline[ i ++ ] * scale + offsetX;
  23396. cpy2 = outline[ i ++ ] * scale + offsetY;
  23397. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  23398. break;
  23399. }
  23400. }
  23401. }
  23402. return { offsetX: glyph.ha * scale, path: path };
  23403. }
  23404. /**
  23405. * @author mrdoob / http://mrdoob.com/
  23406. */
  23407. function FontLoader( manager ) {
  23408. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23409. }
  23410. Object.assign( FontLoader.prototype, {
  23411. load: function ( url, onLoad, onProgress, onError ) {
  23412. var scope = this;
  23413. var loader = new FileLoader( this.manager );
  23414. loader.setPath( this.path );
  23415. loader.load( url, function ( text ) {
  23416. var json;
  23417. try {
  23418. json = JSON.parse( text );
  23419. } catch ( e ) {
  23420. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  23421. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  23422. }
  23423. var font = scope.parse( json );
  23424. if ( onLoad ) onLoad( font );
  23425. }, onProgress, onError );
  23426. },
  23427. parse: function ( json ) {
  23428. return new Font( json );
  23429. },
  23430. setPath: function ( value ) {
  23431. this.path = value;
  23432. return this;
  23433. }
  23434. } );
  23435. /**
  23436. * @author alteredq / http://alteredqualia.com/
  23437. */
  23438. function Loader() {}
  23439. Loader.Handlers = {
  23440. handlers: [],
  23441. add: function ( regex, loader ) {
  23442. this.handlers.push( regex, loader );
  23443. },
  23444. get: function ( file ) {
  23445. var handlers = this.handlers;
  23446. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  23447. var regex = handlers[ i ];
  23448. var loader = handlers[ i + 1 ];
  23449. if ( regex.test( file ) ) {
  23450. return loader;
  23451. }
  23452. }
  23453. return null;
  23454. }
  23455. };
  23456. Object.assign( Loader.prototype, {
  23457. crossOrigin: 'anonymous',
  23458. onLoadStart: function () {},
  23459. onLoadProgress: function () {},
  23460. onLoadComplete: function () {},
  23461. initMaterials: function ( materials, texturePath, crossOrigin ) {
  23462. var array = [];
  23463. for ( var i = 0; i < materials.length; ++ i ) {
  23464. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  23465. }
  23466. return array;
  23467. },
  23468. createMaterial: ( function () {
  23469. var BlendingMode = {
  23470. NoBlending: NoBlending,
  23471. NormalBlending: NormalBlending,
  23472. AdditiveBlending: AdditiveBlending,
  23473. SubtractiveBlending: SubtractiveBlending,
  23474. MultiplyBlending: MultiplyBlending,
  23475. CustomBlending: CustomBlending
  23476. };
  23477. var color = new Color();
  23478. var textureLoader = new TextureLoader();
  23479. var materialLoader = new MaterialLoader();
  23480. return function createMaterial( m, texturePath, crossOrigin ) {
  23481. // convert from old material format
  23482. var textures = {};
  23483. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  23484. var fullPath = texturePath + path;
  23485. var loader = Loader.Handlers.get( fullPath );
  23486. var texture;
  23487. if ( loader !== null ) {
  23488. texture = loader.load( fullPath );
  23489. } else {
  23490. textureLoader.setCrossOrigin( crossOrigin );
  23491. texture = textureLoader.load( fullPath );
  23492. }
  23493. if ( repeat !== undefined ) {
  23494. texture.repeat.fromArray( repeat );
  23495. if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
  23496. if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
  23497. }
  23498. if ( offset !== undefined ) {
  23499. texture.offset.fromArray( offset );
  23500. }
  23501. if ( wrap !== undefined ) {
  23502. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
  23503. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
  23504. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
  23505. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
  23506. }
  23507. if ( anisotropy !== undefined ) {
  23508. texture.anisotropy = anisotropy;
  23509. }
  23510. var uuid = _Math.generateUUID();
  23511. textures[ uuid ] = texture;
  23512. return uuid;
  23513. }
  23514. //
  23515. var json = {
  23516. uuid: _Math.generateUUID(),
  23517. type: 'MeshLambertMaterial'
  23518. };
  23519. for ( var name in m ) {
  23520. var value = m[ name ];
  23521. switch ( name ) {
  23522. case 'DbgColor':
  23523. case 'DbgIndex':
  23524. case 'opticalDensity':
  23525. case 'illumination':
  23526. break;
  23527. case 'DbgName':
  23528. json.name = value;
  23529. break;
  23530. case 'blending':
  23531. json.blending = BlendingMode[ value ];
  23532. break;
  23533. case 'colorAmbient':
  23534. case 'mapAmbient':
  23535. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  23536. break;
  23537. case 'colorDiffuse':
  23538. json.color = color.fromArray( value ).getHex();
  23539. break;
  23540. case 'colorSpecular':
  23541. json.specular = color.fromArray( value ).getHex();
  23542. break;
  23543. case 'colorEmissive':
  23544. json.emissive = color.fromArray( value ).getHex();
  23545. break;
  23546. case 'specularCoef':
  23547. json.shininess = value;
  23548. break;
  23549. case 'shading':
  23550. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  23551. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  23552. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  23553. break;
  23554. case 'mapDiffuse':
  23555. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  23556. break;
  23557. case 'mapDiffuseRepeat':
  23558. case 'mapDiffuseOffset':
  23559. case 'mapDiffuseWrap':
  23560. case 'mapDiffuseAnisotropy':
  23561. break;
  23562. case 'mapEmissive':
  23563. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  23564. break;
  23565. case 'mapEmissiveRepeat':
  23566. case 'mapEmissiveOffset':
  23567. case 'mapEmissiveWrap':
  23568. case 'mapEmissiveAnisotropy':
  23569. break;
  23570. case 'mapLight':
  23571. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  23572. break;
  23573. case 'mapLightRepeat':
  23574. case 'mapLightOffset':
  23575. case 'mapLightWrap':
  23576. case 'mapLightAnisotropy':
  23577. break;
  23578. case 'mapAO':
  23579. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  23580. break;
  23581. case 'mapAORepeat':
  23582. case 'mapAOOffset':
  23583. case 'mapAOWrap':
  23584. case 'mapAOAnisotropy':
  23585. break;
  23586. case 'mapBump':
  23587. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  23588. break;
  23589. case 'mapBumpScale':
  23590. json.bumpScale = value;
  23591. break;
  23592. case 'mapBumpRepeat':
  23593. case 'mapBumpOffset':
  23594. case 'mapBumpWrap':
  23595. case 'mapBumpAnisotropy':
  23596. break;
  23597. case 'mapNormal':
  23598. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  23599. break;
  23600. case 'mapNormalFactor':
  23601. json.normalScale = value;
  23602. break;
  23603. case 'mapNormalRepeat':
  23604. case 'mapNormalOffset':
  23605. case 'mapNormalWrap':
  23606. case 'mapNormalAnisotropy':
  23607. break;
  23608. case 'mapSpecular':
  23609. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  23610. break;
  23611. case 'mapSpecularRepeat':
  23612. case 'mapSpecularOffset':
  23613. case 'mapSpecularWrap':
  23614. case 'mapSpecularAnisotropy':
  23615. break;
  23616. case 'mapMetalness':
  23617. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  23618. break;
  23619. case 'mapMetalnessRepeat':
  23620. case 'mapMetalnessOffset':
  23621. case 'mapMetalnessWrap':
  23622. case 'mapMetalnessAnisotropy':
  23623. break;
  23624. case 'mapRoughness':
  23625. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  23626. break;
  23627. case 'mapRoughnessRepeat':
  23628. case 'mapRoughnessOffset':
  23629. case 'mapRoughnessWrap':
  23630. case 'mapRoughnessAnisotropy':
  23631. break;
  23632. case 'mapAlpha':
  23633. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  23634. break;
  23635. case 'mapAlphaRepeat':
  23636. case 'mapAlphaOffset':
  23637. case 'mapAlphaWrap':
  23638. case 'mapAlphaAnisotropy':
  23639. break;
  23640. case 'flipSided':
  23641. json.side = BackSide;
  23642. break;
  23643. case 'doubleSided':
  23644. json.side = DoubleSide;
  23645. break;
  23646. case 'transparency':
  23647. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  23648. json.opacity = value;
  23649. break;
  23650. case 'depthTest':
  23651. case 'depthWrite':
  23652. case 'colorWrite':
  23653. case 'opacity':
  23654. case 'reflectivity':
  23655. case 'transparent':
  23656. case 'visible':
  23657. case 'wireframe':
  23658. json[ name ] = value;
  23659. break;
  23660. case 'vertexColors':
  23661. if ( value === true ) json.vertexColors = VertexColors;
  23662. if ( value === 'face' ) json.vertexColors = FaceColors;
  23663. break;
  23664. default:
  23665. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  23666. break;
  23667. }
  23668. }
  23669. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  23670. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  23671. if ( json.opacity < 1 ) json.transparent = true;
  23672. materialLoader.setTextures( textures );
  23673. return materialLoader.parse( json );
  23674. };
  23675. } )()
  23676. } );
  23677. /**
  23678. * @author mrdoob / http://mrdoob.com/
  23679. */
  23680. var context;
  23681. var AudioContext = {
  23682. getContext: function () {
  23683. if ( context === undefined ) {
  23684. context = new ( window.AudioContext || window.webkitAudioContext )();
  23685. }
  23686. return context;
  23687. },
  23688. setContext: function ( value ) {
  23689. context = value;
  23690. }
  23691. };
  23692. /**
  23693. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  23694. */
  23695. function AudioLoader( manager ) {
  23696. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23697. }
  23698. Object.assign( AudioLoader.prototype, {
  23699. load: function ( url, onLoad, onProgress, onError ) {
  23700. var loader = new FileLoader( this.manager );
  23701. loader.setResponseType( 'arraybuffer' );
  23702. loader.setPath( this.path );
  23703. loader.load( url, function ( buffer ) {
  23704. // Create a copy of the buffer. The `decodeAudioData` method
  23705. // detaches the buffer when complete, preventing reuse.
  23706. var bufferCopy = buffer.slice( 0 );
  23707. var context = AudioContext.getContext();
  23708. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  23709. onLoad( audioBuffer );
  23710. } );
  23711. }, onProgress, onError );
  23712. },
  23713. setPath: function ( value ) {
  23714. this.path = value;
  23715. return this;
  23716. }
  23717. } );
  23718. /**
  23719. * @author mrdoob / http://mrdoob.com/
  23720. */
  23721. function StereoCamera() {
  23722. this.type = 'StereoCamera';
  23723. this.aspect = 1;
  23724. this.eyeSep = 0.064;
  23725. this.cameraL = new PerspectiveCamera();
  23726. this.cameraL.layers.enable( 1 );
  23727. this.cameraL.matrixAutoUpdate = false;
  23728. this.cameraR = new PerspectiveCamera();
  23729. this.cameraR.layers.enable( 2 );
  23730. this.cameraR.matrixAutoUpdate = false;
  23731. }
  23732. Object.assign( StereoCamera.prototype, {
  23733. update: ( function () {
  23734. var instance, focus, fov, aspect, near, far, zoom, eyeSep;
  23735. var eyeRight = new Matrix4();
  23736. var eyeLeft = new Matrix4();
  23737. return function update( camera ) {
  23738. var needsUpdate = instance !== this || focus !== camera.focus || fov !== camera.fov ||
  23739. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  23740. far !== camera.far || zoom !== camera.zoom || eyeSep !== this.eyeSep;
  23741. if ( needsUpdate ) {
  23742. instance = this;
  23743. focus = camera.focus;
  23744. fov = camera.fov;
  23745. aspect = camera.aspect * this.aspect;
  23746. near = camera.near;
  23747. far = camera.far;
  23748. zoom = camera.zoom;
  23749. // Off-axis stereoscopic effect based on
  23750. // http://paulbourke.net/stereographics/stereorender/
  23751. var projectionMatrix = camera.projectionMatrix.clone();
  23752. eyeSep = this.eyeSep / 2;
  23753. var eyeSepOnProjection = eyeSep * near / focus;
  23754. var ymax = ( near * Math.tan( _Math.DEG2RAD * fov * 0.5 ) ) / zoom;
  23755. var xmin, xmax;
  23756. // translate xOffset
  23757. eyeLeft.elements[ 12 ] = - eyeSep;
  23758. eyeRight.elements[ 12 ] = eyeSep;
  23759. // for left eye
  23760. xmin = - ymax * aspect + eyeSepOnProjection;
  23761. xmax = ymax * aspect + eyeSepOnProjection;
  23762. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  23763. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  23764. this.cameraL.projectionMatrix.copy( projectionMatrix );
  23765. // for right eye
  23766. xmin = - ymax * aspect - eyeSepOnProjection;
  23767. xmax = ymax * aspect - eyeSepOnProjection;
  23768. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  23769. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  23770. this.cameraR.projectionMatrix.copy( projectionMatrix );
  23771. }
  23772. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  23773. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  23774. };
  23775. } )()
  23776. } );
  23777. /**
  23778. * Camera for rendering cube maps
  23779. * - renders scene into axis-aligned cube
  23780. *
  23781. * @author alteredq / http://alteredqualia.com/
  23782. */
  23783. function CubeCamera( near, far, cubeResolution, options ) {
  23784. Object3D.call( this );
  23785. this.type = 'CubeCamera';
  23786. var fov = 90, aspect = 1;
  23787. var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  23788. cameraPX.up.set( 0, - 1, 0 );
  23789. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  23790. this.add( cameraPX );
  23791. var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  23792. cameraNX.up.set( 0, - 1, 0 );
  23793. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  23794. this.add( cameraNX );
  23795. var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  23796. cameraPY.up.set( 0, 0, 1 );
  23797. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  23798. this.add( cameraPY );
  23799. var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  23800. cameraNY.up.set( 0, 0, - 1 );
  23801. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  23802. this.add( cameraNY );
  23803. var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  23804. cameraPZ.up.set( 0, - 1, 0 );
  23805. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  23806. this.add( cameraPZ );
  23807. var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  23808. cameraNZ.up.set( 0, - 1, 0 );
  23809. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  23810. this.add( cameraNZ );
  23811. options = options || { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
  23812. this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  23813. this.renderTarget.texture.name = "CubeCamera";
  23814. this.update = function ( renderer, scene ) {
  23815. if ( this.parent === null ) this.updateMatrixWorld();
  23816. var currentRenderTarget = renderer.getRenderTarget();
  23817. var renderTarget = this.renderTarget;
  23818. var generateMipmaps = renderTarget.texture.generateMipmaps;
  23819. renderTarget.texture.generateMipmaps = false;
  23820. renderTarget.activeCubeFace = 0;
  23821. renderer.render( scene, cameraPX, renderTarget );
  23822. renderTarget.activeCubeFace = 1;
  23823. renderer.render( scene, cameraNX, renderTarget );
  23824. renderTarget.activeCubeFace = 2;
  23825. renderer.render( scene, cameraPY, renderTarget );
  23826. renderTarget.activeCubeFace = 3;
  23827. renderer.render( scene, cameraNY, renderTarget );
  23828. renderTarget.activeCubeFace = 4;
  23829. renderer.render( scene, cameraPZ, renderTarget );
  23830. renderTarget.texture.generateMipmaps = generateMipmaps;
  23831. renderTarget.activeCubeFace = 5;
  23832. renderer.render( scene, cameraNZ, renderTarget );
  23833. renderer.setRenderTarget( currentRenderTarget );
  23834. };
  23835. this.clear = function ( renderer, color, depth, stencil ) {
  23836. var currentRenderTarget = renderer.getRenderTarget();
  23837. var renderTarget = this.renderTarget;
  23838. for ( var i = 0; i < 6; i ++ ) {
  23839. renderTarget.activeCubeFace = i;
  23840. renderer.setRenderTarget( renderTarget );
  23841. renderer.clear( color, depth, stencil );
  23842. }
  23843. renderer.setRenderTarget( currentRenderTarget );
  23844. };
  23845. }
  23846. CubeCamera.prototype = Object.create( Object3D.prototype );
  23847. CubeCamera.prototype.constructor = CubeCamera;
  23848. /**
  23849. * @author alteredq / http://alteredqualia.com/
  23850. */
  23851. function Clock( autoStart ) {
  23852. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  23853. this.startTime = 0;
  23854. this.oldTime = 0;
  23855. this.elapsedTime = 0;
  23856. this.running = false;
  23857. }
  23858. Object.assign( Clock.prototype, {
  23859. start: function () {
  23860. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  23861. this.oldTime = this.startTime;
  23862. this.elapsedTime = 0;
  23863. this.running = true;
  23864. },
  23865. stop: function () {
  23866. this.getElapsedTime();
  23867. this.running = false;
  23868. this.autoStart = false;
  23869. },
  23870. getElapsedTime: function () {
  23871. this.getDelta();
  23872. return this.elapsedTime;
  23873. },
  23874. getDelta: function () {
  23875. var diff = 0;
  23876. if ( this.autoStart && ! this.running ) {
  23877. this.start();
  23878. return 0;
  23879. }
  23880. if ( this.running ) {
  23881. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  23882. diff = ( newTime - this.oldTime ) / 1000;
  23883. this.oldTime = newTime;
  23884. this.elapsedTime += diff;
  23885. }
  23886. return diff;
  23887. }
  23888. } );
  23889. /**
  23890. * @author mrdoob / http://mrdoob.com/
  23891. */
  23892. function AudioListener() {
  23893. Object3D.call( this );
  23894. this.type = 'AudioListener';
  23895. this.context = AudioContext.getContext();
  23896. this.gain = this.context.createGain();
  23897. this.gain.connect( this.context.destination );
  23898. this.filter = null;
  23899. this.timeDelta = 0;
  23900. }
  23901. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  23902. constructor: AudioListener,
  23903. getInput: function () {
  23904. return this.gain;
  23905. },
  23906. removeFilter: function ( ) {
  23907. if ( this.filter !== null ) {
  23908. this.gain.disconnect( this.filter );
  23909. this.filter.disconnect( this.context.destination );
  23910. this.gain.connect( this.context.destination );
  23911. this.filter = null;
  23912. }
  23913. return this;
  23914. },
  23915. getFilter: function () {
  23916. return this.filter;
  23917. },
  23918. setFilter: function ( value ) {
  23919. if ( this.filter !== null ) {
  23920. this.gain.disconnect( this.filter );
  23921. this.filter.disconnect( this.context.destination );
  23922. } else {
  23923. this.gain.disconnect( this.context.destination );
  23924. }
  23925. this.filter = value;
  23926. this.gain.connect( this.filter );
  23927. this.filter.connect( this.context.destination );
  23928. return this;
  23929. },
  23930. getMasterVolume: function () {
  23931. return this.gain.gain.value;
  23932. },
  23933. setMasterVolume: function ( value ) {
  23934. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  23935. return this;
  23936. },
  23937. updateMatrixWorld: ( function () {
  23938. var position = new Vector3();
  23939. var quaternion = new Quaternion();
  23940. var scale = new Vector3();
  23941. var orientation = new Vector3();
  23942. var clock = new Clock();
  23943. return function updateMatrixWorld( force ) {
  23944. Object3D.prototype.updateMatrixWorld.call( this, force );
  23945. var listener = this.context.listener;
  23946. var up = this.up;
  23947. this.timeDelta = clock.getDelta();
  23948. this.matrixWorld.decompose( position, quaternion, scale );
  23949. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  23950. if ( listener.positionX ) {
  23951. // code path for Chrome (see #14393)
  23952. var endTime = this.context.currentTime + this.timeDelta;
  23953. listener.positionX.linearRampToValueAtTime( position.x, endTime );
  23954. listener.positionY.linearRampToValueAtTime( position.y, endTime );
  23955. listener.positionZ.linearRampToValueAtTime( position.z, endTime );
  23956. listener.forwardX.linearRampToValueAtTime( orientation.x, endTime );
  23957. listener.forwardY.linearRampToValueAtTime( orientation.y, endTime );
  23958. listener.forwardZ.linearRampToValueAtTime( orientation.z, endTime );
  23959. listener.upX.linearRampToValueAtTime( up.x, endTime );
  23960. listener.upY.linearRampToValueAtTime( up.y, endTime );
  23961. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  23962. } else {
  23963. listener.setPosition( position.x, position.y, position.z );
  23964. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  23965. }
  23966. };
  23967. } )()
  23968. } );
  23969. /**
  23970. * @author mrdoob / http://mrdoob.com/
  23971. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  23972. */
  23973. function Audio( listener ) {
  23974. Object3D.call( this );
  23975. this.type = 'Audio';
  23976. this.listener = listener;
  23977. this.context = listener.context;
  23978. this.gain = this.context.createGain();
  23979. this.gain.connect( listener.getInput() );
  23980. this.autoplay = false;
  23981. this.buffer = null;
  23982. this.detune = 0;
  23983. this.loop = false;
  23984. this.startTime = 0;
  23985. this.offset = 0;
  23986. this.playbackRate = 1;
  23987. this.isPlaying = false;
  23988. this.hasPlaybackControl = true;
  23989. this.sourceType = 'empty';
  23990. this.filters = [];
  23991. }
  23992. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  23993. constructor: Audio,
  23994. getOutput: function () {
  23995. return this.gain;
  23996. },
  23997. setNodeSource: function ( audioNode ) {
  23998. this.hasPlaybackControl = false;
  23999. this.sourceType = 'audioNode';
  24000. this.source = audioNode;
  24001. this.connect();
  24002. return this;
  24003. },
  24004. setMediaElementSource: function ( mediaElement ) {
  24005. this.hasPlaybackControl = false;
  24006. this.sourceType = 'mediaNode';
  24007. this.source = this.context.createMediaElementSource( mediaElement );
  24008. this.connect();
  24009. return this;
  24010. },
  24011. setBuffer: function ( audioBuffer ) {
  24012. this.buffer = audioBuffer;
  24013. this.sourceType = 'buffer';
  24014. if ( this.autoplay ) this.play();
  24015. return this;
  24016. },
  24017. play: function () {
  24018. if ( this.isPlaying === true ) {
  24019. console.warn( 'THREE.Audio: Audio is already playing.' );
  24020. return;
  24021. }
  24022. if ( this.hasPlaybackControl === false ) {
  24023. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24024. return;
  24025. }
  24026. var source = this.context.createBufferSource();
  24027. source.buffer = this.buffer;
  24028. source.detune.value = this.detune;
  24029. source.loop = this.loop;
  24030. source.onended = this.onEnded.bind( this );
  24031. source.playbackRate.setValueAtTime( this.playbackRate, this.startTime );
  24032. this.startTime = this.context.currentTime;
  24033. source.start( this.startTime, this.offset );
  24034. this.isPlaying = true;
  24035. this.source = source;
  24036. return this.connect();
  24037. },
  24038. pause: function () {
  24039. if ( this.hasPlaybackControl === false ) {
  24040. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24041. return;
  24042. }
  24043. if ( this.isPlaying === true ) {
  24044. this.source.stop();
  24045. this.source.onended = null;
  24046. this.offset += ( this.context.currentTime - this.startTime ) * this.playbackRate;
  24047. this.isPlaying = false;
  24048. }
  24049. return this;
  24050. },
  24051. stop: function () {
  24052. if ( this.hasPlaybackControl === false ) {
  24053. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24054. return;
  24055. }
  24056. this.source.stop();
  24057. this.source.onended = null;
  24058. this.offset = 0;
  24059. this.isPlaying = false;
  24060. return this;
  24061. },
  24062. connect: function () {
  24063. if ( this.filters.length > 0 ) {
  24064. this.source.connect( this.filters[ 0 ] );
  24065. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  24066. this.filters[ i - 1 ].connect( this.filters[ i ] );
  24067. }
  24068. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  24069. } else {
  24070. this.source.connect( this.getOutput() );
  24071. }
  24072. return this;
  24073. },
  24074. disconnect: function () {
  24075. if ( this.filters.length > 0 ) {
  24076. this.source.disconnect( this.filters[ 0 ] );
  24077. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  24078. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  24079. }
  24080. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  24081. } else {
  24082. this.source.disconnect( this.getOutput() );
  24083. }
  24084. return this;
  24085. },
  24086. getFilters: function () {
  24087. return this.filters;
  24088. },
  24089. setFilters: function ( value ) {
  24090. if ( ! value ) value = [];
  24091. if ( this.isPlaying === true ) {
  24092. this.disconnect();
  24093. this.filters = value;
  24094. this.connect();
  24095. } else {
  24096. this.filters = value;
  24097. }
  24098. return this;
  24099. },
  24100. setDetune: function ( value ) {
  24101. this.detune = value;
  24102. if ( this.isPlaying === true ) {
  24103. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  24104. }
  24105. return this;
  24106. },
  24107. getDetune: function () {
  24108. return this.detune;
  24109. },
  24110. getFilter: function () {
  24111. return this.getFilters()[ 0 ];
  24112. },
  24113. setFilter: function ( filter ) {
  24114. return this.setFilters( filter ? [ filter ] : [] );
  24115. },
  24116. setPlaybackRate: function ( value ) {
  24117. if ( this.hasPlaybackControl === false ) {
  24118. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24119. return;
  24120. }
  24121. this.playbackRate = value;
  24122. if ( this.isPlaying === true ) {
  24123. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  24124. }
  24125. return this;
  24126. },
  24127. getPlaybackRate: function () {
  24128. return this.playbackRate;
  24129. },
  24130. onEnded: function () {
  24131. this.isPlaying = false;
  24132. },
  24133. getLoop: function () {
  24134. if ( this.hasPlaybackControl === false ) {
  24135. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24136. return false;
  24137. }
  24138. return this.loop;
  24139. },
  24140. setLoop: function ( value ) {
  24141. if ( this.hasPlaybackControl === false ) {
  24142. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24143. return;
  24144. }
  24145. this.loop = value;
  24146. if ( this.isPlaying === true ) {
  24147. this.source.loop = this.loop;
  24148. }
  24149. return this;
  24150. },
  24151. getVolume: function () {
  24152. return this.gain.gain.value;
  24153. },
  24154. setVolume: function ( value ) {
  24155. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24156. return this;
  24157. }
  24158. } );
  24159. /**
  24160. * @author mrdoob / http://mrdoob.com/
  24161. */
  24162. function PositionalAudio( listener ) {
  24163. Audio.call( this, listener );
  24164. this.panner = this.context.createPanner();
  24165. this.panner.connect( this.gain );
  24166. }
  24167. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  24168. constructor: PositionalAudio,
  24169. getOutput: function () {
  24170. return this.panner;
  24171. },
  24172. getRefDistance: function () {
  24173. return this.panner.refDistance;
  24174. },
  24175. setRefDistance: function ( value ) {
  24176. this.panner.refDistance = value;
  24177. return this;
  24178. },
  24179. getRolloffFactor: function () {
  24180. return this.panner.rolloffFactor;
  24181. },
  24182. setRolloffFactor: function ( value ) {
  24183. this.panner.rolloffFactor = value;
  24184. return this;
  24185. },
  24186. getDistanceModel: function () {
  24187. return this.panner.distanceModel;
  24188. },
  24189. setDistanceModel: function ( value ) {
  24190. this.panner.distanceModel = value;
  24191. return this;
  24192. },
  24193. getMaxDistance: function () {
  24194. return this.panner.maxDistance;
  24195. },
  24196. setMaxDistance: function ( value ) {
  24197. this.panner.maxDistance = value;
  24198. return this;
  24199. },
  24200. setDirectionalCone: function ( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  24201. this.panner.coneInnerAngle = coneInnerAngle;
  24202. this.panner.coneOuterAngle = coneOuterAngle;
  24203. this.panner.coneOuterGain = coneOuterGain;
  24204. return this;
  24205. },
  24206. updateMatrixWorld: ( function () {
  24207. var position = new Vector3();
  24208. var quaternion = new Quaternion();
  24209. var scale = new Vector3();
  24210. var orientation = new Vector3();
  24211. return function updateMatrixWorld( force ) {
  24212. Object3D.prototype.updateMatrixWorld.call( this, force );
  24213. if ( this.isPlaying === false ) return;
  24214. this.matrixWorld.decompose( position, quaternion, scale );
  24215. orientation.set( 0, 0, 1 ).applyQuaternion( quaternion );
  24216. var panner = this.panner;
  24217. if ( panner.positionX ) {
  24218. // code path for Chrome and Firefox (see #14393)
  24219. var endTime = this.context.currentTime + this.listener.timeDelta;
  24220. panner.positionX.linearRampToValueAtTime( position.x, endTime );
  24221. panner.positionY.linearRampToValueAtTime( position.y, endTime );
  24222. panner.positionZ.linearRampToValueAtTime( position.z, endTime );
  24223. panner.orientationX.linearRampToValueAtTime( orientation.x, endTime );
  24224. panner.orientationY.linearRampToValueAtTime( orientation.y, endTime );
  24225. panner.orientationZ.linearRampToValueAtTime( orientation.z, endTime );
  24226. } else {
  24227. panner.setPosition( position.x, position.y, position.z );
  24228. panner.setOrientation( orientation.x, orientation.y, orientation.z );
  24229. }
  24230. };
  24231. } )()
  24232. } );
  24233. /**
  24234. * @author mrdoob / http://mrdoob.com/
  24235. */
  24236. function AudioAnalyser( audio, fftSize ) {
  24237. this.analyser = audio.context.createAnalyser();
  24238. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  24239. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  24240. audio.getOutput().connect( this.analyser );
  24241. }
  24242. Object.assign( AudioAnalyser.prototype, {
  24243. getFrequencyData: function () {
  24244. this.analyser.getByteFrequencyData( this.data );
  24245. return this.data;
  24246. },
  24247. getAverageFrequency: function () {
  24248. var value = 0, data = this.getFrequencyData();
  24249. for ( var i = 0; i < data.length; i ++ ) {
  24250. value += data[ i ];
  24251. }
  24252. return value / data.length;
  24253. }
  24254. } );
  24255. /**
  24256. *
  24257. * Buffered scene graph property that allows weighted accumulation.
  24258. *
  24259. *
  24260. * @author Ben Houston / http://clara.io/
  24261. * @author David Sarno / http://lighthaus.us/
  24262. * @author tschw
  24263. */
  24264. function PropertyMixer( binding, typeName, valueSize ) {
  24265. this.binding = binding;
  24266. this.valueSize = valueSize;
  24267. var bufferType = Float64Array,
  24268. mixFunction;
  24269. switch ( typeName ) {
  24270. case 'quaternion':
  24271. mixFunction = this._slerp;
  24272. break;
  24273. case 'string':
  24274. case 'bool':
  24275. bufferType = Array;
  24276. mixFunction = this._select;
  24277. break;
  24278. default:
  24279. mixFunction = this._lerp;
  24280. }
  24281. this.buffer = new bufferType( valueSize * 4 );
  24282. // layout: [ incoming | accu0 | accu1 | orig ]
  24283. //
  24284. // interpolators can use .buffer as their .result
  24285. // the data then goes to 'incoming'
  24286. //
  24287. // 'accu0' and 'accu1' are used frame-interleaved for
  24288. // the cumulative result and are compared to detect
  24289. // changes
  24290. //
  24291. // 'orig' stores the original state of the property
  24292. this._mixBufferRegion = mixFunction;
  24293. this.cumulativeWeight = 0;
  24294. this.useCount = 0;
  24295. this.referenceCount = 0;
  24296. }
  24297. Object.assign( PropertyMixer.prototype, {
  24298. // accumulate data in the 'incoming' region into 'accu<i>'
  24299. accumulate: function ( accuIndex, weight ) {
  24300. // note: happily accumulating nothing when weight = 0, the caller knows
  24301. // the weight and shouldn't have made the call in the first place
  24302. var buffer = this.buffer,
  24303. stride = this.valueSize,
  24304. offset = accuIndex * stride + stride,
  24305. currentWeight = this.cumulativeWeight;
  24306. if ( currentWeight === 0 ) {
  24307. // accuN := incoming * weight
  24308. for ( var i = 0; i !== stride; ++ i ) {
  24309. buffer[ offset + i ] = buffer[ i ];
  24310. }
  24311. currentWeight = weight;
  24312. } else {
  24313. // accuN := accuN + incoming * weight
  24314. currentWeight += weight;
  24315. var mix = weight / currentWeight;
  24316. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  24317. }
  24318. this.cumulativeWeight = currentWeight;
  24319. },
  24320. // apply the state of 'accu<i>' to the binding when accus differ
  24321. apply: function ( accuIndex ) {
  24322. var stride = this.valueSize,
  24323. buffer = this.buffer,
  24324. offset = accuIndex * stride + stride,
  24325. weight = this.cumulativeWeight,
  24326. binding = this.binding;
  24327. this.cumulativeWeight = 0;
  24328. if ( weight < 1 ) {
  24329. // accuN := accuN + original * ( 1 - cumulativeWeight )
  24330. var originalValueOffset = stride * 3;
  24331. this._mixBufferRegion(
  24332. buffer, offset, originalValueOffset, 1 - weight, stride );
  24333. }
  24334. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  24335. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  24336. // value has changed -> update scene graph
  24337. binding.setValue( buffer, offset );
  24338. break;
  24339. }
  24340. }
  24341. },
  24342. // remember the state of the bound property and copy it to both accus
  24343. saveOriginalState: function () {
  24344. var binding = this.binding;
  24345. var buffer = this.buffer,
  24346. stride = this.valueSize,
  24347. originalValueOffset = stride * 3;
  24348. binding.getValue( buffer, originalValueOffset );
  24349. // accu[0..1] := orig -- initially detect changes against the original
  24350. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  24351. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  24352. }
  24353. this.cumulativeWeight = 0;
  24354. },
  24355. // apply the state previously taken via 'saveOriginalState' to the binding
  24356. restoreOriginalState: function () {
  24357. var originalValueOffset = this.valueSize * 3;
  24358. this.binding.setValue( this.buffer, originalValueOffset );
  24359. },
  24360. // mix functions
  24361. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  24362. if ( t >= 0.5 ) {
  24363. for ( var i = 0; i !== stride; ++ i ) {
  24364. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  24365. }
  24366. }
  24367. },
  24368. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  24369. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  24370. },
  24371. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  24372. var s = 1 - t;
  24373. for ( var i = 0; i !== stride; ++ i ) {
  24374. var j = dstOffset + i;
  24375. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  24376. }
  24377. }
  24378. } );
  24379. /**
  24380. *
  24381. * A reference to a real property in the scene graph.
  24382. *
  24383. *
  24384. * @author Ben Houston / http://clara.io/
  24385. * @author David Sarno / http://lighthaus.us/
  24386. * @author tschw
  24387. */
  24388. // Characters [].:/ are reserved for track binding syntax.
  24389. var RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  24390. function Composite( targetGroup, path, optionalParsedPath ) {
  24391. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  24392. this._targetGroup = targetGroup;
  24393. this._bindings = targetGroup.subscribe_( path, parsedPath );
  24394. }
  24395. Object.assign( Composite.prototype, {
  24396. getValue: function ( array, offset ) {
  24397. this.bind(); // bind all binding
  24398. var firstValidIndex = this._targetGroup.nCachedObjects_,
  24399. binding = this._bindings[ firstValidIndex ];
  24400. // and only call .getValue on the first
  24401. if ( binding !== undefined ) binding.getValue( array, offset );
  24402. },
  24403. setValue: function ( array, offset ) {
  24404. var bindings = this._bindings;
  24405. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24406. bindings[ i ].setValue( array, offset );
  24407. }
  24408. },
  24409. bind: function () {
  24410. var bindings = this._bindings;
  24411. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24412. bindings[ i ].bind();
  24413. }
  24414. },
  24415. unbind: function () {
  24416. var bindings = this._bindings;
  24417. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24418. bindings[ i ].unbind();
  24419. }
  24420. }
  24421. } );
  24422. function PropertyBinding( rootNode, path, parsedPath ) {
  24423. this.path = path;
  24424. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  24425. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  24426. this.rootNode = rootNode;
  24427. }
  24428. Object.assign( PropertyBinding, {
  24429. Composite: Composite,
  24430. create: function ( root, path, parsedPath ) {
  24431. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  24432. return new PropertyBinding( root, path, parsedPath );
  24433. } else {
  24434. return new PropertyBinding.Composite( root, path, parsedPath );
  24435. }
  24436. },
  24437. /**
  24438. * Replaces spaces with underscores and removes unsupported characters from
  24439. * node names, to ensure compatibility with parseTrackName().
  24440. *
  24441. * @param {string} name Node name to be sanitized.
  24442. * @return {string}
  24443. */
  24444. sanitizeNodeName: ( function () {
  24445. var reservedRe = new RegExp( '[' + RESERVED_CHARS_RE + ']', 'g' );
  24446. return function sanitizeNodeName( name ) {
  24447. return name.replace( /\s/g, '_' ).replace( reservedRe, '' );
  24448. };
  24449. }() ),
  24450. parseTrackName: function () {
  24451. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  24452. // only latin characters, and the unicode \p{L} is not yet supported. So
  24453. // instead, we exclude reserved characters and match everything else.
  24454. var wordChar = '[^' + RESERVED_CHARS_RE + ']';
  24455. var wordCharOrDot = '[^' + RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  24456. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  24457. // be matched to parse the rest of the track name.
  24458. var directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', wordChar );
  24459. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  24460. var nodeRe = /(WCOD+)?/.source.replace( 'WCOD', wordCharOrDot );
  24461. // Object on target node, and accessor. May not contain reserved
  24462. // characters. Accessor may contain any character except closing bracket.
  24463. var objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', wordChar );
  24464. // Property and accessor. May not contain reserved characters. Accessor may
  24465. // contain any non-bracket characters.
  24466. var propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', wordChar );
  24467. var trackRe = new RegExp( ''
  24468. + '^'
  24469. + directoryRe
  24470. + nodeRe
  24471. + objectRe
  24472. + propertyRe
  24473. + '$'
  24474. );
  24475. var supportedObjectNames = [ 'material', 'materials', 'bones' ];
  24476. return function parseTrackName( trackName ) {
  24477. var matches = trackRe.exec( trackName );
  24478. if ( ! matches ) {
  24479. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  24480. }
  24481. var results = {
  24482. // directoryName: matches[ 1 ], // (tschw) currently unused
  24483. nodeName: matches[ 2 ],
  24484. objectName: matches[ 3 ],
  24485. objectIndex: matches[ 4 ],
  24486. propertyName: matches[ 5 ], // required
  24487. propertyIndex: matches[ 6 ]
  24488. };
  24489. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  24490. if ( lastDot !== undefined && lastDot !== - 1 ) {
  24491. var objectName = results.nodeName.substring( lastDot + 1 );
  24492. // Object names must be checked against a whitelist. Otherwise, there
  24493. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  24494. // 'bar' could be the objectName, or part of a nodeName (which can
  24495. // include '.' characters).
  24496. if ( supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  24497. results.nodeName = results.nodeName.substring( 0, lastDot );
  24498. results.objectName = objectName;
  24499. }
  24500. }
  24501. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  24502. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  24503. }
  24504. return results;
  24505. };
  24506. }(),
  24507. findNode: function ( root, nodeName ) {
  24508. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  24509. return root;
  24510. }
  24511. // search into skeleton bones.
  24512. if ( root.skeleton ) {
  24513. var bone = root.skeleton.getBoneByName( nodeName );
  24514. if ( bone !== undefined ) {
  24515. return bone;
  24516. }
  24517. }
  24518. // search into node subtree.
  24519. if ( root.children ) {
  24520. var searchNodeSubtree = function ( children ) {
  24521. for ( var i = 0; i < children.length; i ++ ) {
  24522. var childNode = children[ i ];
  24523. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  24524. return childNode;
  24525. }
  24526. var result = searchNodeSubtree( childNode.children );
  24527. if ( result ) return result;
  24528. }
  24529. return null;
  24530. };
  24531. var subTreeNode = searchNodeSubtree( root.children );
  24532. if ( subTreeNode ) {
  24533. return subTreeNode;
  24534. }
  24535. }
  24536. return null;
  24537. }
  24538. } );
  24539. Object.assign( PropertyBinding.prototype, { // prototype, continued
  24540. // these are used to "bind" a nonexistent property
  24541. _getValue_unavailable: function () {},
  24542. _setValue_unavailable: function () {},
  24543. BindingType: {
  24544. Direct: 0,
  24545. EntireArray: 1,
  24546. ArrayElement: 2,
  24547. HasFromToArray: 3
  24548. },
  24549. Versioning: {
  24550. None: 0,
  24551. NeedsUpdate: 1,
  24552. MatrixWorldNeedsUpdate: 2
  24553. },
  24554. GetterByBindingType: [
  24555. function getValue_direct( buffer, offset ) {
  24556. buffer[ offset ] = this.node[ this.propertyName ];
  24557. },
  24558. function getValue_array( buffer, offset ) {
  24559. var source = this.resolvedProperty;
  24560. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  24561. buffer[ offset ++ ] = source[ i ];
  24562. }
  24563. },
  24564. function getValue_arrayElement( buffer, offset ) {
  24565. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  24566. },
  24567. function getValue_toArray( buffer, offset ) {
  24568. this.resolvedProperty.toArray( buffer, offset );
  24569. }
  24570. ],
  24571. SetterByBindingTypeAndVersioning: [
  24572. [
  24573. // Direct
  24574. function setValue_direct( buffer, offset ) {
  24575. this.targetObject[ this.propertyName ] = buffer[ offset ];
  24576. },
  24577. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  24578. this.targetObject[ this.propertyName ] = buffer[ offset ];
  24579. this.targetObject.needsUpdate = true;
  24580. },
  24581. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  24582. this.targetObject[ this.propertyName ] = buffer[ offset ];
  24583. this.targetObject.matrixWorldNeedsUpdate = true;
  24584. }
  24585. ], [
  24586. // EntireArray
  24587. function setValue_array( buffer, offset ) {
  24588. var dest = this.resolvedProperty;
  24589. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  24590. dest[ i ] = buffer[ offset ++ ];
  24591. }
  24592. },
  24593. function setValue_array_setNeedsUpdate( buffer, offset ) {
  24594. var dest = this.resolvedProperty;
  24595. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  24596. dest[ i ] = buffer[ offset ++ ];
  24597. }
  24598. this.targetObject.needsUpdate = true;
  24599. },
  24600. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  24601. var dest = this.resolvedProperty;
  24602. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  24603. dest[ i ] = buffer[ offset ++ ];
  24604. }
  24605. this.targetObject.matrixWorldNeedsUpdate = true;
  24606. }
  24607. ], [
  24608. // ArrayElement
  24609. function setValue_arrayElement( buffer, offset ) {
  24610. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  24611. },
  24612. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  24613. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  24614. this.targetObject.needsUpdate = true;
  24615. },
  24616. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  24617. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  24618. this.targetObject.matrixWorldNeedsUpdate = true;
  24619. }
  24620. ], [
  24621. // HasToFromArray
  24622. function setValue_fromArray( buffer, offset ) {
  24623. this.resolvedProperty.fromArray( buffer, offset );
  24624. },
  24625. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  24626. this.resolvedProperty.fromArray( buffer, offset );
  24627. this.targetObject.needsUpdate = true;
  24628. },
  24629. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  24630. this.resolvedProperty.fromArray( buffer, offset );
  24631. this.targetObject.matrixWorldNeedsUpdate = true;
  24632. }
  24633. ]
  24634. ],
  24635. getValue: function getValue_unbound( targetArray, offset ) {
  24636. this.bind();
  24637. this.getValue( targetArray, offset );
  24638. // Note: This class uses a State pattern on a per-method basis:
  24639. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  24640. // prototype version of these methods with one that represents
  24641. // the bound state. When the property is not found, the methods
  24642. // become no-ops.
  24643. },
  24644. setValue: function getValue_unbound( sourceArray, offset ) {
  24645. this.bind();
  24646. this.setValue( sourceArray, offset );
  24647. },
  24648. // create getter / setter pair for a property in the scene graph
  24649. bind: function () {
  24650. var targetObject = this.node,
  24651. parsedPath = this.parsedPath,
  24652. objectName = parsedPath.objectName,
  24653. propertyName = parsedPath.propertyName,
  24654. propertyIndex = parsedPath.propertyIndex;
  24655. if ( ! targetObject ) {
  24656. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  24657. this.node = targetObject;
  24658. }
  24659. // set fail state so we can just 'return' on error
  24660. this.getValue = this._getValue_unavailable;
  24661. this.setValue = this._setValue_unavailable;
  24662. // ensure there is a value node
  24663. if ( ! targetObject ) {
  24664. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  24665. return;
  24666. }
  24667. if ( objectName ) {
  24668. var objectIndex = parsedPath.objectIndex;
  24669. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  24670. switch ( objectName ) {
  24671. case 'materials':
  24672. if ( ! targetObject.material ) {
  24673. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  24674. return;
  24675. }
  24676. if ( ! targetObject.material.materials ) {
  24677. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  24678. return;
  24679. }
  24680. targetObject = targetObject.material.materials;
  24681. break;
  24682. case 'bones':
  24683. if ( ! targetObject.skeleton ) {
  24684. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  24685. return;
  24686. }
  24687. // potential future optimization: skip this if propertyIndex is already an integer
  24688. // and convert the integer string to a true integer.
  24689. targetObject = targetObject.skeleton.bones;
  24690. // support resolving morphTarget names into indices.
  24691. for ( var i = 0; i < targetObject.length; i ++ ) {
  24692. if ( targetObject[ i ].name === objectIndex ) {
  24693. objectIndex = i;
  24694. break;
  24695. }
  24696. }
  24697. break;
  24698. default:
  24699. if ( targetObject[ objectName ] === undefined ) {
  24700. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  24701. return;
  24702. }
  24703. targetObject = targetObject[ objectName ];
  24704. }
  24705. if ( objectIndex !== undefined ) {
  24706. if ( targetObject[ objectIndex ] === undefined ) {
  24707. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  24708. return;
  24709. }
  24710. targetObject = targetObject[ objectIndex ];
  24711. }
  24712. }
  24713. // resolve property
  24714. var nodeProperty = targetObject[ propertyName ];
  24715. if ( nodeProperty === undefined ) {
  24716. var nodeName = parsedPath.nodeName;
  24717. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  24718. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  24719. return;
  24720. }
  24721. // determine versioning scheme
  24722. var versioning = this.Versioning.None;
  24723. this.targetObject = targetObject;
  24724. if ( targetObject.needsUpdate !== undefined ) { // material
  24725. versioning = this.Versioning.NeedsUpdate;
  24726. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  24727. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  24728. }
  24729. // determine how the property gets bound
  24730. var bindingType = this.BindingType.Direct;
  24731. if ( propertyIndex !== undefined ) {
  24732. // access a sub element of the property array (only primitives are supported right now)
  24733. if ( propertyName === "morphTargetInfluences" ) {
  24734. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  24735. // support resolving morphTarget names into indices.
  24736. if ( ! targetObject.geometry ) {
  24737. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  24738. return;
  24739. }
  24740. if ( targetObject.geometry.isBufferGeometry ) {
  24741. if ( ! targetObject.geometry.morphAttributes ) {
  24742. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  24743. return;
  24744. }
  24745. for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {
  24746. if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {
  24747. propertyIndex = i;
  24748. break;
  24749. }
  24750. }
  24751. } else {
  24752. if ( ! targetObject.geometry.morphTargets ) {
  24753. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.', this );
  24754. return;
  24755. }
  24756. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  24757. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  24758. propertyIndex = i;
  24759. break;
  24760. }
  24761. }
  24762. }
  24763. }
  24764. bindingType = this.BindingType.ArrayElement;
  24765. this.resolvedProperty = nodeProperty;
  24766. this.propertyIndex = propertyIndex;
  24767. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  24768. // must use copy for Object3D.Euler/Quaternion
  24769. bindingType = this.BindingType.HasFromToArray;
  24770. this.resolvedProperty = nodeProperty;
  24771. } else if ( Array.isArray( nodeProperty ) ) {
  24772. bindingType = this.BindingType.EntireArray;
  24773. this.resolvedProperty = nodeProperty;
  24774. } else {
  24775. this.propertyName = propertyName;
  24776. }
  24777. // select getter / setter
  24778. this.getValue = this.GetterByBindingType[ bindingType ];
  24779. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  24780. },
  24781. unbind: function () {
  24782. this.node = null;
  24783. // back to the prototype version of getValue / setValue
  24784. // note: avoiding to mutate the shape of 'this' via 'delete'
  24785. this.getValue = this._getValue_unbound;
  24786. this.setValue = this._setValue_unbound;
  24787. }
  24788. } );
  24789. //!\ DECLARE ALIAS AFTER assign prototype !
  24790. Object.assign( PropertyBinding.prototype, {
  24791. // initial state of these methods that calls 'bind'
  24792. _getValue_unbound: PropertyBinding.prototype.getValue,
  24793. _setValue_unbound: PropertyBinding.prototype.setValue,
  24794. } );
  24795. /**
  24796. *
  24797. * A group of objects that receives a shared animation state.
  24798. *
  24799. * Usage:
  24800. *
  24801. * - Add objects you would otherwise pass as 'root' to the
  24802. * constructor or the .clipAction method of AnimationMixer.
  24803. *
  24804. * - Instead pass this object as 'root'.
  24805. *
  24806. * - You can also add and remove objects later when the mixer
  24807. * is running.
  24808. *
  24809. * Note:
  24810. *
  24811. * Objects of this class appear as one object to the mixer,
  24812. * so cache control of the individual objects must be done
  24813. * on the group.
  24814. *
  24815. * Limitation:
  24816. *
  24817. * - The animated properties must be compatible among the
  24818. * all objects in the group.
  24819. *
  24820. * - A single property can either be controlled through a
  24821. * target group or directly, but not both.
  24822. *
  24823. * @author tschw
  24824. */
  24825. function AnimationObjectGroup() {
  24826. this.uuid = _Math.generateUUID();
  24827. // cached objects followed by the active ones
  24828. this._objects = Array.prototype.slice.call( arguments );
  24829. this.nCachedObjects_ = 0; // threshold
  24830. // note: read by PropertyBinding.Composite
  24831. var indices = {};
  24832. this._indicesByUUID = indices; // for bookkeeping
  24833. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  24834. indices[ arguments[ i ].uuid ] = i;
  24835. }
  24836. this._paths = []; // inside: string
  24837. this._parsedPaths = []; // inside: { we don't care, here }
  24838. this._bindings = []; // inside: Array< PropertyBinding >
  24839. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  24840. var scope = this;
  24841. this.stats = {
  24842. objects: {
  24843. get total() {
  24844. return scope._objects.length;
  24845. },
  24846. get inUse() {
  24847. return this.total - scope.nCachedObjects_;
  24848. }
  24849. },
  24850. get bindingsPerObject() {
  24851. return scope._bindings.length;
  24852. }
  24853. };
  24854. }
  24855. Object.assign( AnimationObjectGroup.prototype, {
  24856. isAnimationObjectGroup: true,
  24857. add: function () {
  24858. var objects = this._objects,
  24859. nObjects = objects.length,
  24860. nCachedObjects = this.nCachedObjects_,
  24861. indicesByUUID = this._indicesByUUID,
  24862. paths = this._paths,
  24863. parsedPaths = this._parsedPaths,
  24864. bindings = this._bindings,
  24865. nBindings = bindings.length,
  24866. knownObject = undefined;
  24867. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  24868. var object = arguments[ i ],
  24869. uuid = object.uuid,
  24870. index = indicesByUUID[ uuid ];
  24871. if ( index === undefined ) {
  24872. // unknown object -> add it to the ACTIVE region
  24873. index = nObjects ++;
  24874. indicesByUUID[ uuid ] = index;
  24875. objects.push( object );
  24876. // accounting is done, now do the same for all bindings
  24877. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  24878. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  24879. }
  24880. } else if ( index < nCachedObjects ) {
  24881. knownObject = objects[ index ];
  24882. // move existing object to the ACTIVE region
  24883. var firstActiveIndex = -- nCachedObjects,
  24884. lastCachedObject = objects[ firstActiveIndex ];
  24885. indicesByUUID[ lastCachedObject.uuid ] = index;
  24886. objects[ index ] = lastCachedObject;
  24887. indicesByUUID[ uuid ] = firstActiveIndex;
  24888. objects[ firstActiveIndex ] = object;
  24889. // accounting is done, now do the same for all bindings
  24890. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  24891. var bindingsForPath = bindings[ j ],
  24892. lastCached = bindingsForPath[ firstActiveIndex ],
  24893. binding = bindingsForPath[ index ];
  24894. bindingsForPath[ index ] = lastCached;
  24895. if ( binding === undefined ) {
  24896. // since we do not bother to create new bindings
  24897. // for objects that are cached, the binding may
  24898. // or may not exist
  24899. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  24900. }
  24901. bindingsForPath[ firstActiveIndex ] = binding;
  24902. }
  24903. } else if ( objects[ index ] !== knownObject ) {
  24904. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  24905. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  24906. } // else the object is already where we want it to be
  24907. } // for arguments
  24908. this.nCachedObjects_ = nCachedObjects;
  24909. },
  24910. remove: function () {
  24911. var objects = this._objects,
  24912. nCachedObjects = this.nCachedObjects_,
  24913. indicesByUUID = this._indicesByUUID,
  24914. bindings = this._bindings,
  24915. nBindings = bindings.length;
  24916. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  24917. var object = arguments[ i ],
  24918. uuid = object.uuid,
  24919. index = indicesByUUID[ uuid ];
  24920. if ( index !== undefined && index >= nCachedObjects ) {
  24921. // move existing object into the CACHED region
  24922. var lastCachedIndex = nCachedObjects ++,
  24923. firstActiveObject = objects[ lastCachedIndex ];
  24924. indicesByUUID[ firstActiveObject.uuid ] = index;
  24925. objects[ index ] = firstActiveObject;
  24926. indicesByUUID[ uuid ] = lastCachedIndex;
  24927. objects[ lastCachedIndex ] = object;
  24928. // accounting is done, now do the same for all bindings
  24929. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  24930. var bindingsForPath = bindings[ j ],
  24931. firstActive = bindingsForPath[ lastCachedIndex ],
  24932. binding = bindingsForPath[ index ];
  24933. bindingsForPath[ index ] = firstActive;
  24934. bindingsForPath[ lastCachedIndex ] = binding;
  24935. }
  24936. }
  24937. } // for arguments
  24938. this.nCachedObjects_ = nCachedObjects;
  24939. },
  24940. // remove & forget
  24941. uncache: function () {
  24942. var objects = this._objects,
  24943. nObjects = objects.length,
  24944. nCachedObjects = this.nCachedObjects_,
  24945. indicesByUUID = this._indicesByUUID,
  24946. bindings = this._bindings,
  24947. nBindings = bindings.length;
  24948. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  24949. var object = arguments[ i ],
  24950. uuid = object.uuid,
  24951. index = indicesByUUID[ uuid ];
  24952. if ( index !== undefined ) {
  24953. delete indicesByUUID[ uuid ];
  24954. if ( index < nCachedObjects ) {
  24955. // object is cached, shrink the CACHED region
  24956. var firstActiveIndex = -- nCachedObjects,
  24957. lastCachedObject = objects[ firstActiveIndex ],
  24958. lastIndex = -- nObjects,
  24959. lastObject = objects[ lastIndex ];
  24960. // last cached object takes this object's place
  24961. indicesByUUID[ lastCachedObject.uuid ] = index;
  24962. objects[ index ] = lastCachedObject;
  24963. // last object goes to the activated slot and pop
  24964. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  24965. objects[ firstActiveIndex ] = lastObject;
  24966. objects.pop();
  24967. // accounting is done, now do the same for all bindings
  24968. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  24969. var bindingsForPath = bindings[ j ],
  24970. lastCached = bindingsForPath[ firstActiveIndex ],
  24971. last = bindingsForPath[ lastIndex ];
  24972. bindingsForPath[ index ] = lastCached;
  24973. bindingsForPath[ firstActiveIndex ] = last;
  24974. bindingsForPath.pop();
  24975. }
  24976. } else {
  24977. // object is active, just swap with the last and pop
  24978. var lastIndex = -- nObjects,
  24979. lastObject = objects[ lastIndex ];
  24980. indicesByUUID[ lastObject.uuid ] = index;
  24981. objects[ index ] = lastObject;
  24982. objects.pop();
  24983. // accounting is done, now do the same for all bindings
  24984. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  24985. var bindingsForPath = bindings[ j ];
  24986. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  24987. bindingsForPath.pop();
  24988. }
  24989. } // cached or active
  24990. } // if object is known
  24991. } // for arguments
  24992. this.nCachedObjects_ = nCachedObjects;
  24993. },
  24994. // Internal interface used by befriended PropertyBinding.Composite:
  24995. subscribe_: function ( path, parsedPath ) {
  24996. // returns an array of bindings for the given path that is changed
  24997. // according to the contained objects in the group
  24998. var indicesByPath = this._bindingsIndicesByPath,
  24999. index = indicesByPath[ path ],
  25000. bindings = this._bindings;
  25001. if ( index !== undefined ) return bindings[ index ];
  25002. var paths = this._paths,
  25003. parsedPaths = this._parsedPaths,
  25004. objects = this._objects,
  25005. nObjects = objects.length,
  25006. nCachedObjects = this.nCachedObjects_,
  25007. bindingsForPath = new Array( nObjects );
  25008. index = bindings.length;
  25009. indicesByPath[ path ] = index;
  25010. paths.push( path );
  25011. parsedPaths.push( parsedPath );
  25012. bindings.push( bindingsForPath );
  25013. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  25014. var object = objects[ i ];
  25015. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  25016. }
  25017. return bindingsForPath;
  25018. },
  25019. unsubscribe_: function ( path ) {
  25020. // tells the group to forget about a property path and no longer
  25021. // update the array previously obtained with 'subscribe_'
  25022. var indicesByPath = this._bindingsIndicesByPath,
  25023. index = indicesByPath[ path ];
  25024. if ( index !== undefined ) {
  25025. var paths = this._paths,
  25026. parsedPaths = this._parsedPaths,
  25027. bindings = this._bindings,
  25028. lastBindingsIndex = bindings.length - 1,
  25029. lastBindings = bindings[ lastBindingsIndex ],
  25030. lastBindingsPath = path[ lastBindingsIndex ];
  25031. indicesByPath[ lastBindingsPath ] = index;
  25032. bindings[ index ] = lastBindings;
  25033. bindings.pop();
  25034. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  25035. parsedPaths.pop();
  25036. paths[ index ] = paths[ lastBindingsIndex ];
  25037. paths.pop();
  25038. }
  25039. }
  25040. } );
  25041. /**
  25042. *
  25043. * Action provided by AnimationMixer for scheduling clip playback on specific
  25044. * objects.
  25045. *
  25046. * @author Ben Houston / http://clara.io/
  25047. * @author David Sarno / http://lighthaus.us/
  25048. * @author tschw
  25049. *
  25050. */
  25051. function AnimationAction( mixer, clip, localRoot ) {
  25052. this._mixer = mixer;
  25053. this._clip = clip;
  25054. this._localRoot = localRoot || null;
  25055. var tracks = clip.tracks,
  25056. nTracks = tracks.length,
  25057. interpolants = new Array( nTracks );
  25058. var interpolantSettings = {
  25059. endingStart: ZeroCurvatureEnding,
  25060. endingEnd: ZeroCurvatureEnding
  25061. };
  25062. for ( var i = 0; i !== nTracks; ++ i ) {
  25063. var interpolant = tracks[ i ].createInterpolant( null );
  25064. interpolants[ i ] = interpolant;
  25065. interpolant.settings = interpolantSettings;
  25066. }
  25067. this._interpolantSettings = interpolantSettings;
  25068. this._interpolants = interpolants; // bound by the mixer
  25069. // inside: PropertyMixer (managed by the mixer)
  25070. this._propertyBindings = new Array( nTracks );
  25071. this._cacheIndex = null; // for the memory manager
  25072. this._byClipCacheIndex = null; // for the memory manager
  25073. this._timeScaleInterpolant = null;
  25074. this._weightInterpolant = null;
  25075. this.loop = LoopRepeat;
  25076. this._loopCount = - 1;
  25077. // global mixer time when the action is to be started
  25078. // it's set back to 'null' upon start of the action
  25079. this._startTime = null;
  25080. // scaled local time of the action
  25081. // gets clamped or wrapped to 0..clip.duration according to loop
  25082. this.time = 0;
  25083. this.timeScale = 1;
  25084. this._effectiveTimeScale = 1;
  25085. this.weight = 1;
  25086. this._effectiveWeight = 1;
  25087. this.repetitions = Infinity; // no. of repetitions when looping
  25088. this.paused = false; // true -> zero effective time scale
  25089. this.enabled = true; // false -> zero effective weight
  25090. this.clampWhenFinished = false;// keep feeding the last frame?
  25091. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  25092. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  25093. }
  25094. Object.assign( AnimationAction.prototype, {
  25095. // State & Scheduling
  25096. play: function () {
  25097. this._mixer._activateAction( this );
  25098. return this;
  25099. },
  25100. stop: function () {
  25101. this._mixer._deactivateAction( this );
  25102. return this.reset();
  25103. },
  25104. reset: function () {
  25105. this.paused = false;
  25106. this.enabled = true;
  25107. this.time = 0; // restart clip
  25108. this._loopCount = - 1;// forget previous loops
  25109. this._startTime = null;// forget scheduling
  25110. return this.stopFading().stopWarping();
  25111. },
  25112. isRunning: function () {
  25113. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  25114. this._startTime === null && this._mixer._isActiveAction( this );
  25115. },
  25116. // return true when play has been called
  25117. isScheduled: function () {
  25118. return this._mixer._isActiveAction( this );
  25119. },
  25120. startAt: function ( time ) {
  25121. this._startTime = time;
  25122. return this;
  25123. },
  25124. setLoop: function ( mode, repetitions ) {
  25125. this.loop = mode;
  25126. this.repetitions = repetitions;
  25127. return this;
  25128. },
  25129. // Weight
  25130. // set the weight stopping any scheduled fading
  25131. // although .enabled = false yields an effective weight of zero, this
  25132. // method does *not* change .enabled, because it would be confusing
  25133. setEffectiveWeight: function ( weight ) {
  25134. this.weight = weight;
  25135. // note: same logic as when updated at runtime
  25136. this._effectiveWeight = this.enabled ? weight : 0;
  25137. return this.stopFading();
  25138. },
  25139. // return the weight considering fading and .enabled
  25140. getEffectiveWeight: function () {
  25141. return this._effectiveWeight;
  25142. },
  25143. fadeIn: function ( duration ) {
  25144. return this._scheduleFading( duration, 0, 1 );
  25145. },
  25146. fadeOut: function ( duration ) {
  25147. return this._scheduleFading( duration, 1, 0 );
  25148. },
  25149. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  25150. fadeOutAction.fadeOut( duration );
  25151. this.fadeIn( duration );
  25152. if ( warp ) {
  25153. var fadeInDuration = this._clip.duration,
  25154. fadeOutDuration = fadeOutAction._clip.duration,
  25155. startEndRatio = fadeOutDuration / fadeInDuration,
  25156. endStartRatio = fadeInDuration / fadeOutDuration;
  25157. fadeOutAction.warp( 1.0, startEndRatio, duration );
  25158. this.warp( endStartRatio, 1.0, duration );
  25159. }
  25160. return this;
  25161. },
  25162. crossFadeTo: function ( fadeInAction, duration, warp ) {
  25163. return fadeInAction.crossFadeFrom( this, duration, warp );
  25164. },
  25165. stopFading: function () {
  25166. var weightInterpolant = this._weightInterpolant;
  25167. if ( weightInterpolant !== null ) {
  25168. this._weightInterpolant = null;
  25169. this._mixer._takeBackControlInterpolant( weightInterpolant );
  25170. }
  25171. return this;
  25172. },
  25173. // Time Scale Control
  25174. // set the time scale stopping any scheduled warping
  25175. // although .paused = true yields an effective time scale of zero, this
  25176. // method does *not* change .paused, because it would be confusing
  25177. setEffectiveTimeScale: function ( timeScale ) {
  25178. this.timeScale = timeScale;
  25179. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  25180. return this.stopWarping();
  25181. },
  25182. // return the time scale considering warping and .paused
  25183. getEffectiveTimeScale: function () {
  25184. return this._effectiveTimeScale;
  25185. },
  25186. setDuration: function ( duration ) {
  25187. this.timeScale = this._clip.duration / duration;
  25188. return this.stopWarping();
  25189. },
  25190. syncWith: function ( action ) {
  25191. this.time = action.time;
  25192. this.timeScale = action.timeScale;
  25193. return this.stopWarping();
  25194. },
  25195. halt: function ( duration ) {
  25196. return this.warp( this._effectiveTimeScale, 0, duration );
  25197. },
  25198. warp: function ( startTimeScale, endTimeScale, duration ) {
  25199. var mixer = this._mixer, now = mixer.time,
  25200. interpolant = this._timeScaleInterpolant,
  25201. timeScale = this.timeScale;
  25202. if ( interpolant === null ) {
  25203. interpolant = mixer._lendControlInterpolant();
  25204. this._timeScaleInterpolant = interpolant;
  25205. }
  25206. var times = interpolant.parameterPositions,
  25207. values = interpolant.sampleValues;
  25208. times[ 0 ] = now;
  25209. times[ 1 ] = now + duration;
  25210. values[ 0 ] = startTimeScale / timeScale;
  25211. values[ 1 ] = endTimeScale / timeScale;
  25212. return this;
  25213. },
  25214. stopWarping: function () {
  25215. var timeScaleInterpolant = this._timeScaleInterpolant;
  25216. if ( timeScaleInterpolant !== null ) {
  25217. this._timeScaleInterpolant = null;
  25218. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  25219. }
  25220. return this;
  25221. },
  25222. // Object Accessors
  25223. getMixer: function () {
  25224. return this._mixer;
  25225. },
  25226. getClip: function () {
  25227. return this._clip;
  25228. },
  25229. getRoot: function () {
  25230. return this._localRoot || this._mixer._root;
  25231. },
  25232. // Interna
  25233. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  25234. // called by the mixer
  25235. if ( ! this.enabled ) {
  25236. // call ._updateWeight() to update ._effectiveWeight
  25237. this._updateWeight( time );
  25238. return;
  25239. }
  25240. var startTime = this._startTime;
  25241. if ( startTime !== null ) {
  25242. // check for scheduled start of action
  25243. var timeRunning = ( time - startTime ) * timeDirection;
  25244. if ( timeRunning < 0 || timeDirection === 0 ) {
  25245. return; // yet to come / don't decide when delta = 0
  25246. }
  25247. // start
  25248. this._startTime = null; // unschedule
  25249. deltaTime = timeDirection * timeRunning;
  25250. }
  25251. // apply time scale and advance time
  25252. deltaTime *= this._updateTimeScale( time );
  25253. var clipTime = this._updateTime( deltaTime );
  25254. // note: _updateTime may disable the action resulting in
  25255. // an effective weight of 0
  25256. var weight = this._updateWeight( time );
  25257. if ( weight > 0 ) {
  25258. var interpolants = this._interpolants;
  25259. var propertyMixers = this._propertyBindings;
  25260. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  25261. interpolants[ j ].evaluate( clipTime );
  25262. propertyMixers[ j ].accumulate( accuIndex, weight );
  25263. }
  25264. }
  25265. },
  25266. _updateWeight: function ( time ) {
  25267. var weight = 0;
  25268. if ( this.enabled ) {
  25269. weight = this.weight;
  25270. var interpolant = this._weightInterpolant;
  25271. if ( interpolant !== null ) {
  25272. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  25273. weight *= interpolantValue;
  25274. if ( time > interpolant.parameterPositions[ 1 ] ) {
  25275. this.stopFading();
  25276. if ( interpolantValue === 0 ) {
  25277. // faded out, disable
  25278. this.enabled = false;
  25279. }
  25280. }
  25281. }
  25282. }
  25283. this._effectiveWeight = weight;
  25284. return weight;
  25285. },
  25286. _updateTimeScale: function ( time ) {
  25287. var timeScale = 0;
  25288. if ( ! this.paused ) {
  25289. timeScale = this.timeScale;
  25290. var interpolant = this._timeScaleInterpolant;
  25291. if ( interpolant !== null ) {
  25292. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  25293. timeScale *= interpolantValue;
  25294. if ( time > interpolant.parameterPositions[ 1 ] ) {
  25295. this.stopWarping();
  25296. if ( timeScale === 0 ) {
  25297. // motion has halted, pause
  25298. this.paused = true;
  25299. } else {
  25300. // warp done - apply final time scale
  25301. this.timeScale = timeScale;
  25302. }
  25303. }
  25304. }
  25305. }
  25306. this._effectiveTimeScale = timeScale;
  25307. return timeScale;
  25308. },
  25309. _updateTime: function ( deltaTime ) {
  25310. var time = this.time + deltaTime;
  25311. var duration = this._clip.duration;
  25312. var loop = this.loop;
  25313. var loopCount = this._loopCount;
  25314. var pingPong = ( loop === LoopPingPong );
  25315. if ( deltaTime === 0 ) {
  25316. if ( loopCount === - 1 ) return time;
  25317. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  25318. }
  25319. if ( loop === LoopOnce ) {
  25320. if ( loopCount === - 1 ) {
  25321. // just started
  25322. this._loopCount = 0;
  25323. this._setEndings( true, true, false );
  25324. }
  25325. handle_stop: {
  25326. if ( time >= duration ) {
  25327. time = duration;
  25328. } else if ( time < 0 ) {
  25329. time = 0;
  25330. } else break handle_stop;
  25331. if ( this.clampWhenFinished ) this.paused = true;
  25332. else this.enabled = false;
  25333. this._mixer.dispatchEvent( {
  25334. type: 'finished', action: this,
  25335. direction: deltaTime < 0 ? - 1 : 1
  25336. } );
  25337. }
  25338. } else { // repetitive Repeat or PingPong
  25339. if ( loopCount === - 1 ) {
  25340. // just started
  25341. if ( deltaTime >= 0 ) {
  25342. loopCount = 0;
  25343. this._setEndings( true, this.repetitions === 0, pingPong );
  25344. } else {
  25345. // when looping in reverse direction, the initial
  25346. // transition through zero counts as a repetition,
  25347. // so leave loopCount at -1
  25348. this._setEndings( this.repetitions === 0, true, pingPong );
  25349. }
  25350. }
  25351. if ( time >= duration || time < 0 ) {
  25352. // wrap around
  25353. var loopDelta = Math.floor( time / duration ); // signed
  25354. time -= duration * loopDelta;
  25355. loopCount += Math.abs( loopDelta );
  25356. var pending = this.repetitions - loopCount;
  25357. if ( pending <= 0 ) {
  25358. // have to stop (switch state, clamp time, fire event)
  25359. if ( this.clampWhenFinished ) this.paused = true;
  25360. else this.enabled = false;
  25361. time = deltaTime > 0 ? duration : 0;
  25362. this._mixer.dispatchEvent( {
  25363. type: 'finished', action: this,
  25364. direction: deltaTime > 0 ? 1 : - 1
  25365. } );
  25366. } else {
  25367. // keep running
  25368. if ( pending === 1 ) {
  25369. // entering the last round
  25370. var atStart = deltaTime < 0;
  25371. this._setEndings( atStart, ! atStart, pingPong );
  25372. } else {
  25373. this._setEndings( false, false, pingPong );
  25374. }
  25375. this._loopCount = loopCount;
  25376. this._mixer.dispatchEvent( {
  25377. type: 'loop', action: this, loopDelta: loopDelta
  25378. } );
  25379. }
  25380. }
  25381. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  25382. // invert time for the "pong round"
  25383. this.time = time;
  25384. return duration - time;
  25385. }
  25386. }
  25387. this.time = time;
  25388. return time;
  25389. },
  25390. _setEndings: function ( atStart, atEnd, pingPong ) {
  25391. var settings = this._interpolantSettings;
  25392. if ( pingPong ) {
  25393. settings.endingStart = ZeroSlopeEnding;
  25394. settings.endingEnd = ZeroSlopeEnding;
  25395. } else {
  25396. // assuming for LoopOnce atStart == atEnd == true
  25397. if ( atStart ) {
  25398. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  25399. } else {
  25400. settings.endingStart = WrapAroundEnding;
  25401. }
  25402. if ( atEnd ) {
  25403. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  25404. } else {
  25405. settings.endingEnd = WrapAroundEnding;
  25406. }
  25407. }
  25408. },
  25409. _scheduleFading: function ( duration, weightNow, weightThen ) {
  25410. var mixer = this._mixer, now = mixer.time,
  25411. interpolant = this._weightInterpolant;
  25412. if ( interpolant === null ) {
  25413. interpolant = mixer._lendControlInterpolant();
  25414. this._weightInterpolant = interpolant;
  25415. }
  25416. var times = interpolant.parameterPositions,
  25417. values = interpolant.sampleValues;
  25418. times[ 0 ] = now;
  25419. values[ 0 ] = weightNow;
  25420. times[ 1 ] = now + duration;
  25421. values[ 1 ] = weightThen;
  25422. return this;
  25423. }
  25424. } );
  25425. /**
  25426. *
  25427. * Player for AnimationClips.
  25428. *
  25429. *
  25430. * @author Ben Houston / http://clara.io/
  25431. * @author David Sarno / http://lighthaus.us/
  25432. * @author tschw
  25433. */
  25434. function AnimationMixer( root ) {
  25435. this._root = root;
  25436. this._initMemoryManager();
  25437. this._accuIndex = 0;
  25438. this.time = 0;
  25439. this.timeScale = 1.0;
  25440. }
  25441. AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  25442. constructor: AnimationMixer,
  25443. _bindAction: function ( action, prototypeAction ) {
  25444. var root = action._localRoot || this._root,
  25445. tracks = action._clip.tracks,
  25446. nTracks = tracks.length,
  25447. bindings = action._propertyBindings,
  25448. interpolants = action._interpolants,
  25449. rootUuid = root.uuid,
  25450. bindingsByRoot = this._bindingsByRootAndName,
  25451. bindingsByName = bindingsByRoot[ rootUuid ];
  25452. if ( bindingsByName === undefined ) {
  25453. bindingsByName = {};
  25454. bindingsByRoot[ rootUuid ] = bindingsByName;
  25455. }
  25456. for ( var i = 0; i !== nTracks; ++ i ) {
  25457. var track = tracks[ i ],
  25458. trackName = track.name,
  25459. binding = bindingsByName[ trackName ];
  25460. if ( binding !== undefined ) {
  25461. bindings[ i ] = binding;
  25462. } else {
  25463. binding = bindings[ i ];
  25464. if ( binding !== undefined ) {
  25465. // existing binding, make sure the cache knows
  25466. if ( binding._cacheIndex === null ) {
  25467. ++ binding.referenceCount;
  25468. this._addInactiveBinding( binding, rootUuid, trackName );
  25469. }
  25470. continue;
  25471. }
  25472. var path = prototypeAction && prototypeAction.
  25473. _propertyBindings[ i ].binding.parsedPath;
  25474. binding = new PropertyMixer(
  25475. PropertyBinding.create( root, trackName, path ),
  25476. track.ValueTypeName, track.getValueSize() );
  25477. ++ binding.referenceCount;
  25478. this._addInactiveBinding( binding, rootUuid, trackName );
  25479. bindings[ i ] = binding;
  25480. }
  25481. interpolants[ i ].resultBuffer = binding.buffer;
  25482. }
  25483. },
  25484. _activateAction: function ( action ) {
  25485. if ( ! this._isActiveAction( action ) ) {
  25486. if ( action._cacheIndex === null ) {
  25487. // this action has been forgotten by the cache, but the user
  25488. // appears to be still using it -> rebind
  25489. var rootUuid = ( action._localRoot || this._root ).uuid,
  25490. clipUuid = action._clip.uuid,
  25491. actionsForClip = this._actionsByClip[ clipUuid ];
  25492. this._bindAction( action,
  25493. actionsForClip && actionsForClip.knownActions[ 0 ] );
  25494. this._addInactiveAction( action, clipUuid, rootUuid );
  25495. }
  25496. var bindings = action._propertyBindings;
  25497. // increment reference counts / sort out state
  25498. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  25499. var binding = bindings[ i ];
  25500. if ( binding.useCount ++ === 0 ) {
  25501. this._lendBinding( binding );
  25502. binding.saveOriginalState();
  25503. }
  25504. }
  25505. this._lendAction( action );
  25506. }
  25507. },
  25508. _deactivateAction: function ( action ) {
  25509. if ( this._isActiveAction( action ) ) {
  25510. var bindings = action._propertyBindings;
  25511. // decrement reference counts / sort out state
  25512. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  25513. var binding = bindings[ i ];
  25514. if ( -- binding.useCount === 0 ) {
  25515. binding.restoreOriginalState();
  25516. this._takeBackBinding( binding );
  25517. }
  25518. }
  25519. this._takeBackAction( action );
  25520. }
  25521. },
  25522. // Memory manager
  25523. _initMemoryManager: function () {
  25524. this._actions = []; // 'nActiveActions' followed by inactive ones
  25525. this._nActiveActions = 0;
  25526. this._actionsByClip = {};
  25527. // inside:
  25528. // {
  25529. // knownActions: Array< AnimationAction > - used as prototypes
  25530. // actionByRoot: AnimationAction - lookup
  25531. // }
  25532. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  25533. this._nActiveBindings = 0;
  25534. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  25535. this._controlInterpolants = []; // same game as above
  25536. this._nActiveControlInterpolants = 0;
  25537. var scope = this;
  25538. this.stats = {
  25539. actions: {
  25540. get total() {
  25541. return scope._actions.length;
  25542. },
  25543. get inUse() {
  25544. return scope._nActiveActions;
  25545. }
  25546. },
  25547. bindings: {
  25548. get total() {
  25549. return scope._bindings.length;
  25550. },
  25551. get inUse() {
  25552. return scope._nActiveBindings;
  25553. }
  25554. },
  25555. controlInterpolants: {
  25556. get total() {
  25557. return scope._controlInterpolants.length;
  25558. },
  25559. get inUse() {
  25560. return scope._nActiveControlInterpolants;
  25561. }
  25562. }
  25563. };
  25564. },
  25565. // Memory management for AnimationAction objects
  25566. _isActiveAction: function ( action ) {
  25567. var index = action._cacheIndex;
  25568. return index !== null && index < this._nActiveActions;
  25569. },
  25570. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  25571. var actions = this._actions,
  25572. actionsByClip = this._actionsByClip,
  25573. actionsForClip = actionsByClip[ clipUuid ];
  25574. if ( actionsForClip === undefined ) {
  25575. actionsForClip = {
  25576. knownActions: [ action ],
  25577. actionByRoot: {}
  25578. };
  25579. action._byClipCacheIndex = 0;
  25580. actionsByClip[ clipUuid ] = actionsForClip;
  25581. } else {
  25582. var knownActions = actionsForClip.knownActions;
  25583. action._byClipCacheIndex = knownActions.length;
  25584. knownActions.push( action );
  25585. }
  25586. action._cacheIndex = actions.length;
  25587. actions.push( action );
  25588. actionsForClip.actionByRoot[ rootUuid ] = action;
  25589. },
  25590. _removeInactiveAction: function ( action ) {
  25591. var actions = this._actions,
  25592. lastInactiveAction = actions[ actions.length - 1 ],
  25593. cacheIndex = action._cacheIndex;
  25594. lastInactiveAction._cacheIndex = cacheIndex;
  25595. actions[ cacheIndex ] = lastInactiveAction;
  25596. actions.pop();
  25597. action._cacheIndex = null;
  25598. var clipUuid = action._clip.uuid,
  25599. actionsByClip = this._actionsByClip,
  25600. actionsForClip = actionsByClip[ clipUuid ],
  25601. knownActionsForClip = actionsForClip.knownActions,
  25602. lastKnownAction =
  25603. knownActionsForClip[ knownActionsForClip.length - 1 ],
  25604. byClipCacheIndex = action._byClipCacheIndex;
  25605. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  25606. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  25607. knownActionsForClip.pop();
  25608. action._byClipCacheIndex = null;
  25609. var actionByRoot = actionsForClip.actionByRoot,
  25610. rootUuid = ( action._localRoot || this._root ).uuid;
  25611. delete actionByRoot[ rootUuid ];
  25612. if ( knownActionsForClip.length === 0 ) {
  25613. delete actionsByClip[ clipUuid ];
  25614. }
  25615. this._removeInactiveBindingsForAction( action );
  25616. },
  25617. _removeInactiveBindingsForAction: function ( action ) {
  25618. var bindings = action._propertyBindings;
  25619. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  25620. var binding = bindings[ i ];
  25621. if ( -- binding.referenceCount === 0 ) {
  25622. this._removeInactiveBinding( binding );
  25623. }
  25624. }
  25625. },
  25626. _lendAction: function ( action ) {
  25627. // [ active actions | inactive actions ]
  25628. // [ active actions >| inactive actions ]
  25629. // s a
  25630. // <-swap->
  25631. // a s
  25632. var actions = this._actions,
  25633. prevIndex = action._cacheIndex,
  25634. lastActiveIndex = this._nActiveActions ++,
  25635. firstInactiveAction = actions[ lastActiveIndex ];
  25636. action._cacheIndex = lastActiveIndex;
  25637. actions[ lastActiveIndex ] = action;
  25638. firstInactiveAction._cacheIndex = prevIndex;
  25639. actions[ prevIndex ] = firstInactiveAction;
  25640. },
  25641. _takeBackAction: function ( action ) {
  25642. // [ active actions | inactive actions ]
  25643. // [ active actions |< inactive actions ]
  25644. // a s
  25645. // <-swap->
  25646. // s a
  25647. var actions = this._actions,
  25648. prevIndex = action._cacheIndex,
  25649. firstInactiveIndex = -- this._nActiveActions,
  25650. lastActiveAction = actions[ firstInactiveIndex ];
  25651. action._cacheIndex = firstInactiveIndex;
  25652. actions[ firstInactiveIndex ] = action;
  25653. lastActiveAction._cacheIndex = prevIndex;
  25654. actions[ prevIndex ] = lastActiveAction;
  25655. },
  25656. // Memory management for PropertyMixer objects
  25657. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  25658. var bindingsByRoot = this._bindingsByRootAndName,
  25659. bindingByName = bindingsByRoot[ rootUuid ],
  25660. bindings = this._bindings;
  25661. if ( bindingByName === undefined ) {
  25662. bindingByName = {};
  25663. bindingsByRoot[ rootUuid ] = bindingByName;
  25664. }
  25665. bindingByName[ trackName ] = binding;
  25666. binding._cacheIndex = bindings.length;
  25667. bindings.push( binding );
  25668. },
  25669. _removeInactiveBinding: function ( binding ) {
  25670. var bindings = this._bindings,
  25671. propBinding = binding.binding,
  25672. rootUuid = propBinding.rootNode.uuid,
  25673. trackName = propBinding.path,
  25674. bindingsByRoot = this._bindingsByRootAndName,
  25675. bindingByName = bindingsByRoot[ rootUuid ],
  25676. lastInactiveBinding = bindings[ bindings.length - 1 ],
  25677. cacheIndex = binding._cacheIndex;
  25678. lastInactiveBinding._cacheIndex = cacheIndex;
  25679. bindings[ cacheIndex ] = lastInactiveBinding;
  25680. bindings.pop();
  25681. delete bindingByName[ trackName ];
  25682. remove_empty_map: {
  25683. for ( var _ in bindingByName ) break remove_empty_map; // eslint-disable-line no-unused-vars
  25684. delete bindingsByRoot[ rootUuid ];
  25685. }
  25686. },
  25687. _lendBinding: function ( binding ) {
  25688. var bindings = this._bindings,
  25689. prevIndex = binding._cacheIndex,
  25690. lastActiveIndex = this._nActiveBindings ++,
  25691. firstInactiveBinding = bindings[ lastActiveIndex ];
  25692. binding._cacheIndex = lastActiveIndex;
  25693. bindings[ lastActiveIndex ] = binding;
  25694. firstInactiveBinding._cacheIndex = prevIndex;
  25695. bindings[ prevIndex ] = firstInactiveBinding;
  25696. },
  25697. _takeBackBinding: function ( binding ) {
  25698. var bindings = this._bindings,
  25699. prevIndex = binding._cacheIndex,
  25700. firstInactiveIndex = -- this._nActiveBindings,
  25701. lastActiveBinding = bindings[ firstInactiveIndex ];
  25702. binding._cacheIndex = firstInactiveIndex;
  25703. bindings[ firstInactiveIndex ] = binding;
  25704. lastActiveBinding._cacheIndex = prevIndex;
  25705. bindings[ prevIndex ] = lastActiveBinding;
  25706. },
  25707. // Memory management of Interpolants for weight and time scale
  25708. _lendControlInterpolant: function () {
  25709. var interpolants = this._controlInterpolants,
  25710. lastActiveIndex = this._nActiveControlInterpolants ++,
  25711. interpolant = interpolants[ lastActiveIndex ];
  25712. if ( interpolant === undefined ) {
  25713. interpolant = new LinearInterpolant(
  25714. new Float32Array( 2 ), new Float32Array( 2 ),
  25715. 1, this._controlInterpolantsResultBuffer );
  25716. interpolant.__cacheIndex = lastActiveIndex;
  25717. interpolants[ lastActiveIndex ] = interpolant;
  25718. }
  25719. return interpolant;
  25720. },
  25721. _takeBackControlInterpolant: function ( interpolant ) {
  25722. var interpolants = this._controlInterpolants,
  25723. prevIndex = interpolant.__cacheIndex,
  25724. firstInactiveIndex = -- this._nActiveControlInterpolants,
  25725. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  25726. interpolant.__cacheIndex = firstInactiveIndex;
  25727. interpolants[ firstInactiveIndex ] = interpolant;
  25728. lastActiveInterpolant.__cacheIndex = prevIndex;
  25729. interpolants[ prevIndex ] = lastActiveInterpolant;
  25730. },
  25731. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  25732. // return an action for a clip optionally using a custom root target
  25733. // object (this method allocates a lot of dynamic memory in case a
  25734. // previously unknown clip/root combination is specified)
  25735. clipAction: function ( clip, optionalRoot ) {
  25736. var root = optionalRoot || this._root,
  25737. rootUuid = root.uuid,
  25738. clipObject = typeof clip === 'string' ?
  25739. AnimationClip.findByName( root, clip ) : clip,
  25740. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  25741. actionsForClip = this._actionsByClip[ clipUuid ],
  25742. prototypeAction = null;
  25743. if ( actionsForClip !== undefined ) {
  25744. var existingAction =
  25745. actionsForClip.actionByRoot[ rootUuid ];
  25746. if ( existingAction !== undefined ) {
  25747. return existingAction;
  25748. }
  25749. // we know the clip, so we don't have to parse all
  25750. // the bindings again but can just copy
  25751. prototypeAction = actionsForClip.knownActions[ 0 ];
  25752. // also, take the clip from the prototype action
  25753. if ( clipObject === null )
  25754. clipObject = prototypeAction._clip;
  25755. }
  25756. // clip must be known when specified via string
  25757. if ( clipObject === null ) return null;
  25758. // allocate all resources required to run it
  25759. var newAction = new AnimationAction( this, clipObject, optionalRoot );
  25760. this._bindAction( newAction, prototypeAction );
  25761. // and make the action known to the memory manager
  25762. this._addInactiveAction( newAction, clipUuid, rootUuid );
  25763. return newAction;
  25764. },
  25765. // get an existing action
  25766. existingAction: function ( clip, optionalRoot ) {
  25767. var root = optionalRoot || this._root,
  25768. rootUuid = root.uuid,
  25769. clipObject = typeof clip === 'string' ?
  25770. AnimationClip.findByName( root, clip ) : clip,
  25771. clipUuid = clipObject ? clipObject.uuid : clip,
  25772. actionsForClip = this._actionsByClip[ clipUuid ];
  25773. if ( actionsForClip !== undefined ) {
  25774. return actionsForClip.actionByRoot[ rootUuid ] || null;
  25775. }
  25776. return null;
  25777. },
  25778. // deactivates all previously scheduled actions
  25779. stopAllAction: function () {
  25780. var actions = this._actions,
  25781. nActions = this._nActiveActions,
  25782. bindings = this._bindings,
  25783. nBindings = this._nActiveBindings;
  25784. this._nActiveActions = 0;
  25785. this._nActiveBindings = 0;
  25786. for ( var i = 0; i !== nActions; ++ i ) {
  25787. actions[ i ].reset();
  25788. }
  25789. for ( var i = 0; i !== nBindings; ++ i ) {
  25790. bindings[ i ].useCount = 0;
  25791. }
  25792. return this;
  25793. },
  25794. // advance the time and update apply the animation
  25795. update: function ( deltaTime ) {
  25796. deltaTime *= this.timeScale;
  25797. var actions = this._actions,
  25798. nActions = this._nActiveActions,
  25799. time = this.time += deltaTime,
  25800. timeDirection = Math.sign( deltaTime ),
  25801. accuIndex = this._accuIndex ^= 1;
  25802. // run active actions
  25803. for ( var i = 0; i !== nActions; ++ i ) {
  25804. var action = actions[ i ];
  25805. action._update( time, deltaTime, timeDirection, accuIndex );
  25806. }
  25807. // update scene graph
  25808. var bindings = this._bindings,
  25809. nBindings = this._nActiveBindings;
  25810. for ( var i = 0; i !== nBindings; ++ i ) {
  25811. bindings[ i ].apply( accuIndex );
  25812. }
  25813. return this;
  25814. },
  25815. // return this mixer's root target object
  25816. getRoot: function () {
  25817. return this._root;
  25818. },
  25819. // free all resources specific to a particular clip
  25820. uncacheClip: function ( clip ) {
  25821. var actions = this._actions,
  25822. clipUuid = clip.uuid,
  25823. actionsByClip = this._actionsByClip,
  25824. actionsForClip = actionsByClip[ clipUuid ];
  25825. if ( actionsForClip !== undefined ) {
  25826. // note: just calling _removeInactiveAction would mess up the
  25827. // iteration state and also require updating the state we can
  25828. // just throw away
  25829. var actionsToRemove = actionsForClip.knownActions;
  25830. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  25831. var action = actionsToRemove[ i ];
  25832. this._deactivateAction( action );
  25833. var cacheIndex = action._cacheIndex,
  25834. lastInactiveAction = actions[ actions.length - 1 ];
  25835. action._cacheIndex = null;
  25836. action._byClipCacheIndex = null;
  25837. lastInactiveAction._cacheIndex = cacheIndex;
  25838. actions[ cacheIndex ] = lastInactiveAction;
  25839. actions.pop();
  25840. this._removeInactiveBindingsForAction( action );
  25841. }
  25842. delete actionsByClip[ clipUuid ];
  25843. }
  25844. },
  25845. // free all resources specific to a particular root target object
  25846. uncacheRoot: function ( root ) {
  25847. var rootUuid = root.uuid,
  25848. actionsByClip = this._actionsByClip;
  25849. for ( var clipUuid in actionsByClip ) {
  25850. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  25851. action = actionByRoot[ rootUuid ];
  25852. if ( action !== undefined ) {
  25853. this._deactivateAction( action );
  25854. this._removeInactiveAction( action );
  25855. }
  25856. }
  25857. var bindingsByRoot = this._bindingsByRootAndName,
  25858. bindingByName = bindingsByRoot[ rootUuid ];
  25859. if ( bindingByName !== undefined ) {
  25860. for ( var trackName in bindingByName ) {
  25861. var binding = bindingByName[ trackName ];
  25862. binding.restoreOriginalState();
  25863. this._removeInactiveBinding( binding );
  25864. }
  25865. }
  25866. },
  25867. // remove a targeted clip from the cache
  25868. uncacheAction: function ( clip, optionalRoot ) {
  25869. var action = this.existingAction( clip, optionalRoot );
  25870. if ( action !== null ) {
  25871. this._deactivateAction( action );
  25872. this._removeInactiveAction( action );
  25873. }
  25874. }
  25875. } );
  25876. /**
  25877. * @author mrdoob / http://mrdoob.com/
  25878. */
  25879. function Uniform( value ) {
  25880. if ( typeof value === 'string' ) {
  25881. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  25882. value = arguments[ 1 ];
  25883. }
  25884. this.value = value;
  25885. }
  25886. Uniform.prototype.clone = function () {
  25887. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  25888. };
  25889. /**
  25890. * @author benaadams / https://twitter.com/ben_a_adams
  25891. */
  25892. function InstancedBufferGeometry() {
  25893. BufferGeometry.call( this );
  25894. this.type = 'InstancedBufferGeometry';
  25895. this.maxInstancedCount = undefined;
  25896. }
  25897. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  25898. constructor: InstancedBufferGeometry,
  25899. isInstancedBufferGeometry: true,
  25900. copy: function ( source ) {
  25901. BufferGeometry.prototype.copy.call( this, source );
  25902. this.maxInstancedCount = source.maxInstancedCount;
  25903. return this;
  25904. },
  25905. clone: function () {
  25906. return new this.constructor().copy( this );
  25907. }
  25908. } );
  25909. /**
  25910. * @author benaadams / https://twitter.com/ben_a_adams
  25911. */
  25912. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  25913. InterleavedBuffer.call( this, array, stride );
  25914. this.meshPerAttribute = meshPerAttribute || 1;
  25915. }
  25916. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  25917. constructor: InstancedInterleavedBuffer,
  25918. isInstancedInterleavedBuffer: true,
  25919. copy: function ( source ) {
  25920. InterleavedBuffer.prototype.copy.call( this, source );
  25921. this.meshPerAttribute = source.meshPerAttribute;
  25922. return this;
  25923. }
  25924. } );
  25925. /**
  25926. * @author benaadams / https://twitter.com/ben_a_adams
  25927. */
  25928. function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) {
  25929. if ( typeof ( normalized ) === 'number' ) {
  25930. meshPerAttribute = normalized;
  25931. normalized = false;
  25932. console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' );
  25933. }
  25934. BufferAttribute.call( this, array, itemSize, normalized );
  25935. this.meshPerAttribute = meshPerAttribute || 1;
  25936. }
  25937. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  25938. constructor: InstancedBufferAttribute,
  25939. isInstancedBufferAttribute: true,
  25940. copy: function ( source ) {
  25941. BufferAttribute.prototype.copy.call( this, source );
  25942. this.meshPerAttribute = source.meshPerAttribute;
  25943. return this;
  25944. }
  25945. } );
  25946. /**
  25947. * @author mrdoob / http://mrdoob.com/
  25948. * @author bhouston / http://clara.io/
  25949. * @author stephomi / http://stephaneginier.com/
  25950. */
  25951. function Raycaster( origin, direction, near, far ) {
  25952. this.ray = new Ray( origin, direction );
  25953. // direction is assumed to be normalized (for accurate distance calculations)
  25954. this.near = near || 0;
  25955. this.far = far || Infinity;
  25956. this.params = {
  25957. Mesh: {},
  25958. Line: {},
  25959. LOD: {},
  25960. Points: { threshold: 1 },
  25961. Sprite: {}
  25962. };
  25963. Object.defineProperties( this.params, {
  25964. PointCloud: {
  25965. get: function () {
  25966. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  25967. return this.Points;
  25968. }
  25969. }
  25970. } );
  25971. }
  25972. function ascSort( a, b ) {
  25973. return a.distance - b.distance;
  25974. }
  25975. function intersectObject( object, raycaster, intersects, recursive ) {
  25976. if ( object.visible === false ) return;
  25977. object.raycast( raycaster, intersects );
  25978. if ( recursive === true ) {
  25979. var children = object.children;
  25980. for ( var i = 0, l = children.length; i < l; i ++ ) {
  25981. intersectObject( children[ i ], raycaster, intersects, true );
  25982. }
  25983. }
  25984. }
  25985. Object.assign( Raycaster.prototype, {
  25986. linePrecision: 1,
  25987. set: function ( origin, direction ) {
  25988. // direction is assumed to be normalized (for accurate distance calculations)
  25989. this.ray.set( origin, direction );
  25990. },
  25991. setFromCamera: function ( coords, camera ) {
  25992. if ( ( camera && camera.isPerspectiveCamera ) ) {
  25993. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  25994. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  25995. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  25996. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  25997. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  25998. } else {
  25999. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  26000. }
  26001. },
  26002. intersectObject: function ( object, recursive, optionalTarget ) {
  26003. var intersects = optionalTarget || [];
  26004. intersectObject( object, this, intersects, recursive );
  26005. intersects.sort( ascSort );
  26006. return intersects;
  26007. },
  26008. intersectObjects: function ( objects, recursive, optionalTarget ) {
  26009. var intersects = optionalTarget || [];
  26010. if ( Array.isArray( objects ) === false ) {
  26011. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  26012. return intersects;
  26013. }
  26014. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  26015. intersectObject( objects[ i ], this, intersects, recursive );
  26016. }
  26017. intersects.sort( ascSort );
  26018. return intersects;
  26019. }
  26020. } );
  26021. /**
  26022. * @author bhouston / http://clara.io
  26023. * @author WestLangley / http://github.com/WestLangley
  26024. *
  26025. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  26026. *
  26027. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  26028. * The azimuthal angle (theta) is measured from the positive z-axiz.
  26029. */
  26030. function Spherical( radius, phi, theta ) {
  26031. this.radius = ( radius !== undefined ) ? radius : 1.0;
  26032. this.phi = ( phi !== undefined ) ? phi : 0; // polar angle
  26033. this.theta = ( theta !== undefined ) ? theta : 0; // azimuthal angle
  26034. return this;
  26035. }
  26036. Object.assign( Spherical.prototype, {
  26037. set: function ( radius, phi, theta ) {
  26038. this.radius = radius;
  26039. this.phi = phi;
  26040. this.theta = theta;
  26041. return this;
  26042. },
  26043. clone: function () {
  26044. return new this.constructor().copy( this );
  26045. },
  26046. copy: function ( other ) {
  26047. this.radius = other.radius;
  26048. this.phi = other.phi;
  26049. this.theta = other.theta;
  26050. return this;
  26051. },
  26052. // restrict phi to be betwee EPS and PI-EPS
  26053. makeSafe: function () {
  26054. var EPS = 0.000001;
  26055. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  26056. return this;
  26057. },
  26058. setFromVector3: function ( v ) {
  26059. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26060. },
  26061. setFromCartesianCoords: function ( x, y, z ) {
  26062. this.radius = Math.sqrt( x * x + y * y + z * z );
  26063. if ( this.radius === 0 ) {
  26064. this.theta = 0;
  26065. this.phi = 0;
  26066. } else {
  26067. this.theta = Math.atan2( x, z );
  26068. this.phi = Math.acos( _Math.clamp( y / this.radius, - 1, 1 ) );
  26069. }
  26070. return this;
  26071. }
  26072. } );
  26073. /**
  26074. * @author Mugen87 / https://github.com/Mugen87
  26075. *
  26076. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  26077. *
  26078. */
  26079. function Cylindrical( radius, theta, y ) {
  26080. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  26081. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  26082. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  26083. return this;
  26084. }
  26085. Object.assign( Cylindrical.prototype, {
  26086. set: function ( radius, theta, y ) {
  26087. this.radius = radius;
  26088. this.theta = theta;
  26089. this.y = y;
  26090. return this;
  26091. },
  26092. clone: function () {
  26093. return new this.constructor().copy( this );
  26094. },
  26095. copy: function ( other ) {
  26096. this.radius = other.radius;
  26097. this.theta = other.theta;
  26098. this.y = other.y;
  26099. return this;
  26100. },
  26101. setFromVector3: function ( v ) {
  26102. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26103. },
  26104. setFromCartesianCoords: function ( x, y, z ) {
  26105. this.radius = Math.sqrt( x * x + z * z );
  26106. this.theta = Math.atan2( x, z );
  26107. this.y = y;
  26108. return this;
  26109. }
  26110. } );
  26111. /**
  26112. * @author bhouston / http://clara.io
  26113. */
  26114. function Box2( min, max ) {
  26115. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  26116. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  26117. }
  26118. Object.assign( Box2.prototype, {
  26119. set: function ( min, max ) {
  26120. this.min.copy( min );
  26121. this.max.copy( max );
  26122. return this;
  26123. },
  26124. setFromPoints: function ( points ) {
  26125. this.makeEmpty();
  26126. for ( var i = 0, il = points.length; i < il; i ++ ) {
  26127. this.expandByPoint( points[ i ] );
  26128. }
  26129. return this;
  26130. },
  26131. setFromCenterAndSize: function () {
  26132. var v1 = new Vector2();
  26133. return function setFromCenterAndSize( center, size ) {
  26134. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  26135. this.min.copy( center ).sub( halfSize );
  26136. this.max.copy( center ).add( halfSize );
  26137. return this;
  26138. };
  26139. }(),
  26140. clone: function () {
  26141. return new this.constructor().copy( this );
  26142. },
  26143. copy: function ( box ) {
  26144. this.min.copy( box.min );
  26145. this.max.copy( box.max );
  26146. return this;
  26147. },
  26148. makeEmpty: function () {
  26149. this.min.x = this.min.y = + Infinity;
  26150. this.max.x = this.max.y = - Infinity;
  26151. return this;
  26152. },
  26153. isEmpty: function () {
  26154. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  26155. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  26156. },
  26157. getCenter: function ( target ) {
  26158. if ( target === undefined ) {
  26159. console.warn( 'THREE.Box2: .getCenter() target is now required' );
  26160. target = new Vector2();
  26161. }
  26162. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  26163. },
  26164. getSize: function ( target ) {
  26165. if ( target === undefined ) {
  26166. console.warn( 'THREE.Box2: .getSize() target is now required' );
  26167. target = new Vector2();
  26168. }
  26169. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  26170. },
  26171. expandByPoint: function ( point ) {
  26172. this.min.min( point );
  26173. this.max.max( point );
  26174. return this;
  26175. },
  26176. expandByVector: function ( vector ) {
  26177. this.min.sub( vector );
  26178. this.max.add( vector );
  26179. return this;
  26180. },
  26181. expandByScalar: function ( scalar ) {
  26182. this.min.addScalar( - scalar );
  26183. this.max.addScalar( scalar );
  26184. return this;
  26185. },
  26186. containsPoint: function ( point ) {
  26187. return point.x < this.min.x || point.x > this.max.x ||
  26188. point.y < this.min.y || point.y > this.max.y ? false : true;
  26189. },
  26190. containsBox: function ( box ) {
  26191. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  26192. this.min.y <= box.min.y && box.max.y <= this.max.y;
  26193. },
  26194. getParameter: function ( point, target ) {
  26195. // This can potentially have a divide by zero if the box
  26196. // has a size dimension of 0.
  26197. if ( target === undefined ) {
  26198. console.warn( 'THREE.Box2: .getParameter() target is now required' );
  26199. target = new Vector2();
  26200. }
  26201. return target.set(
  26202. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  26203. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  26204. );
  26205. },
  26206. intersectsBox: function ( box ) {
  26207. // using 4 splitting planes to rule out intersections
  26208. return box.max.x < this.min.x || box.min.x > this.max.x ||
  26209. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  26210. },
  26211. clampPoint: function ( point, target ) {
  26212. if ( target === undefined ) {
  26213. console.warn( 'THREE.Box2: .clampPoint() target is now required' );
  26214. target = new Vector2();
  26215. }
  26216. return target.copy( point ).clamp( this.min, this.max );
  26217. },
  26218. distanceToPoint: function () {
  26219. var v1 = new Vector2();
  26220. return function distanceToPoint( point ) {
  26221. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  26222. return clampedPoint.sub( point ).length();
  26223. };
  26224. }(),
  26225. intersect: function ( box ) {
  26226. this.min.max( box.min );
  26227. this.max.min( box.max );
  26228. return this;
  26229. },
  26230. union: function ( box ) {
  26231. this.min.min( box.min );
  26232. this.max.max( box.max );
  26233. return this;
  26234. },
  26235. translate: function ( offset ) {
  26236. this.min.add( offset );
  26237. this.max.add( offset );
  26238. return this;
  26239. },
  26240. equals: function ( box ) {
  26241. return box.min.equals( this.min ) && box.max.equals( this.max );
  26242. }
  26243. } );
  26244. /**
  26245. * @author bhouston / http://clara.io
  26246. */
  26247. function Line3( start, end ) {
  26248. this.start = ( start !== undefined ) ? start : new Vector3();
  26249. this.end = ( end !== undefined ) ? end : new Vector3();
  26250. }
  26251. Object.assign( Line3.prototype, {
  26252. set: function ( start, end ) {
  26253. this.start.copy( start );
  26254. this.end.copy( end );
  26255. return this;
  26256. },
  26257. clone: function () {
  26258. return new this.constructor().copy( this );
  26259. },
  26260. copy: function ( line ) {
  26261. this.start.copy( line.start );
  26262. this.end.copy( line.end );
  26263. return this;
  26264. },
  26265. getCenter: function ( target ) {
  26266. if ( target === undefined ) {
  26267. console.warn( 'THREE.Line3: .getCenter() target is now required' );
  26268. target = new Vector3();
  26269. }
  26270. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  26271. },
  26272. delta: function ( target ) {
  26273. if ( target === undefined ) {
  26274. console.warn( 'THREE.Line3: .delta() target is now required' );
  26275. target = new Vector3();
  26276. }
  26277. return target.subVectors( this.end, this.start );
  26278. },
  26279. distanceSq: function () {
  26280. return this.start.distanceToSquared( this.end );
  26281. },
  26282. distance: function () {
  26283. return this.start.distanceTo( this.end );
  26284. },
  26285. at: function ( t, target ) {
  26286. if ( target === undefined ) {
  26287. console.warn( 'THREE.Line3: .at() target is now required' );
  26288. target = new Vector3();
  26289. }
  26290. return this.delta( target ).multiplyScalar( t ).add( this.start );
  26291. },
  26292. closestPointToPointParameter: function () {
  26293. var startP = new Vector3();
  26294. var startEnd = new Vector3();
  26295. return function closestPointToPointParameter( point, clampToLine ) {
  26296. startP.subVectors( point, this.start );
  26297. startEnd.subVectors( this.end, this.start );
  26298. var startEnd2 = startEnd.dot( startEnd );
  26299. var startEnd_startP = startEnd.dot( startP );
  26300. var t = startEnd_startP / startEnd2;
  26301. if ( clampToLine ) {
  26302. t = _Math.clamp( t, 0, 1 );
  26303. }
  26304. return t;
  26305. };
  26306. }(),
  26307. closestPointToPoint: function ( point, clampToLine, target ) {
  26308. var t = this.closestPointToPointParameter( point, clampToLine );
  26309. if ( target === undefined ) {
  26310. console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' );
  26311. target = new Vector3();
  26312. }
  26313. return this.delta( target ).multiplyScalar( t ).add( this.start );
  26314. },
  26315. applyMatrix4: function ( matrix ) {
  26316. this.start.applyMatrix4( matrix );
  26317. this.end.applyMatrix4( matrix );
  26318. return this;
  26319. },
  26320. equals: function ( line ) {
  26321. return line.start.equals( this.start ) && line.end.equals( this.end );
  26322. }
  26323. } );
  26324. /**
  26325. * @author alteredq / http://alteredqualia.com/
  26326. */
  26327. function ImmediateRenderObject( material ) {
  26328. Object3D.call( this );
  26329. this.material = material;
  26330. this.render = function ( /* renderCallback */ ) {};
  26331. }
  26332. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  26333. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  26334. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  26335. /**
  26336. * @author mrdoob / http://mrdoob.com/
  26337. * @author WestLangley / http://github.com/WestLangley
  26338. */
  26339. function VertexNormalsHelper( object, size, hex, linewidth ) {
  26340. this.object = object;
  26341. this.size = ( size !== undefined ) ? size : 1;
  26342. var color = ( hex !== undefined ) ? hex : 0xff0000;
  26343. var width = ( linewidth !== undefined ) ? linewidth : 1;
  26344. //
  26345. var nNormals = 0;
  26346. var objGeometry = this.object.geometry;
  26347. if ( objGeometry && objGeometry.isGeometry ) {
  26348. nNormals = objGeometry.faces.length * 3;
  26349. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  26350. nNormals = objGeometry.attributes.normal.count;
  26351. }
  26352. //
  26353. var geometry = new BufferGeometry();
  26354. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  26355. geometry.addAttribute( 'position', positions );
  26356. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  26357. //
  26358. this.matrixAutoUpdate = false;
  26359. this.update();
  26360. }
  26361. VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
  26362. VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
  26363. VertexNormalsHelper.prototype.update = ( function () {
  26364. var v1 = new Vector3();
  26365. var v2 = new Vector3();
  26366. var normalMatrix = new Matrix3();
  26367. return function update() {
  26368. var keys = [ 'a', 'b', 'c' ];
  26369. this.object.updateMatrixWorld( true );
  26370. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  26371. var matrixWorld = this.object.matrixWorld;
  26372. var position = this.geometry.attributes.position;
  26373. //
  26374. var objGeometry = this.object.geometry;
  26375. if ( objGeometry && objGeometry.isGeometry ) {
  26376. var vertices = objGeometry.vertices;
  26377. var faces = objGeometry.faces;
  26378. var idx = 0;
  26379. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  26380. var face = faces[ i ];
  26381. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  26382. var vertex = vertices[ face[ keys[ j ] ] ];
  26383. var normal = face.vertexNormals[ j ];
  26384. v1.copy( vertex ).applyMatrix4( matrixWorld );
  26385. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  26386. position.setXYZ( idx, v1.x, v1.y, v1.z );
  26387. idx = idx + 1;
  26388. position.setXYZ( idx, v2.x, v2.y, v2.z );
  26389. idx = idx + 1;
  26390. }
  26391. }
  26392. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  26393. var objPos = objGeometry.attributes.position;
  26394. var objNorm = objGeometry.attributes.normal;
  26395. var idx = 0;
  26396. // for simplicity, ignore index and drawcalls, and render every normal
  26397. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  26398. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  26399. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  26400. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  26401. position.setXYZ( idx, v1.x, v1.y, v1.z );
  26402. idx = idx + 1;
  26403. position.setXYZ( idx, v2.x, v2.y, v2.z );
  26404. idx = idx + 1;
  26405. }
  26406. }
  26407. position.needsUpdate = true;
  26408. };
  26409. }() );
  26410. /**
  26411. * @author alteredq / http://alteredqualia.com/
  26412. * @author mrdoob / http://mrdoob.com/
  26413. * @author WestLangley / http://github.com/WestLangley
  26414. */
  26415. function SpotLightHelper( light, color ) {
  26416. Object3D.call( this );
  26417. this.light = light;
  26418. this.light.updateMatrixWorld();
  26419. this.matrix = light.matrixWorld;
  26420. this.matrixAutoUpdate = false;
  26421. this.color = color;
  26422. var geometry = new BufferGeometry();
  26423. var positions = [
  26424. 0, 0, 0, 0, 0, 1,
  26425. 0, 0, 0, 1, 0, 1,
  26426. 0, 0, 0, - 1, 0, 1,
  26427. 0, 0, 0, 0, 1, 1,
  26428. 0, 0, 0, 0, - 1, 1
  26429. ];
  26430. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  26431. var p1 = ( i / l ) * Math.PI * 2;
  26432. var p2 = ( j / l ) * Math.PI * 2;
  26433. positions.push(
  26434. Math.cos( p1 ), Math.sin( p1 ), 1,
  26435. Math.cos( p2 ), Math.sin( p2 ), 1
  26436. );
  26437. }
  26438. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  26439. var material = new LineBasicMaterial( { fog: false } );
  26440. this.cone = new LineSegments( geometry, material );
  26441. this.add( this.cone );
  26442. this.update();
  26443. }
  26444. SpotLightHelper.prototype = Object.create( Object3D.prototype );
  26445. SpotLightHelper.prototype.constructor = SpotLightHelper;
  26446. SpotLightHelper.prototype.dispose = function () {
  26447. this.cone.geometry.dispose();
  26448. this.cone.material.dispose();
  26449. };
  26450. SpotLightHelper.prototype.update = function () {
  26451. var vector = new Vector3();
  26452. return function update() {
  26453. this.light.updateMatrixWorld();
  26454. var coneLength = this.light.distance ? this.light.distance : 1000;
  26455. var coneWidth = coneLength * Math.tan( this.light.angle );
  26456. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  26457. vector.setFromMatrixPosition( this.light.target.matrixWorld );
  26458. this.cone.lookAt( vector );
  26459. if ( this.color !== undefined ) {
  26460. this.cone.material.color.set( this.color );
  26461. } else {
  26462. this.cone.material.color.copy( this.light.color );
  26463. }
  26464. };
  26465. }();
  26466. /**
  26467. * @author Sean Griffin / http://twitter.com/sgrif
  26468. * @author Michael Guerrero / http://realitymeltdown.com
  26469. * @author mrdoob / http://mrdoob.com/
  26470. * @author ikerr / http://verold.com
  26471. * @author Mugen87 / https://github.com/Mugen87
  26472. */
  26473. function getBoneList( object ) {
  26474. var boneList = [];
  26475. if ( object && object.isBone ) {
  26476. boneList.push( object );
  26477. }
  26478. for ( var i = 0; i < object.children.length; i ++ ) {
  26479. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  26480. }
  26481. return boneList;
  26482. }
  26483. function SkeletonHelper( object ) {
  26484. var bones = getBoneList( object );
  26485. var geometry = new BufferGeometry();
  26486. var vertices = [];
  26487. var colors = [];
  26488. var color1 = new Color( 0, 0, 1 );
  26489. var color2 = new Color( 0, 1, 0 );
  26490. for ( var i = 0; i < bones.length; i ++ ) {
  26491. var bone = bones[ i ];
  26492. if ( bone.parent && bone.parent.isBone ) {
  26493. vertices.push( 0, 0, 0 );
  26494. vertices.push( 0, 0, 0 );
  26495. colors.push( color1.r, color1.g, color1.b );
  26496. colors.push( color2.r, color2.g, color2.b );
  26497. }
  26498. }
  26499. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26500. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26501. var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  26502. LineSegments.call( this, geometry, material );
  26503. this.root = object;
  26504. this.bones = bones;
  26505. this.matrix = object.matrixWorld;
  26506. this.matrixAutoUpdate = false;
  26507. }
  26508. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  26509. SkeletonHelper.prototype.constructor = SkeletonHelper;
  26510. SkeletonHelper.prototype.updateMatrixWorld = function () {
  26511. var vector = new Vector3();
  26512. var boneMatrix = new Matrix4();
  26513. var matrixWorldInv = new Matrix4();
  26514. return function updateMatrixWorld( force ) {
  26515. var bones = this.bones;
  26516. var geometry = this.geometry;
  26517. var position = geometry.getAttribute( 'position' );
  26518. matrixWorldInv.getInverse( this.root.matrixWorld );
  26519. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  26520. var bone = bones[ i ];
  26521. if ( bone.parent && bone.parent.isBone ) {
  26522. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  26523. vector.setFromMatrixPosition( boneMatrix );
  26524. position.setXYZ( j, vector.x, vector.y, vector.z );
  26525. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  26526. vector.setFromMatrixPosition( boneMatrix );
  26527. position.setXYZ( j + 1, vector.x, vector.y, vector.z );
  26528. j += 2;
  26529. }
  26530. }
  26531. geometry.getAttribute( 'position' ).needsUpdate = true;
  26532. Object3D.prototype.updateMatrixWorld.call( this, force );
  26533. };
  26534. }();
  26535. /**
  26536. * @author alteredq / http://alteredqualia.com/
  26537. * @author mrdoob / http://mrdoob.com/
  26538. */
  26539. function PointLightHelper( light, sphereSize, color ) {
  26540. this.light = light;
  26541. this.light.updateMatrixWorld();
  26542. this.color = color;
  26543. var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  26544. var material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  26545. Mesh.call( this, geometry, material );
  26546. this.matrix = this.light.matrixWorld;
  26547. this.matrixAutoUpdate = false;
  26548. this.update();
  26549. /*
  26550. var distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  26551. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  26552. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  26553. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  26554. var d = light.distance;
  26555. if ( d === 0.0 ) {
  26556. this.lightDistance.visible = false;
  26557. } else {
  26558. this.lightDistance.scale.set( d, d, d );
  26559. }
  26560. this.add( this.lightDistance );
  26561. */
  26562. }
  26563. PointLightHelper.prototype = Object.create( Mesh.prototype );
  26564. PointLightHelper.prototype.constructor = PointLightHelper;
  26565. PointLightHelper.prototype.dispose = function () {
  26566. this.geometry.dispose();
  26567. this.material.dispose();
  26568. };
  26569. PointLightHelper.prototype.update = function () {
  26570. if ( this.color !== undefined ) {
  26571. this.material.color.set( this.color );
  26572. } else {
  26573. this.material.color.copy( this.light.color );
  26574. }
  26575. /*
  26576. var d = this.light.distance;
  26577. if ( d === 0.0 ) {
  26578. this.lightDistance.visible = false;
  26579. } else {
  26580. this.lightDistance.visible = true;
  26581. this.lightDistance.scale.set( d, d, d );
  26582. }
  26583. */
  26584. };
  26585. /**
  26586. * @author abelnation / http://github.com/abelnation
  26587. * @author Mugen87 / http://github.com/Mugen87
  26588. * @author WestLangley / http://github.com/WestLangley
  26589. *
  26590. * This helper must be added as a child of the light
  26591. */
  26592. function RectAreaLightHelper( light, color ) {
  26593. this.type = 'RectAreaLightHelper';
  26594. this.light = light;
  26595. this.color = color; // optional hardwired color for the helper
  26596. var positions = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, - 1, 0, 1, 1, 0 ];
  26597. var geometry = new BufferGeometry();
  26598. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  26599. geometry.computeBoundingSphere();
  26600. var material = new LineBasicMaterial( { fog: false } );
  26601. Line.call( this, geometry, material );
  26602. //
  26603. var positions2 = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ];
  26604. var geometry2 = new BufferGeometry();
  26605. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  26606. geometry2.computeBoundingSphere();
  26607. this.add( new Mesh( geometry2, new MeshBasicMaterial( { side: THREE.BackSide, fog: false } ) ) );
  26608. this.update();
  26609. }
  26610. RectAreaLightHelper.prototype = Object.create( Line.prototype );
  26611. RectAreaLightHelper.prototype.constructor = RectAreaLightHelper;
  26612. RectAreaLightHelper.prototype.update = function () {
  26613. this.scale.set( 0.5 * this.light.width, 0.5 * this.light.height, 1 );
  26614. if ( this.color !== undefined ) {
  26615. this.material.color.set( this.color );
  26616. this.children[ 0 ].material.color.set( this.color );
  26617. } else {
  26618. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  26619. // prevent hue shift
  26620. var c = this.material.color;
  26621. var max = Math.max( c.r, c.g, c.b );
  26622. if ( max > 1 ) c.multiplyScalar( 1 / max );
  26623. this.children[ 0 ].material.color.copy( this.material.color );
  26624. }
  26625. };
  26626. RectAreaLightHelper.prototype.dispose = function () {
  26627. this.geometry.dispose();
  26628. this.material.dispose();
  26629. this.children[ 0 ].geometry.dispose();
  26630. this.children[ 0 ].material.dispose();
  26631. };
  26632. /**
  26633. * @author alteredq / http://alteredqualia.com/
  26634. * @author mrdoob / http://mrdoob.com/
  26635. * @author Mugen87 / https://github.com/Mugen87
  26636. */
  26637. function HemisphereLightHelper( light, size, color ) {
  26638. Object3D.call( this );
  26639. this.light = light;
  26640. this.light.updateMatrixWorld();
  26641. this.matrix = light.matrixWorld;
  26642. this.matrixAutoUpdate = false;
  26643. this.color = color;
  26644. var geometry = new OctahedronBufferGeometry( size );
  26645. geometry.rotateY( Math.PI * 0.5 );
  26646. this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  26647. if ( this.color === undefined ) this.material.vertexColors = VertexColors;
  26648. var position = geometry.getAttribute( 'position' );
  26649. var colors = new Float32Array( position.count * 3 );
  26650. geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
  26651. this.add( new Mesh( geometry, this.material ) );
  26652. this.update();
  26653. }
  26654. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  26655. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  26656. HemisphereLightHelper.prototype.dispose = function () {
  26657. this.children[ 0 ].geometry.dispose();
  26658. this.children[ 0 ].material.dispose();
  26659. };
  26660. HemisphereLightHelper.prototype.update = function () {
  26661. var vector = new Vector3();
  26662. var color1 = new Color();
  26663. var color2 = new Color();
  26664. return function update() {
  26665. var mesh = this.children[ 0 ];
  26666. if ( this.color !== undefined ) {
  26667. this.material.color.set( this.color );
  26668. } else {
  26669. var colors = mesh.geometry.getAttribute( 'color' );
  26670. color1.copy( this.light.color );
  26671. color2.copy( this.light.groundColor );
  26672. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  26673. var color = ( i < ( l / 2 ) ) ? color1 : color2;
  26674. colors.setXYZ( i, color.r, color.g, color.b );
  26675. }
  26676. colors.needsUpdate = true;
  26677. }
  26678. mesh.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  26679. };
  26680. }();
  26681. /**
  26682. * @author mrdoob / http://mrdoob.com/
  26683. */
  26684. function GridHelper( size, divisions, color1, color2 ) {
  26685. size = size || 10;
  26686. divisions = divisions || 10;
  26687. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  26688. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  26689. var center = divisions / 2;
  26690. var step = size / divisions;
  26691. var halfSize = size / 2;
  26692. var vertices = [], colors = [];
  26693. for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  26694. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  26695. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  26696. var color = i === center ? color1 : color2;
  26697. color.toArray( colors, j ); j += 3;
  26698. color.toArray( colors, j ); j += 3;
  26699. color.toArray( colors, j ); j += 3;
  26700. color.toArray( colors, j ); j += 3;
  26701. }
  26702. var geometry = new BufferGeometry();
  26703. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26704. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26705. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  26706. LineSegments.call( this, geometry, material );
  26707. }
  26708. GridHelper.prototype = Object.create( LineSegments.prototype );
  26709. GridHelper.prototype.constructor = GridHelper;
  26710. /**
  26711. * @author mrdoob / http://mrdoob.com/
  26712. * @author Mugen87 / http://github.com/Mugen87
  26713. * @author Hectate / http://www.github.com/Hectate
  26714. */
  26715. function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
  26716. radius = radius || 10;
  26717. radials = radials || 16;
  26718. circles = circles || 8;
  26719. divisions = divisions || 64;
  26720. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  26721. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  26722. var vertices = [];
  26723. var colors = [];
  26724. var x, z;
  26725. var v, i, j, r, color;
  26726. // create the radials
  26727. for ( i = 0; i <= radials; i ++ ) {
  26728. v = ( i / radials ) * ( Math.PI * 2 );
  26729. x = Math.sin( v ) * radius;
  26730. z = Math.cos( v ) * radius;
  26731. vertices.push( 0, 0, 0 );
  26732. vertices.push( x, 0, z );
  26733. color = ( i & 1 ) ? color1 : color2;
  26734. colors.push( color.r, color.g, color.b );
  26735. colors.push( color.r, color.g, color.b );
  26736. }
  26737. // create the circles
  26738. for ( i = 0; i <= circles; i ++ ) {
  26739. color = ( i & 1 ) ? color1 : color2;
  26740. r = radius - ( radius / circles * i );
  26741. for ( j = 0; j < divisions; j ++ ) {
  26742. // first vertex
  26743. v = ( j / divisions ) * ( Math.PI * 2 );
  26744. x = Math.sin( v ) * r;
  26745. z = Math.cos( v ) * r;
  26746. vertices.push( x, 0, z );
  26747. colors.push( color.r, color.g, color.b );
  26748. // second vertex
  26749. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  26750. x = Math.sin( v ) * r;
  26751. z = Math.cos( v ) * r;
  26752. vertices.push( x, 0, z );
  26753. colors.push( color.r, color.g, color.b );
  26754. }
  26755. }
  26756. var geometry = new BufferGeometry();
  26757. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26758. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26759. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  26760. LineSegments.call( this, geometry, material );
  26761. }
  26762. PolarGridHelper.prototype = Object.create( LineSegments.prototype );
  26763. PolarGridHelper.prototype.constructor = PolarGridHelper;
  26764. /**
  26765. * @author mrdoob / http://mrdoob.com/
  26766. * @author WestLangley / http://github.com/WestLangley
  26767. */
  26768. function FaceNormalsHelper( object, size, hex, linewidth ) {
  26769. // FaceNormalsHelper only supports THREE.Geometry
  26770. this.object = object;
  26771. this.size = ( size !== undefined ) ? size : 1;
  26772. var color = ( hex !== undefined ) ? hex : 0xffff00;
  26773. var width = ( linewidth !== undefined ) ? linewidth : 1;
  26774. //
  26775. var nNormals = 0;
  26776. var objGeometry = this.object.geometry;
  26777. if ( objGeometry && objGeometry.isGeometry ) {
  26778. nNormals = objGeometry.faces.length;
  26779. } else {
  26780. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  26781. }
  26782. //
  26783. var geometry = new BufferGeometry();
  26784. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  26785. geometry.addAttribute( 'position', positions );
  26786. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  26787. //
  26788. this.matrixAutoUpdate = false;
  26789. this.update();
  26790. }
  26791. FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
  26792. FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
  26793. FaceNormalsHelper.prototype.update = ( function () {
  26794. var v1 = new Vector3();
  26795. var v2 = new Vector3();
  26796. var normalMatrix = new Matrix3();
  26797. return function update() {
  26798. this.object.updateMatrixWorld( true );
  26799. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  26800. var matrixWorld = this.object.matrixWorld;
  26801. var position = this.geometry.attributes.position;
  26802. //
  26803. var objGeometry = this.object.geometry;
  26804. var vertices = objGeometry.vertices;
  26805. var faces = objGeometry.faces;
  26806. var idx = 0;
  26807. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  26808. var face = faces[ i ];
  26809. var normal = face.normal;
  26810. v1.copy( vertices[ face.a ] )
  26811. .add( vertices[ face.b ] )
  26812. .add( vertices[ face.c ] )
  26813. .divideScalar( 3 )
  26814. .applyMatrix4( matrixWorld );
  26815. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  26816. position.setXYZ( idx, v1.x, v1.y, v1.z );
  26817. idx = idx + 1;
  26818. position.setXYZ( idx, v2.x, v2.y, v2.z );
  26819. idx = idx + 1;
  26820. }
  26821. position.needsUpdate = true;
  26822. };
  26823. }() );
  26824. /**
  26825. * @author alteredq / http://alteredqualia.com/
  26826. * @author mrdoob / http://mrdoob.com/
  26827. * @author WestLangley / http://github.com/WestLangley
  26828. */
  26829. function DirectionalLightHelper( light, size, color ) {
  26830. Object3D.call( this );
  26831. this.light = light;
  26832. this.light.updateMatrixWorld();
  26833. this.matrix = light.matrixWorld;
  26834. this.matrixAutoUpdate = false;
  26835. this.color = color;
  26836. if ( size === undefined ) size = 1;
  26837. var geometry = new BufferGeometry();
  26838. geometry.addAttribute( 'position', new Float32BufferAttribute( [
  26839. - size, size, 0,
  26840. size, size, 0,
  26841. size, - size, 0,
  26842. - size, - size, 0,
  26843. - size, size, 0
  26844. ], 3 ) );
  26845. var material = new LineBasicMaterial( { fog: false } );
  26846. this.lightPlane = new Line( geometry, material );
  26847. this.add( this.lightPlane );
  26848. geometry = new BufferGeometry();
  26849. geometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  26850. this.targetLine = new Line( geometry, material );
  26851. this.add( this.targetLine );
  26852. this.update();
  26853. }
  26854. DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
  26855. DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
  26856. DirectionalLightHelper.prototype.dispose = function () {
  26857. this.lightPlane.geometry.dispose();
  26858. this.lightPlane.material.dispose();
  26859. this.targetLine.geometry.dispose();
  26860. this.targetLine.material.dispose();
  26861. };
  26862. DirectionalLightHelper.prototype.update = function () {
  26863. var v1 = new Vector3();
  26864. var v2 = new Vector3();
  26865. var v3 = new Vector3();
  26866. return function update() {
  26867. v1.setFromMatrixPosition( this.light.matrixWorld );
  26868. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  26869. v3.subVectors( v2, v1 );
  26870. this.lightPlane.lookAt( v2 );
  26871. if ( this.color !== undefined ) {
  26872. this.lightPlane.material.color.set( this.color );
  26873. this.targetLine.material.color.set( this.color );
  26874. } else {
  26875. this.lightPlane.material.color.copy( this.light.color );
  26876. this.targetLine.material.color.copy( this.light.color );
  26877. }
  26878. this.targetLine.lookAt( v2 );
  26879. this.targetLine.scale.z = v3.length();
  26880. };
  26881. }();
  26882. /**
  26883. * @author alteredq / http://alteredqualia.com/
  26884. * @author Mugen87 / https://github.com/Mugen87
  26885. *
  26886. * - shows frustum, line of sight and up of the camera
  26887. * - suitable for fast updates
  26888. * - based on frustum visualization in lightgl.js shadowmap example
  26889. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  26890. */
  26891. function CameraHelper( camera ) {
  26892. var geometry = new BufferGeometry();
  26893. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
  26894. var vertices = [];
  26895. var colors = [];
  26896. var pointMap = {};
  26897. // colors
  26898. var colorFrustum = new Color( 0xffaa00 );
  26899. var colorCone = new Color( 0xff0000 );
  26900. var colorUp = new Color( 0x00aaff );
  26901. var colorTarget = new Color( 0xffffff );
  26902. var colorCross = new Color( 0x333333 );
  26903. // near
  26904. addLine( 'n1', 'n2', colorFrustum );
  26905. addLine( 'n2', 'n4', colorFrustum );
  26906. addLine( 'n4', 'n3', colorFrustum );
  26907. addLine( 'n3', 'n1', colorFrustum );
  26908. // far
  26909. addLine( 'f1', 'f2', colorFrustum );
  26910. addLine( 'f2', 'f4', colorFrustum );
  26911. addLine( 'f4', 'f3', colorFrustum );
  26912. addLine( 'f3', 'f1', colorFrustum );
  26913. // sides
  26914. addLine( 'n1', 'f1', colorFrustum );
  26915. addLine( 'n2', 'f2', colorFrustum );
  26916. addLine( 'n3', 'f3', colorFrustum );
  26917. addLine( 'n4', 'f4', colorFrustum );
  26918. // cone
  26919. addLine( 'p', 'n1', colorCone );
  26920. addLine( 'p', 'n2', colorCone );
  26921. addLine( 'p', 'n3', colorCone );
  26922. addLine( 'p', 'n4', colorCone );
  26923. // up
  26924. addLine( 'u1', 'u2', colorUp );
  26925. addLine( 'u2', 'u3', colorUp );
  26926. addLine( 'u3', 'u1', colorUp );
  26927. // target
  26928. addLine( 'c', 't', colorTarget );
  26929. addLine( 'p', 'c', colorCross );
  26930. // cross
  26931. addLine( 'cn1', 'cn2', colorCross );
  26932. addLine( 'cn3', 'cn4', colorCross );
  26933. addLine( 'cf1', 'cf2', colorCross );
  26934. addLine( 'cf3', 'cf4', colorCross );
  26935. function addLine( a, b, color ) {
  26936. addPoint( a, color );
  26937. addPoint( b, color );
  26938. }
  26939. function addPoint( id, color ) {
  26940. vertices.push( 0, 0, 0 );
  26941. colors.push( color.r, color.g, color.b );
  26942. if ( pointMap[ id ] === undefined ) {
  26943. pointMap[ id ] = [];
  26944. }
  26945. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  26946. }
  26947. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26948. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26949. LineSegments.call( this, geometry, material );
  26950. this.camera = camera;
  26951. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  26952. this.matrix = camera.matrixWorld;
  26953. this.matrixAutoUpdate = false;
  26954. this.pointMap = pointMap;
  26955. this.update();
  26956. }
  26957. CameraHelper.prototype = Object.create( LineSegments.prototype );
  26958. CameraHelper.prototype.constructor = CameraHelper;
  26959. CameraHelper.prototype.update = function () {
  26960. var geometry, pointMap;
  26961. var vector = new Vector3();
  26962. var camera = new Camera();
  26963. function setPoint( point, x, y, z ) {
  26964. vector.set( x, y, z ).unproject( camera );
  26965. var points = pointMap[ point ];
  26966. if ( points !== undefined ) {
  26967. var position = geometry.getAttribute( 'position' );
  26968. for ( var i = 0, l = points.length; i < l; i ++ ) {
  26969. position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
  26970. }
  26971. }
  26972. }
  26973. return function update() {
  26974. geometry = this.geometry;
  26975. pointMap = this.pointMap;
  26976. var w = 1, h = 1;
  26977. // we need just camera projection matrix
  26978. // world matrix must be identity
  26979. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  26980. // center / target
  26981. setPoint( 'c', 0, 0, - 1 );
  26982. setPoint( 't', 0, 0, 1 );
  26983. // near
  26984. setPoint( 'n1', - w, - h, - 1 );
  26985. setPoint( 'n2', w, - h, - 1 );
  26986. setPoint( 'n3', - w, h, - 1 );
  26987. setPoint( 'n4', w, h, - 1 );
  26988. // far
  26989. setPoint( 'f1', - w, - h, 1 );
  26990. setPoint( 'f2', w, - h, 1 );
  26991. setPoint( 'f3', - w, h, 1 );
  26992. setPoint( 'f4', w, h, 1 );
  26993. // up
  26994. setPoint( 'u1', w * 0.7, h * 1.1, - 1 );
  26995. setPoint( 'u2', - w * 0.7, h * 1.1, - 1 );
  26996. setPoint( 'u3', 0, h * 2, - 1 );
  26997. // cross
  26998. setPoint( 'cf1', - w, 0, 1 );
  26999. setPoint( 'cf2', w, 0, 1 );
  27000. setPoint( 'cf3', 0, - h, 1 );
  27001. setPoint( 'cf4', 0, h, 1 );
  27002. setPoint( 'cn1', - w, 0, - 1 );
  27003. setPoint( 'cn2', w, 0, - 1 );
  27004. setPoint( 'cn3', 0, - h, - 1 );
  27005. setPoint( 'cn4', 0, h, - 1 );
  27006. geometry.getAttribute( 'position' ).needsUpdate = true;
  27007. };
  27008. }();
  27009. /**
  27010. * @author mrdoob / http://mrdoob.com/
  27011. * @author Mugen87 / http://github.com/Mugen87
  27012. */
  27013. function BoxHelper( object, color ) {
  27014. this.object = object;
  27015. if ( color === undefined ) color = 0xffff00;
  27016. 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 ] );
  27017. var positions = new Float32Array( 8 * 3 );
  27018. var geometry = new BufferGeometry();
  27019. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27020. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  27021. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27022. this.matrixAutoUpdate = false;
  27023. this.update();
  27024. }
  27025. BoxHelper.prototype = Object.create( LineSegments.prototype );
  27026. BoxHelper.prototype.constructor = BoxHelper;
  27027. BoxHelper.prototype.update = ( function () {
  27028. var box = new Box3();
  27029. return function update( object ) {
  27030. if ( object !== undefined ) {
  27031. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  27032. }
  27033. if ( this.object !== undefined ) {
  27034. box.setFromObject( this.object );
  27035. }
  27036. if ( box.isEmpty() ) return;
  27037. var min = box.min;
  27038. var max = box.max;
  27039. /*
  27040. 5____4
  27041. 1/___0/|
  27042. | 6__|_7
  27043. 2/___3/
  27044. 0: max.x, max.y, max.z
  27045. 1: min.x, max.y, max.z
  27046. 2: min.x, min.y, max.z
  27047. 3: max.x, min.y, max.z
  27048. 4: max.x, max.y, min.z
  27049. 5: min.x, max.y, min.z
  27050. 6: min.x, min.y, min.z
  27051. 7: max.x, min.y, min.z
  27052. */
  27053. var position = this.geometry.attributes.position;
  27054. var array = position.array;
  27055. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  27056. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  27057. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  27058. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  27059. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  27060. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  27061. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  27062. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  27063. position.needsUpdate = true;
  27064. this.geometry.computeBoundingSphere();
  27065. };
  27066. } )();
  27067. BoxHelper.prototype.setFromObject = function ( object ) {
  27068. this.object = object;
  27069. this.update();
  27070. return this;
  27071. };
  27072. BoxHelper.prototype.copy = function ( source ) {
  27073. LineSegments.prototype.copy.call( this, source );
  27074. this.object = source.object;
  27075. return this;
  27076. };
  27077. BoxHelper.prototype.clone = function () {
  27078. return new this.constructor().copy( this );
  27079. };
  27080. /**
  27081. * @author WestLangley / http://github.com/WestLangley
  27082. */
  27083. function Box3Helper( box, hex ) {
  27084. this.type = 'Box3Helper';
  27085. this.box = box;
  27086. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27087. 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 ] );
  27088. 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 ];
  27089. var geometry = new BufferGeometry();
  27090. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27091. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27092. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27093. this.geometry.computeBoundingSphere();
  27094. }
  27095. Box3Helper.prototype = Object.create( LineSegments.prototype );
  27096. Box3Helper.prototype.constructor = Box3Helper;
  27097. Box3Helper.prototype.updateMatrixWorld = function ( force ) {
  27098. var box = this.box;
  27099. if ( box.isEmpty() ) return;
  27100. box.getCenter( this.position );
  27101. box.getSize( this.scale );
  27102. this.scale.multiplyScalar( 0.5 );
  27103. Object3D.prototype.updateMatrixWorld.call( this, force );
  27104. };
  27105. /**
  27106. * @author WestLangley / http://github.com/WestLangley
  27107. */
  27108. function PlaneHelper( plane, size, hex ) {
  27109. this.type = 'PlaneHelper';
  27110. this.plane = plane;
  27111. this.size = ( size === undefined ) ? 1 : size;
  27112. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27113. 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 ];
  27114. var geometry = new BufferGeometry();
  27115. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27116. geometry.computeBoundingSphere();
  27117. Line.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27118. //
  27119. var positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  27120. var geometry2 = new BufferGeometry();
  27121. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  27122. geometry2.computeBoundingSphere();
  27123. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false } ) ) );
  27124. }
  27125. PlaneHelper.prototype = Object.create( Line.prototype );
  27126. PlaneHelper.prototype.constructor = PlaneHelper;
  27127. PlaneHelper.prototype.updateMatrixWorld = function ( force ) {
  27128. var scale = - this.plane.constant;
  27129. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  27130. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  27131. this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  27132. this.lookAt( this.plane.normal );
  27133. Object3D.prototype.updateMatrixWorld.call( this, force );
  27134. };
  27135. /**
  27136. * @author WestLangley / http://github.com/WestLangley
  27137. * @author zz85 / http://github.com/zz85
  27138. * @author bhouston / http://clara.io
  27139. *
  27140. * Creates an arrow for visualizing directions
  27141. *
  27142. * Parameters:
  27143. * dir - Vector3
  27144. * origin - Vector3
  27145. * length - Number
  27146. * color - color in hex value
  27147. * headLength - Number
  27148. * headWidth - Number
  27149. */
  27150. var lineGeometry, coneGeometry;
  27151. function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  27152. // dir is assumed to be normalized
  27153. Object3D.call( this );
  27154. if ( dir === undefined ) dir = new THREE.Vector3( 0, 0, 1 );
  27155. if ( origin === undefined ) origin = new THREE.Vector3( 0, 0, 0 );
  27156. if ( length === undefined ) length = 1;
  27157. if ( color === undefined ) color = 0xffff00;
  27158. if ( headLength === undefined ) headLength = 0.2 * length;
  27159. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  27160. if ( lineGeometry === undefined ) {
  27161. lineGeometry = new BufferGeometry();
  27162. lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  27163. coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  27164. coneGeometry.translate( 0, - 0.5, 0 );
  27165. }
  27166. this.position.copy( origin );
  27167. this.line = new Line( lineGeometry, new LineBasicMaterial( { color: color } ) );
  27168. this.line.matrixAutoUpdate = false;
  27169. this.add( this.line );
  27170. this.cone = new Mesh( coneGeometry, new MeshBasicMaterial( { color: color } ) );
  27171. this.cone.matrixAutoUpdate = false;
  27172. this.add( this.cone );
  27173. this.setDirection( dir );
  27174. this.setLength( length, headLength, headWidth );
  27175. }
  27176. ArrowHelper.prototype = Object.create( Object3D.prototype );
  27177. ArrowHelper.prototype.constructor = ArrowHelper;
  27178. ArrowHelper.prototype.setDirection = ( function () {
  27179. var axis = new Vector3();
  27180. var radians;
  27181. return function setDirection( dir ) {
  27182. // dir is assumed to be normalized
  27183. if ( dir.y > 0.99999 ) {
  27184. this.quaternion.set( 0, 0, 0, 1 );
  27185. } else if ( dir.y < - 0.99999 ) {
  27186. this.quaternion.set( 1, 0, 0, 0 );
  27187. } else {
  27188. axis.set( dir.z, 0, - dir.x ).normalize();
  27189. radians = Math.acos( dir.y );
  27190. this.quaternion.setFromAxisAngle( axis, radians );
  27191. }
  27192. };
  27193. }() );
  27194. ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  27195. if ( headLength === undefined ) headLength = 0.2 * length;
  27196. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  27197. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  27198. this.line.updateMatrix();
  27199. this.cone.scale.set( headWidth, headLength, headWidth );
  27200. this.cone.position.y = length;
  27201. this.cone.updateMatrix();
  27202. };
  27203. ArrowHelper.prototype.setColor = function ( color ) {
  27204. this.line.material.color.copy( color );
  27205. this.cone.material.color.copy( color );
  27206. };
  27207. ArrowHelper.prototype.copy = function ( source ) {
  27208. Object3D.prototype.copy.call( this, source, false );
  27209. this.line.copy( source.line );
  27210. this.cone.copy( source.cone );
  27211. return this;
  27212. };
  27213. ArrowHelper.prototype.clone = function () {
  27214. return new this.constructor().copy( this );
  27215. };
  27216. /**
  27217. * @author sroucheray / http://sroucheray.org/
  27218. * @author mrdoob / http://mrdoob.com/
  27219. */
  27220. function AxesHelper( size ) {
  27221. size = size || 1;
  27222. var vertices = [
  27223. 0, 0, 0, size, 0, 0,
  27224. 0, 0, 0, 0, size, 0,
  27225. 0, 0, 0, 0, 0, size
  27226. ];
  27227. var colors = [
  27228. 1, 0, 0, 1, 0.6, 0,
  27229. 0, 1, 0, 0.6, 1, 0,
  27230. 0, 0, 1, 0, 0.6, 1
  27231. ];
  27232. var geometry = new BufferGeometry();
  27233. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27234. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27235. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27236. LineSegments.call( this, geometry, material );
  27237. }
  27238. AxesHelper.prototype = Object.create( LineSegments.prototype );
  27239. AxesHelper.prototype.constructor = AxesHelper;
  27240. /**
  27241. * @author mrdoob / http://mrdoob.com/
  27242. */
  27243. function Face4( a, b, c, d, normal, color, materialIndex ) {
  27244. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  27245. return new Face3( a, b, c, normal, color, materialIndex );
  27246. }
  27247. var LineStrip = 0;
  27248. var LinePieces = 1;
  27249. function MeshFaceMaterial( materials ) {
  27250. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  27251. return materials;
  27252. }
  27253. function MultiMaterial( materials ) {
  27254. if ( materials === undefined ) materials = [];
  27255. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  27256. materials.isMultiMaterial = true;
  27257. materials.materials = materials;
  27258. materials.clone = function () {
  27259. return materials.slice();
  27260. };
  27261. return materials;
  27262. }
  27263. function PointCloud( geometry, material ) {
  27264. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  27265. return new Points( geometry, material );
  27266. }
  27267. function Particle( material ) {
  27268. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  27269. return new Sprite( material );
  27270. }
  27271. function ParticleSystem( geometry, material ) {
  27272. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  27273. return new Points( geometry, material );
  27274. }
  27275. function PointCloudMaterial( parameters ) {
  27276. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  27277. return new PointsMaterial( parameters );
  27278. }
  27279. function ParticleBasicMaterial( parameters ) {
  27280. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  27281. return new PointsMaterial( parameters );
  27282. }
  27283. function ParticleSystemMaterial( parameters ) {
  27284. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  27285. return new PointsMaterial( parameters );
  27286. }
  27287. function Vertex( x, y, z ) {
  27288. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  27289. return new Vector3( x, y, z );
  27290. }
  27291. //
  27292. function DynamicBufferAttribute( array, itemSize ) {
  27293. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  27294. return new BufferAttribute( array, itemSize ).setDynamic( true );
  27295. }
  27296. function Int8Attribute( array, itemSize ) {
  27297. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  27298. return new Int8BufferAttribute( array, itemSize );
  27299. }
  27300. function Uint8Attribute( array, itemSize ) {
  27301. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  27302. return new Uint8BufferAttribute( array, itemSize );
  27303. }
  27304. function Uint8ClampedAttribute( array, itemSize ) {
  27305. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  27306. return new Uint8ClampedBufferAttribute( array, itemSize );
  27307. }
  27308. function Int16Attribute( array, itemSize ) {
  27309. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  27310. return new Int16BufferAttribute( array, itemSize );
  27311. }
  27312. function Uint16Attribute( array, itemSize ) {
  27313. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  27314. return new Uint16BufferAttribute( array, itemSize );
  27315. }
  27316. function Int32Attribute( array, itemSize ) {
  27317. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  27318. return new Int32BufferAttribute( array, itemSize );
  27319. }
  27320. function Uint32Attribute( array, itemSize ) {
  27321. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  27322. return new Uint32BufferAttribute( array, itemSize );
  27323. }
  27324. function Float32Attribute( array, itemSize ) {
  27325. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  27326. return new Float32BufferAttribute( array, itemSize );
  27327. }
  27328. function Float64Attribute( array, itemSize ) {
  27329. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  27330. return new Float64BufferAttribute( array, itemSize );
  27331. }
  27332. //
  27333. Curve.create = function ( construct, getPoint ) {
  27334. console.log( 'THREE.Curve.create() has been deprecated' );
  27335. construct.prototype = Object.create( Curve.prototype );
  27336. construct.prototype.constructor = construct;
  27337. construct.prototype.getPoint = getPoint;
  27338. return construct;
  27339. };
  27340. //
  27341. Object.assign( CurvePath.prototype, {
  27342. createPointsGeometry: function ( divisions ) {
  27343. console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  27344. // generate geometry from path points (for Line or Points objects)
  27345. var pts = this.getPoints( divisions );
  27346. return this.createGeometry( pts );
  27347. },
  27348. createSpacedPointsGeometry: function ( divisions ) {
  27349. console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  27350. // generate geometry from equidistant sampling along the path
  27351. var pts = this.getSpacedPoints( divisions );
  27352. return this.createGeometry( pts );
  27353. },
  27354. createGeometry: function ( points ) {
  27355. console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  27356. var geometry = new Geometry();
  27357. for ( var i = 0, l = points.length; i < l; i ++ ) {
  27358. var point = points[ i ];
  27359. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  27360. }
  27361. return geometry;
  27362. }
  27363. } );
  27364. //
  27365. Object.assign( Path.prototype, {
  27366. fromPoints: function ( points ) {
  27367. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  27368. this.setFromPoints( points );
  27369. }
  27370. } );
  27371. //
  27372. function ClosedSplineCurve3( points ) {
  27373. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  27374. CatmullRomCurve3.call( this, points );
  27375. this.type = 'catmullrom';
  27376. this.closed = true;
  27377. }
  27378. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  27379. //
  27380. function SplineCurve3( points ) {
  27381. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  27382. CatmullRomCurve3.call( this, points );
  27383. this.type = 'catmullrom';
  27384. }
  27385. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  27386. //
  27387. function Spline( points ) {
  27388. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  27389. CatmullRomCurve3.call( this, points );
  27390. this.type = 'catmullrom';
  27391. }
  27392. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  27393. Object.assign( Spline.prototype, {
  27394. initFromArray: function ( /* a */ ) {
  27395. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  27396. },
  27397. getControlPointsArray: function ( /* optionalTarget */ ) {
  27398. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  27399. },
  27400. reparametrizeByArcLength: function ( /* samplingCoef */ ) {
  27401. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  27402. }
  27403. } );
  27404. //
  27405. function AxisHelper( size ) {
  27406. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  27407. return new AxesHelper( size );
  27408. }
  27409. function BoundingBoxHelper( object, color ) {
  27410. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  27411. return new BoxHelper( object, color );
  27412. }
  27413. function EdgesHelper( object, hex ) {
  27414. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  27415. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  27416. }
  27417. GridHelper.prototype.setColors = function () {
  27418. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  27419. };
  27420. SkeletonHelper.prototype.update = function () {
  27421. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  27422. };
  27423. function WireframeHelper( object, hex ) {
  27424. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  27425. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  27426. }
  27427. //
  27428. Object.assign( Loader.prototype, {
  27429. extractUrlBase: function ( url ) {
  27430. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  27431. return LoaderUtils.extractUrlBase( url );
  27432. }
  27433. } );
  27434. function XHRLoader( manager ) {
  27435. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  27436. return new FileLoader( manager );
  27437. }
  27438. function BinaryTextureLoader( manager ) {
  27439. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  27440. return new DataTextureLoader( manager );
  27441. }
  27442. Object.assign( ObjectLoader.prototype, {
  27443. setTexturePath: function ( value ) {
  27444. console.warn( 'THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().' );
  27445. return this.setResourcePath( value );
  27446. }
  27447. } );
  27448. //
  27449. Object.assign( Box2.prototype, {
  27450. center: function ( optionalTarget ) {
  27451. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  27452. return this.getCenter( optionalTarget );
  27453. },
  27454. empty: function () {
  27455. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  27456. return this.isEmpty();
  27457. },
  27458. isIntersectionBox: function ( box ) {
  27459. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  27460. return this.intersectsBox( box );
  27461. },
  27462. size: function ( optionalTarget ) {
  27463. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  27464. return this.getSize( optionalTarget );
  27465. }
  27466. } );
  27467. Object.assign( Box3.prototype, {
  27468. center: function ( optionalTarget ) {
  27469. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  27470. return this.getCenter( optionalTarget );
  27471. },
  27472. empty: function () {
  27473. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  27474. return this.isEmpty();
  27475. },
  27476. isIntersectionBox: function ( box ) {
  27477. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  27478. return this.intersectsBox( box );
  27479. },
  27480. isIntersectionSphere: function ( sphere ) {
  27481. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  27482. return this.intersectsSphere( sphere );
  27483. },
  27484. size: function ( optionalTarget ) {
  27485. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  27486. return this.getSize( optionalTarget );
  27487. }
  27488. } );
  27489. Line3.prototype.center = function ( optionalTarget ) {
  27490. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  27491. return this.getCenter( optionalTarget );
  27492. };
  27493. Object.assign( _Math, {
  27494. random16: function () {
  27495. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  27496. return Math.random();
  27497. },
  27498. nearestPowerOfTwo: function ( value ) {
  27499. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  27500. return _Math.floorPowerOfTwo( value );
  27501. },
  27502. nextPowerOfTwo: function ( value ) {
  27503. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  27504. return _Math.ceilPowerOfTwo( value );
  27505. }
  27506. } );
  27507. Object.assign( Matrix3.prototype, {
  27508. flattenToArrayOffset: function ( array, offset ) {
  27509. console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  27510. return this.toArray( array, offset );
  27511. },
  27512. multiplyVector3: function ( vector ) {
  27513. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  27514. return vector.applyMatrix3( this );
  27515. },
  27516. multiplyVector3Array: function ( /* a */ ) {
  27517. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  27518. },
  27519. applyToBuffer: function ( buffer /*, offset, length */ ) {
  27520. console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  27521. return this.applyToBufferAttribute( buffer );
  27522. },
  27523. applyToVector3Array: function ( /* array, offset, length */ ) {
  27524. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  27525. }
  27526. } );
  27527. Object.assign( Matrix4.prototype, {
  27528. extractPosition: function ( m ) {
  27529. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  27530. return this.copyPosition( m );
  27531. },
  27532. flattenToArrayOffset: function ( array, offset ) {
  27533. console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  27534. return this.toArray( array, offset );
  27535. },
  27536. getPosition: function () {
  27537. var v1;
  27538. return function getPosition() {
  27539. if ( v1 === undefined ) v1 = new Vector3();
  27540. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  27541. return v1.setFromMatrixColumn( this, 3 );
  27542. };
  27543. }(),
  27544. setRotationFromQuaternion: function ( q ) {
  27545. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  27546. return this.makeRotationFromQuaternion( q );
  27547. },
  27548. multiplyToArray: function () {
  27549. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  27550. },
  27551. multiplyVector3: function ( vector ) {
  27552. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  27553. return vector.applyMatrix4( this );
  27554. },
  27555. multiplyVector4: function ( vector ) {
  27556. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  27557. return vector.applyMatrix4( this );
  27558. },
  27559. multiplyVector3Array: function ( /* a */ ) {
  27560. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  27561. },
  27562. rotateAxis: function ( v ) {
  27563. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  27564. v.transformDirection( this );
  27565. },
  27566. crossVector: function ( vector ) {
  27567. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  27568. return vector.applyMatrix4( this );
  27569. },
  27570. translate: function () {
  27571. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  27572. },
  27573. rotateX: function () {
  27574. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  27575. },
  27576. rotateY: function () {
  27577. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  27578. },
  27579. rotateZ: function () {
  27580. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  27581. },
  27582. rotateByAxis: function () {
  27583. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  27584. },
  27585. applyToBuffer: function ( buffer /*, offset, length */ ) {
  27586. console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  27587. return this.applyToBufferAttribute( buffer );
  27588. },
  27589. applyToVector3Array: function ( /* array, offset, length */ ) {
  27590. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  27591. },
  27592. makeFrustum: function ( left, right, bottom, top, near, far ) {
  27593. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  27594. return this.makePerspective( left, right, top, bottom, near, far );
  27595. }
  27596. } );
  27597. Plane.prototype.isIntersectionLine = function ( line ) {
  27598. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  27599. return this.intersectsLine( line );
  27600. };
  27601. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  27602. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  27603. return vector.applyQuaternion( this );
  27604. };
  27605. Object.assign( Ray.prototype, {
  27606. isIntersectionBox: function ( box ) {
  27607. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  27608. return this.intersectsBox( box );
  27609. },
  27610. isIntersectionPlane: function ( plane ) {
  27611. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  27612. return this.intersectsPlane( plane );
  27613. },
  27614. isIntersectionSphere: function ( sphere ) {
  27615. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  27616. return this.intersectsSphere( sphere );
  27617. }
  27618. } );
  27619. Object.assign( Triangle.prototype, {
  27620. area: function () {
  27621. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  27622. return this.getArea();
  27623. },
  27624. barycoordFromPoint: function ( point, target ) {
  27625. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  27626. return this.getBarycoord( point, target );
  27627. },
  27628. midpoint: function ( target ) {
  27629. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  27630. return this.getMidpoint( target );
  27631. },
  27632. normal: function ( target ) {
  27633. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  27634. return this.getNormal( target );
  27635. },
  27636. plane: function ( target ) {
  27637. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  27638. return this.getPlane( target );
  27639. }
  27640. } );
  27641. Object.assign( Triangle, {
  27642. barycoordFromPoint: function ( point, a, b, c, target ) {
  27643. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  27644. return Triangle.getBarycoord( point, a, b, c, target );
  27645. },
  27646. normal: function ( a, b, c, target ) {
  27647. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  27648. return Triangle.getNormal( a, b, c, target );
  27649. }
  27650. } );
  27651. Object.assign( Shape.prototype, {
  27652. extractAllPoints: function ( divisions ) {
  27653. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  27654. return this.extractPoints( divisions );
  27655. },
  27656. extrude: function ( options ) {
  27657. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  27658. return new ExtrudeGeometry( this, options );
  27659. },
  27660. makeGeometry: function ( options ) {
  27661. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  27662. return new ShapeGeometry( this, options );
  27663. }
  27664. } );
  27665. Object.assign( Vector2.prototype, {
  27666. fromAttribute: function ( attribute, index, offset ) {
  27667. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  27668. return this.fromBufferAttribute( attribute, index, offset );
  27669. },
  27670. distanceToManhattan: function ( v ) {
  27671. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  27672. return this.manhattanDistanceTo( v );
  27673. },
  27674. lengthManhattan: function () {
  27675. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  27676. return this.manhattanLength();
  27677. }
  27678. } );
  27679. Object.assign( Vector3.prototype, {
  27680. setEulerFromRotationMatrix: function () {
  27681. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  27682. },
  27683. setEulerFromQuaternion: function () {
  27684. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  27685. },
  27686. getPositionFromMatrix: function ( m ) {
  27687. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  27688. return this.setFromMatrixPosition( m );
  27689. },
  27690. getScaleFromMatrix: function ( m ) {
  27691. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  27692. return this.setFromMatrixScale( m );
  27693. },
  27694. getColumnFromMatrix: function ( index, matrix ) {
  27695. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  27696. return this.setFromMatrixColumn( matrix, index );
  27697. },
  27698. applyProjection: function ( m ) {
  27699. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  27700. return this.applyMatrix4( m );
  27701. },
  27702. fromAttribute: function ( attribute, index, offset ) {
  27703. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  27704. return this.fromBufferAttribute( attribute, index, offset );
  27705. },
  27706. distanceToManhattan: function ( v ) {
  27707. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  27708. return this.manhattanDistanceTo( v );
  27709. },
  27710. lengthManhattan: function () {
  27711. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  27712. return this.manhattanLength();
  27713. }
  27714. } );
  27715. Object.assign( Vector4.prototype, {
  27716. fromAttribute: function ( attribute, index, offset ) {
  27717. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  27718. return this.fromBufferAttribute( attribute, index, offset );
  27719. },
  27720. lengthManhattan: function () {
  27721. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  27722. return this.manhattanLength();
  27723. }
  27724. } );
  27725. //
  27726. Object.assign( Geometry.prototype, {
  27727. computeTangents: function () {
  27728. console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
  27729. },
  27730. computeLineDistances: function () {
  27731. console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
  27732. }
  27733. } );
  27734. Object.assign( Object3D.prototype, {
  27735. getChildByName: function ( name ) {
  27736. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  27737. return this.getObjectByName( name );
  27738. },
  27739. renderDepth: function () {
  27740. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  27741. },
  27742. translate: function ( distance, axis ) {
  27743. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  27744. return this.translateOnAxis( axis, distance );
  27745. },
  27746. getWorldRotation: function () {
  27747. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  27748. }
  27749. } );
  27750. Object.defineProperties( Object3D.prototype, {
  27751. eulerOrder: {
  27752. get: function () {
  27753. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  27754. return this.rotation.order;
  27755. },
  27756. set: function ( value ) {
  27757. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  27758. this.rotation.order = value;
  27759. }
  27760. },
  27761. useQuaternion: {
  27762. get: function () {
  27763. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  27764. },
  27765. set: function () {
  27766. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  27767. }
  27768. }
  27769. } );
  27770. Object.defineProperties( LOD.prototype, {
  27771. objects: {
  27772. get: function () {
  27773. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  27774. return this.levels;
  27775. }
  27776. }
  27777. } );
  27778. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  27779. get: function () {
  27780. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  27781. },
  27782. set: function () {
  27783. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  27784. }
  27785. } );
  27786. SkinnedMesh.prototype.initBones = function () {
  27787. console.error( 'THREE.SkinnedMesh: initBones() has been removed.' );
  27788. };
  27789. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  27790. get: function () {
  27791. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  27792. return this.arcLengthDivisions;
  27793. },
  27794. set: function ( value ) {
  27795. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  27796. this.arcLengthDivisions = value;
  27797. }
  27798. } );
  27799. //
  27800. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  27801. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  27802. "Use .setFocalLength and .filmGauge for a photographic setup." );
  27803. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  27804. this.setFocalLength( focalLength );
  27805. };
  27806. //
  27807. Object.defineProperties( Light.prototype, {
  27808. onlyShadow: {
  27809. set: function () {
  27810. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  27811. }
  27812. },
  27813. shadowCameraFov: {
  27814. set: function ( value ) {
  27815. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  27816. this.shadow.camera.fov = value;
  27817. }
  27818. },
  27819. shadowCameraLeft: {
  27820. set: function ( value ) {
  27821. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  27822. this.shadow.camera.left = value;
  27823. }
  27824. },
  27825. shadowCameraRight: {
  27826. set: function ( value ) {
  27827. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  27828. this.shadow.camera.right = value;
  27829. }
  27830. },
  27831. shadowCameraTop: {
  27832. set: function ( value ) {
  27833. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  27834. this.shadow.camera.top = value;
  27835. }
  27836. },
  27837. shadowCameraBottom: {
  27838. set: function ( value ) {
  27839. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  27840. this.shadow.camera.bottom = value;
  27841. }
  27842. },
  27843. shadowCameraNear: {
  27844. set: function ( value ) {
  27845. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  27846. this.shadow.camera.near = value;
  27847. }
  27848. },
  27849. shadowCameraFar: {
  27850. set: function ( value ) {
  27851. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  27852. this.shadow.camera.far = value;
  27853. }
  27854. },
  27855. shadowCameraVisible: {
  27856. set: function () {
  27857. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  27858. }
  27859. },
  27860. shadowBias: {
  27861. set: function ( value ) {
  27862. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  27863. this.shadow.bias = value;
  27864. }
  27865. },
  27866. shadowDarkness: {
  27867. set: function () {
  27868. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  27869. }
  27870. },
  27871. shadowMapWidth: {
  27872. set: function ( value ) {
  27873. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  27874. this.shadow.mapSize.width = value;
  27875. }
  27876. },
  27877. shadowMapHeight: {
  27878. set: function ( value ) {
  27879. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  27880. this.shadow.mapSize.height = value;
  27881. }
  27882. }
  27883. } );
  27884. //
  27885. Object.defineProperties( BufferAttribute.prototype, {
  27886. length: {
  27887. get: function () {
  27888. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  27889. return this.array.length;
  27890. }
  27891. },
  27892. copyIndicesArray: function ( /* indices */ ) {
  27893. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  27894. }
  27895. } );
  27896. Object.assign( BufferGeometry.prototype, {
  27897. addIndex: function ( index ) {
  27898. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  27899. this.setIndex( index );
  27900. },
  27901. addDrawCall: function ( start, count, indexOffset ) {
  27902. if ( indexOffset !== undefined ) {
  27903. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  27904. }
  27905. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  27906. this.addGroup( start, count );
  27907. },
  27908. clearDrawCalls: function () {
  27909. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  27910. this.clearGroups();
  27911. },
  27912. computeTangents: function () {
  27913. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  27914. },
  27915. computeOffsets: function () {
  27916. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  27917. }
  27918. } );
  27919. Object.defineProperties( BufferGeometry.prototype, {
  27920. drawcalls: {
  27921. get: function () {
  27922. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  27923. return this.groups;
  27924. }
  27925. },
  27926. offsets: {
  27927. get: function () {
  27928. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  27929. return this.groups;
  27930. }
  27931. }
  27932. } );
  27933. //
  27934. Object.assign( ExtrudeBufferGeometry.prototype, {
  27935. getArrays: function () {
  27936. console.error( 'THREE.ExtrudeBufferGeometry: .getArrays() has been removed.' );
  27937. },
  27938. addShapeList: function () {
  27939. console.error( 'THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.' );
  27940. },
  27941. addShape: function () {
  27942. console.error( 'THREE.ExtrudeBufferGeometry: .addShape() has been removed.' );
  27943. }
  27944. } );
  27945. //
  27946. Object.defineProperties( Uniform.prototype, {
  27947. dynamic: {
  27948. set: function () {
  27949. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  27950. }
  27951. },
  27952. onUpdate: {
  27953. value: function () {
  27954. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  27955. return this;
  27956. }
  27957. }
  27958. } );
  27959. //
  27960. Object.defineProperties( Material.prototype, {
  27961. wrapAround: {
  27962. get: function () {
  27963. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  27964. },
  27965. set: function () {
  27966. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  27967. }
  27968. },
  27969. overdraw: {
  27970. get: function () {
  27971. console.warn( 'THREE.Material: .overdraw has been removed.' );
  27972. },
  27973. set: function () {
  27974. console.warn( 'THREE.Material: .overdraw has been removed.' );
  27975. }
  27976. },
  27977. wrapRGB: {
  27978. get: function () {
  27979. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  27980. return new Color();
  27981. }
  27982. },
  27983. shading: {
  27984. get: function () {
  27985. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  27986. },
  27987. set: function ( value ) {
  27988. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  27989. this.flatShading = ( value === FlatShading );
  27990. }
  27991. }
  27992. } );
  27993. Object.defineProperties( MeshPhongMaterial.prototype, {
  27994. metal: {
  27995. get: function () {
  27996. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  27997. return false;
  27998. },
  27999. set: function () {
  28000. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  28001. }
  28002. }
  28003. } );
  28004. Object.defineProperties( ShaderMaterial.prototype, {
  28005. derivatives: {
  28006. get: function () {
  28007. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28008. return this.extensions.derivatives;
  28009. },
  28010. set: function ( value ) {
  28011. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28012. this.extensions.derivatives = value;
  28013. }
  28014. }
  28015. } );
  28016. //
  28017. Object.assign( WebGLRenderer.prototype, {
  28018. clearTarget: function ( renderTarget, color, depth, stencil ) {
  28019. console.warn( 'THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.' );
  28020. this.setRenderTarget( renderTarget );
  28021. this.clear( color, depth, stencil );
  28022. },
  28023. animate: function ( callback ) {
  28024. console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' );
  28025. this.setAnimationLoop( callback );
  28026. },
  28027. getCurrentRenderTarget: function () {
  28028. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  28029. return this.getRenderTarget();
  28030. },
  28031. getMaxAnisotropy: function () {
  28032. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  28033. return this.capabilities.getMaxAnisotropy();
  28034. },
  28035. getPrecision: function () {
  28036. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  28037. return this.capabilities.precision;
  28038. },
  28039. resetGLState: function () {
  28040. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  28041. return this.state.reset();
  28042. },
  28043. supportsFloatTextures: function () {
  28044. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  28045. return this.extensions.get( 'OES_texture_float' );
  28046. },
  28047. supportsHalfFloatTextures: function () {
  28048. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  28049. return this.extensions.get( 'OES_texture_half_float' );
  28050. },
  28051. supportsStandardDerivatives: function () {
  28052. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  28053. return this.extensions.get( 'OES_standard_derivatives' );
  28054. },
  28055. supportsCompressedTextureS3TC: function () {
  28056. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  28057. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  28058. },
  28059. supportsCompressedTexturePVRTC: function () {
  28060. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  28061. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  28062. },
  28063. supportsBlendMinMax: function () {
  28064. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  28065. return this.extensions.get( 'EXT_blend_minmax' );
  28066. },
  28067. supportsVertexTextures: function () {
  28068. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  28069. return this.capabilities.vertexTextures;
  28070. },
  28071. supportsInstancedArrays: function () {
  28072. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  28073. return this.extensions.get( 'ANGLE_instanced_arrays' );
  28074. },
  28075. enableScissorTest: function ( boolean ) {
  28076. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  28077. this.setScissorTest( boolean );
  28078. },
  28079. initMaterial: function () {
  28080. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  28081. },
  28082. addPrePlugin: function () {
  28083. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  28084. },
  28085. addPostPlugin: function () {
  28086. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  28087. },
  28088. updateShadowMap: function () {
  28089. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  28090. },
  28091. setFaceCulling: function () {
  28092. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  28093. }
  28094. } );
  28095. Object.defineProperties( WebGLRenderer.prototype, {
  28096. shadowMapEnabled: {
  28097. get: function () {
  28098. return this.shadowMap.enabled;
  28099. },
  28100. set: function ( value ) {
  28101. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  28102. this.shadowMap.enabled = value;
  28103. }
  28104. },
  28105. shadowMapType: {
  28106. get: function () {
  28107. return this.shadowMap.type;
  28108. },
  28109. set: function ( value ) {
  28110. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  28111. this.shadowMap.type = value;
  28112. }
  28113. },
  28114. shadowMapCullFace: {
  28115. get: function () {
  28116. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  28117. return undefined;
  28118. },
  28119. set: function ( /* value */ ) {
  28120. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  28121. }
  28122. }
  28123. } );
  28124. Object.defineProperties( WebGLShadowMap.prototype, {
  28125. cullFace: {
  28126. get: function () {
  28127. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  28128. return undefined;
  28129. },
  28130. set: function ( /* cullFace */ ) {
  28131. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  28132. }
  28133. },
  28134. renderReverseSided: {
  28135. get: function () {
  28136. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  28137. return undefined;
  28138. },
  28139. set: function () {
  28140. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  28141. }
  28142. },
  28143. renderSingleSided: {
  28144. get: function () {
  28145. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  28146. return undefined;
  28147. },
  28148. set: function () {
  28149. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  28150. }
  28151. }
  28152. } );
  28153. //
  28154. Object.defineProperties( WebGLRenderTarget.prototype, {
  28155. wrapS: {
  28156. get: function () {
  28157. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  28158. return this.texture.wrapS;
  28159. },
  28160. set: function ( value ) {
  28161. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  28162. this.texture.wrapS = value;
  28163. }
  28164. },
  28165. wrapT: {
  28166. get: function () {
  28167. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  28168. return this.texture.wrapT;
  28169. },
  28170. set: function ( value ) {
  28171. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  28172. this.texture.wrapT = value;
  28173. }
  28174. },
  28175. magFilter: {
  28176. get: function () {
  28177. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  28178. return this.texture.magFilter;
  28179. },
  28180. set: function ( value ) {
  28181. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  28182. this.texture.magFilter = value;
  28183. }
  28184. },
  28185. minFilter: {
  28186. get: function () {
  28187. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  28188. return this.texture.minFilter;
  28189. },
  28190. set: function ( value ) {
  28191. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  28192. this.texture.minFilter = value;
  28193. }
  28194. },
  28195. anisotropy: {
  28196. get: function () {
  28197. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  28198. return this.texture.anisotropy;
  28199. },
  28200. set: function ( value ) {
  28201. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  28202. this.texture.anisotropy = value;
  28203. }
  28204. },
  28205. offset: {
  28206. get: function () {
  28207. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  28208. return this.texture.offset;
  28209. },
  28210. set: function ( value ) {
  28211. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  28212. this.texture.offset = value;
  28213. }
  28214. },
  28215. repeat: {
  28216. get: function () {
  28217. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  28218. return this.texture.repeat;
  28219. },
  28220. set: function ( value ) {
  28221. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  28222. this.texture.repeat = value;
  28223. }
  28224. },
  28225. format: {
  28226. get: function () {
  28227. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  28228. return this.texture.format;
  28229. },
  28230. set: function ( value ) {
  28231. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  28232. this.texture.format = value;
  28233. }
  28234. },
  28235. type: {
  28236. get: function () {
  28237. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  28238. return this.texture.type;
  28239. },
  28240. set: function ( value ) {
  28241. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  28242. this.texture.type = value;
  28243. }
  28244. },
  28245. generateMipmaps: {
  28246. get: function () {
  28247. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  28248. return this.texture.generateMipmaps;
  28249. },
  28250. set: function ( value ) {
  28251. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  28252. this.texture.generateMipmaps = value;
  28253. }
  28254. }
  28255. } );
  28256. //
  28257. Object.defineProperties( WebVRManager.prototype, {
  28258. standing: {
  28259. set: function ( /* value */ ) {
  28260. console.warn( 'THREE.WebVRManager: .standing has been removed.' );
  28261. }
  28262. },
  28263. userHeight: {
  28264. set: function ( /* value */ ) {
  28265. console.warn( 'THREE.WebVRManager: .userHeight has been removed.' );
  28266. }
  28267. }
  28268. } );
  28269. //
  28270. Audio.prototype.load = function ( file ) {
  28271. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  28272. var scope = this;
  28273. var audioLoader = new AudioLoader();
  28274. audioLoader.load( file, function ( buffer ) {
  28275. scope.setBuffer( buffer );
  28276. } );
  28277. return this;
  28278. };
  28279. AudioAnalyser.prototype.getData = function () {
  28280. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  28281. return this.getFrequencyData();
  28282. };
  28283. //
  28284. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  28285. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  28286. return this.update( renderer, scene );
  28287. };
  28288. //
  28289. var GeometryUtils = {
  28290. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  28291. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  28292. var matrix;
  28293. if ( geometry2.isMesh ) {
  28294. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  28295. matrix = geometry2.matrix;
  28296. geometry2 = geometry2.geometry;
  28297. }
  28298. geometry1.merge( geometry2, matrix, materialIndexOffset );
  28299. },
  28300. center: function ( geometry ) {
  28301. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  28302. return geometry.center();
  28303. }
  28304. };
  28305. ImageUtils.crossOrigin = undefined;
  28306. ImageUtils.loadTexture = function ( url, mapping, onLoad, onError ) {
  28307. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  28308. var loader = new TextureLoader();
  28309. loader.setCrossOrigin( this.crossOrigin );
  28310. var texture = loader.load( url, onLoad, undefined, onError );
  28311. if ( mapping ) texture.mapping = mapping;
  28312. return texture;
  28313. };
  28314. ImageUtils.loadTextureCube = function ( urls, mapping, onLoad, onError ) {
  28315. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  28316. var loader = new CubeTextureLoader();
  28317. loader.setCrossOrigin( this.crossOrigin );
  28318. var texture = loader.load( urls, onLoad, undefined, onError );
  28319. if ( mapping ) texture.mapping = mapping;
  28320. return texture;
  28321. };
  28322. ImageUtils.loadCompressedTexture = function () {
  28323. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  28324. };
  28325. ImageUtils.loadCompressedTextureCube = function () {
  28326. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  28327. };
  28328. //
  28329. function Projector() {
  28330. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  28331. this.projectVector = function ( vector, camera ) {
  28332. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  28333. vector.project( camera );
  28334. };
  28335. this.unprojectVector = function ( vector, camera ) {
  28336. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  28337. vector.unproject( camera );
  28338. };
  28339. this.pickingRay = function () {
  28340. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  28341. };
  28342. }
  28343. //
  28344. function CanvasRenderer() {
  28345. console.error( 'THREE.CanvasRenderer has been removed' );
  28346. }
  28347. //
  28348. function JSONLoader() {
  28349. console.error( 'THREE.JSONLoader has been removed.' );
  28350. }
  28351. //
  28352. var SceneUtils = {
  28353. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  28354. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  28355. },
  28356. detach: function ( /* child, parent, scene */ ) {
  28357. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  28358. },
  28359. attach: function ( /* child, scene, parent */ ) {
  28360. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  28361. }
  28362. };
  28363. //
  28364. function LensFlare() {
  28365. console.error( 'THREE.LensFlare has been moved to /examples/js/objects/Lensflare.js' );
  28366. }
  28367. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  28368. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  28369. exports.WebGLRenderTarget = WebGLRenderTarget;
  28370. exports.WebGLRenderer = WebGLRenderer;
  28371. exports.ShaderLib = ShaderLib;
  28372. exports.UniformsLib = UniformsLib;
  28373. exports.UniformsUtils = UniformsUtils;
  28374. exports.ShaderChunk = ShaderChunk;
  28375. exports.FogExp2 = FogExp2;
  28376. exports.Fog = Fog;
  28377. exports.Scene = Scene;
  28378. exports.Sprite = Sprite;
  28379. exports.LOD = LOD;
  28380. exports.SkinnedMesh = SkinnedMesh;
  28381. exports.Skeleton = Skeleton;
  28382. exports.Bone = Bone;
  28383. exports.Mesh = Mesh;
  28384. exports.LineSegments = LineSegments;
  28385. exports.LineLoop = LineLoop;
  28386. exports.Line = Line;
  28387. exports.Points = Points;
  28388. exports.Group = Group;
  28389. exports.VideoTexture = VideoTexture;
  28390. exports.DataTexture = DataTexture;
  28391. exports.DataTexture3D = DataTexture3D;
  28392. exports.CompressedTexture = CompressedTexture;
  28393. exports.CubeTexture = CubeTexture;
  28394. exports.CanvasTexture = CanvasTexture;
  28395. exports.DepthTexture = DepthTexture;
  28396. exports.Texture = Texture;
  28397. exports.AnimationLoader = AnimationLoader;
  28398. exports.CompressedTextureLoader = CompressedTextureLoader;
  28399. exports.DataTextureLoader = DataTextureLoader;
  28400. exports.CubeTextureLoader = CubeTextureLoader;
  28401. exports.TextureLoader = TextureLoader;
  28402. exports.ObjectLoader = ObjectLoader;
  28403. exports.MaterialLoader = MaterialLoader;
  28404. exports.BufferGeometryLoader = BufferGeometryLoader;
  28405. exports.DefaultLoadingManager = DefaultLoadingManager;
  28406. exports.LoadingManager = LoadingManager;
  28407. exports.ImageLoader = ImageLoader;
  28408. exports.ImageBitmapLoader = ImageBitmapLoader;
  28409. exports.FontLoader = FontLoader;
  28410. exports.FileLoader = FileLoader;
  28411. exports.Loader = Loader;
  28412. exports.LoaderUtils = LoaderUtils;
  28413. exports.Cache = Cache;
  28414. exports.AudioLoader = AudioLoader;
  28415. exports.SpotLightShadow = SpotLightShadow;
  28416. exports.SpotLight = SpotLight;
  28417. exports.PointLight = PointLight;
  28418. exports.RectAreaLight = RectAreaLight;
  28419. exports.HemisphereLight = HemisphereLight;
  28420. exports.DirectionalLightShadow = DirectionalLightShadow;
  28421. exports.DirectionalLight = DirectionalLight;
  28422. exports.AmbientLight = AmbientLight;
  28423. exports.LightShadow = LightShadow;
  28424. exports.Light = Light;
  28425. exports.StereoCamera = StereoCamera;
  28426. exports.PerspectiveCamera = PerspectiveCamera;
  28427. exports.OrthographicCamera = OrthographicCamera;
  28428. exports.CubeCamera = CubeCamera;
  28429. exports.ArrayCamera = ArrayCamera;
  28430. exports.Camera = Camera;
  28431. exports.AudioListener = AudioListener;
  28432. exports.PositionalAudio = PositionalAudio;
  28433. exports.AudioContext = AudioContext;
  28434. exports.AudioAnalyser = AudioAnalyser;
  28435. exports.Audio = Audio;
  28436. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  28437. exports.StringKeyframeTrack = StringKeyframeTrack;
  28438. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  28439. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  28440. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  28441. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  28442. exports.PropertyMixer = PropertyMixer;
  28443. exports.PropertyBinding = PropertyBinding;
  28444. exports.KeyframeTrack = KeyframeTrack;
  28445. exports.AnimationUtils = AnimationUtils;
  28446. exports.AnimationObjectGroup = AnimationObjectGroup;
  28447. exports.AnimationMixer = AnimationMixer;
  28448. exports.AnimationClip = AnimationClip;
  28449. exports.Uniform = Uniform;
  28450. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  28451. exports.BufferGeometry = BufferGeometry;
  28452. exports.Geometry = Geometry;
  28453. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  28454. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  28455. exports.InterleavedBuffer = InterleavedBuffer;
  28456. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  28457. exports.Face3 = Face3;
  28458. exports.Object3D = Object3D;
  28459. exports.Raycaster = Raycaster;
  28460. exports.Layers = Layers;
  28461. exports.EventDispatcher = EventDispatcher;
  28462. exports.Clock = Clock;
  28463. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  28464. exports.LinearInterpolant = LinearInterpolant;
  28465. exports.DiscreteInterpolant = DiscreteInterpolant;
  28466. exports.CubicInterpolant = CubicInterpolant;
  28467. exports.Interpolant = Interpolant;
  28468. exports.Triangle = Triangle;
  28469. exports.Math = _Math;
  28470. exports.Spherical = Spherical;
  28471. exports.Cylindrical = Cylindrical;
  28472. exports.Plane = Plane;
  28473. exports.Frustum = Frustum;
  28474. exports.Sphere = Sphere;
  28475. exports.Ray = Ray;
  28476. exports.Matrix4 = Matrix4;
  28477. exports.Matrix3 = Matrix3;
  28478. exports.Box3 = Box3;
  28479. exports.Box2 = Box2;
  28480. exports.Line3 = Line3;
  28481. exports.Euler = Euler;
  28482. exports.Vector4 = Vector4;
  28483. exports.Vector3 = Vector3;
  28484. exports.Vector2 = Vector2;
  28485. exports.Quaternion = Quaternion;
  28486. exports.Color = Color;
  28487. exports.ImmediateRenderObject = ImmediateRenderObject;
  28488. exports.VertexNormalsHelper = VertexNormalsHelper;
  28489. exports.SpotLightHelper = SpotLightHelper;
  28490. exports.SkeletonHelper = SkeletonHelper;
  28491. exports.PointLightHelper = PointLightHelper;
  28492. exports.RectAreaLightHelper = RectAreaLightHelper;
  28493. exports.HemisphereLightHelper = HemisphereLightHelper;
  28494. exports.GridHelper = GridHelper;
  28495. exports.PolarGridHelper = PolarGridHelper;
  28496. exports.FaceNormalsHelper = FaceNormalsHelper;
  28497. exports.DirectionalLightHelper = DirectionalLightHelper;
  28498. exports.CameraHelper = CameraHelper;
  28499. exports.BoxHelper = BoxHelper;
  28500. exports.Box3Helper = Box3Helper;
  28501. exports.PlaneHelper = PlaneHelper;
  28502. exports.ArrowHelper = ArrowHelper;
  28503. exports.AxesHelper = AxesHelper;
  28504. exports.Shape = Shape;
  28505. exports.Path = Path;
  28506. exports.ShapePath = ShapePath;
  28507. exports.Font = Font;
  28508. exports.CurvePath = CurvePath;
  28509. exports.Curve = Curve;
  28510. exports.ImageUtils = ImageUtils;
  28511. exports.ShapeUtils = ShapeUtils;
  28512. exports.WebGLUtils = WebGLUtils;
  28513. exports.WireframeGeometry = WireframeGeometry;
  28514. exports.ParametricGeometry = ParametricGeometry;
  28515. exports.ParametricBufferGeometry = ParametricBufferGeometry;
  28516. exports.TetrahedronGeometry = TetrahedronGeometry;
  28517. exports.TetrahedronBufferGeometry = TetrahedronBufferGeometry;
  28518. exports.OctahedronGeometry = OctahedronGeometry;
  28519. exports.OctahedronBufferGeometry = OctahedronBufferGeometry;
  28520. exports.IcosahedronGeometry = IcosahedronGeometry;
  28521. exports.IcosahedronBufferGeometry = IcosahedronBufferGeometry;
  28522. exports.DodecahedronGeometry = DodecahedronGeometry;
  28523. exports.DodecahedronBufferGeometry = DodecahedronBufferGeometry;
  28524. exports.PolyhedronGeometry = PolyhedronGeometry;
  28525. exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
  28526. exports.TubeGeometry = TubeGeometry;
  28527. exports.TubeBufferGeometry = TubeBufferGeometry;
  28528. exports.TorusKnotGeometry = TorusKnotGeometry;
  28529. exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
  28530. exports.TorusGeometry = TorusGeometry;
  28531. exports.TorusBufferGeometry = TorusBufferGeometry;
  28532. exports.TextGeometry = TextGeometry;
  28533. exports.TextBufferGeometry = TextBufferGeometry;
  28534. exports.SphereGeometry = SphereGeometry;
  28535. exports.SphereBufferGeometry = SphereBufferGeometry;
  28536. exports.RingGeometry = RingGeometry;
  28537. exports.RingBufferGeometry = RingBufferGeometry;
  28538. exports.PlaneGeometry = PlaneGeometry;
  28539. exports.PlaneBufferGeometry = PlaneBufferGeometry;
  28540. exports.LatheGeometry = LatheGeometry;
  28541. exports.LatheBufferGeometry = LatheBufferGeometry;
  28542. exports.ShapeGeometry = ShapeGeometry;
  28543. exports.ShapeBufferGeometry = ShapeBufferGeometry;
  28544. exports.ExtrudeGeometry = ExtrudeGeometry;
  28545. exports.ExtrudeBufferGeometry = ExtrudeBufferGeometry;
  28546. exports.EdgesGeometry = EdgesGeometry;
  28547. exports.ConeGeometry = ConeGeometry;
  28548. exports.ConeBufferGeometry = ConeBufferGeometry;
  28549. exports.CylinderGeometry = CylinderGeometry;
  28550. exports.CylinderBufferGeometry = CylinderBufferGeometry;
  28551. exports.CircleGeometry = CircleGeometry;
  28552. exports.CircleBufferGeometry = CircleBufferGeometry;
  28553. exports.BoxGeometry = BoxGeometry;
  28554. exports.BoxBufferGeometry = BoxBufferGeometry;
  28555. exports.ShadowMaterial = ShadowMaterial;
  28556. exports.SpriteMaterial = SpriteMaterial;
  28557. exports.RawShaderMaterial = RawShaderMaterial;
  28558. exports.ShaderMaterial = ShaderMaterial;
  28559. exports.PointsMaterial = PointsMaterial;
  28560. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  28561. exports.MeshStandardMaterial = MeshStandardMaterial;
  28562. exports.MeshPhongMaterial = MeshPhongMaterial;
  28563. exports.MeshToonMaterial = MeshToonMaterial;
  28564. exports.MeshNormalMaterial = MeshNormalMaterial;
  28565. exports.MeshLambertMaterial = MeshLambertMaterial;
  28566. exports.MeshDepthMaterial = MeshDepthMaterial;
  28567. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  28568. exports.MeshBasicMaterial = MeshBasicMaterial;
  28569. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  28570. exports.LineDashedMaterial = LineDashedMaterial;
  28571. exports.LineBasicMaterial = LineBasicMaterial;
  28572. exports.Material = Material;
  28573. exports.Float64BufferAttribute = Float64BufferAttribute;
  28574. exports.Float32BufferAttribute = Float32BufferAttribute;
  28575. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  28576. exports.Int32BufferAttribute = Int32BufferAttribute;
  28577. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  28578. exports.Int16BufferAttribute = Int16BufferAttribute;
  28579. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  28580. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  28581. exports.Int8BufferAttribute = Int8BufferAttribute;
  28582. exports.BufferAttribute = BufferAttribute;
  28583. exports.ArcCurve = ArcCurve;
  28584. exports.CatmullRomCurve3 = CatmullRomCurve3;
  28585. exports.CubicBezierCurve = CubicBezierCurve;
  28586. exports.CubicBezierCurve3 = CubicBezierCurve3;
  28587. exports.EllipseCurve = EllipseCurve;
  28588. exports.LineCurve = LineCurve;
  28589. exports.LineCurve3 = LineCurve3;
  28590. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  28591. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  28592. exports.SplineCurve = SplineCurve;
  28593. exports.REVISION = REVISION;
  28594. exports.MOUSE = MOUSE;
  28595. exports.CullFaceNone = CullFaceNone;
  28596. exports.CullFaceBack = CullFaceBack;
  28597. exports.CullFaceFront = CullFaceFront;
  28598. exports.CullFaceFrontBack = CullFaceFrontBack;
  28599. exports.FrontFaceDirectionCW = FrontFaceDirectionCW;
  28600. exports.FrontFaceDirectionCCW = FrontFaceDirectionCCW;
  28601. exports.BasicShadowMap = BasicShadowMap;
  28602. exports.PCFShadowMap = PCFShadowMap;
  28603. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  28604. exports.FrontSide = FrontSide;
  28605. exports.BackSide = BackSide;
  28606. exports.DoubleSide = DoubleSide;
  28607. exports.FlatShading = FlatShading;
  28608. exports.SmoothShading = SmoothShading;
  28609. exports.NoColors = NoColors;
  28610. exports.FaceColors = FaceColors;
  28611. exports.VertexColors = VertexColors;
  28612. exports.NoBlending = NoBlending;
  28613. exports.NormalBlending = NormalBlending;
  28614. exports.AdditiveBlending = AdditiveBlending;
  28615. exports.SubtractiveBlending = SubtractiveBlending;
  28616. exports.MultiplyBlending = MultiplyBlending;
  28617. exports.CustomBlending = CustomBlending;
  28618. exports.AddEquation = AddEquation;
  28619. exports.SubtractEquation = SubtractEquation;
  28620. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  28621. exports.MinEquation = MinEquation;
  28622. exports.MaxEquation = MaxEquation;
  28623. exports.ZeroFactor = ZeroFactor;
  28624. exports.OneFactor = OneFactor;
  28625. exports.SrcColorFactor = SrcColorFactor;
  28626. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  28627. exports.SrcAlphaFactor = SrcAlphaFactor;
  28628. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  28629. exports.DstAlphaFactor = DstAlphaFactor;
  28630. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  28631. exports.DstColorFactor = DstColorFactor;
  28632. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  28633. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  28634. exports.NeverDepth = NeverDepth;
  28635. exports.AlwaysDepth = AlwaysDepth;
  28636. exports.LessDepth = LessDepth;
  28637. exports.LessEqualDepth = LessEqualDepth;
  28638. exports.EqualDepth = EqualDepth;
  28639. exports.GreaterEqualDepth = GreaterEqualDepth;
  28640. exports.GreaterDepth = GreaterDepth;
  28641. exports.NotEqualDepth = NotEqualDepth;
  28642. exports.MultiplyOperation = MultiplyOperation;
  28643. exports.MixOperation = MixOperation;
  28644. exports.AddOperation = AddOperation;
  28645. exports.NoToneMapping = NoToneMapping;
  28646. exports.LinearToneMapping = LinearToneMapping;
  28647. exports.ReinhardToneMapping = ReinhardToneMapping;
  28648. exports.Uncharted2ToneMapping = Uncharted2ToneMapping;
  28649. exports.CineonToneMapping = CineonToneMapping;
  28650. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  28651. exports.UVMapping = UVMapping;
  28652. exports.CubeReflectionMapping = CubeReflectionMapping;
  28653. exports.CubeRefractionMapping = CubeRefractionMapping;
  28654. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  28655. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  28656. exports.SphericalReflectionMapping = SphericalReflectionMapping;
  28657. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  28658. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  28659. exports.RepeatWrapping = RepeatWrapping;
  28660. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  28661. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  28662. exports.NearestFilter = NearestFilter;
  28663. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  28664. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  28665. exports.LinearFilter = LinearFilter;
  28666. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  28667. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  28668. exports.UnsignedByteType = UnsignedByteType;
  28669. exports.ByteType = ByteType;
  28670. exports.ShortType = ShortType;
  28671. exports.UnsignedShortType = UnsignedShortType;
  28672. exports.IntType = IntType;
  28673. exports.UnsignedIntType = UnsignedIntType;
  28674. exports.FloatType = FloatType;
  28675. exports.HalfFloatType = HalfFloatType;
  28676. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  28677. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  28678. exports.UnsignedShort565Type = UnsignedShort565Type;
  28679. exports.UnsignedInt248Type = UnsignedInt248Type;
  28680. exports.AlphaFormat = AlphaFormat;
  28681. exports.RGBFormat = RGBFormat;
  28682. exports.RGBAFormat = RGBAFormat;
  28683. exports.LuminanceFormat = LuminanceFormat;
  28684. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  28685. exports.RGBEFormat = RGBEFormat;
  28686. exports.DepthFormat = DepthFormat;
  28687. exports.DepthStencilFormat = DepthStencilFormat;
  28688. exports.RedFormat = RedFormat;
  28689. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  28690. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  28691. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  28692. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  28693. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  28694. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  28695. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  28696. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  28697. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  28698. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  28699. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  28700. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  28701. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  28702. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  28703. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  28704. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  28705. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  28706. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  28707. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  28708. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  28709. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  28710. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  28711. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  28712. exports.LoopOnce = LoopOnce;
  28713. exports.LoopRepeat = LoopRepeat;
  28714. exports.LoopPingPong = LoopPingPong;
  28715. exports.InterpolateDiscrete = InterpolateDiscrete;
  28716. exports.InterpolateLinear = InterpolateLinear;
  28717. exports.InterpolateSmooth = InterpolateSmooth;
  28718. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  28719. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  28720. exports.WrapAroundEnding = WrapAroundEnding;
  28721. exports.TrianglesDrawMode = TrianglesDrawMode;
  28722. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  28723. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  28724. exports.LinearEncoding = LinearEncoding;
  28725. exports.sRGBEncoding = sRGBEncoding;
  28726. exports.GammaEncoding = GammaEncoding;
  28727. exports.RGBEEncoding = RGBEEncoding;
  28728. exports.LogLuvEncoding = LogLuvEncoding;
  28729. exports.RGBM7Encoding = RGBM7Encoding;
  28730. exports.RGBM16Encoding = RGBM16Encoding;
  28731. exports.RGBDEncoding = RGBDEncoding;
  28732. exports.BasicDepthPacking = BasicDepthPacking;
  28733. exports.RGBADepthPacking = RGBADepthPacking;
  28734. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  28735. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  28736. exports.CubeGeometry = BoxGeometry;
  28737. exports.Face4 = Face4;
  28738. exports.LineStrip = LineStrip;
  28739. exports.LinePieces = LinePieces;
  28740. exports.MeshFaceMaterial = MeshFaceMaterial;
  28741. exports.MultiMaterial = MultiMaterial;
  28742. exports.PointCloud = PointCloud;
  28743. exports.Particle = Particle;
  28744. exports.ParticleSystem = ParticleSystem;
  28745. exports.PointCloudMaterial = PointCloudMaterial;
  28746. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  28747. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  28748. exports.Vertex = Vertex;
  28749. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  28750. exports.Int8Attribute = Int8Attribute;
  28751. exports.Uint8Attribute = Uint8Attribute;
  28752. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  28753. exports.Int16Attribute = Int16Attribute;
  28754. exports.Uint16Attribute = Uint16Attribute;
  28755. exports.Int32Attribute = Int32Attribute;
  28756. exports.Uint32Attribute = Uint32Attribute;
  28757. exports.Float32Attribute = Float32Attribute;
  28758. exports.Float64Attribute = Float64Attribute;
  28759. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  28760. exports.SplineCurve3 = SplineCurve3;
  28761. exports.Spline = Spline;
  28762. exports.AxisHelper = AxisHelper;
  28763. exports.BoundingBoxHelper = BoundingBoxHelper;
  28764. exports.EdgesHelper = EdgesHelper;
  28765. exports.WireframeHelper = WireframeHelper;
  28766. exports.XHRLoader = XHRLoader;
  28767. exports.BinaryTextureLoader = BinaryTextureLoader;
  28768. exports.GeometryUtils = GeometryUtils;
  28769. exports.Projector = Projector;
  28770. exports.CanvasRenderer = CanvasRenderer;
  28771. exports.JSONLoader = JSONLoader;
  28772. exports.SceneUtils = SceneUtils;
  28773. exports.LensFlare = LensFlare;
  28774. Object.defineProperty(exports, '__esModule', { value: true });
  28775. })));