three.js 1.0 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (factory((global.THREE = {})));
  5. }(this, (function (exports) { 'use strict';
  6. // Polyfills
  7. if ( Number.EPSILON === undefined ) {
  8. Number.EPSILON = Math.pow( 2, - 52 );
  9. }
  10. if ( Number.isInteger === undefined ) {
  11. // Missing in IE
  12. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  13. Number.isInteger = function ( value ) {
  14. return typeof value === 'number' && isFinite( value ) && Math.floor( value ) === value;
  15. };
  16. }
  17. //
  18. if ( Math.sign === undefined ) {
  19. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  20. Math.sign = function ( x ) {
  21. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  22. };
  23. }
  24. if ( 'name' in Function.prototype === false ) {
  25. // Missing in IE
  26. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  27. Object.defineProperty( Function.prototype, 'name', {
  28. get: function () {
  29. return this.toString().match( /^\s*function\s*([^\(\s]*)/ )[ 1 ];
  30. }
  31. } );
  32. }
  33. if ( Object.assign === undefined ) {
  34. // Missing in IE
  35. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  36. ( function () {
  37. Object.assign = function ( target ) {
  38. if ( target === undefined || target === null ) {
  39. throw new TypeError( 'Cannot convert undefined or null to object' );
  40. }
  41. var output = Object( target );
  42. for ( var index = 1; index < arguments.length; index ++ ) {
  43. var source = arguments[ index ];
  44. if ( source !== undefined && source !== null ) {
  45. for ( var nextKey in source ) {
  46. if ( Object.prototype.hasOwnProperty.call( source, nextKey ) ) {
  47. output[ nextKey ] = source[ nextKey ];
  48. }
  49. }
  50. }
  51. }
  52. return output;
  53. };
  54. } )();
  55. }
  56. /**
  57. * https://github.com/mrdoob/eventdispatcher.js/
  58. */
  59. function EventDispatcher() {}
  60. Object.assign( EventDispatcher.prototype, {
  61. addEventListener: function ( type, listener ) {
  62. if ( this._listeners === undefined ) this._listeners = {};
  63. var listeners = this._listeners;
  64. if ( listeners[ type ] === undefined ) {
  65. listeners[ type ] = [];
  66. }
  67. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  68. listeners[ type ].push( listener );
  69. }
  70. },
  71. hasEventListener: function ( type, listener ) {
  72. if ( this._listeners === undefined ) return false;
  73. var listeners = this._listeners;
  74. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  75. },
  76. removeEventListener: function ( type, listener ) {
  77. if ( this._listeners === undefined ) return;
  78. var listeners = this._listeners;
  79. var listenerArray = listeners[ type ];
  80. if ( listenerArray !== undefined ) {
  81. var index = listenerArray.indexOf( listener );
  82. if ( index !== - 1 ) {
  83. listenerArray.splice( index, 1 );
  84. }
  85. }
  86. },
  87. dispatchEvent: function ( event ) {
  88. if ( this._listeners === undefined ) return;
  89. var listeners = this._listeners;
  90. var listenerArray = listeners[ event.type ];
  91. if ( listenerArray !== undefined ) {
  92. event.target = this;
  93. var array = listenerArray.slice( 0 );
  94. for ( var i = 0, l = array.length; i < l; i ++ ) {
  95. array[ i ].call( this, event );
  96. }
  97. }
  98. }
  99. } );
  100. var REVISION = '93dev';
  101. var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  102. var CullFaceNone = 0;
  103. var CullFaceBack = 1;
  104. var CullFaceFront = 2;
  105. var CullFaceFrontBack = 3;
  106. var FrontFaceDirectionCW = 0;
  107. var FrontFaceDirectionCCW = 1;
  108. var BasicShadowMap = 0;
  109. var PCFShadowMap = 1;
  110. var PCFSoftShadowMap = 2;
  111. var FrontSide = 0;
  112. var BackSide = 1;
  113. var DoubleSide = 2;
  114. var FlatShading = 1;
  115. var SmoothShading = 2;
  116. var NoColors = 0;
  117. var FaceColors = 1;
  118. var VertexColors = 2;
  119. var NoBlending = 0;
  120. var NormalBlending = 1;
  121. var AdditiveBlending = 2;
  122. var SubtractiveBlending = 3;
  123. var MultiplyBlending = 4;
  124. var CustomBlending = 5;
  125. var AddEquation = 100;
  126. var SubtractEquation = 101;
  127. var ReverseSubtractEquation = 102;
  128. var MinEquation = 103;
  129. var MaxEquation = 104;
  130. var ZeroFactor = 200;
  131. var OneFactor = 201;
  132. var SrcColorFactor = 202;
  133. var OneMinusSrcColorFactor = 203;
  134. var SrcAlphaFactor = 204;
  135. var OneMinusSrcAlphaFactor = 205;
  136. var DstAlphaFactor = 206;
  137. var OneMinusDstAlphaFactor = 207;
  138. var DstColorFactor = 208;
  139. var OneMinusDstColorFactor = 209;
  140. var SrcAlphaSaturateFactor = 210;
  141. var NeverDepth = 0;
  142. var AlwaysDepth = 1;
  143. var LessDepth = 2;
  144. var LessEqualDepth = 3;
  145. var EqualDepth = 4;
  146. var GreaterEqualDepth = 5;
  147. var GreaterDepth = 6;
  148. var NotEqualDepth = 7;
  149. var MultiplyOperation = 0;
  150. var MixOperation = 1;
  151. var AddOperation = 2;
  152. var NoToneMapping = 0;
  153. var LinearToneMapping = 1;
  154. var ReinhardToneMapping = 2;
  155. var Uncharted2ToneMapping = 3;
  156. var CineonToneMapping = 4;
  157. var UVMapping = 300;
  158. var CubeReflectionMapping = 301;
  159. var CubeRefractionMapping = 302;
  160. var EquirectangularReflectionMapping = 303;
  161. var EquirectangularRefractionMapping = 304;
  162. var SphericalReflectionMapping = 305;
  163. var CubeUVReflectionMapping = 306;
  164. var CubeUVRefractionMapping = 307;
  165. var RepeatWrapping = 1000;
  166. var ClampToEdgeWrapping = 1001;
  167. var MirroredRepeatWrapping = 1002;
  168. var NearestFilter = 1003;
  169. var NearestMipMapNearestFilter = 1004;
  170. var NearestMipMapLinearFilter = 1005;
  171. var LinearFilter = 1006;
  172. var LinearMipMapNearestFilter = 1007;
  173. var LinearMipMapLinearFilter = 1008;
  174. var UnsignedByteType = 1009;
  175. var ByteType = 1010;
  176. var ShortType = 1011;
  177. var UnsignedShortType = 1012;
  178. var IntType = 1013;
  179. var UnsignedIntType = 1014;
  180. var FloatType = 1015;
  181. var HalfFloatType = 1016;
  182. var UnsignedShort4444Type = 1017;
  183. var UnsignedShort5551Type = 1018;
  184. var UnsignedShort565Type = 1019;
  185. var UnsignedInt248Type = 1020;
  186. var AlphaFormat = 1021;
  187. var RGBFormat = 1022;
  188. var RGBAFormat = 1023;
  189. var LuminanceFormat = 1024;
  190. var LuminanceAlphaFormat = 1025;
  191. var RGBEFormat = RGBAFormat;
  192. var DepthFormat = 1026;
  193. var DepthStencilFormat = 1027;
  194. var RGB_S3TC_DXT1_Format = 33776;
  195. var RGBA_S3TC_DXT1_Format = 33777;
  196. var RGBA_S3TC_DXT3_Format = 33778;
  197. var RGBA_S3TC_DXT5_Format = 33779;
  198. var RGB_PVRTC_4BPPV1_Format = 35840;
  199. var RGB_PVRTC_2BPPV1_Format = 35841;
  200. var RGBA_PVRTC_4BPPV1_Format = 35842;
  201. var RGBA_PVRTC_2BPPV1_Format = 35843;
  202. var RGB_ETC1_Format = 36196;
  203. var RGBA_ASTC_4x4_Format = 37808;
  204. var RGBA_ASTC_5x4_Format = 37809;
  205. var RGBA_ASTC_5x5_Format = 37810;
  206. var RGBA_ASTC_6x5_Format = 37811;
  207. var RGBA_ASTC_6x6_Format = 37812;
  208. var RGBA_ASTC_8x5_Format = 37813;
  209. var RGBA_ASTC_8x6_Format = 37814;
  210. var RGBA_ASTC_8x8_Format = 37815;
  211. var RGBA_ASTC_10x5_Format = 37816;
  212. var RGBA_ASTC_10x6_Format = 37817;
  213. var RGBA_ASTC_10x8_Format = 37818;
  214. var RGBA_ASTC_10x10_Format = 37819;
  215. var RGBA_ASTC_12x10_Format = 37820;
  216. var RGBA_ASTC_12x12_Format = 37821;
  217. var LoopOnce = 2200;
  218. var LoopRepeat = 2201;
  219. var LoopPingPong = 2202;
  220. var InterpolateDiscrete = 2300;
  221. var InterpolateLinear = 2301;
  222. var InterpolateSmooth = 2302;
  223. var ZeroCurvatureEnding = 2400;
  224. var ZeroSlopeEnding = 2401;
  225. var WrapAroundEnding = 2402;
  226. var TrianglesDrawMode = 0;
  227. var TriangleStripDrawMode = 1;
  228. var TriangleFanDrawMode = 2;
  229. var LinearEncoding = 3000;
  230. var sRGBEncoding = 3001;
  231. var GammaEncoding = 3007;
  232. var RGBEEncoding = 3002;
  233. var LogLuvEncoding = 3003;
  234. var RGBM7Encoding = 3004;
  235. var RGBM16Encoding = 3005;
  236. var RGBDEncoding = 3006;
  237. var BasicDepthPacking = 3200;
  238. var RGBADepthPacking = 3201;
  239. /**
  240. * @author alteredq / http://alteredqualia.com/
  241. * @author mrdoob / http://mrdoob.com/
  242. */
  243. var _Math = {
  244. DEG2RAD: Math.PI / 180,
  245. RAD2DEG: 180 / Math.PI,
  246. generateUUID: ( function () {
  247. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  248. var lut = [];
  249. for ( var i = 0; i < 256; i ++ ) {
  250. lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
  251. }
  252. return function generateUUID() {
  253. var d0 = Math.random() * 0xffffffff | 0;
  254. var d1 = Math.random() * 0xffffffff | 0;
  255. var d2 = Math.random() * 0xffffffff | 0;
  256. var d3 = Math.random() * 0xffffffff | 0;
  257. var uuid = lut[ d0 & 0xff ] + lut[ d0 >> 8 & 0xff ] + lut[ d0 >> 16 & 0xff ] + lut[ d0 >> 24 & 0xff ] + '-' +
  258. lut[ d1 & 0xff ] + lut[ d1 >> 8 & 0xff ] + '-' + lut[ d1 >> 16 & 0x0f | 0x40 ] + lut[ d1 >> 24 & 0xff ] + '-' +
  259. lut[ d2 & 0x3f | 0x80 ] + lut[ d2 >> 8 & 0xff ] + '-' + lut[ d2 >> 16 & 0xff ] + lut[ d2 >> 24 & 0xff ] +
  260. lut[ d3 & 0xff ] + lut[ d3 >> 8 & 0xff ] + lut[ d3 >> 16 & 0xff ] + lut[ d3 >> 24 & 0xff ];
  261. // .toUpperCase() here flattens concatenated strings to save heap memory space.
  262. return uuid.toUpperCase();
  263. };
  264. } )(),
  265. clamp: function ( value, min, max ) {
  266. return Math.max( min, Math.min( max, value ) );
  267. },
  268. // compute euclidian modulo of m % n
  269. // https://en.wikipedia.org/wiki/Modulo_operation
  270. euclideanModulo: function ( n, m ) {
  271. return ( ( n % m ) + m ) % m;
  272. },
  273. // Linear mapping from range <a1, a2> to range <b1, b2>
  274. mapLinear: function ( x, a1, a2, b1, b2 ) {
  275. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  276. },
  277. // https://en.wikipedia.org/wiki/Linear_interpolation
  278. lerp: function ( x, y, t ) {
  279. return ( 1 - t ) * x + t * y;
  280. },
  281. // http://en.wikipedia.org/wiki/Smoothstep
  282. smoothstep: function ( x, min, max ) {
  283. if ( x <= min ) return 0;
  284. if ( x >= max ) return 1;
  285. x = ( x - min ) / ( max - min );
  286. return x * x * ( 3 - 2 * x );
  287. },
  288. smootherstep: 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 * x * ( x * ( x * 6 - 15 ) + 10 );
  293. },
  294. // Random integer from <low, high> interval
  295. randInt: function ( low, high ) {
  296. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  297. },
  298. // Random float from <low, high> interval
  299. randFloat: function ( low, high ) {
  300. return low + Math.random() * ( high - low );
  301. },
  302. // Random float from <-range/2, range/2> interval
  303. randFloatSpread: function ( range ) {
  304. return range * ( 0.5 - Math.random() );
  305. },
  306. degToRad: function ( degrees ) {
  307. return degrees * _Math.DEG2RAD;
  308. },
  309. radToDeg: function ( radians ) {
  310. return radians * _Math.RAD2DEG;
  311. },
  312. isPowerOfTwo: function ( value ) {
  313. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  314. },
  315. ceilPowerOfTwo: function ( value ) {
  316. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  317. },
  318. floorPowerOfTwo: function ( value ) {
  319. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  320. }
  321. };
  322. /**
  323. * @author mrdoob / http://mrdoob.com/
  324. * @author philogb / http://blog.thejit.org/
  325. * @author egraether / http://egraether.com/
  326. * @author zz85 / http://www.lab4games.net/zz85/blog
  327. */
  328. function Vector2( x, y ) {
  329. this.x = x || 0;
  330. this.y = y || 0;
  331. }
  332. Object.defineProperties( Vector2.prototype, {
  333. "width": {
  334. get: function () {
  335. return this.x;
  336. },
  337. set: function ( value ) {
  338. this.x = value;
  339. }
  340. },
  341. "height": {
  342. get: function () {
  343. return this.y;
  344. },
  345. set: function ( value ) {
  346. this.y = value;
  347. }
  348. }
  349. } );
  350. Object.assign( Vector2.prototype, {
  351. isVector2: true,
  352. set: function ( x, y ) {
  353. this.x = x;
  354. this.y = y;
  355. return this;
  356. },
  357. setScalar: function ( scalar ) {
  358. this.x = scalar;
  359. this.y = scalar;
  360. return this;
  361. },
  362. setX: function ( x ) {
  363. this.x = x;
  364. return this;
  365. },
  366. setY: function ( y ) {
  367. this.y = y;
  368. return this;
  369. },
  370. setComponent: function ( index, value ) {
  371. switch ( index ) {
  372. case 0: this.x = value; break;
  373. case 1: this.y = value; break;
  374. default: throw new Error( 'index is out of range: ' + index );
  375. }
  376. return this;
  377. },
  378. getComponent: function ( index ) {
  379. switch ( index ) {
  380. case 0: return this.x;
  381. case 1: return this.y;
  382. default: throw new Error( 'index is out of range: ' + index );
  383. }
  384. },
  385. clone: function () {
  386. return new this.constructor( this.x, this.y );
  387. },
  388. copy: function ( v ) {
  389. this.x = v.x;
  390. this.y = v.y;
  391. return this;
  392. },
  393. add: function ( v, w ) {
  394. if ( w !== undefined ) {
  395. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  396. return this.addVectors( v, w );
  397. }
  398. this.x += v.x;
  399. this.y += v.y;
  400. return this;
  401. },
  402. addScalar: function ( s ) {
  403. this.x += s;
  404. this.y += s;
  405. return this;
  406. },
  407. addVectors: function ( a, b ) {
  408. this.x = a.x + b.x;
  409. this.y = a.y + b.y;
  410. return this;
  411. },
  412. addScaledVector: function ( v, s ) {
  413. this.x += v.x * s;
  414. this.y += v.y * s;
  415. return this;
  416. },
  417. sub: function ( v, w ) {
  418. if ( w !== undefined ) {
  419. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  420. return this.subVectors( v, w );
  421. }
  422. this.x -= v.x;
  423. this.y -= v.y;
  424. return this;
  425. },
  426. subScalar: function ( s ) {
  427. this.x -= s;
  428. this.y -= s;
  429. return this;
  430. },
  431. subVectors: function ( a, b ) {
  432. this.x = a.x - b.x;
  433. this.y = a.y - b.y;
  434. return this;
  435. },
  436. multiply: function ( v ) {
  437. this.x *= v.x;
  438. this.y *= v.y;
  439. return this;
  440. },
  441. multiplyScalar: function ( scalar ) {
  442. this.x *= scalar;
  443. this.y *= scalar;
  444. return this;
  445. },
  446. divide: function ( v ) {
  447. this.x /= v.x;
  448. this.y /= v.y;
  449. return this;
  450. },
  451. divideScalar: function ( scalar ) {
  452. return this.multiplyScalar( 1 / scalar );
  453. },
  454. applyMatrix3: function ( m ) {
  455. var x = this.x, y = this.y;
  456. var e = m.elements;
  457. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  458. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  459. return this;
  460. },
  461. min: function ( v ) {
  462. this.x = Math.min( this.x, v.x );
  463. this.y = Math.min( this.y, v.y );
  464. return this;
  465. },
  466. max: function ( v ) {
  467. this.x = Math.max( this.x, v.x );
  468. this.y = Math.max( this.y, v.y );
  469. return this;
  470. },
  471. clamp: function ( min, max ) {
  472. // assumes min < max, componentwise
  473. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  474. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  475. return this;
  476. },
  477. clampScalar: function () {
  478. var min = new Vector2();
  479. var max = new Vector2();
  480. return function clampScalar( minVal, maxVal ) {
  481. min.set( minVal, minVal );
  482. max.set( maxVal, maxVal );
  483. return this.clamp( min, max );
  484. };
  485. }(),
  486. clampLength: function ( min, max ) {
  487. var length = this.length();
  488. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  489. },
  490. floor: function () {
  491. this.x = Math.floor( this.x );
  492. this.y = Math.floor( this.y );
  493. return this;
  494. },
  495. ceil: function () {
  496. this.x = Math.ceil( this.x );
  497. this.y = Math.ceil( this.y );
  498. return this;
  499. },
  500. round: function () {
  501. this.x = Math.round( this.x );
  502. this.y = Math.round( this.y );
  503. return this;
  504. },
  505. roundToZero: function () {
  506. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  507. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  508. return this;
  509. },
  510. negate: function () {
  511. this.x = - this.x;
  512. this.y = - this.y;
  513. return this;
  514. },
  515. dot: function ( v ) {
  516. return this.x * v.x + this.y * v.y;
  517. },
  518. lengthSq: function () {
  519. return this.x * this.x + this.y * this.y;
  520. },
  521. length: function () {
  522. return Math.sqrt( this.x * this.x + this.y * this.y );
  523. },
  524. manhattanLength: function () {
  525. return Math.abs( this.x ) + Math.abs( this.y );
  526. },
  527. normalize: function () {
  528. return this.divideScalar( this.length() || 1 );
  529. },
  530. angle: function () {
  531. // computes the angle in radians with respect to the positive x-axis
  532. var angle = Math.atan2( this.y, this.x );
  533. if ( angle < 0 ) angle += 2 * Math.PI;
  534. return angle;
  535. },
  536. distanceTo: function ( v ) {
  537. return Math.sqrt( this.distanceToSquared( v ) );
  538. },
  539. distanceToSquared: function ( v ) {
  540. var dx = this.x - v.x, dy = this.y - v.y;
  541. return dx * dx + dy * dy;
  542. },
  543. manhattanDistanceTo: function ( v ) {
  544. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  545. },
  546. setLength: function ( length ) {
  547. return this.normalize().multiplyScalar( length );
  548. },
  549. lerp: function ( v, alpha ) {
  550. this.x += ( v.x - this.x ) * alpha;
  551. this.y += ( v.y - this.y ) * alpha;
  552. return this;
  553. },
  554. lerpVectors: function ( v1, v2, alpha ) {
  555. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  556. },
  557. equals: function ( v ) {
  558. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  559. },
  560. fromArray: function ( array, offset ) {
  561. if ( offset === undefined ) offset = 0;
  562. this.x = array[ offset ];
  563. this.y = array[ offset + 1 ];
  564. return this;
  565. },
  566. toArray: function ( array, offset ) {
  567. if ( array === undefined ) array = [];
  568. if ( offset === undefined ) offset = 0;
  569. array[ offset ] = this.x;
  570. array[ offset + 1 ] = this.y;
  571. return array;
  572. },
  573. fromBufferAttribute: function ( attribute, index, offset ) {
  574. if ( offset !== undefined ) {
  575. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  576. }
  577. this.x = attribute.getX( index );
  578. this.y = attribute.getY( index );
  579. return this;
  580. },
  581. rotateAround: function ( center, angle ) {
  582. var c = Math.cos( angle ), s = Math.sin( angle );
  583. var x = this.x - center.x;
  584. var y = this.y - center.y;
  585. this.x = x * c - y * s + center.x;
  586. this.y = x * s + y * c + center.y;
  587. return this;
  588. }
  589. } );
  590. /**
  591. * @author mrdoob / http://mrdoob.com/
  592. * @author supereggbert / http://www.paulbrunt.co.uk/
  593. * @author philogb / http://blog.thejit.org/
  594. * @author jordi_ros / http://plattsoft.com
  595. * @author D1plo1d / http://github.com/D1plo1d
  596. * @author alteredq / http://alteredqualia.com/
  597. * @author mikael emtinger / http://gomo.se/
  598. * @author timknip / http://www.floorplanner.com/
  599. * @author bhouston / http://clara.io
  600. * @author WestLangley / http://github.com/WestLangley
  601. */
  602. function Matrix4() {
  603. this.elements = [
  604. 1, 0, 0, 0,
  605. 0, 1, 0, 0,
  606. 0, 0, 1, 0,
  607. 0, 0, 0, 1
  608. ];
  609. if ( arguments.length > 0 ) {
  610. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  611. }
  612. }
  613. Object.assign( Matrix4.prototype, {
  614. isMatrix4: true,
  615. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  616. var te = this.elements;
  617. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  618. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  619. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  620. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  621. return this;
  622. },
  623. identity: function () {
  624. this.set(
  625. 1, 0, 0, 0,
  626. 0, 1, 0, 0,
  627. 0, 0, 1, 0,
  628. 0, 0, 0, 1
  629. );
  630. return this;
  631. },
  632. clone: function () {
  633. return new Matrix4().fromArray( this.elements );
  634. },
  635. copy: function ( m ) {
  636. var te = this.elements;
  637. var me = m.elements;
  638. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  639. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  640. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  641. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  642. return this;
  643. },
  644. copyPosition: function ( m ) {
  645. var te = this.elements, me = m.elements;
  646. te[ 12 ] = me[ 12 ];
  647. te[ 13 ] = me[ 13 ];
  648. te[ 14 ] = me[ 14 ];
  649. return this;
  650. },
  651. extractBasis: function ( xAxis, yAxis, zAxis ) {
  652. xAxis.setFromMatrixColumn( this, 0 );
  653. yAxis.setFromMatrixColumn( this, 1 );
  654. zAxis.setFromMatrixColumn( this, 2 );
  655. return this;
  656. },
  657. makeBasis: function ( xAxis, yAxis, zAxis ) {
  658. this.set(
  659. xAxis.x, yAxis.x, zAxis.x, 0,
  660. xAxis.y, yAxis.y, zAxis.y, 0,
  661. xAxis.z, yAxis.z, zAxis.z, 0,
  662. 0, 0, 0, 1
  663. );
  664. return this;
  665. },
  666. extractRotation: function () {
  667. var v1 = new Vector3();
  668. return function extractRotation( m ) {
  669. var te = this.elements;
  670. var me = m.elements;
  671. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  672. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  673. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  674. te[ 0 ] = me[ 0 ] * scaleX;
  675. te[ 1 ] = me[ 1 ] * scaleX;
  676. te[ 2 ] = me[ 2 ] * scaleX;
  677. te[ 4 ] = me[ 4 ] * scaleY;
  678. te[ 5 ] = me[ 5 ] * scaleY;
  679. te[ 6 ] = me[ 6 ] * scaleY;
  680. te[ 8 ] = me[ 8 ] * scaleZ;
  681. te[ 9 ] = me[ 9 ] * scaleZ;
  682. te[ 10 ] = me[ 10 ] * scaleZ;
  683. return this;
  684. };
  685. }(),
  686. makeRotationFromEuler: function ( euler ) {
  687. if ( ! ( euler && euler.isEuler ) ) {
  688. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  689. }
  690. var te = this.elements;
  691. var x = euler.x, y = euler.y, z = euler.z;
  692. var a = Math.cos( x ), b = Math.sin( x );
  693. var c = Math.cos( y ), d = Math.sin( y );
  694. var e = Math.cos( z ), f = Math.sin( z );
  695. if ( euler.order === 'XYZ' ) {
  696. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  697. te[ 0 ] = c * e;
  698. te[ 4 ] = - c * f;
  699. te[ 8 ] = d;
  700. te[ 1 ] = af + be * d;
  701. te[ 5 ] = ae - bf * d;
  702. te[ 9 ] = - b * c;
  703. te[ 2 ] = bf - ae * d;
  704. te[ 6 ] = be + af * d;
  705. te[ 10 ] = a * c;
  706. } else if ( euler.order === 'YXZ' ) {
  707. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  708. te[ 0 ] = ce + df * b;
  709. te[ 4 ] = de * b - cf;
  710. te[ 8 ] = a * d;
  711. te[ 1 ] = a * f;
  712. te[ 5 ] = a * e;
  713. te[ 9 ] = - b;
  714. te[ 2 ] = cf * b - de;
  715. te[ 6 ] = df + ce * b;
  716. te[ 10 ] = a * c;
  717. } else if ( euler.order === 'ZXY' ) {
  718. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  719. te[ 0 ] = ce - df * b;
  720. te[ 4 ] = - a * f;
  721. te[ 8 ] = de + cf * b;
  722. te[ 1 ] = cf + de * b;
  723. te[ 5 ] = a * e;
  724. te[ 9 ] = df - ce * b;
  725. te[ 2 ] = - a * d;
  726. te[ 6 ] = b;
  727. te[ 10 ] = a * c;
  728. } else if ( euler.order === 'ZYX' ) {
  729. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  730. te[ 0 ] = c * e;
  731. te[ 4 ] = be * d - af;
  732. te[ 8 ] = ae * d + bf;
  733. te[ 1 ] = c * f;
  734. te[ 5 ] = bf * d + ae;
  735. te[ 9 ] = af * d - be;
  736. te[ 2 ] = - d;
  737. te[ 6 ] = b * c;
  738. te[ 10 ] = a * c;
  739. } else if ( euler.order === 'YZX' ) {
  740. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  741. te[ 0 ] = c * e;
  742. te[ 4 ] = bd - ac * f;
  743. te[ 8 ] = bc * f + ad;
  744. te[ 1 ] = f;
  745. te[ 5 ] = a * e;
  746. te[ 9 ] = - b * e;
  747. te[ 2 ] = - d * e;
  748. te[ 6 ] = ad * f + bc;
  749. te[ 10 ] = ac - bd * f;
  750. } else if ( euler.order === 'XZY' ) {
  751. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  752. te[ 0 ] = c * e;
  753. te[ 4 ] = - f;
  754. te[ 8 ] = d * e;
  755. te[ 1 ] = ac * f + bd;
  756. te[ 5 ] = a * e;
  757. te[ 9 ] = ad * f - bc;
  758. te[ 2 ] = bc * f - ad;
  759. te[ 6 ] = b * e;
  760. te[ 10 ] = bd * f + ac;
  761. }
  762. // bottom row
  763. te[ 3 ] = 0;
  764. te[ 7 ] = 0;
  765. te[ 11 ] = 0;
  766. // last column
  767. te[ 12 ] = 0;
  768. te[ 13 ] = 0;
  769. te[ 14 ] = 0;
  770. te[ 15 ] = 1;
  771. return this;
  772. },
  773. makeRotationFromQuaternion: function () {
  774. var zero = new Vector3( 0, 0, 0 );
  775. var one = new Vector3( 1, 1, 1 );
  776. return function makeRotationFromQuaternion( q ) {
  777. return this.compose( zero, q, one );
  778. };
  779. }(),
  780. lookAt: function () {
  781. var x = new Vector3();
  782. var y = new Vector3();
  783. var z = new Vector3();
  784. return function lookAt( eye, target, up ) {
  785. var te = this.elements;
  786. z.subVectors( eye, target );
  787. if ( z.lengthSq() === 0 ) {
  788. // eye and target are in the same position
  789. z.z = 1;
  790. }
  791. z.normalize();
  792. x.crossVectors( up, z );
  793. if ( x.lengthSq() === 0 ) {
  794. // up and z are parallel
  795. if ( Math.abs( up.z ) === 1 ) {
  796. z.x += 0.0001;
  797. } else {
  798. z.z += 0.0001;
  799. }
  800. z.normalize();
  801. x.crossVectors( up, z );
  802. }
  803. x.normalize();
  804. y.crossVectors( z, x );
  805. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  806. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  807. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  808. return this;
  809. };
  810. }(),
  811. multiply: function ( m, n ) {
  812. if ( n !== undefined ) {
  813. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  814. return this.multiplyMatrices( m, n );
  815. }
  816. return this.multiplyMatrices( this, m );
  817. },
  818. premultiply: function ( m ) {
  819. return this.multiplyMatrices( m, this );
  820. },
  821. multiplyMatrices: function ( a, b ) {
  822. var ae = a.elements;
  823. var be = b.elements;
  824. var te = this.elements;
  825. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  826. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  827. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  828. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  829. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  830. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  831. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  832. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  833. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  834. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  835. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  836. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  837. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  838. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  839. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  840. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  841. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  842. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  843. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  844. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  845. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  846. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  847. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  848. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  849. return this;
  850. },
  851. multiplyScalar: function ( s ) {
  852. var te = this.elements;
  853. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  854. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  855. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  856. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  857. return this;
  858. },
  859. applyToBufferAttribute: function () {
  860. var v1 = new Vector3();
  861. return function applyToBufferAttribute( attribute ) {
  862. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  863. v1.x = attribute.getX( i );
  864. v1.y = attribute.getY( i );
  865. v1.z = attribute.getZ( i );
  866. v1.applyMatrix4( this );
  867. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  868. }
  869. return attribute;
  870. };
  871. }(),
  872. determinant: function () {
  873. var te = this.elements;
  874. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  875. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  876. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  877. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  878. //TODO: make this more efficient
  879. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  880. return (
  881. n41 * (
  882. + n14 * n23 * n32
  883. - n13 * n24 * n32
  884. - n14 * n22 * n33
  885. + n12 * n24 * n33
  886. + n13 * n22 * n34
  887. - n12 * n23 * n34
  888. ) +
  889. n42 * (
  890. + n11 * n23 * n34
  891. - n11 * n24 * n33
  892. + n14 * n21 * n33
  893. - n13 * n21 * n34
  894. + n13 * n24 * n31
  895. - n14 * n23 * n31
  896. ) +
  897. n43 * (
  898. + n11 * n24 * n32
  899. - n11 * n22 * n34
  900. - n14 * n21 * n32
  901. + n12 * n21 * n34
  902. + n14 * n22 * n31
  903. - n12 * n24 * n31
  904. ) +
  905. n44 * (
  906. - n13 * n22 * n31
  907. - n11 * n23 * n32
  908. + n11 * n22 * n33
  909. + n13 * n21 * n32
  910. - n12 * n21 * n33
  911. + n12 * n23 * n31
  912. )
  913. );
  914. },
  915. transpose: function () {
  916. var te = this.elements;
  917. var tmp;
  918. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  919. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  920. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  921. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  922. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  923. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  924. return this;
  925. },
  926. setPosition: function ( v ) {
  927. var te = this.elements;
  928. te[ 12 ] = v.x;
  929. te[ 13 ] = v.y;
  930. te[ 14 ] = v.z;
  931. return this;
  932. },
  933. getInverse: function ( m, throwOnDegenerate ) {
  934. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  935. var te = this.elements,
  936. me = m.elements,
  937. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  938. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  939. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  940. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  941. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  942. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  943. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  944. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  945. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  946. if ( det === 0 ) {
  947. var msg = "THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0";
  948. if ( throwOnDegenerate === true ) {
  949. throw new Error( msg );
  950. } else {
  951. console.warn( msg );
  952. }
  953. return this.identity();
  954. }
  955. var detInv = 1 / det;
  956. te[ 0 ] = t11 * detInv;
  957. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  958. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  959. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  960. te[ 4 ] = t12 * detInv;
  961. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  962. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  963. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  964. te[ 8 ] = t13 * detInv;
  965. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  966. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  967. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  968. te[ 12 ] = t14 * detInv;
  969. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  970. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  971. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  972. return this;
  973. },
  974. scale: function ( v ) {
  975. var te = this.elements;
  976. var x = v.x, y = v.y, z = v.z;
  977. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  978. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  979. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  980. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  981. return this;
  982. },
  983. getMaxScaleOnAxis: function () {
  984. var te = this.elements;
  985. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  986. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  987. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  988. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  989. },
  990. makeTranslation: function ( x, y, z ) {
  991. this.set(
  992. 1, 0, 0, x,
  993. 0, 1, 0, y,
  994. 0, 0, 1, z,
  995. 0, 0, 0, 1
  996. );
  997. return this;
  998. },
  999. makeRotationX: function ( theta ) {
  1000. var c = Math.cos( theta ), s = Math.sin( theta );
  1001. this.set(
  1002. 1, 0, 0, 0,
  1003. 0, c, - s, 0,
  1004. 0, s, c, 0,
  1005. 0, 0, 0, 1
  1006. );
  1007. return this;
  1008. },
  1009. makeRotationY: function ( theta ) {
  1010. var c = Math.cos( theta ), s = Math.sin( theta );
  1011. this.set(
  1012. c, 0, s, 0,
  1013. 0, 1, 0, 0,
  1014. - s, 0, c, 0,
  1015. 0, 0, 0, 1
  1016. );
  1017. return this;
  1018. },
  1019. makeRotationZ: function ( theta ) {
  1020. var c = Math.cos( theta ), s = Math.sin( theta );
  1021. this.set(
  1022. c, - s, 0, 0,
  1023. s, c, 0, 0,
  1024. 0, 0, 1, 0,
  1025. 0, 0, 0, 1
  1026. );
  1027. return this;
  1028. },
  1029. makeRotationAxis: function ( axis, angle ) {
  1030. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  1031. var c = Math.cos( angle );
  1032. var s = Math.sin( angle );
  1033. var t = 1 - c;
  1034. var x = axis.x, y = axis.y, z = axis.z;
  1035. var tx = t * x, ty = t * y;
  1036. this.set(
  1037. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  1038. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  1039. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  1040. 0, 0, 0, 1
  1041. );
  1042. return this;
  1043. },
  1044. makeScale: function ( x, y, z ) {
  1045. this.set(
  1046. x, 0, 0, 0,
  1047. 0, y, 0, 0,
  1048. 0, 0, z, 0,
  1049. 0, 0, 0, 1
  1050. );
  1051. return this;
  1052. },
  1053. makeShear: function ( x, y, z ) {
  1054. this.set(
  1055. 1, y, z, 0,
  1056. x, 1, z, 0,
  1057. x, y, 1, 0,
  1058. 0, 0, 0, 1
  1059. );
  1060. return this;
  1061. },
  1062. compose: function ( position, quaternion, scale ) {
  1063. var te = this.elements;
  1064. var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  1065. var x2 = x + x, y2 = y + y, z2 = z + z;
  1066. var xx = x * x2, xy = x * y2, xz = x * z2;
  1067. var yy = y * y2, yz = y * z2, zz = z * z2;
  1068. var wx = w * x2, wy = w * y2, wz = w * z2;
  1069. var sx = scale.x, sy = scale.y, sz = scale.z;
  1070. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  1071. te[ 1 ] = ( xy + wz ) * sx;
  1072. te[ 2 ] = ( xz - wy ) * sx;
  1073. te[ 3 ] = 0;
  1074. te[ 4 ] = ( xy - wz ) * sy;
  1075. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  1076. te[ 6 ] = ( yz + wx ) * sy;
  1077. te[ 7 ] = 0;
  1078. te[ 8 ] = ( xz + wy ) * sz;
  1079. te[ 9 ] = ( yz - wx ) * sz;
  1080. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  1081. te[ 11 ] = 0;
  1082. te[ 12 ] = position.x;
  1083. te[ 13 ] = position.y;
  1084. te[ 14 ] = position.z;
  1085. te[ 15 ] = 1;
  1086. return this;
  1087. },
  1088. decompose: function () {
  1089. var vector = new Vector3();
  1090. var matrix = new Matrix4();
  1091. return function decompose( position, quaternion, scale ) {
  1092. var te = this.elements;
  1093. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  1094. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  1095. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  1096. // if determine is negative, we need to invert one scale
  1097. var det = this.determinant();
  1098. if ( det < 0 ) sx = - sx;
  1099. position.x = te[ 12 ];
  1100. position.y = te[ 13 ];
  1101. position.z = te[ 14 ];
  1102. // scale the rotation part
  1103. matrix.copy( this );
  1104. var invSX = 1 / sx;
  1105. var invSY = 1 / sy;
  1106. var invSZ = 1 / sz;
  1107. matrix.elements[ 0 ] *= invSX;
  1108. matrix.elements[ 1 ] *= invSX;
  1109. matrix.elements[ 2 ] *= invSX;
  1110. matrix.elements[ 4 ] *= invSY;
  1111. matrix.elements[ 5 ] *= invSY;
  1112. matrix.elements[ 6 ] *= invSY;
  1113. matrix.elements[ 8 ] *= invSZ;
  1114. matrix.elements[ 9 ] *= invSZ;
  1115. matrix.elements[ 10 ] *= invSZ;
  1116. quaternion.setFromRotationMatrix( matrix );
  1117. scale.x = sx;
  1118. scale.y = sy;
  1119. scale.z = sz;
  1120. return this;
  1121. };
  1122. }(),
  1123. makePerspective: function ( left, right, top, bottom, near, far ) {
  1124. if ( far === undefined ) {
  1125. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  1126. }
  1127. var te = this.elements;
  1128. var x = 2 * near / ( right - left );
  1129. var y = 2 * near / ( top - bottom );
  1130. var a = ( right + left ) / ( right - left );
  1131. var b = ( top + bottom ) / ( top - bottom );
  1132. var c = - ( far + near ) / ( far - near );
  1133. var d = - 2 * far * near / ( far - near );
  1134. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  1135. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  1136. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  1137. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  1138. return this;
  1139. },
  1140. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  1141. var te = this.elements;
  1142. var w = 1.0 / ( right - left );
  1143. var h = 1.0 / ( top - bottom );
  1144. var p = 1.0 / ( far - near );
  1145. var x = ( right + left ) * w;
  1146. var y = ( top + bottom ) * h;
  1147. var z = ( far + near ) * p;
  1148. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  1149. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  1150. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  1151. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  1152. return this;
  1153. },
  1154. equals: function ( matrix ) {
  1155. var te = this.elements;
  1156. var me = matrix.elements;
  1157. for ( var i = 0; i < 16; i ++ ) {
  1158. if ( te[ i ] !== me[ i ] ) return false;
  1159. }
  1160. return true;
  1161. },
  1162. fromArray: function ( array, offset ) {
  1163. if ( offset === undefined ) offset = 0;
  1164. for ( var i = 0; i < 16; i ++ ) {
  1165. this.elements[ i ] = array[ i + offset ];
  1166. }
  1167. return this;
  1168. },
  1169. toArray: function ( array, offset ) {
  1170. if ( array === undefined ) array = [];
  1171. if ( offset === undefined ) offset = 0;
  1172. var te = this.elements;
  1173. array[ offset ] = te[ 0 ];
  1174. array[ offset + 1 ] = te[ 1 ];
  1175. array[ offset + 2 ] = te[ 2 ];
  1176. array[ offset + 3 ] = te[ 3 ];
  1177. array[ offset + 4 ] = te[ 4 ];
  1178. array[ offset + 5 ] = te[ 5 ];
  1179. array[ offset + 6 ] = te[ 6 ];
  1180. array[ offset + 7 ] = te[ 7 ];
  1181. array[ offset + 8 ] = te[ 8 ];
  1182. array[ offset + 9 ] = te[ 9 ];
  1183. array[ offset + 10 ] = te[ 10 ];
  1184. array[ offset + 11 ] = te[ 11 ];
  1185. array[ offset + 12 ] = te[ 12 ];
  1186. array[ offset + 13 ] = te[ 13 ];
  1187. array[ offset + 14 ] = te[ 14 ];
  1188. array[ offset + 15 ] = te[ 15 ];
  1189. return array;
  1190. }
  1191. } );
  1192. /**
  1193. * @author mikael emtinger / http://gomo.se/
  1194. * @author alteredq / http://alteredqualia.com/
  1195. * @author WestLangley / http://github.com/WestLangley
  1196. * @author bhouston / http://clara.io
  1197. */
  1198. function Quaternion( x, y, z, w ) {
  1199. this._x = x || 0;
  1200. this._y = y || 0;
  1201. this._z = z || 0;
  1202. this._w = ( w !== undefined ) ? w : 1;
  1203. }
  1204. Object.assign( Quaternion, {
  1205. slerp: function ( qa, qb, qm, t ) {
  1206. return qm.copy( qa ).slerp( qb, t );
  1207. },
  1208. slerpFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  1209. // fuzz-free, array-based Quaternion SLERP operation
  1210. var x0 = src0[ srcOffset0 + 0 ],
  1211. y0 = src0[ srcOffset0 + 1 ],
  1212. z0 = src0[ srcOffset0 + 2 ],
  1213. w0 = src0[ srcOffset0 + 3 ],
  1214. x1 = src1[ srcOffset1 + 0 ],
  1215. y1 = src1[ srcOffset1 + 1 ],
  1216. z1 = src1[ srcOffset1 + 2 ],
  1217. w1 = src1[ srcOffset1 + 3 ];
  1218. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  1219. var s = 1 - t,
  1220. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1221. dir = ( cos >= 0 ? 1 : - 1 ),
  1222. sqrSin = 1 - cos * cos;
  1223. // Skip the Slerp for tiny steps to avoid numeric problems:
  1224. if ( sqrSin > Number.EPSILON ) {
  1225. var sin = Math.sqrt( sqrSin ),
  1226. len = Math.atan2( sin, cos * dir );
  1227. s = Math.sin( s * len ) / sin;
  1228. t = Math.sin( t * len ) / sin;
  1229. }
  1230. var tDir = t * dir;
  1231. x0 = x0 * s + x1 * tDir;
  1232. y0 = y0 * s + y1 * tDir;
  1233. z0 = z0 * s + z1 * tDir;
  1234. w0 = w0 * s + w1 * tDir;
  1235. // Normalize in case we just did a lerp:
  1236. if ( s === 1 - t ) {
  1237. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  1238. x0 *= f;
  1239. y0 *= f;
  1240. z0 *= f;
  1241. w0 *= f;
  1242. }
  1243. }
  1244. dst[ dstOffset ] = x0;
  1245. dst[ dstOffset + 1 ] = y0;
  1246. dst[ dstOffset + 2 ] = z0;
  1247. dst[ dstOffset + 3 ] = w0;
  1248. }
  1249. } );
  1250. Object.defineProperties( Quaternion.prototype, {
  1251. x: {
  1252. get: function () {
  1253. return this._x;
  1254. },
  1255. set: function ( value ) {
  1256. this._x = value;
  1257. this.onChangeCallback();
  1258. }
  1259. },
  1260. y: {
  1261. get: function () {
  1262. return this._y;
  1263. },
  1264. set: function ( value ) {
  1265. this._y = value;
  1266. this.onChangeCallback();
  1267. }
  1268. },
  1269. z: {
  1270. get: function () {
  1271. return this._z;
  1272. },
  1273. set: function ( value ) {
  1274. this._z = value;
  1275. this.onChangeCallback();
  1276. }
  1277. },
  1278. w: {
  1279. get: function () {
  1280. return this._w;
  1281. },
  1282. set: function ( value ) {
  1283. this._w = value;
  1284. this.onChangeCallback();
  1285. }
  1286. }
  1287. } );
  1288. Object.assign( Quaternion.prototype, {
  1289. set: function ( x, y, z, w ) {
  1290. this._x = x;
  1291. this._y = y;
  1292. this._z = z;
  1293. this._w = w;
  1294. this.onChangeCallback();
  1295. return this;
  1296. },
  1297. clone: function () {
  1298. return new this.constructor( this._x, this._y, this._z, this._w );
  1299. },
  1300. copy: function ( quaternion ) {
  1301. this._x = quaternion.x;
  1302. this._y = quaternion.y;
  1303. this._z = quaternion.z;
  1304. this._w = quaternion.w;
  1305. this.onChangeCallback();
  1306. return this;
  1307. },
  1308. setFromEuler: function ( euler, update ) {
  1309. if ( ! ( euler && euler.isEuler ) ) {
  1310. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1311. }
  1312. var x = euler._x, y = euler._y, z = euler._z, order = euler.order;
  1313. // http://www.mathworks.com/matlabcentral/fileexchange/
  1314. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1315. // content/SpinCalc.m
  1316. var cos = Math.cos;
  1317. var sin = Math.sin;
  1318. var c1 = cos( x / 2 );
  1319. var c2 = cos( y / 2 );
  1320. var c3 = cos( z / 2 );
  1321. var s1 = sin( x / 2 );
  1322. var s2 = sin( y / 2 );
  1323. var s3 = sin( z / 2 );
  1324. if ( order === 'XYZ' ) {
  1325. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1326. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1327. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1328. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1329. } else if ( order === 'YXZ' ) {
  1330. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1331. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1332. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1333. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1334. } else if ( order === 'ZXY' ) {
  1335. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1336. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1337. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1338. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1339. } else if ( order === 'ZYX' ) {
  1340. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1341. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1342. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1343. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1344. } else if ( order === 'YZX' ) {
  1345. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1346. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1347. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1348. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1349. } else if ( order === 'XZY' ) {
  1350. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1351. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1352. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1353. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1354. }
  1355. if ( update !== false ) this.onChangeCallback();
  1356. return this;
  1357. },
  1358. setFromAxisAngle: function ( axis, angle ) {
  1359. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1360. // assumes axis is normalized
  1361. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  1362. this._x = axis.x * s;
  1363. this._y = axis.y * s;
  1364. this._z = axis.z * s;
  1365. this._w = Math.cos( halfAngle );
  1366. this.onChangeCallback();
  1367. return this;
  1368. },
  1369. setFromRotationMatrix: function ( m ) {
  1370. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1371. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1372. var te = m.elements,
  1373. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1374. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1375. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  1376. trace = m11 + m22 + m33,
  1377. s;
  1378. if ( trace > 0 ) {
  1379. s = 0.5 / Math.sqrt( trace + 1.0 );
  1380. this._w = 0.25 / s;
  1381. this._x = ( m32 - m23 ) * s;
  1382. this._y = ( m13 - m31 ) * s;
  1383. this._z = ( m21 - m12 ) * s;
  1384. } else if ( m11 > m22 && m11 > m33 ) {
  1385. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  1386. this._w = ( m32 - m23 ) / s;
  1387. this._x = 0.25 * s;
  1388. this._y = ( m12 + m21 ) / s;
  1389. this._z = ( m13 + m31 ) / s;
  1390. } else if ( m22 > m33 ) {
  1391. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  1392. this._w = ( m13 - m31 ) / s;
  1393. this._x = ( m12 + m21 ) / s;
  1394. this._y = 0.25 * s;
  1395. this._z = ( m23 + m32 ) / s;
  1396. } else {
  1397. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  1398. this._w = ( m21 - m12 ) / s;
  1399. this._x = ( m13 + m31 ) / s;
  1400. this._y = ( m23 + m32 ) / s;
  1401. this._z = 0.25 * s;
  1402. }
  1403. this.onChangeCallback();
  1404. return this;
  1405. },
  1406. setFromUnitVectors: function () {
  1407. // assumes direction vectors vFrom and vTo are normalized
  1408. var v1 = new Vector3();
  1409. var r;
  1410. var EPS = 0.000001;
  1411. return function setFromUnitVectors( vFrom, vTo ) {
  1412. if ( v1 === undefined ) v1 = new Vector3();
  1413. r = vFrom.dot( vTo ) + 1;
  1414. if ( r < EPS ) {
  1415. r = 0;
  1416. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  1417. v1.set( - vFrom.y, vFrom.x, 0 );
  1418. } else {
  1419. v1.set( 0, - vFrom.z, vFrom.y );
  1420. }
  1421. } else {
  1422. v1.crossVectors( vFrom, vTo );
  1423. }
  1424. this._x = v1.x;
  1425. this._y = v1.y;
  1426. this._z = v1.z;
  1427. this._w = r;
  1428. return this.normalize();
  1429. };
  1430. }(),
  1431. inverse: function () {
  1432. // quaternion is assumed to have unit length
  1433. return this.conjugate();
  1434. },
  1435. conjugate: function () {
  1436. this._x *= - 1;
  1437. this._y *= - 1;
  1438. this._z *= - 1;
  1439. this.onChangeCallback();
  1440. return this;
  1441. },
  1442. dot: function ( v ) {
  1443. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1444. },
  1445. lengthSq: function () {
  1446. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1447. },
  1448. length: function () {
  1449. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  1450. },
  1451. normalize: function () {
  1452. var l = this.length();
  1453. if ( l === 0 ) {
  1454. this._x = 0;
  1455. this._y = 0;
  1456. this._z = 0;
  1457. this._w = 1;
  1458. } else {
  1459. l = 1 / l;
  1460. this._x = this._x * l;
  1461. this._y = this._y * l;
  1462. this._z = this._z * l;
  1463. this._w = this._w * l;
  1464. }
  1465. this.onChangeCallback();
  1466. return this;
  1467. },
  1468. multiply: function ( q, p ) {
  1469. if ( p !== undefined ) {
  1470. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  1471. return this.multiplyQuaternions( q, p );
  1472. }
  1473. return this.multiplyQuaternions( this, q );
  1474. },
  1475. premultiply: function ( q ) {
  1476. return this.multiplyQuaternions( q, this );
  1477. },
  1478. multiplyQuaternions: function ( a, b ) {
  1479. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  1480. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  1481. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  1482. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  1483. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  1484. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  1485. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  1486. this.onChangeCallback();
  1487. return this;
  1488. },
  1489. slerp: function ( qb, t ) {
  1490. if ( t === 0 ) return this;
  1491. if ( t === 1 ) return this.copy( qb );
  1492. var x = this._x, y = this._y, z = this._z, w = this._w;
  1493. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  1494. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  1495. if ( cosHalfTheta < 0 ) {
  1496. this._w = - qb._w;
  1497. this._x = - qb._x;
  1498. this._y = - qb._y;
  1499. this._z = - qb._z;
  1500. cosHalfTheta = - cosHalfTheta;
  1501. } else {
  1502. this.copy( qb );
  1503. }
  1504. if ( cosHalfTheta >= 1.0 ) {
  1505. this._w = w;
  1506. this._x = x;
  1507. this._y = y;
  1508. this._z = z;
  1509. return this;
  1510. }
  1511. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  1512. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  1513. this._w = 0.5 * ( w + this._w );
  1514. this._x = 0.5 * ( x + this._x );
  1515. this._y = 0.5 * ( y + this._y );
  1516. this._z = 0.5 * ( z + this._z );
  1517. return this;
  1518. }
  1519. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  1520. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  1521. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  1522. this._w = ( w * ratioA + this._w * ratioB );
  1523. this._x = ( x * ratioA + this._x * ratioB );
  1524. this._y = ( y * ratioA + this._y * ratioB );
  1525. this._z = ( z * ratioA + this._z * ratioB );
  1526. this.onChangeCallback();
  1527. return this;
  1528. },
  1529. equals: function ( quaternion ) {
  1530. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  1531. },
  1532. fromArray: function ( array, offset ) {
  1533. if ( offset === undefined ) offset = 0;
  1534. this._x = array[ offset ];
  1535. this._y = array[ offset + 1 ];
  1536. this._z = array[ offset + 2 ];
  1537. this._w = array[ offset + 3 ];
  1538. this.onChangeCallback();
  1539. return this;
  1540. },
  1541. toArray: function ( array, offset ) {
  1542. if ( array === undefined ) array = [];
  1543. if ( offset === undefined ) offset = 0;
  1544. array[ offset ] = this._x;
  1545. array[ offset + 1 ] = this._y;
  1546. array[ offset + 2 ] = this._z;
  1547. array[ offset + 3 ] = this._w;
  1548. return array;
  1549. },
  1550. onChange: function ( callback ) {
  1551. this.onChangeCallback = callback;
  1552. return this;
  1553. },
  1554. onChangeCallback: function () {}
  1555. } );
  1556. /**
  1557. * @author mrdoob / http://mrdoob.com/
  1558. * @author kile / http://kile.stravaganza.org/
  1559. * @author philogb / http://blog.thejit.org/
  1560. * @author mikael emtinger / http://gomo.se/
  1561. * @author egraether / http://egraether.com/
  1562. * @author WestLangley / http://github.com/WestLangley
  1563. */
  1564. function Vector3( x, y, z ) {
  1565. this.x = x || 0;
  1566. this.y = y || 0;
  1567. this.z = z || 0;
  1568. }
  1569. Object.assign( Vector3.prototype, {
  1570. isVector3: true,
  1571. set: function ( x, y, z ) {
  1572. this.x = x;
  1573. this.y = y;
  1574. this.z = z;
  1575. return this;
  1576. },
  1577. setScalar: function ( scalar ) {
  1578. this.x = scalar;
  1579. this.y = scalar;
  1580. this.z = scalar;
  1581. return this;
  1582. },
  1583. setX: function ( x ) {
  1584. this.x = x;
  1585. return this;
  1586. },
  1587. setY: function ( y ) {
  1588. this.y = y;
  1589. return this;
  1590. },
  1591. setZ: function ( z ) {
  1592. this.z = z;
  1593. return this;
  1594. },
  1595. setComponent: function ( index, value ) {
  1596. switch ( index ) {
  1597. case 0: this.x = value; break;
  1598. case 1: this.y = value; break;
  1599. case 2: this.z = value; break;
  1600. default: throw new Error( 'index is out of range: ' + index );
  1601. }
  1602. return this;
  1603. },
  1604. getComponent: function ( index ) {
  1605. switch ( index ) {
  1606. case 0: return this.x;
  1607. case 1: return this.y;
  1608. case 2: return this.z;
  1609. default: throw new Error( 'index is out of range: ' + index );
  1610. }
  1611. },
  1612. clone: function () {
  1613. return new this.constructor( this.x, this.y, this.z );
  1614. },
  1615. copy: function ( v ) {
  1616. this.x = v.x;
  1617. this.y = v.y;
  1618. this.z = v.z;
  1619. return this;
  1620. },
  1621. add: function ( v, w ) {
  1622. if ( w !== undefined ) {
  1623. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1624. return this.addVectors( v, w );
  1625. }
  1626. this.x += v.x;
  1627. this.y += v.y;
  1628. this.z += v.z;
  1629. return this;
  1630. },
  1631. addScalar: function ( s ) {
  1632. this.x += s;
  1633. this.y += s;
  1634. this.z += s;
  1635. return this;
  1636. },
  1637. addVectors: function ( a, b ) {
  1638. this.x = a.x + b.x;
  1639. this.y = a.y + b.y;
  1640. this.z = a.z + b.z;
  1641. return this;
  1642. },
  1643. addScaledVector: function ( v, s ) {
  1644. this.x += v.x * s;
  1645. this.y += v.y * s;
  1646. this.z += v.z * s;
  1647. return this;
  1648. },
  1649. sub: function ( v, w ) {
  1650. if ( w !== undefined ) {
  1651. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1652. return this.subVectors( v, w );
  1653. }
  1654. this.x -= v.x;
  1655. this.y -= v.y;
  1656. this.z -= v.z;
  1657. return this;
  1658. },
  1659. subScalar: function ( s ) {
  1660. this.x -= s;
  1661. this.y -= s;
  1662. this.z -= s;
  1663. return this;
  1664. },
  1665. subVectors: function ( a, b ) {
  1666. this.x = a.x - b.x;
  1667. this.y = a.y - b.y;
  1668. this.z = a.z - b.z;
  1669. return this;
  1670. },
  1671. multiply: function ( v, w ) {
  1672. if ( w !== undefined ) {
  1673. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1674. return this.multiplyVectors( v, w );
  1675. }
  1676. this.x *= v.x;
  1677. this.y *= v.y;
  1678. this.z *= v.z;
  1679. return this;
  1680. },
  1681. multiplyScalar: function ( scalar ) {
  1682. this.x *= scalar;
  1683. this.y *= scalar;
  1684. this.z *= scalar;
  1685. return this;
  1686. },
  1687. multiplyVectors: function ( a, b ) {
  1688. this.x = a.x * b.x;
  1689. this.y = a.y * b.y;
  1690. this.z = a.z * b.z;
  1691. return this;
  1692. },
  1693. applyEuler: function () {
  1694. var quaternion = new Quaternion();
  1695. return function applyEuler( euler ) {
  1696. if ( ! ( euler && euler.isEuler ) ) {
  1697. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1698. }
  1699. return this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1700. };
  1701. }(),
  1702. applyAxisAngle: function () {
  1703. var quaternion = new Quaternion();
  1704. return function applyAxisAngle( axis, angle ) {
  1705. return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1706. };
  1707. }(),
  1708. applyMatrix3: function ( m ) {
  1709. var x = this.x, y = this.y, z = this.z;
  1710. var e = m.elements;
  1711. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1712. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1713. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1714. return this;
  1715. },
  1716. applyMatrix4: function ( m ) {
  1717. var x = this.x, y = this.y, z = this.z;
  1718. var e = m.elements;
  1719. var w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  1720. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  1721. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  1722. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  1723. return this;
  1724. },
  1725. applyQuaternion: function ( q ) {
  1726. var x = this.x, y = this.y, z = this.z;
  1727. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1728. // calculate quat * vector
  1729. var ix = qw * x + qy * z - qz * y;
  1730. var iy = qw * y + qz * x - qx * z;
  1731. var iz = qw * z + qx * y - qy * x;
  1732. var iw = - qx * x - qy * y - qz * z;
  1733. // calculate result * inverse quat
  1734. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1735. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1736. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1737. return this;
  1738. },
  1739. project: function () {
  1740. var matrix = new Matrix4();
  1741. return function project( camera ) {
  1742. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1743. return this.applyMatrix4( matrix );
  1744. };
  1745. }(),
  1746. unproject: function () {
  1747. var matrix = new Matrix4();
  1748. return function unproject( camera ) {
  1749. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1750. return this.applyMatrix4( matrix );
  1751. };
  1752. }(),
  1753. transformDirection: function ( m ) {
  1754. // input: THREE.Matrix4 affine matrix
  1755. // vector interpreted as a direction
  1756. var x = this.x, y = this.y, z = this.z;
  1757. var e = m.elements;
  1758. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1759. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1760. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1761. return this.normalize();
  1762. },
  1763. divide: function ( v ) {
  1764. this.x /= v.x;
  1765. this.y /= v.y;
  1766. this.z /= v.z;
  1767. return this;
  1768. },
  1769. divideScalar: function ( scalar ) {
  1770. return this.multiplyScalar( 1 / scalar );
  1771. },
  1772. min: function ( v ) {
  1773. this.x = Math.min( this.x, v.x );
  1774. this.y = Math.min( this.y, v.y );
  1775. this.z = Math.min( this.z, v.z );
  1776. return this;
  1777. },
  1778. max: function ( v ) {
  1779. this.x = Math.max( this.x, v.x );
  1780. this.y = Math.max( this.y, v.y );
  1781. this.z = Math.max( this.z, v.z );
  1782. return this;
  1783. },
  1784. clamp: function ( min, max ) {
  1785. // assumes min < max, componentwise
  1786. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1787. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1788. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1789. return this;
  1790. },
  1791. clampScalar: function () {
  1792. var min = new Vector3();
  1793. var max = new Vector3();
  1794. return function clampScalar( minVal, maxVal ) {
  1795. min.set( minVal, minVal, minVal );
  1796. max.set( maxVal, maxVal, maxVal );
  1797. return this.clamp( min, max );
  1798. };
  1799. }(),
  1800. clampLength: function ( min, max ) {
  1801. var length = this.length();
  1802. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1803. },
  1804. floor: function () {
  1805. this.x = Math.floor( this.x );
  1806. this.y = Math.floor( this.y );
  1807. this.z = Math.floor( this.z );
  1808. return this;
  1809. },
  1810. ceil: function () {
  1811. this.x = Math.ceil( this.x );
  1812. this.y = Math.ceil( this.y );
  1813. this.z = Math.ceil( this.z );
  1814. return this;
  1815. },
  1816. round: function () {
  1817. this.x = Math.round( this.x );
  1818. this.y = Math.round( this.y );
  1819. this.z = Math.round( this.z );
  1820. return this;
  1821. },
  1822. roundToZero: function () {
  1823. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1824. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1825. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1826. return this;
  1827. },
  1828. negate: function () {
  1829. this.x = - this.x;
  1830. this.y = - this.y;
  1831. this.z = - this.z;
  1832. return this;
  1833. },
  1834. dot: function ( v ) {
  1835. return this.x * v.x + this.y * v.y + this.z * v.z;
  1836. },
  1837. // TODO lengthSquared?
  1838. lengthSq: function () {
  1839. return this.x * this.x + this.y * this.y + this.z * this.z;
  1840. },
  1841. length: function () {
  1842. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1843. },
  1844. manhattanLength: function () {
  1845. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1846. },
  1847. normalize: function () {
  1848. return this.divideScalar( this.length() || 1 );
  1849. },
  1850. setLength: function ( length ) {
  1851. return this.normalize().multiplyScalar( length );
  1852. },
  1853. lerp: function ( v, alpha ) {
  1854. this.x += ( v.x - this.x ) * alpha;
  1855. this.y += ( v.y - this.y ) * alpha;
  1856. this.z += ( v.z - this.z ) * alpha;
  1857. return this;
  1858. },
  1859. lerpVectors: function ( v1, v2, alpha ) {
  1860. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1861. },
  1862. cross: function ( v, w ) {
  1863. if ( w !== undefined ) {
  1864. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1865. return this.crossVectors( v, w );
  1866. }
  1867. return this.crossVectors( this, v );
  1868. },
  1869. crossVectors: function ( a, b ) {
  1870. var ax = a.x, ay = a.y, az = a.z;
  1871. var bx = b.x, by = b.y, bz = b.z;
  1872. this.x = ay * bz - az * by;
  1873. this.y = az * bx - ax * bz;
  1874. this.z = ax * by - ay * bx;
  1875. return this;
  1876. },
  1877. projectOnVector: function ( vector ) {
  1878. var scalar = vector.dot( this ) / vector.lengthSq();
  1879. return this.copy( vector ).multiplyScalar( scalar );
  1880. },
  1881. projectOnPlane: function () {
  1882. var v1 = new Vector3();
  1883. return function projectOnPlane( planeNormal ) {
  1884. v1.copy( this ).projectOnVector( planeNormal );
  1885. return this.sub( v1 );
  1886. };
  1887. }(),
  1888. reflect: function () {
  1889. // reflect incident vector off plane orthogonal to normal
  1890. // normal is assumed to have unit length
  1891. var v1 = new Vector3();
  1892. return function reflect( normal ) {
  1893. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1894. };
  1895. }(),
  1896. angleTo: function ( v ) {
  1897. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1898. // clamp, to handle numerical problems
  1899. return Math.acos( _Math.clamp( theta, - 1, 1 ) );
  1900. },
  1901. distanceTo: function ( v ) {
  1902. return Math.sqrt( this.distanceToSquared( v ) );
  1903. },
  1904. distanceToSquared: function ( v ) {
  1905. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1906. return dx * dx + dy * dy + dz * dz;
  1907. },
  1908. manhattanDistanceTo: function ( v ) {
  1909. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  1910. },
  1911. setFromSpherical: function ( s ) {
  1912. var sinPhiRadius = Math.sin( s.phi ) * s.radius;
  1913. this.x = sinPhiRadius * Math.sin( s.theta );
  1914. this.y = Math.cos( s.phi ) * s.radius;
  1915. this.z = sinPhiRadius * Math.cos( s.theta );
  1916. return this;
  1917. },
  1918. setFromCylindrical: function ( c ) {
  1919. this.x = c.radius * Math.sin( c.theta );
  1920. this.y = c.y;
  1921. this.z = c.radius * Math.cos( c.theta );
  1922. return this;
  1923. },
  1924. setFromMatrixPosition: function ( m ) {
  1925. var e = m.elements;
  1926. this.x = e[ 12 ];
  1927. this.y = e[ 13 ];
  1928. this.z = e[ 14 ];
  1929. return this;
  1930. },
  1931. setFromMatrixScale: function ( m ) {
  1932. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1933. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1934. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1935. this.x = sx;
  1936. this.y = sy;
  1937. this.z = sz;
  1938. return this;
  1939. },
  1940. setFromMatrixColumn: function ( m, index ) {
  1941. return this.fromArray( m.elements, index * 4 );
  1942. },
  1943. equals: function ( v ) {
  1944. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1945. },
  1946. fromArray: function ( array, offset ) {
  1947. if ( offset === undefined ) offset = 0;
  1948. this.x = array[ offset ];
  1949. this.y = array[ offset + 1 ];
  1950. this.z = array[ offset + 2 ];
  1951. return this;
  1952. },
  1953. toArray: function ( array, offset ) {
  1954. if ( array === undefined ) array = [];
  1955. if ( offset === undefined ) offset = 0;
  1956. array[ offset ] = this.x;
  1957. array[ offset + 1 ] = this.y;
  1958. array[ offset + 2 ] = this.z;
  1959. return array;
  1960. },
  1961. fromBufferAttribute: function ( attribute, index, offset ) {
  1962. if ( offset !== undefined ) {
  1963. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  1964. }
  1965. this.x = attribute.getX( index );
  1966. this.y = attribute.getY( index );
  1967. this.z = attribute.getZ( index );
  1968. return this;
  1969. }
  1970. } );
  1971. /**
  1972. * @author alteredq / http://alteredqualia.com/
  1973. * @author WestLangley / http://github.com/WestLangley
  1974. * @author bhouston / http://clara.io
  1975. * @author tschw
  1976. */
  1977. function Matrix3() {
  1978. this.elements = [
  1979. 1, 0, 0,
  1980. 0, 1, 0,
  1981. 0, 0, 1
  1982. ];
  1983. if ( arguments.length > 0 ) {
  1984. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  1985. }
  1986. }
  1987. Object.assign( Matrix3.prototype, {
  1988. isMatrix3: true,
  1989. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  1990. var te = this.elements;
  1991. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  1992. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  1993. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  1994. return this;
  1995. },
  1996. identity: function () {
  1997. this.set(
  1998. 1, 0, 0,
  1999. 0, 1, 0,
  2000. 0, 0, 1
  2001. );
  2002. return this;
  2003. },
  2004. clone: function () {
  2005. return new this.constructor().fromArray( this.elements );
  2006. },
  2007. copy: function ( m ) {
  2008. var te = this.elements;
  2009. var me = m.elements;
  2010. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  2011. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  2012. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  2013. return this;
  2014. },
  2015. setFromMatrix4: function ( m ) {
  2016. var me = m.elements;
  2017. this.set(
  2018. me[ 0 ], me[ 4 ], me[ 8 ],
  2019. me[ 1 ], me[ 5 ], me[ 9 ],
  2020. me[ 2 ], me[ 6 ], me[ 10 ]
  2021. );
  2022. return this;
  2023. },
  2024. applyToBufferAttribute: function () {
  2025. var v1 = new Vector3();
  2026. return function applyToBufferAttribute( attribute ) {
  2027. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2028. v1.x = attribute.getX( i );
  2029. v1.y = attribute.getY( i );
  2030. v1.z = attribute.getZ( i );
  2031. v1.applyMatrix3( this );
  2032. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  2033. }
  2034. return attribute;
  2035. };
  2036. }(),
  2037. multiply: function ( m ) {
  2038. return this.multiplyMatrices( this, m );
  2039. },
  2040. premultiply: function ( m ) {
  2041. return this.multiplyMatrices( m, this );
  2042. },
  2043. multiplyMatrices: function ( a, b ) {
  2044. var ae = a.elements;
  2045. var be = b.elements;
  2046. var te = this.elements;
  2047. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  2048. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  2049. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  2050. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  2051. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  2052. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  2053. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  2054. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  2055. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  2056. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  2057. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  2058. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  2059. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  2060. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  2061. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  2062. return this;
  2063. },
  2064. multiplyScalar: function ( s ) {
  2065. var te = this.elements;
  2066. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2067. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2068. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2069. return this;
  2070. },
  2071. determinant: function () {
  2072. var te = this.elements;
  2073. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2074. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2075. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2076. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2077. },
  2078. getInverse: function ( matrix, throwOnDegenerate ) {
  2079. if ( matrix && matrix.isMatrix4 ) {
  2080. console.error( "THREE.Matrix3: .getInverse() no longer takes a Matrix4 argument." );
  2081. }
  2082. var me = matrix.elements,
  2083. te = this.elements,
  2084. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  2085. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  2086. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  2087. t11 = n33 * n22 - n32 * n23,
  2088. t12 = n32 * n13 - n33 * n12,
  2089. t13 = n23 * n12 - n22 * n13,
  2090. det = n11 * t11 + n21 * t12 + n31 * t13;
  2091. if ( det === 0 ) {
  2092. var msg = "THREE.Matrix3: .getInverse() can't invert matrix, determinant is 0";
  2093. if ( throwOnDegenerate === true ) {
  2094. throw new Error( msg );
  2095. } else {
  2096. console.warn( msg );
  2097. }
  2098. return this.identity();
  2099. }
  2100. var detInv = 1 / det;
  2101. te[ 0 ] = t11 * detInv;
  2102. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  2103. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  2104. te[ 3 ] = t12 * detInv;
  2105. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  2106. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  2107. te[ 6 ] = t13 * detInv;
  2108. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  2109. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  2110. return this;
  2111. },
  2112. transpose: function () {
  2113. var tmp, m = this.elements;
  2114. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2115. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2116. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2117. return this;
  2118. },
  2119. getNormalMatrix: function ( matrix4 ) {
  2120. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  2121. },
  2122. transposeIntoArray: function ( r ) {
  2123. var m = this.elements;
  2124. r[ 0 ] = m[ 0 ];
  2125. r[ 1 ] = m[ 3 ];
  2126. r[ 2 ] = m[ 6 ];
  2127. r[ 3 ] = m[ 1 ];
  2128. r[ 4 ] = m[ 4 ];
  2129. r[ 5 ] = m[ 7 ];
  2130. r[ 6 ] = m[ 2 ];
  2131. r[ 7 ] = m[ 5 ];
  2132. r[ 8 ] = m[ 8 ];
  2133. return this;
  2134. },
  2135. setUvTransform: function ( tx, ty, sx, sy, rotation, cx, cy ) {
  2136. var c = Math.cos( rotation );
  2137. var s = Math.sin( rotation );
  2138. this.set(
  2139. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  2140. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  2141. 0, 0, 1
  2142. );
  2143. },
  2144. scale: function ( sx, sy ) {
  2145. var te = this.elements;
  2146. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  2147. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  2148. return this;
  2149. },
  2150. rotate: function ( theta ) {
  2151. var c = Math.cos( theta );
  2152. var s = Math.sin( theta );
  2153. var te = this.elements;
  2154. var a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  2155. var a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  2156. te[ 0 ] = c * a11 + s * a21;
  2157. te[ 3 ] = c * a12 + s * a22;
  2158. te[ 6 ] = c * a13 + s * a23;
  2159. te[ 1 ] = - s * a11 + c * a21;
  2160. te[ 4 ] = - s * a12 + c * a22;
  2161. te[ 7 ] = - s * a13 + c * a23;
  2162. return this;
  2163. },
  2164. translate: function ( tx, ty ) {
  2165. var te = this.elements;
  2166. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  2167. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  2168. return this;
  2169. },
  2170. equals: function ( matrix ) {
  2171. var te = this.elements;
  2172. var me = matrix.elements;
  2173. for ( var i = 0; i < 9; i ++ ) {
  2174. if ( te[ i ] !== me[ i ] ) return false;
  2175. }
  2176. return true;
  2177. },
  2178. fromArray: function ( array, offset ) {
  2179. if ( offset === undefined ) offset = 0;
  2180. for ( var i = 0; i < 9; i ++ ) {
  2181. this.elements[ i ] = array[ i + offset ];
  2182. }
  2183. return this;
  2184. },
  2185. toArray: function ( array, offset ) {
  2186. if ( array === undefined ) array = [];
  2187. if ( offset === undefined ) offset = 0;
  2188. var te = this.elements;
  2189. array[ offset ] = te[ 0 ];
  2190. array[ offset + 1 ] = te[ 1 ];
  2191. array[ offset + 2 ] = te[ 2 ];
  2192. array[ offset + 3 ] = te[ 3 ];
  2193. array[ offset + 4 ] = te[ 4 ];
  2194. array[ offset + 5 ] = te[ 5 ];
  2195. array[ offset + 6 ] = te[ 6 ];
  2196. array[ offset + 7 ] = te[ 7 ];
  2197. array[ offset + 8 ] = te[ 8 ];
  2198. return array;
  2199. }
  2200. } );
  2201. /**
  2202. * @author mrdoob / http://mrdoob.com/
  2203. * @author alteredq / http://alteredqualia.com/
  2204. * @author szimek / https://github.com/szimek/
  2205. */
  2206. var textureId = 0;
  2207. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  2208. Object.defineProperty( this, 'id', { value: textureId ++ } );
  2209. this.uuid = _Math.generateUUID();
  2210. this.name = '';
  2211. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  2212. this.mipmaps = [];
  2213. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  2214. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  2215. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  2216. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  2217. this.minFilter = minFilter !== undefined ? minFilter : LinearMipMapLinearFilter;
  2218. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  2219. this.format = format !== undefined ? format : RGBAFormat;
  2220. this.type = type !== undefined ? type : UnsignedByteType;
  2221. this.offset = new Vector2( 0, 0 );
  2222. this.repeat = new Vector2( 1, 1 );
  2223. this.center = new Vector2( 0, 0 );
  2224. this.rotation = 0;
  2225. this.matrixAutoUpdate = true;
  2226. this.matrix = new Matrix3();
  2227. this.generateMipmaps = true;
  2228. this.premultiplyAlpha = false;
  2229. this.flipY = true;
  2230. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  2231. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  2232. //
  2233. // Also changing the encoding after already used by a Material will not automatically make the Material
  2234. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  2235. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  2236. this.version = 0;
  2237. this.onUpdate = null;
  2238. }
  2239. Texture.DEFAULT_IMAGE = undefined;
  2240. Texture.DEFAULT_MAPPING = UVMapping;
  2241. Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2242. constructor: Texture,
  2243. isTexture: true,
  2244. updateMatrix: function () {
  2245. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  2246. },
  2247. clone: function () {
  2248. return new this.constructor().copy( this );
  2249. },
  2250. copy: function ( source ) {
  2251. this.name = source.name;
  2252. this.image = source.image;
  2253. this.mipmaps = source.mipmaps.slice( 0 );
  2254. this.mapping = source.mapping;
  2255. this.wrapS = source.wrapS;
  2256. this.wrapT = source.wrapT;
  2257. this.magFilter = source.magFilter;
  2258. this.minFilter = source.minFilter;
  2259. this.anisotropy = source.anisotropy;
  2260. this.format = source.format;
  2261. this.type = source.type;
  2262. this.offset.copy( source.offset );
  2263. this.repeat.copy( source.repeat );
  2264. this.center.copy( source.center );
  2265. this.rotation = source.rotation;
  2266. this.matrixAutoUpdate = source.matrixAutoUpdate;
  2267. this.matrix.copy( source.matrix );
  2268. this.generateMipmaps = source.generateMipmaps;
  2269. this.premultiplyAlpha = source.premultiplyAlpha;
  2270. this.flipY = source.flipY;
  2271. this.unpackAlignment = source.unpackAlignment;
  2272. this.encoding = source.encoding;
  2273. return this;
  2274. },
  2275. toJSON: function ( meta ) {
  2276. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  2277. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  2278. return meta.textures[ this.uuid ];
  2279. }
  2280. function getDataURL( image ) {
  2281. var canvas;
  2282. if ( image instanceof HTMLCanvasElement ) {
  2283. canvas = image;
  2284. } else {
  2285. canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  2286. canvas.width = image.width;
  2287. canvas.height = image.height;
  2288. var context = canvas.getContext( '2d' );
  2289. if ( image instanceof ImageData ) {
  2290. context.putImageData( image, 0, 0 );
  2291. } else {
  2292. context.drawImage( image, 0, 0, image.width, image.height );
  2293. }
  2294. }
  2295. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  2296. return canvas.toDataURL( 'image/jpeg', 0.6 );
  2297. } else {
  2298. return canvas.toDataURL( 'image/png' );
  2299. }
  2300. }
  2301. var output = {
  2302. metadata: {
  2303. version: 4.5,
  2304. type: 'Texture',
  2305. generator: 'Texture.toJSON'
  2306. },
  2307. uuid: this.uuid,
  2308. name: this.name,
  2309. mapping: this.mapping,
  2310. repeat: [ this.repeat.x, this.repeat.y ],
  2311. offset: [ this.offset.x, this.offset.y ],
  2312. center: [ this.center.x, this.center.y ],
  2313. rotation: this.rotation,
  2314. wrap: [ this.wrapS, this.wrapT ],
  2315. format: this.format,
  2316. minFilter: this.minFilter,
  2317. magFilter: this.magFilter,
  2318. anisotropy: this.anisotropy,
  2319. flipY: this.flipY
  2320. };
  2321. if ( this.image !== undefined ) {
  2322. // TODO: Move to THREE.Image
  2323. var image = this.image;
  2324. if ( image.uuid === undefined ) {
  2325. image.uuid = _Math.generateUUID(); // UGH
  2326. }
  2327. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  2328. meta.images[ image.uuid ] = {
  2329. uuid: image.uuid,
  2330. url: getDataURL( image )
  2331. };
  2332. }
  2333. output.image = image.uuid;
  2334. }
  2335. if ( ! isRootObject ) {
  2336. meta.textures[ this.uuid ] = output;
  2337. }
  2338. return output;
  2339. },
  2340. dispose: function () {
  2341. this.dispatchEvent( { type: 'dispose' } );
  2342. },
  2343. transformUv: function ( uv ) {
  2344. if ( this.mapping !== UVMapping ) return;
  2345. uv.applyMatrix3( this.matrix );
  2346. if ( uv.x < 0 || uv.x > 1 ) {
  2347. switch ( this.wrapS ) {
  2348. case RepeatWrapping:
  2349. uv.x = uv.x - Math.floor( uv.x );
  2350. break;
  2351. case ClampToEdgeWrapping:
  2352. uv.x = uv.x < 0 ? 0 : 1;
  2353. break;
  2354. case MirroredRepeatWrapping:
  2355. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  2356. uv.x = Math.ceil( uv.x ) - uv.x;
  2357. } else {
  2358. uv.x = uv.x - Math.floor( uv.x );
  2359. }
  2360. break;
  2361. }
  2362. }
  2363. if ( uv.y < 0 || uv.y > 1 ) {
  2364. switch ( this.wrapT ) {
  2365. case RepeatWrapping:
  2366. uv.y = uv.y - Math.floor( uv.y );
  2367. break;
  2368. case ClampToEdgeWrapping:
  2369. uv.y = uv.y < 0 ? 0 : 1;
  2370. break;
  2371. case MirroredRepeatWrapping:
  2372. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  2373. uv.y = Math.ceil( uv.y ) - uv.y;
  2374. } else {
  2375. uv.y = uv.y - Math.floor( uv.y );
  2376. }
  2377. break;
  2378. }
  2379. }
  2380. if ( this.flipY ) {
  2381. uv.y = 1 - uv.y;
  2382. }
  2383. }
  2384. } );
  2385. Object.defineProperty( Texture.prototype, "needsUpdate", {
  2386. set: function ( value ) {
  2387. if ( value === true ) this.version ++;
  2388. }
  2389. } );
  2390. /**
  2391. * @author supereggbert / http://www.paulbrunt.co.uk/
  2392. * @author philogb / http://blog.thejit.org/
  2393. * @author mikael emtinger / http://gomo.se/
  2394. * @author egraether / http://egraether.com/
  2395. * @author WestLangley / http://github.com/WestLangley
  2396. */
  2397. function Vector4( x, y, z, w ) {
  2398. this.x = x || 0;
  2399. this.y = y || 0;
  2400. this.z = z || 0;
  2401. this.w = ( w !== undefined ) ? w : 1;
  2402. }
  2403. Object.assign( Vector4.prototype, {
  2404. isVector4: true,
  2405. set: function ( x, y, z, w ) {
  2406. this.x = x;
  2407. this.y = y;
  2408. this.z = z;
  2409. this.w = w;
  2410. return this;
  2411. },
  2412. setScalar: function ( scalar ) {
  2413. this.x = scalar;
  2414. this.y = scalar;
  2415. this.z = scalar;
  2416. this.w = scalar;
  2417. return this;
  2418. },
  2419. setX: function ( x ) {
  2420. this.x = x;
  2421. return this;
  2422. },
  2423. setY: function ( y ) {
  2424. this.y = y;
  2425. return this;
  2426. },
  2427. setZ: function ( z ) {
  2428. this.z = z;
  2429. return this;
  2430. },
  2431. setW: function ( w ) {
  2432. this.w = w;
  2433. return this;
  2434. },
  2435. setComponent: function ( index, value ) {
  2436. switch ( index ) {
  2437. case 0: this.x = value; break;
  2438. case 1: this.y = value; break;
  2439. case 2: this.z = value; break;
  2440. case 3: this.w = value; break;
  2441. default: throw new Error( 'index is out of range: ' + index );
  2442. }
  2443. return this;
  2444. },
  2445. getComponent: function ( index ) {
  2446. switch ( index ) {
  2447. case 0: return this.x;
  2448. case 1: return this.y;
  2449. case 2: return this.z;
  2450. case 3: return this.w;
  2451. default: throw new Error( 'index is out of range: ' + index );
  2452. }
  2453. },
  2454. clone: function () {
  2455. return new this.constructor( this.x, this.y, this.z, this.w );
  2456. },
  2457. copy: function ( v ) {
  2458. this.x = v.x;
  2459. this.y = v.y;
  2460. this.z = v.z;
  2461. this.w = ( v.w !== undefined ) ? v.w : 1;
  2462. return this;
  2463. },
  2464. add: function ( v, w ) {
  2465. if ( w !== undefined ) {
  2466. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  2467. return this.addVectors( v, w );
  2468. }
  2469. this.x += v.x;
  2470. this.y += v.y;
  2471. this.z += v.z;
  2472. this.w += v.w;
  2473. return this;
  2474. },
  2475. addScalar: function ( s ) {
  2476. this.x += s;
  2477. this.y += s;
  2478. this.z += s;
  2479. this.w += s;
  2480. return this;
  2481. },
  2482. addVectors: function ( a, b ) {
  2483. this.x = a.x + b.x;
  2484. this.y = a.y + b.y;
  2485. this.z = a.z + b.z;
  2486. this.w = a.w + b.w;
  2487. return this;
  2488. },
  2489. addScaledVector: function ( v, s ) {
  2490. this.x += v.x * s;
  2491. this.y += v.y * s;
  2492. this.z += v.z * s;
  2493. this.w += v.w * s;
  2494. return this;
  2495. },
  2496. sub: function ( v, w ) {
  2497. if ( w !== undefined ) {
  2498. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  2499. return this.subVectors( v, w );
  2500. }
  2501. this.x -= v.x;
  2502. this.y -= v.y;
  2503. this.z -= v.z;
  2504. this.w -= v.w;
  2505. return this;
  2506. },
  2507. subScalar: function ( s ) {
  2508. this.x -= s;
  2509. this.y -= s;
  2510. this.z -= s;
  2511. this.w -= s;
  2512. return this;
  2513. },
  2514. subVectors: function ( a, b ) {
  2515. this.x = a.x - b.x;
  2516. this.y = a.y - b.y;
  2517. this.z = a.z - b.z;
  2518. this.w = a.w - b.w;
  2519. return this;
  2520. },
  2521. multiplyScalar: function ( scalar ) {
  2522. this.x *= scalar;
  2523. this.y *= scalar;
  2524. this.z *= scalar;
  2525. this.w *= scalar;
  2526. return this;
  2527. },
  2528. applyMatrix4: function ( m ) {
  2529. var x = this.x, y = this.y, z = this.z, w = this.w;
  2530. var e = m.elements;
  2531. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  2532. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  2533. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  2534. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  2535. return this;
  2536. },
  2537. divideScalar: function ( scalar ) {
  2538. return this.multiplyScalar( 1 / scalar );
  2539. },
  2540. setAxisAngleFromQuaternion: function ( q ) {
  2541. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  2542. // q is assumed to be normalized
  2543. this.w = 2 * Math.acos( q.w );
  2544. var s = Math.sqrt( 1 - q.w * q.w );
  2545. if ( s < 0.0001 ) {
  2546. this.x = 1;
  2547. this.y = 0;
  2548. this.z = 0;
  2549. } else {
  2550. this.x = q.x / s;
  2551. this.y = q.y / s;
  2552. this.z = q.z / s;
  2553. }
  2554. return this;
  2555. },
  2556. setAxisAngleFromRotationMatrix: function ( m ) {
  2557. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2558. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2559. var angle, x, y, z, // variables for result
  2560. epsilon = 0.01, // margin to allow for rounding errors
  2561. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  2562. te = m.elements,
  2563. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  2564. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  2565. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2566. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  2567. ( Math.abs( m13 - m31 ) < epsilon ) &&
  2568. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  2569. // singularity found
  2570. // first check for identity matrix which must have +1 for all terms
  2571. // in leading diagonal and zero in other terms
  2572. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  2573. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  2574. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  2575. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  2576. // this singularity is identity matrix so angle = 0
  2577. this.set( 1, 0, 0, 0 );
  2578. return this; // zero angle, arbitrary axis
  2579. }
  2580. // otherwise this singularity is angle = 180
  2581. angle = Math.PI;
  2582. var xx = ( m11 + 1 ) / 2;
  2583. var yy = ( m22 + 1 ) / 2;
  2584. var zz = ( m33 + 1 ) / 2;
  2585. var xy = ( m12 + m21 ) / 4;
  2586. var xz = ( m13 + m31 ) / 4;
  2587. var yz = ( m23 + m32 ) / 4;
  2588. if ( ( xx > yy ) && ( xx > zz ) ) {
  2589. // m11 is the largest diagonal term
  2590. if ( xx < epsilon ) {
  2591. x = 0;
  2592. y = 0.707106781;
  2593. z = 0.707106781;
  2594. } else {
  2595. x = Math.sqrt( xx );
  2596. y = xy / x;
  2597. z = xz / x;
  2598. }
  2599. } else if ( yy > zz ) {
  2600. // m22 is the largest diagonal term
  2601. if ( yy < epsilon ) {
  2602. x = 0.707106781;
  2603. y = 0;
  2604. z = 0.707106781;
  2605. } else {
  2606. y = Math.sqrt( yy );
  2607. x = xy / y;
  2608. z = yz / y;
  2609. }
  2610. } else {
  2611. // m33 is the largest diagonal term so base result on this
  2612. if ( zz < epsilon ) {
  2613. x = 0.707106781;
  2614. y = 0.707106781;
  2615. z = 0;
  2616. } else {
  2617. z = Math.sqrt( zz );
  2618. x = xz / z;
  2619. y = yz / z;
  2620. }
  2621. }
  2622. this.set( x, y, z, angle );
  2623. return this; // return 180 deg rotation
  2624. }
  2625. // as we have reached here there are no singularities so we can handle normally
  2626. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  2627. ( m13 - m31 ) * ( m13 - m31 ) +
  2628. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  2629. if ( Math.abs( s ) < 0.001 ) s = 1;
  2630. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2631. // caught by singularity test above, but I've left it in just in case
  2632. this.x = ( m32 - m23 ) / s;
  2633. this.y = ( m13 - m31 ) / s;
  2634. this.z = ( m21 - m12 ) / s;
  2635. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  2636. return this;
  2637. },
  2638. min: function ( v ) {
  2639. this.x = Math.min( this.x, v.x );
  2640. this.y = Math.min( this.y, v.y );
  2641. this.z = Math.min( this.z, v.z );
  2642. this.w = Math.min( this.w, v.w );
  2643. return this;
  2644. },
  2645. max: function ( v ) {
  2646. this.x = Math.max( this.x, v.x );
  2647. this.y = Math.max( this.y, v.y );
  2648. this.z = Math.max( this.z, v.z );
  2649. this.w = Math.max( this.w, v.w );
  2650. return this;
  2651. },
  2652. clamp: function ( min, max ) {
  2653. // assumes min < max, componentwise
  2654. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2655. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2656. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2657. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  2658. return this;
  2659. },
  2660. clampScalar: function () {
  2661. var min, max;
  2662. return function clampScalar( minVal, maxVal ) {
  2663. if ( min === undefined ) {
  2664. min = new Vector4();
  2665. max = new Vector4();
  2666. }
  2667. min.set( minVal, minVal, minVal, minVal );
  2668. max.set( maxVal, maxVal, maxVal, maxVal );
  2669. return this.clamp( min, max );
  2670. };
  2671. }(),
  2672. clampLength: function ( min, max ) {
  2673. var length = this.length();
  2674. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2675. },
  2676. floor: function () {
  2677. this.x = Math.floor( this.x );
  2678. this.y = Math.floor( this.y );
  2679. this.z = Math.floor( this.z );
  2680. this.w = Math.floor( this.w );
  2681. return this;
  2682. },
  2683. ceil: function () {
  2684. this.x = Math.ceil( this.x );
  2685. this.y = Math.ceil( this.y );
  2686. this.z = Math.ceil( this.z );
  2687. this.w = Math.ceil( this.w );
  2688. return this;
  2689. },
  2690. round: function () {
  2691. this.x = Math.round( this.x );
  2692. this.y = Math.round( this.y );
  2693. this.z = Math.round( this.z );
  2694. this.w = Math.round( this.w );
  2695. return this;
  2696. },
  2697. roundToZero: function () {
  2698. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2699. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2700. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2701. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  2702. return this;
  2703. },
  2704. negate: function () {
  2705. this.x = - this.x;
  2706. this.y = - this.y;
  2707. this.z = - this.z;
  2708. this.w = - this.w;
  2709. return this;
  2710. },
  2711. dot: function ( v ) {
  2712. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2713. },
  2714. lengthSq: function () {
  2715. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2716. },
  2717. length: function () {
  2718. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  2719. },
  2720. manhattanLength: function () {
  2721. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  2722. },
  2723. normalize: function () {
  2724. return this.divideScalar( this.length() || 1 );
  2725. },
  2726. setLength: function ( length ) {
  2727. return this.normalize().multiplyScalar( length );
  2728. },
  2729. lerp: function ( v, alpha ) {
  2730. this.x += ( v.x - this.x ) * alpha;
  2731. this.y += ( v.y - this.y ) * alpha;
  2732. this.z += ( v.z - this.z ) * alpha;
  2733. this.w += ( v.w - this.w ) * alpha;
  2734. return this;
  2735. },
  2736. lerpVectors: function ( v1, v2, alpha ) {
  2737. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  2738. },
  2739. equals: function ( v ) {
  2740. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  2741. },
  2742. fromArray: function ( array, offset ) {
  2743. if ( offset === undefined ) offset = 0;
  2744. this.x = array[ offset ];
  2745. this.y = array[ offset + 1 ];
  2746. this.z = array[ offset + 2 ];
  2747. this.w = array[ offset + 3 ];
  2748. return this;
  2749. },
  2750. toArray: function ( array, offset ) {
  2751. if ( array === undefined ) array = [];
  2752. if ( offset === undefined ) offset = 0;
  2753. array[ offset ] = this.x;
  2754. array[ offset + 1 ] = this.y;
  2755. array[ offset + 2 ] = this.z;
  2756. array[ offset + 3 ] = this.w;
  2757. return array;
  2758. },
  2759. fromBufferAttribute: function ( attribute, index, offset ) {
  2760. if ( offset !== undefined ) {
  2761. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  2762. }
  2763. this.x = attribute.getX( index );
  2764. this.y = attribute.getY( index );
  2765. this.z = attribute.getZ( index );
  2766. this.w = attribute.getW( index );
  2767. return this;
  2768. }
  2769. } );
  2770. /**
  2771. * @author szimek / https://github.com/szimek/
  2772. * @author alteredq / http://alteredqualia.com/
  2773. * @author Marius Kintel / https://github.com/kintel
  2774. */
  2775. /*
  2776. In options, we can specify:
  2777. * Texture parameters for an auto-generated target texture
  2778. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2779. */
  2780. function WebGLRenderTarget( width, height, options ) {
  2781. this.width = width;
  2782. this.height = height;
  2783. this.scissor = new Vector4( 0, 0, width, height );
  2784. this.scissorTest = false;
  2785. this.viewport = new Vector4( 0, 0, width, height );
  2786. options = options || {};
  2787. if ( options.minFilter === undefined ) options.minFilter = LinearFilter;
  2788. this.texture = new Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  2789. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : true;
  2790. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2791. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  2792. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2793. }
  2794. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2795. constructor: WebGLRenderTarget,
  2796. isWebGLRenderTarget: true,
  2797. setSize: function ( width, height ) {
  2798. if ( this.width !== width || this.height !== height ) {
  2799. this.width = width;
  2800. this.height = height;
  2801. this.dispose();
  2802. }
  2803. this.viewport.set( 0, 0, width, height );
  2804. this.scissor.set( 0, 0, width, height );
  2805. },
  2806. clone: function () {
  2807. return new this.constructor().copy( this );
  2808. },
  2809. copy: function ( source ) {
  2810. this.width = source.width;
  2811. this.height = source.height;
  2812. this.viewport.copy( source.viewport );
  2813. this.texture = source.texture.clone();
  2814. this.depthBuffer = source.depthBuffer;
  2815. this.stencilBuffer = source.stencilBuffer;
  2816. this.depthTexture = source.depthTexture;
  2817. return this;
  2818. },
  2819. dispose: function () {
  2820. this.dispatchEvent( { type: 'dispose' } );
  2821. }
  2822. } );
  2823. /**
  2824. * @author alteredq / http://alteredqualia.com
  2825. */
  2826. function WebGLRenderTargetCube( width, height, options ) {
  2827. WebGLRenderTarget.call( this, width, height, options );
  2828. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  2829. this.activeMipMapLevel = 0;
  2830. }
  2831. WebGLRenderTargetCube.prototype = Object.create( WebGLRenderTarget.prototype );
  2832. WebGLRenderTargetCube.prototype.constructor = WebGLRenderTargetCube;
  2833. WebGLRenderTargetCube.prototype.isWebGLRenderTargetCube = true;
  2834. /**
  2835. * @author alteredq / http://alteredqualia.com/
  2836. */
  2837. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  2838. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  2839. this.image = { data: data, width: width, height: height };
  2840. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  2841. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  2842. this.generateMipmaps = false;
  2843. this.flipY = false;
  2844. this.unpackAlignment = 1;
  2845. }
  2846. DataTexture.prototype = Object.create( Texture.prototype );
  2847. DataTexture.prototype.constructor = DataTexture;
  2848. DataTexture.prototype.isDataTexture = true;
  2849. /**
  2850. * @author bhouston / http://clara.io
  2851. * @author WestLangley / http://github.com/WestLangley
  2852. */
  2853. function Box3( min, max ) {
  2854. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  2855. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  2856. }
  2857. Object.assign( Box3.prototype, {
  2858. isBox3: true,
  2859. set: function ( min, max ) {
  2860. this.min.copy( min );
  2861. this.max.copy( max );
  2862. return this;
  2863. },
  2864. setFromArray: function ( array ) {
  2865. var minX = + Infinity;
  2866. var minY = + Infinity;
  2867. var minZ = + Infinity;
  2868. var maxX = - Infinity;
  2869. var maxY = - Infinity;
  2870. var maxZ = - Infinity;
  2871. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  2872. var x = array[ i ];
  2873. var y = array[ i + 1 ];
  2874. var z = array[ i + 2 ];
  2875. if ( x < minX ) minX = x;
  2876. if ( y < minY ) minY = y;
  2877. if ( z < minZ ) minZ = z;
  2878. if ( x > maxX ) maxX = x;
  2879. if ( y > maxY ) maxY = y;
  2880. if ( z > maxZ ) maxZ = z;
  2881. }
  2882. this.min.set( minX, minY, minZ );
  2883. this.max.set( maxX, maxY, maxZ );
  2884. return this;
  2885. },
  2886. setFromBufferAttribute: function ( attribute ) {
  2887. var minX = + Infinity;
  2888. var minY = + Infinity;
  2889. var minZ = + Infinity;
  2890. var maxX = - Infinity;
  2891. var maxY = - Infinity;
  2892. var maxZ = - Infinity;
  2893. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2894. var x = attribute.getX( i );
  2895. var y = attribute.getY( i );
  2896. var z = attribute.getZ( i );
  2897. if ( x < minX ) minX = x;
  2898. if ( y < minY ) minY = y;
  2899. if ( z < minZ ) minZ = z;
  2900. if ( x > maxX ) maxX = x;
  2901. if ( y > maxY ) maxY = y;
  2902. if ( z > maxZ ) maxZ = z;
  2903. }
  2904. this.min.set( minX, minY, minZ );
  2905. this.max.set( maxX, maxY, maxZ );
  2906. return this;
  2907. },
  2908. setFromPoints: function ( points ) {
  2909. this.makeEmpty();
  2910. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2911. this.expandByPoint( points[ i ] );
  2912. }
  2913. return this;
  2914. },
  2915. setFromCenterAndSize: function () {
  2916. var v1 = new Vector3();
  2917. return function setFromCenterAndSize( center, size ) {
  2918. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2919. this.min.copy( center ).sub( halfSize );
  2920. this.max.copy( center ).add( halfSize );
  2921. return this;
  2922. };
  2923. }(),
  2924. setFromObject: function ( object ) {
  2925. this.makeEmpty();
  2926. return this.expandByObject( object );
  2927. },
  2928. clone: function () {
  2929. return new this.constructor().copy( this );
  2930. },
  2931. copy: function ( box ) {
  2932. this.min.copy( box.min );
  2933. this.max.copy( box.max );
  2934. return this;
  2935. },
  2936. makeEmpty: function () {
  2937. this.min.x = this.min.y = this.min.z = + Infinity;
  2938. this.max.x = this.max.y = this.max.z = - Infinity;
  2939. return this;
  2940. },
  2941. isEmpty: function () {
  2942. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2943. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2944. },
  2945. getCenter: function ( target ) {
  2946. if ( target === undefined ) {
  2947. console.warn( 'THREE.Box3: .getCenter() target is now required' );
  2948. target = new Vector3();
  2949. }
  2950. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2951. },
  2952. getSize: function ( target ) {
  2953. if ( target === undefined ) {
  2954. console.warn( 'THREE.Box3: .getSize() target is now required' );
  2955. target = new Vector3();
  2956. }
  2957. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  2958. },
  2959. expandByPoint: function ( point ) {
  2960. this.min.min( point );
  2961. this.max.max( point );
  2962. return this;
  2963. },
  2964. expandByVector: function ( vector ) {
  2965. this.min.sub( vector );
  2966. this.max.add( vector );
  2967. return this;
  2968. },
  2969. expandByScalar: function ( scalar ) {
  2970. this.min.addScalar( - scalar );
  2971. this.max.addScalar( scalar );
  2972. return this;
  2973. },
  2974. expandByObject: function () {
  2975. // Computes the world-axis-aligned bounding box of an object (including its children),
  2976. // accounting for both the object's, and children's, world transforms
  2977. var scope, i, l;
  2978. var v1 = new Vector3();
  2979. function traverse( node ) {
  2980. var geometry = node.geometry;
  2981. if ( geometry !== undefined ) {
  2982. if ( geometry.isGeometry ) {
  2983. var vertices = geometry.vertices;
  2984. for ( i = 0, l = vertices.length; i < l; i ++ ) {
  2985. v1.copy( vertices[ i ] );
  2986. v1.applyMatrix4( node.matrixWorld );
  2987. scope.expandByPoint( v1 );
  2988. }
  2989. } else if ( geometry.isBufferGeometry ) {
  2990. var attribute = geometry.attributes.position;
  2991. if ( attribute !== undefined ) {
  2992. for ( i = 0, l = attribute.count; i < l; i ++ ) {
  2993. v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
  2994. scope.expandByPoint( v1 );
  2995. }
  2996. }
  2997. }
  2998. }
  2999. }
  3000. return function expandByObject( object ) {
  3001. scope = this;
  3002. object.updateMatrixWorld( true );
  3003. object.traverse( traverse );
  3004. return this;
  3005. };
  3006. }(),
  3007. containsPoint: function ( point ) {
  3008. return point.x < this.min.x || point.x > this.max.x ||
  3009. point.y < this.min.y || point.y > this.max.y ||
  3010. point.z < this.min.z || point.z > this.max.z ? false : true;
  3011. },
  3012. containsBox: function ( box ) {
  3013. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  3014. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  3015. this.min.z <= box.min.z && box.max.z <= this.max.z;
  3016. },
  3017. getParameter: function ( point, target ) {
  3018. // This can potentially have a divide by zero if the box
  3019. // has a size dimension of 0.
  3020. if ( target === undefined ) {
  3021. console.warn( 'THREE.Box3: .getParameter() target is now required' );
  3022. target = new Vector3();
  3023. }
  3024. return target.set(
  3025. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  3026. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  3027. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  3028. );
  3029. },
  3030. intersectsBox: function ( box ) {
  3031. // using 6 splitting planes to rule out intersections.
  3032. return box.max.x < this.min.x || box.min.x > this.max.x ||
  3033. box.max.y < this.min.y || box.min.y > this.max.y ||
  3034. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  3035. },
  3036. intersectsSphere: ( function () {
  3037. var closestPoint = new Vector3();
  3038. return function intersectsSphere( sphere ) {
  3039. // Find the point on the AABB closest to the sphere center.
  3040. this.clampPoint( sphere.center, closestPoint );
  3041. // If that point is inside the sphere, the AABB and sphere intersect.
  3042. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  3043. };
  3044. } )(),
  3045. intersectsPlane: function ( plane ) {
  3046. // We compute the minimum and maximum dot product values. If those values
  3047. // are on the same side (back or front) of the plane, then there is no intersection.
  3048. var min, max;
  3049. if ( plane.normal.x > 0 ) {
  3050. min = plane.normal.x * this.min.x;
  3051. max = plane.normal.x * this.max.x;
  3052. } else {
  3053. min = plane.normal.x * this.max.x;
  3054. max = plane.normal.x * this.min.x;
  3055. }
  3056. if ( plane.normal.y > 0 ) {
  3057. min += plane.normal.y * this.min.y;
  3058. max += plane.normal.y * this.max.y;
  3059. } else {
  3060. min += plane.normal.y * this.max.y;
  3061. max += plane.normal.y * this.min.y;
  3062. }
  3063. if ( plane.normal.z > 0 ) {
  3064. min += plane.normal.z * this.min.z;
  3065. max += plane.normal.z * this.max.z;
  3066. } else {
  3067. min += plane.normal.z * this.max.z;
  3068. max += plane.normal.z * this.min.z;
  3069. }
  3070. return ( min <= plane.constant && max >= plane.constant );
  3071. },
  3072. intersectsTriangle: ( function () {
  3073. // triangle centered vertices
  3074. var v0 = new Vector3();
  3075. var v1 = new Vector3();
  3076. var v2 = new Vector3();
  3077. // triangle edge vectors
  3078. var f0 = new Vector3();
  3079. var f1 = new Vector3();
  3080. var f2 = new Vector3();
  3081. var testAxis = new Vector3();
  3082. var center = new Vector3();
  3083. var extents = new Vector3();
  3084. var triangleNormal = new Vector3();
  3085. function satForAxes( axes ) {
  3086. var i, j;
  3087. for ( i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  3088. testAxis.fromArray( axes, i );
  3089. // project the aabb onto the seperating axis
  3090. var r = extents.x * Math.abs( testAxis.x ) + extents.y * Math.abs( testAxis.y ) + extents.z * Math.abs( testAxis.z );
  3091. // project all 3 vertices of the triangle onto the seperating axis
  3092. var p0 = v0.dot( testAxis );
  3093. var p1 = v1.dot( testAxis );
  3094. var p2 = v2.dot( testAxis );
  3095. // actual test, basically see if either of the most extreme of the triangle points intersects r
  3096. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  3097. // points of the projected triangle are outside the projected half-length of the aabb
  3098. // the axis is seperating and we can exit
  3099. return false;
  3100. }
  3101. }
  3102. return true;
  3103. }
  3104. return function intersectsTriangle( triangle ) {
  3105. if ( this.isEmpty() ) {
  3106. return false;
  3107. }
  3108. // compute box center and extents
  3109. this.getCenter( center );
  3110. extents.subVectors( this.max, center );
  3111. // translate triangle to aabb origin
  3112. v0.subVectors( triangle.a, center );
  3113. v1.subVectors( triangle.b, center );
  3114. v2.subVectors( triangle.c, center );
  3115. // compute edge vectors for triangle
  3116. f0.subVectors( v1, v0 );
  3117. f1.subVectors( v2, v1 );
  3118. f2.subVectors( v0, v2 );
  3119. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  3120. // 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
  3121. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3122. var axes = [
  3123. 0, - f0.z, f0.y, 0, - f1.z, f1.y, 0, - f2.z, f2.y,
  3124. f0.z, 0, - f0.x, f1.z, 0, - f1.x, f2.z, 0, - f2.x,
  3125. - f0.y, f0.x, 0, - f1.y, f1.x, 0, - f2.y, f2.x, 0
  3126. ];
  3127. if ( ! satForAxes( axes ) ) {
  3128. return false;
  3129. }
  3130. // test 3 face normals from the aabb
  3131. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  3132. if ( ! satForAxes( axes ) ) {
  3133. return false;
  3134. }
  3135. // finally testing the face normal of the triangle
  3136. // use already existing triangle edge vectors here
  3137. triangleNormal.crossVectors( f0, f1 );
  3138. axes = [ triangleNormal.x, triangleNormal.y, triangleNormal.z ];
  3139. return satForAxes( axes );
  3140. };
  3141. } )(),
  3142. clampPoint: function ( point, target ) {
  3143. if ( target === undefined ) {
  3144. console.warn( 'THREE.Box3: .clampPoint() target is now required' );
  3145. target = new Vector3();
  3146. }
  3147. return target.copy( point ).clamp( this.min, this.max );
  3148. },
  3149. distanceToPoint: function () {
  3150. var v1 = new Vector3();
  3151. return function distanceToPoint( point ) {
  3152. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  3153. return clampedPoint.sub( point ).length();
  3154. };
  3155. }(),
  3156. getBoundingSphere: function () {
  3157. var v1 = new Vector3();
  3158. return function getBoundingSphere( target ) {
  3159. if ( target === undefined ) {
  3160. console.warn( 'THREE.Box3: .getBoundingSphere() target is now required' );
  3161. target = new Sphere();
  3162. }
  3163. this.getCenter( target.center );
  3164. target.radius = this.getSize( v1 ).length() * 0.5;
  3165. return target;
  3166. };
  3167. }(),
  3168. intersect: function ( box ) {
  3169. this.min.max( box.min );
  3170. this.max.min( box.max );
  3171. // 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.
  3172. if ( this.isEmpty() ) this.makeEmpty();
  3173. return this;
  3174. },
  3175. union: function ( box ) {
  3176. this.min.min( box.min );
  3177. this.max.max( box.max );
  3178. return this;
  3179. },
  3180. applyMatrix4: function ( matrix ) {
  3181. // transform of empty box is an empty box.
  3182. if ( this.isEmpty( ) ) return this;
  3183. var m = matrix.elements;
  3184. var xax = m[ 0 ] * this.min.x, xay = m[ 1 ] * this.min.x, xaz = m[ 2 ] * this.min.x;
  3185. var xbx = m[ 0 ] * this.max.x, xby = m[ 1 ] * this.max.x, xbz = m[ 2 ] * this.max.x;
  3186. var yax = m[ 4 ] * this.min.y, yay = m[ 5 ] * this.min.y, yaz = m[ 6 ] * this.min.y;
  3187. var ybx = m[ 4 ] * this.max.y, yby = m[ 5 ] * this.max.y, ybz = m[ 6 ] * this.max.y;
  3188. var zax = m[ 8 ] * this.min.z, zay = m[ 9 ] * this.min.z, zaz = m[ 10 ] * this.min.z;
  3189. var zbx = m[ 8 ] * this.max.z, zby = m[ 9 ] * this.max.z, zbz = m[ 10 ] * this.max.z;
  3190. this.min.x = Math.min( xax, xbx ) + Math.min( yax, ybx ) + Math.min( zax, zbx ) + m[ 12 ];
  3191. this.min.y = Math.min( xay, xby ) + Math.min( yay, yby ) + Math.min( zay, zby ) + m[ 13 ];
  3192. this.min.z = Math.min( xaz, xbz ) + Math.min( yaz, ybz ) + Math.min( zaz, zbz ) + m[ 14 ];
  3193. this.max.x = Math.max( xax, xbx ) + Math.max( yax, ybx ) + Math.max( zax, zbx ) + m[ 12 ];
  3194. this.max.y = Math.max( xay, xby ) + Math.max( yay, yby ) + Math.max( zay, zby ) + m[ 13 ];
  3195. this.max.z = Math.max( xaz, xbz ) + Math.max( yaz, ybz ) + Math.max( zaz, zbz ) + m[ 14 ];
  3196. return this;
  3197. },
  3198. translate: function ( offset ) {
  3199. this.min.add( offset );
  3200. this.max.add( offset );
  3201. return this;
  3202. },
  3203. equals: function ( box ) {
  3204. return box.min.equals( this.min ) && box.max.equals( this.max );
  3205. }
  3206. } );
  3207. /**
  3208. * @author bhouston / http://clara.io
  3209. * @author mrdoob / http://mrdoob.com/
  3210. */
  3211. function Sphere( center, radius ) {
  3212. this.center = ( center !== undefined ) ? center : new Vector3();
  3213. this.radius = ( radius !== undefined ) ? radius : 0;
  3214. }
  3215. Object.assign( Sphere.prototype, {
  3216. set: function ( center, radius ) {
  3217. this.center.copy( center );
  3218. this.radius = radius;
  3219. return this;
  3220. },
  3221. setFromPoints: function () {
  3222. var box = new Box3();
  3223. return function setFromPoints( points, optionalCenter ) {
  3224. var center = this.center;
  3225. if ( optionalCenter !== undefined ) {
  3226. center.copy( optionalCenter );
  3227. } else {
  3228. box.setFromPoints( points ).getCenter( center );
  3229. }
  3230. var maxRadiusSq = 0;
  3231. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3232. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3233. }
  3234. this.radius = Math.sqrt( maxRadiusSq );
  3235. return this;
  3236. };
  3237. }(),
  3238. clone: function () {
  3239. return new this.constructor().copy( this );
  3240. },
  3241. copy: function ( sphere ) {
  3242. this.center.copy( sphere.center );
  3243. this.radius = sphere.radius;
  3244. return this;
  3245. },
  3246. empty: function () {
  3247. return ( this.radius <= 0 );
  3248. },
  3249. containsPoint: function ( point ) {
  3250. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3251. },
  3252. distanceToPoint: function ( point ) {
  3253. return ( point.distanceTo( this.center ) - this.radius );
  3254. },
  3255. intersectsSphere: function ( sphere ) {
  3256. var radiusSum = this.radius + sphere.radius;
  3257. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3258. },
  3259. intersectsBox: function ( box ) {
  3260. return box.intersectsSphere( this );
  3261. },
  3262. intersectsPlane: function ( plane ) {
  3263. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  3264. },
  3265. clampPoint: function ( point, target ) {
  3266. var deltaLengthSq = this.center.distanceToSquared( point );
  3267. if ( target === undefined ) {
  3268. console.warn( 'THREE.Sphere: .clampPoint() target is now required' );
  3269. target = new Vector3();
  3270. }
  3271. target.copy( point );
  3272. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3273. target.sub( this.center ).normalize();
  3274. target.multiplyScalar( this.radius ).add( this.center );
  3275. }
  3276. return target;
  3277. },
  3278. getBoundingBox: function ( target ) {
  3279. if ( target === undefined ) {
  3280. console.warn( 'THREE.Sphere: .getBoundingBox() target is now required' );
  3281. target = new Box3();
  3282. }
  3283. target.set( this.center, this.center );
  3284. target.expandByScalar( this.radius );
  3285. return target;
  3286. },
  3287. applyMatrix4: function ( matrix ) {
  3288. this.center.applyMatrix4( matrix );
  3289. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3290. return this;
  3291. },
  3292. translate: function ( offset ) {
  3293. this.center.add( offset );
  3294. return this;
  3295. },
  3296. equals: function ( sphere ) {
  3297. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3298. }
  3299. } );
  3300. /**
  3301. * @author bhouston / http://clara.io
  3302. */
  3303. function Plane( normal, constant ) {
  3304. // normal is assumed to be normalized
  3305. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  3306. this.constant = ( constant !== undefined ) ? constant : 0;
  3307. }
  3308. Object.assign( Plane.prototype, {
  3309. set: function ( normal, constant ) {
  3310. this.normal.copy( normal );
  3311. this.constant = constant;
  3312. return this;
  3313. },
  3314. setComponents: function ( x, y, z, w ) {
  3315. this.normal.set( x, y, z );
  3316. this.constant = w;
  3317. return this;
  3318. },
  3319. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3320. this.normal.copy( normal );
  3321. this.constant = - point.dot( this.normal );
  3322. return this;
  3323. },
  3324. setFromCoplanarPoints: function () {
  3325. var v1 = new Vector3();
  3326. var v2 = new Vector3();
  3327. return function setFromCoplanarPoints( a, b, c ) {
  3328. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3329. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3330. this.setFromNormalAndCoplanarPoint( normal, a );
  3331. return this;
  3332. };
  3333. }(),
  3334. clone: function () {
  3335. return new this.constructor().copy( this );
  3336. },
  3337. copy: function ( plane ) {
  3338. this.normal.copy( plane.normal );
  3339. this.constant = plane.constant;
  3340. return this;
  3341. },
  3342. normalize: function () {
  3343. // Note: will lead to a divide by zero if the plane is invalid.
  3344. var inverseNormalLength = 1.0 / this.normal.length();
  3345. this.normal.multiplyScalar( inverseNormalLength );
  3346. this.constant *= inverseNormalLength;
  3347. return this;
  3348. },
  3349. negate: function () {
  3350. this.constant *= - 1;
  3351. this.normal.negate();
  3352. return this;
  3353. },
  3354. distanceToPoint: function ( point ) {
  3355. return this.normal.dot( point ) + this.constant;
  3356. },
  3357. distanceToSphere: function ( sphere ) {
  3358. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3359. },
  3360. projectPoint: function ( point, target ) {
  3361. if ( target === undefined ) {
  3362. console.warn( 'THREE.Plane: .projectPoint() target is now required' );
  3363. target = new Vector3();
  3364. }
  3365. return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  3366. },
  3367. intersectLine: function () {
  3368. var v1 = new Vector3();
  3369. return function intersectLine( line, target ) {
  3370. if ( target === undefined ) {
  3371. console.warn( 'THREE.Plane: .intersectLine() target is now required' );
  3372. target = new Vector3();
  3373. }
  3374. var direction = line.delta( v1 );
  3375. var denominator = this.normal.dot( direction );
  3376. if ( denominator === 0 ) {
  3377. // line is coplanar, return origin
  3378. if ( this.distanceToPoint( line.start ) === 0 ) {
  3379. return target.copy( line.start );
  3380. }
  3381. // Unsure if this is the correct method to handle this case.
  3382. return undefined;
  3383. }
  3384. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  3385. if ( t < 0 || t > 1 ) {
  3386. return undefined;
  3387. }
  3388. return target.copy( direction ).multiplyScalar( t ).add( line.start );
  3389. };
  3390. }(),
  3391. intersectsLine: function ( line ) {
  3392. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  3393. var startSign = this.distanceToPoint( line.start );
  3394. var endSign = this.distanceToPoint( line.end );
  3395. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  3396. },
  3397. intersectsBox: function ( box ) {
  3398. return box.intersectsPlane( this );
  3399. },
  3400. intersectsSphere: function ( sphere ) {
  3401. return sphere.intersectsPlane( this );
  3402. },
  3403. coplanarPoint: function ( target ) {
  3404. if ( target === undefined ) {
  3405. console.warn( 'THREE.Plane: .coplanarPoint() target is now required' );
  3406. target = new Vector3();
  3407. }
  3408. return target.copy( this.normal ).multiplyScalar( - this.constant );
  3409. },
  3410. applyMatrix4: function () {
  3411. var v1 = new Vector3();
  3412. var m1 = new Matrix3();
  3413. return function applyMatrix4( matrix, optionalNormalMatrix ) {
  3414. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  3415. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  3416. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  3417. this.constant = - referencePoint.dot( normal );
  3418. return this;
  3419. };
  3420. }(),
  3421. translate: function ( offset ) {
  3422. this.constant -= offset.dot( this.normal );
  3423. return this;
  3424. },
  3425. equals: function ( plane ) {
  3426. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  3427. }
  3428. } );
  3429. /**
  3430. * @author mrdoob / http://mrdoob.com/
  3431. * @author alteredq / http://alteredqualia.com/
  3432. * @author bhouston / http://clara.io
  3433. */
  3434. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  3435. this.planes = [
  3436. ( p0 !== undefined ) ? p0 : new Plane(),
  3437. ( p1 !== undefined ) ? p1 : new Plane(),
  3438. ( p2 !== undefined ) ? p2 : new Plane(),
  3439. ( p3 !== undefined ) ? p3 : new Plane(),
  3440. ( p4 !== undefined ) ? p4 : new Plane(),
  3441. ( p5 !== undefined ) ? p5 : new Plane()
  3442. ];
  3443. }
  3444. Object.assign( Frustum.prototype, {
  3445. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3446. var planes = this.planes;
  3447. planes[ 0 ].copy( p0 );
  3448. planes[ 1 ].copy( p1 );
  3449. planes[ 2 ].copy( p2 );
  3450. planes[ 3 ].copy( p3 );
  3451. planes[ 4 ].copy( p4 );
  3452. planes[ 5 ].copy( p5 );
  3453. return this;
  3454. },
  3455. clone: function () {
  3456. return new this.constructor().copy( this );
  3457. },
  3458. copy: function ( frustum ) {
  3459. var planes = this.planes;
  3460. for ( var i = 0; i < 6; i ++ ) {
  3461. planes[ i ].copy( frustum.planes[ i ] );
  3462. }
  3463. return this;
  3464. },
  3465. setFromMatrix: function ( m ) {
  3466. var planes = this.planes;
  3467. var me = m.elements;
  3468. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3469. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3470. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3471. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3472. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3473. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3474. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3475. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3476. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3477. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3478. return this;
  3479. },
  3480. intersectsObject: function () {
  3481. var sphere = new Sphere();
  3482. return function intersectsObject( object ) {
  3483. var geometry = object.geometry;
  3484. if ( geometry.boundingSphere === null )
  3485. geometry.computeBoundingSphere();
  3486. sphere.copy( geometry.boundingSphere )
  3487. .applyMatrix4( object.matrixWorld );
  3488. return this.intersectsSphere( sphere );
  3489. };
  3490. }(),
  3491. intersectsSprite: function () {
  3492. var sphere = new Sphere();
  3493. return function intersectsSprite( sprite ) {
  3494. sphere.center.set( 0, 0, 0 );
  3495. sphere.radius = 0.7071067811865476;
  3496. sphere.applyMatrix4( sprite.matrixWorld );
  3497. return this.intersectsSphere( sphere );
  3498. };
  3499. }(),
  3500. intersectsSphere: function ( sphere ) {
  3501. var planes = this.planes;
  3502. var center = sphere.center;
  3503. var negRadius = - sphere.radius;
  3504. for ( var i = 0; i < 6; i ++ ) {
  3505. var distance = planes[ i ].distanceToPoint( center );
  3506. if ( distance < negRadius ) {
  3507. return false;
  3508. }
  3509. }
  3510. return true;
  3511. },
  3512. intersectsBox: function () {
  3513. var p1 = new Vector3(),
  3514. p2 = new Vector3();
  3515. return function intersectsBox( box ) {
  3516. var planes = this.planes;
  3517. for ( var i = 0; i < 6; i ++ ) {
  3518. var plane = planes[ i ];
  3519. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3520. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3521. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3522. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3523. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3524. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3525. var d1 = plane.distanceToPoint( p1 );
  3526. var d2 = plane.distanceToPoint( p2 );
  3527. // if both outside plane, no intersection
  3528. if ( d1 < 0 && d2 < 0 ) {
  3529. return false;
  3530. }
  3531. }
  3532. return true;
  3533. };
  3534. }(),
  3535. containsPoint: function ( point ) {
  3536. var planes = this.planes;
  3537. for ( var i = 0; i < 6; i ++ ) {
  3538. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3539. return false;
  3540. }
  3541. }
  3542. return true;
  3543. }
  3544. } );
  3545. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif\n";
  3546. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif\n";
  3547. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif\n";
  3548. 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";
  3549. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  3550. var begin_vertex = "\nvec3 transformed = vec3( position );\n";
  3551. var beginnormal_vertex = "\nvec3 objectNormal = vec3( normal );\n";
  3552. 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";
  3553. var bumpmap_pars_fragment = "#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vUv );\n\t\tvec2 dSTdy = dFdy( vUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\n\t\tvec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n\t\tvec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 );\n\t\tfDet *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif\n";
  3554. 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";
  3555. 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";
  3556. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n\tvarying vec3 vViewPosition;\n#endif\n";
  3557. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n";
  3558. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  3559. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif\n";
  3560. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  3561. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  3562. 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";
  3563. 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";
  3564. var defaultnormal_vertex = "vec3 transformedNormal = normalMatrix * objectNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n";
  3565. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif\n";
  3566. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif\n";
  3567. 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";
  3568. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif\n";
  3569. var encodings_fragment = " gl_FragColor = linearToOutputTexel( gl_FragColor );\n";
  3570. 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";
  3571. 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";
  3572. 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";
  3573. 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";
  3574. 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";
  3575. var fog_vertex = "\n#ifdef USE_FOG\nfogDepth = -mvPosition.z;\n#endif";
  3576. var fog_pars_vertex = "#ifdef USE_FOG\n varying float fogDepth;\n#endif\n";
  3577. 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";
  3578. 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";
  3579. 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";
  3580. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\treflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif\n";
  3581. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  3582. 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";
  3583. 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";
  3584. 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";
  3585. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;\n";
  3586. 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";
  3587. 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";
  3588. 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";
  3589. 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";
  3590. 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";
  3591. 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";
  3592. var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";
  3593. 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";
  3594. 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";
  3595. 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";
  3596. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif\n";
  3597. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n";
  3598. 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";
  3599. var map_particle_pars_fragment = "#ifdef USE_MAP\n\tuniform mat3 uvTransform;\n\tuniform sampler2D map;\n#endif\n";
  3600. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif\n";
  3601. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  3602. 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";
  3603. 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";
  3604. 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";
  3605. 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";
  3606. 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";
  3607. 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 );\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\tmat3 tsn = mat3( S, T, N );\n\t\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\tmapN.xy *= normalScale;\n\t\tmapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\treturn normalize( tsn * mapN );\n\t}\n#endif\n";
  3608. 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";
  3609. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif\n";
  3610. var project_vertex = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = projectionMatrix * mvPosition;\n";
  3611. var dithering_fragment = "#if defined( DITHERING )\n gl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif\n";
  3612. 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";
  3613. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif\n";
  3614. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  3615. 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";
  3616. 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";
  3617. 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";
  3618. 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";
  3619. 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";
  3620. 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";
  3621. 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";
  3622. 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";
  3623. 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";
  3624. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  3625. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif\n";
  3626. 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";
  3627. 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";
  3628. 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";
  3629. 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";
  3630. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  3631. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n#endif";
  3632. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = uv2;\n#endif";
  3633. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n#endif\n";
  3634. 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";
  3635. 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";
  3636. 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";
  3637. 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";
  3638. 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";
  3639. 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";
  3640. 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";
  3641. 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";
  3642. 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";
  3643. 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";
  3644. 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";
  3645. 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";
  3646. 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";
  3647. 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";
  3648. 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";
  3649. 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";
  3650. 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";
  3651. 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";
  3652. 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";
  3653. 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";
  3654. 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 <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";
  3655. var points_vert = "uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\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 <fog_vertex>\n}\n";
  3656. 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";
  3657. 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";
  3658. var ShaderChunk = {
  3659. alphamap_fragment: alphamap_fragment,
  3660. alphamap_pars_fragment: alphamap_pars_fragment,
  3661. alphatest_fragment: alphatest_fragment,
  3662. aomap_fragment: aomap_fragment,
  3663. aomap_pars_fragment: aomap_pars_fragment,
  3664. begin_vertex: begin_vertex,
  3665. beginnormal_vertex: beginnormal_vertex,
  3666. bsdfs: bsdfs,
  3667. bumpmap_pars_fragment: bumpmap_pars_fragment,
  3668. clipping_planes_fragment: clipping_planes_fragment,
  3669. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  3670. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  3671. clipping_planes_vertex: clipping_planes_vertex,
  3672. color_fragment: color_fragment,
  3673. color_pars_fragment: color_pars_fragment,
  3674. color_pars_vertex: color_pars_vertex,
  3675. color_vertex: color_vertex,
  3676. common: common,
  3677. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  3678. defaultnormal_vertex: defaultnormal_vertex,
  3679. displacementmap_pars_vertex: displacementmap_pars_vertex,
  3680. displacementmap_vertex: displacementmap_vertex,
  3681. emissivemap_fragment: emissivemap_fragment,
  3682. emissivemap_pars_fragment: emissivemap_pars_fragment,
  3683. encodings_fragment: encodings_fragment,
  3684. encodings_pars_fragment: encodings_pars_fragment,
  3685. envmap_fragment: envmap_fragment,
  3686. envmap_pars_fragment: envmap_pars_fragment,
  3687. envmap_pars_vertex: envmap_pars_vertex,
  3688. envmap_vertex: envmap_vertex,
  3689. fog_vertex: fog_vertex,
  3690. fog_pars_vertex: fog_pars_vertex,
  3691. fog_fragment: fog_fragment,
  3692. fog_pars_fragment: fog_pars_fragment,
  3693. gradientmap_pars_fragment: gradientmap_pars_fragment,
  3694. lightmap_fragment: lightmap_fragment,
  3695. lightmap_pars_fragment: lightmap_pars_fragment,
  3696. lights_lambert_vertex: lights_lambert_vertex,
  3697. lights_pars_begin: lights_pars_begin,
  3698. lights_pars_maps: lights_pars_maps,
  3699. lights_phong_fragment: lights_phong_fragment,
  3700. lights_phong_pars_fragment: lights_phong_pars_fragment,
  3701. lights_physical_fragment: lights_physical_fragment,
  3702. lights_physical_pars_fragment: lights_physical_pars_fragment,
  3703. lights_fragment_begin: lights_fragment_begin,
  3704. lights_fragment_maps: lights_fragment_maps,
  3705. lights_fragment_end: lights_fragment_end,
  3706. logdepthbuf_fragment: logdepthbuf_fragment,
  3707. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  3708. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  3709. logdepthbuf_vertex: logdepthbuf_vertex,
  3710. map_fragment: map_fragment,
  3711. map_pars_fragment: map_pars_fragment,
  3712. map_particle_fragment: map_particle_fragment,
  3713. map_particle_pars_fragment: map_particle_pars_fragment,
  3714. metalnessmap_fragment: metalnessmap_fragment,
  3715. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  3716. morphnormal_vertex: morphnormal_vertex,
  3717. morphtarget_pars_vertex: morphtarget_pars_vertex,
  3718. morphtarget_vertex: morphtarget_vertex,
  3719. normal_fragment_begin: normal_fragment_begin,
  3720. normal_fragment_maps: normal_fragment_maps,
  3721. normalmap_pars_fragment: normalmap_pars_fragment,
  3722. packing: packing,
  3723. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  3724. project_vertex: project_vertex,
  3725. dithering_fragment: dithering_fragment,
  3726. dithering_pars_fragment: dithering_pars_fragment,
  3727. roughnessmap_fragment: roughnessmap_fragment,
  3728. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  3729. shadowmap_pars_fragment: shadowmap_pars_fragment,
  3730. shadowmap_pars_vertex: shadowmap_pars_vertex,
  3731. shadowmap_vertex: shadowmap_vertex,
  3732. shadowmask_pars_fragment: shadowmask_pars_fragment,
  3733. skinbase_vertex: skinbase_vertex,
  3734. skinning_pars_vertex: skinning_pars_vertex,
  3735. skinning_vertex: skinning_vertex,
  3736. skinnormal_vertex: skinnormal_vertex,
  3737. specularmap_fragment: specularmap_fragment,
  3738. specularmap_pars_fragment: specularmap_pars_fragment,
  3739. tonemapping_fragment: tonemapping_fragment,
  3740. tonemapping_pars_fragment: tonemapping_pars_fragment,
  3741. uv_pars_fragment: uv_pars_fragment,
  3742. uv_pars_vertex: uv_pars_vertex,
  3743. uv_vertex: uv_vertex,
  3744. uv2_pars_fragment: uv2_pars_fragment,
  3745. uv2_pars_vertex: uv2_pars_vertex,
  3746. uv2_vertex: uv2_vertex,
  3747. worldpos_vertex: worldpos_vertex,
  3748. cube_frag: cube_frag,
  3749. cube_vert: cube_vert,
  3750. depth_frag: depth_frag,
  3751. depth_vert: depth_vert,
  3752. distanceRGBA_frag: distanceRGBA_frag,
  3753. distanceRGBA_vert: distanceRGBA_vert,
  3754. equirect_frag: equirect_frag,
  3755. equirect_vert: equirect_vert,
  3756. linedashed_frag: linedashed_frag,
  3757. linedashed_vert: linedashed_vert,
  3758. meshbasic_frag: meshbasic_frag,
  3759. meshbasic_vert: meshbasic_vert,
  3760. meshlambert_frag: meshlambert_frag,
  3761. meshlambert_vert: meshlambert_vert,
  3762. meshphong_frag: meshphong_frag,
  3763. meshphong_vert: meshphong_vert,
  3764. meshphysical_frag: meshphysical_frag,
  3765. meshphysical_vert: meshphysical_vert,
  3766. normal_frag: normal_frag,
  3767. normal_vert: normal_vert,
  3768. points_frag: points_frag,
  3769. points_vert: points_vert,
  3770. shadow_frag: shadow_frag,
  3771. shadow_vert: shadow_vert
  3772. };
  3773. /**
  3774. * Uniform Utilities
  3775. */
  3776. var UniformsUtils = {
  3777. merge: function ( uniforms ) {
  3778. var merged = {};
  3779. for ( var u = 0; u < uniforms.length; u ++ ) {
  3780. var tmp = this.clone( uniforms[ u ] );
  3781. for ( var p in tmp ) {
  3782. merged[ p ] = tmp[ p ];
  3783. }
  3784. }
  3785. return merged;
  3786. },
  3787. clone: function ( uniforms_src ) {
  3788. var uniforms_dst = {};
  3789. for ( var u in uniforms_src ) {
  3790. uniforms_dst[ u ] = {};
  3791. for ( var p in uniforms_src[ u ] ) {
  3792. var parameter_src = uniforms_src[ u ][ p ];
  3793. if ( parameter_src && ( parameter_src.isColor ||
  3794. parameter_src.isMatrix3 || parameter_src.isMatrix4 ||
  3795. parameter_src.isVector2 || parameter_src.isVector3 || parameter_src.isVector4 ||
  3796. parameter_src.isTexture ) ) {
  3797. uniforms_dst[ u ][ p ] = parameter_src.clone();
  3798. } else if ( Array.isArray( parameter_src ) ) {
  3799. uniforms_dst[ u ][ p ] = parameter_src.slice();
  3800. } else {
  3801. uniforms_dst[ u ][ p ] = parameter_src;
  3802. }
  3803. }
  3804. }
  3805. return uniforms_dst;
  3806. }
  3807. };
  3808. /**
  3809. * @author mrdoob / http://mrdoob.com/
  3810. */
  3811. var ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  3812. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  3813. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  3814. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  3815. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  3816. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  3817. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  3818. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  3819. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  3820. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  3821. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  3822. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  3823. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  3824. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  3825. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  3826. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  3827. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  3828. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  3829. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  3830. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  3831. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  3832. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  3833. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  3834. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  3835. function Color( r, g, b ) {
  3836. if ( g === undefined && b === undefined ) {
  3837. // r is THREE.Color, hex or string
  3838. return this.set( r );
  3839. }
  3840. return this.setRGB( r, g, b );
  3841. }
  3842. Object.assign( Color.prototype, {
  3843. isColor: true,
  3844. r: 1, g: 1, b: 1,
  3845. set: function ( value ) {
  3846. if ( value && value.isColor ) {
  3847. this.copy( value );
  3848. } else if ( typeof value === 'number' ) {
  3849. this.setHex( value );
  3850. } else if ( typeof value === 'string' ) {
  3851. this.setStyle( value );
  3852. }
  3853. return this;
  3854. },
  3855. setScalar: function ( scalar ) {
  3856. this.r = scalar;
  3857. this.g = scalar;
  3858. this.b = scalar;
  3859. return this;
  3860. },
  3861. setHex: function ( hex ) {
  3862. hex = Math.floor( hex );
  3863. this.r = ( hex >> 16 & 255 ) / 255;
  3864. this.g = ( hex >> 8 & 255 ) / 255;
  3865. this.b = ( hex & 255 ) / 255;
  3866. return this;
  3867. },
  3868. setRGB: function ( r, g, b ) {
  3869. this.r = r;
  3870. this.g = g;
  3871. this.b = b;
  3872. return this;
  3873. },
  3874. setHSL: function () {
  3875. function hue2rgb( p, q, t ) {
  3876. if ( t < 0 ) t += 1;
  3877. if ( t > 1 ) t -= 1;
  3878. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  3879. if ( t < 1 / 2 ) return q;
  3880. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  3881. return p;
  3882. }
  3883. return function setHSL( h, s, l ) {
  3884. // h,s,l ranges are in 0.0 - 1.0
  3885. h = _Math.euclideanModulo( h, 1 );
  3886. s = _Math.clamp( s, 0, 1 );
  3887. l = _Math.clamp( l, 0, 1 );
  3888. if ( s === 0 ) {
  3889. this.r = this.g = this.b = l;
  3890. } else {
  3891. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  3892. var q = ( 2 * l ) - p;
  3893. this.r = hue2rgb( q, p, h + 1 / 3 );
  3894. this.g = hue2rgb( q, p, h );
  3895. this.b = hue2rgb( q, p, h - 1 / 3 );
  3896. }
  3897. return this;
  3898. };
  3899. }(),
  3900. setStyle: function ( style ) {
  3901. function handleAlpha( string ) {
  3902. if ( string === undefined ) return;
  3903. if ( parseFloat( string ) < 1 ) {
  3904. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  3905. }
  3906. }
  3907. var m;
  3908. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  3909. // rgb / hsl
  3910. var color;
  3911. var name = m[ 1 ];
  3912. var components = m[ 2 ];
  3913. switch ( name ) {
  3914. case 'rgb':
  3915. case 'rgba':
  3916. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  3917. // rgb(255,0,0) rgba(255,0,0,0.5)
  3918. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  3919. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  3920. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  3921. handleAlpha( color[ 5 ] );
  3922. return this;
  3923. }
  3924. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  3925. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  3926. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  3927. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  3928. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  3929. handleAlpha( color[ 5 ] );
  3930. return this;
  3931. }
  3932. break;
  3933. case 'hsl':
  3934. case 'hsla':
  3935. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  3936. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  3937. var h = parseFloat( color[ 1 ] ) / 360;
  3938. var s = parseInt( color[ 2 ], 10 ) / 100;
  3939. var l = parseInt( color[ 3 ], 10 ) / 100;
  3940. handleAlpha( color[ 5 ] );
  3941. return this.setHSL( h, s, l );
  3942. }
  3943. break;
  3944. }
  3945. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  3946. // hex color
  3947. var hex = m[ 1 ];
  3948. var size = hex.length;
  3949. if ( size === 3 ) {
  3950. // #ff0
  3951. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  3952. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  3953. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  3954. return this;
  3955. } else if ( size === 6 ) {
  3956. // #ff0000
  3957. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  3958. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  3959. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  3960. return this;
  3961. }
  3962. }
  3963. if ( style && style.length > 0 ) {
  3964. // color keywords
  3965. var hex = ColorKeywords[ style ];
  3966. if ( hex !== undefined ) {
  3967. // red
  3968. this.setHex( hex );
  3969. } else {
  3970. // unknown color
  3971. console.warn( 'THREE.Color: Unknown color ' + style );
  3972. }
  3973. }
  3974. return this;
  3975. },
  3976. clone: function () {
  3977. return new this.constructor( this.r, this.g, this.b );
  3978. },
  3979. copy: function ( color ) {
  3980. this.r = color.r;
  3981. this.g = color.g;
  3982. this.b = color.b;
  3983. return this;
  3984. },
  3985. copyGammaToLinear: function ( color, gammaFactor ) {
  3986. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  3987. this.r = Math.pow( color.r, gammaFactor );
  3988. this.g = Math.pow( color.g, gammaFactor );
  3989. this.b = Math.pow( color.b, gammaFactor );
  3990. return this;
  3991. },
  3992. copyLinearToGamma: function ( color, gammaFactor ) {
  3993. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  3994. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  3995. this.r = Math.pow( color.r, safeInverse );
  3996. this.g = Math.pow( color.g, safeInverse );
  3997. this.b = Math.pow( color.b, safeInverse );
  3998. return this;
  3999. },
  4000. convertGammaToLinear: function ( gammaFactor ) {
  4001. this.copyGammaToLinear( this, gammaFactor );
  4002. return this;
  4003. },
  4004. convertLinearToGamma: function ( gammaFactor ) {
  4005. this.copyLinearToGamma( this, gammaFactor );
  4006. return this;
  4007. },
  4008. getHex: function () {
  4009. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  4010. },
  4011. getHexString: function () {
  4012. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  4013. },
  4014. getHSL: function ( target ) {
  4015. // h,s,l ranges are in 0.0 - 1.0
  4016. if ( target === undefined ) {
  4017. console.warn( 'THREE.Color: .getHSL() target is now required' );
  4018. target = { h: 0, s: 0, l: 0 };
  4019. }
  4020. var r = this.r, g = this.g, b = this.b;
  4021. var max = Math.max( r, g, b );
  4022. var min = Math.min( r, g, b );
  4023. var hue, saturation;
  4024. var lightness = ( min + max ) / 2.0;
  4025. if ( min === max ) {
  4026. hue = 0;
  4027. saturation = 0;
  4028. } else {
  4029. var delta = max - min;
  4030. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  4031. switch ( max ) {
  4032. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  4033. case g: hue = ( b - r ) / delta + 2; break;
  4034. case b: hue = ( r - g ) / delta + 4; break;
  4035. }
  4036. hue /= 6;
  4037. }
  4038. target.h = hue;
  4039. target.s = saturation;
  4040. target.l = lightness;
  4041. return target;
  4042. },
  4043. getStyle: function () {
  4044. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  4045. },
  4046. offsetHSL: function () {
  4047. var hsl = {};
  4048. return function ( h, s, l ) {
  4049. this.getHSL( hsl );
  4050. hsl.h += h; hsl.s += s; hsl.l += l;
  4051. this.setHSL( hsl.h, hsl.s, hsl.l );
  4052. return this;
  4053. };
  4054. }(),
  4055. add: function ( color ) {
  4056. this.r += color.r;
  4057. this.g += color.g;
  4058. this.b += color.b;
  4059. return this;
  4060. },
  4061. addColors: function ( color1, color2 ) {
  4062. this.r = color1.r + color2.r;
  4063. this.g = color1.g + color2.g;
  4064. this.b = color1.b + color2.b;
  4065. return this;
  4066. },
  4067. addScalar: function ( s ) {
  4068. this.r += s;
  4069. this.g += s;
  4070. this.b += s;
  4071. return this;
  4072. },
  4073. sub: function ( color ) {
  4074. this.r = Math.max( 0, this.r - color.r );
  4075. this.g = Math.max( 0, this.g - color.g );
  4076. this.b = Math.max( 0, this.b - color.b );
  4077. return this;
  4078. },
  4079. multiply: function ( color ) {
  4080. this.r *= color.r;
  4081. this.g *= color.g;
  4082. this.b *= color.b;
  4083. return this;
  4084. },
  4085. multiplyScalar: function ( s ) {
  4086. this.r *= s;
  4087. this.g *= s;
  4088. this.b *= s;
  4089. return this;
  4090. },
  4091. lerp: function ( color, alpha ) {
  4092. this.r += ( color.r - this.r ) * alpha;
  4093. this.g += ( color.g - this.g ) * alpha;
  4094. this.b += ( color.b - this.b ) * alpha;
  4095. return this;
  4096. },
  4097. equals: function ( c ) {
  4098. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  4099. },
  4100. fromArray: function ( array, offset ) {
  4101. if ( offset === undefined ) offset = 0;
  4102. this.r = array[ offset ];
  4103. this.g = array[ offset + 1 ];
  4104. this.b = array[ offset + 2 ];
  4105. return this;
  4106. },
  4107. toArray: function ( array, offset ) {
  4108. if ( array === undefined ) array = [];
  4109. if ( offset === undefined ) offset = 0;
  4110. array[ offset ] = this.r;
  4111. array[ offset + 1 ] = this.g;
  4112. array[ offset + 2 ] = this.b;
  4113. return array;
  4114. },
  4115. toJSON: function () {
  4116. return this.getHex();
  4117. }
  4118. } );
  4119. /**
  4120. * Uniforms library for shared webgl shaders
  4121. */
  4122. var UniformsLib = {
  4123. common: {
  4124. diffuse: { value: new Color( 0xeeeeee ) },
  4125. opacity: { value: 1.0 },
  4126. map: { value: null },
  4127. uvTransform: { value: new Matrix3() },
  4128. alphaMap: { value: null },
  4129. },
  4130. specularmap: {
  4131. specularMap: { value: null },
  4132. },
  4133. envmap: {
  4134. envMap: { value: null },
  4135. flipEnvMap: { value: - 1 },
  4136. reflectivity: { value: 1.0 },
  4137. refractionRatio: { value: 0.98 },
  4138. maxMipLevel: { value: 0 }
  4139. },
  4140. aomap: {
  4141. aoMap: { value: null },
  4142. aoMapIntensity: { value: 1 }
  4143. },
  4144. lightmap: {
  4145. lightMap: { value: null },
  4146. lightMapIntensity: { value: 1 }
  4147. },
  4148. emissivemap: {
  4149. emissiveMap: { value: null }
  4150. },
  4151. bumpmap: {
  4152. bumpMap: { value: null },
  4153. bumpScale: { value: 1 }
  4154. },
  4155. normalmap: {
  4156. normalMap: { value: null },
  4157. normalScale: { value: new Vector2( 1, 1 ) }
  4158. },
  4159. displacementmap: {
  4160. displacementMap: { value: null },
  4161. displacementScale: { value: 1 },
  4162. displacementBias: { value: 0 }
  4163. },
  4164. roughnessmap: {
  4165. roughnessMap: { value: null }
  4166. },
  4167. metalnessmap: {
  4168. metalnessMap: { value: null }
  4169. },
  4170. gradientmap: {
  4171. gradientMap: { value: null }
  4172. },
  4173. fog: {
  4174. fogDensity: { value: 0.00025 },
  4175. fogNear: { value: 1 },
  4176. fogFar: { value: 2000 },
  4177. fogColor: { value: new Color( 0xffffff ) }
  4178. },
  4179. lights: {
  4180. ambientLightColor: { value: [] },
  4181. directionalLights: { value: [], properties: {
  4182. direction: {},
  4183. color: {},
  4184. shadow: {},
  4185. shadowBias: {},
  4186. shadowRadius: {},
  4187. shadowMapSize: {}
  4188. } },
  4189. directionalShadowMap: { value: [] },
  4190. directionalShadowMatrix: { value: [] },
  4191. spotLights: { value: [], properties: {
  4192. color: {},
  4193. position: {},
  4194. direction: {},
  4195. distance: {},
  4196. coneCos: {},
  4197. penumbraCos: {},
  4198. decay: {},
  4199. shadow: {},
  4200. shadowBias: {},
  4201. shadowRadius: {},
  4202. shadowMapSize: {}
  4203. } },
  4204. spotShadowMap: { value: [] },
  4205. spotShadowMatrix: { value: [] },
  4206. pointLights: { value: [], properties: {
  4207. color: {},
  4208. position: {},
  4209. decay: {},
  4210. distance: {},
  4211. shadow: {},
  4212. shadowBias: {},
  4213. shadowRadius: {},
  4214. shadowMapSize: {},
  4215. shadowCameraNear: {},
  4216. shadowCameraFar: {}
  4217. } },
  4218. pointShadowMap: { value: [] },
  4219. pointShadowMatrix: { value: [] },
  4220. hemisphereLights: { value: [], properties: {
  4221. direction: {},
  4222. skyColor: {},
  4223. groundColor: {}
  4224. } },
  4225. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  4226. rectAreaLights: { value: [], properties: {
  4227. color: {},
  4228. position: {},
  4229. width: {},
  4230. height: {}
  4231. } }
  4232. },
  4233. points: {
  4234. diffuse: { value: new Color( 0xeeeeee ) },
  4235. opacity: { value: 1.0 },
  4236. size: { value: 1.0 },
  4237. scale: { value: 1.0 },
  4238. map: { value: null },
  4239. uvTransform: { value: new Matrix3() }
  4240. }
  4241. };
  4242. /**
  4243. * @author alteredq / http://alteredqualia.com/
  4244. * @author mrdoob / http://mrdoob.com/
  4245. * @author mikael emtinger / http://gomo.se/
  4246. */
  4247. var ShaderLib = {
  4248. basic: {
  4249. uniforms: UniformsUtils.merge( [
  4250. UniformsLib.common,
  4251. UniformsLib.specularmap,
  4252. UniformsLib.envmap,
  4253. UniformsLib.aomap,
  4254. UniformsLib.lightmap,
  4255. UniformsLib.fog
  4256. ] ),
  4257. vertexShader: ShaderChunk.meshbasic_vert,
  4258. fragmentShader: ShaderChunk.meshbasic_frag
  4259. },
  4260. lambert: {
  4261. uniforms: UniformsUtils.merge( [
  4262. UniformsLib.common,
  4263. UniformsLib.specularmap,
  4264. UniformsLib.envmap,
  4265. UniformsLib.aomap,
  4266. UniformsLib.lightmap,
  4267. UniformsLib.emissivemap,
  4268. UniformsLib.fog,
  4269. UniformsLib.lights,
  4270. {
  4271. emissive: { value: new Color( 0x000000 ) }
  4272. }
  4273. ] ),
  4274. vertexShader: ShaderChunk.meshlambert_vert,
  4275. fragmentShader: ShaderChunk.meshlambert_frag
  4276. },
  4277. phong: {
  4278. uniforms: UniformsUtils.merge( [
  4279. UniformsLib.common,
  4280. UniformsLib.specularmap,
  4281. UniformsLib.envmap,
  4282. UniformsLib.aomap,
  4283. UniformsLib.lightmap,
  4284. UniformsLib.emissivemap,
  4285. UniformsLib.bumpmap,
  4286. UniformsLib.normalmap,
  4287. UniformsLib.displacementmap,
  4288. UniformsLib.gradientmap,
  4289. UniformsLib.fog,
  4290. UniformsLib.lights,
  4291. {
  4292. emissive: { value: new Color( 0x000000 ) },
  4293. specular: { value: new Color( 0x111111 ) },
  4294. shininess: { value: 30 }
  4295. }
  4296. ] ),
  4297. vertexShader: ShaderChunk.meshphong_vert,
  4298. fragmentShader: ShaderChunk.meshphong_frag
  4299. },
  4300. standard: {
  4301. uniforms: UniformsUtils.merge( [
  4302. UniformsLib.common,
  4303. UniformsLib.envmap,
  4304. UniformsLib.aomap,
  4305. UniformsLib.lightmap,
  4306. UniformsLib.emissivemap,
  4307. UniformsLib.bumpmap,
  4308. UniformsLib.normalmap,
  4309. UniformsLib.displacementmap,
  4310. UniformsLib.roughnessmap,
  4311. UniformsLib.metalnessmap,
  4312. UniformsLib.fog,
  4313. UniformsLib.lights,
  4314. {
  4315. emissive: { value: new Color( 0x000000 ) },
  4316. roughness: { value: 0.5 },
  4317. metalness: { value: 0.5 },
  4318. envMapIntensity: { value: 1 } // temporary
  4319. }
  4320. ] ),
  4321. vertexShader: ShaderChunk.meshphysical_vert,
  4322. fragmentShader: ShaderChunk.meshphysical_frag
  4323. },
  4324. points: {
  4325. uniforms: UniformsUtils.merge( [
  4326. UniformsLib.points,
  4327. UniformsLib.fog
  4328. ] ),
  4329. vertexShader: ShaderChunk.points_vert,
  4330. fragmentShader: ShaderChunk.points_frag
  4331. },
  4332. dashed: {
  4333. uniforms: UniformsUtils.merge( [
  4334. UniformsLib.common,
  4335. UniformsLib.fog,
  4336. {
  4337. scale: { value: 1 },
  4338. dashSize: { value: 1 },
  4339. totalSize: { value: 2 }
  4340. }
  4341. ] ),
  4342. vertexShader: ShaderChunk.linedashed_vert,
  4343. fragmentShader: ShaderChunk.linedashed_frag
  4344. },
  4345. depth: {
  4346. uniforms: UniformsUtils.merge( [
  4347. UniformsLib.common,
  4348. UniformsLib.displacementmap
  4349. ] ),
  4350. vertexShader: ShaderChunk.depth_vert,
  4351. fragmentShader: ShaderChunk.depth_frag
  4352. },
  4353. normal: {
  4354. uniforms: UniformsUtils.merge( [
  4355. UniformsLib.common,
  4356. UniformsLib.bumpmap,
  4357. UniformsLib.normalmap,
  4358. UniformsLib.displacementmap,
  4359. {
  4360. opacity: { value: 1.0 }
  4361. }
  4362. ] ),
  4363. vertexShader: ShaderChunk.normal_vert,
  4364. fragmentShader: ShaderChunk.normal_frag
  4365. },
  4366. /* -------------------------------------------------------------------------
  4367. // Cube map shader
  4368. ------------------------------------------------------------------------- */
  4369. cube: {
  4370. uniforms: {
  4371. tCube: { value: null },
  4372. tFlip: { value: - 1 },
  4373. opacity: { value: 1.0 }
  4374. },
  4375. vertexShader: ShaderChunk.cube_vert,
  4376. fragmentShader: ShaderChunk.cube_frag
  4377. },
  4378. equirect: {
  4379. uniforms: {
  4380. tEquirect: { value: null },
  4381. },
  4382. vertexShader: ShaderChunk.equirect_vert,
  4383. fragmentShader: ShaderChunk.equirect_frag
  4384. },
  4385. distanceRGBA: {
  4386. uniforms: UniformsUtils.merge( [
  4387. UniformsLib.common,
  4388. UniformsLib.displacementmap,
  4389. {
  4390. referencePosition: { value: new Vector3() },
  4391. nearDistance: { value: 1 },
  4392. farDistance: { value: 1000 }
  4393. }
  4394. ] ),
  4395. vertexShader: ShaderChunk.distanceRGBA_vert,
  4396. fragmentShader: ShaderChunk.distanceRGBA_frag
  4397. },
  4398. shadow: {
  4399. uniforms: UniformsUtils.merge( [
  4400. UniformsLib.lights,
  4401. UniformsLib.fog,
  4402. {
  4403. color: { value: new Color( 0x00000 ) },
  4404. opacity: { value: 1.0 }
  4405. },
  4406. ] ),
  4407. vertexShader: ShaderChunk.shadow_vert,
  4408. fragmentShader: ShaderChunk.shadow_frag
  4409. }
  4410. };
  4411. ShaderLib.physical = {
  4412. uniforms: UniformsUtils.merge( [
  4413. ShaderLib.standard.uniforms,
  4414. {
  4415. clearCoat: { value: 0 },
  4416. clearCoatRoughness: { value: 0 }
  4417. }
  4418. ] ),
  4419. vertexShader: ShaderChunk.meshphysical_vert,
  4420. fragmentShader: ShaderChunk.meshphysical_frag
  4421. };
  4422. /**
  4423. * @author mrdoob / http://mrdoob.com/
  4424. */
  4425. function WebGLAnimation() {
  4426. var context = null;
  4427. var isAnimating = false;
  4428. var animationLoop = null;
  4429. function onAnimationFrame( time, frame ) {
  4430. if ( isAnimating === false ) return;
  4431. animationLoop( time, frame );
  4432. context.requestAnimationFrame( onAnimationFrame );
  4433. }
  4434. return {
  4435. start: function () {
  4436. if ( isAnimating === true ) return;
  4437. if ( animationLoop === null ) return;
  4438. context.requestAnimationFrame( onAnimationFrame );
  4439. isAnimating = true;
  4440. },
  4441. stop: function () {
  4442. isAnimating = false;
  4443. },
  4444. setAnimationLoop: function ( callback ) {
  4445. animationLoop = callback;
  4446. },
  4447. setContext: function ( value ) {
  4448. context = value;
  4449. }
  4450. };
  4451. }
  4452. /**
  4453. * @author mrdoob / http://mrdoob.com/
  4454. */
  4455. function WebGLAttributes( gl ) {
  4456. var buffers = new WeakMap();
  4457. function createBuffer( attribute, bufferType ) {
  4458. var array = attribute.array;
  4459. var usage = attribute.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  4460. var buffer = gl.createBuffer();
  4461. gl.bindBuffer( bufferType, buffer );
  4462. gl.bufferData( bufferType, array, usage );
  4463. attribute.onUploadCallback();
  4464. var type = gl.FLOAT;
  4465. if ( array instanceof Float32Array ) {
  4466. type = gl.FLOAT;
  4467. } else if ( array instanceof Float64Array ) {
  4468. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  4469. } else if ( array instanceof Uint16Array ) {
  4470. type = gl.UNSIGNED_SHORT;
  4471. } else if ( array instanceof Int16Array ) {
  4472. type = gl.SHORT;
  4473. } else if ( array instanceof Uint32Array ) {
  4474. type = gl.UNSIGNED_INT;
  4475. } else if ( array instanceof Int32Array ) {
  4476. type = gl.INT;
  4477. } else if ( array instanceof Int8Array ) {
  4478. type = gl.BYTE;
  4479. } else if ( array instanceof Uint8Array ) {
  4480. type = gl.UNSIGNED_BYTE;
  4481. }
  4482. return {
  4483. buffer: buffer,
  4484. type: type,
  4485. bytesPerElement: array.BYTES_PER_ELEMENT,
  4486. version: attribute.version
  4487. };
  4488. }
  4489. function updateBuffer( buffer, attribute, bufferType ) {
  4490. var array = attribute.array;
  4491. var updateRange = attribute.updateRange;
  4492. gl.bindBuffer( bufferType, buffer );
  4493. if ( attribute.dynamic === false ) {
  4494. gl.bufferData( bufferType, array, gl.STATIC_DRAW );
  4495. } else if ( updateRange.count === - 1 ) {
  4496. // Not using update ranges
  4497. gl.bufferSubData( bufferType, 0, array );
  4498. } else if ( updateRange.count === 0 ) {
  4499. 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.' );
  4500. } else {
  4501. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  4502. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  4503. updateRange.count = - 1; // reset range
  4504. }
  4505. }
  4506. //
  4507. function get( attribute ) {
  4508. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4509. return buffers.get( attribute );
  4510. }
  4511. function remove( attribute ) {
  4512. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4513. var data = buffers.get( attribute );
  4514. if ( data ) {
  4515. gl.deleteBuffer( data.buffer );
  4516. buffers.delete( attribute );
  4517. }
  4518. }
  4519. function update( attribute, bufferType ) {
  4520. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4521. var data = buffers.get( attribute );
  4522. if ( data === undefined ) {
  4523. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  4524. } else if ( data.version < attribute.version ) {
  4525. updateBuffer( data.buffer, attribute, bufferType );
  4526. data.version = attribute.version;
  4527. }
  4528. }
  4529. return {
  4530. get: get,
  4531. remove: remove,
  4532. update: update
  4533. };
  4534. }
  4535. /**
  4536. * @author mrdoob / http://mrdoob.com/
  4537. * @author WestLangley / http://github.com/WestLangley
  4538. * @author bhouston / http://clara.io
  4539. */
  4540. function Euler( x, y, z, order ) {
  4541. this._x = x || 0;
  4542. this._y = y || 0;
  4543. this._z = z || 0;
  4544. this._order = order || Euler.DefaultOrder;
  4545. }
  4546. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  4547. Euler.DefaultOrder = 'XYZ';
  4548. Object.defineProperties( Euler.prototype, {
  4549. x: {
  4550. get: function () {
  4551. return this._x;
  4552. },
  4553. set: function ( value ) {
  4554. this._x = value;
  4555. this.onChangeCallback();
  4556. }
  4557. },
  4558. y: {
  4559. get: function () {
  4560. return this._y;
  4561. },
  4562. set: function ( value ) {
  4563. this._y = value;
  4564. this.onChangeCallback();
  4565. }
  4566. },
  4567. z: {
  4568. get: function () {
  4569. return this._z;
  4570. },
  4571. set: function ( value ) {
  4572. this._z = value;
  4573. this.onChangeCallback();
  4574. }
  4575. },
  4576. order: {
  4577. get: function () {
  4578. return this._order;
  4579. },
  4580. set: function ( value ) {
  4581. this._order = value;
  4582. this.onChangeCallback();
  4583. }
  4584. }
  4585. } );
  4586. Object.assign( Euler.prototype, {
  4587. isEuler: true,
  4588. set: function ( x, y, z, order ) {
  4589. this._x = x;
  4590. this._y = y;
  4591. this._z = z;
  4592. this._order = order || this._order;
  4593. this.onChangeCallback();
  4594. return this;
  4595. },
  4596. clone: function () {
  4597. return new this.constructor( this._x, this._y, this._z, this._order );
  4598. },
  4599. copy: function ( euler ) {
  4600. this._x = euler._x;
  4601. this._y = euler._y;
  4602. this._z = euler._z;
  4603. this._order = euler._order;
  4604. this.onChangeCallback();
  4605. return this;
  4606. },
  4607. setFromRotationMatrix: function ( m, order, update ) {
  4608. var clamp = _Math.clamp;
  4609. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4610. var te = m.elements;
  4611. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  4612. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  4613. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  4614. order = order || this._order;
  4615. if ( order === 'XYZ' ) {
  4616. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  4617. if ( Math.abs( m13 ) < 0.99999 ) {
  4618. this._x = Math.atan2( - m23, m33 );
  4619. this._z = Math.atan2( - m12, m11 );
  4620. } else {
  4621. this._x = Math.atan2( m32, m22 );
  4622. this._z = 0;
  4623. }
  4624. } else if ( order === 'YXZ' ) {
  4625. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  4626. if ( Math.abs( m23 ) < 0.99999 ) {
  4627. this._y = Math.atan2( m13, m33 );
  4628. this._z = Math.atan2( m21, m22 );
  4629. } else {
  4630. this._y = Math.atan2( - m31, m11 );
  4631. this._z = 0;
  4632. }
  4633. } else if ( order === 'ZXY' ) {
  4634. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  4635. if ( Math.abs( m32 ) < 0.99999 ) {
  4636. this._y = Math.atan2( - m31, m33 );
  4637. this._z = Math.atan2( - m12, m22 );
  4638. } else {
  4639. this._y = 0;
  4640. this._z = Math.atan2( m21, m11 );
  4641. }
  4642. } else if ( order === 'ZYX' ) {
  4643. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  4644. if ( Math.abs( m31 ) < 0.99999 ) {
  4645. this._x = Math.atan2( m32, m33 );
  4646. this._z = Math.atan2( m21, m11 );
  4647. } else {
  4648. this._x = 0;
  4649. this._z = Math.atan2( - m12, m22 );
  4650. }
  4651. } else if ( order === 'YZX' ) {
  4652. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  4653. if ( Math.abs( m21 ) < 0.99999 ) {
  4654. this._x = Math.atan2( - m23, m22 );
  4655. this._y = Math.atan2( - m31, m11 );
  4656. } else {
  4657. this._x = 0;
  4658. this._y = Math.atan2( m13, m33 );
  4659. }
  4660. } else if ( order === 'XZY' ) {
  4661. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  4662. if ( Math.abs( m12 ) < 0.99999 ) {
  4663. this._x = Math.atan2( m32, m22 );
  4664. this._y = Math.atan2( m13, m11 );
  4665. } else {
  4666. this._x = Math.atan2( - m23, m33 );
  4667. this._y = 0;
  4668. }
  4669. } else {
  4670. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  4671. }
  4672. this._order = order;
  4673. if ( update !== false ) this.onChangeCallback();
  4674. return this;
  4675. },
  4676. setFromQuaternion: function () {
  4677. var matrix = new Matrix4();
  4678. return function setFromQuaternion( q, order, update ) {
  4679. matrix.makeRotationFromQuaternion( q );
  4680. return this.setFromRotationMatrix( matrix, order, update );
  4681. };
  4682. }(),
  4683. setFromVector3: function ( v, order ) {
  4684. return this.set( v.x, v.y, v.z, order || this._order );
  4685. },
  4686. reorder: function () {
  4687. // WARNING: this discards revolution information -bhouston
  4688. var q = new Quaternion();
  4689. return function reorder( newOrder ) {
  4690. q.setFromEuler( this );
  4691. return this.setFromQuaternion( q, newOrder );
  4692. };
  4693. }(),
  4694. equals: function ( euler ) {
  4695. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  4696. },
  4697. fromArray: function ( array ) {
  4698. this._x = array[ 0 ];
  4699. this._y = array[ 1 ];
  4700. this._z = array[ 2 ];
  4701. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  4702. this.onChangeCallback();
  4703. return this;
  4704. },
  4705. toArray: function ( array, offset ) {
  4706. if ( array === undefined ) array = [];
  4707. if ( offset === undefined ) offset = 0;
  4708. array[ offset ] = this._x;
  4709. array[ offset + 1 ] = this._y;
  4710. array[ offset + 2 ] = this._z;
  4711. array[ offset + 3 ] = this._order;
  4712. return array;
  4713. },
  4714. toVector3: function ( optionalResult ) {
  4715. if ( optionalResult ) {
  4716. return optionalResult.set( this._x, this._y, this._z );
  4717. } else {
  4718. return new Vector3( this._x, this._y, this._z );
  4719. }
  4720. },
  4721. onChange: function ( callback ) {
  4722. this.onChangeCallback = callback;
  4723. return this;
  4724. },
  4725. onChangeCallback: function () {}
  4726. } );
  4727. /**
  4728. * @author mrdoob / http://mrdoob.com/
  4729. */
  4730. function Layers() {
  4731. this.mask = 1 | 0;
  4732. }
  4733. Object.assign( Layers.prototype, {
  4734. set: function ( channel ) {
  4735. this.mask = 1 << channel | 0;
  4736. },
  4737. enable: function ( channel ) {
  4738. this.mask |= 1 << channel | 0;
  4739. },
  4740. toggle: function ( channel ) {
  4741. this.mask ^= 1 << channel | 0;
  4742. },
  4743. disable: function ( channel ) {
  4744. this.mask &= ~ ( 1 << channel | 0 );
  4745. },
  4746. test: function ( layers ) {
  4747. return ( this.mask & layers.mask ) !== 0;
  4748. }
  4749. } );
  4750. /**
  4751. * @author mrdoob / http://mrdoob.com/
  4752. * @author mikael emtinger / http://gomo.se/
  4753. * @author alteredq / http://alteredqualia.com/
  4754. * @author WestLangley / http://github.com/WestLangley
  4755. * @author elephantatwork / www.elephantatwork.ch
  4756. */
  4757. var object3DId = 0;
  4758. function Object3D() {
  4759. Object.defineProperty( this, 'id', { value: object3DId ++ } );
  4760. this.uuid = _Math.generateUUID();
  4761. this.name = '';
  4762. this.type = 'Object3D';
  4763. this.parent = null;
  4764. this.children = [];
  4765. this.up = Object3D.DefaultUp.clone();
  4766. var position = new Vector3();
  4767. var rotation = new Euler();
  4768. var quaternion = new Quaternion();
  4769. var scale = new Vector3( 1, 1, 1 );
  4770. function onRotationChange() {
  4771. quaternion.setFromEuler( rotation, false );
  4772. }
  4773. function onQuaternionChange() {
  4774. rotation.setFromQuaternion( quaternion, undefined, false );
  4775. }
  4776. rotation.onChange( onRotationChange );
  4777. quaternion.onChange( onQuaternionChange );
  4778. Object.defineProperties( this, {
  4779. position: {
  4780. enumerable: true,
  4781. value: position
  4782. },
  4783. rotation: {
  4784. enumerable: true,
  4785. value: rotation
  4786. },
  4787. quaternion: {
  4788. enumerable: true,
  4789. value: quaternion
  4790. },
  4791. scale: {
  4792. enumerable: true,
  4793. value: scale
  4794. },
  4795. modelViewMatrix: {
  4796. value: new Matrix4()
  4797. },
  4798. normalMatrix: {
  4799. value: new Matrix3()
  4800. }
  4801. } );
  4802. this.matrix = new Matrix4();
  4803. this.matrixWorld = new Matrix4();
  4804. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  4805. this.matrixWorldNeedsUpdate = false;
  4806. this.layers = new Layers();
  4807. this.visible = true;
  4808. this.castShadow = false;
  4809. this.receiveShadow = false;
  4810. this.frustumCulled = true;
  4811. this.renderOrder = 0;
  4812. this.userData = {};
  4813. }
  4814. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  4815. Object3D.DefaultMatrixAutoUpdate = true;
  4816. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  4817. constructor: Object3D,
  4818. isObject3D: true,
  4819. onBeforeRender: function () {},
  4820. onAfterRender: function () {},
  4821. applyMatrix: function ( matrix ) {
  4822. this.matrix.multiplyMatrices( matrix, this.matrix );
  4823. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4824. },
  4825. applyQuaternion: function ( q ) {
  4826. this.quaternion.premultiply( q );
  4827. return this;
  4828. },
  4829. setRotationFromAxisAngle: function ( axis, angle ) {
  4830. // assumes axis is normalized
  4831. this.quaternion.setFromAxisAngle( axis, angle );
  4832. },
  4833. setRotationFromEuler: function ( euler ) {
  4834. this.quaternion.setFromEuler( euler, true );
  4835. },
  4836. setRotationFromMatrix: function ( m ) {
  4837. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4838. this.quaternion.setFromRotationMatrix( m );
  4839. },
  4840. setRotationFromQuaternion: function ( q ) {
  4841. // assumes q is normalized
  4842. this.quaternion.copy( q );
  4843. },
  4844. rotateOnAxis: function () {
  4845. // rotate object on axis in object space
  4846. // axis is assumed to be normalized
  4847. var q1 = new Quaternion();
  4848. return function rotateOnAxis( axis, angle ) {
  4849. q1.setFromAxisAngle( axis, angle );
  4850. this.quaternion.multiply( q1 );
  4851. return this;
  4852. };
  4853. }(),
  4854. rotateOnWorldAxis: function () {
  4855. // rotate object on axis in world space
  4856. // axis is assumed to be normalized
  4857. // method assumes no rotated parent
  4858. var q1 = new Quaternion();
  4859. return function rotateOnWorldAxis( axis, angle ) {
  4860. q1.setFromAxisAngle( axis, angle );
  4861. this.quaternion.premultiply( q1 );
  4862. return this;
  4863. };
  4864. }(),
  4865. rotateX: function () {
  4866. var v1 = new Vector3( 1, 0, 0 );
  4867. return function rotateX( angle ) {
  4868. return this.rotateOnAxis( v1, angle );
  4869. };
  4870. }(),
  4871. rotateY: function () {
  4872. var v1 = new Vector3( 0, 1, 0 );
  4873. return function rotateY( angle ) {
  4874. return this.rotateOnAxis( v1, angle );
  4875. };
  4876. }(),
  4877. rotateZ: function () {
  4878. var v1 = new Vector3( 0, 0, 1 );
  4879. return function rotateZ( angle ) {
  4880. return this.rotateOnAxis( v1, angle );
  4881. };
  4882. }(),
  4883. translateOnAxis: function () {
  4884. // translate object by distance along axis in object space
  4885. // axis is assumed to be normalized
  4886. var v1 = new Vector3();
  4887. return function translateOnAxis( axis, distance ) {
  4888. v1.copy( axis ).applyQuaternion( this.quaternion );
  4889. this.position.add( v1.multiplyScalar( distance ) );
  4890. return this;
  4891. };
  4892. }(),
  4893. translateX: function () {
  4894. var v1 = new Vector3( 1, 0, 0 );
  4895. return function translateX( distance ) {
  4896. return this.translateOnAxis( v1, distance );
  4897. };
  4898. }(),
  4899. translateY: function () {
  4900. var v1 = new Vector3( 0, 1, 0 );
  4901. return function translateY( distance ) {
  4902. return this.translateOnAxis( v1, distance );
  4903. };
  4904. }(),
  4905. translateZ: function () {
  4906. var v1 = new Vector3( 0, 0, 1 );
  4907. return function translateZ( distance ) {
  4908. return this.translateOnAxis( v1, distance );
  4909. };
  4910. }(),
  4911. localToWorld: function ( vector ) {
  4912. return vector.applyMatrix4( this.matrixWorld );
  4913. },
  4914. worldToLocal: function () {
  4915. var m1 = new Matrix4();
  4916. return function worldToLocal( vector ) {
  4917. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  4918. };
  4919. }(),
  4920. lookAt: function () {
  4921. // This method does not support objects with rotated and/or translated parent(s)
  4922. var m1 = new Matrix4();
  4923. var vector = new Vector3();
  4924. return function lookAt( x, y, z ) {
  4925. if ( x.isVector3 ) {
  4926. vector.copy( x );
  4927. } else {
  4928. vector.set( x, y, z );
  4929. }
  4930. if ( this.isCamera ) {
  4931. m1.lookAt( this.position, vector, this.up );
  4932. } else {
  4933. m1.lookAt( vector, this.position, this.up );
  4934. }
  4935. this.quaternion.setFromRotationMatrix( m1 );
  4936. };
  4937. }(),
  4938. add: function ( object ) {
  4939. if ( arguments.length > 1 ) {
  4940. for ( var i = 0; i < arguments.length; i ++ ) {
  4941. this.add( arguments[ i ] );
  4942. }
  4943. return this;
  4944. }
  4945. if ( object === this ) {
  4946. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  4947. return this;
  4948. }
  4949. if ( ( object && object.isObject3D ) ) {
  4950. if ( object.parent !== null ) {
  4951. object.parent.remove( object );
  4952. }
  4953. object.parent = this;
  4954. object.dispatchEvent( { type: 'added' } );
  4955. this.children.push( object );
  4956. } else {
  4957. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  4958. }
  4959. return this;
  4960. },
  4961. remove: function ( object ) {
  4962. if ( arguments.length > 1 ) {
  4963. for ( var i = 0; i < arguments.length; i ++ ) {
  4964. this.remove( arguments[ i ] );
  4965. }
  4966. return this;
  4967. }
  4968. var index = this.children.indexOf( object );
  4969. if ( index !== - 1 ) {
  4970. object.parent = null;
  4971. object.dispatchEvent( { type: 'removed' } );
  4972. this.children.splice( index, 1 );
  4973. }
  4974. return this;
  4975. },
  4976. getObjectById: function ( id ) {
  4977. return this.getObjectByProperty( 'id', id );
  4978. },
  4979. getObjectByName: function ( name ) {
  4980. return this.getObjectByProperty( 'name', name );
  4981. },
  4982. getObjectByProperty: function ( name, value ) {
  4983. if ( this[ name ] === value ) return this;
  4984. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4985. var child = this.children[ i ];
  4986. var object = child.getObjectByProperty( name, value );
  4987. if ( object !== undefined ) {
  4988. return object;
  4989. }
  4990. }
  4991. return undefined;
  4992. },
  4993. getWorldPosition: function ( target ) {
  4994. if ( target === undefined ) {
  4995. console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
  4996. target = new Vector3();
  4997. }
  4998. this.updateMatrixWorld( true );
  4999. return target.setFromMatrixPosition( this.matrixWorld );
  5000. },
  5001. getWorldQuaternion: function () {
  5002. var position = new Vector3();
  5003. var scale = new Vector3();
  5004. return function getWorldQuaternion( target ) {
  5005. if ( target === undefined ) {
  5006. console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
  5007. target = new Quaternion();
  5008. }
  5009. this.updateMatrixWorld( true );
  5010. this.matrixWorld.decompose( position, target, scale );
  5011. return target;
  5012. };
  5013. }(),
  5014. getWorldScale: function () {
  5015. var position = new Vector3();
  5016. var quaternion = new Quaternion();
  5017. return function getWorldScale( target ) {
  5018. if ( target === undefined ) {
  5019. console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
  5020. target = new Vector3();
  5021. }
  5022. this.updateMatrixWorld( true );
  5023. this.matrixWorld.decompose( position, quaternion, target );
  5024. return target;
  5025. };
  5026. }(),
  5027. getWorldDirection: function () {
  5028. var quaternion = new Quaternion();
  5029. return function getWorldDirection( target ) {
  5030. if ( target === undefined ) {
  5031. console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
  5032. target = new Vector3();
  5033. }
  5034. this.getWorldQuaternion( quaternion );
  5035. return target.set( 0, 0, 1 ).applyQuaternion( quaternion );
  5036. };
  5037. }(),
  5038. raycast: function () {},
  5039. traverse: function ( callback ) {
  5040. callback( this );
  5041. var children = this.children;
  5042. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5043. children[ i ].traverse( callback );
  5044. }
  5045. },
  5046. traverseVisible: function ( callback ) {
  5047. if ( this.visible === false ) return;
  5048. callback( this );
  5049. var children = this.children;
  5050. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5051. children[ i ].traverseVisible( callback );
  5052. }
  5053. },
  5054. traverseAncestors: function ( callback ) {
  5055. var parent = this.parent;
  5056. if ( parent !== null ) {
  5057. callback( parent );
  5058. parent.traverseAncestors( callback );
  5059. }
  5060. },
  5061. updateMatrix: function () {
  5062. this.matrix.compose( this.position, this.quaternion, this.scale );
  5063. this.matrixWorldNeedsUpdate = true;
  5064. },
  5065. updateMatrixWorld: function ( force ) {
  5066. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5067. if ( this.matrixWorldNeedsUpdate || force ) {
  5068. if ( this.parent === null ) {
  5069. this.matrixWorld.copy( this.matrix );
  5070. } else {
  5071. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5072. }
  5073. this.matrixWorldNeedsUpdate = false;
  5074. force = true;
  5075. }
  5076. // update children
  5077. var children = this.children;
  5078. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5079. children[ i ].updateMatrixWorld( force );
  5080. }
  5081. },
  5082. toJSON: function ( meta ) {
  5083. // meta is a string when called from JSON.stringify
  5084. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  5085. var output = {};
  5086. // meta is a hash used to collect geometries, materials.
  5087. // not providing it implies that this is the root object
  5088. // being serialized.
  5089. if ( isRootObject ) {
  5090. // initialize meta obj
  5091. meta = {
  5092. geometries: {},
  5093. materials: {},
  5094. textures: {},
  5095. images: {},
  5096. shapes: {}
  5097. };
  5098. output.metadata = {
  5099. version: 4.5,
  5100. type: 'Object',
  5101. generator: 'Object3D.toJSON'
  5102. };
  5103. }
  5104. // standard Object3D serialization
  5105. var object = {};
  5106. object.uuid = this.uuid;
  5107. object.type = this.type;
  5108. if ( this.name !== '' ) object.name = this.name;
  5109. if ( this.castShadow === true ) object.castShadow = true;
  5110. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5111. if ( this.visible === false ) object.visible = false;
  5112. if ( this.frustumCulled === false ) object.frustumCulled = false;
  5113. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  5114. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5115. object.matrix = this.matrix.toArray();
  5116. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  5117. //
  5118. function serialize( library, element ) {
  5119. if ( library[ element.uuid ] === undefined ) {
  5120. library[ element.uuid ] = element.toJSON( meta );
  5121. }
  5122. return element.uuid;
  5123. }
  5124. if ( this.geometry !== undefined ) {
  5125. object.geometry = serialize( meta.geometries, this.geometry );
  5126. var parameters = this.geometry.parameters;
  5127. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  5128. var shapes = parameters.shapes;
  5129. if ( Array.isArray( shapes ) ) {
  5130. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  5131. var shape = shapes[ i ];
  5132. serialize( meta.shapes, shape );
  5133. }
  5134. } else {
  5135. serialize( meta.shapes, shapes );
  5136. }
  5137. }
  5138. }
  5139. if ( this.material !== undefined ) {
  5140. if ( Array.isArray( this.material ) ) {
  5141. var uuids = [];
  5142. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  5143. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  5144. }
  5145. object.material = uuids;
  5146. } else {
  5147. object.material = serialize( meta.materials, this.material );
  5148. }
  5149. }
  5150. //
  5151. if ( this.children.length > 0 ) {
  5152. object.children = [];
  5153. for ( var i = 0; i < this.children.length; i ++ ) {
  5154. object.children.push( this.children[ i ].toJSON( meta ).object );
  5155. }
  5156. }
  5157. if ( isRootObject ) {
  5158. var geometries = extractFromCache( meta.geometries );
  5159. var materials = extractFromCache( meta.materials );
  5160. var textures = extractFromCache( meta.textures );
  5161. var images = extractFromCache( meta.images );
  5162. var shapes = extractFromCache( meta.shapes );
  5163. if ( geometries.length > 0 ) output.geometries = geometries;
  5164. if ( materials.length > 0 ) output.materials = materials;
  5165. if ( textures.length > 0 ) output.textures = textures;
  5166. if ( images.length > 0 ) output.images = images;
  5167. if ( shapes.length > 0 ) output.shapes = shapes;
  5168. }
  5169. output.object = object;
  5170. return output;
  5171. // extract data from the cache hash
  5172. // remove metadata on each item
  5173. // and return as array
  5174. function extractFromCache( cache ) {
  5175. var values = [];
  5176. for ( var key in cache ) {
  5177. var data = cache[ key ];
  5178. delete data.metadata;
  5179. values.push( data );
  5180. }
  5181. return values;
  5182. }
  5183. },
  5184. clone: function ( recursive ) {
  5185. return new this.constructor().copy( this, recursive );
  5186. },
  5187. copy: function ( source, recursive ) {
  5188. if ( recursive === undefined ) recursive = true;
  5189. this.name = source.name;
  5190. this.up.copy( source.up );
  5191. this.position.copy( source.position );
  5192. this.quaternion.copy( source.quaternion );
  5193. this.scale.copy( source.scale );
  5194. this.matrix.copy( source.matrix );
  5195. this.matrixWorld.copy( source.matrixWorld );
  5196. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5197. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5198. this.layers.mask = source.layers.mask;
  5199. this.visible = source.visible;
  5200. this.castShadow = source.castShadow;
  5201. this.receiveShadow = source.receiveShadow;
  5202. this.frustumCulled = source.frustumCulled;
  5203. this.renderOrder = source.renderOrder;
  5204. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5205. if ( recursive === true ) {
  5206. for ( var i = 0; i < source.children.length; i ++ ) {
  5207. var child = source.children[ i ];
  5208. this.add( child.clone() );
  5209. }
  5210. }
  5211. return this;
  5212. }
  5213. } );
  5214. /**
  5215. * @author mrdoob / http://mrdoob.com/
  5216. * @author mikael emtinger / http://gomo.se/
  5217. * @author WestLangley / http://github.com/WestLangley
  5218. */
  5219. function Camera() {
  5220. Object3D.call( this );
  5221. this.type = 'Camera';
  5222. this.matrixWorldInverse = new Matrix4();
  5223. this.projectionMatrix = new Matrix4();
  5224. }
  5225. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  5226. constructor: Camera,
  5227. isCamera: true,
  5228. copy: function ( source, recursive ) {
  5229. Object3D.prototype.copy.call( this, source, recursive );
  5230. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  5231. this.projectionMatrix.copy( source.projectionMatrix );
  5232. return this;
  5233. },
  5234. getWorldDirection: function () {
  5235. var quaternion = new Quaternion();
  5236. return function getWorldDirection( target ) {
  5237. if ( target === undefined ) {
  5238. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  5239. target = new Vector3();
  5240. }
  5241. this.getWorldQuaternion( quaternion );
  5242. return target.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  5243. };
  5244. }(),
  5245. updateMatrixWorld: function ( force ) {
  5246. Object3D.prototype.updateMatrixWorld.call( this, force );
  5247. this.matrixWorldInverse.getInverse( this.matrixWorld );
  5248. },
  5249. clone: function () {
  5250. return new this.constructor().copy( this );
  5251. }
  5252. } );
  5253. /**
  5254. * @author alteredq / http://alteredqualia.com/
  5255. * @author arose / http://github.com/arose
  5256. */
  5257. function OrthographicCamera( left, right, top, bottom, near, far ) {
  5258. Camera.call( this );
  5259. this.type = 'OrthographicCamera';
  5260. this.zoom = 1;
  5261. this.view = null;
  5262. this.left = left;
  5263. this.right = right;
  5264. this.top = top;
  5265. this.bottom = bottom;
  5266. this.near = ( near !== undefined ) ? near : 0.1;
  5267. this.far = ( far !== undefined ) ? far : 2000;
  5268. this.updateProjectionMatrix();
  5269. }
  5270. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  5271. constructor: OrthographicCamera,
  5272. isOrthographicCamera: true,
  5273. copy: function ( source, recursive ) {
  5274. Camera.prototype.copy.call( this, source, recursive );
  5275. this.left = source.left;
  5276. this.right = source.right;
  5277. this.top = source.top;
  5278. this.bottom = source.bottom;
  5279. this.near = source.near;
  5280. this.far = source.far;
  5281. this.zoom = source.zoom;
  5282. this.view = source.view === null ? null : Object.assign( {}, source.view );
  5283. return this;
  5284. },
  5285. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  5286. if ( this.view === null ) {
  5287. this.view = {
  5288. enabled: true,
  5289. fullWidth: 1,
  5290. fullHeight: 1,
  5291. offsetX: 0,
  5292. offsetY: 0,
  5293. width: 1,
  5294. height: 1
  5295. };
  5296. }
  5297. this.view.enabled = true;
  5298. this.view.fullWidth = fullWidth;
  5299. this.view.fullHeight = fullHeight;
  5300. this.view.offsetX = x;
  5301. this.view.offsetY = y;
  5302. this.view.width = width;
  5303. this.view.height = height;
  5304. this.updateProjectionMatrix();
  5305. },
  5306. clearViewOffset: function () {
  5307. if ( this.view !== null ) {
  5308. this.view.enabled = false;
  5309. }
  5310. this.updateProjectionMatrix();
  5311. },
  5312. updateProjectionMatrix: function () {
  5313. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  5314. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  5315. var cx = ( this.right + this.left ) / 2;
  5316. var cy = ( this.top + this.bottom ) / 2;
  5317. var left = cx - dx;
  5318. var right = cx + dx;
  5319. var top = cy + dy;
  5320. var bottom = cy - dy;
  5321. if ( this.view !== null && this.view.enabled ) {
  5322. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  5323. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  5324. var scaleW = ( this.right - this.left ) / this.view.width;
  5325. var scaleH = ( this.top - this.bottom ) / this.view.height;
  5326. left += scaleW * ( this.view.offsetX / zoomW );
  5327. right = left + scaleW * ( this.view.width / zoomW );
  5328. top -= scaleH * ( this.view.offsetY / zoomH );
  5329. bottom = top - scaleH * ( this.view.height / zoomH );
  5330. }
  5331. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  5332. },
  5333. toJSON: function ( meta ) {
  5334. var data = Object3D.prototype.toJSON.call( this, meta );
  5335. data.object.zoom = this.zoom;
  5336. data.object.left = this.left;
  5337. data.object.right = this.right;
  5338. data.object.top = this.top;
  5339. data.object.bottom = this.bottom;
  5340. data.object.near = this.near;
  5341. data.object.far = this.far;
  5342. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  5343. return data;
  5344. }
  5345. } );
  5346. /**
  5347. * @author mrdoob / http://mrdoob.com/
  5348. * @author alteredq / http://alteredqualia.com/
  5349. */
  5350. function Face3( a, b, c, normal, color, materialIndex ) {
  5351. this.a = a;
  5352. this.b = b;
  5353. this.c = c;
  5354. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  5355. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5356. this.color = ( color && color.isColor ) ? color : new Color();
  5357. this.vertexColors = Array.isArray( color ) ? color : [];
  5358. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5359. }
  5360. Object.assign( Face3.prototype, {
  5361. clone: function () {
  5362. return new this.constructor().copy( this );
  5363. },
  5364. copy: function ( source ) {
  5365. this.a = source.a;
  5366. this.b = source.b;
  5367. this.c = source.c;
  5368. this.normal.copy( source.normal );
  5369. this.color.copy( source.color );
  5370. this.materialIndex = source.materialIndex;
  5371. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5372. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5373. }
  5374. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5375. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5376. }
  5377. return this;
  5378. }
  5379. } );
  5380. /**
  5381. * @author mrdoob / http://mrdoob.com/
  5382. * @author kile / http://kile.stravaganza.org/
  5383. * @author alteredq / http://alteredqualia.com/
  5384. * @author mikael emtinger / http://gomo.se/
  5385. * @author zz85 / http://www.lab4games.net/zz85/blog
  5386. * @author bhouston / http://clara.io
  5387. */
  5388. var geometryId = 0; // Geometry uses even numbers as Id
  5389. function Geometry() {
  5390. Object.defineProperty( this, 'id', { value: geometryId += 2 } );
  5391. this.uuid = _Math.generateUUID();
  5392. this.name = '';
  5393. this.type = 'Geometry';
  5394. this.vertices = [];
  5395. this.colors = [];
  5396. this.faces = [];
  5397. this.faceVertexUvs = [[]];
  5398. this.morphTargets = [];
  5399. this.morphNormals = [];
  5400. this.skinWeights = [];
  5401. this.skinIndices = [];
  5402. this.lineDistances = [];
  5403. this.boundingBox = null;
  5404. this.boundingSphere = null;
  5405. // update flags
  5406. this.elementsNeedUpdate = false;
  5407. this.verticesNeedUpdate = false;
  5408. this.uvsNeedUpdate = false;
  5409. this.normalsNeedUpdate = false;
  5410. this.colorsNeedUpdate = false;
  5411. this.lineDistancesNeedUpdate = false;
  5412. this.groupsNeedUpdate = false;
  5413. }
  5414. Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5415. constructor: Geometry,
  5416. isGeometry: true,
  5417. applyMatrix: function ( matrix ) {
  5418. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5419. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5420. var vertex = this.vertices[ i ];
  5421. vertex.applyMatrix4( matrix );
  5422. }
  5423. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5424. var face = this.faces[ i ];
  5425. face.normal.applyMatrix3( normalMatrix ).normalize();
  5426. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5427. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5428. }
  5429. }
  5430. if ( this.boundingBox !== null ) {
  5431. this.computeBoundingBox();
  5432. }
  5433. if ( this.boundingSphere !== null ) {
  5434. this.computeBoundingSphere();
  5435. }
  5436. this.verticesNeedUpdate = true;
  5437. this.normalsNeedUpdate = true;
  5438. return this;
  5439. },
  5440. rotateX: function () {
  5441. // rotate geometry around world x-axis
  5442. var m1 = new Matrix4();
  5443. return function rotateX( angle ) {
  5444. m1.makeRotationX( angle );
  5445. this.applyMatrix( m1 );
  5446. return this;
  5447. };
  5448. }(),
  5449. rotateY: function () {
  5450. // rotate geometry around world y-axis
  5451. var m1 = new Matrix4();
  5452. return function rotateY( angle ) {
  5453. m1.makeRotationY( angle );
  5454. this.applyMatrix( m1 );
  5455. return this;
  5456. };
  5457. }(),
  5458. rotateZ: function () {
  5459. // rotate geometry around world z-axis
  5460. var m1 = new Matrix4();
  5461. return function rotateZ( angle ) {
  5462. m1.makeRotationZ( angle );
  5463. this.applyMatrix( m1 );
  5464. return this;
  5465. };
  5466. }(),
  5467. translate: function () {
  5468. // translate geometry
  5469. var m1 = new Matrix4();
  5470. return function translate( x, y, z ) {
  5471. m1.makeTranslation( x, y, z );
  5472. this.applyMatrix( m1 );
  5473. return this;
  5474. };
  5475. }(),
  5476. scale: function () {
  5477. // scale geometry
  5478. var m1 = new Matrix4();
  5479. return function scale( x, y, z ) {
  5480. m1.makeScale( x, y, z );
  5481. this.applyMatrix( m1 );
  5482. return this;
  5483. };
  5484. }(),
  5485. lookAt: function () {
  5486. var obj = new Object3D();
  5487. return function lookAt( vector ) {
  5488. obj.lookAt( vector );
  5489. obj.updateMatrix();
  5490. this.applyMatrix( obj.matrix );
  5491. };
  5492. }(),
  5493. fromBufferGeometry: function ( geometry ) {
  5494. var scope = this;
  5495. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5496. var attributes = geometry.attributes;
  5497. var positions = attributes.position.array;
  5498. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5499. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5500. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5501. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5502. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5503. var tempNormals = [];
  5504. var tempUVs = [];
  5505. var tempUVs2 = [];
  5506. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  5507. scope.vertices.push( new Vector3( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] ) );
  5508. if ( normals !== undefined ) {
  5509. tempNormals.push( new Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5510. }
  5511. if ( colors !== undefined ) {
  5512. scope.colors.push( new Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5513. }
  5514. if ( uvs !== undefined ) {
  5515. tempUVs.push( new Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5516. }
  5517. if ( uvs2 !== undefined ) {
  5518. tempUVs2.push( new Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5519. }
  5520. }
  5521. function addFace( a, b, c, materialIndex ) {
  5522. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5523. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5524. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  5525. scope.faces.push( face );
  5526. if ( uvs !== undefined ) {
  5527. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5528. }
  5529. if ( uvs2 !== undefined ) {
  5530. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5531. }
  5532. }
  5533. var groups = geometry.groups;
  5534. if ( groups.length > 0 ) {
  5535. for ( var i = 0; i < groups.length; i ++ ) {
  5536. var group = groups[ i ];
  5537. var start = group.start;
  5538. var count = group.count;
  5539. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5540. if ( indices !== undefined ) {
  5541. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  5542. } else {
  5543. addFace( j, j + 1, j + 2, group.materialIndex );
  5544. }
  5545. }
  5546. }
  5547. } else {
  5548. if ( indices !== undefined ) {
  5549. for ( var i = 0; i < indices.length; i += 3 ) {
  5550. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5551. }
  5552. } else {
  5553. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  5554. addFace( i, i + 1, i + 2 );
  5555. }
  5556. }
  5557. }
  5558. this.computeFaceNormals();
  5559. if ( geometry.boundingBox !== null ) {
  5560. this.boundingBox = geometry.boundingBox.clone();
  5561. }
  5562. if ( geometry.boundingSphere !== null ) {
  5563. this.boundingSphere = geometry.boundingSphere.clone();
  5564. }
  5565. return this;
  5566. },
  5567. center: function () {
  5568. var offset = new Vector3();
  5569. return function center() {
  5570. this.computeBoundingBox();
  5571. this.boundingBox.getCenter( offset ).negate();
  5572. this.translate( offset.x, offset.y, offset.z );
  5573. return this;
  5574. };
  5575. }(),
  5576. normalize: function () {
  5577. this.computeBoundingSphere();
  5578. var center = this.boundingSphere.center;
  5579. var radius = this.boundingSphere.radius;
  5580. var s = radius === 0 ? 1 : 1.0 / radius;
  5581. var matrix = new Matrix4();
  5582. matrix.set(
  5583. s, 0, 0, - s * center.x,
  5584. 0, s, 0, - s * center.y,
  5585. 0, 0, s, - s * center.z,
  5586. 0, 0, 0, 1
  5587. );
  5588. this.applyMatrix( matrix );
  5589. return this;
  5590. },
  5591. computeFaceNormals: function () {
  5592. var cb = new Vector3(), ab = new Vector3();
  5593. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5594. var face = this.faces[ f ];
  5595. var vA = this.vertices[ face.a ];
  5596. var vB = this.vertices[ face.b ];
  5597. var vC = this.vertices[ face.c ];
  5598. cb.subVectors( vC, vB );
  5599. ab.subVectors( vA, vB );
  5600. cb.cross( ab );
  5601. cb.normalize();
  5602. face.normal.copy( cb );
  5603. }
  5604. },
  5605. computeVertexNormals: function ( areaWeighted ) {
  5606. if ( areaWeighted === undefined ) areaWeighted = true;
  5607. var v, vl, f, fl, face, vertices;
  5608. vertices = new Array( this.vertices.length );
  5609. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5610. vertices[ v ] = new Vector3();
  5611. }
  5612. if ( areaWeighted ) {
  5613. // vertex normals weighted by triangle areas
  5614. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5615. var vA, vB, vC;
  5616. var cb = new Vector3(), ab = new Vector3();
  5617. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5618. face = this.faces[ f ];
  5619. vA = this.vertices[ face.a ];
  5620. vB = this.vertices[ face.b ];
  5621. vC = this.vertices[ face.c ];
  5622. cb.subVectors( vC, vB );
  5623. ab.subVectors( vA, vB );
  5624. cb.cross( ab );
  5625. vertices[ face.a ].add( cb );
  5626. vertices[ face.b ].add( cb );
  5627. vertices[ face.c ].add( cb );
  5628. }
  5629. } else {
  5630. this.computeFaceNormals();
  5631. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5632. face = this.faces[ f ];
  5633. vertices[ face.a ].add( face.normal );
  5634. vertices[ face.b ].add( face.normal );
  5635. vertices[ face.c ].add( face.normal );
  5636. }
  5637. }
  5638. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5639. vertices[ v ].normalize();
  5640. }
  5641. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5642. face = this.faces[ f ];
  5643. var vertexNormals = face.vertexNormals;
  5644. if ( vertexNormals.length === 3 ) {
  5645. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5646. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5647. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5648. } else {
  5649. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5650. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5651. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5652. }
  5653. }
  5654. if ( this.faces.length > 0 ) {
  5655. this.normalsNeedUpdate = true;
  5656. }
  5657. },
  5658. computeFlatVertexNormals: function () {
  5659. var f, fl, face;
  5660. this.computeFaceNormals();
  5661. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5662. face = this.faces[ f ];
  5663. var vertexNormals = face.vertexNormals;
  5664. if ( vertexNormals.length === 3 ) {
  5665. vertexNormals[ 0 ].copy( face.normal );
  5666. vertexNormals[ 1 ].copy( face.normal );
  5667. vertexNormals[ 2 ].copy( face.normal );
  5668. } else {
  5669. vertexNormals[ 0 ] = face.normal.clone();
  5670. vertexNormals[ 1 ] = face.normal.clone();
  5671. vertexNormals[ 2 ] = face.normal.clone();
  5672. }
  5673. }
  5674. if ( this.faces.length > 0 ) {
  5675. this.normalsNeedUpdate = true;
  5676. }
  5677. },
  5678. computeMorphNormals: function () {
  5679. var i, il, f, fl, face;
  5680. // save original normals
  5681. // - create temp variables on first access
  5682. // otherwise just copy (for faster repeated calls)
  5683. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5684. face = this.faces[ f ];
  5685. if ( ! face.__originalFaceNormal ) {
  5686. face.__originalFaceNormal = face.normal.clone();
  5687. } else {
  5688. face.__originalFaceNormal.copy( face.normal );
  5689. }
  5690. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5691. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5692. if ( ! face.__originalVertexNormals[ i ] ) {
  5693. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5694. } else {
  5695. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5696. }
  5697. }
  5698. }
  5699. // use temp geometry to compute face and vertex normals for each morph
  5700. var tmpGeo = new Geometry();
  5701. tmpGeo.faces = this.faces;
  5702. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5703. // create on first access
  5704. if ( ! this.morphNormals[ i ] ) {
  5705. this.morphNormals[ i ] = {};
  5706. this.morphNormals[ i ].faceNormals = [];
  5707. this.morphNormals[ i ].vertexNormals = [];
  5708. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5709. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5710. var faceNormal, vertexNormals;
  5711. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5712. faceNormal = new Vector3();
  5713. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  5714. dstNormalsFace.push( faceNormal );
  5715. dstNormalsVertex.push( vertexNormals );
  5716. }
  5717. }
  5718. var morphNormals = this.morphNormals[ i ];
  5719. // set vertices to morph target
  5720. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5721. // compute morph normals
  5722. tmpGeo.computeFaceNormals();
  5723. tmpGeo.computeVertexNormals();
  5724. // store morph normals
  5725. var faceNormal, vertexNormals;
  5726. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5727. face = this.faces[ f ];
  5728. faceNormal = morphNormals.faceNormals[ f ];
  5729. vertexNormals = morphNormals.vertexNormals[ f ];
  5730. faceNormal.copy( face.normal );
  5731. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5732. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5733. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5734. }
  5735. }
  5736. // restore original normals
  5737. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5738. face = this.faces[ f ];
  5739. face.normal = face.__originalFaceNormal;
  5740. face.vertexNormals = face.__originalVertexNormals;
  5741. }
  5742. },
  5743. computeBoundingBox: function () {
  5744. if ( this.boundingBox === null ) {
  5745. this.boundingBox = new Box3();
  5746. }
  5747. this.boundingBox.setFromPoints( this.vertices );
  5748. },
  5749. computeBoundingSphere: function () {
  5750. if ( this.boundingSphere === null ) {
  5751. this.boundingSphere = new Sphere();
  5752. }
  5753. this.boundingSphere.setFromPoints( this.vertices );
  5754. },
  5755. merge: function ( geometry, matrix, materialIndexOffset ) {
  5756. if ( ! ( geometry && geometry.isGeometry ) ) {
  5757. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  5758. return;
  5759. }
  5760. var normalMatrix,
  5761. vertexOffset = this.vertices.length,
  5762. vertices1 = this.vertices,
  5763. vertices2 = geometry.vertices,
  5764. faces1 = this.faces,
  5765. faces2 = geometry.faces,
  5766. uvs1 = this.faceVertexUvs[ 0 ],
  5767. uvs2 = geometry.faceVertexUvs[ 0 ],
  5768. colors1 = this.colors,
  5769. colors2 = geometry.colors;
  5770. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  5771. if ( matrix !== undefined ) {
  5772. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5773. }
  5774. // vertices
  5775. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  5776. var vertex = vertices2[ i ];
  5777. var vertexCopy = vertex.clone();
  5778. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  5779. vertices1.push( vertexCopy );
  5780. }
  5781. // colors
  5782. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  5783. colors1.push( colors2[ i ].clone() );
  5784. }
  5785. // faces
  5786. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  5787. var face = faces2[ i ], faceCopy, normal, color,
  5788. faceVertexNormals = face.vertexNormals,
  5789. faceVertexColors = face.vertexColors;
  5790. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  5791. faceCopy.normal.copy( face.normal );
  5792. if ( normalMatrix !== undefined ) {
  5793. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  5794. }
  5795. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  5796. normal = faceVertexNormals[ j ].clone();
  5797. if ( normalMatrix !== undefined ) {
  5798. normal.applyMatrix3( normalMatrix ).normalize();
  5799. }
  5800. faceCopy.vertexNormals.push( normal );
  5801. }
  5802. faceCopy.color.copy( face.color );
  5803. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  5804. color = faceVertexColors[ j ];
  5805. faceCopy.vertexColors.push( color.clone() );
  5806. }
  5807. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  5808. faces1.push( faceCopy );
  5809. }
  5810. // uvs
  5811. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  5812. var uv = uvs2[ i ], uvCopy = [];
  5813. if ( uv === undefined ) {
  5814. continue;
  5815. }
  5816. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  5817. uvCopy.push( uv[ j ].clone() );
  5818. }
  5819. uvs1.push( uvCopy );
  5820. }
  5821. },
  5822. mergeMesh: function ( mesh ) {
  5823. if ( ! ( mesh && mesh.isMesh ) ) {
  5824. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  5825. return;
  5826. }
  5827. if ( mesh.matrixAutoUpdate ) mesh.updateMatrix();
  5828. this.merge( mesh.geometry, mesh.matrix );
  5829. },
  5830. /*
  5831. * Checks for duplicate vertices with hashmap.
  5832. * Duplicated vertices are removed
  5833. * and faces' vertices are updated.
  5834. */
  5835. mergeVertices: function () {
  5836. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  5837. var unique = [], changes = [];
  5838. var v, key;
  5839. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  5840. var precision = Math.pow( 10, precisionPoints );
  5841. var i, il, face;
  5842. var indices, j, jl;
  5843. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  5844. v = this.vertices[ i ];
  5845. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  5846. if ( verticesMap[ key ] === undefined ) {
  5847. verticesMap[ key ] = i;
  5848. unique.push( this.vertices[ i ] );
  5849. changes[ i ] = unique.length - 1;
  5850. } else {
  5851. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  5852. changes[ i ] = changes[ verticesMap[ key ] ];
  5853. }
  5854. }
  5855. // if faces are completely degenerate after merging vertices, we
  5856. // have to remove them from the geometry.
  5857. var faceIndicesToRemove = [];
  5858. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  5859. face = this.faces[ i ];
  5860. face.a = changes[ face.a ];
  5861. face.b = changes[ face.b ];
  5862. face.c = changes[ face.c ];
  5863. indices = [ face.a, face.b, face.c ];
  5864. // if any duplicate vertices are found in a Face3
  5865. // we have to remove the face as nothing can be saved
  5866. for ( var n = 0; n < 3; n ++ ) {
  5867. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  5868. faceIndicesToRemove.push( i );
  5869. break;
  5870. }
  5871. }
  5872. }
  5873. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  5874. var idx = faceIndicesToRemove[ i ];
  5875. this.faces.splice( idx, 1 );
  5876. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  5877. this.faceVertexUvs[ j ].splice( idx, 1 );
  5878. }
  5879. }
  5880. // Use unique set of vertices
  5881. var diff = this.vertices.length - unique.length;
  5882. this.vertices = unique;
  5883. return diff;
  5884. },
  5885. setFromPoints: function ( points ) {
  5886. this.vertices = [];
  5887. for ( var i = 0, l = points.length; i < l; i ++ ) {
  5888. var point = points[ i ];
  5889. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  5890. }
  5891. return this;
  5892. },
  5893. sortFacesByMaterialIndex: function () {
  5894. var faces = this.faces;
  5895. var length = faces.length;
  5896. // tag faces
  5897. for ( var i = 0; i < length; i ++ ) {
  5898. faces[ i ]._id = i;
  5899. }
  5900. // sort faces
  5901. function materialIndexSort( a, b ) {
  5902. return a.materialIndex - b.materialIndex;
  5903. }
  5904. faces.sort( materialIndexSort );
  5905. // sort uvs
  5906. var uvs1 = this.faceVertexUvs[ 0 ];
  5907. var uvs2 = this.faceVertexUvs[ 1 ];
  5908. var newUvs1, newUvs2;
  5909. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  5910. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  5911. for ( var i = 0; i < length; i ++ ) {
  5912. var id = faces[ i ]._id;
  5913. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  5914. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  5915. }
  5916. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  5917. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  5918. },
  5919. toJSON: function () {
  5920. var data = {
  5921. metadata: {
  5922. version: 4.5,
  5923. type: 'Geometry',
  5924. generator: 'Geometry.toJSON'
  5925. }
  5926. };
  5927. // standard Geometry serialization
  5928. data.uuid = this.uuid;
  5929. data.type = this.type;
  5930. if ( this.name !== '' ) data.name = this.name;
  5931. if ( this.parameters !== undefined ) {
  5932. var parameters = this.parameters;
  5933. for ( var key in parameters ) {
  5934. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  5935. }
  5936. return data;
  5937. }
  5938. var vertices = [];
  5939. for ( var i = 0; i < this.vertices.length; i ++ ) {
  5940. var vertex = this.vertices[ i ];
  5941. vertices.push( vertex.x, vertex.y, vertex.z );
  5942. }
  5943. var faces = [];
  5944. var normals = [];
  5945. var normalsHash = {};
  5946. var colors = [];
  5947. var colorsHash = {};
  5948. var uvs = [];
  5949. var uvsHash = {};
  5950. for ( var i = 0; i < this.faces.length; i ++ ) {
  5951. var face = this.faces[ i ];
  5952. var hasMaterial = true;
  5953. var hasFaceUv = false; // deprecated
  5954. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  5955. var hasFaceNormal = face.normal.length() > 0;
  5956. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  5957. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  5958. var hasFaceVertexColor = face.vertexColors.length > 0;
  5959. var faceType = 0;
  5960. faceType = setBit( faceType, 0, 0 ); // isQuad
  5961. faceType = setBit( faceType, 1, hasMaterial );
  5962. faceType = setBit( faceType, 2, hasFaceUv );
  5963. faceType = setBit( faceType, 3, hasFaceVertexUv );
  5964. faceType = setBit( faceType, 4, hasFaceNormal );
  5965. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  5966. faceType = setBit( faceType, 6, hasFaceColor );
  5967. faceType = setBit( faceType, 7, hasFaceVertexColor );
  5968. faces.push( faceType );
  5969. faces.push( face.a, face.b, face.c );
  5970. faces.push( face.materialIndex );
  5971. if ( hasFaceVertexUv ) {
  5972. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  5973. faces.push(
  5974. getUvIndex( faceVertexUvs[ 0 ] ),
  5975. getUvIndex( faceVertexUvs[ 1 ] ),
  5976. getUvIndex( faceVertexUvs[ 2 ] )
  5977. );
  5978. }
  5979. if ( hasFaceNormal ) {
  5980. faces.push( getNormalIndex( face.normal ) );
  5981. }
  5982. if ( hasFaceVertexNormal ) {
  5983. var vertexNormals = face.vertexNormals;
  5984. faces.push(
  5985. getNormalIndex( vertexNormals[ 0 ] ),
  5986. getNormalIndex( vertexNormals[ 1 ] ),
  5987. getNormalIndex( vertexNormals[ 2 ] )
  5988. );
  5989. }
  5990. if ( hasFaceColor ) {
  5991. faces.push( getColorIndex( face.color ) );
  5992. }
  5993. if ( hasFaceVertexColor ) {
  5994. var vertexColors = face.vertexColors;
  5995. faces.push(
  5996. getColorIndex( vertexColors[ 0 ] ),
  5997. getColorIndex( vertexColors[ 1 ] ),
  5998. getColorIndex( vertexColors[ 2 ] )
  5999. );
  6000. }
  6001. }
  6002. function setBit( value, position, enabled ) {
  6003. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  6004. }
  6005. function getNormalIndex( normal ) {
  6006. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  6007. if ( normalsHash[ hash ] !== undefined ) {
  6008. return normalsHash[ hash ];
  6009. }
  6010. normalsHash[ hash ] = normals.length / 3;
  6011. normals.push( normal.x, normal.y, normal.z );
  6012. return normalsHash[ hash ];
  6013. }
  6014. function getColorIndex( color ) {
  6015. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6016. if ( colorsHash[ hash ] !== undefined ) {
  6017. return colorsHash[ hash ];
  6018. }
  6019. colorsHash[ hash ] = colors.length;
  6020. colors.push( color.getHex() );
  6021. return colorsHash[ hash ];
  6022. }
  6023. function getUvIndex( uv ) {
  6024. var hash = uv.x.toString() + uv.y.toString();
  6025. if ( uvsHash[ hash ] !== undefined ) {
  6026. return uvsHash[ hash ];
  6027. }
  6028. uvsHash[ hash ] = uvs.length / 2;
  6029. uvs.push( uv.x, uv.y );
  6030. return uvsHash[ hash ];
  6031. }
  6032. data.data = {};
  6033. data.data.vertices = vertices;
  6034. data.data.normals = normals;
  6035. if ( colors.length > 0 ) data.data.colors = colors;
  6036. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6037. data.data.faces = faces;
  6038. return data;
  6039. },
  6040. clone: function () {
  6041. /*
  6042. // Handle primitives
  6043. var parameters = this.parameters;
  6044. if ( parameters !== undefined ) {
  6045. var values = [];
  6046. for ( var key in parameters ) {
  6047. values.push( parameters[ key ] );
  6048. }
  6049. var geometry = Object.create( this.constructor.prototype );
  6050. this.constructor.apply( geometry, values );
  6051. return geometry;
  6052. }
  6053. return new this.constructor().copy( this );
  6054. */
  6055. return new Geometry().copy( this );
  6056. },
  6057. copy: function ( source ) {
  6058. var i, il, j, jl, k, kl;
  6059. // reset
  6060. this.vertices = [];
  6061. this.colors = [];
  6062. this.faces = [];
  6063. this.faceVertexUvs = [[]];
  6064. this.morphTargets = [];
  6065. this.morphNormals = [];
  6066. this.skinWeights = [];
  6067. this.skinIndices = [];
  6068. this.lineDistances = [];
  6069. this.boundingBox = null;
  6070. this.boundingSphere = null;
  6071. // name
  6072. this.name = source.name;
  6073. // vertices
  6074. var vertices = source.vertices;
  6075. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  6076. this.vertices.push( vertices[ i ].clone() );
  6077. }
  6078. // colors
  6079. var colors = source.colors;
  6080. for ( i = 0, il = colors.length; i < il; i ++ ) {
  6081. this.colors.push( colors[ i ].clone() );
  6082. }
  6083. // faces
  6084. var faces = source.faces;
  6085. for ( i = 0, il = faces.length; i < il; i ++ ) {
  6086. this.faces.push( faces[ i ].clone() );
  6087. }
  6088. // face vertex uvs
  6089. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6090. var faceVertexUvs = source.faceVertexUvs[ i ];
  6091. if ( this.faceVertexUvs[ i ] === undefined ) {
  6092. this.faceVertexUvs[ i ] = [];
  6093. }
  6094. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6095. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6096. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  6097. var uv = uvs[ k ];
  6098. uvsCopy.push( uv.clone() );
  6099. }
  6100. this.faceVertexUvs[ i ].push( uvsCopy );
  6101. }
  6102. }
  6103. // morph targets
  6104. var morphTargets = source.morphTargets;
  6105. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  6106. var morphTarget = {};
  6107. morphTarget.name = morphTargets[ i ].name;
  6108. // vertices
  6109. if ( morphTargets[ i ].vertices !== undefined ) {
  6110. morphTarget.vertices = [];
  6111. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  6112. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  6113. }
  6114. }
  6115. // normals
  6116. if ( morphTargets[ i ].normals !== undefined ) {
  6117. morphTarget.normals = [];
  6118. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  6119. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  6120. }
  6121. }
  6122. this.morphTargets.push( morphTarget );
  6123. }
  6124. // morph normals
  6125. var morphNormals = source.morphNormals;
  6126. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  6127. var morphNormal = {};
  6128. // vertex normals
  6129. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  6130. morphNormal.vertexNormals = [];
  6131. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  6132. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  6133. var destVertexNormal = {};
  6134. destVertexNormal.a = srcVertexNormal.a.clone();
  6135. destVertexNormal.b = srcVertexNormal.b.clone();
  6136. destVertexNormal.c = srcVertexNormal.c.clone();
  6137. morphNormal.vertexNormals.push( destVertexNormal );
  6138. }
  6139. }
  6140. // face normals
  6141. if ( morphNormals[ i ].faceNormals !== undefined ) {
  6142. morphNormal.faceNormals = [];
  6143. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  6144. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  6145. }
  6146. }
  6147. this.morphNormals.push( morphNormal );
  6148. }
  6149. // skin weights
  6150. var skinWeights = source.skinWeights;
  6151. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  6152. this.skinWeights.push( skinWeights[ i ].clone() );
  6153. }
  6154. // skin indices
  6155. var skinIndices = source.skinIndices;
  6156. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  6157. this.skinIndices.push( skinIndices[ i ].clone() );
  6158. }
  6159. // line distances
  6160. var lineDistances = source.lineDistances;
  6161. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  6162. this.lineDistances.push( lineDistances[ i ] );
  6163. }
  6164. // bounding box
  6165. var boundingBox = source.boundingBox;
  6166. if ( boundingBox !== null ) {
  6167. this.boundingBox = boundingBox.clone();
  6168. }
  6169. // bounding sphere
  6170. var boundingSphere = source.boundingSphere;
  6171. if ( boundingSphere !== null ) {
  6172. this.boundingSphere = boundingSphere.clone();
  6173. }
  6174. // update flags
  6175. this.elementsNeedUpdate = source.elementsNeedUpdate;
  6176. this.verticesNeedUpdate = source.verticesNeedUpdate;
  6177. this.uvsNeedUpdate = source.uvsNeedUpdate;
  6178. this.normalsNeedUpdate = source.normalsNeedUpdate;
  6179. this.colorsNeedUpdate = source.colorsNeedUpdate;
  6180. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  6181. this.groupsNeedUpdate = source.groupsNeedUpdate;
  6182. return this;
  6183. },
  6184. dispose: function () {
  6185. this.dispatchEvent( { type: 'dispose' } );
  6186. }
  6187. } );
  6188. /**
  6189. * @author mrdoob / http://mrdoob.com/
  6190. */
  6191. function BufferAttribute( array, itemSize, normalized ) {
  6192. if ( Array.isArray( array ) ) {
  6193. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6194. }
  6195. this.name = '';
  6196. this.array = array;
  6197. this.itemSize = itemSize;
  6198. this.count = array !== undefined ? array.length / itemSize : 0;
  6199. this.normalized = normalized === true;
  6200. this.dynamic = false;
  6201. this.updateRange = { offset: 0, count: - 1 };
  6202. this.version = 0;
  6203. }
  6204. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  6205. set: function ( value ) {
  6206. if ( value === true ) this.version ++;
  6207. }
  6208. } );
  6209. Object.assign( BufferAttribute.prototype, {
  6210. isBufferAttribute: true,
  6211. onUploadCallback: function () {},
  6212. setArray: function ( array ) {
  6213. if ( Array.isArray( array ) ) {
  6214. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6215. }
  6216. this.count = array !== undefined ? array.length / this.itemSize : 0;
  6217. this.array = array;
  6218. return this;
  6219. },
  6220. setDynamic: function ( value ) {
  6221. this.dynamic = value;
  6222. return this;
  6223. },
  6224. copy: function ( source ) {
  6225. this.name = source.name;
  6226. this.array = new source.array.constructor( source.array );
  6227. this.itemSize = source.itemSize;
  6228. this.count = source.count;
  6229. this.normalized = source.normalized;
  6230. this.dynamic = source.dynamic;
  6231. return this;
  6232. },
  6233. copyAt: function ( index1, attribute, index2 ) {
  6234. index1 *= this.itemSize;
  6235. index2 *= attribute.itemSize;
  6236. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  6237. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  6238. }
  6239. return this;
  6240. },
  6241. copyArray: function ( array ) {
  6242. this.array.set( array );
  6243. return this;
  6244. },
  6245. copyColorsArray: function ( colors ) {
  6246. var array = this.array, offset = 0;
  6247. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  6248. var color = colors[ i ];
  6249. if ( color === undefined ) {
  6250. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  6251. color = new Color();
  6252. }
  6253. array[ offset ++ ] = color.r;
  6254. array[ offset ++ ] = color.g;
  6255. array[ offset ++ ] = color.b;
  6256. }
  6257. return this;
  6258. },
  6259. copyVector2sArray: function ( vectors ) {
  6260. var array = this.array, offset = 0;
  6261. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6262. var vector = vectors[ i ];
  6263. if ( vector === undefined ) {
  6264. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  6265. vector = new Vector2();
  6266. }
  6267. array[ offset ++ ] = vector.x;
  6268. array[ offset ++ ] = vector.y;
  6269. }
  6270. return this;
  6271. },
  6272. copyVector3sArray: function ( vectors ) {
  6273. var array = this.array, offset = 0;
  6274. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6275. var vector = vectors[ i ];
  6276. if ( vector === undefined ) {
  6277. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  6278. vector = new Vector3();
  6279. }
  6280. array[ offset ++ ] = vector.x;
  6281. array[ offset ++ ] = vector.y;
  6282. array[ offset ++ ] = vector.z;
  6283. }
  6284. return this;
  6285. },
  6286. copyVector4sArray: function ( vectors ) {
  6287. var array = this.array, offset = 0;
  6288. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6289. var vector = vectors[ i ];
  6290. if ( vector === undefined ) {
  6291. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  6292. vector = new Vector4();
  6293. }
  6294. array[ offset ++ ] = vector.x;
  6295. array[ offset ++ ] = vector.y;
  6296. array[ offset ++ ] = vector.z;
  6297. array[ offset ++ ] = vector.w;
  6298. }
  6299. return this;
  6300. },
  6301. set: function ( value, offset ) {
  6302. if ( offset === undefined ) offset = 0;
  6303. this.array.set( value, offset );
  6304. return this;
  6305. },
  6306. getX: function ( index ) {
  6307. return this.array[ index * this.itemSize ];
  6308. },
  6309. setX: function ( index, x ) {
  6310. this.array[ index * this.itemSize ] = x;
  6311. return this;
  6312. },
  6313. getY: function ( index ) {
  6314. return this.array[ index * this.itemSize + 1 ];
  6315. },
  6316. setY: function ( index, y ) {
  6317. this.array[ index * this.itemSize + 1 ] = y;
  6318. return this;
  6319. },
  6320. getZ: function ( index ) {
  6321. return this.array[ index * this.itemSize + 2 ];
  6322. },
  6323. setZ: function ( index, z ) {
  6324. this.array[ index * this.itemSize + 2 ] = z;
  6325. return this;
  6326. },
  6327. getW: function ( index ) {
  6328. return this.array[ index * this.itemSize + 3 ];
  6329. },
  6330. setW: function ( index, w ) {
  6331. this.array[ index * this.itemSize + 3 ] = w;
  6332. return this;
  6333. },
  6334. setXY: function ( index, x, y ) {
  6335. index *= this.itemSize;
  6336. this.array[ index + 0 ] = x;
  6337. this.array[ index + 1 ] = y;
  6338. return this;
  6339. },
  6340. setXYZ: function ( index, x, y, z ) {
  6341. index *= this.itemSize;
  6342. this.array[ index + 0 ] = x;
  6343. this.array[ index + 1 ] = y;
  6344. this.array[ index + 2 ] = z;
  6345. return this;
  6346. },
  6347. setXYZW: function ( index, x, y, z, w ) {
  6348. index *= this.itemSize;
  6349. this.array[ index + 0 ] = x;
  6350. this.array[ index + 1 ] = y;
  6351. this.array[ index + 2 ] = z;
  6352. this.array[ index + 3 ] = w;
  6353. return this;
  6354. },
  6355. onUpload: function ( callback ) {
  6356. this.onUploadCallback = callback;
  6357. return this;
  6358. },
  6359. clone: function () {
  6360. return new this.constructor( this.array, this.itemSize ).copy( this );
  6361. }
  6362. } );
  6363. //
  6364. function Int8BufferAttribute( array, itemSize, normalized ) {
  6365. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  6366. }
  6367. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6368. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6369. function Uint8BufferAttribute( array, itemSize, normalized ) {
  6370. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  6371. }
  6372. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6373. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6374. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  6375. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  6376. }
  6377. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6378. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6379. function Int16BufferAttribute( array, itemSize, normalized ) {
  6380. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  6381. }
  6382. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6383. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6384. function Uint16BufferAttribute( array, itemSize, normalized ) {
  6385. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  6386. }
  6387. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6388. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6389. function Int32BufferAttribute( array, itemSize, normalized ) {
  6390. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  6391. }
  6392. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6393. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6394. function Uint32BufferAttribute( array, itemSize, normalized ) {
  6395. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  6396. }
  6397. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6398. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6399. function Float32BufferAttribute( array, itemSize, normalized ) {
  6400. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  6401. }
  6402. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6403. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6404. function Float64BufferAttribute( array, itemSize, normalized ) {
  6405. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  6406. }
  6407. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6408. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  6409. /**
  6410. * @author mrdoob / http://mrdoob.com/
  6411. */
  6412. function DirectGeometry() {
  6413. this.vertices = [];
  6414. this.normals = [];
  6415. this.colors = [];
  6416. this.uvs = [];
  6417. this.uvs2 = [];
  6418. this.groups = [];
  6419. this.morphTargets = {};
  6420. this.skinWeights = [];
  6421. this.skinIndices = [];
  6422. // this.lineDistances = [];
  6423. this.boundingBox = null;
  6424. this.boundingSphere = null;
  6425. // update flags
  6426. this.verticesNeedUpdate = false;
  6427. this.normalsNeedUpdate = false;
  6428. this.colorsNeedUpdate = false;
  6429. this.uvsNeedUpdate = false;
  6430. this.groupsNeedUpdate = false;
  6431. }
  6432. Object.assign( DirectGeometry.prototype, {
  6433. computeGroups: function ( geometry ) {
  6434. var group;
  6435. var groups = [];
  6436. var materialIndex = undefined;
  6437. var faces = geometry.faces;
  6438. for ( var i = 0; i < faces.length; i ++ ) {
  6439. var face = faces[ i ];
  6440. // materials
  6441. if ( face.materialIndex !== materialIndex ) {
  6442. materialIndex = face.materialIndex;
  6443. if ( group !== undefined ) {
  6444. group.count = ( i * 3 ) - group.start;
  6445. groups.push( group );
  6446. }
  6447. group = {
  6448. start: i * 3,
  6449. materialIndex: materialIndex
  6450. };
  6451. }
  6452. }
  6453. if ( group !== undefined ) {
  6454. group.count = ( i * 3 ) - group.start;
  6455. groups.push( group );
  6456. }
  6457. this.groups = groups;
  6458. },
  6459. fromGeometry: function ( geometry ) {
  6460. var faces = geometry.faces;
  6461. var vertices = geometry.vertices;
  6462. var faceVertexUvs = geometry.faceVertexUvs;
  6463. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6464. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6465. // morphs
  6466. var morphTargets = geometry.morphTargets;
  6467. var morphTargetsLength = morphTargets.length;
  6468. var morphTargetsPosition;
  6469. if ( morphTargetsLength > 0 ) {
  6470. morphTargetsPosition = [];
  6471. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6472. morphTargetsPosition[ i ] = [];
  6473. }
  6474. this.morphTargets.position = morphTargetsPosition;
  6475. }
  6476. var morphNormals = geometry.morphNormals;
  6477. var morphNormalsLength = morphNormals.length;
  6478. var morphTargetsNormal;
  6479. if ( morphNormalsLength > 0 ) {
  6480. morphTargetsNormal = [];
  6481. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6482. morphTargetsNormal[ i ] = [];
  6483. }
  6484. this.morphTargets.normal = morphTargetsNormal;
  6485. }
  6486. // skins
  6487. var skinIndices = geometry.skinIndices;
  6488. var skinWeights = geometry.skinWeights;
  6489. var hasSkinIndices = skinIndices.length === vertices.length;
  6490. var hasSkinWeights = skinWeights.length === vertices.length;
  6491. //
  6492. if ( faces.length === 0 ) {
  6493. console.error( 'THREE.DirectGeometry: Faceless geometries are not supported.' );
  6494. }
  6495. for ( var i = 0; i < faces.length; i ++ ) {
  6496. var face = faces[ i ];
  6497. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6498. var vertexNormals = face.vertexNormals;
  6499. if ( vertexNormals.length === 3 ) {
  6500. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6501. } else {
  6502. var normal = face.normal;
  6503. this.normals.push( normal, normal, normal );
  6504. }
  6505. var vertexColors = face.vertexColors;
  6506. if ( vertexColors.length === 3 ) {
  6507. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6508. } else {
  6509. var color = face.color;
  6510. this.colors.push( color, color, color );
  6511. }
  6512. if ( hasFaceVertexUv === true ) {
  6513. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6514. if ( vertexUvs !== undefined ) {
  6515. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6516. } else {
  6517. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6518. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  6519. }
  6520. }
  6521. if ( hasFaceVertexUv2 === true ) {
  6522. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6523. if ( vertexUvs !== undefined ) {
  6524. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6525. } else {
  6526. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6527. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  6528. }
  6529. }
  6530. // morphs
  6531. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6532. var morphTarget = morphTargets[ j ].vertices;
  6533. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6534. }
  6535. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6536. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6537. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6538. }
  6539. // skins
  6540. if ( hasSkinIndices ) {
  6541. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6542. }
  6543. if ( hasSkinWeights ) {
  6544. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6545. }
  6546. }
  6547. this.computeGroups( geometry );
  6548. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6549. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6550. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6551. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6552. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6553. return this;
  6554. }
  6555. } );
  6556. /**
  6557. * @author mrdoob / http://mrdoob.com/
  6558. */
  6559. function arrayMax( array ) {
  6560. if ( array.length === 0 ) return - Infinity;
  6561. var max = array[ 0 ];
  6562. for ( var i = 1, l = array.length; i < l; ++ i ) {
  6563. if ( array[ i ] > max ) max = array[ i ];
  6564. }
  6565. return max;
  6566. }
  6567. /**
  6568. * @author alteredq / http://alteredqualia.com/
  6569. * @author mrdoob / http://mrdoob.com/
  6570. */
  6571. var bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6572. function BufferGeometry() {
  6573. Object.defineProperty( this, 'id', { value: bufferGeometryId += 2 } );
  6574. this.uuid = _Math.generateUUID();
  6575. this.name = '';
  6576. this.type = 'BufferGeometry';
  6577. this.index = null;
  6578. this.attributes = {};
  6579. this.morphAttributes = {};
  6580. this.groups = [];
  6581. this.boundingBox = null;
  6582. this.boundingSphere = null;
  6583. this.drawRange = { start: 0, count: Infinity };
  6584. this.userData = {};
  6585. }
  6586. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  6587. constructor: BufferGeometry,
  6588. isBufferGeometry: true,
  6589. getIndex: function () {
  6590. return this.index;
  6591. },
  6592. setIndex: function ( index ) {
  6593. if ( Array.isArray( index ) ) {
  6594. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  6595. } else {
  6596. this.index = index;
  6597. }
  6598. },
  6599. addAttribute: function ( name, attribute ) {
  6600. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  6601. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6602. return this.addAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6603. }
  6604. if ( name === 'index' ) {
  6605. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6606. this.setIndex( attribute );
  6607. return this;
  6608. }
  6609. this.attributes[ name ] = attribute;
  6610. return this;
  6611. },
  6612. getAttribute: function ( name ) {
  6613. return this.attributes[ name ];
  6614. },
  6615. removeAttribute: function ( name ) {
  6616. delete this.attributes[ name ];
  6617. return this;
  6618. },
  6619. addGroup: function ( start, count, materialIndex ) {
  6620. this.groups.push( {
  6621. start: start,
  6622. count: count,
  6623. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6624. } );
  6625. },
  6626. clearGroups: function () {
  6627. this.groups = [];
  6628. },
  6629. setDrawRange: function ( start, count ) {
  6630. this.drawRange.start = start;
  6631. this.drawRange.count = count;
  6632. },
  6633. applyMatrix: function ( matrix ) {
  6634. var position = this.attributes.position;
  6635. if ( position !== undefined ) {
  6636. matrix.applyToBufferAttribute( position );
  6637. position.needsUpdate = true;
  6638. }
  6639. var normal = this.attributes.normal;
  6640. if ( normal !== undefined ) {
  6641. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6642. normalMatrix.applyToBufferAttribute( normal );
  6643. normal.needsUpdate = true;
  6644. }
  6645. if ( this.boundingBox !== null ) {
  6646. this.computeBoundingBox();
  6647. }
  6648. if ( this.boundingSphere !== null ) {
  6649. this.computeBoundingSphere();
  6650. }
  6651. return this;
  6652. },
  6653. rotateX: function () {
  6654. // rotate geometry around world x-axis
  6655. var m1 = new Matrix4();
  6656. return function rotateX( angle ) {
  6657. m1.makeRotationX( angle );
  6658. this.applyMatrix( m1 );
  6659. return this;
  6660. };
  6661. }(),
  6662. rotateY: function () {
  6663. // rotate geometry around world y-axis
  6664. var m1 = new Matrix4();
  6665. return function rotateY( angle ) {
  6666. m1.makeRotationY( angle );
  6667. this.applyMatrix( m1 );
  6668. return this;
  6669. };
  6670. }(),
  6671. rotateZ: function () {
  6672. // rotate geometry around world z-axis
  6673. var m1 = new Matrix4();
  6674. return function rotateZ( angle ) {
  6675. m1.makeRotationZ( angle );
  6676. this.applyMatrix( m1 );
  6677. return this;
  6678. };
  6679. }(),
  6680. translate: function () {
  6681. // translate geometry
  6682. var m1 = new Matrix4();
  6683. return function translate( x, y, z ) {
  6684. m1.makeTranslation( x, y, z );
  6685. this.applyMatrix( m1 );
  6686. return this;
  6687. };
  6688. }(),
  6689. scale: function () {
  6690. // scale geometry
  6691. var m1 = new Matrix4();
  6692. return function scale( x, y, z ) {
  6693. m1.makeScale( x, y, z );
  6694. this.applyMatrix( m1 );
  6695. return this;
  6696. };
  6697. }(),
  6698. lookAt: function () {
  6699. var obj = new Object3D();
  6700. return function lookAt( vector ) {
  6701. obj.lookAt( vector );
  6702. obj.updateMatrix();
  6703. this.applyMatrix( obj.matrix );
  6704. };
  6705. }(),
  6706. center: function () {
  6707. var offset = new Vector3();
  6708. return function center() {
  6709. this.computeBoundingBox();
  6710. this.boundingBox.getCenter( offset ).negate();
  6711. this.translate( offset.x, offset.y, offset.z );
  6712. return this;
  6713. };
  6714. }(),
  6715. setFromObject: function ( object ) {
  6716. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6717. var geometry = object.geometry;
  6718. if ( object.isPoints || object.isLine ) {
  6719. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  6720. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  6721. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6722. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6723. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6724. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  6725. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6726. }
  6727. if ( geometry.boundingSphere !== null ) {
  6728. this.boundingSphere = geometry.boundingSphere.clone();
  6729. }
  6730. if ( geometry.boundingBox !== null ) {
  6731. this.boundingBox = geometry.boundingBox.clone();
  6732. }
  6733. } else if ( object.isMesh ) {
  6734. if ( geometry && geometry.isGeometry ) {
  6735. this.fromGeometry( geometry );
  6736. }
  6737. }
  6738. return this;
  6739. },
  6740. setFromPoints: function ( points ) {
  6741. var position = [];
  6742. for ( var i = 0, l = points.length; i < l; i ++ ) {
  6743. var point = points[ i ];
  6744. position.push( point.x, point.y, point.z || 0 );
  6745. }
  6746. this.addAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  6747. return this;
  6748. },
  6749. updateFromObject: function ( object ) {
  6750. var geometry = object.geometry;
  6751. if ( object.isMesh ) {
  6752. var direct = geometry.__directGeometry;
  6753. if ( geometry.elementsNeedUpdate === true ) {
  6754. direct = undefined;
  6755. geometry.elementsNeedUpdate = false;
  6756. }
  6757. if ( direct === undefined ) {
  6758. return this.fromGeometry( geometry );
  6759. }
  6760. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6761. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6762. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6763. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6764. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6765. geometry.verticesNeedUpdate = false;
  6766. geometry.normalsNeedUpdate = false;
  6767. geometry.colorsNeedUpdate = false;
  6768. geometry.uvsNeedUpdate = false;
  6769. geometry.groupsNeedUpdate = false;
  6770. geometry = direct;
  6771. }
  6772. var attribute;
  6773. if ( geometry.verticesNeedUpdate === true ) {
  6774. attribute = this.attributes.position;
  6775. if ( attribute !== undefined ) {
  6776. attribute.copyVector3sArray( geometry.vertices );
  6777. attribute.needsUpdate = true;
  6778. }
  6779. geometry.verticesNeedUpdate = false;
  6780. }
  6781. if ( geometry.normalsNeedUpdate === true ) {
  6782. attribute = this.attributes.normal;
  6783. if ( attribute !== undefined ) {
  6784. attribute.copyVector3sArray( geometry.normals );
  6785. attribute.needsUpdate = true;
  6786. }
  6787. geometry.normalsNeedUpdate = false;
  6788. }
  6789. if ( geometry.colorsNeedUpdate === true ) {
  6790. attribute = this.attributes.color;
  6791. if ( attribute !== undefined ) {
  6792. attribute.copyColorsArray( geometry.colors );
  6793. attribute.needsUpdate = true;
  6794. }
  6795. geometry.colorsNeedUpdate = false;
  6796. }
  6797. if ( geometry.uvsNeedUpdate ) {
  6798. attribute = this.attributes.uv;
  6799. if ( attribute !== undefined ) {
  6800. attribute.copyVector2sArray( geometry.uvs );
  6801. attribute.needsUpdate = true;
  6802. }
  6803. geometry.uvsNeedUpdate = false;
  6804. }
  6805. if ( geometry.lineDistancesNeedUpdate ) {
  6806. attribute = this.attributes.lineDistance;
  6807. if ( attribute !== undefined ) {
  6808. attribute.copyArray( geometry.lineDistances );
  6809. attribute.needsUpdate = true;
  6810. }
  6811. geometry.lineDistancesNeedUpdate = false;
  6812. }
  6813. if ( geometry.groupsNeedUpdate ) {
  6814. geometry.computeGroups( object.geometry );
  6815. this.groups = geometry.groups;
  6816. geometry.groupsNeedUpdate = false;
  6817. }
  6818. return this;
  6819. },
  6820. fromGeometry: function ( geometry ) {
  6821. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  6822. return this.fromDirectGeometry( geometry.__directGeometry );
  6823. },
  6824. fromDirectGeometry: function ( geometry ) {
  6825. var positions = new Float32Array( geometry.vertices.length * 3 );
  6826. this.addAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6827. if ( geometry.normals.length > 0 ) {
  6828. var normals = new Float32Array( geometry.normals.length * 3 );
  6829. this.addAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6830. }
  6831. if ( geometry.colors.length > 0 ) {
  6832. var colors = new Float32Array( geometry.colors.length * 3 );
  6833. this.addAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6834. }
  6835. if ( geometry.uvs.length > 0 ) {
  6836. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6837. this.addAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6838. }
  6839. if ( geometry.uvs2.length > 0 ) {
  6840. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6841. this.addAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6842. }
  6843. // groups
  6844. this.groups = geometry.groups;
  6845. // morphs
  6846. for ( var name in geometry.morphTargets ) {
  6847. var array = [];
  6848. var morphTargets = geometry.morphTargets[ name ];
  6849. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6850. var morphTarget = morphTargets[ i ];
  6851. var attribute = new Float32BufferAttribute( morphTarget.length * 3, 3 );
  6852. array.push( attribute.copyVector3sArray( morphTarget ) );
  6853. }
  6854. this.morphAttributes[ name ] = array;
  6855. }
  6856. // skinning
  6857. if ( geometry.skinIndices.length > 0 ) {
  6858. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  6859. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6860. }
  6861. if ( geometry.skinWeights.length > 0 ) {
  6862. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  6863. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6864. }
  6865. //
  6866. if ( geometry.boundingSphere !== null ) {
  6867. this.boundingSphere = geometry.boundingSphere.clone();
  6868. }
  6869. if ( geometry.boundingBox !== null ) {
  6870. this.boundingBox = geometry.boundingBox.clone();
  6871. }
  6872. return this;
  6873. },
  6874. computeBoundingBox: function () {
  6875. if ( this.boundingBox === null ) {
  6876. this.boundingBox = new Box3();
  6877. }
  6878. var position = this.attributes.position;
  6879. if ( position !== undefined ) {
  6880. this.boundingBox.setFromBufferAttribute( position );
  6881. } else {
  6882. this.boundingBox.makeEmpty();
  6883. }
  6884. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6885. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6886. }
  6887. },
  6888. computeBoundingSphere: function () {
  6889. var box = new Box3();
  6890. var vector = new Vector3();
  6891. return function computeBoundingSphere() {
  6892. if ( this.boundingSphere === null ) {
  6893. this.boundingSphere = new Sphere();
  6894. }
  6895. var position = this.attributes.position;
  6896. if ( position ) {
  6897. var center = this.boundingSphere.center;
  6898. box.setFromBufferAttribute( position );
  6899. box.getCenter( center );
  6900. // hoping to find a boundingSphere with a radius smaller than the
  6901. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6902. var maxRadiusSq = 0;
  6903. for ( var i = 0, il = position.count; i < il; i ++ ) {
  6904. vector.x = position.getX( i );
  6905. vector.y = position.getY( i );
  6906. vector.z = position.getZ( i );
  6907. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6908. }
  6909. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6910. if ( isNaN( this.boundingSphere.radius ) ) {
  6911. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6912. }
  6913. }
  6914. };
  6915. }(),
  6916. computeFaceNormals: function () {
  6917. // backwards compatibility
  6918. },
  6919. computeVertexNormals: function () {
  6920. var index = this.index;
  6921. var attributes = this.attributes;
  6922. var groups = this.groups;
  6923. if ( attributes.position ) {
  6924. var positions = attributes.position.array;
  6925. if ( attributes.normal === undefined ) {
  6926. this.addAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6927. } else {
  6928. // reset existing normals to zero
  6929. var array = attributes.normal.array;
  6930. for ( var i = 0, il = array.length; i < il; i ++ ) {
  6931. array[ i ] = 0;
  6932. }
  6933. }
  6934. var normals = attributes.normal.array;
  6935. var vA, vB, vC;
  6936. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  6937. var cb = new Vector3(), ab = new Vector3();
  6938. // indexed elements
  6939. if ( index ) {
  6940. var indices = index.array;
  6941. if ( groups.length === 0 ) {
  6942. this.addGroup( 0, indices.length );
  6943. }
  6944. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  6945. var group = groups[ j ];
  6946. var start = group.start;
  6947. var count = group.count;
  6948. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6949. vA = indices[ i + 0 ] * 3;
  6950. vB = indices[ i + 1 ] * 3;
  6951. vC = indices[ i + 2 ] * 3;
  6952. pA.fromArray( positions, vA );
  6953. pB.fromArray( positions, vB );
  6954. pC.fromArray( positions, vC );
  6955. cb.subVectors( pC, pB );
  6956. ab.subVectors( pA, pB );
  6957. cb.cross( ab );
  6958. normals[ vA ] += cb.x;
  6959. normals[ vA + 1 ] += cb.y;
  6960. normals[ vA + 2 ] += cb.z;
  6961. normals[ vB ] += cb.x;
  6962. normals[ vB + 1 ] += cb.y;
  6963. normals[ vB + 2 ] += cb.z;
  6964. normals[ vC ] += cb.x;
  6965. normals[ vC + 1 ] += cb.y;
  6966. normals[ vC + 2 ] += cb.z;
  6967. }
  6968. }
  6969. } else {
  6970. // non-indexed elements (unconnected triangle soup)
  6971. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6972. pA.fromArray( positions, i );
  6973. pB.fromArray( positions, i + 3 );
  6974. pC.fromArray( positions, i + 6 );
  6975. cb.subVectors( pC, pB );
  6976. ab.subVectors( pA, pB );
  6977. cb.cross( ab );
  6978. normals[ i ] = cb.x;
  6979. normals[ i + 1 ] = cb.y;
  6980. normals[ i + 2 ] = cb.z;
  6981. normals[ i + 3 ] = cb.x;
  6982. normals[ i + 4 ] = cb.y;
  6983. normals[ i + 5 ] = cb.z;
  6984. normals[ i + 6 ] = cb.x;
  6985. normals[ i + 7 ] = cb.y;
  6986. normals[ i + 8 ] = cb.z;
  6987. }
  6988. }
  6989. this.normalizeNormals();
  6990. attributes.normal.needsUpdate = true;
  6991. }
  6992. },
  6993. merge: function ( geometry, offset ) {
  6994. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  6995. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6996. return;
  6997. }
  6998. if ( offset === undefined ) {
  6999. offset = 0;
  7000. console.warn(
  7001. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  7002. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  7003. );
  7004. }
  7005. var attributes = this.attributes;
  7006. for ( var key in attributes ) {
  7007. if ( geometry.attributes[ key ] === undefined ) continue;
  7008. var attribute1 = attributes[ key ];
  7009. var attributeArray1 = attribute1.array;
  7010. var attribute2 = geometry.attributes[ key ];
  7011. var attributeArray2 = attribute2.array;
  7012. var attributeSize = attribute2.itemSize;
  7013. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  7014. attributeArray1[ j ] = attributeArray2[ i ];
  7015. }
  7016. }
  7017. return this;
  7018. },
  7019. normalizeNormals: function () {
  7020. var vector = new Vector3();
  7021. return function normalizeNormals() {
  7022. var normals = this.attributes.normal;
  7023. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  7024. vector.x = normals.getX( i );
  7025. vector.y = normals.getY( i );
  7026. vector.z = normals.getZ( i );
  7027. vector.normalize();
  7028. normals.setXYZ( i, vector.x, vector.y, vector.z );
  7029. }
  7030. };
  7031. }(),
  7032. toNonIndexed: function () {
  7033. if ( this.index === null ) {
  7034. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  7035. return this;
  7036. }
  7037. var geometry2 = new BufferGeometry();
  7038. var indices = this.index.array;
  7039. var attributes = this.attributes;
  7040. for ( var name in attributes ) {
  7041. var attribute = attributes[ name ];
  7042. var array = attribute.array;
  7043. var itemSize = attribute.itemSize;
  7044. var array2 = new array.constructor( indices.length * itemSize );
  7045. var index = 0, index2 = 0;
  7046. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  7047. index = indices[ i ] * itemSize;
  7048. for ( var j = 0; j < itemSize; j ++ ) {
  7049. array2[ index2 ++ ] = array[ index ++ ];
  7050. }
  7051. }
  7052. geometry2.addAttribute( name, new BufferAttribute( array2, itemSize ) );
  7053. }
  7054. var groups = this.groups;
  7055. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7056. var group = groups[ i ];
  7057. geometry2.addGroup( group.start, group.count, group.materialIndex );
  7058. }
  7059. return geometry2;
  7060. },
  7061. toJSON: function () {
  7062. var data = {
  7063. metadata: {
  7064. version: 4.5,
  7065. type: 'BufferGeometry',
  7066. generator: 'BufferGeometry.toJSON'
  7067. }
  7068. };
  7069. // standard BufferGeometry serialization
  7070. data.uuid = this.uuid;
  7071. data.type = this.type;
  7072. if ( this.name !== '' ) data.name = this.name;
  7073. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  7074. if ( this.parameters !== undefined ) {
  7075. var parameters = this.parameters;
  7076. for ( var key in parameters ) {
  7077. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7078. }
  7079. return data;
  7080. }
  7081. data.data = { attributes: {} };
  7082. var index = this.index;
  7083. if ( index !== null ) {
  7084. var array = Array.prototype.slice.call( index.array );
  7085. data.data.index = {
  7086. type: index.array.constructor.name,
  7087. array: array
  7088. };
  7089. }
  7090. var attributes = this.attributes;
  7091. for ( var key in attributes ) {
  7092. var attribute = attributes[ key ];
  7093. var array = Array.prototype.slice.call( attribute.array );
  7094. data.data.attributes[ key ] = {
  7095. itemSize: attribute.itemSize,
  7096. type: attribute.array.constructor.name,
  7097. array: array,
  7098. normalized: attribute.normalized
  7099. };
  7100. }
  7101. var groups = this.groups;
  7102. if ( groups.length > 0 ) {
  7103. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7104. }
  7105. var boundingSphere = this.boundingSphere;
  7106. if ( boundingSphere !== null ) {
  7107. data.data.boundingSphere = {
  7108. center: boundingSphere.center.toArray(),
  7109. radius: boundingSphere.radius
  7110. };
  7111. }
  7112. return data;
  7113. },
  7114. clone: function () {
  7115. /*
  7116. // Handle primitives
  7117. var parameters = this.parameters;
  7118. if ( parameters !== undefined ) {
  7119. var values = [];
  7120. for ( var key in parameters ) {
  7121. values.push( parameters[ key ] );
  7122. }
  7123. var geometry = Object.create( this.constructor.prototype );
  7124. this.constructor.apply( geometry, values );
  7125. return geometry;
  7126. }
  7127. return new this.constructor().copy( this );
  7128. */
  7129. return new BufferGeometry().copy( this );
  7130. },
  7131. copy: function ( source ) {
  7132. var name, i, l;
  7133. // reset
  7134. this.index = null;
  7135. this.attributes = {};
  7136. this.morphAttributes = {};
  7137. this.groups = [];
  7138. this.boundingBox = null;
  7139. this.boundingSphere = null;
  7140. // name
  7141. this.name = source.name;
  7142. // index
  7143. var index = source.index;
  7144. if ( index !== null ) {
  7145. this.setIndex( index.clone() );
  7146. }
  7147. // attributes
  7148. var attributes = source.attributes;
  7149. for ( name in attributes ) {
  7150. var attribute = attributes[ name ];
  7151. this.addAttribute( name, attribute.clone() );
  7152. }
  7153. // morph attributes
  7154. var morphAttributes = source.morphAttributes;
  7155. for ( name in morphAttributes ) {
  7156. var array = [];
  7157. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  7158. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  7159. array.push( morphAttribute[ i ].clone() );
  7160. }
  7161. this.morphAttributes[ name ] = array;
  7162. }
  7163. // groups
  7164. var groups = source.groups;
  7165. for ( i = 0, l = groups.length; i < l; i ++ ) {
  7166. var group = groups[ i ];
  7167. this.addGroup( group.start, group.count, group.materialIndex );
  7168. }
  7169. // bounding box
  7170. var boundingBox = source.boundingBox;
  7171. if ( boundingBox !== null ) {
  7172. this.boundingBox = boundingBox.clone();
  7173. }
  7174. // bounding sphere
  7175. var boundingSphere = source.boundingSphere;
  7176. if ( boundingSphere !== null ) {
  7177. this.boundingSphere = boundingSphere.clone();
  7178. }
  7179. // draw range
  7180. this.drawRange.start = source.drawRange.start;
  7181. this.drawRange.count = source.drawRange.count;
  7182. // user data
  7183. this.userData = source.userData;
  7184. return this;
  7185. },
  7186. dispose: function () {
  7187. this.dispatchEvent( { type: 'dispose' } );
  7188. }
  7189. } );
  7190. /**
  7191. * @author mrdoob / http://mrdoob.com/
  7192. * @author Mugen87 / https://github.com/Mugen87
  7193. */
  7194. // BoxGeometry
  7195. function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7196. Geometry.call( this );
  7197. this.type = 'BoxGeometry';
  7198. this.parameters = {
  7199. width: width,
  7200. height: height,
  7201. depth: depth,
  7202. widthSegments: widthSegments,
  7203. heightSegments: heightSegments,
  7204. depthSegments: depthSegments
  7205. };
  7206. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  7207. this.mergeVertices();
  7208. }
  7209. BoxGeometry.prototype = Object.create( Geometry.prototype );
  7210. BoxGeometry.prototype.constructor = BoxGeometry;
  7211. // BoxBufferGeometry
  7212. function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7213. BufferGeometry.call( this );
  7214. this.type = 'BoxBufferGeometry';
  7215. this.parameters = {
  7216. width: width,
  7217. height: height,
  7218. depth: depth,
  7219. widthSegments: widthSegments,
  7220. heightSegments: heightSegments,
  7221. depthSegments: depthSegments
  7222. };
  7223. var scope = this;
  7224. width = width || 1;
  7225. height = height || 1;
  7226. depth = depth || 1;
  7227. // segments
  7228. widthSegments = Math.floor( widthSegments ) || 1;
  7229. heightSegments = Math.floor( heightSegments ) || 1;
  7230. depthSegments = Math.floor( depthSegments ) || 1;
  7231. // buffers
  7232. var indices = [];
  7233. var vertices = [];
  7234. var normals = [];
  7235. var uvs = [];
  7236. // helper variables
  7237. var numberOfVertices = 0;
  7238. var groupStart = 0;
  7239. // build each side of the box geometry
  7240. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7241. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7242. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7243. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7244. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7245. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7246. // build geometry
  7247. this.setIndex( indices );
  7248. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7249. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7250. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7251. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7252. var segmentWidth = width / gridX;
  7253. var segmentHeight = height / gridY;
  7254. var widthHalf = width / 2;
  7255. var heightHalf = height / 2;
  7256. var depthHalf = depth / 2;
  7257. var gridX1 = gridX + 1;
  7258. var gridY1 = gridY + 1;
  7259. var vertexCounter = 0;
  7260. var groupCount = 0;
  7261. var ix, iy;
  7262. var vector = new Vector3();
  7263. // generate vertices, normals and uvs
  7264. for ( iy = 0; iy < gridY1; iy ++ ) {
  7265. var y = iy * segmentHeight - heightHalf;
  7266. for ( ix = 0; ix < gridX1; ix ++ ) {
  7267. var x = ix * segmentWidth - widthHalf;
  7268. // set values to correct vector component
  7269. vector[ u ] = x * udir;
  7270. vector[ v ] = y * vdir;
  7271. vector[ w ] = depthHalf;
  7272. // now apply vector to vertex buffer
  7273. vertices.push( vector.x, vector.y, vector.z );
  7274. // set values to correct vector component
  7275. vector[ u ] = 0;
  7276. vector[ v ] = 0;
  7277. vector[ w ] = depth > 0 ? 1 : - 1;
  7278. // now apply vector to normal buffer
  7279. normals.push( vector.x, vector.y, vector.z );
  7280. // uvs
  7281. uvs.push( ix / gridX );
  7282. uvs.push( 1 - ( iy / gridY ) );
  7283. // counters
  7284. vertexCounter += 1;
  7285. }
  7286. }
  7287. // indices
  7288. // 1. you need three indices to draw a single face
  7289. // 2. a single segment consists of two faces
  7290. // 3. so we need to generate six (2*3) indices per segment
  7291. for ( iy = 0; iy < gridY; iy ++ ) {
  7292. for ( ix = 0; ix < gridX; ix ++ ) {
  7293. var a = numberOfVertices + ix + gridX1 * iy;
  7294. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7295. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7296. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7297. // faces
  7298. indices.push( a, b, d );
  7299. indices.push( b, c, d );
  7300. // increase counter
  7301. groupCount += 6;
  7302. }
  7303. }
  7304. // add a group to the geometry. this will ensure multi material support
  7305. scope.addGroup( groupStart, groupCount, materialIndex );
  7306. // calculate new start value for groups
  7307. groupStart += groupCount;
  7308. // update total number of vertices
  7309. numberOfVertices += vertexCounter;
  7310. }
  7311. }
  7312. BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7313. BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
  7314. /**
  7315. * @author mrdoob / http://mrdoob.com/
  7316. * @author Mugen87 / https://github.com/Mugen87
  7317. */
  7318. // PlaneGeometry
  7319. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  7320. Geometry.call( this );
  7321. this.type = 'PlaneGeometry';
  7322. this.parameters = {
  7323. width: width,
  7324. height: height,
  7325. widthSegments: widthSegments,
  7326. heightSegments: heightSegments
  7327. };
  7328. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  7329. this.mergeVertices();
  7330. }
  7331. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  7332. PlaneGeometry.prototype.constructor = PlaneGeometry;
  7333. // PlaneBufferGeometry
  7334. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  7335. BufferGeometry.call( this );
  7336. this.type = 'PlaneBufferGeometry';
  7337. this.parameters = {
  7338. width: width,
  7339. height: height,
  7340. widthSegments: widthSegments,
  7341. heightSegments: heightSegments
  7342. };
  7343. width = width || 1;
  7344. height = height || 1;
  7345. var width_half = width / 2;
  7346. var height_half = height / 2;
  7347. var gridX = Math.floor( widthSegments ) || 1;
  7348. var gridY = Math.floor( heightSegments ) || 1;
  7349. var gridX1 = gridX + 1;
  7350. var gridY1 = gridY + 1;
  7351. var segment_width = width / gridX;
  7352. var segment_height = height / gridY;
  7353. var ix, iy;
  7354. // buffers
  7355. var indices = [];
  7356. var vertices = [];
  7357. var normals = [];
  7358. var uvs = [];
  7359. // generate vertices, normals and uvs
  7360. for ( iy = 0; iy < gridY1; iy ++ ) {
  7361. var y = iy * segment_height - height_half;
  7362. for ( ix = 0; ix < gridX1; ix ++ ) {
  7363. var x = ix * segment_width - width_half;
  7364. vertices.push( x, - y, 0 );
  7365. normals.push( 0, 0, 1 );
  7366. uvs.push( ix / gridX );
  7367. uvs.push( 1 - ( iy / gridY ) );
  7368. }
  7369. }
  7370. // indices
  7371. for ( iy = 0; iy < gridY; iy ++ ) {
  7372. for ( ix = 0; ix < gridX; ix ++ ) {
  7373. var a = ix + gridX1 * iy;
  7374. var b = ix + gridX1 * ( iy + 1 );
  7375. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  7376. var d = ( ix + 1 ) + gridX1 * iy;
  7377. // faces
  7378. indices.push( a, b, d );
  7379. indices.push( b, c, d );
  7380. }
  7381. }
  7382. // build geometry
  7383. this.setIndex( indices );
  7384. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7385. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7386. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7387. }
  7388. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7389. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  7390. /**
  7391. * @author mrdoob / http://mrdoob.com/
  7392. * @author alteredq / http://alteredqualia.com/
  7393. */
  7394. var materialId = 0;
  7395. function Material() {
  7396. Object.defineProperty( this, 'id', { value: materialId ++ } );
  7397. this.uuid = _Math.generateUUID();
  7398. this.name = '';
  7399. this.type = 'Material';
  7400. this.fog = true;
  7401. this.lights = true;
  7402. this.blending = NormalBlending;
  7403. this.side = FrontSide;
  7404. this.flatShading = false;
  7405. this.vertexColors = NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  7406. this.opacity = 1;
  7407. this.transparent = false;
  7408. this.blendSrc = SrcAlphaFactor;
  7409. this.blendDst = OneMinusSrcAlphaFactor;
  7410. this.blendEquation = AddEquation;
  7411. this.blendSrcAlpha = null;
  7412. this.blendDstAlpha = null;
  7413. this.blendEquationAlpha = null;
  7414. this.depthFunc = LessEqualDepth;
  7415. this.depthTest = true;
  7416. this.depthWrite = true;
  7417. this.clippingPlanes = null;
  7418. this.clipIntersection = false;
  7419. this.clipShadows = false;
  7420. this.shadowSide = null;
  7421. this.colorWrite = true;
  7422. this.precision = null; // override the renderer's default precision for this material
  7423. this.polygonOffset = false;
  7424. this.polygonOffsetFactor = 0;
  7425. this.polygonOffsetUnits = 0;
  7426. this.dithering = false;
  7427. this.alphaTest = 0;
  7428. this.premultipliedAlpha = false;
  7429. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  7430. this.visible = true;
  7431. this.userData = {};
  7432. this.needsUpdate = true;
  7433. }
  7434. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  7435. constructor: Material,
  7436. isMaterial: true,
  7437. onBeforeCompile: function () {},
  7438. setValues: function ( values ) {
  7439. if ( values === undefined ) return;
  7440. for ( var key in values ) {
  7441. var newValue = values[ key ];
  7442. if ( newValue === undefined ) {
  7443. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  7444. continue;
  7445. }
  7446. // for backward compatability if shading is set in the constructor
  7447. if ( key === 'shading' ) {
  7448. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  7449. this.flatShading = ( newValue === FlatShading ) ? true : false;
  7450. continue;
  7451. }
  7452. var currentValue = this[ key ];
  7453. if ( currentValue === undefined ) {
  7454. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  7455. continue;
  7456. }
  7457. if ( currentValue && currentValue.isColor ) {
  7458. currentValue.set( newValue );
  7459. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  7460. currentValue.copy( newValue );
  7461. } else if ( key === 'overdraw' ) {
  7462. // ensure overdraw is backwards-compatible with legacy boolean type
  7463. this[ key ] = Number( newValue );
  7464. } else {
  7465. this[ key ] = newValue;
  7466. }
  7467. }
  7468. },
  7469. toJSON: function ( meta ) {
  7470. var isRoot = ( meta === undefined || typeof meta === 'string' );
  7471. if ( isRoot ) {
  7472. meta = {
  7473. textures: {},
  7474. images: {}
  7475. };
  7476. }
  7477. var data = {
  7478. metadata: {
  7479. version: 4.5,
  7480. type: 'Material',
  7481. generator: 'Material.toJSON'
  7482. }
  7483. };
  7484. // standard Material serialization
  7485. data.uuid = this.uuid;
  7486. data.type = this.type;
  7487. if ( this.name !== '' ) data.name = this.name;
  7488. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  7489. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  7490. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  7491. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  7492. if ( this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  7493. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  7494. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  7495. if ( this.clearCoat !== undefined ) data.clearCoat = this.clearCoat;
  7496. if ( this.clearCoatRoughness !== undefined ) data.clearCoatRoughness = this.clearCoatRoughness;
  7497. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  7498. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  7499. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  7500. if ( this.aoMap && this.aoMap.isTexture ) {
  7501. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  7502. data.aoMapIntensity = this.aoMapIntensity;
  7503. }
  7504. if ( this.bumpMap && this.bumpMap.isTexture ) {
  7505. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  7506. data.bumpScale = this.bumpScale;
  7507. }
  7508. if ( this.normalMap && this.normalMap.isTexture ) {
  7509. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  7510. data.normalScale = this.normalScale.toArray();
  7511. }
  7512. if ( this.displacementMap && this.displacementMap.isTexture ) {
  7513. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  7514. data.displacementScale = this.displacementScale;
  7515. data.displacementBias = this.displacementBias;
  7516. }
  7517. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  7518. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  7519. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  7520. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  7521. if ( this.envMap && this.envMap.isTexture ) {
  7522. data.envMap = this.envMap.toJSON( meta ).uuid;
  7523. data.reflectivity = this.reflectivity; // Scale behind envMap
  7524. }
  7525. if ( this.gradientMap && this.gradientMap.isTexture ) {
  7526. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  7527. }
  7528. if ( this.size !== undefined ) data.size = this.size;
  7529. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  7530. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  7531. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  7532. if ( this.side !== FrontSide ) data.side = this.side;
  7533. if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
  7534. if ( this.opacity < 1 ) data.opacity = this.opacity;
  7535. if ( this.transparent === true ) data.transparent = this.transparent;
  7536. data.depthFunc = this.depthFunc;
  7537. data.depthTest = this.depthTest;
  7538. data.depthWrite = this.depthWrite;
  7539. // rotation (SpriteMaterial)
  7540. if ( this.rotation !== 0 ) data.rotation = this.rotation;
  7541. if ( this.linewidth !== 1 ) data.linewidth = this.linewidth;
  7542. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  7543. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  7544. if ( this.scale !== undefined ) data.scale = this.scale;
  7545. if ( this.dithering === true ) data.dithering = true;
  7546. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  7547. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  7548. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  7549. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  7550. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  7551. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  7552. if ( this.morphTargets === true ) data.morphTargets = true;
  7553. if ( this.skinning === true ) data.skinning = true;
  7554. if ( this.visible === false ) data.visible = false;
  7555. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  7556. // TODO: Copied from Object3D.toJSON
  7557. function extractFromCache( cache ) {
  7558. var values = [];
  7559. for ( var key in cache ) {
  7560. var data = cache[ key ];
  7561. delete data.metadata;
  7562. values.push( data );
  7563. }
  7564. return values;
  7565. }
  7566. if ( isRoot ) {
  7567. var textures = extractFromCache( meta.textures );
  7568. var images = extractFromCache( meta.images );
  7569. if ( textures.length > 0 ) data.textures = textures;
  7570. if ( images.length > 0 ) data.images = images;
  7571. }
  7572. return data;
  7573. },
  7574. clone: function () {
  7575. return new this.constructor().copy( this );
  7576. },
  7577. copy: function ( source ) {
  7578. this.name = source.name;
  7579. this.fog = source.fog;
  7580. this.lights = source.lights;
  7581. this.blending = source.blending;
  7582. this.side = source.side;
  7583. this.flatShading = source.flatShading;
  7584. this.vertexColors = source.vertexColors;
  7585. this.opacity = source.opacity;
  7586. this.transparent = source.transparent;
  7587. this.blendSrc = source.blendSrc;
  7588. this.blendDst = source.blendDst;
  7589. this.blendEquation = source.blendEquation;
  7590. this.blendSrcAlpha = source.blendSrcAlpha;
  7591. this.blendDstAlpha = source.blendDstAlpha;
  7592. this.blendEquationAlpha = source.blendEquationAlpha;
  7593. this.depthFunc = source.depthFunc;
  7594. this.depthTest = source.depthTest;
  7595. this.depthWrite = source.depthWrite;
  7596. this.colorWrite = source.colorWrite;
  7597. this.precision = source.precision;
  7598. this.polygonOffset = source.polygonOffset;
  7599. this.polygonOffsetFactor = source.polygonOffsetFactor;
  7600. this.polygonOffsetUnits = source.polygonOffsetUnits;
  7601. this.dithering = source.dithering;
  7602. this.alphaTest = source.alphaTest;
  7603. this.premultipliedAlpha = source.premultipliedAlpha;
  7604. this.overdraw = source.overdraw;
  7605. this.visible = source.visible;
  7606. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  7607. this.clipShadows = source.clipShadows;
  7608. this.clipIntersection = source.clipIntersection;
  7609. var srcPlanes = source.clippingPlanes,
  7610. dstPlanes = null;
  7611. if ( srcPlanes !== null ) {
  7612. var n = srcPlanes.length;
  7613. dstPlanes = new Array( n );
  7614. for ( var i = 0; i !== n; ++ i )
  7615. dstPlanes[ i ] = srcPlanes[ i ].clone();
  7616. }
  7617. this.clippingPlanes = dstPlanes;
  7618. this.shadowSide = source.shadowSide;
  7619. return this;
  7620. },
  7621. dispose: function () {
  7622. this.dispatchEvent( { type: 'dispose' } );
  7623. }
  7624. } );
  7625. /**
  7626. * @author mrdoob / http://mrdoob.com/
  7627. * @author alteredq / http://alteredqualia.com/
  7628. *
  7629. * parameters = {
  7630. * color: <hex>,
  7631. * opacity: <float>,
  7632. * map: new THREE.Texture( <Image> ),
  7633. *
  7634. * lightMap: new THREE.Texture( <Image> ),
  7635. * lightMapIntensity: <float>
  7636. *
  7637. * aoMap: new THREE.Texture( <Image> ),
  7638. * aoMapIntensity: <float>
  7639. *
  7640. * specularMap: new THREE.Texture( <Image> ),
  7641. *
  7642. * alphaMap: new THREE.Texture( <Image> ),
  7643. *
  7644. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  7645. * combine: THREE.Multiply,
  7646. * reflectivity: <float>,
  7647. * refractionRatio: <float>,
  7648. *
  7649. * depthTest: <bool>,
  7650. * depthWrite: <bool>,
  7651. *
  7652. * wireframe: <boolean>,
  7653. * wireframeLinewidth: <float>,
  7654. *
  7655. * skinning: <bool>,
  7656. * morphTargets: <bool>
  7657. * }
  7658. */
  7659. function MeshBasicMaterial( parameters ) {
  7660. Material.call( this );
  7661. this.type = 'MeshBasicMaterial';
  7662. this.color = new Color( 0xffffff ); // emissive
  7663. this.map = null;
  7664. this.lightMap = null;
  7665. this.lightMapIntensity = 1.0;
  7666. this.aoMap = null;
  7667. this.aoMapIntensity = 1.0;
  7668. this.specularMap = null;
  7669. this.alphaMap = null;
  7670. this.envMap = null;
  7671. this.combine = MultiplyOperation;
  7672. this.reflectivity = 1;
  7673. this.refractionRatio = 0.98;
  7674. this.wireframe = false;
  7675. this.wireframeLinewidth = 1;
  7676. this.wireframeLinecap = 'round';
  7677. this.wireframeLinejoin = 'round';
  7678. this.skinning = false;
  7679. this.morphTargets = false;
  7680. this.lights = false;
  7681. this.setValues( parameters );
  7682. }
  7683. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  7684. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  7685. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  7686. MeshBasicMaterial.prototype.copy = function ( source ) {
  7687. Material.prototype.copy.call( this, source );
  7688. this.color.copy( source.color );
  7689. this.map = source.map;
  7690. this.lightMap = source.lightMap;
  7691. this.lightMapIntensity = source.lightMapIntensity;
  7692. this.aoMap = source.aoMap;
  7693. this.aoMapIntensity = source.aoMapIntensity;
  7694. this.specularMap = source.specularMap;
  7695. this.alphaMap = source.alphaMap;
  7696. this.envMap = source.envMap;
  7697. this.combine = source.combine;
  7698. this.reflectivity = source.reflectivity;
  7699. this.refractionRatio = source.refractionRatio;
  7700. this.wireframe = source.wireframe;
  7701. this.wireframeLinewidth = source.wireframeLinewidth;
  7702. this.wireframeLinecap = source.wireframeLinecap;
  7703. this.wireframeLinejoin = source.wireframeLinejoin;
  7704. this.skinning = source.skinning;
  7705. this.morphTargets = source.morphTargets;
  7706. return this;
  7707. };
  7708. /**
  7709. * @author alteredq / http://alteredqualia.com/
  7710. *
  7711. * parameters = {
  7712. * defines: { "label" : "value" },
  7713. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7714. *
  7715. * fragmentShader: <string>,
  7716. * vertexShader: <string>,
  7717. *
  7718. * wireframe: <boolean>,
  7719. * wireframeLinewidth: <float>,
  7720. *
  7721. * lights: <bool>,
  7722. *
  7723. * skinning: <bool>,
  7724. * morphTargets: <bool>,
  7725. * morphNormals: <bool>
  7726. * }
  7727. */
  7728. function ShaderMaterial( parameters ) {
  7729. Material.call( this );
  7730. this.type = 'ShaderMaterial';
  7731. this.defines = {};
  7732. this.uniforms = {};
  7733. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  7734. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  7735. this.linewidth = 1;
  7736. this.wireframe = false;
  7737. this.wireframeLinewidth = 1;
  7738. this.fog = false; // set to use scene fog
  7739. this.lights = false; // set to use scene lights
  7740. this.clipping = false; // set to use user-defined clipping planes
  7741. this.skinning = false; // set to use skinning attribute streams
  7742. this.morphTargets = false; // set to use morph targets
  7743. this.morphNormals = false; // set to use morph normals
  7744. this.extensions = {
  7745. derivatives: false, // set to use derivatives
  7746. fragDepth: false, // set to use fragment depth values
  7747. drawBuffers: false, // set to use draw buffers
  7748. shaderTextureLOD: false // set to use shader texture LOD
  7749. };
  7750. // When rendered geometry doesn't include these attributes but the material does,
  7751. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7752. this.defaultAttributeValues = {
  7753. 'color': [ 1, 1, 1 ],
  7754. 'uv': [ 0, 0 ],
  7755. 'uv2': [ 0, 0 ]
  7756. };
  7757. this.index0AttributeName = undefined;
  7758. this.uniformsNeedUpdate = false;
  7759. if ( parameters !== undefined ) {
  7760. if ( parameters.attributes !== undefined ) {
  7761. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  7762. }
  7763. this.setValues( parameters );
  7764. }
  7765. }
  7766. ShaderMaterial.prototype = Object.create( Material.prototype );
  7767. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7768. ShaderMaterial.prototype.isShaderMaterial = true;
  7769. ShaderMaterial.prototype.copy = function ( source ) {
  7770. Material.prototype.copy.call( this, source );
  7771. this.fragmentShader = source.fragmentShader;
  7772. this.vertexShader = source.vertexShader;
  7773. this.uniforms = UniformsUtils.clone( source.uniforms );
  7774. this.defines = Object.assign( {}, source.defines );
  7775. this.wireframe = source.wireframe;
  7776. this.wireframeLinewidth = source.wireframeLinewidth;
  7777. this.lights = source.lights;
  7778. this.clipping = source.clipping;
  7779. this.skinning = source.skinning;
  7780. this.morphTargets = source.morphTargets;
  7781. this.morphNormals = source.morphNormals;
  7782. this.extensions = source.extensions;
  7783. return this;
  7784. };
  7785. ShaderMaterial.prototype.toJSON = function ( meta ) {
  7786. var data = Material.prototype.toJSON.call( this, meta );
  7787. data.uniforms = this.uniforms;
  7788. data.vertexShader = this.vertexShader;
  7789. data.fragmentShader = this.fragmentShader;
  7790. return data;
  7791. };
  7792. /**
  7793. * @author bhouston / http://clara.io
  7794. */
  7795. function Ray( origin, direction ) {
  7796. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  7797. this.direction = ( direction !== undefined ) ? direction : new Vector3();
  7798. }
  7799. Object.assign( Ray.prototype, {
  7800. set: function ( origin, direction ) {
  7801. this.origin.copy( origin );
  7802. this.direction.copy( direction );
  7803. return this;
  7804. },
  7805. clone: function () {
  7806. return new this.constructor().copy( this );
  7807. },
  7808. copy: function ( ray ) {
  7809. this.origin.copy( ray.origin );
  7810. this.direction.copy( ray.direction );
  7811. return this;
  7812. },
  7813. at: function ( t, target ) {
  7814. if ( target === undefined ) {
  7815. console.warn( 'THREE.Ray: .at() target is now required' );
  7816. target = new Vector3();
  7817. }
  7818. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  7819. },
  7820. lookAt: function ( v ) {
  7821. this.direction.copy( v ).sub( this.origin ).normalize();
  7822. return this;
  7823. },
  7824. recast: function () {
  7825. var v1 = new Vector3();
  7826. return function recast( t ) {
  7827. this.origin.copy( this.at( t, v1 ) );
  7828. return this;
  7829. };
  7830. }(),
  7831. closestPointToPoint: function ( point, target ) {
  7832. if ( target === undefined ) {
  7833. console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
  7834. target = new Vector3();
  7835. }
  7836. target.subVectors( point, this.origin );
  7837. var directionDistance = target.dot( this.direction );
  7838. if ( directionDistance < 0 ) {
  7839. return target.copy( this.origin );
  7840. }
  7841. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  7842. },
  7843. distanceToPoint: function ( point ) {
  7844. return Math.sqrt( this.distanceSqToPoint( point ) );
  7845. },
  7846. distanceSqToPoint: function () {
  7847. var v1 = new Vector3();
  7848. return function distanceSqToPoint( point ) {
  7849. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  7850. // point behind the ray
  7851. if ( directionDistance < 0 ) {
  7852. return this.origin.distanceToSquared( point );
  7853. }
  7854. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  7855. return v1.distanceToSquared( point );
  7856. };
  7857. }(),
  7858. distanceSqToSegment: function () {
  7859. var segCenter = new Vector3();
  7860. var segDir = new Vector3();
  7861. var diff = new Vector3();
  7862. return function distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  7863. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  7864. // It returns the min distance between the ray and the segment
  7865. // defined by v0 and v1
  7866. // It can also set two optional targets :
  7867. // - The closest point on the ray
  7868. // - The closest point on the segment
  7869. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  7870. segDir.copy( v1 ).sub( v0 ).normalize();
  7871. diff.copy( this.origin ).sub( segCenter );
  7872. var segExtent = v0.distanceTo( v1 ) * 0.5;
  7873. var a01 = - this.direction.dot( segDir );
  7874. var b0 = diff.dot( this.direction );
  7875. var b1 = - diff.dot( segDir );
  7876. var c = diff.lengthSq();
  7877. var det = Math.abs( 1 - a01 * a01 );
  7878. var s0, s1, sqrDist, extDet;
  7879. if ( det > 0 ) {
  7880. // The ray and segment are not parallel.
  7881. s0 = a01 * b1 - b0;
  7882. s1 = a01 * b0 - b1;
  7883. extDet = segExtent * det;
  7884. if ( s0 >= 0 ) {
  7885. if ( s1 >= - extDet ) {
  7886. if ( s1 <= extDet ) {
  7887. // region 0
  7888. // Minimum at interior points of ray and segment.
  7889. var invDet = 1 / det;
  7890. s0 *= invDet;
  7891. s1 *= invDet;
  7892. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  7893. } else {
  7894. // region 1
  7895. s1 = segExtent;
  7896. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  7897. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7898. }
  7899. } else {
  7900. // region 5
  7901. s1 = - segExtent;
  7902. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  7903. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7904. }
  7905. } else {
  7906. if ( s1 <= - extDet ) {
  7907. // region 4
  7908. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  7909. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  7910. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7911. } else if ( s1 <= extDet ) {
  7912. // region 3
  7913. s0 = 0;
  7914. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  7915. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  7916. } else {
  7917. // region 2
  7918. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  7919. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  7920. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7921. }
  7922. }
  7923. } else {
  7924. // Ray and segment are parallel.
  7925. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  7926. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  7927. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7928. }
  7929. if ( optionalPointOnRay ) {
  7930. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  7931. }
  7932. if ( optionalPointOnSegment ) {
  7933. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  7934. }
  7935. return sqrDist;
  7936. };
  7937. }(),
  7938. intersectSphere: function () {
  7939. var v1 = new Vector3();
  7940. return function intersectSphere( sphere, target ) {
  7941. v1.subVectors( sphere.center, this.origin );
  7942. var tca = v1.dot( this.direction );
  7943. var d2 = v1.dot( v1 ) - tca * tca;
  7944. var radius2 = sphere.radius * sphere.radius;
  7945. if ( d2 > radius2 ) return null;
  7946. var thc = Math.sqrt( radius2 - d2 );
  7947. // t0 = first intersect point - entrance on front of sphere
  7948. var t0 = tca - thc;
  7949. // t1 = second intersect point - exit point on back of sphere
  7950. var t1 = tca + thc;
  7951. // test to see if both t0 and t1 are behind the ray - if so, return null
  7952. if ( t0 < 0 && t1 < 0 ) return null;
  7953. // test to see if t0 is behind the ray:
  7954. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  7955. // in order to always return an intersect point that is in front of the ray.
  7956. if ( t0 < 0 ) return this.at( t1, target );
  7957. // else t0 is in front of the ray, so return the first collision point scaled by t0
  7958. return this.at( t0, target );
  7959. };
  7960. }(),
  7961. intersectsSphere: function ( sphere ) {
  7962. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  7963. },
  7964. distanceToPlane: function ( plane ) {
  7965. var denominator = plane.normal.dot( this.direction );
  7966. if ( denominator === 0 ) {
  7967. // line is coplanar, return origin
  7968. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  7969. return 0;
  7970. }
  7971. // Null is preferable to undefined since undefined means.... it is undefined
  7972. return null;
  7973. }
  7974. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  7975. // Return if the ray never intersects the plane
  7976. return t >= 0 ? t : null;
  7977. },
  7978. intersectPlane: function ( plane, target ) {
  7979. var t = this.distanceToPlane( plane );
  7980. if ( t === null ) {
  7981. return null;
  7982. }
  7983. return this.at( t, target );
  7984. },
  7985. intersectsPlane: function ( plane ) {
  7986. // check if the ray lies on the plane first
  7987. var distToPoint = plane.distanceToPoint( this.origin );
  7988. if ( distToPoint === 0 ) {
  7989. return true;
  7990. }
  7991. var denominator = plane.normal.dot( this.direction );
  7992. if ( denominator * distToPoint < 0 ) {
  7993. return true;
  7994. }
  7995. // ray origin is behind the plane (and is pointing behind it)
  7996. return false;
  7997. },
  7998. intersectBox: function ( box, target ) {
  7999. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  8000. var invdirx = 1 / this.direction.x,
  8001. invdiry = 1 / this.direction.y,
  8002. invdirz = 1 / this.direction.z;
  8003. var origin = this.origin;
  8004. if ( invdirx >= 0 ) {
  8005. tmin = ( box.min.x - origin.x ) * invdirx;
  8006. tmax = ( box.max.x - origin.x ) * invdirx;
  8007. } else {
  8008. tmin = ( box.max.x - origin.x ) * invdirx;
  8009. tmax = ( box.min.x - origin.x ) * invdirx;
  8010. }
  8011. if ( invdiry >= 0 ) {
  8012. tymin = ( box.min.y - origin.y ) * invdiry;
  8013. tymax = ( box.max.y - origin.y ) * invdiry;
  8014. } else {
  8015. tymin = ( box.max.y - origin.y ) * invdiry;
  8016. tymax = ( box.min.y - origin.y ) * invdiry;
  8017. }
  8018. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  8019. // These lines also handle the case where tmin or tmax is NaN
  8020. // (result of 0 * Infinity). x !== x returns true if x is NaN
  8021. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  8022. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  8023. if ( invdirz >= 0 ) {
  8024. tzmin = ( box.min.z - origin.z ) * invdirz;
  8025. tzmax = ( box.max.z - origin.z ) * invdirz;
  8026. } else {
  8027. tzmin = ( box.max.z - origin.z ) * invdirz;
  8028. tzmax = ( box.min.z - origin.z ) * invdirz;
  8029. }
  8030. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  8031. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  8032. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  8033. //return point closest to the ray (positive side)
  8034. if ( tmax < 0 ) return null;
  8035. return this.at( tmin >= 0 ? tmin : tmax, target );
  8036. },
  8037. intersectsBox: ( function () {
  8038. var v = new Vector3();
  8039. return function intersectsBox( box ) {
  8040. return this.intersectBox( box, v ) !== null;
  8041. };
  8042. } )(),
  8043. intersectTriangle: function () {
  8044. // Compute the offset origin, edges, and normal.
  8045. var diff = new Vector3();
  8046. var edge1 = new Vector3();
  8047. var edge2 = new Vector3();
  8048. var normal = new Vector3();
  8049. return function intersectTriangle( a, b, c, backfaceCulling, target ) {
  8050. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  8051. edge1.subVectors( b, a );
  8052. edge2.subVectors( c, a );
  8053. normal.crossVectors( edge1, edge2 );
  8054. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  8055. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  8056. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  8057. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  8058. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  8059. var DdN = this.direction.dot( normal );
  8060. var sign;
  8061. if ( DdN > 0 ) {
  8062. if ( backfaceCulling ) return null;
  8063. sign = 1;
  8064. } else if ( DdN < 0 ) {
  8065. sign = - 1;
  8066. DdN = - DdN;
  8067. } else {
  8068. return null;
  8069. }
  8070. diff.subVectors( this.origin, a );
  8071. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  8072. // b1 < 0, no intersection
  8073. if ( DdQxE2 < 0 ) {
  8074. return null;
  8075. }
  8076. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  8077. // b2 < 0, no intersection
  8078. if ( DdE1xQ < 0 ) {
  8079. return null;
  8080. }
  8081. // b1+b2 > 1, no intersection
  8082. if ( DdQxE2 + DdE1xQ > DdN ) {
  8083. return null;
  8084. }
  8085. // Line intersects triangle, check if ray does.
  8086. var QdN = - sign * diff.dot( normal );
  8087. // t < 0, no intersection
  8088. if ( QdN < 0 ) {
  8089. return null;
  8090. }
  8091. // Ray intersects triangle.
  8092. return this.at( QdN / DdN, target );
  8093. };
  8094. }(),
  8095. applyMatrix4: function ( matrix4 ) {
  8096. this.origin.applyMatrix4( matrix4 );
  8097. this.direction.transformDirection( matrix4 );
  8098. return this;
  8099. },
  8100. equals: function ( ray ) {
  8101. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  8102. }
  8103. } );
  8104. /**
  8105. * @author bhouston / http://clara.io
  8106. */
  8107. function Line3( start, end ) {
  8108. this.start = ( start !== undefined ) ? start : new Vector3();
  8109. this.end = ( end !== undefined ) ? end : new Vector3();
  8110. }
  8111. Object.assign( Line3.prototype, {
  8112. set: function ( start, end ) {
  8113. this.start.copy( start );
  8114. this.end.copy( end );
  8115. return this;
  8116. },
  8117. clone: function () {
  8118. return new this.constructor().copy( this );
  8119. },
  8120. copy: function ( line ) {
  8121. this.start.copy( line.start );
  8122. this.end.copy( line.end );
  8123. return this;
  8124. },
  8125. getCenter: function ( target ) {
  8126. if ( target === undefined ) {
  8127. console.warn( 'THREE.Line3: .getCenter() target is now required' );
  8128. target = new Vector3();
  8129. }
  8130. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  8131. },
  8132. delta: function ( target ) {
  8133. if ( target === undefined ) {
  8134. console.warn( 'THREE.Line3: .delta() target is now required' );
  8135. target = new Vector3();
  8136. }
  8137. return target.subVectors( this.end, this.start );
  8138. },
  8139. distanceSq: function () {
  8140. return this.start.distanceToSquared( this.end );
  8141. },
  8142. distance: function () {
  8143. return this.start.distanceTo( this.end );
  8144. },
  8145. at: function ( t, target ) {
  8146. if ( target === undefined ) {
  8147. console.warn( 'THREE.Line3: .at() target is now required' );
  8148. target = new Vector3();
  8149. }
  8150. return this.delta( target ).multiplyScalar( t ).add( this.start );
  8151. },
  8152. closestPointToPointParameter: function () {
  8153. var startP = new Vector3();
  8154. var startEnd = new Vector3();
  8155. return function closestPointToPointParameter( point, clampToLine ) {
  8156. startP.subVectors( point, this.start );
  8157. startEnd.subVectors( this.end, this.start );
  8158. var startEnd2 = startEnd.dot( startEnd );
  8159. var startEnd_startP = startEnd.dot( startP );
  8160. var t = startEnd_startP / startEnd2;
  8161. if ( clampToLine ) {
  8162. t = _Math.clamp( t, 0, 1 );
  8163. }
  8164. return t;
  8165. };
  8166. }(),
  8167. closestPointToPoint: function ( point, clampToLine, target ) {
  8168. var t = this.closestPointToPointParameter( point, clampToLine );
  8169. if ( target === undefined ) {
  8170. console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' );
  8171. target = new Vector3();
  8172. }
  8173. return this.delta( target ).multiplyScalar( t ).add( this.start );
  8174. },
  8175. applyMatrix4: function ( matrix ) {
  8176. this.start.applyMatrix4( matrix );
  8177. this.end.applyMatrix4( matrix );
  8178. return this;
  8179. },
  8180. equals: function ( line ) {
  8181. return line.start.equals( this.start ) && line.end.equals( this.end );
  8182. }
  8183. } );
  8184. /**
  8185. * @author bhouston / http://clara.io
  8186. * @author mrdoob / http://mrdoob.com/
  8187. */
  8188. function Triangle( a, b, c ) {
  8189. this.a = ( a !== undefined ) ? a : new Vector3();
  8190. this.b = ( b !== undefined ) ? b : new Vector3();
  8191. this.c = ( c !== undefined ) ? c : new Vector3();
  8192. }
  8193. Object.assign( Triangle, {
  8194. getNormal: function () {
  8195. var v0 = new Vector3();
  8196. return function getNormal( a, b, c, target ) {
  8197. if ( target === undefined ) {
  8198. console.warn( 'THREE.Triangle: .getNormal() target is now required' );
  8199. target = new Vector3();
  8200. }
  8201. target.subVectors( c, b );
  8202. v0.subVectors( a, b );
  8203. target.cross( v0 );
  8204. var targetLengthSq = target.lengthSq();
  8205. if ( targetLengthSq > 0 ) {
  8206. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  8207. }
  8208. return target.set( 0, 0, 0 );
  8209. };
  8210. }(),
  8211. // static/instance method to calculate barycentric coordinates
  8212. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  8213. getBarycoord: function () {
  8214. var v0 = new Vector3();
  8215. var v1 = new Vector3();
  8216. var v2 = new Vector3();
  8217. return function getBarycoord( point, a, b, c, target ) {
  8218. v0.subVectors( c, a );
  8219. v1.subVectors( b, a );
  8220. v2.subVectors( point, a );
  8221. var dot00 = v0.dot( v0 );
  8222. var dot01 = v0.dot( v1 );
  8223. var dot02 = v0.dot( v2 );
  8224. var dot11 = v1.dot( v1 );
  8225. var dot12 = v1.dot( v2 );
  8226. var denom = ( dot00 * dot11 - dot01 * dot01 );
  8227. if ( target === undefined ) {
  8228. console.warn( 'THREE.Triangle: .getBarycoord() target is now required' );
  8229. target = new Vector3();
  8230. }
  8231. // collinear or singular triangle
  8232. if ( denom === 0 ) {
  8233. // arbitrary location outside of triangle?
  8234. // not sure if this is the best idea, maybe should be returning undefined
  8235. return target.set( - 2, - 1, - 1 );
  8236. }
  8237. var invDenom = 1 / denom;
  8238. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  8239. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  8240. // barycentric coordinates must always sum to 1
  8241. return target.set( 1 - u - v, v, u );
  8242. };
  8243. }(),
  8244. containsPoint: function () {
  8245. var v1 = new Vector3();
  8246. return function containsPoint( point, a, b, c ) {
  8247. Triangle.getBarycoord( point, a, b, c, v1 );
  8248. return ( v1.x >= 0 ) && ( v1.y >= 0 ) && ( ( v1.x + v1.y ) <= 1 );
  8249. };
  8250. }()
  8251. } );
  8252. Object.assign( Triangle.prototype, {
  8253. set: function ( a, b, c ) {
  8254. this.a.copy( a );
  8255. this.b.copy( b );
  8256. this.c.copy( c );
  8257. return this;
  8258. },
  8259. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  8260. this.a.copy( points[ i0 ] );
  8261. this.b.copy( points[ i1 ] );
  8262. this.c.copy( points[ i2 ] );
  8263. return this;
  8264. },
  8265. clone: function () {
  8266. return new this.constructor().copy( this );
  8267. },
  8268. copy: function ( triangle ) {
  8269. this.a.copy( triangle.a );
  8270. this.b.copy( triangle.b );
  8271. this.c.copy( triangle.c );
  8272. return this;
  8273. },
  8274. getArea: function () {
  8275. var v0 = new Vector3();
  8276. var v1 = new Vector3();
  8277. return function getArea() {
  8278. v0.subVectors( this.c, this.b );
  8279. v1.subVectors( this.a, this.b );
  8280. return v0.cross( v1 ).length() * 0.5;
  8281. };
  8282. }(),
  8283. getMidpoint: function ( target ) {
  8284. if ( target === undefined ) {
  8285. console.warn( 'THREE.Triangle: .getMidpoint() target is now required' );
  8286. target = new Vector3();
  8287. }
  8288. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  8289. },
  8290. getNormal: function ( target ) {
  8291. return Triangle.getNormal( this.a, this.b, this.c, target );
  8292. },
  8293. getPlane: function ( target ) {
  8294. if ( target === undefined ) {
  8295. console.warn( 'THREE.Triangle: .getPlane() target is now required' );
  8296. target = new Vector3();
  8297. }
  8298. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  8299. },
  8300. getBarycoord: function ( point, target ) {
  8301. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  8302. },
  8303. containsPoint: function ( point ) {
  8304. return Triangle.containsPoint( point, this.a, this.b, this.c );
  8305. },
  8306. intersectsBox: function ( box ) {
  8307. return box.intersectsTriangle( this );
  8308. },
  8309. closestPointToPoint: function () {
  8310. var plane = new Plane();
  8311. var edgeList = [ new Line3(), new Line3(), new Line3() ];
  8312. var projectedPoint = new Vector3();
  8313. var closestPoint = new Vector3();
  8314. return function closestPointToPoint( point, target ) {
  8315. if ( target === undefined ) {
  8316. console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
  8317. target = new Vector3();
  8318. }
  8319. var minDistance = Infinity;
  8320. // project the point onto the plane of the triangle
  8321. plane.setFromCoplanarPoints( this.a, this.b, this.c );
  8322. plane.projectPoint( point, projectedPoint );
  8323. // check if the projection lies within the triangle
  8324. if ( this.containsPoint( projectedPoint ) === true ) {
  8325. // if so, this is the closest point
  8326. target.copy( projectedPoint );
  8327. } else {
  8328. // if not, the point falls outside the triangle. the target is the closest point to the triangle's edges or vertices
  8329. edgeList[ 0 ].set( this.a, this.b );
  8330. edgeList[ 1 ].set( this.b, this.c );
  8331. edgeList[ 2 ].set( this.c, this.a );
  8332. for ( var i = 0; i < edgeList.length; i ++ ) {
  8333. edgeList[ i ].closestPointToPoint( projectedPoint, true, closestPoint );
  8334. var distance = projectedPoint.distanceToSquared( closestPoint );
  8335. if ( distance < minDistance ) {
  8336. minDistance = distance;
  8337. target.copy( closestPoint );
  8338. }
  8339. }
  8340. }
  8341. return target;
  8342. };
  8343. }(),
  8344. equals: function ( triangle ) {
  8345. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  8346. }
  8347. } );
  8348. /**
  8349. * @author mrdoob / http://mrdoob.com/
  8350. * @author alteredq / http://alteredqualia.com/
  8351. * @author mikael emtinger / http://gomo.se/
  8352. * @author jonobr1 / http://jonobr1.com/
  8353. */
  8354. function Mesh( geometry, material ) {
  8355. Object3D.call( this );
  8356. this.type = 'Mesh';
  8357. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  8358. this.material = material !== undefined ? material : new MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  8359. this.drawMode = TrianglesDrawMode;
  8360. this.updateMorphTargets();
  8361. }
  8362. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  8363. constructor: Mesh,
  8364. isMesh: true,
  8365. setDrawMode: function ( value ) {
  8366. this.drawMode = value;
  8367. },
  8368. copy: function ( source ) {
  8369. Object3D.prototype.copy.call( this, source );
  8370. this.drawMode = source.drawMode;
  8371. if ( source.morphTargetInfluences !== undefined ) {
  8372. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  8373. }
  8374. if ( source.morphTargetDictionary !== undefined ) {
  8375. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  8376. }
  8377. return this;
  8378. },
  8379. updateMorphTargets: function () {
  8380. var geometry = this.geometry;
  8381. var m, ml, name;
  8382. if ( geometry.isBufferGeometry ) {
  8383. var morphAttributes = geometry.morphAttributes;
  8384. var keys = Object.keys( morphAttributes );
  8385. if ( keys.length > 0 ) {
  8386. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  8387. if ( morphAttribute !== undefined ) {
  8388. this.morphTargetInfluences = [];
  8389. this.morphTargetDictionary = {};
  8390. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  8391. name = morphAttribute[ m ].name || String( m );
  8392. this.morphTargetInfluences.push( 0 );
  8393. this.morphTargetDictionary[ name ] = m;
  8394. }
  8395. }
  8396. }
  8397. } else {
  8398. var morphTargets = geometry.morphTargets;
  8399. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  8400. this.morphTargetInfluences = [];
  8401. this.morphTargetDictionary = {};
  8402. for ( m = 0, ml = morphTargets.length; m < ml; m ++ ) {
  8403. name = morphTargets[ m ].name || String( m );
  8404. this.morphTargetInfluences.push( 0 );
  8405. this.morphTargetDictionary[ name ] = m;
  8406. }
  8407. }
  8408. }
  8409. },
  8410. raycast: ( function () {
  8411. var inverseMatrix = new Matrix4();
  8412. var ray = new Ray();
  8413. var sphere = new Sphere();
  8414. var vA = new Vector3();
  8415. var vB = new Vector3();
  8416. var vC = new Vector3();
  8417. var tempA = new Vector3();
  8418. var tempB = new Vector3();
  8419. var tempC = new Vector3();
  8420. var uvA = new Vector2();
  8421. var uvB = new Vector2();
  8422. var uvC = new Vector2();
  8423. var barycoord = new Vector3();
  8424. var intersectionPoint = new Vector3();
  8425. var intersectionPointWorld = new Vector3();
  8426. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  8427. Triangle.getBarycoord( point, p1, p2, p3, barycoord );
  8428. uv1.multiplyScalar( barycoord.x );
  8429. uv2.multiplyScalar( barycoord.y );
  8430. uv3.multiplyScalar( barycoord.z );
  8431. uv1.add( uv2 ).add( uv3 );
  8432. return uv1.clone();
  8433. }
  8434. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  8435. var intersect;
  8436. if ( material.side === BackSide ) {
  8437. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  8438. } else {
  8439. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  8440. }
  8441. if ( intersect === null ) return null;
  8442. intersectionPointWorld.copy( point );
  8443. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  8444. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  8445. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  8446. return {
  8447. distance: distance,
  8448. point: intersectionPointWorld.clone(),
  8449. object: object
  8450. };
  8451. }
  8452. function checkBufferGeometryIntersection( object, raycaster, ray, position, uv, a, b, c ) {
  8453. vA.fromBufferAttribute( position, a );
  8454. vB.fromBufferAttribute( position, b );
  8455. vC.fromBufferAttribute( position, c );
  8456. var intersection = checkIntersection( object, object.material, raycaster, ray, vA, vB, vC, intersectionPoint );
  8457. if ( intersection ) {
  8458. if ( uv ) {
  8459. uvA.fromBufferAttribute( uv, a );
  8460. uvB.fromBufferAttribute( uv, b );
  8461. uvC.fromBufferAttribute( uv, c );
  8462. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  8463. }
  8464. var face = new Face3( a, b, c );
  8465. Triangle.getNormal( vA, vB, vC, face.normal );
  8466. intersection.face = face;
  8467. }
  8468. return intersection;
  8469. }
  8470. return function raycast( raycaster, intersects ) {
  8471. var geometry = this.geometry;
  8472. var material = this.material;
  8473. var matrixWorld = this.matrixWorld;
  8474. if ( material === undefined ) return;
  8475. // Checking boundingSphere distance to ray
  8476. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  8477. sphere.copy( geometry.boundingSphere );
  8478. sphere.applyMatrix4( matrixWorld );
  8479. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  8480. //
  8481. inverseMatrix.getInverse( matrixWorld );
  8482. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  8483. // Check boundingBox before continuing
  8484. if ( geometry.boundingBox !== null ) {
  8485. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  8486. }
  8487. var intersection;
  8488. if ( geometry.isBufferGeometry ) {
  8489. var a, b, c;
  8490. var index = geometry.index;
  8491. var position = geometry.attributes.position;
  8492. var uv = geometry.attributes.uv;
  8493. var i, l;
  8494. if ( index !== null ) {
  8495. // indexed buffer geometry
  8496. for ( i = 0, l = index.count; i < l; i += 3 ) {
  8497. a = index.getX( i );
  8498. b = index.getX( i + 1 );
  8499. c = index.getX( i + 2 );
  8500. intersection = checkBufferGeometryIntersection( this, raycaster, ray, position, uv, a, b, c );
  8501. if ( intersection ) {
  8502. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  8503. intersects.push( intersection );
  8504. }
  8505. }
  8506. } else if ( position !== undefined ) {
  8507. // non-indexed buffer geometry
  8508. for ( i = 0, l = position.count; i < l; i += 3 ) {
  8509. a = i;
  8510. b = i + 1;
  8511. c = i + 2;
  8512. intersection = checkBufferGeometryIntersection( this, raycaster, ray, position, uv, a, b, c );
  8513. if ( intersection ) {
  8514. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  8515. intersects.push( intersection );
  8516. }
  8517. }
  8518. }
  8519. } else if ( geometry.isGeometry ) {
  8520. var fvA, fvB, fvC;
  8521. var isMultiMaterial = Array.isArray( material );
  8522. var vertices = geometry.vertices;
  8523. var faces = geometry.faces;
  8524. var uvs;
  8525. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  8526. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  8527. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  8528. var face = faces[ f ];
  8529. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  8530. if ( faceMaterial === undefined ) continue;
  8531. fvA = vertices[ face.a ];
  8532. fvB = vertices[ face.b ];
  8533. fvC = vertices[ face.c ];
  8534. if ( faceMaterial.morphTargets === true ) {
  8535. var morphTargets = geometry.morphTargets;
  8536. var morphInfluences = this.morphTargetInfluences;
  8537. vA.set( 0, 0, 0 );
  8538. vB.set( 0, 0, 0 );
  8539. vC.set( 0, 0, 0 );
  8540. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  8541. var influence = morphInfluences[ t ];
  8542. if ( influence === 0 ) continue;
  8543. var targets = morphTargets[ t ].vertices;
  8544. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  8545. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  8546. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  8547. }
  8548. vA.add( fvA );
  8549. vB.add( fvB );
  8550. vC.add( fvC );
  8551. fvA = vA;
  8552. fvB = vB;
  8553. fvC = vC;
  8554. }
  8555. intersection = checkIntersection( this, faceMaterial, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  8556. if ( intersection ) {
  8557. if ( uvs && uvs[ f ] ) {
  8558. var uvs_f = uvs[ f ];
  8559. uvA.copy( uvs_f[ 0 ] );
  8560. uvB.copy( uvs_f[ 1 ] );
  8561. uvC.copy( uvs_f[ 2 ] );
  8562. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  8563. }
  8564. intersection.face = face;
  8565. intersection.faceIndex = f;
  8566. intersects.push( intersection );
  8567. }
  8568. }
  8569. }
  8570. };
  8571. }() ),
  8572. clone: function () {
  8573. return new this.constructor( this.geometry, this.material ).copy( this );
  8574. }
  8575. } );
  8576. /**
  8577. * @author mrdoob / http://mrdoob.com/
  8578. */
  8579. function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
  8580. var clearColor = new Color( 0x000000 );
  8581. var clearAlpha = 0;
  8582. var planeCamera, planeMesh;
  8583. var boxMesh;
  8584. function render( renderList, scene, camera, forceClear ) {
  8585. var background = scene.background;
  8586. if ( background === null ) {
  8587. setClear( clearColor, clearAlpha );
  8588. } else if ( background && background.isColor ) {
  8589. setClear( background, 1 );
  8590. forceClear = true;
  8591. }
  8592. if ( renderer.autoClear || forceClear ) {
  8593. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  8594. }
  8595. if ( background && background.isCubeTexture ) {
  8596. if ( boxMesh === undefined ) {
  8597. boxMesh = new Mesh(
  8598. new BoxBufferGeometry( 1, 1, 1 ),
  8599. new ShaderMaterial( {
  8600. uniforms: ShaderLib.cube.uniforms,
  8601. vertexShader: ShaderLib.cube.vertexShader,
  8602. fragmentShader: ShaderLib.cube.fragmentShader,
  8603. side: BackSide,
  8604. depthTest: true,
  8605. depthWrite: false,
  8606. fog: false
  8607. } )
  8608. );
  8609. boxMesh.geometry.removeAttribute( 'normal' );
  8610. boxMesh.geometry.removeAttribute( 'uv' );
  8611. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  8612. this.matrixWorld.copyPosition( camera.matrixWorld );
  8613. };
  8614. objects.update( boxMesh );
  8615. }
  8616. boxMesh.material.uniforms.tCube.value = background;
  8617. renderList.push( boxMesh, boxMesh.geometry, boxMesh.material, 0, null );
  8618. } else if ( background && background.isTexture ) {
  8619. if ( planeCamera === undefined ) {
  8620. planeCamera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  8621. planeMesh = new Mesh(
  8622. new PlaneBufferGeometry( 2, 2 ),
  8623. new MeshBasicMaterial( { depthTest: false, depthWrite: false, fog: false } )
  8624. );
  8625. objects.update( planeMesh );
  8626. }
  8627. planeMesh.material.map = background;
  8628. // TODO Push this to renderList
  8629. renderer.renderBufferDirect( planeCamera, null, planeMesh.geometry, planeMesh.material, planeMesh, null );
  8630. }
  8631. }
  8632. function setClear( color, alpha ) {
  8633. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  8634. }
  8635. return {
  8636. getClearColor: function () {
  8637. return clearColor;
  8638. },
  8639. setClearColor: function ( color, alpha ) {
  8640. clearColor.set( color );
  8641. clearAlpha = alpha !== undefined ? alpha : 1;
  8642. setClear( clearColor, clearAlpha );
  8643. },
  8644. getClearAlpha: function () {
  8645. return clearAlpha;
  8646. },
  8647. setClearAlpha: function ( alpha ) {
  8648. clearAlpha = alpha;
  8649. setClear( clearColor, clearAlpha );
  8650. },
  8651. render: render
  8652. };
  8653. }
  8654. /**
  8655. * @author mrdoob / http://mrdoob.com/
  8656. */
  8657. function WebGLBufferRenderer( gl, extensions, info ) {
  8658. var mode;
  8659. function setMode( value ) {
  8660. mode = value;
  8661. }
  8662. function render( start, count ) {
  8663. gl.drawArrays( mode, start, count );
  8664. info.update( count, mode );
  8665. }
  8666. function renderInstances( geometry, start, count ) {
  8667. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  8668. if ( extension === null ) {
  8669. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  8670. return;
  8671. }
  8672. extension.drawArraysInstancedANGLE( mode, start, count, geometry.maxInstancedCount );
  8673. info.update( count, mode, geometry.maxInstancedCount );
  8674. }
  8675. //
  8676. this.setMode = setMode;
  8677. this.render = render;
  8678. this.renderInstances = renderInstances;
  8679. }
  8680. /**
  8681. * @author mrdoob / http://mrdoob.com/
  8682. */
  8683. function WebGLCapabilities( gl, extensions, parameters ) {
  8684. var maxAnisotropy;
  8685. function getMaxAnisotropy() {
  8686. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  8687. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  8688. if ( extension !== null ) {
  8689. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  8690. } else {
  8691. maxAnisotropy = 0;
  8692. }
  8693. return maxAnisotropy;
  8694. }
  8695. function getMaxPrecision( precision ) {
  8696. if ( precision === 'highp' ) {
  8697. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  8698. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  8699. return 'highp';
  8700. }
  8701. precision = 'mediump';
  8702. }
  8703. if ( precision === 'mediump' ) {
  8704. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  8705. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  8706. return 'mediump';
  8707. }
  8708. }
  8709. return 'lowp';
  8710. }
  8711. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  8712. var maxPrecision = getMaxPrecision( precision );
  8713. if ( maxPrecision !== precision ) {
  8714. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  8715. precision = maxPrecision;
  8716. }
  8717. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  8718. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  8719. var maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  8720. var maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  8721. var maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  8722. var maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  8723. var maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  8724. var maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  8725. var maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  8726. var vertexTextures = maxVertexTextures > 0;
  8727. var floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  8728. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  8729. return {
  8730. getMaxAnisotropy: getMaxAnisotropy,
  8731. getMaxPrecision: getMaxPrecision,
  8732. precision: precision,
  8733. logarithmicDepthBuffer: logarithmicDepthBuffer,
  8734. maxTextures: maxTextures,
  8735. maxVertexTextures: maxVertexTextures,
  8736. maxTextureSize: maxTextureSize,
  8737. maxCubemapSize: maxCubemapSize,
  8738. maxAttributes: maxAttributes,
  8739. maxVertexUniforms: maxVertexUniforms,
  8740. maxVaryings: maxVaryings,
  8741. maxFragmentUniforms: maxFragmentUniforms,
  8742. vertexTextures: vertexTextures,
  8743. floatFragmentTextures: floatFragmentTextures,
  8744. floatVertexTextures: floatVertexTextures
  8745. };
  8746. }
  8747. /**
  8748. * @author tschw
  8749. */
  8750. function WebGLClipping() {
  8751. var scope = this,
  8752. globalState = null,
  8753. numGlobalPlanes = 0,
  8754. localClippingEnabled = false,
  8755. renderingShadows = false,
  8756. plane = new Plane(),
  8757. viewNormalMatrix = new Matrix3(),
  8758. uniform = { value: null, needsUpdate: false };
  8759. this.uniform = uniform;
  8760. this.numPlanes = 0;
  8761. this.numIntersection = 0;
  8762. this.init = function ( planes, enableLocalClipping, camera ) {
  8763. var enabled =
  8764. planes.length !== 0 ||
  8765. enableLocalClipping ||
  8766. // enable state of previous frame - the clipping code has to
  8767. // run another frame in order to reset the state:
  8768. numGlobalPlanes !== 0 ||
  8769. localClippingEnabled;
  8770. localClippingEnabled = enableLocalClipping;
  8771. globalState = projectPlanes( planes, camera, 0 );
  8772. numGlobalPlanes = planes.length;
  8773. return enabled;
  8774. };
  8775. this.beginShadows = function () {
  8776. renderingShadows = true;
  8777. projectPlanes( null );
  8778. };
  8779. this.endShadows = function () {
  8780. renderingShadows = false;
  8781. resetGlobalState();
  8782. };
  8783. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  8784. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  8785. // there's no local clipping
  8786. if ( renderingShadows ) {
  8787. // there's no global clipping
  8788. projectPlanes( null );
  8789. } else {
  8790. resetGlobalState();
  8791. }
  8792. } else {
  8793. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  8794. lGlobal = nGlobal * 4,
  8795. dstArray = cache.clippingState || null;
  8796. uniform.value = dstArray; // ensure unique state
  8797. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  8798. for ( var i = 0; i !== lGlobal; ++ i ) {
  8799. dstArray[ i ] = globalState[ i ];
  8800. }
  8801. cache.clippingState = dstArray;
  8802. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  8803. this.numPlanes += nGlobal;
  8804. }
  8805. };
  8806. function resetGlobalState() {
  8807. if ( uniform.value !== globalState ) {
  8808. uniform.value = globalState;
  8809. uniform.needsUpdate = numGlobalPlanes > 0;
  8810. }
  8811. scope.numPlanes = numGlobalPlanes;
  8812. scope.numIntersection = 0;
  8813. }
  8814. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  8815. var nPlanes = planes !== null ? planes.length : 0,
  8816. dstArray = null;
  8817. if ( nPlanes !== 0 ) {
  8818. dstArray = uniform.value;
  8819. if ( skipTransform !== true || dstArray === null ) {
  8820. var flatSize = dstOffset + nPlanes * 4,
  8821. viewMatrix = camera.matrixWorldInverse;
  8822. viewNormalMatrix.getNormalMatrix( viewMatrix );
  8823. if ( dstArray === null || dstArray.length < flatSize ) {
  8824. dstArray = new Float32Array( flatSize );
  8825. }
  8826. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  8827. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  8828. plane.normal.toArray( dstArray, i4 );
  8829. dstArray[ i4 + 3 ] = plane.constant;
  8830. }
  8831. }
  8832. uniform.value = dstArray;
  8833. uniform.needsUpdate = true;
  8834. }
  8835. scope.numPlanes = nPlanes;
  8836. return dstArray;
  8837. }
  8838. }
  8839. /**
  8840. * @author mrdoob / http://mrdoob.com/
  8841. */
  8842. function WebGLExtensions( gl ) {
  8843. var extensions = {};
  8844. return {
  8845. get: function ( name ) {
  8846. if ( extensions[ name ] !== undefined ) {
  8847. return extensions[ name ];
  8848. }
  8849. var extension;
  8850. switch ( name ) {
  8851. case 'WEBGL_depth_texture':
  8852. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  8853. break;
  8854. case 'EXT_texture_filter_anisotropic':
  8855. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  8856. break;
  8857. case 'WEBGL_compressed_texture_s3tc':
  8858. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  8859. break;
  8860. case 'WEBGL_compressed_texture_pvrtc':
  8861. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  8862. break;
  8863. default:
  8864. extension = gl.getExtension( name );
  8865. }
  8866. if ( extension === null ) {
  8867. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  8868. }
  8869. extensions[ name ] = extension;
  8870. return extension;
  8871. }
  8872. };
  8873. }
  8874. /**
  8875. * @author mrdoob / http://mrdoob.com/
  8876. */
  8877. function WebGLGeometries( gl, attributes, info ) {
  8878. var geometries = {};
  8879. var wireframeAttributes = {};
  8880. function onGeometryDispose( event ) {
  8881. var geometry = event.target;
  8882. var buffergeometry = geometries[ geometry.id ];
  8883. if ( buffergeometry.index !== null ) {
  8884. attributes.remove( buffergeometry.index );
  8885. }
  8886. for ( var name in buffergeometry.attributes ) {
  8887. attributes.remove( buffergeometry.attributes[ name ] );
  8888. }
  8889. geometry.removeEventListener( 'dispose', onGeometryDispose );
  8890. delete geometries[ geometry.id ];
  8891. // TODO Remove duplicate code
  8892. var attribute = wireframeAttributes[ geometry.id ];
  8893. if ( attribute ) {
  8894. attributes.remove( attribute );
  8895. delete wireframeAttributes[ geometry.id ];
  8896. }
  8897. attribute = wireframeAttributes[ buffergeometry.id ];
  8898. if ( attribute ) {
  8899. attributes.remove( attribute );
  8900. delete wireframeAttributes[ buffergeometry.id ];
  8901. }
  8902. //
  8903. info.memory.geometries --;
  8904. }
  8905. function get( object, geometry ) {
  8906. var buffergeometry = geometries[ geometry.id ];
  8907. if ( buffergeometry ) return buffergeometry;
  8908. geometry.addEventListener( 'dispose', onGeometryDispose );
  8909. if ( geometry.isBufferGeometry ) {
  8910. buffergeometry = geometry;
  8911. } else if ( geometry.isGeometry ) {
  8912. if ( geometry._bufferGeometry === undefined ) {
  8913. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  8914. }
  8915. buffergeometry = geometry._bufferGeometry;
  8916. }
  8917. geometries[ geometry.id ] = buffergeometry;
  8918. info.memory.geometries ++;
  8919. return buffergeometry;
  8920. }
  8921. function update( geometry ) {
  8922. var index = geometry.index;
  8923. var geometryAttributes = geometry.attributes;
  8924. if ( index !== null ) {
  8925. attributes.update( index, gl.ELEMENT_ARRAY_BUFFER );
  8926. }
  8927. for ( var name in geometryAttributes ) {
  8928. attributes.update( geometryAttributes[ name ], gl.ARRAY_BUFFER );
  8929. }
  8930. // morph targets
  8931. var morphAttributes = geometry.morphAttributes;
  8932. for ( var name in morphAttributes ) {
  8933. var array = morphAttributes[ name ];
  8934. for ( var i = 0, l = array.length; i < l; i ++ ) {
  8935. attributes.update( array[ i ], gl.ARRAY_BUFFER );
  8936. }
  8937. }
  8938. }
  8939. function getWireframeAttribute( geometry ) {
  8940. var attribute = wireframeAttributes[ geometry.id ];
  8941. if ( attribute ) return attribute;
  8942. var indices = [];
  8943. var geometryIndex = geometry.index;
  8944. var geometryAttributes = geometry.attributes;
  8945. // console.time( 'wireframe' );
  8946. if ( geometryIndex !== null ) {
  8947. var array = geometryIndex.array;
  8948. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  8949. var a = array[ i + 0 ];
  8950. var b = array[ i + 1 ];
  8951. var c = array[ i + 2 ];
  8952. indices.push( a, b, b, c, c, a );
  8953. }
  8954. } else {
  8955. var array = geometryAttributes.position.array;
  8956. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  8957. var a = i + 0;
  8958. var b = i + 1;
  8959. var c = i + 2;
  8960. indices.push( a, b, b, c, c, a );
  8961. }
  8962. }
  8963. // console.timeEnd( 'wireframe' );
  8964. attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  8965. attributes.update( attribute, gl.ELEMENT_ARRAY_BUFFER );
  8966. wireframeAttributes[ geometry.id ] = attribute;
  8967. return attribute;
  8968. }
  8969. return {
  8970. get: get,
  8971. update: update,
  8972. getWireframeAttribute: getWireframeAttribute
  8973. };
  8974. }
  8975. /**
  8976. * @author mrdoob / http://mrdoob.com/
  8977. */
  8978. function WebGLIndexedBufferRenderer( gl, extensions, info ) {
  8979. var mode;
  8980. function setMode( value ) {
  8981. mode = value;
  8982. }
  8983. var type, bytesPerElement;
  8984. function setIndex( value ) {
  8985. type = value.type;
  8986. bytesPerElement = value.bytesPerElement;
  8987. }
  8988. function render( start, count ) {
  8989. gl.drawElements( mode, count, type, start * bytesPerElement );
  8990. info.update( count, mode );
  8991. }
  8992. function renderInstances( geometry, start, count ) {
  8993. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  8994. if ( extension === null ) {
  8995. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  8996. return;
  8997. }
  8998. extension.drawElementsInstancedANGLE( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
  8999. info.update( count, mode, geometry.maxInstancedCount );
  9000. }
  9001. //
  9002. this.setMode = setMode;
  9003. this.setIndex = setIndex;
  9004. this.render = render;
  9005. this.renderInstances = renderInstances;
  9006. }
  9007. /**
  9008. * @author Mugen87 / https://github.com/Mugen87
  9009. */
  9010. function WebGLInfo( gl ) {
  9011. var memory = {
  9012. geometries: 0,
  9013. textures: 0
  9014. };
  9015. var render = {
  9016. frame: 0,
  9017. calls: 0,
  9018. triangles: 0,
  9019. points: 0,
  9020. lines: 0
  9021. };
  9022. function update( count, mode, instanceCount ) {
  9023. instanceCount = instanceCount || 1;
  9024. render.calls ++;
  9025. switch ( mode ) {
  9026. case gl.TRIANGLES:
  9027. render.triangles += instanceCount * ( count / 3 );
  9028. break;
  9029. case gl.TRIANGLE_STRIP:
  9030. case gl.TRIANGLE_FAN:
  9031. render.triangles += instanceCount * ( count - 2 );
  9032. break;
  9033. case gl.LINES:
  9034. render.lines += instanceCount * ( count / 2 );
  9035. break;
  9036. case gl.LINE_STRIP:
  9037. render.lines += instanceCount * ( count - 1 );
  9038. break;
  9039. case gl.LINE_LOOP:
  9040. render.lines += instanceCount * count;
  9041. break;
  9042. case gl.POINTS:
  9043. render.points += instanceCount * count;
  9044. break;
  9045. default:
  9046. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  9047. break;
  9048. }
  9049. }
  9050. function reset() {
  9051. render.frame ++;
  9052. render.calls = 0;
  9053. render.triangles = 0;
  9054. render.points = 0;
  9055. render.lines = 0;
  9056. }
  9057. return {
  9058. memory: memory,
  9059. render: render,
  9060. programs: null,
  9061. autoReset: true,
  9062. reset: reset,
  9063. update: update
  9064. };
  9065. }
  9066. /**
  9067. * @author mrdoob / http://mrdoob.com/
  9068. */
  9069. function absNumericalSort( a, b ) {
  9070. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  9071. }
  9072. function WebGLMorphtargets( gl ) {
  9073. var influencesList = {};
  9074. var morphInfluences = new Float32Array( 8 );
  9075. function update( object, geometry, material, program ) {
  9076. var objectInfluences = object.morphTargetInfluences;
  9077. var length = objectInfluences.length;
  9078. var influences = influencesList[ geometry.id ];
  9079. if ( influences === undefined ) {
  9080. // initialise list
  9081. influences = [];
  9082. for ( var i = 0; i < length; i ++ ) {
  9083. influences[ i ] = [ i, 0 ];
  9084. }
  9085. influencesList[ geometry.id ] = influences;
  9086. }
  9087. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9088. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9089. // Remove current morphAttributes
  9090. for ( var i = 0; i < length; i ++ ) {
  9091. var influence = influences[ i ];
  9092. if ( influence[ 1 ] !== 0 ) {
  9093. if ( morphTargets ) geometry.removeAttribute( 'morphTarget' + i );
  9094. if ( morphNormals ) geometry.removeAttribute( 'morphNormal' + i );
  9095. }
  9096. }
  9097. // Collect influences
  9098. for ( var i = 0; i < length; i ++ ) {
  9099. var influence = influences[ i ];
  9100. influence[ 0 ] = i;
  9101. influence[ 1 ] = objectInfluences[ i ];
  9102. }
  9103. influences.sort( absNumericalSort );
  9104. // Add morphAttributes
  9105. for ( var i = 0; i < 8; i ++ ) {
  9106. var influence = influences[ i ];
  9107. if ( influence ) {
  9108. var index = influence[ 0 ];
  9109. var value = influence[ 1 ];
  9110. if ( value ) {
  9111. if ( morphTargets ) geometry.addAttribute( 'morphTarget' + i, morphTargets[ index ] );
  9112. if ( morphNormals ) geometry.addAttribute( 'morphNormal' + i, morphNormals[ index ] );
  9113. morphInfluences[ i ] = value;
  9114. continue;
  9115. }
  9116. }
  9117. morphInfluences[ i ] = 0;
  9118. }
  9119. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  9120. }
  9121. return {
  9122. update: update
  9123. };
  9124. }
  9125. /**
  9126. * @author mrdoob / http://mrdoob.com/
  9127. */
  9128. function WebGLObjects( geometries, info ) {
  9129. var updateList = {};
  9130. function update( object ) {
  9131. var frame = info.render.frame;
  9132. var geometry = object.geometry;
  9133. var buffergeometry = geometries.get( object, geometry );
  9134. // Update once per frame
  9135. if ( updateList[ buffergeometry.id ] !== frame ) {
  9136. if ( geometry.isGeometry ) {
  9137. buffergeometry.updateFromObject( object );
  9138. }
  9139. geometries.update( buffergeometry );
  9140. updateList[ buffergeometry.id ] = frame;
  9141. }
  9142. return buffergeometry;
  9143. }
  9144. function dispose() {
  9145. updateList = {};
  9146. }
  9147. return {
  9148. update: update,
  9149. dispose: dispose
  9150. };
  9151. }
  9152. /**
  9153. * @author mrdoob / http://mrdoob.com/
  9154. */
  9155. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  9156. images = images !== undefined ? images : [];
  9157. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  9158. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  9159. this.flipY = false;
  9160. }
  9161. CubeTexture.prototype = Object.create( Texture.prototype );
  9162. CubeTexture.prototype.constructor = CubeTexture;
  9163. CubeTexture.prototype.isCubeTexture = true;
  9164. Object.defineProperty( CubeTexture.prototype, 'images', {
  9165. get: function () {
  9166. return this.image;
  9167. },
  9168. set: function ( value ) {
  9169. this.image = value;
  9170. }
  9171. } );
  9172. /**
  9173. * @author tschw
  9174. *
  9175. * Uniforms of a program.
  9176. * Those form a tree structure with a special top-level container for the root,
  9177. * which you get by calling 'new WebGLUniforms( gl, program, renderer )'.
  9178. *
  9179. *
  9180. * Properties of inner nodes including the top-level container:
  9181. *
  9182. * .seq - array of nested uniforms
  9183. * .map - nested uniforms by name
  9184. *
  9185. *
  9186. * Methods of all nodes except the top-level container:
  9187. *
  9188. * .setValue( gl, value, [renderer] )
  9189. *
  9190. * uploads a uniform value(s)
  9191. * the 'renderer' parameter is needed for sampler uniforms
  9192. *
  9193. *
  9194. * Static methods of the top-level container (renderer factorizations):
  9195. *
  9196. * .upload( gl, seq, values, renderer )
  9197. *
  9198. * sets uniforms in 'seq' to 'values[id].value'
  9199. *
  9200. * .seqWithValue( seq, values ) : filteredSeq
  9201. *
  9202. * filters 'seq' entries with corresponding entry in values
  9203. *
  9204. *
  9205. * Methods of the top-level container (renderer factorizations):
  9206. *
  9207. * .setValue( gl, name, value )
  9208. *
  9209. * sets uniform with name 'name' to 'value'
  9210. *
  9211. * .set( gl, obj, prop )
  9212. *
  9213. * sets uniform from object and property with same name than uniform
  9214. *
  9215. * .setOptional( gl, obj, prop )
  9216. *
  9217. * like .set for an optional property of the object
  9218. *
  9219. */
  9220. var emptyTexture = new Texture();
  9221. var emptyCubeTexture = new CubeTexture();
  9222. // --- Base for inner nodes (including the root) ---
  9223. function UniformContainer() {
  9224. this.seq = [];
  9225. this.map = {};
  9226. }
  9227. // --- Utilities ---
  9228. // Array Caches (provide typed arrays for temporary by size)
  9229. var arrayCacheF32 = [];
  9230. var arrayCacheI32 = [];
  9231. // Float32Array caches used for uploading Matrix uniforms
  9232. var mat4array = new Float32Array( 16 );
  9233. var mat3array = new Float32Array( 9 );
  9234. var mat2array = new Float32Array( 4 );
  9235. // Flattening for arrays of vectors and matrices
  9236. function flatten( array, nBlocks, blockSize ) {
  9237. var firstElem = array[ 0 ];
  9238. if ( firstElem <= 0 || firstElem > 0 ) return array;
  9239. // unoptimized: ! isNaN( firstElem )
  9240. // see http://jacksondunstan.com/articles/983
  9241. var n = nBlocks * blockSize,
  9242. r = arrayCacheF32[ n ];
  9243. if ( r === undefined ) {
  9244. r = new Float32Array( n );
  9245. arrayCacheF32[ n ] = r;
  9246. }
  9247. if ( nBlocks !== 0 ) {
  9248. firstElem.toArray( r, 0 );
  9249. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  9250. offset += blockSize;
  9251. array[ i ].toArray( r, offset );
  9252. }
  9253. }
  9254. return r;
  9255. }
  9256. function arraysEqual( a, b ) {
  9257. if ( a.length !== b.length ) return false;
  9258. for ( var i = 0, l = a.length; i < l; i ++ ) {
  9259. if ( a[ i ] !== b[ i ] ) return false;
  9260. }
  9261. return true;
  9262. }
  9263. function copyArray( a, b ) {
  9264. for ( var i = 0, l = b.length; i < l; i ++ ) {
  9265. a[ i ] = b[ i ];
  9266. }
  9267. }
  9268. // Texture unit allocation
  9269. function allocTexUnits( renderer, n ) {
  9270. var r = arrayCacheI32[ n ];
  9271. if ( r === undefined ) {
  9272. r = new Int32Array( n );
  9273. arrayCacheI32[ n ] = r;
  9274. }
  9275. for ( var i = 0; i !== n; ++ i )
  9276. r[ i ] = renderer.allocTextureUnit();
  9277. return r;
  9278. }
  9279. // --- Setters ---
  9280. // Note: Defining these methods externally, because they come in a bunch
  9281. // and this way their names minify.
  9282. // Single scalar
  9283. function setValue1f( gl, v ) {
  9284. var cache = this.cache;
  9285. if ( cache[ 0 ] === v ) return;
  9286. gl.uniform1f( this.addr, v );
  9287. cache[ 0 ] = v;
  9288. }
  9289. function setValue1i( gl, v ) {
  9290. var cache = this.cache;
  9291. if ( cache[ 0 ] === v ) return;
  9292. gl.uniform1i( this.addr, v );
  9293. cache[ 0 ] = v;
  9294. }
  9295. // Single float vector (from flat array or THREE.VectorN)
  9296. function setValue2fv( gl, v ) {
  9297. var cache = this.cache;
  9298. if ( v.x !== undefined ) {
  9299. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {
  9300. gl.uniform2f( this.addr, v.x, v.y );
  9301. cache[ 0 ] = v.x;
  9302. cache[ 1 ] = v.y;
  9303. }
  9304. } else {
  9305. if ( arraysEqual( cache, v ) ) return;
  9306. gl.uniform2fv( this.addr, v );
  9307. copyArray( cache, v );
  9308. }
  9309. }
  9310. function setValue3fv( gl, v ) {
  9311. var cache = this.cache;
  9312. if ( v.x !== undefined ) {
  9313. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
  9314. gl.uniform3f( this.addr, v.x, v.y, v.z );
  9315. cache[ 0 ] = v.x;
  9316. cache[ 1 ] = v.y;
  9317. cache[ 2 ] = v.z;
  9318. }
  9319. } else if ( v.r !== undefined ) {
  9320. if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
  9321. gl.uniform3f( this.addr, v.r, v.g, v.b );
  9322. cache[ 0 ] = v.r;
  9323. cache[ 1 ] = v.g;
  9324. cache[ 2 ] = v.b;
  9325. }
  9326. } else {
  9327. if ( arraysEqual( cache, v ) ) return;
  9328. gl.uniform3fv( this.addr, v );
  9329. copyArray( cache, v );
  9330. }
  9331. }
  9332. function setValue4fv( gl, v ) {
  9333. var cache = this.cache;
  9334. if ( v.x !== undefined ) {
  9335. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {
  9336. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  9337. cache[ 0 ] = v.x;
  9338. cache[ 1 ] = v.y;
  9339. cache[ 2 ] = v.z;
  9340. cache[ 3 ] = v.w;
  9341. }
  9342. } else {
  9343. if ( arraysEqual( cache, v ) ) return;
  9344. gl.uniform4fv( this.addr, v );
  9345. copyArray( cache, v );
  9346. }
  9347. }
  9348. // Single matrix (from flat array or MatrixN)
  9349. function setValue2fm( gl, v ) {
  9350. var cache = this.cache;
  9351. var elements = v.elements;
  9352. if ( elements === undefined ) {
  9353. if ( arraysEqual( cache, v ) ) return;
  9354. gl.uniformMatrix2fv( this.addr, false, v );
  9355. copyArray( cache, v );
  9356. } else {
  9357. if ( arraysEqual( cache, elements ) ) return;
  9358. mat2array.set( elements );
  9359. gl.uniformMatrix2fv( this.addr, false, mat2array );
  9360. copyArray( cache, elements );
  9361. }
  9362. }
  9363. function setValue3fm( gl, v ) {
  9364. var cache = this.cache;
  9365. var elements = v.elements;
  9366. if ( elements === undefined ) {
  9367. if ( arraysEqual( cache, v ) ) return;
  9368. gl.uniformMatrix3fv( this.addr, false, v );
  9369. copyArray( cache, v );
  9370. } else {
  9371. if ( arraysEqual( cache, elements ) ) return;
  9372. mat3array.set( elements );
  9373. gl.uniformMatrix3fv( this.addr, false, mat3array );
  9374. copyArray( cache, elements );
  9375. }
  9376. }
  9377. function setValue4fm( gl, v ) {
  9378. var cache = this.cache;
  9379. var elements = v.elements;
  9380. if ( elements === undefined ) {
  9381. if ( arraysEqual( cache, v ) ) return;
  9382. gl.uniformMatrix4fv( this.addr, false, v );
  9383. copyArray( cache, v );
  9384. } else {
  9385. if ( arraysEqual( cache, elements ) ) return;
  9386. mat4array.set( elements );
  9387. gl.uniformMatrix4fv( this.addr, false, mat4array );
  9388. copyArray( cache, elements );
  9389. }
  9390. }
  9391. // Single texture (2D / Cube)
  9392. function setValueT1( gl, v, renderer ) {
  9393. var cache = this.cache;
  9394. var unit = renderer.allocTextureUnit();
  9395. if ( cache[ 0 ] !== unit ) {
  9396. gl.uniform1i( this.addr, unit );
  9397. cache[ 0 ] = unit;
  9398. }
  9399. renderer.setTexture2D( v || emptyTexture, unit );
  9400. }
  9401. function setValueT6( gl, v, renderer ) {
  9402. var cache = this.cache;
  9403. var unit = renderer.allocTextureUnit();
  9404. if ( cache[ 0 ] !== unit ) {
  9405. gl.uniform1i( this.addr, unit );
  9406. cache[ 0 ] = unit;
  9407. }
  9408. renderer.setTextureCube( v || emptyCubeTexture, unit );
  9409. }
  9410. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  9411. function setValue2iv( gl, v ) {
  9412. var cache = this.cache;
  9413. if ( arraysEqual( cache, v ) ) return;
  9414. gl.uniform2iv( this.addr, v );
  9415. copyArray( cache, v );
  9416. }
  9417. function setValue3iv( gl, v ) {
  9418. var cache = this.cache;
  9419. if ( arraysEqual( cache, v ) ) return;
  9420. gl.uniform3iv( this.addr, v );
  9421. copyArray( cache, v );
  9422. }
  9423. function setValue4iv( gl, v ) {
  9424. var cache = this.cache;
  9425. if ( arraysEqual( cache, v ) ) return;
  9426. gl.uniform4iv( this.addr, v );
  9427. copyArray( cache, v );
  9428. }
  9429. // Helper to pick the right setter for the singular case
  9430. function getSingularSetter( type ) {
  9431. switch ( type ) {
  9432. case 0x1406: return setValue1f; // FLOAT
  9433. case 0x8b50: return setValue2fv; // _VEC2
  9434. case 0x8b51: return setValue3fv; // _VEC3
  9435. case 0x8b52: return setValue4fv; // _VEC4
  9436. case 0x8b5a: return setValue2fm; // _MAT2
  9437. case 0x8b5b: return setValue3fm; // _MAT3
  9438. case 0x8b5c: return setValue4fm; // _MAT4
  9439. case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
  9440. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  9441. case 0x1404: case 0x8b56: return setValue1i; // INT, BOOL
  9442. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  9443. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  9444. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  9445. }
  9446. }
  9447. // Array of scalars
  9448. function setValue1fv( gl, v ) {
  9449. var cache = this.cache;
  9450. if ( arraysEqual( cache, v ) ) return;
  9451. gl.uniform1fv( this.addr, v );
  9452. copyArray( cache, v );
  9453. }
  9454. function setValue1iv( gl, v ) {
  9455. var cache = this.cache;
  9456. if ( arraysEqual( cache, v ) ) return;
  9457. gl.uniform1iv( this.addr, v );
  9458. copyArray( cache, v );
  9459. }
  9460. // Array of vectors (flat or from THREE classes)
  9461. function setValueV2a( gl, v ) {
  9462. var cache = this.cache;
  9463. var data = flatten( v, this.size, 2 );
  9464. if ( arraysEqual( cache, data ) ) return;
  9465. gl.uniform2fv( this.addr, data );
  9466. this.updateCache( data );
  9467. }
  9468. function setValueV3a( gl, v ) {
  9469. var cache = this.cache;
  9470. var data = flatten( v, this.size, 3 );
  9471. if ( arraysEqual( cache, data ) ) return;
  9472. gl.uniform3fv( this.addr, data );
  9473. this.updateCache( data );
  9474. }
  9475. function setValueV4a( gl, v ) {
  9476. var cache = this.cache;
  9477. var data = flatten( v, this.size, 4 );
  9478. if ( arraysEqual( cache, data ) ) return;
  9479. gl.uniform4fv( this.addr, data );
  9480. this.updateCache( data );
  9481. }
  9482. // Array of matrices (flat or from THREE clases)
  9483. function setValueM2a( gl, v ) {
  9484. var cache = this.cache;
  9485. var data = flatten( v, this.size, 4 );
  9486. if ( arraysEqual( cache, data ) ) return;
  9487. gl.uniformMatrix2fv( this.addr, false, data );
  9488. this.updateCache( data );
  9489. }
  9490. function setValueM3a( gl, v ) {
  9491. var cache = this.cache;
  9492. var data = flatten( v, this.size, 9 );
  9493. if ( arraysEqual( cache, data ) ) return;
  9494. gl.uniformMatrix3fv( this.addr, false, data );
  9495. this.updateCache( data );
  9496. }
  9497. function setValueM4a( gl, v ) {
  9498. var cache = this.cache;
  9499. var data = flatten( v, this.size, 16 );
  9500. if ( arraysEqual( cache, data ) ) return;
  9501. gl.uniformMatrix4fv( this.addr, false, data );
  9502. this.updateCache( data );
  9503. }
  9504. // Array of textures (2D / Cube)
  9505. function setValueT1a( gl, v, renderer ) {
  9506. var cache = this.cache;
  9507. var n = v.length;
  9508. var units = allocTexUnits( renderer, n );
  9509. if ( arraysEqual( cache, units ) === false ) {
  9510. gl.uniform1iv( this.addr, units );
  9511. copyArray( cache, units );
  9512. }
  9513. for ( var i = 0; i !== n; ++ i ) {
  9514. renderer.setTexture2D( v[ i ] || emptyTexture, units[ i ] );
  9515. }
  9516. }
  9517. function setValueT6a( gl, v, renderer ) {
  9518. var cache = this.cache;
  9519. var n = v.length;
  9520. var units = allocTexUnits( renderer, n );
  9521. if ( arraysEqual( cache, units ) === false ) {
  9522. gl.uniform1iv( this.addr, units );
  9523. copyArray( cache, units );
  9524. }
  9525. for ( var i = 0; i !== n; ++ i ) {
  9526. renderer.setTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  9527. }
  9528. }
  9529. // Helper to pick the right setter for a pure (bottom-level) array
  9530. function getPureArraySetter( type ) {
  9531. switch ( type ) {
  9532. case 0x1406: return setValue1fv; // FLOAT
  9533. case 0x8b50: return setValueV2a; // _VEC2
  9534. case 0x8b51: return setValueV3a; // _VEC3
  9535. case 0x8b52: return setValueV4a; // _VEC4
  9536. case 0x8b5a: return setValueM2a; // _MAT2
  9537. case 0x8b5b: return setValueM3a; // _MAT3
  9538. case 0x8b5c: return setValueM4a; // _MAT4
  9539. case 0x8b5e: return setValueT1a; // SAMPLER_2D
  9540. case 0x8b60: return setValueT6a; // SAMPLER_CUBE
  9541. case 0x1404: case 0x8b56: return setValue1iv; // INT, BOOL
  9542. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  9543. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  9544. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  9545. }
  9546. }
  9547. // --- Uniform Classes ---
  9548. function SingleUniform( id, activeInfo, addr ) {
  9549. this.id = id;
  9550. this.addr = addr;
  9551. this.cache = [];
  9552. this.setValue = getSingularSetter( activeInfo.type );
  9553. // this.path = activeInfo.name; // DEBUG
  9554. }
  9555. function PureArrayUniform( id, activeInfo, addr ) {
  9556. this.id = id;
  9557. this.addr = addr;
  9558. this.cache = [];
  9559. this.size = activeInfo.size;
  9560. this.setValue = getPureArraySetter( activeInfo.type );
  9561. // this.path = activeInfo.name; // DEBUG
  9562. }
  9563. PureArrayUniform.prototype.updateCache = function ( data ) {
  9564. var cache = this.cache;
  9565. if ( data instanceof Float32Array && cache.length !== data.length ) {
  9566. this.cache = new Float32Array( data.length );
  9567. }
  9568. copyArray( cache, data );
  9569. };
  9570. function StructuredUniform( id ) {
  9571. this.id = id;
  9572. UniformContainer.call( this ); // mix-in
  9573. }
  9574. StructuredUniform.prototype.setValue = function ( gl, value ) {
  9575. // Note: Don't need an extra 'renderer' parameter, since samplers
  9576. // are not allowed in structured uniforms.
  9577. var seq = this.seq;
  9578. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9579. var u = seq[ i ];
  9580. u.setValue( gl, value[ u.id ] );
  9581. }
  9582. };
  9583. // --- Top-level ---
  9584. // Parser - builds up the property tree from the path strings
  9585. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  9586. // extracts
  9587. // - the identifier (member name or array index)
  9588. // - followed by an optional right bracket (found when array index)
  9589. // - followed by an optional left bracket or dot (type of subscript)
  9590. //
  9591. // Note: These portions can be read in a non-overlapping fashion and
  9592. // allow straightforward parsing of the hierarchy that WebGL encodes
  9593. // in the uniform names.
  9594. function addUniform( container, uniformObject ) {
  9595. container.seq.push( uniformObject );
  9596. container.map[ uniformObject.id ] = uniformObject;
  9597. }
  9598. function parseUniform( activeInfo, addr, container ) {
  9599. var path = activeInfo.name,
  9600. pathLength = path.length;
  9601. // reset RegExp object, because of the early exit of a previous run
  9602. RePathPart.lastIndex = 0;
  9603. while ( true ) {
  9604. var match = RePathPart.exec( path ),
  9605. matchEnd = RePathPart.lastIndex,
  9606. id = match[ 1 ],
  9607. idIsIndex = match[ 2 ] === ']',
  9608. subscript = match[ 3 ];
  9609. if ( idIsIndex ) id = id | 0; // convert to integer
  9610. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  9611. // bare name or "pure" bottom-level array "[0]" suffix
  9612. addUniform( container, subscript === undefined ?
  9613. new SingleUniform( id, activeInfo, addr ) :
  9614. new PureArrayUniform( id, activeInfo, addr ) );
  9615. break;
  9616. } else {
  9617. // step into inner node / create it in case it doesn't exist
  9618. var map = container.map, next = map[ id ];
  9619. if ( next === undefined ) {
  9620. next = new StructuredUniform( id );
  9621. addUniform( container, next );
  9622. }
  9623. container = next;
  9624. }
  9625. }
  9626. }
  9627. // Root Container
  9628. function WebGLUniforms( gl, program, renderer ) {
  9629. UniformContainer.call( this );
  9630. this.renderer = renderer;
  9631. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  9632. for ( var i = 0; i < n; ++ i ) {
  9633. var info = gl.getActiveUniform( program, i ),
  9634. addr = gl.getUniformLocation( program, info.name );
  9635. parseUniform( info, addr, this );
  9636. }
  9637. }
  9638. WebGLUniforms.prototype.setValue = function ( gl, name, value ) {
  9639. var u = this.map[ name ];
  9640. if ( u !== undefined ) u.setValue( gl, value, this.renderer );
  9641. };
  9642. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  9643. var v = object[ name ];
  9644. if ( v !== undefined ) this.setValue( gl, name, v );
  9645. };
  9646. // Static interface
  9647. WebGLUniforms.upload = function ( gl, seq, values, renderer ) {
  9648. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9649. var u = seq[ i ],
  9650. v = values[ u.id ];
  9651. if ( v.needsUpdate !== false ) {
  9652. // note: always updating when .needsUpdate is undefined
  9653. u.setValue( gl, v.value, renderer );
  9654. }
  9655. }
  9656. };
  9657. WebGLUniforms.seqWithValue = function ( seq, values ) {
  9658. var r = [];
  9659. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9660. var u = seq[ i ];
  9661. if ( u.id in values ) r.push( u );
  9662. }
  9663. return r;
  9664. };
  9665. /**
  9666. * @author mrdoob / http://mrdoob.com/
  9667. */
  9668. function addLineNumbers( string ) {
  9669. var lines = string.split( '\n' );
  9670. for ( var i = 0; i < lines.length; i ++ ) {
  9671. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  9672. }
  9673. return lines.join( '\n' );
  9674. }
  9675. function WebGLShader( gl, type, string ) {
  9676. var shader = gl.createShader( type );
  9677. gl.shaderSource( shader, string );
  9678. gl.compileShader( shader );
  9679. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  9680. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  9681. }
  9682. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  9683. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  9684. }
  9685. // --enable-privileged-webgl-extension
  9686. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  9687. return shader;
  9688. }
  9689. /**
  9690. * @author mrdoob / http://mrdoob.com/
  9691. */
  9692. var programIdCount = 0;
  9693. function getEncodingComponents( encoding ) {
  9694. switch ( encoding ) {
  9695. case LinearEncoding:
  9696. return [ 'Linear', '( value )' ];
  9697. case sRGBEncoding:
  9698. return [ 'sRGB', '( value )' ];
  9699. case RGBEEncoding:
  9700. return [ 'RGBE', '( value )' ];
  9701. case RGBM7Encoding:
  9702. return [ 'RGBM', '( value, 7.0 )' ];
  9703. case RGBM16Encoding:
  9704. return [ 'RGBM', '( value, 16.0 )' ];
  9705. case RGBDEncoding:
  9706. return [ 'RGBD', '( value, 256.0 )' ];
  9707. case GammaEncoding:
  9708. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  9709. default:
  9710. throw new Error( 'unsupported encoding: ' + encoding );
  9711. }
  9712. }
  9713. function getTexelDecodingFunction( functionName, encoding ) {
  9714. var components = getEncodingComponents( encoding );
  9715. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  9716. }
  9717. function getTexelEncodingFunction( functionName, encoding ) {
  9718. var components = getEncodingComponents( encoding );
  9719. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  9720. }
  9721. function getToneMappingFunction( functionName, toneMapping ) {
  9722. var toneMappingName;
  9723. switch ( toneMapping ) {
  9724. case LinearToneMapping:
  9725. toneMappingName = 'Linear';
  9726. break;
  9727. case ReinhardToneMapping:
  9728. toneMappingName = 'Reinhard';
  9729. break;
  9730. case Uncharted2ToneMapping:
  9731. toneMappingName = 'Uncharted2';
  9732. break;
  9733. case CineonToneMapping:
  9734. toneMappingName = 'OptimizedCineon';
  9735. break;
  9736. default:
  9737. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  9738. }
  9739. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  9740. }
  9741. function generateExtensions( extensions, parameters, rendererExtensions ) {
  9742. extensions = extensions || {};
  9743. var chunks = [
  9744. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.normalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  9745. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  9746. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  9747. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  9748. ];
  9749. return chunks.filter( filterEmptyLine ).join( '\n' );
  9750. }
  9751. function generateDefines( defines ) {
  9752. var chunks = [];
  9753. for ( var name in defines ) {
  9754. var value = defines[ name ];
  9755. if ( value === false ) continue;
  9756. chunks.push( '#define ' + name + ' ' + value );
  9757. }
  9758. return chunks.join( '\n' );
  9759. }
  9760. function fetchAttributeLocations( gl, program ) {
  9761. var attributes = {};
  9762. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  9763. for ( var i = 0; i < n; i ++ ) {
  9764. var info = gl.getActiveAttrib( program, i );
  9765. var name = info.name;
  9766. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  9767. attributes[ name ] = gl.getAttribLocation( program, name );
  9768. }
  9769. return attributes;
  9770. }
  9771. function filterEmptyLine( string ) {
  9772. return string !== '';
  9773. }
  9774. function replaceLightNums( string, parameters ) {
  9775. return string
  9776. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  9777. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  9778. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  9779. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  9780. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  9781. }
  9782. function replaceClippingPlaneNums( string, parameters ) {
  9783. return string
  9784. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  9785. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  9786. }
  9787. function parseIncludes( string ) {
  9788. var pattern = /^[ \t]*#include +<([\w\d.]+)>/gm;
  9789. function replace( match, include ) {
  9790. var replace = ShaderChunk[ include ];
  9791. if ( replace === undefined ) {
  9792. throw new Error( 'Can not resolve #include <' + include + '>' );
  9793. }
  9794. return parseIncludes( replace );
  9795. }
  9796. return string.replace( pattern, replace );
  9797. }
  9798. function unrollLoops( string ) {
  9799. var pattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  9800. function replace( match, start, end, snippet ) {
  9801. var unroll = '';
  9802. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  9803. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  9804. }
  9805. return unroll;
  9806. }
  9807. return string.replace( pattern, replace );
  9808. }
  9809. function WebGLProgram( renderer, extensions, code, material, shader, parameters ) {
  9810. var gl = renderer.context;
  9811. var defines = material.defines;
  9812. var vertexShader = shader.vertexShader;
  9813. var fragmentShader = shader.fragmentShader;
  9814. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  9815. if ( parameters.shadowMapType === PCFShadowMap ) {
  9816. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  9817. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  9818. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  9819. }
  9820. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  9821. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  9822. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  9823. if ( parameters.envMap ) {
  9824. switch ( material.envMap.mapping ) {
  9825. case CubeReflectionMapping:
  9826. case CubeRefractionMapping:
  9827. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  9828. break;
  9829. case CubeUVReflectionMapping:
  9830. case CubeUVRefractionMapping:
  9831. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  9832. break;
  9833. case EquirectangularReflectionMapping:
  9834. case EquirectangularRefractionMapping:
  9835. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  9836. break;
  9837. case SphericalReflectionMapping:
  9838. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  9839. break;
  9840. }
  9841. switch ( material.envMap.mapping ) {
  9842. case CubeRefractionMapping:
  9843. case EquirectangularRefractionMapping:
  9844. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  9845. break;
  9846. }
  9847. switch ( material.combine ) {
  9848. case MultiplyOperation:
  9849. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  9850. break;
  9851. case MixOperation:
  9852. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  9853. break;
  9854. case AddOperation:
  9855. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  9856. break;
  9857. }
  9858. }
  9859. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  9860. // console.log( 'building new program ' );
  9861. //
  9862. var customExtensions = generateExtensions( material.extensions, parameters, extensions );
  9863. var customDefines = generateDefines( defines );
  9864. //
  9865. var program = gl.createProgram();
  9866. var prefixVertex, prefixFragment;
  9867. if ( material.isRawShaderMaterial ) {
  9868. prefixVertex = [
  9869. customDefines
  9870. ].filter( filterEmptyLine ).join( '\n' );
  9871. if ( prefixVertex.length > 0 ) {
  9872. prefixVertex += '\n';
  9873. }
  9874. prefixFragment = [
  9875. customExtensions,
  9876. customDefines
  9877. ].filter( filterEmptyLine ).join( '\n' );
  9878. if ( prefixFragment.length > 0 ) {
  9879. prefixFragment += '\n';
  9880. }
  9881. } else {
  9882. prefixVertex = [
  9883. 'precision ' + parameters.precision + ' float;',
  9884. 'precision ' + parameters.precision + ' int;',
  9885. '#define SHADER_NAME ' + shader.name,
  9886. customDefines,
  9887. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  9888. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  9889. '#define MAX_BONES ' + parameters.maxBones,
  9890. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  9891. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  9892. parameters.map ? '#define USE_MAP' : '',
  9893. parameters.envMap ? '#define USE_ENVMAP' : '',
  9894. parameters.envMap ? '#define ' + envMapModeDefine : '',
  9895. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  9896. parameters.aoMap ? '#define USE_AOMAP' : '',
  9897. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  9898. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  9899. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  9900. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  9901. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  9902. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  9903. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  9904. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  9905. parameters.vertexColors ? '#define USE_COLOR' : '',
  9906. parameters.flatShading ? '#define FLAT_SHADED' : '',
  9907. parameters.skinning ? '#define USE_SKINNING' : '',
  9908. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  9909. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  9910. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  9911. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  9912. parameters.flipSided ? '#define FLIP_SIDED' : '',
  9913. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  9914. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  9915. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  9916. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  9917. parameters.logarithmicDepthBuffer && extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  9918. 'uniform mat4 modelMatrix;',
  9919. 'uniform mat4 modelViewMatrix;',
  9920. 'uniform mat4 projectionMatrix;',
  9921. 'uniform mat4 viewMatrix;',
  9922. 'uniform mat3 normalMatrix;',
  9923. 'uniform vec3 cameraPosition;',
  9924. 'attribute vec3 position;',
  9925. 'attribute vec3 normal;',
  9926. 'attribute vec2 uv;',
  9927. '#ifdef USE_COLOR',
  9928. ' attribute vec3 color;',
  9929. '#endif',
  9930. '#ifdef USE_MORPHTARGETS',
  9931. ' attribute vec3 morphTarget0;',
  9932. ' attribute vec3 morphTarget1;',
  9933. ' attribute vec3 morphTarget2;',
  9934. ' attribute vec3 morphTarget3;',
  9935. ' #ifdef USE_MORPHNORMALS',
  9936. ' attribute vec3 morphNormal0;',
  9937. ' attribute vec3 morphNormal1;',
  9938. ' attribute vec3 morphNormal2;',
  9939. ' attribute vec3 morphNormal3;',
  9940. ' #else',
  9941. ' attribute vec3 morphTarget4;',
  9942. ' attribute vec3 morphTarget5;',
  9943. ' attribute vec3 morphTarget6;',
  9944. ' attribute vec3 morphTarget7;',
  9945. ' #endif',
  9946. '#endif',
  9947. '#ifdef USE_SKINNING',
  9948. ' attribute vec4 skinIndex;',
  9949. ' attribute vec4 skinWeight;',
  9950. '#endif',
  9951. '\n'
  9952. ].filter( filterEmptyLine ).join( '\n' );
  9953. prefixFragment = [
  9954. customExtensions,
  9955. 'precision ' + parameters.precision + ' float;',
  9956. 'precision ' + parameters.precision + ' int;',
  9957. '#define SHADER_NAME ' + shader.name,
  9958. customDefines,
  9959. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + ( parameters.alphaTest % 1 ? '' : '.0' ) : '', // add '.0' if integer
  9960. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  9961. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  9962. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  9963. parameters.map ? '#define USE_MAP' : '',
  9964. parameters.envMap ? '#define USE_ENVMAP' : '',
  9965. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  9966. parameters.envMap ? '#define ' + envMapModeDefine : '',
  9967. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  9968. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  9969. parameters.aoMap ? '#define USE_AOMAP' : '',
  9970. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  9971. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  9972. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  9973. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  9974. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  9975. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  9976. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  9977. parameters.vertexColors ? '#define USE_COLOR' : '',
  9978. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  9979. parameters.flatShading ? '#define FLAT_SHADED' : '',
  9980. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  9981. parameters.flipSided ? '#define FLIP_SIDED' : '',
  9982. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  9983. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  9984. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  9985. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  9986. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  9987. parameters.logarithmicDepthBuffer && extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  9988. parameters.envMap && extensions.get( 'EXT_shader_texture_lod' ) ? '#define TEXTURE_LOD_EXT' : '',
  9989. 'uniform mat4 viewMatrix;',
  9990. 'uniform vec3 cameraPosition;',
  9991. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  9992. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  9993. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  9994. parameters.dithering ? '#define DITHERING' : '',
  9995. ( 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
  9996. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  9997. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  9998. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  9999. parameters.outputEncoding ? getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ) : '',
  10000. parameters.depthPacking ? '#define DEPTH_PACKING ' + material.depthPacking : '',
  10001. '\n'
  10002. ].filter( filterEmptyLine ).join( '\n' );
  10003. }
  10004. vertexShader = parseIncludes( vertexShader );
  10005. vertexShader = replaceLightNums( vertexShader, parameters );
  10006. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  10007. fragmentShader = parseIncludes( fragmentShader );
  10008. fragmentShader = replaceLightNums( fragmentShader, parameters );
  10009. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  10010. vertexShader = unrollLoops( vertexShader );
  10011. fragmentShader = unrollLoops( fragmentShader );
  10012. var vertexGlsl = prefixVertex + vertexShader;
  10013. var fragmentGlsl = prefixFragment + fragmentShader;
  10014. // console.log( '*VERTEX*', vertexGlsl );
  10015. // console.log( '*FRAGMENT*', fragmentGlsl );
  10016. var glVertexShader = WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  10017. var glFragmentShader = WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  10018. gl.attachShader( program, glVertexShader );
  10019. gl.attachShader( program, glFragmentShader );
  10020. // Force a particular attribute to index 0.
  10021. if ( material.index0AttributeName !== undefined ) {
  10022. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  10023. } else if ( parameters.morphTargets === true ) {
  10024. // programs with morphTargets displace position out of attribute 0
  10025. gl.bindAttribLocation( program, 0, 'position' );
  10026. }
  10027. gl.linkProgram( program );
  10028. var programLog = gl.getProgramInfoLog( program ).trim();
  10029. var vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  10030. var fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  10031. var runnable = true;
  10032. var haveDiagnostics = true;
  10033. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  10034. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  10035. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  10036. runnable = false;
  10037. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  10038. } else if ( programLog !== '' ) {
  10039. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  10040. } else if ( vertexLog === '' || fragmentLog === '' ) {
  10041. haveDiagnostics = false;
  10042. }
  10043. if ( haveDiagnostics ) {
  10044. this.diagnostics = {
  10045. runnable: runnable,
  10046. material: material,
  10047. programLog: programLog,
  10048. vertexShader: {
  10049. log: vertexLog,
  10050. prefix: prefixVertex
  10051. },
  10052. fragmentShader: {
  10053. log: fragmentLog,
  10054. prefix: prefixFragment
  10055. }
  10056. };
  10057. }
  10058. // clean up
  10059. gl.deleteShader( glVertexShader );
  10060. gl.deleteShader( glFragmentShader );
  10061. // set up caching for uniform locations
  10062. var cachedUniforms;
  10063. this.getUniforms = function () {
  10064. if ( cachedUniforms === undefined ) {
  10065. cachedUniforms = new WebGLUniforms( gl, program, renderer );
  10066. }
  10067. return cachedUniforms;
  10068. };
  10069. // set up caching for attribute locations
  10070. var cachedAttributes;
  10071. this.getAttributes = function () {
  10072. if ( cachedAttributes === undefined ) {
  10073. cachedAttributes = fetchAttributeLocations( gl, program );
  10074. }
  10075. return cachedAttributes;
  10076. };
  10077. // free resource
  10078. this.destroy = function () {
  10079. gl.deleteProgram( program );
  10080. this.program = undefined;
  10081. };
  10082. // DEPRECATED
  10083. Object.defineProperties( this, {
  10084. uniforms: {
  10085. get: function () {
  10086. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  10087. return this.getUniforms();
  10088. }
  10089. },
  10090. attributes: {
  10091. get: function () {
  10092. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  10093. return this.getAttributes();
  10094. }
  10095. }
  10096. } );
  10097. //
  10098. this.name = shader.name;
  10099. this.id = programIdCount ++;
  10100. this.code = code;
  10101. this.usedTimes = 1;
  10102. this.program = program;
  10103. this.vertexShader = glVertexShader;
  10104. this.fragmentShader = glFragmentShader;
  10105. return this;
  10106. }
  10107. /**
  10108. * @author mrdoob / http://mrdoob.com/
  10109. */
  10110. function WebGLPrograms( renderer, extensions, capabilities ) {
  10111. var programs = [];
  10112. var shaderIDs = {
  10113. MeshDepthMaterial: 'depth',
  10114. MeshDistanceMaterial: 'distanceRGBA',
  10115. MeshNormalMaterial: 'normal',
  10116. MeshBasicMaterial: 'basic',
  10117. MeshLambertMaterial: 'lambert',
  10118. MeshPhongMaterial: 'phong',
  10119. MeshToonMaterial: 'phong',
  10120. MeshStandardMaterial: 'physical',
  10121. MeshPhysicalMaterial: 'physical',
  10122. LineBasicMaterial: 'basic',
  10123. LineDashedMaterial: 'dashed',
  10124. PointsMaterial: 'points',
  10125. ShadowMaterial: 'shadow'
  10126. };
  10127. var parameterNames = [
  10128. "precision", "supportsVertexTextures", "map", "mapEncoding", "envMap", "envMapMode", "envMapEncoding",
  10129. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "displacementMap", "specularMap",
  10130. "roughnessMap", "metalnessMap", "gradientMap",
  10131. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  10132. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  10133. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  10134. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  10135. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  10136. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  10137. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering"
  10138. ];
  10139. function allocateBones( object ) {
  10140. var skeleton = object.skeleton;
  10141. var bones = skeleton.bones;
  10142. if ( capabilities.floatVertexTextures ) {
  10143. return 1024;
  10144. } else {
  10145. // default for when object is not specified
  10146. // ( for example when prebuilding shader to be used with multiple objects )
  10147. //
  10148. // - leave some extra space for other uniforms
  10149. // - limit here is ANGLE's 254 max uniform vectors
  10150. // (up to 54 should be safe)
  10151. var nVertexUniforms = capabilities.maxVertexUniforms;
  10152. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  10153. var maxBones = Math.min( nVertexMatrices, bones.length );
  10154. if ( maxBones < bones.length ) {
  10155. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  10156. return 0;
  10157. }
  10158. return maxBones;
  10159. }
  10160. }
  10161. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  10162. var encoding;
  10163. if ( ! map ) {
  10164. encoding = LinearEncoding;
  10165. } else if ( map.isTexture ) {
  10166. encoding = map.encoding;
  10167. } else if ( map.isWebGLRenderTarget ) {
  10168. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  10169. encoding = map.texture.encoding;
  10170. }
  10171. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  10172. if ( encoding === LinearEncoding && gammaOverrideLinear ) {
  10173. encoding = GammaEncoding;
  10174. }
  10175. return encoding;
  10176. }
  10177. this.getParameters = function ( material, lights, shadows, fog, nClipPlanes, nClipIntersection, object ) {
  10178. var shaderID = shaderIDs[ material.type ];
  10179. // heuristics to create shader parameters according to lights in the scene
  10180. // (not to blow over maxLights budget)
  10181. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  10182. var precision = capabilities.precision;
  10183. if ( material.precision !== null ) {
  10184. precision = capabilities.getMaxPrecision( material.precision );
  10185. if ( precision !== material.precision ) {
  10186. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  10187. }
  10188. }
  10189. var currentRenderTarget = renderer.getRenderTarget();
  10190. var parameters = {
  10191. shaderID: shaderID,
  10192. precision: precision,
  10193. supportsVertexTextures: capabilities.vertexTextures,
  10194. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  10195. map: !! material.map,
  10196. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  10197. envMap: !! material.envMap,
  10198. envMapMode: material.envMap && material.envMap.mapping,
  10199. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  10200. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
  10201. lightMap: !! material.lightMap,
  10202. aoMap: !! material.aoMap,
  10203. emissiveMap: !! material.emissiveMap,
  10204. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  10205. bumpMap: !! material.bumpMap,
  10206. normalMap: !! material.normalMap,
  10207. displacementMap: !! material.displacementMap,
  10208. roughnessMap: !! material.roughnessMap,
  10209. metalnessMap: !! material.metalnessMap,
  10210. specularMap: !! material.specularMap,
  10211. alphaMap: !! material.alphaMap,
  10212. gradientMap: !! material.gradientMap,
  10213. combine: material.combine,
  10214. vertexColors: material.vertexColors,
  10215. fog: !! fog,
  10216. useFog: material.fog,
  10217. fogExp: ( fog && fog.isFogExp2 ),
  10218. flatShading: material.flatShading,
  10219. sizeAttenuation: material.sizeAttenuation,
  10220. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  10221. skinning: material.skinning && maxBones > 0,
  10222. maxBones: maxBones,
  10223. useVertexTexture: capabilities.floatVertexTextures,
  10224. morphTargets: material.morphTargets,
  10225. morphNormals: material.morphNormals,
  10226. maxMorphTargets: renderer.maxMorphTargets,
  10227. maxMorphNormals: renderer.maxMorphNormals,
  10228. numDirLights: lights.directional.length,
  10229. numPointLights: lights.point.length,
  10230. numSpotLights: lights.spot.length,
  10231. numRectAreaLights: lights.rectArea.length,
  10232. numHemiLights: lights.hemi.length,
  10233. numClippingPlanes: nClipPlanes,
  10234. numClipIntersection: nClipIntersection,
  10235. dithering: material.dithering,
  10236. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && shadows.length > 0,
  10237. shadowMapType: renderer.shadowMap.type,
  10238. toneMapping: renderer.toneMapping,
  10239. physicallyCorrectLights: renderer.physicallyCorrectLights,
  10240. premultipliedAlpha: material.premultipliedAlpha,
  10241. alphaTest: material.alphaTest,
  10242. doubleSided: material.side === DoubleSide,
  10243. flipSided: material.side === BackSide,
  10244. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  10245. };
  10246. return parameters;
  10247. };
  10248. this.getProgramCode = function ( material, parameters ) {
  10249. var array = [];
  10250. if ( parameters.shaderID ) {
  10251. array.push( parameters.shaderID );
  10252. } else {
  10253. array.push( material.fragmentShader );
  10254. array.push( material.vertexShader );
  10255. }
  10256. if ( material.defines !== undefined ) {
  10257. for ( var name in material.defines ) {
  10258. array.push( name );
  10259. array.push( material.defines[ name ] );
  10260. }
  10261. }
  10262. for ( var i = 0; i < parameterNames.length; i ++ ) {
  10263. array.push( parameters[ parameterNames[ i ] ] );
  10264. }
  10265. array.push( material.onBeforeCompile.toString() );
  10266. array.push( renderer.gammaOutput );
  10267. return array.join();
  10268. };
  10269. this.acquireProgram = function ( material, shader, parameters, code ) {
  10270. var program;
  10271. // Check if code has been already compiled
  10272. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  10273. var programInfo = programs[ p ];
  10274. if ( programInfo.code === code ) {
  10275. program = programInfo;
  10276. ++ program.usedTimes;
  10277. break;
  10278. }
  10279. }
  10280. if ( program === undefined ) {
  10281. program = new WebGLProgram( renderer, extensions, code, material, shader, parameters );
  10282. programs.push( program );
  10283. }
  10284. return program;
  10285. };
  10286. this.releaseProgram = function ( program ) {
  10287. if ( -- program.usedTimes === 0 ) {
  10288. // Remove from unordered set
  10289. var i = programs.indexOf( program );
  10290. programs[ i ] = programs[ programs.length - 1 ];
  10291. programs.pop();
  10292. // Free WebGL resources
  10293. program.destroy();
  10294. }
  10295. };
  10296. // Exposed for resource monitoring & error feedback via renderer.info:
  10297. this.programs = programs;
  10298. }
  10299. /**
  10300. * @author fordacious / fordacious.github.io
  10301. */
  10302. function WebGLProperties() {
  10303. var properties = new WeakMap();
  10304. function get( object ) {
  10305. var map = properties.get( object );
  10306. if ( map === undefined ) {
  10307. map = {};
  10308. properties.set( object, map );
  10309. }
  10310. return map;
  10311. }
  10312. function remove( object ) {
  10313. properties.delete( object );
  10314. }
  10315. function update( object, key, value ) {
  10316. properties.get( object )[ key ] = value;
  10317. }
  10318. function dispose() {
  10319. properties = new WeakMap();
  10320. }
  10321. return {
  10322. get: get,
  10323. remove: remove,
  10324. update: update,
  10325. dispose: dispose
  10326. };
  10327. }
  10328. /**
  10329. * @author mrdoob / http://mrdoob.com/
  10330. */
  10331. function painterSortStable( a, b ) {
  10332. if ( a.renderOrder !== b.renderOrder ) {
  10333. return a.renderOrder - b.renderOrder;
  10334. } else if ( a.program && b.program && a.program !== b.program ) {
  10335. return a.program.id - b.program.id;
  10336. } else if ( a.material.id !== b.material.id ) {
  10337. return a.material.id - b.material.id;
  10338. } else if ( a.z !== b.z ) {
  10339. return a.z - b.z;
  10340. } else {
  10341. return a.id - b.id;
  10342. }
  10343. }
  10344. function reversePainterSortStable( a, b ) {
  10345. if ( a.renderOrder !== b.renderOrder ) {
  10346. return a.renderOrder - b.renderOrder;
  10347. } if ( a.z !== b.z ) {
  10348. return b.z - a.z;
  10349. } else {
  10350. return a.id - b.id;
  10351. }
  10352. }
  10353. function WebGLRenderList() {
  10354. var renderItems = [];
  10355. var renderItemsIndex = 0;
  10356. var opaque = [];
  10357. var transparent = [];
  10358. function init() {
  10359. renderItemsIndex = 0;
  10360. opaque.length = 0;
  10361. transparent.length = 0;
  10362. }
  10363. function push( object, geometry, material, z, group ) {
  10364. var renderItem = renderItems[ renderItemsIndex ];
  10365. if ( renderItem === undefined ) {
  10366. renderItem = {
  10367. id: object.id,
  10368. object: object,
  10369. geometry: geometry,
  10370. material: material,
  10371. program: material.program,
  10372. renderOrder: object.renderOrder,
  10373. z: z,
  10374. group: group
  10375. };
  10376. renderItems[ renderItemsIndex ] = renderItem;
  10377. } else {
  10378. renderItem.id = object.id;
  10379. renderItem.object = object;
  10380. renderItem.geometry = geometry;
  10381. renderItem.material = material;
  10382. renderItem.program = material.program;
  10383. renderItem.renderOrder = object.renderOrder;
  10384. renderItem.z = z;
  10385. renderItem.group = group;
  10386. }
  10387. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  10388. renderItemsIndex ++;
  10389. }
  10390. function sort() {
  10391. if ( opaque.length > 1 ) opaque.sort( painterSortStable );
  10392. if ( transparent.length > 1 ) transparent.sort( reversePainterSortStable );
  10393. }
  10394. return {
  10395. opaque: opaque,
  10396. transparent: transparent,
  10397. init: init,
  10398. push: push,
  10399. sort: sort
  10400. };
  10401. }
  10402. function WebGLRenderLists() {
  10403. var lists = {};
  10404. function get( scene, camera ) {
  10405. var hash = scene.id + ',' + camera.id;
  10406. var list = lists[ hash ];
  10407. if ( list === undefined ) {
  10408. // console.log( 'THREE.WebGLRenderLists:', hash );
  10409. list = new WebGLRenderList();
  10410. lists[ hash ] = list;
  10411. }
  10412. return list;
  10413. }
  10414. function dispose() {
  10415. lists = {};
  10416. }
  10417. return {
  10418. get: get,
  10419. dispose: dispose
  10420. };
  10421. }
  10422. /**
  10423. * @author mrdoob / http://mrdoob.com/
  10424. */
  10425. function UniformsCache() {
  10426. var lights = {};
  10427. return {
  10428. get: function ( light ) {
  10429. if ( lights[ light.id ] !== undefined ) {
  10430. return lights[ light.id ];
  10431. }
  10432. var uniforms;
  10433. switch ( light.type ) {
  10434. case 'DirectionalLight':
  10435. uniforms = {
  10436. direction: new Vector3(),
  10437. color: new Color(),
  10438. shadow: false,
  10439. shadowBias: 0,
  10440. shadowRadius: 1,
  10441. shadowMapSize: new Vector2()
  10442. };
  10443. break;
  10444. case 'SpotLight':
  10445. uniforms = {
  10446. position: new Vector3(),
  10447. direction: new Vector3(),
  10448. color: new Color(),
  10449. distance: 0,
  10450. coneCos: 0,
  10451. penumbraCos: 0,
  10452. decay: 0,
  10453. shadow: false,
  10454. shadowBias: 0,
  10455. shadowRadius: 1,
  10456. shadowMapSize: new Vector2()
  10457. };
  10458. break;
  10459. case 'PointLight':
  10460. uniforms = {
  10461. position: new Vector3(),
  10462. color: new Color(),
  10463. distance: 0,
  10464. decay: 0,
  10465. shadow: false,
  10466. shadowBias: 0,
  10467. shadowRadius: 1,
  10468. shadowMapSize: new Vector2(),
  10469. shadowCameraNear: 1,
  10470. shadowCameraFar: 1000
  10471. };
  10472. break;
  10473. case 'HemisphereLight':
  10474. uniforms = {
  10475. direction: new Vector3(),
  10476. skyColor: new Color(),
  10477. groundColor: new Color()
  10478. };
  10479. break;
  10480. case 'RectAreaLight':
  10481. uniforms = {
  10482. color: new Color(),
  10483. position: new Vector3(),
  10484. halfWidth: new Vector3(),
  10485. halfHeight: new Vector3()
  10486. // TODO (abelnation): set RectAreaLight shadow uniforms
  10487. };
  10488. break;
  10489. }
  10490. lights[ light.id ] = uniforms;
  10491. return uniforms;
  10492. }
  10493. };
  10494. }
  10495. var count = 0;
  10496. function WebGLLights() {
  10497. var cache = new UniformsCache();
  10498. var state = {
  10499. id: count ++,
  10500. hash: '',
  10501. ambient: [ 0, 0, 0 ],
  10502. directional: [],
  10503. directionalShadowMap: [],
  10504. directionalShadowMatrix: [],
  10505. spot: [],
  10506. spotShadowMap: [],
  10507. spotShadowMatrix: [],
  10508. rectArea: [],
  10509. point: [],
  10510. pointShadowMap: [],
  10511. pointShadowMatrix: [],
  10512. hemi: []
  10513. };
  10514. var vector3 = new Vector3();
  10515. var matrix4 = new Matrix4();
  10516. var matrix42 = new Matrix4();
  10517. function setup( lights, shadows, camera ) {
  10518. var r = 0, g = 0, b = 0;
  10519. var directionalLength = 0;
  10520. var pointLength = 0;
  10521. var spotLength = 0;
  10522. var rectAreaLength = 0;
  10523. var hemiLength = 0;
  10524. var viewMatrix = camera.matrixWorldInverse;
  10525. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  10526. var light = lights[ i ];
  10527. var color = light.color;
  10528. var intensity = light.intensity;
  10529. var distance = light.distance;
  10530. var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  10531. if ( light.isAmbientLight ) {
  10532. r += color.r * intensity;
  10533. g += color.g * intensity;
  10534. b += color.b * intensity;
  10535. } else if ( light.isDirectionalLight ) {
  10536. var uniforms = cache.get( light );
  10537. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  10538. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10539. vector3.setFromMatrixPosition( light.target.matrixWorld );
  10540. uniforms.direction.sub( vector3 );
  10541. uniforms.direction.transformDirection( viewMatrix );
  10542. uniforms.shadow = light.castShadow;
  10543. if ( light.castShadow ) {
  10544. var shadow = light.shadow;
  10545. uniforms.shadowBias = shadow.bias;
  10546. uniforms.shadowRadius = shadow.radius;
  10547. uniforms.shadowMapSize = shadow.mapSize;
  10548. }
  10549. state.directionalShadowMap[ directionalLength ] = shadowMap;
  10550. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  10551. state.directional[ directionalLength ] = uniforms;
  10552. directionalLength ++;
  10553. } else if ( light.isSpotLight ) {
  10554. var uniforms = cache.get( light );
  10555. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10556. uniforms.position.applyMatrix4( viewMatrix );
  10557. uniforms.color.copy( color ).multiplyScalar( intensity );
  10558. uniforms.distance = distance;
  10559. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10560. vector3.setFromMatrixPosition( light.target.matrixWorld );
  10561. uniforms.direction.sub( vector3 );
  10562. uniforms.direction.transformDirection( viewMatrix );
  10563. uniforms.coneCos = Math.cos( light.angle );
  10564. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  10565. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  10566. uniforms.shadow = light.castShadow;
  10567. if ( light.castShadow ) {
  10568. var shadow = light.shadow;
  10569. uniforms.shadowBias = shadow.bias;
  10570. uniforms.shadowRadius = shadow.radius;
  10571. uniforms.shadowMapSize = shadow.mapSize;
  10572. }
  10573. state.spotShadowMap[ spotLength ] = shadowMap;
  10574. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  10575. state.spot[ spotLength ] = uniforms;
  10576. spotLength ++;
  10577. } else if ( light.isRectAreaLight ) {
  10578. var uniforms = cache.get( light );
  10579. // (a) intensity is the total visible light emitted
  10580. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  10581. // (b) intensity is the brightness of the light
  10582. uniforms.color.copy( color ).multiplyScalar( intensity );
  10583. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10584. uniforms.position.applyMatrix4( viewMatrix );
  10585. // extract local rotation of light to derive width/height half vectors
  10586. matrix42.identity();
  10587. matrix4.copy( light.matrixWorld );
  10588. matrix4.premultiply( viewMatrix );
  10589. matrix42.extractRotation( matrix4 );
  10590. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  10591. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  10592. uniforms.halfWidth.applyMatrix4( matrix42 );
  10593. uniforms.halfHeight.applyMatrix4( matrix42 );
  10594. // TODO (abelnation): RectAreaLight distance?
  10595. // uniforms.distance = distance;
  10596. state.rectArea[ rectAreaLength ] = uniforms;
  10597. rectAreaLength ++;
  10598. } else if ( light.isPointLight ) {
  10599. var uniforms = cache.get( light );
  10600. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10601. uniforms.position.applyMatrix4( viewMatrix );
  10602. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  10603. uniforms.distance = light.distance;
  10604. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  10605. uniforms.shadow = light.castShadow;
  10606. if ( light.castShadow ) {
  10607. var shadow = light.shadow;
  10608. uniforms.shadowBias = shadow.bias;
  10609. uniforms.shadowRadius = shadow.radius;
  10610. uniforms.shadowMapSize = shadow.mapSize;
  10611. uniforms.shadowCameraNear = shadow.camera.near;
  10612. uniforms.shadowCameraFar = shadow.camera.far;
  10613. }
  10614. state.pointShadowMap[ pointLength ] = shadowMap;
  10615. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  10616. state.point[ pointLength ] = uniforms;
  10617. pointLength ++;
  10618. } else if ( light.isHemisphereLight ) {
  10619. var uniforms = cache.get( light );
  10620. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10621. uniforms.direction.transformDirection( viewMatrix );
  10622. uniforms.direction.normalize();
  10623. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  10624. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  10625. state.hemi[ hemiLength ] = uniforms;
  10626. hemiLength ++;
  10627. }
  10628. }
  10629. state.ambient[ 0 ] = r;
  10630. state.ambient[ 1 ] = g;
  10631. state.ambient[ 2 ] = b;
  10632. state.directional.length = directionalLength;
  10633. state.spot.length = spotLength;
  10634. state.rectArea.length = rectAreaLength;
  10635. state.point.length = pointLength;
  10636. state.hemi.length = hemiLength;
  10637. state.hash = state.id + ',' + directionalLength + ',' + pointLength + ',' + spotLength + ',' + rectAreaLength + ',' + hemiLength + ',' + shadows.length;
  10638. }
  10639. return {
  10640. setup: setup,
  10641. state: state
  10642. };
  10643. }
  10644. /**
  10645. * @author Mugen87 / https://github.com/Mugen87
  10646. */
  10647. function WebGLRenderState() {
  10648. var lights = new WebGLLights();
  10649. var lightsArray = [];
  10650. var shadowsArray = [];
  10651. var spritesArray = [];
  10652. function init() {
  10653. lightsArray.length = 0;
  10654. shadowsArray.length = 0;
  10655. spritesArray.length = 0;
  10656. }
  10657. function pushLight( light ) {
  10658. lightsArray.push( light );
  10659. }
  10660. function pushShadow( shadowLight ) {
  10661. shadowsArray.push( shadowLight );
  10662. }
  10663. function pushSprite( shadowLight ) {
  10664. spritesArray.push( shadowLight );
  10665. }
  10666. function setupLights( camera ) {
  10667. lights.setup( lightsArray, shadowsArray, camera );
  10668. }
  10669. var state = {
  10670. lightsArray: lightsArray,
  10671. shadowsArray: shadowsArray,
  10672. spritesArray: spritesArray,
  10673. lights: lights
  10674. };
  10675. return {
  10676. init: init,
  10677. state: state,
  10678. setupLights: setupLights,
  10679. pushLight: pushLight,
  10680. pushShadow: pushShadow,
  10681. pushSprite: pushSprite
  10682. };
  10683. }
  10684. function WebGLRenderStates() {
  10685. var renderStates = {};
  10686. function get( scene, camera ) {
  10687. var hash = scene.id + ',' + camera.id;
  10688. var renderState = renderStates[ hash ];
  10689. if ( renderState === undefined ) {
  10690. renderState = new WebGLRenderState();
  10691. renderStates[ hash ] = renderState;
  10692. }
  10693. return renderState;
  10694. }
  10695. function dispose() {
  10696. renderStates = {};
  10697. }
  10698. return {
  10699. get: get,
  10700. dispose: dispose
  10701. };
  10702. }
  10703. /**
  10704. * @author mrdoob / http://mrdoob.com/
  10705. * @author alteredq / http://alteredqualia.com/
  10706. * @author bhouston / https://clara.io
  10707. * @author WestLangley / http://github.com/WestLangley
  10708. *
  10709. * parameters = {
  10710. *
  10711. * opacity: <float>,
  10712. *
  10713. * map: new THREE.Texture( <Image> ),
  10714. *
  10715. * alphaMap: new THREE.Texture( <Image> ),
  10716. *
  10717. * displacementMap: new THREE.Texture( <Image> ),
  10718. * displacementScale: <float>,
  10719. * displacementBias: <float>,
  10720. *
  10721. * wireframe: <boolean>,
  10722. * wireframeLinewidth: <float>
  10723. * }
  10724. */
  10725. function MeshDepthMaterial( parameters ) {
  10726. Material.call( this );
  10727. this.type = 'MeshDepthMaterial';
  10728. this.depthPacking = BasicDepthPacking;
  10729. this.skinning = false;
  10730. this.morphTargets = false;
  10731. this.map = null;
  10732. this.alphaMap = null;
  10733. this.displacementMap = null;
  10734. this.displacementScale = 1;
  10735. this.displacementBias = 0;
  10736. this.wireframe = false;
  10737. this.wireframeLinewidth = 1;
  10738. this.fog = false;
  10739. this.lights = false;
  10740. this.setValues( parameters );
  10741. }
  10742. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  10743. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  10744. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  10745. MeshDepthMaterial.prototype.copy = function ( source ) {
  10746. Material.prototype.copy.call( this, source );
  10747. this.depthPacking = source.depthPacking;
  10748. this.skinning = source.skinning;
  10749. this.morphTargets = source.morphTargets;
  10750. this.map = source.map;
  10751. this.alphaMap = source.alphaMap;
  10752. this.displacementMap = source.displacementMap;
  10753. this.displacementScale = source.displacementScale;
  10754. this.displacementBias = source.displacementBias;
  10755. this.wireframe = source.wireframe;
  10756. this.wireframeLinewidth = source.wireframeLinewidth;
  10757. return this;
  10758. };
  10759. /**
  10760. * @author WestLangley / http://github.com/WestLangley
  10761. *
  10762. * parameters = {
  10763. *
  10764. * referencePosition: <float>,
  10765. * nearDistance: <float>,
  10766. * farDistance: <float>,
  10767. *
  10768. * skinning: <bool>,
  10769. * morphTargets: <bool>,
  10770. *
  10771. * map: new THREE.Texture( <Image> ),
  10772. *
  10773. * alphaMap: new THREE.Texture( <Image> ),
  10774. *
  10775. * displacementMap: new THREE.Texture( <Image> ),
  10776. * displacementScale: <float>,
  10777. * displacementBias: <float>
  10778. *
  10779. * }
  10780. */
  10781. function MeshDistanceMaterial( parameters ) {
  10782. Material.call( this );
  10783. this.type = 'MeshDistanceMaterial';
  10784. this.referencePosition = new Vector3();
  10785. this.nearDistance = 1;
  10786. this.farDistance = 1000;
  10787. this.skinning = false;
  10788. this.morphTargets = false;
  10789. this.map = null;
  10790. this.alphaMap = null;
  10791. this.displacementMap = null;
  10792. this.displacementScale = 1;
  10793. this.displacementBias = 0;
  10794. this.fog = false;
  10795. this.lights = false;
  10796. this.setValues( parameters );
  10797. }
  10798. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  10799. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  10800. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  10801. MeshDistanceMaterial.prototype.copy = function ( source ) {
  10802. Material.prototype.copy.call( this, source );
  10803. this.referencePosition.copy( source.referencePosition );
  10804. this.nearDistance = source.nearDistance;
  10805. this.farDistance = source.farDistance;
  10806. this.skinning = source.skinning;
  10807. this.morphTargets = source.morphTargets;
  10808. this.map = source.map;
  10809. this.alphaMap = source.alphaMap;
  10810. this.displacementMap = source.displacementMap;
  10811. this.displacementScale = source.displacementScale;
  10812. this.displacementBias = source.displacementBias;
  10813. return this;
  10814. };
  10815. /**
  10816. * @author alteredq / http://alteredqualia.com/
  10817. * @author mrdoob / http://mrdoob.com/
  10818. */
  10819. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  10820. var _frustum = new Frustum(),
  10821. _projScreenMatrix = new Matrix4(),
  10822. _shadowMapSize = new Vector2(),
  10823. _maxShadowMapSize = new Vector2( maxTextureSize, maxTextureSize ),
  10824. _lookTarget = new Vector3(),
  10825. _lightPositionWorld = new Vector3(),
  10826. _MorphingFlag = 1,
  10827. _SkinningFlag = 2,
  10828. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  10829. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  10830. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  10831. _materialCache = {};
  10832. var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  10833. var cubeDirections = [
  10834. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  10835. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  10836. ];
  10837. var cubeUps = [
  10838. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  10839. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  10840. ];
  10841. var cube2DViewPorts = [
  10842. new Vector4(), new Vector4(), new Vector4(),
  10843. new Vector4(), new Vector4(), new Vector4()
  10844. ];
  10845. // init
  10846. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  10847. var useMorphing = ( i & _MorphingFlag ) !== 0;
  10848. var useSkinning = ( i & _SkinningFlag ) !== 0;
  10849. var depthMaterial = new MeshDepthMaterial( {
  10850. depthPacking: RGBADepthPacking,
  10851. morphTargets: useMorphing,
  10852. skinning: useSkinning
  10853. } );
  10854. _depthMaterials[ i ] = depthMaterial;
  10855. //
  10856. var distanceMaterial = new MeshDistanceMaterial( {
  10857. morphTargets: useMorphing,
  10858. skinning: useSkinning
  10859. } );
  10860. _distanceMaterials[ i ] = distanceMaterial;
  10861. }
  10862. //
  10863. var scope = this;
  10864. this.enabled = false;
  10865. this.autoUpdate = true;
  10866. this.needsUpdate = false;
  10867. this.type = PCFShadowMap;
  10868. this.render = function ( lights, scene, camera ) {
  10869. if ( scope.enabled === false ) return;
  10870. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  10871. if ( lights.length === 0 ) return;
  10872. // TODO Clean up (needed in case of contextlost)
  10873. var _gl = _renderer.context;
  10874. var _state = _renderer.state;
  10875. // Set GL state for depth map.
  10876. _state.disable( _gl.BLEND );
  10877. _state.buffers.color.setClear( 1, 1, 1, 1 );
  10878. _state.buffers.depth.setTest( true );
  10879. _state.setScissorTest( false );
  10880. // render depth map
  10881. var faceCount;
  10882. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  10883. var light = lights[ i ];
  10884. var shadow = light.shadow;
  10885. var isPointLight = light && light.isPointLight;
  10886. if ( shadow === undefined ) {
  10887. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  10888. continue;
  10889. }
  10890. var shadowCamera = shadow.camera;
  10891. _shadowMapSize.copy( shadow.mapSize );
  10892. _shadowMapSize.min( _maxShadowMapSize );
  10893. if ( isPointLight ) {
  10894. var vpWidth = _shadowMapSize.x;
  10895. var vpHeight = _shadowMapSize.y;
  10896. // These viewports map a cube-map onto a 2D texture with the
  10897. // following orientation:
  10898. //
  10899. // xzXZ
  10900. // y Y
  10901. //
  10902. // X - Positive x direction
  10903. // x - Negative x direction
  10904. // Y - Positive y direction
  10905. // y - Negative y direction
  10906. // Z - Positive z direction
  10907. // z - Negative z direction
  10908. // positive X
  10909. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  10910. // negative X
  10911. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  10912. // positive Z
  10913. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  10914. // negative Z
  10915. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  10916. // positive Y
  10917. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  10918. // negative Y
  10919. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  10920. _shadowMapSize.x *= 4.0;
  10921. _shadowMapSize.y *= 2.0;
  10922. }
  10923. if ( shadow.map === null ) {
  10924. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  10925. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  10926. shadow.map.texture.name = light.name + ".shadowMap";
  10927. shadowCamera.updateProjectionMatrix();
  10928. }
  10929. if ( shadow.isSpotLightShadow ) {
  10930. shadow.update( light );
  10931. }
  10932. var shadowMap = shadow.map;
  10933. var shadowMatrix = shadow.matrix;
  10934. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  10935. shadowCamera.position.copy( _lightPositionWorld );
  10936. if ( isPointLight ) {
  10937. faceCount = 6;
  10938. // for point lights we set the shadow matrix to be a translation-only matrix
  10939. // equal to inverse of the light's position
  10940. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  10941. } else {
  10942. faceCount = 1;
  10943. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  10944. shadowCamera.lookAt( _lookTarget );
  10945. shadowCamera.updateMatrixWorld();
  10946. // compute shadow matrix
  10947. shadowMatrix.set(
  10948. 0.5, 0.0, 0.0, 0.5,
  10949. 0.0, 0.5, 0.0, 0.5,
  10950. 0.0, 0.0, 0.5, 0.5,
  10951. 0.0, 0.0, 0.0, 1.0
  10952. );
  10953. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  10954. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  10955. }
  10956. _renderer.setRenderTarget( shadowMap );
  10957. _renderer.clear();
  10958. // render shadow map for each cube face (if omni-directional) or
  10959. // run a single pass if not
  10960. for ( var face = 0; face < faceCount; face ++ ) {
  10961. if ( isPointLight ) {
  10962. _lookTarget.copy( shadowCamera.position );
  10963. _lookTarget.add( cubeDirections[ face ] );
  10964. shadowCamera.up.copy( cubeUps[ face ] );
  10965. shadowCamera.lookAt( _lookTarget );
  10966. shadowCamera.updateMatrixWorld();
  10967. var vpDimensions = cube2DViewPorts[ face ];
  10968. _state.viewport( vpDimensions );
  10969. }
  10970. // update camera matrices and frustum
  10971. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  10972. _frustum.setFromMatrix( _projScreenMatrix );
  10973. // set object matrices & frustum culling
  10974. renderObject( scene, camera, shadowCamera, isPointLight );
  10975. }
  10976. }
  10977. scope.needsUpdate = false;
  10978. };
  10979. function getDepthMaterial( object, material, isPointLight, lightPositionWorld, shadowCameraNear, shadowCameraFar ) {
  10980. var geometry = object.geometry;
  10981. var result = null;
  10982. var materialVariants = _depthMaterials;
  10983. var customMaterial = object.customDepthMaterial;
  10984. if ( isPointLight ) {
  10985. materialVariants = _distanceMaterials;
  10986. customMaterial = object.customDistanceMaterial;
  10987. }
  10988. if ( ! customMaterial ) {
  10989. var useMorphing = false;
  10990. if ( material.morphTargets ) {
  10991. if ( geometry && geometry.isBufferGeometry ) {
  10992. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  10993. } else if ( geometry && geometry.isGeometry ) {
  10994. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  10995. }
  10996. }
  10997. if ( object.isSkinnedMesh && material.skinning === false ) {
  10998. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  10999. }
  11000. var useSkinning = object.isSkinnedMesh && material.skinning;
  11001. var variantIndex = 0;
  11002. if ( useMorphing ) variantIndex |= _MorphingFlag;
  11003. if ( useSkinning ) variantIndex |= _SkinningFlag;
  11004. result = materialVariants[ variantIndex ];
  11005. } else {
  11006. result = customMaterial;
  11007. }
  11008. if ( _renderer.localClippingEnabled &&
  11009. material.clipShadows === true &&
  11010. material.clippingPlanes.length !== 0 ) {
  11011. // in this case we need a unique material instance reflecting the
  11012. // appropriate state
  11013. var keyA = result.uuid, keyB = material.uuid;
  11014. var materialsForVariant = _materialCache[ keyA ];
  11015. if ( materialsForVariant === undefined ) {
  11016. materialsForVariant = {};
  11017. _materialCache[ keyA ] = materialsForVariant;
  11018. }
  11019. var cachedMaterial = materialsForVariant[ keyB ];
  11020. if ( cachedMaterial === undefined ) {
  11021. cachedMaterial = result.clone();
  11022. materialsForVariant[ keyB ] = cachedMaterial;
  11023. }
  11024. result = cachedMaterial;
  11025. }
  11026. result.visible = material.visible;
  11027. result.wireframe = material.wireframe;
  11028. result.side = ( material.shadowSide != null ) ? material.shadowSide : shadowSide[ material.side ];
  11029. result.clipShadows = material.clipShadows;
  11030. result.clippingPlanes = material.clippingPlanes;
  11031. result.clipIntersection = material.clipIntersection;
  11032. result.wireframeLinewidth = material.wireframeLinewidth;
  11033. result.linewidth = material.linewidth;
  11034. if ( isPointLight && result.isMeshDistanceMaterial ) {
  11035. result.referencePosition.copy( lightPositionWorld );
  11036. result.nearDistance = shadowCameraNear;
  11037. result.farDistance = shadowCameraFar;
  11038. }
  11039. return result;
  11040. }
  11041. function renderObject( object, camera, shadowCamera, isPointLight ) {
  11042. if ( object.visible === false ) return;
  11043. var visible = object.layers.test( camera.layers );
  11044. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  11045. if ( object.castShadow && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  11046. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  11047. var geometry = _objects.update( object );
  11048. var material = object.material;
  11049. if ( Array.isArray( material ) ) {
  11050. var groups = geometry.groups;
  11051. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  11052. var group = groups[ k ];
  11053. var groupMaterial = material[ group.materialIndex ];
  11054. if ( groupMaterial && groupMaterial.visible ) {
  11055. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11056. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  11057. }
  11058. }
  11059. } else if ( material.visible ) {
  11060. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11061. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  11062. }
  11063. }
  11064. }
  11065. var children = object.children;
  11066. for ( var i = 0, l = children.length; i < l; i ++ ) {
  11067. renderObject( children[ i ], camera, shadowCamera, isPointLight );
  11068. }
  11069. }
  11070. }
  11071. /**
  11072. * @author mrdoob / http://mrdoob.com/
  11073. */
  11074. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  11075. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  11076. this.needsUpdate = true;
  11077. }
  11078. CanvasTexture.prototype = Object.create( Texture.prototype );
  11079. CanvasTexture.prototype.constructor = CanvasTexture;
  11080. CanvasTexture.prototype.isCanvasTexture = true;
  11081. /**
  11082. * @author mikael emtinger / http://gomo.se/
  11083. * @author alteredq / http://alteredqualia.com/
  11084. */
  11085. function WebGLSpriteRenderer( renderer, gl, state, textures, capabilities ) {
  11086. var vertexBuffer, elementBuffer;
  11087. var program, attributes, uniforms;
  11088. var texture;
  11089. // decompose matrixWorld
  11090. var spritePosition = new Vector3();
  11091. var spriteRotation = new Quaternion();
  11092. var spriteScale = new Vector3();
  11093. function init() {
  11094. var vertices = new Float32Array( [
  11095. - 0.5, - 0.5, 0, 0,
  11096. 0.5, - 0.5, 1, 0,
  11097. 0.5, 0.5, 1, 1,
  11098. - 0.5, 0.5, 0, 1
  11099. ] );
  11100. var faces = new Uint16Array( [
  11101. 0, 1, 2,
  11102. 0, 2, 3
  11103. ] );
  11104. vertexBuffer = gl.createBuffer();
  11105. elementBuffer = gl.createBuffer();
  11106. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  11107. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  11108. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  11109. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  11110. program = createProgram();
  11111. attributes = {
  11112. position: gl.getAttribLocation( program, 'position' ),
  11113. uv: gl.getAttribLocation( program, 'uv' )
  11114. };
  11115. uniforms = {
  11116. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  11117. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  11118. rotation: gl.getUniformLocation( program, 'rotation' ),
  11119. center: gl.getUniformLocation( program, 'center' ),
  11120. scale: gl.getUniformLocation( program, 'scale' ),
  11121. color: gl.getUniformLocation( program, 'color' ),
  11122. map: gl.getUniformLocation( program, 'map' ),
  11123. opacity: gl.getUniformLocation( program, 'opacity' ),
  11124. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  11125. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  11126. fogType: gl.getUniformLocation( program, 'fogType' ),
  11127. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  11128. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  11129. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  11130. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  11131. fogDepth: gl.getUniformLocation( program, 'fogDepth' ),
  11132. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  11133. };
  11134. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  11135. canvas.width = 8;
  11136. canvas.height = 8;
  11137. var context = canvas.getContext( '2d' );
  11138. context.fillStyle = 'white';
  11139. context.fillRect( 0, 0, 8, 8 );
  11140. texture = new CanvasTexture( canvas );
  11141. }
  11142. this.render = function ( sprites, scene, camera ) {
  11143. if ( sprites.length === 0 ) return;
  11144. // setup gl
  11145. if ( program === undefined ) {
  11146. init();
  11147. }
  11148. state.useProgram( program );
  11149. state.initAttributes();
  11150. state.enableAttribute( attributes.position );
  11151. state.enableAttribute( attributes.uv );
  11152. state.disableUnusedAttributes();
  11153. state.disable( gl.CULL_FACE );
  11154. state.enable( gl.BLEND );
  11155. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  11156. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  11157. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  11158. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  11159. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  11160. state.activeTexture( gl.TEXTURE0 );
  11161. gl.uniform1i( uniforms.map, 0 );
  11162. var oldFogType = 0;
  11163. var sceneFogType = 0;
  11164. var fog = scene.fog;
  11165. if ( fog ) {
  11166. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  11167. if ( fog.isFog ) {
  11168. gl.uniform1f( uniforms.fogNear, fog.near );
  11169. gl.uniform1f( uniforms.fogFar, fog.far );
  11170. gl.uniform1i( uniforms.fogType, 1 );
  11171. oldFogType = 1;
  11172. sceneFogType = 1;
  11173. } else if ( fog.isFogExp2 ) {
  11174. gl.uniform1f( uniforms.fogDensity, fog.density );
  11175. gl.uniform1i( uniforms.fogType, 2 );
  11176. oldFogType = 2;
  11177. sceneFogType = 2;
  11178. }
  11179. } else {
  11180. gl.uniform1i( uniforms.fogType, 0 );
  11181. oldFogType = 0;
  11182. sceneFogType = 0;
  11183. }
  11184. // update positions and sort
  11185. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  11186. var sprite = sprites[ i ];
  11187. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  11188. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  11189. }
  11190. sprites.sort( painterSortStable );
  11191. // render all sprites
  11192. var scale = [];
  11193. var center = [];
  11194. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  11195. var sprite = sprites[ i ];
  11196. var material = sprite.material;
  11197. if ( material.visible === false ) continue;
  11198. sprite.onBeforeRender( renderer, scene, camera, undefined, material, undefined );
  11199. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  11200. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  11201. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  11202. scale[ 0 ] = spriteScale.x;
  11203. scale[ 1 ] = spriteScale.y;
  11204. center[ 0 ] = sprite.center.x - 0.5;
  11205. center[ 1 ] = sprite.center.y - 0.5;
  11206. var fogType = 0;
  11207. if ( scene.fog && material.fog ) {
  11208. fogType = sceneFogType;
  11209. }
  11210. if ( oldFogType !== fogType ) {
  11211. gl.uniform1i( uniforms.fogType, fogType );
  11212. oldFogType = fogType;
  11213. }
  11214. if ( material.map !== null ) {
  11215. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  11216. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  11217. } else {
  11218. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  11219. gl.uniform2f( uniforms.uvScale, 1, 1 );
  11220. }
  11221. gl.uniform1f( uniforms.opacity, material.opacity );
  11222. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  11223. gl.uniform1f( uniforms.rotation, material.rotation );
  11224. gl.uniform2fv( uniforms.center, center );
  11225. gl.uniform2fv( uniforms.scale, scale );
  11226. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  11227. state.buffers.depth.setTest( material.depthTest );
  11228. state.buffers.depth.setMask( material.depthWrite );
  11229. state.buffers.color.setMask( material.colorWrite );
  11230. textures.setTexture2D( material.map || texture, 0 );
  11231. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  11232. sprite.onAfterRender( renderer, scene, camera, undefined, material, undefined );
  11233. }
  11234. // restore gl
  11235. state.enable( gl.CULL_FACE );
  11236. state.reset();
  11237. };
  11238. function createProgram() {
  11239. var program = gl.createProgram();
  11240. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  11241. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  11242. gl.shaderSource( vertexShader, [
  11243. 'precision ' + capabilities.precision + ' float;',
  11244. '#define SHADER_NAME ' + 'SpriteMaterial',
  11245. 'uniform mat4 modelViewMatrix;',
  11246. 'uniform mat4 projectionMatrix;',
  11247. 'uniform float rotation;',
  11248. 'uniform vec2 center;',
  11249. 'uniform vec2 scale;',
  11250. 'uniform vec2 uvOffset;',
  11251. 'uniform vec2 uvScale;',
  11252. 'attribute vec2 position;',
  11253. 'attribute vec2 uv;',
  11254. 'varying vec2 vUV;',
  11255. 'varying float fogDepth;',
  11256. 'void main() {',
  11257. ' vUV = uvOffset + uv * uvScale;',
  11258. ' vec2 alignedPosition = ( position - center ) * scale;',
  11259. ' vec2 rotatedPosition;',
  11260. ' rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  11261. ' rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  11262. ' vec4 mvPosition;',
  11263. ' mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  11264. ' mvPosition.xy += rotatedPosition;',
  11265. ' gl_Position = projectionMatrix * mvPosition;',
  11266. ' fogDepth = - mvPosition.z;',
  11267. '}'
  11268. ].join( '\n' ) );
  11269. gl.shaderSource( fragmentShader, [
  11270. 'precision ' + capabilities.precision + ' float;',
  11271. '#define SHADER_NAME ' + 'SpriteMaterial',
  11272. 'uniform vec3 color;',
  11273. 'uniform sampler2D map;',
  11274. 'uniform float opacity;',
  11275. 'uniform int fogType;',
  11276. 'uniform vec3 fogColor;',
  11277. 'uniform float fogDensity;',
  11278. 'uniform float fogNear;',
  11279. 'uniform float fogFar;',
  11280. 'uniform float alphaTest;',
  11281. 'varying vec2 vUV;',
  11282. 'varying float fogDepth;',
  11283. 'void main() {',
  11284. ' vec4 texture = texture2D( map, vUV );',
  11285. ' gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  11286. ' if ( gl_FragColor.a < alphaTest ) discard;',
  11287. ' if ( fogType > 0 ) {',
  11288. ' float fogFactor = 0.0;',
  11289. ' if ( fogType == 1 ) {',
  11290. ' fogFactor = smoothstep( fogNear, fogFar, fogDepth );',
  11291. ' } else {',
  11292. ' const float LOG2 = 1.442695;',
  11293. ' fogFactor = exp2( - fogDensity * fogDensity * fogDepth * fogDepth * LOG2 );',
  11294. ' fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  11295. ' }',
  11296. ' gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );',
  11297. ' }',
  11298. '}'
  11299. ].join( '\n' ) );
  11300. gl.compileShader( vertexShader );
  11301. gl.compileShader( fragmentShader );
  11302. gl.attachShader( program, vertexShader );
  11303. gl.attachShader( program, fragmentShader );
  11304. gl.linkProgram( program );
  11305. return program;
  11306. }
  11307. function painterSortStable( a, b ) {
  11308. if ( a.renderOrder !== b.renderOrder ) {
  11309. return a.renderOrder - b.renderOrder;
  11310. } else if ( a.z !== b.z ) {
  11311. return b.z - a.z;
  11312. } else {
  11313. return b.id - a.id;
  11314. }
  11315. }
  11316. }
  11317. /**
  11318. * @author mrdoob / http://mrdoob.com/
  11319. */
  11320. function WebGLState( gl, extensions, utils ) {
  11321. function ColorBuffer() {
  11322. var locked = false;
  11323. var color = new Vector4();
  11324. var currentColorMask = null;
  11325. var currentColorClear = new Vector4( 0, 0, 0, 0 );
  11326. return {
  11327. setMask: function ( colorMask ) {
  11328. if ( currentColorMask !== colorMask && ! locked ) {
  11329. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  11330. currentColorMask = colorMask;
  11331. }
  11332. },
  11333. setLocked: function ( lock ) {
  11334. locked = lock;
  11335. },
  11336. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  11337. if ( premultipliedAlpha === true ) {
  11338. r *= a; g *= a; b *= a;
  11339. }
  11340. color.set( r, g, b, a );
  11341. if ( currentColorClear.equals( color ) === false ) {
  11342. gl.clearColor( r, g, b, a );
  11343. currentColorClear.copy( color );
  11344. }
  11345. },
  11346. reset: function () {
  11347. locked = false;
  11348. currentColorMask = null;
  11349. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  11350. }
  11351. };
  11352. }
  11353. function DepthBuffer() {
  11354. var locked = false;
  11355. var currentDepthMask = null;
  11356. var currentDepthFunc = null;
  11357. var currentDepthClear = null;
  11358. return {
  11359. setTest: function ( depthTest ) {
  11360. if ( depthTest ) {
  11361. enable( gl.DEPTH_TEST );
  11362. } else {
  11363. disable( gl.DEPTH_TEST );
  11364. }
  11365. },
  11366. setMask: function ( depthMask ) {
  11367. if ( currentDepthMask !== depthMask && ! locked ) {
  11368. gl.depthMask( depthMask );
  11369. currentDepthMask = depthMask;
  11370. }
  11371. },
  11372. setFunc: function ( depthFunc ) {
  11373. if ( currentDepthFunc !== depthFunc ) {
  11374. if ( depthFunc ) {
  11375. switch ( depthFunc ) {
  11376. case NeverDepth:
  11377. gl.depthFunc( gl.NEVER );
  11378. break;
  11379. case AlwaysDepth:
  11380. gl.depthFunc( gl.ALWAYS );
  11381. break;
  11382. case LessDepth:
  11383. gl.depthFunc( gl.LESS );
  11384. break;
  11385. case LessEqualDepth:
  11386. gl.depthFunc( gl.LEQUAL );
  11387. break;
  11388. case EqualDepth:
  11389. gl.depthFunc( gl.EQUAL );
  11390. break;
  11391. case GreaterEqualDepth:
  11392. gl.depthFunc( gl.GEQUAL );
  11393. break;
  11394. case GreaterDepth:
  11395. gl.depthFunc( gl.GREATER );
  11396. break;
  11397. case NotEqualDepth:
  11398. gl.depthFunc( gl.NOTEQUAL );
  11399. break;
  11400. default:
  11401. gl.depthFunc( gl.LEQUAL );
  11402. }
  11403. } else {
  11404. gl.depthFunc( gl.LEQUAL );
  11405. }
  11406. currentDepthFunc = depthFunc;
  11407. }
  11408. },
  11409. setLocked: function ( lock ) {
  11410. locked = lock;
  11411. },
  11412. setClear: function ( depth ) {
  11413. if ( currentDepthClear !== depth ) {
  11414. gl.clearDepth( depth );
  11415. currentDepthClear = depth;
  11416. }
  11417. },
  11418. reset: function () {
  11419. locked = false;
  11420. currentDepthMask = null;
  11421. currentDepthFunc = null;
  11422. currentDepthClear = null;
  11423. }
  11424. };
  11425. }
  11426. function StencilBuffer() {
  11427. var locked = false;
  11428. var currentStencilMask = null;
  11429. var currentStencilFunc = null;
  11430. var currentStencilRef = null;
  11431. var currentStencilFuncMask = null;
  11432. var currentStencilFail = null;
  11433. var currentStencilZFail = null;
  11434. var currentStencilZPass = null;
  11435. var currentStencilClear = null;
  11436. return {
  11437. setTest: function ( stencilTest ) {
  11438. if ( stencilTest ) {
  11439. enable( gl.STENCIL_TEST );
  11440. } else {
  11441. disable( gl.STENCIL_TEST );
  11442. }
  11443. },
  11444. setMask: function ( stencilMask ) {
  11445. if ( currentStencilMask !== stencilMask && ! locked ) {
  11446. gl.stencilMask( stencilMask );
  11447. currentStencilMask = stencilMask;
  11448. }
  11449. },
  11450. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  11451. if ( currentStencilFunc !== stencilFunc ||
  11452. currentStencilRef !== stencilRef ||
  11453. currentStencilFuncMask !== stencilMask ) {
  11454. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  11455. currentStencilFunc = stencilFunc;
  11456. currentStencilRef = stencilRef;
  11457. currentStencilFuncMask = stencilMask;
  11458. }
  11459. },
  11460. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  11461. if ( currentStencilFail !== stencilFail ||
  11462. currentStencilZFail !== stencilZFail ||
  11463. currentStencilZPass !== stencilZPass ) {
  11464. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  11465. currentStencilFail = stencilFail;
  11466. currentStencilZFail = stencilZFail;
  11467. currentStencilZPass = stencilZPass;
  11468. }
  11469. },
  11470. setLocked: function ( lock ) {
  11471. locked = lock;
  11472. },
  11473. setClear: function ( stencil ) {
  11474. if ( currentStencilClear !== stencil ) {
  11475. gl.clearStencil( stencil );
  11476. currentStencilClear = stencil;
  11477. }
  11478. },
  11479. reset: function () {
  11480. locked = false;
  11481. currentStencilMask = null;
  11482. currentStencilFunc = null;
  11483. currentStencilRef = null;
  11484. currentStencilFuncMask = null;
  11485. currentStencilFail = null;
  11486. currentStencilZFail = null;
  11487. currentStencilZPass = null;
  11488. currentStencilClear = null;
  11489. }
  11490. };
  11491. }
  11492. //
  11493. var colorBuffer = new ColorBuffer();
  11494. var depthBuffer = new DepthBuffer();
  11495. var stencilBuffer = new StencilBuffer();
  11496. var maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  11497. var newAttributes = new Uint8Array( maxVertexAttributes );
  11498. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  11499. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  11500. var capabilities = {};
  11501. var compressedTextureFormats = null;
  11502. var currentProgram = null;
  11503. var currentBlending = null;
  11504. var currentBlendEquation = null;
  11505. var currentBlendSrc = null;
  11506. var currentBlendDst = null;
  11507. var currentBlendEquationAlpha = null;
  11508. var currentBlendSrcAlpha = null;
  11509. var currentBlendDstAlpha = null;
  11510. var currentPremultipledAlpha = false;
  11511. var currentFlipSided = null;
  11512. var currentCullFace = null;
  11513. var currentLineWidth = null;
  11514. var currentPolygonOffsetFactor = null;
  11515. var currentPolygonOffsetUnits = null;
  11516. var maxTextures = gl.getParameter( gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS );
  11517. var lineWidthAvailable = false;
  11518. var version = 0;
  11519. var glVersion = gl.getParameter( gl.VERSION );
  11520. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  11521. version = parseFloat( /^WebGL\ ([0-9])/.exec( glVersion )[ 1 ] );
  11522. lineWidthAvailable = ( version >= 1.0 );
  11523. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  11524. version = parseFloat( /^OpenGL\ ES\ ([0-9])/.exec( glVersion )[ 1 ] );
  11525. lineWidthAvailable = ( version >= 2.0 );
  11526. }
  11527. var currentTextureSlot = null;
  11528. var currentBoundTextures = {};
  11529. var currentScissor = new Vector4();
  11530. var currentViewport = new Vector4();
  11531. function createTexture( type, target, count ) {
  11532. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  11533. var texture = gl.createTexture();
  11534. gl.bindTexture( type, texture );
  11535. gl.texParameteri( type, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  11536. gl.texParameteri( type, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  11537. for ( var i = 0; i < count; i ++ ) {
  11538. gl.texImage2D( target + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data );
  11539. }
  11540. return texture;
  11541. }
  11542. var emptyTextures = {};
  11543. emptyTextures[ gl.TEXTURE_2D ] = createTexture( gl.TEXTURE_2D, gl.TEXTURE_2D, 1 );
  11544. emptyTextures[ gl.TEXTURE_CUBE_MAP ] = createTexture( gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6 );
  11545. // init
  11546. colorBuffer.setClear( 0, 0, 0, 1 );
  11547. depthBuffer.setClear( 1 );
  11548. stencilBuffer.setClear( 0 );
  11549. enable( gl.DEPTH_TEST );
  11550. depthBuffer.setFunc( LessEqualDepth );
  11551. setFlipSided( false );
  11552. setCullFace( CullFaceBack );
  11553. enable( gl.CULL_FACE );
  11554. enable( gl.BLEND );
  11555. setBlending( NormalBlending );
  11556. //
  11557. function initAttributes() {
  11558. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  11559. newAttributes[ i ] = 0;
  11560. }
  11561. }
  11562. function enableAttribute( attribute ) {
  11563. enableAttributeAndDivisor( attribute, 0 );
  11564. }
  11565. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  11566. newAttributes[ attribute ] = 1;
  11567. if ( enabledAttributes[ attribute ] === 0 ) {
  11568. gl.enableVertexAttribArray( attribute );
  11569. enabledAttributes[ attribute ] = 1;
  11570. }
  11571. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  11572. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  11573. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  11574. attributeDivisors[ attribute ] = meshPerAttribute;
  11575. }
  11576. }
  11577. function disableUnusedAttributes() {
  11578. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  11579. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  11580. gl.disableVertexAttribArray( i );
  11581. enabledAttributes[ i ] = 0;
  11582. }
  11583. }
  11584. }
  11585. function enable( id ) {
  11586. if ( capabilities[ id ] !== true ) {
  11587. gl.enable( id );
  11588. capabilities[ id ] = true;
  11589. }
  11590. }
  11591. function disable( id ) {
  11592. if ( capabilities[ id ] !== false ) {
  11593. gl.disable( id );
  11594. capabilities[ id ] = false;
  11595. }
  11596. }
  11597. function getCompressedTextureFormats() {
  11598. if ( compressedTextureFormats === null ) {
  11599. compressedTextureFormats = [];
  11600. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  11601. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  11602. extensions.get( 'WEBGL_compressed_texture_etc1' ) ||
  11603. extensions.get( 'WEBGL_compressed_texture_astc' ) ) {
  11604. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  11605. for ( var i = 0; i < formats.length; i ++ ) {
  11606. compressedTextureFormats.push( formats[ i ] );
  11607. }
  11608. }
  11609. }
  11610. return compressedTextureFormats;
  11611. }
  11612. function useProgram( program ) {
  11613. if ( currentProgram !== program ) {
  11614. gl.useProgram( program );
  11615. currentProgram = program;
  11616. return true;
  11617. }
  11618. return false;
  11619. }
  11620. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  11621. if ( blending !== NoBlending ) {
  11622. enable( gl.BLEND );
  11623. } else {
  11624. disable( gl.BLEND );
  11625. }
  11626. if ( blending !== CustomBlending ) {
  11627. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  11628. switch ( blending ) {
  11629. case AdditiveBlending:
  11630. if ( premultipliedAlpha ) {
  11631. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11632. gl.blendFuncSeparate( gl.ONE, gl.ONE, gl.ONE, gl.ONE );
  11633. } else {
  11634. gl.blendEquation( gl.FUNC_ADD );
  11635. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  11636. }
  11637. break;
  11638. case SubtractiveBlending:
  11639. if ( premultipliedAlpha ) {
  11640. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11641. gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ONE_MINUS_SRC_ALPHA );
  11642. } else {
  11643. gl.blendEquation( gl.FUNC_ADD );
  11644. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  11645. }
  11646. break;
  11647. case MultiplyBlending:
  11648. if ( premultipliedAlpha ) {
  11649. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11650. gl.blendFuncSeparate( gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA );
  11651. } else {
  11652. gl.blendEquation( gl.FUNC_ADD );
  11653. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  11654. }
  11655. break;
  11656. default:
  11657. if ( premultipliedAlpha ) {
  11658. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11659. gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  11660. } else {
  11661. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  11662. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  11663. }
  11664. }
  11665. }
  11666. currentBlendEquation = null;
  11667. currentBlendSrc = null;
  11668. currentBlendDst = null;
  11669. currentBlendEquationAlpha = null;
  11670. currentBlendSrcAlpha = null;
  11671. currentBlendDstAlpha = null;
  11672. } else {
  11673. blendEquationAlpha = blendEquationAlpha || blendEquation;
  11674. blendSrcAlpha = blendSrcAlpha || blendSrc;
  11675. blendDstAlpha = blendDstAlpha || blendDst;
  11676. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  11677. gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
  11678. currentBlendEquation = blendEquation;
  11679. currentBlendEquationAlpha = blendEquationAlpha;
  11680. }
  11681. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  11682. gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) );
  11683. currentBlendSrc = blendSrc;
  11684. currentBlendDst = blendDst;
  11685. currentBlendSrcAlpha = blendSrcAlpha;
  11686. currentBlendDstAlpha = blendDstAlpha;
  11687. }
  11688. }
  11689. currentBlending = blending;
  11690. currentPremultipledAlpha = premultipliedAlpha;
  11691. }
  11692. function setMaterial( material, frontFaceCW ) {
  11693. material.side === DoubleSide
  11694. ? disable( gl.CULL_FACE )
  11695. : enable( gl.CULL_FACE );
  11696. var flipSided = ( material.side === BackSide );
  11697. if ( frontFaceCW ) flipSided = ! flipSided;
  11698. setFlipSided( flipSided );
  11699. material.transparent === true
  11700. ? setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha )
  11701. : setBlending( NoBlending );
  11702. depthBuffer.setFunc( material.depthFunc );
  11703. depthBuffer.setTest( material.depthTest );
  11704. depthBuffer.setMask( material.depthWrite );
  11705. colorBuffer.setMask( material.colorWrite );
  11706. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  11707. }
  11708. //
  11709. function setFlipSided( flipSided ) {
  11710. if ( currentFlipSided !== flipSided ) {
  11711. if ( flipSided ) {
  11712. gl.frontFace( gl.CW );
  11713. } else {
  11714. gl.frontFace( gl.CCW );
  11715. }
  11716. currentFlipSided = flipSided;
  11717. }
  11718. }
  11719. function setCullFace( cullFace ) {
  11720. if ( cullFace !== CullFaceNone ) {
  11721. enable( gl.CULL_FACE );
  11722. if ( cullFace !== currentCullFace ) {
  11723. if ( cullFace === CullFaceBack ) {
  11724. gl.cullFace( gl.BACK );
  11725. } else if ( cullFace === CullFaceFront ) {
  11726. gl.cullFace( gl.FRONT );
  11727. } else {
  11728. gl.cullFace( gl.FRONT_AND_BACK );
  11729. }
  11730. }
  11731. } else {
  11732. disable( gl.CULL_FACE );
  11733. }
  11734. currentCullFace = cullFace;
  11735. }
  11736. function setLineWidth( width ) {
  11737. if ( width !== currentLineWidth ) {
  11738. if ( lineWidthAvailable ) gl.lineWidth( width );
  11739. currentLineWidth = width;
  11740. }
  11741. }
  11742. function setPolygonOffset( polygonOffset, factor, units ) {
  11743. if ( polygonOffset ) {
  11744. enable( gl.POLYGON_OFFSET_FILL );
  11745. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  11746. gl.polygonOffset( factor, units );
  11747. currentPolygonOffsetFactor = factor;
  11748. currentPolygonOffsetUnits = units;
  11749. }
  11750. } else {
  11751. disable( gl.POLYGON_OFFSET_FILL );
  11752. }
  11753. }
  11754. function setScissorTest( scissorTest ) {
  11755. if ( scissorTest ) {
  11756. enable( gl.SCISSOR_TEST );
  11757. } else {
  11758. disable( gl.SCISSOR_TEST );
  11759. }
  11760. }
  11761. // texture
  11762. function activeTexture( webglSlot ) {
  11763. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  11764. if ( currentTextureSlot !== webglSlot ) {
  11765. gl.activeTexture( webglSlot );
  11766. currentTextureSlot = webglSlot;
  11767. }
  11768. }
  11769. function bindTexture( webglType, webglTexture ) {
  11770. if ( currentTextureSlot === null ) {
  11771. activeTexture();
  11772. }
  11773. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  11774. if ( boundTexture === undefined ) {
  11775. boundTexture = { type: undefined, texture: undefined };
  11776. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  11777. }
  11778. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  11779. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  11780. boundTexture.type = webglType;
  11781. boundTexture.texture = webglTexture;
  11782. }
  11783. }
  11784. function compressedTexImage2D() {
  11785. try {
  11786. gl.compressedTexImage2D.apply( gl, arguments );
  11787. } catch ( error ) {
  11788. console.error( 'THREE.WebGLState:', error );
  11789. }
  11790. }
  11791. function texImage2D() {
  11792. try {
  11793. gl.texImage2D.apply( gl, arguments );
  11794. } catch ( error ) {
  11795. console.error( 'THREE.WebGLState:', error );
  11796. }
  11797. }
  11798. //
  11799. function scissor( scissor ) {
  11800. if ( currentScissor.equals( scissor ) === false ) {
  11801. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  11802. currentScissor.copy( scissor );
  11803. }
  11804. }
  11805. function viewport( viewport ) {
  11806. if ( currentViewport.equals( viewport ) === false ) {
  11807. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  11808. currentViewport.copy( viewport );
  11809. }
  11810. }
  11811. //
  11812. function reset() {
  11813. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  11814. if ( enabledAttributes[ i ] === 1 ) {
  11815. gl.disableVertexAttribArray( i );
  11816. enabledAttributes[ i ] = 0;
  11817. }
  11818. }
  11819. capabilities = {};
  11820. compressedTextureFormats = null;
  11821. currentTextureSlot = null;
  11822. currentBoundTextures = {};
  11823. currentProgram = null;
  11824. currentBlending = null;
  11825. currentFlipSided = null;
  11826. currentCullFace = null;
  11827. colorBuffer.reset();
  11828. depthBuffer.reset();
  11829. stencilBuffer.reset();
  11830. }
  11831. return {
  11832. buffers: {
  11833. color: colorBuffer,
  11834. depth: depthBuffer,
  11835. stencil: stencilBuffer
  11836. },
  11837. initAttributes: initAttributes,
  11838. enableAttribute: enableAttribute,
  11839. enableAttributeAndDivisor: enableAttributeAndDivisor,
  11840. disableUnusedAttributes: disableUnusedAttributes,
  11841. enable: enable,
  11842. disable: disable,
  11843. getCompressedTextureFormats: getCompressedTextureFormats,
  11844. useProgram: useProgram,
  11845. setBlending: setBlending,
  11846. setMaterial: setMaterial,
  11847. setFlipSided: setFlipSided,
  11848. setCullFace: setCullFace,
  11849. setLineWidth: setLineWidth,
  11850. setPolygonOffset: setPolygonOffset,
  11851. setScissorTest: setScissorTest,
  11852. activeTexture: activeTexture,
  11853. bindTexture: bindTexture,
  11854. compressedTexImage2D: compressedTexImage2D,
  11855. texImage2D: texImage2D,
  11856. scissor: scissor,
  11857. viewport: viewport,
  11858. reset: reset
  11859. };
  11860. }
  11861. /**
  11862. * @author mrdoob / http://mrdoob.com/
  11863. */
  11864. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  11865. var _isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof WebGL2RenderingContext ); /* global WebGL2RenderingContext */
  11866. var _videoTextures = {};
  11867. var _canvas;
  11868. //
  11869. function clampToMaxSize( image, maxSize ) {
  11870. if ( image.width > maxSize || image.height > maxSize ) {
  11871. if ( 'data' in image ) {
  11872. console.warn( 'THREE.WebGLRenderer: image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  11873. return;
  11874. }
  11875. // Warning: Scaling through the canvas will only work with images that use
  11876. // premultiplied alpha.
  11877. var scale = maxSize / Math.max( image.width, image.height );
  11878. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  11879. canvas.width = Math.floor( image.width * scale );
  11880. canvas.height = Math.floor( image.height * scale );
  11881. var context = canvas.getContext( '2d' );
  11882. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  11883. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  11884. return canvas;
  11885. }
  11886. return image;
  11887. }
  11888. function isPowerOfTwo( image ) {
  11889. return _Math.isPowerOfTwo( image.width ) && _Math.isPowerOfTwo( image.height );
  11890. }
  11891. function makePowerOfTwo( image ) {
  11892. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof ImageBitmap ) {
  11893. if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  11894. _canvas.width = _Math.floorPowerOfTwo( image.width );
  11895. _canvas.height = _Math.floorPowerOfTwo( image.height );
  11896. var context = _canvas.getContext( '2d' );
  11897. context.drawImage( image, 0, 0, _canvas.width, _canvas.height );
  11898. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + _canvas.width + 'x' + _canvas.height, image );
  11899. return _canvas;
  11900. }
  11901. return image;
  11902. }
  11903. function textureNeedsPowerOfTwo( texture ) {
  11904. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  11905. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  11906. }
  11907. function textureNeedsGenerateMipmaps( texture, isPowerOfTwo ) {
  11908. return texture.generateMipmaps && isPowerOfTwo &&
  11909. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  11910. }
  11911. function generateMipmap( target, texture, width, height ) {
  11912. _gl.generateMipmap( target );
  11913. var textureProperties = properties.get( texture );
  11914. // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  11915. textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
  11916. }
  11917. // Fallback filters for non-power-of-2 textures
  11918. function filterFallback( f ) {
  11919. if ( f === NearestFilter || f === NearestMipMapNearestFilter || f === NearestMipMapLinearFilter ) {
  11920. return _gl.NEAREST;
  11921. }
  11922. return _gl.LINEAR;
  11923. }
  11924. //
  11925. function onTextureDispose( event ) {
  11926. var texture = event.target;
  11927. texture.removeEventListener( 'dispose', onTextureDispose );
  11928. deallocateTexture( texture );
  11929. if ( texture.isVideoTexture ) {
  11930. delete _videoTextures[ texture.id ];
  11931. }
  11932. info.memory.textures --;
  11933. }
  11934. function onRenderTargetDispose( event ) {
  11935. var renderTarget = event.target;
  11936. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  11937. deallocateRenderTarget( renderTarget );
  11938. info.memory.textures --;
  11939. }
  11940. //
  11941. function deallocateTexture( texture ) {
  11942. var textureProperties = properties.get( texture );
  11943. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  11944. // cube texture
  11945. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  11946. } else {
  11947. // 2D texture
  11948. if ( textureProperties.__webglInit === undefined ) return;
  11949. _gl.deleteTexture( textureProperties.__webglTexture );
  11950. }
  11951. // remove all webgl properties
  11952. properties.remove( texture );
  11953. }
  11954. function deallocateRenderTarget( renderTarget ) {
  11955. var renderTargetProperties = properties.get( renderTarget );
  11956. var textureProperties = properties.get( renderTarget.texture );
  11957. if ( ! renderTarget ) return;
  11958. if ( textureProperties.__webglTexture !== undefined ) {
  11959. _gl.deleteTexture( textureProperties.__webglTexture );
  11960. }
  11961. if ( renderTarget.depthTexture ) {
  11962. renderTarget.depthTexture.dispose();
  11963. }
  11964. if ( renderTarget.isWebGLRenderTargetCube ) {
  11965. for ( var i = 0; i < 6; i ++ ) {
  11966. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  11967. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  11968. }
  11969. } else {
  11970. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  11971. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  11972. }
  11973. properties.remove( renderTarget.texture );
  11974. properties.remove( renderTarget );
  11975. }
  11976. //
  11977. function setTexture2D( texture, slot ) {
  11978. var textureProperties = properties.get( texture );
  11979. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  11980. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  11981. var image = texture.image;
  11982. if ( image === undefined ) {
  11983. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  11984. } else if ( image.complete === false ) {
  11985. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  11986. } else {
  11987. uploadTexture( textureProperties, texture, slot );
  11988. return;
  11989. }
  11990. }
  11991. state.activeTexture( _gl.TEXTURE0 + slot );
  11992. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  11993. }
  11994. function setTextureCube( texture, slot ) {
  11995. var textureProperties = properties.get( texture );
  11996. if ( texture.image.length === 6 ) {
  11997. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  11998. if ( ! textureProperties.__image__webglTextureCube ) {
  11999. texture.addEventListener( 'dispose', onTextureDispose );
  12000. textureProperties.__image__webglTextureCube = _gl.createTexture();
  12001. info.memory.textures ++;
  12002. }
  12003. state.activeTexture( _gl.TEXTURE0 + slot );
  12004. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  12005. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  12006. var isCompressed = ( texture && texture.isCompressedTexture );
  12007. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  12008. var cubeImage = [];
  12009. for ( var i = 0; i < 6; i ++ ) {
  12010. if ( ! isCompressed && ! isDataTexture ) {
  12011. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  12012. } else {
  12013. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  12014. }
  12015. }
  12016. var image = cubeImage[ 0 ],
  12017. isPowerOfTwoImage = isPowerOfTwo( image ),
  12018. glFormat = utils.convert( texture.format ),
  12019. glType = utils.convert( texture.type );
  12020. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
  12021. for ( var i = 0; i < 6; i ++ ) {
  12022. if ( ! isCompressed ) {
  12023. if ( isDataTexture ) {
  12024. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  12025. } else {
  12026. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  12027. }
  12028. } else {
  12029. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  12030. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  12031. mipmap = mipmaps[ j ];
  12032. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12033. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12034. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12035. } else {
  12036. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  12037. }
  12038. } else {
  12039. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12040. }
  12041. }
  12042. }
  12043. }
  12044. if ( ! isCompressed ) {
  12045. textureProperties.__maxMipLevel = 0;
  12046. } else {
  12047. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12048. }
  12049. if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) {
  12050. // We assume images for cube map have the same size.
  12051. generateMipmap( _gl.TEXTURE_CUBE_MAP, texture, image.width, image.height );
  12052. }
  12053. textureProperties.__version = texture.version;
  12054. if ( texture.onUpdate ) texture.onUpdate( texture );
  12055. } else {
  12056. state.activeTexture( _gl.TEXTURE0 + slot );
  12057. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  12058. }
  12059. }
  12060. }
  12061. function setTextureCubeDynamic( texture, slot ) {
  12062. state.activeTexture( _gl.TEXTURE0 + slot );
  12063. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  12064. }
  12065. function setTextureParameters( textureType, texture, isPowerOfTwoImage ) {
  12066. var extension;
  12067. if ( isPowerOfTwoImage ) {
  12068. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, utils.convert( texture.wrapS ) );
  12069. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, utils.convert( texture.wrapT ) );
  12070. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, utils.convert( texture.magFilter ) );
  12071. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, utils.convert( texture.minFilter ) );
  12072. } else {
  12073. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  12074. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  12075. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  12076. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  12077. }
  12078. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  12079. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  12080. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  12081. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  12082. }
  12083. }
  12084. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  12085. if ( extension ) {
  12086. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  12087. if ( texture.type === HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  12088. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  12089. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  12090. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  12091. }
  12092. }
  12093. }
  12094. function uploadTexture( textureProperties, texture, slot ) {
  12095. if ( textureProperties.__webglInit === undefined ) {
  12096. textureProperties.__webglInit = true;
  12097. texture.addEventListener( 'dispose', onTextureDispose );
  12098. textureProperties.__webglTexture = _gl.createTexture();
  12099. info.memory.textures ++;
  12100. }
  12101. state.activeTexture( _gl.TEXTURE0 + slot );
  12102. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  12103. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  12104. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  12105. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  12106. var image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  12107. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( image ) === false ) {
  12108. image = makePowerOfTwo( image );
  12109. }
  12110. var isPowerOfTwoImage = isPowerOfTwo( image ),
  12111. glFormat = utils.convert( texture.format ),
  12112. glType = utils.convert( texture.type );
  12113. setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
  12114. var mipmap, mipmaps = texture.mipmaps;
  12115. if ( texture.isDepthTexture ) {
  12116. // populate depth texture with dummy data
  12117. var internalFormat = _gl.DEPTH_COMPONENT;
  12118. if ( texture.type === FloatType ) {
  12119. if ( ! _isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
  12120. internalFormat = _gl.DEPTH_COMPONENT32F;
  12121. } else if ( _isWebGL2 ) {
  12122. // WebGL 2.0 requires signed internalformat for glTexImage2D
  12123. internalFormat = _gl.DEPTH_COMPONENT16;
  12124. }
  12125. if ( texture.format === DepthFormat && internalFormat === _gl.DEPTH_COMPONENT ) {
  12126. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12127. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12128. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12129. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  12130. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  12131. texture.type = UnsignedShortType;
  12132. glType = utils.convert( texture.type );
  12133. }
  12134. }
  12135. // Depth stencil textures need the DEPTH_STENCIL internal format
  12136. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12137. if ( texture.format === DepthStencilFormat ) {
  12138. internalFormat = _gl.DEPTH_STENCIL;
  12139. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12140. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12141. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12142. if ( texture.type !== UnsignedInt248Type ) {
  12143. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  12144. texture.type = UnsignedInt248Type;
  12145. glType = utils.convert( texture.type );
  12146. }
  12147. }
  12148. state.texImage2D( _gl.TEXTURE_2D, 0, internalFormat, image.width, image.height, 0, glFormat, glType, null );
  12149. } else if ( texture.isDataTexture ) {
  12150. // use manually created mipmaps if available
  12151. // if there are no manual mipmaps
  12152. // set 0 level mipmap and then use GL to generate other mipmap levels
  12153. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  12154. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12155. mipmap = mipmaps[ i ];
  12156. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12157. }
  12158. texture.generateMipmaps = false;
  12159. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12160. } else {
  12161. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  12162. textureProperties.__maxMipLevel = 0;
  12163. }
  12164. } else if ( texture.isCompressedTexture ) {
  12165. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12166. mipmap = mipmaps[ i ];
  12167. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12168. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12169. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12170. } else {
  12171. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  12172. }
  12173. } else {
  12174. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12175. }
  12176. }
  12177. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12178. } else {
  12179. // regular Texture (image, video, canvas)
  12180. // use manually created mipmaps if available
  12181. // if there are no manual mipmaps
  12182. // set 0 level mipmap and then use GL to generate other mipmap levels
  12183. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  12184. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12185. mipmap = mipmaps[ i ];
  12186. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  12187. }
  12188. texture.generateMipmaps = false;
  12189. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12190. } else {
  12191. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, image );
  12192. textureProperties.__maxMipLevel = 0;
  12193. }
  12194. }
  12195. if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) {
  12196. generateMipmap( _gl.TEXTURE_2D, texture, image.width, image.height );
  12197. }
  12198. textureProperties.__version = texture.version;
  12199. if ( texture.onUpdate ) texture.onUpdate( texture );
  12200. }
  12201. // Render targets
  12202. // Setup storage for target texture and bind it to correct framebuffer
  12203. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  12204. var glFormat = utils.convert( renderTarget.texture.format );
  12205. var glType = utils.convert( renderTarget.texture.type );
  12206. state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  12207. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  12208. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  12209. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  12210. }
  12211. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  12212. function setupRenderBufferStorage( renderbuffer, renderTarget ) {
  12213. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  12214. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  12215. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  12216. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  12217. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  12218. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  12219. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  12220. } else {
  12221. // FIXME: We don't support !depth !stencil
  12222. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  12223. }
  12224. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  12225. }
  12226. // Setup resources for a Depth Texture for a FBO (needs an extension)
  12227. function setupDepthTexture( framebuffer, renderTarget ) {
  12228. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  12229. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  12230. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  12231. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  12232. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  12233. }
  12234. // upload an empty depth texture with framebuffer size
  12235. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  12236. renderTarget.depthTexture.image.width !== renderTarget.width ||
  12237. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  12238. renderTarget.depthTexture.image.width = renderTarget.width;
  12239. renderTarget.depthTexture.image.height = renderTarget.height;
  12240. renderTarget.depthTexture.needsUpdate = true;
  12241. }
  12242. setTexture2D( renderTarget.depthTexture, 0 );
  12243. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  12244. if ( renderTarget.depthTexture.format === DepthFormat ) {
  12245. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  12246. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  12247. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  12248. } else {
  12249. throw new Error( 'Unknown depthTexture format' );
  12250. }
  12251. }
  12252. // Setup GL resources for a non-texture depth buffer
  12253. function setupDepthRenderbuffer( renderTarget ) {
  12254. var renderTargetProperties = properties.get( renderTarget );
  12255. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  12256. if ( renderTarget.depthTexture ) {
  12257. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  12258. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  12259. } else {
  12260. if ( isCube ) {
  12261. renderTargetProperties.__webglDepthbuffer = [];
  12262. for ( var i = 0; i < 6; i ++ ) {
  12263. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );
  12264. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  12265. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  12266. }
  12267. } else {
  12268. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
  12269. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  12270. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  12271. }
  12272. }
  12273. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  12274. }
  12275. // Set up GL resources for the render target
  12276. function setupRenderTarget( renderTarget ) {
  12277. var renderTargetProperties = properties.get( renderTarget );
  12278. var textureProperties = properties.get( renderTarget.texture );
  12279. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  12280. textureProperties.__webglTexture = _gl.createTexture();
  12281. info.memory.textures ++;
  12282. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  12283. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  12284. // Setup framebuffer
  12285. if ( isCube ) {
  12286. renderTargetProperties.__webglFramebuffer = [];
  12287. for ( var i = 0; i < 6; i ++ ) {
  12288. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  12289. }
  12290. } else {
  12291. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  12292. }
  12293. // Setup color buffer
  12294. if ( isCube ) {
  12295. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  12296. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  12297. for ( var i = 0; i < 6; i ++ ) {
  12298. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  12299. }
  12300. if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) {
  12301. generateMipmap( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, renderTarget.width, renderTarget.height );
  12302. }
  12303. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  12304. } else {
  12305. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  12306. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  12307. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );
  12308. if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) {
  12309. generateMipmap( _gl.TEXTURE_2D, renderTarget.texture, renderTarget.width, renderTarget.height );
  12310. }
  12311. state.bindTexture( _gl.TEXTURE_2D, null );
  12312. }
  12313. // Setup depth and stencil buffers
  12314. if ( renderTarget.depthBuffer ) {
  12315. setupDepthRenderbuffer( renderTarget );
  12316. }
  12317. }
  12318. function updateRenderTargetMipmap( renderTarget ) {
  12319. var texture = renderTarget.texture;
  12320. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  12321. if ( textureNeedsGenerateMipmaps( texture, isTargetPowerOfTwo ) ) {
  12322. var target = renderTarget.isWebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  12323. var webglTexture = properties.get( texture ).__webglTexture;
  12324. state.bindTexture( target, webglTexture );
  12325. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  12326. state.bindTexture( target, null );
  12327. }
  12328. }
  12329. function updateVideoTexture( texture ) {
  12330. var id = texture.id;
  12331. var frame = info.render.frame;
  12332. // Check the last frame we updated the VideoTexture
  12333. if ( _videoTextures[ id ] !== frame ) {
  12334. _videoTextures[ id ] = frame;
  12335. texture.update();
  12336. }
  12337. }
  12338. this.setTexture2D = setTexture2D;
  12339. this.setTextureCube = setTextureCube;
  12340. this.setTextureCubeDynamic = setTextureCubeDynamic;
  12341. this.setupRenderTarget = setupRenderTarget;
  12342. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  12343. }
  12344. /**
  12345. * @author thespite / http://www.twitter.com/thespite
  12346. */
  12347. function WebGLUtils( gl, extensions ) {
  12348. function convert( p ) {
  12349. var extension;
  12350. if ( p === RepeatWrapping ) return gl.REPEAT;
  12351. if ( p === ClampToEdgeWrapping ) return gl.CLAMP_TO_EDGE;
  12352. if ( p === MirroredRepeatWrapping ) return gl.MIRRORED_REPEAT;
  12353. if ( p === NearestFilter ) return gl.NEAREST;
  12354. if ( p === NearestMipMapNearestFilter ) return gl.NEAREST_MIPMAP_NEAREST;
  12355. if ( p === NearestMipMapLinearFilter ) return gl.NEAREST_MIPMAP_LINEAR;
  12356. if ( p === LinearFilter ) return gl.LINEAR;
  12357. if ( p === LinearMipMapNearestFilter ) return gl.LINEAR_MIPMAP_NEAREST;
  12358. if ( p === LinearMipMapLinearFilter ) return gl.LINEAR_MIPMAP_LINEAR;
  12359. if ( p === UnsignedByteType ) return gl.UNSIGNED_BYTE;
  12360. if ( p === UnsignedShort4444Type ) return gl.UNSIGNED_SHORT_4_4_4_4;
  12361. if ( p === UnsignedShort5551Type ) return gl.UNSIGNED_SHORT_5_5_5_1;
  12362. if ( p === UnsignedShort565Type ) return gl.UNSIGNED_SHORT_5_6_5;
  12363. if ( p === ByteType ) return gl.BYTE;
  12364. if ( p === ShortType ) return gl.SHORT;
  12365. if ( p === UnsignedShortType ) return gl.UNSIGNED_SHORT;
  12366. if ( p === IntType ) return gl.INT;
  12367. if ( p === UnsignedIntType ) return gl.UNSIGNED_INT;
  12368. if ( p === FloatType ) return gl.FLOAT;
  12369. if ( p === HalfFloatType ) {
  12370. extension = extensions.get( 'OES_texture_half_float' );
  12371. if ( extension !== null ) return extension.HALF_FLOAT_OES;
  12372. }
  12373. if ( p === AlphaFormat ) return gl.ALPHA;
  12374. if ( p === RGBFormat ) return gl.RGB;
  12375. if ( p === RGBAFormat ) return gl.RGBA;
  12376. if ( p === LuminanceFormat ) return gl.LUMINANCE;
  12377. if ( p === LuminanceAlphaFormat ) return gl.LUMINANCE_ALPHA;
  12378. if ( p === DepthFormat ) return gl.DEPTH_COMPONENT;
  12379. if ( p === DepthStencilFormat ) return gl.DEPTH_STENCIL;
  12380. if ( p === AddEquation ) return gl.FUNC_ADD;
  12381. if ( p === SubtractEquation ) return gl.FUNC_SUBTRACT;
  12382. if ( p === ReverseSubtractEquation ) return gl.FUNC_REVERSE_SUBTRACT;
  12383. if ( p === ZeroFactor ) return gl.ZERO;
  12384. if ( p === OneFactor ) return gl.ONE;
  12385. if ( p === SrcColorFactor ) return gl.SRC_COLOR;
  12386. if ( p === OneMinusSrcColorFactor ) return gl.ONE_MINUS_SRC_COLOR;
  12387. if ( p === SrcAlphaFactor ) return gl.SRC_ALPHA;
  12388. if ( p === OneMinusSrcAlphaFactor ) return gl.ONE_MINUS_SRC_ALPHA;
  12389. if ( p === DstAlphaFactor ) return gl.DST_ALPHA;
  12390. if ( p === OneMinusDstAlphaFactor ) return gl.ONE_MINUS_DST_ALPHA;
  12391. if ( p === DstColorFactor ) return gl.DST_COLOR;
  12392. if ( p === OneMinusDstColorFactor ) return gl.ONE_MINUS_DST_COLOR;
  12393. if ( p === SrcAlphaSaturateFactor ) return gl.SRC_ALPHA_SATURATE;
  12394. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  12395. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  12396. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  12397. if ( extension !== null ) {
  12398. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  12399. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  12400. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  12401. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  12402. }
  12403. }
  12404. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  12405. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  12406. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  12407. if ( extension !== null ) {
  12408. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  12409. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  12410. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  12411. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  12412. }
  12413. }
  12414. if ( p === RGB_ETC1_Format ) {
  12415. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  12416. if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  12417. }
  12418. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  12419. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  12420. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  12421. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  12422. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ) {
  12423. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  12424. if ( extension !== null ) {
  12425. return p;
  12426. }
  12427. }
  12428. if ( p === MinEquation || p === MaxEquation ) {
  12429. extension = extensions.get( 'EXT_blend_minmax' );
  12430. if ( extension !== null ) {
  12431. if ( p === MinEquation ) return extension.MIN_EXT;
  12432. if ( p === MaxEquation ) return extension.MAX_EXT;
  12433. }
  12434. }
  12435. if ( p === UnsignedInt248Type ) {
  12436. extension = extensions.get( 'WEBGL_depth_texture' );
  12437. if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
  12438. }
  12439. return 0;
  12440. }
  12441. return { convert: convert };
  12442. }
  12443. /**
  12444. * @author mrdoob / http://mrdoob.com/
  12445. * @author greggman / http://games.greggman.com/
  12446. * @author zz85 / http://www.lab4games.net/zz85/blog
  12447. * @author tschw
  12448. */
  12449. function PerspectiveCamera( fov, aspect, near, far ) {
  12450. Camera.call( this );
  12451. this.type = 'PerspectiveCamera';
  12452. this.fov = fov !== undefined ? fov : 50;
  12453. this.zoom = 1;
  12454. this.near = near !== undefined ? near : 0.1;
  12455. this.far = far !== undefined ? far : 2000;
  12456. this.focus = 10;
  12457. this.aspect = aspect !== undefined ? aspect : 1;
  12458. this.view = null;
  12459. this.filmGauge = 35; // width of the film (default in millimeters)
  12460. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  12461. this.updateProjectionMatrix();
  12462. }
  12463. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  12464. constructor: PerspectiveCamera,
  12465. isPerspectiveCamera: true,
  12466. copy: function ( source, recursive ) {
  12467. Camera.prototype.copy.call( this, source, recursive );
  12468. this.fov = source.fov;
  12469. this.zoom = source.zoom;
  12470. this.near = source.near;
  12471. this.far = source.far;
  12472. this.focus = source.focus;
  12473. this.aspect = source.aspect;
  12474. this.view = source.view === null ? null : Object.assign( {}, source.view );
  12475. this.filmGauge = source.filmGauge;
  12476. this.filmOffset = source.filmOffset;
  12477. return this;
  12478. },
  12479. /**
  12480. * Sets the FOV by focal length in respect to the current .filmGauge.
  12481. *
  12482. * The default film gauge is 35, so that the focal length can be specified for
  12483. * a 35mm (full frame) camera.
  12484. *
  12485. * Values for focal length and film gauge must have the same unit.
  12486. */
  12487. setFocalLength: function ( focalLength ) {
  12488. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  12489. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  12490. this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  12491. this.updateProjectionMatrix();
  12492. },
  12493. /**
  12494. * Calculates the focal length from the current .fov and .filmGauge.
  12495. */
  12496. getFocalLength: function () {
  12497. var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
  12498. return 0.5 * this.getFilmHeight() / vExtentSlope;
  12499. },
  12500. getEffectiveFOV: function () {
  12501. return _Math.RAD2DEG * 2 * Math.atan(
  12502. Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  12503. },
  12504. getFilmWidth: function () {
  12505. // film not completely covered in portrait format (aspect < 1)
  12506. return this.filmGauge * Math.min( this.aspect, 1 );
  12507. },
  12508. getFilmHeight: function () {
  12509. // film not completely covered in landscape format (aspect > 1)
  12510. return this.filmGauge / Math.max( this.aspect, 1 );
  12511. },
  12512. /**
  12513. * Sets an offset in a larger frustum. This is useful for multi-window or
  12514. * multi-monitor/multi-machine setups.
  12515. *
  12516. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  12517. * the monitors are in grid like this
  12518. *
  12519. * +---+---+---+
  12520. * | A | B | C |
  12521. * +---+---+---+
  12522. * | D | E | F |
  12523. * +---+---+---+
  12524. *
  12525. * then for each monitor you would call it like this
  12526. *
  12527. * var w = 1920;
  12528. * var h = 1080;
  12529. * var fullWidth = w * 3;
  12530. * var fullHeight = h * 2;
  12531. *
  12532. * --A--
  12533. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  12534. * --B--
  12535. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  12536. * --C--
  12537. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  12538. * --D--
  12539. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  12540. * --E--
  12541. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  12542. * --F--
  12543. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  12544. *
  12545. * Note there is no reason monitors have to be the same size or in a grid.
  12546. */
  12547. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  12548. this.aspect = fullWidth / fullHeight;
  12549. if ( this.view === null ) {
  12550. this.view = {
  12551. enabled: true,
  12552. fullWidth: 1,
  12553. fullHeight: 1,
  12554. offsetX: 0,
  12555. offsetY: 0,
  12556. width: 1,
  12557. height: 1
  12558. };
  12559. }
  12560. this.view.enabled = true;
  12561. this.view.fullWidth = fullWidth;
  12562. this.view.fullHeight = fullHeight;
  12563. this.view.offsetX = x;
  12564. this.view.offsetY = y;
  12565. this.view.width = width;
  12566. this.view.height = height;
  12567. this.updateProjectionMatrix();
  12568. },
  12569. clearViewOffset: function () {
  12570. if ( this.view !== null ) {
  12571. this.view.enabled = false;
  12572. }
  12573. this.updateProjectionMatrix();
  12574. },
  12575. updateProjectionMatrix: function () {
  12576. var near = this.near,
  12577. top = near * Math.tan(
  12578. _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  12579. height = 2 * top,
  12580. width = this.aspect * height,
  12581. left = - 0.5 * width,
  12582. view = this.view;
  12583. if ( this.view !== null && this.view.enabled ) {
  12584. var fullWidth = view.fullWidth,
  12585. fullHeight = view.fullHeight;
  12586. left += view.offsetX * width / fullWidth;
  12587. top -= view.offsetY * height / fullHeight;
  12588. width *= view.width / fullWidth;
  12589. height *= view.height / fullHeight;
  12590. }
  12591. var skew = this.filmOffset;
  12592. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  12593. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  12594. },
  12595. toJSON: function ( meta ) {
  12596. var data = Object3D.prototype.toJSON.call( this, meta );
  12597. data.object.fov = this.fov;
  12598. data.object.zoom = this.zoom;
  12599. data.object.near = this.near;
  12600. data.object.far = this.far;
  12601. data.object.focus = this.focus;
  12602. data.object.aspect = this.aspect;
  12603. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  12604. data.object.filmGauge = this.filmGauge;
  12605. data.object.filmOffset = this.filmOffset;
  12606. return data;
  12607. }
  12608. } );
  12609. /**
  12610. * @author mrdoob / http://mrdoob.com/
  12611. */
  12612. function ArrayCamera( array ) {
  12613. PerspectiveCamera.call( this );
  12614. this.cameras = array || [];
  12615. }
  12616. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  12617. constructor: ArrayCamera,
  12618. isArrayCamera: true
  12619. } );
  12620. /**
  12621. * @author mrdoob / http://mrdoob.com/
  12622. */
  12623. function WebVRManager( renderer ) {
  12624. var scope = this;
  12625. var device = null;
  12626. var frameData = null;
  12627. var poseTarget = null;
  12628. var standingMatrix = new Matrix4();
  12629. var standingMatrixInverse = new Matrix4();
  12630. if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
  12631. frameData = new window.VRFrameData();
  12632. window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
  12633. }
  12634. var matrixWorldInverse = new Matrix4();
  12635. var tempQuaternion = new Quaternion();
  12636. var tempPosition = new Vector3();
  12637. var cameraL = new PerspectiveCamera();
  12638. cameraL.bounds = new Vector4( 0.0, 0.0, 0.5, 1.0 );
  12639. cameraL.layers.enable( 1 );
  12640. var cameraR = new PerspectiveCamera();
  12641. cameraR.bounds = new Vector4( 0.5, 0.0, 0.5, 1.0 );
  12642. cameraR.layers.enable( 2 );
  12643. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  12644. cameraVR.layers.enable( 1 );
  12645. cameraVR.layers.enable( 2 );
  12646. //
  12647. function isPresenting() {
  12648. return device !== null && device.isPresenting === true;
  12649. }
  12650. var currentSize, currentPixelRatio;
  12651. function onVRDisplayPresentChange() {
  12652. if ( isPresenting() ) {
  12653. var eyeParameters = device.getEyeParameters( 'left' );
  12654. var renderWidth = eyeParameters.renderWidth;
  12655. var renderHeight = eyeParameters.renderHeight;
  12656. currentPixelRatio = renderer.getPixelRatio();
  12657. currentSize = renderer.getSize();
  12658. renderer.setDrawingBufferSize( renderWidth * 2, renderHeight, 1 );
  12659. animation.start();
  12660. } else if ( scope.enabled ) {
  12661. renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
  12662. animation.stop();
  12663. }
  12664. }
  12665. //
  12666. this.enabled = false;
  12667. this.userHeight = 1.6;
  12668. this.getDevice = function () {
  12669. return device;
  12670. };
  12671. this.setDevice = function ( value ) {
  12672. if ( value !== undefined ) device = value;
  12673. animation.setContext( value );
  12674. };
  12675. this.setPoseTarget = function ( object ) {
  12676. if ( object !== undefined ) poseTarget = object;
  12677. };
  12678. this.getCamera = function ( camera ) {
  12679. if ( device === null ) return camera;
  12680. device.depthNear = camera.near;
  12681. device.depthFar = camera.far;
  12682. device.getFrameData( frameData );
  12683. //
  12684. var stageParameters = device.stageParameters;
  12685. if ( stageParameters ) {
  12686. standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
  12687. } else {
  12688. standingMatrix.makeTranslation( 0, scope.userHeight, 0 );
  12689. }
  12690. var pose = frameData.pose;
  12691. var poseObject = poseTarget !== null ? poseTarget : camera;
  12692. // We want to manipulate poseObject by its position and quaternion components since users may rely on them.
  12693. poseObject.matrix.copy( standingMatrix );
  12694. poseObject.matrix.decompose( poseObject.position, poseObject.quaternion, poseObject.scale );
  12695. if ( pose.orientation !== null ) {
  12696. tempQuaternion.fromArray( pose.orientation );
  12697. poseObject.quaternion.multiply( tempQuaternion );
  12698. }
  12699. if ( pose.position !== null ) {
  12700. tempQuaternion.setFromRotationMatrix( standingMatrix );
  12701. tempPosition.fromArray( pose.position );
  12702. tempPosition.applyQuaternion( tempQuaternion );
  12703. poseObject.position.add( tempPosition );
  12704. }
  12705. poseObject.updateMatrixWorld();
  12706. if ( device.isPresenting === false ) return camera;
  12707. //
  12708. cameraL.near = camera.near;
  12709. cameraR.near = camera.near;
  12710. cameraL.far = camera.far;
  12711. cameraR.far = camera.far;
  12712. cameraVR.matrixWorld.copy( camera.matrixWorld );
  12713. cameraVR.matrixWorldInverse.copy( camera.matrixWorldInverse );
  12714. cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
  12715. cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
  12716. // TODO (mrdoob) Double check this code
  12717. standingMatrixInverse.getInverse( standingMatrix );
  12718. cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
  12719. cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
  12720. var parent = poseObject.parent;
  12721. if ( parent !== null ) {
  12722. matrixWorldInverse.getInverse( parent.matrixWorld );
  12723. cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
  12724. cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
  12725. }
  12726. // envMap and Mirror needs camera.matrixWorld
  12727. cameraL.matrixWorld.getInverse( cameraL.matrixWorldInverse );
  12728. cameraR.matrixWorld.getInverse( cameraR.matrixWorldInverse );
  12729. cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
  12730. cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
  12731. // HACK (mrdoob)
  12732. // https://github.com/w3c/webvr/issues/203
  12733. cameraVR.projectionMatrix.copy( cameraL.projectionMatrix );
  12734. //
  12735. var layers = device.getLayers();
  12736. if ( layers.length ) {
  12737. var layer = layers[ 0 ];
  12738. if ( layer.leftBounds !== null && layer.leftBounds.length === 4 ) {
  12739. cameraL.bounds.fromArray( layer.leftBounds );
  12740. }
  12741. if ( layer.rightBounds !== null && layer.rightBounds.length === 4 ) {
  12742. cameraR.bounds.fromArray( layer.rightBounds );
  12743. }
  12744. }
  12745. return cameraVR;
  12746. };
  12747. this.getStandingMatrix = function () {
  12748. return standingMatrix;
  12749. };
  12750. this.isPresenting = isPresenting;
  12751. // Animation Loop
  12752. var animation = new WebGLAnimation();
  12753. this.setAnimationLoop = function ( callback ) {
  12754. animation.setAnimationLoop( callback );
  12755. };
  12756. this.submitFrame = function () {
  12757. if ( isPresenting() ) device.submitFrame();
  12758. };
  12759. this.dispose = function () {
  12760. if ( typeof window !== 'undefined' ) {
  12761. window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
  12762. }
  12763. };
  12764. }
  12765. /**
  12766. * @author mrdoob / http://mrdoob.com/
  12767. */
  12768. function WebXRManager( renderer ) {
  12769. var gl = renderer.context;
  12770. var device = null;
  12771. var session = null;
  12772. var frameOfRef = null;
  12773. var pose = null;
  12774. function isPresenting() {
  12775. return session !== null && frameOfRef !== null;
  12776. }
  12777. //
  12778. var cameraL = new PerspectiveCamera();
  12779. cameraL.layers.enable( 1 );
  12780. cameraL.viewport = new Vector4();
  12781. var cameraR = new PerspectiveCamera();
  12782. cameraR.layers.enable( 2 );
  12783. cameraR.viewport = new Vector4();
  12784. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  12785. cameraVR.layers.enable( 1 );
  12786. cameraVR.layers.enable( 2 );
  12787. //
  12788. this.enabled = false;
  12789. this.getDevice = function () {
  12790. return device;
  12791. };
  12792. this.setDevice = function ( value ) {
  12793. if ( value !== undefined ) device = value;
  12794. gl.setCompatibleXRDevice( value );
  12795. };
  12796. //
  12797. this.setSession = function ( value, options ) {
  12798. session = value;
  12799. if ( session !== null ) {
  12800. session.addEventListener( 'end', function () {
  12801. renderer.setFramebuffer( null );
  12802. animation.stop();
  12803. } );
  12804. session.baseLayer = new XRWebGLLayer( session, gl );
  12805. session.requestFrameOfReference( options.frameOfReferenceType ).then( function ( value ) {
  12806. frameOfRef = value;
  12807. renderer.setFramebuffer( session.baseLayer.framebuffer );
  12808. animation.setContext( session );
  12809. animation.start();
  12810. } );
  12811. }
  12812. };
  12813. function updateCamera( camera, parent ) {
  12814. if ( parent === null ) {
  12815. camera.matrixWorld.copy( camera.matrix );
  12816. } else {
  12817. camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );
  12818. }
  12819. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  12820. }
  12821. this.getCamera = function ( camera ) {
  12822. if ( isPresenting() ) {
  12823. var parent = camera.parent;
  12824. var cameras = cameraVR.cameras;
  12825. // apply camera.parent to cameraVR
  12826. updateCamera( cameraVR, parent );
  12827. for ( var i = 0; i < cameras.length; i ++ ) {
  12828. updateCamera( cameras[ i ], parent );
  12829. }
  12830. // update camera and its children
  12831. camera.matrixWorld.copy( cameraVR.matrixWorld );
  12832. var children = camera.children;
  12833. for ( var i = 0, l = children.length; i < l; i ++ ) {
  12834. children[ i ].updateMatrixWorld( true );
  12835. }
  12836. return cameraVR;
  12837. }
  12838. return camera;
  12839. };
  12840. this.isPresenting = isPresenting;
  12841. // Animation Loop
  12842. var onAnimationFrameCallback = null;
  12843. function onAnimationFrame( time, frame ) {
  12844. pose = frame.getDevicePose( frameOfRef );
  12845. var layer = session.baseLayer;
  12846. var views = frame.views;
  12847. for ( var i = 0; i < views.length; i ++ ) {
  12848. var view = views[ i ];
  12849. var viewport = layer.getViewport( view );
  12850. var viewMatrix = pose.getViewMatrix( view );
  12851. var camera = cameraVR.cameras[ i ];
  12852. camera.matrix.fromArray( viewMatrix ).getInverse( camera.matrix );
  12853. camera.projectionMatrix.fromArray( view.projectionMatrix );
  12854. camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
  12855. if ( i === 0 ) {
  12856. cameraVR.matrix.copy( camera.matrix );
  12857. // HACK (mrdoob)
  12858. // https://github.com/w3c/webvr/issues/203
  12859. cameraVR.projectionMatrix.copy( camera.projectionMatrix );
  12860. }
  12861. }
  12862. if ( onAnimationFrameCallback ) onAnimationFrameCallback();
  12863. }
  12864. var animation = new WebGLAnimation();
  12865. animation.setAnimationLoop( onAnimationFrame );
  12866. this.setAnimationLoop = function ( callback ) {
  12867. onAnimationFrameCallback = callback;
  12868. };
  12869. // DEPRECATED
  12870. this.getStandingMatrix = function () {
  12871. console.warn( 'THREE.WebXRManager: getStandingMatrix() is no longer needed.' );
  12872. return new THREE.Matrix4();
  12873. };
  12874. this.submitFrame = function () {};
  12875. }
  12876. /**
  12877. * @author supereggbert / http://www.paulbrunt.co.uk/
  12878. * @author mrdoob / http://mrdoob.com/
  12879. * @author alteredq / http://alteredqualia.com/
  12880. * @author szimek / https://github.com/szimek/
  12881. * @author tschw
  12882. */
  12883. function WebGLRenderer( parameters ) {
  12884. console.log( 'THREE.WebGLRenderer', REVISION );
  12885. parameters = parameters || {};
  12886. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  12887. _context = parameters.context !== undefined ? parameters.context : null,
  12888. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  12889. _depth = parameters.depth !== undefined ? parameters.depth : true,
  12890. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  12891. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  12892. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  12893. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  12894. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default';
  12895. var currentRenderList = null;
  12896. var currentRenderState = null;
  12897. // public properties
  12898. this.domElement = _canvas;
  12899. this.context = null;
  12900. // clearing
  12901. this.autoClear = true;
  12902. this.autoClearColor = true;
  12903. this.autoClearDepth = true;
  12904. this.autoClearStencil = true;
  12905. // scene graph
  12906. this.sortObjects = true;
  12907. // user-defined clipping
  12908. this.clippingPlanes = [];
  12909. this.localClippingEnabled = false;
  12910. // physically based shading
  12911. this.gammaFactor = 2.0; // for backwards compatibility
  12912. this.gammaInput = false;
  12913. this.gammaOutput = false;
  12914. // physical lights
  12915. this.physicallyCorrectLights = false;
  12916. // tone mapping
  12917. this.toneMapping = LinearToneMapping;
  12918. this.toneMappingExposure = 1.0;
  12919. this.toneMappingWhitePoint = 1.0;
  12920. // morphs
  12921. this.maxMorphTargets = 8;
  12922. this.maxMorphNormals = 4;
  12923. // internal properties
  12924. var _this = this,
  12925. _isContextLost = false,
  12926. // internal state cache
  12927. _framebuffer = null,
  12928. _currentRenderTarget = null,
  12929. _currentFramebuffer = null,
  12930. _currentMaterialId = - 1,
  12931. _currentGeometryProgram = '',
  12932. _currentCamera = null,
  12933. _currentArrayCamera = null,
  12934. _currentViewport = new Vector4(),
  12935. _currentScissor = new Vector4(),
  12936. _currentScissorTest = null,
  12937. //
  12938. _usedTextureUnits = 0,
  12939. //
  12940. _width = _canvas.width,
  12941. _height = _canvas.height,
  12942. _pixelRatio = 1,
  12943. _viewport = new Vector4( 0, 0, _width, _height ),
  12944. _scissor = new Vector4( 0, 0, _width, _height ),
  12945. _scissorTest = false,
  12946. // frustum
  12947. _frustum = new Frustum(),
  12948. // clipping
  12949. _clipping = new WebGLClipping(),
  12950. _clippingEnabled = false,
  12951. _localClippingEnabled = false,
  12952. // camera matrices cache
  12953. _projScreenMatrix = new Matrix4(),
  12954. _vector3 = new Vector3();
  12955. function getTargetPixelRatio() {
  12956. return _currentRenderTarget === null ? _pixelRatio : 1;
  12957. }
  12958. // initialize
  12959. var _gl;
  12960. try {
  12961. var contextAttributes = {
  12962. alpha: _alpha,
  12963. depth: _depth,
  12964. stencil: _stencil,
  12965. antialias: _antialias,
  12966. premultipliedAlpha: _premultipliedAlpha,
  12967. preserveDrawingBuffer: _preserveDrawingBuffer,
  12968. powerPreference: _powerPreference
  12969. };
  12970. // event listeners must be registered before WebGL context is created, see #12753
  12971. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  12972. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  12973. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  12974. if ( _gl === null ) {
  12975. if ( _canvas.getContext( 'webgl' ) !== null ) {
  12976. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  12977. } else {
  12978. throw new Error( 'Error creating WebGL context.' );
  12979. }
  12980. }
  12981. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  12982. if ( _gl.getShaderPrecisionFormat === undefined ) {
  12983. _gl.getShaderPrecisionFormat = function () {
  12984. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  12985. };
  12986. }
  12987. } catch ( error ) {
  12988. console.error( 'THREE.WebGLRenderer: ' + error.message );
  12989. }
  12990. var extensions, capabilities, state, info;
  12991. var properties, textures, attributes, geometries, objects;
  12992. var programCache, renderLists, renderStates;
  12993. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  12994. var spriteRenderer;
  12995. var utils;
  12996. function initGLContext() {
  12997. extensions = new WebGLExtensions( _gl );
  12998. extensions.get( 'WEBGL_depth_texture' );
  12999. extensions.get( 'OES_texture_float' );
  13000. extensions.get( 'OES_texture_float_linear' );
  13001. extensions.get( 'OES_texture_half_float' );
  13002. extensions.get( 'OES_texture_half_float_linear' );
  13003. extensions.get( 'OES_standard_derivatives' );
  13004. extensions.get( 'OES_element_index_uint' );
  13005. extensions.get( 'ANGLE_instanced_arrays' );
  13006. utils = new WebGLUtils( _gl, extensions );
  13007. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  13008. state = new WebGLState( _gl, extensions, utils );
  13009. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  13010. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  13011. info = new WebGLInfo( _gl );
  13012. properties = new WebGLProperties();
  13013. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  13014. attributes = new WebGLAttributes( _gl );
  13015. geometries = new WebGLGeometries( _gl, attributes, info );
  13016. objects = new WebGLObjects( geometries, info );
  13017. morphtargets = new WebGLMorphtargets( _gl );
  13018. programCache = new WebGLPrograms( _this, extensions, capabilities );
  13019. renderLists = new WebGLRenderLists();
  13020. renderStates = new WebGLRenderStates();
  13021. background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
  13022. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info );
  13023. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info );
  13024. spriteRenderer = new WebGLSpriteRenderer( _this, _gl, state, textures, capabilities );
  13025. info.programs = programCache.programs;
  13026. _this.context = _gl;
  13027. _this.capabilities = capabilities;
  13028. _this.extensions = extensions;
  13029. _this.properties = properties;
  13030. _this.renderLists = renderLists;
  13031. _this.state = state;
  13032. _this.info = info;
  13033. }
  13034. initGLContext();
  13035. // vr
  13036. var vr = ( 'xr' in navigator ) ? new WebXRManager( _this ) : new WebVRManager( _this );
  13037. this.vr = vr;
  13038. // shadow map
  13039. var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  13040. this.shadowMap = shadowMap;
  13041. // API
  13042. this.getContext = function () {
  13043. return _gl;
  13044. };
  13045. this.getContextAttributes = function () {
  13046. return _gl.getContextAttributes();
  13047. };
  13048. this.forceContextLoss = function () {
  13049. var extension = extensions.get( 'WEBGL_lose_context' );
  13050. if ( extension ) extension.loseContext();
  13051. };
  13052. this.forceContextRestore = function () {
  13053. var extension = extensions.get( 'WEBGL_lose_context' );
  13054. if ( extension ) extension.restoreContext();
  13055. };
  13056. this.getPixelRatio = function () {
  13057. return _pixelRatio;
  13058. };
  13059. this.setPixelRatio = function ( value ) {
  13060. if ( value === undefined ) return;
  13061. _pixelRatio = value;
  13062. this.setSize( _width, _height, false );
  13063. };
  13064. this.getSize = function () {
  13065. return {
  13066. width: _width,
  13067. height: _height
  13068. };
  13069. };
  13070. this.setSize = function ( width, height, updateStyle ) {
  13071. if ( vr.isPresenting() ) {
  13072. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  13073. return;
  13074. }
  13075. _width = width;
  13076. _height = height;
  13077. _canvas.width = width * _pixelRatio;
  13078. _canvas.height = height * _pixelRatio;
  13079. if ( updateStyle !== false ) {
  13080. _canvas.style.width = width + 'px';
  13081. _canvas.style.height = height + 'px';
  13082. }
  13083. this.setViewport( 0, 0, width, height );
  13084. };
  13085. this.getDrawingBufferSize = function () {
  13086. return {
  13087. width: _width * _pixelRatio,
  13088. height: _height * _pixelRatio
  13089. };
  13090. };
  13091. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  13092. _width = width;
  13093. _height = height;
  13094. _pixelRatio = pixelRatio;
  13095. _canvas.width = width * pixelRatio;
  13096. _canvas.height = height * pixelRatio;
  13097. this.setViewport( 0, 0, width, height );
  13098. };
  13099. this.getCurrentViewport = function () {
  13100. return _currentViewport;
  13101. };
  13102. this.setViewport = function ( x, y, width, height ) {
  13103. _viewport.set( x, _height - y - height, width, height );
  13104. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  13105. };
  13106. this.setScissor = function ( x, y, width, height ) {
  13107. _scissor.set( x, _height - y - height, width, height );
  13108. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  13109. };
  13110. this.setScissorTest = function ( boolean ) {
  13111. state.setScissorTest( _scissorTest = boolean );
  13112. };
  13113. // Clearing
  13114. this.getClearColor = function () {
  13115. return background.getClearColor();
  13116. };
  13117. this.setClearColor = function () {
  13118. background.setClearColor.apply( background, arguments );
  13119. };
  13120. this.getClearAlpha = function () {
  13121. return background.getClearAlpha();
  13122. };
  13123. this.setClearAlpha = function () {
  13124. background.setClearAlpha.apply( background, arguments );
  13125. };
  13126. this.clear = function ( color, depth, stencil ) {
  13127. var bits = 0;
  13128. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  13129. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  13130. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  13131. _gl.clear( bits );
  13132. };
  13133. this.clearColor = function () {
  13134. this.clear( true, false, false );
  13135. };
  13136. this.clearDepth = function () {
  13137. this.clear( false, true, false );
  13138. };
  13139. this.clearStencil = function () {
  13140. this.clear( false, false, true );
  13141. };
  13142. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  13143. this.setRenderTarget( renderTarget );
  13144. this.clear( color, depth, stencil );
  13145. };
  13146. //
  13147. this.dispose = function () {
  13148. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  13149. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  13150. renderLists.dispose();
  13151. renderStates.dispose();
  13152. properties.dispose();
  13153. objects.dispose();
  13154. vr.dispose();
  13155. animation.stop();
  13156. };
  13157. // Events
  13158. function onContextLost( event ) {
  13159. event.preventDefault();
  13160. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  13161. _isContextLost = true;
  13162. }
  13163. function onContextRestore( /* event */ ) {
  13164. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  13165. _isContextLost = false;
  13166. initGLContext();
  13167. }
  13168. function onMaterialDispose( event ) {
  13169. var material = event.target;
  13170. material.removeEventListener( 'dispose', onMaterialDispose );
  13171. deallocateMaterial( material );
  13172. }
  13173. // Buffer deallocation
  13174. function deallocateMaterial( material ) {
  13175. releaseMaterialProgramReference( material );
  13176. properties.remove( material );
  13177. }
  13178. function releaseMaterialProgramReference( material ) {
  13179. var programInfo = properties.get( material ).program;
  13180. material.program = undefined;
  13181. if ( programInfo !== undefined ) {
  13182. programCache.releaseProgram( programInfo );
  13183. }
  13184. }
  13185. // Buffer rendering
  13186. function renderObjectImmediate( object, program, material ) {
  13187. object.render( function ( object ) {
  13188. _this.renderBufferImmediate( object, program, material );
  13189. } );
  13190. }
  13191. this.renderBufferImmediate = function ( object, program, material ) {
  13192. state.initAttributes();
  13193. var buffers = properties.get( object );
  13194. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  13195. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  13196. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  13197. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  13198. var programAttributes = program.getAttributes();
  13199. if ( object.hasPositions ) {
  13200. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  13201. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  13202. state.enableAttribute( programAttributes.position );
  13203. _gl.vertexAttribPointer( programAttributes.position, 3, _gl.FLOAT, false, 0, 0 );
  13204. }
  13205. if ( object.hasNormals ) {
  13206. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  13207. if ( ! material.isMeshPhongMaterial &&
  13208. ! material.isMeshStandardMaterial &&
  13209. ! material.isMeshNormalMaterial &&
  13210. material.flatShading === true ) {
  13211. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  13212. var array = object.normalArray;
  13213. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  13214. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  13215. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  13216. array[ i + 0 ] = nx;
  13217. array[ i + 1 ] = ny;
  13218. array[ i + 2 ] = nz;
  13219. array[ i + 3 ] = nx;
  13220. array[ i + 4 ] = ny;
  13221. array[ i + 5 ] = nz;
  13222. array[ i + 6 ] = nx;
  13223. array[ i + 7 ] = ny;
  13224. array[ i + 8 ] = nz;
  13225. }
  13226. }
  13227. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  13228. state.enableAttribute( programAttributes.normal );
  13229. _gl.vertexAttribPointer( programAttributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  13230. }
  13231. if ( object.hasUvs && material.map ) {
  13232. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  13233. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  13234. state.enableAttribute( programAttributes.uv );
  13235. _gl.vertexAttribPointer( programAttributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  13236. }
  13237. if ( object.hasColors && material.vertexColors !== NoColors ) {
  13238. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  13239. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  13240. state.enableAttribute( programAttributes.color );
  13241. _gl.vertexAttribPointer( programAttributes.color, 3, _gl.FLOAT, false, 0, 0 );
  13242. }
  13243. state.disableUnusedAttributes();
  13244. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  13245. object.count = 0;
  13246. };
  13247. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  13248. var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  13249. state.setMaterial( material, frontFaceCW );
  13250. var program = setProgram( camera, fog, material, object );
  13251. var geometryProgram = geometry.id + '_' + program.id + '_' + ( material.wireframe === true );
  13252. var updateBuffers = false;
  13253. if ( geometryProgram !== _currentGeometryProgram ) {
  13254. _currentGeometryProgram = geometryProgram;
  13255. updateBuffers = true;
  13256. }
  13257. if ( object.morphTargetInfluences ) {
  13258. morphtargets.update( object, geometry, material, program );
  13259. updateBuffers = true;
  13260. }
  13261. //
  13262. var index = geometry.index;
  13263. var position = geometry.attributes.position;
  13264. var rangeFactor = 1;
  13265. if ( material.wireframe === true ) {
  13266. index = geometries.getWireframeAttribute( geometry );
  13267. rangeFactor = 2;
  13268. }
  13269. var attribute;
  13270. var renderer = bufferRenderer;
  13271. if ( index !== null ) {
  13272. attribute = attributes.get( index );
  13273. renderer = indexedBufferRenderer;
  13274. renderer.setIndex( attribute );
  13275. }
  13276. if ( updateBuffers ) {
  13277. setupVertexAttributes( material, program, geometry );
  13278. if ( index !== null ) {
  13279. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, attribute.buffer );
  13280. }
  13281. }
  13282. //
  13283. var dataCount = Infinity;
  13284. if ( index !== null ) {
  13285. dataCount = index.count;
  13286. } else if ( position !== undefined ) {
  13287. dataCount = position.count;
  13288. }
  13289. var rangeStart = geometry.drawRange.start * rangeFactor;
  13290. var rangeCount = geometry.drawRange.count * rangeFactor;
  13291. var groupStart = group !== null ? group.start * rangeFactor : 0;
  13292. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  13293. var drawStart = Math.max( rangeStart, groupStart );
  13294. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  13295. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  13296. if ( drawCount === 0 ) return;
  13297. //
  13298. if ( object.isMesh ) {
  13299. if ( material.wireframe === true ) {
  13300. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  13301. renderer.setMode( _gl.LINES );
  13302. } else {
  13303. switch ( object.drawMode ) {
  13304. case TrianglesDrawMode:
  13305. renderer.setMode( _gl.TRIANGLES );
  13306. break;
  13307. case TriangleStripDrawMode:
  13308. renderer.setMode( _gl.TRIANGLE_STRIP );
  13309. break;
  13310. case TriangleFanDrawMode:
  13311. renderer.setMode( _gl.TRIANGLE_FAN );
  13312. break;
  13313. }
  13314. }
  13315. } else if ( object.isLine ) {
  13316. var lineWidth = material.linewidth;
  13317. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  13318. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  13319. if ( object.isLineSegments ) {
  13320. renderer.setMode( _gl.LINES );
  13321. } else if ( object.isLineLoop ) {
  13322. renderer.setMode( _gl.LINE_LOOP );
  13323. } else {
  13324. renderer.setMode( _gl.LINE_STRIP );
  13325. }
  13326. } else if ( object.isPoints ) {
  13327. renderer.setMode( _gl.POINTS );
  13328. }
  13329. if ( geometry && geometry.isInstancedBufferGeometry ) {
  13330. if ( geometry.maxInstancedCount > 0 ) {
  13331. renderer.renderInstances( geometry, drawStart, drawCount );
  13332. }
  13333. } else {
  13334. renderer.render( drawStart, drawCount );
  13335. }
  13336. };
  13337. function setupVertexAttributes( material, program, geometry ) {
  13338. if ( geometry && geometry.isInstancedBufferGeometry ) {
  13339. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
  13340. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  13341. return;
  13342. }
  13343. }
  13344. state.initAttributes();
  13345. var geometryAttributes = geometry.attributes;
  13346. var programAttributes = program.getAttributes();
  13347. var materialDefaultAttributeValues = material.defaultAttributeValues;
  13348. for ( var name in programAttributes ) {
  13349. var programAttribute = programAttributes[ name ];
  13350. if ( programAttribute >= 0 ) {
  13351. var geometryAttribute = geometryAttributes[ name ];
  13352. if ( geometryAttribute !== undefined ) {
  13353. var normalized = geometryAttribute.normalized;
  13354. var size = geometryAttribute.itemSize;
  13355. var attribute = attributes.get( geometryAttribute );
  13356. // TODO Attribute may not be available on context restore
  13357. if ( attribute === undefined ) continue;
  13358. var buffer = attribute.buffer;
  13359. var type = attribute.type;
  13360. var bytesPerElement = attribute.bytesPerElement;
  13361. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  13362. var data = geometryAttribute.data;
  13363. var stride = data.stride;
  13364. var offset = geometryAttribute.offset;
  13365. if ( data && data.isInstancedInterleavedBuffer ) {
  13366. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  13367. if ( geometry.maxInstancedCount === undefined ) {
  13368. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  13369. }
  13370. } else {
  13371. state.enableAttribute( programAttribute );
  13372. }
  13373. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  13374. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
  13375. } else {
  13376. if ( geometryAttribute.isInstancedBufferAttribute ) {
  13377. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  13378. if ( geometry.maxInstancedCount === undefined ) {
  13379. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  13380. }
  13381. } else {
  13382. state.enableAttribute( programAttribute );
  13383. }
  13384. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  13385. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
  13386. }
  13387. } else if ( materialDefaultAttributeValues !== undefined ) {
  13388. var value = materialDefaultAttributeValues[ name ];
  13389. if ( value !== undefined ) {
  13390. switch ( value.length ) {
  13391. case 2:
  13392. _gl.vertexAttrib2fv( programAttribute, value );
  13393. break;
  13394. case 3:
  13395. _gl.vertexAttrib3fv( programAttribute, value );
  13396. break;
  13397. case 4:
  13398. _gl.vertexAttrib4fv( programAttribute, value );
  13399. break;
  13400. default:
  13401. _gl.vertexAttrib1fv( programAttribute, value );
  13402. }
  13403. }
  13404. }
  13405. }
  13406. }
  13407. state.disableUnusedAttributes();
  13408. }
  13409. // Compile
  13410. this.compile = function ( scene, camera ) {
  13411. currentRenderState = renderStates.get( scene, camera );
  13412. currentRenderState.init();
  13413. scene.traverse( function ( object ) {
  13414. if ( object.isLight ) {
  13415. currentRenderState.pushLight( object );
  13416. if ( object.castShadow ) {
  13417. currentRenderState.pushShadow( object );
  13418. }
  13419. }
  13420. } );
  13421. currentRenderState.setupLights( camera );
  13422. scene.traverse( function ( object ) {
  13423. if ( object.material ) {
  13424. if ( Array.isArray( object.material ) ) {
  13425. for ( var i = 0; i < object.material.length; i ++ ) {
  13426. initMaterial( object.material[ i ], scene.fog, object );
  13427. }
  13428. } else {
  13429. initMaterial( object.material, scene.fog, object );
  13430. }
  13431. }
  13432. } );
  13433. };
  13434. // Animation Loop
  13435. var onAnimationFrameCallback = null;
  13436. function onAnimationFrame() {
  13437. if ( vr.isPresenting() ) return;
  13438. if ( onAnimationFrameCallback ) onAnimationFrameCallback();
  13439. }
  13440. var animation = new WebGLAnimation();
  13441. animation.setAnimationLoop( onAnimationFrame );
  13442. animation.setContext( window );
  13443. this.setAnimationLoop = function ( callback ) {
  13444. onAnimationFrameCallback = callback;
  13445. vr.setAnimationLoop( callback );
  13446. animation.start();
  13447. };
  13448. // Rendering
  13449. this.render = function ( scene, camera, renderTarget, forceClear ) {
  13450. if ( ! ( camera && camera.isCamera ) ) {
  13451. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  13452. return;
  13453. }
  13454. if ( _isContextLost ) return;
  13455. // reset caching for this frame
  13456. _currentGeometryProgram = '';
  13457. _currentMaterialId = - 1;
  13458. _currentCamera = null;
  13459. // update scene graph
  13460. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  13461. // update camera matrices and frustum
  13462. if ( camera.parent === null ) camera.updateMatrixWorld();
  13463. if ( vr.enabled ) {
  13464. camera = vr.getCamera( camera );
  13465. }
  13466. //
  13467. currentRenderState = renderStates.get( scene, camera );
  13468. currentRenderState.init();
  13469. scene.onBeforeRender( _this, scene, camera, renderTarget );
  13470. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  13471. _frustum.setFromMatrix( _projScreenMatrix );
  13472. _localClippingEnabled = this.localClippingEnabled;
  13473. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  13474. currentRenderList = renderLists.get( scene, camera );
  13475. currentRenderList.init();
  13476. projectObject( scene, camera, _this.sortObjects );
  13477. if ( _this.sortObjects === true ) {
  13478. currentRenderList.sort();
  13479. }
  13480. //
  13481. if ( _clippingEnabled ) _clipping.beginShadows();
  13482. var shadowsArray = currentRenderState.state.shadowsArray;
  13483. shadowMap.render( shadowsArray, scene, camera );
  13484. currentRenderState.setupLights( camera );
  13485. if ( _clippingEnabled ) _clipping.endShadows();
  13486. //
  13487. if ( this.info.autoReset ) this.info.reset();
  13488. if ( renderTarget === undefined ) {
  13489. renderTarget = null;
  13490. }
  13491. this.setRenderTarget( renderTarget );
  13492. //
  13493. background.render( currentRenderList, scene, camera, forceClear );
  13494. // render scene
  13495. var opaqueObjects = currentRenderList.opaque;
  13496. var transparentObjects = currentRenderList.transparent;
  13497. if ( scene.overrideMaterial ) {
  13498. var overrideMaterial = scene.overrideMaterial;
  13499. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  13500. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  13501. } else {
  13502. // opaque pass (front-to-back order)
  13503. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  13504. // transparent pass (back-to-front order)
  13505. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  13506. }
  13507. // custom renderers
  13508. var spritesArray = currentRenderState.state.spritesArray;
  13509. spriteRenderer.render( spritesArray, scene, camera );
  13510. // Generate mipmap if we're using any kind of mipmap filtering
  13511. if ( renderTarget ) {
  13512. textures.updateRenderTargetMipmap( renderTarget );
  13513. }
  13514. // Ensure depth buffer writing is enabled so it can be cleared on next render
  13515. state.buffers.depth.setTest( true );
  13516. state.buffers.depth.setMask( true );
  13517. state.buffers.color.setMask( true );
  13518. state.setPolygonOffset( false );
  13519. scene.onAfterRender( _this, scene, camera );
  13520. if ( vr.enabled ) {
  13521. vr.submitFrame();
  13522. }
  13523. // _gl.finish();
  13524. currentRenderList = null;
  13525. currentRenderState = null;
  13526. };
  13527. /*
  13528. // TODO Duplicated code (Frustum)
  13529. var _sphere = new Sphere();
  13530. function isObjectViewable( object ) {
  13531. var geometry = object.geometry;
  13532. if ( geometry.boundingSphere === null )
  13533. geometry.computeBoundingSphere();
  13534. _sphere.copy( geometry.boundingSphere ).
  13535. applyMatrix4( object.matrixWorld );
  13536. return isSphereViewable( _sphere );
  13537. }
  13538. function isSpriteViewable( sprite ) {
  13539. _sphere.center.set( 0, 0, 0 );
  13540. _sphere.radius = 0.7071067811865476;
  13541. _sphere.applyMatrix4( sprite.matrixWorld );
  13542. return isSphereViewable( _sphere );
  13543. }
  13544. function isSphereViewable( sphere ) {
  13545. if ( ! _frustum.intersectsSphere( sphere ) ) return false;
  13546. var numPlanes = _clipping.numPlanes;
  13547. if ( numPlanes === 0 ) return true;
  13548. var planes = _this.clippingPlanes,
  13549. center = sphere.center,
  13550. negRad = - sphere.radius,
  13551. i = 0;
  13552. do {
  13553. // out when deeper than radius in the negative halfspace
  13554. if ( planes[ i ].distanceToPoint( center ) < negRad ) return false;
  13555. } while ( ++ i !== numPlanes );
  13556. return true;
  13557. }
  13558. */
  13559. function projectObject( object, camera, sortObjects ) {
  13560. if ( object.visible === false ) return;
  13561. var visible = object.layers.test( camera.layers );
  13562. if ( visible ) {
  13563. if ( object.isLight ) {
  13564. currentRenderState.pushLight( object );
  13565. if ( object.castShadow ) {
  13566. currentRenderState.pushShadow( object );
  13567. }
  13568. } else if ( object.isSprite ) {
  13569. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  13570. currentRenderState.pushSprite( object );
  13571. }
  13572. } else if ( object.isImmediateRenderObject ) {
  13573. if ( sortObjects ) {
  13574. _vector3.setFromMatrixPosition( object.matrixWorld )
  13575. .applyMatrix4( _projScreenMatrix );
  13576. }
  13577. currentRenderList.push( object, null, object.material, _vector3.z, null );
  13578. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  13579. if ( object.isSkinnedMesh ) {
  13580. object.skeleton.update();
  13581. }
  13582. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  13583. if ( sortObjects ) {
  13584. _vector3.setFromMatrixPosition( object.matrixWorld )
  13585. .applyMatrix4( _projScreenMatrix );
  13586. }
  13587. var geometry = objects.update( object );
  13588. var material = object.material;
  13589. if ( Array.isArray( material ) ) {
  13590. var groups = geometry.groups;
  13591. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  13592. var group = groups[ i ];
  13593. var groupMaterial = material[ group.materialIndex ];
  13594. if ( groupMaterial && groupMaterial.visible ) {
  13595. currentRenderList.push( object, geometry, groupMaterial, _vector3.z, group );
  13596. }
  13597. }
  13598. } else if ( material.visible ) {
  13599. currentRenderList.push( object, geometry, material, _vector3.z, null );
  13600. }
  13601. }
  13602. }
  13603. }
  13604. var children = object.children;
  13605. for ( var i = 0, l = children.length; i < l; i ++ ) {
  13606. projectObject( children[ i ], camera, sortObjects );
  13607. }
  13608. }
  13609. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  13610. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  13611. var renderItem = renderList[ i ];
  13612. var object = renderItem.object;
  13613. var geometry = renderItem.geometry;
  13614. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  13615. var group = renderItem.group;
  13616. if ( camera.isArrayCamera ) {
  13617. _currentArrayCamera = camera;
  13618. var cameras = camera.cameras;
  13619. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  13620. var camera2 = cameras[ j ];
  13621. if ( object.layers.test( camera2.layers ) ) {
  13622. if ( 'viewport' in camera2 ) { // XR
  13623. state.viewport( _currentViewport.copy( camera2.viewport ) );
  13624. } else {
  13625. var bounds = camera2.bounds;
  13626. var x = bounds.x * _width;
  13627. var y = bounds.y * _height;
  13628. var width = bounds.z * _width;
  13629. var height = bounds.w * _height;
  13630. state.viewport( _currentViewport.set( x, y, width, height ).multiplyScalar( _pixelRatio ) );
  13631. }
  13632. renderObject( object, scene, camera2, geometry, material, group );
  13633. }
  13634. }
  13635. } else {
  13636. _currentArrayCamera = null;
  13637. renderObject( object, scene, camera, geometry, material, group );
  13638. }
  13639. }
  13640. }
  13641. function renderObject( object, scene, camera, geometry, material, group ) {
  13642. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  13643. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  13644. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  13645. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  13646. if ( object.isImmediateRenderObject ) {
  13647. var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  13648. state.setMaterial( material, frontFaceCW );
  13649. var program = setProgram( camera, scene.fog, material, object );
  13650. _currentGeometryProgram = '';
  13651. renderObjectImmediate( object, program, material );
  13652. } else {
  13653. _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
  13654. }
  13655. object.onAfterRender( _this, scene, camera, geometry, material, group );
  13656. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  13657. }
  13658. function initMaterial( material, fog, object ) {
  13659. var materialProperties = properties.get( material );
  13660. var lights = currentRenderState.state.lights;
  13661. var shadowsArray = currentRenderState.state.shadowsArray;
  13662. var parameters = programCache.getParameters(
  13663. material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );
  13664. var code = programCache.getProgramCode( material, parameters );
  13665. var program = materialProperties.program;
  13666. var programChange = true;
  13667. if ( program === undefined ) {
  13668. // new material
  13669. material.addEventListener( 'dispose', onMaterialDispose );
  13670. } else if ( program.code !== code ) {
  13671. // changed glsl or parameters
  13672. releaseMaterialProgramReference( material );
  13673. } else if ( materialProperties.lightsHash !== lights.state.hash ) {
  13674. properties.update( material, 'lightsHash', lights.state.hash );
  13675. programChange = false;
  13676. } else if ( parameters.shaderID !== undefined ) {
  13677. // same glsl and uniform list
  13678. return;
  13679. } else {
  13680. // only rebuild uniform list
  13681. programChange = false;
  13682. }
  13683. if ( programChange ) {
  13684. if ( parameters.shaderID ) {
  13685. var shader = ShaderLib[ parameters.shaderID ];
  13686. materialProperties.shader = {
  13687. name: material.type,
  13688. uniforms: UniformsUtils.clone( shader.uniforms ),
  13689. vertexShader: shader.vertexShader,
  13690. fragmentShader: shader.fragmentShader
  13691. };
  13692. } else {
  13693. materialProperties.shader = {
  13694. name: material.type,
  13695. uniforms: material.uniforms,
  13696. vertexShader: material.vertexShader,
  13697. fragmentShader: material.fragmentShader
  13698. };
  13699. }
  13700. material.onBeforeCompile( materialProperties.shader, _this );
  13701. program = programCache.acquireProgram( material, materialProperties.shader, parameters, code );
  13702. materialProperties.program = program;
  13703. material.program = program;
  13704. }
  13705. var programAttributes = program.getAttributes();
  13706. if ( material.morphTargets ) {
  13707. material.numSupportedMorphTargets = 0;
  13708. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  13709. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  13710. material.numSupportedMorphTargets ++;
  13711. }
  13712. }
  13713. }
  13714. if ( material.morphNormals ) {
  13715. material.numSupportedMorphNormals = 0;
  13716. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  13717. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  13718. material.numSupportedMorphNormals ++;
  13719. }
  13720. }
  13721. }
  13722. var uniforms = materialProperties.shader.uniforms;
  13723. if ( ! material.isShaderMaterial &&
  13724. ! material.isRawShaderMaterial ||
  13725. material.clipping === true ) {
  13726. materialProperties.numClippingPlanes = _clipping.numPlanes;
  13727. materialProperties.numIntersection = _clipping.numIntersection;
  13728. uniforms.clippingPlanes = _clipping.uniform;
  13729. }
  13730. materialProperties.fog = fog;
  13731. // store the light setup it was created for
  13732. materialProperties.lightsHash = lights.state.hash;
  13733. if ( material.lights ) {
  13734. // wire up the material to this renderer's lighting state
  13735. uniforms.ambientLightColor.value = lights.state.ambient;
  13736. uniforms.directionalLights.value = lights.state.directional;
  13737. uniforms.spotLights.value = lights.state.spot;
  13738. uniforms.rectAreaLights.value = lights.state.rectArea;
  13739. uniforms.pointLights.value = lights.state.point;
  13740. uniforms.hemisphereLights.value = lights.state.hemi;
  13741. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  13742. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  13743. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  13744. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  13745. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  13746. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  13747. // TODO (abelnation): add area lights shadow info to uniforms
  13748. }
  13749. var progUniforms = materialProperties.program.getUniforms(),
  13750. uniformsList =
  13751. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  13752. materialProperties.uniformsList = uniformsList;
  13753. }
  13754. function setProgram( camera, fog, material, object ) {
  13755. _usedTextureUnits = 0;
  13756. var materialProperties = properties.get( material );
  13757. var lights = currentRenderState.state.lights;
  13758. if ( _clippingEnabled ) {
  13759. if ( _localClippingEnabled || camera !== _currentCamera ) {
  13760. var useCache =
  13761. camera === _currentCamera &&
  13762. material.id === _currentMaterialId;
  13763. // we might want to call this function with some ClippingGroup
  13764. // object instead of the material, once it becomes feasible
  13765. // (#8465, #8379)
  13766. _clipping.setState(
  13767. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  13768. camera, materialProperties, useCache );
  13769. }
  13770. }
  13771. if ( material.needsUpdate === false ) {
  13772. if ( materialProperties.program === undefined ) {
  13773. material.needsUpdate = true;
  13774. } else if ( material.fog && materialProperties.fog !== fog ) {
  13775. material.needsUpdate = true;
  13776. } else if ( material.lights && materialProperties.lightsHash !== lights.state.hash ) {
  13777. material.needsUpdate = true;
  13778. } else if ( materialProperties.numClippingPlanes !== undefined &&
  13779. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  13780. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  13781. material.needsUpdate = true;
  13782. }
  13783. }
  13784. if ( material.needsUpdate ) {
  13785. initMaterial( material, fog, object );
  13786. material.needsUpdate = false;
  13787. }
  13788. var refreshProgram = false;
  13789. var refreshMaterial = false;
  13790. var refreshLights = false;
  13791. var program = materialProperties.program,
  13792. p_uniforms = program.getUniforms(),
  13793. m_uniforms = materialProperties.shader.uniforms;
  13794. if ( state.useProgram( program.program ) ) {
  13795. refreshProgram = true;
  13796. refreshMaterial = true;
  13797. refreshLights = true;
  13798. }
  13799. if ( material.id !== _currentMaterialId ) {
  13800. _currentMaterialId = material.id;
  13801. refreshMaterial = true;
  13802. }
  13803. if ( refreshProgram || camera !== _currentCamera ) {
  13804. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  13805. if ( capabilities.logarithmicDepthBuffer ) {
  13806. p_uniforms.setValue( _gl, 'logDepthBufFC',
  13807. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  13808. }
  13809. // Avoid unneeded uniform updates per ArrayCamera's sub-camera
  13810. if ( _currentCamera !== ( _currentArrayCamera || camera ) ) {
  13811. _currentCamera = ( _currentArrayCamera || camera );
  13812. // lighting uniforms depend on the camera so enforce an update
  13813. // now, in case this material supports lights - or later, when
  13814. // the next material that does gets activated:
  13815. refreshMaterial = true; // set to true on material change
  13816. refreshLights = true; // remains set until update done
  13817. }
  13818. // load material specific uniforms
  13819. // (shader material also gets them for the sake of genericity)
  13820. if ( material.isShaderMaterial ||
  13821. material.isMeshPhongMaterial ||
  13822. material.isMeshStandardMaterial ||
  13823. material.envMap ) {
  13824. var uCamPos = p_uniforms.map.cameraPosition;
  13825. if ( uCamPos !== undefined ) {
  13826. uCamPos.setValue( _gl,
  13827. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  13828. }
  13829. }
  13830. if ( material.isMeshPhongMaterial ||
  13831. material.isMeshLambertMaterial ||
  13832. material.isMeshBasicMaterial ||
  13833. material.isMeshStandardMaterial ||
  13834. material.isShaderMaterial ||
  13835. material.skinning ) {
  13836. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  13837. }
  13838. }
  13839. // skinning uniforms must be set even if material didn't change
  13840. // auto-setting of texture unit for bone texture must go before other textures
  13841. // not sure why, but otherwise weird things happen
  13842. if ( material.skinning ) {
  13843. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  13844. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  13845. var skeleton = object.skeleton;
  13846. if ( skeleton ) {
  13847. var bones = skeleton.bones;
  13848. if ( capabilities.floatVertexTextures ) {
  13849. if ( skeleton.boneTexture === undefined ) {
  13850. // layout (1 matrix = 4 pixels)
  13851. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  13852. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  13853. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  13854. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  13855. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  13856. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  13857. size = _Math.ceilPowerOfTwo( size );
  13858. size = Math.max( size, 4 );
  13859. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  13860. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  13861. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  13862. boneTexture.needsUpdate = true;
  13863. skeleton.boneMatrices = boneMatrices;
  13864. skeleton.boneTexture = boneTexture;
  13865. skeleton.boneTextureSize = size;
  13866. }
  13867. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture );
  13868. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  13869. } else {
  13870. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  13871. }
  13872. }
  13873. }
  13874. if ( refreshMaterial ) {
  13875. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  13876. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  13877. if ( material.lights ) {
  13878. // the current material requires lighting info
  13879. // note: all lighting uniforms are always set correctly
  13880. // they simply reference the renderer's state for their
  13881. // values
  13882. //
  13883. // use the current material's .needsUpdate flags to set
  13884. // the GL state when required
  13885. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  13886. }
  13887. // refresh uniforms common to several materials
  13888. if ( fog && material.fog ) {
  13889. refreshUniformsFog( m_uniforms, fog );
  13890. }
  13891. if ( material.isMeshBasicMaterial ) {
  13892. refreshUniformsCommon( m_uniforms, material );
  13893. } else if ( material.isMeshLambertMaterial ) {
  13894. refreshUniformsCommon( m_uniforms, material );
  13895. refreshUniformsLambert( m_uniforms, material );
  13896. } else if ( material.isMeshPhongMaterial ) {
  13897. refreshUniformsCommon( m_uniforms, material );
  13898. if ( material.isMeshToonMaterial ) {
  13899. refreshUniformsToon( m_uniforms, material );
  13900. } else {
  13901. refreshUniformsPhong( m_uniforms, material );
  13902. }
  13903. } else if ( material.isMeshStandardMaterial ) {
  13904. refreshUniformsCommon( m_uniforms, material );
  13905. if ( material.isMeshPhysicalMaterial ) {
  13906. refreshUniformsPhysical( m_uniforms, material );
  13907. } else {
  13908. refreshUniformsStandard( m_uniforms, material );
  13909. }
  13910. } else if ( material.isMeshDepthMaterial ) {
  13911. refreshUniformsCommon( m_uniforms, material );
  13912. refreshUniformsDepth( m_uniforms, material );
  13913. } else if ( material.isMeshDistanceMaterial ) {
  13914. refreshUniformsCommon( m_uniforms, material );
  13915. refreshUniformsDistance( m_uniforms, material );
  13916. } else if ( material.isMeshNormalMaterial ) {
  13917. refreshUniformsCommon( m_uniforms, material );
  13918. refreshUniformsNormal( m_uniforms, material );
  13919. } else if ( material.isLineBasicMaterial ) {
  13920. refreshUniformsLine( m_uniforms, material );
  13921. if ( material.isLineDashedMaterial ) {
  13922. refreshUniformsDash( m_uniforms, material );
  13923. }
  13924. } else if ( material.isPointsMaterial ) {
  13925. refreshUniformsPoints( m_uniforms, material );
  13926. } else if ( material.isShadowMaterial ) {
  13927. m_uniforms.color.value = material.color;
  13928. m_uniforms.opacity.value = material.opacity;
  13929. }
  13930. // RectAreaLight Texture
  13931. // TODO (mrdoob): Find a nicer implementation
  13932. if ( m_uniforms.ltc_1 !== undefined ) m_uniforms.ltc_1.value = UniformsLib.LTC_1;
  13933. if ( m_uniforms.ltc_2 !== undefined ) m_uniforms.ltc_2.value = UniformsLib.LTC_2;
  13934. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, _this );
  13935. }
  13936. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  13937. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, _this );
  13938. material.uniformsNeedUpdate = false;
  13939. }
  13940. // common matrices
  13941. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  13942. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  13943. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  13944. return program;
  13945. }
  13946. // Uniforms (refresh uniforms objects)
  13947. function refreshUniformsCommon( uniforms, material ) {
  13948. uniforms.opacity.value = material.opacity;
  13949. if ( material.color ) {
  13950. uniforms.diffuse.value = material.color;
  13951. }
  13952. if ( material.emissive ) {
  13953. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  13954. }
  13955. if ( material.map ) {
  13956. uniforms.map.value = material.map;
  13957. }
  13958. if ( material.alphaMap ) {
  13959. uniforms.alphaMap.value = material.alphaMap;
  13960. }
  13961. if ( material.specularMap ) {
  13962. uniforms.specularMap.value = material.specularMap;
  13963. }
  13964. if ( material.envMap ) {
  13965. uniforms.envMap.value = material.envMap;
  13966. // don't flip CubeTexture envMaps, flip everything else:
  13967. // WebGLRenderTargetCube will be flipped for backwards compatibility
  13968. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  13969. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  13970. uniforms.flipEnvMap.value = ( ! ( material.envMap && material.envMap.isCubeTexture ) ) ? 1 : - 1;
  13971. uniforms.reflectivity.value = material.reflectivity;
  13972. uniforms.refractionRatio.value = material.refractionRatio;
  13973. uniforms.maxMipLevel.value = properties.get( material.envMap ).__maxMipLevel;
  13974. }
  13975. if ( material.lightMap ) {
  13976. uniforms.lightMap.value = material.lightMap;
  13977. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  13978. }
  13979. if ( material.aoMap ) {
  13980. uniforms.aoMap.value = material.aoMap;
  13981. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13982. }
  13983. // uv repeat and offset setting priorities
  13984. // 1. color map
  13985. // 2. specular map
  13986. // 3. normal map
  13987. // 4. bump map
  13988. // 5. alpha map
  13989. // 6. emissive map
  13990. var uvScaleMap;
  13991. if ( material.map ) {
  13992. uvScaleMap = material.map;
  13993. } else if ( material.specularMap ) {
  13994. uvScaleMap = material.specularMap;
  13995. } else if ( material.displacementMap ) {
  13996. uvScaleMap = material.displacementMap;
  13997. } else if ( material.normalMap ) {
  13998. uvScaleMap = material.normalMap;
  13999. } else if ( material.bumpMap ) {
  14000. uvScaleMap = material.bumpMap;
  14001. } else if ( material.roughnessMap ) {
  14002. uvScaleMap = material.roughnessMap;
  14003. } else if ( material.metalnessMap ) {
  14004. uvScaleMap = material.metalnessMap;
  14005. } else if ( material.alphaMap ) {
  14006. uvScaleMap = material.alphaMap;
  14007. } else if ( material.emissiveMap ) {
  14008. uvScaleMap = material.emissiveMap;
  14009. }
  14010. if ( uvScaleMap !== undefined ) {
  14011. // backwards compatibility
  14012. if ( uvScaleMap.isWebGLRenderTarget ) {
  14013. uvScaleMap = uvScaleMap.texture;
  14014. }
  14015. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14016. uvScaleMap.updateMatrix();
  14017. }
  14018. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14019. }
  14020. }
  14021. function refreshUniformsLine( uniforms, material ) {
  14022. uniforms.diffuse.value = material.color;
  14023. uniforms.opacity.value = material.opacity;
  14024. }
  14025. function refreshUniformsDash( uniforms, material ) {
  14026. uniforms.dashSize.value = material.dashSize;
  14027. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14028. uniforms.scale.value = material.scale;
  14029. }
  14030. function refreshUniformsPoints( uniforms, material ) {
  14031. uniforms.diffuse.value = material.color;
  14032. uniforms.opacity.value = material.opacity;
  14033. uniforms.size.value = material.size * _pixelRatio;
  14034. uniforms.scale.value = _height * 0.5;
  14035. uniforms.map.value = material.map;
  14036. if ( material.map !== null ) {
  14037. if ( material.map.matrixAutoUpdate === true ) {
  14038. material.map.updateMatrix();
  14039. }
  14040. uniforms.uvTransform.value.copy( material.map.matrix );
  14041. }
  14042. }
  14043. function refreshUniformsFog( uniforms, fog ) {
  14044. uniforms.fogColor.value = fog.color;
  14045. if ( fog.isFog ) {
  14046. uniforms.fogNear.value = fog.near;
  14047. uniforms.fogFar.value = fog.far;
  14048. } else if ( fog.isFogExp2 ) {
  14049. uniforms.fogDensity.value = fog.density;
  14050. }
  14051. }
  14052. function refreshUniformsLambert( uniforms, material ) {
  14053. if ( material.emissiveMap ) {
  14054. uniforms.emissiveMap.value = material.emissiveMap;
  14055. }
  14056. }
  14057. function refreshUniformsPhong( uniforms, material ) {
  14058. uniforms.specular.value = material.specular;
  14059. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  14060. if ( material.emissiveMap ) {
  14061. uniforms.emissiveMap.value = material.emissiveMap;
  14062. }
  14063. if ( material.bumpMap ) {
  14064. uniforms.bumpMap.value = material.bumpMap;
  14065. uniforms.bumpScale.value = material.bumpScale;
  14066. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14067. }
  14068. if ( material.normalMap ) {
  14069. uniforms.normalMap.value = material.normalMap;
  14070. uniforms.normalScale.value.copy( material.normalScale );
  14071. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14072. }
  14073. if ( material.displacementMap ) {
  14074. uniforms.displacementMap.value = material.displacementMap;
  14075. uniforms.displacementScale.value = material.displacementScale;
  14076. uniforms.displacementBias.value = material.displacementBias;
  14077. }
  14078. }
  14079. function refreshUniformsToon( uniforms, material ) {
  14080. refreshUniformsPhong( uniforms, material );
  14081. if ( material.gradientMap ) {
  14082. uniforms.gradientMap.value = material.gradientMap;
  14083. }
  14084. }
  14085. function refreshUniformsStandard( uniforms, material ) {
  14086. uniforms.roughness.value = material.roughness;
  14087. uniforms.metalness.value = material.metalness;
  14088. if ( material.roughnessMap ) {
  14089. uniforms.roughnessMap.value = material.roughnessMap;
  14090. }
  14091. if ( material.metalnessMap ) {
  14092. uniforms.metalnessMap.value = material.metalnessMap;
  14093. }
  14094. if ( material.emissiveMap ) {
  14095. uniforms.emissiveMap.value = material.emissiveMap;
  14096. }
  14097. if ( material.bumpMap ) {
  14098. uniforms.bumpMap.value = material.bumpMap;
  14099. uniforms.bumpScale.value = material.bumpScale;
  14100. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14101. }
  14102. if ( material.normalMap ) {
  14103. uniforms.normalMap.value = material.normalMap;
  14104. uniforms.normalScale.value.copy( material.normalScale );
  14105. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14106. }
  14107. if ( material.displacementMap ) {
  14108. uniforms.displacementMap.value = material.displacementMap;
  14109. uniforms.displacementScale.value = material.displacementScale;
  14110. uniforms.displacementBias.value = material.displacementBias;
  14111. }
  14112. if ( material.envMap ) {
  14113. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14114. uniforms.envMapIntensity.value = material.envMapIntensity;
  14115. }
  14116. }
  14117. function refreshUniformsPhysical( uniforms, material ) {
  14118. uniforms.clearCoat.value = material.clearCoat;
  14119. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  14120. refreshUniformsStandard( uniforms, material );
  14121. }
  14122. function refreshUniformsDepth( uniforms, material ) {
  14123. if ( material.displacementMap ) {
  14124. uniforms.displacementMap.value = material.displacementMap;
  14125. uniforms.displacementScale.value = material.displacementScale;
  14126. uniforms.displacementBias.value = material.displacementBias;
  14127. }
  14128. }
  14129. function refreshUniformsDistance( uniforms, material ) {
  14130. if ( material.displacementMap ) {
  14131. uniforms.displacementMap.value = material.displacementMap;
  14132. uniforms.displacementScale.value = material.displacementScale;
  14133. uniforms.displacementBias.value = material.displacementBias;
  14134. }
  14135. uniforms.referencePosition.value.copy( material.referencePosition );
  14136. uniforms.nearDistance.value = material.nearDistance;
  14137. uniforms.farDistance.value = material.farDistance;
  14138. }
  14139. function refreshUniformsNormal( uniforms, material ) {
  14140. if ( material.bumpMap ) {
  14141. uniforms.bumpMap.value = material.bumpMap;
  14142. uniforms.bumpScale.value = material.bumpScale;
  14143. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14144. }
  14145. if ( material.normalMap ) {
  14146. uniforms.normalMap.value = material.normalMap;
  14147. uniforms.normalScale.value.copy( material.normalScale );
  14148. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14149. }
  14150. if ( material.displacementMap ) {
  14151. uniforms.displacementMap.value = material.displacementMap;
  14152. uniforms.displacementScale.value = material.displacementScale;
  14153. uniforms.displacementBias.value = material.displacementBias;
  14154. }
  14155. }
  14156. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  14157. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  14158. uniforms.ambientLightColor.needsUpdate = value;
  14159. uniforms.directionalLights.needsUpdate = value;
  14160. uniforms.pointLights.needsUpdate = value;
  14161. uniforms.spotLights.needsUpdate = value;
  14162. uniforms.rectAreaLights.needsUpdate = value;
  14163. uniforms.hemisphereLights.needsUpdate = value;
  14164. }
  14165. // Textures
  14166. function allocTextureUnit() {
  14167. var textureUnit = _usedTextureUnits;
  14168. if ( textureUnit >= capabilities.maxTextures ) {
  14169. console.warn( 'THREE.WebGLRenderer: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  14170. }
  14171. _usedTextureUnits += 1;
  14172. return textureUnit;
  14173. }
  14174. this.allocTextureUnit = allocTextureUnit;
  14175. // this.setTexture2D = setTexture2D;
  14176. this.setTexture2D = ( function () {
  14177. var warned = false;
  14178. // backwards compatibility: peel texture.texture
  14179. return function setTexture2D( texture, slot ) {
  14180. if ( texture && texture.isWebGLRenderTarget ) {
  14181. if ( ! warned ) {
  14182. console.warn( "THREE.WebGLRenderer.setTexture2D: don't use render targets as textures. Use their .texture property instead." );
  14183. warned = true;
  14184. }
  14185. texture = texture.texture;
  14186. }
  14187. textures.setTexture2D( texture, slot );
  14188. };
  14189. }() );
  14190. this.setTexture = ( function () {
  14191. var warned = false;
  14192. return function setTexture( texture, slot ) {
  14193. if ( ! warned ) {
  14194. console.warn( "THREE.WebGLRenderer: .setTexture is deprecated, use setTexture2D instead." );
  14195. warned = true;
  14196. }
  14197. textures.setTexture2D( texture, slot );
  14198. };
  14199. }() );
  14200. this.setTextureCube = ( function () {
  14201. var warned = false;
  14202. return function setTextureCube( texture, slot ) {
  14203. // backwards compatibility: peel texture.texture
  14204. if ( texture && texture.isWebGLRenderTargetCube ) {
  14205. if ( ! warned ) {
  14206. console.warn( "THREE.WebGLRenderer.setTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  14207. warned = true;
  14208. }
  14209. texture = texture.texture;
  14210. }
  14211. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  14212. // TODO: unify these code paths
  14213. if ( ( texture && texture.isCubeTexture ) ||
  14214. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  14215. // CompressedTexture can have Array in image :/
  14216. // this function alone should take care of cube textures
  14217. textures.setTextureCube( texture, slot );
  14218. } else {
  14219. // assumed: texture property of THREE.WebGLRenderTargetCube
  14220. textures.setTextureCubeDynamic( texture, slot );
  14221. }
  14222. };
  14223. }() );
  14224. //
  14225. this.setFramebuffer = function ( value ) {
  14226. _framebuffer = value;
  14227. };
  14228. this.getRenderTarget = function () {
  14229. return _currentRenderTarget;
  14230. };
  14231. this.setRenderTarget = function ( renderTarget ) {
  14232. _currentRenderTarget = renderTarget;
  14233. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  14234. textures.setupRenderTarget( renderTarget );
  14235. }
  14236. var framebuffer = _framebuffer;
  14237. var isCube = false;
  14238. if ( renderTarget ) {
  14239. var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14240. if ( renderTarget.isWebGLRenderTargetCube ) {
  14241. framebuffer = __webglFramebuffer[ renderTarget.activeCubeFace ];
  14242. isCube = true;
  14243. } else {
  14244. framebuffer = __webglFramebuffer;
  14245. }
  14246. _currentViewport.copy( renderTarget.viewport );
  14247. _currentScissor.copy( renderTarget.scissor );
  14248. _currentScissorTest = renderTarget.scissorTest;
  14249. } else {
  14250. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  14251. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  14252. _currentScissorTest = _scissorTest;
  14253. }
  14254. if ( _currentFramebuffer !== framebuffer ) {
  14255. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  14256. _currentFramebuffer = framebuffer;
  14257. }
  14258. state.viewport( _currentViewport );
  14259. state.scissor( _currentScissor );
  14260. state.setScissorTest( _currentScissorTest );
  14261. if ( isCube ) {
  14262. var textureProperties = properties.get( renderTarget.texture );
  14263. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, renderTarget.activeMipMapLevel );
  14264. }
  14265. };
  14266. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  14267. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  14268. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  14269. return;
  14270. }
  14271. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14272. if ( framebuffer ) {
  14273. var restore = false;
  14274. if ( framebuffer !== _currentFramebuffer ) {
  14275. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  14276. restore = true;
  14277. }
  14278. try {
  14279. var texture = renderTarget.texture;
  14280. var textureFormat = texture.format;
  14281. var textureType = texture.type;
  14282. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  14283. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  14284. return;
  14285. }
  14286. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  14287. ! ( textureType === FloatType && ( extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  14288. ! ( textureType === HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  14289. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  14290. return;
  14291. }
  14292. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  14293. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  14294. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  14295. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  14296. }
  14297. } else {
  14298. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  14299. }
  14300. } finally {
  14301. if ( restore ) {
  14302. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  14303. }
  14304. }
  14305. }
  14306. };
  14307. this.copyFramebufferToTexture = function ( position, texture, level ) {
  14308. var width = texture.image.width;
  14309. var height = texture.image.height;
  14310. var glFormat = utils.convert( texture.format );
  14311. this.setTexture2D( texture, 0 );
  14312. _gl.copyTexImage2D( _gl.TEXTURE_2D, level || 0, glFormat, position.x, position.y, width, height, 0 );
  14313. };
  14314. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level ) {
  14315. var width = srcTexture.image.width;
  14316. var height = srcTexture.image.height;
  14317. var glFormat = utils.convert( dstTexture.format );
  14318. var glType = utils.convert( dstTexture.type );
  14319. this.setTexture2D( dstTexture, 0 );
  14320. if ( srcTexture.isDataTexture ) {
  14321. _gl.texSubImage2D( _gl.TEXTURE_2D, level || 0, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
  14322. } else {
  14323. _gl.texSubImage2D( _gl.TEXTURE_2D, level || 0, position.x, position.y, glFormat, glType, srcTexture.image );
  14324. }
  14325. };
  14326. }
  14327. /**
  14328. * @author mrdoob / http://mrdoob.com/
  14329. * @author alteredq / http://alteredqualia.com/
  14330. */
  14331. function FogExp2( color, density ) {
  14332. this.name = '';
  14333. this.color = new Color( color );
  14334. this.density = ( density !== undefined ) ? density : 0.00025;
  14335. }
  14336. FogExp2.prototype.isFogExp2 = true;
  14337. FogExp2.prototype.clone = function () {
  14338. return new FogExp2( this.color, this.density );
  14339. };
  14340. FogExp2.prototype.toJSON = function ( /* meta */ ) {
  14341. return {
  14342. type: 'FogExp2',
  14343. color: this.color.getHex(),
  14344. density: this.density
  14345. };
  14346. };
  14347. /**
  14348. * @author mrdoob / http://mrdoob.com/
  14349. * @author alteredq / http://alteredqualia.com/
  14350. */
  14351. function Fog( color, near, far ) {
  14352. this.name = '';
  14353. this.color = new Color( color );
  14354. this.near = ( near !== undefined ) ? near : 1;
  14355. this.far = ( far !== undefined ) ? far : 1000;
  14356. }
  14357. Fog.prototype.isFog = true;
  14358. Fog.prototype.clone = function () {
  14359. return new Fog( this.color, this.near, this.far );
  14360. };
  14361. Fog.prototype.toJSON = function ( /* meta */ ) {
  14362. return {
  14363. type: 'Fog',
  14364. color: this.color.getHex(),
  14365. near: this.near,
  14366. far: this.far
  14367. };
  14368. };
  14369. /**
  14370. * @author mrdoob / http://mrdoob.com/
  14371. */
  14372. function Scene() {
  14373. Object3D.call( this );
  14374. this.type = 'Scene';
  14375. this.background = null;
  14376. this.fog = null;
  14377. this.overrideMaterial = null;
  14378. this.autoUpdate = true; // checked by the renderer
  14379. }
  14380. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14381. constructor: Scene,
  14382. copy: function ( source, recursive ) {
  14383. Object3D.prototype.copy.call( this, source, recursive );
  14384. if ( source.background !== null ) this.background = source.background.clone();
  14385. if ( source.fog !== null ) this.fog = source.fog.clone();
  14386. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  14387. this.autoUpdate = source.autoUpdate;
  14388. this.matrixAutoUpdate = source.matrixAutoUpdate;
  14389. return this;
  14390. },
  14391. toJSON: function ( meta ) {
  14392. var data = Object3D.prototype.toJSON.call( this, meta );
  14393. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  14394. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  14395. return data;
  14396. }
  14397. } );
  14398. /**
  14399. * @author alteredq / http://alteredqualia.com/
  14400. *
  14401. * parameters = {
  14402. * color: <hex>,
  14403. * opacity: <float>,
  14404. * map: new THREE.Texture( <Image> ),
  14405. *
  14406. * uvOffset: new THREE.Vector2(),
  14407. * uvScale: new THREE.Vector2()
  14408. * }
  14409. */
  14410. function SpriteMaterial( parameters ) {
  14411. Material.call( this );
  14412. this.type = 'SpriteMaterial';
  14413. this.color = new Color( 0xffffff );
  14414. this.map = null;
  14415. this.rotation = 0;
  14416. this.fog = false;
  14417. this.lights = false;
  14418. this.setValues( parameters );
  14419. }
  14420. SpriteMaterial.prototype = Object.create( Material.prototype );
  14421. SpriteMaterial.prototype.constructor = SpriteMaterial;
  14422. SpriteMaterial.prototype.isSpriteMaterial = true;
  14423. SpriteMaterial.prototype.copy = function ( source ) {
  14424. Material.prototype.copy.call( this, source );
  14425. this.color.copy( source.color );
  14426. this.map = source.map;
  14427. this.rotation = source.rotation;
  14428. return this;
  14429. };
  14430. /**
  14431. * @author mikael emtinger / http://gomo.se/
  14432. * @author alteredq / http://alteredqualia.com/
  14433. */
  14434. function Sprite( material ) {
  14435. Object3D.call( this );
  14436. this.type = 'Sprite';
  14437. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  14438. this.center = new Vector2( 0.5, 0.5 );
  14439. }
  14440. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14441. constructor: Sprite,
  14442. isSprite: true,
  14443. raycast: ( function () {
  14444. var intersectPoint = new Vector3();
  14445. var worldPosition = new Vector3();
  14446. var worldScale = new Vector3();
  14447. return function raycast( raycaster, intersects ) {
  14448. worldPosition.setFromMatrixPosition( this.matrixWorld );
  14449. raycaster.ray.closestPointToPoint( worldPosition, intersectPoint );
  14450. worldScale.setFromMatrixScale( this.matrixWorld );
  14451. var guessSizeSq = worldScale.x * worldScale.y / 4;
  14452. if ( worldPosition.distanceToSquared( intersectPoint ) > guessSizeSq ) return;
  14453. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  14454. if ( distance < raycaster.near || distance > raycaster.far ) return;
  14455. intersects.push( {
  14456. distance: distance,
  14457. point: intersectPoint.clone(),
  14458. face: null,
  14459. object: this
  14460. } );
  14461. };
  14462. }() ),
  14463. clone: function () {
  14464. return new this.constructor( this.material ).copy( this );
  14465. },
  14466. copy: function ( source ) {
  14467. Object3D.prototype.copy.call( this, source );
  14468. if ( source.center !== undefined ) this.center.copy( source.center );
  14469. return this;
  14470. }
  14471. } );
  14472. /**
  14473. * @author mikael emtinger / http://gomo.se/
  14474. * @author alteredq / http://alteredqualia.com/
  14475. * @author mrdoob / http://mrdoob.com/
  14476. */
  14477. function LOD() {
  14478. Object3D.call( this );
  14479. this.type = 'LOD';
  14480. Object.defineProperties( this, {
  14481. levels: {
  14482. enumerable: true,
  14483. value: []
  14484. }
  14485. } );
  14486. }
  14487. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14488. constructor: LOD,
  14489. copy: function ( source ) {
  14490. Object3D.prototype.copy.call( this, source, false );
  14491. var levels = source.levels;
  14492. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  14493. var level = levels[ i ];
  14494. this.addLevel( level.object.clone(), level.distance );
  14495. }
  14496. return this;
  14497. },
  14498. addLevel: function ( object, distance ) {
  14499. if ( distance === undefined ) distance = 0;
  14500. distance = Math.abs( distance );
  14501. var levels = this.levels;
  14502. for ( var l = 0; l < levels.length; l ++ ) {
  14503. if ( distance < levels[ l ].distance ) {
  14504. break;
  14505. }
  14506. }
  14507. levels.splice( l, 0, { distance: distance, object: object } );
  14508. this.add( object );
  14509. },
  14510. getObjectForDistance: function ( distance ) {
  14511. var levels = this.levels;
  14512. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  14513. if ( distance < levels[ i ].distance ) {
  14514. break;
  14515. }
  14516. }
  14517. return levels[ i - 1 ].object;
  14518. },
  14519. raycast: ( function () {
  14520. var matrixPosition = new Vector3();
  14521. return function raycast( raycaster, intersects ) {
  14522. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  14523. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  14524. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  14525. };
  14526. }() ),
  14527. update: function () {
  14528. var v1 = new Vector3();
  14529. var v2 = new Vector3();
  14530. return function update( camera ) {
  14531. var levels = this.levels;
  14532. if ( levels.length > 1 ) {
  14533. v1.setFromMatrixPosition( camera.matrixWorld );
  14534. v2.setFromMatrixPosition( this.matrixWorld );
  14535. var distance = v1.distanceTo( v2 );
  14536. levels[ 0 ].object.visible = true;
  14537. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  14538. if ( distance >= levels[ i ].distance ) {
  14539. levels[ i - 1 ].object.visible = false;
  14540. levels[ i ].object.visible = true;
  14541. } else {
  14542. break;
  14543. }
  14544. }
  14545. for ( ; i < l; i ++ ) {
  14546. levels[ i ].object.visible = false;
  14547. }
  14548. }
  14549. };
  14550. }(),
  14551. toJSON: function ( meta ) {
  14552. var data = Object3D.prototype.toJSON.call( this, meta );
  14553. data.object.levels = [];
  14554. var levels = this.levels;
  14555. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  14556. var level = levels[ i ];
  14557. data.object.levels.push( {
  14558. object: level.object.uuid,
  14559. distance: level.distance
  14560. } );
  14561. }
  14562. return data;
  14563. }
  14564. } );
  14565. /**
  14566. * @author mikael emtinger / http://gomo.se/
  14567. * @author alteredq / http://alteredqualia.com/
  14568. * @author michael guerrero / http://realitymeltdown.com
  14569. * @author ikerr / http://verold.com
  14570. */
  14571. function Skeleton( bones, boneInverses ) {
  14572. // copy the bone array
  14573. bones = bones || [];
  14574. this.bones = bones.slice( 0 );
  14575. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  14576. // use the supplied bone inverses or calculate the inverses
  14577. if ( boneInverses === undefined ) {
  14578. this.calculateInverses();
  14579. } else {
  14580. if ( this.bones.length === boneInverses.length ) {
  14581. this.boneInverses = boneInverses.slice( 0 );
  14582. } else {
  14583. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  14584. this.boneInverses = [];
  14585. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  14586. this.boneInverses.push( new Matrix4() );
  14587. }
  14588. }
  14589. }
  14590. }
  14591. Object.assign( Skeleton.prototype, {
  14592. calculateInverses: function () {
  14593. this.boneInverses = [];
  14594. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  14595. var inverse = new Matrix4();
  14596. if ( this.bones[ i ] ) {
  14597. inverse.getInverse( this.bones[ i ].matrixWorld );
  14598. }
  14599. this.boneInverses.push( inverse );
  14600. }
  14601. },
  14602. pose: function () {
  14603. var bone, i, il;
  14604. // recover the bind-time world matrices
  14605. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  14606. bone = this.bones[ i ];
  14607. if ( bone ) {
  14608. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  14609. }
  14610. }
  14611. // compute the local matrices, positions, rotations and scales
  14612. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  14613. bone = this.bones[ i ];
  14614. if ( bone ) {
  14615. if ( bone.parent && bone.parent.isBone ) {
  14616. bone.matrix.getInverse( bone.parent.matrixWorld );
  14617. bone.matrix.multiply( bone.matrixWorld );
  14618. } else {
  14619. bone.matrix.copy( bone.matrixWorld );
  14620. }
  14621. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  14622. }
  14623. }
  14624. },
  14625. update: ( function () {
  14626. var offsetMatrix = new Matrix4();
  14627. var identityMatrix = new Matrix4();
  14628. return function update() {
  14629. var bones = this.bones;
  14630. var boneInverses = this.boneInverses;
  14631. var boneMatrices = this.boneMatrices;
  14632. var boneTexture = this.boneTexture;
  14633. // flatten bone matrices to array
  14634. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  14635. // compute the offset between the current and the original transform
  14636. var matrix = bones[ i ] ? bones[ i ].matrixWorld : identityMatrix;
  14637. offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  14638. offsetMatrix.toArray( boneMatrices, i * 16 );
  14639. }
  14640. if ( boneTexture !== undefined ) {
  14641. boneTexture.needsUpdate = true;
  14642. }
  14643. };
  14644. } )(),
  14645. clone: function () {
  14646. return new Skeleton( this.bones, this.boneInverses );
  14647. },
  14648. getBoneByName: function ( name ) {
  14649. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  14650. var bone = this.bones[ i ];
  14651. if ( bone.name === name ) {
  14652. return bone;
  14653. }
  14654. }
  14655. return undefined;
  14656. }
  14657. } );
  14658. /**
  14659. * @author mikael emtinger / http://gomo.se/
  14660. * @author alteredq / http://alteredqualia.com/
  14661. * @author ikerr / http://verold.com
  14662. */
  14663. function Bone() {
  14664. Object3D.call( this );
  14665. this.type = 'Bone';
  14666. }
  14667. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14668. constructor: Bone,
  14669. isBone: true
  14670. } );
  14671. /**
  14672. * @author mikael emtinger / http://gomo.se/
  14673. * @author alteredq / http://alteredqualia.com/
  14674. * @author ikerr / http://verold.com
  14675. */
  14676. function SkinnedMesh( geometry, material ) {
  14677. Mesh.call( this, geometry, material );
  14678. this.type = 'SkinnedMesh';
  14679. this.bindMode = 'attached';
  14680. this.bindMatrix = new Matrix4();
  14681. this.bindMatrixInverse = new Matrix4();
  14682. var bones = this.initBones();
  14683. var skeleton = new Skeleton( bones );
  14684. this.bind( skeleton, this.matrixWorld );
  14685. this.normalizeSkinWeights();
  14686. }
  14687. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  14688. constructor: SkinnedMesh,
  14689. isSkinnedMesh: true,
  14690. initBones: function () {
  14691. var bones = [], bone, gbone;
  14692. var i, il;
  14693. if ( this.geometry && this.geometry.bones !== undefined ) {
  14694. // first, create array of 'Bone' objects from geometry data
  14695. for ( i = 0, il = this.geometry.bones.length; i < il; i ++ ) {
  14696. gbone = this.geometry.bones[ i ];
  14697. // create new 'Bone' object
  14698. bone = new Bone();
  14699. bones.push( bone );
  14700. // apply values
  14701. bone.name = gbone.name;
  14702. bone.position.fromArray( gbone.pos );
  14703. bone.quaternion.fromArray( gbone.rotq );
  14704. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  14705. }
  14706. // second, create bone hierarchy
  14707. for ( i = 0, il = this.geometry.bones.length; i < il; i ++ ) {
  14708. gbone = this.geometry.bones[ i ];
  14709. if ( ( gbone.parent !== - 1 ) && ( gbone.parent !== null ) && ( bones[ gbone.parent ] !== undefined ) ) {
  14710. // subsequent bones in the hierarchy
  14711. bones[ gbone.parent ].add( bones[ i ] );
  14712. } else {
  14713. // topmost bone, immediate child of the skinned mesh
  14714. this.add( bones[ i ] );
  14715. }
  14716. }
  14717. }
  14718. // now the bones are part of the scene graph and children of the skinned mesh.
  14719. // let's update the corresponding matrices
  14720. this.updateMatrixWorld( true );
  14721. return bones;
  14722. },
  14723. bind: function ( skeleton, bindMatrix ) {
  14724. this.skeleton = skeleton;
  14725. if ( bindMatrix === undefined ) {
  14726. this.updateMatrixWorld( true );
  14727. this.skeleton.calculateInverses();
  14728. bindMatrix = this.matrixWorld;
  14729. }
  14730. this.bindMatrix.copy( bindMatrix );
  14731. this.bindMatrixInverse.getInverse( bindMatrix );
  14732. },
  14733. pose: function () {
  14734. this.skeleton.pose();
  14735. },
  14736. normalizeSkinWeights: function () {
  14737. var scale, i;
  14738. if ( this.geometry && this.geometry.isGeometry ) {
  14739. for ( i = 0; i < this.geometry.skinWeights.length; i ++ ) {
  14740. var sw = this.geometry.skinWeights[ i ];
  14741. scale = 1.0 / sw.manhattanLength();
  14742. if ( scale !== Infinity ) {
  14743. sw.multiplyScalar( scale );
  14744. } else {
  14745. sw.set( 1, 0, 0, 0 ); // do something reasonable
  14746. }
  14747. }
  14748. } else if ( this.geometry && this.geometry.isBufferGeometry ) {
  14749. var vec = new Vector4();
  14750. var skinWeight = this.geometry.attributes.skinWeight;
  14751. for ( i = 0; i < skinWeight.count; i ++ ) {
  14752. vec.x = skinWeight.getX( i );
  14753. vec.y = skinWeight.getY( i );
  14754. vec.z = skinWeight.getZ( i );
  14755. vec.w = skinWeight.getW( i );
  14756. scale = 1.0 / vec.manhattanLength();
  14757. if ( scale !== Infinity ) {
  14758. vec.multiplyScalar( scale );
  14759. } else {
  14760. vec.set( 1, 0, 0, 0 ); // do something reasonable
  14761. }
  14762. skinWeight.setXYZW( i, vec.x, vec.y, vec.z, vec.w );
  14763. }
  14764. }
  14765. },
  14766. updateMatrixWorld: function ( force ) {
  14767. Mesh.prototype.updateMatrixWorld.call( this, force );
  14768. if ( this.bindMode === 'attached' ) {
  14769. this.bindMatrixInverse.getInverse( this.matrixWorld );
  14770. } else if ( this.bindMode === 'detached' ) {
  14771. this.bindMatrixInverse.getInverse( this.bindMatrix );
  14772. } else {
  14773. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  14774. }
  14775. },
  14776. clone: function () {
  14777. return new this.constructor( this.geometry, this.material ).copy( this );
  14778. }
  14779. } );
  14780. /**
  14781. * @author mrdoob / http://mrdoob.com/
  14782. * @author alteredq / http://alteredqualia.com/
  14783. *
  14784. * parameters = {
  14785. * color: <hex>,
  14786. * opacity: <float>,
  14787. *
  14788. * linewidth: <float>,
  14789. * linecap: "round",
  14790. * linejoin: "round"
  14791. * }
  14792. */
  14793. function LineBasicMaterial( parameters ) {
  14794. Material.call( this );
  14795. this.type = 'LineBasicMaterial';
  14796. this.color = new Color( 0xffffff );
  14797. this.linewidth = 1;
  14798. this.linecap = 'round';
  14799. this.linejoin = 'round';
  14800. this.lights = false;
  14801. this.setValues( parameters );
  14802. }
  14803. LineBasicMaterial.prototype = Object.create( Material.prototype );
  14804. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  14805. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  14806. LineBasicMaterial.prototype.copy = function ( source ) {
  14807. Material.prototype.copy.call( this, source );
  14808. this.color.copy( source.color );
  14809. this.linewidth = source.linewidth;
  14810. this.linecap = source.linecap;
  14811. this.linejoin = source.linejoin;
  14812. return this;
  14813. };
  14814. /**
  14815. * @author mrdoob / http://mrdoob.com/
  14816. */
  14817. function Line( geometry, material, mode ) {
  14818. if ( mode === 1 ) {
  14819. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  14820. return new LineSegments( geometry, material );
  14821. }
  14822. Object3D.call( this );
  14823. this.type = 'Line';
  14824. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  14825. this.material = material !== undefined ? material : new LineBasicMaterial( { color: Math.random() * 0xffffff } );
  14826. }
  14827. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14828. constructor: Line,
  14829. isLine: true,
  14830. computeLineDistances: ( function () {
  14831. var start = new Vector3();
  14832. var end = new Vector3();
  14833. return function computeLineDistances() {
  14834. var geometry = this.geometry;
  14835. if ( geometry.isBufferGeometry ) {
  14836. // we assume non-indexed geometry
  14837. if ( geometry.index === null ) {
  14838. var positionAttribute = geometry.attributes.position;
  14839. var lineDistances = [ 0 ];
  14840. for ( var i = 1, l = positionAttribute.count; i < l; i ++ ) {
  14841. start.fromBufferAttribute( positionAttribute, i - 1 );
  14842. end.fromBufferAttribute( positionAttribute, i );
  14843. lineDistances[ i ] = lineDistances[ i - 1 ];
  14844. lineDistances[ i ] += start.distanceTo( end );
  14845. }
  14846. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  14847. } else {
  14848. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  14849. }
  14850. } else if ( geometry.isGeometry ) {
  14851. var vertices = geometry.vertices;
  14852. var lineDistances = geometry.lineDistances;
  14853. lineDistances[ 0 ] = 0;
  14854. for ( var i = 1, l = vertices.length; i < l; i ++ ) {
  14855. lineDistances[ i ] = lineDistances[ i - 1 ];
  14856. lineDistances[ i ] += vertices[ i - 1 ].distanceTo( vertices[ i ] );
  14857. }
  14858. }
  14859. return this;
  14860. };
  14861. }() ),
  14862. raycast: ( function () {
  14863. var inverseMatrix = new Matrix4();
  14864. var ray = new Ray();
  14865. var sphere = new Sphere();
  14866. return function raycast( raycaster, intersects ) {
  14867. var precision = raycaster.linePrecision;
  14868. var precisionSq = precision * precision;
  14869. var geometry = this.geometry;
  14870. var matrixWorld = this.matrixWorld;
  14871. // Checking boundingSphere distance to ray
  14872. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  14873. sphere.copy( geometry.boundingSphere );
  14874. sphere.applyMatrix4( matrixWorld );
  14875. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  14876. //
  14877. inverseMatrix.getInverse( matrixWorld );
  14878. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  14879. var vStart = new Vector3();
  14880. var vEnd = new Vector3();
  14881. var interSegment = new Vector3();
  14882. var interRay = new Vector3();
  14883. var step = ( this && this.isLineSegments ) ? 2 : 1;
  14884. if ( geometry.isBufferGeometry ) {
  14885. var index = geometry.index;
  14886. var attributes = geometry.attributes;
  14887. var positions = attributes.position.array;
  14888. if ( index !== null ) {
  14889. var indices = index.array;
  14890. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  14891. var a = indices[ i ];
  14892. var b = indices[ i + 1 ];
  14893. vStart.fromArray( positions, a * 3 );
  14894. vEnd.fromArray( positions, b * 3 );
  14895. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  14896. if ( distSq > precisionSq ) continue;
  14897. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14898. var distance = raycaster.ray.origin.distanceTo( interRay );
  14899. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14900. intersects.push( {
  14901. distance: distance,
  14902. // What do we want? intersection point on the ray or on the segment??
  14903. // point: raycaster.ray.at( distance ),
  14904. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14905. index: i,
  14906. face: null,
  14907. faceIndex: null,
  14908. object: this
  14909. } );
  14910. }
  14911. } else {
  14912. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  14913. vStart.fromArray( positions, 3 * i );
  14914. vEnd.fromArray( positions, 3 * i + 3 );
  14915. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  14916. if ( distSq > precisionSq ) continue;
  14917. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14918. var distance = raycaster.ray.origin.distanceTo( interRay );
  14919. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14920. intersects.push( {
  14921. distance: distance,
  14922. // What do we want? intersection point on the ray or on the segment??
  14923. // point: raycaster.ray.at( distance ),
  14924. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14925. index: i,
  14926. face: null,
  14927. faceIndex: null,
  14928. object: this
  14929. } );
  14930. }
  14931. }
  14932. } else if ( geometry.isGeometry ) {
  14933. var vertices = geometry.vertices;
  14934. var nbVertices = vertices.length;
  14935. for ( var i = 0; i < nbVertices - 1; i += step ) {
  14936. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  14937. if ( distSq > precisionSq ) continue;
  14938. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14939. var distance = raycaster.ray.origin.distanceTo( interRay );
  14940. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14941. intersects.push( {
  14942. distance: distance,
  14943. // What do we want? intersection point on the ray or on the segment??
  14944. // point: raycaster.ray.at( distance ),
  14945. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14946. index: i,
  14947. face: null,
  14948. faceIndex: null,
  14949. object: this
  14950. } );
  14951. }
  14952. }
  14953. };
  14954. }() ),
  14955. clone: function () {
  14956. return new this.constructor( this.geometry, this.material ).copy( this );
  14957. }
  14958. } );
  14959. /**
  14960. * @author mrdoob / http://mrdoob.com/
  14961. */
  14962. function LineSegments( geometry, material ) {
  14963. Line.call( this, geometry, material );
  14964. this.type = 'LineSegments';
  14965. }
  14966. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  14967. constructor: LineSegments,
  14968. isLineSegments: true,
  14969. computeLineDistances: ( function () {
  14970. var start = new Vector3();
  14971. var end = new Vector3();
  14972. return function computeLineDistances() {
  14973. var geometry = this.geometry;
  14974. if ( geometry.isBufferGeometry ) {
  14975. // we assume non-indexed geometry
  14976. if ( geometry.index === null ) {
  14977. var positionAttribute = geometry.attributes.position;
  14978. var lineDistances = [];
  14979. for ( var i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  14980. start.fromBufferAttribute( positionAttribute, i );
  14981. end.fromBufferAttribute( positionAttribute, i + 1 );
  14982. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  14983. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  14984. }
  14985. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  14986. } else {
  14987. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  14988. }
  14989. } else if ( geometry.isGeometry ) {
  14990. var vertices = geometry.vertices;
  14991. var lineDistances = geometry.lineDistances;
  14992. for ( var i = 0, l = vertices.length; i < l; i += 2 ) {
  14993. start.copy( vertices[ i ] );
  14994. end.copy( vertices[ i + 1 ] );
  14995. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  14996. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  14997. }
  14998. }
  14999. return this;
  15000. };
  15001. }() )
  15002. } );
  15003. /**
  15004. * @author mgreter / http://github.com/mgreter
  15005. */
  15006. function LineLoop( geometry, material ) {
  15007. Line.call( this, geometry, material );
  15008. this.type = 'LineLoop';
  15009. }
  15010. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  15011. constructor: LineLoop,
  15012. isLineLoop: true,
  15013. } );
  15014. /**
  15015. * @author mrdoob / http://mrdoob.com/
  15016. * @author alteredq / http://alteredqualia.com/
  15017. *
  15018. * parameters = {
  15019. * color: <hex>,
  15020. * opacity: <float>,
  15021. * map: new THREE.Texture( <Image> ),
  15022. *
  15023. * size: <float>,
  15024. * sizeAttenuation: <bool>
  15025. *
  15026. * morphTargets: <bool>
  15027. * }
  15028. */
  15029. function PointsMaterial( parameters ) {
  15030. Material.call( this );
  15031. this.type = 'PointsMaterial';
  15032. this.color = new Color( 0xffffff );
  15033. this.map = null;
  15034. this.size = 1;
  15035. this.sizeAttenuation = true;
  15036. this.morphTargets = false;
  15037. this.lights = false;
  15038. this.setValues( parameters );
  15039. }
  15040. PointsMaterial.prototype = Object.create( Material.prototype );
  15041. PointsMaterial.prototype.constructor = PointsMaterial;
  15042. PointsMaterial.prototype.isPointsMaterial = true;
  15043. PointsMaterial.prototype.copy = function ( source ) {
  15044. Material.prototype.copy.call( this, source );
  15045. this.color.copy( source.color );
  15046. this.map = source.map;
  15047. this.size = source.size;
  15048. this.sizeAttenuation = source.sizeAttenuation;
  15049. this.morphTargets = source.morphTargets;
  15050. return this;
  15051. };
  15052. /**
  15053. * @author alteredq / http://alteredqualia.com/
  15054. */
  15055. function Points( geometry, material ) {
  15056. Object3D.call( this );
  15057. this.type = 'Points';
  15058. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15059. this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
  15060. }
  15061. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15062. constructor: Points,
  15063. isPoints: true,
  15064. raycast: ( function () {
  15065. var inverseMatrix = new Matrix4();
  15066. var ray = new Ray();
  15067. var sphere = new Sphere();
  15068. return function raycast( raycaster, intersects ) {
  15069. var object = this;
  15070. var geometry = this.geometry;
  15071. var matrixWorld = this.matrixWorld;
  15072. var threshold = raycaster.params.Points.threshold;
  15073. // Checking boundingSphere distance to ray
  15074. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15075. sphere.copy( geometry.boundingSphere );
  15076. sphere.applyMatrix4( matrixWorld );
  15077. sphere.radius += threshold;
  15078. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  15079. //
  15080. inverseMatrix.getInverse( matrixWorld );
  15081. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  15082. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15083. var localThresholdSq = localThreshold * localThreshold;
  15084. var position = new Vector3();
  15085. var intersectPoint = new Vector3();
  15086. function testPoint( point, index ) {
  15087. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  15088. if ( rayPointDistanceSq < localThresholdSq ) {
  15089. ray.closestPointToPoint( point, intersectPoint );
  15090. intersectPoint.applyMatrix4( matrixWorld );
  15091. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  15092. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15093. intersects.push( {
  15094. distance: distance,
  15095. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  15096. point: intersectPoint.clone(),
  15097. index: index,
  15098. face: null,
  15099. object: object
  15100. } );
  15101. }
  15102. }
  15103. if ( geometry.isBufferGeometry ) {
  15104. var index = geometry.index;
  15105. var attributes = geometry.attributes;
  15106. var positions = attributes.position.array;
  15107. if ( index !== null ) {
  15108. var indices = index.array;
  15109. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  15110. var a = indices[ i ];
  15111. position.fromArray( positions, a * 3 );
  15112. testPoint( position, a );
  15113. }
  15114. } else {
  15115. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  15116. position.fromArray( positions, i * 3 );
  15117. testPoint( position, i );
  15118. }
  15119. }
  15120. } else {
  15121. var vertices = geometry.vertices;
  15122. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  15123. testPoint( vertices[ i ], i );
  15124. }
  15125. }
  15126. };
  15127. }() ),
  15128. clone: function () {
  15129. return new this.constructor( this.geometry, this.material ).copy( this );
  15130. }
  15131. } );
  15132. /**
  15133. * @author mrdoob / http://mrdoob.com/
  15134. */
  15135. function Group() {
  15136. Object3D.call( this );
  15137. this.type = 'Group';
  15138. }
  15139. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15140. constructor: Group,
  15141. isGroup: true
  15142. } );
  15143. /**
  15144. * @author mrdoob / http://mrdoob.com/
  15145. */
  15146. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  15147. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15148. this.generateMipmaps = false;
  15149. }
  15150. VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
  15151. constructor: VideoTexture,
  15152. isVideoTexture: true,
  15153. update: function () {
  15154. var video = this.image;
  15155. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  15156. this.needsUpdate = true;
  15157. }
  15158. }
  15159. } );
  15160. /**
  15161. * @author alteredq / http://alteredqualia.com/
  15162. */
  15163. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  15164. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  15165. this.image = { width: width, height: height };
  15166. this.mipmaps = mipmaps;
  15167. // no flipping for cube textures
  15168. // (also flipping doesn't work for compressed textures )
  15169. this.flipY = false;
  15170. // can't generate mipmaps for compressed textures
  15171. // mips must be embedded in DDS files
  15172. this.generateMipmaps = false;
  15173. }
  15174. CompressedTexture.prototype = Object.create( Texture.prototype );
  15175. CompressedTexture.prototype.constructor = CompressedTexture;
  15176. CompressedTexture.prototype.isCompressedTexture = true;
  15177. /**
  15178. * @author Matt DesLauriers / @mattdesl
  15179. * @author atix / arthursilber.de
  15180. */
  15181. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  15182. format = format !== undefined ? format : DepthFormat;
  15183. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  15184. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  15185. }
  15186. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  15187. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  15188. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15189. this.image = { width: width, height: height };
  15190. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  15191. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  15192. this.flipY = false;
  15193. this.generateMipmaps = false;
  15194. }
  15195. DepthTexture.prototype = Object.create( Texture.prototype );
  15196. DepthTexture.prototype.constructor = DepthTexture;
  15197. DepthTexture.prototype.isDepthTexture = true;
  15198. /**
  15199. * @author mrdoob / http://mrdoob.com/
  15200. * @author Mugen87 / https://github.com/Mugen87
  15201. */
  15202. function WireframeGeometry( geometry ) {
  15203. BufferGeometry.call( this );
  15204. this.type = 'WireframeGeometry';
  15205. // buffer
  15206. var vertices = [];
  15207. // helper variables
  15208. var i, j, l, o, ol;
  15209. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  15210. var key, keys = [ 'a', 'b', 'c' ];
  15211. var vertex;
  15212. // different logic for Geometry and BufferGeometry
  15213. if ( geometry && geometry.isGeometry ) {
  15214. // create a data structure that contains all edges without duplicates
  15215. var faces = geometry.faces;
  15216. for ( i = 0, l = faces.length; i < l; i ++ ) {
  15217. var face = faces[ i ];
  15218. for ( j = 0; j < 3; j ++ ) {
  15219. edge1 = face[ keys[ j ] ];
  15220. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  15221. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  15222. edge[ 1 ] = Math.max( edge1, edge2 );
  15223. key = edge[ 0 ] + ',' + edge[ 1 ];
  15224. if ( edges[ key ] === undefined ) {
  15225. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  15226. }
  15227. }
  15228. }
  15229. // generate vertices
  15230. for ( key in edges ) {
  15231. e = edges[ key ];
  15232. vertex = geometry.vertices[ e.index1 ];
  15233. vertices.push( vertex.x, vertex.y, vertex.z );
  15234. vertex = geometry.vertices[ e.index2 ];
  15235. vertices.push( vertex.x, vertex.y, vertex.z );
  15236. }
  15237. } else if ( geometry && geometry.isBufferGeometry ) {
  15238. var position, indices, groups;
  15239. var group, start, count;
  15240. var index1, index2;
  15241. vertex = new Vector3();
  15242. if ( geometry.index !== null ) {
  15243. // indexed BufferGeometry
  15244. position = geometry.attributes.position;
  15245. indices = geometry.index;
  15246. groups = geometry.groups;
  15247. if ( groups.length === 0 ) {
  15248. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  15249. }
  15250. // create a data structure that contains all eges without duplicates
  15251. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  15252. group = groups[ o ];
  15253. start = group.start;
  15254. count = group.count;
  15255. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  15256. for ( j = 0; j < 3; j ++ ) {
  15257. edge1 = indices.getX( i + j );
  15258. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  15259. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  15260. edge[ 1 ] = Math.max( edge1, edge2 );
  15261. key = edge[ 0 ] + ',' + edge[ 1 ];
  15262. if ( edges[ key ] === undefined ) {
  15263. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  15264. }
  15265. }
  15266. }
  15267. }
  15268. // generate vertices
  15269. for ( key in edges ) {
  15270. e = edges[ key ];
  15271. vertex.fromBufferAttribute( position, e.index1 );
  15272. vertices.push( vertex.x, vertex.y, vertex.z );
  15273. vertex.fromBufferAttribute( position, e.index2 );
  15274. vertices.push( vertex.x, vertex.y, vertex.z );
  15275. }
  15276. } else {
  15277. // non-indexed BufferGeometry
  15278. position = geometry.attributes.position;
  15279. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  15280. for ( j = 0; j < 3; j ++ ) {
  15281. // three edges per triangle, an edge is represented as (index1, index2)
  15282. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  15283. index1 = 3 * i + j;
  15284. vertex.fromBufferAttribute( position, index1 );
  15285. vertices.push( vertex.x, vertex.y, vertex.z );
  15286. index2 = 3 * i + ( ( j + 1 ) % 3 );
  15287. vertex.fromBufferAttribute( position, index2 );
  15288. vertices.push( vertex.x, vertex.y, vertex.z );
  15289. }
  15290. }
  15291. }
  15292. }
  15293. // build geometry
  15294. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  15295. }
  15296. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  15297. WireframeGeometry.prototype.constructor = WireframeGeometry;
  15298. /**
  15299. * @author zz85 / https://github.com/zz85
  15300. * @author Mugen87 / https://github.com/Mugen87
  15301. *
  15302. * Parametric Surfaces Geometry
  15303. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  15304. */
  15305. // ParametricGeometry
  15306. function ParametricGeometry( func, slices, stacks ) {
  15307. Geometry.call( this );
  15308. this.type = 'ParametricGeometry';
  15309. this.parameters = {
  15310. func: func,
  15311. slices: slices,
  15312. stacks: stacks
  15313. };
  15314. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  15315. this.mergeVertices();
  15316. }
  15317. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  15318. ParametricGeometry.prototype.constructor = ParametricGeometry;
  15319. // ParametricBufferGeometry
  15320. function ParametricBufferGeometry( func, slices, stacks ) {
  15321. BufferGeometry.call( this );
  15322. this.type = 'ParametricBufferGeometry';
  15323. this.parameters = {
  15324. func: func,
  15325. slices: slices,
  15326. stacks: stacks
  15327. };
  15328. // buffers
  15329. var indices = [];
  15330. var vertices = [];
  15331. var normals = [];
  15332. var uvs = [];
  15333. var EPS = 0.00001;
  15334. var normal = new Vector3();
  15335. var p0 = new Vector3(), p1 = new Vector3();
  15336. var pu = new Vector3(), pv = new Vector3();
  15337. var i, j;
  15338. if ( func.length < 3 ) {
  15339. console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' );
  15340. }
  15341. // generate vertices, normals and uvs
  15342. var sliceCount = slices + 1;
  15343. for ( i = 0; i <= stacks; i ++ ) {
  15344. var v = i / stacks;
  15345. for ( j = 0; j <= slices; j ++ ) {
  15346. var u = j / slices;
  15347. // vertex
  15348. func( u, v, p0 );
  15349. vertices.push( p0.x, p0.y, p0.z );
  15350. // normal
  15351. // approximate tangent vectors via finite differences
  15352. if ( u - EPS >= 0 ) {
  15353. func( u - EPS, v, p1 );
  15354. pu.subVectors( p0, p1 );
  15355. } else {
  15356. func( u + EPS, v, p1 );
  15357. pu.subVectors( p1, p0 );
  15358. }
  15359. if ( v - EPS >= 0 ) {
  15360. func( u, v - EPS, p1 );
  15361. pv.subVectors( p0, p1 );
  15362. } else {
  15363. func( u, v + EPS, p1 );
  15364. pv.subVectors( p1, p0 );
  15365. }
  15366. // cross product of tangent vectors returns surface normal
  15367. normal.crossVectors( pu, pv ).normalize();
  15368. normals.push( normal.x, normal.y, normal.z );
  15369. // uv
  15370. uvs.push( u, v );
  15371. }
  15372. }
  15373. // generate indices
  15374. for ( i = 0; i < stacks; i ++ ) {
  15375. for ( j = 0; j < slices; j ++ ) {
  15376. var a = i * sliceCount + j;
  15377. var b = i * sliceCount + j + 1;
  15378. var c = ( i + 1 ) * sliceCount + j + 1;
  15379. var d = ( i + 1 ) * sliceCount + j;
  15380. // faces one and two
  15381. indices.push( a, b, d );
  15382. indices.push( b, c, d );
  15383. }
  15384. }
  15385. // build geometry
  15386. this.setIndex( indices );
  15387. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  15388. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  15389. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  15390. }
  15391. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15392. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  15393. /**
  15394. * @author clockworkgeek / https://github.com/clockworkgeek
  15395. * @author timothypratley / https://github.com/timothypratley
  15396. * @author WestLangley / http://github.com/WestLangley
  15397. * @author Mugen87 / https://github.com/Mugen87
  15398. */
  15399. // PolyhedronGeometry
  15400. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  15401. Geometry.call( this );
  15402. this.type = 'PolyhedronGeometry';
  15403. this.parameters = {
  15404. vertices: vertices,
  15405. indices: indices,
  15406. radius: radius,
  15407. detail: detail
  15408. };
  15409. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  15410. this.mergeVertices();
  15411. }
  15412. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  15413. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  15414. // PolyhedronBufferGeometry
  15415. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  15416. BufferGeometry.call( this );
  15417. this.type = 'PolyhedronBufferGeometry';
  15418. this.parameters = {
  15419. vertices: vertices,
  15420. indices: indices,
  15421. radius: radius,
  15422. detail: detail
  15423. };
  15424. radius = radius || 1;
  15425. detail = detail || 0;
  15426. // default buffer data
  15427. var vertexBuffer = [];
  15428. var uvBuffer = [];
  15429. // the subdivision creates the vertex buffer data
  15430. subdivide( detail );
  15431. // all vertices should lie on a conceptual sphere with a given radius
  15432. appplyRadius( radius );
  15433. // finally, create the uv data
  15434. generateUVs();
  15435. // build non-indexed geometry
  15436. this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  15437. this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  15438. this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  15439. if ( detail === 0 ) {
  15440. this.computeVertexNormals(); // flat normals
  15441. } else {
  15442. this.normalizeNormals(); // smooth normals
  15443. }
  15444. // helper functions
  15445. function subdivide( detail ) {
  15446. var a = new Vector3();
  15447. var b = new Vector3();
  15448. var c = new Vector3();
  15449. // iterate over all faces and apply a subdivison with the given detail value
  15450. for ( var i = 0; i < indices.length; i += 3 ) {
  15451. // get the vertices of the face
  15452. getVertexByIndex( indices[ i + 0 ], a );
  15453. getVertexByIndex( indices[ i + 1 ], b );
  15454. getVertexByIndex( indices[ i + 2 ], c );
  15455. // perform subdivision
  15456. subdivideFace( a, b, c, detail );
  15457. }
  15458. }
  15459. function subdivideFace( a, b, c, detail ) {
  15460. var cols = Math.pow( 2, detail );
  15461. // we use this multidimensional array as a data structure for creating the subdivision
  15462. var v = [];
  15463. var i, j;
  15464. // construct all of the vertices for this subdivision
  15465. for ( i = 0; i <= cols; i ++ ) {
  15466. v[ i ] = [];
  15467. var aj = a.clone().lerp( c, i / cols );
  15468. var bj = b.clone().lerp( c, i / cols );
  15469. var rows = cols - i;
  15470. for ( j = 0; j <= rows; j ++ ) {
  15471. if ( j === 0 && i === cols ) {
  15472. v[ i ][ j ] = aj;
  15473. } else {
  15474. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  15475. }
  15476. }
  15477. }
  15478. // construct all of the faces
  15479. for ( i = 0; i < cols; i ++ ) {
  15480. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  15481. var k = Math.floor( j / 2 );
  15482. if ( j % 2 === 0 ) {
  15483. pushVertex( v[ i ][ k + 1 ] );
  15484. pushVertex( v[ i + 1 ][ k ] );
  15485. pushVertex( v[ i ][ k ] );
  15486. } else {
  15487. pushVertex( v[ i ][ k + 1 ] );
  15488. pushVertex( v[ i + 1 ][ k + 1 ] );
  15489. pushVertex( v[ i + 1 ][ k ] );
  15490. }
  15491. }
  15492. }
  15493. }
  15494. function appplyRadius( radius ) {
  15495. var vertex = new Vector3();
  15496. // iterate over the entire buffer and apply the radius to each vertex
  15497. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  15498. vertex.x = vertexBuffer[ i + 0 ];
  15499. vertex.y = vertexBuffer[ i + 1 ];
  15500. vertex.z = vertexBuffer[ i + 2 ];
  15501. vertex.normalize().multiplyScalar( radius );
  15502. vertexBuffer[ i + 0 ] = vertex.x;
  15503. vertexBuffer[ i + 1 ] = vertex.y;
  15504. vertexBuffer[ i + 2 ] = vertex.z;
  15505. }
  15506. }
  15507. function generateUVs() {
  15508. var vertex = new Vector3();
  15509. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  15510. vertex.x = vertexBuffer[ i + 0 ];
  15511. vertex.y = vertexBuffer[ i + 1 ];
  15512. vertex.z = vertexBuffer[ i + 2 ];
  15513. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  15514. var v = inclination( vertex ) / Math.PI + 0.5;
  15515. uvBuffer.push( u, 1 - v );
  15516. }
  15517. correctUVs();
  15518. correctSeam();
  15519. }
  15520. function correctSeam() {
  15521. // handle case when face straddles the seam, see #3269
  15522. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  15523. // uv data of a single face
  15524. var x0 = uvBuffer[ i + 0 ];
  15525. var x1 = uvBuffer[ i + 2 ];
  15526. var x2 = uvBuffer[ i + 4 ];
  15527. var max = Math.max( x0, x1, x2 );
  15528. var min = Math.min( x0, x1, x2 );
  15529. // 0.9 is somewhat arbitrary
  15530. if ( max > 0.9 && min < 0.1 ) {
  15531. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  15532. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  15533. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  15534. }
  15535. }
  15536. }
  15537. function pushVertex( vertex ) {
  15538. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  15539. }
  15540. function getVertexByIndex( index, vertex ) {
  15541. var stride = index * 3;
  15542. vertex.x = vertices[ stride + 0 ];
  15543. vertex.y = vertices[ stride + 1 ];
  15544. vertex.z = vertices[ stride + 2 ];
  15545. }
  15546. function correctUVs() {
  15547. var a = new Vector3();
  15548. var b = new Vector3();
  15549. var c = new Vector3();
  15550. var centroid = new Vector3();
  15551. var uvA = new Vector2();
  15552. var uvB = new Vector2();
  15553. var uvC = new Vector2();
  15554. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  15555. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  15556. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  15557. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  15558. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  15559. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  15560. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  15561. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  15562. var azi = azimuth( centroid );
  15563. correctUV( uvA, j + 0, a, azi );
  15564. correctUV( uvB, j + 2, b, azi );
  15565. correctUV( uvC, j + 4, c, azi );
  15566. }
  15567. }
  15568. function correctUV( uv, stride, vector, azimuth ) {
  15569. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  15570. uvBuffer[ stride ] = uv.x - 1;
  15571. }
  15572. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  15573. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  15574. }
  15575. }
  15576. // Angle around the Y axis, counter-clockwise when looking from above.
  15577. function azimuth( vector ) {
  15578. return Math.atan2( vector.z, - vector.x );
  15579. }
  15580. // Angle above the XZ plane.
  15581. function inclination( vector ) {
  15582. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  15583. }
  15584. }
  15585. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15586. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  15587. /**
  15588. * @author timothypratley / https://github.com/timothypratley
  15589. * @author Mugen87 / https://github.com/Mugen87
  15590. */
  15591. // TetrahedronGeometry
  15592. function TetrahedronGeometry( radius, detail ) {
  15593. Geometry.call( this );
  15594. this.type = 'TetrahedronGeometry';
  15595. this.parameters = {
  15596. radius: radius,
  15597. detail: detail
  15598. };
  15599. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  15600. this.mergeVertices();
  15601. }
  15602. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  15603. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  15604. // TetrahedronBufferGeometry
  15605. function TetrahedronBufferGeometry( radius, detail ) {
  15606. var vertices = [
  15607. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  15608. ];
  15609. var indices = [
  15610. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  15611. ];
  15612. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  15613. this.type = 'TetrahedronBufferGeometry';
  15614. this.parameters = {
  15615. radius: radius,
  15616. detail: detail
  15617. };
  15618. }
  15619. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  15620. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  15621. /**
  15622. * @author timothypratley / https://github.com/timothypratley
  15623. * @author Mugen87 / https://github.com/Mugen87
  15624. */
  15625. // OctahedronGeometry
  15626. function OctahedronGeometry( radius, detail ) {
  15627. Geometry.call( this );
  15628. this.type = 'OctahedronGeometry';
  15629. this.parameters = {
  15630. radius: radius,
  15631. detail: detail
  15632. };
  15633. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  15634. this.mergeVertices();
  15635. }
  15636. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  15637. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  15638. // OctahedronBufferGeometry
  15639. function OctahedronBufferGeometry( radius, detail ) {
  15640. var vertices = [
  15641. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  15642. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  15643. ];
  15644. var indices = [
  15645. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  15646. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  15647. 1, 3, 4, 1, 4, 2
  15648. ];
  15649. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  15650. this.type = 'OctahedronBufferGeometry';
  15651. this.parameters = {
  15652. radius: radius,
  15653. detail: detail
  15654. };
  15655. }
  15656. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  15657. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  15658. /**
  15659. * @author timothypratley / https://github.com/timothypratley
  15660. * @author Mugen87 / https://github.com/Mugen87
  15661. */
  15662. // IcosahedronGeometry
  15663. function IcosahedronGeometry( radius, detail ) {
  15664. Geometry.call( this );
  15665. this.type = 'IcosahedronGeometry';
  15666. this.parameters = {
  15667. radius: radius,
  15668. detail: detail
  15669. };
  15670. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  15671. this.mergeVertices();
  15672. }
  15673. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  15674. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  15675. // IcosahedronBufferGeometry
  15676. function IcosahedronBufferGeometry( radius, detail ) {
  15677. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  15678. var vertices = [
  15679. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  15680. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  15681. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  15682. ];
  15683. var indices = [
  15684. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  15685. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  15686. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  15687. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  15688. ];
  15689. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  15690. this.type = 'IcosahedronBufferGeometry';
  15691. this.parameters = {
  15692. radius: radius,
  15693. detail: detail
  15694. };
  15695. }
  15696. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  15697. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  15698. /**
  15699. * @author Abe Pazos / https://hamoid.com
  15700. * @author Mugen87 / https://github.com/Mugen87
  15701. */
  15702. // DodecahedronGeometry
  15703. function DodecahedronGeometry( radius, detail ) {
  15704. Geometry.call( this );
  15705. this.type = 'DodecahedronGeometry';
  15706. this.parameters = {
  15707. radius: radius,
  15708. detail: detail
  15709. };
  15710. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  15711. this.mergeVertices();
  15712. }
  15713. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  15714. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  15715. // DodecahedronBufferGeometry
  15716. function DodecahedronBufferGeometry( radius, detail ) {
  15717. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  15718. var r = 1 / t;
  15719. var vertices = [
  15720. // (±1, ±1, ±1)
  15721. - 1, - 1, - 1, - 1, - 1, 1,
  15722. - 1, 1, - 1, - 1, 1, 1,
  15723. 1, - 1, - 1, 1, - 1, 1,
  15724. 1, 1, - 1, 1, 1, 1,
  15725. // (0, ±1/φ, ±φ)
  15726. 0, - r, - t, 0, - r, t,
  15727. 0, r, - t, 0, r, t,
  15728. // (±1/φ, ±φ, 0)
  15729. - r, - t, 0, - r, t, 0,
  15730. r, - t, 0, r, t, 0,
  15731. // (±φ, 0, ±1/φ)
  15732. - t, 0, - r, t, 0, - r,
  15733. - t, 0, r, t, 0, r
  15734. ];
  15735. var indices = [
  15736. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  15737. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  15738. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  15739. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  15740. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  15741. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  15742. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  15743. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  15744. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  15745. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  15746. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  15747. 1, 12, 14, 1, 14, 5, 1, 5, 9
  15748. ];
  15749. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  15750. this.type = 'DodecahedronBufferGeometry';
  15751. this.parameters = {
  15752. radius: radius,
  15753. detail: detail
  15754. };
  15755. }
  15756. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  15757. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  15758. /**
  15759. * @author oosmoxiecode / https://github.com/oosmoxiecode
  15760. * @author WestLangley / https://github.com/WestLangley
  15761. * @author zz85 / https://github.com/zz85
  15762. * @author miningold / https://github.com/miningold
  15763. * @author jonobr1 / https://github.com/jonobr1
  15764. * @author Mugen87 / https://github.com/Mugen87
  15765. *
  15766. */
  15767. // TubeGeometry
  15768. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  15769. Geometry.call( this );
  15770. this.type = 'TubeGeometry';
  15771. this.parameters = {
  15772. path: path,
  15773. tubularSegments: tubularSegments,
  15774. radius: radius,
  15775. radialSegments: radialSegments,
  15776. closed: closed
  15777. };
  15778. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  15779. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  15780. // expose internals
  15781. this.tangents = bufferGeometry.tangents;
  15782. this.normals = bufferGeometry.normals;
  15783. this.binormals = bufferGeometry.binormals;
  15784. // create geometry
  15785. this.fromBufferGeometry( bufferGeometry );
  15786. this.mergeVertices();
  15787. }
  15788. TubeGeometry.prototype = Object.create( Geometry.prototype );
  15789. TubeGeometry.prototype.constructor = TubeGeometry;
  15790. // TubeBufferGeometry
  15791. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  15792. BufferGeometry.call( this );
  15793. this.type = 'TubeBufferGeometry';
  15794. this.parameters = {
  15795. path: path,
  15796. tubularSegments: tubularSegments,
  15797. radius: radius,
  15798. radialSegments: radialSegments,
  15799. closed: closed
  15800. };
  15801. tubularSegments = tubularSegments || 64;
  15802. radius = radius || 1;
  15803. radialSegments = radialSegments || 8;
  15804. closed = closed || false;
  15805. var frames = path.computeFrenetFrames( tubularSegments, closed );
  15806. // expose internals
  15807. this.tangents = frames.tangents;
  15808. this.normals = frames.normals;
  15809. this.binormals = frames.binormals;
  15810. // helper variables
  15811. var vertex = new Vector3();
  15812. var normal = new Vector3();
  15813. var uv = new Vector2();
  15814. var P = new Vector3();
  15815. var i, j;
  15816. // buffer
  15817. var vertices = [];
  15818. var normals = [];
  15819. var uvs = [];
  15820. var indices = [];
  15821. // create buffer data
  15822. generateBufferData();
  15823. // build geometry
  15824. this.setIndex( indices );
  15825. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  15826. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  15827. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  15828. // functions
  15829. function generateBufferData() {
  15830. for ( i = 0; i < tubularSegments; i ++ ) {
  15831. generateSegment( i );
  15832. }
  15833. // if the geometry is not closed, generate the last row of vertices and normals
  15834. // at the regular position on the given path
  15835. //
  15836. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  15837. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  15838. // uvs are generated in a separate function.
  15839. // this makes it easy compute correct values for closed geometries
  15840. generateUVs();
  15841. // finally create faces
  15842. generateIndices();
  15843. }
  15844. function generateSegment( i ) {
  15845. // we use getPointAt to sample evenly distributed points from the given path
  15846. P = path.getPointAt( i / tubularSegments, P );
  15847. // retrieve corresponding normal and binormal
  15848. var N = frames.normals[ i ];
  15849. var B = frames.binormals[ i ];
  15850. // generate normals and vertices for the current segment
  15851. for ( j = 0; j <= radialSegments; j ++ ) {
  15852. var v = j / radialSegments * Math.PI * 2;
  15853. var sin = Math.sin( v );
  15854. var cos = - Math.cos( v );
  15855. // normal
  15856. normal.x = ( cos * N.x + sin * B.x );
  15857. normal.y = ( cos * N.y + sin * B.y );
  15858. normal.z = ( cos * N.z + sin * B.z );
  15859. normal.normalize();
  15860. normals.push( normal.x, normal.y, normal.z );
  15861. // vertex
  15862. vertex.x = P.x + radius * normal.x;
  15863. vertex.y = P.y + radius * normal.y;
  15864. vertex.z = P.z + radius * normal.z;
  15865. vertices.push( vertex.x, vertex.y, vertex.z );
  15866. }
  15867. }
  15868. function generateIndices() {
  15869. for ( j = 1; j <= tubularSegments; j ++ ) {
  15870. for ( i = 1; i <= radialSegments; i ++ ) {
  15871. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  15872. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  15873. var c = ( radialSegments + 1 ) * j + i;
  15874. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  15875. // faces
  15876. indices.push( a, b, d );
  15877. indices.push( b, c, d );
  15878. }
  15879. }
  15880. }
  15881. function generateUVs() {
  15882. for ( i = 0; i <= tubularSegments; i ++ ) {
  15883. for ( j = 0; j <= radialSegments; j ++ ) {
  15884. uv.x = i / tubularSegments;
  15885. uv.y = j / radialSegments;
  15886. uvs.push( uv.x, uv.y );
  15887. }
  15888. }
  15889. }
  15890. }
  15891. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15892. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  15893. /**
  15894. * @author oosmoxiecode
  15895. * @author Mugen87 / https://github.com/Mugen87
  15896. *
  15897. * based on http://www.blackpawn.com/texts/pqtorus/
  15898. */
  15899. // TorusKnotGeometry
  15900. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  15901. Geometry.call( this );
  15902. this.type = 'TorusKnotGeometry';
  15903. this.parameters = {
  15904. radius: radius,
  15905. tube: tube,
  15906. tubularSegments: tubularSegments,
  15907. radialSegments: radialSegments,
  15908. p: p,
  15909. q: q
  15910. };
  15911. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  15912. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  15913. this.mergeVertices();
  15914. }
  15915. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  15916. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  15917. // TorusKnotBufferGeometry
  15918. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  15919. BufferGeometry.call( this );
  15920. this.type = 'TorusKnotBufferGeometry';
  15921. this.parameters = {
  15922. radius: radius,
  15923. tube: tube,
  15924. tubularSegments: tubularSegments,
  15925. radialSegments: radialSegments,
  15926. p: p,
  15927. q: q
  15928. };
  15929. radius = radius || 1;
  15930. tube = tube || 0.4;
  15931. tubularSegments = Math.floor( tubularSegments ) || 64;
  15932. radialSegments = Math.floor( radialSegments ) || 8;
  15933. p = p || 2;
  15934. q = q || 3;
  15935. // buffers
  15936. var indices = [];
  15937. var vertices = [];
  15938. var normals = [];
  15939. var uvs = [];
  15940. // helper variables
  15941. var i, j;
  15942. var vertex = new Vector3();
  15943. var normal = new Vector3();
  15944. var P1 = new Vector3();
  15945. var P2 = new Vector3();
  15946. var B = new Vector3();
  15947. var T = new Vector3();
  15948. var N = new Vector3();
  15949. // generate vertices, normals and uvs
  15950. for ( i = 0; i <= tubularSegments; ++ i ) {
  15951. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  15952. var u = i / tubularSegments * p * Math.PI * 2;
  15953. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  15954. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  15955. calculatePositionOnCurve( u, p, q, radius, P1 );
  15956. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  15957. // calculate orthonormal basis
  15958. T.subVectors( P2, P1 );
  15959. N.addVectors( P2, P1 );
  15960. B.crossVectors( T, N );
  15961. N.crossVectors( B, T );
  15962. // normalize B, N. T can be ignored, we don't use it
  15963. B.normalize();
  15964. N.normalize();
  15965. for ( j = 0; j <= radialSegments; ++ j ) {
  15966. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  15967. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  15968. var v = j / radialSegments * Math.PI * 2;
  15969. var cx = - tube * Math.cos( v );
  15970. var cy = tube * Math.sin( v );
  15971. // now calculate the final vertex position.
  15972. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  15973. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  15974. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  15975. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  15976. vertices.push( vertex.x, vertex.y, vertex.z );
  15977. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  15978. normal.subVectors( vertex, P1 ).normalize();
  15979. normals.push( normal.x, normal.y, normal.z );
  15980. // uv
  15981. uvs.push( i / tubularSegments );
  15982. uvs.push( j / radialSegments );
  15983. }
  15984. }
  15985. // generate indices
  15986. for ( j = 1; j <= tubularSegments; j ++ ) {
  15987. for ( i = 1; i <= radialSegments; i ++ ) {
  15988. // indices
  15989. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  15990. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  15991. var c = ( radialSegments + 1 ) * j + i;
  15992. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  15993. // faces
  15994. indices.push( a, b, d );
  15995. indices.push( b, c, d );
  15996. }
  15997. }
  15998. // build geometry
  15999. this.setIndex( indices );
  16000. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16001. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16002. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16003. // this function calculates the current position on the torus curve
  16004. function calculatePositionOnCurve( u, p, q, radius, position ) {
  16005. var cu = Math.cos( u );
  16006. var su = Math.sin( u );
  16007. var quOverP = q / p * u;
  16008. var cs = Math.cos( quOverP );
  16009. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  16010. position.y = radius * ( 2 + cs ) * su * 0.5;
  16011. position.z = radius * Math.sin( quOverP ) * 0.5;
  16012. }
  16013. }
  16014. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16015. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  16016. /**
  16017. * @author oosmoxiecode
  16018. * @author mrdoob / http://mrdoob.com/
  16019. * @author Mugen87 / https://github.com/Mugen87
  16020. */
  16021. // TorusGeometry
  16022. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  16023. Geometry.call( this );
  16024. this.type = 'TorusGeometry';
  16025. this.parameters = {
  16026. radius: radius,
  16027. tube: tube,
  16028. radialSegments: radialSegments,
  16029. tubularSegments: tubularSegments,
  16030. arc: arc
  16031. };
  16032. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  16033. this.mergeVertices();
  16034. }
  16035. TorusGeometry.prototype = Object.create( Geometry.prototype );
  16036. TorusGeometry.prototype.constructor = TorusGeometry;
  16037. // TorusBufferGeometry
  16038. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  16039. BufferGeometry.call( this );
  16040. this.type = 'TorusBufferGeometry';
  16041. this.parameters = {
  16042. radius: radius,
  16043. tube: tube,
  16044. radialSegments: radialSegments,
  16045. tubularSegments: tubularSegments,
  16046. arc: arc
  16047. };
  16048. radius = radius || 1;
  16049. tube = tube || 0.4;
  16050. radialSegments = Math.floor( radialSegments ) || 8;
  16051. tubularSegments = Math.floor( tubularSegments ) || 6;
  16052. arc = arc || Math.PI * 2;
  16053. // buffers
  16054. var indices = [];
  16055. var vertices = [];
  16056. var normals = [];
  16057. var uvs = [];
  16058. // helper variables
  16059. var center = new Vector3();
  16060. var vertex = new Vector3();
  16061. var normal = new Vector3();
  16062. var j, i;
  16063. // generate vertices, normals and uvs
  16064. for ( j = 0; j <= radialSegments; j ++ ) {
  16065. for ( i = 0; i <= tubularSegments; i ++ ) {
  16066. var u = i / tubularSegments * arc;
  16067. var v = j / radialSegments * Math.PI * 2;
  16068. // vertex
  16069. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  16070. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  16071. vertex.z = tube * Math.sin( v );
  16072. vertices.push( vertex.x, vertex.y, vertex.z );
  16073. // normal
  16074. center.x = radius * Math.cos( u );
  16075. center.y = radius * Math.sin( u );
  16076. normal.subVectors( vertex, center ).normalize();
  16077. normals.push( normal.x, normal.y, normal.z );
  16078. // uv
  16079. uvs.push( i / tubularSegments );
  16080. uvs.push( j / radialSegments );
  16081. }
  16082. }
  16083. // generate indices
  16084. for ( j = 1; j <= radialSegments; j ++ ) {
  16085. for ( i = 1; i <= tubularSegments; i ++ ) {
  16086. // indices
  16087. var a = ( tubularSegments + 1 ) * j + i - 1;
  16088. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  16089. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  16090. var d = ( tubularSegments + 1 ) * j + i;
  16091. // faces
  16092. indices.push( a, b, d );
  16093. indices.push( b, c, d );
  16094. }
  16095. }
  16096. // build geometry
  16097. this.setIndex( indices );
  16098. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16099. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16100. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16101. }
  16102. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16103. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  16104. /**
  16105. * @author Mugen87 / https://github.com/Mugen87
  16106. * Port from https://github.com/mapbox/earcut (v2.1.2)
  16107. */
  16108. var Earcut = {
  16109. triangulate: function ( data, holeIndices, dim ) {
  16110. dim = dim || 2;
  16111. var hasHoles = holeIndices && holeIndices.length,
  16112. outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length,
  16113. outerNode = linkedList( data, 0, outerLen, dim, true ),
  16114. triangles = [];
  16115. if ( ! outerNode ) return triangles;
  16116. var minX, minY, maxX, maxY, x, y, invSize;
  16117. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  16118. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  16119. if ( data.length > 80 * dim ) {
  16120. minX = maxX = data[ 0 ];
  16121. minY = maxY = data[ 1 ];
  16122. for ( var i = dim; i < outerLen; i += dim ) {
  16123. x = data[ i ];
  16124. y = data[ i + 1 ];
  16125. if ( x < minX ) minX = x;
  16126. if ( y < minY ) minY = y;
  16127. if ( x > maxX ) maxX = x;
  16128. if ( y > maxY ) maxY = y;
  16129. }
  16130. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  16131. invSize = Math.max( maxX - minX, maxY - minY );
  16132. invSize = invSize !== 0 ? 1 / invSize : 0;
  16133. }
  16134. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  16135. return triangles;
  16136. }
  16137. };
  16138. // create a circular doubly linked list from polygon points in the specified winding order
  16139. function linkedList( data, start, end, dim, clockwise ) {
  16140. var i, last;
  16141. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  16142. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  16143. } else {
  16144. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  16145. }
  16146. if ( last && equals( last, last.next ) ) {
  16147. removeNode( last );
  16148. last = last.next;
  16149. }
  16150. return last;
  16151. }
  16152. // eliminate colinear or duplicate points
  16153. function filterPoints( start, end ) {
  16154. if ( ! start ) return start;
  16155. if ( ! end ) end = start;
  16156. var p = start, again;
  16157. do {
  16158. again = false;
  16159. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  16160. removeNode( p );
  16161. p = end = p.prev;
  16162. if ( p === p.next ) break;
  16163. again = true;
  16164. } else {
  16165. p = p.next;
  16166. }
  16167. } while ( again || p !== end );
  16168. return end;
  16169. }
  16170. // main ear slicing loop which triangulates a polygon (given as a linked list)
  16171. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  16172. if ( ! ear ) return;
  16173. // interlink polygon nodes in z-order
  16174. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  16175. var stop = ear, prev, next;
  16176. // iterate through ears, slicing them one by one
  16177. while ( ear.prev !== ear.next ) {
  16178. prev = ear.prev;
  16179. next = ear.next;
  16180. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  16181. // cut off the triangle
  16182. triangles.push( prev.i / dim );
  16183. triangles.push( ear.i / dim );
  16184. triangles.push( next.i / dim );
  16185. removeNode( ear );
  16186. // skipping the next vertice leads to less sliver triangles
  16187. ear = next.next;
  16188. stop = next.next;
  16189. continue;
  16190. }
  16191. ear = next;
  16192. // if we looped through the whole remaining polygon and can't find any more ears
  16193. if ( ear === stop ) {
  16194. // try filtering points and slicing again
  16195. if ( ! pass ) {
  16196. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  16197. // if this didn't work, try curing all small self-intersections locally
  16198. } else if ( pass === 1 ) {
  16199. ear = cureLocalIntersections( ear, triangles, dim );
  16200. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  16201. // as a last resort, try splitting the remaining polygon into two
  16202. } else if ( pass === 2 ) {
  16203. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  16204. }
  16205. break;
  16206. }
  16207. }
  16208. }
  16209. // check whether a polygon node forms a valid ear with adjacent nodes
  16210. function isEar( ear ) {
  16211. var a = ear.prev,
  16212. b = ear,
  16213. c = ear.next;
  16214. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  16215. // now make sure we don't have other points inside the potential ear
  16216. var p = ear.next.next;
  16217. while ( p !== ear.prev ) {
  16218. 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 ) {
  16219. return false;
  16220. }
  16221. p = p.next;
  16222. }
  16223. return true;
  16224. }
  16225. function isEarHashed( ear, minX, minY, invSize ) {
  16226. var a = ear.prev,
  16227. b = ear,
  16228. c = ear.next;
  16229. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  16230. // triangle bbox; min & max are calculated like this for speed
  16231. var minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  16232. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  16233. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  16234. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  16235. // z-order range for the current triangle bbox;
  16236. var minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  16237. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  16238. // first look for points inside the triangle in increasing z-order
  16239. var p = ear.nextZ;
  16240. while ( p && p.z <= maxZ ) {
  16241. if ( p !== ear.prev && p !== ear.next &&
  16242. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  16243. area( p.prev, p, p.next ) >= 0 ) return false;
  16244. p = p.nextZ;
  16245. }
  16246. // then look for points in decreasing z-order
  16247. p = ear.prevZ;
  16248. while ( p && p.z >= minZ ) {
  16249. if ( p !== ear.prev && p !== ear.next &&
  16250. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  16251. area( p.prev, p, p.next ) >= 0 ) return false;
  16252. p = p.prevZ;
  16253. }
  16254. return true;
  16255. }
  16256. // go through all polygon nodes and cure small local self-intersections
  16257. function cureLocalIntersections( start, triangles, dim ) {
  16258. var p = start;
  16259. do {
  16260. var a = p.prev, b = p.next.next;
  16261. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  16262. triangles.push( a.i / dim );
  16263. triangles.push( p.i / dim );
  16264. triangles.push( b.i / dim );
  16265. // remove two nodes involved
  16266. removeNode( p );
  16267. removeNode( p.next );
  16268. p = start = b;
  16269. }
  16270. p = p.next;
  16271. } while ( p !== start );
  16272. return p;
  16273. }
  16274. // try splitting polygon into two and triangulate them independently
  16275. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  16276. // look for a valid diagonal that divides the polygon into two
  16277. var a = start;
  16278. do {
  16279. var b = a.next.next;
  16280. while ( b !== a.prev ) {
  16281. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  16282. // split the polygon in two by the diagonal
  16283. var c = splitPolygon( a, b );
  16284. // filter colinear points around the cuts
  16285. a = filterPoints( a, a.next );
  16286. c = filterPoints( c, c.next );
  16287. // run earcut on each half
  16288. earcutLinked( a, triangles, dim, minX, minY, invSize );
  16289. earcutLinked( c, triangles, dim, minX, minY, invSize );
  16290. return;
  16291. }
  16292. b = b.next;
  16293. }
  16294. a = a.next;
  16295. } while ( a !== start );
  16296. }
  16297. // link every hole into the outer loop, producing a single-ring polygon without holes
  16298. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  16299. var queue = [], i, len, start, end, list;
  16300. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  16301. start = holeIndices[ i ] * dim;
  16302. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  16303. list = linkedList( data, start, end, dim, false );
  16304. if ( list === list.next ) list.steiner = true;
  16305. queue.push( getLeftmost( list ) );
  16306. }
  16307. queue.sort( compareX );
  16308. // process holes from left to right
  16309. for ( i = 0; i < queue.length; i ++ ) {
  16310. eliminateHole( queue[ i ], outerNode );
  16311. outerNode = filterPoints( outerNode, outerNode.next );
  16312. }
  16313. return outerNode;
  16314. }
  16315. function compareX( a, b ) {
  16316. return a.x - b.x;
  16317. }
  16318. // find a bridge between vertices that connects hole with an outer ring and and link it
  16319. function eliminateHole( hole, outerNode ) {
  16320. outerNode = findHoleBridge( hole, outerNode );
  16321. if ( outerNode ) {
  16322. var b = splitPolygon( outerNode, hole );
  16323. filterPoints( b, b.next );
  16324. }
  16325. }
  16326. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  16327. function findHoleBridge( hole, outerNode ) {
  16328. var p = outerNode,
  16329. hx = hole.x,
  16330. hy = hole.y,
  16331. qx = - Infinity,
  16332. m;
  16333. // find a segment intersected by a ray from the hole's leftmost point to the left;
  16334. // segment's endpoint with lesser x will be potential connection point
  16335. do {
  16336. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  16337. var x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  16338. if ( x <= hx && x > qx ) {
  16339. qx = x;
  16340. if ( x === hx ) {
  16341. if ( hy === p.y ) return p;
  16342. if ( hy === p.next.y ) return p.next;
  16343. }
  16344. m = p.x < p.next.x ? p : p.next;
  16345. }
  16346. }
  16347. p = p.next;
  16348. } while ( p !== outerNode );
  16349. if ( ! m ) return null;
  16350. if ( hx === qx ) return m.prev; // hole touches outer segment; pick lower endpoint
  16351. // look for points inside the triangle of hole point, segment intersection and endpoint;
  16352. // if there are no points found, we have a valid connection;
  16353. // otherwise choose the point of the minimum angle with the ray as connection point
  16354. var stop = m,
  16355. mx = m.x,
  16356. my = m.y,
  16357. tanMin = Infinity,
  16358. tan;
  16359. p = m.next;
  16360. while ( p !== stop ) {
  16361. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  16362. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  16363. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  16364. if ( ( tan < tanMin || ( tan === tanMin && p.x > m.x ) ) && locallyInside( p, hole ) ) {
  16365. m = p;
  16366. tanMin = tan;
  16367. }
  16368. }
  16369. p = p.next;
  16370. }
  16371. return m;
  16372. }
  16373. // interlink polygon nodes in z-order
  16374. function indexCurve( start, minX, minY, invSize ) {
  16375. var p = start;
  16376. do {
  16377. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  16378. p.prevZ = p.prev;
  16379. p.nextZ = p.next;
  16380. p = p.next;
  16381. } while ( p !== start );
  16382. p.prevZ.nextZ = null;
  16383. p.prevZ = null;
  16384. sortLinked( p );
  16385. }
  16386. // Simon Tatham's linked list merge sort algorithm
  16387. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  16388. function sortLinked( list ) {
  16389. var i, p, q, e, tail, numMerges, pSize, qSize, inSize = 1;
  16390. do {
  16391. p = list;
  16392. list = null;
  16393. tail = null;
  16394. numMerges = 0;
  16395. while ( p ) {
  16396. numMerges ++;
  16397. q = p;
  16398. pSize = 0;
  16399. for ( i = 0; i < inSize; i ++ ) {
  16400. pSize ++;
  16401. q = q.nextZ;
  16402. if ( ! q ) break;
  16403. }
  16404. qSize = inSize;
  16405. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  16406. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  16407. e = p;
  16408. p = p.nextZ;
  16409. pSize --;
  16410. } else {
  16411. e = q;
  16412. q = q.nextZ;
  16413. qSize --;
  16414. }
  16415. if ( tail ) tail.nextZ = e;
  16416. else list = e;
  16417. e.prevZ = tail;
  16418. tail = e;
  16419. }
  16420. p = q;
  16421. }
  16422. tail.nextZ = null;
  16423. inSize *= 2;
  16424. } while ( numMerges > 1 );
  16425. return list;
  16426. }
  16427. // z-order of a point given coords and inverse of the longer side of data bbox
  16428. function zOrder( x, y, minX, minY, invSize ) {
  16429. // coords are transformed into non-negative 15-bit integer range
  16430. x = 32767 * ( x - minX ) * invSize;
  16431. y = 32767 * ( y - minY ) * invSize;
  16432. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  16433. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  16434. x = ( x | ( x << 2 ) ) & 0x33333333;
  16435. x = ( x | ( x << 1 ) ) & 0x55555555;
  16436. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  16437. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  16438. y = ( y | ( y << 2 ) ) & 0x33333333;
  16439. y = ( y | ( y << 1 ) ) & 0x55555555;
  16440. return x | ( y << 1 );
  16441. }
  16442. // find the leftmost node of a polygon ring
  16443. function getLeftmost( start ) {
  16444. var p = start, leftmost = start;
  16445. do {
  16446. if ( p.x < leftmost.x ) leftmost = p;
  16447. p = p.next;
  16448. } while ( p !== start );
  16449. return leftmost;
  16450. }
  16451. // check if a point lies within a convex triangle
  16452. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  16453. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  16454. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  16455. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  16456. }
  16457. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  16458. function isValidDiagonal( a, b ) {
  16459. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) &&
  16460. locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b );
  16461. }
  16462. // signed area of a triangle
  16463. function area( p, q, r ) {
  16464. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  16465. }
  16466. // check if two points are equal
  16467. function equals( p1, p2 ) {
  16468. return p1.x === p2.x && p1.y === p2.y;
  16469. }
  16470. // check if two segments intersect
  16471. function intersects( p1, q1, p2, q2 ) {
  16472. if ( ( equals( p1, q1 ) && equals( p2, q2 ) ) ||
  16473. ( equals( p1, q2 ) && equals( p2, q1 ) ) ) return true;
  16474. return area( p1, q1, p2 ) > 0 !== area( p1, q1, q2 ) > 0 &&
  16475. area( p2, q2, p1 ) > 0 !== area( p2, q2, q1 ) > 0;
  16476. }
  16477. // check if a polygon diagonal intersects any polygon segments
  16478. function intersectsPolygon( a, b ) {
  16479. var p = a;
  16480. do {
  16481. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  16482. intersects( p, p.next, a, b ) ) {
  16483. return true;
  16484. }
  16485. p = p.next;
  16486. } while ( p !== a );
  16487. return false;
  16488. }
  16489. // check if a polygon diagonal is locally inside the polygon
  16490. function locallyInside( a, b ) {
  16491. return area( a.prev, a, a.next ) < 0 ?
  16492. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  16493. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  16494. }
  16495. // check if the middle point of a polygon diagonal is inside the polygon
  16496. function middleInside( a, b ) {
  16497. var p = a,
  16498. inside = false,
  16499. px = ( a.x + b.x ) / 2,
  16500. py = ( a.y + b.y ) / 2;
  16501. do {
  16502. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  16503. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) ) {
  16504. inside = ! inside;
  16505. }
  16506. p = p.next;
  16507. } while ( p !== a );
  16508. return inside;
  16509. }
  16510. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  16511. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  16512. function splitPolygon( a, b ) {
  16513. var a2 = new Node( a.i, a.x, a.y ),
  16514. b2 = new Node( b.i, b.x, b.y ),
  16515. an = a.next,
  16516. bp = b.prev;
  16517. a.next = b;
  16518. b.prev = a;
  16519. a2.next = an;
  16520. an.prev = a2;
  16521. b2.next = a2;
  16522. a2.prev = b2;
  16523. bp.next = b2;
  16524. b2.prev = bp;
  16525. return b2;
  16526. }
  16527. // create a node and optionally link it with previous one (in a circular doubly linked list)
  16528. function insertNode( i, x, y, last ) {
  16529. var p = new Node( i, x, y );
  16530. if ( ! last ) {
  16531. p.prev = p;
  16532. p.next = p;
  16533. } else {
  16534. p.next = last.next;
  16535. p.prev = last;
  16536. last.next.prev = p;
  16537. last.next = p;
  16538. }
  16539. return p;
  16540. }
  16541. function removeNode( p ) {
  16542. p.next.prev = p.prev;
  16543. p.prev.next = p.next;
  16544. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  16545. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  16546. }
  16547. function Node( i, x, y ) {
  16548. // vertice index in coordinates array
  16549. this.i = i;
  16550. // vertex coordinates
  16551. this.x = x;
  16552. this.y = y;
  16553. // previous and next vertice nodes in a polygon ring
  16554. this.prev = null;
  16555. this.next = null;
  16556. // z-order curve value
  16557. this.z = null;
  16558. // previous and next nodes in z-order
  16559. this.prevZ = null;
  16560. this.nextZ = null;
  16561. // indicates whether this is a steiner point
  16562. this.steiner = false;
  16563. }
  16564. function signedArea( data, start, end, dim ) {
  16565. var sum = 0;
  16566. for ( var i = start, j = end - dim; i < end; i += dim ) {
  16567. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  16568. j = i;
  16569. }
  16570. return sum;
  16571. }
  16572. /**
  16573. * @author zz85 / http://www.lab4games.net/zz85/blog
  16574. */
  16575. var ShapeUtils = {
  16576. // calculate area of the contour polygon
  16577. area: function ( contour ) {
  16578. var n = contour.length;
  16579. var a = 0.0;
  16580. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  16581. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  16582. }
  16583. return a * 0.5;
  16584. },
  16585. isClockWise: function ( pts ) {
  16586. return ShapeUtils.area( pts ) < 0;
  16587. },
  16588. triangulateShape: function ( contour, holes ) {
  16589. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  16590. var holeIndices = []; // array of hole indices
  16591. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  16592. removeDupEndPts( contour );
  16593. addContour( vertices, contour );
  16594. //
  16595. var holeIndex = contour.length;
  16596. holes.forEach( removeDupEndPts );
  16597. for ( var i = 0; i < holes.length; i ++ ) {
  16598. holeIndices.push( holeIndex );
  16599. holeIndex += holes[ i ].length;
  16600. addContour( vertices, holes[ i ] );
  16601. }
  16602. //
  16603. var triangles = Earcut.triangulate( vertices, holeIndices );
  16604. //
  16605. for ( var i = 0; i < triangles.length; i += 3 ) {
  16606. faces.push( triangles.slice( i, i + 3 ) );
  16607. }
  16608. return faces;
  16609. }
  16610. };
  16611. function removeDupEndPts( points ) {
  16612. var l = points.length;
  16613. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  16614. points.pop();
  16615. }
  16616. }
  16617. function addContour( vertices, contour ) {
  16618. for ( var i = 0; i < contour.length; i ++ ) {
  16619. vertices.push( contour[ i ].x );
  16620. vertices.push( contour[ i ].y );
  16621. }
  16622. }
  16623. /**
  16624. * @author zz85 / http://www.lab4games.net/zz85/blog
  16625. *
  16626. * Creates extruded geometry from a path shape.
  16627. *
  16628. * parameters = {
  16629. *
  16630. * curveSegments: <int>, // number of points on the curves
  16631. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  16632. * depth: <float>, // Depth to extrude the shape
  16633. *
  16634. * bevelEnabled: <bool>, // turn on bevel
  16635. * bevelThickness: <float>, // how deep into the original shape bevel goes
  16636. * bevelSize: <float>, // how far from shape outline is bevel
  16637. * bevelSegments: <int>, // number of bevel layers
  16638. *
  16639. * extrudePath: <THREE.Curve> // curve to extrude shape along
  16640. *
  16641. * UVGenerator: <Object> // object that provides UV generator functions
  16642. *
  16643. * }
  16644. */
  16645. // ExtrudeGeometry
  16646. function ExtrudeGeometry( shapes, options ) {
  16647. Geometry.call( this );
  16648. this.type = 'ExtrudeGeometry';
  16649. this.parameters = {
  16650. shapes: shapes,
  16651. options: options
  16652. };
  16653. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  16654. this.mergeVertices();
  16655. }
  16656. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  16657. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  16658. // ExtrudeBufferGeometry
  16659. function ExtrudeBufferGeometry( shapes, options ) {
  16660. BufferGeometry.call( this );
  16661. this.type = 'ExtrudeBufferGeometry';
  16662. this.parameters = {
  16663. shapes: shapes,
  16664. options: options
  16665. };
  16666. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  16667. var scope = this;
  16668. var verticesArray = [];
  16669. var uvArray = [];
  16670. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  16671. var shape = shapes[ i ];
  16672. addShape( shape );
  16673. }
  16674. // build geometry
  16675. this.addAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  16676. this.addAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  16677. this.computeVertexNormals();
  16678. // functions
  16679. function addShape( shape ) {
  16680. var placeholder = [];
  16681. // options
  16682. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  16683. var steps = options.steps !== undefined ? options.steps : 1;
  16684. var depth = options.depth !== undefined ? options.depth : 100;
  16685. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  16686. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  16687. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  16688. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  16689. var extrudePath = options.extrudePath;
  16690. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  16691. // deprecated options
  16692. if ( options.amount !== undefined ) {
  16693. console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' );
  16694. depth = options.amount;
  16695. }
  16696. //
  16697. var extrudePts, extrudeByPath = false;
  16698. var splineTube, binormal, normal, position2;
  16699. if ( extrudePath ) {
  16700. extrudePts = extrudePath.getSpacedPoints( steps );
  16701. extrudeByPath = true;
  16702. bevelEnabled = false; // bevels not supported for path extrusion
  16703. // SETUP TNB variables
  16704. // TODO1 - have a .isClosed in spline?
  16705. splineTube = extrudePath.computeFrenetFrames( steps, false );
  16706. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  16707. binormal = new Vector3();
  16708. normal = new Vector3();
  16709. position2 = new Vector3();
  16710. }
  16711. // Safeguards if bevels are not enabled
  16712. if ( ! bevelEnabled ) {
  16713. bevelSegments = 0;
  16714. bevelThickness = 0;
  16715. bevelSize = 0;
  16716. }
  16717. // Variables initialization
  16718. var ahole, h, hl; // looping of holes
  16719. var shapePoints = shape.extractPoints( curveSegments );
  16720. var vertices = shapePoints.shape;
  16721. var holes = shapePoints.holes;
  16722. var reverse = ! ShapeUtils.isClockWise( vertices );
  16723. if ( reverse ) {
  16724. vertices = vertices.reverse();
  16725. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  16726. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16727. ahole = holes[ h ];
  16728. if ( ShapeUtils.isClockWise( ahole ) ) {
  16729. holes[ h ] = ahole.reverse();
  16730. }
  16731. }
  16732. }
  16733. var faces = ShapeUtils.triangulateShape( vertices, holes );
  16734. /* Vertices */
  16735. var contour = vertices; // vertices has all points but contour has only points of circumference
  16736. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16737. ahole = holes[ h ];
  16738. vertices = vertices.concat( ahole );
  16739. }
  16740. function scalePt2( pt, vec, size ) {
  16741. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  16742. return vec.clone().multiplyScalar( size ).add( pt );
  16743. }
  16744. var b, bs, t, z,
  16745. vert, vlen = vertices.length,
  16746. face, flen = faces.length;
  16747. // Find directions for point movement
  16748. function getBevelVec( inPt, inPrev, inNext ) {
  16749. // computes for inPt the corresponding point inPt' on a new contour
  16750. // shifted by 1 unit (length of normalized vector) to the left
  16751. // if we walk along contour clockwise, this new contour is outside the old one
  16752. //
  16753. // inPt' is the intersection of the two lines parallel to the two
  16754. // adjacent edges of inPt at a distance of 1 unit on the left side.
  16755. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  16756. // good reading for geometry algorithms (here: line-line intersection)
  16757. // http://geomalgorithms.com/a05-_intersect-1.html
  16758. var v_prev_x = inPt.x - inPrev.x,
  16759. v_prev_y = inPt.y - inPrev.y;
  16760. var v_next_x = inNext.x - inPt.x,
  16761. v_next_y = inNext.y - inPt.y;
  16762. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  16763. // check for collinear edges
  16764. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  16765. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  16766. // not collinear
  16767. // length of vectors for normalizing
  16768. var v_prev_len = Math.sqrt( v_prev_lensq );
  16769. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  16770. // shift adjacent points by unit vectors to the left
  16771. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  16772. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  16773. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  16774. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  16775. // scaling factor for v_prev to intersection point
  16776. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  16777. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  16778. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  16779. // vector from inPt to intersection point
  16780. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  16781. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  16782. // Don't normalize!, otherwise sharp corners become ugly
  16783. // but prevent crazy spikes
  16784. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  16785. if ( v_trans_lensq <= 2 ) {
  16786. return new Vector2( v_trans_x, v_trans_y );
  16787. } else {
  16788. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  16789. }
  16790. } else {
  16791. // handle special case of collinear edges
  16792. var direction_eq = false; // assumes: opposite
  16793. if ( v_prev_x > Number.EPSILON ) {
  16794. if ( v_next_x > Number.EPSILON ) {
  16795. direction_eq = true;
  16796. }
  16797. } else {
  16798. if ( v_prev_x < - Number.EPSILON ) {
  16799. if ( v_next_x < - Number.EPSILON ) {
  16800. direction_eq = true;
  16801. }
  16802. } else {
  16803. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  16804. direction_eq = true;
  16805. }
  16806. }
  16807. }
  16808. if ( direction_eq ) {
  16809. // console.log("Warning: lines are a straight sequence");
  16810. v_trans_x = - v_prev_y;
  16811. v_trans_y = v_prev_x;
  16812. shrink_by = Math.sqrt( v_prev_lensq );
  16813. } else {
  16814. // console.log("Warning: lines are a straight spike");
  16815. v_trans_x = v_prev_x;
  16816. v_trans_y = v_prev_y;
  16817. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  16818. }
  16819. }
  16820. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  16821. }
  16822. var contourMovements = [];
  16823. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  16824. if ( j === il ) j = 0;
  16825. if ( k === il ) k = 0;
  16826. // (j)---(i)---(k)
  16827. // console.log('i,j,k', i, j , k)
  16828. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  16829. }
  16830. var holesMovements = [],
  16831. oneHoleMovements, verticesMovements = contourMovements.concat();
  16832. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16833. ahole = holes[ h ];
  16834. oneHoleMovements = [];
  16835. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  16836. if ( j === il ) j = 0;
  16837. if ( k === il ) k = 0;
  16838. // (j)---(i)---(k)
  16839. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  16840. }
  16841. holesMovements.push( oneHoleMovements );
  16842. verticesMovements = verticesMovements.concat( oneHoleMovements );
  16843. }
  16844. // Loop bevelSegments, 1 for the front, 1 for the back
  16845. for ( b = 0; b < bevelSegments; b ++ ) {
  16846. //for ( b = bevelSegments; b > 0; b -- ) {
  16847. t = b / bevelSegments;
  16848. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  16849. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  16850. // contract shape
  16851. for ( i = 0, il = contour.length; i < il; i ++ ) {
  16852. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  16853. v( vert.x, vert.y, - z );
  16854. }
  16855. // expand holes
  16856. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16857. ahole = holes[ h ];
  16858. oneHoleMovements = holesMovements[ h ];
  16859. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  16860. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  16861. v( vert.x, vert.y, - z );
  16862. }
  16863. }
  16864. }
  16865. bs = bevelSize;
  16866. // Back facing vertices
  16867. for ( i = 0; i < vlen; i ++ ) {
  16868. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  16869. if ( ! extrudeByPath ) {
  16870. v( vert.x, vert.y, 0 );
  16871. } else {
  16872. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  16873. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  16874. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  16875. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  16876. v( position2.x, position2.y, position2.z );
  16877. }
  16878. }
  16879. // Add stepped vertices...
  16880. // Including front facing vertices
  16881. var s;
  16882. for ( s = 1; s <= steps; s ++ ) {
  16883. for ( i = 0; i < vlen; i ++ ) {
  16884. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  16885. if ( ! extrudeByPath ) {
  16886. v( vert.x, vert.y, depth / steps * s );
  16887. } else {
  16888. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  16889. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  16890. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  16891. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  16892. v( position2.x, position2.y, position2.z );
  16893. }
  16894. }
  16895. }
  16896. // Add bevel segments planes
  16897. //for ( b = 1; b <= bevelSegments; b ++ ) {
  16898. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  16899. t = b / bevelSegments;
  16900. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  16901. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  16902. // contract shape
  16903. for ( i = 0, il = contour.length; i < il; i ++ ) {
  16904. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  16905. v( vert.x, vert.y, depth + z );
  16906. }
  16907. // expand holes
  16908. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16909. ahole = holes[ h ];
  16910. oneHoleMovements = holesMovements[ h ];
  16911. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  16912. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  16913. if ( ! extrudeByPath ) {
  16914. v( vert.x, vert.y, depth + z );
  16915. } else {
  16916. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  16917. }
  16918. }
  16919. }
  16920. }
  16921. /* Faces */
  16922. // Top and bottom faces
  16923. buildLidFaces();
  16924. // Sides faces
  16925. buildSideFaces();
  16926. ///// Internal functions
  16927. function buildLidFaces() {
  16928. var start = verticesArray.length / 3;
  16929. if ( bevelEnabled ) {
  16930. var layer = 0; // steps + 1
  16931. var offset = vlen * layer;
  16932. // Bottom faces
  16933. for ( i = 0; i < flen; i ++ ) {
  16934. face = faces[ i ];
  16935. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  16936. }
  16937. layer = steps + bevelSegments * 2;
  16938. offset = vlen * layer;
  16939. // Top faces
  16940. for ( i = 0; i < flen; i ++ ) {
  16941. face = faces[ i ];
  16942. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  16943. }
  16944. } else {
  16945. // Bottom faces
  16946. for ( i = 0; i < flen; i ++ ) {
  16947. face = faces[ i ];
  16948. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  16949. }
  16950. // Top faces
  16951. for ( i = 0; i < flen; i ++ ) {
  16952. face = faces[ i ];
  16953. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  16954. }
  16955. }
  16956. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  16957. }
  16958. // Create faces for the z-sides of the shape
  16959. function buildSideFaces() {
  16960. var start = verticesArray.length / 3;
  16961. var layeroffset = 0;
  16962. sidewalls( contour, layeroffset );
  16963. layeroffset += contour.length;
  16964. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  16965. ahole = holes[ h ];
  16966. sidewalls( ahole, layeroffset );
  16967. //, true
  16968. layeroffset += ahole.length;
  16969. }
  16970. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  16971. }
  16972. function sidewalls( contour, layeroffset ) {
  16973. var j, k;
  16974. i = contour.length;
  16975. while ( -- i >= 0 ) {
  16976. j = i;
  16977. k = i - 1;
  16978. if ( k < 0 ) k = contour.length - 1;
  16979. //console.log('b', i,j, i-1, k,vertices.length);
  16980. var s = 0,
  16981. sl = steps + bevelSegments * 2;
  16982. for ( s = 0; s < sl; s ++ ) {
  16983. var slen1 = vlen * s;
  16984. var slen2 = vlen * ( s + 1 );
  16985. var a = layeroffset + j + slen1,
  16986. b = layeroffset + k + slen1,
  16987. c = layeroffset + k + slen2,
  16988. d = layeroffset + j + slen2;
  16989. f4( a, b, c, d );
  16990. }
  16991. }
  16992. }
  16993. function v( x, y, z ) {
  16994. placeholder.push( x );
  16995. placeholder.push( y );
  16996. placeholder.push( z );
  16997. }
  16998. function f3( a, b, c ) {
  16999. addVertex( a );
  17000. addVertex( b );
  17001. addVertex( c );
  17002. var nextIndex = verticesArray.length / 3;
  17003. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  17004. addUV( uvs[ 0 ] );
  17005. addUV( uvs[ 1 ] );
  17006. addUV( uvs[ 2 ] );
  17007. }
  17008. function f4( a, b, c, d ) {
  17009. addVertex( a );
  17010. addVertex( b );
  17011. addVertex( d );
  17012. addVertex( b );
  17013. addVertex( c );
  17014. addVertex( d );
  17015. var nextIndex = verticesArray.length / 3;
  17016. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  17017. addUV( uvs[ 0 ] );
  17018. addUV( uvs[ 1 ] );
  17019. addUV( uvs[ 3 ] );
  17020. addUV( uvs[ 1 ] );
  17021. addUV( uvs[ 2 ] );
  17022. addUV( uvs[ 3 ] );
  17023. }
  17024. function addVertex( index ) {
  17025. verticesArray.push( placeholder[ index * 3 + 0 ] );
  17026. verticesArray.push( placeholder[ index * 3 + 1 ] );
  17027. verticesArray.push( placeholder[ index * 3 + 2 ] );
  17028. }
  17029. function addUV( vector2 ) {
  17030. uvArray.push( vector2.x );
  17031. uvArray.push( vector2.y );
  17032. }
  17033. }
  17034. }
  17035. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17036. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  17037. var WorldUVGenerator = {
  17038. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  17039. var a_x = vertices[ indexA * 3 ];
  17040. var a_y = vertices[ indexA * 3 + 1 ];
  17041. var b_x = vertices[ indexB * 3 ];
  17042. var b_y = vertices[ indexB * 3 + 1 ];
  17043. var c_x = vertices[ indexC * 3 ];
  17044. var c_y = vertices[ indexC * 3 + 1 ];
  17045. return [
  17046. new Vector2( a_x, a_y ),
  17047. new Vector2( b_x, b_y ),
  17048. new Vector2( c_x, c_y )
  17049. ];
  17050. },
  17051. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  17052. var a_x = vertices[ indexA * 3 ];
  17053. var a_y = vertices[ indexA * 3 + 1 ];
  17054. var a_z = vertices[ indexA * 3 + 2 ];
  17055. var b_x = vertices[ indexB * 3 ];
  17056. var b_y = vertices[ indexB * 3 + 1 ];
  17057. var b_z = vertices[ indexB * 3 + 2 ];
  17058. var c_x = vertices[ indexC * 3 ];
  17059. var c_y = vertices[ indexC * 3 + 1 ];
  17060. var c_z = vertices[ indexC * 3 + 2 ];
  17061. var d_x = vertices[ indexD * 3 ];
  17062. var d_y = vertices[ indexD * 3 + 1 ];
  17063. var d_z = vertices[ indexD * 3 + 2 ];
  17064. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  17065. return [
  17066. new Vector2( a_x, 1 - a_z ),
  17067. new Vector2( b_x, 1 - b_z ),
  17068. new Vector2( c_x, 1 - c_z ),
  17069. new Vector2( d_x, 1 - d_z )
  17070. ];
  17071. } else {
  17072. return [
  17073. new Vector2( a_y, 1 - a_z ),
  17074. new Vector2( b_y, 1 - b_z ),
  17075. new Vector2( c_y, 1 - c_z ),
  17076. new Vector2( d_y, 1 - d_z )
  17077. ];
  17078. }
  17079. }
  17080. };
  17081. /**
  17082. * @author zz85 / http://www.lab4games.net/zz85/blog
  17083. * @author alteredq / http://alteredqualia.com/
  17084. *
  17085. * Text = 3D Text
  17086. *
  17087. * parameters = {
  17088. * font: <THREE.Font>, // font
  17089. *
  17090. * size: <float>, // size of the text
  17091. * height: <float>, // thickness to extrude text
  17092. * curveSegments: <int>, // number of points on the curves
  17093. *
  17094. * bevelEnabled: <bool>, // turn on bevel
  17095. * bevelThickness: <float>, // how deep into text bevel goes
  17096. * bevelSize: <float> // how far from text outline is bevel
  17097. * }
  17098. */
  17099. // TextGeometry
  17100. function TextGeometry( text, parameters ) {
  17101. Geometry.call( this );
  17102. this.type = 'TextGeometry';
  17103. this.parameters = {
  17104. text: text,
  17105. parameters: parameters
  17106. };
  17107. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  17108. this.mergeVertices();
  17109. }
  17110. TextGeometry.prototype = Object.create( Geometry.prototype );
  17111. TextGeometry.prototype.constructor = TextGeometry;
  17112. // TextBufferGeometry
  17113. function TextBufferGeometry( text, parameters ) {
  17114. parameters = parameters || {};
  17115. var font = parameters.font;
  17116. if ( ! ( font && font.isFont ) ) {
  17117. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  17118. return new Geometry();
  17119. }
  17120. var shapes = font.generateShapes( text, parameters.size, parameters.curveSegments );
  17121. // translate parameters to ExtrudeGeometry API
  17122. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  17123. // defaults
  17124. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  17125. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  17126. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  17127. ExtrudeBufferGeometry.call( this, shapes, parameters );
  17128. this.type = 'TextBufferGeometry';
  17129. }
  17130. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  17131. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  17132. /**
  17133. * @author mrdoob / http://mrdoob.com/
  17134. * @author benaadams / https://twitter.com/ben_a_adams
  17135. * @author Mugen87 / https://github.com/Mugen87
  17136. */
  17137. // SphereGeometry
  17138. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  17139. Geometry.call( this );
  17140. this.type = 'SphereGeometry';
  17141. this.parameters = {
  17142. radius: radius,
  17143. widthSegments: widthSegments,
  17144. heightSegments: heightSegments,
  17145. phiStart: phiStart,
  17146. phiLength: phiLength,
  17147. thetaStart: thetaStart,
  17148. thetaLength: thetaLength
  17149. };
  17150. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  17151. this.mergeVertices();
  17152. }
  17153. SphereGeometry.prototype = Object.create( Geometry.prototype );
  17154. SphereGeometry.prototype.constructor = SphereGeometry;
  17155. // SphereBufferGeometry
  17156. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  17157. BufferGeometry.call( this );
  17158. this.type = 'SphereBufferGeometry';
  17159. this.parameters = {
  17160. radius: radius,
  17161. widthSegments: widthSegments,
  17162. heightSegments: heightSegments,
  17163. phiStart: phiStart,
  17164. phiLength: phiLength,
  17165. thetaStart: thetaStart,
  17166. thetaLength: thetaLength
  17167. };
  17168. radius = radius || 1;
  17169. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  17170. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  17171. phiStart = phiStart !== undefined ? phiStart : 0;
  17172. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  17173. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  17174. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  17175. var thetaEnd = thetaStart + thetaLength;
  17176. var ix, iy;
  17177. var index = 0;
  17178. var grid = [];
  17179. var vertex = new Vector3();
  17180. var normal = new Vector3();
  17181. // buffers
  17182. var indices = [];
  17183. var vertices = [];
  17184. var normals = [];
  17185. var uvs = [];
  17186. // generate vertices, normals and uvs
  17187. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  17188. var verticesRow = [];
  17189. var v = iy / heightSegments;
  17190. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  17191. var u = ix / widthSegments;
  17192. // vertex
  17193. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  17194. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  17195. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  17196. vertices.push( vertex.x, vertex.y, vertex.z );
  17197. // normal
  17198. normal.set( vertex.x, vertex.y, vertex.z ).normalize();
  17199. normals.push( normal.x, normal.y, normal.z );
  17200. // uv
  17201. uvs.push( u, 1 - v );
  17202. verticesRow.push( index ++ );
  17203. }
  17204. grid.push( verticesRow );
  17205. }
  17206. // indices
  17207. for ( iy = 0; iy < heightSegments; iy ++ ) {
  17208. for ( ix = 0; ix < widthSegments; ix ++ ) {
  17209. var a = grid[ iy ][ ix + 1 ];
  17210. var b = grid[ iy ][ ix ];
  17211. var c = grid[ iy + 1 ][ ix ];
  17212. var d = grid[ iy + 1 ][ ix + 1 ];
  17213. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  17214. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  17215. }
  17216. }
  17217. // build geometry
  17218. this.setIndex( indices );
  17219. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17220. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17221. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17222. }
  17223. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17224. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  17225. /**
  17226. * @author Kaleb Murphy
  17227. * @author Mugen87 / https://github.com/Mugen87
  17228. */
  17229. // RingGeometry
  17230. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  17231. Geometry.call( this );
  17232. this.type = 'RingGeometry';
  17233. this.parameters = {
  17234. innerRadius: innerRadius,
  17235. outerRadius: outerRadius,
  17236. thetaSegments: thetaSegments,
  17237. phiSegments: phiSegments,
  17238. thetaStart: thetaStart,
  17239. thetaLength: thetaLength
  17240. };
  17241. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  17242. this.mergeVertices();
  17243. }
  17244. RingGeometry.prototype = Object.create( Geometry.prototype );
  17245. RingGeometry.prototype.constructor = RingGeometry;
  17246. // RingBufferGeometry
  17247. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  17248. BufferGeometry.call( this );
  17249. this.type = 'RingBufferGeometry';
  17250. this.parameters = {
  17251. innerRadius: innerRadius,
  17252. outerRadius: outerRadius,
  17253. thetaSegments: thetaSegments,
  17254. phiSegments: phiSegments,
  17255. thetaStart: thetaStart,
  17256. thetaLength: thetaLength
  17257. };
  17258. innerRadius = innerRadius || 0.5;
  17259. outerRadius = outerRadius || 1;
  17260. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  17261. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  17262. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  17263. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  17264. // buffers
  17265. var indices = [];
  17266. var vertices = [];
  17267. var normals = [];
  17268. var uvs = [];
  17269. // some helper variables
  17270. var segment;
  17271. var radius = innerRadius;
  17272. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  17273. var vertex = new Vector3();
  17274. var uv = new Vector2();
  17275. var j, i;
  17276. // generate vertices, normals and uvs
  17277. for ( j = 0; j <= phiSegments; j ++ ) {
  17278. for ( i = 0; i <= thetaSegments; i ++ ) {
  17279. // values are generate from the inside of the ring to the outside
  17280. segment = thetaStart + i / thetaSegments * thetaLength;
  17281. // vertex
  17282. vertex.x = radius * Math.cos( segment );
  17283. vertex.y = radius * Math.sin( segment );
  17284. vertices.push( vertex.x, vertex.y, vertex.z );
  17285. // normal
  17286. normals.push( 0, 0, 1 );
  17287. // uv
  17288. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  17289. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  17290. uvs.push( uv.x, uv.y );
  17291. }
  17292. // increase the radius for next row of vertices
  17293. radius += radiusStep;
  17294. }
  17295. // indices
  17296. for ( j = 0; j < phiSegments; j ++ ) {
  17297. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  17298. for ( i = 0; i < thetaSegments; i ++ ) {
  17299. segment = i + thetaSegmentLevel;
  17300. var a = segment;
  17301. var b = segment + thetaSegments + 1;
  17302. var c = segment + thetaSegments + 2;
  17303. var d = segment + 1;
  17304. // faces
  17305. indices.push( a, b, d );
  17306. indices.push( b, c, d );
  17307. }
  17308. }
  17309. // build geometry
  17310. this.setIndex( indices );
  17311. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17312. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17313. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17314. }
  17315. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17316. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  17317. /**
  17318. * @author astrodud / http://astrodud.isgreat.org/
  17319. * @author zz85 / https://github.com/zz85
  17320. * @author bhouston / http://clara.io
  17321. * @author Mugen87 / https://github.com/Mugen87
  17322. */
  17323. // LatheGeometry
  17324. function LatheGeometry( points, segments, phiStart, phiLength ) {
  17325. Geometry.call( this );
  17326. this.type = 'LatheGeometry';
  17327. this.parameters = {
  17328. points: points,
  17329. segments: segments,
  17330. phiStart: phiStart,
  17331. phiLength: phiLength
  17332. };
  17333. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  17334. this.mergeVertices();
  17335. }
  17336. LatheGeometry.prototype = Object.create( Geometry.prototype );
  17337. LatheGeometry.prototype.constructor = LatheGeometry;
  17338. // LatheBufferGeometry
  17339. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  17340. BufferGeometry.call( this );
  17341. this.type = 'LatheBufferGeometry';
  17342. this.parameters = {
  17343. points: points,
  17344. segments: segments,
  17345. phiStart: phiStart,
  17346. phiLength: phiLength
  17347. };
  17348. segments = Math.floor( segments ) || 12;
  17349. phiStart = phiStart || 0;
  17350. phiLength = phiLength || Math.PI * 2;
  17351. // clamp phiLength so it's in range of [ 0, 2PI ]
  17352. phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
  17353. // buffers
  17354. var indices = [];
  17355. var vertices = [];
  17356. var uvs = [];
  17357. // helper variables
  17358. var base;
  17359. var inverseSegments = 1.0 / segments;
  17360. var vertex = new Vector3();
  17361. var uv = new Vector2();
  17362. var i, j;
  17363. // generate vertices and uvs
  17364. for ( i = 0; i <= segments; i ++ ) {
  17365. var phi = phiStart + i * inverseSegments * phiLength;
  17366. var sin = Math.sin( phi );
  17367. var cos = Math.cos( phi );
  17368. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  17369. // vertex
  17370. vertex.x = points[ j ].x * sin;
  17371. vertex.y = points[ j ].y;
  17372. vertex.z = points[ j ].x * cos;
  17373. vertices.push( vertex.x, vertex.y, vertex.z );
  17374. // uv
  17375. uv.x = i / segments;
  17376. uv.y = j / ( points.length - 1 );
  17377. uvs.push( uv.x, uv.y );
  17378. }
  17379. }
  17380. // indices
  17381. for ( i = 0; i < segments; i ++ ) {
  17382. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  17383. base = j + i * points.length;
  17384. var a = base;
  17385. var b = base + points.length;
  17386. var c = base + points.length + 1;
  17387. var d = base + 1;
  17388. // faces
  17389. indices.push( a, b, d );
  17390. indices.push( b, c, d );
  17391. }
  17392. }
  17393. // build geometry
  17394. this.setIndex( indices );
  17395. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17396. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17397. // generate normals
  17398. this.computeVertexNormals();
  17399. // if the geometry is closed, we need to average the normals along the seam.
  17400. // because the corresponding vertices are identical (but still have different UVs).
  17401. if ( phiLength === Math.PI * 2 ) {
  17402. var normals = this.attributes.normal.array;
  17403. var n1 = new Vector3();
  17404. var n2 = new Vector3();
  17405. var n = new Vector3();
  17406. // this is the buffer offset for the last line of vertices
  17407. base = segments * points.length * 3;
  17408. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  17409. // select the normal of the vertex in the first line
  17410. n1.x = normals[ j + 0 ];
  17411. n1.y = normals[ j + 1 ];
  17412. n1.z = normals[ j + 2 ];
  17413. // select the normal of the vertex in the last line
  17414. n2.x = normals[ base + j + 0 ];
  17415. n2.y = normals[ base + j + 1 ];
  17416. n2.z = normals[ base + j + 2 ];
  17417. // average normals
  17418. n.addVectors( n1, n2 ).normalize();
  17419. // assign the new values to both normals
  17420. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  17421. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  17422. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  17423. }
  17424. }
  17425. }
  17426. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17427. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  17428. /**
  17429. * @author jonobr1 / http://jonobr1.com
  17430. * @author Mugen87 / https://github.com/Mugen87
  17431. */
  17432. // ShapeGeometry
  17433. function ShapeGeometry( shapes, curveSegments ) {
  17434. Geometry.call( this );
  17435. this.type = 'ShapeGeometry';
  17436. if ( typeof curveSegments === 'object' ) {
  17437. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  17438. curveSegments = curveSegments.curveSegments;
  17439. }
  17440. this.parameters = {
  17441. shapes: shapes,
  17442. curveSegments: curveSegments
  17443. };
  17444. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  17445. this.mergeVertices();
  17446. }
  17447. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  17448. ShapeGeometry.prototype.constructor = ShapeGeometry;
  17449. ShapeGeometry.prototype.toJSON = function () {
  17450. var data = Geometry.prototype.toJSON.call( this );
  17451. var shapes = this.parameters.shapes;
  17452. return toJSON( shapes, data );
  17453. };
  17454. // ShapeBufferGeometry
  17455. function ShapeBufferGeometry( shapes, curveSegments ) {
  17456. BufferGeometry.call( this );
  17457. this.type = 'ShapeBufferGeometry';
  17458. this.parameters = {
  17459. shapes: shapes,
  17460. curveSegments: curveSegments
  17461. };
  17462. curveSegments = curveSegments || 12;
  17463. // buffers
  17464. var indices = [];
  17465. var vertices = [];
  17466. var normals = [];
  17467. var uvs = [];
  17468. // helper variables
  17469. var groupStart = 0;
  17470. var groupCount = 0;
  17471. // allow single and array values for "shapes" parameter
  17472. if ( Array.isArray( shapes ) === false ) {
  17473. addShape( shapes );
  17474. } else {
  17475. for ( var i = 0; i < shapes.length; i ++ ) {
  17476. addShape( shapes[ i ] );
  17477. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  17478. groupStart += groupCount;
  17479. groupCount = 0;
  17480. }
  17481. }
  17482. // build geometry
  17483. this.setIndex( indices );
  17484. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17485. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17486. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17487. // helper functions
  17488. function addShape( shape ) {
  17489. var i, l, shapeHole;
  17490. var indexOffset = vertices.length / 3;
  17491. var points = shape.extractPoints( curveSegments );
  17492. var shapeVertices = points.shape;
  17493. var shapeHoles = points.holes;
  17494. // check direction of vertices
  17495. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  17496. shapeVertices = shapeVertices.reverse();
  17497. // also check if holes are in the opposite direction
  17498. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  17499. shapeHole = shapeHoles[ i ];
  17500. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  17501. shapeHoles[ i ] = shapeHole.reverse();
  17502. }
  17503. }
  17504. }
  17505. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  17506. // join vertices of inner and outer paths to a single array
  17507. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  17508. shapeHole = shapeHoles[ i ];
  17509. shapeVertices = shapeVertices.concat( shapeHole );
  17510. }
  17511. // vertices, normals, uvs
  17512. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  17513. var vertex = shapeVertices[ i ];
  17514. vertices.push( vertex.x, vertex.y, 0 );
  17515. normals.push( 0, 0, 1 );
  17516. uvs.push( vertex.x, vertex.y ); // world uvs
  17517. }
  17518. // incides
  17519. for ( i = 0, l = faces.length; i < l; i ++ ) {
  17520. var face = faces[ i ];
  17521. var a = face[ 0 ] + indexOffset;
  17522. var b = face[ 1 ] + indexOffset;
  17523. var c = face[ 2 ] + indexOffset;
  17524. indices.push( a, b, c );
  17525. groupCount += 3;
  17526. }
  17527. }
  17528. }
  17529. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17530. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  17531. ShapeBufferGeometry.prototype.toJSON = function () {
  17532. var data = BufferGeometry.prototype.toJSON.call( this );
  17533. var shapes = this.parameters.shapes;
  17534. return toJSON( shapes, data );
  17535. };
  17536. //
  17537. function toJSON( shapes, data ) {
  17538. data.shapes = [];
  17539. if ( Array.isArray( shapes ) ) {
  17540. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  17541. var shape = shapes[ i ];
  17542. data.shapes.push( shape.uuid );
  17543. }
  17544. } else {
  17545. data.shapes.push( shapes.uuid );
  17546. }
  17547. return data;
  17548. }
  17549. /**
  17550. * @author WestLangley / http://github.com/WestLangley
  17551. * @author Mugen87 / https://github.com/Mugen87
  17552. */
  17553. function EdgesGeometry( geometry, thresholdAngle ) {
  17554. BufferGeometry.call( this );
  17555. this.type = 'EdgesGeometry';
  17556. this.parameters = {
  17557. thresholdAngle: thresholdAngle
  17558. };
  17559. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  17560. // buffer
  17561. var vertices = [];
  17562. // helper variables
  17563. var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
  17564. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  17565. var key, keys = [ 'a', 'b', 'c' ];
  17566. // prepare source geometry
  17567. var geometry2;
  17568. if ( geometry.isBufferGeometry ) {
  17569. geometry2 = new Geometry();
  17570. geometry2.fromBufferGeometry( geometry );
  17571. } else {
  17572. geometry2 = geometry.clone();
  17573. }
  17574. geometry2.mergeVertices();
  17575. geometry2.computeFaceNormals();
  17576. var sourceVertices = geometry2.vertices;
  17577. var faces = geometry2.faces;
  17578. // now create a data structure where each entry represents an edge with its adjoining faces
  17579. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  17580. var face = faces[ i ];
  17581. for ( var j = 0; j < 3; j ++ ) {
  17582. edge1 = face[ keys[ j ] ];
  17583. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  17584. edge[ 0 ] = Math.min( edge1, edge2 );
  17585. edge[ 1 ] = Math.max( edge1, edge2 );
  17586. key = edge[ 0 ] + ',' + edge[ 1 ];
  17587. if ( edges[ key ] === undefined ) {
  17588. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  17589. } else {
  17590. edges[ key ].face2 = i;
  17591. }
  17592. }
  17593. }
  17594. // generate vertices
  17595. for ( key in edges ) {
  17596. var e = edges[ key ];
  17597. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  17598. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  17599. var vertex = sourceVertices[ e.index1 ];
  17600. vertices.push( vertex.x, vertex.y, vertex.z );
  17601. vertex = sourceVertices[ e.index2 ];
  17602. vertices.push( vertex.x, vertex.y, vertex.z );
  17603. }
  17604. }
  17605. // build geometry
  17606. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17607. }
  17608. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  17609. EdgesGeometry.prototype.constructor = EdgesGeometry;
  17610. /**
  17611. * @author mrdoob / http://mrdoob.com/
  17612. * @author Mugen87 / https://github.com/Mugen87
  17613. */
  17614. // CylinderGeometry
  17615. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  17616. Geometry.call( this );
  17617. this.type = 'CylinderGeometry';
  17618. this.parameters = {
  17619. radiusTop: radiusTop,
  17620. radiusBottom: radiusBottom,
  17621. height: height,
  17622. radialSegments: radialSegments,
  17623. heightSegments: heightSegments,
  17624. openEnded: openEnded,
  17625. thetaStart: thetaStart,
  17626. thetaLength: thetaLength
  17627. };
  17628. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  17629. this.mergeVertices();
  17630. }
  17631. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  17632. CylinderGeometry.prototype.constructor = CylinderGeometry;
  17633. // CylinderBufferGeometry
  17634. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  17635. BufferGeometry.call( this );
  17636. this.type = 'CylinderBufferGeometry';
  17637. this.parameters = {
  17638. radiusTop: radiusTop,
  17639. radiusBottom: radiusBottom,
  17640. height: height,
  17641. radialSegments: radialSegments,
  17642. heightSegments: heightSegments,
  17643. openEnded: openEnded,
  17644. thetaStart: thetaStart,
  17645. thetaLength: thetaLength
  17646. };
  17647. var scope = this;
  17648. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  17649. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  17650. height = height || 1;
  17651. radialSegments = Math.floor( radialSegments ) || 8;
  17652. heightSegments = Math.floor( heightSegments ) || 1;
  17653. openEnded = openEnded !== undefined ? openEnded : false;
  17654. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  17655. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  17656. // buffers
  17657. var indices = [];
  17658. var vertices = [];
  17659. var normals = [];
  17660. var uvs = [];
  17661. // helper variables
  17662. var index = 0;
  17663. var indexArray = [];
  17664. var halfHeight = height / 2;
  17665. var groupStart = 0;
  17666. // generate geometry
  17667. generateTorso();
  17668. if ( openEnded === false ) {
  17669. if ( radiusTop > 0 ) generateCap( true );
  17670. if ( radiusBottom > 0 ) generateCap( false );
  17671. }
  17672. // build geometry
  17673. this.setIndex( indices );
  17674. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17675. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17676. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17677. function generateTorso() {
  17678. var x, y;
  17679. var normal = new Vector3();
  17680. var vertex = new Vector3();
  17681. var groupCount = 0;
  17682. // this will be used to calculate the normal
  17683. var slope = ( radiusBottom - radiusTop ) / height;
  17684. // generate vertices, normals and uvs
  17685. for ( y = 0; y <= heightSegments; y ++ ) {
  17686. var indexRow = [];
  17687. var v = y / heightSegments;
  17688. // calculate the radius of the current row
  17689. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  17690. for ( x = 0; x <= radialSegments; x ++ ) {
  17691. var u = x / radialSegments;
  17692. var theta = u * thetaLength + thetaStart;
  17693. var sinTheta = Math.sin( theta );
  17694. var cosTheta = Math.cos( theta );
  17695. // vertex
  17696. vertex.x = radius * sinTheta;
  17697. vertex.y = - v * height + halfHeight;
  17698. vertex.z = radius * cosTheta;
  17699. vertices.push( vertex.x, vertex.y, vertex.z );
  17700. // normal
  17701. normal.set( sinTheta, slope, cosTheta ).normalize();
  17702. normals.push( normal.x, normal.y, normal.z );
  17703. // uv
  17704. uvs.push( u, 1 - v );
  17705. // save index of vertex in respective row
  17706. indexRow.push( index ++ );
  17707. }
  17708. // now save vertices of the row in our index array
  17709. indexArray.push( indexRow );
  17710. }
  17711. // generate indices
  17712. for ( x = 0; x < radialSegments; x ++ ) {
  17713. for ( y = 0; y < heightSegments; y ++ ) {
  17714. // we use the index array to access the correct indices
  17715. var a = indexArray[ y ][ x ];
  17716. var b = indexArray[ y + 1 ][ x ];
  17717. var c = indexArray[ y + 1 ][ x + 1 ];
  17718. var d = indexArray[ y ][ x + 1 ];
  17719. // faces
  17720. indices.push( a, b, d );
  17721. indices.push( b, c, d );
  17722. // update group counter
  17723. groupCount += 6;
  17724. }
  17725. }
  17726. // add a group to the geometry. this will ensure multi material support
  17727. scope.addGroup( groupStart, groupCount, 0 );
  17728. // calculate new start value for groups
  17729. groupStart += groupCount;
  17730. }
  17731. function generateCap( top ) {
  17732. var x, centerIndexStart, centerIndexEnd;
  17733. var uv = new Vector2();
  17734. var vertex = new Vector3();
  17735. var groupCount = 0;
  17736. var radius = ( top === true ) ? radiusTop : radiusBottom;
  17737. var sign = ( top === true ) ? 1 : - 1;
  17738. // save the index of the first center vertex
  17739. centerIndexStart = index;
  17740. // first we generate the center vertex data of the cap.
  17741. // because the geometry needs one set of uvs per face,
  17742. // we must generate a center vertex per face/segment
  17743. for ( x = 1; x <= radialSegments; x ++ ) {
  17744. // vertex
  17745. vertices.push( 0, halfHeight * sign, 0 );
  17746. // normal
  17747. normals.push( 0, sign, 0 );
  17748. // uv
  17749. uvs.push( 0.5, 0.5 );
  17750. // increase index
  17751. index ++;
  17752. }
  17753. // save the index of the last center vertex
  17754. centerIndexEnd = index;
  17755. // now we generate the surrounding vertices, normals and uvs
  17756. for ( x = 0; x <= radialSegments; x ++ ) {
  17757. var u = x / radialSegments;
  17758. var theta = u * thetaLength + thetaStart;
  17759. var cosTheta = Math.cos( theta );
  17760. var sinTheta = Math.sin( theta );
  17761. // vertex
  17762. vertex.x = radius * sinTheta;
  17763. vertex.y = halfHeight * sign;
  17764. vertex.z = radius * cosTheta;
  17765. vertices.push( vertex.x, vertex.y, vertex.z );
  17766. // normal
  17767. normals.push( 0, sign, 0 );
  17768. // uv
  17769. uv.x = ( cosTheta * 0.5 ) + 0.5;
  17770. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  17771. uvs.push( uv.x, uv.y );
  17772. // increase index
  17773. index ++;
  17774. }
  17775. // generate indices
  17776. for ( x = 0; x < radialSegments; x ++ ) {
  17777. var c = centerIndexStart + x;
  17778. var i = centerIndexEnd + x;
  17779. if ( top === true ) {
  17780. // face top
  17781. indices.push( i, i + 1, c );
  17782. } else {
  17783. // face bottom
  17784. indices.push( i + 1, i, c );
  17785. }
  17786. groupCount += 3;
  17787. }
  17788. // add a group to the geometry. this will ensure multi material support
  17789. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  17790. // calculate new start value for groups
  17791. groupStart += groupCount;
  17792. }
  17793. }
  17794. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17795. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  17796. /**
  17797. * @author abelnation / http://github.com/abelnation
  17798. */
  17799. // ConeGeometry
  17800. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  17801. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  17802. this.type = 'ConeGeometry';
  17803. this.parameters = {
  17804. radius: radius,
  17805. height: height,
  17806. radialSegments: radialSegments,
  17807. heightSegments: heightSegments,
  17808. openEnded: openEnded,
  17809. thetaStart: thetaStart,
  17810. thetaLength: thetaLength
  17811. };
  17812. }
  17813. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  17814. ConeGeometry.prototype.constructor = ConeGeometry;
  17815. // ConeBufferGeometry
  17816. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  17817. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  17818. this.type = 'ConeBufferGeometry';
  17819. this.parameters = {
  17820. radius: radius,
  17821. height: height,
  17822. radialSegments: radialSegments,
  17823. heightSegments: heightSegments,
  17824. openEnded: openEnded,
  17825. thetaStart: thetaStart,
  17826. thetaLength: thetaLength
  17827. };
  17828. }
  17829. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  17830. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  17831. /**
  17832. * @author benaadams / https://twitter.com/ben_a_adams
  17833. * @author Mugen87 / https://github.com/Mugen87
  17834. * @author hughes
  17835. */
  17836. // CircleGeometry
  17837. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  17838. Geometry.call( this );
  17839. this.type = 'CircleGeometry';
  17840. this.parameters = {
  17841. radius: radius,
  17842. segments: segments,
  17843. thetaStart: thetaStart,
  17844. thetaLength: thetaLength
  17845. };
  17846. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  17847. this.mergeVertices();
  17848. }
  17849. CircleGeometry.prototype = Object.create( Geometry.prototype );
  17850. CircleGeometry.prototype.constructor = CircleGeometry;
  17851. // CircleBufferGeometry
  17852. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  17853. BufferGeometry.call( this );
  17854. this.type = 'CircleBufferGeometry';
  17855. this.parameters = {
  17856. radius: radius,
  17857. segments: segments,
  17858. thetaStart: thetaStart,
  17859. thetaLength: thetaLength
  17860. };
  17861. radius = radius || 1;
  17862. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  17863. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  17864. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  17865. // buffers
  17866. var indices = [];
  17867. var vertices = [];
  17868. var normals = [];
  17869. var uvs = [];
  17870. // helper variables
  17871. var i, s;
  17872. var vertex = new Vector3();
  17873. var uv = new Vector2();
  17874. // center point
  17875. vertices.push( 0, 0, 0 );
  17876. normals.push( 0, 0, 1 );
  17877. uvs.push( 0.5, 0.5 );
  17878. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  17879. var segment = thetaStart + s / segments * thetaLength;
  17880. // vertex
  17881. vertex.x = radius * Math.cos( segment );
  17882. vertex.y = radius * Math.sin( segment );
  17883. vertices.push( vertex.x, vertex.y, vertex.z );
  17884. // normal
  17885. normals.push( 0, 0, 1 );
  17886. // uvs
  17887. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  17888. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  17889. uvs.push( uv.x, uv.y );
  17890. }
  17891. // indices
  17892. for ( i = 1; i <= segments; i ++ ) {
  17893. indices.push( i, i + 1, 0 );
  17894. }
  17895. // build geometry
  17896. this.setIndex( indices );
  17897. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17898. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17899. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17900. }
  17901. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17902. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  17903. var Geometries = Object.freeze({
  17904. WireframeGeometry: WireframeGeometry,
  17905. ParametricGeometry: ParametricGeometry,
  17906. ParametricBufferGeometry: ParametricBufferGeometry,
  17907. TetrahedronGeometry: TetrahedronGeometry,
  17908. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  17909. OctahedronGeometry: OctahedronGeometry,
  17910. OctahedronBufferGeometry: OctahedronBufferGeometry,
  17911. IcosahedronGeometry: IcosahedronGeometry,
  17912. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  17913. DodecahedronGeometry: DodecahedronGeometry,
  17914. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  17915. PolyhedronGeometry: PolyhedronGeometry,
  17916. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  17917. TubeGeometry: TubeGeometry,
  17918. TubeBufferGeometry: TubeBufferGeometry,
  17919. TorusKnotGeometry: TorusKnotGeometry,
  17920. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  17921. TorusGeometry: TorusGeometry,
  17922. TorusBufferGeometry: TorusBufferGeometry,
  17923. TextGeometry: TextGeometry,
  17924. TextBufferGeometry: TextBufferGeometry,
  17925. SphereGeometry: SphereGeometry,
  17926. SphereBufferGeometry: SphereBufferGeometry,
  17927. RingGeometry: RingGeometry,
  17928. RingBufferGeometry: RingBufferGeometry,
  17929. PlaneGeometry: PlaneGeometry,
  17930. PlaneBufferGeometry: PlaneBufferGeometry,
  17931. LatheGeometry: LatheGeometry,
  17932. LatheBufferGeometry: LatheBufferGeometry,
  17933. ShapeGeometry: ShapeGeometry,
  17934. ShapeBufferGeometry: ShapeBufferGeometry,
  17935. ExtrudeGeometry: ExtrudeGeometry,
  17936. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  17937. EdgesGeometry: EdgesGeometry,
  17938. ConeGeometry: ConeGeometry,
  17939. ConeBufferGeometry: ConeBufferGeometry,
  17940. CylinderGeometry: CylinderGeometry,
  17941. CylinderBufferGeometry: CylinderBufferGeometry,
  17942. CircleGeometry: CircleGeometry,
  17943. CircleBufferGeometry: CircleBufferGeometry,
  17944. BoxGeometry: BoxGeometry,
  17945. BoxBufferGeometry: BoxBufferGeometry
  17946. });
  17947. /**
  17948. * @author mrdoob / http://mrdoob.com/
  17949. *
  17950. * parameters = {
  17951. * color: <THREE.Color>
  17952. * }
  17953. */
  17954. function ShadowMaterial( parameters ) {
  17955. Material.call( this );
  17956. this.type = 'ShadowMaterial';
  17957. this.color = new Color( 0x000000 );
  17958. this.transparent = true;
  17959. this.setValues( parameters );
  17960. }
  17961. ShadowMaterial.prototype = Object.create( Material.prototype );
  17962. ShadowMaterial.prototype.constructor = ShadowMaterial;
  17963. ShadowMaterial.prototype.isShadowMaterial = true;
  17964. ShadowMaterial.prototype.copy = function ( source ) {
  17965. Material.prototype.copy.call( this, source );
  17966. this.color.copy( source.color );
  17967. return this;
  17968. };
  17969. /**
  17970. * @author mrdoob / http://mrdoob.com/
  17971. */
  17972. function RawShaderMaterial( parameters ) {
  17973. ShaderMaterial.call( this, parameters );
  17974. this.type = 'RawShaderMaterial';
  17975. }
  17976. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  17977. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  17978. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  17979. /**
  17980. * @author WestLangley / http://github.com/WestLangley
  17981. *
  17982. * parameters = {
  17983. * color: <hex>,
  17984. * roughness: <float>,
  17985. * metalness: <float>,
  17986. * opacity: <float>,
  17987. *
  17988. * map: new THREE.Texture( <Image> ),
  17989. *
  17990. * lightMap: new THREE.Texture( <Image> ),
  17991. * lightMapIntensity: <float>
  17992. *
  17993. * aoMap: new THREE.Texture( <Image> ),
  17994. * aoMapIntensity: <float>
  17995. *
  17996. * emissive: <hex>,
  17997. * emissiveIntensity: <float>
  17998. * emissiveMap: new THREE.Texture( <Image> ),
  17999. *
  18000. * bumpMap: new THREE.Texture( <Image> ),
  18001. * bumpScale: <float>,
  18002. *
  18003. * normalMap: new THREE.Texture( <Image> ),
  18004. * normalScale: <Vector2>,
  18005. *
  18006. * displacementMap: new THREE.Texture( <Image> ),
  18007. * displacementScale: <float>,
  18008. * displacementBias: <float>,
  18009. *
  18010. * roughnessMap: new THREE.Texture( <Image> ),
  18011. *
  18012. * metalnessMap: new THREE.Texture( <Image> ),
  18013. *
  18014. * alphaMap: new THREE.Texture( <Image> ),
  18015. *
  18016. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  18017. * envMapIntensity: <float>
  18018. *
  18019. * refractionRatio: <float>,
  18020. *
  18021. * wireframe: <boolean>,
  18022. * wireframeLinewidth: <float>,
  18023. *
  18024. * skinning: <bool>,
  18025. * morphTargets: <bool>,
  18026. * morphNormals: <bool>
  18027. * }
  18028. */
  18029. function MeshStandardMaterial( parameters ) {
  18030. Material.call( this );
  18031. this.defines = { 'STANDARD': '' };
  18032. this.type = 'MeshStandardMaterial';
  18033. this.color = new Color( 0xffffff ); // diffuse
  18034. this.roughness = 0.5;
  18035. this.metalness = 0.5;
  18036. this.map = null;
  18037. this.lightMap = null;
  18038. this.lightMapIntensity = 1.0;
  18039. this.aoMap = null;
  18040. this.aoMapIntensity = 1.0;
  18041. this.emissive = new Color( 0x000000 );
  18042. this.emissiveIntensity = 1.0;
  18043. this.emissiveMap = null;
  18044. this.bumpMap = null;
  18045. this.bumpScale = 1;
  18046. this.normalMap = null;
  18047. this.normalScale = new Vector2( 1, 1 );
  18048. this.displacementMap = null;
  18049. this.displacementScale = 1;
  18050. this.displacementBias = 0;
  18051. this.roughnessMap = null;
  18052. this.metalnessMap = null;
  18053. this.alphaMap = null;
  18054. this.envMap = null;
  18055. this.envMapIntensity = 1.0;
  18056. this.refractionRatio = 0.98;
  18057. this.wireframe = false;
  18058. this.wireframeLinewidth = 1;
  18059. this.wireframeLinecap = 'round';
  18060. this.wireframeLinejoin = 'round';
  18061. this.skinning = false;
  18062. this.morphTargets = false;
  18063. this.morphNormals = false;
  18064. this.setValues( parameters );
  18065. }
  18066. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  18067. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  18068. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  18069. MeshStandardMaterial.prototype.copy = function ( source ) {
  18070. Material.prototype.copy.call( this, source );
  18071. this.defines = { 'STANDARD': '' };
  18072. this.color.copy( source.color );
  18073. this.roughness = source.roughness;
  18074. this.metalness = source.metalness;
  18075. this.map = source.map;
  18076. this.lightMap = source.lightMap;
  18077. this.lightMapIntensity = source.lightMapIntensity;
  18078. this.aoMap = source.aoMap;
  18079. this.aoMapIntensity = source.aoMapIntensity;
  18080. this.emissive.copy( source.emissive );
  18081. this.emissiveMap = source.emissiveMap;
  18082. this.emissiveIntensity = source.emissiveIntensity;
  18083. this.bumpMap = source.bumpMap;
  18084. this.bumpScale = source.bumpScale;
  18085. this.normalMap = source.normalMap;
  18086. this.normalScale.copy( source.normalScale );
  18087. this.displacementMap = source.displacementMap;
  18088. this.displacementScale = source.displacementScale;
  18089. this.displacementBias = source.displacementBias;
  18090. this.roughnessMap = source.roughnessMap;
  18091. this.metalnessMap = source.metalnessMap;
  18092. this.alphaMap = source.alphaMap;
  18093. this.envMap = source.envMap;
  18094. this.envMapIntensity = source.envMapIntensity;
  18095. this.refractionRatio = source.refractionRatio;
  18096. this.wireframe = source.wireframe;
  18097. this.wireframeLinewidth = source.wireframeLinewidth;
  18098. this.wireframeLinecap = source.wireframeLinecap;
  18099. this.wireframeLinejoin = source.wireframeLinejoin;
  18100. this.skinning = source.skinning;
  18101. this.morphTargets = source.morphTargets;
  18102. this.morphNormals = source.morphNormals;
  18103. return this;
  18104. };
  18105. /**
  18106. * @author WestLangley / http://github.com/WestLangley
  18107. *
  18108. * parameters = {
  18109. * reflectivity: <float>
  18110. * }
  18111. */
  18112. function MeshPhysicalMaterial( parameters ) {
  18113. MeshStandardMaterial.call( this );
  18114. this.defines = { 'PHYSICAL': '' };
  18115. this.type = 'MeshPhysicalMaterial';
  18116. this.reflectivity = 0.5; // maps to F0 = 0.04
  18117. this.clearCoat = 0.0;
  18118. this.clearCoatRoughness = 0.0;
  18119. this.setValues( parameters );
  18120. }
  18121. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  18122. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  18123. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  18124. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  18125. MeshStandardMaterial.prototype.copy.call( this, source );
  18126. this.defines = { 'PHYSICAL': '' };
  18127. this.reflectivity = source.reflectivity;
  18128. this.clearCoat = source.clearCoat;
  18129. this.clearCoatRoughness = source.clearCoatRoughness;
  18130. return this;
  18131. };
  18132. /**
  18133. * @author mrdoob / http://mrdoob.com/
  18134. * @author alteredq / http://alteredqualia.com/
  18135. *
  18136. * parameters = {
  18137. * color: <hex>,
  18138. * specular: <hex>,
  18139. * shininess: <float>,
  18140. * opacity: <float>,
  18141. *
  18142. * map: new THREE.Texture( <Image> ),
  18143. *
  18144. * lightMap: new THREE.Texture( <Image> ),
  18145. * lightMapIntensity: <float>
  18146. *
  18147. * aoMap: new THREE.Texture( <Image> ),
  18148. * aoMapIntensity: <float>
  18149. *
  18150. * emissive: <hex>,
  18151. * emissiveIntensity: <float>
  18152. * emissiveMap: new THREE.Texture( <Image> ),
  18153. *
  18154. * bumpMap: new THREE.Texture( <Image> ),
  18155. * bumpScale: <float>,
  18156. *
  18157. * normalMap: new THREE.Texture( <Image> ),
  18158. * normalScale: <Vector2>,
  18159. *
  18160. * displacementMap: new THREE.Texture( <Image> ),
  18161. * displacementScale: <float>,
  18162. * displacementBias: <float>,
  18163. *
  18164. * specularMap: new THREE.Texture( <Image> ),
  18165. *
  18166. * alphaMap: new THREE.Texture( <Image> ),
  18167. *
  18168. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  18169. * combine: THREE.Multiply,
  18170. * reflectivity: <float>,
  18171. * refractionRatio: <float>,
  18172. *
  18173. * wireframe: <boolean>,
  18174. * wireframeLinewidth: <float>,
  18175. *
  18176. * skinning: <bool>,
  18177. * morphTargets: <bool>,
  18178. * morphNormals: <bool>
  18179. * }
  18180. */
  18181. function MeshPhongMaterial( parameters ) {
  18182. Material.call( this );
  18183. this.type = 'MeshPhongMaterial';
  18184. this.color = new Color( 0xffffff ); // diffuse
  18185. this.specular = new Color( 0x111111 );
  18186. this.shininess = 30;
  18187. this.map = null;
  18188. this.lightMap = null;
  18189. this.lightMapIntensity = 1.0;
  18190. this.aoMap = null;
  18191. this.aoMapIntensity = 1.0;
  18192. this.emissive = new Color( 0x000000 );
  18193. this.emissiveIntensity = 1.0;
  18194. this.emissiveMap = null;
  18195. this.bumpMap = null;
  18196. this.bumpScale = 1;
  18197. this.normalMap = null;
  18198. this.normalScale = new Vector2( 1, 1 );
  18199. this.displacementMap = null;
  18200. this.displacementScale = 1;
  18201. this.displacementBias = 0;
  18202. this.specularMap = null;
  18203. this.alphaMap = null;
  18204. this.envMap = null;
  18205. this.combine = MultiplyOperation;
  18206. this.reflectivity = 1;
  18207. this.refractionRatio = 0.98;
  18208. this.wireframe = false;
  18209. this.wireframeLinewidth = 1;
  18210. this.wireframeLinecap = 'round';
  18211. this.wireframeLinejoin = 'round';
  18212. this.skinning = false;
  18213. this.morphTargets = false;
  18214. this.morphNormals = false;
  18215. this.setValues( parameters );
  18216. }
  18217. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  18218. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  18219. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  18220. MeshPhongMaterial.prototype.copy = function ( source ) {
  18221. Material.prototype.copy.call( this, source );
  18222. this.color.copy( source.color );
  18223. this.specular.copy( source.specular );
  18224. this.shininess = source.shininess;
  18225. this.map = source.map;
  18226. this.lightMap = source.lightMap;
  18227. this.lightMapIntensity = source.lightMapIntensity;
  18228. this.aoMap = source.aoMap;
  18229. this.aoMapIntensity = source.aoMapIntensity;
  18230. this.emissive.copy( source.emissive );
  18231. this.emissiveMap = source.emissiveMap;
  18232. this.emissiveIntensity = source.emissiveIntensity;
  18233. this.bumpMap = source.bumpMap;
  18234. this.bumpScale = source.bumpScale;
  18235. this.normalMap = source.normalMap;
  18236. this.normalScale.copy( source.normalScale );
  18237. this.displacementMap = source.displacementMap;
  18238. this.displacementScale = source.displacementScale;
  18239. this.displacementBias = source.displacementBias;
  18240. this.specularMap = source.specularMap;
  18241. this.alphaMap = source.alphaMap;
  18242. this.envMap = source.envMap;
  18243. this.combine = source.combine;
  18244. this.reflectivity = source.reflectivity;
  18245. this.refractionRatio = source.refractionRatio;
  18246. this.wireframe = source.wireframe;
  18247. this.wireframeLinewidth = source.wireframeLinewidth;
  18248. this.wireframeLinecap = source.wireframeLinecap;
  18249. this.wireframeLinejoin = source.wireframeLinejoin;
  18250. this.skinning = source.skinning;
  18251. this.morphTargets = source.morphTargets;
  18252. this.morphNormals = source.morphNormals;
  18253. return this;
  18254. };
  18255. /**
  18256. * @author takahirox / http://github.com/takahirox
  18257. *
  18258. * parameters = {
  18259. * gradientMap: new THREE.Texture( <Image> )
  18260. * }
  18261. */
  18262. function MeshToonMaterial( parameters ) {
  18263. MeshPhongMaterial.call( this );
  18264. this.defines = { 'TOON': '' };
  18265. this.type = 'MeshToonMaterial';
  18266. this.gradientMap = null;
  18267. this.setValues( parameters );
  18268. }
  18269. MeshToonMaterial.prototype = Object.create( MeshPhongMaterial.prototype );
  18270. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  18271. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  18272. MeshToonMaterial.prototype.copy = function ( source ) {
  18273. MeshPhongMaterial.prototype.copy.call( this, source );
  18274. this.gradientMap = source.gradientMap;
  18275. return this;
  18276. };
  18277. /**
  18278. * @author mrdoob / http://mrdoob.com/
  18279. * @author WestLangley / http://github.com/WestLangley
  18280. *
  18281. * parameters = {
  18282. * opacity: <float>,
  18283. *
  18284. * bumpMap: new THREE.Texture( <Image> ),
  18285. * bumpScale: <float>,
  18286. *
  18287. * normalMap: new THREE.Texture( <Image> ),
  18288. * normalScale: <Vector2>,
  18289. *
  18290. * displacementMap: new THREE.Texture( <Image> ),
  18291. * displacementScale: <float>,
  18292. * displacementBias: <float>,
  18293. *
  18294. * wireframe: <boolean>,
  18295. * wireframeLinewidth: <float>
  18296. *
  18297. * skinning: <bool>,
  18298. * morphTargets: <bool>,
  18299. * morphNormals: <bool>
  18300. * }
  18301. */
  18302. function MeshNormalMaterial( parameters ) {
  18303. Material.call( this );
  18304. this.type = 'MeshNormalMaterial';
  18305. this.bumpMap = null;
  18306. this.bumpScale = 1;
  18307. this.normalMap = null;
  18308. this.normalScale = new Vector2( 1, 1 );
  18309. this.displacementMap = null;
  18310. this.displacementScale = 1;
  18311. this.displacementBias = 0;
  18312. this.wireframe = false;
  18313. this.wireframeLinewidth = 1;
  18314. this.fog = false;
  18315. this.lights = false;
  18316. this.skinning = false;
  18317. this.morphTargets = false;
  18318. this.morphNormals = false;
  18319. this.setValues( parameters );
  18320. }
  18321. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  18322. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  18323. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  18324. MeshNormalMaterial.prototype.copy = function ( source ) {
  18325. Material.prototype.copy.call( this, source );
  18326. this.bumpMap = source.bumpMap;
  18327. this.bumpScale = source.bumpScale;
  18328. this.normalMap = source.normalMap;
  18329. this.normalScale.copy( source.normalScale );
  18330. this.displacementMap = source.displacementMap;
  18331. this.displacementScale = source.displacementScale;
  18332. this.displacementBias = source.displacementBias;
  18333. this.wireframe = source.wireframe;
  18334. this.wireframeLinewidth = source.wireframeLinewidth;
  18335. this.skinning = source.skinning;
  18336. this.morphTargets = source.morphTargets;
  18337. this.morphNormals = source.morphNormals;
  18338. return this;
  18339. };
  18340. /**
  18341. * @author mrdoob / http://mrdoob.com/
  18342. * @author alteredq / http://alteredqualia.com/
  18343. *
  18344. * parameters = {
  18345. * color: <hex>,
  18346. * opacity: <float>,
  18347. *
  18348. * map: new THREE.Texture( <Image> ),
  18349. *
  18350. * lightMap: new THREE.Texture( <Image> ),
  18351. * lightMapIntensity: <float>
  18352. *
  18353. * aoMap: new THREE.Texture( <Image> ),
  18354. * aoMapIntensity: <float>
  18355. *
  18356. * emissive: <hex>,
  18357. * emissiveIntensity: <float>
  18358. * emissiveMap: new THREE.Texture( <Image> ),
  18359. *
  18360. * specularMap: new THREE.Texture( <Image> ),
  18361. *
  18362. * alphaMap: new THREE.Texture( <Image> ),
  18363. *
  18364. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  18365. * combine: THREE.Multiply,
  18366. * reflectivity: <float>,
  18367. * refractionRatio: <float>,
  18368. *
  18369. * wireframe: <boolean>,
  18370. * wireframeLinewidth: <float>,
  18371. *
  18372. * skinning: <bool>,
  18373. * morphTargets: <bool>,
  18374. * morphNormals: <bool>
  18375. * }
  18376. */
  18377. function MeshLambertMaterial( parameters ) {
  18378. Material.call( this );
  18379. this.type = 'MeshLambertMaterial';
  18380. this.color = new Color( 0xffffff ); // diffuse
  18381. this.map = null;
  18382. this.lightMap = null;
  18383. this.lightMapIntensity = 1.0;
  18384. this.aoMap = null;
  18385. this.aoMapIntensity = 1.0;
  18386. this.emissive = new Color( 0x000000 );
  18387. this.emissiveIntensity = 1.0;
  18388. this.emissiveMap = null;
  18389. this.specularMap = null;
  18390. this.alphaMap = null;
  18391. this.envMap = null;
  18392. this.combine = MultiplyOperation;
  18393. this.reflectivity = 1;
  18394. this.refractionRatio = 0.98;
  18395. this.wireframe = false;
  18396. this.wireframeLinewidth = 1;
  18397. this.wireframeLinecap = 'round';
  18398. this.wireframeLinejoin = 'round';
  18399. this.skinning = false;
  18400. this.morphTargets = false;
  18401. this.morphNormals = false;
  18402. this.setValues( parameters );
  18403. }
  18404. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  18405. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  18406. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  18407. MeshLambertMaterial.prototype.copy = function ( source ) {
  18408. Material.prototype.copy.call( this, source );
  18409. this.color.copy( source.color );
  18410. this.map = source.map;
  18411. this.lightMap = source.lightMap;
  18412. this.lightMapIntensity = source.lightMapIntensity;
  18413. this.aoMap = source.aoMap;
  18414. this.aoMapIntensity = source.aoMapIntensity;
  18415. this.emissive.copy( source.emissive );
  18416. this.emissiveMap = source.emissiveMap;
  18417. this.emissiveIntensity = source.emissiveIntensity;
  18418. this.specularMap = source.specularMap;
  18419. this.alphaMap = source.alphaMap;
  18420. this.envMap = source.envMap;
  18421. this.combine = source.combine;
  18422. this.reflectivity = source.reflectivity;
  18423. this.refractionRatio = source.refractionRatio;
  18424. this.wireframe = source.wireframe;
  18425. this.wireframeLinewidth = source.wireframeLinewidth;
  18426. this.wireframeLinecap = source.wireframeLinecap;
  18427. this.wireframeLinejoin = source.wireframeLinejoin;
  18428. this.skinning = source.skinning;
  18429. this.morphTargets = source.morphTargets;
  18430. this.morphNormals = source.morphNormals;
  18431. return this;
  18432. };
  18433. /**
  18434. * @author alteredq / http://alteredqualia.com/
  18435. *
  18436. * parameters = {
  18437. * color: <hex>,
  18438. * opacity: <float>,
  18439. *
  18440. * linewidth: <float>,
  18441. *
  18442. * scale: <float>,
  18443. * dashSize: <float>,
  18444. * gapSize: <float>
  18445. * }
  18446. */
  18447. function LineDashedMaterial( parameters ) {
  18448. LineBasicMaterial.call( this );
  18449. this.type = 'LineDashedMaterial';
  18450. this.scale = 1;
  18451. this.dashSize = 3;
  18452. this.gapSize = 1;
  18453. this.setValues( parameters );
  18454. }
  18455. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  18456. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  18457. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  18458. LineDashedMaterial.prototype.copy = function ( source ) {
  18459. LineBasicMaterial.prototype.copy.call( this, source );
  18460. this.scale = source.scale;
  18461. this.dashSize = source.dashSize;
  18462. this.gapSize = source.gapSize;
  18463. return this;
  18464. };
  18465. var Materials = Object.freeze({
  18466. ShadowMaterial: ShadowMaterial,
  18467. SpriteMaterial: SpriteMaterial,
  18468. RawShaderMaterial: RawShaderMaterial,
  18469. ShaderMaterial: ShaderMaterial,
  18470. PointsMaterial: PointsMaterial,
  18471. MeshPhysicalMaterial: MeshPhysicalMaterial,
  18472. MeshStandardMaterial: MeshStandardMaterial,
  18473. MeshPhongMaterial: MeshPhongMaterial,
  18474. MeshToonMaterial: MeshToonMaterial,
  18475. MeshNormalMaterial: MeshNormalMaterial,
  18476. MeshLambertMaterial: MeshLambertMaterial,
  18477. MeshDepthMaterial: MeshDepthMaterial,
  18478. MeshDistanceMaterial: MeshDistanceMaterial,
  18479. MeshBasicMaterial: MeshBasicMaterial,
  18480. LineDashedMaterial: LineDashedMaterial,
  18481. LineBasicMaterial: LineBasicMaterial,
  18482. Material: Material
  18483. });
  18484. /**
  18485. * @author mrdoob / http://mrdoob.com/
  18486. */
  18487. var Cache = {
  18488. enabled: false,
  18489. files: {},
  18490. add: function ( key, file ) {
  18491. if ( this.enabled === false ) return;
  18492. // console.log( 'THREE.Cache', 'Adding key:', key );
  18493. this.files[ key ] = file;
  18494. },
  18495. get: function ( key ) {
  18496. if ( this.enabled === false ) return;
  18497. // console.log( 'THREE.Cache', 'Checking key:', key );
  18498. return this.files[ key ];
  18499. },
  18500. remove: function ( key ) {
  18501. delete this.files[ key ];
  18502. },
  18503. clear: function () {
  18504. this.files = {};
  18505. }
  18506. };
  18507. /**
  18508. * @author mrdoob / http://mrdoob.com/
  18509. */
  18510. function LoadingManager( onLoad, onProgress, onError ) {
  18511. var scope = this;
  18512. var isLoading = false;
  18513. var itemsLoaded = 0;
  18514. var itemsTotal = 0;
  18515. var urlModifier = undefined;
  18516. this.onStart = undefined;
  18517. this.onLoad = onLoad;
  18518. this.onProgress = onProgress;
  18519. this.onError = onError;
  18520. this.itemStart = function ( url ) {
  18521. itemsTotal ++;
  18522. if ( isLoading === false ) {
  18523. if ( scope.onStart !== undefined ) {
  18524. scope.onStart( url, itemsLoaded, itemsTotal );
  18525. }
  18526. }
  18527. isLoading = true;
  18528. };
  18529. this.itemEnd = function ( url ) {
  18530. itemsLoaded ++;
  18531. if ( scope.onProgress !== undefined ) {
  18532. scope.onProgress( url, itemsLoaded, itemsTotal );
  18533. }
  18534. if ( itemsLoaded === itemsTotal ) {
  18535. isLoading = false;
  18536. if ( scope.onLoad !== undefined ) {
  18537. scope.onLoad();
  18538. }
  18539. }
  18540. };
  18541. this.itemError = function ( url ) {
  18542. if ( scope.onError !== undefined ) {
  18543. scope.onError( url );
  18544. }
  18545. };
  18546. this.resolveURL = function ( url ) {
  18547. if ( urlModifier ) {
  18548. return urlModifier( url );
  18549. }
  18550. return url;
  18551. };
  18552. this.setURLModifier = function ( transform ) {
  18553. urlModifier = transform;
  18554. return this;
  18555. };
  18556. }
  18557. var DefaultLoadingManager = new LoadingManager();
  18558. /**
  18559. * @author mrdoob / http://mrdoob.com/
  18560. */
  18561. var loading = {};
  18562. function FileLoader( manager ) {
  18563. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18564. }
  18565. Object.assign( FileLoader.prototype, {
  18566. load: function ( url, onLoad, onProgress, onError ) {
  18567. if ( url === undefined ) url = '';
  18568. if ( this.path !== undefined ) url = this.path + url;
  18569. url = this.manager.resolveURL( url );
  18570. var scope = this;
  18571. var cached = Cache.get( url );
  18572. if ( cached !== undefined ) {
  18573. scope.manager.itemStart( url );
  18574. setTimeout( function () {
  18575. if ( onLoad ) onLoad( cached );
  18576. scope.manager.itemEnd( url );
  18577. }, 0 );
  18578. return cached;
  18579. }
  18580. // Check if request is duplicate
  18581. if ( loading[ url ] !== undefined ) {
  18582. loading[ url ].push( {
  18583. onLoad: onLoad,
  18584. onProgress: onProgress,
  18585. onError: onError
  18586. } );
  18587. return;
  18588. }
  18589. // Check for data: URI
  18590. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  18591. var dataUriRegexResult = url.match( dataUriRegex );
  18592. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  18593. if ( dataUriRegexResult ) {
  18594. var mimeType = dataUriRegexResult[ 1 ];
  18595. var isBase64 = !! dataUriRegexResult[ 2 ];
  18596. var data = dataUriRegexResult[ 3 ];
  18597. data = window.decodeURIComponent( data );
  18598. if ( isBase64 ) data = window.atob( data );
  18599. try {
  18600. var response;
  18601. var responseType = ( this.responseType || '' ).toLowerCase();
  18602. switch ( responseType ) {
  18603. case 'arraybuffer':
  18604. case 'blob':
  18605. var view = new Uint8Array( data.length );
  18606. for ( var i = 0; i < data.length; i ++ ) {
  18607. view[ i ] = data.charCodeAt( i );
  18608. }
  18609. if ( responseType === 'blob' ) {
  18610. response = new Blob( [ view.buffer ], { type: mimeType } );
  18611. } else {
  18612. response = view.buffer;
  18613. }
  18614. break;
  18615. case 'document':
  18616. var parser = new DOMParser();
  18617. response = parser.parseFromString( data, mimeType );
  18618. break;
  18619. case 'json':
  18620. response = JSON.parse( data );
  18621. break;
  18622. default: // 'text' or other
  18623. response = data;
  18624. break;
  18625. }
  18626. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  18627. window.setTimeout( function () {
  18628. if ( onLoad ) onLoad( response );
  18629. scope.manager.itemEnd( url );
  18630. }, 0 );
  18631. } catch ( error ) {
  18632. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  18633. window.setTimeout( function () {
  18634. if ( onError ) onError( error );
  18635. scope.manager.itemEnd( url );
  18636. scope.manager.itemError( url );
  18637. }, 0 );
  18638. }
  18639. } else {
  18640. // Initialise array for duplicate requests
  18641. loading[ url ] = [];
  18642. loading[ url ].push( {
  18643. onLoad: onLoad,
  18644. onProgress: onProgress,
  18645. onError: onError
  18646. } );
  18647. var request = new XMLHttpRequest();
  18648. request.open( 'GET', url, true );
  18649. request.addEventListener( 'load', function ( event ) {
  18650. var response = this.response;
  18651. Cache.add( url, response );
  18652. var callbacks = loading[ url ];
  18653. delete loading[ url ];
  18654. if ( this.status === 200 || this.status === 0 ) {
  18655. // Some browsers return HTTP Status 0 when using non-http protocol
  18656. // e.g. 'file://' or 'data://'. Handle as success.
  18657. if ( this.status === 0 ) console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  18658. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  18659. var callback = callbacks[ i ];
  18660. if ( callback.onLoad ) callback.onLoad( response );
  18661. }
  18662. scope.manager.itemEnd( url );
  18663. } else {
  18664. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  18665. var callback = callbacks[ i ];
  18666. if ( callback.onError ) callback.onError( event );
  18667. }
  18668. scope.manager.itemEnd( url );
  18669. scope.manager.itemError( url );
  18670. }
  18671. }, false );
  18672. request.addEventListener( 'progress', function ( event ) {
  18673. var callbacks = loading[ url ];
  18674. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  18675. var callback = callbacks[ i ];
  18676. if ( callback.onProgress ) callback.onProgress( event );
  18677. }
  18678. }, false );
  18679. request.addEventListener( 'error', function ( event ) {
  18680. var callbacks = loading[ url ];
  18681. delete loading[ url ];
  18682. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  18683. var callback = callbacks[ i ];
  18684. if ( callback.onError ) callback.onError( event );
  18685. }
  18686. scope.manager.itemEnd( url );
  18687. scope.manager.itemError( url );
  18688. }, false );
  18689. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  18690. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  18691. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  18692. for ( var header in this.requestHeader ) {
  18693. request.setRequestHeader( header, this.requestHeader[ header ] );
  18694. }
  18695. request.send( null );
  18696. }
  18697. scope.manager.itemStart( url );
  18698. return request;
  18699. },
  18700. setPath: function ( value ) {
  18701. this.path = value;
  18702. return this;
  18703. },
  18704. setResponseType: function ( value ) {
  18705. this.responseType = value;
  18706. return this;
  18707. },
  18708. setWithCredentials: function ( value ) {
  18709. this.withCredentials = value;
  18710. return this;
  18711. },
  18712. setMimeType: function ( value ) {
  18713. this.mimeType = value;
  18714. return this;
  18715. },
  18716. setRequestHeader: function ( value ) {
  18717. this.requestHeader = value;
  18718. return this;
  18719. }
  18720. } );
  18721. /**
  18722. * @author mrdoob / http://mrdoob.com/
  18723. *
  18724. * Abstract Base class to block based textures loader (dds, pvr, ...)
  18725. */
  18726. function CompressedTextureLoader( manager ) {
  18727. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18728. // override in sub classes
  18729. this._parser = null;
  18730. }
  18731. Object.assign( CompressedTextureLoader.prototype, {
  18732. load: function ( url, onLoad, onProgress, onError ) {
  18733. var scope = this;
  18734. var images = [];
  18735. var texture = new CompressedTexture();
  18736. texture.image = images;
  18737. var loader = new FileLoader( this.manager );
  18738. loader.setPath( this.path );
  18739. loader.setResponseType( 'arraybuffer' );
  18740. function loadTexture( i ) {
  18741. loader.load( url[ i ], function ( buffer ) {
  18742. var texDatas = scope._parser( buffer, true );
  18743. images[ i ] = {
  18744. width: texDatas.width,
  18745. height: texDatas.height,
  18746. format: texDatas.format,
  18747. mipmaps: texDatas.mipmaps
  18748. };
  18749. loaded += 1;
  18750. if ( loaded === 6 ) {
  18751. if ( texDatas.mipmapCount === 1 )
  18752. texture.minFilter = LinearFilter;
  18753. texture.format = texDatas.format;
  18754. texture.needsUpdate = true;
  18755. if ( onLoad ) onLoad( texture );
  18756. }
  18757. }, onProgress, onError );
  18758. }
  18759. if ( Array.isArray( url ) ) {
  18760. var loaded = 0;
  18761. for ( var i = 0, il = url.length; i < il; ++ i ) {
  18762. loadTexture( i );
  18763. }
  18764. } else {
  18765. // compressed cubemap texture stored in a single DDS file
  18766. loader.load( url, function ( buffer ) {
  18767. var texDatas = scope._parser( buffer, true );
  18768. if ( texDatas.isCubemap ) {
  18769. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  18770. for ( var f = 0; f < faces; f ++ ) {
  18771. images[ f ] = { mipmaps: [] };
  18772. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  18773. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  18774. images[ f ].format = texDatas.format;
  18775. images[ f ].width = texDatas.width;
  18776. images[ f ].height = texDatas.height;
  18777. }
  18778. }
  18779. } else {
  18780. texture.image.width = texDatas.width;
  18781. texture.image.height = texDatas.height;
  18782. texture.mipmaps = texDatas.mipmaps;
  18783. }
  18784. if ( texDatas.mipmapCount === 1 ) {
  18785. texture.minFilter = LinearFilter;
  18786. }
  18787. texture.format = texDatas.format;
  18788. texture.needsUpdate = true;
  18789. if ( onLoad ) onLoad( texture );
  18790. }, onProgress, onError );
  18791. }
  18792. return texture;
  18793. },
  18794. setPath: function ( value ) {
  18795. this.path = value;
  18796. return this;
  18797. }
  18798. } );
  18799. /**
  18800. * @author Nikos M. / https://github.com/foo123/
  18801. *
  18802. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  18803. */
  18804. function DataTextureLoader( manager ) {
  18805. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18806. // override in sub classes
  18807. this._parser = null;
  18808. }
  18809. Object.assign( DataTextureLoader.prototype, {
  18810. load: function ( url, onLoad, onProgress, onError ) {
  18811. var scope = this;
  18812. var texture = new DataTexture();
  18813. var loader = new FileLoader( this.manager );
  18814. loader.setResponseType( 'arraybuffer' );
  18815. loader.load( url, function ( buffer ) {
  18816. var texData = scope._parser( buffer );
  18817. if ( ! texData ) return;
  18818. if ( undefined !== texData.image ) {
  18819. texture.image = texData.image;
  18820. } else if ( undefined !== texData.data ) {
  18821. texture.image.width = texData.width;
  18822. texture.image.height = texData.height;
  18823. texture.image.data = texData.data;
  18824. }
  18825. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : ClampToEdgeWrapping;
  18826. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : ClampToEdgeWrapping;
  18827. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : LinearFilter;
  18828. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : LinearMipMapLinearFilter;
  18829. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  18830. if ( undefined !== texData.format ) {
  18831. texture.format = texData.format;
  18832. }
  18833. if ( undefined !== texData.type ) {
  18834. texture.type = texData.type;
  18835. }
  18836. if ( undefined !== texData.mipmaps ) {
  18837. texture.mipmaps = texData.mipmaps;
  18838. }
  18839. if ( 1 === texData.mipmapCount ) {
  18840. texture.minFilter = LinearFilter;
  18841. }
  18842. texture.needsUpdate = true;
  18843. if ( onLoad ) onLoad( texture, texData );
  18844. }, onProgress, onError );
  18845. return texture;
  18846. }
  18847. } );
  18848. /**
  18849. * @author mrdoob / http://mrdoob.com/
  18850. */
  18851. function ImageLoader( manager ) {
  18852. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18853. }
  18854. Object.assign( ImageLoader.prototype, {
  18855. crossOrigin: 'Anonymous',
  18856. load: function ( url, onLoad, onProgress, onError ) {
  18857. if ( url === undefined ) url = '';
  18858. if ( this.path !== undefined ) url = this.path + url;
  18859. url = this.manager.resolveURL( url );
  18860. var scope = this;
  18861. var cached = Cache.get( url );
  18862. if ( cached !== undefined ) {
  18863. scope.manager.itemStart( url );
  18864. setTimeout( function () {
  18865. if ( onLoad ) onLoad( cached );
  18866. scope.manager.itemEnd( url );
  18867. }, 0 );
  18868. return cached;
  18869. }
  18870. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  18871. function onImageLoad() {
  18872. image.removeEventListener( 'load', onImageLoad, false );
  18873. image.removeEventListener( 'error', onImageError, false );
  18874. Cache.add( url, this );
  18875. if ( onLoad ) onLoad( this );
  18876. scope.manager.itemEnd( url );
  18877. }
  18878. function onImageError( event ) {
  18879. image.removeEventListener( 'load', onImageLoad, false );
  18880. image.removeEventListener( 'error', onImageError, false );
  18881. if ( onError ) onError( event );
  18882. scope.manager.itemEnd( url );
  18883. scope.manager.itemError( url );
  18884. }
  18885. image.addEventListener( 'load', onImageLoad, false );
  18886. image.addEventListener( 'error', onImageError, false );
  18887. if ( url.substr( 0, 5 ) !== 'data:' ) {
  18888. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  18889. }
  18890. scope.manager.itemStart( url );
  18891. image.src = url;
  18892. return image;
  18893. },
  18894. setCrossOrigin: function ( value ) {
  18895. this.crossOrigin = value;
  18896. return this;
  18897. },
  18898. setPath: function ( value ) {
  18899. this.path = value;
  18900. return this;
  18901. }
  18902. } );
  18903. /**
  18904. * @author mrdoob / http://mrdoob.com/
  18905. */
  18906. function CubeTextureLoader( manager ) {
  18907. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18908. }
  18909. Object.assign( CubeTextureLoader.prototype, {
  18910. crossOrigin: 'Anonymous',
  18911. load: function ( urls, onLoad, onProgress, onError ) {
  18912. var texture = new CubeTexture();
  18913. var loader = new ImageLoader( this.manager );
  18914. loader.setCrossOrigin( this.crossOrigin );
  18915. loader.setPath( this.path );
  18916. var loaded = 0;
  18917. function loadTexture( i ) {
  18918. loader.load( urls[ i ], function ( image ) {
  18919. texture.images[ i ] = image;
  18920. loaded ++;
  18921. if ( loaded === 6 ) {
  18922. texture.needsUpdate = true;
  18923. if ( onLoad ) onLoad( texture );
  18924. }
  18925. }, undefined, onError );
  18926. }
  18927. for ( var i = 0; i < urls.length; ++ i ) {
  18928. loadTexture( i );
  18929. }
  18930. return texture;
  18931. },
  18932. setCrossOrigin: function ( value ) {
  18933. this.crossOrigin = value;
  18934. return this;
  18935. },
  18936. setPath: function ( value ) {
  18937. this.path = value;
  18938. return this;
  18939. }
  18940. } );
  18941. /**
  18942. * @author mrdoob / http://mrdoob.com/
  18943. */
  18944. function TextureLoader( manager ) {
  18945. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  18946. }
  18947. Object.assign( TextureLoader.prototype, {
  18948. crossOrigin: 'Anonymous',
  18949. load: function ( url, onLoad, onProgress, onError ) {
  18950. var texture = new Texture();
  18951. var loader = new ImageLoader( this.manager );
  18952. loader.setCrossOrigin( this.crossOrigin );
  18953. loader.setPath( this.path );
  18954. loader.load( url, function ( image ) {
  18955. texture.image = image;
  18956. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  18957. var isJPEG = url.search( /\.(jpg|jpeg)$/ ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  18958. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  18959. texture.needsUpdate = true;
  18960. if ( onLoad !== undefined ) {
  18961. onLoad( texture );
  18962. }
  18963. }, onProgress, onError );
  18964. return texture;
  18965. },
  18966. setCrossOrigin: function ( value ) {
  18967. this.crossOrigin = value;
  18968. return this;
  18969. },
  18970. setPath: function ( value ) {
  18971. this.path = value;
  18972. return this;
  18973. }
  18974. } );
  18975. /**
  18976. * @author zz85 / http://www.lab4games.net/zz85/blog
  18977. * Extensible curve object
  18978. *
  18979. * Some common of curve methods:
  18980. * .getPoint( t, optionalTarget ), .getTangent( t )
  18981. * .getPointAt( u, optionalTarget ), .getTangentAt( u )
  18982. * .getPoints(), .getSpacedPoints()
  18983. * .getLength()
  18984. * .updateArcLengths()
  18985. *
  18986. * This following curves inherit from THREE.Curve:
  18987. *
  18988. * -- 2D curves --
  18989. * THREE.ArcCurve
  18990. * THREE.CubicBezierCurve
  18991. * THREE.EllipseCurve
  18992. * THREE.LineCurve
  18993. * THREE.QuadraticBezierCurve
  18994. * THREE.SplineCurve
  18995. *
  18996. * -- 3D curves --
  18997. * THREE.CatmullRomCurve3
  18998. * THREE.CubicBezierCurve3
  18999. * THREE.LineCurve3
  19000. * THREE.QuadraticBezierCurve3
  19001. *
  19002. * A series of curves can be represented as a THREE.CurvePath.
  19003. *
  19004. **/
  19005. /**************************************************************
  19006. * Abstract Curve base class
  19007. **************************************************************/
  19008. function Curve() {
  19009. this.type = 'Curve';
  19010. this.arcLengthDivisions = 200;
  19011. }
  19012. Object.assign( Curve.prototype, {
  19013. // Virtual base class method to overwrite and implement in subclasses
  19014. // - t [0 .. 1]
  19015. getPoint: function ( /* t, optionalTarget */ ) {
  19016. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  19017. return null;
  19018. },
  19019. // Get point at relative position in curve according to arc length
  19020. // - u [0 .. 1]
  19021. getPointAt: function ( u, optionalTarget ) {
  19022. var t = this.getUtoTmapping( u );
  19023. return this.getPoint( t, optionalTarget );
  19024. },
  19025. // Get sequence of points using getPoint( t )
  19026. getPoints: function ( divisions ) {
  19027. if ( divisions === undefined ) divisions = 5;
  19028. var points = [];
  19029. for ( var d = 0; d <= divisions; d ++ ) {
  19030. points.push( this.getPoint( d / divisions ) );
  19031. }
  19032. return points;
  19033. },
  19034. // Get sequence of points using getPointAt( u )
  19035. getSpacedPoints: function ( divisions ) {
  19036. if ( divisions === undefined ) divisions = 5;
  19037. var points = [];
  19038. for ( var d = 0; d <= divisions; d ++ ) {
  19039. points.push( this.getPointAt( d / divisions ) );
  19040. }
  19041. return points;
  19042. },
  19043. // Get total curve arc length
  19044. getLength: function () {
  19045. var lengths = this.getLengths();
  19046. return lengths[ lengths.length - 1 ];
  19047. },
  19048. // Get list of cumulative segment lengths
  19049. getLengths: function ( divisions ) {
  19050. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  19051. if ( this.cacheArcLengths &&
  19052. ( this.cacheArcLengths.length === divisions + 1 ) &&
  19053. ! this.needsUpdate ) {
  19054. return this.cacheArcLengths;
  19055. }
  19056. this.needsUpdate = false;
  19057. var cache = [];
  19058. var current, last = this.getPoint( 0 );
  19059. var p, sum = 0;
  19060. cache.push( 0 );
  19061. for ( p = 1; p <= divisions; p ++ ) {
  19062. current = this.getPoint( p / divisions );
  19063. sum += current.distanceTo( last );
  19064. cache.push( sum );
  19065. last = current;
  19066. }
  19067. this.cacheArcLengths = cache;
  19068. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  19069. },
  19070. updateArcLengths: function () {
  19071. this.needsUpdate = true;
  19072. this.getLengths();
  19073. },
  19074. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  19075. getUtoTmapping: function ( u, distance ) {
  19076. var arcLengths = this.getLengths();
  19077. var i = 0, il = arcLengths.length;
  19078. var targetArcLength; // The targeted u distance value to get
  19079. if ( distance ) {
  19080. targetArcLength = distance;
  19081. } else {
  19082. targetArcLength = u * arcLengths[ il - 1 ];
  19083. }
  19084. // binary search for the index with largest value smaller than target u distance
  19085. var low = 0, high = il - 1, comparison;
  19086. while ( low <= high ) {
  19087. 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
  19088. comparison = arcLengths[ i ] - targetArcLength;
  19089. if ( comparison < 0 ) {
  19090. low = i + 1;
  19091. } else if ( comparison > 0 ) {
  19092. high = i - 1;
  19093. } else {
  19094. high = i;
  19095. break;
  19096. // DONE
  19097. }
  19098. }
  19099. i = high;
  19100. if ( arcLengths[ i ] === targetArcLength ) {
  19101. return i / ( il - 1 );
  19102. }
  19103. // we could get finer grain at lengths, or use simple interpolation between two points
  19104. var lengthBefore = arcLengths[ i ];
  19105. var lengthAfter = arcLengths[ i + 1 ];
  19106. var segmentLength = lengthAfter - lengthBefore;
  19107. // determine where we are between the 'before' and 'after' points
  19108. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  19109. // add that fractional amount to t
  19110. var t = ( i + segmentFraction ) / ( il - 1 );
  19111. return t;
  19112. },
  19113. // Returns a unit vector tangent at t
  19114. // In case any sub curve does not implement its tangent derivation,
  19115. // 2 points a small delta apart will be used to find its gradient
  19116. // which seems to give a reasonable approximation
  19117. getTangent: function ( t ) {
  19118. var delta = 0.0001;
  19119. var t1 = t - delta;
  19120. var t2 = t + delta;
  19121. // Capping in case of danger
  19122. if ( t1 < 0 ) t1 = 0;
  19123. if ( t2 > 1 ) t2 = 1;
  19124. var pt1 = this.getPoint( t1 );
  19125. var pt2 = this.getPoint( t2 );
  19126. var vec = pt2.clone().sub( pt1 );
  19127. return vec.normalize();
  19128. },
  19129. getTangentAt: function ( u ) {
  19130. var t = this.getUtoTmapping( u );
  19131. return this.getTangent( t );
  19132. },
  19133. computeFrenetFrames: function ( segments, closed ) {
  19134. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  19135. var normal = new Vector3();
  19136. var tangents = [];
  19137. var normals = [];
  19138. var binormals = [];
  19139. var vec = new Vector3();
  19140. var mat = new Matrix4();
  19141. var i, u, theta;
  19142. // compute the tangent vectors for each segment on the curve
  19143. for ( i = 0; i <= segments; i ++ ) {
  19144. u = i / segments;
  19145. tangents[ i ] = this.getTangentAt( u );
  19146. tangents[ i ].normalize();
  19147. }
  19148. // select an initial normal vector perpendicular to the first tangent vector,
  19149. // and in the direction of the minimum tangent xyz component
  19150. normals[ 0 ] = new Vector3();
  19151. binormals[ 0 ] = new Vector3();
  19152. var min = Number.MAX_VALUE;
  19153. var tx = Math.abs( tangents[ 0 ].x );
  19154. var ty = Math.abs( tangents[ 0 ].y );
  19155. var tz = Math.abs( tangents[ 0 ].z );
  19156. if ( tx <= min ) {
  19157. min = tx;
  19158. normal.set( 1, 0, 0 );
  19159. }
  19160. if ( ty <= min ) {
  19161. min = ty;
  19162. normal.set( 0, 1, 0 );
  19163. }
  19164. if ( tz <= min ) {
  19165. normal.set( 0, 0, 1 );
  19166. }
  19167. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  19168. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  19169. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  19170. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  19171. for ( i = 1; i <= segments; i ++ ) {
  19172. normals[ i ] = normals[ i - 1 ].clone();
  19173. binormals[ i ] = binormals[ i - 1 ].clone();
  19174. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  19175. if ( vec.length() > Number.EPSILON ) {
  19176. vec.normalize();
  19177. theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  19178. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  19179. }
  19180. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  19181. }
  19182. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  19183. if ( closed === true ) {
  19184. theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  19185. theta /= segments;
  19186. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  19187. theta = - theta;
  19188. }
  19189. for ( i = 1; i <= segments; i ++ ) {
  19190. // twist a little...
  19191. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  19192. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  19193. }
  19194. }
  19195. return {
  19196. tangents: tangents,
  19197. normals: normals,
  19198. binormals: binormals
  19199. };
  19200. },
  19201. clone: function () {
  19202. return new this.constructor().copy( this );
  19203. },
  19204. copy: function ( source ) {
  19205. this.arcLengthDivisions = source.arcLengthDivisions;
  19206. return this;
  19207. },
  19208. toJSON: function () {
  19209. var data = {
  19210. metadata: {
  19211. version: 4.5,
  19212. type: 'Curve',
  19213. generator: 'Curve.toJSON'
  19214. }
  19215. };
  19216. data.arcLengthDivisions = this.arcLengthDivisions;
  19217. data.type = this.type;
  19218. return data;
  19219. },
  19220. fromJSON: function ( json ) {
  19221. this.arcLengthDivisions = json.arcLengthDivisions;
  19222. return this;
  19223. }
  19224. } );
  19225. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  19226. Curve.call( this );
  19227. this.type = 'EllipseCurve';
  19228. this.aX = aX || 0;
  19229. this.aY = aY || 0;
  19230. this.xRadius = xRadius || 1;
  19231. this.yRadius = yRadius || 1;
  19232. this.aStartAngle = aStartAngle || 0;
  19233. this.aEndAngle = aEndAngle || 2 * Math.PI;
  19234. this.aClockwise = aClockwise || false;
  19235. this.aRotation = aRotation || 0;
  19236. }
  19237. EllipseCurve.prototype = Object.create( Curve.prototype );
  19238. EllipseCurve.prototype.constructor = EllipseCurve;
  19239. EllipseCurve.prototype.isEllipseCurve = true;
  19240. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  19241. var point = optionalTarget || new Vector2();
  19242. var twoPi = Math.PI * 2;
  19243. var deltaAngle = this.aEndAngle - this.aStartAngle;
  19244. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  19245. // ensures that deltaAngle is 0 .. 2 PI
  19246. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  19247. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  19248. if ( deltaAngle < Number.EPSILON ) {
  19249. if ( samePoints ) {
  19250. deltaAngle = 0;
  19251. } else {
  19252. deltaAngle = twoPi;
  19253. }
  19254. }
  19255. if ( this.aClockwise === true && ! samePoints ) {
  19256. if ( deltaAngle === twoPi ) {
  19257. deltaAngle = - twoPi;
  19258. } else {
  19259. deltaAngle = deltaAngle - twoPi;
  19260. }
  19261. }
  19262. var angle = this.aStartAngle + t * deltaAngle;
  19263. var x = this.aX + this.xRadius * Math.cos( angle );
  19264. var y = this.aY + this.yRadius * Math.sin( angle );
  19265. if ( this.aRotation !== 0 ) {
  19266. var cos = Math.cos( this.aRotation );
  19267. var sin = Math.sin( this.aRotation );
  19268. var tx = x - this.aX;
  19269. var ty = y - this.aY;
  19270. // Rotate the point about the center of the ellipse.
  19271. x = tx * cos - ty * sin + this.aX;
  19272. y = tx * sin + ty * cos + this.aY;
  19273. }
  19274. return point.set( x, y );
  19275. };
  19276. EllipseCurve.prototype.copy = function ( source ) {
  19277. Curve.prototype.copy.call( this, source );
  19278. this.aX = source.aX;
  19279. this.aY = source.aY;
  19280. this.xRadius = source.xRadius;
  19281. this.yRadius = source.yRadius;
  19282. this.aStartAngle = source.aStartAngle;
  19283. this.aEndAngle = source.aEndAngle;
  19284. this.aClockwise = source.aClockwise;
  19285. this.aRotation = source.aRotation;
  19286. return this;
  19287. };
  19288. EllipseCurve.prototype.toJSON = function () {
  19289. var data = Curve.prototype.toJSON.call( this );
  19290. data.aX = this.aX;
  19291. data.aY = this.aY;
  19292. data.xRadius = this.xRadius;
  19293. data.yRadius = this.yRadius;
  19294. data.aStartAngle = this.aStartAngle;
  19295. data.aEndAngle = this.aEndAngle;
  19296. data.aClockwise = this.aClockwise;
  19297. data.aRotation = this.aRotation;
  19298. return data;
  19299. };
  19300. EllipseCurve.prototype.fromJSON = function ( json ) {
  19301. Curve.prototype.fromJSON.call( this, json );
  19302. this.aX = json.aX;
  19303. this.aY = json.aY;
  19304. this.xRadius = json.xRadius;
  19305. this.yRadius = json.yRadius;
  19306. this.aStartAngle = json.aStartAngle;
  19307. this.aEndAngle = json.aEndAngle;
  19308. this.aClockwise = json.aClockwise;
  19309. this.aRotation = json.aRotation;
  19310. return this;
  19311. };
  19312. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  19313. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  19314. this.type = 'ArcCurve';
  19315. }
  19316. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  19317. ArcCurve.prototype.constructor = ArcCurve;
  19318. ArcCurve.prototype.isArcCurve = true;
  19319. /**
  19320. * @author zz85 https://github.com/zz85
  19321. *
  19322. * Centripetal CatmullRom Curve - which is useful for avoiding
  19323. * cusps and self-intersections in non-uniform catmull rom curves.
  19324. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  19325. *
  19326. * curve.type accepts centripetal(default), chordal and catmullrom
  19327. * curve.tension is used for catmullrom which defaults to 0.5
  19328. */
  19329. /*
  19330. Based on an optimized c++ solution in
  19331. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  19332. - http://ideone.com/NoEbVM
  19333. This CubicPoly class could be used for reusing some variables and calculations,
  19334. but for three.js curve use, it could be possible inlined and flatten into a single function call
  19335. which can be placed in CurveUtils.
  19336. */
  19337. function CubicPoly() {
  19338. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  19339. /*
  19340. * Compute coefficients for a cubic polynomial
  19341. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  19342. * such that
  19343. * p(0) = x0, p(1) = x1
  19344. * and
  19345. * p'(0) = t0, p'(1) = t1.
  19346. */
  19347. function init( x0, x1, t0, t1 ) {
  19348. c0 = x0;
  19349. c1 = t0;
  19350. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  19351. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  19352. }
  19353. return {
  19354. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  19355. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  19356. },
  19357. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  19358. // compute tangents when parameterized in [t1,t2]
  19359. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  19360. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  19361. // rescale tangents for parametrization in [0,1]
  19362. t1 *= dt1;
  19363. t2 *= dt1;
  19364. init( x1, x2, t1, t2 );
  19365. },
  19366. calc: function ( t ) {
  19367. var t2 = t * t;
  19368. var t3 = t2 * t;
  19369. return c0 + c1 * t + c2 * t2 + c3 * t3;
  19370. }
  19371. };
  19372. }
  19373. //
  19374. var tmp = new Vector3();
  19375. var px = new CubicPoly();
  19376. var py = new CubicPoly();
  19377. var pz = new CubicPoly();
  19378. function CatmullRomCurve3( points, closed, curveType, tension ) {
  19379. Curve.call( this );
  19380. this.type = 'CatmullRomCurve3';
  19381. this.points = points || [];
  19382. this.closed = closed || false;
  19383. this.curveType = curveType || 'centripetal';
  19384. this.tension = tension || 0.5;
  19385. }
  19386. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  19387. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  19388. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  19389. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  19390. var point = optionalTarget || new Vector3();
  19391. var points = this.points;
  19392. var l = points.length;
  19393. var p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  19394. var intPoint = Math.floor( p );
  19395. var weight = p - intPoint;
  19396. if ( this.closed ) {
  19397. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  19398. } else if ( weight === 0 && intPoint === l - 1 ) {
  19399. intPoint = l - 2;
  19400. weight = 1;
  19401. }
  19402. var p0, p1, p2, p3; // 4 points
  19403. if ( this.closed || intPoint > 0 ) {
  19404. p0 = points[ ( intPoint - 1 ) % l ];
  19405. } else {
  19406. // extrapolate first point
  19407. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  19408. p0 = tmp;
  19409. }
  19410. p1 = points[ intPoint % l ];
  19411. p2 = points[ ( intPoint + 1 ) % l ];
  19412. if ( this.closed || intPoint + 2 < l ) {
  19413. p3 = points[ ( intPoint + 2 ) % l ];
  19414. } else {
  19415. // extrapolate last point
  19416. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  19417. p3 = tmp;
  19418. }
  19419. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  19420. // init Centripetal / Chordal Catmull-Rom
  19421. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  19422. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  19423. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  19424. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  19425. // safety check for repeated points
  19426. if ( dt1 < 1e-4 ) dt1 = 1.0;
  19427. if ( dt0 < 1e-4 ) dt0 = dt1;
  19428. if ( dt2 < 1e-4 ) dt2 = dt1;
  19429. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  19430. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  19431. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  19432. } else if ( this.curveType === 'catmullrom' ) {
  19433. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  19434. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  19435. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  19436. }
  19437. point.set(
  19438. px.calc( weight ),
  19439. py.calc( weight ),
  19440. pz.calc( weight )
  19441. );
  19442. return point;
  19443. };
  19444. CatmullRomCurve3.prototype.copy = function ( source ) {
  19445. Curve.prototype.copy.call( this, source );
  19446. this.points = [];
  19447. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  19448. var point = source.points[ i ];
  19449. this.points.push( point.clone() );
  19450. }
  19451. this.closed = source.closed;
  19452. this.curveType = source.curveType;
  19453. this.tension = source.tension;
  19454. return this;
  19455. };
  19456. CatmullRomCurve3.prototype.toJSON = function () {
  19457. var data = Curve.prototype.toJSON.call( this );
  19458. data.points = [];
  19459. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  19460. var point = this.points[ i ];
  19461. data.points.push( point.toArray() );
  19462. }
  19463. data.closed = this.closed;
  19464. data.curveType = this.curveType;
  19465. data.tension = this.tension;
  19466. return data;
  19467. };
  19468. CatmullRomCurve3.prototype.fromJSON = function ( json ) {
  19469. Curve.prototype.fromJSON.call( this, json );
  19470. this.points = [];
  19471. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  19472. var point = json.points[ i ];
  19473. this.points.push( new Vector3().fromArray( point ) );
  19474. }
  19475. this.closed = json.closed;
  19476. this.curveType = json.curveType;
  19477. this.tension = json.tension;
  19478. return this;
  19479. };
  19480. /**
  19481. * @author zz85 / http://www.lab4games.net/zz85/blog
  19482. *
  19483. * Bezier Curves formulas obtained from
  19484. * http://en.wikipedia.org/wiki/Bézier_curve
  19485. */
  19486. function CatmullRom( t, p0, p1, p2, p3 ) {
  19487. var v0 = ( p2 - p0 ) * 0.5;
  19488. var v1 = ( p3 - p1 ) * 0.5;
  19489. var t2 = t * t;
  19490. var t3 = t * t2;
  19491. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  19492. }
  19493. //
  19494. function QuadraticBezierP0( t, p ) {
  19495. var k = 1 - t;
  19496. return k * k * p;
  19497. }
  19498. function QuadraticBezierP1( t, p ) {
  19499. return 2 * ( 1 - t ) * t * p;
  19500. }
  19501. function QuadraticBezierP2( t, p ) {
  19502. return t * t * p;
  19503. }
  19504. function QuadraticBezier( t, p0, p1, p2 ) {
  19505. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  19506. QuadraticBezierP2( t, p2 );
  19507. }
  19508. //
  19509. function CubicBezierP0( t, p ) {
  19510. var k = 1 - t;
  19511. return k * k * k * p;
  19512. }
  19513. function CubicBezierP1( t, p ) {
  19514. var k = 1 - t;
  19515. return 3 * k * k * t * p;
  19516. }
  19517. function CubicBezierP2( t, p ) {
  19518. return 3 * ( 1 - t ) * t * t * p;
  19519. }
  19520. function CubicBezierP3( t, p ) {
  19521. return t * t * t * p;
  19522. }
  19523. function CubicBezier( t, p0, p1, p2, p3 ) {
  19524. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  19525. CubicBezierP3( t, p3 );
  19526. }
  19527. function CubicBezierCurve( v0, v1, v2, v3 ) {
  19528. Curve.call( this );
  19529. this.type = 'CubicBezierCurve';
  19530. this.v0 = v0 || new Vector2();
  19531. this.v1 = v1 || new Vector2();
  19532. this.v2 = v2 || new Vector2();
  19533. this.v3 = v3 || new Vector2();
  19534. }
  19535. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  19536. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  19537. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  19538. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  19539. var point = optionalTarget || new Vector2();
  19540. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  19541. point.set(
  19542. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  19543. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  19544. );
  19545. return point;
  19546. };
  19547. CubicBezierCurve.prototype.copy = function ( source ) {
  19548. Curve.prototype.copy.call( this, source );
  19549. this.v0.copy( source.v0 );
  19550. this.v1.copy( source.v1 );
  19551. this.v2.copy( source.v2 );
  19552. this.v3.copy( source.v3 );
  19553. return this;
  19554. };
  19555. CubicBezierCurve.prototype.toJSON = function () {
  19556. var data = Curve.prototype.toJSON.call( this );
  19557. data.v0 = this.v0.toArray();
  19558. data.v1 = this.v1.toArray();
  19559. data.v2 = this.v2.toArray();
  19560. data.v3 = this.v3.toArray();
  19561. return data;
  19562. };
  19563. CubicBezierCurve.prototype.fromJSON = function ( json ) {
  19564. Curve.prototype.fromJSON.call( this, json );
  19565. this.v0.fromArray( json.v0 );
  19566. this.v1.fromArray( json.v1 );
  19567. this.v2.fromArray( json.v2 );
  19568. this.v3.fromArray( json.v3 );
  19569. return this;
  19570. };
  19571. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  19572. Curve.call( this );
  19573. this.type = 'CubicBezierCurve3';
  19574. this.v0 = v0 || new Vector3();
  19575. this.v1 = v1 || new Vector3();
  19576. this.v2 = v2 || new Vector3();
  19577. this.v3 = v3 || new Vector3();
  19578. }
  19579. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  19580. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  19581. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  19582. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  19583. var point = optionalTarget || new Vector3();
  19584. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  19585. point.set(
  19586. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  19587. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  19588. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  19589. );
  19590. return point;
  19591. };
  19592. CubicBezierCurve3.prototype.copy = function ( source ) {
  19593. Curve.prototype.copy.call( this, source );
  19594. this.v0.copy( source.v0 );
  19595. this.v1.copy( source.v1 );
  19596. this.v2.copy( source.v2 );
  19597. this.v3.copy( source.v3 );
  19598. return this;
  19599. };
  19600. CubicBezierCurve3.prototype.toJSON = function () {
  19601. var data = Curve.prototype.toJSON.call( this );
  19602. data.v0 = this.v0.toArray();
  19603. data.v1 = this.v1.toArray();
  19604. data.v2 = this.v2.toArray();
  19605. data.v3 = this.v3.toArray();
  19606. return data;
  19607. };
  19608. CubicBezierCurve3.prototype.fromJSON = function ( json ) {
  19609. Curve.prototype.fromJSON.call( this, json );
  19610. this.v0.fromArray( json.v0 );
  19611. this.v1.fromArray( json.v1 );
  19612. this.v2.fromArray( json.v2 );
  19613. this.v3.fromArray( json.v3 );
  19614. return this;
  19615. };
  19616. function LineCurve( v1, v2 ) {
  19617. Curve.call( this );
  19618. this.type = 'LineCurve';
  19619. this.v1 = v1 || new Vector2();
  19620. this.v2 = v2 || new Vector2();
  19621. }
  19622. LineCurve.prototype = Object.create( Curve.prototype );
  19623. LineCurve.prototype.constructor = LineCurve;
  19624. LineCurve.prototype.isLineCurve = true;
  19625. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  19626. var point = optionalTarget || new Vector2();
  19627. if ( t === 1 ) {
  19628. point.copy( this.v2 );
  19629. } else {
  19630. point.copy( this.v2 ).sub( this.v1 );
  19631. point.multiplyScalar( t ).add( this.v1 );
  19632. }
  19633. return point;
  19634. };
  19635. // Line curve is linear, so we can overwrite default getPointAt
  19636. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  19637. return this.getPoint( u, optionalTarget );
  19638. };
  19639. LineCurve.prototype.getTangent = function ( /* t */ ) {
  19640. var tangent = this.v2.clone().sub( this.v1 );
  19641. return tangent.normalize();
  19642. };
  19643. LineCurve.prototype.copy = function ( source ) {
  19644. Curve.prototype.copy.call( this, source );
  19645. this.v1.copy( source.v1 );
  19646. this.v2.copy( source.v2 );
  19647. return this;
  19648. };
  19649. LineCurve.prototype.toJSON = function () {
  19650. var data = Curve.prototype.toJSON.call( this );
  19651. data.v1 = this.v1.toArray();
  19652. data.v2 = this.v2.toArray();
  19653. return data;
  19654. };
  19655. LineCurve.prototype.fromJSON = function ( json ) {
  19656. Curve.prototype.fromJSON.call( this, json );
  19657. this.v1.fromArray( json.v1 );
  19658. this.v2.fromArray( json.v2 );
  19659. return this;
  19660. };
  19661. function LineCurve3( v1, v2 ) {
  19662. Curve.call( this );
  19663. this.type = 'LineCurve3';
  19664. this.v1 = v1 || new Vector3();
  19665. this.v2 = v2 || new Vector3();
  19666. }
  19667. LineCurve3.prototype = Object.create( Curve.prototype );
  19668. LineCurve3.prototype.constructor = LineCurve3;
  19669. LineCurve3.prototype.isLineCurve3 = true;
  19670. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  19671. var point = optionalTarget || new Vector3();
  19672. if ( t === 1 ) {
  19673. point.copy( this.v2 );
  19674. } else {
  19675. point.copy( this.v2 ).sub( this.v1 );
  19676. point.multiplyScalar( t ).add( this.v1 );
  19677. }
  19678. return point;
  19679. };
  19680. // Line curve is linear, so we can overwrite default getPointAt
  19681. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  19682. return this.getPoint( u, optionalTarget );
  19683. };
  19684. LineCurve3.prototype.copy = function ( source ) {
  19685. Curve.prototype.copy.call( this, source );
  19686. this.v1.copy( source.v1 );
  19687. this.v2.copy( source.v2 );
  19688. return this;
  19689. };
  19690. LineCurve3.prototype.toJSON = function () {
  19691. var data = Curve.prototype.toJSON.call( this );
  19692. data.v1 = this.v1.toArray();
  19693. data.v2 = this.v2.toArray();
  19694. return data;
  19695. };
  19696. LineCurve3.prototype.fromJSON = function ( json ) {
  19697. Curve.prototype.fromJSON.call( this, json );
  19698. this.v1.fromArray( json.v1 );
  19699. this.v2.fromArray( json.v2 );
  19700. return this;
  19701. };
  19702. function QuadraticBezierCurve( v0, v1, v2 ) {
  19703. Curve.call( this );
  19704. this.type = 'QuadraticBezierCurve';
  19705. this.v0 = v0 || new Vector2();
  19706. this.v1 = v1 || new Vector2();
  19707. this.v2 = v2 || new Vector2();
  19708. }
  19709. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  19710. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  19711. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  19712. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  19713. var point = optionalTarget || new Vector2();
  19714. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  19715. point.set(
  19716. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  19717. QuadraticBezier( t, v0.y, v1.y, v2.y )
  19718. );
  19719. return point;
  19720. };
  19721. QuadraticBezierCurve.prototype.copy = function ( source ) {
  19722. Curve.prototype.copy.call( this, source );
  19723. this.v0.copy( source.v0 );
  19724. this.v1.copy( source.v1 );
  19725. this.v2.copy( source.v2 );
  19726. return this;
  19727. };
  19728. QuadraticBezierCurve.prototype.toJSON = function () {
  19729. var data = Curve.prototype.toJSON.call( this );
  19730. data.v0 = this.v0.toArray();
  19731. data.v1 = this.v1.toArray();
  19732. data.v2 = this.v2.toArray();
  19733. return data;
  19734. };
  19735. QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
  19736. Curve.prototype.fromJSON.call( this, json );
  19737. this.v0.fromArray( json.v0 );
  19738. this.v1.fromArray( json.v1 );
  19739. this.v2.fromArray( json.v2 );
  19740. return this;
  19741. };
  19742. function QuadraticBezierCurve3( v0, v1, v2 ) {
  19743. Curve.call( this );
  19744. this.type = 'QuadraticBezierCurve3';
  19745. this.v0 = v0 || new Vector3();
  19746. this.v1 = v1 || new Vector3();
  19747. this.v2 = v2 || new Vector3();
  19748. }
  19749. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  19750. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  19751. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  19752. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  19753. var point = optionalTarget || new Vector3();
  19754. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  19755. point.set(
  19756. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  19757. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  19758. QuadraticBezier( t, v0.z, v1.z, v2.z )
  19759. );
  19760. return point;
  19761. };
  19762. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  19763. Curve.prototype.copy.call( this, source );
  19764. this.v0.copy( source.v0 );
  19765. this.v1.copy( source.v1 );
  19766. this.v2.copy( source.v2 );
  19767. return this;
  19768. };
  19769. QuadraticBezierCurve3.prototype.toJSON = function () {
  19770. var data = Curve.prototype.toJSON.call( this );
  19771. data.v0 = this.v0.toArray();
  19772. data.v1 = this.v1.toArray();
  19773. data.v2 = this.v2.toArray();
  19774. return data;
  19775. };
  19776. QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
  19777. Curve.prototype.fromJSON.call( this, json );
  19778. this.v0.fromArray( json.v0 );
  19779. this.v1.fromArray( json.v1 );
  19780. this.v2.fromArray( json.v2 );
  19781. return this;
  19782. };
  19783. function SplineCurve( points /* array of Vector2 */ ) {
  19784. Curve.call( this );
  19785. this.type = 'SplineCurve';
  19786. this.points = points || [];
  19787. }
  19788. SplineCurve.prototype = Object.create( Curve.prototype );
  19789. SplineCurve.prototype.constructor = SplineCurve;
  19790. SplineCurve.prototype.isSplineCurve = true;
  19791. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  19792. var point = optionalTarget || new Vector2();
  19793. var points = this.points;
  19794. var p = ( points.length - 1 ) * t;
  19795. var intPoint = Math.floor( p );
  19796. var weight = p - intPoint;
  19797. var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  19798. var p1 = points[ intPoint ];
  19799. var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  19800. var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  19801. point.set(
  19802. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  19803. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  19804. );
  19805. return point;
  19806. };
  19807. SplineCurve.prototype.copy = function ( source ) {
  19808. Curve.prototype.copy.call( this, source );
  19809. this.points = [];
  19810. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  19811. var point = source.points[ i ];
  19812. this.points.push( point.clone() );
  19813. }
  19814. return this;
  19815. };
  19816. SplineCurve.prototype.toJSON = function () {
  19817. var data = Curve.prototype.toJSON.call( this );
  19818. data.points = [];
  19819. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  19820. var point = this.points[ i ];
  19821. data.points.push( point.toArray() );
  19822. }
  19823. return data;
  19824. };
  19825. SplineCurve.prototype.fromJSON = function ( json ) {
  19826. Curve.prototype.fromJSON.call( this, json );
  19827. this.points = [];
  19828. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  19829. var point = json.points[ i ];
  19830. this.points.push( new Vector2().fromArray( point ) );
  19831. }
  19832. return this;
  19833. };
  19834. var Curves = Object.freeze({
  19835. ArcCurve: ArcCurve,
  19836. CatmullRomCurve3: CatmullRomCurve3,
  19837. CubicBezierCurve: CubicBezierCurve,
  19838. CubicBezierCurve3: CubicBezierCurve3,
  19839. EllipseCurve: EllipseCurve,
  19840. LineCurve: LineCurve,
  19841. LineCurve3: LineCurve3,
  19842. QuadraticBezierCurve: QuadraticBezierCurve,
  19843. QuadraticBezierCurve3: QuadraticBezierCurve3,
  19844. SplineCurve: SplineCurve
  19845. });
  19846. /**
  19847. * @author zz85 / http://www.lab4games.net/zz85/blog
  19848. *
  19849. **/
  19850. /**************************************************************
  19851. * Curved Path - a curve path is simply a array of connected
  19852. * curves, but retains the api of a curve
  19853. **************************************************************/
  19854. function CurvePath() {
  19855. Curve.call( this );
  19856. this.type = 'CurvePath';
  19857. this.curves = [];
  19858. this.autoClose = false; // Automatically closes the path
  19859. }
  19860. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  19861. constructor: CurvePath,
  19862. add: function ( curve ) {
  19863. this.curves.push( curve );
  19864. },
  19865. closePath: function () {
  19866. // Add a line curve if start and end of lines are not connected
  19867. var startPoint = this.curves[ 0 ].getPoint( 0 );
  19868. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  19869. if ( ! startPoint.equals( endPoint ) ) {
  19870. this.curves.push( new LineCurve( endPoint, startPoint ) );
  19871. }
  19872. },
  19873. // To get accurate point with reference to
  19874. // entire path distance at time t,
  19875. // following has to be done:
  19876. // 1. Length of each sub path have to be known
  19877. // 2. Locate and identify type of curve
  19878. // 3. Get t for the curve
  19879. // 4. Return curve.getPointAt(t')
  19880. getPoint: function ( t ) {
  19881. var d = t * this.getLength();
  19882. var curveLengths = this.getCurveLengths();
  19883. var i = 0;
  19884. // To think about boundaries points.
  19885. while ( i < curveLengths.length ) {
  19886. if ( curveLengths[ i ] >= d ) {
  19887. var diff = curveLengths[ i ] - d;
  19888. var curve = this.curves[ i ];
  19889. var segmentLength = curve.getLength();
  19890. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  19891. return curve.getPointAt( u );
  19892. }
  19893. i ++;
  19894. }
  19895. return null;
  19896. // loop where sum != 0, sum > d , sum+1 <d
  19897. },
  19898. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  19899. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  19900. // getPoint() depends on getLength
  19901. getLength: function () {
  19902. var lens = this.getCurveLengths();
  19903. return lens[ lens.length - 1 ];
  19904. },
  19905. // cacheLengths must be recalculated.
  19906. updateArcLengths: function () {
  19907. this.needsUpdate = true;
  19908. this.cacheLengths = null;
  19909. this.getCurveLengths();
  19910. },
  19911. // Compute lengths and cache them
  19912. // We cannot overwrite getLengths() because UtoT mapping uses it.
  19913. getCurveLengths: function () {
  19914. // We use cache values if curves and cache array are same length
  19915. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  19916. return this.cacheLengths;
  19917. }
  19918. // Get length of sub-curve
  19919. // Push sums into cached array
  19920. var lengths = [], sums = 0;
  19921. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  19922. sums += this.curves[ i ].getLength();
  19923. lengths.push( sums );
  19924. }
  19925. this.cacheLengths = lengths;
  19926. return lengths;
  19927. },
  19928. getSpacedPoints: function ( divisions ) {
  19929. if ( divisions === undefined ) divisions = 40;
  19930. var points = [];
  19931. for ( var i = 0; i <= divisions; i ++ ) {
  19932. points.push( this.getPoint( i / divisions ) );
  19933. }
  19934. if ( this.autoClose ) {
  19935. points.push( points[ 0 ] );
  19936. }
  19937. return points;
  19938. },
  19939. getPoints: function ( divisions ) {
  19940. divisions = divisions || 12;
  19941. var points = [], last;
  19942. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  19943. var curve = curves[ i ];
  19944. var resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  19945. : ( curve && curve.isLineCurve ) ? 1
  19946. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  19947. : divisions;
  19948. var pts = curve.getPoints( resolution );
  19949. for ( var j = 0; j < pts.length; j ++ ) {
  19950. var point = pts[ j ];
  19951. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  19952. points.push( point );
  19953. last = point;
  19954. }
  19955. }
  19956. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  19957. points.push( points[ 0 ] );
  19958. }
  19959. return points;
  19960. },
  19961. copy: function ( source ) {
  19962. Curve.prototype.copy.call( this, source );
  19963. this.curves = [];
  19964. for ( var i = 0, l = source.curves.length; i < l; i ++ ) {
  19965. var curve = source.curves[ i ];
  19966. this.curves.push( curve.clone() );
  19967. }
  19968. this.autoClose = source.autoClose;
  19969. return this;
  19970. },
  19971. toJSON: function () {
  19972. var data = Curve.prototype.toJSON.call( this );
  19973. data.autoClose = this.autoClose;
  19974. data.curves = [];
  19975. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  19976. var curve = this.curves[ i ];
  19977. data.curves.push( curve.toJSON() );
  19978. }
  19979. return data;
  19980. },
  19981. fromJSON: function ( json ) {
  19982. Curve.prototype.fromJSON.call( this, json );
  19983. this.autoClose = json.autoClose;
  19984. this.curves = [];
  19985. for ( var i = 0, l = json.curves.length; i < l; i ++ ) {
  19986. var curve = json.curves[ i ];
  19987. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  19988. }
  19989. return this;
  19990. }
  19991. } );
  19992. /**
  19993. * @author zz85 / http://www.lab4games.net/zz85/blog
  19994. * Creates free form 2d path using series of points, lines or curves.
  19995. **/
  19996. function Path( points ) {
  19997. CurvePath.call( this );
  19998. this.type = 'Path';
  19999. this.currentPoint = new Vector2();
  20000. if ( points ) {
  20001. this.setFromPoints( points );
  20002. }
  20003. }
  20004. Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
  20005. constructor: Path,
  20006. setFromPoints: function ( points ) {
  20007. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  20008. for ( var i = 1, l = points.length; i < l; i ++ ) {
  20009. this.lineTo( points[ i ].x, points[ i ].y );
  20010. }
  20011. },
  20012. moveTo: function ( x, y ) {
  20013. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  20014. },
  20015. lineTo: function ( x, y ) {
  20016. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  20017. this.curves.push( curve );
  20018. this.currentPoint.set( x, y );
  20019. },
  20020. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  20021. var curve = new QuadraticBezierCurve(
  20022. this.currentPoint.clone(),
  20023. new Vector2( aCPx, aCPy ),
  20024. new Vector2( aX, aY )
  20025. );
  20026. this.curves.push( curve );
  20027. this.currentPoint.set( aX, aY );
  20028. },
  20029. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  20030. var curve = new CubicBezierCurve(
  20031. this.currentPoint.clone(),
  20032. new Vector2( aCP1x, aCP1y ),
  20033. new Vector2( aCP2x, aCP2y ),
  20034. new Vector2( aX, aY )
  20035. );
  20036. this.curves.push( curve );
  20037. this.currentPoint.set( aX, aY );
  20038. },
  20039. splineThru: function ( pts /*Array of Vector*/ ) {
  20040. var npts = [ this.currentPoint.clone() ].concat( pts );
  20041. var curve = new SplineCurve( npts );
  20042. this.curves.push( curve );
  20043. this.currentPoint.copy( pts[ pts.length - 1 ] );
  20044. },
  20045. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20046. var x0 = this.currentPoint.x;
  20047. var y0 = this.currentPoint.y;
  20048. this.absarc( aX + x0, aY + y0, aRadius,
  20049. aStartAngle, aEndAngle, aClockwise );
  20050. },
  20051. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20052. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  20053. },
  20054. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20055. var x0 = this.currentPoint.x;
  20056. var y0 = this.currentPoint.y;
  20057. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20058. },
  20059. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20060. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20061. if ( this.curves.length > 0 ) {
  20062. // if a previous curve is present, attempt to join
  20063. var firstPoint = curve.getPoint( 0 );
  20064. if ( ! firstPoint.equals( this.currentPoint ) ) {
  20065. this.lineTo( firstPoint.x, firstPoint.y );
  20066. }
  20067. }
  20068. this.curves.push( curve );
  20069. var lastPoint = curve.getPoint( 1 );
  20070. this.currentPoint.copy( lastPoint );
  20071. },
  20072. copy: function ( source ) {
  20073. CurvePath.prototype.copy.call( this, source );
  20074. this.currentPoint.copy( source.currentPoint );
  20075. return this;
  20076. },
  20077. toJSON: function () {
  20078. var data = CurvePath.prototype.toJSON.call( this );
  20079. data.currentPoint = this.currentPoint.toArray();
  20080. return data;
  20081. },
  20082. fromJSON: function ( json ) {
  20083. CurvePath.prototype.fromJSON.call( this, json );
  20084. this.currentPoint.fromArray( json.currentPoint );
  20085. return this;
  20086. }
  20087. } );
  20088. /**
  20089. * @author zz85 / http://www.lab4games.net/zz85/blog
  20090. * Defines a 2d shape plane using paths.
  20091. **/
  20092. // STEP 1 Create a path.
  20093. // STEP 2 Turn path into shape.
  20094. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  20095. // STEP 3a - Extract points from each shape, turn to vertices
  20096. // STEP 3b - Triangulate each shape, add faces.
  20097. function Shape( points ) {
  20098. Path.call( this, points );
  20099. this.uuid = _Math.generateUUID();
  20100. this.type = 'Shape';
  20101. this.holes = [];
  20102. }
  20103. Shape.prototype = Object.assign( Object.create( Path.prototype ), {
  20104. constructor: Shape,
  20105. getPointsHoles: function ( divisions ) {
  20106. var holesPts = [];
  20107. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  20108. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  20109. }
  20110. return holesPts;
  20111. },
  20112. // get points of shape and holes (keypoints based on segments parameter)
  20113. extractPoints: function ( divisions ) {
  20114. return {
  20115. shape: this.getPoints( divisions ),
  20116. holes: this.getPointsHoles( divisions )
  20117. };
  20118. },
  20119. copy: function ( source ) {
  20120. Path.prototype.copy.call( this, source );
  20121. this.holes = [];
  20122. for ( var i = 0, l = source.holes.length; i < l; i ++ ) {
  20123. var hole = source.holes[ i ];
  20124. this.holes.push( hole.clone() );
  20125. }
  20126. return this;
  20127. },
  20128. toJSON: function () {
  20129. var data = Path.prototype.toJSON.call( this );
  20130. data.uuid = this.uuid;
  20131. data.holes = [];
  20132. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  20133. var hole = this.holes[ i ];
  20134. data.holes.push( hole.toJSON() );
  20135. }
  20136. return data;
  20137. },
  20138. fromJSON: function ( json ) {
  20139. Path.prototype.fromJSON.call( this, json );
  20140. this.uuid = json.uuid;
  20141. this.holes = [];
  20142. for ( var i = 0, l = json.holes.length; i < l; i ++ ) {
  20143. var hole = json.holes[ i ];
  20144. this.holes.push( new Path().fromJSON( hole ) );
  20145. }
  20146. return this;
  20147. }
  20148. } );
  20149. /**
  20150. * @author mrdoob / http://mrdoob.com/
  20151. * @author alteredq / http://alteredqualia.com/
  20152. */
  20153. function Light( color, intensity ) {
  20154. Object3D.call( this );
  20155. this.type = 'Light';
  20156. this.color = new Color( color );
  20157. this.intensity = intensity !== undefined ? intensity : 1;
  20158. this.receiveShadow = undefined;
  20159. }
  20160. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  20161. constructor: Light,
  20162. isLight: true,
  20163. copy: function ( source ) {
  20164. Object3D.prototype.copy.call( this, source );
  20165. this.color.copy( source.color );
  20166. this.intensity = source.intensity;
  20167. return this;
  20168. },
  20169. toJSON: function ( meta ) {
  20170. var data = Object3D.prototype.toJSON.call( this, meta );
  20171. data.object.color = this.color.getHex();
  20172. data.object.intensity = this.intensity;
  20173. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  20174. if ( this.distance !== undefined ) data.object.distance = this.distance;
  20175. if ( this.angle !== undefined ) data.object.angle = this.angle;
  20176. if ( this.decay !== undefined ) data.object.decay = this.decay;
  20177. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  20178. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  20179. return data;
  20180. }
  20181. } );
  20182. /**
  20183. * @author alteredq / http://alteredqualia.com/
  20184. */
  20185. function HemisphereLight( skyColor, groundColor, intensity ) {
  20186. Light.call( this, skyColor, intensity );
  20187. this.type = 'HemisphereLight';
  20188. this.castShadow = undefined;
  20189. this.position.copy( Object3D.DefaultUp );
  20190. this.updateMatrix();
  20191. this.groundColor = new Color( groundColor );
  20192. }
  20193. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  20194. constructor: HemisphereLight,
  20195. isHemisphereLight: true,
  20196. copy: function ( source ) {
  20197. Light.prototype.copy.call( this, source );
  20198. this.groundColor.copy( source.groundColor );
  20199. return this;
  20200. }
  20201. } );
  20202. /**
  20203. * @author mrdoob / http://mrdoob.com/
  20204. */
  20205. function LightShadow( camera ) {
  20206. this.camera = camera;
  20207. this.bias = 0;
  20208. this.radius = 1;
  20209. this.mapSize = new Vector2( 512, 512 );
  20210. this.map = null;
  20211. this.matrix = new Matrix4();
  20212. }
  20213. Object.assign( LightShadow.prototype, {
  20214. copy: function ( source ) {
  20215. this.camera = source.camera.clone();
  20216. this.bias = source.bias;
  20217. this.radius = source.radius;
  20218. this.mapSize.copy( source.mapSize );
  20219. return this;
  20220. },
  20221. clone: function () {
  20222. return new this.constructor().copy( this );
  20223. },
  20224. toJSON: function () {
  20225. var object = {};
  20226. if ( this.bias !== 0 ) object.bias = this.bias;
  20227. if ( this.radius !== 1 ) object.radius = this.radius;
  20228. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  20229. object.camera = this.camera.toJSON( false ).object;
  20230. delete object.camera.matrix;
  20231. return object;
  20232. }
  20233. } );
  20234. /**
  20235. * @author mrdoob / http://mrdoob.com/
  20236. */
  20237. function SpotLightShadow() {
  20238. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  20239. }
  20240. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  20241. constructor: SpotLightShadow,
  20242. isSpotLightShadow: true,
  20243. update: function ( light ) {
  20244. var camera = this.camera;
  20245. var fov = _Math.RAD2DEG * 2 * light.angle;
  20246. var aspect = this.mapSize.width / this.mapSize.height;
  20247. var far = light.distance || camera.far;
  20248. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  20249. camera.fov = fov;
  20250. camera.aspect = aspect;
  20251. camera.far = far;
  20252. camera.updateProjectionMatrix();
  20253. }
  20254. }
  20255. } );
  20256. /**
  20257. * @author alteredq / http://alteredqualia.com/
  20258. */
  20259. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  20260. Light.call( this, color, intensity );
  20261. this.type = 'SpotLight';
  20262. this.position.copy( Object3D.DefaultUp );
  20263. this.updateMatrix();
  20264. this.target = new Object3D();
  20265. Object.defineProperty( this, 'power', {
  20266. get: function () {
  20267. // intensity = power per solid angle.
  20268. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  20269. return this.intensity * Math.PI;
  20270. },
  20271. set: function ( power ) {
  20272. // intensity = power per solid angle.
  20273. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  20274. this.intensity = power / Math.PI;
  20275. }
  20276. } );
  20277. this.distance = ( distance !== undefined ) ? distance : 0;
  20278. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  20279. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  20280. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  20281. this.shadow = new SpotLightShadow();
  20282. }
  20283. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  20284. constructor: SpotLight,
  20285. isSpotLight: true,
  20286. copy: function ( source ) {
  20287. Light.prototype.copy.call( this, source );
  20288. this.distance = source.distance;
  20289. this.angle = source.angle;
  20290. this.penumbra = source.penumbra;
  20291. this.decay = source.decay;
  20292. this.target = source.target.clone();
  20293. this.shadow = source.shadow.clone();
  20294. return this;
  20295. }
  20296. } );
  20297. /**
  20298. * @author mrdoob / http://mrdoob.com/
  20299. */
  20300. function PointLight( color, intensity, distance, decay ) {
  20301. Light.call( this, color, intensity );
  20302. this.type = 'PointLight';
  20303. Object.defineProperty( this, 'power', {
  20304. get: function () {
  20305. // intensity = power per solid angle.
  20306. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  20307. return this.intensity * 4 * Math.PI;
  20308. },
  20309. set: function ( power ) {
  20310. // intensity = power per solid angle.
  20311. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  20312. this.intensity = power / ( 4 * Math.PI );
  20313. }
  20314. } );
  20315. this.distance = ( distance !== undefined ) ? distance : 0;
  20316. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  20317. this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  20318. }
  20319. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  20320. constructor: PointLight,
  20321. isPointLight: true,
  20322. copy: function ( source ) {
  20323. Light.prototype.copy.call( this, source );
  20324. this.distance = source.distance;
  20325. this.decay = source.decay;
  20326. this.shadow = source.shadow.clone();
  20327. return this;
  20328. }
  20329. } );
  20330. /**
  20331. * @author mrdoob / http://mrdoob.com/
  20332. */
  20333. function DirectionalLightShadow( ) {
  20334. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  20335. }
  20336. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  20337. constructor: DirectionalLightShadow
  20338. } );
  20339. /**
  20340. * @author mrdoob / http://mrdoob.com/
  20341. * @author alteredq / http://alteredqualia.com/
  20342. */
  20343. function DirectionalLight( color, intensity ) {
  20344. Light.call( this, color, intensity );
  20345. this.type = 'DirectionalLight';
  20346. this.position.copy( Object3D.DefaultUp );
  20347. this.updateMatrix();
  20348. this.target = new Object3D();
  20349. this.shadow = new DirectionalLightShadow();
  20350. }
  20351. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  20352. constructor: DirectionalLight,
  20353. isDirectionalLight: true,
  20354. copy: function ( source ) {
  20355. Light.prototype.copy.call( this, source );
  20356. this.target = source.target.clone();
  20357. this.shadow = source.shadow.clone();
  20358. return this;
  20359. }
  20360. } );
  20361. /**
  20362. * @author mrdoob / http://mrdoob.com/
  20363. */
  20364. function AmbientLight( color, intensity ) {
  20365. Light.call( this, color, intensity );
  20366. this.type = 'AmbientLight';
  20367. this.castShadow = undefined;
  20368. }
  20369. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  20370. constructor: AmbientLight,
  20371. isAmbientLight: true
  20372. } );
  20373. /**
  20374. * @author abelnation / http://github.com/abelnation
  20375. */
  20376. function RectAreaLight( color, intensity, width, height ) {
  20377. Light.call( this, color, intensity );
  20378. this.type = 'RectAreaLight';
  20379. this.width = ( width !== undefined ) ? width : 10;
  20380. this.height = ( height !== undefined ) ? height : 10;
  20381. }
  20382. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  20383. constructor: RectAreaLight,
  20384. isRectAreaLight: true,
  20385. copy: function ( source ) {
  20386. Light.prototype.copy.call( this, source );
  20387. this.width = source.width;
  20388. this.height = source.height;
  20389. return this;
  20390. },
  20391. toJSON: function ( meta ) {
  20392. var data = Light.prototype.toJSON.call( this, meta );
  20393. data.object.width = this.width;
  20394. data.object.height = this.height;
  20395. return data;
  20396. }
  20397. } );
  20398. /**
  20399. *
  20400. * A Track that interpolates Strings
  20401. *
  20402. *
  20403. * @author Ben Houston / http://clara.io/
  20404. * @author David Sarno / http://lighthaus.us/
  20405. * @author tschw
  20406. */
  20407. function StringKeyframeTrack( name, times, values, interpolation ) {
  20408. KeyframeTrack.call( this, name, times, values, interpolation );
  20409. }
  20410. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20411. constructor: StringKeyframeTrack,
  20412. ValueTypeName: 'string',
  20413. ValueBufferType: Array,
  20414. DefaultInterpolation: InterpolateDiscrete,
  20415. InterpolantFactoryMethodLinear: undefined,
  20416. InterpolantFactoryMethodSmooth: undefined
  20417. } );
  20418. /**
  20419. *
  20420. * A Track of Boolean keyframe values.
  20421. *
  20422. *
  20423. * @author Ben Houston / http://clara.io/
  20424. * @author David Sarno / http://lighthaus.us/
  20425. * @author tschw
  20426. */
  20427. function BooleanKeyframeTrack( name, times, values ) {
  20428. KeyframeTrack.call( this, name, times, values );
  20429. }
  20430. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20431. constructor: BooleanKeyframeTrack,
  20432. ValueTypeName: 'bool',
  20433. ValueBufferType: Array,
  20434. DefaultInterpolation: InterpolateDiscrete,
  20435. InterpolantFactoryMethodLinear: undefined,
  20436. InterpolantFactoryMethodSmooth: undefined
  20437. // Note: Actually this track could have a optimized / compressed
  20438. // representation of a single value and a custom interpolant that
  20439. // computes "firstValue ^ isOdd( index )".
  20440. } );
  20441. /**
  20442. * Abstract base class of interpolants over parametric samples.
  20443. *
  20444. * The parameter domain is one dimensional, typically the time or a path
  20445. * along a curve defined by the data.
  20446. *
  20447. * The sample values can have any dimensionality and derived classes may
  20448. * apply special interpretations to the data.
  20449. *
  20450. * This class provides the interval seek in a Template Method, deferring
  20451. * the actual interpolation to derived classes.
  20452. *
  20453. * Time complexity is O(1) for linear access crossing at most two points
  20454. * and O(log N) for random access, where N is the number of positions.
  20455. *
  20456. * References:
  20457. *
  20458. * http://www.oodesign.com/template-method-pattern.html
  20459. *
  20460. * @author tschw
  20461. */
  20462. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20463. this.parameterPositions = parameterPositions;
  20464. this._cachedIndex = 0;
  20465. this.resultBuffer = resultBuffer !== undefined ?
  20466. resultBuffer : new sampleValues.constructor( sampleSize );
  20467. this.sampleValues = sampleValues;
  20468. this.valueSize = sampleSize;
  20469. }
  20470. Object.assign( Interpolant.prototype, {
  20471. evaluate: function ( t ) {
  20472. var pp = this.parameterPositions,
  20473. i1 = this._cachedIndex,
  20474. t1 = pp[ i1 ],
  20475. t0 = pp[ i1 - 1 ];
  20476. validate_interval: {
  20477. seek: {
  20478. var right;
  20479. linear_scan: {
  20480. //- See http://jsperf.com/comparison-to-undefined/3
  20481. //- slower code:
  20482. //-
  20483. //- if ( t >= t1 || t1 === undefined ) {
  20484. forward_scan: if ( ! ( t < t1 ) ) {
  20485. for ( var giveUpAt = i1 + 2; ; ) {
  20486. if ( t1 === undefined ) {
  20487. if ( t < t0 ) break forward_scan;
  20488. // after end
  20489. i1 = pp.length;
  20490. this._cachedIndex = i1;
  20491. return this.afterEnd_( i1 - 1, t, t0 );
  20492. }
  20493. if ( i1 === giveUpAt ) break; // this loop
  20494. t0 = t1;
  20495. t1 = pp[ ++ i1 ];
  20496. if ( t < t1 ) {
  20497. // we have arrived at the sought interval
  20498. break seek;
  20499. }
  20500. }
  20501. // prepare binary search on the right side of the index
  20502. right = pp.length;
  20503. break linear_scan;
  20504. }
  20505. //- slower code:
  20506. //- if ( t < t0 || t0 === undefined ) {
  20507. if ( ! ( t >= t0 ) ) {
  20508. // looping?
  20509. var t1global = pp[ 1 ];
  20510. if ( t < t1global ) {
  20511. i1 = 2; // + 1, using the scan for the details
  20512. t0 = t1global;
  20513. }
  20514. // linear reverse scan
  20515. for ( var giveUpAt = i1 - 2; ; ) {
  20516. if ( t0 === undefined ) {
  20517. // before start
  20518. this._cachedIndex = 0;
  20519. return this.beforeStart_( 0, t, t1 );
  20520. }
  20521. if ( i1 === giveUpAt ) break; // this loop
  20522. t1 = t0;
  20523. t0 = pp[ -- i1 - 1 ];
  20524. if ( t >= t0 ) {
  20525. // we have arrived at the sought interval
  20526. break seek;
  20527. }
  20528. }
  20529. // prepare binary search on the left side of the index
  20530. right = i1;
  20531. i1 = 0;
  20532. break linear_scan;
  20533. }
  20534. // the interval is valid
  20535. break validate_interval;
  20536. } // linear scan
  20537. // binary search
  20538. while ( i1 < right ) {
  20539. var mid = ( i1 + right ) >>> 1;
  20540. if ( t < pp[ mid ] ) {
  20541. right = mid;
  20542. } else {
  20543. i1 = mid + 1;
  20544. }
  20545. }
  20546. t1 = pp[ i1 ];
  20547. t0 = pp[ i1 - 1 ];
  20548. // check boundary cases, again
  20549. if ( t0 === undefined ) {
  20550. this._cachedIndex = 0;
  20551. return this.beforeStart_( 0, t, t1 );
  20552. }
  20553. if ( t1 === undefined ) {
  20554. i1 = pp.length;
  20555. this._cachedIndex = i1;
  20556. return this.afterEnd_( i1 - 1, t0, t );
  20557. }
  20558. } // seek
  20559. this._cachedIndex = i1;
  20560. this.intervalChanged_( i1, t0, t1 );
  20561. } // validate_interval
  20562. return this.interpolate_( i1, t0, t, t1 );
  20563. },
  20564. settings: null, // optional, subclass-specific settings structure
  20565. // Note: The indirection allows central control of many interpolants.
  20566. // --- Protected interface
  20567. DefaultSettings_: {},
  20568. getSettings_: function () {
  20569. return this.settings || this.DefaultSettings_;
  20570. },
  20571. copySampleValue_: function ( index ) {
  20572. // copies a sample value to the result buffer
  20573. var result = this.resultBuffer,
  20574. values = this.sampleValues,
  20575. stride = this.valueSize,
  20576. offset = index * stride;
  20577. for ( var i = 0; i !== stride; ++ i ) {
  20578. result[ i ] = values[ offset + i ];
  20579. }
  20580. return result;
  20581. },
  20582. // Template methods for derived classes:
  20583. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  20584. throw new Error( 'call to abstract method' );
  20585. // implementations shall return this.resultBuffer
  20586. },
  20587. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  20588. // empty
  20589. }
  20590. } );
  20591. //!\ DECLARE ALIAS AFTER assign prototype !
  20592. Object.assign( Interpolant.prototype, {
  20593. //( 0, t, t0 ), returns this.resultBuffer
  20594. beforeStart_: Interpolant.prototype.copySampleValue_,
  20595. //( N-1, tN-1, t ), returns this.resultBuffer
  20596. afterEnd_: Interpolant.prototype.copySampleValue_,
  20597. } );
  20598. /**
  20599. * Spherical linear unit quaternion interpolant.
  20600. *
  20601. * @author tschw
  20602. */
  20603. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20604. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20605. }
  20606. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20607. constructor: QuaternionLinearInterpolant,
  20608. interpolate_: function ( i1, t0, t, t1 ) {
  20609. var result = this.resultBuffer,
  20610. values = this.sampleValues,
  20611. stride = this.valueSize,
  20612. offset = i1 * stride,
  20613. alpha = ( t - t0 ) / ( t1 - t0 );
  20614. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  20615. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  20616. }
  20617. return result;
  20618. }
  20619. } );
  20620. /**
  20621. *
  20622. * A Track of quaternion keyframe values.
  20623. *
  20624. * @author Ben Houston / http://clara.io/
  20625. * @author David Sarno / http://lighthaus.us/
  20626. * @author tschw
  20627. */
  20628. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  20629. KeyframeTrack.call( this, name, times, values, interpolation );
  20630. }
  20631. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20632. constructor: QuaternionKeyframeTrack,
  20633. ValueTypeName: 'quaternion',
  20634. // ValueBufferType is inherited
  20635. DefaultInterpolation: InterpolateLinear,
  20636. InterpolantFactoryMethodLinear: function ( result ) {
  20637. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20638. },
  20639. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  20640. } );
  20641. /**
  20642. *
  20643. * A Track of keyframe values that represent color.
  20644. *
  20645. *
  20646. * @author Ben Houston / http://clara.io/
  20647. * @author David Sarno / http://lighthaus.us/
  20648. * @author tschw
  20649. */
  20650. function ColorKeyframeTrack( name, times, values, interpolation ) {
  20651. KeyframeTrack.call( this, name, times, values, interpolation );
  20652. }
  20653. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20654. constructor: ColorKeyframeTrack,
  20655. ValueTypeName: 'color'
  20656. // ValueBufferType is inherited
  20657. // DefaultInterpolation is inherited
  20658. // Note: Very basic implementation and nothing special yet.
  20659. // However, this is the place for color space parameterization.
  20660. } );
  20661. /**
  20662. *
  20663. * A Track of numeric keyframe values.
  20664. *
  20665. * @author Ben Houston / http://clara.io/
  20666. * @author David Sarno / http://lighthaus.us/
  20667. * @author tschw
  20668. */
  20669. function NumberKeyframeTrack( name, times, values, interpolation ) {
  20670. KeyframeTrack.call( this, name, times, values, interpolation );
  20671. }
  20672. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20673. constructor: NumberKeyframeTrack,
  20674. ValueTypeName: 'number'
  20675. // ValueBufferType is inherited
  20676. // DefaultInterpolation is inherited
  20677. } );
  20678. /**
  20679. * Fast and simple cubic spline interpolant.
  20680. *
  20681. * It was derived from a Hermitian construction setting the first derivative
  20682. * at each sample position to the linear slope between neighboring positions
  20683. * over their parameter interval.
  20684. *
  20685. * @author tschw
  20686. */
  20687. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20688. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20689. this._weightPrev = - 0;
  20690. this._offsetPrev = - 0;
  20691. this._weightNext = - 0;
  20692. this._offsetNext = - 0;
  20693. }
  20694. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20695. constructor: CubicInterpolant,
  20696. DefaultSettings_: {
  20697. endingStart: ZeroCurvatureEnding,
  20698. endingEnd: ZeroCurvatureEnding
  20699. },
  20700. intervalChanged_: function ( i1, t0, t1 ) {
  20701. var pp = this.parameterPositions,
  20702. iPrev = i1 - 2,
  20703. iNext = i1 + 1,
  20704. tPrev = pp[ iPrev ],
  20705. tNext = pp[ iNext ];
  20706. if ( tPrev === undefined ) {
  20707. switch ( this.getSettings_().endingStart ) {
  20708. case ZeroSlopeEnding:
  20709. // f'(t0) = 0
  20710. iPrev = i1;
  20711. tPrev = 2 * t0 - t1;
  20712. break;
  20713. case WrapAroundEnding:
  20714. // use the other end of the curve
  20715. iPrev = pp.length - 2;
  20716. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  20717. break;
  20718. default: // ZeroCurvatureEnding
  20719. // f''(t0) = 0 a.k.a. Natural Spline
  20720. iPrev = i1;
  20721. tPrev = t1;
  20722. }
  20723. }
  20724. if ( tNext === undefined ) {
  20725. switch ( this.getSettings_().endingEnd ) {
  20726. case ZeroSlopeEnding:
  20727. // f'(tN) = 0
  20728. iNext = i1;
  20729. tNext = 2 * t1 - t0;
  20730. break;
  20731. case WrapAroundEnding:
  20732. // use the other end of the curve
  20733. iNext = 1;
  20734. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  20735. break;
  20736. default: // ZeroCurvatureEnding
  20737. // f''(tN) = 0, a.k.a. Natural Spline
  20738. iNext = i1 - 1;
  20739. tNext = t0;
  20740. }
  20741. }
  20742. var halfDt = ( t1 - t0 ) * 0.5,
  20743. stride = this.valueSize;
  20744. this._weightPrev = halfDt / ( t0 - tPrev );
  20745. this._weightNext = halfDt / ( tNext - t1 );
  20746. this._offsetPrev = iPrev * stride;
  20747. this._offsetNext = iNext * stride;
  20748. },
  20749. interpolate_: function ( i1, t0, t, t1 ) {
  20750. var result = this.resultBuffer,
  20751. values = this.sampleValues,
  20752. stride = this.valueSize,
  20753. o1 = i1 * stride, o0 = o1 - stride,
  20754. oP = this._offsetPrev, oN = this._offsetNext,
  20755. wP = this._weightPrev, wN = this._weightNext,
  20756. p = ( t - t0 ) / ( t1 - t0 ),
  20757. pp = p * p,
  20758. ppp = pp * p;
  20759. // evaluate polynomials
  20760. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  20761. var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  20762. var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  20763. var sN = wN * ppp - wN * pp;
  20764. // combine data linearly
  20765. for ( var i = 0; i !== stride; ++ i ) {
  20766. result[ i ] =
  20767. sP * values[ oP + i ] +
  20768. s0 * values[ o0 + i ] +
  20769. s1 * values[ o1 + i ] +
  20770. sN * values[ oN + i ];
  20771. }
  20772. return result;
  20773. }
  20774. } );
  20775. /**
  20776. * @author tschw
  20777. */
  20778. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20779. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20780. }
  20781. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20782. constructor: LinearInterpolant,
  20783. interpolate_: function ( i1, t0, t, t1 ) {
  20784. var result = this.resultBuffer,
  20785. values = this.sampleValues,
  20786. stride = this.valueSize,
  20787. offset1 = i1 * stride,
  20788. offset0 = offset1 - stride,
  20789. weight1 = ( t - t0 ) / ( t1 - t0 ),
  20790. weight0 = 1 - weight1;
  20791. for ( var i = 0; i !== stride; ++ i ) {
  20792. result[ i ] =
  20793. values[ offset0 + i ] * weight0 +
  20794. values[ offset1 + i ] * weight1;
  20795. }
  20796. return result;
  20797. }
  20798. } );
  20799. /**
  20800. *
  20801. * Interpolant that evaluates to the sample value at the position preceeding
  20802. * the parameter.
  20803. *
  20804. * @author tschw
  20805. */
  20806. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20807. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20808. }
  20809. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20810. constructor: DiscreteInterpolant,
  20811. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  20812. return this.copySampleValue_( i1 - 1 );
  20813. }
  20814. } );
  20815. /**
  20816. * @author tschw
  20817. * @author Ben Houston / http://clara.io/
  20818. * @author David Sarno / http://lighthaus.us/
  20819. */
  20820. var AnimationUtils = {
  20821. // same as Array.prototype.slice, but also works on typed arrays
  20822. arraySlice: function ( array, from, to ) {
  20823. if ( AnimationUtils.isTypedArray( array ) ) {
  20824. // in ios9 array.subarray(from, undefined) will return empty array
  20825. // but array.subarray(from) or array.subarray(from, len) is correct
  20826. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  20827. }
  20828. return array.slice( from, to );
  20829. },
  20830. // converts an array to a specific type
  20831. convertArray: function ( array, type, forceClone ) {
  20832. if ( ! array || // let 'undefined' and 'null' pass
  20833. ! forceClone && array.constructor === type ) return array;
  20834. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  20835. return new type( array ); // create typed array
  20836. }
  20837. return Array.prototype.slice.call( array ); // create Array
  20838. },
  20839. isTypedArray: function ( object ) {
  20840. return ArrayBuffer.isView( object ) &&
  20841. ! ( object instanceof DataView );
  20842. },
  20843. // returns an array by which times and values can be sorted
  20844. getKeyframeOrder: function ( times ) {
  20845. function compareTime( i, j ) {
  20846. return times[ i ] - times[ j ];
  20847. }
  20848. var n = times.length;
  20849. var result = new Array( n );
  20850. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  20851. result.sort( compareTime );
  20852. return result;
  20853. },
  20854. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20855. sortedArray: function ( values, stride, order ) {
  20856. var nValues = values.length;
  20857. var result = new values.constructor( nValues );
  20858. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  20859. var srcOffset = order[ i ] * stride;
  20860. for ( var j = 0; j !== stride; ++ j ) {
  20861. result[ dstOffset ++ ] = values[ srcOffset + j ];
  20862. }
  20863. }
  20864. return result;
  20865. },
  20866. // function for parsing AOS keyframe formats
  20867. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  20868. var i = 1, key = jsonKeys[ 0 ];
  20869. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  20870. key = jsonKeys[ i ++ ];
  20871. }
  20872. if ( key === undefined ) return; // no data
  20873. var value = key[ valuePropertyName ];
  20874. if ( value === undefined ) return; // no data
  20875. if ( Array.isArray( value ) ) {
  20876. do {
  20877. value = key[ valuePropertyName ];
  20878. if ( value !== undefined ) {
  20879. times.push( key.time );
  20880. values.push.apply( values, value ); // push all elements
  20881. }
  20882. key = jsonKeys[ i ++ ];
  20883. } while ( key !== undefined );
  20884. } else if ( value.toArray !== undefined ) {
  20885. // ...assume THREE.Math-ish
  20886. do {
  20887. value = key[ valuePropertyName ];
  20888. if ( value !== undefined ) {
  20889. times.push( key.time );
  20890. value.toArray( values, values.length );
  20891. }
  20892. key = jsonKeys[ i ++ ];
  20893. } while ( key !== undefined );
  20894. } else {
  20895. // otherwise push as-is
  20896. do {
  20897. value = key[ valuePropertyName ];
  20898. if ( value !== undefined ) {
  20899. times.push( key.time );
  20900. values.push( value );
  20901. }
  20902. key = jsonKeys[ i ++ ];
  20903. } while ( key !== undefined );
  20904. }
  20905. }
  20906. };
  20907. /**
  20908. *
  20909. * A timed sequence of keyframes for a specific property.
  20910. *
  20911. *
  20912. * @author Ben Houston / http://clara.io/
  20913. * @author David Sarno / http://lighthaus.us/
  20914. * @author tschw
  20915. */
  20916. function KeyframeTrack( name, times, values, interpolation ) {
  20917. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  20918. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  20919. this.name = name;
  20920. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  20921. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  20922. this.setInterpolation( interpolation || this.DefaultInterpolation );
  20923. this.validate();
  20924. this.optimize();
  20925. }
  20926. // Static methods:
  20927. Object.assign( KeyframeTrack, {
  20928. // Serialization (in static context, because of constructor invocation
  20929. // and automatic invocation of .toJSON):
  20930. parse: function ( json ) {
  20931. if ( json.type === undefined ) {
  20932. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  20933. }
  20934. var trackType = KeyframeTrack._getTrackTypeForValueTypeName( json.type );
  20935. if ( json.times === undefined ) {
  20936. var times = [], values = [];
  20937. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  20938. json.times = times;
  20939. json.values = values;
  20940. }
  20941. // derived classes can define a static parse method
  20942. if ( trackType.parse !== undefined ) {
  20943. return trackType.parse( json );
  20944. } else {
  20945. // by default, we assume a constructor compatible with the base
  20946. return new trackType( json.name, json.times, json.values, json.interpolation );
  20947. }
  20948. },
  20949. toJSON: function ( track ) {
  20950. var trackType = track.constructor;
  20951. var json;
  20952. // derived classes can define a static toJSON method
  20953. if ( trackType.toJSON !== undefined ) {
  20954. json = trackType.toJSON( track );
  20955. } else {
  20956. // by default, we assume the data can be serialized as-is
  20957. json = {
  20958. 'name': track.name,
  20959. 'times': AnimationUtils.convertArray( track.times, Array ),
  20960. 'values': AnimationUtils.convertArray( track.values, Array )
  20961. };
  20962. var interpolation = track.getInterpolation();
  20963. if ( interpolation !== track.DefaultInterpolation ) {
  20964. json.interpolation = interpolation;
  20965. }
  20966. }
  20967. json.type = track.ValueTypeName; // mandatory
  20968. return json;
  20969. },
  20970. _getTrackTypeForValueTypeName: function ( typeName ) {
  20971. switch ( typeName.toLowerCase() ) {
  20972. case 'scalar':
  20973. case 'double':
  20974. case 'float':
  20975. case 'number':
  20976. case 'integer':
  20977. return NumberKeyframeTrack;
  20978. case 'vector':
  20979. case 'vector2':
  20980. case 'vector3':
  20981. case 'vector4':
  20982. return VectorKeyframeTrack;
  20983. case 'color':
  20984. return ColorKeyframeTrack;
  20985. case 'quaternion':
  20986. return QuaternionKeyframeTrack;
  20987. case 'bool':
  20988. case 'boolean':
  20989. return BooleanKeyframeTrack;
  20990. case 'string':
  20991. return StringKeyframeTrack;
  20992. }
  20993. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  20994. }
  20995. } );
  20996. Object.assign( KeyframeTrack.prototype, {
  20997. constructor: KeyframeTrack,
  20998. TimeBufferType: Float32Array,
  20999. ValueBufferType: Float32Array,
  21000. DefaultInterpolation: InterpolateLinear,
  21001. InterpolantFactoryMethodDiscrete: function ( result ) {
  21002. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  21003. },
  21004. InterpolantFactoryMethodLinear: function ( result ) {
  21005. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  21006. },
  21007. InterpolantFactoryMethodSmooth: function ( result ) {
  21008. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  21009. },
  21010. setInterpolation: function ( interpolation ) {
  21011. var factoryMethod;
  21012. switch ( interpolation ) {
  21013. case InterpolateDiscrete:
  21014. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  21015. break;
  21016. case InterpolateLinear:
  21017. factoryMethod = this.InterpolantFactoryMethodLinear;
  21018. break;
  21019. case InterpolateSmooth:
  21020. factoryMethod = this.InterpolantFactoryMethodSmooth;
  21021. break;
  21022. }
  21023. if ( factoryMethod === undefined ) {
  21024. var message = "unsupported interpolation for " +
  21025. this.ValueTypeName + " keyframe track named " + this.name;
  21026. if ( this.createInterpolant === undefined ) {
  21027. // fall back to default, unless the default itself is messed up
  21028. if ( interpolation !== this.DefaultInterpolation ) {
  21029. this.setInterpolation( this.DefaultInterpolation );
  21030. } else {
  21031. throw new Error( message ); // fatal, in this case
  21032. }
  21033. }
  21034. console.warn( 'THREE.KeyframeTrack:', message );
  21035. return;
  21036. }
  21037. this.createInterpolant = factoryMethod;
  21038. },
  21039. getInterpolation: function () {
  21040. switch ( this.createInterpolant ) {
  21041. case this.InterpolantFactoryMethodDiscrete:
  21042. return InterpolateDiscrete;
  21043. case this.InterpolantFactoryMethodLinear:
  21044. return InterpolateLinear;
  21045. case this.InterpolantFactoryMethodSmooth:
  21046. return InterpolateSmooth;
  21047. }
  21048. },
  21049. getValueSize: function () {
  21050. return this.values.length / this.times.length;
  21051. },
  21052. // move all keyframes either forwards or backwards in time
  21053. shift: function ( timeOffset ) {
  21054. if ( timeOffset !== 0.0 ) {
  21055. var times = this.times;
  21056. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  21057. times[ i ] += timeOffset;
  21058. }
  21059. }
  21060. return this;
  21061. },
  21062. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  21063. scale: function ( timeScale ) {
  21064. if ( timeScale !== 1.0 ) {
  21065. var times = this.times;
  21066. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  21067. times[ i ] *= timeScale;
  21068. }
  21069. }
  21070. return this;
  21071. },
  21072. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  21073. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  21074. trim: function ( startTime, endTime ) {
  21075. var times = this.times,
  21076. nKeys = times.length,
  21077. from = 0,
  21078. to = nKeys - 1;
  21079. while ( from !== nKeys && times[ from ] < startTime ) {
  21080. ++ from;
  21081. }
  21082. while ( to !== - 1 && times[ to ] > endTime ) {
  21083. -- to;
  21084. }
  21085. ++ to; // inclusive -> exclusive bound
  21086. if ( from !== 0 || to !== nKeys ) {
  21087. // empty tracks are forbidden, so keep at least one keyframe
  21088. if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
  21089. var stride = this.getValueSize();
  21090. this.times = AnimationUtils.arraySlice( times, from, to );
  21091. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  21092. }
  21093. return this;
  21094. },
  21095. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  21096. validate: function () {
  21097. var valid = true;
  21098. var valueSize = this.getValueSize();
  21099. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  21100. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  21101. valid = false;
  21102. }
  21103. var times = this.times,
  21104. values = this.values,
  21105. nKeys = times.length;
  21106. if ( nKeys === 0 ) {
  21107. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  21108. valid = false;
  21109. }
  21110. var prevTime = null;
  21111. for ( var i = 0; i !== nKeys; i ++ ) {
  21112. var currTime = times[ i ];
  21113. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  21114. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  21115. valid = false;
  21116. break;
  21117. }
  21118. if ( prevTime !== null && prevTime > currTime ) {
  21119. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  21120. valid = false;
  21121. break;
  21122. }
  21123. prevTime = currTime;
  21124. }
  21125. if ( values !== undefined ) {
  21126. if ( AnimationUtils.isTypedArray( values ) ) {
  21127. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  21128. var value = values[ i ];
  21129. if ( isNaN( value ) ) {
  21130. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  21131. valid = false;
  21132. break;
  21133. }
  21134. }
  21135. }
  21136. }
  21137. return valid;
  21138. },
  21139. // removes equivalent sequential keys as common in morph target sequences
  21140. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  21141. optimize: function () {
  21142. var times = this.times,
  21143. values = this.values,
  21144. stride = this.getValueSize(),
  21145. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  21146. writeIndex = 1,
  21147. lastIndex = times.length - 1;
  21148. for ( var i = 1; i < lastIndex; ++ i ) {
  21149. var keep = false;
  21150. var time = times[ i ];
  21151. var timeNext = times[ i + 1 ];
  21152. // remove adjacent keyframes scheduled at the same time
  21153. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  21154. if ( ! smoothInterpolation ) {
  21155. // remove unnecessary keyframes same as their neighbors
  21156. var offset = i * stride,
  21157. offsetP = offset - stride,
  21158. offsetN = offset + stride;
  21159. for ( var j = 0; j !== stride; ++ j ) {
  21160. var value = values[ offset + j ];
  21161. if ( value !== values[ offsetP + j ] ||
  21162. value !== values[ offsetN + j ] ) {
  21163. keep = true;
  21164. break;
  21165. }
  21166. }
  21167. } else {
  21168. keep = true;
  21169. }
  21170. }
  21171. // in-place compaction
  21172. if ( keep ) {
  21173. if ( i !== writeIndex ) {
  21174. times[ writeIndex ] = times[ i ];
  21175. var readOffset = i * stride,
  21176. writeOffset = writeIndex * stride;
  21177. for ( var j = 0; j !== stride; ++ j ) {
  21178. values[ writeOffset + j ] = values[ readOffset + j ];
  21179. }
  21180. }
  21181. ++ writeIndex;
  21182. }
  21183. }
  21184. // flush last keyframe (compaction looks ahead)
  21185. if ( lastIndex > 0 ) {
  21186. times[ writeIndex ] = times[ lastIndex ];
  21187. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  21188. values[ writeOffset + j ] = values[ readOffset + j ];
  21189. }
  21190. ++ writeIndex;
  21191. }
  21192. if ( writeIndex !== times.length ) {
  21193. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  21194. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  21195. }
  21196. return this;
  21197. }
  21198. } );
  21199. /**
  21200. *
  21201. * A Track of vectored keyframe values.
  21202. *
  21203. *
  21204. * @author Ben Houston / http://clara.io/
  21205. * @author David Sarno / http://lighthaus.us/
  21206. * @author tschw
  21207. */
  21208. function VectorKeyframeTrack( name, times, values, interpolation ) {
  21209. KeyframeTrack.call( this, name, times, values, interpolation );
  21210. }
  21211. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21212. constructor: VectorKeyframeTrack,
  21213. ValueTypeName: 'vector'
  21214. // ValueBufferType is inherited
  21215. // DefaultInterpolation is inherited
  21216. } );
  21217. /**
  21218. *
  21219. * Reusable set of Tracks that represent an animation.
  21220. *
  21221. * @author Ben Houston / http://clara.io/
  21222. * @author David Sarno / http://lighthaus.us/
  21223. */
  21224. function AnimationClip( name, duration, tracks ) {
  21225. this.name = name;
  21226. this.tracks = tracks;
  21227. this.duration = ( duration !== undefined ) ? duration : - 1;
  21228. this.uuid = _Math.generateUUID();
  21229. // this means it should figure out its duration by scanning the tracks
  21230. if ( this.duration < 0 ) {
  21231. this.resetDuration();
  21232. }
  21233. this.optimize();
  21234. }
  21235. Object.assign( AnimationClip, {
  21236. parse: function ( json ) {
  21237. var tracks = [],
  21238. jsonTracks = json.tracks,
  21239. frameTime = 1.0 / ( json.fps || 1.0 );
  21240. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  21241. tracks.push( KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
  21242. }
  21243. return new AnimationClip( json.name, json.duration, tracks );
  21244. },
  21245. toJSON: function ( clip ) {
  21246. var tracks = [],
  21247. clipTracks = clip.tracks;
  21248. var json = {
  21249. 'name': clip.name,
  21250. 'duration': clip.duration,
  21251. 'tracks': tracks,
  21252. 'uuid': clip.uuid
  21253. };
  21254. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  21255. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  21256. }
  21257. return json;
  21258. },
  21259. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  21260. var numMorphTargets = morphTargetSequence.length;
  21261. var tracks = [];
  21262. for ( var i = 0; i < numMorphTargets; i ++ ) {
  21263. var times = [];
  21264. var values = [];
  21265. times.push(
  21266. ( i + numMorphTargets - 1 ) % numMorphTargets,
  21267. i,
  21268. ( i + 1 ) % numMorphTargets );
  21269. values.push( 0, 1, 0 );
  21270. var order = AnimationUtils.getKeyframeOrder( times );
  21271. times = AnimationUtils.sortedArray( times, 1, order );
  21272. values = AnimationUtils.sortedArray( values, 1, order );
  21273. // if there is a key at the first frame, duplicate it as the
  21274. // last frame as well for perfect loop.
  21275. if ( ! noLoop && times[ 0 ] === 0 ) {
  21276. times.push( numMorphTargets );
  21277. values.push( values[ 0 ] );
  21278. }
  21279. tracks.push(
  21280. new NumberKeyframeTrack(
  21281. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  21282. times, values
  21283. ).scale( 1.0 / fps ) );
  21284. }
  21285. return new AnimationClip( name, - 1, tracks );
  21286. },
  21287. findByName: function ( objectOrClipArray, name ) {
  21288. var clipArray = objectOrClipArray;
  21289. if ( ! Array.isArray( objectOrClipArray ) ) {
  21290. var o = objectOrClipArray;
  21291. clipArray = o.geometry && o.geometry.animations || o.animations;
  21292. }
  21293. for ( var i = 0; i < clipArray.length; i ++ ) {
  21294. if ( clipArray[ i ].name === name ) {
  21295. return clipArray[ i ];
  21296. }
  21297. }
  21298. return null;
  21299. },
  21300. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  21301. var animationToMorphTargets = {};
  21302. // tested with https://regex101.com/ on trick sequences
  21303. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21304. var pattern = /^([\w-]*?)([\d]+)$/;
  21305. // sort morph target names into animation groups based
  21306. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21307. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  21308. var morphTarget = morphTargets[ i ];
  21309. var parts = morphTarget.name.match( pattern );
  21310. if ( parts && parts.length > 1 ) {
  21311. var name = parts[ 1 ];
  21312. var animationMorphTargets = animationToMorphTargets[ name ];
  21313. if ( ! animationMorphTargets ) {
  21314. animationToMorphTargets[ name ] = animationMorphTargets = [];
  21315. }
  21316. animationMorphTargets.push( morphTarget );
  21317. }
  21318. }
  21319. var clips = [];
  21320. for ( var name in animationToMorphTargets ) {
  21321. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  21322. }
  21323. return clips;
  21324. },
  21325. // parse the animation.hierarchy format
  21326. parseAnimation: function ( animation, bones ) {
  21327. if ( ! animation ) {
  21328. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  21329. return null;
  21330. }
  21331. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  21332. // only return track if there are actually keys.
  21333. if ( animationKeys.length !== 0 ) {
  21334. var times = [];
  21335. var values = [];
  21336. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  21337. // empty keys are filtered out, so check again
  21338. if ( times.length !== 0 ) {
  21339. destTracks.push( new trackType( trackName, times, values ) );
  21340. }
  21341. }
  21342. };
  21343. var tracks = [];
  21344. var clipName = animation.name || 'default';
  21345. // automatic length determination in AnimationClip.
  21346. var duration = animation.length || - 1;
  21347. var fps = animation.fps || 30;
  21348. var hierarchyTracks = animation.hierarchy || [];
  21349. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  21350. var animationKeys = hierarchyTracks[ h ].keys;
  21351. // skip empty tracks
  21352. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  21353. // process morph targets
  21354. if ( animationKeys[ 0 ].morphTargets ) {
  21355. // figure out all morph targets used in this track
  21356. var morphTargetNames = {};
  21357. for ( var k = 0; k < animationKeys.length; k ++ ) {
  21358. if ( animationKeys[ k ].morphTargets ) {
  21359. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  21360. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  21361. }
  21362. }
  21363. }
  21364. // create a track for each morph target with all zero
  21365. // morphTargetInfluences except for the keys in which
  21366. // the morphTarget is named.
  21367. for ( var morphTargetName in morphTargetNames ) {
  21368. var times = [];
  21369. var values = [];
  21370. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  21371. var animationKey = animationKeys[ k ];
  21372. times.push( animationKey.time );
  21373. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  21374. }
  21375. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  21376. }
  21377. duration = morphTargetNames.length * ( fps || 1.0 );
  21378. } else {
  21379. // ...assume skeletal animation
  21380. var boneName = '.bones[' + bones[ h ].name + ']';
  21381. addNonemptyTrack(
  21382. VectorKeyframeTrack, boneName + '.position',
  21383. animationKeys, 'pos', tracks );
  21384. addNonemptyTrack(
  21385. QuaternionKeyframeTrack, boneName + '.quaternion',
  21386. animationKeys, 'rot', tracks );
  21387. addNonemptyTrack(
  21388. VectorKeyframeTrack, boneName + '.scale',
  21389. animationKeys, 'scl', tracks );
  21390. }
  21391. }
  21392. if ( tracks.length === 0 ) {
  21393. return null;
  21394. }
  21395. var clip = new AnimationClip( clipName, duration, tracks );
  21396. return clip;
  21397. }
  21398. } );
  21399. Object.assign( AnimationClip.prototype, {
  21400. resetDuration: function () {
  21401. var tracks = this.tracks, duration = 0;
  21402. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  21403. var track = this.tracks[ i ];
  21404. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  21405. }
  21406. this.duration = duration;
  21407. },
  21408. trim: function () {
  21409. for ( var i = 0; i < this.tracks.length; i ++ ) {
  21410. this.tracks[ i ].trim( 0, this.duration );
  21411. }
  21412. return this;
  21413. },
  21414. optimize: function () {
  21415. for ( var i = 0; i < this.tracks.length; i ++ ) {
  21416. this.tracks[ i ].optimize();
  21417. }
  21418. return this;
  21419. }
  21420. } );
  21421. /**
  21422. * @author mrdoob / http://mrdoob.com/
  21423. */
  21424. function MaterialLoader( manager ) {
  21425. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21426. this.textures = {};
  21427. }
  21428. Object.assign( MaterialLoader.prototype, {
  21429. load: function ( url, onLoad, onProgress, onError ) {
  21430. var scope = this;
  21431. var loader = new FileLoader( scope.manager );
  21432. loader.load( url, function ( text ) {
  21433. onLoad( scope.parse( JSON.parse( text ) ) );
  21434. }, onProgress, onError );
  21435. },
  21436. setTextures: function ( value ) {
  21437. this.textures = value;
  21438. },
  21439. parse: function ( json ) {
  21440. var textures = this.textures;
  21441. function getTexture( name ) {
  21442. if ( textures[ name ] === undefined ) {
  21443. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  21444. }
  21445. return textures[ name ];
  21446. }
  21447. var material = new Materials[ json.type ]();
  21448. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  21449. if ( json.name !== undefined ) material.name = json.name;
  21450. if ( json.color !== undefined ) material.color.setHex( json.color );
  21451. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  21452. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  21453. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  21454. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  21455. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  21456. if ( json.clearCoat !== undefined ) material.clearCoat = json.clearCoat;
  21457. if ( json.clearCoatRoughness !== undefined ) material.clearCoatRoughness = json.clearCoatRoughness;
  21458. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  21459. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  21460. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  21461. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  21462. if ( json.fog !== undefined ) material.fog = json.fog;
  21463. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  21464. if ( json.blending !== undefined ) material.blending = json.blending;
  21465. if ( json.side !== undefined ) material.side = json.side;
  21466. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  21467. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  21468. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  21469. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  21470. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  21471. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  21472. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  21473. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  21474. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  21475. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  21476. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  21477. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  21478. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  21479. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  21480. if ( json.scale !== undefined ) material.scale = json.scale;
  21481. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  21482. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  21483. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  21484. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  21485. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  21486. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  21487. if ( json.visible !== undefined ) material.visible = json.visible;
  21488. if ( json.userData !== undefined ) material.userData = json.userData;
  21489. // Deprecated
  21490. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  21491. // for PointsMaterial
  21492. if ( json.size !== undefined ) material.size = json.size;
  21493. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  21494. // maps
  21495. if ( json.map !== undefined ) material.map = getTexture( json.map );
  21496. if ( json.alphaMap !== undefined ) {
  21497. material.alphaMap = getTexture( json.alphaMap );
  21498. material.transparent = true;
  21499. }
  21500. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  21501. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  21502. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  21503. if ( json.normalScale !== undefined ) {
  21504. var normalScale = json.normalScale;
  21505. if ( Array.isArray( normalScale ) === false ) {
  21506. // Blender exporter used to export a scalar. See #7459
  21507. normalScale = [ normalScale, normalScale ];
  21508. }
  21509. material.normalScale = new Vector2().fromArray( normalScale );
  21510. }
  21511. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  21512. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  21513. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  21514. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  21515. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  21516. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  21517. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  21518. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  21519. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  21520. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  21521. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  21522. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  21523. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  21524. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  21525. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  21526. return material;
  21527. }
  21528. } );
  21529. /**
  21530. * @author mrdoob / http://mrdoob.com/
  21531. */
  21532. function BufferGeometryLoader( manager ) {
  21533. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21534. }
  21535. Object.assign( BufferGeometryLoader.prototype, {
  21536. load: function ( url, onLoad, onProgress, onError ) {
  21537. var scope = this;
  21538. var loader = new FileLoader( scope.manager );
  21539. loader.load( url, function ( text ) {
  21540. onLoad( scope.parse( JSON.parse( text ) ) );
  21541. }, onProgress, onError );
  21542. },
  21543. parse: function ( json ) {
  21544. var geometry = new BufferGeometry();
  21545. var index = json.data.index;
  21546. if ( index !== undefined ) {
  21547. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  21548. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  21549. }
  21550. var attributes = json.data.attributes;
  21551. for ( var key in attributes ) {
  21552. var attribute = attributes[ key ];
  21553. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  21554. geometry.addAttribute( key, new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized ) );
  21555. }
  21556. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  21557. if ( groups !== undefined ) {
  21558. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  21559. var group = groups[ i ];
  21560. geometry.addGroup( group.start, group.count, group.materialIndex );
  21561. }
  21562. }
  21563. var boundingSphere = json.data.boundingSphere;
  21564. if ( boundingSphere !== undefined ) {
  21565. var center = new Vector3();
  21566. if ( boundingSphere.center !== undefined ) {
  21567. center.fromArray( boundingSphere.center );
  21568. }
  21569. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  21570. }
  21571. return geometry;
  21572. }
  21573. } );
  21574. var TYPED_ARRAYS = {
  21575. Int8Array: Int8Array,
  21576. Uint8Array: Uint8Array,
  21577. // Workaround for IE11 pre KB2929437. See #11440
  21578. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  21579. Int16Array: Int16Array,
  21580. Uint16Array: Uint16Array,
  21581. Int32Array: Int32Array,
  21582. Uint32Array: Uint32Array,
  21583. Float32Array: Float32Array,
  21584. Float64Array: Float64Array
  21585. };
  21586. /**
  21587. * @author alteredq / http://alteredqualia.com/
  21588. */
  21589. function Loader() {}
  21590. Loader.Handlers = {
  21591. handlers: [],
  21592. add: function ( regex, loader ) {
  21593. this.handlers.push( regex, loader );
  21594. },
  21595. get: function ( file ) {
  21596. var handlers = this.handlers;
  21597. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  21598. var regex = handlers[ i ];
  21599. var loader = handlers[ i + 1 ];
  21600. if ( regex.test( file ) ) {
  21601. return loader;
  21602. }
  21603. }
  21604. return null;
  21605. }
  21606. };
  21607. Object.assign( Loader.prototype, {
  21608. crossOrigin: undefined,
  21609. onLoadStart: function () {},
  21610. onLoadProgress: function () {},
  21611. onLoadComplete: function () {},
  21612. initMaterials: function ( materials, texturePath, crossOrigin ) {
  21613. var array = [];
  21614. for ( var i = 0; i < materials.length; ++ i ) {
  21615. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  21616. }
  21617. return array;
  21618. },
  21619. createMaterial: ( function () {
  21620. var BlendingMode = {
  21621. NoBlending: NoBlending,
  21622. NormalBlending: NormalBlending,
  21623. AdditiveBlending: AdditiveBlending,
  21624. SubtractiveBlending: SubtractiveBlending,
  21625. MultiplyBlending: MultiplyBlending,
  21626. CustomBlending: CustomBlending
  21627. };
  21628. var color = new Color();
  21629. var textureLoader = new TextureLoader();
  21630. var materialLoader = new MaterialLoader();
  21631. return function createMaterial( m, texturePath, crossOrigin ) {
  21632. // convert from old material format
  21633. var textures = {};
  21634. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  21635. var fullPath = texturePath + path;
  21636. var loader = Loader.Handlers.get( fullPath );
  21637. var texture;
  21638. if ( loader !== null ) {
  21639. texture = loader.load( fullPath );
  21640. } else {
  21641. textureLoader.setCrossOrigin( crossOrigin );
  21642. texture = textureLoader.load( fullPath );
  21643. }
  21644. if ( repeat !== undefined ) {
  21645. texture.repeat.fromArray( repeat );
  21646. if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
  21647. if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
  21648. }
  21649. if ( offset !== undefined ) {
  21650. texture.offset.fromArray( offset );
  21651. }
  21652. if ( wrap !== undefined ) {
  21653. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
  21654. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
  21655. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
  21656. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
  21657. }
  21658. if ( anisotropy !== undefined ) {
  21659. texture.anisotropy = anisotropy;
  21660. }
  21661. var uuid = _Math.generateUUID();
  21662. textures[ uuid ] = texture;
  21663. return uuid;
  21664. }
  21665. //
  21666. var json = {
  21667. uuid: _Math.generateUUID(),
  21668. type: 'MeshLambertMaterial'
  21669. };
  21670. for ( var name in m ) {
  21671. var value = m[ name ];
  21672. switch ( name ) {
  21673. case 'DbgColor':
  21674. case 'DbgIndex':
  21675. case 'opticalDensity':
  21676. case 'illumination':
  21677. break;
  21678. case 'DbgName':
  21679. json.name = value;
  21680. break;
  21681. case 'blending':
  21682. json.blending = BlendingMode[ value ];
  21683. break;
  21684. case 'colorAmbient':
  21685. case 'mapAmbient':
  21686. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  21687. break;
  21688. case 'colorDiffuse':
  21689. json.color = color.fromArray( value ).getHex();
  21690. break;
  21691. case 'colorSpecular':
  21692. json.specular = color.fromArray( value ).getHex();
  21693. break;
  21694. case 'colorEmissive':
  21695. json.emissive = color.fromArray( value ).getHex();
  21696. break;
  21697. case 'specularCoef':
  21698. json.shininess = value;
  21699. break;
  21700. case 'shading':
  21701. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  21702. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  21703. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  21704. break;
  21705. case 'mapDiffuse':
  21706. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  21707. break;
  21708. case 'mapDiffuseRepeat':
  21709. case 'mapDiffuseOffset':
  21710. case 'mapDiffuseWrap':
  21711. case 'mapDiffuseAnisotropy':
  21712. break;
  21713. case 'mapEmissive':
  21714. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  21715. break;
  21716. case 'mapEmissiveRepeat':
  21717. case 'mapEmissiveOffset':
  21718. case 'mapEmissiveWrap':
  21719. case 'mapEmissiveAnisotropy':
  21720. break;
  21721. case 'mapLight':
  21722. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  21723. break;
  21724. case 'mapLightRepeat':
  21725. case 'mapLightOffset':
  21726. case 'mapLightWrap':
  21727. case 'mapLightAnisotropy':
  21728. break;
  21729. case 'mapAO':
  21730. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  21731. break;
  21732. case 'mapAORepeat':
  21733. case 'mapAOOffset':
  21734. case 'mapAOWrap':
  21735. case 'mapAOAnisotropy':
  21736. break;
  21737. case 'mapBump':
  21738. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  21739. break;
  21740. case 'mapBumpScale':
  21741. json.bumpScale = value;
  21742. break;
  21743. case 'mapBumpRepeat':
  21744. case 'mapBumpOffset':
  21745. case 'mapBumpWrap':
  21746. case 'mapBumpAnisotropy':
  21747. break;
  21748. case 'mapNormal':
  21749. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  21750. break;
  21751. case 'mapNormalFactor':
  21752. json.normalScale = value;
  21753. break;
  21754. case 'mapNormalRepeat':
  21755. case 'mapNormalOffset':
  21756. case 'mapNormalWrap':
  21757. case 'mapNormalAnisotropy':
  21758. break;
  21759. case 'mapSpecular':
  21760. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  21761. break;
  21762. case 'mapSpecularRepeat':
  21763. case 'mapSpecularOffset':
  21764. case 'mapSpecularWrap':
  21765. case 'mapSpecularAnisotropy':
  21766. break;
  21767. case 'mapMetalness':
  21768. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  21769. break;
  21770. case 'mapMetalnessRepeat':
  21771. case 'mapMetalnessOffset':
  21772. case 'mapMetalnessWrap':
  21773. case 'mapMetalnessAnisotropy':
  21774. break;
  21775. case 'mapRoughness':
  21776. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  21777. break;
  21778. case 'mapRoughnessRepeat':
  21779. case 'mapRoughnessOffset':
  21780. case 'mapRoughnessWrap':
  21781. case 'mapRoughnessAnisotropy':
  21782. break;
  21783. case 'mapAlpha':
  21784. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  21785. break;
  21786. case 'mapAlphaRepeat':
  21787. case 'mapAlphaOffset':
  21788. case 'mapAlphaWrap':
  21789. case 'mapAlphaAnisotropy':
  21790. break;
  21791. case 'flipSided':
  21792. json.side = BackSide;
  21793. break;
  21794. case 'doubleSided':
  21795. json.side = DoubleSide;
  21796. break;
  21797. case 'transparency':
  21798. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  21799. json.opacity = value;
  21800. break;
  21801. case 'depthTest':
  21802. case 'depthWrite':
  21803. case 'colorWrite':
  21804. case 'opacity':
  21805. case 'reflectivity':
  21806. case 'transparent':
  21807. case 'visible':
  21808. case 'wireframe':
  21809. json[ name ] = value;
  21810. break;
  21811. case 'vertexColors':
  21812. if ( value === true ) json.vertexColors = VertexColors;
  21813. if ( value === 'face' ) json.vertexColors = FaceColors;
  21814. break;
  21815. default:
  21816. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  21817. break;
  21818. }
  21819. }
  21820. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  21821. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  21822. if ( json.opacity < 1 ) json.transparent = true;
  21823. materialLoader.setTextures( textures );
  21824. return materialLoader.parse( json );
  21825. };
  21826. } )()
  21827. } );
  21828. /**
  21829. * @author Don McCurdy / https://www.donmccurdy.com
  21830. */
  21831. var LoaderUtils = {
  21832. decodeText: function ( array ) {
  21833. if ( typeof TextDecoder !== 'undefined' ) {
  21834. return new TextDecoder().decode( array );
  21835. }
  21836. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  21837. // throws a "maximum call stack size exceeded" error for large arrays.
  21838. var s = '';
  21839. for ( var i = 0, il = array.length; i < il; i ++ ) {
  21840. // Implicitly assumes little-endian.
  21841. s += String.fromCharCode( array[ i ] );
  21842. }
  21843. // Merges multi-byte utf-8 characters.
  21844. return decodeURIComponent( escape( s ) );
  21845. },
  21846. extractUrlBase: function ( url ) {
  21847. var index = url.lastIndexOf( '/' );
  21848. if ( index === - 1 ) return './';
  21849. return url.substr( 0, index + 1 );
  21850. }
  21851. };
  21852. /**
  21853. * @author mrdoob / http://mrdoob.com/
  21854. * @author alteredq / http://alteredqualia.com/
  21855. */
  21856. function JSONLoader( manager ) {
  21857. if ( typeof manager === 'boolean' ) {
  21858. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  21859. manager = undefined;
  21860. }
  21861. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21862. this.withCredentials = false;
  21863. }
  21864. Object.assign( JSONLoader.prototype, {
  21865. load: function ( url, onLoad, onProgress, onError ) {
  21866. var scope = this;
  21867. var texturePath = this.texturePath && ( typeof this.texturePath === 'string' ) ? this.texturePath : LoaderUtils.extractUrlBase( url );
  21868. var loader = new FileLoader( this.manager );
  21869. loader.setWithCredentials( this.withCredentials );
  21870. loader.load( url, function ( text ) {
  21871. var json = JSON.parse( text );
  21872. var metadata = json.metadata;
  21873. if ( metadata !== undefined ) {
  21874. var type = metadata.type;
  21875. if ( type !== undefined ) {
  21876. if ( type.toLowerCase() === 'object' ) {
  21877. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  21878. return;
  21879. }
  21880. }
  21881. }
  21882. var object = scope.parse( json, texturePath );
  21883. onLoad( object.geometry, object.materials );
  21884. }, onProgress, onError );
  21885. },
  21886. setTexturePath: function ( value ) {
  21887. this.texturePath = value;
  21888. },
  21889. parse: ( function () {
  21890. function parseModel( json, geometry ) {
  21891. function isBitSet( value, position ) {
  21892. return value & ( 1 << position );
  21893. }
  21894. var i, j, fi,
  21895. offset, zLength,
  21896. colorIndex, normalIndex, uvIndex, materialIndex,
  21897. type,
  21898. isQuad,
  21899. hasMaterial,
  21900. hasFaceVertexUv,
  21901. hasFaceNormal, hasFaceVertexNormal,
  21902. hasFaceColor, hasFaceVertexColor,
  21903. vertex, face, faceA, faceB, hex, normal,
  21904. uvLayer, uv, u, v,
  21905. faces = json.faces,
  21906. vertices = json.vertices,
  21907. normals = json.normals,
  21908. colors = json.colors,
  21909. scale = json.scale,
  21910. nUvLayers = 0;
  21911. if ( json.uvs !== undefined ) {
  21912. // disregard empty arrays
  21913. for ( i = 0; i < json.uvs.length; i ++ ) {
  21914. if ( json.uvs[ i ].length ) nUvLayers ++;
  21915. }
  21916. for ( i = 0; i < nUvLayers; i ++ ) {
  21917. geometry.faceVertexUvs[ i ] = [];
  21918. }
  21919. }
  21920. offset = 0;
  21921. zLength = vertices.length;
  21922. while ( offset < zLength ) {
  21923. vertex = new Vector3();
  21924. vertex.x = vertices[ offset ++ ] * scale;
  21925. vertex.y = vertices[ offset ++ ] * scale;
  21926. vertex.z = vertices[ offset ++ ] * scale;
  21927. geometry.vertices.push( vertex );
  21928. }
  21929. offset = 0;
  21930. zLength = faces.length;
  21931. while ( offset < zLength ) {
  21932. type = faces[ offset ++ ];
  21933. isQuad = isBitSet( type, 0 );
  21934. hasMaterial = isBitSet( type, 1 );
  21935. hasFaceVertexUv = isBitSet( type, 3 );
  21936. hasFaceNormal = isBitSet( type, 4 );
  21937. hasFaceVertexNormal = isBitSet( type, 5 );
  21938. hasFaceColor = isBitSet( type, 6 );
  21939. hasFaceVertexColor = isBitSet( type, 7 );
  21940. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  21941. if ( isQuad ) {
  21942. faceA = new Face3();
  21943. faceA.a = faces[ offset ];
  21944. faceA.b = faces[ offset + 1 ];
  21945. faceA.c = faces[ offset + 3 ];
  21946. faceB = new Face3();
  21947. faceB.a = faces[ offset + 1 ];
  21948. faceB.b = faces[ offset + 2 ];
  21949. faceB.c = faces[ offset + 3 ];
  21950. offset += 4;
  21951. if ( hasMaterial ) {
  21952. materialIndex = faces[ offset ++ ];
  21953. faceA.materialIndex = materialIndex;
  21954. faceB.materialIndex = materialIndex;
  21955. }
  21956. // to get face <=> uv index correspondence
  21957. fi = geometry.faces.length;
  21958. if ( hasFaceVertexUv ) {
  21959. for ( i = 0; i < nUvLayers; i ++ ) {
  21960. uvLayer = json.uvs[ i ];
  21961. geometry.faceVertexUvs[ i ][ fi ] = [];
  21962. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  21963. for ( j = 0; j < 4; j ++ ) {
  21964. uvIndex = faces[ offset ++ ];
  21965. u = uvLayer[ uvIndex * 2 ];
  21966. v = uvLayer[ uvIndex * 2 + 1 ];
  21967. uv = new Vector2( u, v );
  21968. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  21969. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  21970. }
  21971. }
  21972. }
  21973. if ( hasFaceNormal ) {
  21974. normalIndex = faces[ offset ++ ] * 3;
  21975. faceA.normal.set(
  21976. normals[ normalIndex ++ ],
  21977. normals[ normalIndex ++ ],
  21978. normals[ normalIndex ]
  21979. );
  21980. faceB.normal.copy( faceA.normal );
  21981. }
  21982. if ( hasFaceVertexNormal ) {
  21983. for ( i = 0; i < 4; i ++ ) {
  21984. normalIndex = faces[ offset ++ ] * 3;
  21985. normal = new Vector3(
  21986. normals[ normalIndex ++ ],
  21987. normals[ normalIndex ++ ],
  21988. normals[ normalIndex ]
  21989. );
  21990. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  21991. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  21992. }
  21993. }
  21994. if ( hasFaceColor ) {
  21995. colorIndex = faces[ offset ++ ];
  21996. hex = colors[ colorIndex ];
  21997. faceA.color.setHex( hex );
  21998. faceB.color.setHex( hex );
  21999. }
  22000. if ( hasFaceVertexColor ) {
  22001. for ( i = 0; i < 4; i ++ ) {
  22002. colorIndex = faces[ offset ++ ];
  22003. hex = colors[ colorIndex ];
  22004. if ( i !== 2 ) faceA.vertexColors.push( new Color( hex ) );
  22005. if ( i !== 0 ) faceB.vertexColors.push( new Color( hex ) );
  22006. }
  22007. }
  22008. geometry.faces.push( faceA );
  22009. geometry.faces.push( faceB );
  22010. } else {
  22011. face = new Face3();
  22012. face.a = faces[ offset ++ ];
  22013. face.b = faces[ offset ++ ];
  22014. face.c = faces[ offset ++ ];
  22015. if ( hasMaterial ) {
  22016. materialIndex = faces[ offset ++ ];
  22017. face.materialIndex = materialIndex;
  22018. }
  22019. // to get face <=> uv index correspondence
  22020. fi = geometry.faces.length;
  22021. if ( hasFaceVertexUv ) {
  22022. for ( i = 0; i < nUvLayers; i ++ ) {
  22023. uvLayer = json.uvs[ i ];
  22024. geometry.faceVertexUvs[ i ][ fi ] = [];
  22025. for ( j = 0; j < 3; j ++ ) {
  22026. uvIndex = faces[ offset ++ ];
  22027. u = uvLayer[ uvIndex * 2 ];
  22028. v = uvLayer[ uvIndex * 2 + 1 ];
  22029. uv = new Vector2( u, v );
  22030. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  22031. }
  22032. }
  22033. }
  22034. if ( hasFaceNormal ) {
  22035. normalIndex = faces[ offset ++ ] * 3;
  22036. face.normal.set(
  22037. normals[ normalIndex ++ ],
  22038. normals[ normalIndex ++ ],
  22039. normals[ normalIndex ]
  22040. );
  22041. }
  22042. if ( hasFaceVertexNormal ) {
  22043. for ( i = 0; i < 3; i ++ ) {
  22044. normalIndex = faces[ offset ++ ] * 3;
  22045. normal = new Vector3(
  22046. normals[ normalIndex ++ ],
  22047. normals[ normalIndex ++ ],
  22048. normals[ normalIndex ]
  22049. );
  22050. face.vertexNormals.push( normal );
  22051. }
  22052. }
  22053. if ( hasFaceColor ) {
  22054. colorIndex = faces[ offset ++ ];
  22055. face.color.setHex( colors[ colorIndex ] );
  22056. }
  22057. if ( hasFaceVertexColor ) {
  22058. for ( i = 0; i < 3; i ++ ) {
  22059. colorIndex = faces[ offset ++ ];
  22060. face.vertexColors.push( new Color( colors[ colorIndex ] ) );
  22061. }
  22062. }
  22063. geometry.faces.push( face );
  22064. }
  22065. }
  22066. }
  22067. function parseSkin( json, geometry ) {
  22068. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  22069. if ( json.skinWeights ) {
  22070. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  22071. var x = json.skinWeights[ i ];
  22072. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  22073. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  22074. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  22075. geometry.skinWeights.push( new Vector4( x, y, z, w ) );
  22076. }
  22077. }
  22078. if ( json.skinIndices ) {
  22079. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  22080. var a = json.skinIndices[ i ];
  22081. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  22082. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  22083. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  22084. geometry.skinIndices.push( new Vector4( a, b, c, d ) );
  22085. }
  22086. }
  22087. geometry.bones = json.bones;
  22088. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  22089. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  22090. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  22091. }
  22092. }
  22093. function parseMorphing( json, geometry ) {
  22094. var scale = json.scale;
  22095. if ( json.morphTargets !== undefined ) {
  22096. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  22097. geometry.morphTargets[ i ] = {};
  22098. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  22099. geometry.morphTargets[ i ].vertices = [];
  22100. var dstVertices = geometry.morphTargets[ i ].vertices;
  22101. var srcVertices = json.morphTargets[ i ].vertices;
  22102. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  22103. var vertex = new Vector3();
  22104. vertex.x = srcVertices[ v ] * scale;
  22105. vertex.y = srcVertices[ v + 1 ] * scale;
  22106. vertex.z = srcVertices[ v + 2 ] * scale;
  22107. dstVertices.push( vertex );
  22108. }
  22109. }
  22110. }
  22111. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  22112. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  22113. var faces = geometry.faces;
  22114. var morphColors = json.morphColors[ 0 ].colors;
  22115. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  22116. faces[ i ].color.fromArray( morphColors, i * 3 );
  22117. }
  22118. }
  22119. }
  22120. function parseAnimations( json, geometry ) {
  22121. var outputAnimations = [];
  22122. // parse old style Bone/Hierarchy animations
  22123. var animations = [];
  22124. if ( json.animation !== undefined ) {
  22125. animations.push( json.animation );
  22126. }
  22127. if ( json.animations !== undefined ) {
  22128. if ( json.animations.length ) {
  22129. animations = animations.concat( json.animations );
  22130. } else {
  22131. animations.push( json.animations );
  22132. }
  22133. }
  22134. for ( var i = 0; i < animations.length; i ++ ) {
  22135. var clip = AnimationClip.parseAnimation( animations[ i ], geometry.bones );
  22136. if ( clip ) outputAnimations.push( clip );
  22137. }
  22138. // parse implicit morph animations
  22139. if ( geometry.morphTargets ) {
  22140. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  22141. var morphAnimationClips = AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  22142. outputAnimations = outputAnimations.concat( morphAnimationClips );
  22143. }
  22144. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  22145. }
  22146. return function parse( json, texturePath ) {
  22147. if ( json.data !== undefined ) {
  22148. // Geometry 4.0 spec
  22149. json = json.data;
  22150. }
  22151. if ( json.scale !== undefined ) {
  22152. json.scale = 1.0 / json.scale;
  22153. } else {
  22154. json.scale = 1.0;
  22155. }
  22156. var geometry = new Geometry();
  22157. parseModel( json, geometry );
  22158. parseSkin( json, geometry );
  22159. parseMorphing( json, geometry );
  22160. parseAnimations( json, geometry );
  22161. geometry.computeFaceNormals();
  22162. geometry.computeBoundingSphere();
  22163. if ( json.materials === undefined || json.materials.length === 0 ) {
  22164. return { geometry: geometry };
  22165. } else {
  22166. var materials = Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  22167. return { geometry: geometry, materials: materials };
  22168. }
  22169. };
  22170. } )()
  22171. } );
  22172. /**
  22173. * @author mrdoob / http://mrdoob.com/
  22174. */
  22175. function ObjectLoader( manager ) {
  22176. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22177. this.texturePath = '';
  22178. }
  22179. Object.assign( ObjectLoader.prototype, {
  22180. load: function ( url, onLoad, onProgress, onError ) {
  22181. if ( this.texturePath === '' ) {
  22182. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  22183. }
  22184. var scope = this;
  22185. var loader = new FileLoader( scope.manager );
  22186. loader.load( url, function ( text ) {
  22187. var json = null;
  22188. try {
  22189. json = JSON.parse( text );
  22190. } catch ( error ) {
  22191. if ( onError !== undefined ) onError( error );
  22192. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  22193. return;
  22194. }
  22195. var metadata = json.metadata;
  22196. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  22197. console.error( 'THREE.ObjectLoader: Can\'t load ' + url + '. Use THREE.JSONLoader instead.' );
  22198. return;
  22199. }
  22200. scope.parse( json, onLoad );
  22201. }, onProgress, onError );
  22202. },
  22203. setTexturePath: function ( value ) {
  22204. this.texturePath = value;
  22205. return this;
  22206. },
  22207. setCrossOrigin: function ( value ) {
  22208. this.crossOrigin = value;
  22209. return this;
  22210. },
  22211. parse: function ( json, onLoad ) {
  22212. var shapes = this.parseShape( json.shapes );
  22213. var geometries = this.parseGeometries( json.geometries, shapes );
  22214. var images = this.parseImages( json.images, function () {
  22215. if ( onLoad !== undefined ) onLoad( object );
  22216. } );
  22217. var textures = this.parseTextures( json.textures, images );
  22218. var materials = this.parseMaterials( json.materials, textures );
  22219. var object = this.parseObject( json.object, geometries, materials );
  22220. if ( json.animations ) {
  22221. object.animations = this.parseAnimations( json.animations );
  22222. }
  22223. if ( json.images === undefined || json.images.length === 0 ) {
  22224. if ( onLoad !== undefined ) onLoad( object );
  22225. }
  22226. return object;
  22227. },
  22228. parseShape: function ( json ) {
  22229. var shapes = {};
  22230. if ( json !== undefined ) {
  22231. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22232. var shape = new Shape().fromJSON( json[ i ] );
  22233. shapes[ shape.uuid ] = shape;
  22234. }
  22235. }
  22236. return shapes;
  22237. },
  22238. parseGeometries: function ( json, shapes ) {
  22239. var geometries = {};
  22240. if ( json !== undefined ) {
  22241. var geometryLoader = new JSONLoader();
  22242. var bufferGeometryLoader = new BufferGeometryLoader();
  22243. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22244. var geometry;
  22245. var data = json[ i ];
  22246. switch ( data.type ) {
  22247. case 'PlaneGeometry':
  22248. case 'PlaneBufferGeometry':
  22249. geometry = new Geometries[ data.type ](
  22250. data.width,
  22251. data.height,
  22252. data.widthSegments,
  22253. data.heightSegments
  22254. );
  22255. break;
  22256. case 'BoxGeometry':
  22257. case 'BoxBufferGeometry':
  22258. case 'CubeGeometry': // backwards compatible
  22259. geometry = new Geometries[ data.type ](
  22260. data.width,
  22261. data.height,
  22262. data.depth,
  22263. data.widthSegments,
  22264. data.heightSegments,
  22265. data.depthSegments
  22266. );
  22267. break;
  22268. case 'CircleGeometry':
  22269. case 'CircleBufferGeometry':
  22270. geometry = new Geometries[ data.type ](
  22271. data.radius,
  22272. data.segments,
  22273. data.thetaStart,
  22274. data.thetaLength
  22275. );
  22276. break;
  22277. case 'CylinderGeometry':
  22278. case 'CylinderBufferGeometry':
  22279. geometry = new Geometries[ data.type ](
  22280. data.radiusTop,
  22281. data.radiusBottom,
  22282. data.height,
  22283. data.radialSegments,
  22284. data.heightSegments,
  22285. data.openEnded,
  22286. data.thetaStart,
  22287. data.thetaLength
  22288. );
  22289. break;
  22290. case 'ConeGeometry':
  22291. case 'ConeBufferGeometry':
  22292. geometry = new Geometries[ data.type ](
  22293. data.radius,
  22294. data.height,
  22295. data.radialSegments,
  22296. data.heightSegments,
  22297. data.openEnded,
  22298. data.thetaStart,
  22299. data.thetaLength
  22300. );
  22301. break;
  22302. case 'SphereGeometry':
  22303. case 'SphereBufferGeometry':
  22304. geometry = new Geometries[ data.type ](
  22305. data.radius,
  22306. data.widthSegments,
  22307. data.heightSegments,
  22308. data.phiStart,
  22309. data.phiLength,
  22310. data.thetaStart,
  22311. data.thetaLength
  22312. );
  22313. break;
  22314. case 'DodecahedronGeometry':
  22315. case 'DodecahedronBufferGeometry':
  22316. case 'IcosahedronGeometry':
  22317. case 'IcosahedronBufferGeometry':
  22318. case 'OctahedronGeometry':
  22319. case 'OctahedronBufferGeometry':
  22320. case 'TetrahedronGeometry':
  22321. case 'TetrahedronBufferGeometry':
  22322. geometry = new Geometries[ data.type ](
  22323. data.radius,
  22324. data.detail
  22325. );
  22326. break;
  22327. case 'RingGeometry':
  22328. case 'RingBufferGeometry':
  22329. geometry = new Geometries[ data.type ](
  22330. data.innerRadius,
  22331. data.outerRadius,
  22332. data.thetaSegments,
  22333. data.phiSegments,
  22334. data.thetaStart,
  22335. data.thetaLength
  22336. );
  22337. break;
  22338. case 'TorusGeometry':
  22339. case 'TorusBufferGeometry':
  22340. geometry = new Geometries[ data.type ](
  22341. data.radius,
  22342. data.tube,
  22343. data.radialSegments,
  22344. data.tubularSegments,
  22345. data.arc
  22346. );
  22347. break;
  22348. case 'TorusKnotGeometry':
  22349. case 'TorusKnotBufferGeometry':
  22350. geometry = new Geometries[ data.type ](
  22351. data.radius,
  22352. data.tube,
  22353. data.tubularSegments,
  22354. data.radialSegments,
  22355. data.p,
  22356. data.q
  22357. );
  22358. break;
  22359. case 'LatheGeometry':
  22360. case 'LatheBufferGeometry':
  22361. geometry = new Geometries[ data.type ](
  22362. data.points,
  22363. data.segments,
  22364. data.phiStart,
  22365. data.phiLength
  22366. );
  22367. break;
  22368. case 'PolyhedronGeometry':
  22369. case 'PolyhedronBufferGeometry':
  22370. geometry = new Geometries[ data.type ](
  22371. data.vertices,
  22372. data.indices,
  22373. data.radius,
  22374. data.details
  22375. );
  22376. break;
  22377. case 'ShapeGeometry':
  22378. case 'ShapeBufferGeometry':
  22379. var geometryShapes = [];
  22380. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  22381. var shape = shapes[ data.shapes[ j ] ];
  22382. geometryShapes.push( shape );
  22383. }
  22384. geometry = new Geometries[ data.type ](
  22385. geometryShapes,
  22386. data.curveSegments
  22387. );
  22388. break;
  22389. case 'BufferGeometry':
  22390. geometry = bufferGeometryLoader.parse( data );
  22391. break;
  22392. case 'Geometry':
  22393. geometry = geometryLoader.parse( data, this.texturePath ).geometry;
  22394. break;
  22395. default:
  22396. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  22397. continue;
  22398. }
  22399. geometry.uuid = data.uuid;
  22400. if ( data.name !== undefined ) geometry.name = data.name;
  22401. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
  22402. geometries[ data.uuid ] = geometry;
  22403. }
  22404. }
  22405. return geometries;
  22406. },
  22407. parseMaterials: function ( json, textures ) {
  22408. var materials = {};
  22409. if ( json !== undefined ) {
  22410. var loader = new MaterialLoader();
  22411. loader.setTextures( textures );
  22412. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22413. var data = json[ i ];
  22414. if ( data.type === 'MultiMaterial' ) {
  22415. // Deprecated
  22416. var array = [];
  22417. for ( var j = 0; j < data.materials.length; j ++ ) {
  22418. array.push( loader.parse( data.materials[ j ] ) );
  22419. }
  22420. materials[ data.uuid ] = array;
  22421. } else {
  22422. materials[ data.uuid ] = loader.parse( data );
  22423. }
  22424. }
  22425. }
  22426. return materials;
  22427. },
  22428. parseAnimations: function ( json ) {
  22429. var animations = [];
  22430. for ( var i = 0; i < json.length; i ++ ) {
  22431. var data = json[ i ];
  22432. var clip = AnimationClip.parse( data );
  22433. if ( data.uuid !== undefined ) clip.uuid = data.uuid;
  22434. animations.push( clip );
  22435. }
  22436. return animations;
  22437. },
  22438. parseImages: function ( json, onLoad ) {
  22439. var scope = this;
  22440. var images = {};
  22441. function loadImage( url ) {
  22442. scope.manager.itemStart( url );
  22443. return loader.load( url, function () {
  22444. scope.manager.itemEnd( url );
  22445. }, undefined, function () {
  22446. scope.manager.itemEnd( url );
  22447. scope.manager.itemError( url );
  22448. } );
  22449. }
  22450. if ( json !== undefined && json.length > 0 ) {
  22451. var manager = new LoadingManager( onLoad );
  22452. var loader = new ImageLoader( manager );
  22453. loader.setCrossOrigin( this.crossOrigin );
  22454. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22455. var image = json[ i ];
  22456. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  22457. images[ image.uuid ] = loadImage( path );
  22458. }
  22459. }
  22460. return images;
  22461. },
  22462. parseTextures: function ( json, images ) {
  22463. function parseConstant( value, type ) {
  22464. if ( typeof value === 'number' ) return value;
  22465. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  22466. return type[ value ];
  22467. }
  22468. var textures = {};
  22469. if ( json !== undefined ) {
  22470. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22471. var data = json[ i ];
  22472. if ( data.image === undefined ) {
  22473. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  22474. }
  22475. if ( images[ data.image ] === undefined ) {
  22476. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  22477. }
  22478. var texture = new Texture( images[ data.image ] );
  22479. texture.needsUpdate = true;
  22480. texture.uuid = data.uuid;
  22481. if ( data.name !== undefined ) texture.name = data.name;
  22482. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  22483. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  22484. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  22485. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  22486. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  22487. if ( data.wrap !== undefined ) {
  22488. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  22489. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  22490. }
  22491. if ( data.format !== undefined ) texture.format = data.format;
  22492. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  22493. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  22494. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  22495. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  22496. textures[ data.uuid ] = texture;
  22497. }
  22498. }
  22499. return textures;
  22500. },
  22501. parseObject: function ( data, geometries, materials ) {
  22502. var object;
  22503. function getGeometry( name ) {
  22504. if ( geometries[ name ] === undefined ) {
  22505. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  22506. }
  22507. return geometries[ name ];
  22508. }
  22509. function getMaterial( name ) {
  22510. if ( name === undefined ) return undefined;
  22511. if ( Array.isArray( name ) ) {
  22512. var array = [];
  22513. for ( var i = 0, l = name.length; i < l; i ++ ) {
  22514. var uuid = name[ i ];
  22515. if ( materials[ uuid ] === undefined ) {
  22516. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  22517. }
  22518. array.push( materials[ uuid ] );
  22519. }
  22520. return array;
  22521. }
  22522. if ( materials[ name ] === undefined ) {
  22523. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  22524. }
  22525. return materials[ name ];
  22526. }
  22527. switch ( data.type ) {
  22528. case 'Scene':
  22529. object = new Scene();
  22530. if ( data.background !== undefined ) {
  22531. if ( Number.isInteger( data.background ) ) {
  22532. object.background = new Color( data.background );
  22533. }
  22534. }
  22535. if ( data.fog !== undefined ) {
  22536. if ( data.fog.type === 'Fog' ) {
  22537. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  22538. } else if ( data.fog.type === 'FogExp2' ) {
  22539. object.fog = new FogExp2( data.fog.color, data.fog.density );
  22540. }
  22541. }
  22542. break;
  22543. case 'PerspectiveCamera':
  22544. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  22545. if ( data.focus !== undefined ) object.focus = data.focus;
  22546. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  22547. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  22548. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  22549. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  22550. break;
  22551. case 'OrthographicCamera':
  22552. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  22553. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  22554. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  22555. break;
  22556. case 'AmbientLight':
  22557. object = new AmbientLight( data.color, data.intensity );
  22558. break;
  22559. case 'DirectionalLight':
  22560. object = new DirectionalLight( data.color, data.intensity );
  22561. break;
  22562. case 'PointLight':
  22563. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  22564. break;
  22565. case 'RectAreaLight':
  22566. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  22567. break;
  22568. case 'SpotLight':
  22569. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  22570. break;
  22571. case 'HemisphereLight':
  22572. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  22573. break;
  22574. case 'SkinnedMesh':
  22575. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  22576. case 'Mesh':
  22577. var geometry = getGeometry( data.geometry );
  22578. var material = getMaterial( data.material );
  22579. if ( geometry.bones && geometry.bones.length > 0 ) {
  22580. object = new SkinnedMesh( geometry, material );
  22581. } else {
  22582. object = new Mesh( geometry, material );
  22583. }
  22584. break;
  22585. case 'LOD':
  22586. object = new LOD();
  22587. break;
  22588. case 'Line':
  22589. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  22590. break;
  22591. case 'LineLoop':
  22592. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  22593. break;
  22594. case 'LineSegments':
  22595. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  22596. break;
  22597. case 'PointCloud':
  22598. case 'Points':
  22599. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  22600. break;
  22601. case 'Sprite':
  22602. object = new Sprite( getMaterial( data.material ) );
  22603. break;
  22604. case 'Group':
  22605. object = new Group();
  22606. break;
  22607. default:
  22608. object = new Object3D();
  22609. }
  22610. object.uuid = data.uuid;
  22611. if ( data.name !== undefined ) object.name = data.name;
  22612. if ( data.matrix !== undefined ) {
  22613. object.matrix.fromArray( data.matrix );
  22614. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  22615. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  22616. } else {
  22617. if ( data.position !== undefined ) object.position.fromArray( data.position );
  22618. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  22619. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  22620. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  22621. }
  22622. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  22623. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  22624. if ( data.shadow ) {
  22625. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  22626. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  22627. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  22628. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  22629. }
  22630. if ( data.visible !== undefined ) object.visible = data.visible;
  22631. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  22632. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  22633. if ( data.userData !== undefined ) object.userData = data.userData;
  22634. if ( data.children !== undefined ) {
  22635. var children = data.children;
  22636. for ( var i = 0; i < children.length; i ++ ) {
  22637. object.add( this.parseObject( children[ i ], geometries, materials ) );
  22638. }
  22639. }
  22640. if ( data.type === 'LOD' ) {
  22641. var levels = data.levels;
  22642. for ( var l = 0; l < levels.length; l ++ ) {
  22643. var level = levels[ l ];
  22644. var child = object.getObjectByProperty( 'uuid', level.object );
  22645. if ( child !== undefined ) {
  22646. object.addLevel( child, level.distance );
  22647. }
  22648. }
  22649. }
  22650. return object;
  22651. }
  22652. } );
  22653. var TEXTURE_MAPPING = {
  22654. UVMapping: UVMapping,
  22655. CubeReflectionMapping: CubeReflectionMapping,
  22656. CubeRefractionMapping: CubeRefractionMapping,
  22657. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  22658. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  22659. SphericalReflectionMapping: SphericalReflectionMapping,
  22660. CubeUVReflectionMapping: CubeUVReflectionMapping,
  22661. CubeUVRefractionMapping: CubeUVRefractionMapping
  22662. };
  22663. var TEXTURE_WRAPPING = {
  22664. RepeatWrapping: RepeatWrapping,
  22665. ClampToEdgeWrapping: ClampToEdgeWrapping,
  22666. MirroredRepeatWrapping: MirroredRepeatWrapping
  22667. };
  22668. var TEXTURE_FILTER = {
  22669. NearestFilter: NearestFilter,
  22670. NearestMipMapNearestFilter: NearestMipMapNearestFilter,
  22671. NearestMipMapLinearFilter: NearestMipMapLinearFilter,
  22672. LinearFilter: LinearFilter,
  22673. LinearMipMapNearestFilter: LinearMipMapNearestFilter,
  22674. LinearMipMapLinearFilter: LinearMipMapLinearFilter
  22675. };
  22676. /**
  22677. * @author thespite / http://clicktorelease.com/
  22678. */
  22679. function ImageBitmapLoader( manager ) {
  22680. if ( typeof createImageBitmap === 'undefined' ) {
  22681. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  22682. }
  22683. if ( typeof fetch === 'undefined' ) {
  22684. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  22685. }
  22686. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  22687. this.options = undefined;
  22688. }
  22689. ImageBitmapLoader.prototype = {
  22690. constructor: ImageBitmapLoader,
  22691. setOptions: function setOptions( options ) {
  22692. this.options = options;
  22693. return this;
  22694. },
  22695. load: function ( url, onLoad, onProgress, onError ) {
  22696. if ( url === undefined ) url = '';
  22697. if ( this.path !== undefined ) url = this.path + url;
  22698. url = this.manager.resolveURL( url );
  22699. var scope = this;
  22700. var cached = Cache.get( url );
  22701. if ( cached !== undefined ) {
  22702. scope.manager.itemStart( url );
  22703. setTimeout( function () {
  22704. if ( onLoad ) onLoad( cached );
  22705. scope.manager.itemEnd( url );
  22706. }, 0 );
  22707. return cached;
  22708. }
  22709. fetch( url ).then( function ( res ) {
  22710. return res.blob();
  22711. } ).then( function ( blob ) {
  22712. return createImageBitmap( blob, scope.options );
  22713. } ).then( function ( imageBitmap ) {
  22714. Cache.add( url, imageBitmap );
  22715. if ( onLoad ) onLoad( imageBitmap );
  22716. scope.manager.itemEnd( url );
  22717. } ).catch( function ( e ) {
  22718. if ( onError ) onError( e );
  22719. scope.manager.itemEnd( url );
  22720. scope.manager.itemError( url );
  22721. } );
  22722. },
  22723. setCrossOrigin: function ( /* value */ ) {
  22724. return this;
  22725. },
  22726. setPath: function ( value ) {
  22727. this.path = value;
  22728. return this;
  22729. }
  22730. };
  22731. /**
  22732. * @author zz85 / http://www.lab4games.net/zz85/blog
  22733. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  22734. **/
  22735. function ShapePath() {
  22736. this.type = 'ShapePath';
  22737. this.color = new Color();
  22738. this.subPaths = [];
  22739. this.currentPath = null;
  22740. }
  22741. Object.assign( ShapePath.prototype, {
  22742. moveTo: function ( x, y ) {
  22743. this.currentPath = new Path();
  22744. this.subPaths.push( this.currentPath );
  22745. this.currentPath.moveTo( x, y );
  22746. },
  22747. lineTo: function ( x, y ) {
  22748. this.currentPath.lineTo( x, y );
  22749. },
  22750. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  22751. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  22752. },
  22753. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  22754. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  22755. },
  22756. splineThru: function ( pts ) {
  22757. this.currentPath.splineThru( pts );
  22758. },
  22759. toShapes: function ( isCCW, noHoles ) {
  22760. function toShapesNoHoles( inSubpaths ) {
  22761. var shapes = [];
  22762. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  22763. var tmpPath = inSubpaths[ i ];
  22764. var tmpShape = new Shape();
  22765. tmpShape.curves = tmpPath.curves;
  22766. shapes.push( tmpShape );
  22767. }
  22768. return shapes;
  22769. }
  22770. function isPointInsidePolygon( inPt, inPolygon ) {
  22771. var polyLen = inPolygon.length;
  22772. // inPt on polygon contour => immediate success or
  22773. // toggling of inside/outside at every single! intersection point of an edge
  22774. // with the horizontal line through inPt, left of inPt
  22775. // not counting lowerY endpoints of edges and whole edges on that line
  22776. var inside = false;
  22777. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  22778. var edgeLowPt = inPolygon[ p ];
  22779. var edgeHighPt = inPolygon[ q ];
  22780. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  22781. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  22782. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  22783. // not parallel
  22784. if ( edgeDy < 0 ) {
  22785. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  22786. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  22787. }
  22788. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  22789. if ( inPt.y === edgeLowPt.y ) {
  22790. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  22791. // continue; // no intersection or edgeLowPt => doesn't count !!!
  22792. } else {
  22793. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  22794. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  22795. if ( perpEdge < 0 ) continue;
  22796. inside = ! inside; // true intersection left of inPt
  22797. }
  22798. } else {
  22799. // parallel or collinear
  22800. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  22801. // edge lies on the same horizontal line as inPt
  22802. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  22803. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  22804. // continue;
  22805. }
  22806. }
  22807. return inside;
  22808. }
  22809. var isClockWise = ShapeUtils.isClockWise;
  22810. var subPaths = this.subPaths;
  22811. if ( subPaths.length === 0 ) return [];
  22812. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  22813. var solid, tmpPath, tmpShape, shapes = [];
  22814. if ( subPaths.length === 1 ) {
  22815. tmpPath = subPaths[ 0 ];
  22816. tmpShape = new Shape();
  22817. tmpShape.curves = tmpPath.curves;
  22818. shapes.push( tmpShape );
  22819. return shapes;
  22820. }
  22821. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  22822. holesFirst = isCCW ? ! holesFirst : holesFirst;
  22823. // console.log("Holes first", holesFirst);
  22824. var betterShapeHoles = [];
  22825. var newShapes = [];
  22826. var newShapeHoles = [];
  22827. var mainIdx = 0;
  22828. var tmpPoints;
  22829. newShapes[ mainIdx ] = undefined;
  22830. newShapeHoles[ mainIdx ] = [];
  22831. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  22832. tmpPath = subPaths[ i ];
  22833. tmpPoints = tmpPath.getPoints();
  22834. solid = isClockWise( tmpPoints );
  22835. solid = isCCW ? ! solid : solid;
  22836. if ( solid ) {
  22837. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  22838. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  22839. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  22840. if ( holesFirst ) mainIdx ++;
  22841. newShapeHoles[ mainIdx ] = [];
  22842. //console.log('cw', i);
  22843. } else {
  22844. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  22845. //console.log('ccw', i);
  22846. }
  22847. }
  22848. // only Holes? -> probably all Shapes with wrong orientation
  22849. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  22850. if ( newShapes.length > 1 ) {
  22851. var ambiguous = false;
  22852. var toChange = [];
  22853. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  22854. betterShapeHoles[ sIdx ] = [];
  22855. }
  22856. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  22857. var sho = newShapeHoles[ sIdx ];
  22858. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  22859. var ho = sho[ hIdx ];
  22860. var hole_unassigned = true;
  22861. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  22862. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  22863. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  22864. if ( hole_unassigned ) {
  22865. hole_unassigned = false;
  22866. betterShapeHoles[ s2Idx ].push( ho );
  22867. } else {
  22868. ambiguous = true;
  22869. }
  22870. }
  22871. }
  22872. if ( hole_unassigned ) {
  22873. betterShapeHoles[ sIdx ].push( ho );
  22874. }
  22875. }
  22876. }
  22877. // console.log("ambiguous: ", ambiguous);
  22878. if ( toChange.length > 0 ) {
  22879. // console.log("to change: ", toChange);
  22880. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  22881. }
  22882. }
  22883. var tmpHoles;
  22884. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  22885. tmpShape = newShapes[ i ].s;
  22886. shapes.push( tmpShape );
  22887. tmpHoles = newShapeHoles[ i ];
  22888. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  22889. tmpShape.holes.push( tmpHoles[ j ].h );
  22890. }
  22891. }
  22892. //console.log("shape", shapes);
  22893. return shapes;
  22894. }
  22895. } );
  22896. /**
  22897. * @author zz85 / http://www.lab4games.net/zz85/blog
  22898. * @author mrdoob / http://mrdoob.com/
  22899. */
  22900. function Font( data ) {
  22901. this.type = 'Font';
  22902. this.data = data;
  22903. }
  22904. Object.assign( Font.prototype, {
  22905. isFont: true,
  22906. generateShapes: function ( text, size, divisions ) {
  22907. if ( size === undefined ) size = 100;
  22908. if ( divisions === undefined ) divisions = 4;
  22909. var shapes = [];
  22910. var paths = createPaths( text, size, divisions, this.data );
  22911. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  22912. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  22913. }
  22914. return shapes;
  22915. }
  22916. } );
  22917. function createPaths( text, size, divisions, data ) {
  22918. var chars = Array.from ? Array.from( text ) : String( text ).split( '' ); // see #13988
  22919. var scale = size / data.resolution;
  22920. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  22921. var paths = [];
  22922. var offsetX = 0, offsetY = 0;
  22923. for ( var i = 0; i < chars.length; i ++ ) {
  22924. var char = chars[ i ];
  22925. if ( char === '\n' ) {
  22926. offsetX = 0;
  22927. offsetY -= line_height;
  22928. } else {
  22929. var ret = createPath( char, divisions, scale, offsetX, offsetY, data );
  22930. offsetX += ret.offsetX;
  22931. paths.push( ret.path );
  22932. }
  22933. }
  22934. return paths;
  22935. }
  22936. function createPath( char, divisions, scale, offsetX, offsetY, data ) {
  22937. var glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  22938. if ( ! glyph ) return;
  22939. var path = new ShapePath();
  22940. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  22941. if ( glyph.o ) {
  22942. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  22943. for ( var i = 0, l = outline.length; i < l; ) {
  22944. var action = outline[ i ++ ];
  22945. switch ( action ) {
  22946. case 'm': // moveTo
  22947. x = outline[ i ++ ] * scale + offsetX;
  22948. y = outline[ i ++ ] * scale + offsetY;
  22949. path.moveTo( x, y );
  22950. break;
  22951. case 'l': // lineTo
  22952. x = outline[ i ++ ] * scale + offsetX;
  22953. y = outline[ i ++ ] * scale + offsetY;
  22954. path.lineTo( x, y );
  22955. break;
  22956. case 'q': // quadraticCurveTo
  22957. cpx = outline[ i ++ ] * scale + offsetX;
  22958. cpy = outline[ i ++ ] * scale + offsetY;
  22959. cpx1 = outline[ i ++ ] * scale + offsetX;
  22960. cpy1 = outline[ i ++ ] * scale + offsetY;
  22961. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  22962. break;
  22963. case 'b': // bezierCurveTo
  22964. cpx = outline[ i ++ ] * scale + offsetX;
  22965. cpy = outline[ i ++ ] * scale + offsetY;
  22966. cpx1 = outline[ i ++ ] * scale + offsetX;
  22967. cpy1 = outline[ i ++ ] * scale + offsetY;
  22968. cpx2 = outline[ i ++ ] * scale + offsetX;
  22969. cpy2 = outline[ i ++ ] * scale + offsetY;
  22970. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  22971. break;
  22972. }
  22973. }
  22974. }
  22975. return { offsetX: glyph.ha * scale, path: path };
  22976. }
  22977. /**
  22978. * @author mrdoob / http://mrdoob.com/
  22979. */
  22980. function FontLoader( manager ) {
  22981. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22982. }
  22983. Object.assign( FontLoader.prototype, {
  22984. load: function ( url, onLoad, onProgress, onError ) {
  22985. var scope = this;
  22986. var loader = new FileLoader( this.manager );
  22987. loader.setPath( this.path );
  22988. loader.load( url, function ( text ) {
  22989. var json;
  22990. try {
  22991. json = JSON.parse( text );
  22992. } catch ( e ) {
  22993. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  22994. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  22995. }
  22996. var font = scope.parse( json );
  22997. if ( onLoad ) onLoad( font );
  22998. }, onProgress, onError );
  22999. },
  23000. parse: function ( json ) {
  23001. return new Font( json );
  23002. },
  23003. setPath: function ( value ) {
  23004. this.path = value;
  23005. return this;
  23006. }
  23007. } );
  23008. /**
  23009. * @author mrdoob / http://mrdoob.com/
  23010. */
  23011. var context;
  23012. var AudioContext = {
  23013. getContext: function () {
  23014. if ( context === undefined ) {
  23015. context = new ( window.AudioContext || window.webkitAudioContext )();
  23016. }
  23017. return context;
  23018. },
  23019. setContext: function ( value ) {
  23020. context = value;
  23021. }
  23022. };
  23023. /**
  23024. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  23025. */
  23026. function AudioLoader( manager ) {
  23027. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23028. }
  23029. Object.assign( AudioLoader.prototype, {
  23030. load: function ( url, onLoad, onProgress, onError ) {
  23031. var loader = new FileLoader( this.manager );
  23032. loader.setResponseType( 'arraybuffer' );
  23033. loader.load( url, function ( buffer ) {
  23034. var context = AudioContext.getContext();
  23035. context.decodeAudioData( buffer, function ( audioBuffer ) {
  23036. onLoad( audioBuffer );
  23037. } );
  23038. }, onProgress, onError );
  23039. }
  23040. } );
  23041. /**
  23042. * @author mrdoob / http://mrdoob.com/
  23043. */
  23044. function StereoCamera() {
  23045. this.type = 'StereoCamera';
  23046. this.aspect = 1;
  23047. this.eyeSep = 0.064;
  23048. this.cameraL = new PerspectiveCamera();
  23049. this.cameraL.layers.enable( 1 );
  23050. this.cameraL.matrixAutoUpdate = false;
  23051. this.cameraR = new PerspectiveCamera();
  23052. this.cameraR.layers.enable( 2 );
  23053. this.cameraR.matrixAutoUpdate = false;
  23054. }
  23055. Object.assign( StereoCamera.prototype, {
  23056. update: ( function () {
  23057. var instance, focus, fov, aspect, near, far, zoom, eyeSep;
  23058. var eyeRight = new Matrix4();
  23059. var eyeLeft = new Matrix4();
  23060. return function update( camera ) {
  23061. var needsUpdate = instance !== this || focus !== camera.focus || fov !== camera.fov ||
  23062. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  23063. far !== camera.far || zoom !== camera.zoom || eyeSep !== this.eyeSep;
  23064. if ( needsUpdate ) {
  23065. instance = this;
  23066. focus = camera.focus;
  23067. fov = camera.fov;
  23068. aspect = camera.aspect * this.aspect;
  23069. near = camera.near;
  23070. far = camera.far;
  23071. zoom = camera.zoom;
  23072. // Off-axis stereoscopic effect based on
  23073. // http://paulbourke.net/stereographics/stereorender/
  23074. var projectionMatrix = camera.projectionMatrix.clone();
  23075. eyeSep = this.eyeSep / 2;
  23076. var eyeSepOnProjection = eyeSep * near / focus;
  23077. var ymax = ( near * Math.tan( _Math.DEG2RAD * fov * 0.5 ) ) / zoom;
  23078. var xmin, xmax;
  23079. // translate xOffset
  23080. eyeLeft.elements[ 12 ] = - eyeSep;
  23081. eyeRight.elements[ 12 ] = eyeSep;
  23082. // for left eye
  23083. xmin = - ymax * aspect + eyeSepOnProjection;
  23084. xmax = ymax * aspect + eyeSepOnProjection;
  23085. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  23086. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  23087. this.cameraL.projectionMatrix.copy( projectionMatrix );
  23088. // for right eye
  23089. xmin = - ymax * aspect - eyeSepOnProjection;
  23090. xmax = ymax * aspect - eyeSepOnProjection;
  23091. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  23092. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  23093. this.cameraR.projectionMatrix.copy( projectionMatrix );
  23094. }
  23095. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  23096. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  23097. };
  23098. } )()
  23099. } );
  23100. /**
  23101. * Camera for rendering cube maps
  23102. * - renders scene into axis-aligned cube
  23103. *
  23104. * @author alteredq / http://alteredqualia.com/
  23105. */
  23106. function CubeCamera( near, far, cubeResolution ) {
  23107. Object3D.call( this );
  23108. this.type = 'CubeCamera';
  23109. var fov = 90, aspect = 1;
  23110. var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  23111. cameraPX.up.set( 0, - 1, 0 );
  23112. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  23113. this.add( cameraPX );
  23114. var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  23115. cameraNX.up.set( 0, - 1, 0 );
  23116. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  23117. this.add( cameraNX );
  23118. var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  23119. cameraPY.up.set( 0, 0, 1 );
  23120. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  23121. this.add( cameraPY );
  23122. var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  23123. cameraNY.up.set( 0, 0, - 1 );
  23124. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  23125. this.add( cameraNY );
  23126. var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  23127. cameraPZ.up.set( 0, - 1, 0 );
  23128. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  23129. this.add( cameraPZ );
  23130. var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  23131. cameraNZ.up.set( 0, - 1, 0 );
  23132. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  23133. this.add( cameraNZ );
  23134. var options = { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
  23135. this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  23136. this.renderTarget.texture.name = "CubeCamera";
  23137. this.update = function ( renderer, scene ) {
  23138. if ( this.parent === null ) this.updateMatrixWorld();
  23139. var renderTarget = this.renderTarget;
  23140. var generateMipmaps = renderTarget.texture.generateMipmaps;
  23141. renderTarget.texture.generateMipmaps = false;
  23142. renderTarget.activeCubeFace = 0;
  23143. renderer.render( scene, cameraPX, renderTarget );
  23144. renderTarget.activeCubeFace = 1;
  23145. renderer.render( scene, cameraNX, renderTarget );
  23146. renderTarget.activeCubeFace = 2;
  23147. renderer.render( scene, cameraPY, renderTarget );
  23148. renderTarget.activeCubeFace = 3;
  23149. renderer.render( scene, cameraNY, renderTarget );
  23150. renderTarget.activeCubeFace = 4;
  23151. renderer.render( scene, cameraPZ, renderTarget );
  23152. renderTarget.texture.generateMipmaps = generateMipmaps;
  23153. renderTarget.activeCubeFace = 5;
  23154. renderer.render( scene, cameraNZ, renderTarget );
  23155. renderer.setRenderTarget( null );
  23156. };
  23157. this.clear = function ( renderer, color, depth, stencil ) {
  23158. var renderTarget = this.renderTarget;
  23159. for ( var i = 0; i < 6; i ++ ) {
  23160. renderTarget.activeCubeFace = i;
  23161. renderer.setRenderTarget( renderTarget );
  23162. renderer.clear( color, depth, stencil );
  23163. }
  23164. renderer.setRenderTarget( null );
  23165. };
  23166. }
  23167. CubeCamera.prototype = Object.create( Object3D.prototype );
  23168. CubeCamera.prototype.constructor = CubeCamera;
  23169. /**
  23170. * @author mrdoob / http://mrdoob.com/
  23171. */
  23172. function AudioListener() {
  23173. Object3D.call( this );
  23174. this.type = 'AudioListener';
  23175. this.context = AudioContext.getContext();
  23176. this.gain = this.context.createGain();
  23177. this.gain.connect( this.context.destination );
  23178. this.filter = null;
  23179. }
  23180. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  23181. constructor: AudioListener,
  23182. getInput: function () {
  23183. return this.gain;
  23184. },
  23185. removeFilter: function ( ) {
  23186. if ( this.filter !== null ) {
  23187. this.gain.disconnect( this.filter );
  23188. this.filter.disconnect( this.context.destination );
  23189. this.gain.connect( this.context.destination );
  23190. this.filter = null;
  23191. }
  23192. },
  23193. getFilter: function () {
  23194. return this.filter;
  23195. },
  23196. setFilter: function ( value ) {
  23197. if ( this.filter !== null ) {
  23198. this.gain.disconnect( this.filter );
  23199. this.filter.disconnect( this.context.destination );
  23200. } else {
  23201. this.gain.disconnect( this.context.destination );
  23202. }
  23203. this.filter = value;
  23204. this.gain.connect( this.filter );
  23205. this.filter.connect( this.context.destination );
  23206. },
  23207. getMasterVolume: function () {
  23208. return this.gain.gain.value;
  23209. },
  23210. setMasterVolume: function ( value ) {
  23211. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  23212. },
  23213. updateMatrixWorld: ( function () {
  23214. var position = new Vector3();
  23215. var quaternion = new Quaternion();
  23216. var scale = new Vector3();
  23217. var orientation = new Vector3();
  23218. return function updateMatrixWorld( force ) {
  23219. Object3D.prototype.updateMatrixWorld.call( this, force );
  23220. var listener = this.context.listener;
  23221. var up = this.up;
  23222. this.matrixWorld.decompose( position, quaternion, scale );
  23223. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  23224. if ( listener.positionX ) {
  23225. listener.positionX.setValueAtTime( position.x, this.context.currentTime );
  23226. listener.positionY.setValueAtTime( position.y, this.context.currentTime );
  23227. listener.positionZ.setValueAtTime( position.z, this.context.currentTime );
  23228. listener.forwardX.setValueAtTime( orientation.x, this.context.currentTime );
  23229. listener.forwardY.setValueAtTime( orientation.y, this.context.currentTime );
  23230. listener.forwardZ.setValueAtTime( orientation.z, this.context.currentTime );
  23231. listener.upX.setValueAtTime( up.x, this.context.currentTime );
  23232. listener.upY.setValueAtTime( up.y, this.context.currentTime );
  23233. listener.upZ.setValueAtTime( up.z, this.context.currentTime );
  23234. } else {
  23235. listener.setPosition( position.x, position.y, position.z );
  23236. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  23237. }
  23238. };
  23239. } )()
  23240. } );
  23241. /**
  23242. * @author mrdoob / http://mrdoob.com/
  23243. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  23244. */
  23245. function Audio( listener ) {
  23246. Object3D.call( this );
  23247. this.type = 'Audio';
  23248. this.context = listener.context;
  23249. this.gain = this.context.createGain();
  23250. this.gain.connect( listener.getInput() );
  23251. this.autoplay = false;
  23252. this.buffer = null;
  23253. this.loop = false;
  23254. this.startTime = 0;
  23255. this.offset = 0;
  23256. this.playbackRate = 1;
  23257. this.isPlaying = false;
  23258. this.hasPlaybackControl = true;
  23259. this.sourceType = 'empty';
  23260. this.filters = [];
  23261. }
  23262. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  23263. constructor: Audio,
  23264. getOutput: function () {
  23265. return this.gain;
  23266. },
  23267. setNodeSource: function ( audioNode ) {
  23268. this.hasPlaybackControl = false;
  23269. this.sourceType = 'audioNode';
  23270. this.source = audioNode;
  23271. this.connect();
  23272. return this;
  23273. },
  23274. setMediaElementSource: function ( mediaElement ) {
  23275. this.hasPlaybackControl = false;
  23276. this.sourceType = 'mediaNode';
  23277. this.source = this.context.createMediaElementSource( mediaElement );
  23278. this.connect();
  23279. return this;
  23280. },
  23281. setBuffer: function ( audioBuffer ) {
  23282. this.buffer = audioBuffer;
  23283. this.sourceType = 'buffer';
  23284. if ( this.autoplay ) this.play();
  23285. return this;
  23286. },
  23287. play: function () {
  23288. if ( this.isPlaying === true ) {
  23289. console.warn( 'THREE.Audio: Audio is already playing.' );
  23290. return;
  23291. }
  23292. if ( this.hasPlaybackControl === false ) {
  23293. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  23294. return;
  23295. }
  23296. var source = this.context.createBufferSource();
  23297. source.buffer = this.buffer;
  23298. source.loop = this.loop;
  23299. source.onended = this.onEnded.bind( this );
  23300. source.playbackRate.setValueAtTime( this.playbackRate, this.startTime );
  23301. this.startTime = this.context.currentTime;
  23302. source.start( this.startTime, this.offset );
  23303. this.isPlaying = true;
  23304. this.source = source;
  23305. return this.connect();
  23306. },
  23307. pause: function () {
  23308. if ( this.hasPlaybackControl === false ) {
  23309. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  23310. return;
  23311. }
  23312. if ( this.isPlaying === true ) {
  23313. this.source.stop();
  23314. this.offset += ( this.context.currentTime - this.startTime ) * this.playbackRate;
  23315. this.isPlaying = false;
  23316. }
  23317. return this;
  23318. },
  23319. stop: function () {
  23320. if ( this.hasPlaybackControl === false ) {
  23321. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  23322. return;
  23323. }
  23324. this.source.stop();
  23325. this.offset = 0;
  23326. this.isPlaying = false;
  23327. return this;
  23328. },
  23329. connect: function () {
  23330. if ( this.filters.length > 0 ) {
  23331. this.source.connect( this.filters[ 0 ] );
  23332. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  23333. this.filters[ i - 1 ].connect( this.filters[ i ] );
  23334. }
  23335. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  23336. } else {
  23337. this.source.connect( this.getOutput() );
  23338. }
  23339. return this;
  23340. },
  23341. disconnect: function () {
  23342. if ( this.filters.length > 0 ) {
  23343. this.source.disconnect( this.filters[ 0 ] );
  23344. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  23345. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  23346. }
  23347. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  23348. } else {
  23349. this.source.disconnect( this.getOutput() );
  23350. }
  23351. return this;
  23352. },
  23353. getFilters: function () {
  23354. return this.filters;
  23355. },
  23356. setFilters: function ( value ) {
  23357. if ( ! value ) value = [];
  23358. if ( this.isPlaying === true ) {
  23359. this.disconnect();
  23360. this.filters = value;
  23361. this.connect();
  23362. } else {
  23363. this.filters = value;
  23364. }
  23365. return this;
  23366. },
  23367. getFilter: function () {
  23368. return this.getFilters()[ 0 ];
  23369. },
  23370. setFilter: function ( filter ) {
  23371. return this.setFilters( filter ? [ filter ] : [] );
  23372. },
  23373. setPlaybackRate: function ( value ) {
  23374. if ( this.hasPlaybackControl === false ) {
  23375. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  23376. return;
  23377. }
  23378. this.playbackRate = value;
  23379. if ( this.isPlaying === true ) {
  23380. this.source.playbackRate.setValueAtTime( this.playbackRate, this.context.currentTime );
  23381. }
  23382. return this;
  23383. },
  23384. getPlaybackRate: function () {
  23385. return this.playbackRate;
  23386. },
  23387. onEnded: function () {
  23388. this.isPlaying = false;
  23389. },
  23390. getLoop: function () {
  23391. if ( this.hasPlaybackControl === false ) {
  23392. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  23393. return false;
  23394. }
  23395. return this.loop;
  23396. },
  23397. setLoop: function ( value ) {
  23398. if ( this.hasPlaybackControl === false ) {
  23399. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  23400. return;
  23401. }
  23402. this.loop = value;
  23403. if ( this.isPlaying === true ) {
  23404. this.source.loop = this.loop;
  23405. }
  23406. return this;
  23407. },
  23408. getVolume: function () {
  23409. return this.gain.gain.value;
  23410. },
  23411. setVolume: function ( value ) {
  23412. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  23413. return this;
  23414. }
  23415. } );
  23416. /**
  23417. * @author mrdoob / http://mrdoob.com/
  23418. */
  23419. function PositionalAudio( listener ) {
  23420. Audio.call( this, listener );
  23421. this.panner = this.context.createPanner();
  23422. this.panner.connect( this.gain );
  23423. }
  23424. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  23425. constructor: PositionalAudio,
  23426. getOutput: function () {
  23427. return this.panner;
  23428. },
  23429. getRefDistance: function () {
  23430. return this.panner.refDistance;
  23431. },
  23432. setRefDistance: function ( value ) {
  23433. this.panner.refDistance = value;
  23434. },
  23435. getRolloffFactor: function () {
  23436. return this.panner.rolloffFactor;
  23437. },
  23438. setRolloffFactor: function ( value ) {
  23439. this.panner.rolloffFactor = value;
  23440. },
  23441. getDistanceModel: function () {
  23442. return this.panner.distanceModel;
  23443. },
  23444. setDistanceModel: function ( value ) {
  23445. this.panner.distanceModel = value;
  23446. },
  23447. getMaxDistance: function () {
  23448. return this.panner.maxDistance;
  23449. },
  23450. setMaxDistance: function ( value ) {
  23451. this.panner.maxDistance = value;
  23452. },
  23453. updateMatrixWorld: ( function () {
  23454. var position = new Vector3();
  23455. return function updateMatrixWorld( force ) {
  23456. Object3D.prototype.updateMatrixWorld.call( this, force );
  23457. position.setFromMatrixPosition( this.matrixWorld );
  23458. this.panner.setPosition( position.x, position.y, position.z );
  23459. };
  23460. } )()
  23461. } );
  23462. /**
  23463. * @author mrdoob / http://mrdoob.com/
  23464. */
  23465. function AudioAnalyser( audio, fftSize ) {
  23466. this.analyser = audio.context.createAnalyser();
  23467. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  23468. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  23469. audio.getOutput().connect( this.analyser );
  23470. }
  23471. Object.assign( AudioAnalyser.prototype, {
  23472. getFrequencyData: function () {
  23473. this.analyser.getByteFrequencyData( this.data );
  23474. return this.data;
  23475. },
  23476. getAverageFrequency: function () {
  23477. var value = 0, data = this.getFrequencyData();
  23478. for ( var i = 0; i < data.length; i ++ ) {
  23479. value += data[ i ];
  23480. }
  23481. return value / data.length;
  23482. }
  23483. } );
  23484. /**
  23485. *
  23486. * Buffered scene graph property that allows weighted accumulation.
  23487. *
  23488. *
  23489. * @author Ben Houston / http://clara.io/
  23490. * @author David Sarno / http://lighthaus.us/
  23491. * @author tschw
  23492. */
  23493. function PropertyMixer( binding, typeName, valueSize ) {
  23494. this.binding = binding;
  23495. this.valueSize = valueSize;
  23496. var bufferType = Float64Array,
  23497. mixFunction;
  23498. switch ( typeName ) {
  23499. case 'quaternion':
  23500. mixFunction = this._slerp;
  23501. break;
  23502. case 'string':
  23503. case 'bool':
  23504. bufferType = Array;
  23505. mixFunction = this._select;
  23506. break;
  23507. default:
  23508. mixFunction = this._lerp;
  23509. }
  23510. this.buffer = new bufferType( valueSize * 4 );
  23511. // layout: [ incoming | accu0 | accu1 | orig ]
  23512. //
  23513. // interpolators can use .buffer as their .result
  23514. // the data then goes to 'incoming'
  23515. //
  23516. // 'accu0' and 'accu1' are used frame-interleaved for
  23517. // the cumulative result and are compared to detect
  23518. // changes
  23519. //
  23520. // 'orig' stores the original state of the property
  23521. this._mixBufferRegion = mixFunction;
  23522. this.cumulativeWeight = 0;
  23523. this.useCount = 0;
  23524. this.referenceCount = 0;
  23525. }
  23526. Object.assign( PropertyMixer.prototype, {
  23527. // accumulate data in the 'incoming' region into 'accu<i>'
  23528. accumulate: function ( accuIndex, weight ) {
  23529. // note: happily accumulating nothing when weight = 0, the caller knows
  23530. // the weight and shouldn't have made the call in the first place
  23531. var buffer = this.buffer,
  23532. stride = this.valueSize,
  23533. offset = accuIndex * stride + stride,
  23534. currentWeight = this.cumulativeWeight;
  23535. if ( currentWeight === 0 ) {
  23536. // accuN := incoming * weight
  23537. for ( var i = 0; i !== stride; ++ i ) {
  23538. buffer[ offset + i ] = buffer[ i ];
  23539. }
  23540. currentWeight = weight;
  23541. } else {
  23542. // accuN := accuN + incoming * weight
  23543. currentWeight += weight;
  23544. var mix = weight / currentWeight;
  23545. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  23546. }
  23547. this.cumulativeWeight = currentWeight;
  23548. },
  23549. // apply the state of 'accu<i>' to the binding when accus differ
  23550. apply: function ( accuIndex ) {
  23551. var stride = this.valueSize,
  23552. buffer = this.buffer,
  23553. offset = accuIndex * stride + stride,
  23554. weight = this.cumulativeWeight,
  23555. binding = this.binding;
  23556. this.cumulativeWeight = 0;
  23557. if ( weight < 1 ) {
  23558. // accuN := accuN + original * ( 1 - cumulativeWeight )
  23559. var originalValueOffset = stride * 3;
  23560. this._mixBufferRegion(
  23561. buffer, offset, originalValueOffset, 1 - weight, stride );
  23562. }
  23563. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  23564. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  23565. // value has changed -> update scene graph
  23566. binding.setValue( buffer, offset );
  23567. break;
  23568. }
  23569. }
  23570. },
  23571. // remember the state of the bound property and copy it to both accus
  23572. saveOriginalState: function () {
  23573. var binding = this.binding;
  23574. var buffer = this.buffer,
  23575. stride = this.valueSize,
  23576. originalValueOffset = stride * 3;
  23577. binding.getValue( buffer, originalValueOffset );
  23578. // accu[0..1] := orig -- initially detect changes against the original
  23579. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  23580. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  23581. }
  23582. this.cumulativeWeight = 0;
  23583. },
  23584. // apply the state previously taken via 'saveOriginalState' to the binding
  23585. restoreOriginalState: function () {
  23586. var originalValueOffset = this.valueSize * 3;
  23587. this.binding.setValue( this.buffer, originalValueOffset );
  23588. },
  23589. // mix functions
  23590. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  23591. if ( t >= 0.5 ) {
  23592. for ( var i = 0; i !== stride; ++ i ) {
  23593. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  23594. }
  23595. }
  23596. },
  23597. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  23598. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  23599. },
  23600. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  23601. var s = 1 - t;
  23602. for ( var i = 0; i !== stride; ++ i ) {
  23603. var j = dstOffset + i;
  23604. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  23605. }
  23606. }
  23607. } );
  23608. /**
  23609. *
  23610. * A reference to a real property in the scene graph.
  23611. *
  23612. *
  23613. * @author Ben Houston / http://clara.io/
  23614. * @author David Sarno / http://lighthaus.us/
  23615. * @author tschw
  23616. */
  23617. // Characters [].:/ are reserved for track binding syntax.
  23618. var RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  23619. function Composite( targetGroup, path, optionalParsedPath ) {
  23620. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  23621. this._targetGroup = targetGroup;
  23622. this._bindings = targetGroup.subscribe_( path, parsedPath );
  23623. }
  23624. Object.assign( Composite.prototype, {
  23625. getValue: function ( array, offset ) {
  23626. this.bind(); // bind all binding
  23627. var firstValidIndex = this._targetGroup.nCachedObjects_,
  23628. binding = this._bindings[ firstValidIndex ];
  23629. // and only call .getValue on the first
  23630. if ( binding !== undefined ) binding.getValue( array, offset );
  23631. },
  23632. setValue: function ( array, offset ) {
  23633. var bindings = this._bindings;
  23634. for ( var i = this._targetGroup.nCachedObjects_,
  23635. n = bindings.length; i !== n; ++ i ) {
  23636. bindings[ i ].setValue( array, offset );
  23637. }
  23638. },
  23639. bind: function () {
  23640. var bindings = this._bindings;
  23641. for ( var i = this._targetGroup.nCachedObjects_,
  23642. n = bindings.length; i !== n; ++ i ) {
  23643. bindings[ i ].bind();
  23644. }
  23645. },
  23646. unbind: function () {
  23647. var bindings = this._bindings;
  23648. for ( var i = this._targetGroup.nCachedObjects_,
  23649. n = bindings.length; i !== n; ++ i ) {
  23650. bindings[ i ].unbind();
  23651. }
  23652. }
  23653. } );
  23654. function PropertyBinding( rootNode, path, parsedPath ) {
  23655. this.path = path;
  23656. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  23657. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  23658. this.rootNode = rootNode;
  23659. }
  23660. Object.assign( PropertyBinding, {
  23661. Composite: Composite,
  23662. create: function ( root, path, parsedPath ) {
  23663. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  23664. return new PropertyBinding( root, path, parsedPath );
  23665. } else {
  23666. return new PropertyBinding.Composite( root, path, parsedPath );
  23667. }
  23668. },
  23669. /**
  23670. * Replaces spaces with underscores and removes unsupported characters from
  23671. * node names, to ensure compatibility with parseTrackName().
  23672. *
  23673. * @param {string} name Node name to be sanitized.
  23674. * @return {string}
  23675. */
  23676. sanitizeNodeName: ( function () {
  23677. var reservedRe = new RegExp( '[' + RESERVED_CHARS_RE + ']', 'g' );
  23678. return function sanitizeNodeName( name ) {
  23679. return name.replace( /\s/g, '_' ).replace( reservedRe, '' );
  23680. };
  23681. }() ),
  23682. parseTrackName: function () {
  23683. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  23684. // only latin characters, and the unicode \p{L} is not yet supported. So
  23685. // instead, we exclude reserved characters and match everything else.
  23686. var wordChar = '[^' + RESERVED_CHARS_RE + ']';
  23687. var wordCharOrDot = '[^' + RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  23688. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  23689. // be matched to parse the rest of the track name.
  23690. var directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', wordChar );
  23691. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  23692. var nodeRe = /(WCOD+)?/.source.replace( 'WCOD', wordCharOrDot );
  23693. // Object on target node, and accessor. May not contain reserved
  23694. // characters. Accessor may contain any character except closing bracket.
  23695. var objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', wordChar );
  23696. // Property and accessor. May not contain reserved characters. Accessor may
  23697. // contain any non-bracket characters.
  23698. var propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', wordChar );
  23699. var trackRe = new RegExp( ''
  23700. + '^'
  23701. + directoryRe
  23702. + nodeRe
  23703. + objectRe
  23704. + propertyRe
  23705. + '$'
  23706. );
  23707. var supportedObjectNames = [ 'material', 'materials', 'bones' ];
  23708. return function parseTrackName( trackName ) {
  23709. var matches = trackRe.exec( trackName );
  23710. if ( ! matches ) {
  23711. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  23712. }
  23713. var results = {
  23714. // directoryName: matches[ 1 ], // (tschw) currently unused
  23715. nodeName: matches[ 2 ],
  23716. objectName: matches[ 3 ],
  23717. objectIndex: matches[ 4 ],
  23718. propertyName: matches[ 5 ], // required
  23719. propertyIndex: matches[ 6 ]
  23720. };
  23721. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  23722. if ( lastDot !== undefined && lastDot !== - 1 ) {
  23723. var objectName = results.nodeName.substring( lastDot + 1 );
  23724. // Object names must be checked against a whitelist. Otherwise, there
  23725. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  23726. // 'bar' could be the objectName, or part of a nodeName (which can
  23727. // include '.' characters).
  23728. if ( supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  23729. results.nodeName = results.nodeName.substring( 0, lastDot );
  23730. results.objectName = objectName;
  23731. }
  23732. }
  23733. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  23734. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  23735. }
  23736. return results;
  23737. };
  23738. }(),
  23739. findNode: function ( root, nodeName ) {
  23740. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  23741. return root;
  23742. }
  23743. // search into skeleton bones.
  23744. if ( root.skeleton ) {
  23745. var bone = root.skeleton.getBoneByName( nodeName );
  23746. if ( bone !== undefined ) {
  23747. return bone;
  23748. }
  23749. }
  23750. // search into node subtree.
  23751. if ( root.children ) {
  23752. var searchNodeSubtree = function ( children ) {
  23753. for ( var i = 0; i < children.length; i ++ ) {
  23754. var childNode = children[ i ];
  23755. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  23756. return childNode;
  23757. }
  23758. var result = searchNodeSubtree( childNode.children );
  23759. if ( result ) return result;
  23760. }
  23761. return null;
  23762. };
  23763. var subTreeNode = searchNodeSubtree( root.children );
  23764. if ( subTreeNode ) {
  23765. return subTreeNode;
  23766. }
  23767. }
  23768. return null;
  23769. }
  23770. } );
  23771. Object.assign( PropertyBinding.prototype, { // prototype, continued
  23772. // these are used to "bind" a nonexistent property
  23773. _getValue_unavailable: function () {},
  23774. _setValue_unavailable: function () {},
  23775. BindingType: {
  23776. Direct: 0,
  23777. EntireArray: 1,
  23778. ArrayElement: 2,
  23779. HasFromToArray: 3
  23780. },
  23781. Versioning: {
  23782. None: 0,
  23783. NeedsUpdate: 1,
  23784. MatrixWorldNeedsUpdate: 2
  23785. },
  23786. GetterByBindingType: [
  23787. function getValue_direct( buffer, offset ) {
  23788. buffer[ offset ] = this.node[ this.propertyName ];
  23789. },
  23790. function getValue_array( buffer, offset ) {
  23791. var source = this.resolvedProperty;
  23792. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  23793. buffer[ offset ++ ] = source[ i ];
  23794. }
  23795. },
  23796. function getValue_arrayElement( buffer, offset ) {
  23797. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  23798. },
  23799. function getValue_toArray( buffer, offset ) {
  23800. this.resolvedProperty.toArray( buffer, offset );
  23801. }
  23802. ],
  23803. SetterByBindingTypeAndVersioning: [
  23804. [
  23805. // Direct
  23806. function setValue_direct( buffer, offset ) {
  23807. this.targetObject[ this.propertyName ] = buffer[ offset ];
  23808. },
  23809. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  23810. this.targetObject[ this.propertyName ] = buffer[ offset ];
  23811. this.targetObject.needsUpdate = true;
  23812. },
  23813. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  23814. this.targetObject[ this.propertyName ] = buffer[ offset ];
  23815. this.targetObject.matrixWorldNeedsUpdate = true;
  23816. }
  23817. ], [
  23818. // EntireArray
  23819. function setValue_array( buffer, offset ) {
  23820. var dest = this.resolvedProperty;
  23821. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  23822. dest[ i ] = buffer[ offset ++ ];
  23823. }
  23824. },
  23825. function setValue_array_setNeedsUpdate( buffer, offset ) {
  23826. var dest = this.resolvedProperty;
  23827. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  23828. dest[ i ] = buffer[ offset ++ ];
  23829. }
  23830. this.targetObject.needsUpdate = true;
  23831. },
  23832. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  23833. var dest = this.resolvedProperty;
  23834. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  23835. dest[ i ] = buffer[ offset ++ ];
  23836. }
  23837. this.targetObject.matrixWorldNeedsUpdate = true;
  23838. }
  23839. ], [
  23840. // ArrayElement
  23841. function setValue_arrayElement( buffer, offset ) {
  23842. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  23843. },
  23844. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  23845. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  23846. this.targetObject.needsUpdate = true;
  23847. },
  23848. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  23849. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  23850. this.targetObject.matrixWorldNeedsUpdate = true;
  23851. }
  23852. ], [
  23853. // HasToFromArray
  23854. function setValue_fromArray( buffer, offset ) {
  23855. this.resolvedProperty.fromArray( buffer, offset );
  23856. },
  23857. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  23858. this.resolvedProperty.fromArray( buffer, offset );
  23859. this.targetObject.needsUpdate = true;
  23860. },
  23861. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  23862. this.resolvedProperty.fromArray( buffer, offset );
  23863. this.targetObject.matrixWorldNeedsUpdate = true;
  23864. }
  23865. ]
  23866. ],
  23867. getValue: function getValue_unbound( targetArray, offset ) {
  23868. this.bind();
  23869. this.getValue( targetArray, offset );
  23870. // Note: This class uses a State pattern on a per-method basis:
  23871. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  23872. // prototype version of these methods with one that represents
  23873. // the bound state. When the property is not found, the methods
  23874. // become no-ops.
  23875. },
  23876. setValue: function getValue_unbound( sourceArray, offset ) {
  23877. this.bind();
  23878. this.setValue( sourceArray, offset );
  23879. },
  23880. // create getter / setter pair for a property in the scene graph
  23881. bind: function () {
  23882. var targetObject = this.node,
  23883. parsedPath = this.parsedPath,
  23884. objectName = parsedPath.objectName,
  23885. propertyName = parsedPath.propertyName,
  23886. propertyIndex = parsedPath.propertyIndex;
  23887. if ( ! targetObject ) {
  23888. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  23889. this.node = targetObject;
  23890. }
  23891. // set fail state so we can just 'return' on error
  23892. this.getValue = this._getValue_unavailable;
  23893. this.setValue = this._setValue_unavailable;
  23894. // ensure there is a value node
  23895. if ( ! targetObject ) {
  23896. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  23897. return;
  23898. }
  23899. if ( objectName ) {
  23900. var objectIndex = parsedPath.objectIndex;
  23901. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  23902. switch ( objectName ) {
  23903. case 'materials':
  23904. if ( ! targetObject.material ) {
  23905. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  23906. return;
  23907. }
  23908. if ( ! targetObject.material.materials ) {
  23909. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  23910. return;
  23911. }
  23912. targetObject = targetObject.material.materials;
  23913. break;
  23914. case 'bones':
  23915. if ( ! targetObject.skeleton ) {
  23916. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  23917. return;
  23918. }
  23919. // potential future optimization: skip this if propertyIndex is already an integer
  23920. // and convert the integer string to a true integer.
  23921. targetObject = targetObject.skeleton.bones;
  23922. // support resolving morphTarget names into indices.
  23923. for ( var i = 0; i < targetObject.length; i ++ ) {
  23924. if ( targetObject[ i ].name === objectIndex ) {
  23925. objectIndex = i;
  23926. break;
  23927. }
  23928. }
  23929. break;
  23930. default:
  23931. if ( targetObject[ objectName ] === undefined ) {
  23932. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  23933. return;
  23934. }
  23935. targetObject = targetObject[ objectName ];
  23936. }
  23937. if ( objectIndex !== undefined ) {
  23938. if ( targetObject[ objectIndex ] === undefined ) {
  23939. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  23940. return;
  23941. }
  23942. targetObject = targetObject[ objectIndex ];
  23943. }
  23944. }
  23945. // resolve property
  23946. var nodeProperty = targetObject[ propertyName ];
  23947. if ( nodeProperty === undefined ) {
  23948. var nodeName = parsedPath.nodeName;
  23949. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  23950. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  23951. return;
  23952. }
  23953. // determine versioning scheme
  23954. var versioning = this.Versioning.None;
  23955. if ( targetObject.needsUpdate !== undefined ) { // material
  23956. versioning = this.Versioning.NeedsUpdate;
  23957. this.targetObject = targetObject;
  23958. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  23959. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  23960. this.targetObject = targetObject;
  23961. }
  23962. // determine how the property gets bound
  23963. var bindingType = this.BindingType.Direct;
  23964. if ( propertyIndex !== undefined ) {
  23965. // access a sub element of the property array (only primitives are supported right now)
  23966. if ( propertyName === "morphTargetInfluences" ) {
  23967. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  23968. // support resolving morphTarget names into indices.
  23969. if ( ! targetObject.geometry ) {
  23970. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  23971. return;
  23972. }
  23973. if ( targetObject.geometry.isBufferGeometry ) {
  23974. if ( ! targetObject.geometry.morphAttributes ) {
  23975. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  23976. return;
  23977. }
  23978. for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {
  23979. if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {
  23980. propertyIndex = i;
  23981. break;
  23982. }
  23983. }
  23984. } else {
  23985. if ( ! targetObject.geometry.morphTargets ) {
  23986. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.', this );
  23987. return;
  23988. }
  23989. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  23990. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  23991. propertyIndex = i;
  23992. break;
  23993. }
  23994. }
  23995. }
  23996. }
  23997. bindingType = this.BindingType.ArrayElement;
  23998. this.resolvedProperty = nodeProperty;
  23999. this.propertyIndex = propertyIndex;
  24000. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  24001. // must use copy for Object3D.Euler/Quaternion
  24002. bindingType = this.BindingType.HasFromToArray;
  24003. this.resolvedProperty = nodeProperty;
  24004. } else if ( Array.isArray( nodeProperty ) ) {
  24005. bindingType = this.BindingType.EntireArray;
  24006. this.resolvedProperty = nodeProperty;
  24007. } else {
  24008. this.propertyName = propertyName;
  24009. }
  24010. // select getter / setter
  24011. this.getValue = this.GetterByBindingType[ bindingType ];
  24012. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  24013. },
  24014. unbind: function () {
  24015. this.node = null;
  24016. // back to the prototype version of getValue / setValue
  24017. // note: avoiding to mutate the shape of 'this' via 'delete'
  24018. this.getValue = this._getValue_unbound;
  24019. this.setValue = this._setValue_unbound;
  24020. }
  24021. } );
  24022. //!\ DECLARE ALIAS AFTER assign prototype !
  24023. Object.assign( PropertyBinding.prototype, {
  24024. // initial state of these methods that calls 'bind'
  24025. _getValue_unbound: PropertyBinding.prototype.getValue,
  24026. _setValue_unbound: PropertyBinding.prototype.setValue,
  24027. } );
  24028. /**
  24029. *
  24030. * A group of objects that receives a shared animation state.
  24031. *
  24032. * Usage:
  24033. *
  24034. * - Add objects you would otherwise pass as 'root' to the
  24035. * constructor or the .clipAction method of AnimationMixer.
  24036. *
  24037. * - Instead pass this object as 'root'.
  24038. *
  24039. * - You can also add and remove objects later when the mixer
  24040. * is running.
  24041. *
  24042. * Note:
  24043. *
  24044. * Objects of this class appear as one object to the mixer,
  24045. * so cache control of the individual objects must be done
  24046. * on the group.
  24047. *
  24048. * Limitation:
  24049. *
  24050. * - The animated properties must be compatible among the
  24051. * all objects in the group.
  24052. *
  24053. * - A single property can either be controlled through a
  24054. * target group or directly, but not both.
  24055. *
  24056. * @author tschw
  24057. */
  24058. function AnimationObjectGroup() {
  24059. this.uuid = _Math.generateUUID();
  24060. // cached objects followed by the active ones
  24061. this._objects = Array.prototype.slice.call( arguments );
  24062. this.nCachedObjects_ = 0; // threshold
  24063. // note: read by PropertyBinding.Composite
  24064. var indices = {};
  24065. this._indicesByUUID = indices; // for bookkeeping
  24066. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  24067. indices[ arguments[ i ].uuid ] = i;
  24068. }
  24069. this._paths = []; // inside: string
  24070. this._parsedPaths = []; // inside: { we don't care, here }
  24071. this._bindings = []; // inside: Array< PropertyBinding >
  24072. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  24073. var scope = this;
  24074. this.stats = {
  24075. objects: {
  24076. get total() {
  24077. return scope._objects.length;
  24078. },
  24079. get inUse() {
  24080. return this.total - scope.nCachedObjects_;
  24081. }
  24082. },
  24083. get bindingsPerObject() {
  24084. return scope._bindings.length;
  24085. }
  24086. };
  24087. }
  24088. Object.assign( AnimationObjectGroup.prototype, {
  24089. isAnimationObjectGroup: true,
  24090. add: function () {
  24091. var objects = this._objects,
  24092. nObjects = objects.length,
  24093. nCachedObjects = this.nCachedObjects_,
  24094. indicesByUUID = this._indicesByUUID,
  24095. paths = this._paths,
  24096. parsedPaths = this._parsedPaths,
  24097. bindings = this._bindings,
  24098. nBindings = bindings.length,
  24099. knownObject = undefined;
  24100. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  24101. var object = arguments[ i ],
  24102. uuid = object.uuid,
  24103. index = indicesByUUID[ uuid ];
  24104. if ( index === undefined ) {
  24105. // unknown object -> add it to the ACTIVE region
  24106. index = nObjects ++;
  24107. indicesByUUID[ uuid ] = index;
  24108. objects.push( object );
  24109. // accounting is done, now do the same for all bindings
  24110. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  24111. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  24112. }
  24113. } else if ( index < nCachedObjects ) {
  24114. knownObject = objects[ index ];
  24115. // move existing object to the ACTIVE region
  24116. var firstActiveIndex = -- nCachedObjects,
  24117. lastCachedObject = objects[ firstActiveIndex ];
  24118. indicesByUUID[ lastCachedObject.uuid ] = index;
  24119. objects[ index ] = lastCachedObject;
  24120. indicesByUUID[ uuid ] = firstActiveIndex;
  24121. objects[ firstActiveIndex ] = object;
  24122. // accounting is done, now do the same for all bindings
  24123. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  24124. var bindingsForPath = bindings[ j ],
  24125. lastCached = bindingsForPath[ firstActiveIndex ],
  24126. binding = bindingsForPath[ index ];
  24127. bindingsForPath[ index ] = lastCached;
  24128. if ( binding === undefined ) {
  24129. // since we do not bother to create new bindings
  24130. // for objects that are cached, the binding may
  24131. // or may not exist
  24132. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  24133. }
  24134. bindingsForPath[ firstActiveIndex ] = binding;
  24135. }
  24136. } else if ( objects[ index ] !== knownObject ) {
  24137. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  24138. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  24139. } // else the object is already where we want it to be
  24140. } // for arguments
  24141. this.nCachedObjects_ = nCachedObjects;
  24142. },
  24143. remove: function () {
  24144. var objects = this._objects,
  24145. nCachedObjects = this.nCachedObjects_,
  24146. indicesByUUID = this._indicesByUUID,
  24147. bindings = this._bindings,
  24148. nBindings = bindings.length;
  24149. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  24150. var object = arguments[ i ],
  24151. uuid = object.uuid,
  24152. index = indicesByUUID[ uuid ];
  24153. if ( index !== undefined && index >= nCachedObjects ) {
  24154. // move existing object into the CACHED region
  24155. var lastCachedIndex = nCachedObjects ++,
  24156. firstActiveObject = objects[ lastCachedIndex ];
  24157. indicesByUUID[ firstActiveObject.uuid ] = index;
  24158. objects[ index ] = firstActiveObject;
  24159. indicesByUUID[ uuid ] = lastCachedIndex;
  24160. objects[ lastCachedIndex ] = object;
  24161. // accounting is done, now do the same for all bindings
  24162. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  24163. var bindingsForPath = bindings[ j ],
  24164. firstActive = bindingsForPath[ lastCachedIndex ],
  24165. binding = bindingsForPath[ index ];
  24166. bindingsForPath[ index ] = firstActive;
  24167. bindingsForPath[ lastCachedIndex ] = binding;
  24168. }
  24169. }
  24170. } // for arguments
  24171. this.nCachedObjects_ = nCachedObjects;
  24172. },
  24173. // remove & forget
  24174. uncache: function () {
  24175. var objects = this._objects,
  24176. nObjects = objects.length,
  24177. nCachedObjects = this.nCachedObjects_,
  24178. indicesByUUID = this._indicesByUUID,
  24179. bindings = this._bindings,
  24180. nBindings = bindings.length;
  24181. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  24182. var object = arguments[ i ],
  24183. uuid = object.uuid,
  24184. index = indicesByUUID[ uuid ];
  24185. if ( index !== undefined ) {
  24186. delete indicesByUUID[ uuid ];
  24187. if ( index < nCachedObjects ) {
  24188. // object is cached, shrink the CACHED region
  24189. var firstActiveIndex = -- nCachedObjects,
  24190. lastCachedObject = objects[ firstActiveIndex ],
  24191. lastIndex = -- nObjects,
  24192. lastObject = objects[ lastIndex ];
  24193. // last cached object takes this object's place
  24194. indicesByUUID[ lastCachedObject.uuid ] = index;
  24195. objects[ index ] = lastCachedObject;
  24196. // last object goes to the activated slot and pop
  24197. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  24198. objects[ firstActiveIndex ] = lastObject;
  24199. objects.pop();
  24200. // accounting is done, now do the same for all bindings
  24201. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  24202. var bindingsForPath = bindings[ j ],
  24203. lastCached = bindingsForPath[ firstActiveIndex ],
  24204. last = bindingsForPath[ lastIndex ];
  24205. bindingsForPath[ index ] = lastCached;
  24206. bindingsForPath[ firstActiveIndex ] = last;
  24207. bindingsForPath.pop();
  24208. }
  24209. } else {
  24210. // object is active, just swap with the last and pop
  24211. var lastIndex = -- nObjects,
  24212. lastObject = objects[ lastIndex ];
  24213. indicesByUUID[ lastObject.uuid ] = index;
  24214. objects[ index ] = lastObject;
  24215. objects.pop();
  24216. // accounting is done, now do the same for all bindings
  24217. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  24218. var bindingsForPath = bindings[ j ];
  24219. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  24220. bindingsForPath.pop();
  24221. }
  24222. } // cached or active
  24223. } // if object is known
  24224. } // for arguments
  24225. this.nCachedObjects_ = nCachedObjects;
  24226. },
  24227. // Internal interface used by befriended PropertyBinding.Composite:
  24228. subscribe_: function ( path, parsedPath ) {
  24229. // returns an array of bindings for the given path that is changed
  24230. // according to the contained objects in the group
  24231. var indicesByPath = this._bindingsIndicesByPath,
  24232. index = indicesByPath[ path ],
  24233. bindings = this._bindings;
  24234. if ( index !== undefined ) return bindings[ index ];
  24235. var paths = this._paths,
  24236. parsedPaths = this._parsedPaths,
  24237. objects = this._objects,
  24238. nObjects = objects.length,
  24239. nCachedObjects = this.nCachedObjects_,
  24240. bindingsForPath = new Array( nObjects );
  24241. index = bindings.length;
  24242. indicesByPath[ path ] = index;
  24243. paths.push( path );
  24244. parsedPaths.push( parsedPath );
  24245. bindings.push( bindingsForPath );
  24246. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  24247. var object = objects[ i ];
  24248. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  24249. }
  24250. return bindingsForPath;
  24251. },
  24252. unsubscribe_: function ( path ) {
  24253. // tells the group to forget about a property path and no longer
  24254. // update the array previously obtained with 'subscribe_'
  24255. var indicesByPath = this._bindingsIndicesByPath,
  24256. index = indicesByPath[ path ];
  24257. if ( index !== undefined ) {
  24258. var paths = this._paths,
  24259. parsedPaths = this._parsedPaths,
  24260. bindings = this._bindings,
  24261. lastBindingsIndex = bindings.length - 1,
  24262. lastBindings = bindings[ lastBindingsIndex ],
  24263. lastBindingsPath = path[ lastBindingsIndex ];
  24264. indicesByPath[ lastBindingsPath ] = index;
  24265. bindings[ index ] = lastBindings;
  24266. bindings.pop();
  24267. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  24268. parsedPaths.pop();
  24269. paths[ index ] = paths[ lastBindingsIndex ];
  24270. paths.pop();
  24271. }
  24272. }
  24273. } );
  24274. /**
  24275. *
  24276. * Action provided by AnimationMixer for scheduling clip playback on specific
  24277. * objects.
  24278. *
  24279. * @author Ben Houston / http://clara.io/
  24280. * @author David Sarno / http://lighthaus.us/
  24281. * @author tschw
  24282. *
  24283. */
  24284. function AnimationAction( mixer, clip, localRoot ) {
  24285. this._mixer = mixer;
  24286. this._clip = clip;
  24287. this._localRoot = localRoot || null;
  24288. var tracks = clip.tracks,
  24289. nTracks = tracks.length,
  24290. interpolants = new Array( nTracks );
  24291. var interpolantSettings = {
  24292. endingStart: ZeroCurvatureEnding,
  24293. endingEnd: ZeroCurvatureEnding
  24294. };
  24295. for ( var i = 0; i !== nTracks; ++ i ) {
  24296. var interpolant = tracks[ i ].createInterpolant( null );
  24297. interpolants[ i ] = interpolant;
  24298. interpolant.settings = interpolantSettings;
  24299. }
  24300. this._interpolantSettings = interpolantSettings;
  24301. this._interpolants = interpolants; // bound by the mixer
  24302. // inside: PropertyMixer (managed by the mixer)
  24303. this._propertyBindings = new Array( nTracks );
  24304. this._cacheIndex = null; // for the memory manager
  24305. this._byClipCacheIndex = null; // for the memory manager
  24306. this._timeScaleInterpolant = null;
  24307. this._weightInterpolant = null;
  24308. this.loop = LoopRepeat;
  24309. this._loopCount = - 1;
  24310. // global mixer time when the action is to be started
  24311. // it's set back to 'null' upon start of the action
  24312. this._startTime = null;
  24313. // scaled local time of the action
  24314. // gets clamped or wrapped to 0..clip.duration according to loop
  24315. this.time = 0;
  24316. this.timeScale = 1;
  24317. this._effectiveTimeScale = 1;
  24318. this.weight = 1;
  24319. this._effectiveWeight = 1;
  24320. this.repetitions = Infinity; // no. of repetitions when looping
  24321. this.paused = false; // true -> zero effective time scale
  24322. this.enabled = true; // false -> zero effective weight
  24323. this.clampWhenFinished = false; // keep feeding the last frame?
  24324. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  24325. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  24326. }
  24327. Object.assign( AnimationAction.prototype, {
  24328. // State & Scheduling
  24329. play: function () {
  24330. this._mixer._activateAction( this );
  24331. return this;
  24332. },
  24333. stop: function () {
  24334. this._mixer._deactivateAction( this );
  24335. return this.reset();
  24336. },
  24337. reset: function () {
  24338. this.paused = false;
  24339. this.enabled = true;
  24340. this.time = 0; // restart clip
  24341. this._loopCount = - 1; // forget previous loops
  24342. this._startTime = null; // forget scheduling
  24343. return this.stopFading().stopWarping();
  24344. },
  24345. isRunning: function () {
  24346. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  24347. this._startTime === null && this._mixer._isActiveAction( this );
  24348. },
  24349. // return true when play has been called
  24350. isScheduled: function () {
  24351. return this._mixer._isActiveAction( this );
  24352. },
  24353. startAt: function ( time ) {
  24354. this._startTime = time;
  24355. return this;
  24356. },
  24357. setLoop: function ( mode, repetitions ) {
  24358. this.loop = mode;
  24359. this.repetitions = repetitions;
  24360. return this;
  24361. },
  24362. // Weight
  24363. // set the weight stopping any scheduled fading
  24364. // although .enabled = false yields an effective weight of zero, this
  24365. // method does *not* change .enabled, because it would be confusing
  24366. setEffectiveWeight: function ( weight ) {
  24367. this.weight = weight;
  24368. // note: same logic as when updated at runtime
  24369. this._effectiveWeight = this.enabled ? weight : 0;
  24370. return this.stopFading();
  24371. },
  24372. // return the weight considering fading and .enabled
  24373. getEffectiveWeight: function () {
  24374. return this._effectiveWeight;
  24375. },
  24376. fadeIn: function ( duration ) {
  24377. return this._scheduleFading( duration, 0, 1 );
  24378. },
  24379. fadeOut: function ( duration ) {
  24380. return this._scheduleFading( duration, 1, 0 );
  24381. },
  24382. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  24383. fadeOutAction.fadeOut( duration );
  24384. this.fadeIn( duration );
  24385. if ( warp ) {
  24386. var fadeInDuration = this._clip.duration,
  24387. fadeOutDuration = fadeOutAction._clip.duration,
  24388. startEndRatio = fadeOutDuration / fadeInDuration,
  24389. endStartRatio = fadeInDuration / fadeOutDuration;
  24390. fadeOutAction.warp( 1.0, startEndRatio, duration );
  24391. this.warp( endStartRatio, 1.0, duration );
  24392. }
  24393. return this;
  24394. },
  24395. crossFadeTo: function ( fadeInAction, duration, warp ) {
  24396. return fadeInAction.crossFadeFrom( this, duration, warp );
  24397. },
  24398. stopFading: function () {
  24399. var weightInterpolant = this._weightInterpolant;
  24400. if ( weightInterpolant !== null ) {
  24401. this._weightInterpolant = null;
  24402. this._mixer._takeBackControlInterpolant( weightInterpolant );
  24403. }
  24404. return this;
  24405. },
  24406. // Time Scale Control
  24407. // set the time scale stopping any scheduled warping
  24408. // although .paused = true yields an effective time scale of zero, this
  24409. // method does *not* change .paused, because it would be confusing
  24410. setEffectiveTimeScale: function ( timeScale ) {
  24411. this.timeScale = timeScale;
  24412. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  24413. return this.stopWarping();
  24414. },
  24415. // return the time scale considering warping and .paused
  24416. getEffectiveTimeScale: function () {
  24417. return this._effectiveTimeScale;
  24418. },
  24419. setDuration: function ( duration ) {
  24420. this.timeScale = this._clip.duration / duration;
  24421. return this.stopWarping();
  24422. },
  24423. syncWith: function ( action ) {
  24424. this.time = action.time;
  24425. this.timeScale = action.timeScale;
  24426. return this.stopWarping();
  24427. },
  24428. halt: function ( duration ) {
  24429. return this.warp( this._effectiveTimeScale, 0, duration );
  24430. },
  24431. warp: function ( startTimeScale, endTimeScale, duration ) {
  24432. var mixer = this._mixer, now = mixer.time,
  24433. interpolant = this._timeScaleInterpolant,
  24434. timeScale = this.timeScale;
  24435. if ( interpolant === null ) {
  24436. interpolant = mixer._lendControlInterpolant();
  24437. this._timeScaleInterpolant = interpolant;
  24438. }
  24439. var times = interpolant.parameterPositions,
  24440. values = interpolant.sampleValues;
  24441. times[ 0 ] = now;
  24442. times[ 1 ] = now + duration;
  24443. values[ 0 ] = startTimeScale / timeScale;
  24444. values[ 1 ] = endTimeScale / timeScale;
  24445. return this;
  24446. },
  24447. stopWarping: function () {
  24448. var timeScaleInterpolant = this._timeScaleInterpolant;
  24449. if ( timeScaleInterpolant !== null ) {
  24450. this._timeScaleInterpolant = null;
  24451. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  24452. }
  24453. return this;
  24454. },
  24455. // Object Accessors
  24456. getMixer: function () {
  24457. return this._mixer;
  24458. },
  24459. getClip: function () {
  24460. return this._clip;
  24461. },
  24462. getRoot: function () {
  24463. return this._localRoot || this._mixer._root;
  24464. },
  24465. // Interna
  24466. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  24467. // called by the mixer
  24468. if ( ! this.enabled ) {
  24469. // call ._updateWeight() to update ._effectiveWeight
  24470. this._updateWeight( time );
  24471. return;
  24472. }
  24473. var startTime = this._startTime;
  24474. if ( startTime !== null ) {
  24475. // check for scheduled start of action
  24476. var timeRunning = ( time - startTime ) * timeDirection;
  24477. if ( timeRunning < 0 || timeDirection === 0 ) {
  24478. return; // yet to come / don't decide when delta = 0
  24479. }
  24480. // start
  24481. this._startTime = null; // unschedule
  24482. deltaTime = timeDirection * timeRunning;
  24483. }
  24484. // apply time scale and advance time
  24485. deltaTime *= this._updateTimeScale( time );
  24486. var clipTime = this._updateTime( deltaTime );
  24487. // note: _updateTime may disable the action resulting in
  24488. // an effective weight of 0
  24489. var weight = this._updateWeight( time );
  24490. if ( weight > 0 ) {
  24491. var interpolants = this._interpolants;
  24492. var propertyMixers = this._propertyBindings;
  24493. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  24494. interpolants[ j ].evaluate( clipTime );
  24495. propertyMixers[ j ].accumulate( accuIndex, weight );
  24496. }
  24497. }
  24498. },
  24499. _updateWeight: function ( time ) {
  24500. var weight = 0;
  24501. if ( this.enabled ) {
  24502. weight = this.weight;
  24503. var interpolant = this._weightInterpolant;
  24504. if ( interpolant !== null ) {
  24505. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  24506. weight *= interpolantValue;
  24507. if ( time > interpolant.parameterPositions[ 1 ] ) {
  24508. this.stopFading();
  24509. if ( interpolantValue === 0 ) {
  24510. // faded out, disable
  24511. this.enabled = false;
  24512. }
  24513. }
  24514. }
  24515. }
  24516. this._effectiveWeight = weight;
  24517. return weight;
  24518. },
  24519. _updateTimeScale: function ( time ) {
  24520. var timeScale = 0;
  24521. if ( ! this.paused ) {
  24522. timeScale = this.timeScale;
  24523. var interpolant = this._timeScaleInterpolant;
  24524. if ( interpolant !== null ) {
  24525. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  24526. timeScale *= interpolantValue;
  24527. if ( time > interpolant.parameterPositions[ 1 ] ) {
  24528. this.stopWarping();
  24529. if ( timeScale === 0 ) {
  24530. // motion has halted, pause
  24531. this.paused = true;
  24532. } else {
  24533. // warp done - apply final time scale
  24534. this.timeScale = timeScale;
  24535. }
  24536. }
  24537. }
  24538. }
  24539. this._effectiveTimeScale = timeScale;
  24540. return timeScale;
  24541. },
  24542. _updateTime: function ( deltaTime ) {
  24543. var time = this.time + deltaTime;
  24544. if ( deltaTime === 0 ) return time;
  24545. var duration = this._clip.duration,
  24546. loop = this.loop,
  24547. loopCount = this._loopCount;
  24548. if ( loop === LoopOnce ) {
  24549. if ( loopCount === - 1 ) {
  24550. // just started
  24551. this._loopCount = 0;
  24552. this._setEndings( true, true, false );
  24553. }
  24554. handle_stop: {
  24555. if ( time >= duration ) {
  24556. time = duration;
  24557. } else if ( time < 0 ) {
  24558. time = 0;
  24559. } else break handle_stop;
  24560. if ( this.clampWhenFinished ) this.paused = true;
  24561. else this.enabled = false;
  24562. this._mixer.dispatchEvent( {
  24563. type: 'finished', action: this,
  24564. direction: deltaTime < 0 ? - 1 : 1
  24565. } );
  24566. }
  24567. } else { // repetitive Repeat or PingPong
  24568. var pingPong = ( loop === LoopPingPong );
  24569. if ( loopCount === - 1 ) {
  24570. // just started
  24571. if ( deltaTime >= 0 ) {
  24572. loopCount = 0;
  24573. this._setEndings( true, this.repetitions === 0, pingPong );
  24574. } else {
  24575. // when looping in reverse direction, the initial
  24576. // transition through zero counts as a repetition,
  24577. // so leave loopCount at -1
  24578. this._setEndings( this.repetitions === 0, true, pingPong );
  24579. }
  24580. }
  24581. if ( time >= duration || time < 0 ) {
  24582. // wrap around
  24583. var loopDelta = Math.floor( time / duration ); // signed
  24584. time -= duration * loopDelta;
  24585. loopCount += Math.abs( loopDelta );
  24586. var pending = this.repetitions - loopCount;
  24587. if ( pending <= 0 ) {
  24588. // have to stop (switch state, clamp time, fire event)
  24589. if ( this.clampWhenFinished ) this.paused = true;
  24590. else this.enabled = false;
  24591. time = deltaTime > 0 ? duration : 0;
  24592. this._mixer.dispatchEvent( {
  24593. type: 'finished', action: this,
  24594. direction: deltaTime > 0 ? 1 : - 1
  24595. } );
  24596. } else {
  24597. // keep running
  24598. if ( pending === 1 ) {
  24599. // entering the last round
  24600. var atStart = deltaTime < 0;
  24601. this._setEndings( atStart, ! atStart, pingPong );
  24602. } else {
  24603. this._setEndings( false, false, pingPong );
  24604. }
  24605. this._loopCount = loopCount;
  24606. this._mixer.dispatchEvent( {
  24607. type: 'loop', action: this, loopDelta: loopDelta
  24608. } );
  24609. }
  24610. }
  24611. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  24612. // invert time for the "pong round"
  24613. this.time = time;
  24614. return duration - time;
  24615. }
  24616. }
  24617. this.time = time;
  24618. return time;
  24619. },
  24620. _setEndings: function ( atStart, atEnd, pingPong ) {
  24621. var settings = this._interpolantSettings;
  24622. if ( pingPong ) {
  24623. settings.endingStart = ZeroSlopeEnding;
  24624. settings.endingEnd = ZeroSlopeEnding;
  24625. } else {
  24626. // assuming for LoopOnce atStart == atEnd == true
  24627. if ( atStart ) {
  24628. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  24629. } else {
  24630. settings.endingStart = WrapAroundEnding;
  24631. }
  24632. if ( atEnd ) {
  24633. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  24634. } else {
  24635. settings.endingEnd = WrapAroundEnding;
  24636. }
  24637. }
  24638. },
  24639. _scheduleFading: function ( duration, weightNow, weightThen ) {
  24640. var mixer = this._mixer, now = mixer.time,
  24641. interpolant = this._weightInterpolant;
  24642. if ( interpolant === null ) {
  24643. interpolant = mixer._lendControlInterpolant();
  24644. this._weightInterpolant = interpolant;
  24645. }
  24646. var times = interpolant.parameterPositions,
  24647. values = interpolant.sampleValues;
  24648. times[ 0 ] = now; values[ 0 ] = weightNow;
  24649. times[ 1 ] = now + duration; values[ 1 ] = weightThen;
  24650. return this;
  24651. }
  24652. } );
  24653. /**
  24654. *
  24655. * Player for AnimationClips.
  24656. *
  24657. *
  24658. * @author Ben Houston / http://clara.io/
  24659. * @author David Sarno / http://lighthaus.us/
  24660. * @author tschw
  24661. */
  24662. function AnimationMixer( root ) {
  24663. this._root = root;
  24664. this._initMemoryManager();
  24665. this._accuIndex = 0;
  24666. this.time = 0;
  24667. this.timeScale = 1.0;
  24668. }
  24669. AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  24670. constructor: AnimationMixer,
  24671. _bindAction: function ( action, prototypeAction ) {
  24672. var root = action._localRoot || this._root,
  24673. tracks = action._clip.tracks,
  24674. nTracks = tracks.length,
  24675. bindings = action._propertyBindings,
  24676. interpolants = action._interpolants,
  24677. rootUuid = root.uuid,
  24678. bindingsByRoot = this._bindingsByRootAndName,
  24679. bindingsByName = bindingsByRoot[ rootUuid ];
  24680. if ( bindingsByName === undefined ) {
  24681. bindingsByName = {};
  24682. bindingsByRoot[ rootUuid ] = bindingsByName;
  24683. }
  24684. for ( var i = 0; i !== nTracks; ++ i ) {
  24685. var track = tracks[ i ],
  24686. trackName = track.name,
  24687. binding = bindingsByName[ trackName ];
  24688. if ( binding !== undefined ) {
  24689. bindings[ i ] = binding;
  24690. } else {
  24691. binding = bindings[ i ];
  24692. if ( binding !== undefined ) {
  24693. // existing binding, make sure the cache knows
  24694. if ( binding._cacheIndex === null ) {
  24695. ++ binding.referenceCount;
  24696. this._addInactiveBinding( binding, rootUuid, trackName );
  24697. }
  24698. continue;
  24699. }
  24700. var path = prototypeAction && prototypeAction.
  24701. _propertyBindings[ i ].binding.parsedPath;
  24702. binding = new PropertyMixer(
  24703. PropertyBinding.create( root, trackName, path ),
  24704. track.ValueTypeName, track.getValueSize() );
  24705. ++ binding.referenceCount;
  24706. this._addInactiveBinding( binding, rootUuid, trackName );
  24707. bindings[ i ] = binding;
  24708. }
  24709. interpolants[ i ].resultBuffer = binding.buffer;
  24710. }
  24711. },
  24712. _activateAction: function ( action ) {
  24713. if ( ! this._isActiveAction( action ) ) {
  24714. if ( action._cacheIndex === null ) {
  24715. // this action has been forgotten by the cache, but the user
  24716. // appears to be still using it -> rebind
  24717. var rootUuid = ( action._localRoot || this._root ).uuid,
  24718. clipUuid = action._clip.uuid,
  24719. actionsForClip = this._actionsByClip[ clipUuid ];
  24720. this._bindAction( action,
  24721. actionsForClip && actionsForClip.knownActions[ 0 ] );
  24722. this._addInactiveAction( action, clipUuid, rootUuid );
  24723. }
  24724. var bindings = action._propertyBindings;
  24725. // increment reference counts / sort out state
  24726. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  24727. var binding = bindings[ i ];
  24728. if ( binding.useCount ++ === 0 ) {
  24729. this._lendBinding( binding );
  24730. binding.saveOriginalState();
  24731. }
  24732. }
  24733. this._lendAction( action );
  24734. }
  24735. },
  24736. _deactivateAction: function ( action ) {
  24737. if ( this._isActiveAction( action ) ) {
  24738. var bindings = action._propertyBindings;
  24739. // decrement reference counts / sort out state
  24740. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  24741. var binding = bindings[ i ];
  24742. if ( -- binding.useCount === 0 ) {
  24743. binding.restoreOriginalState();
  24744. this._takeBackBinding( binding );
  24745. }
  24746. }
  24747. this._takeBackAction( action );
  24748. }
  24749. },
  24750. // Memory manager
  24751. _initMemoryManager: function () {
  24752. this._actions = []; // 'nActiveActions' followed by inactive ones
  24753. this._nActiveActions = 0;
  24754. this._actionsByClip = {};
  24755. // inside:
  24756. // {
  24757. // knownActions: Array< AnimationAction > - used as prototypes
  24758. // actionByRoot: AnimationAction - lookup
  24759. // }
  24760. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  24761. this._nActiveBindings = 0;
  24762. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  24763. this._controlInterpolants = []; // same game as above
  24764. this._nActiveControlInterpolants = 0;
  24765. var scope = this;
  24766. this.stats = {
  24767. actions: {
  24768. get total() {
  24769. return scope._actions.length;
  24770. },
  24771. get inUse() {
  24772. return scope._nActiveActions;
  24773. }
  24774. },
  24775. bindings: {
  24776. get total() {
  24777. return scope._bindings.length;
  24778. },
  24779. get inUse() {
  24780. return scope._nActiveBindings;
  24781. }
  24782. },
  24783. controlInterpolants: {
  24784. get total() {
  24785. return scope._controlInterpolants.length;
  24786. },
  24787. get inUse() {
  24788. return scope._nActiveControlInterpolants;
  24789. }
  24790. }
  24791. };
  24792. },
  24793. // Memory management for AnimationAction objects
  24794. _isActiveAction: function ( action ) {
  24795. var index = action._cacheIndex;
  24796. return index !== null && index < this._nActiveActions;
  24797. },
  24798. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  24799. var actions = this._actions,
  24800. actionsByClip = this._actionsByClip,
  24801. actionsForClip = actionsByClip[ clipUuid ];
  24802. if ( actionsForClip === undefined ) {
  24803. actionsForClip = {
  24804. knownActions: [ action ],
  24805. actionByRoot: {}
  24806. };
  24807. action._byClipCacheIndex = 0;
  24808. actionsByClip[ clipUuid ] = actionsForClip;
  24809. } else {
  24810. var knownActions = actionsForClip.knownActions;
  24811. action._byClipCacheIndex = knownActions.length;
  24812. knownActions.push( action );
  24813. }
  24814. action._cacheIndex = actions.length;
  24815. actions.push( action );
  24816. actionsForClip.actionByRoot[ rootUuid ] = action;
  24817. },
  24818. _removeInactiveAction: function ( action ) {
  24819. var actions = this._actions,
  24820. lastInactiveAction = actions[ actions.length - 1 ],
  24821. cacheIndex = action._cacheIndex;
  24822. lastInactiveAction._cacheIndex = cacheIndex;
  24823. actions[ cacheIndex ] = lastInactiveAction;
  24824. actions.pop();
  24825. action._cacheIndex = null;
  24826. var clipUuid = action._clip.uuid,
  24827. actionsByClip = this._actionsByClip,
  24828. actionsForClip = actionsByClip[ clipUuid ],
  24829. knownActionsForClip = actionsForClip.knownActions,
  24830. lastKnownAction =
  24831. knownActionsForClip[ knownActionsForClip.length - 1 ],
  24832. byClipCacheIndex = action._byClipCacheIndex;
  24833. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  24834. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  24835. knownActionsForClip.pop();
  24836. action._byClipCacheIndex = null;
  24837. var actionByRoot = actionsForClip.actionByRoot,
  24838. rootUuid = ( action._localRoot || this._root ).uuid;
  24839. delete actionByRoot[ rootUuid ];
  24840. if ( knownActionsForClip.length === 0 ) {
  24841. delete actionsByClip[ clipUuid ];
  24842. }
  24843. this._removeInactiveBindingsForAction( action );
  24844. },
  24845. _removeInactiveBindingsForAction: function ( action ) {
  24846. var bindings = action._propertyBindings;
  24847. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  24848. var binding = bindings[ i ];
  24849. if ( -- binding.referenceCount === 0 ) {
  24850. this._removeInactiveBinding( binding );
  24851. }
  24852. }
  24853. },
  24854. _lendAction: function ( action ) {
  24855. // [ active actions | inactive actions ]
  24856. // [ active actions >| inactive actions ]
  24857. // s a
  24858. // <-swap->
  24859. // a s
  24860. var actions = this._actions,
  24861. prevIndex = action._cacheIndex,
  24862. lastActiveIndex = this._nActiveActions ++,
  24863. firstInactiveAction = actions[ lastActiveIndex ];
  24864. action._cacheIndex = lastActiveIndex;
  24865. actions[ lastActiveIndex ] = action;
  24866. firstInactiveAction._cacheIndex = prevIndex;
  24867. actions[ prevIndex ] = firstInactiveAction;
  24868. },
  24869. _takeBackAction: function ( action ) {
  24870. // [ active actions | inactive actions ]
  24871. // [ active actions |< inactive actions ]
  24872. // a s
  24873. // <-swap->
  24874. // s a
  24875. var actions = this._actions,
  24876. prevIndex = action._cacheIndex,
  24877. firstInactiveIndex = -- this._nActiveActions,
  24878. lastActiveAction = actions[ firstInactiveIndex ];
  24879. action._cacheIndex = firstInactiveIndex;
  24880. actions[ firstInactiveIndex ] = action;
  24881. lastActiveAction._cacheIndex = prevIndex;
  24882. actions[ prevIndex ] = lastActiveAction;
  24883. },
  24884. // Memory management for PropertyMixer objects
  24885. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  24886. var bindingsByRoot = this._bindingsByRootAndName,
  24887. bindingByName = bindingsByRoot[ rootUuid ],
  24888. bindings = this._bindings;
  24889. if ( bindingByName === undefined ) {
  24890. bindingByName = {};
  24891. bindingsByRoot[ rootUuid ] = bindingByName;
  24892. }
  24893. bindingByName[ trackName ] = binding;
  24894. binding._cacheIndex = bindings.length;
  24895. bindings.push( binding );
  24896. },
  24897. _removeInactiveBinding: function ( binding ) {
  24898. var bindings = this._bindings,
  24899. propBinding = binding.binding,
  24900. rootUuid = propBinding.rootNode.uuid,
  24901. trackName = propBinding.path,
  24902. bindingsByRoot = this._bindingsByRootAndName,
  24903. bindingByName = bindingsByRoot[ rootUuid ],
  24904. lastInactiveBinding = bindings[ bindings.length - 1 ],
  24905. cacheIndex = binding._cacheIndex;
  24906. lastInactiveBinding._cacheIndex = cacheIndex;
  24907. bindings[ cacheIndex ] = lastInactiveBinding;
  24908. bindings.pop();
  24909. delete bindingByName[ trackName ];
  24910. remove_empty_map: {
  24911. for ( var _ in bindingByName ) break remove_empty_map; // eslint-disable-line no-unused-vars
  24912. delete bindingsByRoot[ rootUuid ];
  24913. }
  24914. },
  24915. _lendBinding: function ( binding ) {
  24916. var bindings = this._bindings,
  24917. prevIndex = binding._cacheIndex,
  24918. lastActiveIndex = this._nActiveBindings ++,
  24919. firstInactiveBinding = bindings[ lastActiveIndex ];
  24920. binding._cacheIndex = lastActiveIndex;
  24921. bindings[ lastActiveIndex ] = binding;
  24922. firstInactiveBinding._cacheIndex = prevIndex;
  24923. bindings[ prevIndex ] = firstInactiveBinding;
  24924. },
  24925. _takeBackBinding: function ( binding ) {
  24926. var bindings = this._bindings,
  24927. prevIndex = binding._cacheIndex,
  24928. firstInactiveIndex = -- this._nActiveBindings,
  24929. lastActiveBinding = bindings[ firstInactiveIndex ];
  24930. binding._cacheIndex = firstInactiveIndex;
  24931. bindings[ firstInactiveIndex ] = binding;
  24932. lastActiveBinding._cacheIndex = prevIndex;
  24933. bindings[ prevIndex ] = lastActiveBinding;
  24934. },
  24935. // Memory management of Interpolants for weight and time scale
  24936. _lendControlInterpolant: function () {
  24937. var interpolants = this._controlInterpolants,
  24938. lastActiveIndex = this._nActiveControlInterpolants ++,
  24939. interpolant = interpolants[ lastActiveIndex ];
  24940. if ( interpolant === undefined ) {
  24941. interpolant = new LinearInterpolant(
  24942. new Float32Array( 2 ), new Float32Array( 2 ),
  24943. 1, this._controlInterpolantsResultBuffer );
  24944. interpolant.__cacheIndex = lastActiveIndex;
  24945. interpolants[ lastActiveIndex ] = interpolant;
  24946. }
  24947. return interpolant;
  24948. },
  24949. _takeBackControlInterpolant: function ( interpolant ) {
  24950. var interpolants = this._controlInterpolants,
  24951. prevIndex = interpolant.__cacheIndex,
  24952. firstInactiveIndex = -- this._nActiveControlInterpolants,
  24953. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  24954. interpolant.__cacheIndex = firstInactiveIndex;
  24955. interpolants[ firstInactiveIndex ] = interpolant;
  24956. lastActiveInterpolant.__cacheIndex = prevIndex;
  24957. interpolants[ prevIndex ] = lastActiveInterpolant;
  24958. },
  24959. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  24960. // return an action for a clip optionally using a custom root target
  24961. // object (this method allocates a lot of dynamic memory in case a
  24962. // previously unknown clip/root combination is specified)
  24963. clipAction: function ( clip, optionalRoot ) {
  24964. var root = optionalRoot || this._root,
  24965. rootUuid = root.uuid,
  24966. clipObject = typeof clip === 'string' ?
  24967. AnimationClip.findByName( root, clip ) : clip,
  24968. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  24969. actionsForClip = this._actionsByClip[ clipUuid ],
  24970. prototypeAction = null;
  24971. if ( actionsForClip !== undefined ) {
  24972. var existingAction =
  24973. actionsForClip.actionByRoot[ rootUuid ];
  24974. if ( existingAction !== undefined ) {
  24975. return existingAction;
  24976. }
  24977. // we know the clip, so we don't have to parse all
  24978. // the bindings again but can just copy
  24979. prototypeAction = actionsForClip.knownActions[ 0 ];
  24980. // also, take the clip from the prototype action
  24981. if ( clipObject === null )
  24982. clipObject = prototypeAction._clip;
  24983. }
  24984. // clip must be known when specified via string
  24985. if ( clipObject === null ) return null;
  24986. // allocate all resources required to run it
  24987. var newAction = new AnimationAction( this, clipObject, optionalRoot );
  24988. this._bindAction( newAction, prototypeAction );
  24989. // and make the action known to the memory manager
  24990. this._addInactiveAction( newAction, clipUuid, rootUuid );
  24991. return newAction;
  24992. },
  24993. // get an existing action
  24994. existingAction: function ( clip, optionalRoot ) {
  24995. var root = optionalRoot || this._root,
  24996. rootUuid = root.uuid,
  24997. clipObject = typeof clip === 'string' ?
  24998. AnimationClip.findByName( root, clip ) : clip,
  24999. clipUuid = clipObject ? clipObject.uuid : clip,
  25000. actionsForClip = this._actionsByClip[ clipUuid ];
  25001. if ( actionsForClip !== undefined ) {
  25002. return actionsForClip.actionByRoot[ rootUuid ] || null;
  25003. }
  25004. return null;
  25005. },
  25006. // deactivates all previously scheduled actions
  25007. stopAllAction: function () {
  25008. var actions = this._actions,
  25009. nActions = this._nActiveActions,
  25010. bindings = this._bindings,
  25011. nBindings = this._nActiveBindings;
  25012. this._nActiveActions = 0;
  25013. this._nActiveBindings = 0;
  25014. for ( var i = 0; i !== nActions; ++ i ) {
  25015. actions[ i ].reset();
  25016. }
  25017. for ( var i = 0; i !== nBindings; ++ i ) {
  25018. bindings[ i ].useCount = 0;
  25019. }
  25020. return this;
  25021. },
  25022. // advance the time and update apply the animation
  25023. update: function ( deltaTime ) {
  25024. deltaTime *= this.timeScale;
  25025. var actions = this._actions,
  25026. nActions = this._nActiveActions,
  25027. time = this.time += deltaTime,
  25028. timeDirection = Math.sign( deltaTime ),
  25029. accuIndex = this._accuIndex ^= 1;
  25030. // run active actions
  25031. for ( var i = 0; i !== nActions; ++ i ) {
  25032. var action = actions[ i ];
  25033. action._update( time, deltaTime, timeDirection, accuIndex );
  25034. }
  25035. // update scene graph
  25036. var bindings = this._bindings,
  25037. nBindings = this._nActiveBindings;
  25038. for ( var i = 0; i !== nBindings; ++ i ) {
  25039. bindings[ i ].apply( accuIndex );
  25040. }
  25041. return this;
  25042. },
  25043. // return this mixer's root target object
  25044. getRoot: function () {
  25045. return this._root;
  25046. },
  25047. // free all resources specific to a particular clip
  25048. uncacheClip: function ( clip ) {
  25049. var actions = this._actions,
  25050. clipUuid = clip.uuid,
  25051. actionsByClip = this._actionsByClip,
  25052. actionsForClip = actionsByClip[ clipUuid ];
  25053. if ( actionsForClip !== undefined ) {
  25054. // note: just calling _removeInactiveAction would mess up the
  25055. // iteration state and also require updating the state we can
  25056. // just throw away
  25057. var actionsToRemove = actionsForClip.knownActions;
  25058. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  25059. var action = actionsToRemove[ i ];
  25060. this._deactivateAction( action );
  25061. var cacheIndex = action._cacheIndex,
  25062. lastInactiveAction = actions[ actions.length - 1 ];
  25063. action._cacheIndex = null;
  25064. action._byClipCacheIndex = null;
  25065. lastInactiveAction._cacheIndex = cacheIndex;
  25066. actions[ cacheIndex ] = lastInactiveAction;
  25067. actions.pop();
  25068. this._removeInactiveBindingsForAction( action );
  25069. }
  25070. delete actionsByClip[ clipUuid ];
  25071. }
  25072. },
  25073. // free all resources specific to a particular root target object
  25074. uncacheRoot: function ( root ) {
  25075. var rootUuid = root.uuid,
  25076. actionsByClip = this._actionsByClip;
  25077. for ( var clipUuid in actionsByClip ) {
  25078. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  25079. action = actionByRoot[ rootUuid ];
  25080. if ( action !== undefined ) {
  25081. this._deactivateAction( action );
  25082. this._removeInactiveAction( action );
  25083. }
  25084. }
  25085. var bindingsByRoot = this._bindingsByRootAndName,
  25086. bindingByName = bindingsByRoot[ rootUuid ];
  25087. if ( bindingByName !== undefined ) {
  25088. for ( var trackName in bindingByName ) {
  25089. var binding = bindingByName[ trackName ];
  25090. binding.restoreOriginalState();
  25091. this._removeInactiveBinding( binding );
  25092. }
  25093. }
  25094. },
  25095. // remove a targeted clip from the cache
  25096. uncacheAction: function ( clip, optionalRoot ) {
  25097. var action = this.existingAction( clip, optionalRoot );
  25098. if ( action !== null ) {
  25099. this._deactivateAction( action );
  25100. this._removeInactiveAction( action );
  25101. }
  25102. }
  25103. } );
  25104. /**
  25105. * @author mrdoob / http://mrdoob.com/
  25106. */
  25107. function Uniform( value ) {
  25108. if ( typeof value === 'string' ) {
  25109. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  25110. value = arguments[ 1 ];
  25111. }
  25112. this.value = value;
  25113. }
  25114. Uniform.prototype.clone = function () {
  25115. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  25116. };
  25117. /**
  25118. * @author benaadams / https://twitter.com/ben_a_adams
  25119. */
  25120. function InstancedBufferGeometry() {
  25121. BufferGeometry.call( this );
  25122. this.type = 'InstancedBufferGeometry';
  25123. this.maxInstancedCount = undefined;
  25124. }
  25125. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  25126. constructor: InstancedBufferGeometry,
  25127. isInstancedBufferGeometry: true,
  25128. copy: function ( source ) {
  25129. BufferGeometry.prototype.copy.call( this, source );
  25130. this.maxInstancedCount = source.maxInstancedCount;
  25131. return this;
  25132. },
  25133. clone: function () {
  25134. return new this.constructor().copy( this );
  25135. }
  25136. } );
  25137. /**
  25138. * @author benaadams / https://twitter.com/ben_a_adams
  25139. */
  25140. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  25141. this.data = interleavedBuffer;
  25142. this.itemSize = itemSize;
  25143. this.offset = offset;
  25144. this.normalized = normalized === true;
  25145. }
  25146. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  25147. count: {
  25148. get: function () {
  25149. return this.data.count;
  25150. }
  25151. },
  25152. array: {
  25153. get: function () {
  25154. return this.data.array;
  25155. }
  25156. }
  25157. } );
  25158. Object.assign( InterleavedBufferAttribute.prototype, {
  25159. isInterleavedBufferAttribute: true,
  25160. setX: function ( index, x ) {
  25161. this.data.array[ index * this.data.stride + this.offset ] = x;
  25162. return this;
  25163. },
  25164. setY: function ( index, y ) {
  25165. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  25166. return this;
  25167. },
  25168. setZ: function ( index, z ) {
  25169. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  25170. return this;
  25171. },
  25172. setW: function ( index, w ) {
  25173. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  25174. return this;
  25175. },
  25176. getX: function ( index ) {
  25177. return this.data.array[ index * this.data.stride + this.offset ];
  25178. },
  25179. getY: function ( index ) {
  25180. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  25181. },
  25182. getZ: function ( index ) {
  25183. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  25184. },
  25185. getW: function ( index ) {
  25186. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  25187. },
  25188. setXY: function ( index, x, y ) {
  25189. index = index * this.data.stride + this.offset;
  25190. this.data.array[ index + 0 ] = x;
  25191. this.data.array[ index + 1 ] = y;
  25192. return this;
  25193. },
  25194. setXYZ: function ( index, x, y, z ) {
  25195. index = index * this.data.stride + this.offset;
  25196. this.data.array[ index + 0 ] = x;
  25197. this.data.array[ index + 1 ] = y;
  25198. this.data.array[ index + 2 ] = z;
  25199. return this;
  25200. },
  25201. setXYZW: function ( index, x, y, z, w ) {
  25202. index = index * this.data.stride + this.offset;
  25203. this.data.array[ index + 0 ] = x;
  25204. this.data.array[ index + 1 ] = y;
  25205. this.data.array[ index + 2 ] = z;
  25206. this.data.array[ index + 3 ] = w;
  25207. return this;
  25208. }
  25209. } );
  25210. /**
  25211. * @author benaadams / https://twitter.com/ben_a_adams
  25212. */
  25213. function InterleavedBuffer( array, stride ) {
  25214. this.array = array;
  25215. this.stride = stride;
  25216. this.count = array !== undefined ? array.length / stride : 0;
  25217. this.dynamic = false;
  25218. this.updateRange = { offset: 0, count: - 1 };
  25219. this.version = 0;
  25220. }
  25221. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  25222. set: function ( value ) {
  25223. if ( value === true ) this.version ++;
  25224. }
  25225. } );
  25226. Object.assign( InterleavedBuffer.prototype, {
  25227. isInterleavedBuffer: true,
  25228. onUploadCallback: function () {},
  25229. setArray: function ( array ) {
  25230. if ( Array.isArray( array ) ) {
  25231. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  25232. }
  25233. this.count = array !== undefined ? array.length / this.stride : 0;
  25234. this.array = array;
  25235. return this;
  25236. },
  25237. setDynamic: function ( value ) {
  25238. this.dynamic = value;
  25239. return this;
  25240. },
  25241. copy: function ( source ) {
  25242. this.array = new source.array.constructor( source.array );
  25243. this.count = source.count;
  25244. this.stride = source.stride;
  25245. this.dynamic = source.dynamic;
  25246. return this;
  25247. },
  25248. copyAt: function ( index1, attribute, index2 ) {
  25249. index1 *= this.stride;
  25250. index2 *= attribute.stride;
  25251. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  25252. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  25253. }
  25254. return this;
  25255. },
  25256. set: function ( value, offset ) {
  25257. if ( offset === undefined ) offset = 0;
  25258. this.array.set( value, offset );
  25259. return this;
  25260. },
  25261. clone: function () {
  25262. return new this.constructor().copy( this );
  25263. },
  25264. onUpload: function ( callback ) {
  25265. this.onUploadCallback = callback;
  25266. return this;
  25267. }
  25268. } );
  25269. /**
  25270. * @author benaadams / https://twitter.com/ben_a_adams
  25271. */
  25272. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  25273. InterleavedBuffer.call( this, array, stride );
  25274. this.meshPerAttribute = meshPerAttribute || 1;
  25275. }
  25276. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  25277. constructor: InstancedInterleavedBuffer,
  25278. isInstancedInterleavedBuffer: true,
  25279. copy: function ( source ) {
  25280. InterleavedBuffer.prototype.copy.call( this, source );
  25281. this.meshPerAttribute = source.meshPerAttribute;
  25282. return this;
  25283. }
  25284. } );
  25285. /**
  25286. * @author benaadams / https://twitter.com/ben_a_adams
  25287. */
  25288. function InstancedBufferAttribute( array, itemSize, meshPerAttribute ) {
  25289. BufferAttribute.call( this, array, itemSize );
  25290. this.meshPerAttribute = meshPerAttribute || 1;
  25291. }
  25292. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  25293. constructor: InstancedBufferAttribute,
  25294. isInstancedBufferAttribute: true,
  25295. copy: function ( source ) {
  25296. BufferAttribute.prototype.copy.call( this, source );
  25297. this.meshPerAttribute = source.meshPerAttribute;
  25298. return this;
  25299. }
  25300. } );
  25301. /**
  25302. * @author mrdoob / http://mrdoob.com/
  25303. * @author bhouston / http://clara.io/
  25304. * @author stephomi / http://stephaneginier.com/
  25305. */
  25306. function Raycaster( origin, direction, near, far ) {
  25307. this.ray = new Ray( origin, direction );
  25308. // direction is assumed to be normalized (for accurate distance calculations)
  25309. this.near = near || 0;
  25310. this.far = far || Infinity;
  25311. this.params = {
  25312. Mesh: {},
  25313. Line: {},
  25314. LOD: {},
  25315. Points: { threshold: 1 },
  25316. Sprite: {}
  25317. };
  25318. Object.defineProperties( this.params, {
  25319. PointCloud: {
  25320. get: function () {
  25321. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  25322. return this.Points;
  25323. }
  25324. }
  25325. } );
  25326. }
  25327. function ascSort( a, b ) {
  25328. return a.distance - b.distance;
  25329. }
  25330. function intersectObject( object, raycaster, intersects, recursive ) {
  25331. if ( object.visible === false ) return;
  25332. object.raycast( raycaster, intersects );
  25333. if ( recursive === true ) {
  25334. var children = object.children;
  25335. for ( var i = 0, l = children.length; i < l; i ++ ) {
  25336. intersectObject( children[ i ], raycaster, intersects, true );
  25337. }
  25338. }
  25339. }
  25340. Object.assign( Raycaster.prototype, {
  25341. linePrecision: 1,
  25342. set: function ( origin, direction ) {
  25343. // direction is assumed to be normalized (for accurate distance calculations)
  25344. this.ray.set( origin, direction );
  25345. },
  25346. setFromCamera: function ( coords, camera ) {
  25347. if ( ( camera && camera.isPerspectiveCamera ) ) {
  25348. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  25349. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  25350. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  25351. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  25352. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  25353. } else {
  25354. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  25355. }
  25356. },
  25357. intersectObject: function ( object, recursive, optionalTarget ) {
  25358. var intersects = optionalTarget || [];
  25359. intersectObject( object, this, intersects, recursive );
  25360. intersects.sort( ascSort );
  25361. return intersects;
  25362. },
  25363. intersectObjects: function ( objects, recursive, optionalTarget ) {
  25364. var intersects = optionalTarget || [];
  25365. if ( Array.isArray( objects ) === false ) {
  25366. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  25367. return intersects;
  25368. }
  25369. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  25370. intersectObject( objects[ i ], this, intersects, recursive );
  25371. }
  25372. intersects.sort( ascSort );
  25373. return intersects;
  25374. }
  25375. } );
  25376. /**
  25377. * @author alteredq / http://alteredqualia.com/
  25378. */
  25379. function Clock( autoStart ) {
  25380. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  25381. this.startTime = 0;
  25382. this.oldTime = 0;
  25383. this.elapsedTime = 0;
  25384. this.running = false;
  25385. }
  25386. Object.assign( Clock.prototype, {
  25387. start: function () {
  25388. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  25389. this.oldTime = this.startTime;
  25390. this.elapsedTime = 0;
  25391. this.running = true;
  25392. },
  25393. stop: function () {
  25394. this.getElapsedTime();
  25395. this.running = false;
  25396. this.autoStart = false;
  25397. },
  25398. getElapsedTime: function () {
  25399. this.getDelta();
  25400. return this.elapsedTime;
  25401. },
  25402. getDelta: function () {
  25403. var diff = 0;
  25404. if ( this.autoStart && ! this.running ) {
  25405. this.start();
  25406. return 0;
  25407. }
  25408. if ( this.running ) {
  25409. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  25410. diff = ( newTime - this.oldTime ) / 1000;
  25411. this.oldTime = newTime;
  25412. this.elapsedTime += diff;
  25413. }
  25414. return diff;
  25415. }
  25416. } );
  25417. /**
  25418. * @author bhouston / http://clara.io
  25419. * @author WestLangley / http://github.com/WestLangley
  25420. *
  25421. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  25422. *
  25423. * The poles (phi) are at the positive and negative y axis.
  25424. * The equator starts at positive z.
  25425. */
  25426. function Spherical( radius, phi, theta ) {
  25427. this.radius = ( radius !== undefined ) ? radius : 1.0;
  25428. this.phi = ( phi !== undefined ) ? phi : 0; // up / down towards top and bottom pole
  25429. this.theta = ( theta !== undefined ) ? theta : 0; // around the equator of the sphere
  25430. return this;
  25431. }
  25432. Object.assign( Spherical.prototype, {
  25433. set: function ( radius, phi, theta ) {
  25434. this.radius = radius;
  25435. this.phi = phi;
  25436. this.theta = theta;
  25437. return this;
  25438. },
  25439. clone: function () {
  25440. return new this.constructor().copy( this );
  25441. },
  25442. copy: function ( other ) {
  25443. this.radius = other.radius;
  25444. this.phi = other.phi;
  25445. this.theta = other.theta;
  25446. return this;
  25447. },
  25448. // restrict phi to be betwee EPS and PI-EPS
  25449. makeSafe: function () {
  25450. var EPS = 0.000001;
  25451. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  25452. return this;
  25453. },
  25454. setFromVector3: function ( vec3 ) {
  25455. this.radius = vec3.length();
  25456. if ( this.radius === 0 ) {
  25457. this.theta = 0;
  25458. this.phi = 0;
  25459. } else {
  25460. this.theta = Math.atan2( vec3.x, vec3.z ); // equator angle around y-up axis
  25461. this.phi = Math.acos( _Math.clamp( vec3.y / this.radius, - 1, 1 ) ); // polar angle
  25462. }
  25463. return this;
  25464. }
  25465. } );
  25466. /**
  25467. * @author Mugen87 / https://github.com/Mugen87
  25468. *
  25469. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  25470. *
  25471. */
  25472. function Cylindrical( radius, theta, y ) {
  25473. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  25474. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  25475. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  25476. return this;
  25477. }
  25478. Object.assign( Cylindrical.prototype, {
  25479. set: function ( radius, theta, y ) {
  25480. this.radius = radius;
  25481. this.theta = theta;
  25482. this.y = y;
  25483. return this;
  25484. },
  25485. clone: function () {
  25486. return new this.constructor().copy( this );
  25487. },
  25488. copy: function ( other ) {
  25489. this.radius = other.radius;
  25490. this.theta = other.theta;
  25491. this.y = other.y;
  25492. return this;
  25493. },
  25494. setFromVector3: function ( vec3 ) {
  25495. this.radius = Math.sqrt( vec3.x * vec3.x + vec3.z * vec3.z );
  25496. this.theta = Math.atan2( vec3.x, vec3.z );
  25497. this.y = vec3.y;
  25498. return this;
  25499. }
  25500. } );
  25501. /**
  25502. * @author bhouston / http://clara.io
  25503. */
  25504. function Box2( min, max ) {
  25505. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  25506. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  25507. }
  25508. Object.assign( Box2.prototype, {
  25509. set: function ( min, max ) {
  25510. this.min.copy( min );
  25511. this.max.copy( max );
  25512. return this;
  25513. },
  25514. setFromPoints: function ( points ) {
  25515. this.makeEmpty();
  25516. for ( var i = 0, il = points.length; i < il; i ++ ) {
  25517. this.expandByPoint( points[ i ] );
  25518. }
  25519. return this;
  25520. },
  25521. setFromCenterAndSize: function () {
  25522. var v1 = new Vector2();
  25523. return function setFromCenterAndSize( center, size ) {
  25524. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  25525. this.min.copy( center ).sub( halfSize );
  25526. this.max.copy( center ).add( halfSize );
  25527. return this;
  25528. };
  25529. }(),
  25530. clone: function () {
  25531. return new this.constructor().copy( this );
  25532. },
  25533. copy: function ( box ) {
  25534. this.min.copy( box.min );
  25535. this.max.copy( box.max );
  25536. return this;
  25537. },
  25538. makeEmpty: function () {
  25539. this.min.x = this.min.y = + Infinity;
  25540. this.max.x = this.max.y = - Infinity;
  25541. return this;
  25542. },
  25543. isEmpty: function () {
  25544. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  25545. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  25546. },
  25547. getCenter: function ( target ) {
  25548. if ( target === undefined ) {
  25549. console.warn( 'THREE.Box2: .getCenter() target is now required' );
  25550. target = new Vector2();
  25551. }
  25552. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  25553. },
  25554. getSize: function ( target ) {
  25555. if ( target === undefined ) {
  25556. console.warn( 'THREE.Box2: .getSize() target is now required' );
  25557. target = new Vector2();
  25558. }
  25559. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  25560. },
  25561. expandByPoint: function ( point ) {
  25562. this.min.min( point );
  25563. this.max.max( point );
  25564. return this;
  25565. },
  25566. expandByVector: function ( vector ) {
  25567. this.min.sub( vector );
  25568. this.max.add( vector );
  25569. return this;
  25570. },
  25571. expandByScalar: function ( scalar ) {
  25572. this.min.addScalar( - scalar );
  25573. this.max.addScalar( scalar );
  25574. return this;
  25575. },
  25576. containsPoint: function ( point ) {
  25577. return point.x < this.min.x || point.x > this.max.x ||
  25578. point.y < this.min.y || point.y > this.max.y ? false : true;
  25579. },
  25580. containsBox: function ( box ) {
  25581. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  25582. this.min.y <= box.min.y && box.max.y <= this.max.y;
  25583. },
  25584. getParameter: function ( point, target ) {
  25585. // This can potentially have a divide by zero if the box
  25586. // has a size dimension of 0.
  25587. if ( target === undefined ) {
  25588. console.warn( 'THREE.Box2: .getParameter() target is now required' );
  25589. target = new Vector2();
  25590. }
  25591. return target.set(
  25592. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  25593. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  25594. );
  25595. },
  25596. intersectsBox: function ( box ) {
  25597. // using 4 splitting planes to rule out intersections
  25598. return box.max.x < this.min.x || box.min.x > this.max.x ||
  25599. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  25600. },
  25601. clampPoint: function ( point, target ) {
  25602. if ( target === undefined ) {
  25603. console.warn( 'THREE.Box2: .clampPoint() target is now required' );
  25604. target = new Vector2();
  25605. }
  25606. return target.copy( point ).clamp( this.min, this.max );
  25607. },
  25608. distanceToPoint: function () {
  25609. var v1 = new Vector2();
  25610. return function distanceToPoint( point ) {
  25611. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  25612. return clampedPoint.sub( point ).length();
  25613. };
  25614. }(),
  25615. intersect: function ( box ) {
  25616. this.min.max( box.min );
  25617. this.max.min( box.max );
  25618. return this;
  25619. },
  25620. union: function ( box ) {
  25621. this.min.min( box.min );
  25622. this.max.max( box.max );
  25623. return this;
  25624. },
  25625. translate: function ( offset ) {
  25626. this.min.add( offset );
  25627. this.max.add( offset );
  25628. return this;
  25629. },
  25630. equals: function ( box ) {
  25631. return box.min.equals( this.min ) && box.max.equals( this.max );
  25632. }
  25633. } );
  25634. /**
  25635. * @author alteredq / http://alteredqualia.com/
  25636. */
  25637. function ImmediateRenderObject( material ) {
  25638. Object3D.call( this );
  25639. this.material = material;
  25640. this.render = function ( /* renderCallback */ ) {};
  25641. }
  25642. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  25643. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  25644. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  25645. /**
  25646. * @author mrdoob / http://mrdoob.com/
  25647. * @author WestLangley / http://github.com/WestLangley
  25648. */
  25649. function VertexNormalsHelper( object, size, hex, linewidth ) {
  25650. this.object = object;
  25651. this.size = ( size !== undefined ) ? size : 1;
  25652. var color = ( hex !== undefined ) ? hex : 0xff0000;
  25653. var width = ( linewidth !== undefined ) ? linewidth : 1;
  25654. //
  25655. var nNormals = 0;
  25656. var objGeometry = this.object.geometry;
  25657. if ( objGeometry && objGeometry.isGeometry ) {
  25658. nNormals = objGeometry.faces.length * 3;
  25659. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  25660. nNormals = objGeometry.attributes.normal.count;
  25661. }
  25662. //
  25663. var geometry = new BufferGeometry();
  25664. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  25665. geometry.addAttribute( 'position', positions );
  25666. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  25667. //
  25668. this.matrixAutoUpdate = false;
  25669. this.update();
  25670. }
  25671. VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
  25672. VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
  25673. VertexNormalsHelper.prototype.update = ( function () {
  25674. var v1 = new Vector3();
  25675. var v2 = new Vector3();
  25676. var normalMatrix = new Matrix3();
  25677. return function update() {
  25678. var keys = [ 'a', 'b', 'c' ];
  25679. this.object.updateMatrixWorld( true );
  25680. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  25681. var matrixWorld = this.object.matrixWorld;
  25682. var position = this.geometry.attributes.position;
  25683. //
  25684. var objGeometry = this.object.geometry;
  25685. if ( objGeometry && objGeometry.isGeometry ) {
  25686. var vertices = objGeometry.vertices;
  25687. var faces = objGeometry.faces;
  25688. var idx = 0;
  25689. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  25690. var face = faces[ i ];
  25691. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  25692. var vertex = vertices[ face[ keys[ j ] ] ];
  25693. var normal = face.vertexNormals[ j ];
  25694. v1.copy( vertex ).applyMatrix4( matrixWorld );
  25695. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  25696. position.setXYZ( idx, v1.x, v1.y, v1.z );
  25697. idx = idx + 1;
  25698. position.setXYZ( idx, v2.x, v2.y, v2.z );
  25699. idx = idx + 1;
  25700. }
  25701. }
  25702. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  25703. var objPos = objGeometry.attributes.position;
  25704. var objNorm = objGeometry.attributes.normal;
  25705. var idx = 0;
  25706. // for simplicity, ignore index and drawcalls, and render every normal
  25707. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  25708. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  25709. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  25710. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  25711. position.setXYZ( idx, v1.x, v1.y, v1.z );
  25712. idx = idx + 1;
  25713. position.setXYZ( idx, v2.x, v2.y, v2.z );
  25714. idx = idx + 1;
  25715. }
  25716. }
  25717. position.needsUpdate = true;
  25718. };
  25719. }() );
  25720. /**
  25721. * @author alteredq / http://alteredqualia.com/
  25722. * @author mrdoob / http://mrdoob.com/
  25723. * @author WestLangley / http://github.com/WestLangley
  25724. */
  25725. function SpotLightHelper( light, color ) {
  25726. Object3D.call( this );
  25727. this.light = light;
  25728. this.light.updateMatrixWorld();
  25729. this.matrix = light.matrixWorld;
  25730. this.matrixAutoUpdate = false;
  25731. this.color = color;
  25732. var geometry = new BufferGeometry();
  25733. var positions = [
  25734. 0, 0, 0, 0, 0, 1,
  25735. 0, 0, 0, 1, 0, 1,
  25736. 0, 0, 0, - 1, 0, 1,
  25737. 0, 0, 0, 0, 1, 1,
  25738. 0, 0, 0, 0, - 1, 1
  25739. ];
  25740. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  25741. var p1 = ( i / l ) * Math.PI * 2;
  25742. var p2 = ( j / l ) * Math.PI * 2;
  25743. positions.push(
  25744. Math.cos( p1 ), Math.sin( p1 ), 1,
  25745. Math.cos( p2 ), Math.sin( p2 ), 1
  25746. );
  25747. }
  25748. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  25749. var material = new LineBasicMaterial( { fog: false } );
  25750. this.cone = new LineSegments( geometry, material );
  25751. this.add( this.cone );
  25752. this.update();
  25753. }
  25754. SpotLightHelper.prototype = Object.create( Object3D.prototype );
  25755. SpotLightHelper.prototype.constructor = SpotLightHelper;
  25756. SpotLightHelper.prototype.dispose = function () {
  25757. this.cone.geometry.dispose();
  25758. this.cone.material.dispose();
  25759. };
  25760. SpotLightHelper.prototype.update = function () {
  25761. var vector = new Vector3();
  25762. var vector2 = new Vector3();
  25763. return function update() {
  25764. this.light.updateMatrixWorld();
  25765. var coneLength = this.light.distance ? this.light.distance : 1000;
  25766. var coneWidth = coneLength * Math.tan( this.light.angle );
  25767. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  25768. vector.setFromMatrixPosition( this.light.matrixWorld );
  25769. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  25770. this.cone.lookAt( vector2.sub( vector ) );
  25771. if ( this.color !== undefined ) {
  25772. this.cone.material.color.set( this.color );
  25773. } else {
  25774. this.cone.material.color.copy( this.light.color );
  25775. }
  25776. };
  25777. }();
  25778. /**
  25779. * @author Sean Griffin / http://twitter.com/sgrif
  25780. * @author Michael Guerrero / http://realitymeltdown.com
  25781. * @author mrdoob / http://mrdoob.com/
  25782. * @author ikerr / http://verold.com
  25783. * @author Mugen87 / https://github.com/Mugen87
  25784. */
  25785. function getBoneList( object ) {
  25786. var boneList = [];
  25787. if ( object && object.isBone ) {
  25788. boneList.push( object );
  25789. }
  25790. for ( var i = 0; i < object.children.length; i ++ ) {
  25791. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  25792. }
  25793. return boneList;
  25794. }
  25795. function SkeletonHelper( object ) {
  25796. var bones = getBoneList( object );
  25797. var geometry = new BufferGeometry();
  25798. var vertices = [];
  25799. var colors = [];
  25800. var color1 = new Color( 0, 0, 1 );
  25801. var color2 = new Color( 0, 1, 0 );
  25802. for ( var i = 0; i < bones.length; i ++ ) {
  25803. var bone = bones[ i ];
  25804. if ( bone.parent && bone.parent.isBone ) {
  25805. vertices.push( 0, 0, 0 );
  25806. vertices.push( 0, 0, 0 );
  25807. colors.push( color1.r, color1.g, color1.b );
  25808. colors.push( color2.r, color2.g, color2.b );
  25809. }
  25810. }
  25811. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  25812. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  25813. var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  25814. LineSegments.call( this, geometry, material );
  25815. this.root = object;
  25816. this.bones = bones;
  25817. this.matrix = object.matrixWorld;
  25818. this.matrixAutoUpdate = false;
  25819. }
  25820. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  25821. SkeletonHelper.prototype.constructor = SkeletonHelper;
  25822. SkeletonHelper.prototype.updateMatrixWorld = function () {
  25823. var vector = new Vector3();
  25824. var boneMatrix = new Matrix4();
  25825. var matrixWorldInv = new Matrix4();
  25826. return function updateMatrixWorld( force ) {
  25827. var bones = this.bones;
  25828. var geometry = this.geometry;
  25829. var position = geometry.getAttribute( 'position' );
  25830. matrixWorldInv.getInverse( this.root.matrixWorld );
  25831. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  25832. var bone = bones[ i ];
  25833. if ( bone.parent && bone.parent.isBone ) {
  25834. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  25835. vector.setFromMatrixPosition( boneMatrix );
  25836. position.setXYZ( j, vector.x, vector.y, vector.z );
  25837. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  25838. vector.setFromMatrixPosition( boneMatrix );
  25839. position.setXYZ( j + 1, vector.x, vector.y, vector.z );
  25840. j += 2;
  25841. }
  25842. }
  25843. geometry.getAttribute( 'position' ).needsUpdate = true;
  25844. Object3D.prototype.updateMatrixWorld.call( this, force );
  25845. };
  25846. }();
  25847. /**
  25848. * @author alteredq / http://alteredqualia.com/
  25849. * @author mrdoob / http://mrdoob.com/
  25850. */
  25851. function PointLightHelper( light, sphereSize, color ) {
  25852. this.light = light;
  25853. this.light.updateMatrixWorld();
  25854. this.color = color;
  25855. var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  25856. var material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  25857. Mesh.call( this, geometry, material );
  25858. this.matrix = this.light.matrixWorld;
  25859. this.matrixAutoUpdate = false;
  25860. this.update();
  25861. /*
  25862. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  25863. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  25864. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  25865. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  25866. var d = light.distance;
  25867. if ( d === 0.0 ) {
  25868. this.lightDistance.visible = false;
  25869. } else {
  25870. this.lightDistance.scale.set( d, d, d );
  25871. }
  25872. this.add( this.lightDistance );
  25873. */
  25874. }
  25875. PointLightHelper.prototype = Object.create( Mesh.prototype );
  25876. PointLightHelper.prototype.constructor = PointLightHelper;
  25877. PointLightHelper.prototype.dispose = function () {
  25878. this.geometry.dispose();
  25879. this.material.dispose();
  25880. };
  25881. PointLightHelper.prototype.update = function () {
  25882. if ( this.color !== undefined ) {
  25883. this.material.color.set( this.color );
  25884. } else {
  25885. this.material.color.copy( this.light.color );
  25886. }
  25887. /*
  25888. var d = this.light.distance;
  25889. if ( d === 0.0 ) {
  25890. this.lightDistance.visible = false;
  25891. } else {
  25892. this.lightDistance.visible = true;
  25893. this.lightDistance.scale.set( d, d, d );
  25894. }
  25895. */
  25896. };
  25897. /**
  25898. * @author abelnation / http://github.com/abelnation
  25899. * @author Mugen87 / http://github.com/Mugen87
  25900. * @author WestLangley / http://github.com/WestLangley
  25901. */
  25902. function RectAreaLightHelper( light, color ) {
  25903. Object3D.call( this );
  25904. this.light = light;
  25905. this.light.updateMatrixWorld();
  25906. this.matrix = light.matrixWorld;
  25907. this.matrixAutoUpdate = false;
  25908. this.color = color;
  25909. var material = new LineBasicMaterial( { fog: false } );
  25910. var geometry = new BufferGeometry();
  25911. geometry.addAttribute( 'position', new BufferAttribute( new Float32Array( 5 * 3 ), 3 ) );
  25912. this.line = new Line( geometry, material );
  25913. this.add( this.line );
  25914. this.update();
  25915. }
  25916. RectAreaLightHelper.prototype = Object.create( Object3D.prototype );
  25917. RectAreaLightHelper.prototype.constructor = RectAreaLightHelper;
  25918. RectAreaLightHelper.prototype.dispose = function () {
  25919. this.children[ 0 ].geometry.dispose();
  25920. this.children[ 0 ].material.dispose();
  25921. };
  25922. RectAreaLightHelper.prototype.update = function () {
  25923. // calculate new dimensions of the helper
  25924. var hx = this.light.width * 0.5;
  25925. var hy = this.light.height * 0.5;
  25926. var position = this.line.geometry.attributes.position;
  25927. var array = position.array;
  25928. // update vertices
  25929. array[ 0 ] = hx; array[ 1 ] = - hy; array[ 2 ] = 0;
  25930. array[ 3 ] = hx; array[ 4 ] = hy; array[ 5 ] = 0;
  25931. array[ 6 ] = - hx; array[ 7 ] = hy; array[ 8 ] = 0;
  25932. array[ 9 ] = - hx; array[ 10 ] = - hy; array[ 11 ] = 0;
  25933. array[ 12 ] = hx; array[ 13 ] = - hy; array[ 14 ] = 0;
  25934. position.needsUpdate = true;
  25935. if ( this.color !== undefined ) {
  25936. this.line.material.color.set( this.color );
  25937. } else {
  25938. this.line.material.color.copy( this.light.color );
  25939. }
  25940. };
  25941. /**
  25942. * @author alteredq / http://alteredqualia.com/
  25943. * @author mrdoob / http://mrdoob.com/
  25944. * @author Mugen87 / https://github.com/Mugen87
  25945. */
  25946. function HemisphereLightHelper( light, size, color ) {
  25947. Object3D.call( this );
  25948. this.light = light;
  25949. this.light.updateMatrixWorld();
  25950. this.matrix = light.matrixWorld;
  25951. this.matrixAutoUpdate = false;
  25952. this.color = color;
  25953. var geometry = new OctahedronBufferGeometry( size );
  25954. geometry.rotateY( Math.PI * 0.5 );
  25955. this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  25956. if ( this.color === undefined ) this.material.vertexColors = VertexColors;
  25957. var position = geometry.getAttribute( 'position' );
  25958. var colors = new Float32Array( position.count * 3 );
  25959. geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
  25960. this.add( new Mesh( geometry, this.material ) );
  25961. this.update();
  25962. }
  25963. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  25964. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  25965. HemisphereLightHelper.prototype.dispose = function () {
  25966. this.children[ 0 ].geometry.dispose();
  25967. this.children[ 0 ].material.dispose();
  25968. };
  25969. HemisphereLightHelper.prototype.update = function () {
  25970. var vector = new Vector3();
  25971. var color1 = new Color();
  25972. var color2 = new Color();
  25973. return function update() {
  25974. var mesh = this.children[ 0 ];
  25975. if ( this.color !== undefined ) {
  25976. this.material.color.set( this.color );
  25977. } else {
  25978. var colors = mesh.geometry.getAttribute( 'color' );
  25979. color1.copy( this.light.color );
  25980. color2.copy( this.light.groundColor );
  25981. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  25982. var color = ( i < ( l / 2 ) ) ? color1 : color2;
  25983. colors.setXYZ( i, color.r, color.g, color.b );
  25984. }
  25985. colors.needsUpdate = true;
  25986. }
  25987. mesh.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  25988. };
  25989. }();
  25990. /**
  25991. * @author mrdoob / http://mrdoob.com/
  25992. */
  25993. function GridHelper( size, divisions, color1, color2 ) {
  25994. size = size || 10;
  25995. divisions = divisions || 10;
  25996. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  25997. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  25998. var center = divisions / 2;
  25999. var step = size / divisions;
  26000. var halfSize = size / 2;
  26001. var vertices = [], colors = [];
  26002. for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  26003. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  26004. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  26005. var color = i === center ? color1 : color2;
  26006. color.toArray( colors, j ); j += 3;
  26007. color.toArray( colors, j ); j += 3;
  26008. color.toArray( colors, j ); j += 3;
  26009. color.toArray( colors, j ); j += 3;
  26010. }
  26011. var geometry = new BufferGeometry();
  26012. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26013. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26014. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  26015. LineSegments.call( this, geometry, material );
  26016. }
  26017. GridHelper.prototype = Object.create( LineSegments.prototype );
  26018. GridHelper.prototype.constructor = GridHelper;
  26019. /**
  26020. * @author mrdoob / http://mrdoob.com/
  26021. * @author Mugen87 / http://github.com/Mugen87
  26022. * @author Hectate / http://www.github.com/Hectate
  26023. */
  26024. function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
  26025. radius = radius || 10;
  26026. radials = radials || 16;
  26027. circles = circles || 8;
  26028. divisions = divisions || 64;
  26029. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  26030. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  26031. var vertices = [];
  26032. var colors = [];
  26033. var x, z;
  26034. var v, i, j, r, color;
  26035. // create the radials
  26036. for ( i = 0; i <= radials; i ++ ) {
  26037. v = ( i / radials ) * ( Math.PI * 2 );
  26038. x = Math.sin( v ) * radius;
  26039. z = Math.cos( v ) * radius;
  26040. vertices.push( 0, 0, 0 );
  26041. vertices.push( x, 0, z );
  26042. color = ( i & 1 ) ? color1 : color2;
  26043. colors.push( color.r, color.g, color.b );
  26044. colors.push( color.r, color.g, color.b );
  26045. }
  26046. // create the circles
  26047. for ( i = 0; i <= circles; i ++ ) {
  26048. color = ( i & 1 ) ? color1 : color2;
  26049. r = radius - ( radius / circles * i );
  26050. for ( j = 0; j < divisions; j ++ ) {
  26051. // first vertex
  26052. v = ( j / divisions ) * ( Math.PI * 2 );
  26053. x = Math.sin( v ) * r;
  26054. z = Math.cos( v ) * r;
  26055. vertices.push( x, 0, z );
  26056. colors.push( color.r, color.g, color.b );
  26057. // second vertex
  26058. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  26059. x = Math.sin( v ) * r;
  26060. z = Math.cos( v ) * r;
  26061. vertices.push( x, 0, z );
  26062. colors.push( color.r, color.g, color.b );
  26063. }
  26064. }
  26065. var geometry = new BufferGeometry();
  26066. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26067. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26068. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  26069. LineSegments.call( this, geometry, material );
  26070. }
  26071. PolarGridHelper.prototype = Object.create( LineSegments.prototype );
  26072. PolarGridHelper.prototype.constructor = PolarGridHelper;
  26073. /**
  26074. * @author mrdoob / http://mrdoob.com/
  26075. * @author WestLangley / http://github.com/WestLangley
  26076. */
  26077. function FaceNormalsHelper( object, size, hex, linewidth ) {
  26078. // FaceNormalsHelper only supports THREE.Geometry
  26079. this.object = object;
  26080. this.size = ( size !== undefined ) ? size : 1;
  26081. var color = ( hex !== undefined ) ? hex : 0xffff00;
  26082. var width = ( linewidth !== undefined ) ? linewidth : 1;
  26083. //
  26084. var nNormals = 0;
  26085. var objGeometry = this.object.geometry;
  26086. if ( objGeometry && objGeometry.isGeometry ) {
  26087. nNormals = objGeometry.faces.length;
  26088. } else {
  26089. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  26090. }
  26091. //
  26092. var geometry = new BufferGeometry();
  26093. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  26094. geometry.addAttribute( 'position', positions );
  26095. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  26096. //
  26097. this.matrixAutoUpdate = false;
  26098. this.update();
  26099. }
  26100. FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
  26101. FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
  26102. FaceNormalsHelper.prototype.update = ( function () {
  26103. var v1 = new Vector3();
  26104. var v2 = new Vector3();
  26105. var normalMatrix = new Matrix3();
  26106. return function update() {
  26107. this.object.updateMatrixWorld( true );
  26108. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  26109. var matrixWorld = this.object.matrixWorld;
  26110. var position = this.geometry.attributes.position;
  26111. //
  26112. var objGeometry = this.object.geometry;
  26113. var vertices = objGeometry.vertices;
  26114. var faces = objGeometry.faces;
  26115. var idx = 0;
  26116. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  26117. var face = faces[ i ];
  26118. var normal = face.normal;
  26119. v1.copy( vertices[ face.a ] )
  26120. .add( vertices[ face.b ] )
  26121. .add( vertices[ face.c ] )
  26122. .divideScalar( 3 )
  26123. .applyMatrix4( matrixWorld );
  26124. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  26125. position.setXYZ( idx, v1.x, v1.y, v1.z );
  26126. idx = idx + 1;
  26127. position.setXYZ( idx, v2.x, v2.y, v2.z );
  26128. idx = idx + 1;
  26129. }
  26130. position.needsUpdate = true;
  26131. };
  26132. }() );
  26133. /**
  26134. * @author alteredq / http://alteredqualia.com/
  26135. * @author mrdoob / http://mrdoob.com/
  26136. * @author WestLangley / http://github.com/WestLangley
  26137. */
  26138. function DirectionalLightHelper( light, size, color ) {
  26139. Object3D.call( this );
  26140. this.light = light;
  26141. this.light.updateMatrixWorld();
  26142. this.matrix = light.matrixWorld;
  26143. this.matrixAutoUpdate = false;
  26144. this.color = color;
  26145. if ( size === undefined ) size = 1;
  26146. var geometry = new BufferGeometry();
  26147. geometry.addAttribute( 'position', new Float32BufferAttribute( [
  26148. - size, size, 0,
  26149. size, size, 0,
  26150. size, - size, 0,
  26151. - size, - size, 0,
  26152. - size, size, 0
  26153. ], 3 ) );
  26154. var material = new LineBasicMaterial( { fog: false } );
  26155. this.lightPlane = new Line( geometry, material );
  26156. this.add( this.lightPlane );
  26157. geometry = new BufferGeometry();
  26158. geometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  26159. this.targetLine = new Line( geometry, material );
  26160. this.add( this.targetLine );
  26161. this.update();
  26162. }
  26163. DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
  26164. DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
  26165. DirectionalLightHelper.prototype.dispose = function () {
  26166. this.lightPlane.geometry.dispose();
  26167. this.lightPlane.material.dispose();
  26168. this.targetLine.geometry.dispose();
  26169. this.targetLine.material.dispose();
  26170. };
  26171. DirectionalLightHelper.prototype.update = function () {
  26172. var v1 = new Vector3();
  26173. var v2 = new Vector3();
  26174. var v3 = new Vector3();
  26175. return function update() {
  26176. v1.setFromMatrixPosition( this.light.matrixWorld );
  26177. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  26178. v3.subVectors( v2, v1 );
  26179. this.lightPlane.lookAt( v3 );
  26180. if ( this.color !== undefined ) {
  26181. this.lightPlane.material.color.set( this.color );
  26182. this.targetLine.material.color.set( this.color );
  26183. } else {
  26184. this.lightPlane.material.color.copy( this.light.color );
  26185. this.targetLine.material.color.copy( this.light.color );
  26186. }
  26187. this.targetLine.lookAt( v3 );
  26188. this.targetLine.scale.z = v3.length();
  26189. };
  26190. }();
  26191. /**
  26192. * @author alteredq / http://alteredqualia.com/
  26193. * @author Mugen87 / https://github.com/Mugen87
  26194. *
  26195. * - shows frustum, line of sight and up of the camera
  26196. * - suitable for fast updates
  26197. * - based on frustum visualization in lightgl.js shadowmap example
  26198. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  26199. */
  26200. function CameraHelper( camera ) {
  26201. var geometry = new BufferGeometry();
  26202. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
  26203. var vertices = [];
  26204. var colors = [];
  26205. var pointMap = {};
  26206. // colors
  26207. var colorFrustum = new Color( 0xffaa00 );
  26208. var colorCone = new Color( 0xff0000 );
  26209. var colorUp = new Color( 0x00aaff );
  26210. var colorTarget = new Color( 0xffffff );
  26211. var colorCross = new Color( 0x333333 );
  26212. // near
  26213. addLine( 'n1', 'n2', colorFrustum );
  26214. addLine( 'n2', 'n4', colorFrustum );
  26215. addLine( 'n4', 'n3', colorFrustum );
  26216. addLine( 'n3', 'n1', colorFrustum );
  26217. // far
  26218. addLine( 'f1', 'f2', colorFrustum );
  26219. addLine( 'f2', 'f4', colorFrustum );
  26220. addLine( 'f4', 'f3', colorFrustum );
  26221. addLine( 'f3', 'f1', colorFrustum );
  26222. // sides
  26223. addLine( 'n1', 'f1', colorFrustum );
  26224. addLine( 'n2', 'f2', colorFrustum );
  26225. addLine( 'n3', 'f3', colorFrustum );
  26226. addLine( 'n4', 'f4', colorFrustum );
  26227. // cone
  26228. addLine( 'p', 'n1', colorCone );
  26229. addLine( 'p', 'n2', colorCone );
  26230. addLine( 'p', 'n3', colorCone );
  26231. addLine( 'p', 'n4', colorCone );
  26232. // up
  26233. addLine( 'u1', 'u2', colorUp );
  26234. addLine( 'u2', 'u3', colorUp );
  26235. addLine( 'u3', 'u1', colorUp );
  26236. // target
  26237. addLine( 'c', 't', colorTarget );
  26238. addLine( 'p', 'c', colorCross );
  26239. // cross
  26240. addLine( 'cn1', 'cn2', colorCross );
  26241. addLine( 'cn3', 'cn4', colorCross );
  26242. addLine( 'cf1', 'cf2', colorCross );
  26243. addLine( 'cf3', 'cf4', colorCross );
  26244. function addLine( a, b, color ) {
  26245. addPoint( a, color );
  26246. addPoint( b, color );
  26247. }
  26248. function addPoint( id, color ) {
  26249. vertices.push( 0, 0, 0 );
  26250. colors.push( color.r, color.g, color.b );
  26251. if ( pointMap[ id ] === undefined ) {
  26252. pointMap[ id ] = [];
  26253. }
  26254. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  26255. }
  26256. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26257. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26258. LineSegments.call( this, geometry, material );
  26259. this.camera = camera;
  26260. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  26261. this.matrix = camera.matrixWorld;
  26262. this.matrixAutoUpdate = false;
  26263. this.pointMap = pointMap;
  26264. this.update();
  26265. }
  26266. CameraHelper.prototype = Object.create( LineSegments.prototype );
  26267. CameraHelper.prototype.constructor = CameraHelper;
  26268. CameraHelper.prototype.update = function () {
  26269. var geometry, pointMap;
  26270. var vector = new Vector3();
  26271. var camera = new Camera();
  26272. function setPoint( point, x, y, z ) {
  26273. vector.set( x, y, z ).unproject( camera );
  26274. var points = pointMap[ point ];
  26275. if ( points !== undefined ) {
  26276. var position = geometry.getAttribute( 'position' );
  26277. for ( var i = 0, l = points.length; i < l; i ++ ) {
  26278. position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
  26279. }
  26280. }
  26281. }
  26282. return function update() {
  26283. geometry = this.geometry;
  26284. pointMap = this.pointMap;
  26285. var w = 1, h = 1;
  26286. // we need just camera projection matrix
  26287. // world matrix must be identity
  26288. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  26289. // center / target
  26290. setPoint( 'c', 0, 0, - 1 );
  26291. setPoint( 't', 0, 0, 1 );
  26292. // near
  26293. setPoint( 'n1', - w, - h, - 1 );
  26294. setPoint( 'n2', w, - h, - 1 );
  26295. setPoint( 'n3', - w, h, - 1 );
  26296. setPoint( 'n4', w, h, - 1 );
  26297. // far
  26298. setPoint( 'f1', - w, - h, 1 );
  26299. setPoint( 'f2', w, - h, 1 );
  26300. setPoint( 'f3', - w, h, 1 );
  26301. setPoint( 'f4', w, h, 1 );
  26302. // up
  26303. setPoint( 'u1', w * 0.7, h * 1.1, - 1 );
  26304. setPoint( 'u2', - w * 0.7, h * 1.1, - 1 );
  26305. setPoint( 'u3', 0, h * 2, - 1 );
  26306. // cross
  26307. setPoint( 'cf1', - w, 0, 1 );
  26308. setPoint( 'cf2', w, 0, 1 );
  26309. setPoint( 'cf3', 0, - h, 1 );
  26310. setPoint( 'cf4', 0, h, 1 );
  26311. setPoint( 'cn1', - w, 0, - 1 );
  26312. setPoint( 'cn2', w, 0, - 1 );
  26313. setPoint( 'cn3', 0, - h, - 1 );
  26314. setPoint( 'cn4', 0, h, - 1 );
  26315. geometry.getAttribute( 'position' ).needsUpdate = true;
  26316. };
  26317. }();
  26318. /**
  26319. * @author mrdoob / http://mrdoob.com/
  26320. * @author Mugen87 / http://github.com/Mugen87
  26321. */
  26322. function BoxHelper( object, color ) {
  26323. this.object = object;
  26324. if ( color === undefined ) color = 0xffff00;
  26325. 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 ] );
  26326. var positions = new Float32Array( 8 * 3 );
  26327. var geometry = new BufferGeometry();
  26328. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  26329. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  26330. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  26331. this.matrixAutoUpdate = false;
  26332. this.update();
  26333. }
  26334. BoxHelper.prototype = Object.create( LineSegments.prototype );
  26335. BoxHelper.prototype.constructor = BoxHelper;
  26336. BoxHelper.prototype.update = ( function () {
  26337. var box = new Box3();
  26338. return function update( object ) {
  26339. if ( object !== undefined ) {
  26340. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  26341. }
  26342. if ( this.object !== undefined ) {
  26343. box.setFromObject( this.object );
  26344. }
  26345. if ( box.isEmpty() ) return;
  26346. var min = box.min;
  26347. var max = box.max;
  26348. /*
  26349. 5____4
  26350. 1/___0/|
  26351. | 6__|_7
  26352. 2/___3/
  26353. 0: max.x, max.y, max.z
  26354. 1: min.x, max.y, max.z
  26355. 2: min.x, min.y, max.z
  26356. 3: max.x, min.y, max.z
  26357. 4: max.x, max.y, min.z
  26358. 5: min.x, max.y, min.z
  26359. 6: min.x, min.y, min.z
  26360. 7: max.x, min.y, min.z
  26361. */
  26362. var position = this.geometry.attributes.position;
  26363. var array = position.array;
  26364. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  26365. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  26366. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  26367. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  26368. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  26369. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  26370. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  26371. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  26372. position.needsUpdate = true;
  26373. this.geometry.computeBoundingSphere();
  26374. };
  26375. } )();
  26376. BoxHelper.prototype.setFromObject = function ( object ) {
  26377. this.object = object;
  26378. this.update();
  26379. return this;
  26380. };
  26381. /**
  26382. * @author WestLangley / http://github.com/WestLangley
  26383. */
  26384. function Box3Helper( box, hex ) {
  26385. this.type = 'Box3Helper';
  26386. this.box = box;
  26387. var color = ( hex !== undefined ) ? hex : 0xffff00;
  26388. 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 ] );
  26389. 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 ];
  26390. var geometry = new BufferGeometry();
  26391. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  26392. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  26393. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  26394. this.geometry.computeBoundingSphere();
  26395. }
  26396. Box3Helper.prototype = Object.create( LineSegments.prototype );
  26397. Box3Helper.prototype.constructor = Box3Helper;
  26398. Box3Helper.prototype.updateMatrixWorld = function ( force ) {
  26399. var box = this.box;
  26400. if ( box.isEmpty() ) return;
  26401. box.getCenter( this.position );
  26402. box.getSize( this.scale );
  26403. this.scale.multiplyScalar( 0.5 );
  26404. Object3D.prototype.updateMatrixWorld.call( this, force );
  26405. };
  26406. /**
  26407. * @author WestLangley / http://github.com/WestLangley
  26408. */
  26409. function PlaneHelper( plane, size, hex ) {
  26410. this.type = 'PlaneHelper';
  26411. this.plane = plane;
  26412. this.size = ( size === undefined ) ? 1 : size;
  26413. var color = ( hex !== undefined ) ? hex : 0xffff00;
  26414. 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 ];
  26415. var geometry = new BufferGeometry();
  26416. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  26417. geometry.computeBoundingSphere();
  26418. Line.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  26419. //
  26420. var positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  26421. var geometry2 = new BufferGeometry();
  26422. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  26423. geometry2.computeBoundingSphere();
  26424. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false } ) ) );
  26425. }
  26426. PlaneHelper.prototype = Object.create( Line.prototype );
  26427. PlaneHelper.prototype.constructor = PlaneHelper;
  26428. PlaneHelper.prototype.updateMatrixWorld = function ( force ) {
  26429. var scale = - this.plane.constant;
  26430. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  26431. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  26432. this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  26433. this.lookAt( this.plane.normal );
  26434. Object3D.prototype.updateMatrixWorld.call( this, force );
  26435. };
  26436. /**
  26437. * @author WestLangley / http://github.com/WestLangley
  26438. * @author zz85 / http://github.com/zz85
  26439. * @author bhouston / http://clara.io
  26440. *
  26441. * Creates an arrow for visualizing directions
  26442. *
  26443. * Parameters:
  26444. * dir - Vector3
  26445. * origin - Vector3
  26446. * length - Number
  26447. * color - color in hex value
  26448. * headLength - Number
  26449. * headWidth - Number
  26450. */
  26451. var lineGeometry;
  26452. var coneGeometry;
  26453. function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  26454. // dir is assumed to be normalized
  26455. Object3D.call( this );
  26456. if ( color === undefined ) color = 0xffff00;
  26457. if ( length === undefined ) length = 1;
  26458. if ( headLength === undefined ) headLength = 0.2 * length;
  26459. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  26460. if ( lineGeometry === undefined ) {
  26461. lineGeometry = new BufferGeometry();
  26462. lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  26463. coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  26464. coneGeometry.translate( 0, - 0.5, 0 );
  26465. }
  26466. this.position.copy( origin );
  26467. this.line = new Line( lineGeometry, new LineBasicMaterial( { color: color } ) );
  26468. this.line.matrixAutoUpdate = false;
  26469. this.add( this.line );
  26470. this.cone = new Mesh( coneGeometry, new MeshBasicMaterial( { color: color } ) );
  26471. this.cone.matrixAutoUpdate = false;
  26472. this.add( this.cone );
  26473. this.setDirection( dir );
  26474. this.setLength( length, headLength, headWidth );
  26475. }
  26476. ArrowHelper.prototype = Object.create( Object3D.prototype );
  26477. ArrowHelper.prototype.constructor = ArrowHelper;
  26478. ArrowHelper.prototype.setDirection = ( function () {
  26479. var axis = new Vector3();
  26480. var radians;
  26481. return function setDirection( dir ) {
  26482. // dir is assumed to be normalized
  26483. if ( dir.y > 0.99999 ) {
  26484. this.quaternion.set( 0, 0, 0, 1 );
  26485. } else if ( dir.y < - 0.99999 ) {
  26486. this.quaternion.set( 1, 0, 0, 0 );
  26487. } else {
  26488. axis.set( dir.z, 0, - dir.x ).normalize();
  26489. radians = Math.acos( dir.y );
  26490. this.quaternion.setFromAxisAngle( axis, radians );
  26491. }
  26492. };
  26493. }() );
  26494. ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  26495. if ( headLength === undefined ) headLength = 0.2 * length;
  26496. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  26497. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  26498. this.line.updateMatrix();
  26499. this.cone.scale.set( headWidth, headLength, headWidth );
  26500. this.cone.position.y = length;
  26501. this.cone.updateMatrix();
  26502. };
  26503. ArrowHelper.prototype.setColor = function ( color ) {
  26504. this.line.material.color.copy( color );
  26505. this.cone.material.color.copy( color );
  26506. };
  26507. /**
  26508. * @author sroucheray / http://sroucheray.org/
  26509. * @author mrdoob / http://mrdoob.com/
  26510. */
  26511. function AxesHelper( size ) {
  26512. size = size || 1;
  26513. var vertices = [
  26514. 0, 0, 0, size, 0, 0,
  26515. 0, 0, 0, 0, size, 0,
  26516. 0, 0, 0, 0, 0, size
  26517. ];
  26518. var colors = [
  26519. 1, 0, 0, 1, 0.6, 0,
  26520. 0, 1, 0, 0.6, 1, 0,
  26521. 0, 0, 1, 0, 0.6, 1
  26522. ];
  26523. var geometry = new BufferGeometry();
  26524. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26525. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26526. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  26527. LineSegments.call( this, geometry, material );
  26528. }
  26529. AxesHelper.prototype = Object.create( LineSegments.prototype );
  26530. AxesHelper.prototype.constructor = AxesHelper;
  26531. /**
  26532. * @author mrdoob / http://mrdoob.com/
  26533. */
  26534. function Face4( a, b, c, d, normal, color, materialIndex ) {
  26535. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  26536. return new Face3( a, b, c, normal, color, materialIndex );
  26537. }
  26538. var LineStrip = 0;
  26539. var LinePieces = 1;
  26540. function MeshFaceMaterial( materials ) {
  26541. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  26542. return materials;
  26543. }
  26544. function MultiMaterial( materials ) {
  26545. if ( materials === undefined ) materials = [];
  26546. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  26547. materials.isMultiMaterial = true;
  26548. materials.materials = materials;
  26549. materials.clone = function () {
  26550. return materials.slice();
  26551. };
  26552. return materials;
  26553. }
  26554. function PointCloud( geometry, material ) {
  26555. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  26556. return new Points( geometry, material );
  26557. }
  26558. function Particle( material ) {
  26559. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  26560. return new Sprite( material );
  26561. }
  26562. function ParticleSystem( geometry, material ) {
  26563. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  26564. return new Points( geometry, material );
  26565. }
  26566. function PointCloudMaterial( parameters ) {
  26567. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  26568. return new PointsMaterial( parameters );
  26569. }
  26570. function ParticleBasicMaterial( parameters ) {
  26571. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  26572. return new PointsMaterial( parameters );
  26573. }
  26574. function ParticleSystemMaterial( parameters ) {
  26575. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  26576. return new PointsMaterial( parameters );
  26577. }
  26578. function Vertex( x, y, z ) {
  26579. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  26580. return new Vector3( x, y, z );
  26581. }
  26582. //
  26583. function DynamicBufferAttribute( array, itemSize ) {
  26584. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  26585. return new BufferAttribute( array, itemSize ).setDynamic( true );
  26586. }
  26587. function Int8Attribute( array, itemSize ) {
  26588. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  26589. return new Int8BufferAttribute( array, itemSize );
  26590. }
  26591. function Uint8Attribute( array, itemSize ) {
  26592. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  26593. return new Uint8BufferAttribute( array, itemSize );
  26594. }
  26595. function Uint8ClampedAttribute( array, itemSize ) {
  26596. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  26597. return new Uint8ClampedBufferAttribute( array, itemSize );
  26598. }
  26599. function Int16Attribute( array, itemSize ) {
  26600. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  26601. return new Int16BufferAttribute( array, itemSize );
  26602. }
  26603. function Uint16Attribute( array, itemSize ) {
  26604. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  26605. return new Uint16BufferAttribute( array, itemSize );
  26606. }
  26607. function Int32Attribute( array, itemSize ) {
  26608. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  26609. return new Int32BufferAttribute( array, itemSize );
  26610. }
  26611. function Uint32Attribute( array, itemSize ) {
  26612. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  26613. return new Uint32BufferAttribute( array, itemSize );
  26614. }
  26615. function Float32Attribute( array, itemSize ) {
  26616. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  26617. return new Float32BufferAttribute( array, itemSize );
  26618. }
  26619. function Float64Attribute( array, itemSize ) {
  26620. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  26621. return new Float64BufferAttribute( array, itemSize );
  26622. }
  26623. //
  26624. Curve.create = function ( construct, getPoint ) {
  26625. console.log( 'THREE.Curve.create() has been deprecated' );
  26626. construct.prototype = Object.create( Curve.prototype );
  26627. construct.prototype.constructor = construct;
  26628. construct.prototype.getPoint = getPoint;
  26629. return construct;
  26630. };
  26631. //
  26632. Object.assign( CurvePath.prototype, {
  26633. createPointsGeometry: function ( divisions ) {
  26634. console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  26635. // generate geometry from path points (for Line or Points objects)
  26636. var pts = this.getPoints( divisions );
  26637. return this.createGeometry( pts );
  26638. },
  26639. createSpacedPointsGeometry: function ( divisions ) {
  26640. console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  26641. // generate geometry from equidistant sampling along the path
  26642. var pts = this.getSpacedPoints( divisions );
  26643. return this.createGeometry( pts );
  26644. },
  26645. createGeometry: function ( points ) {
  26646. console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  26647. var geometry = new Geometry();
  26648. for ( var i = 0, l = points.length; i < l; i ++ ) {
  26649. var point = points[ i ];
  26650. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  26651. }
  26652. return geometry;
  26653. }
  26654. } );
  26655. //
  26656. Object.assign( Path.prototype, {
  26657. fromPoints: function ( points ) {
  26658. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  26659. this.setFromPoints( points );
  26660. }
  26661. } );
  26662. //
  26663. function ClosedSplineCurve3( points ) {
  26664. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  26665. CatmullRomCurve3.call( this, points );
  26666. this.type = 'catmullrom';
  26667. this.closed = true;
  26668. }
  26669. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  26670. //
  26671. function SplineCurve3( points ) {
  26672. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  26673. CatmullRomCurve3.call( this, points );
  26674. this.type = 'catmullrom';
  26675. }
  26676. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  26677. //
  26678. function Spline( points ) {
  26679. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  26680. CatmullRomCurve3.call( this, points );
  26681. this.type = 'catmullrom';
  26682. }
  26683. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  26684. Object.assign( Spline.prototype, {
  26685. initFromArray: function ( /* a */ ) {
  26686. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  26687. },
  26688. getControlPointsArray: function ( /* optionalTarget */ ) {
  26689. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  26690. },
  26691. reparametrizeByArcLength: function ( /* samplingCoef */ ) {
  26692. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  26693. }
  26694. } );
  26695. //
  26696. function AxisHelper( size ) {
  26697. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  26698. return new AxesHelper( size );
  26699. }
  26700. function BoundingBoxHelper( object, color ) {
  26701. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  26702. return new BoxHelper( object, color );
  26703. }
  26704. function EdgesHelper( object, hex ) {
  26705. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  26706. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  26707. }
  26708. GridHelper.prototype.setColors = function () {
  26709. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  26710. };
  26711. SkeletonHelper.prototype.update = function () {
  26712. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  26713. };
  26714. function WireframeHelper( object, hex ) {
  26715. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  26716. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  26717. }
  26718. //
  26719. Object.assign( Loader.prototype, {
  26720. extractUrlBase: function ( url ) {
  26721. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  26722. return LoaderUtils.extractUrlBase( url );
  26723. }
  26724. } );
  26725. function XHRLoader( manager ) {
  26726. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  26727. return new FileLoader( manager );
  26728. }
  26729. function BinaryTextureLoader( manager ) {
  26730. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  26731. return new DataTextureLoader( manager );
  26732. }
  26733. //
  26734. Object.assign( Box2.prototype, {
  26735. center: function ( optionalTarget ) {
  26736. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  26737. return this.getCenter( optionalTarget );
  26738. },
  26739. empty: function () {
  26740. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  26741. return this.isEmpty();
  26742. },
  26743. isIntersectionBox: function ( box ) {
  26744. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  26745. return this.intersectsBox( box );
  26746. },
  26747. size: function ( optionalTarget ) {
  26748. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  26749. return this.getSize( optionalTarget );
  26750. }
  26751. } );
  26752. Object.assign( Box3.prototype, {
  26753. center: function ( optionalTarget ) {
  26754. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  26755. return this.getCenter( optionalTarget );
  26756. },
  26757. empty: function () {
  26758. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  26759. return this.isEmpty();
  26760. },
  26761. isIntersectionBox: function ( box ) {
  26762. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  26763. return this.intersectsBox( box );
  26764. },
  26765. isIntersectionSphere: function ( sphere ) {
  26766. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  26767. return this.intersectsSphere( sphere );
  26768. },
  26769. size: function ( optionalTarget ) {
  26770. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  26771. return this.getSize( optionalTarget );
  26772. }
  26773. } );
  26774. Line3.prototype.center = function ( optionalTarget ) {
  26775. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  26776. return this.getCenter( optionalTarget );
  26777. };
  26778. Object.assign( _Math, {
  26779. random16: function () {
  26780. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  26781. return Math.random();
  26782. },
  26783. nearestPowerOfTwo: function ( value ) {
  26784. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  26785. return _Math.floorPowerOfTwo( value );
  26786. },
  26787. nextPowerOfTwo: function ( value ) {
  26788. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  26789. return _Math.ceilPowerOfTwo( value );
  26790. }
  26791. } );
  26792. Object.assign( Matrix3.prototype, {
  26793. flattenToArrayOffset: function ( array, offset ) {
  26794. console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  26795. return this.toArray( array, offset );
  26796. },
  26797. multiplyVector3: function ( vector ) {
  26798. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  26799. return vector.applyMatrix3( this );
  26800. },
  26801. multiplyVector3Array: function ( /* a */ ) {
  26802. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  26803. },
  26804. applyToBuffer: function ( buffer /*, offset, length */ ) {
  26805. console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  26806. return this.applyToBufferAttribute( buffer );
  26807. },
  26808. applyToVector3Array: function ( /* array, offset, length */ ) {
  26809. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  26810. }
  26811. } );
  26812. Object.assign( Matrix4.prototype, {
  26813. extractPosition: function ( m ) {
  26814. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  26815. return this.copyPosition( m );
  26816. },
  26817. flattenToArrayOffset: function ( array, offset ) {
  26818. console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  26819. return this.toArray( array, offset );
  26820. },
  26821. getPosition: function () {
  26822. var v1;
  26823. return function getPosition() {
  26824. if ( v1 === undefined ) v1 = new Vector3();
  26825. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  26826. return v1.setFromMatrixColumn( this, 3 );
  26827. };
  26828. }(),
  26829. setRotationFromQuaternion: function ( q ) {
  26830. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  26831. return this.makeRotationFromQuaternion( q );
  26832. },
  26833. multiplyToArray: function () {
  26834. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  26835. },
  26836. multiplyVector3: function ( vector ) {
  26837. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  26838. return vector.applyMatrix4( this );
  26839. },
  26840. multiplyVector4: function ( vector ) {
  26841. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  26842. return vector.applyMatrix4( this );
  26843. },
  26844. multiplyVector3Array: function ( /* a */ ) {
  26845. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  26846. },
  26847. rotateAxis: function ( v ) {
  26848. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  26849. v.transformDirection( this );
  26850. },
  26851. crossVector: function ( vector ) {
  26852. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  26853. return vector.applyMatrix4( this );
  26854. },
  26855. translate: function () {
  26856. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  26857. },
  26858. rotateX: function () {
  26859. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  26860. },
  26861. rotateY: function () {
  26862. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  26863. },
  26864. rotateZ: function () {
  26865. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  26866. },
  26867. rotateByAxis: function () {
  26868. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  26869. },
  26870. applyToBuffer: function ( buffer /*, offset, length */ ) {
  26871. console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  26872. return this.applyToBufferAttribute( buffer );
  26873. },
  26874. applyToVector3Array: function ( /* array, offset, length */ ) {
  26875. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  26876. },
  26877. makeFrustum: function ( left, right, bottom, top, near, far ) {
  26878. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  26879. return this.makePerspective( left, right, top, bottom, near, far );
  26880. }
  26881. } );
  26882. Plane.prototype.isIntersectionLine = function ( line ) {
  26883. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  26884. return this.intersectsLine( line );
  26885. };
  26886. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  26887. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  26888. return vector.applyQuaternion( this );
  26889. };
  26890. Object.assign( Ray.prototype, {
  26891. isIntersectionBox: function ( box ) {
  26892. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  26893. return this.intersectsBox( box );
  26894. },
  26895. isIntersectionPlane: function ( plane ) {
  26896. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  26897. return this.intersectsPlane( plane );
  26898. },
  26899. isIntersectionSphere: function ( sphere ) {
  26900. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  26901. return this.intersectsSphere( sphere );
  26902. }
  26903. } );
  26904. Object.assign( Triangle.prototype, {
  26905. area: function () {
  26906. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  26907. return this.getArea();
  26908. },
  26909. barycoordFromPoint: function ( point, target ) {
  26910. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  26911. return this.getBarycoord( point, target );
  26912. },
  26913. midpoint: function ( target ) {
  26914. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  26915. return this.getMidpoint( target );
  26916. },
  26917. normal: function ( target ) {
  26918. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  26919. return this.getNormal( target );
  26920. },
  26921. plane: function ( target ) {
  26922. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  26923. return this.getPlane( target );
  26924. }
  26925. } );
  26926. Object.assign( Triangle, {
  26927. barycoordFromPoint: function ( point, a, b, c, target ) {
  26928. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  26929. return Triangle.getBarycoord( point, a, b, c, target );
  26930. },
  26931. normal: function ( a, b, c, target ) {
  26932. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  26933. return Triangle.getNormal( a, b, c, target );
  26934. }
  26935. } );
  26936. Object.assign( Shape.prototype, {
  26937. extractAllPoints: function ( divisions ) {
  26938. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  26939. return this.extractPoints( divisions );
  26940. },
  26941. extrude: function ( options ) {
  26942. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  26943. return new ExtrudeGeometry( this, options );
  26944. },
  26945. makeGeometry: function ( options ) {
  26946. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  26947. return new ShapeGeometry( this, options );
  26948. }
  26949. } );
  26950. Object.assign( Vector2.prototype, {
  26951. fromAttribute: function ( attribute, index, offset ) {
  26952. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  26953. return this.fromBufferAttribute( attribute, index, offset );
  26954. },
  26955. distanceToManhattan: function ( v ) {
  26956. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  26957. return this.manhattanDistanceTo( v );
  26958. },
  26959. lengthManhattan: function () {
  26960. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  26961. return this.manhattanLength();
  26962. }
  26963. } );
  26964. Object.assign( Vector3.prototype, {
  26965. setEulerFromRotationMatrix: function () {
  26966. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  26967. },
  26968. setEulerFromQuaternion: function () {
  26969. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  26970. },
  26971. getPositionFromMatrix: function ( m ) {
  26972. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  26973. return this.setFromMatrixPosition( m );
  26974. },
  26975. getScaleFromMatrix: function ( m ) {
  26976. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  26977. return this.setFromMatrixScale( m );
  26978. },
  26979. getColumnFromMatrix: function ( index, matrix ) {
  26980. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  26981. return this.setFromMatrixColumn( matrix, index );
  26982. },
  26983. applyProjection: function ( m ) {
  26984. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  26985. return this.applyMatrix4( m );
  26986. },
  26987. fromAttribute: function ( attribute, index, offset ) {
  26988. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  26989. return this.fromBufferAttribute( attribute, index, offset );
  26990. },
  26991. distanceToManhattan: function ( v ) {
  26992. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  26993. return this.manhattanDistanceTo( v );
  26994. },
  26995. lengthManhattan: function () {
  26996. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  26997. return this.manhattanLength();
  26998. }
  26999. } );
  27000. Object.assign( Vector4.prototype, {
  27001. fromAttribute: function ( attribute, index, offset ) {
  27002. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  27003. return this.fromBufferAttribute( attribute, index, offset );
  27004. },
  27005. lengthManhattan: function () {
  27006. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  27007. return this.manhattanLength();
  27008. }
  27009. } );
  27010. //
  27011. Object.assign( Geometry.prototype, {
  27012. computeTangents: function () {
  27013. console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
  27014. },
  27015. computeLineDistances: function () {
  27016. console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
  27017. }
  27018. } );
  27019. Object.assign( Object3D.prototype, {
  27020. getChildByName: function ( name ) {
  27021. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  27022. return this.getObjectByName( name );
  27023. },
  27024. renderDepth: function () {
  27025. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  27026. },
  27027. translate: function ( distance, axis ) {
  27028. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  27029. return this.translateOnAxis( axis, distance );
  27030. },
  27031. getWorldRotation: function () {
  27032. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  27033. }
  27034. } );
  27035. Object.defineProperties( Object3D.prototype, {
  27036. eulerOrder: {
  27037. get: function () {
  27038. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  27039. return this.rotation.order;
  27040. },
  27041. set: function ( value ) {
  27042. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  27043. this.rotation.order = value;
  27044. }
  27045. },
  27046. useQuaternion: {
  27047. get: function () {
  27048. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  27049. },
  27050. set: function () {
  27051. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  27052. }
  27053. }
  27054. } );
  27055. Object.defineProperties( LOD.prototype, {
  27056. objects: {
  27057. get: function () {
  27058. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  27059. return this.levels;
  27060. }
  27061. }
  27062. } );
  27063. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  27064. get: function () {
  27065. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  27066. },
  27067. set: function () {
  27068. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  27069. }
  27070. } );
  27071. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  27072. get: function () {
  27073. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  27074. return this.arcLengthDivisions;
  27075. },
  27076. set: function ( value ) {
  27077. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  27078. this.arcLengthDivisions = value;
  27079. }
  27080. } );
  27081. //
  27082. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  27083. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  27084. "Use .setFocalLength and .filmGauge for a photographic setup." );
  27085. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  27086. this.setFocalLength( focalLength );
  27087. };
  27088. //
  27089. Object.defineProperties( Light.prototype, {
  27090. onlyShadow: {
  27091. set: function () {
  27092. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  27093. }
  27094. },
  27095. shadowCameraFov: {
  27096. set: function ( value ) {
  27097. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  27098. this.shadow.camera.fov = value;
  27099. }
  27100. },
  27101. shadowCameraLeft: {
  27102. set: function ( value ) {
  27103. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  27104. this.shadow.camera.left = value;
  27105. }
  27106. },
  27107. shadowCameraRight: {
  27108. set: function ( value ) {
  27109. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  27110. this.shadow.camera.right = value;
  27111. }
  27112. },
  27113. shadowCameraTop: {
  27114. set: function ( value ) {
  27115. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  27116. this.shadow.camera.top = value;
  27117. }
  27118. },
  27119. shadowCameraBottom: {
  27120. set: function ( value ) {
  27121. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  27122. this.shadow.camera.bottom = value;
  27123. }
  27124. },
  27125. shadowCameraNear: {
  27126. set: function ( value ) {
  27127. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  27128. this.shadow.camera.near = value;
  27129. }
  27130. },
  27131. shadowCameraFar: {
  27132. set: function ( value ) {
  27133. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  27134. this.shadow.camera.far = value;
  27135. }
  27136. },
  27137. shadowCameraVisible: {
  27138. set: function () {
  27139. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  27140. }
  27141. },
  27142. shadowBias: {
  27143. set: function ( value ) {
  27144. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  27145. this.shadow.bias = value;
  27146. }
  27147. },
  27148. shadowDarkness: {
  27149. set: function () {
  27150. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  27151. }
  27152. },
  27153. shadowMapWidth: {
  27154. set: function ( value ) {
  27155. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  27156. this.shadow.mapSize.width = value;
  27157. }
  27158. },
  27159. shadowMapHeight: {
  27160. set: function ( value ) {
  27161. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  27162. this.shadow.mapSize.height = value;
  27163. }
  27164. }
  27165. } );
  27166. //
  27167. Object.defineProperties( BufferAttribute.prototype, {
  27168. length: {
  27169. get: function () {
  27170. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  27171. return this.array.length;
  27172. }
  27173. },
  27174. copyIndicesArray: function ( /* indices */ ) {
  27175. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  27176. }
  27177. } );
  27178. Object.assign( BufferGeometry.prototype, {
  27179. addIndex: function ( index ) {
  27180. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  27181. this.setIndex( index );
  27182. },
  27183. addDrawCall: function ( start, count, indexOffset ) {
  27184. if ( indexOffset !== undefined ) {
  27185. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  27186. }
  27187. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  27188. this.addGroup( start, count );
  27189. },
  27190. clearDrawCalls: function () {
  27191. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  27192. this.clearGroups();
  27193. },
  27194. computeTangents: function () {
  27195. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  27196. },
  27197. computeOffsets: function () {
  27198. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  27199. }
  27200. } );
  27201. Object.defineProperties( BufferGeometry.prototype, {
  27202. drawcalls: {
  27203. get: function () {
  27204. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  27205. return this.groups;
  27206. }
  27207. },
  27208. offsets: {
  27209. get: function () {
  27210. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  27211. return this.groups;
  27212. }
  27213. }
  27214. } );
  27215. //
  27216. Object.assign( ExtrudeBufferGeometry.prototype, {
  27217. getArrays: function () {
  27218. console.error( 'THREE.ExtrudeBufferGeometry: .getArrays() has been removed.' );
  27219. },
  27220. addShapeList: function () {
  27221. console.error( 'THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.' );
  27222. },
  27223. addShape: function () {
  27224. console.error( 'THREE.ExtrudeBufferGeometry: .addShape() has been removed.' );
  27225. }
  27226. } );
  27227. //
  27228. Object.defineProperties( Uniform.prototype, {
  27229. dynamic: {
  27230. set: function () {
  27231. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  27232. }
  27233. },
  27234. onUpdate: {
  27235. value: function () {
  27236. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  27237. return this;
  27238. }
  27239. }
  27240. } );
  27241. //
  27242. Object.defineProperties( Material.prototype, {
  27243. wrapAround: {
  27244. get: function () {
  27245. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  27246. },
  27247. set: function () {
  27248. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  27249. }
  27250. },
  27251. wrapRGB: {
  27252. get: function () {
  27253. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  27254. return new Color();
  27255. }
  27256. },
  27257. shading: {
  27258. get: function () {
  27259. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  27260. },
  27261. set: function ( value ) {
  27262. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  27263. this.flatShading = ( value === FlatShading );
  27264. }
  27265. }
  27266. } );
  27267. Object.defineProperties( MeshPhongMaterial.prototype, {
  27268. metal: {
  27269. get: function () {
  27270. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  27271. return false;
  27272. },
  27273. set: function () {
  27274. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  27275. }
  27276. }
  27277. } );
  27278. Object.defineProperties( ShaderMaterial.prototype, {
  27279. derivatives: {
  27280. get: function () {
  27281. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  27282. return this.extensions.derivatives;
  27283. },
  27284. set: function ( value ) {
  27285. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  27286. this.extensions.derivatives = value;
  27287. }
  27288. }
  27289. } );
  27290. //
  27291. Object.assign( WebGLRenderer.prototype, {
  27292. animate: function ( callback ) {
  27293. console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' );
  27294. this.setAnimationLoop( callback );
  27295. },
  27296. getCurrentRenderTarget: function () {
  27297. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  27298. return this.getRenderTarget();
  27299. },
  27300. getMaxAnisotropy: function () {
  27301. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  27302. return this.capabilities.getMaxAnisotropy();
  27303. },
  27304. getPrecision: function () {
  27305. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  27306. return this.capabilities.precision;
  27307. },
  27308. resetGLState: function () {
  27309. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  27310. return this.state.reset();
  27311. },
  27312. supportsFloatTextures: function () {
  27313. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  27314. return this.extensions.get( 'OES_texture_float' );
  27315. },
  27316. supportsHalfFloatTextures: function () {
  27317. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  27318. return this.extensions.get( 'OES_texture_half_float' );
  27319. },
  27320. supportsStandardDerivatives: function () {
  27321. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  27322. return this.extensions.get( 'OES_standard_derivatives' );
  27323. },
  27324. supportsCompressedTextureS3TC: function () {
  27325. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  27326. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  27327. },
  27328. supportsCompressedTexturePVRTC: function () {
  27329. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  27330. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  27331. },
  27332. supportsBlendMinMax: function () {
  27333. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  27334. return this.extensions.get( 'EXT_blend_minmax' );
  27335. },
  27336. supportsVertexTextures: function () {
  27337. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  27338. return this.capabilities.vertexTextures;
  27339. },
  27340. supportsInstancedArrays: function () {
  27341. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  27342. return this.extensions.get( 'ANGLE_instanced_arrays' );
  27343. },
  27344. enableScissorTest: function ( boolean ) {
  27345. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  27346. this.setScissorTest( boolean );
  27347. },
  27348. initMaterial: function () {
  27349. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  27350. },
  27351. addPrePlugin: function () {
  27352. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  27353. },
  27354. addPostPlugin: function () {
  27355. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  27356. },
  27357. updateShadowMap: function () {
  27358. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  27359. },
  27360. setFaceCulling: function () {
  27361. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  27362. }
  27363. } );
  27364. Object.defineProperties( WebGLRenderer.prototype, {
  27365. shadowMapEnabled: {
  27366. get: function () {
  27367. return this.shadowMap.enabled;
  27368. },
  27369. set: function ( value ) {
  27370. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  27371. this.shadowMap.enabled = value;
  27372. }
  27373. },
  27374. shadowMapType: {
  27375. get: function () {
  27376. return this.shadowMap.type;
  27377. },
  27378. set: function ( value ) {
  27379. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  27380. this.shadowMap.type = value;
  27381. }
  27382. },
  27383. shadowMapCullFace: {
  27384. get: function () {
  27385. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  27386. return undefined;
  27387. },
  27388. set: function ( /* value */ ) {
  27389. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  27390. }
  27391. }
  27392. } );
  27393. Object.defineProperties( WebGLShadowMap.prototype, {
  27394. cullFace: {
  27395. get: function () {
  27396. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  27397. return undefined;
  27398. },
  27399. set: function ( /* cullFace */ ) {
  27400. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  27401. }
  27402. },
  27403. renderReverseSided: {
  27404. get: function () {
  27405. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  27406. return undefined;
  27407. },
  27408. set: function () {
  27409. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  27410. }
  27411. },
  27412. renderSingleSided: {
  27413. get: function () {
  27414. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  27415. return undefined;
  27416. },
  27417. set: function () {
  27418. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  27419. }
  27420. }
  27421. } );
  27422. //
  27423. Object.defineProperties( WebGLRenderTarget.prototype, {
  27424. wrapS: {
  27425. get: function () {
  27426. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  27427. return this.texture.wrapS;
  27428. },
  27429. set: function ( value ) {
  27430. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  27431. this.texture.wrapS = value;
  27432. }
  27433. },
  27434. wrapT: {
  27435. get: function () {
  27436. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  27437. return this.texture.wrapT;
  27438. },
  27439. set: function ( value ) {
  27440. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  27441. this.texture.wrapT = value;
  27442. }
  27443. },
  27444. magFilter: {
  27445. get: function () {
  27446. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  27447. return this.texture.magFilter;
  27448. },
  27449. set: function ( value ) {
  27450. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  27451. this.texture.magFilter = value;
  27452. }
  27453. },
  27454. minFilter: {
  27455. get: function () {
  27456. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  27457. return this.texture.minFilter;
  27458. },
  27459. set: function ( value ) {
  27460. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  27461. this.texture.minFilter = value;
  27462. }
  27463. },
  27464. anisotropy: {
  27465. get: function () {
  27466. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  27467. return this.texture.anisotropy;
  27468. },
  27469. set: function ( value ) {
  27470. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  27471. this.texture.anisotropy = value;
  27472. }
  27473. },
  27474. offset: {
  27475. get: function () {
  27476. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  27477. return this.texture.offset;
  27478. },
  27479. set: function ( value ) {
  27480. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  27481. this.texture.offset = value;
  27482. }
  27483. },
  27484. repeat: {
  27485. get: function () {
  27486. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  27487. return this.texture.repeat;
  27488. },
  27489. set: function ( value ) {
  27490. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  27491. this.texture.repeat = value;
  27492. }
  27493. },
  27494. format: {
  27495. get: function () {
  27496. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  27497. return this.texture.format;
  27498. },
  27499. set: function ( value ) {
  27500. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  27501. this.texture.format = value;
  27502. }
  27503. },
  27504. type: {
  27505. get: function () {
  27506. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  27507. return this.texture.type;
  27508. },
  27509. set: function ( value ) {
  27510. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  27511. this.texture.type = value;
  27512. }
  27513. },
  27514. generateMipmaps: {
  27515. get: function () {
  27516. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  27517. return this.texture.generateMipmaps;
  27518. },
  27519. set: function ( value ) {
  27520. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  27521. this.texture.generateMipmaps = value;
  27522. }
  27523. }
  27524. } );
  27525. //
  27526. Object.defineProperties( WebVRManager.prototype, {
  27527. standing: {
  27528. set: function ( /* value */ ) {
  27529. console.warn( 'THREE.WebVRManager: .standing has been removed.' );
  27530. }
  27531. }
  27532. } );
  27533. //
  27534. Audio.prototype.load = function ( file ) {
  27535. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  27536. var scope = this;
  27537. var audioLoader = new AudioLoader();
  27538. audioLoader.load( file, function ( buffer ) {
  27539. scope.setBuffer( buffer );
  27540. } );
  27541. return this;
  27542. };
  27543. AudioAnalyser.prototype.getData = function () {
  27544. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  27545. return this.getFrequencyData();
  27546. };
  27547. //
  27548. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  27549. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  27550. return this.update( renderer, scene );
  27551. };
  27552. //
  27553. var GeometryUtils = {
  27554. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  27555. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  27556. var matrix;
  27557. if ( geometry2.isMesh ) {
  27558. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  27559. matrix = geometry2.matrix;
  27560. geometry2 = geometry2.geometry;
  27561. }
  27562. geometry1.merge( geometry2, matrix, materialIndexOffset );
  27563. },
  27564. center: function ( geometry ) {
  27565. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  27566. return geometry.center();
  27567. }
  27568. };
  27569. var ImageUtils = {
  27570. crossOrigin: undefined,
  27571. loadTexture: function ( url, mapping, onLoad, onError ) {
  27572. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  27573. var loader = new TextureLoader();
  27574. loader.setCrossOrigin( this.crossOrigin );
  27575. var texture = loader.load( url, onLoad, undefined, onError );
  27576. if ( mapping ) texture.mapping = mapping;
  27577. return texture;
  27578. },
  27579. loadTextureCube: function ( urls, mapping, onLoad, onError ) {
  27580. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  27581. var loader = new CubeTextureLoader();
  27582. loader.setCrossOrigin( this.crossOrigin );
  27583. var texture = loader.load( urls, onLoad, undefined, onError );
  27584. if ( mapping ) texture.mapping = mapping;
  27585. return texture;
  27586. },
  27587. loadCompressedTexture: function () {
  27588. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  27589. },
  27590. loadCompressedTextureCube: function () {
  27591. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  27592. }
  27593. };
  27594. //
  27595. function Projector() {
  27596. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  27597. this.projectVector = function ( vector, camera ) {
  27598. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  27599. vector.project( camera );
  27600. };
  27601. this.unprojectVector = function ( vector, camera ) {
  27602. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  27603. vector.unproject( camera );
  27604. };
  27605. this.pickingRay = function () {
  27606. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  27607. };
  27608. }
  27609. //
  27610. function CanvasRenderer() {
  27611. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  27612. this.domElement = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  27613. this.clear = function () {};
  27614. this.render = function () {};
  27615. this.setClearColor = function () {};
  27616. this.setSize = function () {};
  27617. }
  27618. //
  27619. var SceneUtils = {
  27620. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  27621. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  27622. },
  27623. detach: function ( /* child, parent, scene */ ) {
  27624. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  27625. },
  27626. attach: function ( /* child, scene, parent */ ) {
  27627. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  27628. }
  27629. };
  27630. //
  27631. function LensFlare() {
  27632. console.error( 'THREE.LensFlare has been moved to /examples/js/objects/Lensflare.js' );
  27633. }
  27634. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  27635. exports.WebGLRenderTarget = WebGLRenderTarget;
  27636. exports.WebGLRenderer = WebGLRenderer;
  27637. exports.ShaderLib = ShaderLib;
  27638. exports.UniformsLib = UniformsLib;
  27639. exports.UniformsUtils = UniformsUtils;
  27640. exports.ShaderChunk = ShaderChunk;
  27641. exports.FogExp2 = FogExp2;
  27642. exports.Fog = Fog;
  27643. exports.Scene = Scene;
  27644. exports.Sprite = Sprite;
  27645. exports.LOD = LOD;
  27646. exports.SkinnedMesh = SkinnedMesh;
  27647. exports.Skeleton = Skeleton;
  27648. exports.Bone = Bone;
  27649. exports.Mesh = Mesh;
  27650. exports.LineSegments = LineSegments;
  27651. exports.LineLoop = LineLoop;
  27652. exports.Line = Line;
  27653. exports.Points = Points;
  27654. exports.Group = Group;
  27655. exports.VideoTexture = VideoTexture;
  27656. exports.DataTexture = DataTexture;
  27657. exports.CompressedTexture = CompressedTexture;
  27658. exports.CubeTexture = CubeTexture;
  27659. exports.CanvasTexture = CanvasTexture;
  27660. exports.DepthTexture = DepthTexture;
  27661. exports.Texture = Texture;
  27662. exports.CompressedTextureLoader = CompressedTextureLoader;
  27663. exports.DataTextureLoader = DataTextureLoader;
  27664. exports.CubeTextureLoader = CubeTextureLoader;
  27665. exports.TextureLoader = TextureLoader;
  27666. exports.ObjectLoader = ObjectLoader;
  27667. exports.MaterialLoader = MaterialLoader;
  27668. exports.BufferGeometryLoader = BufferGeometryLoader;
  27669. exports.DefaultLoadingManager = DefaultLoadingManager;
  27670. exports.LoadingManager = LoadingManager;
  27671. exports.JSONLoader = JSONLoader;
  27672. exports.ImageLoader = ImageLoader;
  27673. exports.ImageBitmapLoader = ImageBitmapLoader;
  27674. exports.FontLoader = FontLoader;
  27675. exports.FileLoader = FileLoader;
  27676. exports.Loader = Loader;
  27677. exports.LoaderUtils = LoaderUtils;
  27678. exports.Cache = Cache;
  27679. exports.AudioLoader = AudioLoader;
  27680. exports.SpotLightShadow = SpotLightShadow;
  27681. exports.SpotLight = SpotLight;
  27682. exports.PointLight = PointLight;
  27683. exports.RectAreaLight = RectAreaLight;
  27684. exports.HemisphereLight = HemisphereLight;
  27685. exports.DirectionalLightShadow = DirectionalLightShadow;
  27686. exports.DirectionalLight = DirectionalLight;
  27687. exports.AmbientLight = AmbientLight;
  27688. exports.LightShadow = LightShadow;
  27689. exports.Light = Light;
  27690. exports.StereoCamera = StereoCamera;
  27691. exports.PerspectiveCamera = PerspectiveCamera;
  27692. exports.OrthographicCamera = OrthographicCamera;
  27693. exports.CubeCamera = CubeCamera;
  27694. exports.ArrayCamera = ArrayCamera;
  27695. exports.Camera = Camera;
  27696. exports.AudioListener = AudioListener;
  27697. exports.PositionalAudio = PositionalAudio;
  27698. exports.AudioContext = AudioContext;
  27699. exports.AudioAnalyser = AudioAnalyser;
  27700. exports.Audio = Audio;
  27701. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  27702. exports.StringKeyframeTrack = StringKeyframeTrack;
  27703. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  27704. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  27705. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  27706. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  27707. exports.PropertyMixer = PropertyMixer;
  27708. exports.PropertyBinding = PropertyBinding;
  27709. exports.KeyframeTrack = KeyframeTrack;
  27710. exports.AnimationUtils = AnimationUtils;
  27711. exports.AnimationObjectGroup = AnimationObjectGroup;
  27712. exports.AnimationMixer = AnimationMixer;
  27713. exports.AnimationClip = AnimationClip;
  27714. exports.Uniform = Uniform;
  27715. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  27716. exports.BufferGeometry = BufferGeometry;
  27717. exports.Geometry = Geometry;
  27718. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  27719. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  27720. exports.InterleavedBuffer = InterleavedBuffer;
  27721. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  27722. exports.Face3 = Face3;
  27723. exports.Object3D = Object3D;
  27724. exports.Raycaster = Raycaster;
  27725. exports.Layers = Layers;
  27726. exports.EventDispatcher = EventDispatcher;
  27727. exports.Clock = Clock;
  27728. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  27729. exports.LinearInterpolant = LinearInterpolant;
  27730. exports.DiscreteInterpolant = DiscreteInterpolant;
  27731. exports.CubicInterpolant = CubicInterpolant;
  27732. exports.Interpolant = Interpolant;
  27733. exports.Triangle = Triangle;
  27734. exports.Math = _Math;
  27735. exports.Spherical = Spherical;
  27736. exports.Cylindrical = Cylindrical;
  27737. exports.Plane = Plane;
  27738. exports.Frustum = Frustum;
  27739. exports.Sphere = Sphere;
  27740. exports.Ray = Ray;
  27741. exports.Matrix4 = Matrix4;
  27742. exports.Matrix3 = Matrix3;
  27743. exports.Box3 = Box3;
  27744. exports.Box2 = Box2;
  27745. exports.Line3 = Line3;
  27746. exports.Euler = Euler;
  27747. exports.Vector4 = Vector4;
  27748. exports.Vector3 = Vector3;
  27749. exports.Vector2 = Vector2;
  27750. exports.Quaternion = Quaternion;
  27751. exports.Color = Color;
  27752. exports.ImmediateRenderObject = ImmediateRenderObject;
  27753. exports.VertexNormalsHelper = VertexNormalsHelper;
  27754. exports.SpotLightHelper = SpotLightHelper;
  27755. exports.SkeletonHelper = SkeletonHelper;
  27756. exports.PointLightHelper = PointLightHelper;
  27757. exports.RectAreaLightHelper = RectAreaLightHelper;
  27758. exports.HemisphereLightHelper = HemisphereLightHelper;
  27759. exports.GridHelper = GridHelper;
  27760. exports.PolarGridHelper = PolarGridHelper;
  27761. exports.FaceNormalsHelper = FaceNormalsHelper;
  27762. exports.DirectionalLightHelper = DirectionalLightHelper;
  27763. exports.CameraHelper = CameraHelper;
  27764. exports.BoxHelper = BoxHelper;
  27765. exports.Box3Helper = Box3Helper;
  27766. exports.PlaneHelper = PlaneHelper;
  27767. exports.ArrowHelper = ArrowHelper;
  27768. exports.AxesHelper = AxesHelper;
  27769. exports.Shape = Shape;
  27770. exports.Path = Path;
  27771. exports.ShapePath = ShapePath;
  27772. exports.Font = Font;
  27773. exports.CurvePath = CurvePath;
  27774. exports.Curve = Curve;
  27775. exports.ShapeUtils = ShapeUtils;
  27776. exports.WebGLUtils = WebGLUtils;
  27777. exports.WireframeGeometry = WireframeGeometry;
  27778. exports.ParametricGeometry = ParametricGeometry;
  27779. exports.ParametricBufferGeometry = ParametricBufferGeometry;
  27780. exports.TetrahedronGeometry = TetrahedronGeometry;
  27781. exports.TetrahedronBufferGeometry = TetrahedronBufferGeometry;
  27782. exports.OctahedronGeometry = OctahedronGeometry;
  27783. exports.OctahedronBufferGeometry = OctahedronBufferGeometry;
  27784. exports.IcosahedronGeometry = IcosahedronGeometry;
  27785. exports.IcosahedronBufferGeometry = IcosahedronBufferGeometry;
  27786. exports.DodecahedronGeometry = DodecahedronGeometry;
  27787. exports.DodecahedronBufferGeometry = DodecahedronBufferGeometry;
  27788. exports.PolyhedronGeometry = PolyhedronGeometry;
  27789. exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
  27790. exports.TubeGeometry = TubeGeometry;
  27791. exports.TubeBufferGeometry = TubeBufferGeometry;
  27792. exports.TorusKnotGeometry = TorusKnotGeometry;
  27793. exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
  27794. exports.TorusGeometry = TorusGeometry;
  27795. exports.TorusBufferGeometry = TorusBufferGeometry;
  27796. exports.TextGeometry = TextGeometry;
  27797. exports.TextBufferGeometry = TextBufferGeometry;
  27798. exports.SphereGeometry = SphereGeometry;
  27799. exports.SphereBufferGeometry = SphereBufferGeometry;
  27800. exports.RingGeometry = RingGeometry;
  27801. exports.RingBufferGeometry = RingBufferGeometry;
  27802. exports.PlaneGeometry = PlaneGeometry;
  27803. exports.PlaneBufferGeometry = PlaneBufferGeometry;
  27804. exports.LatheGeometry = LatheGeometry;
  27805. exports.LatheBufferGeometry = LatheBufferGeometry;
  27806. exports.ShapeGeometry = ShapeGeometry;
  27807. exports.ShapeBufferGeometry = ShapeBufferGeometry;
  27808. exports.ExtrudeGeometry = ExtrudeGeometry;
  27809. exports.ExtrudeBufferGeometry = ExtrudeBufferGeometry;
  27810. exports.EdgesGeometry = EdgesGeometry;
  27811. exports.ConeGeometry = ConeGeometry;
  27812. exports.ConeBufferGeometry = ConeBufferGeometry;
  27813. exports.CylinderGeometry = CylinderGeometry;
  27814. exports.CylinderBufferGeometry = CylinderBufferGeometry;
  27815. exports.CircleGeometry = CircleGeometry;
  27816. exports.CircleBufferGeometry = CircleBufferGeometry;
  27817. exports.BoxGeometry = BoxGeometry;
  27818. exports.BoxBufferGeometry = BoxBufferGeometry;
  27819. exports.ShadowMaterial = ShadowMaterial;
  27820. exports.SpriteMaterial = SpriteMaterial;
  27821. exports.RawShaderMaterial = RawShaderMaterial;
  27822. exports.ShaderMaterial = ShaderMaterial;
  27823. exports.PointsMaterial = PointsMaterial;
  27824. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  27825. exports.MeshStandardMaterial = MeshStandardMaterial;
  27826. exports.MeshPhongMaterial = MeshPhongMaterial;
  27827. exports.MeshToonMaterial = MeshToonMaterial;
  27828. exports.MeshNormalMaterial = MeshNormalMaterial;
  27829. exports.MeshLambertMaterial = MeshLambertMaterial;
  27830. exports.MeshDepthMaterial = MeshDepthMaterial;
  27831. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  27832. exports.MeshBasicMaterial = MeshBasicMaterial;
  27833. exports.LineDashedMaterial = LineDashedMaterial;
  27834. exports.LineBasicMaterial = LineBasicMaterial;
  27835. exports.Material = Material;
  27836. exports.Float64BufferAttribute = Float64BufferAttribute;
  27837. exports.Float32BufferAttribute = Float32BufferAttribute;
  27838. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  27839. exports.Int32BufferAttribute = Int32BufferAttribute;
  27840. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  27841. exports.Int16BufferAttribute = Int16BufferAttribute;
  27842. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  27843. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  27844. exports.Int8BufferAttribute = Int8BufferAttribute;
  27845. exports.BufferAttribute = BufferAttribute;
  27846. exports.ArcCurve = ArcCurve;
  27847. exports.CatmullRomCurve3 = CatmullRomCurve3;
  27848. exports.CubicBezierCurve = CubicBezierCurve;
  27849. exports.CubicBezierCurve3 = CubicBezierCurve3;
  27850. exports.EllipseCurve = EllipseCurve;
  27851. exports.LineCurve = LineCurve;
  27852. exports.LineCurve3 = LineCurve3;
  27853. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  27854. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  27855. exports.SplineCurve = SplineCurve;
  27856. exports.REVISION = REVISION;
  27857. exports.MOUSE = MOUSE;
  27858. exports.CullFaceNone = CullFaceNone;
  27859. exports.CullFaceBack = CullFaceBack;
  27860. exports.CullFaceFront = CullFaceFront;
  27861. exports.CullFaceFrontBack = CullFaceFrontBack;
  27862. exports.FrontFaceDirectionCW = FrontFaceDirectionCW;
  27863. exports.FrontFaceDirectionCCW = FrontFaceDirectionCCW;
  27864. exports.BasicShadowMap = BasicShadowMap;
  27865. exports.PCFShadowMap = PCFShadowMap;
  27866. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  27867. exports.FrontSide = FrontSide;
  27868. exports.BackSide = BackSide;
  27869. exports.DoubleSide = DoubleSide;
  27870. exports.FlatShading = FlatShading;
  27871. exports.SmoothShading = SmoothShading;
  27872. exports.NoColors = NoColors;
  27873. exports.FaceColors = FaceColors;
  27874. exports.VertexColors = VertexColors;
  27875. exports.NoBlending = NoBlending;
  27876. exports.NormalBlending = NormalBlending;
  27877. exports.AdditiveBlending = AdditiveBlending;
  27878. exports.SubtractiveBlending = SubtractiveBlending;
  27879. exports.MultiplyBlending = MultiplyBlending;
  27880. exports.CustomBlending = CustomBlending;
  27881. exports.AddEquation = AddEquation;
  27882. exports.SubtractEquation = SubtractEquation;
  27883. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  27884. exports.MinEquation = MinEquation;
  27885. exports.MaxEquation = MaxEquation;
  27886. exports.ZeroFactor = ZeroFactor;
  27887. exports.OneFactor = OneFactor;
  27888. exports.SrcColorFactor = SrcColorFactor;
  27889. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  27890. exports.SrcAlphaFactor = SrcAlphaFactor;
  27891. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  27892. exports.DstAlphaFactor = DstAlphaFactor;
  27893. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  27894. exports.DstColorFactor = DstColorFactor;
  27895. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  27896. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  27897. exports.NeverDepth = NeverDepth;
  27898. exports.AlwaysDepth = AlwaysDepth;
  27899. exports.LessDepth = LessDepth;
  27900. exports.LessEqualDepth = LessEqualDepth;
  27901. exports.EqualDepth = EqualDepth;
  27902. exports.GreaterEqualDepth = GreaterEqualDepth;
  27903. exports.GreaterDepth = GreaterDepth;
  27904. exports.NotEqualDepth = NotEqualDepth;
  27905. exports.MultiplyOperation = MultiplyOperation;
  27906. exports.MixOperation = MixOperation;
  27907. exports.AddOperation = AddOperation;
  27908. exports.NoToneMapping = NoToneMapping;
  27909. exports.LinearToneMapping = LinearToneMapping;
  27910. exports.ReinhardToneMapping = ReinhardToneMapping;
  27911. exports.Uncharted2ToneMapping = Uncharted2ToneMapping;
  27912. exports.CineonToneMapping = CineonToneMapping;
  27913. exports.UVMapping = UVMapping;
  27914. exports.CubeReflectionMapping = CubeReflectionMapping;
  27915. exports.CubeRefractionMapping = CubeRefractionMapping;
  27916. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  27917. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  27918. exports.SphericalReflectionMapping = SphericalReflectionMapping;
  27919. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  27920. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  27921. exports.RepeatWrapping = RepeatWrapping;
  27922. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  27923. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  27924. exports.NearestFilter = NearestFilter;
  27925. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  27926. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  27927. exports.LinearFilter = LinearFilter;
  27928. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  27929. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  27930. exports.UnsignedByteType = UnsignedByteType;
  27931. exports.ByteType = ByteType;
  27932. exports.ShortType = ShortType;
  27933. exports.UnsignedShortType = UnsignedShortType;
  27934. exports.IntType = IntType;
  27935. exports.UnsignedIntType = UnsignedIntType;
  27936. exports.FloatType = FloatType;
  27937. exports.HalfFloatType = HalfFloatType;
  27938. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  27939. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  27940. exports.UnsignedShort565Type = UnsignedShort565Type;
  27941. exports.UnsignedInt248Type = UnsignedInt248Type;
  27942. exports.AlphaFormat = AlphaFormat;
  27943. exports.RGBFormat = RGBFormat;
  27944. exports.RGBAFormat = RGBAFormat;
  27945. exports.LuminanceFormat = LuminanceFormat;
  27946. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  27947. exports.RGBEFormat = RGBEFormat;
  27948. exports.DepthFormat = DepthFormat;
  27949. exports.DepthStencilFormat = DepthStencilFormat;
  27950. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  27951. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  27952. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  27953. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  27954. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  27955. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  27956. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  27957. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  27958. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  27959. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  27960. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  27961. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  27962. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  27963. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  27964. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  27965. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  27966. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  27967. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  27968. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  27969. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  27970. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  27971. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  27972. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  27973. exports.LoopOnce = LoopOnce;
  27974. exports.LoopRepeat = LoopRepeat;
  27975. exports.LoopPingPong = LoopPingPong;
  27976. exports.InterpolateDiscrete = InterpolateDiscrete;
  27977. exports.InterpolateLinear = InterpolateLinear;
  27978. exports.InterpolateSmooth = InterpolateSmooth;
  27979. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  27980. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  27981. exports.WrapAroundEnding = WrapAroundEnding;
  27982. exports.TrianglesDrawMode = TrianglesDrawMode;
  27983. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  27984. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  27985. exports.LinearEncoding = LinearEncoding;
  27986. exports.sRGBEncoding = sRGBEncoding;
  27987. exports.GammaEncoding = GammaEncoding;
  27988. exports.RGBEEncoding = RGBEEncoding;
  27989. exports.LogLuvEncoding = LogLuvEncoding;
  27990. exports.RGBM7Encoding = RGBM7Encoding;
  27991. exports.RGBM16Encoding = RGBM16Encoding;
  27992. exports.RGBDEncoding = RGBDEncoding;
  27993. exports.BasicDepthPacking = BasicDepthPacking;
  27994. exports.RGBADepthPacking = RGBADepthPacking;
  27995. exports.CubeGeometry = BoxGeometry;
  27996. exports.Face4 = Face4;
  27997. exports.LineStrip = LineStrip;
  27998. exports.LinePieces = LinePieces;
  27999. exports.MeshFaceMaterial = MeshFaceMaterial;
  28000. exports.MultiMaterial = MultiMaterial;
  28001. exports.PointCloud = PointCloud;
  28002. exports.Particle = Particle;
  28003. exports.ParticleSystem = ParticleSystem;
  28004. exports.PointCloudMaterial = PointCloudMaterial;
  28005. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  28006. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  28007. exports.Vertex = Vertex;
  28008. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  28009. exports.Int8Attribute = Int8Attribute;
  28010. exports.Uint8Attribute = Uint8Attribute;
  28011. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  28012. exports.Int16Attribute = Int16Attribute;
  28013. exports.Uint16Attribute = Uint16Attribute;
  28014. exports.Int32Attribute = Int32Attribute;
  28015. exports.Uint32Attribute = Uint32Attribute;
  28016. exports.Float32Attribute = Float32Attribute;
  28017. exports.Float64Attribute = Float64Attribute;
  28018. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  28019. exports.SplineCurve3 = SplineCurve3;
  28020. exports.Spline = Spline;
  28021. exports.AxisHelper = AxisHelper;
  28022. exports.BoundingBoxHelper = BoundingBoxHelper;
  28023. exports.EdgesHelper = EdgesHelper;
  28024. exports.WireframeHelper = WireframeHelper;
  28025. exports.XHRLoader = XHRLoader;
  28026. exports.BinaryTextureLoader = BinaryTextureLoader;
  28027. exports.GeometryUtils = GeometryUtils;
  28028. exports.ImageUtils = ImageUtils;
  28029. exports.Projector = Projector;
  28030. exports.CanvasRenderer = CanvasRenderer;
  28031. exports.SceneUtils = SceneUtils;
  28032. exports.LensFlare = LensFlare;
  28033. Object.defineProperty(exports, '__esModule', { value: true });
  28034. })));