three.js 1.0 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272
  1. /**
  2. * Copyright © 2010-2018 three.js authors
  3. * github: https://github.com/mrdoob/three.js
  4. * license: MIT License
  5. * version: 92
  6. */
  7. (function (global, factory) {
  8. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  9. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  10. (factory((global.THREE = {})));
  11. }(this, (function (exports) { 'use strict';
  12. // Polyfills
  13. if ( Number.EPSILON === undefined ) {
  14. Number.EPSILON = Math.pow( 2, - 52 );
  15. }
  16. if ( Number.isInteger === undefined ) {
  17. // Missing in IE
  18. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  19. Number.isInteger = function ( value ) {
  20. return typeof value === 'number' && isFinite( value ) && Math.floor( value ) === value;
  21. };
  22. }
  23. //
  24. if ( Math.sign === undefined ) {
  25. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  26. Math.sign = function ( x ) {
  27. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  28. };
  29. }
  30. if ( 'name' in Function.prototype === false ) {
  31. // Missing in IE
  32. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  33. Object.defineProperty( Function.prototype, 'name', {
  34. get: function () {
  35. return this.toString().match( /^\s*function\s*([^\(\s]*)/ )[ 1 ];
  36. }
  37. } );
  38. }
  39. if ( Object.assign === undefined ) {
  40. // Missing in IE
  41. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  42. ( function () {
  43. Object.assign = function ( target ) {
  44. if ( target === undefined || target === null ) {
  45. throw new TypeError( 'Cannot convert undefined or null to object' );
  46. }
  47. var output = Object( target );
  48. for ( var index = 1; index < arguments.length; index ++ ) {
  49. var source = arguments[ index ];
  50. if ( source !== undefined && source !== null ) {
  51. for ( var nextKey in source ) {
  52. if ( Object.prototype.hasOwnProperty.call( source, nextKey ) ) {
  53. output[ nextKey ] = source[ nextKey ];
  54. }
  55. }
  56. }
  57. }
  58. return output;
  59. };
  60. } )();
  61. }
  62. /**
  63. * https://github.com/mrdoob/eventdispatcher.js/
  64. */
  65. function EventDispatcher() {}
  66. Object.assign( EventDispatcher.prototype, {
  67. addEventListener: function ( type, listener ) {
  68. if ( this._listeners === undefined ) this._listeners = {};
  69. var listeners = this._listeners;
  70. if ( listeners[ type ] === undefined ) {
  71. listeners[ type ] = [];
  72. }
  73. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  74. listeners[ type ].push( listener );
  75. }
  76. },
  77. hasEventListener: function ( type, listener ) {
  78. if ( this._listeners === undefined ) return false;
  79. var listeners = this._listeners;
  80. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  81. },
  82. removeEventListener: function ( type, listener ) {
  83. if ( this._listeners === undefined ) return;
  84. var listeners = this._listeners;
  85. var listenerArray = listeners[ type ];
  86. if ( listenerArray !== undefined ) {
  87. var index = listenerArray.indexOf( listener );
  88. if ( index !== - 1 ) {
  89. listenerArray.splice( index, 1 );
  90. }
  91. }
  92. },
  93. dispatchEvent: function ( event ) {
  94. if ( this._listeners === undefined ) return;
  95. var listeners = this._listeners;
  96. var listenerArray = listeners[ event.type ];
  97. if ( listenerArray !== undefined ) {
  98. event.target = this;
  99. var array = listenerArray.slice( 0 );
  100. for ( var i = 0, l = array.length; i < l; i ++ ) {
  101. array[ i ].call( this, event );
  102. }
  103. }
  104. }
  105. } );
  106. var REVISION = '92';
  107. var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  108. var CullFaceNone = 0;
  109. var CullFaceBack = 1;
  110. var CullFaceFront = 2;
  111. var CullFaceFrontBack = 3;
  112. var FrontFaceDirectionCW = 0;
  113. var FrontFaceDirectionCCW = 1;
  114. var BasicShadowMap = 0;
  115. var PCFShadowMap = 1;
  116. var PCFSoftShadowMap = 2;
  117. var FrontSide = 0;
  118. var BackSide = 1;
  119. var DoubleSide = 2;
  120. var FlatShading = 1;
  121. var SmoothShading = 2;
  122. var NoColors = 0;
  123. var FaceColors = 1;
  124. var VertexColors = 2;
  125. var NoBlending = 0;
  126. var NormalBlending = 1;
  127. var AdditiveBlending = 2;
  128. var SubtractiveBlending = 3;
  129. var MultiplyBlending = 4;
  130. var CustomBlending = 5;
  131. var AddEquation = 100;
  132. var SubtractEquation = 101;
  133. var ReverseSubtractEquation = 102;
  134. var MinEquation = 103;
  135. var MaxEquation = 104;
  136. var ZeroFactor = 200;
  137. var OneFactor = 201;
  138. var SrcColorFactor = 202;
  139. var OneMinusSrcColorFactor = 203;
  140. var SrcAlphaFactor = 204;
  141. var OneMinusSrcAlphaFactor = 205;
  142. var DstAlphaFactor = 206;
  143. var OneMinusDstAlphaFactor = 207;
  144. var DstColorFactor = 208;
  145. var OneMinusDstColorFactor = 209;
  146. var SrcAlphaSaturateFactor = 210;
  147. var NeverDepth = 0;
  148. var AlwaysDepth = 1;
  149. var LessDepth = 2;
  150. var LessEqualDepth = 3;
  151. var EqualDepth = 4;
  152. var GreaterEqualDepth = 5;
  153. var GreaterDepth = 6;
  154. var NotEqualDepth = 7;
  155. var MultiplyOperation = 0;
  156. var MixOperation = 1;
  157. var AddOperation = 2;
  158. var NoToneMapping = 0;
  159. var LinearToneMapping = 1;
  160. var ReinhardToneMapping = 2;
  161. var Uncharted2ToneMapping = 3;
  162. var CineonToneMapping = 4;
  163. var UVMapping = 300;
  164. var CubeReflectionMapping = 301;
  165. var CubeRefractionMapping = 302;
  166. var EquirectangularReflectionMapping = 303;
  167. var EquirectangularRefractionMapping = 304;
  168. var SphericalReflectionMapping = 305;
  169. var CubeUVReflectionMapping = 306;
  170. var CubeUVRefractionMapping = 307;
  171. var RepeatWrapping = 1000;
  172. var ClampToEdgeWrapping = 1001;
  173. var MirroredRepeatWrapping = 1002;
  174. var NearestFilter = 1003;
  175. var NearestMipMapNearestFilter = 1004;
  176. var NearestMipMapLinearFilter = 1005;
  177. var LinearFilter = 1006;
  178. var LinearMipMapNearestFilter = 1007;
  179. var LinearMipMapLinearFilter = 1008;
  180. var UnsignedByteType = 1009;
  181. var ByteType = 1010;
  182. var ShortType = 1011;
  183. var UnsignedShortType = 1012;
  184. var IntType = 1013;
  185. var UnsignedIntType = 1014;
  186. var FloatType = 1015;
  187. var HalfFloatType = 1016;
  188. var UnsignedShort4444Type = 1017;
  189. var UnsignedShort5551Type = 1018;
  190. var UnsignedShort565Type = 1019;
  191. var UnsignedInt248Type = 1020;
  192. var AlphaFormat = 1021;
  193. var RGBFormat = 1022;
  194. var RGBAFormat = 1023;
  195. var LuminanceFormat = 1024;
  196. var LuminanceAlphaFormat = 1025;
  197. var RGBEFormat = RGBAFormat;
  198. var DepthFormat = 1026;
  199. var DepthStencilFormat = 1027;
  200. var RGB_S3TC_DXT1_Format = 33776;
  201. var RGBA_S3TC_DXT1_Format = 33777;
  202. var RGBA_S3TC_DXT3_Format = 33778;
  203. var RGBA_S3TC_DXT5_Format = 33779;
  204. var RGB_PVRTC_4BPPV1_Format = 35840;
  205. var RGB_PVRTC_2BPPV1_Format = 35841;
  206. var RGBA_PVRTC_4BPPV1_Format = 35842;
  207. var RGBA_PVRTC_2BPPV1_Format = 35843;
  208. var RGB_ETC1_Format = 36196;
  209. var RGBA_ASTC_4x4_Format = 37808;
  210. var RGBA_ASTC_5x4_Format = 37809;
  211. var RGBA_ASTC_5x5_Format = 37810;
  212. var RGBA_ASTC_6x5_Format = 37811;
  213. var RGBA_ASTC_6x6_Format = 37812;
  214. var RGBA_ASTC_8x5_Format = 37813;
  215. var RGBA_ASTC_8x6_Format = 37814;
  216. var RGBA_ASTC_8x8_Format = 37815;
  217. var RGBA_ASTC_10x5_Format = 37816;
  218. var RGBA_ASTC_10x6_Format = 37817;
  219. var RGBA_ASTC_10x8_Format = 37818;
  220. var RGBA_ASTC_10x10_Format = 37819;
  221. var RGBA_ASTC_12x10_Format = 37820;
  222. var RGBA_ASTC_12x12_Format = 37821;
  223. var LoopOnce = 2200;
  224. var LoopRepeat = 2201;
  225. var LoopPingPong = 2202;
  226. var InterpolateDiscrete = 2300;
  227. var InterpolateLinear = 2301;
  228. var InterpolateSmooth = 2302;
  229. var ZeroCurvatureEnding = 2400;
  230. var ZeroSlopeEnding = 2401;
  231. var WrapAroundEnding = 2402;
  232. var TrianglesDrawMode = 0;
  233. var TriangleStripDrawMode = 1;
  234. var TriangleFanDrawMode = 2;
  235. var LinearEncoding = 3000;
  236. var sRGBEncoding = 3001;
  237. var GammaEncoding = 3007;
  238. var RGBEEncoding = 3002;
  239. var LogLuvEncoding = 3003;
  240. var RGBM7Encoding = 3004;
  241. var RGBM16Encoding = 3005;
  242. var RGBDEncoding = 3006;
  243. var BasicDepthPacking = 3200;
  244. var RGBADepthPacking = 3201;
  245. /**
  246. * @author alteredq / http://alteredqualia.com/
  247. * @author mrdoob / http://mrdoob.com/
  248. */
  249. var _Math = {
  250. DEG2RAD: Math.PI / 180,
  251. RAD2DEG: 180 / Math.PI,
  252. generateUUID: ( function () {
  253. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  254. var lut = [];
  255. for ( var i = 0; i < 256; i ++ ) {
  256. lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
  257. }
  258. return function generateUUID() {
  259. var d0 = Math.random() * 0xffffffff | 0;
  260. var d1 = Math.random() * 0xffffffff | 0;
  261. var d2 = Math.random() * 0xffffffff | 0;
  262. var d3 = Math.random() * 0xffffffff | 0;
  263. var uuid = lut[ d0 & 0xff ] + lut[ d0 >> 8 & 0xff ] + lut[ d0 >> 16 & 0xff ] + lut[ d0 >> 24 & 0xff ] + '-' +
  264. lut[ d1 & 0xff ] + lut[ d1 >> 8 & 0xff ] + '-' + lut[ d1 >> 16 & 0x0f | 0x40 ] + lut[ d1 >> 24 & 0xff ] + '-' +
  265. lut[ d2 & 0x3f | 0x80 ] + lut[ d2 >> 8 & 0xff ] + '-' + lut[ d2 >> 16 & 0xff ] + lut[ d2 >> 24 & 0xff ] +
  266. lut[ d3 & 0xff ] + lut[ d3 >> 8 & 0xff ] + lut[ d3 >> 16 & 0xff ] + lut[ d3 >> 24 & 0xff ];
  267. // .toUpperCase() here flattens concatenated strings to save heap memory space.
  268. return uuid.toUpperCase();
  269. };
  270. } )(),
  271. clamp: function ( value, min, max ) {
  272. return Math.max( min, Math.min( max, value ) );
  273. },
  274. // compute euclidian modulo of m % n
  275. // https://en.wikipedia.org/wiki/Modulo_operation
  276. euclideanModulo: function ( n, m ) {
  277. return ( ( n % m ) + m ) % m;
  278. },
  279. // Linear mapping from range <a1, a2> to range <b1, b2>
  280. mapLinear: function ( x, a1, a2, b1, b2 ) {
  281. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  282. },
  283. // https://en.wikipedia.org/wiki/Linear_interpolation
  284. lerp: function ( x, y, t ) {
  285. return ( 1 - t ) * x + t * y;
  286. },
  287. // http://en.wikipedia.org/wiki/Smoothstep
  288. smoothstep: function ( x, min, max ) {
  289. if ( x <= min ) return 0;
  290. if ( x >= max ) return 1;
  291. x = ( x - min ) / ( max - min );
  292. return x * x * ( 3 - 2 * x );
  293. },
  294. smootherstep: function ( x, min, max ) {
  295. if ( x <= min ) return 0;
  296. if ( x >= max ) return 1;
  297. x = ( x - min ) / ( max - min );
  298. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  299. },
  300. // Random integer from <low, high> interval
  301. randInt: function ( low, high ) {
  302. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  303. },
  304. // Random float from <low, high> interval
  305. randFloat: function ( low, high ) {
  306. return low + Math.random() * ( high - low );
  307. },
  308. // Random float from <-range/2, range/2> interval
  309. randFloatSpread: function ( range ) {
  310. return range * ( 0.5 - Math.random() );
  311. },
  312. degToRad: function ( degrees ) {
  313. return degrees * _Math.DEG2RAD;
  314. },
  315. radToDeg: function ( radians ) {
  316. return radians * _Math.RAD2DEG;
  317. },
  318. isPowerOfTwo: function ( value ) {
  319. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  320. },
  321. ceilPowerOfTwo: function ( value ) {
  322. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  323. },
  324. floorPowerOfTwo: function ( value ) {
  325. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  326. }
  327. };
  328. /**
  329. * @author mrdoob / http://mrdoob.com/
  330. * @author philogb / http://blog.thejit.org/
  331. * @author egraether / http://egraether.com/
  332. * @author zz85 / http://www.lab4games.net/zz85/blog
  333. */
  334. function Vector2( x, y ) {
  335. this.x = x || 0;
  336. this.y = y || 0;
  337. }
  338. Object.defineProperties( Vector2.prototype, {
  339. "width": {
  340. get: function () {
  341. return this.x;
  342. },
  343. set: function ( value ) {
  344. this.x = value;
  345. }
  346. },
  347. "height": {
  348. get: function () {
  349. return this.y;
  350. },
  351. set: function ( value ) {
  352. this.y = value;
  353. }
  354. }
  355. } );
  356. Object.assign( Vector2.prototype, {
  357. isVector2: true,
  358. set: function ( x, y ) {
  359. this.x = x;
  360. this.y = y;
  361. return this;
  362. },
  363. setScalar: function ( scalar ) {
  364. this.x = scalar;
  365. this.y = scalar;
  366. return this;
  367. },
  368. setX: function ( x ) {
  369. this.x = x;
  370. return this;
  371. },
  372. setY: function ( y ) {
  373. this.y = y;
  374. return this;
  375. },
  376. setComponent: function ( index, value ) {
  377. switch ( index ) {
  378. case 0: this.x = value; break;
  379. case 1: this.y = value; break;
  380. default: throw new Error( 'index is out of range: ' + index );
  381. }
  382. return this;
  383. },
  384. getComponent: function ( index ) {
  385. switch ( index ) {
  386. case 0: return this.x;
  387. case 1: return this.y;
  388. default: throw new Error( 'index is out of range: ' + index );
  389. }
  390. },
  391. clone: function () {
  392. return new this.constructor( this.x, this.y );
  393. },
  394. copy: function ( v ) {
  395. this.x = v.x;
  396. this.y = v.y;
  397. return this;
  398. },
  399. add: function ( v, w ) {
  400. if ( w !== undefined ) {
  401. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  402. return this.addVectors( v, w );
  403. }
  404. this.x += v.x;
  405. this.y += v.y;
  406. return this;
  407. },
  408. addScalar: function ( s ) {
  409. this.x += s;
  410. this.y += s;
  411. return this;
  412. },
  413. addVectors: function ( a, b ) {
  414. this.x = a.x + b.x;
  415. this.y = a.y + b.y;
  416. return this;
  417. },
  418. addScaledVector: function ( v, s ) {
  419. this.x += v.x * s;
  420. this.y += v.y * s;
  421. return this;
  422. },
  423. sub: function ( v, w ) {
  424. if ( w !== undefined ) {
  425. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  426. return this.subVectors( v, w );
  427. }
  428. this.x -= v.x;
  429. this.y -= v.y;
  430. return this;
  431. },
  432. subScalar: function ( s ) {
  433. this.x -= s;
  434. this.y -= s;
  435. return this;
  436. },
  437. subVectors: function ( a, b ) {
  438. this.x = a.x - b.x;
  439. this.y = a.y - b.y;
  440. return this;
  441. },
  442. multiply: function ( v ) {
  443. this.x *= v.x;
  444. this.y *= v.y;
  445. return this;
  446. },
  447. multiplyScalar: function ( scalar ) {
  448. this.x *= scalar;
  449. this.y *= scalar;
  450. return this;
  451. },
  452. divide: function ( v ) {
  453. this.x /= v.x;
  454. this.y /= v.y;
  455. return this;
  456. },
  457. divideScalar: function ( scalar ) {
  458. return this.multiplyScalar( 1 / scalar );
  459. },
  460. applyMatrix3: function ( m ) {
  461. var x = this.x, y = this.y;
  462. var e = m.elements;
  463. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  464. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  465. return this;
  466. },
  467. min: function ( v ) {
  468. this.x = Math.min( this.x, v.x );
  469. this.y = Math.min( this.y, v.y );
  470. return this;
  471. },
  472. max: function ( v ) {
  473. this.x = Math.max( this.x, v.x );
  474. this.y = Math.max( this.y, v.y );
  475. return this;
  476. },
  477. clamp: function ( min, max ) {
  478. // assumes min < max, componentwise
  479. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  480. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  481. return this;
  482. },
  483. clampScalar: function () {
  484. var min = new Vector2();
  485. var max = new Vector2();
  486. return function clampScalar( minVal, maxVal ) {
  487. min.set( minVal, minVal );
  488. max.set( maxVal, maxVal );
  489. return this.clamp( min, max );
  490. };
  491. }(),
  492. clampLength: function ( min, max ) {
  493. var length = this.length();
  494. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  495. },
  496. floor: function () {
  497. this.x = Math.floor( this.x );
  498. this.y = Math.floor( this.y );
  499. return this;
  500. },
  501. ceil: function () {
  502. this.x = Math.ceil( this.x );
  503. this.y = Math.ceil( this.y );
  504. return this;
  505. },
  506. round: function () {
  507. this.x = Math.round( this.x );
  508. this.y = Math.round( this.y );
  509. return this;
  510. },
  511. roundToZero: function () {
  512. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  513. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  514. return this;
  515. },
  516. negate: function () {
  517. this.x = - this.x;
  518. this.y = - this.y;
  519. return this;
  520. },
  521. dot: function ( v ) {
  522. return this.x * v.x + this.y * v.y;
  523. },
  524. lengthSq: function () {
  525. return this.x * this.x + this.y * this.y;
  526. },
  527. length: function () {
  528. return Math.sqrt( this.x * this.x + this.y * this.y );
  529. },
  530. manhattanLength: function () {
  531. return Math.abs( this.x ) + Math.abs( this.y );
  532. },
  533. normalize: function () {
  534. return this.divideScalar( this.length() || 1 );
  535. },
  536. angle: function () {
  537. // computes the angle in radians with respect to the positive x-axis
  538. var angle = Math.atan2( this.y, this.x );
  539. if ( angle < 0 ) angle += 2 * Math.PI;
  540. return angle;
  541. },
  542. distanceTo: function ( v ) {
  543. return Math.sqrt( this.distanceToSquared( v ) );
  544. },
  545. distanceToSquared: function ( v ) {
  546. var dx = this.x - v.x, dy = this.y - v.y;
  547. return dx * dx + dy * dy;
  548. },
  549. manhattanDistanceTo: function ( v ) {
  550. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  551. },
  552. setLength: function ( length ) {
  553. return this.normalize().multiplyScalar( length );
  554. },
  555. lerp: function ( v, alpha ) {
  556. this.x += ( v.x - this.x ) * alpha;
  557. this.y += ( v.y - this.y ) * alpha;
  558. return this;
  559. },
  560. lerpVectors: function ( v1, v2, alpha ) {
  561. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  562. },
  563. equals: function ( v ) {
  564. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  565. },
  566. fromArray: function ( array, offset ) {
  567. if ( offset === undefined ) offset = 0;
  568. this.x = array[ offset ];
  569. this.y = array[ offset + 1 ];
  570. return this;
  571. },
  572. toArray: function ( array, offset ) {
  573. if ( array === undefined ) array = [];
  574. if ( offset === undefined ) offset = 0;
  575. array[ offset ] = this.x;
  576. array[ offset + 1 ] = this.y;
  577. return array;
  578. },
  579. fromBufferAttribute: function ( attribute, index, offset ) {
  580. if ( offset !== undefined ) {
  581. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  582. }
  583. this.x = attribute.getX( index );
  584. this.y = attribute.getY( index );
  585. return this;
  586. },
  587. rotateAround: function ( center, angle ) {
  588. var c = Math.cos( angle ), s = Math.sin( angle );
  589. var x = this.x - center.x;
  590. var y = this.y - center.y;
  591. this.x = x * c - y * s + center.x;
  592. this.y = x * s + y * c + center.y;
  593. return this;
  594. }
  595. } );
  596. /**
  597. * @author mrdoob / http://mrdoob.com/
  598. * @author supereggbert / http://www.paulbrunt.co.uk/
  599. * @author philogb / http://blog.thejit.org/
  600. * @author jordi_ros / http://plattsoft.com
  601. * @author D1plo1d / http://github.com/D1plo1d
  602. * @author alteredq / http://alteredqualia.com/
  603. * @author mikael emtinger / http://gomo.se/
  604. * @author timknip / http://www.floorplanner.com/
  605. * @author bhouston / http://clara.io
  606. * @author WestLangley / http://github.com/WestLangley
  607. */
  608. function Matrix4() {
  609. this.elements = [
  610. 1, 0, 0, 0,
  611. 0, 1, 0, 0,
  612. 0, 0, 1, 0,
  613. 0, 0, 0, 1
  614. ];
  615. if ( arguments.length > 0 ) {
  616. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  617. }
  618. }
  619. Object.assign( Matrix4.prototype, {
  620. isMatrix4: true,
  621. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  622. var te = this.elements;
  623. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  624. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  625. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  626. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  627. return this;
  628. },
  629. identity: function () {
  630. this.set(
  631. 1, 0, 0, 0,
  632. 0, 1, 0, 0,
  633. 0, 0, 1, 0,
  634. 0, 0, 0, 1
  635. );
  636. return this;
  637. },
  638. clone: function () {
  639. return new Matrix4().fromArray( this.elements );
  640. },
  641. copy: function ( m ) {
  642. var te = this.elements;
  643. var me = m.elements;
  644. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  645. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  646. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  647. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  648. return this;
  649. },
  650. copyPosition: function ( m ) {
  651. var te = this.elements, me = m.elements;
  652. te[ 12 ] = me[ 12 ];
  653. te[ 13 ] = me[ 13 ];
  654. te[ 14 ] = me[ 14 ];
  655. return this;
  656. },
  657. extractBasis: function ( xAxis, yAxis, zAxis ) {
  658. xAxis.setFromMatrixColumn( this, 0 );
  659. yAxis.setFromMatrixColumn( this, 1 );
  660. zAxis.setFromMatrixColumn( this, 2 );
  661. return this;
  662. },
  663. makeBasis: function ( xAxis, yAxis, zAxis ) {
  664. this.set(
  665. xAxis.x, yAxis.x, zAxis.x, 0,
  666. xAxis.y, yAxis.y, zAxis.y, 0,
  667. xAxis.z, yAxis.z, zAxis.z, 0,
  668. 0, 0, 0, 1
  669. );
  670. return this;
  671. },
  672. extractRotation: function () {
  673. var v1 = new Vector3();
  674. return function extractRotation( m ) {
  675. var te = this.elements;
  676. var me = m.elements;
  677. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  678. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  679. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  680. te[ 0 ] = me[ 0 ] * scaleX;
  681. te[ 1 ] = me[ 1 ] * scaleX;
  682. te[ 2 ] = me[ 2 ] * scaleX;
  683. te[ 4 ] = me[ 4 ] * scaleY;
  684. te[ 5 ] = me[ 5 ] * scaleY;
  685. te[ 6 ] = me[ 6 ] * scaleY;
  686. te[ 8 ] = me[ 8 ] * scaleZ;
  687. te[ 9 ] = me[ 9 ] * scaleZ;
  688. te[ 10 ] = me[ 10 ] * scaleZ;
  689. return this;
  690. };
  691. }(),
  692. makeRotationFromEuler: function ( euler ) {
  693. if ( ! ( euler && euler.isEuler ) ) {
  694. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  695. }
  696. var te = this.elements;
  697. var x = euler.x, y = euler.y, z = euler.z;
  698. var a = Math.cos( x ), b = Math.sin( x );
  699. var c = Math.cos( y ), d = Math.sin( y );
  700. var e = Math.cos( z ), f = Math.sin( z );
  701. if ( euler.order === 'XYZ' ) {
  702. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  703. te[ 0 ] = c * e;
  704. te[ 4 ] = - c * f;
  705. te[ 8 ] = d;
  706. te[ 1 ] = af + be * d;
  707. te[ 5 ] = ae - bf * d;
  708. te[ 9 ] = - b * c;
  709. te[ 2 ] = bf - ae * d;
  710. te[ 6 ] = be + af * d;
  711. te[ 10 ] = a * c;
  712. } else if ( euler.order === 'YXZ' ) {
  713. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  714. te[ 0 ] = ce + df * b;
  715. te[ 4 ] = de * b - cf;
  716. te[ 8 ] = a * d;
  717. te[ 1 ] = a * f;
  718. te[ 5 ] = a * e;
  719. te[ 9 ] = - b;
  720. te[ 2 ] = cf * b - de;
  721. te[ 6 ] = df + ce * b;
  722. te[ 10 ] = a * c;
  723. } else if ( euler.order === 'ZXY' ) {
  724. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  725. te[ 0 ] = ce - df * b;
  726. te[ 4 ] = - a * f;
  727. te[ 8 ] = de + cf * b;
  728. te[ 1 ] = cf + de * b;
  729. te[ 5 ] = a * e;
  730. te[ 9 ] = df - ce * b;
  731. te[ 2 ] = - a * d;
  732. te[ 6 ] = b;
  733. te[ 10 ] = a * c;
  734. } else if ( euler.order === 'ZYX' ) {
  735. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  736. te[ 0 ] = c * e;
  737. te[ 4 ] = be * d - af;
  738. te[ 8 ] = ae * d + bf;
  739. te[ 1 ] = c * f;
  740. te[ 5 ] = bf * d + ae;
  741. te[ 9 ] = af * d - be;
  742. te[ 2 ] = - d;
  743. te[ 6 ] = b * c;
  744. te[ 10 ] = a * c;
  745. } else if ( euler.order === 'YZX' ) {
  746. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  747. te[ 0 ] = c * e;
  748. te[ 4 ] = bd - ac * f;
  749. te[ 8 ] = bc * f + ad;
  750. te[ 1 ] = f;
  751. te[ 5 ] = a * e;
  752. te[ 9 ] = - b * e;
  753. te[ 2 ] = - d * e;
  754. te[ 6 ] = ad * f + bc;
  755. te[ 10 ] = ac - bd * f;
  756. } else if ( euler.order === 'XZY' ) {
  757. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  758. te[ 0 ] = c * e;
  759. te[ 4 ] = - f;
  760. te[ 8 ] = d * e;
  761. te[ 1 ] = ac * f + bd;
  762. te[ 5 ] = a * e;
  763. te[ 9 ] = ad * f - bc;
  764. te[ 2 ] = bc * f - ad;
  765. te[ 6 ] = b * e;
  766. te[ 10 ] = bd * f + ac;
  767. }
  768. // last column
  769. te[ 3 ] = 0;
  770. te[ 7 ] = 0;
  771. te[ 11 ] = 0;
  772. // bottom row
  773. te[ 12 ] = 0;
  774. te[ 13 ] = 0;
  775. te[ 14 ] = 0;
  776. te[ 15 ] = 1;
  777. return this;
  778. },
  779. makeRotationFromQuaternion: function ( q ) {
  780. var te = this.elements;
  781. var x = q._x, y = q._y, z = q._z, w = q._w;
  782. var x2 = x + x, y2 = y + y, z2 = z + z;
  783. var xx = x * x2, xy = x * y2, xz = x * z2;
  784. var yy = y * y2, yz = y * z2, zz = z * z2;
  785. var wx = w * x2, wy = w * y2, wz = w * z2;
  786. te[ 0 ] = 1 - ( yy + zz );
  787. te[ 4 ] = xy - wz;
  788. te[ 8 ] = xz + wy;
  789. te[ 1 ] = xy + wz;
  790. te[ 5 ] = 1 - ( xx + zz );
  791. te[ 9 ] = yz - wx;
  792. te[ 2 ] = xz - wy;
  793. te[ 6 ] = yz + wx;
  794. te[ 10 ] = 1 - ( xx + yy );
  795. // last column
  796. te[ 3 ] = 0;
  797. te[ 7 ] = 0;
  798. te[ 11 ] = 0;
  799. // bottom row
  800. te[ 12 ] = 0;
  801. te[ 13 ] = 0;
  802. te[ 14 ] = 0;
  803. te[ 15 ] = 1;
  804. return this;
  805. },
  806. lookAt: function () {
  807. var x = new Vector3();
  808. var y = new Vector3();
  809. var z = new Vector3();
  810. return function lookAt( eye, target, up ) {
  811. var te = this.elements;
  812. z.subVectors( eye, target );
  813. if ( z.lengthSq() === 0 ) {
  814. // eye and target are in the same position
  815. z.z = 1;
  816. }
  817. z.normalize();
  818. x.crossVectors( up, z );
  819. if ( x.lengthSq() === 0 ) {
  820. // up and z are parallel
  821. if ( Math.abs( up.z ) === 1 ) {
  822. z.x += 0.0001;
  823. } else {
  824. z.z += 0.0001;
  825. }
  826. z.normalize();
  827. x.crossVectors( up, z );
  828. }
  829. x.normalize();
  830. y.crossVectors( z, x );
  831. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  832. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  833. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  834. return this;
  835. };
  836. }(),
  837. multiply: function ( m, n ) {
  838. if ( n !== undefined ) {
  839. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  840. return this.multiplyMatrices( m, n );
  841. }
  842. return this.multiplyMatrices( this, m );
  843. },
  844. premultiply: function ( m ) {
  845. return this.multiplyMatrices( m, this );
  846. },
  847. multiplyMatrices: function ( a, b ) {
  848. var ae = a.elements;
  849. var be = b.elements;
  850. var te = this.elements;
  851. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  852. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  853. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  854. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  855. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  856. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  857. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  858. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  859. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  860. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  861. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  862. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  863. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  864. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  865. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  866. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  867. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  868. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  869. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  870. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  871. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  872. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  873. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  874. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  875. return this;
  876. },
  877. multiplyScalar: function ( s ) {
  878. var te = this.elements;
  879. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  880. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  881. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  882. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  883. return this;
  884. },
  885. applyToBufferAttribute: function () {
  886. var v1 = new Vector3();
  887. return function applyToBufferAttribute( attribute ) {
  888. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  889. v1.x = attribute.getX( i );
  890. v1.y = attribute.getY( i );
  891. v1.z = attribute.getZ( i );
  892. v1.applyMatrix4( this );
  893. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  894. }
  895. return attribute;
  896. };
  897. }(),
  898. determinant: function () {
  899. var te = this.elements;
  900. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  901. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  902. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  903. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  904. //TODO: make this more efficient
  905. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  906. return (
  907. n41 * (
  908. + n14 * n23 * n32
  909. - n13 * n24 * n32
  910. - n14 * n22 * n33
  911. + n12 * n24 * n33
  912. + n13 * n22 * n34
  913. - n12 * n23 * n34
  914. ) +
  915. n42 * (
  916. + n11 * n23 * n34
  917. - n11 * n24 * n33
  918. + n14 * n21 * n33
  919. - n13 * n21 * n34
  920. + n13 * n24 * n31
  921. - n14 * n23 * n31
  922. ) +
  923. n43 * (
  924. + n11 * n24 * n32
  925. - n11 * n22 * n34
  926. - n14 * n21 * n32
  927. + n12 * n21 * n34
  928. + n14 * n22 * n31
  929. - n12 * n24 * n31
  930. ) +
  931. n44 * (
  932. - n13 * n22 * n31
  933. - n11 * n23 * n32
  934. + n11 * n22 * n33
  935. + n13 * n21 * n32
  936. - n12 * n21 * n33
  937. + n12 * n23 * n31
  938. )
  939. );
  940. },
  941. transpose: function () {
  942. var te = this.elements;
  943. var tmp;
  944. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  945. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  946. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  947. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  948. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  949. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  950. return this;
  951. },
  952. setPosition: function ( v ) {
  953. var te = this.elements;
  954. te[ 12 ] = v.x;
  955. te[ 13 ] = v.y;
  956. te[ 14 ] = v.z;
  957. return this;
  958. },
  959. getInverse: function ( m, throwOnDegenerate ) {
  960. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  961. var te = this.elements,
  962. me = m.elements,
  963. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  964. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  965. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  966. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  967. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  968. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  969. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  970. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  971. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  972. if ( det === 0 ) {
  973. var msg = "THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0";
  974. if ( throwOnDegenerate === true ) {
  975. throw new Error( msg );
  976. } else {
  977. console.warn( msg );
  978. }
  979. return this.identity();
  980. }
  981. var detInv = 1 / det;
  982. te[ 0 ] = t11 * detInv;
  983. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  984. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  985. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  986. te[ 4 ] = t12 * detInv;
  987. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  988. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  989. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  990. te[ 8 ] = t13 * detInv;
  991. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  992. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  993. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  994. te[ 12 ] = t14 * detInv;
  995. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  996. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  997. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  998. return this;
  999. },
  1000. scale: function ( v ) {
  1001. var te = this.elements;
  1002. var x = v.x, y = v.y, z = v.z;
  1003. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  1004. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  1005. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  1006. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  1007. return this;
  1008. },
  1009. getMaxScaleOnAxis: function () {
  1010. var te = this.elements;
  1011. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  1012. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  1013. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  1014. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  1015. },
  1016. makeTranslation: function ( x, y, z ) {
  1017. this.set(
  1018. 1, 0, 0, x,
  1019. 0, 1, 0, y,
  1020. 0, 0, 1, z,
  1021. 0, 0, 0, 1
  1022. );
  1023. return this;
  1024. },
  1025. makeRotationX: function ( theta ) {
  1026. var c = Math.cos( theta ), s = Math.sin( theta );
  1027. this.set(
  1028. 1, 0, 0, 0,
  1029. 0, c, - s, 0,
  1030. 0, s, c, 0,
  1031. 0, 0, 0, 1
  1032. );
  1033. return this;
  1034. },
  1035. makeRotationY: function ( theta ) {
  1036. var c = Math.cos( theta ), s = Math.sin( theta );
  1037. this.set(
  1038. c, 0, s, 0,
  1039. 0, 1, 0, 0,
  1040. - s, 0, c, 0,
  1041. 0, 0, 0, 1
  1042. );
  1043. return this;
  1044. },
  1045. makeRotationZ: function ( theta ) {
  1046. var c = Math.cos( theta ), s = Math.sin( theta );
  1047. this.set(
  1048. c, - s, 0, 0,
  1049. s, c, 0, 0,
  1050. 0, 0, 1, 0,
  1051. 0, 0, 0, 1
  1052. );
  1053. return this;
  1054. },
  1055. makeRotationAxis: function ( axis, angle ) {
  1056. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  1057. var c = Math.cos( angle );
  1058. var s = Math.sin( angle );
  1059. var t = 1 - c;
  1060. var x = axis.x, y = axis.y, z = axis.z;
  1061. var tx = t * x, ty = t * y;
  1062. this.set(
  1063. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  1064. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  1065. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  1066. 0, 0, 0, 1
  1067. );
  1068. return this;
  1069. },
  1070. makeScale: function ( x, y, z ) {
  1071. this.set(
  1072. x, 0, 0, 0,
  1073. 0, y, 0, 0,
  1074. 0, 0, z, 0,
  1075. 0, 0, 0, 1
  1076. );
  1077. return this;
  1078. },
  1079. makeShear: function ( x, y, z ) {
  1080. this.set(
  1081. 1, y, z, 0,
  1082. x, 1, z, 0,
  1083. x, y, 1, 0,
  1084. 0, 0, 0, 1
  1085. );
  1086. return this;
  1087. },
  1088. compose: function ( position, quaternion, scale ) {
  1089. this.makeRotationFromQuaternion( quaternion );
  1090. this.scale( scale );
  1091. this.setPosition( position );
  1092. return this;
  1093. },
  1094. decompose: function () {
  1095. var vector = new Vector3();
  1096. var matrix = new Matrix4();
  1097. return function decompose( position, quaternion, scale ) {
  1098. var te = this.elements;
  1099. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  1100. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  1101. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  1102. // if determine is negative, we need to invert one scale
  1103. var det = this.determinant();
  1104. if ( det < 0 ) sx = - sx;
  1105. position.x = te[ 12 ];
  1106. position.y = te[ 13 ];
  1107. position.z = te[ 14 ];
  1108. // scale the rotation part
  1109. matrix.copy( this );
  1110. var invSX = 1 / sx;
  1111. var invSY = 1 / sy;
  1112. var invSZ = 1 / sz;
  1113. matrix.elements[ 0 ] *= invSX;
  1114. matrix.elements[ 1 ] *= invSX;
  1115. matrix.elements[ 2 ] *= invSX;
  1116. matrix.elements[ 4 ] *= invSY;
  1117. matrix.elements[ 5 ] *= invSY;
  1118. matrix.elements[ 6 ] *= invSY;
  1119. matrix.elements[ 8 ] *= invSZ;
  1120. matrix.elements[ 9 ] *= invSZ;
  1121. matrix.elements[ 10 ] *= invSZ;
  1122. quaternion.setFromRotationMatrix( matrix );
  1123. scale.x = sx;
  1124. scale.y = sy;
  1125. scale.z = sz;
  1126. return this;
  1127. };
  1128. }(),
  1129. makePerspective: function ( left, right, top, bottom, near, far ) {
  1130. if ( far === undefined ) {
  1131. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  1132. }
  1133. var te = this.elements;
  1134. var x = 2 * near / ( right - left );
  1135. var y = 2 * near / ( top - bottom );
  1136. var a = ( right + left ) / ( right - left );
  1137. var b = ( top + bottom ) / ( top - bottom );
  1138. var c = - ( far + near ) / ( far - near );
  1139. var d = - 2 * far * near / ( far - near );
  1140. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  1141. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  1142. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  1143. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  1144. return this;
  1145. },
  1146. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  1147. var te = this.elements;
  1148. var w = 1.0 / ( right - left );
  1149. var h = 1.0 / ( top - bottom );
  1150. var p = 1.0 / ( far - near );
  1151. var x = ( right + left ) * w;
  1152. var y = ( top + bottom ) * h;
  1153. var z = ( far + near ) * p;
  1154. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  1155. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  1156. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  1157. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  1158. return this;
  1159. },
  1160. equals: function ( matrix ) {
  1161. var te = this.elements;
  1162. var me = matrix.elements;
  1163. for ( var i = 0; i < 16; i ++ ) {
  1164. if ( te[ i ] !== me[ i ] ) return false;
  1165. }
  1166. return true;
  1167. },
  1168. fromArray: function ( array, offset ) {
  1169. if ( offset === undefined ) offset = 0;
  1170. for ( var i = 0; i < 16; i ++ ) {
  1171. this.elements[ i ] = array[ i + offset ];
  1172. }
  1173. return this;
  1174. },
  1175. toArray: function ( array, offset ) {
  1176. if ( array === undefined ) array = [];
  1177. if ( offset === undefined ) offset = 0;
  1178. var te = this.elements;
  1179. array[ offset ] = te[ 0 ];
  1180. array[ offset + 1 ] = te[ 1 ];
  1181. array[ offset + 2 ] = te[ 2 ];
  1182. array[ offset + 3 ] = te[ 3 ];
  1183. array[ offset + 4 ] = te[ 4 ];
  1184. array[ offset + 5 ] = te[ 5 ];
  1185. array[ offset + 6 ] = te[ 6 ];
  1186. array[ offset + 7 ] = te[ 7 ];
  1187. array[ offset + 8 ] = te[ 8 ];
  1188. array[ offset + 9 ] = te[ 9 ];
  1189. array[ offset + 10 ] = te[ 10 ];
  1190. array[ offset + 11 ] = te[ 11 ];
  1191. array[ offset + 12 ] = te[ 12 ];
  1192. array[ offset + 13 ] = te[ 13 ];
  1193. array[ offset + 14 ] = te[ 14 ];
  1194. array[ offset + 15 ] = te[ 15 ];
  1195. return array;
  1196. }
  1197. } );
  1198. /**
  1199. * @author mikael emtinger / http://gomo.se/
  1200. * @author alteredq / http://alteredqualia.com/
  1201. * @author WestLangley / http://github.com/WestLangley
  1202. * @author bhouston / http://clara.io
  1203. */
  1204. function Quaternion( x, y, z, w ) {
  1205. this._x = x || 0;
  1206. this._y = y || 0;
  1207. this._z = z || 0;
  1208. this._w = ( w !== undefined ) ? w : 1;
  1209. }
  1210. Object.assign( Quaternion, {
  1211. slerp: function ( qa, qb, qm, t ) {
  1212. return qm.copy( qa ).slerp( qb, t );
  1213. },
  1214. slerpFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  1215. // fuzz-free, array-based Quaternion SLERP operation
  1216. var x0 = src0[ srcOffset0 + 0 ],
  1217. y0 = src0[ srcOffset0 + 1 ],
  1218. z0 = src0[ srcOffset0 + 2 ],
  1219. w0 = src0[ srcOffset0 + 3 ],
  1220. x1 = src1[ srcOffset1 + 0 ],
  1221. y1 = src1[ srcOffset1 + 1 ],
  1222. z1 = src1[ srcOffset1 + 2 ],
  1223. w1 = src1[ srcOffset1 + 3 ];
  1224. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  1225. var s = 1 - t,
  1226. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1227. dir = ( cos >= 0 ? 1 : - 1 ),
  1228. sqrSin = 1 - cos * cos;
  1229. // Skip the Slerp for tiny steps to avoid numeric problems:
  1230. if ( sqrSin > Number.EPSILON ) {
  1231. var sin = Math.sqrt( sqrSin ),
  1232. len = Math.atan2( sin, cos * dir );
  1233. s = Math.sin( s * len ) / sin;
  1234. t = Math.sin( t * len ) / sin;
  1235. }
  1236. var tDir = t * dir;
  1237. x0 = x0 * s + x1 * tDir;
  1238. y0 = y0 * s + y1 * tDir;
  1239. z0 = z0 * s + z1 * tDir;
  1240. w0 = w0 * s + w1 * tDir;
  1241. // Normalize in case we just did a lerp:
  1242. if ( s === 1 - t ) {
  1243. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  1244. x0 *= f;
  1245. y0 *= f;
  1246. z0 *= f;
  1247. w0 *= f;
  1248. }
  1249. }
  1250. dst[ dstOffset ] = x0;
  1251. dst[ dstOffset + 1 ] = y0;
  1252. dst[ dstOffset + 2 ] = z0;
  1253. dst[ dstOffset + 3 ] = w0;
  1254. }
  1255. } );
  1256. Object.defineProperties( Quaternion.prototype, {
  1257. x: {
  1258. get: function () {
  1259. return this._x;
  1260. },
  1261. set: function ( value ) {
  1262. this._x = value;
  1263. this.onChangeCallback();
  1264. }
  1265. },
  1266. y: {
  1267. get: function () {
  1268. return this._y;
  1269. },
  1270. set: function ( value ) {
  1271. this._y = value;
  1272. this.onChangeCallback();
  1273. }
  1274. },
  1275. z: {
  1276. get: function () {
  1277. return this._z;
  1278. },
  1279. set: function ( value ) {
  1280. this._z = value;
  1281. this.onChangeCallback();
  1282. }
  1283. },
  1284. w: {
  1285. get: function () {
  1286. return this._w;
  1287. },
  1288. set: function ( value ) {
  1289. this._w = value;
  1290. this.onChangeCallback();
  1291. }
  1292. }
  1293. } );
  1294. Object.assign( Quaternion.prototype, {
  1295. set: function ( x, y, z, w ) {
  1296. this._x = x;
  1297. this._y = y;
  1298. this._z = z;
  1299. this._w = w;
  1300. this.onChangeCallback();
  1301. return this;
  1302. },
  1303. clone: function () {
  1304. return new this.constructor( this._x, this._y, this._z, this._w );
  1305. },
  1306. copy: function ( quaternion ) {
  1307. this._x = quaternion.x;
  1308. this._y = quaternion.y;
  1309. this._z = quaternion.z;
  1310. this._w = quaternion.w;
  1311. this.onChangeCallback();
  1312. return this;
  1313. },
  1314. setFromEuler: function ( euler, update ) {
  1315. if ( ! ( euler && euler.isEuler ) ) {
  1316. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1317. }
  1318. var x = euler._x, y = euler._y, z = euler._z, order = euler.order;
  1319. // http://www.mathworks.com/matlabcentral/fileexchange/
  1320. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1321. // content/SpinCalc.m
  1322. var cos = Math.cos;
  1323. var sin = Math.sin;
  1324. var c1 = cos( x / 2 );
  1325. var c2 = cos( y / 2 );
  1326. var c3 = cos( z / 2 );
  1327. var s1 = sin( x / 2 );
  1328. var s2 = sin( y / 2 );
  1329. var s3 = sin( z / 2 );
  1330. if ( order === 'XYZ' ) {
  1331. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1332. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1333. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1334. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1335. } else if ( order === 'YXZ' ) {
  1336. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1337. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1338. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1339. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1340. } else if ( order === 'ZXY' ) {
  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 === 'ZYX' ) {
  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 === 'YZX' ) {
  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 === 'XZY' ) {
  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. }
  1361. if ( update !== false ) this.onChangeCallback();
  1362. return this;
  1363. },
  1364. setFromAxisAngle: function ( axis, angle ) {
  1365. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1366. // assumes axis is normalized
  1367. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  1368. this._x = axis.x * s;
  1369. this._y = axis.y * s;
  1370. this._z = axis.z * s;
  1371. this._w = Math.cos( halfAngle );
  1372. this.onChangeCallback();
  1373. return this;
  1374. },
  1375. setFromRotationMatrix: function ( m ) {
  1376. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1377. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1378. var te = m.elements,
  1379. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1380. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1381. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  1382. trace = m11 + m22 + m33,
  1383. s;
  1384. if ( trace > 0 ) {
  1385. s = 0.5 / Math.sqrt( trace + 1.0 );
  1386. this._w = 0.25 / s;
  1387. this._x = ( m32 - m23 ) * s;
  1388. this._y = ( m13 - m31 ) * s;
  1389. this._z = ( m21 - m12 ) * s;
  1390. } else if ( m11 > m22 && m11 > m33 ) {
  1391. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  1392. this._w = ( m32 - m23 ) / s;
  1393. this._x = 0.25 * s;
  1394. this._y = ( m12 + m21 ) / s;
  1395. this._z = ( m13 + m31 ) / s;
  1396. } else if ( m22 > m33 ) {
  1397. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  1398. this._w = ( m13 - m31 ) / s;
  1399. this._x = ( m12 + m21 ) / s;
  1400. this._y = 0.25 * s;
  1401. this._z = ( m23 + m32 ) / s;
  1402. } else {
  1403. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  1404. this._w = ( m21 - m12 ) / s;
  1405. this._x = ( m13 + m31 ) / s;
  1406. this._y = ( m23 + m32 ) / s;
  1407. this._z = 0.25 * s;
  1408. }
  1409. this.onChangeCallback();
  1410. return this;
  1411. },
  1412. setFromUnitVectors: function () {
  1413. // assumes direction vectors vFrom and vTo are normalized
  1414. var v1 = new Vector3();
  1415. var r;
  1416. var EPS = 0.000001;
  1417. return function setFromUnitVectors( vFrom, vTo ) {
  1418. if ( v1 === undefined ) v1 = new Vector3();
  1419. r = vFrom.dot( vTo ) + 1;
  1420. if ( r < EPS ) {
  1421. r = 0;
  1422. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  1423. v1.set( - vFrom.y, vFrom.x, 0 );
  1424. } else {
  1425. v1.set( 0, - vFrom.z, vFrom.y );
  1426. }
  1427. } else {
  1428. v1.crossVectors( vFrom, vTo );
  1429. }
  1430. this._x = v1.x;
  1431. this._y = v1.y;
  1432. this._z = v1.z;
  1433. this._w = r;
  1434. return this.normalize();
  1435. };
  1436. }(),
  1437. inverse: function () {
  1438. // quaternion is assumed to have unit length
  1439. return this.conjugate();
  1440. },
  1441. conjugate: function () {
  1442. this._x *= - 1;
  1443. this._y *= - 1;
  1444. this._z *= - 1;
  1445. this.onChangeCallback();
  1446. return this;
  1447. },
  1448. dot: function ( v ) {
  1449. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1450. },
  1451. lengthSq: function () {
  1452. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1453. },
  1454. length: function () {
  1455. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  1456. },
  1457. normalize: function () {
  1458. var l = this.length();
  1459. if ( l === 0 ) {
  1460. this._x = 0;
  1461. this._y = 0;
  1462. this._z = 0;
  1463. this._w = 1;
  1464. } else {
  1465. l = 1 / l;
  1466. this._x = this._x * l;
  1467. this._y = this._y * l;
  1468. this._z = this._z * l;
  1469. this._w = this._w * l;
  1470. }
  1471. this.onChangeCallback();
  1472. return this;
  1473. },
  1474. multiply: function ( q, p ) {
  1475. if ( p !== undefined ) {
  1476. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  1477. return this.multiplyQuaternions( q, p );
  1478. }
  1479. return this.multiplyQuaternions( this, q );
  1480. },
  1481. premultiply: function ( q ) {
  1482. return this.multiplyQuaternions( q, this );
  1483. },
  1484. multiplyQuaternions: function ( a, b ) {
  1485. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  1486. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  1487. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  1488. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  1489. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  1490. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  1491. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  1492. this.onChangeCallback();
  1493. return this;
  1494. },
  1495. slerp: function ( qb, t ) {
  1496. if ( t === 0 ) return this;
  1497. if ( t === 1 ) return this.copy( qb );
  1498. var x = this._x, y = this._y, z = this._z, w = this._w;
  1499. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  1500. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  1501. if ( cosHalfTheta < 0 ) {
  1502. this._w = - qb._w;
  1503. this._x = - qb._x;
  1504. this._y = - qb._y;
  1505. this._z = - qb._z;
  1506. cosHalfTheta = - cosHalfTheta;
  1507. } else {
  1508. this.copy( qb );
  1509. }
  1510. if ( cosHalfTheta >= 1.0 ) {
  1511. this._w = w;
  1512. this._x = x;
  1513. this._y = y;
  1514. this._z = z;
  1515. return this;
  1516. }
  1517. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  1518. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  1519. this._w = 0.5 * ( w + this._w );
  1520. this._x = 0.5 * ( x + this._x );
  1521. this._y = 0.5 * ( y + this._y );
  1522. this._z = 0.5 * ( z + this._z );
  1523. return this;
  1524. }
  1525. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  1526. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  1527. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  1528. this._w = ( w * ratioA + this._w * ratioB );
  1529. this._x = ( x * ratioA + this._x * ratioB );
  1530. this._y = ( y * ratioA + this._y * ratioB );
  1531. this._z = ( z * ratioA + this._z * ratioB );
  1532. this.onChangeCallback();
  1533. return this;
  1534. },
  1535. equals: function ( quaternion ) {
  1536. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  1537. },
  1538. fromArray: function ( array, offset ) {
  1539. if ( offset === undefined ) offset = 0;
  1540. this._x = array[ offset ];
  1541. this._y = array[ offset + 1 ];
  1542. this._z = array[ offset + 2 ];
  1543. this._w = array[ offset + 3 ];
  1544. this.onChangeCallback();
  1545. return this;
  1546. },
  1547. toArray: function ( array, offset ) {
  1548. if ( array === undefined ) array = [];
  1549. if ( offset === undefined ) offset = 0;
  1550. array[ offset ] = this._x;
  1551. array[ offset + 1 ] = this._y;
  1552. array[ offset + 2 ] = this._z;
  1553. array[ offset + 3 ] = this._w;
  1554. return array;
  1555. },
  1556. onChange: function ( callback ) {
  1557. this.onChangeCallback = callback;
  1558. return this;
  1559. },
  1560. onChangeCallback: function () {}
  1561. } );
  1562. /**
  1563. * @author mrdoob / http://mrdoob.com/
  1564. * @author kile / http://kile.stravaganza.org/
  1565. * @author philogb / http://blog.thejit.org/
  1566. * @author mikael emtinger / http://gomo.se/
  1567. * @author egraether / http://egraether.com/
  1568. * @author WestLangley / http://github.com/WestLangley
  1569. */
  1570. function Vector3( x, y, z ) {
  1571. this.x = x || 0;
  1572. this.y = y || 0;
  1573. this.z = z || 0;
  1574. }
  1575. Object.assign( Vector3.prototype, {
  1576. isVector3: true,
  1577. set: function ( x, y, z ) {
  1578. this.x = x;
  1579. this.y = y;
  1580. this.z = z;
  1581. return this;
  1582. },
  1583. setScalar: function ( scalar ) {
  1584. this.x = scalar;
  1585. this.y = scalar;
  1586. this.z = scalar;
  1587. return this;
  1588. },
  1589. setX: function ( x ) {
  1590. this.x = x;
  1591. return this;
  1592. },
  1593. setY: function ( y ) {
  1594. this.y = y;
  1595. return this;
  1596. },
  1597. setZ: function ( z ) {
  1598. this.z = z;
  1599. return this;
  1600. },
  1601. setComponent: function ( index, value ) {
  1602. switch ( index ) {
  1603. case 0: this.x = value; break;
  1604. case 1: this.y = value; break;
  1605. case 2: this.z = value; break;
  1606. default: throw new Error( 'index is out of range: ' + index );
  1607. }
  1608. return this;
  1609. },
  1610. getComponent: function ( index ) {
  1611. switch ( index ) {
  1612. case 0: return this.x;
  1613. case 1: return this.y;
  1614. case 2: return this.z;
  1615. default: throw new Error( 'index is out of range: ' + index );
  1616. }
  1617. },
  1618. clone: function () {
  1619. return new this.constructor( this.x, this.y, this.z );
  1620. },
  1621. copy: function ( v ) {
  1622. this.x = v.x;
  1623. this.y = v.y;
  1624. this.z = v.z;
  1625. return this;
  1626. },
  1627. add: function ( v, w ) {
  1628. if ( w !== undefined ) {
  1629. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1630. return this.addVectors( v, w );
  1631. }
  1632. this.x += v.x;
  1633. this.y += v.y;
  1634. this.z += v.z;
  1635. return this;
  1636. },
  1637. addScalar: function ( s ) {
  1638. this.x += s;
  1639. this.y += s;
  1640. this.z += s;
  1641. return this;
  1642. },
  1643. addVectors: function ( a, b ) {
  1644. this.x = a.x + b.x;
  1645. this.y = a.y + b.y;
  1646. this.z = a.z + b.z;
  1647. return this;
  1648. },
  1649. addScaledVector: function ( v, s ) {
  1650. this.x += v.x * s;
  1651. this.y += v.y * s;
  1652. this.z += v.z * s;
  1653. return this;
  1654. },
  1655. sub: function ( v, w ) {
  1656. if ( w !== undefined ) {
  1657. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1658. return this.subVectors( v, w );
  1659. }
  1660. this.x -= v.x;
  1661. this.y -= v.y;
  1662. this.z -= v.z;
  1663. return this;
  1664. },
  1665. subScalar: function ( s ) {
  1666. this.x -= s;
  1667. this.y -= s;
  1668. this.z -= s;
  1669. return this;
  1670. },
  1671. subVectors: function ( a, b ) {
  1672. this.x = a.x - b.x;
  1673. this.y = a.y - b.y;
  1674. this.z = a.z - b.z;
  1675. return this;
  1676. },
  1677. multiply: function ( v, w ) {
  1678. if ( w !== undefined ) {
  1679. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1680. return this.multiplyVectors( v, w );
  1681. }
  1682. this.x *= v.x;
  1683. this.y *= v.y;
  1684. this.z *= v.z;
  1685. return this;
  1686. },
  1687. multiplyScalar: function ( scalar ) {
  1688. this.x *= scalar;
  1689. this.y *= scalar;
  1690. this.z *= scalar;
  1691. return this;
  1692. },
  1693. multiplyVectors: 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. applyEuler: function () {
  1700. var quaternion = new Quaternion();
  1701. return function applyEuler( euler ) {
  1702. if ( ! ( euler && euler.isEuler ) ) {
  1703. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1704. }
  1705. return this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1706. };
  1707. }(),
  1708. applyAxisAngle: function () {
  1709. var quaternion = new Quaternion();
  1710. return function applyAxisAngle( axis, angle ) {
  1711. return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1712. };
  1713. }(),
  1714. applyMatrix3: function ( m ) {
  1715. var x = this.x, y = this.y, z = this.z;
  1716. var e = m.elements;
  1717. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1718. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1719. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1720. return this;
  1721. },
  1722. applyMatrix4: function ( m ) {
  1723. var x = this.x, y = this.y, z = this.z;
  1724. var e = m.elements;
  1725. var w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  1726. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  1727. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  1728. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  1729. return this;
  1730. },
  1731. applyQuaternion: function ( q ) {
  1732. var x = this.x, y = this.y, z = this.z;
  1733. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1734. // calculate quat * vector
  1735. var ix = qw * x + qy * z - qz * y;
  1736. var iy = qw * y + qz * x - qx * z;
  1737. var iz = qw * z + qx * y - qy * x;
  1738. var iw = - qx * x - qy * y - qz * z;
  1739. // calculate result * inverse quat
  1740. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1741. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1742. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1743. return this;
  1744. },
  1745. project: function () {
  1746. var matrix = new Matrix4();
  1747. return function project( camera ) {
  1748. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1749. return this.applyMatrix4( matrix );
  1750. };
  1751. }(),
  1752. unproject: function () {
  1753. var matrix = new Matrix4();
  1754. return function unproject( camera ) {
  1755. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1756. return this.applyMatrix4( matrix );
  1757. };
  1758. }(),
  1759. transformDirection: function ( m ) {
  1760. // input: THREE.Matrix4 affine matrix
  1761. // vector interpreted as a direction
  1762. var x = this.x, y = this.y, z = this.z;
  1763. var e = m.elements;
  1764. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1765. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1766. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1767. return this.normalize();
  1768. },
  1769. divide: function ( v ) {
  1770. this.x /= v.x;
  1771. this.y /= v.y;
  1772. this.z /= v.z;
  1773. return this;
  1774. },
  1775. divideScalar: function ( scalar ) {
  1776. return this.multiplyScalar( 1 / scalar );
  1777. },
  1778. min: function ( v ) {
  1779. this.x = Math.min( this.x, v.x );
  1780. this.y = Math.min( this.y, v.y );
  1781. this.z = Math.min( this.z, v.z );
  1782. return this;
  1783. },
  1784. max: function ( v ) {
  1785. this.x = Math.max( this.x, v.x );
  1786. this.y = Math.max( this.y, v.y );
  1787. this.z = Math.max( this.z, v.z );
  1788. return this;
  1789. },
  1790. clamp: function ( min, max ) {
  1791. // assumes min < max, componentwise
  1792. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1793. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1794. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1795. return this;
  1796. },
  1797. clampScalar: function () {
  1798. var min = new Vector3();
  1799. var max = new Vector3();
  1800. return function clampScalar( minVal, maxVal ) {
  1801. min.set( minVal, minVal, minVal );
  1802. max.set( maxVal, maxVal, maxVal );
  1803. return this.clamp( min, max );
  1804. };
  1805. }(),
  1806. clampLength: function ( min, max ) {
  1807. var length = this.length();
  1808. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1809. },
  1810. floor: function () {
  1811. this.x = Math.floor( this.x );
  1812. this.y = Math.floor( this.y );
  1813. this.z = Math.floor( this.z );
  1814. return this;
  1815. },
  1816. ceil: function () {
  1817. this.x = Math.ceil( this.x );
  1818. this.y = Math.ceil( this.y );
  1819. this.z = Math.ceil( this.z );
  1820. return this;
  1821. },
  1822. round: function () {
  1823. this.x = Math.round( this.x );
  1824. this.y = Math.round( this.y );
  1825. this.z = Math.round( this.z );
  1826. return this;
  1827. },
  1828. roundToZero: function () {
  1829. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1830. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1831. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1832. return this;
  1833. },
  1834. negate: function () {
  1835. this.x = - this.x;
  1836. this.y = - this.y;
  1837. this.z = - this.z;
  1838. return this;
  1839. },
  1840. dot: function ( v ) {
  1841. return this.x * v.x + this.y * v.y + this.z * v.z;
  1842. },
  1843. // TODO lengthSquared?
  1844. lengthSq: function () {
  1845. return this.x * this.x + this.y * this.y + this.z * this.z;
  1846. },
  1847. length: function () {
  1848. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1849. },
  1850. manhattanLength: function () {
  1851. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1852. },
  1853. normalize: function () {
  1854. return this.divideScalar( this.length() || 1 );
  1855. },
  1856. setLength: function ( length ) {
  1857. return this.normalize().multiplyScalar( length );
  1858. },
  1859. lerp: function ( v, alpha ) {
  1860. this.x += ( v.x - this.x ) * alpha;
  1861. this.y += ( v.y - this.y ) * alpha;
  1862. this.z += ( v.z - this.z ) * alpha;
  1863. return this;
  1864. },
  1865. lerpVectors: function ( v1, v2, alpha ) {
  1866. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1867. },
  1868. cross: function ( v, w ) {
  1869. if ( w !== undefined ) {
  1870. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1871. return this.crossVectors( v, w );
  1872. }
  1873. return this.crossVectors( this, v );
  1874. },
  1875. crossVectors: function ( a, b ) {
  1876. var ax = a.x, ay = a.y, az = a.z;
  1877. var bx = b.x, by = b.y, bz = b.z;
  1878. this.x = ay * bz - az * by;
  1879. this.y = az * bx - ax * bz;
  1880. this.z = ax * by - ay * bx;
  1881. return this;
  1882. },
  1883. projectOnVector: function ( vector ) {
  1884. var scalar = vector.dot( this ) / vector.lengthSq();
  1885. return this.copy( vector ).multiplyScalar( scalar );
  1886. },
  1887. projectOnPlane: function () {
  1888. var v1 = new Vector3();
  1889. return function projectOnPlane( planeNormal ) {
  1890. v1.copy( this ).projectOnVector( planeNormal );
  1891. return this.sub( v1 );
  1892. };
  1893. }(),
  1894. reflect: function () {
  1895. // reflect incident vector off plane orthogonal to normal
  1896. // normal is assumed to have unit length
  1897. var v1 = new Vector3();
  1898. return function reflect( normal ) {
  1899. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1900. };
  1901. }(),
  1902. angleTo: function ( v ) {
  1903. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1904. // clamp, to handle numerical problems
  1905. return Math.acos( _Math.clamp( theta, - 1, 1 ) );
  1906. },
  1907. distanceTo: function ( v ) {
  1908. return Math.sqrt( this.distanceToSquared( v ) );
  1909. },
  1910. distanceToSquared: function ( v ) {
  1911. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1912. return dx * dx + dy * dy + dz * dz;
  1913. },
  1914. manhattanDistanceTo: function ( v ) {
  1915. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  1916. },
  1917. setFromSpherical: function ( s ) {
  1918. var sinPhiRadius = Math.sin( s.phi ) * s.radius;
  1919. this.x = sinPhiRadius * Math.sin( s.theta );
  1920. this.y = Math.cos( s.phi ) * s.radius;
  1921. this.z = sinPhiRadius * Math.cos( s.theta );
  1922. return this;
  1923. },
  1924. setFromCylindrical: function ( c ) {
  1925. this.x = c.radius * Math.sin( c.theta );
  1926. this.y = c.y;
  1927. this.z = c.radius * Math.cos( c.theta );
  1928. return this;
  1929. },
  1930. setFromMatrixPosition: function ( m ) {
  1931. var e = m.elements;
  1932. this.x = e[ 12 ];
  1933. this.y = e[ 13 ];
  1934. this.z = e[ 14 ];
  1935. return this;
  1936. },
  1937. setFromMatrixScale: function ( m ) {
  1938. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1939. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1940. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1941. this.x = sx;
  1942. this.y = sy;
  1943. this.z = sz;
  1944. return this;
  1945. },
  1946. setFromMatrixColumn: function ( m, index ) {
  1947. return this.fromArray( m.elements, index * 4 );
  1948. },
  1949. equals: function ( v ) {
  1950. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1951. },
  1952. fromArray: function ( array, offset ) {
  1953. if ( offset === undefined ) offset = 0;
  1954. this.x = array[ offset ];
  1955. this.y = array[ offset + 1 ];
  1956. this.z = array[ offset + 2 ];
  1957. return this;
  1958. },
  1959. toArray: function ( array, offset ) {
  1960. if ( array === undefined ) array = [];
  1961. if ( offset === undefined ) offset = 0;
  1962. array[ offset ] = this.x;
  1963. array[ offset + 1 ] = this.y;
  1964. array[ offset + 2 ] = this.z;
  1965. return array;
  1966. },
  1967. fromBufferAttribute: function ( attribute, index, offset ) {
  1968. if ( offset !== undefined ) {
  1969. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  1970. }
  1971. this.x = attribute.getX( index );
  1972. this.y = attribute.getY( index );
  1973. this.z = attribute.getZ( index );
  1974. return this;
  1975. }
  1976. } );
  1977. /**
  1978. * @author alteredq / http://alteredqualia.com/
  1979. * @author WestLangley / http://github.com/WestLangley
  1980. * @author bhouston / http://clara.io
  1981. * @author tschw
  1982. */
  1983. function Matrix3() {
  1984. this.elements = [
  1985. 1, 0, 0,
  1986. 0, 1, 0,
  1987. 0, 0, 1
  1988. ];
  1989. if ( arguments.length > 0 ) {
  1990. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  1991. }
  1992. }
  1993. Object.assign( Matrix3.prototype, {
  1994. isMatrix3: true,
  1995. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  1996. var te = this.elements;
  1997. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  1998. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  1999. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  2000. return this;
  2001. },
  2002. identity: function () {
  2003. this.set(
  2004. 1, 0, 0,
  2005. 0, 1, 0,
  2006. 0, 0, 1
  2007. );
  2008. return this;
  2009. },
  2010. clone: function () {
  2011. return new this.constructor().fromArray( this.elements );
  2012. },
  2013. copy: function ( m ) {
  2014. var te = this.elements;
  2015. var me = m.elements;
  2016. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  2017. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  2018. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  2019. return this;
  2020. },
  2021. setFromMatrix4: function ( m ) {
  2022. var me = m.elements;
  2023. this.set(
  2024. me[ 0 ], me[ 4 ], me[ 8 ],
  2025. me[ 1 ], me[ 5 ], me[ 9 ],
  2026. me[ 2 ], me[ 6 ], me[ 10 ]
  2027. );
  2028. return this;
  2029. },
  2030. applyToBufferAttribute: function () {
  2031. var v1 = new Vector3();
  2032. return function applyToBufferAttribute( attribute ) {
  2033. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2034. v1.x = attribute.getX( i );
  2035. v1.y = attribute.getY( i );
  2036. v1.z = attribute.getZ( i );
  2037. v1.applyMatrix3( this );
  2038. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  2039. }
  2040. return attribute;
  2041. };
  2042. }(),
  2043. multiply: function ( m ) {
  2044. return this.multiplyMatrices( this, m );
  2045. },
  2046. premultiply: function ( m ) {
  2047. return this.multiplyMatrices( m, this );
  2048. },
  2049. multiplyMatrices: function ( a, b ) {
  2050. var ae = a.elements;
  2051. var be = b.elements;
  2052. var te = this.elements;
  2053. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  2054. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  2055. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  2056. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  2057. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  2058. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  2059. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  2060. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  2061. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  2062. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  2063. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  2064. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  2065. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  2066. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  2067. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  2068. return this;
  2069. },
  2070. multiplyScalar: function ( s ) {
  2071. var te = this.elements;
  2072. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2073. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2074. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2075. return this;
  2076. },
  2077. determinant: function () {
  2078. var te = this.elements;
  2079. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2080. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2081. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2082. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2083. },
  2084. getInverse: function ( matrix, throwOnDegenerate ) {
  2085. if ( matrix && matrix.isMatrix4 ) {
  2086. console.error( "THREE.Matrix3: .getInverse() no longer takes a Matrix4 argument." );
  2087. }
  2088. var me = matrix.elements,
  2089. te = this.elements,
  2090. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  2091. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  2092. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  2093. t11 = n33 * n22 - n32 * n23,
  2094. t12 = n32 * n13 - n33 * n12,
  2095. t13 = n23 * n12 - n22 * n13,
  2096. det = n11 * t11 + n21 * t12 + n31 * t13;
  2097. if ( det === 0 ) {
  2098. var msg = "THREE.Matrix3: .getInverse() can't invert matrix, determinant is 0";
  2099. if ( throwOnDegenerate === true ) {
  2100. throw new Error( msg );
  2101. } else {
  2102. console.warn( msg );
  2103. }
  2104. return this.identity();
  2105. }
  2106. var detInv = 1 / det;
  2107. te[ 0 ] = t11 * detInv;
  2108. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  2109. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  2110. te[ 3 ] = t12 * detInv;
  2111. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  2112. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  2113. te[ 6 ] = t13 * detInv;
  2114. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  2115. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  2116. return this;
  2117. },
  2118. transpose: function () {
  2119. var tmp, m = this.elements;
  2120. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2121. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2122. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2123. return this;
  2124. },
  2125. getNormalMatrix: function ( matrix4 ) {
  2126. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  2127. },
  2128. transposeIntoArray: function ( r ) {
  2129. var m = this.elements;
  2130. r[ 0 ] = m[ 0 ];
  2131. r[ 1 ] = m[ 3 ];
  2132. r[ 2 ] = m[ 6 ];
  2133. r[ 3 ] = m[ 1 ];
  2134. r[ 4 ] = m[ 4 ];
  2135. r[ 5 ] = m[ 7 ];
  2136. r[ 6 ] = m[ 2 ];
  2137. r[ 7 ] = m[ 5 ];
  2138. r[ 8 ] = m[ 8 ];
  2139. return this;
  2140. },
  2141. setUvTransform: function ( tx, ty, sx, sy, rotation, cx, cy ) {
  2142. var c = Math.cos( rotation );
  2143. var s = Math.sin( rotation );
  2144. this.set(
  2145. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  2146. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  2147. 0, 0, 1
  2148. );
  2149. },
  2150. scale: function ( sx, sy ) {
  2151. var te = this.elements;
  2152. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  2153. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  2154. return this;
  2155. },
  2156. rotate: function ( theta ) {
  2157. var c = Math.cos( theta );
  2158. var s = Math.sin( theta );
  2159. var te = this.elements;
  2160. var a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  2161. var a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  2162. te[ 0 ] = c * a11 + s * a21;
  2163. te[ 3 ] = c * a12 + s * a22;
  2164. te[ 6 ] = c * a13 + s * a23;
  2165. te[ 1 ] = - s * a11 + c * a21;
  2166. te[ 4 ] = - s * a12 + c * a22;
  2167. te[ 7 ] = - s * a13 + c * a23;
  2168. return this;
  2169. },
  2170. translate: function ( tx, ty ) {
  2171. var te = this.elements;
  2172. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  2173. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  2174. return this;
  2175. },
  2176. equals: function ( matrix ) {
  2177. var te = this.elements;
  2178. var me = matrix.elements;
  2179. for ( var i = 0; i < 9; i ++ ) {
  2180. if ( te[ i ] !== me[ i ] ) return false;
  2181. }
  2182. return true;
  2183. },
  2184. fromArray: function ( array, offset ) {
  2185. if ( offset === undefined ) offset = 0;
  2186. for ( var i = 0; i < 9; i ++ ) {
  2187. this.elements[ i ] = array[ i + offset ];
  2188. }
  2189. return this;
  2190. },
  2191. toArray: function ( array, offset ) {
  2192. if ( array === undefined ) array = [];
  2193. if ( offset === undefined ) offset = 0;
  2194. var te = this.elements;
  2195. array[ offset ] = te[ 0 ];
  2196. array[ offset + 1 ] = te[ 1 ];
  2197. array[ offset + 2 ] = te[ 2 ];
  2198. array[ offset + 3 ] = te[ 3 ];
  2199. array[ offset + 4 ] = te[ 4 ];
  2200. array[ offset + 5 ] = te[ 5 ];
  2201. array[ offset + 6 ] = te[ 6 ];
  2202. array[ offset + 7 ] = te[ 7 ];
  2203. array[ offset + 8 ] = te[ 8 ];
  2204. return array;
  2205. }
  2206. } );
  2207. /**
  2208. * @author mrdoob / http://mrdoob.com/
  2209. * @author alteredq / http://alteredqualia.com/
  2210. * @author szimek / https://github.com/szimek/
  2211. */
  2212. var textureId = 0;
  2213. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  2214. Object.defineProperty( this, 'id', { value: textureId ++ } );
  2215. this.uuid = _Math.generateUUID();
  2216. this.name = '';
  2217. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  2218. this.mipmaps = [];
  2219. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  2220. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  2221. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  2222. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  2223. this.minFilter = minFilter !== undefined ? minFilter : LinearMipMapLinearFilter;
  2224. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  2225. this.format = format !== undefined ? format : RGBAFormat;
  2226. this.type = type !== undefined ? type : UnsignedByteType;
  2227. this.offset = new Vector2( 0, 0 );
  2228. this.repeat = new Vector2( 1, 1 );
  2229. this.center = new Vector2( 0, 0 );
  2230. this.rotation = 0;
  2231. this.matrixAutoUpdate = true;
  2232. this.matrix = new Matrix3();
  2233. this.generateMipmaps = true;
  2234. this.premultiplyAlpha = false;
  2235. this.flipY = true;
  2236. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  2237. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  2238. //
  2239. // Also changing the encoding after already used by a Material will not automatically make the Material
  2240. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  2241. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  2242. this.version = 0;
  2243. this.onUpdate = null;
  2244. }
  2245. Texture.DEFAULT_IMAGE = undefined;
  2246. Texture.DEFAULT_MAPPING = UVMapping;
  2247. Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2248. constructor: Texture,
  2249. isTexture: true,
  2250. updateMatrix: function () {
  2251. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  2252. },
  2253. clone: function () {
  2254. return new this.constructor().copy( this );
  2255. },
  2256. copy: function ( source ) {
  2257. this.name = source.name;
  2258. this.image = source.image;
  2259. this.mipmaps = source.mipmaps.slice( 0 );
  2260. this.mapping = source.mapping;
  2261. this.wrapS = source.wrapS;
  2262. this.wrapT = source.wrapT;
  2263. this.magFilter = source.magFilter;
  2264. this.minFilter = source.minFilter;
  2265. this.anisotropy = source.anisotropy;
  2266. this.format = source.format;
  2267. this.type = source.type;
  2268. this.offset.copy( source.offset );
  2269. this.repeat.copy( source.repeat );
  2270. this.center.copy( source.center );
  2271. this.rotation = source.rotation;
  2272. this.matrixAutoUpdate = source.matrixAutoUpdate;
  2273. this.matrix.copy( source.matrix );
  2274. this.generateMipmaps = source.generateMipmaps;
  2275. this.premultiplyAlpha = source.premultiplyAlpha;
  2276. this.flipY = source.flipY;
  2277. this.unpackAlignment = source.unpackAlignment;
  2278. this.encoding = source.encoding;
  2279. return this;
  2280. },
  2281. toJSON: function ( meta ) {
  2282. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  2283. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  2284. return meta.textures[ this.uuid ];
  2285. }
  2286. function getDataURL( image ) {
  2287. var canvas;
  2288. if ( image instanceof HTMLCanvasElement ) {
  2289. canvas = image;
  2290. } else {
  2291. canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  2292. canvas.width = image.width;
  2293. canvas.height = image.height;
  2294. var context = canvas.getContext( '2d' );
  2295. if ( image instanceof ImageData ) {
  2296. context.putImageData( image, 0, 0 );
  2297. } else {
  2298. context.drawImage( image, 0, 0, image.width, image.height );
  2299. }
  2300. }
  2301. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  2302. return canvas.toDataURL( 'image/jpeg', 0.6 );
  2303. } else {
  2304. return canvas.toDataURL( 'image/png' );
  2305. }
  2306. }
  2307. var output = {
  2308. metadata: {
  2309. version: 4.5,
  2310. type: 'Texture',
  2311. generator: 'Texture.toJSON'
  2312. },
  2313. uuid: this.uuid,
  2314. name: this.name,
  2315. mapping: this.mapping,
  2316. repeat: [ this.repeat.x, this.repeat.y ],
  2317. offset: [ this.offset.x, this.offset.y ],
  2318. center: [ this.center.x, this.center.y ],
  2319. rotation: this.rotation,
  2320. wrap: [ this.wrapS, this.wrapT ],
  2321. format: this.format,
  2322. minFilter: this.minFilter,
  2323. magFilter: this.magFilter,
  2324. anisotropy: this.anisotropy,
  2325. flipY: this.flipY
  2326. };
  2327. if ( this.image !== undefined ) {
  2328. // TODO: Move to THREE.Image
  2329. var image = this.image;
  2330. if ( image.uuid === undefined ) {
  2331. image.uuid = _Math.generateUUID(); // UGH
  2332. }
  2333. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  2334. meta.images[ image.uuid ] = {
  2335. uuid: image.uuid,
  2336. url: getDataURL( image )
  2337. };
  2338. }
  2339. output.image = image.uuid;
  2340. }
  2341. if ( ! isRootObject ) {
  2342. meta.textures[ this.uuid ] = output;
  2343. }
  2344. return output;
  2345. },
  2346. dispose: function () {
  2347. this.dispatchEvent( { type: 'dispose' } );
  2348. },
  2349. transformUv: function ( uv ) {
  2350. if ( this.mapping !== UVMapping ) return;
  2351. uv.applyMatrix3( this.matrix );
  2352. if ( uv.x < 0 || uv.x > 1 ) {
  2353. switch ( this.wrapS ) {
  2354. case RepeatWrapping:
  2355. uv.x = uv.x - Math.floor( uv.x );
  2356. break;
  2357. case ClampToEdgeWrapping:
  2358. uv.x = uv.x < 0 ? 0 : 1;
  2359. break;
  2360. case MirroredRepeatWrapping:
  2361. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  2362. uv.x = Math.ceil( uv.x ) - uv.x;
  2363. } else {
  2364. uv.x = uv.x - Math.floor( uv.x );
  2365. }
  2366. break;
  2367. }
  2368. }
  2369. if ( uv.y < 0 || uv.y > 1 ) {
  2370. switch ( this.wrapT ) {
  2371. case RepeatWrapping:
  2372. uv.y = uv.y - Math.floor( uv.y );
  2373. break;
  2374. case ClampToEdgeWrapping:
  2375. uv.y = uv.y < 0 ? 0 : 1;
  2376. break;
  2377. case MirroredRepeatWrapping:
  2378. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  2379. uv.y = Math.ceil( uv.y ) - uv.y;
  2380. } else {
  2381. uv.y = uv.y - Math.floor( uv.y );
  2382. }
  2383. break;
  2384. }
  2385. }
  2386. if ( this.flipY ) {
  2387. uv.y = 1 - uv.y;
  2388. }
  2389. }
  2390. } );
  2391. Object.defineProperty( Texture.prototype, "needsUpdate", {
  2392. set: function ( value ) {
  2393. if ( value === true ) this.version ++;
  2394. }
  2395. } );
  2396. /**
  2397. * @author supereggbert / http://www.paulbrunt.co.uk/
  2398. * @author philogb / http://blog.thejit.org/
  2399. * @author mikael emtinger / http://gomo.se/
  2400. * @author egraether / http://egraether.com/
  2401. * @author WestLangley / http://github.com/WestLangley
  2402. */
  2403. function Vector4( x, y, z, w ) {
  2404. this.x = x || 0;
  2405. this.y = y || 0;
  2406. this.z = z || 0;
  2407. this.w = ( w !== undefined ) ? w : 1;
  2408. }
  2409. Object.assign( Vector4.prototype, {
  2410. isVector4: true,
  2411. set: function ( x, y, z, w ) {
  2412. this.x = x;
  2413. this.y = y;
  2414. this.z = z;
  2415. this.w = w;
  2416. return this;
  2417. },
  2418. setScalar: function ( scalar ) {
  2419. this.x = scalar;
  2420. this.y = scalar;
  2421. this.z = scalar;
  2422. this.w = scalar;
  2423. return this;
  2424. },
  2425. setX: function ( x ) {
  2426. this.x = x;
  2427. return this;
  2428. },
  2429. setY: function ( y ) {
  2430. this.y = y;
  2431. return this;
  2432. },
  2433. setZ: function ( z ) {
  2434. this.z = z;
  2435. return this;
  2436. },
  2437. setW: function ( w ) {
  2438. this.w = w;
  2439. return this;
  2440. },
  2441. setComponent: function ( index, value ) {
  2442. switch ( index ) {
  2443. case 0: this.x = value; break;
  2444. case 1: this.y = value; break;
  2445. case 2: this.z = value; break;
  2446. case 3: this.w = value; break;
  2447. default: throw new Error( 'index is out of range: ' + index );
  2448. }
  2449. return this;
  2450. },
  2451. getComponent: function ( index ) {
  2452. switch ( index ) {
  2453. case 0: return this.x;
  2454. case 1: return this.y;
  2455. case 2: return this.z;
  2456. case 3: return this.w;
  2457. default: throw new Error( 'index is out of range: ' + index );
  2458. }
  2459. },
  2460. clone: function () {
  2461. return new this.constructor( this.x, this.y, this.z, this.w );
  2462. },
  2463. copy: function ( v ) {
  2464. this.x = v.x;
  2465. this.y = v.y;
  2466. this.z = v.z;
  2467. this.w = ( v.w !== undefined ) ? v.w : 1;
  2468. return this;
  2469. },
  2470. add: function ( v, w ) {
  2471. if ( w !== undefined ) {
  2472. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  2473. return this.addVectors( v, w );
  2474. }
  2475. this.x += v.x;
  2476. this.y += v.y;
  2477. this.z += v.z;
  2478. this.w += v.w;
  2479. return this;
  2480. },
  2481. addScalar: function ( s ) {
  2482. this.x += s;
  2483. this.y += s;
  2484. this.z += s;
  2485. this.w += s;
  2486. return this;
  2487. },
  2488. addVectors: function ( a, b ) {
  2489. this.x = a.x + b.x;
  2490. this.y = a.y + b.y;
  2491. this.z = a.z + b.z;
  2492. this.w = a.w + b.w;
  2493. return this;
  2494. },
  2495. addScaledVector: function ( v, s ) {
  2496. this.x += v.x * s;
  2497. this.y += v.y * s;
  2498. this.z += v.z * s;
  2499. this.w += v.w * s;
  2500. return this;
  2501. },
  2502. sub: function ( v, w ) {
  2503. if ( w !== undefined ) {
  2504. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  2505. return this.subVectors( v, w );
  2506. }
  2507. this.x -= v.x;
  2508. this.y -= v.y;
  2509. this.z -= v.z;
  2510. this.w -= v.w;
  2511. return this;
  2512. },
  2513. subScalar: function ( s ) {
  2514. this.x -= s;
  2515. this.y -= s;
  2516. this.z -= s;
  2517. this.w -= s;
  2518. return this;
  2519. },
  2520. subVectors: function ( a, b ) {
  2521. this.x = a.x - b.x;
  2522. this.y = a.y - b.y;
  2523. this.z = a.z - b.z;
  2524. this.w = a.w - b.w;
  2525. return this;
  2526. },
  2527. multiplyScalar: function ( scalar ) {
  2528. this.x *= scalar;
  2529. this.y *= scalar;
  2530. this.z *= scalar;
  2531. this.w *= scalar;
  2532. return this;
  2533. },
  2534. applyMatrix4: function ( m ) {
  2535. var x = this.x, y = this.y, z = this.z, w = this.w;
  2536. var e = m.elements;
  2537. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  2538. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  2539. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  2540. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  2541. return this;
  2542. },
  2543. divideScalar: function ( scalar ) {
  2544. return this.multiplyScalar( 1 / scalar );
  2545. },
  2546. setAxisAngleFromQuaternion: function ( q ) {
  2547. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  2548. // q is assumed to be normalized
  2549. this.w = 2 * Math.acos( q.w );
  2550. var s = Math.sqrt( 1 - q.w * q.w );
  2551. if ( s < 0.0001 ) {
  2552. this.x = 1;
  2553. this.y = 0;
  2554. this.z = 0;
  2555. } else {
  2556. this.x = q.x / s;
  2557. this.y = q.y / s;
  2558. this.z = q.z / s;
  2559. }
  2560. return this;
  2561. },
  2562. setAxisAngleFromRotationMatrix: function ( m ) {
  2563. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2564. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2565. var angle, x, y, z, // variables for result
  2566. epsilon = 0.01, // margin to allow for rounding errors
  2567. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  2568. te = m.elements,
  2569. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  2570. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  2571. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2572. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  2573. ( Math.abs( m13 - m31 ) < epsilon ) &&
  2574. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  2575. // singularity found
  2576. // first check for identity matrix which must have +1 for all terms
  2577. // in leading diagonal and zero in other terms
  2578. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  2579. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  2580. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  2581. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  2582. // this singularity is identity matrix so angle = 0
  2583. this.set( 1, 0, 0, 0 );
  2584. return this; // zero angle, arbitrary axis
  2585. }
  2586. // otherwise this singularity is angle = 180
  2587. angle = Math.PI;
  2588. var xx = ( m11 + 1 ) / 2;
  2589. var yy = ( m22 + 1 ) / 2;
  2590. var zz = ( m33 + 1 ) / 2;
  2591. var xy = ( m12 + m21 ) / 4;
  2592. var xz = ( m13 + m31 ) / 4;
  2593. var yz = ( m23 + m32 ) / 4;
  2594. if ( ( xx > yy ) && ( xx > zz ) ) {
  2595. // m11 is the largest diagonal term
  2596. if ( xx < epsilon ) {
  2597. x = 0;
  2598. y = 0.707106781;
  2599. z = 0.707106781;
  2600. } else {
  2601. x = Math.sqrt( xx );
  2602. y = xy / x;
  2603. z = xz / x;
  2604. }
  2605. } else if ( yy > zz ) {
  2606. // m22 is the largest diagonal term
  2607. if ( yy < epsilon ) {
  2608. x = 0.707106781;
  2609. y = 0;
  2610. z = 0.707106781;
  2611. } else {
  2612. y = Math.sqrt( yy );
  2613. x = xy / y;
  2614. z = yz / y;
  2615. }
  2616. } else {
  2617. // m33 is the largest diagonal term so base result on this
  2618. if ( zz < epsilon ) {
  2619. x = 0.707106781;
  2620. y = 0.707106781;
  2621. z = 0;
  2622. } else {
  2623. z = Math.sqrt( zz );
  2624. x = xz / z;
  2625. y = yz / z;
  2626. }
  2627. }
  2628. this.set( x, y, z, angle );
  2629. return this; // return 180 deg rotation
  2630. }
  2631. // as we have reached here there are no singularities so we can handle normally
  2632. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  2633. ( m13 - m31 ) * ( m13 - m31 ) +
  2634. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  2635. if ( Math.abs( s ) < 0.001 ) s = 1;
  2636. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2637. // caught by singularity test above, but I've left it in just in case
  2638. this.x = ( m32 - m23 ) / s;
  2639. this.y = ( m13 - m31 ) / s;
  2640. this.z = ( m21 - m12 ) / s;
  2641. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  2642. return this;
  2643. },
  2644. min: function ( v ) {
  2645. this.x = Math.min( this.x, v.x );
  2646. this.y = Math.min( this.y, v.y );
  2647. this.z = Math.min( this.z, v.z );
  2648. this.w = Math.min( this.w, v.w );
  2649. return this;
  2650. },
  2651. max: function ( v ) {
  2652. this.x = Math.max( this.x, v.x );
  2653. this.y = Math.max( this.y, v.y );
  2654. this.z = Math.max( this.z, v.z );
  2655. this.w = Math.max( this.w, v.w );
  2656. return this;
  2657. },
  2658. clamp: function ( min, max ) {
  2659. // assumes min < max, componentwise
  2660. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2661. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2662. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2663. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  2664. return this;
  2665. },
  2666. clampScalar: function () {
  2667. var min, max;
  2668. return function clampScalar( minVal, maxVal ) {
  2669. if ( min === undefined ) {
  2670. min = new Vector4();
  2671. max = new Vector4();
  2672. }
  2673. min.set( minVal, minVal, minVal, minVal );
  2674. max.set( maxVal, maxVal, maxVal, maxVal );
  2675. return this.clamp( min, max );
  2676. };
  2677. }(),
  2678. clampLength: function ( min, max ) {
  2679. var length = this.length();
  2680. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2681. },
  2682. floor: function () {
  2683. this.x = Math.floor( this.x );
  2684. this.y = Math.floor( this.y );
  2685. this.z = Math.floor( this.z );
  2686. this.w = Math.floor( this.w );
  2687. return this;
  2688. },
  2689. ceil: function () {
  2690. this.x = Math.ceil( this.x );
  2691. this.y = Math.ceil( this.y );
  2692. this.z = Math.ceil( this.z );
  2693. this.w = Math.ceil( this.w );
  2694. return this;
  2695. },
  2696. round: function () {
  2697. this.x = Math.round( this.x );
  2698. this.y = Math.round( this.y );
  2699. this.z = Math.round( this.z );
  2700. this.w = Math.round( this.w );
  2701. return this;
  2702. },
  2703. roundToZero: function () {
  2704. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2705. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2706. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2707. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  2708. return this;
  2709. },
  2710. negate: function () {
  2711. this.x = - this.x;
  2712. this.y = - this.y;
  2713. this.z = - this.z;
  2714. this.w = - this.w;
  2715. return this;
  2716. },
  2717. dot: function ( v ) {
  2718. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2719. },
  2720. lengthSq: function () {
  2721. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2722. },
  2723. length: function () {
  2724. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  2725. },
  2726. manhattanLength: function () {
  2727. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  2728. },
  2729. normalize: function () {
  2730. return this.divideScalar( this.length() || 1 );
  2731. },
  2732. setLength: function ( length ) {
  2733. return this.normalize().multiplyScalar( length );
  2734. },
  2735. lerp: function ( v, alpha ) {
  2736. this.x += ( v.x - this.x ) * alpha;
  2737. this.y += ( v.y - this.y ) * alpha;
  2738. this.z += ( v.z - this.z ) * alpha;
  2739. this.w += ( v.w - this.w ) * alpha;
  2740. return this;
  2741. },
  2742. lerpVectors: function ( v1, v2, alpha ) {
  2743. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  2744. },
  2745. equals: function ( v ) {
  2746. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  2747. },
  2748. fromArray: function ( array, offset ) {
  2749. if ( offset === undefined ) offset = 0;
  2750. this.x = array[ offset ];
  2751. this.y = array[ offset + 1 ];
  2752. this.z = array[ offset + 2 ];
  2753. this.w = array[ offset + 3 ];
  2754. return this;
  2755. },
  2756. toArray: function ( array, offset ) {
  2757. if ( array === undefined ) array = [];
  2758. if ( offset === undefined ) offset = 0;
  2759. array[ offset ] = this.x;
  2760. array[ offset + 1 ] = this.y;
  2761. array[ offset + 2 ] = this.z;
  2762. array[ offset + 3 ] = this.w;
  2763. return array;
  2764. },
  2765. fromBufferAttribute: function ( attribute, index, offset ) {
  2766. if ( offset !== undefined ) {
  2767. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  2768. }
  2769. this.x = attribute.getX( index );
  2770. this.y = attribute.getY( index );
  2771. this.z = attribute.getZ( index );
  2772. this.w = attribute.getW( index );
  2773. return this;
  2774. }
  2775. } );
  2776. /**
  2777. * @author szimek / https://github.com/szimek/
  2778. * @author alteredq / http://alteredqualia.com/
  2779. * @author Marius Kintel / https://github.com/kintel
  2780. */
  2781. /*
  2782. In options, we can specify:
  2783. * Texture parameters for an auto-generated target texture
  2784. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2785. */
  2786. function WebGLRenderTarget( width, height, options ) {
  2787. this.width = width;
  2788. this.height = height;
  2789. this.scissor = new Vector4( 0, 0, width, height );
  2790. this.scissorTest = false;
  2791. this.viewport = new Vector4( 0, 0, width, height );
  2792. options = options || {};
  2793. if ( options.minFilter === undefined ) options.minFilter = LinearFilter;
  2794. this.texture = new Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  2795. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2796. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  2797. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2798. }
  2799. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2800. constructor: WebGLRenderTarget,
  2801. isWebGLRenderTarget: true,
  2802. setSize: function ( width, height ) {
  2803. if ( this.width !== width || this.height !== height ) {
  2804. this.width = width;
  2805. this.height = height;
  2806. this.dispose();
  2807. }
  2808. this.viewport.set( 0, 0, width, height );
  2809. this.scissor.set( 0, 0, width, height );
  2810. },
  2811. clone: function () {
  2812. return new this.constructor().copy( this );
  2813. },
  2814. copy: function ( source ) {
  2815. this.width = source.width;
  2816. this.height = source.height;
  2817. this.viewport.copy( source.viewport );
  2818. this.texture = source.texture.clone();
  2819. this.depthBuffer = source.depthBuffer;
  2820. this.stencilBuffer = source.stencilBuffer;
  2821. this.depthTexture = source.depthTexture;
  2822. return this;
  2823. },
  2824. dispose: function () {
  2825. this.dispatchEvent( { type: 'dispose' } );
  2826. }
  2827. } );
  2828. /**
  2829. * @author alteredq / http://alteredqualia.com
  2830. */
  2831. function WebGLRenderTargetCube( width, height, options ) {
  2832. WebGLRenderTarget.call( this, width, height, options );
  2833. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  2834. this.activeMipMapLevel = 0;
  2835. }
  2836. WebGLRenderTargetCube.prototype = Object.create( WebGLRenderTarget.prototype );
  2837. WebGLRenderTargetCube.prototype.constructor = WebGLRenderTargetCube;
  2838. WebGLRenderTargetCube.prototype.isWebGLRenderTargetCube = true;
  2839. /**
  2840. * @author alteredq / http://alteredqualia.com/
  2841. */
  2842. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  2843. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  2844. this.image = { data: data, width: width, height: height };
  2845. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  2846. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  2847. this.generateMipmaps = false;
  2848. this.flipY = false;
  2849. this.unpackAlignment = 1;
  2850. }
  2851. DataTexture.prototype = Object.create( Texture.prototype );
  2852. DataTexture.prototype.constructor = DataTexture;
  2853. DataTexture.prototype.isDataTexture = true;
  2854. /**
  2855. * @author bhouston / http://clara.io
  2856. * @author WestLangley / http://github.com/WestLangley
  2857. */
  2858. function Box3( min, max ) {
  2859. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  2860. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  2861. }
  2862. Object.assign( Box3.prototype, {
  2863. isBox3: true,
  2864. set: function ( min, max ) {
  2865. this.min.copy( min );
  2866. this.max.copy( max );
  2867. return this;
  2868. },
  2869. setFromArray: function ( array ) {
  2870. var minX = + Infinity;
  2871. var minY = + Infinity;
  2872. var minZ = + Infinity;
  2873. var maxX = - Infinity;
  2874. var maxY = - Infinity;
  2875. var maxZ = - Infinity;
  2876. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  2877. var x = array[ i ];
  2878. var y = array[ i + 1 ];
  2879. var z = array[ i + 2 ];
  2880. if ( x < minX ) minX = x;
  2881. if ( y < minY ) minY = y;
  2882. if ( z < minZ ) minZ = z;
  2883. if ( x > maxX ) maxX = x;
  2884. if ( y > maxY ) maxY = y;
  2885. if ( z > maxZ ) maxZ = z;
  2886. }
  2887. this.min.set( minX, minY, minZ );
  2888. this.max.set( maxX, maxY, maxZ );
  2889. return this;
  2890. },
  2891. setFromBufferAttribute: function ( attribute ) {
  2892. var minX = + Infinity;
  2893. var minY = + Infinity;
  2894. var minZ = + Infinity;
  2895. var maxX = - Infinity;
  2896. var maxY = - Infinity;
  2897. var maxZ = - Infinity;
  2898. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2899. var x = attribute.getX( i );
  2900. var y = attribute.getY( i );
  2901. var z = attribute.getZ( i );
  2902. if ( x < minX ) minX = x;
  2903. if ( y < minY ) minY = y;
  2904. if ( z < minZ ) minZ = z;
  2905. if ( x > maxX ) maxX = x;
  2906. if ( y > maxY ) maxY = y;
  2907. if ( z > maxZ ) maxZ = z;
  2908. }
  2909. this.min.set( minX, minY, minZ );
  2910. this.max.set( maxX, maxY, maxZ );
  2911. return this;
  2912. },
  2913. setFromPoints: function ( points ) {
  2914. this.makeEmpty();
  2915. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2916. this.expandByPoint( points[ i ] );
  2917. }
  2918. return this;
  2919. },
  2920. setFromCenterAndSize: function () {
  2921. var v1 = new Vector3();
  2922. return function setFromCenterAndSize( center, size ) {
  2923. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2924. this.min.copy( center ).sub( halfSize );
  2925. this.max.copy( center ).add( halfSize );
  2926. return this;
  2927. };
  2928. }(),
  2929. setFromObject: function ( object ) {
  2930. this.makeEmpty();
  2931. return this.expandByObject( object );
  2932. },
  2933. clone: function () {
  2934. return new this.constructor().copy( this );
  2935. },
  2936. copy: function ( box ) {
  2937. this.min.copy( box.min );
  2938. this.max.copy( box.max );
  2939. return this;
  2940. },
  2941. makeEmpty: function () {
  2942. this.min.x = this.min.y = this.min.z = + Infinity;
  2943. this.max.x = this.max.y = this.max.z = - Infinity;
  2944. return this;
  2945. },
  2946. isEmpty: function () {
  2947. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2948. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2949. },
  2950. getCenter: function ( target ) {
  2951. if ( target === undefined ) {
  2952. console.warn( 'THREE.Box3: .getCenter() target is now required' );
  2953. target = new Vector3();
  2954. }
  2955. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2956. },
  2957. getSize: function ( target ) {
  2958. if ( target === undefined ) {
  2959. console.warn( 'THREE.Box3: .getSize() target is now required' );
  2960. target = new Vector3();
  2961. }
  2962. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  2963. },
  2964. expandByPoint: function ( point ) {
  2965. this.min.min( point );
  2966. this.max.max( point );
  2967. return this;
  2968. },
  2969. expandByVector: function ( vector ) {
  2970. this.min.sub( vector );
  2971. this.max.add( vector );
  2972. return this;
  2973. },
  2974. expandByScalar: function ( scalar ) {
  2975. this.min.addScalar( - scalar );
  2976. this.max.addScalar( scalar );
  2977. return this;
  2978. },
  2979. expandByObject: function () {
  2980. // Computes the world-axis-aligned bounding box of an object (including its children),
  2981. // accounting for both the object's, and children's, world transforms
  2982. var scope, i, l;
  2983. var v1 = new Vector3();
  2984. function traverse( node ) {
  2985. var geometry = node.geometry;
  2986. if ( geometry !== undefined ) {
  2987. if ( geometry.isGeometry ) {
  2988. var vertices = geometry.vertices;
  2989. for ( i = 0, l = vertices.length; i < l; i ++ ) {
  2990. v1.copy( vertices[ i ] );
  2991. v1.applyMatrix4( node.matrixWorld );
  2992. scope.expandByPoint( v1 );
  2993. }
  2994. } else if ( geometry.isBufferGeometry ) {
  2995. var attribute = geometry.attributes.position;
  2996. if ( attribute !== undefined ) {
  2997. for ( i = 0, l = attribute.count; i < l; i ++ ) {
  2998. v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
  2999. scope.expandByPoint( v1 );
  3000. }
  3001. }
  3002. }
  3003. }
  3004. }
  3005. return function expandByObject( object ) {
  3006. scope = this;
  3007. object.updateMatrixWorld( true );
  3008. object.traverse( traverse );
  3009. return this;
  3010. };
  3011. }(),
  3012. containsPoint: function ( point ) {
  3013. return point.x < this.min.x || point.x > this.max.x ||
  3014. point.y < this.min.y || point.y > this.max.y ||
  3015. point.z < this.min.z || point.z > this.max.z ? false : true;
  3016. },
  3017. containsBox: function ( box ) {
  3018. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  3019. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  3020. this.min.z <= box.min.z && box.max.z <= this.max.z;
  3021. },
  3022. getParameter: function ( point, target ) {
  3023. // This can potentially have a divide by zero if the box
  3024. // has a size dimension of 0.
  3025. if ( target === undefined ) {
  3026. console.warn( 'THREE.Box3: .getParameter() target is now required' );
  3027. target = new Vector3();
  3028. }
  3029. return target.set(
  3030. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  3031. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  3032. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  3033. );
  3034. },
  3035. intersectsBox: function ( box ) {
  3036. // using 6 splitting planes to rule out intersections.
  3037. return box.max.x < this.min.x || box.min.x > this.max.x ||
  3038. box.max.y < this.min.y || box.min.y > this.max.y ||
  3039. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  3040. },
  3041. intersectsSphere: ( function () {
  3042. var closestPoint = new Vector3();
  3043. return function intersectsSphere( sphere ) {
  3044. // Find the point on the AABB closest to the sphere center.
  3045. this.clampPoint( sphere.center, closestPoint );
  3046. // If that point is inside the sphere, the AABB and sphere intersect.
  3047. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  3048. };
  3049. } )(),
  3050. intersectsPlane: function ( plane ) {
  3051. // We compute the minimum and maximum dot product values. If those values
  3052. // are on the same side (back or front) of the plane, then there is no intersection.
  3053. var min, max;
  3054. if ( plane.normal.x > 0 ) {
  3055. min = plane.normal.x * this.min.x;
  3056. max = plane.normal.x * this.max.x;
  3057. } else {
  3058. min = plane.normal.x * this.max.x;
  3059. max = plane.normal.x * this.min.x;
  3060. }
  3061. if ( plane.normal.y > 0 ) {
  3062. min += plane.normal.y * this.min.y;
  3063. max += plane.normal.y * this.max.y;
  3064. } else {
  3065. min += plane.normal.y * this.max.y;
  3066. max += plane.normal.y * this.min.y;
  3067. }
  3068. if ( plane.normal.z > 0 ) {
  3069. min += plane.normal.z * this.min.z;
  3070. max += plane.normal.z * this.max.z;
  3071. } else {
  3072. min += plane.normal.z * this.max.z;
  3073. max += plane.normal.z * this.min.z;
  3074. }
  3075. return ( min <= plane.constant && max >= plane.constant );
  3076. },
  3077. intersectsTriangle: ( function () {
  3078. // triangle centered vertices
  3079. var v0 = new Vector3();
  3080. var v1 = new Vector3();
  3081. var v2 = new Vector3();
  3082. // triangle edge vectors
  3083. var f0 = new Vector3();
  3084. var f1 = new Vector3();
  3085. var f2 = new Vector3();
  3086. var testAxis = new Vector3();
  3087. var center = new Vector3();
  3088. var extents = new Vector3();
  3089. var triangleNormal = new Vector3();
  3090. function satForAxes( axes ) {
  3091. var i, j;
  3092. for ( i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  3093. testAxis.fromArray( axes, i );
  3094. // project the aabb onto the seperating axis
  3095. var r = extents.x * Math.abs( testAxis.x ) + extents.y * Math.abs( testAxis.y ) + extents.z * Math.abs( testAxis.z );
  3096. // project all 3 vertices of the triangle onto the seperating axis
  3097. var p0 = v0.dot( testAxis );
  3098. var p1 = v1.dot( testAxis );
  3099. var p2 = v2.dot( testAxis );
  3100. // actual test, basically see if either of the most extreme of the triangle points intersects r
  3101. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  3102. // points of the projected triangle are outside the projected half-length of the aabb
  3103. // the axis is seperating and we can exit
  3104. return false;
  3105. }
  3106. }
  3107. return true;
  3108. }
  3109. return function intersectsTriangle( triangle ) {
  3110. if ( this.isEmpty() ) {
  3111. return false;
  3112. }
  3113. // compute box center and extents
  3114. this.getCenter( center );
  3115. extents.subVectors( this.max, center );
  3116. // translate triangle to aabb origin
  3117. v0.subVectors( triangle.a, center );
  3118. v1.subVectors( triangle.b, center );
  3119. v2.subVectors( triangle.c, center );
  3120. // compute edge vectors for triangle
  3121. f0.subVectors( v1, v0 );
  3122. f1.subVectors( v2, v1 );
  3123. f2.subVectors( v0, v2 );
  3124. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  3125. // 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
  3126. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3127. var axes = [
  3128. 0, - f0.z, f0.y, 0, - f1.z, f1.y, 0, - f2.z, f2.y,
  3129. f0.z, 0, - f0.x, f1.z, 0, - f1.x, f2.z, 0, - f2.x,
  3130. - f0.y, f0.x, 0, - f1.y, f1.x, 0, - f2.y, f2.x, 0
  3131. ];
  3132. if ( ! satForAxes( axes ) ) {
  3133. return false;
  3134. }
  3135. // test 3 face normals from the aabb
  3136. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  3137. if ( ! satForAxes( axes ) ) {
  3138. return false;
  3139. }
  3140. // finally testing the face normal of the triangle
  3141. // use already existing triangle edge vectors here
  3142. triangleNormal.crossVectors( f0, f1 );
  3143. axes = [ triangleNormal.x, triangleNormal.y, triangleNormal.z ];
  3144. return satForAxes( axes );
  3145. };
  3146. } )(),
  3147. clampPoint: function ( point, target ) {
  3148. if ( target === undefined ) {
  3149. console.warn( 'THREE.Box3: .clampPoint() target is now required' );
  3150. target = new Vector3();
  3151. }
  3152. return target.copy( point ).clamp( this.min, this.max );
  3153. },
  3154. distanceToPoint: function () {
  3155. var v1 = new Vector3();
  3156. return function distanceToPoint( point ) {
  3157. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  3158. return clampedPoint.sub( point ).length();
  3159. };
  3160. }(),
  3161. getBoundingSphere: function () {
  3162. var v1 = new Vector3();
  3163. return function getBoundingSphere( target ) {
  3164. if ( target === undefined ) {
  3165. console.warn( 'THREE.Box3: .getBoundingSphere() target is now required' );
  3166. target = new Sphere();
  3167. }
  3168. this.getCenter( target.center );
  3169. target.radius = this.getSize( v1 ).length() * 0.5;
  3170. return target;
  3171. };
  3172. }(),
  3173. intersect: function ( box ) {
  3174. this.min.max( box.min );
  3175. this.max.min( box.max );
  3176. // 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.
  3177. if ( this.isEmpty() ) this.makeEmpty();
  3178. return this;
  3179. },
  3180. union: function ( box ) {
  3181. this.min.min( box.min );
  3182. this.max.max( box.max );
  3183. return this;
  3184. },
  3185. applyMatrix4: function () {
  3186. var points = [
  3187. new Vector3(),
  3188. new Vector3(),
  3189. new Vector3(),
  3190. new Vector3(),
  3191. new Vector3(),
  3192. new Vector3(),
  3193. new Vector3(),
  3194. new Vector3()
  3195. ];
  3196. return function applyMatrix4( matrix ) {
  3197. // transform of empty box is an empty box.
  3198. if ( this.isEmpty() ) return this;
  3199. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  3200. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  3201. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  3202. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  3203. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  3204. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  3205. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  3206. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  3207. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  3208. this.setFromPoints( points );
  3209. return this;
  3210. };
  3211. }(),
  3212. translate: function ( offset ) {
  3213. this.min.add( offset );
  3214. this.max.add( offset );
  3215. return this;
  3216. },
  3217. equals: function ( box ) {
  3218. return box.min.equals( this.min ) && box.max.equals( this.max );
  3219. }
  3220. } );
  3221. /**
  3222. * @author bhouston / http://clara.io
  3223. * @author mrdoob / http://mrdoob.com/
  3224. */
  3225. function Sphere( center, radius ) {
  3226. this.center = ( center !== undefined ) ? center : new Vector3();
  3227. this.radius = ( radius !== undefined ) ? radius : 0;
  3228. }
  3229. Object.assign( Sphere.prototype, {
  3230. set: function ( center, radius ) {
  3231. this.center.copy( center );
  3232. this.radius = radius;
  3233. return this;
  3234. },
  3235. setFromPoints: function () {
  3236. var box = new Box3();
  3237. return function setFromPoints( points, optionalCenter ) {
  3238. var center = this.center;
  3239. if ( optionalCenter !== undefined ) {
  3240. center.copy( optionalCenter );
  3241. } else {
  3242. box.setFromPoints( points ).getCenter( center );
  3243. }
  3244. var maxRadiusSq = 0;
  3245. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3246. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3247. }
  3248. this.radius = Math.sqrt( maxRadiusSq );
  3249. return this;
  3250. };
  3251. }(),
  3252. clone: function () {
  3253. return new this.constructor().copy( this );
  3254. },
  3255. copy: function ( sphere ) {
  3256. this.center.copy( sphere.center );
  3257. this.radius = sphere.radius;
  3258. return this;
  3259. },
  3260. empty: function () {
  3261. return ( this.radius <= 0 );
  3262. },
  3263. containsPoint: function ( point ) {
  3264. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3265. },
  3266. distanceToPoint: function ( point ) {
  3267. return ( point.distanceTo( this.center ) - this.radius );
  3268. },
  3269. intersectsSphere: function ( sphere ) {
  3270. var radiusSum = this.radius + sphere.radius;
  3271. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3272. },
  3273. intersectsBox: function ( box ) {
  3274. return box.intersectsSphere( this );
  3275. },
  3276. intersectsPlane: function ( plane ) {
  3277. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  3278. },
  3279. clampPoint: function ( point, target ) {
  3280. var deltaLengthSq = this.center.distanceToSquared( point );
  3281. if ( target === undefined ) {
  3282. console.warn( 'THREE.Sphere: .clampPoint() target is now required' );
  3283. target = new Vector3();
  3284. }
  3285. target.copy( point );
  3286. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3287. target.sub( this.center ).normalize();
  3288. target.multiplyScalar( this.radius ).add( this.center );
  3289. }
  3290. return target;
  3291. },
  3292. getBoundingBox: function ( target ) {
  3293. if ( target === undefined ) {
  3294. console.warn( 'THREE.Sphere: .getBoundingBox() target is now required' );
  3295. target = new Box3();
  3296. }
  3297. target.set( this.center, this.center );
  3298. target.expandByScalar( this.radius );
  3299. return target;
  3300. },
  3301. applyMatrix4: function ( matrix ) {
  3302. this.center.applyMatrix4( matrix );
  3303. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3304. return this;
  3305. },
  3306. translate: function ( offset ) {
  3307. this.center.add( offset );
  3308. return this;
  3309. },
  3310. equals: function ( sphere ) {
  3311. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3312. }
  3313. } );
  3314. /**
  3315. * @author bhouston / http://clara.io
  3316. */
  3317. function Plane( normal, constant ) {
  3318. // normal is assumed to be normalized
  3319. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  3320. this.constant = ( constant !== undefined ) ? constant : 0;
  3321. }
  3322. Object.assign( Plane.prototype, {
  3323. set: function ( normal, constant ) {
  3324. this.normal.copy( normal );
  3325. this.constant = constant;
  3326. return this;
  3327. },
  3328. setComponents: function ( x, y, z, w ) {
  3329. this.normal.set( x, y, z );
  3330. this.constant = w;
  3331. return this;
  3332. },
  3333. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3334. this.normal.copy( normal );
  3335. this.constant = - point.dot( this.normal );
  3336. return this;
  3337. },
  3338. setFromCoplanarPoints: function () {
  3339. var v1 = new Vector3();
  3340. var v2 = new Vector3();
  3341. return function setFromCoplanarPoints( a, b, c ) {
  3342. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3343. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3344. this.setFromNormalAndCoplanarPoint( normal, a );
  3345. return this;
  3346. };
  3347. }(),
  3348. clone: function () {
  3349. return new this.constructor().copy( this );
  3350. },
  3351. copy: function ( plane ) {
  3352. this.normal.copy( plane.normal );
  3353. this.constant = plane.constant;
  3354. return this;
  3355. },
  3356. normalize: function () {
  3357. // Note: will lead to a divide by zero if the plane is invalid.
  3358. var inverseNormalLength = 1.0 / this.normal.length();
  3359. this.normal.multiplyScalar( inverseNormalLength );
  3360. this.constant *= inverseNormalLength;
  3361. return this;
  3362. },
  3363. negate: function () {
  3364. this.constant *= - 1;
  3365. this.normal.negate();
  3366. return this;
  3367. },
  3368. distanceToPoint: function ( point ) {
  3369. return this.normal.dot( point ) + this.constant;
  3370. },
  3371. distanceToSphere: function ( sphere ) {
  3372. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3373. },
  3374. projectPoint: function ( point, target ) {
  3375. if ( target === undefined ) {
  3376. console.warn( 'THREE.Plane: .projectPoint() target is now required' );
  3377. target = new Vector3();
  3378. }
  3379. return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  3380. },
  3381. intersectLine: function () {
  3382. var v1 = new Vector3();
  3383. return function intersectLine( line, target ) {
  3384. if ( target === undefined ) {
  3385. console.warn( 'THREE.Plane: .intersectLine() target is now required' );
  3386. target = new Vector3();
  3387. }
  3388. var direction = line.delta( v1 );
  3389. var denominator = this.normal.dot( direction );
  3390. if ( denominator === 0 ) {
  3391. // line is coplanar, return origin
  3392. if ( this.distanceToPoint( line.start ) === 0 ) {
  3393. return target.copy( line.start );
  3394. }
  3395. // Unsure if this is the correct method to handle this case.
  3396. return undefined;
  3397. }
  3398. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  3399. if ( t < 0 || t > 1 ) {
  3400. return undefined;
  3401. }
  3402. return target.copy( direction ).multiplyScalar( t ).add( line.start );
  3403. };
  3404. }(),
  3405. intersectsLine: function ( line ) {
  3406. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  3407. var startSign = this.distanceToPoint( line.start );
  3408. var endSign = this.distanceToPoint( line.end );
  3409. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  3410. },
  3411. intersectsBox: function ( box ) {
  3412. return box.intersectsPlane( this );
  3413. },
  3414. intersectsSphere: function ( sphere ) {
  3415. return sphere.intersectsPlane( this );
  3416. },
  3417. coplanarPoint: function ( target ) {
  3418. if ( target === undefined ) {
  3419. console.warn( 'THREE.Plane: .coplanarPoint() target is now required' );
  3420. target = new Vector3();
  3421. }
  3422. return target.copy( this.normal ).multiplyScalar( - this.constant );
  3423. },
  3424. applyMatrix4: function () {
  3425. var v1 = new Vector3();
  3426. var m1 = new Matrix3();
  3427. return function applyMatrix4( matrix, optionalNormalMatrix ) {
  3428. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  3429. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  3430. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  3431. this.constant = - referencePoint.dot( normal );
  3432. return this;
  3433. };
  3434. }(),
  3435. translate: function ( offset ) {
  3436. this.constant -= offset.dot( this.normal );
  3437. return this;
  3438. },
  3439. equals: function ( plane ) {
  3440. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  3441. }
  3442. } );
  3443. /**
  3444. * @author mrdoob / http://mrdoob.com/
  3445. * @author alteredq / http://alteredqualia.com/
  3446. * @author bhouston / http://clara.io
  3447. */
  3448. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  3449. this.planes = [
  3450. ( p0 !== undefined ) ? p0 : new Plane(),
  3451. ( p1 !== undefined ) ? p1 : new Plane(),
  3452. ( p2 !== undefined ) ? p2 : new Plane(),
  3453. ( p3 !== undefined ) ? p3 : new Plane(),
  3454. ( p4 !== undefined ) ? p4 : new Plane(),
  3455. ( p5 !== undefined ) ? p5 : new Plane()
  3456. ];
  3457. }
  3458. Object.assign( Frustum.prototype, {
  3459. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3460. var planes = this.planes;
  3461. planes[ 0 ].copy( p0 );
  3462. planes[ 1 ].copy( p1 );
  3463. planes[ 2 ].copy( p2 );
  3464. planes[ 3 ].copy( p3 );
  3465. planes[ 4 ].copy( p4 );
  3466. planes[ 5 ].copy( p5 );
  3467. return this;
  3468. },
  3469. clone: function () {
  3470. return new this.constructor().copy( this );
  3471. },
  3472. copy: function ( frustum ) {
  3473. var planes = this.planes;
  3474. for ( var i = 0; i < 6; i ++ ) {
  3475. planes[ i ].copy( frustum.planes[ i ] );
  3476. }
  3477. return this;
  3478. },
  3479. setFromMatrix: function ( m ) {
  3480. var planes = this.planes;
  3481. var me = m.elements;
  3482. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3483. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3484. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3485. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3486. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3487. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3488. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3489. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3490. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3491. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3492. return this;
  3493. },
  3494. intersectsObject: function () {
  3495. var sphere = new Sphere();
  3496. return function intersectsObject( object ) {
  3497. var geometry = object.geometry;
  3498. if ( geometry.boundingSphere === null )
  3499. geometry.computeBoundingSphere();
  3500. sphere.copy( geometry.boundingSphere )
  3501. .applyMatrix4( object.matrixWorld );
  3502. return this.intersectsSphere( sphere );
  3503. };
  3504. }(),
  3505. intersectsSprite: function () {
  3506. var sphere = new Sphere();
  3507. return function intersectsSprite( sprite ) {
  3508. sphere.center.set( 0, 0, 0 );
  3509. sphere.radius = 0.7071067811865476;
  3510. sphere.applyMatrix4( sprite.matrixWorld );
  3511. return this.intersectsSphere( sphere );
  3512. };
  3513. }(),
  3514. intersectsSphere: function ( sphere ) {
  3515. var planes = this.planes;
  3516. var center = sphere.center;
  3517. var negRadius = - sphere.radius;
  3518. for ( var i = 0; i < 6; i ++ ) {
  3519. var distance = planes[ i ].distanceToPoint( center );
  3520. if ( distance < negRadius ) {
  3521. return false;
  3522. }
  3523. }
  3524. return true;
  3525. },
  3526. intersectsBox: function () {
  3527. var p1 = new Vector3(),
  3528. p2 = new Vector3();
  3529. return function intersectsBox( box ) {
  3530. var planes = this.planes;
  3531. for ( var i = 0; i < 6; i ++ ) {
  3532. var plane = planes[ i ];
  3533. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3534. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3535. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3536. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3537. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3538. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3539. var d1 = plane.distanceToPoint( p1 );
  3540. var d2 = plane.distanceToPoint( p2 );
  3541. // if both outside plane, no intersection
  3542. if ( d1 < 0 && d2 < 0 ) {
  3543. return false;
  3544. }
  3545. }
  3546. return true;
  3547. };
  3548. }(),
  3549. containsPoint: function ( point ) {
  3550. var planes = this.planes;
  3551. for ( var i = 0; i < 6; i ++ ) {
  3552. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3553. return false;
  3554. }
  3555. }
  3556. return true;
  3557. }
  3558. } );
  3559. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif\n";
  3560. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif\n";
  3561. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif\n";
  3562. 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\n";
  3563. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  3564. var begin_vertex = "\nvec3 transformed = vec3( position );\n";
  3565. var beginnormal_vertex = "\nvec3 objectNormal = vec3( normal );\n";
  3566. var bsdfs = "float punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n\tif( decayExponent > 0.0 ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\t\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\t\tfloat maxDistanceCutoffFactor = pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t\treturn distanceFalloff * maxDistanceCutoffFactor;\n#else\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n#endif\n\t}\n\treturn 1.0;\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}\n";
  3567. 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\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif\n";
  3568. 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\n";
  3569. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\t#if ! defined( PHYSICAL ) && ! defined( PHONG )\n\t\tvarying vec3 vViewPosition;\n\t#endif\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif\n";
  3570. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n\tvarying vec3 vViewPosition;\n#endif\n";
  3571. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n";
  3572. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  3573. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif\n";
  3574. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  3575. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  3576. 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}\n";
  3577. 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(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\n";
  3578. var defaultnormal_vertex = "vec3 transformedNormal = normalMatrix * objectNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n";
  3579. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif\n";
  3580. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif\n";
  3581. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif\n";
  3582. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif\n";
  3583. var encodings_fragment = " gl_FragColor = linearToOutputTexel( gl_FragColor );\n";
  3584. 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.xyz, vec3( gammaFactor ) ), value.w );\n}\nvec4 LinearToGamma( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );\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.w );\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.w );\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.xyz * value.w * maxRange, 1.0 );\n}\nvec4 LinearToRGBM( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.x, 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.x, 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}\n";
  3585. 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\n";
  3586. 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\n";
  3587. 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\n";
  3588. 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\n";
  3589. var fog_vertex = "\n#ifdef USE_FOG\nfogDepth = -mvPosition.z;\n#endif";
  3590. var fog_pars_vertex = "#ifdef USE_FOG\n varying float fogDepth;\n#endif\n";
  3591. 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\n";
  3592. 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\n";
  3593. 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\n";
  3594. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\treflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif\n";
  3595. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  3596. 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\n";
  3597. 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\n";
  3598. var lights_pars_maps = "#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( 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(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\n";
  3599. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;\n";
  3600. 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)\n";
  3601. 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\n";
  3602. 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}\n";
  3603. 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\n";
  3604. 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\n";
  3605. 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\n";
  3606. var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";
  3607. var logdepthbuf_pars_fragment = "#ifdef USE_LOGDEPTHBUF\n\tuniform float logDepthBufFC;\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t#endif\n#endif\n";
  3608. var logdepthbuf_pars_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t#endif\n\tuniform float logDepthBufFC;\n#endif";
  3609. 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\n";
  3610. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif\n";
  3611. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n";
  3612. 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\n";
  3613. var map_particle_pars_fragment = "#ifdef USE_MAP\n\tuniform mat3 uvTransform;\n\tuniform sampler2D map;\n#endif\n";
  3614. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif\n";
  3615. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  3616. 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\n";
  3617. 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";
  3618. 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\n";
  3619. 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\n";
  3620. var normal_fragment_maps = "#ifdef USE_NORMALMAP\n\tnormal = perturbNormal2Arb( -vViewPosition, normal );\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif\n";
  3621. var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {\n\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\tvec2 st0 = dFdx( vUv.st );\n\t\tvec2 st1 = dFdy( vUv.st );\n\t\tfloat scale = sign( st1.t * st0.s - st0.t * st1.s );\t\tscale *= float( gl_FrontFacing ) * 2.0 - 1.0;\n\t\tvec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );\n\t\tvec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );\n\t\tvec3 N = normalize( surf_norm );\n\t\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\tmapN.xy = normalScale * mapN.xy;\n\t\tmat3 tsn = mat3( S, T, N );\n\t\treturn normalize( tsn * mapN );\n\t}\n#endif\n";
  3622. 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}\n";
  3623. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif\n";
  3624. var project_vertex = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = projectionMatrix * mvPosition;\n";
  3625. var dithering_fragment = "#if defined( DITHERING )\n gl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif\n";
  3626. 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\n";
  3627. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif\n";
  3628. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  3629. 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\n";
  3630. 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\n";
  3631. 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\n";
  3632. 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}\n";
  3633. 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";
  3634. 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\n";
  3635. 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\n";
  3636. 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\n";
  3637. 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";
  3638. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  3639. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif\n";
  3640. 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}\n";
  3641. 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";
  3642. 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\n";
  3643. 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";
  3644. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  3645. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n#endif";
  3646. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = uv2;\n#endif";
  3647. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n#endif\n";
  3648. var cube_frag = "uniform samplerCube tCube;\nuniform float tFlip;\nuniform float opacity;\nvarying vec3 vWorldPosition;\nvoid main() {\n\tgl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );\n\tgl_FragColor.a *= opacity;\n}\n";
  3649. var cube_vert = "varying vec3 vWorldPosition;\n#include <common>\nvoid main() {\n\tvWorldPosition = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}\n";
  3650. 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}\n";
  3651. 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}\n";
  3652. 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}\n";
  3653. 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}\n";
  3654. var equirect_frag = "uniform sampler2D tEquirect;\nvarying vec3 vWorldPosition;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldPosition );\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\tgl_FragColor = texture2D( tEquirect, sampleUV );\n}\n";
  3655. var equirect_vert = "varying vec3 vWorldPosition;\n#include <common>\nvoid main() {\n\tvWorldPosition = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}\n";
  3656. 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}\n";
  3657. 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}\n";
  3658. 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}\n";
  3659. 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}\n";
  3660. 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 <lights_pars_maps>\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}\n";
  3661. 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 <lights_pars_maps>\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}\n";
  3662. 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_pars_maps>\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}\n";
  3663. 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}\n";
  3664. 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 <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <cube_uv_reflection_fragment>\n#include <lights_pars_begin>\n#include <lights_pars_maps>\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}\n";
  3665. 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}\n";
  3666. var normal_frag = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_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}\n";
  3667. var normal_vert = "#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_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 )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}\n";
  3668. var points_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <fog_pars_fragment>\n#include <shadowmap_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}\n";
  3669. var points_vert = "uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <shadowmap_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 <project_vertex>\n\t#ifdef USE_SIZEATTENUATION\n\t\tgl_PointSize = size * ( scale / - mvPosition.z );\n\t#else\n\t\tgl_PointSize = size;\n\t#endif\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}\n";
  3670. 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}\n";
  3671. 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}\n";
  3672. var ShaderChunk = {
  3673. alphamap_fragment: alphamap_fragment,
  3674. alphamap_pars_fragment: alphamap_pars_fragment,
  3675. alphatest_fragment: alphatest_fragment,
  3676. aomap_fragment: aomap_fragment,
  3677. aomap_pars_fragment: aomap_pars_fragment,
  3678. begin_vertex: begin_vertex,
  3679. beginnormal_vertex: beginnormal_vertex,
  3680. bsdfs: bsdfs,
  3681. bumpmap_pars_fragment: bumpmap_pars_fragment,
  3682. clipping_planes_fragment: clipping_planes_fragment,
  3683. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  3684. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  3685. clipping_planes_vertex: clipping_planes_vertex,
  3686. color_fragment: color_fragment,
  3687. color_pars_fragment: color_pars_fragment,
  3688. color_pars_vertex: color_pars_vertex,
  3689. color_vertex: color_vertex,
  3690. common: common,
  3691. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  3692. defaultnormal_vertex: defaultnormal_vertex,
  3693. displacementmap_pars_vertex: displacementmap_pars_vertex,
  3694. displacementmap_vertex: displacementmap_vertex,
  3695. emissivemap_fragment: emissivemap_fragment,
  3696. emissivemap_pars_fragment: emissivemap_pars_fragment,
  3697. encodings_fragment: encodings_fragment,
  3698. encodings_pars_fragment: encodings_pars_fragment,
  3699. envmap_fragment: envmap_fragment,
  3700. envmap_pars_fragment: envmap_pars_fragment,
  3701. envmap_pars_vertex: envmap_pars_vertex,
  3702. envmap_vertex: envmap_vertex,
  3703. fog_vertex: fog_vertex,
  3704. fog_pars_vertex: fog_pars_vertex,
  3705. fog_fragment: fog_fragment,
  3706. fog_pars_fragment: fog_pars_fragment,
  3707. gradientmap_pars_fragment: gradientmap_pars_fragment,
  3708. lightmap_fragment: lightmap_fragment,
  3709. lightmap_pars_fragment: lightmap_pars_fragment,
  3710. lights_lambert_vertex: lights_lambert_vertex,
  3711. lights_pars_begin: lights_pars_begin,
  3712. lights_pars_maps: lights_pars_maps,
  3713. lights_phong_fragment: lights_phong_fragment,
  3714. lights_phong_pars_fragment: lights_phong_pars_fragment,
  3715. lights_physical_fragment: lights_physical_fragment,
  3716. lights_physical_pars_fragment: lights_physical_pars_fragment,
  3717. lights_fragment_begin: lights_fragment_begin,
  3718. lights_fragment_maps: lights_fragment_maps,
  3719. lights_fragment_end: lights_fragment_end,
  3720. logdepthbuf_fragment: logdepthbuf_fragment,
  3721. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  3722. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  3723. logdepthbuf_vertex: logdepthbuf_vertex,
  3724. map_fragment: map_fragment,
  3725. map_pars_fragment: map_pars_fragment,
  3726. map_particle_fragment: map_particle_fragment,
  3727. map_particle_pars_fragment: map_particle_pars_fragment,
  3728. metalnessmap_fragment: metalnessmap_fragment,
  3729. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  3730. morphnormal_vertex: morphnormal_vertex,
  3731. morphtarget_pars_vertex: morphtarget_pars_vertex,
  3732. morphtarget_vertex: morphtarget_vertex,
  3733. normal_fragment_begin: normal_fragment_begin,
  3734. normal_fragment_maps: normal_fragment_maps,
  3735. normalmap_pars_fragment: normalmap_pars_fragment,
  3736. packing: packing,
  3737. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  3738. project_vertex: project_vertex,
  3739. dithering_fragment: dithering_fragment,
  3740. dithering_pars_fragment: dithering_pars_fragment,
  3741. roughnessmap_fragment: roughnessmap_fragment,
  3742. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  3743. shadowmap_pars_fragment: shadowmap_pars_fragment,
  3744. shadowmap_pars_vertex: shadowmap_pars_vertex,
  3745. shadowmap_vertex: shadowmap_vertex,
  3746. shadowmask_pars_fragment: shadowmask_pars_fragment,
  3747. skinbase_vertex: skinbase_vertex,
  3748. skinning_pars_vertex: skinning_pars_vertex,
  3749. skinning_vertex: skinning_vertex,
  3750. skinnormal_vertex: skinnormal_vertex,
  3751. specularmap_fragment: specularmap_fragment,
  3752. specularmap_pars_fragment: specularmap_pars_fragment,
  3753. tonemapping_fragment: tonemapping_fragment,
  3754. tonemapping_pars_fragment: tonemapping_pars_fragment,
  3755. uv_pars_fragment: uv_pars_fragment,
  3756. uv_pars_vertex: uv_pars_vertex,
  3757. uv_vertex: uv_vertex,
  3758. uv2_pars_fragment: uv2_pars_fragment,
  3759. uv2_pars_vertex: uv2_pars_vertex,
  3760. uv2_vertex: uv2_vertex,
  3761. worldpos_vertex: worldpos_vertex,
  3762. cube_frag: cube_frag,
  3763. cube_vert: cube_vert,
  3764. depth_frag: depth_frag,
  3765. depth_vert: depth_vert,
  3766. distanceRGBA_frag: distanceRGBA_frag,
  3767. distanceRGBA_vert: distanceRGBA_vert,
  3768. equirect_frag: equirect_frag,
  3769. equirect_vert: equirect_vert,
  3770. linedashed_frag: linedashed_frag,
  3771. linedashed_vert: linedashed_vert,
  3772. meshbasic_frag: meshbasic_frag,
  3773. meshbasic_vert: meshbasic_vert,
  3774. meshlambert_frag: meshlambert_frag,
  3775. meshlambert_vert: meshlambert_vert,
  3776. meshphong_frag: meshphong_frag,
  3777. meshphong_vert: meshphong_vert,
  3778. meshphysical_frag: meshphysical_frag,
  3779. meshphysical_vert: meshphysical_vert,
  3780. normal_frag: normal_frag,
  3781. normal_vert: normal_vert,
  3782. points_frag: points_frag,
  3783. points_vert: points_vert,
  3784. shadow_frag: shadow_frag,
  3785. shadow_vert: shadow_vert
  3786. };
  3787. /**
  3788. * Uniform Utilities
  3789. */
  3790. var UniformsUtils = {
  3791. merge: function ( uniforms ) {
  3792. var merged = {};
  3793. for ( var u = 0; u < uniforms.length; u ++ ) {
  3794. var tmp = this.clone( uniforms[ u ] );
  3795. for ( var p in tmp ) {
  3796. merged[ p ] = tmp[ p ];
  3797. }
  3798. }
  3799. return merged;
  3800. },
  3801. clone: function ( uniforms_src ) {
  3802. var uniforms_dst = {};
  3803. for ( var u in uniforms_src ) {
  3804. uniforms_dst[ u ] = {};
  3805. for ( var p in uniforms_src[ u ] ) {
  3806. var parameter_src = uniforms_src[ u ][ p ];
  3807. if ( parameter_src && ( parameter_src.isColor ||
  3808. parameter_src.isMatrix3 || parameter_src.isMatrix4 ||
  3809. parameter_src.isVector2 || parameter_src.isVector3 || parameter_src.isVector4 ||
  3810. parameter_src.isTexture ) ) {
  3811. uniforms_dst[ u ][ p ] = parameter_src.clone();
  3812. } else if ( Array.isArray( parameter_src ) ) {
  3813. uniforms_dst[ u ][ p ] = parameter_src.slice();
  3814. } else {
  3815. uniforms_dst[ u ][ p ] = parameter_src;
  3816. }
  3817. }
  3818. }
  3819. return uniforms_dst;
  3820. }
  3821. };
  3822. /**
  3823. * @author mrdoob / http://mrdoob.com/
  3824. */
  3825. var ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  3826. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  3827. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  3828. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  3829. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  3830. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  3831. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  3832. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  3833. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  3834. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  3835. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  3836. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  3837. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  3838. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  3839. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  3840. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  3841. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  3842. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  3843. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  3844. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  3845. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  3846. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  3847. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  3848. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  3849. function Color( r, g, b ) {
  3850. if ( g === undefined && b === undefined ) {
  3851. // r is THREE.Color, hex or string
  3852. return this.set( r );
  3853. }
  3854. return this.setRGB( r, g, b );
  3855. }
  3856. Object.assign( Color.prototype, {
  3857. isColor: true,
  3858. r: 1, g: 1, b: 1,
  3859. set: function ( value ) {
  3860. if ( value && value.isColor ) {
  3861. this.copy( value );
  3862. } else if ( typeof value === 'number' ) {
  3863. this.setHex( value );
  3864. } else if ( typeof value === 'string' ) {
  3865. this.setStyle( value );
  3866. }
  3867. return this;
  3868. },
  3869. setScalar: function ( scalar ) {
  3870. this.r = scalar;
  3871. this.g = scalar;
  3872. this.b = scalar;
  3873. return this;
  3874. },
  3875. setHex: function ( hex ) {
  3876. hex = Math.floor( hex );
  3877. this.r = ( hex >> 16 & 255 ) / 255;
  3878. this.g = ( hex >> 8 & 255 ) / 255;
  3879. this.b = ( hex & 255 ) / 255;
  3880. return this;
  3881. },
  3882. setRGB: function ( r, g, b ) {
  3883. this.r = r;
  3884. this.g = g;
  3885. this.b = b;
  3886. return this;
  3887. },
  3888. setHSL: function () {
  3889. function hue2rgb( p, q, t ) {
  3890. if ( t < 0 ) t += 1;
  3891. if ( t > 1 ) t -= 1;
  3892. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  3893. if ( t < 1 / 2 ) return q;
  3894. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  3895. return p;
  3896. }
  3897. return function setHSL( h, s, l ) {
  3898. // h,s,l ranges are in 0.0 - 1.0
  3899. h = _Math.euclideanModulo( h, 1 );
  3900. s = _Math.clamp( s, 0, 1 );
  3901. l = _Math.clamp( l, 0, 1 );
  3902. if ( s === 0 ) {
  3903. this.r = this.g = this.b = l;
  3904. } else {
  3905. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  3906. var q = ( 2 * l ) - p;
  3907. this.r = hue2rgb( q, p, h + 1 / 3 );
  3908. this.g = hue2rgb( q, p, h );
  3909. this.b = hue2rgb( q, p, h - 1 / 3 );
  3910. }
  3911. return this;
  3912. };
  3913. }(),
  3914. setStyle: function ( style ) {
  3915. function handleAlpha( string ) {
  3916. if ( string === undefined ) return;
  3917. if ( parseFloat( string ) < 1 ) {
  3918. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  3919. }
  3920. }
  3921. var m;
  3922. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  3923. // rgb / hsl
  3924. var color;
  3925. var name = m[ 1 ];
  3926. var components = m[ 2 ];
  3927. switch ( name ) {
  3928. case 'rgb':
  3929. case 'rgba':
  3930. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  3931. // rgb(255,0,0) rgba(255,0,0,0.5)
  3932. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  3933. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  3934. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  3935. handleAlpha( color[ 5 ] );
  3936. return this;
  3937. }
  3938. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  3939. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  3940. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  3941. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  3942. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  3943. handleAlpha( color[ 5 ] );
  3944. return this;
  3945. }
  3946. break;
  3947. case 'hsl':
  3948. case 'hsla':
  3949. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  3950. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  3951. var h = parseFloat( color[ 1 ] ) / 360;
  3952. var s = parseInt( color[ 2 ], 10 ) / 100;
  3953. var l = parseInt( color[ 3 ], 10 ) / 100;
  3954. handleAlpha( color[ 5 ] );
  3955. return this.setHSL( h, s, l );
  3956. }
  3957. break;
  3958. }
  3959. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  3960. // hex color
  3961. var hex = m[ 1 ];
  3962. var size = hex.length;
  3963. if ( size === 3 ) {
  3964. // #ff0
  3965. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  3966. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  3967. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  3968. return this;
  3969. } else if ( size === 6 ) {
  3970. // #ff0000
  3971. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  3972. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  3973. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  3974. return this;
  3975. }
  3976. }
  3977. if ( style && style.length > 0 ) {
  3978. // color keywords
  3979. var hex = ColorKeywords[ style ];
  3980. if ( hex !== undefined ) {
  3981. // red
  3982. this.setHex( hex );
  3983. } else {
  3984. // unknown color
  3985. console.warn( 'THREE.Color: Unknown color ' + style );
  3986. }
  3987. }
  3988. return this;
  3989. },
  3990. clone: function () {
  3991. return new this.constructor( this.r, this.g, this.b );
  3992. },
  3993. copy: function ( color ) {
  3994. this.r = color.r;
  3995. this.g = color.g;
  3996. this.b = color.b;
  3997. return this;
  3998. },
  3999. copyGammaToLinear: function ( color, gammaFactor ) {
  4000. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4001. this.r = Math.pow( color.r, gammaFactor );
  4002. this.g = Math.pow( color.g, gammaFactor );
  4003. this.b = Math.pow( color.b, gammaFactor );
  4004. return this;
  4005. },
  4006. copyLinearToGamma: function ( color, gammaFactor ) {
  4007. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4008. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  4009. this.r = Math.pow( color.r, safeInverse );
  4010. this.g = Math.pow( color.g, safeInverse );
  4011. this.b = Math.pow( color.b, safeInverse );
  4012. return this;
  4013. },
  4014. convertGammaToLinear: function () {
  4015. var r = this.r, g = this.g, b = this.b;
  4016. this.r = r * r;
  4017. this.g = g * g;
  4018. this.b = b * b;
  4019. return this;
  4020. },
  4021. convertLinearToGamma: function () {
  4022. this.r = Math.sqrt( this.r );
  4023. this.g = Math.sqrt( this.g );
  4024. this.b = Math.sqrt( this.b );
  4025. return this;
  4026. },
  4027. getHex: function () {
  4028. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  4029. },
  4030. getHexString: function () {
  4031. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  4032. },
  4033. getHSL: function ( target ) {
  4034. // h,s,l ranges are in 0.0 - 1.0
  4035. if ( target === undefined ) {
  4036. console.warn( 'THREE.Color: .getHSL() target is now required' );
  4037. target = { h: 0, s: 0, l: 0 };
  4038. }
  4039. var r = this.r, g = this.g, b = this.b;
  4040. var max = Math.max( r, g, b );
  4041. var min = Math.min( r, g, b );
  4042. var hue, saturation;
  4043. var lightness = ( min + max ) / 2.0;
  4044. if ( min === max ) {
  4045. hue = 0;
  4046. saturation = 0;
  4047. } else {
  4048. var delta = max - min;
  4049. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  4050. switch ( max ) {
  4051. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  4052. case g: hue = ( b - r ) / delta + 2; break;
  4053. case b: hue = ( r - g ) / delta + 4; break;
  4054. }
  4055. hue /= 6;
  4056. }
  4057. target.h = hue;
  4058. target.s = saturation;
  4059. target.l = lightness;
  4060. return target;
  4061. },
  4062. getStyle: function () {
  4063. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  4064. },
  4065. offsetHSL: function () {
  4066. var hsl = {};
  4067. return function ( h, s, l ) {
  4068. this.getHSL( hsl );
  4069. hsl.h += h; hsl.s += s; hsl.l += l;
  4070. this.setHSL( hsl.h, hsl.s, hsl.l );
  4071. return this;
  4072. };
  4073. }(),
  4074. add: function ( color ) {
  4075. this.r += color.r;
  4076. this.g += color.g;
  4077. this.b += color.b;
  4078. return this;
  4079. },
  4080. addColors: function ( color1, color2 ) {
  4081. this.r = color1.r + color2.r;
  4082. this.g = color1.g + color2.g;
  4083. this.b = color1.b + color2.b;
  4084. return this;
  4085. },
  4086. addScalar: function ( s ) {
  4087. this.r += s;
  4088. this.g += s;
  4089. this.b += s;
  4090. return this;
  4091. },
  4092. sub: function ( color ) {
  4093. this.r = Math.max( 0, this.r - color.r );
  4094. this.g = Math.max( 0, this.g - color.g );
  4095. this.b = Math.max( 0, this.b - color.b );
  4096. return this;
  4097. },
  4098. multiply: function ( color ) {
  4099. this.r *= color.r;
  4100. this.g *= color.g;
  4101. this.b *= color.b;
  4102. return this;
  4103. },
  4104. multiplyScalar: function ( s ) {
  4105. this.r *= s;
  4106. this.g *= s;
  4107. this.b *= s;
  4108. return this;
  4109. },
  4110. lerp: function ( color, alpha ) {
  4111. this.r += ( color.r - this.r ) * alpha;
  4112. this.g += ( color.g - this.g ) * alpha;
  4113. this.b += ( color.b - this.b ) * alpha;
  4114. return this;
  4115. },
  4116. equals: function ( c ) {
  4117. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  4118. },
  4119. fromArray: function ( array, offset ) {
  4120. if ( offset === undefined ) offset = 0;
  4121. this.r = array[ offset ];
  4122. this.g = array[ offset + 1 ];
  4123. this.b = array[ offset + 2 ];
  4124. return this;
  4125. },
  4126. toArray: function ( array, offset ) {
  4127. if ( array === undefined ) array = [];
  4128. if ( offset === undefined ) offset = 0;
  4129. array[ offset ] = this.r;
  4130. array[ offset + 1 ] = this.g;
  4131. array[ offset + 2 ] = this.b;
  4132. return array;
  4133. },
  4134. toJSON: function () {
  4135. return this.getHex();
  4136. }
  4137. } );
  4138. /**
  4139. * Uniforms library for shared webgl shaders
  4140. */
  4141. var UniformsLib = {
  4142. common: {
  4143. diffuse: { value: new Color( 0xeeeeee ) },
  4144. opacity: { value: 1.0 },
  4145. map: { value: null },
  4146. uvTransform: { value: new Matrix3() },
  4147. alphaMap: { value: null },
  4148. },
  4149. specularmap: {
  4150. specularMap: { value: null },
  4151. },
  4152. envmap: {
  4153. envMap: { value: null },
  4154. flipEnvMap: { value: - 1 },
  4155. reflectivity: { value: 1.0 },
  4156. refractionRatio: { value: 0.98 },
  4157. maxMipLevel: { value: 0 }
  4158. },
  4159. aomap: {
  4160. aoMap: { value: null },
  4161. aoMapIntensity: { value: 1 }
  4162. },
  4163. lightmap: {
  4164. lightMap: { value: null },
  4165. lightMapIntensity: { value: 1 }
  4166. },
  4167. emissivemap: {
  4168. emissiveMap: { value: null }
  4169. },
  4170. bumpmap: {
  4171. bumpMap: { value: null },
  4172. bumpScale: { value: 1 }
  4173. },
  4174. normalmap: {
  4175. normalMap: { value: null },
  4176. normalScale: { value: new Vector2( 1, 1 ) }
  4177. },
  4178. displacementmap: {
  4179. displacementMap: { value: null },
  4180. displacementScale: { value: 1 },
  4181. displacementBias: { value: 0 }
  4182. },
  4183. roughnessmap: {
  4184. roughnessMap: { value: null }
  4185. },
  4186. metalnessmap: {
  4187. metalnessMap: { value: null }
  4188. },
  4189. gradientmap: {
  4190. gradientMap: { value: null }
  4191. },
  4192. fog: {
  4193. fogDensity: { value: 0.00025 },
  4194. fogNear: { value: 1 },
  4195. fogFar: { value: 2000 },
  4196. fogColor: { value: new Color( 0xffffff ) }
  4197. },
  4198. lights: {
  4199. ambientLightColor: { value: [] },
  4200. directionalLights: { value: [], properties: {
  4201. direction: {},
  4202. color: {},
  4203. shadow: {},
  4204. shadowBias: {},
  4205. shadowRadius: {},
  4206. shadowMapSize: {}
  4207. } },
  4208. directionalShadowMap: { value: [] },
  4209. directionalShadowMatrix: { value: [] },
  4210. spotLights: { value: [], properties: {
  4211. color: {},
  4212. position: {},
  4213. direction: {},
  4214. distance: {},
  4215. coneCos: {},
  4216. penumbraCos: {},
  4217. decay: {},
  4218. shadow: {},
  4219. shadowBias: {},
  4220. shadowRadius: {},
  4221. shadowMapSize: {}
  4222. } },
  4223. spotShadowMap: { value: [] },
  4224. spotShadowMatrix: { value: [] },
  4225. pointLights: { value: [], properties: {
  4226. color: {},
  4227. position: {},
  4228. decay: {},
  4229. distance: {},
  4230. shadow: {},
  4231. shadowBias: {},
  4232. shadowRadius: {},
  4233. shadowMapSize: {},
  4234. shadowCameraNear: {},
  4235. shadowCameraFar: {}
  4236. } },
  4237. pointShadowMap: { value: [] },
  4238. pointShadowMatrix: { value: [] },
  4239. hemisphereLights: { value: [], properties: {
  4240. direction: {},
  4241. skyColor: {},
  4242. groundColor: {}
  4243. } },
  4244. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  4245. rectAreaLights: { value: [], properties: {
  4246. color: {},
  4247. position: {},
  4248. width: {},
  4249. height: {}
  4250. } }
  4251. },
  4252. points: {
  4253. diffuse: { value: new Color( 0xeeeeee ) },
  4254. opacity: { value: 1.0 },
  4255. size: { value: 1.0 },
  4256. scale: { value: 1.0 },
  4257. map: { value: null },
  4258. uvTransform: { value: new Matrix3() }
  4259. }
  4260. };
  4261. /**
  4262. * @author alteredq / http://alteredqualia.com/
  4263. * @author mrdoob / http://mrdoob.com/
  4264. * @author mikael emtinger / http://gomo.se/
  4265. */
  4266. var ShaderLib = {
  4267. basic: {
  4268. uniforms: UniformsUtils.merge( [
  4269. UniformsLib.common,
  4270. UniformsLib.specularmap,
  4271. UniformsLib.envmap,
  4272. UniformsLib.aomap,
  4273. UniformsLib.lightmap,
  4274. UniformsLib.fog
  4275. ] ),
  4276. vertexShader: ShaderChunk.meshbasic_vert,
  4277. fragmentShader: ShaderChunk.meshbasic_frag
  4278. },
  4279. lambert: {
  4280. uniforms: UniformsUtils.merge( [
  4281. UniformsLib.common,
  4282. UniformsLib.specularmap,
  4283. UniformsLib.envmap,
  4284. UniformsLib.aomap,
  4285. UniformsLib.lightmap,
  4286. UniformsLib.emissivemap,
  4287. UniformsLib.fog,
  4288. UniformsLib.lights,
  4289. {
  4290. emissive: { value: new Color( 0x000000 ) }
  4291. }
  4292. ] ),
  4293. vertexShader: ShaderChunk.meshlambert_vert,
  4294. fragmentShader: ShaderChunk.meshlambert_frag
  4295. },
  4296. phong: {
  4297. uniforms: UniformsUtils.merge( [
  4298. UniformsLib.common,
  4299. UniformsLib.specularmap,
  4300. UniformsLib.envmap,
  4301. UniformsLib.aomap,
  4302. UniformsLib.lightmap,
  4303. UniformsLib.emissivemap,
  4304. UniformsLib.bumpmap,
  4305. UniformsLib.normalmap,
  4306. UniformsLib.displacementmap,
  4307. UniformsLib.gradientmap,
  4308. UniformsLib.fog,
  4309. UniformsLib.lights,
  4310. {
  4311. emissive: { value: new Color( 0x000000 ) },
  4312. specular: { value: new Color( 0x111111 ) },
  4313. shininess: { value: 30 }
  4314. }
  4315. ] ),
  4316. vertexShader: ShaderChunk.meshphong_vert,
  4317. fragmentShader: ShaderChunk.meshphong_frag
  4318. },
  4319. standard: {
  4320. uniforms: UniformsUtils.merge( [
  4321. UniformsLib.common,
  4322. UniformsLib.envmap,
  4323. UniformsLib.aomap,
  4324. UniformsLib.lightmap,
  4325. UniformsLib.emissivemap,
  4326. UniformsLib.bumpmap,
  4327. UniformsLib.normalmap,
  4328. UniformsLib.displacementmap,
  4329. UniformsLib.roughnessmap,
  4330. UniformsLib.metalnessmap,
  4331. UniformsLib.fog,
  4332. UniformsLib.lights,
  4333. {
  4334. emissive: { value: new Color( 0x000000 ) },
  4335. roughness: { value: 0.5 },
  4336. metalness: { value: 0.5 },
  4337. envMapIntensity: { value: 1 } // temporary
  4338. }
  4339. ] ),
  4340. vertexShader: ShaderChunk.meshphysical_vert,
  4341. fragmentShader: ShaderChunk.meshphysical_frag
  4342. },
  4343. points: {
  4344. uniforms: UniformsUtils.merge( [
  4345. UniformsLib.points,
  4346. UniformsLib.fog
  4347. ] ),
  4348. vertexShader: ShaderChunk.points_vert,
  4349. fragmentShader: ShaderChunk.points_frag
  4350. },
  4351. dashed: {
  4352. uniforms: UniformsUtils.merge( [
  4353. UniformsLib.common,
  4354. UniformsLib.fog,
  4355. {
  4356. scale: { value: 1 },
  4357. dashSize: { value: 1 },
  4358. totalSize: { value: 2 }
  4359. }
  4360. ] ),
  4361. vertexShader: ShaderChunk.linedashed_vert,
  4362. fragmentShader: ShaderChunk.linedashed_frag
  4363. },
  4364. depth: {
  4365. uniforms: UniformsUtils.merge( [
  4366. UniformsLib.common,
  4367. UniformsLib.displacementmap
  4368. ] ),
  4369. vertexShader: ShaderChunk.depth_vert,
  4370. fragmentShader: ShaderChunk.depth_frag
  4371. },
  4372. normal: {
  4373. uniforms: UniformsUtils.merge( [
  4374. UniformsLib.common,
  4375. UniformsLib.bumpmap,
  4376. UniformsLib.normalmap,
  4377. UniformsLib.displacementmap,
  4378. {
  4379. opacity: { value: 1.0 }
  4380. }
  4381. ] ),
  4382. vertexShader: ShaderChunk.normal_vert,
  4383. fragmentShader: ShaderChunk.normal_frag
  4384. },
  4385. /* -------------------------------------------------------------------------
  4386. // Cube map shader
  4387. ------------------------------------------------------------------------- */
  4388. cube: {
  4389. uniforms: {
  4390. tCube: { value: null },
  4391. tFlip: { value: - 1 },
  4392. opacity: { value: 1.0 }
  4393. },
  4394. vertexShader: ShaderChunk.cube_vert,
  4395. fragmentShader: ShaderChunk.cube_frag
  4396. },
  4397. equirect: {
  4398. uniforms: {
  4399. tEquirect: { value: null },
  4400. },
  4401. vertexShader: ShaderChunk.equirect_vert,
  4402. fragmentShader: ShaderChunk.equirect_frag
  4403. },
  4404. distanceRGBA: {
  4405. uniforms: UniformsUtils.merge( [
  4406. UniformsLib.common,
  4407. UniformsLib.displacementmap,
  4408. {
  4409. referencePosition: { value: new Vector3() },
  4410. nearDistance: { value: 1 },
  4411. farDistance: { value: 1000 }
  4412. }
  4413. ] ),
  4414. vertexShader: ShaderChunk.distanceRGBA_vert,
  4415. fragmentShader: ShaderChunk.distanceRGBA_frag
  4416. },
  4417. shadow: {
  4418. uniforms: UniformsUtils.merge( [
  4419. UniformsLib.lights,
  4420. UniformsLib.fog,
  4421. {
  4422. color: { value: new Color( 0x00000 ) },
  4423. opacity: { value: 1.0 }
  4424. },
  4425. ] ),
  4426. vertexShader: ShaderChunk.shadow_vert,
  4427. fragmentShader: ShaderChunk.shadow_frag
  4428. }
  4429. };
  4430. ShaderLib.physical = {
  4431. uniforms: UniformsUtils.merge( [
  4432. ShaderLib.standard.uniforms,
  4433. {
  4434. clearCoat: { value: 0 },
  4435. clearCoatRoughness: { value: 0 }
  4436. }
  4437. ] ),
  4438. vertexShader: ShaderChunk.meshphysical_vert,
  4439. fragmentShader: ShaderChunk.meshphysical_frag
  4440. };
  4441. /**
  4442. * @author mrdoob / http://mrdoob.com/
  4443. */
  4444. function WebGLAttributes( gl ) {
  4445. var buffers = new WeakMap();
  4446. function createBuffer( attribute, bufferType ) {
  4447. var array = attribute.array;
  4448. var usage = attribute.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  4449. var buffer = gl.createBuffer();
  4450. gl.bindBuffer( bufferType, buffer );
  4451. gl.bufferData( bufferType, array, usage );
  4452. attribute.onUploadCallback();
  4453. var type = gl.FLOAT;
  4454. if ( array instanceof Float32Array ) {
  4455. type = gl.FLOAT;
  4456. } else if ( array instanceof Float64Array ) {
  4457. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  4458. } else if ( array instanceof Uint16Array ) {
  4459. type = gl.UNSIGNED_SHORT;
  4460. } else if ( array instanceof Int16Array ) {
  4461. type = gl.SHORT;
  4462. } else if ( array instanceof Uint32Array ) {
  4463. type = gl.UNSIGNED_INT;
  4464. } else if ( array instanceof Int32Array ) {
  4465. type = gl.INT;
  4466. } else if ( array instanceof Int8Array ) {
  4467. type = gl.BYTE;
  4468. } else if ( array instanceof Uint8Array ) {
  4469. type = gl.UNSIGNED_BYTE;
  4470. }
  4471. return {
  4472. buffer: buffer,
  4473. type: type,
  4474. bytesPerElement: array.BYTES_PER_ELEMENT,
  4475. version: attribute.version
  4476. };
  4477. }
  4478. function updateBuffer( buffer, attribute, bufferType ) {
  4479. var array = attribute.array;
  4480. var updateRange = attribute.updateRange;
  4481. gl.bindBuffer( bufferType, buffer );
  4482. if ( attribute.dynamic === false ) {
  4483. gl.bufferData( bufferType, array, gl.STATIC_DRAW );
  4484. } else if ( updateRange.count === - 1 ) {
  4485. // Not using update ranges
  4486. gl.bufferSubData( bufferType, 0, array );
  4487. } else if ( updateRange.count === 0 ) {
  4488. 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.' );
  4489. } else {
  4490. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  4491. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  4492. updateRange.count = - 1; // reset range
  4493. }
  4494. }
  4495. //
  4496. function get( attribute ) {
  4497. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4498. return buffers.get( attribute );
  4499. }
  4500. function remove( attribute ) {
  4501. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4502. var data = buffers.get( attribute );
  4503. if ( data ) {
  4504. gl.deleteBuffer( data.buffer );
  4505. buffers.delete( attribute );
  4506. }
  4507. }
  4508. function update( attribute, bufferType ) {
  4509. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4510. var data = buffers.get( attribute );
  4511. if ( data === undefined ) {
  4512. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  4513. } else if ( data.version < attribute.version ) {
  4514. updateBuffer( data.buffer, attribute, bufferType );
  4515. data.version = attribute.version;
  4516. }
  4517. }
  4518. return {
  4519. get: get,
  4520. remove: remove,
  4521. update: update
  4522. };
  4523. }
  4524. /**
  4525. * @author mrdoob / http://mrdoob.com/
  4526. * @author WestLangley / http://github.com/WestLangley
  4527. * @author bhouston / http://clara.io
  4528. */
  4529. function Euler( x, y, z, order ) {
  4530. this._x = x || 0;
  4531. this._y = y || 0;
  4532. this._z = z || 0;
  4533. this._order = order || Euler.DefaultOrder;
  4534. }
  4535. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  4536. Euler.DefaultOrder = 'XYZ';
  4537. Object.defineProperties( Euler.prototype, {
  4538. x: {
  4539. get: function () {
  4540. return this._x;
  4541. },
  4542. set: function ( value ) {
  4543. this._x = value;
  4544. this.onChangeCallback();
  4545. }
  4546. },
  4547. y: {
  4548. get: function () {
  4549. return this._y;
  4550. },
  4551. set: function ( value ) {
  4552. this._y = value;
  4553. this.onChangeCallback();
  4554. }
  4555. },
  4556. z: {
  4557. get: function () {
  4558. return this._z;
  4559. },
  4560. set: function ( value ) {
  4561. this._z = value;
  4562. this.onChangeCallback();
  4563. }
  4564. },
  4565. order: {
  4566. get: function () {
  4567. return this._order;
  4568. },
  4569. set: function ( value ) {
  4570. this._order = value;
  4571. this.onChangeCallback();
  4572. }
  4573. }
  4574. } );
  4575. Object.assign( Euler.prototype, {
  4576. isEuler: true,
  4577. set: function ( x, y, z, order ) {
  4578. this._x = x;
  4579. this._y = y;
  4580. this._z = z;
  4581. this._order = order || this._order;
  4582. this.onChangeCallback();
  4583. return this;
  4584. },
  4585. clone: function () {
  4586. return new this.constructor( this._x, this._y, this._z, this._order );
  4587. },
  4588. copy: function ( euler ) {
  4589. this._x = euler._x;
  4590. this._y = euler._y;
  4591. this._z = euler._z;
  4592. this._order = euler._order;
  4593. this.onChangeCallback();
  4594. return this;
  4595. },
  4596. setFromRotationMatrix: function ( m, order, update ) {
  4597. var clamp = _Math.clamp;
  4598. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4599. var te = m.elements;
  4600. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  4601. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  4602. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  4603. order = order || this._order;
  4604. if ( order === 'XYZ' ) {
  4605. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  4606. if ( Math.abs( m13 ) < 0.99999 ) {
  4607. this._x = Math.atan2( - m23, m33 );
  4608. this._z = Math.atan2( - m12, m11 );
  4609. } else {
  4610. this._x = Math.atan2( m32, m22 );
  4611. this._z = 0;
  4612. }
  4613. } else if ( order === 'YXZ' ) {
  4614. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  4615. if ( Math.abs( m23 ) < 0.99999 ) {
  4616. this._y = Math.atan2( m13, m33 );
  4617. this._z = Math.atan2( m21, m22 );
  4618. } else {
  4619. this._y = Math.atan2( - m31, m11 );
  4620. this._z = 0;
  4621. }
  4622. } else if ( order === 'ZXY' ) {
  4623. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  4624. if ( Math.abs( m32 ) < 0.99999 ) {
  4625. this._y = Math.atan2( - m31, m33 );
  4626. this._z = Math.atan2( - m12, m22 );
  4627. } else {
  4628. this._y = 0;
  4629. this._z = Math.atan2( m21, m11 );
  4630. }
  4631. } else if ( order === 'ZYX' ) {
  4632. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  4633. if ( Math.abs( m31 ) < 0.99999 ) {
  4634. this._x = Math.atan2( m32, m33 );
  4635. this._z = Math.atan2( m21, m11 );
  4636. } else {
  4637. this._x = 0;
  4638. this._z = Math.atan2( - m12, m22 );
  4639. }
  4640. } else if ( order === 'YZX' ) {
  4641. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  4642. if ( Math.abs( m21 ) < 0.99999 ) {
  4643. this._x = Math.atan2( - m23, m22 );
  4644. this._y = Math.atan2( - m31, m11 );
  4645. } else {
  4646. this._x = 0;
  4647. this._y = Math.atan2( m13, m33 );
  4648. }
  4649. } else if ( order === 'XZY' ) {
  4650. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  4651. if ( Math.abs( m12 ) < 0.99999 ) {
  4652. this._x = Math.atan2( m32, m22 );
  4653. this._y = Math.atan2( m13, m11 );
  4654. } else {
  4655. this._x = Math.atan2( - m23, m33 );
  4656. this._y = 0;
  4657. }
  4658. } else {
  4659. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  4660. }
  4661. this._order = order;
  4662. if ( update !== false ) this.onChangeCallback();
  4663. return this;
  4664. },
  4665. setFromQuaternion: function () {
  4666. var matrix = new Matrix4();
  4667. return function setFromQuaternion( q, order, update ) {
  4668. matrix.makeRotationFromQuaternion( q );
  4669. return this.setFromRotationMatrix( matrix, order, update );
  4670. };
  4671. }(),
  4672. setFromVector3: function ( v, order ) {
  4673. return this.set( v.x, v.y, v.z, order || this._order );
  4674. },
  4675. reorder: function () {
  4676. // WARNING: this discards revolution information -bhouston
  4677. var q = new Quaternion();
  4678. return function reorder( newOrder ) {
  4679. q.setFromEuler( this );
  4680. return this.setFromQuaternion( q, newOrder );
  4681. };
  4682. }(),
  4683. equals: function ( euler ) {
  4684. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  4685. },
  4686. fromArray: function ( array ) {
  4687. this._x = array[ 0 ];
  4688. this._y = array[ 1 ];
  4689. this._z = array[ 2 ];
  4690. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  4691. this.onChangeCallback();
  4692. return this;
  4693. },
  4694. toArray: function ( array, offset ) {
  4695. if ( array === undefined ) array = [];
  4696. if ( offset === undefined ) offset = 0;
  4697. array[ offset ] = this._x;
  4698. array[ offset + 1 ] = this._y;
  4699. array[ offset + 2 ] = this._z;
  4700. array[ offset + 3 ] = this._order;
  4701. return array;
  4702. },
  4703. toVector3: function ( optionalResult ) {
  4704. if ( optionalResult ) {
  4705. return optionalResult.set( this._x, this._y, this._z );
  4706. } else {
  4707. return new Vector3( this._x, this._y, this._z );
  4708. }
  4709. },
  4710. onChange: function ( callback ) {
  4711. this.onChangeCallback = callback;
  4712. return this;
  4713. },
  4714. onChangeCallback: function () {}
  4715. } );
  4716. /**
  4717. * @author mrdoob / http://mrdoob.com/
  4718. */
  4719. function Layers() {
  4720. this.mask = 1 | 0;
  4721. }
  4722. Object.assign( Layers.prototype, {
  4723. set: function ( channel ) {
  4724. this.mask = 1 << channel | 0;
  4725. },
  4726. enable: function ( channel ) {
  4727. this.mask |= 1 << channel | 0;
  4728. },
  4729. toggle: function ( channel ) {
  4730. this.mask ^= 1 << channel | 0;
  4731. },
  4732. disable: function ( channel ) {
  4733. this.mask &= ~ ( 1 << channel | 0 );
  4734. },
  4735. test: function ( layers ) {
  4736. return ( this.mask & layers.mask ) !== 0;
  4737. }
  4738. } );
  4739. /**
  4740. * @author mrdoob / http://mrdoob.com/
  4741. * @author mikael emtinger / http://gomo.se/
  4742. * @author alteredq / http://alteredqualia.com/
  4743. * @author WestLangley / http://github.com/WestLangley
  4744. * @author elephantatwork / www.elephantatwork.ch
  4745. */
  4746. var object3DId = 0;
  4747. function Object3D() {
  4748. Object.defineProperty( this, 'id', { value: object3DId ++ } );
  4749. this.uuid = _Math.generateUUID();
  4750. this.name = '';
  4751. this.type = 'Object3D';
  4752. this.parent = null;
  4753. this.children = [];
  4754. this.up = Object3D.DefaultUp.clone();
  4755. var position = new Vector3();
  4756. var rotation = new Euler();
  4757. var quaternion = new Quaternion();
  4758. var scale = new Vector3( 1, 1, 1 );
  4759. function onRotationChange() {
  4760. quaternion.setFromEuler( rotation, false );
  4761. }
  4762. function onQuaternionChange() {
  4763. rotation.setFromQuaternion( quaternion, undefined, false );
  4764. }
  4765. rotation.onChange( onRotationChange );
  4766. quaternion.onChange( onQuaternionChange );
  4767. Object.defineProperties( this, {
  4768. position: {
  4769. enumerable: true,
  4770. value: position
  4771. },
  4772. rotation: {
  4773. enumerable: true,
  4774. value: rotation
  4775. },
  4776. quaternion: {
  4777. enumerable: true,
  4778. value: quaternion
  4779. },
  4780. scale: {
  4781. enumerable: true,
  4782. value: scale
  4783. },
  4784. modelViewMatrix: {
  4785. value: new Matrix4()
  4786. },
  4787. normalMatrix: {
  4788. value: new Matrix3()
  4789. }
  4790. } );
  4791. this.matrix = new Matrix4();
  4792. this.matrixWorld = new Matrix4();
  4793. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  4794. this.matrixWorldNeedsUpdate = false;
  4795. this.layers = new Layers();
  4796. this.visible = true;
  4797. this.castShadow = false;
  4798. this.receiveShadow = false;
  4799. this.frustumCulled = true;
  4800. this.renderOrder = 0;
  4801. this.userData = {};
  4802. }
  4803. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  4804. Object3D.DefaultMatrixAutoUpdate = true;
  4805. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  4806. constructor: Object3D,
  4807. isObject3D: true,
  4808. onBeforeRender: function () {},
  4809. onAfterRender: function () {},
  4810. applyMatrix: function ( matrix ) {
  4811. this.matrix.multiplyMatrices( matrix, this.matrix );
  4812. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4813. },
  4814. applyQuaternion: function ( q ) {
  4815. this.quaternion.premultiply( q );
  4816. return this;
  4817. },
  4818. setRotationFromAxisAngle: function ( axis, angle ) {
  4819. // assumes axis is normalized
  4820. this.quaternion.setFromAxisAngle( axis, angle );
  4821. },
  4822. setRotationFromEuler: function ( euler ) {
  4823. this.quaternion.setFromEuler( euler, true );
  4824. },
  4825. setRotationFromMatrix: function ( m ) {
  4826. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4827. this.quaternion.setFromRotationMatrix( m );
  4828. },
  4829. setRotationFromQuaternion: function ( q ) {
  4830. // assumes q is normalized
  4831. this.quaternion.copy( q );
  4832. },
  4833. rotateOnAxis: function () {
  4834. // rotate object on axis in object space
  4835. // axis is assumed to be normalized
  4836. var q1 = new Quaternion();
  4837. return function rotateOnAxis( axis, angle ) {
  4838. q1.setFromAxisAngle( axis, angle );
  4839. this.quaternion.multiply( q1 );
  4840. return this;
  4841. };
  4842. }(),
  4843. rotateOnWorldAxis: function () {
  4844. // rotate object on axis in world space
  4845. // axis is assumed to be normalized
  4846. // method assumes no rotated parent
  4847. var q1 = new Quaternion();
  4848. return function rotateOnWorldAxis( axis, angle ) {
  4849. q1.setFromAxisAngle( axis, angle );
  4850. this.quaternion.premultiply( q1 );
  4851. return this;
  4852. };
  4853. }(),
  4854. rotateX: function () {
  4855. var v1 = new Vector3( 1, 0, 0 );
  4856. return function rotateX( angle ) {
  4857. return this.rotateOnAxis( v1, angle );
  4858. };
  4859. }(),
  4860. rotateY: function () {
  4861. var v1 = new Vector3( 0, 1, 0 );
  4862. return function rotateY( angle ) {
  4863. return this.rotateOnAxis( v1, angle );
  4864. };
  4865. }(),
  4866. rotateZ: function () {
  4867. var v1 = new Vector3( 0, 0, 1 );
  4868. return function rotateZ( angle ) {
  4869. return this.rotateOnAxis( v1, angle );
  4870. };
  4871. }(),
  4872. translateOnAxis: function () {
  4873. // translate object by distance along axis in object space
  4874. // axis is assumed to be normalized
  4875. var v1 = new Vector3();
  4876. return function translateOnAxis( axis, distance ) {
  4877. v1.copy( axis ).applyQuaternion( this.quaternion );
  4878. this.position.add( v1.multiplyScalar( distance ) );
  4879. return this;
  4880. };
  4881. }(),
  4882. translateX: function () {
  4883. var v1 = new Vector3( 1, 0, 0 );
  4884. return function translateX( distance ) {
  4885. return this.translateOnAxis( v1, distance );
  4886. };
  4887. }(),
  4888. translateY: function () {
  4889. var v1 = new Vector3( 0, 1, 0 );
  4890. return function translateY( distance ) {
  4891. return this.translateOnAxis( v1, distance );
  4892. };
  4893. }(),
  4894. translateZ: function () {
  4895. var v1 = new Vector3( 0, 0, 1 );
  4896. return function translateZ( distance ) {
  4897. return this.translateOnAxis( v1, distance );
  4898. };
  4899. }(),
  4900. localToWorld: function ( vector ) {
  4901. return vector.applyMatrix4( this.matrixWorld );
  4902. },
  4903. worldToLocal: function () {
  4904. var m1 = new Matrix4();
  4905. return function worldToLocal( vector ) {
  4906. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  4907. };
  4908. }(),
  4909. lookAt: function () {
  4910. // This method does not support objects with rotated and/or translated parent(s)
  4911. var m1 = new Matrix4();
  4912. var vector = new Vector3();
  4913. return function lookAt( x, y, z ) {
  4914. if ( x.isVector3 ) {
  4915. vector.copy( x );
  4916. } else {
  4917. vector.set( x, y, z );
  4918. }
  4919. if ( this.isCamera ) {
  4920. m1.lookAt( this.position, vector, this.up );
  4921. } else {
  4922. m1.lookAt( vector, this.position, this.up );
  4923. }
  4924. this.quaternion.setFromRotationMatrix( m1 );
  4925. };
  4926. }(),
  4927. add: function ( object ) {
  4928. if ( arguments.length > 1 ) {
  4929. for ( var i = 0; i < arguments.length; i ++ ) {
  4930. this.add( arguments[ i ] );
  4931. }
  4932. return this;
  4933. }
  4934. if ( object === this ) {
  4935. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  4936. return this;
  4937. }
  4938. if ( ( object && object.isObject3D ) ) {
  4939. if ( object.parent !== null ) {
  4940. object.parent.remove( object );
  4941. }
  4942. object.parent = this;
  4943. object.dispatchEvent( { type: 'added' } );
  4944. this.children.push( object );
  4945. } else {
  4946. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  4947. }
  4948. return this;
  4949. },
  4950. remove: function ( object ) {
  4951. if ( arguments.length > 1 ) {
  4952. for ( var i = 0; i < arguments.length; i ++ ) {
  4953. this.remove( arguments[ i ] );
  4954. }
  4955. return this;
  4956. }
  4957. var index = this.children.indexOf( object );
  4958. if ( index !== - 1 ) {
  4959. object.parent = null;
  4960. object.dispatchEvent( { type: 'removed' } );
  4961. this.children.splice( index, 1 );
  4962. }
  4963. return this;
  4964. },
  4965. getObjectById: function ( id ) {
  4966. return this.getObjectByProperty( 'id', id );
  4967. },
  4968. getObjectByName: function ( name ) {
  4969. return this.getObjectByProperty( 'name', name );
  4970. },
  4971. getObjectByProperty: function ( name, value ) {
  4972. if ( this[ name ] === value ) return this;
  4973. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4974. var child = this.children[ i ];
  4975. var object = child.getObjectByProperty( name, value );
  4976. if ( object !== undefined ) {
  4977. return object;
  4978. }
  4979. }
  4980. return undefined;
  4981. },
  4982. getWorldPosition: function ( target ) {
  4983. if ( target === undefined ) {
  4984. console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
  4985. target = new Vector3();
  4986. }
  4987. this.updateMatrixWorld( true );
  4988. return target.setFromMatrixPosition( this.matrixWorld );
  4989. },
  4990. getWorldQuaternion: function () {
  4991. var position = new Vector3();
  4992. var scale = new Vector3();
  4993. return function getWorldQuaternion( target ) {
  4994. if ( target === undefined ) {
  4995. console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
  4996. target = new Quaternion();
  4997. }
  4998. this.updateMatrixWorld( true );
  4999. this.matrixWorld.decompose( position, target, scale );
  5000. return target;
  5001. };
  5002. }(),
  5003. getWorldScale: function () {
  5004. var position = new Vector3();
  5005. var quaternion = new Quaternion();
  5006. return function getWorldScale( target ) {
  5007. if ( target === undefined ) {
  5008. console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
  5009. target = new Vector3();
  5010. }
  5011. this.updateMatrixWorld( true );
  5012. this.matrixWorld.decompose( position, quaternion, target );
  5013. return target;
  5014. };
  5015. }(),
  5016. getWorldDirection: function () {
  5017. var quaternion = new Quaternion();
  5018. return function getWorldDirection( target ) {
  5019. if ( target === undefined ) {
  5020. console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
  5021. target = new Vector3();
  5022. }
  5023. this.getWorldQuaternion( quaternion );
  5024. return target.set( 0, 0, 1 ).applyQuaternion( quaternion );
  5025. };
  5026. }(),
  5027. raycast: function () {},
  5028. traverse: function ( callback ) {
  5029. callback( this );
  5030. var children = this.children;
  5031. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5032. children[ i ].traverse( callback );
  5033. }
  5034. },
  5035. traverseVisible: function ( callback ) {
  5036. if ( this.visible === false ) return;
  5037. callback( this );
  5038. var children = this.children;
  5039. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5040. children[ i ].traverseVisible( callback );
  5041. }
  5042. },
  5043. traverseAncestors: function ( callback ) {
  5044. var parent = this.parent;
  5045. if ( parent !== null ) {
  5046. callback( parent );
  5047. parent.traverseAncestors( callback );
  5048. }
  5049. },
  5050. updateMatrix: function () {
  5051. this.matrix.compose( this.position, this.quaternion, this.scale );
  5052. this.matrixWorldNeedsUpdate = true;
  5053. },
  5054. updateMatrixWorld: function ( force ) {
  5055. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5056. if ( this.matrixWorldNeedsUpdate || force ) {
  5057. if ( this.parent === null ) {
  5058. this.matrixWorld.copy( this.matrix );
  5059. } else {
  5060. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5061. }
  5062. this.matrixWorldNeedsUpdate = false;
  5063. force = true;
  5064. }
  5065. // update children
  5066. var children = this.children;
  5067. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5068. children[ i ].updateMatrixWorld( force );
  5069. }
  5070. },
  5071. toJSON: function ( meta ) {
  5072. // meta is a string when called from JSON.stringify
  5073. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  5074. var output = {};
  5075. // meta is a hash used to collect geometries, materials.
  5076. // not providing it implies that this is the root object
  5077. // being serialized.
  5078. if ( isRootObject ) {
  5079. // initialize meta obj
  5080. meta = {
  5081. geometries: {},
  5082. materials: {},
  5083. textures: {},
  5084. images: {},
  5085. shapes: {}
  5086. };
  5087. output.metadata = {
  5088. version: 4.5,
  5089. type: 'Object',
  5090. generator: 'Object3D.toJSON'
  5091. };
  5092. }
  5093. // standard Object3D serialization
  5094. var object = {};
  5095. object.uuid = this.uuid;
  5096. object.type = this.type;
  5097. if ( this.name !== '' ) object.name = this.name;
  5098. if ( this.castShadow === true ) object.castShadow = true;
  5099. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5100. if ( this.visible === false ) object.visible = false;
  5101. if ( this.frustumCulled === false ) object.frustumCulled = false;
  5102. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  5103. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5104. object.matrix = this.matrix.toArray();
  5105. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  5106. //
  5107. function serialize( library, element ) {
  5108. if ( library[ element.uuid ] === undefined ) {
  5109. library[ element.uuid ] = element.toJSON( meta );
  5110. }
  5111. return element.uuid;
  5112. }
  5113. if ( this.geometry !== undefined ) {
  5114. object.geometry = serialize( meta.geometries, this.geometry );
  5115. var parameters = this.geometry.parameters;
  5116. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  5117. var shapes = parameters.shapes;
  5118. if ( Array.isArray( shapes ) ) {
  5119. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  5120. var shape = shapes[ i ];
  5121. serialize( meta.shapes, shape );
  5122. }
  5123. } else {
  5124. serialize( meta.shapes, shapes );
  5125. }
  5126. }
  5127. }
  5128. if ( this.material !== undefined ) {
  5129. if ( Array.isArray( this.material ) ) {
  5130. var uuids = [];
  5131. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  5132. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  5133. }
  5134. object.material = uuids;
  5135. } else {
  5136. object.material = serialize( meta.materials, this.material );
  5137. }
  5138. }
  5139. //
  5140. if ( this.children.length > 0 ) {
  5141. object.children = [];
  5142. for ( var i = 0; i < this.children.length; i ++ ) {
  5143. object.children.push( this.children[ i ].toJSON( meta ).object );
  5144. }
  5145. }
  5146. if ( isRootObject ) {
  5147. var geometries = extractFromCache( meta.geometries );
  5148. var materials = extractFromCache( meta.materials );
  5149. var textures = extractFromCache( meta.textures );
  5150. var images = extractFromCache( meta.images );
  5151. var shapes = extractFromCache( meta.shapes );
  5152. if ( geometries.length > 0 ) output.geometries = geometries;
  5153. if ( materials.length > 0 ) output.materials = materials;
  5154. if ( textures.length > 0 ) output.textures = textures;
  5155. if ( images.length > 0 ) output.images = images;
  5156. if ( shapes.length > 0 ) output.shapes = shapes;
  5157. }
  5158. output.object = object;
  5159. return output;
  5160. // extract data from the cache hash
  5161. // remove metadata on each item
  5162. // and return as array
  5163. function extractFromCache( cache ) {
  5164. var values = [];
  5165. for ( var key in cache ) {
  5166. var data = cache[ key ];
  5167. delete data.metadata;
  5168. values.push( data );
  5169. }
  5170. return values;
  5171. }
  5172. },
  5173. clone: function ( recursive ) {
  5174. return new this.constructor().copy( this, recursive );
  5175. },
  5176. copy: function ( source, recursive ) {
  5177. if ( recursive === undefined ) recursive = true;
  5178. this.name = source.name;
  5179. this.up.copy( source.up );
  5180. this.position.copy( source.position );
  5181. this.quaternion.copy( source.quaternion );
  5182. this.scale.copy( source.scale );
  5183. this.matrix.copy( source.matrix );
  5184. this.matrixWorld.copy( source.matrixWorld );
  5185. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5186. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5187. this.layers.mask = source.layers.mask;
  5188. this.visible = source.visible;
  5189. this.castShadow = source.castShadow;
  5190. this.receiveShadow = source.receiveShadow;
  5191. this.frustumCulled = source.frustumCulled;
  5192. this.renderOrder = source.renderOrder;
  5193. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5194. if ( recursive === true ) {
  5195. for ( var i = 0; i < source.children.length; i ++ ) {
  5196. var child = source.children[ i ];
  5197. this.add( child.clone() );
  5198. }
  5199. }
  5200. return this;
  5201. }
  5202. } );
  5203. /**
  5204. * @author mrdoob / http://mrdoob.com/
  5205. * @author mikael emtinger / http://gomo.se/
  5206. * @author WestLangley / http://github.com/WestLangley
  5207. */
  5208. function Camera() {
  5209. Object3D.call( this );
  5210. this.type = 'Camera';
  5211. this.matrixWorldInverse = new Matrix4();
  5212. this.projectionMatrix = new Matrix4();
  5213. }
  5214. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  5215. constructor: Camera,
  5216. isCamera: true,
  5217. copy: function ( source, recursive ) {
  5218. Object3D.prototype.copy.call( this, source, recursive );
  5219. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  5220. this.projectionMatrix.copy( source.projectionMatrix );
  5221. return this;
  5222. },
  5223. getWorldDirection: function () {
  5224. var quaternion = new Quaternion();
  5225. return function getWorldDirection( target ) {
  5226. if ( target === undefined ) {
  5227. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  5228. target = new Vector3();
  5229. }
  5230. this.getWorldQuaternion( quaternion );
  5231. return target.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  5232. };
  5233. }(),
  5234. updateMatrixWorld: function ( force ) {
  5235. Object3D.prototype.updateMatrixWorld.call( this, force );
  5236. this.matrixWorldInverse.getInverse( this.matrixWorld );
  5237. },
  5238. clone: function () {
  5239. return new this.constructor().copy( this );
  5240. }
  5241. } );
  5242. /**
  5243. * @author alteredq / http://alteredqualia.com/
  5244. * @author arose / http://github.com/arose
  5245. */
  5246. function OrthographicCamera( left, right, top, bottom, near, far ) {
  5247. Camera.call( this );
  5248. this.type = 'OrthographicCamera';
  5249. this.zoom = 1;
  5250. this.view = null;
  5251. this.left = left;
  5252. this.right = right;
  5253. this.top = top;
  5254. this.bottom = bottom;
  5255. this.near = ( near !== undefined ) ? near : 0.1;
  5256. this.far = ( far !== undefined ) ? far : 2000;
  5257. this.updateProjectionMatrix();
  5258. }
  5259. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  5260. constructor: OrthographicCamera,
  5261. isOrthographicCamera: true,
  5262. copy: function ( source, recursive ) {
  5263. Camera.prototype.copy.call( this, source, recursive );
  5264. this.left = source.left;
  5265. this.right = source.right;
  5266. this.top = source.top;
  5267. this.bottom = source.bottom;
  5268. this.near = source.near;
  5269. this.far = source.far;
  5270. this.zoom = source.zoom;
  5271. this.view = source.view === null ? null : Object.assign( {}, source.view );
  5272. return this;
  5273. },
  5274. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  5275. if ( this.view === null ) {
  5276. this.view = {
  5277. enabled: true,
  5278. fullWidth: 1,
  5279. fullHeight: 1,
  5280. offsetX: 0,
  5281. offsetY: 0,
  5282. width: 1,
  5283. height: 1
  5284. };
  5285. }
  5286. this.view.enabled = true;
  5287. this.view.fullWidth = fullWidth;
  5288. this.view.fullHeight = fullHeight;
  5289. this.view.offsetX = x;
  5290. this.view.offsetY = y;
  5291. this.view.width = width;
  5292. this.view.height = height;
  5293. this.updateProjectionMatrix();
  5294. },
  5295. clearViewOffset: function () {
  5296. if ( this.view !== null ) {
  5297. this.view.enabled = false;
  5298. }
  5299. this.updateProjectionMatrix();
  5300. },
  5301. updateProjectionMatrix: function () {
  5302. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  5303. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  5304. var cx = ( this.right + this.left ) / 2;
  5305. var cy = ( this.top + this.bottom ) / 2;
  5306. var left = cx - dx;
  5307. var right = cx + dx;
  5308. var top = cy + dy;
  5309. var bottom = cy - dy;
  5310. if ( this.view !== null && this.view.enabled ) {
  5311. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  5312. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  5313. var scaleW = ( this.right - this.left ) / this.view.width;
  5314. var scaleH = ( this.top - this.bottom ) / this.view.height;
  5315. left += scaleW * ( this.view.offsetX / zoomW );
  5316. right = left + scaleW * ( this.view.width / zoomW );
  5317. top -= scaleH * ( this.view.offsetY / zoomH );
  5318. bottom = top - scaleH * ( this.view.height / zoomH );
  5319. }
  5320. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  5321. },
  5322. toJSON: function ( meta ) {
  5323. var data = Object3D.prototype.toJSON.call( this, meta );
  5324. data.object.zoom = this.zoom;
  5325. data.object.left = this.left;
  5326. data.object.right = this.right;
  5327. data.object.top = this.top;
  5328. data.object.bottom = this.bottom;
  5329. data.object.near = this.near;
  5330. data.object.far = this.far;
  5331. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  5332. return data;
  5333. }
  5334. } );
  5335. /**
  5336. * @author mrdoob / http://mrdoob.com/
  5337. * @author alteredq / http://alteredqualia.com/
  5338. */
  5339. function Face3( a, b, c, normal, color, materialIndex ) {
  5340. this.a = a;
  5341. this.b = b;
  5342. this.c = c;
  5343. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  5344. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5345. this.color = ( color && color.isColor ) ? color : new Color();
  5346. this.vertexColors = Array.isArray( color ) ? color : [];
  5347. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5348. }
  5349. Object.assign( Face3.prototype, {
  5350. clone: function () {
  5351. return new this.constructor().copy( this );
  5352. },
  5353. copy: function ( source ) {
  5354. this.a = source.a;
  5355. this.b = source.b;
  5356. this.c = source.c;
  5357. this.normal.copy( source.normal );
  5358. this.color.copy( source.color );
  5359. this.materialIndex = source.materialIndex;
  5360. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5361. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5362. }
  5363. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5364. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5365. }
  5366. return this;
  5367. }
  5368. } );
  5369. /**
  5370. * @author mrdoob / http://mrdoob.com/
  5371. * @author kile / http://kile.stravaganza.org/
  5372. * @author alteredq / http://alteredqualia.com/
  5373. * @author mikael emtinger / http://gomo.se/
  5374. * @author zz85 / http://www.lab4games.net/zz85/blog
  5375. * @author bhouston / http://clara.io
  5376. */
  5377. var geometryId = 0; // Geometry uses even numbers as Id
  5378. function Geometry() {
  5379. Object.defineProperty( this, 'id', { value: geometryId += 2 } );
  5380. this.uuid = _Math.generateUUID();
  5381. this.name = '';
  5382. this.type = 'Geometry';
  5383. this.vertices = [];
  5384. this.colors = [];
  5385. this.faces = [];
  5386. this.faceVertexUvs = [[]];
  5387. this.morphTargets = [];
  5388. this.morphNormals = [];
  5389. this.skinWeights = [];
  5390. this.skinIndices = [];
  5391. this.lineDistances = [];
  5392. this.boundingBox = null;
  5393. this.boundingSphere = null;
  5394. // update flags
  5395. this.elementsNeedUpdate = false;
  5396. this.verticesNeedUpdate = false;
  5397. this.uvsNeedUpdate = false;
  5398. this.normalsNeedUpdate = false;
  5399. this.colorsNeedUpdate = false;
  5400. this.lineDistancesNeedUpdate = false;
  5401. this.groupsNeedUpdate = false;
  5402. }
  5403. Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5404. constructor: Geometry,
  5405. isGeometry: true,
  5406. applyMatrix: function ( matrix ) {
  5407. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5408. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5409. var vertex = this.vertices[ i ];
  5410. vertex.applyMatrix4( matrix );
  5411. }
  5412. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5413. var face = this.faces[ i ];
  5414. face.normal.applyMatrix3( normalMatrix ).normalize();
  5415. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5416. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5417. }
  5418. }
  5419. if ( this.boundingBox !== null ) {
  5420. this.computeBoundingBox();
  5421. }
  5422. if ( this.boundingSphere !== null ) {
  5423. this.computeBoundingSphere();
  5424. }
  5425. this.verticesNeedUpdate = true;
  5426. this.normalsNeedUpdate = true;
  5427. return this;
  5428. },
  5429. rotateX: function () {
  5430. // rotate geometry around world x-axis
  5431. var m1 = new Matrix4();
  5432. return function rotateX( angle ) {
  5433. m1.makeRotationX( angle );
  5434. this.applyMatrix( m1 );
  5435. return this;
  5436. };
  5437. }(),
  5438. rotateY: function () {
  5439. // rotate geometry around world y-axis
  5440. var m1 = new Matrix4();
  5441. return function rotateY( angle ) {
  5442. m1.makeRotationY( angle );
  5443. this.applyMatrix( m1 );
  5444. return this;
  5445. };
  5446. }(),
  5447. rotateZ: function () {
  5448. // rotate geometry around world z-axis
  5449. var m1 = new Matrix4();
  5450. return function rotateZ( angle ) {
  5451. m1.makeRotationZ( angle );
  5452. this.applyMatrix( m1 );
  5453. return this;
  5454. };
  5455. }(),
  5456. translate: function () {
  5457. // translate geometry
  5458. var m1 = new Matrix4();
  5459. return function translate( x, y, z ) {
  5460. m1.makeTranslation( x, y, z );
  5461. this.applyMatrix( m1 );
  5462. return this;
  5463. };
  5464. }(),
  5465. scale: function () {
  5466. // scale geometry
  5467. var m1 = new Matrix4();
  5468. return function scale( x, y, z ) {
  5469. m1.makeScale( x, y, z );
  5470. this.applyMatrix( m1 );
  5471. return this;
  5472. };
  5473. }(),
  5474. lookAt: function () {
  5475. var obj = new Object3D();
  5476. return function lookAt( vector ) {
  5477. obj.lookAt( vector );
  5478. obj.updateMatrix();
  5479. this.applyMatrix( obj.matrix );
  5480. };
  5481. }(),
  5482. fromBufferGeometry: function ( geometry ) {
  5483. var scope = this;
  5484. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5485. var attributes = geometry.attributes;
  5486. var positions = attributes.position.array;
  5487. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5488. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5489. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5490. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5491. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5492. var tempNormals = [];
  5493. var tempUVs = [];
  5494. var tempUVs2 = [];
  5495. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  5496. scope.vertices.push( new Vector3( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] ) );
  5497. if ( normals !== undefined ) {
  5498. tempNormals.push( new Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5499. }
  5500. if ( colors !== undefined ) {
  5501. scope.colors.push( new Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5502. }
  5503. if ( uvs !== undefined ) {
  5504. tempUVs.push( new Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5505. }
  5506. if ( uvs2 !== undefined ) {
  5507. tempUVs2.push( new Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5508. }
  5509. }
  5510. function addFace( a, b, c, materialIndex ) {
  5511. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5512. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5513. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  5514. scope.faces.push( face );
  5515. if ( uvs !== undefined ) {
  5516. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5517. }
  5518. if ( uvs2 !== undefined ) {
  5519. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5520. }
  5521. }
  5522. var groups = geometry.groups;
  5523. if ( groups.length > 0 ) {
  5524. for ( var i = 0; i < groups.length; i ++ ) {
  5525. var group = groups[ i ];
  5526. var start = group.start;
  5527. var count = group.count;
  5528. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5529. if ( indices !== undefined ) {
  5530. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  5531. } else {
  5532. addFace( j, j + 1, j + 2, group.materialIndex );
  5533. }
  5534. }
  5535. }
  5536. } else {
  5537. if ( indices !== undefined ) {
  5538. for ( var i = 0; i < indices.length; i += 3 ) {
  5539. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5540. }
  5541. } else {
  5542. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  5543. addFace( i, i + 1, i + 2 );
  5544. }
  5545. }
  5546. }
  5547. this.computeFaceNormals();
  5548. if ( geometry.boundingBox !== null ) {
  5549. this.boundingBox = geometry.boundingBox.clone();
  5550. }
  5551. if ( geometry.boundingSphere !== null ) {
  5552. this.boundingSphere = geometry.boundingSphere.clone();
  5553. }
  5554. return this;
  5555. },
  5556. center: function () {
  5557. var offset = new Vector3();
  5558. return function center() {
  5559. this.computeBoundingBox();
  5560. this.boundingBox.getCenter( offset ).negate();
  5561. this.translate( offset.x, offset.y, offset.z );
  5562. return this;
  5563. };
  5564. }(),
  5565. normalize: function () {
  5566. this.computeBoundingSphere();
  5567. var center = this.boundingSphere.center;
  5568. var radius = this.boundingSphere.radius;
  5569. var s = radius === 0 ? 1 : 1.0 / radius;
  5570. var matrix = new Matrix4();
  5571. matrix.set(
  5572. s, 0, 0, - s * center.x,
  5573. 0, s, 0, - s * center.y,
  5574. 0, 0, s, - s * center.z,
  5575. 0, 0, 0, 1
  5576. );
  5577. this.applyMatrix( matrix );
  5578. return this;
  5579. },
  5580. computeFaceNormals: function () {
  5581. var cb = new Vector3(), ab = new Vector3();
  5582. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5583. var face = this.faces[ f ];
  5584. var vA = this.vertices[ face.a ];
  5585. var vB = this.vertices[ face.b ];
  5586. var vC = this.vertices[ face.c ];
  5587. cb.subVectors( vC, vB );
  5588. ab.subVectors( vA, vB );
  5589. cb.cross( ab );
  5590. cb.normalize();
  5591. face.normal.copy( cb );
  5592. }
  5593. },
  5594. computeVertexNormals: function ( areaWeighted ) {
  5595. if ( areaWeighted === undefined ) areaWeighted = true;
  5596. var v, vl, f, fl, face, vertices;
  5597. vertices = new Array( this.vertices.length );
  5598. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5599. vertices[ v ] = new Vector3();
  5600. }
  5601. if ( areaWeighted ) {
  5602. // vertex normals weighted by triangle areas
  5603. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5604. var vA, vB, vC;
  5605. var cb = new Vector3(), ab = new Vector3();
  5606. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5607. face = this.faces[ f ];
  5608. vA = this.vertices[ face.a ];
  5609. vB = this.vertices[ face.b ];
  5610. vC = this.vertices[ face.c ];
  5611. cb.subVectors( vC, vB );
  5612. ab.subVectors( vA, vB );
  5613. cb.cross( ab );
  5614. vertices[ face.a ].add( cb );
  5615. vertices[ face.b ].add( cb );
  5616. vertices[ face.c ].add( cb );
  5617. }
  5618. } else {
  5619. this.computeFaceNormals();
  5620. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5621. face = this.faces[ f ];
  5622. vertices[ face.a ].add( face.normal );
  5623. vertices[ face.b ].add( face.normal );
  5624. vertices[ face.c ].add( face.normal );
  5625. }
  5626. }
  5627. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5628. vertices[ v ].normalize();
  5629. }
  5630. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5631. face = this.faces[ f ];
  5632. var vertexNormals = face.vertexNormals;
  5633. if ( vertexNormals.length === 3 ) {
  5634. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5635. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5636. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5637. } else {
  5638. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5639. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5640. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5641. }
  5642. }
  5643. if ( this.faces.length > 0 ) {
  5644. this.normalsNeedUpdate = true;
  5645. }
  5646. },
  5647. computeFlatVertexNormals: function () {
  5648. var f, fl, face;
  5649. this.computeFaceNormals();
  5650. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5651. face = this.faces[ f ];
  5652. var vertexNormals = face.vertexNormals;
  5653. if ( vertexNormals.length === 3 ) {
  5654. vertexNormals[ 0 ].copy( face.normal );
  5655. vertexNormals[ 1 ].copy( face.normal );
  5656. vertexNormals[ 2 ].copy( face.normal );
  5657. } else {
  5658. vertexNormals[ 0 ] = face.normal.clone();
  5659. vertexNormals[ 1 ] = face.normal.clone();
  5660. vertexNormals[ 2 ] = face.normal.clone();
  5661. }
  5662. }
  5663. if ( this.faces.length > 0 ) {
  5664. this.normalsNeedUpdate = true;
  5665. }
  5666. },
  5667. computeMorphNormals: function () {
  5668. var i, il, f, fl, face;
  5669. // save original normals
  5670. // - create temp variables on first access
  5671. // otherwise just copy (for faster repeated calls)
  5672. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5673. face = this.faces[ f ];
  5674. if ( ! face.__originalFaceNormal ) {
  5675. face.__originalFaceNormal = face.normal.clone();
  5676. } else {
  5677. face.__originalFaceNormal.copy( face.normal );
  5678. }
  5679. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5680. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5681. if ( ! face.__originalVertexNormals[ i ] ) {
  5682. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5683. } else {
  5684. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5685. }
  5686. }
  5687. }
  5688. // use temp geometry to compute face and vertex normals for each morph
  5689. var tmpGeo = new Geometry();
  5690. tmpGeo.faces = this.faces;
  5691. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5692. // create on first access
  5693. if ( ! this.morphNormals[ i ] ) {
  5694. this.morphNormals[ i ] = {};
  5695. this.morphNormals[ i ].faceNormals = [];
  5696. this.morphNormals[ i ].vertexNormals = [];
  5697. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5698. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5699. var faceNormal, vertexNormals;
  5700. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5701. faceNormal = new Vector3();
  5702. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  5703. dstNormalsFace.push( faceNormal );
  5704. dstNormalsVertex.push( vertexNormals );
  5705. }
  5706. }
  5707. var morphNormals = this.morphNormals[ i ];
  5708. // set vertices to morph target
  5709. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5710. // compute morph normals
  5711. tmpGeo.computeFaceNormals();
  5712. tmpGeo.computeVertexNormals();
  5713. // store morph normals
  5714. var faceNormal, vertexNormals;
  5715. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5716. face = this.faces[ f ];
  5717. faceNormal = morphNormals.faceNormals[ f ];
  5718. vertexNormals = morphNormals.vertexNormals[ f ];
  5719. faceNormal.copy( face.normal );
  5720. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5721. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5722. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5723. }
  5724. }
  5725. // restore original normals
  5726. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5727. face = this.faces[ f ];
  5728. face.normal = face.__originalFaceNormal;
  5729. face.vertexNormals = face.__originalVertexNormals;
  5730. }
  5731. },
  5732. computeBoundingBox: function () {
  5733. if ( this.boundingBox === null ) {
  5734. this.boundingBox = new Box3();
  5735. }
  5736. this.boundingBox.setFromPoints( this.vertices );
  5737. },
  5738. computeBoundingSphere: function () {
  5739. if ( this.boundingSphere === null ) {
  5740. this.boundingSphere = new Sphere();
  5741. }
  5742. this.boundingSphere.setFromPoints( this.vertices );
  5743. },
  5744. merge: function ( geometry, matrix, materialIndexOffset ) {
  5745. if ( ! ( geometry && geometry.isGeometry ) ) {
  5746. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  5747. return;
  5748. }
  5749. var normalMatrix,
  5750. vertexOffset = this.vertices.length,
  5751. vertices1 = this.vertices,
  5752. vertices2 = geometry.vertices,
  5753. faces1 = this.faces,
  5754. faces2 = geometry.faces,
  5755. uvs1 = this.faceVertexUvs[ 0 ],
  5756. uvs2 = geometry.faceVertexUvs[ 0 ],
  5757. colors1 = this.colors,
  5758. colors2 = geometry.colors;
  5759. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  5760. if ( matrix !== undefined ) {
  5761. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5762. }
  5763. // vertices
  5764. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  5765. var vertex = vertices2[ i ];
  5766. var vertexCopy = vertex.clone();
  5767. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  5768. vertices1.push( vertexCopy );
  5769. }
  5770. // colors
  5771. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  5772. colors1.push( colors2[ i ].clone() );
  5773. }
  5774. // faces
  5775. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  5776. var face = faces2[ i ], faceCopy, normal, color,
  5777. faceVertexNormals = face.vertexNormals,
  5778. faceVertexColors = face.vertexColors;
  5779. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  5780. faceCopy.normal.copy( face.normal );
  5781. if ( normalMatrix !== undefined ) {
  5782. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  5783. }
  5784. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  5785. normal = faceVertexNormals[ j ].clone();
  5786. if ( normalMatrix !== undefined ) {
  5787. normal.applyMatrix3( normalMatrix ).normalize();
  5788. }
  5789. faceCopy.vertexNormals.push( normal );
  5790. }
  5791. faceCopy.color.copy( face.color );
  5792. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  5793. color = faceVertexColors[ j ];
  5794. faceCopy.vertexColors.push( color.clone() );
  5795. }
  5796. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  5797. faces1.push( faceCopy );
  5798. }
  5799. // uvs
  5800. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  5801. var uv = uvs2[ i ], uvCopy = [];
  5802. if ( uv === undefined ) {
  5803. continue;
  5804. }
  5805. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  5806. uvCopy.push( uv[ j ].clone() );
  5807. }
  5808. uvs1.push( uvCopy );
  5809. }
  5810. },
  5811. mergeMesh: function ( mesh ) {
  5812. if ( ! ( mesh && mesh.isMesh ) ) {
  5813. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  5814. return;
  5815. }
  5816. if ( mesh.matrixAutoUpdate ) mesh.updateMatrix();
  5817. this.merge( mesh.geometry, mesh.matrix );
  5818. },
  5819. /*
  5820. * Checks for duplicate vertices with hashmap.
  5821. * Duplicated vertices are removed
  5822. * and faces' vertices are updated.
  5823. */
  5824. mergeVertices: function () {
  5825. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  5826. var unique = [], changes = [];
  5827. var v, key;
  5828. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  5829. var precision = Math.pow( 10, precisionPoints );
  5830. var i, il, face;
  5831. var indices, j, jl;
  5832. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  5833. v = this.vertices[ i ];
  5834. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  5835. if ( verticesMap[ key ] === undefined ) {
  5836. verticesMap[ key ] = i;
  5837. unique.push( this.vertices[ i ] );
  5838. changes[ i ] = unique.length - 1;
  5839. } else {
  5840. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  5841. changes[ i ] = changes[ verticesMap[ key ] ];
  5842. }
  5843. }
  5844. // if faces are completely degenerate after merging vertices, we
  5845. // have to remove them from the geometry.
  5846. var faceIndicesToRemove = [];
  5847. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  5848. face = this.faces[ i ];
  5849. face.a = changes[ face.a ];
  5850. face.b = changes[ face.b ];
  5851. face.c = changes[ face.c ];
  5852. indices = [ face.a, face.b, face.c ];
  5853. // if any duplicate vertices are found in a Face3
  5854. // we have to remove the face as nothing can be saved
  5855. for ( var n = 0; n < 3; n ++ ) {
  5856. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  5857. faceIndicesToRemove.push( i );
  5858. break;
  5859. }
  5860. }
  5861. }
  5862. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  5863. var idx = faceIndicesToRemove[ i ];
  5864. this.faces.splice( idx, 1 );
  5865. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  5866. this.faceVertexUvs[ j ].splice( idx, 1 );
  5867. }
  5868. }
  5869. // Use unique set of vertices
  5870. var diff = this.vertices.length - unique.length;
  5871. this.vertices = unique;
  5872. return diff;
  5873. },
  5874. setFromPoints: function ( points ) {
  5875. this.vertices = [];
  5876. for ( var i = 0, l = points.length; i < l; i ++ ) {
  5877. var point = points[ i ];
  5878. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  5879. }
  5880. return this;
  5881. },
  5882. sortFacesByMaterialIndex: function () {
  5883. var faces = this.faces;
  5884. var length = faces.length;
  5885. // tag faces
  5886. for ( var i = 0; i < length; i ++ ) {
  5887. faces[ i ]._id = i;
  5888. }
  5889. // sort faces
  5890. function materialIndexSort( a, b ) {
  5891. return a.materialIndex - b.materialIndex;
  5892. }
  5893. faces.sort( materialIndexSort );
  5894. // sort uvs
  5895. var uvs1 = this.faceVertexUvs[ 0 ];
  5896. var uvs2 = this.faceVertexUvs[ 1 ];
  5897. var newUvs1, newUvs2;
  5898. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  5899. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  5900. for ( var i = 0; i < length; i ++ ) {
  5901. var id = faces[ i ]._id;
  5902. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  5903. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  5904. }
  5905. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  5906. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  5907. },
  5908. toJSON: function () {
  5909. var data = {
  5910. metadata: {
  5911. version: 4.5,
  5912. type: 'Geometry',
  5913. generator: 'Geometry.toJSON'
  5914. }
  5915. };
  5916. // standard Geometry serialization
  5917. data.uuid = this.uuid;
  5918. data.type = this.type;
  5919. if ( this.name !== '' ) data.name = this.name;
  5920. if ( this.parameters !== undefined ) {
  5921. var parameters = this.parameters;
  5922. for ( var key in parameters ) {
  5923. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  5924. }
  5925. return data;
  5926. }
  5927. var vertices = [];
  5928. for ( var i = 0; i < this.vertices.length; i ++ ) {
  5929. var vertex = this.vertices[ i ];
  5930. vertices.push( vertex.x, vertex.y, vertex.z );
  5931. }
  5932. var faces = [];
  5933. var normals = [];
  5934. var normalsHash = {};
  5935. var colors = [];
  5936. var colorsHash = {};
  5937. var uvs = [];
  5938. var uvsHash = {};
  5939. for ( var i = 0; i < this.faces.length; i ++ ) {
  5940. var face = this.faces[ i ];
  5941. var hasMaterial = true;
  5942. var hasFaceUv = false; // deprecated
  5943. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  5944. var hasFaceNormal = face.normal.length() > 0;
  5945. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  5946. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  5947. var hasFaceVertexColor = face.vertexColors.length > 0;
  5948. var faceType = 0;
  5949. faceType = setBit( faceType, 0, 0 ); // isQuad
  5950. faceType = setBit( faceType, 1, hasMaterial );
  5951. faceType = setBit( faceType, 2, hasFaceUv );
  5952. faceType = setBit( faceType, 3, hasFaceVertexUv );
  5953. faceType = setBit( faceType, 4, hasFaceNormal );
  5954. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  5955. faceType = setBit( faceType, 6, hasFaceColor );
  5956. faceType = setBit( faceType, 7, hasFaceVertexColor );
  5957. faces.push( faceType );
  5958. faces.push( face.a, face.b, face.c );
  5959. faces.push( face.materialIndex );
  5960. if ( hasFaceVertexUv ) {
  5961. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  5962. faces.push(
  5963. getUvIndex( faceVertexUvs[ 0 ] ),
  5964. getUvIndex( faceVertexUvs[ 1 ] ),
  5965. getUvIndex( faceVertexUvs[ 2 ] )
  5966. );
  5967. }
  5968. if ( hasFaceNormal ) {
  5969. faces.push( getNormalIndex( face.normal ) );
  5970. }
  5971. if ( hasFaceVertexNormal ) {
  5972. var vertexNormals = face.vertexNormals;
  5973. faces.push(
  5974. getNormalIndex( vertexNormals[ 0 ] ),
  5975. getNormalIndex( vertexNormals[ 1 ] ),
  5976. getNormalIndex( vertexNormals[ 2 ] )
  5977. );
  5978. }
  5979. if ( hasFaceColor ) {
  5980. faces.push( getColorIndex( face.color ) );
  5981. }
  5982. if ( hasFaceVertexColor ) {
  5983. var vertexColors = face.vertexColors;
  5984. faces.push(
  5985. getColorIndex( vertexColors[ 0 ] ),
  5986. getColorIndex( vertexColors[ 1 ] ),
  5987. getColorIndex( vertexColors[ 2 ] )
  5988. );
  5989. }
  5990. }
  5991. function setBit( value, position, enabled ) {
  5992. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  5993. }
  5994. function getNormalIndex( normal ) {
  5995. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  5996. if ( normalsHash[ hash ] !== undefined ) {
  5997. return normalsHash[ hash ];
  5998. }
  5999. normalsHash[ hash ] = normals.length / 3;
  6000. normals.push( normal.x, normal.y, normal.z );
  6001. return normalsHash[ hash ];
  6002. }
  6003. function getColorIndex( color ) {
  6004. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6005. if ( colorsHash[ hash ] !== undefined ) {
  6006. return colorsHash[ hash ];
  6007. }
  6008. colorsHash[ hash ] = colors.length;
  6009. colors.push( color.getHex() );
  6010. return colorsHash[ hash ];
  6011. }
  6012. function getUvIndex( uv ) {
  6013. var hash = uv.x.toString() + uv.y.toString();
  6014. if ( uvsHash[ hash ] !== undefined ) {
  6015. return uvsHash[ hash ];
  6016. }
  6017. uvsHash[ hash ] = uvs.length / 2;
  6018. uvs.push( uv.x, uv.y );
  6019. return uvsHash[ hash ];
  6020. }
  6021. data.data = {};
  6022. data.data.vertices = vertices;
  6023. data.data.normals = normals;
  6024. if ( colors.length > 0 ) data.data.colors = colors;
  6025. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6026. data.data.faces = faces;
  6027. return data;
  6028. },
  6029. clone: function () {
  6030. /*
  6031. // Handle primitives
  6032. var parameters = this.parameters;
  6033. if ( parameters !== undefined ) {
  6034. var values = [];
  6035. for ( var key in parameters ) {
  6036. values.push( parameters[ key ] );
  6037. }
  6038. var geometry = Object.create( this.constructor.prototype );
  6039. this.constructor.apply( geometry, values );
  6040. return geometry;
  6041. }
  6042. return new this.constructor().copy( this );
  6043. */
  6044. return new Geometry().copy( this );
  6045. },
  6046. copy: function ( source ) {
  6047. var i, il, j, jl, k, kl;
  6048. // reset
  6049. this.vertices = [];
  6050. this.colors = [];
  6051. this.faces = [];
  6052. this.faceVertexUvs = [[]];
  6053. this.morphTargets = [];
  6054. this.morphNormals = [];
  6055. this.skinWeights = [];
  6056. this.skinIndices = [];
  6057. this.lineDistances = [];
  6058. this.boundingBox = null;
  6059. this.boundingSphere = null;
  6060. // name
  6061. this.name = source.name;
  6062. // vertices
  6063. var vertices = source.vertices;
  6064. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  6065. this.vertices.push( vertices[ i ].clone() );
  6066. }
  6067. // colors
  6068. var colors = source.colors;
  6069. for ( i = 0, il = colors.length; i < il; i ++ ) {
  6070. this.colors.push( colors[ i ].clone() );
  6071. }
  6072. // faces
  6073. var faces = source.faces;
  6074. for ( i = 0, il = faces.length; i < il; i ++ ) {
  6075. this.faces.push( faces[ i ].clone() );
  6076. }
  6077. // face vertex uvs
  6078. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6079. var faceVertexUvs = source.faceVertexUvs[ i ];
  6080. if ( this.faceVertexUvs[ i ] === undefined ) {
  6081. this.faceVertexUvs[ i ] = [];
  6082. }
  6083. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6084. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6085. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  6086. var uv = uvs[ k ];
  6087. uvsCopy.push( uv.clone() );
  6088. }
  6089. this.faceVertexUvs[ i ].push( uvsCopy );
  6090. }
  6091. }
  6092. // morph targets
  6093. var morphTargets = source.morphTargets;
  6094. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  6095. var morphTarget = {};
  6096. morphTarget.name = morphTargets[ i ].name;
  6097. // vertices
  6098. if ( morphTargets[ i ].vertices !== undefined ) {
  6099. morphTarget.vertices = [];
  6100. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  6101. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  6102. }
  6103. }
  6104. // normals
  6105. if ( morphTargets[ i ].normals !== undefined ) {
  6106. morphTarget.normals = [];
  6107. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  6108. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  6109. }
  6110. }
  6111. this.morphTargets.push( morphTarget );
  6112. }
  6113. // morph normals
  6114. var morphNormals = source.morphNormals;
  6115. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  6116. var morphNormal = {};
  6117. // vertex normals
  6118. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  6119. morphNormal.vertexNormals = [];
  6120. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  6121. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  6122. var destVertexNormal = {};
  6123. destVertexNormal.a = srcVertexNormal.a.clone();
  6124. destVertexNormal.b = srcVertexNormal.b.clone();
  6125. destVertexNormal.c = srcVertexNormal.c.clone();
  6126. morphNormal.vertexNormals.push( destVertexNormal );
  6127. }
  6128. }
  6129. // face normals
  6130. if ( morphNormals[ i ].faceNormals !== undefined ) {
  6131. morphNormal.faceNormals = [];
  6132. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  6133. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  6134. }
  6135. }
  6136. this.morphNormals.push( morphNormal );
  6137. }
  6138. // skin weights
  6139. var skinWeights = source.skinWeights;
  6140. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  6141. this.skinWeights.push( skinWeights[ i ].clone() );
  6142. }
  6143. // skin indices
  6144. var skinIndices = source.skinIndices;
  6145. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  6146. this.skinIndices.push( skinIndices[ i ].clone() );
  6147. }
  6148. // line distances
  6149. var lineDistances = source.lineDistances;
  6150. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  6151. this.lineDistances.push( lineDistances[ i ] );
  6152. }
  6153. // bounding box
  6154. var boundingBox = source.boundingBox;
  6155. if ( boundingBox !== null ) {
  6156. this.boundingBox = boundingBox.clone();
  6157. }
  6158. // bounding sphere
  6159. var boundingSphere = source.boundingSphere;
  6160. if ( boundingSphere !== null ) {
  6161. this.boundingSphere = boundingSphere.clone();
  6162. }
  6163. // update flags
  6164. this.elementsNeedUpdate = source.elementsNeedUpdate;
  6165. this.verticesNeedUpdate = source.verticesNeedUpdate;
  6166. this.uvsNeedUpdate = source.uvsNeedUpdate;
  6167. this.normalsNeedUpdate = source.normalsNeedUpdate;
  6168. this.colorsNeedUpdate = source.colorsNeedUpdate;
  6169. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  6170. this.groupsNeedUpdate = source.groupsNeedUpdate;
  6171. return this;
  6172. },
  6173. dispose: function () {
  6174. this.dispatchEvent( { type: 'dispose' } );
  6175. }
  6176. } );
  6177. /**
  6178. * @author mrdoob / http://mrdoob.com/
  6179. */
  6180. function BufferAttribute( array, itemSize, normalized ) {
  6181. if ( Array.isArray( array ) ) {
  6182. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6183. }
  6184. this.name = '';
  6185. this.array = array;
  6186. this.itemSize = itemSize;
  6187. this.count = array !== undefined ? array.length / itemSize : 0;
  6188. this.normalized = normalized === true;
  6189. this.dynamic = false;
  6190. this.updateRange = { offset: 0, count: - 1 };
  6191. this.version = 0;
  6192. }
  6193. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  6194. set: function ( value ) {
  6195. if ( value === true ) this.version ++;
  6196. }
  6197. } );
  6198. Object.assign( BufferAttribute.prototype, {
  6199. isBufferAttribute: true,
  6200. onUploadCallback: function () {},
  6201. setArray: function ( array ) {
  6202. if ( Array.isArray( array ) ) {
  6203. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6204. }
  6205. this.count = array !== undefined ? array.length / this.itemSize : 0;
  6206. this.array = array;
  6207. return this;
  6208. },
  6209. setDynamic: function ( value ) {
  6210. this.dynamic = value;
  6211. return this;
  6212. },
  6213. copy: function ( source ) {
  6214. this.name = source.name;
  6215. this.array = new source.array.constructor( source.array );
  6216. this.itemSize = source.itemSize;
  6217. this.count = source.count;
  6218. this.normalized = source.normalized;
  6219. this.dynamic = source.dynamic;
  6220. return this;
  6221. },
  6222. copyAt: function ( index1, attribute, index2 ) {
  6223. index1 *= this.itemSize;
  6224. index2 *= attribute.itemSize;
  6225. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  6226. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  6227. }
  6228. return this;
  6229. },
  6230. copyArray: function ( array ) {
  6231. this.array.set( array );
  6232. return this;
  6233. },
  6234. copyColorsArray: function ( colors ) {
  6235. var array = this.array, offset = 0;
  6236. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  6237. var color = colors[ i ];
  6238. if ( color === undefined ) {
  6239. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  6240. color = new Color();
  6241. }
  6242. array[ offset ++ ] = color.r;
  6243. array[ offset ++ ] = color.g;
  6244. array[ offset ++ ] = color.b;
  6245. }
  6246. return this;
  6247. },
  6248. copyVector2sArray: function ( vectors ) {
  6249. var array = this.array, offset = 0;
  6250. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6251. var vector = vectors[ i ];
  6252. if ( vector === undefined ) {
  6253. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  6254. vector = new Vector2();
  6255. }
  6256. array[ offset ++ ] = vector.x;
  6257. array[ offset ++ ] = vector.y;
  6258. }
  6259. return this;
  6260. },
  6261. copyVector3sArray: function ( vectors ) {
  6262. var array = this.array, offset = 0;
  6263. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6264. var vector = vectors[ i ];
  6265. if ( vector === undefined ) {
  6266. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  6267. vector = new Vector3();
  6268. }
  6269. array[ offset ++ ] = vector.x;
  6270. array[ offset ++ ] = vector.y;
  6271. array[ offset ++ ] = vector.z;
  6272. }
  6273. return this;
  6274. },
  6275. copyVector4sArray: function ( vectors ) {
  6276. var array = this.array, offset = 0;
  6277. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6278. var vector = vectors[ i ];
  6279. if ( vector === undefined ) {
  6280. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  6281. vector = new Vector4();
  6282. }
  6283. array[ offset ++ ] = vector.x;
  6284. array[ offset ++ ] = vector.y;
  6285. array[ offset ++ ] = vector.z;
  6286. array[ offset ++ ] = vector.w;
  6287. }
  6288. return this;
  6289. },
  6290. set: function ( value, offset ) {
  6291. if ( offset === undefined ) offset = 0;
  6292. this.array.set( value, offset );
  6293. return this;
  6294. },
  6295. getX: function ( index ) {
  6296. return this.array[ index * this.itemSize ];
  6297. },
  6298. setX: function ( index, x ) {
  6299. this.array[ index * this.itemSize ] = x;
  6300. return this;
  6301. },
  6302. getY: function ( index ) {
  6303. return this.array[ index * this.itemSize + 1 ];
  6304. },
  6305. setY: function ( index, y ) {
  6306. this.array[ index * this.itemSize + 1 ] = y;
  6307. return this;
  6308. },
  6309. getZ: function ( index ) {
  6310. return this.array[ index * this.itemSize + 2 ];
  6311. },
  6312. setZ: function ( index, z ) {
  6313. this.array[ index * this.itemSize + 2 ] = z;
  6314. return this;
  6315. },
  6316. getW: function ( index ) {
  6317. return this.array[ index * this.itemSize + 3 ];
  6318. },
  6319. setW: function ( index, w ) {
  6320. this.array[ index * this.itemSize + 3 ] = w;
  6321. return this;
  6322. },
  6323. setXY: function ( index, x, y ) {
  6324. index *= this.itemSize;
  6325. this.array[ index + 0 ] = x;
  6326. this.array[ index + 1 ] = y;
  6327. return this;
  6328. },
  6329. setXYZ: function ( index, x, y, z ) {
  6330. index *= this.itemSize;
  6331. this.array[ index + 0 ] = x;
  6332. this.array[ index + 1 ] = y;
  6333. this.array[ index + 2 ] = z;
  6334. return this;
  6335. },
  6336. setXYZW: function ( index, x, y, z, w ) {
  6337. index *= this.itemSize;
  6338. this.array[ index + 0 ] = x;
  6339. this.array[ index + 1 ] = y;
  6340. this.array[ index + 2 ] = z;
  6341. this.array[ index + 3 ] = w;
  6342. return this;
  6343. },
  6344. onUpload: function ( callback ) {
  6345. this.onUploadCallback = callback;
  6346. return this;
  6347. },
  6348. clone: function () {
  6349. return new this.constructor( this.array, this.itemSize ).copy( this );
  6350. }
  6351. } );
  6352. //
  6353. function Int8BufferAttribute( array, itemSize, normalized ) {
  6354. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  6355. }
  6356. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6357. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6358. function Uint8BufferAttribute( array, itemSize, normalized ) {
  6359. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  6360. }
  6361. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6362. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6363. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  6364. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  6365. }
  6366. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6367. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6368. function Int16BufferAttribute( array, itemSize, normalized ) {
  6369. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  6370. }
  6371. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6372. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6373. function Uint16BufferAttribute( array, itemSize, normalized ) {
  6374. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  6375. }
  6376. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6377. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6378. function Int32BufferAttribute( array, itemSize, normalized ) {
  6379. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  6380. }
  6381. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6382. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6383. function Uint32BufferAttribute( array, itemSize, normalized ) {
  6384. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  6385. }
  6386. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6387. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6388. function Float32BufferAttribute( array, itemSize, normalized ) {
  6389. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  6390. }
  6391. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6392. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6393. function Float64BufferAttribute( array, itemSize, normalized ) {
  6394. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  6395. }
  6396. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6397. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  6398. /**
  6399. * @author mrdoob / http://mrdoob.com/
  6400. */
  6401. function DirectGeometry() {
  6402. this.vertices = [];
  6403. this.normals = [];
  6404. this.colors = [];
  6405. this.uvs = [];
  6406. this.uvs2 = [];
  6407. this.groups = [];
  6408. this.morphTargets = {};
  6409. this.skinWeights = [];
  6410. this.skinIndices = [];
  6411. // this.lineDistances = [];
  6412. this.boundingBox = null;
  6413. this.boundingSphere = null;
  6414. // update flags
  6415. this.verticesNeedUpdate = false;
  6416. this.normalsNeedUpdate = false;
  6417. this.colorsNeedUpdate = false;
  6418. this.uvsNeedUpdate = false;
  6419. this.groupsNeedUpdate = false;
  6420. }
  6421. Object.assign( DirectGeometry.prototype, {
  6422. computeGroups: function ( geometry ) {
  6423. var group;
  6424. var groups = [];
  6425. var materialIndex = undefined;
  6426. var faces = geometry.faces;
  6427. for ( var i = 0; i < faces.length; i ++ ) {
  6428. var face = faces[ i ];
  6429. // materials
  6430. if ( face.materialIndex !== materialIndex ) {
  6431. materialIndex = face.materialIndex;
  6432. if ( group !== undefined ) {
  6433. group.count = ( i * 3 ) - group.start;
  6434. groups.push( group );
  6435. }
  6436. group = {
  6437. start: i * 3,
  6438. materialIndex: materialIndex
  6439. };
  6440. }
  6441. }
  6442. if ( group !== undefined ) {
  6443. group.count = ( i * 3 ) - group.start;
  6444. groups.push( group );
  6445. }
  6446. this.groups = groups;
  6447. },
  6448. fromGeometry: function ( geometry ) {
  6449. var faces = geometry.faces;
  6450. var vertices = geometry.vertices;
  6451. var faceVertexUvs = geometry.faceVertexUvs;
  6452. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6453. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6454. // morphs
  6455. var morphTargets = geometry.morphTargets;
  6456. var morphTargetsLength = morphTargets.length;
  6457. var morphTargetsPosition;
  6458. if ( morphTargetsLength > 0 ) {
  6459. morphTargetsPosition = [];
  6460. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6461. morphTargetsPosition[ i ] = [];
  6462. }
  6463. this.morphTargets.position = morphTargetsPosition;
  6464. }
  6465. var morphNormals = geometry.morphNormals;
  6466. var morphNormalsLength = morphNormals.length;
  6467. var morphTargetsNormal;
  6468. if ( morphNormalsLength > 0 ) {
  6469. morphTargetsNormal = [];
  6470. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6471. morphTargetsNormal[ i ] = [];
  6472. }
  6473. this.morphTargets.normal = morphTargetsNormal;
  6474. }
  6475. // skins
  6476. var skinIndices = geometry.skinIndices;
  6477. var skinWeights = geometry.skinWeights;
  6478. var hasSkinIndices = skinIndices.length === vertices.length;
  6479. var hasSkinWeights = skinWeights.length === vertices.length;
  6480. //
  6481. for ( var i = 0; i < faces.length; i ++ ) {
  6482. var face = faces[ i ];
  6483. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6484. var vertexNormals = face.vertexNormals;
  6485. if ( vertexNormals.length === 3 ) {
  6486. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6487. } else {
  6488. var normal = face.normal;
  6489. this.normals.push( normal, normal, normal );
  6490. }
  6491. var vertexColors = face.vertexColors;
  6492. if ( vertexColors.length === 3 ) {
  6493. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6494. } else {
  6495. var color = face.color;
  6496. this.colors.push( color, color, color );
  6497. }
  6498. if ( hasFaceVertexUv === true ) {
  6499. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6500. if ( vertexUvs !== undefined ) {
  6501. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6502. } else {
  6503. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6504. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  6505. }
  6506. }
  6507. if ( hasFaceVertexUv2 === true ) {
  6508. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6509. if ( vertexUvs !== undefined ) {
  6510. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6511. } else {
  6512. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6513. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  6514. }
  6515. }
  6516. // morphs
  6517. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6518. var morphTarget = morphTargets[ j ].vertices;
  6519. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6520. }
  6521. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6522. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6523. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6524. }
  6525. // skins
  6526. if ( hasSkinIndices ) {
  6527. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6528. }
  6529. if ( hasSkinWeights ) {
  6530. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6531. }
  6532. }
  6533. this.computeGroups( geometry );
  6534. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6535. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6536. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6537. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6538. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6539. return this;
  6540. }
  6541. } );
  6542. /**
  6543. * @author mrdoob / http://mrdoob.com/
  6544. */
  6545. function arrayMax( array ) {
  6546. if ( array.length === 0 ) return - Infinity;
  6547. var max = array[ 0 ];
  6548. for ( var i = 1, l = array.length; i < l; ++ i ) {
  6549. if ( array[ i ] > max ) max = array[ i ];
  6550. }
  6551. return max;
  6552. }
  6553. /**
  6554. * @author alteredq / http://alteredqualia.com/
  6555. * @author mrdoob / http://mrdoob.com/
  6556. */
  6557. var bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6558. function BufferGeometry() {
  6559. Object.defineProperty( this, 'id', { value: bufferGeometryId += 2 } );
  6560. this.uuid = _Math.generateUUID();
  6561. this.name = '';
  6562. this.type = 'BufferGeometry';
  6563. this.index = null;
  6564. this.attributes = {};
  6565. this.morphAttributes = {};
  6566. this.groups = [];
  6567. this.boundingBox = null;
  6568. this.boundingSphere = null;
  6569. this.drawRange = { start: 0, count: Infinity };
  6570. }
  6571. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  6572. constructor: BufferGeometry,
  6573. isBufferGeometry: true,
  6574. getIndex: function () {
  6575. return this.index;
  6576. },
  6577. setIndex: function ( index ) {
  6578. if ( Array.isArray( index ) ) {
  6579. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  6580. } else {
  6581. this.index = index;
  6582. }
  6583. },
  6584. addAttribute: function ( name, attribute ) {
  6585. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  6586. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6587. this.addAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6588. return;
  6589. }
  6590. if ( name === 'index' ) {
  6591. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6592. this.setIndex( attribute );
  6593. return;
  6594. }
  6595. this.attributes[ name ] = attribute;
  6596. return this;
  6597. },
  6598. getAttribute: function ( name ) {
  6599. return this.attributes[ name ];
  6600. },
  6601. removeAttribute: function ( name ) {
  6602. delete this.attributes[ name ];
  6603. return this;
  6604. },
  6605. addGroup: function ( start, count, materialIndex ) {
  6606. this.groups.push( {
  6607. start: start,
  6608. count: count,
  6609. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6610. } );
  6611. },
  6612. clearGroups: function () {
  6613. this.groups = [];
  6614. },
  6615. setDrawRange: function ( start, count ) {
  6616. this.drawRange.start = start;
  6617. this.drawRange.count = count;
  6618. },
  6619. applyMatrix: function ( matrix ) {
  6620. var position = this.attributes.position;
  6621. if ( position !== undefined ) {
  6622. matrix.applyToBufferAttribute( position );
  6623. position.needsUpdate = true;
  6624. }
  6625. var normal = this.attributes.normal;
  6626. if ( normal !== undefined ) {
  6627. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6628. normalMatrix.applyToBufferAttribute( normal );
  6629. normal.needsUpdate = true;
  6630. }
  6631. if ( this.boundingBox !== null ) {
  6632. this.computeBoundingBox();
  6633. }
  6634. if ( this.boundingSphere !== null ) {
  6635. this.computeBoundingSphere();
  6636. }
  6637. return this;
  6638. },
  6639. rotateX: function () {
  6640. // rotate geometry around world x-axis
  6641. var m1 = new Matrix4();
  6642. return function rotateX( angle ) {
  6643. m1.makeRotationX( angle );
  6644. this.applyMatrix( m1 );
  6645. return this;
  6646. };
  6647. }(),
  6648. rotateY: function () {
  6649. // rotate geometry around world y-axis
  6650. var m1 = new Matrix4();
  6651. return function rotateY( angle ) {
  6652. m1.makeRotationY( angle );
  6653. this.applyMatrix( m1 );
  6654. return this;
  6655. };
  6656. }(),
  6657. rotateZ: function () {
  6658. // rotate geometry around world z-axis
  6659. var m1 = new Matrix4();
  6660. return function rotateZ( angle ) {
  6661. m1.makeRotationZ( angle );
  6662. this.applyMatrix( m1 );
  6663. return this;
  6664. };
  6665. }(),
  6666. translate: function () {
  6667. // translate geometry
  6668. var m1 = new Matrix4();
  6669. return function translate( x, y, z ) {
  6670. m1.makeTranslation( x, y, z );
  6671. this.applyMatrix( m1 );
  6672. return this;
  6673. };
  6674. }(),
  6675. scale: function () {
  6676. // scale geometry
  6677. var m1 = new Matrix4();
  6678. return function scale( x, y, z ) {
  6679. m1.makeScale( x, y, z );
  6680. this.applyMatrix( m1 );
  6681. return this;
  6682. };
  6683. }(),
  6684. lookAt: function () {
  6685. var obj = new Object3D();
  6686. return function lookAt( vector ) {
  6687. obj.lookAt( vector );
  6688. obj.updateMatrix();
  6689. this.applyMatrix( obj.matrix );
  6690. };
  6691. }(),
  6692. center: function () {
  6693. var offset = new Vector3();
  6694. return function center() {
  6695. this.computeBoundingBox();
  6696. this.boundingBox.getCenter( offset ).negate();
  6697. this.translate( offset.x, offset.y, offset.z );
  6698. return this;
  6699. };
  6700. }(),
  6701. setFromObject: function ( object ) {
  6702. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6703. var geometry = object.geometry;
  6704. if ( object.isPoints || object.isLine ) {
  6705. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  6706. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  6707. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6708. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6709. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6710. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  6711. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6712. }
  6713. if ( geometry.boundingSphere !== null ) {
  6714. this.boundingSphere = geometry.boundingSphere.clone();
  6715. }
  6716. if ( geometry.boundingBox !== null ) {
  6717. this.boundingBox = geometry.boundingBox.clone();
  6718. }
  6719. } else if ( object.isMesh ) {
  6720. if ( geometry && geometry.isGeometry ) {
  6721. this.fromGeometry( geometry );
  6722. }
  6723. }
  6724. return this;
  6725. },
  6726. setFromPoints: function ( points ) {
  6727. var position = [];
  6728. for ( var i = 0, l = points.length; i < l; i ++ ) {
  6729. var point = points[ i ];
  6730. position.push( point.x, point.y, point.z || 0 );
  6731. }
  6732. this.addAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  6733. return this;
  6734. },
  6735. updateFromObject: function ( object ) {
  6736. var geometry = object.geometry;
  6737. if ( object.isMesh ) {
  6738. var direct = geometry.__directGeometry;
  6739. if ( geometry.elementsNeedUpdate === true ) {
  6740. direct = undefined;
  6741. geometry.elementsNeedUpdate = false;
  6742. }
  6743. if ( direct === undefined ) {
  6744. return this.fromGeometry( geometry );
  6745. }
  6746. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6747. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6748. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6749. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6750. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6751. geometry.verticesNeedUpdate = false;
  6752. geometry.normalsNeedUpdate = false;
  6753. geometry.colorsNeedUpdate = false;
  6754. geometry.uvsNeedUpdate = false;
  6755. geometry.groupsNeedUpdate = false;
  6756. geometry = direct;
  6757. }
  6758. var attribute;
  6759. if ( geometry.verticesNeedUpdate === true ) {
  6760. attribute = this.attributes.position;
  6761. if ( attribute !== undefined ) {
  6762. attribute.copyVector3sArray( geometry.vertices );
  6763. attribute.needsUpdate = true;
  6764. }
  6765. geometry.verticesNeedUpdate = false;
  6766. }
  6767. if ( geometry.normalsNeedUpdate === true ) {
  6768. attribute = this.attributes.normal;
  6769. if ( attribute !== undefined ) {
  6770. attribute.copyVector3sArray( geometry.normals );
  6771. attribute.needsUpdate = true;
  6772. }
  6773. geometry.normalsNeedUpdate = false;
  6774. }
  6775. if ( geometry.colorsNeedUpdate === true ) {
  6776. attribute = this.attributes.color;
  6777. if ( attribute !== undefined ) {
  6778. attribute.copyColorsArray( geometry.colors );
  6779. attribute.needsUpdate = true;
  6780. }
  6781. geometry.colorsNeedUpdate = false;
  6782. }
  6783. if ( geometry.uvsNeedUpdate ) {
  6784. attribute = this.attributes.uv;
  6785. if ( attribute !== undefined ) {
  6786. attribute.copyVector2sArray( geometry.uvs );
  6787. attribute.needsUpdate = true;
  6788. }
  6789. geometry.uvsNeedUpdate = false;
  6790. }
  6791. if ( geometry.lineDistancesNeedUpdate ) {
  6792. attribute = this.attributes.lineDistance;
  6793. if ( attribute !== undefined ) {
  6794. attribute.copyArray( geometry.lineDistances );
  6795. attribute.needsUpdate = true;
  6796. }
  6797. geometry.lineDistancesNeedUpdate = false;
  6798. }
  6799. if ( geometry.groupsNeedUpdate ) {
  6800. geometry.computeGroups( object.geometry );
  6801. this.groups = geometry.groups;
  6802. geometry.groupsNeedUpdate = false;
  6803. }
  6804. return this;
  6805. },
  6806. fromGeometry: function ( geometry ) {
  6807. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  6808. return this.fromDirectGeometry( geometry.__directGeometry );
  6809. },
  6810. fromDirectGeometry: function ( geometry ) {
  6811. var positions = new Float32Array( geometry.vertices.length * 3 );
  6812. this.addAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6813. if ( geometry.normals.length > 0 ) {
  6814. var normals = new Float32Array( geometry.normals.length * 3 );
  6815. this.addAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6816. }
  6817. if ( geometry.colors.length > 0 ) {
  6818. var colors = new Float32Array( geometry.colors.length * 3 );
  6819. this.addAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6820. }
  6821. if ( geometry.uvs.length > 0 ) {
  6822. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6823. this.addAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6824. }
  6825. if ( geometry.uvs2.length > 0 ) {
  6826. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6827. this.addAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6828. }
  6829. // groups
  6830. this.groups = geometry.groups;
  6831. // morphs
  6832. for ( var name in geometry.morphTargets ) {
  6833. var array = [];
  6834. var morphTargets = geometry.morphTargets[ name ];
  6835. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6836. var morphTarget = morphTargets[ i ];
  6837. var attribute = new Float32BufferAttribute( morphTarget.length * 3, 3 );
  6838. array.push( attribute.copyVector3sArray( morphTarget ) );
  6839. }
  6840. this.morphAttributes[ name ] = array;
  6841. }
  6842. // skinning
  6843. if ( geometry.skinIndices.length > 0 ) {
  6844. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  6845. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6846. }
  6847. if ( geometry.skinWeights.length > 0 ) {
  6848. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  6849. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6850. }
  6851. //
  6852. if ( geometry.boundingSphere !== null ) {
  6853. this.boundingSphere = geometry.boundingSphere.clone();
  6854. }
  6855. if ( geometry.boundingBox !== null ) {
  6856. this.boundingBox = geometry.boundingBox.clone();
  6857. }
  6858. return this;
  6859. },
  6860. computeBoundingBox: function () {
  6861. if ( this.boundingBox === null ) {
  6862. this.boundingBox = new Box3();
  6863. }
  6864. var position = this.attributes.position;
  6865. if ( position !== undefined ) {
  6866. this.boundingBox.setFromBufferAttribute( position );
  6867. } else {
  6868. this.boundingBox.makeEmpty();
  6869. }
  6870. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6871. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6872. }
  6873. },
  6874. computeBoundingSphere: function () {
  6875. var box = new Box3();
  6876. var vector = new Vector3();
  6877. return function computeBoundingSphere() {
  6878. if ( this.boundingSphere === null ) {
  6879. this.boundingSphere = new Sphere();
  6880. }
  6881. var position = this.attributes.position;
  6882. if ( position ) {
  6883. var center = this.boundingSphere.center;
  6884. box.setFromBufferAttribute( position );
  6885. box.getCenter( center );
  6886. // hoping to find a boundingSphere with a radius smaller than the
  6887. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6888. var maxRadiusSq = 0;
  6889. for ( var i = 0, il = position.count; i < il; i ++ ) {
  6890. vector.x = position.getX( i );
  6891. vector.y = position.getY( i );
  6892. vector.z = position.getZ( i );
  6893. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6894. }
  6895. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6896. if ( isNaN( this.boundingSphere.radius ) ) {
  6897. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6898. }
  6899. }
  6900. };
  6901. }(),
  6902. computeFaceNormals: function () {
  6903. // backwards compatibility
  6904. },
  6905. computeVertexNormals: function () {
  6906. var index = this.index;
  6907. var attributes = this.attributes;
  6908. var groups = this.groups;
  6909. if ( attributes.position ) {
  6910. var positions = attributes.position.array;
  6911. if ( attributes.normal === undefined ) {
  6912. this.addAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6913. } else {
  6914. // reset existing normals to zero
  6915. var array = attributes.normal.array;
  6916. for ( var i = 0, il = array.length; i < il; i ++ ) {
  6917. array[ i ] = 0;
  6918. }
  6919. }
  6920. var normals = attributes.normal.array;
  6921. var vA, vB, vC;
  6922. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  6923. var cb = new Vector3(), ab = new Vector3();
  6924. // indexed elements
  6925. if ( index ) {
  6926. var indices = index.array;
  6927. if ( groups.length === 0 ) {
  6928. this.addGroup( 0, indices.length );
  6929. }
  6930. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  6931. var group = groups[ j ];
  6932. var start = group.start;
  6933. var count = group.count;
  6934. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6935. vA = indices[ i + 0 ] * 3;
  6936. vB = indices[ i + 1 ] * 3;
  6937. vC = indices[ i + 2 ] * 3;
  6938. pA.fromArray( positions, vA );
  6939. pB.fromArray( positions, vB );
  6940. pC.fromArray( positions, vC );
  6941. cb.subVectors( pC, pB );
  6942. ab.subVectors( pA, pB );
  6943. cb.cross( ab );
  6944. normals[ vA ] += cb.x;
  6945. normals[ vA + 1 ] += cb.y;
  6946. normals[ vA + 2 ] += cb.z;
  6947. normals[ vB ] += cb.x;
  6948. normals[ vB + 1 ] += cb.y;
  6949. normals[ vB + 2 ] += cb.z;
  6950. normals[ vC ] += cb.x;
  6951. normals[ vC + 1 ] += cb.y;
  6952. normals[ vC + 2 ] += cb.z;
  6953. }
  6954. }
  6955. } else {
  6956. // non-indexed elements (unconnected triangle soup)
  6957. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6958. pA.fromArray( positions, i );
  6959. pB.fromArray( positions, i + 3 );
  6960. pC.fromArray( positions, i + 6 );
  6961. cb.subVectors( pC, pB );
  6962. ab.subVectors( pA, pB );
  6963. cb.cross( ab );
  6964. normals[ i ] = cb.x;
  6965. normals[ i + 1 ] = cb.y;
  6966. normals[ i + 2 ] = cb.z;
  6967. normals[ i + 3 ] = cb.x;
  6968. normals[ i + 4 ] = cb.y;
  6969. normals[ i + 5 ] = cb.z;
  6970. normals[ i + 6 ] = cb.x;
  6971. normals[ i + 7 ] = cb.y;
  6972. normals[ i + 8 ] = cb.z;
  6973. }
  6974. }
  6975. this.normalizeNormals();
  6976. attributes.normal.needsUpdate = true;
  6977. }
  6978. },
  6979. merge: function ( geometry, offset ) {
  6980. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  6981. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6982. return;
  6983. }
  6984. if ( offset === undefined ) {
  6985. offset = 0;
  6986. console.warn(
  6987. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  6988. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  6989. );
  6990. }
  6991. var attributes = this.attributes;
  6992. for ( var key in attributes ) {
  6993. if ( geometry.attributes[ key ] === undefined ) continue;
  6994. var attribute1 = attributes[ key ];
  6995. var attributeArray1 = attribute1.array;
  6996. var attribute2 = geometry.attributes[ key ];
  6997. var attributeArray2 = attribute2.array;
  6998. var attributeSize = attribute2.itemSize;
  6999. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  7000. attributeArray1[ j ] = attributeArray2[ i ];
  7001. }
  7002. }
  7003. return this;
  7004. },
  7005. normalizeNormals: function () {
  7006. var vector = new Vector3();
  7007. return function normalizeNormals() {
  7008. var normals = this.attributes.normal;
  7009. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  7010. vector.x = normals.getX( i );
  7011. vector.y = normals.getY( i );
  7012. vector.z = normals.getZ( i );
  7013. vector.normalize();
  7014. normals.setXYZ( i, vector.x, vector.y, vector.z );
  7015. }
  7016. };
  7017. }(),
  7018. toNonIndexed: function () {
  7019. if ( this.index === null ) {
  7020. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  7021. return this;
  7022. }
  7023. var geometry2 = new BufferGeometry();
  7024. var indices = this.index.array;
  7025. var attributes = this.attributes;
  7026. for ( var name in attributes ) {
  7027. var attribute = attributes[ name ];
  7028. var array = attribute.array;
  7029. var itemSize = attribute.itemSize;
  7030. var array2 = new array.constructor( indices.length * itemSize );
  7031. var index = 0, index2 = 0;
  7032. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  7033. index = indices[ i ] * itemSize;
  7034. for ( var j = 0; j < itemSize; j ++ ) {
  7035. array2[ index2 ++ ] = array[ index ++ ];
  7036. }
  7037. }
  7038. geometry2.addAttribute( name, new BufferAttribute( array2, itemSize ) );
  7039. }
  7040. var groups = this.groups;
  7041. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7042. var group = groups[ i ];
  7043. geometry2.addGroup( group.start, group.count, group.materialIndex );
  7044. }
  7045. return geometry2;
  7046. },
  7047. toJSON: function () {
  7048. var data = {
  7049. metadata: {
  7050. version: 4.5,
  7051. type: 'BufferGeometry',
  7052. generator: 'BufferGeometry.toJSON'
  7053. }
  7054. };
  7055. // standard BufferGeometry serialization
  7056. data.uuid = this.uuid;
  7057. data.type = this.type;
  7058. if ( this.name !== '' ) data.name = this.name;
  7059. if ( this.parameters !== undefined ) {
  7060. var parameters = this.parameters;
  7061. for ( var key in parameters ) {
  7062. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7063. }
  7064. return data;
  7065. }
  7066. data.data = { attributes: {} };
  7067. var index = this.index;
  7068. if ( index !== null ) {
  7069. var array = Array.prototype.slice.call( index.array );
  7070. data.data.index = {
  7071. type: index.array.constructor.name,
  7072. array: array
  7073. };
  7074. }
  7075. var attributes = this.attributes;
  7076. for ( var key in attributes ) {
  7077. var attribute = attributes[ key ];
  7078. var array = Array.prototype.slice.call( attribute.array );
  7079. data.data.attributes[ key ] = {
  7080. itemSize: attribute.itemSize,
  7081. type: attribute.array.constructor.name,
  7082. array: array,
  7083. normalized: attribute.normalized
  7084. };
  7085. }
  7086. var groups = this.groups;
  7087. if ( groups.length > 0 ) {
  7088. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7089. }
  7090. var boundingSphere = this.boundingSphere;
  7091. if ( boundingSphere !== null ) {
  7092. data.data.boundingSphere = {
  7093. center: boundingSphere.center.toArray(),
  7094. radius: boundingSphere.radius
  7095. };
  7096. }
  7097. return data;
  7098. },
  7099. clone: function () {
  7100. /*
  7101. // Handle primitives
  7102. var parameters = this.parameters;
  7103. if ( parameters !== undefined ) {
  7104. var values = [];
  7105. for ( var key in parameters ) {
  7106. values.push( parameters[ key ] );
  7107. }
  7108. var geometry = Object.create( this.constructor.prototype );
  7109. this.constructor.apply( geometry, values );
  7110. return geometry;
  7111. }
  7112. return new this.constructor().copy( this );
  7113. */
  7114. return new BufferGeometry().copy( this );
  7115. },
  7116. copy: function ( source ) {
  7117. var name, i, l;
  7118. // reset
  7119. this.index = null;
  7120. this.attributes = {};
  7121. this.morphAttributes = {};
  7122. this.groups = [];
  7123. this.boundingBox = null;
  7124. this.boundingSphere = null;
  7125. // name
  7126. this.name = source.name;
  7127. // index
  7128. var index = source.index;
  7129. if ( index !== null ) {
  7130. this.setIndex( index.clone() );
  7131. }
  7132. // attributes
  7133. var attributes = source.attributes;
  7134. for ( name in attributes ) {
  7135. var attribute = attributes[ name ];
  7136. this.addAttribute( name, attribute.clone() );
  7137. }
  7138. // morph attributes
  7139. var morphAttributes = source.morphAttributes;
  7140. for ( name in morphAttributes ) {
  7141. var array = [];
  7142. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  7143. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  7144. array.push( morphAttribute[ i ].clone() );
  7145. }
  7146. this.morphAttributes[ name ] = array;
  7147. }
  7148. // groups
  7149. var groups = source.groups;
  7150. for ( i = 0, l = groups.length; i < l; i ++ ) {
  7151. var group = groups[ i ];
  7152. this.addGroup( group.start, group.count, group.materialIndex );
  7153. }
  7154. // bounding box
  7155. var boundingBox = source.boundingBox;
  7156. if ( boundingBox !== null ) {
  7157. this.boundingBox = boundingBox.clone();
  7158. }
  7159. // bounding sphere
  7160. var boundingSphere = source.boundingSphere;
  7161. if ( boundingSphere !== null ) {
  7162. this.boundingSphere = boundingSphere.clone();
  7163. }
  7164. // draw range
  7165. this.drawRange.start = source.drawRange.start;
  7166. this.drawRange.count = source.drawRange.count;
  7167. return this;
  7168. },
  7169. dispose: function () {
  7170. this.dispatchEvent( { type: 'dispose' } );
  7171. }
  7172. } );
  7173. /**
  7174. * @author mrdoob / http://mrdoob.com/
  7175. * @author Mugen87 / https://github.com/Mugen87
  7176. */
  7177. // BoxGeometry
  7178. function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7179. Geometry.call( this );
  7180. this.type = 'BoxGeometry';
  7181. this.parameters = {
  7182. width: width,
  7183. height: height,
  7184. depth: depth,
  7185. widthSegments: widthSegments,
  7186. heightSegments: heightSegments,
  7187. depthSegments: depthSegments
  7188. };
  7189. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  7190. this.mergeVertices();
  7191. }
  7192. BoxGeometry.prototype = Object.create( Geometry.prototype );
  7193. BoxGeometry.prototype.constructor = BoxGeometry;
  7194. // BoxBufferGeometry
  7195. function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7196. BufferGeometry.call( this );
  7197. this.type = 'BoxBufferGeometry';
  7198. this.parameters = {
  7199. width: width,
  7200. height: height,
  7201. depth: depth,
  7202. widthSegments: widthSegments,
  7203. heightSegments: heightSegments,
  7204. depthSegments: depthSegments
  7205. };
  7206. var scope = this;
  7207. width = width || 1;
  7208. height = height || 1;
  7209. depth = depth || 1;
  7210. // segments
  7211. widthSegments = Math.floor( widthSegments ) || 1;
  7212. heightSegments = Math.floor( heightSegments ) || 1;
  7213. depthSegments = Math.floor( depthSegments ) || 1;
  7214. // buffers
  7215. var indices = [];
  7216. var vertices = [];
  7217. var normals = [];
  7218. var uvs = [];
  7219. // helper variables
  7220. var numberOfVertices = 0;
  7221. var groupStart = 0;
  7222. // build each side of the box geometry
  7223. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7224. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7225. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7226. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7227. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7228. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7229. // build geometry
  7230. this.setIndex( indices );
  7231. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7232. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7233. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7234. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7235. var segmentWidth = width / gridX;
  7236. var segmentHeight = height / gridY;
  7237. var widthHalf = width / 2;
  7238. var heightHalf = height / 2;
  7239. var depthHalf = depth / 2;
  7240. var gridX1 = gridX + 1;
  7241. var gridY1 = gridY + 1;
  7242. var vertexCounter = 0;
  7243. var groupCount = 0;
  7244. var ix, iy;
  7245. var vector = new Vector3();
  7246. // generate vertices, normals and uvs
  7247. for ( iy = 0; iy < gridY1; iy ++ ) {
  7248. var y = iy * segmentHeight - heightHalf;
  7249. for ( ix = 0; ix < gridX1; ix ++ ) {
  7250. var x = ix * segmentWidth - widthHalf;
  7251. // set values to correct vector component
  7252. vector[ u ] = x * udir;
  7253. vector[ v ] = y * vdir;
  7254. vector[ w ] = depthHalf;
  7255. // now apply vector to vertex buffer
  7256. vertices.push( vector.x, vector.y, vector.z );
  7257. // set values to correct vector component
  7258. vector[ u ] = 0;
  7259. vector[ v ] = 0;
  7260. vector[ w ] = depth > 0 ? 1 : - 1;
  7261. // now apply vector to normal buffer
  7262. normals.push( vector.x, vector.y, vector.z );
  7263. // uvs
  7264. uvs.push( ix / gridX );
  7265. uvs.push( 1 - ( iy / gridY ) );
  7266. // counters
  7267. vertexCounter += 1;
  7268. }
  7269. }
  7270. // indices
  7271. // 1. you need three indices to draw a single face
  7272. // 2. a single segment consists of two faces
  7273. // 3. so we need to generate six (2*3) indices per segment
  7274. for ( iy = 0; iy < gridY; iy ++ ) {
  7275. for ( ix = 0; ix < gridX; ix ++ ) {
  7276. var a = numberOfVertices + ix + gridX1 * iy;
  7277. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7278. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7279. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7280. // faces
  7281. indices.push( a, b, d );
  7282. indices.push( b, c, d );
  7283. // increase counter
  7284. groupCount += 6;
  7285. }
  7286. }
  7287. // add a group to the geometry. this will ensure multi material support
  7288. scope.addGroup( groupStart, groupCount, materialIndex );
  7289. // calculate new start value for groups
  7290. groupStart += groupCount;
  7291. // update total number of vertices
  7292. numberOfVertices += vertexCounter;
  7293. }
  7294. }
  7295. BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7296. BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
  7297. /**
  7298. * @author mrdoob / http://mrdoob.com/
  7299. * @author Mugen87 / https://github.com/Mugen87
  7300. */
  7301. // PlaneGeometry
  7302. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  7303. Geometry.call( this );
  7304. this.type = 'PlaneGeometry';
  7305. this.parameters = {
  7306. width: width,
  7307. height: height,
  7308. widthSegments: widthSegments,
  7309. heightSegments: heightSegments
  7310. };
  7311. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  7312. this.mergeVertices();
  7313. }
  7314. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  7315. PlaneGeometry.prototype.constructor = PlaneGeometry;
  7316. // PlaneBufferGeometry
  7317. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  7318. BufferGeometry.call( this );
  7319. this.type = 'PlaneBufferGeometry';
  7320. this.parameters = {
  7321. width: width,
  7322. height: height,
  7323. widthSegments: widthSegments,
  7324. heightSegments: heightSegments
  7325. };
  7326. width = width || 1;
  7327. height = height || 1;
  7328. var width_half = width / 2;
  7329. var height_half = height / 2;
  7330. var gridX = Math.floor( widthSegments ) || 1;
  7331. var gridY = Math.floor( heightSegments ) || 1;
  7332. var gridX1 = gridX + 1;
  7333. var gridY1 = gridY + 1;
  7334. var segment_width = width / gridX;
  7335. var segment_height = height / gridY;
  7336. var ix, iy;
  7337. // buffers
  7338. var indices = [];
  7339. var vertices = [];
  7340. var normals = [];
  7341. var uvs = [];
  7342. // generate vertices, normals and uvs
  7343. for ( iy = 0; iy < gridY1; iy ++ ) {
  7344. var y = iy * segment_height - height_half;
  7345. for ( ix = 0; ix < gridX1; ix ++ ) {
  7346. var x = ix * segment_width - width_half;
  7347. vertices.push( x, - y, 0 );
  7348. normals.push( 0, 0, 1 );
  7349. uvs.push( ix / gridX );
  7350. uvs.push( 1 - ( iy / gridY ) );
  7351. }
  7352. }
  7353. // indices
  7354. for ( iy = 0; iy < gridY; iy ++ ) {
  7355. for ( ix = 0; ix < gridX; ix ++ ) {
  7356. var a = ix + gridX1 * iy;
  7357. var b = ix + gridX1 * ( iy + 1 );
  7358. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  7359. var d = ( ix + 1 ) + gridX1 * iy;
  7360. // faces
  7361. indices.push( a, b, d );
  7362. indices.push( b, c, d );
  7363. }
  7364. }
  7365. // build geometry
  7366. this.setIndex( indices );
  7367. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7368. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7369. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7370. }
  7371. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7372. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  7373. /**
  7374. * @author mrdoob / http://mrdoob.com/
  7375. * @author alteredq / http://alteredqualia.com/
  7376. */
  7377. var materialId = 0;
  7378. function Material() {
  7379. Object.defineProperty( this, 'id', { value: materialId ++ } );
  7380. this.uuid = _Math.generateUUID();
  7381. this.name = '';
  7382. this.type = 'Material';
  7383. this.fog = true;
  7384. this.lights = true;
  7385. this.blending = NormalBlending;
  7386. this.side = FrontSide;
  7387. this.flatShading = false;
  7388. this.vertexColors = NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  7389. this.opacity = 1;
  7390. this.transparent = false;
  7391. this.blendSrc = SrcAlphaFactor;
  7392. this.blendDst = OneMinusSrcAlphaFactor;
  7393. this.blendEquation = AddEquation;
  7394. this.blendSrcAlpha = null;
  7395. this.blendDstAlpha = null;
  7396. this.blendEquationAlpha = null;
  7397. this.depthFunc = LessEqualDepth;
  7398. this.depthTest = true;
  7399. this.depthWrite = true;
  7400. this.clippingPlanes = null;
  7401. this.clipIntersection = false;
  7402. this.clipShadows = false;
  7403. this.shadowSide = null;
  7404. this.colorWrite = true;
  7405. this.precision = null; // override the renderer's default precision for this material
  7406. this.polygonOffset = false;
  7407. this.polygonOffsetFactor = 0;
  7408. this.polygonOffsetUnits = 0;
  7409. this.dithering = false;
  7410. this.alphaTest = 0;
  7411. this.premultipliedAlpha = false;
  7412. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  7413. this.visible = true;
  7414. this.userData = {};
  7415. this.needsUpdate = true;
  7416. }
  7417. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  7418. constructor: Material,
  7419. isMaterial: true,
  7420. onBeforeCompile: function () {},
  7421. setValues: function ( values ) {
  7422. if ( values === undefined ) return;
  7423. for ( var key in values ) {
  7424. var newValue = values[ key ];
  7425. if ( newValue === undefined ) {
  7426. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  7427. continue;
  7428. }
  7429. // for backward compatability if shading is set in the constructor
  7430. if ( key === 'shading' ) {
  7431. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  7432. this.flatShading = ( newValue === FlatShading ) ? true : false;
  7433. continue;
  7434. }
  7435. var currentValue = this[ key ];
  7436. if ( currentValue === undefined ) {
  7437. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  7438. continue;
  7439. }
  7440. if ( currentValue && currentValue.isColor ) {
  7441. currentValue.set( newValue );
  7442. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  7443. currentValue.copy( newValue );
  7444. } else if ( key === 'overdraw' ) {
  7445. // ensure overdraw is backwards-compatible with legacy boolean type
  7446. this[ key ] = Number( newValue );
  7447. } else {
  7448. this[ key ] = newValue;
  7449. }
  7450. }
  7451. },
  7452. toJSON: function ( meta ) {
  7453. var isRoot = ( meta === undefined || typeof meta === 'string' );
  7454. if ( isRoot ) {
  7455. meta = {
  7456. textures: {},
  7457. images: {}
  7458. };
  7459. }
  7460. var data = {
  7461. metadata: {
  7462. version: 4.5,
  7463. type: 'Material',
  7464. generator: 'Material.toJSON'
  7465. }
  7466. };
  7467. // standard Material serialization
  7468. data.uuid = this.uuid;
  7469. data.type = this.type;
  7470. if ( this.name !== '' ) data.name = this.name;
  7471. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  7472. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  7473. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  7474. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  7475. if ( this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  7476. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  7477. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  7478. if ( this.clearCoat !== undefined ) data.clearCoat = this.clearCoat;
  7479. if ( this.clearCoatRoughness !== undefined ) data.clearCoatRoughness = this.clearCoatRoughness;
  7480. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  7481. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  7482. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  7483. if ( this.bumpMap && this.bumpMap.isTexture ) {
  7484. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  7485. data.bumpScale = this.bumpScale;
  7486. }
  7487. if ( this.normalMap && this.normalMap.isTexture ) {
  7488. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  7489. data.normalScale = this.normalScale.toArray();
  7490. }
  7491. if ( this.displacementMap && this.displacementMap.isTexture ) {
  7492. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  7493. data.displacementScale = this.displacementScale;
  7494. data.displacementBias = this.displacementBias;
  7495. }
  7496. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  7497. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  7498. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  7499. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  7500. if ( this.envMap && this.envMap.isTexture ) {
  7501. data.envMap = this.envMap.toJSON( meta ).uuid;
  7502. data.reflectivity = this.reflectivity; // Scale behind envMap
  7503. }
  7504. if ( this.gradientMap && this.gradientMap.isTexture ) {
  7505. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  7506. }
  7507. if ( this.size !== undefined ) data.size = this.size;
  7508. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  7509. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  7510. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  7511. if ( this.side !== FrontSide ) data.side = this.side;
  7512. if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
  7513. if ( this.opacity < 1 ) data.opacity = this.opacity;
  7514. if ( this.transparent === true ) data.transparent = this.transparent;
  7515. data.depthFunc = this.depthFunc;
  7516. data.depthTest = this.depthTest;
  7517. data.depthWrite = this.depthWrite;
  7518. // rotation (SpriteMaterial)
  7519. if ( this.rotation !== 0 ) data.rotation = this.rotation;
  7520. if ( this.linewidth !== 1 ) data.linewidth = this.linewidth;
  7521. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  7522. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  7523. if ( this.scale !== undefined ) data.scale = this.scale;
  7524. if ( this.dithering === true ) data.dithering = true;
  7525. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  7526. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  7527. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  7528. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  7529. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  7530. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  7531. if ( this.morphTargets === true ) data.morphTargets = true;
  7532. if ( this.skinning === true ) data.skinning = true;
  7533. if ( this.visible === false ) data.visible = false;
  7534. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  7535. // TODO: Copied from Object3D.toJSON
  7536. function extractFromCache( cache ) {
  7537. var values = [];
  7538. for ( var key in cache ) {
  7539. var data = cache[ key ];
  7540. delete data.metadata;
  7541. values.push( data );
  7542. }
  7543. return values;
  7544. }
  7545. if ( isRoot ) {
  7546. var textures = extractFromCache( meta.textures );
  7547. var images = extractFromCache( meta.images );
  7548. if ( textures.length > 0 ) data.textures = textures;
  7549. if ( images.length > 0 ) data.images = images;
  7550. }
  7551. return data;
  7552. },
  7553. clone: function () {
  7554. return new this.constructor().copy( this );
  7555. },
  7556. copy: function ( source ) {
  7557. this.name = source.name;
  7558. this.fog = source.fog;
  7559. this.lights = source.lights;
  7560. this.blending = source.blending;
  7561. this.side = source.side;
  7562. this.flatShading = source.flatShading;
  7563. this.vertexColors = source.vertexColors;
  7564. this.opacity = source.opacity;
  7565. this.transparent = source.transparent;
  7566. this.blendSrc = source.blendSrc;
  7567. this.blendDst = source.blendDst;
  7568. this.blendEquation = source.blendEquation;
  7569. this.blendSrcAlpha = source.blendSrcAlpha;
  7570. this.blendDstAlpha = source.blendDstAlpha;
  7571. this.blendEquationAlpha = source.blendEquationAlpha;
  7572. this.depthFunc = source.depthFunc;
  7573. this.depthTest = source.depthTest;
  7574. this.depthWrite = source.depthWrite;
  7575. this.colorWrite = source.colorWrite;
  7576. this.precision = source.precision;
  7577. this.polygonOffset = source.polygonOffset;
  7578. this.polygonOffsetFactor = source.polygonOffsetFactor;
  7579. this.polygonOffsetUnits = source.polygonOffsetUnits;
  7580. this.dithering = source.dithering;
  7581. this.alphaTest = source.alphaTest;
  7582. this.premultipliedAlpha = source.premultipliedAlpha;
  7583. this.overdraw = source.overdraw;
  7584. this.visible = source.visible;
  7585. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  7586. this.clipShadows = source.clipShadows;
  7587. this.clipIntersection = source.clipIntersection;
  7588. var srcPlanes = source.clippingPlanes,
  7589. dstPlanes = null;
  7590. if ( srcPlanes !== null ) {
  7591. var n = srcPlanes.length;
  7592. dstPlanes = new Array( n );
  7593. for ( var i = 0; i !== n; ++ i )
  7594. dstPlanes[ i ] = srcPlanes[ i ].clone();
  7595. }
  7596. this.clippingPlanes = dstPlanes;
  7597. this.shadowSide = source.shadowSide;
  7598. return this;
  7599. },
  7600. dispose: function () {
  7601. this.dispatchEvent( { type: 'dispose' } );
  7602. }
  7603. } );
  7604. /**
  7605. * @author mrdoob / http://mrdoob.com/
  7606. * @author alteredq / http://alteredqualia.com/
  7607. *
  7608. * parameters = {
  7609. * color: <hex>,
  7610. * opacity: <float>,
  7611. * map: new THREE.Texture( <Image> ),
  7612. *
  7613. * lightMap: new THREE.Texture( <Image> ),
  7614. * lightMapIntensity: <float>
  7615. *
  7616. * aoMap: new THREE.Texture( <Image> ),
  7617. * aoMapIntensity: <float>
  7618. *
  7619. * specularMap: new THREE.Texture( <Image> ),
  7620. *
  7621. * alphaMap: new THREE.Texture( <Image> ),
  7622. *
  7623. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  7624. * combine: THREE.Multiply,
  7625. * reflectivity: <float>,
  7626. * refractionRatio: <float>,
  7627. *
  7628. * depthTest: <bool>,
  7629. * depthWrite: <bool>,
  7630. *
  7631. * wireframe: <boolean>,
  7632. * wireframeLinewidth: <float>,
  7633. *
  7634. * skinning: <bool>,
  7635. * morphTargets: <bool>
  7636. * }
  7637. */
  7638. function MeshBasicMaterial( parameters ) {
  7639. Material.call( this );
  7640. this.type = 'MeshBasicMaterial';
  7641. this.color = new Color( 0xffffff ); // emissive
  7642. this.map = null;
  7643. this.lightMap = null;
  7644. this.lightMapIntensity = 1.0;
  7645. this.aoMap = null;
  7646. this.aoMapIntensity = 1.0;
  7647. this.specularMap = null;
  7648. this.alphaMap = null;
  7649. this.envMap = null;
  7650. this.combine = MultiplyOperation;
  7651. this.reflectivity = 1;
  7652. this.refractionRatio = 0.98;
  7653. this.wireframe = false;
  7654. this.wireframeLinewidth = 1;
  7655. this.wireframeLinecap = 'round';
  7656. this.wireframeLinejoin = 'round';
  7657. this.skinning = false;
  7658. this.morphTargets = false;
  7659. this.lights = false;
  7660. this.setValues( parameters );
  7661. }
  7662. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  7663. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  7664. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  7665. MeshBasicMaterial.prototype.copy = function ( source ) {
  7666. Material.prototype.copy.call( this, source );
  7667. this.color.copy( source.color );
  7668. this.map = source.map;
  7669. this.lightMap = source.lightMap;
  7670. this.lightMapIntensity = source.lightMapIntensity;
  7671. this.aoMap = source.aoMap;
  7672. this.aoMapIntensity = source.aoMapIntensity;
  7673. this.specularMap = source.specularMap;
  7674. this.alphaMap = source.alphaMap;
  7675. this.envMap = source.envMap;
  7676. this.combine = source.combine;
  7677. this.reflectivity = source.reflectivity;
  7678. this.refractionRatio = source.refractionRatio;
  7679. this.wireframe = source.wireframe;
  7680. this.wireframeLinewidth = source.wireframeLinewidth;
  7681. this.wireframeLinecap = source.wireframeLinecap;
  7682. this.wireframeLinejoin = source.wireframeLinejoin;
  7683. this.skinning = source.skinning;
  7684. this.morphTargets = source.morphTargets;
  7685. return this;
  7686. };
  7687. /**
  7688. * @author alteredq / http://alteredqualia.com/
  7689. *
  7690. * parameters = {
  7691. * defines: { "label" : "value" },
  7692. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7693. *
  7694. * fragmentShader: <string>,
  7695. * vertexShader: <string>,
  7696. *
  7697. * wireframe: <boolean>,
  7698. * wireframeLinewidth: <float>,
  7699. *
  7700. * lights: <bool>,
  7701. *
  7702. * skinning: <bool>,
  7703. * morphTargets: <bool>,
  7704. * morphNormals: <bool>
  7705. * }
  7706. */
  7707. function ShaderMaterial( parameters ) {
  7708. Material.call( this );
  7709. this.type = 'ShaderMaterial';
  7710. this.defines = {};
  7711. this.uniforms = {};
  7712. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  7713. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  7714. this.linewidth = 1;
  7715. this.wireframe = false;
  7716. this.wireframeLinewidth = 1;
  7717. this.fog = false; // set to use scene fog
  7718. this.lights = false; // set to use scene lights
  7719. this.clipping = false; // set to use user-defined clipping planes
  7720. this.skinning = false; // set to use skinning attribute streams
  7721. this.morphTargets = false; // set to use morph targets
  7722. this.morphNormals = false; // set to use morph normals
  7723. this.extensions = {
  7724. derivatives: false, // set to use derivatives
  7725. fragDepth: false, // set to use fragment depth values
  7726. drawBuffers: false, // set to use draw buffers
  7727. shaderTextureLOD: false // set to use shader texture LOD
  7728. };
  7729. // When rendered geometry doesn't include these attributes but the material does,
  7730. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7731. this.defaultAttributeValues = {
  7732. 'color': [ 1, 1, 1 ],
  7733. 'uv': [ 0, 0 ],
  7734. 'uv2': [ 0, 0 ]
  7735. };
  7736. this.index0AttributeName = undefined;
  7737. this.uniformsNeedUpdate = false;
  7738. if ( parameters !== undefined ) {
  7739. if ( parameters.attributes !== undefined ) {
  7740. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  7741. }
  7742. this.setValues( parameters );
  7743. }
  7744. }
  7745. ShaderMaterial.prototype = Object.create( Material.prototype );
  7746. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7747. ShaderMaterial.prototype.isShaderMaterial = true;
  7748. ShaderMaterial.prototype.copy = function ( source ) {
  7749. Material.prototype.copy.call( this, source );
  7750. this.fragmentShader = source.fragmentShader;
  7751. this.vertexShader = source.vertexShader;
  7752. this.uniforms = UniformsUtils.clone( source.uniforms );
  7753. this.defines = Object.assign( {}, source.defines );
  7754. this.wireframe = source.wireframe;
  7755. this.wireframeLinewidth = source.wireframeLinewidth;
  7756. this.lights = source.lights;
  7757. this.clipping = source.clipping;
  7758. this.skinning = source.skinning;
  7759. this.morphTargets = source.morphTargets;
  7760. this.morphNormals = source.morphNormals;
  7761. this.extensions = source.extensions;
  7762. return this;
  7763. };
  7764. ShaderMaterial.prototype.toJSON = function ( meta ) {
  7765. var data = Material.prototype.toJSON.call( this, meta );
  7766. data.uniforms = this.uniforms;
  7767. data.vertexShader = this.vertexShader;
  7768. data.fragmentShader = this.fragmentShader;
  7769. return data;
  7770. };
  7771. /**
  7772. * @author bhouston / http://clara.io
  7773. */
  7774. function Ray( origin, direction ) {
  7775. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  7776. this.direction = ( direction !== undefined ) ? direction : new Vector3();
  7777. }
  7778. Object.assign( Ray.prototype, {
  7779. set: function ( origin, direction ) {
  7780. this.origin.copy( origin );
  7781. this.direction.copy( direction );
  7782. return this;
  7783. },
  7784. clone: function () {
  7785. return new this.constructor().copy( this );
  7786. },
  7787. copy: function ( ray ) {
  7788. this.origin.copy( ray.origin );
  7789. this.direction.copy( ray.direction );
  7790. return this;
  7791. },
  7792. at: function ( t, target ) {
  7793. if ( target === undefined ) {
  7794. console.warn( 'THREE.Ray: .at() target is now required' );
  7795. target = new Vector3();
  7796. }
  7797. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  7798. },
  7799. lookAt: function ( v ) {
  7800. this.direction.copy( v ).sub( this.origin ).normalize();
  7801. return this;
  7802. },
  7803. recast: function () {
  7804. var v1 = new Vector3();
  7805. return function recast( t ) {
  7806. this.origin.copy( this.at( t, v1 ) );
  7807. return this;
  7808. };
  7809. }(),
  7810. closestPointToPoint: function ( point, target ) {
  7811. if ( target === undefined ) {
  7812. console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
  7813. target = new Vector3();
  7814. }
  7815. target.subVectors( point, this.origin );
  7816. var directionDistance = target.dot( this.direction );
  7817. if ( directionDistance < 0 ) {
  7818. return target.copy( this.origin );
  7819. }
  7820. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  7821. },
  7822. distanceToPoint: function ( point ) {
  7823. return Math.sqrt( this.distanceSqToPoint( point ) );
  7824. },
  7825. distanceSqToPoint: function () {
  7826. var v1 = new Vector3();
  7827. return function distanceSqToPoint( point ) {
  7828. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  7829. // point behind the ray
  7830. if ( directionDistance < 0 ) {
  7831. return this.origin.distanceToSquared( point );
  7832. }
  7833. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  7834. return v1.distanceToSquared( point );
  7835. };
  7836. }(),
  7837. distanceSqToSegment: function () {
  7838. var segCenter = new Vector3();
  7839. var segDir = new Vector3();
  7840. var diff = new Vector3();
  7841. return function distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  7842. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  7843. // It returns the min distance between the ray and the segment
  7844. // defined by v0 and v1
  7845. // It can also set two optional targets :
  7846. // - The closest point on the ray
  7847. // - The closest point on the segment
  7848. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  7849. segDir.copy( v1 ).sub( v0 ).normalize();
  7850. diff.copy( this.origin ).sub( segCenter );
  7851. var segExtent = v0.distanceTo( v1 ) * 0.5;
  7852. var a01 = - this.direction.dot( segDir );
  7853. var b0 = diff.dot( this.direction );
  7854. var b1 = - diff.dot( segDir );
  7855. var c = diff.lengthSq();
  7856. var det = Math.abs( 1 - a01 * a01 );
  7857. var s0, s1, sqrDist, extDet;
  7858. if ( det > 0 ) {
  7859. // The ray and segment are not parallel.
  7860. s0 = a01 * b1 - b0;
  7861. s1 = a01 * b0 - b1;
  7862. extDet = segExtent * det;
  7863. if ( s0 >= 0 ) {
  7864. if ( s1 >= - extDet ) {
  7865. if ( s1 <= extDet ) {
  7866. // region 0
  7867. // Minimum at interior points of ray and segment.
  7868. var invDet = 1 / det;
  7869. s0 *= invDet;
  7870. s1 *= invDet;
  7871. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  7872. } else {
  7873. // region 1
  7874. s1 = segExtent;
  7875. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  7876. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7877. }
  7878. } else {
  7879. // region 5
  7880. s1 = - segExtent;
  7881. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  7882. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7883. }
  7884. } else {
  7885. if ( s1 <= - extDet ) {
  7886. // region 4
  7887. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  7888. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  7889. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7890. } else if ( s1 <= extDet ) {
  7891. // region 3
  7892. s0 = 0;
  7893. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  7894. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  7895. } else {
  7896. // region 2
  7897. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  7898. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  7899. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7900. }
  7901. }
  7902. } else {
  7903. // Ray and segment are parallel.
  7904. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  7905. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  7906. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7907. }
  7908. if ( optionalPointOnRay ) {
  7909. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  7910. }
  7911. if ( optionalPointOnSegment ) {
  7912. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  7913. }
  7914. return sqrDist;
  7915. };
  7916. }(),
  7917. intersectSphere: function () {
  7918. var v1 = new Vector3();
  7919. return function intersectSphere( sphere, target ) {
  7920. v1.subVectors( sphere.center, this.origin );
  7921. var tca = v1.dot( this.direction );
  7922. var d2 = v1.dot( v1 ) - tca * tca;
  7923. var radius2 = sphere.radius * sphere.radius;
  7924. if ( d2 > radius2 ) return null;
  7925. var thc = Math.sqrt( radius2 - d2 );
  7926. // t0 = first intersect point - entrance on front of sphere
  7927. var t0 = tca - thc;
  7928. // t1 = second intersect point - exit point on back of sphere
  7929. var t1 = tca + thc;
  7930. // test to see if both t0 and t1 are behind the ray - if so, return null
  7931. if ( t0 < 0 && t1 < 0 ) return null;
  7932. // test to see if t0 is behind the ray:
  7933. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  7934. // in order to always return an intersect point that is in front of the ray.
  7935. if ( t0 < 0 ) return this.at( t1, target );
  7936. // else t0 is in front of the ray, so return the first collision point scaled by t0
  7937. return this.at( t0, target );
  7938. };
  7939. }(),
  7940. intersectsSphere: function ( sphere ) {
  7941. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  7942. },
  7943. distanceToPlane: function ( plane ) {
  7944. var denominator = plane.normal.dot( this.direction );
  7945. if ( denominator === 0 ) {
  7946. // line is coplanar, return origin
  7947. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  7948. return 0;
  7949. }
  7950. // Null is preferable to undefined since undefined means.... it is undefined
  7951. return null;
  7952. }
  7953. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  7954. // Return if the ray never intersects the plane
  7955. return t >= 0 ? t : null;
  7956. },
  7957. intersectPlane: function ( plane, target ) {
  7958. var t = this.distanceToPlane( plane );
  7959. if ( t === null ) {
  7960. return null;
  7961. }
  7962. return this.at( t, target );
  7963. },
  7964. intersectsPlane: function ( plane ) {
  7965. // check if the ray lies on the plane first
  7966. var distToPoint = plane.distanceToPoint( this.origin );
  7967. if ( distToPoint === 0 ) {
  7968. return true;
  7969. }
  7970. var denominator = plane.normal.dot( this.direction );
  7971. if ( denominator * distToPoint < 0 ) {
  7972. return true;
  7973. }
  7974. // ray origin is behind the plane (and is pointing behind it)
  7975. return false;
  7976. },
  7977. intersectBox: function ( box, target ) {
  7978. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  7979. var invdirx = 1 / this.direction.x,
  7980. invdiry = 1 / this.direction.y,
  7981. invdirz = 1 / this.direction.z;
  7982. var origin = this.origin;
  7983. if ( invdirx >= 0 ) {
  7984. tmin = ( box.min.x - origin.x ) * invdirx;
  7985. tmax = ( box.max.x - origin.x ) * invdirx;
  7986. } else {
  7987. tmin = ( box.max.x - origin.x ) * invdirx;
  7988. tmax = ( box.min.x - origin.x ) * invdirx;
  7989. }
  7990. if ( invdiry >= 0 ) {
  7991. tymin = ( box.min.y - origin.y ) * invdiry;
  7992. tymax = ( box.max.y - origin.y ) * invdiry;
  7993. } else {
  7994. tymin = ( box.max.y - origin.y ) * invdiry;
  7995. tymax = ( box.min.y - origin.y ) * invdiry;
  7996. }
  7997. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  7998. // These lines also handle the case where tmin or tmax is NaN
  7999. // (result of 0 * Infinity). x !== x returns true if x is NaN
  8000. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  8001. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  8002. if ( invdirz >= 0 ) {
  8003. tzmin = ( box.min.z - origin.z ) * invdirz;
  8004. tzmax = ( box.max.z - origin.z ) * invdirz;
  8005. } else {
  8006. tzmin = ( box.max.z - origin.z ) * invdirz;
  8007. tzmax = ( box.min.z - origin.z ) * invdirz;
  8008. }
  8009. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  8010. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  8011. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  8012. //return point closest to the ray (positive side)
  8013. if ( tmax < 0 ) return null;
  8014. return this.at( tmin >= 0 ? tmin : tmax, target );
  8015. },
  8016. intersectsBox: ( function () {
  8017. var v = new Vector3();
  8018. return function intersectsBox( box ) {
  8019. return this.intersectBox( box, v ) !== null;
  8020. };
  8021. } )(),
  8022. intersectTriangle: function () {
  8023. // Compute the offset origin, edges, and normal.
  8024. var diff = new Vector3();
  8025. var edge1 = new Vector3();
  8026. var edge2 = new Vector3();
  8027. var normal = new Vector3();
  8028. return function intersectTriangle( a, b, c, backfaceCulling, target ) {
  8029. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  8030. edge1.subVectors( b, a );
  8031. edge2.subVectors( c, a );
  8032. normal.crossVectors( edge1, edge2 );
  8033. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  8034. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  8035. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  8036. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  8037. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  8038. var DdN = this.direction.dot( normal );
  8039. var sign;
  8040. if ( DdN > 0 ) {
  8041. if ( backfaceCulling ) return null;
  8042. sign = 1;
  8043. } else if ( DdN < 0 ) {
  8044. sign = - 1;
  8045. DdN = - DdN;
  8046. } else {
  8047. return null;
  8048. }
  8049. diff.subVectors( this.origin, a );
  8050. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  8051. // b1 < 0, no intersection
  8052. if ( DdQxE2 < 0 ) {
  8053. return null;
  8054. }
  8055. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  8056. // b2 < 0, no intersection
  8057. if ( DdE1xQ < 0 ) {
  8058. return null;
  8059. }
  8060. // b1+b2 > 1, no intersection
  8061. if ( DdQxE2 + DdE1xQ > DdN ) {
  8062. return null;
  8063. }
  8064. // Line intersects triangle, check if ray does.
  8065. var QdN = - sign * diff.dot( normal );
  8066. // t < 0, no intersection
  8067. if ( QdN < 0 ) {
  8068. return null;
  8069. }
  8070. // Ray intersects triangle.
  8071. return this.at( QdN / DdN, target );
  8072. };
  8073. }(),
  8074. applyMatrix4: function ( matrix4 ) {
  8075. this.origin.applyMatrix4( matrix4 );
  8076. this.direction.transformDirection( matrix4 );
  8077. return this;
  8078. },
  8079. equals: function ( ray ) {
  8080. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  8081. }
  8082. } );
  8083. /**
  8084. * @author bhouston / http://clara.io
  8085. */
  8086. function Line3( start, end ) {
  8087. this.start = ( start !== undefined ) ? start : new Vector3();
  8088. this.end = ( end !== undefined ) ? end : new Vector3();
  8089. }
  8090. Object.assign( Line3.prototype, {
  8091. set: function ( start, end ) {
  8092. this.start.copy( start );
  8093. this.end.copy( end );
  8094. return this;
  8095. },
  8096. clone: function () {
  8097. return new this.constructor().copy( this );
  8098. },
  8099. copy: function ( line ) {
  8100. this.start.copy( line.start );
  8101. this.end.copy( line.end );
  8102. return this;
  8103. },
  8104. getCenter: function ( target ) {
  8105. if ( target === undefined ) {
  8106. console.warn( 'THREE.Line3: .getCenter() target is now required' );
  8107. target = new Vector3();
  8108. }
  8109. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  8110. },
  8111. delta: function ( target ) {
  8112. if ( target === undefined ) {
  8113. console.warn( 'THREE.Line3: .delta() target is now required' );
  8114. target = new Vector3();
  8115. }
  8116. return target.subVectors( this.end, this.start );
  8117. },
  8118. distanceSq: function () {
  8119. return this.start.distanceToSquared( this.end );
  8120. },
  8121. distance: function () {
  8122. return this.start.distanceTo( this.end );
  8123. },
  8124. at: function ( t, target ) {
  8125. if ( target === undefined ) {
  8126. console.warn( 'THREE.Line3: .at() target is now required' );
  8127. target = new Vector3();
  8128. }
  8129. return this.delta( target ).multiplyScalar( t ).add( this.start );
  8130. },
  8131. closestPointToPointParameter: function () {
  8132. var startP = new Vector3();
  8133. var startEnd = new Vector3();
  8134. return function closestPointToPointParameter( point, clampToLine ) {
  8135. startP.subVectors( point, this.start );
  8136. startEnd.subVectors( this.end, this.start );
  8137. var startEnd2 = startEnd.dot( startEnd );
  8138. var startEnd_startP = startEnd.dot( startP );
  8139. var t = startEnd_startP / startEnd2;
  8140. if ( clampToLine ) {
  8141. t = _Math.clamp( t, 0, 1 );
  8142. }
  8143. return t;
  8144. };
  8145. }(),
  8146. closestPointToPoint: function ( point, clampToLine, target ) {
  8147. var t = this.closestPointToPointParameter( point, clampToLine );
  8148. if ( target === undefined ) {
  8149. console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' );
  8150. target = new Vector3();
  8151. }
  8152. return this.delta( target ).multiplyScalar( t ).add( this.start );
  8153. },
  8154. applyMatrix4: function ( matrix ) {
  8155. this.start.applyMatrix4( matrix );
  8156. this.end.applyMatrix4( matrix );
  8157. return this;
  8158. },
  8159. equals: function ( line ) {
  8160. return line.start.equals( this.start ) && line.end.equals( this.end );
  8161. }
  8162. } );
  8163. /**
  8164. * @author bhouston / http://clara.io
  8165. * @author mrdoob / http://mrdoob.com/
  8166. */
  8167. function Triangle( a, b, c ) {
  8168. this.a = ( a !== undefined ) ? a : new Vector3();
  8169. this.b = ( b !== undefined ) ? b : new Vector3();
  8170. this.c = ( c !== undefined ) ? c : new Vector3();
  8171. }
  8172. Object.assign( Triangle, {
  8173. getNormal: function () {
  8174. var v0 = new Vector3();
  8175. return function getNormal( a, b, c, target ) {
  8176. if ( target === undefined ) {
  8177. console.warn( 'THREE.Triangle: .getNormal() target is now required' );
  8178. target = new Vector3();
  8179. }
  8180. target.subVectors( c, b );
  8181. v0.subVectors( a, b );
  8182. target.cross( v0 );
  8183. var targetLengthSq = target.lengthSq();
  8184. if ( targetLengthSq > 0 ) {
  8185. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  8186. }
  8187. return target.set( 0, 0, 0 );
  8188. };
  8189. }(),
  8190. // static/instance method to calculate barycentric coordinates
  8191. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  8192. getBarycoord: function () {
  8193. var v0 = new Vector3();
  8194. var v1 = new Vector3();
  8195. var v2 = new Vector3();
  8196. return function getBarycoord( point, a, b, c, target ) {
  8197. v0.subVectors( c, a );
  8198. v1.subVectors( b, a );
  8199. v2.subVectors( point, a );
  8200. var dot00 = v0.dot( v0 );
  8201. var dot01 = v0.dot( v1 );
  8202. var dot02 = v0.dot( v2 );
  8203. var dot11 = v1.dot( v1 );
  8204. var dot12 = v1.dot( v2 );
  8205. var denom = ( dot00 * dot11 - dot01 * dot01 );
  8206. if ( target === undefined ) {
  8207. console.warn( 'THREE.Triangle: .getBarycoord() target is now required' );
  8208. target = new Vector3();
  8209. }
  8210. // collinear or singular triangle
  8211. if ( denom === 0 ) {
  8212. // arbitrary location outside of triangle?
  8213. // not sure if this is the best idea, maybe should be returning undefined
  8214. return target.set( - 2, - 1, - 1 );
  8215. }
  8216. var invDenom = 1 / denom;
  8217. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  8218. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  8219. // barycentric coordinates must always sum to 1
  8220. return target.set( 1 - u - v, v, u );
  8221. };
  8222. }(),
  8223. containsPoint: function () {
  8224. var v1 = new Vector3();
  8225. return function containsPoint( point, a, b, c ) {
  8226. Triangle.getBarycoord( point, a, b, c, v1 );
  8227. return ( v1.x >= 0 ) && ( v1.y >= 0 ) && ( ( v1.x + v1.y ) <= 1 );
  8228. };
  8229. }()
  8230. } );
  8231. Object.assign( Triangle.prototype, {
  8232. set: function ( a, b, c ) {
  8233. this.a.copy( a );
  8234. this.b.copy( b );
  8235. this.c.copy( c );
  8236. return this;
  8237. },
  8238. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  8239. this.a.copy( points[ i0 ] );
  8240. this.b.copy( points[ i1 ] );
  8241. this.c.copy( points[ i2 ] );
  8242. return this;
  8243. },
  8244. clone: function () {
  8245. return new this.constructor().copy( this );
  8246. },
  8247. copy: function ( triangle ) {
  8248. this.a.copy( triangle.a );
  8249. this.b.copy( triangle.b );
  8250. this.c.copy( triangle.c );
  8251. return this;
  8252. },
  8253. getArea: function () {
  8254. var v0 = new Vector3();
  8255. var v1 = new Vector3();
  8256. return function getArea() {
  8257. v0.subVectors( this.c, this.b );
  8258. v1.subVectors( this.a, this.b );
  8259. return v0.cross( v1 ).length() * 0.5;
  8260. };
  8261. }(),
  8262. getMidpoint: function ( target ) {
  8263. if ( target === undefined ) {
  8264. console.warn( 'THREE.Triangle: .getMidpoint() target is now required' );
  8265. target = new Vector3();
  8266. }
  8267. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  8268. },
  8269. getNormal: function ( target ) {
  8270. return Triangle.getNormal( this.a, this.b, this.c, target );
  8271. },
  8272. getPlane: function ( target ) {
  8273. if ( target === undefined ) {
  8274. console.warn( 'THREE.Triangle: .getPlane() target is now required' );
  8275. target = new Vector3();
  8276. }
  8277. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  8278. },
  8279. getBarycoord: function ( point, target ) {
  8280. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  8281. },
  8282. containsPoint: function ( point ) {
  8283. return Triangle.containsPoint( point, this.a, this.b, this.c );
  8284. },
  8285. intersectsBox: function ( box ) {
  8286. return box.intersectsTriangle( this );
  8287. },
  8288. closestPointToPoint: function () {
  8289. var plane = new Plane();
  8290. var edgeList = [ new Line3(), new Line3(), new Line3() ];
  8291. var projectedPoint = new Vector3();
  8292. var closestPoint = new Vector3();
  8293. return function closestPointToPoint( point, target ) {
  8294. if ( target === undefined ) {
  8295. console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
  8296. target = new Vector3();
  8297. }
  8298. var minDistance = Infinity;
  8299. // project the point onto the plane of the triangle
  8300. plane.setFromCoplanarPoints( this.a, this.b, this.c );
  8301. plane.projectPoint( point, projectedPoint );
  8302. // check if the projection lies within the triangle
  8303. if ( this.containsPoint( projectedPoint ) === true ) {
  8304. // if so, this is the closest point
  8305. target.copy( projectedPoint );
  8306. } else {
  8307. // if not, the point falls outside the triangle. the target is the closest point to the triangle's edges or vertices
  8308. edgeList[ 0 ].set( this.a, this.b );
  8309. edgeList[ 1 ].set( this.b, this.c );
  8310. edgeList[ 2 ].set( this.c, this.a );
  8311. for ( var i = 0; i < edgeList.length; i ++ ) {
  8312. edgeList[ i ].closestPointToPoint( projectedPoint, true, closestPoint );
  8313. var distance = projectedPoint.distanceToSquared( closestPoint );
  8314. if ( distance < minDistance ) {
  8315. minDistance = distance;
  8316. target.copy( closestPoint );
  8317. }
  8318. }
  8319. }
  8320. return target;
  8321. };
  8322. }(),
  8323. equals: function ( triangle ) {
  8324. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  8325. }
  8326. } );
  8327. /**
  8328. * @author mrdoob / http://mrdoob.com/
  8329. * @author alteredq / http://alteredqualia.com/
  8330. * @author mikael emtinger / http://gomo.se/
  8331. * @author jonobr1 / http://jonobr1.com/
  8332. */
  8333. function Mesh( geometry, material ) {
  8334. Object3D.call( this );
  8335. this.type = 'Mesh';
  8336. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  8337. this.material = material !== undefined ? material : new MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  8338. this.drawMode = TrianglesDrawMode;
  8339. this.updateMorphTargets();
  8340. }
  8341. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  8342. constructor: Mesh,
  8343. isMesh: true,
  8344. setDrawMode: function ( value ) {
  8345. this.drawMode = value;
  8346. },
  8347. copy: function ( source ) {
  8348. Object3D.prototype.copy.call( this, source );
  8349. this.drawMode = source.drawMode;
  8350. if ( source.morphTargetInfluences !== undefined ) {
  8351. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  8352. }
  8353. if ( source.morphTargetDictionary !== undefined ) {
  8354. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  8355. }
  8356. return this;
  8357. },
  8358. updateMorphTargets: function () {
  8359. var geometry = this.geometry;
  8360. var m, ml, name;
  8361. if ( geometry.isBufferGeometry ) {
  8362. var morphAttributes = geometry.morphAttributes;
  8363. var keys = Object.keys( morphAttributes );
  8364. if ( keys.length > 0 ) {
  8365. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  8366. if ( morphAttribute !== undefined ) {
  8367. this.morphTargetInfluences = [];
  8368. this.morphTargetDictionary = {};
  8369. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  8370. name = morphAttribute[ m ].name || String( m );
  8371. this.morphTargetInfluences.push( 0 );
  8372. this.morphTargetDictionary[ name ] = m;
  8373. }
  8374. }
  8375. }
  8376. } else {
  8377. var morphTargets = geometry.morphTargets;
  8378. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  8379. this.morphTargetInfluences = [];
  8380. this.morphTargetDictionary = {};
  8381. for ( m = 0, ml = morphTargets.length; m < ml; m ++ ) {
  8382. name = morphTargets[ m ].name || String( m );
  8383. this.morphTargetInfluences.push( 0 );
  8384. this.morphTargetDictionary[ name ] = m;
  8385. }
  8386. }
  8387. }
  8388. },
  8389. raycast: ( function () {
  8390. var inverseMatrix = new Matrix4();
  8391. var ray = new Ray();
  8392. var sphere = new Sphere();
  8393. var vA = new Vector3();
  8394. var vB = new Vector3();
  8395. var vC = new Vector3();
  8396. var tempA = new Vector3();
  8397. var tempB = new Vector3();
  8398. var tempC = new Vector3();
  8399. var uvA = new Vector2();
  8400. var uvB = new Vector2();
  8401. var uvC = new Vector2();
  8402. var barycoord = new Vector3();
  8403. var intersectionPoint = new Vector3();
  8404. var intersectionPointWorld = new Vector3();
  8405. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  8406. Triangle.getBarycoord( point, p1, p2, p3, barycoord );
  8407. uv1.multiplyScalar( barycoord.x );
  8408. uv2.multiplyScalar( barycoord.y );
  8409. uv3.multiplyScalar( barycoord.z );
  8410. uv1.add( uv2 ).add( uv3 );
  8411. return uv1.clone();
  8412. }
  8413. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  8414. var intersect;
  8415. if ( material.side === BackSide ) {
  8416. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  8417. } else {
  8418. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  8419. }
  8420. if ( intersect === null ) return null;
  8421. intersectionPointWorld.copy( point );
  8422. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  8423. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  8424. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  8425. return {
  8426. distance: distance,
  8427. point: intersectionPointWorld.clone(),
  8428. object: object
  8429. };
  8430. }
  8431. function checkBufferGeometryIntersection( object, raycaster, ray, position, uv, a, b, c ) {
  8432. vA.fromBufferAttribute( position, a );
  8433. vB.fromBufferAttribute( position, b );
  8434. vC.fromBufferAttribute( position, c );
  8435. var intersection = checkIntersection( object, object.material, raycaster, ray, vA, vB, vC, intersectionPoint );
  8436. if ( intersection ) {
  8437. if ( uv ) {
  8438. uvA.fromBufferAttribute( uv, a );
  8439. uvB.fromBufferAttribute( uv, b );
  8440. uvC.fromBufferAttribute( uv, c );
  8441. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  8442. }
  8443. var face = new Face3( a, b, c );
  8444. Triangle.getNormal( vA, vB, vC, face.normal );
  8445. intersection.face = face;
  8446. intersection.faceIndex = a;
  8447. }
  8448. return intersection;
  8449. }
  8450. return function raycast( raycaster, intersects ) {
  8451. var geometry = this.geometry;
  8452. var material = this.material;
  8453. var matrixWorld = this.matrixWorld;
  8454. if ( material === undefined ) return;
  8455. // Checking boundingSphere distance to ray
  8456. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  8457. sphere.copy( geometry.boundingSphere );
  8458. sphere.applyMatrix4( matrixWorld );
  8459. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  8460. //
  8461. inverseMatrix.getInverse( matrixWorld );
  8462. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  8463. // Check boundingBox before continuing
  8464. if ( geometry.boundingBox !== null ) {
  8465. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  8466. }
  8467. var intersection;
  8468. if ( geometry.isBufferGeometry ) {
  8469. var a, b, c;
  8470. var index = geometry.index;
  8471. var position = geometry.attributes.position;
  8472. var uv = geometry.attributes.uv;
  8473. var i, l;
  8474. if ( index !== null ) {
  8475. // indexed buffer geometry
  8476. for ( i = 0, l = index.count; i < l; i += 3 ) {
  8477. a = index.getX( i );
  8478. b = index.getX( i + 1 );
  8479. c = index.getX( i + 2 );
  8480. intersection = checkBufferGeometryIntersection( this, raycaster, ray, position, uv, a, b, c );
  8481. if ( intersection ) {
  8482. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indices buffer semantics
  8483. intersects.push( intersection );
  8484. }
  8485. }
  8486. } else if ( position !== undefined ) {
  8487. // non-indexed buffer geometry
  8488. for ( i = 0, l = position.count; i < l; i += 3 ) {
  8489. a = i;
  8490. b = i + 1;
  8491. c = i + 2;
  8492. intersection = checkBufferGeometryIntersection( this, raycaster, ray, position, uv, a, b, c );
  8493. if ( intersection ) intersects.push( intersection );
  8494. }
  8495. }
  8496. } else if ( geometry.isGeometry ) {
  8497. var fvA, fvB, fvC;
  8498. var isMultiMaterial = Array.isArray( material );
  8499. var vertices = geometry.vertices;
  8500. var faces = geometry.faces;
  8501. var uvs;
  8502. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  8503. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  8504. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  8505. var face = faces[ f ];
  8506. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  8507. if ( faceMaterial === undefined ) continue;
  8508. fvA = vertices[ face.a ];
  8509. fvB = vertices[ face.b ];
  8510. fvC = vertices[ face.c ];
  8511. if ( faceMaterial.morphTargets === true ) {
  8512. var morphTargets = geometry.morphTargets;
  8513. var morphInfluences = this.morphTargetInfluences;
  8514. vA.set( 0, 0, 0 );
  8515. vB.set( 0, 0, 0 );
  8516. vC.set( 0, 0, 0 );
  8517. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  8518. var influence = morphInfluences[ t ];
  8519. if ( influence === 0 ) continue;
  8520. var targets = morphTargets[ t ].vertices;
  8521. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  8522. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  8523. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  8524. }
  8525. vA.add( fvA );
  8526. vB.add( fvB );
  8527. vC.add( fvC );
  8528. fvA = vA;
  8529. fvB = vB;
  8530. fvC = vC;
  8531. }
  8532. intersection = checkIntersection( this, faceMaterial, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  8533. if ( intersection ) {
  8534. if ( uvs && uvs[ f ] ) {
  8535. var uvs_f = uvs[ f ];
  8536. uvA.copy( uvs_f[ 0 ] );
  8537. uvB.copy( uvs_f[ 1 ] );
  8538. uvC.copy( uvs_f[ 2 ] );
  8539. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  8540. }
  8541. intersection.face = face;
  8542. intersection.faceIndex = f;
  8543. intersects.push( intersection );
  8544. }
  8545. }
  8546. }
  8547. };
  8548. }() ),
  8549. clone: function () {
  8550. return new this.constructor( this.geometry, this.material ).copy( this );
  8551. }
  8552. } );
  8553. /**
  8554. * @author mrdoob / http://mrdoob.com/
  8555. */
  8556. function WebGLBackground( renderer, state, geometries, premultipliedAlpha ) {
  8557. var clearColor = new Color( 0x000000 );
  8558. var clearAlpha = 0;
  8559. var planeCamera, planeMesh;
  8560. var boxMesh;
  8561. function render( renderList, scene, camera, forceClear ) {
  8562. var background = scene.background;
  8563. if ( background === null ) {
  8564. setClear( clearColor, clearAlpha );
  8565. } else if ( background && background.isColor ) {
  8566. setClear( background, 1 );
  8567. forceClear = true;
  8568. }
  8569. if ( renderer.autoClear || forceClear ) {
  8570. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  8571. }
  8572. if ( background && background.isCubeTexture ) {
  8573. if ( boxMesh === undefined ) {
  8574. boxMesh = new Mesh(
  8575. new BoxBufferGeometry( 1, 1, 1 ),
  8576. new ShaderMaterial( {
  8577. uniforms: ShaderLib.cube.uniforms,
  8578. vertexShader: ShaderLib.cube.vertexShader,
  8579. fragmentShader: ShaderLib.cube.fragmentShader,
  8580. side: BackSide,
  8581. depthTest: true,
  8582. depthWrite: false,
  8583. fog: false
  8584. } )
  8585. );
  8586. boxMesh.geometry.removeAttribute( 'normal' );
  8587. boxMesh.geometry.removeAttribute( 'uv' );
  8588. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  8589. this.matrixWorld.copyPosition( camera.matrixWorld );
  8590. };
  8591. geometries.update( boxMesh.geometry );
  8592. }
  8593. boxMesh.material.uniforms.tCube.value = background;
  8594. renderList.push( boxMesh, boxMesh.geometry, boxMesh.material, 0, null );
  8595. } else if ( background && background.isTexture ) {
  8596. if ( planeCamera === undefined ) {
  8597. planeCamera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  8598. planeMesh = new Mesh(
  8599. new PlaneBufferGeometry( 2, 2 ),
  8600. new MeshBasicMaterial( { depthTest: false, depthWrite: false, fog: false } )
  8601. );
  8602. geometries.update( planeMesh.geometry );
  8603. }
  8604. planeMesh.material.map = background;
  8605. // TODO Push this to renderList
  8606. renderer.renderBufferDirect( planeCamera, null, planeMesh.geometry, planeMesh.material, planeMesh, null );
  8607. }
  8608. }
  8609. function setClear( color, alpha ) {
  8610. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  8611. }
  8612. return {
  8613. getClearColor: function () {
  8614. return clearColor;
  8615. },
  8616. setClearColor: function ( color, alpha ) {
  8617. clearColor.set( color );
  8618. clearAlpha = alpha !== undefined ? alpha : 1;
  8619. setClear( clearColor, clearAlpha );
  8620. },
  8621. getClearAlpha: function () {
  8622. return clearAlpha;
  8623. },
  8624. setClearAlpha: function ( alpha ) {
  8625. clearAlpha = alpha;
  8626. setClear( clearColor, clearAlpha );
  8627. },
  8628. render: render
  8629. };
  8630. }
  8631. /**
  8632. * @author mrdoob / http://mrdoob.com/
  8633. */
  8634. function WebGLBufferRenderer( gl, extensions, info ) {
  8635. var mode;
  8636. function setMode( value ) {
  8637. mode = value;
  8638. }
  8639. function render( start, count ) {
  8640. gl.drawArrays( mode, start, count );
  8641. info.update( count, mode );
  8642. }
  8643. function renderInstances( geometry, start, count ) {
  8644. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  8645. if ( extension === null ) {
  8646. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  8647. return;
  8648. }
  8649. var position = geometry.attributes.position;
  8650. if ( position.isInterleavedBufferAttribute ) {
  8651. count = position.data.count;
  8652. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  8653. } else {
  8654. extension.drawArraysInstancedANGLE( mode, start, count, geometry.maxInstancedCount );
  8655. }
  8656. info.update( count, mode, geometry.maxInstancedCount );
  8657. }
  8658. //
  8659. this.setMode = setMode;
  8660. this.render = render;
  8661. this.renderInstances = renderInstances;
  8662. }
  8663. /**
  8664. * @author mrdoob / http://mrdoob.com/
  8665. */
  8666. function WebGLCapabilities( gl, extensions, parameters ) {
  8667. var maxAnisotropy;
  8668. function getMaxAnisotropy() {
  8669. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  8670. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  8671. if ( extension !== null ) {
  8672. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  8673. } else {
  8674. maxAnisotropy = 0;
  8675. }
  8676. return maxAnisotropy;
  8677. }
  8678. function getMaxPrecision( precision ) {
  8679. if ( precision === 'highp' ) {
  8680. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  8681. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  8682. return 'highp';
  8683. }
  8684. precision = 'mediump';
  8685. }
  8686. if ( precision === 'mediump' ) {
  8687. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  8688. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  8689. return 'mediump';
  8690. }
  8691. }
  8692. return 'lowp';
  8693. }
  8694. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  8695. var maxPrecision = getMaxPrecision( precision );
  8696. if ( maxPrecision !== precision ) {
  8697. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  8698. precision = maxPrecision;
  8699. }
  8700. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  8701. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  8702. var maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  8703. var maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  8704. var maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  8705. var maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  8706. var maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  8707. var maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  8708. var maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  8709. var vertexTextures = maxVertexTextures > 0;
  8710. var floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  8711. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  8712. return {
  8713. getMaxAnisotropy: getMaxAnisotropy,
  8714. getMaxPrecision: getMaxPrecision,
  8715. precision: precision,
  8716. logarithmicDepthBuffer: logarithmicDepthBuffer,
  8717. maxTextures: maxTextures,
  8718. maxVertexTextures: maxVertexTextures,
  8719. maxTextureSize: maxTextureSize,
  8720. maxCubemapSize: maxCubemapSize,
  8721. maxAttributes: maxAttributes,
  8722. maxVertexUniforms: maxVertexUniforms,
  8723. maxVaryings: maxVaryings,
  8724. maxFragmentUniforms: maxFragmentUniforms,
  8725. vertexTextures: vertexTextures,
  8726. floatFragmentTextures: floatFragmentTextures,
  8727. floatVertexTextures: floatVertexTextures
  8728. };
  8729. }
  8730. /**
  8731. * @author tschw
  8732. */
  8733. function WebGLClipping() {
  8734. var scope = this,
  8735. globalState = null,
  8736. numGlobalPlanes = 0,
  8737. localClippingEnabled = false,
  8738. renderingShadows = false,
  8739. plane = new Plane(),
  8740. viewNormalMatrix = new Matrix3(),
  8741. uniform = { value: null, needsUpdate: false };
  8742. this.uniform = uniform;
  8743. this.numPlanes = 0;
  8744. this.numIntersection = 0;
  8745. this.init = function ( planes, enableLocalClipping, camera ) {
  8746. var enabled =
  8747. planes.length !== 0 ||
  8748. enableLocalClipping ||
  8749. // enable state of previous frame - the clipping code has to
  8750. // run another frame in order to reset the state:
  8751. numGlobalPlanes !== 0 ||
  8752. localClippingEnabled;
  8753. localClippingEnabled = enableLocalClipping;
  8754. globalState = projectPlanes( planes, camera, 0 );
  8755. numGlobalPlanes = planes.length;
  8756. return enabled;
  8757. };
  8758. this.beginShadows = function () {
  8759. renderingShadows = true;
  8760. projectPlanes( null );
  8761. };
  8762. this.endShadows = function () {
  8763. renderingShadows = false;
  8764. resetGlobalState();
  8765. };
  8766. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  8767. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  8768. // there's no local clipping
  8769. if ( renderingShadows ) {
  8770. // there's no global clipping
  8771. projectPlanes( null );
  8772. } else {
  8773. resetGlobalState();
  8774. }
  8775. } else {
  8776. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  8777. lGlobal = nGlobal * 4,
  8778. dstArray = cache.clippingState || null;
  8779. uniform.value = dstArray; // ensure unique state
  8780. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  8781. for ( var i = 0; i !== lGlobal; ++ i ) {
  8782. dstArray[ i ] = globalState[ i ];
  8783. }
  8784. cache.clippingState = dstArray;
  8785. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  8786. this.numPlanes += nGlobal;
  8787. }
  8788. };
  8789. function resetGlobalState() {
  8790. if ( uniform.value !== globalState ) {
  8791. uniform.value = globalState;
  8792. uniform.needsUpdate = numGlobalPlanes > 0;
  8793. }
  8794. scope.numPlanes = numGlobalPlanes;
  8795. scope.numIntersection = 0;
  8796. }
  8797. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  8798. var nPlanes = planes !== null ? planes.length : 0,
  8799. dstArray = null;
  8800. if ( nPlanes !== 0 ) {
  8801. dstArray = uniform.value;
  8802. if ( skipTransform !== true || dstArray === null ) {
  8803. var flatSize = dstOffset + nPlanes * 4,
  8804. viewMatrix = camera.matrixWorldInverse;
  8805. viewNormalMatrix.getNormalMatrix( viewMatrix );
  8806. if ( dstArray === null || dstArray.length < flatSize ) {
  8807. dstArray = new Float32Array( flatSize );
  8808. }
  8809. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  8810. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  8811. plane.normal.toArray( dstArray, i4 );
  8812. dstArray[ i4 + 3 ] = plane.constant;
  8813. }
  8814. }
  8815. uniform.value = dstArray;
  8816. uniform.needsUpdate = true;
  8817. }
  8818. scope.numPlanes = nPlanes;
  8819. return dstArray;
  8820. }
  8821. }
  8822. /**
  8823. * @author mrdoob / http://mrdoob.com/
  8824. */
  8825. function WebGLExtensions( gl ) {
  8826. var extensions = {};
  8827. return {
  8828. get: function ( name ) {
  8829. if ( extensions[ name ] !== undefined ) {
  8830. return extensions[ name ];
  8831. }
  8832. var extension;
  8833. switch ( name ) {
  8834. case 'WEBGL_depth_texture':
  8835. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  8836. break;
  8837. case 'EXT_texture_filter_anisotropic':
  8838. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  8839. break;
  8840. case 'WEBGL_compressed_texture_s3tc':
  8841. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  8842. break;
  8843. case 'WEBGL_compressed_texture_pvrtc':
  8844. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  8845. break;
  8846. default:
  8847. extension = gl.getExtension( name );
  8848. }
  8849. if ( extension === null ) {
  8850. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  8851. }
  8852. extensions[ name ] = extension;
  8853. return extension;
  8854. }
  8855. };
  8856. }
  8857. /**
  8858. * @author mrdoob / http://mrdoob.com/
  8859. */
  8860. function WebGLGeometries( gl, attributes, info ) {
  8861. var geometries = {};
  8862. var wireframeAttributes = {};
  8863. function onGeometryDispose( event ) {
  8864. var geometry = event.target;
  8865. var buffergeometry = geometries[ geometry.id ];
  8866. if ( buffergeometry.index !== null ) {
  8867. attributes.remove( buffergeometry.index );
  8868. }
  8869. for ( var name in buffergeometry.attributes ) {
  8870. attributes.remove( buffergeometry.attributes[ name ] );
  8871. }
  8872. geometry.removeEventListener( 'dispose', onGeometryDispose );
  8873. delete geometries[ geometry.id ];
  8874. // TODO Remove duplicate code
  8875. var attribute = wireframeAttributes[ geometry.id ];
  8876. if ( attribute ) {
  8877. attributes.remove( attribute );
  8878. delete wireframeAttributes[ geometry.id ];
  8879. }
  8880. attribute = wireframeAttributes[ buffergeometry.id ];
  8881. if ( attribute ) {
  8882. attributes.remove( attribute );
  8883. delete wireframeAttributes[ buffergeometry.id ];
  8884. }
  8885. //
  8886. info.memory.geometries --;
  8887. }
  8888. function get( object, geometry ) {
  8889. var buffergeometry = geometries[ geometry.id ];
  8890. if ( buffergeometry ) return buffergeometry;
  8891. geometry.addEventListener( 'dispose', onGeometryDispose );
  8892. if ( geometry.isBufferGeometry ) {
  8893. buffergeometry = geometry;
  8894. } else if ( geometry.isGeometry ) {
  8895. if ( geometry._bufferGeometry === undefined ) {
  8896. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  8897. }
  8898. buffergeometry = geometry._bufferGeometry;
  8899. }
  8900. geometries[ geometry.id ] = buffergeometry;
  8901. info.memory.geometries ++;
  8902. return buffergeometry;
  8903. }
  8904. function update( geometry ) {
  8905. var index = geometry.index;
  8906. var geometryAttributes = geometry.attributes;
  8907. if ( index !== null ) {
  8908. attributes.update( index, gl.ELEMENT_ARRAY_BUFFER );
  8909. }
  8910. for ( var name in geometryAttributes ) {
  8911. attributes.update( geometryAttributes[ name ], gl.ARRAY_BUFFER );
  8912. }
  8913. // morph targets
  8914. var morphAttributes = geometry.morphAttributes;
  8915. for ( var name in morphAttributes ) {
  8916. var array = morphAttributes[ name ];
  8917. for ( var i = 0, l = array.length; i < l; i ++ ) {
  8918. attributes.update( array[ i ], gl.ARRAY_BUFFER );
  8919. }
  8920. }
  8921. }
  8922. function getWireframeAttribute( geometry ) {
  8923. var attribute = wireframeAttributes[ geometry.id ];
  8924. if ( attribute ) return attribute;
  8925. var indices = [];
  8926. var geometryIndex = geometry.index;
  8927. var geometryAttributes = geometry.attributes;
  8928. // console.time( 'wireframe' );
  8929. if ( geometryIndex !== null ) {
  8930. var array = geometryIndex.array;
  8931. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  8932. var a = array[ i + 0 ];
  8933. var b = array[ i + 1 ];
  8934. var c = array[ i + 2 ];
  8935. indices.push( a, b, b, c, c, a );
  8936. }
  8937. } else {
  8938. var array = geometryAttributes.position.array;
  8939. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  8940. var a = i + 0;
  8941. var b = i + 1;
  8942. var c = i + 2;
  8943. indices.push( a, b, b, c, c, a );
  8944. }
  8945. }
  8946. // console.timeEnd( 'wireframe' );
  8947. attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  8948. attributes.update( attribute, gl.ELEMENT_ARRAY_BUFFER );
  8949. wireframeAttributes[ geometry.id ] = attribute;
  8950. return attribute;
  8951. }
  8952. return {
  8953. get: get,
  8954. update: update,
  8955. getWireframeAttribute: getWireframeAttribute
  8956. };
  8957. }
  8958. /**
  8959. * @author mrdoob / http://mrdoob.com/
  8960. */
  8961. function WebGLIndexedBufferRenderer( gl, extensions, info ) {
  8962. var mode;
  8963. function setMode( value ) {
  8964. mode = value;
  8965. }
  8966. var type, bytesPerElement;
  8967. function setIndex( value ) {
  8968. type = value.type;
  8969. bytesPerElement = value.bytesPerElement;
  8970. }
  8971. function render( start, count ) {
  8972. gl.drawElements( mode, count, type, start * bytesPerElement );
  8973. info.update( count, mode );
  8974. }
  8975. function renderInstances( geometry, start, count ) {
  8976. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  8977. if ( extension === null ) {
  8978. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  8979. return;
  8980. }
  8981. extension.drawElementsInstancedANGLE( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
  8982. info.update( count, mode, geometry.maxInstancedCount );
  8983. }
  8984. //
  8985. this.setMode = setMode;
  8986. this.setIndex = setIndex;
  8987. this.render = render;
  8988. this.renderInstances = renderInstances;
  8989. }
  8990. /**
  8991. * @author Mugen87 / https://github.com/Mugen87
  8992. */
  8993. function WebGLInfo( gl ) {
  8994. var memory = {
  8995. geometries: 0,
  8996. textures: 0
  8997. };
  8998. var render = {
  8999. frame: 0,
  9000. calls: 0,
  9001. triangles: 0,
  9002. points: 0,
  9003. lines: 0
  9004. };
  9005. function update( count, mode, instanceCount ) {
  9006. instanceCount = instanceCount || 1;
  9007. render.calls ++;
  9008. switch ( mode ) {
  9009. case gl.TRIANGLES:
  9010. render.triangles += instanceCount * ( count / 3 );
  9011. break;
  9012. case gl.TRIANGLE_STRIP:
  9013. case gl.TRIANGLE_FAN:
  9014. render.triangles += instanceCount * ( count - 2 );
  9015. break;
  9016. case gl.LINES:
  9017. render.lines += instanceCount * ( count / 2 );
  9018. break;
  9019. case gl.LINE_STRIP:
  9020. render.lines += instanceCount * ( count - 1 );
  9021. break;
  9022. case gl.LINE_LOOP:
  9023. render.lines += instanceCount * count;
  9024. break;
  9025. case gl.POINTS:
  9026. render.points += instanceCount * count;
  9027. break;
  9028. default:
  9029. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  9030. break;
  9031. }
  9032. }
  9033. function reset() {
  9034. render.frame ++;
  9035. render.calls = 0;
  9036. render.triangles = 0;
  9037. render.points = 0;
  9038. render.lines = 0;
  9039. }
  9040. return {
  9041. memory: memory,
  9042. render: render,
  9043. programs: null,
  9044. autoReset: true,
  9045. reset: reset,
  9046. update: update
  9047. };
  9048. }
  9049. /**
  9050. * @author mrdoob / http://mrdoob.com/
  9051. */
  9052. function absNumericalSort( a, b ) {
  9053. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  9054. }
  9055. function WebGLMorphtargets( gl ) {
  9056. var influencesList = {};
  9057. var morphInfluences = new Float32Array( 8 );
  9058. function update( object, geometry, material, program ) {
  9059. var objectInfluences = object.morphTargetInfluences;
  9060. var length = objectInfluences.length;
  9061. var influences = influencesList[ geometry.id ];
  9062. if ( influences === undefined ) {
  9063. // initialise list
  9064. influences = [];
  9065. for ( var i = 0; i < length; i ++ ) {
  9066. influences[ i ] = [ i, 0 ];
  9067. }
  9068. influencesList[ geometry.id ] = influences;
  9069. }
  9070. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9071. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9072. // Remove current morphAttributes
  9073. for ( var i = 0; i < length; i ++ ) {
  9074. var influence = influences[ i ];
  9075. if ( influence[ 1 ] !== 0 ) {
  9076. if ( morphTargets ) geometry.removeAttribute( 'morphTarget' + i );
  9077. if ( morphNormals ) geometry.removeAttribute( 'morphNormal' + i );
  9078. }
  9079. }
  9080. // Collect influences
  9081. for ( var i = 0; i < length; i ++ ) {
  9082. var influence = influences[ i ];
  9083. influence[ 0 ] = i;
  9084. influence[ 1 ] = objectInfluences[ i ];
  9085. }
  9086. influences.sort( absNumericalSort );
  9087. // Add morphAttributes
  9088. for ( var i = 0; i < 8; i ++ ) {
  9089. var influence = influences[ i ];
  9090. if ( influence ) {
  9091. var index = influence[ 0 ];
  9092. var value = influence[ 1 ];
  9093. if ( value ) {
  9094. if ( morphTargets ) geometry.addAttribute( 'morphTarget' + i, morphTargets[ index ] );
  9095. if ( morphNormals ) geometry.addAttribute( 'morphNormal' + i, morphNormals[ index ] );
  9096. morphInfluences[ i ] = value;
  9097. continue;
  9098. }
  9099. }
  9100. morphInfluences[ i ] = 0;
  9101. }
  9102. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  9103. }
  9104. return {
  9105. update: update
  9106. };
  9107. }
  9108. /**
  9109. * @author mrdoob / http://mrdoob.com/
  9110. */
  9111. function WebGLObjects( geometries, info ) {
  9112. var updateList = {};
  9113. function update( object ) {
  9114. var frame = info.render.frame;
  9115. var geometry = object.geometry;
  9116. var buffergeometry = geometries.get( object, geometry );
  9117. // Update once per frame
  9118. if ( updateList[ buffergeometry.id ] !== frame ) {
  9119. if ( geometry.isGeometry ) {
  9120. buffergeometry.updateFromObject( object );
  9121. }
  9122. geometries.update( buffergeometry );
  9123. updateList[ buffergeometry.id ] = frame;
  9124. }
  9125. return buffergeometry;
  9126. }
  9127. function dispose() {
  9128. updateList = {};
  9129. }
  9130. return {
  9131. update: update,
  9132. dispose: dispose
  9133. };
  9134. }
  9135. /**
  9136. * @author mrdoob / http://mrdoob.com/
  9137. */
  9138. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  9139. images = images !== undefined ? images : [];
  9140. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  9141. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  9142. this.flipY = false;
  9143. }
  9144. CubeTexture.prototype = Object.create( Texture.prototype );
  9145. CubeTexture.prototype.constructor = CubeTexture;
  9146. CubeTexture.prototype.isCubeTexture = true;
  9147. Object.defineProperty( CubeTexture.prototype, 'images', {
  9148. get: function () {
  9149. return this.image;
  9150. },
  9151. set: function ( value ) {
  9152. this.image = value;
  9153. }
  9154. } );
  9155. /**
  9156. * @author tschw
  9157. *
  9158. * Uniforms of a program.
  9159. * Those form a tree structure with a special top-level container for the root,
  9160. * which you get by calling 'new WebGLUniforms( gl, program, renderer )'.
  9161. *
  9162. *
  9163. * Properties of inner nodes including the top-level container:
  9164. *
  9165. * .seq - array of nested uniforms
  9166. * .map - nested uniforms by name
  9167. *
  9168. *
  9169. * Methods of all nodes except the top-level container:
  9170. *
  9171. * .setValue( gl, value, [renderer] )
  9172. *
  9173. * uploads a uniform value(s)
  9174. * the 'renderer' parameter is needed for sampler uniforms
  9175. *
  9176. *
  9177. * Static methods of the top-level container (renderer factorizations):
  9178. *
  9179. * .upload( gl, seq, values, renderer )
  9180. *
  9181. * sets uniforms in 'seq' to 'values[id].value'
  9182. *
  9183. * .seqWithValue( seq, values ) : filteredSeq
  9184. *
  9185. * filters 'seq' entries with corresponding entry in values
  9186. *
  9187. *
  9188. * Methods of the top-level container (renderer factorizations):
  9189. *
  9190. * .setValue( gl, name, value )
  9191. *
  9192. * sets uniform with name 'name' to 'value'
  9193. *
  9194. * .set( gl, obj, prop )
  9195. *
  9196. * sets uniform from object and property with same name than uniform
  9197. *
  9198. * .setOptional( gl, obj, prop )
  9199. *
  9200. * like .set for an optional property of the object
  9201. *
  9202. */
  9203. var emptyTexture = new Texture();
  9204. var emptyCubeTexture = new CubeTexture();
  9205. // --- Base for inner nodes (including the root) ---
  9206. function UniformContainer() {
  9207. this.seq = [];
  9208. this.map = {};
  9209. }
  9210. // --- Utilities ---
  9211. // Array Caches (provide typed arrays for temporary by size)
  9212. var arrayCacheF32 = [];
  9213. var arrayCacheI32 = [];
  9214. // Float32Array caches used for uploading Matrix uniforms
  9215. var mat4array = new Float32Array( 16 );
  9216. var mat3array = new Float32Array( 9 );
  9217. // Flattening for arrays of vectors and matrices
  9218. function flatten( array, nBlocks, blockSize ) {
  9219. var firstElem = array[ 0 ];
  9220. if ( firstElem <= 0 || firstElem > 0 ) return array;
  9221. // unoptimized: ! isNaN( firstElem )
  9222. // see http://jacksondunstan.com/articles/983
  9223. var n = nBlocks * blockSize,
  9224. r = arrayCacheF32[ n ];
  9225. if ( r === undefined ) {
  9226. r = new Float32Array( n );
  9227. arrayCacheF32[ n ] = r;
  9228. }
  9229. if ( nBlocks !== 0 ) {
  9230. firstElem.toArray( r, 0 );
  9231. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  9232. offset += blockSize;
  9233. array[ i ].toArray( r, offset );
  9234. }
  9235. }
  9236. return r;
  9237. }
  9238. // Texture unit allocation
  9239. function allocTexUnits( renderer, n ) {
  9240. var r = arrayCacheI32[ n ];
  9241. if ( r === undefined ) {
  9242. r = new Int32Array( n );
  9243. arrayCacheI32[ n ] = r;
  9244. }
  9245. for ( var i = 0; i !== n; ++ i )
  9246. r[ i ] = renderer.allocTextureUnit();
  9247. return r;
  9248. }
  9249. // --- Setters ---
  9250. // Note: Defining these methods externally, because they come in a bunch
  9251. // and this way their names minify.
  9252. // Single scalar
  9253. function setValue1f( gl, v ) {
  9254. gl.uniform1f( this.addr, v );
  9255. }
  9256. function setValue1i( gl, v ) {
  9257. gl.uniform1i( this.addr, v );
  9258. }
  9259. // Single float vector (from flat array or THREE.VectorN)
  9260. function setValue2fv( gl, v ) {
  9261. if ( v.x === undefined ) {
  9262. gl.uniform2fv( this.addr, v );
  9263. } else {
  9264. gl.uniform2f( this.addr, v.x, v.y );
  9265. }
  9266. }
  9267. function setValue3fv( gl, v ) {
  9268. if ( v.x !== undefined ) {
  9269. gl.uniform3f( this.addr, v.x, v.y, v.z );
  9270. } else if ( v.r !== undefined ) {
  9271. gl.uniform3f( this.addr, v.r, v.g, v.b );
  9272. } else {
  9273. gl.uniform3fv( this.addr, v );
  9274. }
  9275. }
  9276. function setValue4fv( gl, v ) {
  9277. if ( v.x === undefined ) {
  9278. gl.uniform4fv( this.addr, v );
  9279. } else {
  9280. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  9281. }
  9282. }
  9283. // Single matrix (from flat array or MatrixN)
  9284. function setValue2fm( gl, v ) {
  9285. gl.uniformMatrix2fv( this.addr, false, v.elements || v );
  9286. }
  9287. function setValue3fm( gl, v ) {
  9288. if ( v.elements === undefined ) {
  9289. gl.uniformMatrix3fv( this.addr, false, v );
  9290. } else {
  9291. mat3array.set( v.elements );
  9292. gl.uniformMatrix3fv( this.addr, false, mat3array );
  9293. }
  9294. }
  9295. function setValue4fm( gl, v ) {
  9296. if ( v.elements === undefined ) {
  9297. gl.uniformMatrix4fv( this.addr, false, v );
  9298. } else {
  9299. mat4array.set( v.elements );
  9300. gl.uniformMatrix4fv( this.addr, false, mat4array );
  9301. }
  9302. }
  9303. // Single texture (2D / Cube)
  9304. function setValueT1( gl, v, renderer ) {
  9305. var unit = renderer.allocTextureUnit();
  9306. gl.uniform1i( this.addr, unit );
  9307. renderer.setTexture2D( v || emptyTexture, unit );
  9308. }
  9309. function setValueT6( gl, v, renderer ) {
  9310. var unit = renderer.allocTextureUnit();
  9311. gl.uniform1i( this.addr, unit );
  9312. renderer.setTextureCube( v || emptyCubeTexture, unit );
  9313. }
  9314. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  9315. function setValue2iv( gl, v ) {
  9316. gl.uniform2iv( this.addr, v );
  9317. }
  9318. function setValue3iv( gl, v ) {
  9319. gl.uniform3iv( this.addr, v );
  9320. }
  9321. function setValue4iv( gl, v ) {
  9322. gl.uniform4iv( this.addr, v );
  9323. }
  9324. // Helper to pick the right setter for the singular case
  9325. function getSingularSetter( type ) {
  9326. switch ( type ) {
  9327. case 0x1406: return setValue1f; // FLOAT
  9328. case 0x8b50: return setValue2fv; // _VEC2
  9329. case 0x8b51: return setValue3fv; // _VEC3
  9330. case 0x8b52: return setValue4fv; // _VEC4
  9331. case 0x8b5a: return setValue2fm; // _MAT2
  9332. case 0x8b5b: return setValue3fm; // _MAT3
  9333. case 0x8b5c: return setValue4fm; // _MAT4
  9334. case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
  9335. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  9336. case 0x1404: case 0x8b56: return setValue1i; // INT, BOOL
  9337. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  9338. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  9339. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  9340. }
  9341. }
  9342. // Array of scalars
  9343. function setValue1fv( gl, v ) {
  9344. gl.uniform1fv( this.addr, v );
  9345. }
  9346. function setValue1iv( gl, v ) {
  9347. gl.uniform1iv( this.addr, v );
  9348. }
  9349. // Array of vectors (flat or from THREE classes)
  9350. function setValueV2a( gl, v ) {
  9351. gl.uniform2fv( this.addr, flatten( v, this.size, 2 ) );
  9352. }
  9353. function setValueV3a( gl, v ) {
  9354. gl.uniform3fv( this.addr, flatten( v, this.size, 3 ) );
  9355. }
  9356. function setValueV4a( gl, v ) {
  9357. gl.uniform4fv( this.addr, flatten( v, this.size, 4 ) );
  9358. }
  9359. // Array of matrices (flat or from THREE clases)
  9360. function setValueM2a( gl, v ) {
  9361. gl.uniformMatrix2fv( this.addr, false, flatten( v, this.size, 4 ) );
  9362. }
  9363. function setValueM3a( gl, v ) {
  9364. gl.uniformMatrix3fv( this.addr, false, flatten( v, this.size, 9 ) );
  9365. }
  9366. function setValueM4a( gl, v ) {
  9367. gl.uniformMatrix4fv( this.addr, false, flatten( v, this.size, 16 ) );
  9368. }
  9369. // Array of textures (2D / Cube)
  9370. function setValueT1a( gl, v, renderer ) {
  9371. var n = v.length,
  9372. units = allocTexUnits( renderer, n );
  9373. gl.uniform1iv( this.addr, units );
  9374. for ( var i = 0; i !== n; ++ i ) {
  9375. renderer.setTexture2D( v[ i ] || emptyTexture, units[ i ] );
  9376. }
  9377. }
  9378. function setValueT6a( gl, v, renderer ) {
  9379. var n = v.length,
  9380. units = allocTexUnits( renderer, n );
  9381. gl.uniform1iv( this.addr, units );
  9382. for ( var i = 0; i !== n; ++ i ) {
  9383. renderer.setTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  9384. }
  9385. }
  9386. // Helper to pick the right setter for a pure (bottom-level) array
  9387. function getPureArraySetter( type ) {
  9388. switch ( type ) {
  9389. case 0x1406: return setValue1fv; // FLOAT
  9390. case 0x8b50: return setValueV2a; // _VEC2
  9391. case 0x8b51: return setValueV3a; // _VEC3
  9392. case 0x8b52: return setValueV4a; // _VEC4
  9393. case 0x8b5a: return setValueM2a; // _MAT2
  9394. case 0x8b5b: return setValueM3a; // _MAT3
  9395. case 0x8b5c: return setValueM4a; // _MAT4
  9396. case 0x8b5e: return setValueT1a; // SAMPLER_2D
  9397. case 0x8b60: return setValueT6a; // SAMPLER_CUBE
  9398. case 0x1404: case 0x8b56: return setValue1iv; // INT, BOOL
  9399. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  9400. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  9401. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  9402. }
  9403. }
  9404. // --- Uniform Classes ---
  9405. function SingleUniform( id, activeInfo, addr ) {
  9406. this.id = id;
  9407. this.addr = addr;
  9408. this.setValue = getSingularSetter( activeInfo.type );
  9409. // this.path = activeInfo.name; // DEBUG
  9410. }
  9411. function PureArrayUniform( id, activeInfo, addr ) {
  9412. this.id = id;
  9413. this.addr = addr;
  9414. this.size = activeInfo.size;
  9415. this.setValue = getPureArraySetter( activeInfo.type );
  9416. // this.path = activeInfo.name; // DEBUG
  9417. }
  9418. function StructuredUniform( id ) {
  9419. this.id = id;
  9420. UniformContainer.call( this ); // mix-in
  9421. }
  9422. StructuredUniform.prototype.setValue = function ( gl, value ) {
  9423. // Note: Don't need an extra 'renderer' parameter, since samplers
  9424. // are not allowed in structured uniforms.
  9425. var seq = this.seq;
  9426. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9427. var u = seq[ i ];
  9428. u.setValue( gl, value[ u.id ] );
  9429. }
  9430. };
  9431. // --- Top-level ---
  9432. // Parser - builds up the property tree from the path strings
  9433. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  9434. // extracts
  9435. // - the identifier (member name or array index)
  9436. // - followed by an optional right bracket (found when array index)
  9437. // - followed by an optional left bracket or dot (type of subscript)
  9438. //
  9439. // Note: These portions can be read in a non-overlapping fashion and
  9440. // allow straightforward parsing of the hierarchy that WebGL encodes
  9441. // in the uniform names.
  9442. function addUniform( container, uniformObject ) {
  9443. container.seq.push( uniformObject );
  9444. container.map[ uniformObject.id ] = uniformObject;
  9445. }
  9446. function parseUniform( activeInfo, addr, container ) {
  9447. var path = activeInfo.name,
  9448. pathLength = path.length;
  9449. // reset RegExp object, because of the early exit of a previous run
  9450. RePathPart.lastIndex = 0;
  9451. for ( ; ; ) {
  9452. var match = RePathPart.exec( path ),
  9453. matchEnd = RePathPart.lastIndex,
  9454. id = match[ 1 ],
  9455. idIsIndex = match[ 2 ] === ']',
  9456. subscript = match[ 3 ];
  9457. if ( idIsIndex ) id = id | 0; // convert to integer
  9458. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  9459. // bare name or "pure" bottom-level array "[0]" suffix
  9460. addUniform( container, subscript === undefined ?
  9461. new SingleUniform( id, activeInfo, addr ) :
  9462. new PureArrayUniform( id, activeInfo, addr ) );
  9463. break;
  9464. } else {
  9465. // step into inner node / create it in case it doesn't exist
  9466. var map = container.map, next = map[ id ];
  9467. if ( next === undefined ) {
  9468. next = new StructuredUniform( id );
  9469. addUniform( container, next );
  9470. }
  9471. container = next;
  9472. }
  9473. }
  9474. }
  9475. // Root Container
  9476. function WebGLUniforms( gl, program, renderer ) {
  9477. UniformContainer.call( this );
  9478. this.renderer = renderer;
  9479. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  9480. for ( var i = 0; i < n; ++ i ) {
  9481. var info = gl.getActiveUniform( program, i ),
  9482. addr = gl.getUniformLocation( program, info.name );
  9483. parseUniform( info, addr, this );
  9484. }
  9485. }
  9486. WebGLUniforms.prototype.setValue = function ( gl, name, value ) {
  9487. var u = this.map[ name ];
  9488. if ( u !== undefined ) u.setValue( gl, value, this.renderer );
  9489. };
  9490. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  9491. var v = object[ name ];
  9492. if ( v !== undefined ) this.setValue( gl, name, v );
  9493. };
  9494. // Static interface
  9495. WebGLUniforms.upload = function ( gl, seq, values, renderer ) {
  9496. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9497. var u = seq[ i ],
  9498. v = values[ u.id ];
  9499. if ( v.needsUpdate !== false ) {
  9500. // note: always updating when .needsUpdate is undefined
  9501. u.setValue( gl, v.value, renderer );
  9502. }
  9503. }
  9504. };
  9505. WebGLUniforms.seqWithValue = function ( seq, values ) {
  9506. var r = [];
  9507. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9508. var u = seq[ i ];
  9509. if ( u.id in values ) r.push( u );
  9510. }
  9511. return r;
  9512. };
  9513. /**
  9514. * @author mrdoob / http://mrdoob.com/
  9515. */
  9516. function addLineNumbers( string ) {
  9517. var lines = string.split( '\n' );
  9518. for ( var i = 0; i < lines.length; i ++ ) {
  9519. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  9520. }
  9521. return lines.join( '\n' );
  9522. }
  9523. function WebGLShader( gl, type, string ) {
  9524. var shader = gl.createShader( type );
  9525. gl.shaderSource( shader, string );
  9526. gl.compileShader( shader );
  9527. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  9528. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  9529. }
  9530. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  9531. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  9532. }
  9533. // --enable-privileged-webgl-extension
  9534. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  9535. return shader;
  9536. }
  9537. /**
  9538. * @author mrdoob / http://mrdoob.com/
  9539. */
  9540. var programIdCount = 0;
  9541. function getEncodingComponents( encoding ) {
  9542. switch ( encoding ) {
  9543. case LinearEncoding:
  9544. return [ 'Linear', '( value )' ];
  9545. case sRGBEncoding:
  9546. return [ 'sRGB', '( value )' ];
  9547. case RGBEEncoding:
  9548. return [ 'RGBE', '( value )' ];
  9549. case RGBM7Encoding:
  9550. return [ 'RGBM', '( value, 7.0 )' ];
  9551. case RGBM16Encoding:
  9552. return [ 'RGBM', '( value, 16.0 )' ];
  9553. case RGBDEncoding:
  9554. return [ 'RGBD', '( value, 256.0 )' ];
  9555. case GammaEncoding:
  9556. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  9557. default:
  9558. throw new Error( 'unsupported encoding: ' + encoding );
  9559. }
  9560. }
  9561. function getTexelDecodingFunction( functionName, encoding ) {
  9562. var components = getEncodingComponents( encoding );
  9563. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  9564. }
  9565. function getTexelEncodingFunction( functionName, encoding ) {
  9566. var components = getEncodingComponents( encoding );
  9567. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  9568. }
  9569. function getToneMappingFunction( functionName, toneMapping ) {
  9570. var toneMappingName;
  9571. switch ( toneMapping ) {
  9572. case LinearToneMapping:
  9573. toneMappingName = 'Linear';
  9574. break;
  9575. case ReinhardToneMapping:
  9576. toneMappingName = 'Reinhard';
  9577. break;
  9578. case Uncharted2ToneMapping:
  9579. toneMappingName = 'Uncharted2';
  9580. break;
  9581. case CineonToneMapping:
  9582. toneMappingName = 'OptimizedCineon';
  9583. break;
  9584. default:
  9585. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  9586. }
  9587. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  9588. }
  9589. function generateExtensions( extensions, parameters, rendererExtensions ) {
  9590. extensions = extensions || {};
  9591. var chunks = [
  9592. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.normalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  9593. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  9594. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  9595. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  9596. ];
  9597. return chunks.filter( filterEmptyLine ).join( '\n' );
  9598. }
  9599. function generateDefines( defines ) {
  9600. var chunks = [];
  9601. for ( var name in defines ) {
  9602. var value = defines[ name ];
  9603. if ( value === false ) continue;
  9604. chunks.push( '#define ' + name + ' ' + value );
  9605. }
  9606. return chunks.join( '\n' );
  9607. }
  9608. function fetchAttributeLocations( gl, program ) {
  9609. var attributes = {};
  9610. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  9611. for ( var i = 0; i < n; i ++ ) {
  9612. var info = gl.getActiveAttrib( program, i );
  9613. var name = info.name;
  9614. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  9615. attributes[ name ] = gl.getAttribLocation( program, name );
  9616. }
  9617. return attributes;
  9618. }
  9619. function filterEmptyLine( string ) {
  9620. return string !== '';
  9621. }
  9622. function replaceLightNums( string, parameters ) {
  9623. return string
  9624. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  9625. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  9626. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  9627. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  9628. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  9629. }
  9630. function replaceClippingPlaneNums( string, parameters ) {
  9631. return string
  9632. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  9633. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  9634. }
  9635. function parseIncludes( string ) {
  9636. var pattern = /^[ \t]*#include +<([\w\d.]+)>/gm;
  9637. function replace( match, include ) {
  9638. var replace = ShaderChunk[ include ];
  9639. if ( replace === undefined ) {
  9640. throw new Error( 'Can not resolve #include <' + include + '>' );
  9641. }
  9642. return parseIncludes( replace );
  9643. }
  9644. return string.replace( pattern, replace );
  9645. }
  9646. function unrollLoops( string ) {
  9647. var pattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  9648. function replace( match, start, end, snippet ) {
  9649. var unroll = '';
  9650. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  9651. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  9652. }
  9653. return unroll;
  9654. }
  9655. return string.replace( pattern, replace );
  9656. }
  9657. function WebGLProgram( renderer, extensions, code, material, shader, parameters ) {
  9658. var gl = renderer.context;
  9659. var defines = material.defines;
  9660. var vertexShader = shader.vertexShader;
  9661. var fragmentShader = shader.fragmentShader;
  9662. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  9663. if ( parameters.shadowMapType === PCFShadowMap ) {
  9664. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  9665. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  9666. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  9667. }
  9668. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  9669. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  9670. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  9671. if ( parameters.envMap ) {
  9672. switch ( material.envMap.mapping ) {
  9673. case CubeReflectionMapping:
  9674. case CubeRefractionMapping:
  9675. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  9676. break;
  9677. case CubeUVReflectionMapping:
  9678. case CubeUVRefractionMapping:
  9679. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  9680. break;
  9681. case EquirectangularReflectionMapping:
  9682. case EquirectangularRefractionMapping:
  9683. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  9684. break;
  9685. case SphericalReflectionMapping:
  9686. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  9687. break;
  9688. }
  9689. switch ( material.envMap.mapping ) {
  9690. case CubeRefractionMapping:
  9691. case EquirectangularRefractionMapping:
  9692. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  9693. break;
  9694. }
  9695. switch ( material.combine ) {
  9696. case MultiplyOperation:
  9697. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  9698. break;
  9699. case MixOperation:
  9700. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  9701. break;
  9702. case AddOperation:
  9703. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  9704. break;
  9705. }
  9706. }
  9707. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  9708. // console.log( 'building new program ' );
  9709. //
  9710. var customExtensions = generateExtensions( material.extensions, parameters, extensions );
  9711. var customDefines = generateDefines( defines );
  9712. //
  9713. var program = gl.createProgram();
  9714. var prefixVertex, prefixFragment;
  9715. if ( material.isRawShaderMaterial ) {
  9716. prefixVertex = [
  9717. customDefines
  9718. ].filter( filterEmptyLine ).join( '\n' );
  9719. if ( prefixVertex.length > 0 ) {
  9720. prefixVertex += '\n';
  9721. }
  9722. prefixFragment = [
  9723. customExtensions,
  9724. customDefines
  9725. ].filter( filterEmptyLine ).join( '\n' );
  9726. if ( prefixFragment.length > 0 ) {
  9727. prefixFragment += '\n';
  9728. }
  9729. } else {
  9730. prefixVertex = [
  9731. 'precision ' + parameters.precision + ' float;',
  9732. 'precision ' + parameters.precision + ' int;',
  9733. '#define SHADER_NAME ' + shader.name,
  9734. customDefines,
  9735. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  9736. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  9737. '#define MAX_BONES ' + parameters.maxBones,
  9738. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  9739. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  9740. parameters.map ? '#define USE_MAP' : '',
  9741. parameters.envMap ? '#define USE_ENVMAP' : '',
  9742. parameters.envMap ? '#define ' + envMapModeDefine : '',
  9743. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  9744. parameters.aoMap ? '#define USE_AOMAP' : '',
  9745. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  9746. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  9747. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  9748. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  9749. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  9750. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  9751. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  9752. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  9753. parameters.vertexColors ? '#define USE_COLOR' : '',
  9754. parameters.flatShading ? '#define FLAT_SHADED' : '',
  9755. parameters.skinning ? '#define USE_SKINNING' : '',
  9756. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  9757. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  9758. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  9759. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  9760. parameters.flipSided ? '#define FLIP_SIDED' : '',
  9761. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  9762. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  9763. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  9764. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  9765. parameters.logarithmicDepthBuffer && extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  9766. 'uniform mat4 modelMatrix;',
  9767. 'uniform mat4 modelViewMatrix;',
  9768. 'uniform mat4 projectionMatrix;',
  9769. 'uniform mat4 viewMatrix;',
  9770. 'uniform mat3 normalMatrix;',
  9771. 'uniform vec3 cameraPosition;',
  9772. 'attribute vec3 position;',
  9773. 'attribute vec3 normal;',
  9774. 'attribute vec2 uv;',
  9775. '#ifdef USE_COLOR',
  9776. ' attribute vec3 color;',
  9777. '#endif',
  9778. '#ifdef USE_MORPHTARGETS',
  9779. ' attribute vec3 morphTarget0;',
  9780. ' attribute vec3 morphTarget1;',
  9781. ' attribute vec3 morphTarget2;',
  9782. ' attribute vec3 morphTarget3;',
  9783. ' #ifdef USE_MORPHNORMALS',
  9784. ' attribute vec3 morphNormal0;',
  9785. ' attribute vec3 morphNormal1;',
  9786. ' attribute vec3 morphNormal2;',
  9787. ' attribute vec3 morphNormal3;',
  9788. ' #else',
  9789. ' attribute vec3 morphTarget4;',
  9790. ' attribute vec3 morphTarget5;',
  9791. ' attribute vec3 morphTarget6;',
  9792. ' attribute vec3 morphTarget7;',
  9793. ' #endif',
  9794. '#endif',
  9795. '#ifdef USE_SKINNING',
  9796. ' attribute vec4 skinIndex;',
  9797. ' attribute vec4 skinWeight;',
  9798. '#endif',
  9799. '\n'
  9800. ].filter( filterEmptyLine ).join( '\n' );
  9801. prefixFragment = [
  9802. customExtensions,
  9803. 'precision ' + parameters.precision + ' float;',
  9804. 'precision ' + parameters.precision + ' int;',
  9805. '#define SHADER_NAME ' + shader.name,
  9806. customDefines,
  9807. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  9808. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  9809. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  9810. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  9811. parameters.map ? '#define USE_MAP' : '',
  9812. parameters.envMap ? '#define USE_ENVMAP' : '',
  9813. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  9814. parameters.envMap ? '#define ' + envMapModeDefine : '',
  9815. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  9816. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  9817. parameters.aoMap ? '#define USE_AOMAP' : '',
  9818. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  9819. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  9820. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  9821. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  9822. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  9823. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  9824. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  9825. parameters.vertexColors ? '#define USE_COLOR' : '',
  9826. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  9827. parameters.flatShading ? '#define FLAT_SHADED' : '',
  9828. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  9829. parameters.flipSided ? '#define FLIP_SIDED' : '',
  9830. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  9831. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  9832. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  9833. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  9834. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  9835. parameters.logarithmicDepthBuffer && extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  9836. parameters.envMap && extensions.get( 'EXT_shader_texture_lod' ) ? '#define TEXTURE_LOD_EXT' : '',
  9837. 'uniform mat4 viewMatrix;',
  9838. 'uniform vec3 cameraPosition;',
  9839. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  9840. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  9841. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  9842. parameters.dithering ? '#define DITHERING' : '',
  9843. ( parameters.outputEncoding || parameters.mapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding ) ? ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
  9844. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  9845. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  9846. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  9847. parameters.outputEncoding ? getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ) : '',
  9848. parameters.depthPacking ? '#define DEPTH_PACKING ' + material.depthPacking : '',
  9849. '\n'
  9850. ].filter( filterEmptyLine ).join( '\n' );
  9851. }
  9852. vertexShader = parseIncludes( vertexShader );
  9853. vertexShader = replaceLightNums( vertexShader, parameters );
  9854. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  9855. fragmentShader = parseIncludes( fragmentShader );
  9856. fragmentShader = replaceLightNums( fragmentShader, parameters );
  9857. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  9858. vertexShader = unrollLoops( vertexShader );
  9859. fragmentShader = unrollLoops( fragmentShader );
  9860. var vertexGlsl = prefixVertex + vertexShader;
  9861. var fragmentGlsl = prefixFragment + fragmentShader;
  9862. // console.log( '*VERTEX*', vertexGlsl );
  9863. // console.log( '*FRAGMENT*', fragmentGlsl );
  9864. var glVertexShader = WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  9865. var glFragmentShader = WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  9866. gl.attachShader( program, glVertexShader );
  9867. gl.attachShader( program, glFragmentShader );
  9868. // Force a particular attribute to index 0.
  9869. if ( material.index0AttributeName !== undefined ) {
  9870. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  9871. } else if ( parameters.morphTargets === true ) {
  9872. // programs with morphTargets displace position out of attribute 0
  9873. gl.bindAttribLocation( program, 0, 'position' );
  9874. }
  9875. gl.linkProgram( program );
  9876. var programLog = gl.getProgramInfoLog( program ).trim();
  9877. var vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  9878. var fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  9879. var runnable = true;
  9880. var haveDiagnostics = true;
  9881. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  9882. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  9883. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  9884. runnable = false;
  9885. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  9886. } else if ( programLog !== '' ) {
  9887. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  9888. } else if ( vertexLog === '' || fragmentLog === '' ) {
  9889. haveDiagnostics = false;
  9890. }
  9891. if ( haveDiagnostics ) {
  9892. this.diagnostics = {
  9893. runnable: runnable,
  9894. material: material,
  9895. programLog: programLog,
  9896. vertexShader: {
  9897. log: vertexLog,
  9898. prefix: prefixVertex
  9899. },
  9900. fragmentShader: {
  9901. log: fragmentLog,
  9902. prefix: prefixFragment
  9903. }
  9904. };
  9905. }
  9906. // clean up
  9907. gl.deleteShader( glVertexShader );
  9908. gl.deleteShader( glFragmentShader );
  9909. // set up caching for uniform locations
  9910. var cachedUniforms;
  9911. this.getUniforms = function () {
  9912. if ( cachedUniforms === undefined ) {
  9913. cachedUniforms = new WebGLUniforms( gl, program, renderer );
  9914. }
  9915. return cachedUniforms;
  9916. };
  9917. // set up caching for attribute locations
  9918. var cachedAttributes;
  9919. this.getAttributes = function () {
  9920. if ( cachedAttributes === undefined ) {
  9921. cachedAttributes = fetchAttributeLocations( gl, program );
  9922. }
  9923. return cachedAttributes;
  9924. };
  9925. // free resource
  9926. this.destroy = function () {
  9927. gl.deleteProgram( program );
  9928. this.program = undefined;
  9929. };
  9930. // DEPRECATED
  9931. Object.defineProperties( this, {
  9932. uniforms: {
  9933. get: function () {
  9934. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  9935. return this.getUniforms();
  9936. }
  9937. },
  9938. attributes: {
  9939. get: function () {
  9940. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  9941. return this.getAttributes();
  9942. }
  9943. }
  9944. } );
  9945. //
  9946. this.name = shader.name;
  9947. this.id = programIdCount ++;
  9948. this.code = code;
  9949. this.usedTimes = 1;
  9950. this.program = program;
  9951. this.vertexShader = glVertexShader;
  9952. this.fragmentShader = glFragmentShader;
  9953. return this;
  9954. }
  9955. /**
  9956. * @author mrdoob / http://mrdoob.com/
  9957. */
  9958. function WebGLPrograms( renderer, extensions, capabilities ) {
  9959. var programs = [];
  9960. var shaderIDs = {
  9961. MeshDepthMaterial: 'depth',
  9962. MeshDistanceMaterial: 'distanceRGBA',
  9963. MeshNormalMaterial: 'normal',
  9964. MeshBasicMaterial: 'basic',
  9965. MeshLambertMaterial: 'lambert',
  9966. MeshPhongMaterial: 'phong',
  9967. MeshToonMaterial: 'phong',
  9968. MeshStandardMaterial: 'physical',
  9969. MeshPhysicalMaterial: 'physical',
  9970. LineBasicMaterial: 'basic',
  9971. LineDashedMaterial: 'dashed',
  9972. PointsMaterial: 'points',
  9973. ShadowMaterial: 'shadow'
  9974. };
  9975. var parameterNames = [
  9976. "precision", "supportsVertexTextures", "map", "mapEncoding", "envMap", "envMapMode", "envMapEncoding",
  9977. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "displacementMap", "specularMap",
  9978. "roughnessMap", "metalnessMap", "gradientMap",
  9979. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  9980. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  9981. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  9982. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  9983. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  9984. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  9985. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering"
  9986. ];
  9987. function allocateBones( object ) {
  9988. var skeleton = object.skeleton;
  9989. var bones = skeleton.bones;
  9990. if ( capabilities.floatVertexTextures ) {
  9991. return 1024;
  9992. } else {
  9993. // default for when object is not specified
  9994. // ( for example when prebuilding shader to be used with multiple objects )
  9995. //
  9996. // - leave some extra space for other uniforms
  9997. // - limit here is ANGLE's 254 max uniform vectors
  9998. // (up to 54 should be safe)
  9999. var nVertexUniforms = capabilities.maxVertexUniforms;
  10000. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  10001. var maxBones = Math.min( nVertexMatrices, bones.length );
  10002. if ( maxBones < bones.length ) {
  10003. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  10004. return 0;
  10005. }
  10006. return maxBones;
  10007. }
  10008. }
  10009. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  10010. var encoding;
  10011. if ( ! map ) {
  10012. encoding = LinearEncoding;
  10013. } else if ( map.isTexture ) {
  10014. encoding = map.encoding;
  10015. } else if ( map.isWebGLRenderTarget ) {
  10016. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  10017. encoding = map.texture.encoding;
  10018. }
  10019. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  10020. if ( encoding === LinearEncoding && gammaOverrideLinear ) {
  10021. encoding = GammaEncoding;
  10022. }
  10023. return encoding;
  10024. }
  10025. this.getParameters = function ( material, lights, shadows, fog, nClipPlanes, nClipIntersection, object ) {
  10026. var shaderID = shaderIDs[ material.type ];
  10027. // heuristics to create shader parameters according to lights in the scene
  10028. // (not to blow over maxLights budget)
  10029. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  10030. var precision = capabilities.precision;
  10031. if ( material.precision !== null ) {
  10032. precision = capabilities.getMaxPrecision( material.precision );
  10033. if ( precision !== material.precision ) {
  10034. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  10035. }
  10036. }
  10037. var currentRenderTarget = renderer.getRenderTarget();
  10038. var parameters = {
  10039. shaderID: shaderID,
  10040. precision: precision,
  10041. supportsVertexTextures: capabilities.vertexTextures,
  10042. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  10043. map: !! material.map,
  10044. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  10045. envMap: !! material.envMap,
  10046. envMapMode: material.envMap && material.envMap.mapping,
  10047. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  10048. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
  10049. lightMap: !! material.lightMap,
  10050. aoMap: !! material.aoMap,
  10051. emissiveMap: !! material.emissiveMap,
  10052. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  10053. bumpMap: !! material.bumpMap,
  10054. normalMap: !! material.normalMap,
  10055. displacementMap: !! material.displacementMap,
  10056. roughnessMap: !! material.roughnessMap,
  10057. metalnessMap: !! material.metalnessMap,
  10058. specularMap: !! material.specularMap,
  10059. alphaMap: !! material.alphaMap,
  10060. gradientMap: !! material.gradientMap,
  10061. combine: material.combine,
  10062. vertexColors: material.vertexColors,
  10063. fog: !! fog,
  10064. useFog: material.fog,
  10065. fogExp: ( fog && fog.isFogExp2 ),
  10066. flatShading: material.flatShading,
  10067. sizeAttenuation: material.sizeAttenuation,
  10068. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  10069. skinning: material.skinning && maxBones > 0,
  10070. maxBones: maxBones,
  10071. useVertexTexture: capabilities.floatVertexTextures,
  10072. morphTargets: material.morphTargets,
  10073. morphNormals: material.morphNormals,
  10074. maxMorphTargets: renderer.maxMorphTargets,
  10075. maxMorphNormals: renderer.maxMorphNormals,
  10076. numDirLights: lights.directional.length,
  10077. numPointLights: lights.point.length,
  10078. numSpotLights: lights.spot.length,
  10079. numRectAreaLights: lights.rectArea.length,
  10080. numHemiLights: lights.hemi.length,
  10081. numClippingPlanes: nClipPlanes,
  10082. numClipIntersection: nClipIntersection,
  10083. dithering: material.dithering,
  10084. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && shadows.length > 0,
  10085. shadowMapType: renderer.shadowMap.type,
  10086. toneMapping: renderer.toneMapping,
  10087. physicallyCorrectLights: renderer.physicallyCorrectLights,
  10088. premultipliedAlpha: material.premultipliedAlpha,
  10089. alphaTest: material.alphaTest,
  10090. doubleSided: material.side === DoubleSide,
  10091. flipSided: material.side === BackSide,
  10092. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  10093. };
  10094. return parameters;
  10095. };
  10096. this.getProgramCode = function ( material, parameters ) {
  10097. var array = [];
  10098. if ( parameters.shaderID ) {
  10099. array.push( parameters.shaderID );
  10100. } else {
  10101. array.push( material.fragmentShader );
  10102. array.push( material.vertexShader );
  10103. }
  10104. if ( material.defines !== undefined ) {
  10105. for ( var name in material.defines ) {
  10106. array.push( name );
  10107. array.push( material.defines[ name ] );
  10108. }
  10109. }
  10110. for ( var i = 0; i < parameterNames.length; i ++ ) {
  10111. array.push( parameters[ parameterNames[ i ] ] );
  10112. }
  10113. array.push( material.onBeforeCompile.toString() );
  10114. array.push( renderer.gammaOutput );
  10115. return array.join();
  10116. };
  10117. this.acquireProgram = function ( material, shader, parameters, code ) {
  10118. var program;
  10119. // Check if code has been already compiled
  10120. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  10121. var programInfo = programs[ p ];
  10122. if ( programInfo.code === code ) {
  10123. program = programInfo;
  10124. ++ program.usedTimes;
  10125. break;
  10126. }
  10127. }
  10128. if ( program === undefined ) {
  10129. program = new WebGLProgram( renderer, extensions, code, material, shader, parameters );
  10130. programs.push( program );
  10131. }
  10132. return program;
  10133. };
  10134. this.releaseProgram = function ( program ) {
  10135. if ( -- program.usedTimes === 0 ) {
  10136. // Remove from unordered set
  10137. var i = programs.indexOf( program );
  10138. programs[ i ] = programs[ programs.length - 1 ];
  10139. programs.pop();
  10140. // Free WebGL resources
  10141. program.destroy();
  10142. }
  10143. };
  10144. // Exposed for resource monitoring & error feedback via renderer.info:
  10145. this.programs = programs;
  10146. }
  10147. /**
  10148. * @author fordacious / fordacious.github.io
  10149. */
  10150. function WebGLProperties() {
  10151. var properties = new WeakMap();
  10152. function get( object ) {
  10153. var map = properties.get( object );
  10154. if ( map === undefined ) {
  10155. map = {};
  10156. properties.set( object, map );
  10157. }
  10158. return map;
  10159. }
  10160. function remove( object ) {
  10161. properties.delete( object );
  10162. }
  10163. function update( object, key, value ) {
  10164. properties.get( object )[ key ] = value;
  10165. }
  10166. function dispose() {
  10167. properties = new WeakMap();
  10168. }
  10169. return {
  10170. get: get,
  10171. remove: remove,
  10172. update: update,
  10173. dispose: dispose
  10174. };
  10175. }
  10176. /**
  10177. * @author mrdoob / http://mrdoob.com/
  10178. */
  10179. function painterSortStable( a, b ) {
  10180. if ( a.renderOrder !== b.renderOrder ) {
  10181. return a.renderOrder - b.renderOrder;
  10182. } else if ( a.program && b.program && a.program !== b.program ) {
  10183. return a.program.id - b.program.id;
  10184. } else if ( a.material.id !== b.material.id ) {
  10185. return a.material.id - b.material.id;
  10186. } else if ( a.z !== b.z ) {
  10187. return a.z - b.z;
  10188. } else {
  10189. return a.id - b.id;
  10190. }
  10191. }
  10192. function reversePainterSortStable( a, b ) {
  10193. if ( a.renderOrder !== b.renderOrder ) {
  10194. return a.renderOrder - b.renderOrder;
  10195. } if ( a.z !== b.z ) {
  10196. return b.z - a.z;
  10197. } else {
  10198. return a.id - b.id;
  10199. }
  10200. }
  10201. function WebGLRenderList() {
  10202. var renderItems = [];
  10203. var renderItemsIndex = 0;
  10204. var opaque = [];
  10205. var transparent = [];
  10206. function init() {
  10207. renderItemsIndex = 0;
  10208. opaque.length = 0;
  10209. transparent.length = 0;
  10210. }
  10211. function push( object, geometry, material, z, group ) {
  10212. var renderItem = renderItems[ renderItemsIndex ];
  10213. if ( renderItem === undefined ) {
  10214. renderItem = {
  10215. id: object.id,
  10216. object: object,
  10217. geometry: geometry,
  10218. material: material,
  10219. program: material.program,
  10220. renderOrder: object.renderOrder,
  10221. z: z,
  10222. group: group
  10223. };
  10224. renderItems[ renderItemsIndex ] = renderItem;
  10225. } else {
  10226. renderItem.id = object.id;
  10227. renderItem.object = object;
  10228. renderItem.geometry = geometry;
  10229. renderItem.material = material;
  10230. renderItem.program = material.program;
  10231. renderItem.renderOrder = object.renderOrder;
  10232. renderItem.z = z;
  10233. renderItem.group = group;
  10234. }
  10235. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  10236. renderItemsIndex ++;
  10237. }
  10238. function sort() {
  10239. if ( opaque.length > 1 ) opaque.sort( painterSortStable );
  10240. if ( transparent.length > 1 ) transparent.sort( reversePainterSortStable );
  10241. }
  10242. return {
  10243. opaque: opaque,
  10244. transparent: transparent,
  10245. init: init,
  10246. push: push,
  10247. sort: sort
  10248. };
  10249. }
  10250. function WebGLRenderLists() {
  10251. var lists = {};
  10252. function get( scene, camera ) {
  10253. var hash = scene.id + ',' + camera.id;
  10254. var list = lists[ hash ];
  10255. if ( list === undefined ) {
  10256. // console.log( 'THREE.WebGLRenderLists:', hash );
  10257. list = new WebGLRenderList();
  10258. lists[ hash ] = list;
  10259. }
  10260. return list;
  10261. }
  10262. function dispose() {
  10263. lists = {};
  10264. }
  10265. return {
  10266. get: get,
  10267. dispose: dispose
  10268. };
  10269. }
  10270. /**
  10271. * @author mrdoob / http://mrdoob.com/
  10272. */
  10273. function UniformsCache() {
  10274. var lights = {};
  10275. return {
  10276. get: function ( light ) {
  10277. if ( lights[ light.id ] !== undefined ) {
  10278. return lights[ light.id ];
  10279. }
  10280. var uniforms;
  10281. switch ( light.type ) {
  10282. case 'DirectionalLight':
  10283. uniforms = {
  10284. direction: new Vector3(),
  10285. color: new Color(),
  10286. shadow: false,
  10287. shadowBias: 0,
  10288. shadowRadius: 1,
  10289. shadowMapSize: new Vector2()
  10290. };
  10291. break;
  10292. case 'SpotLight':
  10293. uniforms = {
  10294. position: new Vector3(),
  10295. direction: new Vector3(),
  10296. color: new Color(),
  10297. distance: 0,
  10298. coneCos: 0,
  10299. penumbraCos: 0,
  10300. decay: 0,
  10301. shadow: false,
  10302. shadowBias: 0,
  10303. shadowRadius: 1,
  10304. shadowMapSize: new Vector2()
  10305. };
  10306. break;
  10307. case 'PointLight':
  10308. uniforms = {
  10309. position: new Vector3(),
  10310. color: new Color(),
  10311. distance: 0,
  10312. decay: 0,
  10313. shadow: false,
  10314. shadowBias: 0,
  10315. shadowRadius: 1,
  10316. shadowMapSize: new Vector2(),
  10317. shadowCameraNear: 1,
  10318. shadowCameraFar: 1000
  10319. };
  10320. break;
  10321. case 'HemisphereLight':
  10322. uniforms = {
  10323. direction: new Vector3(),
  10324. skyColor: new Color(),
  10325. groundColor: new Color()
  10326. };
  10327. break;
  10328. case 'RectAreaLight':
  10329. uniforms = {
  10330. color: new Color(),
  10331. position: new Vector3(),
  10332. halfWidth: new Vector3(),
  10333. halfHeight: new Vector3()
  10334. // TODO (abelnation): set RectAreaLight shadow uniforms
  10335. };
  10336. break;
  10337. }
  10338. lights[ light.id ] = uniforms;
  10339. return uniforms;
  10340. }
  10341. };
  10342. }
  10343. var count = 0;
  10344. function WebGLLights() {
  10345. var cache = new UniformsCache();
  10346. var state = {
  10347. id: count ++,
  10348. hash: '',
  10349. ambient: [ 0, 0, 0 ],
  10350. directional: [],
  10351. directionalShadowMap: [],
  10352. directionalShadowMatrix: [],
  10353. spot: [],
  10354. spotShadowMap: [],
  10355. spotShadowMatrix: [],
  10356. rectArea: [],
  10357. point: [],
  10358. pointShadowMap: [],
  10359. pointShadowMatrix: [],
  10360. hemi: []
  10361. };
  10362. var vector3 = new Vector3();
  10363. var matrix4 = new Matrix4();
  10364. var matrix42 = new Matrix4();
  10365. function setup( lights, shadows, camera ) {
  10366. var r = 0, g = 0, b = 0;
  10367. var directionalLength = 0;
  10368. var pointLength = 0;
  10369. var spotLength = 0;
  10370. var rectAreaLength = 0;
  10371. var hemiLength = 0;
  10372. var viewMatrix = camera.matrixWorldInverse;
  10373. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  10374. var light = lights[ i ];
  10375. var color = light.color;
  10376. var intensity = light.intensity;
  10377. var distance = light.distance;
  10378. var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  10379. if ( light.isAmbientLight ) {
  10380. r += color.r * intensity;
  10381. g += color.g * intensity;
  10382. b += color.b * intensity;
  10383. } else if ( light.isDirectionalLight ) {
  10384. var uniforms = cache.get( light );
  10385. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  10386. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10387. vector3.setFromMatrixPosition( light.target.matrixWorld );
  10388. uniforms.direction.sub( vector3 );
  10389. uniforms.direction.transformDirection( viewMatrix );
  10390. uniforms.shadow = light.castShadow;
  10391. if ( light.castShadow ) {
  10392. var shadow = light.shadow;
  10393. uniforms.shadowBias = shadow.bias;
  10394. uniforms.shadowRadius = shadow.radius;
  10395. uniforms.shadowMapSize = shadow.mapSize;
  10396. }
  10397. state.directionalShadowMap[ directionalLength ] = shadowMap;
  10398. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  10399. state.directional[ directionalLength ] = uniforms;
  10400. directionalLength ++;
  10401. } else if ( light.isSpotLight ) {
  10402. var uniforms = cache.get( light );
  10403. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10404. uniforms.position.applyMatrix4( viewMatrix );
  10405. uniforms.color.copy( color ).multiplyScalar( intensity );
  10406. uniforms.distance = distance;
  10407. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10408. vector3.setFromMatrixPosition( light.target.matrixWorld );
  10409. uniforms.direction.sub( vector3 );
  10410. uniforms.direction.transformDirection( viewMatrix );
  10411. uniforms.coneCos = Math.cos( light.angle );
  10412. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  10413. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  10414. uniforms.shadow = light.castShadow;
  10415. if ( light.castShadow ) {
  10416. var shadow = light.shadow;
  10417. uniforms.shadowBias = shadow.bias;
  10418. uniforms.shadowRadius = shadow.radius;
  10419. uniforms.shadowMapSize = shadow.mapSize;
  10420. }
  10421. state.spotShadowMap[ spotLength ] = shadowMap;
  10422. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  10423. state.spot[ spotLength ] = uniforms;
  10424. spotLength ++;
  10425. } else if ( light.isRectAreaLight ) {
  10426. var uniforms = cache.get( light );
  10427. // (a) intensity is the total visible light emitted
  10428. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  10429. // (b) intensity is the brightness of the light
  10430. uniforms.color.copy( color ).multiplyScalar( intensity );
  10431. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10432. uniforms.position.applyMatrix4( viewMatrix );
  10433. // extract local rotation of light to derive width/height half vectors
  10434. matrix42.identity();
  10435. matrix4.copy( light.matrixWorld );
  10436. matrix4.premultiply( viewMatrix );
  10437. matrix42.extractRotation( matrix4 );
  10438. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  10439. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  10440. uniforms.halfWidth.applyMatrix4( matrix42 );
  10441. uniforms.halfHeight.applyMatrix4( matrix42 );
  10442. // TODO (abelnation): RectAreaLight distance?
  10443. // uniforms.distance = distance;
  10444. state.rectArea[ rectAreaLength ] = uniforms;
  10445. rectAreaLength ++;
  10446. } else if ( light.isPointLight ) {
  10447. var uniforms = cache.get( light );
  10448. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10449. uniforms.position.applyMatrix4( viewMatrix );
  10450. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  10451. uniforms.distance = light.distance;
  10452. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  10453. uniforms.shadow = light.castShadow;
  10454. if ( light.castShadow ) {
  10455. var shadow = light.shadow;
  10456. uniforms.shadowBias = shadow.bias;
  10457. uniforms.shadowRadius = shadow.radius;
  10458. uniforms.shadowMapSize = shadow.mapSize;
  10459. uniforms.shadowCameraNear = shadow.camera.near;
  10460. uniforms.shadowCameraFar = shadow.camera.far;
  10461. }
  10462. state.pointShadowMap[ pointLength ] = shadowMap;
  10463. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  10464. state.point[ pointLength ] = uniforms;
  10465. pointLength ++;
  10466. } else if ( light.isHemisphereLight ) {
  10467. var uniforms = cache.get( light );
  10468. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10469. uniforms.direction.transformDirection( viewMatrix );
  10470. uniforms.direction.normalize();
  10471. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  10472. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  10473. state.hemi[ hemiLength ] = uniforms;
  10474. hemiLength ++;
  10475. }
  10476. }
  10477. state.ambient[ 0 ] = r;
  10478. state.ambient[ 1 ] = g;
  10479. state.ambient[ 2 ] = b;
  10480. state.directional.length = directionalLength;
  10481. state.spot.length = spotLength;
  10482. state.rectArea.length = rectAreaLength;
  10483. state.point.length = pointLength;
  10484. state.hemi.length = hemiLength;
  10485. state.hash = state.id + ',' + directionalLength + ',' + pointLength + ',' + spotLength + ',' + rectAreaLength + ',' + hemiLength + ',' + shadows.length;
  10486. }
  10487. return {
  10488. setup: setup,
  10489. state: state
  10490. };
  10491. }
  10492. /**
  10493. * @author Mugen87 / https://github.com/Mugen87
  10494. */
  10495. function WebGLRenderState() {
  10496. var lights = new WebGLLights();
  10497. var lightsArray = [];
  10498. var shadowsArray = [];
  10499. var spritesArray = [];
  10500. function init() {
  10501. lightsArray.length = 0;
  10502. shadowsArray.length = 0;
  10503. spritesArray.length = 0;
  10504. }
  10505. function pushLight( light ) {
  10506. lightsArray.push( light );
  10507. }
  10508. function pushShadow( shadowLight ) {
  10509. shadowsArray.push( shadowLight );
  10510. }
  10511. function pushSprite( shadowLight ) {
  10512. spritesArray.push( shadowLight );
  10513. }
  10514. function setupLights( camera ) {
  10515. lights.setup( lightsArray, shadowsArray, camera );
  10516. }
  10517. var state = {
  10518. lightsArray: lightsArray,
  10519. shadowsArray: shadowsArray,
  10520. spritesArray: spritesArray,
  10521. lights: lights
  10522. };
  10523. return {
  10524. init: init,
  10525. state: state,
  10526. setupLights: setupLights,
  10527. pushLight: pushLight,
  10528. pushShadow: pushShadow,
  10529. pushSprite: pushSprite
  10530. };
  10531. }
  10532. function WebGLRenderStates() {
  10533. var renderStates = {};
  10534. function get( scene, camera ) {
  10535. var hash = scene.id + ',' + camera.id;
  10536. var renderState = renderStates[ hash ];
  10537. if ( renderState === undefined ) {
  10538. renderState = new WebGLRenderState();
  10539. renderStates[ hash ] = renderState;
  10540. }
  10541. return renderState;
  10542. }
  10543. function dispose() {
  10544. renderStates = {};
  10545. }
  10546. return {
  10547. get: get,
  10548. dispose: dispose
  10549. };
  10550. }
  10551. /**
  10552. * @author mrdoob / http://mrdoob.com/
  10553. * @author alteredq / http://alteredqualia.com/
  10554. * @author bhouston / https://clara.io
  10555. * @author WestLangley / http://github.com/WestLangley
  10556. *
  10557. * parameters = {
  10558. *
  10559. * opacity: <float>,
  10560. *
  10561. * map: new THREE.Texture( <Image> ),
  10562. *
  10563. * alphaMap: new THREE.Texture( <Image> ),
  10564. *
  10565. * displacementMap: new THREE.Texture( <Image> ),
  10566. * displacementScale: <float>,
  10567. * displacementBias: <float>,
  10568. *
  10569. * wireframe: <boolean>,
  10570. * wireframeLinewidth: <float>
  10571. * }
  10572. */
  10573. function MeshDepthMaterial( parameters ) {
  10574. Material.call( this );
  10575. this.type = 'MeshDepthMaterial';
  10576. this.depthPacking = BasicDepthPacking;
  10577. this.skinning = false;
  10578. this.morphTargets = false;
  10579. this.map = null;
  10580. this.alphaMap = null;
  10581. this.displacementMap = null;
  10582. this.displacementScale = 1;
  10583. this.displacementBias = 0;
  10584. this.wireframe = false;
  10585. this.wireframeLinewidth = 1;
  10586. this.fog = false;
  10587. this.lights = false;
  10588. this.setValues( parameters );
  10589. }
  10590. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  10591. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  10592. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  10593. MeshDepthMaterial.prototype.copy = function ( source ) {
  10594. Material.prototype.copy.call( this, source );
  10595. this.depthPacking = source.depthPacking;
  10596. this.skinning = source.skinning;
  10597. this.morphTargets = source.morphTargets;
  10598. this.map = source.map;
  10599. this.alphaMap = source.alphaMap;
  10600. this.displacementMap = source.displacementMap;
  10601. this.displacementScale = source.displacementScale;
  10602. this.displacementBias = source.displacementBias;
  10603. this.wireframe = source.wireframe;
  10604. this.wireframeLinewidth = source.wireframeLinewidth;
  10605. return this;
  10606. };
  10607. /**
  10608. * @author WestLangley / http://github.com/WestLangley
  10609. *
  10610. * parameters = {
  10611. *
  10612. * referencePosition: <float>,
  10613. * nearDistance: <float>,
  10614. * farDistance: <float>,
  10615. *
  10616. * skinning: <bool>,
  10617. * morphTargets: <bool>,
  10618. *
  10619. * map: new THREE.Texture( <Image> ),
  10620. *
  10621. * alphaMap: new THREE.Texture( <Image> ),
  10622. *
  10623. * displacementMap: new THREE.Texture( <Image> ),
  10624. * displacementScale: <float>,
  10625. * displacementBias: <float>
  10626. *
  10627. * }
  10628. */
  10629. function MeshDistanceMaterial( parameters ) {
  10630. Material.call( this );
  10631. this.type = 'MeshDistanceMaterial';
  10632. this.referencePosition = new Vector3();
  10633. this.nearDistance = 1;
  10634. this.farDistance = 1000;
  10635. this.skinning = false;
  10636. this.morphTargets = false;
  10637. this.map = null;
  10638. this.alphaMap = null;
  10639. this.displacementMap = null;
  10640. this.displacementScale = 1;
  10641. this.displacementBias = 0;
  10642. this.fog = false;
  10643. this.lights = false;
  10644. this.setValues( parameters );
  10645. }
  10646. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  10647. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  10648. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  10649. MeshDistanceMaterial.prototype.copy = function ( source ) {
  10650. Material.prototype.copy.call( this, source );
  10651. this.referencePosition.copy( source.referencePosition );
  10652. this.nearDistance = source.nearDistance;
  10653. this.farDistance = source.farDistance;
  10654. this.skinning = source.skinning;
  10655. this.morphTargets = source.morphTargets;
  10656. this.map = source.map;
  10657. this.alphaMap = source.alphaMap;
  10658. this.displacementMap = source.displacementMap;
  10659. this.displacementScale = source.displacementScale;
  10660. this.displacementBias = source.displacementBias;
  10661. return this;
  10662. };
  10663. /**
  10664. * @author alteredq / http://alteredqualia.com/
  10665. * @author mrdoob / http://mrdoob.com/
  10666. */
  10667. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  10668. var _frustum = new Frustum(),
  10669. _projScreenMatrix = new Matrix4(),
  10670. _shadowMapSize = new Vector2(),
  10671. _maxShadowMapSize = new Vector2( maxTextureSize, maxTextureSize ),
  10672. _lookTarget = new Vector3(),
  10673. _lightPositionWorld = new Vector3(),
  10674. _MorphingFlag = 1,
  10675. _SkinningFlag = 2,
  10676. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  10677. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  10678. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  10679. _materialCache = {};
  10680. var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  10681. var cubeDirections = [
  10682. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  10683. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  10684. ];
  10685. var cubeUps = [
  10686. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  10687. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  10688. ];
  10689. var cube2DViewPorts = [
  10690. new Vector4(), new Vector4(), new Vector4(),
  10691. new Vector4(), new Vector4(), new Vector4()
  10692. ];
  10693. // init
  10694. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  10695. var useMorphing = ( i & _MorphingFlag ) !== 0;
  10696. var useSkinning = ( i & _SkinningFlag ) !== 0;
  10697. var depthMaterial = new MeshDepthMaterial( {
  10698. depthPacking: RGBADepthPacking,
  10699. morphTargets: useMorphing,
  10700. skinning: useSkinning
  10701. } );
  10702. _depthMaterials[ i ] = depthMaterial;
  10703. //
  10704. var distanceMaterial = new MeshDistanceMaterial( {
  10705. morphTargets: useMorphing,
  10706. skinning: useSkinning
  10707. } );
  10708. _distanceMaterials[ i ] = distanceMaterial;
  10709. }
  10710. //
  10711. var scope = this;
  10712. this.enabled = false;
  10713. this.autoUpdate = true;
  10714. this.needsUpdate = false;
  10715. this.type = PCFShadowMap;
  10716. this.render = function ( lights, scene, camera ) {
  10717. if ( scope.enabled === false ) return;
  10718. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  10719. if ( lights.length === 0 ) return;
  10720. // TODO Clean up (needed in case of contextlost)
  10721. var _gl = _renderer.context;
  10722. var _state = _renderer.state;
  10723. // Set GL state for depth map.
  10724. _state.disable( _gl.BLEND );
  10725. _state.buffers.color.setClear( 1, 1, 1, 1 );
  10726. _state.buffers.depth.setTest( true );
  10727. _state.setScissorTest( false );
  10728. // render depth map
  10729. var faceCount;
  10730. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  10731. var light = lights[ i ];
  10732. var shadow = light.shadow;
  10733. var isPointLight = light && light.isPointLight;
  10734. if ( shadow === undefined ) {
  10735. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  10736. continue;
  10737. }
  10738. var shadowCamera = shadow.camera;
  10739. _shadowMapSize.copy( shadow.mapSize );
  10740. _shadowMapSize.min( _maxShadowMapSize );
  10741. if ( isPointLight ) {
  10742. var vpWidth = _shadowMapSize.x;
  10743. var vpHeight = _shadowMapSize.y;
  10744. // These viewports map a cube-map onto a 2D texture with the
  10745. // following orientation:
  10746. //
  10747. // xzXZ
  10748. // y Y
  10749. //
  10750. // X - Positive x direction
  10751. // x - Negative x direction
  10752. // Y - Positive y direction
  10753. // y - Negative y direction
  10754. // Z - Positive z direction
  10755. // z - Negative z direction
  10756. // positive X
  10757. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  10758. // negative X
  10759. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  10760. // positive Z
  10761. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  10762. // negative Z
  10763. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  10764. // positive Y
  10765. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  10766. // negative Y
  10767. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  10768. _shadowMapSize.x *= 4.0;
  10769. _shadowMapSize.y *= 2.0;
  10770. }
  10771. if ( shadow.map === null ) {
  10772. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  10773. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  10774. shadow.map.texture.name = light.name + ".shadowMap";
  10775. shadowCamera.updateProjectionMatrix();
  10776. }
  10777. if ( shadow.isSpotLightShadow ) {
  10778. shadow.update( light );
  10779. }
  10780. var shadowMap = shadow.map;
  10781. var shadowMatrix = shadow.matrix;
  10782. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  10783. shadowCamera.position.copy( _lightPositionWorld );
  10784. if ( isPointLight ) {
  10785. faceCount = 6;
  10786. // for point lights we set the shadow matrix to be a translation-only matrix
  10787. // equal to inverse of the light's position
  10788. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  10789. } else {
  10790. faceCount = 1;
  10791. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  10792. shadowCamera.lookAt( _lookTarget );
  10793. shadowCamera.updateMatrixWorld();
  10794. // compute shadow matrix
  10795. shadowMatrix.set(
  10796. 0.5, 0.0, 0.0, 0.5,
  10797. 0.0, 0.5, 0.0, 0.5,
  10798. 0.0, 0.0, 0.5, 0.5,
  10799. 0.0, 0.0, 0.0, 1.0
  10800. );
  10801. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  10802. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  10803. }
  10804. _renderer.setRenderTarget( shadowMap );
  10805. _renderer.clear();
  10806. // render shadow map for each cube face (if omni-directional) or
  10807. // run a single pass if not
  10808. for ( var face = 0; face < faceCount; face ++ ) {
  10809. if ( isPointLight ) {
  10810. _lookTarget.copy( shadowCamera.position );
  10811. _lookTarget.add( cubeDirections[ face ] );
  10812. shadowCamera.up.copy( cubeUps[ face ] );
  10813. shadowCamera.lookAt( _lookTarget );
  10814. shadowCamera.updateMatrixWorld();
  10815. var vpDimensions = cube2DViewPorts[ face ];
  10816. _state.viewport( vpDimensions );
  10817. }
  10818. // update camera matrices and frustum
  10819. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  10820. _frustum.setFromMatrix( _projScreenMatrix );
  10821. // set object matrices & frustum culling
  10822. renderObject( scene, camera, shadowCamera, isPointLight );
  10823. }
  10824. }
  10825. scope.needsUpdate = false;
  10826. };
  10827. function getDepthMaterial( object, material, isPointLight, lightPositionWorld, shadowCameraNear, shadowCameraFar ) {
  10828. var geometry = object.geometry;
  10829. var result = null;
  10830. var materialVariants = _depthMaterials;
  10831. var customMaterial = object.customDepthMaterial;
  10832. if ( isPointLight ) {
  10833. materialVariants = _distanceMaterials;
  10834. customMaterial = object.customDistanceMaterial;
  10835. }
  10836. if ( ! customMaterial ) {
  10837. var useMorphing = false;
  10838. if ( material.morphTargets ) {
  10839. if ( geometry && geometry.isBufferGeometry ) {
  10840. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  10841. } else if ( geometry && geometry.isGeometry ) {
  10842. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  10843. }
  10844. }
  10845. if ( object.isSkinnedMesh && material.skinning === false ) {
  10846. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  10847. }
  10848. var useSkinning = object.isSkinnedMesh && material.skinning;
  10849. var variantIndex = 0;
  10850. if ( useMorphing ) variantIndex |= _MorphingFlag;
  10851. if ( useSkinning ) variantIndex |= _SkinningFlag;
  10852. result = materialVariants[ variantIndex ];
  10853. } else {
  10854. result = customMaterial;
  10855. }
  10856. if ( _renderer.localClippingEnabled &&
  10857. material.clipShadows === true &&
  10858. material.clippingPlanes.length !== 0 ) {
  10859. // in this case we need a unique material instance reflecting the
  10860. // appropriate state
  10861. var keyA = result.uuid, keyB = material.uuid;
  10862. var materialsForVariant = _materialCache[ keyA ];
  10863. if ( materialsForVariant === undefined ) {
  10864. materialsForVariant = {};
  10865. _materialCache[ keyA ] = materialsForVariant;
  10866. }
  10867. var cachedMaterial = materialsForVariant[ keyB ];
  10868. if ( cachedMaterial === undefined ) {
  10869. cachedMaterial = result.clone();
  10870. materialsForVariant[ keyB ] = cachedMaterial;
  10871. }
  10872. result = cachedMaterial;
  10873. }
  10874. result.visible = material.visible;
  10875. result.wireframe = material.wireframe;
  10876. result.side = ( material.shadowSide != null ) ? material.shadowSide : shadowSide[ material.side ];
  10877. result.clipShadows = material.clipShadows;
  10878. result.clippingPlanes = material.clippingPlanes;
  10879. result.clipIntersection = material.clipIntersection;
  10880. result.wireframeLinewidth = material.wireframeLinewidth;
  10881. result.linewidth = material.linewidth;
  10882. if ( isPointLight && result.isMeshDistanceMaterial ) {
  10883. result.referencePosition.copy( lightPositionWorld );
  10884. result.nearDistance = shadowCameraNear;
  10885. result.farDistance = shadowCameraFar;
  10886. }
  10887. return result;
  10888. }
  10889. function renderObject( object, camera, shadowCamera, isPointLight ) {
  10890. if ( object.visible === false ) return;
  10891. var visible = object.layers.test( camera.layers );
  10892. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  10893. if ( object.castShadow && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  10894. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  10895. var geometry = _objects.update( object );
  10896. var material = object.material;
  10897. if ( Array.isArray( material ) ) {
  10898. var groups = geometry.groups;
  10899. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  10900. var group = groups[ k ];
  10901. var groupMaterial = material[ group.materialIndex ];
  10902. if ( groupMaterial && groupMaterial.visible ) {
  10903. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  10904. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  10905. }
  10906. }
  10907. } else if ( material.visible ) {
  10908. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  10909. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  10910. }
  10911. }
  10912. }
  10913. var children = object.children;
  10914. for ( var i = 0, l = children.length; i < l; i ++ ) {
  10915. renderObject( children[ i ], camera, shadowCamera, isPointLight );
  10916. }
  10917. }
  10918. }
  10919. /**
  10920. * @author mrdoob / http://mrdoob.com/
  10921. */
  10922. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10923. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10924. this.needsUpdate = true;
  10925. }
  10926. CanvasTexture.prototype = Object.create( Texture.prototype );
  10927. CanvasTexture.prototype.constructor = CanvasTexture;
  10928. /**
  10929. * @author mikael emtinger / http://gomo.se/
  10930. * @author alteredq / http://alteredqualia.com/
  10931. */
  10932. function WebGLSpriteRenderer( renderer, gl, state, textures, capabilities ) {
  10933. var vertexBuffer, elementBuffer;
  10934. var program, attributes, uniforms;
  10935. var texture;
  10936. // decompose matrixWorld
  10937. var spritePosition = new Vector3();
  10938. var spriteRotation = new Quaternion();
  10939. var spriteScale = new Vector3();
  10940. function init() {
  10941. var vertices = new Float32Array( [
  10942. - 0.5, - 0.5, 0, 0,
  10943. 0.5, - 0.5, 1, 0,
  10944. 0.5, 0.5, 1, 1,
  10945. - 0.5, 0.5, 0, 1
  10946. ] );
  10947. var faces = new Uint16Array( [
  10948. 0, 1, 2,
  10949. 0, 2, 3
  10950. ] );
  10951. vertexBuffer = gl.createBuffer();
  10952. elementBuffer = gl.createBuffer();
  10953. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  10954. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  10955. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  10956. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  10957. program = createProgram();
  10958. attributes = {
  10959. position: gl.getAttribLocation( program, 'position' ),
  10960. uv: gl.getAttribLocation( program, 'uv' )
  10961. };
  10962. uniforms = {
  10963. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  10964. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  10965. rotation: gl.getUniformLocation( program, 'rotation' ),
  10966. center: gl.getUniformLocation( program, 'center' ),
  10967. scale: gl.getUniformLocation( program, 'scale' ),
  10968. color: gl.getUniformLocation( program, 'color' ),
  10969. map: gl.getUniformLocation( program, 'map' ),
  10970. opacity: gl.getUniformLocation( program, 'opacity' ),
  10971. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  10972. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  10973. fogType: gl.getUniformLocation( program, 'fogType' ),
  10974. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  10975. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  10976. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  10977. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  10978. fogDepth: gl.getUniformLocation( program, 'fogDepth' ),
  10979. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  10980. };
  10981. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  10982. canvas.width = 8;
  10983. canvas.height = 8;
  10984. var context = canvas.getContext( '2d' );
  10985. context.fillStyle = 'white';
  10986. context.fillRect( 0, 0, 8, 8 );
  10987. texture = new CanvasTexture( canvas );
  10988. }
  10989. this.render = function ( sprites, scene, camera ) {
  10990. if ( sprites.length === 0 ) return;
  10991. // setup gl
  10992. if ( program === undefined ) {
  10993. init();
  10994. }
  10995. state.useProgram( program );
  10996. state.initAttributes();
  10997. state.enableAttribute( attributes.position );
  10998. state.enableAttribute( attributes.uv );
  10999. state.disableUnusedAttributes();
  11000. state.disable( gl.CULL_FACE );
  11001. state.enable( gl.BLEND );
  11002. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  11003. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  11004. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  11005. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  11006. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  11007. state.activeTexture( gl.TEXTURE0 );
  11008. gl.uniform1i( uniforms.map, 0 );
  11009. var oldFogType = 0;
  11010. var sceneFogType = 0;
  11011. var fog = scene.fog;
  11012. if ( fog ) {
  11013. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  11014. if ( fog.isFog ) {
  11015. gl.uniform1f( uniforms.fogNear, fog.near );
  11016. gl.uniform1f( uniforms.fogFar, fog.far );
  11017. gl.uniform1i( uniforms.fogType, 1 );
  11018. oldFogType = 1;
  11019. sceneFogType = 1;
  11020. } else if ( fog.isFogExp2 ) {
  11021. gl.uniform1f( uniforms.fogDensity, fog.density );
  11022. gl.uniform1i( uniforms.fogType, 2 );
  11023. oldFogType = 2;
  11024. sceneFogType = 2;
  11025. }
  11026. } else {
  11027. gl.uniform1i( uniforms.fogType, 0 );
  11028. oldFogType = 0;
  11029. sceneFogType = 0;
  11030. }
  11031. // update positions and sort
  11032. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  11033. var sprite = sprites[ i ];
  11034. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  11035. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  11036. }
  11037. sprites.sort( painterSortStable );
  11038. // render all sprites
  11039. var scale = [];
  11040. var center = [];
  11041. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  11042. var sprite = sprites[ i ];
  11043. var material = sprite.material;
  11044. if ( material.visible === false ) continue;
  11045. sprite.onBeforeRender( renderer, scene, camera, undefined, material, undefined );
  11046. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  11047. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  11048. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  11049. scale[ 0 ] = spriteScale.x;
  11050. scale[ 1 ] = spriteScale.y;
  11051. center[ 0 ] = sprite.center.x - 0.5;
  11052. center[ 1 ] = sprite.center.y - 0.5;
  11053. var fogType = 0;
  11054. if ( scene.fog && material.fog ) {
  11055. fogType = sceneFogType;
  11056. }
  11057. if ( oldFogType !== fogType ) {
  11058. gl.uniform1i( uniforms.fogType, fogType );
  11059. oldFogType = fogType;
  11060. }
  11061. if ( material.map !== null ) {
  11062. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  11063. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  11064. } else {
  11065. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  11066. gl.uniform2f( uniforms.uvScale, 1, 1 );
  11067. }
  11068. gl.uniform1f( uniforms.opacity, material.opacity );
  11069. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  11070. gl.uniform1f( uniforms.rotation, material.rotation );
  11071. gl.uniform2fv( uniforms.center, center );
  11072. gl.uniform2fv( uniforms.scale, scale );
  11073. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  11074. state.buffers.depth.setTest( material.depthTest );
  11075. state.buffers.depth.setMask( material.depthWrite );
  11076. state.buffers.color.setMask( material.colorWrite );
  11077. textures.setTexture2D( material.map || texture, 0 );
  11078. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  11079. sprite.onAfterRender( renderer, scene, camera, undefined, material, undefined );
  11080. }
  11081. // restore gl
  11082. state.enable( gl.CULL_FACE );
  11083. state.reset();
  11084. };
  11085. function createProgram() {
  11086. var program = gl.createProgram();
  11087. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  11088. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  11089. gl.shaderSource( vertexShader, [
  11090. 'precision ' + capabilities.precision + ' float;',
  11091. '#define SHADER_NAME ' + 'SpriteMaterial',
  11092. 'uniform mat4 modelViewMatrix;',
  11093. 'uniform mat4 projectionMatrix;',
  11094. 'uniform float rotation;',
  11095. 'uniform vec2 center;',
  11096. 'uniform vec2 scale;',
  11097. 'uniform vec2 uvOffset;',
  11098. 'uniform vec2 uvScale;',
  11099. 'attribute vec2 position;',
  11100. 'attribute vec2 uv;',
  11101. 'varying vec2 vUV;',
  11102. 'varying float fogDepth;',
  11103. 'void main() {',
  11104. ' vUV = uvOffset + uv * uvScale;',
  11105. ' vec2 alignedPosition = ( position - center ) * scale;',
  11106. ' vec2 rotatedPosition;',
  11107. ' rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  11108. ' rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  11109. ' vec4 mvPosition;',
  11110. ' mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  11111. ' mvPosition.xy += rotatedPosition;',
  11112. ' gl_Position = projectionMatrix * mvPosition;',
  11113. ' fogDepth = - mvPosition.z;',
  11114. '}'
  11115. ].join( '\n' ) );
  11116. gl.shaderSource( fragmentShader, [
  11117. 'precision ' + capabilities.precision + ' float;',
  11118. '#define SHADER_NAME ' + 'SpriteMaterial',
  11119. 'uniform vec3 color;',
  11120. 'uniform sampler2D map;',
  11121. 'uniform float opacity;',
  11122. 'uniform int fogType;',
  11123. 'uniform vec3 fogColor;',
  11124. 'uniform float fogDensity;',
  11125. 'uniform float fogNear;',
  11126. 'uniform float fogFar;',
  11127. 'uniform float alphaTest;',
  11128. 'varying vec2 vUV;',
  11129. 'varying float fogDepth;',
  11130. 'void main() {',
  11131. ' vec4 texture = texture2D( map, vUV );',
  11132. ' gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  11133. ' if ( gl_FragColor.a < alphaTest ) discard;',
  11134. ' if ( fogType > 0 ) {',
  11135. ' float fogFactor = 0.0;',
  11136. ' if ( fogType == 1 ) {',
  11137. ' fogFactor = smoothstep( fogNear, fogFar, fogDepth );',
  11138. ' } else {',
  11139. ' const float LOG2 = 1.442695;',
  11140. ' fogFactor = exp2( - fogDensity * fogDensity * fogDepth * fogDepth * LOG2 );',
  11141. ' fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  11142. ' }',
  11143. ' gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );',
  11144. ' }',
  11145. '}'
  11146. ].join( '\n' ) );
  11147. gl.compileShader( vertexShader );
  11148. gl.compileShader( fragmentShader );
  11149. gl.attachShader( program, vertexShader );
  11150. gl.attachShader( program, fragmentShader );
  11151. gl.linkProgram( program );
  11152. return program;
  11153. }
  11154. function painterSortStable( a, b ) {
  11155. if ( a.renderOrder !== b.renderOrder ) {
  11156. return a.renderOrder - b.renderOrder;
  11157. } else if ( a.z !== b.z ) {
  11158. return b.z - a.z;
  11159. } else {
  11160. return b.id - a.id;
  11161. }
  11162. }
  11163. }
  11164. /**
  11165. * @author mrdoob / http://mrdoob.com/
  11166. */
  11167. function WebGLState( gl, extensions, utils ) {
  11168. function ColorBuffer() {
  11169. var locked = false;
  11170. var color = new Vector4();
  11171. var currentColorMask = null;
  11172. var currentColorClear = new Vector4( 0, 0, 0, 0 );
  11173. return {
  11174. setMask: function ( colorMask ) {
  11175. if ( currentColorMask !== colorMask && ! locked ) {
  11176. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  11177. currentColorMask = colorMask;
  11178. }
  11179. },
  11180. setLocked: function ( lock ) {
  11181. locked = lock;
  11182. },
  11183. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  11184. if ( premultipliedAlpha === true ) {
  11185. r *= a; g *= a; b *= a;
  11186. }
  11187. color.set( r, g, b, a );
  11188. if ( currentColorClear.equals( color ) === false ) {
  11189. gl.clearColor( r, g, b, a );
  11190. currentColorClear.copy( color );
  11191. }
  11192. },
  11193. reset: function () {
  11194. locked = false;
  11195. currentColorMask = null;
  11196. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  11197. }
  11198. };
  11199. }
  11200. function DepthBuffer() {
  11201. var locked = false;
  11202. var currentDepthMask = null;
  11203. var currentDepthFunc = null;
  11204. var currentDepthClear = null;
  11205. return {
  11206. setTest: function ( depthTest ) {
  11207. if ( depthTest ) {
  11208. enable( gl.DEPTH_TEST );
  11209. } else {
  11210. disable( gl.DEPTH_TEST );
  11211. }
  11212. },
  11213. setMask: function ( depthMask ) {
  11214. if ( currentDepthMask !== depthMask && ! locked ) {
  11215. gl.depthMask( depthMask );
  11216. currentDepthMask = depthMask;
  11217. }
  11218. },
  11219. setFunc: function ( depthFunc ) {
  11220. if ( currentDepthFunc !== depthFunc ) {
  11221. if ( depthFunc ) {
  11222. switch ( depthFunc ) {
  11223. case NeverDepth:
  11224. gl.depthFunc( gl.NEVER );
  11225. break;
  11226. case AlwaysDepth:
  11227. gl.depthFunc( gl.ALWAYS );
  11228. break;
  11229. case LessDepth:
  11230. gl.depthFunc( gl.LESS );
  11231. break;
  11232. case LessEqualDepth:
  11233. gl.depthFunc( gl.LEQUAL );
  11234. break;
  11235. case EqualDepth:
  11236. gl.depthFunc( gl.EQUAL );
  11237. break;
  11238. case GreaterEqualDepth:
  11239. gl.depthFunc( gl.GEQUAL );
  11240. break;
  11241. case GreaterDepth:
  11242. gl.depthFunc( gl.GREATER );
  11243. break;
  11244. case NotEqualDepth:
  11245. gl.depthFunc( gl.NOTEQUAL );
  11246. break;
  11247. default:
  11248. gl.depthFunc( gl.LEQUAL );
  11249. }
  11250. } else {
  11251. gl.depthFunc( gl.LEQUAL );
  11252. }
  11253. currentDepthFunc = depthFunc;
  11254. }
  11255. },
  11256. setLocked: function ( lock ) {
  11257. locked = lock;
  11258. },
  11259. setClear: function ( depth ) {
  11260. if ( currentDepthClear !== depth ) {
  11261. gl.clearDepth( depth );
  11262. currentDepthClear = depth;
  11263. }
  11264. },
  11265. reset: function () {
  11266. locked = false;
  11267. currentDepthMask = null;
  11268. currentDepthFunc = null;
  11269. currentDepthClear = null;
  11270. }
  11271. };
  11272. }
  11273. function StencilBuffer() {
  11274. var locked = false;
  11275. var currentStencilMask = null;
  11276. var currentStencilFunc = null;
  11277. var currentStencilRef = null;
  11278. var currentStencilFuncMask = null;
  11279. var currentStencilFail = null;
  11280. var currentStencilZFail = null;
  11281. var currentStencilZPass = null;
  11282. var currentStencilClear = null;
  11283. return {
  11284. setTest: function ( stencilTest ) {
  11285. if ( stencilTest ) {
  11286. enable( gl.STENCIL_TEST );
  11287. } else {
  11288. disable( gl.STENCIL_TEST );
  11289. }
  11290. },
  11291. setMask: function ( stencilMask ) {
  11292. if ( currentStencilMask !== stencilMask && ! locked ) {
  11293. gl.stencilMask( stencilMask );
  11294. currentStencilMask = stencilMask;
  11295. }
  11296. },
  11297. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  11298. if ( currentStencilFunc !== stencilFunc ||
  11299. currentStencilRef !== stencilRef ||
  11300. currentStencilFuncMask !== stencilMask ) {
  11301. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  11302. currentStencilFunc = stencilFunc;
  11303. currentStencilRef = stencilRef;
  11304. currentStencilFuncMask = stencilMask;
  11305. }
  11306. },
  11307. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  11308. if ( currentStencilFail !== stencilFail ||
  11309. currentStencilZFail !== stencilZFail ||
  11310. currentStencilZPass !== stencilZPass ) {
  11311. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  11312. currentStencilFail = stencilFail;
  11313. currentStencilZFail = stencilZFail;
  11314. currentStencilZPass = stencilZPass;
  11315. }
  11316. },
  11317. setLocked: function ( lock ) {
  11318. locked = lock;
  11319. },
  11320. setClear: function ( stencil ) {
  11321. if ( currentStencilClear !== stencil ) {
  11322. gl.clearStencil( stencil );
  11323. currentStencilClear = stencil;
  11324. }
  11325. },
  11326. reset: function () {
  11327. locked = false;
  11328. currentStencilMask = null;
  11329. currentStencilFunc = null;
  11330. currentStencilRef = null;
  11331. currentStencilFuncMask = null;
  11332. currentStencilFail = null;
  11333. currentStencilZFail = null;
  11334. currentStencilZPass = null;
  11335. currentStencilClear = null;
  11336. }
  11337. };
  11338. }
  11339. //
  11340. var colorBuffer = new ColorBuffer();
  11341. var depthBuffer = new DepthBuffer();
  11342. var stencilBuffer = new StencilBuffer();
  11343. var maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  11344. var newAttributes = new Uint8Array( maxVertexAttributes );
  11345. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  11346. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  11347. var capabilities = {};
  11348. var compressedTextureFormats = null;
  11349. var currentProgram = null;
  11350. var currentBlending = null;
  11351. var currentBlendEquation = null;
  11352. var currentBlendSrc = null;
  11353. var currentBlendDst = null;
  11354. var currentBlendEquationAlpha = null;
  11355. var currentBlendSrcAlpha = null;
  11356. var currentBlendDstAlpha = null;
  11357. var currentPremultipledAlpha = false;
  11358. var currentFlipSided = null;
  11359. var currentCullFace = null;
  11360. var currentLineWidth = null;
  11361. var currentPolygonOffsetFactor = null;
  11362. var currentPolygonOffsetUnits = null;
  11363. var maxTextures = gl.getParameter( gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS );
  11364. var lineWidthAvailable = false;
  11365. var version = 0;
  11366. var glVersion = gl.getParameter( gl.VERSION );
  11367. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  11368. version = parseFloat( /^WebGL\ ([0-9])/.exec( glVersion )[ 1 ] );
  11369. lineWidthAvailable = ( version >= 1.0 );
  11370. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  11371. version = parseFloat( /^OpenGL\ ES\ ([0-9])/.exec( glVersion )[ 1 ] );
  11372. lineWidthAvailable = ( version >= 2.0 );
  11373. }
  11374. var currentTextureSlot = null;
  11375. var currentBoundTextures = {};
  11376. var currentScissor = new Vector4();
  11377. var currentViewport = new Vector4();
  11378. function createTexture( type, target, count ) {
  11379. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  11380. var texture = gl.createTexture();
  11381. gl.bindTexture( type, texture );
  11382. gl.texParameteri( type, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  11383. gl.texParameteri( type, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  11384. for ( var i = 0; i < count; i ++ ) {
  11385. gl.texImage2D( target + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data );
  11386. }
  11387. return texture;
  11388. }
  11389. var emptyTextures = {};
  11390. emptyTextures[ gl.TEXTURE_2D ] = createTexture( gl.TEXTURE_2D, gl.TEXTURE_2D, 1 );
  11391. emptyTextures[ gl.TEXTURE_CUBE_MAP ] = createTexture( gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6 );
  11392. // init
  11393. colorBuffer.setClear( 0, 0, 0, 1 );
  11394. depthBuffer.setClear( 1 );
  11395. stencilBuffer.setClear( 0 );
  11396. enable( gl.DEPTH_TEST );
  11397. depthBuffer.setFunc( LessEqualDepth );
  11398. setFlipSided( false );
  11399. setCullFace( CullFaceBack );
  11400. enable( gl.CULL_FACE );
  11401. enable( gl.BLEND );
  11402. setBlending( NormalBlending );
  11403. //
  11404. function initAttributes() {
  11405. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  11406. newAttributes[ i ] = 0;
  11407. }
  11408. }
  11409. function enableAttribute( attribute ) {
  11410. newAttributes[ attribute ] = 1;
  11411. if ( enabledAttributes[ attribute ] === 0 ) {
  11412. gl.enableVertexAttribArray( attribute );
  11413. enabledAttributes[ attribute ] = 1;
  11414. }
  11415. if ( attributeDivisors[ attribute ] !== 0 ) {
  11416. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  11417. extension.vertexAttribDivisorANGLE( attribute, 0 );
  11418. attributeDivisors[ attribute ] = 0;
  11419. }
  11420. }
  11421. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  11422. newAttributes[ attribute ] = 1;
  11423. if ( enabledAttributes[ attribute ] === 0 ) {
  11424. gl.enableVertexAttribArray( attribute );
  11425. enabledAttributes[ attribute ] = 1;
  11426. }
  11427. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  11428. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  11429. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  11430. attributeDivisors[ attribute ] = meshPerAttribute;
  11431. }
  11432. }
  11433. function disableUnusedAttributes() {
  11434. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  11435. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  11436. gl.disableVertexAttribArray( i );
  11437. enabledAttributes[ i ] = 0;
  11438. }
  11439. }
  11440. }
  11441. function enable( id ) {
  11442. if ( capabilities[ id ] !== true ) {
  11443. gl.enable( id );
  11444. capabilities[ id ] = true;
  11445. }
  11446. }
  11447. function disable( id ) {
  11448. if ( capabilities[ id ] !== false ) {
  11449. gl.disable( id );
  11450. capabilities[ id ] = false;
  11451. }
  11452. }
  11453. function getCompressedTextureFormats() {
  11454. if ( compressedTextureFormats === null ) {
  11455. compressedTextureFormats = [];
  11456. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  11457. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  11458. extensions.get( 'WEBGL_compressed_texture_etc1' ) ||
  11459. extensions.get( 'WEBGL_compressed_texture_astc' ) ) {
  11460. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  11461. for ( var i = 0; i < formats.length; i ++ ) {
  11462. compressedTextureFormats.push( formats[ i ] );
  11463. }
  11464. }
  11465. }
  11466. return compressedTextureFormats;
  11467. }
  11468. function useProgram( program ) {
  11469. if ( currentProgram !== program ) {
  11470. gl.useProgram( program );
  11471. currentProgram = program;
  11472. return true;
  11473. }
  11474. return false;
  11475. }
  11476. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  11477. if ( blending !== NoBlending ) {
  11478. enable( gl.BLEND );
  11479. } else {
  11480. disable( gl.BLEND );
  11481. }
  11482. if ( blending !== CustomBlending ) {
  11483. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  11484. switch ( blending ) {
  11485. case AdditiveBlending:
  11486. if ( premultipliedAlpha ) {
  11487. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11488. gl.blendFuncSeparate( gl.ONE, gl.ONE, gl.ONE, gl.ONE );
  11489. } else {
  11490. gl.blendEquation( gl.FUNC_ADD );
  11491. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  11492. }
  11493. break;
  11494. case SubtractiveBlending:
  11495. if ( premultipliedAlpha ) {
  11496. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11497. gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ONE_MINUS_SRC_ALPHA );
  11498. } else {
  11499. gl.blendEquation( gl.FUNC_ADD );
  11500. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  11501. }
  11502. break;
  11503. case MultiplyBlending:
  11504. if ( premultipliedAlpha ) {
  11505. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11506. gl.blendFuncSeparate( gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA );
  11507. } else {
  11508. gl.blendEquation( gl.FUNC_ADD );
  11509. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  11510. }
  11511. break;
  11512. default:
  11513. if ( premultipliedAlpha ) {
  11514. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11515. gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  11516. } else {
  11517. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11518. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  11519. }
  11520. }
  11521. }
  11522. currentBlendEquation = null;
  11523. currentBlendSrc = null;
  11524. currentBlendDst = null;
  11525. currentBlendEquationAlpha = null;
  11526. currentBlendSrcAlpha = null;
  11527. currentBlendDstAlpha = null;
  11528. } else {
  11529. blendEquationAlpha = blendEquationAlpha || blendEquation;
  11530. blendSrcAlpha = blendSrcAlpha || blendSrc;
  11531. blendDstAlpha = blendDstAlpha || blendDst;
  11532. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  11533. gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
  11534. currentBlendEquation = blendEquation;
  11535. currentBlendEquationAlpha = blendEquationAlpha;
  11536. }
  11537. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  11538. gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) );
  11539. currentBlendSrc = blendSrc;
  11540. currentBlendDst = blendDst;
  11541. currentBlendSrcAlpha = blendSrcAlpha;
  11542. currentBlendDstAlpha = blendDstAlpha;
  11543. }
  11544. }
  11545. currentBlending = blending;
  11546. currentPremultipledAlpha = premultipliedAlpha;
  11547. }
  11548. function setMaterial( material, frontFaceCW ) {
  11549. material.side === DoubleSide
  11550. ? disable( gl.CULL_FACE )
  11551. : enable( gl.CULL_FACE );
  11552. var flipSided = ( material.side === BackSide );
  11553. if ( frontFaceCW ) flipSided = ! flipSided;
  11554. setFlipSided( flipSided );
  11555. material.transparent === true
  11556. ? setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha )
  11557. : setBlending( NoBlending );
  11558. depthBuffer.setFunc( material.depthFunc );
  11559. depthBuffer.setTest( material.depthTest );
  11560. depthBuffer.setMask( material.depthWrite );
  11561. colorBuffer.setMask( material.colorWrite );
  11562. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  11563. }
  11564. //
  11565. function setFlipSided( flipSided ) {
  11566. if ( currentFlipSided !== flipSided ) {
  11567. if ( flipSided ) {
  11568. gl.frontFace( gl.CW );
  11569. } else {
  11570. gl.frontFace( gl.CCW );
  11571. }
  11572. currentFlipSided = flipSided;
  11573. }
  11574. }
  11575. function setCullFace( cullFace ) {
  11576. if ( cullFace !== CullFaceNone ) {
  11577. enable( gl.CULL_FACE );
  11578. if ( cullFace !== currentCullFace ) {
  11579. if ( cullFace === CullFaceBack ) {
  11580. gl.cullFace( gl.BACK );
  11581. } else if ( cullFace === CullFaceFront ) {
  11582. gl.cullFace( gl.FRONT );
  11583. } else {
  11584. gl.cullFace( gl.FRONT_AND_BACK );
  11585. }
  11586. }
  11587. } else {
  11588. disable( gl.CULL_FACE );
  11589. }
  11590. currentCullFace = cullFace;
  11591. }
  11592. function setLineWidth( width ) {
  11593. if ( width !== currentLineWidth ) {
  11594. if ( lineWidthAvailable ) gl.lineWidth( width );
  11595. currentLineWidth = width;
  11596. }
  11597. }
  11598. function setPolygonOffset( polygonOffset, factor, units ) {
  11599. if ( polygonOffset ) {
  11600. enable( gl.POLYGON_OFFSET_FILL );
  11601. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  11602. gl.polygonOffset( factor, units );
  11603. currentPolygonOffsetFactor = factor;
  11604. currentPolygonOffsetUnits = units;
  11605. }
  11606. } else {
  11607. disable( gl.POLYGON_OFFSET_FILL );
  11608. }
  11609. }
  11610. function setScissorTest( scissorTest ) {
  11611. if ( scissorTest ) {
  11612. enable( gl.SCISSOR_TEST );
  11613. } else {
  11614. disable( gl.SCISSOR_TEST );
  11615. }
  11616. }
  11617. // texture
  11618. function activeTexture( webglSlot ) {
  11619. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  11620. if ( currentTextureSlot !== webglSlot ) {
  11621. gl.activeTexture( webglSlot );
  11622. currentTextureSlot = webglSlot;
  11623. }
  11624. }
  11625. function bindTexture( webglType, webglTexture ) {
  11626. if ( currentTextureSlot === null ) {
  11627. activeTexture();
  11628. }
  11629. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  11630. if ( boundTexture === undefined ) {
  11631. boundTexture = { type: undefined, texture: undefined };
  11632. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  11633. }
  11634. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  11635. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  11636. boundTexture.type = webglType;
  11637. boundTexture.texture = webglTexture;
  11638. }
  11639. }
  11640. function compressedTexImage2D() {
  11641. try {
  11642. gl.compressedTexImage2D.apply( gl, arguments );
  11643. } catch ( error ) {
  11644. console.error( 'THREE.WebGLState:', error );
  11645. }
  11646. }
  11647. function texImage2D() {
  11648. try {
  11649. gl.texImage2D.apply( gl, arguments );
  11650. } catch ( error ) {
  11651. console.error( 'THREE.WebGLState:', error );
  11652. }
  11653. }
  11654. //
  11655. function scissor( scissor ) {
  11656. if ( currentScissor.equals( scissor ) === false ) {
  11657. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  11658. currentScissor.copy( scissor );
  11659. }
  11660. }
  11661. function viewport( viewport ) {
  11662. if ( currentViewport.equals( viewport ) === false ) {
  11663. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  11664. currentViewport.copy( viewport );
  11665. }
  11666. }
  11667. //
  11668. function reset() {
  11669. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  11670. if ( enabledAttributes[ i ] === 1 ) {
  11671. gl.disableVertexAttribArray( i );
  11672. enabledAttributes[ i ] = 0;
  11673. }
  11674. }
  11675. capabilities = {};
  11676. compressedTextureFormats = null;
  11677. currentTextureSlot = null;
  11678. currentBoundTextures = {};
  11679. currentProgram = null;
  11680. currentBlending = null;
  11681. currentFlipSided = null;
  11682. currentCullFace = null;
  11683. colorBuffer.reset();
  11684. depthBuffer.reset();
  11685. stencilBuffer.reset();
  11686. }
  11687. return {
  11688. buffers: {
  11689. color: colorBuffer,
  11690. depth: depthBuffer,
  11691. stencil: stencilBuffer
  11692. },
  11693. initAttributes: initAttributes,
  11694. enableAttribute: enableAttribute,
  11695. enableAttributeAndDivisor: enableAttributeAndDivisor,
  11696. disableUnusedAttributes: disableUnusedAttributes,
  11697. enable: enable,
  11698. disable: disable,
  11699. getCompressedTextureFormats: getCompressedTextureFormats,
  11700. useProgram: useProgram,
  11701. setBlending: setBlending,
  11702. setMaterial: setMaterial,
  11703. setFlipSided: setFlipSided,
  11704. setCullFace: setCullFace,
  11705. setLineWidth: setLineWidth,
  11706. setPolygonOffset: setPolygonOffset,
  11707. setScissorTest: setScissorTest,
  11708. activeTexture: activeTexture,
  11709. bindTexture: bindTexture,
  11710. compressedTexImage2D: compressedTexImage2D,
  11711. texImage2D: texImage2D,
  11712. scissor: scissor,
  11713. viewport: viewport,
  11714. reset: reset
  11715. };
  11716. }
  11717. /**
  11718. * @author mrdoob / http://mrdoob.com/
  11719. */
  11720. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  11721. var _isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof WebGL2RenderingContext ); /* global WebGL2RenderingContext */
  11722. var _videoTextures = {};
  11723. var _canvas;
  11724. //
  11725. function clampToMaxSize( image, maxSize ) {
  11726. if ( image.width > maxSize || image.height > maxSize ) {
  11727. if ( 'data' in image ) {
  11728. console.warn( 'THREE.WebGLRenderer: image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  11729. return;
  11730. }
  11731. // Warning: Scaling through the canvas will only work with images that use
  11732. // premultiplied alpha.
  11733. var scale = maxSize / Math.max( image.width, image.height );
  11734. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  11735. canvas.width = Math.floor( image.width * scale );
  11736. canvas.height = Math.floor( image.height * scale );
  11737. var context = canvas.getContext( '2d' );
  11738. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  11739. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  11740. return canvas;
  11741. }
  11742. return image;
  11743. }
  11744. function isPowerOfTwo( image ) {
  11745. return _Math.isPowerOfTwo( image.width ) && _Math.isPowerOfTwo( image.height );
  11746. }
  11747. function makePowerOfTwo( image ) {
  11748. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof ImageBitmap ) {
  11749. if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  11750. _canvas.width = _Math.floorPowerOfTwo( image.width );
  11751. _canvas.height = _Math.floorPowerOfTwo( image.height );
  11752. var context = _canvas.getContext( '2d' );
  11753. context.drawImage( image, 0, 0, _canvas.width, _canvas.height );
  11754. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + _canvas.width + 'x' + _canvas.height, image );
  11755. return _canvas;
  11756. }
  11757. return image;
  11758. }
  11759. function textureNeedsPowerOfTwo( texture ) {
  11760. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  11761. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  11762. }
  11763. function textureNeedsGenerateMipmaps( texture, isPowerOfTwo ) {
  11764. return texture.generateMipmaps && isPowerOfTwo &&
  11765. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  11766. }
  11767. function generateMipmap( target, texture, width, height ) {
  11768. _gl.generateMipmap( target );
  11769. var textureProperties = properties.get( texture );
  11770. // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  11771. textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
  11772. }
  11773. // Fallback filters for non-power-of-2 textures
  11774. function filterFallback( f ) {
  11775. if ( f === NearestFilter || f === NearestMipMapNearestFilter || f === NearestMipMapLinearFilter ) {
  11776. return _gl.NEAREST;
  11777. }
  11778. return _gl.LINEAR;
  11779. }
  11780. //
  11781. function onTextureDispose( event ) {
  11782. var texture = event.target;
  11783. texture.removeEventListener( 'dispose', onTextureDispose );
  11784. deallocateTexture( texture );
  11785. if ( texture.isVideoTexture ) {
  11786. delete _videoTextures[ texture.id ];
  11787. }
  11788. info.memory.textures --;
  11789. }
  11790. function onRenderTargetDispose( event ) {
  11791. var renderTarget = event.target;
  11792. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  11793. deallocateRenderTarget( renderTarget );
  11794. info.memory.textures --;
  11795. }
  11796. //
  11797. function deallocateTexture( texture ) {
  11798. var textureProperties = properties.get( texture );
  11799. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  11800. // cube texture
  11801. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  11802. } else {
  11803. // 2D texture
  11804. if ( textureProperties.__webglInit === undefined ) return;
  11805. _gl.deleteTexture( textureProperties.__webglTexture );
  11806. }
  11807. // remove all webgl properties
  11808. properties.remove( texture );
  11809. }
  11810. function deallocateRenderTarget( renderTarget ) {
  11811. var renderTargetProperties = properties.get( renderTarget );
  11812. var textureProperties = properties.get( renderTarget.texture );
  11813. if ( ! renderTarget ) return;
  11814. if ( textureProperties.__webglTexture !== undefined ) {
  11815. _gl.deleteTexture( textureProperties.__webglTexture );
  11816. }
  11817. if ( renderTarget.depthTexture ) {
  11818. renderTarget.depthTexture.dispose();
  11819. }
  11820. if ( renderTarget.isWebGLRenderTargetCube ) {
  11821. for ( var i = 0; i < 6; i ++ ) {
  11822. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  11823. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  11824. }
  11825. } else {
  11826. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  11827. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  11828. }
  11829. properties.remove( renderTarget.texture );
  11830. properties.remove( renderTarget );
  11831. }
  11832. //
  11833. function setTexture2D( texture, slot ) {
  11834. var textureProperties = properties.get( texture );
  11835. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  11836. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  11837. var image = texture.image;
  11838. if ( image === undefined ) {
  11839. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  11840. } else if ( image.complete === false ) {
  11841. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  11842. } else {
  11843. uploadTexture( textureProperties, texture, slot );
  11844. return;
  11845. }
  11846. }
  11847. state.activeTexture( _gl.TEXTURE0 + slot );
  11848. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  11849. }
  11850. function setTextureCube( texture, slot ) {
  11851. var textureProperties = properties.get( texture );
  11852. if ( texture.image.length === 6 ) {
  11853. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  11854. if ( ! textureProperties.__image__webglTextureCube ) {
  11855. texture.addEventListener( 'dispose', onTextureDispose );
  11856. textureProperties.__image__webglTextureCube = _gl.createTexture();
  11857. info.memory.textures ++;
  11858. }
  11859. state.activeTexture( _gl.TEXTURE0 + slot );
  11860. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  11861. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  11862. var isCompressed = ( texture && texture.isCompressedTexture );
  11863. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  11864. var cubeImage = [];
  11865. for ( var i = 0; i < 6; i ++ ) {
  11866. if ( ! isCompressed && ! isDataTexture ) {
  11867. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  11868. } else {
  11869. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  11870. }
  11871. }
  11872. var image = cubeImage[ 0 ],
  11873. isPowerOfTwoImage = isPowerOfTwo( image ),
  11874. glFormat = utils.convert( texture.format ),
  11875. glType = utils.convert( texture.type );
  11876. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
  11877. for ( var i = 0; i < 6; i ++ ) {
  11878. if ( ! isCompressed ) {
  11879. if ( isDataTexture ) {
  11880. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  11881. } else {
  11882. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  11883. }
  11884. } else {
  11885. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  11886. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  11887. mipmap = mipmaps[ j ];
  11888. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  11889. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  11890. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  11891. } else {
  11892. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  11893. }
  11894. } else {
  11895. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  11896. }
  11897. }
  11898. }
  11899. }
  11900. if ( ! isCompressed ) {
  11901. textureProperties.__maxMipLevel = 0;
  11902. } else {
  11903. textureProperties.__maxMipLevel = mipmaps.length - 1;
  11904. }
  11905. if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) {
  11906. // We assume images for cube map have the same size.
  11907. generateMipmap( _gl.TEXTURE_CUBE_MAP, texture, image.width, image.height );
  11908. }
  11909. textureProperties.__version = texture.version;
  11910. if ( texture.onUpdate ) texture.onUpdate( texture );
  11911. } else {
  11912. state.activeTexture( _gl.TEXTURE0 + slot );
  11913. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  11914. }
  11915. }
  11916. }
  11917. function setTextureCubeDynamic( texture, slot ) {
  11918. state.activeTexture( _gl.TEXTURE0 + slot );
  11919. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  11920. }
  11921. function setTextureParameters( textureType, texture, isPowerOfTwoImage ) {
  11922. var extension;
  11923. if ( isPowerOfTwoImage ) {
  11924. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, utils.convert( texture.wrapS ) );
  11925. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, utils.convert( texture.wrapT ) );
  11926. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, utils.convert( texture.magFilter ) );
  11927. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, utils.convert( texture.minFilter ) );
  11928. } else {
  11929. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  11930. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  11931. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  11932. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  11933. }
  11934. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  11935. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  11936. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  11937. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  11938. }
  11939. }
  11940. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  11941. if ( extension ) {
  11942. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  11943. if ( texture.type === HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  11944. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  11945. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  11946. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  11947. }
  11948. }
  11949. }
  11950. function uploadTexture( textureProperties, texture, slot ) {
  11951. if ( textureProperties.__webglInit === undefined ) {
  11952. textureProperties.__webglInit = true;
  11953. texture.addEventListener( 'dispose', onTextureDispose );
  11954. textureProperties.__webglTexture = _gl.createTexture();
  11955. info.memory.textures ++;
  11956. }
  11957. state.activeTexture( _gl.TEXTURE0 + slot );
  11958. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  11959. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  11960. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  11961. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  11962. var image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  11963. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( image ) === false ) {
  11964. image = makePowerOfTwo( image );
  11965. }
  11966. var isPowerOfTwoImage = isPowerOfTwo( image ),
  11967. glFormat = utils.convert( texture.format ),
  11968. glType = utils.convert( texture.type );
  11969. setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
  11970. var mipmap, mipmaps = texture.mipmaps;
  11971. if ( texture.isDepthTexture ) {
  11972. // populate depth texture with dummy data
  11973. var internalFormat = _gl.DEPTH_COMPONENT;
  11974. if ( texture.type === FloatType ) {
  11975. if ( ! _isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
  11976. internalFormat = _gl.DEPTH_COMPONENT32F;
  11977. } else if ( _isWebGL2 ) {
  11978. // WebGL 2.0 requires signed internalformat for glTexImage2D
  11979. internalFormat = _gl.DEPTH_COMPONENT16;
  11980. }
  11981. if ( texture.format === DepthFormat && internalFormat === _gl.DEPTH_COMPONENT ) {
  11982. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  11983. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  11984. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  11985. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  11986. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  11987. texture.type = UnsignedShortType;
  11988. glType = utils.convert( texture.type );
  11989. }
  11990. }
  11991. // Depth stencil textures need the DEPTH_STENCIL internal format
  11992. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  11993. if ( texture.format === DepthStencilFormat ) {
  11994. internalFormat = _gl.DEPTH_STENCIL;
  11995. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  11996. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  11997. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  11998. if ( texture.type !== UnsignedInt248Type ) {
  11999. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  12000. texture.type = UnsignedInt248Type;
  12001. glType = utils.convert( texture.type );
  12002. }
  12003. }
  12004. state.texImage2D( _gl.TEXTURE_2D, 0, internalFormat, image.width, image.height, 0, glFormat, glType, null );
  12005. } else if ( texture.isDataTexture ) {
  12006. // use manually created mipmaps if available
  12007. // if there are no manual mipmaps
  12008. // set 0 level mipmap and then use GL to generate other mipmap levels
  12009. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  12010. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12011. mipmap = mipmaps[ i ];
  12012. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12013. }
  12014. texture.generateMipmaps = false;
  12015. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12016. } else {
  12017. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  12018. textureProperties.__maxMipLevel = 0;
  12019. }
  12020. } else if ( texture.isCompressedTexture ) {
  12021. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12022. mipmap = mipmaps[ i ];
  12023. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12024. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12025. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12026. } else {
  12027. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  12028. }
  12029. } else {
  12030. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12031. }
  12032. }
  12033. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12034. } else {
  12035. // regular Texture (image, video, canvas)
  12036. // use manually created mipmaps if available
  12037. // if there are no manual mipmaps
  12038. // set 0 level mipmap and then use GL to generate other mipmap levels
  12039. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  12040. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12041. mipmap = mipmaps[ i ];
  12042. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  12043. }
  12044. texture.generateMipmaps = false;
  12045. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12046. } else {
  12047. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, image );
  12048. textureProperties.__maxMipLevel = 0;
  12049. }
  12050. }
  12051. if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) {
  12052. generateMipmap( _gl.TEXTURE_2D, texture, image.width, image.height );
  12053. }
  12054. textureProperties.__version = texture.version;
  12055. if ( texture.onUpdate ) texture.onUpdate( texture );
  12056. }
  12057. // Render targets
  12058. // Setup storage for target texture and bind it to correct framebuffer
  12059. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  12060. var glFormat = utils.convert( renderTarget.texture.format );
  12061. var glType = utils.convert( renderTarget.texture.type );
  12062. state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  12063. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  12064. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  12065. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  12066. }
  12067. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  12068. function setupRenderBufferStorage( renderbuffer, renderTarget ) {
  12069. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  12070. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  12071. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  12072. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  12073. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  12074. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  12075. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  12076. } else {
  12077. // FIXME: We don't support !depth !stencil
  12078. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  12079. }
  12080. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  12081. }
  12082. // Setup resources for a Depth Texture for a FBO (needs an extension)
  12083. function setupDepthTexture( framebuffer, renderTarget ) {
  12084. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  12085. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  12086. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  12087. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  12088. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  12089. }
  12090. // upload an empty depth texture with framebuffer size
  12091. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  12092. renderTarget.depthTexture.image.width !== renderTarget.width ||
  12093. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  12094. renderTarget.depthTexture.image.width = renderTarget.width;
  12095. renderTarget.depthTexture.image.height = renderTarget.height;
  12096. renderTarget.depthTexture.needsUpdate = true;
  12097. }
  12098. setTexture2D( renderTarget.depthTexture, 0 );
  12099. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  12100. if ( renderTarget.depthTexture.format === DepthFormat ) {
  12101. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  12102. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  12103. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  12104. } else {
  12105. throw new Error( 'Unknown depthTexture format' );
  12106. }
  12107. }
  12108. // Setup GL resources for a non-texture depth buffer
  12109. function setupDepthRenderbuffer( renderTarget ) {
  12110. var renderTargetProperties = properties.get( renderTarget );
  12111. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  12112. if ( renderTarget.depthTexture ) {
  12113. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  12114. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  12115. } else {
  12116. if ( isCube ) {
  12117. renderTargetProperties.__webglDepthbuffer = [];
  12118. for ( var i = 0; i < 6; i ++ ) {
  12119. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );
  12120. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  12121. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  12122. }
  12123. } else {
  12124. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
  12125. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  12126. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  12127. }
  12128. }
  12129. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  12130. }
  12131. // Set up GL resources for the render target
  12132. function setupRenderTarget( renderTarget ) {
  12133. var renderTargetProperties = properties.get( renderTarget );
  12134. var textureProperties = properties.get( renderTarget.texture );
  12135. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  12136. textureProperties.__webglTexture = _gl.createTexture();
  12137. info.memory.textures ++;
  12138. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  12139. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  12140. // Setup framebuffer
  12141. if ( isCube ) {
  12142. renderTargetProperties.__webglFramebuffer = [];
  12143. for ( var i = 0; i < 6; i ++ ) {
  12144. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  12145. }
  12146. } else {
  12147. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  12148. }
  12149. // Setup color buffer
  12150. if ( isCube ) {
  12151. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  12152. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  12153. for ( var i = 0; i < 6; i ++ ) {
  12154. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  12155. }
  12156. if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) {
  12157. generateMipmap( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, renderTarget.width, renderTarget.height );
  12158. }
  12159. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  12160. } else {
  12161. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  12162. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  12163. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );
  12164. if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) {
  12165. generateMipmap( _gl.TEXTURE_2D, renderTarget.texture, renderTarget.width, renderTarget.height );
  12166. }
  12167. state.bindTexture( _gl.TEXTURE_2D, null );
  12168. }
  12169. // Setup depth and stencil buffers
  12170. if ( renderTarget.depthBuffer ) {
  12171. setupDepthRenderbuffer( renderTarget );
  12172. }
  12173. }
  12174. function updateRenderTargetMipmap( renderTarget ) {
  12175. var texture = renderTarget.texture;
  12176. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  12177. if ( textureNeedsGenerateMipmaps( texture, isTargetPowerOfTwo ) ) {
  12178. var target = renderTarget.isWebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  12179. var webglTexture = properties.get( texture ).__webglTexture;
  12180. state.bindTexture( target, webglTexture );
  12181. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  12182. state.bindTexture( target, null );
  12183. }
  12184. }
  12185. function updateVideoTexture( texture ) {
  12186. var id = texture.id;
  12187. var frame = info.render.frame;
  12188. // Check the last frame we updated the VideoTexture
  12189. if ( _videoTextures[ id ] !== frame ) {
  12190. _videoTextures[ id ] = frame;
  12191. texture.update();
  12192. }
  12193. }
  12194. this.setTexture2D = setTexture2D;
  12195. this.setTextureCube = setTextureCube;
  12196. this.setTextureCubeDynamic = setTextureCubeDynamic;
  12197. this.setupRenderTarget = setupRenderTarget;
  12198. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  12199. }
  12200. /**
  12201. * @author thespite / http://www.twitter.com/thespite
  12202. */
  12203. function WebGLUtils( gl, extensions ) {
  12204. function convert( p ) {
  12205. var extension;
  12206. if ( p === RepeatWrapping ) return gl.REPEAT;
  12207. if ( p === ClampToEdgeWrapping ) return gl.CLAMP_TO_EDGE;
  12208. if ( p === MirroredRepeatWrapping ) return gl.MIRRORED_REPEAT;
  12209. if ( p === NearestFilter ) return gl.NEAREST;
  12210. if ( p === NearestMipMapNearestFilter ) return gl.NEAREST_MIPMAP_NEAREST;
  12211. if ( p === NearestMipMapLinearFilter ) return gl.NEAREST_MIPMAP_LINEAR;
  12212. if ( p === LinearFilter ) return gl.LINEAR;
  12213. if ( p === LinearMipMapNearestFilter ) return gl.LINEAR_MIPMAP_NEAREST;
  12214. if ( p === LinearMipMapLinearFilter ) return gl.LINEAR_MIPMAP_LINEAR;
  12215. if ( p === UnsignedByteType ) return gl.UNSIGNED_BYTE;
  12216. if ( p === UnsignedShort4444Type ) return gl.UNSIGNED_SHORT_4_4_4_4;
  12217. if ( p === UnsignedShort5551Type ) return gl.UNSIGNED_SHORT_5_5_5_1;
  12218. if ( p === UnsignedShort565Type ) return gl.UNSIGNED_SHORT_5_6_5;
  12219. if ( p === ByteType ) return gl.BYTE;
  12220. if ( p === ShortType ) return gl.SHORT;
  12221. if ( p === UnsignedShortType ) return gl.UNSIGNED_SHORT;
  12222. if ( p === IntType ) return gl.INT;
  12223. if ( p === UnsignedIntType ) return gl.UNSIGNED_INT;
  12224. if ( p === FloatType ) return gl.FLOAT;
  12225. if ( p === HalfFloatType ) {
  12226. extension = extensions.get( 'OES_texture_half_float' );
  12227. if ( extension !== null ) return extension.HALF_FLOAT_OES;
  12228. }
  12229. if ( p === AlphaFormat ) return gl.ALPHA;
  12230. if ( p === RGBFormat ) return gl.RGB;
  12231. if ( p === RGBAFormat ) return gl.RGBA;
  12232. if ( p === LuminanceFormat ) return gl.LUMINANCE;
  12233. if ( p === LuminanceAlphaFormat ) return gl.LUMINANCE_ALPHA;
  12234. if ( p === DepthFormat ) return gl.DEPTH_COMPONENT;
  12235. if ( p === DepthStencilFormat ) return gl.DEPTH_STENCIL;
  12236. if ( p === AddEquation ) return gl.FUNC_ADD;
  12237. if ( p === SubtractEquation ) return gl.FUNC_SUBTRACT;
  12238. if ( p === ReverseSubtractEquation ) return gl.FUNC_REVERSE_SUBTRACT;
  12239. if ( p === ZeroFactor ) return gl.ZERO;
  12240. if ( p === OneFactor ) return gl.ONE;
  12241. if ( p === SrcColorFactor ) return gl.SRC_COLOR;
  12242. if ( p === OneMinusSrcColorFactor ) return gl.ONE_MINUS_SRC_COLOR;
  12243. if ( p === SrcAlphaFactor ) return gl.SRC_ALPHA;
  12244. if ( p === OneMinusSrcAlphaFactor ) return gl.ONE_MINUS_SRC_ALPHA;
  12245. if ( p === DstAlphaFactor ) return gl.DST_ALPHA;
  12246. if ( p === OneMinusDstAlphaFactor ) return gl.ONE_MINUS_DST_ALPHA;
  12247. if ( p === DstColorFactor ) return gl.DST_COLOR;
  12248. if ( p === OneMinusDstColorFactor ) return gl.ONE_MINUS_DST_COLOR;
  12249. if ( p === SrcAlphaSaturateFactor ) return gl.SRC_ALPHA_SATURATE;
  12250. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  12251. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  12252. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  12253. if ( extension !== null ) {
  12254. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  12255. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  12256. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  12257. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  12258. }
  12259. }
  12260. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  12261. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  12262. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  12263. if ( extension !== null ) {
  12264. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  12265. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  12266. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  12267. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  12268. }
  12269. }
  12270. if ( p === RGB_ETC1_Format ) {
  12271. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  12272. if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  12273. }
  12274. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  12275. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  12276. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  12277. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  12278. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ) {
  12279. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  12280. if ( extension !== null ) {
  12281. return p;
  12282. }
  12283. }
  12284. if ( p === MinEquation || p === MaxEquation ) {
  12285. extension = extensions.get( 'EXT_blend_minmax' );
  12286. if ( extension !== null ) {
  12287. if ( p === MinEquation ) return extension.MIN_EXT;
  12288. if ( p === MaxEquation ) return extension.MAX_EXT;
  12289. }
  12290. }
  12291. if ( p === UnsignedInt248Type ) {
  12292. extension = extensions.get( 'WEBGL_depth_texture' );
  12293. if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
  12294. }
  12295. return 0;
  12296. }
  12297. return { convert: convert };
  12298. }
  12299. /**
  12300. * @author mrdoob / http://mrdoob.com/
  12301. * @author greggman / http://games.greggman.com/
  12302. * @author zz85 / http://www.lab4games.net/zz85/blog
  12303. * @author tschw
  12304. */
  12305. function PerspectiveCamera( fov, aspect, near, far ) {
  12306. Camera.call( this );
  12307. this.type = 'PerspectiveCamera';
  12308. this.fov = fov !== undefined ? fov : 50;
  12309. this.zoom = 1;
  12310. this.near = near !== undefined ? near : 0.1;
  12311. this.far = far !== undefined ? far : 2000;
  12312. this.focus = 10;
  12313. this.aspect = aspect !== undefined ? aspect : 1;
  12314. this.view = null;
  12315. this.filmGauge = 35; // width of the film (default in millimeters)
  12316. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  12317. this.updateProjectionMatrix();
  12318. }
  12319. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  12320. constructor: PerspectiveCamera,
  12321. isPerspectiveCamera: true,
  12322. copy: function ( source, recursive ) {
  12323. Camera.prototype.copy.call( this, source, recursive );
  12324. this.fov = source.fov;
  12325. this.zoom = source.zoom;
  12326. this.near = source.near;
  12327. this.far = source.far;
  12328. this.focus = source.focus;
  12329. this.aspect = source.aspect;
  12330. this.view = source.view === null ? null : Object.assign( {}, source.view );
  12331. this.filmGauge = source.filmGauge;
  12332. this.filmOffset = source.filmOffset;
  12333. return this;
  12334. },
  12335. /**
  12336. * Sets the FOV by focal length in respect to the current .filmGauge.
  12337. *
  12338. * The default film gauge is 35, so that the focal length can be specified for
  12339. * a 35mm (full frame) camera.
  12340. *
  12341. * Values for focal length and film gauge must have the same unit.
  12342. */
  12343. setFocalLength: function ( focalLength ) {
  12344. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  12345. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  12346. this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  12347. this.updateProjectionMatrix();
  12348. },
  12349. /**
  12350. * Calculates the focal length from the current .fov and .filmGauge.
  12351. */
  12352. getFocalLength: function () {
  12353. var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
  12354. return 0.5 * this.getFilmHeight() / vExtentSlope;
  12355. },
  12356. getEffectiveFOV: function () {
  12357. return _Math.RAD2DEG * 2 * Math.atan(
  12358. Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  12359. },
  12360. getFilmWidth: function () {
  12361. // film not completely covered in portrait format (aspect < 1)
  12362. return this.filmGauge * Math.min( this.aspect, 1 );
  12363. },
  12364. getFilmHeight: function () {
  12365. // film not completely covered in landscape format (aspect > 1)
  12366. return this.filmGauge / Math.max( this.aspect, 1 );
  12367. },
  12368. /**
  12369. * Sets an offset in a larger frustum. This is useful for multi-window or
  12370. * multi-monitor/multi-machine setups.
  12371. *
  12372. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  12373. * the monitors are in grid like this
  12374. *
  12375. * +---+---+---+
  12376. * | A | B | C |
  12377. * +---+---+---+
  12378. * | D | E | F |
  12379. * +---+---+---+
  12380. *
  12381. * then for each monitor you would call it like this
  12382. *
  12383. * var w = 1920;
  12384. * var h = 1080;
  12385. * var fullWidth = w * 3;
  12386. * var fullHeight = h * 2;
  12387. *
  12388. * --A--
  12389. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  12390. * --B--
  12391. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  12392. * --C--
  12393. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  12394. * --D--
  12395. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  12396. * --E--
  12397. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  12398. * --F--
  12399. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  12400. *
  12401. * Note there is no reason monitors have to be the same size or in a grid.
  12402. */
  12403. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  12404. this.aspect = fullWidth / fullHeight;
  12405. if ( this.view === null ) {
  12406. this.view = {
  12407. enabled: true,
  12408. fullWidth: 1,
  12409. fullHeight: 1,
  12410. offsetX: 0,
  12411. offsetY: 0,
  12412. width: 1,
  12413. height: 1
  12414. };
  12415. }
  12416. this.view.enabled = true;
  12417. this.view.fullWidth = fullWidth;
  12418. this.view.fullHeight = fullHeight;
  12419. this.view.offsetX = x;
  12420. this.view.offsetY = y;
  12421. this.view.width = width;
  12422. this.view.height = height;
  12423. this.updateProjectionMatrix();
  12424. },
  12425. clearViewOffset: function () {
  12426. if ( this.view !== null ) {
  12427. this.view.enabled = false;
  12428. }
  12429. this.updateProjectionMatrix();
  12430. },
  12431. updateProjectionMatrix: function () {
  12432. var near = this.near,
  12433. top = near * Math.tan(
  12434. _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  12435. height = 2 * top,
  12436. width = this.aspect * height,
  12437. left = - 0.5 * width,
  12438. view = this.view;
  12439. if ( this.view !== null && this.view.enabled ) {
  12440. var fullWidth = view.fullWidth,
  12441. fullHeight = view.fullHeight;
  12442. left += view.offsetX * width / fullWidth;
  12443. top -= view.offsetY * height / fullHeight;
  12444. width *= view.width / fullWidth;
  12445. height *= view.height / fullHeight;
  12446. }
  12447. var skew = this.filmOffset;
  12448. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  12449. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  12450. },
  12451. toJSON: function ( meta ) {
  12452. var data = Object3D.prototype.toJSON.call( this, meta );
  12453. data.object.fov = this.fov;
  12454. data.object.zoom = this.zoom;
  12455. data.object.near = this.near;
  12456. data.object.far = this.far;
  12457. data.object.focus = this.focus;
  12458. data.object.aspect = this.aspect;
  12459. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  12460. data.object.filmGauge = this.filmGauge;
  12461. data.object.filmOffset = this.filmOffset;
  12462. return data;
  12463. }
  12464. } );
  12465. /**
  12466. * @author mrdoob / http://mrdoob.com/
  12467. */
  12468. function ArrayCamera( array ) {
  12469. PerspectiveCamera.call( this );
  12470. this.cameras = array || [];
  12471. }
  12472. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  12473. constructor: ArrayCamera,
  12474. isArrayCamera: true
  12475. } );
  12476. /**
  12477. * @author mrdoob / http://mrdoob.com/
  12478. */
  12479. function WebVRManager( renderer ) {
  12480. var scope = this;
  12481. var device = null;
  12482. var frameData = null;
  12483. var poseTarget = null;
  12484. var standingMatrix = new Matrix4();
  12485. var standingMatrixInverse = new Matrix4();
  12486. if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
  12487. frameData = new window.VRFrameData();
  12488. window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
  12489. }
  12490. var matrixWorldInverse = new Matrix4();
  12491. var tempQuaternion = new Quaternion();
  12492. var tempPosition = new Vector3();
  12493. var cameraL = new PerspectiveCamera();
  12494. cameraL.bounds = new Vector4( 0.0, 0.0, 0.5, 1.0 );
  12495. cameraL.layers.enable( 1 );
  12496. var cameraR = new PerspectiveCamera();
  12497. cameraR.bounds = new Vector4( 0.5, 0.0, 0.5, 1.0 );
  12498. cameraR.layers.enable( 2 );
  12499. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  12500. cameraVR.layers.enable( 1 );
  12501. cameraVR.layers.enable( 2 );
  12502. //
  12503. function isPresenting() {
  12504. return device !== null && device.isPresenting === true;
  12505. }
  12506. var currentSize, currentPixelRatio;
  12507. function onVRDisplayPresentChange() {
  12508. if ( isPresenting() ) {
  12509. var eyeParameters = device.getEyeParameters( 'left' );
  12510. var renderWidth = eyeParameters.renderWidth;
  12511. var renderHeight = eyeParameters.renderHeight;
  12512. currentPixelRatio = renderer.getPixelRatio();
  12513. currentSize = renderer.getSize();
  12514. renderer.setDrawingBufferSize( renderWidth * 2, renderHeight, 1 );
  12515. } else if ( scope.enabled ) {
  12516. renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
  12517. }
  12518. }
  12519. //
  12520. this.enabled = false;
  12521. this.userHeight = 1.6;
  12522. this.getDevice = function () {
  12523. return device;
  12524. };
  12525. this.setDevice = function ( value ) {
  12526. if ( value !== undefined ) device = value;
  12527. };
  12528. this.setPoseTarget = function ( object ) {
  12529. if ( object !== undefined ) poseTarget = object;
  12530. };
  12531. this.getCamera = function ( camera ) {
  12532. if ( device === null ) return camera;
  12533. device.depthNear = camera.near;
  12534. device.depthFar = camera.far;
  12535. device.getFrameData( frameData );
  12536. //
  12537. var stageParameters = device.stageParameters;
  12538. if ( stageParameters ) {
  12539. standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
  12540. } else {
  12541. standingMatrix.makeTranslation( 0, scope.userHeight, 0 );
  12542. }
  12543. var pose = frameData.pose;
  12544. var poseObject = poseTarget !== null ? poseTarget : camera;
  12545. // We want to manipulate poseObject by its position and quaternion components since users may rely on them.
  12546. poseObject.matrix.copy( standingMatrix );
  12547. poseObject.matrix.decompose( poseObject.position, poseObject.quaternion, poseObject.scale );
  12548. if ( pose.orientation !== null ) {
  12549. tempQuaternion.fromArray( pose.orientation );
  12550. poseObject.quaternion.multiply( tempQuaternion );
  12551. }
  12552. if ( pose.position !== null ) {
  12553. tempQuaternion.setFromRotationMatrix( standingMatrix );
  12554. tempPosition.fromArray( pose.position );
  12555. tempPosition.applyQuaternion( tempQuaternion );
  12556. poseObject.position.add( tempPosition );
  12557. }
  12558. poseObject.updateMatrixWorld();
  12559. if ( device.isPresenting === false ) return camera;
  12560. //
  12561. cameraL.near = camera.near;
  12562. cameraR.near = camera.near;
  12563. cameraL.far = camera.far;
  12564. cameraR.far = camera.far;
  12565. cameraVR.matrixWorld.copy( camera.matrixWorld );
  12566. cameraVR.matrixWorldInverse.copy( camera.matrixWorldInverse );
  12567. cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
  12568. cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
  12569. // TODO (mrdoob) Double check this code
  12570. standingMatrixInverse.getInverse( standingMatrix );
  12571. cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
  12572. cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
  12573. var parent = poseObject.parent;
  12574. if ( parent !== null ) {
  12575. matrixWorldInverse.getInverse( parent.matrixWorld );
  12576. cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
  12577. cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
  12578. }
  12579. // envMap and Mirror needs camera.matrixWorld
  12580. cameraL.matrixWorld.getInverse( cameraL.matrixWorldInverse );
  12581. cameraR.matrixWorld.getInverse( cameraR.matrixWorldInverse );
  12582. cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
  12583. cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
  12584. // HACK (mrdoob)
  12585. // https://github.com/w3c/webvr/issues/203
  12586. cameraVR.projectionMatrix.copy( cameraL.projectionMatrix );
  12587. //
  12588. var layers = device.getLayers();
  12589. if ( layers.length ) {
  12590. var layer = layers[ 0 ];
  12591. if ( layer.leftBounds !== null && layer.leftBounds.length === 4 ) {
  12592. cameraL.bounds.fromArray( layer.leftBounds );
  12593. }
  12594. if ( layer.rightBounds !== null && layer.rightBounds.length === 4 ) {
  12595. cameraR.bounds.fromArray( layer.rightBounds );
  12596. }
  12597. }
  12598. return cameraVR;
  12599. };
  12600. this.getStandingMatrix = function () {
  12601. return standingMatrix;
  12602. };
  12603. this.submitFrame = function () {
  12604. if ( isPresenting() ) device.submitFrame();
  12605. };
  12606. this.dispose = function () {
  12607. if ( typeof window !== 'undefined' ) {
  12608. window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
  12609. }
  12610. };
  12611. }
  12612. /**
  12613. * @author supereggbert / http://www.paulbrunt.co.uk/
  12614. * @author mrdoob / http://mrdoob.com/
  12615. * @author alteredq / http://alteredqualia.com/
  12616. * @author szimek / https://github.com/szimek/
  12617. * @author tschw
  12618. */
  12619. function WebGLRenderer( parameters ) {
  12620. console.log( 'THREE.WebGLRenderer', REVISION );
  12621. parameters = parameters || {};
  12622. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  12623. _context = parameters.context !== undefined ? parameters.context : null,
  12624. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  12625. _depth = parameters.depth !== undefined ? parameters.depth : true,
  12626. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  12627. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  12628. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  12629. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  12630. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default';
  12631. var currentRenderList = null;
  12632. var currentRenderState = null;
  12633. // public properties
  12634. this.domElement = _canvas;
  12635. this.context = null;
  12636. // clearing
  12637. this.autoClear = true;
  12638. this.autoClearColor = true;
  12639. this.autoClearDepth = true;
  12640. this.autoClearStencil = true;
  12641. // scene graph
  12642. this.sortObjects = true;
  12643. // user-defined clipping
  12644. this.clippingPlanes = [];
  12645. this.localClippingEnabled = false;
  12646. // physically based shading
  12647. this.gammaFactor = 2.0; // for backwards compatibility
  12648. this.gammaInput = false;
  12649. this.gammaOutput = false;
  12650. // physical lights
  12651. this.physicallyCorrectLights = false;
  12652. // tone mapping
  12653. this.toneMapping = LinearToneMapping;
  12654. this.toneMappingExposure = 1.0;
  12655. this.toneMappingWhitePoint = 1.0;
  12656. // morphs
  12657. this.maxMorphTargets = 8;
  12658. this.maxMorphNormals = 4;
  12659. // internal properties
  12660. var _this = this,
  12661. _isContextLost = false,
  12662. // internal state cache
  12663. _currentRenderTarget = null,
  12664. _currentFramebuffer = null,
  12665. _currentMaterialId = - 1,
  12666. _currentGeometryProgram = '',
  12667. _currentCamera = null,
  12668. _currentArrayCamera = null,
  12669. _currentViewport = new Vector4(),
  12670. _currentScissor = new Vector4(),
  12671. _currentScissorTest = null,
  12672. //
  12673. _usedTextureUnits = 0,
  12674. //
  12675. _width = _canvas.width,
  12676. _height = _canvas.height,
  12677. _pixelRatio = 1,
  12678. _viewport = new Vector4( 0, 0, _width, _height ),
  12679. _scissor = new Vector4( 0, 0, _width, _height ),
  12680. _scissorTest = false,
  12681. // frustum
  12682. _frustum = new Frustum(),
  12683. // clipping
  12684. _clipping = new WebGLClipping(),
  12685. _clippingEnabled = false,
  12686. _localClippingEnabled = false,
  12687. // camera matrices cache
  12688. _projScreenMatrix = new Matrix4(),
  12689. _vector3 = new Vector3();
  12690. function getTargetPixelRatio() {
  12691. return _currentRenderTarget === null ? _pixelRatio : 1;
  12692. }
  12693. // initialize
  12694. var _gl;
  12695. try {
  12696. var contextAttributes = {
  12697. alpha: _alpha,
  12698. depth: _depth,
  12699. stencil: _stencil,
  12700. antialias: _antialias,
  12701. premultipliedAlpha: _premultipliedAlpha,
  12702. preserveDrawingBuffer: _preserveDrawingBuffer,
  12703. powerPreference: _powerPreference
  12704. };
  12705. // event listeners must be registered before WebGL context is created, see #12753
  12706. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  12707. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  12708. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  12709. if ( _gl === null ) {
  12710. if ( _canvas.getContext( 'webgl' ) !== null ) {
  12711. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  12712. } else {
  12713. throw new Error( 'Error creating WebGL context.' );
  12714. }
  12715. }
  12716. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  12717. if ( _gl.getShaderPrecisionFormat === undefined ) {
  12718. _gl.getShaderPrecisionFormat = function () {
  12719. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  12720. };
  12721. }
  12722. } catch ( error ) {
  12723. console.error( 'THREE.WebGLRenderer: ' + error.message );
  12724. }
  12725. var extensions, capabilities, state, info;
  12726. var properties, textures, attributes, geometries, objects;
  12727. var programCache, renderLists, renderStates;
  12728. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  12729. var spriteRenderer;
  12730. var utils;
  12731. function initGLContext() {
  12732. extensions = new WebGLExtensions( _gl );
  12733. extensions.get( 'WEBGL_depth_texture' );
  12734. extensions.get( 'OES_texture_float' );
  12735. extensions.get( 'OES_texture_float_linear' );
  12736. extensions.get( 'OES_texture_half_float' );
  12737. extensions.get( 'OES_texture_half_float_linear' );
  12738. extensions.get( 'OES_standard_derivatives' );
  12739. extensions.get( 'OES_element_index_uint' );
  12740. extensions.get( 'ANGLE_instanced_arrays' );
  12741. utils = new WebGLUtils( _gl, extensions );
  12742. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  12743. state = new WebGLState( _gl, extensions, utils );
  12744. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  12745. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  12746. info = new WebGLInfo( _gl );
  12747. properties = new WebGLProperties();
  12748. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  12749. attributes = new WebGLAttributes( _gl );
  12750. geometries = new WebGLGeometries( _gl, attributes, info );
  12751. objects = new WebGLObjects( geometries, info );
  12752. morphtargets = new WebGLMorphtargets( _gl );
  12753. programCache = new WebGLPrograms( _this, extensions, capabilities );
  12754. renderLists = new WebGLRenderLists();
  12755. renderStates = new WebGLRenderStates();
  12756. background = new WebGLBackground( _this, state, geometries, _premultipliedAlpha );
  12757. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info );
  12758. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info );
  12759. spriteRenderer = new WebGLSpriteRenderer( _this, _gl, state, textures, capabilities );
  12760. info.programs = programCache.programs;
  12761. _this.context = _gl;
  12762. _this.capabilities = capabilities;
  12763. _this.extensions = extensions;
  12764. _this.properties = properties;
  12765. _this.renderLists = renderLists;
  12766. _this.state = state;
  12767. _this.info = info;
  12768. }
  12769. initGLContext();
  12770. // vr
  12771. var vr = new WebVRManager( _this );
  12772. this.vr = vr;
  12773. // shadow map
  12774. var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  12775. this.shadowMap = shadowMap;
  12776. // API
  12777. this.getContext = function () {
  12778. return _gl;
  12779. };
  12780. this.getContextAttributes = function () {
  12781. return _gl.getContextAttributes();
  12782. };
  12783. this.forceContextLoss = function () {
  12784. var extension = extensions.get( 'WEBGL_lose_context' );
  12785. if ( extension ) extension.loseContext();
  12786. };
  12787. this.forceContextRestore = function () {
  12788. var extension = extensions.get( 'WEBGL_lose_context' );
  12789. if ( extension ) extension.restoreContext();
  12790. };
  12791. this.getPixelRatio = function () {
  12792. return _pixelRatio;
  12793. };
  12794. this.setPixelRatio = function ( value ) {
  12795. if ( value === undefined ) return;
  12796. _pixelRatio = value;
  12797. this.setSize( _width, _height, false );
  12798. };
  12799. this.getSize = function () {
  12800. return {
  12801. width: _width,
  12802. height: _height
  12803. };
  12804. };
  12805. this.setSize = function ( width, height, updateStyle ) {
  12806. var device = vr.getDevice();
  12807. if ( device && device.isPresenting ) {
  12808. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  12809. return;
  12810. }
  12811. _width = width;
  12812. _height = height;
  12813. _canvas.width = width * _pixelRatio;
  12814. _canvas.height = height * _pixelRatio;
  12815. if ( updateStyle !== false ) {
  12816. _canvas.style.width = width + 'px';
  12817. _canvas.style.height = height + 'px';
  12818. }
  12819. this.setViewport( 0, 0, width, height );
  12820. };
  12821. this.getDrawingBufferSize = function () {
  12822. return {
  12823. width: _width * _pixelRatio,
  12824. height: _height * _pixelRatio
  12825. };
  12826. };
  12827. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  12828. _width = width;
  12829. _height = height;
  12830. _pixelRatio = pixelRatio;
  12831. _canvas.width = width * pixelRatio;
  12832. _canvas.height = height * pixelRatio;
  12833. this.setViewport( 0, 0, width, height );
  12834. };
  12835. this.getCurrentViewport = function () {
  12836. return _currentViewport;
  12837. };
  12838. this.setViewport = function ( x, y, width, height ) {
  12839. _viewport.set( x, _height - y - height, width, height );
  12840. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  12841. };
  12842. this.setScissor = function ( x, y, width, height ) {
  12843. _scissor.set( x, _height - y - height, width, height );
  12844. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  12845. };
  12846. this.setScissorTest = function ( boolean ) {
  12847. state.setScissorTest( _scissorTest = boolean );
  12848. };
  12849. // Clearing
  12850. this.getClearColor = function () {
  12851. return background.getClearColor();
  12852. };
  12853. this.setClearColor = function () {
  12854. background.setClearColor.apply( background, arguments );
  12855. };
  12856. this.getClearAlpha = function () {
  12857. return background.getClearAlpha();
  12858. };
  12859. this.setClearAlpha = function () {
  12860. background.setClearAlpha.apply( background, arguments );
  12861. };
  12862. this.clear = function ( color, depth, stencil ) {
  12863. var bits = 0;
  12864. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  12865. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  12866. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  12867. _gl.clear( bits );
  12868. };
  12869. this.clearColor = function () {
  12870. this.clear( true, false, false );
  12871. };
  12872. this.clearDepth = function () {
  12873. this.clear( false, true, false );
  12874. };
  12875. this.clearStencil = function () {
  12876. this.clear( false, false, true );
  12877. };
  12878. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  12879. this.setRenderTarget( renderTarget );
  12880. this.clear( color, depth, stencil );
  12881. };
  12882. //
  12883. this.dispose = function () {
  12884. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  12885. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  12886. renderLists.dispose();
  12887. renderStates.dispose();
  12888. properties.dispose();
  12889. objects.dispose();
  12890. vr.dispose();
  12891. stopAnimation();
  12892. };
  12893. // Events
  12894. function onContextLost( event ) {
  12895. event.preventDefault();
  12896. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  12897. _isContextLost = true;
  12898. }
  12899. function onContextRestore( /* event */ ) {
  12900. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  12901. _isContextLost = false;
  12902. initGLContext();
  12903. }
  12904. function onMaterialDispose( event ) {
  12905. var material = event.target;
  12906. material.removeEventListener( 'dispose', onMaterialDispose );
  12907. deallocateMaterial( material );
  12908. }
  12909. // Buffer deallocation
  12910. function deallocateMaterial( material ) {
  12911. releaseMaterialProgramReference( material );
  12912. properties.remove( material );
  12913. }
  12914. function releaseMaterialProgramReference( material ) {
  12915. var programInfo = properties.get( material ).program;
  12916. material.program = undefined;
  12917. if ( programInfo !== undefined ) {
  12918. programCache.releaseProgram( programInfo );
  12919. }
  12920. }
  12921. // Buffer rendering
  12922. function renderObjectImmediate( object, program, material ) {
  12923. object.render( function ( object ) {
  12924. _this.renderBufferImmediate( object, program, material );
  12925. } );
  12926. }
  12927. this.renderBufferImmediate = function ( object, program, material ) {
  12928. state.initAttributes();
  12929. var buffers = properties.get( object );
  12930. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  12931. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  12932. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  12933. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  12934. var programAttributes = program.getAttributes();
  12935. if ( object.hasPositions ) {
  12936. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  12937. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  12938. state.enableAttribute( programAttributes.position );
  12939. _gl.vertexAttribPointer( programAttributes.position, 3, _gl.FLOAT, false, 0, 0 );
  12940. }
  12941. if ( object.hasNormals ) {
  12942. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  12943. if ( ! material.isMeshPhongMaterial &&
  12944. ! material.isMeshStandardMaterial &&
  12945. ! material.isMeshNormalMaterial &&
  12946. material.flatShading === true ) {
  12947. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  12948. var array = object.normalArray;
  12949. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  12950. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  12951. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  12952. array[ i + 0 ] = nx;
  12953. array[ i + 1 ] = ny;
  12954. array[ i + 2 ] = nz;
  12955. array[ i + 3 ] = nx;
  12956. array[ i + 4 ] = ny;
  12957. array[ i + 5 ] = nz;
  12958. array[ i + 6 ] = nx;
  12959. array[ i + 7 ] = ny;
  12960. array[ i + 8 ] = nz;
  12961. }
  12962. }
  12963. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  12964. state.enableAttribute( programAttributes.normal );
  12965. _gl.vertexAttribPointer( programAttributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  12966. }
  12967. if ( object.hasUvs && material.map ) {
  12968. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  12969. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  12970. state.enableAttribute( programAttributes.uv );
  12971. _gl.vertexAttribPointer( programAttributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  12972. }
  12973. if ( object.hasColors && material.vertexColors !== NoColors ) {
  12974. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  12975. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  12976. state.enableAttribute( programAttributes.color );
  12977. _gl.vertexAttribPointer( programAttributes.color, 3, _gl.FLOAT, false, 0, 0 );
  12978. }
  12979. state.disableUnusedAttributes();
  12980. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  12981. object.count = 0;
  12982. };
  12983. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  12984. var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  12985. state.setMaterial( material, frontFaceCW );
  12986. var program = setProgram( camera, fog, material, object );
  12987. var geometryProgram = geometry.id + '_' + program.id + '_' + ( material.wireframe === true );
  12988. var updateBuffers = false;
  12989. if ( geometryProgram !== _currentGeometryProgram ) {
  12990. _currentGeometryProgram = geometryProgram;
  12991. updateBuffers = true;
  12992. }
  12993. if ( object.morphTargetInfluences ) {
  12994. morphtargets.update( object, geometry, material, program );
  12995. updateBuffers = true;
  12996. }
  12997. //
  12998. var index = geometry.index;
  12999. var position = geometry.attributes.position;
  13000. var rangeFactor = 1;
  13001. if ( material.wireframe === true ) {
  13002. index = geometries.getWireframeAttribute( geometry );
  13003. rangeFactor = 2;
  13004. }
  13005. var attribute;
  13006. var renderer = bufferRenderer;
  13007. if ( index !== null ) {
  13008. attribute = attributes.get( index );
  13009. renderer = indexedBufferRenderer;
  13010. renderer.setIndex( attribute );
  13011. }
  13012. if ( updateBuffers ) {
  13013. setupVertexAttributes( material, program, geometry );
  13014. if ( index !== null ) {
  13015. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, attribute.buffer );
  13016. }
  13017. }
  13018. //
  13019. var dataCount = Infinity;
  13020. if ( index !== null ) {
  13021. dataCount = index.count;
  13022. } else if ( position !== undefined ) {
  13023. dataCount = position.count;
  13024. }
  13025. var rangeStart = geometry.drawRange.start * rangeFactor;
  13026. var rangeCount = geometry.drawRange.count * rangeFactor;
  13027. var groupStart = group !== null ? group.start * rangeFactor : 0;
  13028. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  13029. var drawStart = Math.max( rangeStart, groupStart );
  13030. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  13031. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  13032. if ( drawCount === 0 ) return;
  13033. //
  13034. if ( object.isMesh ) {
  13035. if ( material.wireframe === true ) {
  13036. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  13037. renderer.setMode( _gl.LINES );
  13038. } else {
  13039. switch ( object.drawMode ) {
  13040. case TrianglesDrawMode:
  13041. renderer.setMode( _gl.TRIANGLES );
  13042. break;
  13043. case TriangleStripDrawMode:
  13044. renderer.setMode( _gl.TRIANGLE_STRIP );
  13045. break;
  13046. case TriangleFanDrawMode:
  13047. renderer.setMode( _gl.TRIANGLE_FAN );
  13048. break;
  13049. }
  13050. }
  13051. } else if ( object.isLine ) {
  13052. var lineWidth = material.linewidth;
  13053. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  13054. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  13055. if ( object.isLineSegments ) {
  13056. renderer.setMode( _gl.LINES );
  13057. } else if ( object.isLineLoop ) {
  13058. renderer.setMode( _gl.LINE_LOOP );
  13059. } else {
  13060. renderer.setMode( _gl.LINE_STRIP );
  13061. }
  13062. } else if ( object.isPoints ) {
  13063. renderer.setMode( _gl.POINTS );
  13064. }
  13065. if ( geometry && geometry.isInstancedBufferGeometry ) {
  13066. if ( geometry.maxInstancedCount > 0 ) {
  13067. renderer.renderInstances( geometry, drawStart, drawCount );
  13068. }
  13069. } else {
  13070. renderer.render( drawStart, drawCount );
  13071. }
  13072. };
  13073. function setupVertexAttributes( material, program, geometry ) {
  13074. if ( geometry && geometry.isInstancedBufferGeometry ) {
  13075. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
  13076. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  13077. return;
  13078. }
  13079. }
  13080. state.initAttributes();
  13081. var geometryAttributes = geometry.attributes;
  13082. var programAttributes = program.getAttributes();
  13083. var materialDefaultAttributeValues = material.defaultAttributeValues;
  13084. for ( var name in programAttributes ) {
  13085. var programAttribute = programAttributes[ name ];
  13086. if ( programAttribute >= 0 ) {
  13087. var geometryAttribute = geometryAttributes[ name ];
  13088. if ( geometryAttribute !== undefined ) {
  13089. var normalized = geometryAttribute.normalized;
  13090. var size = geometryAttribute.itemSize;
  13091. var attribute = attributes.get( geometryAttribute );
  13092. // TODO Attribute may not be available on context restore
  13093. if ( attribute === undefined ) continue;
  13094. var buffer = attribute.buffer;
  13095. var type = attribute.type;
  13096. var bytesPerElement = attribute.bytesPerElement;
  13097. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  13098. var data = geometryAttribute.data;
  13099. var stride = data.stride;
  13100. var offset = geometryAttribute.offset;
  13101. if ( data && data.isInstancedInterleavedBuffer ) {
  13102. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  13103. if ( geometry.maxInstancedCount === undefined ) {
  13104. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  13105. }
  13106. } else {
  13107. state.enableAttribute( programAttribute );
  13108. }
  13109. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  13110. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
  13111. } else {
  13112. if ( geometryAttribute.isInstancedBufferAttribute ) {
  13113. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  13114. if ( geometry.maxInstancedCount === undefined ) {
  13115. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  13116. }
  13117. } else {
  13118. state.enableAttribute( programAttribute );
  13119. }
  13120. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  13121. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
  13122. }
  13123. } else if ( materialDefaultAttributeValues !== undefined ) {
  13124. var value = materialDefaultAttributeValues[ name ];
  13125. if ( value !== undefined ) {
  13126. switch ( value.length ) {
  13127. case 2:
  13128. _gl.vertexAttrib2fv( programAttribute, value );
  13129. break;
  13130. case 3:
  13131. _gl.vertexAttrib3fv( programAttribute, value );
  13132. break;
  13133. case 4:
  13134. _gl.vertexAttrib4fv( programAttribute, value );
  13135. break;
  13136. default:
  13137. _gl.vertexAttrib1fv( programAttribute, value );
  13138. }
  13139. }
  13140. }
  13141. }
  13142. }
  13143. state.disableUnusedAttributes();
  13144. }
  13145. // Compile
  13146. this.compile = function ( scene, camera ) {
  13147. currentRenderState = renderStates.get( scene, camera );
  13148. currentRenderState.init();
  13149. scene.traverse( function ( object ) {
  13150. if ( object.isLight ) {
  13151. currentRenderState.pushLight( object );
  13152. if ( object.castShadow ) {
  13153. currentRenderState.pushShadow( object );
  13154. }
  13155. }
  13156. } );
  13157. currentRenderState.setupLights( camera );
  13158. scene.traverse( function ( object ) {
  13159. if ( object.material ) {
  13160. if ( Array.isArray( object.material ) ) {
  13161. for ( var i = 0; i < object.material.length; i ++ ) {
  13162. initMaterial( object.material[ i ], scene.fog, object );
  13163. }
  13164. } else {
  13165. initMaterial( object.material, scene.fog, object );
  13166. }
  13167. }
  13168. } );
  13169. };
  13170. // Animation Loop
  13171. var isAnimating = false;
  13172. var onAnimationFrame = null;
  13173. function startAnimation() {
  13174. if ( isAnimating ) return;
  13175. requestAnimationLoopFrame();
  13176. isAnimating = true;
  13177. }
  13178. function stopAnimation() {
  13179. isAnimating = false;
  13180. }
  13181. function requestAnimationLoopFrame() {
  13182. var device = vr.getDevice();
  13183. if ( device && device.isPresenting ) {
  13184. device.requestAnimationFrame( animationLoop );
  13185. } else {
  13186. window.requestAnimationFrame( animationLoop );
  13187. }
  13188. }
  13189. function animationLoop( time ) {
  13190. if ( isAnimating === false ) return;
  13191. onAnimationFrame( time );
  13192. requestAnimationLoopFrame();
  13193. }
  13194. this.animate = function ( callback ) {
  13195. onAnimationFrame = callback;
  13196. onAnimationFrame !== null ? startAnimation() : stopAnimation();
  13197. };
  13198. // Rendering
  13199. this.render = function ( scene, camera, renderTarget, forceClear ) {
  13200. if ( ! ( camera && camera.isCamera ) ) {
  13201. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  13202. return;
  13203. }
  13204. if ( _isContextLost ) return;
  13205. // reset caching for this frame
  13206. _currentGeometryProgram = '';
  13207. _currentMaterialId = - 1;
  13208. _currentCamera = null;
  13209. // update scene graph
  13210. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  13211. // update camera matrices and frustum
  13212. if ( camera.parent === null ) camera.updateMatrixWorld();
  13213. if ( vr.enabled ) {
  13214. camera = vr.getCamera( camera );
  13215. }
  13216. //
  13217. currentRenderState = renderStates.get( scene, camera );
  13218. currentRenderState.init();
  13219. scene.onBeforeRender( _this, scene, camera, renderTarget );
  13220. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  13221. _frustum.setFromMatrix( _projScreenMatrix );
  13222. _localClippingEnabled = this.localClippingEnabled;
  13223. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  13224. currentRenderList = renderLists.get( scene, camera );
  13225. currentRenderList.init();
  13226. projectObject( scene, camera, _this.sortObjects );
  13227. if ( _this.sortObjects === true ) {
  13228. currentRenderList.sort();
  13229. }
  13230. //
  13231. if ( _clippingEnabled ) _clipping.beginShadows();
  13232. var shadowsArray = currentRenderState.state.shadowsArray;
  13233. shadowMap.render( shadowsArray, scene, camera );
  13234. currentRenderState.setupLights( camera );
  13235. if ( _clippingEnabled ) _clipping.endShadows();
  13236. //
  13237. if ( this.info.autoReset ) this.info.reset();
  13238. if ( renderTarget === undefined ) {
  13239. renderTarget = null;
  13240. }
  13241. this.setRenderTarget( renderTarget );
  13242. //
  13243. background.render( currentRenderList, scene, camera, forceClear );
  13244. // render scene
  13245. var opaqueObjects = currentRenderList.opaque;
  13246. var transparentObjects = currentRenderList.transparent;
  13247. if ( scene.overrideMaterial ) {
  13248. var overrideMaterial = scene.overrideMaterial;
  13249. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  13250. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  13251. } else {
  13252. // opaque pass (front-to-back order)
  13253. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  13254. // transparent pass (back-to-front order)
  13255. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  13256. }
  13257. // custom renderers
  13258. var spritesArray = currentRenderState.state.spritesArray;
  13259. spriteRenderer.render( spritesArray, scene, camera );
  13260. // Generate mipmap if we're using any kind of mipmap filtering
  13261. if ( renderTarget ) {
  13262. textures.updateRenderTargetMipmap( renderTarget );
  13263. }
  13264. // Ensure depth buffer writing is enabled so it can be cleared on next render
  13265. state.buffers.depth.setTest( true );
  13266. state.buffers.depth.setMask( true );
  13267. state.buffers.color.setMask( true );
  13268. state.setPolygonOffset( false );
  13269. scene.onAfterRender( _this, scene, camera );
  13270. if ( vr.enabled ) {
  13271. vr.submitFrame();
  13272. }
  13273. // _gl.finish();
  13274. currentRenderList = null;
  13275. currentRenderState = null;
  13276. };
  13277. /*
  13278. // TODO Duplicated code (Frustum)
  13279. var _sphere = new Sphere();
  13280. function isObjectViewable( object ) {
  13281. var geometry = object.geometry;
  13282. if ( geometry.boundingSphere === null )
  13283. geometry.computeBoundingSphere();
  13284. _sphere.copy( geometry.boundingSphere ).
  13285. applyMatrix4( object.matrixWorld );
  13286. return isSphereViewable( _sphere );
  13287. }
  13288. function isSpriteViewable( sprite ) {
  13289. _sphere.center.set( 0, 0, 0 );
  13290. _sphere.radius = 0.7071067811865476;
  13291. _sphere.applyMatrix4( sprite.matrixWorld );
  13292. return isSphereViewable( _sphere );
  13293. }
  13294. function isSphereViewable( sphere ) {
  13295. if ( ! _frustum.intersectsSphere( sphere ) ) return false;
  13296. var numPlanes = _clipping.numPlanes;
  13297. if ( numPlanes === 0 ) return true;
  13298. var planes = _this.clippingPlanes,
  13299. center = sphere.center,
  13300. negRad = - sphere.radius,
  13301. i = 0;
  13302. do {
  13303. // out when deeper than radius in the negative halfspace
  13304. if ( planes[ i ].distanceToPoint( center ) < negRad ) return false;
  13305. } while ( ++ i !== numPlanes );
  13306. return true;
  13307. }
  13308. */
  13309. function projectObject( object, camera, sortObjects ) {
  13310. if ( object.visible === false ) return;
  13311. var visible = object.layers.test( camera.layers );
  13312. if ( visible ) {
  13313. if ( object.isLight ) {
  13314. currentRenderState.pushLight( object );
  13315. if ( object.castShadow ) {
  13316. currentRenderState.pushShadow( object );
  13317. }
  13318. } else if ( object.isSprite ) {
  13319. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  13320. currentRenderState.pushSprite( object );
  13321. }
  13322. } else if ( object.isImmediateRenderObject ) {
  13323. if ( sortObjects ) {
  13324. _vector3.setFromMatrixPosition( object.matrixWorld )
  13325. .applyMatrix4( _projScreenMatrix );
  13326. }
  13327. currentRenderList.push( object, null, object.material, _vector3.z, null );
  13328. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  13329. if ( object.isSkinnedMesh ) {
  13330. object.skeleton.update();
  13331. }
  13332. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  13333. if ( sortObjects ) {
  13334. _vector3.setFromMatrixPosition( object.matrixWorld )
  13335. .applyMatrix4( _projScreenMatrix );
  13336. }
  13337. var geometry = objects.update( object );
  13338. var material = object.material;
  13339. if ( Array.isArray( material ) ) {
  13340. var groups = geometry.groups;
  13341. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  13342. var group = groups[ i ];
  13343. var groupMaterial = material[ group.materialIndex ];
  13344. if ( groupMaterial && groupMaterial.visible ) {
  13345. currentRenderList.push( object, geometry, groupMaterial, _vector3.z, group );
  13346. }
  13347. }
  13348. } else if ( material.visible ) {
  13349. currentRenderList.push( object, geometry, material, _vector3.z, null );
  13350. }
  13351. }
  13352. }
  13353. }
  13354. var children = object.children;
  13355. for ( var i = 0, l = children.length; i < l; i ++ ) {
  13356. projectObject( children[ i ], camera, sortObjects );
  13357. }
  13358. }
  13359. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  13360. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  13361. var renderItem = renderList[ i ];
  13362. var object = renderItem.object;
  13363. var geometry = renderItem.geometry;
  13364. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  13365. var group = renderItem.group;
  13366. if ( camera.isArrayCamera ) {
  13367. _currentArrayCamera = camera;
  13368. var cameras = camera.cameras;
  13369. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  13370. var camera2 = cameras[ j ];
  13371. if ( object.layers.test( camera2.layers ) ) {
  13372. var bounds = camera2.bounds;
  13373. var x = bounds.x * _width;
  13374. var y = bounds.y * _height;
  13375. var width = bounds.z * _width;
  13376. var height = bounds.w * _height;
  13377. state.viewport( _currentViewport.set( x, y, width, height ).multiplyScalar( _pixelRatio ) );
  13378. renderObject( object, scene, camera2, geometry, material, group );
  13379. }
  13380. }
  13381. } else {
  13382. _currentArrayCamera = null;
  13383. renderObject( object, scene, camera, geometry, material, group );
  13384. }
  13385. }
  13386. }
  13387. function renderObject( object, scene, camera, geometry, material, group ) {
  13388. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  13389. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  13390. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  13391. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  13392. if ( object.isImmediateRenderObject ) {
  13393. var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  13394. state.setMaterial( material, frontFaceCW );
  13395. var program = setProgram( camera, scene.fog, material, object );
  13396. _currentGeometryProgram = '';
  13397. renderObjectImmediate( object, program, material );
  13398. } else {
  13399. _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
  13400. }
  13401. object.onAfterRender( _this, scene, camera, geometry, material, group );
  13402. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  13403. }
  13404. function initMaterial( material, fog, object ) {
  13405. var materialProperties = properties.get( material );
  13406. var lights = currentRenderState.state.lights;
  13407. var shadowsArray = currentRenderState.state.shadowsArray;
  13408. var parameters = programCache.getParameters(
  13409. material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );
  13410. var code = programCache.getProgramCode( material, parameters );
  13411. var program = materialProperties.program;
  13412. var programChange = true;
  13413. if ( program === undefined ) {
  13414. // new material
  13415. material.addEventListener( 'dispose', onMaterialDispose );
  13416. } else if ( program.code !== code ) {
  13417. // changed glsl or parameters
  13418. releaseMaterialProgramReference( material );
  13419. } else if ( materialProperties.lightsHash !== lights.state.hash ) {
  13420. properties.update( material, 'lightsHash', lights.state.hash );
  13421. programChange = false;
  13422. } else if ( parameters.shaderID !== undefined ) {
  13423. // same glsl and uniform list
  13424. return;
  13425. } else {
  13426. // only rebuild uniform list
  13427. programChange = false;
  13428. }
  13429. if ( programChange ) {
  13430. if ( parameters.shaderID ) {
  13431. var shader = ShaderLib[ parameters.shaderID ];
  13432. materialProperties.shader = {
  13433. name: material.type,
  13434. uniforms: UniformsUtils.clone( shader.uniforms ),
  13435. vertexShader: shader.vertexShader,
  13436. fragmentShader: shader.fragmentShader
  13437. };
  13438. } else {
  13439. materialProperties.shader = {
  13440. name: material.type,
  13441. uniforms: material.uniforms,
  13442. vertexShader: material.vertexShader,
  13443. fragmentShader: material.fragmentShader
  13444. };
  13445. }
  13446. material.onBeforeCompile( materialProperties.shader, _this );
  13447. program = programCache.acquireProgram( material, materialProperties.shader, parameters, code );
  13448. materialProperties.program = program;
  13449. material.program = program;
  13450. }
  13451. var programAttributes = program.getAttributes();
  13452. if ( material.morphTargets ) {
  13453. material.numSupportedMorphTargets = 0;
  13454. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  13455. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  13456. material.numSupportedMorphTargets ++;
  13457. }
  13458. }
  13459. }
  13460. if ( material.morphNormals ) {
  13461. material.numSupportedMorphNormals = 0;
  13462. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  13463. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  13464. material.numSupportedMorphNormals ++;
  13465. }
  13466. }
  13467. }
  13468. var uniforms = materialProperties.shader.uniforms;
  13469. if ( ! material.isShaderMaterial &&
  13470. ! material.isRawShaderMaterial ||
  13471. material.clipping === true ) {
  13472. materialProperties.numClippingPlanes = _clipping.numPlanes;
  13473. materialProperties.numIntersection = _clipping.numIntersection;
  13474. uniforms.clippingPlanes = _clipping.uniform;
  13475. }
  13476. materialProperties.fog = fog;
  13477. // store the light setup it was created for
  13478. materialProperties.lightsHash = lights.state.hash;
  13479. if ( material.lights ) {
  13480. // wire up the material to this renderer's lighting state
  13481. uniforms.ambientLightColor.value = lights.state.ambient;
  13482. uniforms.directionalLights.value = lights.state.directional;
  13483. uniforms.spotLights.value = lights.state.spot;
  13484. uniforms.rectAreaLights.value = lights.state.rectArea;
  13485. uniforms.pointLights.value = lights.state.point;
  13486. uniforms.hemisphereLights.value = lights.state.hemi;
  13487. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  13488. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  13489. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  13490. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  13491. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  13492. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  13493. // TODO (abelnation): add area lights shadow info to uniforms
  13494. }
  13495. var progUniforms = materialProperties.program.getUniforms(),
  13496. uniformsList =
  13497. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  13498. materialProperties.uniformsList = uniformsList;
  13499. }
  13500. function setProgram( camera, fog, material, object ) {
  13501. _usedTextureUnits = 0;
  13502. var materialProperties = properties.get( material );
  13503. var lights = currentRenderState.state.lights;
  13504. if ( _clippingEnabled ) {
  13505. if ( _localClippingEnabled || camera !== _currentCamera ) {
  13506. var useCache =
  13507. camera === _currentCamera &&
  13508. material.id === _currentMaterialId;
  13509. // we might want to call this function with some ClippingGroup
  13510. // object instead of the material, once it becomes feasible
  13511. // (#8465, #8379)
  13512. _clipping.setState(
  13513. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  13514. camera, materialProperties, useCache );
  13515. }
  13516. }
  13517. if ( material.needsUpdate === false ) {
  13518. if ( materialProperties.program === undefined ) {
  13519. material.needsUpdate = true;
  13520. } else if ( material.fog && materialProperties.fog !== fog ) {
  13521. material.needsUpdate = true;
  13522. } else if ( material.lights && materialProperties.lightsHash !== lights.state.hash ) {
  13523. material.needsUpdate = true;
  13524. } else if ( materialProperties.numClippingPlanes !== undefined &&
  13525. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  13526. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  13527. material.needsUpdate = true;
  13528. }
  13529. }
  13530. if ( material.needsUpdate ) {
  13531. initMaterial( material, fog, object );
  13532. material.needsUpdate = false;
  13533. }
  13534. var refreshProgram = false;
  13535. var refreshMaterial = false;
  13536. var refreshLights = false;
  13537. var program = materialProperties.program,
  13538. p_uniforms = program.getUniforms(),
  13539. m_uniforms = materialProperties.shader.uniforms;
  13540. if ( state.useProgram( program.program ) ) {
  13541. refreshProgram = true;
  13542. refreshMaterial = true;
  13543. refreshLights = true;
  13544. }
  13545. if ( material.id !== _currentMaterialId ) {
  13546. _currentMaterialId = material.id;
  13547. refreshMaterial = true;
  13548. }
  13549. if ( refreshProgram || camera !== _currentCamera ) {
  13550. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  13551. if ( capabilities.logarithmicDepthBuffer ) {
  13552. p_uniforms.setValue( _gl, 'logDepthBufFC',
  13553. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  13554. }
  13555. // Avoid unneeded uniform updates per ArrayCamera's sub-camera
  13556. if ( _currentCamera !== ( _currentArrayCamera || camera ) ) {
  13557. _currentCamera = ( _currentArrayCamera || camera );
  13558. // lighting uniforms depend on the camera so enforce an update
  13559. // now, in case this material supports lights - or later, when
  13560. // the next material that does gets activated:
  13561. refreshMaterial = true; // set to true on material change
  13562. refreshLights = true; // remains set until update done
  13563. }
  13564. // load material specific uniforms
  13565. // (shader material also gets them for the sake of genericity)
  13566. if ( material.isShaderMaterial ||
  13567. material.isMeshPhongMaterial ||
  13568. material.isMeshStandardMaterial ||
  13569. material.envMap ) {
  13570. var uCamPos = p_uniforms.map.cameraPosition;
  13571. if ( uCamPos !== undefined ) {
  13572. uCamPos.setValue( _gl,
  13573. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  13574. }
  13575. }
  13576. if ( material.isMeshPhongMaterial ||
  13577. material.isMeshLambertMaterial ||
  13578. material.isMeshBasicMaterial ||
  13579. material.isMeshStandardMaterial ||
  13580. material.isShaderMaterial ||
  13581. material.skinning ) {
  13582. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  13583. }
  13584. }
  13585. // skinning uniforms must be set even if material didn't change
  13586. // auto-setting of texture unit for bone texture must go before other textures
  13587. // not sure why, but otherwise weird things happen
  13588. if ( material.skinning ) {
  13589. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  13590. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  13591. var skeleton = object.skeleton;
  13592. if ( skeleton ) {
  13593. var bones = skeleton.bones;
  13594. if ( capabilities.floatVertexTextures ) {
  13595. if ( skeleton.boneTexture === undefined ) {
  13596. // layout (1 matrix = 4 pixels)
  13597. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  13598. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  13599. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  13600. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  13601. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  13602. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  13603. size = _Math.ceilPowerOfTwo( size );
  13604. size = Math.max( size, 4 );
  13605. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  13606. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  13607. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  13608. boneTexture.needsUpdate = true;
  13609. skeleton.boneMatrices = boneMatrices;
  13610. skeleton.boneTexture = boneTexture;
  13611. skeleton.boneTextureSize = size;
  13612. }
  13613. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture );
  13614. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  13615. } else {
  13616. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  13617. }
  13618. }
  13619. }
  13620. if ( refreshMaterial ) {
  13621. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  13622. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  13623. if ( material.lights ) {
  13624. // the current material requires lighting info
  13625. // note: all lighting uniforms are always set correctly
  13626. // they simply reference the renderer's state for their
  13627. // values
  13628. //
  13629. // use the current material's .needsUpdate flags to set
  13630. // the GL state when required
  13631. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  13632. }
  13633. // refresh uniforms common to several materials
  13634. if ( fog && material.fog ) {
  13635. refreshUniformsFog( m_uniforms, fog );
  13636. }
  13637. if ( material.isMeshBasicMaterial ) {
  13638. refreshUniformsCommon( m_uniforms, material );
  13639. } else if ( material.isMeshLambertMaterial ) {
  13640. refreshUniformsCommon( m_uniforms, material );
  13641. refreshUniformsLambert( m_uniforms, material );
  13642. } else if ( material.isMeshPhongMaterial ) {
  13643. refreshUniformsCommon( m_uniforms, material );
  13644. if ( material.isMeshToonMaterial ) {
  13645. refreshUniformsToon( m_uniforms, material );
  13646. } else {
  13647. refreshUniformsPhong( m_uniforms, material );
  13648. }
  13649. } else if ( material.isMeshStandardMaterial ) {
  13650. refreshUniformsCommon( m_uniforms, material );
  13651. if ( material.isMeshPhysicalMaterial ) {
  13652. refreshUniformsPhysical( m_uniforms, material );
  13653. } else {
  13654. refreshUniformsStandard( m_uniforms, material );
  13655. }
  13656. } else if ( material.isMeshDepthMaterial ) {
  13657. refreshUniformsCommon( m_uniforms, material );
  13658. refreshUniformsDepth( m_uniforms, material );
  13659. } else if ( material.isMeshDistanceMaterial ) {
  13660. refreshUniformsCommon( m_uniforms, material );
  13661. refreshUniformsDistance( m_uniforms, material );
  13662. } else if ( material.isMeshNormalMaterial ) {
  13663. refreshUniformsCommon( m_uniforms, material );
  13664. refreshUniformsNormal( m_uniforms, material );
  13665. } else if ( material.isLineBasicMaterial ) {
  13666. refreshUniformsLine( m_uniforms, material );
  13667. if ( material.isLineDashedMaterial ) {
  13668. refreshUniformsDash( m_uniforms, material );
  13669. }
  13670. } else if ( material.isPointsMaterial ) {
  13671. refreshUniformsPoints( m_uniforms, material );
  13672. } else if ( material.isShadowMaterial ) {
  13673. m_uniforms.color.value = material.color;
  13674. m_uniforms.opacity.value = material.opacity;
  13675. }
  13676. // RectAreaLight Texture
  13677. // TODO (mrdoob): Find a nicer implementation
  13678. if ( m_uniforms.ltc_1 !== undefined ) m_uniforms.ltc_1.value = UniformsLib.LTC_1;
  13679. if ( m_uniforms.ltc_2 !== undefined ) m_uniforms.ltc_2.value = UniformsLib.LTC_2;
  13680. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, _this );
  13681. }
  13682. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  13683. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, _this );
  13684. material.uniformsNeedUpdate = false;
  13685. }
  13686. // common matrices
  13687. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  13688. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  13689. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  13690. return program;
  13691. }
  13692. // Uniforms (refresh uniforms objects)
  13693. function refreshUniformsCommon( uniforms, material ) {
  13694. uniforms.opacity.value = material.opacity;
  13695. if ( material.color ) {
  13696. uniforms.diffuse.value = material.color;
  13697. }
  13698. if ( material.emissive ) {
  13699. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  13700. }
  13701. if ( material.map ) {
  13702. uniforms.map.value = material.map;
  13703. }
  13704. if ( material.alphaMap ) {
  13705. uniforms.alphaMap.value = material.alphaMap;
  13706. }
  13707. if ( material.specularMap ) {
  13708. uniforms.specularMap.value = material.specularMap;
  13709. }
  13710. if ( material.envMap ) {
  13711. uniforms.envMap.value = material.envMap;
  13712. // don't flip CubeTexture envMaps, flip everything else:
  13713. // WebGLRenderTargetCube will be flipped for backwards compatibility
  13714. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  13715. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  13716. uniforms.flipEnvMap.value = ( ! ( material.envMap && material.envMap.isCubeTexture ) ) ? 1 : - 1;
  13717. uniforms.reflectivity.value = material.reflectivity;
  13718. uniforms.refractionRatio.value = material.refractionRatio;
  13719. uniforms.maxMipLevel.value = properties.get( material.envMap ).__maxMipLevel;
  13720. }
  13721. if ( material.lightMap ) {
  13722. uniforms.lightMap.value = material.lightMap;
  13723. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  13724. }
  13725. if ( material.aoMap ) {
  13726. uniforms.aoMap.value = material.aoMap;
  13727. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13728. }
  13729. // uv repeat and offset setting priorities
  13730. // 1. color map
  13731. // 2. specular map
  13732. // 3. normal map
  13733. // 4. bump map
  13734. // 5. alpha map
  13735. // 6. emissive map
  13736. var uvScaleMap;
  13737. if ( material.map ) {
  13738. uvScaleMap = material.map;
  13739. } else if ( material.specularMap ) {
  13740. uvScaleMap = material.specularMap;
  13741. } else if ( material.displacementMap ) {
  13742. uvScaleMap = material.displacementMap;
  13743. } else if ( material.normalMap ) {
  13744. uvScaleMap = material.normalMap;
  13745. } else if ( material.bumpMap ) {
  13746. uvScaleMap = material.bumpMap;
  13747. } else if ( material.roughnessMap ) {
  13748. uvScaleMap = material.roughnessMap;
  13749. } else if ( material.metalnessMap ) {
  13750. uvScaleMap = material.metalnessMap;
  13751. } else if ( material.alphaMap ) {
  13752. uvScaleMap = material.alphaMap;
  13753. } else if ( material.emissiveMap ) {
  13754. uvScaleMap = material.emissiveMap;
  13755. }
  13756. if ( uvScaleMap !== undefined ) {
  13757. // backwards compatibility
  13758. if ( uvScaleMap.isWebGLRenderTarget ) {
  13759. uvScaleMap = uvScaleMap.texture;
  13760. }
  13761. if ( uvScaleMap.matrixAutoUpdate === true ) {
  13762. uvScaleMap.updateMatrix();
  13763. }
  13764. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  13765. }
  13766. }
  13767. function refreshUniformsLine( uniforms, material ) {
  13768. uniforms.diffuse.value = material.color;
  13769. uniforms.opacity.value = material.opacity;
  13770. }
  13771. function refreshUniformsDash( uniforms, material ) {
  13772. uniforms.dashSize.value = material.dashSize;
  13773. uniforms.totalSize.value = material.dashSize + material.gapSize;
  13774. uniforms.scale.value = material.scale;
  13775. }
  13776. function refreshUniformsPoints( uniforms, material ) {
  13777. uniforms.diffuse.value = material.color;
  13778. uniforms.opacity.value = material.opacity;
  13779. uniforms.size.value = material.size * _pixelRatio;
  13780. uniforms.scale.value = _height * 0.5;
  13781. uniforms.map.value = material.map;
  13782. if ( material.map !== null ) {
  13783. if ( material.map.matrixAutoUpdate === true ) {
  13784. material.map.updateMatrix();
  13785. }
  13786. uniforms.uvTransform.value.copy( material.map.matrix );
  13787. }
  13788. }
  13789. function refreshUniformsFog( uniforms, fog ) {
  13790. uniforms.fogColor.value = fog.color;
  13791. if ( fog.isFog ) {
  13792. uniforms.fogNear.value = fog.near;
  13793. uniforms.fogFar.value = fog.far;
  13794. } else if ( fog.isFogExp2 ) {
  13795. uniforms.fogDensity.value = fog.density;
  13796. }
  13797. }
  13798. function refreshUniformsLambert( uniforms, material ) {
  13799. if ( material.emissiveMap ) {
  13800. uniforms.emissiveMap.value = material.emissiveMap;
  13801. }
  13802. }
  13803. function refreshUniformsPhong( uniforms, material ) {
  13804. uniforms.specular.value = material.specular;
  13805. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  13806. if ( material.emissiveMap ) {
  13807. uniforms.emissiveMap.value = material.emissiveMap;
  13808. }
  13809. if ( material.bumpMap ) {
  13810. uniforms.bumpMap.value = material.bumpMap;
  13811. uniforms.bumpScale.value = material.bumpScale;
  13812. }
  13813. if ( material.normalMap ) {
  13814. uniforms.normalMap.value = material.normalMap;
  13815. uniforms.normalScale.value.copy( material.normalScale );
  13816. }
  13817. if ( material.displacementMap ) {
  13818. uniforms.displacementMap.value = material.displacementMap;
  13819. uniforms.displacementScale.value = material.displacementScale;
  13820. uniforms.displacementBias.value = material.displacementBias;
  13821. }
  13822. }
  13823. function refreshUniformsToon( uniforms, material ) {
  13824. refreshUniformsPhong( uniforms, material );
  13825. if ( material.gradientMap ) {
  13826. uniforms.gradientMap.value = material.gradientMap;
  13827. }
  13828. }
  13829. function refreshUniformsStandard( uniforms, material ) {
  13830. uniforms.roughness.value = material.roughness;
  13831. uniforms.metalness.value = material.metalness;
  13832. if ( material.roughnessMap ) {
  13833. uniforms.roughnessMap.value = material.roughnessMap;
  13834. }
  13835. if ( material.metalnessMap ) {
  13836. uniforms.metalnessMap.value = material.metalnessMap;
  13837. }
  13838. if ( material.emissiveMap ) {
  13839. uniforms.emissiveMap.value = material.emissiveMap;
  13840. }
  13841. if ( material.bumpMap ) {
  13842. uniforms.bumpMap.value = material.bumpMap;
  13843. uniforms.bumpScale.value = material.bumpScale;
  13844. }
  13845. if ( material.normalMap ) {
  13846. uniforms.normalMap.value = material.normalMap;
  13847. uniforms.normalScale.value.copy( material.normalScale );
  13848. }
  13849. if ( material.displacementMap ) {
  13850. uniforms.displacementMap.value = material.displacementMap;
  13851. uniforms.displacementScale.value = material.displacementScale;
  13852. uniforms.displacementBias.value = material.displacementBias;
  13853. }
  13854. if ( material.envMap ) {
  13855. //uniforms.envMap.value = material.envMap; // part of uniforms common
  13856. uniforms.envMapIntensity.value = material.envMapIntensity;
  13857. }
  13858. }
  13859. function refreshUniformsPhysical( uniforms, material ) {
  13860. uniforms.clearCoat.value = material.clearCoat;
  13861. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  13862. refreshUniformsStandard( uniforms, material );
  13863. }
  13864. function refreshUniformsDepth( uniforms, material ) {
  13865. if ( material.displacementMap ) {
  13866. uniforms.displacementMap.value = material.displacementMap;
  13867. uniforms.displacementScale.value = material.displacementScale;
  13868. uniforms.displacementBias.value = material.displacementBias;
  13869. }
  13870. }
  13871. function refreshUniformsDistance( uniforms, material ) {
  13872. if ( material.displacementMap ) {
  13873. uniforms.displacementMap.value = material.displacementMap;
  13874. uniforms.displacementScale.value = material.displacementScale;
  13875. uniforms.displacementBias.value = material.displacementBias;
  13876. }
  13877. uniforms.referencePosition.value.copy( material.referencePosition );
  13878. uniforms.nearDistance.value = material.nearDistance;
  13879. uniforms.farDistance.value = material.farDistance;
  13880. }
  13881. function refreshUniformsNormal( uniforms, material ) {
  13882. if ( material.bumpMap ) {
  13883. uniforms.bumpMap.value = material.bumpMap;
  13884. uniforms.bumpScale.value = material.bumpScale;
  13885. }
  13886. if ( material.normalMap ) {
  13887. uniforms.normalMap.value = material.normalMap;
  13888. uniforms.normalScale.value.copy( material.normalScale );
  13889. }
  13890. if ( material.displacementMap ) {
  13891. uniforms.displacementMap.value = material.displacementMap;
  13892. uniforms.displacementScale.value = material.displacementScale;
  13893. uniforms.displacementBias.value = material.displacementBias;
  13894. }
  13895. }
  13896. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  13897. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  13898. uniforms.ambientLightColor.needsUpdate = value;
  13899. uniforms.directionalLights.needsUpdate = value;
  13900. uniforms.pointLights.needsUpdate = value;
  13901. uniforms.spotLights.needsUpdate = value;
  13902. uniforms.rectAreaLights.needsUpdate = value;
  13903. uniforms.hemisphereLights.needsUpdate = value;
  13904. }
  13905. // Textures
  13906. function allocTextureUnit() {
  13907. var textureUnit = _usedTextureUnits;
  13908. if ( textureUnit >= capabilities.maxTextures ) {
  13909. console.warn( 'THREE.WebGLRenderer: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  13910. }
  13911. _usedTextureUnits += 1;
  13912. return textureUnit;
  13913. }
  13914. this.allocTextureUnit = allocTextureUnit;
  13915. // this.setTexture2D = setTexture2D;
  13916. this.setTexture2D = ( function () {
  13917. var warned = false;
  13918. // backwards compatibility: peel texture.texture
  13919. return function setTexture2D( texture, slot ) {
  13920. if ( texture && texture.isWebGLRenderTarget ) {
  13921. if ( ! warned ) {
  13922. console.warn( "THREE.WebGLRenderer.setTexture2D: don't use render targets as textures. Use their .texture property instead." );
  13923. warned = true;
  13924. }
  13925. texture = texture.texture;
  13926. }
  13927. textures.setTexture2D( texture, slot );
  13928. };
  13929. }() );
  13930. this.setTexture = ( function () {
  13931. var warned = false;
  13932. return function setTexture( texture, slot ) {
  13933. if ( ! warned ) {
  13934. console.warn( "THREE.WebGLRenderer: .setTexture is deprecated, use setTexture2D instead." );
  13935. warned = true;
  13936. }
  13937. textures.setTexture2D( texture, slot );
  13938. };
  13939. }() );
  13940. this.setTextureCube = ( function () {
  13941. var warned = false;
  13942. return function setTextureCube( texture, slot ) {
  13943. // backwards compatibility: peel texture.texture
  13944. if ( texture && texture.isWebGLRenderTargetCube ) {
  13945. if ( ! warned ) {
  13946. console.warn( "THREE.WebGLRenderer.setTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  13947. warned = true;
  13948. }
  13949. texture = texture.texture;
  13950. }
  13951. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  13952. // TODO: unify these code paths
  13953. if ( ( texture && texture.isCubeTexture ) ||
  13954. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  13955. // CompressedTexture can have Array in image :/
  13956. // this function alone should take care of cube textures
  13957. textures.setTextureCube( texture, slot );
  13958. } else {
  13959. // assumed: texture property of THREE.WebGLRenderTargetCube
  13960. textures.setTextureCubeDynamic( texture, slot );
  13961. }
  13962. };
  13963. }() );
  13964. this.getRenderTarget = function () {
  13965. return _currentRenderTarget;
  13966. };
  13967. this.setRenderTarget = function ( renderTarget ) {
  13968. _currentRenderTarget = renderTarget;
  13969. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  13970. textures.setupRenderTarget( renderTarget );
  13971. }
  13972. var framebuffer = null;
  13973. var isCube = false;
  13974. if ( renderTarget ) {
  13975. var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  13976. if ( renderTarget.isWebGLRenderTargetCube ) {
  13977. framebuffer = __webglFramebuffer[ renderTarget.activeCubeFace ];
  13978. isCube = true;
  13979. } else {
  13980. framebuffer = __webglFramebuffer;
  13981. }
  13982. _currentViewport.copy( renderTarget.viewport );
  13983. _currentScissor.copy( renderTarget.scissor );
  13984. _currentScissorTest = renderTarget.scissorTest;
  13985. } else {
  13986. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  13987. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  13988. _currentScissorTest = _scissorTest;
  13989. }
  13990. if ( _currentFramebuffer !== framebuffer ) {
  13991. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  13992. _currentFramebuffer = framebuffer;
  13993. }
  13994. state.viewport( _currentViewport );
  13995. state.scissor( _currentScissor );
  13996. state.setScissorTest( _currentScissorTest );
  13997. if ( isCube ) {
  13998. var textureProperties = properties.get( renderTarget.texture );
  13999. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, renderTarget.activeMipMapLevel );
  14000. }
  14001. };
  14002. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  14003. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  14004. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  14005. return;
  14006. }
  14007. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14008. if ( framebuffer ) {
  14009. var restore = false;
  14010. if ( framebuffer !== _currentFramebuffer ) {
  14011. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  14012. restore = true;
  14013. }
  14014. try {
  14015. var texture = renderTarget.texture;
  14016. var textureFormat = texture.format;
  14017. var textureType = texture.type;
  14018. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  14019. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  14020. return;
  14021. }
  14022. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  14023. ! ( textureType === FloatType && ( extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  14024. ! ( textureType === HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  14025. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  14026. return;
  14027. }
  14028. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  14029. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  14030. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  14031. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  14032. }
  14033. } else {
  14034. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  14035. }
  14036. } finally {
  14037. if ( restore ) {
  14038. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  14039. }
  14040. }
  14041. }
  14042. };
  14043. this.copyFramebufferToTexture = function ( position, texture, level ) {
  14044. var width = texture.image.width;
  14045. var height = texture.image.height;
  14046. var glFormat = utils.convert( texture.format );
  14047. this.setTexture2D( texture, 0 );
  14048. _gl.copyTexImage2D( _gl.TEXTURE_2D, level || 0, glFormat, position.x, position.y, width, height, 0 );
  14049. };
  14050. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level ) {
  14051. var width = srcTexture.image.width;
  14052. var height = srcTexture.image.height;
  14053. var glFormat = utils.convert( dstTexture.format );
  14054. var glType = utils.convert( dstTexture.type );
  14055. var pixels = srcTexture.isDataTexture ? srcTexture.image.data : srcTexture.image;
  14056. this.setTexture2D( dstTexture, 0 );
  14057. _gl.texSubImage2D( _gl.TEXTURE_2D, level || 0, position.x, position.y, width, height, glFormat, glType, pixels );
  14058. };
  14059. }
  14060. /**
  14061. * @author mrdoob / http://mrdoob.com/
  14062. * @author alteredq / http://alteredqualia.com/
  14063. */
  14064. function FogExp2( color, density ) {
  14065. this.name = '';
  14066. this.color = new Color( color );
  14067. this.density = ( density !== undefined ) ? density : 0.00025;
  14068. }
  14069. FogExp2.prototype.isFogExp2 = true;
  14070. FogExp2.prototype.clone = function () {
  14071. return new FogExp2( this.color.getHex(), this.density );
  14072. };
  14073. FogExp2.prototype.toJSON = function ( /* meta */ ) {
  14074. return {
  14075. type: 'FogExp2',
  14076. color: this.color.getHex(),
  14077. density: this.density
  14078. };
  14079. };
  14080. /**
  14081. * @author mrdoob / http://mrdoob.com/
  14082. * @author alteredq / http://alteredqualia.com/
  14083. */
  14084. function Fog( color, near, far ) {
  14085. this.name = '';
  14086. this.color = new Color( color );
  14087. this.near = ( near !== undefined ) ? near : 1;
  14088. this.far = ( far !== undefined ) ? far : 1000;
  14089. }
  14090. Fog.prototype.isFog = true;
  14091. Fog.prototype.clone = function () {
  14092. return new Fog( this.color.getHex(), this.near, this.far );
  14093. };
  14094. Fog.prototype.toJSON = function ( /* meta */ ) {
  14095. return {
  14096. type: 'Fog',
  14097. color: this.color.getHex(),
  14098. near: this.near,
  14099. far: this.far
  14100. };
  14101. };
  14102. /**
  14103. * @author mrdoob / http://mrdoob.com/
  14104. */
  14105. function Scene() {
  14106. Object3D.call( this );
  14107. this.type = 'Scene';
  14108. this.background = null;
  14109. this.fog = null;
  14110. this.overrideMaterial = null;
  14111. this.autoUpdate = true; // checked by the renderer
  14112. }
  14113. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14114. constructor: Scene,
  14115. copy: function ( source, recursive ) {
  14116. Object3D.prototype.copy.call( this, source, recursive );
  14117. if ( source.background !== null ) this.background = source.background.clone();
  14118. if ( source.fog !== null ) this.fog = source.fog.clone();
  14119. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  14120. this.autoUpdate = source.autoUpdate;
  14121. this.matrixAutoUpdate = source.matrixAutoUpdate;
  14122. return this;
  14123. },
  14124. toJSON: function ( meta ) {
  14125. var data = Object3D.prototype.toJSON.call( this, meta );
  14126. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  14127. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  14128. return data;
  14129. }
  14130. } );
  14131. /**
  14132. * @author alteredq / http://alteredqualia.com/
  14133. *
  14134. * parameters = {
  14135. * color: <hex>,
  14136. * opacity: <float>,
  14137. * map: new THREE.Texture( <Image> ),
  14138. *
  14139. * uvOffset: new THREE.Vector2(),
  14140. * uvScale: new THREE.Vector2()
  14141. * }
  14142. */
  14143. function SpriteMaterial( parameters ) {
  14144. Material.call( this );
  14145. this.type = 'SpriteMaterial';
  14146. this.color = new Color( 0xffffff );
  14147. this.map = null;
  14148. this.rotation = 0;
  14149. this.fog = false;
  14150. this.lights = false;
  14151. this.setValues( parameters );
  14152. }
  14153. SpriteMaterial.prototype = Object.create( Material.prototype );
  14154. SpriteMaterial.prototype.constructor = SpriteMaterial;
  14155. SpriteMaterial.prototype.isSpriteMaterial = true;
  14156. SpriteMaterial.prototype.copy = function ( source ) {
  14157. Material.prototype.copy.call( this, source );
  14158. this.color.copy( source.color );
  14159. this.map = source.map;
  14160. this.rotation = source.rotation;
  14161. return this;
  14162. };
  14163. /**
  14164. * @author mikael emtinger / http://gomo.se/
  14165. * @author alteredq / http://alteredqualia.com/
  14166. */
  14167. function Sprite( material ) {
  14168. Object3D.call( this );
  14169. this.type = 'Sprite';
  14170. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  14171. this.center = new Vector2( 0.5, 0.5 );
  14172. }
  14173. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14174. constructor: Sprite,
  14175. isSprite: true,
  14176. raycast: ( function () {
  14177. var intersectPoint = new Vector3();
  14178. var worldPosition = new Vector3();
  14179. var worldScale = new Vector3();
  14180. return function raycast( raycaster, intersects ) {
  14181. worldPosition.setFromMatrixPosition( this.matrixWorld );
  14182. raycaster.ray.closestPointToPoint( worldPosition, intersectPoint );
  14183. worldScale.setFromMatrixScale( this.matrixWorld );
  14184. var guessSizeSq = worldScale.x * worldScale.y / 4;
  14185. if ( worldPosition.distanceToSquared( intersectPoint ) > guessSizeSq ) return;
  14186. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  14187. if ( distance < raycaster.near || distance > raycaster.far ) return;
  14188. intersects.push( {
  14189. distance: distance,
  14190. point: intersectPoint.clone(),
  14191. face: null,
  14192. object: this
  14193. } );
  14194. };
  14195. }() ),
  14196. clone: function () {
  14197. return new this.constructor( this.material ).copy( this );
  14198. },
  14199. copy: function ( source ) {
  14200. Object3D.prototype.copy.call( this, source );
  14201. if ( source.center !== undefined ) this.center.copy( source.center );
  14202. return this;
  14203. }
  14204. } );
  14205. /**
  14206. * @author mikael emtinger / http://gomo.se/
  14207. * @author alteredq / http://alteredqualia.com/
  14208. * @author mrdoob / http://mrdoob.com/
  14209. */
  14210. function LOD() {
  14211. Object3D.call( this );
  14212. this.type = 'LOD';
  14213. Object.defineProperties( this, {
  14214. levels: {
  14215. enumerable: true,
  14216. value: []
  14217. }
  14218. } );
  14219. }
  14220. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14221. constructor: LOD,
  14222. copy: function ( source ) {
  14223. Object3D.prototype.copy.call( this, source, false );
  14224. var levels = source.levels;
  14225. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  14226. var level = levels[ i ];
  14227. this.addLevel( level.object.clone(), level.distance );
  14228. }
  14229. return this;
  14230. },
  14231. addLevel: function ( object, distance ) {
  14232. if ( distance === undefined ) distance = 0;
  14233. distance = Math.abs( distance );
  14234. var levels = this.levels;
  14235. for ( var l = 0; l < levels.length; l ++ ) {
  14236. if ( distance < levels[ l ].distance ) {
  14237. break;
  14238. }
  14239. }
  14240. levels.splice( l, 0, { distance: distance, object: object } );
  14241. this.add( object );
  14242. },
  14243. getObjectForDistance: function ( distance ) {
  14244. var levels = this.levels;
  14245. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  14246. if ( distance < levels[ i ].distance ) {
  14247. break;
  14248. }
  14249. }
  14250. return levels[ i - 1 ].object;
  14251. },
  14252. raycast: ( function () {
  14253. var matrixPosition = new Vector3();
  14254. return function raycast( raycaster, intersects ) {
  14255. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  14256. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  14257. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  14258. };
  14259. }() ),
  14260. update: function () {
  14261. var v1 = new Vector3();
  14262. var v2 = new Vector3();
  14263. return function update( camera ) {
  14264. var levels = this.levels;
  14265. if ( levels.length > 1 ) {
  14266. v1.setFromMatrixPosition( camera.matrixWorld );
  14267. v2.setFromMatrixPosition( this.matrixWorld );
  14268. var distance = v1.distanceTo( v2 );
  14269. levels[ 0 ].object.visible = true;
  14270. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  14271. if ( distance >= levels[ i ].distance ) {
  14272. levels[ i - 1 ].object.visible = false;
  14273. levels[ i ].object.visible = true;
  14274. } else {
  14275. break;
  14276. }
  14277. }
  14278. for ( ; i < l; i ++ ) {
  14279. levels[ i ].object.visible = false;
  14280. }
  14281. }
  14282. };
  14283. }(),
  14284. toJSON: function ( meta ) {
  14285. var data = Object3D.prototype.toJSON.call( this, meta );
  14286. data.object.levels = [];
  14287. var levels = this.levels;
  14288. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  14289. var level = levels[ i ];
  14290. data.object.levels.push( {
  14291. object: level.object.uuid,
  14292. distance: level.distance
  14293. } );
  14294. }
  14295. return data;
  14296. }
  14297. } );
  14298. /**
  14299. * @author mikael emtinger / http://gomo.se/
  14300. * @author alteredq / http://alteredqualia.com/
  14301. * @author michael guerrero / http://realitymeltdown.com
  14302. * @author ikerr / http://verold.com
  14303. */
  14304. function Skeleton( bones, boneInverses ) {
  14305. // copy the bone array
  14306. bones = bones || [];
  14307. this.bones = bones.slice( 0 );
  14308. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  14309. // use the supplied bone inverses or calculate the inverses
  14310. if ( boneInverses === undefined ) {
  14311. this.calculateInverses();
  14312. } else {
  14313. if ( this.bones.length === boneInverses.length ) {
  14314. this.boneInverses = boneInverses.slice( 0 );
  14315. } else {
  14316. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  14317. this.boneInverses = [];
  14318. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  14319. this.boneInverses.push( new Matrix4() );
  14320. }
  14321. }
  14322. }
  14323. }
  14324. Object.assign( Skeleton.prototype, {
  14325. calculateInverses: function () {
  14326. this.boneInverses = [];
  14327. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  14328. var inverse = new Matrix4();
  14329. if ( this.bones[ i ] ) {
  14330. inverse.getInverse( this.bones[ i ].matrixWorld );
  14331. }
  14332. this.boneInverses.push( inverse );
  14333. }
  14334. },
  14335. pose: function () {
  14336. var bone, i, il;
  14337. // recover the bind-time world matrices
  14338. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  14339. bone = this.bones[ i ];
  14340. if ( bone ) {
  14341. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  14342. }
  14343. }
  14344. // compute the local matrices, positions, rotations and scales
  14345. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  14346. bone = this.bones[ i ];
  14347. if ( bone ) {
  14348. if ( bone.parent && bone.parent.isBone ) {
  14349. bone.matrix.getInverse( bone.parent.matrixWorld );
  14350. bone.matrix.multiply( bone.matrixWorld );
  14351. } else {
  14352. bone.matrix.copy( bone.matrixWorld );
  14353. }
  14354. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  14355. }
  14356. }
  14357. },
  14358. update: ( function () {
  14359. var offsetMatrix = new Matrix4();
  14360. var identityMatrix = new Matrix4();
  14361. return function update() {
  14362. var bones = this.bones;
  14363. var boneInverses = this.boneInverses;
  14364. var boneMatrices = this.boneMatrices;
  14365. var boneTexture = this.boneTexture;
  14366. // flatten bone matrices to array
  14367. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  14368. // compute the offset between the current and the original transform
  14369. var matrix = bones[ i ] ? bones[ i ].matrixWorld : identityMatrix;
  14370. offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  14371. offsetMatrix.toArray( boneMatrices, i * 16 );
  14372. }
  14373. if ( boneTexture !== undefined ) {
  14374. boneTexture.needsUpdate = true;
  14375. }
  14376. };
  14377. } )(),
  14378. clone: function () {
  14379. return new Skeleton( this.bones, this.boneInverses );
  14380. },
  14381. getBoneByName: function ( name ) {
  14382. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  14383. var bone = this.bones[ i ];
  14384. if ( bone.name === name ) {
  14385. return bone;
  14386. }
  14387. }
  14388. return undefined;
  14389. }
  14390. } );
  14391. /**
  14392. * @author mikael emtinger / http://gomo.se/
  14393. * @author alteredq / http://alteredqualia.com/
  14394. * @author ikerr / http://verold.com
  14395. */
  14396. function Bone() {
  14397. Object3D.call( this );
  14398. this.type = 'Bone';
  14399. }
  14400. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14401. constructor: Bone,
  14402. isBone: true
  14403. } );
  14404. /**
  14405. * @author mikael emtinger / http://gomo.se/
  14406. * @author alteredq / http://alteredqualia.com/
  14407. * @author ikerr / http://verold.com
  14408. */
  14409. function SkinnedMesh( geometry, material ) {
  14410. Mesh.call( this, geometry, material );
  14411. this.type = 'SkinnedMesh';
  14412. this.bindMode = 'attached';
  14413. this.bindMatrix = new Matrix4();
  14414. this.bindMatrixInverse = new Matrix4();
  14415. var bones = this.initBones();
  14416. var skeleton = new Skeleton( bones );
  14417. this.bind( skeleton, this.matrixWorld );
  14418. this.normalizeSkinWeights();
  14419. }
  14420. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  14421. constructor: SkinnedMesh,
  14422. isSkinnedMesh: true,
  14423. initBones: function () {
  14424. var bones = [], bone, gbone;
  14425. var i, il;
  14426. if ( this.geometry && this.geometry.bones !== undefined ) {
  14427. // first, create array of 'Bone' objects from geometry data
  14428. for ( i = 0, il = this.geometry.bones.length; i < il; i ++ ) {
  14429. gbone = this.geometry.bones[ i ];
  14430. // create new 'Bone' object
  14431. bone = new Bone();
  14432. bones.push( bone );
  14433. // apply values
  14434. bone.name = gbone.name;
  14435. bone.position.fromArray( gbone.pos );
  14436. bone.quaternion.fromArray( gbone.rotq );
  14437. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  14438. }
  14439. // second, create bone hierarchy
  14440. for ( i = 0, il = this.geometry.bones.length; i < il; i ++ ) {
  14441. gbone = this.geometry.bones[ i ];
  14442. if ( ( gbone.parent !== - 1 ) && ( gbone.parent !== null ) && ( bones[ gbone.parent ] !== undefined ) ) {
  14443. // subsequent bones in the hierarchy
  14444. bones[ gbone.parent ].add( bones[ i ] );
  14445. } else {
  14446. // topmost bone, immediate child of the skinned mesh
  14447. this.add( bones[ i ] );
  14448. }
  14449. }
  14450. }
  14451. // now the bones are part of the scene graph and children of the skinned mesh.
  14452. // let's update the corresponding matrices
  14453. this.updateMatrixWorld( true );
  14454. return bones;
  14455. },
  14456. bind: function ( skeleton, bindMatrix ) {
  14457. this.skeleton = skeleton;
  14458. if ( bindMatrix === undefined ) {
  14459. this.updateMatrixWorld( true );
  14460. this.skeleton.calculateInverses();
  14461. bindMatrix = this.matrixWorld;
  14462. }
  14463. this.bindMatrix.copy( bindMatrix );
  14464. this.bindMatrixInverse.getInverse( bindMatrix );
  14465. },
  14466. pose: function () {
  14467. this.skeleton.pose();
  14468. },
  14469. normalizeSkinWeights: function () {
  14470. var scale, i;
  14471. if ( this.geometry && this.geometry.isGeometry ) {
  14472. for ( i = 0; i < this.geometry.skinWeights.length; i ++ ) {
  14473. var sw = this.geometry.skinWeights[ i ];
  14474. scale = 1.0 / sw.manhattanLength();
  14475. if ( scale !== Infinity ) {
  14476. sw.multiplyScalar( scale );
  14477. } else {
  14478. sw.set( 1, 0, 0, 0 ); // do something reasonable
  14479. }
  14480. }
  14481. } else if ( this.geometry && this.geometry.isBufferGeometry ) {
  14482. var vec = new Vector4();
  14483. var skinWeight = this.geometry.attributes.skinWeight;
  14484. for ( i = 0; i < skinWeight.count; i ++ ) {
  14485. vec.x = skinWeight.getX( i );
  14486. vec.y = skinWeight.getY( i );
  14487. vec.z = skinWeight.getZ( i );
  14488. vec.w = skinWeight.getW( i );
  14489. scale = 1.0 / vec.manhattanLength();
  14490. if ( scale !== Infinity ) {
  14491. vec.multiplyScalar( scale );
  14492. } else {
  14493. vec.set( 1, 0, 0, 0 ); // do something reasonable
  14494. }
  14495. skinWeight.setXYZW( i, vec.x, vec.y, vec.z, vec.w );
  14496. }
  14497. }
  14498. },
  14499. updateMatrixWorld: function ( force ) {
  14500. Mesh.prototype.updateMatrixWorld.call( this, force );
  14501. if ( this.bindMode === 'attached' ) {
  14502. this.bindMatrixInverse.getInverse( this.matrixWorld );
  14503. } else if ( this.bindMode === 'detached' ) {
  14504. this.bindMatrixInverse.getInverse( this.bindMatrix );
  14505. } else {
  14506. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  14507. }
  14508. },
  14509. clone: function () {
  14510. return new this.constructor( this.geometry, this.material ).copy( this );
  14511. }
  14512. } );
  14513. /**
  14514. * @author mrdoob / http://mrdoob.com/
  14515. * @author alteredq / http://alteredqualia.com/
  14516. *
  14517. * parameters = {
  14518. * color: <hex>,
  14519. * opacity: <float>,
  14520. *
  14521. * linewidth: <float>,
  14522. * linecap: "round",
  14523. * linejoin: "round"
  14524. * }
  14525. */
  14526. function LineBasicMaterial( parameters ) {
  14527. Material.call( this );
  14528. this.type = 'LineBasicMaterial';
  14529. this.color = new Color( 0xffffff );
  14530. this.linewidth = 1;
  14531. this.linecap = 'round';
  14532. this.linejoin = 'round';
  14533. this.lights = false;
  14534. this.setValues( parameters );
  14535. }
  14536. LineBasicMaterial.prototype = Object.create( Material.prototype );
  14537. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  14538. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  14539. LineBasicMaterial.prototype.copy = function ( source ) {
  14540. Material.prototype.copy.call( this, source );
  14541. this.color.copy( source.color );
  14542. this.linewidth = source.linewidth;
  14543. this.linecap = source.linecap;
  14544. this.linejoin = source.linejoin;
  14545. return this;
  14546. };
  14547. /**
  14548. * @author mrdoob / http://mrdoob.com/
  14549. */
  14550. function Line( geometry, material, mode ) {
  14551. if ( mode === 1 ) {
  14552. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  14553. return new LineSegments( geometry, material );
  14554. }
  14555. Object3D.call( this );
  14556. this.type = 'Line';
  14557. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  14558. this.material = material !== undefined ? material : new LineBasicMaterial( { color: Math.random() * 0xffffff } );
  14559. }
  14560. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14561. constructor: Line,
  14562. isLine: true,
  14563. computeLineDistances: ( function () {
  14564. var start = new Vector3();
  14565. var end = new Vector3();
  14566. return function computeLineDistances() {
  14567. var geometry = this.geometry;
  14568. if ( geometry.isBufferGeometry ) {
  14569. // we assume non-indexed geometry
  14570. if ( geometry.index === null ) {
  14571. var positionAttribute = geometry.attributes.position;
  14572. var lineDistances = [ 0 ];
  14573. for ( var i = 1, l = positionAttribute.count; i < l; i ++ ) {
  14574. start.fromBufferAttribute( positionAttribute, i - 1 );
  14575. end.fromBufferAttribute( positionAttribute, i );
  14576. lineDistances[ i ] = lineDistances[ i - 1 ];
  14577. lineDistances[ i ] += start.distanceTo( end );
  14578. }
  14579. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  14580. } else {
  14581. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  14582. }
  14583. } else if ( geometry.isGeometry ) {
  14584. var vertices = geometry.vertices;
  14585. var lineDistances = geometry.lineDistances;
  14586. lineDistances[ 0 ] = 0;
  14587. for ( var i = 1, l = vertices.length; i < l; i ++ ) {
  14588. lineDistances[ i ] = lineDistances[ i - 1 ];
  14589. lineDistances[ i ] += vertices[ i - 1 ].distanceTo( vertices[ i ] );
  14590. }
  14591. }
  14592. return this;
  14593. };
  14594. }() ),
  14595. raycast: ( function () {
  14596. var inverseMatrix = new Matrix4();
  14597. var ray = new Ray();
  14598. var sphere = new Sphere();
  14599. return function raycast( raycaster, intersects ) {
  14600. var precision = raycaster.linePrecision;
  14601. var precisionSq = precision * precision;
  14602. var geometry = this.geometry;
  14603. var matrixWorld = this.matrixWorld;
  14604. // Checking boundingSphere distance to ray
  14605. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  14606. sphere.copy( geometry.boundingSphere );
  14607. sphere.applyMatrix4( matrixWorld );
  14608. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  14609. //
  14610. inverseMatrix.getInverse( matrixWorld );
  14611. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  14612. var vStart = new Vector3();
  14613. var vEnd = new Vector3();
  14614. var interSegment = new Vector3();
  14615. var interRay = new Vector3();
  14616. var step = ( this && this.isLineSegments ) ? 2 : 1;
  14617. if ( geometry.isBufferGeometry ) {
  14618. var index = geometry.index;
  14619. var attributes = geometry.attributes;
  14620. var positions = attributes.position.array;
  14621. if ( index !== null ) {
  14622. var indices = index.array;
  14623. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  14624. var a = indices[ i ];
  14625. var b = indices[ i + 1 ];
  14626. vStart.fromArray( positions, a * 3 );
  14627. vEnd.fromArray( positions, b * 3 );
  14628. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  14629. if ( distSq > precisionSq ) continue;
  14630. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14631. var distance = raycaster.ray.origin.distanceTo( interRay );
  14632. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14633. intersects.push( {
  14634. distance: distance,
  14635. // What do we want? intersection point on the ray or on the segment??
  14636. // point: raycaster.ray.at( distance ),
  14637. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14638. index: i,
  14639. face: null,
  14640. faceIndex: null,
  14641. object: this
  14642. } );
  14643. }
  14644. } else {
  14645. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  14646. vStart.fromArray( positions, 3 * i );
  14647. vEnd.fromArray( positions, 3 * i + 3 );
  14648. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  14649. if ( distSq > precisionSq ) continue;
  14650. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14651. var distance = raycaster.ray.origin.distanceTo( interRay );
  14652. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14653. intersects.push( {
  14654. distance: distance,
  14655. // What do we want? intersection point on the ray or on the segment??
  14656. // point: raycaster.ray.at( distance ),
  14657. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14658. index: i,
  14659. face: null,
  14660. faceIndex: null,
  14661. object: this
  14662. } );
  14663. }
  14664. }
  14665. } else if ( geometry.isGeometry ) {
  14666. var vertices = geometry.vertices;
  14667. var nbVertices = vertices.length;
  14668. for ( var i = 0; i < nbVertices - 1; i += step ) {
  14669. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  14670. if ( distSq > precisionSq ) continue;
  14671. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14672. var distance = raycaster.ray.origin.distanceTo( interRay );
  14673. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14674. intersects.push( {
  14675. distance: distance,
  14676. // What do we want? intersection point on the ray or on the segment??
  14677. // point: raycaster.ray.at( distance ),
  14678. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14679. index: i,
  14680. face: null,
  14681. faceIndex: null,
  14682. object: this
  14683. } );
  14684. }
  14685. }
  14686. };
  14687. }() ),
  14688. clone: function () {
  14689. return new this.constructor( this.geometry, this.material ).copy( this );
  14690. }
  14691. } );
  14692. /**
  14693. * @author mrdoob / http://mrdoob.com/
  14694. */
  14695. function LineSegments( geometry, material ) {
  14696. Line.call( this, geometry, material );
  14697. this.type = 'LineSegments';
  14698. }
  14699. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  14700. constructor: LineSegments,
  14701. isLineSegments: true,
  14702. computeLineDistances: ( function () {
  14703. var start = new Vector3();
  14704. var end = new Vector3();
  14705. return function computeLineDistances() {
  14706. var geometry = this.geometry;
  14707. if ( geometry.isBufferGeometry ) {
  14708. // we assume non-indexed geometry
  14709. if ( geometry.index === null ) {
  14710. var positionAttribute = geometry.attributes.position;
  14711. var lineDistances = [];
  14712. for ( var i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  14713. start.fromBufferAttribute( positionAttribute, i );
  14714. end.fromBufferAttribute( positionAttribute, i + 1 );
  14715. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  14716. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  14717. }
  14718. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  14719. } else {
  14720. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  14721. }
  14722. } else if ( geometry.isGeometry ) {
  14723. var vertices = geometry.vertices;
  14724. var lineDistances = geometry.lineDistances;
  14725. for ( var i = 0, l = vertices.length; i < l; i += 2 ) {
  14726. start.copy( vertices[ i ] );
  14727. end.copy( vertices[ i + 1 ] );
  14728. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  14729. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  14730. }
  14731. }
  14732. return this;
  14733. };
  14734. }() )
  14735. } );
  14736. /**
  14737. * @author mgreter / http://github.com/mgreter
  14738. */
  14739. function LineLoop( geometry, material ) {
  14740. Line.call( this, geometry, material );
  14741. this.type = 'LineLoop';
  14742. }
  14743. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  14744. constructor: LineLoop,
  14745. isLineLoop: true,
  14746. } );
  14747. /**
  14748. * @author mrdoob / http://mrdoob.com/
  14749. * @author alteredq / http://alteredqualia.com/
  14750. *
  14751. * parameters = {
  14752. * color: <hex>,
  14753. * opacity: <float>,
  14754. * map: new THREE.Texture( <Image> ),
  14755. *
  14756. * size: <float>,
  14757. * sizeAttenuation: <bool>
  14758. * }
  14759. */
  14760. function PointsMaterial( parameters ) {
  14761. Material.call( this );
  14762. this.type = 'PointsMaterial';
  14763. this.color = new Color( 0xffffff );
  14764. this.map = null;
  14765. this.size = 1;
  14766. this.sizeAttenuation = true;
  14767. this.lights = false;
  14768. this.setValues( parameters );
  14769. }
  14770. PointsMaterial.prototype = Object.create( Material.prototype );
  14771. PointsMaterial.prototype.constructor = PointsMaterial;
  14772. PointsMaterial.prototype.isPointsMaterial = true;
  14773. PointsMaterial.prototype.copy = function ( source ) {
  14774. Material.prototype.copy.call( this, source );
  14775. this.color.copy( source.color );
  14776. this.map = source.map;
  14777. this.size = source.size;
  14778. this.sizeAttenuation = source.sizeAttenuation;
  14779. return this;
  14780. };
  14781. /**
  14782. * @author alteredq / http://alteredqualia.com/
  14783. */
  14784. function Points( geometry, material ) {
  14785. Object3D.call( this );
  14786. this.type = 'Points';
  14787. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  14788. this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
  14789. }
  14790. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14791. constructor: Points,
  14792. isPoints: true,
  14793. raycast: ( function () {
  14794. var inverseMatrix = new Matrix4();
  14795. var ray = new Ray();
  14796. var sphere = new Sphere();
  14797. return function raycast( raycaster, intersects ) {
  14798. var object = this;
  14799. var geometry = this.geometry;
  14800. var matrixWorld = this.matrixWorld;
  14801. var threshold = raycaster.params.Points.threshold;
  14802. // Checking boundingSphere distance to ray
  14803. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  14804. sphere.copy( geometry.boundingSphere );
  14805. sphere.applyMatrix4( matrixWorld );
  14806. sphere.radius += threshold;
  14807. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  14808. //
  14809. inverseMatrix.getInverse( matrixWorld );
  14810. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  14811. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  14812. var localThresholdSq = localThreshold * localThreshold;
  14813. var position = new Vector3();
  14814. var intersectPoint = new Vector3();
  14815. function testPoint( point, index ) {
  14816. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  14817. if ( rayPointDistanceSq < localThresholdSq ) {
  14818. ray.closestPointToPoint( point, intersectPoint );
  14819. intersectPoint.applyMatrix4( matrixWorld );
  14820. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  14821. if ( distance < raycaster.near || distance > raycaster.far ) return;
  14822. intersects.push( {
  14823. distance: distance,
  14824. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  14825. point: intersectPoint.clone(),
  14826. index: index,
  14827. face: null,
  14828. object: object
  14829. } );
  14830. }
  14831. }
  14832. if ( geometry.isBufferGeometry ) {
  14833. var index = geometry.index;
  14834. var attributes = geometry.attributes;
  14835. var positions = attributes.position.array;
  14836. if ( index !== null ) {
  14837. var indices = index.array;
  14838. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  14839. var a = indices[ i ];
  14840. position.fromArray( positions, a * 3 );
  14841. testPoint( position, a );
  14842. }
  14843. } else {
  14844. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  14845. position.fromArray( positions, i * 3 );
  14846. testPoint( position, i );
  14847. }
  14848. }
  14849. } else {
  14850. var vertices = geometry.vertices;
  14851. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  14852. testPoint( vertices[ i ], i );
  14853. }
  14854. }
  14855. };
  14856. }() ),
  14857. clone: function () {
  14858. return new this.constructor( this.geometry, this.material ).copy( this );
  14859. }
  14860. } );
  14861. /**
  14862. * @author mrdoob / http://mrdoob.com/
  14863. */
  14864. function Group() {
  14865. Object3D.call( this );
  14866. this.type = 'Group';
  14867. }
  14868. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14869. constructor: Group,
  14870. isGroup: true
  14871. } );
  14872. /**
  14873. * @author mrdoob / http://mrdoob.com/
  14874. */
  14875. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  14876. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  14877. this.generateMipmaps = false;
  14878. }
  14879. VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
  14880. constructor: VideoTexture,
  14881. isVideoTexture: true,
  14882. update: function () {
  14883. var video = this.image;
  14884. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  14885. this.needsUpdate = true;
  14886. }
  14887. }
  14888. } );
  14889. /**
  14890. * @author alteredq / http://alteredqualia.com/
  14891. */
  14892. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  14893. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  14894. this.image = { width: width, height: height };
  14895. this.mipmaps = mipmaps;
  14896. // no flipping for cube textures
  14897. // (also flipping doesn't work for compressed textures )
  14898. this.flipY = false;
  14899. // can't generate mipmaps for compressed textures
  14900. // mips must be embedded in DDS files
  14901. this.generateMipmaps = false;
  14902. }
  14903. CompressedTexture.prototype = Object.create( Texture.prototype );
  14904. CompressedTexture.prototype.constructor = CompressedTexture;
  14905. CompressedTexture.prototype.isCompressedTexture = true;
  14906. /**
  14907. * @author Matt DesLauriers / @mattdesl
  14908. * @author atix / arthursilber.de
  14909. */
  14910. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  14911. format = format !== undefined ? format : DepthFormat;
  14912. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  14913. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  14914. }
  14915. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  14916. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  14917. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  14918. this.image = { width: width, height: height };
  14919. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  14920. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  14921. this.flipY = false;
  14922. this.generateMipmaps = false;
  14923. }
  14924. DepthTexture.prototype = Object.create( Texture.prototype );
  14925. DepthTexture.prototype.constructor = DepthTexture;
  14926. DepthTexture.prototype.isDepthTexture = true;
  14927. /**
  14928. * @author mrdoob / http://mrdoob.com/
  14929. * @author Mugen87 / https://github.com/Mugen87
  14930. */
  14931. function WireframeGeometry( geometry ) {
  14932. BufferGeometry.call( this );
  14933. this.type = 'WireframeGeometry';
  14934. // buffer
  14935. var vertices = [];
  14936. // helper variables
  14937. var i, j, l, o, ol;
  14938. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  14939. var key, keys = [ 'a', 'b', 'c' ];
  14940. var vertex;
  14941. // different logic for Geometry and BufferGeometry
  14942. if ( geometry && geometry.isGeometry ) {
  14943. // create a data structure that contains all edges without duplicates
  14944. var faces = geometry.faces;
  14945. for ( i = 0, l = faces.length; i < l; i ++ ) {
  14946. var face = faces[ i ];
  14947. for ( j = 0; j < 3; j ++ ) {
  14948. edge1 = face[ keys[ j ] ];
  14949. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  14950. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  14951. edge[ 1 ] = Math.max( edge1, edge2 );
  14952. key = edge[ 0 ] + ',' + edge[ 1 ];
  14953. if ( edges[ key ] === undefined ) {
  14954. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  14955. }
  14956. }
  14957. }
  14958. // generate vertices
  14959. for ( key in edges ) {
  14960. e = edges[ key ];
  14961. vertex = geometry.vertices[ e.index1 ];
  14962. vertices.push( vertex.x, vertex.y, vertex.z );
  14963. vertex = geometry.vertices[ e.index2 ];
  14964. vertices.push( vertex.x, vertex.y, vertex.z );
  14965. }
  14966. } else if ( geometry && geometry.isBufferGeometry ) {
  14967. var position, indices, groups;
  14968. var group, start, count;
  14969. var index1, index2;
  14970. vertex = new Vector3();
  14971. if ( geometry.index !== null ) {
  14972. // indexed BufferGeometry
  14973. position = geometry.attributes.position;
  14974. indices = geometry.index;
  14975. groups = geometry.groups;
  14976. if ( groups.length === 0 ) {
  14977. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  14978. }
  14979. // create a data structure that contains all eges without duplicates
  14980. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  14981. group = groups[ o ];
  14982. start = group.start;
  14983. count = group.count;
  14984. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  14985. for ( j = 0; j < 3; j ++ ) {
  14986. edge1 = indices.getX( i + j );
  14987. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  14988. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  14989. edge[ 1 ] = Math.max( edge1, edge2 );
  14990. key = edge[ 0 ] + ',' + edge[ 1 ];
  14991. if ( edges[ key ] === undefined ) {
  14992. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  14993. }
  14994. }
  14995. }
  14996. }
  14997. // generate vertices
  14998. for ( key in edges ) {
  14999. e = edges[ key ];
  15000. vertex.fromBufferAttribute( position, e.index1 );
  15001. vertices.push( vertex.x, vertex.y, vertex.z );
  15002. vertex.fromBufferAttribute( position, e.index2 );
  15003. vertices.push( vertex.x, vertex.y, vertex.z );
  15004. }
  15005. } else {
  15006. // non-indexed BufferGeometry
  15007. position = geometry.attributes.position;
  15008. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  15009. for ( j = 0; j < 3; j ++ ) {
  15010. // three edges per triangle, an edge is represented as (index1, index2)
  15011. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  15012. index1 = 3 * i + j;
  15013. vertex.fromBufferAttribute( position, index1 );
  15014. vertices.push( vertex.x, vertex.y, vertex.z );
  15015. index2 = 3 * i + ( ( j + 1 ) % 3 );
  15016. vertex.fromBufferAttribute( position, index2 );
  15017. vertices.push( vertex.x, vertex.y, vertex.z );
  15018. }
  15019. }
  15020. }
  15021. }
  15022. // build geometry
  15023. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  15024. }
  15025. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  15026. WireframeGeometry.prototype.constructor = WireframeGeometry;
  15027. /**
  15028. * @author zz85 / https://github.com/zz85
  15029. * @author Mugen87 / https://github.com/Mugen87
  15030. *
  15031. * Parametric Surfaces Geometry
  15032. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  15033. */
  15034. // ParametricGeometry
  15035. function ParametricGeometry( func, slices, stacks ) {
  15036. Geometry.call( this );
  15037. this.type = 'ParametricGeometry';
  15038. this.parameters = {
  15039. func: func,
  15040. slices: slices,
  15041. stacks: stacks
  15042. };
  15043. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  15044. this.mergeVertices();
  15045. }
  15046. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  15047. ParametricGeometry.prototype.constructor = ParametricGeometry;
  15048. // ParametricBufferGeometry
  15049. function ParametricBufferGeometry( func, slices, stacks ) {
  15050. BufferGeometry.call( this );
  15051. this.type = 'ParametricBufferGeometry';
  15052. this.parameters = {
  15053. func: func,
  15054. slices: slices,
  15055. stacks: stacks
  15056. };
  15057. // buffers
  15058. var indices = [];
  15059. var vertices = [];
  15060. var normals = [];
  15061. var uvs = [];
  15062. var EPS = 0.00001;
  15063. var normal = new Vector3();
  15064. var p0 = new Vector3(), p1 = new Vector3();
  15065. var pu = new Vector3(), pv = new Vector3();
  15066. var i, j;
  15067. // generate vertices, normals and uvs
  15068. var sliceCount = slices + 1;
  15069. for ( i = 0; i <= stacks; i ++ ) {
  15070. var v = i / stacks;
  15071. for ( j = 0; j <= slices; j ++ ) {
  15072. var u = j / slices;
  15073. // vertex
  15074. func( u, v, p0 );
  15075. vertices.push( p0.x, p0.y, p0.z );
  15076. // normal
  15077. // approximate tangent vectors via finite differences
  15078. if ( u - EPS >= 0 ) {
  15079. func( u - EPS, v, p1 );
  15080. pu.subVectors( p0, p1 );
  15081. } else {
  15082. func( u + EPS, v, p1 );
  15083. pu.subVectors( p1, p0 );
  15084. }
  15085. if ( v - EPS >= 0 ) {
  15086. func( u, v - EPS, p1 );
  15087. pv.subVectors( p0, p1 );
  15088. } else {
  15089. func( u, v + EPS, p1 );
  15090. pv.subVectors( p1, p0 );
  15091. }
  15092. // cross product of tangent vectors returns surface normal
  15093. normal.crossVectors( pu, pv ).normalize();
  15094. normals.push( normal.x, normal.y, normal.z );
  15095. // uv
  15096. uvs.push( u, v );
  15097. }
  15098. }
  15099. // generate indices
  15100. for ( i = 0; i < stacks; i ++ ) {
  15101. for ( j = 0; j < slices; j ++ ) {
  15102. var a = i * sliceCount + j;
  15103. var b = i * sliceCount + j + 1;
  15104. var c = ( i + 1 ) * sliceCount + j + 1;
  15105. var d = ( i + 1 ) * sliceCount + j;
  15106. // faces one and two
  15107. indices.push( a, b, d );
  15108. indices.push( b, c, d );
  15109. }
  15110. }
  15111. // build geometry
  15112. this.setIndex( indices );
  15113. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  15114. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  15115. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  15116. }
  15117. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15118. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  15119. /**
  15120. * @author clockworkgeek / https://github.com/clockworkgeek
  15121. * @author timothypratley / https://github.com/timothypratley
  15122. * @author WestLangley / http://github.com/WestLangley
  15123. * @author Mugen87 / https://github.com/Mugen87
  15124. */
  15125. // PolyhedronGeometry
  15126. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  15127. Geometry.call( this );
  15128. this.type = 'PolyhedronGeometry';
  15129. this.parameters = {
  15130. vertices: vertices,
  15131. indices: indices,
  15132. radius: radius,
  15133. detail: detail
  15134. };
  15135. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  15136. this.mergeVertices();
  15137. }
  15138. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  15139. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  15140. // PolyhedronBufferGeometry
  15141. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  15142. BufferGeometry.call( this );
  15143. this.type = 'PolyhedronBufferGeometry';
  15144. this.parameters = {
  15145. vertices: vertices,
  15146. indices: indices,
  15147. radius: radius,
  15148. detail: detail
  15149. };
  15150. radius = radius || 1;
  15151. detail = detail || 0;
  15152. // default buffer data
  15153. var vertexBuffer = [];
  15154. var uvBuffer = [];
  15155. // the subdivision creates the vertex buffer data
  15156. subdivide( detail );
  15157. // all vertices should lie on a conceptual sphere with a given radius
  15158. appplyRadius( radius );
  15159. // finally, create the uv data
  15160. generateUVs();
  15161. // build non-indexed geometry
  15162. this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  15163. this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  15164. this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  15165. if ( detail === 0 ) {
  15166. this.computeVertexNormals(); // flat normals
  15167. } else {
  15168. this.normalizeNormals(); // smooth normals
  15169. }
  15170. // helper functions
  15171. function subdivide( detail ) {
  15172. var a = new Vector3();
  15173. var b = new Vector3();
  15174. var c = new Vector3();
  15175. // iterate over all faces and apply a subdivison with the given detail value
  15176. for ( var i = 0; i < indices.length; i += 3 ) {
  15177. // get the vertices of the face
  15178. getVertexByIndex( indices[ i + 0 ], a );
  15179. getVertexByIndex( indices[ i + 1 ], b );
  15180. getVertexByIndex( indices[ i + 2 ], c );
  15181. // perform subdivision
  15182. subdivideFace( a, b, c, detail );
  15183. }
  15184. }
  15185. function subdivideFace( a, b, c, detail ) {
  15186. var cols = Math.pow( 2, detail );
  15187. // we use this multidimensional array as a data structure for creating the subdivision
  15188. var v = [];
  15189. var i, j;
  15190. // construct all of the vertices for this subdivision
  15191. for ( i = 0; i <= cols; i ++ ) {
  15192. v[ i ] = [];
  15193. var aj = a.clone().lerp( c, i / cols );
  15194. var bj = b.clone().lerp( c, i / cols );
  15195. var rows = cols - i;
  15196. for ( j = 0; j <= rows; j ++ ) {
  15197. if ( j === 0 && i === cols ) {
  15198. v[ i ][ j ] = aj;
  15199. } else {
  15200. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  15201. }
  15202. }
  15203. }
  15204. // construct all of the faces
  15205. for ( i = 0; i < cols; i ++ ) {
  15206. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  15207. var k = Math.floor( j / 2 );
  15208. if ( j % 2 === 0 ) {
  15209. pushVertex( v[ i ][ k + 1 ] );
  15210. pushVertex( v[ i + 1 ][ k ] );
  15211. pushVertex( v[ i ][ k ] );
  15212. } else {
  15213. pushVertex( v[ i ][ k + 1 ] );
  15214. pushVertex( v[ i + 1 ][ k + 1 ] );
  15215. pushVertex( v[ i + 1 ][ k ] );
  15216. }
  15217. }
  15218. }
  15219. }
  15220. function appplyRadius( radius ) {
  15221. var vertex = new Vector3();
  15222. // iterate over the entire buffer and apply the radius to each vertex
  15223. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  15224. vertex.x = vertexBuffer[ i + 0 ];
  15225. vertex.y = vertexBuffer[ i + 1 ];
  15226. vertex.z = vertexBuffer[ i + 2 ];
  15227. vertex.normalize().multiplyScalar( radius );
  15228. vertexBuffer[ i + 0 ] = vertex.x;
  15229. vertexBuffer[ i + 1 ] = vertex.y;
  15230. vertexBuffer[ i + 2 ] = vertex.z;
  15231. }
  15232. }
  15233. function generateUVs() {
  15234. var vertex = new Vector3();
  15235. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  15236. vertex.x = vertexBuffer[ i + 0 ];
  15237. vertex.y = vertexBuffer[ i + 1 ];
  15238. vertex.z = vertexBuffer[ i + 2 ];
  15239. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  15240. var v = inclination( vertex ) / Math.PI + 0.5;
  15241. uvBuffer.push( u, 1 - v );
  15242. }
  15243. correctUVs();
  15244. correctSeam();
  15245. }
  15246. function correctSeam() {
  15247. // handle case when face straddles the seam, see #3269
  15248. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  15249. // uv data of a single face
  15250. var x0 = uvBuffer[ i + 0 ];
  15251. var x1 = uvBuffer[ i + 2 ];
  15252. var x2 = uvBuffer[ i + 4 ];
  15253. var max = Math.max( x0, x1, x2 );
  15254. var min = Math.min( x0, x1, x2 );
  15255. // 0.9 is somewhat arbitrary
  15256. if ( max > 0.9 && min < 0.1 ) {
  15257. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  15258. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  15259. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  15260. }
  15261. }
  15262. }
  15263. function pushVertex( vertex ) {
  15264. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  15265. }
  15266. function getVertexByIndex( index, vertex ) {
  15267. var stride = index * 3;
  15268. vertex.x = vertices[ stride + 0 ];
  15269. vertex.y = vertices[ stride + 1 ];
  15270. vertex.z = vertices[ stride + 2 ];
  15271. }
  15272. function correctUVs() {
  15273. var a = new Vector3();
  15274. var b = new Vector3();
  15275. var c = new Vector3();
  15276. var centroid = new Vector3();
  15277. var uvA = new Vector2();
  15278. var uvB = new Vector2();
  15279. var uvC = new Vector2();
  15280. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  15281. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  15282. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  15283. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  15284. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  15285. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  15286. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  15287. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  15288. var azi = azimuth( centroid );
  15289. correctUV( uvA, j + 0, a, azi );
  15290. correctUV( uvB, j + 2, b, azi );
  15291. correctUV( uvC, j + 4, c, azi );
  15292. }
  15293. }
  15294. function correctUV( uv, stride, vector, azimuth ) {
  15295. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  15296. uvBuffer[ stride ] = uv.x - 1;
  15297. }
  15298. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  15299. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  15300. }
  15301. }
  15302. // Angle around the Y axis, counter-clockwise when looking from above.
  15303. function azimuth( vector ) {
  15304. return Math.atan2( vector.z, - vector.x );
  15305. }
  15306. // Angle above the XZ plane.
  15307. function inclination( vector ) {
  15308. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  15309. }
  15310. }
  15311. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15312. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  15313. /**
  15314. * @author timothypratley / https://github.com/timothypratley
  15315. * @author Mugen87 / https://github.com/Mugen87
  15316. */
  15317. // TetrahedronGeometry
  15318. function TetrahedronGeometry( radius, detail ) {
  15319. Geometry.call( this );
  15320. this.type = 'TetrahedronGeometry';
  15321. this.parameters = {
  15322. radius: radius,
  15323. detail: detail
  15324. };
  15325. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  15326. this.mergeVertices();
  15327. }
  15328. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  15329. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  15330. // TetrahedronBufferGeometry
  15331. function TetrahedronBufferGeometry( radius, detail ) {
  15332. var vertices = [
  15333. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  15334. ];
  15335. var indices = [
  15336. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  15337. ];
  15338. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  15339. this.type = 'TetrahedronBufferGeometry';
  15340. this.parameters = {
  15341. radius: radius,
  15342. detail: detail
  15343. };
  15344. }
  15345. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  15346. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  15347. /**
  15348. * @author timothypratley / https://github.com/timothypratley
  15349. * @author Mugen87 / https://github.com/Mugen87
  15350. */
  15351. // OctahedronGeometry
  15352. function OctahedronGeometry( radius, detail ) {
  15353. Geometry.call( this );
  15354. this.type = 'OctahedronGeometry';
  15355. this.parameters = {
  15356. radius: radius,
  15357. detail: detail
  15358. };
  15359. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  15360. this.mergeVertices();
  15361. }
  15362. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  15363. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  15364. // OctahedronBufferGeometry
  15365. function OctahedronBufferGeometry( radius, detail ) {
  15366. var vertices = [
  15367. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  15368. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  15369. ];
  15370. var indices = [
  15371. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  15372. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  15373. 1, 3, 4, 1, 4, 2
  15374. ];
  15375. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  15376. this.type = 'OctahedronBufferGeometry';
  15377. this.parameters = {
  15378. radius: radius,
  15379. detail: detail
  15380. };
  15381. }
  15382. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  15383. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  15384. /**
  15385. * @author timothypratley / https://github.com/timothypratley
  15386. * @author Mugen87 / https://github.com/Mugen87
  15387. */
  15388. // IcosahedronGeometry
  15389. function IcosahedronGeometry( radius, detail ) {
  15390. Geometry.call( this );
  15391. this.type = 'IcosahedronGeometry';
  15392. this.parameters = {
  15393. radius: radius,
  15394. detail: detail
  15395. };
  15396. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  15397. this.mergeVertices();
  15398. }
  15399. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  15400. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  15401. // IcosahedronBufferGeometry
  15402. function IcosahedronBufferGeometry( radius, detail ) {
  15403. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  15404. var vertices = [
  15405. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  15406. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  15407. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  15408. ];
  15409. var indices = [
  15410. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  15411. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  15412. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  15413. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  15414. ];
  15415. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  15416. this.type = 'IcosahedronBufferGeometry';
  15417. this.parameters = {
  15418. radius: radius,
  15419. detail: detail
  15420. };
  15421. }
  15422. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  15423. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  15424. /**
  15425. * @author Abe Pazos / https://hamoid.com
  15426. * @author Mugen87 / https://github.com/Mugen87
  15427. */
  15428. // DodecahedronGeometry
  15429. function DodecahedronGeometry( radius, detail ) {
  15430. Geometry.call( this );
  15431. this.type = 'DodecahedronGeometry';
  15432. this.parameters = {
  15433. radius: radius,
  15434. detail: detail
  15435. };
  15436. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  15437. this.mergeVertices();
  15438. }
  15439. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  15440. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  15441. // DodecahedronBufferGeometry
  15442. function DodecahedronBufferGeometry( radius, detail ) {
  15443. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  15444. var r = 1 / t;
  15445. var vertices = [
  15446. // (±1, ±1, ±1)
  15447. - 1, - 1, - 1, - 1, - 1, 1,
  15448. - 1, 1, - 1, - 1, 1, 1,
  15449. 1, - 1, - 1, 1, - 1, 1,
  15450. 1, 1, - 1, 1, 1, 1,
  15451. // (0, ±1/φ, ±φ)
  15452. 0, - r, - t, 0, - r, t,
  15453. 0, r, - t, 0, r, t,
  15454. // (±1/φ, ±φ, 0)
  15455. - r, - t, 0, - r, t, 0,
  15456. r, - t, 0, r, t, 0,
  15457. // (±φ, 0, ±1/φ)
  15458. - t, 0, - r, t, 0, - r,
  15459. - t, 0, r, t, 0, r
  15460. ];
  15461. var indices = [
  15462. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  15463. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  15464. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  15465. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  15466. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  15467. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  15468. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  15469. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  15470. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  15471. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  15472. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  15473. 1, 12, 14, 1, 14, 5, 1, 5, 9
  15474. ];
  15475. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  15476. this.type = 'DodecahedronBufferGeometry';
  15477. this.parameters = {
  15478. radius: radius,
  15479. detail: detail
  15480. };
  15481. }
  15482. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  15483. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  15484. /**
  15485. * @author oosmoxiecode / https://github.com/oosmoxiecode
  15486. * @author WestLangley / https://github.com/WestLangley
  15487. * @author zz85 / https://github.com/zz85
  15488. * @author miningold / https://github.com/miningold
  15489. * @author jonobr1 / https://github.com/jonobr1
  15490. * @author Mugen87 / https://github.com/Mugen87
  15491. *
  15492. */
  15493. // TubeGeometry
  15494. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  15495. Geometry.call( this );
  15496. this.type = 'TubeGeometry';
  15497. this.parameters = {
  15498. path: path,
  15499. tubularSegments: tubularSegments,
  15500. radius: radius,
  15501. radialSegments: radialSegments,
  15502. closed: closed
  15503. };
  15504. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  15505. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  15506. // expose internals
  15507. this.tangents = bufferGeometry.tangents;
  15508. this.normals = bufferGeometry.normals;
  15509. this.binormals = bufferGeometry.binormals;
  15510. // create geometry
  15511. this.fromBufferGeometry( bufferGeometry );
  15512. this.mergeVertices();
  15513. }
  15514. TubeGeometry.prototype = Object.create( Geometry.prototype );
  15515. TubeGeometry.prototype.constructor = TubeGeometry;
  15516. // TubeBufferGeometry
  15517. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  15518. BufferGeometry.call( this );
  15519. this.type = 'TubeBufferGeometry';
  15520. this.parameters = {
  15521. path: path,
  15522. tubularSegments: tubularSegments,
  15523. radius: radius,
  15524. radialSegments: radialSegments,
  15525. closed: closed
  15526. };
  15527. tubularSegments = tubularSegments || 64;
  15528. radius = radius || 1;
  15529. radialSegments = radialSegments || 8;
  15530. closed = closed || false;
  15531. var frames = path.computeFrenetFrames( tubularSegments, closed );
  15532. // expose internals
  15533. this.tangents = frames.tangents;
  15534. this.normals = frames.normals;
  15535. this.binormals = frames.binormals;
  15536. // helper variables
  15537. var vertex = new Vector3();
  15538. var normal = new Vector3();
  15539. var uv = new Vector2();
  15540. var P = new Vector3();
  15541. var i, j;
  15542. // buffer
  15543. var vertices = [];
  15544. var normals = [];
  15545. var uvs = [];
  15546. var indices = [];
  15547. // create buffer data
  15548. generateBufferData();
  15549. // build geometry
  15550. this.setIndex( indices );
  15551. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  15552. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  15553. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  15554. // functions
  15555. function generateBufferData() {
  15556. for ( i = 0; i < tubularSegments; i ++ ) {
  15557. generateSegment( i );
  15558. }
  15559. // if the geometry is not closed, generate the last row of vertices and normals
  15560. // at the regular position on the given path
  15561. //
  15562. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  15563. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  15564. // uvs are generated in a separate function.
  15565. // this makes it easy compute correct values for closed geometries
  15566. generateUVs();
  15567. // finally create faces
  15568. generateIndices();
  15569. }
  15570. function generateSegment( i ) {
  15571. // we use getPointAt to sample evenly distributed points from the given path
  15572. P = path.getPointAt( i / tubularSegments, P );
  15573. // retrieve corresponding normal and binormal
  15574. var N = frames.normals[ i ];
  15575. var B = frames.binormals[ i ];
  15576. // generate normals and vertices for the current segment
  15577. for ( j = 0; j <= radialSegments; j ++ ) {
  15578. var v = j / radialSegments * Math.PI * 2;
  15579. var sin = Math.sin( v );
  15580. var cos = - Math.cos( v );
  15581. // normal
  15582. normal.x = ( cos * N.x + sin * B.x );
  15583. normal.y = ( cos * N.y + sin * B.y );
  15584. normal.z = ( cos * N.z + sin * B.z );
  15585. normal.normalize();
  15586. normals.push( normal.x, normal.y, normal.z );
  15587. // vertex
  15588. vertex.x = P.x + radius * normal.x;
  15589. vertex.y = P.y + radius * normal.y;
  15590. vertex.z = P.z + radius * normal.z;
  15591. vertices.push( vertex.x, vertex.y, vertex.z );
  15592. }
  15593. }
  15594. function generateIndices() {
  15595. for ( j = 1; j <= tubularSegments; j ++ ) {
  15596. for ( i = 1; i <= radialSegments; i ++ ) {
  15597. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  15598. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  15599. var c = ( radialSegments + 1 ) * j + i;
  15600. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  15601. // faces
  15602. indices.push( a, b, d );
  15603. indices.push( b, c, d );
  15604. }
  15605. }
  15606. }
  15607. function generateUVs() {
  15608. for ( i = 0; i <= tubularSegments; i ++ ) {
  15609. for ( j = 0; j <= radialSegments; j ++ ) {
  15610. uv.x = i / tubularSegments;
  15611. uv.y = j / radialSegments;
  15612. uvs.push( uv.x, uv.y );
  15613. }
  15614. }
  15615. }
  15616. }
  15617. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15618. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  15619. /**
  15620. * @author oosmoxiecode
  15621. * @author Mugen87 / https://github.com/Mugen87
  15622. *
  15623. * based on http://www.blackpawn.com/texts/pqtorus/
  15624. */
  15625. // TorusKnotGeometry
  15626. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  15627. Geometry.call( this );
  15628. this.type = 'TorusKnotGeometry';
  15629. this.parameters = {
  15630. radius: radius,
  15631. tube: tube,
  15632. tubularSegments: tubularSegments,
  15633. radialSegments: radialSegments,
  15634. p: p,
  15635. q: q
  15636. };
  15637. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  15638. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  15639. this.mergeVertices();
  15640. }
  15641. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  15642. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  15643. // TorusKnotBufferGeometry
  15644. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  15645. BufferGeometry.call( this );
  15646. this.type = 'TorusKnotBufferGeometry';
  15647. this.parameters = {
  15648. radius: radius,
  15649. tube: tube,
  15650. tubularSegments: tubularSegments,
  15651. radialSegments: radialSegments,
  15652. p: p,
  15653. q: q
  15654. };
  15655. radius = radius || 1;
  15656. tube = tube || 0.4;
  15657. tubularSegments = Math.floor( tubularSegments ) || 64;
  15658. radialSegments = Math.floor( radialSegments ) || 8;
  15659. p = p || 2;
  15660. q = q || 3;
  15661. // buffers
  15662. var indices = [];
  15663. var vertices = [];
  15664. var normals = [];
  15665. var uvs = [];
  15666. // helper variables
  15667. var i, j;
  15668. var vertex = new Vector3();
  15669. var normal = new Vector3();
  15670. var P1 = new Vector3();
  15671. var P2 = new Vector3();
  15672. var B = new Vector3();
  15673. var T = new Vector3();
  15674. var N = new Vector3();
  15675. // generate vertices, normals and uvs
  15676. for ( i = 0; i <= tubularSegments; ++ i ) {
  15677. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  15678. var u = i / tubularSegments * p * Math.PI * 2;
  15679. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  15680. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  15681. calculatePositionOnCurve( u, p, q, radius, P1 );
  15682. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  15683. // calculate orthonormal basis
  15684. T.subVectors( P2, P1 );
  15685. N.addVectors( P2, P1 );
  15686. B.crossVectors( T, N );
  15687. N.crossVectors( B, T );
  15688. // normalize B, N. T can be ignored, we don't use it
  15689. B.normalize();
  15690. N.normalize();
  15691. for ( j = 0; j <= radialSegments; ++ j ) {
  15692. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  15693. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  15694. var v = j / radialSegments * Math.PI * 2;
  15695. var cx = - tube * Math.cos( v );
  15696. var cy = tube * Math.sin( v );
  15697. // now calculate the final vertex position.
  15698. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  15699. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  15700. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  15701. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  15702. vertices.push( vertex.x, vertex.y, vertex.z );
  15703. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  15704. normal.subVectors( vertex, P1 ).normalize();
  15705. normals.push( normal.x, normal.y, normal.z );
  15706. // uv
  15707. uvs.push( i / tubularSegments );
  15708. uvs.push( j / radialSegments );
  15709. }
  15710. }
  15711. // generate indices
  15712. for ( j = 1; j <= tubularSegments; j ++ ) {
  15713. for ( i = 1; i <= radialSegments; i ++ ) {
  15714. // indices
  15715. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  15716. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  15717. var c = ( radialSegments + 1 ) * j + i;
  15718. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  15719. // faces
  15720. indices.push( a, b, d );
  15721. indices.push( b, c, d );
  15722. }
  15723. }
  15724. // build geometry
  15725. this.setIndex( indices );
  15726. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  15727. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  15728. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  15729. // this function calculates the current position on the torus curve
  15730. function calculatePositionOnCurve( u, p, q, radius, position ) {
  15731. var cu = Math.cos( u );
  15732. var su = Math.sin( u );
  15733. var quOverP = q / p * u;
  15734. var cs = Math.cos( quOverP );
  15735. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  15736. position.y = radius * ( 2 + cs ) * su * 0.5;
  15737. position.z = radius * Math.sin( quOverP ) * 0.5;
  15738. }
  15739. }
  15740. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15741. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  15742. /**
  15743. * @author oosmoxiecode
  15744. * @author mrdoob / http://mrdoob.com/
  15745. * @author Mugen87 / https://github.com/Mugen87
  15746. */
  15747. // TorusGeometry
  15748. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  15749. Geometry.call( this );
  15750. this.type = 'TorusGeometry';
  15751. this.parameters = {
  15752. radius: radius,
  15753. tube: tube,
  15754. radialSegments: radialSegments,
  15755. tubularSegments: tubularSegments,
  15756. arc: arc
  15757. };
  15758. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  15759. this.mergeVertices();
  15760. }
  15761. TorusGeometry.prototype = Object.create( Geometry.prototype );
  15762. TorusGeometry.prototype.constructor = TorusGeometry;
  15763. // TorusBufferGeometry
  15764. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  15765. BufferGeometry.call( this );
  15766. this.type = 'TorusBufferGeometry';
  15767. this.parameters = {
  15768. radius: radius,
  15769. tube: tube,
  15770. radialSegments: radialSegments,
  15771. tubularSegments: tubularSegments,
  15772. arc: arc
  15773. };
  15774. radius = radius || 1;
  15775. tube = tube || 0.4;
  15776. radialSegments = Math.floor( radialSegments ) || 8;
  15777. tubularSegments = Math.floor( tubularSegments ) || 6;
  15778. arc = arc || Math.PI * 2;
  15779. // buffers
  15780. var indices = [];
  15781. var vertices = [];
  15782. var normals = [];
  15783. var uvs = [];
  15784. // helper variables
  15785. var center = new Vector3();
  15786. var vertex = new Vector3();
  15787. var normal = new Vector3();
  15788. var j, i;
  15789. // generate vertices, normals and uvs
  15790. for ( j = 0; j <= radialSegments; j ++ ) {
  15791. for ( i = 0; i <= tubularSegments; i ++ ) {
  15792. var u = i / tubularSegments * arc;
  15793. var v = j / radialSegments * Math.PI * 2;
  15794. // vertex
  15795. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  15796. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  15797. vertex.z = tube * Math.sin( v );
  15798. vertices.push( vertex.x, vertex.y, vertex.z );
  15799. // normal
  15800. center.x = radius * Math.cos( u );
  15801. center.y = radius * Math.sin( u );
  15802. normal.subVectors( vertex, center ).normalize();
  15803. normals.push( normal.x, normal.y, normal.z );
  15804. // uv
  15805. uvs.push( i / tubularSegments );
  15806. uvs.push( j / radialSegments );
  15807. }
  15808. }
  15809. // generate indices
  15810. for ( j = 1; j <= radialSegments; j ++ ) {
  15811. for ( i = 1; i <= tubularSegments; i ++ ) {
  15812. // indices
  15813. var a = ( tubularSegments + 1 ) * j + i - 1;
  15814. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  15815. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  15816. var d = ( tubularSegments + 1 ) * j + i;
  15817. // faces
  15818. indices.push( a, b, d );
  15819. indices.push( b, c, d );
  15820. }
  15821. }
  15822. // build geometry
  15823. this.setIndex( indices );
  15824. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  15825. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  15826. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  15827. }
  15828. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15829. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  15830. /**
  15831. * @author Mugen87 / https://github.com/Mugen87
  15832. * Port from https://github.com/mapbox/earcut (v2.1.2)
  15833. */
  15834. var Earcut = {
  15835. triangulate: function ( data, holeIndices, dim ) {
  15836. dim = dim || 2;
  15837. var hasHoles = holeIndices && holeIndices.length,
  15838. outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length,
  15839. outerNode = linkedList( data, 0, outerLen, dim, true ),
  15840. triangles = [];
  15841. if ( ! outerNode ) return triangles;
  15842. var minX, minY, maxX, maxY, x, y, invSize;
  15843. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  15844. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  15845. if ( data.length > 80 * dim ) {
  15846. minX = maxX = data[ 0 ];
  15847. minY = maxY = data[ 1 ];
  15848. for ( var i = dim; i < outerLen; i += dim ) {
  15849. x = data[ i ];
  15850. y = data[ i + 1 ];
  15851. if ( x < minX ) minX = x;
  15852. if ( y < minY ) minY = y;
  15853. if ( x > maxX ) maxX = x;
  15854. if ( y > maxY ) maxY = y;
  15855. }
  15856. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  15857. invSize = Math.max( maxX - minX, maxY - minY );
  15858. invSize = invSize !== 0 ? 1 / invSize : 0;
  15859. }
  15860. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  15861. return triangles;
  15862. }
  15863. };
  15864. // create a circular doubly linked list from polygon points in the specified winding order
  15865. function linkedList( data, start, end, dim, clockwise ) {
  15866. var i, last;
  15867. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  15868. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  15869. } else {
  15870. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  15871. }
  15872. if ( last && equals( last, last.next ) ) {
  15873. removeNode( last );
  15874. last = last.next;
  15875. }
  15876. return last;
  15877. }
  15878. // eliminate colinear or duplicate points
  15879. function filterPoints( start, end ) {
  15880. if ( ! start ) return start;
  15881. if ( ! end ) end = start;
  15882. var p = start, again;
  15883. do {
  15884. again = false;
  15885. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  15886. removeNode( p );
  15887. p = end = p.prev;
  15888. if ( p === p.next ) break;
  15889. again = true;
  15890. } else {
  15891. p = p.next;
  15892. }
  15893. } while ( again || p !== end );
  15894. return end;
  15895. }
  15896. // main ear slicing loop which triangulates a polygon (given as a linked list)
  15897. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  15898. if ( ! ear ) return;
  15899. // interlink polygon nodes in z-order
  15900. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  15901. var stop = ear, prev, next;
  15902. // iterate through ears, slicing them one by one
  15903. while ( ear.prev !== ear.next ) {
  15904. prev = ear.prev;
  15905. next = ear.next;
  15906. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  15907. // cut off the triangle
  15908. triangles.push( prev.i / dim );
  15909. triangles.push( ear.i / dim );
  15910. triangles.push( next.i / dim );
  15911. removeNode( ear );
  15912. // skipping the next vertice leads to less sliver triangles
  15913. ear = next.next;
  15914. stop = next.next;
  15915. continue;
  15916. }
  15917. ear = next;
  15918. // if we looped through the whole remaining polygon and can't find any more ears
  15919. if ( ear === stop ) {
  15920. // try filtering points and slicing again
  15921. if ( ! pass ) {
  15922. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  15923. // if this didn't work, try curing all small self-intersections locally
  15924. } else if ( pass === 1 ) {
  15925. ear = cureLocalIntersections( ear, triangles, dim );
  15926. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  15927. // as a last resort, try splitting the remaining polygon into two
  15928. } else if ( pass === 2 ) {
  15929. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  15930. }
  15931. break;
  15932. }
  15933. }
  15934. }
  15935. // check whether a polygon node forms a valid ear with adjacent nodes
  15936. function isEar( ear ) {
  15937. var a = ear.prev,
  15938. b = ear,
  15939. c = ear.next;
  15940. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  15941. // now make sure we don't have other points inside the potential ear
  15942. var p = ear.next.next;
  15943. while ( p !== ear.prev ) {
  15944. 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 ) {
  15945. return false;
  15946. }
  15947. p = p.next;
  15948. }
  15949. return true;
  15950. }
  15951. function isEarHashed( ear, minX, minY, invSize ) {
  15952. var a = ear.prev,
  15953. b = ear,
  15954. c = ear.next;
  15955. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  15956. // triangle bbox; min & max are calculated like this for speed
  15957. var minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  15958. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  15959. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  15960. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  15961. // z-order range for the current triangle bbox;
  15962. var minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  15963. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  15964. // first look for points inside the triangle in increasing z-order
  15965. var p = ear.nextZ;
  15966. while ( p && p.z <= maxZ ) {
  15967. if ( p !== ear.prev && p !== ear.next &&
  15968. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  15969. area( p.prev, p, p.next ) >= 0 ) return false;
  15970. p = p.nextZ;
  15971. }
  15972. // then look for points in decreasing z-order
  15973. p = ear.prevZ;
  15974. while ( p && p.z >= minZ ) {
  15975. if ( p !== ear.prev && p !== ear.next &&
  15976. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  15977. area( p.prev, p, p.next ) >= 0 ) return false;
  15978. p = p.prevZ;
  15979. }
  15980. return true;
  15981. }
  15982. // go through all polygon nodes and cure small local self-intersections
  15983. function cureLocalIntersections( start, triangles, dim ) {
  15984. var p = start;
  15985. do {
  15986. var a = p.prev, b = p.next.next;
  15987. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  15988. triangles.push( a.i / dim );
  15989. triangles.push( p.i / dim );
  15990. triangles.push( b.i / dim );
  15991. // remove two nodes involved
  15992. removeNode( p );
  15993. removeNode( p.next );
  15994. p = start = b;
  15995. }
  15996. p = p.next;
  15997. } while ( p !== start );
  15998. return p;
  15999. }
  16000. // try splitting polygon into two and triangulate them independently
  16001. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  16002. // look for a valid diagonal that divides the polygon into two
  16003. var a = start;
  16004. do {
  16005. var b = a.next.next;
  16006. while ( b !== a.prev ) {
  16007. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  16008. // split the polygon in two by the diagonal
  16009. var c = splitPolygon( a, b );
  16010. // filter colinear points around the cuts
  16011. a = filterPoints( a, a.next );
  16012. c = filterPoints( c, c.next );
  16013. // run earcut on each half
  16014. earcutLinked( a, triangles, dim, minX, minY, invSize );
  16015. earcutLinked( c, triangles, dim, minX, minY, invSize );
  16016. return;
  16017. }
  16018. b = b.next;
  16019. }
  16020. a = a.next;
  16021. } while ( a !== start );
  16022. }
  16023. // link every hole into the outer loop, producing a single-ring polygon without holes
  16024. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  16025. var queue = [], i, len, start, end, list;
  16026. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  16027. start = holeIndices[ i ] * dim;
  16028. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  16029. list = linkedList( data, start, end, dim, false );
  16030. if ( list === list.next ) list.steiner = true;
  16031. queue.push( getLeftmost( list ) );
  16032. }
  16033. queue.sort( compareX );
  16034. // process holes from left to right
  16035. for ( i = 0; i < queue.length; i ++ ) {
  16036. eliminateHole( queue[ i ], outerNode );
  16037. outerNode = filterPoints( outerNode, outerNode.next );
  16038. }
  16039. return outerNode;
  16040. }
  16041. function compareX( a, b ) {
  16042. return a.x - b.x;
  16043. }
  16044. // find a bridge between vertices that connects hole with an outer ring and and link it
  16045. function eliminateHole( hole, outerNode ) {
  16046. outerNode = findHoleBridge( hole, outerNode );
  16047. if ( outerNode ) {
  16048. var b = splitPolygon( outerNode, hole );
  16049. filterPoints( b, b.next );
  16050. }
  16051. }
  16052. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  16053. function findHoleBridge( hole, outerNode ) {
  16054. var p = outerNode,
  16055. hx = hole.x,
  16056. hy = hole.y,
  16057. qx = - Infinity,
  16058. m;
  16059. // find a segment intersected by a ray from the hole's leftmost point to the left;
  16060. // segment's endpoint with lesser x will be potential connection point
  16061. do {
  16062. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  16063. var x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  16064. if ( x <= hx && x > qx ) {
  16065. qx = x;
  16066. if ( x === hx ) {
  16067. if ( hy === p.y ) return p;
  16068. if ( hy === p.next.y ) return p.next;
  16069. }
  16070. m = p.x < p.next.x ? p : p.next;
  16071. }
  16072. }
  16073. p = p.next;
  16074. } while ( p !== outerNode );
  16075. if ( ! m ) return null;
  16076. if ( hx === qx ) return m.prev; // hole touches outer segment; pick lower endpoint
  16077. // look for points inside the triangle of hole point, segment intersection and endpoint;
  16078. // if there are no points found, we have a valid connection;
  16079. // otherwise choose the point of the minimum angle with the ray as connection point
  16080. var stop = m,
  16081. mx = m.x,
  16082. my = m.y,
  16083. tanMin = Infinity,
  16084. tan;
  16085. p = m.next;
  16086. while ( p !== stop ) {
  16087. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  16088. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  16089. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  16090. if ( ( tan < tanMin || ( tan === tanMin && p.x > m.x ) ) && locallyInside( p, hole ) ) {
  16091. m = p;
  16092. tanMin = tan;
  16093. }
  16094. }
  16095. p = p.next;
  16096. }
  16097. return m;
  16098. }
  16099. // interlink polygon nodes in z-order
  16100. function indexCurve( start, minX, minY, invSize ) {
  16101. var p = start;
  16102. do {
  16103. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  16104. p.prevZ = p.prev;
  16105. p.nextZ = p.next;
  16106. p = p.next;
  16107. } while ( p !== start );
  16108. p.prevZ.nextZ = null;
  16109. p.prevZ = null;
  16110. sortLinked( p );
  16111. }
  16112. // Simon Tatham's linked list merge sort algorithm
  16113. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  16114. function sortLinked( list ) {
  16115. var i, p, q, e, tail, numMerges, pSize, qSize, inSize = 1;
  16116. do {
  16117. p = list;
  16118. list = null;
  16119. tail = null;
  16120. numMerges = 0;
  16121. while ( p ) {
  16122. numMerges ++;
  16123. q = p;
  16124. pSize = 0;
  16125. for ( i = 0; i < inSize; i ++ ) {
  16126. pSize ++;
  16127. q = q.nextZ;
  16128. if ( ! q ) break;
  16129. }
  16130. qSize = inSize;
  16131. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  16132. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  16133. e = p;
  16134. p = p.nextZ;
  16135. pSize --;
  16136. } else {
  16137. e = q;
  16138. q = q.nextZ;
  16139. qSize --;
  16140. }
  16141. if ( tail ) tail.nextZ = e;
  16142. else list = e;
  16143. e.prevZ = tail;
  16144. tail = e;
  16145. }
  16146. p = q;
  16147. }
  16148. tail.nextZ = null;
  16149. inSize *= 2;
  16150. } while ( numMerges > 1 );
  16151. return list;
  16152. }
  16153. // z-order of a point given coords and inverse of the longer side of data bbox
  16154. function zOrder( x, y, minX, minY, invSize ) {
  16155. // coords are transformed into non-negative 15-bit integer range
  16156. x = 32767 * ( x - minX ) * invSize;
  16157. y = 32767 * ( y - minY ) * invSize;
  16158. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  16159. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  16160. x = ( x | ( x << 2 ) ) & 0x33333333;
  16161. x = ( x | ( x << 1 ) ) & 0x55555555;
  16162. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  16163. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  16164. y = ( y | ( y << 2 ) ) & 0x33333333;
  16165. y = ( y | ( y << 1 ) ) & 0x55555555;
  16166. return x | ( y << 1 );
  16167. }
  16168. // find the leftmost node of a polygon ring
  16169. function getLeftmost( start ) {
  16170. var p = start, leftmost = start;
  16171. do {
  16172. if ( p.x < leftmost.x ) leftmost = p;
  16173. p = p.next;
  16174. } while ( p !== start );
  16175. return leftmost;
  16176. }
  16177. // check if a point lies within a convex triangle
  16178. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  16179. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  16180. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  16181. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  16182. }
  16183. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  16184. function isValidDiagonal( a, b ) {
  16185. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) &&
  16186. locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b );
  16187. }
  16188. // signed area of a triangle
  16189. function area( p, q, r ) {
  16190. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  16191. }
  16192. // check if two points are equal
  16193. function equals( p1, p2 ) {
  16194. return p1.x === p2.x && p1.y === p2.y;
  16195. }
  16196. // check if two segments intersect
  16197. function intersects( p1, q1, p2, q2 ) {
  16198. if ( ( equals( p1, q1 ) && equals( p2, q2 ) ) ||
  16199. ( equals( p1, q2 ) && equals( p2, q1 ) ) ) return true;
  16200. return area( p1, q1, p2 ) > 0 !== area( p1, q1, q2 ) > 0 &&
  16201. area( p2, q2, p1 ) > 0 !== area( p2, q2, q1 ) > 0;
  16202. }
  16203. // check if a polygon diagonal intersects any polygon segments
  16204. function intersectsPolygon( a, b ) {
  16205. var p = a;
  16206. do {
  16207. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  16208. intersects( p, p.next, a, b ) ) {
  16209. return true;
  16210. }
  16211. p = p.next;
  16212. } while ( p !== a );
  16213. return false;
  16214. }
  16215. // check if a polygon diagonal is locally inside the polygon
  16216. function locallyInside( a, b ) {
  16217. return area( a.prev, a, a.next ) < 0 ?
  16218. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  16219. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  16220. }
  16221. // check if the middle point of a polygon diagonal is inside the polygon
  16222. function middleInside( a, b ) {
  16223. var p = a,
  16224. inside = false,
  16225. px = ( a.x + b.x ) / 2,
  16226. py = ( a.y + b.y ) / 2;
  16227. do {
  16228. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  16229. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) ) {
  16230. inside = ! inside;
  16231. }
  16232. p = p.next;
  16233. } while ( p !== a );
  16234. return inside;
  16235. }
  16236. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  16237. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  16238. function splitPolygon( a, b ) {
  16239. var a2 = new Node( a.i, a.x, a.y ),
  16240. b2 = new Node( b.i, b.x, b.y ),
  16241. an = a.next,
  16242. bp = b.prev;
  16243. a.next = b;
  16244. b.prev = a;
  16245. a2.next = an;
  16246. an.prev = a2;
  16247. b2.next = a2;
  16248. a2.prev = b2;
  16249. bp.next = b2;
  16250. b2.prev = bp;
  16251. return b2;
  16252. }
  16253. // create a node and optionally link it with previous one (in a circular doubly linked list)
  16254. function insertNode( i, x, y, last ) {
  16255. var p = new Node( i, x, y );
  16256. if ( ! last ) {
  16257. p.prev = p;
  16258. p.next = p;
  16259. } else {
  16260. p.next = last.next;
  16261. p.prev = last;
  16262. last.next.prev = p;
  16263. last.next = p;
  16264. }
  16265. return p;
  16266. }
  16267. function removeNode( p ) {
  16268. p.next.prev = p.prev;
  16269. p.prev.next = p.next;
  16270. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  16271. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  16272. }
  16273. function Node( i, x, y ) {
  16274. // vertice index in coordinates array
  16275. this.i = i;
  16276. // vertex coordinates
  16277. this.x = x;
  16278. this.y = y;
  16279. // previous and next vertice nodes in a polygon ring
  16280. this.prev = null;
  16281. this.next = null;
  16282. // z-order curve value
  16283. this.z = null;
  16284. // previous and next nodes in z-order
  16285. this.prevZ = null;
  16286. this.nextZ = null;
  16287. // indicates whether this is a steiner point
  16288. this.steiner = false;
  16289. }
  16290. function signedArea( data, start, end, dim ) {
  16291. var sum = 0;
  16292. for ( var i = start, j = end - dim; i < end; i += dim ) {
  16293. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  16294. j = i;
  16295. }
  16296. return sum;
  16297. }
  16298. /**
  16299. * @author zz85 / http://www.lab4games.net/zz85/blog
  16300. */
  16301. var ShapeUtils = {
  16302. // calculate area of the contour polygon
  16303. area: function ( contour ) {
  16304. var n = contour.length;
  16305. var a = 0.0;
  16306. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  16307. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  16308. }
  16309. return a * 0.5;
  16310. },
  16311. isClockWise: function ( pts ) {
  16312. return ShapeUtils.area( pts ) < 0;
  16313. },
  16314. triangulateShape: function ( contour, holes ) {
  16315. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  16316. var holeIndices = []; // array of hole indices
  16317. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  16318. removeDupEndPts( contour );
  16319. addContour( vertices, contour );
  16320. //
  16321. var holeIndex = contour.length;
  16322. holes.forEach( removeDupEndPts );
  16323. for ( var i = 0; i < holes.length; i ++ ) {
  16324. holeIndices.push( holeIndex );
  16325. holeIndex += holes[ i ].length;
  16326. addContour( vertices, holes[ i ] );
  16327. }
  16328. //
  16329. var triangles = Earcut.triangulate( vertices, holeIndices );
  16330. //
  16331. for ( var i = 0; i < triangles.length; i += 3 ) {
  16332. faces.push( triangles.slice( i, i + 3 ) );
  16333. }
  16334. return faces;
  16335. }
  16336. };
  16337. function removeDupEndPts( points ) {
  16338. var l = points.length;
  16339. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  16340. points.pop();
  16341. }
  16342. }
  16343. function addContour( vertices, contour ) {
  16344. for ( var i = 0; i < contour.length; i ++ ) {
  16345. vertices.push( contour[ i ].x );
  16346. vertices.push( contour[ i ].y );
  16347. }
  16348. }
  16349. /**
  16350. * @author zz85 / http://www.lab4games.net/zz85/blog
  16351. *
  16352. * Creates extruded geometry from a path shape.
  16353. *
  16354. * parameters = {
  16355. *
  16356. * curveSegments: <int>, // number of points on the curves
  16357. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  16358. * amount: <int>, // Depth to extrude the shape
  16359. *
  16360. * bevelEnabled: <bool>, // turn on bevel
  16361. * bevelThickness: <float>, // how deep into the original shape bevel goes
  16362. * bevelSize: <float>, // how far from shape outline is bevel
  16363. * bevelSegments: <int>, // number of bevel layers
  16364. *
  16365. * extrudePath: <THREE.Curve> // curve to extrude shape along
  16366. *
  16367. * UVGenerator: <Object> // object that provides UV generator functions
  16368. *
  16369. * }
  16370. */
  16371. // ExtrudeGeometry
  16372. function ExtrudeGeometry( shapes, options ) {
  16373. Geometry.call( this );
  16374. this.type = 'ExtrudeGeometry';
  16375. this.parameters = {
  16376. shapes: shapes,
  16377. options: options
  16378. };
  16379. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  16380. this.mergeVertices();
  16381. }
  16382. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  16383. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  16384. // ExtrudeBufferGeometry
  16385. function ExtrudeBufferGeometry( shapes, options ) {
  16386. BufferGeometry.call( this );
  16387. this.type = 'ExtrudeBufferGeometry';
  16388. this.parameters = {
  16389. shapes: shapes,
  16390. options: options
  16391. };
  16392. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  16393. var scope = this;
  16394. var verticesArray = [];
  16395. var uvArray = [];
  16396. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  16397. var shape = shapes[ i ];
  16398. addShape( shape, options );
  16399. }
  16400. // build geometry
  16401. this.addAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  16402. this.addAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  16403. this.computeVertexNormals();
  16404. // functions
  16405. function addShape( shape ) {
  16406. var placeholder = [];
  16407. // options
  16408. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  16409. var steps = options.steps !== undefined ? options.steps : 1;
  16410. var amount = options.amount !== undefined ? options.amount : 100;
  16411. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  16412. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  16413. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  16414. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  16415. var extrudePath = options.extrudePath;
  16416. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  16417. //
  16418. var extrudePts, extrudeByPath = false;
  16419. var splineTube, binormal, normal, position2;
  16420. if ( extrudePath ) {
  16421. extrudePts = extrudePath.getSpacedPoints( steps );
  16422. extrudeByPath = true;
  16423. bevelEnabled = false; // bevels not supported for path extrusion
  16424. // SETUP TNB variables
  16425. // TODO1 - have a .isClosed in spline?
  16426. splineTube = extrudePath.computeFrenetFrames( steps, false );
  16427. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  16428. binormal = new Vector3();
  16429. normal = new Vector3();
  16430. position2 = new Vector3();
  16431. }
  16432. // Safeguards if bevels are not enabled
  16433. if ( ! bevelEnabled ) {
  16434. bevelSegments = 0;
  16435. bevelThickness = 0;
  16436. bevelSize = 0;
  16437. }
  16438. // Variables initialization
  16439. var ahole, h, hl; // looping of holes
  16440. var shapePoints = shape.extractPoints( curveSegments );
  16441. var vertices = shapePoints.shape;
  16442. var holes = shapePoints.holes;
  16443. var reverse = ! ShapeUtils.isClockWise( vertices );
  16444. if ( reverse ) {
  16445. vertices = vertices.reverse();
  16446. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  16447. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16448. ahole = holes[ h ];
  16449. if ( ShapeUtils.isClockWise( ahole ) ) {
  16450. holes[ h ] = ahole.reverse();
  16451. }
  16452. }
  16453. }
  16454. var faces = ShapeUtils.triangulateShape( vertices, holes );
  16455. /* Vertices */
  16456. var contour = vertices; // vertices has all points but contour has only points of circumference
  16457. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16458. ahole = holes[ h ];
  16459. vertices = vertices.concat( ahole );
  16460. }
  16461. function scalePt2( pt, vec, size ) {
  16462. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  16463. return vec.clone().multiplyScalar( size ).add( pt );
  16464. }
  16465. var b, bs, t, z,
  16466. vert, vlen = vertices.length,
  16467. face, flen = faces.length;
  16468. // Find directions for point movement
  16469. function getBevelVec( inPt, inPrev, inNext ) {
  16470. // computes for inPt the corresponding point inPt' on a new contour
  16471. // shifted by 1 unit (length of normalized vector) to the left
  16472. // if we walk along contour clockwise, this new contour is outside the old one
  16473. //
  16474. // inPt' is the intersection of the two lines parallel to the two
  16475. // adjacent edges of inPt at a distance of 1 unit on the left side.
  16476. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  16477. // good reading for geometry algorithms (here: line-line intersection)
  16478. // http://geomalgorithms.com/a05-_intersect-1.html
  16479. var v_prev_x = inPt.x - inPrev.x,
  16480. v_prev_y = inPt.y - inPrev.y;
  16481. var v_next_x = inNext.x - inPt.x,
  16482. v_next_y = inNext.y - inPt.y;
  16483. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  16484. // check for collinear edges
  16485. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  16486. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  16487. // not collinear
  16488. // length of vectors for normalizing
  16489. var v_prev_len = Math.sqrt( v_prev_lensq );
  16490. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  16491. // shift adjacent points by unit vectors to the left
  16492. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  16493. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  16494. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  16495. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  16496. // scaling factor for v_prev to intersection point
  16497. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  16498. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  16499. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  16500. // vector from inPt to intersection point
  16501. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  16502. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  16503. // Don't normalize!, otherwise sharp corners become ugly
  16504. // but prevent crazy spikes
  16505. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  16506. if ( v_trans_lensq <= 2 ) {
  16507. return new Vector2( v_trans_x, v_trans_y );
  16508. } else {
  16509. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  16510. }
  16511. } else {
  16512. // handle special case of collinear edges
  16513. var direction_eq = false; // assumes: opposite
  16514. if ( v_prev_x > Number.EPSILON ) {
  16515. if ( v_next_x > Number.EPSILON ) {
  16516. direction_eq = true;
  16517. }
  16518. } else {
  16519. if ( v_prev_x < - Number.EPSILON ) {
  16520. if ( v_next_x < - Number.EPSILON ) {
  16521. direction_eq = true;
  16522. }
  16523. } else {
  16524. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  16525. direction_eq = true;
  16526. }
  16527. }
  16528. }
  16529. if ( direction_eq ) {
  16530. // console.log("Warning: lines are a straight sequence");
  16531. v_trans_x = - v_prev_y;
  16532. v_trans_y = v_prev_x;
  16533. shrink_by = Math.sqrt( v_prev_lensq );
  16534. } else {
  16535. // console.log("Warning: lines are a straight spike");
  16536. v_trans_x = v_prev_x;
  16537. v_trans_y = v_prev_y;
  16538. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  16539. }
  16540. }
  16541. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  16542. }
  16543. var contourMovements = [];
  16544. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  16545. if ( j === il ) j = 0;
  16546. if ( k === il ) k = 0;
  16547. // (j)---(i)---(k)
  16548. // console.log('i,j,k', i, j , k)
  16549. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  16550. }
  16551. var holesMovements = [],
  16552. oneHoleMovements, verticesMovements = contourMovements.concat();
  16553. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16554. ahole = holes[ h ];
  16555. oneHoleMovements = [];
  16556. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  16557. if ( j === il ) j = 0;
  16558. if ( k === il ) k = 0;
  16559. // (j)---(i)---(k)
  16560. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  16561. }
  16562. holesMovements.push( oneHoleMovements );
  16563. verticesMovements = verticesMovements.concat( oneHoleMovements );
  16564. }
  16565. // Loop bevelSegments, 1 for the front, 1 for the back
  16566. for ( b = 0; b < bevelSegments; b ++ ) {
  16567. //for ( b = bevelSegments; b > 0; b -- ) {
  16568. t = b / bevelSegments;
  16569. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  16570. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  16571. // contract shape
  16572. for ( i = 0, il = contour.length; i < il; i ++ ) {
  16573. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  16574. v( vert.x, vert.y, - z );
  16575. }
  16576. // expand holes
  16577. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16578. ahole = holes[ h ];
  16579. oneHoleMovements = holesMovements[ h ];
  16580. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  16581. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  16582. v( vert.x, vert.y, - z );
  16583. }
  16584. }
  16585. }
  16586. bs = bevelSize;
  16587. // Back facing vertices
  16588. for ( i = 0; i < vlen; i ++ ) {
  16589. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  16590. if ( ! extrudeByPath ) {
  16591. v( vert.x, vert.y, 0 );
  16592. } else {
  16593. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  16594. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  16595. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  16596. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  16597. v( position2.x, position2.y, position2.z );
  16598. }
  16599. }
  16600. // Add stepped vertices...
  16601. // Including front facing vertices
  16602. var s;
  16603. for ( s = 1; s <= steps; s ++ ) {
  16604. for ( i = 0; i < vlen; i ++ ) {
  16605. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  16606. if ( ! extrudeByPath ) {
  16607. v( vert.x, vert.y, amount / steps * s );
  16608. } else {
  16609. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  16610. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  16611. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  16612. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  16613. v( position2.x, position2.y, position2.z );
  16614. }
  16615. }
  16616. }
  16617. // Add bevel segments planes
  16618. //for ( b = 1; b <= bevelSegments; b ++ ) {
  16619. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  16620. t = b / bevelSegments;
  16621. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  16622. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  16623. // contract shape
  16624. for ( i = 0, il = contour.length; i < il; i ++ ) {
  16625. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  16626. v( vert.x, vert.y, amount + z );
  16627. }
  16628. // expand holes
  16629. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16630. ahole = holes[ h ];
  16631. oneHoleMovements = holesMovements[ h ];
  16632. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  16633. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  16634. if ( ! extrudeByPath ) {
  16635. v( vert.x, vert.y, amount + z );
  16636. } else {
  16637. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  16638. }
  16639. }
  16640. }
  16641. }
  16642. /* Faces */
  16643. // Top and bottom faces
  16644. buildLidFaces();
  16645. // Sides faces
  16646. buildSideFaces();
  16647. ///// Internal functions
  16648. function buildLidFaces() {
  16649. var start = verticesArray.length / 3;
  16650. if ( bevelEnabled ) {
  16651. var layer = 0; // steps + 1
  16652. var offset = vlen * layer;
  16653. // Bottom faces
  16654. for ( i = 0; i < flen; i ++ ) {
  16655. face = faces[ i ];
  16656. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  16657. }
  16658. layer = steps + bevelSegments * 2;
  16659. offset = vlen * layer;
  16660. // Top faces
  16661. for ( i = 0; i < flen; i ++ ) {
  16662. face = faces[ i ];
  16663. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  16664. }
  16665. } else {
  16666. // Bottom faces
  16667. for ( i = 0; i < flen; i ++ ) {
  16668. face = faces[ i ];
  16669. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  16670. }
  16671. // Top faces
  16672. for ( i = 0; i < flen; i ++ ) {
  16673. face = faces[ i ];
  16674. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  16675. }
  16676. }
  16677. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  16678. }
  16679. // Create faces for the z-sides of the shape
  16680. function buildSideFaces() {
  16681. var start = verticesArray.length / 3;
  16682. var layeroffset = 0;
  16683. sidewalls( contour, layeroffset );
  16684. layeroffset += contour.length;
  16685. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16686. ahole = holes[ h ];
  16687. sidewalls( ahole, layeroffset );
  16688. //, true
  16689. layeroffset += ahole.length;
  16690. }
  16691. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  16692. }
  16693. function sidewalls( contour, layeroffset ) {
  16694. var j, k;
  16695. i = contour.length;
  16696. while ( -- i >= 0 ) {
  16697. j = i;
  16698. k = i - 1;
  16699. if ( k < 0 ) k = contour.length - 1;
  16700. //console.log('b', i,j, i-1, k,vertices.length);
  16701. var s = 0,
  16702. sl = steps + bevelSegments * 2;
  16703. for ( s = 0; s < sl; s ++ ) {
  16704. var slen1 = vlen * s;
  16705. var slen2 = vlen * ( s + 1 );
  16706. var a = layeroffset + j + slen1,
  16707. b = layeroffset + k + slen1,
  16708. c = layeroffset + k + slen2,
  16709. d = layeroffset + j + slen2;
  16710. f4( a, b, c, d );
  16711. }
  16712. }
  16713. }
  16714. function v( x, y, z ) {
  16715. placeholder.push( x );
  16716. placeholder.push( y );
  16717. placeholder.push( z );
  16718. }
  16719. function f3( a, b, c ) {
  16720. addVertex( a );
  16721. addVertex( b );
  16722. addVertex( c );
  16723. var nextIndex = verticesArray.length / 3;
  16724. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  16725. addUV( uvs[ 0 ] );
  16726. addUV( uvs[ 1 ] );
  16727. addUV( uvs[ 2 ] );
  16728. }
  16729. function f4( a, b, c, d ) {
  16730. addVertex( a );
  16731. addVertex( b );
  16732. addVertex( d );
  16733. addVertex( b );
  16734. addVertex( c );
  16735. addVertex( d );
  16736. var nextIndex = verticesArray.length / 3;
  16737. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  16738. addUV( uvs[ 0 ] );
  16739. addUV( uvs[ 1 ] );
  16740. addUV( uvs[ 3 ] );
  16741. addUV( uvs[ 1 ] );
  16742. addUV( uvs[ 2 ] );
  16743. addUV( uvs[ 3 ] );
  16744. }
  16745. function addVertex( index ) {
  16746. verticesArray.push( placeholder[ index * 3 + 0 ] );
  16747. verticesArray.push( placeholder[ index * 3 + 1 ] );
  16748. verticesArray.push( placeholder[ index * 3 + 2 ] );
  16749. }
  16750. function addUV( vector2 ) {
  16751. uvArray.push( vector2.x );
  16752. uvArray.push( vector2.y );
  16753. }
  16754. }
  16755. }
  16756. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16757. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  16758. var WorldUVGenerator = {
  16759. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  16760. var a_x = vertices[ indexA * 3 ];
  16761. var a_y = vertices[ indexA * 3 + 1 ];
  16762. var b_x = vertices[ indexB * 3 ];
  16763. var b_y = vertices[ indexB * 3 + 1 ];
  16764. var c_x = vertices[ indexC * 3 ];
  16765. var c_y = vertices[ indexC * 3 + 1 ];
  16766. return [
  16767. new Vector2( a_x, a_y ),
  16768. new Vector2( b_x, b_y ),
  16769. new Vector2( c_x, c_y )
  16770. ];
  16771. },
  16772. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  16773. var a_x = vertices[ indexA * 3 ];
  16774. var a_y = vertices[ indexA * 3 + 1 ];
  16775. var a_z = vertices[ indexA * 3 + 2 ];
  16776. var b_x = vertices[ indexB * 3 ];
  16777. var b_y = vertices[ indexB * 3 + 1 ];
  16778. var b_z = vertices[ indexB * 3 + 2 ];
  16779. var c_x = vertices[ indexC * 3 ];
  16780. var c_y = vertices[ indexC * 3 + 1 ];
  16781. var c_z = vertices[ indexC * 3 + 2 ];
  16782. var d_x = vertices[ indexD * 3 ];
  16783. var d_y = vertices[ indexD * 3 + 1 ];
  16784. var d_z = vertices[ indexD * 3 + 2 ];
  16785. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  16786. return [
  16787. new Vector2( a_x, 1 - a_z ),
  16788. new Vector2( b_x, 1 - b_z ),
  16789. new Vector2( c_x, 1 - c_z ),
  16790. new Vector2( d_x, 1 - d_z )
  16791. ];
  16792. } else {
  16793. return [
  16794. new Vector2( a_y, 1 - a_z ),
  16795. new Vector2( b_y, 1 - b_z ),
  16796. new Vector2( c_y, 1 - c_z ),
  16797. new Vector2( d_y, 1 - d_z )
  16798. ];
  16799. }
  16800. }
  16801. };
  16802. /**
  16803. * @author zz85 / http://www.lab4games.net/zz85/blog
  16804. * @author alteredq / http://alteredqualia.com/
  16805. *
  16806. * Text = 3D Text
  16807. *
  16808. * parameters = {
  16809. * font: <THREE.Font>, // font
  16810. *
  16811. * size: <float>, // size of the text
  16812. * height: <float>, // thickness to extrude text
  16813. * curveSegments: <int>, // number of points on the curves
  16814. *
  16815. * bevelEnabled: <bool>, // turn on bevel
  16816. * bevelThickness: <float>, // how deep into text bevel goes
  16817. * bevelSize: <float> // how far from text outline is bevel
  16818. * }
  16819. */
  16820. // TextGeometry
  16821. function TextGeometry( text, parameters ) {
  16822. Geometry.call( this );
  16823. this.type = 'TextGeometry';
  16824. this.parameters = {
  16825. text: text,
  16826. parameters: parameters
  16827. };
  16828. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  16829. this.mergeVertices();
  16830. }
  16831. TextGeometry.prototype = Object.create( Geometry.prototype );
  16832. TextGeometry.prototype.constructor = TextGeometry;
  16833. // TextBufferGeometry
  16834. function TextBufferGeometry( text, parameters ) {
  16835. parameters = parameters || {};
  16836. var font = parameters.font;
  16837. if ( ! ( font && font.isFont ) ) {
  16838. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  16839. return new Geometry();
  16840. }
  16841. var shapes = font.generateShapes( text, parameters.size, parameters.curveSegments );
  16842. // translate parameters to ExtrudeGeometry API
  16843. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  16844. // defaults
  16845. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  16846. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  16847. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  16848. ExtrudeBufferGeometry.call( this, shapes, parameters );
  16849. this.type = 'TextBufferGeometry';
  16850. }
  16851. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  16852. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  16853. /**
  16854. * @author mrdoob / http://mrdoob.com/
  16855. * @author benaadams / https://twitter.com/ben_a_adams
  16856. * @author Mugen87 / https://github.com/Mugen87
  16857. */
  16858. // SphereGeometry
  16859. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  16860. Geometry.call( this );
  16861. this.type = 'SphereGeometry';
  16862. this.parameters = {
  16863. radius: radius,
  16864. widthSegments: widthSegments,
  16865. heightSegments: heightSegments,
  16866. phiStart: phiStart,
  16867. phiLength: phiLength,
  16868. thetaStart: thetaStart,
  16869. thetaLength: thetaLength
  16870. };
  16871. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  16872. this.mergeVertices();
  16873. }
  16874. SphereGeometry.prototype = Object.create( Geometry.prototype );
  16875. SphereGeometry.prototype.constructor = SphereGeometry;
  16876. // SphereBufferGeometry
  16877. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  16878. BufferGeometry.call( this );
  16879. this.type = 'SphereBufferGeometry';
  16880. this.parameters = {
  16881. radius: radius,
  16882. widthSegments: widthSegments,
  16883. heightSegments: heightSegments,
  16884. phiStart: phiStart,
  16885. phiLength: phiLength,
  16886. thetaStart: thetaStart,
  16887. thetaLength: thetaLength
  16888. };
  16889. radius = radius || 1;
  16890. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  16891. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  16892. phiStart = phiStart !== undefined ? phiStart : 0;
  16893. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  16894. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  16895. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  16896. var thetaEnd = thetaStart + thetaLength;
  16897. var ix, iy;
  16898. var index = 0;
  16899. var grid = [];
  16900. var vertex = new Vector3();
  16901. var normal = new Vector3();
  16902. // buffers
  16903. var indices = [];
  16904. var vertices = [];
  16905. var normals = [];
  16906. var uvs = [];
  16907. // generate vertices, normals and uvs
  16908. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  16909. var verticesRow = [];
  16910. var v = iy / heightSegments;
  16911. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  16912. var u = ix / widthSegments;
  16913. // vertex
  16914. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  16915. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  16916. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  16917. vertices.push( vertex.x, vertex.y, vertex.z );
  16918. // normal
  16919. normal.set( vertex.x, vertex.y, vertex.z ).normalize();
  16920. normals.push( normal.x, normal.y, normal.z );
  16921. // uv
  16922. uvs.push( u, 1 - v );
  16923. verticesRow.push( index ++ );
  16924. }
  16925. grid.push( verticesRow );
  16926. }
  16927. // indices
  16928. for ( iy = 0; iy < heightSegments; iy ++ ) {
  16929. for ( ix = 0; ix < widthSegments; ix ++ ) {
  16930. var a = grid[ iy ][ ix + 1 ];
  16931. var b = grid[ iy ][ ix ];
  16932. var c = grid[ iy + 1 ][ ix ];
  16933. var d = grid[ iy + 1 ][ ix + 1 ];
  16934. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  16935. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  16936. }
  16937. }
  16938. // build geometry
  16939. this.setIndex( indices );
  16940. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16941. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16942. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16943. }
  16944. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16945. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  16946. /**
  16947. * @author Kaleb Murphy
  16948. * @author Mugen87 / https://github.com/Mugen87
  16949. */
  16950. // RingGeometry
  16951. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  16952. Geometry.call( this );
  16953. this.type = 'RingGeometry';
  16954. this.parameters = {
  16955. innerRadius: innerRadius,
  16956. outerRadius: outerRadius,
  16957. thetaSegments: thetaSegments,
  16958. phiSegments: phiSegments,
  16959. thetaStart: thetaStart,
  16960. thetaLength: thetaLength
  16961. };
  16962. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  16963. this.mergeVertices();
  16964. }
  16965. RingGeometry.prototype = Object.create( Geometry.prototype );
  16966. RingGeometry.prototype.constructor = RingGeometry;
  16967. // RingBufferGeometry
  16968. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  16969. BufferGeometry.call( this );
  16970. this.type = 'RingBufferGeometry';
  16971. this.parameters = {
  16972. innerRadius: innerRadius,
  16973. outerRadius: outerRadius,
  16974. thetaSegments: thetaSegments,
  16975. phiSegments: phiSegments,
  16976. thetaStart: thetaStart,
  16977. thetaLength: thetaLength
  16978. };
  16979. innerRadius = innerRadius || 0.5;
  16980. outerRadius = outerRadius || 1;
  16981. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  16982. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  16983. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  16984. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  16985. // buffers
  16986. var indices = [];
  16987. var vertices = [];
  16988. var normals = [];
  16989. var uvs = [];
  16990. // some helper variables
  16991. var segment;
  16992. var radius = innerRadius;
  16993. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  16994. var vertex = new Vector3();
  16995. var uv = new Vector2();
  16996. var j, i;
  16997. // generate vertices, normals and uvs
  16998. for ( j = 0; j <= phiSegments; j ++ ) {
  16999. for ( i = 0; i <= thetaSegments; i ++ ) {
  17000. // values are generate from the inside of the ring to the outside
  17001. segment = thetaStart + i / thetaSegments * thetaLength;
  17002. // vertex
  17003. vertex.x = radius * Math.cos( segment );
  17004. vertex.y = radius * Math.sin( segment );
  17005. vertices.push( vertex.x, vertex.y, vertex.z );
  17006. // normal
  17007. normals.push( 0, 0, 1 );
  17008. // uv
  17009. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  17010. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  17011. uvs.push( uv.x, uv.y );
  17012. }
  17013. // increase the radius for next row of vertices
  17014. radius += radiusStep;
  17015. }
  17016. // indices
  17017. for ( j = 0; j < phiSegments; j ++ ) {
  17018. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  17019. for ( i = 0; i < thetaSegments; i ++ ) {
  17020. segment = i + thetaSegmentLevel;
  17021. var a = segment;
  17022. var b = segment + thetaSegments + 1;
  17023. var c = segment + thetaSegments + 2;
  17024. var d = segment + 1;
  17025. // faces
  17026. indices.push( a, b, d );
  17027. indices.push( b, c, d );
  17028. }
  17029. }
  17030. // build geometry
  17031. this.setIndex( indices );
  17032. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17033. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17034. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17035. }
  17036. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17037. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  17038. /**
  17039. * @author astrodud / http://astrodud.isgreat.org/
  17040. * @author zz85 / https://github.com/zz85
  17041. * @author bhouston / http://clara.io
  17042. * @author Mugen87 / https://github.com/Mugen87
  17043. */
  17044. // LatheGeometry
  17045. function LatheGeometry( points, segments, phiStart, phiLength ) {
  17046. Geometry.call( this );
  17047. this.type = 'LatheGeometry';
  17048. this.parameters = {
  17049. points: points,
  17050. segments: segments,
  17051. phiStart: phiStart,
  17052. phiLength: phiLength
  17053. };
  17054. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  17055. this.mergeVertices();
  17056. }
  17057. LatheGeometry.prototype = Object.create( Geometry.prototype );
  17058. LatheGeometry.prototype.constructor = LatheGeometry;
  17059. // LatheBufferGeometry
  17060. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  17061. BufferGeometry.call( this );
  17062. this.type = 'LatheBufferGeometry';
  17063. this.parameters = {
  17064. points: points,
  17065. segments: segments,
  17066. phiStart: phiStart,
  17067. phiLength: phiLength
  17068. };
  17069. segments = Math.floor( segments ) || 12;
  17070. phiStart = phiStart || 0;
  17071. phiLength = phiLength || Math.PI * 2;
  17072. // clamp phiLength so it's in range of [ 0, 2PI ]
  17073. phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
  17074. // buffers
  17075. var indices = [];
  17076. var vertices = [];
  17077. var uvs = [];
  17078. // helper variables
  17079. var base;
  17080. var inverseSegments = 1.0 / segments;
  17081. var vertex = new Vector3();
  17082. var uv = new Vector2();
  17083. var i, j;
  17084. // generate vertices and uvs
  17085. for ( i = 0; i <= segments; i ++ ) {
  17086. var phi = phiStart + i * inverseSegments * phiLength;
  17087. var sin = Math.sin( phi );
  17088. var cos = Math.cos( phi );
  17089. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  17090. // vertex
  17091. vertex.x = points[ j ].x * sin;
  17092. vertex.y = points[ j ].y;
  17093. vertex.z = points[ j ].x * cos;
  17094. vertices.push( vertex.x, vertex.y, vertex.z );
  17095. // uv
  17096. uv.x = i / segments;
  17097. uv.y = j / ( points.length - 1 );
  17098. uvs.push( uv.x, uv.y );
  17099. }
  17100. }
  17101. // indices
  17102. for ( i = 0; i < segments; i ++ ) {
  17103. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  17104. base = j + i * points.length;
  17105. var a = base;
  17106. var b = base + points.length;
  17107. var c = base + points.length + 1;
  17108. var d = base + 1;
  17109. // faces
  17110. indices.push( a, b, d );
  17111. indices.push( b, c, d );
  17112. }
  17113. }
  17114. // build geometry
  17115. this.setIndex( indices );
  17116. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17117. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17118. // generate normals
  17119. this.computeVertexNormals();
  17120. // if the geometry is closed, we need to average the normals along the seam.
  17121. // because the corresponding vertices are identical (but still have different UVs).
  17122. if ( phiLength === Math.PI * 2 ) {
  17123. var normals = this.attributes.normal.array;
  17124. var n1 = new Vector3();
  17125. var n2 = new Vector3();
  17126. var n = new Vector3();
  17127. // this is the buffer offset for the last line of vertices
  17128. base = segments * points.length * 3;
  17129. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  17130. // select the normal of the vertex in the first line
  17131. n1.x = normals[ j + 0 ];
  17132. n1.y = normals[ j + 1 ];
  17133. n1.z = normals[ j + 2 ];
  17134. // select the normal of the vertex in the last line
  17135. n2.x = normals[ base + j + 0 ];
  17136. n2.y = normals[ base + j + 1 ];
  17137. n2.z = normals[ base + j + 2 ];
  17138. // average normals
  17139. n.addVectors( n1, n2 ).normalize();
  17140. // assign the new values to both normals
  17141. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  17142. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  17143. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  17144. }
  17145. }
  17146. }
  17147. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17148. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  17149. /**
  17150. * @author jonobr1 / http://jonobr1.com
  17151. * @author Mugen87 / https://github.com/Mugen87
  17152. */
  17153. // ShapeGeometry
  17154. function ShapeGeometry( shapes, curveSegments ) {
  17155. Geometry.call( this );
  17156. this.type = 'ShapeGeometry';
  17157. if ( typeof curveSegments === 'object' ) {
  17158. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  17159. curveSegments = curveSegments.curveSegments;
  17160. }
  17161. this.parameters = {
  17162. shapes: shapes,
  17163. curveSegments: curveSegments
  17164. };
  17165. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  17166. this.mergeVertices();
  17167. }
  17168. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  17169. ShapeGeometry.prototype.constructor = ShapeGeometry;
  17170. ShapeGeometry.prototype.toJSON = function () {
  17171. var data = Geometry.prototype.toJSON.call( this );
  17172. var shapes = this.parameters.shapes;
  17173. return toJSON( shapes, data );
  17174. };
  17175. // ShapeBufferGeometry
  17176. function ShapeBufferGeometry( shapes, curveSegments ) {
  17177. BufferGeometry.call( this );
  17178. this.type = 'ShapeBufferGeometry';
  17179. this.parameters = {
  17180. shapes: shapes,
  17181. curveSegments: curveSegments
  17182. };
  17183. curveSegments = curveSegments || 12;
  17184. // buffers
  17185. var indices = [];
  17186. var vertices = [];
  17187. var normals = [];
  17188. var uvs = [];
  17189. // helper variables
  17190. var groupStart = 0;
  17191. var groupCount = 0;
  17192. // allow single and array values for "shapes" parameter
  17193. if ( Array.isArray( shapes ) === false ) {
  17194. addShape( shapes );
  17195. } else {
  17196. for ( var i = 0; i < shapes.length; i ++ ) {
  17197. addShape( shapes[ i ] );
  17198. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  17199. groupStart += groupCount;
  17200. groupCount = 0;
  17201. }
  17202. }
  17203. // build geometry
  17204. this.setIndex( indices );
  17205. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17206. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17207. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17208. // helper functions
  17209. function addShape( shape ) {
  17210. var i, l, shapeHole;
  17211. var indexOffset = vertices.length / 3;
  17212. var points = shape.extractPoints( curveSegments );
  17213. var shapeVertices = points.shape;
  17214. var shapeHoles = points.holes;
  17215. // check direction of vertices
  17216. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  17217. shapeVertices = shapeVertices.reverse();
  17218. // also check if holes are in the opposite direction
  17219. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  17220. shapeHole = shapeHoles[ i ];
  17221. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  17222. shapeHoles[ i ] = shapeHole.reverse();
  17223. }
  17224. }
  17225. }
  17226. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  17227. // join vertices of inner and outer paths to a single array
  17228. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  17229. shapeHole = shapeHoles[ i ];
  17230. shapeVertices = shapeVertices.concat( shapeHole );
  17231. }
  17232. // vertices, normals, uvs
  17233. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  17234. var vertex = shapeVertices[ i ];
  17235. vertices.push( vertex.x, vertex.y, 0 );
  17236. normals.push( 0, 0, 1 );
  17237. uvs.push( vertex.x, vertex.y ); // world uvs
  17238. }
  17239. // incides
  17240. for ( i = 0, l = faces.length; i < l; i ++ ) {
  17241. var face = faces[ i ];
  17242. var a = face[ 0 ] + indexOffset;
  17243. var b = face[ 1 ] + indexOffset;
  17244. var c = face[ 2 ] + indexOffset;
  17245. indices.push( a, b, c );
  17246. groupCount += 3;
  17247. }
  17248. }
  17249. }
  17250. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17251. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  17252. ShapeBufferGeometry.prototype.toJSON = function () {
  17253. var data = BufferGeometry.prototype.toJSON.call( this );
  17254. var shapes = this.parameters.shapes;
  17255. return toJSON( shapes, data );
  17256. };
  17257. //
  17258. function toJSON( shapes, data ) {
  17259. data.shapes = [];
  17260. if ( Array.isArray( shapes ) ) {
  17261. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  17262. var shape = shapes[ i ];
  17263. data.shapes.push( shape.uuid );
  17264. }
  17265. } else {
  17266. data.shapes.push( shapes.uuid );
  17267. }
  17268. return data;
  17269. }
  17270. /**
  17271. * @author WestLangley / http://github.com/WestLangley
  17272. * @author Mugen87 / https://github.com/Mugen87
  17273. */
  17274. function EdgesGeometry( geometry, thresholdAngle ) {
  17275. BufferGeometry.call( this );
  17276. this.type = 'EdgesGeometry';
  17277. this.parameters = {
  17278. thresholdAngle: thresholdAngle
  17279. };
  17280. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  17281. // buffer
  17282. var vertices = [];
  17283. // helper variables
  17284. var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
  17285. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  17286. var key, keys = [ 'a', 'b', 'c' ];
  17287. // prepare source geometry
  17288. var geometry2;
  17289. if ( geometry.isBufferGeometry ) {
  17290. geometry2 = new Geometry();
  17291. geometry2.fromBufferGeometry( geometry );
  17292. } else {
  17293. geometry2 = geometry.clone();
  17294. }
  17295. geometry2.mergeVertices();
  17296. geometry2.computeFaceNormals();
  17297. var sourceVertices = geometry2.vertices;
  17298. var faces = geometry2.faces;
  17299. // now create a data structure where each entry represents an edge with its adjoining faces
  17300. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  17301. var face = faces[ i ];
  17302. for ( var j = 0; j < 3; j ++ ) {
  17303. edge1 = face[ keys[ j ] ];
  17304. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  17305. edge[ 0 ] = Math.min( edge1, edge2 );
  17306. edge[ 1 ] = Math.max( edge1, edge2 );
  17307. key = edge[ 0 ] + ',' + edge[ 1 ];
  17308. if ( edges[ key ] === undefined ) {
  17309. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  17310. } else {
  17311. edges[ key ].face2 = i;
  17312. }
  17313. }
  17314. }
  17315. // generate vertices
  17316. for ( key in edges ) {
  17317. var e = edges[ key ];
  17318. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  17319. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  17320. var vertex = sourceVertices[ e.index1 ];
  17321. vertices.push( vertex.x, vertex.y, vertex.z );
  17322. vertex = sourceVertices[ e.index2 ];
  17323. vertices.push( vertex.x, vertex.y, vertex.z );
  17324. }
  17325. }
  17326. // build geometry
  17327. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17328. }
  17329. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  17330. EdgesGeometry.prototype.constructor = EdgesGeometry;
  17331. /**
  17332. * @author mrdoob / http://mrdoob.com/
  17333. * @author Mugen87 / https://github.com/Mugen87
  17334. */
  17335. // CylinderGeometry
  17336. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  17337. Geometry.call( this );
  17338. this.type = 'CylinderGeometry';
  17339. this.parameters = {
  17340. radiusTop: radiusTop,
  17341. radiusBottom: radiusBottom,
  17342. height: height,
  17343. radialSegments: radialSegments,
  17344. heightSegments: heightSegments,
  17345. openEnded: openEnded,
  17346. thetaStart: thetaStart,
  17347. thetaLength: thetaLength
  17348. };
  17349. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  17350. this.mergeVertices();
  17351. }
  17352. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  17353. CylinderGeometry.prototype.constructor = CylinderGeometry;
  17354. // CylinderBufferGeometry
  17355. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  17356. BufferGeometry.call( this );
  17357. this.type = 'CylinderBufferGeometry';
  17358. this.parameters = {
  17359. radiusTop: radiusTop,
  17360. radiusBottom: radiusBottom,
  17361. height: height,
  17362. radialSegments: radialSegments,
  17363. heightSegments: heightSegments,
  17364. openEnded: openEnded,
  17365. thetaStart: thetaStart,
  17366. thetaLength: thetaLength
  17367. };
  17368. var scope = this;
  17369. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  17370. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  17371. height = height || 1;
  17372. radialSegments = Math.floor( radialSegments ) || 8;
  17373. heightSegments = Math.floor( heightSegments ) || 1;
  17374. openEnded = openEnded !== undefined ? openEnded : false;
  17375. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  17376. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  17377. // buffers
  17378. var indices = [];
  17379. var vertices = [];
  17380. var normals = [];
  17381. var uvs = [];
  17382. // helper variables
  17383. var index = 0;
  17384. var indexArray = [];
  17385. var halfHeight = height / 2;
  17386. var groupStart = 0;
  17387. // generate geometry
  17388. generateTorso();
  17389. if ( openEnded === false ) {
  17390. if ( radiusTop > 0 ) generateCap( true );
  17391. if ( radiusBottom > 0 ) generateCap( false );
  17392. }
  17393. // build geometry
  17394. this.setIndex( indices );
  17395. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17396. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17397. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17398. function generateTorso() {
  17399. var x, y;
  17400. var normal = new Vector3();
  17401. var vertex = new Vector3();
  17402. var groupCount = 0;
  17403. // this will be used to calculate the normal
  17404. var slope = ( radiusBottom - radiusTop ) / height;
  17405. // generate vertices, normals and uvs
  17406. for ( y = 0; y <= heightSegments; y ++ ) {
  17407. var indexRow = [];
  17408. var v = y / heightSegments;
  17409. // calculate the radius of the current row
  17410. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  17411. for ( x = 0; x <= radialSegments; x ++ ) {
  17412. var u = x / radialSegments;
  17413. var theta = u * thetaLength + thetaStart;
  17414. var sinTheta = Math.sin( theta );
  17415. var cosTheta = Math.cos( theta );
  17416. // vertex
  17417. vertex.x = radius * sinTheta;
  17418. vertex.y = - v * height + halfHeight;
  17419. vertex.z = radius * cosTheta;
  17420. vertices.push( vertex.x, vertex.y, vertex.z );
  17421. // normal
  17422. normal.set( sinTheta, slope, cosTheta ).normalize();
  17423. normals.push( normal.x, normal.y, normal.z );
  17424. // uv
  17425. uvs.push( u, 1 - v );
  17426. // save index of vertex in respective row
  17427. indexRow.push( index ++ );
  17428. }
  17429. // now save vertices of the row in our index array
  17430. indexArray.push( indexRow );
  17431. }
  17432. // generate indices
  17433. for ( x = 0; x < radialSegments; x ++ ) {
  17434. for ( y = 0; y < heightSegments; y ++ ) {
  17435. // we use the index array to access the correct indices
  17436. var a = indexArray[ y ][ x ];
  17437. var b = indexArray[ y + 1 ][ x ];
  17438. var c = indexArray[ y + 1 ][ x + 1 ];
  17439. var d = indexArray[ y ][ x + 1 ];
  17440. // faces
  17441. indices.push( a, b, d );
  17442. indices.push( b, c, d );
  17443. // update group counter
  17444. groupCount += 6;
  17445. }
  17446. }
  17447. // add a group to the geometry. this will ensure multi material support
  17448. scope.addGroup( groupStart, groupCount, 0 );
  17449. // calculate new start value for groups
  17450. groupStart += groupCount;
  17451. }
  17452. function generateCap( top ) {
  17453. var x, centerIndexStart, centerIndexEnd;
  17454. var uv = new Vector2();
  17455. var vertex = new Vector3();
  17456. var groupCount = 0;
  17457. var radius = ( top === true ) ? radiusTop : radiusBottom;
  17458. var sign = ( top === true ) ? 1 : - 1;
  17459. // save the index of the first center vertex
  17460. centerIndexStart = index;
  17461. // first we generate the center vertex data of the cap.
  17462. // because the geometry needs one set of uvs per face,
  17463. // we must generate a center vertex per face/segment
  17464. for ( x = 1; x <= radialSegments; x ++ ) {
  17465. // vertex
  17466. vertices.push( 0, halfHeight * sign, 0 );
  17467. // normal
  17468. normals.push( 0, sign, 0 );
  17469. // uv
  17470. uvs.push( 0.5, 0.5 );
  17471. // increase index
  17472. index ++;
  17473. }
  17474. // save the index of the last center vertex
  17475. centerIndexEnd = index;
  17476. // now we generate the surrounding vertices, normals and uvs
  17477. for ( x = 0; x <= radialSegments; x ++ ) {
  17478. var u = x / radialSegments;
  17479. var theta = u * thetaLength + thetaStart;
  17480. var cosTheta = Math.cos( theta );
  17481. var sinTheta = Math.sin( theta );
  17482. // vertex
  17483. vertex.x = radius * sinTheta;
  17484. vertex.y = halfHeight * sign;
  17485. vertex.z = radius * cosTheta;
  17486. vertices.push( vertex.x, vertex.y, vertex.z );
  17487. // normal
  17488. normals.push( 0, sign, 0 );
  17489. // uv
  17490. uv.x = ( cosTheta * 0.5 ) + 0.5;
  17491. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  17492. uvs.push( uv.x, uv.y );
  17493. // increase index
  17494. index ++;
  17495. }
  17496. // generate indices
  17497. for ( x = 0; x < radialSegments; x ++ ) {
  17498. var c = centerIndexStart + x;
  17499. var i = centerIndexEnd + x;
  17500. if ( top === true ) {
  17501. // face top
  17502. indices.push( i, i + 1, c );
  17503. } else {
  17504. // face bottom
  17505. indices.push( i + 1, i, c );
  17506. }
  17507. groupCount += 3;
  17508. }
  17509. // add a group to the geometry. this will ensure multi material support
  17510. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  17511. // calculate new start value for groups
  17512. groupStart += groupCount;
  17513. }
  17514. }
  17515. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17516. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  17517. /**
  17518. * @author abelnation / http://github.com/abelnation
  17519. */
  17520. // ConeGeometry
  17521. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  17522. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  17523. this.type = 'ConeGeometry';
  17524. this.parameters = {
  17525. radius: radius,
  17526. height: height,
  17527. radialSegments: radialSegments,
  17528. heightSegments: heightSegments,
  17529. openEnded: openEnded,
  17530. thetaStart: thetaStart,
  17531. thetaLength: thetaLength
  17532. };
  17533. }
  17534. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  17535. ConeGeometry.prototype.constructor = ConeGeometry;
  17536. // ConeBufferGeometry
  17537. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  17538. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  17539. this.type = 'ConeBufferGeometry';
  17540. this.parameters = {
  17541. radius: radius,
  17542. height: height,
  17543. radialSegments: radialSegments,
  17544. heightSegments: heightSegments,
  17545. openEnded: openEnded,
  17546. thetaStart: thetaStart,
  17547. thetaLength: thetaLength
  17548. };
  17549. }
  17550. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  17551. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  17552. /**
  17553. * @author benaadams / https://twitter.com/ben_a_adams
  17554. * @author Mugen87 / https://github.com/Mugen87
  17555. * @author hughes
  17556. */
  17557. // CircleGeometry
  17558. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  17559. Geometry.call( this );
  17560. this.type = 'CircleGeometry';
  17561. this.parameters = {
  17562. radius: radius,
  17563. segments: segments,
  17564. thetaStart: thetaStart,
  17565. thetaLength: thetaLength
  17566. };
  17567. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  17568. this.mergeVertices();
  17569. }
  17570. CircleGeometry.prototype = Object.create( Geometry.prototype );
  17571. CircleGeometry.prototype.constructor = CircleGeometry;
  17572. // CircleBufferGeometry
  17573. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  17574. BufferGeometry.call( this );
  17575. this.type = 'CircleBufferGeometry';
  17576. this.parameters = {
  17577. radius: radius,
  17578. segments: segments,
  17579. thetaStart: thetaStart,
  17580. thetaLength: thetaLength
  17581. };
  17582. radius = radius || 1;
  17583. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  17584. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  17585. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  17586. // buffers
  17587. var indices = [];
  17588. var vertices = [];
  17589. var normals = [];
  17590. var uvs = [];
  17591. // helper variables
  17592. var i, s;
  17593. var vertex = new Vector3();
  17594. var uv = new Vector2();
  17595. // center point
  17596. vertices.push( 0, 0, 0 );
  17597. normals.push( 0, 0, 1 );
  17598. uvs.push( 0.5, 0.5 );
  17599. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  17600. var segment = thetaStart + s / segments * thetaLength;
  17601. // vertex
  17602. vertex.x = radius * Math.cos( segment );
  17603. vertex.y = radius * Math.sin( segment );
  17604. vertices.push( vertex.x, vertex.y, vertex.z );
  17605. // normal
  17606. normals.push( 0, 0, 1 );
  17607. // uvs
  17608. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  17609. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  17610. uvs.push( uv.x, uv.y );
  17611. }
  17612. // indices
  17613. for ( i = 1; i <= segments; i ++ ) {
  17614. indices.push( i, i + 1, 0 );
  17615. }
  17616. // build geometry
  17617. this.setIndex( indices );
  17618. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17619. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17620. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17621. }
  17622. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17623. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  17624. var Geometries = Object.freeze({
  17625. WireframeGeometry: WireframeGeometry,
  17626. ParametricGeometry: ParametricGeometry,
  17627. ParametricBufferGeometry: ParametricBufferGeometry,
  17628. TetrahedronGeometry: TetrahedronGeometry,
  17629. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  17630. OctahedronGeometry: OctahedronGeometry,
  17631. OctahedronBufferGeometry: OctahedronBufferGeometry,
  17632. IcosahedronGeometry: IcosahedronGeometry,
  17633. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  17634. DodecahedronGeometry: DodecahedronGeometry,
  17635. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  17636. PolyhedronGeometry: PolyhedronGeometry,
  17637. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  17638. TubeGeometry: TubeGeometry,
  17639. TubeBufferGeometry: TubeBufferGeometry,
  17640. TorusKnotGeometry: TorusKnotGeometry,
  17641. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  17642. TorusGeometry: TorusGeometry,
  17643. TorusBufferGeometry: TorusBufferGeometry,
  17644. TextGeometry: TextGeometry,
  17645. TextBufferGeometry: TextBufferGeometry,
  17646. SphereGeometry: SphereGeometry,
  17647. SphereBufferGeometry: SphereBufferGeometry,
  17648. RingGeometry: RingGeometry,
  17649. RingBufferGeometry: RingBufferGeometry,
  17650. PlaneGeometry: PlaneGeometry,
  17651. PlaneBufferGeometry: PlaneBufferGeometry,
  17652. LatheGeometry: LatheGeometry,
  17653. LatheBufferGeometry: LatheBufferGeometry,
  17654. ShapeGeometry: ShapeGeometry,
  17655. ShapeBufferGeometry: ShapeBufferGeometry,
  17656. ExtrudeGeometry: ExtrudeGeometry,
  17657. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  17658. EdgesGeometry: EdgesGeometry,
  17659. ConeGeometry: ConeGeometry,
  17660. ConeBufferGeometry: ConeBufferGeometry,
  17661. CylinderGeometry: CylinderGeometry,
  17662. CylinderBufferGeometry: CylinderBufferGeometry,
  17663. CircleGeometry: CircleGeometry,
  17664. CircleBufferGeometry: CircleBufferGeometry,
  17665. BoxGeometry: BoxGeometry,
  17666. BoxBufferGeometry: BoxBufferGeometry
  17667. });
  17668. /**
  17669. * @author mrdoob / http://mrdoob.com/
  17670. *
  17671. * parameters = {
  17672. * color: <THREE.Color>
  17673. * }
  17674. */
  17675. function ShadowMaterial( parameters ) {
  17676. Material.call( this );
  17677. this.type = 'ShadowMaterial';
  17678. this.color = new Color( 0x000000 );
  17679. this.transparent = true;
  17680. this.setValues( parameters );
  17681. }
  17682. ShadowMaterial.prototype = Object.create( Material.prototype );
  17683. ShadowMaterial.prototype.constructor = ShadowMaterial;
  17684. ShadowMaterial.prototype.isShadowMaterial = true;
  17685. ShadowMaterial.prototype.copy = function ( source ) {
  17686. Material.prototype.copy.call( this, source );
  17687. this.color.copy( source.color );
  17688. return this;
  17689. };
  17690. /**
  17691. * @author mrdoob / http://mrdoob.com/
  17692. */
  17693. function RawShaderMaterial( parameters ) {
  17694. ShaderMaterial.call( this, parameters );
  17695. this.type = 'RawShaderMaterial';
  17696. }
  17697. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  17698. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  17699. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  17700. /**
  17701. * @author WestLangley / http://github.com/WestLangley
  17702. *
  17703. * parameters = {
  17704. * color: <hex>,
  17705. * roughness: <float>,
  17706. * metalness: <float>,
  17707. * opacity: <float>,
  17708. *
  17709. * map: new THREE.Texture( <Image> ),
  17710. *
  17711. * lightMap: new THREE.Texture( <Image> ),
  17712. * lightMapIntensity: <float>
  17713. *
  17714. * aoMap: new THREE.Texture( <Image> ),
  17715. * aoMapIntensity: <float>
  17716. *
  17717. * emissive: <hex>,
  17718. * emissiveIntensity: <float>
  17719. * emissiveMap: new THREE.Texture( <Image> ),
  17720. *
  17721. * bumpMap: new THREE.Texture( <Image> ),
  17722. * bumpScale: <float>,
  17723. *
  17724. * normalMap: new THREE.Texture( <Image> ),
  17725. * normalScale: <Vector2>,
  17726. *
  17727. * displacementMap: new THREE.Texture( <Image> ),
  17728. * displacementScale: <float>,
  17729. * displacementBias: <float>,
  17730. *
  17731. * roughnessMap: new THREE.Texture( <Image> ),
  17732. *
  17733. * metalnessMap: new THREE.Texture( <Image> ),
  17734. *
  17735. * alphaMap: new THREE.Texture( <Image> ),
  17736. *
  17737. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  17738. * envMapIntensity: <float>
  17739. *
  17740. * refractionRatio: <float>,
  17741. *
  17742. * wireframe: <boolean>,
  17743. * wireframeLinewidth: <float>,
  17744. *
  17745. * skinning: <bool>,
  17746. * morphTargets: <bool>,
  17747. * morphNormals: <bool>
  17748. * }
  17749. */
  17750. function MeshStandardMaterial( parameters ) {
  17751. Material.call( this );
  17752. this.defines = { 'STANDARD': '' };
  17753. this.type = 'MeshStandardMaterial';
  17754. this.color = new Color( 0xffffff ); // diffuse
  17755. this.roughness = 0.5;
  17756. this.metalness = 0.5;
  17757. this.map = null;
  17758. this.lightMap = null;
  17759. this.lightMapIntensity = 1.0;
  17760. this.aoMap = null;
  17761. this.aoMapIntensity = 1.0;
  17762. this.emissive = new Color( 0x000000 );
  17763. this.emissiveIntensity = 1.0;
  17764. this.emissiveMap = null;
  17765. this.bumpMap = null;
  17766. this.bumpScale = 1;
  17767. this.normalMap = null;
  17768. this.normalScale = new Vector2( 1, 1 );
  17769. this.displacementMap = null;
  17770. this.displacementScale = 1;
  17771. this.displacementBias = 0;
  17772. this.roughnessMap = null;
  17773. this.metalnessMap = null;
  17774. this.alphaMap = null;
  17775. this.envMap = null;
  17776. this.envMapIntensity = 1.0;
  17777. this.refractionRatio = 0.98;
  17778. this.wireframe = false;
  17779. this.wireframeLinewidth = 1;
  17780. this.wireframeLinecap = 'round';
  17781. this.wireframeLinejoin = 'round';
  17782. this.skinning = false;
  17783. this.morphTargets = false;
  17784. this.morphNormals = false;
  17785. this.setValues( parameters );
  17786. }
  17787. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  17788. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  17789. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  17790. MeshStandardMaterial.prototype.copy = function ( source ) {
  17791. Material.prototype.copy.call( this, source );
  17792. this.defines = { 'STANDARD': '' };
  17793. this.color.copy( source.color );
  17794. this.roughness = source.roughness;
  17795. this.metalness = source.metalness;
  17796. this.map = source.map;
  17797. this.lightMap = source.lightMap;
  17798. this.lightMapIntensity = source.lightMapIntensity;
  17799. this.aoMap = source.aoMap;
  17800. this.aoMapIntensity = source.aoMapIntensity;
  17801. this.emissive.copy( source.emissive );
  17802. this.emissiveMap = source.emissiveMap;
  17803. this.emissiveIntensity = source.emissiveIntensity;
  17804. this.bumpMap = source.bumpMap;
  17805. this.bumpScale = source.bumpScale;
  17806. this.normalMap = source.normalMap;
  17807. this.normalScale.copy( source.normalScale );
  17808. this.displacementMap = source.displacementMap;
  17809. this.displacementScale = source.displacementScale;
  17810. this.displacementBias = source.displacementBias;
  17811. this.roughnessMap = source.roughnessMap;
  17812. this.metalnessMap = source.metalnessMap;
  17813. this.alphaMap = source.alphaMap;
  17814. this.envMap = source.envMap;
  17815. this.envMapIntensity = source.envMapIntensity;
  17816. this.refractionRatio = source.refractionRatio;
  17817. this.wireframe = source.wireframe;
  17818. this.wireframeLinewidth = source.wireframeLinewidth;
  17819. this.wireframeLinecap = source.wireframeLinecap;
  17820. this.wireframeLinejoin = source.wireframeLinejoin;
  17821. this.skinning = source.skinning;
  17822. this.morphTargets = source.morphTargets;
  17823. this.morphNormals = source.morphNormals;
  17824. return this;
  17825. };
  17826. /**
  17827. * @author WestLangley / http://github.com/WestLangley
  17828. *
  17829. * parameters = {
  17830. * reflectivity: <float>
  17831. * }
  17832. */
  17833. function MeshPhysicalMaterial( parameters ) {
  17834. MeshStandardMaterial.call( this );
  17835. this.defines = { 'PHYSICAL': '' };
  17836. this.type = 'MeshPhysicalMaterial';
  17837. this.reflectivity = 0.5; // maps to F0 = 0.04
  17838. this.clearCoat = 0.0;
  17839. this.clearCoatRoughness = 0.0;
  17840. this.setValues( parameters );
  17841. }
  17842. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  17843. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  17844. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  17845. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  17846. MeshStandardMaterial.prototype.copy.call( this, source );
  17847. this.defines = { 'PHYSICAL': '' };
  17848. this.reflectivity = source.reflectivity;
  17849. this.clearCoat = source.clearCoat;
  17850. this.clearCoatRoughness = source.clearCoatRoughness;
  17851. return this;
  17852. };
  17853. /**
  17854. * @author mrdoob / http://mrdoob.com/
  17855. * @author alteredq / http://alteredqualia.com/
  17856. *
  17857. * parameters = {
  17858. * color: <hex>,
  17859. * specular: <hex>,
  17860. * shininess: <float>,
  17861. * opacity: <float>,
  17862. *
  17863. * map: new THREE.Texture( <Image> ),
  17864. *
  17865. * lightMap: new THREE.Texture( <Image> ),
  17866. * lightMapIntensity: <float>
  17867. *
  17868. * aoMap: new THREE.Texture( <Image> ),
  17869. * aoMapIntensity: <float>
  17870. *
  17871. * emissive: <hex>,
  17872. * emissiveIntensity: <float>
  17873. * emissiveMap: new THREE.Texture( <Image> ),
  17874. *
  17875. * bumpMap: new THREE.Texture( <Image> ),
  17876. * bumpScale: <float>,
  17877. *
  17878. * normalMap: new THREE.Texture( <Image> ),
  17879. * normalScale: <Vector2>,
  17880. *
  17881. * displacementMap: new THREE.Texture( <Image> ),
  17882. * displacementScale: <float>,
  17883. * displacementBias: <float>,
  17884. *
  17885. * specularMap: new THREE.Texture( <Image> ),
  17886. *
  17887. * alphaMap: new THREE.Texture( <Image> ),
  17888. *
  17889. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  17890. * combine: THREE.Multiply,
  17891. * reflectivity: <float>,
  17892. * refractionRatio: <float>,
  17893. *
  17894. * wireframe: <boolean>,
  17895. * wireframeLinewidth: <float>,
  17896. *
  17897. * skinning: <bool>,
  17898. * morphTargets: <bool>,
  17899. * morphNormals: <bool>
  17900. * }
  17901. */
  17902. function MeshPhongMaterial( parameters ) {
  17903. Material.call( this );
  17904. this.type = 'MeshPhongMaterial';
  17905. this.color = new Color( 0xffffff ); // diffuse
  17906. this.specular = new Color( 0x111111 );
  17907. this.shininess = 30;
  17908. this.map = null;
  17909. this.lightMap = null;
  17910. this.lightMapIntensity = 1.0;
  17911. this.aoMap = null;
  17912. this.aoMapIntensity = 1.0;
  17913. this.emissive = new Color( 0x000000 );
  17914. this.emissiveIntensity = 1.0;
  17915. this.emissiveMap = null;
  17916. this.bumpMap = null;
  17917. this.bumpScale = 1;
  17918. this.normalMap = null;
  17919. this.normalScale = new Vector2( 1, 1 );
  17920. this.displacementMap = null;
  17921. this.displacementScale = 1;
  17922. this.displacementBias = 0;
  17923. this.specularMap = null;
  17924. this.alphaMap = null;
  17925. this.envMap = null;
  17926. this.combine = MultiplyOperation;
  17927. this.reflectivity = 1;
  17928. this.refractionRatio = 0.98;
  17929. this.wireframe = false;
  17930. this.wireframeLinewidth = 1;
  17931. this.wireframeLinecap = 'round';
  17932. this.wireframeLinejoin = 'round';
  17933. this.skinning = false;
  17934. this.morphTargets = false;
  17935. this.morphNormals = false;
  17936. this.setValues( parameters );
  17937. }
  17938. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  17939. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  17940. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  17941. MeshPhongMaterial.prototype.copy = function ( source ) {
  17942. Material.prototype.copy.call( this, source );
  17943. this.color.copy( source.color );
  17944. this.specular.copy( source.specular );
  17945. this.shininess = source.shininess;
  17946. this.map = source.map;
  17947. this.lightMap = source.lightMap;
  17948. this.lightMapIntensity = source.lightMapIntensity;
  17949. this.aoMap = source.aoMap;
  17950. this.aoMapIntensity = source.aoMapIntensity;
  17951. this.emissive.copy( source.emissive );
  17952. this.emissiveMap = source.emissiveMap;
  17953. this.emissiveIntensity = source.emissiveIntensity;
  17954. this.bumpMap = source.bumpMap;
  17955. this.bumpScale = source.bumpScale;
  17956. this.normalMap = source.normalMap;
  17957. this.normalScale.copy( source.normalScale );
  17958. this.displacementMap = source.displacementMap;
  17959. this.displacementScale = source.displacementScale;
  17960. this.displacementBias = source.displacementBias;
  17961. this.specularMap = source.specularMap;
  17962. this.alphaMap = source.alphaMap;
  17963. this.envMap = source.envMap;
  17964. this.combine = source.combine;
  17965. this.reflectivity = source.reflectivity;
  17966. this.refractionRatio = source.refractionRatio;
  17967. this.wireframe = source.wireframe;
  17968. this.wireframeLinewidth = source.wireframeLinewidth;
  17969. this.wireframeLinecap = source.wireframeLinecap;
  17970. this.wireframeLinejoin = source.wireframeLinejoin;
  17971. this.skinning = source.skinning;
  17972. this.morphTargets = source.morphTargets;
  17973. this.morphNormals = source.morphNormals;
  17974. return this;
  17975. };
  17976. /**
  17977. * @author takahirox / http://github.com/takahirox
  17978. *
  17979. * parameters = {
  17980. * gradientMap: new THREE.Texture( <Image> )
  17981. * }
  17982. */
  17983. function MeshToonMaterial( parameters ) {
  17984. MeshPhongMaterial.call( this );
  17985. this.defines = { 'TOON': '' };
  17986. this.type = 'MeshToonMaterial';
  17987. this.gradientMap = null;
  17988. this.setValues( parameters );
  17989. }
  17990. MeshToonMaterial.prototype = Object.create( MeshPhongMaterial.prototype );
  17991. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  17992. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  17993. MeshToonMaterial.prototype.copy = function ( source ) {
  17994. MeshPhongMaterial.prototype.copy.call( this, source );
  17995. this.gradientMap = source.gradientMap;
  17996. return this;
  17997. };
  17998. /**
  17999. * @author mrdoob / http://mrdoob.com/
  18000. * @author WestLangley / http://github.com/WestLangley
  18001. *
  18002. * parameters = {
  18003. * opacity: <float>,
  18004. *
  18005. * bumpMap: new THREE.Texture( <Image> ),
  18006. * bumpScale: <float>,
  18007. *
  18008. * normalMap: new THREE.Texture( <Image> ),
  18009. * normalScale: <Vector2>,
  18010. *
  18011. * displacementMap: new THREE.Texture( <Image> ),
  18012. * displacementScale: <float>,
  18013. * displacementBias: <float>,
  18014. *
  18015. * wireframe: <boolean>,
  18016. * wireframeLinewidth: <float>
  18017. *
  18018. * skinning: <bool>,
  18019. * morphTargets: <bool>,
  18020. * morphNormals: <bool>
  18021. * }
  18022. */
  18023. function MeshNormalMaterial( parameters ) {
  18024. Material.call( this );
  18025. this.type = 'MeshNormalMaterial';
  18026. this.bumpMap = null;
  18027. this.bumpScale = 1;
  18028. this.normalMap = null;
  18029. this.normalScale = new Vector2( 1, 1 );
  18030. this.displacementMap = null;
  18031. this.displacementScale = 1;
  18032. this.displacementBias = 0;
  18033. this.wireframe = false;
  18034. this.wireframeLinewidth = 1;
  18035. this.fog = false;
  18036. this.lights = false;
  18037. this.skinning = false;
  18038. this.morphTargets = false;
  18039. this.morphNormals = false;
  18040. this.setValues( parameters );
  18041. }
  18042. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  18043. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  18044. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  18045. MeshNormalMaterial.prototype.copy = function ( source ) {
  18046. Material.prototype.copy.call( this, source );
  18047. this.bumpMap = source.bumpMap;
  18048. this.bumpScale = source.bumpScale;
  18049. this.normalMap = source.normalMap;
  18050. this.normalScale.copy( source.normalScale );
  18051. this.displacementMap = source.displacementMap;
  18052. this.displacementScale = source.displacementScale;
  18053. this.displacementBias = source.displacementBias;
  18054. this.wireframe = source.wireframe;
  18055. this.wireframeLinewidth = source.wireframeLinewidth;
  18056. this.skinning = source.skinning;
  18057. this.morphTargets = source.morphTargets;
  18058. this.morphNormals = source.morphNormals;
  18059. return this;
  18060. };
  18061. /**
  18062. * @author mrdoob / http://mrdoob.com/
  18063. * @author alteredq / http://alteredqualia.com/
  18064. *
  18065. * parameters = {
  18066. * color: <hex>,
  18067. * opacity: <float>,
  18068. *
  18069. * map: new THREE.Texture( <Image> ),
  18070. *
  18071. * lightMap: new THREE.Texture( <Image> ),
  18072. * lightMapIntensity: <float>
  18073. *
  18074. * aoMap: new THREE.Texture( <Image> ),
  18075. * aoMapIntensity: <float>
  18076. *
  18077. * emissive: <hex>,
  18078. * emissiveIntensity: <float>
  18079. * emissiveMap: new THREE.Texture( <Image> ),
  18080. *
  18081. * specularMap: new THREE.Texture( <Image> ),
  18082. *
  18083. * alphaMap: new THREE.Texture( <Image> ),
  18084. *
  18085. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  18086. * combine: THREE.Multiply,
  18087. * reflectivity: <float>,
  18088. * refractionRatio: <float>,
  18089. *
  18090. * wireframe: <boolean>,
  18091. * wireframeLinewidth: <float>,
  18092. *
  18093. * skinning: <bool>,
  18094. * morphTargets: <bool>,
  18095. * morphNormals: <bool>
  18096. * }
  18097. */
  18098. function MeshLambertMaterial( parameters ) {
  18099. Material.call( this );
  18100. this.type = 'MeshLambertMaterial';
  18101. this.color = new Color( 0xffffff ); // diffuse
  18102. this.map = null;
  18103. this.lightMap = null;
  18104. this.lightMapIntensity = 1.0;
  18105. this.aoMap = null;
  18106. this.aoMapIntensity = 1.0;
  18107. this.emissive = new Color( 0x000000 );
  18108. this.emissiveIntensity = 1.0;
  18109. this.emissiveMap = null;
  18110. this.specularMap = null;
  18111. this.alphaMap = null;
  18112. this.envMap = null;
  18113. this.combine = MultiplyOperation;
  18114. this.reflectivity = 1;
  18115. this.refractionRatio = 0.98;
  18116. this.wireframe = false;
  18117. this.wireframeLinewidth = 1;
  18118. this.wireframeLinecap = 'round';
  18119. this.wireframeLinejoin = 'round';
  18120. this.skinning = false;
  18121. this.morphTargets = false;
  18122. this.morphNormals = false;
  18123. this.setValues( parameters );
  18124. }
  18125. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  18126. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  18127. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  18128. MeshLambertMaterial.prototype.copy = function ( source ) {
  18129. Material.prototype.copy.call( this, source );
  18130. this.color.copy( source.color );
  18131. this.map = source.map;
  18132. this.lightMap = source.lightMap;
  18133. this.lightMapIntensity = source.lightMapIntensity;
  18134. this.aoMap = source.aoMap;
  18135. this.aoMapIntensity = source.aoMapIntensity;
  18136. this.emissive.copy( source.emissive );
  18137. this.emissiveMap = source.emissiveMap;
  18138. this.emissiveIntensity = source.emissiveIntensity;
  18139. this.specularMap = source.specularMap;
  18140. this.alphaMap = source.alphaMap;
  18141. this.envMap = source.envMap;
  18142. this.combine = source.combine;
  18143. this.reflectivity = source.reflectivity;
  18144. this.refractionRatio = source.refractionRatio;
  18145. this.wireframe = source.wireframe;
  18146. this.wireframeLinewidth = source.wireframeLinewidth;
  18147. this.wireframeLinecap = source.wireframeLinecap;
  18148. this.wireframeLinejoin = source.wireframeLinejoin;
  18149. this.skinning = source.skinning;
  18150. this.morphTargets = source.morphTargets;
  18151. this.morphNormals = source.morphNormals;
  18152. return this;
  18153. };
  18154. /**
  18155. * @author alteredq / http://alteredqualia.com/
  18156. *
  18157. * parameters = {
  18158. * color: <hex>,
  18159. * opacity: <float>,
  18160. *
  18161. * linewidth: <float>,
  18162. *
  18163. * scale: <float>,
  18164. * dashSize: <float>,
  18165. * gapSize: <float>
  18166. * }
  18167. */
  18168. function LineDashedMaterial( parameters ) {
  18169. LineBasicMaterial.call( this );
  18170. this.type = 'LineDashedMaterial';
  18171. this.scale = 1;
  18172. this.dashSize = 3;
  18173. this.gapSize = 1;
  18174. this.setValues( parameters );
  18175. }
  18176. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  18177. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  18178. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  18179. LineDashedMaterial.prototype.copy = function ( source ) {
  18180. LineBasicMaterial.prototype.copy.call( this, source );
  18181. this.scale = source.scale;
  18182. this.dashSize = source.dashSize;
  18183. this.gapSize = source.gapSize;
  18184. return this;
  18185. };
  18186. var Materials = Object.freeze({
  18187. ShadowMaterial: ShadowMaterial,
  18188. SpriteMaterial: SpriteMaterial,
  18189. RawShaderMaterial: RawShaderMaterial,
  18190. ShaderMaterial: ShaderMaterial,
  18191. PointsMaterial: PointsMaterial,
  18192. MeshPhysicalMaterial: MeshPhysicalMaterial,
  18193. MeshStandardMaterial: MeshStandardMaterial,
  18194. MeshPhongMaterial: MeshPhongMaterial,
  18195. MeshToonMaterial: MeshToonMaterial,
  18196. MeshNormalMaterial: MeshNormalMaterial,
  18197. MeshLambertMaterial: MeshLambertMaterial,
  18198. MeshDepthMaterial: MeshDepthMaterial,
  18199. MeshDistanceMaterial: MeshDistanceMaterial,
  18200. MeshBasicMaterial: MeshBasicMaterial,
  18201. LineDashedMaterial: LineDashedMaterial,
  18202. LineBasicMaterial: LineBasicMaterial,
  18203. Material: Material
  18204. });
  18205. /**
  18206. * @author mrdoob / http://mrdoob.com/
  18207. */
  18208. var Cache = {
  18209. enabled: false,
  18210. files: {},
  18211. add: function ( key, file ) {
  18212. if ( this.enabled === false ) return;
  18213. // console.log( 'THREE.Cache', 'Adding key:', key );
  18214. this.files[ key ] = file;
  18215. },
  18216. get: function ( key ) {
  18217. if ( this.enabled === false ) return;
  18218. // console.log( 'THREE.Cache', 'Checking key:', key );
  18219. return this.files[ key ];
  18220. },
  18221. remove: function ( key ) {
  18222. delete this.files[ key ];
  18223. },
  18224. clear: function () {
  18225. this.files = {};
  18226. }
  18227. };
  18228. /**
  18229. * @author mrdoob / http://mrdoob.com/
  18230. */
  18231. function LoadingManager( onLoad, onProgress, onError ) {
  18232. var scope = this;
  18233. var isLoading = false;
  18234. var itemsLoaded = 0;
  18235. var itemsTotal = 0;
  18236. var urlModifier = undefined;
  18237. this.onStart = undefined;
  18238. this.onLoad = onLoad;
  18239. this.onProgress = onProgress;
  18240. this.onError = onError;
  18241. this.itemStart = function ( url ) {
  18242. itemsTotal ++;
  18243. if ( isLoading === false ) {
  18244. if ( scope.onStart !== undefined ) {
  18245. scope.onStart( url, itemsLoaded, itemsTotal );
  18246. }
  18247. }
  18248. isLoading = true;
  18249. };
  18250. this.itemEnd = function ( url ) {
  18251. itemsLoaded ++;
  18252. if ( scope.onProgress !== undefined ) {
  18253. scope.onProgress( url, itemsLoaded, itemsTotal );
  18254. }
  18255. if ( itemsLoaded === itemsTotal ) {
  18256. isLoading = false;
  18257. if ( scope.onLoad !== undefined ) {
  18258. scope.onLoad();
  18259. }
  18260. }
  18261. };
  18262. this.itemError = function ( url ) {
  18263. if ( scope.onError !== undefined ) {
  18264. scope.onError( url );
  18265. }
  18266. };
  18267. this.resolveURL = function ( url ) {
  18268. if ( urlModifier ) {
  18269. return urlModifier( url );
  18270. }
  18271. return url;
  18272. };
  18273. this.setURLModifier = function ( transform ) {
  18274. urlModifier = transform;
  18275. return this;
  18276. };
  18277. }
  18278. var DefaultLoadingManager = new LoadingManager();
  18279. /**
  18280. * @author mrdoob / http://mrdoob.com/
  18281. */
  18282. var loading = {};
  18283. function FileLoader( manager ) {
  18284. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18285. }
  18286. Object.assign( FileLoader.prototype, {
  18287. load: function ( url, onLoad, onProgress, onError ) {
  18288. if ( url === undefined ) url = '';
  18289. if ( this.path !== undefined ) url = this.path + url;
  18290. url = this.manager.resolveURL( url );
  18291. var scope = this;
  18292. var cached = Cache.get( url );
  18293. if ( cached !== undefined ) {
  18294. scope.manager.itemStart( url );
  18295. setTimeout( function () {
  18296. if ( onLoad ) onLoad( cached );
  18297. scope.manager.itemEnd( url );
  18298. }, 0 );
  18299. return cached;
  18300. }
  18301. // Check if request is duplicate
  18302. if ( loading[ url ] !== undefined ) {
  18303. loading[ url ].push( {
  18304. onLoad: onLoad,
  18305. onProgress: onProgress,
  18306. onError: onError
  18307. } );
  18308. return;
  18309. }
  18310. // Check for data: URI
  18311. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  18312. var dataUriRegexResult = url.match( dataUriRegex );
  18313. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  18314. if ( dataUriRegexResult ) {
  18315. var mimeType = dataUriRegexResult[ 1 ];
  18316. var isBase64 = !! dataUriRegexResult[ 2 ];
  18317. var data = dataUriRegexResult[ 3 ];
  18318. data = window.decodeURIComponent( data );
  18319. if ( isBase64 ) data = window.atob( data );
  18320. try {
  18321. var response;
  18322. var responseType = ( this.responseType || '' ).toLowerCase();
  18323. switch ( responseType ) {
  18324. case 'arraybuffer':
  18325. case 'blob':
  18326. var view = new Uint8Array( data.length );
  18327. for ( var i = 0; i < data.length; i ++ ) {
  18328. view[ i ] = data.charCodeAt( i );
  18329. }
  18330. if ( responseType === 'blob' ) {
  18331. response = new Blob( [ view.buffer ], { type: mimeType } );
  18332. } else {
  18333. response = view.buffer;
  18334. }
  18335. break;
  18336. case 'document':
  18337. var parser = new DOMParser();
  18338. response = parser.parseFromString( data, mimeType );
  18339. break;
  18340. case 'json':
  18341. response = JSON.parse( data );
  18342. break;
  18343. default: // 'text' or other
  18344. response = data;
  18345. break;
  18346. }
  18347. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  18348. window.setTimeout( function () {
  18349. if ( onLoad ) onLoad( response );
  18350. scope.manager.itemEnd( url );
  18351. }, 0 );
  18352. } catch ( error ) {
  18353. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  18354. window.setTimeout( function () {
  18355. if ( onError ) onError( error );
  18356. scope.manager.itemEnd( url );
  18357. scope.manager.itemError( url );
  18358. }, 0 );
  18359. }
  18360. } else {
  18361. // Initialise array for duplicate requests
  18362. loading[ url ] = [];
  18363. loading[ url ].push( {
  18364. onLoad: onLoad,
  18365. onProgress: onProgress,
  18366. onError: onError
  18367. } );
  18368. var request = new XMLHttpRequest();
  18369. request.open( 'GET', url, true );
  18370. request.addEventListener( 'load', function ( event ) {
  18371. var response = this.response;
  18372. Cache.add( url, response );
  18373. var callbacks = loading[ url ];
  18374. delete loading[ url ];
  18375. if ( this.status === 200 ) {
  18376. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  18377. var callback = callbacks[ i ];
  18378. if ( callback.onLoad ) callback.onLoad( response );
  18379. }
  18380. scope.manager.itemEnd( url );
  18381. } else if ( this.status === 0 ) {
  18382. // Some browsers return HTTP Status 0 when using non-http protocol
  18383. // e.g. 'file://' or 'data://'. Handle as success.
  18384. console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  18385. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  18386. var callback = callbacks[ i ];
  18387. if ( callback.onLoad ) callback.onLoad( response );
  18388. }
  18389. scope.manager.itemEnd( url );
  18390. } else {
  18391. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  18392. var callback = callbacks[ i ];
  18393. if ( callback.onError ) callback.onError( event );
  18394. }
  18395. scope.manager.itemEnd( url );
  18396. scope.manager.itemError( url );
  18397. }
  18398. }, false );
  18399. request.addEventListener( 'progress', function ( event ) {
  18400. var callbacks = loading[ url ];
  18401. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  18402. var callback = callbacks[ i ];
  18403. if ( callback.onProgress ) callback.onProgress( event );
  18404. }
  18405. }, false );
  18406. request.addEventListener( 'error', function ( event ) {
  18407. var callbacks = loading[ url ];
  18408. delete loading[ url ];
  18409. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  18410. var callback = callbacks[ i ];
  18411. if ( callback.onError ) callback.onError( event );
  18412. }
  18413. scope.manager.itemEnd( url );
  18414. scope.manager.itemError( url );
  18415. }, false );
  18416. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  18417. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  18418. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  18419. for ( var header in this.requestHeader ) {
  18420. request.setRequestHeader( header, this.requestHeader[ header ] );
  18421. }
  18422. request.send( null );
  18423. }
  18424. scope.manager.itemStart( url );
  18425. return request;
  18426. },
  18427. setPath: function ( value ) {
  18428. this.path = value;
  18429. return this;
  18430. },
  18431. setResponseType: function ( value ) {
  18432. this.responseType = value;
  18433. return this;
  18434. },
  18435. setWithCredentials: function ( value ) {
  18436. this.withCredentials = value;
  18437. return this;
  18438. },
  18439. setMimeType: function ( value ) {
  18440. this.mimeType = value;
  18441. return this;
  18442. },
  18443. setRequestHeader: function ( value ) {
  18444. this.requestHeader = value;
  18445. return this;
  18446. }
  18447. } );
  18448. /**
  18449. * @author mrdoob / http://mrdoob.com/
  18450. *
  18451. * Abstract Base class to block based textures loader (dds, pvr, ...)
  18452. */
  18453. function CompressedTextureLoader( manager ) {
  18454. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18455. // override in sub classes
  18456. this._parser = null;
  18457. }
  18458. Object.assign( CompressedTextureLoader.prototype, {
  18459. load: function ( url, onLoad, onProgress, onError ) {
  18460. var scope = this;
  18461. var images = [];
  18462. var texture = new CompressedTexture();
  18463. texture.image = images;
  18464. var loader = new FileLoader( this.manager );
  18465. loader.setPath( this.path );
  18466. loader.setResponseType( 'arraybuffer' );
  18467. function loadTexture( i ) {
  18468. loader.load( url[ i ], function ( buffer ) {
  18469. var texDatas = scope._parser( buffer, true );
  18470. images[ i ] = {
  18471. width: texDatas.width,
  18472. height: texDatas.height,
  18473. format: texDatas.format,
  18474. mipmaps: texDatas.mipmaps
  18475. };
  18476. loaded += 1;
  18477. if ( loaded === 6 ) {
  18478. if ( texDatas.mipmapCount === 1 )
  18479. texture.minFilter = LinearFilter;
  18480. texture.format = texDatas.format;
  18481. texture.needsUpdate = true;
  18482. if ( onLoad ) onLoad( texture );
  18483. }
  18484. }, onProgress, onError );
  18485. }
  18486. if ( Array.isArray( url ) ) {
  18487. var loaded = 0;
  18488. for ( var i = 0, il = url.length; i < il; ++ i ) {
  18489. loadTexture( i );
  18490. }
  18491. } else {
  18492. // compressed cubemap texture stored in a single DDS file
  18493. loader.load( url, function ( buffer ) {
  18494. var texDatas = scope._parser( buffer, true );
  18495. if ( texDatas.isCubemap ) {
  18496. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  18497. for ( var f = 0; f < faces; f ++ ) {
  18498. images[ f ] = { mipmaps: [] };
  18499. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  18500. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  18501. images[ f ].format = texDatas.format;
  18502. images[ f ].width = texDatas.width;
  18503. images[ f ].height = texDatas.height;
  18504. }
  18505. }
  18506. } else {
  18507. texture.image.width = texDatas.width;
  18508. texture.image.height = texDatas.height;
  18509. texture.mipmaps = texDatas.mipmaps;
  18510. }
  18511. if ( texDatas.mipmapCount === 1 ) {
  18512. texture.minFilter = LinearFilter;
  18513. }
  18514. texture.format = texDatas.format;
  18515. texture.needsUpdate = true;
  18516. if ( onLoad ) onLoad( texture );
  18517. }, onProgress, onError );
  18518. }
  18519. return texture;
  18520. },
  18521. setPath: function ( value ) {
  18522. this.path = value;
  18523. return this;
  18524. }
  18525. } );
  18526. /**
  18527. * @author Nikos M. / https://github.com/foo123/
  18528. *
  18529. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  18530. */
  18531. function DataTextureLoader( manager ) {
  18532. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18533. // override in sub classes
  18534. this._parser = null;
  18535. }
  18536. Object.assign( DataTextureLoader.prototype, {
  18537. load: function ( url, onLoad, onProgress, onError ) {
  18538. var scope = this;
  18539. var texture = new DataTexture();
  18540. var loader = new FileLoader( this.manager );
  18541. loader.setResponseType( 'arraybuffer' );
  18542. loader.load( url, function ( buffer ) {
  18543. var texData = scope._parser( buffer );
  18544. if ( ! texData ) return;
  18545. if ( undefined !== texData.image ) {
  18546. texture.image = texData.image;
  18547. } else if ( undefined !== texData.data ) {
  18548. texture.image.width = texData.width;
  18549. texture.image.height = texData.height;
  18550. texture.image.data = texData.data;
  18551. }
  18552. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : ClampToEdgeWrapping;
  18553. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : ClampToEdgeWrapping;
  18554. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : LinearFilter;
  18555. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : LinearMipMapLinearFilter;
  18556. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  18557. if ( undefined !== texData.format ) {
  18558. texture.format = texData.format;
  18559. }
  18560. if ( undefined !== texData.type ) {
  18561. texture.type = texData.type;
  18562. }
  18563. if ( undefined !== texData.mipmaps ) {
  18564. texture.mipmaps = texData.mipmaps;
  18565. }
  18566. if ( 1 === texData.mipmapCount ) {
  18567. texture.minFilter = LinearFilter;
  18568. }
  18569. texture.needsUpdate = true;
  18570. if ( onLoad ) onLoad( texture, texData );
  18571. }, onProgress, onError );
  18572. return texture;
  18573. }
  18574. } );
  18575. /**
  18576. * @author mrdoob / http://mrdoob.com/
  18577. */
  18578. function ImageLoader( manager ) {
  18579. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18580. }
  18581. Object.assign( ImageLoader.prototype, {
  18582. crossOrigin: 'Anonymous',
  18583. load: function ( url, onLoad, onProgress, onError ) {
  18584. if ( url === undefined ) url = '';
  18585. if ( this.path !== undefined ) url = this.path + url;
  18586. url = this.manager.resolveURL( url );
  18587. var scope = this;
  18588. var cached = Cache.get( url );
  18589. if ( cached !== undefined ) {
  18590. scope.manager.itemStart( url );
  18591. setTimeout( function () {
  18592. if ( onLoad ) onLoad( cached );
  18593. scope.manager.itemEnd( url );
  18594. }, 0 );
  18595. return cached;
  18596. }
  18597. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  18598. image.addEventListener( 'load', function () {
  18599. Cache.add( url, this );
  18600. if ( onLoad ) onLoad( this );
  18601. scope.manager.itemEnd( url );
  18602. }, false );
  18603. /*
  18604. image.addEventListener( 'progress', function ( event ) {
  18605. if ( onProgress ) onProgress( event );
  18606. }, false );
  18607. */
  18608. image.addEventListener( 'error', function ( event ) {
  18609. if ( onError ) onError( event );
  18610. scope.manager.itemEnd( url );
  18611. scope.manager.itemError( url );
  18612. }, false );
  18613. if ( url.substr( 0, 5 ) !== 'data:' ) {
  18614. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  18615. }
  18616. scope.manager.itemStart( url );
  18617. image.src = url;
  18618. return image;
  18619. },
  18620. setCrossOrigin: function ( value ) {
  18621. this.crossOrigin = value;
  18622. return this;
  18623. },
  18624. setPath: function ( value ) {
  18625. this.path = value;
  18626. return this;
  18627. }
  18628. } );
  18629. /**
  18630. * @author mrdoob / http://mrdoob.com/
  18631. */
  18632. function CubeTextureLoader( manager ) {
  18633. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18634. }
  18635. Object.assign( CubeTextureLoader.prototype, {
  18636. crossOrigin: 'Anonymous',
  18637. load: function ( urls, onLoad, onProgress, onError ) {
  18638. var texture = new CubeTexture();
  18639. var loader = new ImageLoader( this.manager );
  18640. loader.setCrossOrigin( this.crossOrigin );
  18641. loader.setPath( this.path );
  18642. var loaded = 0;
  18643. function loadTexture( i ) {
  18644. loader.load( urls[ i ], function ( image ) {
  18645. texture.images[ i ] = image;
  18646. loaded ++;
  18647. if ( loaded === 6 ) {
  18648. texture.needsUpdate = true;
  18649. if ( onLoad ) onLoad( texture );
  18650. }
  18651. }, undefined, onError );
  18652. }
  18653. for ( var i = 0; i < urls.length; ++ i ) {
  18654. loadTexture( i );
  18655. }
  18656. return texture;
  18657. },
  18658. setCrossOrigin: function ( value ) {
  18659. this.crossOrigin = value;
  18660. return this;
  18661. },
  18662. setPath: function ( value ) {
  18663. this.path = value;
  18664. return this;
  18665. }
  18666. } );
  18667. /**
  18668. * @author mrdoob / http://mrdoob.com/
  18669. */
  18670. function TextureLoader( manager ) {
  18671. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18672. }
  18673. Object.assign( TextureLoader.prototype, {
  18674. crossOrigin: 'Anonymous',
  18675. load: function ( url, onLoad, onProgress, onError ) {
  18676. var texture = new Texture();
  18677. var loader = new ImageLoader( this.manager );
  18678. loader.setCrossOrigin( this.crossOrigin );
  18679. loader.setPath( this.path );
  18680. loader.load( url, function ( image ) {
  18681. texture.image = image;
  18682. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  18683. var isJPEG = url.search( /\.(jpg|jpeg)$/ ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  18684. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  18685. texture.needsUpdate = true;
  18686. if ( onLoad !== undefined ) {
  18687. onLoad( texture );
  18688. }
  18689. }, onProgress, onError );
  18690. return texture;
  18691. },
  18692. setCrossOrigin: function ( value ) {
  18693. this.crossOrigin = value;
  18694. return this;
  18695. },
  18696. setPath: function ( value ) {
  18697. this.path = value;
  18698. return this;
  18699. }
  18700. } );
  18701. /**
  18702. * @author zz85 / http://www.lab4games.net/zz85/blog
  18703. * Extensible curve object
  18704. *
  18705. * Some common of curve methods:
  18706. * .getPoint( t, optionalTarget ), .getTangent( t )
  18707. * .getPointAt( u, optionalTarget ), .getTangentAt( u )
  18708. * .getPoints(), .getSpacedPoints()
  18709. * .getLength()
  18710. * .updateArcLengths()
  18711. *
  18712. * This following curves inherit from THREE.Curve:
  18713. *
  18714. * -- 2D curves --
  18715. * THREE.ArcCurve
  18716. * THREE.CubicBezierCurve
  18717. * THREE.EllipseCurve
  18718. * THREE.LineCurve
  18719. * THREE.QuadraticBezierCurve
  18720. * THREE.SplineCurve
  18721. *
  18722. * -- 3D curves --
  18723. * THREE.CatmullRomCurve3
  18724. * THREE.CubicBezierCurve3
  18725. * THREE.LineCurve3
  18726. * THREE.QuadraticBezierCurve3
  18727. *
  18728. * A series of curves can be represented as a THREE.CurvePath.
  18729. *
  18730. **/
  18731. /**************************************************************
  18732. * Abstract Curve base class
  18733. **************************************************************/
  18734. function Curve() {
  18735. this.type = 'Curve';
  18736. this.arcLengthDivisions = 200;
  18737. }
  18738. Object.assign( Curve.prototype, {
  18739. // Virtual base class method to overwrite and implement in subclasses
  18740. // - t [0 .. 1]
  18741. getPoint: function ( /* t, optionalTarget */ ) {
  18742. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  18743. return null;
  18744. },
  18745. // Get point at relative position in curve according to arc length
  18746. // - u [0 .. 1]
  18747. getPointAt: function ( u, optionalTarget ) {
  18748. var t = this.getUtoTmapping( u );
  18749. return this.getPoint( t, optionalTarget );
  18750. },
  18751. // Get sequence of points using getPoint( t )
  18752. getPoints: function ( divisions ) {
  18753. if ( divisions === undefined ) divisions = 5;
  18754. var points = [];
  18755. for ( var d = 0; d <= divisions; d ++ ) {
  18756. points.push( this.getPoint( d / divisions ) );
  18757. }
  18758. return points;
  18759. },
  18760. // Get sequence of points using getPointAt( u )
  18761. getSpacedPoints: function ( divisions ) {
  18762. if ( divisions === undefined ) divisions = 5;
  18763. var points = [];
  18764. for ( var d = 0; d <= divisions; d ++ ) {
  18765. points.push( this.getPointAt( d / divisions ) );
  18766. }
  18767. return points;
  18768. },
  18769. // Get total curve arc length
  18770. getLength: function () {
  18771. var lengths = this.getLengths();
  18772. return lengths[ lengths.length - 1 ];
  18773. },
  18774. // Get list of cumulative segment lengths
  18775. getLengths: function ( divisions ) {
  18776. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  18777. if ( this.cacheArcLengths &&
  18778. ( this.cacheArcLengths.length === divisions + 1 ) &&
  18779. ! this.needsUpdate ) {
  18780. return this.cacheArcLengths;
  18781. }
  18782. this.needsUpdate = false;
  18783. var cache = [];
  18784. var current, last = this.getPoint( 0 );
  18785. var p, sum = 0;
  18786. cache.push( 0 );
  18787. for ( p = 1; p <= divisions; p ++ ) {
  18788. current = this.getPoint( p / divisions );
  18789. sum += current.distanceTo( last );
  18790. cache.push( sum );
  18791. last = current;
  18792. }
  18793. this.cacheArcLengths = cache;
  18794. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  18795. },
  18796. updateArcLengths: function () {
  18797. this.needsUpdate = true;
  18798. this.getLengths();
  18799. },
  18800. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  18801. getUtoTmapping: function ( u, distance ) {
  18802. var arcLengths = this.getLengths();
  18803. var i = 0, il = arcLengths.length;
  18804. var targetArcLength; // The targeted u distance value to get
  18805. if ( distance ) {
  18806. targetArcLength = distance;
  18807. } else {
  18808. targetArcLength = u * arcLengths[ il - 1 ];
  18809. }
  18810. // binary search for the index with largest value smaller than target u distance
  18811. var low = 0, high = il - 1, comparison;
  18812. while ( low <= high ) {
  18813. 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
  18814. comparison = arcLengths[ i ] - targetArcLength;
  18815. if ( comparison < 0 ) {
  18816. low = i + 1;
  18817. } else if ( comparison > 0 ) {
  18818. high = i - 1;
  18819. } else {
  18820. high = i;
  18821. break;
  18822. // DONE
  18823. }
  18824. }
  18825. i = high;
  18826. if ( arcLengths[ i ] === targetArcLength ) {
  18827. return i / ( il - 1 );
  18828. }
  18829. // we could get finer grain at lengths, or use simple interpolation between two points
  18830. var lengthBefore = arcLengths[ i ];
  18831. var lengthAfter = arcLengths[ i + 1 ];
  18832. var segmentLength = lengthAfter - lengthBefore;
  18833. // determine where we are between the 'before' and 'after' points
  18834. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  18835. // add that fractional amount to t
  18836. var t = ( i + segmentFraction ) / ( il - 1 );
  18837. return t;
  18838. },
  18839. // Returns a unit vector tangent at t
  18840. // In case any sub curve does not implement its tangent derivation,
  18841. // 2 points a small delta apart will be used to find its gradient
  18842. // which seems to give a reasonable approximation
  18843. getTangent: function ( t ) {
  18844. var delta = 0.0001;
  18845. var t1 = t - delta;
  18846. var t2 = t + delta;
  18847. // Capping in case of danger
  18848. if ( t1 < 0 ) t1 = 0;
  18849. if ( t2 > 1 ) t2 = 1;
  18850. var pt1 = this.getPoint( t1 );
  18851. var pt2 = this.getPoint( t2 );
  18852. var vec = pt2.clone().sub( pt1 );
  18853. return vec.normalize();
  18854. },
  18855. getTangentAt: function ( u ) {
  18856. var t = this.getUtoTmapping( u );
  18857. return this.getTangent( t );
  18858. },
  18859. computeFrenetFrames: function ( segments, closed ) {
  18860. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  18861. var normal = new Vector3();
  18862. var tangents = [];
  18863. var normals = [];
  18864. var binormals = [];
  18865. var vec = new Vector3();
  18866. var mat = new Matrix4();
  18867. var i, u, theta;
  18868. // compute the tangent vectors for each segment on the curve
  18869. for ( i = 0; i <= segments; i ++ ) {
  18870. u = i / segments;
  18871. tangents[ i ] = this.getTangentAt( u );
  18872. tangents[ i ].normalize();
  18873. }
  18874. // select an initial normal vector perpendicular to the first tangent vector,
  18875. // and in the direction of the minimum tangent xyz component
  18876. normals[ 0 ] = new Vector3();
  18877. binormals[ 0 ] = new Vector3();
  18878. var min = Number.MAX_VALUE;
  18879. var tx = Math.abs( tangents[ 0 ].x );
  18880. var ty = Math.abs( tangents[ 0 ].y );
  18881. var tz = Math.abs( tangents[ 0 ].z );
  18882. if ( tx <= min ) {
  18883. min = tx;
  18884. normal.set( 1, 0, 0 );
  18885. }
  18886. if ( ty <= min ) {
  18887. min = ty;
  18888. normal.set( 0, 1, 0 );
  18889. }
  18890. if ( tz <= min ) {
  18891. normal.set( 0, 0, 1 );
  18892. }
  18893. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  18894. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  18895. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  18896. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  18897. for ( i = 1; i <= segments; i ++ ) {
  18898. normals[ i ] = normals[ i - 1 ].clone();
  18899. binormals[ i ] = binormals[ i - 1 ].clone();
  18900. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  18901. if ( vec.length() > Number.EPSILON ) {
  18902. vec.normalize();
  18903. theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  18904. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  18905. }
  18906. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  18907. }
  18908. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  18909. if ( closed === true ) {
  18910. theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  18911. theta /= segments;
  18912. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  18913. theta = - theta;
  18914. }
  18915. for ( i = 1; i <= segments; i ++ ) {
  18916. // twist a little...
  18917. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  18918. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  18919. }
  18920. }
  18921. return {
  18922. tangents: tangents,
  18923. normals: normals,
  18924. binormals: binormals
  18925. };
  18926. },
  18927. clone: function () {
  18928. return new this.constructor().copy( this );
  18929. },
  18930. copy: function ( source ) {
  18931. this.arcLengthDivisions = source.arcLengthDivisions;
  18932. return this;
  18933. },
  18934. toJSON: function () {
  18935. var data = {
  18936. metadata: {
  18937. version: 4.5,
  18938. type: 'Curve',
  18939. generator: 'Curve.toJSON'
  18940. }
  18941. };
  18942. data.arcLengthDivisions = this.arcLengthDivisions;
  18943. data.type = this.type;
  18944. return data;
  18945. },
  18946. fromJSON: function ( json ) {
  18947. this.arcLengthDivisions = json.arcLengthDivisions;
  18948. return this;
  18949. }
  18950. } );
  18951. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  18952. Curve.call( this );
  18953. this.type = 'EllipseCurve';
  18954. this.aX = aX || 0;
  18955. this.aY = aY || 0;
  18956. this.xRadius = xRadius || 1;
  18957. this.yRadius = yRadius || 1;
  18958. this.aStartAngle = aStartAngle || 0;
  18959. this.aEndAngle = aEndAngle || 2 * Math.PI;
  18960. this.aClockwise = aClockwise || false;
  18961. this.aRotation = aRotation || 0;
  18962. }
  18963. EllipseCurve.prototype = Object.create( Curve.prototype );
  18964. EllipseCurve.prototype.constructor = EllipseCurve;
  18965. EllipseCurve.prototype.isEllipseCurve = true;
  18966. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  18967. var point = optionalTarget || new Vector2();
  18968. var twoPi = Math.PI * 2;
  18969. var deltaAngle = this.aEndAngle - this.aStartAngle;
  18970. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  18971. // ensures that deltaAngle is 0 .. 2 PI
  18972. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  18973. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  18974. if ( deltaAngle < Number.EPSILON ) {
  18975. if ( samePoints ) {
  18976. deltaAngle = 0;
  18977. } else {
  18978. deltaAngle = twoPi;
  18979. }
  18980. }
  18981. if ( this.aClockwise === true && ! samePoints ) {
  18982. if ( deltaAngle === twoPi ) {
  18983. deltaAngle = - twoPi;
  18984. } else {
  18985. deltaAngle = deltaAngle - twoPi;
  18986. }
  18987. }
  18988. var angle = this.aStartAngle + t * deltaAngle;
  18989. var x = this.aX + this.xRadius * Math.cos( angle );
  18990. var y = this.aY + this.yRadius * Math.sin( angle );
  18991. if ( this.aRotation !== 0 ) {
  18992. var cos = Math.cos( this.aRotation );
  18993. var sin = Math.sin( this.aRotation );
  18994. var tx = x - this.aX;
  18995. var ty = y - this.aY;
  18996. // Rotate the point about the center of the ellipse.
  18997. x = tx * cos - ty * sin + this.aX;
  18998. y = tx * sin + ty * cos + this.aY;
  18999. }
  19000. return point.set( x, y );
  19001. };
  19002. EllipseCurve.prototype.copy = function ( source ) {
  19003. Curve.prototype.copy.call( this, source );
  19004. this.aX = source.aX;
  19005. this.aY = source.aY;
  19006. this.xRadius = source.xRadius;
  19007. this.yRadius = source.yRadius;
  19008. this.aStartAngle = source.aStartAngle;
  19009. this.aEndAngle = source.aEndAngle;
  19010. this.aClockwise = source.aClockwise;
  19011. this.aRotation = source.aRotation;
  19012. return this;
  19013. };
  19014. EllipseCurve.prototype.toJSON = function () {
  19015. var data = Curve.prototype.toJSON.call( this );
  19016. data.aX = this.aX;
  19017. data.aY = this.aY;
  19018. data.xRadius = this.xRadius;
  19019. data.yRadius = this.yRadius;
  19020. data.aStartAngle = this.aStartAngle;
  19021. data.aEndAngle = this.aEndAngle;
  19022. data.aClockwise = this.aClockwise;
  19023. data.aRotation = this.aRotation;
  19024. return data;
  19025. };
  19026. EllipseCurve.prototype.fromJSON = function ( json ) {
  19027. Curve.prototype.fromJSON.call( this, json );
  19028. this.aX = json.aX;
  19029. this.aY = json.aY;
  19030. this.xRadius = json.xRadius;
  19031. this.yRadius = json.yRadius;
  19032. this.aStartAngle = json.aStartAngle;
  19033. this.aEndAngle = json.aEndAngle;
  19034. this.aClockwise = json.aClockwise;
  19035. this.aRotation = json.aRotation;
  19036. return this;
  19037. };
  19038. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  19039. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  19040. this.type = 'ArcCurve';
  19041. }
  19042. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  19043. ArcCurve.prototype.constructor = ArcCurve;
  19044. ArcCurve.prototype.isArcCurve = true;
  19045. /**
  19046. * @author zz85 https://github.com/zz85
  19047. *
  19048. * Centripetal CatmullRom Curve - which is useful for avoiding
  19049. * cusps and self-intersections in non-uniform catmull rom curves.
  19050. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  19051. *
  19052. * curve.type accepts centripetal(default), chordal and catmullrom
  19053. * curve.tension is used for catmullrom which defaults to 0.5
  19054. */
  19055. /*
  19056. Based on an optimized c++ solution in
  19057. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  19058. - http://ideone.com/NoEbVM
  19059. This CubicPoly class could be used for reusing some variables and calculations,
  19060. but for three.js curve use, it could be possible inlined and flatten into a single function call
  19061. which can be placed in CurveUtils.
  19062. */
  19063. function CubicPoly() {
  19064. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  19065. /*
  19066. * Compute coefficients for a cubic polynomial
  19067. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  19068. * such that
  19069. * p(0) = x0, p(1) = x1
  19070. * and
  19071. * p'(0) = t0, p'(1) = t1.
  19072. */
  19073. function init( x0, x1, t0, t1 ) {
  19074. c0 = x0;
  19075. c1 = t0;
  19076. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  19077. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  19078. }
  19079. return {
  19080. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  19081. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  19082. },
  19083. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  19084. // compute tangents when parameterized in [t1,t2]
  19085. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  19086. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  19087. // rescale tangents for parametrization in [0,1]
  19088. t1 *= dt1;
  19089. t2 *= dt1;
  19090. init( x1, x2, t1, t2 );
  19091. },
  19092. calc: function ( t ) {
  19093. var t2 = t * t;
  19094. var t3 = t2 * t;
  19095. return c0 + c1 * t + c2 * t2 + c3 * t3;
  19096. }
  19097. };
  19098. }
  19099. //
  19100. var tmp = new Vector3();
  19101. var px = new CubicPoly();
  19102. var py = new CubicPoly();
  19103. var pz = new CubicPoly();
  19104. function CatmullRomCurve3( points, closed, curveType, tension ) {
  19105. Curve.call( this );
  19106. this.type = 'CatmullRomCurve3';
  19107. this.points = points || [];
  19108. this.closed = closed || false;
  19109. this.curveType = curveType || 'centripetal';
  19110. this.tension = tension || 0.5;
  19111. }
  19112. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  19113. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  19114. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  19115. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  19116. var point = optionalTarget || new Vector3();
  19117. var points = this.points;
  19118. var l = points.length;
  19119. var p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  19120. var intPoint = Math.floor( p );
  19121. var weight = p - intPoint;
  19122. if ( this.closed ) {
  19123. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  19124. } else if ( weight === 0 && intPoint === l - 1 ) {
  19125. intPoint = l - 2;
  19126. weight = 1;
  19127. }
  19128. var p0, p1, p2, p3; // 4 points
  19129. if ( this.closed || intPoint > 0 ) {
  19130. p0 = points[ ( intPoint - 1 ) % l ];
  19131. } else {
  19132. // extrapolate first point
  19133. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  19134. p0 = tmp;
  19135. }
  19136. p1 = points[ intPoint % l ];
  19137. p2 = points[ ( intPoint + 1 ) % l ];
  19138. if ( this.closed || intPoint + 2 < l ) {
  19139. p3 = points[ ( intPoint + 2 ) % l ];
  19140. } else {
  19141. // extrapolate last point
  19142. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  19143. p3 = tmp;
  19144. }
  19145. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  19146. // init Centripetal / Chordal Catmull-Rom
  19147. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  19148. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  19149. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  19150. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  19151. // safety check for repeated points
  19152. if ( dt1 < 1e-4 ) dt1 = 1.0;
  19153. if ( dt0 < 1e-4 ) dt0 = dt1;
  19154. if ( dt2 < 1e-4 ) dt2 = dt1;
  19155. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  19156. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  19157. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  19158. } else if ( this.curveType === 'catmullrom' ) {
  19159. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  19160. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  19161. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  19162. }
  19163. point.set(
  19164. px.calc( weight ),
  19165. py.calc( weight ),
  19166. pz.calc( weight )
  19167. );
  19168. return point;
  19169. };
  19170. CatmullRomCurve3.prototype.copy = function ( source ) {
  19171. Curve.prototype.copy.call( this, source );
  19172. this.points = [];
  19173. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  19174. var point = source.points[ i ];
  19175. this.points.push( point.clone() );
  19176. }
  19177. this.closed = source.closed;
  19178. this.curveType = source.curveType;
  19179. this.tension = source.tension;
  19180. return this;
  19181. };
  19182. CatmullRomCurve3.prototype.toJSON = function () {
  19183. var data = Curve.prototype.toJSON.call( this );
  19184. data.points = [];
  19185. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  19186. var point = this.points[ i ];
  19187. data.points.push( point.toArray() );
  19188. }
  19189. data.closed = this.closed;
  19190. data.curveType = this.curveType;
  19191. data.tension = this.tension;
  19192. return data;
  19193. };
  19194. CatmullRomCurve3.prototype.fromJSON = function ( json ) {
  19195. Curve.prototype.fromJSON.call( this, json );
  19196. this.points = [];
  19197. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  19198. var point = json.points[ i ];
  19199. this.points.push( new Vector3().fromArray( point ) );
  19200. }
  19201. this.closed = json.closed;
  19202. this.curveType = json.curveType;
  19203. this.tension = json.tension;
  19204. return this;
  19205. };
  19206. /**
  19207. * @author zz85 / http://www.lab4games.net/zz85/blog
  19208. *
  19209. * Bezier Curves formulas obtained from
  19210. * http://en.wikipedia.org/wiki/Bézier_curve
  19211. */
  19212. function CatmullRom( t, p0, p1, p2, p3 ) {
  19213. var v0 = ( p2 - p0 ) * 0.5;
  19214. var v1 = ( p3 - p1 ) * 0.5;
  19215. var t2 = t * t;
  19216. var t3 = t * t2;
  19217. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  19218. }
  19219. //
  19220. function QuadraticBezierP0( t, p ) {
  19221. var k = 1 - t;
  19222. return k * k * p;
  19223. }
  19224. function QuadraticBezierP1( t, p ) {
  19225. return 2 * ( 1 - t ) * t * p;
  19226. }
  19227. function QuadraticBezierP2( t, p ) {
  19228. return t * t * p;
  19229. }
  19230. function QuadraticBezier( t, p0, p1, p2 ) {
  19231. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  19232. QuadraticBezierP2( t, p2 );
  19233. }
  19234. //
  19235. function CubicBezierP0( t, p ) {
  19236. var k = 1 - t;
  19237. return k * k * k * p;
  19238. }
  19239. function CubicBezierP1( t, p ) {
  19240. var k = 1 - t;
  19241. return 3 * k * k * t * p;
  19242. }
  19243. function CubicBezierP2( t, p ) {
  19244. return 3 * ( 1 - t ) * t * t * p;
  19245. }
  19246. function CubicBezierP3( t, p ) {
  19247. return t * t * t * p;
  19248. }
  19249. function CubicBezier( t, p0, p1, p2, p3 ) {
  19250. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  19251. CubicBezierP3( t, p3 );
  19252. }
  19253. function CubicBezierCurve( v0, v1, v2, v3 ) {
  19254. Curve.call( this );
  19255. this.type = 'CubicBezierCurve';
  19256. this.v0 = v0 || new Vector2();
  19257. this.v1 = v1 || new Vector2();
  19258. this.v2 = v2 || new Vector2();
  19259. this.v3 = v3 || new Vector2();
  19260. }
  19261. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  19262. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  19263. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  19264. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  19265. var point = optionalTarget || new Vector2();
  19266. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  19267. point.set(
  19268. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  19269. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  19270. );
  19271. return point;
  19272. };
  19273. CubicBezierCurve.prototype.copy = function ( source ) {
  19274. Curve.prototype.copy.call( this, source );
  19275. this.v0.copy( source.v0 );
  19276. this.v1.copy( source.v1 );
  19277. this.v2.copy( source.v2 );
  19278. this.v3.copy( source.v3 );
  19279. return this;
  19280. };
  19281. CubicBezierCurve.prototype.toJSON = function () {
  19282. var data = Curve.prototype.toJSON.call( this );
  19283. data.v0 = this.v0.toArray();
  19284. data.v1 = this.v1.toArray();
  19285. data.v2 = this.v2.toArray();
  19286. data.v3 = this.v3.toArray();
  19287. return data;
  19288. };
  19289. CubicBezierCurve.prototype.fromJSON = function ( json ) {
  19290. Curve.prototype.fromJSON.call( this, json );
  19291. this.v0.fromArray( json.v0 );
  19292. this.v1.fromArray( json.v1 );
  19293. this.v2.fromArray( json.v2 );
  19294. this.v3.fromArray( json.v3 );
  19295. return this;
  19296. };
  19297. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  19298. Curve.call( this );
  19299. this.type = 'CubicBezierCurve3';
  19300. this.v0 = v0 || new Vector3();
  19301. this.v1 = v1 || new Vector3();
  19302. this.v2 = v2 || new Vector3();
  19303. this.v3 = v3 || new Vector3();
  19304. }
  19305. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  19306. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  19307. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  19308. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  19309. var point = optionalTarget || new Vector3();
  19310. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  19311. point.set(
  19312. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  19313. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  19314. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  19315. );
  19316. return point;
  19317. };
  19318. CubicBezierCurve3.prototype.copy = function ( source ) {
  19319. Curve.prototype.copy.call( this, source );
  19320. this.v0.copy( source.v0 );
  19321. this.v1.copy( source.v1 );
  19322. this.v2.copy( source.v2 );
  19323. this.v3.copy( source.v3 );
  19324. return this;
  19325. };
  19326. CubicBezierCurve3.prototype.toJSON = function () {
  19327. var data = Curve.prototype.toJSON.call( this );
  19328. data.v0 = this.v0.toArray();
  19329. data.v1 = this.v1.toArray();
  19330. data.v2 = this.v2.toArray();
  19331. data.v3 = this.v3.toArray();
  19332. return data;
  19333. };
  19334. CubicBezierCurve3.prototype.fromJSON = function ( json ) {
  19335. Curve.prototype.fromJSON.call( this, json );
  19336. this.v0.fromArray( json.v0 );
  19337. this.v1.fromArray( json.v1 );
  19338. this.v2.fromArray( json.v2 );
  19339. this.v3.fromArray( json.v3 );
  19340. return this;
  19341. };
  19342. function LineCurve( v1, v2 ) {
  19343. Curve.call( this );
  19344. this.type = 'LineCurve';
  19345. this.v1 = v1 || new Vector2();
  19346. this.v2 = v2 || new Vector2();
  19347. }
  19348. LineCurve.prototype = Object.create( Curve.prototype );
  19349. LineCurve.prototype.constructor = LineCurve;
  19350. LineCurve.prototype.isLineCurve = true;
  19351. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  19352. var point = optionalTarget || new Vector2();
  19353. if ( t === 1 ) {
  19354. point.copy( this.v2 );
  19355. } else {
  19356. point.copy( this.v2 ).sub( this.v1 );
  19357. point.multiplyScalar( t ).add( this.v1 );
  19358. }
  19359. return point;
  19360. };
  19361. // Line curve is linear, so we can overwrite default getPointAt
  19362. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  19363. return this.getPoint( u, optionalTarget );
  19364. };
  19365. LineCurve.prototype.getTangent = function ( /* t */ ) {
  19366. var tangent = this.v2.clone().sub( this.v1 );
  19367. return tangent.normalize();
  19368. };
  19369. LineCurve.prototype.copy = function ( source ) {
  19370. Curve.prototype.copy.call( this, source );
  19371. this.v1.copy( source.v1 );
  19372. this.v2.copy( source.v2 );
  19373. return this;
  19374. };
  19375. LineCurve.prototype.toJSON = function () {
  19376. var data = Curve.prototype.toJSON.call( this );
  19377. data.v1 = this.v1.toArray();
  19378. data.v2 = this.v2.toArray();
  19379. return data;
  19380. };
  19381. LineCurve.prototype.fromJSON = function ( json ) {
  19382. Curve.prototype.fromJSON.call( this, json );
  19383. this.v1.fromArray( json.v1 );
  19384. this.v2.fromArray( json.v2 );
  19385. return this;
  19386. };
  19387. function LineCurve3( v1, v2 ) {
  19388. Curve.call( this );
  19389. this.type = 'LineCurve3';
  19390. this.v1 = v1 || new Vector3();
  19391. this.v2 = v2 || new Vector3();
  19392. }
  19393. LineCurve3.prototype = Object.create( Curve.prototype );
  19394. LineCurve3.prototype.constructor = LineCurve3;
  19395. LineCurve3.prototype.isLineCurve3 = true;
  19396. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  19397. var point = optionalTarget || new Vector3();
  19398. if ( t === 1 ) {
  19399. point.copy( this.v2 );
  19400. } else {
  19401. point.copy( this.v2 ).sub( this.v1 );
  19402. point.multiplyScalar( t ).add( this.v1 );
  19403. }
  19404. return point;
  19405. };
  19406. // Line curve is linear, so we can overwrite default getPointAt
  19407. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  19408. return this.getPoint( u, optionalTarget );
  19409. };
  19410. LineCurve3.prototype.copy = function ( source ) {
  19411. Curve.prototype.copy.call( this, source );
  19412. this.v1.copy( source.v1 );
  19413. this.v2.copy( source.v2 );
  19414. return this;
  19415. };
  19416. LineCurve3.prototype.toJSON = function () {
  19417. var data = Curve.prototype.toJSON.call( this );
  19418. data.v1 = this.v1.toArray();
  19419. data.v2 = this.v2.toArray();
  19420. return data;
  19421. };
  19422. LineCurve3.prototype.fromJSON = function ( json ) {
  19423. Curve.prototype.fromJSON.call( this, json );
  19424. this.v1.fromArray( json.v1 );
  19425. this.v2.fromArray( json.v2 );
  19426. return this;
  19427. };
  19428. function QuadraticBezierCurve( v0, v1, v2 ) {
  19429. Curve.call( this );
  19430. this.type = 'QuadraticBezierCurve';
  19431. this.v0 = v0 || new Vector2();
  19432. this.v1 = v1 || new Vector2();
  19433. this.v2 = v2 || new Vector2();
  19434. }
  19435. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  19436. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  19437. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  19438. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  19439. var point = optionalTarget || new Vector2();
  19440. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  19441. point.set(
  19442. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  19443. QuadraticBezier( t, v0.y, v1.y, v2.y )
  19444. );
  19445. return point;
  19446. };
  19447. QuadraticBezierCurve.prototype.copy = function ( source ) {
  19448. Curve.prototype.copy.call( this, source );
  19449. this.v0.copy( source.v0 );
  19450. this.v1.copy( source.v1 );
  19451. this.v2.copy( source.v2 );
  19452. return this;
  19453. };
  19454. QuadraticBezierCurve.prototype.toJSON = function () {
  19455. var data = Curve.prototype.toJSON.call( this );
  19456. data.v0 = this.v0.toArray();
  19457. data.v1 = this.v1.toArray();
  19458. data.v2 = this.v2.toArray();
  19459. return data;
  19460. };
  19461. QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
  19462. Curve.prototype.fromJSON.call( this, json );
  19463. this.v0.fromArray( json.v0 );
  19464. this.v1.fromArray( json.v1 );
  19465. this.v2.fromArray( json.v2 );
  19466. return this;
  19467. };
  19468. function QuadraticBezierCurve3( v0, v1, v2 ) {
  19469. Curve.call( this );
  19470. this.type = 'QuadraticBezierCurve3';
  19471. this.v0 = v0 || new Vector3();
  19472. this.v1 = v1 || new Vector3();
  19473. this.v2 = v2 || new Vector3();
  19474. }
  19475. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  19476. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  19477. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  19478. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  19479. var point = optionalTarget || new Vector3();
  19480. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  19481. point.set(
  19482. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  19483. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  19484. QuadraticBezier( t, v0.z, v1.z, v2.z )
  19485. );
  19486. return point;
  19487. };
  19488. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  19489. Curve.prototype.copy.call( this, source );
  19490. this.v0.copy( source.v0 );
  19491. this.v1.copy( source.v1 );
  19492. this.v2.copy( source.v2 );
  19493. return this;
  19494. };
  19495. QuadraticBezierCurve3.prototype.toJSON = function () {
  19496. var data = Curve.prototype.toJSON.call( this );
  19497. data.v0 = this.v0.toArray();
  19498. data.v1 = this.v1.toArray();
  19499. data.v2 = this.v2.toArray();
  19500. return data;
  19501. };
  19502. QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
  19503. Curve.prototype.fromJSON.call( this, json );
  19504. this.v0.fromArray( json.v0 );
  19505. this.v1.fromArray( json.v1 );
  19506. this.v2.fromArray( json.v2 );
  19507. return this;
  19508. };
  19509. function SplineCurve( points /* array of Vector2 */ ) {
  19510. Curve.call( this );
  19511. this.type = 'SplineCurve';
  19512. this.points = points || [];
  19513. }
  19514. SplineCurve.prototype = Object.create( Curve.prototype );
  19515. SplineCurve.prototype.constructor = SplineCurve;
  19516. SplineCurve.prototype.isSplineCurve = true;
  19517. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  19518. var point = optionalTarget || new Vector2();
  19519. var points = this.points;
  19520. var p = ( points.length - 1 ) * t;
  19521. var intPoint = Math.floor( p );
  19522. var weight = p - intPoint;
  19523. var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  19524. var p1 = points[ intPoint ];
  19525. var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  19526. var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  19527. point.set(
  19528. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  19529. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  19530. );
  19531. return point;
  19532. };
  19533. SplineCurve.prototype.copy = function ( source ) {
  19534. Curve.prototype.copy.call( this, source );
  19535. this.points = [];
  19536. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  19537. var point = source.points[ i ];
  19538. this.points.push( point.clone() );
  19539. }
  19540. return this;
  19541. };
  19542. SplineCurve.prototype.toJSON = function () {
  19543. var data = Curve.prototype.toJSON.call( this );
  19544. data.points = [];
  19545. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  19546. var point = this.points[ i ];
  19547. data.points.push( point.toArray() );
  19548. }
  19549. return data;
  19550. };
  19551. SplineCurve.prototype.fromJSON = function ( json ) {
  19552. Curve.prototype.fromJSON.call( this, json );
  19553. this.points = [];
  19554. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  19555. var point = json.points[ i ];
  19556. this.points.push( new Vector2().fromArray( point ) );
  19557. }
  19558. return this;
  19559. };
  19560. var Curves = Object.freeze({
  19561. ArcCurve: ArcCurve,
  19562. CatmullRomCurve3: CatmullRomCurve3,
  19563. CubicBezierCurve: CubicBezierCurve,
  19564. CubicBezierCurve3: CubicBezierCurve3,
  19565. EllipseCurve: EllipseCurve,
  19566. LineCurve: LineCurve,
  19567. LineCurve3: LineCurve3,
  19568. QuadraticBezierCurve: QuadraticBezierCurve,
  19569. QuadraticBezierCurve3: QuadraticBezierCurve3,
  19570. SplineCurve: SplineCurve
  19571. });
  19572. /**
  19573. * @author zz85 / http://www.lab4games.net/zz85/blog
  19574. *
  19575. **/
  19576. /**************************************************************
  19577. * Curved Path - a curve path is simply a array of connected
  19578. * curves, but retains the api of a curve
  19579. **************************************************************/
  19580. function CurvePath() {
  19581. Curve.call( this );
  19582. this.type = 'CurvePath';
  19583. this.curves = [];
  19584. this.autoClose = false; // Automatically closes the path
  19585. }
  19586. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  19587. constructor: CurvePath,
  19588. add: function ( curve ) {
  19589. this.curves.push( curve );
  19590. },
  19591. closePath: function () {
  19592. // Add a line curve if start and end of lines are not connected
  19593. var startPoint = this.curves[ 0 ].getPoint( 0 );
  19594. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  19595. if ( ! startPoint.equals( endPoint ) ) {
  19596. this.curves.push( new LineCurve( endPoint, startPoint ) );
  19597. }
  19598. },
  19599. // To get accurate point with reference to
  19600. // entire path distance at time t,
  19601. // following has to be done:
  19602. // 1. Length of each sub path have to be known
  19603. // 2. Locate and identify type of curve
  19604. // 3. Get t for the curve
  19605. // 4. Return curve.getPointAt(t')
  19606. getPoint: function ( t ) {
  19607. var d = t * this.getLength();
  19608. var curveLengths = this.getCurveLengths();
  19609. var i = 0;
  19610. // To think about boundaries points.
  19611. while ( i < curveLengths.length ) {
  19612. if ( curveLengths[ i ] >= d ) {
  19613. var diff = curveLengths[ i ] - d;
  19614. var curve = this.curves[ i ];
  19615. var segmentLength = curve.getLength();
  19616. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  19617. return curve.getPointAt( u );
  19618. }
  19619. i ++;
  19620. }
  19621. return null;
  19622. // loop where sum != 0, sum > d , sum+1 <d
  19623. },
  19624. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  19625. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  19626. // getPoint() depends on getLength
  19627. getLength: function () {
  19628. var lens = this.getCurveLengths();
  19629. return lens[ lens.length - 1 ];
  19630. },
  19631. // cacheLengths must be recalculated.
  19632. updateArcLengths: function () {
  19633. this.needsUpdate = true;
  19634. this.cacheLengths = null;
  19635. this.getCurveLengths();
  19636. },
  19637. // Compute lengths and cache them
  19638. // We cannot overwrite getLengths() because UtoT mapping uses it.
  19639. getCurveLengths: function () {
  19640. // We use cache values if curves and cache array are same length
  19641. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  19642. return this.cacheLengths;
  19643. }
  19644. // Get length of sub-curve
  19645. // Push sums into cached array
  19646. var lengths = [], sums = 0;
  19647. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  19648. sums += this.curves[ i ].getLength();
  19649. lengths.push( sums );
  19650. }
  19651. this.cacheLengths = lengths;
  19652. return lengths;
  19653. },
  19654. getSpacedPoints: function ( divisions ) {
  19655. if ( divisions === undefined ) divisions = 40;
  19656. var points = [];
  19657. for ( var i = 0; i <= divisions; i ++ ) {
  19658. points.push( this.getPoint( i / divisions ) );
  19659. }
  19660. if ( this.autoClose ) {
  19661. points.push( points[ 0 ] );
  19662. }
  19663. return points;
  19664. },
  19665. getPoints: function ( divisions ) {
  19666. divisions = divisions || 12;
  19667. var points = [], last;
  19668. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  19669. var curve = curves[ i ];
  19670. var resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  19671. : ( curve && curve.isLineCurve ) ? 1
  19672. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  19673. : divisions;
  19674. var pts = curve.getPoints( resolution );
  19675. for ( var j = 0; j < pts.length; j ++ ) {
  19676. var point = pts[ j ];
  19677. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  19678. points.push( point );
  19679. last = point;
  19680. }
  19681. }
  19682. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  19683. points.push( points[ 0 ] );
  19684. }
  19685. return points;
  19686. },
  19687. copy: function ( source ) {
  19688. Curve.prototype.copy.call( this, source );
  19689. this.curves = [];
  19690. for ( var i = 0, l = source.curves.length; i < l; i ++ ) {
  19691. var curve = source.curves[ i ];
  19692. this.curves.push( curve.clone() );
  19693. }
  19694. this.autoClose = source.autoClose;
  19695. return this;
  19696. },
  19697. toJSON: function () {
  19698. var data = Curve.prototype.toJSON.call( this );
  19699. data.autoClose = this.autoClose;
  19700. data.curves = [];
  19701. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  19702. var curve = this.curves[ i ];
  19703. data.curves.push( curve.toJSON() );
  19704. }
  19705. return data;
  19706. },
  19707. fromJSON: function ( json ) {
  19708. Curve.prototype.fromJSON.call( this, json );
  19709. this.autoClose = json.autoClose;
  19710. this.curves = [];
  19711. for ( var i = 0, l = json.curves.length; i < l; i ++ ) {
  19712. var curve = json.curves[ i ];
  19713. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  19714. }
  19715. return this;
  19716. }
  19717. } );
  19718. /**
  19719. * @author zz85 / http://www.lab4games.net/zz85/blog
  19720. * Creates free form 2d path using series of points, lines or curves.
  19721. **/
  19722. function Path( points ) {
  19723. CurvePath.call( this );
  19724. this.type = 'Path';
  19725. this.currentPoint = new Vector2();
  19726. if ( points ) {
  19727. this.setFromPoints( points );
  19728. }
  19729. }
  19730. Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
  19731. constructor: Path,
  19732. setFromPoints: function ( points ) {
  19733. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  19734. for ( var i = 1, l = points.length; i < l; i ++ ) {
  19735. this.lineTo( points[ i ].x, points[ i ].y );
  19736. }
  19737. },
  19738. moveTo: function ( x, y ) {
  19739. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  19740. },
  19741. lineTo: function ( x, y ) {
  19742. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  19743. this.curves.push( curve );
  19744. this.currentPoint.set( x, y );
  19745. },
  19746. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  19747. var curve = new QuadraticBezierCurve(
  19748. this.currentPoint.clone(),
  19749. new Vector2( aCPx, aCPy ),
  19750. new Vector2( aX, aY )
  19751. );
  19752. this.curves.push( curve );
  19753. this.currentPoint.set( aX, aY );
  19754. },
  19755. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  19756. var curve = new CubicBezierCurve(
  19757. this.currentPoint.clone(),
  19758. new Vector2( aCP1x, aCP1y ),
  19759. new Vector2( aCP2x, aCP2y ),
  19760. new Vector2( aX, aY )
  19761. );
  19762. this.curves.push( curve );
  19763. this.currentPoint.set( aX, aY );
  19764. },
  19765. splineThru: function ( pts /*Array of Vector*/ ) {
  19766. var npts = [ this.currentPoint.clone() ].concat( pts );
  19767. var curve = new SplineCurve( npts );
  19768. this.curves.push( curve );
  19769. this.currentPoint.copy( pts[ pts.length - 1 ] );
  19770. },
  19771. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  19772. var x0 = this.currentPoint.x;
  19773. var y0 = this.currentPoint.y;
  19774. this.absarc( aX + x0, aY + y0, aRadius,
  19775. aStartAngle, aEndAngle, aClockwise );
  19776. },
  19777. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  19778. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  19779. },
  19780. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  19781. var x0 = this.currentPoint.x;
  19782. var y0 = this.currentPoint.y;
  19783. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  19784. },
  19785. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  19786. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  19787. if ( this.curves.length > 0 ) {
  19788. // if a previous curve is present, attempt to join
  19789. var firstPoint = curve.getPoint( 0 );
  19790. if ( ! firstPoint.equals( this.currentPoint ) ) {
  19791. this.lineTo( firstPoint.x, firstPoint.y );
  19792. }
  19793. }
  19794. this.curves.push( curve );
  19795. var lastPoint = curve.getPoint( 1 );
  19796. this.currentPoint.copy( lastPoint );
  19797. },
  19798. copy: function ( source ) {
  19799. CurvePath.prototype.copy.call( this, source );
  19800. this.currentPoint.copy( source.currentPoint );
  19801. return this;
  19802. },
  19803. toJSON: function () {
  19804. var data = CurvePath.prototype.toJSON.call( this );
  19805. data.currentPoint = this.currentPoint.toArray();
  19806. return data;
  19807. },
  19808. fromJSON: function ( json ) {
  19809. CurvePath.prototype.fromJSON.call( this, json );
  19810. this.currentPoint.fromArray( json.currentPoint );
  19811. return this;
  19812. }
  19813. } );
  19814. /**
  19815. * @author zz85 / http://www.lab4games.net/zz85/blog
  19816. * Defines a 2d shape plane using paths.
  19817. **/
  19818. // STEP 1 Create a path.
  19819. // STEP 2 Turn path into shape.
  19820. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  19821. // STEP 3a - Extract points from each shape, turn to vertices
  19822. // STEP 3b - Triangulate each shape, add faces.
  19823. function Shape( points ) {
  19824. Path.call( this, points );
  19825. this.uuid = _Math.generateUUID();
  19826. this.type = 'Shape';
  19827. this.holes = [];
  19828. }
  19829. Shape.prototype = Object.assign( Object.create( Path.prototype ), {
  19830. constructor: Shape,
  19831. getPointsHoles: function ( divisions ) {
  19832. var holesPts = [];
  19833. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  19834. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  19835. }
  19836. return holesPts;
  19837. },
  19838. // get points of shape and holes (keypoints based on segments parameter)
  19839. extractPoints: function ( divisions ) {
  19840. return {
  19841. shape: this.getPoints( divisions ),
  19842. holes: this.getPointsHoles( divisions )
  19843. };
  19844. },
  19845. copy: function ( source ) {
  19846. Path.prototype.copy.call( this, source );
  19847. this.holes = [];
  19848. for ( var i = 0, l = source.holes.length; i < l; i ++ ) {
  19849. var hole = source.holes[ i ];
  19850. this.holes.push( hole.clone() );
  19851. }
  19852. return this;
  19853. },
  19854. toJSON: function () {
  19855. var data = Path.prototype.toJSON.call( this );
  19856. data.uuid = this.uuid;
  19857. data.holes = [];
  19858. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  19859. var hole = this.holes[ i ];
  19860. data.holes.push( hole.toJSON() );
  19861. }
  19862. return data;
  19863. },
  19864. fromJSON: function ( json ) {
  19865. Path.prototype.fromJSON.call( this, json );
  19866. this.uuid = json.uuid;
  19867. this.holes = [];
  19868. for ( var i = 0, l = json.holes.length; i < l; i ++ ) {
  19869. var hole = json.holes[ i ];
  19870. this.holes.push( new Path().fromJSON( hole ) );
  19871. }
  19872. return this;
  19873. }
  19874. } );
  19875. /**
  19876. * @author mrdoob / http://mrdoob.com/
  19877. * @author alteredq / http://alteredqualia.com/
  19878. */
  19879. function Light( color, intensity ) {
  19880. Object3D.call( this );
  19881. this.type = 'Light';
  19882. this.color = new Color( color );
  19883. this.intensity = intensity !== undefined ? intensity : 1;
  19884. this.receiveShadow = undefined;
  19885. }
  19886. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  19887. constructor: Light,
  19888. isLight: true,
  19889. copy: function ( source ) {
  19890. Object3D.prototype.copy.call( this, source );
  19891. this.color.copy( source.color );
  19892. this.intensity = source.intensity;
  19893. return this;
  19894. },
  19895. toJSON: function ( meta ) {
  19896. var data = Object3D.prototype.toJSON.call( this, meta );
  19897. data.object.color = this.color.getHex();
  19898. data.object.intensity = this.intensity;
  19899. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  19900. if ( this.distance !== undefined ) data.object.distance = this.distance;
  19901. if ( this.angle !== undefined ) data.object.angle = this.angle;
  19902. if ( this.decay !== undefined ) data.object.decay = this.decay;
  19903. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  19904. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  19905. return data;
  19906. }
  19907. } );
  19908. /**
  19909. * @author alteredq / http://alteredqualia.com/
  19910. */
  19911. function HemisphereLight( skyColor, groundColor, intensity ) {
  19912. Light.call( this, skyColor, intensity );
  19913. this.type = 'HemisphereLight';
  19914. this.castShadow = undefined;
  19915. this.position.copy( Object3D.DefaultUp );
  19916. this.updateMatrix();
  19917. this.groundColor = new Color( groundColor );
  19918. }
  19919. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  19920. constructor: HemisphereLight,
  19921. isHemisphereLight: true,
  19922. copy: function ( source ) {
  19923. Light.prototype.copy.call( this, source );
  19924. this.groundColor.copy( source.groundColor );
  19925. return this;
  19926. }
  19927. } );
  19928. /**
  19929. * @author mrdoob / http://mrdoob.com/
  19930. */
  19931. function LightShadow( camera ) {
  19932. this.camera = camera;
  19933. this.bias = 0;
  19934. this.radius = 1;
  19935. this.mapSize = new Vector2( 512, 512 );
  19936. this.map = null;
  19937. this.matrix = new Matrix4();
  19938. }
  19939. Object.assign( LightShadow.prototype, {
  19940. copy: function ( source ) {
  19941. this.camera = source.camera.clone();
  19942. this.bias = source.bias;
  19943. this.radius = source.radius;
  19944. this.mapSize.copy( source.mapSize );
  19945. return this;
  19946. },
  19947. clone: function () {
  19948. return new this.constructor().copy( this );
  19949. },
  19950. toJSON: function () {
  19951. var object = {};
  19952. if ( this.bias !== 0 ) object.bias = this.bias;
  19953. if ( this.radius !== 1 ) object.radius = this.radius;
  19954. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  19955. object.camera = this.camera.toJSON( false ).object;
  19956. delete object.camera.matrix;
  19957. return object;
  19958. }
  19959. } );
  19960. /**
  19961. * @author mrdoob / http://mrdoob.com/
  19962. */
  19963. function SpotLightShadow() {
  19964. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  19965. }
  19966. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  19967. constructor: SpotLightShadow,
  19968. isSpotLightShadow: true,
  19969. update: function ( light ) {
  19970. var camera = this.camera;
  19971. var fov = _Math.RAD2DEG * 2 * light.angle;
  19972. var aspect = this.mapSize.width / this.mapSize.height;
  19973. var far = light.distance || camera.far;
  19974. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  19975. camera.fov = fov;
  19976. camera.aspect = aspect;
  19977. camera.far = far;
  19978. camera.updateProjectionMatrix();
  19979. }
  19980. }
  19981. } );
  19982. /**
  19983. * @author alteredq / http://alteredqualia.com/
  19984. */
  19985. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  19986. Light.call( this, color, intensity );
  19987. this.type = 'SpotLight';
  19988. this.position.copy( Object3D.DefaultUp );
  19989. this.updateMatrix();
  19990. this.target = new Object3D();
  19991. Object.defineProperty( this, 'power', {
  19992. get: function () {
  19993. // intensity = power per solid angle.
  19994. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  19995. return this.intensity * Math.PI;
  19996. },
  19997. set: function ( power ) {
  19998. // intensity = power per solid angle.
  19999. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  20000. this.intensity = power / Math.PI;
  20001. }
  20002. } );
  20003. this.distance = ( distance !== undefined ) ? distance : 0;
  20004. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  20005. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  20006. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  20007. this.shadow = new SpotLightShadow();
  20008. }
  20009. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  20010. constructor: SpotLight,
  20011. isSpotLight: true,
  20012. copy: function ( source ) {
  20013. Light.prototype.copy.call( this, source );
  20014. this.distance = source.distance;
  20015. this.angle = source.angle;
  20016. this.penumbra = source.penumbra;
  20017. this.decay = source.decay;
  20018. this.target = source.target.clone();
  20019. this.shadow = source.shadow.clone();
  20020. return this;
  20021. }
  20022. } );
  20023. /**
  20024. * @author mrdoob / http://mrdoob.com/
  20025. */
  20026. function PointLight( color, intensity, distance, decay ) {
  20027. Light.call( this, color, intensity );
  20028. this.type = 'PointLight';
  20029. Object.defineProperty( this, 'power', {
  20030. get: function () {
  20031. // intensity = power per solid angle.
  20032. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  20033. return this.intensity * 4 * Math.PI;
  20034. },
  20035. set: function ( power ) {
  20036. // intensity = power per solid angle.
  20037. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  20038. this.intensity = power / ( 4 * Math.PI );
  20039. }
  20040. } );
  20041. this.distance = ( distance !== undefined ) ? distance : 0;
  20042. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  20043. this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  20044. }
  20045. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  20046. constructor: PointLight,
  20047. isPointLight: true,
  20048. copy: function ( source ) {
  20049. Light.prototype.copy.call( this, source );
  20050. this.distance = source.distance;
  20051. this.decay = source.decay;
  20052. this.shadow = source.shadow.clone();
  20053. return this;
  20054. }
  20055. } );
  20056. /**
  20057. * @author mrdoob / http://mrdoob.com/
  20058. */
  20059. function DirectionalLightShadow( ) {
  20060. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  20061. }
  20062. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  20063. constructor: DirectionalLightShadow
  20064. } );
  20065. /**
  20066. * @author mrdoob / http://mrdoob.com/
  20067. * @author alteredq / http://alteredqualia.com/
  20068. */
  20069. function DirectionalLight( color, intensity ) {
  20070. Light.call( this, color, intensity );
  20071. this.type = 'DirectionalLight';
  20072. this.position.copy( Object3D.DefaultUp );
  20073. this.updateMatrix();
  20074. this.target = new Object3D();
  20075. this.shadow = new DirectionalLightShadow();
  20076. }
  20077. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  20078. constructor: DirectionalLight,
  20079. isDirectionalLight: true,
  20080. copy: function ( source ) {
  20081. Light.prototype.copy.call( this, source );
  20082. this.target = source.target.clone();
  20083. this.shadow = source.shadow.clone();
  20084. return this;
  20085. }
  20086. } );
  20087. /**
  20088. * @author mrdoob / http://mrdoob.com/
  20089. */
  20090. function AmbientLight( color, intensity ) {
  20091. Light.call( this, color, intensity );
  20092. this.type = 'AmbientLight';
  20093. this.castShadow = undefined;
  20094. }
  20095. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  20096. constructor: AmbientLight,
  20097. isAmbientLight: true
  20098. } );
  20099. /**
  20100. * @author abelnation / http://github.com/abelnation
  20101. */
  20102. function RectAreaLight( color, intensity, width, height ) {
  20103. Light.call( this, color, intensity );
  20104. this.type = 'RectAreaLight';
  20105. this.width = ( width !== undefined ) ? width : 10;
  20106. this.height = ( height !== undefined ) ? height : 10;
  20107. }
  20108. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  20109. constructor: RectAreaLight,
  20110. isRectAreaLight: true,
  20111. copy: function ( source ) {
  20112. Light.prototype.copy.call( this, source );
  20113. this.width = source.width;
  20114. this.height = source.height;
  20115. return this;
  20116. },
  20117. toJSON: function ( meta ) {
  20118. var data = Light.prototype.toJSON.call( this, meta );
  20119. data.object.width = this.width;
  20120. data.object.height = this.height;
  20121. return data;
  20122. }
  20123. } );
  20124. /**
  20125. *
  20126. * A Track that interpolates Strings
  20127. *
  20128. *
  20129. * @author Ben Houston / http://clara.io/
  20130. * @author David Sarno / http://lighthaus.us/
  20131. * @author tschw
  20132. */
  20133. function StringKeyframeTrack( name, times, values, interpolation ) {
  20134. KeyframeTrack.call( this, name, times, values, interpolation );
  20135. }
  20136. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20137. constructor: StringKeyframeTrack,
  20138. ValueTypeName: 'string',
  20139. ValueBufferType: Array,
  20140. DefaultInterpolation: InterpolateDiscrete,
  20141. InterpolantFactoryMethodLinear: undefined,
  20142. InterpolantFactoryMethodSmooth: undefined
  20143. } );
  20144. /**
  20145. *
  20146. * A Track of Boolean keyframe values.
  20147. *
  20148. *
  20149. * @author Ben Houston / http://clara.io/
  20150. * @author David Sarno / http://lighthaus.us/
  20151. * @author tschw
  20152. */
  20153. function BooleanKeyframeTrack( name, times, values ) {
  20154. KeyframeTrack.call( this, name, times, values );
  20155. }
  20156. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20157. constructor: BooleanKeyframeTrack,
  20158. ValueTypeName: 'bool',
  20159. ValueBufferType: Array,
  20160. DefaultInterpolation: InterpolateDiscrete,
  20161. InterpolantFactoryMethodLinear: undefined,
  20162. InterpolantFactoryMethodSmooth: undefined
  20163. // Note: Actually this track could have a optimized / compressed
  20164. // representation of a single value and a custom interpolant that
  20165. // computes "firstValue ^ isOdd( index )".
  20166. } );
  20167. /**
  20168. * Abstract base class of interpolants over parametric samples.
  20169. *
  20170. * The parameter domain is one dimensional, typically the time or a path
  20171. * along a curve defined by the data.
  20172. *
  20173. * The sample values can have any dimensionality and derived classes may
  20174. * apply special interpretations to the data.
  20175. *
  20176. * This class provides the interval seek in a Template Method, deferring
  20177. * the actual interpolation to derived classes.
  20178. *
  20179. * Time complexity is O(1) for linear access crossing at most two points
  20180. * and O(log N) for random access, where N is the number of positions.
  20181. *
  20182. * References:
  20183. *
  20184. * http://www.oodesign.com/template-method-pattern.html
  20185. *
  20186. * @author tschw
  20187. */
  20188. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20189. this.parameterPositions = parameterPositions;
  20190. this._cachedIndex = 0;
  20191. this.resultBuffer = resultBuffer !== undefined ?
  20192. resultBuffer : new sampleValues.constructor( sampleSize );
  20193. this.sampleValues = sampleValues;
  20194. this.valueSize = sampleSize;
  20195. }
  20196. Object.assign( Interpolant.prototype, {
  20197. evaluate: function ( t ) {
  20198. var pp = this.parameterPositions,
  20199. i1 = this._cachedIndex,
  20200. t1 = pp[ i1 ],
  20201. t0 = pp[ i1 - 1 ];
  20202. validate_interval: {
  20203. seek: {
  20204. var right;
  20205. linear_scan: {
  20206. //- See http://jsperf.com/comparison-to-undefined/3
  20207. //- slower code:
  20208. //-
  20209. //- if ( t >= t1 || t1 === undefined ) {
  20210. forward_scan: if ( ! ( t < t1 ) ) {
  20211. for ( var giveUpAt = i1 + 2; ; ) {
  20212. if ( t1 === undefined ) {
  20213. if ( t < t0 ) break forward_scan;
  20214. // after end
  20215. i1 = pp.length;
  20216. this._cachedIndex = i1;
  20217. return this.afterEnd_( i1 - 1, t, t0 );
  20218. }
  20219. if ( i1 === giveUpAt ) break; // this loop
  20220. t0 = t1;
  20221. t1 = pp[ ++ i1 ];
  20222. if ( t < t1 ) {
  20223. // we have arrived at the sought interval
  20224. break seek;
  20225. }
  20226. }
  20227. // prepare binary search on the right side of the index
  20228. right = pp.length;
  20229. break linear_scan;
  20230. }
  20231. //- slower code:
  20232. //- if ( t < t0 || t0 === undefined ) {
  20233. if ( ! ( t >= t0 ) ) {
  20234. // looping?
  20235. var t1global = pp[ 1 ];
  20236. if ( t < t1global ) {
  20237. i1 = 2; // + 1, using the scan for the details
  20238. t0 = t1global;
  20239. }
  20240. // linear reverse scan
  20241. for ( var giveUpAt = i1 - 2; ; ) {
  20242. if ( t0 === undefined ) {
  20243. // before start
  20244. this._cachedIndex = 0;
  20245. return this.beforeStart_( 0, t, t1 );
  20246. }
  20247. if ( i1 === giveUpAt ) break; // this loop
  20248. t1 = t0;
  20249. t0 = pp[ -- i1 - 1 ];
  20250. if ( t >= t0 ) {
  20251. // we have arrived at the sought interval
  20252. break seek;
  20253. }
  20254. }
  20255. // prepare binary search on the left side of the index
  20256. right = i1;
  20257. i1 = 0;
  20258. break linear_scan;
  20259. }
  20260. // the interval is valid
  20261. break validate_interval;
  20262. } // linear scan
  20263. // binary search
  20264. while ( i1 < right ) {
  20265. var mid = ( i1 + right ) >>> 1;
  20266. if ( t < pp[ mid ] ) {
  20267. right = mid;
  20268. } else {
  20269. i1 = mid + 1;
  20270. }
  20271. }
  20272. t1 = pp[ i1 ];
  20273. t0 = pp[ i1 - 1 ];
  20274. // check boundary cases, again
  20275. if ( t0 === undefined ) {
  20276. this._cachedIndex = 0;
  20277. return this.beforeStart_( 0, t, t1 );
  20278. }
  20279. if ( t1 === undefined ) {
  20280. i1 = pp.length;
  20281. this._cachedIndex = i1;
  20282. return this.afterEnd_( i1 - 1, t0, t );
  20283. }
  20284. } // seek
  20285. this._cachedIndex = i1;
  20286. this.intervalChanged_( i1, t0, t1 );
  20287. } // validate_interval
  20288. return this.interpolate_( i1, t0, t, t1 );
  20289. },
  20290. settings: null, // optional, subclass-specific settings structure
  20291. // Note: The indirection allows central control of many interpolants.
  20292. // --- Protected interface
  20293. DefaultSettings_: {},
  20294. getSettings_: function () {
  20295. return this.settings || this.DefaultSettings_;
  20296. },
  20297. copySampleValue_: function ( index ) {
  20298. // copies a sample value to the result buffer
  20299. var result = this.resultBuffer,
  20300. values = this.sampleValues,
  20301. stride = this.valueSize,
  20302. offset = index * stride;
  20303. for ( var i = 0; i !== stride; ++ i ) {
  20304. result[ i ] = values[ offset + i ];
  20305. }
  20306. return result;
  20307. },
  20308. // Template methods for derived classes:
  20309. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  20310. throw new Error( 'call to abstract method' );
  20311. // implementations shall return this.resultBuffer
  20312. },
  20313. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  20314. // empty
  20315. }
  20316. } );
  20317. //!\ DECLARE ALIAS AFTER assign prototype !
  20318. Object.assign( Interpolant.prototype, {
  20319. //( 0, t, t0 ), returns this.resultBuffer
  20320. beforeStart_: Interpolant.prototype.copySampleValue_,
  20321. //( N-1, tN-1, t ), returns this.resultBuffer
  20322. afterEnd_: Interpolant.prototype.copySampleValue_,
  20323. } );
  20324. /**
  20325. * Spherical linear unit quaternion interpolant.
  20326. *
  20327. * @author tschw
  20328. */
  20329. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20330. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20331. }
  20332. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20333. constructor: QuaternionLinearInterpolant,
  20334. interpolate_: function ( i1, t0, t, t1 ) {
  20335. var result = this.resultBuffer,
  20336. values = this.sampleValues,
  20337. stride = this.valueSize,
  20338. offset = i1 * stride,
  20339. alpha = ( t - t0 ) / ( t1 - t0 );
  20340. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  20341. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  20342. }
  20343. return result;
  20344. }
  20345. } );
  20346. /**
  20347. *
  20348. * A Track of quaternion keyframe values.
  20349. *
  20350. * @author Ben Houston / http://clara.io/
  20351. * @author David Sarno / http://lighthaus.us/
  20352. * @author tschw
  20353. */
  20354. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  20355. KeyframeTrack.call( this, name, times, values, interpolation );
  20356. }
  20357. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20358. constructor: QuaternionKeyframeTrack,
  20359. ValueTypeName: 'quaternion',
  20360. // ValueBufferType is inherited
  20361. DefaultInterpolation: InterpolateLinear,
  20362. InterpolantFactoryMethodLinear: function ( result ) {
  20363. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20364. },
  20365. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  20366. } );
  20367. /**
  20368. *
  20369. * A Track of keyframe values that represent color.
  20370. *
  20371. *
  20372. * @author Ben Houston / http://clara.io/
  20373. * @author David Sarno / http://lighthaus.us/
  20374. * @author tschw
  20375. */
  20376. function ColorKeyframeTrack( name, times, values, interpolation ) {
  20377. KeyframeTrack.call( this, name, times, values, interpolation );
  20378. }
  20379. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20380. constructor: ColorKeyframeTrack,
  20381. ValueTypeName: 'color'
  20382. // ValueBufferType is inherited
  20383. // DefaultInterpolation is inherited
  20384. // Note: Very basic implementation and nothing special yet.
  20385. // However, this is the place for color space parameterization.
  20386. } );
  20387. /**
  20388. *
  20389. * A Track of numeric keyframe values.
  20390. *
  20391. * @author Ben Houston / http://clara.io/
  20392. * @author David Sarno / http://lighthaus.us/
  20393. * @author tschw
  20394. */
  20395. function NumberKeyframeTrack( name, times, values, interpolation ) {
  20396. KeyframeTrack.call( this, name, times, values, interpolation );
  20397. }
  20398. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20399. constructor: NumberKeyframeTrack,
  20400. ValueTypeName: 'number'
  20401. // ValueBufferType is inherited
  20402. // DefaultInterpolation is inherited
  20403. } );
  20404. /**
  20405. * Fast and simple cubic spline interpolant.
  20406. *
  20407. * It was derived from a Hermitian construction setting the first derivative
  20408. * at each sample position to the linear slope between neighboring positions
  20409. * over their parameter interval.
  20410. *
  20411. * @author tschw
  20412. */
  20413. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20414. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20415. this._weightPrev = - 0;
  20416. this._offsetPrev = - 0;
  20417. this._weightNext = - 0;
  20418. this._offsetNext = - 0;
  20419. }
  20420. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20421. constructor: CubicInterpolant,
  20422. DefaultSettings_: {
  20423. endingStart: ZeroCurvatureEnding,
  20424. endingEnd: ZeroCurvatureEnding
  20425. },
  20426. intervalChanged_: function ( i1, t0, t1 ) {
  20427. var pp = this.parameterPositions,
  20428. iPrev = i1 - 2,
  20429. iNext = i1 + 1,
  20430. tPrev = pp[ iPrev ],
  20431. tNext = pp[ iNext ];
  20432. if ( tPrev === undefined ) {
  20433. switch ( this.getSettings_().endingStart ) {
  20434. case ZeroSlopeEnding:
  20435. // f'(t0) = 0
  20436. iPrev = i1;
  20437. tPrev = 2 * t0 - t1;
  20438. break;
  20439. case WrapAroundEnding:
  20440. // use the other end of the curve
  20441. iPrev = pp.length - 2;
  20442. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  20443. break;
  20444. default: // ZeroCurvatureEnding
  20445. // f''(t0) = 0 a.k.a. Natural Spline
  20446. iPrev = i1;
  20447. tPrev = t1;
  20448. }
  20449. }
  20450. if ( tNext === undefined ) {
  20451. switch ( this.getSettings_().endingEnd ) {
  20452. case ZeroSlopeEnding:
  20453. // f'(tN) = 0
  20454. iNext = i1;
  20455. tNext = 2 * t1 - t0;
  20456. break;
  20457. case WrapAroundEnding:
  20458. // use the other end of the curve
  20459. iNext = 1;
  20460. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  20461. break;
  20462. default: // ZeroCurvatureEnding
  20463. // f''(tN) = 0, a.k.a. Natural Spline
  20464. iNext = i1 - 1;
  20465. tNext = t0;
  20466. }
  20467. }
  20468. var halfDt = ( t1 - t0 ) * 0.5,
  20469. stride = this.valueSize;
  20470. this._weightPrev = halfDt / ( t0 - tPrev );
  20471. this._weightNext = halfDt / ( tNext - t1 );
  20472. this._offsetPrev = iPrev * stride;
  20473. this._offsetNext = iNext * stride;
  20474. },
  20475. interpolate_: function ( i1, t0, t, t1 ) {
  20476. var result = this.resultBuffer,
  20477. values = this.sampleValues,
  20478. stride = this.valueSize,
  20479. o1 = i1 * stride, o0 = o1 - stride,
  20480. oP = this._offsetPrev, oN = this._offsetNext,
  20481. wP = this._weightPrev, wN = this._weightNext,
  20482. p = ( t - t0 ) / ( t1 - t0 ),
  20483. pp = p * p,
  20484. ppp = pp * p;
  20485. // evaluate polynomials
  20486. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  20487. var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  20488. var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  20489. var sN = wN * ppp - wN * pp;
  20490. // combine data linearly
  20491. for ( var i = 0; i !== stride; ++ i ) {
  20492. result[ i ] =
  20493. sP * values[ oP + i ] +
  20494. s0 * values[ o0 + i ] +
  20495. s1 * values[ o1 + i ] +
  20496. sN * values[ oN + i ];
  20497. }
  20498. return result;
  20499. }
  20500. } );
  20501. /**
  20502. * @author tschw
  20503. */
  20504. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20505. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20506. }
  20507. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20508. constructor: LinearInterpolant,
  20509. interpolate_: function ( i1, t0, t, t1 ) {
  20510. var result = this.resultBuffer,
  20511. values = this.sampleValues,
  20512. stride = this.valueSize,
  20513. offset1 = i1 * stride,
  20514. offset0 = offset1 - stride,
  20515. weight1 = ( t - t0 ) / ( t1 - t0 ),
  20516. weight0 = 1 - weight1;
  20517. for ( var i = 0; i !== stride; ++ i ) {
  20518. result[ i ] =
  20519. values[ offset0 + i ] * weight0 +
  20520. values[ offset1 + i ] * weight1;
  20521. }
  20522. return result;
  20523. }
  20524. } );
  20525. /**
  20526. *
  20527. * Interpolant that evaluates to the sample value at the position preceeding
  20528. * the parameter.
  20529. *
  20530. * @author tschw
  20531. */
  20532. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20533. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20534. }
  20535. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20536. constructor: DiscreteInterpolant,
  20537. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  20538. return this.copySampleValue_( i1 - 1 );
  20539. }
  20540. } );
  20541. /**
  20542. * @author tschw
  20543. * @author Ben Houston / http://clara.io/
  20544. * @author David Sarno / http://lighthaus.us/
  20545. */
  20546. var AnimationUtils = {
  20547. // same as Array.prototype.slice, but also works on typed arrays
  20548. arraySlice: function ( array, from, to ) {
  20549. if ( AnimationUtils.isTypedArray( array ) ) {
  20550. // in ios9 array.subarray(from, undefined) will return empty array
  20551. // but array.subarray(from) or array.subarray(from, len) is correct
  20552. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  20553. }
  20554. return array.slice( from, to );
  20555. },
  20556. // converts an array to a specific type
  20557. convertArray: function ( array, type, forceClone ) {
  20558. if ( ! array || // let 'undefined' and 'null' pass
  20559. ! forceClone && array.constructor === type ) return array;
  20560. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  20561. return new type( array ); // create typed array
  20562. }
  20563. return Array.prototype.slice.call( array ); // create Array
  20564. },
  20565. isTypedArray: function ( object ) {
  20566. return ArrayBuffer.isView( object ) &&
  20567. ! ( object instanceof DataView );
  20568. },
  20569. // returns an array by which times and values can be sorted
  20570. getKeyframeOrder: function ( times ) {
  20571. function compareTime( i, j ) {
  20572. return times[ i ] - times[ j ];
  20573. }
  20574. var n = times.length;
  20575. var result = new Array( n );
  20576. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  20577. result.sort( compareTime );
  20578. return result;
  20579. },
  20580. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20581. sortedArray: function ( values, stride, order ) {
  20582. var nValues = values.length;
  20583. var result = new values.constructor( nValues );
  20584. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  20585. var srcOffset = order[ i ] * stride;
  20586. for ( var j = 0; j !== stride; ++ j ) {
  20587. result[ dstOffset ++ ] = values[ srcOffset + j ];
  20588. }
  20589. }
  20590. return result;
  20591. },
  20592. // function for parsing AOS keyframe formats
  20593. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  20594. var i = 1, key = jsonKeys[ 0 ];
  20595. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  20596. key = jsonKeys[ i ++ ];
  20597. }
  20598. if ( key === undefined ) return; // no data
  20599. var value = key[ valuePropertyName ];
  20600. if ( value === undefined ) return; // no data
  20601. if ( Array.isArray( value ) ) {
  20602. do {
  20603. value = key[ valuePropertyName ];
  20604. if ( value !== undefined ) {
  20605. times.push( key.time );
  20606. values.push.apply( values, value ); // push all elements
  20607. }
  20608. key = jsonKeys[ i ++ ];
  20609. } while ( key !== undefined );
  20610. } else if ( value.toArray !== undefined ) {
  20611. // ...assume THREE.Math-ish
  20612. do {
  20613. value = key[ valuePropertyName ];
  20614. if ( value !== undefined ) {
  20615. times.push( key.time );
  20616. value.toArray( values, values.length );
  20617. }
  20618. key = jsonKeys[ i ++ ];
  20619. } while ( key !== undefined );
  20620. } else {
  20621. // otherwise push as-is
  20622. do {
  20623. value = key[ valuePropertyName ];
  20624. if ( value !== undefined ) {
  20625. times.push( key.time );
  20626. values.push( value );
  20627. }
  20628. key = jsonKeys[ i ++ ];
  20629. } while ( key !== undefined );
  20630. }
  20631. }
  20632. };
  20633. /**
  20634. *
  20635. * A timed sequence of keyframes for a specific property.
  20636. *
  20637. *
  20638. * @author Ben Houston / http://clara.io/
  20639. * @author David Sarno / http://lighthaus.us/
  20640. * @author tschw
  20641. */
  20642. function KeyframeTrack( name, times, values, interpolation ) {
  20643. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  20644. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  20645. this.name = name;
  20646. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  20647. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  20648. this.setInterpolation( interpolation || this.DefaultInterpolation );
  20649. this.validate();
  20650. this.optimize();
  20651. }
  20652. // Static methods:
  20653. Object.assign( KeyframeTrack, {
  20654. // Serialization (in static context, because of constructor invocation
  20655. // and automatic invocation of .toJSON):
  20656. parse: function ( json ) {
  20657. if ( json.type === undefined ) {
  20658. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  20659. }
  20660. var trackType = KeyframeTrack._getTrackTypeForValueTypeName( json.type );
  20661. if ( json.times === undefined ) {
  20662. var times = [], values = [];
  20663. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  20664. json.times = times;
  20665. json.values = values;
  20666. }
  20667. // derived classes can define a static parse method
  20668. if ( trackType.parse !== undefined ) {
  20669. return trackType.parse( json );
  20670. } else {
  20671. // by default, we assume a constructor compatible with the base
  20672. return new trackType( json.name, json.times, json.values, json.interpolation );
  20673. }
  20674. },
  20675. toJSON: function ( track ) {
  20676. var trackType = track.constructor;
  20677. var json;
  20678. // derived classes can define a static toJSON method
  20679. if ( trackType.toJSON !== undefined ) {
  20680. json = trackType.toJSON( track );
  20681. } else {
  20682. // by default, we assume the data can be serialized as-is
  20683. json = {
  20684. 'name': track.name,
  20685. 'times': AnimationUtils.convertArray( track.times, Array ),
  20686. 'values': AnimationUtils.convertArray( track.values, Array )
  20687. };
  20688. var interpolation = track.getInterpolation();
  20689. if ( interpolation !== track.DefaultInterpolation ) {
  20690. json.interpolation = interpolation;
  20691. }
  20692. }
  20693. json.type = track.ValueTypeName; // mandatory
  20694. return json;
  20695. },
  20696. _getTrackTypeForValueTypeName: function ( typeName ) {
  20697. switch ( typeName.toLowerCase() ) {
  20698. case 'scalar':
  20699. case 'double':
  20700. case 'float':
  20701. case 'number':
  20702. case 'integer':
  20703. return NumberKeyframeTrack;
  20704. case 'vector':
  20705. case 'vector2':
  20706. case 'vector3':
  20707. case 'vector4':
  20708. return VectorKeyframeTrack;
  20709. case 'color':
  20710. return ColorKeyframeTrack;
  20711. case 'quaternion':
  20712. return QuaternionKeyframeTrack;
  20713. case 'bool':
  20714. case 'boolean':
  20715. return BooleanKeyframeTrack;
  20716. case 'string':
  20717. return StringKeyframeTrack;
  20718. }
  20719. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  20720. }
  20721. } );
  20722. Object.assign( KeyframeTrack.prototype, {
  20723. constructor: KeyframeTrack,
  20724. TimeBufferType: Float32Array,
  20725. ValueBufferType: Float32Array,
  20726. DefaultInterpolation: InterpolateLinear,
  20727. InterpolantFactoryMethodDiscrete: function ( result ) {
  20728. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  20729. },
  20730. InterpolantFactoryMethodLinear: function ( result ) {
  20731. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20732. },
  20733. InterpolantFactoryMethodSmooth: function ( result ) {
  20734. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  20735. },
  20736. setInterpolation: function ( interpolation ) {
  20737. var factoryMethod;
  20738. switch ( interpolation ) {
  20739. case InterpolateDiscrete:
  20740. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  20741. break;
  20742. case InterpolateLinear:
  20743. factoryMethod = this.InterpolantFactoryMethodLinear;
  20744. break;
  20745. case InterpolateSmooth:
  20746. factoryMethod = this.InterpolantFactoryMethodSmooth;
  20747. break;
  20748. }
  20749. if ( factoryMethod === undefined ) {
  20750. var message = "unsupported interpolation for " +
  20751. this.ValueTypeName + " keyframe track named " + this.name;
  20752. if ( this.createInterpolant === undefined ) {
  20753. // fall back to default, unless the default itself is messed up
  20754. if ( interpolation !== this.DefaultInterpolation ) {
  20755. this.setInterpolation( this.DefaultInterpolation );
  20756. } else {
  20757. throw new Error( message ); // fatal, in this case
  20758. }
  20759. }
  20760. console.warn( 'THREE.KeyframeTrack:', message );
  20761. return;
  20762. }
  20763. this.createInterpolant = factoryMethod;
  20764. },
  20765. getInterpolation: function () {
  20766. switch ( this.createInterpolant ) {
  20767. case this.InterpolantFactoryMethodDiscrete:
  20768. return InterpolateDiscrete;
  20769. case this.InterpolantFactoryMethodLinear:
  20770. return InterpolateLinear;
  20771. case this.InterpolantFactoryMethodSmooth:
  20772. return InterpolateSmooth;
  20773. }
  20774. },
  20775. getValueSize: function () {
  20776. return this.values.length / this.times.length;
  20777. },
  20778. // move all keyframes either forwards or backwards in time
  20779. shift: function ( timeOffset ) {
  20780. if ( timeOffset !== 0.0 ) {
  20781. var times = this.times;
  20782. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  20783. times[ i ] += timeOffset;
  20784. }
  20785. }
  20786. return this;
  20787. },
  20788. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  20789. scale: function ( timeScale ) {
  20790. if ( timeScale !== 1.0 ) {
  20791. var times = this.times;
  20792. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  20793. times[ i ] *= timeScale;
  20794. }
  20795. }
  20796. return this;
  20797. },
  20798. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  20799. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  20800. trim: function ( startTime, endTime ) {
  20801. var times = this.times,
  20802. nKeys = times.length,
  20803. from = 0,
  20804. to = nKeys - 1;
  20805. while ( from !== nKeys && times[ from ] < startTime ) {
  20806. ++ from;
  20807. }
  20808. while ( to !== - 1 && times[ to ] > endTime ) {
  20809. -- to;
  20810. }
  20811. ++ to; // inclusive -> exclusive bound
  20812. if ( from !== 0 || to !== nKeys ) {
  20813. // empty tracks are forbidden, so keep at least one keyframe
  20814. if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
  20815. var stride = this.getValueSize();
  20816. this.times = AnimationUtils.arraySlice( times, from, to );
  20817. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  20818. }
  20819. return this;
  20820. },
  20821. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  20822. validate: function () {
  20823. var valid = true;
  20824. var valueSize = this.getValueSize();
  20825. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  20826. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  20827. valid = false;
  20828. }
  20829. var times = this.times,
  20830. values = this.values,
  20831. nKeys = times.length;
  20832. if ( nKeys === 0 ) {
  20833. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  20834. valid = false;
  20835. }
  20836. var prevTime = null;
  20837. for ( var i = 0; i !== nKeys; i ++ ) {
  20838. var currTime = times[ i ];
  20839. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  20840. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  20841. valid = false;
  20842. break;
  20843. }
  20844. if ( prevTime !== null && prevTime > currTime ) {
  20845. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  20846. valid = false;
  20847. break;
  20848. }
  20849. prevTime = currTime;
  20850. }
  20851. if ( values !== undefined ) {
  20852. if ( AnimationUtils.isTypedArray( values ) ) {
  20853. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  20854. var value = values[ i ];
  20855. if ( isNaN( value ) ) {
  20856. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  20857. valid = false;
  20858. break;
  20859. }
  20860. }
  20861. }
  20862. }
  20863. return valid;
  20864. },
  20865. // removes equivalent sequential keys as common in morph target sequences
  20866. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  20867. optimize: function () {
  20868. var times = this.times,
  20869. values = this.values,
  20870. stride = this.getValueSize(),
  20871. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  20872. writeIndex = 1,
  20873. lastIndex = times.length - 1;
  20874. for ( var i = 1; i < lastIndex; ++ i ) {
  20875. var keep = false;
  20876. var time = times[ i ];
  20877. var timeNext = times[ i + 1 ];
  20878. // remove adjacent keyframes scheduled at the same time
  20879. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  20880. if ( ! smoothInterpolation ) {
  20881. // remove unnecessary keyframes same as their neighbors
  20882. var offset = i * stride,
  20883. offsetP = offset - stride,
  20884. offsetN = offset + stride;
  20885. for ( var j = 0; j !== stride; ++ j ) {
  20886. var value = values[ offset + j ];
  20887. if ( value !== values[ offsetP + j ] ||
  20888. value !== values[ offsetN + j ] ) {
  20889. keep = true;
  20890. break;
  20891. }
  20892. }
  20893. } else {
  20894. keep = true;
  20895. }
  20896. }
  20897. // in-place compaction
  20898. if ( keep ) {
  20899. if ( i !== writeIndex ) {
  20900. times[ writeIndex ] = times[ i ];
  20901. var readOffset = i * stride,
  20902. writeOffset = writeIndex * stride;
  20903. for ( var j = 0; j !== stride; ++ j ) {
  20904. values[ writeOffset + j ] = values[ readOffset + j ];
  20905. }
  20906. }
  20907. ++ writeIndex;
  20908. }
  20909. }
  20910. // flush last keyframe (compaction looks ahead)
  20911. if ( lastIndex > 0 ) {
  20912. times[ writeIndex ] = times[ lastIndex ];
  20913. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  20914. values[ writeOffset + j ] = values[ readOffset + j ];
  20915. }
  20916. ++ writeIndex;
  20917. }
  20918. if ( writeIndex !== times.length ) {
  20919. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  20920. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  20921. }
  20922. return this;
  20923. }
  20924. } );
  20925. /**
  20926. *
  20927. * A Track of vectored keyframe values.
  20928. *
  20929. *
  20930. * @author Ben Houston / http://clara.io/
  20931. * @author David Sarno / http://lighthaus.us/
  20932. * @author tschw
  20933. */
  20934. function VectorKeyframeTrack( name, times, values, interpolation ) {
  20935. KeyframeTrack.call( this, name, times, values, interpolation );
  20936. }
  20937. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20938. constructor: VectorKeyframeTrack,
  20939. ValueTypeName: 'vector'
  20940. // ValueBufferType is inherited
  20941. // DefaultInterpolation is inherited
  20942. } );
  20943. /**
  20944. *
  20945. * Reusable set of Tracks that represent an animation.
  20946. *
  20947. * @author Ben Houston / http://clara.io/
  20948. * @author David Sarno / http://lighthaus.us/
  20949. */
  20950. function AnimationClip( name, duration, tracks ) {
  20951. this.name = name;
  20952. this.tracks = tracks;
  20953. this.duration = ( duration !== undefined ) ? duration : - 1;
  20954. this.uuid = _Math.generateUUID();
  20955. // this means it should figure out its duration by scanning the tracks
  20956. if ( this.duration < 0 ) {
  20957. this.resetDuration();
  20958. }
  20959. this.optimize();
  20960. }
  20961. Object.assign( AnimationClip, {
  20962. parse: function ( json ) {
  20963. var tracks = [],
  20964. jsonTracks = json.tracks,
  20965. frameTime = 1.0 / ( json.fps || 1.0 );
  20966. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  20967. tracks.push( KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
  20968. }
  20969. return new AnimationClip( json.name, json.duration, tracks );
  20970. },
  20971. toJSON: function ( clip ) {
  20972. var tracks = [],
  20973. clipTracks = clip.tracks;
  20974. var json = {
  20975. 'name': clip.name,
  20976. 'duration': clip.duration,
  20977. 'tracks': tracks
  20978. };
  20979. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  20980. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  20981. }
  20982. return json;
  20983. },
  20984. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  20985. var numMorphTargets = morphTargetSequence.length;
  20986. var tracks = [];
  20987. for ( var i = 0; i < numMorphTargets; i ++ ) {
  20988. var times = [];
  20989. var values = [];
  20990. times.push(
  20991. ( i + numMorphTargets - 1 ) % numMorphTargets,
  20992. i,
  20993. ( i + 1 ) % numMorphTargets );
  20994. values.push( 0, 1, 0 );
  20995. var order = AnimationUtils.getKeyframeOrder( times );
  20996. times = AnimationUtils.sortedArray( times, 1, order );
  20997. values = AnimationUtils.sortedArray( values, 1, order );
  20998. // if there is a key at the first frame, duplicate it as the
  20999. // last frame as well for perfect loop.
  21000. if ( ! noLoop && times[ 0 ] === 0 ) {
  21001. times.push( numMorphTargets );
  21002. values.push( values[ 0 ] );
  21003. }
  21004. tracks.push(
  21005. new NumberKeyframeTrack(
  21006. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  21007. times, values
  21008. ).scale( 1.0 / fps ) );
  21009. }
  21010. return new AnimationClip( name, - 1, tracks );
  21011. },
  21012. findByName: function ( objectOrClipArray, name ) {
  21013. var clipArray = objectOrClipArray;
  21014. if ( ! Array.isArray( objectOrClipArray ) ) {
  21015. var o = objectOrClipArray;
  21016. clipArray = o.geometry && o.geometry.animations || o.animations;
  21017. }
  21018. for ( var i = 0; i < clipArray.length; i ++ ) {
  21019. if ( clipArray[ i ].name === name ) {
  21020. return clipArray[ i ];
  21021. }
  21022. }
  21023. return null;
  21024. },
  21025. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  21026. var animationToMorphTargets = {};
  21027. // tested with https://regex101.com/ on trick sequences
  21028. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21029. var pattern = /^([\w-]*?)([\d]+)$/;
  21030. // sort morph target names into animation groups based
  21031. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21032. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  21033. var morphTarget = morphTargets[ i ];
  21034. var parts = morphTarget.name.match( pattern );
  21035. if ( parts && parts.length > 1 ) {
  21036. var name = parts[ 1 ];
  21037. var animationMorphTargets = animationToMorphTargets[ name ];
  21038. if ( ! animationMorphTargets ) {
  21039. animationToMorphTargets[ name ] = animationMorphTargets = [];
  21040. }
  21041. animationMorphTargets.push( morphTarget );
  21042. }
  21043. }
  21044. var clips = [];
  21045. for ( var name in animationToMorphTargets ) {
  21046. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  21047. }
  21048. return clips;
  21049. },
  21050. // parse the animation.hierarchy format
  21051. parseAnimation: function ( animation, bones ) {
  21052. if ( ! animation ) {
  21053. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  21054. return null;
  21055. }
  21056. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  21057. // only return track if there are actually keys.
  21058. if ( animationKeys.length !== 0 ) {
  21059. var times = [];
  21060. var values = [];
  21061. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  21062. // empty keys are filtered out, so check again
  21063. if ( times.length !== 0 ) {
  21064. destTracks.push( new trackType( trackName, times, values ) );
  21065. }
  21066. }
  21067. };
  21068. var tracks = [];
  21069. var clipName = animation.name || 'default';
  21070. // automatic length determination in AnimationClip.
  21071. var duration = animation.length || - 1;
  21072. var fps = animation.fps || 30;
  21073. var hierarchyTracks = animation.hierarchy || [];
  21074. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  21075. var animationKeys = hierarchyTracks[ h ].keys;
  21076. // skip empty tracks
  21077. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  21078. // process morph targets
  21079. if ( animationKeys[ 0 ].morphTargets ) {
  21080. // figure out all morph targets used in this track
  21081. var morphTargetNames = {};
  21082. for ( var k = 0; k < animationKeys.length; k ++ ) {
  21083. if ( animationKeys[ k ].morphTargets ) {
  21084. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  21085. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  21086. }
  21087. }
  21088. }
  21089. // create a track for each morph target with all zero
  21090. // morphTargetInfluences except for the keys in which
  21091. // the morphTarget is named.
  21092. for ( var morphTargetName in morphTargetNames ) {
  21093. var times = [];
  21094. var values = [];
  21095. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  21096. var animationKey = animationKeys[ k ];
  21097. times.push( animationKey.time );
  21098. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  21099. }
  21100. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  21101. }
  21102. duration = morphTargetNames.length * ( fps || 1.0 );
  21103. } else {
  21104. // ...assume skeletal animation
  21105. var boneName = '.bones[' + bones[ h ].name + ']';
  21106. addNonemptyTrack(
  21107. VectorKeyframeTrack, boneName + '.position',
  21108. animationKeys, 'pos', tracks );
  21109. addNonemptyTrack(
  21110. QuaternionKeyframeTrack, boneName + '.quaternion',
  21111. animationKeys, 'rot', tracks );
  21112. addNonemptyTrack(
  21113. VectorKeyframeTrack, boneName + '.scale',
  21114. animationKeys, 'scl', tracks );
  21115. }
  21116. }
  21117. if ( tracks.length === 0 ) {
  21118. return null;
  21119. }
  21120. var clip = new AnimationClip( clipName, duration, tracks );
  21121. return clip;
  21122. }
  21123. } );
  21124. Object.assign( AnimationClip.prototype, {
  21125. resetDuration: function () {
  21126. var tracks = this.tracks, duration = 0;
  21127. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  21128. var track = this.tracks[ i ];
  21129. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  21130. }
  21131. this.duration = duration;
  21132. },
  21133. trim: function () {
  21134. for ( var i = 0; i < this.tracks.length; i ++ ) {
  21135. this.tracks[ i ].trim( 0, this.duration );
  21136. }
  21137. return this;
  21138. },
  21139. optimize: function () {
  21140. for ( var i = 0; i < this.tracks.length; i ++ ) {
  21141. this.tracks[ i ].optimize();
  21142. }
  21143. return this;
  21144. }
  21145. } );
  21146. /**
  21147. * @author mrdoob / http://mrdoob.com/
  21148. */
  21149. function MaterialLoader( manager ) {
  21150. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21151. this.textures = {};
  21152. }
  21153. Object.assign( MaterialLoader.prototype, {
  21154. load: function ( url, onLoad, onProgress, onError ) {
  21155. var scope = this;
  21156. var loader = new FileLoader( scope.manager );
  21157. loader.load( url, function ( text ) {
  21158. onLoad( scope.parse( JSON.parse( text ) ) );
  21159. }, onProgress, onError );
  21160. },
  21161. setTextures: function ( value ) {
  21162. this.textures = value;
  21163. },
  21164. parse: function ( json ) {
  21165. var textures = this.textures;
  21166. function getTexture( name ) {
  21167. if ( textures[ name ] === undefined ) {
  21168. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  21169. }
  21170. return textures[ name ];
  21171. }
  21172. var material = new Materials[ json.type ]();
  21173. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  21174. if ( json.name !== undefined ) material.name = json.name;
  21175. if ( json.color !== undefined ) material.color.setHex( json.color );
  21176. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  21177. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  21178. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  21179. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  21180. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  21181. if ( json.clearCoat !== undefined ) material.clearCoat = json.clearCoat;
  21182. if ( json.clearCoatRoughness !== undefined ) material.clearCoatRoughness = json.clearCoatRoughness;
  21183. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  21184. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  21185. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  21186. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  21187. if ( json.fog !== undefined ) material.fog = json.fog;
  21188. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  21189. if ( json.blending !== undefined ) material.blending = json.blending;
  21190. if ( json.side !== undefined ) material.side = json.side;
  21191. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  21192. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  21193. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  21194. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  21195. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  21196. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  21197. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  21198. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  21199. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  21200. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  21201. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  21202. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  21203. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  21204. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  21205. if ( json.scale !== undefined ) material.scale = json.scale;
  21206. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  21207. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  21208. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  21209. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  21210. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  21211. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  21212. if ( json.visible !== undefined ) material.visible = json.visible;
  21213. if ( json.userData !== undefined ) material.userData = json.userData;
  21214. // Deprecated
  21215. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  21216. // for PointsMaterial
  21217. if ( json.size !== undefined ) material.size = json.size;
  21218. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  21219. // maps
  21220. if ( json.map !== undefined ) material.map = getTexture( json.map );
  21221. if ( json.alphaMap !== undefined ) {
  21222. material.alphaMap = getTexture( json.alphaMap );
  21223. material.transparent = true;
  21224. }
  21225. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  21226. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  21227. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  21228. if ( json.normalScale !== undefined ) {
  21229. var normalScale = json.normalScale;
  21230. if ( Array.isArray( normalScale ) === false ) {
  21231. // Blender exporter used to export a scalar. See #7459
  21232. normalScale = [ normalScale, normalScale ];
  21233. }
  21234. material.normalScale = new Vector2().fromArray( normalScale );
  21235. }
  21236. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  21237. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  21238. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  21239. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  21240. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  21241. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  21242. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  21243. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  21244. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  21245. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  21246. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  21247. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  21248. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  21249. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  21250. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  21251. return material;
  21252. }
  21253. } );
  21254. /**
  21255. * @author mrdoob / http://mrdoob.com/
  21256. */
  21257. function BufferGeometryLoader( manager ) {
  21258. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21259. }
  21260. Object.assign( BufferGeometryLoader.prototype, {
  21261. load: function ( url, onLoad, onProgress, onError ) {
  21262. var scope = this;
  21263. var loader = new FileLoader( scope.manager );
  21264. loader.load( url, function ( text ) {
  21265. onLoad( scope.parse( JSON.parse( text ) ) );
  21266. }, onProgress, onError );
  21267. },
  21268. parse: function ( json ) {
  21269. var geometry = new BufferGeometry();
  21270. var index = json.data.index;
  21271. if ( index !== undefined ) {
  21272. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  21273. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  21274. }
  21275. var attributes = json.data.attributes;
  21276. for ( var key in attributes ) {
  21277. var attribute = attributes[ key ];
  21278. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  21279. geometry.addAttribute( key, new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized ) );
  21280. }
  21281. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  21282. if ( groups !== undefined ) {
  21283. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  21284. var group = groups[ i ];
  21285. geometry.addGroup( group.start, group.count, group.materialIndex );
  21286. }
  21287. }
  21288. var boundingSphere = json.data.boundingSphere;
  21289. if ( boundingSphere !== undefined ) {
  21290. var center = new Vector3();
  21291. if ( boundingSphere.center !== undefined ) {
  21292. center.fromArray( boundingSphere.center );
  21293. }
  21294. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  21295. }
  21296. return geometry;
  21297. }
  21298. } );
  21299. var TYPED_ARRAYS = {
  21300. Int8Array: Int8Array,
  21301. Uint8Array: Uint8Array,
  21302. // Workaround for IE11 pre KB2929437. See #11440
  21303. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  21304. Int16Array: Int16Array,
  21305. Uint16Array: Uint16Array,
  21306. Int32Array: Int32Array,
  21307. Uint32Array: Uint32Array,
  21308. Float32Array: Float32Array,
  21309. Float64Array: Float64Array
  21310. };
  21311. /**
  21312. * @author alteredq / http://alteredqualia.com/
  21313. */
  21314. function Loader() {}
  21315. Loader.Handlers = {
  21316. handlers: [],
  21317. add: function ( regex, loader ) {
  21318. this.handlers.push( regex, loader );
  21319. },
  21320. get: function ( file ) {
  21321. var handlers = this.handlers;
  21322. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  21323. var regex = handlers[ i ];
  21324. var loader = handlers[ i + 1 ];
  21325. if ( regex.test( file ) ) {
  21326. return loader;
  21327. }
  21328. }
  21329. return null;
  21330. }
  21331. };
  21332. Object.assign( Loader.prototype, {
  21333. crossOrigin: undefined,
  21334. onLoadStart: function () {},
  21335. onLoadProgress: function () {},
  21336. onLoadComplete: function () {},
  21337. initMaterials: function ( materials, texturePath, crossOrigin ) {
  21338. var array = [];
  21339. for ( var i = 0; i < materials.length; ++ i ) {
  21340. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  21341. }
  21342. return array;
  21343. },
  21344. createMaterial: ( function () {
  21345. var BlendingMode = {
  21346. NoBlending: NoBlending,
  21347. NormalBlending: NormalBlending,
  21348. AdditiveBlending: AdditiveBlending,
  21349. SubtractiveBlending: SubtractiveBlending,
  21350. MultiplyBlending: MultiplyBlending,
  21351. CustomBlending: CustomBlending
  21352. };
  21353. var color = new Color();
  21354. var textureLoader = new TextureLoader();
  21355. var materialLoader = new MaterialLoader();
  21356. return function createMaterial( m, texturePath, crossOrigin ) {
  21357. // convert from old material format
  21358. var textures = {};
  21359. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  21360. var fullPath = texturePath + path;
  21361. var loader = Loader.Handlers.get( fullPath );
  21362. var texture;
  21363. if ( loader !== null ) {
  21364. texture = loader.load( fullPath );
  21365. } else {
  21366. textureLoader.setCrossOrigin( crossOrigin );
  21367. texture = textureLoader.load( fullPath );
  21368. }
  21369. if ( repeat !== undefined ) {
  21370. texture.repeat.fromArray( repeat );
  21371. if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
  21372. if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
  21373. }
  21374. if ( offset !== undefined ) {
  21375. texture.offset.fromArray( offset );
  21376. }
  21377. if ( wrap !== undefined ) {
  21378. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
  21379. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
  21380. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
  21381. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
  21382. }
  21383. if ( anisotropy !== undefined ) {
  21384. texture.anisotropy = anisotropy;
  21385. }
  21386. var uuid = _Math.generateUUID();
  21387. textures[ uuid ] = texture;
  21388. return uuid;
  21389. }
  21390. //
  21391. var json = {
  21392. uuid: _Math.generateUUID(),
  21393. type: 'MeshLambertMaterial'
  21394. };
  21395. for ( var name in m ) {
  21396. var value = m[ name ];
  21397. switch ( name ) {
  21398. case 'DbgColor':
  21399. case 'DbgIndex':
  21400. case 'opticalDensity':
  21401. case 'illumination':
  21402. break;
  21403. case 'DbgName':
  21404. json.name = value;
  21405. break;
  21406. case 'blending':
  21407. json.blending = BlendingMode[ value ];
  21408. break;
  21409. case 'colorAmbient':
  21410. case 'mapAmbient':
  21411. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  21412. break;
  21413. case 'colorDiffuse':
  21414. json.color = color.fromArray( value ).getHex();
  21415. break;
  21416. case 'colorSpecular':
  21417. json.specular = color.fromArray( value ).getHex();
  21418. break;
  21419. case 'colorEmissive':
  21420. json.emissive = color.fromArray( value ).getHex();
  21421. break;
  21422. case 'specularCoef':
  21423. json.shininess = value;
  21424. break;
  21425. case 'shading':
  21426. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  21427. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  21428. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  21429. break;
  21430. case 'mapDiffuse':
  21431. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  21432. break;
  21433. case 'mapDiffuseRepeat':
  21434. case 'mapDiffuseOffset':
  21435. case 'mapDiffuseWrap':
  21436. case 'mapDiffuseAnisotropy':
  21437. break;
  21438. case 'mapEmissive':
  21439. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  21440. break;
  21441. case 'mapEmissiveRepeat':
  21442. case 'mapEmissiveOffset':
  21443. case 'mapEmissiveWrap':
  21444. case 'mapEmissiveAnisotropy':
  21445. break;
  21446. case 'mapLight':
  21447. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  21448. break;
  21449. case 'mapLightRepeat':
  21450. case 'mapLightOffset':
  21451. case 'mapLightWrap':
  21452. case 'mapLightAnisotropy':
  21453. break;
  21454. case 'mapAO':
  21455. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  21456. break;
  21457. case 'mapAORepeat':
  21458. case 'mapAOOffset':
  21459. case 'mapAOWrap':
  21460. case 'mapAOAnisotropy':
  21461. break;
  21462. case 'mapBump':
  21463. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  21464. break;
  21465. case 'mapBumpScale':
  21466. json.bumpScale = value;
  21467. break;
  21468. case 'mapBumpRepeat':
  21469. case 'mapBumpOffset':
  21470. case 'mapBumpWrap':
  21471. case 'mapBumpAnisotropy':
  21472. break;
  21473. case 'mapNormal':
  21474. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  21475. break;
  21476. case 'mapNormalFactor':
  21477. json.normalScale = value;
  21478. break;
  21479. case 'mapNormalRepeat':
  21480. case 'mapNormalOffset':
  21481. case 'mapNormalWrap':
  21482. case 'mapNormalAnisotropy':
  21483. break;
  21484. case 'mapSpecular':
  21485. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  21486. break;
  21487. case 'mapSpecularRepeat':
  21488. case 'mapSpecularOffset':
  21489. case 'mapSpecularWrap':
  21490. case 'mapSpecularAnisotropy':
  21491. break;
  21492. case 'mapMetalness':
  21493. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  21494. break;
  21495. case 'mapMetalnessRepeat':
  21496. case 'mapMetalnessOffset':
  21497. case 'mapMetalnessWrap':
  21498. case 'mapMetalnessAnisotropy':
  21499. break;
  21500. case 'mapRoughness':
  21501. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  21502. break;
  21503. case 'mapRoughnessRepeat':
  21504. case 'mapRoughnessOffset':
  21505. case 'mapRoughnessWrap':
  21506. case 'mapRoughnessAnisotropy':
  21507. break;
  21508. case 'mapAlpha':
  21509. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  21510. break;
  21511. case 'mapAlphaRepeat':
  21512. case 'mapAlphaOffset':
  21513. case 'mapAlphaWrap':
  21514. case 'mapAlphaAnisotropy':
  21515. break;
  21516. case 'flipSided':
  21517. json.side = BackSide;
  21518. break;
  21519. case 'doubleSided':
  21520. json.side = DoubleSide;
  21521. break;
  21522. case 'transparency':
  21523. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  21524. json.opacity = value;
  21525. break;
  21526. case 'depthTest':
  21527. case 'depthWrite':
  21528. case 'colorWrite':
  21529. case 'opacity':
  21530. case 'reflectivity':
  21531. case 'transparent':
  21532. case 'visible':
  21533. case 'wireframe':
  21534. json[ name ] = value;
  21535. break;
  21536. case 'vertexColors':
  21537. if ( value === true ) json.vertexColors = VertexColors;
  21538. if ( value === 'face' ) json.vertexColors = FaceColors;
  21539. break;
  21540. default:
  21541. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  21542. break;
  21543. }
  21544. }
  21545. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  21546. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  21547. if ( json.opacity < 1 ) json.transparent = true;
  21548. materialLoader.setTextures( textures );
  21549. return materialLoader.parse( json );
  21550. };
  21551. } )()
  21552. } );
  21553. /**
  21554. * @author Don McCurdy / https://www.donmccurdy.com
  21555. */
  21556. var LoaderUtils = {
  21557. decodeText: function ( array ) {
  21558. if ( typeof TextDecoder !== 'undefined' ) {
  21559. return new TextDecoder().decode( array );
  21560. }
  21561. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  21562. // throws a "maximum call stack size exceeded" error for large arrays.
  21563. var s = '';
  21564. for ( var i = 0, il = array.length; i < il; i ++ ) {
  21565. // Implicitly assumes little-endian.
  21566. s += String.fromCharCode( array[ i ] );
  21567. }
  21568. // Merges multi-byte utf-8 characters.
  21569. return decodeURIComponent( escape( s ) );
  21570. },
  21571. extractUrlBase: function ( url ) {
  21572. var index = url.lastIndexOf( '/' );
  21573. if ( index === - 1 ) return './';
  21574. return url.substr( 0, index + 1 );
  21575. }
  21576. };
  21577. /**
  21578. * @author mrdoob / http://mrdoob.com/
  21579. * @author alteredq / http://alteredqualia.com/
  21580. */
  21581. function JSONLoader( manager ) {
  21582. if ( typeof manager === 'boolean' ) {
  21583. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  21584. manager = undefined;
  21585. }
  21586. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21587. this.withCredentials = false;
  21588. }
  21589. Object.assign( JSONLoader.prototype, {
  21590. load: function ( url, onLoad, onProgress, onError ) {
  21591. var scope = this;
  21592. var texturePath = this.texturePath && ( typeof this.texturePath === 'string' ) ? this.texturePath : LoaderUtils.extractUrlBase( url );
  21593. var loader = new FileLoader( this.manager );
  21594. loader.setWithCredentials( this.withCredentials );
  21595. loader.load( url, function ( text ) {
  21596. var json = JSON.parse( text );
  21597. var metadata = json.metadata;
  21598. if ( metadata !== undefined ) {
  21599. var type = metadata.type;
  21600. if ( type !== undefined ) {
  21601. if ( type.toLowerCase() === 'object' ) {
  21602. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  21603. return;
  21604. }
  21605. }
  21606. }
  21607. var object = scope.parse( json, texturePath );
  21608. onLoad( object.geometry, object.materials );
  21609. }, onProgress, onError );
  21610. },
  21611. setTexturePath: function ( value ) {
  21612. this.texturePath = value;
  21613. },
  21614. parse: ( function () {
  21615. function parseModel( json, geometry ) {
  21616. function isBitSet( value, position ) {
  21617. return value & ( 1 << position );
  21618. }
  21619. var i, j, fi,
  21620. offset, zLength,
  21621. colorIndex, normalIndex, uvIndex, materialIndex,
  21622. type,
  21623. isQuad,
  21624. hasMaterial,
  21625. hasFaceVertexUv,
  21626. hasFaceNormal, hasFaceVertexNormal,
  21627. hasFaceColor, hasFaceVertexColor,
  21628. vertex, face, faceA, faceB, hex, normal,
  21629. uvLayer, uv, u, v,
  21630. faces = json.faces,
  21631. vertices = json.vertices,
  21632. normals = json.normals,
  21633. colors = json.colors,
  21634. scale = json.scale,
  21635. nUvLayers = 0;
  21636. if ( json.uvs !== undefined ) {
  21637. // disregard empty arrays
  21638. for ( i = 0; i < json.uvs.length; i ++ ) {
  21639. if ( json.uvs[ i ].length ) nUvLayers ++;
  21640. }
  21641. for ( i = 0; i < nUvLayers; i ++ ) {
  21642. geometry.faceVertexUvs[ i ] = [];
  21643. }
  21644. }
  21645. offset = 0;
  21646. zLength = vertices.length;
  21647. while ( offset < zLength ) {
  21648. vertex = new Vector3();
  21649. vertex.x = vertices[ offset ++ ] * scale;
  21650. vertex.y = vertices[ offset ++ ] * scale;
  21651. vertex.z = vertices[ offset ++ ] * scale;
  21652. geometry.vertices.push( vertex );
  21653. }
  21654. offset = 0;
  21655. zLength = faces.length;
  21656. while ( offset < zLength ) {
  21657. type = faces[ offset ++ ];
  21658. isQuad = isBitSet( type, 0 );
  21659. hasMaterial = isBitSet( type, 1 );
  21660. hasFaceVertexUv = isBitSet( type, 3 );
  21661. hasFaceNormal = isBitSet( type, 4 );
  21662. hasFaceVertexNormal = isBitSet( type, 5 );
  21663. hasFaceColor = isBitSet( type, 6 );
  21664. hasFaceVertexColor = isBitSet( type, 7 );
  21665. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  21666. if ( isQuad ) {
  21667. faceA = new Face3();
  21668. faceA.a = faces[ offset ];
  21669. faceA.b = faces[ offset + 1 ];
  21670. faceA.c = faces[ offset + 3 ];
  21671. faceB = new Face3();
  21672. faceB.a = faces[ offset + 1 ];
  21673. faceB.b = faces[ offset + 2 ];
  21674. faceB.c = faces[ offset + 3 ];
  21675. offset += 4;
  21676. if ( hasMaterial ) {
  21677. materialIndex = faces[ offset ++ ];
  21678. faceA.materialIndex = materialIndex;
  21679. faceB.materialIndex = materialIndex;
  21680. }
  21681. // to get face <=> uv index correspondence
  21682. fi = geometry.faces.length;
  21683. if ( hasFaceVertexUv ) {
  21684. for ( i = 0; i < nUvLayers; i ++ ) {
  21685. uvLayer = json.uvs[ i ];
  21686. geometry.faceVertexUvs[ i ][ fi ] = [];
  21687. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  21688. for ( j = 0; j < 4; j ++ ) {
  21689. uvIndex = faces[ offset ++ ];
  21690. u = uvLayer[ uvIndex * 2 ];
  21691. v = uvLayer[ uvIndex * 2 + 1 ];
  21692. uv = new Vector2( u, v );
  21693. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  21694. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  21695. }
  21696. }
  21697. }
  21698. if ( hasFaceNormal ) {
  21699. normalIndex = faces[ offset ++ ] * 3;
  21700. faceA.normal.set(
  21701. normals[ normalIndex ++ ],
  21702. normals[ normalIndex ++ ],
  21703. normals[ normalIndex ]
  21704. );
  21705. faceB.normal.copy( faceA.normal );
  21706. }
  21707. if ( hasFaceVertexNormal ) {
  21708. for ( i = 0; i < 4; i ++ ) {
  21709. normalIndex = faces[ offset ++ ] * 3;
  21710. normal = new Vector3(
  21711. normals[ normalIndex ++ ],
  21712. normals[ normalIndex ++ ],
  21713. normals[ normalIndex ]
  21714. );
  21715. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  21716. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  21717. }
  21718. }
  21719. if ( hasFaceColor ) {
  21720. colorIndex = faces[ offset ++ ];
  21721. hex = colors[ colorIndex ];
  21722. faceA.color.setHex( hex );
  21723. faceB.color.setHex( hex );
  21724. }
  21725. if ( hasFaceVertexColor ) {
  21726. for ( i = 0; i < 4; i ++ ) {
  21727. colorIndex = faces[ offset ++ ];
  21728. hex = colors[ colorIndex ];
  21729. if ( i !== 2 ) faceA.vertexColors.push( new Color( hex ) );
  21730. if ( i !== 0 ) faceB.vertexColors.push( new Color( hex ) );
  21731. }
  21732. }
  21733. geometry.faces.push( faceA );
  21734. geometry.faces.push( faceB );
  21735. } else {
  21736. face = new Face3();
  21737. face.a = faces[ offset ++ ];
  21738. face.b = faces[ offset ++ ];
  21739. face.c = faces[ offset ++ ];
  21740. if ( hasMaterial ) {
  21741. materialIndex = faces[ offset ++ ];
  21742. face.materialIndex = materialIndex;
  21743. }
  21744. // to get face <=> uv index correspondence
  21745. fi = geometry.faces.length;
  21746. if ( hasFaceVertexUv ) {
  21747. for ( i = 0; i < nUvLayers; i ++ ) {
  21748. uvLayer = json.uvs[ i ];
  21749. geometry.faceVertexUvs[ i ][ fi ] = [];
  21750. for ( j = 0; j < 3; j ++ ) {
  21751. uvIndex = faces[ offset ++ ];
  21752. u = uvLayer[ uvIndex * 2 ];
  21753. v = uvLayer[ uvIndex * 2 + 1 ];
  21754. uv = new Vector2( u, v );
  21755. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  21756. }
  21757. }
  21758. }
  21759. if ( hasFaceNormal ) {
  21760. normalIndex = faces[ offset ++ ] * 3;
  21761. face.normal.set(
  21762. normals[ normalIndex ++ ],
  21763. normals[ normalIndex ++ ],
  21764. normals[ normalIndex ]
  21765. );
  21766. }
  21767. if ( hasFaceVertexNormal ) {
  21768. for ( i = 0; i < 3; i ++ ) {
  21769. normalIndex = faces[ offset ++ ] * 3;
  21770. normal = new Vector3(
  21771. normals[ normalIndex ++ ],
  21772. normals[ normalIndex ++ ],
  21773. normals[ normalIndex ]
  21774. );
  21775. face.vertexNormals.push( normal );
  21776. }
  21777. }
  21778. if ( hasFaceColor ) {
  21779. colorIndex = faces[ offset ++ ];
  21780. face.color.setHex( colors[ colorIndex ] );
  21781. }
  21782. if ( hasFaceVertexColor ) {
  21783. for ( i = 0; i < 3; i ++ ) {
  21784. colorIndex = faces[ offset ++ ];
  21785. face.vertexColors.push( new Color( colors[ colorIndex ] ) );
  21786. }
  21787. }
  21788. geometry.faces.push( face );
  21789. }
  21790. }
  21791. }
  21792. function parseSkin( json, geometry ) {
  21793. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  21794. if ( json.skinWeights ) {
  21795. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  21796. var x = json.skinWeights[ i ];
  21797. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  21798. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  21799. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  21800. geometry.skinWeights.push( new Vector4( x, y, z, w ) );
  21801. }
  21802. }
  21803. if ( json.skinIndices ) {
  21804. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  21805. var a = json.skinIndices[ i ];
  21806. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  21807. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  21808. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  21809. geometry.skinIndices.push( new Vector4( a, b, c, d ) );
  21810. }
  21811. }
  21812. geometry.bones = json.bones;
  21813. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  21814. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  21815. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  21816. }
  21817. }
  21818. function parseMorphing( json, geometry ) {
  21819. var scale = json.scale;
  21820. if ( json.morphTargets !== undefined ) {
  21821. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  21822. geometry.morphTargets[ i ] = {};
  21823. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  21824. geometry.morphTargets[ i ].vertices = [];
  21825. var dstVertices = geometry.morphTargets[ i ].vertices;
  21826. var srcVertices = json.morphTargets[ i ].vertices;
  21827. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  21828. var vertex = new Vector3();
  21829. vertex.x = srcVertices[ v ] * scale;
  21830. vertex.y = srcVertices[ v + 1 ] * scale;
  21831. vertex.z = srcVertices[ v + 2 ] * scale;
  21832. dstVertices.push( vertex );
  21833. }
  21834. }
  21835. }
  21836. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  21837. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  21838. var faces = geometry.faces;
  21839. var morphColors = json.morphColors[ 0 ].colors;
  21840. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21841. faces[ i ].color.fromArray( morphColors, i * 3 );
  21842. }
  21843. }
  21844. }
  21845. function parseAnimations( json, geometry ) {
  21846. var outputAnimations = [];
  21847. // parse old style Bone/Hierarchy animations
  21848. var animations = [];
  21849. if ( json.animation !== undefined ) {
  21850. animations.push( json.animation );
  21851. }
  21852. if ( json.animations !== undefined ) {
  21853. if ( json.animations.length ) {
  21854. animations = animations.concat( json.animations );
  21855. } else {
  21856. animations.push( json.animations );
  21857. }
  21858. }
  21859. for ( var i = 0; i < animations.length; i ++ ) {
  21860. var clip = AnimationClip.parseAnimation( animations[ i ], geometry.bones );
  21861. if ( clip ) outputAnimations.push( clip );
  21862. }
  21863. // parse implicit morph animations
  21864. if ( geometry.morphTargets ) {
  21865. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  21866. var morphAnimationClips = AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  21867. outputAnimations = outputAnimations.concat( morphAnimationClips );
  21868. }
  21869. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  21870. }
  21871. return function parse( json, texturePath ) {
  21872. if ( json.data !== undefined ) {
  21873. // Geometry 4.0 spec
  21874. json = json.data;
  21875. }
  21876. if ( json.scale !== undefined ) {
  21877. json.scale = 1.0 / json.scale;
  21878. } else {
  21879. json.scale = 1.0;
  21880. }
  21881. var geometry = new Geometry();
  21882. parseModel( json, geometry );
  21883. parseSkin( json, geometry );
  21884. parseMorphing( json, geometry );
  21885. parseAnimations( json, geometry );
  21886. geometry.computeFaceNormals();
  21887. geometry.computeBoundingSphere();
  21888. if ( json.materials === undefined || json.materials.length === 0 ) {
  21889. return { geometry: geometry };
  21890. } else {
  21891. var materials = Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  21892. return { geometry: geometry, materials: materials };
  21893. }
  21894. };
  21895. } )()
  21896. } );
  21897. /**
  21898. * @author mrdoob / http://mrdoob.com/
  21899. */
  21900. function ObjectLoader( manager ) {
  21901. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21902. this.texturePath = '';
  21903. }
  21904. Object.assign( ObjectLoader.prototype, {
  21905. load: function ( url, onLoad, onProgress, onError ) {
  21906. if ( this.texturePath === '' ) {
  21907. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  21908. }
  21909. var scope = this;
  21910. var loader = new FileLoader( scope.manager );
  21911. loader.load( url, function ( text ) {
  21912. var json = null;
  21913. try {
  21914. json = JSON.parse( text );
  21915. } catch ( error ) {
  21916. if ( onError !== undefined ) onError( error );
  21917. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  21918. return;
  21919. }
  21920. var metadata = json.metadata;
  21921. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  21922. console.error( 'THREE.ObjectLoader: Can\'t load ' + url + '. Use THREE.JSONLoader instead.' );
  21923. return;
  21924. }
  21925. scope.parse( json, onLoad );
  21926. }, onProgress, onError );
  21927. },
  21928. setTexturePath: function ( value ) {
  21929. this.texturePath = value;
  21930. },
  21931. setCrossOrigin: function ( value ) {
  21932. this.crossOrigin = value;
  21933. },
  21934. parse: function ( json, onLoad ) {
  21935. var shapes = this.parseShape( json.shapes );
  21936. var geometries = this.parseGeometries( json.geometries, shapes );
  21937. var images = this.parseImages( json.images, function () {
  21938. if ( onLoad !== undefined ) onLoad( object );
  21939. } );
  21940. var textures = this.parseTextures( json.textures, images );
  21941. var materials = this.parseMaterials( json.materials, textures );
  21942. var object = this.parseObject( json.object, geometries, materials );
  21943. if ( json.animations ) {
  21944. object.animations = this.parseAnimations( json.animations );
  21945. }
  21946. if ( json.images === undefined || json.images.length === 0 ) {
  21947. if ( onLoad !== undefined ) onLoad( object );
  21948. }
  21949. return object;
  21950. },
  21951. parseShape: function ( json ) {
  21952. var shapes = {};
  21953. if ( json !== undefined ) {
  21954. for ( var i = 0, l = json.length; i < l; i ++ ) {
  21955. var shape = new Shape().fromJSON( json[ i ] );
  21956. shapes[ shape.uuid ] = shape;
  21957. }
  21958. }
  21959. return shapes;
  21960. },
  21961. parseGeometries: function ( json, shapes ) {
  21962. var geometries = {};
  21963. if ( json !== undefined ) {
  21964. var geometryLoader = new JSONLoader();
  21965. var bufferGeometryLoader = new BufferGeometryLoader();
  21966. for ( var i = 0, l = json.length; i < l; i ++ ) {
  21967. var geometry;
  21968. var data = json[ i ];
  21969. switch ( data.type ) {
  21970. case 'PlaneGeometry':
  21971. case 'PlaneBufferGeometry':
  21972. geometry = new Geometries[ data.type ](
  21973. data.width,
  21974. data.height,
  21975. data.widthSegments,
  21976. data.heightSegments
  21977. );
  21978. break;
  21979. case 'BoxGeometry':
  21980. case 'BoxBufferGeometry':
  21981. case 'CubeGeometry': // backwards compatible
  21982. geometry = new Geometries[ data.type ](
  21983. data.width,
  21984. data.height,
  21985. data.depth,
  21986. data.widthSegments,
  21987. data.heightSegments,
  21988. data.depthSegments
  21989. );
  21990. break;
  21991. case 'CircleGeometry':
  21992. case 'CircleBufferGeometry':
  21993. geometry = new Geometries[ data.type ](
  21994. data.radius,
  21995. data.segments,
  21996. data.thetaStart,
  21997. data.thetaLength
  21998. );
  21999. break;
  22000. case 'CylinderGeometry':
  22001. case 'CylinderBufferGeometry':
  22002. geometry = new Geometries[ data.type ](
  22003. data.radiusTop,
  22004. data.radiusBottom,
  22005. data.height,
  22006. data.radialSegments,
  22007. data.heightSegments,
  22008. data.openEnded,
  22009. data.thetaStart,
  22010. data.thetaLength
  22011. );
  22012. break;
  22013. case 'ConeGeometry':
  22014. case 'ConeBufferGeometry':
  22015. geometry = new Geometries[ data.type ](
  22016. data.radius,
  22017. data.height,
  22018. data.radialSegments,
  22019. data.heightSegments,
  22020. data.openEnded,
  22021. data.thetaStart,
  22022. data.thetaLength
  22023. );
  22024. break;
  22025. case 'SphereGeometry':
  22026. case 'SphereBufferGeometry':
  22027. geometry = new Geometries[ data.type ](
  22028. data.radius,
  22029. data.widthSegments,
  22030. data.heightSegments,
  22031. data.phiStart,
  22032. data.phiLength,
  22033. data.thetaStart,
  22034. data.thetaLength
  22035. );
  22036. break;
  22037. case 'DodecahedronGeometry':
  22038. case 'DodecahedronBufferGeometry':
  22039. case 'IcosahedronGeometry':
  22040. case 'IcosahedronBufferGeometry':
  22041. case 'OctahedronGeometry':
  22042. case 'OctahedronBufferGeometry':
  22043. case 'TetrahedronGeometry':
  22044. case 'TetrahedronBufferGeometry':
  22045. geometry = new Geometries[ data.type ](
  22046. data.radius,
  22047. data.detail
  22048. );
  22049. break;
  22050. case 'RingGeometry':
  22051. case 'RingBufferGeometry':
  22052. geometry = new Geometries[ data.type ](
  22053. data.innerRadius,
  22054. data.outerRadius,
  22055. data.thetaSegments,
  22056. data.phiSegments,
  22057. data.thetaStart,
  22058. data.thetaLength
  22059. );
  22060. break;
  22061. case 'TorusGeometry':
  22062. case 'TorusBufferGeometry':
  22063. geometry = new Geometries[ data.type ](
  22064. data.radius,
  22065. data.tube,
  22066. data.radialSegments,
  22067. data.tubularSegments,
  22068. data.arc
  22069. );
  22070. break;
  22071. case 'TorusKnotGeometry':
  22072. case 'TorusKnotBufferGeometry':
  22073. geometry = new Geometries[ data.type ](
  22074. data.radius,
  22075. data.tube,
  22076. data.tubularSegments,
  22077. data.radialSegments,
  22078. data.p,
  22079. data.q
  22080. );
  22081. break;
  22082. case 'LatheGeometry':
  22083. case 'LatheBufferGeometry':
  22084. geometry = new Geometries[ data.type ](
  22085. data.points,
  22086. data.segments,
  22087. data.phiStart,
  22088. data.phiLength
  22089. );
  22090. break;
  22091. case 'PolyhedronGeometry':
  22092. case 'PolyhedronBufferGeometry':
  22093. geometry = new Geometries[ data.type ](
  22094. data.vertices,
  22095. data.indices,
  22096. data.radius,
  22097. data.details
  22098. );
  22099. break;
  22100. case 'ShapeGeometry':
  22101. case 'ShapeBufferGeometry':
  22102. var geometryShapes = [];
  22103. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  22104. var shape = shapes[ data.shapes[ j ] ];
  22105. geometryShapes.push( shape );
  22106. }
  22107. geometry = new Geometries[ data.type ](
  22108. geometryShapes,
  22109. data.curveSegments
  22110. );
  22111. break;
  22112. case 'BufferGeometry':
  22113. geometry = bufferGeometryLoader.parse( data );
  22114. break;
  22115. case 'Geometry':
  22116. geometry = geometryLoader.parse( data, this.texturePath ).geometry;
  22117. break;
  22118. default:
  22119. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  22120. continue;
  22121. }
  22122. geometry.uuid = data.uuid;
  22123. if ( data.name !== undefined ) geometry.name = data.name;
  22124. geometries[ data.uuid ] = geometry;
  22125. }
  22126. }
  22127. return geometries;
  22128. },
  22129. parseMaterials: function ( json, textures ) {
  22130. var materials = {};
  22131. if ( json !== undefined ) {
  22132. var loader = new MaterialLoader();
  22133. loader.setTextures( textures );
  22134. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22135. var data = json[ i ];
  22136. if ( data.type === 'MultiMaterial' ) {
  22137. // Deprecated
  22138. var array = [];
  22139. for ( var j = 0; j < data.materials.length; j ++ ) {
  22140. array.push( loader.parse( data.materials[ j ] ) );
  22141. }
  22142. materials[ data.uuid ] = array;
  22143. } else {
  22144. materials[ data.uuid ] = loader.parse( data );
  22145. }
  22146. }
  22147. }
  22148. return materials;
  22149. },
  22150. parseAnimations: function ( json ) {
  22151. var animations = [];
  22152. for ( var i = 0; i < json.length; i ++ ) {
  22153. var clip = AnimationClip.parse( json[ i ] );
  22154. animations.push( clip );
  22155. }
  22156. return animations;
  22157. },
  22158. parseImages: function ( json, onLoad ) {
  22159. var scope = this;
  22160. var images = {};
  22161. function loadImage( url ) {
  22162. scope.manager.itemStart( url );
  22163. return loader.load( url, function () {
  22164. scope.manager.itemEnd( url );
  22165. }, undefined, function () {
  22166. scope.manager.itemEnd( url );
  22167. scope.manager.itemError( url );
  22168. } );
  22169. }
  22170. if ( json !== undefined && json.length > 0 ) {
  22171. var manager = new LoadingManager( onLoad );
  22172. var loader = new ImageLoader( manager );
  22173. loader.setCrossOrigin( this.crossOrigin );
  22174. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22175. var image = json[ i ];
  22176. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  22177. images[ image.uuid ] = loadImage( path );
  22178. }
  22179. }
  22180. return images;
  22181. },
  22182. parseTextures: function ( json, images ) {
  22183. function parseConstant( value, type ) {
  22184. if ( typeof value === 'number' ) return value;
  22185. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  22186. return type[ value ];
  22187. }
  22188. var textures = {};
  22189. if ( json !== undefined ) {
  22190. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22191. var data = json[ i ];
  22192. if ( data.image === undefined ) {
  22193. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  22194. }
  22195. if ( images[ data.image ] === undefined ) {
  22196. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  22197. }
  22198. var texture = new Texture( images[ data.image ] );
  22199. texture.needsUpdate = true;
  22200. texture.uuid = data.uuid;
  22201. if ( data.name !== undefined ) texture.name = data.name;
  22202. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  22203. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  22204. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  22205. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  22206. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  22207. if ( data.wrap !== undefined ) {
  22208. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  22209. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  22210. }
  22211. if ( data.format !== undefined ) texture.format = data.format;
  22212. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  22213. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  22214. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  22215. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  22216. textures[ data.uuid ] = texture;
  22217. }
  22218. }
  22219. return textures;
  22220. },
  22221. parseObject: function ( data, geometries, materials ) {
  22222. var object;
  22223. function getGeometry( name ) {
  22224. if ( geometries[ name ] === undefined ) {
  22225. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  22226. }
  22227. return geometries[ name ];
  22228. }
  22229. function getMaterial( name ) {
  22230. if ( name === undefined ) return undefined;
  22231. if ( Array.isArray( name ) ) {
  22232. var array = [];
  22233. for ( var i = 0, l = name.length; i < l; i ++ ) {
  22234. var uuid = name[ i ];
  22235. if ( materials[ uuid ] === undefined ) {
  22236. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  22237. }
  22238. array.push( materials[ uuid ] );
  22239. }
  22240. return array;
  22241. }
  22242. if ( materials[ name ] === undefined ) {
  22243. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  22244. }
  22245. return materials[ name ];
  22246. }
  22247. switch ( data.type ) {
  22248. case 'Scene':
  22249. object = new Scene();
  22250. if ( data.background !== undefined ) {
  22251. if ( Number.isInteger( data.background ) ) {
  22252. object.background = new Color( data.background );
  22253. }
  22254. }
  22255. if ( data.fog !== undefined ) {
  22256. if ( data.fog.type === 'Fog' ) {
  22257. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  22258. } else if ( data.fog.type === 'FogExp2' ) {
  22259. object.fog = new FogExp2( data.fog.color, data.fog.density );
  22260. }
  22261. }
  22262. break;
  22263. case 'PerspectiveCamera':
  22264. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  22265. if ( data.focus !== undefined ) object.focus = data.focus;
  22266. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  22267. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  22268. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  22269. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  22270. break;
  22271. case 'OrthographicCamera':
  22272. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  22273. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  22274. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  22275. break;
  22276. case 'AmbientLight':
  22277. object = new AmbientLight( data.color, data.intensity );
  22278. break;
  22279. case 'DirectionalLight':
  22280. object = new DirectionalLight( data.color, data.intensity );
  22281. break;
  22282. case 'PointLight':
  22283. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  22284. break;
  22285. case 'RectAreaLight':
  22286. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  22287. break;
  22288. case 'SpotLight':
  22289. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  22290. break;
  22291. case 'HemisphereLight':
  22292. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  22293. break;
  22294. case 'SkinnedMesh':
  22295. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  22296. case 'Mesh':
  22297. var geometry = getGeometry( data.geometry );
  22298. var material = getMaterial( data.material );
  22299. if ( geometry.bones && geometry.bones.length > 0 ) {
  22300. object = new SkinnedMesh( geometry, material );
  22301. } else {
  22302. object = new Mesh( geometry, material );
  22303. }
  22304. break;
  22305. case 'LOD':
  22306. object = new LOD();
  22307. break;
  22308. case 'Line':
  22309. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  22310. break;
  22311. case 'LineLoop':
  22312. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  22313. break;
  22314. case 'LineSegments':
  22315. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  22316. break;
  22317. case 'PointCloud':
  22318. case 'Points':
  22319. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  22320. break;
  22321. case 'Sprite':
  22322. object = new Sprite( getMaterial( data.material ) );
  22323. break;
  22324. case 'Group':
  22325. object = new Group();
  22326. break;
  22327. default:
  22328. object = new Object3D();
  22329. }
  22330. object.uuid = data.uuid;
  22331. if ( data.name !== undefined ) object.name = data.name;
  22332. if ( data.matrix !== undefined ) {
  22333. object.matrix.fromArray( data.matrix );
  22334. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  22335. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  22336. } else {
  22337. if ( data.position !== undefined ) object.position.fromArray( data.position );
  22338. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  22339. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  22340. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  22341. }
  22342. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  22343. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  22344. if ( data.shadow ) {
  22345. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  22346. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  22347. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  22348. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  22349. }
  22350. if ( data.visible !== undefined ) object.visible = data.visible;
  22351. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  22352. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  22353. if ( data.userData !== undefined ) object.userData = data.userData;
  22354. if ( data.children !== undefined ) {
  22355. var children = data.children;
  22356. for ( var i = 0; i < children.length; i ++ ) {
  22357. object.add( this.parseObject( children[ i ], geometries, materials ) );
  22358. }
  22359. }
  22360. if ( data.type === 'LOD' ) {
  22361. var levels = data.levels;
  22362. for ( var l = 0; l < levels.length; l ++ ) {
  22363. var level = levels[ l ];
  22364. var child = object.getObjectByProperty( 'uuid', level.object );
  22365. if ( child !== undefined ) {
  22366. object.addLevel( child, level.distance );
  22367. }
  22368. }
  22369. }
  22370. return object;
  22371. }
  22372. } );
  22373. var TEXTURE_MAPPING = {
  22374. UVMapping: UVMapping,
  22375. CubeReflectionMapping: CubeReflectionMapping,
  22376. CubeRefractionMapping: CubeRefractionMapping,
  22377. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  22378. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  22379. SphericalReflectionMapping: SphericalReflectionMapping,
  22380. CubeUVReflectionMapping: CubeUVReflectionMapping,
  22381. CubeUVRefractionMapping: CubeUVRefractionMapping
  22382. };
  22383. var TEXTURE_WRAPPING = {
  22384. RepeatWrapping: RepeatWrapping,
  22385. ClampToEdgeWrapping: ClampToEdgeWrapping,
  22386. MirroredRepeatWrapping: MirroredRepeatWrapping
  22387. };
  22388. var TEXTURE_FILTER = {
  22389. NearestFilter: NearestFilter,
  22390. NearestMipMapNearestFilter: NearestMipMapNearestFilter,
  22391. NearestMipMapLinearFilter: NearestMipMapLinearFilter,
  22392. LinearFilter: LinearFilter,
  22393. LinearMipMapNearestFilter: LinearMipMapNearestFilter,
  22394. LinearMipMapLinearFilter: LinearMipMapLinearFilter
  22395. };
  22396. /**
  22397. * @author thespite / http://clicktorelease.com/
  22398. */
  22399. function ImageBitmapLoader( manager ) {
  22400. if ( typeof createImageBitmap === 'undefined' ) {
  22401. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  22402. }
  22403. if ( typeof fetch === 'undefined' ) {
  22404. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  22405. }
  22406. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  22407. this.options = undefined;
  22408. }
  22409. ImageBitmapLoader.prototype = {
  22410. constructor: ImageBitmapLoader,
  22411. setOptions: function setOptions( options ) {
  22412. this.options = options;
  22413. return this;
  22414. },
  22415. load: function load( url, onLoad, onProgress, onError ) {
  22416. if ( url === undefined ) url = '';
  22417. if ( this.path !== undefined ) url = this.path + url;
  22418. var scope = this;
  22419. var cached = Cache.get( url );
  22420. if ( cached !== undefined ) {
  22421. scope.manager.itemStart( url );
  22422. setTimeout( function () {
  22423. if ( onLoad ) onLoad( cached );
  22424. scope.manager.itemEnd( url );
  22425. }, 0 );
  22426. return cached;
  22427. }
  22428. fetch( url ).then( function ( res ) {
  22429. return res.blob();
  22430. } ).then( function ( blob ) {
  22431. return createImageBitmap( blob, scope.options );
  22432. } ).then( function ( imageBitmap ) {
  22433. Cache.add( url, imageBitmap );
  22434. if ( onLoad ) onLoad( imageBitmap );
  22435. scope.manager.itemEnd( url );
  22436. } ).catch( function ( e ) {
  22437. if ( onError ) onError( e );
  22438. scope.manager.itemEnd( url );
  22439. scope.manager.itemError( url );
  22440. } );
  22441. },
  22442. setCrossOrigin: function ( /* value */ ) {
  22443. return this;
  22444. },
  22445. setPath: function ( value ) {
  22446. this.path = value;
  22447. return this;
  22448. }
  22449. };
  22450. /**
  22451. * @author zz85 / http://www.lab4games.net/zz85/blog
  22452. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  22453. **/
  22454. function ShapePath() {
  22455. this.type = 'ShapePath';
  22456. this.color = new Color();
  22457. this.subPaths = [];
  22458. this.currentPath = null;
  22459. }
  22460. Object.assign( ShapePath.prototype, {
  22461. moveTo: function ( x, y ) {
  22462. this.currentPath = new Path();
  22463. this.subPaths.push( this.currentPath );
  22464. this.currentPath.moveTo( x, y );
  22465. },
  22466. lineTo: function ( x, y ) {
  22467. this.currentPath.lineTo( x, y );
  22468. },
  22469. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  22470. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  22471. },
  22472. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  22473. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  22474. },
  22475. splineThru: function ( pts ) {
  22476. this.currentPath.splineThru( pts );
  22477. },
  22478. toShapes: function ( isCCW, noHoles ) {
  22479. function toShapesNoHoles( inSubpaths ) {
  22480. var shapes = [];
  22481. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  22482. var tmpPath = inSubpaths[ i ];
  22483. var tmpShape = new Shape();
  22484. tmpShape.curves = tmpPath.curves;
  22485. shapes.push( tmpShape );
  22486. }
  22487. return shapes;
  22488. }
  22489. function isPointInsidePolygon( inPt, inPolygon ) {
  22490. var polyLen = inPolygon.length;
  22491. // inPt on polygon contour => immediate success or
  22492. // toggling of inside/outside at every single! intersection point of an edge
  22493. // with the horizontal line through inPt, left of inPt
  22494. // not counting lowerY endpoints of edges and whole edges on that line
  22495. var inside = false;
  22496. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  22497. var edgeLowPt = inPolygon[ p ];
  22498. var edgeHighPt = inPolygon[ q ];
  22499. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  22500. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  22501. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  22502. // not parallel
  22503. if ( edgeDy < 0 ) {
  22504. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  22505. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  22506. }
  22507. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  22508. if ( inPt.y === edgeLowPt.y ) {
  22509. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  22510. // continue; // no intersection or edgeLowPt => doesn't count !!!
  22511. } else {
  22512. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  22513. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  22514. if ( perpEdge < 0 ) continue;
  22515. inside = ! inside; // true intersection left of inPt
  22516. }
  22517. } else {
  22518. // parallel or collinear
  22519. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  22520. // edge lies on the same horizontal line as inPt
  22521. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  22522. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  22523. // continue;
  22524. }
  22525. }
  22526. return inside;
  22527. }
  22528. var isClockWise = ShapeUtils.isClockWise;
  22529. var subPaths = this.subPaths;
  22530. if ( subPaths.length === 0 ) return [];
  22531. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  22532. var solid, tmpPath, tmpShape, shapes = [];
  22533. if ( subPaths.length === 1 ) {
  22534. tmpPath = subPaths[ 0 ];
  22535. tmpShape = new Shape();
  22536. tmpShape.curves = tmpPath.curves;
  22537. shapes.push( tmpShape );
  22538. return shapes;
  22539. }
  22540. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  22541. holesFirst = isCCW ? ! holesFirst : holesFirst;
  22542. // console.log("Holes first", holesFirst);
  22543. var betterShapeHoles = [];
  22544. var newShapes = [];
  22545. var newShapeHoles = [];
  22546. var mainIdx = 0;
  22547. var tmpPoints;
  22548. newShapes[ mainIdx ] = undefined;
  22549. newShapeHoles[ mainIdx ] = [];
  22550. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  22551. tmpPath = subPaths[ i ];
  22552. tmpPoints = tmpPath.getPoints();
  22553. solid = isClockWise( tmpPoints );
  22554. solid = isCCW ? ! solid : solid;
  22555. if ( solid ) {
  22556. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  22557. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  22558. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  22559. if ( holesFirst ) mainIdx ++;
  22560. newShapeHoles[ mainIdx ] = [];
  22561. //console.log('cw', i);
  22562. } else {
  22563. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  22564. //console.log('ccw', i);
  22565. }
  22566. }
  22567. // only Holes? -> probably all Shapes with wrong orientation
  22568. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  22569. if ( newShapes.length > 1 ) {
  22570. var ambiguous = false;
  22571. var toChange = [];
  22572. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  22573. betterShapeHoles[ sIdx ] = [];
  22574. }
  22575. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  22576. var sho = newShapeHoles[ sIdx ];
  22577. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  22578. var ho = sho[ hIdx ];
  22579. var hole_unassigned = true;
  22580. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  22581. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  22582. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  22583. if ( hole_unassigned ) {
  22584. hole_unassigned = false;
  22585. betterShapeHoles[ s2Idx ].push( ho );
  22586. } else {
  22587. ambiguous = true;
  22588. }
  22589. }
  22590. }
  22591. if ( hole_unassigned ) {
  22592. betterShapeHoles[ sIdx ].push( ho );
  22593. }
  22594. }
  22595. }
  22596. // console.log("ambiguous: ", ambiguous);
  22597. if ( toChange.length > 0 ) {
  22598. // console.log("to change: ", toChange);
  22599. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  22600. }
  22601. }
  22602. var tmpHoles;
  22603. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  22604. tmpShape = newShapes[ i ].s;
  22605. shapes.push( tmpShape );
  22606. tmpHoles = newShapeHoles[ i ];
  22607. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  22608. tmpShape.holes.push( tmpHoles[ j ].h );
  22609. }
  22610. }
  22611. //console.log("shape", shapes);
  22612. return shapes;
  22613. }
  22614. } );
  22615. /**
  22616. * @author zz85 / http://www.lab4games.net/zz85/blog
  22617. * @author mrdoob / http://mrdoob.com/
  22618. */
  22619. function Font( data ) {
  22620. this.type = 'Font';
  22621. this.data = data;
  22622. }
  22623. Object.assign( Font.prototype, {
  22624. isFont: true,
  22625. generateShapes: function ( text, size, divisions ) {
  22626. if ( size === undefined ) size = 100;
  22627. if ( divisions === undefined ) divisions = 4;
  22628. var shapes = [];
  22629. var paths = createPaths( text, size, divisions, this.data );
  22630. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  22631. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  22632. }
  22633. return shapes;
  22634. }
  22635. } );
  22636. function createPaths( text, size, divisions, data ) {
  22637. var chars = String( text ).split( '' );
  22638. var scale = size / data.resolution;
  22639. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  22640. var paths = [];
  22641. var offsetX = 0, offsetY = 0;
  22642. for ( var i = 0; i < chars.length; i ++ ) {
  22643. var char = chars[ i ];
  22644. if ( char === '\n' ) {
  22645. offsetX = 0;
  22646. offsetY -= line_height;
  22647. } else {
  22648. var ret = createPath( char, divisions, scale, offsetX, offsetY, data );
  22649. offsetX += ret.offsetX;
  22650. paths.push( ret.path );
  22651. }
  22652. }
  22653. return paths;
  22654. }
  22655. function createPath( char, divisions, scale, offsetX, offsetY, data ) {
  22656. var glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  22657. if ( ! glyph ) return;
  22658. var path = new ShapePath();
  22659. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  22660. if ( glyph.o ) {
  22661. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  22662. for ( var i = 0, l = outline.length; i < l; ) {
  22663. var action = outline[ i ++ ];
  22664. switch ( action ) {
  22665. case 'm': // moveTo
  22666. x = outline[ i ++ ] * scale + offsetX;
  22667. y = outline[ i ++ ] * scale + offsetY;
  22668. path.moveTo( x, y );
  22669. break;
  22670. case 'l': // lineTo
  22671. x = outline[ i ++ ] * scale + offsetX;
  22672. y = outline[ i ++ ] * scale + offsetY;
  22673. path.lineTo( x, y );
  22674. break;
  22675. case 'q': // quadraticCurveTo
  22676. cpx = outline[ i ++ ] * scale + offsetX;
  22677. cpy = outline[ i ++ ] * scale + offsetY;
  22678. cpx1 = outline[ i ++ ] * scale + offsetX;
  22679. cpy1 = outline[ i ++ ] * scale + offsetY;
  22680. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  22681. break;
  22682. case 'b': // bezierCurveTo
  22683. cpx = outline[ i ++ ] * scale + offsetX;
  22684. cpy = outline[ i ++ ] * scale + offsetY;
  22685. cpx1 = outline[ i ++ ] * scale + offsetX;
  22686. cpy1 = outline[ i ++ ] * scale + offsetY;
  22687. cpx2 = outline[ i ++ ] * scale + offsetX;
  22688. cpy2 = outline[ i ++ ] * scale + offsetY;
  22689. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  22690. break;
  22691. }
  22692. }
  22693. }
  22694. return { offsetX: glyph.ha * scale, path: path };
  22695. }
  22696. /**
  22697. * @author mrdoob / http://mrdoob.com/
  22698. */
  22699. function FontLoader( manager ) {
  22700. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22701. }
  22702. Object.assign( FontLoader.prototype, {
  22703. load: function ( url, onLoad, onProgress, onError ) {
  22704. var scope = this;
  22705. var loader = new FileLoader( this.manager );
  22706. loader.setPath( this.path );
  22707. loader.load( url, function ( text ) {
  22708. var json;
  22709. try {
  22710. json = JSON.parse( text );
  22711. } catch ( e ) {
  22712. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  22713. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  22714. }
  22715. var font = scope.parse( json );
  22716. if ( onLoad ) onLoad( font );
  22717. }, onProgress, onError );
  22718. },
  22719. parse: function ( json ) {
  22720. return new Font( json );
  22721. },
  22722. setPath: function ( value ) {
  22723. this.path = value;
  22724. return this;
  22725. }
  22726. } );
  22727. /**
  22728. * @author mrdoob / http://mrdoob.com/
  22729. */
  22730. var context;
  22731. var AudioContext = {
  22732. getContext: function () {
  22733. if ( context === undefined ) {
  22734. context = new ( window.AudioContext || window.webkitAudioContext )();
  22735. }
  22736. return context;
  22737. },
  22738. setContext: function ( value ) {
  22739. context = value;
  22740. }
  22741. };
  22742. /**
  22743. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  22744. */
  22745. function AudioLoader( manager ) {
  22746. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22747. }
  22748. Object.assign( AudioLoader.prototype, {
  22749. load: function ( url, onLoad, onProgress, onError ) {
  22750. var loader = new FileLoader( this.manager );
  22751. loader.setResponseType( 'arraybuffer' );
  22752. loader.load( url, function ( buffer ) {
  22753. var context = AudioContext.getContext();
  22754. context.decodeAudioData( buffer, function ( audioBuffer ) {
  22755. onLoad( audioBuffer );
  22756. } );
  22757. }, onProgress, onError );
  22758. }
  22759. } );
  22760. /**
  22761. * @author mrdoob / http://mrdoob.com/
  22762. */
  22763. function StereoCamera() {
  22764. this.type = 'StereoCamera';
  22765. this.aspect = 1;
  22766. this.eyeSep = 0.064;
  22767. this.cameraL = new PerspectiveCamera();
  22768. this.cameraL.layers.enable( 1 );
  22769. this.cameraL.matrixAutoUpdate = false;
  22770. this.cameraR = new PerspectiveCamera();
  22771. this.cameraR.layers.enable( 2 );
  22772. this.cameraR.matrixAutoUpdate = false;
  22773. }
  22774. Object.assign( StereoCamera.prototype, {
  22775. update: ( function () {
  22776. var instance, focus, fov, aspect, near, far, zoom, eyeSep;
  22777. var eyeRight = new Matrix4();
  22778. var eyeLeft = new Matrix4();
  22779. return function update( camera ) {
  22780. var needsUpdate = instance !== this || focus !== camera.focus || fov !== camera.fov ||
  22781. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  22782. far !== camera.far || zoom !== camera.zoom || eyeSep !== this.eyeSep;
  22783. if ( needsUpdate ) {
  22784. instance = this;
  22785. focus = camera.focus;
  22786. fov = camera.fov;
  22787. aspect = camera.aspect * this.aspect;
  22788. near = camera.near;
  22789. far = camera.far;
  22790. zoom = camera.zoom;
  22791. // Off-axis stereoscopic effect based on
  22792. // http://paulbourke.net/stereographics/stereorender/
  22793. var projectionMatrix = camera.projectionMatrix.clone();
  22794. eyeSep = this.eyeSep / 2;
  22795. var eyeSepOnProjection = eyeSep * near / focus;
  22796. var ymax = ( near * Math.tan( _Math.DEG2RAD * fov * 0.5 ) ) / zoom;
  22797. var xmin, xmax;
  22798. // translate xOffset
  22799. eyeLeft.elements[ 12 ] = - eyeSep;
  22800. eyeRight.elements[ 12 ] = eyeSep;
  22801. // for left eye
  22802. xmin = - ymax * aspect + eyeSepOnProjection;
  22803. xmax = ymax * aspect + eyeSepOnProjection;
  22804. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  22805. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  22806. this.cameraL.projectionMatrix.copy( projectionMatrix );
  22807. // for right eye
  22808. xmin = - ymax * aspect - eyeSepOnProjection;
  22809. xmax = ymax * aspect - eyeSepOnProjection;
  22810. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  22811. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  22812. this.cameraR.projectionMatrix.copy( projectionMatrix );
  22813. }
  22814. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  22815. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  22816. };
  22817. } )()
  22818. } );
  22819. /**
  22820. * Camera for rendering cube maps
  22821. * - renders scene into axis-aligned cube
  22822. *
  22823. * @author alteredq / http://alteredqualia.com/
  22824. */
  22825. function CubeCamera( near, far, cubeResolution ) {
  22826. Object3D.call( this );
  22827. this.type = 'CubeCamera';
  22828. var fov = 90, aspect = 1;
  22829. var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  22830. cameraPX.up.set( 0, - 1, 0 );
  22831. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  22832. this.add( cameraPX );
  22833. var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  22834. cameraNX.up.set( 0, - 1, 0 );
  22835. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  22836. this.add( cameraNX );
  22837. var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  22838. cameraPY.up.set( 0, 0, 1 );
  22839. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  22840. this.add( cameraPY );
  22841. var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  22842. cameraNY.up.set( 0, 0, - 1 );
  22843. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  22844. this.add( cameraNY );
  22845. var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  22846. cameraPZ.up.set( 0, - 1, 0 );
  22847. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  22848. this.add( cameraPZ );
  22849. var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  22850. cameraNZ.up.set( 0, - 1, 0 );
  22851. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  22852. this.add( cameraNZ );
  22853. var options = { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
  22854. this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  22855. this.renderTarget.texture.name = "CubeCamera";
  22856. this.update = function ( renderer, scene ) {
  22857. if ( this.parent === null ) this.updateMatrixWorld();
  22858. var renderTarget = this.renderTarget;
  22859. var generateMipmaps = renderTarget.texture.generateMipmaps;
  22860. renderTarget.texture.generateMipmaps = false;
  22861. renderTarget.activeCubeFace = 0;
  22862. renderer.render( scene, cameraPX, renderTarget );
  22863. renderTarget.activeCubeFace = 1;
  22864. renderer.render( scene, cameraNX, renderTarget );
  22865. renderTarget.activeCubeFace = 2;
  22866. renderer.render( scene, cameraPY, renderTarget );
  22867. renderTarget.activeCubeFace = 3;
  22868. renderer.render( scene, cameraNY, renderTarget );
  22869. renderTarget.activeCubeFace = 4;
  22870. renderer.render( scene, cameraPZ, renderTarget );
  22871. renderTarget.texture.generateMipmaps = generateMipmaps;
  22872. renderTarget.activeCubeFace = 5;
  22873. renderer.render( scene, cameraNZ, renderTarget );
  22874. renderer.setRenderTarget( null );
  22875. };
  22876. this.clear = function ( renderer, color, depth, stencil ) {
  22877. var renderTarget = this.renderTarget;
  22878. for ( var i = 0; i < 6; i ++ ) {
  22879. renderTarget.activeCubeFace = i;
  22880. renderer.setRenderTarget( renderTarget );
  22881. renderer.clear( color, depth, stencil );
  22882. }
  22883. renderer.setRenderTarget( null );
  22884. };
  22885. }
  22886. CubeCamera.prototype = Object.create( Object3D.prototype );
  22887. CubeCamera.prototype.constructor = CubeCamera;
  22888. /**
  22889. * @author mrdoob / http://mrdoob.com/
  22890. */
  22891. function AudioListener() {
  22892. Object3D.call( this );
  22893. this.type = 'AudioListener';
  22894. this.context = AudioContext.getContext();
  22895. this.gain = this.context.createGain();
  22896. this.gain.connect( this.context.destination );
  22897. this.filter = null;
  22898. }
  22899. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  22900. constructor: AudioListener,
  22901. getInput: function () {
  22902. return this.gain;
  22903. },
  22904. removeFilter: function ( ) {
  22905. if ( this.filter !== null ) {
  22906. this.gain.disconnect( this.filter );
  22907. this.filter.disconnect( this.context.destination );
  22908. this.gain.connect( this.context.destination );
  22909. this.filter = null;
  22910. }
  22911. },
  22912. getFilter: function () {
  22913. return this.filter;
  22914. },
  22915. setFilter: function ( value ) {
  22916. if ( this.filter !== null ) {
  22917. this.gain.disconnect( this.filter );
  22918. this.filter.disconnect( this.context.destination );
  22919. } else {
  22920. this.gain.disconnect( this.context.destination );
  22921. }
  22922. this.filter = value;
  22923. this.gain.connect( this.filter );
  22924. this.filter.connect( this.context.destination );
  22925. },
  22926. getMasterVolume: function () {
  22927. return this.gain.gain.value;
  22928. },
  22929. setMasterVolume: function ( value ) {
  22930. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  22931. },
  22932. updateMatrixWorld: ( function () {
  22933. var position = new Vector3();
  22934. var quaternion = new Quaternion();
  22935. var scale = new Vector3();
  22936. var orientation = new Vector3();
  22937. return function updateMatrixWorld( force ) {
  22938. Object3D.prototype.updateMatrixWorld.call( this, force );
  22939. var listener = this.context.listener;
  22940. var up = this.up;
  22941. this.matrixWorld.decompose( position, quaternion, scale );
  22942. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  22943. if ( listener.positionX ) {
  22944. listener.positionX.setValueAtTime( position.x, this.context.currentTime );
  22945. listener.positionY.setValueAtTime( position.y, this.context.currentTime );
  22946. listener.positionZ.setValueAtTime( position.z, this.context.currentTime );
  22947. listener.forwardX.setValueAtTime( orientation.x, this.context.currentTime );
  22948. listener.forwardY.setValueAtTime( orientation.y, this.context.currentTime );
  22949. listener.forwardZ.setValueAtTime( orientation.z, this.context.currentTime );
  22950. listener.upX.setValueAtTime( up.x, this.context.currentTime );
  22951. listener.upY.setValueAtTime( up.y, this.context.currentTime );
  22952. listener.upZ.setValueAtTime( up.z, this.context.currentTime );
  22953. } else {
  22954. listener.setPosition( position.x, position.y, position.z );
  22955. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  22956. }
  22957. };
  22958. } )()
  22959. } );
  22960. /**
  22961. * @author mrdoob / http://mrdoob.com/
  22962. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  22963. */
  22964. function Audio( listener ) {
  22965. Object3D.call( this );
  22966. this.type = 'Audio';
  22967. this.context = listener.context;
  22968. this.gain = this.context.createGain();
  22969. this.gain.connect( listener.getInput() );
  22970. this.autoplay = false;
  22971. this.buffer = null;
  22972. this.loop = false;
  22973. this.startTime = 0;
  22974. this.offset = 0;
  22975. this.playbackRate = 1;
  22976. this.isPlaying = false;
  22977. this.hasPlaybackControl = true;
  22978. this.sourceType = 'empty';
  22979. this.filters = [];
  22980. }
  22981. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  22982. constructor: Audio,
  22983. getOutput: function () {
  22984. return this.gain;
  22985. },
  22986. setNodeSource: function ( audioNode ) {
  22987. this.hasPlaybackControl = false;
  22988. this.sourceType = 'audioNode';
  22989. this.source = audioNode;
  22990. this.connect();
  22991. return this;
  22992. },
  22993. setBuffer: function ( audioBuffer ) {
  22994. this.buffer = audioBuffer;
  22995. this.sourceType = 'buffer';
  22996. if ( this.autoplay ) this.play();
  22997. return this;
  22998. },
  22999. play: function () {
  23000. if ( this.isPlaying === true ) {
  23001. console.warn( 'THREE.Audio: Audio is already playing.' );
  23002. return;
  23003. }
  23004. if ( this.hasPlaybackControl === false ) {
  23005. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  23006. return;
  23007. }
  23008. var source = this.context.createBufferSource();
  23009. source.buffer = this.buffer;
  23010. source.loop = this.loop;
  23011. source.onended = this.onEnded.bind( this );
  23012. source.playbackRate.setValueAtTime( this.playbackRate, this.startTime );
  23013. this.startTime = this.context.currentTime;
  23014. source.start( this.startTime, this.offset );
  23015. this.isPlaying = true;
  23016. this.source = source;
  23017. return this.connect();
  23018. },
  23019. pause: function () {
  23020. if ( this.hasPlaybackControl === false ) {
  23021. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  23022. return;
  23023. }
  23024. if ( this.isPlaying === true ) {
  23025. this.source.stop();
  23026. this.offset += ( this.context.currentTime - this.startTime ) * this.playbackRate;
  23027. this.isPlaying = false;
  23028. }
  23029. return this;
  23030. },
  23031. stop: function () {
  23032. if ( this.hasPlaybackControl === false ) {
  23033. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  23034. return;
  23035. }
  23036. this.source.stop();
  23037. this.offset = 0;
  23038. this.isPlaying = false;
  23039. return this;
  23040. },
  23041. connect: function () {
  23042. if ( this.filters.length > 0 ) {
  23043. this.source.connect( this.filters[ 0 ] );
  23044. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  23045. this.filters[ i - 1 ].connect( this.filters[ i ] );
  23046. }
  23047. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  23048. } else {
  23049. this.source.connect( this.getOutput() );
  23050. }
  23051. return this;
  23052. },
  23053. disconnect: function () {
  23054. if ( this.filters.length > 0 ) {
  23055. this.source.disconnect( this.filters[ 0 ] );
  23056. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  23057. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  23058. }
  23059. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  23060. } else {
  23061. this.source.disconnect( this.getOutput() );
  23062. }
  23063. return this;
  23064. },
  23065. getFilters: function () {
  23066. return this.filters;
  23067. },
  23068. setFilters: function ( value ) {
  23069. if ( ! value ) value = [];
  23070. if ( this.isPlaying === true ) {
  23071. this.disconnect();
  23072. this.filters = value;
  23073. this.connect();
  23074. } else {
  23075. this.filters = value;
  23076. }
  23077. return this;
  23078. },
  23079. getFilter: function () {
  23080. return this.getFilters()[ 0 ];
  23081. },
  23082. setFilter: function ( filter ) {
  23083. return this.setFilters( filter ? [ filter ] : [] );
  23084. },
  23085. setPlaybackRate: function ( value ) {
  23086. if ( this.hasPlaybackControl === false ) {
  23087. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  23088. return;
  23089. }
  23090. this.playbackRate = value;
  23091. if ( this.isPlaying === true ) {
  23092. this.source.playbackRate.setValueAtTime( this.playbackRate, this.context.currentTime );
  23093. }
  23094. return this;
  23095. },
  23096. getPlaybackRate: function () {
  23097. return this.playbackRate;
  23098. },
  23099. onEnded: function () {
  23100. this.isPlaying = false;
  23101. },
  23102. getLoop: function () {
  23103. if ( this.hasPlaybackControl === false ) {
  23104. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  23105. return false;
  23106. }
  23107. return this.loop;
  23108. },
  23109. setLoop: function ( value ) {
  23110. if ( this.hasPlaybackControl === false ) {
  23111. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  23112. return;
  23113. }
  23114. this.loop = value;
  23115. if ( this.isPlaying === true ) {
  23116. this.source.loop = this.loop;
  23117. }
  23118. return this;
  23119. },
  23120. getVolume: function () {
  23121. return this.gain.gain.value;
  23122. },
  23123. setVolume: function ( value ) {
  23124. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  23125. return this;
  23126. }
  23127. } );
  23128. /**
  23129. * @author mrdoob / http://mrdoob.com/
  23130. */
  23131. function PositionalAudio( listener ) {
  23132. Audio.call( this, listener );
  23133. this.panner = this.context.createPanner();
  23134. this.panner.connect( this.gain );
  23135. }
  23136. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  23137. constructor: PositionalAudio,
  23138. getOutput: function () {
  23139. return this.panner;
  23140. },
  23141. getRefDistance: function () {
  23142. return this.panner.refDistance;
  23143. },
  23144. setRefDistance: function ( value ) {
  23145. this.panner.refDistance = value;
  23146. },
  23147. getRolloffFactor: function () {
  23148. return this.panner.rolloffFactor;
  23149. },
  23150. setRolloffFactor: function ( value ) {
  23151. this.panner.rolloffFactor = value;
  23152. },
  23153. getDistanceModel: function () {
  23154. return this.panner.distanceModel;
  23155. },
  23156. setDistanceModel: function ( value ) {
  23157. this.panner.distanceModel = value;
  23158. },
  23159. getMaxDistance: function () {
  23160. return this.panner.maxDistance;
  23161. },
  23162. setMaxDistance: function ( value ) {
  23163. this.panner.maxDistance = value;
  23164. },
  23165. updateMatrixWorld: ( function () {
  23166. var position = new Vector3();
  23167. return function updateMatrixWorld( force ) {
  23168. Object3D.prototype.updateMatrixWorld.call( this, force );
  23169. position.setFromMatrixPosition( this.matrixWorld );
  23170. this.panner.setPosition( position.x, position.y, position.z );
  23171. };
  23172. } )()
  23173. } );
  23174. /**
  23175. * @author mrdoob / http://mrdoob.com/
  23176. */
  23177. function AudioAnalyser( audio, fftSize ) {
  23178. this.analyser = audio.context.createAnalyser();
  23179. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  23180. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  23181. audio.getOutput().connect( this.analyser );
  23182. }
  23183. Object.assign( AudioAnalyser.prototype, {
  23184. getFrequencyData: function () {
  23185. this.analyser.getByteFrequencyData( this.data );
  23186. return this.data;
  23187. },
  23188. getAverageFrequency: function () {
  23189. var value = 0, data = this.getFrequencyData();
  23190. for ( var i = 0; i < data.length; i ++ ) {
  23191. value += data[ i ];
  23192. }
  23193. return value / data.length;
  23194. }
  23195. } );
  23196. /**
  23197. *
  23198. * Buffered scene graph property that allows weighted accumulation.
  23199. *
  23200. *
  23201. * @author Ben Houston / http://clara.io/
  23202. * @author David Sarno / http://lighthaus.us/
  23203. * @author tschw
  23204. */
  23205. function PropertyMixer( binding, typeName, valueSize ) {
  23206. this.binding = binding;
  23207. this.valueSize = valueSize;
  23208. var bufferType = Float64Array,
  23209. mixFunction;
  23210. switch ( typeName ) {
  23211. case 'quaternion':
  23212. mixFunction = this._slerp;
  23213. break;
  23214. case 'string':
  23215. case 'bool':
  23216. bufferType = Array;
  23217. mixFunction = this._select;
  23218. break;
  23219. default:
  23220. mixFunction = this._lerp;
  23221. }
  23222. this.buffer = new bufferType( valueSize * 4 );
  23223. // layout: [ incoming | accu0 | accu1 | orig ]
  23224. //
  23225. // interpolators can use .buffer as their .result
  23226. // the data then goes to 'incoming'
  23227. //
  23228. // 'accu0' and 'accu1' are used frame-interleaved for
  23229. // the cumulative result and are compared to detect
  23230. // changes
  23231. //
  23232. // 'orig' stores the original state of the property
  23233. this._mixBufferRegion = mixFunction;
  23234. this.cumulativeWeight = 0;
  23235. this.useCount = 0;
  23236. this.referenceCount = 0;
  23237. }
  23238. Object.assign( PropertyMixer.prototype, {
  23239. // accumulate data in the 'incoming' region into 'accu<i>'
  23240. accumulate: function ( accuIndex, weight ) {
  23241. // note: happily accumulating nothing when weight = 0, the caller knows
  23242. // the weight and shouldn't have made the call in the first place
  23243. var buffer = this.buffer,
  23244. stride = this.valueSize,
  23245. offset = accuIndex * stride + stride,
  23246. currentWeight = this.cumulativeWeight;
  23247. if ( currentWeight === 0 ) {
  23248. // accuN := incoming * weight
  23249. for ( var i = 0; i !== stride; ++ i ) {
  23250. buffer[ offset + i ] = buffer[ i ];
  23251. }
  23252. currentWeight = weight;
  23253. } else {
  23254. // accuN := accuN + incoming * weight
  23255. currentWeight += weight;
  23256. var mix = weight / currentWeight;
  23257. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  23258. }
  23259. this.cumulativeWeight = currentWeight;
  23260. },
  23261. // apply the state of 'accu<i>' to the binding when accus differ
  23262. apply: function ( accuIndex ) {
  23263. var stride = this.valueSize,
  23264. buffer = this.buffer,
  23265. offset = accuIndex * stride + stride,
  23266. weight = this.cumulativeWeight,
  23267. binding = this.binding;
  23268. this.cumulativeWeight = 0;
  23269. if ( weight < 1 ) {
  23270. // accuN := accuN + original * ( 1 - cumulativeWeight )
  23271. var originalValueOffset = stride * 3;
  23272. this._mixBufferRegion(
  23273. buffer, offset, originalValueOffset, 1 - weight, stride );
  23274. }
  23275. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  23276. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  23277. // value has changed -> update scene graph
  23278. binding.setValue( buffer, offset );
  23279. break;
  23280. }
  23281. }
  23282. },
  23283. // remember the state of the bound property and copy it to both accus
  23284. saveOriginalState: function () {
  23285. var binding = this.binding;
  23286. var buffer = this.buffer,
  23287. stride = this.valueSize,
  23288. originalValueOffset = stride * 3;
  23289. binding.getValue( buffer, originalValueOffset );
  23290. // accu[0..1] := orig -- initially detect changes against the original
  23291. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  23292. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  23293. }
  23294. this.cumulativeWeight = 0;
  23295. },
  23296. // apply the state previously taken via 'saveOriginalState' to the binding
  23297. restoreOriginalState: function () {
  23298. var originalValueOffset = this.valueSize * 3;
  23299. this.binding.setValue( this.buffer, originalValueOffset );
  23300. },
  23301. // mix functions
  23302. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  23303. if ( t >= 0.5 ) {
  23304. for ( var i = 0; i !== stride; ++ i ) {
  23305. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  23306. }
  23307. }
  23308. },
  23309. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  23310. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  23311. },
  23312. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  23313. var s = 1 - t;
  23314. for ( var i = 0; i !== stride; ++ i ) {
  23315. var j = dstOffset + i;
  23316. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  23317. }
  23318. }
  23319. } );
  23320. /**
  23321. *
  23322. * A reference to a real property in the scene graph.
  23323. *
  23324. *
  23325. * @author Ben Houston / http://clara.io/
  23326. * @author David Sarno / http://lighthaus.us/
  23327. * @author tschw
  23328. */
  23329. // Characters [].:/ are reserved for track binding syntax.
  23330. var RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  23331. function Composite( targetGroup, path, optionalParsedPath ) {
  23332. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  23333. this._targetGroup = targetGroup;
  23334. this._bindings = targetGroup.subscribe_( path, parsedPath );
  23335. }
  23336. Object.assign( Composite.prototype, {
  23337. getValue: function ( array, offset ) {
  23338. this.bind(); // bind all binding
  23339. var firstValidIndex = this._targetGroup.nCachedObjects_,
  23340. binding = this._bindings[ firstValidIndex ];
  23341. // and only call .getValue on the first
  23342. if ( binding !== undefined ) binding.getValue( array, offset );
  23343. },
  23344. setValue: function ( array, offset ) {
  23345. var bindings = this._bindings;
  23346. for ( var i = this._targetGroup.nCachedObjects_,
  23347. n = bindings.length; i !== n; ++ i ) {
  23348. bindings[ i ].setValue( array, offset );
  23349. }
  23350. },
  23351. bind: function () {
  23352. var bindings = this._bindings;
  23353. for ( var i = this._targetGroup.nCachedObjects_,
  23354. n = bindings.length; i !== n; ++ i ) {
  23355. bindings[ i ].bind();
  23356. }
  23357. },
  23358. unbind: function () {
  23359. var bindings = this._bindings;
  23360. for ( var i = this._targetGroup.nCachedObjects_,
  23361. n = bindings.length; i !== n; ++ i ) {
  23362. bindings[ i ].unbind();
  23363. }
  23364. }
  23365. } );
  23366. function PropertyBinding( rootNode, path, parsedPath ) {
  23367. this.path = path;
  23368. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  23369. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  23370. this.rootNode = rootNode;
  23371. }
  23372. Object.assign( PropertyBinding, {
  23373. Composite: Composite,
  23374. create: function ( root, path, parsedPath ) {
  23375. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  23376. return new PropertyBinding( root, path, parsedPath );
  23377. } else {
  23378. return new PropertyBinding.Composite( root, path, parsedPath );
  23379. }
  23380. },
  23381. /**
  23382. * Replaces spaces with underscores and removes unsupported characters from
  23383. * node names, to ensure compatibility with parseTrackName().
  23384. *
  23385. * @param {string} name Node name to be sanitized.
  23386. * @return {string}
  23387. */
  23388. sanitizeNodeName: ( function () {
  23389. var reservedRe = new RegExp( '[' + RESERVED_CHARS_RE + ']', 'g' );
  23390. return function sanitizeNodeName( name ) {
  23391. return name.replace( /\s/g, '_' ).replace( reservedRe, '' );
  23392. };
  23393. }() ),
  23394. parseTrackName: function () {
  23395. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  23396. // only latin characters, and the unicode \p{L} is not yet supported. So
  23397. // instead, we exclude reserved characters and match everything else.
  23398. var wordChar = '[^' + RESERVED_CHARS_RE + ']';
  23399. var wordCharOrDot = '[^' + RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  23400. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  23401. // be matched to parse the rest of the track name.
  23402. var directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', wordChar );
  23403. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  23404. var nodeRe = /(WCOD+)?/.source.replace( 'WCOD', wordCharOrDot );
  23405. // Object on target node, and accessor. May not contain reserved
  23406. // characters. Accessor may contain any character except closing bracket.
  23407. var objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', wordChar );
  23408. // Property and accessor. May not contain reserved characters. Accessor may
  23409. // contain any non-bracket characters.
  23410. var propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', wordChar );
  23411. var trackRe = new RegExp( ''
  23412. + '^'
  23413. + directoryRe
  23414. + nodeRe
  23415. + objectRe
  23416. + propertyRe
  23417. + '$'
  23418. );
  23419. var supportedObjectNames = [ 'material', 'materials', 'bones' ];
  23420. return function parseTrackName( trackName ) {
  23421. var matches = trackRe.exec( trackName );
  23422. if ( ! matches ) {
  23423. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  23424. }
  23425. var results = {
  23426. // directoryName: matches[ 1 ], // (tschw) currently unused
  23427. nodeName: matches[ 2 ],
  23428. objectName: matches[ 3 ],
  23429. objectIndex: matches[ 4 ],
  23430. propertyName: matches[ 5 ], // required
  23431. propertyIndex: matches[ 6 ]
  23432. };
  23433. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  23434. if ( lastDot !== undefined && lastDot !== - 1 ) {
  23435. var objectName = results.nodeName.substring( lastDot + 1 );
  23436. // Object names must be checked against a whitelist. Otherwise, there
  23437. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  23438. // 'bar' could be the objectName, or part of a nodeName (which can
  23439. // include '.' characters).
  23440. if ( supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  23441. results.nodeName = results.nodeName.substring( 0, lastDot );
  23442. results.objectName = objectName;
  23443. }
  23444. }
  23445. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  23446. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  23447. }
  23448. return results;
  23449. };
  23450. }(),
  23451. findNode: function ( root, nodeName ) {
  23452. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  23453. return root;
  23454. }
  23455. // search into skeleton bones.
  23456. if ( root.skeleton ) {
  23457. var bone = root.skeleton.getBoneByName( nodeName );
  23458. if ( bone !== undefined ) {
  23459. return bone;
  23460. }
  23461. }
  23462. // search into node subtree.
  23463. if ( root.children ) {
  23464. var searchNodeSubtree = function ( children ) {
  23465. for ( var i = 0; i < children.length; i ++ ) {
  23466. var childNode = children[ i ];
  23467. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  23468. return childNode;
  23469. }
  23470. var result = searchNodeSubtree( childNode.children );
  23471. if ( result ) return result;
  23472. }
  23473. return null;
  23474. };
  23475. var subTreeNode = searchNodeSubtree( root.children );
  23476. if ( subTreeNode ) {
  23477. return subTreeNode;
  23478. }
  23479. }
  23480. return null;
  23481. }
  23482. } );
  23483. Object.assign( PropertyBinding.prototype, { // prototype, continued
  23484. // these are used to "bind" a nonexistent property
  23485. _getValue_unavailable: function () {},
  23486. _setValue_unavailable: function () {},
  23487. BindingType: {
  23488. Direct: 0,
  23489. EntireArray: 1,
  23490. ArrayElement: 2,
  23491. HasFromToArray: 3
  23492. },
  23493. Versioning: {
  23494. None: 0,
  23495. NeedsUpdate: 1,
  23496. MatrixWorldNeedsUpdate: 2
  23497. },
  23498. GetterByBindingType: [
  23499. function getValue_direct( buffer, offset ) {
  23500. buffer[ offset ] = this.node[ this.propertyName ];
  23501. },
  23502. function getValue_array( buffer, offset ) {
  23503. var source = this.resolvedProperty;
  23504. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  23505. buffer[ offset ++ ] = source[ i ];
  23506. }
  23507. },
  23508. function getValue_arrayElement( buffer, offset ) {
  23509. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  23510. },
  23511. function getValue_toArray( buffer, offset ) {
  23512. this.resolvedProperty.toArray( buffer, offset );
  23513. }
  23514. ],
  23515. SetterByBindingTypeAndVersioning: [
  23516. [
  23517. // Direct
  23518. function setValue_direct( buffer, offset ) {
  23519. this.targetObject[ this.propertyName ] = buffer[ offset ];
  23520. },
  23521. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  23522. this.targetObject[ this.propertyName ] = buffer[ offset ];
  23523. this.targetObject.needsUpdate = true;
  23524. },
  23525. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  23526. this.targetObject[ this.propertyName ] = buffer[ offset ];
  23527. this.targetObject.matrixWorldNeedsUpdate = true;
  23528. }
  23529. ], [
  23530. // EntireArray
  23531. function setValue_array( buffer, offset ) {
  23532. var dest = this.resolvedProperty;
  23533. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  23534. dest[ i ] = buffer[ offset ++ ];
  23535. }
  23536. },
  23537. function setValue_array_setNeedsUpdate( buffer, offset ) {
  23538. var dest = this.resolvedProperty;
  23539. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  23540. dest[ i ] = buffer[ offset ++ ];
  23541. }
  23542. this.targetObject.needsUpdate = true;
  23543. },
  23544. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  23545. var dest = this.resolvedProperty;
  23546. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  23547. dest[ i ] = buffer[ offset ++ ];
  23548. }
  23549. this.targetObject.matrixWorldNeedsUpdate = true;
  23550. }
  23551. ], [
  23552. // ArrayElement
  23553. function setValue_arrayElement( buffer, offset ) {
  23554. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  23555. },
  23556. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  23557. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  23558. this.targetObject.needsUpdate = true;
  23559. },
  23560. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  23561. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  23562. this.targetObject.matrixWorldNeedsUpdate = true;
  23563. }
  23564. ], [
  23565. // HasToFromArray
  23566. function setValue_fromArray( buffer, offset ) {
  23567. this.resolvedProperty.fromArray( buffer, offset );
  23568. },
  23569. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  23570. this.resolvedProperty.fromArray( buffer, offset );
  23571. this.targetObject.needsUpdate = true;
  23572. },
  23573. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  23574. this.resolvedProperty.fromArray( buffer, offset );
  23575. this.targetObject.matrixWorldNeedsUpdate = true;
  23576. }
  23577. ]
  23578. ],
  23579. getValue: function getValue_unbound( targetArray, offset ) {
  23580. this.bind();
  23581. this.getValue( targetArray, offset );
  23582. // Note: This class uses a State pattern on a per-method basis:
  23583. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  23584. // prototype version of these methods with one that represents
  23585. // the bound state. When the property is not found, the methods
  23586. // become no-ops.
  23587. },
  23588. setValue: function getValue_unbound( sourceArray, offset ) {
  23589. this.bind();
  23590. this.setValue( sourceArray, offset );
  23591. },
  23592. // create getter / setter pair for a property in the scene graph
  23593. bind: function () {
  23594. var targetObject = this.node,
  23595. parsedPath = this.parsedPath,
  23596. objectName = parsedPath.objectName,
  23597. propertyName = parsedPath.propertyName,
  23598. propertyIndex = parsedPath.propertyIndex;
  23599. if ( ! targetObject ) {
  23600. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  23601. this.node = targetObject;
  23602. }
  23603. // set fail state so we can just 'return' on error
  23604. this.getValue = this._getValue_unavailable;
  23605. this.setValue = this._setValue_unavailable;
  23606. // ensure there is a value node
  23607. if ( ! targetObject ) {
  23608. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  23609. return;
  23610. }
  23611. if ( objectName ) {
  23612. var objectIndex = parsedPath.objectIndex;
  23613. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  23614. switch ( objectName ) {
  23615. case 'materials':
  23616. if ( ! targetObject.material ) {
  23617. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  23618. return;
  23619. }
  23620. if ( ! targetObject.material.materials ) {
  23621. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  23622. return;
  23623. }
  23624. targetObject = targetObject.material.materials;
  23625. break;
  23626. case 'bones':
  23627. if ( ! targetObject.skeleton ) {
  23628. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  23629. return;
  23630. }
  23631. // potential future optimization: skip this if propertyIndex is already an integer
  23632. // and convert the integer string to a true integer.
  23633. targetObject = targetObject.skeleton.bones;
  23634. // support resolving morphTarget names into indices.
  23635. for ( var i = 0; i < targetObject.length; i ++ ) {
  23636. if ( targetObject[ i ].name === objectIndex ) {
  23637. objectIndex = i;
  23638. break;
  23639. }
  23640. }
  23641. break;
  23642. default:
  23643. if ( targetObject[ objectName ] === undefined ) {
  23644. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  23645. return;
  23646. }
  23647. targetObject = targetObject[ objectName ];
  23648. }
  23649. if ( objectIndex !== undefined ) {
  23650. if ( targetObject[ objectIndex ] === undefined ) {
  23651. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  23652. return;
  23653. }
  23654. targetObject = targetObject[ objectIndex ];
  23655. }
  23656. }
  23657. // resolve property
  23658. var nodeProperty = targetObject[ propertyName ];
  23659. if ( nodeProperty === undefined ) {
  23660. var nodeName = parsedPath.nodeName;
  23661. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  23662. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  23663. return;
  23664. }
  23665. // determine versioning scheme
  23666. var versioning = this.Versioning.None;
  23667. if ( targetObject.needsUpdate !== undefined ) { // material
  23668. versioning = this.Versioning.NeedsUpdate;
  23669. this.targetObject = targetObject;
  23670. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  23671. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  23672. this.targetObject = targetObject;
  23673. }
  23674. // determine how the property gets bound
  23675. var bindingType = this.BindingType.Direct;
  23676. if ( propertyIndex !== undefined ) {
  23677. // access a sub element of the property array (only primitives are supported right now)
  23678. if ( propertyName === "morphTargetInfluences" ) {
  23679. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  23680. // support resolving morphTarget names into indices.
  23681. if ( ! targetObject.geometry ) {
  23682. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  23683. return;
  23684. }
  23685. if ( targetObject.geometry.isBufferGeometry ) {
  23686. if ( ! targetObject.geometry.morphAttributes ) {
  23687. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  23688. return;
  23689. }
  23690. for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {
  23691. if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {
  23692. propertyIndex = i;
  23693. break;
  23694. }
  23695. }
  23696. } else {
  23697. if ( ! targetObject.geometry.morphTargets ) {
  23698. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.', this );
  23699. return;
  23700. }
  23701. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  23702. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  23703. propertyIndex = i;
  23704. break;
  23705. }
  23706. }
  23707. }
  23708. }
  23709. bindingType = this.BindingType.ArrayElement;
  23710. this.resolvedProperty = nodeProperty;
  23711. this.propertyIndex = propertyIndex;
  23712. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  23713. // must use copy for Object3D.Euler/Quaternion
  23714. bindingType = this.BindingType.HasFromToArray;
  23715. this.resolvedProperty = nodeProperty;
  23716. } else if ( Array.isArray( nodeProperty ) ) {
  23717. bindingType = this.BindingType.EntireArray;
  23718. this.resolvedProperty = nodeProperty;
  23719. } else {
  23720. this.propertyName = propertyName;
  23721. }
  23722. // select getter / setter
  23723. this.getValue = this.GetterByBindingType[ bindingType ];
  23724. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  23725. },
  23726. unbind: function () {
  23727. this.node = null;
  23728. // back to the prototype version of getValue / setValue
  23729. // note: avoiding to mutate the shape of 'this' via 'delete'
  23730. this.getValue = this._getValue_unbound;
  23731. this.setValue = this._setValue_unbound;
  23732. }
  23733. } );
  23734. //!\ DECLARE ALIAS AFTER assign prototype !
  23735. Object.assign( PropertyBinding.prototype, {
  23736. // initial state of these methods that calls 'bind'
  23737. _getValue_unbound: PropertyBinding.prototype.getValue,
  23738. _setValue_unbound: PropertyBinding.prototype.setValue,
  23739. } );
  23740. /**
  23741. *
  23742. * A group of objects that receives a shared animation state.
  23743. *
  23744. * Usage:
  23745. *
  23746. * - Add objects you would otherwise pass as 'root' to the
  23747. * constructor or the .clipAction method of AnimationMixer.
  23748. *
  23749. * - Instead pass this object as 'root'.
  23750. *
  23751. * - You can also add and remove objects later when the mixer
  23752. * is running.
  23753. *
  23754. * Note:
  23755. *
  23756. * Objects of this class appear as one object to the mixer,
  23757. * so cache control of the individual objects must be done
  23758. * on the group.
  23759. *
  23760. * Limitation:
  23761. *
  23762. * - The animated properties must be compatible among the
  23763. * all objects in the group.
  23764. *
  23765. * - A single property can either be controlled through a
  23766. * target group or directly, but not both.
  23767. *
  23768. * @author tschw
  23769. */
  23770. function AnimationObjectGroup() {
  23771. this.uuid = _Math.generateUUID();
  23772. // cached objects followed by the active ones
  23773. this._objects = Array.prototype.slice.call( arguments );
  23774. this.nCachedObjects_ = 0; // threshold
  23775. // note: read by PropertyBinding.Composite
  23776. var indices = {};
  23777. this._indicesByUUID = indices; // for bookkeeping
  23778. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  23779. indices[ arguments[ i ].uuid ] = i;
  23780. }
  23781. this._paths = []; // inside: string
  23782. this._parsedPaths = []; // inside: { we don't care, here }
  23783. this._bindings = []; // inside: Array< PropertyBinding >
  23784. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  23785. var scope = this;
  23786. this.stats = {
  23787. objects: {
  23788. get total() {
  23789. return scope._objects.length;
  23790. },
  23791. get inUse() {
  23792. return this.total - scope.nCachedObjects_;
  23793. }
  23794. },
  23795. get bindingsPerObject() {
  23796. return scope._bindings.length;
  23797. }
  23798. };
  23799. }
  23800. Object.assign( AnimationObjectGroup.prototype, {
  23801. isAnimationObjectGroup: true,
  23802. add: function () {
  23803. var objects = this._objects,
  23804. nObjects = objects.length,
  23805. nCachedObjects = this.nCachedObjects_,
  23806. indicesByUUID = this._indicesByUUID,
  23807. paths = this._paths,
  23808. parsedPaths = this._parsedPaths,
  23809. bindings = this._bindings,
  23810. nBindings = bindings.length,
  23811. knownObject = undefined;
  23812. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  23813. var object = arguments[ i ],
  23814. uuid = object.uuid,
  23815. index = indicesByUUID[ uuid ];
  23816. if ( index === undefined ) {
  23817. // unknown object -> add it to the ACTIVE region
  23818. index = nObjects ++;
  23819. indicesByUUID[ uuid ] = index;
  23820. objects.push( object );
  23821. // accounting is done, now do the same for all bindings
  23822. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  23823. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  23824. }
  23825. } else if ( index < nCachedObjects ) {
  23826. knownObject = objects[ index ];
  23827. // move existing object to the ACTIVE region
  23828. var firstActiveIndex = -- nCachedObjects,
  23829. lastCachedObject = objects[ firstActiveIndex ];
  23830. indicesByUUID[ lastCachedObject.uuid ] = index;
  23831. objects[ index ] = lastCachedObject;
  23832. indicesByUUID[ uuid ] = firstActiveIndex;
  23833. objects[ firstActiveIndex ] = object;
  23834. // accounting is done, now do the same for all bindings
  23835. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  23836. var bindingsForPath = bindings[ j ],
  23837. lastCached = bindingsForPath[ firstActiveIndex ],
  23838. binding = bindingsForPath[ index ];
  23839. bindingsForPath[ index ] = lastCached;
  23840. if ( binding === undefined ) {
  23841. // since we do not bother to create new bindings
  23842. // for objects that are cached, the binding may
  23843. // or may not exist
  23844. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  23845. }
  23846. bindingsForPath[ firstActiveIndex ] = binding;
  23847. }
  23848. } else if ( objects[ index ] !== knownObject ) {
  23849. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  23850. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  23851. } // else the object is already where we want it to be
  23852. } // for arguments
  23853. this.nCachedObjects_ = nCachedObjects;
  23854. },
  23855. remove: function () {
  23856. var objects = this._objects,
  23857. nCachedObjects = this.nCachedObjects_,
  23858. indicesByUUID = this._indicesByUUID,
  23859. bindings = this._bindings,
  23860. nBindings = bindings.length;
  23861. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  23862. var object = arguments[ i ],
  23863. uuid = object.uuid,
  23864. index = indicesByUUID[ uuid ];
  23865. if ( index !== undefined && index >= nCachedObjects ) {
  23866. // move existing object into the CACHED region
  23867. var lastCachedIndex = nCachedObjects ++,
  23868. firstActiveObject = objects[ lastCachedIndex ];
  23869. indicesByUUID[ firstActiveObject.uuid ] = index;
  23870. objects[ index ] = firstActiveObject;
  23871. indicesByUUID[ uuid ] = lastCachedIndex;
  23872. objects[ lastCachedIndex ] = object;
  23873. // accounting is done, now do the same for all bindings
  23874. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  23875. var bindingsForPath = bindings[ j ],
  23876. firstActive = bindingsForPath[ lastCachedIndex ],
  23877. binding = bindingsForPath[ index ];
  23878. bindingsForPath[ index ] = firstActive;
  23879. bindingsForPath[ lastCachedIndex ] = binding;
  23880. }
  23881. }
  23882. } // for arguments
  23883. this.nCachedObjects_ = nCachedObjects;
  23884. },
  23885. // remove & forget
  23886. uncache: function () {
  23887. var objects = this._objects,
  23888. nObjects = objects.length,
  23889. nCachedObjects = this.nCachedObjects_,
  23890. indicesByUUID = this._indicesByUUID,
  23891. bindings = this._bindings,
  23892. nBindings = bindings.length;
  23893. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  23894. var object = arguments[ i ],
  23895. uuid = object.uuid,
  23896. index = indicesByUUID[ uuid ];
  23897. if ( index !== undefined ) {
  23898. delete indicesByUUID[ uuid ];
  23899. if ( index < nCachedObjects ) {
  23900. // object is cached, shrink the CACHED region
  23901. var firstActiveIndex = -- nCachedObjects,
  23902. lastCachedObject = objects[ firstActiveIndex ],
  23903. lastIndex = -- nObjects,
  23904. lastObject = objects[ lastIndex ];
  23905. // last cached object takes this object's place
  23906. indicesByUUID[ lastCachedObject.uuid ] = index;
  23907. objects[ index ] = lastCachedObject;
  23908. // last object goes to the activated slot and pop
  23909. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  23910. objects[ firstActiveIndex ] = lastObject;
  23911. objects.pop();
  23912. // accounting is done, now do the same for all bindings
  23913. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  23914. var bindingsForPath = bindings[ j ],
  23915. lastCached = bindingsForPath[ firstActiveIndex ],
  23916. last = bindingsForPath[ lastIndex ];
  23917. bindingsForPath[ index ] = lastCached;
  23918. bindingsForPath[ firstActiveIndex ] = last;
  23919. bindingsForPath.pop();
  23920. }
  23921. } else {
  23922. // object is active, just swap with the last and pop
  23923. var lastIndex = -- nObjects,
  23924. lastObject = objects[ lastIndex ];
  23925. indicesByUUID[ lastObject.uuid ] = index;
  23926. objects[ index ] = lastObject;
  23927. objects.pop();
  23928. // accounting is done, now do the same for all bindings
  23929. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  23930. var bindingsForPath = bindings[ j ];
  23931. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  23932. bindingsForPath.pop();
  23933. }
  23934. } // cached or active
  23935. } // if object is known
  23936. } // for arguments
  23937. this.nCachedObjects_ = nCachedObjects;
  23938. },
  23939. // Internal interface used by befriended PropertyBinding.Composite:
  23940. subscribe_: function ( path, parsedPath ) {
  23941. // returns an array of bindings for the given path that is changed
  23942. // according to the contained objects in the group
  23943. var indicesByPath = this._bindingsIndicesByPath,
  23944. index = indicesByPath[ path ],
  23945. bindings = this._bindings;
  23946. if ( index !== undefined ) return bindings[ index ];
  23947. var paths = this._paths,
  23948. parsedPaths = this._parsedPaths,
  23949. objects = this._objects,
  23950. nObjects = objects.length,
  23951. nCachedObjects = this.nCachedObjects_,
  23952. bindingsForPath = new Array( nObjects );
  23953. index = bindings.length;
  23954. indicesByPath[ path ] = index;
  23955. paths.push( path );
  23956. parsedPaths.push( parsedPath );
  23957. bindings.push( bindingsForPath );
  23958. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  23959. var object = objects[ i ];
  23960. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  23961. }
  23962. return bindingsForPath;
  23963. },
  23964. unsubscribe_: function ( path ) {
  23965. // tells the group to forget about a property path and no longer
  23966. // update the array previously obtained with 'subscribe_'
  23967. var indicesByPath = this._bindingsIndicesByPath,
  23968. index = indicesByPath[ path ];
  23969. if ( index !== undefined ) {
  23970. var paths = this._paths,
  23971. parsedPaths = this._parsedPaths,
  23972. bindings = this._bindings,
  23973. lastBindingsIndex = bindings.length - 1,
  23974. lastBindings = bindings[ lastBindingsIndex ],
  23975. lastBindingsPath = path[ lastBindingsIndex ];
  23976. indicesByPath[ lastBindingsPath ] = index;
  23977. bindings[ index ] = lastBindings;
  23978. bindings.pop();
  23979. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  23980. parsedPaths.pop();
  23981. paths[ index ] = paths[ lastBindingsIndex ];
  23982. paths.pop();
  23983. }
  23984. }
  23985. } );
  23986. /**
  23987. *
  23988. * Action provided by AnimationMixer for scheduling clip playback on specific
  23989. * objects.
  23990. *
  23991. * @author Ben Houston / http://clara.io/
  23992. * @author David Sarno / http://lighthaus.us/
  23993. * @author tschw
  23994. *
  23995. */
  23996. function AnimationAction( mixer, clip, localRoot ) {
  23997. this._mixer = mixer;
  23998. this._clip = clip;
  23999. this._localRoot = localRoot || null;
  24000. var tracks = clip.tracks,
  24001. nTracks = tracks.length,
  24002. interpolants = new Array( nTracks );
  24003. var interpolantSettings = {
  24004. endingStart: ZeroCurvatureEnding,
  24005. endingEnd: ZeroCurvatureEnding
  24006. };
  24007. for ( var i = 0; i !== nTracks; ++ i ) {
  24008. var interpolant = tracks[ i ].createInterpolant( null );
  24009. interpolants[ i ] = interpolant;
  24010. interpolant.settings = interpolantSettings;
  24011. }
  24012. this._interpolantSettings = interpolantSettings;
  24013. this._interpolants = interpolants; // bound by the mixer
  24014. // inside: PropertyMixer (managed by the mixer)
  24015. this._propertyBindings = new Array( nTracks );
  24016. this._cacheIndex = null; // for the memory manager
  24017. this._byClipCacheIndex = null; // for the memory manager
  24018. this._timeScaleInterpolant = null;
  24019. this._weightInterpolant = null;
  24020. this.loop = LoopRepeat;
  24021. this._loopCount = - 1;
  24022. // global mixer time when the action is to be started
  24023. // it's set back to 'null' upon start of the action
  24024. this._startTime = null;
  24025. // scaled local time of the action
  24026. // gets clamped or wrapped to 0..clip.duration according to loop
  24027. this.time = 0;
  24028. this.timeScale = 1;
  24029. this._effectiveTimeScale = 1;
  24030. this.weight = 1;
  24031. this._effectiveWeight = 1;
  24032. this.repetitions = Infinity; // no. of repetitions when looping
  24033. this.paused = false; // true -> zero effective time scale
  24034. this.enabled = true; // false -> zero effective weight
  24035. this.clampWhenFinished = false; // keep feeding the last frame?
  24036. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  24037. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  24038. }
  24039. Object.assign( AnimationAction.prototype, {
  24040. // State & Scheduling
  24041. play: function () {
  24042. this._mixer._activateAction( this );
  24043. return this;
  24044. },
  24045. stop: function () {
  24046. this._mixer._deactivateAction( this );
  24047. return this.reset();
  24048. },
  24049. reset: function () {
  24050. this.paused = false;
  24051. this.enabled = true;
  24052. this.time = 0; // restart clip
  24053. this._loopCount = - 1; // forget previous loops
  24054. this._startTime = null; // forget scheduling
  24055. return this.stopFading().stopWarping();
  24056. },
  24057. isRunning: function () {
  24058. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  24059. this._startTime === null && this._mixer._isActiveAction( this );
  24060. },
  24061. // return true when play has been called
  24062. isScheduled: function () {
  24063. return this._mixer._isActiveAction( this );
  24064. },
  24065. startAt: function ( time ) {
  24066. this._startTime = time;
  24067. return this;
  24068. },
  24069. setLoop: function ( mode, repetitions ) {
  24070. this.loop = mode;
  24071. this.repetitions = repetitions;
  24072. return this;
  24073. },
  24074. // Weight
  24075. // set the weight stopping any scheduled fading
  24076. // although .enabled = false yields an effective weight of zero, this
  24077. // method does *not* change .enabled, because it would be confusing
  24078. setEffectiveWeight: function ( weight ) {
  24079. this.weight = weight;
  24080. // note: same logic as when updated at runtime
  24081. this._effectiveWeight = this.enabled ? weight : 0;
  24082. return this.stopFading();
  24083. },
  24084. // return the weight considering fading and .enabled
  24085. getEffectiveWeight: function () {
  24086. return this._effectiveWeight;
  24087. },
  24088. fadeIn: function ( duration ) {
  24089. return this._scheduleFading( duration, 0, 1 );
  24090. },
  24091. fadeOut: function ( duration ) {
  24092. return this._scheduleFading( duration, 1, 0 );
  24093. },
  24094. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  24095. fadeOutAction.fadeOut( duration );
  24096. this.fadeIn( duration );
  24097. if ( warp ) {
  24098. var fadeInDuration = this._clip.duration,
  24099. fadeOutDuration = fadeOutAction._clip.duration,
  24100. startEndRatio = fadeOutDuration / fadeInDuration,
  24101. endStartRatio = fadeInDuration / fadeOutDuration;
  24102. fadeOutAction.warp( 1.0, startEndRatio, duration );
  24103. this.warp( endStartRatio, 1.0, duration );
  24104. }
  24105. return this;
  24106. },
  24107. crossFadeTo: function ( fadeInAction, duration, warp ) {
  24108. return fadeInAction.crossFadeFrom( this, duration, warp );
  24109. },
  24110. stopFading: function () {
  24111. var weightInterpolant = this._weightInterpolant;
  24112. if ( weightInterpolant !== null ) {
  24113. this._weightInterpolant = null;
  24114. this._mixer._takeBackControlInterpolant( weightInterpolant );
  24115. }
  24116. return this;
  24117. },
  24118. // Time Scale Control
  24119. // set the time scale stopping any scheduled warping
  24120. // although .paused = true yields an effective time scale of zero, this
  24121. // method does *not* change .paused, because it would be confusing
  24122. setEffectiveTimeScale: function ( timeScale ) {
  24123. this.timeScale = timeScale;
  24124. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  24125. return this.stopWarping();
  24126. },
  24127. // return the time scale considering warping and .paused
  24128. getEffectiveTimeScale: function () {
  24129. return this._effectiveTimeScale;
  24130. },
  24131. setDuration: function ( duration ) {
  24132. this.timeScale = this._clip.duration / duration;
  24133. return this.stopWarping();
  24134. },
  24135. syncWith: function ( action ) {
  24136. this.time = action.time;
  24137. this.timeScale = action.timeScale;
  24138. return this.stopWarping();
  24139. },
  24140. halt: function ( duration ) {
  24141. return this.warp( this._effectiveTimeScale, 0, duration );
  24142. },
  24143. warp: function ( startTimeScale, endTimeScale, duration ) {
  24144. var mixer = this._mixer, now = mixer.time,
  24145. interpolant = this._timeScaleInterpolant,
  24146. timeScale = this.timeScale;
  24147. if ( interpolant === null ) {
  24148. interpolant = mixer._lendControlInterpolant();
  24149. this._timeScaleInterpolant = interpolant;
  24150. }
  24151. var times = interpolant.parameterPositions,
  24152. values = interpolant.sampleValues;
  24153. times[ 0 ] = now;
  24154. times[ 1 ] = now + duration;
  24155. values[ 0 ] = startTimeScale / timeScale;
  24156. values[ 1 ] = endTimeScale / timeScale;
  24157. return this;
  24158. },
  24159. stopWarping: function () {
  24160. var timeScaleInterpolant = this._timeScaleInterpolant;
  24161. if ( timeScaleInterpolant !== null ) {
  24162. this._timeScaleInterpolant = null;
  24163. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  24164. }
  24165. return this;
  24166. },
  24167. // Object Accessors
  24168. getMixer: function () {
  24169. return this._mixer;
  24170. },
  24171. getClip: function () {
  24172. return this._clip;
  24173. },
  24174. getRoot: function () {
  24175. return this._localRoot || this._mixer._root;
  24176. },
  24177. // Interna
  24178. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  24179. // called by the mixer
  24180. if ( ! this.enabled ) {
  24181. // call ._updateWeight() to update ._effectiveWeight
  24182. this._updateWeight( time );
  24183. return;
  24184. }
  24185. var startTime = this._startTime;
  24186. if ( startTime !== null ) {
  24187. // check for scheduled start of action
  24188. var timeRunning = ( time - startTime ) * timeDirection;
  24189. if ( timeRunning < 0 || timeDirection === 0 ) {
  24190. return; // yet to come / don't decide when delta = 0
  24191. }
  24192. // start
  24193. this._startTime = null; // unschedule
  24194. deltaTime = timeDirection * timeRunning;
  24195. }
  24196. // apply time scale and advance time
  24197. deltaTime *= this._updateTimeScale( time );
  24198. var clipTime = this._updateTime( deltaTime );
  24199. // note: _updateTime may disable the action resulting in
  24200. // an effective weight of 0
  24201. var weight = this._updateWeight( time );
  24202. if ( weight > 0 ) {
  24203. var interpolants = this._interpolants;
  24204. var propertyMixers = this._propertyBindings;
  24205. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  24206. interpolants[ j ].evaluate( clipTime );
  24207. propertyMixers[ j ].accumulate( accuIndex, weight );
  24208. }
  24209. }
  24210. },
  24211. _updateWeight: function ( time ) {
  24212. var weight = 0;
  24213. if ( this.enabled ) {
  24214. weight = this.weight;
  24215. var interpolant = this._weightInterpolant;
  24216. if ( interpolant !== null ) {
  24217. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  24218. weight *= interpolantValue;
  24219. if ( time > interpolant.parameterPositions[ 1 ] ) {
  24220. this.stopFading();
  24221. if ( interpolantValue === 0 ) {
  24222. // faded out, disable
  24223. this.enabled = false;
  24224. }
  24225. }
  24226. }
  24227. }
  24228. this._effectiveWeight = weight;
  24229. return weight;
  24230. },
  24231. _updateTimeScale: function ( time ) {
  24232. var timeScale = 0;
  24233. if ( ! this.paused ) {
  24234. timeScale = this.timeScale;
  24235. var interpolant = this._timeScaleInterpolant;
  24236. if ( interpolant !== null ) {
  24237. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  24238. timeScale *= interpolantValue;
  24239. if ( time > interpolant.parameterPositions[ 1 ] ) {
  24240. this.stopWarping();
  24241. if ( timeScale === 0 ) {
  24242. // motion has halted, pause
  24243. this.paused = true;
  24244. } else {
  24245. // warp done - apply final time scale
  24246. this.timeScale = timeScale;
  24247. }
  24248. }
  24249. }
  24250. }
  24251. this._effectiveTimeScale = timeScale;
  24252. return timeScale;
  24253. },
  24254. _updateTime: function ( deltaTime ) {
  24255. var time = this.time + deltaTime;
  24256. if ( deltaTime === 0 ) return time;
  24257. var duration = this._clip.duration,
  24258. loop = this.loop,
  24259. loopCount = this._loopCount;
  24260. if ( loop === LoopOnce ) {
  24261. if ( loopCount === - 1 ) {
  24262. // just started
  24263. this._loopCount = 0;
  24264. this._setEndings( true, true, false );
  24265. }
  24266. handle_stop: {
  24267. if ( time >= duration ) {
  24268. time = duration;
  24269. } else if ( time < 0 ) {
  24270. time = 0;
  24271. } else break handle_stop;
  24272. if ( this.clampWhenFinished ) this.paused = true;
  24273. else this.enabled = false;
  24274. this._mixer.dispatchEvent( {
  24275. type: 'finished', action: this,
  24276. direction: deltaTime < 0 ? - 1 : 1
  24277. } );
  24278. }
  24279. } else { // repetitive Repeat or PingPong
  24280. var pingPong = ( loop === LoopPingPong );
  24281. if ( loopCount === - 1 ) {
  24282. // just started
  24283. if ( deltaTime >= 0 ) {
  24284. loopCount = 0;
  24285. this._setEndings( true, this.repetitions === 0, pingPong );
  24286. } else {
  24287. // when looping in reverse direction, the initial
  24288. // transition through zero counts as a repetition,
  24289. // so leave loopCount at -1
  24290. this._setEndings( this.repetitions === 0, true, pingPong );
  24291. }
  24292. }
  24293. if ( time >= duration || time < 0 ) {
  24294. // wrap around
  24295. var loopDelta = Math.floor( time / duration ); // signed
  24296. time -= duration * loopDelta;
  24297. loopCount += Math.abs( loopDelta );
  24298. var pending = this.repetitions - loopCount;
  24299. if ( pending <= 0 ) {
  24300. // have to stop (switch state, clamp time, fire event)
  24301. if ( this.clampWhenFinished ) this.paused = true;
  24302. else this.enabled = false;
  24303. time = deltaTime > 0 ? duration : 0;
  24304. this._mixer.dispatchEvent( {
  24305. type: 'finished', action: this,
  24306. direction: deltaTime > 0 ? 1 : - 1
  24307. } );
  24308. } else {
  24309. // keep running
  24310. if ( pending === 1 ) {
  24311. // entering the last round
  24312. var atStart = deltaTime < 0;
  24313. this._setEndings( atStart, ! atStart, pingPong );
  24314. } else {
  24315. this._setEndings( false, false, pingPong );
  24316. }
  24317. this._loopCount = loopCount;
  24318. this._mixer.dispatchEvent( {
  24319. type: 'loop', action: this, loopDelta: loopDelta
  24320. } );
  24321. }
  24322. }
  24323. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  24324. // invert time for the "pong round"
  24325. this.time = time;
  24326. return duration - time;
  24327. }
  24328. }
  24329. this.time = time;
  24330. return time;
  24331. },
  24332. _setEndings: function ( atStart, atEnd, pingPong ) {
  24333. var settings = this._interpolantSettings;
  24334. if ( pingPong ) {
  24335. settings.endingStart = ZeroSlopeEnding;
  24336. settings.endingEnd = ZeroSlopeEnding;
  24337. } else {
  24338. // assuming for LoopOnce atStart == atEnd == true
  24339. if ( atStart ) {
  24340. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  24341. } else {
  24342. settings.endingStart = WrapAroundEnding;
  24343. }
  24344. if ( atEnd ) {
  24345. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  24346. } else {
  24347. settings.endingEnd = WrapAroundEnding;
  24348. }
  24349. }
  24350. },
  24351. _scheduleFading: function ( duration, weightNow, weightThen ) {
  24352. var mixer = this._mixer, now = mixer.time,
  24353. interpolant = this._weightInterpolant;
  24354. if ( interpolant === null ) {
  24355. interpolant = mixer._lendControlInterpolant();
  24356. this._weightInterpolant = interpolant;
  24357. }
  24358. var times = interpolant.parameterPositions,
  24359. values = interpolant.sampleValues;
  24360. times[ 0 ] = now; values[ 0 ] = weightNow;
  24361. times[ 1 ] = now + duration; values[ 1 ] = weightThen;
  24362. return this;
  24363. }
  24364. } );
  24365. /**
  24366. *
  24367. * Player for AnimationClips.
  24368. *
  24369. *
  24370. * @author Ben Houston / http://clara.io/
  24371. * @author David Sarno / http://lighthaus.us/
  24372. * @author tschw
  24373. */
  24374. function AnimationMixer( root ) {
  24375. this._root = root;
  24376. this._initMemoryManager();
  24377. this._accuIndex = 0;
  24378. this.time = 0;
  24379. this.timeScale = 1.0;
  24380. }
  24381. AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  24382. constructor: AnimationMixer,
  24383. _bindAction: function ( action, prototypeAction ) {
  24384. var root = action._localRoot || this._root,
  24385. tracks = action._clip.tracks,
  24386. nTracks = tracks.length,
  24387. bindings = action._propertyBindings,
  24388. interpolants = action._interpolants,
  24389. rootUuid = root.uuid,
  24390. bindingsByRoot = this._bindingsByRootAndName,
  24391. bindingsByName = bindingsByRoot[ rootUuid ];
  24392. if ( bindingsByName === undefined ) {
  24393. bindingsByName = {};
  24394. bindingsByRoot[ rootUuid ] = bindingsByName;
  24395. }
  24396. for ( var i = 0; i !== nTracks; ++ i ) {
  24397. var track = tracks[ i ],
  24398. trackName = track.name,
  24399. binding = bindingsByName[ trackName ];
  24400. if ( binding !== undefined ) {
  24401. bindings[ i ] = binding;
  24402. } else {
  24403. binding = bindings[ i ];
  24404. if ( binding !== undefined ) {
  24405. // existing binding, make sure the cache knows
  24406. if ( binding._cacheIndex === null ) {
  24407. ++ binding.referenceCount;
  24408. this._addInactiveBinding( binding, rootUuid, trackName );
  24409. }
  24410. continue;
  24411. }
  24412. var path = prototypeAction && prototypeAction.
  24413. _propertyBindings[ i ].binding.parsedPath;
  24414. binding = new PropertyMixer(
  24415. PropertyBinding.create( root, trackName, path ),
  24416. track.ValueTypeName, track.getValueSize() );
  24417. ++ binding.referenceCount;
  24418. this._addInactiveBinding( binding, rootUuid, trackName );
  24419. bindings[ i ] = binding;
  24420. }
  24421. interpolants[ i ].resultBuffer = binding.buffer;
  24422. }
  24423. },
  24424. _activateAction: function ( action ) {
  24425. if ( ! this._isActiveAction( action ) ) {
  24426. if ( action._cacheIndex === null ) {
  24427. // this action has been forgotten by the cache, but the user
  24428. // appears to be still using it -> rebind
  24429. var rootUuid = ( action._localRoot || this._root ).uuid,
  24430. clipUuid = action._clip.uuid,
  24431. actionsForClip = this._actionsByClip[ clipUuid ];
  24432. this._bindAction( action,
  24433. actionsForClip && actionsForClip.knownActions[ 0 ] );
  24434. this._addInactiveAction( action, clipUuid, rootUuid );
  24435. }
  24436. var bindings = action._propertyBindings;
  24437. // increment reference counts / sort out state
  24438. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  24439. var binding = bindings[ i ];
  24440. if ( binding.useCount ++ === 0 ) {
  24441. this._lendBinding( binding );
  24442. binding.saveOriginalState();
  24443. }
  24444. }
  24445. this._lendAction( action );
  24446. }
  24447. },
  24448. _deactivateAction: function ( action ) {
  24449. if ( this._isActiveAction( action ) ) {
  24450. var bindings = action._propertyBindings;
  24451. // decrement reference counts / sort out state
  24452. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  24453. var binding = bindings[ i ];
  24454. if ( -- binding.useCount === 0 ) {
  24455. binding.restoreOriginalState();
  24456. this._takeBackBinding( binding );
  24457. }
  24458. }
  24459. this._takeBackAction( action );
  24460. }
  24461. },
  24462. // Memory manager
  24463. _initMemoryManager: function () {
  24464. this._actions = []; // 'nActiveActions' followed by inactive ones
  24465. this._nActiveActions = 0;
  24466. this._actionsByClip = {};
  24467. // inside:
  24468. // {
  24469. // knownActions: Array< AnimationAction > - used as prototypes
  24470. // actionByRoot: AnimationAction - lookup
  24471. // }
  24472. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  24473. this._nActiveBindings = 0;
  24474. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  24475. this._controlInterpolants = []; // same game as above
  24476. this._nActiveControlInterpolants = 0;
  24477. var scope = this;
  24478. this.stats = {
  24479. actions: {
  24480. get total() {
  24481. return scope._actions.length;
  24482. },
  24483. get inUse() {
  24484. return scope._nActiveActions;
  24485. }
  24486. },
  24487. bindings: {
  24488. get total() {
  24489. return scope._bindings.length;
  24490. },
  24491. get inUse() {
  24492. return scope._nActiveBindings;
  24493. }
  24494. },
  24495. controlInterpolants: {
  24496. get total() {
  24497. return scope._controlInterpolants.length;
  24498. },
  24499. get inUse() {
  24500. return scope._nActiveControlInterpolants;
  24501. }
  24502. }
  24503. };
  24504. },
  24505. // Memory management for AnimationAction objects
  24506. _isActiveAction: function ( action ) {
  24507. var index = action._cacheIndex;
  24508. return index !== null && index < this._nActiveActions;
  24509. },
  24510. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  24511. var actions = this._actions,
  24512. actionsByClip = this._actionsByClip,
  24513. actionsForClip = actionsByClip[ clipUuid ];
  24514. if ( actionsForClip === undefined ) {
  24515. actionsForClip = {
  24516. knownActions: [ action ],
  24517. actionByRoot: {}
  24518. };
  24519. action._byClipCacheIndex = 0;
  24520. actionsByClip[ clipUuid ] = actionsForClip;
  24521. } else {
  24522. var knownActions = actionsForClip.knownActions;
  24523. action._byClipCacheIndex = knownActions.length;
  24524. knownActions.push( action );
  24525. }
  24526. action._cacheIndex = actions.length;
  24527. actions.push( action );
  24528. actionsForClip.actionByRoot[ rootUuid ] = action;
  24529. },
  24530. _removeInactiveAction: function ( action ) {
  24531. var actions = this._actions,
  24532. lastInactiveAction = actions[ actions.length - 1 ],
  24533. cacheIndex = action._cacheIndex;
  24534. lastInactiveAction._cacheIndex = cacheIndex;
  24535. actions[ cacheIndex ] = lastInactiveAction;
  24536. actions.pop();
  24537. action._cacheIndex = null;
  24538. var clipUuid = action._clip.uuid,
  24539. actionsByClip = this._actionsByClip,
  24540. actionsForClip = actionsByClip[ clipUuid ],
  24541. knownActionsForClip = actionsForClip.knownActions,
  24542. lastKnownAction =
  24543. knownActionsForClip[ knownActionsForClip.length - 1 ],
  24544. byClipCacheIndex = action._byClipCacheIndex;
  24545. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  24546. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  24547. knownActionsForClip.pop();
  24548. action._byClipCacheIndex = null;
  24549. var actionByRoot = actionsForClip.actionByRoot,
  24550. rootUuid = ( action._localRoot || this._root ).uuid;
  24551. delete actionByRoot[ rootUuid ];
  24552. if ( knownActionsForClip.length === 0 ) {
  24553. delete actionsByClip[ clipUuid ];
  24554. }
  24555. this._removeInactiveBindingsForAction( action );
  24556. },
  24557. _removeInactiveBindingsForAction: function ( action ) {
  24558. var bindings = action._propertyBindings;
  24559. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  24560. var binding = bindings[ i ];
  24561. if ( -- binding.referenceCount === 0 ) {
  24562. this._removeInactiveBinding( binding );
  24563. }
  24564. }
  24565. },
  24566. _lendAction: function ( action ) {
  24567. // [ active actions | inactive actions ]
  24568. // [ active actions >| inactive actions ]
  24569. // s a
  24570. // <-swap->
  24571. // a s
  24572. var actions = this._actions,
  24573. prevIndex = action._cacheIndex,
  24574. lastActiveIndex = this._nActiveActions ++,
  24575. firstInactiveAction = actions[ lastActiveIndex ];
  24576. action._cacheIndex = lastActiveIndex;
  24577. actions[ lastActiveIndex ] = action;
  24578. firstInactiveAction._cacheIndex = prevIndex;
  24579. actions[ prevIndex ] = firstInactiveAction;
  24580. },
  24581. _takeBackAction: function ( action ) {
  24582. // [ active actions | inactive actions ]
  24583. // [ active actions |< inactive actions ]
  24584. // a s
  24585. // <-swap->
  24586. // s a
  24587. var actions = this._actions,
  24588. prevIndex = action._cacheIndex,
  24589. firstInactiveIndex = -- this._nActiveActions,
  24590. lastActiveAction = actions[ firstInactiveIndex ];
  24591. action._cacheIndex = firstInactiveIndex;
  24592. actions[ firstInactiveIndex ] = action;
  24593. lastActiveAction._cacheIndex = prevIndex;
  24594. actions[ prevIndex ] = lastActiveAction;
  24595. },
  24596. // Memory management for PropertyMixer objects
  24597. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  24598. var bindingsByRoot = this._bindingsByRootAndName,
  24599. bindingByName = bindingsByRoot[ rootUuid ],
  24600. bindings = this._bindings;
  24601. if ( bindingByName === undefined ) {
  24602. bindingByName = {};
  24603. bindingsByRoot[ rootUuid ] = bindingByName;
  24604. }
  24605. bindingByName[ trackName ] = binding;
  24606. binding._cacheIndex = bindings.length;
  24607. bindings.push( binding );
  24608. },
  24609. _removeInactiveBinding: function ( binding ) {
  24610. var bindings = this._bindings,
  24611. propBinding = binding.binding,
  24612. rootUuid = propBinding.rootNode.uuid,
  24613. trackName = propBinding.path,
  24614. bindingsByRoot = this._bindingsByRootAndName,
  24615. bindingByName = bindingsByRoot[ rootUuid ],
  24616. lastInactiveBinding = bindings[ bindings.length - 1 ],
  24617. cacheIndex = binding._cacheIndex;
  24618. lastInactiveBinding._cacheIndex = cacheIndex;
  24619. bindings[ cacheIndex ] = lastInactiveBinding;
  24620. bindings.pop();
  24621. delete bindingByName[ trackName ];
  24622. remove_empty_map: {
  24623. for ( var _ in bindingByName ) break remove_empty_map; // eslint-disable-line no-unused-vars
  24624. delete bindingsByRoot[ rootUuid ];
  24625. }
  24626. },
  24627. _lendBinding: function ( binding ) {
  24628. var bindings = this._bindings,
  24629. prevIndex = binding._cacheIndex,
  24630. lastActiveIndex = this._nActiveBindings ++,
  24631. firstInactiveBinding = bindings[ lastActiveIndex ];
  24632. binding._cacheIndex = lastActiveIndex;
  24633. bindings[ lastActiveIndex ] = binding;
  24634. firstInactiveBinding._cacheIndex = prevIndex;
  24635. bindings[ prevIndex ] = firstInactiveBinding;
  24636. },
  24637. _takeBackBinding: function ( binding ) {
  24638. var bindings = this._bindings,
  24639. prevIndex = binding._cacheIndex,
  24640. firstInactiveIndex = -- this._nActiveBindings,
  24641. lastActiveBinding = bindings[ firstInactiveIndex ];
  24642. binding._cacheIndex = firstInactiveIndex;
  24643. bindings[ firstInactiveIndex ] = binding;
  24644. lastActiveBinding._cacheIndex = prevIndex;
  24645. bindings[ prevIndex ] = lastActiveBinding;
  24646. },
  24647. // Memory management of Interpolants for weight and time scale
  24648. _lendControlInterpolant: function () {
  24649. var interpolants = this._controlInterpolants,
  24650. lastActiveIndex = this._nActiveControlInterpolants ++,
  24651. interpolant = interpolants[ lastActiveIndex ];
  24652. if ( interpolant === undefined ) {
  24653. interpolant = new LinearInterpolant(
  24654. new Float32Array( 2 ), new Float32Array( 2 ),
  24655. 1, this._controlInterpolantsResultBuffer );
  24656. interpolant.__cacheIndex = lastActiveIndex;
  24657. interpolants[ lastActiveIndex ] = interpolant;
  24658. }
  24659. return interpolant;
  24660. },
  24661. _takeBackControlInterpolant: function ( interpolant ) {
  24662. var interpolants = this._controlInterpolants,
  24663. prevIndex = interpolant.__cacheIndex,
  24664. firstInactiveIndex = -- this._nActiveControlInterpolants,
  24665. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  24666. interpolant.__cacheIndex = firstInactiveIndex;
  24667. interpolants[ firstInactiveIndex ] = interpolant;
  24668. lastActiveInterpolant.__cacheIndex = prevIndex;
  24669. interpolants[ prevIndex ] = lastActiveInterpolant;
  24670. },
  24671. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  24672. // return an action for a clip optionally using a custom root target
  24673. // object (this method allocates a lot of dynamic memory in case a
  24674. // previously unknown clip/root combination is specified)
  24675. clipAction: function ( clip, optionalRoot ) {
  24676. var root = optionalRoot || this._root,
  24677. rootUuid = root.uuid,
  24678. clipObject = typeof clip === 'string' ?
  24679. AnimationClip.findByName( root, clip ) : clip,
  24680. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  24681. actionsForClip = this._actionsByClip[ clipUuid ],
  24682. prototypeAction = null;
  24683. if ( actionsForClip !== undefined ) {
  24684. var existingAction =
  24685. actionsForClip.actionByRoot[ rootUuid ];
  24686. if ( existingAction !== undefined ) {
  24687. return existingAction;
  24688. }
  24689. // we know the clip, so we don't have to parse all
  24690. // the bindings again but can just copy
  24691. prototypeAction = actionsForClip.knownActions[ 0 ];
  24692. // also, take the clip from the prototype action
  24693. if ( clipObject === null )
  24694. clipObject = prototypeAction._clip;
  24695. }
  24696. // clip must be known when specified via string
  24697. if ( clipObject === null ) return null;
  24698. // allocate all resources required to run it
  24699. var newAction = new AnimationAction( this, clipObject, optionalRoot );
  24700. this._bindAction( newAction, prototypeAction );
  24701. // and make the action known to the memory manager
  24702. this._addInactiveAction( newAction, clipUuid, rootUuid );
  24703. return newAction;
  24704. },
  24705. // get an existing action
  24706. existingAction: function ( clip, optionalRoot ) {
  24707. var root = optionalRoot || this._root,
  24708. rootUuid = root.uuid,
  24709. clipObject = typeof clip === 'string' ?
  24710. AnimationClip.findByName( root, clip ) : clip,
  24711. clipUuid = clipObject ? clipObject.uuid : clip,
  24712. actionsForClip = this._actionsByClip[ clipUuid ];
  24713. if ( actionsForClip !== undefined ) {
  24714. return actionsForClip.actionByRoot[ rootUuid ] || null;
  24715. }
  24716. return null;
  24717. },
  24718. // deactivates all previously scheduled actions
  24719. stopAllAction: function () {
  24720. var actions = this._actions,
  24721. nActions = this._nActiveActions,
  24722. bindings = this._bindings,
  24723. nBindings = this._nActiveBindings;
  24724. this._nActiveActions = 0;
  24725. this._nActiveBindings = 0;
  24726. for ( var i = 0; i !== nActions; ++ i ) {
  24727. actions[ i ].reset();
  24728. }
  24729. for ( var i = 0; i !== nBindings; ++ i ) {
  24730. bindings[ i ].useCount = 0;
  24731. }
  24732. return this;
  24733. },
  24734. // advance the time and update apply the animation
  24735. update: function ( deltaTime ) {
  24736. deltaTime *= this.timeScale;
  24737. var actions = this._actions,
  24738. nActions = this._nActiveActions,
  24739. time = this.time += deltaTime,
  24740. timeDirection = Math.sign( deltaTime ),
  24741. accuIndex = this._accuIndex ^= 1;
  24742. // run active actions
  24743. for ( var i = 0; i !== nActions; ++ i ) {
  24744. var action = actions[ i ];
  24745. action._update( time, deltaTime, timeDirection, accuIndex );
  24746. }
  24747. // update scene graph
  24748. var bindings = this._bindings,
  24749. nBindings = this._nActiveBindings;
  24750. for ( var i = 0; i !== nBindings; ++ i ) {
  24751. bindings[ i ].apply( accuIndex );
  24752. }
  24753. return this;
  24754. },
  24755. // return this mixer's root target object
  24756. getRoot: function () {
  24757. return this._root;
  24758. },
  24759. // free all resources specific to a particular clip
  24760. uncacheClip: function ( clip ) {
  24761. var actions = this._actions,
  24762. clipUuid = clip.uuid,
  24763. actionsByClip = this._actionsByClip,
  24764. actionsForClip = actionsByClip[ clipUuid ];
  24765. if ( actionsForClip !== undefined ) {
  24766. // note: just calling _removeInactiveAction would mess up the
  24767. // iteration state and also require updating the state we can
  24768. // just throw away
  24769. var actionsToRemove = actionsForClip.knownActions;
  24770. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  24771. var action = actionsToRemove[ i ];
  24772. this._deactivateAction( action );
  24773. var cacheIndex = action._cacheIndex,
  24774. lastInactiveAction = actions[ actions.length - 1 ];
  24775. action._cacheIndex = null;
  24776. action._byClipCacheIndex = null;
  24777. lastInactiveAction._cacheIndex = cacheIndex;
  24778. actions[ cacheIndex ] = lastInactiveAction;
  24779. actions.pop();
  24780. this._removeInactiveBindingsForAction( action );
  24781. }
  24782. delete actionsByClip[ clipUuid ];
  24783. }
  24784. },
  24785. // free all resources specific to a particular root target object
  24786. uncacheRoot: function ( root ) {
  24787. var rootUuid = root.uuid,
  24788. actionsByClip = this._actionsByClip;
  24789. for ( var clipUuid in actionsByClip ) {
  24790. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  24791. action = actionByRoot[ rootUuid ];
  24792. if ( action !== undefined ) {
  24793. this._deactivateAction( action );
  24794. this._removeInactiveAction( action );
  24795. }
  24796. }
  24797. var bindingsByRoot = this._bindingsByRootAndName,
  24798. bindingByName = bindingsByRoot[ rootUuid ];
  24799. if ( bindingByName !== undefined ) {
  24800. for ( var trackName in bindingByName ) {
  24801. var binding = bindingByName[ trackName ];
  24802. binding.restoreOriginalState();
  24803. this._removeInactiveBinding( binding );
  24804. }
  24805. }
  24806. },
  24807. // remove a targeted clip from the cache
  24808. uncacheAction: function ( clip, optionalRoot ) {
  24809. var action = this.existingAction( clip, optionalRoot );
  24810. if ( action !== null ) {
  24811. this._deactivateAction( action );
  24812. this._removeInactiveAction( action );
  24813. }
  24814. }
  24815. } );
  24816. /**
  24817. * @author mrdoob / http://mrdoob.com/
  24818. */
  24819. function Uniform( value ) {
  24820. if ( typeof value === 'string' ) {
  24821. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  24822. value = arguments[ 1 ];
  24823. }
  24824. this.value = value;
  24825. }
  24826. Uniform.prototype.clone = function () {
  24827. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  24828. };
  24829. /**
  24830. * @author benaadams / https://twitter.com/ben_a_adams
  24831. */
  24832. function InstancedBufferGeometry() {
  24833. BufferGeometry.call( this );
  24834. this.type = 'InstancedBufferGeometry';
  24835. this.maxInstancedCount = undefined;
  24836. }
  24837. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  24838. constructor: InstancedBufferGeometry,
  24839. isInstancedBufferGeometry: true,
  24840. copy: function ( source ) {
  24841. BufferGeometry.prototype.copy.call( this, source );
  24842. this.maxInstancedCount = source.maxInstancedCount;
  24843. return this;
  24844. },
  24845. clone: function () {
  24846. return new this.constructor().copy( this );
  24847. }
  24848. } );
  24849. /**
  24850. * @author benaadams / https://twitter.com/ben_a_adams
  24851. */
  24852. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  24853. this.data = interleavedBuffer;
  24854. this.itemSize = itemSize;
  24855. this.offset = offset;
  24856. this.normalized = normalized === true;
  24857. }
  24858. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  24859. count: {
  24860. get: function () {
  24861. return this.data.count;
  24862. }
  24863. },
  24864. array: {
  24865. get: function () {
  24866. return this.data.array;
  24867. }
  24868. }
  24869. } );
  24870. Object.assign( InterleavedBufferAttribute.prototype, {
  24871. isInterleavedBufferAttribute: true,
  24872. setX: function ( index, x ) {
  24873. this.data.array[ index * this.data.stride + this.offset ] = x;
  24874. return this;
  24875. },
  24876. setY: function ( index, y ) {
  24877. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  24878. return this;
  24879. },
  24880. setZ: function ( index, z ) {
  24881. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  24882. return this;
  24883. },
  24884. setW: function ( index, w ) {
  24885. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  24886. return this;
  24887. },
  24888. getX: function ( index ) {
  24889. return this.data.array[ index * this.data.stride + this.offset ];
  24890. },
  24891. getY: function ( index ) {
  24892. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  24893. },
  24894. getZ: function ( index ) {
  24895. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  24896. },
  24897. getW: function ( index ) {
  24898. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  24899. },
  24900. setXY: function ( index, x, y ) {
  24901. index = index * this.data.stride + this.offset;
  24902. this.data.array[ index + 0 ] = x;
  24903. this.data.array[ index + 1 ] = y;
  24904. return this;
  24905. },
  24906. setXYZ: function ( index, x, y, z ) {
  24907. index = index * this.data.stride + this.offset;
  24908. this.data.array[ index + 0 ] = x;
  24909. this.data.array[ index + 1 ] = y;
  24910. this.data.array[ index + 2 ] = z;
  24911. return this;
  24912. },
  24913. setXYZW: function ( index, x, y, z, w ) {
  24914. index = index * this.data.stride + this.offset;
  24915. this.data.array[ index + 0 ] = x;
  24916. this.data.array[ index + 1 ] = y;
  24917. this.data.array[ index + 2 ] = z;
  24918. this.data.array[ index + 3 ] = w;
  24919. return this;
  24920. }
  24921. } );
  24922. /**
  24923. * @author benaadams / https://twitter.com/ben_a_adams
  24924. */
  24925. function InterleavedBuffer( array, stride ) {
  24926. this.array = array;
  24927. this.stride = stride;
  24928. this.count = array !== undefined ? array.length / stride : 0;
  24929. this.dynamic = false;
  24930. this.updateRange = { offset: 0, count: - 1 };
  24931. this.version = 0;
  24932. }
  24933. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  24934. set: function ( value ) {
  24935. if ( value === true ) this.version ++;
  24936. }
  24937. } );
  24938. Object.assign( InterleavedBuffer.prototype, {
  24939. isInterleavedBuffer: true,
  24940. onUploadCallback: function () {},
  24941. setArray: function ( array ) {
  24942. if ( Array.isArray( array ) ) {
  24943. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  24944. }
  24945. this.count = array !== undefined ? array.length / this.stride : 0;
  24946. this.array = array;
  24947. return this;
  24948. },
  24949. setDynamic: function ( value ) {
  24950. this.dynamic = value;
  24951. return this;
  24952. },
  24953. copy: function ( source ) {
  24954. this.array = new source.array.constructor( source.array );
  24955. this.count = source.count;
  24956. this.stride = source.stride;
  24957. this.dynamic = source.dynamic;
  24958. return this;
  24959. },
  24960. copyAt: function ( index1, attribute, index2 ) {
  24961. index1 *= this.stride;
  24962. index2 *= attribute.stride;
  24963. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  24964. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  24965. }
  24966. return this;
  24967. },
  24968. set: function ( value, offset ) {
  24969. if ( offset === undefined ) offset = 0;
  24970. this.array.set( value, offset );
  24971. return this;
  24972. },
  24973. clone: function () {
  24974. return new this.constructor().copy( this );
  24975. },
  24976. onUpload: function ( callback ) {
  24977. this.onUploadCallback = callback;
  24978. return this;
  24979. }
  24980. } );
  24981. /**
  24982. * @author benaadams / https://twitter.com/ben_a_adams
  24983. */
  24984. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  24985. InterleavedBuffer.call( this, array, stride );
  24986. this.meshPerAttribute = meshPerAttribute || 1;
  24987. }
  24988. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  24989. constructor: InstancedInterleavedBuffer,
  24990. isInstancedInterleavedBuffer: true,
  24991. copy: function ( source ) {
  24992. InterleavedBuffer.prototype.copy.call( this, source );
  24993. this.meshPerAttribute = source.meshPerAttribute;
  24994. return this;
  24995. }
  24996. } );
  24997. /**
  24998. * @author benaadams / https://twitter.com/ben_a_adams
  24999. */
  25000. function InstancedBufferAttribute( array, itemSize, meshPerAttribute ) {
  25001. BufferAttribute.call( this, array, itemSize );
  25002. this.meshPerAttribute = meshPerAttribute || 1;
  25003. }
  25004. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  25005. constructor: InstancedBufferAttribute,
  25006. isInstancedBufferAttribute: true,
  25007. copy: function ( source ) {
  25008. BufferAttribute.prototype.copy.call( this, source );
  25009. this.meshPerAttribute = source.meshPerAttribute;
  25010. return this;
  25011. }
  25012. } );
  25013. /**
  25014. * @author mrdoob / http://mrdoob.com/
  25015. * @author bhouston / http://clara.io/
  25016. * @author stephomi / http://stephaneginier.com/
  25017. */
  25018. function Raycaster( origin, direction, near, far ) {
  25019. this.ray = new Ray( origin, direction );
  25020. // direction is assumed to be normalized (for accurate distance calculations)
  25021. this.near = near || 0;
  25022. this.far = far || Infinity;
  25023. this.params = {
  25024. Mesh: {},
  25025. Line: {},
  25026. LOD: {},
  25027. Points: { threshold: 1 },
  25028. Sprite: {}
  25029. };
  25030. Object.defineProperties( this.params, {
  25031. PointCloud: {
  25032. get: function () {
  25033. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  25034. return this.Points;
  25035. }
  25036. }
  25037. } );
  25038. }
  25039. function ascSort( a, b ) {
  25040. return a.distance - b.distance;
  25041. }
  25042. function intersectObject( object, raycaster, intersects, recursive ) {
  25043. if ( object.visible === false ) return;
  25044. object.raycast( raycaster, intersects );
  25045. if ( recursive === true ) {
  25046. var children = object.children;
  25047. for ( var i = 0, l = children.length; i < l; i ++ ) {
  25048. intersectObject( children[ i ], raycaster, intersects, true );
  25049. }
  25050. }
  25051. }
  25052. Object.assign( Raycaster.prototype, {
  25053. linePrecision: 1,
  25054. set: function ( origin, direction ) {
  25055. // direction is assumed to be normalized (for accurate distance calculations)
  25056. this.ray.set( origin, direction );
  25057. },
  25058. setFromCamera: function ( coords, camera ) {
  25059. if ( ( camera && camera.isPerspectiveCamera ) ) {
  25060. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  25061. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  25062. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  25063. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  25064. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  25065. } else {
  25066. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  25067. }
  25068. },
  25069. intersectObject: function ( object, recursive, optionalTarget ) {
  25070. var intersects = optionalTarget || [];
  25071. intersectObject( object, this, intersects, recursive );
  25072. intersects.sort( ascSort );
  25073. return intersects;
  25074. },
  25075. intersectObjects: function ( objects, recursive, optionalTarget ) {
  25076. var intersects = optionalTarget || [];
  25077. if ( Array.isArray( objects ) === false ) {
  25078. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  25079. return intersects;
  25080. }
  25081. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  25082. intersectObject( objects[ i ], this, intersects, recursive );
  25083. }
  25084. intersects.sort( ascSort );
  25085. return intersects;
  25086. }
  25087. } );
  25088. /**
  25089. * @author alteredq / http://alteredqualia.com/
  25090. */
  25091. function Clock( autoStart ) {
  25092. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  25093. this.startTime = 0;
  25094. this.oldTime = 0;
  25095. this.elapsedTime = 0;
  25096. this.running = false;
  25097. }
  25098. Object.assign( Clock.prototype, {
  25099. start: function () {
  25100. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  25101. this.oldTime = this.startTime;
  25102. this.elapsedTime = 0;
  25103. this.running = true;
  25104. },
  25105. stop: function () {
  25106. this.getElapsedTime();
  25107. this.running = false;
  25108. this.autoStart = false;
  25109. },
  25110. getElapsedTime: function () {
  25111. this.getDelta();
  25112. return this.elapsedTime;
  25113. },
  25114. getDelta: function () {
  25115. var diff = 0;
  25116. if ( this.autoStart && ! this.running ) {
  25117. this.start();
  25118. return 0;
  25119. }
  25120. if ( this.running ) {
  25121. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  25122. diff = ( newTime - this.oldTime ) / 1000;
  25123. this.oldTime = newTime;
  25124. this.elapsedTime += diff;
  25125. }
  25126. return diff;
  25127. }
  25128. } );
  25129. /**
  25130. * @author bhouston / http://clara.io
  25131. * @author WestLangley / http://github.com/WestLangley
  25132. *
  25133. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  25134. *
  25135. * The poles (phi) are at the positive and negative y axis.
  25136. * The equator starts at positive z.
  25137. */
  25138. function Spherical( radius, phi, theta ) {
  25139. this.radius = ( radius !== undefined ) ? radius : 1.0;
  25140. this.phi = ( phi !== undefined ) ? phi : 0; // up / down towards top and bottom pole
  25141. this.theta = ( theta !== undefined ) ? theta : 0; // around the equator of the sphere
  25142. return this;
  25143. }
  25144. Object.assign( Spherical.prototype, {
  25145. set: function ( radius, phi, theta ) {
  25146. this.radius = radius;
  25147. this.phi = phi;
  25148. this.theta = theta;
  25149. return this;
  25150. },
  25151. clone: function () {
  25152. return new this.constructor().copy( this );
  25153. },
  25154. copy: function ( other ) {
  25155. this.radius = other.radius;
  25156. this.phi = other.phi;
  25157. this.theta = other.theta;
  25158. return this;
  25159. },
  25160. // restrict phi to be betwee EPS and PI-EPS
  25161. makeSafe: function () {
  25162. var EPS = 0.000001;
  25163. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  25164. return this;
  25165. },
  25166. setFromVector3: function ( vec3 ) {
  25167. this.radius = vec3.length();
  25168. if ( this.radius === 0 ) {
  25169. this.theta = 0;
  25170. this.phi = 0;
  25171. } else {
  25172. this.theta = Math.atan2( vec3.x, vec3.z ); // equator angle around y-up axis
  25173. this.phi = Math.acos( _Math.clamp( vec3.y / this.radius, - 1, 1 ) ); // polar angle
  25174. }
  25175. return this;
  25176. }
  25177. } );
  25178. /**
  25179. * @author Mugen87 / https://github.com/Mugen87
  25180. *
  25181. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  25182. *
  25183. */
  25184. function Cylindrical( radius, theta, y ) {
  25185. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  25186. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  25187. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  25188. return this;
  25189. }
  25190. Object.assign( Cylindrical.prototype, {
  25191. set: function ( radius, theta, y ) {
  25192. this.radius = radius;
  25193. this.theta = theta;
  25194. this.y = y;
  25195. return this;
  25196. },
  25197. clone: function () {
  25198. return new this.constructor().copy( this );
  25199. },
  25200. copy: function ( other ) {
  25201. this.radius = other.radius;
  25202. this.theta = other.theta;
  25203. this.y = other.y;
  25204. return this;
  25205. },
  25206. setFromVector3: function ( vec3 ) {
  25207. this.radius = Math.sqrt( vec3.x * vec3.x + vec3.z * vec3.z );
  25208. this.theta = Math.atan2( vec3.x, vec3.z );
  25209. this.y = vec3.y;
  25210. return this;
  25211. }
  25212. } );
  25213. /**
  25214. * @author bhouston / http://clara.io
  25215. */
  25216. function Box2( min, max ) {
  25217. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  25218. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  25219. }
  25220. Object.assign( Box2.prototype, {
  25221. set: function ( min, max ) {
  25222. this.min.copy( min );
  25223. this.max.copy( max );
  25224. return this;
  25225. },
  25226. setFromPoints: function ( points ) {
  25227. this.makeEmpty();
  25228. for ( var i = 0, il = points.length; i < il; i ++ ) {
  25229. this.expandByPoint( points[ i ] );
  25230. }
  25231. return this;
  25232. },
  25233. setFromCenterAndSize: function () {
  25234. var v1 = new Vector2();
  25235. return function setFromCenterAndSize( center, size ) {
  25236. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  25237. this.min.copy( center ).sub( halfSize );
  25238. this.max.copy( center ).add( halfSize );
  25239. return this;
  25240. };
  25241. }(),
  25242. clone: function () {
  25243. return new this.constructor().copy( this );
  25244. },
  25245. copy: function ( box ) {
  25246. this.min.copy( box.min );
  25247. this.max.copy( box.max );
  25248. return this;
  25249. },
  25250. makeEmpty: function () {
  25251. this.min.x = this.min.y = + Infinity;
  25252. this.max.x = this.max.y = - Infinity;
  25253. return this;
  25254. },
  25255. isEmpty: function () {
  25256. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  25257. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  25258. },
  25259. getCenter: function ( target ) {
  25260. if ( target === undefined ) {
  25261. console.warn( 'THREE.Box2: .getCenter() target is now required' );
  25262. target = new Vector2();
  25263. }
  25264. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  25265. },
  25266. getSize: function ( target ) {
  25267. if ( target === undefined ) {
  25268. console.warn( 'THREE.Box2: .getSize() target is now required' );
  25269. target = new Vector2();
  25270. }
  25271. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  25272. },
  25273. expandByPoint: function ( point ) {
  25274. this.min.min( point );
  25275. this.max.max( point );
  25276. return this;
  25277. },
  25278. expandByVector: function ( vector ) {
  25279. this.min.sub( vector );
  25280. this.max.add( vector );
  25281. return this;
  25282. },
  25283. expandByScalar: function ( scalar ) {
  25284. this.min.addScalar( - scalar );
  25285. this.max.addScalar( scalar );
  25286. return this;
  25287. },
  25288. containsPoint: function ( point ) {
  25289. return point.x < this.min.x || point.x > this.max.x ||
  25290. point.y < this.min.y || point.y > this.max.y ? false : true;
  25291. },
  25292. containsBox: function ( box ) {
  25293. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  25294. this.min.y <= box.min.y && box.max.y <= this.max.y;
  25295. },
  25296. getParameter: function ( point, target ) {
  25297. // This can potentially have a divide by zero if the box
  25298. // has a size dimension of 0.
  25299. if ( target === undefined ) {
  25300. console.warn( 'THREE.Box2: .getParameter() target is now required' );
  25301. target = new Vector2();
  25302. }
  25303. return target.set(
  25304. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  25305. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  25306. );
  25307. },
  25308. intersectsBox: function ( box ) {
  25309. // using 4 splitting planes to rule out intersections
  25310. return box.max.x < this.min.x || box.min.x > this.max.x ||
  25311. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  25312. },
  25313. clampPoint: function ( point, target ) {
  25314. if ( target === undefined ) {
  25315. console.warn( 'THREE.Box2: .clampPoint() target is now required' );
  25316. target = new Vector2();
  25317. }
  25318. return target.copy( point ).clamp( this.min, this.max );
  25319. },
  25320. distanceToPoint: function () {
  25321. var v1 = new Vector2();
  25322. return function distanceToPoint( point ) {
  25323. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  25324. return clampedPoint.sub( point ).length();
  25325. };
  25326. }(),
  25327. intersect: function ( box ) {
  25328. this.min.max( box.min );
  25329. this.max.min( box.max );
  25330. return this;
  25331. },
  25332. union: function ( box ) {
  25333. this.min.min( box.min );
  25334. this.max.max( box.max );
  25335. return this;
  25336. },
  25337. translate: function ( offset ) {
  25338. this.min.add( offset );
  25339. this.max.add( offset );
  25340. return this;
  25341. },
  25342. equals: function ( box ) {
  25343. return box.min.equals( this.min ) && box.max.equals( this.max );
  25344. }
  25345. } );
  25346. /**
  25347. * @author alteredq / http://alteredqualia.com/
  25348. */
  25349. function ImmediateRenderObject( material ) {
  25350. Object3D.call( this );
  25351. this.material = material;
  25352. this.render = function ( /* renderCallback */ ) {};
  25353. }
  25354. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  25355. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  25356. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  25357. /**
  25358. * @author mrdoob / http://mrdoob.com/
  25359. * @author WestLangley / http://github.com/WestLangley
  25360. */
  25361. function VertexNormalsHelper( object, size, hex, linewidth ) {
  25362. this.object = object;
  25363. this.size = ( size !== undefined ) ? size : 1;
  25364. var color = ( hex !== undefined ) ? hex : 0xff0000;
  25365. var width = ( linewidth !== undefined ) ? linewidth : 1;
  25366. //
  25367. var nNormals = 0;
  25368. var objGeometry = this.object.geometry;
  25369. if ( objGeometry && objGeometry.isGeometry ) {
  25370. nNormals = objGeometry.faces.length * 3;
  25371. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  25372. nNormals = objGeometry.attributes.normal.count;
  25373. }
  25374. //
  25375. var geometry = new BufferGeometry();
  25376. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  25377. geometry.addAttribute( 'position', positions );
  25378. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  25379. //
  25380. this.matrixAutoUpdate = false;
  25381. this.update();
  25382. }
  25383. VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
  25384. VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
  25385. VertexNormalsHelper.prototype.update = ( function () {
  25386. var v1 = new Vector3();
  25387. var v2 = new Vector3();
  25388. var normalMatrix = new Matrix3();
  25389. return function update() {
  25390. var keys = [ 'a', 'b', 'c' ];
  25391. this.object.updateMatrixWorld( true );
  25392. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  25393. var matrixWorld = this.object.matrixWorld;
  25394. var position = this.geometry.attributes.position;
  25395. //
  25396. var objGeometry = this.object.geometry;
  25397. if ( objGeometry && objGeometry.isGeometry ) {
  25398. var vertices = objGeometry.vertices;
  25399. var faces = objGeometry.faces;
  25400. var idx = 0;
  25401. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  25402. var face = faces[ i ];
  25403. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  25404. var vertex = vertices[ face[ keys[ j ] ] ];
  25405. var normal = face.vertexNormals[ j ];
  25406. v1.copy( vertex ).applyMatrix4( matrixWorld );
  25407. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  25408. position.setXYZ( idx, v1.x, v1.y, v1.z );
  25409. idx = idx + 1;
  25410. position.setXYZ( idx, v2.x, v2.y, v2.z );
  25411. idx = idx + 1;
  25412. }
  25413. }
  25414. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  25415. var objPos = objGeometry.attributes.position;
  25416. var objNorm = objGeometry.attributes.normal;
  25417. var idx = 0;
  25418. // for simplicity, ignore index and drawcalls, and render every normal
  25419. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  25420. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  25421. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  25422. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  25423. position.setXYZ( idx, v1.x, v1.y, v1.z );
  25424. idx = idx + 1;
  25425. position.setXYZ( idx, v2.x, v2.y, v2.z );
  25426. idx = idx + 1;
  25427. }
  25428. }
  25429. position.needsUpdate = true;
  25430. };
  25431. }() );
  25432. /**
  25433. * @author alteredq / http://alteredqualia.com/
  25434. * @author mrdoob / http://mrdoob.com/
  25435. * @author WestLangley / http://github.com/WestLangley
  25436. */
  25437. function SpotLightHelper( light, color ) {
  25438. Object3D.call( this );
  25439. this.light = light;
  25440. this.light.updateMatrixWorld();
  25441. this.matrix = light.matrixWorld;
  25442. this.matrixAutoUpdate = false;
  25443. this.color = color;
  25444. var geometry = new BufferGeometry();
  25445. var positions = [
  25446. 0, 0, 0, 0, 0, 1,
  25447. 0, 0, 0, 1, 0, 1,
  25448. 0, 0, 0, - 1, 0, 1,
  25449. 0, 0, 0, 0, 1, 1,
  25450. 0, 0, 0, 0, - 1, 1
  25451. ];
  25452. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  25453. var p1 = ( i / l ) * Math.PI * 2;
  25454. var p2 = ( j / l ) * Math.PI * 2;
  25455. positions.push(
  25456. Math.cos( p1 ), Math.sin( p1 ), 1,
  25457. Math.cos( p2 ), Math.sin( p2 ), 1
  25458. );
  25459. }
  25460. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  25461. var material = new LineBasicMaterial( { fog: false } );
  25462. this.cone = new LineSegments( geometry, material );
  25463. this.add( this.cone );
  25464. this.update();
  25465. }
  25466. SpotLightHelper.prototype = Object.create( Object3D.prototype );
  25467. SpotLightHelper.prototype.constructor = SpotLightHelper;
  25468. SpotLightHelper.prototype.dispose = function () {
  25469. this.cone.geometry.dispose();
  25470. this.cone.material.dispose();
  25471. };
  25472. SpotLightHelper.prototype.update = function () {
  25473. var vector = new Vector3();
  25474. var vector2 = new Vector3();
  25475. return function update() {
  25476. this.light.updateMatrixWorld();
  25477. var coneLength = this.light.distance ? this.light.distance : 1000;
  25478. var coneWidth = coneLength * Math.tan( this.light.angle );
  25479. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  25480. vector.setFromMatrixPosition( this.light.matrixWorld );
  25481. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  25482. this.cone.lookAt( vector2.sub( vector ) );
  25483. if ( this.color !== undefined ) {
  25484. this.cone.material.color.set( this.color );
  25485. } else {
  25486. this.cone.material.color.copy( this.light.color );
  25487. }
  25488. };
  25489. }();
  25490. /**
  25491. * @author Sean Griffin / http://twitter.com/sgrif
  25492. * @author Michael Guerrero / http://realitymeltdown.com
  25493. * @author mrdoob / http://mrdoob.com/
  25494. * @author ikerr / http://verold.com
  25495. * @author Mugen87 / https://github.com/Mugen87
  25496. */
  25497. function getBoneList( object ) {
  25498. var boneList = [];
  25499. if ( object && object.isBone ) {
  25500. boneList.push( object );
  25501. }
  25502. for ( var i = 0; i < object.children.length; i ++ ) {
  25503. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  25504. }
  25505. return boneList;
  25506. }
  25507. function SkeletonHelper( object ) {
  25508. var bones = getBoneList( object );
  25509. var geometry = new BufferGeometry();
  25510. var vertices = [];
  25511. var colors = [];
  25512. var color1 = new Color( 0, 0, 1 );
  25513. var color2 = new Color( 0, 1, 0 );
  25514. for ( var i = 0; i < bones.length; i ++ ) {
  25515. var bone = bones[ i ];
  25516. if ( bone.parent && bone.parent.isBone ) {
  25517. vertices.push( 0, 0, 0 );
  25518. vertices.push( 0, 0, 0 );
  25519. colors.push( color1.r, color1.g, color1.b );
  25520. colors.push( color2.r, color2.g, color2.b );
  25521. }
  25522. }
  25523. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  25524. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  25525. var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  25526. LineSegments.call( this, geometry, material );
  25527. this.root = object;
  25528. this.bones = bones;
  25529. this.matrix = object.matrixWorld;
  25530. this.matrixAutoUpdate = false;
  25531. }
  25532. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  25533. SkeletonHelper.prototype.constructor = SkeletonHelper;
  25534. SkeletonHelper.prototype.updateMatrixWorld = function () {
  25535. var vector = new Vector3();
  25536. var boneMatrix = new Matrix4();
  25537. var matrixWorldInv = new Matrix4();
  25538. return function updateMatrixWorld( force ) {
  25539. var bones = this.bones;
  25540. var geometry = this.geometry;
  25541. var position = geometry.getAttribute( 'position' );
  25542. matrixWorldInv.getInverse( this.root.matrixWorld );
  25543. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  25544. var bone = bones[ i ];
  25545. if ( bone.parent && bone.parent.isBone ) {
  25546. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  25547. vector.setFromMatrixPosition( boneMatrix );
  25548. position.setXYZ( j, vector.x, vector.y, vector.z );
  25549. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  25550. vector.setFromMatrixPosition( boneMatrix );
  25551. position.setXYZ( j + 1, vector.x, vector.y, vector.z );
  25552. j += 2;
  25553. }
  25554. }
  25555. geometry.getAttribute( 'position' ).needsUpdate = true;
  25556. Object3D.prototype.updateMatrixWorld.call( this, force );
  25557. };
  25558. }();
  25559. /**
  25560. * @author alteredq / http://alteredqualia.com/
  25561. * @author mrdoob / http://mrdoob.com/
  25562. */
  25563. function PointLightHelper( light, sphereSize, color ) {
  25564. this.light = light;
  25565. this.light.updateMatrixWorld();
  25566. this.color = color;
  25567. var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  25568. var material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  25569. Mesh.call( this, geometry, material );
  25570. this.matrix = this.light.matrixWorld;
  25571. this.matrixAutoUpdate = false;
  25572. this.update();
  25573. /*
  25574. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  25575. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  25576. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  25577. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  25578. var d = light.distance;
  25579. if ( d === 0.0 ) {
  25580. this.lightDistance.visible = false;
  25581. } else {
  25582. this.lightDistance.scale.set( d, d, d );
  25583. }
  25584. this.add( this.lightDistance );
  25585. */
  25586. }
  25587. PointLightHelper.prototype = Object.create( Mesh.prototype );
  25588. PointLightHelper.prototype.constructor = PointLightHelper;
  25589. PointLightHelper.prototype.dispose = function () {
  25590. this.geometry.dispose();
  25591. this.material.dispose();
  25592. };
  25593. PointLightHelper.prototype.update = function () {
  25594. if ( this.color !== undefined ) {
  25595. this.material.color.set( this.color );
  25596. } else {
  25597. this.material.color.copy( this.light.color );
  25598. }
  25599. /*
  25600. var d = this.light.distance;
  25601. if ( d === 0.0 ) {
  25602. this.lightDistance.visible = false;
  25603. } else {
  25604. this.lightDistance.visible = true;
  25605. this.lightDistance.scale.set( d, d, d );
  25606. }
  25607. */
  25608. };
  25609. /**
  25610. * @author abelnation / http://github.com/abelnation
  25611. * @author Mugen87 / http://github.com/Mugen87
  25612. * @author WestLangley / http://github.com/WestLangley
  25613. */
  25614. function RectAreaLightHelper( light, color ) {
  25615. Object3D.call( this );
  25616. this.light = light;
  25617. this.light.updateMatrixWorld();
  25618. this.matrix = light.matrixWorld;
  25619. this.matrixAutoUpdate = false;
  25620. this.color = color;
  25621. var material = new LineBasicMaterial( { fog: false } );
  25622. var geometry = new BufferGeometry();
  25623. geometry.addAttribute( 'position', new BufferAttribute( new Float32Array( 5 * 3 ), 3 ) );
  25624. this.line = new Line( geometry, material );
  25625. this.add( this.line );
  25626. this.update();
  25627. }
  25628. RectAreaLightHelper.prototype = Object.create( Object3D.prototype );
  25629. RectAreaLightHelper.prototype.constructor = RectAreaLightHelper;
  25630. RectAreaLightHelper.prototype.dispose = function () {
  25631. this.children[ 0 ].geometry.dispose();
  25632. this.children[ 0 ].material.dispose();
  25633. };
  25634. RectAreaLightHelper.prototype.update = function () {
  25635. // calculate new dimensions of the helper
  25636. var hx = this.light.width * 0.5;
  25637. var hy = this.light.height * 0.5;
  25638. var position = this.line.geometry.attributes.position;
  25639. var array = position.array;
  25640. // update vertices
  25641. array[ 0 ] = hx; array[ 1 ] = - hy; array[ 2 ] = 0;
  25642. array[ 3 ] = hx; array[ 4 ] = hy; array[ 5 ] = 0;
  25643. array[ 6 ] = - hx; array[ 7 ] = hy; array[ 8 ] = 0;
  25644. array[ 9 ] = - hx; array[ 10 ] = - hy; array[ 11 ] = 0;
  25645. array[ 12 ] = hx; array[ 13 ] = - hy; array[ 14 ] = 0;
  25646. position.needsUpdate = true;
  25647. if ( this.color !== undefined ) {
  25648. this.line.material.color.set( this.color );
  25649. } else {
  25650. this.line.material.color.copy( this.light.color );
  25651. }
  25652. };
  25653. /**
  25654. * @author alteredq / http://alteredqualia.com/
  25655. * @author mrdoob / http://mrdoob.com/
  25656. * @author Mugen87 / https://github.com/Mugen87
  25657. */
  25658. function HemisphereLightHelper( light, size, color ) {
  25659. Object3D.call( this );
  25660. this.light = light;
  25661. this.light.updateMatrixWorld();
  25662. this.matrix = light.matrixWorld;
  25663. this.matrixAutoUpdate = false;
  25664. this.color = color;
  25665. var geometry = new OctahedronBufferGeometry( size );
  25666. geometry.rotateY( Math.PI * 0.5 );
  25667. this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  25668. if ( this.color === undefined ) this.material.vertexColors = VertexColors;
  25669. var position = geometry.getAttribute( 'position' );
  25670. var colors = new Float32Array( position.count * 3 );
  25671. geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
  25672. this.add( new Mesh( geometry, this.material ) );
  25673. this.update();
  25674. }
  25675. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  25676. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  25677. HemisphereLightHelper.prototype.dispose = function () {
  25678. this.children[ 0 ].geometry.dispose();
  25679. this.children[ 0 ].material.dispose();
  25680. };
  25681. HemisphereLightHelper.prototype.update = function () {
  25682. var vector = new Vector3();
  25683. var color1 = new Color();
  25684. var color2 = new Color();
  25685. return function update() {
  25686. var mesh = this.children[ 0 ];
  25687. if ( this.color !== undefined ) {
  25688. this.material.color.set( this.color );
  25689. } else {
  25690. var colors = mesh.geometry.getAttribute( 'color' );
  25691. color1.copy( this.light.color );
  25692. color2.copy( this.light.groundColor );
  25693. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  25694. var color = ( i < ( l / 2 ) ) ? color1 : color2;
  25695. colors.setXYZ( i, color.r, color.g, color.b );
  25696. }
  25697. colors.needsUpdate = true;
  25698. }
  25699. mesh.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  25700. };
  25701. }();
  25702. /**
  25703. * @author mrdoob / http://mrdoob.com/
  25704. */
  25705. function GridHelper( size, divisions, color1, color2 ) {
  25706. size = size || 10;
  25707. divisions = divisions || 10;
  25708. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  25709. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  25710. var center = divisions / 2;
  25711. var step = size / divisions;
  25712. var halfSize = size / 2;
  25713. var vertices = [], colors = [];
  25714. for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  25715. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  25716. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  25717. var color = i === center ? color1 : color2;
  25718. color.toArray( colors, j ); j += 3;
  25719. color.toArray( colors, j ); j += 3;
  25720. color.toArray( colors, j ); j += 3;
  25721. color.toArray( colors, j ); j += 3;
  25722. }
  25723. var geometry = new BufferGeometry();
  25724. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  25725. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  25726. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  25727. LineSegments.call( this, geometry, material );
  25728. }
  25729. GridHelper.prototype = Object.create( LineSegments.prototype );
  25730. GridHelper.prototype.constructor = GridHelper;
  25731. /**
  25732. * @author mrdoob / http://mrdoob.com/
  25733. * @author Mugen87 / http://github.com/Mugen87
  25734. * @author Hectate / http://www.github.com/Hectate
  25735. */
  25736. function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
  25737. radius = radius || 10;
  25738. radials = radials || 16;
  25739. circles = circles || 8;
  25740. divisions = divisions || 64;
  25741. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  25742. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  25743. var vertices = [];
  25744. var colors = [];
  25745. var x, z;
  25746. var v, i, j, r, color;
  25747. // create the radials
  25748. for ( i = 0; i <= radials; i ++ ) {
  25749. v = ( i / radials ) * ( Math.PI * 2 );
  25750. x = Math.sin( v ) * radius;
  25751. z = Math.cos( v ) * radius;
  25752. vertices.push( 0, 0, 0 );
  25753. vertices.push( x, 0, z );
  25754. color = ( i & 1 ) ? color1 : color2;
  25755. colors.push( color.r, color.g, color.b );
  25756. colors.push( color.r, color.g, color.b );
  25757. }
  25758. // create the circles
  25759. for ( i = 0; i <= circles; i ++ ) {
  25760. color = ( i & 1 ) ? color1 : color2;
  25761. r = radius - ( radius / circles * i );
  25762. for ( j = 0; j < divisions; j ++ ) {
  25763. // first vertex
  25764. v = ( j / divisions ) * ( Math.PI * 2 );
  25765. x = Math.sin( v ) * r;
  25766. z = Math.cos( v ) * r;
  25767. vertices.push( x, 0, z );
  25768. colors.push( color.r, color.g, color.b );
  25769. // second vertex
  25770. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  25771. x = Math.sin( v ) * r;
  25772. z = Math.cos( v ) * r;
  25773. vertices.push( x, 0, z );
  25774. colors.push( color.r, color.g, color.b );
  25775. }
  25776. }
  25777. var geometry = new BufferGeometry();
  25778. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  25779. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  25780. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  25781. LineSegments.call( this, geometry, material );
  25782. }
  25783. PolarGridHelper.prototype = Object.create( LineSegments.prototype );
  25784. PolarGridHelper.prototype.constructor = PolarGridHelper;
  25785. /**
  25786. * @author mrdoob / http://mrdoob.com/
  25787. * @author WestLangley / http://github.com/WestLangley
  25788. */
  25789. function FaceNormalsHelper( object, size, hex, linewidth ) {
  25790. // FaceNormalsHelper only supports THREE.Geometry
  25791. this.object = object;
  25792. this.size = ( size !== undefined ) ? size : 1;
  25793. var color = ( hex !== undefined ) ? hex : 0xffff00;
  25794. var width = ( linewidth !== undefined ) ? linewidth : 1;
  25795. //
  25796. var nNormals = 0;
  25797. var objGeometry = this.object.geometry;
  25798. if ( objGeometry && objGeometry.isGeometry ) {
  25799. nNormals = objGeometry.faces.length;
  25800. } else {
  25801. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  25802. }
  25803. //
  25804. var geometry = new BufferGeometry();
  25805. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  25806. geometry.addAttribute( 'position', positions );
  25807. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  25808. //
  25809. this.matrixAutoUpdate = false;
  25810. this.update();
  25811. }
  25812. FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
  25813. FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
  25814. FaceNormalsHelper.prototype.update = ( function () {
  25815. var v1 = new Vector3();
  25816. var v2 = new Vector3();
  25817. var normalMatrix = new Matrix3();
  25818. return function update() {
  25819. this.object.updateMatrixWorld( true );
  25820. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  25821. var matrixWorld = this.object.matrixWorld;
  25822. var position = this.geometry.attributes.position;
  25823. //
  25824. var objGeometry = this.object.geometry;
  25825. var vertices = objGeometry.vertices;
  25826. var faces = objGeometry.faces;
  25827. var idx = 0;
  25828. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  25829. var face = faces[ i ];
  25830. var normal = face.normal;
  25831. v1.copy( vertices[ face.a ] )
  25832. .add( vertices[ face.b ] )
  25833. .add( vertices[ face.c ] )
  25834. .divideScalar( 3 )
  25835. .applyMatrix4( matrixWorld );
  25836. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  25837. position.setXYZ( idx, v1.x, v1.y, v1.z );
  25838. idx = idx + 1;
  25839. position.setXYZ( idx, v2.x, v2.y, v2.z );
  25840. idx = idx + 1;
  25841. }
  25842. position.needsUpdate = true;
  25843. };
  25844. }() );
  25845. /**
  25846. * @author alteredq / http://alteredqualia.com/
  25847. * @author mrdoob / http://mrdoob.com/
  25848. * @author WestLangley / http://github.com/WestLangley
  25849. */
  25850. function DirectionalLightHelper( light, size, color ) {
  25851. Object3D.call( this );
  25852. this.light = light;
  25853. this.light.updateMatrixWorld();
  25854. this.matrix = light.matrixWorld;
  25855. this.matrixAutoUpdate = false;
  25856. this.color = color;
  25857. if ( size === undefined ) size = 1;
  25858. var geometry = new BufferGeometry();
  25859. geometry.addAttribute( 'position', new Float32BufferAttribute( [
  25860. - size, size, 0,
  25861. size, size, 0,
  25862. size, - size, 0,
  25863. - size, - size, 0,
  25864. - size, size, 0
  25865. ], 3 ) );
  25866. var material = new LineBasicMaterial( { fog: false } );
  25867. this.lightPlane = new Line( geometry, material );
  25868. this.add( this.lightPlane );
  25869. geometry = new BufferGeometry();
  25870. geometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  25871. this.targetLine = new Line( geometry, material );
  25872. this.add( this.targetLine );
  25873. this.update();
  25874. }
  25875. DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
  25876. DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
  25877. DirectionalLightHelper.prototype.dispose = function () {
  25878. this.lightPlane.geometry.dispose();
  25879. this.lightPlane.material.dispose();
  25880. this.targetLine.geometry.dispose();
  25881. this.targetLine.material.dispose();
  25882. };
  25883. DirectionalLightHelper.prototype.update = function () {
  25884. var v1 = new Vector3();
  25885. var v2 = new Vector3();
  25886. var v3 = new Vector3();
  25887. return function update() {
  25888. v1.setFromMatrixPosition( this.light.matrixWorld );
  25889. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  25890. v3.subVectors( v2, v1 );
  25891. this.lightPlane.lookAt( v3 );
  25892. if ( this.color !== undefined ) {
  25893. this.lightPlane.material.color.set( this.color );
  25894. this.targetLine.material.color.set( this.color );
  25895. } else {
  25896. this.lightPlane.material.color.copy( this.light.color );
  25897. this.targetLine.material.color.copy( this.light.color );
  25898. }
  25899. this.targetLine.lookAt( v3 );
  25900. this.targetLine.scale.z = v3.length();
  25901. };
  25902. }();
  25903. /**
  25904. * @author alteredq / http://alteredqualia.com/
  25905. * @author Mugen87 / https://github.com/Mugen87
  25906. *
  25907. * - shows frustum, line of sight and up of the camera
  25908. * - suitable for fast updates
  25909. * - based on frustum visualization in lightgl.js shadowmap example
  25910. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  25911. */
  25912. function CameraHelper( camera ) {
  25913. var geometry = new BufferGeometry();
  25914. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
  25915. var vertices = [];
  25916. var colors = [];
  25917. var pointMap = {};
  25918. // colors
  25919. var colorFrustum = new Color( 0xffaa00 );
  25920. var colorCone = new Color( 0xff0000 );
  25921. var colorUp = new Color( 0x00aaff );
  25922. var colorTarget = new Color( 0xffffff );
  25923. var colorCross = new Color( 0x333333 );
  25924. // near
  25925. addLine( 'n1', 'n2', colorFrustum );
  25926. addLine( 'n2', 'n4', colorFrustum );
  25927. addLine( 'n4', 'n3', colorFrustum );
  25928. addLine( 'n3', 'n1', colorFrustum );
  25929. // far
  25930. addLine( 'f1', 'f2', colorFrustum );
  25931. addLine( 'f2', 'f4', colorFrustum );
  25932. addLine( 'f4', 'f3', colorFrustum );
  25933. addLine( 'f3', 'f1', colorFrustum );
  25934. // sides
  25935. addLine( 'n1', 'f1', colorFrustum );
  25936. addLine( 'n2', 'f2', colorFrustum );
  25937. addLine( 'n3', 'f3', colorFrustum );
  25938. addLine( 'n4', 'f4', colorFrustum );
  25939. // cone
  25940. addLine( 'p', 'n1', colorCone );
  25941. addLine( 'p', 'n2', colorCone );
  25942. addLine( 'p', 'n3', colorCone );
  25943. addLine( 'p', 'n4', colorCone );
  25944. // up
  25945. addLine( 'u1', 'u2', colorUp );
  25946. addLine( 'u2', 'u3', colorUp );
  25947. addLine( 'u3', 'u1', colorUp );
  25948. // target
  25949. addLine( 'c', 't', colorTarget );
  25950. addLine( 'p', 'c', colorCross );
  25951. // cross
  25952. addLine( 'cn1', 'cn2', colorCross );
  25953. addLine( 'cn3', 'cn4', colorCross );
  25954. addLine( 'cf1', 'cf2', colorCross );
  25955. addLine( 'cf3', 'cf4', colorCross );
  25956. function addLine( a, b, color ) {
  25957. addPoint( a, color );
  25958. addPoint( b, color );
  25959. }
  25960. function addPoint( id, color ) {
  25961. vertices.push( 0, 0, 0 );
  25962. colors.push( color.r, color.g, color.b );
  25963. if ( pointMap[ id ] === undefined ) {
  25964. pointMap[ id ] = [];
  25965. }
  25966. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  25967. }
  25968. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  25969. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  25970. LineSegments.call( this, geometry, material );
  25971. this.camera = camera;
  25972. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  25973. this.matrix = camera.matrixWorld;
  25974. this.matrixAutoUpdate = false;
  25975. this.pointMap = pointMap;
  25976. this.update();
  25977. }
  25978. CameraHelper.prototype = Object.create( LineSegments.prototype );
  25979. CameraHelper.prototype.constructor = CameraHelper;
  25980. CameraHelper.prototype.update = function () {
  25981. var geometry, pointMap;
  25982. var vector = new Vector3();
  25983. var camera = new Camera();
  25984. function setPoint( point, x, y, z ) {
  25985. vector.set( x, y, z ).unproject( camera );
  25986. var points = pointMap[ point ];
  25987. if ( points !== undefined ) {
  25988. var position = geometry.getAttribute( 'position' );
  25989. for ( var i = 0, l = points.length; i < l; i ++ ) {
  25990. position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
  25991. }
  25992. }
  25993. }
  25994. return function update() {
  25995. geometry = this.geometry;
  25996. pointMap = this.pointMap;
  25997. var w = 1, h = 1;
  25998. // we need just camera projection matrix
  25999. // world matrix must be identity
  26000. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  26001. // center / target
  26002. setPoint( 'c', 0, 0, - 1 );
  26003. setPoint( 't', 0, 0, 1 );
  26004. // near
  26005. setPoint( 'n1', - w, - h, - 1 );
  26006. setPoint( 'n2', w, - h, - 1 );
  26007. setPoint( 'n3', - w, h, - 1 );
  26008. setPoint( 'n4', w, h, - 1 );
  26009. // far
  26010. setPoint( 'f1', - w, - h, 1 );
  26011. setPoint( 'f2', w, - h, 1 );
  26012. setPoint( 'f3', - w, h, 1 );
  26013. setPoint( 'f4', w, h, 1 );
  26014. // up
  26015. setPoint( 'u1', w * 0.7, h * 1.1, - 1 );
  26016. setPoint( 'u2', - w * 0.7, h * 1.1, - 1 );
  26017. setPoint( 'u3', 0, h * 2, - 1 );
  26018. // cross
  26019. setPoint( 'cf1', - w, 0, 1 );
  26020. setPoint( 'cf2', w, 0, 1 );
  26021. setPoint( 'cf3', 0, - h, 1 );
  26022. setPoint( 'cf4', 0, h, 1 );
  26023. setPoint( 'cn1', - w, 0, - 1 );
  26024. setPoint( 'cn2', w, 0, - 1 );
  26025. setPoint( 'cn3', 0, - h, - 1 );
  26026. setPoint( 'cn4', 0, h, - 1 );
  26027. geometry.getAttribute( 'position' ).needsUpdate = true;
  26028. };
  26029. }();
  26030. /**
  26031. * @author mrdoob / http://mrdoob.com/
  26032. * @author Mugen87 / http://github.com/Mugen87
  26033. */
  26034. function BoxHelper( object, color ) {
  26035. this.object = object;
  26036. if ( color === undefined ) color = 0xffff00;
  26037. 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 ] );
  26038. var positions = new Float32Array( 8 * 3 );
  26039. var geometry = new BufferGeometry();
  26040. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  26041. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  26042. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  26043. this.matrixAutoUpdate = false;
  26044. this.update();
  26045. }
  26046. BoxHelper.prototype = Object.create( LineSegments.prototype );
  26047. BoxHelper.prototype.constructor = BoxHelper;
  26048. BoxHelper.prototype.update = ( function () {
  26049. var box = new Box3();
  26050. return function update( object ) {
  26051. if ( object !== undefined ) {
  26052. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  26053. }
  26054. if ( this.object !== undefined ) {
  26055. box.setFromObject( this.object );
  26056. }
  26057. if ( box.isEmpty() ) return;
  26058. var min = box.min;
  26059. var max = box.max;
  26060. /*
  26061. 5____4
  26062. 1/___0/|
  26063. | 6__|_7
  26064. 2/___3/
  26065. 0: max.x, max.y, max.z
  26066. 1: min.x, max.y, max.z
  26067. 2: min.x, min.y, max.z
  26068. 3: max.x, min.y, max.z
  26069. 4: max.x, max.y, min.z
  26070. 5: min.x, max.y, min.z
  26071. 6: min.x, min.y, min.z
  26072. 7: max.x, min.y, min.z
  26073. */
  26074. var position = this.geometry.attributes.position;
  26075. var array = position.array;
  26076. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  26077. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  26078. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  26079. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  26080. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  26081. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  26082. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  26083. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  26084. position.needsUpdate = true;
  26085. this.geometry.computeBoundingSphere();
  26086. };
  26087. } )();
  26088. BoxHelper.prototype.setFromObject = function ( object ) {
  26089. this.object = object;
  26090. this.update();
  26091. return this;
  26092. };
  26093. /**
  26094. * @author WestLangley / http://github.com/WestLangley
  26095. */
  26096. function Box3Helper( box, hex ) {
  26097. this.type = 'Box3Helper';
  26098. this.box = box;
  26099. var color = ( hex !== undefined ) ? hex : 0xffff00;
  26100. 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 ] );
  26101. 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 ];
  26102. var geometry = new BufferGeometry();
  26103. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  26104. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  26105. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  26106. this.geometry.computeBoundingSphere();
  26107. }
  26108. Box3Helper.prototype = Object.create( LineSegments.prototype );
  26109. Box3Helper.prototype.constructor = Box3Helper;
  26110. Box3Helper.prototype.updateMatrixWorld = function ( force ) {
  26111. var box = this.box;
  26112. if ( box.isEmpty() ) return;
  26113. box.getCenter( this.position );
  26114. box.getSize( this.scale );
  26115. this.scale.multiplyScalar( 0.5 );
  26116. Object3D.prototype.updateMatrixWorld.call( this, force );
  26117. };
  26118. /**
  26119. * @author WestLangley / http://github.com/WestLangley
  26120. */
  26121. function PlaneHelper( plane, size, hex ) {
  26122. this.type = 'PlaneHelper';
  26123. this.plane = plane;
  26124. this.size = ( size === undefined ) ? 1 : size;
  26125. var color = ( hex !== undefined ) ? hex : 0xffff00;
  26126. 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 ];
  26127. var geometry = new BufferGeometry();
  26128. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  26129. geometry.computeBoundingSphere();
  26130. Line.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  26131. //
  26132. var positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  26133. var geometry2 = new BufferGeometry();
  26134. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  26135. geometry2.computeBoundingSphere();
  26136. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false } ) ) );
  26137. }
  26138. PlaneHelper.prototype = Object.create( Line.prototype );
  26139. PlaneHelper.prototype.constructor = PlaneHelper;
  26140. PlaneHelper.prototype.updateMatrixWorld = function ( force ) {
  26141. var scale = - this.plane.constant;
  26142. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  26143. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  26144. this.lookAt( this.plane.normal );
  26145. Object3D.prototype.updateMatrixWorld.call( this, force );
  26146. };
  26147. /**
  26148. * @author WestLangley / http://github.com/WestLangley
  26149. * @author zz85 / http://github.com/zz85
  26150. * @author bhouston / http://clara.io
  26151. *
  26152. * Creates an arrow for visualizing directions
  26153. *
  26154. * Parameters:
  26155. * dir - Vector3
  26156. * origin - Vector3
  26157. * length - Number
  26158. * color - color in hex value
  26159. * headLength - Number
  26160. * headWidth - Number
  26161. */
  26162. var lineGeometry;
  26163. var coneGeometry;
  26164. function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  26165. // dir is assumed to be normalized
  26166. Object3D.call( this );
  26167. if ( color === undefined ) color = 0xffff00;
  26168. if ( length === undefined ) length = 1;
  26169. if ( headLength === undefined ) headLength = 0.2 * length;
  26170. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  26171. if ( lineGeometry === undefined ) {
  26172. lineGeometry = new BufferGeometry();
  26173. lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  26174. coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  26175. coneGeometry.translate( 0, - 0.5, 0 );
  26176. }
  26177. this.position.copy( origin );
  26178. this.line = new Line( lineGeometry, new LineBasicMaterial( { color: color } ) );
  26179. this.line.matrixAutoUpdate = false;
  26180. this.add( this.line );
  26181. this.cone = new Mesh( coneGeometry, new MeshBasicMaterial( { color: color } ) );
  26182. this.cone.matrixAutoUpdate = false;
  26183. this.add( this.cone );
  26184. this.setDirection( dir );
  26185. this.setLength( length, headLength, headWidth );
  26186. }
  26187. ArrowHelper.prototype = Object.create( Object3D.prototype );
  26188. ArrowHelper.prototype.constructor = ArrowHelper;
  26189. ArrowHelper.prototype.setDirection = ( function () {
  26190. var axis = new Vector3();
  26191. var radians;
  26192. return function setDirection( dir ) {
  26193. // dir is assumed to be normalized
  26194. if ( dir.y > 0.99999 ) {
  26195. this.quaternion.set( 0, 0, 0, 1 );
  26196. } else if ( dir.y < - 0.99999 ) {
  26197. this.quaternion.set( 1, 0, 0, 0 );
  26198. } else {
  26199. axis.set( dir.z, 0, - dir.x ).normalize();
  26200. radians = Math.acos( dir.y );
  26201. this.quaternion.setFromAxisAngle( axis, radians );
  26202. }
  26203. };
  26204. }() );
  26205. ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  26206. if ( headLength === undefined ) headLength = 0.2 * length;
  26207. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  26208. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  26209. this.line.updateMatrix();
  26210. this.cone.scale.set( headWidth, headLength, headWidth );
  26211. this.cone.position.y = length;
  26212. this.cone.updateMatrix();
  26213. };
  26214. ArrowHelper.prototype.setColor = function ( color ) {
  26215. this.line.material.color.copy( color );
  26216. this.cone.material.color.copy( color );
  26217. };
  26218. /**
  26219. * @author sroucheray / http://sroucheray.org/
  26220. * @author mrdoob / http://mrdoob.com/
  26221. */
  26222. function AxesHelper( size ) {
  26223. size = size || 1;
  26224. var vertices = [
  26225. 0, 0, 0, size, 0, 0,
  26226. 0, 0, 0, 0, size, 0,
  26227. 0, 0, 0, 0, 0, size
  26228. ];
  26229. var colors = [
  26230. 1, 0, 0, 1, 0.6, 0,
  26231. 0, 1, 0, 0.6, 1, 0,
  26232. 0, 0, 1, 0, 0.6, 1
  26233. ];
  26234. var geometry = new BufferGeometry();
  26235. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26236. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26237. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  26238. LineSegments.call( this, geometry, material );
  26239. }
  26240. AxesHelper.prototype = Object.create( LineSegments.prototype );
  26241. AxesHelper.prototype.constructor = AxesHelper;
  26242. /**
  26243. * @author mrdoob / http://mrdoob.com/
  26244. */
  26245. function Face4( a, b, c, d, normal, color, materialIndex ) {
  26246. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  26247. return new Face3( a, b, c, normal, color, materialIndex );
  26248. }
  26249. var LineStrip = 0;
  26250. var LinePieces = 1;
  26251. function MeshFaceMaterial( materials ) {
  26252. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  26253. return materials;
  26254. }
  26255. function MultiMaterial( materials ) {
  26256. if ( materials === undefined ) materials = [];
  26257. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  26258. materials.isMultiMaterial = true;
  26259. materials.materials = materials;
  26260. materials.clone = function () {
  26261. return materials.slice();
  26262. };
  26263. return materials;
  26264. }
  26265. function PointCloud( geometry, material ) {
  26266. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  26267. return new Points( geometry, material );
  26268. }
  26269. function Particle( material ) {
  26270. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  26271. return new Sprite( material );
  26272. }
  26273. function ParticleSystem( geometry, material ) {
  26274. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  26275. return new Points( geometry, material );
  26276. }
  26277. function PointCloudMaterial( parameters ) {
  26278. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  26279. return new PointsMaterial( parameters );
  26280. }
  26281. function ParticleBasicMaterial( parameters ) {
  26282. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  26283. return new PointsMaterial( parameters );
  26284. }
  26285. function ParticleSystemMaterial( parameters ) {
  26286. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  26287. return new PointsMaterial( parameters );
  26288. }
  26289. function Vertex( x, y, z ) {
  26290. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  26291. return new Vector3( x, y, z );
  26292. }
  26293. //
  26294. function DynamicBufferAttribute( array, itemSize ) {
  26295. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  26296. return new BufferAttribute( array, itemSize ).setDynamic( true );
  26297. }
  26298. function Int8Attribute( array, itemSize ) {
  26299. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  26300. return new Int8BufferAttribute( array, itemSize );
  26301. }
  26302. function Uint8Attribute( array, itemSize ) {
  26303. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  26304. return new Uint8BufferAttribute( array, itemSize );
  26305. }
  26306. function Uint8ClampedAttribute( array, itemSize ) {
  26307. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  26308. return new Uint8ClampedBufferAttribute( array, itemSize );
  26309. }
  26310. function Int16Attribute( array, itemSize ) {
  26311. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  26312. return new Int16BufferAttribute( array, itemSize );
  26313. }
  26314. function Uint16Attribute( array, itemSize ) {
  26315. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  26316. return new Uint16BufferAttribute( array, itemSize );
  26317. }
  26318. function Int32Attribute( array, itemSize ) {
  26319. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  26320. return new Int32BufferAttribute( array, itemSize );
  26321. }
  26322. function Uint32Attribute( array, itemSize ) {
  26323. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  26324. return new Uint32BufferAttribute( array, itemSize );
  26325. }
  26326. function Float32Attribute( array, itemSize ) {
  26327. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  26328. return new Float32BufferAttribute( array, itemSize );
  26329. }
  26330. function Float64Attribute( array, itemSize ) {
  26331. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  26332. return new Float64BufferAttribute( array, itemSize );
  26333. }
  26334. //
  26335. Curve.create = function ( construct, getPoint ) {
  26336. console.log( 'THREE.Curve.create() has been deprecated' );
  26337. construct.prototype = Object.create( Curve.prototype );
  26338. construct.prototype.constructor = construct;
  26339. construct.prototype.getPoint = getPoint;
  26340. return construct;
  26341. };
  26342. //
  26343. Object.assign( CurvePath.prototype, {
  26344. createPointsGeometry: function ( divisions ) {
  26345. console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  26346. // generate geometry from path points (for Line or Points objects)
  26347. var pts = this.getPoints( divisions );
  26348. return this.createGeometry( pts );
  26349. },
  26350. createSpacedPointsGeometry: function ( divisions ) {
  26351. console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  26352. // generate geometry from equidistant sampling along the path
  26353. var pts = this.getSpacedPoints( divisions );
  26354. return this.createGeometry( pts );
  26355. },
  26356. createGeometry: function ( points ) {
  26357. console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  26358. var geometry = new Geometry();
  26359. for ( var i = 0, l = points.length; i < l; i ++ ) {
  26360. var point = points[ i ];
  26361. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  26362. }
  26363. return geometry;
  26364. }
  26365. } );
  26366. //
  26367. Object.assign( Path.prototype, {
  26368. fromPoints: function ( points ) {
  26369. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  26370. this.setFromPoints( points );
  26371. }
  26372. } );
  26373. //
  26374. function ClosedSplineCurve3( points ) {
  26375. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  26376. CatmullRomCurve3.call( this, points );
  26377. this.type = 'catmullrom';
  26378. this.closed = true;
  26379. }
  26380. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  26381. //
  26382. function SplineCurve3( points ) {
  26383. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  26384. CatmullRomCurve3.call( this, points );
  26385. this.type = 'catmullrom';
  26386. }
  26387. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  26388. //
  26389. function Spline( points ) {
  26390. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  26391. CatmullRomCurve3.call( this, points );
  26392. this.type = 'catmullrom';
  26393. }
  26394. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  26395. Object.assign( Spline.prototype, {
  26396. initFromArray: function ( /* a */ ) {
  26397. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  26398. },
  26399. getControlPointsArray: function ( /* optionalTarget */ ) {
  26400. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  26401. },
  26402. reparametrizeByArcLength: function ( /* samplingCoef */ ) {
  26403. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  26404. }
  26405. } );
  26406. //
  26407. function AxisHelper( size ) {
  26408. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  26409. return new AxesHelper( size );
  26410. }
  26411. function BoundingBoxHelper( object, color ) {
  26412. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  26413. return new BoxHelper( object, color );
  26414. }
  26415. function EdgesHelper( object, hex ) {
  26416. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  26417. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  26418. }
  26419. GridHelper.prototype.setColors = function () {
  26420. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  26421. };
  26422. SkeletonHelper.prototype.update = function () {
  26423. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  26424. };
  26425. function WireframeHelper( object, hex ) {
  26426. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  26427. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  26428. }
  26429. //
  26430. Object.assign( Loader.prototype, {
  26431. extractUrlBase: function ( url ) {
  26432. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  26433. return LoaderUtils.extractUrlBase( url );
  26434. }
  26435. } );
  26436. function XHRLoader( manager ) {
  26437. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  26438. return new FileLoader( manager );
  26439. }
  26440. function BinaryTextureLoader( manager ) {
  26441. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  26442. return new DataTextureLoader( manager );
  26443. }
  26444. //
  26445. Object.assign( Box2.prototype, {
  26446. center: function ( optionalTarget ) {
  26447. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  26448. return this.getCenter( optionalTarget );
  26449. },
  26450. empty: function () {
  26451. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  26452. return this.isEmpty();
  26453. },
  26454. isIntersectionBox: function ( box ) {
  26455. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  26456. return this.intersectsBox( box );
  26457. },
  26458. size: function ( optionalTarget ) {
  26459. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  26460. return this.getSize( optionalTarget );
  26461. }
  26462. } );
  26463. Object.assign( Box3.prototype, {
  26464. center: function ( optionalTarget ) {
  26465. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  26466. return this.getCenter( optionalTarget );
  26467. },
  26468. empty: function () {
  26469. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  26470. return this.isEmpty();
  26471. },
  26472. isIntersectionBox: function ( box ) {
  26473. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  26474. return this.intersectsBox( box );
  26475. },
  26476. isIntersectionSphere: function ( sphere ) {
  26477. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  26478. return this.intersectsSphere( sphere );
  26479. },
  26480. size: function ( optionalTarget ) {
  26481. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  26482. return this.getSize( optionalTarget );
  26483. }
  26484. } );
  26485. Line3.prototype.center = function ( optionalTarget ) {
  26486. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  26487. return this.getCenter( optionalTarget );
  26488. };
  26489. Object.assign( _Math, {
  26490. random16: function () {
  26491. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  26492. return Math.random();
  26493. },
  26494. nearestPowerOfTwo: function ( value ) {
  26495. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  26496. return _Math.floorPowerOfTwo( value );
  26497. },
  26498. nextPowerOfTwo: function ( value ) {
  26499. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  26500. return _Math.ceilPowerOfTwo( value );
  26501. }
  26502. } );
  26503. Object.assign( Matrix3.prototype, {
  26504. flattenToArrayOffset: function ( array, offset ) {
  26505. console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  26506. return this.toArray( array, offset );
  26507. },
  26508. multiplyVector3: function ( vector ) {
  26509. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  26510. return vector.applyMatrix3( this );
  26511. },
  26512. multiplyVector3Array: function ( /* a */ ) {
  26513. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  26514. },
  26515. applyToBuffer: function ( buffer /*, offset, length */ ) {
  26516. console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  26517. return this.applyToBufferAttribute( buffer );
  26518. },
  26519. applyToVector3Array: function ( /* array, offset, length */ ) {
  26520. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  26521. }
  26522. } );
  26523. Object.assign( Matrix4.prototype, {
  26524. extractPosition: function ( m ) {
  26525. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  26526. return this.copyPosition( m );
  26527. },
  26528. flattenToArrayOffset: function ( array, offset ) {
  26529. console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  26530. return this.toArray( array, offset );
  26531. },
  26532. getPosition: function () {
  26533. var v1;
  26534. return function getPosition() {
  26535. if ( v1 === undefined ) v1 = new Vector3();
  26536. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  26537. return v1.setFromMatrixColumn( this, 3 );
  26538. };
  26539. }(),
  26540. setRotationFromQuaternion: function ( q ) {
  26541. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  26542. return this.makeRotationFromQuaternion( q );
  26543. },
  26544. multiplyToArray: function () {
  26545. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  26546. },
  26547. multiplyVector3: function ( vector ) {
  26548. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  26549. return vector.applyMatrix4( this );
  26550. },
  26551. multiplyVector4: function ( vector ) {
  26552. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  26553. return vector.applyMatrix4( this );
  26554. },
  26555. multiplyVector3Array: function ( /* a */ ) {
  26556. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  26557. },
  26558. rotateAxis: function ( v ) {
  26559. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  26560. v.transformDirection( this );
  26561. },
  26562. crossVector: function ( vector ) {
  26563. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  26564. return vector.applyMatrix4( this );
  26565. },
  26566. translate: function () {
  26567. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  26568. },
  26569. rotateX: function () {
  26570. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  26571. },
  26572. rotateY: function () {
  26573. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  26574. },
  26575. rotateZ: function () {
  26576. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  26577. },
  26578. rotateByAxis: function () {
  26579. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  26580. },
  26581. applyToBuffer: function ( buffer /*, offset, length */ ) {
  26582. console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  26583. return this.applyToBufferAttribute( buffer );
  26584. },
  26585. applyToVector3Array: function ( /* array, offset, length */ ) {
  26586. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  26587. },
  26588. makeFrustum: function ( left, right, bottom, top, near, far ) {
  26589. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  26590. return this.makePerspective( left, right, top, bottom, near, far );
  26591. }
  26592. } );
  26593. Plane.prototype.isIntersectionLine = function ( line ) {
  26594. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  26595. return this.intersectsLine( line );
  26596. };
  26597. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  26598. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  26599. return vector.applyQuaternion( this );
  26600. };
  26601. Object.assign( Ray.prototype, {
  26602. isIntersectionBox: function ( box ) {
  26603. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  26604. return this.intersectsBox( box );
  26605. },
  26606. isIntersectionPlane: function ( plane ) {
  26607. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  26608. return this.intersectsPlane( plane );
  26609. },
  26610. isIntersectionSphere: function ( sphere ) {
  26611. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  26612. return this.intersectsSphere( sphere );
  26613. }
  26614. } );
  26615. Object.assign( Triangle.prototype, {
  26616. area: function () {
  26617. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  26618. return this.getArea();
  26619. },
  26620. barycoordFromPoint: function ( point, target ) {
  26621. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  26622. return this.getBarycoord( point, target );
  26623. },
  26624. midpoint: function ( target ) {
  26625. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  26626. return this.getMidpoint( target );
  26627. },
  26628. normal: function ( target ) {
  26629. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  26630. return this.getNormal( target );
  26631. },
  26632. plane: function ( target ) {
  26633. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  26634. return this.getPlane( target );
  26635. }
  26636. } );
  26637. Object.assign( Triangle, {
  26638. barycoordFromPoint: function ( point, a, b, c, target ) {
  26639. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  26640. return Triangle.getBarycoord( point, a, b, c, target );
  26641. },
  26642. normal: function ( a, b, c, target ) {
  26643. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  26644. return Triangle.getNormal( a, b, c, target );
  26645. }
  26646. } );
  26647. Object.assign( Shape.prototype, {
  26648. extractAllPoints: function ( divisions ) {
  26649. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  26650. return this.extractPoints( divisions );
  26651. },
  26652. extrude: function ( options ) {
  26653. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  26654. return new ExtrudeGeometry( this, options );
  26655. },
  26656. makeGeometry: function ( options ) {
  26657. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  26658. return new ShapeGeometry( this, options );
  26659. }
  26660. } );
  26661. Object.assign( Vector2.prototype, {
  26662. fromAttribute: function ( attribute, index, offset ) {
  26663. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  26664. return this.fromBufferAttribute( attribute, index, offset );
  26665. },
  26666. distanceToManhattan: function ( v ) {
  26667. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  26668. return this.manhattanDistanceTo( v );
  26669. },
  26670. lengthManhattan: function () {
  26671. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  26672. return this.manhattanLength();
  26673. }
  26674. } );
  26675. Object.assign( Vector3.prototype, {
  26676. setEulerFromRotationMatrix: function () {
  26677. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  26678. },
  26679. setEulerFromQuaternion: function () {
  26680. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  26681. },
  26682. getPositionFromMatrix: function ( m ) {
  26683. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  26684. return this.setFromMatrixPosition( m );
  26685. },
  26686. getScaleFromMatrix: function ( m ) {
  26687. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  26688. return this.setFromMatrixScale( m );
  26689. },
  26690. getColumnFromMatrix: function ( index, matrix ) {
  26691. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  26692. return this.setFromMatrixColumn( matrix, index );
  26693. },
  26694. applyProjection: function ( m ) {
  26695. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  26696. return this.applyMatrix4( m );
  26697. },
  26698. fromAttribute: function ( attribute, index, offset ) {
  26699. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  26700. return this.fromBufferAttribute( attribute, index, offset );
  26701. },
  26702. distanceToManhattan: function ( v ) {
  26703. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  26704. return this.manhattanDistanceTo( v );
  26705. },
  26706. lengthManhattan: function () {
  26707. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  26708. return this.manhattanLength();
  26709. }
  26710. } );
  26711. Object.assign( Vector4.prototype, {
  26712. fromAttribute: function ( attribute, index, offset ) {
  26713. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  26714. return this.fromBufferAttribute( attribute, index, offset );
  26715. },
  26716. lengthManhattan: function () {
  26717. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  26718. return this.manhattanLength();
  26719. }
  26720. } );
  26721. //
  26722. Object.assign( Geometry.prototype, {
  26723. computeTangents: function () {
  26724. console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
  26725. },
  26726. computeLineDistances: function () {
  26727. console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
  26728. }
  26729. } );
  26730. Object.assign( Object3D.prototype, {
  26731. getChildByName: function ( name ) {
  26732. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  26733. return this.getObjectByName( name );
  26734. },
  26735. renderDepth: function () {
  26736. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  26737. },
  26738. translate: function ( distance, axis ) {
  26739. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  26740. return this.translateOnAxis( axis, distance );
  26741. },
  26742. getWorldRotation: function () {
  26743. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  26744. }
  26745. } );
  26746. Object.defineProperties( Object3D.prototype, {
  26747. eulerOrder: {
  26748. get: function () {
  26749. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  26750. return this.rotation.order;
  26751. },
  26752. set: function ( value ) {
  26753. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  26754. this.rotation.order = value;
  26755. }
  26756. },
  26757. useQuaternion: {
  26758. get: function () {
  26759. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  26760. },
  26761. set: function () {
  26762. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  26763. }
  26764. }
  26765. } );
  26766. Object.defineProperties( LOD.prototype, {
  26767. objects: {
  26768. get: function () {
  26769. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  26770. return this.levels;
  26771. }
  26772. }
  26773. } );
  26774. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  26775. get: function () {
  26776. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  26777. },
  26778. set: function () {
  26779. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  26780. }
  26781. } );
  26782. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  26783. get: function () {
  26784. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  26785. return this.arcLengthDivisions;
  26786. },
  26787. set: function ( value ) {
  26788. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  26789. this.arcLengthDivisions = value;
  26790. }
  26791. } );
  26792. //
  26793. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  26794. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  26795. "Use .setFocalLength and .filmGauge for a photographic setup." );
  26796. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  26797. this.setFocalLength( focalLength );
  26798. };
  26799. //
  26800. Object.defineProperties( Light.prototype, {
  26801. onlyShadow: {
  26802. set: function () {
  26803. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  26804. }
  26805. },
  26806. shadowCameraFov: {
  26807. set: function ( value ) {
  26808. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  26809. this.shadow.camera.fov = value;
  26810. }
  26811. },
  26812. shadowCameraLeft: {
  26813. set: function ( value ) {
  26814. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  26815. this.shadow.camera.left = value;
  26816. }
  26817. },
  26818. shadowCameraRight: {
  26819. set: function ( value ) {
  26820. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  26821. this.shadow.camera.right = value;
  26822. }
  26823. },
  26824. shadowCameraTop: {
  26825. set: function ( value ) {
  26826. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  26827. this.shadow.camera.top = value;
  26828. }
  26829. },
  26830. shadowCameraBottom: {
  26831. set: function ( value ) {
  26832. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  26833. this.shadow.camera.bottom = value;
  26834. }
  26835. },
  26836. shadowCameraNear: {
  26837. set: function ( value ) {
  26838. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  26839. this.shadow.camera.near = value;
  26840. }
  26841. },
  26842. shadowCameraFar: {
  26843. set: function ( value ) {
  26844. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  26845. this.shadow.camera.far = value;
  26846. }
  26847. },
  26848. shadowCameraVisible: {
  26849. set: function () {
  26850. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  26851. }
  26852. },
  26853. shadowBias: {
  26854. set: function ( value ) {
  26855. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  26856. this.shadow.bias = value;
  26857. }
  26858. },
  26859. shadowDarkness: {
  26860. set: function () {
  26861. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  26862. }
  26863. },
  26864. shadowMapWidth: {
  26865. set: function ( value ) {
  26866. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  26867. this.shadow.mapSize.width = value;
  26868. }
  26869. },
  26870. shadowMapHeight: {
  26871. set: function ( value ) {
  26872. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  26873. this.shadow.mapSize.height = value;
  26874. }
  26875. }
  26876. } );
  26877. //
  26878. Object.defineProperties( BufferAttribute.prototype, {
  26879. length: {
  26880. get: function () {
  26881. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  26882. return this.array.length;
  26883. }
  26884. },
  26885. copyIndicesArray: function ( /* indices */ ) {
  26886. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  26887. }
  26888. } );
  26889. Object.assign( BufferGeometry.prototype, {
  26890. addIndex: function ( index ) {
  26891. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  26892. this.setIndex( index );
  26893. },
  26894. addDrawCall: function ( start, count, indexOffset ) {
  26895. if ( indexOffset !== undefined ) {
  26896. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  26897. }
  26898. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  26899. this.addGroup( start, count );
  26900. },
  26901. clearDrawCalls: function () {
  26902. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  26903. this.clearGroups();
  26904. },
  26905. computeTangents: function () {
  26906. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  26907. },
  26908. computeOffsets: function () {
  26909. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  26910. }
  26911. } );
  26912. Object.defineProperties( BufferGeometry.prototype, {
  26913. drawcalls: {
  26914. get: function () {
  26915. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  26916. return this.groups;
  26917. }
  26918. },
  26919. offsets: {
  26920. get: function () {
  26921. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  26922. return this.groups;
  26923. }
  26924. }
  26925. } );
  26926. //
  26927. Object.assign( ExtrudeBufferGeometry.prototype, {
  26928. getArrays: function () {
  26929. console.error( 'THREE.ExtrudeBufferGeometry: .getArrays() has been removed.' );
  26930. },
  26931. addShapeList: function () {
  26932. console.error( 'THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.' );
  26933. },
  26934. addShape: function () {
  26935. console.error( 'THREE.ExtrudeBufferGeometry: .addShape() has been removed.' );
  26936. }
  26937. } );
  26938. //
  26939. Object.defineProperties( Uniform.prototype, {
  26940. dynamic: {
  26941. set: function () {
  26942. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  26943. }
  26944. },
  26945. onUpdate: {
  26946. value: function () {
  26947. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  26948. return this;
  26949. }
  26950. }
  26951. } );
  26952. //
  26953. Object.defineProperties( Material.prototype, {
  26954. wrapAround: {
  26955. get: function () {
  26956. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  26957. },
  26958. set: function () {
  26959. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  26960. }
  26961. },
  26962. wrapRGB: {
  26963. get: function () {
  26964. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  26965. return new Color();
  26966. }
  26967. },
  26968. shading: {
  26969. get: function () {
  26970. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  26971. },
  26972. set: function ( value ) {
  26973. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  26974. this.flatShading = ( value === FlatShading );
  26975. }
  26976. }
  26977. } );
  26978. Object.defineProperties( MeshPhongMaterial.prototype, {
  26979. metal: {
  26980. get: function () {
  26981. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  26982. return false;
  26983. },
  26984. set: function () {
  26985. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  26986. }
  26987. }
  26988. } );
  26989. Object.defineProperties( ShaderMaterial.prototype, {
  26990. derivatives: {
  26991. get: function () {
  26992. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  26993. return this.extensions.derivatives;
  26994. },
  26995. set: function ( value ) {
  26996. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  26997. this.extensions.derivatives = value;
  26998. }
  26999. }
  27000. } );
  27001. //
  27002. Object.assign( WebGLRenderer.prototype, {
  27003. getCurrentRenderTarget: function () {
  27004. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  27005. return this.getRenderTarget();
  27006. },
  27007. getMaxAnisotropy: function () {
  27008. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  27009. return this.capabilities.getMaxAnisotropy();
  27010. },
  27011. getPrecision: function () {
  27012. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  27013. return this.capabilities.precision;
  27014. },
  27015. resetGLState: function () {
  27016. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  27017. return this.state.reset();
  27018. },
  27019. supportsFloatTextures: function () {
  27020. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  27021. return this.extensions.get( 'OES_texture_float' );
  27022. },
  27023. supportsHalfFloatTextures: function () {
  27024. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  27025. return this.extensions.get( 'OES_texture_half_float' );
  27026. },
  27027. supportsStandardDerivatives: function () {
  27028. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  27029. return this.extensions.get( 'OES_standard_derivatives' );
  27030. },
  27031. supportsCompressedTextureS3TC: function () {
  27032. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  27033. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  27034. },
  27035. supportsCompressedTexturePVRTC: function () {
  27036. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  27037. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  27038. },
  27039. supportsBlendMinMax: function () {
  27040. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  27041. return this.extensions.get( 'EXT_blend_minmax' );
  27042. },
  27043. supportsVertexTextures: function () {
  27044. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  27045. return this.capabilities.vertexTextures;
  27046. },
  27047. supportsInstancedArrays: function () {
  27048. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  27049. return this.extensions.get( 'ANGLE_instanced_arrays' );
  27050. },
  27051. enableScissorTest: function ( boolean ) {
  27052. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  27053. this.setScissorTest( boolean );
  27054. },
  27055. initMaterial: function () {
  27056. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  27057. },
  27058. addPrePlugin: function () {
  27059. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  27060. },
  27061. addPostPlugin: function () {
  27062. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  27063. },
  27064. updateShadowMap: function () {
  27065. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  27066. },
  27067. setFaceCulling: function () {
  27068. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  27069. }
  27070. } );
  27071. Object.defineProperties( WebGLRenderer.prototype, {
  27072. shadowMapEnabled: {
  27073. get: function () {
  27074. return this.shadowMap.enabled;
  27075. },
  27076. set: function ( value ) {
  27077. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  27078. this.shadowMap.enabled = value;
  27079. }
  27080. },
  27081. shadowMapType: {
  27082. get: function () {
  27083. return this.shadowMap.type;
  27084. },
  27085. set: function ( value ) {
  27086. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  27087. this.shadowMap.type = value;
  27088. }
  27089. },
  27090. shadowMapCullFace: {
  27091. get: function () {
  27092. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  27093. return undefined;
  27094. },
  27095. set: function ( /* value */ ) {
  27096. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  27097. }
  27098. }
  27099. } );
  27100. Object.defineProperties( WebGLShadowMap.prototype, {
  27101. cullFace: {
  27102. get: function () {
  27103. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  27104. return undefined;
  27105. },
  27106. set: function ( /* cullFace */ ) {
  27107. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  27108. }
  27109. },
  27110. renderReverseSided: {
  27111. get: function () {
  27112. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  27113. return undefined;
  27114. },
  27115. set: function () {
  27116. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  27117. }
  27118. },
  27119. renderSingleSided: {
  27120. get: function () {
  27121. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  27122. return undefined;
  27123. },
  27124. set: function () {
  27125. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  27126. }
  27127. }
  27128. } );
  27129. //
  27130. Object.defineProperties( WebGLRenderTarget.prototype, {
  27131. wrapS: {
  27132. get: function () {
  27133. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  27134. return this.texture.wrapS;
  27135. },
  27136. set: function ( value ) {
  27137. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  27138. this.texture.wrapS = value;
  27139. }
  27140. },
  27141. wrapT: {
  27142. get: function () {
  27143. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  27144. return this.texture.wrapT;
  27145. },
  27146. set: function ( value ) {
  27147. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  27148. this.texture.wrapT = value;
  27149. }
  27150. },
  27151. magFilter: {
  27152. get: function () {
  27153. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  27154. return this.texture.magFilter;
  27155. },
  27156. set: function ( value ) {
  27157. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  27158. this.texture.magFilter = value;
  27159. }
  27160. },
  27161. minFilter: {
  27162. get: function () {
  27163. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  27164. return this.texture.minFilter;
  27165. },
  27166. set: function ( value ) {
  27167. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  27168. this.texture.minFilter = value;
  27169. }
  27170. },
  27171. anisotropy: {
  27172. get: function () {
  27173. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  27174. return this.texture.anisotropy;
  27175. },
  27176. set: function ( value ) {
  27177. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  27178. this.texture.anisotropy = value;
  27179. }
  27180. },
  27181. offset: {
  27182. get: function () {
  27183. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  27184. return this.texture.offset;
  27185. },
  27186. set: function ( value ) {
  27187. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  27188. this.texture.offset = value;
  27189. }
  27190. },
  27191. repeat: {
  27192. get: function () {
  27193. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  27194. return this.texture.repeat;
  27195. },
  27196. set: function ( value ) {
  27197. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  27198. this.texture.repeat = value;
  27199. }
  27200. },
  27201. format: {
  27202. get: function () {
  27203. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  27204. return this.texture.format;
  27205. },
  27206. set: function ( value ) {
  27207. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  27208. this.texture.format = value;
  27209. }
  27210. },
  27211. type: {
  27212. get: function () {
  27213. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  27214. return this.texture.type;
  27215. },
  27216. set: function ( value ) {
  27217. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  27218. this.texture.type = value;
  27219. }
  27220. },
  27221. generateMipmaps: {
  27222. get: function () {
  27223. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  27224. return this.texture.generateMipmaps;
  27225. },
  27226. set: function ( value ) {
  27227. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  27228. this.texture.generateMipmaps = value;
  27229. }
  27230. }
  27231. } );
  27232. //
  27233. Object.defineProperties( WebVRManager.prototype, {
  27234. standing: {
  27235. set: function ( /* value */ ) {
  27236. console.warn( 'THREE.WebVRManager: .standing has been removed.' );
  27237. }
  27238. }
  27239. } );
  27240. //
  27241. Audio.prototype.load = function ( file ) {
  27242. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  27243. var scope = this;
  27244. var audioLoader = new AudioLoader();
  27245. audioLoader.load( file, function ( buffer ) {
  27246. scope.setBuffer( buffer );
  27247. } );
  27248. return this;
  27249. };
  27250. AudioAnalyser.prototype.getData = function () {
  27251. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  27252. return this.getFrequencyData();
  27253. };
  27254. //
  27255. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  27256. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  27257. return this.update( renderer, scene );
  27258. };
  27259. //
  27260. var GeometryUtils = {
  27261. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  27262. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  27263. var matrix;
  27264. if ( geometry2.isMesh ) {
  27265. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  27266. matrix = geometry2.matrix;
  27267. geometry2 = geometry2.geometry;
  27268. }
  27269. geometry1.merge( geometry2, matrix, materialIndexOffset );
  27270. },
  27271. center: function ( geometry ) {
  27272. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  27273. return geometry.center();
  27274. }
  27275. };
  27276. var ImageUtils = {
  27277. crossOrigin: undefined,
  27278. loadTexture: function ( url, mapping, onLoad, onError ) {
  27279. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  27280. var loader = new TextureLoader();
  27281. loader.setCrossOrigin( this.crossOrigin );
  27282. var texture = loader.load( url, onLoad, undefined, onError );
  27283. if ( mapping ) texture.mapping = mapping;
  27284. return texture;
  27285. },
  27286. loadTextureCube: function ( urls, mapping, onLoad, onError ) {
  27287. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  27288. var loader = new CubeTextureLoader();
  27289. loader.setCrossOrigin( this.crossOrigin );
  27290. var texture = loader.load( urls, onLoad, undefined, onError );
  27291. if ( mapping ) texture.mapping = mapping;
  27292. return texture;
  27293. },
  27294. loadCompressedTexture: function () {
  27295. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  27296. },
  27297. loadCompressedTextureCube: function () {
  27298. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  27299. }
  27300. };
  27301. //
  27302. function Projector() {
  27303. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  27304. this.projectVector = function ( vector, camera ) {
  27305. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  27306. vector.project( camera );
  27307. };
  27308. this.unprojectVector = function ( vector, camera ) {
  27309. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  27310. vector.unproject( camera );
  27311. };
  27312. this.pickingRay = function () {
  27313. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  27314. };
  27315. }
  27316. //
  27317. function CanvasRenderer() {
  27318. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  27319. this.domElement = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  27320. this.clear = function () {};
  27321. this.render = function () {};
  27322. this.setClearColor = function () {};
  27323. this.setSize = function () {};
  27324. }
  27325. //
  27326. var SceneUtils = {
  27327. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  27328. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  27329. },
  27330. detach: function ( /* child, parent, scene */ ) {
  27331. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  27332. },
  27333. attach: function ( /* child, scene, parent */ ) {
  27334. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  27335. }
  27336. };
  27337. //
  27338. function LensFlare() {
  27339. console.error( 'THREE.LensFlare has been moved to /examples/js/objects/Lensflare.js' );
  27340. }
  27341. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  27342. exports.WebGLRenderTarget = WebGLRenderTarget;
  27343. exports.WebGLRenderer = WebGLRenderer;
  27344. exports.ShaderLib = ShaderLib;
  27345. exports.UniformsLib = UniformsLib;
  27346. exports.UniformsUtils = UniformsUtils;
  27347. exports.ShaderChunk = ShaderChunk;
  27348. exports.FogExp2 = FogExp2;
  27349. exports.Fog = Fog;
  27350. exports.Scene = Scene;
  27351. exports.Sprite = Sprite;
  27352. exports.LOD = LOD;
  27353. exports.SkinnedMesh = SkinnedMesh;
  27354. exports.Skeleton = Skeleton;
  27355. exports.Bone = Bone;
  27356. exports.Mesh = Mesh;
  27357. exports.LineSegments = LineSegments;
  27358. exports.LineLoop = LineLoop;
  27359. exports.Line = Line;
  27360. exports.Points = Points;
  27361. exports.Group = Group;
  27362. exports.VideoTexture = VideoTexture;
  27363. exports.DataTexture = DataTexture;
  27364. exports.CompressedTexture = CompressedTexture;
  27365. exports.CubeTexture = CubeTexture;
  27366. exports.CanvasTexture = CanvasTexture;
  27367. exports.DepthTexture = DepthTexture;
  27368. exports.Texture = Texture;
  27369. exports.CompressedTextureLoader = CompressedTextureLoader;
  27370. exports.DataTextureLoader = DataTextureLoader;
  27371. exports.CubeTextureLoader = CubeTextureLoader;
  27372. exports.TextureLoader = TextureLoader;
  27373. exports.ObjectLoader = ObjectLoader;
  27374. exports.MaterialLoader = MaterialLoader;
  27375. exports.BufferGeometryLoader = BufferGeometryLoader;
  27376. exports.DefaultLoadingManager = DefaultLoadingManager;
  27377. exports.LoadingManager = LoadingManager;
  27378. exports.JSONLoader = JSONLoader;
  27379. exports.ImageLoader = ImageLoader;
  27380. exports.ImageBitmapLoader = ImageBitmapLoader;
  27381. exports.FontLoader = FontLoader;
  27382. exports.FileLoader = FileLoader;
  27383. exports.Loader = Loader;
  27384. exports.LoaderUtils = LoaderUtils;
  27385. exports.Cache = Cache;
  27386. exports.AudioLoader = AudioLoader;
  27387. exports.SpotLightShadow = SpotLightShadow;
  27388. exports.SpotLight = SpotLight;
  27389. exports.PointLight = PointLight;
  27390. exports.RectAreaLight = RectAreaLight;
  27391. exports.HemisphereLight = HemisphereLight;
  27392. exports.DirectionalLightShadow = DirectionalLightShadow;
  27393. exports.DirectionalLight = DirectionalLight;
  27394. exports.AmbientLight = AmbientLight;
  27395. exports.LightShadow = LightShadow;
  27396. exports.Light = Light;
  27397. exports.StereoCamera = StereoCamera;
  27398. exports.PerspectiveCamera = PerspectiveCamera;
  27399. exports.OrthographicCamera = OrthographicCamera;
  27400. exports.CubeCamera = CubeCamera;
  27401. exports.ArrayCamera = ArrayCamera;
  27402. exports.Camera = Camera;
  27403. exports.AudioListener = AudioListener;
  27404. exports.PositionalAudio = PositionalAudio;
  27405. exports.AudioContext = AudioContext;
  27406. exports.AudioAnalyser = AudioAnalyser;
  27407. exports.Audio = Audio;
  27408. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  27409. exports.StringKeyframeTrack = StringKeyframeTrack;
  27410. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  27411. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  27412. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  27413. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  27414. exports.PropertyMixer = PropertyMixer;
  27415. exports.PropertyBinding = PropertyBinding;
  27416. exports.KeyframeTrack = KeyframeTrack;
  27417. exports.AnimationUtils = AnimationUtils;
  27418. exports.AnimationObjectGroup = AnimationObjectGroup;
  27419. exports.AnimationMixer = AnimationMixer;
  27420. exports.AnimationClip = AnimationClip;
  27421. exports.Uniform = Uniform;
  27422. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  27423. exports.BufferGeometry = BufferGeometry;
  27424. exports.Geometry = Geometry;
  27425. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  27426. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  27427. exports.InterleavedBuffer = InterleavedBuffer;
  27428. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  27429. exports.Face3 = Face3;
  27430. exports.Object3D = Object3D;
  27431. exports.Raycaster = Raycaster;
  27432. exports.Layers = Layers;
  27433. exports.EventDispatcher = EventDispatcher;
  27434. exports.Clock = Clock;
  27435. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  27436. exports.LinearInterpolant = LinearInterpolant;
  27437. exports.DiscreteInterpolant = DiscreteInterpolant;
  27438. exports.CubicInterpolant = CubicInterpolant;
  27439. exports.Interpolant = Interpolant;
  27440. exports.Triangle = Triangle;
  27441. exports.Math = _Math;
  27442. exports.Spherical = Spherical;
  27443. exports.Cylindrical = Cylindrical;
  27444. exports.Plane = Plane;
  27445. exports.Frustum = Frustum;
  27446. exports.Sphere = Sphere;
  27447. exports.Ray = Ray;
  27448. exports.Matrix4 = Matrix4;
  27449. exports.Matrix3 = Matrix3;
  27450. exports.Box3 = Box3;
  27451. exports.Box2 = Box2;
  27452. exports.Line3 = Line3;
  27453. exports.Euler = Euler;
  27454. exports.Vector4 = Vector4;
  27455. exports.Vector3 = Vector3;
  27456. exports.Vector2 = Vector2;
  27457. exports.Quaternion = Quaternion;
  27458. exports.Color = Color;
  27459. exports.ImmediateRenderObject = ImmediateRenderObject;
  27460. exports.VertexNormalsHelper = VertexNormalsHelper;
  27461. exports.SpotLightHelper = SpotLightHelper;
  27462. exports.SkeletonHelper = SkeletonHelper;
  27463. exports.PointLightHelper = PointLightHelper;
  27464. exports.RectAreaLightHelper = RectAreaLightHelper;
  27465. exports.HemisphereLightHelper = HemisphereLightHelper;
  27466. exports.GridHelper = GridHelper;
  27467. exports.PolarGridHelper = PolarGridHelper;
  27468. exports.FaceNormalsHelper = FaceNormalsHelper;
  27469. exports.DirectionalLightHelper = DirectionalLightHelper;
  27470. exports.CameraHelper = CameraHelper;
  27471. exports.BoxHelper = BoxHelper;
  27472. exports.Box3Helper = Box3Helper;
  27473. exports.PlaneHelper = PlaneHelper;
  27474. exports.ArrowHelper = ArrowHelper;
  27475. exports.AxesHelper = AxesHelper;
  27476. exports.Shape = Shape;
  27477. exports.Path = Path;
  27478. exports.ShapePath = ShapePath;
  27479. exports.Font = Font;
  27480. exports.CurvePath = CurvePath;
  27481. exports.Curve = Curve;
  27482. exports.ShapeUtils = ShapeUtils;
  27483. exports.WebGLUtils = WebGLUtils;
  27484. exports.WireframeGeometry = WireframeGeometry;
  27485. exports.ParametricGeometry = ParametricGeometry;
  27486. exports.ParametricBufferGeometry = ParametricBufferGeometry;
  27487. exports.TetrahedronGeometry = TetrahedronGeometry;
  27488. exports.TetrahedronBufferGeometry = TetrahedronBufferGeometry;
  27489. exports.OctahedronGeometry = OctahedronGeometry;
  27490. exports.OctahedronBufferGeometry = OctahedronBufferGeometry;
  27491. exports.IcosahedronGeometry = IcosahedronGeometry;
  27492. exports.IcosahedronBufferGeometry = IcosahedronBufferGeometry;
  27493. exports.DodecahedronGeometry = DodecahedronGeometry;
  27494. exports.DodecahedronBufferGeometry = DodecahedronBufferGeometry;
  27495. exports.PolyhedronGeometry = PolyhedronGeometry;
  27496. exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
  27497. exports.TubeGeometry = TubeGeometry;
  27498. exports.TubeBufferGeometry = TubeBufferGeometry;
  27499. exports.TorusKnotGeometry = TorusKnotGeometry;
  27500. exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
  27501. exports.TorusGeometry = TorusGeometry;
  27502. exports.TorusBufferGeometry = TorusBufferGeometry;
  27503. exports.TextGeometry = TextGeometry;
  27504. exports.TextBufferGeometry = TextBufferGeometry;
  27505. exports.SphereGeometry = SphereGeometry;
  27506. exports.SphereBufferGeometry = SphereBufferGeometry;
  27507. exports.RingGeometry = RingGeometry;
  27508. exports.RingBufferGeometry = RingBufferGeometry;
  27509. exports.PlaneGeometry = PlaneGeometry;
  27510. exports.PlaneBufferGeometry = PlaneBufferGeometry;
  27511. exports.LatheGeometry = LatheGeometry;
  27512. exports.LatheBufferGeometry = LatheBufferGeometry;
  27513. exports.ShapeGeometry = ShapeGeometry;
  27514. exports.ShapeBufferGeometry = ShapeBufferGeometry;
  27515. exports.ExtrudeGeometry = ExtrudeGeometry;
  27516. exports.ExtrudeBufferGeometry = ExtrudeBufferGeometry;
  27517. exports.EdgesGeometry = EdgesGeometry;
  27518. exports.ConeGeometry = ConeGeometry;
  27519. exports.ConeBufferGeometry = ConeBufferGeometry;
  27520. exports.CylinderGeometry = CylinderGeometry;
  27521. exports.CylinderBufferGeometry = CylinderBufferGeometry;
  27522. exports.CircleGeometry = CircleGeometry;
  27523. exports.CircleBufferGeometry = CircleBufferGeometry;
  27524. exports.BoxGeometry = BoxGeometry;
  27525. exports.BoxBufferGeometry = BoxBufferGeometry;
  27526. exports.ShadowMaterial = ShadowMaterial;
  27527. exports.SpriteMaterial = SpriteMaterial;
  27528. exports.RawShaderMaterial = RawShaderMaterial;
  27529. exports.ShaderMaterial = ShaderMaterial;
  27530. exports.PointsMaterial = PointsMaterial;
  27531. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  27532. exports.MeshStandardMaterial = MeshStandardMaterial;
  27533. exports.MeshPhongMaterial = MeshPhongMaterial;
  27534. exports.MeshToonMaterial = MeshToonMaterial;
  27535. exports.MeshNormalMaterial = MeshNormalMaterial;
  27536. exports.MeshLambertMaterial = MeshLambertMaterial;
  27537. exports.MeshDepthMaterial = MeshDepthMaterial;
  27538. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  27539. exports.MeshBasicMaterial = MeshBasicMaterial;
  27540. exports.LineDashedMaterial = LineDashedMaterial;
  27541. exports.LineBasicMaterial = LineBasicMaterial;
  27542. exports.Material = Material;
  27543. exports.Float64BufferAttribute = Float64BufferAttribute;
  27544. exports.Float32BufferAttribute = Float32BufferAttribute;
  27545. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  27546. exports.Int32BufferAttribute = Int32BufferAttribute;
  27547. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  27548. exports.Int16BufferAttribute = Int16BufferAttribute;
  27549. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  27550. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  27551. exports.Int8BufferAttribute = Int8BufferAttribute;
  27552. exports.BufferAttribute = BufferAttribute;
  27553. exports.ArcCurve = ArcCurve;
  27554. exports.CatmullRomCurve3 = CatmullRomCurve3;
  27555. exports.CubicBezierCurve = CubicBezierCurve;
  27556. exports.CubicBezierCurve3 = CubicBezierCurve3;
  27557. exports.EllipseCurve = EllipseCurve;
  27558. exports.LineCurve = LineCurve;
  27559. exports.LineCurve3 = LineCurve3;
  27560. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  27561. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  27562. exports.SplineCurve = SplineCurve;
  27563. exports.REVISION = REVISION;
  27564. exports.MOUSE = MOUSE;
  27565. exports.CullFaceNone = CullFaceNone;
  27566. exports.CullFaceBack = CullFaceBack;
  27567. exports.CullFaceFront = CullFaceFront;
  27568. exports.CullFaceFrontBack = CullFaceFrontBack;
  27569. exports.FrontFaceDirectionCW = FrontFaceDirectionCW;
  27570. exports.FrontFaceDirectionCCW = FrontFaceDirectionCCW;
  27571. exports.BasicShadowMap = BasicShadowMap;
  27572. exports.PCFShadowMap = PCFShadowMap;
  27573. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  27574. exports.FrontSide = FrontSide;
  27575. exports.BackSide = BackSide;
  27576. exports.DoubleSide = DoubleSide;
  27577. exports.FlatShading = FlatShading;
  27578. exports.SmoothShading = SmoothShading;
  27579. exports.NoColors = NoColors;
  27580. exports.FaceColors = FaceColors;
  27581. exports.VertexColors = VertexColors;
  27582. exports.NoBlending = NoBlending;
  27583. exports.NormalBlending = NormalBlending;
  27584. exports.AdditiveBlending = AdditiveBlending;
  27585. exports.SubtractiveBlending = SubtractiveBlending;
  27586. exports.MultiplyBlending = MultiplyBlending;
  27587. exports.CustomBlending = CustomBlending;
  27588. exports.AddEquation = AddEquation;
  27589. exports.SubtractEquation = SubtractEquation;
  27590. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  27591. exports.MinEquation = MinEquation;
  27592. exports.MaxEquation = MaxEquation;
  27593. exports.ZeroFactor = ZeroFactor;
  27594. exports.OneFactor = OneFactor;
  27595. exports.SrcColorFactor = SrcColorFactor;
  27596. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  27597. exports.SrcAlphaFactor = SrcAlphaFactor;
  27598. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  27599. exports.DstAlphaFactor = DstAlphaFactor;
  27600. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  27601. exports.DstColorFactor = DstColorFactor;
  27602. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  27603. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  27604. exports.NeverDepth = NeverDepth;
  27605. exports.AlwaysDepth = AlwaysDepth;
  27606. exports.LessDepth = LessDepth;
  27607. exports.LessEqualDepth = LessEqualDepth;
  27608. exports.EqualDepth = EqualDepth;
  27609. exports.GreaterEqualDepth = GreaterEqualDepth;
  27610. exports.GreaterDepth = GreaterDepth;
  27611. exports.NotEqualDepth = NotEqualDepth;
  27612. exports.MultiplyOperation = MultiplyOperation;
  27613. exports.MixOperation = MixOperation;
  27614. exports.AddOperation = AddOperation;
  27615. exports.NoToneMapping = NoToneMapping;
  27616. exports.LinearToneMapping = LinearToneMapping;
  27617. exports.ReinhardToneMapping = ReinhardToneMapping;
  27618. exports.Uncharted2ToneMapping = Uncharted2ToneMapping;
  27619. exports.CineonToneMapping = CineonToneMapping;
  27620. exports.UVMapping = UVMapping;
  27621. exports.CubeReflectionMapping = CubeReflectionMapping;
  27622. exports.CubeRefractionMapping = CubeRefractionMapping;
  27623. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  27624. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  27625. exports.SphericalReflectionMapping = SphericalReflectionMapping;
  27626. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  27627. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  27628. exports.RepeatWrapping = RepeatWrapping;
  27629. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  27630. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  27631. exports.NearestFilter = NearestFilter;
  27632. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  27633. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  27634. exports.LinearFilter = LinearFilter;
  27635. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  27636. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  27637. exports.UnsignedByteType = UnsignedByteType;
  27638. exports.ByteType = ByteType;
  27639. exports.ShortType = ShortType;
  27640. exports.UnsignedShortType = UnsignedShortType;
  27641. exports.IntType = IntType;
  27642. exports.UnsignedIntType = UnsignedIntType;
  27643. exports.FloatType = FloatType;
  27644. exports.HalfFloatType = HalfFloatType;
  27645. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  27646. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  27647. exports.UnsignedShort565Type = UnsignedShort565Type;
  27648. exports.UnsignedInt248Type = UnsignedInt248Type;
  27649. exports.AlphaFormat = AlphaFormat;
  27650. exports.RGBFormat = RGBFormat;
  27651. exports.RGBAFormat = RGBAFormat;
  27652. exports.LuminanceFormat = LuminanceFormat;
  27653. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  27654. exports.RGBEFormat = RGBEFormat;
  27655. exports.DepthFormat = DepthFormat;
  27656. exports.DepthStencilFormat = DepthStencilFormat;
  27657. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  27658. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  27659. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  27660. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  27661. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  27662. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  27663. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  27664. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  27665. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  27666. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  27667. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  27668. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  27669. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  27670. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  27671. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  27672. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  27673. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  27674. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  27675. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  27676. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  27677. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  27678. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  27679. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  27680. exports.LoopOnce = LoopOnce;
  27681. exports.LoopRepeat = LoopRepeat;
  27682. exports.LoopPingPong = LoopPingPong;
  27683. exports.InterpolateDiscrete = InterpolateDiscrete;
  27684. exports.InterpolateLinear = InterpolateLinear;
  27685. exports.InterpolateSmooth = InterpolateSmooth;
  27686. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  27687. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  27688. exports.WrapAroundEnding = WrapAroundEnding;
  27689. exports.TrianglesDrawMode = TrianglesDrawMode;
  27690. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  27691. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  27692. exports.LinearEncoding = LinearEncoding;
  27693. exports.sRGBEncoding = sRGBEncoding;
  27694. exports.GammaEncoding = GammaEncoding;
  27695. exports.RGBEEncoding = RGBEEncoding;
  27696. exports.LogLuvEncoding = LogLuvEncoding;
  27697. exports.RGBM7Encoding = RGBM7Encoding;
  27698. exports.RGBM16Encoding = RGBM16Encoding;
  27699. exports.RGBDEncoding = RGBDEncoding;
  27700. exports.BasicDepthPacking = BasicDepthPacking;
  27701. exports.RGBADepthPacking = RGBADepthPacking;
  27702. exports.CubeGeometry = BoxGeometry;
  27703. exports.Face4 = Face4;
  27704. exports.LineStrip = LineStrip;
  27705. exports.LinePieces = LinePieces;
  27706. exports.MeshFaceMaterial = MeshFaceMaterial;
  27707. exports.MultiMaterial = MultiMaterial;
  27708. exports.PointCloud = PointCloud;
  27709. exports.Particle = Particle;
  27710. exports.ParticleSystem = ParticleSystem;
  27711. exports.PointCloudMaterial = PointCloudMaterial;
  27712. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  27713. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  27714. exports.Vertex = Vertex;
  27715. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  27716. exports.Int8Attribute = Int8Attribute;
  27717. exports.Uint8Attribute = Uint8Attribute;
  27718. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  27719. exports.Int16Attribute = Int16Attribute;
  27720. exports.Uint16Attribute = Uint16Attribute;
  27721. exports.Int32Attribute = Int32Attribute;
  27722. exports.Uint32Attribute = Uint32Attribute;
  27723. exports.Float32Attribute = Float32Attribute;
  27724. exports.Float64Attribute = Float64Attribute;
  27725. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  27726. exports.SplineCurve3 = SplineCurve3;
  27727. exports.Spline = Spline;
  27728. exports.AxisHelper = AxisHelper;
  27729. exports.BoundingBoxHelper = BoundingBoxHelper;
  27730. exports.EdgesHelper = EdgesHelper;
  27731. exports.WireframeHelper = WireframeHelper;
  27732. exports.XHRLoader = XHRLoader;
  27733. exports.BinaryTextureLoader = BinaryTextureLoader;
  27734. exports.GeometryUtils = GeometryUtils;
  27735. exports.ImageUtils = ImageUtils;
  27736. exports.Projector = Projector;
  27737. exports.CanvasRenderer = CanvasRenderer;
  27738. exports.SceneUtils = SceneUtils;
  27739. exports.LensFlare = LensFlare;
  27740. Object.defineProperty(exports, '__esModule', { value: true });
  27741. })));