Three.js 1.1 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509
  1. <<<<<<< HEAD
  2. /**
  3. * @author mr.doob / http://mrdoob.com/
  4. */
  5. var THREE = THREE || { REVISION: '49dev' };
  6. if ( ! self.Int32Array ) {
  7. self.Int32Array = Array;
  8. self.Float32Array = Array;
  9. }
  10. // http://paulirish.com/2011/requestanimationframe-for-smart-animating/
  11. // http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
  12. // requestAnimationFrame polyfill by Erik Möller
  13. // fixes from Paul Irish and Tino Zijdel
  14. ( function () {
  15. var lastTime = 0;
  16. var vendors = [ 'ms', 'moz', 'webkit', 'o' ];
  17. for ( var x = 0; x < vendors.length && !window.requestAnimationFrame; ++ x ) {
  18. window.requestAnimationFrame = window[ vendors[ x ] + 'RequestAnimationFrame' ];
  19. window.cancelAnimationFrame = window[ vendors[ x ] + 'CancelAnimationFrame' ] || window[ vendors[ x ] + 'CancelRequestAnimationFrame' ];
  20. }
  21. if ( !window.requestAnimationFrame ) {
  22. window.requestAnimationFrame = function ( callback, element ) {
  23. var currTime = Date.now(), timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
  24. var id = window.setTimeout( function() { callback( currTime + timeToCall ); }, timeToCall );
  25. lastTime = currTime + timeToCall;
  26. return id;
  27. };
  28. }
  29. if ( !window.cancelAnimationFrame ) {
  30. window.cancelAnimationFrame = function ( id ) { clearTimeout( id ); };
  31. }
  32. }() );
  33. /**
  34. * @author alteredq / http://alteredqualia.com/
  35. */
  36. THREE.Clock = function ( autoStart ) {
  37. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  38. this.startTime = 0;
  39. this.oldTime = 0;
  40. this.elapsedTime = 0;
  41. this.running = false;
  42. };
  43. THREE.Clock.prototype.start = function () {
  44. this.startTime = Date.now();
  45. this.oldTime = this.startTime;
  46. this.running = true;
  47. };
  48. THREE.Clock.prototype.stop = function () {
  49. this.getElapsedTime();
  50. this.running = false;
  51. };
  52. THREE.Clock.prototype.getElapsedTime = function () {
  53. this.elapsedTime += this.getDelta();
  54. return this.elapsedTime;
  55. };
  56. THREE.Clock.prototype.getDelta = function () {
  57. var diff = 0;
  58. if ( this.autoStart && ! this.running ) {
  59. this.start();
  60. }
  61. if ( this.running ) {
  62. var newTime = Date.now();
  63. diff = 0.001 * ( newTime - this.oldTime );
  64. this.oldTime = newTime;
  65. this.elapsedTime += diff;
  66. }
  67. return diff;
  68. };/**
  69. * @author mr.doob / http://mrdoob.com/
  70. */
  71. THREE.Color = function ( hex ) {
  72. if ( hex !== undefined ) this.setHex( hex );
  73. return this;
  74. };
  75. THREE.Color.prototype = {
  76. constructor: THREE.Color,
  77. r: 1, g: 1, b: 1,
  78. copy: function ( color ) {
  79. this.r = color.r;
  80. this.g = color.g;
  81. this.b = color.b;
  82. return this;
  83. },
  84. copyGammaToLinear: function ( color ) {
  85. this.r = color.r * color.r;
  86. this.g = color.g * color.g;
  87. this.b = color.b * color.b;
  88. return this;
  89. },
  90. copyLinearToGamma: function ( color ) {
  91. this.r = Math.sqrt( color.r );
  92. this.g = Math.sqrt( color.g );
  93. this.b = Math.sqrt( color.b );
  94. return this;
  95. },
  96. convertGammaToLinear: function () {
  97. var r = this.r, g = this.g, b = this.b;
  98. this.r = r * r;
  99. this.g = g * g;
  100. this.b = b * b;
  101. return this;
  102. },
  103. convertLinearToGamma: function () {
  104. this.r = Math.sqrt( this.r );
  105. this.g = Math.sqrt( this.g );
  106. this.b = Math.sqrt( this.b );
  107. return this;
  108. },
  109. setRGB: function ( r, g, b ) {
  110. this.r = r;
  111. this.g = g;
  112. this.b = b;
  113. return this;
  114. },
  115. setHSV: function ( h, s, v ) {
  116. // based on MochiKit implementation by Bob Ippolito
  117. // h,s,v ranges are < 0.0 - 1.0 >
  118. var i, f, p, q, t;
  119. if ( v === 0 ) {
  120. this.r = this.g = this.b = 0;
  121. } else {
  122. i = Math.floor( h * 6 );
  123. f = ( h * 6 ) - i;
  124. p = v * ( 1 - s );
  125. q = v * ( 1 - ( s * f ) );
  126. t = v * ( 1 - ( s * ( 1 - f ) ) );
  127. switch ( i ) {
  128. case 1: this.r = q; this.g = v; this.b = p; break;
  129. case 2: this.r = p; this.g = v; this.b = t; break;
  130. case 3: this.r = p; this.g = q; this.b = v; break;
  131. case 4: this.r = t; this.g = p; this.b = v; break;
  132. case 5: this.r = v; this.g = p; this.b = q; break;
  133. case 6: // fall through
  134. case 0: this.r = v; this.g = t; this.b = p; break;
  135. }
  136. }
  137. return this;
  138. },
  139. setHex: function ( hex ) {
  140. hex = Math.floor( hex );
  141. this.r = ( hex >> 16 & 255 ) / 255;
  142. this.g = ( hex >> 8 & 255 ) / 255;
  143. this.b = ( hex & 255 ) / 255;
  144. return this;
  145. },
  146. lerpSelf: function ( color, alpha ) {
  147. this.r += ( color.r - this.r ) * alpha;
  148. this.g += ( color.g - this.g ) * alpha;
  149. this.b += ( color.b - this.b ) * alpha;
  150. return this;
  151. },
  152. getHex: function () {
  153. return Math.floor( this.r * 255 ) << 16 ^ Math.floor( this.g * 255 ) << 8 ^ Math.floor( this.b * 255 );
  154. },
  155. getContextStyle: function () {
  156. return 'rgb(' + Math.floor( this.r * 255 ) + ',' + Math.floor( this.g * 255 ) + ',' + Math.floor( this.b * 255 ) + ')';
  157. },
  158. clone: function () {
  159. return new THREE.Color().setRGB( this.r, this.g, this.b );
  160. }
  161. };
  162. /**
  163. * @author mr.doob / http://mrdoob.com/
  164. * @author philogb / http://blog.thejit.org/
  165. * @author egraether / http://egraether.com/
  166. * @author zz85 / http://www.lab4games.net/zz85/blog
  167. */
  168. THREE.Vector2 = function ( x, y ) {
  169. this.x = x || 0;
  170. this.y = y || 0;
  171. };
  172. THREE.Vector2.prototype = {
  173. constructor: THREE.Vector2,
  174. set: function ( x, y ) {
  175. this.x = x;
  176. this.y = y;
  177. return this;
  178. },
  179. copy: function ( v ) {
  180. this.x = v.x;
  181. this.y = v.y;
  182. return this;
  183. },
  184. add: function ( a, b ) {
  185. this.x = a.x + b.x;
  186. this.y = a.y + b.y;
  187. return this;
  188. },
  189. addSelf: function ( v ) {
  190. this.x += v.x;
  191. this.y += v.y;
  192. return this;
  193. },
  194. sub: function ( a, b ) {
  195. this.x = a.x - b.x;
  196. this.y = a.y - b.y;
  197. return this;
  198. },
  199. subSelf: function ( v ) {
  200. this.x -= v.x;
  201. this.y -= v.y;
  202. return this;
  203. },
  204. multiplyScalar: function ( s ) {
  205. this.x *= s;
  206. this.y *= s;
  207. return this;
  208. },
  209. divideScalar: function ( s ) {
  210. if ( s ) {
  211. this.x /= s;
  212. this.y /= s;
  213. } else {
  214. this.set( 0, 0 );
  215. }
  216. return this;
  217. },
  218. negate: function() {
  219. return this.multiplyScalar( - 1 );
  220. },
  221. dot: function ( v ) {
  222. return this.x * v.x + this.y * v.y;
  223. },
  224. lengthSq: function () {
  225. return this.x * this.x + this.y * this.y;
  226. },
  227. length: function () {
  228. return Math.sqrt( this.lengthSq() );
  229. },
  230. normalize: function () {
  231. return this.divideScalar( this.length() );
  232. },
  233. distanceTo: function ( v ) {
  234. return Math.sqrt( this.distanceToSquared( v ) );
  235. },
  236. distanceToSquared: function ( v ) {
  237. var dx = this.x - v.x, dy = this.y - v.y;
  238. return dx * dx + dy * dy;
  239. },
  240. setLength: function ( l ) {
  241. return this.normalize().multiplyScalar( l );
  242. },
  243. lerpSelf: function ( v, alpha ) {
  244. this.x += ( v.x - this.x ) * alpha;
  245. this.y += ( v.y - this.y ) * alpha;
  246. return this;
  247. },
  248. equals: function( v ) {
  249. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  250. },
  251. isZero: function () {
  252. return ( this.lengthSq() < 0.0001 /* almostZero */ );
  253. },
  254. clone: function () {
  255. return new THREE.Vector2( this.x, this.y );
  256. }
  257. };
  258. /**
  259. * @author mr.doob / http://mrdoob.com/
  260. * @author kile / http://kile.stravaganza.org/
  261. * @author philogb / http://blog.thejit.org/
  262. * @author mikael emtinger / http://gomo.se/
  263. * @author egraether / http://egraether.com/
  264. */
  265. THREE.Vector3 = function ( x, y, z ) {
  266. this.x = x || 0;
  267. this.y = y || 0;
  268. this.z = z || 0;
  269. };
  270. THREE.Vector3.prototype = {
  271. constructor: THREE.Vector3,
  272. set: function ( x, y, z ) {
  273. this.x = x;
  274. this.y = y;
  275. this.z = z;
  276. return this;
  277. },
  278. setX: function ( x ) {
  279. this.x = x;
  280. return this;
  281. },
  282. setY: function ( y ) {
  283. this.y = y;
  284. return this;
  285. },
  286. setZ: function ( z ) {
  287. this.z = z;
  288. return this;
  289. },
  290. copy: function ( v ) {
  291. this.x = v.x;
  292. this.y = v.y;
  293. this.z = v.z;
  294. return this;
  295. },
  296. add: function ( a, b ) {
  297. this.x = a.x + b.x;
  298. this.y = a.y + b.y;
  299. this.z = a.z + b.z;
  300. return this;
  301. },
  302. addSelf: function ( v ) {
  303. this.x += v.x;
  304. this.y += v.y;
  305. this.z += v.z;
  306. return this;
  307. },
  308. addScalar: function ( s ) {
  309. this.x += s;
  310. this.y += s;
  311. this.z += s;
  312. return this;
  313. },
  314. sub: function ( a, b ) {
  315. this.x = a.x - b.x;
  316. this.y = a.y - b.y;
  317. this.z = a.z - b.z;
  318. return this;
  319. },
  320. subSelf: function ( v ) {
  321. this.x -= v.x;
  322. this.y -= v.y;
  323. this.z -= v.z;
  324. return this;
  325. },
  326. multiply: function ( a, b ) {
  327. this.x = a.x * b.x;
  328. this.y = a.y * b.y;
  329. this.z = a.z * b.z;
  330. return this;
  331. },
  332. multiplySelf: function ( v ) {
  333. this.x *= v.x;
  334. this.y *= v.y;
  335. this.z *= v.z;
  336. return this;
  337. },
  338. multiplyScalar: function ( s ) {
  339. this.x *= s;
  340. this.y *= s;
  341. this.z *= s;
  342. return this;
  343. },
  344. divideSelf: function ( v ) {
  345. this.x /= v.x;
  346. this.y /= v.y;
  347. this.z /= v.z;
  348. return this;
  349. },
  350. divideScalar: function ( s ) {
  351. if ( s ) {
  352. this.x /= s;
  353. this.y /= s;
  354. this.z /= s;
  355. } else {
  356. this.x = 0;
  357. this.y = 0;
  358. this.z = 0;
  359. }
  360. return this;
  361. },
  362. negate: function() {
  363. return this.multiplyScalar( - 1 );
  364. },
  365. dot: function ( v ) {
  366. return this.x * v.x + this.y * v.y + this.z * v.z;
  367. },
  368. lengthSq: function () {
  369. return this.x * this.x + this.y * this.y + this.z * this.z;
  370. },
  371. length: function () {
  372. return Math.sqrt( this.lengthSq() );
  373. },
  374. lengthManhattan: function () {
  375. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  376. },
  377. normalize: function () {
  378. return this.divideScalar( this.length() );
  379. },
  380. setLength: function ( l ) {
  381. return this.normalize().multiplyScalar( l );
  382. },
  383. lerpSelf: function ( v, alpha ) {
  384. this.x += ( v.x - this.x ) * alpha;
  385. this.y += ( v.y - this.y ) * alpha;
  386. this.z += ( v.z - this.z ) * alpha;
  387. return this;
  388. },
  389. cross: function ( a, b ) {
  390. this.x = a.y * b.z - a.z * b.y;
  391. this.y = a.z * b.x - a.x * b.z;
  392. this.z = a.x * b.y - a.y * b.x;
  393. return this;
  394. },
  395. crossSelf: function ( v ) {
  396. var x = this.x, y = this.y, z = this.z;
  397. this.x = y * v.z - z * v.y;
  398. this.y = z * v.x - x * v.z;
  399. this.z = x * v.y - y * v.x;
  400. return this;
  401. },
  402. distanceTo: function ( v ) {
  403. return Math.sqrt( this.distanceToSquared( v ) );
  404. },
  405. distanceToSquared: function ( v ) {
  406. return new THREE.Vector3().sub( this, v ).lengthSq();
  407. },
  408. getPositionFromMatrix: function ( m ) {
  409. this.x = m.elements[12];
  410. this.y = m.elements[13];
  411. this.z = m.elements[14];
  412. return this;
  413. },
  414. getRotationFromMatrix: function ( m, scale ) {
  415. var sx = scale ? scale.x : 1;
  416. var sy = scale ? scale.y : 1;
  417. var sz = scale ? scale.z : 1;
  418. var m11 = m.elements[0] / sx, m12 = m.elements[4] / sy, m13 = m.elements[8] / sz;
  419. var m21 = m.elements[1] / sx, m22 = m.elements[5] / sy, m23 = m.elements[9] / sz;
  420. var m33 = m.elements[10] / sz;
  421. this.y = Math.asin( m13 );
  422. var cosY = Math.cos( this.y );
  423. if ( Math.abs( cosY ) > 0.00001 ) {
  424. this.x = Math.atan2( - m23 / cosY, m33 / cosY );
  425. this.z = Math.atan2( - m12 / cosY, m11 / cosY );
  426. } else {
  427. this.x = 0;
  428. this.z = Math.atan2( m21, m22 );
  429. }
  430. return this;
  431. },
  432. /*
  433. // from http://www.mathworks.com/matlabcentral/fileexchange/20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/content/SpinCalc.m
  434. // order XYZ
  435. getEulerXYZFromQuaternion: function ( q ) {
  436. this.x = Math.atan2( 2 * ( q.x * q.w - q.y * q.z ), ( q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z ) );
  437. this.y = Math.asin( 2 * ( q.x * q.z + q.y * q.w ) );
  438. this.z = Math.atan2( 2 * ( q.z * q.w - q.x * q.y ), ( q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z ) );
  439. },
  440. // from http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/index.htm
  441. // order YZX (assuming heading == y, attitude == z, bank == x)
  442. getEulerYZXFromQuaternion: function ( q ) {
  443. var sqw = q.w * q.w;
  444. var sqx = q.x * q.x;
  445. var sqy = q.y * q.y;
  446. var sqz = q.z * q.z;
  447. var unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
  448. var test = q.x * q.y + q.z * q.w;
  449. if ( test > 0.499 * unit ) { // singularity at north pole
  450. this.y = 2 * Math.atan2( q.x, q.w );
  451. this.z = Math.PI / 2;
  452. this.x = 0;
  453. return;
  454. }
  455. if ( test < -0.499 * unit ) { // singularity at south pole
  456. this.y = -2 * Math.atan2( q.x, q.w );
  457. this.z = -Math.PI / 2;
  458. this.x = 0;
  459. return;
  460. }
  461. this.y = Math.atan2( 2 * q.y * q.w - 2 * q.x * q.z, sqx - sqy - sqz + sqw );
  462. this.z = Math.asin( 2 * test / unit );
  463. this.x = Math.atan2( 2 * q.x * q.w - 2 * q.y * q.z, -sqx + sqy - sqz + sqw );
  464. },
  465. */
  466. getScaleFromMatrix: function ( m ) {
  467. var sx = this.set( m.elements[0], m.elements[1], m.elements[2] ).length();
  468. var sy = this.set( m.elements[4], m.elements[5], m.elements[6] ).length();
  469. var sz = this.set( m.elements[8], m.elements[9], m.elements[10] ).length();
  470. this.x = sx;
  471. this.y = sy;
  472. this.z = sz;
  473. },
  474. equals: function ( v ) {
  475. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  476. },
  477. isZero: function () {
  478. return ( this.lengthSq() < 0.0001 /* almostZero */ );
  479. },
  480. clone: function () {
  481. return new THREE.Vector3( this.x, this.y, this.z );
  482. }
  483. };
  484. /**
  485. * @author supereggbert / http://www.paulbrunt.co.uk/
  486. * @author philogb / http://blog.thejit.org/
  487. * @author mikael emtinger / http://gomo.se/
  488. * @author egraether / http://egraether.com/
  489. */
  490. THREE.Vector4 = function ( x, y, z, w ) {
  491. this.x = x || 0;
  492. this.y = y || 0;
  493. this.z = z || 0;
  494. this.w = ( w !== undefined ) ? w : 1;
  495. };
  496. THREE.Vector4.prototype = {
  497. constructor: THREE.Vector4,
  498. set: function ( x, y, z, w ) {
  499. this.x = x;
  500. this.y = y;
  501. this.z = z;
  502. this.w = w;
  503. return this;
  504. },
  505. copy: function ( v ) {
  506. this.x = v.x;
  507. this.y = v.y;
  508. this.z = v.z;
  509. this.w = ( v.w !== undefined ) ? v.w : 1;
  510. return this;
  511. },
  512. add: function ( a, b ) {
  513. this.x = a.x + b.x;
  514. this.y = a.y + b.y;
  515. this.z = a.z + b.z;
  516. this.w = a.w + b.w;
  517. return this;
  518. },
  519. addSelf: function ( v ) {
  520. this.x += v.x;
  521. this.y += v.y;
  522. this.z += v.z;
  523. this.w += v.w;
  524. return this;
  525. },
  526. sub: function ( a, b ) {
  527. this.x = a.x - b.x;
  528. this.y = a.y - b.y;
  529. this.z = a.z - b.z;
  530. this.w = a.w - b.w;
  531. return this;
  532. },
  533. subSelf: function ( v ) {
  534. this.x -= v.x;
  535. this.y -= v.y;
  536. this.z -= v.z;
  537. this.w -= v.w;
  538. return this;
  539. },
  540. multiplyScalar: function ( s ) {
  541. this.x *= s;
  542. this.y *= s;
  543. this.z *= s;
  544. this.w *= s;
  545. return this;
  546. },
  547. divideScalar: function ( s ) {
  548. if ( s ) {
  549. this.x /= s;
  550. this.y /= s;
  551. this.z /= s;
  552. this.w /= s;
  553. } else {
  554. this.x = 0;
  555. this.y = 0;
  556. this.z = 0;
  557. this.w = 1;
  558. }
  559. return this;
  560. },
  561. negate: function() {
  562. return this.multiplyScalar( -1 );
  563. },
  564. dot: function ( v ) {
  565. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  566. },
  567. lengthSq: function () {
  568. return this.dot( this );
  569. },
  570. length: function () {
  571. return Math.sqrt( this.lengthSq() );
  572. },
  573. normalize: function () {
  574. return this.divideScalar( this.length() );
  575. },
  576. setLength: function ( l ) {
  577. return this.normalize().multiplyScalar( l );
  578. },
  579. lerpSelf: function ( v, alpha ) {
  580. this.x += ( v.x - this.x ) * alpha;
  581. this.y += ( v.y - this.y ) * alpha;
  582. this.z += ( v.z - this.z ) * alpha;
  583. this.w += ( v.w - this.w ) * alpha;
  584. return this;
  585. },
  586. clone: function () {
  587. return new THREE.Vector4( this.x, this.y, this.z, this.w );
  588. }
  589. };
  590. /**
  591. * @author mrdoob / http://mrdoob.com/
  592. * @author alteredq / http://alteredqualia.com/
  593. */
  594. THREE.Frustum = function ( ) {
  595. this.planes = [
  596. new THREE.Vector4(),
  597. new THREE.Vector4(),
  598. new THREE.Vector4(),
  599. new THREE.Vector4(),
  600. new THREE.Vector4(),
  601. new THREE.Vector4()
  602. ];
  603. };
  604. THREE.Frustum.prototype.setFromMatrix = function ( m ) {
  605. var i, plane, planes = this.planes;
  606. var me = m.elements;
  607. var me0 = me[0], me1 = me[1], me2 = me[2], me3 = me[3];
  608. var me4 = me[4], me5 = me[5], me6 = me[6], me7 = me[7];
  609. var me8 = me[8], me9 = me[9], me10 = me[10], me11 = me[11];
  610. var me12 = me[12], me13 = me[13], me14 = me[14], me15 = me[15];
  611. planes[ 0 ].set( me3 - me0, me7 - me4, me11 - me8, me15 - me12 );
  612. planes[ 1 ].set( me3 + me0, me7 + me4, me11 + me8, me15 + me12 );
  613. planes[ 2 ].set( me3 + me1, me7 + me5, me11 + me9, me15 + me13 );
  614. planes[ 3 ].set( me3 - me1, me7 - me5, me11 - me9, me15 - me13 );
  615. planes[ 4 ].set( me3 - me2, me7 - me6, me11 - me10, me15 - me14 );
  616. planes[ 5 ].set( me3 + me2, me7 + me6, me11 + me10, me15 + me14 );
  617. for ( i = 0; i < 6; i ++ ) {
  618. plane = planes[ i ];
  619. plane.divideScalar( Math.sqrt( plane.x * plane.x + plane.y * plane.y + plane.z * plane.z ) );
  620. }
  621. };
  622. THREE.Frustum.prototype.contains = function ( object ) {
  623. var distance,
  624. planes = this.planes,
  625. matrix = object.matrixWorld,
  626. me = matrix.elements,
  627. radius = - object.geometry.boundingSphere.radius * matrix.getMaxScaleOnAxis();
  628. for ( var i = 0; i < 6; i ++ ) {
  629. distance = planes[ i ].x * me[12] + planes[ i ].y * me[13] + planes[ i ].z * me[14] + planes[ i ].w;
  630. if ( distance <= radius ) return false;
  631. }
  632. return true;
  633. };
  634. THREE.Frustum.__v1 = new THREE.Vector3();
  635. /**
  636. * @author mr.doob / http://mrdoob.com/
  637. */
  638. THREE.Ray = function ( origin, direction ) {
  639. this.origin = origin || new THREE.Vector3();
  640. this.direction = direction || new THREE.Vector3();
  641. var precision = 0.0001;
  642. this.setPrecision = function ( value ) {
  643. precision = value;
  644. };
  645. var a = new THREE.Vector3();
  646. var b = new THREE.Vector3();
  647. var c = new THREE.Vector3();
  648. var d = new THREE.Vector3();
  649. var originCopy = new THREE.Vector3();
  650. var directionCopy = new THREE.Vector3();
  651. var vector = new THREE.Vector3();
  652. var normal = new THREE.Vector3();
  653. var intersectPoint = new THREE.Vector3()
  654. this.intersectObject = function ( object ) {
  655. var intersect, intersects = [];
  656. if ( object instanceof THREE.Particle ) {
  657. var distance = distanceFromIntersection( this.origin, this.direction, object.matrixWorld.getPosition() );
  658. if ( distance > object.scale.x ) {
  659. return [];
  660. }
  661. intersect = {
  662. distance: distance,
  663. point: object.position,
  664. face: null,
  665. object: object
  666. };
  667. intersects.push( intersect );
  668. } else if ( object instanceof THREE.Mesh ) {
  669. // Checking boundingSphere
  670. var distance = distanceFromIntersection( this.origin, this.direction, object.matrixWorld.getPosition() );
  671. var scale = THREE.Frustum.__v1.set( object.matrixWorld.getColumnX().length(), object.matrixWorld.getColumnY().length(), object.matrixWorld.getColumnZ().length() );
  672. if ( distance > object.geometry.boundingSphere.radius * Math.max( scale.x, Math.max( scale.y, scale.z ) ) ) {
  673. return intersects;
  674. }
  675. // Checking faces
  676. var f, fl, face, dot, scalar,
  677. geometry = object.geometry,
  678. vertices = geometry.vertices,
  679. objMatrix;
  680. object.matrixRotationWorld.extractRotation( object.matrixWorld );
  681. for ( f = 0, fl = geometry.faces.length; f < fl; f ++ ) {
  682. face = geometry.faces[ f ];
  683. originCopy.copy( this.origin );
  684. directionCopy.copy( this.direction );
  685. objMatrix = object.matrixWorld;
  686. // determine if ray intersects the plane of the face
  687. // note: this works regardless of the direction of the face normal
  688. vector = objMatrix.multiplyVector3( vector.copy( face.centroid ) ).subSelf( originCopy );
  689. normal = object.matrixRotationWorld.multiplyVector3( normal.copy( face.normal ) );
  690. dot = directionCopy.dot( normal );
  691. // bail if ray and plane are parallel
  692. if ( Math.abs( dot ) < precision ) continue;
  693. // calc distance to plane
  694. scalar = normal.dot( vector ) / dot;
  695. // if negative distance, then plane is behind ray
  696. if ( scalar < 0 ) continue;
  697. if ( object.doubleSided || ( object.flipSided ? dot > 0 : dot < 0 ) ) {
  698. intersectPoint.add( originCopy, directionCopy.multiplyScalar( scalar ) );
  699. if ( face instanceof THREE.Face3 ) {
  700. a = objMatrix.multiplyVector3( a.copy( vertices[ face.a ] ) );
  701. b = objMatrix.multiplyVector3( b.copy( vertices[ face.b ] ) );
  702. c = objMatrix.multiplyVector3( c.copy( vertices[ face.c ] ) );
  703. if ( pointInFace3( intersectPoint, a, b, c ) ) {
  704. intersect = {
  705. distance: originCopy.distanceTo( intersectPoint ),
  706. point: intersectPoint.clone(),
  707. face: face,
  708. object: object
  709. };
  710. intersects.push( intersect );
  711. }
  712. } else if ( face instanceof THREE.Face4 ) {
  713. a = objMatrix.multiplyVector3( a.copy( vertices[ face.a ] ) );
  714. b = objMatrix.multiplyVector3( b.copy( vertices[ face.b ] ) );
  715. c = objMatrix.multiplyVector3( c.copy( vertices[ face.c ] ) );
  716. d = objMatrix.multiplyVector3( d.copy( vertices[ face.d ] ) );
  717. if ( pointInFace3( intersectPoint, a, b, d ) || pointInFace3( intersectPoint, b, c, d ) ) {
  718. intersect = {
  719. distance: originCopy.distanceTo( intersectPoint ),
  720. point: intersectPoint.clone(),
  721. face: face,
  722. object: object
  723. };
  724. intersects.push( intersect );
  725. }
  726. }
  727. }
  728. }
  729. }
  730. return intersects;
  731. }
  732. this.intersectObjects = function ( objects ) {
  733. var intersects = [];
  734. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  735. Array.prototype.push.apply( intersects, this.intersectObject( objects[ i ] ) );
  736. }
  737. intersects.sort( function ( a, b ) { return a.distance - b.distance; } );
  738. return intersects;
  739. };
  740. var v0 = new THREE.Vector3(), v1 = new THREE.Vector3(), v2 = new THREE.Vector3();
  741. var dot, intersect, distance;
  742. function distanceFromIntersection( origin, direction, position ) {
  743. v0.sub( position, origin );
  744. dot = v0.dot( direction );
  745. intersect = v1.add( origin, v2.copy( direction ).multiplyScalar( dot ) );
  746. distance = position.distanceTo( intersect );
  747. return distance;
  748. }
  749. // http://www.blackpawn.com/texts/pointinpoly/default.html
  750. var dot00, dot01, dot02, dot11, dot12, invDenom, u, v;
  751. function pointInFace3( p, a, b, c ) {
  752. v0.sub( c, a );
  753. v1.sub( b, a );
  754. v2.sub( p, a );
  755. dot00 = v0.dot( v0 );
  756. dot01 = v0.dot( v1 );
  757. dot02 = v0.dot( v2 );
  758. dot11 = v1.dot( v1 );
  759. dot12 = v1.dot( v2 );
  760. invDenom = 1 / ( dot00 * dot11 - dot01 * dot01 );
  761. u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  762. v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  763. return ( u >= 0 ) && ( v >= 0 ) && ( u + v < 1 );
  764. }
  765. };
  766. /**
  767. * @author mr.doob / http://mrdoob.com/
  768. */
  769. THREE.Rectangle = function () {
  770. var _left, _top, _right, _bottom,
  771. _width, _height, _isEmpty = true;
  772. function resize() {
  773. _width = _right - _left;
  774. _height = _bottom - _top;
  775. }
  776. this.getX = function () {
  777. return _left;
  778. };
  779. this.getY = function () {
  780. return _top;
  781. };
  782. this.getWidth = function () {
  783. return _width;
  784. };
  785. this.getHeight = function () {
  786. return _height;
  787. };
  788. this.getLeft = function() {
  789. return _left;
  790. };
  791. this.getTop = function() {
  792. return _top;
  793. };
  794. this.getRight = function() {
  795. return _right;
  796. };
  797. this.getBottom = function() {
  798. return _bottom;
  799. };
  800. this.set = function ( left, top, right, bottom ) {
  801. _isEmpty = false;
  802. _left = left; _top = top;
  803. _right = right; _bottom = bottom;
  804. resize();
  805. };
  806. this.addPoint = function ( x, y ) {
  807. if ( _isEmpty ) {
  808. _isEmpty = false;
  809. _left = x; _top = y;
  810. _right = x; _bottom = y;
  811. resize();
  812. } else {
  813. _left = _left < x ? _left : x; // Math.min( _left, x );
  814. _top = _top < y ? _top : y; // Math.min( _top, y );
  815. _right = _right > x ? _right : x; // Math.max( _right, x );
  816. _bottom = _bottom > y ? _bottom : y; // Math.max( _bottom, y );
  817. resize();
  818. }
  819. };
  820. this.add3Points = function ( x1, y1, x2, y2, x3, y3 ) {
  821. if (_isEmpty) {
  822. _isEmpty = false;
  823. _left = x1 < x2 ? ( x1 < x3 ? x1 : x3 ) : ( x2 < x3 ? x2 : x3 );
  824. _top = y1 < y2 ? ( y1 < y3 ? y1 : y3 ) : ( y2 < y3 ? y2 : y3 );
  825. _right = x1 > x2 ? ( x1 > x3 ? x1 : x3 ) : ( x2 > x3 ? x2 : x3 );
  826. _bottom = y1 > y2 ? ( y1 > y3 ? y1 : y3 ) : ( y2 > y3 ? y2 : y3 );
  827. resize();
  828. } else {
  829. _left = x1 < x2 ? ( x1 < x3 ? ( x1 < _left ? x1 : _left ) : ( x3 < _left ? x3 : _left ) ) : ( x2 < x3 ? ( x2 < _left ? x2 : _left ) : ( x3 < _left ? x3 : _left ) );
  830. _top = y1 < y2 ? ( y1 < y3 ? ( y1 < _top ? y1 : _top ) : ( y3 < _top ? y3 : _top ) ) : ( y2 < y3 ? ( y2 < _top ? y2 : _top ) : ( y3 < _top ? y3 : _top ) );
  831. _right = x1 > x2 ? ( x1 > x3 ? ( x1 > _right ? x1 : _right ) : ( x3 > _right ? x3 : _right ) ) : ( x2 > x3 ? ( x2 > _right ? x2 : _right ) : ( x3 > _right ? x3 : _right ) );
  832. _bottom = y1 > y2 ? ( y1 > y3 ? ( y1 > _bottom ? y1 : _bottom ) : ( y3 > _bottom ? y3 : _bottom ) ) : ( y2 > y3 ? ( y2 > _bottom ? y2 : _bottom ) : ( y3 > _bottom ? y3 : _bottom ) );
  833. resize();
  834. };
  835. };
  836. this.addRectangle = function ( r ) {
  837. if ( _isEmpty ) {
  838. _isEmpty = false;
  839. _left = r.getLeft(); _top = r.getTop();
  840. _right = r.getRight(); _bottom = r.getBottom();
  841. resize();
  842. } else {
  843. _left = _left < r.getLeft() ? _left : r.getLeft(); // Math.min(_left, r.getLeft() );
  844. _top = _top < r.getTop() ? _top : r.getTop(); // Math.min(_top, r.getTop() );
  845. _right = _right > r.getRight() ? _right : r.getRight(); // Math.max(_right, r.getRight() );
  846. _bottom = _bottom > r.getBottom() ? _bottom : r.getBottom(); // Math.max(_bottom, r.getBottom() );
  847. resize();
  848. }
  849. };
  850. this.inflate = function ( v ) {
  851. _left -= v; _top -= v;
  852. _right += v; _bottom += v;
  853. resize();
  854. };
  855. this.minSelf = function ( r ) {
  856. _left = _left > r.getLeft() ? _left : r.getLeft(); // Math.max( _left, r.getLeft() );
  857. _top = _top > r.getTop() ? _top : r.getTop(); // Math.max( _top, r.getTop() );
  858. _right = _right < r.getRight() ? _right : r.getRight(); // Math.min( _right, r.getRight() );
  859. _bottom = _bottom < r.getBottom() ? _bottom : r.getBottom(); // Math.min( _bottom, r.getBottom() );
  860. resize();
  861. };
  862. this.intersects = function ( r ) {
  863. // http://gamemath.com/2011/09/detecting-whether-two-boxes-overlap/
  864. if ( _right < r.getLeft() ) return false;
  865. if ( _left > r.getRight() ) return false;
  866. if ( _bottom < r.getTop() ) return false;
  867. if ( _top > r.getBottom() ) return false;
  868. return true;
  869. };
  870. this.empty = function () {
  871. _isEmpty = true;
  872. _left = 0; _top = 0;
  873. _right = 0; _bottom = 0;
  874. resize();
  875. };
  876. this.isEmpty = function () {
  877. return _isEmpty;
  878. };
  879. };
  880. /**
  881. * @author alteredq / http://alteredqualia.com/
  882. */
  883. THREE.Math = {
  884. // Clamp value to range <a, b>
  885. clamp: function ( x, a, b ) {
  886. return ( x < a ) ? a : ( ( x > b ) ? b : x );
  887. },
  888. // Clamp value to range <a, inf)
  889. clampBottom: function ( x, a ) {
  890. return x < a ? a : x;
  891. },
  892. // Linear mapping from range <a1, a2> to range <b1, b2>
  893. mapLinear: function ( x, a1, a2, b1, b2 ) {
  894. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  895. },
  896. // Random float from <0, 1> with 16 bits of randomness
  897. // (standard Math.random() creates repetitive patterns when applied over larger space)
  898. random16: function () {
  899. return ( 65280 * Math.random() + 255 * Math.random() ) / 65535;
  900. },
  901. // Random integer from <low, high> interval
  902. randInt: function ( low, high ) {
  903. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  904. },
  905. // Random float from <low, high> interval
  906. randFloat: function ( low, high ) {
  907. return low + Math.random() * ( high - low );
  908. },
  909. // Random float from <-range/2, range/2> interval
  910. randFloatSpread: function ( range ) {
  911. return range * ( 0.5 - Math.random() );
  912. },
  913. sign: function ( x ) {
  914. return ( x < 0 ) ? -1 : ( ( x > 0 ) ? 1 : 0 );
  915. }
  916. };
  917. /**
  918. * @author alteredq / http://alteredqualia.com/
  919. */
  920. THREE.Matrix3 = function () {
  921. this.elements = new Float32Array(9);
  922. };
  923. THREE.Matrix3.prototype = {
  924. constructor: THREE.Matrix3,
  925. getInverse: function ( matrix ) {
  926. // input: THREE.Matrix4
  927. // ( based on http://code.google.com/p/webgl-mjs/ )
  928. var me = matrix.elements;
  929. var a11 = me[10] * me[5] - me[6] * me[9];
  930. var a21 = - me[10] * me[1] + me[2] * me[9];
  931. var a31 = me[6] * me[1] - me[2] * me[5];
  932. var a12 = - me[10] * me[4] + me[6] * me[8];
  933. var a22 = me[10] * me[0] - me[2] * me[8];
  934. var a32 = - me[6] * me[0] + me[2] * me[4];
  935. var a13 = me[9] * me[4] - me[5] * me[8];
  936. var a23 = - me[9] * me[0] + me[1] * me[8];
  937. var a33 = me[5] * me[0] - me[1] * me[4];
  938. var det = me[0] * a11 + me[1] * a12 + me[2] * a13;
  939. // no inverse
  940. if ( det === 0 ) {
  941. console.warn( "Matrix3.getInverse(): determinant == 0" );
  942. }
  943. var idet = 1.0 / det;
  944. var m = this.elements;
  945. m[ 0 ] = idet * a11; m[ 1 ] = idet * a21; m[ 2 ] = idet * a31;
  946. m[ 3 ] = idet * a12; m[ 4 ] = idet * a22; m[ 5 ] = idet * a32;
  947. m[ 6 ] = idet * a13; m[ 7 ] = idet * a23; m[ 8 ] = idet * a33;
  948. return this;
  949. },
  950. transpose: function () {
  951. var tmp, m = this.elements;
  952. tmp = m[1]; m[1] = m[3]; m[3] = tmp;
  953. tmp = m[2]; m[2] = m[6]; m[6] = tmp;
  954. tmp = m[5]; m[5] = m[7]; m[7] = tmp;
  955. return this;
  956. },
  957. transposeIntoArray: function ( r ) {
  958. var m = this.m;
  959. r[ 0 ] = m[ 0 ];
  960. r[ 1 ] = m[ 3 ];
  961. r[ 2 ] = m[ 6 ];
  962. r[ 3 ] = m[ 1 ];
  963. r[ 4 ] = m[ 4 ];
  964. r[ 5 ] = m[ 7 ];
  965. r[ 6 ] = m[ 2 ];
  966. r[ 7 ] = m[ 5 ];
  967. r[ 8 ] = m[ 8 ];
  968. return this;
  969. }
  970. };
  971. /**
  972. * @author mr.doob / http://mrdoob.com/
  973. * @author supereggbert / http://www.paulbrunt.co.uk/
  974. * @author philogb / http://blog.thejit.org/
  975. * @author jordi_ros / http://plattsoft.com
  976. * @author D1plo1d / http://github.com/D1plo1d
  977. * @author alteredq / http://alteredqualia.com/
  978. * @author mikael emtinger / http://gomo.se/
  979. * @author timknip / http://www.floorplanner.com/
  980. */
  981. THREE.Matrix4 = function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  982. this.elements = new Float32Array(16);
  983. this.set(
  984. ( n11 !== undefined ) ? n11 : 1, n12 || 0, n13 || 0, n14 || 0,
  985. n21 || 0, ( n22 !== undefined ) ? n22 : 1, n23 || 0, n24 || 0,
  986. n31 || 0, n32 || 0, ( n33 !== undefined ) ? n33 : 1, n34 || 0,
  987. n41 || 0, n42 || 0, n43 || 0, ( n44 !== undefined ) ? n44 : 1
  988. );
  989. };
  990. THREE.Matrix4.prototype = {
  991. constructor: THREE.Matrix4,
  992. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  993. var te = this.elements;
  994. te[0] = n11; te[4] = n12; te[8] = n13; te[12] = n14;
  995. te[1] = n21; te[5] = n22; te[9] = n23; te[13] = n24;
  996. te[2] = n31; te[6] = n32; te[10] = n33; te[14] = n34;
  997. te[3] = n41; te[7] = n42; te[11] = n43; te[15] = n44;
  998. return this;
  999. },
  1000. identity: function () {
  1001. this.set(
  1002. 1, 0, 0, 0,
  1003. 0, 1, 0, 0,
  1004. 0, 0, 1, 0,
  1005. 0, 0, 0, 1
  1006. );
  1007. return this;
  1008. },
  1009. copy: function ( m ) {
  1010. var me = m.elements;
  1011. this.set(
  1012. me[0], me[4], me[8], me[12],
  1013. me[1], me[5], me[9], me[13],
  1014. me[2], me[6], me[10], me[14],
  1015. me[3], me[7], me[11], me[15]
  1016. );
  1017. return this;
  1018. },
  1019. lookAt: function ( eye, target, up ) {
  1020. var te = this.elements;
  1021. var x = THREE.Matrix4.__v1;
  1022. var y = THREE.Matrix4.__v2;
  1023. var z = THREE.Matrix4.__v3;
  1024. z.sub( eye, target ).normalize();
  1025. if ( z.length() === 0 ) {
  1026. z.z = 1;
  1027. }
  1028. x.cross( up, z ).normalize();
  1029. if ( x.length() === 0 ) {
  1030. z.x += 0.0001;
  1031. x.cross( up, z ).normalize();
  1032. }
  1033. y.cross( z, x );
  1034. te[0] = x.x; te[4] = y.x; te[8] = z.x;
  1035. te[1] = x.y; te[5] = y.y; te[9] = z.y;
  1036. te[2] = x.z; te[6] = y.z; te[10] = z.z;
  1037. return this;
  1038. },
  1039. multiply: function ( a, b ) {
  1040. var ae = a.elements,
  1041. be = b.elements,
  1042. te = this.elements;
  1043. var a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12];
  1044. var a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13];
  1045. var a31 = ae[2], a32 = ae[6], a33 = ae[10], a34 = ae[14];
  1046. var a41 = ae[3], a42 = ae[7], a43 = ae[11], a44 = ae[15];
  1047. var b11 = be[0], b12 = be[4], b13 = be[8], b14 = be[12];
  1048. var b21 = be[1], b22 = be[5], b23 = be[9], b24 = be[13];
  1049. var b31 = be[2], b32 = be[6], b33 = be[10], b34 = be[14];
  1050. var b41 = be[3], b42 = be[7], b43 = be[11], b44 = be[15];
  1051. te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  1052. te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  1053. te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  1054. te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  1055. te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  1056. te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  1057. te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  1058. te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  1059. te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  1060. te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  1061. te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  1062. te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  1063. te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  1064. te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  1065. te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  1066. te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  1067. return this;
  1068. },
  1069. multiplySelf: function ( m ) {
  1070. return this.multiply( this, m );
  1071. },
  1072. multiplyToArray: function ( a, b, r ) {
  1073. var te = this.elements;
  1074. this.multiply( a, b );
  1075. r[ 0 ] = te[0]; r[ 1 ] = te[1]; r[ 2 ] = te[2]; r[ 3 ] = te[3];
  1076. r[ 4 ] = te[4]; r[ 5 ] = te[5]; r[ 6 ] = te[6]; r[ 7 ] = te[7];
  1077. r[ 8 ] = te[8]; r[ 9 ] = te[9]; r[ 10 ] = te[10]; r[ 11 ] = te[11];
  1078. r[ 12 ] = te[12]; r[ 13 ] = te[13]; r[ 14 ] = te[14]; r[ 15 ] = te[15];
  1079. return this;
  1080. },
  1081. multiplyScalar: function ( s ) {
  1082. var te = this.elements;
  1083. te[0] *= s; te[4] *= s; te[8] *= s; te[12] *= s;
  1084. te[1] *= s; te[5] *= s; te[9] *= s; te[13] *= s;
  1085. te[2] *= s; te[6] *= s; te[10] *= s; te[14] *= s;
  1086. te[3] *= s; te[7] *= s; te[11] *= s; te[15] *= s;
  1087. return this;
  1088. },
  1089. multiplyVector3: function ( v ) {
  1090. var te = this.elements;
  1091. var vx = v.x, vy = v.y, vz = v.z;
  1092. var d = 1 / ( te[3] * vx + te[7] * vy + te[11] * vz + te[15] );
  1093. v.x = ( te[0] * vx + te[4] * vy + te[8] * vz + te[12] ) * d;
  1094. v.y = ( te[1] * vx + te[5] * vy + te[9] * vz + te[13] ) * d;
  1095. v.z = ( te[2] * vx + te[6] * vy + te[10] * vz + te[14] ) * d;
  1096. return v;
  1097. },
  1098. multiplyVector4: function ( v ) {
  1099. var te = this.elements;
  1100. var vx = v.x, vy = v.y, vz = v.z, vw = v.w;
  1101. v.x = te[0] * vx + te[4] * vy + te[8] * vz + te[12] * vw;
  1102. v.y = te[1] * vx + te[5] * vy + te[9] * vz + te[13] * vw;
  1103. v.z = te[2] * vx + te[6] * vy + te[10] * vz + te[14] * vw;
  1104. v.w = te[3] * vx + te[7] * vy + te[11] * vz + te[15] * vw;
  1105. return v;
  1106. },
  1107. rotateAxis: function ( v ) {
  1108. var te = this.elements;
  1109. var vx = v.x, vy = v.y, vz = v.z;
  1110. v.x = vx * te[0] + vy * te[4] + vz * te[8];
  1111. v.y = vx * te[1] + vy * te[5] + vz * te[9];
  1112. v.z = vx * te[2] + vy * te[6] + vz * te[10];
  1113. v.normalize();
  1114. return v;
  1115. },
  1116. crossVector: function ( a ) {
  1117. var te = this.elements;
  1118. var v = new THREE.Vector4();
  1119. v.x = te[0] * a.x + te[4] * a.y + te[8] * a.z + te[12] * a.w;
  1120. v.y = te[1] * a.x + te[5] * a.y + te[9] * a.z + te[13] * a.w;
  1121. v.z = te[2] * a.x + te[6] * a.y + te[10] * a.z + te[14] * a.w;
  1122. v.w = ( a.w ) ? te[3] * a.x + te[7] * a.y + te[11] * a.z + te[15] * a.w : 1;
  1123. return v;
  1124. },
  1125. determinant: function () {
  1126. var te = this.elements;
  1127. var n11 = te[0], n12 = te[4], n13 = te[8], n14 = te[12];
  1128. var n21 = te[1], n22 = te[5], n23 = te[9], n24 = te[13];
  1129. var n31 = te[2], n32 = te[6], n33 = te[10], n34 = te[14];
  1130. var n41 = te[3], n42 = te[7], n43 = te[11], n44 = te[15];
  1131. //TODO: make this more efficient
  1132. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  1133. return (
  1134. n14 * n23 * n32 * n41-
  1135. n13 * n24 * n32 * n41-
  1136. n14 * n22 * n33 * n41+
  1137. n12 * n24 * n33 * n41+
  1138. n13 * n22 * n34 * n41-
  1139. n12 * n23 * n34 * n41-
  1140. n14 * n23 * n31 * n42+
  1141. n13 * n24 * n31 * n42+
  1142. n14 * n21 * n33 * n42-
  1143. n11 * n24 * n33 * n42-
  1144. n13 * n21 * n34 * n42+
  1145. n11 * n23 * n34 * n42+
  1146. n14 * n22 * n31 * n43-
  1147. n12 * n24 * n31 * n43-
  1148. n14 * n21 * n32 * n43+
  1149. n11 * n24 * n32 * n43+
  1150. n12 * n21 * n34 * n43-
  1151. n11 * n22 * n34 * n43-
  1152. n13 * n22 * n31 * n44+
  1153. n12 * n23 * n31 * n44+
  1154. n13 * n21 * n32 * n44-
  1155. n11 * n23 * n32 * n44-
  1156. n12 * n21 * n33 * n44+
  1157. n11 * n22 * n33 * n44
  1158. );
  1159. },
  1160. transpose: function () {
  1161. var te = this.elements;
  1162. var tmp;
  1163. tmp = te[1]; te[1] = te[4]; te[4] = tmp;
  1164. tmp = te[2]; te[2] = te[8]; te[8] = tmp;
  1165. tmp = te[6]; te[6] = te[9]; te[9] = tmp;
  1166. tmp = te[3]; te[3] = te[12]; te[12] = tmp;
  1167. tmp = te[7]; te[7] = te[13]; te[13] = tmp;
  1168. tmp = te[11]; te[11] = te[14]; te[14] = tmp;
  1169. return this;
  1170. },
  1171. flattenToArray: function ( flat ) {
  1172. var te = this.elements;
  1173. flat[ 0 ] = te[0]; flat[ 1 ] = te[1]; flat[ 2 ] = te[2]; flat[ 3 ] = te[3];
  1174. flat[ 4 ] = te[4]; flat[ 5 ] = te[5]; flat[ 6 ] = te[6]; flat[ 7 ] = te[7];
  1175. flat[ 8 ] = te[8]; flat[ 9 ] = te[9]; flat[ 10 ] = te[10]; flat[ 11 ] = te[11];
  1176. flat[ 12 ] = te[12]; flat[ 13 ] = te[13]; flat[ 14 ] = te[14]; flat[ 15 ] = te[15];
  1177. return flat;
  1178. },
  1179. flattenToArrayOffset: function( flat, offset ) {
  1180. var te = this.elements;
  1181. flat[ offset ] = te[0];
  1182. flat[ offset + 1 ] = te[1];
  1183. flat[ offset + 2 ] = te[2];
  1184. flat[ offset + 3 ] = te[3];
  1185. flat[ offset + 4 ] = te[4];
  1186. flat[ offset + 5 ] = te[5];
  1187. flat[ offset + 6 ] = te[6];
  1188. flat[ offset + 7 ] = te[7];
  1189. flat[ offset + 8 ] = te[8];
  1190. flat[ offset + 9 ] = te[9];
  1191. flat[ offset + 10 ] = te[10];
  1192. flat[ offset + 11 ] = te[11];
  1193. flat[ offset + 12 ] = te[12];
  1194. flat[ offset + 13 ] = te[13];
  1195. flat[ offset + 14 ] = te[14];
  1196. flat[ offset + 15 ] = te[15];
  1197. return flat;
  1198. },
  1199. getPosition: function () {
  1200. var te = this.elements;
  1201. return THREE.Matrix4.__v1.set( te[12], te[13], te[14] );
  1202. },
  1203. setPosition: function ( v ) {
  1204. var te = this.elements;
  1205. te[12] = v.x;
  1206. te[13] = v.y;
  1207. te[14] = v.z;
  1208. return this;
  1209. },
  1210. getColumnX: function () {
  1211. var te = this.elements;
  1212. return THREE.Matrix4.__v1.set( te[0], te[1], te[2] );
  1213. },
  1214. getColumnY: function () {
  1215. var te = this.elements;
  1216. return THREE.Matrix4.__v1.set( te[4], te[5], te[6] );
  1217. },
  1218. getColumnZ: function() {
  1219. var te = this.elements;
  1220. return THREE.Matrix4.__v1.set( te[8], te[9], te[10] );
  1221. },
  1222. getInverse: function ( m ) {
  1223. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  1224. var te = this.elements;
  1225. var me = m.elements;
  1226. var n11 = me[0], n12 = me[4], n13 = me[8], n14 = me[12];
  1227. var n21 = me[1], n22 = me[5], n23 = me[9], n24 = me[13];
  1228. var n31 = me[2], n32 = me[6], n33 = me[10], n34 = me[14];
  1229. var n41 = me[3], n42 = me[7], n43 = me[11], n44 = me[15];
  1230. te[0] = n23*n34*n42 - n24*n33*n42 + n24*n32*n43 - n22*n34*n43 - n23*n32*n44 + n22*n33*n44;
  1231. te[4] = n14*n33*n42 - n13*n34*n42 - n14*n32*n43 + n12*n34*n43 + n13*n32*n44 - n12*n33*n44;
  1232. te[8] = n13*n24*n42 - n14*n23*n42 + n14*n22*n43 - n12*n24*n43 - n13*n22*n44 + n12*n23*n44;
  1233. te[12] = n14*n23*n32 - n13*n24*n32 - n14*n22*n33 + n12*n24*n33 + n13*n22*n34 - n12*n23*n34;
  1234. te[1] = n24*n33*n41 - n23*n34*n41 - n24*n31*n43 + n21*n34*n43 + n23*n31*n44 - n21*n33*n44;
  1235. te[5] = n13*n34*n41 - n14*n33*n41 + n14*n31*n43 - n11*n34*n43 - n13*n31*n44 + n11*n33*n44;
  1236. te[9] = n14*n23*n41 - n13*n24*n41 - n14*n21*n43 + n11*n24*n43 + n13*n21*n44 - n11*n23*n44;
  1237. te[13] = n13*n24*n31 - n14*n23*n31 + n14*n21*n33 - n11*n24*n33 - n13*n21*n34 + n11*n23*n34;
  1238. te[2] = n22*n34*n41 - n24*n32*n41 + n24*n31*n42 - n21*n34*n42 - n22*n31*n44 + n21*n32*n44;
  1239. te[6] = n14*n32*n41 - n12*n34*n41 - n14*n31*n42 + n11*n34*n42 + n12*n31*n44 - n11*n32*n44;
  1240. te[10] = n12*n24*n41 - n14*n22*n41 + n14*n21*n42 - n11*n24*n42 - n12*n21*n44 + n11*n22*n44;
  1241. te[14] = n14*n22*n31 - n12*n24*n31 - n14*n21*n32 + n11*n24*n32 + n12*n21*n34 - n11*n22*n34;
  1242. te[3] = n23*n32*n41 - n22*n33*n41 - n23*n31*n42 + n21*n33*n42 + n22*n31*n43 - n21*n32*n43;
  1243. te[7] = n12*n33*n41 - n13*n32*n41 + n13*n31*n42 - n11*n33*n42 - n12*n31*n43 + n11*n32*n43;
  1244. te[11] = n13*n22*n41 - n12*n23*n41 - n13*n21*n42 + n11*n23*n42 + n12*n21*n43 - n11*n22*n43;
  1245. te[15] = n12*n23*n31 - n13*n22*n31 + n13*n21*n32 - n11*n23*n32 - n12*n21*n33 + n11*n22*n33;
  1246. this.multiplyScalar( 1 / m.determinant() );
  1247. return this;
  1248. },
  1249. setRotationFromEuler: function( v, order ) {
  1250. var te = this.elements;
  1251. var x = v.x, y = v.y, z = v.z;
  1252. var a = Math.cos( x ), b = Math.sin( x );
  1253. var c = Math.cos( y ), d = Math.sin( y );
  1254. var e = Math.cos( z ), f = Math.sin( z );
  1255. switch ( order ) {
  1256. case 'YXZ':
  1257. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  1258. te[0] = ce + df * b;
  1259. te[4] = de * b - cf;
  1260. te[8] = a * d;
  1261. te[1] = a * f;
  1262. te[5] = a * e;
  1263. te[9] = - b;
  1264. te[2] = cf * b - de;
  1265. te[6] = df + ce * b;
  1266. te[10] = a * c;
  1267. break;
  1268. case 'ZXY':
  1269. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  1270. te[0] = ce - df * b;
  1271. te[4] = - a * f;
  1272. te[8] = de + cf * b;
  1273. te[1] = cf + de * b;
  1274. te[5] = a * e;
  1275. te[9] = df - ce * b;
  1276. te[2] = - a * d;
  1277. te[6] = b;
  1278. te[10] = a * c;
  1279. break;
  1280. case 'ZYX':
  1281. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  1282. te[0] = c * e;
  1283. te[4] = be * d - af;
  1284. te[8] = ae * d + bf;
  1285. te[1] = c * f;
  1286. te[5] = bf * d + ae;
  1287. te[9] = af * d - be;
  1288. te[2] = - d;
  1289. te[6] = b * c;
  1290. te[10] = a * c;
  1291. break;
  1292. case 'YZX':
  1293. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  1294. te[0] = c * e;
  1295. te[4] = bd - ac * f;
  1296. te[8] = bc * f + ad;
  1297. te[1] = f;
  1298. te[5] = a * e;
  1299. te[9] = - b * e;
  1300. te[2] = - d * e;
  1301. te[6] = ad * f + bc;
  1302. te[10] = ac - bd * f;
  1303. break;
  1304. case 'XZY':
  1305. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  1306. te[0] = c * e;
  1307. te[4] = - f;
  1308. te[8] = d * e;
  1309. te[1] = ac * f + bd;
  1310. te[5] = a * e;
  1311. te[9] = ad * f - bc;
  1312. te[2] = bc * f - ad;
  1313. te[6] = b * e;
  1314. te[10] = bd * f + ac;
  1315. break;
  1316. default: // 'XYZ'
  1317. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  1318. te[0] = c * e;
  1319. te[4] = - c * f;
  1320. te[8] = d;
  1321. te[1] = af + be * d;
  1322. te[5] = ae - bf * d;
  1323. te[9] = - b * c;
  1324. te[2] = bf - ae * d;
  1325. te[6] = be + af * d;
  1326. te[10] = a * c;
  1327. break;
  1328. }
  1329. return this;
  1330. },
  1331. setRotationFromQuaternion: function( q ) {
  1332. var te = this.elements;
  1333. var x = q.x, y = q.y, z = q.z, w = q.w;
  1334. var x2 = x + x, y2 = y + y, z2 = z + z;
  1335. var xx = x * x2, xy = x * y2, xz = x * z2;
  1336. var yy = y * y2, yz = y * z2, zz = z * z2;
  1337. var wx = w * x2, wy = w * y2, wz = w * z2;
  1338. te[0] = 1 - ( yy + zz );
  1339. te[4] = xy - wz;
  1340. te[8] = xz + wy;
  1341. te[1] = xy + wz;
  1342. te[5] = 1 - ( xx + zz );
  1343. te[9] = yz - wx;
  1344. te[2] = xz - wy;
  1345. te[6] = yz + wx;
  1346. te[10] = 1 - ( xx + yy );
  1347. return this;
  1348. },
  1349. compose: function ( translation, rotation, scale ) {
  1350. var te = this.elements;
  1351. var mRotation = THREE.Matrix4.__m1;
  1352. var mScale = THREE.Matrix4.__m2;
  1353. mRotation.identity();
  1354. mRotation.setRotationFromQuaternion( rotation );
  1355. mScale.makeScale( scale.x, scale.y, scale.z );
  1356. this.multiply( mRotation, mScale );
  1357. te[12] = translation.x;
  1358. te[13] = translation.y;
  1359. te[14] = translation.z;
  1360. return this;
  1361. },
  1362. decompose: function ( translation, rotation, scale ) {
  1363. // grab the axis vectors
  1364. var te = this.elements;
  1365. var x = THREE.Matrix4.__v1;
  1366. var y = THREE.Matrix4.__v2;
  1367. var z = THREE.Matrix4.__v3;
  1368. x.set( te[0], te[1], te[2] );
  1369. y.set( te[4], te[5], te[6] );
  1370. z.set( te[8], te[9], te[10] );
  1371. translation = ( translation instanceof THREE.Vector3 ) ? translation : new THREE.Vector3();
  1372. rotation = ( rotation instanceof THREE.Quaternion ) ? rotation : new THREE.Quaternion();
  1373. scale = ( scale instanceof THREE.Vector3 ) ? scale : new THREE.Vector3();
  1374. scale.x = x.length();
  1375. scale.y = y.length();
  1376. scale.z = z.length();
  1377. translation.x = te[12];
  1378. translation.y = te[13];
  1379. translation.z = te[14];
  1380. // scale the rotation part
  1381. var matrix = THREE.Matrix4.__m1;
  1382. matrix.copy( this );
  1383. matrix.elements[0] /= scale.x;
  1384. matrix.elements[1] /= scale.x;
  1385. matrix.elements[2] /= scale.x;
  1386. matrix.elements[4] /= scale.y;
  1387. matrix.elements[5] /= scale.y;
  1388. matrix.elements[6] /= scale.y;
  1389. matrix.elements[8] /= scale.z;
  1390. matrix.elements[9] /= scale.z;
  1391. matrix.elements[10] /= scale.z;
  1392. rotation.setFromRotationMatrix( matrix );
  1393. return [ translation, rotation, scale ];
  1394. },
  1395. extractPosition: function ( m ) {
  1396. var te = this.elements;
  1397. var me = m.elements;
  1398. te[12] = me[12];
  1399. te[13] = me[13];
  1400. te[14] = me[14];
  1401. return this;
  1402. },
  1403. extractRotation: function ( m ) {
  1404. var te = this.elements;
  1405. var me = m.elements;
  1406. var vector = THREE.Matrix4.__v1;
  1407. var scaleX = 1 / vector.set( me[0], me[1], me[2] ).length();
  1408. var scaleY = 1 / vector.set( me[4], me[5], me[6] ).length();
  1409. var scaleZ = 1 / vector.set( me[8], me[9], me[10] ).length();
  1410. te[0] = me[0] * scaleX;
  1411. te[1] = me[1] * scaleX;
  1412. te[2] = me[2] * scaleX;
  1413. te[4] = me[4] * scaleY;
  1414. te[5] = me[5] * scaleY;
  1415. te[6] = me[6] * scaleY;
  1416. te[8] = me[8] * scaleZ;
  1417. te[9] = me[9] * scaleZ;
  1418. te[10] = me[10] * scaleZ;
  1419. return this;
  1420. },
  1421. //
  1422. translate: function ( v ) {
  1423. var te = this.elements;
  1424. var x = v.x, y = v.y, z = v.z;
  1425. te[12] = te[0] * x + te[4] * y + te[8] * z + te[12];
  1426. te[13] = te[1] * x + te[5] * y + te[9] * z + te[13];
  1427. te[14] = te[2] * x + te[6] * y + te[10] * z + te[14];
  1428. te[15] = te[3] * x + te[7] * y + te[11] * z + te[15];
  1429. return this;
  1430. },
  1431. rotateX: function ( angle ) {
  1432. var te = this.elements;
  1433. var m12 = te[4];
  1434. var m22 = te[5];
  1435. var m32 = te[6];
  1436. var m42 = te[7];
  1437. var m13 = te[8];
  1438. var m23 = te[9];
  1439. var m33 = te[10];
  1440. var m43 = te[11];
  1441. var c = Math.cos( angle );
  1442. var s = Math.sin( angle );
  1443. te[4] = c * m12 + s * m13;
  1444. te[5] = c * m22 + s * m23;
  1445. te[6] = c * m32 + s * m33;
  1446. te[7] = c * m42 + s * m43;
  1447. te[8] = c * m13 - s * m12;
  1448. te[9] = c * m23 - s * m22;
  1449. te[10] = c * m33 - s * m32;
  1450. te[11] = c * m43 - s * m42;
  1451. return this;
  1452. },
  1453. rotateY: function ( angle ) {
  1454. var te = this.elements;
  1455. var m11 = te[0];
  1456. var m21 = te[1];
  1457. var m31 = te[2];
  1458. var m41 = te[3];
  1459. var m13 = te[8];
  1460. var m23 = te[9];
  1461. var m33 = te[10];
  1462. var m43 = te[11];
  1463. var c = Math.cos( angle );
  1464. var s = Math.sin( angle );
  1465. te[0] = c * m11 - s * m13;
  1466. te[1] = c * m21 - s * m23;
  1467. te[2] = c * m31 - s * m33;
  1468. te[3] = c * m41 - s * m43;
  1469. te[8] = c * m13 + s * m11;
  1470. te[9] = c * m23 + s * m21;
  1471. te[10] = c * m33 + s * m31;
  1472. te[11] = c * m43 + s * m41;
  1473. return this;
  1474. },
  1475. rotateZ: function ( angle ) {
  1476. var te = this.elements;
  1477. var m11 = te[0];
  1478. var m21 = te[1];
  1479. var m31 = te[2];
  1480. var m41 = te[3];
  1481. var m12 = te[4];
  1482. var m22 = te[5];
  1483. var m32 = te[6];
  1484. var m42 = te[7];
  1485. var c = Math.cos( angle );
  1486. var s = Math.sin( angle );
  1487. te[0] = c * m11 + s * m12;
  1488. te[1] = c * m21 + s * m22;
  1489. te[2] = c * m31 + s * m32;
  1490. te[3] = c * m41 + s * m42;
  1491. te[4] = c * m12 - s * m11;
  1492. te[5] = c * m22 - s * m21;
  1493. te[6] = c * m32 - s * m31;
  1494. te[7] = c * m42 - s * m41;
  1495. return this;
  1496. },
  1497. rotateByAxis: function ( axis, angle ) {
  1498. var te = this.elements;
  1499. // optimize by checking axis
  1500. if ( axis.x === 1 && axis.y === 0 && axis.z === 0 ) {
  1501. return this.rotateX( angle );
  1502. } else if ( axis.x === 0 && axis.y === 1 && axis.z === 0 ) {
  1503. return this.rotateY( angle );
  1504. } else if ( axis.x === 0 && axis.y === 0 && axis.z === 1 ) {
  1505. return this.rotateZ( angle );
  1506. }
  1507. var x = axis.x, y = axis.y, z = axis.z;
  1508. var n = Math.sqrt(x * x + y * y + z * z);
  1509. x /= n;
  1510. y /= n;
  1511. z /= n;
  1512. var xx = x * x, yy = y * y, zz = z * z;
  1513. var c = Math.cos( angle );
  1514. var s = Math.sin( angle );
  1515. var oneMinusCosine = 1 - c;
  1516. var xy = x * y * oneMinusCosine;
  1517. var xz = x * z * oneMinusCosine;
  1518. var yz = y * z * oneMinusCosine;
  1519. var xs = x * s;
  1520. var ys = y * s;
  1521. var zs = z * s;
  1522. var r11 = xx + (1 - xx) * c;
  1523. var r21 = xy + zs;
  1524. var r31 = xz - ys;
  1525. var r12 = xy - zs;
  1526. var r22 = yy + (1 - yy) * c;
  1527. var r32 = yz + xs;
  1528. var r13 = xz + ys;
  1529. var r23 = yz - xs;
  1530. var r33 = zz + (1 - zz) * c;
  1531. var m11 = te[0], m21 = te[1], m31 = te[2], m41 = te[3];
  1532. var m12 = te[4], m22 = te[5], m32 = te[6], m42 = te[7];
  1533. var m13 = te[8], m23 = te[9], m33 = te[10], m43 = te[11];
  1534. var m14 = te[12], m24 = te[13], m34 = te[14], m44 = te[15];
  1535. te[0] = r11 * m11 + r21 * m12 + r31 * m13;
  1536. te[1] = r11 * m21 + r21 * m22 + r31 * m23;
  1537. te[2] = r11 * m31 + r21 * m32 + r31 * m33;
  1538. te[3] = r11 * m41 + r21 * m42 + r31 * m43;
  1539. te[4] = r12 * m11 + r22 * m12 + r32 * m13;
  1540. te[5] = r12 * m21 + r22 * m22 + r32 * m23;
  1541. te[6] = r12 * m31 + r22 * m32 + r32 * m33;
  1542. te[7] = r12 * m41 + r22 * m42 + r32 * m43;
  1543. te[8] = r13 * m11 + r23 * m12 + r33 * m13;
  1544. te[9] = r13 * m21 + r23 * m22 + r33 * m23;
  1545. te[10] = r13 * m31 + r23 * m32 + r33 * m33;
  1546. te[11] = r13 * m41 + r23 * m42 + r33 * m43;
  1547. return this;
  1548. },
  1549. scale: function ( v ) {
  1550. var te = this.elements;
  1551. var x = v.x, y = v.y, z = v.z;
  1552. te[0] *= x; te[4] *= y; te[8] *= z;
  1553. te[1] *= x; te[5] *= y; te[9] *= z;
  1554. te[2] *= x; te[6] *= y; te[10] *= z;
  1555. te[3] *= x; te[7] *= y; te[11] *= z;
  1556. return this;
  1557. },
  1558. getMaxScaleOnAxis: function () {
  1559. var te = this.elements;
  1560. var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
  1561. var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
  1562. var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
  1563. return Math.sqrt( Math.max( scaleXSq, Math.max( scaleYSq, scaleZSq ) ) );
  1564. },
  1565. //
  1566. makeTranslation: function ( x, y, z ) {
  1567. this.set(
  1568. 1, 0, 0, x,
  1569. 0, 1, 0, y,
  1570. 0, 0, 1, z,
  1571. 0, 0, 0, 1
  1572. );
  1573. return this;
  1574. },
  1575. makeRotationX: function ( theta ) {
  1576. var c = Math.cos( theta ), s = Math.sin( theta );
  1577. this.set(
  1578. 1, 0, 0, 0,
  1579. 0, c, -s, 0,
  1580. 0, s, c, 0,
  1581. 0, 0, 0, 1
  1582. );
  1583. return this;
  1584. },
  1585. makeRotationY: function ( theta ) {
  1586. var c = Math.cos( theta ), s = Math.sin( theta );
  1587. this.set(
  1588. c, 0, s, 0,
  1589. 0, 1, 0, 0,
  1590. -s, 0, c, 0,
  1591. 0, 0, 0, 1
  1592. );
  1593. return this;
  1594. },
  1595. makeRotationZ: function ( theta ) {
  1596. var c = Math.cos( theta ), s = Math.sin( theta );
  1597. this.set(
  1598. c, -s, 0, 0,
  1599. s, c, 0, 0,
  1600. 0, 0, 1, 0,
  1601. 0, 0, 0, 1
  1602. );
  1603. return this;
  1604. },
  1605. makeRotationAxis: function ( axis, angle ) {
  1606. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  1607. var c = Math.cos( angle );
  1608. var s = Math.sin( angle );
  1609. var t = 1 - c;
  1610. var x = axis.x, y = axis.y, z = axis.z;
  1611. var tx = t * x, ty = t * y;
  1612. this.set(
  1613. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  1614. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  1615. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  1616. 0, 0, 0, 1
  1617. );
  1618. return this;
  1619. },
  1620. makeScale: function ( x, y, z ) {
  1621. this.set(
  1622. x, 0, 0, 0,
  1623. 0, y, 0, 0,
  1624. 0, 0, z, 0,
  1625. 0, 0, 0, 1
  1626. );
  1627. return this;
  1628. },
  1629. makeFrustum: function ( left, right, bottom, top, near, far ) {
  1630. var te = this.elements;
  1631. var x = 2 * near / ( right - left );
  1632. var y = 2 * near / ( top - bottom );
  1633. var a = ( right + left ) / ( right - left );
  1634. var b = ( top + bottom ) / ( top - bottom );
  1635. var c = - ( far + near ) / ( far - near );
  1636. var d = - 2 * far * near / ( far - near );
  1637. te[0] = x; te[4] = 0; te[8] = a; te[12] = 0;
  1638. te[1] = 0; te[5] = y; te[9] = b; te[13] = 0;
  1639. te[2] = 0; te[6] = 0; te[10] = c; te[14] = d;
  1640. te[3] = 0; te[7] = 0; te[11] = - 1; te[15] = 0;
  1641. return this;
  1642. },
  1643. makePerspective: function ( fov, aspect, near, far ) {
  1644. var ymax = near * Math.tan( fov * Math.PI / 360 );
  1645. var ymin = - ymax;
  1646. var xmin = ymin * aspect;
  1647. var xmax = ymax * aspect;
  1648. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  1649. },
  1650. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  1651. var te = this.elements;
  1652. var w = right - left;
  1653. var h = top - bottom;
  1654. var p = far - near;
  1655. var x = ( right + left ) / w;
  1656. var y = ( top + bottom ) / h;
  1657. var z = ( far + near ) / p;
  1658. te[0] = 2 / w; te[4] = 0; te[8] = 0; te[12] = -x;
  1659. te[1] = 0; te[5] = 2 / h; te[9] = 0; te[13] = -y;
  1660. te[2] = 0; te[6] = 0; te[10] = -2 / p; te[14] = -z;
  1661. te[3] = 0; te[7] = 0; te[11] = 0; te[15] = 1;
  1662. return this;
  1663. },
  1664. clone: function () {
  1665. var te = this.elements;
  1666. return new THREE.Matrix4(
  1667. te[0], te[4], te[8], te[12],
  1668. te[1], te[5], te[9], te[13],
  1669. te[2], te[6], te[10], te[14],
  1670. te[3], te[7], te[11], te[15]
  1671. );
  1672. }
  1673. };
  1674. THREE.Matrix4.__v1 = new THREE.Vector3();
  1675. THREE.Matrix4.__v2 = new THREE.Vector3();
  1676. THREE.Matrix4.__v3 = new THREE.Vector3();
  1677. THREE.Matrix4.__m1 = new THREE.Matrix4();
  1678. THREE.Matrix4.__m2 = new THREE.Matrix4();
  1679. /**
  1680. * @author mr.doob / http://mrdoob.com/
  1681. * @author mikael emtinger / http://gomo.se/
  1682. * @author alteredq / http://alteredqualia.com/
  1683. */
  1684. THREE.Object3D = function () {
  1685. this.id = THREE.Object3DCount ++;
  1686. this.name = '';
  1687. this.parent = undefined;
  1688. this.children = [];
  1689. this.up = new THREE.Vector3( 0, 1, 0 );
  1690. this.position = new THREE.Vector3();
  1691. this.rotation = new THREE.Vector3();
  1692. this.eulerOrder = 'XYZ';
  1693. this.scale = new THREE.Vector3( 1, 1, 1 );
  1694. this.doubleSided = false;
  1695. this.flipSided = false;
  1696. this.renderDepth = null;
  1697. this.rotationAutoUpdate = true;
  1698. this.matrix = new THREE.Matrix4();
  1699. this.matrixWorld = new THREE.Matrix4();
  1700. this.matrixRotationWorld = new THREE.Matrix4();
  1701. this.matrixAutoUpdate = true;
  1702. this.matrixWorldNeedsUpdate = true;
  1703. this.quaternion = new THREE.Quaternion();
  1704. this.useQuaternion = false;
  1705. this.boundRadius = 0.0;
  1706. this.boundRadiusScale = 1.0;
  1707. this.visible = true;
  1708. this.castShadow = false;
  1709. this.receiveShadow = false;
  1710. this.frustumCulled = true;
  1711. this._vector = new THREE.Vector3();
  1712. };
  1713. THREE.Object3D.prototype = {
  1714. constructor: THREE.Object3D,
  1715. applyMatrix: function ( matrix ) {
  1716. this.matrix.multiply( matrix, this.matrix );
  1717. this.scale.getScaleFromMatrix( this.matrix );
  1718. this.rotation.getRotationFromMatrix( this.matrix, this.scale );
  1719. this.position.getPositionFromMatrix( this.matrix );
  1720. },
  1721. translate: function ( distance, axis ) {
  1722. this.matrix.rotateAxis( axis );
  1723. this.position.addSelf( axis.multiplyScalar( distance ) );
  1724. },
  1725. translateX: function ( distance ) {
  1726. this.translate( distance, this._vector.set( 1, 0, 0 ) );
  1727. },
  1728. translateY: function ( distance ) {
  1729. this.translate( distance, this._vector.set( 0, 1, 0 ) );
  1730. },
  1731. translateZ: function ( distance ) {
  1732. this.translate( distance, this._vector.set( 0, 0, 1 ) );
  1733. },
  1734. lookAt: function ( vector ) {
  1735. // TODO: Add hierarchy support.
  1736. this.matrix.lookAt( vector, this.position, this.up );
  1737. if ( this.rotationAutoUpdate ) {
  1738. this.rotation.getRotationFromMatrix( this.matrix );
  1739. }
  1740. },
  1741. add: function ( object ) {
  1742. if ( object === this ) {
  1743. console.warn( 'THREE.Object3D.add: An object can\'t be added as a child of itself.' );
  1744. return;
  1745. }
  1746. if ( object instanceof THREE.Object3D ) { // && this.children.indexOf( object ) === - 1
  1747. if ( object.parent !== undefined ) {
  1748. object.parent.remove( object );
  1749. }
  1750. object.parent = this;
  1751. this.children.push( object );
  1752. // add to scene
  1753. var scene = this;
  1754. while ( scene.parent !== undefined ) {
  1755. scene = scene.parent;
  1756. }
  1757. if ( scene !== undefined && scene instanceof THREE.Scene ) {
  1758. scene.__addObject( object );
  1759. }
  1760. }
  1761. },
  1762. remove: function ( object ) {
  1763. var index = this.children.indexOf( object );
  1764. if ( index !== - 1 ) {
  1765. object.parent = undefined;
  1766. this.children.splice( index, 1 );
  1767. // remove from scene
  1768. var scene = this;
  1769. while ( scene.parent !== undefined ) {
  1770. scene = scene.parent;
  1771. }
  1772. if ( scene !== undefined && scene instanceof THREE.Scene ) {
  1773. scene.__removeObject( object );
  1774. }
  1775. }
  1776. },
  1777. getChildByName: function ( name, recursive ) {
  1778. var c, cl, child;
  1779. for ( c = 0, cl = this.children.length; c < cl; c ++ ) {
  1780. child = this.children[ c ];
  1781. if ( child.name === name ) {
  1782. return child;
  1783. }
  1784. if ( recursive ) {
  1785. child = child.getChildByName( name, recursive );
  1786. if ( child !== undefined ) {
  1787. return child;
  1788. }
  1789. }
  1790. }
  1791. return undefined;
  1792. },
  1793. updateMatrix: function () {
  1794. this.matrix.setPosition( this.position );
  1795. if ( this.useQuaternion ) {
  1796. this.matrix.setRotationFromQuaternion( this.quaternion );
  1797. } else {
  1798. this.matrix.setRotationFromEuler( this.rotation, this.eulerOrder );
  1799. }
  1800. if ( this.scale.x !== 1 || this.scale.y !== 1 || this.scale.z !== 1 ) {
  1801. this.matrix.scale( this.scale );
  1802. this.boundRadiusScale = Math.max( this.scale.x, Math.max( this.scale.y, this.scale.z ) );
  1803. }
  1804. this.matrixWorldNeedsUpdate = true;
  1805. },
  1806. updateMatrixWorld: function ( force ) {
  1807. this.matrixAutoUpdate && this.updateMatrix();
  1808. // update matrixWorld
  1809. if ( this.matrixWorldNeedsUpdate || force ) {
  1810. if ( this.parent ) {
  1811. this.matrixWorld.multiply( this.parent.matrixWorld, this.matrix );
  1812. } else {
  1813. this.matrixWorld.copy( this.matrix );
  1814. }
  1815. this.matrixWorldNeedsUpdate = false;
  1816. force = true;
  1817. }
  1818. // update children
  1819. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  1820. this.children[ i ].updateMatrixWorld( force );
  1821. }
  1822. }
  1823. };
  1824. THREE.Object3DCount = 0;
  1825. /**
  1826. * @author mr.doob / http://mrdoob.com/
  1827. * @author supereggbert / http://www.paulbrunt.co.uk/
  1828. * @author julianwa / https://github.com/julianwa
  1829. */
  1830. THREE.Projector = function() {
  1831. var _object, _objectCount, _objectPool = [],
  1832. _vertex, _vertexCount, _vertexPool = [],
  1833. _face, _face3Count, _face3Pool = [], _face4Count, _face4Pool = [],
  1834. _line, _lineCount, _linePool = [],
  1835. _particle, _particleCount, _particlePool = [],
  1836. _renderData = { objects: [], sprites: [], lights: [], elements: [] },
  1837. _vector3 = new THREE.Vector3(),
  1838. _vector4 = new THREE.Vector4(),
  1839. _projScreenMatrix = new THREE.Matrix4(),
  1840. _projScreenobjectMatrixWorld = new THREE.Matrix4(),
  1841. _frustum = new THREE.Frustum(),
  1842. _clippedVertex1PositionScreen = new THREE.Vector4(),
  1843. _clippedVertex2PositionScreen = new THREE.Vector4(),
  1844. _face3VertexNormals;
  1845. this.projectVector = function ( vector, camera ) {
  1846. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  1847. _projScreenMatrix.multiply( camera.projectionMatrix, camera.matrixWorldInverse );
  1848. _projScreenMatrix.multiplyVector3( vector );
  1849. return vector;
  1850. };
  1851. this.unprojectVector = function ( vector, camera ) {
  1852. camera.projectionMatrixInverse.getInverse( camera.projectionMatrix );
  1853. _projScreenMatrix.multiply( camera.matrixWorld, camera.projectionMatrixInverse );
  1854. _projScreenMatrix.multiplyVector3( vector );
  1855. return vector;
  1856. };
  1857. this.pickingRay = function ( vector, camera ) {
  1858. var end, ray, t;
  1859. // set two vectors with opposing z values
  1860. vector.z = -1.0;
  1861. end = new THREE.Vector3( vector.x, vector.y, 1.0 );
  1862. this.unprojectVector( vector, camera );
  1863. this.unprojectVector( end, camera );
  1864. // find direction from vector to end
  1865. end.subSelf( vector ).normalize();
  1866. return new THREE.Ray( vector, end );
  1867. };
  1868. this.projectGraph = function ( root, sort ) {
  1869. _objectCount = 0;
  1870. _renderData.objects.length = 0;
  1871. _renderData.sprites.length = 0;
  1872. _renderData.lights.length = 0;
  1873. var projectObject = function ( object ) {
  1874. if ( object.visible === false ) return;
  1875. if ( ( object instanceof THREE.Mesh || object instanceof THREE.Line ) &&
  1876. ( object.frustumCulled === false || _frustum.contains( object ) ) ) {
  1877. _vector3.copy( object.matrixWorld.getPosition() );
  1878. _projScreenMatrix.multiplyVector3( _vector3 );
  1879. _object = getNextObjectInPool();
  1880. _object.object = object;
  1881. _object.z = _vector3.z;
  1882. _renderData.objects.push( _object );
  1883. } else if ( object instanceof THREE.Sprite || object instanceof THREE.Particle ) {
  1884. _vector3.copy( object.matrixWorld.getPosition() );
  1885. _projScreenMatrix.multiplyVector3( _vector3 );
  1886. _object = getNextObjectInPool();
  1887. _object.object = object;
  1888. _object.z = _vector3.z;
  1889. _renderData.sprites.push( _object );
  1890. } else if ( object instanceof THREE.Light ) {
  1891. _renderData.lights.push( object );
  1892. }
  1893. for ( var c = 0, cl = object.children.length; c < cl; c ++ ) {
  1894. projectObject( object.children[ c ] );
  1895. }
  1896. };
  1897. projectObject( root );
  1898. sort && _renderData.objects.sort( painterSort );
  1899. return _renderData;
  1900. };
  1901. this.projectScene = function ( scene, camera, sort ) {
  1902. var near = camera.near, far = camera.far, visible = false,
  1903. o, ol, v, vl, f, fl, n, nl, c, cl, u, ul, object,
  1904. objectMatrixWorld, objectMatrixWorldRotation,
  1905. geometry, geometryMaterials, vertices, vertex, vertexPositionScreen,
  1906. faces, face, faceVertexNormals, normal, faceVertexUvs, uvs,
  1907. v1, v2, v3, v4;
  1908. _face3Count = 0;
  1909. _face4Count = 0;
  1910. _lineCount = 0;
  1911. _particleCount = 0;
  1912. _renderData.elements.length = 0;
  1913. if ( camera.parent === undefined ) {
  1914. console.warn( 'DEPRECATED: Camera hasn\'t been added to a Scene. Adding it...' );
  1915. scene.add( camera );
  1916. }
  1917. scene.updateMatrixWorld();
  1918. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  1919. _projScreenMatrix.multiply( camera.projectionMatrix, camera.matrixWorldInverse );
  1920. _frustum.setFromMatrix( _projScreenMatrix );
  1921. _renderData = this.projectGraph( scene, false );
  1922. for ( o = 0, ol = _renderData.objects.length; o < ol; o++ ) {
  1923. object = _renderData.objects[ o ].object;
  1924. objectMatrixWorld = object.matrixWorld;
  1925. _vertexCount = 0;
  1926. if ( object instanceof THREE.Mesh ) {
  1927. geometry = object.geometry;
  1928. geometryMaterials = object.geometry.materials;
  1929. vertices = geometry.vertices;
  1930. faces = geometry.faces;
  1931. faceVertexUvs = geometry.faceVertexUvs;
  1932. objectMatrixWorldRotation = object.matrixRotationWorld.extractRotation( objectMatrixWorld );
  1933. for ( v = 0, vl = vertices.length; v < vl; v ++ ) {
  1934. _vertex = getNextVertexInPool();
  1935. _vertex.positionWorld.copy( vertices[ v ] );
  1936. objectMatrixWorld.multiplyVector3( _vertex.positionWorld );
  1937. _vertex.positionScreen.copy( _vertex.positionWorld );
  1938. _projScreenMatrix.multiplyVector4( _vertex.positionScreen );
  1939. _vertex.positionScreen.x /= _vertex.positionScreen.w;
  1940. _vertex.positionScreen.y /= _vertex.positionScreen.w;
  1941. _vertex.visible = _vertex.positionScreen.z > near && _vertex.positionScreen.z < far;
  1942. }
  1943. for ( f = 0, fl = faces.length; f < fl; f ++ ) {
  1944. face = faces[ f ];
  1945. if ( face instanceof THREE.Face3 ) {
  1946. v1 = _vertexPool[ face.a ];
  1947. v2 = _vertexPool[ face.b ];
  1948. v3 = _vertexPool[ face.c ];
  1949. if ( v1.visible && v2.visible && v3.visible ) {
  1950. visible = ( ( v3.positionScreen.x - v1.positionScreen.x ) * ( v2.positionScreen.y - v1.positionScreen.y ) -
  1951. ( v3.positionScreen.y - v1.positionScreen.y ) * ( v2.positionScreen.x - v1.positionScreen.x ) ) < 0;
  1952. if ( object.doubleSided || visible != object.flipSided ) {
  1953. _face = getNextFace3InPool();
  1954. _face.v1.copy( v1 );
  1955. _face.v2.copy( v2 );
  1956. _face.v3.copy( v3 );
  1957. } else {
  1958. continue;
  1959. }
  1960. } else {
  1961. continue;
  1962. }
  1963. } else if ( face instanceof THREE.Face4 ) {
  1964. v1 = _vertexPool[ face.a ];
  1965. v2 = _vertexPool[ face.b ];
  1966. v3 = _vertexPool[ face.c ];
  1967. v4 = _vertexPool[ face.d ];
  1968. if ( v1.visible && v2.visible && v3.visible && v4.visible ) {
  1969. visible = ( v4.positionScreen.x - v1.positionScreen.x ) * ( v2.positionScreen.y - v1.positionScreen.y ) -
  1970. ( v4.positionScreen.y - v1.positionScreen.y ) * ( v2.positionScreen.x - v1.positionScreen.x ) < 0 ||
  1971. ( v2.positionScreen.x - v3.positionScreen.x ) * ( v4.positionScreen.y - v3.positionScreen.y ) -
  1972. ( v2.positionScreen.y - v3.positionScreen.y ) * ( v4.positionScreen.x - v3.positionScreen.x ) < 0;
  1973. if ( object.doubleSided || visible != object.flipSided ) {
  1974. _face = getNextFace4InPool();
  1975. _face.v1.copy( v1 );
  1976. _face.v2.copy( v2 );
  1977. _face.v3.copy( v3 );
  1978. _face.v4.copy( v4 );
  1979. } else {
  1980. continue;
  1981. }
  1982. } else {
  1983. continue;
  1984. }
  1985. }
  1986. _face.normalWorld.copy( face.normal );
  1987. if ( !visible && ( object.flipSided || object.doubleSided ) ) _face.normalWorld.negate();
  1988. objectMatrixWorldRotation.multiplyVector3( _face.normalWorld );
  1989. _face.centroidWorld.copy( face.centroid );
  1990. objectMatrixWorld.multiplyVector3( _face.centroidWorld );
  1991. _face.centroidScreen.copy( _face.centroidWorld );
  1992. _projScreenMatrix.multiplyVector3( _face.centroidScreen );
  1993. faceVertexNormals = face.vertexNormals;
  1994. for ( n = 0, nl = faceVertexNormals.length; n < nl; n ++ ) {
  1995. normal = _face.vertexNormalsWorld[ n ];
  1996. normal.copy( faceVertexNormals[ n ] );
  1997. if ( !visible && ( object.flipSided || object.doubleSided ) ) normal.negate();
  1998. objectMatrixWorldRotation.multiplyVector3( normal );
  1999. }
  2000. for ( c = 0, cl = faceVertexUvs.length; c < cl; c ++ ) {
  2001. uvs = faceVertexUvs[ c ][ f ];
  2002. if ( !uvs ) continue;
  2003. for ( u = 0, ul = uvs.length; u < ul; u ++ ) {
  2004. _face.uvs[ c ][ u ] = uvs[ u ];
  2005. }
  2006. }
  2007. _face.material = object.material;
  2008. _face.faceMaterial = face.materialIndex !== null ? geometryMaterials[ face.materialIndex ] : null;
  2009. _face.z = _face.centroidScreen.z;
  2010. _renderData.elements.push( _face );
  2011. }
  2012. } else if ( object instanceof THREE.Line ) {
  2013. _projScreenobjectMatrixWorld.multiply( _projScreenMatrix, objectMatrixWorld );
  2014. vertices = object.geometry.vertices;
  2015. v1 = getNextVertexInPool();
  2016. v1.positionScreen.copy( vertices[ 0 ] );
  2017. _projScreenobjectMatrixWorld.multiplyVector4( v1.positionScreen );
  2018. // Handle LineStrip and LinePieces
  2019. var step = object.type === THREE.LinePieces ? 2 : 1;
  2020. for ( v = 1, vl = vertices.length; v < vl; v ++ ) {
  2021. v1 = getNextVertexInPool();
  2022. v1.positionScreen.copy( vertices[ v ] );
  2023. _projScreenobjectMatrixWorld.multiplyVector4( v1.positionScreen );
  2024. if ( ( v + 1 ) % step > 0 ) continue;
  2025. v2 = _vertexPool[ _vertexCount - 2 ];
  2026. _clippedVertex1PositionScreen.copy( v1.positionScreen );
  2027. _clippedVertex2PositionScreen.copy( v2.positionScreen );
  2028. if ( clipLine( _clippedVertex1PositionScreen, _clippedVertex2PositionScreen ) ) {
  2029. // Perform the perspective divide
  2030. _clippedVertex1PositionScreen.multiplyScalar( 1 / _clippedVertex1PositionScreen.w );
  2031. _clippedVertex2PositionScreen.multiplyScalar( 1 / _clippedVertex2PositionScreen.w );
  2032. _line = getNextLineInPool();
  2033. _line.v1.positionScreen.copy( _clippedVertex1PositionScreen );
  2034. _line.v2.positionScreen.copy( _clippedVertex2PositionScreen );
  2035. _line.z = Math.max( _clippedVertex1PositionScreen.z, _clippedVertex2PositionScreen.z );
  2036. _line.material = object.material;
  2037. _renderData.elements.push( _line );
  2038. }
  2039. }
  2040. }
  2041. }
  2042. for ( o = 0, ol = _renderData.sprites.length; o < ol; o++ ) {
  2043. object = _renderData.sprites[ o ].object;
  2044. objectMatrixWorld = object.matrixWorld;
  2045. if ( object instanceof THREE.Particle ) {
  2046. _vector4.set( objectMatrixWorld.elements[12], objectMatrixWorld.elements[13], objectMatrixWorld.elements[14], 1 );
  2047. _projScreenMatrix.multiplyVector4( _vector4 );
  2048. _vector4.z /= _vector4.w;
  2049. if ( _vector4.z > 0 && _vector4.z < 1 ) {
  2050. _particle = getNextParticleInPool();
  2051. _particle.x = _vector4.x / _vector4.w;
  2052. _particle.y = _vector4.y / _vector4.w;
  2053. _particle.z = _vector4.z;
  2054. _particle.rotation = object.rotation.z;
  2055. _particle.scale.x = object.scale.x * Math.abs( _particle.x - ( _vector4.x + camera.projectionMatrix.elements[0] ) / ( _vector4.w + camera.projectionMatrix.elements[12] ) );
  2056. _particle.scale.y = object.scale.y * Math.abs( _particle.y - ( _vector4.y + camera.projectionMatrix.elements[5] ) / ( _vector4.w + camera.projectionMatrix.elements[13] ) );
  2057. _particle.material = object.material;
  2058. _renderData.elements.push( _particle );
  2059. }
  2060. }
  2061. }
  2062. sort && _renderData.elements.sort( painterSort );
  2063. return _renderData;
  2064. };
  2065. // Pools
  2066. function getNextObjectInPool() {
  2067. var object = _objectPool[ _objectCount ] = _objectPool[ _objectCount ] || new THREE.RenderableObject();
  2068. _objectCount ++;
  2069. return object;
  2070. }
  2071. function getNextVertexInPool() {
  2072. var vertex = _vertexPool[ _vertexCount ] = _vertexPool[ _vertexCount ] || new THREE.RenderableVertex();
  2073. _vertexCount ++;
  2074. return vertex;
  2075. }
  2076. function getNextFace3InPool() {
  2077. var face = _face3Pool[ _face3Count ] = _face3Pool[ _face3Count ] || new THREE.RenderableFace3();
  2078. _face3Count ++;
  2079. return face;
  2080. }
  2081. function getNextFace4InPool() {
  2082. var face = _face4Pool[ _face4Count ] = _face4Pool[ _face4Count ] || new THREE.RenderableFace4();
  2083. _face4Count ++;
  2084. return face;
  2085. }
  2086. function getNextLineInPool() {
  2087. var line = _linePool[ _lineCount ] = _linePool[ _lineCount ] || new THREE.RenderableLine();
  2088. _lineCount ++;
  2089. return line;
  2090. }
  2091. function getNextParticleInPool() {
  2092. var particle = _particlePool[ _particleCount ] = _particlePool[ _particleCount ] || new THREE.RenderableParticle();
  2093. _particleCount ++;
  2094. return particle;
  2095. }
  2096. //
  2097. function painterSort( a, b ) {
  2098. return b.z - a.z;
  2099. }
  2100. function clipLine( s1, s2 ) {
  2101. var alpha1 = 0, alpha2 = 1,
  2102. // Calculate the boundary coordinate of each vertex for the near and far clip planes,
  2103. // Z = -1 and Z = +1, respectively.
  2104. bc1near = s1.z + s1.w,
  2105. bc2near = s2.z + s2.w,
  2106. bc1far = - s1.z + s1.w,
  2107. bc2far = - s2.z + s2.w;
  2108. if ( bc1near >= 0 && bc2near >= 0 && bc1far >= 0 && bc2far >= 0 ) {
  2109. // Both vertices lie entirely within all clip planes.
  2110. return true;
  2111. } else if ( ( bc1near < 0 && bc2near < 0) || (bc1far < 0 && bc2far < 0 ) ) {
  2112. // Both vertices lie entirely outside one of the clip planes.
  2113. return false;
  2114. } else {
  2115. // The line segment spans at least one clip plane.
  2116. if ( bc1near < 0 ) {
  2117. // v1 lies outside the near plane, v2 inside
  2118. alpha1 = Math.max( alpha1, bc1near / ( bc1near - bc2near ) );
  2119. } else if ( bc2near < 0 ) {
  2120. // v2 lies outside the near plane, v1 inside
  2121. alpha2 = Math.min( alpha2, bc1near / ( bc1near - bc2near ) );
  2122. }
  2123. if ( bc1far < 0 ) {
  2124. // v1 lies outside the far plane, v2 inside
  2125. alpha1 = Math.max( alpha1, bc1far / ( bc1far - bc2far ) );
  2126. } else if ( bc2far < 0 ) {
  2127. // v2 lies outside the far plane, v2 inside
  2128. alpha2 = Math.min( alpha2, bc1far / ( bc1far - bc2far ) );
  2129. }
  2130. if ( alpha2 < alpha1 ) {
  2131. // The line segment spans two boundaries, but is outside both of them.
  2132. // (This can't happen when we're only clipping against just near/far but good
  2133. // to leave the check here for future usage if other clip planes are added.)
  2134. return false;
  2135. } else {
  2136. // Update the s1 and s2 vertices to match the clipped line segment.
  2137. s1.lerpSelf( s2, alpha1 );
  2138. s2.lerpSelf( s1, 1 - alpha2 );
  2139. return true;
  2140. }
  2141. }
  2142. }
  2143. };
  2144. /**
  2145. * @author mikael emtinger / http://gomo.se/
  2146. * @author alteredq / http://alteredqualia.com/
  2147. */
  2148. THREE.Quaternion = function( x, y, z, w ) {
  2149. this.x = x || 0;
  2150. this.y = y || 0;
  2151. this.z = z || 0;
  2152. this.w = ( w !== undefined ) ? w : 1;
  2153. };
  2154. THREE.Quaternion.prototype = {
  2155. constructor: THREE.Quaternion,
  2156. set: function ( x, y, z, w ) {
  2157. this.x = x;
  2158. this.y = y;
  2159. this.z = z;
  2160. this.w = w;
  2161. return this;
  2162. },
  2163. copy: function ( q ) {
  2164. this.x = q.x;
  2165. this.y = q.y;
  2166. this.z = q.z;
  2167. this.w = q.w;
  2168. return this;
  2169. },
  2170. setFromEuler: function ( vector ) {
  2171. var c = Math.PI / 360, // 0.5 * Math.PI / 360, // 0.5 is an optimization
  2172. x = vector.x * c,
  2173. y = vector.y * c,
  2174. z = vector.z * c,
  2175. c1 = Math.cos( y ),
  2176. s1 = Math.sin( y ),
  2177. c2 = Math.cos( -z ),
  2178. s2 = Math.sin( -z ),
  2179. c3 = Math.cos( x ),
  2180. s3 = Math.sin( x ),
  2181. c1c2 = c1 * c2,
  2182. s1s2 = s1 * s2;
  2183. this.w = c1c2 * c3 - s1s2 * s3;
  2184. this.x = c1c2 * s3 + s1s2 * c3;
  2185. this.y = s1 * c2 * c3 + c1 * s2 * s3;
  2186. this.z = c1 * s2 * c3 - s1 * c2 * s3;
  2187. return this;
  2188. },
  2189. setFromAxisAngle: function ( axis, angle ) {
  2190. // from http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  2191. // axis have to be normalized
  2192. var halfAngle = angle / 2,
  2193. s = Math.sin( halfAngle );
  2194. this.x = axis.x * s;
  2195. this.y = axis.y * s;
  2196. this.z = axis.z * s;
  2197. this.w = Math.cos( halfAngle );
  2198. return this;
  2199. },
  2200. setFromRotationMatrix: function ( m ) {
  2201. // Adapted from: http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  2202. function copySign( a, b ) {
  2203. return b < 0 ? -Math.abs( a ) : Math.abs( a );
  2204. }
  2205. var absQ = Math.pow( m.determinant(), 1.0 / 3.0 );
  2206. this.w = Math.sqrt( Math.max( 0, absQ + m.elements[0] + m.elements[5] + m.elements[10] ) ) / 2;
  2207. this.x = Math.sqrt( Math.max( 0, absQ + m.elements[0] - m.elements[5] - m.elements[10] ) ) / 2;
  2208. this.y = Math.sqrt( Math.max( 0, absQ - m.elements[0] + m.elements[5] - m.elements[10] ) ) / 2;
  2209. this.z = Math.sqrt( Math.max( 0, absQ - m.elements[0] - m.elements[5] + m.elements[10] ) ) / 2;
  2210. this.x = copySign( this.x, ( m.elements[6] - m.elements[9] ) );
  2211. this.y = copySign( this.y, ( m.elements[8] - m.elements[2] ) );
  2212. this.z = copySign( this.z, ( m.elements[1] - m.elements[4] ) );
  2213. this.normalize();
  2214. return this;
  2215. },
  2216. calculateW : function () {
  2217. this.w = - Math.sqrt( Math.abs( 1.0 - this.x * this.x - this.y * this.y - this.z * this.z ) );
  2218. return this;
  2219. },
  2220. inverse: function () {
  2221. this.x *= -1;
  2222. this.y *= -1;
  2223. this.z *= -1;
  2224. return this;
  2225. },
  2226. length: function () {
  2227. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  2228. },
  2229. normalize: function () {
  2230. var l = Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  2231. if ( l === 0 ) {
  2232. this.x = 0;
  2233. this.y = 0;
  2234. this.z = 0;
  2235. this.w = 0;
  2236. } else {
  2237. l = 1 / l;
  2238. this.x = this.x * l;
  2239. this.y = this.y * l;
  2240. this.z = this.z * l;
  2241. this.w = this.w * l;
  2242. }
  2243. return this;
  2244. },
  2245. multiply: function ( a, b ) {
  2246. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2247. this.x = a.x * b.w + a.y * b.z - a.z * b.y + a.w * b.x;
  2248. this.y = -a.x * b.z + a.y * b.w + a.z * b.x + a.w * b.y;
  2249. this.z = a.x * b.y - a.y * b.x + a.z * b.w + a.w * b.z;
  2250. this.w = -a.x * b.x - a.y * b.y - a.z * b.z + a.w * b.w;
  2251. return this;
  2252. },
  2253. multiplySelf: function ( b ) {
  2254. var qax = this.x, qay = this.y, qaz = this.z, qaw = this.w,
  2255. qbx = b.x, qby = b.y, qbz = b.z, qbw = b.w;
  2256. this.x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2257. this.y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2258. this.z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2259. this.w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2260. return this;
  2261. },
  2262. multiplyVector3: function ( vector, dest ) {
  2263. if ( !dest ) { dest = vector; }
  2264. var x = vector.x, y = vector.y, z = vector.z,
  2265. qx = this.x, qy = this.y, qz = this.z, qw = this.w;
  2266. // calculate quat * vector
  2267. var ix = qw * x + qy * z - qz * y,
  2268. iy = qw * y + qz * x - qx * z,
  2269. iz = qw * z + qx * y - qy * x,
  2270. iw = -qx * x - qy * y - qz * z;
  2271. // calculate result * inverse quat
  2272. dest.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  2273. dest.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  2274. dest.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  2275. return dest;
  2276. },
  2277. clone: function () {
  2278. return new THREE.Quaternion( this.x, this.y, this.z, this.w );
  2279. }
  2280. }
  2281. THREE.Quaternion.slerp = function ( qa, qb, qm, t ) {
  2282. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2283. var cosHalfTheta = qa.w * qb.w + qa.x * qb.x + qa.y * qb.y + qa.z * qb.z;
  2284. if (cosHalfTheta < 0) {
  2285. qm.w = -qb.w; qm.x = -qb.x; qm.y = -qb.y; qm.z = -qb.z;
  2286. cosHalfTheta = -cosHalfTheta;
  2287. } else {
  2288. qm.copy(qb);
  2289. }
  2290. if ( Math.abs( cosHalfTheta ) >= 1.0 ) {
  2291. qm.w = qa.w; qm.x = qa.x; qm.y = qa.y; qm.z = qa.z;
  2292. return qm;
  2293. }
  2294. var halfTheta = Math.acos( cosHalfTheta ),
  2295. sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  2296. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  2297. qm.w = 0.5 * ( qa.w + qb.w );
  2298. qm.x = 0.5 * ( qa.x + qb.x );
  2299. qm.y = 0.5 * ( qa.y + qb.y );
  2300. qm.z = 0.5 * ( qa.z + qb.z );
  2301. return qm;
  2302. }
  2303. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  2304. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  2305. qm.w = ( qa.w * ratioA + qm.w * ratioB );
  2306. qm.x = ( qa.x * ratioA + qm.x * ratioB );
  2307. qm.y = ( qa.y * ratioA + qm.y * ratioB );
  2308. qm.z = ( qa.z * ratioA + qm.z * ratioB );
  2309. return qm;
  2310. }
  2311. /**
  2312. * @author mr.doob / http://mrdoob.com/
  2313. */
  2314. THREE.Vertex = function () {
  2315. console.warn( 'THREE.Vertex has been DEPRECATED. Use THREE.Vector3 instead.')
  2316. };
  2317. /**
  2318. * @author mr.doob / http://mrdoob.com/
  2319. * @author alteredq / http://alteredqualia.com/
  2320. */
  2321. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  2322. this.a = a;
  2323. this.b = b;
  2324. this.c = c;
  2325. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  2326. this.vertexNormals = normal instanceof Array ? normal : [ ];
  2327. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  2328. this.vertexColors = color instanceof Array ? color : [];
  2329. this.vertexTangents = [];
  2330. this.materialIndex = materialIndex;
  2331. this.centroid = new THREE.Vector3();
  2332. };
  2333. THREE.Face3.prototype = {
  2334. constructor: THREE.Face3,
  2335. clone: function () {
  2336. var face = new THREE.Face3( this.a, this.b, this.c );
  2337. face.normal.copy( this.normal );
  2338. face.color.copy( this.color );
  2339. face.centroid.copy( this.centroid );
  2340. face.materialIndex = this.materialIndex;
  2341. var i, il;
  2342. for ( i = 0, il = this.vertexNormals.length; i < il; i ++ ) face.vertexNormals[ i ] = this.vertexNormals[ i ].clone();
  2343. for ( i = 0, il = this.vertexColors.length; i < il; i ++ ) face.vertexColors[ i ] = this.vertexColors[ i ].clone();
  2344. for ( i = 0, il = this.vertexTangents.length; i < il; i ++ ) face.vertexTangents[ i ] = this.vertexTangents[ i ].clone();
  2345. return face;
  2346. }
  2347. };
  2348. /**
  2349. * @author mr.doob / http://mrdoob.com/
  2350. * @author alteredq / http://alteredqualia.com/
  2351. */
  2352. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  2353. this.a = a;
  2354. this.b = b;
  2355. this.c = c;
  2356. this.d = d;
  2357. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  2358. this.vertexNormals = normal instanceof Array ? normal : [ ];
  2359. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  2360. this.vertexColors = color instanceof Array ? color : [];
  2361. this.vertexTangents = [];
  2362. this.materialIndex = materialIndex;
  2363. this.centroid = new THREE.Vector3();
  2364. };
  2365. THREE.Face4.prototype = {
  2366. constructor: THREE.Face4,
  2367. clone: function () {
  2368. var face = new THREE.Face4( this.a, this.b, this.c, this.d );
  2369. face.normal.copy( this.normal );
  2370. face.color.copy( this.color );
  2371. face.centroid.copy( this.centroid );
  2372. face.materialIndex = this.materialIndex;
  2373. var i, il;
  2374. for ( i = 0, il = this.vertexNormals.length; i < il; i ++ ) face.vertexNormals[ i ] = this.vertexNormals[ i ].clone();
  2375. for ( i = 0, il = this.vertexColors.length; i < il; i ++ ) face.vertexColors[ i ] = this.vertexColors[ i ].clone();
  2376. for ( i = 0, il = this.vertexTangents.length; i < il; i ++ ) face.vertexTangents[ i ] = this.vertexTangents[ i ].clone();
  2377. return face;
  2378. }
  2379. };
  2380. /**
  2381. * @author mr.doob / http://mrdoob.com/
  2382. */
  2383. THREE.UV = function ( u, v ) {
  2384. this.u = u || 0;
  2385. this.v = v || 0;
  2386. };
  2387. THREE.UV.prototype = {
  2388. constructor: THREE.UV,
  2389. set: function ( u, v ) {
  2390. this.u = u;
  2391. this.v = v;
  2392. return this;
  2393. },
  2394. copy: function ( uv ) {
  2395. this.u = uv.u;
  2396. this.v = uv.v;
  2397. return this;
  2398. },
  2399. lerpSelf: function ( uv, alpha ) {
  2400. this.u += ( uv.u - this.u ) * alpha;
  2401. this.v += ( uv.v - this.v ) * alpha;
  2402. return this;
  2403. },
  2404. clone: function () {
  2405. return new THREE.UV( this.u, this.v );
  2406. }
  2407. };
  2408. /**
  2409. * @author mr.doob / http://mrdoob.com/
  2410. * @author kile / http://kile.stravaganza.org/
  2411. * @author alteredq / http://alteredqualia.com/
  2412. * @author mikael emtinger / http://gomo.se/
  2413. * @author zz85 / http://www.lab4games.net/zz85/blog
  2414. */
  2415. THREE.Geometry = function () {
  2416. this.id = THREE.GeometryCount ++;
  2417. this.vertices = [];
  2418. this.colors = []; // one-to-one vertex colors, used in ParticleSystem, Line and Ribbon
  2419. this.materials = [];
  2420. this.faces = [];
  2421. this.faceUvs = [[]];
  2422. this.faceVertexUvs = [[]];
  2423. this.morphTargets = [];
  2424. this.morphColors = [];
  2425. this.morphNormals = [];
  2426. this.skinWeights = [];
  2427. this.skinIndices = [];
  2428. this.boundingBox = null;
  2429. this.boundingSphere = null;
  2430. this.hasTangents = false;
  2431. this.dynamic = false; // unless set to true the *Arrays will be deleted once sent to a buffer.
  2432. };
  2433. THREE.Geometry.prototype = {
  2434. constructor : THREE.Geometry,
  2435. applyMatrix: function ( matrix ) {
  2436. var matrixRotation = new THREE.Matrix4();
  2437. matrixRotation.extractRotation( matrix );
  2438. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  2439. var vertex = this.vertices[ i ];
  2440. matrix.multiplyVector3( vertex );
  2441. }
  2442. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  2443. var face = this.faces[ i ];
  2444. matrixRotation.multiplyVector3( face.normal );
  2445. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  2446. matrixRotation.multiplyVector3( face.vertexNormals[ j ] );
  2447. }
  2448. matrix.multiplyVector3( face.centroid );
  2449. }
  2450. },
  2451. computeCentroids: function () {
  2452. var f, fl, face;
  2453. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2454. face = this.faces[ f ];
  2455. face.centroid.set( 0, 0, 0 );
  2456. if ( face instanceof THREE.Face3 ) {
  2457. face.centroid.addSelf( this.vertices[ face.a ] );
  2458. face.centroid.addSelf( this.vertices[ face.b ] );
  2459. face.centroid.addSelf( this.vertices[ face.c ] );
  2460. face.centroid.divideScalar( 3 );
  2461. } else if ( face instanceof THREE.Face4 ) {
  2462. face.centroid.addSelf( this.vertices[ face.a ] );
  2463. face.centroid.addSelf( this.vertices[ face.b ] );
  2464. face.centroid.addSelf( this.vertices[ face.c ] );
  2465. face.centroid.addSelf( this.vertices[ face.d ] );
  2466. face.centroid.divideScalar( 4 );
  2467. }
  2468. }
  2469. },
  2470. computeFaceNormals: function () {
  2471. var n, nl, v, vl, vertex, f, fl, face, vA, vB, vC,
  2472. cb = new THREE.Vector3(), ab = new THREE.Vector3();
  2473. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2474. face = this.faces[ f ];
  2475. vA = this.vertices[ face.a ];
  2476. vB = this.vertices[ face.b ];
  2477. vC = this.vertices[ face.c ];
  2478. cb.sub( vC, vB );
  2479. ab.sub( vA, vB );
  2480. cb.crossSelf( ab );
  2481. if ( !cb.isZero() ) {
  2482. cb.normalize();
  2483. }
  2484. face.normal.copy( cb );
  2485. }
  2486. },
  2487. computeVertexNormals: function () {
  2488. var v, vl, f, fl, face, vertices;
  2489. // create internal buffers for reuse when calling this method repeatedly
  2490. // (otherwise memory allocation / deallocation every frame is big resource hog)
  2491. if ( this.__tmpVertices === undefined ) {
  2492. this.__tmpVertices = new Array( this.vertices.length );
  2493. vertices = this.__tmpVertices;
  2494. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  2495. vertices[ v ] = new THREE.Vector3();
  2496. }
  2497. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2498. face = this.faces[ f ];
  2499. if ( face instanceof THREE.Face3 ) {
  2500. face.vertexNormals = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ];
  2501. } else if ( face instanceof THREE.Face4 ) {
  2502. face.vertexNormals = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ];
  2503. }
  2504. }
  2505. } else {
  2506. vertices = this.__tmpVertices;
  2507. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  2508. vertices[ v ].set( 0, 0, 0 );
  2509. }
  2510. }
  2511. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2512. face = this.faces[ f ];
  2513. if ( face instanceof THREE.Face3 ) {
  2514. vertices[ face.a ].addSelf( face.normal );
  2515. vertices[ face.b ].addSelf( face.normal );
  2516. vertices[ face.c ].addSelf( face.normal );
  2517. } else if ( face instanceof THREE.Face4 ) {
  2518. vertices[ face.a ].addSelf( face.normal );
  2519. vertices[ face.b ].addSelf( face.normal );
  2520. vertices[ face.c ].addSelf( face.normal );
  2521. vertices[ face.d ].addSelf( face.normal );
  2522. }
  2523. }
  2524. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  2525. vertices[ v ].normalize();
  2526. }
  2527. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2528. face = this.faces[ f ];
  2529. if ( face instanceof THREE.Face3 ) {
  2530. face.vertexNormals[ 0 ].copy( vertices[ face.a ] );
  2531. face.vertexNormals[ 1 ].copy( vertices[ face.b ] );
  2532. face.vertexNormals[ 2 ].copy( vertices[ face.c ] );
  2533. } else if ( face instanceof THREE.Face4 ) {
  2534. face.vertexNormals[ 0 ].copy( vertices[ face.a ] );
  2535. face.vertexNormals[ 1 ].copy( vertices[ face.b ] );
  2536. face.vertexNormals[ 2 ].copy( vertices[ face.c ] );
  2537. face.vertexNormals[ 3 ].copy( vertices[ face.d ] );
  2538. }
  2539. }
  2540. },
  2541. computeMorphNormals: function () {
  2542. var i, il, f, fl, face;
  2543. // save original normals
  2544. // - create temp variables on first access
  2545. // otherwise just copy (for faster repeated calls)
  2546. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2547. face = this.faces[ f ];
  2548. if ( ! face.__originalFaceNormal ) {
  2549. face.__originalFaceNormal = face.normal.clone();
  2550. } else {
  2551. face.__originalFaceNormal.copy( face.normal );
  2552. }
  2553. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  2554. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  2555. if ( ! face.__originalVertexNormals[ i ] ) {
  2556. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  2557. } else {
  2558. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  2559. }
  2560. }
  2561. }
  2562. // use temp geometry to compute face and vertex normals for each morph
  2563. var tmpGeo = new THREE.Geometry();
  2564. tmpGeo.faces = this.faces;
  2565. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  2566. // create on first access
  2567. if ( ! this.morphNormals[ i ] ) {
  2568. this.morphNormals[ i ] = {};
  2569. this.morphNormals[ i ].faceNormals = [];
  2570. this.morphNormals[ i ].vertexNormals = [];
  2571. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  2572. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  2573. var faceNormal, vertexNormals;
  2574. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2575. face = this.faces[ f ];
  2576. faceNormal = new THREE.Vector3();
  2577. if ( face instanceof THREE.Face3 ) {
  2578. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  2579. } else {
  2580. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3(), d: new THREE.Vector3() };
  2581. }
  2582. dstNormalsFace.push( faceNormal );
  2583. dstNormalsVertex.push( vertexNormals );
  2584. }
  2585. }
  2586. var morphNormals = this.morphNormals[ i ];
  2587. // set vertices to morph target
  2588. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  2589. // compute morph normals
  2590. tmpGeo.computeFaceNormals();
  2591. tmpGeo.computeVertexNormals();
  2592. // store morph normals
  2593. var faceNormal, vertexNormals;
  2594. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2595. face = this.faces[ f ];
  2596. faceNormal = morphNormals.faceNormals[ f ];
  2597. vertexNormals = morphNormals.vertexNormals[ f ];
  2598. faceNormal.copy( face.normal );
  2599. if ( face instanceof THREE.Face3 ) {
  2600. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  2601. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  2602. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  2603. } else {
  2604. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  2605. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  2606. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  2607. vertexNormals.d.copy( face.vertexNormals[ 3 ] );
  2608. }
  2609. }
  2610. }
  2611. // restore original normals
  2612. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2613. face = this.faces[ f ];
  2614. face.normal = face.__originalFaceNormal;
  2615. face.vertexNormals = face.__originalVertexNormals;
  2616. }
  2617. },
  2618. computeTangents: function () {
  2619. // based on http://www.terathon.com/code/tangent.html
  2620. // tangents go to vertices
  2621. var f, fl, v, vl, i, il, vertexIndex,
  2622. face, uv, vA, vB, vC, uvA, uvB, uvC,
  2623. x1, x2, y1, y2, z1, z2,
  2624. s1, s2, t1, t2, r, t, test,
  2625. tan1 = [], tan2 = [],
  2626. sdir = new THREE.Vector3(), tdir = new THREE.Vector3(),
  2627. tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3(),
  2628. n = new THREE.Vector3(), w;
  2629. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  2630. tan1[ v ] = new THREE.Vector3();
  2631. tan2[ v ] = new THREE.Vector3();
  2632. }
  2633. function handleTriangle( context, a, b, c, ua, ub, uc ) {
  2634. vA = context.vertices[ a ];
  2635. vB = context.vertices[ b ];
  2636. vC = context.vertices[ c ];
  2637. uvA = uv[ ua ];
  2638. uvB = uv[ ub ];
  2639. uvC = uv[ uc ];
  2640. x1 = vB.x - vA.x;
  2641. x2 = vC.x - vA.x;
  2642. y1 = vB.y - vA.y;
  2643. y2 = vC.y - vA.y;
  2644. z1 = vB.z - vA.z;
  2645. z2 = vC.z - vA.z;
  2646. s1 = uvB.u - uvA.u;
  2647. s2 = uvC.u - uvA.u;
  2648. t1 = uvB.v - uvA.v;
  2649. t2 = uvC.v - uvA.v;
  2650. r = 1.0 / ( s1 * t2 - s2 * t1 );
  2651. sdir.set( ( t2 * x1 - t1 * x2 ) * r,
  2652. ( t2 * y1 - t1 * y2 ) * r,
  2653. ( t2 * z1 - t1 * z2 ) * r );
  2654. tdir.set( ( s1 * x2 - s2 * x1 ) * r,
  2655. ( s1 * y2 - s2 * y1 ) * r,
  2656. ( s1 * z2 - s2 * z1 ) * r );
  2657. tan1[ a ].addSelf( sdir );
  2658. tan1[ b ].addSelf( sdir );
  2659. tan1[ c ].addSelf( sdir );
  2660. tan2[ a ].addSelf( tdir );
  2661. tan2[ b ].addSelf( tdir );
  2662. tan2[ c ].addSelf( tdir );
  2663. }
  2664. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2665. face = this.faces[ f ];
  2666. uv = this.faceVertexUvs[ 0 ][ f ]; // use UV layer 0 for tangents
  2667. if ( face instanceof THREE.Face3 ) {
  2668. handleTriangle( this, face.a, face.b, face.c, 0, 1, 2 );
  2669. } else if ( face instanceof THREE.Face4 ) {
  2670. handleTriangle( this, face.a, face.b, face.d, 0, 1, 3 );
  2671. handleTriangle( this, face.b, face.c, face.d, 1, 2, 3 );
  2672. }
  2673. }
  2674. var faceIndex = [ 'a', 'b', 'c', 'd' ];
  2675. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  2676. face = this.faces[ f ];
  2677. for ( i = 0; i < face.vertexNormals.length; i++ ) {
  2678. n.copy( face.vertexNormals[ i ] );
  2679. vertexIndex = face[ faceIndex[ i ] ];
  2680. t = tan1[ vertexIndex ];
  2681. // Gram-Schmidt orthogonalize
  2682. tmp.copy( t );
  2683. tmp.subSelf( n.multiplyScalar( n.dot( t ) ) ).normalize();
  2684. // Calculate handedness
  2685. tmp2.cross( face.vertexNormals[ i ], t );
  2686. test = tmp2.dot( tan2[ vertexIndex ] );
  2687. w = (test < 0.0) ? -1.0 : 1.0;
  2688. face.vertexTangents[ i ] = new THREE.Vector4( tmp.x, tmp.y, tmp.z, w );
  2689. }
  2690. }
  2691. this.hasTangents = true;
  2692. },
  2693. computeBoundingBox: function () {
  2694. if ( ! this.boundingBox ) {
  2695. this.boundingBox = { min: new THREE.Vector3(), max: new THREE.Vector3() };
  2696. }
  2697. if ( this.vertices.length > 0 ) {
  2698. var position, firstPosition = this.vertices[ 0 ];
  2699. this.boundingBox.min.copy( firstPosition );
  2700. this.boundingBox.max.copy( firstPosition );
  2701. var min = this.boundingBox.min,
  2702. max = this.boundingBox.max;
  2703. for ( var v = 1, vl = this.vertices.length; v < vl; v ++ ) {
  2704. position = this.vertices[ v ];
  2705. if ( position.x < min.x ) {
  2706. min.x = position.x;
  2707. } else if ( position.x > max.x ) {
  2708. max.x = position.x;
  2709. }
  2710. if ( position.y < min.y ) {
  2711. min.y = position.y;
  2712. } else if ( position.y > max.y ) {
  2713. max.y = position.y;
  2714. }
  2715. if ( position.z < min.z ) {
  2716. min.z = position.z;
  2717. } else if ( position.z > max.z ) {
  2718. max.z = position.z;
  2719. }
  2720. }
  2721. } else {
  2722. this.boundingBox.min.set( 0, 0, 0 );
  2723. this.boundingBox.max.set( 0, 0, 0 );
  2724. }
  2725. },
  2726. computeBoundingSphere: function () {
  2727. if ( ! this.boundingSphere ) this.boundingSphere = { radius: 0 };
  2728. var radius, maxRadius = 0;
  2729. for ( var v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  2730. radius = this.vertices[ v ].length();
  2731. if ( radius > maxRadius ) maxRadius = radius;
  2732. }
  2733. this.boundingSphere.radius = maxRadius;
  2734. },
  2735. /*
  2736. * Checks for duplicate vertices with hashmap.
  2737. * Duplicated vertices are removed
  2738. * and faces' vertices are updated.
  2739. */
  2740. mergeVertices: function() {
  2741. var verticesMap = {}; // Hashmap for looking up vertice by position coordinates (and making sure they are unique)
  2742. var unique = [], changes = [];
  2743. var v, key;
  2744. var precisionPoints = 4; // number of decimal points, eg. 4 for epsilon of 0.0001
  2745. var precision = Math.pow( 10, precisionPoints );
  2746. var i,il, face;
  2747. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  2748. v = this.vertices[ i ];
  2749. key = [ Math.round( v.x * precision ), Math.round( v.y * precision ), Math.round( v.z * precision ) ].join( '_' );
  2750. if ( verticesMap[ key ] === undefined ) {
  2751. verticesMap[ key ] = i;
  2752. unique.push( this.vertices[ i ] );
  2753. changes[ i ] = unique.length - 1;
  2754. } else {
  2755. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  2756. changes[ i ] = changes[ verticesMap[ key ] ];
  2757. }
  2758. };
  2759. // Start to patch face indices
  2760. for( i = 0, il = this.faces.length; i < il; i ++ ) {
  2761. face = this.faces[ i ];
  2762. if ( face instanceof THREE.Face3 ) {
  2763. face.a = changes[ face.a ];
  2764. face.b = changes[ face.b ];
  2765. face.c = changes[ face.c ];
  2766. } else if ( face instanceof THREE.Face4 ) {
  2767. face.a = changes[ face.a ];
  2768. face.b = changes[ face.b ];
  2769. face.c = changes[ face.c ];
  2770. face.d = changes[ face.d ];
  2771. }
  2772. }
  2773. // Use unique set of vertices
  2774. this.vertices = unique;
  2775. }
  2776. };
  2777. THREE.GeometryCount = 0;
  2778. /**
  2779. * Spline from Tween.js, slightly optimized (and trashed)
  2780. * http://sole.github.com/tween.js/examples/05_spline.html
  2781. *
  2782. * @author mrdoob / http://mrdoob.com/
  2783. * @author alteredq / http://alteredqualia.com/
  2784. */
  2785. THREE.Spline = function ( points ) {
  2786. this.points = points;
  2787. var c = [], v3 = { x: 0, y: 0, z: 0 },
  2788. point, intPoint, weight, w2, w3,
  2789. pa, pb, pc, pd;
  2790. this.initFromArray = function( a ) {
  2791. this.points = [];
  2792. for ( var i = 0; i < a.length; i++ ) {
  2793. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  2794. }
  2795. };
  2796. this.getPoint = function ( k ) {
  2797. point = ( this.points.length - 1 ) * k;
  2798. intPoint = Math.floor( point );
  2799. weight = point - intPoint;
  2800. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  2801. c[ 1 ] = intPoint;
  2802. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  2803. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  2804. pa = this.points[ c[ 0 ] ];
  2805. pb = this.points[ c[ 1 ] ];
  2806. pc = this.points[ c[ 2 ] ];
  2807. pd = this.points[ c[ 3 ] ];
  2808. w2 = weight * weight;
  2809. w3 = weight * w2;
  2810. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  2811. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  2812. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  2813. return v3;
  2814. };
  2815. this.getControlPointsArray = function () {
  2816. var i, p, l = this.points.length,
  2817. coords = [];
  2818. for ( i = 0; i < l; i ++ ) {
  2819. p = this.points[ i ];
  2820. coords[ i ] = [ p.x, p.y, p.z ];
  2821. }
  2822. return coords;
  2823. };
  2824. // approximate length by summing linear segments
  2825. this.getLength = function ( nSubDivisions ) {
  2826. var i, index, nSamples, position,
  2827. point = 0, intPoint = 0, oldIntPoint = 0,
  2828. oldPosition = new THREE.Vector3(),
  2829. tmpVec = new THREE.Vector3(),
  2830. chunkLengths = [],
  2831. totalLength = 0;
  2832. // first point has 0 length
  2833. chunkLengths[ 0 ] = 0;
  2834. if ( !nSubDivisions ) nSubDivisions = 100;
  2835. nSamples = this.points.length * nSubDivisions;
  2836. oldPosition.copy( this.points[ 0 ] );
  2837. for ( i = 1; i < nSamples; i ++ ) {
  2838. index = i / nSamples;
  2839. position = this.getPoint( index );
  2840. tmpVec.copy( position );
  2841. totalLength += tmpVec.distanceTo( oldPosition );
  2842. oldPosition.copy( position );
  2843. point = ( this.points.length - 1 ) * index;
  2844. intPoint = Math.floor( point );
  2845. if ( intPoint != oldIntPoint ) {
  2846. chunkLengths[ intPoint ] = totalLength;
  2847. oldIntPoint = intPoint;
  2848. }
  2849. }
  2850. // last point ends with total length
  2851. chunkLengths[ chunkLengths.length ] = totalLength;
  2852. return { chunks: chunkLengths, total: totalLength };
  2853. };
  2854. this.reparametrizeByArcLength = function ( samplingCoef ) {
  2855. var i, j,
  2856. index, indexCurrent, indexNext,
  2857. linearDistance, realDistance,
  2858. sampling, position,
  2859. newpoints = [],
  2860. tmpVec = new THREE.Vector3(),
  2861. sl = this.getLength();
  2862. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  2863. for ( i = 1; i < this.points.length; i++ ) {
  2864. //tmpVec.copy( this.points[ i - 1 ] );
  2865. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  2866. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  2867. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  2868. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  2869. indexNext = i / ( this.points.length - 1 );
  2870. for ( j = 1; j < sampling - 1; j++ ) {
  2871. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  2872. position = this.getPoint( index );
  2873. newpoints.push( tmpVec.copy( position ).clone() );
  2874. }
  2875. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  2876. }
  2877. this.points = newpoints;
  2878. };
  2879. // Catmull-Rom
  2880. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  2881. var v0 = ( p2 - p0 ) * 0.5,
  2882. v1 = ( p3 - p1 ) * 0.5;
  2883. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  2884. };
  2885. };
  2886. /**
  2887. * @author mr.doob / http://mrdoob.com/
  2888. * @author mikael emtinger / http://gomo.se/
  2889. */
  2890. THREE.Camera = function () {
  2891. THREE.Object3D.call( this );
  2892. this.matrixWorldInverse = new THREE.Matrix4();
  2893. this.projectionMatrix = new THREE.Matrix4();
  2894. this.projectionMatrixInverse = new THREE.Matrix4();
  2895. };
  2896. THREE.Camera.prototype = new THREE.Object3D();
  2897. THREE.Camera.prototype.constructor = THREE.Camera;
  2898. THREE.Camera.prototype.lookAt = function ( vector ) {
  2899. // TODO: Add hierarchy support.
  2900. this.matrix.lookAt( this.position, vector, this.up );
  2901. if ( this.rotationAutoUpdate ) {
  2902. this.rotation.getRotationFromMatrix( this.matrix );
  2903. }
  2904. };
  2905. /**
  2906. * @author alteredq / http://alteredqualia.com/
  2907. */
  2908. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  2909. THREE.Camera.call( this );
  2910. this.left = left;
  2911. this.right = right;
  2912. this.top = top;
  2913. this.bottom = bottom;
  2914. this.near = ( near !== undefined ) ? near : 0.1;
  2915. this.far = ( far !== undefined ) ? far : 2000;
  2916. this.updateProjectionMatrix();
  2917. };
  2918. THREE.OrthographicCamera.prototype = new THREE.Camera();
  2919. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  2920. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  2921. this.projectionMatrix.makeOrthographic( this.left, this.right, this.top, this.bottom, this.near, this.far );
  2922. };
  2923. /**
  2924. * @author mr.doob / http://mrdoob.com/
  2925. * @author greggman / http://games.greggman.com/
  2926. * @author zz85 / http://www.lab4games.net/zz85/blog
  2927. */
  2928. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  2929. THREE.Camera.call( this );
  2930. this.fov = fov !== undefined ? fov : 50;
  2931. this.aspect = aspect !== undefined ? aspect : 1;
  2932. this.near = near !== undefined ? near : 0.1;
  2933. this.far = far !== undefined ? far : 2000;
  2934. this.updateProjectionMatrix();
  2935. };
  2936. THREE.PerspectiveCamera.prototype = new THREE.Camera();
  2937. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  2938. /**
  2939. * Uses Focal Length (in mm) to estimate and set FOV
  2940. * 35mm (fullframe) camera is used if frame size is not specified;
  2941. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  2942. */
  2943. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  2944. frameHeight = frameHeight !== undefined ? frameHeight : 24;
  2945. this.fov = 2 * Math.atan( frameHeight / ( focalLength * 2 ) ) * ( 180 / Math.PI );
  2946. this.updateProjectionMatrix();
  2947. }
  2948. /**
  2949. * Sets an offset in a larger frustum. This is useful for multi-window or
  2950. * multi-monitor/multi-machine setups.
  2951. *
  2952. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  2953. * the monitors are in grid like this
  2954. *
  2955. * +---+---+---+
  2956. * | A | B | C |
  2957. * +---+---+---+
  2958. * | D | E | F |
  2959. * +---+---+---+
  2960. *
  2961. * then for each monitor you would call it like this
  2962. *
  2963. * var w = 1920;
  2964. * var h = 1080;
  2965. * var fullWidth = w * 3;
  2966. * var fullHeight = h * 2;
  2967. *
  2968. * --A--
  2969. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  2970. * --B--
  2971. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  2972. * --C--
  2973. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  2974. * --D--
  2975. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  2976. * --E--
  2977. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  2978. * --F--
  2979. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  2980. *
  2981. * Note there is no reason monitors have to be the same size or in a grid.
  2982. */
  2983. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  2984. this.fullWidth = fullWidth;
  2985. this.fullHeight = fullHeight;
  2986. this.x = x;
  2987. this.y = y;
  2988. this.width = width;
  2989. this.height = height;
  2990. this.updateProjectionMatrix();
  2991. };
  2992. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  2993. if ( this.fullWidth ) {
  2994. var aspect = this.fullWidth / this.fullHeight;
  2995. var top = Math.tan( this.fov * Math.PI / 360 ) * this.near;
  2996. var bottom = -top;
  2997. var left = aspect * bottom;
  2998. var right = aspect * top;
  2999. var width = Math.abs( right - left );
  3000. var height = Math.abs( top - bottom );
  3001. this.projectionMatrix.makeFrustum(
  3002. left + this.x * width / this.fullWidth,
  3003. left + ( this.x + this.width ) * width / this.fullWidth,
  3004. top - ( this.y + this.height ) * height / this.fullHeight,
  3005. top - this.y * height / this.fullHeight,
  3006. this.near,
  3007. this.far
  3008. );
  3009. } else {
  3010. this.projectionMatrix.makePerspective( this.fov, this.aspect, this.near, this.far );
  3011. }
  3012. };
  3013. /**
  3014. * @author mr.doob / http://mrdoob.com/
  3015. * @author alteredq / http://alteredqualia.com/
  3016. */
  3017. THREE.Light = function ( hex ) {
  3018. THREE.Object3D.call( this );
  3019. this.color = new THREE.Color( hex );
  3020. };
  3021. THREE.Light.prototype = new THREE.Object3D();
  3022. THREE.Light.prototype.constructor = THREE.Light;
  3023. THREE.Light.prototype.supr = THREE.Object3D.prototype;
  3024. /**
  3025. * @author mr.doob / http://mrdoob.com/
  3026. */
  3027. THREE.AmbientLight = function ( hex ) {
  3028. THREE.Light.call( this, hex );
  3029. };
  3030. THREE.AmbientLight.prototype = new THREE.Light();
  3031. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  3032. /**
  3033. * @author mr.doob / http://mrdoob.com/
  3034. * @author alteredq / http://alteredqualia.com/
  3035. */
  3036. THREE.DirectionalLight = function ( hex, intensity, distance ) {
  3037. THREE.Light.call( this, hex );
  3038. this.position = new THREE.Vector3( 0, 1, 0 );
  3039. this.target = new THREE.Object3D();
  3040. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  3041. this.distance = ( distance !== undefined ) ? distance : 0;
  3042. this.castShadow = false;
  3043. this.onlyShadow = false;
  3044. //
  3045. this.shadowCameraNear = 50;
  3046. this.shadowCameraFar = 5000;
  3047. this.shadowCameraLeft = -500;
  3048. this.shadowCameraRight = 500;
  3049. this.shadowCameraTop = 500;
  3050. this.shadowCameraBottom = -500;
  3051. this.shadowCameraVisible = false;
  3052. this.shadowBias = 0;
  3053. this.shadowDarkness = 0.5;
  3054. this.shadowMapWidth = 512;
  3055. this.shadowMapHeight = 512;
  3056. //
  3057. this.shadowCascade = false;
  3058. this.shadowCascadeOffset = new THREE.Vector3( 0, 0, -1000 );
  3059. this.shadowCascadeCount = 2;
  3060. this.shadowCascadeBias = [ 0, 0, 0 ];
  3061. this.shadowCascadeWidth = [ 512, 512, 512 ];
  3062. this.shadowCascadeHeight = [ 512, 512, 512 ];
  3063. this.shadowCascadeNearZ = [ -1.000, 0.990, 0.998 ];
  3064. this.shadowCascadeFarZ = [ 0.990, 0.998, 1.000 ];
  3065. this.shadowCascadeArray = [];
  3066. //
  3067. this.shadowMap = null;
  3068. this.shadowMapSize = null;
  3069. this.shadowCamera = null;
  3070. this.shadowMatrix = null;
  3071. };
  3072. THREE.DirectionalLight.prototype = new THREE.Light();
  3073. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  3074. /**
  3075. * @author mr.doob / http://mrdoob.com/
  3076. */
  3077. THREE.PointLight = function ( hex, intensity, distance ) {
  3078. THREE.Light.call( this, hex );
  3079. this.position = new THREE.Vector3( 0, 0, 0 );
  3080. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  3081. this.distance = ( distance !== undefined ) ? distance : 0;
  3082. };
  3083. THREE.PointLight.prototype = new THREE.Light();
  3084. THREE.PointLight.prototype.constructor = THREE.PointLight;
  3085. /**
  3086. * @author alteredq / http://alteredqualia.com/
  3087. */
  3088. THREE.SpotLight = function ( hex, intensity, distance, angle, exponent ) {
  3089. THREE.Light.call( this, hex );
  3090. this.position = new THREE.Vector3( 0, 1, 0 );
  3091. this.target = new THREE.Object3D();
  3092. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  3093. this.distance = ( distance !== undefined ) ? distance : 0;
  3094. this.angle = ( angle !== undefined ) ? angle : Math.PI / 2;
  3095. this.exponent = ( exponent !== undefined ) ? exponent : 10;
  3096. this.castShadow = false;
  3097. this.onlyShadow = false;
  3098. //
  3099. this.shadowCameraNear = 50;
  3100. this.shadowCameraFar = 5000;
  3101. this.shadowCameraFov = 50;
  3102. this.shadowCameraVisible = false;
  3103. this.shadowBias = 0;
  3104. this.shadowDarkness = 0.5;
  3105. this.shadowMapWidth = 512;
  3106. this.shadowMapHeight = 512;
  3107. //
  3108. this.shadowMap = null;
  3109. this.shadowMapSize = null;
  3110. this.shadowCamera = null;
  3111. this.shadowMatrix = null;
  3112. };
  3113. THREE.SpotLight.prototype = new THREE.Light();
  3114. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  3115. /**
  3116. * @author mr.doob / http://mrdoob.com/
  3117. * @author alteredq / http://alteredqualia.com/
  3118. */
  3119. THREE.Material = function ( parameters ) {
  3120. parameters = parameters || {};
  3121. this.id = THREE.MaterialCount ++;
  3122. this.name = '';
  3123. this.opacity = parameters.opacity !== undefined ? parameters.opacity : 1;
  3124. this.transparent = parameters.transparent !== undefined ? parameters.transparent : false;
  3125. this.blending = parameters.blending !== undefined ? parameters.blending : THREE.NormalBlending;
  3126. this.blendSrc = parameters.blendSrc !== undefined ? parameters.blendSrc : THREE.SrcAlphaFactor;
  3127. this.blendDst = parameters.blendDst !== undefined ? parameters.blendDst : THREE.OneMinusSrcAlphaFactor;
  3128. this.blendEquation = parameters.blendEquation !== undefined ? parameters.blendEquation : THREE.AddEquation;
  3129. this.depthTest = parameters.depthTest !== undefined ? parameters.depthTest : true;
  3130. this.depthWrite = parameters.depthWrite !== undefined ? parameters.depthWrite : true;
  3131. this.polygonOffset = parameters.polygonOffset !== undefined ? parameters.polygonOffset : false;
  3132. this.polygonOffsetFactor = parameters.polygonOffsetFactor !== undefined ? parameters.polygonOffsetFactor : 0;
  3133. this.polygonOffsetUnits = parameters.polygonOffsetUnits !== undefined ? parameters.polygonOffsetUnits : 0;
  3134. this.alphaTest = parameters.alphaTest !== undefined ? parameters.alphaTest : 0;
  3135. this.overdraw = parameters.overdraw !== undefined ? parameters.overdraw : false; // Boolean for fixing antialiasing gaps in CanvasRenderer
  3136. this.needsUpdate = true;
  3137. }
  3138. THREE.MaterialCount = 0;
  3139. // shading
  3140. THREE.NoShading = 0;
  3141. THREE.FlatShading = 1;
  3142. THREE.SmoothShading = 2;
  3143. // colors
  3144. THREE.NoColors = 0;
  3145. THREE.FaceColors = 1;
  3146. THREE.VertexColors = 2;
  3147. // blending modes
  3148. THREE.NoBlending = 0;
  3149. THREE.NormalBlending = 1;
  3150. THREE.AdditiveBlending = 2;
  3151. THREE.SubtractiveBlending = 3;
  3152. THREE.MultiplyBlending = 4;
  3153. THREE.AdditiveAlphaBlending = 5;
  3154. THREE.CustomBlending = 6;
  3155. // custom blending equations
  3156. // (numbers start from 100 not to clash with other
  3157. // mappings to OpenGL constants defined in Texture.js)
  3158. THREE.AddEquation = 100;
  3159. THREE.SubtractEquation = 101;
  3160. THREE.ReverseSubtractEquation = 102;
  3161. // custom blending destination factors
  3162. THREE.ZeroFactor = 200;
  3163. THREE.OneFactor = 201;
  3164. THREE.SrcColorFactor = 202;
  3165. THREE.OneMinusSrcColorFactor = 203;
  3166. THREE.SrcAlphaFactor = 204;
  3167. THREE.OneMinusSrcAlphaFactor = 205;
  3168. THREE.DstAlphaFactor = 206;
  3169. THREE.OneMinusDstAlphaFactor = 207;
  3170. // custom blending source factors
  3171. //THREE.ZeroFactor = 200;
  3172. //THREE.OneFactor = 201;
  3173. //THREE.SrcAlphaFactor = 204;
  3174. //THREE.OneMinusSrcAlphaFactor = 205;
  3175. //THREE.DstAlphaFactor = 206;
  3176. //THREE.OneMinusDstAlphaFactor = 207;
  3177. THREE.DstColorFactor = 208;
  3178. THREE.OneMinusDstColorFactor = 209;
  3179. THREE.SrcAlphaSaturateFactor = 210;
  3180. /**
  3181. * @author mr.doob / http://mrdoob.com/
  3182. * @author alteredq / http://alteredqualia.com/
  3183. *
  3184. * parameters = {
  3185. * color: <hex>,
  3186. * opacity: <float>,
  3187. *
  3188. * blending: THREE.NormalBlending,
  3189. * depthTest: <bool>,
  3190. *
  3191. * linewidth: <float>,
  3192. * linecap: "round",
  3193. * linejoin: "round",
  3194. *
  3195. * vertexColors: <bool>
  3196. *
  3197. * fog: <bool>
  3198. * }
  3199. */
  3200. THREE.LineBasicMaterial = function ( parameters ) {
  3201. THREE.Material.call( this, parameters );
  3202. parameters = parameters || {};
  3203. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3204. this.linewidth = parameters.linewidth !== undefined ? parameters.linewidth : 1;
  3205. this.linecap = parameters.linecap !== undefined ? parameters.linecap : 'round';
  3206. this.linejoin = parameters.linejoin !== undefined ? parameters.linejoin : 'round';
  3207. this.vertexColors = parameters.vertexColors ? parameters.vertexColors : false;
  3208. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  3209. };
  3210. THREE.LineBasicMaterial.prototype = new THREE.Material();
  3211. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  3212. /**
  3213. * @author mr.doob / http://mrdoob.com/
  3214. * @author alteredq / http://alteredqualia.com/
  3215. *
  3216. * parameters = {
  3217. * color: <hex>,
  3218. * opacity: <float>,
  3219. * map: new THREE.Texture( <Image> ),
  3220. *
  3221. * lightMap: new THREE.Texture( <Image> ),
  3222. *
  3223. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  3224. * combine: THREE.Multiply,
  3225. * reflectivity: <float>,
  3226. * refractionRatio: <float>,
  3227. *
  3228. * shading: THREE.SmoothShading,
  3229. * blending: THREE.NormalBlending,
  3230. * depthTest: <bool>,
  3231. *
  3232. * wireframe: <boolean>,
  3233. * wireframeLinewidth: <float>,
  3234. *
  3235. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  3236. *
  3237. * skinning: <bool>,
  3238. * morphTargets: <bool>,
  3239. *
  3240. * fog: <bool>
  3241. * }
  3242. */
  3243. THREE.MeshBasicMaterial = function ( parameters ) {
  3244. THREE.Material.call( this, parameters );
  3245. parameters = parameters || {};
  3246. // color property represents emissive for MeshBasicMaterial
  3247. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3248. this.map = parameters.map !== undefined ? parameters.map : null;
  3249. this.lightMap = parameters.lightMap !== undefined ? parameters.lightMap : null;
  3250. this.envMap = parameters.envMap !== undefined ? parameters.envMap : null;
  3251. this.combine = parameters.combine !== undefined ? parameters.combine : THREE.MultiplyOperation;
  3252. this.reflectivity = parameters.reflectivity !== undefined ? parameters.reflectivity : 1;
  3253. this.refractionRatio = parameters.refractionRatio !== undefined ? parameters.refractionRatio : 0.98;
  3254. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  3255. this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading;
  3256. this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false;
  3257. this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1;
  3258. this.wireframeLinecap = parameters.wireframeLinecap !== undefined ? parameters.wireframeLinecap : 'round';
  3259. this.wireframeLinejoin = parameters.wireframeLinejoin !== undefined ? parameters.wireframeLinejoin : 'round';
  3260. this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : THREE.NoColors;
  3261. this.skinning = parameters.skinning !== undefined ? parameters.skinning : false;
  3262. this.morphTargets = parameters.morphTargets !== undefined ? parameters.morphTargets : false;
  3263. };
  3264. THREE.MeshBasicMaterial.prototype = new THREE.Material();
  3265. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  3266. /**
  3267. * @author mr.doob / http://mrdoob.com/
  3268. * @author alteredq / http://alteredqualia.com/
  3269. *
  3270. * parameters = {
  3271. * color: <hex>,
  3272. * ambient: <hex>,
  3273. * emissive: <hex>,
  3274. * opacity: <float>,
  3275. *
  3276. * map: new THREE.Texture( <Image> ),
  3277. *
  3278. * lightMap: new THREE.Texture( <Image> ),
  3279. *
  3280. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  3281. * combine: THREE.Multiply,
  3282. * reflectivity: <float>,
  3283. * refractionRatio: <float>,
  3284. *
  3285. * shading: THREE.SmoothShading,
  3286. * blending: THREE.NormalBlending,
  3287. * depthTest: <bool>,
  3288. *
  3289. * wireframe: <boolean>,
  3290. * wireframeLinewidth: <float>,
  3291. *
  3292. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  3293. *
  3294. * skinning: <bool>,
  3295. * morphTargets: <bool>,
  3296. * morphNormals: <bool>,
  3297. *
  3298. * fog: <bool>
  3299. * }
  3300. */
  3301. THREE.MeshLambertMaterial = function ( parameters ) {
  3302. THREE.Material.call( this, parameters );
  3303. parameters = parameters || {};
  3304. // color property represents diffuse for MeshLambertMaterial
  3305. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3306. this.ambient = parameters.ambient !== undefined ? new THREE.Color( parameters.ambient ) : new THREE.Color( 0xffffff );
  3307. this.emissive = parameters.emissive !== undefined ? new THREE.Color( parameters.emissive ) : new THREE.Color( 0x000000 );
  3308. this.wrapAround = parameters.wrapAround !== undefined ? parameters.wrapAround: false;
  3309. this.wrapRGB = new THREE.Vector3( 1, 1, 1 );
  3310. this.map = parameters.map !== undefined ? parameters.map : null;
  3311. this.lightMap = parameters.lightMap !== undefined ? parameters.lightMap : null;
  3312. this.envMap = parameters.envMap !== undefined ? parameters.envMap : null;
  3313. this.combine = parameters.combine !== undefined ? parameters.combine : THREE.MultiplyOperation;
  3314. this.reflectivity = parameters.reflectivity !== undefined ? parameters.reflectivity : 1;
  3315. this.refractionRatio = parameters.refractionRatio !== undefined ? parameters.refractionRatio : 0.98;
  3316. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  3317. this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading;
  3318. this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false;
  3319. this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1;
  3320. this.wireframeLinecap = parameters.wireframeLinecap !== undefined ? parameters.wireframeLinecap : 'round';
  3321. this.wireframeLinejoin = parameters.wireframeLinejoin !== undefined ? parameters.wireframeLinejoin : 'round';
  3322. this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : THREE.NoColors;
  3323. this.skinning = parameters.skinning !== undefined ? parameters.skinning : false;
  3324. this.morphTargets = parameters.morphTargets !== undefined ? parameters.morphTargets : false;
  3325. this.morphNormals = parameters.morphNormals !== undefined ? parameters.morphNormals : false;
  3326. };
  3327. THREE.MeshLambertMaterial.prototype = new THREE.Material();
  3328. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  3329. /**
  3330. * @author mr.doob / http://mrdoob.com/
  3331. * @author alteredq / http://alteredqualia.com/
  3332. *
  3333. * parameters = {
  3334. * color: <hex>,
  3335. * ambient: <hex>,
  3336. * emissive: <hex>,
  3337. * specular: <hex>,
  3338. * shininess: <float>,
  3339. * opacity: <float>,
  3340. *
  3341. * map: new THREE.Texture( <Image> ),
  3342. *
  3343. * lightMap: new THREE.Texture( <Image> ),
  3344. *
  3345. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  3346. * combine: THREE.Multiply,
  3347. * reflectivity: <float>,
  3348. * refractionRatio: <float>,
  3349. *
  3350. * shading: THREE.SmoothShading,
  3351. * blending: THREE.NormalBlending,
  3352. * depthTest: <bool>,
  3353. *
  3354. * wireframe: <boolean>,
  3355. * wireframeLinewidth: <float>,
  3356. *
  3357. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  3358. *
  3359. * skinning: <bool>,
  3360. * morphTargets: <bool>,
  3361. * morphNormals: <bool>,
  3362. *
  3363. * fog: <bool>
  3364. * }
  3365. */
  3366. THREE.MeshPhongMaterial = function ( parameters ) {
  3367. THREE.Material.call( this, parameters );
  3368. parameters = parameters || {};
  3369. // color property represents diffuse for MeshPhongMaterial
  3370. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3371. this.ambient = parameters.ambient !== undefined ? new THREE.Color( parameters.ambient ) : new THREE.Color( 0xffffff );
  3372. this.emissive = parameters.emissive !== undefined ? new THREE.Color( parameters.emissive ) : new THREE.Color( 0x000000 );
  3373. this.specular = parameters.specular !== undefined ? new THREE.Color( parameters.specular ) : new THREE.Color( 0x111111 );
  3374. this.shininess = parameters.shininess !== undefined ? parameters.shininess : 30;
  3375. this.metal = parameters.metal !== undefined ? parameters.metal : false;
  3376. this.perPixel = parameters.perPixel !== undefined ? parameters.perPixel : false;
  3377. this.wrapAround = parameters.wrapAround !== undefined ? parameters.wrapAround: false;
  3378. this.wrapRGB = new THREE.Vector3( 1, 1, 1 );
  3379. this.map = parameters.map !== undefined ? parameters.map : null;
  3380. this.lightMap = parameters.lightMap !== undefined ? parameters.lightMap : null;
  3381. this.envMap = parameters.envMap !== undefined ? parameters.envMap : null;
  3382. this.combine = parameters.combine !== undefined ? parameters.combine : THREE.MultiplyOperation;
  3383. this.reflectivity = parameters.reflectivity !== undefined ? parameters.reflectivity : 1;
  3384. this.refractionRatio = parameters.refractionRatio !== undefined ? parameters.refractionRatio : 0.98;
  3385. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  3386. this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading;
  3387. this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false;
  3388. this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1;
  3389. this.wireframeLinecap = parameters.wireframeLinecap !== undefined ? parameters.wireframeLinecap : 'round';
  3390. this.wireframeLinejoin = parameters.wireframeLinejoin !== undefined ? parameters.wireframeLinejoin : 'round';
  3391. this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : THREE.NoColors;
  3392. this.skinning = parameters.skinning !== undefined ? parameters.skinning : false;
  3393. this.morphTargets = parameters.morphTargets !== undefined ? parameters.morphTargets : false;
  3394. this.morphNormals = parameters.morphNormals !== undefined ? parameters.morphNormals : false;
  3395. };
  3396. THREE.MeshPhongMaterial.prototype = new THREE.Material();
  3397. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  3398. /**
  3399. * @author mr.doob / http://mrdoob.com/
  3400. * @author alteredq / http://alteredqualia.com/
  3401. *
  3402. * parameters = {
  3403. * opacity: <float>,
  3404. * blending: THREE.NormalBlending,
  3405. * depthTest: <bool>,
  3406. * wireframe: <boolean>,
  3407. * wireframeLinewidth: <float>
  3408. * }
  3409. */
  3410. THREE.MeshDepthMaterial = function ( parameters ) {
  3411. THREE.Material.call( this, parameters );
  3412. parameters = parameters || {};
  3413. this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading; // doesn't really apply here, normals are not used
  3414. this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false;
  3415. this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1;
  3416. };
  3417. THREE.MeshDepthMaterial.prototype = new THREE.Material();
  3418. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  3419. /**
  3420. * @author mr.doob / http://mrdoob.com/
  3421. *
  3422. * parameters = {
  3423. * opacity: <float>,
  3424. * shading: THREE.FlatShading,
  3425. * blending: THREE.NormalBlending,
  3426. * depthTest: <bool>,
  3427. * wireframe: <boolean>,
  3428. * wireframeLinewidth: <float>
  3429. * }
  3430. */
  3431. THREE.MeshNormalMaterial = function ( parameters ) {
  3432. THREE.Material.call( this, parameters );
  3433. parameters = parameters || {};
  3434. this.shading = parameters.shading ? parameters.shading : THREE.FlatShading;
  3435. this.wireframe = parameters.wireframe ? parameters.wireframe : false;
  3436. this.wireframeLinewidth = parameters.wireframeLinewidth ? parameters.wireframeLinewidth : 1;
  3437. };
  3438. THREE.MeshNormalMaterial.prototype = new THREE.Material();
  3439. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  3440. /**
  3441. * @author mr.doob / http://mrdoob.com/
  3442. */
  3443. THREE.MeshFaceMaterial = function () {
  3444. };
  3445. /**
  3446. * @author mr.doob / http://mrdoob.com/
  3447. * @author alteredq / http://alteredqualia.com/
  3448. *
  3449. * parameters = {
  3450. * color: <hex>,
  3451. * opacity: <float>,
  3452. * map: new THREE.Texture( <Image> ),
  3453. *
  3454. * size: <float>,
  3455. *
  3456. * blending: THREE.NormalBlending,
  3457. * depthTest: <bool>,
  3458. *
  3459. * vertexColors: <bool>,
  3460. *
  3461. * fog: <bool>
  3462. * }
  3463. */
  3464. THREE.ParticleBasicMaterial = function ( parameters ) {
  3465. THREE.Material.call( this, parameters );
  3466. parameters = parameters || {};
  3467. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3468. this.map = parameters.map !== undefined ? parameters.map : null;
  3469. this.size = parameters.size !== undefined ? parameters.size : 1;
  3470. this.sizeAttenuation = parameters.sizeAttenuation !== undefined ? parameters.sizeAttenuation : true;
  3471. this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : false;
  3472. this.fog = parameters.fog !== undefined ? parameters.fog : true;
  3473. };
  3474. THREE.ParticleBasicMaterial.prototype = new THREE.Material();
  3475. THREE.ParticleBasicMaterial.prototype.constructor = THREE.ParticleBasicMaterial;
  3476. /**
  3477. * @author mr.doob / http://mrdoob.com/
  3478. *
  3479. * parameters = {
  3480. * color: <hex>,
  3481. * program: <function>,
  3482. * opacity: <float>,
  3483. * blending: THREE.NormalBlending
  3484. * }
  3485. */
  3486. THREE.ParticleCanvasMaterial = function ( parameters ) {
  3487. THREE.Material.call( this, parameters );
  3488. parameters = parameters || {};
  3489. this.color = parameters.color !== undefined ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  3490. this.program = parameters.program !== undefined ? parameters.program : function ( context, color ) {};
  3491. };
  3492. THREE.ParticleCanvasMaterial.prototype = new THREE.Material();
  3493. THREE.ParticleCanvasMaterial.prototype.constructor = THREE.ParticleCanvasMaterial;
  3494. /**
  3495. * @author mr.doob / http://mrdoob.com/
  3496. */
  3497. THREE.ParticleDOMMaterial = function ( domElement ) {
  3498. THREE.Material.call( this );
  3499. this.domElement = domElement;
  3500. };
  3501. /**
  3502. * @author alteredq / http://alteredqualia.com/
  3503. *
  3504. * parameters = {
  3505. * fragmentShader: <string>,
  3506. * vertexShader: <string>,
  3507. *
  3508. * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  3509. *
  3510. * shading: THREE.SmoothShading,
  3511. * blending: THREE.NormalBlending,
  3512. * depthTest: <bool>,
  3513. *
  3514. * wireframe: <boolean>,
  3515. * wireframeLinewidth: <float>,
  3516. *
  3517. * lights: <bool>,
  3518. *
  3519. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  3520. *
  3521. * skinning: <bool>,
  3522. * morphTargets: <bool>,
  3523. * morphNormals: <bool>,
  3524. *
  3525. * fog: <bool>
  3526. * }
  3527. */
  3528. THREE.ShaderMaterial = function ( parameters ) {
  3529. THREE.Material.call( this, parameters );
  3530. parameters = parameters || {};
  3531. this.fragmentShader = parameters.fragmentShader !== undefined ? parameters.fragmentShader : "void main() {}";
  3532. this.vertexShader = parameters.vertexShader !== undefined ? parameters.vertexShader : "void main() {}";
  3533. this.uniforms = parameters.uniforms !== undefined ? parameters.uniforms : {};
  3534. this.attributes = parameters.attributes;
  3535. this.shading = parameters.shading !== undefined ? parameters.shading : THREE.SmoothShading;
  3536. this.wireframe = parameters.wireframe !== undefined ? parameters.wireframe : false;
  3537. this.wireframeLinewidth = parameters.wireframeLinewidth !== undefined ? parameters.wireframeLinewidth : 1;
  3538. this.fog = parameters.fog !== undefined ? parameters.fog : false; // set to use scene fog
  3539. this.lights = parameters.lights !== undefined ? parameters.lights : false; // set to use scene lights
  3540. this.vertexColors = parameters.vertexColors !== undefined ? parameters.vertexColors : THREE.NoColors; // set to use "color" attribute stream
  3541. this.skinning = parameters.skinning !== undefined ? parameters.skinning : false; // set to use skinning attribute streams
  3542. this.morphTargets = parameters.morphTargets !== undefined ? parameters.morphTargets : false; // set to use morph targets
  3543. this.morphNormals = parameters.morphNormals !== undefined ? parameters.morphNormals : false; // set to use morph normals
  3544. };
  3545. THREE.ShaderMaterial.prototype = new THREE.Material();
  3546. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  3547. /**
  3548. * @author mr.doob / http://mrdoob.com/
  3549. * @author alteredq / http://alteredqualia.com/
  3550. * @author szimek / https://github.com/szimek/
  3551. */
  3552. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type ) {
  3553. this.id = THREE.TextureCount ++;
  3554. this.image = image;
  3555. this.mapping = mapping !== undefined ? mapping : new THREE.UVMapping();
  3556. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  3557. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  3558. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  3559. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  3560. this.format = format !== undefined ? format : THREE.RGBAFormat;
  3561. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  3562. this.offset = new THREE.Vector2( 0, 0 );
  3563. this.repeat = new THREE.Vector2( 1, 1 );
  3564. this.generateMipmaps = true;
  3565. this.premultiplyAlpha = false;
  3566. this.needsUpdate = false;
  3567. this.onUpdate = null;
  3568. };
  3569. THREE.Texture.prototype = {
  3570. constructor: THREE.Texture,
  3571. clone: function () {
  3572. var clonedTexture = new THREE.Texture( this.image, this.mapping, this.wrapS, this.wrapT, this.magFilter, this.minFilter, this.format, this.type );
  3573. clonedTexture.offset.copy( this.offset );
  3574. clonedTexture.repeat.copy( this.repeat );
  3575. return clonedTexture;
  3576. }
  3577. };
  3578. THREE.TextureCount = 0;
  3579. THREE.MultiplyOperation = 0;
  3580. THREE.MixOperation = 1;
  3581. // Mapping modes
  3582. THREE.UVMapping = function () {};
  3583. THREE.CubeReflectionMapping = function () {};
  3584. THREE.CubeRefractionMapping = function () {};
  3585. THREE.SphericalReflectionMapping = function () {};
  3586. THREE.SphericalRefractionMapping = function () {};
  3587. // Wrapping modes
  3588. THREE.RepeatWrapping = 0;
  3589. THREE.ClampToEdgeWrapping = 1;
  3590. THREE.MirroredRepeatWrapping = 2;
  3591. // Filters
  3592. THREE.NearestFilter = 3;
  3593. THREE.NearestMipMapNearestFilter = 4;
  3594. THREE.NearestMipMapLinearFilter = 5;
  3595. THREE.LinearFilter = 6;
  3596. THREE.LinearMipMapNearestFilter = 7;
  3597. THREE.LinearMipMapLinearFilter = 8;
  3598. // Types
  3599. THREE.ByteType = 9;
  3600. THREE.UnsignedByteType = 10;
  3601. THREE.ShortType = 11;
  3602. THREE.UnsignedShortType = 12;
  3603. THREE.IntType = 13;
  3604. THREE.UnsignedIntType = 14;
  3605. THREE.FloatType = 15;
  3606. // Formats
  3607. THREE.AlphaFormat = 16;
  3608. THREE.RGBFormat = 17;
  3609. THREE.RGBAFormat = 18;
  3610. THREE.LuminanceFormat = 19;
  3611. THREE.LuminanceAlphaFormat = 20;
  3612. /**
  3613. * @author alteredq / http://alteredqualia.com/
  3614. */
  3615. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter ) {
  3616. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type );
  3617. this.image = { data: data, width: width, height: height };
  3618. };
  3619. THREE.DataTexture.prototype = new THREE.Texture();
  3620. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  3621. THREE.DataTexture.prototype.clone = function () {
  3622. var clonedTexture = new THREE.DataTexture( this.image.data, this.image.width, this.image.height, this.format, this.type, this.mapping, this.wrapS, this.wrapT, this.magFilter, this.minFilter );
  3623. clonedTexture.offset.copy( this.offset );
  3624. clonedTexture.repeat.copy( this.repeat );
  3625. return clonedTexture;
  3626. };
  3627. /**
  3628. * @author mr.doob / http://mrdoob.com/
  3629. */
  3630. THREE.Particle = function ( material ) {
  3631. THREE.Object3D.call( this );
  3632. this.material = material;
  3633. };
  3634. THREE.Particle.prototype = new THREE.Object3D();
  3635. THREE.Particle.prototype.constructor = THREE.Particle;
  3636. /**
  3637. * @author alteredq / http://alteredqualia.com/
  3638. */
  3639. THREE.ParticleSystem = function ( geometry, material ) {
  3640. THREE.Object3D.call( this );
  3641. this.geometry = geometry;
  3642. this.material = ( material !== undefined ) ? material : new THREE.ParticleBasicMaterial( { color: Math.random() * 0xffffff } );
  3643. this.sortParticles = false;
  3644. if ( this.geometry ) {
  3645. // calc bound radius
  3646. if( !this.geometry.boundingSphere ) {
  3647. this.geometry.computeBoundingSphere();
  3648. }
  3649. this.boundRadius = geometry.boundingSphere.radius;
  3650. }
  3651. this.frustumCulled = false;
  3652. };
  3653. THREE.ParticleSystem.prototype = new THREE.Object3D();
  3654. THREE.ParticleSystem.prototype.constructor = THREE.ParticleSystem;
  3655. /**
  3656. * @author mr.doob / http://mrdoob.com/
  3657. */
  3658. THREE.Line = function ( geometry, material, type ) {
  3659. THREE.Object3D.call( this );
  3660. this.geometry = geometry;
  3661. this.material = ( material !== undefined ) ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  3662. this.type = ( type !== undefined ) ? type : THREE.LineStrip;
  3663. if ( this.geometry ) {
  3664. if ( ! this.geometry.boundingSphere ) {
  3665. this.geometry.computeBoundingSphere();
  3666. }
  3667. }
  3668. };
  3669. THREE.LineStrip = 0;
  3670. THREE.LinePieces = 1;
  3671. THREE.Line.prototype = new THREE.Object3D();
  3672. THREE.Line.prototype.constructor = THREE.Line;
  3673. /**
  3674. * @author mr.doob / http://mrdoob.com/
  3675. * @author alteredq / http://alteredqualia.com/
  3676. * @author mikael emtinger / http://gomo.se/
  3677. */
  3678. THREE.Mesh = function ( geometry, material ) {
  3679. THREE.Object3D.call( this );
  3680. this.geometry = geometry;
  3681. this.material = ( material !== undefined ) ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff, wireframe: true } );
  3682. if ( this.geometry ) {
  3683. // calc bound radius
  3684. if( ! this.geometry.boundingSphere ) {
  3685. this.geometry.computeBoundingSphere();
  3686. }
  3687. this.boundRadius = geometry.boundingSphere.radius;
  3688. // setup morph targets
  3689. if( this.geometry.morphTargets.length ) {
  3690. this.morphTargetBase = -1;
  3691. this.morphTargetForcedOrder = [];
  3692. this.morphTargetInfluences = [];
  3693. this.morphTargetDictionary = {};
  3694. for( var m = 0; m < this.geometry.morphTargets.length; m ++ ) {
  3695. this.morphTargetInfluences.push( 0 );
  3696. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  3697. }
  3698. }
  3699. }
  3700. }
  3701. THREE.Mesh.prototype = new THREE.Object3D();
  3702. THREE.Mesh.prototype.constructor = THREE.Mesh;
  3703. THREE.Mesh.prototype.supr = THREE.Object3D.prototype;
  3704. /*
  3705. * Get Morph Target Index by Name
  3706. */
  3707. THREE.Mesh.prototype.getMorphTargetIndexByName = function( name ) {
  3708. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  3709. return this.morphTargetDictionary[ name ];
  3710. }
  3711. console.log( "THREE.Mesh.getMorphTargetIndexByName: morph target " + name + " does not exist. Returning 0." );
  3712. return 0;
  3713. }
  3714. /**
  3715. * @author mikael emtinger / http://gomo.se/
  3716. * @author alteredq / http://alteredqualia.com/
  3717. */
  3718. THREE.Bone = function( belongsToSkin ) {
  3719. THREE.Object3D.call( this );
  3720. this.skin = belongsToSkin;
  3721. this.skinMatrix = new THREE.Matrix4();
  3722. };
  3723. THREE.Bone.prototype = new THREE.Object3D();
  3724. THREE.Bone.prototype.constructor = THREE.Bone;
  3725. THREE.Bone.prototype.supr = THREE.Object3D.prototype;
  3726. THREE.Bone.prototype.update = function( parentSkinMatrix, forceUpdate ) {
  3727. // update local
  3728. if ( this.matrixAutoUpdate ) {
  3729. forceUpdate |= this.updateMatrix();
  3730. }
  3731. // update skin matrix
  3732. if ( forceUpdate || this.matrixWorldNeedsUpdate ) {
  3733. if( parentSkinMatrix ) {
  3734. this.skinMatrix.multiply( parentSkinMatrix, this.matrix );
  3735. } else {
  3736. this.skinMatrix.copy( this.matrix );
  3737. }
  3738. this.matrixWorldNeedsUpdate = false;
  3739. forceUpdate = true;
  3740. }
  3741. // update children
  3742. var child, i, l = this.children.length;
  3743. for ( i = 0; i < l; i ++ ) {
  3744. this.children[ i ].update( this.skinMatrix, forceUpdate );
  3745. }
  3746. };
  3747. /**
  3748. * @author mikael emtinger / http://gomo.se/
  3749. * @author alteredq / http://alteredqualia.com/
  3750. */
  3751. THREE.SkinnedMesh = function ( geometry, material ) {
  3752. THREE.Mesh.call( this, geometry, material );
  3753. // init bones
  3754. this.identityMatrix = new THREE.Matrix4();
  3755. this.bones = [];
  3756. this.boneMatrices = [];
  3757. var b, bone, gbone, p, q, s;
  3758. if ( this.geometry.bones !== undefined ) {
  3759. for ( b = 0; b < this.geometry.bones.length; b ++ ) {
  3760. gbone = this.geometry.bones[ b ];
  3761. p = gbone.pos;
  3762. q = gbone.rotq;
  3763. s = gbone.scl;
  3764. bone = this.addBone();
  3765. bone.name = gbone.name;
  3766. bone.position.set( p[0], p[1], p[2] );
  3767. bone.quaternion.set( q[0], q[1], q[2], q[3] );
  3768. bone.useQuaternion = true;
  3769. if ( s !== undefined ) {
  3770. bone.scale.set( s[0], s[1], s[2] );
  3771. } else {
  3772. bone.scale.set( 1, 1, 1 );
  3773. }
  3774. }
  3775. for ( b = 0; b < this.bones.length; b ++ ) {
  3776. gbone = this.geometry.bones[ b ];
  3777. bone = this.bones[ b ];
  3778. if ( gbone.parent === -1 ) {
  3779. this.add( bone );
  3780. } else {
  3781. this.bones[ gbone.parent ].add( bone );
  3782. }
  3783. }
  3784. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  3785. this.pose();
  3786. }
  3787. };
  3788. THREE.SkinnedMesh.prototype = new THREE.Mesh();
  3789. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  3790. THREE.SkinnedMesh.prototype.addBone = function( bone ) {
  3791. if ( bone === undefined ) {
  3792. bone = new THREE.Bone( this );
  3793. }
  3794. this.bones.push( bone );
  3795. return bone;
  3796. };
  3797. THREE.SkinnedMesh.prototype.updateMatrixWorld = function ( force ) {
  3798. this.matrixAutoUpdate && this.updateMatrix();
  3799. // update matrixWorld
  3800. if ( this.matrixWorldNeedsUpdate || force ) {
  3801. if ( this.parent ) {
  3802. this.matrixWorld.multiply( this.parent.matrixWorld, this.matrix );
  3803. } else {
  3804. this.matrixWorld.copy( this.matrix );
  3805. }
  3806. this.matrixWorldNeedsUpdate = false;
  3807. force = true;
  3808. }
  3809. // update children
  3810. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  3811. var child = this.children[ i ];
  3812. if ( child instanceof THREE.Bone ) {
  3813. child.update( this.identityMatrix, false );
  3814. } else {
  3815. child.updateMatrixWorld( true );
  3816. }
  3817. }
  3818. // flatten bone matrices to array
  3819. var b, bl = this.bones.length,
  3820. ba = this.bones,
  3821. bm = this.boneMatrices;
  3822. for ( b = 0; b < bl; b ++ ) {
  3823. ba[ b ].skinMatrix.flattenToArrayOffset( bm, b * 16 );
  3824. }
  3825. };
  3826. /*
  3827. * Pose
  3828. */
  3829. THREE.SkinnedMesh.prototype.pose = function() {
  3830. this.updateMatrixWorld( true );
  3831. var bim, bone, boneInverses = [];
  3832. for ( var b = 0; b < this.bones.length; b ++ ) {
  3833. bone = this.bones[ b ];
  3834. var inverseMatrix = new THREE.Matrix4();
  3835. inverseMatrix.getInverse( bone.skinMatrix );
  3836. boneInverses.push( inverseMatrix );
  3837. bone.skinMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
  3838. }
  3839. // project vertices to local
  3840. if ( this.geometry.skinVerticesA === undefined ) {
  3841. this.geometry.skinVerticesA = [];
  3842. this.geometry.skinVerticesB = [];
  3843. var orgVertex, vertex;
  3844. for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
  3845. orgVertex = this.geometry.vertices[ i ];
  3846. var indexA = this.geometry.skinIndices[ i ].x;
  3847. var indexB = this.geometry.skinIndices[ i ].y;
  3848. vertex = new THREE.Vector3( orgVertex.x, orgVertex.y, orgVertex.z );
  3849. this.geometry.skinVerticesA.push( boneInverses[ indexA ].multiplyVector3( vertex ) );
  3850. vertex = new THREE.Vector3( orgVertex.x, orgVertex.y, orgVertex.z );
  3851. this.geometry.skinVerticesB.push( boneInverses[ indexB ].multiplyVector3( vertex ) );
  3852. // todo: add more influences
  3853. // normalize weights
  3854. if ( this.geometry.skinWeights[ i ].x + this.geometry.skinWeights[ i ].y !== 1 ) {
  3855. var len = ( 1.0 - ( this.geometry.skinWeights[ i ].x + this.geometry.skinWeights[ i ].y ) ) * 0.5;
  3856. this.geometry.skinWeights[ i ].x += len;
  3857. this.geometry.skinWeights[ i ].y += len;
  3858. }
  3859. }
  3860. }
  3861. };
  3862. /**
  3863. * @author alteredq / http://alteredqualia.com/
  3864. */
  3865. THREE.MorphAnimMesh = function ( geometry, material ) {
  3866. THREE.Mesh.call( this, geometry, material );
  3867. // API
  3868. this.duration = 1000; // milliseconds
  3869. this.mirroredLoop = false;
  3870. this.time = 0;
  3871. // internals
  3872. this.lastKeyframe = 0;
  3873. this.currentKeyframe = 0;
  3874. this.direction = 1;
  3875. this.directionBackwards = false;
  3876. this.setFrameRange( 0, this.geometry.morphTargets.length - 1 );
  3877. };
  3878. THREE.MorphAnimMesh.prototype = new THREE.Mesh();
  3879. THREE.MorphAnimMesh.prototype.constructor = THREE.MorphAnimMesh;
  3880. THREE.MorphAnimMesh.prototype.setFrameRange = function ( start, end ) {
  3881. this.startKeyframe = start;
  3882. this.endKeyframe = end;
  3883. this.length = this.endKeyframe - this.startKeyframe + 1;
  3884. };
  3885. THREE.MorphAnimMesh.prototype.setDirectionForward = function () {
  3886. this.direction = 1;
  3887. this.directionBackwards = false;
  3888. };
  3889. THREE.MorphAnimMesh.prototype.setDirectionBackward = function () {
  3890. this.direction = -1;
  3891. this.directionBackwards = true;
  3892. };
  3893. THREE.MorphAnimMesh.prototype.parseAnimations = function () {
  3894. var geometry = this.geometry;
  3895. if ( ! geometry.animations ) geometry.animations = {};
  3896. var firstAnimation, animations = geometry.animations;
  3897. var pattern = /([a-z]+)(\d+)/;
  3898. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  3899. var morph = geometry.morphTargets[ i ];
  3900. var parts = morph.name.match( pattern );
  3901. if ( parts && parts.length > 1 ) {
  3902. var label = parts[ 1 ];
  3903. var num = parts[ 2 ];
  3904. if ( ! animations[ label ] ) animations[ label ] = { start: Infinity, end: -Infinity };
  3905. var animation = animations[ label ];
  3906. if ( i < animation.start ) animation.start = i;
  3907. if ( i > animation.end ) animation.end = i;
  3908. if ( ! firstAnimation ) firstAnimation = label;
  3909. }
  3910. }
  3911. geometry.firstAnimation = firstAnimation;
  3912. };
  3913. THREE.MorphAnimMesh.prototype.setAnimationLabel = function ( label, start, end ) {
  3914. if ( ! this.geometry.animations ) this.geometry.animations = {};
  3915. this.geometry.animations[ label ] = { start: start, end: end };
  3916. };
  3917. THREE.MorphAnimMesh.prototype.playAnimation = function ( label, fps ) {
  3918. var animation = this.geometry.animations[ label ];
  3919. if ( animation ) {
  3920. this.setFrameRange( animation.start, animation.end );
  3921. this.duration = 1000 * ( ( animation.end - animation.start ) / fps );
  3922. this.time = 0;
  3923. } else {
  3924. console.warn( "animation[" + label + "] undefined" );
  3925. }
  3926. };
  3927. THREE.MorphAnimMesh.prototype.updateAnimation = function ( delta ) {
  3928. var frameTime = this.duration / this.length;
  3929. this.time += this.direction * delta;
  3930. if ( this.mirroredLoop ) {
  3931. if ( this.time > this.duration || this.time < 0 ) {
  3932. this.direction *= -1;
  3933. if ( this.time > this.duration ) {
  3934. this.time = this.duration;
  3935. this.directionBackwards = true;
  3936. }
  3937. if ( this.time < 0 ) {
  3938. this.time = 0;
  3939. this.directionBackwards = false;
  3940. }
  3941. }
  3942. } else {
  3943. this.time = this.time % this.duration;
  3944. if ( this.time < 0 ) this.time += this.duration;
  3945. }
  3946. var keyframe = this.startKeyframe + THREE.Math.clamp( Math.floor( this.time / frameTime ), 0, this.length - 1 );
  3947. if ( keyframe !== this.currentKeyframe ) {
  3948. this.morphTargetInfluences[ this.lastKeyframe ] = 0;
  3949. this.morphTargetInfluences[ this.currentKeyframe ] = 1;
  3950. this.morphTargetInfluences[ keyframe ] = 0;
  3951. this.lastKeyframe = this.currentKeyframe;
  3952. this.currentKeyframe = keyframe;
  3953. }
  3954. var mix = ( this.time % frameTime ) / frameTime;
  3955. if ( this.directionBackwards ) {
  3956. mix = 1 - mix;
  3957. }
  3958. this.morphTargetInfluences[ this.currentKeyframe ] = mix;
  3959. this.morphTargetInfluences[ this.lastKeyframe ] = 1 - mix;
  3960. };
  3961. /**
  3962. * @author alteredq / http://alteredqualia.com/
  3963. */
  3964. THREE.Ribbon = function ( geometry, material ) {
  3965. THREE.Object3D.call( this );
  3966. this.geometry = geometry;
  3967. this.material = material;
  3968. };
  3969. THREE.Ribbon.prototype = new THREE.Object3D();
  3970. THREE.Ribbon.prototype.constructor = THREE.Ribbon;
  3971. /**
  3972. * @author mikael emtinger / http://gomo.se/
  3973. * @author alteredq / http://alteredqualia.com/
  3974. * @author mr.doob / http://mrdoob.com/
  3975. */
  3976. THREE.LOD = function () {
  3977. THREE.Object3D.call( this );
  3978. this.LODs = [];
  3979. };
  3980. THREE.LOD.prototype = new THREE.Object3D();
  3981. THREE.LOD.prototype.constructor = THREE.LOD;
  3982. THREE.LOD.prototype.supr = THREE.Object3D.prototype;
  3983. THREE.LOD.prototype.addLevel = function ( object3D, visibleAtDistance ) {
  3984. if ( visibleAtDistance === undefined ) {
  3985. visibleAtDistance = 0;
  3986. }
  3987. visibleAtDistance = Math.abs( visibleAtDistance );
  3988. for ( var l = 0; l < this.LODs.length; l ++ ) {
  3989. if ( visibleAtDistance < this.LODs[ l ].visibleAtDistance ) {
  3990. break;
  3991. }
  3992. }
  3993. this.LODs.splice( l, 0, { visibleAtDistance: visibleAtDistance, object3D: object3D } );
  3994. this.add( object3D );
  3995. };
  3996. THREE.LOD.prototype.update = function ( camera ) {
  3997. if ( this.LODs.length > 1 ) {
  3998. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  3999. var inverse = camera.matrixWorldInverse;
  4000. var distance = -( inverse.elements[2] * this.matrixWorld.elements[12] + inverse.elements[6] * this.matrixWorld.elements[13] + inverse.elements[10] * this.matrixWorld.elements[14] + inverse.elements[14] );
  4001. this.LODs[ 0 ].object3D.visible = true;
  4002. for ( var l = 1; l < this.LODs.length; l ++ ) {
  4003. if( distance >= this.LODs[ l ].visibleAtDistance ) {
  4004. this.LODs[ l - 1 ].object3D.visible = false;
  4005. this.LODs[ l ].object3D.visible = true;
  4006. } else {
  4007. break;
  4008. }
  4009. }
  4010. for( ; l < this.LODs.length; l ++ ) {
  4011. this.LODs[ l ].object3D.visible = false;
  4012. }
  4013. }
  4014. };
  4015. /**
  4016. * @author mikael emtinger / http://gomo.se/
  4017. */
  4018. THREE.Sprite = function ( parameters ) {
  4019. THREE.Object3D.call( this );
  4020. this.color = ( parameters.color !== undefined ) ? new THREE.Color( parameters.color ) : new THREE.Color( 0xffffff );
  4021. this.map = ( parameters.map !== undefined ) ? parameters.map : new THREE.Texture();
  4022. this.blending = ( parameters.blending !== undefined ) ? parameters.blending : THREE.NormalBlending;
  4023. this.blendSrc = parameters.blendSrc !== undefined ? parameters.blendSrc : THREE.SrcAlphaFactor;
  4024. this.blendDst = parameters.blendDst !== undefined ? parameters.blendDst : THREE.OneMinusSrcAlphaFactor;
  4025. this.blendEquation = parameters.blendEquation !== undefined ? parameters.blendEquation : THREE.AddEquation;
  4026. this.useScreenCoordinates = ( parameters.useScreenCoordinates !== undefined ) ? parameters.useScreenCoordinates : true;
  4027. this.mergeWith3D = ( parameters.mergeWith3D !== undefined ) ? parameters.mergeWith3D : !this.useScreenCoordinates;
  4028. this.affectedByDistance = ( parameters.affectedByDistance !== undefined ) ? parameters.affectedByDistance : !this.useScreenCoordinates;
  4029. this.scaleByViewport = ( parameters.scaleByViewport !== undefined ) ? parameters.scaleByViewport : !this.affectedByDistance;
  4030. this.alignment = ( parameters.alignment instanceof THREE.Vector2 ) ? parameters.alignment : THREE.SpriteAlignment.center;
  4031. this.rotation3d = this.rotation;
  4032. this.rotation = 0;
  4033. this.opacity = 1;
  4034. this.uvOffset = new THREE.Vector2( 0, 0 );
  4035. this.uvScale = new THREE.Vector2( 1, 1 );
  4036. };
  4037. THREE.Sprite.prototype = new THREE.Object3D();
  4038. THREE.Sprite.prototype.constructor = THREE.Sprite;
  4039. /*
  4040. * Custom update matrix
  4041. */
  4042. THREE.Sprite.prototype.updateMatrix = function () {
  4043. this.matrix.setPosition( this.position );
  4044. this.rotation3d.set( 0, 0, this.rotation );
  4045. this.matrix.setRotationFromEuler( this.rotation3d );
  4046. if ( this.scale.x !== 1 || this.scale.y !== 1 ) {
  4047. this.matrix.scale( this.scale );
  4048. this.boundRadiusScale = Math.max( this.scale.x, this.scale.y );
  4049. }
  4050. this.matrixWorldNeedsUpdate = true;
  4051. };
  4052. /*
  4053. * Alignment
  4054. */
  4055. THREE.SpriteAlignment = {};
  4056. THREE.SpriteAlignment.topLeft = new THREE.Vector2( 1, -1 );
  4057. THREE.SpriteAlignment.topCenter = new THREE.Vector2( 0, -1 );
  4058. THREE.SpriteAlignment.topRight = new THREE.Vector2( -1, -1 );
  4059. THREE.SpriteAlignment.centerLeft = new THREE.Vector2( 1, 0 );
  4060. THREE.SpriteAlignment.center = new THREE.Vector2( 0, 0 );
  4061. THREE.SpriteAlignment.centerRight = new THREE.Vector2( -1, 0 );
  4062. THREE.SpriteAlignment.bottomLeft = new THREE.Vector2( 1, 1 );
  4063. THREE.SpriteAlignment.bottomCenter = new THREE.Vector2( 0, 1 );
  4064. THREE.SpriteAlignment.bottomRight = new THREE.Vector2( -1, 1 );
  4065. /**
  4066. * @author mr.doob / http://mrdoob.com/
  4067. */
  4068. THREE.Scene = function () {
  4069. THREE.Object3D.call( this );
  4070. this.fog = null;
  4071. this.overrideMaterial = null;
  4072. this.matrixAutoUpdate = false;
  4073. this.__objects = [];
  4074. this.__lights = [];
  4075. this.__objectsAdded = [];
  4076. this.__objectsRemoved = [];
  4077. };
  4078. THREE.Scene.prototype = new THREE.Object3D();
  4079. THREE.Scene.prototype.constructor = THREE.Scene;
  4080. THREE.Scene.prototype.__addObject = function ( object ) {
  4081. if ( object instanceof THREE.Light ) {
  4082. if ( this.__lights.indexOf( object ) === - 1 ) {
  4083. this.__lights.push( object );
  4084. }
  4085. } else if ( !( object instanceof THREE.Camera || object instanceof THREE.Bone ) ) {
  4086. if ( this.__objects.indexOf( object ) === - 1 ) {
  4087. this.__objects.push( object );
  4088. this.__objectsAdded.push( object );
  4089. // check if previously removed
  4090. var i = this.__objectsRemoved.indexOf( object );
  4091. if ( i !== -1 ) {
  4092. this.__objectsRemoved.splice( i, 1 );
  4093. }
  4094. }
  4095. }
  4096. for ( var c = 0; c < object.children.length; c ++ ) {
  4097. this.__addObject( object.children[ c ] );
  4098. }
  4099. };
  4100. THREE.Scene.prototype.__removeObject = function ( object ) {
  4101. if ( object instanceof THREE.Light ) {
  4102. var i = this.__lights.indexOf( object );
  4103. if ( i !== -1 ) {
  4104. this.__lights.splice( i, 1 );
  4105. }
  4106. } else if ( !( object instanceof THREE.Camera ) ) {
  4107. var i = this.__objects.indexOf( object );
  4108. if( i !== -1 ) {
  4109. this.__objects.splice( i, 1 );
  4110. this.__objectsRemoved.push( object );
  4111. // check if previously added
  4112. var ai = this.__objectsAdded.indexOf( object );
  4113. if ( ai !== -1 ) {
  4114. this.__objectsAdded.splice( ai, 1 );
  4115. }
  4116. }
  4117. }
  4118. for ( var c = 0; c < object.children.length; c ++ ) {
  4119. this.__removeObject( object.children[ c ] );
  4120. }
  4121. };
  4122. /**
  4123. * @author mr.doob / http://mrdoob.com/
  4124. * @author alteredq / http://alteredqualia.com/
  4125. */
  4126. THREE.Fog = function ( hex, near, far ) {
  4127. this.color = new THREE.Color( hex );
  4128. this.near = ( near !== undefined ) ? near : 1;
  4129. this.far = ( far !== undefined ) ? far : 1000;
  4130. };
  4131. /**
  4132. * @author mr.doob / http://mrdoob.com/
  4133. * @author alteredq / http://alteredqualia.com/
  4134. */
  4135. THREE.FogExp2 = function ( hex, density ) {
  4136. this.color = new THREE.Color( hex );
  4137. this.density = ( density !== undefined ) ? density : 0.00025;
  4138. };
  4139. /**
  4140. * @author mr.doob / http://mrdoob.com/
  4141. */
  4142. THREE.DOMRenderer = function () {
  4143. console.log( 'THREE.DOMRenderer', THREE.REVISION );
  4144. var _renderData, _elements,
  4145. _width, _height, _widthHalf, _heightHalf, _transformProp,
  4146. _projector = new THREE.Projector();
  4147. var getSupportedProp = function ( proparray ) {
  4148. var root = document.documentElement
  4149. for ( var i = 0; i < proparray.length; i ++ ) {
  4150. if ( typeof root.style[ proparray[ i ] ] === "string" ) {
  4151. return proparray[i];
  4152. }
  4153. }
  4154. return null;
  4155. };
  4156. _transformProp = getSupportedProp( [ 'transform', 'MozTransform', 'WebkitTransform', 'msTransform', 'OTransform' ] );
  4157. this.domElement = document.createElement( 'div' );
  4158. this.setSize = function ( width, height ) {
  4159. _width = width;
  4160. _height = height;
  4161. _widthHalf = _width / 2;
  4162. _heightHalf = _height / 2;
  4163. };
  4164. this.render = function ( scene, camera ) {
  4165. var e, el, m, ml, element, material, dom, v1x, v1y;
  4166. _renderData = _projector.projectScene( scene, camera );
  4167. _elements = _renderData.elements;
  4168. for ( e = 0, el = _elements.length; e < el; e ++ ) {
  4169. element = _elements[ e ];
  4170. if ( element instanceof THREE.RenderableParticle && element.material instanceof THREE.ParticleDOMMaterial ) {
  4171. dom = element.material.domElement;
  4172. v1x = element.x * _widthHalf + _widthHalf - ( dom.offsetWidth >> 1 );
  4173. v1y = element.y * _heightHalf + _heightHalf - ( dom.offsetHeight >> 1 );
  4174. dom.style.left = v1x + 'px';
  4175. dom.style.top = v1y + 'px';
  4176. dom.style.zIndex = Math.abs( Math.floor( ( 1 - element.z ) * camera.far / camera.near ) )
  4177. if ( _transformProp ) {
  4178. var scaleX = element.scale.x * _widthHalf;
  4179. var scaleY = element.scale.y * _heightHalf;
  4180. var scaleVal = "scale(" + scaleX + "," + scaleY + ")";
  4181. dom.style[ _transformProp ] = scaleVal;
  4182. }
  4183. }
  4184. }
  4185. };
  4186. };
  4187. /**
  4188. * @author mr.doob / http://mrdoob.com/
  4189. */
  4190. THREE.CanvasRenderer = function ( parameters ) {
  4191. console.log( 'THREE.CanvasRenderer', THREE.REVISION );
  4192. parameters = parameters || {};
  4193. var _this = this,
  4194. _renderData, _elements, _lights,
  4195. _projector = new THREE.Projector(),
  4196. _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  4197. _canvasWidth, _canvasHeight, _canvasWidthHalf, _canvasHeightHalf,
  4198. _context = _canvas.getContext( '2d' ),
  4199. _clearColor = new THREE.Color( 0x000000 ),
  4200. _clearOpacity = 0,
  4201. _contextGlobalAlpha = 1,
  4202. _contextGlobalCompositeOperation = 0,
  4203. _contextStrokeStyle = null,
  4204. _contextFillStyle = null,
  4205. _contextLineWidth = null,
  4206. _contextLineCap = null,
  4207. _contextLineJoin = null,
  4208. _v1, _v2, _v3, _v4,
  4209. _v5 = new THREE.RenderableVertex(),
  4210. _v6 = new THREE.RenderableVertex(),
  4211. _v1x, _v1y, _v2x, _v2y, _v3x, _v3y,
  4212. _v4x, _v4y, _v5x, _v5y, _v6x, _v6y,
  4213. _color = new THREE.Color(),
  4214. _color1 = new THREE.Color(),
  4215. _color2 = new THREE.Color(),
  4216. _color3 = new THREE.Color(),
  4217. _color4 = new THREE.Color(),
  4218. _patterns = [], _imagedatas = [],
  4219. _near, _far,
  4220. _image, _uvs,
  4221. _uv1x, _uv1y, _uv2x, _uv2y, _uv3x, _uv3y,
  4222. _clipRect = new THREE.Rectangle(),
  4223. _clearRect = new THREE.Rectangle(),
  4224. _bboxRect = new THREE.Rectangle(),
  4225. _enableLighting = false,
  4226. _ambientLight = new THREE.Color(),
  4227. _directionalLights = new THREE.Color(),
  4228. _pointLights = new THREE.Color(),
  4229. _pi2 = Math.PI * 2,
  4230. _vector3 = new THREE.Vector3(), // Needed for PointLight
  4231. _pixelMap, _pixelMapContext, _pixelMapImage, _pixelMapData,
  4232. _gradientMap, _gradientMapContext, _gradientMapQuality = 16;
  4233. _pixelMap = document.createElement( 'canvas' );
  4234. _pixelMap.width = _pixelMap.height = 2;
  4235. _pixelMapContext = _pixelMap.getContext( '2d' );
  4236. _pixelMapContext.fillStyle = 'rgba(0,0,0,1)';
  4237. _pixelMapContext.fillRect( 0, 0, 2, 2 );
  4238. _pixelMapImage = _pixelMapContext.getImageData( 0, 0, 2, 2 );
  4239. _pixelMapData = _pixelMapImage.data;
  4240. _gradientMap = document.createElement( 'canvas' );
  4241. _gradientMap.width = _gradientMap.height = _gradientMapQuality;
  4242. _gradientMapContext = _gradientMap.getContext( '2d' );
  4243. _gradientMapContext.translate( - _gradientMapQuality / 2, - _gradientMapQuality / 2 );
  4244. _gradientMapContext.scale( _gradientMapQuality, _gradientMapQuality );
  4245. _gradientMapQuality --; // Fix UVs
  4246. this.domElement = _canvas;
  4247. this.autoClear = true;
  4248. this.sortObjects = true;
  4249. this.sortElements = true;
  4250. this.info = {
  4251. render: {
  4252. vertices: 0,
  4253. faces: 0
  4254. }
  4255. }
  4256. this.setSize = function ( width, height ) {
  4257. _canvasWidth = width;
  4258. _canvasHeight = height;
  4259. _canvasWidthHalf = Math.floor( _canvasWidth / 2 );
  4260. _canvasHeightHalf = Math.floor( _canvasHeight / 2 );
  4261. _canvas.width = _canvasWidth;
  4262. _canvas.height = _canvasHeight;
  4263. _clipRect.set( - _canvasWidthHalf, - _canvasHeightHalf, _canvasWidthHalf, _canvasHeightHalf );
  4264. _clearRect.set( - _canvasWidthHalf, - _canvasHeightHalf, _canvasWidthHalf, _canvasHeightHalf );
  4265. _contextGlobalAlpha = 1;
  4266. _contextGlobalCompositeOperation = 0;
  4267. _contextStrokeStyle = null;
  4268. _contextFillStyle = null;
  4269. _contextLineWidth = null;
  4270. _contextLineCap = null;
  4271. _contextLineJoin = null;
  4272. };
  4273. this.setClearColor = function ( color, opacity ) {
  4274. _clearColor.copy( color );
  4275. _clearOpacity = opacity !== undefined ? opacity : 1;
  4276. _clearRect.set( - _canvasWidthHalf, - _canvasHeightHalf, _canvasWidthHalf, _canvasHeightHalf );
  4277. };
  4278. this.setClearColorHex = function ( hex, opacity ) {
  4279. _clearColor.setHex( hex );
  4280. _clearOpacity = opacity !== undefined ? opacity : 1;
  4281. _clearRect.set( - _canvasWidthHalf, - _canvasHeightHalf, _canvasWidthHalf, _canvasHeightHalf );
  4282. };
  4283. this.clear = function () {
  4284. _context.setTransform( 1, 0, 0, - 1, _canvasWidthHalf, _canvasHeightHalf );
  4285. if ( !_clearRect.isEmpty() ) {
  4286. _clearRect.minSelf( _clipRect );
  4287. _clearRect.inflate( 2 );
  4288. if ( _clearOpacity < 1 ) {
  4289. _context.clearRect( Math.floor( _clearRect.getX() ), Math.floor( _clearRect.getY() ), Math.floor( _clearRect.getWidth() ), Math.floor( _clearRect.getHeight() ) );
  4290. }
  4291. if ( _clearOpacity > 0 ) {
  4292. setBlending( THREE.NormalBlending );
  4293. setOpacity( 1 );
  4294. setFillStyle( 'rgba(' + Math.floor( _clearColor.r * 255 ) + ',' + Math.floor( _clearColor.g * 255 ) + ',' + Math.floor( _clearColor.b * 255 ) + ',' + _clearOpacity + ')' );
  4295. _context.fillRect( Math.floor( _clearRect.getX() ), Math.floor( _clearRect.getY() ), Math.floor( _clearRect.getWidth() ), Math.floor( _clearRect.getHeight() ) );
  4296. }
  4297. _clearRect.empty();
  4298. }
  4299. };
  4300. this.render = function ( scene, camera ) {
  4301. var e, el, element, material;
  4302. this.autoClear ? this.clear() : _context.setTransform( 1, 0, 0, - 1, _canvasWidthHalf, _canvasHeightHalf );
  4303. _this.info.render.vertices = 0;
  4304. _this.info.render.faces = 0;
  4305. _renderData = _projector.projectScene( scene, camera, this.sortElements );
  4306. _elements = _renderData.elements;
  4307. _lights = _renderData.lights;
  4308. /* DEBUG
  4309. _context.fillStyle = 'rgba( 0, 255, 255, 0.5 )';
  4310. _context.fillRect( _clipRect.getX(), _clipRect.getY(), _clipRect.getWidth(), _clipRect.getHeight() );
  4311. */
  4312. _enableLighting = _lights.length > 0;
  4313. if ( _enableLighting ) {
  4314. calculateLights( _lights );
  4315. }
  4316. for ( e = 0, el = _elements.length; e < el; e++ ) {
  4317. element = _elements[ e ];
  4318. material = element.material;
  4319. material = material instanceof THREE.MeshFaceMaterial ? element.faceMaterial : material;
  4320. if ( material == null || material.opacity == 0 ) continue;
  4321. _bboxRect.empty();
  4322. if ( element instanceof THREE.RenderableParticle ) {
  4323. _v1 = element;
  4324. _v1.x *= _canvasWidthHalf; _v1.y *= _canvasHeightHalf;
  4325. renderParticle( _v1, element, material, scene );
  4326. } else if ( element instanceof THREE.RenderableLine ) {
  4327. _v1 = element.v1; _v2 = element.v2;
  4328. _v1.positionScreen.x *= _canvasWidthHalf; _v1.positionScreen.y *= _canvasHeightHalf;
  4329. _v2.positionScreen.x *= _canvasWidthHalf; _v2.positionScreen.y *= _canvasHeightHalf;
  4330. _bboxRect.addPoint( _v1.positionScreen.x, _v1.positionScreen.y );
  4331. _bboxRect.addPoint( _v2.positionScreen.x, _v2.positionScreen.y );
  4332. if ( _clipRect.intersects( _bboxRect ) ) {
  4333. renderLine( _v1, _v2, element, material, scene );
  4334. }
  4335. } else if ( element instanceof THREE.RenderableFace3 ) {
  4336. _v1 = element.v1; _v2 = element.v2; _v3 = element.v3;
  4337. _v1.positionScreen.x *= _canvasWidthHalf; _v1.positionScreen.y *= _canvasHeightHalf;
  4338. _v2.positionScreen.x *= _canvasWidthHalf; _v2.positionScreen.y *= _canvasHeightHalf;
  4339. _v3.positionScreen.x *= _canvasWidthHalf; _v3.positionScreen.y *= _canvasHeightHalf;
  4340. if ( material.overdraw ) {
  4341. expand( _v1.positionScreen, _v2.positionScreen );
  4342. expand( _v2.positionScreen, _v3.positionScreen );
  4343. expand( _v3.positionScreen, _v1.positionScreen );
  4344. }
  4345. _bboxRect.add3Points( _v1.positionScreen.x, _v1.positionScreen.y,
  4346. _v2.positionScreen.x, _v2.positionScreen.y,
  4347. _v3.positionScreen.x, _v3.positionScreen.y );
  4348. if ( _clipRect.intersects( _bboxRect ) ) {
  4349. renderFace3( _v1, _v2, _v3, 0, 1, 2, element, material, scene );
  4350. }
  4351. } else if ( element instanceof THREE.RenderableFace4 ) {
  4352. _v1 = element.v1; _v2 = element.v2; _v3 = element.v3; _v4 = element.v4;
  4353. _v1.positionScreen.x *= _canvasWidthHalf; _v1.positionScreen.y *= _canvasHeightHalf;
  4354. _v2.positionScreen.x *= _canvasWidthHalf; _v2.positionScreen.y *= _canvasHeightHalf;
  4355. _v3.positionScreen.x *= _canvasWidthHalf; _v3.positionScreen.y *= _canvasHeightHalf;
  4356. _v4.positionScreen.x *= _canvasWidthHalf; _v4.positionScreen.y *= _canvasHeightHalf;
  4357. _v5.positionScreen.copy( _v2.positionScreen );
  4358. _v6.positionScreen.copy( _v4.positionScreen );
  4359. if ( material.overdraw ) {
  4360. expand( _v1.positionScreen, _v2.positionScreen );
  4361. expand( _v2.positionScreen, _v4.positionScreen );
  4362. expand( _v4.positionScreen, _v1.positionScreen );
  4363. expand( _v3.positionScreen, _v5.positionScreen );
  4364. expand( _v3.positionScreen, _v6.positionScreen );
  4365. }
  4366. _bboxRect.addPoint( _v1.positionScreen.x, _v1.positionScreen.y );
  4367. _bboxRect.addPoint( _v2.positionScreen.x, _v2.positionScreen.y );
  4368. _bboxRect.addPoint( _v3.positionScreen.x, _v3.positionScreen.y );
  4369. _bboxRect.addPoint( _v4.positionScreen.x, _v4.positionScreen.y );
  4370. if ( _clipRect.intersects( _bboxRect ) ) {
  4371. renderFace4( _v1, _v2, _v3, _v4, _v5, _v6, element, material, scene );
  4372. }
  4373. }
  4374. /*
  4375. _context.lineWidth = 1;
  4376. _context.strokeStyle = 'rgba( 0, 255, 0, 0.5 )';
  4377. _context.strokeRect( _bboxRect.getX(), _bboxRect.getY(), _bboxRect.getWidth(), _bboxRect.getHeight() );
  4378. */
  4379. _clearRect.addRectangle( _bboxRect );
  4380. }
  4381. /* DEBUG
  4382. _context.lineWidth = 1;
  4383. _context.strokeStyle = 'rgba( 255, 0, 0, 0.5 )';
  4384. _context.strokeRect( _clearRect.getX(), _clearRect.getY(), _clearRect.getWidth(), _clearRect.getHeight() );
  4385. */
  4386. _context.setTransform( 1, 0, 0, 1, 0, 0 );
  4387. //
  4388. function calculateLights( lights ) {
  4389. var l, ll, light, lightColor;
  4390. _ambientLight.setRGB( 0, 0, 0 );
  4391. _directionalLights.setRGB( 0, 0, 0 );
  4392. _pointLights.setRGB( 0, 0, 0 );
  4393. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  4394. light = lights[ l ];
  4395. lightColor = light.color;
  4396. if ( light instanceof THREE.AmbientLight ) {
  4397. _ambientLight.r += lightColor.r;
  4398. _ambientLight.g += lightColor.g;
  4399. _ambientLight.b += lightColor.b;
  4400. } else if ( light instanceof THREE.DirectionalLight ) {
  4401. // for particles
  4402. _directionalLights.r += lightColor.r;
  4403. _directionalLights.g += lightColor.g;
  4404. _directionalLights.b += lightColor.b;
  4405. } else if ( light instanceof THREE.PointLight ) {
  4406. // for particles
  4407. _pointLights.r += lightColor.r;
  4408. _pointLights.g += lightColor.g;
  4409. _pointLights.b += lightColor.b;
  4410. }
  4411. }
  4412. }
  4413. function calculateLight( lights, position, normal, color ) {
  4414. var l, ll, light, lightColor, lightPosition, amount;
  4415. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  4416. light = lights[ l ];
  4417. lightColor = light.color;
  4418. if ( light instanceof THREE.DirectionalLight ) {
  4419. lightPosition = light.matrixWorld.getPosition();
  4420. amount = normal.dot( lightPosition );
  4421. if ( amount <= 0 ) continue;
  4422. amount *= light.intensity;
  4423. color.r += lightColor.r * amount;
  4424. color.g += lightColor.g * amount;
  4425. color.b += lightColor.b * amount;
  4426. } else if ( light instanceof THREE.PointLight ) {
  4427. lightPosition = light.matrixWorld.getPosition();
  4428. amount = normal.dot( _vector3.sub( lightPosition, position ).normalize() );
  4429. if ( amount <= 0 ) continue;
  4430. amount *= light.distance == 0 ? 1 : 1 - Math.min( position.distanceTo( lightPosition ) / light.distance, 1 );
  4431. if ( amount == 0 ) continue;
  4432. amount *= light.intensity;
  4433. color.r += lightColor.r * amount;
  4434. color.g += lightColor.g * amount;
  4435. color.b += lightColor.b * amount;
  4436. }
  4437. }
  4438. }
  4439. function renderParticle ( v1, element, material, scene ) {
  4440. setOpacity( material.opacity );
  4441. setBlending( material.blending );
  4442. var width, height, scaleX, scaleY,
  4443. bitmap, bitmapWidth, bitmapHeight;
  4444. if ( material instanceof THREE.ParticleBasicMaterial ) {
  4445. if ( material.map ) {
  4446. bitmap = material.map.image;
  4447. bitmapWidth = bitmap.width >> 1;
  4448. bitmapHeight = bitmap.height >> 1;
  4449. scaleX = element.scale.x * _canvasWidthHalf;
  4450. scaleY = element.scale.y * _canvasHeightHalf;
  4451. width = scaleX * bitmapWidth;
  4452. height = scaleY * bitmapHeight;
  4453. // TODO: Rotations break this...
  4454. _bboxRect.set( v1.x - width, v1.y - height, v1.x + width, v1.y + height );
  4455. if ( !_clipRect.intersects( _bboxRect ) ) {
  4456. return;
  4457. }
  4458. _context.save();
  4459. _context.translate( v1.x, v1.y );
  4460. _context.rotate( - element.rotation );
  4461. _context.scale( scaleX, - scaleY );
  4462. _context.translate( - bitmapWidth, - bitmapHeight );
  4463. _context.drawImage( bitmap, 0, 0 );
  4464. _context.restore();
  4465. }
  4466. /* DEBUG
  4467. _context.beginPath();
  4468. _context.moveTo( v1.x - 10, v1.y );
  4469. _context.lineTo( v1.x + 10, v1.y );
  4470. _context.moveTo( v1.x, v1.y - 10 );
  4471. _context.lineTo( v1.x, v1.y + 10 );
  4472. _context.closePath();
  4473. _context.strokeStyle = 'rgb(255,255,0)';
  4474. _context.stroke();
  4475. */
  4476. } else if ( material instanceof THREE.ParticleCanvasMaterial ) {
  4477. width = element.scale.x * _canvasWidthHalf;
  4478. height = element.scale.y * _canvasHeightHalf;
  4479. _bboxRect.set( v1.x - width, v1.y - height, v1.x + width, v1.y + height );
  4480. if ( !_clipRect.intersects( _bboxRect ) ) {
  4481. return;
  4482. }
  4483. setStrokeStyle( material.color.getContextStyle() );
  4484. setFillStyle( material.color.getContextStyle() );
  4485. _context.save();
  4486. _context.translate( v1.x, v1.y );
  4487. _context.rotate( - element.rotation );
  4488. _context.scale( width, height );
  4489. material.program( _context );
  4490. _context.restore();
  4491. }
  4492. }
  4493. function renderLine( v1, v2, element, material, scene ) {
  4494. setOpacity( material.opacity );
  4495. setBlending( material.blending );
  4496. _context.beginPath();
  4497. _context.moveTo( v1.positionScreen.x, v1.positionScreen.y );
  4498. _context.lineTo( v2.positionScreen.x, v2.positionScreen.y );
  4499. _context.closePath();
  4500. if ( material instanceof THREE.LineBasicMaterial ) {
  4501. setLineWidth( material.linewidth );
  4502. setLineCap( material.linecap );
  4503. setLineJoin( material.linejoin );
  4504. setStrokeStyle( material.color.getContextStyle() );
  4505. _context.stroke();
  4506. _bboxRect.inflate( material.linewidth * 2 );
  4507. }
  4508. }
  4509. function renderFace3( v1, v2, v3, uv1, uv2, uv3, element, material, scene ) {
  4510. _this.info.render.vertices += 3;
  4511. _this.info.render.faces ++;
  4512. setOpacity( material.opacity );
  4513. setBlending( material.blending );
  4514. _v1x = v1.positionScreen.x; _v1y = v1.positionScreen.y;
  4515. _v2x = v2.positionScreen.x; _v2y = v2.positionScreen.y;
  4516. _v3x = v3.positionScreen.x; _v3y = v3.positionScreen.y;
  4517. drawTriangle( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y );
  4518. if ( material instanceof THREE.MeshBasicMaterial ) {
  4519. if ( material.map/* && !material.wireframe*/ ) {
  4520. if ( material.map.mapping instanceof THREE.UVMapping ) {
  4521. _uvs = element.uvs[ 0 ];
  4522. patternPath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _uvs[ uv1 ].u, _uvs[ uv1 ].v, _uvs[ uv2 ].u, _uvs[ uv2 ].v, _uvs[ uv3 ].u, _uvs[ uv3 ].v, material.map );
  4523. }
  4524. } else if ( material.envMap ) {
  4525. if ( material.envMap.mapping instanceof THREE.SphericalReflectionMapping ) {
  4526. var cameraMatrix = camera.matrixWorldInverse;
  4527. _vector3.copy( element.vertexNormalsWorld[ uv1 ] );
  4528. _uv1x = ( _vector3.x * cameraMatrix.elements[0] + _vector3.y * cameraMatrix.elements[4] + _vector3.z * cameraMatrix.elements[8] ) * 0.5 + 0.5;
  4529. _uv1y = - ( _vector3.x * cameraMatrix.elements[1] + _vector3.y * cameraMatrix.elements[5] + _vector3.z * cameraMatrix.elements[9] ) * 0.5 + 0.5;
  4530. _vector3.copy( element.vertexNormalsWorld[ uv2 ] );
  4531. _uv2x = ( _vector3.x * cameraMatrix.elements[0] + _vector3.y * cameraMatrix.elements[4] + _vector3.z * cameraMatrix.elements[8] ) * 0.5 + 0.5;
  4532. _uv2y = - ( _vector3.x * cameraMatrix.elements[1] + _vector3.y * cameraMatrix.elements[5] + _vector3.z * cameraMatrix.elements[9] ) * 0.5 + 0.5;
  4533. _vector3.copy( element.vertexNormalsWorld[ uv3 ] );
  4534. _uv3x = ( _vector3.x * cameraMatrix.elements[0] + _vector3.y * cameraMatrix.elements[4] + _vector3.z * cameraMatrix.elements[8] ) * 0.5 + 0.5;
  4535. _uv3y = - ( _vector3.x * cameraMatrix.elements[1] + _vector3.y * cameraMatrix.elements[5] + _vector3.z * cameraMatrix.elements[9] ) * 0.5 + 0.5;
  4536. patternPath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _uv1x, _uv1y, _uv2x, _uv2y, _uv3x, _uv3y, material.envMap );
  4537. }/* else if ( material.envMap.mapping == THREE.SphericalRefractionMapping ) {
  4538. }*/
  4539. } else {
  4540. material.wireframe ? strokePath( material.color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( material.color );
  4541. }
  4542. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  4543. if ( material.map && !material.wireframe ) {
  4544. if ( material.map.mapping instanceof THREE.UVMapping ) {
  4545. _uvs = element.uvs[ 0 ];
  4546. patternPath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _uvs[ uv1 ].u, _uvs[ uv1 ].v, _uvs[ uv2 ].u, _uvs[ uv2 ].v, _uvs[ uv3 ].u, _uvs[ uv3 ].v, material.map );
  4547. }
  4548. setBlending( THREE.SubtractiveBlending );
  4549. }
  4550. if ( _enableLighting ) {
  4551. if ( !material.wireframe && material.shading == THREE.SmoothShading && element.vertexNormalsWorld.length == 3 ) {
  4552. _color1.r = _color2.r = _color3.r = _ambientLight.r;
  4553. _color1.g = _color2.g = _color3.g = _ambientLight.g;
  4554. _color1.b = _color2.b = _color3.b = _ambientLight.b;
  4555. calculateLight( _lights, element.v1.positionWorld, element.vertexNormalsWorld[ 0 ], _color1 );
  4556. calculateLight( _lights, element.v2.positionWorld, element.vertexNormalsWorld[ 1 ], _color2 );
  4557. calculateLight( _lights, element.v3.positionWorld, element.vertexNormalsWorld[ 2 ], _color3 );
  4558. _color1.r = Math.max( 0, Math.min( material.color.r * _color1.r, 1 ) );
  4559. _color1.g = Math.max( 0, Math.min( material.color.g * _color1.g, 1 ) );
  4560. _color1.b = Math.max( 0, Math.min( material.color.b * _color1.b, 1 ) );
  4561. _color2.r = Math.max( 0, Math.min( material.color.r * _color2.r, 1 ) );
  4562. _color2.g = Math.max( 0, Math.min( material.color.g * _color2.g, 1 ) );
  4563. _color2.b = Math.max( 0, Math.min( material.color.b * _color2.b, 1 ) );
  4564. _color3.r = Math.max( 0, Math.min( material.color.r * _color3.r, 1 ) );
  4565. _color3.g = Math.max( 0, Math.min( material.color.g * _color3.g, 1 ) );
  4566. _color3.b = Math.max( 0, Math.min( material.color.b * _color3.b, 1 ) );
  4567. _color4.r = ( _color2.r + _color3.r ) * 0.5;
  4568. _color4.g = ( _color2.g + _color3.g ) * 0.5;
  4569. _color4.b = ( _color2.b + _color3.b ) * 0.5;
  4570. _image = getGradientTexture( _color1, _color2, _color3, _color4 );
  4571. clipImage( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, 0, 0, 1, 0, 0, 1, _image );
  4572. } else {
  4573. _color.r = _ambientLight.r;
  4574. _color.g = _ambientLight.g;
  4575. _color.b = _ambientLight.b;
  4576. calculateLight( _lights, element.centroidWorld, element.normalWorld, _color );
  4577. _color.r = Math.max( 0, Math.min( material.color.r * _color.r, 1 ) );
  4578. _color.g = Math.max( 0, Math.min( material.color.g * _color.g, 1 ) );
  4579. _color.b = Math.max( 0, Math.min( material.color.b * _color.b, 1 ) );
  4580. material.wireframe ? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( _color );
  4581. }
  4582. } else {
  4583. material.wireframe ? strokePath( material.color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( material.color );
  4584. }
  4585. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  4586. _near = camera.near;
  4587. _far = camera.far;
  4588. _color1.r = _color1.g = _color1.b = 1 - smoothstep( v1.positionScreen.z, _near, _far );
  4589. _color2.r = _color2.g = _color2.b = 1 - smoothstep( v2.positionScreen.z, _near, _far );
  4590. _color3.r = _color3.g = _color3.b = 1 - smoothstep( v3.positionScreen.z, _near, _far );
  4591. _color4.r = ( _color2.r + _color3.r ) * 0.5;
  4592. _color4.g = ( _color2.g + _color3.g ) * 0.5;
  4593. _color4.b = ( _color2.b + _color3.b ) * 0.5;
  4594. _image = getGradientTexture( _color1, _color2, _color3, _color4 );
  4595. clipImage( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, 0, 0, 1, 0, 0, 1, _image );
  4596. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  4597. _color.r = normalToComponent( element.normalWorld.x );
  4598. _color.g = normalToComponent( element.normalWorld.y );
  4599. _color.b = normalToComponent( element.normalWorld.z );
  4600. material.wireframe ? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( _color );
  4601. }
  4602. }
  4603. function renderFace4( v1, v2, v3, v4, v5, v6, element, material, scene ) {
  4604. _this.info.render.vertices += 4;
  4605. _this.info.render.faces ++;
  4606. setOpacity( material.opacity );
  4607. setBlending( material.blending );
  4608. if ( material.map || material.envMap ) {
  4609. // Let renderFace3() handle this
  4610. renderFace3( v1, v2, v4, 0, 1, 3, element, material, scene );
  4611. renderFace3( v5, v3, v6, 1, 2, 3, element, material, scene );
  4612. return;
  4613. }
  4614. _v1x = v1.positionScreen.x; _v1y = v1.positionScreen.y;
  4615. _v2x = v2.positionScreen.x; _v2y = v2.positionScreen.y;
  4616. _v3x = v3.positionScreen.x; _v3y = v3.positionScreen.y;
  4617. _v4x = v4.positionScreen.x; _v4y = v4.positionScreen.y;
  4618. _v5x = v5.positionScreen.x; _v5y = v5.positionScreen.y;
  4619. _v6x = v6.positionScreen.x; _v6y = v6.positionScreen.y;
  4620. if ( material instanceof THREE.MeshBasicMaterial ) {
  4621. drawQuad( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _v4x, _v4y );
  4622. material.wireframe ? strokePath( material.color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( material.color );
  4623. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  4624. if ( _enableLighting ) {
  4625. if ( !material.wireframe && material.shading == THREE.SmoothShading && element.vertexNormalsWorld.length == 4 ) {
  4626. _color1.r = _color2.r = _color3.r = _color4.r = _ambientLight.r;
  4627. _color1.g = _color2.g = _color3.g = _color4.g = _ambientLight.g;
  4628. _color1.b = _color2.b = _color3.b = _color4.b = _ambientLight.b;
  4629. calculateLight( _lights, element.v1.positionWorld, element.vertexNormalsWorld[ 0 ], _color1 );
  4630. calculateLight( _lights, element.v2.positionWorld, element.vertexNormalsWorld[ 1 ], _color2 );
  4631. calculateLight( _lights, element.v4.positionWorld, element.vertexNormalsWorld[ 3 ], _color3 );
  4632. calculateLight( _lights, element.v3.positionWorld, element.vertexNormalsWorld[ 2 ], _color4 );
  4633. _color1.r = Math.max( 0, Math.min( material.color.r * _color1.r, 1 ) );
  4634. _color1.g = Math.max( 0, Math.min( material.color.g * _color1.g, 1 ) );
  4635. _color1.b = Math.max( 0, Math.min( material.color.b * _color1.b, 1 ) );
  4636. _color2.r = Math.max( 0, Math.min( material.color.r * _color2.r, 1 ) );
  4637. _color2.g = Math.max( 0, Math.min( material.color.g * _color2.g, 1 ) );
  4638. _color2.b = Math.max( 0, Math.min( material.color.b * _color2.b, 1 ) );
  4639. _color3.r = Math.max( 0, Math.min( material.color.r * _color3.r, 1 ) );
  4640. _color3.g = Math.max( 0, Math.min( material.color.g * _color3.g, 1 ) );
  4641. _color3.b = Math.max( 0, Math.min( material.color.b * _color3.b, 1 ) );
  4642. _color4.r = Math.max( 0, Math.min( material.color.r * _color4.r, 1 ) );
  4643. _color4.g = Math.max( 0, Math.min( material.color.g * _color4.g, 1 ) );
  4644. _color4.b = Math.max( 0, Math.min( material.color.b * _color4.b, 1 ) );
  4645. _image = getGradientTexture( _color1, _color2, _color3, _color4 );
  4646. // TODO: UVs are incorrect, v4->v3?
  4647. drawTriangle( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y );
  4648. clipImage( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y, 0, 0, 1, 0, 0, 1, _image );
  4649. drawTriangle( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y );
  4650. clipImage( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y, 1, 0, 1, 1, 0, 1, _image );
  4651. } else {
  4652. _color.r = _ambientLight.r;
  4653. _color.g = _ambientLight.g;
  4654. _color.b = _ambientLight.b;
  4655. calculateLight( _lights, element.centroidWorld, element.normalWorld, _color );
  4656. _color.r = Math.max( 0, Math.min( material.color.r * _color.r, 1 ) );
  4657. _color.g = Math.max( 0, Math.min( material.color.g * _color.g, 1 ) );
  4658. _color.b = Math.max( 0, Math.min( material.color.b * _color.b, 1 ) );
  4659. drawQuad( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _v4x, _v4y );
  4660. material.wireframe ? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( _color );
  4661. }
  4662. } else {
  4663. drawQuad( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _v4x, _v4y );
  4664. material.wireframe ? strokePath( material.color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( material.color );
  4665. }
  4666. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  4667. _color.r = normalToComponent( element.normalWorld.x );
  4668. _color.g = normalToComponent( element.normalWorld.y );
  4669. _color.b = normalToComponent( element.normalWorld.z );
  4670. drawQuad( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _v4x, _v4y );
  4671. material.wireframe ? strokePath( _color, material.wireframeLinewidth, material.wireframeLinecap, material.wireframeLinejoin ) : fillPath( _color );
  4672. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  4673. _near = camera.near;
  4674. _far = camera.far;
  4675. _color1.r = _color1.g = _color1.b = 1 - smoothstep( v1.positionScreen.z, _near, _far );
  4676. _color2.r = _color2.g = _color2.b = 1 - smoothstep( v2.positionScreen.z, _near, _far );
  4677. _color3.r = _color3.g = _color3.b = 1 - smoothstep( v4.positionScreen.z, _near, _far );
  4678. _color4.r = _color4.g = _color4.b = 1 - smoothstep( v3.positionScreen.z, _near, _far );
  4679. _image = getGradientTexture( _color1, _color2, _color3, _color4 );
  4680. // TODO: UVs are incorrect, v4->v3?
  4681. drawTriangle( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y );
  4682. clipImage( _v1x, _v1y, _v2x, _v2y, _v4x, _v4y, 0, 0, 1, 0, 0, 1, _image );
  4683. drawTriangle( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y );
  4684. clipImage( _v5x, _v5y, _v3x, _v3y, _v6x, _v6y, 1, 0, 1, 1, 0, 1, _image );
  4685. }
  4686. }
  4687. //
  4688. function drawTriangle( x0, y0, x1, y1, x2, y2 ) {
  4689. _context.beginPath();
  4690. _context.moveTo( x0, y0 );
  4691. _context.lineTo( x1, y1 );
  4692. _context.lineTo( x2, y2 );
  4693. _context.lineTo( x0, y0 );
  4694. _context.closePath();
  4695. }
  4696. function drawQuad( x0, y0, x1, y1, x2, y2, x3, y3 ) {
  4697. _context.beginPath();
  4698. _context.moveTo( x0, y0 );
  4699. _context.lineTo( x1, y1 );
  4700. _context.lineTo( x2, y2 );
  4701. _context.lineTo( x3, y3 );
  4702. _context.lineTo( x0, y0 );
  4703. _context.closePath();
  4704. }
  4705. function strokePath( color, linewidth, linecap, linejoin ) {
  4706. setLineWidth( linewidth );
  4707. setLineCap( linecap );
  4708. setLineJoin( linejoin );
  4709. setStrokeStyle( color.getContextStyle() );
  4710. _context.stroke();
  4711. _bboxRect.inflate( linewidth * 2 );
  4712. }
  4713. function fillPath( color ) {
  4714. setFillStyle( color.getContextStyle() );
  4715. _context.fill();
  4716. }
  4717. function patternPath( x0, y0, x1, y1, x2, y2, u0, v0, u1, v1, u2, v2, texture ) {
  4718. if ( texture.image.width == 0 ) return;
  4719. if ( texture.needsUpdate == true || _patterns[ texture.id ] == undefined ) {
  4720. var repeatX = texture.wrapS == THREE.RepeatWrapping;
  4721. var repeatY = texture.wrapT == THREE.RepeatWrapping;
  4722. _patterns[ texture.id ] = _context.createPattern( texture.image, repeatX && repeatY ? 'repeat' : repeatX && !repeatY ? 'repeat-x' : !repeatX && repeatY ? 'repeat-y' : 'no-repeat' );
  4723. texture.needsUpdate = false;
  4724. }
  4725. setFillStyle( _patterns[ texture.id ] );
  4726. // http://extremelysatisfactorytotalitarianism.com/blog/?p=2120
  4727. var a, b, c, d, e, f, det, idet,
  4728. offsetX = texture.offset.x / texture.repeat.x,
  4729. offsetY = texture.offset.y / texture.repeat.y,
  4730. width = texture.image.width * texture.repeat.x,
  4731. height = texture.image.height * texture.repeat.y;
  4732. u0 = ( u0 + offsetX ) * width;
  4733. v0 = ( v0 + offsetY ) * height;
  4734. u1 = ( u1 + offsetX ) * width;
  4735. v1 = ( v1 + offsetY ) * height;
  4736. u2 = ( u2 + offsetX ) * width;
  4737. v2 = ( v2 + offsetY ) * height;
  4738. x1 -= x0; y1 -= y0;
  4739. x2 -= x0; y2 -= y0;
  4740. u1 -= u0; v1 -= v0;
  4741. u2 -= u0; v2 -= v0;
  4742. det = u1 * v2 - u2 * v1;
  4743. if ( det == 0 ) {
  4744. if ( _imagedatas[ texture.id ] === undefined ) {
  4745. var canvas = document.createElement( 'canvas' )
  4746. canvas.width = texture.image.width;
  4747. canvas.height = texture.image.height;
  4748. var context = canvas.getContext( '2d' );
  4749. context.drawImage( texture.image, 0, 0 );
  4750. _imagedatas[ texture.id ] = context.getImageData( 0, 0, texture.image.width, texture.image.height ).data;
  4751. // variables cannot be deleted in ES5 strict mode
  4752. //delete canvas;
  4753. }
  4754. var data = _imagedatas[ texture.id ];
  4755. var index = ( Math.floor( u0 ) + Math.floor( v0 ) * texture.image.width ) * 4;
  4756. _color.setRGB( data[ index ] / 255, data[ index + 1 ] / 255, data[ index + 2 ] / 255 );
  4757. fillPath( _color );
  4758. return;
  4759. }
  4760. idet = 1 / det;
  4761. a = ( v2 * x1 - v1 * x2 ) * idet;
  4762. b = ( v2 * y1 - v1 * y2 ) * idet;
  4763. c = ( u1 * x2 - u2 * x1 ) * idet;
  4764. d = ( u1 * y2 - u2 * y1 ) * idet;
  4765. e = x0 - a * u0 - c * v0;
  4766. f = y0 - b * u0 - d * v0;
  4767. _context.save();
  4768. _context.transform( a, b, c, d, e, f );
  4769. _context.fill();
  4770. _context.restore();
  4771. }
  4772. function clipImage( x0, y0, x1, y1, x2, y2, u0, v0, u1, v1, u2, v2, image ) {
  4773. // http://extremelysatisfactorytotalitarianism.com/blog/?p=2120
  4774. var a, b, c, d, e, f, det, idet,
  4775. width = image.width - 1,
  4776. height = image.height - 1;
  4777. u0 *= width; v0 *= height;
  4778. u1 *= width; v1 *= height;
  4779. u2 *= width; v2 *= height;
  4780. x1 -= x0; y1 -= y0;
  4781. x2 -= x0; y2 -= y0;
  4782. u1 -= u0; v1 -= v0;
  4783. u2 -= u0; v2 -= v0;
  4784. det = u1 * v2 - u2 * v1;
  4785. idet = 1 / det;
  4786. a = ( v2 * x1 - v1 * x2 ) * idet;
  4787. b = ( v2 * y1 - v1 * y2 ) * idet;
  4788. c = ( u1 * x2 - u2 * x1 ) * idet;
  4789. d = ( u1 * y2 - u2 * y1 ) * idet;
  4790. e = x0 - a * u0 - c * v0;
  4791. f = y0 - b * u0 - d * v0;
  4792. _context.save();
  4793. _context.transform( a, b, c, d, e, f );
  4794. _context.clip();
  4795. _context.drawImage( image, 0, 0 );
  4796. _context.restore();
  4797. }
  4798. function getGradientTexture( color1, color2, color3, color4 ) {
  4799. // http://mrdoob.com/blog/post/710
  4800. var c1r = ~~ ( color1.r * 255 ), c1g = ~~ ( color1.g * 255 ), c1b = ~~ ( color1.b * 255 ),
  4801. c2r = ~~ ( color2.r * 255 ), c2g = ~~ ( color2.g * 255 ), c2b = ~~ ( color2.b * 255 ),
  4802. c3r = ~~ ( color3.r * 255 ), c3g = ~~ ( color3.g * 255 ), c3b = ~~ ( color3.b * 255 ),
  4803. c4r = ~~ ( color4.r * 255 ), c4g = ~~ ( color4.g * 255 ), c4b = ~~ ( color4.b * 255 );
  4804. _pixelMapData[ 0 ] = c1r < 0 ? 0 : c1r > 255 ? 255 : c1r;
  4805. _pixelMapData[ 1 ] = c1g < 0 ? 0 : c1g > 255 ? 255 : c1g;
  4806. _pixelMapData[ 2 ] = c1b < 0 ? 0 : c1b > 255 ? 255 : c1b;
  4807. _pixelMapData[ 4 ] = c2r < 0 ? 0 : c2r > 255 ? 255 : c2r;
  4808. _pixelMapData[ 5 ] = c2g < 0 ? 0 : c2g > 255 ? 255 : c2g;
  4809. _pixelMapData[ 6 ] = c2b < 0 ? 0 : c2b > 255 ? 255 : c2b;
  4810. _pixelMapData[ 8 ] = c3r < 0 ? 0 : c3r > 255 ? 255 : c3r;
  4811. _pixelMapData[ 9 ] = c3g < 0 ? 0 : c3g > 255 ? 255 : c3g;
  4812. _pixelMapData[ 10 ] = c3b < 0 ? 0 : c3b > 255 ? 255 : c3b;
  4813. _pixelMapData[ 12 ] = c4r < 0 ? 0 : c4r > 255 ? 255 : c4r;
  4814. _pixelMapData[ 13 ] = c4g < 0 ? 0 : c4g > 255 ? 255 : c4g;
  4815. _pixelMapData[ 14 ] = c4b < 0 ? 0 : c4b > 255 ? 255 : c4b;
  4816. _pixelMapContext.putImageData( _pixelMapImage, 0, 0 );
  4817. _gradientMapContext.drawImage( _pixelMap, 0, 0 );
  4818. return _gradientMap;
  4819. }
  4820. function smoothstep( value, min, max ) {
  4821. var x = ( value - min ) / ( max - min );
  4822. return x * x * ( 3 - 2 * x );
  4823. }
  4824. function normalToComponent( normal ) {
  4825. var component = ( normal + 1 ) * 0.5;
  4826. return component < 0 ? 0 : ( component > 1 ? 1 : component );
  4827. }
  4828. // Hide anti-alias gaps
  4829. function expand( v1, v2 ) {
  4830. var x = v2.x - v1.x, y = v2.y - v1.y,
  4831. det = x * x + y * y, idet;
  4832. if ( det == 0 ) return;
  4833. idet = 1 / Math.sqrt( det );
  4834. x *= idet; y *= idet;
  4835. v2.x += x; v2.y += y;
  4836. v1.x -= x; v1.y -= y;
  4837. }
  4838. };
  4839. // Context cached methods.
  4840. function setOpacity( value ) {
  4841. if ( _contextGlobalAlpha != value ) {
  4842. _context.globalAlpha = _contextGlobalAlpha = value;
  4843. }
  4844. }
  4845. function setBlending( value ) {
  4846. if ( _contextGlobalCompositeOperation != value ) {
  4847. switch ( value ) {
  4848. case THREE.NormalBlending:
  4849. _context.globalCompositeOperation = 'source-over';
  4850. break;
  4851. case THREE.AdditiveBlending:
  4852. _context.globalCompositeOperation = 'lighter';
  4853. break;
  4854. case THREE.SubtractiveBlending:
  4855. _context.globalCompositeOperation = 'darker';
  4856. break;
  4857. }
  4858. _contextGlobalCompositeOperation = value;
  4859. }
  4860. }
  4861. function setLineWidth( value ) {
  4862. if ( _contextLineWidth != value ) {
  4863. _context.lineWidth = _contextLineWidth = value;
  4864. }
  4865. }
  4866. function setLineCap( value ) {
  4867. // "butt", "round", "square"
  4868. if ( _contextLineCap != value ) {
  4869. _context.lineCap = _contextLineCap = value;
  4870. }
  4871. }
  4872. function setLineJoin( value ) {
  4873. // "round", "bevel", "miter"
  4874. if ( _contextLineJoin != value ) {
  4875. _context.lineJoin = _contextLineJoin = value;
  4876. }
  4877. }
  4878. function setStrokeStyle( style ) {
  4879. if ( _contextStrokeStyle != style ) {
  4880. _context.strokeStyle = _contextStrokeStyle = style;
  4881. }
  4882. }
  4883. function setFillStyle( style ) {
  4884. if ( _contextFillStyle != style ) {
  4885. _context.fillStyle = _contextFillStyle = style;
  4886. }
  4887. }
  4888. };
  4889. /**
  4890. * @author mr.doob / http://mrdoob.com/
  4891. */
  4892. THREE.SVGRenderer = function () {
  4893. console.log( 'THREE.SVGRenderer', THREE.REVISION );
  4894. var _this = this,
  4895. _renderData, _elements, _lights,
  4896. _projector = new THREE.Projector(),
  4897. _svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'),
  4898. _svgWidth, _svgHeight, _svgWidthHalf, _svgHeightHalf,
  4899. _v1, _v2, _v3, _v4,
  4900. _clipRect = new THREE.Rectangle(),
  4901. _bboxRect = new THREE.Rectangle(),
  4902. _enableLighting = false,
  4903. _color = new THREE.Color(),
  4904. _ambientLight = new THREE.Color(),
  4905. _directionalLights = new THREE.Color(),
  4906. _pointLights = new THREE.Color(),
  4907. _w, // z-buffer to w-buffer
  4908. _vector3 = new THREE.Vector3(), // Needed for PointLight
  4909. _svgPathPool = [], _svgCirclePool = [], _svgLinePool = [],
  4910. _svgNode, _pathCount, _circleCount, _lineCount,
  4911. _quality = 1;
  4912. this.domElement = _svg;
  4913. this.autoClear = true;
  4914. this.sortObjects = true;
  4915. this.sortElements = true;
  4916. this.info = {
  4917. render: {
  4918. vertices: 0,
  4919. faces: 0
  4920. }
  4921. }
  4922. this.setQuality = function( quality ) {
  4923. switch(quality) {
  4924. case "high": _quality = 1; break;
  4925. case "low": _quality = 0; break;
  4926. }
  4927. };
  4928. this.setSize = function( width, height ) {
  4929. _svgWidth = width; _svgHeight = height;
  4930. _svgWidthHalf = _svgWidth / 2; _svgHeightHalf = _svgHeight / 2;
  4931. _svg.setAttribute( 'viewBox', ( - _svgWidthHalf ) + ' ' + ( - _svgHeightHalf ) + ' ' + _svgWidth + ' ' + _svgHeight );
  4932. _svg.setAttribute( 'width', _svgWidth );
  4933. _svg.setAttribute( 'height', _svgHeight );
  4934. _clipRect.set( - _svgWidthHalf, - _svgHeightHalf, _svgWidthHalf, _svgHeightHalf );
  4935. };
  4936. this.clear = function () {
  4937. while ( _svg.childNodes.length > 0 ) {
  4938. _svg.removeChild( _svg.childNodes[ 0 ] );
  4939. }
  4940. };
  4941. this.render = function ( scene, camera ) {
  4942. var e, el, element, material;
  4943. this.autoClear && this.clear();
  4944. _this.info.render.vertices = 0;
  4945. _this.info.render.faces = 0;
  4946. _renderData = _projector.projectScene( scene, camera, this.sortElements );
  4947. _elements = _renderData.elements;
  4948. _lights = _renderData.lights;
  4949. _pathCount = 0; _circleCount = 0; _lineCount = 0;
  4950. _enableLighting = _lights.length > 0;
  4951. if ( _enableLighting ) {
  4952. calculateLights( _lights );
  4953. }
  4954. for ( e = 0, el = _elements.length; e < el; e ++ ) {
  4955. element = _elements[ e ];
  4956. material = element.material;
  4957. material = material instanceof THREE.MeshFaceMaterial ? element.faceMaterial : material;
  4958. if ( material == null || material.opacity == 0 ) continue;
  4959. _bboxRect.empty();
  4960. if ( element instanceof THREE.RenderableParticle ) {
  4961. _v1 = element;
  4962. _v1.x *= _svgWidthHalf; _v1.y *= -_svgHeightHalf;
  4963. renderParticle( _v1, element, material, scene );
  4964. } else if ( element instanceof THREE.RenderableLine ) {
  4965. _v1 = element.v1; _v2 = element.v2;
  4966. _v1.positionScreen.x *= _svgWidthHalf; _v1.positionScreen.y *= - _svgHeightHalf;
  4967. _v2.positionScreen.x *= _svgWidthHalf; _v2.positionScreen.y *= - _svgHeightHalf;
  4968. _bboxRect.addPoint( _v1.positionScreen.x, _v1.positionScreen.y );
  4969. _bboxRect.addPoint( _v2.positionScreen.x, _v2.positionScreen.y );
  4970. if ( !_clipRect.intersects( _bboxRect ) ) {
  4971. continue;
  4972. }
  4973. renderLine( _v1, _v2, element, material, scene );
  4974. } else if ( element instanceof THREE.RenderableFace3 ) {
  4975. _v1 = element.v1; _v2 = element.v2; _v3 = element.v3;
  4976. _v1.positionScreen.x *= _svgWidthHalf; _v1.positionScreen.y *= - _svgHeightHalf;
  4977. _v2.positionScreen.x *= _svgWidthHalf; _v2.positionScreen.y *= - _svgHeightHalf;
  4978. _v3.positionScreen.x *= _svgWidthHalf; _v3.positionScreen.y *= - _svgHeightHalf;
  4979. _bboxRect.addPoint( _v1.positionScreen.x, _v1.positionScreen.y );
  4980. _bboxRect.addPoint( _v2.positionScreen.x, _v2.positionScreen.y );
  4981. _bboxRect.addPoint( _v3.positionScreen.x, _v3.positionScreen.y );
  4982. if ( !_clipRect.intersects( _bboxRect ) ) {
  4983. continue;
  4984. }
  4985. renderFace3( _v1, _v2, _v3, element, material, scene );
  4986. } else if ( element instanceof THREE.RenderableFace4 ) {
  4987. _v1 = element.v1; _v2 = element.v2; _v3 = element.v3; _v4 = element.v4;
  4988. _v1.positionScreen.x *= _svgWidthHalf; _v1.positionScreen.y *= -_svgHeightHalf;
  4989. _v2.positionScreen.x *= _svgWidthHalf; _v2.positionScreen.y *= -_svgHeightHalf;
  4990. _v3.positionScreen.x *= _svgWidthHalf; _v3.positionScreen.y *= -_svgHeightHalf;
  4991. _v4.positionScreen.x *= _svgWidthHalf; _v4.positionScreen.y *= -_svgHeightHalf;
  4992. _bboxRect.addPoint( _v1.positionScreen.x, _v1.positionScreen.y );
  4993. _bboxRect.addPoint( _v2.positionScreen.x, _v2.positionScreen.y );
  4994. _bboxRect.addPoint( _v3.positionScreen.x, _v3.positionScreen.y );
  4995. _bboxRect.addPoint( _v4.positionScreen.x, _v4.positionScreen.y );
  4996. if ( !_clipRect.intersects( _bboxRect) ) {
  4997. continue;
  4998. }
  4999. renderFace4( _v1, _v2, _v3, _v4, element, material, scene );
  5000. }
  5001. }
  5002. };
  5003. function calculateLights( lights ) {
  5004. var l, ll, light, lightColor;
  5005. _ambientLight.setRGB( 0, 0, 0 );
  5006. _directionalLights.setRGB( 0, 0, 0 );
  5007. _pointLights.setRGB( 0, 0, 0 );
  5008. for ( l = 0, ll = lights.length; l < ll; l++ ) {
  5009. light = lights[ l ];
  5010. lightColor = light.color;
  5011. if ( light instanceof THREE.AmbientLight ) {
  5012. _ambientLight.r += lightColor.r;
  5013. _ambientLight.g += lightColor.g;
  5014. _ambientLight.b += lightColor.b;
  5015. } else if ( light instanceof THREE.DirectionalLight ) {
  5016. _directionalLights.r += lightColor.r;
  5017. _directionalLights.g += lightColor.g;
  5018. _directionalLights.b += lightColor.b;
  5019. } else if ( light instanceof THREE.PointLight ) {
  5020. _pointLights.r += lightColor.r;
  5021. _pointLights.g += lightColor.g;
  5022. _pointLights.b += lightColor.b;
  5023. }
  5024. }
  5025. }
  5026. function calculateLight( lights, position, normal, color ) {
  5027. var l, ll, light, lightColor, lightPosition, amount;
  5028. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  5029. light = lights[ l ];
  5030. lightColor = light.color;
  5031. if ( light instanceof THREE.DirectionalLight ) {
  5032. lightPosition = light.matrixWorld.getPosition();
  5033. amount = normal.dot( lightPosition );
  5034. if ( amount <= 0 ) continue;
  5035. amount *= light.intensity;
  5036. color.r += lightColor.r * amount;
  5037. color.g += lightColor.g * amount;
  5038. color.b += lightColor.b * amount;
  5039. } else if ( light instanceof THREE.PointLight ) {
  5040. lightPosition = light.matrixWorld.getPosition();
  5041. amount = normal.dot( _vector3.sub( lightPosition, position ).normalize() );
  5042. if ( amount <= 0 ) continue;
  5043. amount *= light.distance == 0 ? 1 : 1 - Math.min( position.distanceTo( lightPosition ) / light.distance, 1 );
  5044. if ( amount == 0 ) continue;
  5045. amount *= light.intensity;
  5046. color.r += lightColor.r * amount;
  5047. color.g += lightColor.g * amount;
  5048. color.b += lightColor.b * amount;
  5049. }
  5050. }
  5051. }
  5052. function renderParticle( v1, element, material, scene ) {
  5053. /*
  5054. _svgNode = getCircleNode( _circleCount++ );
  5055. _svgNode.setAttribute( 'cx', v1.x );
  5056. _svgNode.setAttribute( 'cy', v1.y );
  5057. _svgNode.setAttribute( 'r', element.scale.x * _svgWidthHalf );
  5058. if ( material instanceof THREE.ParticleCircleMaterial ) {
  5059. if ( _enableLighting ) {
  5060. _color.r = _ambientLight.r + _directionalLights.r + _pointLights.r;
  5061. _color.g = _ambientLight.g + _directionalLights.g + _pointLights.g;
  5062. _color.b = _ambientLight.b + _directionalLights.b + _pointLights.b;
  5063. _color.r = material.color.r * _color.r;
  5064. _color.g = material.color.g * _color.g;
  5065. _color.b = material.color.b * _color.b;
  5066. _color.updateStyleString();
  5067. } else {
  5068. _color = material.color;
  5069. }
  5070. _svgNode.setAttribute( 'style', 'fill: ' + _color.__styleString );
  5071. }
  5072. _svg.appendChild( _svgNode );
  5073. */
  5074. }
  5075. function renderLine ( v1, v2, element, material, scene ) {
  5076. _svgNode = getLineNode( _lineCount ++ );
  5077. _svgNode.setAttribute( 'x1', v1.positionScreen.x );
  5078. _svgNode.setAttribute( 'y1', v1.positionScreen.y );
  5079. _svgNode.setAttribute( 'x2', v2.positionScreen.x );
  5080. _svgNode.setAttribute( 'y2', v2.positionScreen.y );
  5081. if ( material instanceof THREE.LineBasicMaterial ) {
  5082. _svgNode.setAttribute( 'style', 'fill: none; stroke: ' + material.color.getContextStyle() + '; stroke-width: ' + material.linewidth + '; stroke-opacity: ' + material.opacity + '; stroke-linecap: ' + material.linecap + '; stroke-linejoin: ' + material.linejoin );
  5083. _svg.appendChild( _svgNode );
  5084. }
  5085. }
  5086. function renderFace3( v1, v2, v3, element, material, scene ) {
  5087. _this.info.render.vertices += 3;
  5088. _this.info.render.faces ++;
  5089. _svgNode = getPathNode( _pathCount ++ );
  5090. _svgNode.setAttribute( 'd', 'M ' + v1.positionScreen.x + ' ' + v1.positionScreen.y + ' L ' + v2.positionScreen.x + ' ' + v2.positionScreen.y + ' L ' + v3.positionScreen.x + ',' + v3.positionScreen.y + 'z' );
  5091. if ( material instanceof THREE.MeshBasicMaterial ) {
  5092. _color.copy( material.color );
  5093. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  5094. if ( _enableLighting ) {
  5095. _color.r = _ambientLight.r;
  5096. _color.g = _ambientLight.g;
  5097. _color.b = _ambientLight.b;
  5098. calculateLight( _lights, element.centroidWorld, element.normalWorld, _color );
  5099. _color.r = Math.max( 0, Math.min( material.color.r * _color.r, 1 ) );
  5100. _color.g = Math.max( 0, Math.min( material.color.g * _color.g, 1 ) );
  5101. _color.b = Math.max( 0, Math.min( material.color.b * _color.b, 1 ) );
  5102. } else {
  5103. _color.copy( material.color );
  5104. }
  5105. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  5106. _w = 1 - ( material.__2near / (material.__farPlusNear - element.z * material.__farMinusNear) );
  5107. _color.setRGB( _w, _w, _w );
  5108. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  5109. _color.setRGB( normalToComponent( element.normalWorld.x ), normalToComponent( element.normalWorld.y ), normalToComponent( element.normalWorld.z ) );
  5110. }
  5111. if ( material.wireframe ) {
  5112. _svgNode.setAttribute( 'style', 'fill: none; stroke: ' + _color.getContextStyle() + '; stroke-width: ' + material.wireframeLinewidth + '; stroke-opacity: ' + material.opacity + '; stroke-linecap: ' + material.wireframeLinecap + '; stroke-linejoin: ' + material.wireframeLinejoin );
  5113. } else {
  5114. _svgNode.setAttribute( 'style', 'fill: ' + _color.getContextStyle() + '; fill-opacity: ' + material.opacity );
  5115. }
  5116. _svg.appendChild( _svgNode );
  5117. }
  5118. function renderFace4( v1, v2, v3, v4, element, material, scene ) {
  5119. _this.info.render.vertices += 4;
  5120. _this.info.render.faces ++;
  5121. _svgNode = getPathNode( _pathCount ++ );
  5122. _svgNode.setAttribute( 'd', 'M ' + v1.positionScreen.x + ' ' + v1.positionScreen.y + ' L ' + v2.positionScreen.x + ' ' + v2.positionScreen.y + ' L ' + v3.positionScreen.x + ',' + v3.positionScreen.y + ' L ' + v4.positionScreen.x + ',' + v4.positionScreen.y + 'z' );
  5123. if ( material instanceof THREE.MeshBasicMaterial ) {
  5124. _color.copy( material.color );
  5125. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  5126. if ( _enableLighting ) {
  5127. _color.r = _ambientLight.r;
  5128. _color.g = _ambientLight.g;
  5129. _color.b = _ambientLight.b;
  5130. calculateLight( _lights, element.centroidWorld, element.normalWorld, _color );
  5131. _color.r = Math.max( 0, Math.min( material.color.r * _color.r, 1 ) );
  5132. _color.g = Math.max( 0, Math.min( material.color.g * _color.g, 1 ) );
  5133. _color.b = Math.max( 0, Math.min( material.color.b * _color.b, 1 ) );
  5134. } else {
  5135. _color.copy( material.color );
  5136. }
  5137. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  5138. _w = 1 - ( material.__2near / (material.__farPlusNear - element.z * material.__farMinusNear) );
  5139. _color.setRGB( _w, _w, _w );
  5140. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  5141. _color.setRGB( normalToComponent( element.normalWorld.x ), normalToComponent( element.normalWorld.y ), normalToComponent( element.normalWorld.z ) );
  5142. }
  5143. if ( material.wireframe ) {
  5144. _svgNode.setAttribute( 'style', 'fill: none; stroke: ' + _color.getContextStyle() + '; stroke-width: ' + material.wireframeLinewidth + '; stroke-opacity: ' + material.opacity + '; stroke-linecap: ' + material.wireframeLinecap + '; stroke-linejoin: ' + material.wireframeLinejoin );
  5145. } else {
  5146. _svgNode.setAttribute( 'style', 'fill: ' + _color.getContextStyle() + '; fill-opacity: ' + material.opacity );
  5147. }
  5148. _svg.appendChild( _svgNode );
  5149. }
  5150. function getLineNode( id ) {
  5151. if ( _svgLinePool[ id ] == null ) {
  5152. _svgLinePool[ id ] = document.createElementNS( 'http://www.w3.org/2000/svg', 'line' );
  5153. if ( _quality == 0 ) {
  5154. _svgLinePool[ id ].setAttribute( 'shape-rendering', 'crispEdges' ); //optimizeSpeed
  5155. }
  5156. return _svgLinePool[ id ];
  5157. }
  5158. return _svgLinePool[ id ];
  5159. }
  5160. function getPathNode( id ) {
  5161. if ( _svgPathPool[ id ] == null ) {
  5162. _svgPathPool[ id ] = document.createElementNS( 'http://www.w3.org/2000/svg', 'path' );
  5163. if ( _quality == 0 ) {
  5164. _svgPathPool[ id ].setAttribute( 'shape-rendering', 'crispEdges' ); //optimizeSpeed
  5165. }
  5166. return _svgPathPool[ id ];
  5167. }
  5168. return _svgPathPool[ id ];
  5169. }
  5170. function getCircleNode( id ) {
  5171. if ( _svgCirclePool[id] == null ) {
  5172. _svgCirclePool[ id ] = document.createElementNS( 'http://www.w3.org/2000/svg', 'circle' );
  5173. if ( _quality == 0 ) {
  5174. _svgCirclePool[id].setAttribute( 'shape-rendering', 'crispEdges' ); //optimizeSpeed
  5175. }
  5176. return _svgCirclePool[ id ];
  5177. }
  5178. return _svgCirclePool[ id ];
  5179. }
  5180. function normalToComponent( normal ) {
  5181. var component = ( normal + 1 ) * 0.5;
  5182. return component < 0 ? 0 : ( component > 1 ? 1 : component );
  5183. }
  5184. function pad( str ) {
  5185. while ( str.length < 6 ) str = '0' + str;
  5186. return str;
  5187. }
  5188. };
  5189. /**
  5190. * @author alteredq / http://alteredqualia.com/
  5191. * @author mrdoob / http://mrdoob.com/
  5192. * @author mikael emtinger / http://gomo.se/
  5193. */
  5194. THREE.ShaderChunk = {
  5195. // FOG
  5196. fog_pars_fragment: [
  5197. "#ifdef USE_FOG",
  5198. "uniform vec3 fogColor;",
  5199. "#ifdef FOG_EXP2",
  5200. "uniform float fogDensity;",
  5201. "#else",
  5202. "uniform float fogNear;",
  5203. "uniform float fogFar;",
  5204. "#endif",
  5205. "#endif"
  5206. ].join("\n"),
  5207. fog_fragment: [
  5208. "#ifdef USE_FOG",
  5209. "float depth = gl_FragCoord.z / gl_FragCoord.w;",
  5210. "#ifdef FOG_EXP2",
  5211. "const float LOG2 = 1.442695;",
  5212. "float fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );",
  5213. "fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );",
  5214. "#else",
  5215. "float fogFactor = smoothstep( fogNear, fogFar, depth );",
  5216. "#endif",
  5217. "gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );",
  5218. "#endif"
  5219. ].join("\n"),
  5220. // ENVIRONMENT MAP
  5221. envmap_pars_fragment: [
  5222. "#ifdef USE_ENVMAP",
  5223. "varying vec3 vReflect;",
  5224. "uniform float reflectivity;",
  5225. "uniform samplerCube envMap;",
  5226. "uniform float flipEnvMap;",
  5227. "uniform int combine;",
  5228. "#endif"
  5229. ].join("\n"),
  5230. envmap_fragment: [
  5231. "#ifdef USE_ENVMAP",
  5232. "#ifdef DOUBLE_SIDED",
  5233. "float flipNormal = ( -1.0 + 2.0 * float( gl_FrontFacing ) );",
  5234. "vec4 cubeColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * vReflect.x, vReflect.yz ) );",
  5235. "#else",
  5236. "vec4 cubeColor = textureCube( envMap, vec3( flipEnvMap * vReflect.x, vReflect.yz ) );",
  5237. "#endif",
  5238. "#ifdef GAMMA_INPUT",
  5239. "cubeColor.xyz *= cubeColor.xyz;",
  5240. "#endif",
  5241. "if ( combine == 1 ) {",
  5242. "gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, reflectivity );",
  5243. "} else {",
  5244. "gl_FragColor.xyz = gl_FragColor.xyz * cubeColor.xyz;",
  5245. "}",
  5246. "#endif"
  5247. ].join("\n"),
  5248. envmap_pars_vertex: [
  5249. "#ifdef USE_ENVMAP",
  5250. "varying vec3 vReflect;",
  5251. "uniform float refractionRatio;",
  5252. "uniform bool useRefract;",
  5253. "#endif"
  5254. ].join("\n"),
  5255. envmap_vertex : [
  5256. "#ifdef USE_ENVMAP",
  5257. "vec4 mPosition = objectMatrix * vec4( position, 1.0 );",
  5258. "vec3 nWorld = mat3( objectMatrix[ 0 ].xyz, objectMatrix[ 1 ].xyz, objectMatrix[ 2 ].xyz ) * normal;",
  5259. "if ( useRefract ) {",
  5260. "vReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refractionRatio );",
  5261. "} else {",
  5262. "vReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );",
  5263. "}",
  5264. "#endif"
  5265. ].join("\n"),
  5266. // COLOR MAP (particles)
  5267. map_particle_pars_fragment: [
  5268. "#ifdef USE_MAP",
  5269. "uniform sampler2D map;",
  5270. "#endif"
  5271. ].join("\n"),
  5272. map_particle_fragment: [
  5273. "#ifdef USE_MAP",
  5274. "gl_FragColor = gl_FragColor * texture2D( map, gl_PointCoord );",
  5275. "#endif"
  5276. ].join("\n"),
  5277. // COLOR MAP (triangles)
  5278. map_pars_vertex: [
  5279. "#ifdef USE_MAP",
  5280. "varying vec2 vUv;",
  5281. "uniform vec4 offsetRepeat;",
  5282. "#endif"
  5283. ].join("\n"),
  5284. map_pars_fragment: [
  5285. "#ifdef USE_MAP",
  5286. "varying vec2 vUv;",
  5287. "uniform sampler2D map;",
  5288. "#endif"
  5289. ].join("\n"),
  5290. map_vertex: [
  5291. "#ifdef USE_MAP",
  5292. "vUv = uv * offsetRepeat.zw + offsetRepeat.xy;",
  5293. "#endif"
  5294. ].join("\n"),
  5295. map_fragment: [
  5296. "#ifdef USE_MAP",
  5297. "#ifdef GAMMA_INPUT",
  5298. "vec4 texelColor = texture2D( map, vUv );",
  5299. "texelColor.xyz *= texelColor.xyz;",
  5300. "gl_FragColor = gl_FragColor * texelColor;",
  5301. "#else",
  5302. "gl_FragColor = gl_FragColor * texture2D( map, vUv );",
  5303. "#endif",
  5304. "#endif"
  5305. ].join("\n"),
  5306. // LIGHT MAP
  5307. lightmap_pars_fragment: [
  5308. "#ifdef USE_LIGHTMAP",
  5309. "varying vec2 vUv2;",
  5310. "uniform sampler2D lightMap;",
  5311. "#endif"
  5312. ].join("\n"),
  5313. lightmap_pars_vertex: [
  5314. "#ifdef USE_LIGHTMAP",
  5315. "varying vec2 vUv2;",
  5316. "#endif"
  5317. ].join("\n"),
  5318. lightmap_fragment: [
  5319. "#ifdef USE_LIGHTMAP",
  5320. "gl_FragColor = gl_FragColor * texture2D( lightMap, vUv2 );",
  5321. "#endif"
  5322. ].join("\n"),
  5323. lightmap_vertex: [
  5324. "#ifdef USE_LIGHTMAP",
  5325. "vUv2 = uv2;",
  5326. "#endif"
  5327. ].join("\n"),
  5328. // LIGHTS LAMBERT
  5329. lights_lambert_pars_vertex: [
  5330. "uniform vec3 ambient;",
  5331. "uniform vec3 diffuse;",
  5332. "uniform vec3 emissive;",
  5333. "uniform vec3 ambientLightColor;",
  5334. "#if MAX_DIR_LIGHTS > 0",
  5335. "uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];",
  5336. "uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];",
  5337. "#endif",
  5338. "#if MAX_POINT_LIGHTS > 0",
  5339. "uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];",
  5340. "uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];",
  5341. "uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",
  5342. "#endif",
  5343. "#if MAX_SPOT_LIGHTS > 0",
  5344. "uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];",
  5345. "uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];",
  5346. "uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];",
  5347. "uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];",
  5348. "uniform float spotLightAngle[ MAX_SPOT_LIGHTS ];",
  5349. "uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];",
  5350. "#endif",
  5351. "#ifdef WRAP_AROUND",
  5352. "uniform vec3 wrapRGB;",
  5353. "#endif"
  5354. ].join("\n"),
  5355. lights_lambert_vertex: [
  5356. "vLightFront = vec3( 0.0 );",
  5357. "#ifdef DOUBLE_SIDED",
  5358. "vLightBack = vec3( 0.0 );",
  5359. "#endif",
  5360. "transformedNormal = normalize( transformedNormal );",
  5361. "#if MAX_DIR_LIGHTS > 0",
  5362. "for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {",
  5363. "vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );",
  5364. "vec3 dirVector = normalize( lDirection.xyz );",
  5365. "float dotProduct = dot( transformedNormal, dirVector );",
  5366. "vec3 directionalLightWeighting = vec3( max( dotProduct, 0.0 ) );",
  5367. "#ifdef DOUBLE_SIDED",
  5368. "vec3 directionalLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );",
  5369. "#ifdef WRAP_AROUND",
  5370. "vec3 directionalLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );",
  5371. "#endif",
  5372. "#endif",
  5373. "#ifdef WRAP_AROUND",
  5374. "vec3 directionalLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );",
  5375. "directionalLightWeighting = mix( directionalLightWeighting, directionalLightWeightingHalf, wrapRGB );",
  5376. "#ifdef DOUBLE_SIDED",
  5377. "directionalLightWeightingBack = mix( directionalLightWeightingBack, directionalLightWeightingHalfBack, wrapRGB );",
  5378. "#endif",
  5379. "#endif",
  5380. "vLightFront += directionalLightColor[ i ] * directionalLightWeighting;",
  5381. "#ifdef DOUBLE_SIDED",
  5382. "vLightBack += directionalLightColor[ i ] * directionalLightWeightingBack;",
  5383. "#endif",
  5384. "}",
  5385. "#endif",
  5386. "#if MAX_POINT_LIGHTS > 0",
  5387. "for( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
  5388. "vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
  5389. "vec3 lVector = lPosition.xyz - mvPosition.xyz;",
  5390. "float lDistance = 1.0;",
  5391. "if ( pointLightDistance[ i ] > 0.0 )",
  5392. "lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
  5393. "lVector = normalize( lVector );",
  5394. "float dotProduct = dot( transformedNormal, lVector );",
  5395. "vec3 pointLightWeighting = vec3( max( dotProduct, 0.0 ) );",
  5396. "#ifdef DOUBLE_SIDED",
  5397. "vec3 pointLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );",
  5398. "#ifdef WRAP_AROUND",
  5399. "vec3 pointLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );",
  5400. "#endif",
  5401. "#endif",
  5402. "#ifdef WRAP_AROUND",
  5403. "vec3 pointLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );",
  5404. "pointLightWeighting = mix( pointLightWeighting, pointLightWeightingHalf, wrapRGB );",
  5405. "#ifdef DOUBLE_SIDED",
  5406. "pointLightWeightingBack = mix( pointLightWeightingBack, pointLightWeightingHalfBack, wrapRGB );",
  5407. "#endif",
  5408. "#endif",
  5409. "vLightFront += pointLightColor[ i ] * pointLightWeighting * lDistance;",
  5410. "#ifdef DOUBLE_SIDED",
  5411. "vLightBack += pointLightColor[ i ] * pointLightWeightingBack * lDistance;",
  5412. "#endif",
  5413. "}",
  5414. "#endif",
  5415. "#if MAX_SPOT_LIGHTS > 0",
  5416. "for( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {",
  5417. "vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );",
  5418. "vec3 lVector = lPosition.xyz - mvPosition.xyz;",
  5419. "lVector = normalize( lVector );",
  5420. "float spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - mPosition.xyz ) );",
  5421. "if ( spotEffect > spotLightAngle[ i ] ) {",
  5422. "spotEffect = pow( spotEffect, spotLightExponent[ i ] );",
  5423. "float lDistance = 1.0;",
  5424. "if ( spotLightDistance[ i ] > 0.0 )",
  5425. "lDistance = 1.0 - min( ( length( lVector ) / spotLightDistance[ i ] ), 1.0 );",
  5426. "float dotProduct = dot( transformedNormal, lVector );",
  5427. "vec3 spotLightWeighting = vec3( max( dotProduct, 0.0 ) );",
  5428. "#ifdef DOUBLE_SIDED",
  5429. "vec3 spotLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );",
  5430. "#ifdef WRAP_AROUND",
  5431. "vec3 spotLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );",
  5432. "#endif",
  5433. "#endif",
  5434. "#ifdef WRAP_AROUND",
  5435. "vec3 spotLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );",
  5436. "spotLightWeighting = mix( spotLightWeighting, spotLightWeightingHalf, wrapRGB );",
  5437. "#ifdef DOUBLE_SIDED",
  5438. "spotLightWeightingBack = mix( spotLightWeightingBack, spotLightWeightingHalfBack, wrapRGB );",
  5439. "#endif",
  5440. "#endif",
  5441. "vLightFront += spotLightColor[ i ] * spotLightWeighting * lDistance * spotEffect;",
  5442. "#ifdef DOUBLE_SIDED",
  5443. "vLightBack += spotLightColor[ i ] * spotLightWeightingBack * lDistance * spotEffect;",
  5444. "#endif",
  5445. "}",
  5446. "}",
  5447. "#endif",
  5448. "vLightFront = vLightFront * diffuse + ambient * ambientLightColor + emissive;",
  5449. "#ifdef DOUBLE_SIDED",
  5450. "vLightBack = vLightBack * diffuse + ambient * ambientLightColor + emissive;",
  5451. "#endif"
  5452. ].join("\n"),
  5453. // LIGHTS PHONG
  5454. lights_phong_pars_vertex: [
  5455. "#ifndef PHONG_PER_PIXEL",
  5456. "#if MAX_POINT_LIGHTS > 0",
  5457. "uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];",
  5458. "uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",
  5459. "varying vec4 vPointLight[ MAX_POINT_LIGHTS ];",
  5460. "#endif",
  5461. "#if MAX_SPOT_LIGHTS > 0",
  5462. "uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];",
  5463. "uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];",
  5464. "varying vec4 vSpotLight[ MAX_SPOT_LIGHTS ];",
  5465. "#endif",
  5466. "#endif",
  5467. "#if MAX_SPOT_LIGHTS > 0",
  5468. "varying vec3 vWorldPosition;",
  5469. "#endif"
  5470. ].join("\n"),
  5471. lights_phong_vertex: [
  5472. "#ifndef PHONG_PER_PIXEL",
  5473. "#if MAX_POINT_LIGHTS > 0",
  5474. "for( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
  5475. "vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
  5476. "vec3 lVector = lPosition.xyz - mvPosition.xyz;",
  5477. "float lDistance = 1.0;",
  5478. "if ( pointLightDistance[ i ] > 0.0 )",
  5479. "lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
  5480. "vPointLight[ i ] = vec4( lVector, lDistance );",
  5481. "}",
  5482. "#endif",
  5483. "#if MAX_SPOT_LIGHTS > 0",
  5484. "for( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {",
  5485. "vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );",
  5486. "vec3 lVector = lPosition.xyz - mvPosition.xyz;",
  5487. "float lDistance = 1.0;",
  5488. "if ( spotLightDistance[ i ] > 0.0 )",
  5489. "lDistance = 1.0 - min( ( length( lVector ) / spotLightDistance[ i ] ), 1.0 );",
  5490. "vSpotLight[ i ] = vec4( lVector, lDistance );",
  5491. "}",
  5492. "#endif",
  5493. "#endif",
  5494. "#if MAX_SPOT_LIGHTS > 0",
  5495. "vWorldPosition = mPosition.xyz;",
  5496. "#endif"
  5497. ].join("\n"),
  5498. lights_phong_pars_fragment: [
  5499. "uniform vec3 ambientLightColor;",
  5500. "#if MAX_DIR_LIGHTS > 0",
  5501. "uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];",
  5502. "uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];",
  5503. "#endif",
  5504. "#if MAX_POINT_LIGHTS > 0",
  5505. "uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];",
  5506. "#ifdef PHONG_PER_PIXEL",
  5507. "uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];",
  5508. "uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",
  5509. "#else",
  5510. "varying vec4 vPointLight[ MAX_POINT_LIGHTS ];",
  5511. "#endif",
  5512. "#endif",
  5513. "#if MAX_SPOT_LIGHTS > 0",
  5514. "uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];",
  5515. "uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];",
  5516. "uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];",
  5517. "uniform float spotLightAngle[ MAX_SPOT_LIGHTS ];",
  5518. "uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];",
  5519. "#ifdef PHONG_PER_PIXEL",
  5520. "uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];",
  5521. "#else",
  5522. "varying vec4 vSpotLight[ MAX_SPOT_LIGHTS ];",
  5523. "#endif",
  5524. "varying vec3 vWorldPosition;",
  5525. "#endif",
  5526. "#ifdef WRAP_AROUND",
  5527. "uniform vec3 wrapRGB;",
  5528. "#endif",
  5529. "varying vec3 vViewPosition;",
  5530. "varying vec3 vNormal;"
  5531. ].join("\n"),
  5532. lights_phong_fragment: [
  5533. "vec3 normal = normalize( vNormal );",
  5534. "vec3 viewPosition = normalize( vViewPosition );",
  5535. "#ifdef DOUBLE_SIDED",
  5536. "normal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );",
  5537. "#endif",
  5538. "#if MAX_POINT_LIGHTS > 0",
  5539. "vec3 pointDiffuse = vec3( 0.0 );",
  5540. "vec3 pointSpecular = vec3( 0.0 );",
  5541. "for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
  5542. "#ifdef PHONG_PER_PIXEL",
  5543. "vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
  5544. "vec3 lVector = lPosition.xyz + vViewPosition.xyz;",
  5545. "float lDistance = 1.0;",
  5546. "if ( pointLightDistance[ i ] > 0.0 )",
  5547. "lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
  5548. "lVector = normalize( lVector );",
  5549. "#else",
  5550. "vec3 lVector = normalize( vPointLight[ i ].xyz );",
  5551. "float lDistance = vPointLight[ i ].w;",
  5552. "#endif",
  5553. // diffuse
  5554. "float dotProduct = dot( normal, lVector );",
  5555. "#ifdef WRAP_AROUND",
  5556. "float pointDiffuseWeightFull = max( dotProduct, 0.0 );",
  5557. "float pointDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );",
  5558. "vec3 pointDiffuseWeight = mix( vec3 ( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );",
  5559. "#else",
  5560. "float pointDiffuseWeight = max( dotProduct, 0.0 );",
  5561. "#endif",
  5562. "pointDiffuse += diffuse * pointLightColor[ i ] * pointDiffuseWeight * lDistance;",
  5563. // specular
  5564. "vec3 pointHalfVector = normalize( lVector + viewPosition );",
  5565. "float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );",
  5566. "float pointSpecularWeight = max( pow( pointDotNormalHalf, shininess ), 0.0 );",
  5567. "#ifdef PHYSICALLY_BASED_SHADING",
  5568. // 2.0 => 2.0001 is hack to work around ANGLE bug
  5569. "float specularNormalization = ( shininess + 2.0001 ) / 8.0;",
  5570. "vec3 schlick = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( lVector, pointHalfVector ), 5.0 );",
  5571. "pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * lDistance * specularNormalization;",
  5572. "#else",
  5573. "pointSpecular += specular * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * lDistance;",
  5574. "#endif",
  5575. "}",
  5576. "#endif",
  5577. "#if MAX_SPOT_LIGHTS > 0",
  5578. "vec3 spotDiffuse = vec3( 0.0 );",
  5579. "vec3 spotSpecular = vec3( 0.0 );",
  5580. "for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {",
  5581. "#ifdef PHONG_PER_PIXEL",
  5582. "vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );",
  5583. "vec3 lVector = lPosition.xyz + vViewPosition.xyz;",
  5584. "float lDistance = 1.0;",
  5585. "if ( spotLightDistance[ i ] > 0.0 )",
  5586. "lDistance = 1.0 - min( ( length( lVector ) / spotLightDistance[ i ] ), 1.0 );",
  5587. "lVector = normalize( lVector );",
  5588. "#else",
  5589. "vec3 lVector = normalize( vSpotLight[ i ].xyz );",
  5590. "float lDistance = vSpotLight[ i ].w;",
  5591. "#endif",
  5592. "float spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - vWorldPosition ) );",
  5593. "if ( spotEffect > spotLightAngle[ i ] ) {",
  5594. "spotEffect = pow( spotEffect, spotLightExponent[ i ] );",
  5595. // diffuse
  5596. "float dotProduct = dot( normal, lVector );",
  5597. "#ifdef WRAP_AROUND",
  5598. "float spotDiffuseWeightFull = max( dotProduct, 0.0 );",
  5599. "float spotDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );",
  5600. "vec3 spotDiffuseWeight = mix( vec3 ( spotDiffuseWeightFull ), vec3( spotDiffuseWeightHalf ), wrapRGB );",
  5601. "#else",
  5602. "float spotDiffuseWeight = max( dotProduct, 0.0 );",
  5603. "#endif",
  5604. "spotDiffuse += diffuse * spotLightColor[ i ] * spotDiffuseWeight * lDistance * spotEffect;",
  5605. // specular
  5606. "vec3 spotHalfVector = normalize( lVector + viewPosition );",
  5607. "float spotDotNormalHalf = max( dot( normal, spotHalfVector ), 0.0 );",
  5608. "float spotSpecularWeight = max( pow( spotDotNormalHalf, shininess ), 0.0 );",
  5609. "#ifdef PHYSICALLY_BASED_SHADING",
  5610. // 2.0 => 2.0001 is hack to work around ANGLE bug
  5611. "float specularNormalization = ( shininess + 2.0001 ) / 8.0;",
  5612. "vec3 schlick = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( lVector, spotHalfVector ), 5.0 );",
  5613. "spotSpecular += schlick * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * lDistance * specularNormalization * spotEffect;",
  5614. "#else",
  5615. "spotSpecular += specular * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * lDistance * spotEffect;",
  5616. "#endif",
  5617. "}",
  5618. "}",
  5619. "#endif",
  5620. "#if MAX_DIR_LIGHTS > 0",
  5621. "vec3 dirDiffuse = vec3( 0.0 );",
  5622. "vec3 dirSpecular = vec3( 0.0 );" ,
  5623. "for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {",
  5624. "vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );",
  5625. "vec3 dirVector = normalize( lDirection.xyz );",
  5626. // diffuse
  5627. "float dotProduct = dot( normal, dirVector );",
  5628. "#ifdef WRAP_AROUND",
  5629. "float dirDiffuseWeightFull = max( dotProduct, 0.0 );",
  5630. "float dirDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );",
  5631. "vec3 dirDiffuseWeight = mix( vec3( dirDiffuseWeightFull ), vec3( dirDiffuseWeightHalf ), wrapRGB );",
  5632. "#else",
  5633. "float dirDiffuseWeight = max( dotProduct, 0.0 );",
  5634. "#endif",
  5635. "dirDiffuse += diffuse * directionalLightColor[ i ] * dirDiffuseWeight;",
  5636. // specular
  5637. "vec3 dirHalfVector = normalize( dirVector + viewPosition );",
  5638. "float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );",
  5639. "float dirSpecularWeight = max( pow( dirDotNormalHalf, shininess ), 0.0 );",
  5640. "#ifdef PHYSICALLY_BASED_SHADING",
  5641. /*
  5642. // fresnel term from skin shader
  5643. "const float F0 = 0.128;",
  5644. "float base = 1.0 - dot( viewPosition, dirHalfVector );",
  5645. "float exponential = pow( base, 5.0 );",
  5646. "float fresnel = exponential + F0 * ( 1.0 - exponential );",
  5647. */
  5648. /*
  5649. // fresnel term from fresnel shader
  5650. "const float mFresnelBias = 0.08;",
  5651. "const float mFresnelScale = 0.3;",
  5652. "const float mFresnelPower = 5.0;",
  5653. "float fresnel = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( -viewPosition ), normal ), mFresnelPower );",
  5654. */
  5655. // 2.0 => 2.0001 is hack to work around ANGLE bug
  5656. "float specularNormalization = ( shininess + 2.0001 ) / 8.0;",
  5657. //"dirSpecular += specular * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization * fresnel;",
  5658. "vec3 schlick = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( dirVector, dirHalfVector ), 5.0 );",
  5659. "dirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;",
  5660. "#else",
  5661. "dirSpecular += specular * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight;",
  5662. "#endif",
  5663. "}",
  5664. "#endif",
  5665. "vec3 totalDiffuse = vec3( 0.0 );",
  5666. "vec3 totalSpecular = vec3( 0.0 );",
  5667. "#if MAX_DIR_LIGHTS > 0",
  5668. "totalDiffuse += dirDiffuse;",
  5669. "totalSpecular += dirSpecular;",
  5670. "#endif",
  5671. "#if MAX_POINT_LIGHTS > 0",
  5672. "totalDiffuse += pointDiffuse;",
  5673. "totalSpecular += pointSpecular;",
  5674. "#endif",
  5675. "#if MAX_SPOT_LIGHTS > 0",
  5676. "totalDiffuse += spotDiffuse;",
  5677. "totalSpecular += spotSpecular;",
  5678. "#endif",
  5679. "#ifdef METAL",
  5680. "gl_FragColor.xyz = gl_FragColor.xyz * ( emissive + totalDiffuse + ambientLightColor * ambient + totalSpecular );",
  5681. "#else",
  5682. "gl_FragColor.xyz = gl_FragColor.xyz * ( emissive + totalDiffuse + ambientLightColor * ambient ) + totalSpecular;",
  5683. "#endif"
  5684. ].join("\n"),
  5685. // VERTEX COLORS
  5686. color_pars_fragment: [
  5687. "#ifdef USE_COLOR",
  5688. "varying vec3 vColor;",
  5689. "#endif"
  5690. ].join("\n"),
  5691. color_fragment: [
  5692. "#ifdef USE_COLOR",
  5693. "gl_FragColor = gl_FragColor * vec4( vColor, opacity );",
  5694. "#endif"
  5695. ].join("\n"),
  5696. color_pars_vertex: [
  5697. "#ifdef USE_COLOR",
  5698. "varying vec3 vColor;",
  5699. "#endif"
  5700. ].join("\n"),
  5701. color_vertex: [
  5702. "#ifdef USE_COLOR",
  5703. "#ifdef GAMMA_INPUT",
  5704. "vColor = color * color;",
  5705. "#else",
  5706. "vColor = color;",
  5707. "#endif",
  5708. "#endif"
  5709. ].join("\n"),
  5710. // SKINNING
  5711. skinning_pars_vertex: [
  5712. "#ifdef USE_SKINNING",
  5713. "uniform mat4 boneGlobalMatrices[ MAX_BONES ];",
  5714. "#endif"
  5715. ].join("\n"),
  5716. skinning_vertex: [
  5717. "#ifdef USE_SKINNING",
  5718. "gl_Position = ( boneGlobalMatrices[ int( skinIndex.x ) ] * skinVertexA ) * skinWeight.x;",
  5719. "gl_Position += ( boneGlobalMatrices[ int( skinIndex.y ) ] * skinVertexB ) * skinWeight.y;",
  5720. "gl_Position = projectionMatrix * modelViewMatrix * gl_Position;",
  5721. "#endif"
  5722. ].join("\n"),
  5723. // MORPHING
  5724. morphtarget_pars_vertex: [
  5725. "#ifdef USE_MORPHTARGETS",
  5726. "#ifndef USE_MORPHNORMALS",
  5727. "uniform float morphTargetInfluences[ 8 ];",
  5728. "#else",
  5729. "uniform float morphTargetInfluences[ 4 ];",
  5730. "#endif",
  5731. "#endif"
  5732. ].join("\n"),
  5733. morphtarget_vertex: [
  5734. "#ifdef USE_MORPHTARGETS",
  5735. "vec3 morphed = vec3( 0.0 );",
  5736. "morphed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];",
  5737. "morphed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];",
  5738. "morphed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];",
  5739. "morphed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];",
  5740. "#ifndef USE_MORPHNORMALS",
  5741. "morphed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];",
  5742. "morphed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];",
  5743. "morphed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];",
  5744. "morphed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];",
  5745. "#endif",
  5746. "morphed += position;",
  5747. "gl_Position = projectionMatrix * modelViewMatrix * vec4( morphed, 1.0 );",
  5748. "#endif"
  5749. ].join("\n"),
  5750. default_vertex : [
  5751. "#ifndef USE_MORPHTARGETS",
  5752. "#ifndef USE_SKINNING",
  5753. "gl_Position = projectionMatrix * mvPosition;",
  5754. "#endif",
  5755. "#endif"
  5756. ].join("\n"),
  5757. morphnormal_vertex: [
  5758. "#ifdef USE_MORPHNORMALS",
  5759. "vec3 morphedNormal = vec3( 0.0 );",
  5760. "morphedNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];",
  5761. "morphedNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];",
  5762. "morphedNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];",
  5763. "morphedNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];",
  5764. "morphedNormal += normal;",
  5765. "vec3 transformedNormal = normalMatrix * morphedNormal;",
  5766. "#else",
  5767. "vec3 transformedNormal = normalMatrix * normal;",
  5768. "#endif"
  5769. ].join("\n"),
  5770. // SHADOW MAP
  5771. // based on SpiderGL shadow map and Fabien Sanglard's GLSL shadow mapping examples
  5772. // http://spidergl.org/example.php?id=6
  5773. // http://fabiensanglard.net/shadowmapping
  5774. shadowmap_pars_fragment: [
  5775. "#ifdef USE_SHADOWMAP",
  5776. "uniform sampler2D shadowMap[ MAX_SHADOWS ];",
  5777. "uniform vec2 shadowMapSize[ MAX_SHADOWS ];",
  5778. "uniform float shadowDarkness[ MAX_SHADOWS ];",
  5779. "uniform float shadowBias[ MAX_SHADOWS ];",
  5780. "varying vec4 vShadowCoord[ MAX_SHADOWS ];",
  5781. "float unpackDepth( const in vec4 rgba_depth ) {",
  5782. "const vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );",
  5783. "float depth = dot( rgba_depth, bit_shift );",
  5784. "return depth;",
  5785. "}",
  5786. "#endif"
  5787. ].join("\n"),
  5788. shadowmap_fragment: [
  5789. "#ifdef USE_SHADOWMAP",
  5790. "#ifdef SHADOWMAP_DEBUG",
  5791. "vec3 frustumColors[3];",
  5792. "frustumColors[0] = vec3( 1.0, 0.5, 0.0 );",
  5793. "frustumColors[1] = vec3( 0.0, 1.0, 0.8 );",
  5794. "frustumColors[2] = vec3( 0.0, 0.5, 1.0 );",
  5795. "#endif",
  5796. "#ifdef SHADOWMAP_CASCADE",
  5797. "int inFrustumCount = 0;",
  5798. "#endif",
  5799. "float fDepth;",
  5800. "vec3 shadowColor = vec3( 1.0 );",
  5801. "for( int i = 0; i < MAX_SHADOWS; i ++ ) {",
  5802. "vec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;",
  5803. // "if ( something && something )" breaks ATI OpenGL shader compiler
  5804. // "if ( all( something, something ) )" using this instead
  5805. "bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );",
  5806. "bool inFrustum = all( inFrustumVec );",
  5807. // don't shadow pixels outside of light frustum
  5808. // use just first frustum (for cascades)
  5809. // don't shadow pixels behind far plane of light frustum
  5810. "#ifdef SHADOWMAP_CASCADE",
  5811. "inFrustumCount += int( inFrustum );",
  5812. "bvec3 frustumTestVec = bvec3( inFrustum, inFrustumCount == 1, shadowCoord.z <= 1.0 );",
  5813. "#else",
  5814. "bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );",
  5815. "#endif",
  5816. "bool frustumTest = all( frustumTestVec );",
  5817. "if ( frustumTest ) {",
  5818. "shadowCoord.z += shadowBias[ i ];",
  5819. "#ifdef SHADOWMAP_SOFT",
  5820. // Percentage-close filtering
  5821. // (9 pixel kernel)
  5822. // http://fabiensanglard.net/shadowmappingPCF/
  5823. "float shadow = 0.0;",
  5824. /*
  5825. // nested loops breaks shader compiler / validator on some ATI cards when using OpenGL
  5826. // must enroll loop manually
  5827. "for ( float y = -1.25; y <= 1.25; y += 1.25 )",
  5828. "for ( float x = -1.25; x <= 1.25; x += 1.25 ) {",
  5829. "vec4 rgbaDepth = texture2D( shadowMap[ i ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );",
  5830. // doesn't seem to produce any noticeable visual difference compared to simple "texture2D" lookup
  5831. //"vec4 rgbaDepth = texture2DProj( shadowMap[ i ], vec4( vShadowCoord[ i ].w * ( vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy ), 0.05, vShadowCoord[ i ].w ) );",
  5832. "float fDepth = unpackDepth( rgbaDepth );",
  5833. "if ( fDepth < shadowCoord.z )",
  5834. "shadow += 1.0;",
  5835. "}",
  5836. "shadow /= 9.0;",
  5837. */
  5838. "const float shadowDelta = 1.0 / 9.0;",
  5839. "float xPixelOffset = 1.0 / shadowMapSize[ i ].x;",
  5840. "float yPixelOffset = 1.0 / shadowMapSize[ i ].y;",
  5841. "float dx0 = -1.25 * xPixelOffset;",
  5842. "float dy0 = -1.25 * yPixelOffset;",
  5843. "float dx1 = 1.25 * xPixelOffset;",
  5844. "float dy1 = 1.25 * yPixelOffset;",
  5845. "fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );",
  5846. "if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
  5847. "fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );",
  5848. "if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
  5849. "fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );",
  5850. "if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
  5851. "fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );",
  5852. "if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
  5853. "fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );",
  5854. "if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
  5855. "fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );",
  5856. "if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
  5857. "fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );",
  5858. "if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
  5859. "fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );",
  5860. "if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
  5861. "fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );",
  5862. "if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
  5863. "shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );",
  5864. "#else",
  5865. "vec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );",
  5866. "float fDepth = unpackDepth( rgbaDepth );",
  5867. "if ( fDepth < shadowCoord.z )",
  5868. // spot with multiple shadows is darker
  5869. "shadowColor = shadowColor * vec3( 1.0 - shadowDarkness[ i ] );",
  5870. // spot with multiple shadows has the same color as single shadow spot
  5871. //"shadowColor = min( shadowColor, vec3( shadowDarkness[ i ] ) );",
  5872. "#endif",
  5873. "}",
  5874. "#ifdef SHADOWMAP_DEBUG",
  5875. "#ifdef SHADOWMAP_CASCADE",
  5876. "if ( inFrustum && inFrustumCount == 1 ) gl_FragColor.xyz *= frustumColors[ i ];",
  5877. "#else",
  5878. "if ( inFrustum ) gl_FragColor.xyz *= frustumColors[ i ];",
  5879. "#endif",
  5880. "#endif",
  5881. "}",
  5882. "#ifdef GAMMA_OUTPUT",
  5883. "shadowColor *= shadowColor;",
  5884. "#endif",
  5885. "gl_FragColor.xyz = gl_FragColor.xyz * shadowColor;",
  5886. "#endif"
  5887. ].join("\n"),
  5888. shadowmap_pars_vertex: [
  5889. "#ifdef USE_SHADOWMAP",
  5890. "varying vec4 vShadowCoord[ MAX_SHADOWS ];",
  5891. "uniform mat4 shadowMatrix[ MAX_SHADOWS ];",
  5892. "#endif"
  5893. ].join("\n"),
  5894. shadowmap_vertex: [
  5895. "#ifdef USE_SHADOWMAP",
  5896. "for( int i = 0; i < MAX_SHADOWS; i ++ ) {",
  5897. "#ifdef USE_MORPHTARGETS",
  5898. "vShadowCoord[ i ] = shadowMatrix[ i ] * objectMatrix * vec4( morphed, 1.0 );",
  5899. "#else",
  5900. "vShadowCoord[ i ] = shadowMatrix[ i ] * objectMatrix * vec4( position, 1.0 );",
  5901. "#endif",
  5902. "}",
  5903. "#endif"
  5904. ].join("\n"),
  5905. // ALPHATEST
  5906. alphatest_fragment: [
  5907. "#ifdef ALPHATEST",
  5908. "if ( gl_FragColor.a < ALPHATEST ) discard;",
  5909. "#endif"
  5910. ].join("\n"),
  5911. // LINEAR SPACE
  5912. linear_to_gamma_fragment: [
  5913. "#ifdef GAMMA_OUTPUT",
  5914. "gl_FragColor.xyz = sqrt( gl_FragColor.xyz );",
  5915. "#endif"
  5916. ].join("\n"),
  5917. };
  5918. THREE.UniformsUtils = {
  5919. merge: function ( uniforms ) {
  5920. var u, p, tmp, merged = {};
  5921. for ( u = 0; u < uniforms.length; u++ ) {
  5922. tmp = this.clone( uniforms[ u ] );
  5923. for ( p in tmp ) {
  5924. merged[ p ] = tmp[ p ];
  5925. }
  5926. }
  5927. return merged;
  5928. },
  5929. clone: function ( uniforms_src ) {
  5930. var u, p, parameter, parameter_src, uniforms_dst = {};
  5931. for ( u in uniforms_src ) {
  5932. uniforms_dst[ u ] = {};
  5933. for ( p in uniforms_src[ u ] ) {
  5934. parameter_src = uniforms_src[ u ][ p ];
  5935. if ( parameter_src instanceof THREE.Color ||
  5936. parameter_src instanceof THREE.Vector2 ||
  5937. parameter_src instanceof THREE.Vector3 ||
  5938. parameter_src instanceof THREE.Vector4 ||
  5939. parameter_src instanceof THREE.Matrix4 ||
  5940. parameter_src instanceof THREE.Texture ) {
  5941. uniforms_dst[ u ][ p ] = parameter_src.clone();
  5942. } else if ( parameter_src instanceof Array ) {
  5943. uniforms_dst[ u ][ p ] = parameter_src.slice();
  5944. } else {
  5945. uniforms_dst[ u ][ p ] = parameter_src;
  5946. }
  5947. }
  5948. }
  5949. return uniforms_dst;
  5950. }
  5951. };
  5952. THREE.UniformsLib = {
  5953. common: {
  5954. "diffuse" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  5955. "opacity" : { type: "f", value: 1.0 },
  5956. "map" : { type: "t", value: 0, texture: null },
  5957. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  5958. "lightMap" : { type: "t", value: 2, texture: null },
  5959. "envMap" : { type: "t", value: 1, texture: null },
  5960. "flipEnvMap" : { type: "f", value: -1 },
  5961. "useRefract" : { type: "i", value: 0 },
  5962. "reflectivity" : { type: "f", value: 1.0 },
  5963. "refractionRatio" : { type: "f", value: 0.98 },
  5964. "combine" : { type: "i", value: 0 },
  5965. "morphTargetInfluences" : { type: "f", value: 0 }
  5966. },
  5967. fog : {
  5968. "fogDensity" : { type: "f", value: 0.00025 },
  5969. "fogNear" : { type: "f", value: 1 },
  5970. "fogFar" : { type: "f", value: 2000 },
  5971. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  5972. },
  5973. lights: {
  5974. "ambientLightColor" : { type: "fv", value: [] },
  5975. "directionalLightDirection" : { type: "fv", value: [] },
  5976. "directionalLightColor" : { type: "fv", value: [] },
  5977. "pointLightColor" : { type: "fv", value: [] },
  5978. "pointLightPosition" : { type: "fv", value: [] },
  5979. "pointLightDistance" : { type: "fv1", value: [] },
  5980. "spotLightColor" : { type: "fv", value: [] },
  5981. "spotLightPosition" : { type: "fv", value: [] },
  5982. "spotLightDirection" : { type: "fv", value: [] },
  5983. "spotLightDistance" : { type: "fv1", value: [] },
  5984. "spotLightAngle" : { type: "fv1", value: [] },
  5985. "spotLightExponent" : { type: "fv1", value: [] }
  5986. },
  5987. particle: {
  5988. "psColor" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  5989. "opacity" : { type: "f", value: 1.0 },
  5990. "size" : { type: "f", value: 1.0 },
  5991. "scale" : { type: "f", value: 1.0 },
  5992. "map" : { type: "t", value: 0, texture: null },
  5993. "fogDensity" : { type: "f", value: 0.00025 },
  5994. "fogNear" : { type: "f", value: 1 },
  5995. "fogFar" : { type: "f", value: 2000 },
  5996. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  5997. },
  5998. shadowmap: {
  5999. "shadowMap": { type: "tv", value: 6, texture: [] },
  6000. "shadowMapSize": { type: "v2v", value: [] },
  6001. "shadowBias" : { type: "fv1", value: [] },
  6002. "shadowDarkness": { type: "fv1", value: [] },
  6003. "shadowMatrix" : { type: "m4v", value: [] },
  6004. }
  6005. };
  6006. THREE.ShaderLib = {
  6007. 'depth': {
  6008. uniforms: {
  6009. "mNear": { type: "f", value: 1.0 },
  6010. "mFar" : { type: "f", value: 2000.0 },
  6011. "opacity" : { type: "f", value: 1.0 }
  6012. },
  6013. vertexShader: [
  6014. "void main() {",
  6015. "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  6016. "}"
  6017. ].join("\n"),
  6018. fragmentShader: [
  6019. "uniform float mNear;",
  6020. "uniform float mFar;",
  6021. "uniform float opacity;",
  6022. "void main() {",
  6023. "float depth = gl_FragCoord.z / gl_FragCoord.w;",
  6024. "float color = 1.0 - smoothstep( mNear, mFar, depth );",
  6025. "gl_FragColor = vec4( vec3( color ), opacity );",
  6026. "}"
  6027. ].join("\n")
  6028. },
  6029. 'normal': {
  6030. uniforms: {
  6031. "opacity" : { type: "f", value: 1.0 }
  6032. },
  6033. vertexShader: [
  6034. "varying vec3 vNormal;",
  6035. "void main() {",
  6036. "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  6037. "vNormal = normalMatrix * normal;",
  6038. "gl_Position = projectionMatrix * mvPosition;",
  6039. "}"
  6040. ].join("\n"),
  6041. fragmentShader: [
  6042. "uniform float opacity;",
  6043. "varying vec3 vNormal;",
  6044. "void main() {",
  6045. "gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
  6046. "}"
  6047. ].join("\n")
  6048. },
  6049. 'basic': {
  6050. uniforms: THREE.UniformsUtils.merge( [
  6051. THREE.UniformsLib[ "common" ],
  6052. THREE.UniformsLib[ "fog" ],
  6053. THREE.UniformsLib[ "shadowmap" ]
  6054. ] ),
  6055. vertexShader: [
  6056. THREE.ShaderChunk[ "map_pars_vertex" ],
  6057. THREE.ShaderChunk[ "lightmap_pars_vertex" ],
  6058. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  6059. THREE.ShaderChunk[ "color_pars_vertex" ],
  6060. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  6061. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  6062. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  6063. "void main() {",
  6064. "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  6065. THREE.ShaderChunk[ "map_vertex" ],
  6066. THREE.ShaderChunk[ "lightmap_vertex" ],
  6067. THREE.ShaderChunk[ "envmap_vertex" ],
  6068. THREE.ShaderChunk[ "color_vertex" ],
  6069. THREE.ShaderChunk[ "skinning_vertex" ],
  6070. THREE.ShaderChunk[ "morphtarget_vertex" ],
  6071. THREE.ShaderChunk[ "default_vertex" ],
  6072. THREE.ShaderChunk[ "shadowmap_vertex" ],
  6073. "}"
  6074. ].join("\n"),
  6075. fragmentShader: [
  6076. "uniform vec3 diffuse;",
  6077. "uniform float opacity;",
  6078. THREE.ShaderChunk[ "color_pars_fragment" ],
  6079. THREE.ShaderChunk[ "map_pars_fragment" ],
  6080. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  6081. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  6082. THREE.ShaderChunk[ "fog_pars_fragment" ],
  6083. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  6084. "void main() {",
  6085. "gl_FragColor = vec4( diffuse, opacity );",
  6086. THREE.ShaderChunk[ "map_fragment" ],
  6087. THREE.ShaderChunk[ "alphatest_fragment" ],
  6088. THREE.ShaderChunk[ "lightmap_fragment" ],
  6089. THREE.ShaderChunk[ "color_fragment" ],
  6090. THREE.ShaderChunk[ "envmap_fragment" ],
  6091. THREE.ShaderChunk[ "shadowmap_fragment" ],
  6092. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  6093. THREE.ShaderChunk[ "fog_fragment" ],
  6094. "}"
  6095. ].join("\n")
  6096. },
  6097. 'lambert': {
  6098. uniforms: THREE.UniformsUtils.merge( [
  6099. THREE.UniformsLib[ "common" ],
  6100. THREE.UniformsLib[ "fog" ],
  6101. THREE.UniformsLib[ "lights" ],
  6102. THREE.UniformsLib[ "shadowmap" ],
  6103. {
  6104. "ambient" : { type: "c", value: new THREE.Color( 0xffffff ) },
  6105. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  6106. "wrapRGB" : { type: "v3", value: new THREE.Vector3( 1, 1, 1 ) }
  6107. }
  6108. ] ),
  6109. vertexShader: [
  6110. "varying vec3 vLightFront;",
  6111. "#ifdef DOUBLE_SIDED",
  6112. "varying vec3 vLightBack;",
  6113. "#endif",
  6114. THREE.ShaderChunk[ "map_pars_vertex" ],
  6115. THREE.ShaderChunk[ "lightmap_pars_vertex" ],
  6116. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  6117. THREE.ShaderChunk[ "lights_lambert_pars_vertex" ],
  6118. THREE.ShaderChunk[ "color_pars_vertex" ],
  6119. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  6120. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  6121. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  6122. "void main() {",
  6123. "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  6124. THREE.ShaderChunk[ "map_vertex" ],
  6125. THREE.ShaderChunk[ "lightmap_vertex" ],
  6126. THREE.ShaderChunk[ "envmap_vertex" ],
  6127. THREE.ShaderChunk[ "color_vertex" ],
  6128. THREE.ShaderChunk[ "morphnormal_vertex" ],
  6129. "#ifndef USE_ENVMAP",
  6130. "vec4 mPosition = objectMatrix * vec4( position, 1.0 );",
  6131. "#endif",
  6132. THREE.ShaderChunk[ "lights_lambert_vertex" ],
  6133. THREE.ShaderChunk[ "skinning_vertex" ],
  6134. THREE.ShaderChunk[ "morphtarget_vertex" ],
  6135. THREE.ShaderChunk[ "default_vertex" ],
  6136. THREE.ShaderChunk[ "shadowmap_vertex" ],
  6137. "}"
  6138. ].join("\n"),
  6139. fragmentShader: [
  6140. "uniform float opacity;",
  6141. "varying vec3 vLightFront;",
  6142. "#ifdef DOUBLE_SIDED",
  6143. "varying vec3 vLightBack;",
  6144. "#endif",
  6145. THREE.ShaderChunk[ "color_pars_fragment" ],
  6146. THREE.ShaderChunk[ "map_pars_fragment" ],
  6147. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  6148. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  6149. THREE.ShaderChunk[ "fog_pars_fragment" ],
  6150. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  6151. "void main() {",
  6152. "gl_FragColor = vec4( vec3 ( 1.0 ), opacity );",
  6153. THREE.ShaderChunk[ "map_fragment" ],
  6154. THREE.ShaderChunk[ "alphatest_fragment" ],
  6155. "#ifdef DOUBLE_SIDED",
  6156. //"float isFront = float( gl_FrontFacing );",
  6157. //"gl_FragColor.xyz *= isFront * vLightFront + ( 1.0 - isFront ) * vLightBack;",
  6158. "if ( gl_FrontFacing )",
  6159. "gl_FragColor.xyz *= vLightFront;",
  6160. "else",
  6161. "gl_FragColor.xyz *= vLightBack;",
  6162. "#else",
  6163. "gl_FragColor.xyz *= vLightFront;",
  6164. "#endif",
  6165. THREE.ShaderChunk[ "lightmap_fragment" ],
  6166. THREE.ShaderChunk[ "color_fragment" ],
  6167. THREE.ShaderChunk[ "envmap_fragment" ],
  6168. THREE.ShaderChunk[ "shadowmap_fragment" ],
  6169. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  6170. THREE.ShaderChunk[ "fog_fragment" ],
  6171. "}"
  6172. ].join("\n")
  6173. },
  6174. 'phong': {
  6175. uniforms: THREE.UniformsUtils.merge( [
  6176. THREE.UniformsLib[ "common" ],
  6177. THREE.UniformsLib[ "fog" ],
  6178. THREE.UniformsLib[ "lights" ],
  6179. THREE.UniformsLib[ "shadowmap" ],
  6180. {
  6181. "ambient" : { type: "c", value: new THREE.Color( 0xffffff ) },
  6182. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  6183. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  6184. "shininess": { type: "f", value: 30 },
  6185. "wrapRGB" : { type: "v3", value: new THREE.Vector3( 1, 1, 1 ) }
  6186. }
  6187. ] ),
  6188. vertexShader: [
  6189. "varying vec3 vViewPosition;",
  6190. "varying vec3 vNormal;",
  6191. THREE.ShaderChunk[ "map_pars_vertex" ],
  6192. THREE.ShaderChunk[ "lightmap_pars_vertex" ],
  6193. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  6194. THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
  6195. THREE.ShaderChunk[ "color_pars_vertex" ],
  6196. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  6197. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  6198. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  6199. "void main() {",
  6200. "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  6201. THREE.ShaderChunk[ "map_vertex" ],
  6202. THREE.ShaderChunk[ "lightmap_vertex" ],
  6203. THREE.ShaderChunk[ "envmap_vertex" ],
  6204. THREE.ShaderChunk[ "color_vertex" ],
  6205. "#ifndef USE_ENVMAP",
  6206. "vec4 mPosition = objectMatrix * vec4( position, 1.0 );",
  6207. "#endif",
  6208. "vViewPosition = -mvPosition.xyz;",
  6209. THREE.ShaderChunk[ "morphnormal_vertex" ],
  6210. "vNormal = transformedNormal;",
  6211. THREE.ShaderChunk[ "lights_phong_vertex" ],
  6212. THREE.ShaderChunk[ "skinning_vertex" ],
  6213. THREE.ShaderChunk[ "morphtarget_vertex" ],
  6214. THREE.ShaderChunk[ "default_vertex" ],
  6215. THREE.ShaderChunk[ "shadowmap_vertex" ],
  6216. "}"
  6217. ].join("\n"),
  6218. fragmentShader: [
  6219. "uniform vec3 diffuse;",
  6220. "uniform float opacity;",
  6221. "uniform vec3 ambient;",
  6222. "uniform vec3 emissive;",
  6223. "uniform vec3 specular;",
  6224. "uniform float shininess;",
  6225. THREE.ShaderChunk[ "color_pars_fragment" ],
  6226. THREE.ShaderChunk[ "map_pars_fragment" ],
  6227. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  6228. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  6229. THREE.ShaderChunk[ "fog_pars_fragment" ],
  6230. THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
  6231. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  6232. "void main() {",
  6233. "gl_FragColor = vec4( vec3 ( 1.0 ), opacity );",
  6234. THREE.ShaderChunk[ "map_fragment" ],
  6235. THREE.ShaderChunk[ "alphatest_fragment" ],
  6236. THREE.ShaderChunk[ "lights_phong_fragment" ],
  6237. THREE.ShaderChunk[ "lightmap_fragment" ],
  6238. THREE.ShaderChunk[ "color_fragment" ],
  6239. THREE.ShaderChunk[ "envmap_fragment" ],
  6240. THREE.ShaderChunk[ "shadowmap_fragment" ],
  6241. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  6242. THREE.ShaderChunk[ "fog_fragment" ],
  6243. "}"
  6244. ].join("\n")
  6245. },
  6246. 'particle_basic': {
  6247. uniforms: THREE.UniformsUtils.merge( [
  6248. THREE.UniformsLib[ "particle" ],
  6249. THREE.UniformsLib[ "shadowmap" ]
  6250. ] ),
  6251. vertexShader: [
  6252. "uniform float size;",
  6253. "uniform float scale;",
  6254. THREE.ShaderChunk[ "color_pars_vertex" ],
  6255. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  6256. "void main() {",
  6257. THREE.ShaderChunk[ "color_vertex" ],
  6258. "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  6259. "#ifdef USE_SIZEATTENUATION",
  6260. "gl_PointSize = size * ( scale / length( mvPosition.xyz ) );",
  6261. "#else",
  6262. "gl_PointSize = size;",
  6263. "#endif",
  6264. "gl_Position = projectionMatrix * mvPosition;",
  6265. THREE.ShaderChunk[ "shadowmap_vertex" ],
  6266. "}"
  6267. ].join("\n"),
  6268. fragmentShader: [
  6269. "uniform vec3 psColor;",
  6270. "uniform float opacity;",
  6271. THREE.ShaderChunk[ "color_pars_fragment" ],
  6272. THREE.ShaderChunk[ "map_particle_pars_fragment" ],
  6273. THREE.ShaderChunk[ "fog_pars_fragment" ],
  6274. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  6275. "void main() {",
  6276. "gl_FragColor = vec4( psColor, opacity );",
  6277. THREE.ShaderChunk[ "map_particle_fragment" ],
  6278. THREE.ShaderChunk[ "alphatest_fragment" ],
  6279. THREE.ShaderChunk[ "color_fragment" ],
  6280. THREE.ShaderChunk[ "shadowmap_fragment" ],
  6281. THREE.ShaderChunk[ "fog_fragment" ],
  6282. "}"
  6283. ].join("\n")
  6284. },
  6285. // Depth encoding into RGBA texture
  6286. // based on SpiderGL shadow map example
  6287. // http://spidergl.org/example.php?id=6
  6288. // originally from
  6289. // http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
  6290. // see also here:
  6291. // http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  6292. 'depthRGBA': {
  6293. uniforms: {},
  6294. vertexShader: [
  6295. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  6296. "void main() {",
  6297. "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  6298. THREE.ShaderChunk[ "morphtarget_vertex" ],
  6299. THREE.ShaderChunk[ "default_vertex" ],
  6300. "}"
  6301. ].join("\n"),
  6302. fragmentShader: [
  6303. "vec4 pack_depth( const in float depth ) {",
  6304. "const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  6305. "const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  6306. "vec4 res = fract( depth * bit_shift );",
  6307. "res -= res.xxyz * bit_mask;",
  6308. "return res;",
  6309. "}",
  6310. "void main() {",
  6311. "gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
  6312. //"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",
  6313. //"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",
  6314. //"gl_FragData[ 0 ] = pack_depth( z );",
  6315. //"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",
  6316. "}"
  6317. ].join("\n")
  6318. }
  6319. };/**
  6320. * @author supereggbert / http://www.paulbrunt.co.uk/
  6321. * @author mrdoob / http://mrdoob.com/
  6322. * @author alteredq / http://alteredqualia.com/
  6323. * @author szimek / https://github.com/szimek/
  6324. */
  6325. THREE.WebGLRenderer = function ( parameters ) {
  6326. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  6327. parameters = parameters || {};
  6328. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  6329. _precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  6330. _alpha = parameters.alpha !== undefined ? parameters.alpha : true,
  6331. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  6332. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  6333. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  6334. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  6335. _clearColor = parameters.clearColor !== undefined ? new THREE.Color( parameters.clearColor ) : new THREE.Color( 0x000000 ),
  6336. _clearAlpha = parameters.clearAlpha !== undefined ? parameters.clearAlpha : 0,
  6337. _maxLights = parameters.maxLights !== undefined ? parameters.maxLights : 4;
  6338. // public properties
  6339. this.domElement = _canvas;
  6340. this.context = null;
  6341. // clearing
  6342. this.autoClear = true;
  6343. this.autoClearColor = true;
  6344. this.autoClearDepth = true;
  6345. this.autoClearStencil = true;
  6346. // scene graph
  6347. this.sortObjects = true;
  6348. this.autoUpdateObjects = true;
  6349. this.autoUpdateScene = true;
  6350. // physically based shading
  6351. this.gammaInput = false;
  6352. this.gammaOutput = false;
  6353. this.physicallyBasedShading = false;
  6354. // shadow map
  6355. this.shadowMapEnabled = false;
  6356. this.shadowMapAutoUpdate = true;
  6357. this.shadowMapSoft = true;
  6358. this.shadowMapCullFrontFaces = true;
  6359. this.shadowMapDebug = false;
  6360. this.shadowMapCascade = false;
  6361. // morphs
  6362. this.maxMorphTargets = 8;
  6363. this.maxMorphNormals = 4;
  6364. // flags
  6365. this.autoScaleCubemaps = true;
  6366. // custom render plugins
  6367. this.renderPluginsPre = [];
  6368. this.renderPluginsPost = [];
  6369. // info
  6370. this.info = {
  6371. memory: {
  6372. programs: 0,
  6373. geometries: 0,
  6374. textures: 0
  6375. },
  6376. render: {
  6377. calls: 0,
  6378. vertices: 0,
  6379. faces: 0,
  6380. points: 0
  6381. }
  6382. };
  6383. // internal properties
  6384. var _this = this,
  6385. _gl,
  6386. _programs = [],
  6387. // internal state cache
  6388. _currentProgram = null,
  6389. _currentFramebuffer = null,
  6390. _currentMaterialId = -1,
  6391. _currentGeometryGroupHash = null,
  6392. _currentCamera = null,
  6393. _geometryGroupCounter = 0,
  6394. // GL state cache
  6395. _oldDoubleSided = null,
  6396. _oldFlipSided = null,
  6397. _oldBlending = null,
  6398. _oldBlendEquation = null,
  6399. _oldBlendSrc = null,
  6400. _oldBlendDst = null,
  6401. _oldDepthTest = null,
  6402. _oldDepthWrite = null,
  6403. _oldPolygonOffset = null,
  6404. _oldPolygonOffsetFactor = null,
  6405. _oldPolygonOffsetUnits = null,
  6406. _oldLineWidth = null,
  6407. _viewportX = 0,
  6408. _viewportY = 0,
  6409. _viewportWidth = 0,
  6410. _viewportHeight = 0,
  6411. _currentWidth = 0,
  6412. _currentHeight = 0,
  6413. // frustum
  6414. _frustum = new THREE.Frustum(),
  6415. // camera matrices cache
  6416. _projScreenMatrix = new THREE.Matrix4(),
  6417. _projScreenMatrixPS = new THREE.Matrix4(),
  6418. _vector3 = new THREE.Vector4(),
  6419. // light arrays cache
  6420. _direction = new THREE.Vector3(),
  6421. _lights = {
  6422. ambient: [ 0, 0, 0 ],
  6423. directional: { length: 0, colors: new Array(), positions: new Array() },
  6424. point: { length: 0, colors: new Array(), positions: new Array(), distances: new Array() },
  6425. spot: { length: 0, colors: new Array(), positions: new Array(), distances: new Array(), directions: new Array(), angles: new Array(), exponents: new Array() }
  6426. };
  6427. // initialize
  6428. _gl = initGL();
  6429. setDefaultGLState();
  6430. this.context = _gl;
  6431. // GPU capabilities
  6432. var _maxVertexTextures = _gl.getParameter( _gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ),
  6433. _maxTextureSize = _gl.getParameter( _gl.MAX_TEXTURE_SIZE ),
  6434. _maxCubemapSize = _gl.getParameter( _gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  6435. // API
  6436. this.getContext = function () {
  6437. return _gl;
  6438. };
  6439. this.supportsVertexTextures = function () {
  6440. return _maxVertexTextures > 0;
  6441. };
  6442. this.setSize = function ( width, height ) {
  6443. _canvas.width = width;
  6444. _canvas.height = height;
  6445. this.setViewport( 0, 0, _canvas.width, _canvas.height );
  6446. };
  6447. this.setViewport = function ( x, y, width, height ) {
  6448. _viewportX = x;
  6449. _viewportY = y;
  6450. _viewportWidth = width;
  6451. _viewportHeight = height;
  6452. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  6453. };
  6454. this.setScissor = function ( x, y, width, height ) {
  6455. _gl.scissor( x, y, width, height );
  6456. };
  6457. this.enableScissorTest = function ( enable ) {
  6458. enable ? _gl.enable( _gl.SCISSOR_TEST ) : _gl.disable( _gl.SCISSOR_TEST );
  6459. };
  6460. // Clearing
  6461. this.setClearColorHex = function ( hex, alpha ) {
  6462. _clearColor.setHex( hex );
  6463. _clearAlpha = alpha;
  6464. _gl.clearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  6465. };
  6466. this.setClearColor = function ( color, alpha ) {
  6467. _clearColor.copy( color );
  6468. _clearAlpha = alpha;
  6469. _gl.clearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  6470. };
  6471. this.getClearColor = function () {
  6472. return _clearColor;
  6473. };
  6474. this.getClearAlpha = function () {
  6475. return _clearAlpha;
  6476. };
  6477. this.clear = function ( color, depth, stencil ) {
  6478. var bits = 0;
  6479. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  6480. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  6481. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  6482. _gl.clear( bits );
  6483. };
  6484. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  6485. this.setRenderTarget( renderTarget );
  6486. this.clear( color, depth, stencil );
  6487. };
  6488. // Plugins
  6489. this.addPostPlugin = function ( plugin ) {
  6490. plugin.init( this );
  6491. this.renderPluginsPost.push( plugin );
  6492. };
  6493. this.addPrePlugin = function ( plugin ) {
  6494. plugin.init( this );
  6495. this.renderPluginsPre.push( plugin );
  6496. };
  6497. // Deallocation
  6498. this.deallocateObject = function ( object ) {
  6499. if ( ! object.__webglInit ) return;
  6500. object.__webglInit = false;
  6501. delete object._modelViewMatrix;
  6502. delete object._normalMatrix;
  6503. delete object._normalMatrixArray;
  6504. delete object._modelViewMatrixArray;
  6505. delete object._objectMatrixArray;
  6506. if ( object instanceof THREE.Mesh ) {
  6507. for ( var g in object.geometry.geometryGroups ) {
  6508. deleteMeshBuffers( object.geometry.geometryGroups[ g ] );
  6509. }
  6510. } else if ( object instanceof THREE.Ribbon ) {
  6511. deleteRibbonBuffers( object.geometry );
  6512. } else if ( object instanceof THREE.Line ) {
  6513. deleteLineBuffers( object.geometry );
  6514. } else if ( object instanceof THREE.ParticleSystem ) {
  6515. deleteParticleBuffers( object.geometry );
  6516. }
  6517. };
  6518. this.deallocateTexture = function ( texture ) {
  6519. if ( ! texture.__webglInit ) return;
  6520. texture.__webglInit = false;
  6521. _gl.deleteTexture( texture.__webglTexture );
  6522. _this.info.memory.textures --;
  6523. };
  6524. this.deallocateRenderTarget = function ( renderTarget ) {
  6525. if ( !renderTarget || ! renderTarget.__webglTexture ) return;
  6526. _gl.deleteTexture( renderTarget.__webglTexture );
  6527. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  6528. for ( var i = 0; i < 6; i ++ ) {
  6529. _gl.deleteFramebuffer( renderTarget.__webglFramebuffer[ i ] );
  6530. _gl.deleteRenderbuffer( renderTarget.__webglRenderbuffer[ i ] );
  6531. }
  6532. } else {
  6533. _gl.deleteFramebuffer( renderTarget.__webglFramebuffer );
  6534. _gl.deleteRenderbuffer( renderTarget.__webglRenderbuffer );
  6535. }
  6536. };
  6537. // Rendering
  6538. this.updateShadowMap = function ( scene, camera ) {
  6539. _currentProgram = null;
  6540. _oldBlending = -1;
  6541. _oldDepthTest = -1;
  6542. _oldDepthWrite = -1;
  6543. _currentGeometryGroupHash = -1;
  6544. _currentMaterialId = -1;
  6545. this.shadowMapPlugin.update( scene, camera );
  6546. };
  6547. // Internal functions
  6548. // Buffer allocation
  6549. function createParticleBuffers ( geometry ) {
  6550. geometry.__webglVertexBuffer = _gl.createBuffer();
  6551. geometry.__webglColorBuffer = _gl.createBuffer();
  6552. _this.info.geometries ++;
  6553. };
  6554. function createLineBuffers ( geometry ) {
  6555. geometry.__webglVertexBuffer = _gl.createBuffer();
  6556. geometry.__webglColorBuffer = _gl.createBuffer();
  6557. _this.info.memory.geometries ++;
  6558. };
  6559. function createRibbonBuffers ( geometry ) {
  6560. geometry.__webglVertexBuffer = _gl.createBuffer();
  6561. geometry.__webglColorBuffer = _gl.createBuffer();
  6562. _this.info.memory.geometries ++;
  6563. };
  6564. function createMeshBuffers ( geometryGroup ) {
  6565. geometryGroup.__webglVertexBuffer = _gl.createBuffer();
  6566. geometryGroup.__webglNormalBuffer = _gl.createBuffer();
  6567. geometryGroup.__webglTangentBuffer = _gl.createBuffer();
  6568. geometryGroup.__webglColorBuffer = _gl.createBuffer();
  6569. geometryGroup.__webglUVBuffer = _gl.createBuffer();
  6570. geometryGroup.__webglUV2Buffer = _gl.createBuffer();
  6571. geometryGroup.__webglSkinVertexABuffer = _gl.createBuffer();
  6572. geometryGroup.__webglSkinVertexBBuffer = _gl.createBuffer();
  6573. geometryGroup.__webglSkinIndicesBuffer = _gl.createBuffer();
  6574. geometryGroup.__webglSkinWeightsBuffer = _gl.createBuffer();
  6575. geometryGroup.__webglFaceBuffer = _gl.createBuffer();
  6576. geometryGroup.__webglLineBuffer = _gl.createBuffer();
  6577. var m, ml;
  6578. if ( geometryGroup.numMorphTargets ) {
  6579. geometryGroup.__webglMorphTargetsBuffers = [];
  6580. for ( m = 0, ml = geometryGroup.numMorphTargets; m < ml; m ++ ) {
  6581. geometryGroup.__webglMorphTargetsBuffers.push( _gl.createBuffer() );
  6582. }
  6583. }
  6584. if ( geometryGroup.numMorphNormals ) {
  6585. geometryGroup.__webglMorphNormalsBuffers = [];
  6586. for ( m = 0, ml = geometryGroup.numMorphNormals; m < ml; m ++ ) {
  6587. geometryGroup.__webglMorphNormalsBuffers.push( _gl.createBuffer() );
  6588. }
  6589. }
  6590. _this.info.memory.geometries ++;
  6591. };
  6592. // Buffer deallocation
  6593. function deleteParticleBuffers ( geometry ) {
  6594. _gl.deleteBuffer( geometry.__webglVertexBuffer );
  6595. _gl.deleteBuffer( geometry.__webglColorBuffer );
  6596. _this.info.memory.geometries --;
  6597. };
  6598. function deleteLineBuffers ( geometry ) {
  6599. _gl.deleteBuffer( geometry.__webglVertexBuffer );
  6600. _gl.deleteBuffer( geometry.__webglColorBuffer );
  6601. _this.info.memory.geometries --;
  6602. };
  6603. function deleteRibbonBuffers ( geometry ) {
  6604. _gl.deleteBuffer( geometry.__webglVertexBuffer );
  6605. _gl.deleteBuffer( geometry.__webglColorBuffer );
  6606. _this.info.memory.geometries --;
  6607. };
  6608. function deleteMeshBuffers ( geometryGroup ) {
  6609. _gl.deleteBuffer( geometryGroup.__webglVertexBuffer );
  6610. _gl.deleteBuffer( geometryGroup.__webglNormalBuffer );
  6611. _gl.deleteBuffer( geometryGroup.__webglTangentBuffer );
  6612. _gl.deleteBuffer( geometryGroup.__webglColorBuffer );
  6613. _gl.deleteBuffer( geometryGroup.__webglUVBuffer );
  6614. _gl.deleteBuffer( geometryGroup.__webglUV2Buffer );
  6615. _gl.deleteBuffer( geometryGroup.__webglSkinVertexABuffer );
  6616. _gl.deleteBuffer( geometryGroup.__webglSkinVertexBBuffer );
  6617. _gl.deleteBuffer( geometryGroup.__webglSkinIndicesBuffer );
  6618. _gl.deleteBuffer( geometryGroup.__webglSkinWeightsBuffer );
  6619. _gl.deleteBuffer( geometryGroup.__webglFaceBuffer );
  6620. _gl.deleteBuffer( geometryGroup.__webglLineBuffer );
  6621. var m, ml;
  6622. if ( geometryGroup.numMorphTargets ) {
  6623. for ( m = 0, ml = geometryGroup.numMorphTargets; m < ml; m ++ ) {
  6624. _gl.deleteBuffer( geometryGroup.__webglMorphTargetsBuffers[ m ] );
  6625. }
  6626. }
  6627. if ( geometryGroup.numMorphNormals ) {
  6628. for ( m = 0, ml = geometryGroup.numMorphNormals; m < ml; m ++ ) {
  6629. _gl.deleteBuffer( geometryGroup.__webglMorphNormalsBuffers[ m ] );
  6630. }
  6631. }
  6632. if ( geometryGroup.__webglCustomAttributesList ) {
  6633. for ( var id in geometryGroup.__webglCustomAttributesList ) {
  6634. _gl.deleteBuffer( geometryGroup.__webglCustomAttributesList[ id ].buffer );
  6635. }
  6636. }
  6637. _this.info.memory.geometries --;
  6638. };
  6639. // Buffer initialization
  6640. function initCustomAttributes ( geometry, object ) {
  6641. var nvertices = geometry.vertices.length;
  6642. var material = object.material;
  6643. if ( material.attributes ) {
  6644. if ( geometry.__webglCustomAttributesList === undefined ) {
  6645. geometry.__webglCustomAttributesList = [];
  6646. }
  6647. for ( var a in material.attributes ) {
  6648. var attribute = material.attributes[ a ];
  6649. if( !attribute.__webglInitialized || attribute.createUniqueBuffers ) {
  6650. attribute.__webglInitialized = true;
  6651. var size = 1; // "f" and "i"
  6652. if ( attribute.type === "v2" ) size = 2;
  6653. else if ( attribute.type === "v3" ) size = 3;
  6654. else if ( attribute.type === "v4" ) size = 4;
  6655. else if ( attribute.type === "c" ) size = 3;
  6656. attribute.size = size;
  6657. attribute.array = new Float32Array( nvertices * size );
  6658. attribute.buffer = _gl.createBuffer();
  6659. attribute.buffer.belongsToAttribute = a;
  6660. attribute.needsUpdate = true;
  6661. }
  6662. geometry.__webglCustomAttributesList.push( attribute );
  6663. }
  6664. }
  6665. };
  6666. function initParticleBuffers ( geometry, object ) {
  6667. var nvertices = geometry.vertices.length;
  6668. geometry.__vertexArray = new Float32Array( nvertices * 3 );
  6669. geometry.__colorArray = new Float32Array( nvertices * 3 );
  6670. geometry.__sortArray = [];
  6671. geometry.__webglParticleCount = nvertices;
  6672. initCustomAttributes ( geometry, object );
  6673. };
  6674. function initLineBuffers ( geometry, object ) {
  6675. var nvertices = geometry.vertices.length;
  6676. geometry.__vertexArray = new Float32Array( nvertices * 3 );
  6677. geometry.__colorArray = new Float32Array( nvertices * 3 );
  6678. geometry.__webglLineCount = nvertices;
  6679. initCustomAttributes ( geometry, object );
  6680. };
  6681. function initRibbonBuffers ( geometry ) {
  6682. var nvertices = geometry.vertices.length;
  6683. geometry.__vertexArray = new Float32Array( nvertices * 3 );
  6684. geometry.__colorArray = new Float32Array( nvertices * 3 );
  6685. geometry.__webglVertexCount = nvertices;
  6686. };
  6687. function initMeshBuffers ( geometryGroup, object ) {
  6688. var geometry = object.geometry,
  6689. faces3 = geometryGroup.faces3,
  6690. faces4 = geometryGroup.faces4,
  6691. nvertices = faces3.length * 3 + faces4.length * 4,
  6692. ntris = faces3.length * 1 + faces4.length * 2,
  6693. nlines = faces3.length * 3 + faces4.length * 4,
  6694. material = getBufferMaterial( object, geometryGroup ),
  6695. uvType = bufferGuessUVType( material ),
  6696. normalType = bufferGuessNormalType( material ),
  6697. vertexColorType = bufferGuessVertexColorType( material );
  6698. //console.log( "uvType", uvType, "normalType", normalType, "vertexColorType", vertexColorType, object, geometryGroup, material );
  6699. geometryGroup.__vertexArray = new Float32Array( nvertices * 3 );
  6700. if ( normalType ) {
  6701. geometryGroup.__normalArray = new Float32Array( nvertices * 3 );
  6702. }
  6703. if ( geometry.hasTangents ) {
  6704. geometryGroup.__tangentArray = new Float32Array( nvertices * 4 );
  6705. }
  6706. if ( vertexColorType ) {
  6707. geometryGroup.__colorArray = new Float32Array( nvertices * 3 );
  6708. }
  6709. if ( uvType ) {
  6710. if ( geometry.faceUvs.length > 0 || geometry.faceVertexUvs.length > 0 ) {
  6711. geometryGroup.__uvArray = new Float32Array( nvertices * 2 );
  6712. }
  6713. if ( geometry.faceUvs.length > 1 || geometry.faceVertexUvs.length > 1 ) {
  6714. geometryGroup.__uv2Array = new Float32Array( nvertices * 2 );
  6715. }
  6716. }
  6717. if ( object.geometry.skinWeights.length && object.geometry.skinIndices.length ) {
  6718. geometryGroup.__skinVertexAArray = new Float32Array( nvertices * 4 );
  6719. geometryGroup.__skinVertexBArray = new Float32Array( nvertices * 4 );
  6720. geometryGroup.__skinIndexArray = new Float32Array( nvertices * 4 );
  6721. geometryGroup.__skinWeightArray = new Float32Array( nvertices * 4 );
  6722. }
  6723. geometryGroup.__faceArray = new Uint16Array( ntris * 3 );
  6724. geometryGroup.__lineArray = new Uint16Array( nlines * 2 );
  6725. var m, ml;
  6726. if ( geometryGroup.numMorphTargets ) {
  6727. geometryGroup.__morphTargetsArrays = [];
  6728. for ( m = 0, ml = geometryGroup.numMorphTargets; m < ml; m ++ ) {
  6729. geometryGroup.__morphTargetsArrays.push( new Float32Array( nvertices * 3 ) );
  6730. }
  6731. }
  6732. if ( geometryGroup.numMorphNormals ) {
  6733. geometryGroup.__morphNormalsArrays = [];
  6734. for ( m = 0, ml = geometryGroup.numMorphNormals; m < ml; m ++ ) {
  6735. geometryGroup.__morphNormalsArrays.push( new Float32Array( nvertices * 3 ) );
  6736. }
  6737. }
  6738. geometryGroup.__webglFaceCount = ntris * 3;
  6739. geometryGroup.__webglLineCount = nlines * 2;
  6740. // custom attributes
  6741. if ( material.attributes ) {
  6742. if ( geometryGroup.__webglCustomAttributesList === undefined ) {
  6743. geometryGroup.__webglCustomAttributesList = [];
  6744. }
  6745. for ( var a in material.attributes ) {
  6746. // Do a shallow copy of the attribute object so different geometryGroup chunks use different
  6747. // attribute buffers which are correctly indexed in the setMeshBuffers function
  6748. var originalAttribute = material.attributes[ a ];
  6749. var attribute = {};
  6750. for ( var property in originalAttribute ) {
  6751. attribute[ property ] = originalAttribute[ property ];
  6752. }
  6753. if( !attribute.__webglInitialized || attribute.createUniqueBuffers ) {
  6754. attribute.__webglInitialized = true;
  6755. var size = 1; // "f" and "i"
  6756. if( attribute.type === "v2" ) size = 2;
  6757. else if( attribute.type === "v3" ) size = 3;
  6758. else if( attribute.type === "v4" ) size = 4;
  6759. else if( attribute.type === "c" ) size = 3;
  6760. attribute.size = size;
  6761. attribute.array = new Float32Array( nvertices * size );
  6762. attribute.buffer = _gl.createBuffer();
  6763. attribute.buffer.belongsToAttribute = a;
  6764. originalAttribute.needsUpdate = true;
  6765. attribute.__original = originalAttribute;
  6766. }
  6767. geometryGroup.__webglCustomAttributesList.push( attribute );
  6768. }
  6769. }
  6770. geometryGroup.__inittedArrays = true;
  6771. };
  6772. function getBufferMaterial( object, geometryGroup ) {
  6773. if ( object.material && ! ( object.material instanceof THREE.MeshFaceMaterial ) ) {
  6774. return object.material;
  6775. } else if ( geometryGroup.materialIndex >= 0 ) {
  6776. return object.geometry.materials[ geometryGroup.materialIndex ];
  6777. }
  6778. };
  6779. function materialNeedsSmoothNormals ( material ) {
  6780. return material && material.shading !== undefined && material.shading === THREE.SmoothShading;
  6781. };
  6782. function bufferGuessNormalType ( material ) {
  6783. // only MeshBasicMaterial and MeshDepthMaterial don't need normals
  6784. if ( ( material instanceof THREE.MeshBasicMaterial && !material.envMap ) || material instanceof THREE.MeshDepthMaterial ) {
  6785. return false;
  6786. }
  6787. if ( materialNeedsSmoothNormals( material ) ) {
  6788. return THREE.SmoothShading;
  6789. } else {
  6790. return THREE.FlatShading;
  6791. }
  6792. };
  6793. function bufferGuessVertexColorType ( material ) {
  6794. if ( material.vertexColors ) {
  6795. return material.vertexColors;
  6796. }
  6797. return false;
  6798. };
  6799. function bufferGuessUVType ( material ) {
  6800. // material must use some texture to require uvs
  6801. if ( material.map || material.lightMap || material instanceof THREE.ShaderMaterial ) {
  6802. return true;
  6803. }
  6804. return false;
  6805. };
  6806. // Buffer setting
  6807. function setParticleBuffers ( geometry, hint, object ) {
  6808. var v, c, vertex, offset, index, color,
  6809. vertices = geometry.vertices,
  6810. vl = vertices.length,
  6811. colors = geometry.colors,
  6812. cl = colors.length,
  6813. vertexArray = geometry.__vertexArray,
  6814. colorArray = geometry.__colorArray,
  6815. sortArray = geometry.__sortArray,
  6816. dirtyVertices = geometry.__dirtyVertices,
  6817. dirtyElements = geometry.__dirtyElements,
  6818. dirtyColors = geometry.__dirtyColors,
  6819. customAttributes = geometry.__webglCustomAttributesList,
  6820. i, il,
  6821. a, ca, cal, value,
  6822. customAttribute;
  6823. if ( object.sortParticles ) {
  6824. _projScreenMatrixPS.copy( _projScreenMatrix );
  6825. _projScreenMatrixPS.multiplySelf( object.matrixWorld );
  6826. for ( v = 0; v < vl; v ++ ) {
  6827. vertex = vertices[ v ];
  6828. _vector3.copy( vertex );
  6829. _projScreenMatrixPS.multiplyVector3( _vector3 );
  6830. sortArray[ v ] = [ _vector3.z, v ];
  6831. }
  6832. sortArray.sort( function( a, b ) { return b[ 0 ] - a[ 0 ]; } );
  6833. for ( v = 0; v < vl; v ++ ) {
  6834. vertex = vertices[ sortArray[v][1] ];
  6835. offset = v * 3;
  6836. vertexArray[ offset ] = vertex.x;
  6837. vertexArray[ offset + 1 ] = vertex.y;
  6838. vertexArray[ offset + 2 ] = vertex.z;
  6839. }
  6840. for ( c = 0; c < cl; c ++ ) {
  6841. offset = c * 3;
  6842. color = colors[ sortArray[c][1] ];
  6843. colorArray[ offset ] = color.r;
  6844. colorArray[ offset + 1 ] = color.g;
  6845. colorArray[ offset + 2 ] = color.b;
  6846. }
  6847. if ( customAttributes ) {
  6848. for ( i = 0, il = customAttributes.length; i < il; i ++ ) {
  6849. customAttribute = customAttributes[ i ];
  6850. if ( ! ( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) ) continue;
  6851. offset = 0;
  6852. cal = customAttribute.value.length;
  6853. if ( customAttribute.size === 1 ) {
  6854. for ( ca = 0; ca < cal; ca ++ ) {
  6855. index = sortArray[ ca ][ 1 ];
  6856. customAttribute.array[ ca ] = customAttribute.value[ index ];
  6857. }
  6858. } else if ( customAttribute.size === 2 ) {
  6859. for ( ca = 0; ca < cal; ca ++ ) {
  6860. index = sortArray[ ca ][ 1 ];
  6861. value = customAttribute.value[ index ];
  6862. customAttribute.array[ offset ] = value.x;
  6863. customAttribute.array[ offset + 1 ] = value.y;
  6864. offset += 2;
  6865. }
  6866. } else if ( customAttribute.size === 3 ) {
  6867. if ( customAttribute.type === "c" ) {
  6868. for ( ca = 0; ca < cal; ca ++ ) {
  6869. index = sortArray[ ca ][ 1 ];
  6870. value = customAttribute.value[ index ];
  6871. customAttribute.array[ offset ] = value.r;
  6872. customAttribute.array[ offset + 1 ] = value.g;
  6873. customAttribute.array[ offset + 2 ] = value.b;
  6874. offset += 3;
  6875. }
  6876. } else {
  6877. for ( ca = 0; ca < cal; ca ++ ) {
  6878. index = sortArray[ ca ][ 1 ];
  6879. value = customAttribute.value[ index ];
  6880. customAttribute.array[ offset ] = value.x;
  6881. customAttribute.array[ offset + 1 ] = value.y;
  6882. customAttribute.array[ offset + 2 ] = value.z;
  6883. offset += 3;
  6884. }
  6885. }
  6886. } else if ( customAttribute.size === 4 ) {
  6887. for ( ca = 0; ca < cal; ca ++ ) {
  6888. index = sortArray[ ca ][ 1 ];
  6889. value = customAttribute.value[ index ];
  6890. customAttribute.array[ offset ] = value.x;
  6891. customAttribute.array[ offset + 1 ] = value.y;
  6892. customAttribute.array[ offset + 2 ] = value.z;
  6893. customAttribute.array[ offset + 3 ] = value.w;
  6894. offset += 4;
  6895. }
  6896. }
  6897. }
  6898. }
  6899. } else {
  6900. if ( dirtyVertices ) {
  6901. for ( v = 0; v < vl; v ++ ) {
  6902. vertex = vertices[ v ];
  6903. offset = v * 3;
  6904. vertexArray[ offset ] = vertex.x;
  6905. vertexArray[ offset + 1 ] = vertex.y;
  6906. vertexArray[ offset + 2 ] = vertex.z;
  6907. }
  6908. }
  6909. if ( dirtyColors ) {
  6910. for ( c = 0; c < cl; c ++ ) {
  6911. color = colors[ c ];
  6912. offset = c * 3;
  6913. colorArray[ offset ] = color.r;
  6914. colorArray[ offset + 1 ] = color.g;
  6915. colorArray[ offset + 2 ] = color.b;
  6916. }
  6917. }
  6918. if ( customAttributes ) {
  6919. for ( i = 0, il = customAttributes.length; i < il; i ++ ) {
  6920. customAttribute = customAttributes[ i ];
  6921. if ( customAttribute.needsUpdate &&
  6922. ( customAttribute.boundTo === undefined ||
  6923. customAttribute.boundTo === "vertices") ) {
  6924. cal = customAttribute.value.length;
  6925. offset = 0;
  6926. if ( customAttribute.size === 1 ) {
  6927. for ( ca = 0; ca < cal; ca ++ ) {
  6928. customAttribute.array[ ca ] = customAttribute.value[ ca ];
  6929. }
  6930. } else if ( customAttribute.size === 2 ) {
  6931. for ( ca = 0; ca < cal; ca ++ ) {
  6932. value = customAttribute.value[ ca ];
  6933. customAttribute.array[ offset ] = value.x;
  6934. customAttribute.array[ offset + 1 ] = value.y;
  6935. offset += 2;
  6936. }
  6937. } else if ( customAttribute.size === 3 ) {
  6938. if ( customAttribute.type === "c" ) {
  6939. for ( ca = 0; ca < cal; ca ++ ) {
  6940. value = customAttribute.value[ ca ];
  6941. customAttribute.array[ offset ] = value.r;
  6942. customAttribute.array[ offset + 1 ] = value.g;
  6943. customAttribute.array[ offset + 2 ] = value.b;
  6944. offset += 3;
  6945. }
  6946. } else {
  6947. for ( ca = 0; ca < cal; ca ++ ) {
  6948. value = customAttribute.value[ ca ];
  6949. customAttribute.array[ offset ] = value.x;
  6950. customAttribute.array[ offset + 1 ] = value.y;
  6951. customAttribute.array[ offset + 2 ] = value.z;
  6952. offset += 3;
  6953. }
  6954. }
  6955. } else if ( customAttribute.size === 4 ) {
  6956. for ( ca = 0; ca < cal; ca ++ ) {
  6957. value = customAttribute.value[ ca ];
  6958. customAttribute.array[ offset ] = value.x;
  6959. customAttribute.array[ offset + 1 ] = value.y;
  6960. customAttribute.array[ offset + 2 ] = value.z;
  6961. customAttribute.array[ offset + 3 ] = value.w;
  6962. offset += 4;
  6963. }
  6964. }
  6965. }
  6966. }
  6967. }
  6968. }
  6969. if ( dirtyVertices || object.sortParticles ) {
  6970. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.__webglVertexBuffer );
  6971. _gl.bufferData( _gl.ARRAY_BUFFER, vertexArray, hint );
  6972. }
  6973. if ( dirtyColors || object.sortParticles ) {
  6974. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.__webglColorBuffer );
  6975. _gl.bufferData( _gl.ARRAY_BUFFER, colorArray, hint );
  6976. }
  6977. if ( customAttributes ) {
  6978. for ( i = 0, il = customAttributes.length; i < il; i ++ ) {
  6979. customAttribute = customAttributes[ i ];
  6980. if ( customAttribute.needsUpdate || object.sortParticles ) {
  6981. _gl.bindBuffer( _gl.ARRAY_BUFFER, customAttribute.buffer );
  6982. _gl.bufferData( _gl.ARRAY_BUFFER, customAttribute.array, hint );
  6983. }
  6984. }
  6985. }
  6986. };
  6987. function setLineBuffers ( geometry, hint ) {
  6988. var v, c, vertex, offset, color,
  6989. vertices = geometry.vertices,
  6990. colors = geometry.colors,
  6991. vl = vertices.length,
  6992. cl = colors.length,
  6993. vertexArray = geometry.__vertexArray,
  6994. colorArray = geometry.__colorArray,
  6995. dirtyVertices = geometry.__dirtyVertices,
  6996. dirtyColors = geometry.__dirtyColors,
  6997. customAttributes = geometry.__webglCustomAttributesList,
  6998. i, il,
  6999. a, ca, cal, value,
  7000. customAttribute;
  7001. if ( dirtyVertices ) {
  7002. for ( v = 0; v < vl; v ++ ) {
  7003. vertex = vertices[ v ];
  7004. offset = v * 3;
  7005. vertexArray[ offset ] = vertex.x;
  7006. vertexArray[ offset + 1 ] = vertex.y;
  7007. vertexArray[ offset + 2 ] = vertex.z;
  7008. }
  7009. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.__webglVertexBuffer );
  7010. _gl.bufferData( _gl.ARRAY_BUFFER, vertexArray, hint );
  7011. }
  7012. if ( dirtyColors ) {
  7013. for ( c = 0; c < cl; c ++ ) {
  7014. color = colors[ c ];
  7015. offset = c * 3;
  7016. colorArray[ offset ] = color.r;
  7017. colorArray[ offset + 1 ] = color.g;
  7018. colorArray[ offset + 2 ] = color.b;
  7019. }
  7020. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.__webglColorBuffer );
  7021. _gl.bufferData( _gl.ARRAY_BUFFER, colorArray, hint );
  7022. }
  7023. if ( customAttributes ) {
  7024. for ( i = 0, il = customAttributes.length; i < il; i ++ ) {
  7025. customAttribute = customAttributes[ i ];
  7026. if ( customAttribute.needsUpdate &&
  7027. ( customAttribute.boundTo === undefined ||
  7028. customAttribute.boundTo === "vertices" ) ) {
  7029. offset = 0;
  7030. cal = customAttribute.value.length;
  7031. if ( customAttribute.size === 1 ) {
  7032. for ( ca = 0; ca < cal; ca ++ ) {
  7033. customAttribute.array[ ca ] = customAttribute.value[ ca ];
  7034. }
  7035. } else if ( customAttribute.size === 2 ) {
  7036. for ( ca = 0; ca < cal; ca ++ ) {
  7037. value = customAttribute.value[ ca ];
  7038. customAttribute.array[ offset ] = value.x;
  7039. customAttribute.array[ offset + 1 ] = value.y;
  7040. offset += 2;
  7041. }
  7042. } else if ( customAttribute.size === 3 ) {
  7043. if ( customAttribute.type === "c" ) {
  7044. for ( ca = 0; ca < cal; ca ++ ) {
  7045. value = customAttribute.value[ ca ];
  7046. customAttribute.array[ offset ] = value.r;
  7047. customAttribute.array[ offset + 1 ] = value.g;
  7048. customAttribute.array[ offset + 2 ] = value.b;
  7049. offset += 3;
  7050. }
  7051. } else {
  7052. for ( ca = 0; ca < cal; ca ++ ) {
  7053. value = customAttribute.value[ ca ];
  7054. customAttribute.array[ offset ] = value.x;
  7055. customAttribute.array[ offset + 1 ] = value.y;
  7056. customAttribute.array[ offset + 2 ] = value.z;
  7057. offset += 3;
  7058. }
  7059. }
  7060. } else if ( customAttribute.size === 4 ) {
  7061. for ( ca = 0; ca < cal; ca ++ ) {
  7062. value = customAttribute.value[ ca ];
  7063. customAttribute.array[ offset ] = value.x;
  7064. customAttribute.array[ offset + 1 ] = value.y;
  7065. customAttribute.array[ offset + 2 ] = value.z;
  7066. customAttribute.array[ offset + 3 ] = value.w;
  7067. offset += 4;
  7068. }
  7069. }
  7070. _gl.bindBuffer( _gl.ARRAY_BUFFER, customAttribute.buffer );
  7071. _gl.bufferData( _gl.ARRAY_BUFFER, customAttribute.array, hint );
  7072. }
  7073. }
  7074. }
  7075. };
  7076. function setRibbonBuffers ( geometry, hint ) {
  7077. var v, c, vertex, offset, color,
  7078. vertices = geometry.vertices,
  7079. colors = geometry.colors,
  7080. vl = vertices.length,
  7081. cl = colors.length,
  7082. vertexArray = geometry.__vertexArray,
  7083. colorArray = geometry.__colorArray,
  7084. dirtyVertices = geometry.__dirtyVertices,
  7085. dirtyColors = geometry.__dirtyColors;
  7086. if ( dirtyVertices ) {
  7087. for ( v = 0; v < vl; v ++ ) {
  7088. vertex = vertices[ v ];
  7089. offset = v * 3;
  7090. vertexArray[ offset ] = vertex.x;
  7091. vertexArray[ offset + 1 ] = vertex.y;
  7092. vertexArray[ offset + 2 ] = vertex.z;
  7093. }
  7094. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.__webglVertexBuffer );
  7095. _gl.bufferData( _gl.ARRAY_BUFFER, vertexArray, hint );
  7096. }
  7097. if ( dirtyColors ) {
  7098. for ( c = 0; c < cl; c ++ ) {
  7099. color = colors[ c ];
  7100. offset = c * 3;
  7101. colorArray[ offset ] = color.r;
  7102. colorArray[ offset + 1 ] = color.g;
  7103. colorArray[ offset + 2 ] = color.b;
  7104. }
  7105. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.__webglColorBuffer );
  7106. _gl.bufferData( _gl.ARRAY_BUFFER, colorArray, hint );
  7107. }
  7108. };
  7109. function setMeshBuffers( geometryGroup, object, hint, dispose, material ) {
  7110. if ( ! geometryGroup.__inittedArrays ) {
  7111. // console.log( object );
  7112. return;
  7113. }
  7114. var normalType = bufferGuessNormalType( material ),
  7115. vertexColorType = bufferGuessVertexColorType( material ),
  7116. uvType = bufferGuessUVType( material ),
  7117. needsSmoothNormals = ( normalType === THREE.SmoothShading );
  7118. var f, fl, fi, face,
  7119. vertexNormals, faceNormal, normal,
  7120. vertexColors, faceColor,
  7121. vertexTangents,
  7122. uv, uv2, v1, v2, v3, v4, t1, t2, t3, t4, n1, n2, n3, n4,
  7123. c1, c2, c3, c4,
  7124. sw1, sw2, sw3, sw4,
  7125. si1, si2, si3, si4,
  7126. sa1, sa2, sa3, sa4,
  7127. sb1, sb2, sb3, sb4,
  7128. m, ml, i, il,
  7129. vn, uvi, uv2i,
  7130. vk, vkl, vka,
  7131. nka, chf, faceVertexNormals,
  7132. a,
  7133. vertexIndex = 0,
  7134. offset = 0,
  7135. offset_uv = 0,
  7136. offset_uv2 = 0,
  7137. offset_face = 0,
  7138. offset_normal = 0,
  7139. offset_tangent = 0,
  7140. offset_line = 0,
  7141. offset_color = 0,
  7142. offset_skin = 0,
  7143. offset_morphTarget = 0,
  7144. offset_custom = 0,
  7145. offset_customSrc = 0,
  7146. value,
  7147. vertexArray = geometryGroup.__vertexArray,
  7148. uvArray = geometryGroup.__uvArray,
  7149. uv2Array = geometryGroup.__uv2Array,
  7150. normalArray = geometryGroup.__normalArray,
  7151. tangentArray = geometryGroup.__tangentArray,
  7152. colorArray = geometryGroup.__colorArray,
  7153. skinVertexAArray = geometryGroup.__skinVertexAArray,
  7154. skinVertexBArray = geometryGroup.__skinVertexBArray,
  7155. skinIndexArray = geometryGroup.__skinIndexArray,
  7156. skinWeightArray = geometryGroup.__skinWeightArray,
  7157. morphTargetsArrays = geometryGroup.__morphTargetsArrays,
  7158. morphNormalsArrays = geometryGroup.__morphNormalsArrays,
  7159. customAttributes = geometryGroup.__webglCustomAttributesList,
  7160. customAttribute,
  7161. faceArray = geometryGroup.__faceArray,
  7162. lineArray = geometryGroup.__lineArray,
  7163. geometry = object.geometry, // this is shared for all chunks
  7164. dirtyVertices = geometry.__dirtyVertices,
  7165. dirtyElements = geometry.__dirtyElements,
  7166. dirtyUvs = geometry.__dirtyUvs,
  7167. dirtyNormals = geometry.__dirtyNormals,
  7168. dirtyTangents = geometry.__dirtyTangents,
  7169. dirtyColors = geometry.__dirtyColors,
  7170. dirtyMorphTargets = geometry.__dirtyMorphTargets,
  7171. vertices = geometry.vertices,
  7172. chunk_faces3 = geometryGroup.faces3,
  7173. chunk_faces4 = geometryGroup.faces4,
  7174. obj_faces = geometry.faces,
  7175. obj_uvs = geometry.faceVertexUvs[ 0 ],
  7176. obj_uvs2 = geometry.faceVertexUvs[ 1 ],
  7177. obj_colors = geometry.colors,
  7178. obj_skinVerticesA = geometry.skinVerticesA,
  7179. obj_skinVerticesB = geometry.skinVerticesB,
  7180. obj_skinIndices = geometry.skinIndices,
  7181. obj_skinWeights = geometry.skinWeights,
  7182. morphTargets = geometry.morphTargets,
  7183. morphNormals = geometry.morphNormals;
  7184. if ( dirtyVertices ) {
  7185. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  7186. face = obj_faces[ chunk_faces3[ f ] ];
  7187. v1 = vertices[ face.a ];
  7188. v2 = vertices[ face.b ];
  7189. v3 = vertices[ face.c ];
  7190. vertexArray[ offset ] = v1.x;
  7191. vertexArray[ offset + 1 ] = v1.y;
  7192. vertexArray[ offset + 2 ] = v1.z;
  7193. vertexArray[ offset + 3 ] = v2.x;
  7194. vertexArray[ offset + 4 ] = v2.y;
  7195. vertexArray[ offset + 5 ] = v2.z;
  7196. vertexArray[ offset + 6 ] = v3.x;
  7197. vertexArray[ offset + 7 ] = v3.y;
  7198. vertexArray[ offset + 8 ] = v3.z;
  7199. offset += 9;
  7200. }
  7201. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  7202. face = obj_faces[ chunk_faces4[ f ] ];
  7203. v1 = vertices[ face.a ];
  7204. v2 = vertices[ face.b ];
  7205. v3 = vertices[ face.c ];
  7206. v4 = vertices[ face.d ];
  7207. vertexArray[ offset ] = v1.x;
  7208. vertexArray[ offset + 1 ] = v1.y;
  7209. vertexArray[ offset + 2 ] = v1.z;
  7210. vertexArray[ offset + 3 ] = v2.x;
  7211. vertexArray[ offset + 4 ] = v2.y;
  7212. vertexArray[ offset + 5 ] = v2.z;
  7213. vertexArray[ offset + 6 ] = v3.x;
  7214. vertexArray[ offset + 7 ] = v3.y;
  7215. vertexArray[ offset + 8 ] = v3.z;
  7216. vertexArray[ offset + 9 ] = v4.x;
  7217. vertexArray[ offset + 10 ] = v4.y;
  7218. vertexArray[ offset + 11 ] = v4.z;
  7219. offset += 12;
  7220. }
  7221. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglVertexBuffer );
  7222. _gl.bufferData( _gl.ARRAY_BUFFER, vertexArray, hint );
  7223. }
  7224. if ( dirtyMorphTargets ) {
  7225. for ( vk = 0, vkl = morphTargets.length; vk < vkl; vk ++ ) {
  7226. offset_morphTarget = 0;
  7227. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  7228. chf = chunk_faces3[ f ];
  7229. face = obj_faces[ chf ];
  7230. // morph positions
  7231. v1 = morphTargets[ vk ].vertices[ face.a ];
  7232. v2 = morphTargets[ vk ].vertices[ face.b ];
  7233. v3 = morphTargets[ vk ].vertices[ face.c ];
  7234. vka = morphTargetsArrays[ vk ];
  7235. vka[ offset_morphTarget ] = v1.x;
  7236. vka[ offset_morphTarget + 1 ] = v1.y;
  7237. vka[ offset_morphTarget + 2 ] = v1.z;
  7238. vka[ offset_morphTarget + 3 ] = v2.x;
  7239. vka[ offset_morphTarget + 4 ] = v2.y;
  7240. vka[ offset_morphTarget + 5 ] = v2.z;
  7241. vka[ offset_morphTarget + 6 ] = v3.x;
  7242. vka[ offset_morphTarget + 7 ] = v3.y;
  7243. vka[ offset_morphTarget + 8 ] = v3.z;
  7244. // morph normals
  7245. if ( material.morphNormals ) {
  7246. if ( needsSmoothNormals ) {
  7247. faceVertexNormals = morphNormals[ vk ].vertexNormals[ chf ];
  7248. n1 = faceVertexNormals.a;
  7249. n2 = faceVertexNormals.b;
  7250. n3 = faceVertexNormals.c;
  7251. } else {
  7252. n1 = morphNormals[ vk ].faceNormals[ chf ];
  7253. n2 = n1;
  7254. n3 = n1;
  7255. }
  7256. nka = morphNormalsArrays[ vk ];
  7257. nka[ offset_morphTarget ] = n1.x;
  7258. nka[ offset_morphTarget + 1 ] = n1.y;
  7259. nka[ offset_morphTarget + 2 ] = n1.z;
  7260. nka[ offset_morphTarget + 3 ] = n2.x;
  7261. nka[ offset_morphTarget + 4 ] = n2.y;
  7262. nka[ offset_morphTarget + 5 ] = n2.z;
  7263. nka[ offset_morphTarget + 6 ] = n3.x;
  7264. nka[ offset_morphTarget + 7 ] = n3.y;
  7265. nka[ offset_morphTarget + 8 ] = n3.z;
  7266. }
  7267. //
  7268. offset_morphTarget += 9;
  7269. }
  7270. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  7271. chf = chunk_faces4[ f ];
  7272. face = obj_faces[ chf ];
  7273. // morph positions
  7274. v1 = morphTargets[ vk ].vertices[ face.a ];
  7275. v2 = morphTargets[ vk ].vertices[ face.b ];
  7276. v3 = morphTargets[ vk ].vertices[ face.c ];
  7277. v4 = morphTargets[ vk ].vertices[ face.d ];
  7278. vka = morphTargetsArrays[ vk ];
  7279. vka[ offset_morphTarget ] = v1.x;
  7280. vka[ offset_morphTarget + 1 ] = v1.y;
  7281. vka[ offset_morphTarget + 2 ] = v1.z;
  7282. vka[ offset_morphTarget + 3 ] = v2.x;
  7283. vka[ offset_morphTarget + 4 ] = v2.y;
  7284. vka[ offset_morphTarget + 5 ] = v2.z;
  7285. vka[ offset_morphTarget + 6 ] = v3.x;
  7286. vka[ offset_morphTarget + 7 ] = v3.y;
  7287. vka[ offset_morphTarget + 8 ] = v3.z;
  7288. vka[ offset_morphTarget + 9 ] = v4.x;
  7289. vka[ offset_morphTarget + 10 ] = v4.y;
  7290. vka[ offset_morphTarget + 11 ] = v4.z;
  7291. // morph normals
  7292. if ( material.morphNormals ) {
  7293. if ( needsSmoothNormals ) {
  7294. faceVertexNormals = morphNormals[ vk ].vertexNormals[ chf ];
  7295. n1 = faceVertexNormals.a;
  7296. n2 = faceVertexNormals.b;
  7297. n3 = faceVertexNormals.c;
  7298. n4 = faceVertexNormals.d;
  7299. } else {
  7300. n1 = morphNormals[ vk ].faceNormals[ chf ];
  7301. n2 = n1;
  7302. n3 = n1;
  7303. n4 = n1;
  7304. }
  7305. nka = morphNormalsArrays[ vk ];
  7306. nka[ offset_morphTarget ] = n1.x;
  7307. nka[ offset_morphTarget + 1 ] = n1.y;
  7308. nka[ offset_morphTarget + 2 ] = n1.z;
  7309. nka[ offset_morphTarget + 3 ] = n2.x;
  7310. nka[ offset_morphTarget + 4 ] = n2.y;
  7311. nka[ offset_morphTarget + 5 ] = n2.z;
  7312. nka[ offset_morphTarget + 6 ] = n3.x;
  7313. nka[ offset_morphTarget + 7 ] = n3.y;
  7314. nka[ offset_morphTarget + 8 ] = n3.z;
  7315. nka[ offset_morphTarget + 9 ] = n4.x;
  7316. nka[ offset_morphTarget + 10 ] = n4.y;
  7317. nka[ offset_morphTarget + 11 ] = n4.z;
  7318. }
  7319. //
  7320. offset_morphTarget += 12;
  7321. }
  7322. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ vk ] );
  7323. _gl.bufferData( _gl.ARRAY_BUFFER, morphTargetsArrays[ vk ], hint );
  7324. if ( material.morphNormals ) {
  7325. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphNormalsBuffers[ vk ] );
  7326. _gl.bufferData( _gl.ARRAY_BUFFER, morphNormalsArrays[ vk ], hint );
  7327. }
  7328. }
  7329. }
  7330. if ( obj_skinWeights.length ) {
  7331. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  7332. face = obj_faces[ chunk_faces3[ f ] ];
  7333. // weights
  7334. sw1 = obj_skinWeights[ face.a ];
  7335. sw2 = obj_skinWeights[ face.b ];
  7336. sw3 = obj_skinWeights[ face.c ];
  7337. skinWeightArray[ offset_skin ] = sw1.x;
  7338. skinWeightArray[ offset_skin + 1 ] = sw1.y;
  7339. skinWeightArray[ offset_skin + 2 ] = sw1.z;
  7340. skinWeightArray[ offset_skin + 3 ] = sw1.w;
  7341. skinWeightArray[ offset_skin + 4 ] = sw2.x;
  7342. skinWeightArray[ offset_skin + 5 ] = sw2.y;
  7343. skinWeightArray[ offset_skin + 6 ] = sw2.z;
  7344. skinWeightArray[ offset_skin + 7 ] = sw2.w;
  7345. skinWeightArray[ offset_skin + 8 ] = sw3.x;
  7346. skinWeightArray[ offset_skin + 9 ] = sw3.y;
  7347. skinWeightArray[ offset_skin + 10 ] = sw3.z;
  7348. skinWeightArray[ offset_skin + 11 ] = sw3.w;
  7349. // indices
  7350. si1 = obj_skinIndices[ face.a ];
  7351. si2 = obj_skinIndices[ face.b ];
  7352. si3 = obj_skinIndices[ face.c ];
  7353. skinIndexArray[ offset_skin ] = si1.x;
  7354. skinIndexArray[ offset_skin + 1 ] = si1.y;
  7355. skinIndexArray[ offset_skin + 2 ] = si1.z;
  7356. skinIndexArray[ offset_skin + 3 ] = si1.w;
  7357. skinIndexArray[ offset_skin + 4 ] = si2.x;
  7358. skinIndexArray[ offset_skin + 5 ] = si2.y;
  7359. skinIndexArray[ offset_skin + 6 ] = si2.z;
  7360. skinIndexArray[ offset_skin + 7 ] = si2.w;
  7361. skinIndexArray[ offset_skin + 8 ] = si3.x;
  7362. skinIndexArray[ offset_skin + 9 ] = si3.y;
  7363. skinIndexArray[ offset_skin + 10 ] = si3.z;
  7364. skinIndexArray[ offset_skin + 11 ] = si3.w;
  7365. // vertices A
  7366. sa1 = obj_skinVerticesA[ face.a ];
  7367. sa2 = obj_skinVerticesA[ face.b ];
  7368. sa3 = obj_skinVerticesA[ face.c ];
  7369. skinVertexAArray[ offset_skin ] = sa1.x;
  7370. skinVertexAArray[ offset_skin + 1 ] = sa1.y;
  7371. skinVertexAArray[ offset_skin + 2 ] = sa1.z;
  7372. skinVertexAArray[ offset_skin + 3 ] = 1; // pad for faster vertex shader
  7373. skinVertexAArray[ offset_skin + 4 ] = sa2.x;
  7374. skinVertexAArray[ offset_skin + 5 ] = sa2.y;
  7375. skinVertexAArray[ offset_skin + 6 ] = sa2.z;
  7376. skinVertexAArray[ offset_skin + 7 ] = 1;
  7377. skinVertexAArray[ offset_skin + 8 ] = sa3.x;
  7378. skinVertexAArray[ offset_skin + 9 ] = sa3.y;
  7379. skinVertexAArray[ offset_skin + 10 ] = sa3.z;
  7380. skinVertexAArray[ offset_skin + 11 ] = 1;
  7381. // vertices B
  7382. sb1 = obj_skinVerticesB[ face.a ];
  7383. sb2 = obj_skinVerticesB[ face.b ];
  7384. sb3 = obj_skinVerticesB[ face.c ];
  7385. skinVertexBArray[ offset_skin ] = sb1.x;
  7386. skinVertexBArray[ offset_skin + 1 ] = sb1.y;
  7387. skinVertexBArray[ offset_skin + 2 ] = sb1.z;
  7388. skinVertexBArray[ offset_skin + 3 ] = 1; // pad for faster vertex shader
  7389. skinVertexBArray[ offset_skin + 4 ] = sb2.x;
  7390. skinVertexBArray[ offset_skin + 5 ] = sb2.y;
  7391. skinVertexBArray[ offset_skin + 6 ] = sb2.z;
  7392. skinVertexBArray[ offset_skin + 7 ] = 1;
  7393. skinVertexBArray[ offset_skin + 8 ] = sb3.x;
  7394. skinVertexBArray[ offset_skin + 9 ] = sb3.y;
  7395. skinVertexBArray[ offset_skin + 10 ] = sb3.z;
  7396. skinVertexBArray[ offset_skin + 11 ] = 1;
  7397. offset_skin += 12;
  7398. }
  7399. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  7400. face = obj_faces[ chunk_faces4[ f ] ];
  7401. // weights
  7402. sw1 = obj_skinWeights[ face.a ];
  7403. sw2 = obj_skinWeights[ face.b ];
  7404. sw3 = obj_skinWeights[ face.c ];
  7405. sw4 = obj_skinWeights[ face.d ];
  7406. skinWeightArray[ offset_skin ] = sw1.x;
  7407. skinWeightArray[ offset_skin + 1 ] = sw1.y;
  7408. skinWeightArray[ offset_skin + 2 ] = sw1.z;
  7409. skinWeightArray[ offset_skin + 3 ] = sw1.w;
  7410. skinWeightArray[ offset_skin + 4 ] = sw2.x;
  7411. skinWeightArray[ offset_skin + 5 ] = sw2.y;
  7412. skinWeightArray[ offset_skin + 6 ] = sw2.z;
  7413. skinWeightArray[ offset_skin + 7 ] = sw2.w;
  7414. skinWeightArray[ offset_skin + 8 ] = sw3.x;
  7415. skinWeightArray[ offset_skin + 9 ] = sw3.y;
  7416. skinWeightArray[ offset_skin + 10 ] = sw3.z;
  7417. skinWeightArray[ offset_skin + 11 ] = sw3.w;
  7418. skinWeightArray[ offset_skin + 12 ] = sw4.x;
  7419. skinWeightArray[ offset_skin + 13 ] = sw4.y;
  7420. skinWeightArray[ offset_skin + 14 ] = sw4.z;
  7421. skinWeightArray[ offset_skin + 15 ] = sw4.w;
  7422. // indices
  7423. si1 = obj_skinIndices[ face.a ];
  7424. si2 = obj_skinIndices[ face.b ];
  7425. si3 = obj_skinIndices[ face.c ];
  7426. si4 = obj_skinIndices[ face.d ];
  7427. skinIndexArray[ offset_skin ] = si1.x;
  7428. skinIndexArray[ offset_skin + 1 ] = si1.y;
  7429. skinIndexArray[ offset_skin + 2 ] = si1.z;
  7430. skinIndexArray[ offset_skin + 3 ] = si1.w;
  7431. skinIndexArray[ offset_skin + 4 ] = si2.x;
  7432. skinIndexArray[ offset_skin + 5 ] = si2.y;
  7433. skinIndexArray[ offset_skin + 6 ] = si2.z;
  7434. skinIndexArray[ offset_skin + 7 ] = si2.w;
  7435. skinIndexArray[ offset_skin + 8 ] = si3.x;
  7436. skinIndexArray[ offset_skin + 9 ] = si3.y;
  7437. skinIndexArray[ offset_skin + 10 ] = si3.z;
  7438. skinIndexArray[ offset_skin + 11 ] = si3.w;
  7439. skinIndexArray[ offset_skin + 12 ] = si4.x;
  7440. skinIndexArray[ offset_skin + 13 ] = si4.y;
  7441. skinIndexArray[ offset_skin + 14 ] = si4.z;
  7442. skinIndexArray[ offset_skin + 15 ] = si4.w;
  7443. // vertices A
  7444. sa1 = obj_skinVerticesA[ face.a ];
  7445. sa2 = obj_skinVerticesA[ face.b ];
  7446. sa3 = obj_skinVerticesA[ face.c ];
  7447. sa4 = obj_skinVerticesA[ face.d ];
  7448. skinVertexAArray[ offset_skin ] = sa1.x;
  7449. skinVertexAArray[ offset_skin + 1 ] = sa1.y;
  7450. skinVertexAArray[ offset_skin + 2 ] = sa1.z;
  7451. skinVertexAArray[ offset_skin + 3 ] = 1; // pad for faster vertex shader
  7452. skinVertexAArray[ offset_skin + 4 ] = sa2.x;
  7453. skinVertexAArray[ offset_skin + 5 ] = sa2.y;
  7454. skinVertexAArray[ offset_skin + 6 ] = sa2.z;
  7455. skinVertexAArray[ offset_skin + 7 ] = 1;
  7456. skinVertexAArray[ offset_skin + 8 ] = sa3.x;
  7457. skinVertexAArray[ offset_skin + 9 ] = sa3.y;
  7458. skinVertexAArray[ offset_skin + 10 ] = sa3.z;
  7459. skinVertexAArray[ offset_skin + 11 ] = 1;
  7460. skinVertexAArray[ offset_skin + 12 ] = sa4.x;
  7461. skinVertexAArray[ offset_skin + 13 ] = sa4.y;
  7462. skinVertexAArray[ offset_skin + 14 ] = sa4.z;
  7463. skinVertexAArray[ offset_skin + 15 ] = 1;
  7464. // vertices B
  7465. sb1 = obj_skinVerticesB[ face.a ];
  7466. sb2 = obj_skinVerticesB[ face.b ];
  7467. sb3 = obj_skinVerticesB[ face.c ];
  7468. sb4 = obj_skinVerticesB[ face.d ];
  7469. skinVertexBArray[ offset_skin ] = sb1.x;
  7470. skinVertexBArray[ offset_skin + 1 ] = sb1.y;
  7471. skinVertexBArray[ offset_skin + 2 ] = sb1.z;
  7472. skinVertexBArray[ offset_skin + 3 ] = 1; // pad for faster vertex shader
  7473. skinVertexBArray[ offset_skin + 4 ] = sb2.x;
  7474. skinVertexBArray[ offset_skin + 5 ] = sb2.y;
  7475. skinVertexBArray[ offset_skin + 6 ] = sb2.z;
  7476. skinVertexBArray[ offset_skin + 7 ] = 1;
  7477. skinVertexBArray[ offset_skin + 8 ] = sb3.x;
  7478. skinVertexBArray[ offset_skin + 9 ] = sb3.y;
  7479. skinVertexBArray[ offset_skin + 10 ] = sb3.z;
  7480. skinVertexBArray[ offset_skin + 11 ] = 1;
  7481. skinVertexBArray[ offset_skin + 12 ] = sb4.x;
  7482. skinVertexBArray[ offset_skin + 13 ] = sb4.y;
  7483. skinVertexBArray[ offset_skin + 14 ] = sb4.z;
  7484. skinVertexBArray[ offset_skin + 15 ] = 1;
  7485. offset_skin += 16;
  7486. }
  7487. if ( offset_skin > 0 ) {
  7488. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglSkinVertexABuffer );
  7489. _gl.bufferData( _gl.ARRAY_BUFFER, skinVertexAArray, hint );
  7490. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglSkinVertexBBuffer );
  7491. _gl.bufferData( _gl.ARRAY_BUFFER, skinVertexBArray, hint );
  7492. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglSkinIndicesBuffer );
  7493. _gl.bufferData( _gl.ARRAY_BUFFER, skinIndexArray, hint );
  7494. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglSkinWeightsBuffer );
  7495. _gl.bufferData( _gl.ARRAY_BUFFER, skinWeightArray, hint );
  7496. }
  7497. }
  7498. if ( dirtyColors && vertexColorType ) {
  7499. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  7500. face = obj_faces[ chunk_faces3[ f ] ];
  7501. vertexColors = face.vertexColors;
  7502. faceColor = face.color;
  7503. if ( vertexColors.length === 3 && vertexColorType === THREE.VertexColors ) {
  7504. c1 = vertexColors[ 0 ];
  7505. c2 = vertexColors[ 1 ];
  7506. c3 = vertexColors[ 2 ];
  7507. } else {
  7508. c1 = faceColor;
  7509. c2 = faceColor;
  7510. c3 = faceColor;
  7511. }
  7512. colorArray[ offset_color ] = c1.r;
  7513. colorArray[ offset_color + 1 ] = c1.g;
  7514. colorArray[ offset_color + 2 ] = c1.b;
  7515. colorArray[ offset_color + 3 ] = c2.r;
  7516. colorArray[ offset_color + 4 ] = c2.g;
  7517. colorArray[ offset_color + 5 ] = c2.b;
  7518. colorArray[ offset_color + 6 ] = c3.r;
  7519. colorArray[ offset_color + 7 ] = c3.g;
  7520. colorArray[ offset_color + 8 ] = c3.b;
  7521. offset_color += 9;
  7522. }
  7523. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  7524. face = obj_faces[ chunk_faces4[ f ] ];
  7525. vertexColors = face.vertexColors;
  7526. faceColor = face.color;
  7527. if ( vertexColors.length === 4 && vertexColorType === THREE.VertexColors ) {
  7528. c1 = vertexColors[ 0 ];
  7529. c2 = vertexColors[ 1 ];
  7530. c3 = vertexColors[ 2 ];
  7531. c4 = vertexColors[ 3 ];
  7532. } else {
  7533. c1 = faceColor;
  7534. c2 = faceColor;
  7535. c3 = faceColor;
  7536. c4 = faceColor;
  7537. }
  7538. colorArray[ offset_color ] = c1.r;
  7539. colorArray[ offset_color + 1 ] = c1.g;
  7540. colorArray[ offset_color + 2 ] = c1.b;
  7541. colorArray[ offset_color + 3 ] = c2.r;
  7542. colorArray[ offset_color + 4 ] = c2.g;
  7543. colorArray[ offset_color + 5 ] = c2.b;
  7544. colorArray[ offset_color + 6 ] = c3.r;
  7545. colorArray[ offset_color + 7 ] = c3.g;
  7546. colorArray[ offset_color + 8 ] = c3.b;
  7547. colorArray[ offset_color + 9 ] = c4.r;
  7548. colorArray[ offset_color + 10 ] = c4.g;
  7549. colorArray[ offset_color + 11 ] = c4.b;
  7550. offset_color += 12;
  7551. }
  7552. if ( offset_color > 0 ) {
  7553. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglColorBuffer );
  7554. _gl.bufferData( _gl.ARRAY_BUFFER, colorArray, hint );
  7555. }
  7556. }
  7557. if ( dirtyTangents && geometry.hasTangents ) {
  7558. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  7559. face = obj_faces[ chunk_faces3[ f ] ];
  7560. vertexTangents = face.vertexTangents;
  7561. t1 = vertexTangents[ 0 ];
  7562. t2 = vertexTangents[ 1 ];
  7563. t3 = vertexTangents[ 2 ];
  7564. tangentArray[ offset_tangent ] = t1.x;
  7565. tangentArray[ offset_tangent + 1 ] = t1.y;
  7566. tangentArray[ offset_tangent + 2 ] = t1.z;
  7567. tangentArray[ offset_tangent + 3 ] = t1.w;
  7568. tangentArray[ offset_tangent + 4 ] = t2.x;
  7569. tangentArray[ offset_tangent + 5 ] = t2.y;
  7570. tangentArray[ offset_tangent + 6 ] = t2.z;
  7571. tangentArray[ offset_tangent + 7 ] = t2.w;
  7572. tangentArray[ offset_tangent + 8 ] = t3.x;
  7573. tangentArray[ offset_tangent + 9 ] = t3.y;
  7574. tangentArray[ offset_tangent + 10 ] = t3.z;
  7575. tangentArray[ offset_tangent + 11 ] = t3.w;
  7576. offset_tangent += 12;
  7577. }
  7578. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  7579. face = obj_faces[ chunk_faces4[ f ] ];
  7580. vertexTangents = face.vertexTangents;
  7581. t1 = vertexTangents[ 0 ];
  7582. t2 = vertexTangents[ 1 ];
  7583. t3 = vertexTangents[ 2 ];
  7584. t4 = vertexTangents[ 3 ];
  7585. tangentArray[ offset_tangent ] = t1.x;
  7586. tangentArray[ offset_tangent + 1 ] = t1.y;
  7587. tangentArray[ offset_tangent + 2 ] = t1.z;
  7588. tangentArray[ offset_tangent + 3 ] = t1.w;
  7589. tangentArray[ offset_tangent + 4 ] = t2.x;
  7590. tangentArray[ offset_tangent + 5 ] = t2.y;
  7591. tangentArray[ offset_tangent + 6 ] = t2.z;
  7592. tangentArray[ offset_tangent + 7 ] = t2.w;
  7593. tangentArray[ offset_tangent + 8 ] = t3.x;
  7594. tangentArray[ offset_tangent + 9 ] = t3.y;
  7595. tangentArray[ offset_tangent + 10 ] = t3.z;
  7596. tangentArray[ offset_tangent + 11 ] = t3.w;
  7597. tangentArray[ offset_tangent + 12 ] = t4.x;
  7598. tangentArray[ offset_tangent + 13 ] = t4.y;
  7599. tangentArray[ offset_tangent + 14 ] = t4.z;
  7600. tangentArray[ offset_tangent + 15 ] = t4.w;
  7601. offset_tangent += 16;
  7602. }
  7603. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglTangentBuffer );
  7604. _gl.bufferData( _gl.ARRAY_BUFFER, tangentArray, hint );
  7605. }
  7606. if ( dirtyNormals && normalType ) {
  7607. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  7608. face = obj_faces[ chunk_faces3[ f ] ];
  7609. vertexNormals = face.vertexNormals;
  7610. faceNormal = face.normal;
  7611. if ( vertexNormals.length === 3 && needsSmoothNormals ) {
  7612. for ( i = 0; i < 3; i ++ ) {
  7613. vn = vertexNormals[ i ];
  7614. normalArray[ offset_normal ] = vn.x;
  7615. normalArray[ offset_normal + 1 ] = vn.y;
  7616. normalArray[ offset_normal + 2 ] = vn.z;
  7617. offset_normal += 3;
  7618. }
  7619. } else {
  7620. for ( i = 0; i < 3; i ++ ) {
  7621. normalArray[ offset_normal ] = faceNormal.x;
  7622. normalArray[ offset_normal + 1 ] = faceNormal.y;
  7623. normalArray[ offset_normal + 2 ] = faceNormal.z;
  7624. offset_normal += 3;
  7625. }
  7626. }
  7627. }
  7628. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  7629. face = obj_faces[ chunk_faces4[ f ] ];
  7630. vertexNormals = face.vertexNormals;
  7631. faceNormal = face.normal;
  7632. if ( vertexNormals.length === 4 && needsSmoothNormals ) {
  7633. for ( i = 0; i < 4; i ++ ) {
  7634. vn = vertexNormals[ i ];
  7635. normalArray[ offset_normal ] = vn.x;
  7636. normalArray[ offset_normal + 1 ] = vn.y;
  7637. normalArray[ offset_normal + 2 ] = vn.z;
  7638. offset_normal += 3;
  7639. }
  7640. } else {
  7641. for ( i = 0; i < 4; i ++ ) {
  7642. normalArray[ offset_normal ] = faceNormal.x;
  7643. normalArray[ offset_normal + 1 ] = faceNormal.y;
  7644. normalArray[ offset_normal + 2 ] = faceNormal.z;
  7645. offset_normal += 3;
  7646. }
  7647. }
  7648. }
  7649. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglNormalBuffer );
  7650. _gl.bufferData( _gl.ARRAY_BUFFER, normalArray, hint );
  7651. }
  7652. if ( dirtyUvs && obj_uvs && uvType ) {
  7653. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  7654. fi = chunk_faces3[ f ];
  7655. face = obj_faces[ fi ];
  7656. uv = obj_uvs[ fi ];
  7657. if ( uv === undefined ) continue;
  7658. for ( i = 0; i < 3; i ++ ) {
  7659. uvi = uv[ i ];
  7660. uvArray[ offset_uv ] = uvi.u;
  7661. uvArray[ offset_uv + 1 ] = uvi.v;
  7662. offset_uv += 2;
  7663. }
  7664. }
  7665. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  7666. fi = chunk_faces4[ f ];
  7667. face = obj_faces[ fi ];
  7668. uv = obj_uvs[ fi ];
  7669. if ( uv === undefined ) continue;
  7670. for ( i = 0; i < 4; i ++ ) {
  7671. uvi = uv[ i ];
  7672. uvArray[ offset_uv ] = uvi.u;
  7673. uvArray[ offset_uv + 1 ] = uvi.v;
  7674. offset_uv += 2;
  7675. }
  7676. }
  7677. if ( offset_uv > 0 ) {
  7678. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglUVBuffer );
  7679. _gl.bufferData( _gl.ARRAY_BUFFER, uvArray, hint );
  7680. }
  7681. }
  7682. if ( dirtyUvs && obj_uvs2 && uvType ) {
  7683. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  7684. fi = chunk_faces3[ f ];
  7685. face = obj_faces[ fi ];
  7686. uv2 = obj_uvs2[ fi ];
  7687. if ( uv2 === undefined ) continue;
  7688. for ( i = 0; i < 3; i ++ ) {
  7689. uv2i = uv2[ i ];
  7690. uv2Array[ offset_uv2 ] = uv2i.u;
  7691. uv2Array[ offset_uv2 + 1 ] = uv2i.v;
  7692. offset_uv2 += 2;
  7693. }
  7694. }
  7695. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  7696. fi = chunk_faces4[ f ];
  7697. face = obj_faces[ fi ];
  7698. uv2 = obj_uvs2[ fi ];
  7699. if ( uv2 === undefined ) continue;
  7700. for ( i = 0; i < 4; i ++ ) {
  7701. uv2i = uv2[ i ];
  7702. uv2Array[ offset_uv2 ] = uv2i.u;
  7703. uv2Array[ offset_uv2 + 1 ] = uv2i.v;
  7704. offset_uv2 += 2;
  7705. }
  7706. }
  7707. if ( offset_uv2 > 0 ) {
  7708. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglUV2Buffer );
  7709. _gl.bufferData( _gl.ARRAY_BUFFER, uv2Array, hint );
  7710. }
  7711. }
  7712. if ( dirtyElements ) {
  7713. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  7714. face = obj_faces[ chunk_faces3[ f ] ];
  7715. faceArray[ offset_face ] = vertexIndex;
  7716. faceArray[ offset_face + 1 ] = vertexIndex + 1;
  7717. faceArray[ offset_face + 2 ] = vertexIndex + 2;
  7718. offset_face += 3;
  7719. lineArray[ offset_line ] = vertexIndex;
  7720. lineArray[ offset_line + 1 ] = vertexIndex + 1;
  7721. lineArray[ offset_line + 2 ] = vertexIndex;
  7722. lineArray[ offset_line + 3 ] = vertexIndex + 2;
  7723. lineArray[ offset_line + 4 ] = vertexIndex + 1;
  7724. lineArray[ offset_line + 5 ] = vertexIndex + 2;
  7725. offset_line += 6;
  7726. vertexIndex += 3;
  7727. }
  7728. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  7729. face = obj_faces[ chunk_faces4[ f ] ];
  7730. faceArray[ offset_face ] = vertexIndex;
  7731. faceArray[ offset_face + 1 ] = vertexIndex + 1;
  7732. faceArray[ offset_face + 2 ] = vertexIndex + 3;
  7733. faceArray[ offset_face + 3 ] = vertexIndex + 1;
  7734. faceArray[ offset_face + 4 ] = vertexIndex + 2;
  7735. faceArray[ offset_face + 5 ] = vertexIndex + 3;
  7736. offset_face += 6;
  7737. lineArray[ offset_line ] = vertexIndex;
  7738. lineArray[ offset_line + 1 ] = vertexIndex + 1;
  7739. lineArray[ offset_line + 2 ] = vertexIndex;
  7740. lineArray[ offset_line + 3 ] = vertexIndex + 3;
  7741. lineArray[ offset_line + 4 ] = vertexIndex + 1;
  7742. lineArray[ offset_line + 5 ] = vertexIndex + 2;
  7743. lineArray[ offset_line + 6 ] = vertexIndex + 2;
  7744. lineArray[ offset_line + 7 ] = vertexIndex + 3;
  7745. offset_line += 8;
  7746. vertexIndex += 4;
  7747. }
  7748. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, geometryGroup.__webglFaceBuffer );
  7749. _gl.bufferData( _gl.ELEMENT_ARRAY_BUFFER, faceArray, hint );
  7750. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, geometryGroup.__webglLineBuffer );
  7751. _gl.bufferData( _gl.ELEMENT_ARRAY_BUFFER, lineArray, hint );
  7752. }
  7753. if ( customAttributes ) {
  7754. for ( i = 0, il = customAttributes.length; i < il; i ++ ) {
  7755. customAttribute = customAttributes[ i ];
  7756. if ( ! customAttribute.__original.needsUpdate ) continue;
  7757. offset_custom = 0;
  7758. offset_customSrc = 0;
  7759. if ( customAttribute.size === 1 ) {
  7760. if ( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) {
  7761. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  7762. face = obj_faces[ chunk_faces3[ f ] ];
  7763. customAttribute.array[ offset_custom ] = customAttribute.value[ face.a ];
  7764. customAttribute.array[ offset_custom + 1 ] = customAttribute.value[ face.b ];
  7765. customAttribute.array[ offset_custom + 2 ] = customAttribute.value[ face.c ];
  7766. offset_custom += 3;
  7767. }
  7768. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  7769. face = obj_faces[ chunk_faces4[ f ] ];
  7770. customAttribute.array[ offset_custom ] = customAttribute.value[ face.a ];
  7771. customAttribute.array[ offset_custom + 1 ] = customAttribute.value[ face.b ];
  7772. customAttribute.array[ offset_custom + 2 ] = customAttribute.value[ face.c ];
  7773. customAttribute.array[ offset_custom + 3 ] = customAttribute.value[ face.d ];
  7774. offset_custom += 4;
  7775. }
  7776. } else if ( customAttribute.boundTo === "faces" ) {
  7777. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  7778. value = customAttribute.value[ chunk_faces3[ f ] ];
  7779. customAttribute.array[ offset_custom ] = value;
  7780. customAttribute.array[ offset_custom + 1 ] = value;
  7781. customAttribute.array[ offset_custom + 2 ] = value;
  7782. offset_custom += 3;
  7783. }
  7784. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  7785. value = customAttribute.value[ chunk_faces4[ f ] ];
  7786. customAttribute.array[ offset_custom ] = value;
  7787. customAttribute.array[ offset_custom + 1 ] = value;
  7788. customAttribute.array[ offset_custom + 2 ] = value;
  7789. customAttribute.array[ offset_custom + 3 ] = value;
  7790. offset_custom += 4;
  7791. }
  7792. }
  7793. } else if ( customAttribute.size === 2 ) {
  7794. if ( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) {
  7795. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  7796. face = obj_faces[ chunk_faces3[ f ] ];
  7797. v1 = customAttribute.value[ face.a ];
  7798. v2 = customAttribute.value[ face.b ];
  7799. v3 = customAttribute.value[ face.c ];
  7800. customAttribute.array[ offset_custom ] = v1.x;
  7801. customAttribute.array[ offset_custom + 1 ] = v1.y;
  7802. customAttribute.array[ offset_custom + 2 ] = v2.x;
  7803. customAttribute.array[ offset_custom + 3 ] = v2.y;
  7804. customAttribute.array[ offset_custom + 4 ] = v3.x;
  7805. customAttribute.array[ offset_custom + 5 ] = v3.y;
  7806. offset_custom += 6;
  7807. }
  7808. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  7809. face = obj_faces[ chunk_faces4[ f ] ];
  7810. v1 = customAttribute.value[ face.a ];
  7811. v2 = customAttribute.value[ face.b ];
  7812. v3 = customAttribute.value[ face.c ];
  7813. v4 = customAttribute.value[ face.d ];
  7814. customAttribute.array[ offset_custom ] = v1.x;
  7815. customAttribute.array[ offset_custom + 1 ] = v1.y;
  7816. customAttribute.array[ offset_custom + 2 ] = v2.x;
  7817. customAttribute.array[ offset_custom + 3 ] = v2.y;
  7818. customAttribute.array[ offset_custom + 4 ] = v3.x;
  7819. customAttribute.array[ offset_custom + 5 ] = v3.y;
  7820. customAttribute.array[ offset_custom + 6 ] = v4.x;
  7821. customAttribute.array[ offset_custom + 7 ] = v4.y;
  7822. offset_custom += 8;
  7823. }
  7824. } else if ( customAttribute.boundTo === "faces" ) {
  7825. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  7826. value = customAttribute.value[ chunk_faces3[ f ] ];
  7827. v1 = value;
  7828. v2 = value;
  7829. v3 = value;
  7830. customAttribute.array[ offset_custom ] = v1.x;
  7831. customAttribute.array[ offset_custom + 1 ] = v1.y;
  7832. customAttribute.array[ offset_custom + 2 ] = v2.x;
  7833. customAttribute.array[ offset_custom + 3 ] = v2.y;
  7834. customAttribute.array[ offset_custom + 4 ] = v3.x;
  7835. customAttribute.array[ offset_custom + 5 ] = v3.y;
  7836. offset_custom += 6;
  7837. }
  7838. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  7839. value = customAttribute.value[ chunk_faces4[ f ] ];
  7840. v1 = value;
  7841. v2 = value;
  7842. v3 = value;
  7843. v4 = value;
  7844. customAttribute.array[ offset_custom ] = v1.x;
  7845. customAttribute.array[ offset_custom + 1 ] = v1.y;
  7846. customAttribute.array[ offset_custom + 2 ] = v2.x;
  7847. customAttribute.array[ offset_custom + 3 ] = v2.y;
  7848. customAttribute.array[ offset_custom + 4 ] = v3.x;
  7849. customAttribute.array[ offset_custom + 5 ] = v3.y;
  7850. customAttribute.array[ offset_custom + 6 ] = v4.x;
  7851. customAttribute.array[ offset_custom + 7 ] = v4.y;
  7852. offset_custom += 8;
  7853. }
  7854. }
  7855. } else if ( customAttribute.size === 3 ) {
  7856. var pp;
  7857. if ( customAttribute.type === "c" ) {
  7858. pp = [ "r", "g", "b" ];
  7859. } else {
  7860. pp = [ "x", "y", "z" ];
  7861. }
  7862. if ( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) {
  7863. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  7864. face = obj_faces[ chunk_faces3[ f ] ];
  7865. v1 = customAttribute.value[ face.a ];
  7866. v2 = customAttribute.value[ face.b ];
  7867. v3 = customAttribute.value[ face.c ];
  7868. customAttribute.array[ offset_custom ] = v1[ pp[ 0 ] ];
  7869. customAttribute.array[ offset_custom + 1 ] = v1[ pp[ 1 ] ];
  7870. customAttribute.array[ offset_custom + 2 ] = v1[ pp[ 2 ] ];
  7871. customAttribute.array[ offset_custom + 3 ] = v2[ pp[ 0 ] ];
  7872. customAttribute.array[ offset_custom + 4 ] = v2[ pp[ 1 ] ];
  7873. customAttribute.array[ offset_custom + 5 ] = v2[ pp[ 2 ] ];
  7874. customAttribute.array[ offset_custom + 6 ] = v3[ pp[ 0 ] ];
  7875. customAttribute.array[ offset_custom + 7 ] = v3[ pp[ 1 ] ];
  7876. customAttribute.array[ offset_custom + 8 ] = v3[ pp[ 2 ] ];
  7877. offset_custom += 9;
  7878. }
  7879. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  7880. face = obj_faces[ chunk_faces4[ f ] ];
  7881. v1 = customAttribute.value[ face.a ];
  7882. v2 = customAttribute.value[ face.b ];
  7883. v3 = customAttribute.value[ face.c ];
  7884. v4 = customAttribute.value[ face.d ];
  7885. customAttribute.array[ offset_custom ] = v1[ pp[ 0 ] ];
  7886. customAttribute.array[ offset_custom + 1 ] = v1[ pp[ 1 ] ];
  7887. customAttribute.array[ offset_custom + 2 ] = v1[ pp[ 2 ] ];
  7888. customAttribute.array[ offset_custom + 3 ] = v2[ pp[ 0 ] ];
  7889. customAttribute.array[ offset_custom + 4 ] = v2[ pp[ 1 ] ];
  7890. customAttribute.array[ offset_custom + 5 ] = v2[ pp[ 2 ] ];
  7891. customAttribute.array[ offset_custom + 6 ] = v3[ pp[ 0 ] ];
  7892. customAttribute.array[ offset_custom + 7 ] = v3[ pp[ 1 ] ];
  7893. customAttribute.array[ offset_custom + 8 ] = v3[ pp[ 2 ] ];
  7894. customAttribute.array[ offset_custom + 9 ] = v4[ pp[ 0 ] ];
  7895. customAttribute.array[ offset_custom + 10 ] = v4[ pp[ 1 ] ];
  7896. customAttribute.array[ offset_custom + 11 ] = v4[ pp[ 2 ] ];
  7897. offset_custom += 12;
  7898. }
  7899. } else if ( customAttribute.boundTo === "faces" ) {
  7900. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  7901. value = customAttribute.value[ chunk_faces3[ f ] ];
  7902. v1 = value;
  7903. v2 = value;
  7904. v3 = value;
  7905. customAttribute.array[ offset_custom ] = v1[ pp[ 0 ] ];
  7906. customAttribute.array[ offset_custom + 1 ] = v1[ pp[ 1 ] ];
  7907. customAttribute.array[ offset_custom + 2 ] = v1[ pp[ 2 ] ];
  7908. customAttribute.array[ offset_custom + 3 ] = v2[ pp[ 0 ] ];
  7909. customAttribute.array[ offset_custom + 4 ] = v2[ pp[ 1 ] ];
  7910. customAttribute.array[ offset_custom + 5 ] = v2[ pp[ 2 ] ];
  7911. customAttribute.array[ offset_custom + 6 ] = v3[ pp[ 0 ] ];
  7912. customAttribute.array[ offset_custom + 7 ] = v3[ pp[ 1 ] ];
  7913. customAttribute.array[ offset_custom + 8 ] = v3[ pp[ 2 ] ];
  7914. offset_custom += 9;
  7915. }
  7916. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  7917. value = customAttribute.value[ chunk_faces4[ f ] ];
  7918. v1 = value;
  7919. v2 = value;
  7920. v3 = value;
  7921. v4 = value;
  7922. customAttribute.array[ offset_custom ] = v1[ pp[ 0 ] ];
  7923. customAttribute.array[ offset_custom + 1 ] = v1[ pp[ 1 ] ];
  7924. customAttribute.array[ offset_custom + 2 ] = v1[ pp[ 2 ] ];
  7925. customAttribute.array[ offset_custom + 3 ] = v2[ pp[ 0 ] ];
  7926. customAttribute.array[ offset_custom + 4 ] = v2[ pp[ 1 ] ];
  7927. customAttribute.array[ offset_custom + 5 ] = v2[ pp[ 2 ] ];
  7928. customAttribute.array[ offset_custom + 6 ] = v3[ pp[ 0 ] ];
  7929. customAttribute.array[ offset_custom + 7 ] = v3[ pp[ 1 ] ];
  7930. customAttribute.array[ offset_custom + 8 ] = v3[ pp[ 2 ] ];
  7931. customAttribute.array[ offset_custom + 9 ] = v4[ pp[ 0 ] ];
  7932. customAttribute.array[ offset_custom + 10 ] = v4[ pp[ 1 ] ];
  7933. customAttribute.array[ offset_custom + 11 ] = v4[ pp[ 2 ] ];
  7934. offset_custom += 12;
  7935. }
  7936. }
  7937. } else if ( customAttribute.size === 4 ) {
  7938. if ( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) {
  7939. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  7940. face = obj_faces[ chunk_faces3[ f ] ];
  7941. v1 = customAttribute.value[ face.a ];
  7942. v2 = customAttribute.value[ face.b ];
  7943. v3 = customAttribute.value[ face.c ];
  7944. customAttribute.array[ offset_custom ] = v1.x;
  7945. customAttribute.array[ offset_custom + 1 ] = v1.y;
  7946. customAttribute.array[ offset_custom + 2 ] = v1.z;
  7947. customAttribute.array[ offset_custom + 3 ] = v1.w;
  7948. customAttribute.array[ offset_custom + 4 ] = v2.x;
  7949. customAttribute.array[ offset_custom + 5 ] = v2.y;
  7950. customAttribute.array[ offset_custom + 6 ] = v2.z;
  7951. customAttribute.array[ offset_custom + 7 ] = v2.w;
  7952. customAttribute.array[ offset_custom + 8 ] = v3.x;
  7953. customAttribute.array[ offset_custom + 9 ] = v3.y;
  7954. customAttribute.array[ offset_custom + 10 ] = v3.z;
  7955. customAttribute.array[ offset_custom + 11 ] = v3.w;
  7956. offset_custom += 12;
  7957. }
  7958. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  7959. face = obj_faces[ chunk_faces4[ f ] ];
  7960. v1 = customAttribute.value[ face.a ];
  7961. v2 = customAttribute.value[ face.b ];
  7962. v3 = customAttribute.value[ face.c ];
  7963. v4 = customAttribute.value[ face.d ];
  7964. customAttribute.array[ offset_custom ] = v1.x;
  7965. customAttribute.array[ offset_custom + 1 ] = v1.y;
  7966. customAttribute.array[ offset_custom + 2 ] = v1.z;
  7967. customAttribute.array[ offset_custom + 3 ] = v1.w;
  7968. customAttribute.array[ offset_custom + 4 ] = v2.x;
  7969. customAttribute.array[ offset_custom + 5 ] = v2.y;
  7970. customAttribute.array[ offset_custom + 6 ] = v2.z;
  7971. customAttribute.array[ offset_custom + 7 ] = v2.w;
  7972. customAttribute.array[ offset_custom + 8 ] = v3.x;
  7973. customAttribute.array[ offset_custom + 9 ] = v3.y;
  7974. customAttribute.array[ offset_custom + 10 ] = v3.z;
  7975. customAttribute.array[ offset_custom + 11 ] = v3.w;
  7976. customAttribute.array[ offset_custom + 12 ] = v4.x;
  7977. customAttribute.array[ offset_custom + 13 ] = v4.y;
  7978. customAttribute.array[ offset_custom + 14 ] = v4.z;
  7979. customAttribute.array[ offset_custom + 15 ] = v4.w;
  7980. offset_custom += 16;
  7981. }
  7982. } else if ( customAttribute.boundTo === "faces" ) {
  7983. for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
  7984. value = customAttribute.value[ chunk_faces3[ f ] ];
  7985. v1 = value;
  7986. v2 = value;
  7987. v3 = value;
  7988. customAttribute.array[ offset_custom ] = v1.x;
  7989. customAttribute.array[ offset_custom + 1 ] = v1.y;
  7990. customAttribute.array[ offset_custom + 2 ] = v1.z;
  7991. customAttribute.array[ offset_custom + 3 ] = v1.w;
  7992. customAttribute.array[ offset_custom + 4 ] = v2.x;
  7993. customAttribute.array[ offset_custom + 5 ] = v2.y;
  7994. customAttribute.array[ offset_custom + 6 ] = v2.z;
  7995. customAttribute.array[ offset_custom + 7 ] = v2.w;
  7996. customAttribute.array[ offset_custom + 8 ] = v3.x;
  7997. customAttribute.array[ offset_custom + 9 ] = v3.y;
  7998. customAttribute.array[ offset_custom + 10 ] = v3.z;
  7999. customAttribute.array[ offset_custom + 11 ] = v3.w;
  8000. offset_custom += 12;
  8001. }
  8002. for ( f = 0, fl = chunk_faces4.length; f < fl; f ++ ) {
  8003. value = customAttribute.value[ chunk_faces4[ f ] ];
  8004. v1 = value;
  8005. v2 = value;
  8006. v3 = value;
  8007. v4 = value;
  8008. customAttribute.array[ offset_custom ] = v1.x;
  8009. customAttribute.array[ offset_custom + 1 ] = v1.y;
  8010. customAttribute.array[ offset_custom + 2 ] = v1.z;
  8011. customAttribute.array[ offset_custom + 3 ] = v1.w;
  8012. customAttribute.array[ offset_custom + 4 ] = v2.x;
  8013. customAttribute.array[ offset_custom + 5 ] = v2.y;
  8014. customAttribute.array[ offset_custom + 6 ] = v2.z;
  8015. customAttribute.array[ offset_custom + 7 ] = v2.w;
  8016. customAttribute.array[ offset_custom + 8 ] = v3.x;
  8017. customAttribute.array[ offset_custom + 9 ] = v3.y;
  8018. customAttribute.array[ offset_custom + 10 ] = v3.z;
  8019. customAttribute.array[ offset_custom + 11 ] = v3.w;
  8020. customAttribute.array[ offset_custom + 12 ] = v4.x;
  8021. customAttribute.array[ offset_custom + 13 ] = v4.y;
  8022. customAttribute.array[ offset_custom + 14 ] = v4.z;
  8023. customAttribute.array[ offset_custom + 15 ] = v4.w;
  8024. offset_custom += 16;
  8025. }
  8026. }
  8027. }
  8028. _gl.bindBuffer( _gl.ARRAY_BUFFER, customAttribute.buffer );
  8029. _gl.bufferData( _gl.ARRAY_BUFFER, customAttribute.array, hint );
  8030. }
  8031. }
  8032. if ( dispose ) {
  8033. delete geometryGroup.__inittedArrays;
  8034. delete geometryGroup.__colorArray;
  8035. delete geometryGroup.__normalArray;
  8036. delete geometryGroup.__tangentArray;
  8037. delete geometryGroup.__uvArray;
  8038. delete geometryGroup.__uv2Array;
  8039. delete geometryGroup.__faceArray;
  8040. delete geometryGroup.__vertexArray;
  8041. delete geometryGroup.__lineArray;
  8042. delete geometryGroup.__skinVertexAArray;
  8043. delete geometryGroup.__skinVertexBArray;
  8044. delete geometryGroup.__skinIndexArray;
  8045. delete geometryGroup.__skinWeightArray;
  8046. }
  8047. };
  8048. // Buffer rendering
  8049. this.renderBufferImmediate = function ( object, program, shading ) {
  8050. if ( ! object.__webglVertexBuffer ) object.__webglVertexBuffer = _gl.createBuffer();
  8051. if ( ! object.__webglNormalBuffer ) object.__webglNormalBuffer = _gl.createBuffer();
  8052. if ( object.hasPos ) {
  8053. _gl.bindBuffer( _gl.ARRAY_BUFFER, object.__webglVertexBuffer );
  8054. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  8055. _gl.enableVertexAttribArray( program.attributes.position );
  8056. _gl.vertexAttribPointer( program.attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  8057. }
  8058. if ( object.hasNormal ) {
  8059. _gl.bindBuffer( _gl.ARRAY_BUFFER, object.__webglNormalBuffer );
  8060. if ( shading === THREE.FlatShading ) {
  8061. var nx, ny, nz,
  8062. nax, nbx, ncx, nay, nby, ncy, naz, nbz, ncz,
  8063. normalArray,
  8064. i, il = object.count * 3;
  8065. for( i = 0; i < il; i += 9 ) {
  8066. normalArray = object.normalArray;
  8067. nax = normalArray[ i ];
  8068. nay = normalArray[ i + 1 ];
  8069. naz = normalArray[ i + 2 ];
  8070. nbx = normalArray[ i + 3 ];
  8071. nby = normalArray[ i + 4 ];
  8072. nbz = normalArray[ i + 5 ];
  8073. ncx = normalArray[ i + 6 ];
  8074. ncy = normalArray[ i + 7 ];
  8075. ncz = normalArray[ i + 8 ];
  8076. nx = ( nax + nbx + ncx ) / 3;
  8077. ny = ( nay + nby + ncy ) / 3;
  8078. nz = ( naz + nbz + ncz ) / 3;
  8079. normalArray[ i ] = nx;
  8080. normalArray[ i + 1 ] = ny;
  8081. normalArray[ i + 2 ] = nz;
  8082. normalArray[ i + 3 ] = nx;
  8083. normalArray[ i + 4 ] = ny;
  8084. normalArray[ i + 5 ] = nz;
  8085. normalArray[ i + 6 ] = nx;
  8086. normalArray[ i + 7 ] = ny;
  8087. normalArray[ i + 8 ] = nz;
  8088. }
  8089. }
  8090. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  8091. _gl.enableVertexAttribArray( program.attributes.normal );
  8092. _gl.vertexAttribPointer( program.attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  8093. }
  8094. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  8095. object.count = 0;
  8096. };
  8097. this.renderBufferDirect = function ( camera, lights, fog, material, geometryGroup, object ) {
  8098. if ( material.opacity === 0 ) return;
  8099. var program, attributes, linewidth, primitives, a, attribute;
  8100. program = setProgram( camera, lights, fog, material, object );
  8101. attributes = program.attributes;
  8102. var updateBuffers = false,
  8103. wireframeBit = material.wireframe ? 1 : 0,
  8104. geometryGroupHash = ( geometryGroup.id * 0xffffff ) + ( program.id * 2 ) + wireframeBit;
  8105. if ( geometryGroupHash !== _currentGeometryGroupHash ) {
  8106. _currentGeometryGroupHash = geometryGroupHash;
  8107. updateBuffers = true;
  8108. }
  8109. // render mesh
  8110. if ( object instanceof THREE.Mesh ) {
  8111. var offsets = geometryGroup.offsets;
  8112. for ( var i = 0, il = offsets.length; i < il; ++ i ) {
  8113. if ( updateBuffers ) {
  8114. // vertices
  8115. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.vertexPositionBuffer );
  8116. _gl.vertexAttribPointer( attributes.position, geometryGroup.vertexPositionBuffer.itemSize, _gl.FLOAT, false, 0, offsets[ i ].index * 4 * 3 );
  8117. // normals
  8118. if ( attributes.normal >= 0 && geometryGroup.vertexNormalBuffer ) {
  8119. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.vertexNormalBuffer );
  8120. _gl.vertexAttribPointer( attributes.normal, geometryGroup.vertexNormalBuffer.itemSize, _gl.FLOAT, false, 0, offsets[ i ].index * 4 * 3 );
  8121. }
  8122. // uvs
  8123. if ( attributes.uv >= 0 && geometryGroup.vertexUvBuffer ) {
  8124. if ( geometryGroup.vertexUvBuffer ) {
  8125. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.vertexUvBuffer );
  8126. _gl.vertexAttribPointer( attributes.uv, geometryGroup.vertexUvBuffer.itemSize, _gl.FLOAT, false, 0, offsets[ i ].index * 4 * 2 );
  8127. _gl.enableVertexAttribArray( attributes.uv );
  8128. } else {
  8129. _gl.disableVertexAttribArray( attributes.uv );
  8130. }
  8131. }
  8132. // colors
  8133. if ( attributes.color >= 0 && geometryGroup.vertexColorBuffer ) {
  8134. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.vertexColorBuffer );
  8135. _gl.vertexAttribPointer( attributes.color, geometryGroup.vertexColorBuffer.itemSize, _gl.FLOAT, false, 0, offsets[ i ].index * 4 * 4 );
  8136. }
  8137. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, geometryGroup.vertexIndexBuffer );
  8138. }
  8139. // render indexed triangles
  8140. _gl.drawElements( _gl.TRIANGLES, offsets[ i ].count, _gl.UNSIGNED_SHORT, offsets[ i ].start * 2 ); // 2 = Uint16
  8141. _this.info.render.calls ++;
  8142. _this.info.render.vertices += offsets[ i ].count; // not really true, here vertices can be shared
  8143. _this.info.render.faces += offsets[ i ].count / 3;
  8144. }
  8145. }
  8146. };
  8147. this.renderBuffer = function ( camera, lights, fog, material, geometryGroup, object ) {
  8148. if ( material.opacity === 0 ) return;
  8149. var program, attributes, linewidth, primitives, a, attribute, i, il;
  8150. program = setProgram( camera, lights, fog, material, object );
  8151. attributes = program.attributes;
  8152. var updateBuffers = false,
  8153. wireframeBit = material.wireframe ? 1 : 0,
  8154. geometryGroupHash = ( geometryGroup.id * 0xffffff ) + ( program.id * 2 ) + wireframeBit;
  8155. if ( geometryGroupHash !== _currentGeometryGroupHash ) {
  8156. _currentGeometryGroupHash = geometryGroupHash;
  8157. updateBuffers = true;
  8158. }
  8159. // vertices
  8160. if ( !material.morphTargets && attributes.position >= 0 ) {
  8161. if ( updateBuffers ) {
  8162. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglVertexBuffer );
  8163. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  8164. }
  8165. } else {
  8166. if ( object.morphTargetBase ) {
  8167. setupMorphTargets( material, geometryGroup, object );
  8168. }
  8169. }
  8170. if ( updateBuffers ) {
  8171. // custom attributes
  8172. // Use the per-geometryGroup custom attribute arrays which are setup in initMeshBuffers
  8173. if ( geometryGroup.__webglCustomAttributesList ) {
  8174. for ( i = 0, il = geometryGroup.__webglCustomAttributesList.length; i < il; i ++ ) {
  8175. attribute = geometryGroup.__webglCustomAttributesList[ i ];
  8176. if( attributes[ attribute.buffer.belongsToAttribute ] >= 0 ) {
  8177. _gl.bindBuffer( _gl.ARRAY_BUFFER, attribute.buffer );
  8178. _gl.vertexAttribPointer( attributes[ attribute.buffer.belongsToAttribute ], attribute.size, _gl.FLOAT, false, 0, 0 );
  8179. }
  8180. }
  8181. }
  8182. // colors
  8183. if ( attributes.color >= 0 ) {
  8184. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglColorBuffer );
  8185. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  8186. }
  8187. // normals
  8188. if ( attributes.normal >= 0 ) {
  8189. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglNormalBuffer );
  8190. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  8191. }
  8192. // tangents
  8193. if ( attributes.tangent >= 0 ) {
  8194. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglTangentBuffer );
  8195. _gl.vertexAttribPointer( attributes.tangent, 4, _gl.FLOAT, false, 0, 0 );
  8196. }
  8197. // uvs
  8198. if ( attributes.uv >= 0 ) {
  8199. if ( geometryGroup.__webglUVBuffer ) {
  8200. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglUVBuffer );
  8201. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  8202. _gl.enableVertexAttribArray( attributes.uv );
  8203. } else {
  8204. _gl.disableVertexAttribArray( attributes.uv );
  8205. }
  8206. }
  8207. if ( attributes.uv2 >= 0 ) {
  8208. if ( geometryGroup.__webglUV2Buffer ) {
  8209. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglUV2Buffer );
  8210. _gl.vertexAttribPointer( attributes.uv2, 2, _gl.FLOAT, false, 0, 0 );
  8211. _gl.enableVertexAttribArray( attributes.uv2 );
  8212. } else {
  8213. _gl.disableVertexAttribArray( attributes.uv2 );
  8214. }
  8215. }
  8216. if ( material.skinning &&
  8217. attributes.skinVertexA >= 0 && attributes.skinVertexB >= 0 &&
  8218. attributes.skinIndex >= 0 && attributes.skinWeight >= 0 ) {
  8219. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglSkinVertexABuffer );
  8220. _gl.vertexAttribPointer( attributes.skinVertexA, 4, _gl.FLOAT, false, 0, 0 );
  8221. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglSkinVertexBBuffer );
  8222. _gl.vertexAttribPointer( attributes.skinVertexB, 4, _gl.FLOAT, false, 0, 0 );
  8223. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglSkinIndicesBuffer );
  8224. _gl.vertexAttribPointer( attributes.skinIndex, 4, _gl.FLOAT, false, 0, 0 );
  8225. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglSkinWeightsBuffer );
  8226. _gl.vertexAttribPointer( attributes.skinWeight, 4, _gl.FLOAT, false, 0, 0 );
  8227. }
  8228. }
  8229. // render mesh
  8230. if ( object instanceof THREE.Mesh ) {
  8231. // wireframe
  8232. if ( material.wireframe ) {
  8233. setLineWidth( material.wireframeLinewidth );
  8234. if ( updateBuffers ) _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, geometryGroup.__webglLineBuffer );
  8235. _gl.drawElements( _gl.LINES, geometryGroup.__webglLineCount, _gl.UNSIGNED_SHORT, 0 );
  8236. // triangles
  8237. } else {
  8238. if ( updateBuffers ) _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, geometryGroup.__webglFaceBuffer );
  8239. _gl.drawElements( _gl.TRIANGLES, geometryGroup.__webglFaceCount, _gl.UNSIGNED_SHORT, 0 );
  8240. }
  8241. _this.info.render.calls ++;
  8242. _this.info.render.vertices += geometryGroup.__webglFaceCount;
  8243. _this.info.render.faces += geometryGroup.__webglFaceCount / 3;
  8244. // render lines
  8245. } else if ( object instanceof THREE.Line ) {
  8246. primitives = ( object.type === THREE.LineStrip ) ? _gl.LINE_STRIP : _gl.LINES;
  8247. setLineWidth( material.linewidth );
  8248. _gl.drawArrays( primitives, 0, geometryGroup.__webglLineCount );
  8249. _this.info.render.calls ++;
  8250. // render particles
  8251. } else if ( object instanceof THREE.ParticleSystem ) {
  8252. _gl.drawArrays( _gl.POINTS, 0, geometryGroup.__webglParticleCount );
  8253. _this.info.render.calls ++;
  8254. _this.info.render.points += geometryGroup.__webglParticleCount;
  8255. // render ribbon
  8256. } else if ( object instanceof THREE.Ribbon ) {
  8257. _gl.drawArrays( _gl.TRIANGLE_STRIP, 0, geometryGroup.__webglVertexCount );
  8258. _this.info.render.calls ++;
  8259. }
  8260. };
  8261. function setupMorphTargets ( material, geometryGroup, object ) {
  8262. // set base
  8263. var attributes = material.program.attributes;
  8264. if ( object.morphTargetBase !== - 1 ) {
  8265. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ object.morphTargetBase ] );
  8266. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  8267. } else if ( attributes.position >= 0 ) {
  8268. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglVertexBuffer );
  8269. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  8270. }
  8271. if ( object.morphTargetForcedOrder.length ) {
  8272. // set forced order
  8273. var m = 0;
  8274. var order = object.morphTargetForcedOrder;
  8275. var influences = object.morphTargetInfluences;
  8276. while ( m < material.numSupportedMorphTargets && m < order.length ) {
  8277. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ order[ m ] ] );
  8278. _gl.vertexAttribPointer( attributes[ "morphTarget" + m ], 3, _gl.FLOAT, false, 0, 0 );
  8279. if ( material.morphNormals ) {
  8280. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphNormalsBuffers[ order[ m ] ] );
  8281. _gl.vertexAttribPointer( attributes[ "morphNormal" + m ], 3, _gl.FLOAT, false, 0, 0 );
  8282. }
  8283. object.__webglMorphTargetInfluences[ m ] = influences[ order[ m ] ];
  8284. m ++;
  8285. }
  8286. } else {
  8287. // find most influencing
  8288. var used = [];
  8289. var candidateInfluence = - 1;
  8290. var candidate = 0;
  8291. var influences = object.morphTargetInfluences;
  8292. var i, il = influences.length;
  8293. var m = 0;
  8294. if ( object.morphTargetBase !== - 1 ) {
  8295. used[ object.morphTargetBase ] = true;
  8296. }
  8297. while ( m < material.numSupportedMorphTargets ) {
  8298. for ( i = 0; i < il; i ++ ) {
  8299. if ( !used[ i ] && influences[ i ] > candidateInfluence ) {
  8300. candidate = i;
  8301. candidateInfluence = influences[ candidate ];
  8302. }
  8303. }
  8304. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ candidate ] );
  8305. _gl.vertexAttribPointer( attributes[ "morphTarget" + m ], 3, _gl.FLOAT, false, 0, 0 );
  8306. if ( material.morphNormals ) {
  8307. _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphNormalsBuffers[ candidate ] );
  8308. _gl.vertexAttribPointer( attributes[ "morphNormal" + m ], 3, _gl.FLOAT, false, 0, 0 );
  8309. }
  8310. object.__webglMorphTargetInfluences[ m ] = candidateInfluence;
  8311. used[ candidate ] = 1;
  8312. candidateInfluence = -1;
  8313. m ++;
  8314. }
  8315. }
  8316. // load updated influences uniform
  8317. if( material.program.uniforms.morphTargetInfluences !== null ) {
  8318. _gl.uniform1fv( material.program.uniforms.morphTargetInfluences, object.__webglMorphTargetInfluences );
  8319. }
  8320. };
  8321. function painterSort ( a, b ) {
  8322. return b.z - a.z;
  8323. };
  8324. // Rendering
  8325. this.render = function ( scene, camera, renderTarget, forceClear ) {
  8326. var i, il,
  8327. webglObject, object,
  8328. renderList,
  8329. lights = scene.__lights,
  8330. fog = scene.fog;
  8331. _currentMaterialId = -1;
  8332. // update scene graph
  8333. if ( camera.parent === undefined ) {
  8334. console.warn( 'DEPRECATED: Camera hasn\'t been added to a Scene. Adding it...' );
  8335. scene.add( camera );
  8336. }
  8337. if ( this.autoUpdateScene ) scene.updateMatrixWorld();
  8338. // update camera matrices and frustum
  8339. if ( ! camera._viewMatrixArray ) camera._viewMatrixArray = new Float32Array( 16 );
  8340. if ( ! camera._projectionMatrixArray ) camera._projectionMatrixArray = new Float32Array( 16 );
  8341. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  8342. camera.matrixWorldInverse.flattenToArray( camera._viewMatrixArray );
  8343. camera.projectionMatrix.flattenToArray( camera._projectionMatrixArray );
  8344. _projScreenMatrix.multiply( camera.projectionMatrix, camera.matrixWorldInverse );
  8345. _frustum.setFromMatrix( _projScreenMatrix );
  8346. // update WebGL objects
  8347. if ( this.autoUpdateObjects ) this.initWebGLObjects( scene );
  8348. // custom render plugins (pre pass)
  8349. renderPlugins( this.renderPluginsPre, scene, camera );
  8350. //
  8351. _this.info.render.calls = 0;
  8352. _this.info.render.vertices = 0;
  8353. _this.info.render.faces = 0;
  8354. _this.info.render.points = 0;
  8355. this.setRenderTarget( renderTarget );
  8356. if ( this.autoClear || forceClear ) {
  8357. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  8358. }
  8359. // set matrices for regular objects (frustum culled)
  8360. renderList = scene.__webglObjects;
  8361. for ( i = 0, il = renderList.length; i < il; i ++ ) {
  8362. webglObject = renderList[ i ];
  8363. object = webglObject.object;
  8364. webglObject.render = false;
  8365. if ( object.visible ) {
  8366. if ( ! ( object instanceof THREE.Mesh || object instanceof THREE.ParticleSystem ) || ! ( object.frustumCulled ) || _frustum.contains( object ) ) {
  8367. //object.matrixWorld.flattenToArray( object._objectMatrixArray );
  8368. setupMatrices( object, camera );
  8369. unrollBufferMaterial( webglObject );
  8370. webglObject.render = true;
  8371. if ( this.sortObjects ) {
  8372. if ( object.renderDepth ) {
  8373. webglObject.z = object.renderDepth;
  8374. } else {
  8375. _vector3.copy( object.matrixWorld.getPosition() );
  8376. _projScreenMatrix.multiplyVector3( _vector3 );
  8377. webglObject.z = _vector3.z;
  8378. }
  8379. }
  8380. }
  8381. }
  8382. }
  8383. if ( this.sortObjects ) {
  8384. renderList.sort( painterSort );
  8385. }
  8386. // set matrices for immediate objects
  8387. renderList = scene.__webglObjectsImmediate;
  8388. for ( i = 0, il = renderList.length; i < il; i ++ ) {
  8389. webglObject = renderList[ i ];
  8390. object = webglObject.object;
  8391. if ( object.visible ) {
  8392. /*
  8393. if ( object.matrixAutoUpdate ) {
  8394. object.matrixWorld.flattenToArray( object._objectMatrixArray );
  8395. }
  8396. */
  8397. setupMatrices( object, camera );
  8398. unrollImmediateBufferMaterial( webglObject );
  8399. }
  8400. }
  8401. if ( scene.overrideMaterial ) {
  8402. var material = scene.overrideMaterial;
  8403. this.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  8404. this.setDepthTest( material.depthTest );
  8405. this.setDepthWrite( material.depthWrite );
  8406. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  8407. renderObjects( scene.__webglObjects, false, "", camera, lights, fog, true, material );
  8408. renderObjectsImmediate( scene.__webglObjectsImmediate, "", camera, lights, fog, false, material );
  8409. } else {
  8410. // opaque pass (front-to-back order)
  8411. this.setBlending( THREE.NormalBlending );
  8412. renderObjects( scene.__webglObjects, true, "opaque", camera, lights, fog, false );
  8413. renderObjectsImmediate( scene.__webglObjectsImmediate, "opaque", camera, lights, fog, false );
  8414. // transparent pass (back-to-front order)
  8415. renderObjects( scene.__webglObjects, false, "transparent", camera, lights, fog, true );
  8416. renderObjectsImmediate( scene.__webglObjectsImmediate, "transparent", camera, lights, fog, true );
  8417. }
  8418. // custom render plugins (post pass)
  8419. renderPlugins( this.renderPluginsPost, scene, camera );
  8420. // Generate mipmap if we're using any kind of mipmap filtering
  8421. if ( renderTarget && renderTarget.generateMipmaps && renderTarget.minFilter !== THREE.NearestFilter && renderTarget.minFilter !== THREE.LinearFilter ) {
  8422. updateRenderTargetMipmap( renderTarget );
  8423. }
  8424. // Ensure depth buffer writing is enabled so it can be cleared on next render
  8425. this.setDepthTest( true );
  8426. this.setDepthWrite( true );
  8427. // _gl.finish();
  8428. };
  8429. function renderPlugins( plugins, scene, camera ) {
  8430. if ( ! plugins.length ) return;
  8431. for ( var i = 0, il = plugins.length; i < il; i ++ ) {
  8432. _currentProgram = null;
  8433. _currentCamera = null;
  8434. _oldBlending = -1;
  8435. _oldDepthTest = -1;
  8436. _oldDepthWrite = -1;
  8437. _currentGeometryGroupHash = -1;
  8438. _currentMaterialId = -1;
  8439. plugins[ i ].render( scene, camera, _currentWidth, _currentHeight );
  8440. _currentProgram = null;
  8441. _currentCamera = null;
  8442. _oldBlending = -1;
  8443. _oldDepthTest = -1;
  8444. _oldDepthWrite = -1;
  8445. _currentGeometryGroupHash = -1;
  8446. _currentMaterialId = -1;
  8447. }
  8448. };
  8449. function renderObjects ( renderList, reverse, materialType, camera, lights, fog, useBlending, overrideMaterial ) {
  8450. var webglObject, object, buffer, material, start, end, delta;
  8451. if ( reverse ) {
  8452. start = renderList.length - 1;
  8453. end = -1;
  8454. delta = -1;
  8455. } else {
  8456. start = 0;
  8457. end = renderList.length;
  8458. delta = 1;
  8459. }
  8460. for ( var i = start; i !== end; i += delta ) {
  8461. webglObject = renderList[ i ];
  8462. if ( webglObject.render ) {
  8463. object = webglObject.object;
  8464. buffer = webglObject.buffer;
  8465. if ( overrideMaterial ) {
  8466. material = overrideMaterial;
  8467. } else {
  8468. material = webglObject[ materialType ];
  8469. if ( ! material ) continue;
  8470. if ( useBlending ) _this.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  8471. _this.setDepthTest( material.depthTest );
  8472. _this.setDepthWrite( material.depthWrite );
  8473. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  8474. }
  8475. _this.setObjectFaces( object );
  8476. if ( buffer instanceof THREE.BufferGeometry ) {
  8477. _this.renderBufferDirect( camera, lights, fog, material, buffer, object );
  8478. } else {
  8479. _this.renderBuffer( camera, lights, fog, material, buffer, object );
  8480. }
  8481. }
  8482. }
  8483. };
  8484. function renderObjectsImmediate ( renderList, materialType, camera, lights, fog, useBlending, overrideMaterial ) {
  8485. var webglObject, object, material, program;
  8486. for ( var i = 0, il = renderList.length; i < il; i ++ ) {
  8487. webglObject = renderList[ i ];
  8488. object = webglObject.object;
  8489. if ( object.visible ) {
  8490. if ( overrideMaterial ) {
  8491. material = overrideMaterial;
  8492. } else {
  8493. material = webglObject[ materialType ];
  8494. if ( ! material ) continue;
  8495. if ( useBlending ) _this.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  8496. _this.setDepthTest( material.depthTest );
  8497. _this.setDepthWrite( material.depthWrite );
  8498. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  8499. }
  8500. _this.renderImmediateObject( camera, lights, fog, material, object );
  8501. }
  8502. }
  8503. };
  8504. this.renderImmediateObject = function ( camera, lights, fog, material, object ) {
  8505. var program = setProgram( camera, lights, fog, material, object );
  8506. _currentGeometryGroupHash = -1;
  8507. _this.setObjectFaces( object );
  8508. if ( object.immediateRenderCallback ) {
  8509. object.immediateRenderCallback( program, _gl, _frustum );
  8510. } else {
  8511. object.render( function( object ) { _this.renderBufferImmediate( object, program, material.shading ); } );
  8512. }
  8513. };
  8514. function unrollImmediateBufferMaterial ( globject ) {
  8515. var object = globject.object,
  8516. material = object.material;
  8517. if ( material.transparent ) {
  8518. globject.transparent = material;
  8519. globject.opaque = null;
  8520. } else {
  8521. globject.opaque = material;
  8522. globject.transparent = null;
  8523. }
  8524. };
  8525. function unrollBufferMaterial ( globject ) {
  8526. var object = globject.object,
  8527. buffer = globject.buffer,
  8528. material, materialIndex, meshMaterial;
  8529. meshMaterial = object.material;
  8530. if ( meshMaterial instanceof THREE.MeshFaceMaterial ) {
  8531. materialIndex = buffer.materialIndex;
  8532. if ( materialIndex >= 0 ) {
  8533. material = object.geometry.materials[ materialIndex ];
  8534. if ( material.transparent ) {
  8535. globject.transparent = material;
  8536. globject.opaque = null;
  8537. } else {
  8538. globject.opaque = material;
  8539. globject.transparent = null;
  8540. }
  8541. }
  8542. } else {
  8543. material = meshMaterial;
  8544. if ( material ) {
  8545. if ( material.transparent ) {
  8546. globject.transparent = material;
  8547. globject.opaque = null;
  8548. } else {
  8549. globject.opaque = material;
  8550. globject.transparent = null;
  8551. }
  8552. }
  8553. }
  8554. };
  8555. // Geometry splitting
  8556. function sortFacesByMaterial ( geometry ) {
  8557. var f, fl, face, materialIndex, vertices,
  8558. materialHash, groupHash,
  8559. hash_map = {};
  8560. var numMorphTargets = geometry.morphTargets.length;
  8561. var numMorphNormals = geometry.morphNormals.length;
  8562. geometry.geometryGroups = {};
  8563. for ( f = 0, fl = geometry.faces.length; f < fl; f ++ ) {
  8564. face = geometry.faces[ f ];
  8565. materialIndex = face.materialIndex;
  8566. materialHash = ( materialIndex !== undefined ) ? materialIndex : -1;
  8567. if ( hash_map[ materialHash ] === undefined ) {
  8568. hash_map[ materialHash ] = { 'hash': materialHash, 'counter': 0 };
  8569. }
  8570. groupHash = hash_map[ materialHash ].hash + '_' + hash_map[ materialHash ].counter;
  8571. if ( geometry.geometryGroups[ groupHash ] === undefined ) {
  8572. geometry.geometryGroups[ groupHash ] = { 'faces3': [], 'faces4': [], 'materialIndex': materialIndex, 'vertices': 0, 'numMorphTargets': numMorphTargets, 'numMorphNormals': numMorphNormals };
  8573. }
  8574. vertices = face instanceof THREE.Face3 ? 3 : 4;
  8575. if ( geometry.geometryGroups[ groupHash ].vertices + vertices > 65535 ) {
  8576. hash_map[ materialHash ].counter += 1;
  8577. groupHash = hash_map[ materialHash ].hash + '_' + hash_map[ materialHash ].counter;
  8578. if ( geometry.geometryGroups[ groupHash ] === undefined ) {
  8579. geometry.geometryGroups[ groupHash ] = { 'faces3': [], 'faces4': [], 'materialIndex': materialIndex, 'vertices': 0, 'numMorphTargets': numMorphTargets, 'numMorphNormals': numMorphNormals };
  8580. }
  8581. }
  8582. if ( face instanceof THREE.Face3 ) {
  8583. geometry.geometryGroups[ groupHash ].faces3.push( f );
  8584. } else {
  8585. geometry.geometryGroups[ groupHash ].faces4.push( f );
  8586. }
  8587. geometry.geometryGroups[ groupHash ].vertices += vertices;
  8588. }
  8589. geometry.geometryGroupsList = [];
  8590. for ( var g in geometry.geometryGroups ) {
  8591. geometry.geometryGroups[ g ].id = _geometryGroupCounter ++;
  8592. geometry.geometryGroupsList.push( geometry.geometryGroups[ g ] );
  8593. }
  8594. };
  8595. // Objects refresh
  8596. this.initWebGLObjects = function ( scene ) {
  8597. if ( !scene.__webglObjects ) {
  8598. scene.__webglObjects = [];
  8599. scene.__webglObjectsImmediate = [];
  8600. scene.__webglSprites = [];
  8601. scene.__webglFlares = [];
  8602. }
  8603. while ( scene.__objectsAdded.length ) {
  8604. addObject( scene.__objectsAdded[ 0 ], scene );
  8605. scene.__objectsAdded.splice( 0, 1 );
  8606. }
  8607. while ( scene.__objectsRemoved.length ) {
  8608. removeObject( scene.__objectsRemoved[ 0 ], scene );
  8609. scene.__objectsRemoved.splice( 0, 1 );
  8610. }
  8611. // update must be called after objects adding / removal
  8612. for ( var o = 0, ol = scene.__webglObjects.length; o < ol; o ++ ) {
  8613. updateObject( scene.__webglObjects[ o ].object );
  8614. }
  8615. };
  8616. // Objects adding
  8617. function addObject ( object, scene ) {
  8618. var g, geometry, geometryGroup;
  8619. if ( ! object.__webglInit ) {
  8620. object.__webglInit = true;
  8621. object._modelViewMatrix = new THREE.Matrix4();
  8622. object._normalMatrix = new THREE.Matrix3();
  8623. //object._normalMatrixArray = new Float32Array( 9 );
  8624. //object._modelViewMatrixArray = new Float32Array( 16 );
  8625. //object._objectMatrixArray = new Float32Array( 16 );
  8626. //object.matrixWorld.flattenToArray( object._objectMatrixArray );
  8627. if ( object instanceof THREE.Mesh ) {
  8628. geometry = object.geometry;
  8629. if ( geometry instanceof THREE.Geometry ) {
  8630. if ( geometry.geometryGroups === undefined ) {
  8631. sortFacesByMaterial( geometry );
  8632. }
  8633. // create separate VBOs per geometry chunk
  8634. for ( g in geometry.geometryGroups ) {
  8635. geometryGroup = geometry.geometryGroups[ g ];
  8636. // initialise VBO on the first access
  8637. if ( ! geometryGroup.__webglVertexBuffer ) {
  8638. createMeshBuffers( geometryGroup );
  8639. initMeshBuffers( geometryGroup, object );
  8640. geometry.__dirtyVertices = true;
  8641. geometry.__dirtyMorphTargets = true;
  8642. geometry.__dirtyElements = true;
  8643. geometry.__dirtyUvs = true;
  8644. geometry.__dirtyNormals = true;
  8645. geometry.__dirtyTangents = true;
  8646. geometry.__dirtyColors = true;
  8647. }
  8648. }
  8649. }
  8650. } else if ( object instanceof THREE.Ribbon ) {
  8651. geometry = object.geometry;
  8652. if( ! geometry.__webglVertexBuffer ) {
  8653. createRibbonBuffers( geometry );
  8654. initRibbonBuffers( geometry );
  8655. geometry.__dirtyVertices = true;
  8656. geometry.__dirtyColors = true;
  8657. }
  8658. } else if ( object instanceof THREE.Line ) {
  8659. geometry = object.geometry;
  8660. if( ! geometry.__webglVertexBuffer ) {
  8661. createLineBuffers( geometry );
  8662. initLineBuffers( geometry, object );
  8663. geometry.__dirtyVertices = true;
  8664. geometry.__dirtyColors = true;
  8665. }
  8666. } else if ( object instanceof THREE.ParticleSystem ) {
  8667. geometry = object.geometry;
  8668. if ( ! geometry.__webglVertexBuffer ) {
  8669. createParticleBuffers( geometry );
  8670. initParticleBuffers( geometry, object );
  8671. geometry.__dirtyVertices = true;
  8672. geometry.__dirtyColors = true;
  8673. }
  8674. }
  8675. }
  8676. if ( ! object.__webglActive ) {
  8677. if ( object instanceof THREE.Mesh ) {
  8678. geometry = object.geometry;
  8679. if ( geometry instanceof THREE.BufferGeometry ) {
  8680. addBuffer( scene.__webglObjects, geometry, object );
  8681. } else {
  8682. for ( g in geometry.geometryGroups ) {
  8683. geometryGroup = geometry.geometryGroups[ g ];
  8684. addBuffer( scene.__webglObjects, geometryGroup, object );
  8685. }
  8686. }
  8687. } else if ( object instanceof THREE.Ribbon ||
  8688. object instanceof THREE.Line ||
  8689. object instanceof THREE.ParticleSystem ) {
  8690. geometry = object.geometry;
  8691. addBuffer( scene.__webglObjects, geometry, object );
  8692. } else if ( object instanceof THREE.ImmediateRenderObject || object.immediateRenderCallback ) {
  8693. addBufferImmediate( scene.__webglObjectsImmediate, object );
  8694. } else if ( object instanceof THREE.Sprite ) {
  8695. scene.__webglSprites.push( object );
  8696. } else if ( object instanceof THREE.LensFlare ) {
  8697. scene.__webglFlares.push( object );
  8698. }
  8699. object.__webglActive = true;
  8700. }
  8701. };
  8702. function addBuffer ( objlist, buffer, object ) {
  8703. objlist.push(
  8704. {
  8705. buffer: buffer,
  8706. object: object,
  8707. opaque: null,
  8708. transparent: null
  8709. }
  8710. );
  8711. };
  8712. function addBufferImmediate ( objlist, object ) {
  8713. objlist.push(
  8714. {
  8715. object: object,
  8716. opaque: null,
  8717. transparent: null
  8718. }
  8719. );
  8720. };
  8721. // Objects updates
  8722. function updateObject ( object ) {
  8723. var geometry = object.geometry,
  8724. geometryGroup, customAttributesDirty, material;
  8725. if ( object instanceof THREE.Mesh ) {
  8726. if ( geometry instanceof THREE.BufferGeometry ) {
  8727. /*
  8728. if ( geometry.__dirtyVertices || geometry.__dirtyElements ||
  8729. geometry.__dirtyUvs || geometry.__dirtyNormals ||
  8730. geometry.__dirtyColors ) {
  8731. // TODO
  8732. // set buffers from typed arrays
  8733. }
  8734. */
  8735. geometry.__dirtyVertices = false;
  8736. geometry.__dirtyElements = false;
  8737. geometry.__dirtyUvs = false;
  8738. geometry.__dirtyNormals = false;
  8739. geometry.__dirtyColors = false;
  8740. } else {
  8741. // check all geometry groups
  8742. for( var i = 0, il = geometry.geometryGroupsList.length; i < il; i ++ ) {
  8743. geometryGroup = geometry.geometryGroupsList[ i ];
  8744. material = getBufferMaterial( object, geometryGroup );
  8745. customAttributesDirty = material.attributes && areCustomAttributesDirty( material );
  8746. if ( geometry.__dirtyVertices || geometry.__dirtyMorphTargets || geometry.__dirtyElements ||
  8747. geometry.__dirtyUvs || geometry.__dirtyNormals ||
  8748. geometry.__dirtyColors || geometry.__dirtyTangents || customAttributesDirty ) {
  8749. setMeshBuffers( geometryGroup, object, _gl.DYNAMIC_DRAW, !geometry.dynamic, material );
  8750. }
  8751. }
  8752. geometry.__dirtyVertices = false;
  8753. geometry.__dirtyMorphTargets = false;
  8754. geometry.__dirtyElements = false;
  8755. geometry.__dirtyUvs = false;
  8756. geometry.__dirtyNormals = false;
  8757. geometry.__dirtyColors = false;
  8758. geometry.__dirtyTangents = false;
  8759. material.attributes && clearCustomAttributes( material );
  8760. }
  8761. } else if ( object instanceof THREE.Ribbon ) {
  8762. if ( geometry.__dirtyVertices || geometry.__dirtyColors ) {
  8763. setRibbonBuffers( geometry, _gl.DYNAMIC_DRAW );
  8764. }
  8765. geometry.__dirtyVertices = false;
  8766. geometry.__dirtyColors = false;
  8767. } else if ( object instanceof THREE.Line ) {
  8768. material = getBufferMaterial( object, geometryGroup );
  8769. customAttributesDirty = material.attributes && areCustomAttributesDirty( material );
  8770. if ( geometry.__dirtyVertices || geometry.__dirtyColors || customAttributesDirty ) {
  8771. setLineBuffers( geometry, _gl.DYNAMIC_DRAW );
  8772. }
  8773. geometry.__dirtyVertices = false;
  8774. geometry.__dirtyColors = false;
  8775. material.attributes && clearCustomAttributes( material );
  8776. } else if ( object instanceof THREE.ParticleSystem ) {
  8777. material = getBufferMaterial( object, geometryGroup );
  8778. customAttributesDirty = material.attributes && areCustomAttributesDirty( material );
  8779. if ( geometry.__dirtyVertices || geometry.__dirtyColors || object.sortParticles || customAttributesDirty ) {
  8780. setParticleBuffers( geometry, _gl.DYNAMIC_DRAW, object );
  8781. }
  8782. geometry.__dirtyVertices = false;
  8783. geometry.__dirtyColors = false;
  8784. material.attributes && clearCustomAttributes( material );
  8785. }
  8786. };
  8787. // Objects updates - custom attributes check
  8788. function areCustomAttributesDirty ( material ) {
  8789. for ( var a in material.attributes ) {
  8790. if ( material.attributes[ a ].needsUpdate ) return true;
  8791. }
  8792. return false;
  8793. };
  8794. function clearCustomAttributes ( material ) {
  8795. for ( var a in material.attributes ) {
  8796. material.attributes[ a ].needsUpdate = false;
  8797. }
  8798. };
  8799. // Objects removal
  8800. function removeObject ( object, scene ) {
  8801. if ( object instanceof THREE.Mesh ||
  8802. object instanceof THREE.ParticleSystem ||
  8803. object instanceof THREE.Ribbon ||
  8804. object instanceof THREE.Line ) {
  8805. removeInstances( scene.__webglObjects, object );
  8806. } else if ( object instanceof THREE.Sprite ) {
  8807. removeInstancesDirect( scene.__webglSprites, object );
  8808. } else if ( object instanceof THREE.LensFlare ) {
  8809. removeInstancesDirect( scene.__webglFlares, object );
  8810. } else if ( object instanceof THREE.ImmediateRenderObject || object.immediateRenderCallback ) {
  8811. removeInstances( scene.__webglObjectsImmediate, object );
  8812. }
  8813. object.__webglActive = false;
  8814. };
  8815. function removeInstances ( objlist, object ) {
  8816. for ( var o = objlist.length - 1; o >= 0; o -- ) {
  8817. if ( objlist[ o ].object === object ) {
  8818. objlist.splice( o, 1 );
  8819. }
  8820. }
  8821. };
  8822. function removeInstancesDirect ( objlist, object ) {
  8823. for ( var o = objlist.length - 1; o >= 0; o -- ) {
  8824. if ( objlist[ o ] === object ) {
  8825. objlist.splice( o, 1 );
  8826. }
  8827. }
  8828. };
  8829. // Materials
  8830. this.initMaterial = function ( material, lights, fog, object ) {
  8831. var u, a, identifiers, i, parameters, maxLightCount, maxBones, maxShadows, shaderID;
  8832. if ( material instanceof THREE.MeshDepthMaterial ) {
  8833. shaderID = 'depth';
  8834. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  8835. shaderID = 'normal';
  8836. } else if ( material instanceof THREE.MeshBasicMaterial ) {
  8837. shaderID = 'basic';
  8838. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  8839. shaderID = 'lambert';
  8840. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  8841. shaderID = 'phong';
  8842. } else if ( material instanceof THREE.LineBasicMaterial ) {
  8843. shaderID = 'basic';
  8844. } else if ( material instanceof THREE.ParticleBasicMaterial ) {
  8845. shaderID = 'particle_basic';
  8846. }
  8847. if ( shaderID ) {
  8848. setMaterialShaders( material, THREE.ShaderLib[ shaderID ] );
  8849. }
  8850. // heuristics to create shader parameters according to lights in the scene
  8851. // (not to blow over maxLights budget)
  8852. maxLightCount = allocateLights( lights );
  8853. maxShadows = allocateShadows( lights );
  8854. maxBones = allocateBones( object );
  8855. parameters = {
  8856. map: !!material.map,
  8857. envMap: !!material.envMap,
  8858. lightMap: !!material.lightMap,
  8859. vertexColors: material.vertexColors,
  8860. fog: fog,
  8861. useFog: material.fog,
  8862. sizeAttenuation: material.sizeAttenuation,
  8863. skinning: material.skinning,
  8864. maxBones: maxBones,
  8865. morphTargets: material.morphTargets,
  8866. morphNormals: material.morphNormals,
  8867. maxMorphTargets: this.maxMorphTargets,
  8868. maxMorphNormals: this.maxMorphNormals,
  8869. maxDirLights: maxLightCount.directional,
  8870. maxPointLights: maxLightCount.point,
  8871. maxSpotLights: maxLightCount.spot,
  8872. maxShadows: maxShadows,
  8873. shadowMapEnabled: this.shadowMapEnabled && object.receiveShadow,
  8874. shadowMapSoft: this.shadowMapSoft,
  8875. shadowMapDebug: this.shadowMapDebug,
  8876. shadowMapCascade: this.shadowMapCascade,
  8877. alphaTest: material.alphaTest,
  8878. metal: material.metal,
  8879. perPixel: material.perPixel,
  8880. wrapAround: material.wrapAround,
  8881. doubleSided: object && object.doubleSided
  8882. };
  8883. material.program = buildProgram( shaderID, material.fragmentShader, material.vertexShader, material.uniforms, material.attributes, parameters );
  8884. var attributes = material.program.attributes;
  8885. if ( attributes.position >= 0 ) _gl.enableVertexAttribArray( attributes.position );
  8886. if ( attributes.color >= 0 ) _gl.enableVertexAttribArray( attributes.color );
  8887. if ( attributes.normal >= 0 ) _gl.enableVertexAttribArray( attributes.normal );
  8888. if ( attributes.tangent >= 0 ) _gl.enableVertexAttribArray( attributes.tangent );
  8889. if ( material.skinning &&
  8890. attributes.skinVertexA >=0 && attributes.skinVertexB >= 0 &&
  8891. attributes.skinIndex >= 0 && attributes.skinWeight >= 0 ) {
  8892. _gl.enableVertexAttribArray( attributes.skinVertexA );
  8893. _gl.enableVertexAttribArray( attributes.skinVertexB );
  8894. _gl.enableVertexAttribArray( attributes.skinIndex );
  8895. _gl.enableVertexAttribArray( attributes.skinWeight );
  8896. }
  8897. if ( material.attributes ) {
  8898. for ( a in material.attributes ) {
  8899. if( attributes[ a ] !== undefined && attributes[ a ] >= 0 ) _gl.enableVertexAttribArray( attributes[ a ] );
  8900. }
  8901. }
  8902. if ( material.morphTargets ) {
  8903. material.numSupportedMorphTargets = 0;
  8904. var id, base = "morphTarget";
  8905. for ( i = 0; i < this.maxMorphTargets; i ++ ) {
  8906. id = base + i;
  8907. if ( attributes[ id ] >= 0 ) {
  8908. _gl.enableVertexAttribArray( attributes[ id ] );
  8909. material.numSupportedMorphTargets ++;
  8910. }
  8911. }
  8912. }
  8913. if ( material.morphNormals ) {
  8914. material.numSupportedMorphNormals = 0;
  8915. var id, base = "morphNormal";
  8916. for ( i = 0; i < this.maxMorphNormals; i ++ ) {
  8917. id = base + i;
  8918. if ( attributes[ id ] >= 0 ) {
  8919. _gl.enableVertexAttribArray( attributes[ id ] );
  8920. material.numSupportedMorphNormals ++;
  8921. }
  8922. }
  8923. }
  8924. material.uniformsList = [];
  8925. for ( u in material.uniforms ) {
  8926. material.uniformsList.push( [ material.uniforms[ u ], u ] );
  8927. }
  8928. };
  8929. function setMaterialShaders( material, shaders ) {
  8930. material.uniforms = THREE.UniformsUtils.clone( shaders.uniforms );
  8931. material.vertexShader = shaders.vertexShader;
  8932. material.fragmentShader = shaders.fragmentShader;
  8933. };
  8934. function setProgram( camera, lights, fog, material, object ) {
  8935. if ( ! material.program || material.needsUpdate ) {
  8936. _this.initMaterial( material, lights, fog, object );
  8937. material.needsUpdate = false;
  8938. }
  8939. if ( material.morphTargets ) {
  8940. if ( ! object.__webglMorphTargetInfluences ) {
  8941. object.__webglMorphTargetInfluences = new Float32Array( _this.maxMorphTargets );
  8942. for ( var i = 0, il = _this.maxMorphTargets; i < il; i ++ ) {
  8943. object.__webglMorphTargetInfluences[ i ] = 0;
  8944. }
  8945. }
  8946. }
  8947. var refreshMaterial = false;
  8948. var program = material.program,
  8949. p_uniforms = program.uniforms,
  8950. m_uniforms = material.uniforms;
  8951. if ( program !== _currentProgram ) {
  8952. _gl.useProgram( program );
  8953. _currentProgram = program;
  8954. refreshMaterial = true;
  8955. }
  8956. if ( material.id !== _currentMaterialId ) {
  8957. _currentMaterialId = material.id;
  8958. refreshMaterial = true;
  8959. }
  8960. if ( refreshMaterial || camera !== _currentCamera ) {
  8961. _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera._projectionMatrixArray );
  8962. if ( camera !== _currentCamera ) _currentCamera = camera;
  8963. }
  8964. if ( refreshMaterial ) {
  8965. // refresh uniforms common to several materials
  8966. if ( fog && material.fog ) {
  8967. refreshUniformsFog( m_uniforms, fog );
  8968. }
  8969. if ( material instanceof THREE.MeshPhongMaterial ||
  8970. material instanceof THREE.MeshLambertMaterial ||
  8971. material.lights ) {
  8972. setupLights( program, lights );
  8973. refreshUniformsLights( m_uniforms, _lights );
  8974. }
  8975. if ( material instanceof THREE.MeshBasicMaterial ||
  8976. material instanceof THREE.MeshLambertMaterial ||
  8977. material instanceof THREE.MeshPhongMaterial ) {
  8978. refreshUniformsCommon( m_uniforms, material );
  8979. }
  8980. // refresh single material specific uniforms
  8981. if ( material instanceof THREE.LineBasicMaterial ) {
  8982. refreshUniformsLine( m_uniforms, material );
  8983. } else if ( material instanceof THREE.ParticleBasicMaterial ) {
  8984. refreshUniformsParticle( m_uniforms, material );
  8985. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  8986. refreshUniformsPhong( m_uniforms, material );
  8987. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  8988. refreshUniformsLambert( m_uniforms, material );
  8989. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  8990. m_uniforms.mNear.value = camera.near;
  8991. m_uniforms.mFar.value = camera.far;
  8992. m_uniforms.opacity.value = material.opacity;
  8993. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  8994. m_uniforms.opacity.value = material.opacity;
  8995. }
  8996. if ( object.receiveShadow && ! material._shadowPass ) {
  8997. refreshUniformsShadow( m_uniforms, lights );
  8998. }
  8999. // load common uniforms
  9000. loadUniformsGeneric( program, material.uniformsList );
  9001. // load material specific uniforms
  9002. // (shader material also gets them for the sake of genericity)
  9003. if ( material instanceof THREE.ShaderMaterial ||
  9004. material instanceof THREE.MeshPhongMaterial ||
  9005. material.envMap ) {
  9006. if ( p_uniforms.cameraPosition !== null ) {
  9007. var position = camera.matrixWorld.getPosition();
  9008. _gl.uniform3f( p_uniforms.cameraPosition, position.x, position.y, position.z );
  9009. }
  9010. }
  9011. if ( material instanceof THREE.MeshPhongMaterial ||
  9012. material instanceof THREE.MeshLambertMaterial ||
  9013. material instanceof THREE.ShaderMaterial ||
  9014. material.skinning ) {
  9015. if ( p_uniforms.viewMatrix !== null ) {
  9016. _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera._viewMatrixArray );
  9017. }
  9018. }
  9019. if ( material.skinning ) {
  9020. _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.boneMatrices );
  9021. }
  9022. }
  9023. loadUniformsMatrices( p_uniforms, object );
  9024. if ( material instanceof THREE.ShaderMaterial ||
  9025. material.envMap ||
  9026. material.skinning ||
  9027. object.receiveShadow ) {
  9028. if ( p_uniforms.objectMatrix !== null ) {
  9029. _gl.uniformMatrix4fv( p_uniforms.objectMatrix, false, object.matrixWorld.elements );
  9030. }
  9031. }
  9032. return program;
  9033. };
  9034. // Uniforms (refresh uniforms objects)
  9035. function refreshUniformsCommon ( uniforms, material ) {
  9036. uniforms.opacity.value = material.opacity;
  9037. if ( _this.gammaInput ) {
  9038. uniforms.diffuse.value.copyGammaToLinear( material.color );
  9039. } else {
  9040. uniforms.diffuse.value = material.color;
  9041. }
  9042. uniforms.map.texture = material.map;
  9043. if ( material.map ) {
  9044. uniforms.offsetRepeat.value.set( material.map.offset.x, material.map.offset.y, material.map.repeat.x, material.map.repeat.y );
  9045. }
  9046. uniforms.lightMap.texture = material.lightMap;
  9047. uniforms.envMap.texture = material.envMap;
  9048. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : -1;
  9049. if ( _this.gammaInput ) {
  9050. //uniforms.reflectivity.value = material.reflectivity * material.reflectivity;
  9051. uniforms.reflectivity.value = material.reflectivity;
  9052. } else {
  9053. uniforms.reflectivity.value = material.reflectivity;
  9054. }
  9055. uniforms.refractionRatio.value = material.refractionRatio;
  9056. uniforms.combine.value = material.combine;
  9057. uniforms.useRefract.value = material.envMap && material.envMap.mapping instanceof THREE.CubeRefractionMapping;
  9058. };
  9059. function refreshUniformsLine ( uniforms, material ) {
  9060. uniforms.diffuse.value = material.color;
  9061. uniforms.opacity.value = material.opacity;
  9062. };
  9063. function refreshUniformsParticle ( uniforms, material ) {
  9064. uniforms.psColor.value = material.color;
  9065. uniforms.opacity.value = material.opacity;
  9066. uniforms.size.value = material.size;
  9067. uniforms.scale.value = _canvas.height / 2.0; // TODO: Cache this.
  9068. uniforms.map.texture = material.map;
  9069. };
  9070. function refreshUniformsFog ( uniforms, fog ) {
  9071. uniforms.fogColor.value = fog.color;
  9072. if ( fog instanceof THREE.Fog ) {
  9073. uniforms.fogNear.value = fog.near;
  9074. uniforms.fogFar.value = fog.far;
  9075. } else if ( fog instanceof THREE.FogExp2 ) {
  9076. uniforms.fogDensity.value = fog.density;
  9077. }
  9078. };
  9079. function refreshUniformsPhong ( uniforms, material ) {
  9080. uniforms.shininess.value = material.shininess;
  9081. if ( _this.gammaInput ) {
  9082. uniforms.ambient.value.copyGammaToLinear( material.ambient );
  9083. uniforms.emissive.value.copyGammaToLinear( material.emissive );
  9084. uniforms.specular.value.copyGammaToLinear( material.specular );
  9085. } else {
  9086. uniforms.ambient.value = material.ambient;
  9087. uniforms.emissive.value = material.emissive;
  9088. uniforms.specular.value = material.specular;
  9089. }
  9090. if ( material.wrapAround ) {
  9091. uniforms.wrapRGB.value.copy( material.wrapRGB );
  9092. }
  9093. };
  9094. function refreshUniformsLambert ( uniforms, material ) {
  9095. if ( _this.gammaInput ) {
  9096. uniforms.ambient.value.copyGammaToLinear( material.ambient );
  9097. uniforms.emissive.value.copyGammaToLinear( material.emissive );
  9098. } else {
  9099. uniforms.ambient.value = material.ambient;
  9100. uniforms.emissive.value = material.emissive;
  9101. }
  9102. if ( material.wrapAround ) {
  9103. uniforms.wrapRGB.value.copy( material.wrapRGB );
  9104. }
  9105. };
  9106. function refreshUniformsLights ( uniforms, lights ) {
  9107. uniforms.ambientLightColor.value = lights.ambient;
  9108. uniforms.directionalLightColor.value = lights.directional.colors;
  9109. uniforms.directionalLightDirection.value = lights.directional.positions;
  9110. uniforms.pointLightColor.value = lights.point.colors;
  9111. uniforms.pointLightPosition.value = lights.point.positions;
  9112. uniforms.pointLightDistance.value = lights.point.distances;
  9113. uniforms.spotLightColor.value = lights.spot.colors;
  9114. uniforms.spotLightPosition.value = lights.spot.positions;
  9115. uniforms.spotLightDistance.value = lights.spot.distances;
  9116. uniforms.spotLightDirection.value = lights.spot.directions;
  9117. uniforms.spotLightAngle.value = lights.spot.angles;
  9118. uniforms.spotLightExponent.value = lights.spot.exponents;
  9119. };
  9120. function refreshUniformsShadow ( uniforms, lights ) {
  9121. if ( uniforms.shadowMatrix ) {
  9122. var j = 0;
  9123. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  9124. var light = lights[ i ];
  9125. if ( ! light.castShadow ) continue;
  9126. if ( light instanceof THREE.SpotLight || ( light instanceof THREE.DirectionalLight && ! light.shadowCascade ) ) {
  9127. uniforms.shadowMap.texture[ j ] = light.shadowMap;
  9128. uniforms.shadowMapSize.value[ j ] = light.shadowMapSize;
  9129. uniforms.shadowMatrix.value[ j ] = light.shadowMatrix;
  9130. uniforms.shadowDarkness.value[ j ] = light.shadowDarkness;
  9131. uniforms.shadowBias.value[ j ] = light.shadowBias;
  9132. j ++;
  9133. }
  9134. }
  9135. }
  9136. };
  9137. // Uniforms (load to GPU)
  9138. function loadUniformsMatrices ( uniforms, object ) {
  9139. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object._modelViewMatrix.elements );
  9140. if ( uniforms.normalMatrix ) {
  9141. _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object._normalMatrix.elements );
  9142. }
  9143. };
  9144. function loadUniformsGeneric ( program, uniforms ) {
  9145. var uniform, value, type, location, texture, i, il, j, jl, offset;
  9146. for( j = 0, jl = uniforms.length; j < jl; j ++ ) {
  9147. location = program.uniforms[ uniforms[ j ][ 1 ] ];
  9148. if ( !location ) continue;
  9149. uniform = uniforms[ j ][ 0 ];
  9150. type = uniform.type;
  9151. value = uniform.value;
  9152. // single integer
  9153. if( type === "i" ) {
  9154. _gl.uniform1i( location, value );
  9155. // single float
  9156. } else if( type === "f" ) {
  9157. _gl.uniform1f( location, value );
  9158. // single THREE.Vector2
  9159. } else if( type === "v2" ) {
  9160. _gl.uniform2f( location, value.x, value.y );
  9161. // single THREE.Vector3
  9162. } else if( type === "v3" ) {
  9163. _gl.uniform3f( location, value.x, value.y, value.z );
  9164. // single THREE.Vector4
  9165. } else if( type === "v4" ) {
  9166. _gl.uniform4f( location, value.x, value.y, value.z, value.w );
  9167. // single THREE.Color
  9168. } else if( type === "c" ) {
  9169. _gl.uniform3f( location, value.r, value.g, value.b );
  9170. // flat array of floats (JS or typed array)
  9171. } else if( type === "fv1" ) {
  9172. _gl.uniform1fv( location, value );
  9173. // flat array of floats with 3 x N size (JS or typed array)
  9174. } else if( type === "fv" ) {
  9175. _gl.uniform3fv( location, value );
  9176. // array of THREE.Vector2
  9177. } else if( type === "v2v" ) {
  9178. if ( ! uniform._array ) {
  9179. uniform._array = new Float32Array( 2 * value.length );
  9180. }
  9181. for ( i = 0, il = value.length; i < il; i ++ ) {
  9182. offset = i * 2;
  9183. uniform._array[ offset ] = value[ i ].x;
  9184. uniform._array[ offset + 1 ] = value[ i ].y;
  9185. }
  9186. _gl.uniform2fv( location, uniform._array );
  9187. // array of THREE.Vector3
  9188. } else if( type === "v3v" ) {
  9189. if ( ! uniform._array ) {
  9190. uniform._array = new Float32Array( 3 * value.length );
  9191. }
  9192. for ( i = 0, il = value.length; i < il; i ++ ) {
  9193. offset = i * 3;
  9194. uniform._array[ offset ] = value[ i ].x;
  9195. uniform._array[ offset + 1 ] = value[ i ].y;
  9196. uniform._array[ offset + 2 ] = value[ i ].z;
  9197. }
  9198. _gl.uniform3fv( location, uniform._array );
  9199. // array of THREE.Vector4
  9200. } else if( type == "v4v" ) {
  9201. if ( ! uniform._array ) {
  9202. uniform._array = new Float32Array( 4 * value.length );
  9203. }
  9204. for ( i = 0, il = value.length; i < il; i ++ ) {
  9205. offset = i * 4;
  9206. uniform._array[ offset ] = value[ i ].x;
  9207. uniform._array[ offset + 1 ] = value[ i ].y;
  9208. uniform._array[ offset + 2 ] = value[ i ].z;
  9209. uniform._array[ offset + 3 ] = value[ i ].w;
  9210. }
  9211. _gl.uniform4fv( location, uniform._array );
  9212. // single THREE.Matrix4
  9213. } else if( type === "m4" ) {
  9214. if ( ! uniform._array ) {
  9215. uniform._array = new Float32Array( 16 );
  9216. }
  9217. value.flattenToArray( uniform._array );
  9218. _gl.uniformMatrix4fv( location, false, uniform._array );
  9219. // array of THREE.Matrix4
  9220. } else if( type === "m4v" ) {
  9221. if ( ! uniform._array ) {
  9222. uniform._array = new Float32Array( 16 * value.length );
  9223. }
  9224. for ( i = 0, il = value.length; i < il; i ++ ) {
  9225. value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
  9226. }
  9227. _gl.uniformMatrix4fv( location, false, uniform._array );
  9228. // single THREE.Texture (2d or cube)
  9229. } else if( type === "t" ) {
  9230. _gl.uniform1i( location, value );
  9231. texture = uniform.texture;
  9232. if ( !texture ) continue;
  9233. if ( texture.image instanceof Array && texture.image.length === 6 ) {
  9234. setCubeTexture( texture, value );
  9235. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  9236. setCubeTextureDynamic( texture, value );
  9237. } else {
  9238. _this.setTexture( texture, value );
  9239. }
  9240. // array of THREE.Texture (2d)
  9241. } else if( type === "tv" ) {
  9242. if ( ! uniform._array ) {
  9243. uniform._array = [];
  9244. for( i = 0, il = uniform.texture.length; i < il; i ++ ) {
  9245. uniform._array[ i ] = value + i;
  9246. }
  9247. }
  9248. _gl.uniform1iv( location, uniform._array );
  9249. for( i = 0, il = uniform.texture.length; i < il; i ++ ) {
  9250. texture = uniform.texture[ i ];
  9251. if ( !texture ) continue;
  9252. _this.setTexture( texture, uniform._array[ i ] );
  9253. }
  9254. }
  9255. }
  9256. };
  9257. function setupMatrices ( object, camera ) {
  9258. object._modelViewMatrix.multiply( camera.matrixWorldInverse, object.matrixWorld);
  9259. object._normalMatrix.getInverse( object._modelViewMatrix );
  9260. object._normalMatrix.transpose();
  9261. };
  9262. function setupLights ( program, lights ) {
  9263. var l, ll, light, n,
  9264. r = 0, g = 0, b = 0,
  9265. color, position, intensity, distance,
  9266. zlights = _lights,
  9267. dcolors = zlights.directional.colors,
  9268. dpositions = zlights.directional.positions,
  9269. pcolors = zlights.point.colors,
  9270. ppositions = zlights.point.positions,
  9271. pdistances = zlights.point.distances,
  9272. scolors = zlights.spot.colors,
  9273. spositions = zlights.spot.positions,
  9274. sdistances = zlights.spot.distances,
  9275. sdirections = zlights.spot.directions,
  9276. sangles = zlights.spot.angles,
  9277. sexponents = zlights.spot.exponents,
  9278. dlength = 0,
  9279. plength = 0,
  9280. slength = 0,
  9281. doffset = 0,
  9282. poffset = 0,
  9283. soffset = 0;
  9284. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  9285. light = lights[ l ];
  9286. if ( light.onlyShadow ) continue;
  9287. color = light.color;
  9288. intensity = light.intensity;
  9289. distance = light.distance;
  9290. if ( light instanceof THREE.AmbientLight ) {
  9291. if ( _this.gammaInput ) {
  9292. r += color.r * color.r;
  9293. g += color.g * color.g;
  9294. b += color.b * color.b;
  9295. } else {
  9296. r += color.r;
  9297. g += color.g;
  9298. b += color.b;
  9299. }
  9300. } else if ( light instanceof THREE.DirectionalLight ) {
  9301. doffset = dlength * 3;
  9302. if ( _this.gammaInput ) {
  9303. dcolors[ doffset ] = color.r * color.r * intensity * intensity;
  9304. dcolors[ doffset + 1 ] = color.g * color.g * intensity * intensity;
  9305. dcolors[ doffset + 2 ] = color.b * color.b * intensity * intensity;
  9306. } else {
  9307. dcolors[ doffset ] = color.r * intensity;
  9308. dcolors[ doffset + 1 ] = color.g * intensity;
  9309. dcolors[ doffset + 2 ] = color.b * intensity;
  9310. }
  9311. _direction.copy( light.matrixWorld.getPosition() );
  9312. _direction.subSelf( light.target.matrixWorld.getPosition() );
  9313. _direction.normalize();
  9314. dpositions[ doffset ] = _direction.x;
  9315. dpositions[ doffset + 1 ] = _direction.y;
  9316. dpositions[ doffset + 2 ] = _direction.z;
  9317. dlength += 1;
  9318. } else if( light instanceof THREE.PointLight ) {
  9319. poffset = plength * 3;
  9320. if ( _this.gammaInput ) {
  9321. pcolors[ poffset ] = color.r * color.r * intensity * intensity;
  9322. pcolors[ poffset + 1 ] = color.g * color.g * intensity * intensity;
  9323. pcolors[ poffset + 2 ] = color.b * color.b * intensity * intensity;
  9324. } else {
  9325. pcolors[ poffset ] = color.r * intensity;
  9326. pcolors[ poffset + 1 ] = color.g * intensity;
  9327. pcolors[ poffset + 2 ] = color.b * intensity;
  9328. }
  9329. position = light.matrixWorld.getPosition();
  9330. ppositions[ poffset ] = position.x;
  9331. ppositions[ poffset + 1 ] = position.y;
  9332. ppositions[ poffset + 2 ] = position.z;
  9333. pdistances[ plength ] = distance;
  9334. plength += 1;
  9335. } else if( light instanceof THREE.SpotLight ) {
  9336. soffset = slength * 3;
  9337. if ( _this.gammaInput ) {
  9338. scolors[ soffset ] = color.r * color.r * intensity * intensity;
  9339. scolors[ soffset + 1 ] = color.g * color.g * intensity * intensity;
  9340. scolors[ soffset + 2 ] = color.b * color.b * intensity * intensity;
  9341. } else {
  9342. scolors[ soffset ] = color.r * intensity;
  9343. scolors[ soffset + 1 ] = color.g * intensity;
  9344. scolors[ soffset + 2 ] = color.b * intensity;
  9345. }
  9346. position = light.matrixWorld.getPosition();
  9347. spositions[ soffset ] = position.x;
  9348. spositions[ soffset + 1 ] = position.y;
  9349. spositions[ soffset + 2 ] = position.z;
  9350. sdistances[ slength ] = distance;
  9351. _direction.copy( position );
  9352. _direction.subSelf( light.target.matrixWorld.getPosition() );
  9353. _direction.normalize();
  9354. sdirections[ soffset ] = _direction.x;
  9355. sdirections[ soffset + 1 ] = _direction.y;
  9356. sdirections[ soffset + 2 ] = _direction.z;
  9357. sangles[ slength ] = Math.cos( light.angle );
  9358. sexponents[ slength ] = light.exponent;
  9359. slength += 1;
  9360. }
  9361. }
  9362. // null eventual remains from removed lights
  9363. // (this is to avoid if in shader)
  9364. for ( l = dlength * 3, ll = dcolors.length; l < ll; l ++ ) dcolors[ l ] = 0.0;
  9365. for ( l = plength * 3, ll = pcolors.length; l < ll; l ++ ) pcolors[ l ] = 0.0;
  9366. for ( l = slength * 3, ll = scolors.length; l < ll; l ++ ) scolors[ l ] = 0.0;
  9367. zlights.directional.length = dlength;
  9368. zlights.point.length = plength;
  9369. zlights.spot.length = slength;
  9370. zlights.ambient[ 0 ] = r;
  9371. zlights.ambient[ 1 ] = g;
  9372. zlights.ambient[ 2 ] = b;
  9373. };
  9374. // GL state setting
  9375. this.setFaceCulling = function ( cullFace, frontFace ) {
  9376. if ( cullFace ) {
  9377. if ( !frontFace || frontFace === "ccw" ) {
  9378. _gl.frontFace( _gl.CCW );
  9379. } else {
  9380. _gl.frontFace( _gl.CW );
  9381. }
  9382. if( cullFace === "back" ) {
  9383. _gl.cullFace( _gl.BACK );
  9384. } else if( cullFace === "front" ) {
  9385. _gl.cullFace( _gl.FRONT );
  9386. } else {
  9387. _gl.cullFace( _gl.FRONT_AND_BACK );
  9388. }
  9389. _gl.enable( _gl.CULL_FACE );
  9390. } else {
  9391. _gl.disable( _gl.CULL_FACE );
  9392. }
  9393. };
  9394. this.setObjectFaces = function ( object ) {
  9395. if ( _oldDoubleSided !== object.doubleSided ) {
  9396. if( object.doubleSided ) {
  9397. _gl.disable( _gl.CULL_FACE );
  9398. } else {
  9399. _gl.enable( _gl.CULL_FACE );
  9400. }
  9401. _oldDoubleSided = object.doubleSided;
  9402. }
  9403. if ( _oldFlipSided !== object.flipSided ) {
  9404. if( object.flipSided ) {
  9405. _gl.frontFace( _gl.CW );
  9406. } else {
  9407. _gl.frontFace( _gl.CCW );
  9408. }
  9409. _oldFlipSided = object.flipSided;
  9410. }
  9411. };
  9412. this.setDepthTest = function ( depthTest ) {
  9413. if ( _oldDepthTest !== depthTest ) {
  9414. if ( depthTest ) {
  9415. _gl.enable( _gl.DEPTH_TEST );
  9416. } else {
  9417. _gl.disable( _gl.DEPTH_TEST );
  9418. }
  9419. _oldDepthTest = depthTest;
  9420. }
  9421. };
  9422. this.setDepthWrite = function ( depthWrite ) {
  9423. if ( _oldDepthWrite !== depthWrite ) {
  9424. _gl.depthMask( depthWrite );
  9425. _oldDepthWrite = depthWrite;
  9426. }
  9427. };
  9428. function setLineWidth ( width ) {
  9429. if ( width !== _oldLineWidth ) {
  9430. _gl.lineWidth( width );
  9431. _oldLineWidth = width;
  9432. }
  9433. };
  9434. function setPolygonOffset ( polygonoffset, factor, units ) {
  9435. if ( _oldPolygonOffset !== polygonoffset ) {
  9436. if ( polygonoffset ) {
  9437. _gl.enable( _gl.POLYGON_OFFSET_FILL );
  9438. } else {
  9439. _gl.disable( _gl.POLYGON_OFFSET_FILL );
  9440. }
  9441. _oldPolygonOffset = polygonoffset;
  9442. }
  9443. if ( polygonoffset && ( _oldPolygonOffsetFactor !== factor || _oldPolygonOffsetUnits !== units ) ) {
  9444. _gl.polygonOffset( factor, units );
  9445. _oldPolygonOffsetFactor = factor;
  9446. _oldPolygonOffsetUnits = units;
  9447. }
  9448. };
  9449. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst ) {
  9450. if ( blending !== _oldBlending ) {
  9451. switch ( blending ) {
  9452. case THREE.NoBlending:
  9453. _gl.disable( _gl.BLEND );
  9454. break;
  9455. case THREE.AdditiveBlending:
  9456. _gl.enable( _gl.BLEND );
  9457. _gl.blendEquation( _gl.FUNC_ADD );
  9458. _gl.blendFunc( _gl.SRC_ALPHA, _gl.ONE );
  9459. break;
  9460. case THREE.SubtractiveBlending:
  9461. // TODO: Find blendFuncSeparate() combination
  9462. _gl.enable( _gl.BLEND );
  9463. _gl.blendEquation( _gl.FUNC_ADD );
  9464. _gl.blendFunc( _gl.ZERO, _gl.ONE_MINUS_SRC_COLOR );
  9465. break;
  9466. case THREE.MultiplyBlending:
  9467. // TODO: Find blendFuncSeparate() combination
  9468. _gl.enable( _gl.BLEND );
  9469. _gl.blendEquation( _gl.FUNC_ADD );
  9470. _gl.blendFunc( _gl.ZERO, _gl.SRC_COLOR );
  9471. break;
  9472. case THREE.CustomBlending:
  9473. _gl.enable( _gl.BLEND );
  9474. break;
  9475. default:
  9476. _gl.enable( _gl.BLEND );
  9477. _gl.blendEquationSeparate( _gl.FUNC_ADD, _gl.FUNC_ADD );
  9478. _gl.blendFuncSeparate( _gl.SRC_ALPHA, _gl.ONE_MINUS_SRC_ALPHA, _gl.ONE, _gl.ONE_MINUS_SRC_ALPHA );
  9479. break;
  9480. }
  9481. _oldBlending = blending;
  9482. }
  9483. if ( blending === THREE.CustomBlending ) {
  9484. if ( blendEquation !== _oldBlendEquation ) {
  9485. _gl.blendEquation( paramThreeToGL( blendEquation ) );
  9486. _oldBlendEquation = blendEquation;
  9487. }
  9488. if ( blendSrc !== _oldBlendSrc || blendDst !== _oldBlendDst ) {
  9489. _gl.blendFunc( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ) );
  9490. _oldBlendSrc = blendSrc;
  9491. _oldBlendDst = blendDst;
  9492. }
  9493. } else {
  9494. _oldBlendEquation = null;
  9495. _oldBlendSrc = null;
  9496. _oldBlendDst = null;
  9497. }
  9498. };
  9499. // Shaders
  9500. function buildProgram ( shaderID, fragmentShader, vertexShader, uniforms, attributes, parameters ) {
  9501. var p, pl, program, code;
  9502. var chunks = [];
  9503. // Generate code
  9504. if ( shaderID ) {
  9505. chunks.push( shaderID );
  9506. } else {
  9507. chunks.push( fragmentShader );
  9508. chunks.push( vertexShader );
  9509. }
  9510. for ( p in parameters ) {
  9511. chunks.push( p );
  9512. chunks.push( parameters[ p ] );
  9513. }
  9514. code = chunks.join();
  9515. // Check if code has been already compiled
  9516. for ( p = 0, pl = _programs.length; p < pl; p ++ ) {
  9517. if ( _programs[ p ].code === code ) {
  9518. // console.log( "Code already compiled." /*: \n\n" + code*/ );
  9519. return _programs[ p ].program;
  9520. }
  9521. }
  9522. //console.log( "building new program " );
  9523. //
  9524. program = _gl.createProgram();
  9525. var prefix_vertex = [
  9526. "precision " + _precision + " float;",
  9527. ( _maxVertexTextures > 0 ) ? "#define VERTEX_TEXTURES" : "",
  9528. _this.gammaInput ? "#define GAMMA_INPUT" : "",
  9529. _this.gammaOutput ? "#define GAMMA_OUTPUT" : "",
  9530. _this.physicallyBasedShading ? "#define PHYSICALLY_BASED_SHADING" : "",
  9531. "#define MAX_DIR_LIGHTS " + parameters.maxDirLights,
  9532. "#define MAX_POINT_LIGHTS " + parameters.maxPointLights,
  9533. "#define MAX_SPOT_LIGHTS " + parameters.maxSpotLights,
  9534. "#define MAX_SHADOWS " + parameters.maxShadows,
  9535. "#define MAX_BONES " + parameters.maxBones,
  9536. parameters.map ? "#define USE_MAP" : "",
  9537. parameters.envMap ? "#define USE_ENVMAP" : "",
  9538. parameters.lightMap ? "#define USE_LIGHTMAP" : "",
  9539. parameters.vertexColors ? "#define USE_COLOR" : "",
  9540. parameters.skinning ? "#define USE_SKINNING" : "",
  9541. parameters.morphTargets ? "#define USE_MORPHTARGETS" : "",
  9542. parameters.morphNormals ? "#define USE_MORPHNORMALS" : "",
  9543. parameters.perPixel ? "#define PHONG_PER_PIXEL" : "",
  9544. parameters.wrapAround ? "#define WRAP_AROUND" : "",
  9545. parameters.doubleSided ? "#define DOUBLE_SIDED" : "",
  9546. parameters.shadowMapEnabled ? "#define USE_SHADOWMAP" : "",
  9547. parameters.shadowMapSoft ? "#define SHADOWMAP_SOFT" : "",
  9548. parameters.shadowMapDebug ? "#define SHADOWMAP_DEBUG" : "",
  9549. parameters.shadowMapCascade ? "#define SHADOWMAP_CASCADE" : "",
  9550. parameters.sizeAttenuation ? "#define USE_SIZEATTENUATION" : "",
  9551. "uniform mat4 objectMatrix;",
  9552. "uniform mat4 modelViewMatrix;",
  9553. "uniform mat4 projectionMatrix;",
  9554. "uniform mat4 viewMatrix;",
  9555. "uniform mat3 normalMatrix;",
  9556. "uniform vec3 cameraPosition;",
  9557. "attribute vec3 position;",
  9558. "attribute vec3 normal;",
  9559. "attribute vec2 uv;",
  9560. "attribute vec2 uv2;",
  9561. "#ifdef USE_COLOR",
  9562. "attribute vec3 color;",
  9563. "#endif",
  9564. "#ifdef USE_MORPHTARGETS",
  9565. "attribute vec3 morphTarget0;",
  9566. "attribute vec3 morphTarget1;",
  9567. "attribute vec3 morphTarget2;",
  9568. "attribute vec3 morphTarget3;",
  9569. "#ifdef USE_MORPHNORMALS",
  9570. "attribute vec3 morphNormal0;",
  9571. "attribute vec3 morphNormal1;",
  9572. "attribute vec3 morphNormal2;",
  9573. "attribute vec3 morphNormal3;",
  9574. "#else",
  9575. "attribute vec3 morphTarget4;",
  9576. "attribute vec3 morphTarget5;",
  9577. "attribute vec3 morphTarget6;",
  9578. "attribute vec3 morphTarget7;",
  9579. "#endif",
  9580. "#endif",
  9581. "#ifdef USE_SKINNING",
  9582. "attribute vec4 skinVertexA;",
  9583. "attribute vec4 skinVertexB;",
  9584. "attribute vec4 skinIndex;",
  9585. "attribute vec4 skinWeight;",
  9586. "#endif",
  9587. ""
  9588. ].join("\n");
  9589. var prefix_fragment = [
  9590. "precision " + _precision + " float;",
  9591. "#define MAX_DIR_LIGHTS " + parameters.maxDirLights,
  9592. "#define MAX_POINT_LIGHTS " + parameters.maxPointLights,
  9593. "#define MAX_SPOT_LIGHTS " + parameters.maxSpotLights,
  9594. "#define MAX_SHADOWS " + parameters.maxShadows,
  9595. parameters.alphaTest ? "#define ALPHATEST " + parameters.alphaTest: "",
  9596. _this.gammaInput ? "#define GAMMA_INPUT" : "",
  9597. _this.gammaOutput ? "#define GAMMA_OUTPUT" : "",
  9598. _this.physicallyBasedShading ? "#define PHYSICALLY_BASED_SHADING" : "",
  9599. ( parameters.useFog && parameters.fog ) ? "#define USE_FOG" : "",
  9600. ( parameters.useFog && parameters.fog instanceof THREE.FogExp2 ) ? "#define FOG_EXP2" : "",
  9601. parameters.map ? "#define USE_MAP" : "",
  9602. parameters.envMap ? "#define USE_ENVMAP" : "",
  9603. parameters.lightMap ? "#define USE_LIGHTMAP" : "",
  9604. parameters.vertexColors ? "#define USE_COLOR" : "",
  9605. parameters.metal ? "#define METAL" : "",
  9606. parameters.perPixel ? "#define PHONG_PER_PIXEL" : "",
  9607. parameters.wrapAround ? "#define WRAP_AROUND" : "",
  9608. parameters.doubleSided ? "#define DOUBLE_SIDED" : "",
  9609. parameters.shadowMapEnabled ? "#define USE_SHADOWMAP" : "",
  9610. parameters.shadowMapSoft ? "#define SHADOWMAP_SOFT" : "",
  9611. parameters.shadowMapDebug ? "#define SHADOWMAP_DEBUG" : "",
  9612. parameters.shadowMapCascade ? "#define SHADOWMAP_CASCADE" : "",
  9613. "uniform mat4 viewMatrix;",
  9614. "uniform vec3 cameraPosition;",
  9615. ""
  9616. ].join("\n");
  9617. _gl.attachShader( program, getShader( "fragment", prefix_fragment + fragmentShader ) );
  9618. _gl.attachShader( program, getShader( "vertex", prefix_vertex + vertexShader ) );
  9619. _gl.linkProgram( program );
  9620. if ( !_gl.getProgramParameter( program, _gl.LINK_STATUS ) ) {
  9621. console.error( "Could not initialise shader\n" + "VALIDATE_STATUS: " + _gl.getProgramParameter( program, _gl.VALIDATE_STATUS ) + ", gl error [" + _gl.getError() + "]" );
  9622. }
  9623. //console.log( prefix_fragment + fragmentShader );
  9624. //console.log( prefix_vertex + vertexShader );
  9625. program.uniforms = {};
  9626. program.attributes = {};
  9627. var identifiers, u, a, i;
  9628. // cache uniform locations
  9629. identifiers = [
  9630. 'viewMatrix', 'modelViewMatrix', 'projectionMatrix', 'normalMatrix', 'objectMatrix', 'cameraPosition',
  9631. 'boneGlobalMatrices', 'morphTargetInfluences'
  9632. ];
  9633. for ( u in uniforms ) {
  9634. identifiers.push( u );
  9635. }
  9636. cacheUniformLocations( program, identifiers );
  9637. // cache attributes locations
  9638. identifiers = [
  9639. "position", "normal", "uv", "uv2", "tangent", "color",
  9640. "skinVertexA", "skinVertexB", "skinIndex", "skinWeight"
  9641. ];
  9642. for ( i = 0; i < parameters.maxMorphTargets; i ++ ) {
  9643. identifiers.push( "morphTarget" + i );
  9644. }
  9645. for ( i = 0; i < parameters.maxMorphNormals; i ++ ) {
  9646. identifiers.push( "morphNormal" + i );
  9647. }
  9648. for ( a in attributes ) {
  9649. identifiers.push( a );
  9650. }
  9651. cacheAttributeLocations( program, identifiers );
  9652. program.id = _programs.length;
  9653. _programs.push( { program: program, code: code } );
  9654. _this.info.memory.programs = _programs.length;
  9655. return program;
  9656. };
  9657. // Shader parameters cache
  9658. function cacheUniformLocations ( program, identifiers ) {
  9659. var i, l, id;
  9660. for( i = 0, l = identifiers.length; i < l; i ++ ) {
  9661. id = identifiers[ i ];
  9662. program.uniforms[ id ] = _gl.getUniformLocation( program, id );
  9663. }
  9664. };
  9665. function cacheAttributeLocations ( program, identifiers ) {
  9666. var i, l, id;
  9667. for( i = 0, l = identifiers.length; i < l; i ++ ) {
  9668. id = identifiers[ i ];
  9669. program.attributes[ id ] = _gl.getAttribLocation( program, id );
  9670. }
  9671. };
  9672. function getShader ( type, string ) {
  9673. var shader;
  9674. if ( type === "fragment" ) {
  9675. shader = _gl.createShader( _gl.FRAGMENT_SHADER );
  9676. } else if ( type === "vertex" ) {
  9677. shader = _gl.createShader( _gl.VERTEX_SHADER );
  9678. }
  9679. _gl.shaderSource( shader, string );
  9680. _gl.compileShader( shader );
  9681. if ( !_gl.getShaderParameter( shader, _gl.COMPILE_STATUS ) ) {
  9682. console.error( _gl.getShaderInfoLog( shader ) );
  9683. console.error( string );
  9684. return null;
  9685. }
  9686. return shader;
  9687. };
  9688. // Textures
  9689. function isPowerOfTwo ( value ) {
  9690. return ( value & ( value - 1 ) ) === 0;
  9691. };
  9692. function setTextureParameters ( textureType, texture, isImagePowerOfTwo ) {
  9693. if ( isImagePowerOfTwo ) {
  9694. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  9695. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  9696. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  9697. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  9698. } else {
  9699. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  9700. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  9701. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  9702. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  9703. }
  9704. };
  9705. this.setTexture = function ( texture, slot ) {
  9706. if ( texture.needsUpdate ) {
  9707. if ( ! texture.__webglInit ) {
  9708. texture.__webglInit = true;
  9709. texture.__webglTexture = _gl.createTexture();
  9710. _this.info.memory.textures ++;
  9711. }
  9712. _gl.activeTexture( _gl.TEXTURE0 + slot );
  9713. _gl.bindTexture( _gl.TEXTURE_2D, texture.__webglTexture );
  9714. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  9715. var image = texture.image,
  9716. isImagePowerOfTwo = isPowerOfTwo( image.width ) && isPowerOfTwo( image.height ),
  9717. glFormat = paramThreeToGL( texture.format ),
  9718. glType = paramThreeToGL( texture.type );
  9719. setTextureParameters( _gl.TEXTURE_2D, texture, isImagePowerOfTwo );
  9720. if ( texture instanceof THREE.DataTexture ) {
  9721. _gl.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  9722. } else {
  9723. _gl.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, texture.image );
  9724. }
  9725. if ( texture.generateMipmaps && isImagePowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  9726. texture.needsUpdate = false;
  9727. if ( texture.onUpdate ) texture.onUpdate();
  9728. } else {
  9729. _gl.activeTexture( _gl.TEXTURE0 + slot );
  9730. _gl.bindTexture( _gl.TEXTURE_2D, texture.__webglTexture );
  9731. }
  9732. };
  9733. function clampToMaxSize ( image, maxSize ) {
  9734. if ( image.width <= maxSize && image.height <= maxSize ) {
  9735. return image;
  9736. }
  9737. // Warning: Scaling through the canvas will only work with images that use
  9738. // premultiplied alpha.
  9739. var maxDimension = Math.max( image.width, image.height );
  9740. var newWidth = Math.floor( image.width * maxSize / maxDimension );
  9741. var newHeight = Math.floor( image.height * maxSize / maxDimension );
  9742. var canvas = document.createElement( 'canvas' );
  9743. canvas.width = newWidth;
  9744. canvas.height = newHeight;
  9745. var ctx = canvas.getContext( "2d" );
  9746. ctx.drawImage( image, 0, 0, image.width, image.height, 0, 0, newWidth, newHeight );
  9747. return canvas;
  9748. }
  9749. function setCubeTexture ( texture, slot ) {
  9750. if ( texture.image.length === 6 ) {
  9751. if ( texture.needsUpdate ) {
  9752. if ( ! texture.image.__webglTextureCube ) {
  9753. texture.image.__webglTextureCube = _gl.createTexture();
  9754. }
  9755. _gl.activeTexture( _gl.TEXTURE0 + slot );
  9756. _gl.bindTexture( _gl.TEXTURE_CUBE_MAP, texture.image.__webglTextureCube );
  9757. var cubeImage = [];
  9758. for ( var i = 0; i < 6; i ++ ) {
  9759. if ( _this.autoScaleCubemaps ) {
  9760. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], _maxCubemapSize );
  9761. } else {
  9762. cubeImage[ i ] = texture.image[ i ];
  9763. }
  9764. }
  9765. var image = cubeImage[ 0 ],
  9766. isImagePowerOfTwo = isPowerOfTwo( image.width ) && isPowerOfTwo( image.height ),
  9767. glFormat = paramThreeToGL( texture.format ),
  9768. glType = paramThreeToGL( texture.type );
  9769. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isImagePowerOfTwo );
  9770. for ( var i = 0; i < 6; i ++ ) {
  9771. _gl.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  9772. }
  9773. if ( texture.generateMipmaps && isImagePowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  9774. texture.needsUpdate = false;
  9775. if ( texture.onUpdate ) texture.onUpdate();
  9776. } else {
  9777. _gl.activeTexture( _gl.TEXTURE0 + slot );
  9778. _gl.bindTexture( _gl.TEXTURE_CUBE_MAP, texture.image.__webglTextureCube );
  9779. }
  9780. }
  9781. };
  9782. function setCubeTextureDynamic ( texture, slot ) {
  9783. _gl.activeTexture( _gl.TEXTURE0 + slot );
  9784. _gl.bindTexture( _gl.TEXTURE_CUBE_MAP, texture.__webglTexture );
  9785. };
  9786. // Render targets
  9787. function setupFrameBuffer ( framebuffer, renderTarget, textureTarget ) {
  9788. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  9789. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureTarget, renderTarget.__webglTexture, 0 );
  9790. };
  9791. function setupRenderBuffer ( renderbuffer, renderTarget ) {
  9792. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  9793. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  9794. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  9795. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  9796. /* For some reason this is not working. Defaulting to RGBA4.
  9797. } else if( ! renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  9798. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.STENCIL_INDEX8, renderTarget.width, renderTarget.height );
  9799. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  9800. */
  9801. } else if( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  9802. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  9803. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  9804. } else {
  9805. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  9806. }
  9807. };
  9808. this.setRenderTarget = function ( renderTarget ) {
  9809. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  9810. if ( renderTarget && ! renderTarget.__webglFramebuffer ) {
  9811. if( renderTarget.depthBuffer === undefined ) renderTarget.depthBuffer = true;
  9812. if( renderTarget.stencilBuffer === undefined ) renderTarget.stencilBuffer = true;
  9813. renderTarget.__webglTexture = _gl.createTexture();
  9814. // Setup texture, create render and frame buffers
  9815. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget.width ) && isPowerOfTwo( renderTarget.height ),
  9816. glFormat = paramThreeToGL( renderTarget.format ),
  9817. glType = paramThreeToGL( renderTarget.type );
  9818. if ( isCube ) {
  9819. renderTarget.__webglFramebuffer = [];
  9820. renderTarget.__webglRenderbuffer = [];
  9821. _gl.bindTexture( _gl.TEXTURE_CUBE_MAP, renderTarget.__webglTexture );
  9822. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget, isTargetPowerOfTwo );
  9823. for ( var i = 0; i < 6; i ++ ) {
  9824. renderTarget.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  9825. renderTarget.__webglRenderbuffer[ i ] = _gl.createRenderbuffer();
  9826. _gl.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  9827. setupFrameBuffer( renderTarget.__webglFramebuffer[ i ], renderTarget, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  9828. setupRenderBuffer( renderTarget.__webglRenderbuffer[ i ], renderTarget );
  9829. }
  9830. if ( isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  9831. } else {
  9832. renderTarget.__webglFramebuffer = _gl.createFramebuffer();
  9833. renderTarget.__webglRenderbuffer = _gl.createRenderbuffer();
  9834. _gl.bindTexture( _gl.TEXTURE_2D, renderTarget.__webglTexture );
  9835. setTextureParameters( _gl.TEXTURE_2D, renderTarget, isTargetPowerOfTwo );
  9836. _gl.texImage2D( _gl.TEXTURE_2D, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  9837. setupFrameBuffer( renderTarget.__webglFramebuffer, renderTarget, _gl.TEXTURE_2D );
  9838. setupRenderBuffer( renderTarget.__webglRenderbuffer, renderTarget );
  9839. if ( isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  9840. }
  9841. // Release everything
  9842. if ( isCube ) {
  9843. _gl.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  9844. } else {
  9845. _gl.bindTexture( _gl.TEXTURE_2D, null );
  9846. }
  9847. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  9848. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null);
  9849. }
  9850. var framebuffer, width, height, vx, vy;
  9851. if ( renderTarget ) {
  9852. if ( isCube ) {
  9853. framebuffer = renderTarget.__webglFramebuffer[ renderTarget.activeCubeFace ];
  9854. } else {
  9855. framebuffer = renderTarget.__webglFramebuffer;
  9856. }
  9857. width = renderTarget.width;
  9858. height = renderTarget.height;
  9859. vx = 0;
  9860. vy = 0;
  9861. } else {
  9862. framebuffer = null;
  9863. width = _viewportWidth;
  9864. height = _viewportHeight;
  9865. vx = _viewportX;
  9866. vy = _viewportY;
  9867. }
  9868. if ( framebuffer !== _currentFramebuffer ) {
  9869. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  9870. _gl.viewport( vx, vy, width, height );
  9871. _currentFramebuffer = framebuffer;
  9872. }
  9873. _currentWidth = width;
  9874. _currentHeight = height;
  9875. };
  9876. function updateRenderTargetMipmap ( renderTarget ) {
  9877. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  9878. _gl.bindTexture( _gl.TEXTURE_CUBE_MAP, renderTarget.__webglTexture );
  9879. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  9880. _gl.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  9881. } else {
  9882. _gl.bindTexture( _gl.TEXTURE_2D, renderTarget.__webglTexture );
  9883. _gl.generateMipmap( _gl.TEXTURE_2D );
  9884. _gl.bindTexture( _gl.TEXTURE_2D, null );
  9885. }
  9886. };
  9887. // Fallback filters for non-power-of-2 textures
  9888. function filterFallback ( f ) {
  9889. switch ( f ) {
  9890. case THREE.NearestFilter:
  9891. case THREE.NearestMipMapNearestFilter:
  9892. case THREE.NearestMipMapLinearFilter: return _gl.NEAREST; break;
  9893. case THREE.LinearFilter:
  9894. case THREE.LinearMipMapNearestFilter:
  9895. case THREE.LinearMipMapLinearFilter:
  9896. default:
  9897. return _gl.LINEAR; break;
  9898. }
  9899. };
  9900. // Map three.js constants to WebGL constants
  9901. function paramThreeToGL ( p ) {
  9902. switch ( p ) {
  9903. case THREE.RepeatWrapping: return _gl.REPEAT; break;
  9904. case THREE.ClampToEdgeWrapping: return _gl.CLAMP_TO_EDGE; break;
  9905. case THREE.MirroredRepeatWrapping: return _gl.MIRRORED_REPEAT; break;
  9906. case THREE.NearestFilter: return _gl.NEAREST; break;
  9907. case THREE.NearestMipMapNearestFilter: return _gl.NEAREST_MIPMAP_NEAREST; break;
  9908. case THREE.NearestMipMapLinearFilter: return _gl.NEAREST_MIPMAP_LINEAR; break;
  9909. case THREE.LinearFilter: return _gl.LINEAR; break;
  9910. case THREE.LinearMipMapNearestFilter: return _gl.LINEAR_MIPMAP_NEAREST; break;
  9911. case THREE.LinearMipMapLinearFilter: return _gl.LINEAR_MIPMAP_LINEAR; break;
  9912. case THREE.ByteType: return _gl.BYTE; break;
  9913. case THREE.UnsignedByteType: return _gl.UNSIGNED_BYTE; break;
  9914. case THREE.ShortType: return _gl.SHORT; break;
  9915. case THREE.UnsignedShortType: return _gl.UNSIGNED_SHORT; break;
  9916. case THREE.IntType: return _gl.INT; break;
  9917. case THREE.UnsignedIntType: return _gl.UNSIGNED_INT; break;
  9918. case THREE.FloatType: return _gl.FLOAT; break;
  9919. case THREE.AlphaFormat: return _gl.ALPHA; break;
  9920. case THREE.RGBFormat: return _gl.RGB; break;
  9921. case THREE.RGBAFormat: return _gl.RGBA; break;
  9922. case THREE.LuminanceFormat: return _gl.LUMINANCE; break;
  9923. case THREE.LuminanceAlphaFormat: return _gl.LUMINANCE_ALPHA; break;
  9924. case THREE.AddEquation: return _gl.FUNC_ADD; break;
  9925. case THREE.SubtractEquation: return _gl.FUNC_SUBTRACT; break;
  9926. case THREE.ReverseSubtractEquation: return _gl.FUNC_REVERSE_SUBTRACT; break;
  9927. case THREE.ZeroFactor: return _gl.ZERO; break;
  9928. case THREE.OneFactor: return _gl.ONE; break;
  9929. case THREE.SrcColorFactor: return _gl.SRC_COLOR; break;
  9930. case THREE.OneMinusSrcColorFactor: return _gl.ONE_MINUS_SRC_COLOR; break;
  9931. case THREE.SrcAlphaFactor: return _gl.SRC_ALPHA; break;
  9932. case THREE.OneMinusSrcAlphaFactor: return _gl.ONE_MINUS_SRC_ALPHA; break;
  9933. case THREE.DstAlphaFactor: return _gl.DST_ALPHA; break;
  9934. case THREE.OneMinusDstAlphaFactor: return _gl.ONE_MINUS_DST_ALPHA; break;
  9935. case THREE.DstColorFactor: return _gl.DST_COLOR; break;
  9936. case THREE.OneMinusDstColorFactor: return _gl.ONE_MINUS_DST_COLOR; break;
  9937. case THREE.SrcAlphaSaturateFactor: return _gl.SRC_ALPHA_SATURATE; break;
  9938. }
  9939. return 0;
  9940. };
  9941. // Allocations
  9942. function allocateBones ( object ) {
  9943. // default for when object is not specified
  9944. // ( for example when prebuilding shader
  9945. // to be used with multiple objects )
  9946. //
  9947. // - leave some extra space for other uniforms
  9948. // - limit here is ANGLE's 254 max uniform vectors
  9949. // (up to 54 should be safe)
  9950. var maxBones = 50;
  9951. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  9952. maxBones = object.bones.length;
  9953. }
  9954. return maxBones;
  9955. };
  9956. function allocateLights ( lights ) {
  9957. var l, ll, light, dirLights, pointLights, spotLights, maxDirLights, maxPointLights, maxSpotLights;
  9958. dirLights = pointLights = spotLights = maxDirLights = maxPointLights = maxSpotLights = 0;
  9959. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  9960. light = lights[ l ];
  9961. if ( light.onlyShadow ) continue;
  9962. if ( light instanceof THREE.DirectionalLight ) dirLights ++;
  9963. if ( light instanceof THREE.PointLight ) pointLights ++;
  9964. if ( light instanceof THREE.SpotLight ) spotLights ++;
  9965. }
  9966. if ( ( pointLights + spotLights + dirLights ) <= _maxLights ) {
  9967. maxDirLights = dirLights;
  9968. maxPointLights = pointLights;
  9969. maxSpotLights = spotLights;
  9970. } else {
  9971. maxDirLights = Math.ceil( _maxLights * dirLights / ( pointLights + dirLights ) );
  9972. maxPointLights = _maxLights - maxDirLights;
  9973. maxSpotLights = maxPointLights; // this is not really correct
  9974. }
  9975. return { 'directional' : maxDirLights, 'point' : maxPointLights, 'spot': maxSpotLights };
  9976. };
  9977. function allocateShadows ( lights ) {
  9978. var l, ll, light, maxShadows = 0;
  9979. for ( l = 0, ll = lights.length; l < ll; l++ ) {
  9980. light = lights[ l ];
  9981. if ( ! light.castShadow ) continue;
  9982. if ( light instanceof THREE.SpotLight ) maxShadows ++;
  9983. if ( light instanceof THREE.DirectionalLight && ! light.shadowCascade ) maxShadows ++;
  9984. }
  9985. return maxShadows;
  9986. };
  9987. // Initialization
  9988. function initGL () {
  9989. var gl;
  9990. try {
  9991. if ( ! ( gl = _canvas.getContext( 'experimental-webgl', { alpha: _alpha, premultipliedAlpha: _premultipliedAlpha, antialias: _antialias, stencil: _stencil, preserveDrawingBuffer: _preserveDrawingBuffer } ) ) ) {
  9992. throw 'Error creating WebGL context.';
  9993. }
  9994. } catch ( error ) {
  9995. console.error( error );
  9996. }
  9997. return gl;
  9998. };
  9999. function setDefaultGLState () {
  10000. _gl.clearColor( 0, 0, 0, 1 );
  10001. _gl.clearDepth( 1 );
  10002. _gl.clearStencil( 0 );
  10003. _gl.enable( _gl.DEPTH_TEST );
  10004. _gl.depthFunc( _gl.LEQUAL );
  10005. _gl.frontFace( _gl.CCW );
  10006. _gl.cullFace( _gl.BACK );
  10007. _gl.enable( _gl.CULL_FACE );
  10008. _gl.enable( _gl.BLEND );
  10009. _gl.blendEquation( _gl.FUNC_ADD );
  10010. _gl.blendFunc( _gl.SRC_ALPHA, _gl.ONE_MINUS_SRC_ALPHA );
  10011. _gl.clearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  10012. };
  10013. // default plugins (order is important)
  10014. this.shadowMapPlugin = new THREE.ShadowMapPlugin();
  10015. this.addPrePlugin( this.shadowMapPlugin );
  10016. this.addPostPlugin( new THREE.SpritePlugin() );
  10017. this.addPostPlugin( new THREE.LensFlarePlugin() );
  10018. };
  10019. /**
  10020. * @author szimek / https://github.com/szimek/
  10021. */
  10022. THREE.WebGLRenderTarget = function ( width, height, options ) {
  10023. this.width = width;
  10024. this.height = height;
  10025. options = options || {};
  10026. this.wrapS = options.wrapS !== undefined ? options.wrapS : THREE.ClampToEdgeWrapping;
  10027. this.wrapT = options.wrapT !== undefined ? options.wrapT : THREE.ClampToEdgeWrapping;
  10028. this.magFilter = options.magFilter !== undefined ? options.magFilter : THREE.LinearFilter;
  10029. this.minFilter = options.minFilter !== undefined ? options.minFilter : THREE.LinearMipMapLinearFilter;
  10030. this.offset = new THREE.Vector2( 0, 0 );
  10031. this.repeat = new THREE.Vector2( 1, 1 );
  10032. this.format = options.format !== undefined ? options.format : THREE.RGBAFormat;
  10033. this.type = options.type !== undefined ? options.type : THREE.UnsignedByteType;
  10034. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  10035. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  10036. this.generateMipmaps = true;
  10037. };
  10038. THREE.WebGLRenderTarget.prototype.clone = function() {
  10039. var tmp = new THREE.WebGLRenderTarget( this.width, this.height );
  10040. tmp.wrapS = this.wrapS;
  10041. tmp.wrapT = this.wrapT;
  10042. tmp.magFilter = this.magFilter;
  10043. tmp.minFilter = this.minFilter;
  10044. tmp.offset.copy( this.offset );
  10045. tmp.repeat.copy( this.repeat );
  10046. tmp.format = this.format;
  10047. tmp.type = this.type;
  10048. tmp.depthBuffer = this.depthBuffer;
  10049. tmp.stencilBuffer = this.stencilBuffer;
  10050. return tmp;
  10051. };
  10052. /**
  10053. * @author alteredq / http://alteredqualia.com
  10054. */
  10055. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  10056. THREE.WebGLRenderTarget.call( this, width, height, options );
  10057. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  10058. };
  10059. THREE.WebGLRenderTargetCube.prototype = new THREE.WebGLRenderTarget();
  10060. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  10061. /**
  10062. * @author mr.doob / http://mrdoob.com/
  10063. */
  10064. THREE.RenderableVertex = function () {
  10065. this.positionWorld = new THREE.Vector3();
  10066. this.positionScreen = new THREE.Vector4();
  10067. this.visible = true;
  10068. };
  10069. THREE.RenderableVertex.prototype.copy = function ( vertex ) {
  10070. this.positionWorld.copy( vertex.positionWorld );
  10071. this.positionScreen.copy( vertex.positionScreen );
  10072. }
  10073. /**
  10074. * @author mr.doob / http://mrdoob.com/
  10075. */
  10076. THREE.RenderableFace3 = function () {
  10077. this.v1 = new THREE.RenderableVertex();
  10078. this.v2 = new THREE.RenderableVertex();
  10079. this.v3 = new THREE.RenderableVertex();
  10080. this.centroidWorld = new THREE.Vector3();
  10081. this.centroidScreen = new THREE.Vector3();
  10082. this.normalWorld = new THREE.Vector3();
  10083. this.vertexNormalsWorld = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ];
  10084. this.material = null;
  10085. this.faceMaterial = null;
  10086. this.uvs = [[]];
  10087. this.z = null;
  10088. };
  10089. /**
  10090. * @author mr.doob / http://mrdoob.com/
  10091. */
  10092. THREE.RenderableFace4 = function () {
  10093. this.v1 = new THREE.RenderableVertex();
  10094. this.v2 = new THREE.RenderableVertex();
  10095. this.v3 = new THREE.RenderableVertex();
  10096. this.v4 = new THREE.RenderableVertex();
  10097. this.centroidWorld = new THREE.Vector3();
  10098. this.centroidScreen = new THREE.Vector3();
  10099. this.normalWorld = new THREE.Vector3();
  10100. this.vertexNormalsWorld = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ];
  10101. this.material = null;
  10102. this.faceMaterial = null;
  10103. this.uvs = [[]];
  10104. this.z = null;
  10105. };
  10106. /**
  10107. * @author mr.doob / http://mrdoob.com/
  10108. */
  10109. THREE.RenderableObject = function () {
  10110. this.object = null;
  10111. this.z = null;
  10112. };
  10113. /**
  10114. * @author mr.doob / http://mrdoob.com/
  10115. */
  10116. THREE.RenderableParticle = function () {
  10117. this.x = null;
  10118. this.y = null;
  10119. this.z = null;
  10120. this.rotation = null;
  10121. this.scale = new THREE.Vector2();
  10122. this.material = null;
  10123. };
  10124. /**
  10125. * @author mr.doob / http://mrdoob.com/
  10126. */
  10127. THREE.RenderableLine = function () {
  10128. this.z = null;
  10129. this.v1 = new THREE.RenderableVertex();
  10130. this.v2 = new THREE.RenderableVertex();
  10131. this.material = null;
  10132. };
  10133. /**
  10134. * @author alteredq / http://alteredqualia.com/
  10135. */
  10136. THREE.ColorUtils = {
  10137. adjustHSV : function ( color, h, s, v ) {
  10138. var hsv = THREE.ColorUtils.__hsv;
  10139. THREE.ColorUtils.rgbToHsv( color, hsv );
  10140. hsv.h = THREE.Math.clamp( hsv.h + h, 0, 1 );
  10141. hsv.s = THREE.Math.clamp( hsv.s + s, 0, 1 );
  10142. hsv.v = THREE.Math.clamp( hsv.v + v, 0, 1 );
  10143. color.setHSV( hsv.h, hsv.s, hsv.v );
  10144. },
  10145. // based on MochiKit implementation by Bob Ippolito
  10146. rgbToHsv : function ( color, hsv ) {
  10147. var r = color.r;
  10148. var g = color.g;
  10149. var b = color.b;
  10150. var max = Math.max( Math.max( r, g ), b );
  10151. var min = Math.min( Math.min( r, g ), b );
  10152. var hue;
  10153. var saturation;
  10154. var value = max;
  10155. if ( min === max ) {
  10156. hue = 0;
  10157. saturation = 0;
  10158. } else {
  10159. var delta = ( max - min );
  10160. saturation = delta / max;
  10161. if ( r === max ) {
  10162. hue = ( g - b ) / delta;
  10163. } else if ( g === max ) {
  10164. hue = 2 + ( ( b - r ) / delta );
  10165. } else {
  10166. hue = 4 + ( ( r - g ) / delta );
  10167. }
  10168. hue /= 6;
  10169. if ( hue < 0 ) {
  10170. hue += 1;
  10171. }
  10172. if ( hue > 1 ) {
  10173. hue -= 1;
  10174. }
  10175. }
  10176. if ( hsv === undefined ) {
  10177. hsv = { h: 0, s: 0, v: 0 };
  10178. }
  10179. hsv.h = hue;
  10180. hsv.s = saturation;
  10181. hsv.v = value;
  10182. return hsv;
  10183. }
  10184. };
  10185. THREE.ColorUtils.__hsv = { h: 0, s: 0, v: 0 };/**
  10186. * @author mrdoob / http://mrdoob.com/
  10187. * @author alteredq / http://alteredqualia.com/
  10188. */
  10189. THREE.GeometryUtils = {
  10190. // Merge two geometries or geometry and geometry from object (using object's transform)
  10191. merge: function ( geometry1, object2 /* mesh | geometry */ ) {
  10192. var matrix, matrixRotation,
  10193. vertexOffset = geometry1.vertices.length,
  10194. uvPosition = geometry1.faceVertexUvs[ 0 ].length,
  10195. geometry2 = object2 instanceof THREE.Mesh ? object2.geometry : object2,
  10196. vertices1 = geometry1.vertices,
  10197. vertices2 = geometry2.vertices,
  10198. faces1 = geometry1.faces,
  10199. faces2 = geometry2.faces,
  10200. uvs1 = geometry1.faceVertexUvs[ 0 ],
  10201. uvs2 = geometry2.faceVertexUvs[ 0 ];
  10202. var geo1MaterialsMap = {};
  10203. for ( var i = 0; i < geometry1.materials.length; i ++ ) {
  10204. var id = geometry1.materials[ i ].id;
  10205. geo1MaterialsMap[ id ] = i;
  10206. }
  10207. if ( object2 instanceof THREE.Mesh ) {
  10208. object2.matrixAutoUpdate && object2.updateMatrix();
  10209. matrix = object2.matrix;
  10210. matrixRotation = new THREE.Matrix4();
  10211. matrixRotation.extractRotation( matrix, object2.scale );
  10212. }
  10213. // vertices
  10214. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  10215. var vertex = vertices2[ i ];
  10216. var vertexCopy = vertex.clone();
  10217. if ( matrix ) matrix.multiplyVector3( vertexCopy );
  10218. vertices1.push( vertexCopy );
  10219. }
  10220. // faces
  10221. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  10222. var face = faces2[ i ], faceCopy, normal, color,
  10223. faceVertexNormals = face.vertexNormals,
  10224. faceVertexColors = face.vertexColors;
  10225. if ( face instanceof THREE.Face3 ) {
  10226. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  10227. } else if ( face instanceof THREE.Face4 ) {
  10228. faceCopy = new THREE.Face4( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset, face.d + vertexOffset );
  10229. }
  10230. faceCopy.normal.copy( face.normal );
  10231. if ( matrixRotation ) matrixRotation.multiplyVector3( faceCopy.normal );
  10232. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  10233. normal = faceVertexNormals[ j ].clone();
  10234. if ( matrixRotation ) matrixRotation.multiplyVector3( normal );
  10235. faceCopy.vertexNormals.push( normal );
  10236. }
  10237. faceCopy.color.copy( face.color );
  10238. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  10239. color = faceVertexColors[ j ];
  10240. faceCopy.vertexColors.push( color.clone() );
  10241. }
  10242. if ( face.materialIndex !== undefined ) {
  10243. var material2 = geometry2.materials[ face.materialIndex ];
  10244. var materialId2 = material2.id;
  10245. var materialIndex = geo1MaterialsMap[ materialId2 ];
  10246. if ( materialIndex === undefined ) {
  10247. materialIndex = geometry1.materials.length;
  10248. geo1MaterialsMap[ materialId2 ] = materialIndex;
  10249. geometry1.materials.push( material2 );
  10250. }
  10251. faceCopy.materialIndex = materialIndex;
  10252. }
  10253. faceCopy.centroid.copy( face.centroid );
  10254. if ( matrix ) matrix.multiplyVector3( faceCopy.centroid );
  10255. faces1.push( faceCopy );
  10256. }
  10257. // uvs
  10258. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  10259. var uv = uvs2[ i ], uvCopy = [];
  10260. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  10261. uvCopy.push( new THREE.UV( uv[ j ].u, uv[ j ].v ) );
  10262. }
  10263. uvs1.push( uvCopy );
  10264. }
  10265. },
  10266. clone: function ( geometry ) {
  10267. var cloneGeo = new THREE.Geometry();
  10268. var i, il;
  10269. var vertices = geometry.vertices,
  10270. faces = geometry.faces,
  10271. uvs = geometry.faceVertexUvs[ 0 ];
  10272. // materials
  10273. if ( geometry.materials ) {
  10274. cloneGeo.materials = geometry.materials.slice();
  10275. }
  10276. // vertices
  10277. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  10278. var vertex = vertices[ i ];
  10279. cloneGeo.vertices.push( vertex.clone() );
  10280. }
  10281. // faces
  10282. for ( i = 0, il = faces.length; i < il; i ++ ) {
  10283. var face = faces[ i ];
  10284. cloneGeo.faces.push( face.clone() );
  10285. }
  10286. // uvs
  10287. for ( i = 0, il = uvs.length; i < il; i ++ ) {
  10288. var uv = uvs[ i ], uvCopy = [];
  10289. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  10290. uvCopy.push( new THREE.UV( uv[ j ].u, uv[ j ].v ) );
  10291. }
  10292. cloneGeo.faceVertexUvs[ 0 ].push( uvCopy );
  10293. }
  10294. return cloneGeo;
  10295. },
  10296. // Get random point in triangle (via barycentric coordinates)
  10297. // (uniform distribution)
  10298. // http://www.cgafaq.info/wiki/Random_Point_In_Triangle
  10299. randomPointInTriangle: function ( vectorA, vectorB, vectorC ) {
  10300. var a, b, c,
  10301. point = new THREE.Vector3(),
  10302. tmp = THREE.GeometryUtils.__v1;
  10303. a = THREE.GeometryUtils.random();
  10304. b = THREE.GeometryUtils.random();
  10305. if ( ( a + b ) > 1 ) {
  10306. a = 1 - a;
  10307. b = 1 - b;
  10308. }
  10309. c = 1 - a - b;
  10310. point.copy( vectorA );
  10311. point.multiplyScalar( a );
  10312. tmp.copy( vectorB );
  10313. tmp.multiplyScalar( b );
  10314. point.addSelf( tmp );
  10315. tmp.copy( vectorC );
  10316. tmp.multiplyScalar( c );
  10317. point.addSelf( tmp );
  10318. return point;
  10319. },
  10320. // Get random point in face (triangle / quad)
  10321. // (uniform distribution)
  10322. randomPointInFace: function ( face, geometry, useCachedAreas ) {
  10323. var vA, vB, vC, vD;
  10324. if ( face instanceof THREE.Face3 ) {
  10325. vA = geometry.vertices[ face.a ];
  10326. vB = geometry.vertices[ face.b ];
  10327. vC = geometry.vertices[ face.c ];
  10328. return THREE.GeometryUtils.randomPointInTriangle( vA, vB, vC );
  10329. } else if ( face instanceof THREE.Face4 ) {
  10330. vA = geometry.vertices[ face.a ];
  10331. vB = geometry.vertices[ face.b ];
  10332. vC = geometry.vertices[ face.c ];
  10333. vD = geometry.vertices[ face.d ];
  10334. var area1, area2;
  10335. if ( useCachedAreas ) {
  10336. if ( face._area1 && face._area2 ) {
  10337. area1 = face._area1;
  10338. area2 = face._area2;
  10339. } else {
  10340. area1 = THREE.GeometryUtils.triangleArea( vA, vB, vD );
  10341. area2 = THREE.GeometryUtils.triangleArea( vB, vC, vD );
  10342. face._area1 = area1;
  10343. face._area2 = area2;
  10344. }
  10345. } else {
  10346. area1 = THREE.GeometryUtils.triangleArea( vA, vB, vD ),
  10347. area2 = THREE.GeometryUtils.triangleArea( vB, vC, vD );
  10348. }
  10349. var r = THREE.GeometryUtils.random() * ( area1 + area2 );
  10350. if ( r < area1 ) {
  10351. return THREE.GeometryUtils.randomPointInTriangle( vA, vB, vD );
  10352. } else {
  10353. return THREE.GeometryUtils.randomPointInTriangle( vB, vC, vD );
  10354. }
  10355. }
  10356. },
  10357. // Get uniformly distributed random points in mesh
  10358. // - create array with cumulative sums of face areas
  10359. // - pick random number from 0 to total area
  10360. // - find corresponding place in area array by binary search
  10361. // - get random point in face
  10362. randomPointsInGeometry: function ( geometry, n ) {
  10363. var face, i,
  10364. faces = geometry.faces,
  10365. vertices = geometry.vertices,
  10366. il = faces.length,
  10367. totalArea = 0,
  10368. cumulativeAreas = [],
  10369. vA, vB, vC, vD;
  10370. // precompute face areas
  10371. for ( i = 0; i < il; i ++ ) {
  10372. face = faces[ i ];
  10373. if ( face instanceof THREE.Face3 ) {
  10374. vA = vertices[ face.a ];
  10375. vB = vertices[ face.b ];
  10376. vC = vertices[ face.c ];
  10377. face._area = THREE.GeometryUtils.triangleArea( vA, vB, vC );
  10378. } else if ( face instanceof THREE.Face4 ) {
  10379. vA = vertices[ face.a ];
  10380. vB = vertices[ face.b ];
  10381. vC = vertices[ face.c ];
  10382. vD = vertices[ face.d ];
  10383. face._area1 = THREE.GeometryUtils.triangleArea( vA, vB, vD );
  10384. face._area2 = THREE.GeometryUtils.triangleArea( vB, vC, vD );
  10385. face._area = face._area1 + face._area2;
  10386. }
  10387. totalArea += face._area;
  10388. cumulativeAreas[ i ] = totalArea;
  10389. }
  10390. // binary search cumulative areas array
  10391. function binarySearchIndices( value ) {
  10392. function binarySearch( start, end ) {
  10393. // return closest larger index
  10394. // if exact number is not found
  10395. if ( end < start )
  10396. return start;
  10397. var mid = start + Math.floor( ( end - start ) / 2 );
  10398. if ( cumulativeAreas[ mid ] > value ) {
  10399. return binarySearch( start, mid - 1 );
  10400. } else if ( cumulativeAreas[ mid ] < value ) {
  10401. return binarySearch( mid + 1, end );
  10402. } else {
  10403. return mid;
  10404. }
  10405. }
  10406. var result = binarySearch( 0, cumulativeAreas.length - 1 )
  10407. return result;
  10408. }
  10409. // pick random face weighted by face area
  10410. var r, index,
  10411. result = [];
  10412. var stats = {};
  10413. for ( i = 0; i < n; i ++ ) {
  10414. r = THREE.GeometryUtils.random() * totalArea;
  10415. index = binarySearchIndices( r );
  10416. result[ i ] = THREE.GeometryUtils.randomPointInFace( faces[ index ], geometry, true );
  10417. if ( ! stats[ index ] ) {
  10418. stats[ index ] = 1;
  10419. } else {
  10420. stats[ index ] += 1;
  10421. }
  10422. }
  10423. return result;
  10424. },
  10425. // Get triangle area (by Heron's formula)
  10426. // http://en.wikipedia.org/wiki/Heron%27s_formula
  10427. triangleArea: function ( vectorA, vectorB, vectorC ) {
  10428. var s, a, b, c,
  10429. tmp = THREE.GeometryUtils.__v1;
  10430. tmp.sub( vectorA, vectorB );
  10431. a = tmp.length();
  10432. tmp.sub( vectorA, vectorC );
  10433. b = tmp.length();
  10434. tmp.sub( vectorB, vectorC );
  10435. c = tmp.length();
  10436. s = 0.5 * ( a + b + c );
  10437. return Math.sqrt( s * ( s - a ) * ( s - b ) * ( s - c ) );
  10438. },
  10439. // Center geometry so that 0,0,0 is in center of bounding box
  10440. center: function ( geometry ) {
  10441. geometry.computeBoundingBox();
  10442. var bb = geometry.boundingBox;
  10443. var offset = new THREE.Vector3();
  10444. offset.add( bb.min, bb.max );
  10445. offset.multiplyScalar( -0.5 );
  10446. geometry.applyMatrix( new THREE.Matrix4().makeTranslation( offset.x, offset.y, offset.z ) );
  10447. geometry.computeBoundingBox();
  10448. return offset;
  10449. },
  10450. // Normalize UVs to be from <0,1>
  10451. // (for now just the first set of UVs)
  10452. normalizeUVs: function ( geometry ) {
  10453. var uvSet = geometry.faceVertexUvs[ 0 ];
  10454. for ( var i = 0, il = uvSet.length; i < il; i ++ ) {
  10455. var uvs = uvSet[ i ];
  10456. for ( var j = 0, jl = uvs.length; j < jl; j ++ ) {
  10457. // texture repeat
  10458. if( uvs[ j ].u !== 1.0 ) uvs[ j ].u = uvs[ j ].u - Math.floor( uvs[ j ].u );
  10459. if( uvs[ j ].v !== 1.0 ) uvs[ j ].v = uvs[ j ].v - Math.floor( uvs[ j ].v );
  10460. }
  10461. }
  10462. },
  10463. triangulateQuads: function ( geometry ) {
  10464. var i, il, j, jl;
  10465. var faces = [];
  10466. var faceUvs = [];
  10467. var faceVertexUvs = [];
  10468. for ( i = 0, il = geometry.faceUvs.length; i < il; i ++ ) {
  10469. faceUvs[ i ] = [];
  10470. }
  10471. for ( i = 0, il = geometry.faceVertexUvs.length; i < il; i ++ ) {
  10472. faceVertexUvs[ i ] = [];
  10473. }
  10474. for ( i = 0, il = geometry.faces.length; i < il; i ++ ) {
  10475. var face = geometry.faces[ i ];
  10476. if ( face instanceof THREE.Face4 ) {
  10477. var a = face.a;
  10478. var b = face.b;
  10479. var c = face.c;
  10480. var d = face.d;
  10481. var triA = new THREE.Face3();
  10482. var triB = new THREE.Face3();
  10483. triA.color.copy( face.color );
  10484. triB.color.copy( face.color );
  10485. triA.materialIndex = face.materialIndex;
  10486. triB.materialIndex = face.materialIndex;
  10487. triA.a = a;
  10488. triA.b = b;
  10489. triA.c = d;
  10490. triB.a = b;
  10491. triB.b = c;
  10492. triB.c = d;
  10493. if ( face.vertexColors.length === 4 ) {
  10494. triA.vertexColors[ 0 ] = face.vertexColors[ 0 ].clone();
  10495. triA.vertexColors[ 1 ] = face.vertexColors[ 1 ].clone();
  10496. triA.vertexColors[ 2 ] = face.vertexColors[ 3 ].clone();
  10497. triB.vertexColors[ 0 ] = face.vertexColors[ 1 ].clone();
  10498. triB.vertexColors[ 1 ] = face.vertexColors[ 2 ].clone();
  10499. triB.vertexColors[ 2 ] = face.vertexColors[ 3 ].clone();
  10500. }
  10501. faces.push( triA, triB );
  10502. for ( j = 0, jl = geometry.faceVertexUvs.length; j < jl; j ++ ) {
  10503. if ( geometry.faceVertexUvs[ j ].length ) {
  10504. var uvs = geometry.faceVertexUvs[ j ][ i ];
  10505. var uvA = uvs[ 0 ];
  10506. var uvB = uvs[ 1 ];
  10507. var uvC = uvs[ 2 ];
  10508. var uvD = uvs[ 3 ];
  10509. var uvsTriA = [ uvA.clone(), uvB.clone(), uvD.clone() ];
  10510. var uvsTriB = [ uvB.clone(), uvC.clone(), uvD.clone() ];
  10511. faceVertexUvs[ j ].push( uvsTriA, uvsTriB );
  10512. }
  10513. }
  10514. for ( j = 0, jl = geometry.faceUvs.length; j < jl; j ++ ) {
  10515. if ( geometry.faceUvs[ j ].length ) {
  10516. var faceUv = geometry.faceUvs[ j ][ i ];
  10517. faceUvs[ j ].push( faceUv, faceUv );
  10518. }
  10519. }
  10520. } else {
  10521. faces.push( face );
  10522. for ( j = 0, jl = geometry.faceUvs.length; j < jl; j ++ ) {
  10523. faceUvs[ j ].push( geometry.faceUvs[ j ] );
  10524. }
  10525. for ( j = 0, jl = geometry.faceVertexUvs.length; j < jl; j ++ ) {
  10526. faceVertexUvs[ j ].push( geometry.faceVertexUvs[ j ] );
  10527. }
  10528. }
  10529. }
  10530. geometry.faces = faces;
  10531. geometry.faceUvs = faceUvs;
  10532. geometry.faceVertexUvs = faceVertexUvs;
  10533. geometry.computeCentroids();
  10534. geometry.computeFaceNormals();
  10535. geometry.computeVertexNormals();
  10536. if ( geometry.hasTangents ) geometry.computeTangents();
  10537. },
  10538. // Make all faces use unique vertices
  10539. // so that each face can be separated from others
  10540. explode: function( geometry ) {
  10541. var vertices = [];
  10542. for ( var i = 0, il = geometry.faces.length; i < il; i ++ ) {
  10543. var n = vertices.length;
  10544. var face = geometry.faces[ i ];
  10545. if ( face instanceof THREE.Face4 ) {
  10546. var a = face.a;
  10547. var b = face.b;
  10548. var c = face.c;
  10549. var d = face.d;
  10550. var va = geometry.vertices[ a ];
  10551. var vb = geometry.vertices[ b ];
  10552. var vc = geometry.vertices[ c ];
  10553. var vd = geometry.vertices[ d ];
  10554. vertices.push( va.clone() );
  10555. vertices.push( vb.clone() );
  10556. vertices.push( vc.clone() );
  10557. vertices.push( vd.clone() );
  10558. face.a = n;
  10559. face.b = n + 1;
  10560. face.c = n + 2;
  10561. face.d = n + 3;
  10562. } else {
  10563. var a = face.a;
  10564. var b = face.b;
  10565. var c = face.c;
  10566. var va = geometry.vertices[ a ];
  10567. var vb = geometry.vertices[ b ];
  10568. var vc = geometry.vertices[ c ];
  10569. vertices.push( va.clone() );
  10570. vertices.push( vb.clone() );
  10571. vertices.push( vc.clone() );
  10572. face.a = n;
  10573. face.b = n + 1;
  10574. face.c = n + 2;
  10575. }
  10576. }
  10577. geometry.vertices = vertices;
  10578. delete geometry.__tmpVertices;
  10579. },
  10580. // Break faces with edges longer than maxEdgeLength
  10581. // - not recursive
  10582. tessellate: function ( geometry, maxEdgeLength ) {
  10583. var i, il, face,
  10584. a, b, c, d,
  10585. va, vb, vc, vd,
  10586. dab, dbc, dac, dcd, dad,
  10587. m, m1, m2,
  10588. vm, vm1, vm2,
  10589. vnm, vnm1, vnm2,
  10590. vcm, vcm1, vcm2,
  10591. triA, triB,
  10592. quadA, quadB,
  10593. edge;
  10594. var faces = [];
  10595. var faceVertexUvs = [];
  10596. for ( i = 0, il = geometry.faceVertexUvs.length; i < il; i ++ ) {
  10597. faceVertexUvs[ i ] = [];
  10598. }
  10599. for ( i = 0, il = geometry.faces.length; i < il; i ++ ) {
  10600. face = geometry.faces[ i ];
  10601. if ( face instanceof THREE.Face3 ) {
  10602. a = face.a;
  10603. b = face.b;
  10604. c = face.c;
  10605. va = geometry.vertices[ a ];
  10606. vb = geometry.vertices[ b ];
  10607. vc = geometry.vertices[ c ];
  10608. dab = va.distanceTo( vb );
  10609. dbc = vb.distanceTo( vc );
  10610. dac = va.distanceTo( vc );
  10611. if ( dab > maxEdgeLength || dbc > maxEdgeLength || dac > maxEdgeLength ) {
  10612. m = geometry.vertices.length;
  10613. triA = face.clone();
  10614. triB = face.clone();
  10615. if ( dab >= dbc && dab >= dac ) {
  10616. vm = va.clone();
  10617. vm.lerpSelf( vb, 0.5 );
  10618. triA.a = a;
  10619. triA.b = m;
  10620. triA.c = c;
  10621. triB.a = m;
  10622. triB.b = b;
  10623. triB.c = c;
  10624. if ( face.vertexNormals.length === 3 ) {
  10625. vnm = face.vertexNormals[ 0 ].clone();
  10626. vnm.lerpSelf( face.vertexNormals[ 1 ], 0.5 );
  10627. triA.vertexNormals[ 1 ].copy( vnm );
  10628. triB.vertexNormals[ 0 ].copy( vnm );
  10629. }
  10630. if ( face.vertexColors.length === 3 ) {
  10631. vcm = face.vertexColors[ 0 ].clone();
  10632. vcm.lerpSelf( face.vertexColors[ 1 ], 0.5 );
  10633. triA.vertexColors[ 1 ].copy( vcm );
  10634. triB.vertexColors[ 0 ].copy( vcm );
  10635. }
  10636. edge = 0;
  10637. } else if ( dbc >= dab && dbc >= dac ) {
  10638. vm = vb.clone();
  10639. vm.lerpSelf( vc, 0.5 );
  10640. triA.a = a;
  10641. triA.b = b;
  10642. triA.c = m;
  10643. triB.a = m;
  10644. triB.b = c;
  10645. triB.c = a;
  10646. if ( face.vertexNormals.length === 3 ) {
  10647. vnm = face.vertexNormals[ 1 ].clone();
  10648. vnm.lerpSelf( face.vertexNormals[ 2 ], 0.5 );
  10649. triA.vertexNormals[ 2 ].copy( vnm );
  10650. triB.vertexNormals[ 0 ].copy( vnm );
  10651. triB.vertexNormals[ 1 ].copy( face.vertexNormals[ 2 ] );
  10652. triB.vertexNormals[ 2 ].copy( face.vertexNormals[ 0 ] );
  10653. }
  10654. if ( face.vertexColors.length === 3 ) {
  10655. vcm = face.vertexColors[ 1 ].clone();
  10656. vcm.lerpSelf( face.vertexColors[ 2 ], 0.5 );
  10657. triA.vertexColors[ 2 ].copy( vcm );
  10658. triB.vertexColors[ 0 ].copy( vcm );
  10659. triB.vertexColors[ 1 ].copy( face.vertexColors[ 2 ] );
  10660. triB.vertexColors[ 2 ].copy( face.vertexColors[ 0 ] );
  10661. }
  10662. edge = 1;
  10663. } else {
  10664. vm = va.clone();
  10665. vm.lerpSelf( vc, 0.5 );
  10666. triA.a = a;
  10667. triA.b = b;
  10668. triA.c = m;
  10669. triB.a = m;
  10670. triB.b = b;
  10671. triB.c = c;
  10672. if ( face.vertexNormals.length === 3 ) {
  10673. vnm = face.vertexNormals[ 0 ].clone();
  10674. vnm.lerpSelf( face.vertexNormals[ 2 ], 0.5 );
  10675. triA.vertexNormals[ 2 ].copy( vnm );
  10676. triB.vertexNormals[ 0 ].copy( vnm );
  10677. }
  10678. if ( face.vertexColors.length === 3 ) {
  10679. vcm = face.vertexColors[ 0 ].clone();
  10680. vcm.lerpSelf( face.vertexColors[ 2 ], 0.5 );
  10681. triA.vertexColors[ 2 ].copy( vcm );
  10682. triB.vertexColors[ 0 ].copy( vcm );
  10683. }
  10684. edge = 2;
  10685. }
  10686. faces.push( triA, triB );
  10687. geometry.vertices.push( vm );
  10688. var j, jl, uvs, uvA, uvB, uvC, uvM, uvsTriA, uvsTriB;
  10689. for ( j = 0, jl = geometry.faceVertexUvs.length; j < jl; j ++ ) {
  10690. if ( geometry.faceVertexUvs[ j ].length ) {
  10691. uvs = geometry.faceVertexUvs[ j ][ i ];
  10692. uvA = uvs[ 0 ];
  10693. uvB = uvs[ 1 ];
  10694. uvC = uvs[ 2 ];
  10695. // AB
  10696. if ( edge === 0 ) {
  10697. uvM = uvA.clone();
  10698. uvM.lerpSelf( uvB, 0.5 );
  10699. uvsTriA = [ uvA.clone(), uvM.clone(), uvC.clone() ];
  10700. uvsTriB = [ uvM.clone(), uvB.clone(), uvC.clone() ];
  10701. // BC
  10702. } else if ( edge === 1 ) {
  10703. uvM = uvB.clone();
  10704. uvM.lerpSelf( uvC, 0.5 );
  10705. uvsTriA = [ uvA.clone(), uvB.clone(), uvM.clone() ];
  10706. uvsTriB = [ uvM.clone(), uvC.clone(), uvA.clone() ];
  10707. // AC
  10708. } else {
  10709. uvM = uvA.clone();
  10710. uvM.lerpSelf( uvC, 0.5 );
  10711. uvsTriA = [ uvA.clone(), uvB.clone(), uvM.clone() ];
  10712. uvsTriB = [ uvM.clone(), uvB.clone(), uvC.clone() ];
  10713. }
  10714. faceVertexUvs[ j ].push( uvsTriA, uvsTriB );
  10715. }
  10716. }
  10717. } else {
  10718. faces.push( face );
  10719. for ( j = 0, jl = geometry.faceVertexUvs.length; j < jl; j ++ ) {
  10720. faceVertexUvs[ j ].push( geometry.faceVertexUvs[ j ][ i ] );
  10721. }
  10722. }
  10723. } else {
  10724. a = face.a;
  10725. b = face.b;
  10726. c = face.c;
  10727. d = face.d;
  10728. va = geometry.vertices[ a ];
  10729. vb = geometry.vertices[ b ];
  10730. vc = geometry.vertices[ c ];
  10731. vd = geometry.vertices[ d ];
  10732. dab = va.distanceTo( vb );
  10733. dbc = vb.distanceTo( vc );
  10734. dcd = vc.distanceTo( vd );
  10735. dad = va.distanceTo( vd );
  10736. if ( dab > maxEdgeLength || dbc > maxEdgeLength || dcd > maxEdgeLength || dad > maxEdgeLength ) {
  10737. m1 = geometry.vertices.length;
  10738. m2 = geometry.vertices.length + 1;
  10739. quadA = face.clone();
  10740. quadB = face.clone();
  10741. if ( ( dab >= dbc && dab >= dcd && dab >= dad ) || ( dcd >= dbc && dcd >= dab && dcd >= dad ) ) {
  10742. vm1 = va.clone();
  10743. vm1.lerpSelf( vb, 0.5 );
  10744. vm2 = vc.clone();
  10745. vm2.lerpSelf( vd, 0.5 );
  10746. quadA.a = a;
  10747. quadA.b = m1;
  10748. quadA.c = m2;
  10749. quadA.d = d;
  10750. quadB.a = m1;
  10751. quadB.b = b;
  10752. quadB.c = c;
  10753. quadB.d = m2;
  10754. if ( face.vertexNormals.length === 4 ) {
  10755. vnm1 = face.vertexNormals[ 0 ].clone();
  10756. vnm1.lerpSelf( face.vertexNormals[ 1 ], 0.5 );
  10757. vnm2 = face.vertexNormals[ 2 ].clone();
  10758. vnm2.lerpSelf( face.vertexNormals[ 3 ], 0.5 );
  10759. quadA.vertexNormals[ 1 ].copy( vnm1 );
  10760. quadA.vertexNormals[ 2 ].copy( vnm2 );
  10761. quadB.vertexNormals[ 0 ].copy( vnm1 );
  10762. quadB.vertexNormals[ 3 ].copy( vnm2 );
  10763. }
  10764. if ( face.vertexColors.length === 4 ) {
  10765. vcm1 = face.vertexColors[ 0 ].clone();
  10766. vcm1.lerpSelf( face.vertexColors[ 1 ], 0.5 );
  10767. vcm2 = face.vertexColors[ 2 ].clone();
  10768. vcm2.lerpSelf( face.vertexColors[ 3 ], 0.5 );
  10769. quadA.vertexColors[ 1 ].copy( vcm1 );
  10770. quadA.vertexColors[ 2 ].copy( vcm2 );
  10771. quadB.vertexColors[ 0 ].copy( vcm1 );
  10772. quadB.vertexColors[ 3 ].copy( vcm2 );
  10773. }
  10774. edge = 0;
  10775. } else {
  10776. vm1 = vb.clone();
  10777. vm1.lerpSelf( vc, 0.5 );
  10778. vm2 = vd.clone();
  10779. vm2.lerpSelf( va, 0.5 );
  10780. quadA.a = a;
  10781. quadA.b = b;
  10782. quadA.c = m1;
  10783. quadA.d = m2;
  10784. quadB.a = m2;
  10785. quadB.b = m1;
  10786. quadB.c = c;
  10787. quadB.d = d;
  10788. if ( face.vertexNormals.length === 4 ) {
  10789. vnm1 = face.vertexNormals[ 1 ].clone();
  10790. vnm1.lerpSelf( face.vertexNormals[ 2 ], 0.5 );
  10791. vnm2 = face.vertexNormals[ 3 ].clone();
  10792. vnm2.lerpSelf( face.vertexNormals[ 0 ], 0.5 );
  10793. quadA.vertexNormals[ 2 ].copy( vnm1 );
  10794. quadA.vertexNormals[ 3 ].copy( vnm2 );
  10795. quadB.vertexNormals[ 0 ].copy( vnm2 );
  10796. quadB.vertexNormals[ 1 ].copy( vnm1 );
  10797. }
  10798. if ( face.vertexColors.length === 4 ) {
  10799. vcm1 = face.vertexColors[ 1 ].clone();
  10800. vcm1.lerpSelf( face.vertexColors[ 2 ], 0.5 );
  10801. vcm2 = face.vertexColors[ 3 ].clone();
  10802. vcm2.lerpSelf( face.vertexColors[ 0 ], 0.5 );
  10803. quadA.vertexColors[ 2 ].copy( vcm1 );
  10804. quadA.vertexColors[ 3 ].copy( vcm2 );
  10805. quadB.vertexColors[ 0 ].copy( vcm2 );
  10806. quadB.vertexColors[ 1 ].copy( vcm1 );
  10807. }
  10808. edge = 1;
  10809. }
  10810. faces.push( quadA, quadB );
  10811. geometry.vertices.push( vm1, vm2 );
  10812. var j, jl, uvs, uvA, uvB, uvC, uvD, uvM1, uvM2, uvsQuadA, uvsQuadB;
  10813. for ( j = 0, jl = geometry.faceVertexUvs.length; j < jl; j ++ ) {
  10814. if ( geometry.faceVertexUvs[ j ].length ) {
  10815. uvs = geometry.faceVertexUvs[ j ][ i ];
  10816. uvA = uvs[ 0 ];
  10817. uvB = uvs[ 1 ];
  10818. uvC = uvs[ 2 ];
  10819. uvD = uvs[ 3 ];
  10820. // AB + CD
  10821. if ( edge === 0 ) {
  10822. uvM1 = uvA.clone();
  10823. uvM1.lerpSelf( uvB, 0.5 );
  10824. uvM2 = uvC.clone();
  10825. uvM2.lerpSelf( uvD, 0.5 );
  10826. uvsQuadA = [ uvA.clone(), uvM1.clone(), uvM2.clone(), uvD.clone() ];
  10827. uvsQuadB = [ uvM1.clone(), uvB.clone(), uvC.clone(), uvM2.clone() ];
  10828. // BC + AD
  10829. } else {
  10830. uvM1 = uvB.clone();
  10831. uvM1.lerpSelf( uvC, 0.5 );
  10832. uvM2 = uvD.clone();
  10833. uvM2.lerpSelf( uvA, 0.5 );
  10834. uvsQuadA = [ uvA.clone(), uvB.clone(), uvM1.clone(), uvM2.clone() ];
  10835. uvsQuadB = [ uvM2.clone(), uvM1.clone(), uvC.clone(), uvD.clone() ];
  10836. }
  10837. faceVertexUvs[ j ].push( uvsQuadA, uvsQuadB );
  10838. }
  10839. }
  10840. } else {
  10841. faces.push( face );
  10842. for ( j = 0, jl = geometry.faceVertexUvs.length; j < jl; j ++ ) {
  10843. faceVertexUvs[ j ].push( geometry.faceVertexUvs[ j ][ i ] );
  10844. }
  10845. }
  10846. }
  10847. }
  10848. geometry.faces = faces;
  10849. geometry.faceVertexUvs = faceVertexUvs;
  10850. }
  10851. };
  10852. THREE.GeometryUtils.random = THREE.Math.random16;
  10853. THREE.GeometryUtils.__v1 = new THREE.Vector3();
  10854. /**
  10855. * @author alteredq / http://alteredqualia.com/
  10856. * @author mrdoob / http://mrdoob.com/
  10857. */
  10858. THREE.ImageUtils = {
  10859. crossOrigin: 'anonymous',
  10860. loadTexture: function ( path, mapping, callback ) {
  10861. var image = new Image(), texture = new THREE.Texture( image, mapping );
  10862. image.onload = function () { texture.needsUpdate = true; if ( callback ) callback( this ); };
  10863. image.crossOrigin = this.crossOrigin;
  10864. image.src = path;
  10865. return texture;
  10866. },
  10867. loadTextureCube: function ( array, mapping, callback ) {
  10868. var i, l, images = [], texture = new THREE.Texture( images, mapping );
  10869. images.loadCount = 0;
  10870. for ( i = 0, l = array.length; i < l; ++ i ) {
  10871. images[ i ] = new Image();
  10872. images[ i ].onload = function () {
  10873. images.loadCount += 1;
  10874. if ( images.loadCount === 6 ) texture.needsUpdate = true;
  10875. if ( callback ) callback( this );
  10876. };
  10877. images[ i ].crossOrigin = this.crossOrigin;
  10878. images[ i ].src = array[ i ];
  10879. }
  10880. return texture;
  10881. },
  10882. getNormalMap: function ( image, depth ) {
  10883. // Adapted from http://www.paulbrunt.co.uk/lab/heightnormal/
  10884. var cross = function ( a, b ) {
  10885. return [ a[ 1 ] * b[ 2 ] - a[ 2 ] * b[ 1 ], a[ 2 ] * b[ 0 ] - a[ 0 ] * b[ 2 ], a[ 0 ] * b[ 1 ] - a[ 1 ] * b[ 0 ] ];
  10886. }
  10887. var subtract = function ( a, b ) {
  10888. return [ a[ 0 ] - b[ 0 ], a[ 1 ] - b[ 1 ], a[ 2 ] - b[ 2 ] ];
  10889. }
  10890. var normalize = function ( a ) {
  10891. var l = Math.sqrt( a[ 0 ] * a[ 0 ] + a[ 1 ] * a[ 1 ] + a[ 2 ] * a[ 2 ] );
  10892. return [ a[ 0 ] / l, a[ 1 ] / l, a[ 2 ] / l ];
  10893. }
  10894. depth = depth | 1;
  10895. var width = image.width;
  10896. var height = image.height;
  10897. var canvas = document.createElement( 'canvas' );
  10898. canvas.width = width;
  10899. canvas.height = height;
  10900. var context = canvas.getContext( '2d' );
  10901. context.drawImage( image, 0, 0 );
  10902. var data = context.getImageData( 0, 0, width, height ).data;
  10903. var imageData = context.createImageData( width, height );
  10904. var output = imageData.data;
  10905. for ( var x = 0; x < width; x ++ ) {
  10906. for ( var y = 1; y < height; y ++ ) {
  10907. var ly = y - 1 < 0 ? height - 1 : y - 1;
  10908. var uy = ( y + 1 ) % height;
  10909. var lx = x - 1 < 0 ? width - 1 : x - 1;
  10910. var ux = ( x + 1 ) % width;
  10911. var points = [];
  10912. var origin = [ 0, 0, data[ ( y * width + x ) * 4 ] / 255 * depth ];
  10913. points.push( [ - 1, 0, data[ ( y * width + lx ) * 4 ] / 255 * depth ] );
  10914. points.push( [ - 1, - 1, data[ ( ly * width + lx ) * 4 ] / 255 * depth ] );
  10915. points.push( [ 0, - 1, data[ ( ly * width + x ) * 4 ] / 255 * depth ] );
  10916. points.push( [ 1, - 1, data[ ( ly * width + ux ) * 4 ] / 255 * depth ] );
  10917. points.push( [ 1, 0, data[ ( y * width + ux ) * 4 ] / 255 * depth ] );
  10918. points.push( [ 1, 1, data[ ( uy * width + ux ) * 4 ] / 255 * depth ] );
  10919. points.push( [ 0, 1, data[ ( uy * width + x ) * 4 ] / 255 * depth ] );
  10920. points.push( [ - 1, 1, data[ ( uy * width + lx ) * 4 ] / 255 * depth ] );
  10921. var normals = [];
  10922. var num_points = points.length;
  10923. for ( var i = 0; i < num_points; i ++ ) {
  10924. var v1 = points[ i ];
  10925. var v2 = points[ ( i + 1 ) % num_points ];
  10926. v1 = subtract( v1, origin );
  10927. v2 = subtract( v2, origin );
  10928. normals.push( normalize( cross( v1, v2 ) ) );
  10929. }
  10930. var normal = [ 0, 0, 0 ];
  10931. for ( var i = 0; i < normals.length; i ++ ) {
  10932. normal[ 0 ] += normals[ i ][ 0 ];
  10933. normal[ 1 ] += normals[ i ][ 1 ];
  10934. normal[ 2 ] += normals[ i ][ 2 ];
  10935. }
  10936. normal[ 0 ] /= normals.length;
  10937. normal[ 1 ] /= normals.length;
  10938. normal[ 2 ] /= normals.length;
  10939. var idx = ( y * width + x ) * 4;
  10940. output[ idx ] = ( ( normal[ 0 ] + 1.0 ) / 2.0 * 255 ) | 0;
  10941. output[ idx + 1 ] = ( ( normal[ 1 ] + 1.0 / 2.0 ) * 255 ) | 0;
  10942. output[ idx + 2 ] = ( normal[ 2 ] * 255 ) | 0;
  10943. output[ idx + 3 ] = 255;
  10944. }
  10945. }
  10946. context.putImageData( imageData, 0, 0 );
  10947. return canvas;
  10948. },
  10949. generateDataTexture: function ( width, height, color ) {
  10950. var size = width * height;
  10951. var data = new Uint8Array( 3 * size );
  10952. var r = Math.floor( color.r * 255 );
  10953. var g = Math.floor( color.g * 255 );
  10954. var b = Math.floor( color.b * 255 );
  10955. for ( var i = 0; i < size; i ++ ) {
  10956. data[ i * 3 ] = r;
  10957. data[ i * 3 + 1 ] = g;
  10958. data[ i * 3 + 2 ] = b;
  10959. }
  10960. var texture = new THREE.DataTexture( data, width, height, THREE.RGBFormat );
  10961. texture.needsUpdate = true;
  10962. return texture;
  10963. }
  10964. };
  10965. /**
  10966. * @author alteredq / http://alteredqualia.com/
  10967. */
  10968. THREE.SceneUtils = {
  10969. showHierarchy : function ( root, visible ) {
  10970. THREE.SceneUtils.traverseHierarchy( root, function( node ) { node.visible = visible; } );
  10971. },
  10972. traverseHierarchy : function ( root, callback ) {
  10973. var n, i, l = root.children.length;
  10974. for ( i = 0; i < l; i ++ ) {
  10975. n = root.children[ i ];
  10976. callback( n );
  10977. THREE.SceneUtils.traverseHierarchy( n, callback );
  10978. }
  10979. },
  10980. createMultiMaterialObject : function ( geometry, materials ) {
  10981. var i, il = materials.length,
  10982. group = new THREE.Object3D();
  10983. for ( i = 0; i < il; i ++ ) {
  10984. var object = new THREE.Mesh( geometry, materials[ i ] );
  10985. group.add( object );
  10986. }
  10987. return group;
  10988. },
  10989. cloneObject: function ( source ) {
  10990. var object;
  10991. // subclass specific properties
  10992. // (must process in order from more specific subclasses to more abstract classes)
  10993. if ( source instanceof THREE.MorphAnimMesh ) {
  10994. object = new THREE.MorphAnimMesh( source.geometry, source.material );
  10995. object.duration = source.duration;
  10996. object.mirroredLoop = source.mirroredLoop;
  10997. object.time = source.time;
  10998. object.lastKeyframe = source.lastKeyframe;
  10999. object.currentKeyframe = source.currentKeyframe;
  11000. object.direction = source.direction;
  11001. object.directionBackwards = source.directionBackwards;
  11002. } else if ( source instanceof THREE.SkinnedMesh ) {
  11003. object = new THREE.SkinnedMesh( source.geometry, source.material );
  11004. } else if ( source instanceof THREE.Mesh ) {
  11005. object = new THREE.Mesh( source.geometry, source.material );
  11006. } else if ( source instanceof THREE.Line ) {
  11007. object = new THREE.Line( source.geometry, source.material, source.type );
  11008. } else if ( source instanceof THREE.Ribbon ) {
  11009. object = new THREE.Ribbon( source.geometry, source.material );
  11010. } else if ( source instanceof THREE.ParticleSystem ) {
  11011. object = new THREE.ParticleSystem( source.geometry, source.material );
  11012. object.sortParticles = source.sortParticles;
  11013. } else if ( source instanceof THREE.Particle ) {
  11014. object = new THREE.Particle( source.material );
  11015. } else if ( source instanceof THREE.Sprite ) {
  11016. object = new THREE.Sprite( {} );
  11017. object.color.copy( source.color );
  11018. object.map = source.map;
  11019. object.blending = source.blending;
  11020. object.useScreenCoordinates = source.useScreenCoordinates;
  11021. object.mergeWith3D = source.mergeWith3D;
  11022. object.affectedByDistance = source.affectedByDistance;
  11023. object.scaleByViewport = source.scaleByViewport;
  11024. object.alignment = source.alignment;
  11025. object.rotation3d.copy( source.rotation3d );
  11026. object.rotation = source.rotation;
  11027. object.opacity = source.opacity;
  11028. object.uvOffset.copy( source.uvOffset );
  11029. object.uvScale.copy( source.uvScale);
  11030. } else if ( source instanceof THREE.LOD ) {
  11031. object = new THREE.LOD();
  11032. } else if ( source instanceof THREE.MarchingCubes ) {
  11033. object = new THREE.MarchingCubes( source.resolution, source.material );
  11034. object.field.set( source.field );
  11035. object.isolation = source.isolation;
  11036. } else if ( source instanceof THREE.Object3D ) {
  11037. object = new THREE.Object3D();
  11038. }
  11039. // base class properties
  11040. object.name = source.name;
  11041. object.parent = source.parent;
  11042. object.up.copy( source.up );
  11043. object.position.copy( source.position );
  11044. // because of Sprite madness
  11045. if ( object.rotation instanceof THREE.Vector3 )
  11046. object.rotation.copy( source.rotation );
  11047. object.eulerOrder = source.eulerOrder;
  11048. object.scale.copy( source.scale );
  11049. object.dynamic = source.dynamic;
  11050. object.doubleSided = source.doubleSided;
  11051. object.flipSided = source.flipSided;
  11052. object.renderDepth = source.renderDepth;
  11053. object.rotationAutoUpdate = source.rotationAutoUpdate;
  11054. object.matrix.copy( source.matrix );
  11055. object.matrixWorld.copy( source.matrixWorld );
  11056. object.matrixRotationWorld.copy( source.matrixRotationWorld );
  11057. object.matrixAutoUpdate = source.matrixAutoUpdate;
  11058. object.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  11059. object.quaternion.copy( source.quaternion );
  11060. object.useQuaternion = source.useQuaternion;
  11061. object.boundRadius = source.boundRadius;
  11062. object.boundRadiusScale = source.boundRadiusScale;
  11063. object.visible = source.visible;
  11064. object.castShadow = source.castShadow;
  11065. object.receiveShadow = source.receiveShadow;
  11066. object.frustumCulled = source.frustumCulled;
  11067. // children
  11068. for ( var i = 0; i < source.children.length; i ++ ) {
  11069. var child = THREE.SceneUtils.cloneObject( source.children[ i ] );
  11070. object.children[ i ] = child;
  11071. child.parent = object;
  11072. }
  11073. // LODs need to be patched separately to use cloned children
  11074. if ( source instanceof THREE.LOD ) {
  11075. for ( var i = 0; i < source.LODs.length; i ++ ) {
  11076. var lod = source.LODs[ i ];
  11077. object.LODs[ i ] = { visibleAtDistance: lod.visibleAtDistance, object3D: object.children[ i ] };
  11078. }
  11079. }
  11080. return object;
  11081. },
  11082. detach : function ( child, parent, scene ) {
  11083. child.applyMatrix( parent.matrixWorld );
  11084. parent.remove( child );
  11085. scene.add( child );
  11086. },
  11087. attach: function ( child, scene, parent ) {
  11088. var matrixWorldInverse = new THREE.Matrix4();
  11089. matrixWorldInverse.getInverse( parent.matrixWorld );
  11090. child.applyMatrix( matrixWorldInverse );
  11091. scene.remove( child );
  11092. parent.add( child );
  11093. }
  11094. };
  11095. /**
  11096. * @author alteredq / http://alteredqualia.com/
  11097. * @author mr.doob / http://mrdoob.com/
  11098. *
  11099. * ShaderUtils currently contains:
  11100. *
  11101. * fresnel
  11102. * normal
  11103. * cube
  11104. *
  11105. */
  11106. if ( THREE.WebGLRenderer ) {
  11107. THREE.ShaderUtils = {
  11108. lib: {
  11109. /* -------------------------------------------------------------------------
  11110. // Fresnel shader
  11111. // - based on Nvidia Cg tutorial
  11112. ------------------------------------------------------------------------- */
  11113. 'fresnel': {
  11114. uniforms: {
  11115. "mRefractionRatio": { type: "f", value: 1.02 },
  11116. "mFresnelBias": { type: "f", value: 0.1 },
  11117. "mFresnelPower": { type: "f", value: 2.0 },
  11118. "mFresnelScale": { type: "f", value: 1.0 },
  11119. "tCube": { type: "t", value: 1, texture: null }
  11120. },
  11121. fragmentShader: [
  11122. "uniform samplerCube tCube;",
  11123. "varying vec3 vReflect;",
  11124. "varying vec3 vRefract[3];",
  11125. "varying float vReflectionFactor;",
  11126. "void main() {",
  11127. "vec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );",
  11128. "vec4 refractedColor = vec4( 1.0, 1.0, 1.0, 1.0 );",
  11129. "refractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;",
  11130. "refractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;",
  11131. "refractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;",
  11132. "refractedColor.a = 1.0;",
  11133. "gl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );",
  11134. "}"
  11135. ].join("\n"),
  11136. vertexShader: [
  11137. "uniform float mRefractionRatio;",
  11138. "uniform float mFresnelBias;",
  11139. "uniform float mFresnelScale;",
  11140. "uniform float mFresnelPower;",
  11141. "varying vec3 vReflect;",
  11142. "varying vec3 vRefract[3];",
  11143. "varying float vReflectionFactor;",
  11144. "void main() {",
  11145. "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  11146. "vec4 mPosition = objectMatrix * vec4( position, 1.0 );",
  11147. "vec3 nWorld = normalize ( mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal );",
  11148. "vec3 I = mPosition.xyz - cameraPosition;",
  11149. "vReflect = reflect( I, nWorld );",
  11150. "vRefract[0] = refract( normalize( I ), nWorld, mRefractionRatio );",
  11151. "vRefract[1] = refract( normalize( I ), nWorld, mRefractionRatio * 0.99 );",
  11152. "vRefract[2] = refract( normalize( I ), nWorld, mRefractionRatio * 0.98 );",
  11153. "vReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), nWorld ), mFresnelPower );",
  11154. "gl_Position = projectionMatrix * mvPosition;",
  11155. "}"
  11156. ].join("\n")
  11157. },
  11158. /* -------------------------------------------------------------------------
  11159. // Normal map shader
  11160. // - Blinn-Phong
  11161. // - normal + diffuse + specular + AO + displacement + reflection + shadow maps
  11162. // - point and directional lights (use with "lights: true" material option)
  11163. ------------------------------------------------------------------------- */
  11164. 'normal' : {
  11165. uniforms: THREE.UniformsUtils.merge( [
  11166. THREE.UniformsLib[ "fog" ],
  11167. THREE.UniformsLib[ "lights" ],
  11168. THREE.UniformsLib[ "shadowmap" ],
  11169. {
  11170. "enableAO" : { type: "i", value: 0 },
  11171. "enableDiffuse" : { type: "i", value: 0 },
  11172. "enableSpecular" : { type: "i", value: 0 },
  11173. "enableReflection": { type: "i", value: 0 },
  11174. "tDiffuse" : { type: "t", value: 0, texture: null },
  11175. "tCube" : { type: "t", value: 1, texture: null },
  11176. "tNormal" : { type: "t", value: 2, texture: null },
  11177. "tSpecular" : { type: "t", value: 3, texture: null },
  11178. "tAO" : { type: "t", value: 4, texture: null },
  11179. "tDisplacement": { type: "t", value: 5, texture: null },
  11180. "uNormalScale": { type: "f", value: 1.0 },
  11181. "uDisplacementBias": { type: "f", value: 0.0 },
  11182. "uDisplacementScale": { type: "f", value: 1.0 },
  11183. "uDiffuseColor": { type: "c", value: new THREE.Color( 0xffffff ) },
  11184. "uSpecularColor": { type: "c", value: new THREE.Color( 0x111111 ) },
  11185. "uAmbientColor": { type: "c", value: new THREE.Color( 0xffffff ) },
  11186. "uShininess": { type: "f", value: 30 },
  11187. "uOpacity": { type: "f", value: 1 },
  11188. "uReflectivity": { type: "f", value: 0.5 },
  11189. "uOffset" : { type: "v2", value: new THREE.Vector2( 0, 0 ) },
  11190. "uRepeat" : { type: "v2", value: new THREE.Vector2( 1, 1 ) },
  11191. "wrapRGB" : { type: "v3", value: new THREE.Vector3( 1, 1, 1 ) }
  11192. }
  11193. ] ),
  11194. fragmentShader: [
  11195. "uniform vec3 uAmbientColor;",
  11196. "uniform vec3 uDiffuseColor;",
  11197. "uniform vec3 uSpecularColor;",
  11198. "uniform float uShininess;",
  11199. "uniform float uOpacity;",
  11200. "uniform bool enableDiffuse;",
  11201. "uniform bool enableSpecular;",
  11202. "uniform bool enableAO;",
  11203. "uniform bool enableReflection;",
  11204. "uniform sampler2D tDiffuse;",
  11205. "uniform sampler2D tNormal;",
  11206. "uniform sampler2D tSpecular;",
  11207. "uniform sampler2D tAO;",
  11208. "uniform samplerCube tCube;",
  11209. "uniform float uNormalScale;",
  11210. "uniform float uReflectivity;",
  11211. "varying vec3 vTangent;",
  11212. "varying vec3 vBinormal;",
  11213. "varying vec3 vNormal;",
  11214. "varying vec2 vUv;",
  11215. "uniform vec3 ambientLightColor;",
  11216. "#if MAX_DIR_LIGHTS > 0",
  11217. "uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];",
  11218. "uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];",
  11219. "#endif",
  11220. "#if MAX_POINT_LIGHTS > 0",
  11221. "uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];",
  11222. "varying vec4 vPointLight[ MAX_POINT_LIGHTS ];",
  11223. "#endif",
  11224. "#ifdef WRAP_AROUND",
  11225. "uniform vec3 wrapRGB;",
  11226. "#endif",
  11227. "varying vec3 vViewPosition;",
  11228. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11229. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11230. "void main() {",
  11231. "gl_FragColor = vec4( vec3( 1.0 ), uOpacity );",
  11232. "vec3 specularTex = vec3( 1.0 );",
  11233. "vec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;",
  11234. "normalTex.xy *= uNormalScale;",
  11235. "normalTex = normalize( normalTex );",
  11236. "if( enableDiffuse ) {",
  11237. "#ifdef GAMMA_INPUT",
  11238. "vec4 texelColor = texture2D( tDiffuse, vUv );",
  11239. "texelColor.xyz *= texelColor.xyz;",
  11240. "gl_FragColor = gl_FragColor * texelColor;",
  11241. "#else",
  11242. "gl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );",
  11243. "#endif",
  11244. "}",
  11245. "if( enableAO ) {",
  11246. "#ifdef GAMMA_INPUT",
  11247. "vec4 aoColor = texture2D( tAO, vUv );",
  11248. "aoColor.xyz *= aoColor.xyz;",
  11249. "gl_FragColor.xyz = gl_FragColor.xyz * aoColor.xyz;",
  11250. "#else",
  11251. "gl_FragColor.xyz = gl_FragColor.xyz * texture2D( tAO, vUv ).xyz;",
  11252. "#endif",
  11253. "}",
  11254. "if( enableSpecular )",
  11255. "specularTex = texture2D( tSpecular, vUv ).xyz;",
  11256. "mat3 tsb = mat3( normalize( vTangent ), normalize( vBinormal ), normalize( vNormal ) );",
  11257. "vec3 finalNormal = tsb * normalTex;",
  11258. "vec3 normal = normalize( finalNormal );",
  11259. "vec3 viewPosition = normalize( vViewPosition );",
  11260. // point lights
  11261. "#if MAX_POINT_LIGHTS > 0",
  11262. "vec3 pointDiffuse = vec3( 0.0 );",
  11263. "vec3 pointSpecular = vec3( 0.0 );",
  11264. "for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
  11265. "vec3 pointVector = normalize( vPointLight[ i ].xyz );",
  11266. "float pointDistance = vPointLight[ i ].w;",
  11267. // diffuse
  11268. "#ifdef WRAP_AROUND",
  11269. "float pointDiffuseWeightFull = max( dot( normal, pointVector ), 0.0 );",
  11270. "float pointDiffuseWeightHalf = max( 0.5 * dot( normal, pointVector ) + 0.5, 0.0 );",
  11271. "vec3 pointDiffuseWeight = mix( vec3 ( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );",
  11272. "#else",
  11273. "float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );",
  11274. "#endif",
  11275. "pointDiffuse += pointDistance * pointLightColor[ i ] * uDiffuseColor * pointDiffuseWeight;",
  11276. // specular
  11277. "vec3 pointHalfVector = normalize( pointVector + viewPosition );",
  11278. "float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );",
  11279. "float pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, uShininess ), 0.0 );",
  11280. "#ifdef PHYSICALLY_BASED_SHADING",
  11281. // 2.0 => 2.0001 is hack to work around ANGLE bug
  11282. "float specularNormalization = ( uShininess + 2.0001 ) / 8.0;",
  11283. "vec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( pointVector, pointHalfVector ), 5.0 );",
  11284. "pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * pointDistance * specularNormalization;",
  11285. "#else",
  11286. "pointSpecular += pointDistance * pointLightColor[ i ] * uSpecularColor * pointSpecularWeight * pointDiffuseWeight;",
  11287. "#endif",
  11288. "}",
  11289. "#endif",
  11290. // directional lights
  11291. "#if MAX_DIR_LIGHTS > 0",
  11292. "vec3 dirDiffuse = vec3( 0.0 );",
  11293. "vec3 dirSpecular = vec3( 0.0 );",
  11294. "for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {",
  11295. "vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );",
  11296. "vec3 dirVector = normalize( lDirection.xyz );",
  11297. // diffuse
  11298. "#ifdef WRAP_AROUND",
  11299. "float directionalLightWeightingFull = max( dot( normal, dirVector ), 0.0 );",
  11300. "float directionalLightWeightingHalf = max( 0.5 * dot( normal, dirVector ) + 0.5, 0.0 );",
  11301. "vec3 dirDiffuseWeight = mix( vec3( directionalLightWeightingFull ), vec3( directionalLightWeightingHalf ), wrapRGB );",
  11302. "#else",
  11303. "float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );",
  11304. "#endif",
  11305. "dirDiffuse += directionalLightColor[ i ] * uDiffuseColor * dirDiffuseWeight;",
  11306. // specular
  11307. "vec3 dirHalfVector = normalize( dirVector + viewPosition );",
  11308. "float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );",
  11309. "float dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, uShininess ), 0.0 );",
  11310. "#ifdef PHYSICALLY_BASED_SHADING",
  11311. // 2.0 => 2.0001 is hack to work around ANGLE bug
  11312. "float specularNormalization = ( uShininess + 2.0001 ) / 8.0;",
  11313. "vec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( dirVector, dirHalfVector ), 5.0 );",
  11314. "dirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;",
  11315. "#else",
  11316. "dirSpecular += directionalLightColor[ i ] * uSpecularColor * dirSpecularWeight * dirDiffuseWeight;",
  11317. "#endif",
  11318. "}",
  11319. "#endif",
  11320. // all lights contribution summation
  11321. "vec3 totalDiffuse = vec3( 0.0 );",
  11322. "vec3 totalSpecular = vec3( 0.0 );",
  11323. "#if MAX_DIR_LIGHTS > 0",
  11324. "totalDiffuse += dirDiffuse;",
  11325. "totalSpecular += dirSpecular;",
  11326. "#endif",
  11327. "#if MAX_POINT_LIGHTS > 0",
  11328. "totalDiffuse += pointDiffuse;",
  11329. "totalSpecular += pointSpecular;",
  11330. "#endif",
  11331. "gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * uAmbientColor) + totalSpecular;",
  11332. "if ( enableReflection ) {",
  11333. "vec3 wPos = cameraPosition - vViewPosition;",
  11334. "vec3 vReflect = reflect( normalize( wPos ), normal );",
  11335. "vec4 cubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );",
  11336. "#ifdef GAMMA_INPUT",
  11337. "cubeColor.xyz *= cubeColor.xyz;",
  11338. "#endif",
  11339. "gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularTex.r * uReflectivity );",
  11340. "}",
  11341. THREE.ShaderChunk[ "shadowmap_fragment" ],
  11342. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  11343. THREE.ShaderChunk[ "fog_fragment" ],
  11344. "}"
  11345. ].join("\n"),
  11346. vertexShader: [
  11347. "attribute vec4 tangent;",
  11348. "uniform vec2 uOffset;",
  11349. "uniform vec2 uRepeat;",
  11350. "#ifdef VERTEX_TEXTURES",
  11351. "uniform sampler2D tDisplacement;",
  11352. "uniform float uDisplacementScale;",
  11353. "uniform float uDisplacementBias;",
  11354. "#endif",
  11355. "varying vec3 vTangent;",
  11356. "varying vec3 vBinormal;",
  11357. "varying vec3 vNormal;",
  11358. "varying vec2 vUv;",
  11359. "#if MAX_POINT_LIGHTS > 0",
  11360. "uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];",
  11361. "uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",
  11362. "varying vec4 vPointLight[ MAX_POINT_LIGHTS ];",
  11363. "#endif",
  11364. "varying vec3 vViewPosition;",
  11365. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  11366. "void main() {",
  11367. "vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  11368. "vViewPosition = -mvPosition.xyz;",
  11369. // normal, tangent and binormal vectors
  11370. "vNormal = normalMatrix * normal;",
  11371. "vTangent = normalMatrix * tangent.xyz;",
  11372. "vBinormal = cross( vNormal, vTangent ) * tangent.w;",
  11373. "vUv = uv * uRepeat + uOffset;",
  11374. // point lights
  11375. "#if MAX_POINT_LIGHTS > 0",
  11376. "for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {",
  11377. "vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
  11378. "vec3 lVector = lPosition.xyz - mvPosition.xyz;",
  11379. "float lDistance = 1.0;",
  11380. "if ( pointLightDistance[ i ] > 0.0 )",
  11381. "lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
  11382. "lVector = normalize( lVector );",
  11383. "vPointLight[ i ] = vec4( lVector, lDistance );",
  11384. "}",
  11385. "#endif",
  11386. // displacement mapping
  11387. "#ifdef VERTEX_TEXTURES",
  11388. "vec3 dv = texture2D( tDisplacement, uv ).xyz;",
  11389. "float df = uDisplacementScale * dv.x + uDisplacementBias;",
  11390. "vec4 displacedPosition = vec4( normalize( vNormal.xyz ) * df, 0.0 ) + mvPosition;",
  11391. "gl_Position = projectionMatrix * displacedPosition;",
  11392. "#else",
  11393. "gl_Position = projectionMatrix * mvPosition;",
  11394. "#endif",
  11395. THREE.ShaderChunk[ "shadowmap_vertex" ],
  11396. "}"
  11397. ].join("\n")
  11398. },
  11399. /* -------------------------------------------------------------------------
  11400. // Cube map shader
  11401. ------------------------------------------------------------------------- */
  11402. 'cube': {
  11403. uniforms: { "tCube": { type: "t", value: 1, texture: null },
  11404. "tFlip": { type: "f", value: -1 } },
  11405. vertexShader: [
  11406. "varying vec3 vViewPosition;",
  11407. "void main() {",
  11408. "vec4 mPosition = objectMatrix * vec4( position, 1.0 );",
  11409. "vViewPosition = cameraPosition - mPosition.xyz;",
  11410. "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  11411. "}"
  11412. ].join("\n"),
  11413. fragmentShader: [
  11414. "uniform samplerCube tCube;",
  11415. "uniform float tFlip;",
  11416. "varying vec3 vViewPosition;",
  11417. "void main() {",
  11418. "vec3 wPos = cameraPosition - vViewPosition;",
  11419. "gl_FragColor = textureCube( tCube, vec3( tFlip * wPos.x, wPos.yz ) );",
  11420. "}"
  11421. ].join("\n")
  11422. }
  11423. }
  11424. };
  11425. };/**
  11426. * @author alteredq / http://alteredqualia.com/
  11427. */
  11428. THREE.BufferGeometry = function () {
  11429. this.id = THREE.GeometryCount ++;
  11430. // GL buffers
  11431. this.vertexIndexBuffer = null;
  11432. this.vertexPositionBuffer = null;
  11433. this.vertexNormalBuffer = null;
  11434. this.vertexUvBuffer = null;
  11435. this.vertexColorBuffer = null;
  11436. // typed arrays (kept only if dynamic flag is set)
  11437. this.vertexIndexArray = null;
  11438. this.vertexPositionArray = null;
  11439. this.vertexNormalArray = null;
  11440. this.vertexUvArray = null;
  11441. this.vertexColorArray = null;
  11442. this.dynamic = false;
  11443. // boundings
  11444. this.boundingBox = null;
  11445. this.boundingSphere = null;
  11446. // for compatibility
  11447. this.morphTargets = [];
  11448. };
  11449. THREE.BufferGeometry.prototype = {
  11450. constructor : THREE.BufferGeometry,
  11451. // for compatibility
  11452. computeBoundingBox: function () {
  11453. },
  11454. // for compatibility
  11455. computeBoundingSphere: function () {
  11456. }
  11457. };
  11458. /**
  11459. * @author zz85 / http://www.lab4games.net/zz85/blog
  11460. * Extensible curve object
  11461. *
  11462. * Some common of Curve methods
  11463. * .getPoint(t), getTangent(t)
  11464. * .getPointAt(u), getTagentAt(u)
  11465. * .getPoints(), .getSpacedPoints()
  11466. * .getLength()
  11467. * .updateArcLengths()
  11468. *
  11469. * This file contains following classes:
  11470. *
  11471. * -- 2d classes --
  11472. * THREE.Curve
  11473. * THREE.LineCurve
  11474. * THREE.QuadraticBezierCurve
  11475. * THREE.CubicBezierCurve
  11476. * THREE.SplineCurve
  11477. * THREE.ArcCurve
  11478. *
  11479. * -- 3d classes --
  11480. * THREE.LineCurve3
  11481. * THREE.QuadraticBezierCurve3
  11482. * THREE.CubicBezierCurve3
  11483. * THREE.SplineCurve3
  11484. * THREE.ClosedSplineCurve3
  11485. *
  11486. * A series of curves can be represented as a THREE.CurvePath
  11487. *
  11488. **/
  11489. /**************************************************************
  11490. * Abstract Curve base class
  11491. **************************************************************/
  11492. THREE.Curve = function () {
  11493. };
  11494. // Virtual base class method to overwrite and implement in subclasses
  11495. // - t [0 .. 1]
  11496. THREE.Curve.prototype.getPoint = function ( t ) {
  11497. console.log( "Warning, getPoint() not implemented!" );
  11498. return null;
  11499. };
  11500. // Get point at relative position in curve according to arc length
  11501. // - u [0 .. 1]
  11502. THREE.Curve.prototype.getPointAt = function ( u ) {
  11503. var t = this.getUtoTmapping( u );
  11504. return this.getPoint( t );
  11505. };
  11506. // Get sequence of points using getPoint( t )
  11507. THREE.Curve.prototype.getPoints = function ( divisions ) {
  11508. if ( !divisions ) divisions = 5;
  11509. var d, pts = [];
  11510. for ( d = 0; d <= divisions; d ++ ) {
  11511. pts.push( this.getPoint( d / divisions ) );
  11512. }
  11513. return pts;
  11514. };
  11515. // Get sequence of points using getPointAt( u )
  11516. THREE.Curve.prototype.getSpacedPoints = function ( divisions ) {
  11517. if ( !divisions ) divisions = 5;
  11518. var d, pts = [];
  11519. for ( d = 0; d <= divisions; d ++ ) {
  11520. pts.push( this.getPointAt( d / divisions ) );
  11521. }
  11522. return pts;
  11523. };
  11524. // Get total curve arc length
  11525. THREE.Curve.prototype.getLength = function () {
  11526. var lengths = this.getLengths();
  11527. return lengths[ lengths.length - 1 ];
  11528. };
  11529. // Get list of cumulative segment lengths
  11530. THREE.Curve.prototype.getLengths = function ( divisions ) {
  11531. if ( !divisions ) divisions = (this.__arcLengthDivisions) ? (this.__arcLengthDivisions): 200;
  11532. if ( this.cacheArcLengths
  11533. && ( this.cacheArcLengths.length == divisions + 1 )
  11534. && !this.needsUpdate) {
  11535. //console.log( "cached", this.cacheArcLengths );
  11536. return this.cacheArcLengths;
  11537. }
  11538. this.needsUpdate = false;
  11539. var cache = [];
  11540. var current, last = this.getPoint( 0 );
  11541. var p, sum = 0;
  11542. cache.push( 0 );
  11543. for ( p = 1; p <= divisions; p ++ ) {
  11544. current = this.getPoint ( p / divisions );
  11545. sum += current.distanceTo( last );
  11546. cache.push( sum );
  11547. last = current;
  11548. }
  11549. this.cacheArcLengths = cache;
  11550. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  11551. };
  11552. THREE.Curve.prototype.updateArcLengths = function() {
  11553. this.needsUpdate = true;
  11554. this.getLengths();
  11555. };
  11556. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equi distance
  11557. THREE.Curve.prototype.getUtoTmapping = function ( u, distance ) {
  11558. var arcLengths = this.getLengths();
  11559. var i = 0, il = arcLengths.length;
  11560. var targetArcLength; // The targeted u distance value to get
  11561. if ( distance ) {
  11562. targetArcLength = distance;
  11563. } else {
  11564. targetArcLength = u * arcLengths[ il - 1 ];
  11565. }
  11566. //var time = Date.now();
  11567. // binary search for the index with largest value smaller than target u distance
  11568. var low = 0, high = il - 1, comparison;
  11569. while ( low <= high ) {
  11570. 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
  11571. comparison = arcLengths[ i ] - targetArcLength;
  11572. if ( comparison < 0 ) {
  11573. low = i + 1;
  11574. continue;
  11575. } else if ( comparison > 0 ) {
  11576. high = i - 1;
  11577. continue;
  11578. } else {
  11579. high = i;
  11580. break;
  11581. // DONE
  11582. }
  11583. }
  11584. i = high;
  11585. //console.log('b' , i, low, high, Date.now()- time);
  11586. if ( arcLengths[ i ] == targetArcLength ) {
  11587. var t = i / ( il - 1 );
  11588. return t;
  11589. }
  11590. // we could get finer grain at lengths, or use simple interpolatation between two points
  11591. var lengthBefore = arcLengths[ i ];
  11592. var lengthAfter = arcLengths[ i + 1 ];
  11593. var segmentLength = lengthAfter - lengthBefore;
  11594. // determine where we are between the 'before' and 'after' points
  11595. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  11596. // add that fractional amount to t
  11597. var t = ( i + segmentFraction ) / ( il -1 );
  11598. return t;
  11599. };
  11600. // In 2D space, there are actually 2 normal vectors,
  11601. // and in 3D space, infinte
  11602. // TODO this should be depreciated.
  11603. THREE.Curve.prototype.getNormalVector = function( t ) {
  11604. var vec = this.getTangent( t );
  11605. return new THREE.Vector2( -vec.y , vec.x );
  11606. };
  11607. // Returns a unit vector tangent at t
  11608. // In case any sub curve does not implement its tangent / normal finding,
  11609. // we get 2 points with a small delta and find a gradient of the 2 points
  11610. // which seems to make a reasonable approximation
  11611. THREE.Curve.prototype.getTangent = function( t ) {
  11612. var delta = 0.0001;
  11613. var t1 = t - delta;
  11614. var t2 = t + delta;
  11615. // Capping in case of danger
  11616. if ( t1 < 0 ) t1 = 0;
  11617. if ( t2 > 1 ) t2 = 1;
  11618. var pt1 = this.getPoint( t1 );
  11619. var pt2 = this.getPoint( t2 );
  11620. var vec = pt2.clone().subSelf(pt1);
  11621. return vec.normalize();
  11622. };
  11623. THREE.Curve.prototype.getTangentAt = function ( u ) {
  11624. var t = this.getUtoTmapping( u );
  11625. return this.getTangent( t );
  11626. };
  11627. /**************************************************************
  11628. * Line
  11629. **************************************************************/
  11630. THREE.LineCurve = function ( v1, v2 ) {
  11631. this.v1 = v1;
  11632. this.v2 = v2;
  11633. };
  11634. THREE.LineCurve.prototype = new THREE.Curve();
  11635. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  11636. THREE.LineCurve.prototype.getPoint = function ( t ) {
  11637. var point = this.v2.clone().subSelf(this.v1);
  11638. point.multiplyScalar( t ).addSelf( this.v1 );
  11639. return point;
  11640. };
  11641. // Line curve is linear, so we can overwrite default getPointAt
  11642. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  11643. return this.getPoint( u );
  11644. };
  11645. THREE.LineCurve.prototype.getTangent = function( t ) {
  11646. var tangent = this.v2.clone().subSelf(this.v1);
  11647. return tangent.normalize();
  11648. };
  11649. /**************************************************************
  11650. * Quadratic Bezier curve
  11651. **************************************************************/
  11652. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  11653. this.v0 = v0;
  11654. this.v1 = v1;
  11655. this.v2 = v2;
  11656. };
  11657. THREE.QuadraticBezierCurve.prototype = new THREE.Curve();
  11658. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  11659. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  11660. var tx, ty;
  11661. tx = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  11662. ty = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  11663. return new THREE.Vector2( tx, ty );
  11664. };
  11665. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  11666. var tx, ty;
  11667. tx = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x );
  11668. ty = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y );
  11669. // returns unit vector
  11670. var tangent = new THREE.Vector2( tx, ty );
  11671. tangent.normalize();
  11672. return tangent;
  11673. };
  11674. /**************************************************************
  11675. * Cubic Bezier curve
  11676. **************************************************************/
  11677. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  11678. this.v0 = v0;
  11679. this.v1 = v1;
  11680. this.v2 = v2;
  11681. this.v3 = v3;
  11682. };
  11683. THREE.CubicBezierCurve.prototype = new THREE.Curve();
  11684. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  11685. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  11686. var tx, ty;
  11687. tx = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  11688. ty = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  11689. return new THREE.Vector2( tx, ty );
  11690. };
  11691. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  11692. var tx, ty;
  11693. tx = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  11694. ty = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  11695. var tangent = new THREE.Vector2( tx, ty );
  11696. tangent.normalize();
  11697. return tangent;
  11698. };
  11699. /**************************************************************
  11700. * Spline curve
  11701. **************************************************************/
  11702. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  11703. this.points = (points == undefined) ? [] : points;
  11704. };
  11705. THREE.SplineCurve.prototype = new THREE.Curve();
  11706. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  11707. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  11708. var v = new THREE.Vector2();
  11709. var c = [];
  11710. var points = this.points, point, intPoint, weight;
  11711. point = ( points.length - 1 ) * t;
  11712. intPoint = Math.floor( point );
  11713. weight = point - intPoint;
  11714. c[ 0 ] = intPoint == 0 ? intPoint : intPoint - 1;
  11715. c[ 1 ] = intPoint;
  11716. c[ 2 ] = intPoint > points.length - 2 ? points.length -1 : intPoint + 1;
  11717. c[ 3 ] = intPoint > points.length - 3 ? points.length -1 : intPoint + 2;
  11718. v.x = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].x, points[ c[ 1 ] ].x, points[ c[ 2 ] ].x, points[ c[ 3 ] ].x, weight );
  11719. v.y = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].y, points[ c[ 1 ] ].y, points[ c[ 2 ] ].y, points[ c[ 3 ] ].y, weight );
  11720. return v;
  11721. };
  11722. /**************************************************************
  11723. * Arc curve
  11724. **************************************************************/
  11725. THREE.ArcCurve = function ( aX, aY, aRadius,
  11726. aStartAngle, aEndAngle,
  11727. aClockwise ) {
  11728. this.aX = aX;
  11729. this.aY = aY;
  11730. this.aRadius = aRadius;
  11731. this.aStartAngle = aStartAngle;
  11732. this.aEndAngle = aEndAngle;
  11733. this.aClockwise = aClockwise;
  11734. };
  11735. THREE.ArcCurve.prototype = new THREE.Curve();
  11736. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  11737. THREE.ArcCurve.prototype.getPoint = function ( t ) {
  11738. var deltaAngle = this.aEndAngle - this.aStartAngle;
  11739. if ( !this.aClockwise ) {
  11740. t = 1 - t;
  11741. }
  11742. var angle = this.aStartAngle + t * deltaAngle;
  11743. var tx = this.aX + this.aRadius * Math.cos( angle );
  11744. var ty = this.aY + this.aRadius * Math.sin( angle );
  11745. return new THREE.Vector2( tx, ty );
  11746. };
  11747. /**************************************************************
  11748. * Utils
  11749. **************************************************************/
  11750. THREE.Curve.Utils = {
  11751. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  11752. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  11753. },
  11754. // Puay Bing, thanks for helping with this derivative!
  11755. tangentCubicBezier: function (t, p0, p1, p2, p3 ) {
  11756. return -3 * p0 * (1 - t) * (1 - t) +
  11757. 3 * p1 * (1 - t) * (1-t) - 6 *t *p1 * (1-t) +
  11758. 6 * t * p2 * (1-t) - 3 * t * t * p2 +
  11759. 3 * t * t * p3;
  11760. },
  11761. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  11762. // To check if my formulas are correct
  11763. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  11764. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  11765. var h01 = -6 * t * t + 6 * t; // − 2t3 + 3t2
  11766. var h11 = 3 * t * t - 2 * t; // t3 − t2
  11767. return h00 + h10 + h01 + h11;
  11768. },
  11769. // Catmull-Rom
  11770. interpolate: function( p0, p1, p2, p3, t ) {
  11771. var v0 = ( p2 - p0 ) * 0.5;
  11772. var v1 = ( p3 - p1 ) * 0.5;
  11773. var t2 = t * t;
  11774. var t3 = t * t2;
  11775. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  11776. }
  11777. };
  11778. // TODO: Transformation for Curves?
  11779. /**************************************************************
  11780. * 3D Curves
  11781. **************************************************************/
  11782. // A Factory method for creating new curve subclasses
  11783. THREE.Curve.create = function( constructor, getPointFunc ) {
  11784. var subClass = constructor;
  11785. subClass.prototype = new THREE.Curve();
  11786. subClass.prototype.constructor = constructor;
  11787. subClass.prototype.getPoint = getPointFunc;
  11788. return subClass;
  11789. };
  11790. /**************************************************************
  11791. * Line3D
  11792. **************************************************************/
  11793. THREE.LineCurve3 = THREE.Curve.create(
  11794. function ( v1, v2 ) {
  11795. this.v1 = v1;
  11796. this.v2 = v2;
  11797. },
  11798. function ( t ) {
  11799. var r = new THREE.Vector3();
  11800. r.sub( this.v2, this.v1 ); // diff
  11801. r.multiplyScalar( t );
  11802. r.addSelf( this.v1 );
  11803. return r;
  11804. }
  11805. );
  11806. /**************************************************************
  11807. * Quadratic Bezier 3D curve
  11808. **************************************************************/
  11809. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  11810. function ( v0, v1, v2 ) {
  11811. this.v0 = v0;
  11812. this.v1 = v1;
  11813. this.v2 = v2;
  11814. },
  11815. function ( t ) {
  11816. var tx, ty, tz;
  11817. tx = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  11818. ty = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  11819. tz = THREE.Shape.Utils.b2( t, this.v0.z, this.v1.z, this.v2.z );
  11820. return new THREE.Vector3( tx, ty, tz );
  11821. }
  11822. );
  11823. /**************************************************************
  11824. * Cubic Bezier 3D curve
  11825. **************************************************************/
  11826. THREE.CubicBezierCurve3 = THREE.Curve.create(
  11827. function ( v0, v1, v2, v3 ) {
  11828. this.v0 = v0;
  11829. this.v1 = v1;
  11830. this.v2 = v2;
  11831. this.v3 = v3;
  11832. },
  11833. function ( t ) {
  11834. var tx, ty, tz;
  11835. tx = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  11836. ty = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  11837. tz = THREE.Shape.Utils.b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z );
  11838. return new THREE.Vector3( tx, ty, tz );
  11839. }
  11840. );
  11841. /**************************************************************
  11842. * Spline 3D curve
  11843. **************************************************************/
  11844. THREE.SplineCurve3 = THREE.Curve.create(
  11845. function ( points /* array of Vector3 */) {
  11846. this.points = (points == undefined) ? [] : points;
  11847. },
  11848. function ( t ) {
  11849. var v = new THREE.Vector3();
  11850. var c = [];
  11851. var points = this.points, point, intPoint, weight;
  11852. point = ( points.length - 1 ) * t;
  11853. intPoint = Math.floor( point );
  11854. weight = point - intPoint;
  11855. c[ 0 ] = intPoint == 0 ? intPoint : intPoint - 1;
  11856. c[ 1 ] = intPoint;
  11857. c[ 2 ] = intPoint > points.length - 2 ? points.length - 1 : intPoint + 1;
  11858. c[ 3 ] = intPoint > points.length - 3 ? points.length - 1 : intPoint + 2;
  11859. var pt0 = points[ c[0] ],
  11860. pt1 = points[ c[1] ],
  11861. pt2 = points[ c[2] ],
  11862. pt3 = points[ c[3] ];
  11863. v.x = THREE.Curve.Utils.interpolate(pt0.x, pt1.x, pt2.x, pt3.x, weight);
  11864. v.y = THREE.Curve.Utils.interpolate(pt0.y, pt1.y, pt2.y, pt3.y, weight);
  11865. v.z = THREE.Curve.Utils.interpolate(pt0.z, pt1.z, pt2.z, pt3.z, weight);
  11866. return v;
  11867. }
  11868. );
  11869. // THREE.SplineCurve3.prototype.getTangent = function(t) {
  11870. // var v = new THREE.Vector3();
  11871. // var c = [];
  11872. // var points = this.points, point, intPoint, weight;
  11873. // point = ( points.length - 1 ) * t;
  11874. // intPoint = Math.floor( point );
  11875. // weight = point - intPoint;
  11876. // c[ 0 ] = intPoint == 0 ? intPoint : intPoint - 1;
  11877. // c[ 1 ] = intPoint;
  11878. // c[ 2 ] = intPoint > points.length - 2 ? points.length - 1 : intPoint + 1;
  11879. // c[ 3 ] = intPoint > points.length - 3 ? points.length - 1 : intPoint + 2;
  11880. // var pt0 = points[ c[0] ],
  11881. // pt1 = points[ c[1] ],
  11882. // pt2 = points[ c[2] ],
  11883. // pt3 = points[ c[3] ];
  11884. // // t = weight;
  11885. // v.x = THREE.Curve.Utils.tangentSpline( t, pt0.x, pt1.x, pt2.x, pt3.x );
  11886. // v.y = THREE.Curve.Utils.tangentSpline( t, pt0.y, pt1.y, pt2.y, pt3.y );
  11887. // v.z = THREE.Curve.Utils.tangentSpline( t, pt0.z, pt1.z, pt2.z, pt3.z );
  11888. // return v;
  11889. // }
  11890. /**************************************************************
  11891. * Closed Spline 3D curve
  11892. **************************************************************/
  11893. THREE.ClosedSplineCurve3 = THREE.Curve.create(
  11894. function ( points /* array of Vector3 */) {
  11895. this.points = (points == undefined) ? [] : points;
  11896. },
  11897. function ( t ) {
  11898. var v = new THREE.Vector3();
  11899. var c = [];
  11900. var points = this.points, point, intPoint, weight;
  11901. point = ( points.length - 0 ) * t;
  11902. // This needs to be from 0-length +1
  11903. intPoint = Math.floor( point );
  11904. weight = point - intPoint;
  11905. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  11906. c[ 0 ] = ( intPoint - 1 ) % points.length;
  11907. c[ 1 ] = ( intPoint ) % points.length;
  11908. c[ 2 ] = ( intPoint + 1 ) % points.length;
  11909. c[ 3 ] = ( intPoint + 2 ) % points.length;
  11910. v.x = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].x, points[ c[ 1 ] ].x, points[ c[ 2 ] ].x, points[ c[ 3 ] ].x, weight );
  11911. v.y = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].y, points[ c[ 1 ] ].y, points[ c[ 2 ] ].y, points[ c[ 3 ] ].y, weight );
  11912. v.z = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].z, points[ c[ 1 ] ].z, points[ c[ 2 ] ].z, points[ c[ 3 ] ].z, weight );
  11913. return v;
  11914. }
  11915. );/**
  11916. * @author zz85 / http://www.lab4games.net/zz85/blog
  11917. *
  11918. **/
  11919. /**************************************************************
  11920. * Curved Path - a curve path is simply a array of connected
  11921. * curves, but retains the api of a curve
  11922. **************************************************************/
  11923. THREE.CurvePath = function () {
  11924. this.curves = [];
  11925. this.bends = [];
  11926. this.autoClose = false; // Automatically closes the path
  11927. };
  11928. THREE.CurvePath.prototype = new THREE.Curve();
  11929. THREE.CurvePath.prototype.constructor = THREE.CurvePath;
  11930. THREE.CurvePath.prototype.add = function ( curve ) {
  11931. this.curves.push( curve );
  11932. };
  11933. THREE.CurvePath.prototype.checkConnection = function() {
  11934. // TODO
  11935. // If the ending of curve is not connected to the starting
  11936. // or the next curve, then, this is not a real path
  11937. };
  11938. THREE.CurvePath.prototype.closePath = function() {
  11939. // TODO Test
  11940. // and verify for vector3 (needs to implement equals)
  11941. // Add a line curve if start and end of lines are not connected
  11942. var startPoint = this.curves[0].getPoint(0);
  11943. var endPoint = this.curves[this.curves.length-1].getPoint(1);
  11944. if (!startPoint.equals(endPoint)) {
  11945. this.curves.push( new THREE.LineCurve(endPoint, startPoint) );
  11946. }
  11947. };
  11948. // To get accurate point with reference to
  11949. // entire path distance at time t,
  11950. // following has to be done:
  11951. // 1. Length of each sub path have to be known
  11952. // 2. Locate and identify type of curve
  11953. // 3. Get t for the curve
  11954. // 4. Return curve.getPointAt(t')
  11955. THREE.CurvePath.prototype.getPoint = function( t ) {
  11956. var d = t * this.getLength();
  11957. var curveLengths = this.getCurveLengths();
  11958. var i = 0, diff, curve;
  11959. // To think about boundaries points.
  11960. while ( i < curveLengths.length ) {
  11961. if ( curveLengths[ i ] >= d ) {
  11962. diff = curveLengths[ i ] - d;
  11963. curve = this.curves[ i ];
  11964. var u = 1 - diff / curve.getLength();
  11965. return curve.getPointAt( u );
  11966. break;
  11967. }
  11968. i ++;
  11969. }
  11970. return null;
  11971. // loop where sum != 0, sum > d , sum+1 <d
  11972. };
  11973. /*
  11974. THREE.CurvePath.prototype.getTangent = function( t ) {
  11975. };*/
  11976. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  11977. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  11978. // getPoint() depends on getLength
  11979. THREE.CurvePath.prototype.getLength = function() {
  11980. var lens = this.getCurveLengths();
  11981. return lens[ lens.length - 1 ];
  11982. };
  11983. // Compute lengths and cache them
  11984. // We cannot overwrite getLengths() because UtoT mapping uses it.
  11985. THREE.CurvePath.prototype.getCurveLengths = function() {
  11986. // We use cache values if curves and cache array are same length
  11987. if ( this.cacheLengths && this.cacheLengths.length == this.curves.length ) {
  11988. return this.cacheLengths;
  11989. };
  11990. // Get length of subsurve
  11991. // Push sums into cached array
  11992. var lengths = [], sums = 0;
  11993. var i, il = this.curves.length;
  11994. for ( i = 0; i < il; i ++ ) {
  11995. sums += this.curves[ i ].getLength();
  11996. lengths.push( sums );
  11997. }
  11998. this.cacheLengths = lengths;
  11999. return lengths;
  12000. };
  12001. // Returns min and max coordinates, as well as centroid
  12002. THREE.CurvePath.prototype.getBoundingBox = function () {
  12003. var points = this.getPoints();
  12004. var maxX, maxY;
  12005. var minX, minY;
  12006. maxX = maxY = Number.NEGATIVE_INFINITY;
  12007. minX = minY = Number.POSITIVE_INFINITY;
  12008. var p, i, il, sum;
  12009. sum = new THREE.Vector2();
  12010. for ( i = 0, il = points.length; i < il; i ++ ) {
  12011. p = points[ i ];
  12012. if ( p.x > maxX ) maxX = p.x;
  12013. else if ( p.x < minX ) minX = p.x;
  12014. if ( p.y > maxY ) maxY = p.y;
  12015. else if ( p.y < maxY ) minY = p.y;
  12016. sum.addSelf( p.x, p.y );
  12017. }
  12018. return {
  12019. minX: minX,
  12020. minY: minY,
  12021. maxX: maxX,
  12022. maxY: maxY,
  12023. centroid: sum.divideScalar( il )
  12024. };
  12025. };
  12026. /**************************************************************
  12027. * Create Geometries Helpers
  12028. **************************************************************/
  12029. /// Generate geometry from path points (for Line or ParticleSystem objects)
  12030. THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
  12031. var pts = this.getPoints( divisions, true );
  12032. return this.createGeometry( pts );
  12033. };
  12034. // Generate geometry from equidistance sampling along the path
  12035. THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
  12036. var pts = this.getSpacedPoints( divisions, true );
  12037. return this.createGeometry( pts );
  12038. };
  12039. THREE.CurvePath.prototype.createGeometry = function( points ) {
  12040. var geometry = new THREE.Geometry();
  12041. for ( var i = 0; i < points.length; i ++ ) {
  12042. geometry.vertices.push( new THREE.Vector3( points[ i ].x, points[ i ].y, 0 ) );
  12043. }
  12044. return geometry;
  12045. };
  12046. /**************************************************************
  12047. * Bend / Wrap Helper Methods
  12048. **************************************************************/
  12049. // Wrap path / Bend modifiers?
  12050. THREE.CurvePath.prototype.addWrapPath = function ( bendpath ) {
  12051. this.bends.push( bendpath );
  12052. };
  12053. THREE.CurvePath.prototype.getTransformedPoints = function( segments, bends ) {
  12054. var oldPts = this.getPoints( segments ); // getPoints getSpacedPoints
  12055. var i, il;
  12056. if ( !bends ) {
  12057. bends = this.bends;
  12058. }
  12059. for ( i = 0, il = bends.length; i < il; i ++ ) {
  12060. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  12061. }
  12062. return oldPts;
  12063. };
  12064. THREE.CurvePath.prototype.getTransformedSpacedPoints = function( segments, bends ) {
  12065. var oldPts = this.getSpacedPoints( segments );
  12066. var i, il;
  12067. if ( !bends ) {
  12068. bends = this.bends;
  12069. }
  12070. for ( i = 0, il = bends.length; i < il; i ++ ) {
  12071. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  12072. }
  12073. return oldPts;
  12074. };
  12075. // This returns getPoints() bend/wrapped around the contour of a path.
  12076. // Read http://www.planetclegg.com/projects/WarpingTextToSplines.html
  12077. THREE.CurvePath.prototype.getWrapPoints = function ( oldPts, path ) {
  12078. var bounds = this.getBoundingBox();
  12079. var i, il, p, oldX, oldY, xNorm;
  12080. for ( i = 0, il = oldPts.length; i < il; i ++ ) {
  12081. p = oldPts[ i ];
  12082. oldX = p.x;
  12083. oldY = p.y;
  12084. xNorm = oldX / bounds.maxX;
  12085. // If using actual distance, for length > path, requires line extrusions
  12086. //xNorm = path.getUtoTmapping(xNorm, oldX); // 3 styles. 1) wrap stretched. 2) wrap stretch by arc length 3) warp by actual distance
  12087. xNorm = path.getUtoTmapping( xNorm, oldX );
  12088. // check for out of bounds?
  12089. var pathPt = path.getPoint( xNorm );
  12090. var normal = path.getNormalVector( xNorm ).multiplyScalar( oldY );
  12091. p.x = pathPt.x + normal.x;
  12092. p.y = pathPt.y + normal.y;
  12093. }
  12094. return oldPts;
  12095. };
  12096. /**
  12097. * https://github.com/mrdoob/eventtarget.js/
  12098. */
  12099. THREE.EventTarget = function () {
  12100. var listeners = {};
  12101. this.addEventListener = function ( type, listener ) {
  12102. if ( listeners[ type ] == undefined ) {
  12103. listeners[ type ] = [];
  12104. }
  12105. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  12106. listeners[ type ].push( listener );
  12107. }
  12108. };
  12109. this.dispatchEvent = function ( event ) {
  12110. for ( var listener in listeners[ event.type ] ) {
  12111. listeners[ event.type ][ listener ]( event );
  12112. }
  12113. };
  12114. this.removeEventListener = function ( type, listener ) {
  12115. var index = listeners[ type ].indexOf( listener );
  12116. if ( index !== - 1 ) {
  12117. listeners[ type ].splice( index, 1 );
  12118. }
  12119. };
  12120. };
  12121. /**
  12122. * @author alteredq / http://alteredqualia.com/
  12123. */
  12124. THREE.Gyroscope = function () {
  12125. THREE.Object3D.call( this );
  12126. };
  12127. THREE.Gyroscope.prototype = new THREE.Object3D();
  12128. THREE.Gyroscope.prototype.constructor = THREE.Gyroscope;
  12129. THREE.Gyroscope.prototype.updateMatrixWorld = function ( force ) {
  12130. this.matrixAutoUpdate && this.updateMatrix();
  12131. // update matrixWorld
  12132. if ( this.matrixWorldNeedsUpdate || force ) {
  12133. if ( this.parent ) {
  12134. this.matrixWorld.multiply( this.parent.matrixWorld, this.matrix );
  12135. this.matrixWorld.decompose( this.translationWorld, this.rotationWorld, this.scaleWorld );
  12136. this.matrix.decompose( this.translationObject, this.rotationObject, this.scaleObject );
  12137. this.matrixWorld.compose( this.translationWorld, this.rotationObject, this.scaleWorld );
  12138. } else {
  12139. this.matrixWorld.copy( this.matrix );
  12140. }
  12141. this.matrixWorldNeedsUpdate = false;
  12142. force = true;
  12143. }
  12144. // update children
  12145. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  12146. this.children[ i ].updateMatrixWorld( force );
  12147. }
  12148. };
  12149. THREE.Gyroscope.prototype.translationWorld = new THREE.Vector3();
  12150. THREE.Gyroscope.prototype.translationObject = new THREE.Vector3();
  12151. THREE.Gyroscope.prototype.rotationWorld = new THREE.Quaternion();
  12152. THREE.Gyroscope.prototype.rotationObject = new THREE.Quaternion();
  12153. THREE.Gyroscope.prototype.scaleWorld = new THREE.Vector3();
  12154. THREE.Gyroscope.prototype.scaleObject = new THREE.Vector3();
  12155. /**
  12156. * @author zz85 / http://www.lab4games.net/zz85/blog
  12157. * Creates free form 2d path using series of points, lines or curves.
  12158. *
  12159. **/
  12160. THREE.Path = function ( points ) {
  12161. THREE.CurvePath.call(this);
  12162. this.actions = [];
  12163. if ( points ) {
  12164. this.fromPoints( points );
  12165. }
  12166. };
  12167. THREE.Path.prototype = new THREE.CurvePath();
  12168. THREE.Path.prototype.constructor = THREE.Path;
  12169. THREE.PathActions = {
  12170. MOVE_TO: 'moveTo',
  12171. LINE_TO: 'lineTo',
  12172. QUADRATIC_CURVE_TO: 'quadraticCurveTo', // Bezier quadratic curve
  12173. BEZIER_CURVE_TO: 'bezierCurveTo', // Bezier cubic curve
  12174. CSPLINE_THRU: 'splineThru', // Catmull-rom spline
  12175. ARC: 'arc' // Circle
  12176. };
  12177. // TODO Clean up PATH API
  12178. // Create path using straight lines to connect all points
  12179. // - vectors: array of Vector2
  12180. THREE.Path.prototype.fromPoints = function ( vectors ) {
  12181. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  12182. for ( var v = 1, vlen = vectors.length; v < vlen; v ++ ) {
  12183. this.lineTo( vectors[ v ].x, vectors[ v ].y );
  12184. };
  12185. };
  12186. // startPath() endPath()?
  12187. THREE.Path.prototype.moveTo = function ( x, y ) {
  12188. var args = Array.prototype.slice.call( arguments );
  12189. this.actions.push( { action: THREE.PathActions.MOVE_TO, args: args } );
  12190. };
  12191. THREE.Path.prototype.lineTo = function ( x, y ) {
  12192. var args = Array.prototype.slice.call( arguments );
  12193. var lastargs = this.actions[ this.actions.length - 1 ].args;
  12194. var x0 = lastargs[ lastargs.length - 2 ];
  12195. var y0 = lastargs[ lastargs.length - 1 ];
  12196. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  12197. this.curves.push( curve );
  12198. this.actions.push( { action: THREE.PathActions.LINE_TO, args: args } );
  12199. };
  12200. THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
  12201. var args = Array.prototype.slice.call( arguments );
  12202. var lastargs = this.actions[ this.actions.length - 1 ].args;
  12203. var x0 = lastargs[ lastargs.length - 2 ];
  12204. var y0 = lastargs[ lastargs.length - 1 ];
  12205. var curve = new THREE.QuadraticBezierCurve( new THREE.Vector2( x0, y0 ),
  12206. new THREE.Vector2( aCPx, aCPy ),
  12207. new THREE.Vector2( aX, aY ) );
  12208. this.curves.push( curve );
  12209. this.actions.push( { action: THREE.PathActions.QUADRATIC_CURVE_TO, args: args } );
  12210. };
  12211. THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y,
  12212. aCP2x, aCP2y,
  12213. aX, aY ) {
  12214. var args = Array.prototype.slice.call( arguments );
  12215. var lastargs = this.actions[ this.actions.length - 1 ].args;
  12216. var x0 = lastargs[ lastargs.length - 2 ];
  12217. var y0 = lastargs[ lastargs.length - 1 ];
  12218. var curve = new THREE.CubicBezierCurve( new THREE.Vector2( x0, y0 ),
  12219. new THREE.Vector2( aCP1x, aCP1y ),
  12220. new THREE.Vector2( aCP2x, aCP2y ),
  12221. new THREE.Vector2( aX, aY ) );
  12222. this.curves.push( curve );
  12223. this.actions.push( { action: THREE.PathActions.BEZIER_CURVE_TO, args: args } );
  12224. };
  12225. THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
  12226. var args = Array.prototype.slice.call( arguments );
  12227. var lastargs = this.actions[ this.actions.length - 1 ].args;
  12228. var x0 = lastargs[ lastargs.length - 2 ];
  12229. var y0 = lastargs[ lastargs.length - 1 ];
  12230. //---
  12231. var npts = [ new THREE.Vector2( x0, y0 ) ];
  12232. Array.prototype.push.apply( npts, pts );
  12233. var curve = new THREE.SplineCurve( npts );
  12234. this.curves.push( curve );
  12235. this.actions.push( { action: THREE.PathActions.CSPLINE_THRU, args: args } );
  12236. };
  12237. // FUTURE: Change the API or follow canvas API?
  12238. // TODO ARC ( x, y, x - radius, y - radius, startAngle, endAngle )
  12239. THREE.Path.prototype.arc = function ( aX, aY, aRadius,
  12240. aStartAngle, aEndAngle, aClockwise ) {
  12241. var args = Array.prototype.slice.call( arguments );
  12242. var laste = this.actions[ this.actions.length - 1];
  12243. var curve = new THREE.ArcCurve( laste.x + aX, laste.y + aY, aRadius,
  12244. aStartAngle, aEndAngle, aClockwise );
  12245. this.curves.push( curve );
  12246. // All of the other actions look to the last two elements in the list to
  12247. // find the ending point, so we need to append them.
  12248. var lastPoint = curve.getPoint(aClockwise ? 1 : 0);
  12249. args.push(lastPoint.x);
  12250. args.push(lastPoint.y);
  12251. this.actions.push( { action: THREE.PathActions.ARC, args: args } );
  12252. };
  12253. THREE.Path.prototype.absarc = function ( aX, aY, aRadius,
  12254. aStartAngle, aEndAngle, aClockwise ) {
  12255. var args = Array.prototype.slice.call( arguments );
  12256. var curve = new THREE.ArcCurve( aX, aY, aRadius,
  12257. aStartAngle, aEndAngle, aClockwise );
  12258. this.curves.push( curve );
  12259. // console.log( 'arc', args );
  12260. // All of the other actions look to the last two elements in the list to
  12261. // find the ending point, so we need to append them.
  12262. var lastPoint = curve.getPoint(aClockwise ? 1 : 0);
  12263. args.push(lastPoint.x);
  12264. args.push(lastPoint.y);
  12265. this.actions.push( { action: THREE.PathActions.ARC, args: args } );
  12266. };
  12267. THREE.Path.prototype.getSpacedPoints = function ( divisions, closedPath ) {
  12268. if ( ! divisions ) divisions = 40;
  12269. var points = [];
  12270. for ( var i = 0; i < divisions; i ++ ) {
  12271. points.push( this.getPoint( i / divisions ) );
  12272. //if( !this.getPoint( i / divisions ) ) throw "DIE";
  12273. }
  12274. // if ( closedPath ) {
  12275. //
  12276. // points.push( points[ 0 ] );
  12277. //
  12278. // }
  12279. return points;
  12280. };
  12281. /* Return an array of vectors based on contour of the path */
  12282. THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
  12283. if (this.useSpacedPoints) {
  12284. console.log('tata');
  12285. return this.getSpacedPoints( divisions, closedPath );
  12286. }
  12287. divisions = divisions || 12;
  12288. var points = [];
  12289. var i, il, item, action, args;
  12290. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  12291. laste, j,
  12292. t, tx, ty;
  12293. for ( i = 0, il = this.actions.length; i < il; i ++ ) {
  12294. item = this.actions[ i ];
  12295. action = item.action;
  12296. args = item.args;
  12297. switch( action ) {
  12298. case THREE.PathActions.MOVE_TO:
  12299. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  12300. break;
  12301. case THREE.PathActions.LINE_TO:
  12302. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  12303. break;
  12304. case THREE.PathActions.QUADRATIC_CURVE_TO:
  12305. cpx = args[ 2 ];
  12306. cpy = args[ 3 ];
  12307. cpx1 = args[ 0 ];
  12308. cpy1 = args[ 1 ];
  12309. if ( points.length > 0 ) {
  12310. laste = points[ points.length - 1 ];
  12311. cpx0 = laste.x;
  12312. cpy0 = laste.y;
  12313. } else {
  12314. laste = this.actions[ i - 1 ].args;
  12315. cpx0 = laste[ laste.length - 2 ];
  12316. cpy0 = laste[ laste.length - 1 ];
  12317. }
  12318. for ( j = 1; j <= divisions; j ++ ) {
  12319. t = j / divisions;
  12320. tx = THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  12321. ty = THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  12322. points.push( new THREE.Vector2( tx, ty ) );
  12323. }
  12324. break;
  12325. case THREE.PathActions.BEZIER_CURVE_TO:
  12326. cpx = args[ 4 ];
  12327. cpy = args[ 5 ];
  12328. cpx1 = args[ 0 ];
  12329. cpy1 = args[ 1 ];
  12330. cpx2 = args[ 2 ];
  12331. cpy2 = args[ 3 ];
  12332. if ( points.length > 0 ) {
  12333. laste = points[ points.length - 1 ];
  12334. cpx0 = laste.x;
  12335. cpy0 = laste.y;
  12336. } else {
  12337. laste = this.actions[ i - 1 ].args;
  12338. cpx0 = laste[ laste.length - 2 ];
  12339. cpy0 = laste[ laste.length - 1 ];
  12340. }
  12341. for ( j = 1; j <= divisions; j ++ ) {
  12342. t = j / divisions;
  12343. tx = THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  12344. ty = THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  12345. points.push( new THREE.Vector2( tx, ty ) );
  12346. }
  12347. break;
  12348. case THREE.PathActions.CSPLINE_THRU:
  12349. laste = this.actions[ i - 1 ].args;
  12350. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  12351. var spts = [ last ];
  12352. var n = divisions * args[ 0 ].length;
  12353. spts = spts.concat( args[ 0 ] );
  12354. var spline = new THREE.SplineCurve( spts );
  12355. for ( j = 1; j <= n; j ++ ) {
  12356. points.push( spline.getPointAt( j / n ) ) ;
  12357. }
  12358. break;
  12359. case THREE.PathActions.ARC:
  12360. laste = this.actions[ i - 1 ].args;
  12361. var aX = args[ 0 ], aY = args[ 1 ],
  12362. aRadius = args[ 2 ],
  12363. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  12364. aClockwise = !!args[ 5 ];
  12365. var deltaAngle = aEndAngle - aStartAngle;
  12366. var angle;
  12367. var tdivisions = divisions * 2;
  12368. for ( j = 1; j <= tdivisions; j ++ ) {
  12369. t = j / tdivisions;
  12370. if ( ! aClockwise ) {
  12371. t = 1 - t;
  12372. }
  12373. angle = aStartAngle + t * deltaAngle;
  12374. tx = aX + aRadius * Math.cos( angle );
  12375. ty = aY + aRadius * Math.sin( angle );
  12376. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  12377. points.push( new THREE.Vector2( tx, ty ) );
  12378. }
  12379. //console.log(points);
  12380. break;
  12381. } // end switch
  12382. }
  12383. // Normalize to remove the closing point by default.
  12384. var lastPoint = points[ points.length - 1];
  12385. var EPSILON = 0.0000000001;
  12386. if ( Math.abs(lastPoint.x - points[ 0 ].x) < EPSILON &&
  12387. Math.abs(lastPoint.y - points[ 0 ].y) < EPSILON)
  12388. points.splice( points.length - 1, 1);
  12389. if ( closedPath ) {
  12390. points.push( points[ 0 ] );
  12391. }
  12392. return points;
  12393. };
  12394. // This was used for testing purposes. Should be removed soon.
  12395. THREE.Path.prototype.transform = function( path, segments ) {
  12396. var bounds = this.getBoundingBox();
  12397. var oldPts = this.getPoints( segments ); // getPoints getSpacedPoints
  12398. //console.log( path.cacheArcLengths() );
  12399. //path.getLengths(400);
  12400. //segments = 40;
  12401. return this.getWrapPoints( oldPts, path );
  12402. };
  12403. // Read http://www.tinaja.com/glib/nonlingr.pdf
  12404. // nonlinear transforms
  12405. THREE.Path.prototype.nltransform = function( a, b, c, d, e, f ) {
  12406. // a - horizontal size
  12407. // b - lean
  12408. // c - x offset
  12409. // d - vertical size
  12410. // e - climb
  12411. // f - y offset
  12412. var oldPts = this.getPoints();
  12413. var i, il, p, oldX, oldY;
  12414. for ( i = 0, il = oldPts.length; i < il; i ++ ) {
  12415. p = oldPts[i];
  12416. oldX = p.x;
  12417. oldY = p.y;
  12418. p.x = a * oldX + b * oldY + c;
  12419. p.y = d * oldY + e * oldX + f;
  12420. }
  12421. return oldPts;
  12422. };
  12423. // FUTURE Export JSON Format
  12424. /* Draws this path onto a 2d canvas easily */
  12425. THREE.Path.prototype.debug = function( canvas ) {
  12426. var bounds = this.getBoundingBox();
  12427. if ( !canvas ) {
  12428. canvas = document.createElement( "canvas" );
  12429. canvas.setAttribute( 'width', bounds.maxX + 100 );
  12430. canvas.setAttribute( 'height', bounds.maxY + 100 );
  12431. document.body.appendChild( canvas );
  12432. }
  12433. var ctx = canvas.getContext( "2d" );
  12434. ctx.fillStyle = "white";
  12435. ctx.fillRect( 0, 0, canvas.width, canvas.height );
  12436. ctx.strokeStyle = "black";
  12437. ctx.beginPath();
  12438. var i, il, item, action, args;
  12439. // Debug Path
  12440. for ( i = 0, il = this.actions.length; i < il; i ++ ) {
  12441. item = this.actions[ i ];
  12442. args = item.args;
  12443. action = item.action;
  12444. // Short hand for now
  12445. if ( action != THREE.PathActions.CSPLINE_THRU ) {
  12446. ctx[ action ].apply( ctx, args );
  12447. }
  12448. /*
  12449. switch ( action ) {
  12450. case THREE.PathActions.MOVE_TO:
  12451. ctx[ action ]( args[ 0 ], args[ 1 ] );
  12452. break;
  12453. case THREE.PathActions.LINE_TO:
  12454. ctx[ action ]( args[ 0 ], args[ 1 ] );
  12455. break;
  12456. case THREE.PathActions.QUADRATIC_CURVE_TO:
  12457. ctx[ action ]( args[ 0 ], args[ 1 ], args[ 2 ], args[ 3 ] );
  12458. break;
  12459. case THREE.PathActions.CUBIC_CURVE_TO:
  12460. ctx[ action ]( args[ 0 ], args[ 1 ], args[ 2 ], args[ 3 ], args[ 4 ], args[ 5 ] );
  12461. break;
  12462. }
  12463. */
  12464. }
  12465. ctx.stroke();
  12466. ctx.closePath();
  12467. // Debug Points
  12468. ctx.strokeStyle = "red";
  12469. /* TO CLEAN UP */
  12470. var p, points = this.getPoints();
  12471. for ( i = 0, il = points.length; i < il; i ++ ) {
  12472. p = points[ i ];
  12473. ctx.beginPath();
  12474. ctx.arc( p.x, p.y, 1.5, 0, Math.PI * 2, false );
  12475. ctx.stroke();
  12476. ctx.closePath();
  12477. }
  12478. };
  12479. // Breaks path into shapes
  12480. THREE.Path.prototype.toShapes = function() {
  12481. var i, il, item, action, args;
  12482. var subPaths = [], lastPath = new THREE.Path();
  12483. for ( i = 0, il = this.actions.length; i < il; i ++ ) {
  12484. item = this.actions[ i ];
  12485. args = item.args;
  12486. action = item.action;
  12487. if ( action == THREE.PathActions.MOVE_TO ) {
  12488. if ( lastPath.actions.length != 0 ) {
  12489. subPaths.push( lastPath );
  12490. lastPath = new THREE.Path();
  12491. }
  12492. }
  12493. lastPath[ action ].apply( lastPath, args );
  12494. }
  12495. if ( lastPath.actions.length != 0 ) {
  12496. subPaths.push( lastPath );
  12497. }
  12498. // console.log(subPaths);
  12499. if ( subPaths.length == 0 ) return [];
  12500. var tmpPath, tmpShape, shapes = [];
  12501. var holesFirst = !THREE.Shape.Utils.isClockWise( subPaths[ 0 ].getPoints() );
  12502. // console.log("Holes first", holesFirst);
  12503. if ( subPaths.length == 1) {
  12504. tmpPath = subPaths[0];
  12505. tmpShape = new THREE.Shape();
  12506. tmpShape.actions = tmpPath.actions;
  12507. tmpShape.curves = tmpPath.curves;
  12508. shapes.push( tmpShape );
  12509. return shapes;
  12510. };
  12511. if ( holesFirst ) {
  12512. tmpShape = new THREE.Shape();
  12513. for ( i = 0, il = subPaths.length; i < il; i ++ ) {
  12514. tmpPath = subPaths[ i ];
  12515. if ( THREE.Shape.Utils.isClockWise( tmpPath.getPoints() ) ) {
  12516. tmpShape.actions = tmpPath.actions;
  12517. tmpShape.curves = tmpPath.curves;
  12518. shapes.push( tmpShape );
  12519. tmpShape = new THREE.Shape();
  12520. //console.log('cw', i);
  12521. } else {
  12522. tmpShape.holes.push( tmpPath );
  12523. //console.log('ccw', i);
  12524. }
  12525. }
  12526. } else {
  12527. // Shapes first
  12528. for ( i = 0, il = subPaths.length; i < il; i ++ ) {
  12529. tmpPath = subPaths[ i ];
  12530. if ( THREE.Shape.Utils.isClockWise( tmpPath.getPoints() ) ) {
  12531. if ( tmpShape ) shapes.push( tmpShape );
  12532. tmpShape = new THREE.Shape();
  12533. tmpShape.actions = tmpPath.actions;
  12534. tmpShape.curves = tmpPath.curves;
  12535. } else {
  12536. tmpShape.holes.push( tmpPath );
  12537. }
  12538. }
  12539. shapes.push( tmpShape );
  12540. }
  12541. //console.log("shape", shapes);
  12542. return shapes;
  12543. };
  12544. /**
  12545. * @author zz85 / http://www.lab4games.net/zz85/blog
  12546. * Defines a 2d shape plane using paths.
  12547. **/
  12548. // STEP 1 Create a path.
  12549. // STEP 2 Turn path into shape.
  12550. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  12551. // STEP 3a - Extract points from each shape, turn to vertices
  12552. // STEP 3b - Triangulate each shape, add faces.
  12553. THREE.Shape = function ( ) {
  12554. THREE.Path.apply( this, arguments );
  12555. this.holes = [];
  12556. };
  12557. THREE.Shape.prototype = new THREE.Path();
  12558. THREE.Shape.prototype.constructor = THREE.Path;
  12559. // Convenience method to return ExtrudeGeometry
  12560. THREE.Shape.prototype.extrude = function ( options ) {
  12561. var extruded = new THREE.ExtrudeGeometry( this, options );
  12562. return extruded;
  12563. };
  12564. // Get points of holes
  12565. THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
  12566. var i, il = this.holes.length, holesPts = [];
  12567. for ( i = 0; i < il; i ++ ) {
  12568. holesPts[ i ] = this.holes[ i ].getTransformedPoints( divisions, this.bends );
  12569. }
  12570. return holesPts;
  12571. };
  12572. // Get points of holes (spaced by regular distance)
  12573. THREE.Shape.prototype.getSpacedPointsHoles = function ( divisions ) {
  12574. var i, il = this.holes.length, holesPts = [];
  12575. for ( i = 0; i < il; i ++ ) {
  12576. holesPts[ i ] = this.holes[ i ].getTransformedSpacedPoints( divisions, this.bends );
  12577. }
  12578. return holesPts;
  12579. };
  12580. // Get points of shape and holes (keypoints based on segments parameter)
  12581. THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
  12582. return {
  12583. shape: this.getTransformedPoints( divisions ),
  12584. holes: this.getPointsHoles( divisions )
  12585. };
  12586. };
  12587. THREE.Shape.prototype.extractPoints = function ( divisions ) {
  12588. if (this.useSpacedPoints) {
  12589. return this.extractAllSpacedPoints(divisions);
  12590. }
  12591. return this.extractAllPoints(divisions);
  12592. };
  12593. //
  12594. // THREE.Shape.prototype.extractAllPointsWithBend = function ( divisions, bend ) {
  12595. //
  12596. // return {
  12597. //
  12598. // shape: this.transform( bend, divisions ),
  12599. // holes: this.getPointsHoles( divisions, bend )
  12600. //
  12601. // };
  12602. //
  12603. // };
  12604. // Get points of shape and holes (spaced by regular distance)
  12605. THREE.Shape.prototype.extractAllSpacedPoints = function ( divisions ) {
  12606. return {
  12607. shape: this.getTransformedSpacedPoints( divisions ),
  12608. holes: this.getSpacedPointsHoles( divisions )
  12609. };
  12610. };
  12611. /**************************************************************
  12612. * Utils
  12613. **************************************************************/
  12614. THREE.Shape.Utils = {
  12615. /*
  12616. contour - array of vector2 for contour
  12617. holes - array of array of vector2
  12618. */
  12619. removeHoles: function ( contour, holes ) {
  12620. var shape = contour.concat(); // work on this shape
  12621. var allpoints = shape.concat();
  12622. /* For each isolated shape, find the closest points and break to the hole to allow triangulation */
  12623. var prevShapeVert, nextShapeVert,
  12624. prevHoleVert, nextHoleVert,
  12625. holeIndex, shapeIndex,
  12626. shapeId, shapeGroup,
  12627. h, h2,
  12628. hole, shortest, d,
  12629. p, pts1, pts2,
  12630. tmpShape1, tmpShape2,
  12631. tmpHole1, tmpHole2,
  12632. verts = [];
  12633. for ( h = 0; h < holes.length; h ++ ) {
  12634. hole = holes[ h ];
  12635. /*
  12636. shapeholes[ h ].concat(); // preserves original
  12637. holes.push( hole );
  12638. */
  12639. Array.prototype.push.apply( allpoints, hole );
  12640. shortest = Number.POSITIVE_INFINITY;
  12641. // Find the shortest pair of pts between shape and hole
  12642. // Note: Actually, I'm not sure now if we could optimize this to be faster than O(m*n)
  12643. // Using distanceToSquared() intead of distanceTo() should speed a little
  12644. // since running square roots operations are reduced.
  12645. for ( h2 = 0; h2 < hole.length; h2 ++ ) {
  12646. pts1 = hole[ h2 ];
  12647. var dist = [];
  12648. for ( p = 0; p < shape.length; p++ ) {
  12649. pts2 = shape[ p ];
  12650. d = pts1.distanceToSquared( pts2 );
  12651. dist.push( d );
  12652. if ( d < shortest ) {
  12653. shortest = d;
  12654. holeIndex = h2;
  12655. shapeIndex = p;
  12656. }
  12657. }
  12658. }
  12659. //console.log("shortest", shortest, dist);
  12660. prevShapeVert = ( shapeIndex - 1 ) >= 0 ? shapeIndex - 1 : shape.length - 1;
  12661. prevHoleVert = ( holeIndex - 1 ) >= 0 ? holeIndex - 1 : hole.length - 1;
  12662. var areaapts = [
  12663. hole[ holeIndex ],
  12664. shape[ shapeIndex ],
  12665. shape[ prevShapeVert ]
  12666. ];
  12667. var areaa = THREE.FontUtils.Triangulate.area( areaapts );
  12668. var areabpts = [
  12669. hole[ holeIndex ],
  12670. hole[ prevHoleVert ],
  12671. shape[ shapeIndex ]
  12672. ];
  12673. var areab = THREE.FontUtils.Triangulate.area( areabpts );
  12674. var shapeOffset = 1;
  12675. var holeOffset = -1;
  12676. var oldShapeIndex = shapeIndex, oldHoleIndex = holeIndex;
  12677. shapeIndex += shapeOffset;
  12678. holeIndex += holeOffset;
  12679. if ( shapeIndex < 0 ) { shapeIndex += shape.length; }
  12680. shapeIndex %= shape.length;
  12681. if ( holeIndex < 0 ) { holeIndex += hole.length; }
  12682. holeIndex %= hole.length;
  12683. prevShapeVert = ( shapeIndex - 1 ) >= 0 ? shapeIndex - 1 : shape.length - 1;
  12684. prevHoleVert = ( holeIndex - 1 ) >= 0 ? holeIndex - 1 : hole.length - 1;
  12685. areaapts = [
  12686. hole[ holeIndex ],
  12687. shape[ shapeIndex ],
  12688. shape[ prevShapeVert ]
  12689. ];
  12690. var areaa2 = THREE.FontUtils.Triangulate.area( areaapts );
  12691. areabpts = [
  12692. hole[ holeIndex ],
  12693. hole[ prevHoleVert ],
  12694. shape[ shapeIndex ]
  12695. ];
  12696. var areab2 = THREE.FontUtils.Triangulate.area( areabpts );
  12697. //console.log(areaa,areab ,areaa2,areab2, ( areaa + areab ), ( areaa2 + areab2 ));
  12698. if ( ( areaa + areab ) > ( areaa2 + areab2 ) ) {
  12699. // In case areas are not correct.
  12700. //console.log("USE THIS");
  12701. shapeIndex = oldShapeIndex;
  12702. holeIndex = oldHoleIndex ;
  12703. if ( shapeIndex < 0 ) { shapeIndex += shape.length; }
  12704. shapeIndex %= shape.length;
  12705. if ( holeIndex < 0 ) { holeIndex += hole.length; }
  12706. holeIndex %= hole.length;
  12707. prevShapeVert = ( shapeIndex - 1 ) >= 0 ? shapeIndex - 1 : shape.length - 1;
  12708. prevHoleVert = ( holeIndex - 1 ) >= 0 ? holeIndex - 1 : hole.length - 1;
  12709. } else {
  12710. //console.log("USE THAT ")
  12711. }
  12712. tmpShape1 = shape.slice( 0, shapeIndex );
  12713. tmpShape2 = shape.slice( shapeIndex );
  12714. tmpHole1 = hole.slice( holeIndex );
  12715. tmpHole2 = hole.slice( 0, holeIndex );
  12716. // Should check orders here again?
  12717. var trianglea = [
  12718. hole[ holeIndex ],
  12719. shape[ shapeIndex ],
  12720. shape[ prevShapeVert ]
  12721. ];
  12722. var triangleb = [
  12723. hole[ holeIndex ] ,
  12724. hole[ prevHoleVert ],
  12725. shape[ shapeIndex ]
  12726. ];
  12727. verts.push( trianglea );
  12728. verts.push( triangleb );
  12729. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  12730. }
  12731. return {
  12732. shape:shape, /* shape with no holes */
  12733. isolatedPts: verts, /* isolated faces */
  12734. allpoints: allpoints
  12735. }
  12736. },
  12737. triangulateShape: function ( contour, holes ) {
  12738. var shapeWithoutHoles = THREE.Shape.Utils.removeHoles( contour, holes );
  12739. var shape = shapeWithoutHoles.shape,
  12740. allpoints = shapeWithoutHoles.allpoints,
  12741. isolatedPts = shapeWithoutHoles.isolatedPts;
  12742. var triangles = THREE.FontUtils.Triangulate( shape, false ); // True returns indices for points of spooled shape
  12743. // To maintain reference to old shape, one must match coordinates, or offset the indices from original arrays. It's probably easier to do the first.
  12744. //console.log( "triangles",triangles, triangles.length );
  12745. //console.log( "allpoints",allpoints, allpoints.length );
  12746. var i, il, f, face,
  12747. key, index,
  12748. allPointsMap = {},
  12749. isolatedPointsMap = {};
  12750. // prepare all points map
  12751. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  12752. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  12753. if ( allPointsMap[ key ] !== undefined ) {
  12754. console.log( "Duplicate point", key );
  12755. }
  12756. allPointsMap[ key ] = i;
  12757. }
  12758. // check all face vertices against all points map
  12759. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  12760. face = triangles[ i ];
  12761. for ( f = 0; f < 3; f ++ ) {
  12762. key = face[ f ].x + ":" + face[ f ].y;
  12763. index = allPointsMap[ key ];
  12764. if ( index !== undefined ) {
  12765. face[ f ] = index;
  12766. }
  12767. }
  12768. }
  12769. // check isolated points vertices against all points map
  12770. for ( i = 0, il = isolatedPts.length; i < il; i ++ ) {
  12771. face = isolatedPts[ i ];
  12772. for ( f = 0; f < 3; f ++ ) {
  12773. key = face[ f ].x + ":" + face[ f ].y;
  12774. index = allPointsMap[ key ];
  12775. if ( index !== undefined ) {
  12776. face[ f ] = index;
  12777. }
  12778. }
  12779. }
  12780. return triangles.concat( isolatedPts );
  12781. }, // end triangulate shapes
  12782. /*
  12783. triangulate2 : function( pts, holes ) {
  12784. // For use with Poly2Tri.js
  12785. var allpts = pts.concat();
  12786. var shape = [];
  12787. for (var p in pts) {
  12788. shape.push(new js.poly2tri.Point(pts[p].x, pts[p].y));
  12789. }
  12790. var swctx = new js.poly2tri.SweepContext(shape);
  12791. for (var h in holes) {
  12792. var aHole = holes[h];
  12793. var newHole = []
  12794. for (i in aHole) {
  12795. newHole.push(new js.poly2tri.Point(aHole[i].x, aHole[i].y));
  12796. allpts.push(aHole[i]);
  12797. }
  12798. swctx.AddHole(newHole);
  12799. }
  12800. var find;
  12801. var findIndexForPt = function (pt) {
  12802. find = new THREE.Vector2(pt.x, pt.y);
  12803. var p;
  12804. for (p=0, pl = allpts.length; p<pl; p++) {
  12805. if (allpts[p].equals(find)) return p;
  12806. }
  12807. return -1;
  12808. };
  12809. // triangulate
  12810. js.poly2tri.sweep.Triangulate(swctx);
  12811. var triangles = swctx.GetTriangles();
  12812. var tr ;
  12813. var facesPts = [];
  12814. for (var t in triangles) {
  12815. tr = triangles[t];
  12816. facesPts.push([
  12817. findIndexForPt(tr.GetPoint(0)),
  12818. findIndexForPt(tr.GetPoint(1)),
  12819. findIndexForPt(tr.GetPoint(2))
  12820. ]);
  12821. }
  12822. // console.log(facesPts);
  12823. // console.log("triangles", triangles.length, triangles);
  12824. // Returns array of faces with 3 element each
  12825. return facesPts;
  12826. },
  12827. */
  12828. isClockWise: function ( pts ) {
  12829. return THREE.FontUtils.Triangulate.area( pts ) < 0;
  12830. },
  12831. // Bezier Curves formulas obtained from
  12832. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  12833. // Quad Bezier Functions
  12834. b2p0: function ( t, p ) {
  12835. var k = 1 - t;
  12836. return k * k * p;
  12837. },
  12838. b2p1: function ( t, p ) {
  12839. return 2 * ( 1 - t ) * t * p;
  12840. },
  12841. b2p2: function ( t, p ) {
  12842. return t * t * p;
  12843. },
  12844. b2: function ( t, p0, p1, p2 ) {
  12845. return this.b2p0( t, p0 ) + this.b2p1( t, p1 ) + this.b2p2( t, p2 );
  12846. },
  12847. // Cubic Bezier Functions
  12848. b3p0: function ( t, p ) {
  12849. var k = 1 - t;
  12850. return k * k * k * p;
  12851. },
  12852. b3p1: function ( t, p ) {
  12853. var k = 1 - t;
  12854. return 3 * k * k * t * p;
  12855. },
  12856. b3p2: function ( t, p ) {
  12857. var k = 1 - t;
  12858. return 3 * k * t * t * p;
  12859. },
  12860. b3p3: function ( t, p ) {
  12861. return t * t * t * p;
  12862. },
  12863. b3: function ( t, p0, p1, p2, p3 ) {
  12864. return this.b3p0( t, p0 ) + this.b3p1( t, p1 ) + this.b3p2( t, p2 ) + this.b3p3( t, p3 );
  12865. }
  12866. };
  12867. /**
  12868. * @author zz85 / http://www.lab4games.net/zz85/blog
  12869. *
  12870. * TextPath
  12871. *
  12872. **/
  12873. THREE.TextPath = function ( text, parameters ) {
  12874. THREE.Path.call( this );
  12875. this.parameters = parameters || {};
  12876. this.set( text );
  12877. };
  12878. THREE.TextPath.prototype.set = function ( text, parameters ) {
  12879. parameters = parameters || this.parameters;
  12880. this.text = text;
  12881. var size = parameters.size !== undefined ? parameters.size : 100;
  12882. var curveSegments = parameters.curveSegments !== undefined ? parameters.curveSegments: 4;
  12883. var font = parameters.font !== undefined ? parameters.font : "helvetiker";
  12884. var weight = parameters.weight !== undefined ? parameters.weight : "normal";
  12885. var style = parameters.style !== undefined ? parameters.style : "normal";
  12886. THREE.FontUtils.size = size;
  12887. THREE.FontUtils.divisions = curveSegments;
  12888. THREE.FontUtils.face = font;
  12889. THREE.FontUtils.weight = weight;
  12890. THREE.FontUtils.style = style;
  12891. };
  12892. THREE.TextPath.prototype.toShapes = function () {
  12893. // Get a Font data json object
  12894. var data = THREE.FontUtils.drawText( this.text );
  12895. var paths = data.paths;
  12896. var shapes = [];
  12897. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  12898. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  12899. }
  12900. return shapes;
  12901. //console.log(path);
  12902. //console.log(fontShapes);
  12903. // Either find actions or curves.
  12904. //var text3d = new THREE.ExtrudeGeometry( shapes , { amount: 20, bevelEnabled:true, bevelThickness:3 } );
  12905. //return text3d;
  12906. };
  12907. /**
  12908. * @author mikael emtinger / http://gomo.se/
  12909. */
  12910. THREE.AnimationHandler = (function() {
  12911. var playing = [];
  12912. var library = {};
  12913. var that = {};
  12914. //--- update ---
  12915. that.update = function( deltaTimeMS ) {
  12916. for( var i = 0; i < playing.length; i++ )
  12917. playing[ i ].update( deltaTimeMS );
  12918. };
  12919. //--- add ---
  12920. that.addToUpdate = function( animation ) {
  12921. if( playing.indexOf( animation ) === -1 )
  12922. playing.push( animation );
  12923. };
  12924. //--- remove ---
  12925. that.removeFromUpdate = function( animation ) {
  12926. var index = playing.indexOf( animation );
  12927. if( index !== -1 )
  12928. playing.splice( index, 1 );
  12929. };
  12930. //--- add ---
  12931. that.add = function( data ) {
  12932. if( library[ data.name ] !== undefined )
  12933. console.log( "THREE.AnimationHandler.add: Warning! " + data.name + " already exists in library. Overwriting." );
  12934. library[ data.name ] = data;
  12935. initData( data );
  12936. };
  12937. //--- get ---
  12938. that.get = function( name ) {
  12939. if( typeof name === "string" ) {
  12940. if( library[ name ] ) {
  12941. return library[ name ];
  12942. } else {
  12943. console.log( "THREE.AnimationHandler.get: Couldn't find animation " + name );
  12944. return null;
  12945. }
  12946. } else {
  12947. // todo: add simple tween library
  12948. }
  12949. };
  12950. //--- parse ---
  12951. that.parse = function( root ) {
  12952. // setup hierarchy
  12953. var hierarchy = [];
  12954. if ( root instanceof THREE.SkinnedMesh ) {
  12955. for( var b = 0; b < root.bones.length; b++ ) {
  12956. hierarchy.push( root.bones[ b ] );
  12957. }
  12958. } else {
  12959. parseRecurseHierarchy( root, hierarchy );
  12960. }
  12961. return hierarchy;
  12962. };
  12963. var parseRecurseHierarchy = function( root, hierarchy ) {
  12964. hierarchy.push( root );
  12965. for( var c = 0; c < root.children.length; c++ )
  12966. parseRecurseHierarchy( root.children[ c ], hierarchy );
  12967. }
  12968. //--- init data ---
  12969. var initData = function( data ) {
  12970. if( data.initialized === true )
  12971. return;
  12972. // loop through all keys
  12973. for( var h = 0; h < data.hierarchy.length; h ++ ) {
  12974. for( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  12975. // remove minus times
  12976. if( data.hierarchy[ h ].keys[ k ].time < 0 )
  12977. data.hierarchy[ h ].keys[ k ].time = 0;
  12978. // create quaternions
  12979. if( data.hierarchy[ h ].keys[ k ].rot !== undefined &&
  12980. !( data.hierarchy[ h ].keys[ k ].rot instanceof THREE.Quaternion ) ) {
  12981. var quat = data.hierarchy[ h ].keys[ k ].rot;
  12982. data.hierarchy[ h ].keys[ k ].rot = new THREE.Quaternion( quat[0], quat[1], quat[2], quat[3] );
  12983. }
  12984. }
  12985. // prepare morph target keys
  12986. if( data.hierarchy[h].keys.length && data.hierarchy[ h ].keys[ 0 ].morphTargets !== undefined ) {
  12987. // get all used
  12988. var usedMorphTargets = {};
  12989. for( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  12990. for( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m ++ ) {
  12991. var morphTargetName = data.hierarchy[ h ].keys[ k ].morphTargets[ m ];
  12992. usedMorphTargets[ morphTargetName ] = -1;
  12993. }
  12994. }
  12995. data.hierarchy[ h ].usedMorphTargets = usedMorphTargets;
  12996. // set all used on all frames
  12997. for( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  12998. var influences = {};
  12999. for( var morphTargetName in usedMorphTargets ) {
  13000. for( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m ++ ) {
  13001. if( data.hierarchy[ h ].keys[ k ].morphTargets[ m ] === morphTargetName ) {
  13002. influences[ morphTargetName ] = data.hierarchy[ h ].keys[ k ].morphTargetsInfluences[ m ];
  13003. break;
  13004. }
  13005. }
  13006. if( m === data.hierarchy[ h ].keys[ k ].morphTargets.length ) {
  13007. influences[ morphTargetName ] = 0;
  13008. }
  13009. }
  13010. data.hierarchy[ h ].keys[ k ].morphTargetsInfluences = influences;
  13011. }
  13012. }
  13013. // remove all keys that are on the same time
  13014. for( var k = 1; k < data.hierarchy[ h ].keys.length; k ++ ) {
  13015. if( data.hierarchy[ h ].keys[ k ].time === data.hierarchy[ h ].keys[ k - 1 ].time ) {
  13016. data.hierarchy[ h ].keys.splice( k, 1 );
  13017. k --;
  13018. }
  13019. }
  13020. // set index
  13021. for( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  13022. data.hierarchy[ h ].keys[ k ].index = k;
  13023. }
  13024. }
  13025. // JIT
  13026. var lengthInFrames = parseInt( data.length * data.fps, 10 );
  13027. data.JIT = {};
  13028. data.JIT.hierarchy = [];
  13029. for( var h = 0; h < data.hierarchy.length; h ++ )
  13030. data.JIT.hierarchy.push( new Array( lengthInFrames ) );
  13031. // done
  13032. data.initialized = true;
  13033. };
  13034. // interpolation types
  13035. that.LINEAR = 0;
  13036. that.CATMULLROM = 1;
  13037. that.CATMULLROM_FORWARD = 2;
  13038. return that;
  13039. }());
  13040. /**
  13041. * @author mikael emtinger / http://gomo.se/
  13042. * @author mrdoob / http://mrdoob.com/
  13043. * @author alteredq / http://alteredqualia.com/
  13044. */
  13045. THREE.Animation = function( root, data, interpolationType, JITCompile ) {
  13046. this.root = root;
  13047. this.data = THREE.AnimationHandler.get( data );
  13048. this.hierarchy = THREE.AnimationHandler.parse( root );
  13049. this.currentTime = 0;
  13050. this.timeScale = 1;
  13051. this.isPlaying = false;
  13052. this.isPaused = true;
  13053. this.loop = true;
  13054. this.interpolationType = interpolationType !== undefined ? interpolationType : THREE.AnimationHandler.LINEAR;
  13055. this.JITCompile = JITCompile !== undefined ? JITCompile : true;
  13056. this.points = [];
  13057. this.target = new THREE.Vector3();
  13058. };
  13059. // Play
  13060. THREE.Animation.prototype.play = function( loop, startTimeMS ) {
  13061. if( !this.isPlaying ) {
  13062. this.isPlaying = true;
  13063. this.loop = loop !== undefined ? loop : true;
  13064. this.currentTime = startTimeMS !== undefined ? startTimeMS : 0;
  13065. // reset key cache
  13066. var h, hl = this.hierarchy.length,
  13067. object;
  13068. for ( h = 0; h < hl; h++ ) {
  13069. object = this.hierarchy[ h ];
  13070. if ( this.interpolationType !== THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  13071. object.useQuaternion = true;
  13072. }
  13073. object.matrixAutoUpdate = true;
  13074. if ( object.animationCache === undefined ) {
  13075. object.animationCache = {};
  13076. object.animationCache.prevKey = { pos: 0, rot: 0, scl: 0 };
  13077. object.animationCache.nextKey = { pos: 0, rot: 0, scl: 0 };
  13078. object.animationCache.originalMatrix = object instanceof THREE.Bone ? object.skinMatrix : object.matrix;
  13079. }
  13080. var prevKey = object.animationCache.prevKey;
  13081. var nextKey = object.animationCache.nextKey;
  13082. prevKey.pos = this.data.hierarchy[ h ].keys[ 0 ];
  13083. prevKey.rot = this.data.hierarchy[ h ].keys[ 0 ];
  13084. prevKey.scl = this.data.hierarchy[ h ].keys[ 0 ];
  13085. nextKey.pos = this.getNextKeyWith( "pos", h, 1 );
  13086. nextKey.rot = this.getNextKeyWith( "rot", h, 1 );
  13087. nextKey.scl = this.getNextKeyWith( "scl", h, 1 );
  13088. }
  13089. this.update( 0 );
  13090. }
  13091. this.isPaused = false;
  13092. THREE.AnimationHandler.addToUpdate( this );
  13093. };
  13094. // Pause
  13095. THREE.Animation.prototype.pause = function() {
  13096. if( this.isPaused ) {
  13097. THREE.AnimationHandler.addToUpdate( this );
  13098. } else {
  13099. THREE.AnimationHandler.removeFromUpdate( this );
  13100. }
  13101. this.isPaused = !this.isPaused;
  13102. };
  13103. // Stop
  13104. THREE.Animation.prototype.stop = function() {
  13105. this.isPlaying = false;
  13106. this.isPaused = false;
  13107. THREE.AnimationHandler.removeFromUpdate( this );
  13108. // reset JIT matrix and remove cache
  13109. for ( var h = 0; h < this.hierarchy.length; h++ ) {
  13110. if ( this.hierarchy[ h ].animationCache !== undefined ) {
  13111. if( this.hierarchy[ h ] instanceof THREE.Bone ) {
  13112. this.hierarchy[ h ].skinMatrix = this.hierarchy[ h ].animationCache.originalMatrix;
  13113. } else {
  13114. this.hierarchy[ h ].matrix = this.hierarchy[ h ].animationCache.originalMatrix;
  13115. }
  13116. delete this.hierarchy[ h ].animationCache;
  13117. }
  13118. }
  13119. };
  13120. // Update
  13121. THREE.Animation.prototype.update = function( deltaTimeMS ) {
  13122. // early out
  13123. if( !this.isPlaying ) return;
  13124. // vars
  13125. var types = [ "pos", "rot", "scl" ];
  13126. var type;
  13127. var scale;
  13128. var vector;
  13129. var prevXYZ, nextXYZ;
  13130. var prevKey, nextKey;
  13131. var object;
  13132. var animationCache;
  13133. var frame;
  13134. var JIThierarchy = this.data.JIT.hierarchy;
  13135. var currentTime, unloopedCurrentTime;
  13136. var currentPoint, forwardPoint, angle;
  13137. // update
  13138. this.currentTime += deltaTimeMS * this.timeScale;
  13139. unloopedCurrentTime = this.currentTime;
  13140. currentTime = this.currentTime = this.currentTime % this.data.length;
  13141. frame = parseInt( Math.min( currentTime * this.data.fps, this.data.length * this.data.fps ), 10 );
  13142. // update
  13143. for ( var h = 0, hl = this.hierarchy.length; h < hl; h++ ) {
  13144. object = this.hierarchy[ h ];
  13145. animationCache = object.animationCache;
  13146. // use JIT?
  13147. if ( this.JITCompile && JIThierarchy[ h ][ frame ] !== undefined ) {
  13148. if( object instanceof THREE.Bone ) {
  13149. object.skinMatrix = JIThierarchy[ h ][ frame ];
  13150. object.matrixAutoUpdate = false;
  13151. object.matrixWorldNeedsUpdate = false;
  13152. } else {
  13153. object.matrix = JIThierarchy[ h ][ frame ];
  13154. object.matrixAutoUpdate = false;
  13155. object.matrixWorldNeedsUpdate = true;
  13156. }
  13157. // use interpolation
  13158. } else {
  13159. // make sure so original matrix and not JIT matrix is set
  13160. if ( this.JITCompile ) {
  13161. if( object instanceof THREE.Bone ) {
  13162. object.skinMatrix = object.animationCache.originalMatrix;
  13163. } else {
  13164. object.matrix = object.animationCache.originalMatrix;
  13165. }
  13166. }
  13167. // loop through pos/rot/scl
  13168. for ( var t = 0; t < 3; t++ ) {
  13169. // get keys
  13170. type = types[ t ];
  13171. prevKey = animationCache.prevKey[ type ];
  13172. nextKey = animationCache.nextKey[ type ];
  13173. // switch keys?
  13174. if ( nextKey.time <= unloopedCurrentTime ) {
  13175. // did we loop?
  13176. if ( currentTime < unloopedCurrentTime ) {
  13177. if ( this.loop ) {
  13178. prevKey = this.data.hierarchy[ h ].keys[ 0 ];
  13179. nextKey = this.getNextKeyWith( type, h, 1 );
  13180. while( nextKey.time < currentTime ) {
  13181. prevKey = nextKey;
  13182. nextKey = this.getNextKeyWith( type, h, nextKey.index + 1 );
  13183. }
  13184. } else {
  13185. this.stop();
  13186. return;
  13187. }
  13188. } else {
  13189. do {
  13190. prevKey = nextKey;
  13191. nextKey = this.getNextKeyWith( type, h, nextKey.index + 1 );
  13192. } while( nextKey.time < currentTime )
  13193. }
  13194. animationCache.prevKey[ type ] = prevKey;
  13195. animationCache.nextKey[ type ] = nextKey;
  13196. }
  13197. object.matrixAutoUpdate = true;
  13198. object.matrixWorldNeedsUpdate = true;
  13199. scale = ( currentTime - prevKey.time ) / ( nextKey.time - prevKey.time );
  13200. prevXYZ = prevKey[ type ];
  13201. nextXYZ = nextKey[ type ];
  13202. // check scale error
  13203. if ( scale < 0 || scale > 1 ) {
  13204. console.log( "THREE.Animation.update: Warning! Scale out of bounds:" + scale + " on bone " + h );
  13205. scale = scale < 0 ? 0 : 1;
  13206. }
  13207. // interpolate
  13208. if ( type === "pos" ) {
  13209. vector = object.position;
  13210. if( this.interpolationType === THREE.AnimationHandler.LINEAR ) {
  13211. vector.x = prevXYZ[ 0 ] + ( nextXYZ[ 0 ] - prevXYZ[ 0 ] ) * scale;
  13212. vector.y = prevXYZ[ 1 ] + ( nextXYZ[ 1 ] - prevXYZ[ 1 ] ) * scale;
  13213. vector.z = prevXYZ[ 2 ] + ( nextXYZ[ 2 ] - prevXYZ[ 2 ] ) * scale;
  13214. } else if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  13215. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  13216. this.points[ 0 ] = this.getPrevKeyWith( "pos", h, prevKey.index - 1 )[ "pos" ];
  13217. this.points[ 1 ] = prevXYZ;
  13218. this.points[ 2 ] = nextXYZ;
  13219. this.points[ 3 ] = this.getNextKeyWith( "pos", h, nextKey.index + 1 )[ "pos" ];
  13220. scale = scale * 0.33 + 0.33;
  13221. currentPoint = this.interpolateCatmullRom( this.points, scale );
  13222. vector.x = currentPoint[ 0 ];
  13223. vector.y = currentPoint[ 1 ];
  13224. vector.z = currentPoint[ 2 ];
  13225. if( this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  13226. forwardPoint = this.interpolateCatmullRom( this.points, scale * 1.01 );
  13227. this.target.set( forwardPoint[ 0 ], forwardPoint[ 1 ], forwardPoint[ 2 ] );
  13228. this.target.subSelf( vector );
  13229. this.target.y = 0;
  13230. this.target.normalize();
  13231. angle = Math.atan2( this.target.x, this.target.z );
  13232. object.rotation.set( 0, angle, 0 );
  13233. }
  13234. }
  13235. } else if ( type === "rot" ) {
  13236. THREE.Quaternion.slerp( prevXYZ, nextXYZ, object.quaternion, scale );
  13237. } else if( type === "scl" ) {
  13238. vector = object.scale;
  13239. vector.x = prevXYZ[ 0 ] + ( nextXYZ[ 0 ] - prevXYZ[ 0 ] ) * scale;
  13240. vector.y = prevXYZ[ 1 ] + ( nextXYZ[ 1 ] - prevXYZ[ 1 ] ) * scale;
  13241. vector.z = prevXYZ[ 2 ] + ( nextXYZ[ 2 ] - prevXYZ[ 2 ] ) * scale;
  13242. }
  13243. }
  13244. }
  13245. }
  13246. // update JIT?
  13247. if ( this.JITCompile ) {
  13248. if ( JIThierarchy[ 0 ][ frame ] === undefined ) {
  13249. this.hierarchy[ 0 ].updateMatrixWorld( true );
  13250. for ( var h = 0; h < this.hierarchy.length; h++ ) {
  13251. if( this.hierarchy[ h ] instanceof THREE.Bone ) {
  13252. JIThierarchy[ h ][ frame ] = this.hierarchy[ h ].skinMatrix.clone();
  13253. } else {
  13254. JIThierarchy[ h ][ frame ] = this.hierarchy[ h ].matrix.clone();
  13255. }
  13256. }
  13257. }
  13258. }
  13259. };
  13260. // Catmull-Rom spline
  13261. THREE.Animation.prototype.interpolateCatmullRom = function ( points, scale ) {
  13262. var c = [], v3 = [],
  13263. point, intPoint, weight, w2, w3,
  13264. pa, pb, pc, pd;
  13265. point = ( points.length - 1 ) * scale;
  13266. intPoint = Math.floor( point );
  13267. weight = point - intPoint;
  13268. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  13269. c[ 1 ] = intPoint;
  13270. c[ 2 ] = intPoint > points.length - 2 ? intPoint : intPoint + 1;
  13271. c[ 3 ] = intPoint > points.length - 3 ? intPoint : intPoint + 2;
  13272. pa = points[ c[ 0 ] ];
  13273. pb = points[ c[ 1 ] ];
  13274. pc = points[ c[ 2 ] ];
  13275. pd = points[ c[ 3 ] ];
  13276. w2 = weight * weight;
  13277. w3 = weight * w2;
  13278. v3[ 0 ] = this.interpolate( pa[ 0 ], pb[ 0 ], pc[ 0 ], pd[ 0 ], weight, w2, w3 );
  13279. v3[ 1 ] = this.interpolate( pa[ 1 ], pb[ 1 ], pc[ 1 ], pd[ 1 ], weight, w2, w3 );
  13280. v3[ 2 ] = this.interpolate( pa[ 2 ], pb[ 2 ], pc[ 2 ], pd[ 2 ], weight, w2, w3 );
  13281. return v3;
  13282. };
  13283. THREE.Animation.prototype.interpolate = function( p0, p1, p2, p3, t, t2, t3 ) {
  13284. var v0 = ( p2 - p0 ) * 0.5,
  13285. v1 = ( p3 - p1 ) * 0.5;
  13286. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  13287. };
  13288. // Get next key with
  13289. THREE.Animation.prototype.getNextKeyWith = function( type, h, key ) {
  13290. var keys = this.data.hierarchy[ h ].keys;
  13291. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  13292. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  13293. key = key < keys.length - 1 ? key : keys.length - 1;
  13294. } else {
  13295. key = key % keys.length;
  13296. }
  13297. for ( ; key < keys.length; key++ ) {
  13298. if ( keys[ key ][ type ] !== undefined ) {
  13299. return keys[ key ];
  13300. }
  13301. }
  13302. return this.data.hierarchy[ h ].keys[ 0 ];
  13303. };
  13304. // Get previous key with
  13305. THREE.Animation.prototype.getPrevKeyWith = function( type, h, key ) {
  13306. var keys = this.data.hierarchy[ h ].keys;
  13307. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  13308. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  13309. key = key > 0 ? key : 0;
  13310. } else {
  13311. key = key >= 0 ? key : key + keys.length;
  13312. }
  13313. for ( ; key >= 0; key-- ) {
  13314. if ( keys[ key ][ type ] !== undefined ) {
  13315. return keys[ key ];
  13316. }
  13317. }
  13318. return this.data.hierarchy[ h ].keys[ keys.length - 1 ];
  13319. };/**
  13320. * @author mikael emtinger / http://gomo.se/
  13321. * @author mrdoob / http://mrdoob.com/
  13322. * @author alteredq / http://alteredqualia.com/
  13323. * @author khang duong
  13324. * @author erik kitson
  13325. */
  13326. THREE.KeyFrameAnimation = function( root, data, JITCompile ) {
  13327. this.root = root;
  13328. this.data = THREE.AnimationHandler.get( data );
  13329. this.hierarchy = THREE.AnimationHandler.parse( root );
  13330. this.currentTime = 0;
  13331. this.timeScale = 0.001;
  13332. this.isPlaying = false;
  13333. this.isPaused = true;
  13334. this.loop = true;
  13335. this.JITCompile = JITCompile !== undefined ? JITCompile : true;
  13336. // initialize to first keyframes
  13337. for ( var h = 0, hl = this.hierarchy.length; h < hl; h++ ) {
  13338. var keys = this.data.hierarchy[h].keys,
  13339. sids = this.data.hierarchy[h].sids,
  13340. obj = this.hierarchy[h];
  13341. if ( keys.length && sids ) {
  13342. for ( var s = 0; s < sids.length; s++ ) {
  13343. var sid = sids[ s ],
  13344. next = this.getNextKeyWith( sid, h, 0 );
  13345. if ( next ) {
  13346. next.apply( sid );
  13347. }
  13348. }
  13349. obj.matrixAutoUpdate = false;
  13350. this.data.hierarchy[h].node.updateMatrix();
  13351. obj.matrixWorldNeedsUpdate = true;
  13352. }
  13353. }
  13354. };
  13355. // Play
  13356. THREE.KeyFrameAnimation.prototype.play = function( loop, startTimeMS ) {
  13357. if( !this.isPlaying ) {
  13358. this.isPlaying = true;
  13359. this.loop = loop !== undefined ? loop : true;
  13360. this.currentTime = startTimeMS !== undefined ? startTimeMS : 0;
  13361. this.startTimeMs = startTimeMS;
  13362. this.startTime = 10000000;
  13363. this.endTime = -this.startTime;
  13364. // reset key cache
  13365. var h, hl = this.hierarchy.length,
  13366. object,
  13367. node;
  13368. for ( h = 0; h < hl; h++ ) {
  13369. object = this.hierarchy[ h ];
  13370. node = this.data.hierarchy[ h ];
  13371. object.useQuaternion = true;
  13372. if ( node.animationCache === undefined ) {
  13373. node.animationCache = {};
  13374. node.animationCache.prevKey = null;
  13375. node.animationCache.nextKey = null;
  13376. node.animationCache.originalMatrix = object instanceof THREE.Bone ? object.skinMatrix : object.matrix;
  13377. }
  13378. var keys = this.data.hierarchy[h].keys;
  13379. if (keys.length) {
  13380. node.animationCache.prevKey = keys[ 0 ];
  13381. node.animationCache.nextKey = keys[ 1 ];
  13382. this.startTime = Math.min( keys[0].time, this.startTime );
  13383. this.endTime = Math.max( keys[keys.length - 1].time, this.endTime );
  13384. }
  13385. }
  13386. this.update( 0 );
  13387. }
  13388. this.isPaused = false;
  13389. THREE.AnimationHandler.addToUpdate( this );
  13390. };
  13391. // Pause
  13392. THREE.KeyFrameAnimation.prototype.pause = function() {
  13393. if( this.isPaused ) {
  13394. THREE.AnimationHandler.addToUpdate( this );
  13395. } else {
  13396. THREE.AnimationHandler.removeFromUpdate( this );
  13397. }
  13398. this.isPaused = !this.isPaused;
  13399. };
  13400. // Stop
  13401. THREE.KeyFrameAnimation.prototype.stop = function() {
  13402. this.isPlaying = false;
  13403. this.isPaused = false;
  13404. THREE.AnimationHandler.removeFromUpdate( this );
  13405. // reset JIT matrix and remove cache
  13406. for ( var h = 0; h < this.data.hierarchy.length; h++ ) {
  13407. var obj = this.hierarchy[ h ];
  13408. var node = this.data.hierarchy[ h ];
  13409. if ( node.animationCache !== undefined ) {
  13410. var original = node.animationCache.originalMatrix;
  13411. if( obj instanceof THREE.Bone ) {
  13412. original.copy( obj.skinMatrix );
  13413. obj.skinMatrix = original;
  13414. } else {
  13415. original.copy( obj.matrix );
  13416. obj.matrix = original;
  13417. }
  13418. delete node.animationCache;
  13419. }
  13420. }
  13421. };
  13422. // Update
  13423. THREE.KeyFrameAnimation.prototype.update = function( deltaTimeMS ) {
  13424. // early out
  13425. if( !this.isPlaying ) return;
  13426. // vars
  13427. var prevKey, nextKey;
  13428. var object;
  13429. var node;
  13430. var frame;
  13431. var JIThierarchy = this.data.JIT.hierarchy;
  13432. var currentTime, unloopedCurrentTime;
  13433. var looped;
  13434. // update
  13435. this.currentTime += deltaTimeMS * this.timeScale;
  13436. unloopedCurrentTime = this.currentTime;
  13437. currentTime = this.currentTime = this.currentTime % this.data.length;
  13438. // if looped around, the current time should be based on the startTime
  13439. if ( currentTime < this.startTimeMs ) {
  13440. currentTime = this.currentTime = this.startTimeMs + currentTime;
  13441. }
  13442. frame = parseInt( Math.min( currentTime * this.data.fps, this.data.length * this.data.fps ), 10 );
  13443. looped = currentTime < unloopedCurrentTime;
  13444. if ( looped && !this.loop ) {
  13445. // Set the animation to the last keyframes and stop
  13446. for ( var h = 0, hl = this.hierarchy.length; h < hl; h++ ) {
  13447. var keys = this.data.hierarchy[h].keys,
  13448. sids = this.data.hierarchy[h].sids,
  13449. end = keys.length-1,
  13450. obj = this.hierarchy[h];
  13451. if ( keys.length ) {
  13452. for ( var s = 0; s < sids.length; s++ ) {
  13453. var sid = sids[ s ],
  13454. prev = this.getPrevKeyWith( sid, h, end );
  13455. if ( prev ) {
  13456. prev.apply( sid );
  13457. }
  13458. }
  13459. this.data.hierarchy[h].node.updateMatrix();
  13460. obj.matrixWorldNeedsUpdate = true;
  13461. }
  13462. }
  13463. this.stop();
  13464. return;
  13465. }
  13466. // check pre-infinity
  13467. if ( currentTime < this.startTime ) {
  13468. return;
  13469. }
  13470. // update
  13471. for ( var h = 0, hl = this.hierarchy.length; h < hl; h++ ) {
  13472. object = this.hierarchy[ h ];
  13473. node = this.data.hierarchy[ h ];
  13474. var keys = node.keys,
  13475. animationCache = node.animationCache;
  13476. // use JIT?
  13477. if ( this.JITCompile && JIThierarchy[ h ][ frame ] !== undefined ) {
  13478. if( object instanceof THREE.Bone ) {
  13479. object.skinMatrix = JIThierarchy[ h ][ frame ];
  13480. object.matrixWorldNeedsUpdate = false;
  13481. } else {
  13482. object.matrix = JIThierarchy[ h ][ frame ];
  13483. object.matrixWorldNeedsUpdate = true;
  13484. }
  13485. // use interpolation
  13486. } else if ( keys.length ) {
  13487. // make sure so original matrix and not JIT matrix is set
  13488. if ( this.JITCompile && animationCache ) {
  13489. if( object instanceof THREE.Bone ) {
  13490. object.skinMatrix = animationCache.originalMatrix;
  13491. } else {
  13492. object.matrix = animationCache.originalMatrix;
  13493. }
  13494. }
  13495. prevKey = animationCache.prevKey;
  13496. nextKey = animationCache.nextKey;
  13497. if ( prevKey && nextKey ) {
  13498. // switch keys?
  13499. if ( nextKey.time <= unloopedCurrentTime ) {
  13500. // did we loop?
  13501. if ( looped && this.loop ) {
  13502. prevKey = keys[ 0 ];
  13503. nextKey = keys[ 1 ];
  13504. while ( nextKey.time < currentTime ) {
  13505. prevKey = nextKey;
  13506. nextKey = keys[ prevKey.index + 1 ];
  13507. }
  13508. } else if ( !looped ) {
  13509. var lastIndex = keys.length - 1;
  13510. while ( nextKey.time < currentTime && nextKey.index !== lastIndex ) {
  13511. prevKey = nextKey;
  13512. nextKey = keys[ prevKey.index + 1 ];
  13513. }
  13514. }
  13515. animationCache.prevKey = prevKey;
  13516. animationCache.nextKey = nextKey;
  13517. }
  13518. if(nextKey.time >= currentTime)
  13519. prevKey.interpolate( nextKey, currentTime );
  13520. else
  13521. prevKey.interpolate( nextKey, nextKey.time);
  13522. }
  13523. this.data.hierarchy[h].node.updateMatrix();
  13524. object.matrixWorldNeedsUpdate = true;
  13525. }
  13526. }
  13527. // update JIT?
  13528. if ( this.JITCompile ) {
  13529. if ( JIThierarchy[ 0 ][ frame ] === undefined ) {
  13530. this.hierarchy[ 0 ].updateMatrixWorld( true );
  13531. for ( var h = 0; h < this.hierarchy.length; h++ ) {
  13532. if( this.hierarchy[ h ] instanceof THREE.Bone ) {
  13533. JIThierarchy[ h ][ frame ] = this.hierarchy[ h ].skinMatrix.clone();
  13534. } else {
  13535. JIThierarchy[ h ][ frame ] = this.hierarchy[ h ].matrix.clone();
  13536. }
  13537. }
  13538. }
  13539. }
  13540. };
  13541. // Get next key with
  13542. THREE.KeyFrameAnimation.prototype.getNextKeyWith = function( sid, h, key ) {
  13543. var keys = this.data.hierarchy[ h ].keys;
  13544. key = key % keys.length;
  13545. for ( ; key < keys.length; key++ ) {
  13546. if ( keys[ key ].hasTarget( sid ) ) {
  13547. return keys[ key ];
  13548. }
  13549. }
  13550. return keys[ 0 ];
  13551. };
  13552. // Get previous key with
  13553. THREE.KeyFrameAnimation.prototype.getPrevKeyWith = function( sid, h, key ) {
  13554. var keys = this.data.hierarchy[ h ].keys;
  13555. key = key >= 0 ? key : key + keys.length;
  13556. for ( ; key >= 0; key-- ) {
  13557. if ( keys[ key ].hasTarget( sid ) ) {
  13558. return keys[ key ];
  13559. }
  13560. }
  13561. return keys[ keys.length - 1 ];
  13562. };
  13563. /**
  13564. * Camera for rendering cube maps
  13565. * - renders scene into axis-aligned cube
  13566. *
  13567. * @author alteredq / http://alteredqualia.com/
  13568. */
  13569. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  13570. THREE.Object3D.call( this );
  13571. var fov = 90, aspect = 1;
  13572. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  13573. cameraPX.up.set( 0, -1, 0 );
  13574. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  13575. this.add( cameraPX );
  13576. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  13577. cameraNX.up.set( 0, -1, 0 );
  13578. cameraNX.lookAt( new THREE.Vector3( -1, 0, 0 ) );
  13579. this.add( cameraNX );
  13580. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  13581. cameraPY.up.set( 0, 0, 1 );
  13582. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  13583. this.add( cameraPY );
  13584. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  13585. cameraNY.up.set( 0, 0, -1 );
  13586. cameraNY.lookAt( new THREE.Vector3( 0, -1, 0 ) );
  13587. this.add( cameraNY );
  13588. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  13589. cameraPZ.up.set( 0, -1, 0 );
  13590. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  13591. this.add( cameraPZ );
  13592. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  13593. cameraNZ.up.set( 0, -1, 0 );
  13594. cameraNZ.lookAt( new THREE.Vector3( 0, 0, -1 ) );
  13595. this.add( cameraNZ );
  13596. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter } );
  13597. this.updateCubeMap = function ( renderer, scene ) {
  13598. var renderTarget = this.renderTarget;
  13599. var generateMipmaps = renderTarget.generateMipmaps;
  13600. renderTarget.generateMipmaps = false;
  13601. renderTarget.activeCubeFace = 0;
  13602. renderer.render( scene, cameraPX, renderTarget );
  13603. renderTarget.activeCubeFace = 1;
  13604. renderer.render( scene, cameraNX, renderTarget );
  13605. renderTarget.activeCubeFace = 2;
  13606. renderer.render( scene, cameraPY, renderTarget );
  13607. renderTarget.activeCubeFace = 3;
  13608. renderer.render( scene, cameraNY, renderTarget );
  13609. renderTarget.activeCubeFace = 4;
  13610. renderer.render( scene, cameraPZ, renderTarget );
  13611. renderTarget.generateMipmaps = generateMipmaps;
  13612. renderTarget.activeCubeFace = 5;
  13613. renderer.render( scene, cameraNZ, renderTarget );
  13614. };
  13615. };
  13616. THREE.CubeCamera.prototype = new THREE.Object3D();
  13617. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  13618. /*
  13619. * @author zz85 / http://twitter.com/blurspline / http://www.lab4games.net/zz85/blog
  13620. *
  13621. * A general perpose camera, for setting FOV, Lens Focal Length,
  13622. * and switching between perspective and orthographic views easily.
  13623. * Use this only if you do not wish to manage
  13624. * both a Orthographic and Perspective Camera
  13625. *
  13626. */
  13627. THREE.CombinedCamera = function ( width, height, fov, near, far, orthonear, orthofar ) {
  13628. THREE.Camera.call( this );
  13629. this.fov = fov;
  13630. this.left = -width / 2;
  13631. this.right = width / 2
  13632. this.top = height / 2;
  13633. this.bottom = -height / 2;
  13634. // We could also handle the projectionMatrix internally, but just wanted to test nested camera objects
  13635. this.cameraO = new THREE.OrthographicCamera( width / - 2, width / 2, height / 2, height / - 2, orthonear, orthofar );
  13636. this.cameraP = new THREE.PerspectiveCamera( fov, width/height, near, far );
  13637. this.zoom = 1;
  13638. this.toPerspective();
  13639. var aspect = width/height;
  13640. };
  13641. THREE.CombinedCamera.prototype = new THREE.Camera();
  13642. THREE.CombinedCamera.prototype.constructor = THREE.CombinedCamera;
  13643. THREE.CombinedCamera.prototype.toPerspective = function () {
  13644. // Switches to the Perspective Camera
  13645. this.near = this.cameraP.near;
  13646. this.far = this.cameraP.far;
  13647. this.cameraP.fov = this.fov / this.zoom ;
  13648. this.cameraP.updateProjectionMatrix();
  13649. this.projectionMatrix = this.cameraP.projectionMatrix;
  13650. this.inPersepectiveMode = true;
  13651. this.inOrthographicMode = false;
  13652. };
  13653. THREE.CombinedCamera.prototype.toOrthographic = function () {
  13654. // Switches to the Orthographic camera estimating viewport from Perspective
  13655. var fov = this.fov;
  13656. var aspect = this.cameraP.aspect;
  13657. var near = this.cameraP.near;
  13658. var far = this.cameraP.far;
  13659. // The size that we set is the mid plane of the viewing frustum
  13660. var hyperfocus = ( near + far ) / 2;
  13661. var halfHeight = Math.tan( fov / 2 ) * hyperfocus;
  13662. var planeHeight = 2 * halfHeight;
  13663. var planeWidth = planeHeight * aspect;
  13664. var halfWidth = planeWidth / 2;
  13665. halfHeight /= this.zoom;
  13666. halfWidth /= this.zoom;
  13667. this.cameraO.left = -halfWidth;
  13668. this.cameraO.right = halfWidth;
  13669. this.cameraO.top = halfHeight;
  13670. this.cameraO.bottom = -halfHeight;
  13671. // this.cameraO.left = -farHalfWidth;
  13672. // this.cameraO.right = farHalfWidth;
  13673. // this.cameraO.top = farHalfHeight;
  13674. // this.cameraO.bottom = -farHalfHeight;
  13675. // this.cameraO.left = this.left / this.zoom;
  13676. // this.cameraO.right = this.right / this.zoom;
  13677. // this.cameraO.top = this.top / this.zoom;
  13678. // this.cameraO.bottom = this.bottom / this.zoom;
  13679. this.cameraO.updateProjectionMatrix();
  13680. this.near = this.cameraO.near;
  13681. this.far = this.cameraO.far;
  13682. this.projectionMatrix = this.cameraO.projectionMatrix;
  13683. this.inPersepectiveMode = false;
  13684. this.inOrthographicMode = true;
  13685. };
  13686. THREE.CombinedCamera.prototype.setSize = function(width, height) {
  13687. this.cameraP.aspect = width / height;
  13688. this.left = -width / 2;
  13689. this.right = width / 2
  13690. this.top = height / 2;
  13691. this.bottom = -height / 2;
  13692. }
  13693. THREE.CombinedCamera.prototype.setFov = function(fov) {
  13694. this.fov = fov;
  13695. if (this.inPersepectiveMode) {
  13696. this.toPerspective();
  13697. } else {
  13698. this.toOrthographic();
  13699. }
  13700. };
  13701. // For mantaining similar API with PerspectiveCamera
  13702. THREE.CombinedCamera.prototype.updateProjectionMatrix = function() {
  13703. if (this.inPersepectiveMode) {
  13704. this.toPerspective();
  13705. } else {
  13706. this.toPerspective();
  13707. this.toOrthographic();
  13708. }
  13709. };
  13710. /*
  13711. * Uses Focal Length (in mm) to estimate and set FOV
  13712. * 35mm (fullframe) camera is used if frame size is not specified;
  13713. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  13714. */
  13715. THREE.CombinedCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  13716. frameHeight = frameHeight !== undefined ? frameHeight : 24;
  13717. var fov = 2 * Math.atan( frameHeight / ( focalLength * 2 ) ) * ( 180 / Math.PI );
  13718. this.setFov( fov );
  13719. return fov;
  13720. };
  13721. THREE.CombinedCamera.prototype.setZoom = function(zoom) {
  13722. this.zoom = zoom;
  13723. if (this.inPersepectiveMode) {
  13724. this.toPerspective();
  13725. } else {
  13726. this.toOrthographic();
  13727. }
  13728. };
  13729. THREE.CombinedCamera.prototype.toFrontView = function() {
  13730. this.rotation.x = 0;
  13731. this.rotation.y = 0;
  13732. this.rotation.z = 0;
  13733. // should we be modifing the matrix instead?
  13734. this.rotationAutoUpdate = false;
  13735. };
  13736. THREE.CombinedCamera.prototype.toBackView = function() {
  13737. this.rotation.x = 0;
  13738. this.rotation.y = Math.PI;
  13739. this.rotation.z = 0;
  13740. this.rotationAutoUpdate = false;
  13741. };
  13742. THREE.CombinedCamera.prototype.toLeftView = function() {
  13743. this.rotation.x = 0;
  13744. this.rotation.y = - Math.PI / 2;
  13745. this.rotation.z = 0;
  13746. this.rotationAutoUpdate = false;
  13747. };
  13748. THREE.CombinedCamera.prototype.toRightView = function() {
  13749. this.rotation.x = 0;
  13750. this.rotation.y = Math.PI / 2;
  13751. this.rotation.z = 0;
  13752. this.rotationAutoUpdate = false;
  13753. };
  13754. THREE.CombinedCamera.prototype.toTopView = function() {
  13755. this.rotation.x = - Math.PI / 2;
  13756. this.rotation.y = 0;
  13757. this.rotation.z = 0;
  13758. this.rotationAutoUpdate = false;
  13759. };
  13760. THREE.CombinedCamera.prototype.toBottomView = function() {
  13761. this.rotation.x = Math.PI / 2;
  13762. this.rotation.y = 0;
  13763. this.rotation.z = 0;
  13764. this.rotationAutoUpdate = false;
  13765. };
  13766. /**
  13767. * @author mrdoob / http://mrdoob.com/
  13768. * @author alteredq / http://alteredqualia.com/
  13769. * @author paulirish / http://paulirish.com/
  13770. */
  13771. THREE.FirstPersonControls = function ( object, domElement ) {
  13772. this.object = object;
  13773. this.target = new THREE.Vector3( 0, 0, 0 );
  13774. this.domElement = ( domElement !== undefined ) ? domElement : document;
  13775. this.movementSpeed = 1.0;
  13776. this.lookSpeed = 0.005;
  13777. this.noFly = false;
  13778. this.lookVertical = true;
  13779. this.autoForward = false;
  13780. this.activeLook = true;
  13781. this.heightSpeed = false;
  13782. this.heightCoef = 1.0;
  13783. this.heightMin = 0.0;
  13784. this.constrainVertical = false;
  13785. this.verticalMin = 0;
  13786. this.verticalMax = Math.PI;
  13787. this.autoSpeedFactor = 0.0;
  13788. this.mouseX = 0;
  13789. this.mouseY = 0;
  13790. this.lat = 0;
  13791. this.lon = 0;
  13792. this.phi = 0;
  13793. this.theta = 0;
  13794. this.moveForward = false;
  13795. this.moveBackward = false;
  13796. this.moveLeft = false;
  13797. this.moveRight = false;
  13798. this.freeze = false;
  13799. this.mouseDragOn = false;
  13800. if ( this.domElement === document ) {
  13801. this.viewHalfX = window.innerWidth / 2;
  13802. this.viewHalfY = window.innerHeight / 2;
  13803. } else {
  13804. this.viewHalfX = this.domElement.offsetWidth / 2;
  13805. this.viewHalfY = this.domElement.offsetHeight / 2;
  13806. this.domElement.setAttribute( 'tabindex', -1 );
  13807. }
  13808. this.onMouseDown = function ( event ) {
  13809. if ( this.domElement !== document ) {
  13810. this.domElement.focus();
  13811. }
  13812. event.preventDefault();
  13813. event.stopPropagation();
  13814. if ( this.activeLook ) {
  13815. switch ( event.button ) {
  13816. case 0: this.moveForward = true; break;
  13817. case 2: this.moveBackward = true; break;
  13818. }
  13819. }
  13820. this.mouseDragOn = true;
  13821. };
  13822. this.onMouseUp = function ( event ) {
  13823. event.preventDefault();
  13824. event.stopPropagation();
  13825. if ( this.activeLook ) {
  13826. switch ( event.button ) {
  13827. case 0: this.moveForward = false; break;
  13828. case 2: this.moveBackward = false; break;
  13829. }
  13830. }
  13831. this.mouseDragOn = false;
  13832. };
  13833. this.onMouseMove = function ( event ) {
  13834. if ( this.domElement === document ) {
  13835. this.mouseX = event.pageX - this.viewHalfX;
  13836. this.mouseY = event.pageY - this.viewHalfY;
  13837. } else {
  13838. this.mouseX = event.pageX - this.domElement.offsetLeft - this.viewHalfX;
  13839. this.mouseY = event.pageY - this.domElement.offsetTop - this.viewHalfY;
  13840. }
  13841. };
  13842. this.onKeyDown = function ( event ) {
  13843. switch( event.keyCode ) {
  13844. case 38: /*up*/
  13845. case 87: /*W*/ this.moveForward = true; break;
  13846. case 37: /*left*/
  13847. case 65: /*A*/ this.moveLeft = true; break;
  13848. case 40: /*down*/
  13849. case 83: /*S*/ this.moveBackward = true; break;
  13850. case 39: /*right*/
  13851. case 68: /*D*/ this.moveRight = true; break;
  13852. case 82: /*R*/ this.moveUp = true; break;
  13853. case 70: /*F*/ this.moveDown = true; break;
  13854. case 81: /*Q*/ this.freeze = !this.freeze; break;
  13855. }
  13856. };
  13857. this.onKeyUp = function ( event ) {
  13858. switch( event.keyCode ) {
  13859. case 38: /*up*/
  13860. case 87: /*W*/ this.moveForward = false; break;
  13861. case 37: /*left*/
  13862. case 65: /*A*/ this.moveLeft = false; break;
  13863. case 40: /*down*/
  13864. case 83: /*S*/ this.moveBackward = false; break;
  13865. case 39: /*right*/
  13866. case 68: /*D*/ this.moveRight = false; break;
  13867. case 82: /*R*/ this.moveUp = false; break;
  13868. case 70: /*F*/ this.moveDown = false; break;
  13869. }
  13870. };
  13871. this.update = function( delta ) {
  13872. var actualMoveSpeed = 0;
  13873. if ( this.freeze ) {
  13874. return;
  13875. } else {
  13876. if ( this.heightSpeed ) {
  13877. var y = THREE.Math.clamp( this.object.position.y, this.heightMin, this.heightMax );
  13878. var heightDelta = y - this.heightMin;
  13879. this.autoSpeedFactor = delta * ( heightDelta * this.heightCoef );
  13880. } else {
  13881. this.autoSpeedFactor = 0.0;
  13882. }
  13883. actualMoveSpeed = delta * this.movementSpeed;
  13884. if ( this.moveForward || ( this.autoForward && !this.moveBackward ) ) this.object.translateZ( - ( actualMoveSpeed + this.autoSpeedFactor ) );
  13885. if ( this.moveBackward ) this.object.translateZ( actualMoveSpeed );
  13886. if ( this.moveLeft ) this.object.translateX( - actualMoveSpeed );
  13887. if ( this.moveRight ) this.object.translateX( actualMoveSpeed );
  13888. if ( this.moveUp ) this.object.translateY( actualMoveSpeed );
  13889. if ( this.moveDown ) this.object.translateY( - actualMoveSpeed );
  13890. var actualLookSpeed = delta * this.lookSpeed;
  13891. if ( !this.activeLook ) {
  13892. actualLookSpeed = 0;
  13893. }
  13894. this.lon += this.mouseX * actualLookSpeed;
  13895. if( this.lookVertical ) this.lat -= this.mouseY * actualLookSpeed;
  13896. this.lat = Math.max( - 85, Math.min( 85, this.lat ) );
  13897. this.phi = ( 90 - this.lat ) * Math.PI / 180;
  13898. this.theta = this.lon * Math.PI / 180;
  13899. var targetPosition = this.target,
  13900. position = this.object.position;
  13901. targetPosition.x = position.x + 100 * Math.sin( this.phi ) * Math.cos( this.theta );
  13902. targetPosition.y = position.y + 100 * Math.cos( this.phi );
  13903. targetPosition.z = position.z + 100 * Math.sin( this.phi ) * Math.sin( this.theta );
  13904. }
  13905. var verticalLookRatio = 1;
  13906. if ( this.constrainVertical ) {
  13907. verticalLookRatio = Math.PI / ( this.verticalMax - this.verticalMin );
  13908. }
  13909. this.lon += this.mouseX * actualLookSpeed;
  13910. if( this.lookVertical ) this.lat -= this.mouseY * actualLookSpeed * verticalLookRatio;
  13911. this.lat = Math.max( - 85, Math.min( 85, this.lat ) );
  13912. this.phi = ( 90 - this.lat ) * Math.PI / 180;
  13913. this.theta = this.lon * Math.PI / 180;
  13914. if ( this.constrainVertical ) {
  13915. this.phi = THREE.Math.mapLinear( this.phi, 0, Math.PI, this.verticalMin, this.verticalMax );
  13916. }
  13917. var targetPosition = this.target,
  13918. position = this.object.position;
  13919. targetPosition.x = position.x + 100 * Math.sin( this.phi ) * Math.cos( this.theta );
  13920. targetPosition.y = position.y + 100 * Math.cos( this.phi );
  13921. targetPosition.z = position.z + 100 * Math.sin( this.phi ) * Math.sin( this.theta );
  13922. this.object.lookAt( targetPosition );
  13923. };
  13924. this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
  13925. this.domElement.addEventListener( 'mousemove', bind( this, this.onMouseMove ), false );
  13926. this.domElement.addEventListener( 'mousedown', bind( this, this.onMouseDown ), false );
  13927. this.domElement.addEventListener( 'mouseup', bind( this, this.onMouseUp ), false );
  13928. this.domElement.addEventListener( 'keydown', bind( this, this.onKeyDown ), false );
  13929. this.domElement.addEventListener( 'keyup', bind( this, this.onKeyUp ), false );
  13930. function bind( scope, fn ) {
  13931. return function () {
  13932. fn.apply( scope, arguments );
  13933. };
  13934. };
  13935. };
  13936. /**
  13937. * @author alteredq / http://alteredqualia.com/
  13938. */
  13939. THREE.PathControls = function ( object, domElement ) {
  13940. this.object = object;
  13941. this.domElement = ( domElement !== undefined ) ? domElement : document;
  13942. this.id = "PathControls" + THREE.PathControlsIdCounter ++;
  13943. // API
  13944. this.duration = 10 * 1000; // milliseconds
  13945. this.waypoints = [];
  13946. this.useConstantSpeed = true;
  13947. this.resamplingCoef = 50;
  13948. this.debugPath = new THREE.Object3D();
  13949. this.debugDummy = new THREE.Object3D();
  13950. this.animationParent = new THREE.Object3D();
  13951. this.lookSpeed = 0.005;
  13952. this.lookVertical = true;
  13953. this.lookHorizontal = true;
  13954. this.verticalAngleMap = { srcRange: [ 0, 2 * Math.PI ], dstRange: [ 0, 2 * Math.PI ] };
  13955. this.horizontalAngleMap = { srcRange: [ 0, 2 * Math.PI ], dstRange: [ 0, 2 * Math.PI ] };
  13956. // internals
  13957. this.target = new THREE.Object3D();
  13958. this.mouseX = 0;
  13959. this.mouseY = 0;
  13960. this.lat = 0;
  13961. this.lon = 0;
  13962. this.phi = 0;
  13963. this.theta = 0;
  13964. if ( this.domElement === document ) {
  13965. this.viewHalfX = window.innerWidth / 2;
  13966. this.viewHalfY = window.innerHeight / 2;
  13967. } else {
  13968. this.viewHalfX = this.domElement.offsetWidth / 2;
  13969. this.viewHalfY = this.domElement.offsetHeight / 2;
  13970. this.domElement.setAttribute( 'tabindex', -1 );
  13971. }
  13972. var PI2 = Math.PI * 2,
  13973. PI180 = Math.PI / 180;
  13974. // methods
  13975. this.update = function ( delta ) {
  13976. var srcRange, dstRange;
  13977. if( this.lookHorizontal ) this.lon += this.mouseX * this.lookSpeed * delta;
  13978. if( this.lookVertical ) this.lat -= this.mouseY * this.lookSpeed * delta;
  13979. this.lon = Math.max( 0, Math.min( 360, this.lon ) );
  13980. this.lat = Math.max( - 85, Math.min( 85, this.lat ) );
  13981. this.phi = ( 90 - this.lat ) * PI180;
  13982. this.theta = this.lon * PI180;
  13983. this.phi = normalize_angle_rad( this.phi );
  13984. // constrain vertical look angle
  13985. srcRange = this.verticalAngleMap.srcRange;
  13986. dstRange = this.verticalAngleMap.dstRange;
  13987. var tmpPhi = THREE.Math.mapLinear( this.phi, srcRange[ 0 ], srcRange[ 1 ], dstRange[ 0 ], dstRange[ 1 ] );
  13988. var tmpPhiFullRange = dstRange[ 1 ] - dstRange[ 0 ];
  13989. var tmpPhiNormalized = ( tmpPhi - dstRange[ 0 ] ) / tmpPhiFullRange;
  13990. this.phi = QuadraticEaseInOut( tmpPhiNormalized ) * tmpPhiFullRange + dstRange[ 0 ];
  13991. // constrain horizontal look angle
  13992. srcRange = this.horizontalAngleMap.srcRange;
  13993. dstRange = this.horizontalAngleMap.dstRange;
  13994. var tmpTheta = THREE.Math.mapLinear( this.theta, srcRange[ 0 ], srcRange[ 1 ], dstRange[ 0 ], dstRange[ 1 ] );
  13995. var tmpThetaFullRange = dstRange[ 1 ] - dstRange[ 0 ];
  13996. var tmpThetaNormalized = ( tmpTheta - dstRange[ 0 ] ) / tmpThetaFullRange;
  13997. this.theta = QuadraticEaseInOut( tmpThetaNormalized ) * tmpThetaFullRange + dstRange[ 0 ];
  13998. var targetPosition = this.target.position,
  13999. position = this.object.position;
  14000. targetPosition.x = 100 * Math.sin( this.phi ) * Math.cos( this.theta );
  14001. targetPosition.y = 100 * Math.cos( this.phi );
  14002. targetPosition.z = 100 * Math.sin( this.phi ) * Math.sin( this.theta );
  14003. this.object.lookAt( this.target.position );
  14004. };
  14005. this.onMouseMove = function ( event ) {
  14006. if ( this.domElement === document ) {
  14007. this.mouseX = event.pageX - this.viewHalfX;
  14008. this.mouseY = event.pageY - this.viewHalfY;
  14009. } else {
  14010. this.mouseX = event.pageX - this.domElement.offsetLeft - this.viewHalfX;
  14011. this.mouseY = event.pageY - this.domElement.offsetTop - this.viewHalfY;
  14012. }
  14013. };
  14014. // utils
  14015. function normalize_angle_rad( a ) {
  14016. var b = a % PI2;
  14017. return b >= 0 ? b : b + PI2;
  14018. };
  14019. function distance( a, b ) {
  14020. var dx = a[ 0 ] - b[ 0 ],
  14021. dy = a[ 1 ] - b[ 1 ],
  14022. dz = a[ 2 ] - b[ 2 ];
  14023. return Math.sqrt( dx * dx + dy * dy + dz * dz );
  14024. };
  14025. function QuadraticEaseInOut ( k ) {
  14026. if ( ( k *= 2 ) < 1 ) return 0.5 * k * k;
  14027. return - 0.5 * ( --k * ( k - 2 ) - 1 );
  14028. };
  14029. function bind( scope, fn ) {
  14030. return function () {
  14031. fn.apply( scope, arguments );
  14032. };
  14033. };
  14034. function initAnimationPath( parent, spline, name, duration ) {
  14035. var animationData = {
  14036. name: name,
  14037. fps: 0.6,
  14038. length: duration,
  14039. hierarchy: []
  14040. };
  14041. var i,
  14042. parentAnimation, childAnimation,
  14043. path = spline.getControlPointsArray(),
  14044. sl = spline.getLength(),
  14045. pl = path.length,
  14046. t = 0,
  14047. first = 0,
  14048. last = pl - 1;
  14049. parentAnimation = { parent: -1, keys: [] };
  14050. parentAnimation.keys[ first ] = { time: 0, pos: path[ first ], rot: [ 0, 0, 0, 1 ], scl: [ 1, 1, 1 ] };
  14051. parentAnimation.keys[ last ] = { time: duration, pos: path[ last ], rot: [ 0, 0, 0, 1 ], scl: [ 1, 1, 1 ] };
  14052. for ( i = 1; i < pl - 1; i++ ) {
  14053. // real distance (approximation via linear segments)
  14054. t = duration * sl.chunks[ i ] / sl.total;
  14055. // equal distance
  14056. //t = duration * ( i / pl );
  14057. // linear distance
  14058. //t += duration * distance( path[ i ], path[ i - 1 ] ) / sl.total;
  14059. parentAnimation.keys[ i ] = { time: t, pos: path[ i ] };
  14060. }
  14061. animationData.hierarchy[ 0 ] = parentAnimation;
  14062. THREE.AnimationHandler.add( animationData );
  14063. return new THREE.Animation( parent, name, THREE.AnimationHandler.CATMULLROM_FORWARD, false );
  14064. };
  14065. function createSplineGeometry( spline, n_sub ) {
  14066. var i, index, position,
  14067. geometry = new THREE.Geometry();
  14068. for ( i = 0; i < spline.points.length * n_sub; i ++ ) {
  14069. index = i / ( spline.points.length * n_sub );
  14070. position = spline.getPoint( index );
  14071. geometry.vertices[ i ] = new THREE.Vector3( position.x, position.y, position.z );
  14072. }
  14073. return geometry;
  14074. };
  14075. function createPath( parent, spline ) {
  14076. var lineGeo = createSplineGeometry( spline, 10 ),
  14077. particleGeo = createSplineGeometry( spline, 10 ),
  14078. lineMat = new THREE.LineBasicMaterial( { color: 0xff0000, linewidth: 3 } ),
  14079. lineObj = new THREE.Line( lineGeo, lineMat ),
  14080. particleObj = new THREE.ParticleSystem( particleGeo, new THREE.ParticleBasicMaterial( { color: 0xffaa00, size: 3 } ) );
  14081. lineObj.scale.set( 1, 1, 1 );
  14082. parent.add( lineObj );
  14083. particleObj.scale.set( 1, 1, 1 );
  14084. parent.add( particleObj );
  14085. var waypoint,
  14086. geo = new THREE.SphereGeometry( 1, 16, 8 ),
  14087. mat = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
  14088. for ( var i = 0; i < spline.points.length; i ++ ) {
  14089. waypoint = new THREE.Mesh( geo, mat );
  14090. waypoint.position.copy( spline.points[ i ] );
  14091. parent.add( waypoint );
  14092. }
  14093. };
  14094. this.init = function ( ) {
  14095. // constructor
  14096. this.spline = new THREE.Spline();
  14097. this.spline.initFromArray( this.waypoints );
  14098. if ( this.useConstantSpeed ) {
  14099. this.spline.reparametrizeByArcLength( this.resamplingCoef );
  14100. }
  14101. if ( this.createDebugDummy ) {
  14102. var dummyParentMaterial = new THREE.MeshLambertMaterial( { color: 0x0077ff } ),
  14103. dummyChildMaterial = new THREE.MeshLambertMaterial( { color: 0x00ff00 } ),
  14104. dummyParentGeo = new THREE.CubeGeometry( 10, 10, 20 ),
  14105. dummyChildGeo = new THREE.CubeGeometry( 2, 2, 10 );
  14106. this.animationParent = new THREE.Mesh( dummyParentGeo, dummyParentMaterial );
  14107. var dummyChild = new THREE.Mesh( dummyChildGeo, dummyChildMaterial );
  14108. dummyChild.position.set( 0, 10, 0 );
  14109. this.animation = initAnimationPath( this.animationParent, this.spline, this.id, this.duration );
  14110. this.animationParent.add( this.object );
  14111. this.animationParent.add( this.target );
  14112. this.animationParent.add( dummyChild );
  14113. } else {
  14114. this.animation = initAnimationPath( this.animationParent, this.spline, this.id, this.duration );
  14115. this.animationParent.add( this.target );
  14116. this.animationParent.add( this.object );
  14117. }
  14118. if ( this.createDebugPath ) {
  14119. createPath( this.debugPath, this.spline );
  14120. }
  14121. this.domElement.addEventListener( 'mousemove', bind( this, this.onMouseMove ), false );
  14122. };
  14123. };
  14124. THREE.PathControlsIdCounter = 0;
  14125. /**
  14126. * @author James Baicoianu / http://www.baicoianu.com/
  14127. */
  14128. THREE.FlyControls = function ( object, domElement ) {
  14129. this.object = object;
  14130. this.domElement = ( domElement !== undefined ) ? domElement : document;
  14131. if ( domElement ) this.domElement.setAttribute( 'tabindex', -1 );
  14132. // API
  14133. this.movementSpeed = 1.0;
  14134. this.rollSpeed = 0.005;
  14135. this.dragToLook = false;
  14136. this.autoForward = false;
  14137. // disable default target object behavior
  14138. this.object.useQuaternion = true;
  14139. // internals
  14140. this.tmpQuaternion = new THREE.Quaternion();
  14141. this.mouseStatus = 0;
  14142. this.moveState = { up: 0, down: 0, left: 0, right: 0, forward: 0, back: 0, pitchUp: 0, pitchDown: 0, yawLeft: 0, yawRight: 0, rollLeft: 0, rollRight: 0 };
  14143. this.moveVector = new THREE.Vector3( 0, 0, 0 );
  14144. this.rotationVector = new THREE.Vector3( 0, 0, 0 );
  14145. this.handleEvent = function ( event ) {
  14146. if ( typeof this[ event.type ] == 'function' ) {
  14147. this[ event.type ]( event );
  14148. }
  14149. };
  14150. this.keydown = function( event ) {
  14151. if ( event.altKey ) {
  14152. return;
  14153. }
  14154. switch( event.keyCode ) {
  14155. case 16: /* shift */ this.movementSpeedMultiplier = .1; break;
  14156. case 87: /*W*/ this.moveState.forward = 1; break;
  14157. case 83: /*S*/ this.moveState.back = 1; break;
  14158. case 65: /*A*/ this.moveState.left = 1; break;
  14159. case 68: /*D*/ this.moveState.right = 1; break;
  14160. case 82: /*R*/ this.moveState.up = 1; break;
  14161. case 70: /*F*/ this.moveState.down = 1; break;
  14162. case 38: /*up*/ this.moveState.pitchUp = 1; break;
  14163. case 40: /*down*/ this.moveState.pitchDown = 1; break;
  14164. case 37: /*left*/ this.moveState.yawLeft = 1; break;
  14165. case 39: /*right*/ this.moveState.yawRight = 1; break;
  14166. case 81: /*Q*/ this.moveState.rollLeft = 1; break;
  14167. case 69: /*E*/ this.moveState.rollRight = 1; break;
  14168. }
  14169. this.updateMovementVector();
  14170. this.updateRotationVector();
  14171. };
  14172. this.keyup = function( event ) {
  14173. switch( event.keyCode ) {
  14174. case 16: /* shift */ this.movementSpeedMultiplier = 1; break;
  14175. case 87: /*W*/ this.moveState.forward = 0; break;
  14176. case 83: /*S*/ this.moveState.back = 0; break;
  14177. case 65: /*A*/ this.moveState.left = 0; break;
  14178. case 68: /*D*/ this.moveState.right = 0; break;
  14179. case 82: /*R*/ this.moveState.up = 0; break;
  14180. case 70: /*F*/ this.moveState.down = 0; break;
  14181. case 38: /*up*/ this.moveState.pitchUp = 0; break;
  14182. case 40: /*down*/ this.moveState.pitchDown = 0; break;
  14183. case 37: /*left*/ this.moveState.yawLeft = 0; break;
  14184. case 39: /*right*/ this.moveState.yawRight = 0; break;
  14185. case 81: /*Q*/ this.moveState.rollLeft = 0; break;
  14186. case 69: /*E*/ this.moveState.rollRight = 0; break;
  14187. }
  14188. this.updateMovementVector();
  14189. this.updateRotationVector();
  14190. };
  14191. this.mousedown = function( event ) {
  14192. if ( this.domElement !== document ) {
  14193. this.domElement.focus();
  14194. }
  14195. event.preventDefault();
  14196. event.stopPropagation();
  14197. if ( this.dragToLook ) {
  14198. this.mouseStatus ++;
  14199. } else {
  14200. switch ( event.button ) {
  14201. case 0: this.object.moveForward = true; break;
  14202. case 2: this.object.moveBackward = true; break;
  14203. }
  14204. }
  14205. };
  14206. this.mousemove = function( event ) {
  14207. if ( !this.dragToLook || this.mouseStatus > 0 ) {
  14208. var container = this.getContainerDimensions();
  14209. var halfWidth = container.size[ 0 ] / 2;
  14210. var halfHeight = container.size[ 1 ] / 2;
  14211. this.moveState.yawLeft = - ( ( event.pageX - container.offset[ 0 ] ) - halfWidth ) / halfWidth;
  14212. this.moveState.pitchDown = ( ( event.pageY - container.offset[ 1 ] ) - halfHeight ) / halfHeight;
  14213. this.updateRotationVector();
  14214. }
  14215. };
  14216. this.mouseup = function( event ) {
  14217. event.preventDefault();
  14218. event.stopPropagation();
  14219. if ( this.dragToLook ) {
  14220. this.mouseStatus --;
  14221. this.moveState.yawLeft = this.moveState.pitchDown = 0;
  14222. } else {
  14223. switch ( event.button ) {
  14224. case 0: this.moveForward = false; break;
  14225. case 2: this.moveBackward = false; break;
  14226. }
  14227. }
  14228. this.updateRotationVector();
  14229. };
  14230. this.update = function( delta ) {
  14231. var moveMult = delta * this.movementSpeed;
  14232. var rotMult = delta * this.rollSpeed;
  14233. this.object.translateX( this.moveVector.x * moveMult );
  14234. this.object.translateY( this.moveVector.y * moveMult );
  14235. this.object.translateZ( this.moveVector.z * moveMult );
  14236. this.tmpQuaternion.set( this.rotationVector.x * rotMult, this.rotationVector.y * rotMult, this.rotationVector.z * rotMult, 1 ).normalize();
  14237. this.object.quaternion.multiplySelf( this.tmpQuaternion );
  14238. this.object.matrix.setPosition( this.object.position );
  14239. this.object.matrix.setRotationFromQuaternion( this.object.quaternion );
  14240. this.object.matrixWorldNeedsUpdate = true;
  14241. };
  14242. this.updateMovementVector = function() {
  14243. var forward = ( this.moveState.forward || ( this.autoForward && !this.moveState.back ) ) ? 1 : 0;
  14244. this.moveVector.x = ( -this.moveState.left + this.moveState.right );
  14245. this.moveVector.y = ( -this.moveState.down + this.moveState.up );
  14246. this.moveVector.z = ( -forward + this.moveState.back );
  14247. //console.log( 'move:', [ this.moveVector.x, this.moveVector.y, this.moveVector.z ] );
  14248. };
  14249. this.updateRotationVector = function() {
  14250. this.rotationVector.x = ( -this.moveState.pitchDown + this.moveState.pitchUp );
  14251. this.rotationVector.y = ( -this.moveState.yawRight + this.moveState.yawLeft );
  14252. this.rotationVector.z = ( -this.moveState.rollRight + this.moveState.rollLeft );
  14253. //console.log( 'rotate:', [ this.rotationVector.x, this.rotationVector.y, this.rotationVector.z ] );
  14254. };
  14255. this.getContainerDimensions = function() {
  14256. if ( this.domElement != document ) {
  14257. return {
  14258. size : [ this.domElement.offsetWidth, this.domElement.offsetHeight ],
  14259. offset : [ this.domElement.offsetLeft, this.domElement.offsetTop ]
  14260. };
  14261. } else {
  14262. return {
  14263. size : [ window.innerWidth, window.innerHeight ],
  14264. offset : [ 0, 0 ]
  14265. };
  14266. }
  14267. };
  14268. function bind( scope, fn ) {
  14269. return function () {
  14270. fn.apply( scope, arguments );
  14271. };
  14272. };
  14273. this.domElement.addEventListener( 'mousemove', bind( this, this.mousemove ), false );
  14274. this.domElement.addEventListener( 'mousedown', bind( this, this.mousedown ), false );
  14275. this.domElement.addEventListener( 'mouseup', bind( this, this.mouseup ), false );
  14276. this.domElement.addEventListener( 'keydown', bind( this, this.keydown ), false );
  14277. this.domElement.addEventListener( 'keyup', bind( this, this.keyup ), false );
  14278. this.updateMovementVector();
  14279. this.updateRotationVector();
  14280. };
  14281. /**
  14282. * @author mikael emtinger / http://gomo.se/
  14283. * @author alteredq / http://alteredqualia.com/
  14284. */
  14285. THREE.RollControls = function ( object, domElement ) {
  14286. this.object = object;
  14287. this.domElement = ( domElement !== undefined ) ? domElement : document;
  14288. // API
  14289. this.mouseLook = true;
  14290. this.autoForward = false;
  14291. this.lookSpeed = 1;
  14292. this.movementSpeed = 1;
  14293. this.rollSpeed = 1;
  14294. this.constrainVertical = [ -0.9, 0.9 ];
  14295. // disable default target object behavior
  14296. this.object.matrixAutoUpdate = false;
  14297. // internals
  14298. this.forward = new THREE.Vector3( 0, 0, 1 );
  14299. this.roll = 0;
  14300. var xTemp = new THREE.Vector3();
  14301. var yTemp = new THREE.Vector3();
  14302. var zTemp = new THREE.Vector3();
  14303. var rollMatrix = new THREE.Matrix4();
  14304. var doRoll = false, rollDirection = 1, forwardSpeed = 0, sideSpeed = 0, upSpeed = 0;
  14305. var mouseX = 0, mouseY = 0;
  14306. var windowHalfX = window.innerWidth / 2;
  14307. var windowHalfY = window.innerHeight / 2;
  14308. // custom update
  14309. this.update = function ( delta ) {
  14310. if ( this.mouseLook ) {
  14311. var actualLookSpeed = delta * this.lookSpeed;
  14312. this.rotateHorizontally( actualLookSpeed * mouseX );
  14313. this.rotateVertically( actualLookSpeed * mouseY );
  14314. }
  14315. var actualSpeed = delta * this.movementSpeed;
  14316. var forwardOrAuto = ( forwardSpeed > 0 || ( this.autoForward && ! ( forwardSpeed < 0 ) ) ) ? 1 : forwardSpeed;
  14317. this.object.translateZ( -actualSpeed * forwardOrAuto );
  14318. this.object.translateX( actualSpeed * sideSpeed );
  14319. this.object.translateY( actualSpeed * upSpeed );
  14320. if( doRoll ) {
  14321. this.roll += this.rollSpeed * delta * rollDirection;
  14322. }
  14323. // cap forward up / down
  14324. if( this.forward.y > this.constrainVertical[ 1 ] ) {
  14325. this.forward.y = this.constrainVertical[ 1 ];
  14326. this.forward.normalize();
  14327. } else if( this.forward.y < this.constrainVertical[ 0 ] ) {
  14328. this.forward.y = this.constrainVertical[ 0 ];
  14329. this.forward.normalize();
  14330. }
  14331. // construct unrolled camera matrix
  14332. zTemp.copy( this.forward );
  14333. yTemp.set( 0, 1, 0 );
  14334. xTemp.cross( yTemp, zTemp ).normalize();
  14335. yTemp.cross( zTemp, xTemp ).normalize();
  14336. this.object.matrix.elements[0] = xTemp.x; this.object.matrix.elements[4] = yTemp.x; this.object.matrix.elements[8] = zTemp.x;
  14337. this.object.matrix.elements[1] = xTemp.y; this.object.matrix.elements[5] = yTemp.y; this.object.matrix.elements[9] = zTemp.y;
  14338. this.object.matrix.elements[2] = xTemp.z; this.object.matrix.elements[6] = yTemp.z; this.object.matrix.elements[10] = zTemp.z;
  14339. // calculate roll matrix
  14340. rollMatrix.identity();
  14341. rollMatrix.elements[0] = Math.cos( this.roll ); rollMatrix.elements[4] = -Math.sin( this.roll );
  14342. rollMatrix.elements[1] = Math.sin( this.roll ); rollMatrix.elements[5] = Math.cos( this.roll );
  14343. // multiply camera with roll
  14344. this.object.matrix.multiplySelf( rollMatrix );
  14345. this.object.matrixWorldNeedsUpdate = true;
  14346. // set position
  14347. this.object.matrix.elements[12] = this.object.position.x;
  14348. this.object.matrix.elements[13] = this.object.position.y;
  14349. this.object.matrix.elements[14] = this.object.position.z;
  14350. };
  14351. this.translateX = function ( distance ) {
  14352. this.object.position.x += this.object.matrix.elements[0] * distance;
  14353. this.object.position.y += this.object.matrix.elements[1] * distance;
  14354. this.object.position.z += this.object.matrix.elements[2] * distance;
  14355. };
  14356. this.translateY = function ( distance ) {
  14357. this.object.position.x += this.object.matrix.elements[4] * distance;
  14358. this.object.position.y += this.object.matrix.elements[5] * distance;
  14359. this.object.position.z += this.object.matrix.elements[6] * distance;
  14360. };
  14361. this.translateZ = function ( distance ) {
  14362. this.object.position.x -= this.object.matrix.elements[8] * distance;
  14363. this.object.position.y -= this.object.matrix.elements[9] * distance;
  14364. this.object.position.z -= this.object.matrix.elements[10] * distance;
  14365. };
  14366. this.rotateHorizontally = function ( amount ) {
  14367. // please note that the amount is NOT degrees, but a scale value
  14368. xTemp.set( this.object.matrix.elements[0], this.object.matrix.elements[1], this.object.matrix.elements[2] );
  14369. xTemp.multiplyScalar( amount );
  14370. this.forward.subSelf( xTemp );
  14371. this.forward.normalize();
  14372. };
  14373. this.rotateVertically = function ( amount ) {
  14374. // please note that the amount is NOT degrees, but a scale value
  14375. yTemp.set( this.object.matrix.elements[4], this.object.matrix.elements[5], this.object.matrix.elements[6] );
  14376. yTemp.multiplyScalar( amount );
  14377. this.forward.addSelf( yTemp );
  14378. this.forward.normalize();
  14379. };
  14380. function onKeyDown( event ) {
  14381. switch( event.keyCode ) {
  14382. case 38: /*up*/
  14383. case 87: /*W*/ forwardSpeed = 1; break;
  14384. case 37: /*left*/
  14385. case 65: /*A*/ sideSpeed = -1; break;
  14386. case 40: /*down*/
  14387. case 83: /*S*/ forwardSpeed = -1; break;
  14388. case 39: /*right*/
  14389. case 68: /*D*/ sideSpeed = 1; break;
  14390. case 81: /*Q*/ doRoll = true; rollDirection = 1; break;
  14391. case 69: /*E*/ doRoll = true; rollDirection = -1; break;
  14392. case 82: /*R*/ upSpeed = 1; break;
  14393. case 70: /*F*/ upSpeed = -1; break;
  14394. }
  14395. };
  14396. function onKeyUp( event ) {
  14397. switch( event.keyCode ) {
  14398. case 38: /*up*/
  14399. case 87: /*W*/ forwardSpeed = 0; break;
  14400. case 37: /*left*/
  14401. case 65: /*A*/ sideSpeed = 0; break;
  14402. case 40: /*down*/
  14403. case 83: /*S*/ forwardSpeed = 0; break;
  14404. case 39: /*right*/
  14405. case 68: /*D*/ sideSpeed = 0; break;
  14406. case 81: /*Q*/ doRoll = false; break;
  14407. case 69: /*E*/ doRoll = false; break;
  14408. case 82: /*R*/ upSpeed = 0; break;
  14409. case 70: /*F*/ upSpeed = 0; break;
  14410. }
  14411. };
  14412. function onMouseMove( event ) {
  14413. mouseX = ( event.clientX - windowHalfX ) / window.innerWidth;
  14414. mouseY = ( event.clientY - windowHalfY ) / window.innerHeight;
  14415. };
  14416. function onMouseDown ( event ) {
  14417. event.preventDefault();
  14418. event.stopPropagation();
  14419. switch ( event.button ) {
  14420. case 0: forwardSpeed = 1; break;
  14421. case 2: forwardSpeed = -1; break;
  14422. }
  14423. };
  14424. function onMouseUp ( event ) {
  14425. event.preventDefault();
  14426. event.stopPropagation();
  14427. switch ( event.button ) {
  14428. case 0: forwardSpeed = 0; break;
  14429. case 2: forwardSpeed = 0; break;
  14430. }
  14431. };
  14432. this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
  14433. this.domElement.addEventListener( 'mousemove', onMouseMove, false );
  14434. this.domElement.addEventListener( 'mousedown', onMouseDown, false );
  14435. this.domElement.addEventListener( 'mouseup', onMouseUp, false );
  14436. this.domElement.addEventListener( 'keydown', onKeyDown, false );
  14437. this.domElement.addEventListener( 'keyup', onKeyUp, false );
  14438. };
  14439. /**
  14440. * @author Eberhard Graether / http://egraether.com/
  14441. */
  14442. THREE.TrackballControls = function ( object, domElement ) {
  14443. THREE.EventTarget.call( this );
  14444. var _this = this,
  14445. STATE = { NONE : -1, ROTATE : 0, ZOOM : 1, PAN : 2 };
  14446. this.object = object;
  14447. this.domElement = ( domElement !== undefined ) ? domElement : document;
  14448. // API
  14449. this.enabled = true;
  14450. this.screen = { width: window.innerWidth, height: window.innerHeight, offsetLeft: 0, offsetTop: 0 };
  14451. this.radius = ( this.screen.width + this.screen.height ) / 4;
  14452. this.rotateSpeed = 1.0;
  14453. this.zoomSpeed = 1.2;
  14454. this.panSpeed = 0.3;
  14455. this.noRotate = false;
  14456. this.noZoom = false;
  14457. this.noPan = false;
  14458. this.staticMoving = false;
  14459. this.dynamicDampingFactor = 0.2;
  14460. this.minDistance = 0;
  14461. this.maxDistance = Infinity;
  14462. this.keys = [ 65 /*A*/, 83 /*S*/, 68 /*D*/ ];
  14463. // internals
  14464. this.target = new THREE.Vector3();
  14465. var lastPosition = new THREE.Vector3();
  14466. var _keyPressed = false,
  14467. _state = STATE.NONE,
  14468. _eye = new THREE.Vector3(),
  14469. _rotateStart = new THREE.Vector3(),
  14470. _rotateEnd = new THREE.Vector3(),
  14471. _zoomStart = new THREE.Vector2(),
  14472. _zoomEnd = new THREE.Vector2(),
  14473. _panStart = new THREE.Vector2(),
  14474. _panEnd = new THREE.Vector2();
  14475. // events
  14476. var changeEvent = { type: 'change' };
  14477. // methods
  14478. this.handleEvent = function ( event ) {
  14479. if ( typeof this[ event.type ] == 'function' ) {
  14480. this[ event.type ]( event );
  14481. }
  14482. };
  14483. this.getMouseOnScreen = function ( clientX, clientY ) {
  14484. return new THREE.Vector2(
  14485. ( clientX - _this.screen.offsetLeft ) / _this.radius * 0.5,
  14486. ( clientY - _this.screen.offsetTop ) / _this.radius * 0.5
  14487. );
  14488. };
  14489. this.getMouseProjectionOnBall = function ( clientX, clientY ) {
  14490. var mouseOnBall = new THREE.Vector3(
  14491. ( clientX - _this.screen.width * 0.5 - _this.screen.offsetLeft ) / _this.radius,
  14492. ( _this.screen.height * 0.5 + _this.screen.offsetTop - clientY ) / _this.radius,
  14493. 0.0
  14494. );
  14495. var length = mouseOnBall.length();
  14496. if ( length > 1.0 ) {
  14497. mouseOnBall.normalize();
  14498. } else {
  14499. mouseOnBall.z = Math.sqrt( 1.0 - length * length );
  14500. }
  14501. _eye.copy( _this.object.position ).subSelf( _this.target );
  14502. var projection = _this.object.up.clone().setLength( mouseOnBall.y );
  14503. projection.addSelf( _this.object.up.clone().crossSelf( _eye ).setLength( mouseOnBall.x ) );
  14504. projection.addSelf( _eye.setLength( mouseOnBall.z ) );
  14505. return projection;
  14506. };
  14507. this.rotateCamera = function () {
  14508. var angle = Math.acos( _rotateStart.dot( _rotateEnd ) / _rotateStart.length() / _rotateEnd.length() );
  14509. if ( angle ) {
  14510. var axis = ( new THREE.Vector3() ).cross( _rotateStart, _rotateEnd ).normalize(),
  14511. quaternion = new THREE.Quaternion();
  14512. angle *= _this.rotateSpeed;
  14513. quaternion.setFromAxisAngle( axis, -angle );
  14514. quaternion.multiplyVector3( _eye );
  14515. quaternion.multiplyVector3( _this.object.up );
  14516. quaternion.multiplyVector3( _rotateEnd );
  14517. if ( _this.staticMoving ) {
  14518. _rotateStart = _rotateEnd;
  14519. } else {
  14520. quaternion.setFromAxisAngle( axis, angle * ( _this.dynamicDampingFactor - 1.0 ) );
  14521. quaternion.multiplyVector3( _rotateStart );
  14522. }
  14523. }
  14524. };
  14525. this.zoomCamera = function () {
  14526. var factor = 1.0 + ( _zoomEnd.y - _zoomStart.y ) * _this.zoomSpeed;
  14527. if ( factor !== 1.0 && factor > 0.0 ) {
  14528. _eye.multiplyScalar( factor );
  14529. if ( _this.staticMoving ) {
  14530. _zoomStart = _zoomEnd;
  14531. } else {
  14532. _zoomStart.y += ( _zoomEnd.y - _zoomStart.y ) * this.dynamicDampingFactor;
  14533. }
  14534. }
  14535. };
  14536. this.panCamera = function () {
  14537. var mouseChange = _panEnd.clone().subSelf( _panStart );
  14538. if ( mouseChange.lengthSq() ) {
  14539. mouseChange.multiplyScalar( _eye.length() * _this.panSpeed );
  14540. var pan = _eye.clone().crossSelf( _this.object.up ).setLength( mouseChange.x );
  14541. pan.addSelf( _this.object.up.clone().setLength( mouseChange.y ) );
  14542. _this.object.position.addSelf( pan );
  14543. _this.target.addSelf( pan );
  14544. if ( _this.staticMoving ) {
  14545. _panStart = _panEnd;
  14546. } else {
  14547. _panStart.addSelf( mouseChange.sub( _panEnd, _panStart ).multiplyScalar( _this.dynamicDampingFactor ) );
  14548. }
  14549. }
  14550. };
  14551. this.checkDistances = function () {
  14552. if ( !_this.noZoom || !_this.noPan ) {
  14553. if ( _this.object.position.lengthSq() > _this.maxDistance * _this.maxDistance ) {
  14554. _this.object.position.setLength( _this.maxDistance );
  14555. }
  14556. if ( _eye.lengthSq() < _this.minDistance * _this.minDistance ) {
  14557. _this.object.position.add( _this.target, _eye.setLength( _this.minDistance ) );
  14558. }
  14559. }
  14560. };
  14561. this.update = function () {
  14562. _eye.copy( _this.object.position ).subSelf( _this.target );
  14563. if ( !_this.noRotate ) {
  14564. _this.rotateCamera();
  14565. }
  14566. if ( !_this.noZoom ) {
  14567. _this.zoomCamera();
  14568. }
  14569. if ( !_this.noPan ) {
  14570. _this.panCamera();
  14571. }
  14572. _this.object.position.add( _this.target, _eye );
  14573. _this.checkDistances();
  14574. _this.object.lookAt( _this.target );
  14575. if ( lastPosition.distanceTo( _this.object.position ) > 0 ) {
  14576. _this.dispatchEvent( changeEvent );
  14577. lastPosition.copy( _this.object.position );
  14578. }
  14579. };
  14580. // listeners
  14581. function keydown( event ) {
  14582. if ( ! _this.enabled ) return;
  14583. if ( _state !== STATE.NONE ) {
  14584. return;
  14585. } else if ( event.keyCode === _this.keys[ STATE.ROTATE ] && !_this.noRotate ) {
  14586. _state = STATE.ROTATE;
  14587. } else if ( event.keyCode === _this.keys[ STATE.ZOOM ] && !_this.noZoom ) {
  14588. _state = STATE.ZOOM;
  14589. } else if ( event.keyCode === _this.keys[ STATE.PAN ] && !_this.noPan ) {
  14590. _state = STATE.PAN;
  14591. }
  14592. if ( _state !== STATE.NONE ) {
  14593. _keyPressed = true;
  14594. }
  14595. };
  14596. function keyup( event ) {
  14597. if ( ! _this.enabled ) return;
  14598. if ( _state !== STATE.NONE ) {
  14599. _state = STATE.NONE;
  14600. }
  14601. };
  14602. function mousedown( event ) {
  14603. if ( ! _this.enabled ) return;
  14604. event.preventDefault();
  14605. event.stopPropagation();
  14606. if ( _state === STATE.NONE ) {
  14607. _state = event.button;
  14608. if ( _state === STATE.ROTATE && !_this.noRotate ) {
  14609. _rotateStart = _rotateEnd = _this.getMouseProjectionOnBall( event.clientX, event.clientY );
  14610. } else if ( _state === STATE.ZOOM && !_this.noZoom ) {
  14611. _zoomStart = _zoomEnd = _this.getMouseOnScreen( event.clientX, event.clientY );
  14612. } else if ( !this.noPan ) {
  14613. _panStart = _panEnd = _this.getMouseOnScreen( event.clientX, event.clientY );
  14614. }
  14615. }
  14616. };
  14617. function mousemove( event ) {
  14618. if ( ! _this.enabled ) return;
  14619. if ( _keyPressed ) {
  14620. _rotateStart = _rotateEnd = _this.getMouseProjectionOnBall( event.clientX, event.clientY );
  14621. _zoomStart = _zoomEnd = _this.getMouseOnScreen( event.clientX, event.clientY );
  14622. _panStart = _panEnd = _this.getMouseOnScreen( event.clientX, event.clientY );
  14623. _keyPressed = false;
  14624. }
  14625. if ( _state === STATE.NONE ) {
  14626. return;
  14627. } else if ( _state === STATE.ROTATE && !_this.noRotate ) {
  14628. _rotateEnd = _this.getMouseProjectionOnBall( event.clientX, event.clientY );
  14629. } else if ( _state === STATE.ZOOM && !_this.noZoom ) {
  14630. _zoomEnd = _this.getMouseOnScreen( event.clientX, event.clientY );
  14631. } else if ( _state === STATE.PAN && !_this.noPan ) {
  14632. _panEnd = _this.getMouseOnScreen( event.clientX, event.clientY );
  14633. }
  14634. };
  14635. function mouseup( event ) {
  14636. if ( ! _this.enabled ) return;
  14637. event.preventDefault();
  14638. event.stopPropagation();
  14639. _state = STATE.NONE;
  14640. };
  14641. this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
  14642. this.domElement.addEventListener( 'mousemove', mousemove, false );
  14643. this.domElement.addEventListener( 'mousedown', mousedown, false );
  14644. this.domElement.addEventListener( 'mouseup', mouseup, false );
  14645. window.addEventListener( 'keydown', keydown, false );
  14646. window.addEventListener( 'keyup', keyup, false );
  14647. };
  14648. /**
  14649. * @author mr.doob / http://mrdoob.com/
  14650. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  14651. */
  14652. THREE.CubeGeometry = function ( width, height, depth, segmentsWidth, segmentsHeight, segmentsDepth, materials, sides ) {
  14653. THREE.Geometry.call( this );
  14654. var scope = this,
  14655. width_half = width / 2,
  14656. height_half = height / 2,
  14657. depth_half = depth / 2;
  14658. var mpx, mpy, mpz, mnx, mny, mnz;
  14659. if ( materials !== undefined ) {
  14660. if ( materials instanceof Array ) {
  14661. this.materials = materials;
  14662. } else {
  14663. this.materials = [];
  14664. for ( var i = 0; i < 6; i ++ ) {
  14665. this.materials.push( materials );
  14666. }
  14667. }
  14668. mpx = 0; mnx = 1; mpy = 2; mny = 3; mpz = 4; mnz = 5;
  14669. } else {
  14670. this.materials = [];
  14671. }
  14672. this.sides = { px: true, nx: true, py: true, ny: true, pz: true, nz: true };
  14673. if ( sides != undefined ) {
  14674. for ( var s in sides ) {
  14675. if ( this.sides[ s ] !== undefined ) {
  14676. this.sides[ s ] = sides[ s ];
  14677. }
  14678. }
  14679. }
  14680. this.sides.px && buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half, mpx ); // px
  14681. this.sides.nx && buildPlane( 'z', 'y', 1, - 1, depth, height, - width_half, mnx ); // nx
  14682. this.sides.py && buildPlane( 'x', 'z', 1, 1, width, depth, height_half, mpy ); // py
  14683. this.sides.ny && buildPlane( 'x', 'z', 1, - 1, width, depth, - height_half, mny ); // ny
  14684. this.sides.pz && buildPlane( 'x', 'y', 1, - 1, width, height, depth_half, mpz ); // pz
  14685. this.sides.nz && buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half, mnz ); // nz
  14686. function buildPlane( u, v, udir, vdir, width, height, depth, material ) {
  14687. var w, ix, iy,
  14688. gridX = segmentsWidth || 1,
  14689. gridY = segmentsHeight || 1,
  14690. width_half = width / 2,
  14691. height_half = height / 2,
  14692. offset = scope.vertices.length;
  14693. if ( ( u === 'x' && v === 'y' ) || ( u === 'y' && v === 'x' ) ) {
  14694. w = 'z';
  14695. } else if ( ( u === 'x' && v === 'z' ) || ( u === 'z' && v === 'x' ) ) {
  14696. w = 'y';
  14697. gridY = segmentsDepth || 1;
  14698. } else if ( ( u === 'z' && v === 'y' ) || ( u === 'y' && v === 'z' ) ) {
  14699. w = 'x';
  14700. gridX = segmentsDepth || 1;
  14701. }
  14702. var gridX1 = gridX + 1,
  14703. gridY1 = gridY + 1,
  14704. segment_width = width / gridX,
  14705. segment_height = height / gridY,
  14706. normal = new THREE.Vector3();
  14707. normal[ w ] = depth > 0 ? 1 : - 1;
  14708. for ( iy = 0; iy < gridY1; iy ++ ) {
  14709. for ( ix = 0; ix < gridX1; ix ++ ) {
  14710. var vector = new THREE.Vector3();
  14711. vector[ u ] = ( ix * segment_width - width_half ) * udir;
  14712. vector[ v ] = ( iy * segment_height - height_half ) * vdir;
  14713. vector[ w ] = depth;
  14714. scope.vertices.push( vector );
  14715. }
  14716. }
  14717. for ( iy = 0; iy < gridY; iy++ ) {
  14718. for ( ix = 0; ix < gridX; ix++ ) {
  14719. var a = ix + gridX1 * iy;
  14720. var b = ix + gridX1 * ( iy + 1 );
  14721. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  14722. var d = ( ix + 1 ) + gridX1 * iy;
  14723. var face = new THREE.Face4( a + offset, b + offset, c + offset, d + offset );
  14724. face.normal.copy( normal );
  14725. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone(), normal.clone() );
  14726. face.materialIndex = material;
  14727. scope.faces.push( face );
  14728. scope.faceVertexUvs[ 0 ].push( [
  14729. new THREE.UV( ix / gridX, iy / gridY ),
  14730. new THREE.UV( ix / gridX, ( iy + 1 ) / gridY ),
  14731. new THREE.UV( ( ix + 1 ) / gridX, ( iy + 1 ) / gridY ),
  14732. new THREE.UV( ( ix + 1 ) / gridX, iy / gridY )
  14733. ] );
  14734. }
  14735. }
  14736. }
  14737. this.computeCentroids();
  14738. this.mergeVertices();
  14739. };
  14740. THREE.CubeGeometry.prototype = new THREE.Geometry();
  14741. THREE.CubeGeometry.prototype.constructor = THREE.CubeGeometry;
  14742. /**
  14743. * @author mr.doob / http://mrdoob.com/
  14744. */
  14745. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, segmentsRadius, segmentsHeight, openEnded ) {
  14746. THREE.Geometry.call( this );
  14747. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  14748. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  14749. height = height !== undefined ? height : 100;
  14750. var heightHalf = height / 2;
  14751. var segmentsX = segmentsRadius || 8;
  14752. var segmentsY = segmentsHeight || 1;
  14753. var x, y, vertices = [], uvs = [];
  14754. for ( y = 0; y <= segmentsY; y ++ ) {
  14755. var verticesRow = [];
  14756. var uvsRow = [];
  14757. var v = y / segmentsY;
  14758. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  14759. for ( x = 0; x <= segmentsX; x ++ ) {
  14760. var u = x / segmentsX;
  14761. var vertex = new THREE.Vector3();
  14762. vertex.x = radius * Math.sin( u * Math.PI * 2 );
  14763. vertex.y = - v * height + heightHalf;
  14764. vertex.z = radius * Math.cos( u * Math.PI * 2 );
  14765. this.vertices.push( vertex );
  14766. verticesRow.push( this.vertices.length - 1 );
  14767. uvsRow.push( new THREE.UV( u, v ) );
  14768. }
  14769. vertices.push( verticesRow );
  14770. uvs.push( uvsRow );
  14771. }
  14772. for ( y = 0; y < segmentsY; y ++ ) {
  14773. for ( x = 0; x < segmentsX; x ++ ) {
  14774. var v1 = vertices[ y ][ x ];
  14775. var v2 = vertices[ y + 1 ][ x ];
  14776. var v3 = vertices[ y + 1 ][ x + 1 ];
  14777. var v4 = vertices[ y ][ x + 1 ];
  14778. // FIXME: These normals aren't right for cones.
  14779. var n1 = this.vertices[ v1 ].clone().setY( 0 ).normalize();
  14780. var n2 = this.vertices[ v2 ].clone().setY( 0 ).normalize();
  14781. var n3 = this.vertices[ v3 ].clone().setY( 0 ).normalize();
  14782. var n4 = this.vertices[ v4 ].clone().setY( 0 ).normalize();
  14783. var uv1 = uvs[ y ][ x ].clone();
  14784. var uv2 = uvs[ y + 1 ][ x ].clone();
  14785. var uv3 = uvs[ y + 1 ][ x + 1 ].clone();
  14786. var uv4 = uvs[ y ][ x + 1 ].clone();
  14787. this.faces.push( new THREE.Face4( v1, v2, v3, v4, [ n1, n2, n3, n4 ] ) );
  14788. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3, uv4 ] );
  14789. }
  14790. }
  14791. // top cap
  14792. if ( !openEnded && radiusTop > 0 ) {
  14793. this.vertices.push( new THREE.Vector3( 0, heightHalf, 0 ) );
  14794. for ( x = 0; x < segmentsX; x ++ ) {
  14795. var v1 = vertices[ 0 ][ x ];
  14796. var v2 = vertices[ 0 ][ x + 1 ];
  14797. var v3 = this.vertices.length - 1;
  14798. var n1 = new THREE.Vector3( 0, 1, 0 );
  14799. var n2 = new THREE.Vector3( 0, 1, 0 );
  14800. var n3 = new THREE.Vector3( 0, 1, 0 );
  14801. var uv1 = uvs[ 0 ][ x ].clone();
  14802. var uv2 = uvs[ 0 ][ x + 1 ].clone();
  14803. var uv3 = new THREE.UV( uv2.u, 0 );
  14804. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  14805. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  14806. }
  14807. }
  14808. // bottom cap
  14809. if ( !openEnded && radiusBottom > 0 ) {
  14810. this.vertices.push( new THREE.Vector3( 0, - heightHalf, 0 ) );
  14811. for ( x = 0; x < segmentsX; x ++ ) {
  14812. var v1 = vertices[ y ][ x + 1 ];
  14813. var v2 = vertices[ y ][ x ];
  14814. var v3 = this.vertices.length - 1;
  14815. var n1 = new THREE.Vector3( 0, - 1, 0 );
  14816. var n2 = new THREE.Vector3( 0, - 1, 0 );
  14817. var n3 = new THREE.Vector3( 0, - 1, 0 );
  14818. var uv1 = uvs[ y ][ x + 1 ].clone();
  14819. var uv2 = uvs[ y ][ x ].clone();
  14820. var uv3 = new THREE.UV( uv2.u, 1 );
  14821. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  14822. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  14823. }
  14824. }
  14825. this.computeCentroids();
  14826. this.computeFaceNormals();
  14827. }
  14828. THREE.CylinderGeometry.prototype = new THREE.Geometry();
  14829. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  14830. /**
  14831. * @author zz85 / http://www.lab4games.net/zz85/blog
  14832. *
  14833. * Creates extruded geometry from a path shape.
  14834. *
  14835. * parameters = {
  14836. *
  14837. * size: <float>, // size of the text
  14838. * height: <float>, // thickness to extrude text
  14839. * curveSegments: <int>, // number of points on the curves
  14840. * steps: <int>, // number of points for z-side extrusions / used for subdividing segements of extrude spline too
  14841. amount: <int>, // Amount
  14842. *
  14843. * bevelEnabled: <bool>, // turn on bevel
  14844. * bevelThickness: <float>, // how deep into text bevel goes
  14845. * bevelSize: <float>, // how far from text outline is bevel
  14846. * bevelSegments: <int>, // number of bevel layers
  14847. *
  14848. * extrudePath: <THREE.CurvePath> // 2d/3d spline path to extrude shape orthogonality to
  14849. * bendPath: <THREE.CurvePath> // 2d path for bend the shape around x/y plane
  14850. *
  14851. * material: <int> // material index for front and back faces
  14852. * extrudeMaterial: <int> // material index for extrusion and beveled faces
  14853. *
  14854. * }
  14855. **/
  14856. THREE.ExtrudeGeometry = function( shapes, options ) {
  14857. if ( typeof( shapes ) === "undefined" ) {
  14858. shapes = [];
  14859. return;
  14860. }
  14861. THREE.Geometry.call( this );
  14862. shapes = shapes instanceof Array ? shapes : [ shapes ];
  14863. this.shapebb = shapes[ shapes.length - 1 ].getBoundingBox();
  14864. this.addShapeList( shapes, options );
  14865. this.computeCentroids();
  14866. this.computeFaceNormals();
  14867. // can't really use automatic vertex normals
  14868. // as then front and back sides get smoothed too
  14869. // should do separate smoothing just for sides
  14870. //this.computeVertexNormals();
  14871. //console.log( "took", ( Date.now() - startTime ) );
  14872. };
  14873. THREE.ExtrudeGeometry.prototype = new THREE.Geometry();
  14874. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  14875. THREE.ExtrudeGeometry.prototype.addShapeList = function(shapes, options) {
  14876. var sl = shapes.length;
  14877. for ( var s = 0; s < sl; s ++ ) {
  14878. var shape = shapes[ s ];
  14879. this.addShape( shape, options );
  14880. }
  14881. };
  14882. THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
  14883. var amount = options.amount !== undefined ? options.amount : 100;
  14884. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  14885. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  14886. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  14887. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  14888. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  14889. var steps = options.steps !== undefined ? options.steps : 1;
  14890. var bendPath = options.bendPath;
  14891. var extrudePath = options.extrudePath;
  14892. var extrudePts, extrudeByPath = false;
  14893. var material = options.material;
  14894. var extrudeMaterial = options.extrudeMaterial;
  14895. var shapebb = this.shapebb;
  14896. //shapebb = shape.getBoundingBox();
  14897. var splineTube, binormal, normal, position2;
  14898. if ( extrudePath ) {
  14899. extrudePts = extrudePath.getSpacedPoints( steps );
  14900. extrudeByPath = true;
  14901. bevelEnabled = false; // bevels not supported for path extrusion
  14902. // SETUP TNB variables
  14903. // Reuse TNB from TubeGeomtry for now.
  14904. // TODO1 - have a .isClosed in spline?
  14905. splineTube = new THREE.TubeGeometry.FrenetFrames(extrudePath, steps, false);
  14906. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  14907. binormal = new THREE.Vector3();
  14908. normal = new THREE.Vector3();
  14909. position2 = new THREE.Vector3();
  14910. }
  14911. // Safeguards if bevels are not enabled
  14912. if ( ! bevelEnabled ) {
  14913. bevelSegments = 0;
  14914. bevelThickness = 0;
  14915. bevelSize = 0;
  14916. }
  14917. // Variables initalization
  14918. var ahole, h, hl; // looping of holes
  14919. var scope = this;
  14920. var bevelPoints = [];
  14921. var shapesOffset = this.vertices.length;
  14922. if ( bendPath ) {
  14923. shape.addWrapPath( bendPath );
  14924. }
  14925. var shapePoints = shape.extractPoints();
  14926. var vertices = shapePoints.shape;
  14927. var holes = shapePoints.holes;
  14928. var reverse = !THREE.Shape.Utils.isClockWise( vertices ) ;
  14929. if ( reverse ) {
  14930. vertices = vertices.reverse();
  14931. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  14932. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  14933. ahole = holes[ h ];
  14934. if ( THREE.Shape.Utils.isClockWise( ahole ) ) {
  14935. holes[ h ] = ahole.reverse();
  14936. }
  14937. }
  14938. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  14939. }
  14940. var faces = THREE.Shape.Utils.triangulateShape ( vertices, holes );
  14941. //var faces = THREE.Shape.Utils.triangulate2( vertices, holes );
  14942. // Would it be better to move points after triangulation?
  14943. // shapePoints = shape.extractAllPointsWithBend( curveSegments, bendPath );
  14944. // vertices = shapePoints.shape;
  14945. // holes = shapePoints.holes;
  14946. //console.log(faces);
  14947. ////
  14948. /// Handle Vertices
  14949. ////
  14950. var contour = vertices; // vertices has all points but contour has only points of circumference
  14951. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  14952. ahole = holes[ h ];
  14953. vertices = vertices.concat( ahole );
  14954. }
  14955. function scalePt2 ( pt, vec, size ) {
  14956. if ( !vec ) console.log( "die" );
  14957. return vec.clone().multiplyScalar( size ).addSelf( pt );
  14958. }
  14959. var b, bs, t, z,
  14960. vert, vlen = vertices.length,
  14961. face, flen = faces.length,
  14962. cont, clen = contour.length;
  14963. //------
  14964. // Find directions for point movement
  14965. //
  14966. var RAD_TO_DEGREES = 180 / Math.PI;
  14967. function getBevelVec( pt_i, pt_j, pt_k ) {
  14968. // Algorithm 2
  14969. return getBevelVec2( pt_i, pt_j, pt_k );
  14970. }
  14971. function getBevelVec1( pt_i, pt_j, pt_k ) {
  14972. var anglea = Math.atan2( pt_j.y - pt_i.y, pt_j.x - pt_i.x );
  14973. var angleb = Math.atan2( pt_k.y - pt_i.y, pt_k.x - pt_i.x );
  14974. if ( anglea > angleb ) {
  14975. angleb += Math.PI * 2;
  14976. }
  14977. var anglec = ( anglea + angleb ) / 2;
  14978. //console.log('angle1', anglea * RAD_TO_DEGREES,'angle2', angleb * RAD_TO_DEGREES, 'anglec', anglec *RAD_TO_DEGREES);
  14979. var x = - Math.cos( anglec );
  14980. var y = - Math.sin( anglec );
  14981. var vec = new THREE.Vector2( x, y ); //.normalize();
  14982. return vec;
  14983. }
  14984. function getBevelVec2( pt_i, pt_j, pt_k ) {
  14985. var a = THREE.ExtrudeGeometry.__v1,
  14986. b = THREE.ExtrudeGeometry.__v2,
  14987. v_hat = THREE.ExtrudeGeometry.__v3,
  14988. w_hat = THREE.ExtrudeGeometry.__v4,
  14989. p = THREE.ExtrudeGeometry.__v5,
  14990. q = THREE.ExtrudeGeometry.__v6,
  14991. v, w,
  14992. v_dot_w_hat, q_sub_p_dot_w_hat,
  14993. s, intersection;
  14994. // good reading for line-line intersection
  14995. // http://sputsoft.com/blog/2010/03/line-line-intersection.html
  14996. // define a as vector j->i
  14997. // define b as vectot k->i
  14998. a.set( pt_i.x - pt_j.x, pt_i.y - pt_j.y );
  14999. b.set( pt_i.x - pt_k.x, pt_i.y - pt_k.y );
  15000. // get unit vectors
  15001. v = a.normalize();
  15002. w = b.normalize();
  15003. // normals from pt i
  15004. v_hat.set( -v.y, v.x );
  15005. w_hat.set( w.y, -w.x );
  15006. // pts from i
  15007. p.copy( pt_i ).addSelf( v_hat );
  15008. q.copy( pt_i ).addSelf( w_hat );
  15009. if ( p.equals( q ) ) {
  15010. //console.log("Warning: lines are straight");
  15011. return w_hat.clone();
  15012. }
  15013. // Points from j, k. helps prevents points cross overover most of the time
  15014. p.copy( pt_j ).addSelf( v_hat );
  15015. q.copy( pt_k ).addSelf( w_hat );
  15016. v_dot_w_hat = v.dot( w_hat );
  15017. q_sub_p_dot_w_hat = q.subSelf( p ).dot( w_hat );
  15018. // We should not reach these conditions
  15019. if ( v_dot_w_hat === 0 ) {
  15020. console.log( "Either infinite or no solutions!" );
  15021. if ( q_sub_p_dot_w_hat === 0 ) {
  15022. console.log( "Its finite solutions." );
  15023. } else {
  15024. console.log( "Too bad, no solutions." );
  15025. }
  15026. }
  15027. s = q_sub_p_dot_w_hat / v_dot_w_hat;
  15028. if ( s < 0 ) {
  15029. // in case of emergecy, revert to algorithm 1.
  15030. return getBevelVec1( pt_i, pt_j, pt_k );
  15031. }
  15032. intersection = v.multiplyScalar( s ).addSelf( p );
  15033. return intersection.subSelf( pt_i ).clone(); // Don't normalize!, otherwise sharp corners become ugly
  15034. }
  15035. var contourMovements = [];
  15036. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  15037. if ( j === il ) j = 0;
  15038. if ( k === il ) k = 0;
  15039. // (j)---(i)---(k)
  15040. // console.log('i,j,k', i, j , k)
  15041. var pt_i = contour[ i ];
  15042. var pt_j = contour[ j ];
  15043. var pt_k = contour[ k ];
  15044. contourMovements[ i ]= getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  15045. }
  15046. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  15047. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  15048. ahole = holes[ h ];
  15049. oneHoleMovements = [];
  15050. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  15051. if ( j === il ) j = 0;
  15052. if ( k === il ) k = 0;
  15053. // (j)---(i)---(k)
  15054. oneHoleMovements[ i ]= getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  15055. }
  15056. holesMovements.push( oneHoleMovements );
  15057. verticesMovements = verticesMovements.concat( oneHoleMovements );
  15058. }
  15059. // Loop bevelSegments, 1 for the front, 1 for the back
  15060. for ( b = 0; b < bevelSegments; b ++ ) {
  15061. //for ( b = bevelSegments; b > 0; b -- ) {
  15062. t = b / bevelSegments;
  15063. z = bevelThickness * ( 1 - t );
  15064. //z = bevelThickness * t;
  15065. bs = bevelSize * ( Math.sin ( t * Math.PI/2 ) ) ; // curved
  15066. //bs = bevelSize * t ; // linear
  15067. // contract shape
  15068. for ( i = 0, il = contour.length; i < il; i ++ ) {
  15069. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  15070. //vert = scalePt( contour[ i ], contourCentroid, bs, false );
  15071. v( vert.x, vert.y, - z );
  15072. }
  15073. // expand holes
  15074. for ( h = 0, hl = holes.length; h < hl; h++ ) {
  15075. ahole = holes[ h ];
  15076. oneHoleMovements = holesMovements[ h ];
  15077. for ( i = 0, il = ahole.length; i < il; i++ ) {
  15078. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  15079. //vert = scalePt( ahole[ i ], holesCentroids[ h ], bs, true );
  15080. v( vert.x, vert.y, -z );
  15081. }
  15082. }
  15083. }
  15084. bs = bevelSize;
  15085. // Back facing vertices
  15086. for ( i = 0; i < vlen; i ++ ) {
  15087. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  15088. if ( !extrudeByPath ) {
  15089. v( vert.x, vert.y, 0 );
  15090. } else {
  15091. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  15092. normal.copy(splineTube.normals[0]).multiplyScalar(vert.x);
  15093. binormal.copy(splineTube.binormals[0]).multiplyScalar(vert.y);
  15094. position2.copy(extrudePts[0]).addSelf(normal).addSelf(binormal);
  15095. v(position2.x, position2.y, position2.z);
  15096. }
  15097. }
  15098. // Add stepped vertices...
  15099. // Including front facing vertices
  15100. var s;
  15101. for ( s = 1; s <= steps; s ++ ) {
  15102. for ( i = 0; i < vlen; i ++ ) {
  15103. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  15104. if ( !extrudeByPath ) {
  15105. v( vert.x, vert.y, amount / steps * s );
  15106. } else {
  15107. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  15108. normal.copy(splineTube.normals[s]).multiplyScalar(vert.x);
  15109. binormal.copy(splineTube.binormals[s]).multiplyScalar(vert.y);
  15110. position2.copy(extrudePts[s]).addSelf(normal).addSelf(binormal);
  15111. v(position2.x, position2.y, position2.z );
  15112. }
  15113. }
  15114. }
  15115. // Add bevel segments planes
  15116. //for ( b = 1; b <= bevelSegments; b ++ ) {
  15117. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  15118. t = b / bevelSegments;
  15119. z = bevelThickness * ( 1 - t );
  15120. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  15121. bs = bevelSize * Math.sin ( t * Math.PI/2 ) ;
  15122. // contract shape
  15123. for ( i = 0, il = contour.length; i < il; i ++ ) {
  15124. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  15125. v( vert.x, vert.y, amount + z );
  15126. }
  15127. // expand holes
  15128. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  15129. ahole = holes[ h ];
  15130. oneHoleMovements = holesMovements[ h ];
  15131. for ( i = 0, il = ahole.length; i < il; i++ ) {
  15132. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  15133. if ( !extrudeByPath ) {
  15134. v( vert.x, vert.y, amount + z );
  15135. } else {
  15136. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  15137. }
  15138. }
  15139. }
  15140. }
  15141. // set UV generator
  15142. var uvgen = THREE.ExtrudeGeometry.WorldUVGenerator;
  15143. ////
  15144. /// Handle Faces
  15145. ////
  15146. // Top and bottom faces
  15147. buildLidFaces();
  15148. // Sides faces
  15149. buildSideFaces();
  15150. ///// Internal functions
  15151. function buildLidFaces() {
  15152. if ( bevelEnabled ) {
  15153. var layer = 0 ; // steps + 1
  15154. var offset = vlen * layer;
  15155. // Bottom faces
  15156. for ( i = 0; i < flen; i ++ ) {
  15157. face = faces[ i ];
  15158. f3( face[ 2 ]+ offset, face[ 1 ]+ offset, face[ 0 ] + offset, true );
  15159. }
  15160. layer = steps + bevelSegments * 2;
  15161. offset = vlen * layer;
  15162. // Top faces
  15163. for ( i = 0; i < flen; i ++ ) {
  15164. face = faces[ i ];
  15165. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset, false );
  15166. }
  15167. } else {
  15168. // Bottom faces
  15169. for ( i = 0; i < flen; i++ ) {
  15170. face = faces[ i ];
  15171. f3( face[ 2 ], face[ 1 ], face[ 0 ], true );
  15172. }
  15173. // Top faces
  15174. for ( i = 0; i < flen; i ++ ) {
  15175. face = faces[ i ];
  15176. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps, false );
  15177. }
  15178. }
  15179. }
  15180. // Create faces for the z-sides of the shape
  15181. function buildSideFaces() {
  15182. var layeroffset = 0;
  15183. sidewalls( contour, layeroffset );
  15184. layeroffset += contour.length;
  15185. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  15186. ahole = holes[ h ];
  15187. sidewalls( ahole, layeroffset );
  15188. //, true
  15189. layeroffset += ahole.length;
  15190. }
  15191. }
  15192. function sidewalls( contour, layeroffset ) {
  15193. var j, k;
  15194. i = contour.length;
  15195. while ( --i >= 0 ) {
  15196. j = i;
  15197. k = i - 1;
  15198. if ( k < 0 ) k = contour.length - 1;
  15199. //console.log('b', i,j, i-1, k,vertices.length);
  15200. var s = 0, sl = steps + bevelSegments * 2;
  15201. for ( s = 0; s < sl; s ++ ) {
  15202. var slen1 = vlen * s;
  15203. var slen2 = vlen * ( s + 1 );
  15204. var a = layeroffset + j + slen1,
  15205. b = layeroffset + k + slen1,
  15206. c = layeroffset + k + slen2,
  15207. d = layeroffset + j + slen2;
  15208. f4( a, b, c, d, contour, s, sl );
  15209. }
  15210. }
  15211. }
  15212. function v( x, y, z ) {
  15213. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  15214. }
  15215. function f3( a, b, c, isBottom ) {
  15216. a += shapesOffset;
  15217. b += shapesOffset;
  15218. c += shapesOffset;
  15219. // normal, color, material
  15220. scope.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  15221. var uvs = isBottom ? uvgen.generateBottomUV( scope, shape, options, a, b, c)
  15222. : uvgen.generateTopUV( scope, shape, options, a, b, c);
  15223. scope.faceVertexUvs[ 0 ].push(uvs);
  15224. }
  15225. function f4( a, b, c, d, wallContour, stepIndex, stepsLength ) {
  15226. a += shapesOffset;
  15227. b += shapesOffset;
  15228. c += shapesOffset;
  15229. d += shapesOffset;
  15230. scope.faces.push( new THREE.Face4( a, b, c, d, null, null, extrudeMaterial ) );
  15231. var uvs = uvgen.generateSideWallUV( scope, shape, wallContour, options, a, b, c, d, stepIndex, stepsLength);
  15232. scope.faceVertexUvs[ 0 ].push(uvs);
  15233. }
  15234. };
  15235. THREE.ExtrudeGeometry.WorldUVGenerator = {
  15236. generateTopUV: function( geometry, extrudedShape, extrudeOptions, indexA, indexB, indexC) {
  15237. var ax = geometry.vertices[ indexA ].x,
  15238. ay = geometry.vertices[ indexA ].y,
  15239. bx = geometry.vertices[ indexB ].x,
  15240. by = geometry.vertices[ indexB ].y,
  15241. cx = geometry.vertices[ indexC ].x,
  15242. cy = geometry.vertices[ indexC ].y;
  15243. return [
  15244. new THREE.UV( ax, 1 - ay ),
  15245. new THREE.UV( bx, 1 - by ),
  15246. new THREE.UV( cx, 1 - cy )
  15247. ];
  15248. },
  15249. generateBottomUV: function( geometry, extrudedShape, extrudeOptions, indexA, indexB, indexC) {
  15250. return this.generateTopUV( geometry, extrudedShape, extrudeOptions, indexA, indexB, indexC );
  15251. },
  15252. generateSideWallUV: function( geometry, extrudedShape, wallContour, extrudeOptions,
  15253. indexA, indexB, indexC, indexD, stepIndex, stepsLength) {
  15254. var ax = geometry.vertices[ indexA ].x,
  15255. ay = geometry.vertices[ indexA ].y,
  15256. az = geometry.vertices[ indexA ].z,
  15257. bx = geometry.vertices[ indexB ].x,
  15258. by = geometry.vertices[ indexB ].y,
  15259. bz = geometry.vertices[ indexB ].z,
  15260. cx = geometry.vertices[ indexC ].x,
  15261. cy = geometry.vertices[ indexC ].y,
  15262. cz = geometry.vertices[ indexC ].z,
  15263. dx = geometry.vertices[ indexD ].x,
  15264. dy = geometry.vertices[ indexD ].y,
  15265. dz = geometry.vertices[ indexD ].z;
  15266. if ( Math.abs( ay - by ) < 0.01 ) {
  15267. return [
  15268. new THREE.UV( ax, az ),
  15269. new THREE.UV( bx, bz ),
  15270. new THREE.UV( cx, cz ),
  15271. new THREE.UV( dx, dz )
  15272. ];
  15273. } else {
  15274. return [
  15275. new THREE.UV( ay, az ),
  15276. new THREE.UV( by, bz ),
  15277. new THREE.UV( cy, cz ),
  15278. new THREE.UV( dy, dz )
  15279. ];
  15280. }
  15281. }
  15282. };
  15283. THREE.ExtrudeGeometry.__v1 = new THREE.Vector2();
  15284. THREE.ExtrudeGeometry.__v2 = new THREE.Vector2();
  15285. THREE.ExtrudeGeometry.__v3 = new THREE.Vector2();
  15286. THREE.ExtrudeGeometry.__v4 = new THREE.Vector2();
  15287. THREE.ExtrudeGeometry.__v5 = new THREE.Vector2();
  15288. THREE.ExtrudeGeometry.__v6 = new THREE.Vector2();
  15289. /**
  15290. * @author astrodud / http://astrodud.isgreat.org/
  15291. * @author zz85 / https://github.com/zz85
  15292. */
  15293. THREE.LatheGeometry = function ( points, steps, angle ) {
  15294. THREE.Geometry.call( this );
  15295. var _steps = steps || 12;
  15296. var _angle = angle || 2 * Math.PI;
  15297. var _newV = [];
  15298. var _matrix = new THREE.Matrix4().makeRotationZ( _angle / _steps );
  15299. for ( var j = 0; j < points.length; j ++ ) {
  15300. _newV[ j ] = points[ j ].clone();
  15301. this.vertices.push( _newV[ j ] );
  15302. }
  15303. var i, il = _steps + 1;
  15304. for ( i = 0; i < il; i ++ ) {
  15305. for ( var j = 0; j < _newV.length; j ++ ) {
  15306. _newV[ j ] = _matrix.multiplyVector3( _newV[ j ].clone() );
  15307. this.vertices.push( _newV[ j ] );
  15308. }
  15309. }
  15310. for ( i = 0; i < _steps; i ++ ) {
  15311. for ( var k = 0, kl = points.length; k < kl - 1; k ++ ) {
  15312. var a = i * kl + k;
  15313. var b = ( ( i + 1 ) % il ) * kl + k;
  15314. var c = ( ( i + 1 ) % il ) * kl + ( k + 1 ) % kl;
  15315. var d = i * kl + ( k + 1 ) % kl;
  15316. this.faces.push( new THREE.Face4( a, b, c, d ) );
  15317. this.faceVertexUvs[ 0 ].push( [
  15318. new THREE.UV( 1 - i / _steps, k / kl ),
  15319. new THREE.UV( 1 - ( i + 1 ) / _steps, k / kl ),
  15320. new THREE.UV( 1 - ( i + 1 ) / _steps, ( k + 1 ) / kl ),
  15321. new THREE.UV( 1 - i / _steps, ( k + 1 ) / kl )
  15322. ] );
  15323. }
  15324. }
  15325. this.computeCentroids();
  15326. this.computeFaceNormals();
  15327. this.computeVertexNormals();
  15328. };
  15329. THREE.LatheGeometry.prototype = new THREE.Geometry();
  15330. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  15331. /**
  15332. * @author mr.doob / http://mrdoob.com/
  15333. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  15334. */
  15335. THREE.PlaneGeometry = function ( width, depth, segmentsWidth, segmentsDepth ) {
  15336. THREE.Geometry.call( this );
  15337. var ix, iz,
  15338. width_half = width / 2,
  15339. depth_half = depth / 2,
  15340. gridX = segmentsWidth || 1,
  15341. gridZ = segmentsDepth || 1,
  15342. gridX1 = gridX + 1,
  15343. gridZ1 = gridZ + 1,
  15344. segment_width = width / gridX,
  15345. segment_depth = depth / gridZ,
  15346. normal = new THREE.Vector3( 0, 1, 0 );
  15347. for ( iz = 0; iz < gridZ1; iz ++ ) {
  15348. for ( ix = 0; ix < gridX1; ix ++ ) {
  15349. var x = ix * segment_width - width_half;
  15350. var z = iz * segment_depth - depth_half;
  15351. this.vertices.push( new THREE.Vector3( x, 0, z ) );
  15352. }
  15353. }
  15354. for ( iz = 0; iz < gridZ; iz ++ ) {
  15355. for ( ix = 0; ix < gridX; ix ++ ) {
  15356. var a = ix + gridX1 * iz;
  15357. var b = ix + gridX1 * ( iz + 1 );
  15358. var c = ( ix + 1 ) + gridX1 * ( iz + 1 );
  15359. var d = ( ix + 1 ) + gridX1 * iz;
  15360. var face = new THREE.Face4( a, b, c, d );
  15361. face.normal.copy( normal );
  15362. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone(), normal.clone() );
  15363. this.faces.push( face );
  15364. this.faceVertexUvs[ 0 ].push( [
  15365. new THREE.UV( ix / gridX, iz / gridZ ),
  15366. new THREE.UV( ix / gridX, ( iz + 1 ) / gridZ ),
  15367. new THREE.UV( ( ix + 1 ) / gridX, ( iz + 1 ) / gridZ ),
  15368. new THREE.UV( ( ix + 1 ) / gridX, iz / gridZ )
  15369. ] );
  15370. }
  15371. }
  15372. this.computeCentroids();
  15373. };
  15374. THREE.PlaneGeometry.prototype = new THREE.Geometry();
  15375. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  15376. /**
  15377. * @author mr.doob / http://mrdoob.com/
  15378. */
  15379. THREE.SphereGeometry = function ( radius, segmentsWidth, segmentsHeight, phiStart, phiLength, thetaStart, thetaLength ) {
  15380. THREE.Geometry.call( this );
  15381. radius = radius || 50;
  15382. phiStart = phiStart !== undefined ? phiStart : 0;
  15383. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  15384. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  15385. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  15386. var segmentsX = Math.max( 3, Math.floor( segmentsWidth ) || 8 );
  15387. var segmentsY = Math.max( 2, Math.floor( segmentsHeight ) || 6 );
  15388. var x, y, vertices = [], uvs = [];
  15389. for ( y = 0; y <= segmentsY; y ++ ) {
  15390. var verticesRow = [];
  15391. var uvsRow = [];
  15392. for ( x = 0; x <= segmentsX; x ++ ) {
  15393. var u = x / segmentsX;
  15394. var v = y / segmentsY;
  15395. var vertex = new THREE.Vector3();
  15396. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  15397. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  15398. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  15399. this.vertices.push( vertex );
  15400. verticesRow.push( this.vertices.length - 1 );
  15401. uvsRow.push( new THREE.UV( u, v ) );
  15402. }
  15403. vertices.push( verticesRow );
  15404. uvs.push( uvsRow );
  15405. }
  15406. for ( y = 0; y < segmentsY; y ++ ) {
  15407. for ( x = 0; x < segmentsX; x ++ ) {
  15408. var v1 = vertices[ y ][ x + 1 ];
  15409. var v2 = vertices[ y ][ x ];
  15410. var v3 = vertices[ y + 1 ][ x ];
  15411. var v4 = vertices[ y + 1 ][ x + 1 ];
  15412. var n1 = this.vertices[ v1 ].clone().normalize();
  15413. var n2 = this.vertices[ v2 ].clone().normalize();
  15414. var n3 = this.vertices[ v3 ].clone().normalize();
  15415. var n4 = this.vertices[ v4 ].clone().normalize();
  15416. var uv1 = uvs[ y ][ x + 1 ].clone();
  15417. var uv2 = uvs[ y ][ x ].clone();
  15418. var uv3 = uvs[ y + 1 ][ x ].clone();
  15419. var uv4 = uvs[ y + 1 ][ x + 1 ].clone();
  15420. if ( Math.abs( this.vertices[ v1 ].y ) == radius ) {
  15421. this.faces.push( new THREE.Face3( v1, v3, v4, [ n1, n3, n4 ] ) );
  15422. this.faceVertexUvs[ 0 ].push( [ uv1, uv3, uv4 ] );
  15423. } else if ( Math.abs( this.vertices[ v3 ].y ) == radius ) {
  15424. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  15425. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  15426. } else {
  15427. this.faces.push( new THREE.Face4( v1, v2, v3, v4, [ n1, n2, n3, n4 ] ) );
  15428. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3, uv4 ] );
  15429. }
  15430. }
  15431. }
  15432. this.computeCentroids();
  15433. this.computeFaceNormals();
  15434. this.boundingSphere = { radius: radius };
  15435. };
  15436. THREE.SphereGeometry.prototype = new THREE.Geometry();
  15437. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  15438. /**
  15439. * @author zz85 / http://www.lab4games.net/zz85/blog
  15440. * @author alteredq / http://alteredqualia.com/
  15441. *
  15442. * For creating 3D text geometry in three.js
  15443. *
  15444. * Text = 3D Text
  15445. *
  15446. * parameters = {
  15447. * size: <float>, // size of the text
  15448. * height: <float>, // thickness to extrude text
  15449. * curveSegments: <int>, // number of points on the curves
  15450. *
  15451. * font: <string>, // font name
  15452. * weight: <string>, // font weight (normal, bold)
  15453. * style: <string>, // font style (normal, italics)
  15454. *
  15455. * bevelEnabled: <bool>, // turn on bevel
  15456. * bevelThickness: <float>, // how deep into text bevel goes
  15457. * bevelSize: <float>, // how far from text outline is bevel
  15458. *
  15459. * bend: <bool> // bend according to hardcoded curve (generates bendPath)
  15460. * bendPath: <curve> // wraps text according to bend Path
  15461. * }
  15462. *
  15463. * It uses techniques used in:
  15464. *
  15465. * typeface.js and canvastext
  15466. * For converting fonts and rendering with javascript
  15467. * http://typeface.neocracy.org
  15468. *
  15469. * Triangulation ported from AS3
  15470. * Simple Polygon Triangulation
  15471. * http://actionsnippet.com/?p=1462
  15472. *
  15473. * A Method to triangulate shapes with holes
  15474. * http://www.sakri.net/blog/2009/06/12/an-approach-to-triangulating-polygons-with-holes/
  15475. *
  15476. */
  15477. /* Usage Examples
  15478. // TextGeometry wrapper
  15479. var text3d = new TextGeometry( text, options );
  15480. // Complete manner
  15481. var textPath = new THREE.TextPath( text, options );
  15482. var textShapes = textPath.toShapes();
  15483. var text3d = new ExtrudeGeometry( textShapes, options );
  15484. */
  15485. THREE.TextGeometry = function ( text, parameters ) {
  15486. var textPath = new THREE.TextPath( text, parameters );
  15487. var textShapes = textPath.toShapes();
  15488. // translate parameters to ExtrudeGeometry API
  15489. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  15490. // defaults
  15491. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  15492. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  15493. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  15494. if ( parameters.bend ) {
  15495. var b = textShapes[ textShapes.length - 1 ].getBoundingBox();
  15496. var max = b.maxX;
  15497. parameters.bendPath = new THREE.QuadraticBezierCurve( new THREE.Vector2( 0, 0 ),
  15498. new THREE.Vector2( max / 2, 120 ),
  15499. new THREE.Vector2( max, 0 ) );
  15500. }
  15501. THREE.ExtrudeGeometry.call( this, textShapes, parameters );
  15502. };
  15503. THREE.TextGeometry.prototype = new THREE.ExtrudeGeometry();
  15504. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
  15505. THREE.FontUtils = {
  15506. faces : {},
  15507. // Just for now. face[weight][style]
  15508. face : "helvetiker",
  15509. weight: "normal",
  15510. style : "normal",
  15511. size : 150,
  15512. divisions : 10,
  15513. getFace : function() {
  15514. return this.faces[ this.face ][ this.weight ][ this.style ];
  15515. },
  15516. loadFace : function( data ) {
  15517. var family = data.familyName.toLowerCase();
  15518. var ThreeFont = this;
  15519. ThreeFont.faces[ family ] = ThreeFont.faces[ family ] || {};
  15520. ThreeFont.faces[ family ][ data.cssFontWeight ] = ThreeFont.faces[ family ][ data.cssFontWeight ] || {};
  15521. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  15522. var face = ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  15523. return data;
  15524. },
  15525. drawText : function( text ) {
  15526. var characterPts = [], allPts = [];
  15527. // RenderText
  15528. var i, p,
  15529. face = this.getFace(),
  15530. scale = this.size / face.resolution,
  15531. offset = 0,
  15532. chars = String( text ).split( '' ),
  15533. length = chars.length;
  15534. var fontPaths = [];
  15535. for ( i = 0; i < length; i ++ ) {
  15536. var path = new THREE.Path();
  15537. var ret = this.extractGlyphPoints( chars[ i ], face, scale, offset, path );
  15538. offset += ret.offset;
  15539. //characterPts.push( ret.points );
  15540. //allPts = allPts.concat( ret.points );
  15541. fontPaths.push( ret.path );
  15542. }
  15543. // get the width
  15544. var width = offset / 2;
  15545. //
  15546. // for ( p = 0; p < allPts.length; p++ ) {
  15547. //
  15548. // allPts[ p ].x -= width;
  15549. //
  15550. // }
  15551. //var extract = this.extractPoints( allPts, characterPts );
  15552. //extract.contour = allPts;
  15553. //extract.paths = fontPaths;
  15554. //extract.offset = width;
  15555. return { paths : fontPaths, offset : width };
  15556. },
  15557. extractGlyphPoints : function( c, face, scale, offset, path ) {
  15558. var pts = [];
  15559. var i, i2, divisions,
  15560. outline, action, length,
  15561. scaleX, scaleY,
  15562. x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2,
  15563. laste,
  15564. glyph = face.glyphs[ c ] || face.glyphs[ '?' ];
  15565. if ( !glyph ) return;
  15566. if ( glyph.o ) {
  15567. outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  15568. length = outline.length;
  15569. scaleX = scale;
  15570. scaleY = scale;
  15571. for ( i = 0; i < length; ) {
  15572. action = outline[ i ++ ];
  15573. //console.log( action );
  15574. switch( action ) {
  15575. case 'm':
  15576. // Move To
  15577. x = outline[ i++ ] * scaleX + offset;
  15578. y = outline[ i++ ] * scaleY;
  15579. pts.push( new THREE.Vector2( x, y ) );
  15580. path.moveTo( x, y );
  15581. break;
  15582. case 'l':
  15583. // Line To
  15584. x = outline[ i++ ] * scaleX + offset;
  15585. y = outline[ i++ ] * scaleY;
  15586. pts.push( new THREE.Vector2( x, y ) );
  15587. path.lineTo(x,y);
  15588. break;
  15589. case 'q':
  15590. // QuadraticCurveTo
  15591. cpx = outline[ i++ ] * scaleX + offset;
  15592. cpy = outline[ i++ ] * scaleY;
  15593. cpx1 = outline[ i++ ] * scaleX + offset;
  15594. cpy1 = outline[ i++ ] * scaleY;
  15595. path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
  15596. laste = pts[ pts.length - 1 ];
  15597. if ( laste ) {
  15598. cpx0 = laste.x;
  15599. cpy0 = laste.y;
  15600. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  15601. var t = i2 / divisions;
  15602. var tx = THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  15603. var ty = THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  15604. pts.push( new THREE.Vector2( tx, ty ) );
  15605. }
  15606. }
  15607. break;
  15608. case 'b':
  15609. // Cubic Bezier Curve
  15610. cpx = outline[ i++ ] * scaleX + offset;
  15611. cpy = outline[ i++ ] * scaleY;
  15612. cpx1 = outline[ i++ ] * scaleX + offset;
  15613. cpy1 = outline[ i++ ] * -scaleY;
  15614. cpx2 = outline[ i++ ] * scaleX + offset;
  15615. cpy2 = outline[ i++ ] * -scaleY;
  15616. path.bezierCurveTo( cpx, cpy, cpx1, cpy1, cpx2, cpy2 );
  15617. laste = pts[ pts.length - 1 ];
  15618. if ( laste ) {
  15619. cpx0 = laste.x;
  15620. cpy0 = laste.y;
  15621. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  15622. var t = i2 / divisions;
  15623. var tx = THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  15624. var ty = THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  15625. pts.push( new THREE.Vector2( tx, ty ) );
  15626. }
  15627. }
  15628. break;
  15629. }
  15630. }
  15631. }
  15632. return { offset: glyph.ha*scale, points:pts, path:path};
  15633. }
  15634. };
  15635. /**
  15636. * This code is a quick port of code written in C++ which was submitted to
  15637. * flipcode.com by John W. Ratcliff // July 22, 2000
  15638. * See original code and more information here:
  15639. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  15640. *
  15641. * ported to actionscript by Zevan Rosser
  15642. * www.actionsnippet.com
  15643. *
  15644. * ported to javascript by Joshua Koo
  15645. * http://www.lab4games.net/zz85/blog
  15646. *
  15647. */
  15648. ( function( namespace ) {
  15649. var EPSILON = 0.0000000001;
  15650. // takes in an contour array and returns
  15651. var process = function( contour, indices ) {
  15652. var n = contour.length;
  15653. if ( n < 3 ) return null;
  15654. var result = [],
  15655. verts = [],
  15656. vertIndices = [];
  15657. /* we want a counter-clockwise polygon in verts */
  15658. var u, v, w;
  15659. if ( area( contour ) > 0.0 ) {
  15660. for ( v = 0; v < n; v++ ) verts[ v ] = v;
  15661. } else {
  15662. for ( v = 0; v < n; v++ ) verts[ v ] = ( n - 1 ) - v;
  15663. }
  15664. var nv = n;
  15665. /* remove nv - 2 vertices, creating 1 triangle every time */
  15666. var count = 2 * nv; /* error detection */
  15667. for( v = nv - 1; nv > 2; ) {
  15668. /* if we loop, it is probably a non-simple polygon */
  15669. if ( ( count-- ) <= 0 ) {
  15670. //** Triangulate: ERROR - probable bad polygon!
  15671. //throw ( "Warning, unable to triangulate polygon!" );
  15672. //return null;
  15673. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  15674. console.log( "Warning, unable to triangulate polygon!" );
  15675. if ( indices ) return vertIndices;
  15676. return result;
  15677. }
  15678. /* three consecutive vertices in current polygon, <u,v,w> */
  15679. u = v; if ( nv <= u ) u = 0; /* previous */
  15680. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  15681. w = v + 1; if ( nv <= w ) w = 0; /* next */
  15682. if ( snip( contour, u, v, w, nv, verts ) ) {
  15683. var a, b, c, s, t;
  15684. /* true names of the vertices */
  15685. a = verts[ u ];
  15686. b = verts[ v ];
  15687. c = verts[ w ];
  15688. /* output Triangle */
  15689. /*
  15690. result.push( contour[ a ] );
  15691. result.push( contour[ b ] );
  15692. result.push( contour[ c ] );
  15693. */
  15694. result.push( [ contour[ a ],
  15695. contour[ b ],
  15696. contour[ c ] ] );
  15697. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  15698. /* remove v from the remaining polygon */
  15699. for( s = v, t = v + 1; t < nv; s++, t++ ) {
  15700. verts[ s ] = verts[ t ];
  15701. }
  15702. nv--;
  15703. /* reset error detection counter */
  15704. count = 2 * nv;
  15705. }
  15706. }
  15707. if ( indices ) return vertIndices;
  15708. return result;
  15709. };
  15710. // calculate area of the contour polygon
  15711. var area = function ( contour ) {
  15712. var n = contour.length;
  15713. var a = 0.0;
  15714. for( var p = n - 1, q = 0; q < n; p = q++ ) {
  15715. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  15716. }
  15717. return a * 0.5;
  15718. };
  15719. // see if p is inside triangle abc
  15720. var insideTriangle = function( ax, ay,
  15721. bx, by,
  15722. cx, cy,
  15723. px, py ) {
  15724. var aX, aY, bX, bY;
  15725. var cX, cY, apx, apy;
  15726. var bpx, bpy, cpx, cpy;
  15727. var cCROSSap, bCROSScp, aCROSSbp;
  15728. aX = cx - bx; aY = cy - by;
  15729. bX = ax - cx; bY = ay - cy;
  15730. cX = bx - ax; cY = by - ay;
  15731. apx= px -ax; apy= py - ay;
  15732. bpx= px - bx; bpy= py - by;
  15733. cpx= px - cx; cpy= py - cy;
  15734. aCROSSbp = aX*bpy - aY*bpx;
  15735. cCROSSap = cX*apy - cY*apx;
  15736. bCROSScp = bX*cpy - bY*cpx;
  15737. return ( (aCROSSbp >= 0.0) && (bCROSScp >= 0.0) && (cCROSSap >= 0.0) );
  15738. };
  15739. var snip = function ( contour, u, v, w, n, verts ) {
  15740. var p;
  15741. var ax, ay, bx, by;
  15742. var cx, cy, px, py;
  15743. ax = contour[ verts[ u ] ].x;
  15744. ay = contour[ verts[ u ] ].y;
  15745. bx = contour[ verts[ v ] ].x;
  15746. by = contour[ verts[ v ] ].y;
  15747. cx = contour[ verts[ w ] ].x;
  15748. cy = contour[ verts[ w ] ].y;
  15749. if ( EPSILON > (((bx-ax)*(cy-ay)) - ((by-ay)*(cx-ax))) ) return false;
  15750. for ( p = 0; p < n; p++ ) {
  15751. if( (p == u) || (p == v) || (p == w) ) continue;
  15752. px = contour[ verts[ p ] ].x
  15753. py = contour[ verts[ p ] ].y
  15754. if ( insideTriangle( ax, ay, bx, by, cx, cy, px, py ) ) return false;
  15755. }
  15756. return true;
  15757. };
  15758. namespace.Triangulate = process;
  15759. namespace.Triangulate.area = area;
  15760. return namespace;
  15761. })(THREE.FontUtils);
  15762. // To use the typeface.js face files, hook up the API
  15763. self._typeface_js = { faces: THREE.FontUtils.faces, loadFace: THREE.FontUtils.loadFace };
  15764. /**
  15765. * @author oosmoxiecode
  15766. * @author mr.doob / http://mrdoob.com/
  15767. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  15768. */
  15769. THREE.TorusGeometry = function ( radius, tube, segmentsR, segmentsT, arc ) {
  15770. THREE.Geometry.call( this );
  15771. var scope = this;
  15772. this.radius = radius || 100;
  15773. this.tube = tube || 40;
  15774. this.segmentsR = segmentsR || 8;
  15775. this.segmentsT = segmentsT || 6;
  15776. this.arc = arc || Math.PI * 2;
  15777. var center = new THREE.Vector3(), uvs = [], normals = [];
  15778. for ( var j = 0; j <= this.segmentsR; j ++ ) {
  15779. for ( var i = 0; i <= this.segmentsT; i ++ ) {
  15780. var u = i / this.segmentsT * this.arc;
  15781. var v = j / this.segmentsR * Math.PI * 2;
  15782. center.x = this.radius * Math.cos( u );
  15783. center.y = this.radius * Math.sin( u );
  15784. var vertex = new THREE.Vector3();
  15785. vertex.x = ( this.radius + this.tube * Math.cos( v ) ) * Math.cos( u );
  15786. vertex.y = ( this.radius + this.tube * Math.cos( v ) ) * Math.sin( u );
  15787. vertex.z = this.tube * Math.sin( v );
  15788. this.vertices.push( vertex );
  15789. uvs.push( new THREE.UV( i / this.segmentsT, 1 - j / this.segmentsR ) );
  15790. normals.push( vertex.clone().subSelf( center ).normalize() );
  15791. }
  15792. }
  15793. for ( var j = 1; j <= this.segmentsR; j ++ ) {
  15794. for ( var i = 1; i <= this.segmentsT; i ++ ) {
  15795. var a = ( this.segmentsT + 1 ) * j + i - 1;
  15796. var b = ( this.segmentsT + 1 ) * ( j - 1 ) + i - 1;
  15797. var c = ( this.segmentsT + 1 ) * ( j - 1 ) + i;
  15798. var d = ( this.segmentsT + 1 ) * j + i;
  15799. var face = new THREE.Face4( a, b, c, d, [ normals[ a ], normals[ b ], normals[ c ], normals[ d ] ] );
  15800. face.normal.addSelf( normals[ a ] );
  15801. face.normal.addSelf( normals[ b ] );
  15802. face.normal.addSelf( normals[ c ] );
  15803. face.normal.addSelf( normals[ d ] );
  15804. face.normal.normalize();
  15805. this.faces.push( face );
  15806. this.faceVertexUvs[ 0 ].push( [ uvs[ a ].clone(), uvs[ b ].clone(), uvs[ c ].clone(), uvs[ d ].clone() ] );
  15807. }
  15808. }
  15809. this.computeCentroids();
  15810. };
  15811. THREE.TorusGeometry.prototype = new THREE.Geometry();
  15812. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  15813. /**
  15814. * @author oosmoxiecode
  15815. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
  15816. */
  15817. THREE.TorusKnotGeometry = function ( radius, tube, segmentsR, segmentsT, p, q, heightScale ) {
  15818. THREE.Geometry.call( this );
  15819. var scope = this;
  15820. this.radius = radius || 200;
  15821. this.tube = tube || 40;
  15822. this.segmentsR = segmentsR || 64;
  15823. this.segmentsT = segmentsT || 8;
  15824. this.p = p || 2;
  15825. this.q = q || 3;
  15826. this.heightScale = heightScale || 1;
  15827. this.grid = new Array(this.segmentsR);
  15828. var tang = new THREE.Vector3();
  15829. var n = new THREE.Vector3();
  15830. var bitan = new THREE.Vector3();
  15831. for ( var i = 0; i < this.segmentsR; ++ i ) {
  15832. this.grid[ i ] = new Array( this.segmentsT );
  15833. for ( var j = 0; j < this.segmentsT; ++ j ) {
  15834. var u = i / this.segmentsR * 2 * this.p * Math.PI;
  15835. var v = j / this.segmentsT * 2 * Math.PI;
  15836. var p1 = getPos( u, v, this.q, this.p, this.radius, this.heightScale );
  15837. var p2 = getPos( u + 0.01, v, this.q, this.p, this.radius, this.heightScale );
  15838. var cx, cy;
  15839. tang.sub( p2, p1 );
  15840. n.add( p2, p1 );
  15841. bitan.cross( tang, n );
  15842. n.cross( bitan, tang );
  15843. bitan.normalize();
  15844. n.normalize();
  15845. cx = - this.tube * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  15846. cy = this.tube * Math.sin( v );
  15847. p1.x += cx * n.x + cy * bitan.x;
  15848. p1.y += cx * n.y + cy * bitan.y;
  15849. p1.z += cx * n.z + cy * bitan.z;
  15850. this.grid[ i ][ j ] = vert( p1.x, p1.y, p1.z );
  15851. }
  15852. }
  15853. for ( var i = 0; i < this.segmentsR; ++ i ) {
  15854. for ( var j = 0; j < this.segmentsT; ++ j ) {
  15855. var ip = ( i + 1 ) % this.segmentsR;
  15856. var jp = ( j + 1 ) % this.segmentsT;
  15857. var a = this.grid[ i ][ j ];
  15858. var b = this.grid[ ip ][ j ];
  15859. var c = this.grid[ ip ][ jp ];
  15860. var d = this.grid[ i ][ jp ];
  15861. var uva = new THREE.UV( i / this.segmentsR, j / this.segmentsT );
  15862. var uvb = new THREE.UV( ( i + 1 ) / this.segmentsR, j / this.segmentsT );
  15863. var uvc = new THREE.UV( ( i + 1 ) / this.segmentsR, ( j + 1 ) / this.segmentsT );
  15864. var uvd = new THREE.UV( i / this.segmentsR, ( j + 1 ) / this.segmentsT );
  15865. this.faces.push( new THREE.Face4( a, b, c, d ) );
  15866. this.faceVertexUvs[ 0 ].push( [ uva,uvb,uvc, uvd ] );
  15867. }
  15868. }
  15869. this.computeCentroids();
  15870. this.computeFaceNormals();
  15871. this.computeVertexNormals();
  15872. function vert( x, y, z ) {
  15873. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  15874. }
  15875. function getPos( u, v, in_q, in_p, radius, heightScale ) {
  15876. var cu = Math.cos( u );
  15877. var cv = Math.cos( v );
  15878. var su = Math.sin( u );
  15879. var quOverP = in_q / in_p * u;
  15880. var cs = Math.cos( quOverP );
  15881. var tx = radius * ( 2 + cs ) * 0.5 * cu;
  15882. var ty = radius * ( 2 + cs ) * su * 0.5;
  15883. var tz = heightScale * radius * Math.sin( quOverP ) * 0.5;
  15884. return new THREE.Vector3( tx, ty, tz );
  15885. }
  15886. };
  15887. THREE.TorusKnotGeometry.prototype = new THREE.Geometry();
  15888. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  15889. /**
  15890. * @author WestLangley / https://github.com/WestLangley
  15891. * @author zz85 / https://github.com/zz85
  15892. * @author miningold / https://github.com/miningold
  15893. *
  15894. * Modified from the TorusKnotGeometry by @oosmoxiecode
  15895. *
  15896. * Creates a tube which extrudes along a 3d spline
  15897. *
  15898. * Uses parallel transport frames as described in
  15899. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  15900. */
  15901. THREE.TubeGeometry = function( path, segments, radius, segmentsRadius, closed, debug ) {
  15902. THREE.Geometry.call( this );
  15903. this.path = path;
  15904. this.segments = segments || 64;
  15905. this.radius = radius || 1;
  15906. this.segmentsRadius = segmentsRadius || 8;
  15907. this.closed = closed || false;
  15908. if ( debug ) this.debug = new THREE.Object3D();
  15909. this.grid = [];
  15910. var scope = this,
  15911. tangent,
  15912. normal,
  15913. binormal,
  15914. numpoints = this.segments + 1,
  15915. x, y, z,
  15916. tx, ty, tz,
  15917. u, v,
  15918. cx, cy,
  15919. pos, pos2 = new THREE.Vector3(),
  15920. i, j,
  15921. ip, jp,
  15922. a, b, c, d,
  15923. uva, uvb, uvc, uvd;
  15924. var frames = new THREE.TubeGeometry.FrenetFrames(path, segments, closed),
  15925. tangents = frames.tangents,
  15926. normals = frames.normals,
  15927. binormals = frames.binormals;
  15928. // proxy internals
  15929. this.tangents = tangents;
  15930. this.normals = normals;
  15931. this.binormals = binormals;
  15932. function vert( x, y, z ) {
  15933. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  15934. }
  15935. // consruct the grid
  15936. for ( i = 0; i < numpoints; i++ ) {
  15937. this.grid[ i ] = [];
  15938. u = i / ( numpoints - 1 );
  15939. pos = path.getPointAt( u );
  15940. tangent = tangents[ i ];
  15941. normal = normals[ i ];
  15942. binormal = binormals[ i ];
  15943. if ( this.debug ) {
  15944. this.debug.add(new THREE.ArrowHelper(tangent, pos, radius, 0x0000ff));
  15945. this.debug.add(new THREE.ArrowHelper(normal, pos, radius, 0xff0000));
  15946. this.debug.add(new THREE.ArrowHelper(binormal, pos, radius, 0x00ff00));
  15947. }
  15948. for ( j = 0; j < this.segmentsRadius; j++ ) {
  15949. v = j / this.segmentsRadius * 2 * Math.PI;
  15950. cx = -this.radius * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  15951. cy = this.radius * Math.sin( v );
  15952. pos2.copy( pos );
  15953. pos2.x += cx * normal.x + cy * binormal.x;
  15954. pos2.y += cx * normal.y + cy * binormal.y;
  15955. pos2.z += cx * normal.z + cy * binormal.z;
  15956. this.grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  15957. }
  15958. }
  15959. // construct the mesh
  15960. for ( i = 0; i < this.segments; i++ ) {
  15961. for ( j = 0; j < this.segmentsRadius; j++ ) {
  15962. ip = ( closed ) ? (i + 1) % this.segments : i + 1;
  15963. jp = (j + 1) % this.segmentsRadius;
  15964. a = this.grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  15965. b = this.grid[ ip ][ j ];
  15966. c = this.grid[ ip ][ jp ];
  15967. d = this.grid[ i ][ jp ];
  15968. uva = new THREE.UV( i / this.segments, j / this.segmentsRadius );
  15969. uvb = new THREE.UV( ( i + 1 ) / this.segments, j / this.segmentsRadius );
  15970. uvc = new THREE.UV( ( i + 1 ) / this.segments, ( j + 1 ) / this.segmentsRadius );
  15971. uvd = new THREE.UV( i / this.segments, ( j + 1 ) / this.segmentsRadius );
  15972. this.faces.push( new THREE.Face4( a, b, c, d ) );
  15973. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvc, uvd ] );
  15974. }
  15975. }
  15976. this.computeCentroids();
  15977. this.computeFaceNormals();
  15978. this.computeVertexNormals();
  15979. };
  15980. THREE.TubeGeometry.prototype = new THREE.Geometry();
  15981. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  15982. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  15983. THREE.TubeGeometry.FrenetFrames = function(path, segments, closed) {
  15984. var
  15985. tangent = new THREE.Vector3(),
  15986. normal = new THREE.Vector3(),
  15987. binormal = new THREE.Vector3(),
  15988. tangents = [],
  15989. normals = [],
  15990. binormals = [],
  15991. vec = new THREE.Vector3(),
  15992. mat = new THREE.Matrix4(),
  15993. numpoints = segments + 1,
  15994. theta,
  15995. epsilon = 0.0001,
  15996. smallest,
  15997. tx, ty, tz,
  15998. i, u, v;
  15999. // expose internals
  16000. this.tangents = tangents;
  16001. this.normals = normals;
  16002. this.binormals = binormals;
  16003. // compute the tangent vectors for each segment on the path
  16004. for ( i = 0; i < numpoints; i++ ) {
  16005. u = i / ( numpoints - 1 );
  16006. tangents[ i ] = path.getTangentAt( u );
  16007. tangents[ i ].normalize();
  16008. }
  16009. initialNormal3();
  16010. function initialNormal1(lastBinormal) {
  16011. // fixed start binormal. Has dangers of 0 vectors
  16012. normals[ 0 ] = new THREE.Vector3();
  16013. binormals[ 0 ] = new THREE.Vector3();
  16014. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  16015. normals[ 0 ].cross( lastBinormal, tangents[ 0 ] ).normalize();
  16016. binormals[ 0 ].cross( tangents[ 0 ], normals[ 0 ] ).normalize();
  16017. }
  16018. function initialNormal2() {
  16019. // This uses the Frenet-Serret formula for deriving binormal
  16020. var t2 = path.getTangentAt( epsilon );
  16021. normals[ 0 ] = new THREE.Vector3().sub( t2, tangents[ 0 ] ).normalize();
  16022. binormals[ 0 ] = new THREE.Vector3().cross( tangents[ 0 ], normals[ 0 ] );
  16023. normals[ 0 ].cross( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  16024. binormals[ 0 ].cross( tangents[ 0 ], normals[ 0 ] ).normalize();
  16025. }
  16026. function initialNormal3() {
  16027. // select an initial normal vector perpenicular to the first tangent vector,
  16028. // and in the direction of the smallest tangent xyz component
  16029. normals[ 0 ] = new THREE.Vector3();
  16030. binormals[ 0 ] = new THREE.Vector3();
  16031. smallest = Number.MAX_VALUE;
  16032. tx = Math.abs( tangents[ 0 ].x );
  16033. ty = Math.abs( tangents[ 0 ].y );
  16034. tz = Math.abs( tangents[ 0 ].z );
  16035. if ( tx <= smallest ) {
  16036. smallest = tx;
  16037. normal.set( 1, 0, 0 );
  16038. }
  16039. if ( ty <= smallest ) {
  16040. smallest = ty;
  16041. normal.set( 0, 1, 0 );
  16042. }
  16043. if ( tz <= smallest ) {
  16044. normal.set( 0, 0, 1 );
  16045. }
  16046. vec.cross( tangents[ 0 ], normal ).normalize();
  16047. normals[ 0 ].cross( tangents[ 0 ], vec );
  16048. binormals[ 0 ].cross( tangents[ 0 ], normals[ 0 ] );
  16049. }
  16050. // compute the slowly-varying normal and binormal vectors for each segment on the path
  16051. for ( i = 1; i < numpoints; i++ ) {
  16052. normals[ i ] = normals[ i-1 ].clone();
  16053. binormals[ i ] = binormals[ i-1 ].clone();
  16054. vec.cross( tangents[ i-1 ], tangents[ i ] );
  16055. if ( vec.length() > epsilon ) {
  16056. vec.normalize();
  16057. theta = Math.acos( tangents[ i-1 ].dot( tangents[ i ] ) );
  16058. mat.makeRotationAxis( vec, theta ).multiplyVector3( normals[ i ] );
  16059. }
  16060. binormals[ i ].cross( tangents[ i ], normals[ i ] );
  16061. }
  16062. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  16063. if ( closed ) {
  16064. theta = Math.acos( normals[ 0 ].dot( normals[ numpoints-1 ] ) );
  16065. theta /= ( numpoints - 1 );
  16066. if ( tangents[ 0 ].dot( vec.cross( normals[ 0 ], normals[ numpoints-1 ] ) ) > 0 ) {
  16067. theta = -theta;
  16068. }
  16069. for ( i = 1; i < numpoints; i++ ) {
  16070. // twist a little...
  16071. mat.makeRotationAxis( tangents[ i ], theta * i ).multiplyVector3( normals[ i ] );
  16072. binormals[ i ].cross( tangents[ i ], normals[ i ] );
  16073. }
  16074. }
  16075. };
  16076. /**
  16077. * @author clockworkgeek / https://github.com/clockworkgeek
  16078. * @author timothypratley / https://github.com/timothypratley
  16079. */
  16080. THREE.PolyhedronGeometry = function ( vertices, faces, radius, detail ) {
  16081. THREE.Geometry.call( this );
  16082. radius = radius || 1;
  16083. detail = detail || 0;
  16084. var that = this;
  16085. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  16086. prepare( new THREE.Vector3( vertices[ i ][ 0 ], vertices[ i ][ 1 ], vertices[ i ][ 2 ] ) );
  16087. }
  16088. var midpoints = [], p = this.vertices;
  16089. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  16090. make( p[ faces[ i ][ 0 ] ], p[ faces[ i ][ 1 ] ], p[ faces[ i ][ 2 ] ], detail );
  16091. }
  16092. this.mergeVertices();
  16093. // Apply radius
  16094. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  16095. this.vertices[ i ].multiplyScalar( radius );
  16096. }
  16097. /**
  16098. * Project vector onto sphere's surface
  16099. */
  16100. function prepare( vector ) {
  16101. var vertex = vector.normalize().clone();
  16102. vertex.index = that.vertices.push( vertex ) - 1;
  16103. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  16104. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  16105. var v = inclination( vector ) / Math.PI + 0.5;
  16106. vertex.uv = new THREE.UV( u, v );
  16107. return vertex;
  16108. }
  16109. /**
  16110. * Approximate a curved face with recursively sub-divided triangles.
  16111. */
  16112. function make( v1, v2, v3, detail ) {
  16113. if ( detail < 1 ) {
  16114. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
  16115. face.centroid.addSelf( v1 ).addSelf( v2 ).addSelf( v3 ).divideScalar( 3 );
  16116. face.normal = face.centroid.clone().normalize();
  16117. that.faces.push( face );
  16118. var azi = azimuth( face.centroid );
  16119. that.faceVertexUvs[ 0 ].push( [
  16120. correctUV( v1.uv, v1, azi ),
  16121. correctUV( v2.uv, v2, azi ),
  16122. correctUV( v3.uv, v3, azi )
  16123. ] );
  16124. }
  16125. else {
  16126. detail -= 1;
  16127. // split triangle into 4 smaller triangles
  16128. make( v1, midpoint( v1, v2 ), midpoint( v1, v3 ), detail ); // top quadrant
  16129. make( midpoint( v1, v2 ), v2, midpoint( v2, v3 ), detail ); // left quadrant
  16130. make( midpoint( v1, v3 ), midpoint( v2, v3 ), v3, detail ); // right quadrant
  16131. make( midpoint( v1, v2 ), midpoint( v2, v3 ), midpoint( v1, v3 ), detail ); // center quadrant
  16132. }
  16133. }
  16134. function midpoint( v1, v2 ) {
  16135. if ( !midpoints[ v1.index ] ) midpoints[ v1.index ] = [];
  16136. if ( !midpoints[ v2.index ] ) midpoints[ v2.index ] = [];
  16137. var mid = midpoints[ v1.index ][ v2.index ];
  16138. if ( mid === undefined ) {
  16139. // generate mean point and project to surface with prepare()
  16140. midpoints[ v1.index ][ v2.index ] = midpoints[ v2.index ][ v1.index ] = mid = prepare(
  16141. new THREE.Vector3().add( v1, v2 ).divideScalar( 2 )
  16142. );
  16143. }
  16144. return mid;
  16145. }
  16146. /**
  16147. * Angle around the Y axis, counter-clockwise when looking from above.
  16148. */
  16149. function azimuth( vector ) {
  16150. return Math.atan2( vector.z, -vector.x );
  16151. }
  16152. /**
  16153. * Angle above the XZ plane.
  16154. */
  16155. function inclination( vector ) {
  16156. return Math.atan2( -vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  16157. }
  16158. /**
  16159. * Texture fixing helper. Spheres have some odd behaviours.
  16160. */
  16161. function correctUV( uv, vector, azimuth ) {
  16162. if ( (azimuth < 0) && (uv.u === 1) ) uv = new THREE.UV( uv.u - 1, uv.v );
  16163. if ( (vector.x === 0) && (vector.z === 0) ) uv = new THREE.UV( azimuth / 2 / Math.PI + 0.5, uv.v );
  16164. return uv;
  16165. }
  16166. this.computeCentroids();
  16167. this.boundingSphere = { radius: radius };
  16168. };
  16169. THREE.PolyhedronGeometry.prototype = new THREE.Geometry();
  16170. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  16171. /**
  16172. * @author timothypratley / https://github.com/timothypratley
  16173. */
  16174. THREE.IcosahedronGeometry = function ( radius, detail ) {
  16175. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16176. var vertices = [
  16177. [ -1, t, 0 ], [ 1, t, 0 ], [ -1, -t, 0 ], [ 1, -t, 0 ],
  16178. [ 0, -1, t ], [ 0, 1, t ], [ 0, -1, -t ], [ 0, 1, -t ],
  16179. [ t, 0, -1 ], [ t, 0, 1 ], [ -t, 0, -1 ], [ -t, 0, 1 ]
  16180. ];
  16181. var faces = [
  16182. [ 0, 11, 5 ], [ 0, 5, 1 ], [ 0, 1, 7 ], [ 0, 7, 10 ], [ 0, 10, 11 ],
  16183. [ 1, 5, 9 ], [ 5, 11, 4 ], [ 11, 10, 2 ], [ 10, 7, 6 ], [ 7, 1, 8 ],
  16184. [ 3, 9, 4 ], [ 3, 4, 2 ], [ 3, 2, 6 ], [ 3, 6, 8 ], [ 3, 8, 9 ],
  16185. [ 4, 9, 5 ], [ 2, 4, 11 ], [ 6, 2, 10 ], [ 8, 6, 7 ], [ 9, 8, 1 ]
  16186. ];
  16187. THREE.PolyhedronGeometry.call( this, vertices, faces, radius, detail );
  16188. };
  16189. THREE.IcosahedronGeometry.prototype = new THREE.Geometry();
  16190. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  16191. /**
  16192. * @author timothypratley / https://github.com/timothypratley
  16193. */
  16194. THREE.OctahedronGeometry = function ( radius, detail ) {
  16195. var vertices = [
  16196. [ 1, 0, 0 ], [ -1, 0, 0 ], [ 0, 1, 0 ], [ 0, -1, 0 ], [ 0, 0, 1 ], [ 0, 0, -1 ]
  16197. ];
  16198. var faces = [
  16199. [ 0, 2, 4 ], [ 0, 4, 3 ], [ 0, 3, 5 ], [ 0, 5, 2 ], [ 1, 2, 5 ], [ 1, 5, 3 ], [ 1, 3, 4 ], [ 1, 4, 2 ]
  16200. ];
  16201. THREE.PolyhedronGeometry.call( this, vertices, faces, radius, detail );
  16202. };
  16203. THREE.OctahedronGeometry.prototype = new THREE.Geometry();
  16204. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  16205. /**
  16206. * @author timothypratley / https://github.com/timothypratley
  16207. */
  16208. THREE.TetrahedronGeometry = function ( radius, detail ) {
  16209. var vertices = [
  16210. [ 1, 1, 1 ], [ -1, -1, 1 ], [ -1, 1, -1 ], [ 1, -1, -1 ]
  16211. ];
  16212. var faces = [
  16213. [ 2, 1, 0 ], [ 0, 3, 2 ], [ 1, 3, 0 ], [ 2, 3, 1 ]
  16214. ];
  16215. THREE.PolyhedronGeometry.call( this, vertices, faces, radius, detail );
  16216. };
  16217. THREE.TetrahedronGeometry.prototype = new THREE.Geometry();
  16218. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  16219. /**
  16220. * @author sroucheray / http://sroucheray.org/
  16221. * @author mr.doob / http://mrdoob.com/
  16222. */
  16223. THREE.AxisHelper = function () {
  16224. THREE.Object3D.call( this );
  16225. var lineGeometry = new THREE.Geometry();
  16226. lineGeometry.vertices.push( new THREE.Vector3() );
  16227. lineGeometry.vertices.push( new THREE.Vector3( 0, 100, 0 ) );
  16228. var coneGeometry = new THREE.CylinderGeometry( 0, 5, 25, 5, 1 );
  16229. var line, cone;
  16230. // x
  16231. line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color : 0xff0000 } ) );
  16232. line.rotation.z = - Math.PI / 2;
  16233. this.add( line );
  16234. cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color : 0xff0000 } ) );
  16235. cone.position.x = 100;
  16236. cone.rotation.z = - Math.PI / 2;
  16237. this.add( cone );
  16238. // y
  16239. line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color : 0x00ff00 } ) );
  16240. this.add( line );
  16241. cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color : 0x00ff00 } ) );
  16242. cone.position.y = 100;
  16243. this.add( cone );
  16244. // z
  16245. line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color : 0x0000ff } ) );
  16246. line.rotation.x = Math.PI / 2;
  16247. this.add( line );
  16248. cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color : 0x0000ff } ) );
  16249. cone.position.z = 100;
  16250. cone.rotation.x = Math.PI / 2;
  16251. this.add( cone );
  16252. };
  16253. THREE.AxisHelper.prototype = new THREE.Object3D();
  16254. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  16255. /**
  16256. * @author WestLangley / https://github.com/WestLangley
  16257. * @author zz85 / https://github.com/zz85
  16258. *
  16259. * Creates an arrow for visualizing directions
  16260. *
  16261. * Parameters:
  16262. * dir - Vector3
  16263. * origin - Vector3
  16264. * length - Number
  16265. * hex - color in hex value
  16266. */
  16267. THREE.ArrowHelper = function ( dir, origin, length, hex ) {
  16268. THREE.Object3D.call( this );
  16269. if ( hex === undefined ) hex = 0xffff00;
  16270. if ( length === undefined ) length = 20;
  16271. var lineGeometry = new THREE.Geometry();
  16272. lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ) );
  16273. lineGeometry.vertices.push( new THREE.Vector3( 0, 1, 0 ) );
  16274. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: hex } ) );
  16275. this.add( this.line );
  16276. var coneGeometry = new THREE.CylinderGeometry( 0, 0.05, 0.25, 5, 1 );
  16277. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: hex } ) );
  16278. this.cone.position.set( 0, 1, 0 );
  16279. this.add( this.cone );
  16280. if ( origin instanceof THREE.Vector3 ) this.position = origin;
  16281. this.setDirection( dir );
  16282. this.setLength( length );
  16283. };
  16284. THREE.ArrowHelper.prototype = new THREE.Object3D();
  16285. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  16286. THREE.ArrowHelper.prototype.setDirection = function ( dir ) {
  16287. var axis = new THREE.Vector3( 0, 1, 0 ).crossSelf( dir );
  16288. var radians = Math.acos( new THREE.Vector3( 0, 1, 0 ).dot( dir.clone().normalize() ) );
  16289. this.matrix = new THREE.Matrix4().makeRotationAxis( axis.normalize(), radians );
  16290. this.rotation.getRotationFromMatrix( this.matrix, this.scale );
  16291. };
  16292. THREE.ArrowHelper.prototype.setLength = function ( length ) {
  16293. this.scale.set( length, length, length );
  16294. };
  16295. THREE.ArrowHelper.prototype.setColor = function ( hex ) {
  16296. this.line.material.color.setHex( hex );
  16297. this.cone.material.color.setHex( hex );
  16298. };
  16299. /**
  16300. * @author alteredq / http://alteredqualia.com/
  16301. *
  16302. * - shows frustum, line of sight and up of the camera
  16303. * - suitable for fast updates
  16304. * - based on frustum visualization in lightgl.js shadowmap example
  16305. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  16306. */
  16307. THREE.CameraHelper = function ( camera ) {
  16308. THREE.Object3D.call( this );
  16309. var _this = this;
  16310. this.lineGeometry = new THREE.Geometry();
  16311. this.lineMaterial = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  16312. this.pointMap = {};
  16313. // colors
  16314. var hexFrustum = 0xffaa00,
  16315. hexCone = 0xff0000,
  16316. hexUp = 0x00aaff,
  16317. hexTarget = 0xffffff,
  16318. hexCross = 0x333333;
  16319. // near
  16320. addLine( "n1", "n2", hexFrustum );
  16321. addLine( "n2", "n4", hexFrustum );
  16322. addLine( "n4", "n3", hexFrustum );
  16323. addLine( "n3", "n1", hexFrustum );
  16324. // far
  16325. addLine( "f1", "f2", hexFrustum );
  16326. addLine( "f2", "f4", hexFrustum );
  16327. addLine( "f4", "f3", hexFrustum );
  16328. addLine( "f3", "f1", hexFrustum );
  16329. // sides
  16330. addLine( "n1", "f1", hexFrustum );
  16331. addLine( "n2", "f2", hexFrustum );
  16332. addLine( "n3", "f3", hexFrustum );
  16333. addLine( "n4", "f4", hexFrustum );
  16334. // cone
  16335. addLine( "p", "n1", hexCone );
  16336. addLine( "p", "n2", hexCone );
  16337. addLine( "p", "n3", hexCone );
  16338. addLine( "p", "n4", hexCone );
  16339. // up
  16340. addLine( "u1", "u2", hexUp );
  16341. addLine( "u2", "u3", hexUp );
  16342. addLine( "u3", "u1", hexUp );
  16343. // target
  16344. addLine( "c", "t", hexTarget );
  16345. addLine( "p", "c", hexCross );
  16346. // cross
  16347. addLine( "cn1", "cn2", hexCross );
  16348. addLine( "cn3", "cn4", hexCross );
  16349. addLine( "cf1", "cf2", hexCross );
  16350. addLine( "cf3", "cf4", hexCross );
  16351. this.camera = camera;
  16352. function addLine( a, b, hex ) {
  16353. addPoint( a, hex );
  16354. addPoint( b, hex );
  16355. }
  16356. function addPoint( id, hex ) {
  16357. _this.lineGeometry.vertices.push( new THREE.Vector3() );
  16358. _this.lineGeometry.colors.push( new THREE.Color( hex ) );
  16359. if ( _this.pointMap[ id ] === undefined ) _this.pointMap[ id ] = [];
  16360. _this.pointMap[ id ].push( _this.lineGeometry.vertices.length - 1 );
  16361. }
  16362. this.update( camera );
  16363. this.lines = new THREE.Line( this.lineGeometry, this.lineMaterial, THREE.LinePieces );
  16364. this.add( this.lines );
  16365. };
  16366. THREE.CameraHelper.prototype = new THREE.Object3D();
  16367. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  16368. THREE.CameraHelper.prototype.update = function () {
  16369. var camera = this.camera;
  16370. var w = 1;
  16371. var h = 1;
  16372. var _this = this;
  16373. // we need just camera projection matrix
  16374. // world matrix must be identity
  16375. THREE.CameraHelper.__c.projectionMatrix.copy( camera.projectionMatrix );
  16376. // center / target
  16377. setPoint( "c", 0, 0, -1 );
  16378. setPoint( "t", 0, 0, 1 );
  16379. // near
  16380. setPoint( "n1", -w, -h, -1 );
  16381. setPoint( "n2", w, -h, -1 );
  16382. setPoint( "n3", -w, h, -1 );
  16383. setPoint( "n4", w, h, -1 );
  16384. // far
  16385. setPoint( "f1", -w, -h, 1 );
  16386. setPoint( "f2", w, -h, 1 );
  16387. setPoint( "f3", -w, h, 1 );
  16388. setPoint( "f4", w, h, 1 );
  16389. // up
  16390. setPoint( "u1", w * 0.7, h * 1.1, -1 );
  16391. setPoint( "u2", -w * 0.7, h * 1.1, -1 );
  16392. setPoint( "u3", 0, h * 2, -1 );
  16393. // cross
  16394. setPoint( "cf1", -w, 0, 1 );
  16395. setPoint( "cf2", w, 0, 1 );
  16396. setPoint( "cf3", 0, -h, 1 );
  16397. setPoint( "cf4", 0, h, 1 );
  16398. setPoint( "cn1", -w, 0, -1 );
  16399. setPoint( "cn2", w, 0, -1 );
  16400. setPoint( "cn3", 0, -h, -1 );
  16401. setPoint( "cn4", 0, h, -1 );
  16402. function setPoint( point, x, y, z ) {
  16403. THREE.CameraHelper.__v.set( x, y, z );
  16404. THREE.CameraHelper.__projector.unprojectVector( THREE.CameraHelper.__v, THREE.CameraHelper.__c );
  16405. var points = _this.pointMap[ point ];
  16406. if ( points !== undefined ) {
  16407. for ( var i = 0, il = points.length; i < il; i ++ ) {
  16408. var j = points[ i ];
  16409. _this.lineGeometry.vertices[ j ].copy( THREE.CameraHelper.__v );
  16410. }
  16411. }
  16412. }
  16413. this.lineGeometry.__dirtyVertices = true;
  16414. };
  16415. THREE.CameraHelper.__projector = new THREE.Projector();
  16416. THREE.CameraHelper.__v = new THREE.Vector3();
  16417. THREE.CameraHelper.__c = new THREE.Camera();
  16418. /*
  16419. * @author zz85 / http://twitter.com/blurspline / http://www.lab4games.net/zz85/blog
  16420. *
  16421. * Subdivision Geometry Modifier
  16422. * using Catmull-Clark Subdivision Surfaces
  16423. * for creating smooth geometry meshes
  16424. *
  16425. * Note: a modifier modifies vertices and faces of geometry,
  16426. * so use THREE.GeometryUtils.clone() if orignal geoemtry needs to be retained
  16427. *
  16428. * Readings:
  16429. * http://en.wikipedia.org/wiki/Catmull%E2%80%93Clark_subdivision_surface
  16430. * http://www.rorydriscoll.com/2008/08/01/catmull-clark-subdivision-the-basics/
  16431. * http://xrt.wikidot.com/blog:31
  16432. * "Subdivision Surfaces in Character Animation"
  16433. *
  16434. * Supports:
  16435. * Closed and Open geometries.
  16436. *
  16437. * TODO:
  16438. * crease vertex and "semi-sharp" features
  16439. * selective subdivision
  16440. */
  16441. THREE.SubdivisionModifier = function( subdivisions ) {
  16442. this.subdivisions = (subdivisions === undefined ) ? 1 : subdivisions;
  16443. // Settings
  16444. this.useOldVertexColors = false;
  16445. this.supportUVs = true;
  16446. this.debug = false;
  16447. };
  16448. //THREE.SubdivisionModifier.prototype = new THREE.Modifier();
  16449. THREE.SubdivisionModifier.prototype.constructor = THREE.SubdivisionModifier;
  16450. // Applies the "modify" pattern
  16451. THREE.SubdivisionModifier.prototype.modify = function ( geometry ) {
  16452. var repeats = this.subdivisions;
  16453. while ( repeats-- > 0 ) {
  16454. this.smooth( geometry );
  16455. }
  16456. };
  16457. // Performs an iteration of Catmull-Clark Subdivision
  16458. THREE.SubdivisionModifier.prototype.smooth = function ( oldGeometry ) {
  16459. //debug( 'running smooth' );
  16460. // New set of vertices, faces and uvs
  16461. var newVertices = [], newFaces = [], newUVs = [];
  16462. function v( x, y, z ) {
  16463. newVertices.push( new THREE.Vector3( x, y, z ) );
  16464. }
  16465. var scope = this;
  16466. function debug() {
  16467. if (scope.debug) console.log.apply(console, arguments);
  16468. }
  16469. function warn() {
  16470. if (console)
  16471. console.log.apply(console, arguments);
  16472. }
  16473. function f4( a, b, c, d, oldFace, orders, facei ) {
  16474. // TODO move vertex selection over here!
  16475. var newFace = new THREE.Face4( a, b, c, d, null, oldFace.color, oldFace.material );
  16476. if (scope.useOldVertexColors) {
  16477. newFace.vertexColors = [];
  16478. var color, tmpColor, order;
  16479. for (var i=0;i<4;i++) {
  16480. order = orders[i];
  16481. color = new THREE.Color(),
  16482. color.setRGB(0,0,0);
  16483. for (var j=0, jl=0; j<order.length;j++) {
  16484. tmpColor = oldFace.vertexColors[order[j]-1];
  16485. color.r += tmpColor.r;
  16486. color.g += tmpColor.g;
  16487. color.b += tmpColor.b;
  16488. }
  16489. color.r /= order.length;
  16490. color.g /= order.length;
  16491. color.b /= order.length;
  16492. newFace.vertexColors[i] = color;
  16493. }
  16494. }
  16495. newFaces.push( newFace );
  16496. if (scope.supportUVs) {
  16497. var aUv = [
  16498. getUV(a, ''),
  16499. getUV(b, facei),
  16500. getUV(c, facei),
  16501. getUV(d, facei)
  16502. ];
  16503. if (!aUv[0]) debug('a :( ', a+':'+facei);
  16504. else if (!aUv[1]) debug('b :( ', b+':'+facei);
  16505. else if (!aUv[2]) debug('c :( ', c+':'+facei);
  16506. else if (!aUv[3]) debug('d :( ', d+':'+facei);
  16507. else
  16508. newUVs.push( aUv );
  16509. }
  16510. }
  16511. function edge_hash( a, b ) {
  16512. return Math.min( a, b ) + "_" + Math.max( a, b );
  16513. }
  16514. function computeEdgeFaces( geometry ) {
  16515. var i, il, v1, v2, j, k,
  16516. face, faceIndices, faceIndex,
  16517. edge,
  16518. hash,
  16519. edgeFaceMap = {};
  16520. function mapEdgeHash( hash, i ) {
  16521. if ( edgeFaceMap[ hash ] === undefined ) {
  16522. edgeFaceMap[ hash ] = [];
  16523. }
  16524. edgeFaceMap[ hash ].push( i );
  16525. }
  16526. // construct vertex -> face map
  16527. for( i = 0, il = geometry.faces.length; i < il; i ++ ) {
  16528. face = geometry.faces[ i ];
  16529. if ( face instanceof THREE.Face3 ) {
  16530. hash = edge_hash( face.a, face.b );
  16531. mapEdgeHash( hash, i );
  16532. hash = edge_hash( face.b, face.c );
  16533. mapEdgeHash( hash, i );
  16534. hash = edge_hash( face.c, face.a );
  16535. mapEdgeHash( hash, i );
  16536. } else if ( face instanceof THREE.Face4 ) {
  16537. hash = edge_hash( face.a, face.b );
  16538. mapEdgeHash( hash, i );
  16539. hash = edge_hash( face.b, face.c );
  16540. mapEdgeHash( hash, i );
  16541. hash = edge_hash( face.c, face.d );
  16542. mapEdgeHash( hash, i );
  16543. hash = edge_hash( face.d, face.a );
  16544. mapEdgeHash( hash, i );
  16545. }
  16546. }
  16547. // extract faces
  16548. // var edges = [];
  16549. //
  16550. // var numOfEdges = 0;
  16551. // for (i in edgeFaceMap) {
  16552. // numOfEdges++;
  16553. //
  16554. // edge = edgeFaceMap[i];
  16555. // edges.push(edge);
  16556. //
  16557. // }
  16558. //debug('edgeFaceMap', edgeFaceMap, 'geometry.edges',geometry.edges, 'numOfEdges', numOfEdges);
  16559. return edgeFaceMap;
  16560. }
  16561. var originalPoints = oldGeometry.vertices;
  16562. var originalFaces = oldGeometry.faces;
  16563. var newPoints = originalPoints.concat(); // Vertices
  16564. var facePoints = [], edgePoints = {};
  16565. var sharpEdges = {}, sharpVertices = [], sharpFaces = [];
  16566. var uvForVertices = {}; // Stored in {vertex}:{old face} format
  16567. var originalVerticesLength = originalPoints.length;
  16568. function getUV(vertexNo, oldFaceNo) {
  16569. var j,jl;
  16570. var key = vertexNo+':'+oldFaceNo;
  16571. var theUV = uvForVertices[key];
  16572. if (!theUV) {
  16573. if (vertexNo>=originalVerticesLength && vertexNo < (originalVerticesLength + originalFaces.length)) {
  16574. debug('face pt');
  16575. } else {
  16576. debug('edge pt');
  16577. }
  16578. warn('warning, UV not found for', key);
  16579. return null;
  16580. }
  16581. return theUV;
  16582. // Original faces -> Vertex Nos.
  16583. // new Facepoint -> Vertex Nos.
  16584. // edge Points
  16585. }
  16586. function addUV(vertexNo, oldFaceNo, value) {
  16587. var key = vertexNo+':'+oldFaceNo;
  16588. if (!(key in uvForVertices)) {
  16589. uvForVertices[key] = value;
  16590. } else {
  16591. warn('dup vertexNo', vertexNo, 'oldFaceNo', oldFaceNo, 'value', value, 'key', key, uvForVertices[key]);
  16592. }
  16593. }
  16594. // Step 1
  16595. // For each face, add a face point
  16596. // Set each face point to be the centroid of all original points for the respective face.
  16597. // debug(oldGeometry);
  16598. var i, il, j, jl, face;
  16599. // For Uvs
  16600. var uvs = oldGeometry.faceVertexUvs[0];
  16601. var abcd = 'abcd', vertice;
  16602. debug('originalFaces, uvs, originalVerticesLength', originalFaces.length, uvs.length, originalVerticesLength);
  16603. if (scope.supportUVs)
  16604. for (i=0, il = uvs.length; i<il; i++ ) {
  16605. for (j=0,jl=uvs[i].length;j<jl;j++) {
  16606. vertice = originalFaces[i][abcd.charAt(j)];
  16607. addUV(vertice, i, uvs[i][j]);
  16608. }
  16609. }
  16610. if (uvs.length == 0) scope.supportUVs = false;
  16611. // Additional UVs check, if we index original
  16612. var uvCount = 0;
  16613. for (var u in uvForVertices) {
  16614. uvCount++;
  16615. }
  16616. if (!uvCount) {
  16617. scope.supportUVs = false;
  16618. debug('no uvs');
  16619. }
  16620. debug('-- Original Faces + Vertices UVs completed', uvForVertices, 'vs', uvs.length);
  16621. var avgUv ;
  16622. for (i=0, il = originalFaces.length; i<il ;i++) {
  16623. face = originalFaces[ i ];
  16624. facePoints.push( face.centroid );
  16625. newPoints.push( face.centroid );
  16626. if (!scope.supportUVs) continue;
  16627. // Prepare subdivided uv
  16628. avgUv = new THREE.UV();
  16629. if ( face instanceof THREE.Face3 ) {
  16630. avgUv.u = getUV( face.a, i ).u + getUV( face.b, i ).u + getUV( face.c, i ).u;
  16631. avgUv.v = getUV( face.a, i ).v + getUV( face.b, i ).v + getUV( face.c, i ).v;
  16632. avgUv.u /= 3;
  16633. avgUv.v /= 3;
  16634. } else if ( face instanceof THREE.Face4 ) {
  16635. avgUv.u = getUV( face.a, i ).u + getUV( face.b, i ).u + getUV( face.c, i ).u + getUV( face.d, i ).u;
  16636. avgUv.v = getUV( face.a, i ).v + getUV( face.b, i ).v + getUV( face.c, i ).v + getUV( face.d, i ).v;
  16637. avgUv.u /= 4;
  16638. avgUv.v /= 4;
  16639. }
  16640. addUV(originalVerticesLength + i, '', avgUv);
  16641. }
  16642. debug('-- added UVs for new Faces', uvForVertices);
  16643. // Step 2
  16644. // For each edge, add an edge point.
  16645. // Set each edge point to be the average of the two neighbouring face points and its two original endpoints.
  16646. var edgeFaceMap = computeEdgeFaces ( oldGeometry ); // Edge Hash -> Faces Index
  16647. var edge, faceIndexA, faceIndexB, avg;
  16648. // debug('edgeFaceMap', edgeFaceMap);
  16649. var edgeCount = 0;
  16650. var edgeVertex, edgeVertexA, edgeVertexB;
  16651. ////
  16652. var vertexEdgeMap = {}; // Gives edges connecting from each vertex
  16653. var vertexFaceMap = {}; // Gives faces connecting from each vertex
  16654. function addVertexEdgeMap(vertex, edge) {
  16655. if (vertexEdgeMap[vertex]===undefined) {
  16656. vertexEdgeMap[vertex] = [];
  16657. }
  16658. vertexEdgeMap[vertex].push(edge);
  16659. }
  16660. function addVertexFaceMap(vertex, face, edge) {
  16661. if (vertexFaceMap[vertex]===undefined) {
  16662. vertexFaceMap[vertex] = {};
  16663. }
  16664. vertexFaceMap[vertex][face] = edge;
  16665. // vertexFaceMap[vertex][face] = null;
  16666. }
  16667. // Prepares vertexEdgeMap and vertexFaceMap
  16668. for (i in edgeFaceMap) { // This is for every edge
  16669. edge = edgeFaceMap[i];
  16670. edgeVertex = i.split('_');
  16671. edgeVertexA = edgeVertex[0];
  16672. edgeVertexB = edgeVertex[1];
  16673. // Maps an edgeVertex to connecting edges
  16674. addVertexEdgeMap(edgeVertexA, [edgeVertexA, edgeVertexB] );
  16675. addVertexEdgeMap(edgeVertexB, [edgeVertexA, edgeVertexB] );
  16676. for (j=0,jl=edge.length;j<jl;j++) {
  16677. face = edge[j];
  16678. addVertexFaceMap(edgeVertexA, face, i);
  16679. addVertexFaceMap(edgeVertexB, face, i);
  16680. }
  16681. if (edge.length < 2) {
  16682. // edge is "sharp";
  16683. sharpEdges[i] = true;
  16684. sharpVertices[edgeVertexA] = true;
  16685. sharpVertices[edgeVertexB] = true;
  16686. }
  16687. }
  16688. debug('vertexEdgeMap',vertexEdgeMap, 'vertexFaceMap', vertexFaceMap);
  16689. for (i in edgeFaceMap) {
  16690. edge = edgeFaceMap[i];
  16691. faceIndexA = edge[0]; // face index a
  16692. faceIndexB = edge[1]; // face index b
  16693. edgeVertex = i.split('_');
  16694. edgeVertexA = edgeVertex[0];
  16695. edgeVertexB = edgeVertex[1];
  16696. avg = new THREE.Vector3();
  16697. //debug(i, faceIndexB,facePoints[faceIndexB]);
  16698. if (sharpEdges[i]) {
  16699. //debug('warning, ', i, 'edge has only 1 connecting face', edge);
  16700. // For a sharp edge, average the edge end points.
  16701. avg.addSelf(originalPoints[edgeVertexA]);
  16702. avg.addSelf(originalPoints[edgeVertexB]);
  16703. avg.multiplyScalar(0.5);
  16704. sharpVertices[newPoints.length] = true;
  16705. } else {
  16706. avg.addSelf(facePoints[faceIndexA]);
  16707. avg.addSelf(facePoints[faceIndexB]);
  16708. avg.addSelf(originalPoints[edgeVertexA]);
  16709. avg.addSelf(originalPoints[edgeVertexB]);
  16710. avg.multiplyScalar(0.25);
  16711. }
  16712. edgePoints[i] = originalVerticesLength + originalFaces.length + edgeCount;
  16713. newPoints.push( avg );
  16714. edgeCount ++;
  16715. if (!scope.supportUVs) {
  16716. continue;
  16717. }
  16718. // debug('faceIndexAB', faceIndexA, faceIndexB, sharpEdges[i]);
  16719. // Prepare subdivided uv
  16720. avgUv = new THREE.UV();
  16721. avgUv.u = getUV(edgeVertexA, faceIndexA).u + getUV(edgeVertexB, faceIndexA).u;
  16722. avgUv.v = getUV(edgeVertexA, faceIndexA).v + getUV(edgeVertexB, faceIndexA).v;
  16723. avgUv.u /= 2;
  16724. avgUv.v /= 2;
  16725. addUV(edgePoints[i], faceIndexA, avgUv);
  16726. if (!sharpEdges[i]) {
  16727. avgUv = new THREE.UV();
  16728. avgUv.u = getUV(edgeVertexA, faceIndexB).u + getUV(edgeVertexB, faceIndexB).u;
  16729. avgUv.v = getUV(edgeVertexA, faceIndexB).v + getUV(edgeVertexB, faceIndexB).v;
  16730. avgUv.u /= 2;
  16731. avgUv.v /= 2;
  16732. addUV(edgePoints[i], faceIndexB, avgUv);
  16733. }
  16734. }
  16735. debug('-- Step 2 done');
  16736. // Step 3
  16737. // For each face point, add an edge for every edge of the face,
  16738. // connecting the face point to each edge point for the face.
  16739. var facePt, currentVerticeIndex;
  16740. var hashAB, hashBC, hashCD, hashDA, hashCA;
  16741. var abc123 = ['123', '12', '2', '23'];
  16742. var bca123 = ['123', '23', '3', '31'];
  16743. var cab123 = ['123', '31', '1', '12'];
  16744. var abc1234 = ['1234', '12', '2', '23'];
  16745. var bcd1234 = ['1234', '23', '3', '34'];
  16746. var cda1234 = ['1234', '34', '4', '41'];
  16747. var dab1234 = ['1234', '41', '1', '12'];
  16748. for (i=0, il = facePoints.length; i<il ;i++) { // for every face
  16749. facePt = facePoints[i];
  16750. face = originalFaces[i];
  16751. currentVerticeIndex = originalVerticesLength+ i;
  16752. if ( face instanceof THREE.Face3 ) {
  16753. // create 3 face4s
  16754. hashAB = edge_hash( face.a, face.b );
  16755. hashBC = edge_hash( face.b, face.c );
  16756. hashCA = edge_hash( face.c, face.a );
  16757. f4( currentVerticeIndex, edgePoints[hashAB], face.b, edgePoints[hashBC], face, abc123, i );
  16758. f4( currentVerticeIndex, edgePoints[hashBC], face.c, edgePoints[hashCA], face, bca123, i );
  16759. f4( currentVerticeIndex, edgePoints[hashCA], face.a, edgePoints[hashAB], face, cab123, i );
  16760. } else if ( face instanceof THREE.Face4 ) {
  16761. // create 4 face4s
  16762. hashAB = edge_hash( face.a, face.b );
  16763. hashBC = edge_hash( face.b, face.c );
  16764. hashCD = edge_hash( face.c, face.d );
  16765. hashDA = edge_hash( face.d, face.a );
  16766. f4( currentVerticeIndex, edgePoints[hashAB], face.b, edgePoints[hashBC], face, abc1234, i );
  16767. f4( currentVerticeIndex, edgePoints[hashBC], face.c, edgePoints[hashCD], face, bcd1234, i );
  16768. f4( currentVerticeIndex, edgePoints[hashCD], face.d, edgePoints[hashDA], face, cda1234, i );
  16769. f4( currentVerticeIndex, edgePoints[hashDA], face.a, edgePoints[hashAB], face, dab1234, i );
  16770. } else {
  16771. debug('face should be a face!', face);
  16772. }
  16773. }
  16774. newVertices = newPoints;
  16775. // debug('original ', oldGeometry.vertices.length, oldGeometry.faces.length );
  16776. // debug('new points', newPoints.length, 'faces', newFaces.length );
  16777. // Step 4
  16778. // For each original point P,
  16779. // take the average F of all n face points for faces touching P,
  16780. // and take the average R of all n edge midpoints for edges touching P,
  16781. // where each edge midpoint is the average of its two endpoint vertices.
  16782. // Move each original point to the point
  16783. var F = new THREE.Vector3();
  16784. var R = new THREE.Vector3();
  16785. var n;
  16786. for (i=0, il = originalPoints.length; i<il; i++) {
  16787. // (F + 2R + (n-3)P) / n
  16788. if (vertexEdgeMap[i]===undefined) continue;
  16789. F.set(0,0,0);
  16790. R.set(0,0,0);
  16791. var newPos = new THREE.Vector3(0,0,0);
  16792. var f =0;
  16793. for (j in vertexFaceMap[i]) {
  16794. F.addSelf(facePoints[j]);
  16795. f++;
  16796. }
  16797. var sharpEdgeCount = 0;
  16798. n = vertexEdgeMap[i].length;
  16799. for (j=0;j<n;j++) {
  16800. if (
  16801. sharpEdges[
  16802. edge_hash(vertexEdgeMap[i][j][0],vertexEdgeMap[i][j][1])
  16803. ]) {
  16804. sharpEdgeCount++;
  16805. }
  16806. }
  16807. if ( sharpEdgeCount==2 ) {
  16808. continue;
  16809. // Do not move vertex if there's 2 connecting sharp edges.
  16810. }
  16811. /*
  16812. if (sharpEdgeCount>2) {
  16813. // TODO
  16814. }
  16815. */
  16816. F.divideScalar(f);
  16817. for (j=0; j<n;j++) {
  16818. edge = vertexEdgeMap[i][j];
  16819. var midPt = originalPoints[edge[0]].clone().addSelf(originalPoints[edge[1]]).divideScalar(2);
  16820. R.addSelf(midPt);
  16821. // R.addSelf(originalPoints[edge[0]]);
  16822. // R.addSelf(originalPoints[edge[1]]);
  16823. }
  16824. R.divideScalar(n);
  16825. newPos.addSelf(originalPoints[i]);
  16826. newPos.multiplyScalar(n - 3);
  16827. newPos.addSelf(F);
  16828. newPos.addSelf(R.multiplyScalar(2));
  16829. newPos.divideScalar(n);
  16830. newVertices[i] = newPos;
  16831. }
  16832. var newGeometry = oldGeometry; // Let's pretend the old geometry is now new :P
  16833. newGeometry.vertices = newVertices;
  16834. newGeometry.faces = newFaces;
  16835. newGeometry.faceVertexUvs[ 0 ] = newUVs;
  16836. delete newGeometry.__tmpVertices; // makes __tmpVertices undefined :P
  16837. newGeometry.computeCentroids();
  16838. newGeometry.computeFaceNormals();
  16839. newGeometry.computeVertexNormals();
  16840. };
  16841. /**
  16842. * @author alteredq / http://alteredqualia.com/
  16843. */
  16844. THREE.Loader = function ( showStatus ) {
  16845. this.showStatus = showStatus;
  16846. this.statusDomElement = showStatus ? THREE.Loader.prototype.addStatusElement() : null;
  16847. this.onLoadStart = function () {};
  16848. this.onLoadProgress = function() {};
  16849. this.onLoadComplete = function () {};
  16850. };
  16851. THREE.Loader.prototype = {
  16852. constructor: THREE.Loader,
  16853. crossOrigin: 'anonymous',
  16854. addStatusElement: function () {
  16855. var e = document.createElement( "div" );
  16856. e.style.position = "absolute";
  16857. e.style.right = "0px";
  16858. e.style.top = "0px";
  16859. e.style.fontSize = "0.8em";
  16860. e.style.textAlign = "left";
  16861. e.style.background = "rgba(0,0,0,0.25)";
  16862. e.style.color = "#fff";
  16863. e.style.width = "120px";
  16864. e.style.padding = "0.5em 0.5em 0.5em 0.5em";
  16865. e.style.zIndex = 1000;
  16866. e.innerHTML = "Loading ...";
  16867. return e;
  16868. },
  16869. updateProgress: function ( progress ) {
  16870. var message = "Loaded ";
  16871. if ( progress.total ) {
  16872. message += ( 100 * progress.loaded / progress.total ).toFixed(0) + "%";
  16873. } else {
  16874. message += ( progress.loaded / 1000 ).toFixed(2) + " KB";
  16875. }
  16876. this.statusDomElement.innerHTML = message;
  16877. },
  16878. extractUrlBase: function ( url ) {
  16879. var parts = url.split( '/' );
  16880. parts.pop();
  16881. return ( parts.length < 1 ? '.' : parts.join( '/' ) ) + '/';
  16882. },
  16883. initMaterials: function ( scope, materials, texturePath ) {
  16884. scope.materials = [];
  16885. for ( var i = 0; i < materials.length; ++ i ) {
  16886. scope.materials[ i ] = THREE.Loader.prototype.createMaterial( materials[ i ], texturePath );
  16887. }
  16888. },
  16889. hasNormals: function ( scope ) {
  16890. var m, i, il = scope.materials.length;
  16891. for( i = 0; i < il; i ++ ) {
  16892. m = scope.materials[ i ];
  16893. if ( m instanceof THREE.ShaderMaterial ) return true;
  16894. }
  16895. return false;
  16896. },
  16897. createMaterial: function ( m, texturePath ) {
  16898. var _this = this;
  16899. function is_pow2( n ) {
  16900. var l = Math.log( n ) / Math.LN2;
  16901. return Math.floor( l ) == l;
  16902. }
  16903. function nearest_pow2( n ) {
  16904. var l = Math.log( n ) / Math.LN2;
  16905. return Math.pow( 2, Math.round( l ) );
  16906. }
  16907. function load_image( where, url ) {
  16908. var image = new Image();
  16909. image.onload = function () {
  16910. if ( !is_pow2( this.width ) || !is_pow2( this.height ) ) {
  16911. var width = nearest_pow2( this.width );
  16912. var height = nearest_pow2( this.height );
  16913. where.image.width = width;
  16914. where.image.height = height;
  16915. where.image.getContext( '2d' ).drawImage( this, 0, 0, width, height );
  16916. } else {
  16917. where.image = this;
  16918. }
  16919. where.needsUpdate = true;
  16920. };
  16921. image.crossOrigin = _this.crossOrigin;
  16922. image.src = url;
  16923. }
  16924. function create_texture( where, name, sourceFile, repeat, offset, wrap ) {
  16925. var texture = document.createElement( 'canvas' );
  16926. where[ name ] = new THREE.Texture( texture );
  16927. where[ name ].sourceFile = sourceFile;
  16928. if( repeat ) {
  16929. where[ name ].repeat.set( repeat[ 0 ], repeat[ 1 ] );
  16930. if ( repeat[ 0 ] != 1 ) where[ name ].wrapS = THREE.RepeatWrapping;
  16931. if ( repeat[ 1 ] != 1 ) where[ name ].wrapT = THREE.RepeatWrapping;
  16932. }
  16933. if ( offset ) {
  16934. where[ name ].offset.set( offset[ 0 ], offset[ 1 ] );
  16935. }
  16936. if ( wrap ) {
  16937. var wrapMap = {
  16938. "repeat" : THREE.RepeatWrapping,
  16939. "mirror" : THREE.MirroredRepeatWrapping
  16940. }
  16941. if ( wrapMap[ wrap[ 0 ] ] !== undefined ) where[ name ].wrapS = wrapMap[ wrap[ 0 ] ];
  16942. if ( wrapMap[ wrap[ 1 ] ] !== undefined ) where[ name ].wrapT = wrapMap[ wrap[ 1 ] ];
  16943. }
  16944. load_image( where[ name ], texturePath + "/" + sourceFile );
  16945. }
  16946. function rgb2hex( rgb ) {
  16947. return ( rgb[ 0 ] * 255 << 16 ) + ( rgb[ 1 ] * 255 << 8 ) + rgb[ 2 ] * 255;
  16948. }
  16949. // defaults
  16950. var mtype = "MeshLambertMaterial";
  16951. var mpars = { color: 0xeeeeee, opacity: 1.0, map: null, lightMap: null, normalMap: null, wireframe: m.wireframe };
  16952. // parameters from model file
  16953. if ( m.shading ) {
  16954. var shading = m.shading.toLowerCase();
  16955. if ( shading === "phong" ) mtype = "MeshPhongMaterial";
  16956. else if ( shading === "basic" ) mtype = "MeshBasicMaterial";
  16957. }
  16958. if ( m.blending !== undefined && THREE[ m.blending ] !== undefined ) {
  16959. mpars.blending = THREE[ m.blending ];
  16960. }
  16961. if ( m.transparent !== undefined || m.opacity < 1.0 ) {
  16962. mpars.transparent = m.transparent;
  16963. }
  16964. if ( m.depthTest !== undefined ) {
  16965. mpars.depthTest = m.depthTest;
  16966. }
  16967. if ( m.depthWrite !== undefined ) {
  16968. mpars.depthWrite = m.depthWrite;
  16969. }
  16970. if ( m.vertexColors !== undefined ) {
  16971. if ( m.vertexColors == "face" ) {
  16972. mpars.vertexColors = THREE.FaceColors;
  16973. } else if ( m.vertexColors ) {
  16974. mpars.vertexColors = THREE.VertexColors;
  16975. }
  16976. }
  16977. // colors
  16978. if ( m.colorDiffuse ) {
  16979. mpars.color = rgb2hex( m.colorDiffuse );
  16980. } else if ( m.DbgColor ) {
  16981. mpars.color = m.DbgColor;
  16982. }
  16983. if ( m.colorSpecular ) {
  16984. mpars.specular = rgb2hex( m.colorSpecular );
  16985. }
  16986. if ( m.colorAmbient ) {
  16987. mpars.ambient = rgb2hex( m.colorAmbient );
  16988. }
  16989. // modifiers
  16990. if ( m.transparency ) {
  16991. mpars.opacity = m.transparency;
  16992. }
  16993. if ( m.specularCoef ) {
  16994. mpars.shininess = m.specularCoef;
  16995. }
  16996. // textures
  16997. if ( m.mapDiffuse && texturePath ) {
  16998. create_texture( mpars, "map", m.mapDiffuse, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap );
  16999. }
  17000. if ( m.mapLight && texturePath ) {
  17001. create_texture( mpars, "lightMap", m.mapLight, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap );
  17002. }
  17003. if ( m.mapNormal && texturePath ) {
  17004. create_texture( mpars, "normalMap", m.mapNormal, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap );
  17005. }
  17006. if ( m.mapSpecular && texturePath ) {
  17007. create_texture( mpars, "specularMap", m.mapSpecular, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap );
  17008. }
  17009. // special case for normal mapped material
  17010. if ( m.mapNormal ) {
  17011. var shader = THREE.ShaderUtils.lib[ "normal" ];
  17012. var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
  17013. uniforms[ "tNormal" ].texture = mpars.normalMap;
  17014. if ( m.mapNormalFactor ) {
  17015. uniforms[ "uNormalScale" ].value = m.mapNormalFactor;
  17016. }
  17017. if ( mpars.map ) {
  17018. uniforms[ "tDiffuse" ].texture = mpars.map;
  17019. uniforms[ "enableDiffuse" ].value = true;
  17020. }
  17021. if ( mpars.specularMap ) {
  17022. uniforms[ "tSpecular" ].texture = mpars.specularMap;
  17023. uniforms[ "enableSpecular" ].value = true;
  17024. }
  17025. if ( mpars.lightMap ) {
  17026. uniforms[ "tAO" ].texture = mpars.lightMap;
  17027. uniforms[ "enableAO" ].value = true;
  17028. }
  17029. // for the moment don't handle displacement texture
  17030. uniforms[ "uDiffuseColor" ].value.setHex( mpars.color );
  17031. uniforms[ "uSpecularColor" ].value.setHex( mpars.specular );
  17032. uniforms[ "uAmbientColor" ].value.setHex( mpars.ambient );
  17033. uniforms[ "uShininess" ].value = mpars.shininess;
  17034. if ( mpars.opacity !== undefined ) {
  17035. uniforms[ "uOpacity" ].value = mpars.opacity;
  17036. }
  17037. var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true, fog: true };
  17038. var material = new THREE.ShaderMaterial( parameters );
  17039. } else {
  17040. var material = new THREE[ mtype ]( mpars );
  17041. }
  17042. if ( m.DbgName !== undefined ) material.name = m.DbgName;
  17043. return material;
  17044. }
  17045. };
  17046. /**
  17047. * @author alteredq / http://alteredqualia.com/
  17048. */
  17049. THREE.BinaryLoader = function ( showStatus ) {
  17050. THREE.Loader.call( this, showStatus );
  17051. };
  17052. THREE.BinaryLoader.prototype = new THREE.Loader();
  17053. THREE.BinaryLoader.prototype.constructor = THREE.BinaryLoader;
  17054. THREE.BinaryLoader.prototype.supr = THREE.Loader.prototype;
  17055. // Load models generated by slim OBJ converter with BINARY option (converter_obj_three_slim.py -t binary)
  17056. // - binary models consist of two files: JS and BIN
  17057. // - parameters
  17058. // - url (required)
  17059. // - callback (required)
  17060. // - texturePath (optional: if not specified, textures will be assumed to be in the same folder as JS model file)
  17061. // - binaryPath (optional: if not specified, binary file will be assumed to be in the same folder as JS model file)
  17062. THREE.BinaryLoader.prototype.load = function( url, callback, texturePath, binaryPath ) {
  17063. texturePath = texturePath ? texturePath : this.extractUrlBase( url );
  17064. binaryPath = binaryPath ? binaryPath : this.extractUrlBase( url );
  17065. var callbackProgress = this.showProgress ? THREE.Loader.prototype.updateProgress : null;
  17066. this.onLoadStart();
  17067. // #1 load JS part via web worker
  17068. this.loadAjaxJSON( this, url, callback, texturePath, binaryPath, callbackProgress );
  17069. };
  17070. THREE.BinaryLoader.prototype.loadAjaxJSON = function ( context, url, callback, texturePath, binaryPath, callbackProgress ) {
  17071. var xhr = new XMLHttpRequest();
  17072. xhr.onreadystatechange = function () {
  17073. if ( xhr.readyState == 4 ) {
  17074. if ( xhr.status == 200 || xhr.status == 0 ) {
  17075. var json = JSON.parse( xhr.responseText );
  17076. context.loadAjaxBuffers( json, callback, binaryPath, texturePath, callbackProgress );
  17077. } else {
  17078. console.error( "THREE.BinaryLoader: Couldn't load [" + url + "] [" + xhr.status + "]" );
  17079. }
  17080. }
  17081. };
  17082. xhr.open( "GET", url, true );
  17083. if ( xhr.overrideMimeType ) xhr.overrideMimeType( "text/plain; charset=x-user-defined" );
  17084. xhr.setRequestHeader( "Content-Type", "text/plain" );
  17085. xhr.send( null );
  17086. };
  17087. THREE.BinaryLoader.prototype.loadAjaxBuffers = function ( json, callback, binaryPath, texturePath, callbackProgress ) {
  17088. var xhr = new XMLHttpRequest(),
  17089. url = binaryPath + "/" + json.buffers;
  17090. var length = 0;
  17091. xhr.onreadystatechange = function () {
  17092. if ( xhr.readyState == 4 ) {
  17093. if ( xhr.status == 200 || xhr.status == 0 ) {
  17094. THREE.BinaryLoader.prototype.createBinModel( xhr.response, callback, texturePath, json.materials );
  17095. } else {
  17096. console.error( "THREE.BinaryLoader: Couldn't load [" + url + "] [" + xhr.status + "]" );
  17097. }
  17098. } else if ( xhr.readyState == 3 ) {
  17099. if ( callbackProgress ) {
  17100. if ( length == 0 ) {
  17101. length = xhr.getResponseHeader( "Content-Length" );
  17102. }
  17103. callbackProgress( { total: length, loaded: xhr.responseText.length } );
  17104. }
  17105. } else if ( xhr.readyState == 2 ) {
  17106. length = xhr.getResponseHeader( "Content-Length" );
  17107. }
  17108. };
  17109. xhr.open( "GET", url, true );
  17110. xhr.responseType = "arraybuffer";
  17111. xhr.send( null );
  17112. };
  17113. // Binary AJAX parser
  17114. THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texturePath, materials ) {
  17115. var Model = function ( texturePath ) {
  17116. var scope = this,
  17117. currentOffset = 0,
  17118. md,
  17119. normals = [],
  17120. uvs = [],
  17121. start_tri_flat, start_tri_smooth, start_tri_flat_uv, start_tri_smooth_uv,
  17122. start_quad_flat, start_quad_smooth, start_quad_flat_uv, start_quad_smooth_uv,
  17123. tri_size, quad_size,
  17124. len_tri_flat, len_tri_smooth, len_tri_flat_uv, len_tri_smooth_uv,
  17125. len_quad_flat, len_quad_smooth, len_quad_flat_uv, len_quad_smooth_uv;
  17126. THREE.Geometry.call( this );
  17127. THREE.Loader.prototype.initMaterials( scope, materials, texturePath );
  17128. md = parseMetaData( data, currentOffset );
  17129. currentOffset += md.header_bytes;
  17130. /*
  17131. md.vertex_index_bytes = Uint32Array.BYTES_PER_ELEMENT;
  17132. md.material_index_bytes = Uint16Array.BYTES_PER_ELEMENT;
  17133. md.normal_index_bytes = Uint32Array.BYTES_PER_ELEMENT;
  17134. md.uv_index_bytes = Uint32Array.BYTES_PER_ELEMENT;
  17135. */
  17136. // buffers sizes
  17137. tri_size = md.vertex_index_bytes * 3 + md.material_index_bytes;
  17138. quad_size = md.vertex_index_bytes * 4 + md.material_index_bytes;
  17139. len_tri_flat = md.ntri_flat * ( tri_size );
  17140. len_tri_smooth = md.ntri_smooth * ( tri_size + md.normal_index_bytes * 3 );
  17141. len_tri_flat_uv = md.ntri_flat_uv * ( tri_size + md.uv_index_bytes * 3 );
  17142. len_tri_smooth_uv = md.ntri_smooth_uv * ( tri_size + md.normal_index_bytes * 3 + md.uv_index_bytes * 3 );
  17143. len_quad_flat = md.nquad_flat * ( quad_size );
  17144. len_quad_smooth = md.nquad_smooth * ( quad_size + md.normal_index_bytes * 4 );
  17145. len_quad_flat_uv = md.nquad_flat_uv * ( quad_size + md.uv_index_bytes * 4 );
  17146. len_quad_smooth_uv = md.nquad_smooth_uv * ( quad_size + md.normal_index_bytes * 4 + md.uv_index_bytes * 4 );
  17147. // read buffers
  17148. currentOffset += init_vertices( currentOffset );
  17149. currentOffset += init_normals( currentOffset );
  17150. currentOffset += handlePadding( md.nnormals * 3 );
  17151. currentOffset += init_uvs( currentOffset );
  17152. start_tri_flat = currentOffset;
  17153. start_tri_smooth = start_tri_flat + len_tri_flat + handlePadding( md.ntri_flat * 2 );
  17154. start_tri_flat_uv = start_tri_smooth + len_tri_smooth + handlePadding( md.ntri_smooth * 2 );
  17155. start_tri_smooth_uv = start_tri_flat_uv + len_tri_flat_uv + handlePadding( md.ntri_flat_uv * 2 );
  17156. start_quad_flat = start_tri_smooth_uv + len_tri_smooth_uv + handlePadding( md.ntri_smooth_uv * 2 );
  17157. start_quad_smooth = start_quad_flat + len_quad_flat + handlePadding( md.nquad_flat * 2 );
  17158. start_quad_flat_uv = start_quad_smooth + len_quad_smooth + handlePadding( md.nquad_smooth * 2 );
  17159. start_quad_smooth_uv= start_quad_flat_uv + len_quad_flat_uv + handlePadding( md.nquad_flat_uv * 2 );
  17160. // have to first process faces with uvs
  17161. // so that face and uv indices match
  17162. init_triangles_flat_uv( start_tri_flat_uv );
  17163. init_triangles_smooth_uv( start_tri_smooth_uv );
  17164. init_quads_flat_uv( start_quad_flat_uv );
  17165. init_quads_smooth_uv( start_quad_smooth_uv );
  17166. // now we can process untextured faces
  17167. init_triangles_flat( start_tri_flat );
  17168. init_triangles_smooth( start_tri_smooth );
  17169. init_quads_flat( start_quad_flat );
  17170. init_quads_smooth( start_quad_smooth );
  17171. this.computeCentroids();
  17172. this.computeFaceNormals();
  17173. if ( THREE.Loader.prototype.hasNormals( this ) ) this.computeTangents();
  17174. function handlePadding( n ) {
  17175. return ( n % 4 ) ? ( 4 - n % 4 ) : 0;
  17176. };
  17177. function parseMetaData( data, offset ) {
  17178. var metaData = {
  17179. 'signature' :parseString( data, offset, 12 ),
  17180. 'header_bytes' :parseUChar8( data, offset + 12 ),
  17181. 'vertex_coordinate_bytes' :parseUChar8( data, offset + 13 ),
  17182. 'normal_coordinate_bytes' :parseUChar8( data, offset + 14 ),
  17183. 'uv_coordinate_bytes' :parseUChar8( data, offset + 15 ),
  17184. 'vertex_index_bytes' :parseUChar8( data, offset + 16 ),
  17185. 'normal_index_bytes' :parseUChar8( data, offset + 17 ),
  17186. 'uv_index_bytes' :parseUChar8( data, offset + 18 ),
  17187. 'material_index_bytes' :parseUChar8( data, offset + 19 ),
  17188. 'nvertices' :parseUInt32( data, offset + 20 ),
  17189. 'nnormals' :parseUInt32( data, offset + 20 + 4*1 ),
  17190. 'nuvs' :parseUInt32( data, offset + 20 + 4*2 ),
  17191. 'ntri_flat' :parseUInt32( data, offset + 20 + 4*3 ),
  17192. 'ntri_smooth' :parseUInt32( data, offset + 20 + 4*4 ),
  17193. 'ntri_flat_uv' :parseUInt32( data, offset + 20 + 4*5 ),
  17194. 'ntri_smooth_uv' :parseUInt32( data, offset + 20 + 4*6 ),
  17195. 'nquad_flat' :parseUInt32( data, offset + 20 + 4*7 ),
  17196. 'nquad_smooth' :parseUInt32( data, offset + 20 + 4*8 ),
  17197. 'nquad_flat_uv' :parseUInt32( data, offset + 20 + 4*9 ),
  17198. 'nquad_smooth_uv' :parseUInt32( data, offset + 20 + 4*10 )
  17199. };
  17200. /*
  17201. console.log( "signature: " + metaData.signature );
  17202. console.log( "header_bytes: " + metaData.header_bytes );
  17203. console.log( "vertex_coordinate_bytes: " + metaData.vertex_coordinate_bytes );
  17204. console.log( "normal_coordinate_bytes: " + metaData.normal_coordinate_bytes );
  17205. console.log( "uv_coordinate_bytes: " + metaData.uv_coordinate_bytes );
  17206. console.log( "vertex_index_bytes: " + metaData.vertex_index_bytes );
  17207. console.log( "normal_index_bytes: " + metaData.normal_index_bytes );
  17208. console.log( "uv_index_bytes: " + metaData.uv_index_bytes );
  17209. console.log( "material_index_bytes: " + metaData.material_index_bytes );
  17210. console.log( "nvertices: " + metaData.nvertices );
  17211. console.log( "nnormals: " + metaData.nnormals );
  17212. console.log( "nuvs: " + metaData.nuvs );
  17213. console.log( "ntri_flat: " + metaData.ntri_flat );
  17214. console.log( "ntri_smooth: " + metaData.ntri_smooth );
  17215. console.log( "ntri_flat_uv: " + metaData.ntri_flat_uv );
  17216. console.log( "ntri_smooth_uv: " + metaData.ntri_smooth_uv );
  17217. console.log( "nquad_flat: " + metaData.nquad_flat );
  17218. console.log( "nquad_smooth: " + metaData.nquad_smooth );
  17219. console.log( "nquad_flat_uv: " + metaData.nquad_flat_uv );
  17220. console.log( "nquad_smooth_uv: " + metaData.nquad_smooth_uv );
  17221. var total = metaData.header_bytes
  17222. + metaData.nvertices * metaData.vertex_coordinate_bytes * 3
  17223. + metaData.nnormals * metaData.normal_coordinate_bytes * 3
  17224. + metaData.nuvs * metaData.uv_coordinate_bytes * 2
  17225. + metaData.ntri_flat * ( metaData.vertex_index_bytes*3 + metaData.material_index_bytes )
  17226. + metaData.ntri_smooth * ( metaData.vertex_index_bytes*3 + metaData.material_index_bytes + metaData.normal_index_bytes*3 )
  17227. + metaData.ntri_flat_uv * ( metaData.vertex_index_bytes*3 + metaData.material_index_bytes + metaData.uv_index_bytes*3 )
  17228. + metaData.ntri_smooth_uv * ( metaData.vertex_index_bytes*3 + metaData.material_index_bytes + metaData.normal_index_bytes*3 + metaData.uv_index_bytes*3 )
  17229. + metaData.nquad_flat * ( metaData.vertex_index_bytes*4 + metaData.material_index_bytes )
  17230. + metaData.nquad_smooth * ( metaData.vertex_index_bytes*4 + metaData.material_index_bytes + metaData.normal_index_bytes*4 )
  17231. + metaData.nquad_flat_uv * ( metaData.vertex_index_bytes*4 + metaData.material_index_bytes + metaData.uv_index_bytes*4 )
  17232. + metaData.nquad_smooth_uv * ( metaData.vertex_index_bytes*4 + metaData.material_index_bytes + metaData.normal_index_bytes*4 + metaData.uv_index_bytes*4 );
  17233. console.log( "total bytes: " + total );
  17234. */
  17235. return metaData;
  17236. };
  17237. function parseString( data, offset, length ) {
  17238. var charArray = new Uint8Array( data, offset, length );
  17239. var text = "";
  17240. for ( var i = 0; i < length; i ++ ) {
  17241. text += String.fromCharCode( charArray[ offset + i ] );
  17242. }
  17243. return text;
  17244. };
  17245. function parseUChar8( data, offset ) {
  17246. var charArray = new Uint8Array( data, offset, 1 );
  17247. return charArray[ 0 ];
  17248. };
  17249. function parseUInt32( data, offset ) {
  17250. var intArray = new Uint32Array( data, offset, 1 );
  17251. return intArray[ 0 ];
  17252. };
  17253. function init_vertices( start ) {
  17254. var nElements = md.nvertices;
  17255. var coordArray = new Float32Array( data, start, nElements * 3 );
  17256. var i, x, y, z;
  17257. for( i = 0; i < nElements; i ++ ) {
  17258. x = coordArray[ i * 3 ];
  17259. y = coordArray[ i * 3 + 1 ];
  17260. z = coordArray[ i * 3 + 2 ];
  17261. vertex( scope, x, y, z );
  17262. }
  17263. return nElements * 3 * Float32Array.BYTES_PER_ELEMENT;
  17264. };
  17265. function init_normals( start ) {
  17266. var nElements = md.nnormals;
  17267. if ( nElements ) {
  17268. var normalArray = new Int8Array( data, start, nElements * 3 );
  17269. var i, x, y, z;
  17270. for( i = 0; i < nElements; i ++ ) {
  17271. x = normalArray[ i * 3 ];
  17272. y = normalArray[ i * 3 + 1 ];
  17273. z = normalArray[ i * 3 + 2 ];
  17274. normals.push( x/127, y/127, z/127 );
  17275. }
  17276. }
  17277. return nElements * 3 * Int8Array.BYTES_PER_ELEMENT;
  17278. };
  17279. function init_uvs( start ) {
  17280. var nElements = md.nuvs;
  17281. if ( nElements ) {
  17282. var uvArray = new Float32Array( data, start, nElements * 2 );
  17283. var i, u, v;
  17284. for( i = 0; i < nElements; i ++ ) {
  17285. u = uvArray[ i * 2 ];
  17286. v = uvArray[ i * 2 + 1 ];
  17287. uvs.push( u, v );
  17288. }
  17289. }
  17290. return nElements * 2 * Float32Array.BYTES_PER_ELEMENT;
  17291. };
  17292. function init_uvs3( nElements, offset ) {
  17293. var i, uva, uvb, uvc, u1, u2, u3, v1, v2, v3;
  17294. var uvIndexBuffer = new Uint32Array( data, offset, 3 * nElements );
  17295. for( i = 0; i < nElements; i ++ ) {
  17296. uva = uvIndexBuffer[ i * 3 ];
  17297. uvb = uvIndexBuffer[ i * 3 + 1 ];
  17298. uvc = uvIndexBuffer[ i * 3 + 2 ];
  17299. u1 = uvs[ uva*2 ];
  17300. v1 = uvs[ uva*2 + 1 ];
  17301. u2 = uvs[ uvb*2 ];
  17302. v2 = uvs[ uvb*2 + 1 ];
  17303. u3 = uvs[ uvc*2 ];
  17304. v3 = uvs[ uvc*2 + 1 ];
  17305. uv3( scope.faceVertexUvs[ 0 ], u1, v1, u2, v2, u3, v3 );
  17306. }
  17307. };
  17308. function init_uvs4( nElements, offset ) {
  17309. var i, uva, uvb, uvc, uvd, u1, u2, u3, u4, v1, v2, v3, v4;
  17310. var uvIndexBuffer = new Uint32Array( data, offset, 4 * nElements );
  17311. for( i = 0; i < nElements; i ++ ) {
  17312. uva = uvIndexBuffer[ i * 4 ];
  17313. uvb = uvIndexBuffer[ i * 4 + 1 ];
  17314. uvc = uvIndexBuffer[ i * 4 + 2 ];
  17315. uvd = uvIndexBuffer[ i * 4 + 3 ];
  17316. u1 = uvs[ uva*2 ];
  17317. v1 = uvs[ uva*2 + 1 ];
  17318. u2 = uvs[ uvb*2 ];
  17319. v2 = uvs[ uvb*2 + 1 ];
  17320. u3 = uvs[ uvc*2 ];
  17321. v3 = uvs[ uvc*2 + 1 ];
  17322. u4 = uvs[ uvd*2 ];
  17323. v4 = uvs[ uvd*2 + 1 ];
  17324. uv4( scope.faceVertexUvs[ 0 ], u1, v1, u2, v2, u3, v3, u4, v4 );
  17325. }
  17326. };
  17327. function init_faces3_flat( nElements, offsetVertices, offsetMaterials ) {
  17328. var i, a, b, c, m;
  17329. var vertexIndexBuffer = new Uint32Array( data, offsetVertices, 3 * nElements );
  17330. var materialIndexBuffer = new Uint16Array( data, offsetMaterials, nElements );
  17331. for( i = 0; i < nElements; i ++ ) {
  17332. a = vertexIndexBuffer[ i * 3 ];
  17333. b = vertexIndexBuffer[ i * 3 + 1 ];
  17334. c = vertexIndexBuffer[ i * 3 + 2 ];
  17335. m = materialIndexBuffer[ i ];
  17336. f3( scope, a, b, c, m );
  17337. }
  17338. };
  17339. function init_faces4_flat( nElements, offsetVertices, offsetMaterials ) {
  17340. var i, a, b, c, d, m;
  17341. var vertexIndexBuffer = new Uint32Array( data, offsetVertices, 4 * nElements );
  17342. var materialIndexBuffer = new Uint16Array( data, offsetMaterials, nElements );
  17343. for( i = 0; i < nElements; i ++ ) {
  17344. a = vertexIndexBuffer[ i * 4 ];
  17345. b = vertexIndexBuffer[ i * 4 + 1 ];
  17346. c = vertexIndexBuffer[ i * 4 + 2 ];
  17347. d = vertexIndexBuffer[ i * 4 + 3 ];
  17348. m = materialIndexBuffer[ i ];
  17349. f4( scope, a, b, c, d, m );
  17350. }
  17351. };
  17352. function init_faces3_smooth( nElements, offsetVertices, offsetNormals, offsetMaterials ) {
  17353. var i, a, b, c, m;
  17354. var na, nb, nc;
  17355. var vertexIndexBuffer = new Uint32Array( data, offsetVertices, 3 * nElements );
  17356. var normalIndexBuffer = new Uint32Array( data, offsetNormals, 3 * nElements );
  17357. var materialIndexBuffer = new Uint16Array( data, offsetMaterials, nElements );
  17358. for( i = 0; i < nElements; i ++ ) {
  17359. a = vertexIndexBuffer[ i * 3 ];
  17360. b = vertexIndexBuffer[ i * 3 + 1 ];
  17361. c = vertexIndexBuffer[ i * 3 + 2 ];
  17362. na = normalIndexBuffer[ i * 3 ];
  17363. nb = normalIndexBuffer[ i * 3 + 1 ];
  17364. nc = normalIndexBuffer[ i * 3 + 2 ];
  17365. m = materialIndexBuffer[ i ];
  17366. f3n( scope, normals, a, b, c, m, na, nb, nc );
  17367. }
  17368. };
  17369. function init_faces4_smooth( nElements, offsetVertices, offsetNormals, offsetMaterials ) {
  17370. var i, a, b, c, d, m;
  17371. var na, nb, nc, nd;
  17372. var vertexIndexBuffer = new Uint32Array( data, offsetVertices, 4 * nElements );
  17373. var normalIndexBuffer = new Uint32Array( data, offsetNormals, 4 * nElements );
  17374. var materialIndexBuffer = new Uint16Array( data, offsetMaterials, nElements );
  17375. for( i = 0; i < nElements; i ++ ) {
  17376. a = vertexIndexBuffer[ i * 4 ];
  17377. b = vertexIndexBuffer[ i * 4 + 1 ];
  17378. c = vertexIndexBuffer[ i * 4 + 2 ];
  17379. d = vertexIndexBuffer[ i * 4 + 3 ];
  17380. na = normalIndexBuffer[ i * 4 ];
  17381. nb = normalIndexBuffer[ i * 4 + 1 ];
  17382. nc = normalIndexBuffer[ i * 4 + 2 ];
  17383. nd = normalIndexBuffer[ i * 4 + 3 ];
  17384. m = materialIndexBuffer[ i ];
  17385. f4n( scope, normals, a, b, c, d, m, na, nb, nc, nd );
  17386. }
  17387. };
  17388. function init_triangles_flat( start ) {
  17389. var nElements = md.ntri_flat;
  17390. if ( nElements ) {
  17391. var offsetMaterials = start + nElements * Uint32Array.BYTES_PER_ELEMENT * 3;
  17392. init_faces3_flat( nElements, start, offsetMaterials );
  17393. }
  17394. };
  17395. function init_triangles_flat_uv( start ) {
  17396. var nElements = md.ntri_flat_uv;
  17397. if ( nElements ) {
  17398. var offsetUvs = start + nElements * Uint32Array.BYTES_PER_ELEMENT * 3;
  17399. var offsetMaterials = offsetUvs + nElements * Uint32Array.BYTES_PER_ELEMENT * 3;
  17400. init_faces3_flat( nElements, start, offsetMaterials );
  17401. init_uvs3( nElements, offsetUvs );
  17402. }
  17403. };
  17404. function init_triangles_smooth( start ) {
  17405. var nElements = md.ntri_smooth;
  17406. if ( nElements ) {
  17407. var offsetNormals = start + nElements * Uint32Array.BYTES_PER_ELEMENT * 3;
  17408. var offsetMaterials = offsetNormals + nElements * Uint32Array.BYTES_PER_ELEMENT * 3;
  17409. init_faces3_smooth( nElements, start, offsetNormals, offsetMaterials );
  17410. }
  17411. };
  17412. function init_triangles_smooth_uv( start ) {
  17413. var nElements = md.ntri_smooth_uv;
  17414. if ( nElements ) {
  17415. var offsetNormals = start + nElements * Uint32Array.BYTES_PER_ELEMENT * 3;
  17416. var offsetUvs = offsetNormals + nElements * Uint32Array.BYTES_PER_ELEMENT * 3;
  17417. var offsetMaterials = offsetUvs + nElements * Uint32Array.BYTES_PER_ELEMENT * 3;
  17418. init_faces3_smooth( nElements, start, offsetNormals, offsetMaterials );
  17419. init_uvs3( nElements, offsetUvs );
  17420. }
  17421. };
  17422. function init_quads_flat( start ) {
  17423. var nElements = md.nquad_flat;
  17424. if ( nElements ) {
  17425. var offsetMaterials = start + nElements * Uint32Array.BYTES_PER_ELEMENT * 4;
  17426. init_faces4_flat( nElements, start, offsetMaterials );
  17427. }
  17428. };
  17429. function init_quads_flat_uv( start ) {
  17430. var nElements = md.nquad_flat_uv;
  17431. if ( nElements ) {
  17432. var offsetUvs = start + nElements * Uint32Array.BYTES_PER_ELEMENT * 4;
  17433. var offsetMaterials = offsetUvs + nElements * Uint32Array.BYTES_PER_ELEMENT * 4;
  17434. init_faces4_flat( nElements, start, offsetMaterials );
  17435. init_uvs4( nElements, offsetUvs );
  17436. }
  17437. };
  17438. function init_quads_smooth( start ) {
  17439. var nElements = md.nquad_smooth;
  17440. if ( nElements ) {
  17441. var offsetNormals = start + nElements * Uint32Array.BYTES_PER_ELEMENT * 4;
  17442. var offsetMaterials = offsetNormals + nElements * Uint32Array.BYTES_PER_ELEMENT * 4;
  17443. init_faces4_smooth( nElements, start, offsetNormals, offsetMaterials );
  17444. }
  17445. };
  17446. function init_quads_smooth_uv( start ) {
  17447. var nElements = md.nquad_smooth_uv;
  17448. if ( nElements ) {
  17449. var offsetNormals = start + nElements * Uint32Array.BYTES_PER_ELEMENT * 4;
  17450. var offsetUvs = offsetNormals + nElements * Uint32Array.BYTES_PER_ELEMENT * 4;
  17451. var offsetMaterials = offsetUvs + nElements * Uint32Array.BYTES_PER_ELEMENT * 4;
  17452. init_faces4_smooth( nElements, start, offsetNormals, offsetMaterials );
  17453. init_uvs4( nElements, offsetUvs );
  17454. }
  17455. };
  17456. };
  17457. function vertex ( scope, x, y, z ) {
  17458. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  17459. };
  17460. function f3 ( scope, a, b, c, mi ) {
  17461. scope.faces.push( new THREE.Face3( a, b, c, null, null, mi ) );
  17462. };
  17463. function f4 ( scope, a, b, c, d, mi ) {
  17464. scope.faces.push( new THREE.Face4( a, b, c, d, null, null, mi ) );
  17465. };
  17466. function f3n ( scope, normals, a, b, c, mi, na, nb, nc ) {
  17467. var nax = normals[ na*3 ],
  17468. nay = normals[ na*3 + 1 ],
  17469. naz = normals[ na*3 + 2 ],
  17470. nbx = normals[ nb*3 ],
  17471. nby = normals[ nb*3 + 1 ],
  17472. nbz = normals[ nb*3 + 2 ],
  17473. ncx = normals[ nc*3 ],
  17474. ncy = normals[ nc*3 + 1 ],
  17475. ncz = normals[ nc*3 + 2 ];
  17476. scope.faces.push( new THREE.Face3( a, b, c,
  17477. [new THREE.Vector3( nax, nay, naz ),
  17478. new THREE.Vector3( nbx, nby, nbz ),
  17479. new THREE.Vector3( ncx, ncy, ncz )],
  17480. null,
  17481. mi ) );
  17482. };
  17483. function f4n ( scope, normals, a, b, c, d, mi, na, nb, nc, nd ) {
  17484. var nax = normals[ na*3 ],
  17485. nay = normals[ na*3 + 1 ],
  17486. naz = normals[ na*3 + 2 ],
  17487. nbx = normals[ nb*3 ],
  17488. nby = normals[ nb*3 + 1 ],
  17489. nbz = normals[ nb*3 + 2 ],
  17490. ncx = normals[ nc*3 ],
  17491. ncy = normals[ nc*3 + 1 ],
  17492. ncz = normals[ nc*3 + 2 ],
  17493. ndx = normals[ nd*3 ],
  17494. ndy = normals[ nd*3 + 1 ],
  17495. ndz = normals[ nd*3 + 2 ];
  17496. scope.faces.push( new THREE.Face4( a, b, c, d,
  17497. [new THREE.Vector3( nax, nay, naz ),
  17498. new THREE.Vector3( nbx, nby, nbz ),
  17499. new THREE.Vector3( ncx, ncy, ncz ),
  17500. new THREE.Vector3( ndx, ndy, ndz )],
  17501. null,
  17502. mi ) );
  17503. };
  17504. function uv3 ( where, u1, v1, u2, v2, u3, v3 ) {
  17505. var uv = [];
  17506. uv.push( new THREE.UV( u1, v1 ) );
  17507. uv.push( new THREE.UV( u2, v2 ) );
  17508. uv.push( new THREE.UV( u3, v3 ) );
  17509. where.push( uv );
  17510. };
  17511. function uv4 ( where, u1, v1, u2, v2, u3, v3, u4, v4 ) {
  17512. var uv = [];
  17513. uv.push( new THREE.UV( u1, v1 ) );
  17514. uv.push( new THREE.UV( u2, v2 ) );
  17515. uv.push( new THREE.UV( u3, v3 ) );
  17516. uv.push( new THREE.UV( u4, v4 ) );
  17517. where.push( uv );
  17518. };
  17519. Model.prototype = new THREE.Geometry();
  17520. Model.prototype.constructor = Model;
  17521. callback( new Model( texturePath ) );
  17522. };
  17523. /**
  17524. * @author Tim Knip / http://www.floorplanner.com/ / tim at floorplanner.com
  17525. */
  17526. THREE.ColladaLoader = function () {
  17527. var COLLADA = null;
  17528. var scene = null;
  17529. var daeScene;
  17530. var readyCallbackFunc = null;
  17531. var sources = {};
  17532. var images = {};
  17533. var animations = {};
  17534. var controllers = {};
  17535. var geometries = {};
  17536. var materials = {};
  17537. var effects = {};
  17538. var cameras = {};
  17539. var animData;
  17540. var visualScenes;
  17541. var baseUrl;
  17542. var morphs;
  17543. var skins;
  17544. var flip_uv = true;
  17545. var preferredShading = THREE.SmoothShading;
  17546. var options = {
  17547. // Force Geometry to always be centered at the local origin of the
  17548. // containing Mesh.
  17549. centerGeometry: false,
  17550. // Axis conversion is done for geometries, animations, and controllers.
  17551. // If we ever pull cameras or lights out of the COLLADA file, they'll
  17552. // need extra work.
  17553. convertUpAxis: false,
  17554. subdivideFaces: true,
  17555. upAxis: 'Y'
  17556. };
  17557. // TODO: support unit conversion as well
  17558. var colladaUnit = 1.0;
  17559. var colladaUp = 'Y';
  17560. var upConversion = null;
  17561. var TO_RADIANS = Math.PI / 180;
  17562. function load ( url, readyCallback, progressCallback ) {
  17563. var length = 0;
  17564. if ( document.implementation && document.implementation.createDocument ) {
  17565. var req = new XMLHttpRequest();
  17566. if ( req.overrideMimeType ) req.overrideMimeType( "text/xml" );
  17567. req.onreadystatechange = function() {
  17568. if( req.readyState == 4 ) {
  17569. if( req.status == 0 || req.status == 200 ) {
  17570. if ( req.responseXML ) {
  17571. readyCallbackFunc = readyCallback;
  17572. parse( req.responseXML, undefined, url );
  17573. } else {
  17574. console.error( "ColladaLoader: Empty or non-existing file (" + url + ")" );
  17575. }
  17576. }
  17577. } else if ( req.readyState == 3 ) {
  17578. if ( progressCallback ) {
  17579. if ( length == 0 ) {
  17580. length = req.getResponseHeader( "Content-Length" );
  17581. }
  17582. progressCallback( { total: length, loaded: req.responseText.length } );
  17583. }
  17584. }
  17585. }
  17586. req.open( "GET", url, true );
  17587. req.send( null );
  17588. } else {
  17589. alert( "Don't know how to parse XML!" );
  17590. }
  17591. };
  17592. function parse( doc, callBack, url ) {
  17593. COLLADA = doc;
  17594. callBack = callBack || readyCallbackFunc;
  17595. if ( url !== undefined ) {
  17596. var parts = url.split( '/' );
  17597. parts.pop();
  17598. baseUrl = ( parts.length < 1 ? '.' : parts.join( '/' ) ) + '/';
  17599. }
  17600. parseAsset();
  17601. setUpConversion();
  17602. images = parseLib( "//dae:library_images/dae:image", _Image, "image" );
  17603. materials = parseLib( "//dae:library_materials/dae:material", Material, "material") ;
  17604. effects = parseLib( "//dae:library_effects/dae:effect", Effect, "effect" );
  17605. geometries = parseLib( "//dae:library_geometries/dae:geometry", Geometry, "geometry" );
  17606. cameras = parseLib( ".//dae:library_cameras/dae:camera", Camera, "camera" );
  17607. controllers = parseLib( "//dae:library_controllers/dae:controller", Controller, "controller" );
  17608. animations = parseLib( "//dae:library_animations/dae:animation", Animation, "animation" );
  17609. visualScenes = parseLib( ".//dae:library_visual_scenes/dae:visual_scene", VisualScene, "visual_scene" );
  17610. morphs = [];
  17611. skins = [];
  17612. daeScene = parseScene();
  17613. scene = new THREE.Object3D();
  17614. for ( var i = 0; i < daeScene.nodes.length; i ++ ) {
  17615. scene.add( createSceneGraph( daeScene.nodes[ i ] ) );
  17616. }
  17617. createAnimations();
  17618. var result = {
  17619. scene: scene,
  17620. morphs: morphs,
  17621. skins: skins,
  17622. animations: animData,
  17623. dae: {
  17624. images: images,
  17625. materials: materials,
  17626. cameras: cameras,
  17627. effects: effects,
  17628. geometries: geometries,
  17629. controllers: controllers,
  17630. animations: animations,
  17631. visualScenes: visualScenes,
  17632. scene: daeScene
  17633. }
  17634. };
  17635. if ( callBack ) {
  17636. callBack( result );
  17637. }
  17638. return result;
  17639. };
  17640. function setPreferredShading ( shading ) {
  17641. preferredShading = shading;
  17642. };
  17643. function parseAsset () {
  17644. var elements = COLLADA.evaluate( '//dae:asset', COLLADA, _nsResolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
  17645. var element = elements.iterateNext();
  17646. if ( element && element.childNodes ) {
  17647. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  17648. var child = element.childNodes[ i ];
  17649. switch ( child.nodeName ) {
  17650. case 'unit':
  17651. var meter = child.getAttribute( 'meter' );
  17652. if ( meter ) {
  17653. colladaUnit = parseFloat( meter );
  17654. }
  17655. break;
  17656. case 'up_axis':
  17657. colladaUp = child.textContent.charAt(0);
  17658. break;
  17659. }
  17660. }
  17661. }
  17662. };
  17663. function parseLib ( q, classSpec, prefix ) {
  17664. var elements = COLLADA.evaluate(q, COLLADA, _nsResolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null) ;
  17665. var lib = {};
  17666. var element = elements.iterateNext();
  17667. var i = 0;
  17668. while ( element ) {
  17669. var daeElement = ( new classSpec() ).parse( element );
  17670. if ( !daeElement.id || daeElement.id.length == 0 ) daeElement.id = prefix + ( i ++ );
  17671. lib[ daeElement.id ] = daeElement;
  17672. element = elements.iterateNext();
  17673. }
  17674. return lib;
  17675. };
  17676. function parseScene() {
  17677. var sceneElement = COLLADA.evaluate( './/dae:scene/dae:instance_visual_scene', COLLADA, _nsResolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ).iterateNext();
  17678. if ( sceneElement ) {
  17679. var url = sceneElement.getAttribute( 'url' ).replace( /^#/, '' );
  17680. return visualScenes[ url.length > 0 ? url : 'visual_scene0' ];
  17681. } else {
  17682. return null;
  17683. }
  17684. };
  17685. function createAnimations() {
  17686. animData = [];
  17687. // fill in the keys
  17688. recurseHierarchy( scene );
  17689. };
  17690. function recurseHierarchy( node ) {
  17691. var n = daeScene.getChildById( node.name, true ),
  17692. newData = null;
  17693. if ( n && n.keys ) {
  17694. newData = {
  17695. fps: 60,
  17696. hierarchy: [ {
  17697. node: n,
  17698. keys: n.keys,
  17699. sids: n.sids
  17700. } ],
  17701. node: node,
  17702. name: 'animation_' + node.name,
  17703. length: 0
  17704. };
  17705. animData.push(newData);
  17706. for ( var i = 0, il = n.keys.length; i < il; i++ ) {
  17707. newData.length = Math.max( newData.length, n.keys[i].time );
  17708. }
  17709. } else {
  17710. newData = {
  17711. hierarchy: [ {
  17712. keys: [],
  17713. sids: []
  17714. } ]
  17715. }
  17716. }
  17717. for ( var i = 0, il = node.children.length; i < il; i++ ) {
  17718. var d = recurseHierarchy( node.children[i] );
  17719. for ( var j = 0, jl = d.hierarchy.length; j < jl; j ++ ) {
  17720. newData.hierarchy.push( {
  17721. keys: [],
  17722. sids: []
  17723. } );
  17724. }
  17725. }
  17726. return newData;
  17727. };
  17728. function calcAnimationBounds () {
  17729. var start = 1000000;
  17730. var end = -start;
  17731. var frames = 0;
  17732. for ( var id in animations ) {
  17733. var animation = animations[ id ];
  17734. for ( var i = 0; i < animation.sampler.length; i ++ ) {
  17735. var sampler = animation.sampler[ i ];
  17736. sampler.create();
  17737. start = Math.min( start, sampler.startTime );
  17738. end = Math.max( end, sampler.endTime );
  17739. frames = Math.max( frames, sampler.input.length );
  17740. }
  17741. }
  17742. return { start:start, end:end, frames:frames };
  17743. };
  17744. function createMorph ( geometry, ctrl ) {
  17745. var morphCtrl = ctrl instanceof InstanceController ? controllers[ ctrl.url ] : ctrl;
  17746. if ( !morphCtrl || !morphCtrl.morph ) {
  17747. console.log("could not find morph controller!");
  17748. return;
  17749. }
  17750. var morph = morphCtrl.morph;
  17751. for ( var i = 0; i < morph.targets.length; i ++ ) {
  17752. var target_id = morph.targets[ i ];
  17753. var daeGeometry = geometries[ target_id ];
  17754. if ( !daeGeometry.mesh ||
  17755. !daeGeometry.mesh.primitives ||
  17756. !daeGeometry.mesh.primitives.length ) {
  17757. continue;
  17758. }
  17759. var target = daeGeometry.mesh.primitives[ 0 ].geometry;
  17760. if ( target.vertices.length === geometry.vertices.length ) {
  17761. geometry.morphTargets.push( { name: "target_1", vertices: target.vertices } );
  17762. }
  17763. }
  17764. geometry.morphTargets.push( { name: "target_Z", vertices: geometry.vertices } );
  17765. };
  17766. function createSkin ( geometry, ctrl, applyBindShape ) {
  17767. var skinCtrl = controllers[ ctrl.url ];
  17768. if ( !skinCtrl || !skinCtrl.skin ) {
  17769. console.log( "could not find skin controller!" );
  17770. return;
  17771. }
  17772. if ( !ctrl.skeleton || !ctrl.skeleton.length ) {
  17773. console.log( "could not find the skeleton for the skin!" );
  17774. return;
  17775. }
  17776. var skin = skinCtrl.skin;
  17777. var skeleton = daeScene.getChildById( ctrl.skeleton[ 0 ] );
  17778. var hierarchy = [];
  17779. applyBindShape = applyBindShape !== undefined ? applyBindShape : true;
  17780. var bones = [];
  17781. geometry.skinWeights = [];
  17782. geometry.skinIndices = [];
  17783. //createBones( geometry.bones, skin, hierarchy, skeleton, null, -1 );
  17784. //createWeights( skin, geometry.bones, geometry.skinIndices, geometry.skinWeights );
  17785. /*
  17786. geometry.animation = {
  17787. name: 'take_001',
  17788. fps: 30,
  17789. length: 2,
  17790. JIT: true,
  17791. hierarchy: hierarchy
  17792. };
  17793. */
  17794. if ( applyBindShape ) {
  17795. for ( var i = 0; i < geometry.vertices.length; i ++ ) {
  17796. skin.bindShapeMatrix.multiplyVector3( geometry.vertices[ i ] );
  17797. }
  17798. }
  17799. };
  17800. function setupSkeleton ( node, bones, frame, parent ) {
  17801. node.world = node.world || new THREE.Matrix4();
  17802. node.world.copy( node.matrix );
  17803. if ( node.channels && node.channels.length ) {
  17804. var channel = node.channels[ 0 ];
  17805. var m = channel.sampler.output[ frame ];
  17806. if ( m instanceof THREE.Matrix4 ) {
  17807. node.world.copy( m );
  17808. }
  17809. }
  17810. if ( parent ) {
  17811. node.world.multiply( parent, node.world );
  17812. }
  17813. bones.push( node );
  17814. for ( var i = 0; i < node.nodes.length; i ++ ) {
  17815. setupSkeleton( node.nodes[ i ], bones, frame, node.world );
  17816. }
  17817. };
  17818. function setupSkinningMatrices ( bones, skin ) {
  17819. // FIXME: this is dumb...
  17820. for ( var i = 0; i < bones.length; i ++ ) {
  17821. var bone = bones[ i ];
  17822. var found = -1;
  17823. if ( bone.type != 'JOINT' ) continue;
  17824. for ( var j = 0; j < skin.joints.length; j ++ ) {
  17825. if ( bone.sid == skin.joints[ j ] ) {
  17826. found = j;
  17827. break;
  17828. }
  17829. }
  17830. if ( found >= 0 ) {
  17831. var inv = skin.invBindMatrices[ found ];
  17832. bone.invBindMatrix = inv;
  17833. bone.skinningMatrix = new THREE.Matrix4();
  17834. bone.skinningMatrix.multiply(bone.world, inv); // (IBMi * JMi)
  17835. bone.weights = [];
  17836. for ( var j = 0; j < skin.weights.length; j ++ ) {
  17837. for (var k = 0; k < skin.weights[ j ].length; k ++) {
  17838. var w = skin.weights[ j ][ k ];
  17839. if ( w.joint == found ) {
  17840. bone.weights.push( w );
  17841. }
  17842. }
  17843. }
  17844. } else {
  17845. throw 'ColladaLoader: Could not find joint \'' + bone.sid + '\'.';
  17846. }
  17847. }
  17848. };
  17849. function applySkin ( geometry, instanceCtrl, frame ) {
  17850. var skinController = controllers[ instanceCtrl.url ];
  17851. frame = frame !== undefined ? frame : 40;
  17852. if ( !skinController || !skinController.skin ) {
  17853. console.log( 'ColladaLoader: Could not find skin controller.' );
  17854. return;
  17855. }
  17856. if ( !instanceCtrl.skeleton || !instanceCtrl.skeleton.length ) {
  17857. console.log( 'ColladaLoader: Could not find the skeleton for the skin. ' );
  17858. return;
  17859. }
  17860. var animationBounds = calcAnimationBounds();
  17861. var skeleton = daeScene.getChildById( instanceCtrl.skeleton[0], true ) ||
  17862. daeScene.getChildBySid( instanceCtrl.skeleton[0], true );
  17863. var i, j, w, vidx, weight;
  17864. var v = new THREE.Vector3(), o, s;
  17865. // move vertices to bind shape
  17866. for ( i = 0; i < geometry.vertices.length; i ++ ) {
  17867. skinController.skin.bindShapeMatrix.multiplyVector3( geometry.vertices[i] );
  17868. }
  17869. // process animation, or simply pose the rig if no animation
  17870. for ( frame = 0; frame < animationBounds.frames; frame ++ ) {
  17871. var bones = [];
  17872. var skinned = [];
  17873. // zero skinned vertices
  17874. for ( i = 0; i < geometry.vertices.length; i++ ) {
  17875. skinned.push( new THREE.Vector3() );
  17876. }
  17877. // process the frame and setup the rig with a fresh
  17878. // transform, possibly from the bone's animation channel(s)
  17879. setupSkeleton( skeleton, bones, frame );
  17880. setupSkinningMatrices( bones, skinController.skin );
  17881. // skin 'm
  17882. for ( i = 0; i < bones.length; i ++ ) {
  17883. if ( bones[ i ].type != 'JOINT' ) continue;
  17884. for ( j = 0; j < bones[ i ].weights.length; j ++ ) {
  17885. w = bones[ i ].weights[ j ];
  17886. vidx = w.index;
  17887. weight = w.weight;
  17888. o = geometry.vertices[vidx];
  17889. s = skinned[vidx];
  17890. v.x = o.x;
  17891. v.y = o.y;
  17892. v.z = o.z;
  17893. bones[i].skinningMatrix.multiplyVector3(v);
  17894. s.x += (v.x * weight);
  17895. s.y += (v.y * weight);
  17896. s.z += (v.z * weight);
  17897. }
  17898. }
  17899. geometry.morphTargets.push( { name: "target_" + frame, vertices: skinned } );
  17900. }
  17901. };
  17902. function createSceneGraph ( node, parent ) {
  17903. var obj = new THREE.Object3D();
  17904. var skinned = false;
  17905. var skinController;
  17906. var morphController;
  17907. var i, j;
  17908. // FIXME: controllers
  17909. for ( i = 0; i < node.controllers.length; i ++ ) {
  17910. var controller = controllers[ node.controllers[ i ].url ];
  17911. switch ( controller.type ) {
  17912. case 'skin':
  17913. if ( geometries[ controller.skin.source ] ) {
  17914. var inst_geom = new InstanceGeometry();
  17915. inst_geom.url = controller.skin.source;
  17916. inst_geom.instance_material = node.controllers[ i ].instance_material;
  17917. node.geometries.push( inst_geom );
  17918. skinned = true;
  17919. skinController = node.controllers[ i ];
  17920. } else if ( controllers[ controller.skin.source ] ) {
  17921. // urgh: controller can be chained
  17922. // handle the most basic case...
  17923. var second = controllers[ controller.skin.source ];
  17924. morphController = second;
  17925. // skinController = node.controllers[i];
  17926. if ( second.morph && geometries[ second.morph.source ] ) {
  17927. var inst_geom = new InstanceGeometry();
  17928. inst_geom.url = second.morph.source;
  17929. inst_geom.instance_material = node.controllers[ i ].instance_material;
  17930. node.geometries.push( inst_geom );
  17931. }
  17932. }
  17933. break;
  17934. case 'morph':
  17935. if ( geometries[ controller.morph.source ] ) {
  17936. var inst_geom = new InstanceGeometry();
  17937. inst_geom.url = controller.morph.source;
  17938. inst_geom.instance_material = node.controllers[ i ].instance_material;
  17939. node.geometries.push( inst_geom );
  17940. morphController = node.controllers[ i ];
  17941. }
  17942. console.log( 'ColladaLoader: Morph-controller partially supported.' );
  17943. default:
  17944. break;
  17945. }
  17946. }
  17947. // FIXME: multi-material mesh?
  17948. // geometries
  17949. for ( i = 0; i < node.geometries.length; i ++ ) {
  17950. var instance_geometry = node.geometries[i];
  17951. var instance_materials = instance_geometry.instance_material;
  17952. var geometry = geometries[instance_geometry.url];
  17953. var used_materials = {};
  17954. var used_materials_array = [];
  17955. var num_materials = 0;
  17956. var first_material;
  17957. if ( geometry ) {
  17958. if ( !geometry.mesh || !geometry.mesh.primitives )
  17959. continue;
  17960. if ( obj.name.length == 0 ) {
  17961. obj.name = geometry.id;
  17962. }
  17963. // collect used fx for this geometry-instance
  17964. if ( instance_materials ) {
  17965. for ( j = 0; j < instance_materials.length; j ++ ) {
  17966. var instance_material = instance_materials[ j ];
  17967. var mat = materials[ instance_material.target ];
  17968. var effect_id = mat.instance_effect.url;
  17969. var shader = effects[ effect_id ].shader;
  17970. shader.material.opacity = !shader.material.opacity ? 1 : shader.material.opacity;
  17971. used_materials[ instance_material.symbol ] = num_materials;
  17972. used_materials_array.push( shader.material )
  17973. first_material = shader.material;
  17974. first_material.name = mat.name == null || mat.name === '' ? mat.id : mat.name;
  17975. num_materials ++;
  17976. }
  17977. }
  17978. var mesh;
  17979. var material = first_material || new THREE.MeshLambertMaterial( { color: 0xdddddd, shading: THREE.FlatShading } );
  17980. var geom = geometry.mesh.geometry3js;
  17981. if ( num_materials > 1 ) {
  17982. material = new THREE.MeshFaceMaterial();
  17983. geom.materials = used_materials_array;
  17984. for ( j = 0; j < geom.faces.length; j ++ ) {
  17985. var face = geom.faces[ j ];
  17986. face.materialIndex = used_materials[ face.daeMaterial ]
  17987. }
  17988. }
  17989. if ( skinController !== undefined) {
  17990. applySkin( geom, skinController );
  17991. material.morphTargets = true;
  17992. mesh = new THREE.SkinnedMesh( geom, material );
  17993. mesh.skeleton = skinController.skeleton;
  17994. mesh.skinController = controllers[ skinController.url ];
  17995. mesh.skinInstanceController = skinController;
  17996. mesh.name = 'skin_' + skins.length;
  17997. skins.push( mesh );
  17998. } else if ( morphController !== undefined ) {
  17999. createMorph( geom, morphController );
  18000. material.morphTargets = true;
  18001. mesh = new THREE.Mesh( geom, material );
  18002. mesh.name = 'morph_' + morphs.length;
  18003. morphs.push( mesh );
  18004. } else {
  18005. mesh = new THREE.Mesh( geom, material );
  18006. // mesh.geom.name = geometry.id;
  18007. }
  18008. node.geometries.length > 1 ? obj.add( mesh ) : obj = mesh;
  18009. }
  18010. }
  18011. for ( i = 0; i < node.cameras.length; i ++ ) {
  18012. var instance_camera = node.cameras[i];
  18013. var cparams = cameras[instance_camera.url];
  18014. obj = new THREE.PerspectiveCamera(cparams.fov, cparams.aspect_ratio, cparams.znear, cparams.zfar);
  18015. }
  18016. obj.name = node.id || "";
  18017. obj.matrix = node.matrix;
  18018. var props = node.matrix.decompose();
  18019. obj.position = props[ 0 ];
  18020. obj.quaternion = props[ 1 ];
  18021. obj.useQuaternion = true;
  18022. obj.scale = props[ 2 ];
  18023. if ( options.centerGeometry && obj.geometry ) {
  18024. var delta = THREE.GeometryUtils.center( obj.geometry );
  18025. obj.quaternion.multiplyVector3( delta.multiplySelf( obj.scale ) );
  18026. obj.position.subSelf( delta );
  18027. }
  18028. for ( i = 0; i < node.nodes.length; i ++ ) {
  18029. obj.add( createSceneGraph( node.nodes[i], node ) );
  18030. }
  18031. return obj;
  18032. };
  18033. function getJointId( skin, id ) {
  18034. for ( var i = 0; i < skin.joints.length; i ++ ) {
  18035. if ( skin.joints[ i ] == id ) {
  18036. return i;
  18037. }
  18038. }
  18039. };
  18040. function getLibraryNode( id ) {
  18041. return COLLADA.evaluate( './/dae:library_nodes//dae:node[@id=\'' + id + '\']', COLLADA, _nsResolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ).iterateNext();
  18042. };
  18043. function getChannelsForNode (node ) {
  18044. var channels = [];
  18045. var startTime = 1000000;
  18046. var endTime = -1000000;
  18047. for ( var id in animations ) {
  18048. var animation = animations[id];
  18049. for ( var i = 0; i < animation.channel.length; i ++ ) {
  18050. var channel = animation.channel[i];
  18051. var sampler = animation.sampler[i];
  18052. var id = channel.target.split('/')[0];
  18053. if ( id == node.id ) {
  18054. sampler.create();
  18055. channel.sampler = sampler;
  18056. startTime = Math.min(startTime, sampler.startTime);
  18057. endTime = Math.max(endTime, sampler.endTime);
  18058. channels.push(channel);
  18059. }
  18060. }
  18061. }
  18062. if ( channels.length ) {
  18063. node.startTime = startTime;
  18064. node.endTime = endTime;
  18065. }
  18066. return channels;
  18067. };
  18068. function calcFrameDuration( node ) {
  18069. var minT = 10000000;
  18070. for ( var i = 0; i < node.channels.length; i ++ ) {
  18071. var sampler = node.channels[i].sampler;
  18072. for ( var j = 0; j < sampler.input.length - 1; j ++ ) {
  18073. var t0 = sampler.input[ j ];
  18074. var t1 = sampler.input[ j + 1 ];
  18075. minT = Math.min( minT, t1 - t0 );
  18076. }
  18077. }
  18078. return minT;
  18079. };
  18080. function calcMatrixAt( node, t ) {
  18081. var animated = {};
  18082. var i, j;
  18083. for ( i = 0; i < node.channels.length; i ++ ) {
  18084. var channel = node.channels[ i ];
  18085. animated[ channel.sid ] = channel;
  18086. }
  18087. var matrix = new THREE.Matrix4();
  18088. for ( i = 0; i < node.transforms.length; i ++ ) {
  18089. var transform = node.transforms[ i ];
  18090. var channel = animated[ transform.sid ];
  18091. if ( channel !== undefined ) {
  18092. var sampler = channel.sampler;
  18093. var value;
  18094. for ( j = 0; j < sampler.input.length - 1; j ++ ) {
  18095. if ( sampler.input[ j + 1 ] > t ) {
  18096. value = sampler.output[ j ];
  18097. //console.log(value.flatten)
  18098. break;
  18099. }
  18100. }
  18101. if ( value !== undefined ) {
  18102. if ( value instanceof THREE.Matrix4 ) {
  18103. matrix = matrix.multiply( matrix, value );
  18104. } else {
  18105. // FIXME: handle other types
  18106. matrix = matrix.multiply( matrix, transform.matrix );
  18107. }
  18108. } else {
  18109. matrix = matrix.multiply( matrix, transform.matrix );
  18110. }
  18111. } else {
  18112. matrix = matrix.multiply( matrix, transform.matrix );
  18113. }
  18114. }
  18115. return matrix;
  18116. };
  18117. function bakeAnimations ( node ) {
  18118. if ( node.channels && node.channels.length ) {
  18119. var keys = [],
  18120. sids = [];
  18121. for ( var i = 0, il = node.channels.length; i < il; i++ ) {
  18122. var channel = node.channels[i],
  18123. fullSid = channel.fullSid,
  18124. sampler = channel.sampler,
  18125. input = sampler.input,
  18126. transform = node.getTransformBySid( channel.sid ),
  18127. member;
  18128. if ( channel.arrIndices ) {
  18129. member = [];
  18130. for ( var j = 0, jl = channel.arrIndices.length; j < jl; j++ ) {
  18131. member[ j ] = getConvertedIndex( channel.arrIndices[ j ] );
  18132. }
  18133. } else {
  18134. member = getConvertedMember( channel.member );
  18135. }
  18136. if ( transform ) {
  18137. if ( sids.indexOf( fullSid ) === -1 ) {
  18138. sids.push( fullSid );
  18139. }
  18140. for ( var j = 0, jl = input.length; j < jl; j++ ) {
  18141. var time = input[j],
  18142. data = sampler.getData( transform.type, j ),
  18143. key = findKey( keys, time );
  18144. if ( !key ) {
  18145. key = new Key( time );
  18146. var timeNdx = findTimeNdx( keys, time );
  18147. keys.splice( timeNdx == -1 ? keys.length : timeNdx, 0, key );
  18148. }
  18149. key.addTarget( fullSid, transform, member, data );
  18150. }
  18151. } else {
  18152. console.log( 'Could not find transform "' + channel.sid + '" in node ' + node.id );
  18153. }
  18154. }
  18155. // post process
  18156. for ( var i = 0; i < sids.length; i++ ) {
  18157. var sid = sids[ i ];
  18158. for ( var j = 0; j < keys.length; j++ ) {
  18159. var key = keys[ j ];
  18160. if ( !key.hasTarget( sid ) ) {
  18161. interpolateKeys( keys, key, j, sid );
  18162. }
  18163. }
  18164. }
  18165. node.keys = keys;
  18166. node.sids = sids;
  18167. }
  18168. };
  18169. function findKey ( keys, time) {
  18170. var retVal = null;
  18171. for ( var i = 0, il = keys.length; i < il && retVal == null; i++ ) {
  18172. var key = keys[i];
  18173. if ( key.time === time ) {
  18174. retVal = key;
  18175. } else if ( key.time > time ) {
  18176. break;
  18177. }
  18178. }
  18179. return retVal;
  18180. };
  18181. function findTimeNdx ( keys, time) {
  18182. var ndx = -1;
  18183. for ( var i = 0, il = keys.length; i < il && ndx == -1; i++ ) {
  18184. var key = keys[i];
  18185. if ( key.time >= time ) {
  18186. ndx = i;
  18187. }
  18188. }
  18189. return ndx;
  18190. };
  18191. function interpolateKeys ( keys, key, ndx, fullSid ) {
  18192. var prevKey = getPrevKeyWith( keys, fullSid, ndx ? ndx-1 : 0 ),
  18193. nextKey = getNextKeyWith( keys, fullSid, ndx+1 );
  18194. if ( prevKey && nextKey ) {
  18195. var scale = (key.time - prevKey.time) / (nextKey.time - prevKey.time),
  18196. prevTarget = prevKey.getTarget( fullSid ),
  18197. nextData = nextKey.getTarget( fullSid ).data,
  18198. prevData = prevTarget.data,
  18199. data;
  18200. if ( prevTarget.type === 'matrix' ) {
  18201. data = prevData;
  18202. } else if ( prevData.length ) {
  18203. data = [];
  18204. for ( var i = 0; i < prevData.length; ++i ) {
  18205. data[ i ] = prevData[ i ] + ( nextData[ i ] - prevData[ i ] ) * scale;
  18206. }
  18207. } else {
  18208. data = prevData + ( nextData - prevData ) * scale;
  18209. }
  18210. key.addTarget( fullSid, prevTarget.transform, prevTarget.member, data );
  18211. }
  18212. };
  18213. // Get next key with given sid
  18214. function getNextKeyWith( keys, fullSid, ndx ) {
  18215. for ( ; ndx < keys.length; ndx++ ) {
  18216. var key = keys[ ndx ];
  18217. if ( key.hasTarget( fullSid ) ) {
  18218. return key;
  18219. }
  18220. }
  18221. return null;
  18222. };
  18223. // Get previous key with given sid
  18224. function getPrevKeyWith( keys, fullSid, ndx ) {
  18225. ndx = ndx >= 0 ? ndx : ndx + keys.length;
  18226. for ( ; ndx >= 0; ndx-- ) {
  18227. var key = keys[ ndx ];
  18228. if ( key.hasTarget( fullSid ) ) {
  18229. return key;
  18230. }
  18231. }
  18232. return null;
  18233. };
  18234. function _Image() {
  18235. this.id = "";
  18236. this.init_from = "";
  18237. };
  18238. _Image.prototype.parse = function(element) {
  18239. this.id = element.getAttribute('id');
  18240. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  18241. var child = element.childNodes[ i ];
  18242. if ( child.nodeName == 'init_from' ) {
  18243. this.init_from = child.textContent;
  18244. }
  18245. }
  18246. return this;
  18247. };
  18248. function Controller() {
  18249. this.id = "";
  18250. this.name = "";
  18251. this.type = "";
  18252. this.skin = null;
  18253. this.morph = null;
  18254. };
  18255. Controller.prototype.parse = function( element ) {
  18256. this.id = element.getAttribute('id');
  18257. this.name = element.getAttribute('name');
  18258. this.type = "none";
  18259. for ( var i = 0; i < element.childNodes.length; i++ ) {
  18260. var child = element.childNodes[ i ];
  18261. switch ( child.nodeName ) {
  18262. case 'skin':
  18263. this.skin = (new Skin()).parse(child);
  18264. this.type = child.nodeName;
  18265. break;
  18266. case 'morph':
  18267. this.morph = (new Morph()).parse(child);
  18268. this.type = child.nodeName;
  18269. break;
  18270. default:
  18271. break;
  18272. }
  18273. }
  18274. return this;
  18275. };
  18276. function Morph() {
  18277. this.method = null;
  18278. this.source = null;
  18279. this.targets = null;
  18280. this.weights = null;
  18281. };
  18282. Morph.prototype.parse = function( element ) {
  18283. var sources = {};
  18284. var inputs = [];
  18285. var i;
  18286. this.method = element.getAttribute( 'method' );
  18287. this.source = element.getAttribute( 'source' ).replace( /^#/, '' );
  18288. for ( i = 0; i < element.childNodes.length; i ++ ) {
  18289. var child = element.childNodes[ i ];
  18290. if ( child.nodeType != 1 ) continue;
  18291. switch ( child.nodeName ) {
  18292. case 'source':
  18293. var source = ( new Source() ).parse( child );
  18294. sources[ source.id ] = source;
  18295. break;
  18296. case 'targets':
  18297. inputs = this.parseInputs( child );
  18298. break;
  18299. default:
  18300. console.log( child.nodeName );
  18301. break;
  18302. }
  18303. }
  18304. for ( i = 0; i < inputs.length; i ++ ) {
  18305. var input = inputs[ i ];
  18306. var source = sources[ input.source ];
  18307. switch ( input.semantic ) {
  18308. case 'MORPH_TARGET':
  18309. this.targets = source.read();
  18310. break;
  18311. case 'MORPH_WEIGHT':
  18312. this.weights = source.read();
  18313. break;
  18314. default:
  18315. break;
  18316. }
  18317. }
  18318. return this;
  18319. };
  18320. Morph.prototype.parseInputs = function(element) {
  18321. var inputs = [];
  18322. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  18323. var child = element.childNodes[i];
  18324. if ( child.nodeType != 1) continue;
  18325. switch ( child.nodeName ) {
  18326. case 'input':
  18327. inputs.push( (new Input()).parse(child) );
  18328. break;
  18329. default:
  18330. break;
  18331. }
  18332. }
  18333. return inputs;
  18334. };
  18335. function Skin() {
  18336. this.source = "";
  18337. this.bindShapeMatrix = null;
  18338. this.invBindMatrices = [];
  18339. this.joints = [];
  18340. this.weights = [];
  18341. };
  18342. Skin.prototype.parse = function( element ) {
  18343. var sources = {};
  18344. var joints, weights;
  18345. this.source = element.getAttribute( 'source' ).replace( /^#/, '' );
  18346. this.invBindMatrices = [];
  18347. this.joints = [];
  18348. this.weights = [];
  18349. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  18350. var child = element.childNodes[i];
  18351. if ( child.nodeType != 1 ) continue;
  18352. switch ( child.nodeName ) {
  18353. case 'bind_shape_matrix':
  18354. var f = _floats(child.textContent);
  18355. this.bindShapeMatrix = getConvertedMat4( f );
  18356. break;
  18357. case 'source':
  18358. var src = new Source().parse(child);
  18359. sources[ src.id ] = src;
  18360. break;
  18361. case 'joints':
  18362. joints = child;
  18363. break;
  18364. case 'vertex_weights':
  18365. weights = child;
  18366. break;
  18367. default:
  18368. console.log( child.nodeName );
  18369. break;
  18370. }
  18371. }
  18372. this.parseJoints( joints, sources );
  18373. this.parseWeights( weights, sources );
  18374. return this;
  18375. };
  18376. Skin.prototype.parseJoints = function ( element, sources ) {
  18377. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  18378. var child = element.childNodes[ i ];
  18379. if ( child.nodeType != 1 ) continue;
  18380. switch ( child.nodeName ) {
  18381. case 'input':
  18382. var input = ( new Input() ).parse( child );
  18383. var source = sources[ input.source ];
  18384. if ( input.semantic == 'JOINT' ) {
  18385. this.joints = source.read();
  18386. } else if ( input.semantic == 'INV_BIND_MATRIX' ) {
  18387. this.invBindMatrices = source.read();
  18388. }
  18389. break;
  18390. default:
  18391. break;
  18392. }
  18393. }
  18394. };
  18395. Skin.prototype.parseWeights = function ( element, sources ) {
  18396. var v, vcount, inputs = [];
  18397. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  18398. var child = element.childNodes[ i ];
  18399. if ( child.nodeType != 1 ) continue;
  18400. switch ( child.nodeName ) {
  18401. case 'input':
  18402. inputs.push( ( new Input() ).parse( child ) );
  18403. break;
  18404. case 'v':
  18405. v = _ints( child.textContent );
  18406. break;
  18407. case 'vcount':
  18408. vcount = _ints( child.textContent );
  18409. break;
  18410. default:
  18411. break;
  18412. }
  18413. }
  18414. var index = 0;
  18415. for ( var i = 0; i < vcount.length; i ++ ) {
  18416. var numBones = vcount[i];
  18417. var vertex_weights = [];
  18418. for ( var j = 0; j < numBones; j++ ) {
  18419. var influence = {};
  18420. for ( var k = 0; k < inputs.length; k ++ ) {
  18421. var input = inputs[ k ];
  18422. var value = v[ index + input.offset ];
  18423. switch ( input.semantic ) {
  18424. case 'JOINT':
  18425. influence.joint = value;//this.joints[value];
  18426. break;
  18427. case 'WEIGHT':
  18428. influence.weight = sources[ input.source ].data[ value ];
  18429. break;
  18430. default:
  18431. break;
  18432. }
  18433. }
  18434. vertex_weights.push( influence );
  18435. index += inputs.length;
  18436. }
  18437. for ( var j = 0; j < vertex_weights.length; j ++ ) {
  18438. vertex_weights[ j ].index = i;
  18439. }
  18440. this.weights.push( vertex_weights );
  18441. }
  18442. };
  18443. function VisualScene () {
  18444. this.id = "";
  18445. this.name = "";
  18446. this.nodes = [];
  18447. this.scene = new THREE.Object3D();
  18448. };
  18449. VisualScene.prototype.getChildById = function( id, recursive ) {
  18450. for ( var i = 0; i < this.nodes.length; i ++ ) {
  18451. var node = this.nodes[ i ].getChildById( id, recursive );
  18452. if ( node ) {
  18453. return node;
  18454. }
  18455. }
  18456. return null;
  18457. };
  18458. VisualScene.prototype.getChildBySid = function( sid, recursive ) {
  18459. for ( var i = 0; i < this.nodes.length; i ++ ) {
  18460. var node = this.nodes[ i ].getChildBySid( sid, recursive );
  18461. if ( node ) {
  18462. return node;
  18463. }
  18464. }
  18465. return null;
  18466. };
  18467. VisualScene.prototype.parse = function( element ) {
  18468. this.id = element.getAttribute( 'id' );
  18469. this.name = element.getAttribute( 'name' );
  18470. this.nodes = [];
  18471. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  18472. var child = element.childNodes[ i ];
  18473. if ( child.nodeType != 1 ) continue;
  18474. switch ( child.nodeName ) {
  18475. case 'node':
  18476. this.nodes.push( ( new Node() ).parse( child ) );
  18477. break;
  18478. default:
  18479. break;
  18480. }
  18481. }
  18482. return this;
  18483. };
  18484. function Node() {
  18485. this.id = "";
  18486. this.name = "";
  18487. this.sid = "";
  18488. this.nodes = [];
  18489. this.controllers = [];
  18490. this.transforms = [];
  18491. this.geometries = [];
  18492. this.channels = [];
  18493. this.matrix = new THREE.Matrix4();
  18494. };
  18495. Node.prototype.getChannelForTransform = function( transformSid ) {
  18496. for ( var i = 0; i < this.channels.length; i ++ ) {
  18497. var channel = this.channels[i];
  18498. var parts = channel.target.split('/');
  18499. var id = parts.shift();
  18500. var sid = parts.shift();
  18501. var dotSyntax = (sid.indexOf(".") >= 0);
  18502. var arrSyntax = (sid.indexOf("(") >= 0);
  18503. var arrIndices;
  18504. var member;
  18505. if ( dotSyntax ) {
  18506. parts = sid.split(".");
  18507. sid = parts.shift();
  18508. member = parts.shift();
  18509. } else if ( arrSyntax ) {
  18510. arrIndices = sid.split("(");
  18511. sid = arrIndices.shift();
  18512. for ( var j = 0; j < arrIndices.length; j ++ ) {
  18513. arrIndices[ j ] = parseInt( arrIndices[ j ].replace( /\)/, '' ) );
  18514. }
  18515. }
  18516. if ( sid == transformSid ) {
  18517. channel.info = { sid: sid, dotSyntax: dotSyntax, arrSyntax: arrSyntax, arrIndices: arrIndices };
  18518. return channel;
  18519. }
  18520. }
  18521. return null;
  18522. };
  18523. Node.prototype.getChildById = function ( id, recursive ) {
  18524. if ( this.id == id ) {
  18525. return this;
  18526. }
  18527. if ( recursive ) {
  18528. for ( var i = 0; i < this.nodes.length; i ++ ) {
  18529. var n = this.nodes[ i ].getChildById( id, recursive );
  18530. if ( n ) {
  18531. return n;
  18532. }
  18533. }
  18534. }
  18535. return null;
  18536. };
  18537. Node.prototype.getChildBySid = function ( sid, recursive ) {
  18538. if ( this.sid == sid ) {
  18539. return this;
  18540. }
  18541. if ( recursive ) {
  18542. for ( var i = 0; i < this.nodes.length; i ++ ) {
  18543. var n = this.nodes[ i ].getChildBySid( sid, recursive );
  18544. if ( n ) {
  18545. return n;
  18546. }
  18547. }
  18548. }
  18549. return null;
  18550. };
  18551. Node.prototype.getTransformBySid = function ( sid ) {
  18552. for ( var i = 0; i < this.transforms.length; i ++ ) {
  18553. if ( this.transforms[ i ].sid == sid ) return this.transforms[ i ];
  18554. }
  18555. return null;
  18556. };
  18557. Node.prototype.parse = function( element ) {
  18558. var url;
  18559. this.id = element.getAttribute('id');
  18560. this.sid = element.getAttribute('sid');
  18561. this.name = element.getAttribute('name');
  18562. this.type = element.getAttribute('type');
  18563. this.type = this.type == 'JOINT' ? this.type : 'NODE';
  18564. this.nodes = [];
  18565. this.transforms = [];
  18566. this.geometries = [];
  18567. this.cameras = [];
  18568. this.controllers = [];
  18569. this.matrix = new THREE.Matrix4();
  18570. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  18571. var child = element.childNodes[ i ];
  18572. if ( child.nodeType != 1 ) continue;
  18573. switch ( child.nodeName ) {
  18574. case 'node':
  18575. this.nodes.push( ( new Node() ).parse( child ) );
  18576. break;
  18577. case 'instance_camera':
  18578. this.cameras.push( ( new InstanceCamera() ).parse( child ) );
  18579. break;
  18580. case 'instance_controller':
  18581. this.controllers.push( ( new InstanceController() ).parse( child ) );
  18582. break;
  18583. case 'instance_geometry':
  18584. this.geometries.push( ( new InstanceGeometry() ).parse( child ) );
  18585. break;
  18586. case 'instance_light':
  18587. break;
  18588. case 'instance_node':
  18589. url = child.getAttribute( 'url' ).replace( /^#/, '' );
  18590. var iNode = getLibraryNode( url );
  18591. if ( iNode ) {
  18592. this.nodes.push( ( new Node() ).parse( iNode )) ;
  18593. }
  18594. break;
  18595. case 'rotate':
  18596. case 'translate':
  18597. case 'scale':
  18598. case 'matrix':
  18599. case 'lookat':
  18600. case 'skew':
  18601. this.transforms.push( ( new Transform() ).parse( child ) );
  18602. break;
  18603. case 'extra':
  18604. break;
  18605. default:
  18606. console.log( child.nodeName );
  18607. break;
  18608. }
  18609. }
  18610. this.channels = getChannelsForNode( this );
  18611. bakeAnimations( this );
  18612. this.updateMatrix();
  18613. return this;
  18614. };
  18615. Node.prototype.updateMatrix = function () {
  18616. this.matrix.identity();
  18617. for ( var i = 0; i < this.transforms.length; i ++ ) {
  18618. this.transforms[ i ].apply( this.matrix );
  18619. }
  18620. };
  18621. function Transform () {
  18622. this.sid = "";
  18623. this.type = "";
  18624. this.data = [];
  18625. this.obj = null;
  18626. };
  18627. Transform.prototype.parse = function ( element ) {
  18628. this.sid = element.getAttribute( 'sid' );
  18629. this.type = element.nodeName;
  18630. this.data = _floats( element.textContent );
  18631. this.convert();
  18632. return this;
  18633. };
  18634. Transform.prototype.convert = function () {
  18635. switch ( this.type ) {
  18636. case 'matrix':
  18637. this.obj = getConvertedMat4( this.data );
  18638. break;
  18639. case 'rotate':
  18640. this.angle = this.data[3] * TO_RADIANS;
  18641. case 'translate':
  18642. fixCoords( this.data, -1 );
  18643. this.obj = new THREE.Vector3( this.data[ 0 ], this.data[ 1 ], this.data[ 2 ] );
  18644. break;
  18645. case 'scale':
  18646. fixCoords( this.data, 1 );
  18647. this.obj = new THREE.Vector3( this.data[ 0 ], this.data[ 1 ], this.data[ 2 ] );
  18648. break;
  18649. default:
  18650. console.log( 'Can not convert Transform of type ' + this.type );
  18651. break;
  18652. }
  18653. };
  18654. Transform.prototype.apply = function ( matrix ) {
  18655. switch ( this.type ) {
  18656. case 'matrix':
  18657. matrix.multiplySelf( this.obj );
  18658. break;
  18659. case 'translate':
  18660. matrix.translate( this.obj );
  18661. break;
  18662. case 'rotate':
  18663. matrix.rotateByAxis( this.obj, this.angle );
  18664. break;
  18665. case 'scale':
  18666. matrix.scale( this.obj );
  18667. break;
  18668. }
  18669. };
  18670. Transform.prototype.update = function ( data, member ) {
  18671. var members = [ 'X', 'Y', 'Z', 'ANGLE' ];
  18672. switch ( this.type ) {
  18673. case 'matrix':
  18674. if ( ! member ) {
  18675. this.obj.copy( data );
  18676. } else if ( member.length === 1 ) {
  18677. switch ( member[ 0 ] ) {
  18678. case 0:
  18679. this.obj.n11 = data[ 0 ];
  18680. this.obj.n21 = data[ 1 ];
  18681. this.obj.n31 = data[ 2 ];
  18682. this.obj.n41 = data[ 3 ];
  18683. break;
  18684. case 1:
  18685. this.obj.n12 = data[ 0 ];
  18686. this.obj.n22 = data[ 1 ];
  18687. this.obj.n32 = data[ 2 ];
  18688. this.obj.n42 = data[ 3 ];
  18689. break;
  18690. case 2:
  18691. this.obj.n13 = data[ 0 ];
  18692. this.obj.n23 = data[ 1 ];
  18693. this.obj.n33 = data[ 2 ];
  18694. this.obj.n43 = data[ 3 ];
  18695. break;
  18696. case 3:
  18697. this.obj.n14 = data[ 0 ];
  18698. this.obj.n24 = data[ 1 ];
  18699. this.obj.n34 = data[ 2 ];
  18700. this.obj.n44 = data[ 3 ];
  18701. break;
  18702. }
  18703. } else if ( member.length === 2 ) {
  18704. var propName = 'n' + ( member[ 0 ] + 1 ) + ( member[ 1 ] + 1 );
  18705. this.obj[ propName ] = data;
  18706. } else {
  18707. console.log('Incorrect addressing of matrix in transform.');
  18708. }
  18709. break;
  18710. case 'translate':
  18711. case 'scale':
  18712. if ( Object.prototype.toString.call( member ) === '[object Array]' ) {
  18713. member = members[ member[ 0 ] ];
  18714. }
  18715. switch ( member ) {
  18716. case 'X':
  18717. this.obj.x = data;
  18718. break;
  18719. case 'Y':
  18720. this.obj.y = data;
  18721. break;
  18722. case 'Z':
  18723. this.obj.z = data;
  18724. break;
  18725. default:
  18726. this.obj.x = data[ 0 ];
  18727. this.obj.y = data[ 1 ];
  18728. this.obj.z = data[ 2 ];
  18729. break;
  18730. }
  18731. break;
  18732. case 'rotate':
  18733. if ( Object.prototype.toString.call( member ) === '[object Array]' ) {
  18734. member = members[ member[ 0 ] ];
  18735. }
  18736. switch ( member ) {
  18737. case 'X':
  18738. this.obj.x = data;
  18739. break;
  18740. case 'Y':
  18741. this.obj.y = data;
  18742. break;
  18743. case 'Z':
  18744. this.obj.z = data;
  18745. break;
  18746. case 'ANGLE':
  18747. this.angle = data * TO_RADIANS;
  18748. break;
  18749. default:
  18750. this.obj.x = data[ 0 ];
  18751. this.obj.y = data[ 1 ];
  18752. this.obj.z = data[ 2 ];
  18753. this.angle = data[ 3 ] * TO_RADIANS;
  18754. break;
  18755. }
  18756. break;
  18757. }
  18758. };
  18759. function InstanceController() {
  18760. this.url = "";
  18761. this.skeleton = [];
  18762. this.instance_material = [];
  18763. };
  18764. InstanceController.prototype.parse = function ( element ) {
  18765. this.url = element.getAttribute('url').replace(/^#/, '');
  18766. this.skeleton = [];
  18767. this.instance_material = [];
  18768. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  18769. var child = element.childNodes[i];
  18770. if (child.nodeType != 1) continue;
  18771. switch ( child.nodeName ) {
  18772. case 'skeleton':
  18773. this.skeleton.push( child.textContent.replace(/^#/, '') );
  18774. break;
  18775. case 'bind_material':
  18776. var instances = COLLADA.evaluate( './/dae:instance_material', child, _nsResolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
  18777. if ( instances ) {
  18778. var instance = instances.iterateNext();
  18779. while ( instance ) {
  18780. this.instance_material.push((new InstanceMaterial()).parse(instance));
  18781. instance = instances.iterateNext();
  18782. }
  18783. }
  18784. break;
  18785. case 'extra':
  18786. break;
  18787. default:
  18788. break;
  18789. }
  18790. }
  18791. return this;
  18792. };
  18793. function InstanceMaterial () {
  18794. this.symbol = "";
  18795. this.target = "";
  18796. };
  18797. InstanceMaterial.prototype.parse = function ( element ) {
  18798. this.symbol = element.getAttribute('symbol');
  18799. this.target = element.getAttribute('target').replace(/^#/, '');
  18800. return this;
  18801. };
  18802. function InstanceGeometry() {
  18803. this.url = "";
  18804. this.instance_material = [];
  18805. };
  18806. InstanceGeometry.prototype.parse = function ( element ) {
  18807. this.url = element.getAttribute('url').replace(/^#/, '');
  18808. this.instance_material = [];
  18809. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  18810. var child = element.childNodes[i];
  18811. if ( child.nodeType != 1 ) continue;
  18812. if ( child.nodeName == 'bind_material' ) {
  18813. var instances = COLLADA.evaluate( './/dae:instance_material', child, _nsResolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
  18814. if ( instances ) {
  18815. var instance = instances.iterateNext();
  18816. while ( instance ) {
  18817. this.instance_material.push( (new InstanceMaterial()).parse(instance) );
  18818. instance = instances.iterateNext();
  18819. }
  18820. }
  18821. break;
  18822. }
  18823. }
  18824. return this;
  18825. };
  18826. function Geometry() {
  18827. this.id = "";
  18828. this.mesh = null;
  18829. };
  18830. Geometry.prototype.parse = function ( element ) {
  18831. this.id = element.getAttribute('id');
  18832. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  18833. var child = element.childNodes[i];
  18834. switch ( child.nodeName ) {
  18835. case 'mesh':
  18836. this.mesh = (new Mesh(this)).parse(child);
  18837. break;
  18838. case 'extra':
  18839. // console.log( child );
  18840. break;
  18841. default:
  18842. break;
  18843. }
  18844. }
  18845. return this;
  18846. };
  18847. function Mesh( geometry ) {
  18848. this.geometry = geometry.id;
  18849. this.primitives = [];
  18850. this.vertices = null;
  18851. this.geometry3js = null;
  18852. };
  18853. Mesh.prototype.parse = function( element ) {
  18854. this.primitives = [];
  18855. var i, j;
  18856. for ( i = 0; i < element.childNodes.length; i ++ ) {
  18857. var child = element.childNodes[ i ];
  18858. switch ( child.nodeName ) {
  18859. case 'source':
  18860. _source( child );
  18861. break;
  18862. case 'vertices':
  18863. this.vertices = ( new Vertices() ).parse( child );
  18864. break;
  18865. case 'triangles':
  18866. this.primitives.push( ( new Triangles().parse( child ) ) );
  18867. break;
  18868. case 'polygons':
  18869. this.primitives.push( ( new Polygons().parse( child ) ) );
  18870. break;
  18871. case 'polylist':
  18872. this.primitives.push( ( new Polylist().parse( child ) ) );
  18873. break;
  18874. default:
  18875. break;
  18876. }
  18877. }
  18878. this.geometry3js = new THREE.Geometry();
  18879. var vertexData = sources[ this.vertices.input['POSITION'].source ].data;
  18880. for ( i = 0; i < vertexData.length; i += 3 ) {
  18881. this.geometry3js.vertices.push( getConvertedVec3( vertexData, i ).clone() );
  18882. }
  18883. for ( i = 0; i < this.primitives.length; i ++ ) {
  18884. var primitive = this.primitives[ i ];
  18885. primitive.setVertices( this.vertices );
  18886. this.handlePrimitive( primitive, this.geometry3js );
  18887. }
  18888. this.geometry3js.computeCentroids();
  18889. this.geometry3js.computeFaceNormals();
  18890. if ( this.geometry3js.calcNormals ) {
  18891. this.geometry3js.computeVertexNormals();
  18892. delete this.geometry3js.calcNormals;
  18893. }
  18894. this.geometry3js.computeBoundingBox();
  18895. return this;
  18896. };
  18897. Mesh.prototype.handlePrimitive = function( primitive, geom ) {
  18898. var j, k, pList = primitive.p, inputs = primitive.inputs;
  18899. var input, index, idx32;
  18900. var source, numParams;
  18901. var vcIndex = 0, vcount = 3, maxOffset = 0;
  18902. var texture_sets = [];
  18903. for ( j = 0; j < inputs.length; j ++ ) {
  18904. input = inputs[ j ];
  18905. var offset = input.offset + 1;
  18906. maxOffset = (maxOffset < offset)? offset : maxOffset;
  18907. switch ( input.semantic ) {
  18908. case 'TEXCOORD':
  18909. texture_sets.push( input.set );
  18910. break;
  18911. }
  18912. }
  18913. for ( var pCount = 0; pCount < pList.length; ++pCount ) {
  18914. var p = pList[pCount], i = 0;
  18915. while ( i < p.length ) {
  18916. var vs = [];
  18917. var ns = [];
  18918. var ts = {};
  18919. var cs = [];
  18920. if ( primitive.vcount ) {
  18921. vcount = primitive.vcount.length ? primitive.vcount[ vcIndex ++ ] : primitive.vcount;
  18922. } else {
  18923. vcount = p.length / maxOffset;
  18924. }
  18925. for ( j = 0; j < vcount; j ++ ) {
  18926. for ( k = 0; k < inputs.length; k ++ ) {
  18927. input = inputs[ k ];
  18928. source = sources[ input.source ];
  18929. index = p[ i + ( j * maxOffset ) + input.offset ];
  18930. numParams = source.accessor.params.length;
  18931. idx32 = index * numParams;
  18932. switch ( input.semantic ) {
  18933. case 'VERTEX':
  18934. vs.push( index );
  18935. break;
  18936. case 'NORMAL':
  18937. ns.push( getConvertedVec3( source.data, idx32 ) );
  18938. break;
  18939. case 'TEXCOORD':
  18940. if ( ts[ input.set ] === undefined ) ts[ input.set ] = [];
  18941. // invert the V
  18942. ts[ input.set ].push( new THREE.UV( source.data[ idx32 ], 1.0 - source.data[ idx32 + 1 ] ) );
  18943. break;
  18944. case 'COLOR':
  18945. cs.push( new THREE.Color().setRGB( source.data[ idx32 ], source.data[ idx32 + 1 ], source.data[ idx32 + 2 ] ) );
  18946. break;
  18947. default:
  18948. break;
  18949. }
  18950. }
  18951. }
  18952. var face = null, faces = [], uv, uvArr;
  18953. if ( ns.length == 0 ) {
  18954. // check the vertices source
  18955. input = this.vertices.input.NORMAL;
  18956. if ( input ) {
  18957. source = sources[ input.source ];
  18958. numParams = source.accessor.params.length;
  18959. for ( var ndx = 0, len = vs.length; ndx < len; ndx++ ) {
  18960. ns.push( getConvertedVec3( source.data, vs[ ndx ] * numParams ) );
  18961. }
  18962. }
  18963. else {
  18964. geom.calcNormals = true;
  18965. }
  18966. }
  18967. if ( vcount === 3 ) {
  18968. faces.push( new THREE.Face3( vs[0], vs[1], vs[2], ns, cs.length ? cs : new THREE.Color() ) );
  18969. } else if ( vcount === 4 ) {
  18970. faces.push( new THREE.Face4( vs[0], vs[1], vs[2], vs[3], ns, cs.length ? cs : new THREE.Color() ) );
  18971. } else if ( vcount > 4 && options.subdivideFaces ) {
  18972. var clr = cs.length ? cs : new THREE.Color(),
  18973. vec1, vec2, vec3, v1, v2, norm;
  18974. // subdivide into multiple Face3s
  18975. for ( k = 1; k < vcount-1; ) {
  18976. // FIXME: normals don't seem to be quite right
  18977. faces.push( new THREE.Face3( vs[0], vs[k], vs[k+1], [ ns[0], ns[k++], ns[k] ], clr ) );
  18978. }
  18979. }
  18980. if ( faces.length ) {
  18981. for (var ndx = 0, len = faces.length; ndx < len; ndx++) {
  18982. face = faces[ndx];
  18983. face.daeMaterial = primitive.material;
  18984. geom.faces.push( face );
  18985. for ( k = 0; k < texture_sets.length; k++ ) {
  18986. uv = ts[ texture_sets[k] ];
  18987. if ( vcount > 4 ) {
  18988. // Grab the right UVs for the vertices in this face
  18989. uvArr = [ uv[0], uv[ndx+1], uv[ndx+2] ];
  18990. } else if ( vcount === 4 ) {
  18991. uvArr = [ uv[0], uv[1], uv[2], uv[3] ];
  18992. } else {
  18993. uvArr = [ uv[0], uv[1], uv[2] ];
  18994. }
  18995. if ( !geom.faceVertexUvs[k] ) {
  18996. geom.faceVertexUvs[k] = [];
  18997. }
  18998. geom.faceVertexUvs[k].push( uvArr );
  18999. }
  19000. }
  19001. } else {
  19002. console.log( 'dropped face with vcount ' + vcount + ' for geometry with id: ' + geom.id );
  19003. }
  19004. i += maxOffset * vcount;
  19005. }
  19006. }
  19007. };
  19008. function Polygons () {
  19009. this.material = "";
  19010. this.count = 0;
  19011. this.inputs = [];
  19012. this.vcount = null;
  19013. this.p = [];
  19014. this.geometry = new THREE.Geometry();
  19015. };
  19016. Polygons.prototype.setVertices = function ( vertices ) {
  19017. for ( var i = 0; i < this.inputs.length; i ++ ) {
  19018. if ( this.inputs[ i ].source == vertices.id ) {
  19019. this.inputs[ i ].source = vertices.input[ 'POSITION' ].source;
  19020. }
  19021. }
  19022. };
  19023. Polygons.prototype.parse = function ( element ) {
  19024. this.material = element.getAttribute( 'material' );
  19025. this.count = _attr_as_int( element, 'count', 0 );
  19026. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  19027. var child = element.childNodes[ i ];
  19028. switch ( child.nodeName ) {
  19029. case 'input':
  19030. this.inputs.push( ( new Input() ).parse( element.childNodes[ i ] ) );
  19031. break;
  19032. case 'vcount':
  19033. this.vcount = _ints( child.textContent );
  19034. break;
  19035. case 'p':
  19036. this.p.push( _ints( child.textContent ) );
  19037. break;
  19038. case 'ph':
  19039. console.warn( 'polygon holes not yet supported!' );
  19040. break;
  19041. default:
  19042. break;
  19043. }
  19044. }
  19045. return this;
  19046. };
  19047. function Polylist () {
  19048. Polygons.call( this );
  19049. this.vcount = [];
  19050. };
  19051. Polylist.prototype = new Polygons();
  19052. Polylist.prototype.constructor = Polylist;
  19053. function Triangles () {
  19054. Polygons.call( this );
  19055. this.vcount = 3;
  19056. };
  19057. Triangles.prototype = new Polygons();
  19058. Triangles.prototype.constructor = Triangles;
  19059. function Accessor() {
  19060. this.source = "";
  19061. this.count = 0;
  19062. this.stride = 0;
  19063. this.params = [];
  19064. };
  19065. Accessor.prototype.parse = function ( element ) {
  19066. this.params = [];
  19067. this.source = element.getAttribute( 'source' );
  19068. this.count = _attr_as_int( element, 'count', 0 );
  19069. this.stride = _attr_as_int( element, 'stride', 0 );
  19070. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  19071. var child = element.childNodes[ i ];
  19072. if ( child.nodeName == 'param' ) {
  19073. var param = {};
  19074. param[ 'name' ] = child.getAttribute( 'name' );
  19075. param[ 'type' ] = child.getAttribute( 'type' );
  19076. this.params.push( param );
  19077. }
  19078. }
  19079. return this;
  19080. };
  19081. function Vertices() {
  19082. this.input = {};
  19083. };
  19084. Vertices.prototype.parse = function ( element ) {
  19085. this.id = element.getAttribute('id');
  19086. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  19087. if ( element.childNodes[i].nodeName == 'input' ) {
  19088. var input = ( new Input() ).parse( element.childNodes[ i ] );
  19089. this.input[ input.semantic ] = input;
  19090. }
  19091. }
  19092. return this;
  19093. };
  19094. function Input () {
  19095. this.semantic = "";
  19096. this.offset = 0;
  19097. this.source = "";
  19098. this.set = 0;
  19099. };
  19100. Input.prototype.parse = function ( element ) {
  19101. this.semantic = element.getAttribute('semantic');
  19102. this.source = element.getAttribute('source').replace(/^#/, '');
  19103. this.set = _attr_as_int(element, 'set', -1);
  19104. this.offset = _attr_as_int(element, 'offset', 0);
  19105. if ( this.semantic == 'TEXCOORD' && this.set < 0 ) {
  19106. this.set = 0;
  19107. }
  19108. return this;
  19109. };
  19110. function Source ( id ) {
  19111. this.id = id;
  19112. this.type = null;
  19113. };
  19114. Source.prototype.parse = function ( element ) {
  19115. this.id = element.getAttribute( 'id' );
  19116. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  19117. var child = element.childNodes[i];
  19118. switch ( child.nodeName ) {
  19119. case 'bool_array':
  19120. this.data = _bools( child.textContent );
  19121. this.type = child.nodeName;
  19122. break;
  19123. case 'float_array':
  19124. this.data = _floats( child.textContent );
  19125. this.type = child.nodeName;
  19126. break;
  19127. case 'int_array':
  19128. this.data = _ints( child.textContent );
  19129. this.type = child.nodeName;
  19130. break;
  19131. case 'IDREF_array':
  19132. case 'Name_array':
  19133. this.data = _strings( child.textContent );
  19134. this.type = child.nodeName;
  19135. break;
  19136. case 'technique_common':
  19137. for ( var j = 0; j < child.childNodes.length; j ++ ) {
  19138. if ( child.childNodes[ j ].nodeName == 'accessor' ) {
  19139. this.accessor = ( new Accessor() ).parse( child.childNodes[ j ] );
  19140. break;
  19141. }
  19142. }
  19143. break;
  19144. default:
  19145. // console.log(child.nodeName);
  19146. break;
  19147. }
  19148. }
  19149. return this;
  19150. };
  19151. Source.prototype.read = function () {
  19152. var result = [];
  19153. //for (var i = 0; i < this.accessor.params.length; i++) {
  19154. var param = this.accessor.params[ 0 ];
  19155. //console.log(param.name + " " + param.type);
  19156. switch ( param.type ) {
  19157. case 'IDREF':
  19158. case 'Name': case 'name':
  19159. case 'float':
  19160. return this.data;
  19161. case 'float4x4':
  19162. for ( var j = 0; j < this.data.length; j += 16 ) {
  19163. var s = this.data.slice( j, j + 16 );
  19164. var m = getConvertedMat4( s );
  19165. result.push( m );
  19166. }
  19167. break;
  19168. default:
  19169. console.log( 'ColladaLoader: Source: Read dont know how to read ' + param.type + '.' );
  19170. break;
  19171. }
  19172. //}
  19173. return result;
  19174. };
  19175. function Material () {
  19176. this.id = "";
  19177. this.name = "";
  19178. this.instance_effect = null;
  19179. };
  19180. Material.prototype.parse = function ( element ) {
  19181. this.id = element.getAttribute( 'id' );
  19182. this.name = element.getAttribute( 'name' );
  19183. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  19184. if ( element.childNodes[ i ].nodeName == 'instance_effect' ) {
  19185. this.instance_effect = ( new InstanceEffect() ).parse( element.childNodes[ i ] );
  19186. break;
  19187. }
  19188. }
  19189. return this;
  19190. };
  19191. function ColorOrTexture () {
  19192. this.color = new THREE.Color( 0 );
  19193. this.color.setRGB( Math.random(), Math.random(), Math.random() );
  19194. this.color.a = 1.0;
  19195. this.texture = null;
  19196. this.texcoord = null;
  19197. this.texOpts = null;
  19198. };
  19199. ColorOrTexture.prototype.isColor = function () {
  19200. return ( this.texture == null );
  19201. };
  19202. ColorOrTexture.prototype.isTexture = function () {
  19203. return ( this.texture != null );
  19204. };
  19205. ColorOrTexture.prototype.parse = function ( element ) {
  19206. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  19207. var child = element.childNodes[ i ];
  19208. if ( child.nodeType != 1 ) continue;
  19209. switch ( child.nodeName ) {
  19210. case 'color':
  19211. var rgba = _floats( child.textContent );
  19212. this.color = new THREE.Color(0);
  19213. this.color.setRGB( rgba[0], rgba[1], rgba[2] );
  19214. this.color.a = rgba[3];
  19215. break;
  19216. case 'texture':
  19217. this.texture = child.getAttribute('texture');
  19218. this.texcoord = child.getAttribute('texcoord');
  19219. // Defaults from:
  19220. // https://collada.org/mediawiki/index.php/Maya_texture_placement_MAYA_extension
  19221. this.texOpts = {
  19222. offsetU: 0,
  19223. offsetV: 0,
  19224. repeatU: 1,
  19225. repeatV: 1,
  19226. wrapU: 1,
  19227. wrapV: 1,
  19228. };
  19229. this.parseTexture( child );
  19230. break;
  19231. default:
  19232. break;
  19233. }
  19234. }
  19235. return this;
  19236. };
  19237. ColorOrTexture.prototype.parseTexture = function ( element ) {
  19238. if ( ! element.childNodes ) return this;
  19239. // This should be supported by Maya, 3dsMax, and MotionBuilder
  19240. if ( element.childNodes[1] && element.childNodes[1].nodeName === 'extra' ) {
  19241. element = element.childNodes[1];
  19242. if ( element.childNodes[1] && element.childNodes[1].nodeName === 'technique' ) {
  19243. element = element.childNodes[1];
  19244. }
  19245. }
  19246. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  19247. var child = element.childNodes[ i ];
  19248. switch ( child.nodeName ) {
  19249. case 'offsetU':
  19250. case 'offsetV':
  19251. case 'repeatU':
  19252. case 'repeatV':
  19253. this.texOpts[ child.nodeName ] = parseFloat( child.textContent );
  19254. break;
  19255. case 'wrapU':
  19256. case 'wrapV':
  19257. this.texOpts[ child.nodeName ] = parseInt( child.textContent );
  19258. break;
  19259. default:
  19260. this.texOpts[ child.nodeName ] = child.textContent;
  19261. break;
  19262. }
  19263. }
  19264. return this;
  19265. };
  19266. function Shader ( type, effect ) {
  19267. this.type = type;
  19268. this.effect = effect;
  19269. this.material = null;
  19270. };
  19271. Shader.prototype.parse = function ( element ) {
  19272. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  19273. var child = element.childNodes[ i ];
  19274. if ( child.nodeType != 1 ) continue;
  19275. switch ( child.nodeName ) {
  19276. case 'ambient':
  19277. case 'emission':
  19278. case 'diffuse':
  19279. case 'specular':
  19280. case 'transparent':
  19281. this[ child.nodeName ] = ( new ColorOrTexture() ).parse( child );
  19282. break;
  19283. case 'shininess':
  19284. case 'reflectivity':
  19285. case 'transparency':
  19286. var f = evaluateXPath( child, './/dae:float' );
  19287. if ( f.length > 0 )
  19288. this[ child.nodeName ] = parseFloat( f[ 0 ].textContent );
  19289. break;
  19290. default:
  19291. break;
  19292. }
  19293. }
  19294. this.create();
  19295. return this;
  19296. };
  19297. Shader.prototype.create = function() {
  19298. var props = {};
  19299. var transparent = ( this['transparency'] !== undefined && this['transparency'] < 1.0 );
  19300. for ( var prop in this ) {
  19301. switch ( prop ) {
  19302. case 'ambient':
  19303. case 'emission':
  19304. case 'diffuse':
  19305. case 'specular':
  19306. var cot = this[prop];
  19307. if ( cot instanceof ColorOrTexture ) {
  19308. if ( cot.isTexture() ) {
  19309. if ( this.effect.sampler && this.effect.surface ) {
  19310. if ( this.effect.sampler.source == this.effect.surface.sid ) {
  19311. var image = images[this.effect.surface.init_from];
  19312. if ( image ) {
  19313. var texture = THREE.ImageUtils.loadTexture(baseUrl + image.init_from);
  19314. texture.wrapS = cot.texOpts.wrapU ? THREE.RepeatWrapping : THREE.ClampToEdgeWrapping;
  19315. texture.wrapT = cot.texOpts.wrapV ? THREE.RepeatWrapping : THREE.ClampToEdgeWrapping;
  19316. texture.offset.x = cot.texOpts.offsetU;
  19317. texture.offset.y = cot.texOpts.offsetV;
  19318. texture.repeat.x = cot.texOpts.repeatU;
  19319. texture.repeat.y = cot.texOpts.repeatV;
  19320. props['map'] = texture;
  19321. // Texture with baked lighting?
  19322. if ( prop == 'emission' ) props[ 'emissive' ] = 0xffffff;
  19323. }
  19324. }
  19325. }
  19326. } else if ( prop == 'diffuse' || !transparent ) {
  19327. if ( prop == 'emission' ) {
  19328. props[ 'emissive' ] = cot.color.getHex();
  19329. } else {
  19330. props[ prop ] = cot.color.getHex();
  19331. }
  19332. }
  19333. }
  19334. break;
  19335. case 'shininess':
  19336. case 'reflectivity':
  19337. props[ prop ] = this[ prop ];
  19338. break;
  19339. case 'transparency':
  19340. if ( transparent ) {
  19341. props[ 'transparent' ] = true;
  19342. props[ 'opacity' ] = this[ prop ];
  19343. transparent = true;
  19344. }
  19345. break;
  19346. default:
  19347. break;
  19348. }
  19349. }
  19350. props[ 'shading' ] = preferredShading;
  19351. switch ( this.type ) {
  19352. case 'constant':
  19353. props.color = props.emission;
  19354. this.material = new THREE.MeshBasicMaterial( props );
  19355. break;
  19356. case 'phong':
  19357. case 'blinn':
  19358. props.color = props.diffuse;
  19359. this.material = new THREE.MeshPhongMaterial( props );
  19360. break;
  19361. case 'lambert':
  19362. default:
  19363. props.color = props.diffuse;
  19364. this.material = new THREE.MeshLambertMaterial( props );
  19365. break;
  19366. }
  19367. return this.material;
  19368. };
  19369. function Surface ( effect ) {
  19370. this.effect = effect;
  19371. this.init_from = null;
  19372. this.format = null;
  19373. };
  19374. Surface.prototype.parse = function ( element ) {
  19375. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  19376. var child = element.childNodes[ i ];
  19377. if ( child.nodeType != 1 ) continue;
  19378. switch ( child.nodeName ) {
  19379. case 'init_from':
  19380. this.init_from = child.textContent;
  19381. break;
  19382. case 'format':
  19383. this.format = child.textContent;
  19384. break;
  19385. default:
  19386. console.log( "unhandled Surface prop: " + child.nodeName );
  19387. break;
  19388. }
  19389. }
  19390. return this;
  19391. };
  19392. function Sampler2D ( effect ) {
  19393. this.effect = effect;
  19394. this.source = null;
  19395. this.wrap_s = null;
  19396. this.wrap_t = null;
  19397. this.minfilter = null;
  19398. this.magfilter = null;
  19399. this.mipfilter = null;
  19400. };
  19401. Sampler2D.prototype.parse = function ( element ) {
  19402. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  19403. var child = element.childNodes[ i ];
  19404. if ( child.nodeType != 1 ) continue;
  19405. switch ( child.nodeName ) {
  19406. case 'source':
  19407. this.source = child.textContent;
  19408. break;
  19409. case 'minfilter':
  19410. this.minfilter = child.textContent;
  19411. break;
  19412. case 'magfilter':
  19413. this.magfilter = child.textContent;
  19414. break;
  19415. case 'mipfilter':
  19416. this.mipfilter = child.textContent;
  19417. break;
  19418. case 'wrap_s':
  19419. this.wrap_s = child.textContent;
  19420. break;
  19421. case 'wrap_t':
  19422. this.wrap_t = child.textContent;
  19423. break;
  19424. default:
  19425. console.log( "unhandled Sampler2D prop: " + child.nodeName );
  19426. break;
  19427. }
  19428. }
  19429. return this;
  19430. };
  19431. function Effect () {
  19432. this.id = "";
  19433. this.name = "";
  19434. this.shader = null;
  19435. this.surface = null;
  19436. this.sampler = null;
  19437. };
  19438. Effect.prototype.create = function () {
  19439. if ( this.shader == null ) {
  19440. return null;
  19441. }
  19442. };
  19443. Effect.prototype.parse = function ( element ) {
  19444. this.id = element.getAttribute( 'id' );
  19445. this.name = element.getAttribute( 'name' );
  19446. this.shader = null;
  19447. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  19448. var child = element.childNodes[ i ];
  19449. if ( child.nodeType != 1 ) continue;
  19450. switch ( child.nodeName ) {
  19451. case 'profile_COMMON':
  19452. this.parseTechnique( this.parseProfileCOMMON( child ) );
  19453. break;
  19454. default:
  19455. break;
  19456. }
  19457. }
  19458. return this;
  19459. };
  19460. Effect.prototype.parseNewparam = function ( element ) {
  19461. var sid = element.getAttribute( 'sid' );
  19462. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  19463. var child = element.childNodes[ i ];
  19464. if ( child.nodeType != 1 ) continue;
  19465. switch ( child.nodeName ) {
  19466. case 'surface':
  19467. this.surface = ( new Surface( this ) ).parse( child );
  19468. this.surface.sid = sid;
  19469. break;
  19470. case 'sampler2D':
  19471. this.sampler = ( new Sampler2D( this ) ).parse( child );
  19472. this.sampler.sid = sid;
  19473. break;
  19474. case 'extra':
  19475. break;
  19476. default:
  19477. console.log( child.nodeName );
  19478. break;
  19479. }
  19480. }
  19481. };
  19482. Effect.prototype.parseProfileCOMMON = function ( element ) {
  19483. var technique;
  19484. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  19485. var child = element.childNodes[ i ];
  19486. if ( child.nodeType != 1 ) continue;
  19487. switch ( child.nodeName ) {
  19488. case 'profile_COMMON':
  19489. this.parseProfileCOMMON( child );
  19490. break;
  19491. case 'technique':
  19492. technique = child;
  19493. break;
  19494. case 'newparam':
  19495. this.parseNewparam( child );
  19496. break;
  19497. case 'image':
  19498. var _image = ( new _Image() ).parse( child );
  19499. images[ _image.id ] = _image;
  19500. break;
  19501. case 'extra':
  19502. break;
  19503. default:
  19504. console.log( child.nodeName );
  19505. break;
  19506. }
  19507. }
  19508. return technique;
  19509. };
  19510. Effect.prototype.parseTechnique= function ( element ) {
  19511. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  19512. var child = element.childNodes[i];
  19513. if ( child.nodeType != 1 ) continue;
  19514. switch ( child.nodeName ) {
  19515. case 'constant':
  19516. case 'lambert':
  19517. case 'blinn':
  19518. case 'phong':
  19519. this.shader = ( new Shader( child.nodeName, this ) ).parse( child );
  19520. break;
  19521. default:
  19522. break;
  19523. }
  19524. }
  19525. };
  19526. function InstanceEffect () {
  19527. this.url = "";
  19528. };
  19529. InstanceEffect.prototype.parse = function ( element ) {
  19530. this.url = element.getAttribute( 'url' ).replace( /^#/, '' );
  19531. return this;
  19532. };
  19533. function Animation() {
  19534. this.id = "";
  19535. this.name = "";
  19536. this.source = {};
  19537. this.sampler = [];
  19538. this.channel = [];
  19539. };
  19540. Animation.prototype.parse = function ( element ) {
  19541. this.id = element.getAttribute( 'id' );
  19542. this.name = element.getAttribute( 'name' );
  19543. this.source = {};
  19544. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  19545. var child = element.childNodes[ i ];
  19546. if ( child.nodeType != 1 ) continue;
  19547. switch ( child.nodeName ) {
  19548. case 'animation':
  19549. var anim = ( new Animation() ).parse( child );
  19550. for ( var src in anim.source ) {
  19551. this.source[ src ] = anim.source[ src ];
  19552. }
  19553. for ( var j = 0; j < anim.channel.length; j ++ ) {
  19554. this.channel.push( anim.channel[ j ] );
  19555. this.sampler.push( anim.sampler[ j ] );
  19556. }
  19557. break;
  19558. case 'source':
  19559. var src = ( new Source() ).parse( child );
  19560. this.source[ src.id ] = src;
  19561. break;
  19562. case 'sampler':
  19563. this.sampler.push( ( new Sampler( this ) ).parse( child ) );
  19564. break;
  19565. case 'channel':
  19566. this.channel.push( ( new Channel( this ) ).parse( child ) );
  19567. break;
  19568. default:
  19569. break;
  19570. }
  19571. }
  19572. return this;
  19573. };
  19574. function Channel( animation ) {
  19575. this.animation = animation;
  19576. this.source = "";
  19577. this.target = "";
  19578. this.fullSid = null;
  19579. this.sid = null;
  19580. this.dotSyntax = null;
  19581. this.arrSyntax = null;
  19582. this.arrIndices = null;
  19583. this.member = null;
  19584. };
  19585. Channel.prototype.parse = function ( element ) {
  19586. this.source = element.getAttribute( 'source' ).replace( /^#/, '' );
  19587. this.target = element.getAttribute( 'target' );
  19588. var parts = this.target.split( '/' );
  19589. var id = parts.shift();
  19590. var sid = parts.shift();
  19591. var dotSyntax = ( sid.indexOf(".") >= 0 );
  19592. var arrSyntax = ( sid.indexOf("(") >= 0 );
  19593. if ( dotSyntax ) {
  19594. parts = sid.split(".");
  19595. this.sid = parts.shift();
  19596. this.member = parts.shift();
  19597. } else if ( arrSyntax ) {
  19598. var arrIndices = sid.split("(");
  19599. this.sid = arrIndices.shift();
  19600. for (var j = 0; j < arrIndices.length; j ++ ) {
  19601. arrIndices[j] = parseInt( arrIndices[j].replace(/\)/, '') );
  19602. }
  19603. this.arrIndices = arrIndices;
  19604. } else {
  19605. this.sid = sid;
  19606. }
  19607. this.fullSid = sid;
  19608. this.dotSyntax = dotSyntax;
  19609. this.arrSyntax = arrSyntax;
  19610. return this;
  19611. };
  19612. function Sampler ( animation ) {
  19613. this.id = "";
  19614. this.animation = animation;
  19615. this.inputs = [];
  19616. this.input = null;
  19617. this.output = null;
  19618. this.strideOut = null;
  19619. this.interpolation = null;
  19620. this.startTime = null;
  19621. this.endTime = null;
  19622. this.duration = 0;
  19623. };
  19624. Sampler.prototype.parse = function ( element ) {
  19625. this.id = element.getAttribute( 'id' );
  19626. this.inputs = [];
  19627. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  19628. var child = element.childNodes[ i ];
  19629. if ( child.nodeType != 1 ) continue;
  19630. switch ( child.nodeName ) {
  19631. case 'input':
  19632. this.inputs.push( (new Input()).parse( child ) );
  19633. break;
  19634. default:
  19635. break;
  19636. }
  19637. }
  19638. return this;
  19639. };
  19640. Sampler.prototype.create = function () {
  19641. for ( var i = 0; i < this.inputs.length; i ++ ) {
  19642. var input = this.inputs[ i ];
  19643. var source = this.animation.source[ input.source ];
  19644. switch ( input.semantic ) {
  19645. case 'INPUT':
  19646. this.input = source.read();
  19647. break;
  19648. case 'OUTPUT':
  19649. this.output = source.read();
  19650. this.strideOut = source.accessor.stride;
  19651. break;
  19652. case 'INTERPOLATION':
  19653. this.interpolation = source.read();
  19654. break;
  19655. case 'IN_TANGENT':
  19656. break;
  19657. case 'OUT_TANGENT':
  19658. break;
  19659. default:
  19660. console.log(input.semantic);
  19661. break;
  19662. }
  19663. }
  19664. this.startTime = 0;
  19665. this.endTime = 0;
  19666. this.duration = 0;
  19667. if ( this.input.length ) {
  19668. this.startTime = 100000000;
  19669. this.endTime = -100000000;
  19670. for ( var i = 0; i < this.input.length; i ++ ) {
  19671. this.startTime = Math.min( this.startTime, this.input[ i ] );
  19672. this.endTime = Math.max( this.endTime, this.input[ i ] );
  19673. }
  19674. this.duration = this.endTime - this.startTime;
  19675. }
  19676. };
  19677. Sampler.prototype.getData = function ( type, ndx ) {
  19678. var data;
  19679. if ( type === 'matrix' && this.strideOut === 16 ) {
  19680. data = this.output[ ndx ];
  19681. } else if ( this.strideOut > 1 ) {
  19682. data = [];
  19683. ndx *= this.strideOut;
  19684. for ( var i = 0; i < this.strideOut; ++i ) {
  19685. data[ i ] = this.output[ ndx + i ];
  19686. }
  19687. if ( this.strideOut === 3 ) {
  19688. switch ( type ) {
  19689. case 'rotate':
  19690. case 'translate':
  19691. fixCoords( data, -1 );
  19692. break;
  19693. case 'scale':
  19694. fixCoords( data, 1 );
  19695. break;
  19696. }
  19697. } else if ( this.strideOut === 4 && type === 'matrix' ) {
  19698. fixCoords( data, -1 );
  19699. }
  19700. } else {
  19701. data = this.output[ ndx ];
  19702. }
  19703. return data;
  19704. };
  19705. function Key ( time ) {
  19706. this.targets = [];
  19707. this.time = time;
  19708. };
  19709. Key.prototype.addTarget = function ( fullSid, transform, member, data ) {
  19710. this.targets.push( {
  19711. sid: fullSid,
  19712. member: member,
  19713. transform: transform,
  19714. data: data
  19715. } );
  19716. };
  19717. Key.prototype.apply = function ( opt_sid ) {
  19718. for ( var i = 0; i < this.targets.length; ++i ) {
  19719. var target = this.targets[ i ];
  19720. if ( !opt_sid || target.sid === opt_sid ) {
  19721. target.transform.update( target.data, target.member );
  19722. }
  19723. }
  19724. };
  19725. Key.prototype.getTarget = function ( fullSid ) {
  19726. for ( var i = 0; i < this.targets.length; ++i ) {
  19727. if ( this.targets[ i ].sid === fullSid ) {
  19728. return this.targets[ i ];
  19729. }
  19730. }
  19731. return null;
  19732. };
  19733. Key.prototype.hasTarget = function ( fullSid ) {
  19734. for ( var i = 0; i < this.targets.length; ++i ) {
  19735. if ( this.targets[ i ].sid === fullSid ) {
  19736. return true;
  19737. }
  19738. }
  19739. return false;
  19740. };
  19741. // TODO: Currently only doing linear interpolation. Should support full COLLADA spec.
  19742. Key.prototype.interpolate = function ( nextKey, time ) {
  19743. for ( var i = 0; i < this.targets.length; ++i ) {
  19744. var target = this.targets[ i ],
  19745. nextTarget = nextKey.getTarget( target.sid ),
  19746. data;
  19747. if ( target.transform.type !== 'matrix' && nextTarget ) {
  19748. var scale = ( time - this.time ) / ( nextKey.time - this.time ),
  19749. nextData = nextTarget.data,
  19750. prevData = target.data;
  19751. // check scale error
  19752. if ( scale < 0 || scale > 1 ) {
  19753. console.log( "Key.interpolate: Warning! Scale out of bounds:" + scale );
  19754. scale = scale < 0 ? 0 : 1;
  19755. }
  19756. if ( prevData.length ) {
  19757. data = [];
  19758. for ( var j = 0; j < prevData.length; ++j ) {
  19759. data[ j ] = prevData[ j ] + ( nextData[ j ] - prevData[ j ] ) * scale;
  19760. }
  19761. } else {
  19762. data = prevData + ( nextData - prevData ) * scale;
  19763. }
  19764. } else {
  19765. data = target.data;
  19766. }
  19767. target.transform.update( data, target.member );
  19768. }
  19769. };
  19770. function Camera() {
  19771. this.id = "";
  19772. this.name = "";
  19773. this.technique = "";
  19774. };
  19775. Camera.prototype.parse = function ( element ) {
  19776. this.id = element.getAttribute( 'id' );
  19777. this.name = element.getAttribute( 'name' );
  19778. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  19779. var child = element.childNodes[ i ];
  19780. if ( child.nodeType != 1 ) continue;
  19781. switch ( child.nodeName ) {
  19782. case 'optics':
  19783. this.parseOptics( child );
  19784. break;
  19785. default:
  19786. break;
  19787. }
  19788. }
  19789. return this;
  19790. };
  19791. Camera.prototype.parseOptics = function ( element ) {
  19792. for ( var i = 0; i < element.childNodes.length; i ++ ) {
  19793. if ( element.childNodes[ i ].nodeName == 'technique_common' ) {
  19794. var technique = element.childNodes[ i ];
  19795. for ( var j = 0; j < technique.childNodes.length; j ++ ) {
  19796. this.technique = technique.childNodes[ j ].nodeName;
  19797. if ( this.technique == 'perspective' ) {
  19798. var perspective = technique.childNodes[ j ];
  19799. for ( var k = 0; k < perspective.childNodes.length; k ++ ) {
  19800. var param = perspective.childNodes[ k ];
  19801. switch ( param.nodeName ) {
  19802. case 'yfov':
  19803. this.yfov = param.textContent;
  19804. break;
  19805. case 'xfov':
  19806. this.xfov = param.textContent;
  19807. break;
  19808. case 'znear':
  19809. this.znear = param.textContent;
  19810. break;
  19811. case 'zfar':
  19812. this.zfar = param.textContent;
  19813. break;
  19814. case 'aspect_ratio':
  19815. this.aspect_ratio = param.textContent;
  19816. break;
  19817. }
  19818. }
  19819. } else if ( this.technique == 'orthographic' ) {
  19820. var orthographic = technique.childNodes[ j ];
  19821. for ( var k = 0; k < orthographic.childNodes.length; k ++ ) {
  19822. var param = orthographic.childNodes[ k ];
  19823. switch ( param.nodeName ) {
  19824. case 'xmag':
  19825. this.xmag = param.textContent;
  19826. break;
  19827. case 'ymag':
  19828. this.ymag = param.textContent;
  19829. break;
  19830. case 'znear':
  19831. this.znear = param.textContent;
  19832. break;
  19833. case 'zfar':
  19834. this.zfar = param.textContent;
  19835. break;
  19836. case 'aspect_ratio':
  19837. this.aspect_ratio = param.textContent;
  19838. break;
  19839. }
  19840. }
  19841. }
  19842. }
  19843. }
  19844. }
  19845. return this;
  19846. };
  19847. function InstanceCamera() {
  19848. this.url = "";
  19849. };
  19850. InstanceCamera.prototype.parse = function ( element ) {
  19851. this.url = element.getAttribute('url').replace(/^#/, '');
  19852. return this;
  19853. };
  19854. function _source( element ) {
  19855. var id = element.getAttribute( 'id' );
  19856. if ( sources[ id ] != undefined ) {
  19857. return sources[ id ];
  19858. }
  19859. sources[ id ] = ( new Source(id )).parse( element );
  19860. return sources[ id ];
  19861. };
  19862. function _nsResolver( nsPrefix ) {
  19863. if ( nsPrefix == "dae" ) {
  19864. return "http://www.collada.org/2005/11/COLLADASchema";
  19865. }
  19866. return null;
  19867. };
  19868. function _bools( str ) {
  19869. var raw = _strings( str );
  19870. var data = [];
  19871. for ( var i = 0, l = raw.length; i < l; i ++ ) {
  19872. data.push( (raw[i] == 'true' || raw[i] == '1') ? true : false );
  19873. }
  19874. return data;
  19875. };
  19876. function _floats( str ) {
  19877. var raw = _strings(str);
  19878. var data = [];
  19879. for ( var i = 0, l = raw.length; i < l; i ++ ) {
  19880. data.push( parseFloat( raw[ i ] ) );
  19881. }
  19882. return data;
  19883. };
  19884. function _ints( str ) {
  19885. var raw = _strings( str );
  19886. var data = [];
  19887. for ( var i = 0, l = raw.length; i < l; i ++ ) {
  19888. data.push( parseInt( raw[ i ], 10 ) );
  19889. }
  19890. return data;
  19891. };
  19892. function _strings( str ) {
  19893. return ( str.length > 0 ) ? _trimString( str ).split( /\s+/ ) : [];
  19894. };
  19895. function _trimString( str ) {
  19896. return str.replace( /^\s+/, "" ).replace( /\s+$/, "" );
  19897. };
  19898. function _attr_as_float( element, name, defaultValue ) {
  19899. if ( element.hasAttribute( name ) ) {
  19900. return parseFloat( element.getAttribute( name ) );
  19901. } else {
  19902. return defaultValue;
  19903. }
  19904. };
  19905. function _attr_as_int( element, name, defaultValue ) {
  19906. if ( element.hasAttribute( name ) ) {
  19907. return parseInt( element.getAttribute( name ), 10) ;
  19908. } else {
  19909. return defaultValue;
  19910. }
  19911. };
  19912. function _attr_as_string( element, name, defaultValue ) {
  19913. if ( element.hasAttribute( name ) ) {
  19914. return element.getAttribute( name );
  19915. } else {
  19916. return defaultValue;
  19917. }
  19918. };
  19919. function _format_float( f, num ) {
  19920. if ( f === undefined ) {
  19921. var s = '0.';
  19922. while ( s.length < num + 2 ) {
  19923. s += '0';
  19924. }
  19925. return s;
  19926. }
  19927. num = num || 2;
  19928. var parts = f.toString().split( '.' );
  19929. parts[ 1 ] = parts.length > 1 ? parts[ 1 ].substr( 0, num ) : "0";
  19930. while( parts[ 1 ].length < num ) {
  19931. parts[ 1 ] += '0';
  19932. }
  19933. return parts.join( '.' );
  19934. };
  19935. function evaluateXPath( node, query ) {
  19936. var instances = COLLADA.evaluate( query, node, _nsResolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
  19937. var inst = instances.iterateNext();
  19938. var result = [];
  19939. while ( inst ) {
  19940. result.push( inst );
  19941. inst = instances.iterateNext();
  19942. }
  19943. return result;
  19944. };
  19945. // Up axis conversion
  19946. function setUpConversion() {
  19947. if ( !options.convertUpAxis || colladaUp === options.upAxis ) {
  19948. upConversion = null;
  19949. } else {
  19950. switch ( colladaUp ) {
  19951. case 'X':
  19952. upConversion = options.upAxis === 'Y' ? 'XtoY' : 'XtoZ';
  19953. break;
  19954. case 'Y':
  19955. upConversion = options.upAxis === 'X' ? 'YtoX' : 'YtoZ';
  19956. break;
  19957. case 'Z':
  19958. upConversion = options.upAxis === 'X' ? 'ZtoX' : 'ZtoY';
  19959. break;
  19960. }
  19961. }
  19962. };
  19963. function fixCoords( data, sign ) {
  19964. if ( !options.convertUpAxis || colladaUp === options.upAxis ) {
  19965. return;
  19966. }
  19967. switch ( upConversion ) {
  19968. case 'XtoY':
  19969. var tmp = data[ 0 ];
  19970. data[ 0 ] = sign * data[ 1 ];
  19971. data[ 1 ] = tmp;
  19972. break;
  19973. case 'XtoZ':
  19974. var tmp = data[ 2 ];
  19975. data[ 2 ] = data[ 1 ];
  19976. data[ 1 ] = data[ 0 ];
  19977. data[ 0 ] = tmp;
  19978. break;
  19979. case 'YtoX':
  19980. var tmp = data[ 0 ];
  19981. data[ 0 ] = data[ 1 ];
  19982. data[ 1 ] = sign * tmp;
  19983. break;
  19984. case 'YtoZ':
  19985. var tmp = data[ 1 ];
  19986. data[ 1 ] = sign * data[ 2 ];
  19987. data[ 2 ] = tmp;
  19988. break;
  19989. case 'ZtoX':
  19990. var tmp = data[ 0 ];
  19991. data[ 0 ] = data[ 1 ];
  19992. data[ 1 ] = data[ 2 ];
  19993. data[ 2 ] = tmp;
  19994. break;
  19995. case 'ZtoY':
  19996. var tmp = data[ 1 ];
  19997. data[ 1 ] = data[ 2 ];
  19998. data[ 2 ] = sign * tmp;
  19999. break;
  20000. }
  20001. };
  20002. function getConvertedVec3( data, offset ) {
  20003. var arr = [ data[ offset ], data[ offset + 1 ], data[ offset + 2 ] ];
  20004. fixCoords( arr, -1 );
  20005. return new THREE.Vector3( arr[ 0 ], arr[ 1 ], arr[ 2 ] );
  20006. };
  20007. function getConvertedMat4( data ) {
  20008. if ( options.convertUpAxis ) {
  20009. // First fix rotation and scale
  20010. // Columns first
  20011. var arr = [ data[ 0 ], data[ 4 ], data[ 8 ] ];
  20012. fixCoords( arr, -1 );
  20013. data[ 0 ] = arr[ 0 ];
  20014. data[ 4 ] = arr[ 1 ];
  20015. data[ 8 ] = arr[ 2 ];
  20016. arr = [ data[ 1 ], data[ 5 ], data[ 9 ] ];
  20017. fixCoords( arr, -1 );
  20018. data[ 1 ] = arr[ 0 ];
  20019. data[ 5 ] = arr[ 1 ];
  20020. data[ 9 ] = arr[ 2 ];
  20021. arr = [ data[ 2 ], data[ 6 ], data[ 10 ] ];
  20022. fixCoords( arr, -1 );
  20023. data[ 2 ] = arr[ 0 ];
  20024. data[ 6 ] = arr[ 1 ];
  20025. data[ 10 ] = arr[ 2 ];
  20026. // Rows second
  20027. arr = [ data[ 0 ], data[ 1 ], data[ 2 ] ];
  20028. fixCoords( arr, -1 );
  20029. data[ 0 ] = arr[ 0 ];
  20030. data[ 1 ] = arr[ 1 ];
  20031. data[ 2 ] = arr[ 2 ];
  20032. arr = [ data[ 4 ], data[ 5 ], data[ 6 ] ];
  20033. fixCoords( arr, -1 );
  20034. data[ 4 ] = arr[ 0 ];
  20035. data[ 5 ] = arr[ 1 ];
  20036. data[ 6 ] = arr[ 2 ];
  20037. arr = [ data[ 8 ], data[ 9 ], data[ 10 ] ];
  20038. fixCoords( arr, -1 );
  20039. data[ 8 ] = arr[ 0 ];
  20040. data[ 9 ] = arr[ 1 ];
  20041. data[ 10 ] = arr[ 2 ];
  20042. // Now fix translation
  20043. arr = [ data[ 3 ], data[ 7 ], data[ 11 ] ];
  20044. fixCoords( arr, -1 );
  20045. data[ 3 ] = arr[ 0 ];
  20046. data[ 7 ] = arr[ 1 ];
  20047. data[ 11 ] = arr[ 2 ];
  20048. }
  20049. return new THREE.Matrix4(
  20050. data[0], data[1], data[2], data[3],
  20051. data[4], data[5], data[6], data[7],
  20052. data[8], data[9], data[10], data[11],
  20053. data[12], data[13], data[14], data[15]
  20054. );
  20055. };
  20056. function getConvertedIndex( index ) {
  20057. if ( index > -1 && index < 3 ) {
  20058. var members = ['X', 'Y', 'Z'],
  20059. indices = { X: 0, Y: 1, Z: 2 };
  20060. index = getConvertedMember( members[ index ] );
  20061. index = indices[ index ];
  20062. }
  20063. return index;
  20064. };
  20065. function getConvertedMember( member ) {
  20066. if ( options.convertUpAxis ) {
  20067. switch ( member ) {
  20068. case 'X':
  20069. switch ( upConversion ) {
  20070. case 'XtoY':
  20071. case 'XtoZ':
  20072. case 'YtoX':
  20073. member = 'Y';
  20074. break;
  20075. case 'ZtoX':
  20076. member = 'Z';
  20077. break;
  20078. }
  20079. break;
  20080. case 'Y':
  20081. switch ( upConversion ) {
  20082. case 'XtoY':
  20083. case 'YtoX':
  20084. case 'ZtoX':
  20085. member = 'X';
  20086. break;
  20087. case 'XtoZ':
  20088. case 'YtoZ':
  20089. case 'ZtoY':
  20090. member = 'Z';
  20091. break;
  20092. }
  20093. break;
  20094. case 'Z':
  20095. switch ( upConversion ) {
  20096. case 'XtoZ':
  20097. member = 'X';
  20098. break;
  20099. case 'YtoZ':
  20100. case 'ZtoX':
  20101. case 'ZtoY':
  20102. member = 'Y';
  20103. break;
  20104. }
  20105. break;
  20106. }
  20107. }
  20108. return member;
  20109. };
  20110. return {
  20111. load: load,
  20112. parse: parse,
  20113. setPreferredShading: setPreferredShading,
  20114. applySkin: applySkin,
  20115. geometries : geometries,
  20116. options: options
  20117. };
  20118. };
  20119. /**
  20120. * @author mrdoob / http://mrdoob.com/
  20121. * @author alteredq / http://alteredqualia.com/
  20122. */
  20123. THREE.JSONLoader = function ( showStatus ) {
  20124. THREE.Loader.call( this, showStatus );
  20125. };
  20126. THREE.JSONLoader.prototype = new THREE.Loader();
  20127. THREE.JSONLoader.prototype.constructor = THREE.JSONLoader;
  20128. THREE.JSONLoader.prototype.supr = THREE.Loader.prototype;
  20129. THREE.JSONLoader.prototype.load = function ( url, callback, texturePath ) {
  20130. var worker, scope = this;
  20131. texturePath = texturePath ? texturePath : this.extractUrlBase( url );
  20132. this.onLoadStart();
  20133. this.loadAjaxJSON( this, url, callback, texturePath );
  20134. };
  20135. THREE.JSONLoader.prototype.loadAjaxJSON = function ( context, url, callback, texturePath, callbackProgress ) {
  20136. var xhr = new XMLHttpRequest();
  20137. var length = 0;
  20138. xhr.onreadystatechange = function () {
  20139. if ( xhr.readyState === xhr.DONE ) {
  20140. if ( xhr.status === 200 || xhr.status === 0 ) {
  20141. if ( xhr.responseText ) {
  20142. var json = JSON.parse( xhr.responseText );
  20143. context.createModel( json, callback, texturePath );
  20144. } else {
  20145. console.warn( "THREE.JSONLoader: [" + url + "] seems to be unreachable or file there is empty" );
  20146. }
  20147. // in context of more complex asset initialization
  20148. // do not block on single failed file
  20149. // maybe should go even one more level up
  20150. context.onLoadComplete();
  20151. } else {
  20152. console.error( "THREE.JSONLoader: Couldn't load [" + url + "] [" + xhr.status + "]" );
  20153. }
  20154. } else if ( xhr.readyState === xhr.LOADING ) {
  20155. if ( callbackProgress ) {
  20156. if ( length === 0 ) {
  20157. length = xhr.getResponseHeader( "Content-Length" );
  20158. }
  20159. callbackProgress( { total: length, loaded: xhr.responseText.length } );
  20160. }
  20161. } else if ( xhr.readyState === xhr.HEADERS_RECEIVED ) {
  20162. length = xhr.getResponseHeader( "Content-Length" );
  20163. }
  20164. };
  20165. xhr.open( "GET", url, true );
  20166. if ( xhr.overrideMimeType ) xhr.overrideMimeType( "text/plain; charset=x-user-defined" );
  20167. xhr.setRequestHeader( "Content-Type", "text/plain" );
  20168. xhr.send( null );
  20169. };
  20170. THREE.JSONLoader.prototype.createModel = function ( json, callback, texturePath ) {
  20171. var scope = this,
  20172. geometry = new THREE.Geometry(),
  20173. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  20174. this.initMaterials( geometry, json.materials, texturePath );
  20175. parseModel( scale );
  20176. parseSkin();
  20177. parseMorphing( scale );
  20178. geometry.computeCentroids();
  20179. geometry.computeFaceNormals();
  20180. if ( this.hasNormals( geometry ) ) geometry.computeTangents();
  20181. function parseModel( scale ) {
  20182. function isBitSet( value, position ) {
  20183. return value & ( 1 << position );
  20184. }
  20185. var i, j, fi,
  20186. offset, zLength, nVertices,
  20187. colorIndex, normalIndex, uvIndex, materialIndex,
  20188. type,
  20189. isQuad,
  20190. hasMaterial,
  20191. hasFaceUv, hasFaceVertexUv,
  20192. hasFaceNormal, hasFaceVertexNormal,
  20193. hasFaceColor, hasFaceVertexColor,
  20194. vertex, face, color, normal,
  20195. uvLayer, uvs, u, v,
  20196. faces = json.faces,
  20197. vertices = json.vertices,
  20198. normals = json.normals,
  20199. colors = json.colors,
  20200. nUvLayers = 0;
  20201. // disregard empty arrays
  20202. for ( i = 0; i < json.uvs.length; i++ ) {
  20203. if ( json.uvs[ i ].length ) nUvLayers ++;
  20204. }
  20205. for ( i = 0; i < nUvLayers; i++ ) {
  20206. geometry.faceUvs[ i ] = [];
  20207. geometry.faceVertexUvs[ i ] = [];
  20208. }
  20209. offset = 0;
  20210. zLength = vertices.length;
  20211. while ( offset < zLength ) {
  20212. vertex = new THREE.Vector3();
  20213. vertex.x = vertices[ offset ++ ] * scale;
  20214. vertex.y = vertices[ offset ++ ] * scale;
  20215. vertex.z = vertices[ offset ++ ] * scale;
  20216. geometry.vertices.push( vertex );
  20217. }
  20218. offset = 0;
  20219. zLength = faces.length;
  20220. while ( offset < zLength ) {
  20221. type = faces[ offset ++ ];
  20222. isQuad = isBitSet( type, 0 );
  20223. hasMaterial = isBitSet( type, 1 );
  20224. hasFaceUv = isBitSet( type, 2 );
  20225. hasFaceVertexUv = isBitSet( type, 3 );
  20226. hasFaceNormal = isBitSet( type, 4 );
  20227. hasFaceVertexNormal = isBitSet( type, 5 );
  20228. hasFaceColor = isBitSet( type, 6 );
  20229. hasFaceVertexColor = isBitSet( type, 7 );
  20230. //console.log("type", type, "bits", isQuad, hasMaterial, hasFaceUv, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  20231. if ( isQuad ) {
  20232. face = new THREE.Face4();
  20233. face.a = faces[ offset ++ ];
  20234. face.b = faces[ offset ++ ];
  20235. face.c = faces[ offset ++ ];
  20236. face.d = faces[ offset ++ ];
  20237. nVertices = 4;
  20238. } else {
  20239. face = new THREE.Face3();
  20240. face.a = faces[ offset ++ ];
  20241. face.b = faces[ offset ++ ];
  20242. face.c = faces[ offset ++ ];
  20243. nVertices = 3;
  20244. }
  20245. if ( hasMaterial ) {
  20246. materialIndex = faces[ offset ++ ];
  20247. face.materialIndex = materialIndex;
  20248. }
  20249. // to get face <=> uv index correspondence
  20250. fi = geometry.faces.length;
  20251. if ( hasFaceUv ) {
  20252. for ( i = 0; i < nUvLayers; i++ ) {
  20253. uvLayer = json.uvs[ i ];
  20254. uvIndex = faces[ offset ++ ];
  20255. u = uvLayer[ uvIndex * 2 ];
  20256. v = uvLayer[ uvIndex * 2 + 1 ];
  20257. geometry.faceUvs[ i ][ fi ] = new THREE.UV( u, v );
  20258. }
  20259. }
  20260. if ( hasFaceVertexUv ) {
  20261. for ( i = 0; i < nUvLayers; i++ ) {
  20262. uvLayer = json.uvs[ i ];
  20263. uvs = [];
  20264. for ( j = 0; j < nVertices; j ++ ) {
  20265. uvIndex = faces[ offset ++ ];
  20266. u = uvLayer[ uvIndex * 2 ];
  20267. v = uvLayer[ uvIndex * 2 + 1 ];
  20268. uvs[ j ] = new THREE.UV( u, v );
  20269. }
  20270. geometry.faceVertexUvs[ i ][ fi ] = uvs;
  20271. }
  20272. }
  20273. if ( hasFaceNormal ) {
  20274. normalIndex = faces[ offset ++ ] * 3;
  20275. normal = new THREE.Vector3();
  20276. normal.x = normals[ normalIndex ++ ];
  20277. normal.y = normals[ normalIndex ++ ];
  20278. normal.z = normals[ normalIndex ];
  20279. face.normal = normal;
  20280. }
  20281. if ( hasFaceVertexNormal ) {
  20282. for ( i = 0; i < nVertices; i++ ) {
  20283. normalIndex = faces[ offset ++ ] * 3;
  20284. normal = new THREE.Vector3();
  20285. normal.x = normals[ normalIndex ++ ];
  20286. normal.y = normals[ normalIndex ++ ];
  20287. normal.z = normals[ normalIndex ];
  20288. face.vertexNormals.push( normal );
  20289. }
  20290. }
  20291. if ( hasFaceColor ) {
  20292. colorIndex = faces[ offset ++ ];
  20293. color = new THREE.Color( colors[ colorIndex ] );
  20294. face.color = color;
  20295. }
  20296. if ( hasFaceVertexColor ) {
  20297. for ( i = 0; i < nVertices; i++ ) {
  20298. colorIndex = faces[ offset ++ ];
  20299. color = new THREE.Color( colors[ colorIndex ] );
  20300. face.vertexColors.push( color );
  20301. }
  20302. }
  20303. geometry.faces.push( face );
  20304. }
  20305. };
  20306. function parseSkin() {
  20307. var i, l, x, y, z, w, a, b, c, d;
  20308. if ( json.skinWeights ) {
  20309. for ( i = 0, l = json.skinWeights.length; i < l; i += 2 ) {
  20310. x = json.skinWeights[ i ];
  20311. y = json.skinWeights[ i + 1 ];
  20312. z = 0;
  20313. w = 0;
  20314. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  20315. }
  20316. }
  20317. if ( json.skinIndices ) {
  20318. for ( i = 0, l = json.skinIndices.length; i < l; i += 2 ) {
  20319. a = json.skinIndices[ i ];
  20320. b = json.skinIndices[ i + 1 ];
  20321. c = 0;
  20322. d = 0;
  20323. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  20324. }
  20325. }
  20326. geometry.bones = json.bones;
  20327. geometry.animation = json.animation;
  20328. };
  20329. function parseMorphing( scale ) {
  20330. if ( json.morphTargets !== undefined ) {
  20331. var i, l, v, vl, dstVertices, srcVertices;
  20332. for ( i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  20333. geometry.morphTargets[ i ] = {};
  20334. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  20335. geometry.morphTargets[ i ].vertices = [];
  20336. dstVertices = geometry.morphTargets[ i ].vertices;
  20337. srcVertices = json.morphTargets [ i ].vertices;
  20338. for( v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  20339. var vertex = new THREE.Vector3();
  20340. vertex.x = srcVertices[ v ] * scale;
  20341. vertex.y = srcVertices[ v + 1 ] * scale;
  20342. vertex.z = srcVertices[ v + 2 ] * scale;
  20343. dstVertices.push( vertex );
  20344. }
  20345. }
  20346. }
  20347. if ( json.morphColors !== undefined ) {
  20348. var i, l, c, cl, dstColors, srcColors, color;
  20349. for ( i = 0, l = json.morphColors.length; i < l; i++ ) {
  20350. geometry.morphColors[ i ] = {};
  20351. geometry.morphColors[ i ].name = json.morphColors[ i ].name;
  20352. geometry.morphColors[ i ].colors = [];
  20353. dstColors = geometry.morphColors[ i ].colors;
  20354. srcColors = json.morphColors [ i ].colors;
  20355. for ( c = 0, cl = srcColors.length; c < cl; c += 3 ) {
  20356. color = new THREE.Color( 0xffaa00 );
  20357. color.setRGB( srcColors[ c ], srcColors[ c + 1 ], srcColors[ c + 2 ] );
  20358. dstColors.push( color );
  20359. }
  20360. }
  20361. }
  20362. };
  20363. callback( geometry );
  20364. };
  20365. /**
  20366. * @author alteredq / http://alteredqualia.com/
  20367. */
  20368. THREE.SceneLoader = function () {
  20369. this.onLoadStart = function () {};
  20370. this.onLoadProgress = function() {};
  20371. this.onLoadComplete = function () {};
  20372. this.callbackSync = function () {};
  20373. this.callbackProgress = function () {};
  20374. };
  20375. THREE.SceneLoader.prototype.constructor = THREE.SceneLoader;
  20376. THREE.SceneLoader.prototype.load = function( url, callbackFinished ) {
  20377. var context = this;
  20378. var xhr = new XMLHttpRequest();
  20379. xhr.onreadystatechange = function () {
  20380. if ( xhr.readyState == 4 ) {
  20381. if ( xhr.status == 200 || xhr.status == 0 ) {
  20382. var json = JSON.parse( xhr.responseText );
  20383. context.createScene( json, callbackFinished, url );
  20384. } else {
  20385. console.error( "THREE.SceneLoader: Couldn't load [" + url + "] [" + xhr.status + "]" );
  20386. }
  20387. }
  20388. };
  20389. xhr.open( "GET", url, true );
  20390. if ( xhr.overrideMimeType ) xhr.overrideMimeType( "text/plain; charset=x-user-defined" );
  20391. xhr.setRequestHeader( "Content-Type", "text/plain" );
  20392. xhr.send( null );
  20393. };
  20394. THREE.SceneLoader.prototype.createScene = function ( json, callbackFinished, url ) {
  20395. var scope = this;
  20396. var urlBase = THREE.Loader.prototype.extractUrlBase( url );
  20397. var dg, dm, dd, dl, dc, df, dt,
  20398. g, o, m, l, d, p, r, q, s, c, t, f, tt, pp, u,
  20399. geometry, material, camera, fog,
  20400. texture, images,
  20401. light,
  20402. data, binLoader, jsonLoader,
  20403. counter_models, counter_textures,
  20404. total_models, total_textures,
  20405. result;
  20406. data = json;
  20407. binLoader = new THREE.BinaryLoader();
  20408. jsonLoader = new THREE.JSONLoader();
  20409. counter_models = 0;
  20410. counter_textures = 0;
  20411. result = {
  20412. scene: new THREE.Scene(),
  20413. geometries: {},
  20414. materials: {},
  20415. textures: {},
  20416. objects: {},
  20417. cameras: {},
  20418. lights: {},
  20419. fogs: {},
  20420. empties: {}
  20421. };
  20422. if ( data.transform ) {
  20423. var position = data.transform.position,
  20424. rotation = data.transform.rotation,
  20425. scale = data.transform.scale;
  20426. if ( position )
  20427. result.scene.position.set( position[ 0 ], position[ 1 ], position [ 2 ] );
  20428. if ( rotation )
  20429. result.scene.rotation.set( rotation[ 0 ], rotation[ 1 ], rotation [ 2 ] );
  20430. if ( scale )
  20431. result.scene.scale.set( scale[ 0 ], scale[ 1 ], scale [ 2 ] );
  20432. if ( position || rotation || scale ) {
  20433. result.scene.updateMatrix();
  20434. result.scene.updateMatrixWorld();
  20435. }
  20436. }
  20437. function get_url( source_url, url_type ) {
  20438. if ( url_type == "relativeToHTML" ) {
  20439. return source_url;
  20440. } else {
  20441. return urlBase + "/" + source_url;
  20442. }
  20443. };
  20444. function handle_objects() {
  20445. var object;
  20446. for( dd in data.objects ) {
  20447. if ( !result.objects[ dd ] ) {
  20448. o = data.objects[ dd ];
  20449. if ( o.geometry !== undefined ) {
  20450. geometry = result.geometries[ o.geometry ];
  20451. // geometry already loaded
  20452. if ( geometry ) {
  20453. var hasNormals = false;
  20454. // not anymore support for multiple materials
  20455. // shouldn't really be array
  20456. material = result.materials[ o.materials[ 0 ] ];
  20457. hasNormals = material instanceof THREE.ShaderMaterial;
  20458. if ( hasNormals ) {
  20459. geometry.computeTangents();
  20460. }
  20461. p = o.position;
  20462. r = o.rotation;
  20463. q = o.quaternion;
  20464. s = o.scale;
  20465. m = o.matrix;
  20466. // turn off quaternions, for the moment
  20467. q = 0;
  20468. if ( o.materials.length == 0 ) {
  20469. material = new THREE.MeshFaceMaterial();
  20470. }
  20471. // dirty hack to handle meshes with multiple materials
  20472. // just use face materials defined in model
  20473. if ( o.materials.length > 1 ) {
  20474. material = new THREE.MeshFaceMaterial();
  20475. }
  20476. object = new THREE.Mesh( geometry, material );
  20477. object.name = dd;
  20478. if ( m ) {
  20479. object.matrixAutoUpdate = false;
  20480. object.matrix.set( m[0], m[1], m[2], m[3],
  20481. m[4], m[5], m[6], m[7],
  20482. m[8], m[9], m[10], m[11],
  20483. m[12], m[13], m[14], m[15]);
  20484. } else {
  20485. object.position.set( p[0], p[1], p[2] );
  20486. if ( q ) {
  20487. object.quaternion.set( q[0], q[1], q[2], q[3] );
  20488. object.useQuaternion = true;
  20489. } else {
  20490. object.rotation.set( r[0], r[1], r[2] );
  20491. }
  20492. object.scale.set( s[0], s[1], s[2] );
  20493. }
  20494. object.visible = o.visible;
  20495. object.doubleSided = o.doubleSided;
  20496. object.castShadow = o.castShadow;
  20497. object.receiveShadow = o.receiveShadow;
  20498. result.scene.add( object );
  20499. result.objects[ dd ] = object;
  20500. }
  20501. // pure Object3D
  20502. } else {
  20503. p = o.position;
  20504. r = o.rotation;
  20505. q = o.quaternion;
  20506. s = o.scale;
  20507. // turn off quaternions, for the moment
  20508. q = 0;
  20509. object = new THREE.Object3D();
  20510. object.name = dd;
  20511. object.position.set( p[0], p[1], p[2] );
  20512. if ( q ) {
  20513. object.quaternion.set( q[0], q[1], q[2], q[3] );
  20514. object.useQuaternion = true;
  20515. } else {
  20516. object.rotation.set( r[0], r[1], r[2] );
  20517. }
  20518. object.scale.set( s[0], s[1], s[2] );
  20519. object.visible = ( o.visible !== undefined ) ? o.visible : false;
  20520. result.scene.add( object );
  20521. result.objects[ dd ] = object;
  20522. result.empties[ dd ] = object;
  20523. }
  20524. }
  20525. }
  20526. };
  20527. function handle_mesh( geo, id ) {
  20528. result.geometries[ id ] = geo;
  20529. handle_objects();
  20530. };
  20531. function create_callback( id ) {
  20532. return function( geo ) {
  20533. handle_mesh( geo, id );
  20534. counter_models -= 1;
  20535. scope.onLoadComplete();
  20536. async_callback_gate();
  20537. }
  20538. };
  20539. function create_callback_embed( id ) {
  20540. return function( geo ) {
  20541. result.geometries[ id ] = geo;
  20542. }
  20543. };
  20544. function async_callback_gate() {
  20545. var progress = {
  20546. totalModels : total_models,
  20547. totalTextures : total_textures,
  20548. loadedModels : total_models - counter_models,
  20549. loadedTextures : total_textures - counter_textures
  20550. };
  20551. scope.callbackProgress( progress, result );
  20552. scope.onLoadProgress();
  20553. if( counter_models == 0 && counter_textures == 0 ) {
  20554. callbackFinished( result );
  20555. }
  20556. };
  20557. var callbackTexture = function( images ) {
  20558. counter_textures -= 1;
  20559. async_callback_gate();
  20560. scope.onLoadComplete();
  20561. };
  20562. // first go synchronous elements
  20563. // cameras
  20564. for( dc in data.cameras ) {
  20565. c = data.cameras[ dc ];
  20566. if ( c.type == "perspective" ) {
  20567. camera = new THREE.PerspectiveCamera( c.fov, c.aspect, c.near, c.far );
  20568. } else if ( c.type == "ortho" ) {
  20569. camera = new THREE.OrthographicCamera( c.left, c.right, c.top, c.bottom, c.near, c.far );
  20570. }
  20571. p = c.position;
  20572. t = c.target;
  20573. u = c.up;
  20574. camera.position.set( p[0], p[1], p[2] );
  20575. camera.target = new THREE.Vector3( t[0], t[1], t[2] );
  20576. if ( u ) camera.up.set( u[0], u[1], u[2] );
  20577. result.cameras[ dc ] = camera;
  20578. }
  20579. // lights
  20580. var hex, intensity;
  20581. for ( dl in data.lights ) {
  20582. l = data.lights[ dl ];
  20583. hex = ( l.color !== undefined ) ? l.color : 0xffffff;
  20584. intensity = ( l.intensity !== undefined ) ? l.intensity : 1;
  20585. if ( l.type == "directional" ) {
  20586. p = l.direction;
  20587. light = new THREE.DirectionalLight( hex, intensity );
  20588. light.position.set( p[0], p[1], p[2] );
  20589. light.position.normalize();
  20590. } else if ( l.type == "point" ) {
  20591. p = l.position;
  20592. d = l.distance;
  20593. light = new THREE.PointLight( hex, intensity, d );
  20594. light.position.set( p[0], p[1], p[2] );
  20595. } else if ( l.type == "ambient" ) {
  20596. light = new THREE.AmbientLight( hex );
  20597. }
  20598. result.scene.add( light );
  20599. result.lights[ dl ] = light;
  20600. }
  20601. // fogs
  20602. for( df in data.fogs ) {
  20603. f = data.fogs[ df ];
  20604. if ( f.type == "linear" ) {
  20605. fog = new THREE.Fog( 0x000000, f.near, f.far );
  20606. } else if ( f.type == "exp2" ) {
  20607. fog = new THREE.FogExp2( 0x000000, f.density );
  20608. }
  20609. c = f.color;
  20610. fog.color.setRGB( c[0], c[1], c[2] );
  20611. result.fogs[ df ] = fog;
  20612. }
  20613. // defaults
  20614. if ( result.cameras && data.defaults.camera ) {
  20615. result.currentCamera = result.cameras[ data.defaults.camera ];
  20616. }
  20617. if ( result.fogs && data.defaults.fog ) {
  20618. result.scene.fog = result.fogs[ data.defaults.fog ];
  20619. }
  20620. c = data.defaults.bgcolor;
  20621. result.bgColor = new THREE.Color();
  20622. result.bgColor.setRGB( c[0], c[1], c[2] );
  20623. result.bgColorAlpha = data.defaults.bgalpha;
  20624. // now come potentially asynchronous elements
  20625. // geometries
  20626. // count how many models will be loaded asynchronously
  20627. for( dg in data.geometries ) {
  20628. g = data.geometries[ dg ];
  20629. if ( g.type == "bin_mesh" || g.type == "ascii_mesh" ) {
  20630. counter_models += 1;
  20631. scope.onLoadStart();
  20632. }
  20633. }
  20634. total_models = counter_models;
  20635. for ( dg in data.geometries ) {
  20636. g = data.geometries[ dg ];
  20637. if ( g.type == "cube" ) {
  20638. geometry = new THREE.CubeGeometry( g.width, g.height, g.depth, g.segmentsWidth, g.segmentsHeight, g.segmentsDepth, null, g.flipped, g.sides );
  20639. result.geometries[ dg ] = geometry;
  20640. } else if ( g.type == "plane" ) {
  20641. geometry = new THREE.PlaneGeometry( g.width, g.height, g.segmentsWidth, g.segmentsHeight );
  20642. result.geometries[ dg ] = geometry;
  20643. } else if ( g.type == "sphere" ) {
  20644. geometry = new THREE.SphereGeometry( g.radius, g.segmentsWidth, g.segmentsHeight );
  20645. result.geometries[ dg ] = geometry;
  20646. } else if ( g.type == "cylinder" ) {
  20647. geometry = new THREE.CylinderGeometry( g.topRad, g.botRad, g.height, g.radSegs, g.heightSegs );
  20648. result.geometries[ dg ] = geometry;
  20649. } else if ( g.type == "torus" ) {
  20650. geometry = new THREE.TorusGeometry( g.radius, g.tube, g.segmentsR, g.segmentsT );
  20651. result.geometries[ dg ] = geometry;
  20652. } else if ( g.type == "icosahedron" ) {
  20653. geometry = new THREE.IcosahedronGeometry( g.radius, g.subdivisions );
  20654. result.geometries[ dg ] = geometry;
  20655. } else if ( g.type == "bin_mesh" ) {
  20656. binLoader.load( get_url( g.url, data.urlBaseType ), create_callback( dg ) );
  20657. } else if ( g.type == "ascii_mesh" ) {
  20658. jsonLoader.load( get_url( g.url, data.urlBaseType ), create_callback( dg ) );
  20659. } else if ( g.type == "embedded_mesh" ) {
  20660. var modelJson = data.embeds[ g.id ],
  20661. texture_path = "";
  20662. // Pass metadata along to jsonLoader so it knows the format version.
  20663. modelJson.metadata = data.metadata;
  20664. if ( modelJson ) {
  20665. jsonLoader.createModel( modelJson, create_callback_embed( dg ), texture_path );
  20666. }
  20667. }
  20668. }
  20669. // textures
  20670. // count how many textures will be loaded asynchronously
  20671. for( dt in data.textures ) {
  20672. tt = data.textures[ dt ];
  20673. if( tt.url instanceof Array ) {
  20674. counter_textures += tt.url.length;
  20675. for( var n = 0; n < tt.url.length; n ++ ) {
  20676. scope.onLoadStart();
  20677. }
  20678. } else {
  20679. counter_textures += 1;
  20680. scope.onLoadStart();
  20681. }
  20682. }
  20683. total_textures = counter_textures;
  20684. for( dt in data.textures ) {
  20685. tt = data.textures[ dt ];
  20686. if ( tt.mapping != undefined && THREE[ tt.mapping ] != undefined ) {
  20687. tt.mapping = new THREE[ tt.mapping ]();
  20688. }
  20689. if( tt.url instanceof Array ) {
  20690. var url_array = [];
  20691. for( var i = 0; i < tt.url.length; i ++ ) {
  20692. url_array[ i ] = get_url( tt.url[ i ], data.urlBaseType );
  20693. }
  20694. texture = THREE.ImageUtils.loadTextureCube( url_array, tt.mapping, callbackTexture );
  20695. } else {
  20696. texture = THREE.ImageUtils.loadTexture( get_url( tt.url, data.urlBaseType ), tt.mapping, callbackTexture );
  20697. if ( THREE[ tt.minFilter ] != undefined )
  20698. texture.minFilter = THREE[ tt.minFilter ];
  20699. if ( THREE[ tt.magFilter ] != undefined )
  20700. texture.magFilter = THREE[ tt.magFilter ];
  20701. if ( tt.repeat ) {
  20702. texture.repeat.set( tt.repeat[ 0 ], tt.repeat[ 1 ] );
  20703. if ( tt.repeat[ 0 ] != 1 ) texture.wrapS = THREE.RepeatWrapping;
  20704. if ( tt.repeat[ 1 ] != 1 ) texture.wrapT = THREE.RepeatWrapping;
  20705. }
  20706. if ( tt.offset ) {
  20707. texture.offset.set( tt.offset[ 0 ], tt.offset[ 1 ] );
  20708. }
  20709. // handle wrap after repeat so that default repeat can be overriden
  20710. if ( tt.wrap ) {
  20711. var wrapMap = {
  20712. "repeat" : THREE.RepeatWrapping,
  20713. "mirror" : THREE.MirroredRepeatWrapping
  20714. }
  20715. if ( wrapMap[ tt.wrap[ 0 ] ] !== undefined ) texture.wrapS = wrapMap[ tt.wrap[ 0 ] ];
  20716. if ( wrapMap[ tt.wrap[ 1 ] ] !== undefined ) texture.wrapT = wrapMap[ tt.wrap[ 1 ] ];
  20717. }
  20718. }
  20719. result.textures[ dt ] = texture;
  20720. }
  20721. // materials
  20722. for ( dm in data.materials ) {
  20723. m = data.materials[ dm ];
  20724. for ( pp in m.parameters ) {
  20725. if ( pp == "envMap" || pp == "map" || pp == "lightMap" ) {
  20726. m.parameters[ pp ] = result.textures[ m.parameters[ pp ] ];
  20727. } else if ( pp == "shading" ) {
  20728. m.parameters[ pp ] = ( m.parameters[ pp ] == "flat" ) ? THREE.FlatShading : THREE.SmoothShading;
  20729. } else if ( pp == "blending" ) {
  20730. m.parameters[ pp ] = THREE[ m.parameters[ pp ] ] ? THREE[ m.parameters[ pp ] ] : THREE.NormalBlending;
  20731. } else if ( pp == "combine" ) {
  20732. m.parameters[ pp ] = ( m.parameters[ pp ] == "MixOperation" ) ? THREE.MixOperation : THREE.MultiplyOperation;
  20733. } else if ( pp == "vertexColors" ) {
  20734. if ( m.parameters[ pp ] == "face" ) {
  20735. m.parameters[ pp ] = THREE.FaceColors;
  20736. // default to vertex colors if "vertexColors" is anything else face colors or 0 / null / false
  20737. } else if ( m.parameters[ pp ] ) {
  20738. m.parameters[ pp ] = THREE.VertexColors;
  20739. }
  20740. }
  20741. }
  20742. if ( m.parameters.opacity !== undefined && m.parameters.opacity < 1.0 ) {
  20743. m.parameters.transparent = true;
  20744. }
  20745. if ( m.parameters.normalMap ) {
  20746. var shader = THREE.ShaderUtils.lib[ "normal" ];
  20747. var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
  20748. var diffuse = m.parameters.color;
  20749. var specular = m.parameters.specular;
  20750. var ambient = m.parameters.ambient;
  20751. var shininess = m.parameters.shininess;
  20752. uniforms[ "tNormal" ].texture = result.textures[ m.parameters.normalMap ];
  20753. if ( m.parameters.normalMapFactor ) {
  20754. uniforms[ "uNormalScale" ].value = m.parameters.normalMapFactor;
  20755. }
  20756. if ( m.parameters.map ) {
  20757. uniforms[ "tDiffuse" ].texture = m.parameters.map;
  20758. uniforms[ "enableDiffuse" ].value = true;
  20759. }
  20760. if ( m.parameters.lightMap ) {
  20761. uniforms[ "tAO" ].texture = m.parameters.lightMap;
  20762. uniforms[ "enableAO" ].value = true;
  20763. }
  20764. if ( m.parameters.specularMap ) {
  20765. uniforms[ "tSpecular" ].texture = result.textures[ m.parameters.specularMap ];
  20766. uniforms[ "enableSpecular" ].value = true;
  20767. }
  20768. uniforms[ "uDiffuseColor" ].value.setHex( diffuse );
  20769. uniforms[ "uSpecularColor" ].value.setHex( specular );
  20770. uniforms[ "uAmbientColor" ].value.setHex( ambient );
  20771. uniforms[ "uShininess" ].value = shininess;
  20772. if ( m.parameters.opacity ) {
  20773. uniforms[ "uOpacity" ].value = m.parameters.opacity;
  20774. }
  20775. var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true, fog: true };
  20776. material = new THREE.ShaderMaterial( parameters );
  20777. } else {
  20778. material = new THREE[ m.type ]( m.parameters );
  20779. }
  20780. result.materials[ dm ] = material;
  20781. }
  20782. // objects ( synchronous init of procedural primitives )
  20783. handle_objects();
  20784. // synchronous callback
  20785. scope.callbackSync( result );
  20786. // just in case there are no async elements:
  20787. async_callback_gate();
  20788. };
  20789. /**
  20790. * Loader for UTF8 encoded models generated by:
  20791. * http://code.google.com/p/webgl-loader/
  20792. *
  20793. * Limitations:
  20794. * - number of vertices < 65536 (this is after optimizations in compressor, input OBJ may have even less)
  20795. * - models must have normals and texture coordinates
  20796. * - texture coordinates must be only from <0,1>
  20797. * - no materials support yet
  20798. * - models are scaled and offset (copy numbers from compressor and use them as parameters in UTF8Loader.load() )
  20799. *
  20800. * @author alteredq / http://alteredqualia.com/
  20801. * @author won3d / http://twitter.com/won3d
  20802. */
  20803. THREE.UTF8Loader = function () {};
  20804. THREE.UTF8Loader.prototype.load = function ( url, callback, metadata ) {
  20805. var xhr = new XMLHttpRequest(),
  20806. callbackProgress = null,
  20807. scale = metadata.scale !== undefined ? metadata.scale : 1,
  20808. offsetX = metadata.offsetX !== undefined ? metadata.offsetX : 0,
  20809. offsetY = metadata.offsetY !== undefined ? metadata.offsetY : 0,
  20810. offsetZ = metadata.offsetZ !== undefined ? metadata.offsetZ : 0;
  20811. var length = 0;
  20812. xhr.onreadystatechange = function() {
  20813. if ( xhr.readyState == 4 ) {
  20814. if ( xhr.status == 200 || xhr.status == 0 ) {
  20815. THREE.UTF8Loader.prototype.createModel( xhr.responseText, callback, scale, offsetX, offsetY, offsetZ );
  20816. } else {
  20817. console.error( "THREE.UTF8Loader: Couldn't load [" + url + "] [" + xhr.status + "]" );
  20818. }
  20819. } else if ( xhr.readyState == 3 ) {
  20820. if ( callbackProgress ) {
  20821. if ( length == 0 ) {
  20822. length = xhr.getResponseHeader( "Content-Length" );
  20823. }
  20824. callbackProgress( { total: length, loaded: xhr.responseText.length } );
  20825. }
  20826. } else if ( xhr.readyState == 2 ) {
  20827. length = xhr.getResponseHeader( "Content-Length" );
  20828. }
  20829. }
  20830. xhr.open( "GET", url, true );
  20831. xhr.send( null );
  20832. };
  20833. // UTF-8 decoder from webgl-loader
  20834. // http://code.google.com/p/webgl-loader/
  20835. // Copyright 2011 Google Inc. All Rights Reserved.
  20836. //
  20837. // Licensed under the Apache License, Version 2.0 (the "License"); you
  20838. // may not use this file except in compliance with the License. You
  20839. // may obtain a copy of the License at
  20840. //
  20841. // http://www.apache.org/licenses/LICENSE-2.0
  20842. //
  20843. // Unless required by applicable law or agreed to in writing, software
  20844. // distributed under the License is distributed on an "AS IS" BASIS,
  20845. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  20846. // implied. See the License for the specific language governing
  20847. // permissions and limitations under the License.
  20848. THREE.UTF8Loader.prototype.decompressMesh = function ( str ) {
  20849. var num_verts = str.charCodeAt( 0 );
  20850. if ( num_verts >= 0xE000 ) {
  20851. num_verts -= 0x0800;
  20852. }
  20853. num_verts ++;
  20854. var attribs_out = new Float32Array( 8 * num_verts );
  20855. var offset = 1;
  20856. for ( var i = 0; i < 8; i ++ ) {
  20857. var prev_attrib = 0;
  20858. for ( var j = 0; j < num_verts; ++ j ) {
  20859. var code = str.charCodeAt( j + offset );
  20860. prev_attrib += ( code >> 1 ) ^ ( - ( code & 1 ) );
  20861. attribs_out[ 8 * j + i ] = prev_attrib;
  20862. }
  20863. offset += num_verts;
  20864. }
  20865. var num_indices = str.length - offset;
  20866. var indices_out = new Uint16Array( num_indices );
  20867. var index_high_water_mark = 0;
  20868. for ( var i = 0; i < num_indices; i ++ ) {
  20869. var code = str.charCodeAt( i + offset );
  20870. indices_out[ i ] = index_high_water_mark - code;
  20871. if ( code == 0 ) {
  20872. index_high_water_mark ++;
  20873. }
  20874. }
  20875. return [ attribs_out, indices_out ];
  20876. };
  20877. THREE.UTF8Loader.prototype.createModel = function ( data, callback, scale, offsetX, offsetY, offsetZ ) {
  20878. var Model = function ( texture_path ) {
  20879. //var s = (new Date).getTime();
  20880. var scope = this;
  20881. scope.materials = [];
  20882. THREE.Geometry.call( this );
  20883. var buffers = THREE.UTF8Loader.prototype.decompressMesh( data );
  20884. var normals = [],
  20885. uvs = [];
  20886. init_vertices( buffers[ 0 ], 8, 0 );
  20887. init_uvs( buffers[ 0 ], 8, 3 );
  20888. init_normals( buffers[ 0 ], 8, 5 );
  20889. init_faces( buffers[ 1 ] );
  20890. this.computeCentroids();
  20891. this.computeFaceNormals();
  20892. //this.computeTangents();
  20893. //var e = (new Date).getTime();
  20894. //console.log( "utf8 data parse time: " + (e-s) + " ms" );
  20895. function init_vertices( data, stride, offset ) {
  20896. var i, x, y, z,
  20897. end = data.length;
  20898. for( i = offset; i < end; i += stride ) {
  20899. x = data[ i ];
  20900. y = data[ i + 1 ];
  20901. z = data[ i + 2 ];
  20902. // fix scale and offsets
  20903. x = ( x / 16383 ) * scale;
  20904. y = ( y / 16383 ) * scale;
  20905. z = ( z / 16383 ) * scale;
  20906. x += offsetX;
  20907. y += offsetY;
  20908. z += offsetZ;
  20909. vertex( scope, x, y, z );
  20910. }
  20911. };
  20912. function init_normals( data, stride, offset ) {
  20913. var i, x, y, z,
  20914. end = data.length;
  20915. for( i = offset; i < end; i += stride ) {
  20916. x = data[ i ];
  20917. y = data[ i + 1 ];
  20918. z = data[ i + 2 ];
  20919. // normalize to <-1,1>
  20920. x = ( x - 512 ) / 511;
  20921. y = ( y - 512 ) / 511;
  20922. z = ( z - 512 ) / 511;
  20923. normals.push( x, y, z );
  20924. }
  20925. };
  20926. function init_uvs( data, stride, offset ) {
  20927. var i, u, v,
  20928. end = data.length;
  20929. for( i = offset; i < end; i += stride ) {
  20930. u = data[ i ];
  20931. v = data[ i + 1 ];
  20932. // normalize to <0,1>
  20933. u /= 1023;
  20934. v /= 1023;
  20935. uvs.push( u, 1 - v );
  20936. }
  20937. };
  20938. function init_faces( indices ) {
  20939. var i,
  20940. a, b, c,
  20941. u1, v1, u2, v2, u3, v3,
  20942. m,
  20943. end = indices.length;
  20944. m = 0; // all faces defaulting to material 0
  20945. for( i = 0; i < end; i += 3 ) {
  20946. a = indices[ i ];
  20947. b = indices[ i + 1 ];
  20948. c = indices[ i + 2 ];
  20949. f3n( scope, normals, a, b, c, m, a, b, c );
  20950. u1 = uvs[ a * 2 ];
  20951. v1 = uvs[ a * 2 + 1 ];
  20952. u2 = uvs[ b * 2 ];
  20953. v2 = uvs[ b * 2 + 1 ];
  20954. u3 = uvs[ c * 2 ];
  20955. v3 = uvs[ c * 2 + 1 ];
  20956. uv3( scope.faceVertexUvs[ 0 ], u1, v1, u2, v2, u3, v3 );
  20957. }
  20958. }
  20959. };
  20960. function vertex ( scope, x, y, z ) {
  20961. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  20962. };
  20963. function f3n ( scope, normals, a, b, c, mi, nai, nbi, nci ) {
  20964. var nax = normals[ nai * 3 ],
  20965. nay = normals[ nai * 3 + 1 ],
  20966. naz = normals[ nai * 3 + 2 ],
  20967. nbx = normals[ nbi * 3 ],
  20968. nby = normals[ nbi * 3 + 1 ],
  20969. nbz = normals[ nbi * 3 + 2 ],
  20970. ncx = normals[ nci * 3 ],
  20971. ncy = normals[ nci * 3 + 1 ],
  20972. ncz = normals[ nci * 3 + 2 ];
  20973. var na = new THREE.Vector3( nax, nay, naz ),
  20974. nb = new THREE.Vector3( nbx, nby, nbz ),
  20975. nc = new THREE.Vector3( ncx, ncy, ncz );
  20976. scope.faces.push( new THREE.Face3( a, b, c, [ na, nb, nc ], null, mi ) );
  20977. };
  20978. function uv3 ( where, u1, v1, u2, v2, u3, v3 ) {
  20979. var uv = [];
  20980. uv.push( new THREE.UV( u1, v1 ) );
  20981. uv.push( new THREE.UV( u2, v2 ) );
  20982. uv.push( new THREE.UV( u3, v3 ) );
  20983. where.push( uv );
  20984. };
  20985. Model.prototype = new THREE.Geometry();
  20986. Model.prototype.constructor = Model;
  20987. callback( new Model() );
  20988. };
  20989. /**
  20990. * @author alteredq / http://alteredqualia.com/
  20991. */
  20992. THREE.ImmediateRenderObject = function ( ) {
  20993. THREE.Object3D.call( this );
  20994. this.render = function( renderCallback ) {
  20995. };
  20996. };
  20997. THREE.ImmediateRenderObject.prototype = new THREE.Object3D();
  20998. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  20999. /**
  21000. * @author mikael emtinger / http://gomo.se/
  21001. * @author alteredq / http://alteredqualia.com/
  21002. */
  21003. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  21004. THREE.Object3D.call( this );
  21005. this.lensFlares = [];
  21006. this.positionScreen = new THREE.Vector3();
  21007. this.customUpdateCallback = undefined;
  21008. if( texture !== undefined ) {
  21009. this.add( texture, size, distance, blending, color );
  21010. }
  21011. };
  21012. THREE.LensFlare.prototype = new THREE.Object3D();
  21013. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  21014. THREE.LensFlare.prototype.supr = THREE.Object3D.prototype;
  21015. /*
  21016. * Add: adds another flare
  21017. */
  21018. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  21019. if( size === undefined ) size = -1;
  21020. if( distance === undefined ) distance = 0;
  21021. if( opacity === undefined ) opacity = 1;
  21022. if( color === undefined ) color = new THREE.Color( 0xffffff );
  21023. if( blending === undefined ) blending = THREE.NormalBlending;
  21024. distance = Math.min( distance, Math.max( 0, distance ) );
  21025. this.lensFlares.push( { texture: texture, // THREE.Texture
  21026. size: size, // size in pixels (-1 = use texture.width)
  21027. distance: distance, // distance (0-1) from light source (0=at light source)
  21028. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is ontop z = 1 is back
  21029. scale: 1, // scale
  21030. rotation: 1, // rotation
  21031. opacity: opacity, // opacity
  21032. color: color, // color
  21033. blending: blending } ); // blending
  21034. };
  21035. /*
  21036. * Update lens flares update positions on all flares based on the screen position
  21037. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  21038. */
  21039. THREE.LensFlare.prototype.updateLensFlares = function () {
  21040. var f, fl = this.lensFlares.length;
  21041. var flare;
  21042. var vecX = -this.positionScreen.x * 2;
  21043. var vecY = -this.positionScreen.y * 2;
  21044. for( f = 0; f < fl; f ++ ) {
  21045. flare = this.lensFlares[ f ];
  21046. flare.x = this.positionScreen.x + vecX * flare.distance;
  21047. flare.y = this.positionScreen.y + vecY * flare.distance;
  21048. flare.wantedRotation = flare.x * Math.PI * 0.25;
  21049. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  21050. }
  21051. };
  21052. /**
  21053. * @author alteredq / http://alteredqualia.com/
  21054. */
  21055. THREE.MorphBlendMesh = function( geometry, material ) {
  21056. THREE.Mesh.call( this, geometry, material );
  21057. this.animationsMap = {};
  21058. this.animationsList = [];
  21059. // prepare default animation
  21060. // (all frames played together in 1 second)
  21061. var numFrames = this.geometry.morphTargets.length;
  21062. var name = "__default";
  21063. var startFrame = 0;
  21064. var endFrame = numFrames - 1;
  21065. var fps = numFrames / 1;
  21066. this.createAnimation( name, startFrame, endFrame, fps );
  21067. this.setAnimationWeight( name, 1 );
  21068. };
  21069. THREE.MorphBlendMesh.prototype = new THREE.Mesh();
  21070. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  21071. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  21072. var animation = {
  21073. startFrame: start,
  21074. endFrame: end,
  21075. length: end - start + 1,
  21076. fps: fps,
  21077. duration: ( end - start ) / fps,
  21078. lastFrame: 0,
  21079. currentFrame: 0,
  21080. active: false,
  21081. time: 0,
  21082. direction: 1,
  21083. weight: 1,
  21084. directionBackwards: false,
  21085. mirroredLoop: false
  21086. };
  21087. this.animationsMap[ name ] = animation;
  21088. this.animationsList.push( animation );
  21089. };
  21090. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  21091. var pattern = /([a-z]+)(\d+)/;
  21092. var firstAnimation, frameRanges = {};
  21093. var geometry = this.geometry;
  21094. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  21095. var morph = geometry.morphTargets[ i ];
  21096. var chunks = morph.name.match( pattern );
  21097. if ( chunks && chunks.length > 1 ) {
  21098. var name = chunks[ 1 ];
  21099. var num = chunks[ 2 ];
  21100. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: -Infinity };
  21101. var range = frameRanges[ name ];
  21102. if ( i < range.start ) range.start = i;
  21103. if ( i > range.end ) range.end = i;
  21104. if ( ! firstAnimation ) firstAnimation = name;
  21105. }
  21106. }
  21107. for ( var name in frameRanges ) {
  21108. var range = frameRanges[ name ];
  21109. this.createAnimation( name, range.start, range.end, fps );
  21110. }
  21111. this.firstAnimation = firstAnimation;
  21112. };
  21113. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  21114. var animation = this.animationsMap[ name ];
  21115. if ( animation ) {
  21116. animation.direction = 1;
  21117. animation.directionBackwards = false;
  21118. }
  21119. };
  21120. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  21121. var animation = this.animationsMap[ name ];
  21122. if ( animation ) {
  21123. animation.direction = -1;
  21124. animation.directionBackwards = true;
  21125. }
  21126. };
  21127. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  21128. var animation = this.animationsMap[ name ];
  21129. if ( animation ) {
  21130. animation.fps = fps;
  21131. animation.duration = ( animation.end - animation.start ) / animation.fps;
  21132. }
  21133. };
  21134. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  21135. var animation = this.animationsMap[ name ];
  21136. if ( animation ) {
  21137. animation.duration = duration;
  21138. animation.fps = ( animation.end - animation.start ) / animation.duration;
  21139. }
  21140. };
  21141. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  21142. var animation = this.animationsMap[ name ];
  21143. if ( animation ) {
  21144. animation.weight = weight;
  21145. }
  21146. };
  21147. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  21148. var animation = this.animationsMap[ name ];
  21149. if ( animation ) {
  21150. animation.time = time;
  21151. }
  21152. };
  21153. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  21154. var time = 0;
  21155. var animation = this.animationsMap[ name ];
  21156. if ( animation ) {
  21157. time = animation.time;
  21158. }
  21159. return time;
  21160. };
  21161. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  21162. var duration = -1;
  21163. var animation = this.animationsMap[ name ];
  21164. if ( animation ) {
  21165. duration = animation.duration;
  21166. }
  21167. return duration;
  21168. };
  21169. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  21170. var animation = this.animationsMap[ name ];
  21171. if ( animation ) {
  21172. animation.time = 0;
  21173. animation.active = true;
  21174. } else {
  21175. console.warn( "animation[" + name + "] undefined" );
  21176. }
  21177. };
  21178. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  21179. var animation = this.animationsMap[ name ];
  21180. if ( animation ) {
  21181. animation.active = false;
  21182. }
  21183. };
  21184. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  21185. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  21186. var animation = this.animationsList[ i ];
  21187. if ( ! animation.active ) continue;
  21188. var frameTime = animation.duration / animation.length;
  21189. animation.time += animation.direction * delta;
  21190. if ( animation.mirroredLoop ) {
  21191. if ( animation.time > animation.duration || animation.time < 0 ) {
  21192. animation.direction *= -1;
  21193. if ( animation.time > animation.duration ) {
  21194. animation.time = animation.duration;
  21195. animation.directionBackwards = true;
  21196. }
  21197. if ( animation.time < 0 ) {
  21198. animation.time = 0;
  21199. animation.directionBackwards = false;
  21200. }
  21201. }
  21202. } else {
  21203. animation.time = animation.time % animation.duration;
  21204. if ( animation.time < 0 ) animation.time += animation.duration;
  21205. }
  21206. var keyframe = animation.startFrame + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  21207. var weight = animation.weight;
  21208. if ( keyframe !== animation.currentFrame ) {
  21209. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  21210. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  21211. this.morphTargetInfluences[ keyframe ] = 0;
  21212. animation.lastFrame = animation.currentFrame;
  21213. animation.currentFrame = keyframe;
  21214. }
  21215. var mix = ( animation.time % frameTime ) / frameTime;
  21216. if ( animation.directionBackwards ) mix = 1 - mix;
  21217. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  21218. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  21219. }
  21220. };
  21221. /**
  21222. * @author mikael emtinger / http://gomo.se/
  21223. * @author alteredq / http://alteredqualia.com/
  21224. */
  21225. THREE.LensFlarePlugin = function ( ) {
  21226. var _gl, _renderer, _lensFlare = {};
  21227. this.init = function ( renderer ) {
  21228. _gl = renderer.context;
  21229. _renderer = renderer;
  21230. _lensFlare.vertices = new Float32Array( 8 + 8 );
  21231. _lensFlare.faces = new Uint16Array( 6 );
  21232. var i = 0;
  21233. _lensFlare.vertices[ i++ ] = -1; _lensFlare.vertices[ i++ ] = -1; // vertex
  21234. _lensFlare.vertices[ i++ ] = 0; _lensFlare.vertices[ i++ ] = 0; // uv... etc.
  21235. _lensFlare.vertices[ i++ ] = 1; _lensFlare.vertices[ i++ ] = -1;
  21236. _lensFlare.vertices[ i++ ] = 1; _lensFlare.vertices[ i++ ] = 0;
  21237. _lensFlare.vertices[ i++ ] = 1; _lensFlare.vertices[ i++ ] = 1;
  21238. _lensFlare.vertices[ i++ ] = 1; _lensFlare.vertices[ i++ ] = 1;
  21239. _lensFlare.vertices[ i++ ] = -1; _lensFlare.vertices[ i++ ] = 1;
  21240. _lensFlare.vertices[ i++ ] = 0; _lensFlare.vertices[ i++ ] = 1;
  21241. i = 0;
  21242. _lensFlare.faces[ i++ ] = 0; _lensFlare.faces[ i++ ] = 1; _lensFlare.faces[ i++ ] = 2;
  21243. _lensFlare.faces[ i++ ] = 0; _lensFlare.faces[ i++ ] = 2; _lensFlare.faces[ i++ ] = 3;
  21244. // buffers
  21245. _lensFlare.vertexBuffer = _gl.createBuffer();
  21246. _lensFlare.elementBuffer = _gl.createBuffer();
  21247. _gl.bindBuffer( _gl.ARRAY_BUFFER, _lensFlare.vertexBuffer );
  21248. _gl.bufferData( _gl.ARRAY_BUFFER, _lensFlare.vertices, _gl.STATIC_DRAW );
  21249. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, _lensFlare.elementBuffer );
  21250. _gl.bufferData( _gl.ELEMENT_ARRAY_BUFFER, _lensFlare.faces, _gl.STATIC_DRAW );
  21251. // textures
  21252. _lensFlare.tempTexture = _gl.createTexture();
  21253. _lensFlare.occlusionTexture = _gl.createTexture();
  21254. _gl.bindTexture( _gl.TEXTURE_2D, _lensFlare.tempTexture );
  21255. _gl.texImage2D( _gl.TEXTURE_2D, 0, _gl.RGB, 16, 16, 0, _gl.RGB, _gl.UNSIGNED_BYTE, null );
  21256. _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  21257. _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  21258. _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_MAG_FILTER, _gl.NEAREST );
  21259. _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_MIN_FILTER, _gl.NEAREST );
  21260. _gl.bindTexture( _gl.TEXTURE_2D, _lensFlare.occlusionTexture );
  21261. _gl.texImage2D( _gl.TEXTURE_2D, 0, _gl.RGBA, 16, 16, 0, _gl.RGBA, _gl.UNSIGNED_BYTE, null );
  21262. _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  21263. _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  21264. _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_MAG_FILTER, _gl.NEAREST );
  21265. _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_MIN_FILTER, _gl.NEAREST );
  21266. if ( _gl.getParameter( _gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) <= 0 ) {
  21267. _lensFlare.hasVertexTexture = false;
  21268. _lensFlare.program = createProgram( THREE.ShaderFlares[ "lensFlare" ] );
  21269. } else {
  21270. _lensFlare.hasVertexTexture = true;
  21271. _lensFlare.program = createProgram( THREE.ShaderFlares[ "lensFlareVertexTexture" ] );
  21272. }
  21273. _lensFlare.attributes = {};
  21274. _lensFlare.uniforms = {};
  21275. _lensFlare.attributes.vertex = _gl.getAttribLocation ( _lensFlare.program, "position" );
  21276. _lensFlare.attributes.uv = _gl.getAttribLocation ( _lensFlare.program, "uv" );
  21277. _lensFlare.uniforms.renderType = _gl.getUniformLocation( _lensFlare.program, "renderType" );
  21278. _lensFlare.uniforms.map = _gl.getUniformLocation( _lensFlare.program, "map" );
  21279. _lensFlare.uniforms.occlusionMap = _gl.getUniformLocation( _lensFlare.program, "occlusionMap" );
  21280. _lensFlare.uniforms.opacity = _gl.getUniformLocation( _lensFlare.program, "opacity" );
  21281. _lensFlare.uniforms.color = _gl.getUniformLocation( _lensFlare.program, "color" );
  21282. _lensFlare.uniforms.scale = _gl.getUniformLocation( _lensFlare.program, "scale" );
  21283. _lensFlare.uniforms.rotation = _gl.getUniformLocation( _lensFlare.program, "rotation" );
  21284. _lensFlare.uniforms.screenPosition = _gl.getUniformLocation( _lensFlare.program, "screenPosition" );
  21285. _lensFlare.attributesEnabled = false;
  21286. };
  21287. /*
  21288. * Render lens flares
  21289. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  21290. * reads these back and calculates occlusion.
  21291. * Then _lensFlare.update_lensFlares() is called to re-position and
  21292. * update transparency of flares. Then they are rendered.
  21293. *
  21294. */
  21295. this.render = function ( scene, camera, viewportWidth, viewportHeight ) {
  21296. var flares = scene.__webglFlares,
  21297. nFlares = flares.length;
  21298. if ( ! nFlares ) return;
  21299. var tempPosition = new THREE.Vector3();
  21300. var invAspect = viewportHeight / viewportWidth,
  21301. halfViewportWidth = viewportWidth * 0.5,
  21302. halfViewportHeight = viewportHeight * 0.5;
  21303. var size = 16 / viewportHeight,
  21304. scale = new THREE.Vector2( size * invAspect, size );
  21305. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  21306. screenPositionPixels = new THREE.Vector2( 1, 1 );
  21307. var uniforms = _lensFlare.uniforms,
  21308. attributes = _lensFlare.attributes;
  21309. // set _lensFlare program and reset blending
  21310. _gl.useProgram( _lensFlare.program );
  21311. if ( ! _lensFlare.attributesEnabled ) {
  21312. _gl.enableVertexAttribArray( _lensFlare.attributes.vertex );
  21313. _gl.enableVertexAttribArray( _lensFlare.attributes.uv );
  21314. _lensFlare.attributesEnabled = true;
  21315. }
  21316. // loop through all lens flares to update their occlusion and positions
  21317. // setup gl and common used attribs/unforms
  21318. _gl.uniform1i( uniforms.occlusionMap, 0 );
  21319. _gl.uniform1i( uniforms.map, 1 );
  21320. _gl.bindBuffer( _gl.ARRAY_BUFFER, _lensFlare.vertexBuffer );
  21321. _gl.vertexAttribPointer( attributes.vertex, 2, _gl.FLOAT, false, 2 * 8, 0 );
  21322. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 2 * 8, 8 );
  21323. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, _lensFlare.elementBuffer );
  21324. _gl.disable( _gl.CULL_FACE );
  21325. _gl.depthMask( false );
  21326. var i, j, jl, flare, sprite;
  21327. for ( i = 0; i < nFlares; i ++ ) {
  21328. size = 16 / viewportHeight;
  21329. scale.set( size * invAspect, size );
  21330. // calc object screen position
  21331. flare = flares[ i ];
  21332. tempPosition.set( flare.matrixWorld.elements[12], flare.matrixWorld.elements[13], flare.matrixWorld.elements[14] );
  21333. camera.matrixWorldInverse.multiplyVector3( tempPosition );
  21334. camera.projectionMatrix.multiplyVector3( tempPosition );
  21335. // setup arrays for gl programs
  21336. screenPosition.copy( tempPosition )
  21337. screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
  21338. screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
  21339. // screen cull
  21340. if ( _lensFlare.hasVertexTexture || (
  21341. screenPositionPixels.x > 0 &&
  21342. screenPositionPixels.x < viewportWidth &&
  21343. screenPositionPixels.y > 0 &&
  21344. screenPositionPixels.y < viewportHeight ) ) {
  21345. // save current RGB to temp texture
  21346. _gl.activeTexture( _gl.TEXTURE1 );
  21347. _gl.bindTexture( _gl.TEXTURE_2D, _lensFlare.tempTexture );
  21348. _gl.copyTexImage2D( _gl.TEXTURE_2D, 0, _gl.RGB, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  21349. // render pink quad
  21350. _gl.uniform1i( uniforms.renderType, 0 );
  21351. _gl.uniform2f( uniforms.scale, scale.x, scale.y );
  21352. _gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  21353. _gl.disable( _gl.BLEND );
  21354. _gl.enable( _gl.DEPTH_TEST );
  21355. _gl.drawElements( _gl.TRIANGLES, 6, _gl.UNSIGNED_SHORT, 0 );
  21356. // copy result to occlusionMap
  21357. _gl.activeTexture( _gl.TEXTURE0 );
  21358. _gl.bindTexture( _gl.TEXTURE_2D, _lensFlare.occlusionTexture );
  21359. _gl.copyTexImage2D( _gl.TEXTURE_2D, 0, _gl.RGBA, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  21360. // restore graphics
  21361. _gl.uniform1i( uniforms.renderType, 1 );
  21362. _gl.disable( _gl.DEPTH_TEST );
  21363. _gl.activeTexture( _gl.TEXTURE1 );
  21364. _gl.bindTexture( _gl.TEXTURE_2D, _lensFlare.tempTexture );
  21365. _gl.drawElements( _gl.TRIANGLES, 6, _gl.UNSIGNED_SHORT, 0 );
  21366. // update object positions
  21367. flare.positionScreen.copy( screenPosition )
  21368. if ( flare.customUpdateCallback ) {
  21369. flare.customUpdateCallback( flare );
  21370. } else {
  21371. flare.updateLensFlares();
  21372. }
  21373. // render flares
  21374. _gl.uniform1i( uniforms.renderType, 2 );
  21375. _gl.enable( _gl.BLEND );
  21376. for ( j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  21377. sprite = flare.lensFlares[ j ];
  21378. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  21379. screenPosition.x = sprite.x;
  21380. screenPosition.y = sprite.y;
  21381. screenPosition.z = sprite.z;
  21382. size = sprite.size * sprite.scale / viewportHeight;
  21383. scale.x = size * invAspect;
  21384. scale.y = size;
  21385. _gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  21386. _gl.uniform2f( uniforms.scale, scale.x, scale.y );
  21387. _gl.uniform1f( uniforms.rotation, sprite.rotation );
  21388. _gl.uniform1f( uniforms.opacity, sprite.opacity );
  21389. _gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  21390. _renderer.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  21391. _renderer.setTexture( sprite.texture, 1 );
  21392. _gl.drawElements( _gl.TRIANGLES, 6, _gl.UNSIGNED_SHORT, 0 );
  21393. }
  21394. }
  21395. }
  21396. }
  21397. // restore gl
  21398. _gl.enable( _gl.CULL_FACE );
  21399. _gl.enable( _gl.DEPTH_TEST );
  21400. _gl.depthMask( true );
  21401. };
  21402. function createProgram ( shader ) {
  21403. var program = _gl.createProgram();
  21404. var fragmentShader = _gl.createShader( _gl.FRAGMENT_SHADER );
  21405. var vertexShader = _gl.createShader( _gl.VERTEX_SHADER );
  21406. _gl.shaderSource( fragmentShader, shader.fragmentShader );
  21407. _gl.shaderSource( vertexShader, shader.vertexShader );
  21408. _gl.compileShader( fragmentShader );
  21409. _gl.compileShader( vertexShader );
  21410. _gl.attachShader( program, fragmentShader );
  21411. _gl.attachShader( program, vertexShader );
  21412. _gl.linkProgram( program );
  21413. return program;
  21414. };
  21415. };/**
  21416. * @author alteredq / http://alteredqualia.com/
  21417. */
  21418. THREE.ShadowMapPlugin = function ( ) {
  21419. var _gl,
  21420. _renderer,
  21421. _depthMaterial, _depthMaterialMorph,
  21422. _frustum = new THREE.Frustum(),
  21423. _projScreenMatrix = new THREE.Matrix4(),
  21424. _min = new THREE.Vector3(),
  21425. _max = new THREE.Vector3();
  21426. this.init = function ( renderer ) {
  21427. _gl = renderer.context;
  21428. _renderer = renderer;
  21429. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  21430. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  21431. _depthMaterial = new THREE.ShaderMaterial( { fragmentShader: depthShader.fragmentShader, vertexShader: depthShader.vertexShader, uniforms: depthUniforms } );
  21432. _depthMaterialMorph = new THREE.ShaderMaterial( { fragmentShader: depthShader.fragmentShader, vertexShader: depthShader.vertexShader, uniforms: depthUniforms, morphTargets: true } );
  21433. _depthMaterial._shadowPass = true;
  21434. _depthMaterialMorph._shadowPass = true;
  21435. };
  21436. this.render = function ( scene, camera ) {
  21437. if ( ! ( _renderer.shadowMapEnabled && _renderer.shadowMapAutoUpdate ) ) return;
  21438. this.update( scene, camera );
  21439. };
  21440. this.update = function ( scene, camera ) {
  21441. var i, il, j, jl, n,
  21442. shadowMap, shadowMatrix, shadowCamera,
  21443. program, buffer, material,
  21444. webglObject, object, light,
  21445. renderList,
  21446. lights = [],
  21447. k = 0,
  21448. fog = null;
  21449. // set GL state for depth map
  21450. _gl.clearColor( 1, 1, 1, 1 );
  21451. _gl.disable( _gl.BLEND );
  21452. if ( _renderer.shadowMapCullFrontFaces ) _gl.cullFace( _gl.FRONT );
  21453. _renderer.setDepthTest( true );
  21454. // preprocess lights
  21455. // - skip lights that are not casting shadows
  21456. // - create virtual lights for cascaded shadow maps
  21457. for ( i = 0, il = scene.__lights.length; i < il; i ++ ) {
  21458. light = scene.__lights[ i ];
  21459. if ( ! light.castShadow ) continue;
  21460. if ( ( light instanceof THREE.DirectionalLight ) && light.shadowCascade ) {
  21461. for ( n = 0; n < light.shadowCascadeCount; n ++ ) {
  21462. var virtualLight;
  21463. if ( ! light.shadowCascadeArray[ n ] ) {
  21464. virtualLight = createVirtualLight( light, n );
  21465. virtualLight.originalCamera = camera;
  21466. var gyro = new THREE.Gyroscope();
  21467. gyro.position = light.shadowCascadeOffset;
  21468. gyro.add( virtualLight );
  21469. gyro.add( virtualLight.target );
  21470. camera.add( gyro );
  21471. light.shadowCascadeArray[ n ] = virtualLight;
  21472. console.log( "Created virtualLight", virtualLight );
  21473. } else {
  21474. virtualLight = light.shadowCascadeArray[ n ];
  21475. }
  21476. updateVirtualLight( light, n );
  21477. lights[ k ] = virtualLight;
  21478. k ++;
  21479. }
  21480. } else {
  21481. lights[ k ] = light;
  21482. k ++;
  21483. }
  21484. }
  21485. // render depth map
  21486. for ( i = 0, il = lights.length; i < il; i ++ ) {
  21487. light = lights[ i ];
  21488. if ( ! light.shadowMap ) {
  21489. var pars = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBAFormat };
  21490. light.shadowMap = new THREE.WebGLRenderTarget( light.shadowMapWidth, light.shadowMapHeight, pars );
  21491. light.shadowMapSize = new THREE.Vector2( light.shadowMapWidth, light.shadowMapHeight );
  21492. light.shadowMatrix = new THREE.Matrix4();
  21493. }
  21494. if ( ! light.shadowCamera ) {
  21495. if ( light instanceof THREE.SpotLight ) {
  21496. light.shadowCamera = new THREE.PerspectiveCamera( light.shadowCameraFov, light.shadowMapWidth / light.shadowMapHeight, light.shadowCameraNear, light.shadowCameraFar );
  21497. } else if ( light instanceof THREE.DirectionalLight ) {
  21498. light.shadowCamera = new THREE.OrthographicCamera( light.shadowCameraLeft, light.shadowCameraRight, light.shadowCameraTop, light.shadowCameraBottom, light.shadowCameraNear, light.shadowCameraFar );
  21499. } else {
  21500. console.error( "Unsupported light type for shadow" );
  21501. continue;
  21502. }
  21503. scene.add( light.shadowCamera );
  21504. if ( _renderer.autoUpdateScene ) scene.updateMatrixWorld();
  21505. }
  21506. if ( light.shadowCameraVisible && ! light.cameraHelper ) {
  21507. light.cameraHelper = new THREE.CameraHelper( light.shadowCamera );
  21508. light.shadowCamera.add( light.cameraHelper );
  21509. }
  21510. if ( light.isVirtual && virtualLight.originalCamera == camera ) {
  21511. updateShadowCamera( camera, light );
  21512. }
  21513. shadowMap = light.shadowMap;
  21514. shadowMatrix = light.shadowMatrix;
  21515. shadowCamera = light.shadowCamera;
  21516. shadowCamera.position.copy( light.matrixWorld.getPosition() );
  21517. shadowCamera.lookAt( light.target.matrixWorld.getPosition() );
  21518. shadowCamera.updateMatrixWorld();
  21519. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  21520. if ( light.cameraHelper ) light.cameraHelper.lines.visible = light.shadowCameraVisible;
  21521. if ( light.shadowCameraVisible ) light.cameraHelper.update();
  21522. // compute shadow matrix
  21523. shadowMatrix.set( 0.5, 0.0, 0.0, 0.5,
  21524. 0.0, 0.5, 0.0, 0.5,
  21525. 0.0, 0.0, 0.5, 0.5,
  21526. 0.0, 0.0, 0.0, 1.0 );
  21527. shadowMatrix.multiplySelf( shadowCamera.projectionMatrix );
  21528. shadowMatrix.multiplySelf( shadowCamera.matrixWorldInverse );
  21529. // update camera matrices and frustum
  21530. if ( ! shadowCamera._viewMatrixArray ) shadowCamera._viewMatrixArray = new Float32Array( 16 );
  21531. if ( ! shadowCamera._projectionMatrixArray ) shadowCamera._projectionMatrixArray = new Float32Array( 16 );
  21532. shadowCamera.matrixWorldInverse.flattenToArray( shadowCamera._viewMatrixArray );
  21533. shadowCamera.projectionMatrix.flattenToArray( shadowCamera._projectionMatrixArray );
  21534. _projScreenMatrix.multiply( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  21535. _frustum.setFromMatrix( _projScreenMatrix );
  21536. // render shadow map
  21537. _renderer.setRenderTarget( shadowMap );
  21538. _renderer.clear();
  21539. // set object matrices & frustum culling
  21540. renderList = scene.__webglObjects;
  21541. for ( j = 0, jl = renderList.length; j < jl; j ++ ) {
  21542. webglObject = renderList[ j ];
  21543. object = webglObject.object;
  21544. webglObject.render = false;
  21545. if ( object.visible && object.castShadow ) {
  21546. if ( ! ( object instanceof THREE.Mesh ) || ! ( object.frustumCulled ) || _frustum.contains( object ) ) {
  21547. //object.matrixWorld.flattenToArray( object._objectMatrixArray );
  21548. object._modelViewMatrix.multiply( shadowCamera.matrixWorldInverse, object.matrixWorld);
  21549. webglObject.render = true;
  21550. }
  21551. }
  21552. }
  21553. // render regular objects
  21554. for ( j = 0, jl = renderList.length; j < jl; j ++ ) {
  21555. webglObject = renderList[ j ];
  21556. if ( webglObject.render ) {
  21557. object = webglObject.object;
  21558. buffer = webglObject.buffer;
  21559. _renderer.setObjectFaces( object );
  21560. if ( object.customDepthMaterial ) {
  21561. material = object.customDepthMaterial;
  21562. } else if ( object.geometry.morphTargets.length ) {
  21563. material = _depthMaterialMorph;
  21564. } else {
  21565. material = _depthMaterial;
  21566. }
  21567. if ( buffer instanceof THREE.BufferGeometry ) {
  21568. _renderer.renderBufferDirect( shadowCamera, scene.__lights, fog, material, buffer, object );
  21569. } else {
  21570. _renderer.renderBuffer( shadowCamera, scene.__lights, fog, material, buffer, object );
  21571. }
  21572. }
  21573. }
  21574. // set matrices and render immediate objects
  21575. renderList = scene.__webglObjectsImmediate;
  21576. for ( j = 0, jl = renderList.length; j < jl; j ++ ) {
  21577. webglObject = renderList[ j ];
  21578. object = webglObject.object;
  21579. if ( object.visible && object.castShadow ) {
  21580. /*
  21581. if ( object.matrixAutoUpdate ) {
  21582. object.matrixWorld.flattenToArray( object._objectMatrixArray );
  21583. }
  21584. */
  21585. object._modelViewMatrix.multiply( shadowCamera.matrixWorldInverse, object.matrixWorld);
  21586. _renderer.renderImmediateObject( shadowCamera, scene.__lights, fog, _depthMaterial, object );
  21587. }
  21588. }
  21589. }
  21590. // restore GL state
  21591. var clearColor = _renderer.getClearColor(),
  21592. clearAlpha = _renderer.getClearAlpha();
  21593. _gl.clearColor( clearColor.r, clearColor.g, clearColor.b, clearAlpha );
  21594. _gl.enable( _gl.BLEND );
  21595. if ( _renderer.shadowMapCullFrontFaces ) _gl.cullFace( _gl.BACK );
  21596. };
  21597. function createVirtualLight( light, cascade ) {
  21598. var virtualLight = new THREE.DirectionalLight();
  21599. virtualLight.isVirtual = true;
  21600. virtualLight.onlyShadow = true;
  21601. virtualLight.castShadow = true;
  21602. virtualLight.shadowCameraNear = light.shadowCameraNear;
  21603. virtualLight.shadowCameraFar = light.shadowCameraFar;
  21604. virtualLight.shadowCameraLeft = light.shadowCameraLeft;
  21605. virtualLight.shadowCameraRight = light.shadowCameraRight;
  21606. virtualLight.shadowCameraBottom = light.shadowCameraBottom;
  21607. virtualLight.shadowCameraTop = light.shadowCameraTop;
  21608. virtualLight.shadowCameraVisible = light.shadowCameraVisible;
  21609. virtualLight.shadowDarkness = light.shadowDarkness;
  21610. virtualLight.shadowBias = light.shadowCascadeBias[ cascade ];
  21611. virtualLight.shadowMapWidth = light.shadowCascadeWidth[ cascade ];
  21612. virtualLight.shadowMapHeight = light.shadowCascadeHeight[ cascade ];
  21613. virtualLight.pointsWorld = [];
  21614. virtualLight.pointsFrustum = [];
  21615. var pointsWorld = virtualLight.pointsWorld,
  21616. pointsFrustum = virtualLight.pointsFrustum;
  21617. for ( var i = 0; i < 8; i ++ ) {
  21618. pointsWorld[ i ] = new THREE.Vector3();
  21619. pointsFrustum[ i ] = new THREE.Vector3();
  21620. }
  21621. var nearZ = light.shadowCascadeNearZ[ cascade ];
  21622. var farZ = light.shadowCascadeFarZ[ cascade ];
  21623. pointsFrustum[ 0 ].set( -1, -1, nearZ );
  21624. pointsFrustum[ 1 ].set( 1, -1, nearZ );
  21625. pointsFrustum[ 2 ].set( -1, 1, nearZ );
  21626. pointsFrustum[ 3 ].set( 1, 1, nearZ );
  21627. pointsFrustum[ 4 ].set( -1, -1, farZ );
  21628. pointsFrustum[ 5 ].set( 1, -1, farZ );
  21629. pointsFrustum[ 6 ].set( -1, 1, farZ );
  21630. pointsFrustum[ 7 ].set( 1, 1, farZ );
  21631. return virtualLight;
  21632. }
  21633. // Synchronize virtual light with the original light
  21634. function updateVirtualLight( light, cascade ) {
  21635. var virtualLight = light.shadowCascadeArray[ cascade ];
  21636. virtualLight.position.copy( light.position );
  21637. virtualLight.target.position.copy( light.target.position );
  21638. virtualLight.lookAt( virtualLight.target );
  21639. virtualLight.shadowCameraVisible = light.shadowCameraVisible;
  21640. virtualLight.shadowDarkness = light.shadowDarkness;
  21641. virtualLight.shadowBias = light.shadowCascadeBias[ cascade ];
  21642. var nearZ = light.shadowCascadeNearZ[ cascade ];
  21643. var farZ = light.shadowCascadeFarZ[ cascade ];
  21644. var pointsFrustum = virtualLight.pointsFrustum;
  21645. pointsFrustum[ 0 ].z = nearZ;
  21646. pointsFrustum[ 1 ].z = nearZ;
  21647. pointsFrustum[ 2 ].z = nearZ;
  21648. pointsFrustum[ 3 ].z = nearZ;
  21649. pointsFrustum[ 4 ].z = farZ;
  21650. pointsFrustum[ 5 ].z = farZ;
  21651. pointsFrustum[ 6 ].z = farZ;
  21652. pointsFrustum[ 7 ].z = farZ;
  21653. }
  21654. // Fit shadow camera's ortho frustum to camera frustum
  21655. function updateShadowCamera( camera, light ) {
  21656. var shadowCamera = light.shadowCamera,
  21657. pointsFrustum = light.pointsFrustum,
  21658. pointsWorld = light.pointsWorld;
  21659. _min.set( Infinity, Infinity, Infinity );
  21660. _max.set( -Infinity, -Infinity, -Infinity );
  21661. for ( var i = 0; i < 8; i ++ ) {
  21662. var p = pointsWorld[ i ];
  21663. p.copy( pointsFrustum[ i ] );
  21664. THREE.ShadowMapPlugin.__projector.unprojectVector( p, camera );
  21665. shadowCamera.matrixWorldInverse.multiplyVector3( p );
  21666. if ( p.x < _min.x ) _min.x = p.x;
  21667. if ( p.x > _max.x ) _max.x = p.x;
  21668. if ( p.y < _min.y ) _min.y = p.y;
  21669. if ( p.y > _max.y ) _max.y = p.y;
  21670. if ( p.z < _min.z ) _min.z = p.z;
  21671. if ( p.z > _max.z ) _max.z = p.z;
  21672. }
  21673. shadowCamera.left = _min.x;
  21674. shadowCamera.right = _max.x;
  21675. shadowCamera.top = _max.y;
  21676. shadowCamera.bottom = _min.y;
  21677. // can't really fit near/far
  21678. //shadowCamera.near = _min.z;
  21679. //shadowCamera.far = _max.z;
  21680. shadowCamera.updateProjectionMatrix();
  21681. }
  21682. };
  21683. THREE.ShadowMapPlugin.__projector = new THREE.Projector();
  21684. /**
  21685. * @author mikael emtinger / http://gomo.se/
  21686. * @author alteredq / http://alteredqualia.com/
  21687. */
  21688. THREE.SpritePlugin = function ( ) {
  21689. var _gl, _renderer, _sprite = {};
  21690. this.init = function ( renderer ) {
  21691. _gl = renderer.context;
  21692. _renderer = renderer;
  21693. _sprite.vertices = new Float32Array( 8 + 8 );
  21694. _sprite.faces = new Uint16Array( 6 );
  21695. var i = 0;
  21696. _sprite.vertices[ i++ ] = -1; _sprite.vertices[ i++ ] = -1; // vertex 0
  21697. _sprite.vertices[ i++ ] = 0; _sprite.vertices[ i++ ] = 1; // uv 0
  21698. _sprite.vertices[ i++ ] = 1; _sprite.vertices[ i++ ] = -1; // vertex 1
  21699. _sprite.vertices[ i++ ] = 1; _sprite.vertices[ i++ ] = 1; // uv 1
  21700. _sprite.vertices[ i++ ] = 1; _sprite.vertices[ i++ ] = 1; // vertex 2
  21701. _sprite.vertices[ i++ ] = 1; _sprite.vertices[ i++ ] = 0; // uv 2
  21702. _sprite.vertices[ i++ ] = -1; _sprite.vertices[ i++ ] = 1; // vertex 3
  21703. _sprite.vertices[ i++ ] = 0; _sprite.vertices[ i++ ] = 0; // uv 3
  21704. i = 0;
  21705. _sprite.faces[ i++ ] = 0; _sprite.faces[ i++ ] = 1; _sprite.faces[ i++ ] = 2;
  21706. _sprite.faces[ i++ ] = 0; _sprite.faces[ i++ ] = 2; _sprite.faces[ i++ ] = 3;
  21707. _sprite.vertexBuffer = _gl.createBuffer();
  21708. _sprite.elementBuffer = _gl.createBuffer();
  21709. _gl.bindBuffer( _gl.ARRAY_BUFFER, _sprite.vertexBuffer );
  21710. _gl.bufferData( _gl.ARRAY_BUFFER, _sprite.vertices, _gl.STATIC_DRAW );
  21711. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, _sprite.elementBuffer );
  21712. _gl.bufferData( _gl.ELEMENT_ARRAY_BUFFER, _sprite.faces, _gl.STATIC_DRAW );
  21713. _sprite.program = createProgram( THREE.ShaderSprite[ "sprite" ] );
  21714. _sprite.attributes = {};
  21715. _sprite.uniforms = {};
  21716. _sprite.attributes.position = _gl.getAttribLocation ( _sprite.program, "position" );
  21717. _sprite.attributes.uv = _gl.getAttribLocation ( _sprite.program, "uv" );
  21718. _sprite.uniforms.uvOffset = _gl.getUniformLocation( _sprite.program, "uvOffset" );
  21719. _sprite.uniforms.uvScale = _gl.getUniformLocation( _sprite.program, "uvScale" );
  21720. _sprite.uniforms.rotation = _gl.getUniformLocation( _sprite.program, "rotation" );
  21721. _sprite.uniforms.scale = _gl.getUniformLocation( _sprite.program, "scale" );
  21722. _sprite.uniforms.alignment = _gl.getUniformLocation( _sprite.program, "alignment" );
  21723. _sprite.uniforms.color = _gl.getUniformLocation( _sprite.program, "color" );
  21724. _sprite.uniforms.map = _gl.getUniformLocation( _sprite.program, "map" );
  21725. _sprite.uniforms.opacity = _gl.getUniformLocation( _sprite.program, "opacity" );
  21726. _sprite.uniforms.useScreenCoordinates = _gl.getUniformLocation( _sprite.program, "useScreenCoordinates" );
  21727. _sprite.uniforms.affectedByDistance = _gl.getUniformLocation( _sprite.program, "affectedByDistance" );
  21728. _sprite.uniforms.screenPosition = _gl.getUniformLocation( _sprite.program, "screenPosition" );
  21729. _sprite.uniforms.modelViewMatrix = _gl.getUniformLocation( _sprite.program, "modelViewMatrix" );
  21730. _sprite.uniforms.projectionMatrix = _gl.getUniformLocation( _sprite.program, "projectionMatrix" );
  21731. _sprite.attributesEnabled = false;
  21732. };
  21733. this.render = function ( scene, camera, viewportWidth, viewportHeight ) {
  21734. var sprites = scene.__webglSprites,
  21735. nSprites = sprites.length;
  21736. if ( ! nSprites ) return;
  21737. var attributes = _sprite.attributes,
  21738. uniforms = _sprite.uniforms;
  21739. var invAspect = viewportHeight / viewportWidth;
  21740. var halfViewportWidth = viewportWidth * 0.5,
  21741. halfViewportHeight = viewportHeight * 0.5;
  21742. var mergeWith3D = true;
  21743. // setup gl
  21744. _gl.useProgram( _sprite.program );
  21745. if ( ! _sprite.attributesEnabled ) {
  21746. _gl.enableVertexAttribArray( attributes.position );
  21747. _gl.enableVertexAttribArray( attributes.uv );
  21748. _sprite.attributesEnabled = true;
  21749. }
  21750. _gl.disable( _gl.CULL_FACE );
  21751. _gl.enable( _gl.BLEND );
  21752. _gl.depthMask( true );
  21753. _gl.bindBuffer( _gl.ARRAY_BUFFER, _sprite.vertexBuffer );
  21754. _gl.vertexAttribPointer( attributes.position, 2, _gl.FLOAT, false, 2 * 8, 0 );
  21755. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 2 * 8, 8 );
  21756. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, _sprite.elementBuffer );
  21757. _gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera._projectionMatrixArray );
  21758. _gl.activeTexture( _gl.TEXTURE0 );
  21759. _gl.uniform1i( uniforms.map, 0 );
  21760. // update positions and sort
  21761. var i, sprite, screenPosition, size, scale = [];
  21762. for( i = 0; i < nSprites; i ++ ) {
  21763. sprite = sprites[ i ];
  21764. if ( ! sprite.visible || sprite.opacity === 0 ) continue;
  21765. if( ! sprite.useScreenCoordinates ) {
  21766. sprite._modelViewMatrix.multiply( camera.matrixWorldInverse, sprite.matrixWorld);
  21767. sprite.z = - sprite._modelViewMatrix.elements[14];
  21768. } else {
  21769. sprite.z = - sprite.position.z;
  21770. }
  21771. }
  21772. sprites.sort( painterSort );
  21773. // render all sprites
  21774. for( i = 0; i < nSprites; i ++ ) {
  21775. sprite = sprites[ i ];
  21776. if ( ! sprite.visible || sprite.opacity === 0 ) continue;
  21777. if ( sprite.map && sprite.map.image && sprite.map.image.width ) {
  21778. if ( sprite.useScreenCoordinates ) {
  21779. _gl.uniform1i( uniforms.useScreenCoordinates, 1 );
  21780. _gl.uniform3f( uniforms.screenPosition, ( sprite.position.x - halfViewportWidth ) / halfViewportWidth,
  21781. ( halfViewportHeight - sprite.position.y ) / halfViewportHeight,
  21782. Math.max( 0, Math.min( 1, sprite.position.z ) ) );
  21783. } else {
  21784. _gl.uniform1i( uniforms.useScreenCoordinates, 0 );
  21785. _gl.uniform1i( uniforms.affectedByDistance, sprite.affectedByDistance ? 1 : 0 );
  21786. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite._modelViewMatrix.elements);
  21787. }
  21788. size = sprite.map.image.width / ( sprite.scaleByViewport ? viewportHeight : 1 );
  21789. scale[ 0 ] = size * invAspect * sprite.scale.x;
  21790. scale[ 1 ] = size * sprite.scale.y;
  21791. _gl.uniform2f( uniforms.uvScale, sprite.uvScale.x, sprite.uvScale.y );
  21792. _gl.uniform2f( uniforms.uvOffset, sprite.uvOffset.x, sprite.uvOffset.y );
  21793. _gl.uniform2f( uniforms.alignment, sprite.alignment.x, sprite.alignment.y );
  21794. _gl.uniform1f( uniforms.opacity, sprite.opacity );
  21795. _gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  21796. _gl.uniform1f( uniforms.rotation, sprite.rotation );
  21797. _gl.uniform2fv( uniforms.scale, scale );
  21798. if ( sprite.mergeWith3D && !mergeWith3D ) {
  21799. _gl.enable( _gl.DEPTH_TEST );
  21800. mergeWith3D = true;
  21801. } else if ( ! sprite.mergeWith3D && mergeWith3D ) {
  21802. _gl.disable( _gl.DEPTH_TEST );
  21803. mergeWith3D = false;
  21804. }
  21805. _renderer.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  21806. _renderer.setTexture( sprite.map, 0 );
  21807. _gl.drawElements( _gl.TRIANGLES, 6, _gl.UNSIGNED_SHORT, 0 );
  21808. }
  21809. }
  21810. // restore gl
  21811. _gl.enable( _gl.CULL_FACE );
  21812. _gl.enable( _gl.DEPTH_TEST );
  21813. _gl.depthMask( true );
  21814. };
  21815. function createProgram ( shader ) {
  21816. var program = _gl.createProgram();
  21817. var fragmentShader = _gl.createShader( _gl.FRAGMENT_SHADER );
  21818. var vertexShader = _gl.createShader( _gl.VERTEX_SHADER );
  21819. _gl.shaderSource( fragmentShader, shader.fragmentShader );
  21820. _gl.shaderSource( vertexShader, shader.vertexShader );
  21821. _gl.compileShader( fragmentShader );
  21822. _gl.compileShader( vertexShader );
  21823. _gl.attachShader( program, fragmentShader );
  21824. _gl.attachShader( program, vertexShader );
  21825. _gl.linkProgram( program );
  21826. return program;
  21827. };
  21828. function painterSort ( a, b ) {
  21829. return b.z - a.z;
  21830. };
  21831. };/**
  21832. * @author alteredq / http://alteredqualia.com/
  21833. */
  21834. THREE.DepthPassPlugin = function ( ) {
  21835. this.enabled = false;
  21836. this.renderTarget = null;
  21837. var _gl,
  21838. _renderer,
  21839. _depthMaterial, _depthMaterialMorph,
  21840. _frustum = new THREE.Frustum(),
  21841. _projScreenMatrix = new THREE.Matrix4();
  21842. this.init = function ( renderer ) {
  21843. _gl = renderer.context;
  21844. _renderer = renderer;
  21845. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  21846. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  21847. _depthMaterial = new THREE.ShaderMaterial( { fragmentShader: depthShader.fragmentShader, vertexShader: depthShader.vertexShader, uniforms: depthUniforms } );
  21848. _depthMaterialMorph = new THREE.ShaderMaterial( { fragmentShader: depthShader.fragmentShader, vertexShader: depthShader.vertexShader, uniforms: depthUniforms, morphTargets: true } );
  21849. _depthMaterial._shadowPass = true;
  21850. _depthMaterialMorph._shadowPass = true;
  21851. };
  21852. this.render = function ( scene, camera ) {
  21853. if ( ! this.enabled ) return;
  21854. this.update( scene, camera );
  21855. };
  21856. this.update = function ( scene, camera ) {
  21857. var i, il, j, jl, n,
  21858. program, buffer, material,
  21859. webglObject, object, light,
  21860. renderList,
  21861. fog = null;
  21862. // set GL state for depth map
  21863. _gl.clearColor( 1, 1, 1, 1 );
  21864. _gl.disable( _gl.BLEND );
  21865. _renderer.setDepthTest( true );
  21866. // update scene
  21867. if ( _renderer.autoUpdateScene ) scene.updateMatrixWorld();
  21868. // update camera matrices and frustum
  21869. if ( ! camera._viewMatrixArray ) camera._viewMatrixArray = new Float32Array( 16 );
  21870. if ( ! camera._projectionMatrixArray ) camera._projectionMatrixArray = new Float32Array( 16 );
  21871. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  21872. camera.matrixWorldInverse.flattenToArray( camera._viewMatrixArray );
  21873. camera.projectionMatrix.flattenToArray( camera._projectionMatrixArray );
  21874. _projScreenMatrix.multiply( camera.projectionMatrix, camera.matrixWorldInverse );
  21875. _frustum.setFromMatrix( _projScreenMatrix );
  21876. // render depth map
  21877. _renderer.setRenderTarget( this.renderTarget );
  21878. _renderer.clear();
  21879. // set object matrices & frustum culling
  21880. renderList = scene.__webglObjects;
  21881. for ( j = 0, jl = renderList.length; j < jl; j ++ ) {
  21882. webglObject = renderList[ j ];
  21883. object = webglObject.object;
  21884. webglObject.render = false;
  21885. if ( object.visible ) {
  21886. if ( ! ( object instanceof THREE.Mesh ) || ! ( object.frustumCulled ) || _frustum.contains( object ) ) {
  21887. //object.matrixWorld.flattenToArray( object._objectMatrixArray );
  21888. object._modelViewMatrix.multiply( camera.matrixWorldInverse, object.matrixWorld);
  21889. webglObject.render = true;
  21890. }
  21891. }
  21892. }
  21893. // render regular objects
  21894. for ( j = 0, jl = renderList.length; j < jl; j ++ ) {
  21895. webglObject = renderList[ j ];
  21896. if ( webglObject.render ) {
  21897. object = webglObject.object;
  21898. buffer = webglObject.buffer;
  21899. _renderer.setObjectFaces( object );
  21900. if ( object.customDepthMaterial ) {
  21901. material = object.customDepthMaterial;
  21902. } else if ( object.geometry.morphTargets.length ) {
  21903. material = _depthMaterialMorph;
  21904. } else {
  21905. material = _depthMaterial;
  21906. }
  21907. if ( buffer instanceof THREE.BufferGeometry ) {
  21908. _renderer.renderBufferDirect( camera, scene.__lights, fog, material, buffer, object );
  21909. } else {
  21910. _renderer.renderBuffer( camera, scene.__lights, fog, material, buffer, object );
  21911. }
  21912. }
  21913. }
  21914. // set matrices and render immediate objects
  21915. renderList = scene.__webglObjectsImmediate;
  21916. for ( j = 0, jl = renderList.length; j < jl; j ++ ) {
  21917. webglObject = renderList[ j ];
  21918. object = webglObject.object;
  21919. if ( object.visible && object.castShadow ) {
  21920. /*
  21921. if ( object.matrixAutoUpdate ) {
  21922. object.matrixWorld.flattenToArray( object._objectMatrixArray );
  21923. }
  21924. */
  21925. object._modelViewMatrix.multiply( camera.matrixWorldInverse, object.matrixWorld);
  21926. _renderer.renderImmediateObject( camera, scene.__lights, fog, _depthMaterial, object );
  21927. }
  21928. }
  21929. // restore GL state
  21930. var clearColor = _renderer.getClearColor(),
  21931. clearAlpha = _renderer.getClearAlpha();
  21932. _gl.clearColor( clearColor.r, clearColor.g, clearColor.b, clearAlpha );
  21933. _gl.enable( _gl.BLEND );
  21934. };
  21935. };
  21936. /**
  21937. * @author mrdoob / http://mrdoob.com/
  21938. * @author marklundin / http://mark-lundin.com/
  21939. * @author alteredq / http://alteredqualia.com/
  21940. */
  21941. if ( THREE.WebGLRenderer ) {
  21942. THREE.AnaglyphWebGLRenderer = function ( parameters ) {
  21943. THREE.WebGLRenderer.call( this, parameters );
  21944. this.autoUpdateScene = false;
  21945. var _this = this, _setSize = this.setSize, _render = this.render;
  21946. var _cameraL = new THREE.PerspectiveCamera(),
  21947. _cameraR = new THREE.PerspectiveCamera();
  21948. var eyeRight = new THREE.Matrix4(),
  21949. eyeLeft = new THREE.Matrix4(),
  21950. focalLength = 125,
  21951. _aspect, _near, _far, _fov;
  21952. _cameraL.matrixAutoUpdate = _cameraR.matrixAutoUpdate = false;
  21953. var _params = { minFilter: THREE.LinearFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat };
  21954. var _renderTargetL = new THREE.WebGLRenderTarget( 512, 512, _params ),
  21955. _renderTargetR = new THREE.WebGLRenderTarget( 512, 512, _params );
  21956. var _camera = new THREE.PerspectiveCamera( 53, 1, 1, 10000 );
  21957. _camera.position.z = 2;
  21958. var _material = new THREE.ShaderMaterial( {
  21959. uniforms: {
  21960. "mapLeft": { type: "t", value: 0, texture: _renderTargetL },
  21961. "mapRight": { type: "t", value: 1, texture: _renderTargetR }
  21962. },
  21963. vertexShader: [
  21964. "varying vec2 vUv;",
  21965. "void main() {",
  21966. "vUv = vec2( uv.x, 1.0 - uv.y );",
  21967. "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  21968. "}"
  21969. ].join("\n"),
  21970. fragmentShader: [
  21971. "uniform sampler2D mapLeft;",
  21972. "uniform sampler2D mapRight;",
  21973. "varying vec2 vUv;",
  21974. "void main() {",
  21975. "vec4 colorL, colorR;",
  21976. "vec2 uv = vUv;",
  21977. "colorL = texture2D( mapLeft, uv );",
  21978. "colorR = texture2D( mapRight, uv );",
  21979. // http://3dtv.at/Knowhow/AnaglyphComparison_en.aspx
  21980. "gl_FragColor = vec4( colorL.g * 0.7 + colorL.b * 0.3, colorR.g, colorR.b, colorL.a + colorR.a ) * 1.1;",
  21981. "}"
  21982. ].join("\n")
  21983. } );
  21984. var _scene = new THREE.Scene();
  21985. var mesh = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), _material );
  21986. mesh.rotation.x = Math.PI / 2;
  21987. _scene.add( mesh );
  21988. _scene.add( _camera );
  21989. this.setSize = function ( width, height ) {
  21990. _setSize.call( _this, width, height );
  21991. _renderTargetL.width = width;
  21992. _renderTargetL.height = height;
  21993. _renderTargetR.width = width;
  21994. _renderTargetR.height = height;
  21995. };
  21996. /*
  21997. * Renderer now uses an asymmetric perspective projection (http://paulbourke.net/miscellaneous/stereographics/stereorender/).
  21998. * Each camera is offset by the eye seperation and its projection matrix is also skewed asymetrically back to converge on the same
  21999. * projection plane. Added a focal length parameter to, this is where the parallax is equal to 0.
  22000. */
  22001. this.render = function ( scene, camera, renderTarget, forceClear ) {
  22002. scene.updateMatrixWorld();
  22003. var hasCameraChanged = ( _aspect !== camera.aspect ) || ( _near !== camera.near ) || ( _far !== camera.far ) || ( _fov !== camera.fov );
  22004. if( hasCameraChanged ) {
  22005. _aspect = camera.aspect;
  22006. _near = camera.near;
  22007. _far = camera.far;
  22008. _fov = camera.fov;
  22009. var projectionMatrix = camera.projectionMatrix.clone(),
  22010. eyeSep = focalLength / 30 * 0.5,
  22011. eyeSepOnProjection = eyeSep * _near / focalLength,
  22012. ymax = _near * Math.tan( _fov * Math.PI / 360 ),
  22013. xmin, xmax;
  22014. // translate xOffset
  22015. eyeRight.elements[12] = eyeSep;
  22016. eyeLeft.elements[12] = -eyeSep;
  22017. // for left eye
  22018. xmin = -ymax * _aspect + eyeSepOnProjection;
  22019. xmax = ymax * _aspect + eyeSepOnProjection;
  22020. projectionMatrix.elements[0] = 2 * _near / ( xmax - xmin );
  22021. projectionMatrix.elements[8] = ( xmax + xmin ) / ( xmax - xmin );
  22022. _cameraL.projectionMatrix.copy( projectionMatrix );
  22023. // for right eye
  22024. xmin = -ymax * _aspect - eyeSepOnProjection;
  22025. xmax = ymax * _aspect - eyeSepOnProjection;
  22026. projectionMatrix.elements[0] = 2 * _near / ( xmax - xmin );
  22027. projectionMatrix.elements[8] = ( xmax + xmin ) / ( xmax - xmin );
  22028. _cameraR.projectionMatrix.copy( projectionMatrix );
  22029. }
  22030. _cameraL.matrixWorld.copy( camera.matrixWorld ).multiplySelf( eyeLeft );
  22031. _cameraL.position.copy( camera.position );
  22032. _cameraL.near = camera.near;
  22033. _cameraL.far = camera.far;
  22034. _render.call( _this, scene, _cameraL, _renderTargetL, true );
  22035. _cameraR.matrixWorld.copy( camera.matrixWorld ).multiplySelf( eyeRight );
  22036. _cameraR.position.copy( camera.position );
  22037. _cameraR.near = camera.near;
  22038. _cameraR.far = camera.far;
  22039. _render.call( _this, scene, _cameraR, _renderTargetR, true );
  22040. _scene.updateMatrixWorld();
  22041. _render.call( _this, _scene, _camera );
  22042. };
  22043. };
  22044. };
  22045. /**
  22046. * @author alteredq / http://alteredqualia.com/
  22047. */
  22048. if ( THREE.WebGLRenderer ) {
  22049. THREE.CrosseyedWebGLRenderer = function ( parameters ) {
  22050. THREE.WebGLRenderer.call( this, parameters );
  22051. this.autoClear = false;
  22052. var _this = this, _setSize = this.setSize, _render = this.render;
  22053. var _width, _height;
  22054. var _cameraL = new THREE.PerspectiveCamera();
  22055. _cameraL.target = new THREE.Vector3( 0, 0, 0 );
  22056. var _cameraR = new THREE.PerspectiveCamera();
  22057. _cameraR.target = new THREE.Vector3( 0, 0, 0 );
  22058. _this.separation = 10;
  22059. if ( parameters && parameters.separation !== undefined ) _this.separation = parameters.separation;
  22060. var SCREEN_WIDTH = window.innerWidth;
  22061. var SCREEN_HEIGHT = window.innerHeight;
  22062. var HALF_WIDTH = SCREEN_WIDTH / 2;
  22063. this.setSize = function ( width, height ) {
  22064. _setSize.call( _this, width, height );
  22065. _width = width/2;
  22066. _height = height;
  22067. };
  22068. this.render = function ( scene, camera, renderTarget, forceClear ) {
  22069. this.clear();
  22070. _cameraL.fov = camera.fov;
  22071. _cameraL.aspect = 0.5 * camera.aspect;
  22072. _cameraL.near = camera.near;
  22073. _cameraL.far = camera.far;
  22074. _cameraL.updateProjectionMatrix();
  22075. _cameraL.position.copy( camera.position );
  22076. _cameraL.target.copy( camera.target );
  22077. _cameraL.translateX( _this.separation );
  22078. _cameraL.lookAt( _cameraL.target );
  22079. _cameraR.projectionMatrix = _cameraL.projectionMatrix;
  22080. _cameraR.position.copy( camera.position );
  22081. _cameraR.target.copy( camera.target );
  22082. _cameraR.translateX( - _this.separation );
  22083. _cameraR.lookAt( _cameraR.target );
  22084. this.setViewport( 0, 0, _width, _height );
  22085. _render.call( _this, scene, _cameraL );
  22086. this.setViewport( _width, 0, _width, _height );
  22087. _render.call( _this, scene, _cameraR, false );
  22088. };
  22089. };
  22090. }
  22091. /**
  22092. * @author mikael emtinger / http://gomo.se/
  22093. *
  22094. */
  22095. THREE.ShaderFlares = {
  22096. 'lensFlareVertexTexture': {
  22097. vertexShader: [
  22098. "uniform vec3 screenPosition;",
  22099. "uniform vec2 scale;",
  22100. "uniform float rotation;",
  22101. "uniform int renderType;",
  22102. "uniform sampler2D occlusionMap;",
  22103. "attribute vec2 position;",
  22104. "attribute vec2 uv;",
  22105. "varying vec2 vUV;",
  22106. "varying float vVisibility;",
  22107. "void main() {",
  22108. "vUV = uv;",
  22109. "vec2 pos = position;",
  22110. "if( renderType == 2 ) {",
  22111. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) ) +",
  22112. "texture2D( occlusionMap, vec2( 0.5, 0.1 ) ) +",
  22113. "texture2D( occlusionMap, vec2( 0.9, 0.1 ) ) +",
  22114. "texture2D( occlusionMap, vec2( 0.9, 0.5 ) ) +",
  22115. "texture2D( occlusionMap, vec2( 0.9, 0.9 ) ) +",
  22116. "texture2D( occlusionMap, vec2( 0.5, 0.9 ) ) +",
  22117. "texture2D( occlusionMap, vec2( 0.1, 0.9 ) ) +",
  22118. "texture2D( occlusionMap, vec2( 0.1, 0.5 ) ) +",
  22119. "texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  22120. "vVisibility = ( visibility.r / 9.0 ) *",
  22121. "( 1.0 - visibility.g / 9.0 ) *",
  22122. "( visibility.b / 9.0 ) *",
  22123. "( 1.0 - visibility.a / 9.0 );",
  22124. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  22125. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  22126. "}",
  22127. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  22128. "}"
  22129. ].join( "\n" ),
  22130. fragmentShader: [
  22131. "precision mediump float;",
  22132. "uniform sampler2D map;",
  22133. "uniform float opacity;",
  22134. "uniform int renderType;",
  22135. "uniform vec3 color;",
  22136. "varying vec2 vUV;",
  22137. "varying float vVisibility;",
  22138. "void main() {",
  22139. // pink square
  22140. "if( renderType == 0 ) {",
  22141. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  22142. // restore
  22143. "} else if( renderType == 1 ) {",
  22144. "gl_FragColor = texture2D( map, vUV );",
  22145. // flare
  22146. "} else {",
  22147. "vec4 texture = texture2D( map, vUV );",
  22148. "texture.a *= opacity * vVisibility;",
  22149. "gl_FragColor = texture;",
  22150. "gl_FragColor.rgb *= color;",
  22151. "}",
  22152. "}"
  22153. ].join( "\n" )
  22154. },
  22155. 'lensFlare': {
  22156. vertexShader: [
  22157. "uniform vec3 screenPosition;",
  22158. "uniform vec2 scale;",
  22159. "uniform float rotation;",
  22160. "uniform int renderType;",
  22161. "attribute vec2 position;",
  22162. "attribute vec2 uv;",
  22163. "varying vec2 vUV;",
  22164. "void main() {",
  22165. "vUV = uv;",
  22166. "vec2 pos = position;",
  22167. "if( renderType == 2 ) {",
  22168. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  22169. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  22170. "}",
  22171. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  22172. "}"
  22173. ].join( "\n" ),
  22174. fragmentShader: [
  22175. "precision mediump float;",
  22176. "uniform sampler2D map;",
  22177. "uniform sampler2D occlusionMap;",
  22178. "uniform float opacity;",
  22179. "uniform int renderType;",
  22180. "uniform vec3 color;",
  22181. "varying vec2 vUV;",
  22182. "void main() {",
  22183. // pink square
  22184. "if( renderType == 0 ) {",
  22185. "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
  22186. // restore
  22187. "} else if( renderType == 1 ) {",
  22188. "gl_FragColor = texture2D( map, vUV );",
  22189. // flare
  22190. "} else {",
  22191. "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a +",
  22192. "texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a +",
  22193. "texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a +",
  22194. "texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
  22195. "visibility = ( 1.0 - visibility / 4.0 );",
  22196. "vec4 texture = texture2D( map, vUV );",
  22197. "texture.a *= opacity * visibility;",
  22198. "gl_FragColor = texture;",
  22199. "gl_FragColor.rgb *= color;",
  22200. "}",
  22201. "}"
  22202. ].join( "\n" )
  22203. }
  22204. };
  22205. /**
  22206. * @author mikael emtinger / http://gomo.se/
  22207. *
  22208. */
  22209. THREE.ShaderSprite = {
  22210. 'sprite': {
  22211. vertexShader: [
  22212. "uniform int useScreenCoordinates;",
  22213. "uniform int affectedByDistance;",
  22214. "uniform vec3 screenPosition;",
  22215. "uniform mat4 modelViewMatrix;",
  22216. "uniform mat4 projectionMatrix;",
  22217. "uniform float rotation;",
  22218. "uniform vec2 scale;",
  22219. "uniform vec2 alignment;",
  22220. "uniform vec2 uvOffset;",
  22221. "uniform vec2 uvScale;",
  22222. "attribute vec2 position;",
  22223. "attribute vec2 uv;",
  22224. "varying vec2 vUV;",
  22225. "void main() {",
  22226. "vUV = uvOffset + uv * uvScale;",
  22227. "vec2 alignedPosition = position + alignment;",
  22228. "vec2 rotatedPosition;",
  22229. "rotatedPosition.x = ( cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y ) * scale.x;",
  22230. "rotatedPosition.y = ( sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y ) * scale.y;",
  22231. "vec4 finalPosition;",
  22232. "if( useScreenCoordinates != 0 ) {",
  22233. "finalPosition = vec4( screenPosition.xy + rotatedPosition, screenPosition.z, 1.0 );",
  22234. "} else {",
  22235. "finalPosition = projectionMatrix * modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );",
  22236. "finalPosition.xy += rotatedPosition * ( affectedByDistance == 1 ? 1.0 : finalPosition.z );",
  22237. "}",
  22238. "gl_Position = finalPosition;",
  22239. "}"
  22240. ].join( "\n" ),
  22241. fragmentShader: [
  22242. "precision mediump float;",
  22243. "uniform vec3 color;",
  22244. "uniform sampler2D map;",
  22245. "uniform float opacity;",
  22246. "varying vec2 vUV;",
  22247. "void main() {",
  22248. "vec4 texture = texture2D( map, vUV );",
  22249. "gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );",
  22250. "}"
  22251. ].join( "\n" )
  22252. }
  22253. };
  22254. =======
  22255. // Three.js - http://github.com/mrdoob/three.js
  22256. 'use strict';var THREE=THREE||{REVISION:"49dev"};self.Int32Array||(self.Int32Array=Array,self.Float32Array=Array);
  22257. (function(){for(var a=0,b=["ms","moz","webkit","o"],c=0;c<b.length&&!window.requestAnimationFrame;++c){window.requestAnimationFrame=window[b[c]+"RequestAnimationFrame"];window.cancelAnimationFrame=window[b[c]+"CancelAnimationFrame"]||window[b[c]+"CancelRequestAnimationFrame"]}if(!window.requestAnimationFrame)window.requestAnimationFrame=function(b){var c=Date.now(),f=Math.max(0,16-(c-a)),g=window.setTimeout(function(){b(c+f)},f);a=c+f;return g};if(!window.cancelAnimationFrame)window.cancelAnimationFrame=
  22258. function(a){clearTimeout(a)}})();THREE.Clock=function(a){this.autoStart=a!==void 0?a:true;this.elapsedTime=this.oldTime=this.startTime=0;this.running=false};THREE.Clock.prototype.start=function(){this.oldTime=this.startTime=Date.now();this.running=true};THREE.Clock.prototype.stop=function(){this.getElapsedTime();this.running=false};THREE.Clock.prototype.getElapsedTime=function(){return this.elapsedTime=this.elapsedTime+this.getDelta()};
  22259. THREE.Clock.prototype.getDelta=function(){var a=0;this.autoStart&&!this.running&&this.start();if(this.running){var b=Date.now(),a=0.001*(b-this.oldTime);this.oldTime=b;this.elapsedTime=this.elapsedTime+a}return a};THREE.Color=function(a){a!==void 0&&this.setHex(a);return this};
  22260. THREE.Color.prototype={constructor:THREE.Color,r:1,g:1,b:1,copy:function(a){this.r=a.r;this.g=a.g;this.b=a.b;return this},copyGammaToLinear:function(a){this.r=a.r*a.r;this.g=a.g*a.g;this.b=a.b*a.b;return this},copyLinearToGamma:function(a){this.r=Math.sqrt(a.r);this.g=Math.sqrt(a.g);this.b=Math.sqrt(a.b);return this},convertGammaToLinear:function(){var a=this.r,b=this.g,c=this.b;this.r=a*a;this.g=b*b;this.b=c*c;return this},convertLinearToGamma:function(){this.r=Math.sqrt(this.r);this.g=Math.sqrt(this.g);
  22261. this.b=Math.sqrt(this.b);return this},setRGB:function(a,b,c){this.r=a;this.g=b;this.b=c;return this},setHSV:function(a,b,c){var d,e,f;if(c===0)this.r=this.g=this.b=0;else{d=Math.floor(a*6);e=a*6-d;a=c*(1-b);f=c*(1-b*e);b=c*(1-b*(1-e));switch(d){case 1:this.r=f;this.g=c;this.b=a;break;case 2:this.r=a;this.g=c;this.b=b;break;case 3:this.r=a;this.g=f;this.b=c;break;case 4:this.r=b;this.g=a;this.b=c;break;case 5:this.r=c;this.g=a;this.b=f;break;case 6:case 0:this.r=c;this.g=b;this.b=a}}return this},setHex:function(a){a=
  22262. Math.floor(a);this.r=(a>>16&255)/255;this.g=(a>>8&255)/255;this.b=(a&255)/255;return this},lerpSelf:function(a,b){this.r=this.r+(a.r-this.r)*b;this.g=this.g+(a.g-this.g)*b;this.b=this.b+(a.b-this.b)*b;return this},getHex:function(){return Math.floor(this.r*255)<<16^Math.floor(this.g*255)<<8^Math.floor(this.b*255)},getContextStyle:function(){return"rgb("+Math.floor(this.r*255)+","+Math.floor(this.g*255)+","+Math.floor(this.b*255)+")"},clone:function(){return(new THREE.Color).setRGB(this.r,this.g,this.b)}};
  22263. THREE.Vector2=function(a,b){this.x=a||0;this.y=b||0};
  22264. THREE.Vector2.prototype={constructor:THREE.Vector2,set:function(a,b){this.x=a;this.y=b;return this},copy:function(a){this.x=a.x;this.y=a.y;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;return this},addSelf:function(a){this.x=this.x+a.x;this.y=this.y+a.y;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;return this},subSelf:function(a){this.x=this.x-a.x;this.y=this.y-a.y;return this},multiplyScalar:function(a){this.x=this.x*a;this.y=this.y*a;return this},divideScalar:function(a){if(a){this.x=
  22265. this.x/a;this.y=this.y/a}else this.set(0,0);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y},lengthSq:function(){return this.x*this.x+this.y*this.y},length:function(){return Math.sqrt(this.lengthSq())},normalize:function(){return this.divideScalar(this.length())},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){var b=this.x-a.x,a=this.y-a.y;return b*b+a*a},setLength:function(a){return this.normalize().multiplyScalar(a)},
  22266. lerpSelf:function(a,b){this.x=this.x+(a.x-this.x)*b;this.y=this.y+(a.y-this.y)*b;return this},equals:function(a){return a.x===this.x&&a.y===this.y},isZero:function(){return this.lengthSq()<1.0E-4},clone:function(){return new THREE.Vector2(this.x,this.y)}};THREE.Vector3=function(a,b,c){this.x=a||0;this.y=b||0;this.z=c||0};
  22267. THREE.Vector3.prototype={constructor:THREE.Vector3,set:function(a,b,c){this.x=a;this.y=b;this.z=c;return this},setX:function(a){this.x=a;return this},setY:function(a){this.y=a;return this},setZ:function(a){this.z=a;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;return this},addSelf:function(a){this.x=this.x+a.x;this.y=this.y+a.y;this.z=this.z+a.z;return this},addScalar:function(a){this.x=this.x+a;this.y=this.y+
  22268. a;this.z=this.z+a;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this},subSelf:function(a){this.x=this.x-a.x;this.y=this.y-a.y;this.z=this.z-a.z;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x=this.x*a.x;this.y=this.y*a.y;this.z=this.z*a.z;return this},multiplyScalar:function(a){this.x=this.x*a;this.y=this.y*a;this.z=this.z*a;return this},divideSelf:function(a){this.x=this.x/a.x;this.y=
  22269. this.y/a.y;this.z=this.z/a.z;return this},divideScalar:function(a){if(a){this.x=this.x/a;this.y=this.y/a;this.z=this.z/a}else this.z=this.y=this.x=0;return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.lengthSq())},lengthManhattan:function(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)},normalize:function(){return this.divideScalar(this.length())},
  22270. setLength:function(a){return this.normalize().multiplyScalar(a)},lerpSelf:function(a,b){this.x=this.x+(a.x-this.x)*b;this.y=this.y+(a.y-this.y)*b;this.z=this.z+(a.z-this.z)*b;return this},cross:function(a,b){this.x=a.y*b.z-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){var b=this.x,c=this.y,d=this.z;this.x=c*a.z-d*a.y;this.y=d*a.x-b*a.z;this.z=b*a.y-c*a.x;return this},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){return(new THREE.Vector3).sub(this,
  22271. a).lengthSq()},getPositionFromMatrix:function(a){this.x=a.elements[12];this.y=a.elements[13];this.z=a.elements[14];return this},getRotationFromMatrix:function(a,b){var c=b?b.x:1,d=b?b.y:1,e=b?b.z:1,f=a.elements[0]/c,g=a.elements[4]/d,c=a.elements[1]/c,d=a.elements[5]/d,h=a.elements[9]/e,k=a.elements[10]/e;this.y=Math.asin(a.elements[8]/e);e=Math.cos(this.y);if(Math.abs(e)>1.0E-5){this.x=Math.atan2(-h/e,k/e);this.z=Math.atan2(-g/e,f/e)}else{this.x=0;this.z=Math.atan2(c,d)}return this},getScaleFromMatrix:function(a){var b=
  22272. this.set(a.elements[0],a.elements[1],a.elements[2]).length(),c=this.set(a.elements[4],a.elements[5],a.elements[6]).length(),a=this.set(a.elements[8],a.elements[9],a.elements[10]).length();this.x=b;this.y=c;this.z=a},equals:function(a){return a.x===this.x&&a.y===this.y&&a.z===this.z},isZero:function(){return this.lengthSq()<1.0E-4},clone:function(){return new THREE.Vector3(this.x,this.y,this.z)}};THREE.Vector4=function(a,b,c,d){this.x=a||0;this.y=b||0;this.z=c||0;this.w=d!==void 0?d:1};
  22273. THREE.Vector4.prototype={constructor:THREE.Vector4,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w!==void 0?a.w:1;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x=this.x+a.x;this.y=this.y+a.y;this.z=this.z+a.z;this.w=this.w+a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x=
  22274. this.x-a.x;this.y=this.y-a.y;this.z=this.z-a.z;this.w=this.w-a.w;return this},multiplyScalar:function(a){this.x=this.x*a;this.y=this.y*a;this.z=this.z*a;this.w=this.w*a;return this},divideScalar:function(a){if(a){this.x=this.x/a;this.y=this.y/a;this.z=this.z/a;this.w=this.w/a}else{this.z=this.y=this.x=0;this.w=1}return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z+this.w*a.w},lengthSq:function(){return this.dot(this)},length:function(){return Math.sqrt(this.lengthSq())},
  22275. normalize:function(){return this.divideScalar(this.length())},setLength:function(a){return this.normalize().multiplyScalar(a)},lerpSelf:function(a,b){this.x=this.x+(a.x-this.x)*b;this.y=this.y+(a.y-this.y)*b;this.z=this.z+(a.z-this.z)*b;this.w=this.w+(a.w-this.w)*b;return this},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)}};THREE.Frustum=function(){this.planes=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4,new THREE.Vector4]};
  22276. THREE.Frustum.prototype.setFromMatrix=function(a){var b,c=this.planes,d=a.elements,a=d[0];b=d[1];var e=d[2],f=d[3],g=d[4],h=d[5],k=d[6],j=d[7],l=d[8],p=d[9],m=d[10],o=d[11],q=d[12],n=d[13],r=d[14],d=d[15];c[0].set(f-a,j-g,o-l,d-q);c[1].set(f+a,j+g,o+l,d+q);c[2].set(f+b,j+h,o+p,d+n);c[3].set(f-b,j-h,o-p,d-n);c[4].set(f-e,j-k,o-m,d-r);c[5].set(f+e,j+k,o+m,d+r);for(a=0;a<6;a++){b=c[a];b.divideScalar(Math.sqrt(b.x*b.x+b.y*b.y+b.z*b.z))}};
  22277. THREE.Frustum.prototype.contains=function(a){for(var b=this.planes,c=a.matrixWorld,d=c.elements,c=-a.geometry.boundingSphere.radius*c.getMaxScaleOnAxis(),e=0;e<6;e++){a=b[e].x*d[12]+b[e].y*d[13]+b[e].z*d[14]+b[e].w;if(a<=c)return false}return true};THREE.Frustum.__v1=new THREE.Vector3;
  22278. THREE.Ray=function(a,b){function c(a,b,c){q.sub(c,a);u=q.dot(b);t=n.add(a,r.copy(b).multiplyScalar(u));return w=c.distanceTo(t)}function d(a,b,c,d){q.sub(d,b);n.sub(c,b);r.sub(a,b);s=q.dot(q);x=q.dot(n);F=q.dot(r);D=n.dot(n);z=n.dot(r);v=1/(s*D-x*x);A=(D*F-x*z)*v;J=(s*z-x*F)*v;return A>=0&&J>=0&&A+J<1}this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3;var e=1.0E-4;this.setPrecision=function(a){e=a};var f=new THREE.Vector3,g=new THREE.Vector3,h=new THREE.Vector3,k=new THREE.Vector3,
  22279. j=new THREE.Vector3,l=new THREE.Vector3,p=new THREE.Vector3,m=new THREE.Vector3,o=new THREE.Vector3;this.intersectObject=function(a){var b,n=[];if(a instanceof THREE.Particle){var q=c(this.origin,this.direction,a.matrixWorld.getPosition());if(q>a.scale.x)return[];b={distance:q,point:a.position,face:null,object:a};n.push(b)}else if(a instanceof THREE.Mesh){var q=c(this.origin,this.direction,a.matrixWorld.getPosition()),r=THREE.Frustum.__v1.set(a.matrixWorld.getColumnX().length(),a.matrixWorld.getColumnY().length(),
  22280. a.matrixWorld.getColumnZ().length());if(q>a.geometry.boundingSphere.radius*Math.max(r.x,Math.max(r.y,r.z)))return n;var s,i,u=a.geometry,t=u.vertices,C;a.matrixRotationWorld.extractRotation(a.matrixWorld);q=0;for(r=u.faces.length;q<r;q++){b=u.faces[q];j.copy(this.origin);l.copy(this.direction);C=a.matrixWorld;p=C.multiplyVector3(p.copy(b.centroid)).subSelf(j);m=a.matrixRotationWorld.multiplyVector3(m.copy(b.normal));s=l.dot(m);if(!(Math.abs(s)<e)){i=m.dot(p)/s;if(!(i<0)&&(a.doubleSided||(a.flipSided?
  22281. s>0:s<0))){o.add(j,l.multiplyScalar(i));if(b instanceof THREE.Face3){f=C.multiplyVector3(f.copy(t[b.a]));g=C.multiplyVector3(g.copy(t[b.b]));h=C.multiplyVector3(h.copy(t[b.c]));if(d(o,f,g,h)){b={distance:j.distanceTo(o),point:o.clone(),face:b,object:a};n.push(b)}}else if(b instanceof THREE.Face4){f=C.multiplyVector3(f.copy(t[b.a]));g=C.multiplyVector3(g.copy(t[b.b]));h=C.multiplyVector3(h.copy(t[b.c]));k=C.multiplyVector3(k.copy(t[b.d]));if(d(o,f,g,k)||d(o,g,h,k)){b={distance:j.distanceTo(o),point:o.clone(),
  22282. face:b,object:a};n.push(b)}}}}}}return n};this.intersectObjects=function(a){for(var b=[],c=0,d=a.length;c<d;c++)Array.prototype.push.apply(b,this.intersectObject(a[c]));b.sort(function(a,b){return a.distance-b.distance});return b};var q=new THREE.Vector3,n=new THREE.Vector3,r=new THREE.Vector3,u,t,w,s,x,F,D,z,v,A,J};
  22283. THREE.Rectangle=function(){function a(){f=d-b;g=e-c}var b,c,d,e,f,g,h=true;this.getX=function(){return b};this.getY=function(){return c};this.getWidth=function(){return f};this.getHeight=function(){return g};this.getLeft=function(){return b};this.getTop=function(){return c};this.getRight=function(){return d};this.getBottom=function(){return e};this.set=function(f,g,l,p){h=false;b=f;c=g;d=l;e=p;a()};this.addPoint=function(f,g){if(h){h=false;b=f;c=g;d=f;e=g}else{b=b<f?b:f;c=c<g?c:g;d=d>f?d:f;e=e>g?
  22284. e:g}a()};this.add3Points=function(f,g,l,p,m,o){if(h){h=false;b=f<l?f<m?f:m:l<m?l:m;c=g<p?g<o?g:o:p<o?p:o;d=f>l?f>m?f:m:l>m?l:m;e=g>p?g>o?g:o:p>o?p:o}else{b=f<l?f<m?f<b?f:b:m<b?m:b:l<m?l<b?l:b:m<b?m:b;c=g<p?g<o?g<c?g:c:o<c?o:c:p<o?p<c?p:c:o<c?o:c;d=f>l?f>m?f>d?f:d:m>d?m:d:l>m?l>d?l:d:m>d?m:d;e=g>p?g>o?g>e?g:e:o>e?o:e:p>o?p>e?p:e:o>e?o:e}a()};this.addRectangle=function(f){if(h){h=false;b=f.getLeft();c=f.getTop();d=f.getRight();e=f.getBottom()}else{b=b<f.getLeft()?b:f.getLeft();c=c<f.getTop()?c:f.getTop();
  22285. d=d>f.getRight()?d:f.getRight();e=e>f.getBottom()?e:f.getBottom()}a()};this.inflate=function(f){b=b-f;c=c-f;d=d+f;e=e+f;a()};this.minSelf=function(f){b=b>f.getLeft()?b:f.getLeft();c=c>f.getTop()?c:f.getTop();d=d<f.getRight()?d:f.getRight();e=e<f.getBottom()?e:f.getBottom();a()};this.intersects=function(a){return d<a.getLeft()||b>a.getRight()||e<a.getTop()||c>a.getBottom()?false:true};this.empty=function(){h=true;e=d=c=b=0;a()};this.isEmpty=function(){return h}};
  22286. THREE.Math={clamp:function(a,b,c){return a<b?b:a>c?c:a},clampBottom:function(a,b){return a<b?b:a},mapLinear:function(a,b,c,d,e){return d+(a-b)*(e-d)/(c-b)},random16:function(){return(65280*Math.random()+255*Math.random())/65535},randInt:function(a,b){return a+Math.floor(Math.random()*(b-a+1))},randFloat:function(a,b){return a+Math.random()*(b-a)},randFloatSpread:function(a){return a*(0.5-Math.random())},sign:function(a){return a<0?-1:a>0?1:0}};THREE.Matrix3=function(){this.elements=new Float32Array(9)};
  22287. THREE.Matrix3.prototype={constructor:THREE.Matrix3,getInverse:function(a){var b=a.elements,a=b[10]*b[5]-b[6]*b[9],c=-b[10]*b[1]+b[2]*b[9],d=b[6]*b[1]-b[2]*b[5],e=-b[10]*b[4]+b[6]*b[8],f=b[10]*b[0]-b[2]*b[8],g=-b[6]*b[0]+b[2]*b[4],h=b[9]*b[4]-b[5]*b[8],k=-b[9]*b[0]+b[1]*b[8],j=b[5]*b[0]-b[1]*b[4],b=b[0]*a+b[1]*e+b[2]*h;b===0&&console.warn("Matrix3.getInverse(): determinant == 0");var b=1/b,l=this.elements;l[0]=b*a;l[1]=b*c;l[2]=b*d;l[3]=b*e;l[4]=b*f;l[5]=b*g;l[6]=b*h;l[7]=b*k;l[8]=b*j;return this},
  22288. transpose:function(){var a,b=this.elements;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this},transposeIntoArray:function(a){var b=this.m;a[0]=b[0];a[1]=b[3];a[2]=b[6];a[3]=b[1];a[4]=b[4];a[5]=b[7];a[6]=b[2];a[7]=b[5];a[8]=b[8];return this}};THREE.Matrix4=function(a,b,c,d,e,f,g,h,k,j,l,p,m,o,q,n){this.elements=new Float32Array(16);this.set(a!==void 0?a:1,b||0,c||0,d||0,e||0,f!==void 0?f:1,g||0,h||0,k||0,j||0,l!==void 0?l:1,p||0,m||0,o||0,q||0,n!==void 0?n:1)};
  22289. THREE.Matrix4.prototype={constructor:THREE.Matrix4,set:function(a,b,c,d,e,f,g,h,k,j,l,p,m,o,q,n){var r=this.elements;r[0]=a;r[4]=b;r[8]=c;r[12]=d;r[1]=e;r[5]=f;r[9]=g;r[13]=h;r[2]=k;r[6]=j;r[10]=l;r[14]=p;r[3]=m;r[7]=o;r[11]=q;r[15]=n;return this},identity:function(){this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);return this},copy:function(a){a=a.elements;this.set(a[0],a[4],a[8],a[12],a[1],a[5],a[9],a[13],a[2],a[6],a[10],a[14],a[3],a[7],a[11],a[15]);return this},lookAt:function(a,b,c){var d=this.elements,
  22290. e=THREE.Matrix4.__v1,f=THREE.Matrix4.__v2,g=THREE.Matrix4.__v3;g.sub(a,b).normalize();if(g.length()===0)g.z=1;e.cross(c,g).normalize();if(e.length()===0){g.x=g.x+1.0E-4;e.cross(c,g).normalize()}f.cross(g,e);d[0]=e.x;d[4]=f.x;d[8]=g.x;d[1]=e.y;d[5]=f.y;d[9]=g.y;d[2]=e.z;d[6]=f.z;d[10]=g.z;return this},multiply:function(a,b){var c=a.elements,d=b.elements,e=this.elements,f=c[0],g=c[4],h=c[8],k=c[12],j=c[1],l=c[5],p=c[9],m=c[13],o=c[2],q=c[6],n=c[10],r=c[14],u=c[3],t=c[7],w=c[11],c=c[15],s=d[0],x=d[4],
  22291. F=d[8],D=d[12],z=d[1],v=d[5],A=d[9],J=d[13],K=d[2],R=d[6],P=d[10],E=d[14],M=d[3],G=d[7],i=d[11],d=d[15];e[0]=f*s+g*z+h*K+k*M;e[4]=f*x+g*v+h*R+k*G;e[8]=f*F+g*A+h*P+k*i;e[12]=f*D+g*J+h*E+k*d;e[1]=j*s+l*z+p*K+m*M;e[5]=j*x+l*v+p*R+m*G;e[9]=j*F+l*A+p*P+m*i;e[13]=j*D+l*J+p*E+m*d;e[2]=o*s+q*z+n*K+r*M;e[6]=o*x+q*v+n*R+r*G;e[10]=o*F+q*A+n*P+r*i;e[14]=o*D+q*J+n*E+r*d;e[3]=u*s+t*z+w*K+c*M;e[7]=u*x+t*v+w*R+c*G;e[11]=u*F+t*A+w*P+c*i;e[15]=u*D+t*J+w*E+c*d;return this},multiplySelf:function(a){return this.multiply(this,
  22292. a)},multiplyToArray:function(a,b,c){var d=this.elements;this.multiply(a,b);c[0]=d[0];c[1]=d[1];c[2]=d[2];c[3]=d[3];c[4]=d[4];c[5]=d[5];c[6]=d[6];c[7]=d[7];c[8]=d[8];c[9]=d[9];c[10]=d[10];c[11]=d[11];c[12]=d[12];c[13]=d[13];c[14]=d[14];c[15]=d[15];return this},multiplyScalar:function(a){var b=this.elements;b[0]=b[0]*a;b[4]=b[4]*a;b[8]=b[8]*a;b[12]=b[12]*a;b[1]=b[1]*a;b[5]=b[5]*a;b[9]=b[9]*a;b[13]=b[13]*a;b[2]=b[2]*a;b[6]=b[6]*a;b[10]=b[10]*a;b[14]=b[14]*a;b[3]=b[3]*a;b[7]=b[7]*a;b[11]=b[11]*a;b[15]=
  22293. b[15]*a;return this},multiplyVector3:function(a){var b=this.elements,c=a.x,d=a.y,e=a.z,f=1/(b[3]*c+b[7]*d+b[11]*e+b[15]);a.x=(b[0]*c+b[4]*d+b[8]*e+b[12])*f;a.y=(b[1]*c+b[5]*d+b[9]*e+b[13])*f;a.z=(b[2]*c+b[6]*d+b[10]*e+b[14])*f;return a},multiplyVector4:function(a){var b=this.elements,c=a.x,d=a.y,e=a.z,f=a.w;a.x=b[0]*c+b[4]*d+b[8]*e+b[12]*f;a.y=b[1]*c+b[5]*d+b[9]*e+b[13]*f;a.z=b[2]*c+b[6]*d+b[10]*e+b[14]*f;a.w=b[3]*c+b[7]*d+b[11]*e+b[15]*f;return a},rotateAxis:function(a){var b=this.elements,c=a.x,
  22294. d=a.y,e=a.z;a.x=c*b[0]+d*b[4]+e*b[8];a.y=c*b[1]+d*b[5]+e*b[9];a.z=c*b[2]+d*b[6]+e*b[10];a.normalize();return a},crossVector:function(a){var b=this.elements,c=new THREE.Vector4;c.x=b[0]*a.x+b[4]*a.y+b[8]*a.z+b[12]*a.w;c.y=b[1]*a.x+b[5]*a.y+b[9]*a.z+b[13]*a.w;c.z=b[2]*a.x+b[6]*a.y+b[10]*a.z+b[14]*a.w;c.w=a.w?b[3]*a.x+b[7]*a.y+b[11]*a.z+b[15]*a.w:1;return c},determinant:function(){var a=this.elements,b=a[0],c=a[4],d=a[8],e=a[12],f=a[1],g=a[5],h=a[9],k=a[13],j=a[2],l=a[6],p=a[10],m=a[14],o=a[3],q=a[7],
  22295. n=a[11],a=a[15];return e*h*l*o-d*k*l*o-e*g*p*o+c*k*p*o+d*g*m*o-c*h*m*o-e*h*j*q+d*k*j*q+e*f*p*q-b*k*p*q-d*f*m*q+b*h*m*q+e*g*j*n-c*k*j*n-e*f*l*n+b*k*l*n+c*f*m*n-b*g*m*n-d*g*j*a+c*h*j*a+d*f*l*a-b*h*l*a-c*f*p*a+b*g*p*a},transpose:function(){var a=this.elements,b;b=a[1];a[1]=a[4];a[4]=b;b=a[2];a[2]=a[8];a[8]=b;b=a[6];a[6]=a[9];a[9]=b;b=a[3];a[3]=a[12];a[12]=b;b=a[7];a[7]=a[13];a[13]=b;b=a[11];a[11]=a[14];a[14]=b;return this},flattenToArray:function(a){var b=this.elements;a[0]=b[0];a[1]=b[1];a[2]=b[2];
  22296. a[3]=b[3];a[4]=b[4];a[5]=b[5];a[6]=b[6];a[7]=b[7];a[8]=b[8];a[9]=b[9];a[10]=b[10];a[11]=b[11];a[12]=b[12];a[13]=b[13];a[14]=b[14];a[15]=b[15];return a},flattenToArrayOffset:function(a,b){var c=this.elements;a[b]=c[0];a[b+1]=c[1];a[b+2]=c[2];a[b+3]=c[3];a[b+4]=c[4];a[b+5]=c[5];a[b+6]=c[6];a[b+7]=c[7];a[b+8]=c[8];a[b+9]=c[9];a[b+10]=c[10];a[b+11]=c[11];a[b+12]=c[12];a[b+13]=c[13];a[b+14]=c[14];a[b+15]=c[15];return a},getPosition:function(){var a=this.elements;return THREE.Matrix4.__v1.set(a[12],a[13],
  22297. a[14])},setPosition:function(a){var b=this.elements;b[12]=a.x;b[13]=a.y;b[14]=a.z;return this},getColumnX:function(){var a=this.elements;return THREE.Matrix4.__v1.set(a[0],a[1],a[2])},getColumnY:function(){var a=this.elements;return THREE.Matrix4.__v1.set(a[4],a[5],a[6])},getColumnZ:function(){var a=this.elements;return THREE.Matrix4.__v1.set(a[8],a[9],a[10])},getInverse:function(a){var b=this.elements,c=a.elements,d=c[0],e=c[4],f=c[8],g=c[12],h=c[1],k=c[5],j=c[9],l=c[13],p=c[2],m=c[6],o=c[10],q=
  22298. c[14],n=c[3],r=c[7],u=c[11],c=c[15];b[0]=j*q*r-l*o*r+l*m*u-k*q*u-j*m*c+k*o*c;b[4]=g*o*r-f*q*r-g*m*u+e*q*u+f*m*c-e*o*c;b[8]=f*l*r-g*j*r+g*k*u-e*l*u-f*k*c+e*j*c;b[12]=g*j*m-f*l*m-g*k*o+e*l*o+f*k*q-e*j*q;b[1]=l*o*n-j*q*n-l*p*u+h*q*u+j*p*c-h*o*c;b[5]=f*q*n-g*o*n+g*p*u-d*q*u-f*p*c+d*o*c;b[9]=g*j*n-f*l*n-g*h*u+d*l*u+f*h*c-d*j*c;b[13]=f*l*p-g*j*p+g*h*o-d*l*o-f*h*q+d*j*q;b[2]=k*q*n-l*m*n+l*p*r-h*q*r-k*p*c+h*m*c;b[6]=g*m*n-e*q*n-g*p*r+d*q*r+e*p*c-d*m*c;b[10]=e*l*n-g*k*n+g*h*r-d*l*r-e*h*c+d*k*c;b[14]=g*k*p-
  22299. e*l*p-g*h*m+d*l*m+e*h*q-d*k*q;b[3]=j*m*n-k*o*n-j*p*r+h*o*r+k*p*u-h*m*u;b[7]=e*o*n-f*m*n+f*p*r-d*o*r-e*p*u+d*m*u;b[11]=f*k*n-e*j*n-f*h*r+d*j*r+e*h*u-d*k*u;b[15]=e*j*p-f*k*p+f*h*m-d*j*m-e*h*o+d*k*o;this.multiplyScalar(1/a.determinant());return this},setRotationFromEuler:function(a,b){var c=this.elements,d=a.x,e=a.y,f=a.z,g=Math.cos(d),d=Math.sin(d),h=Math.cos(e),e=Math.sin(e),k=Math.cos(f),f=Math.sin(f);switch(b){case "YXZ":var j=h*k,l=h*f,p=e*k,m=e*f;c[0]=j+m*d;c[4]=p*d-l;c[8]=g*e;c[1]=g*f;c[5]=g*
  22300. k;c[9]=-d;c[2]=l*d-p;c[6]=m+j*d;c[10]=g*h;break;case "ZXY":j=h*k;l=h*f;p=e*k;m=e*f;c[0]=j-m*d;c[4]=-g*f;c[8]=p+l*d;c[1]=l+p*d;c[5]=g*k;c[9]=m-j*d;c[2]=-g*e;c[6]=d;c[10]=g*h;break;case "ZYX":j=g*k;l=g*f;p=d*k;m=d*f;c[0]=h*k;c[4]=p*e-l;c[8]=j*e+m;c[1]=h*f;c[5]=m*e+j;c[9]=l*e-p;c[2]=-e;c[6]=d*h;c[10]=g*h;break;case "YZX":j=g*h;l=g*e;p=d*h;m=d*e;c[0]=h*k;c[4]=m-j*f;c[8]=p*f+l;c[1]=f;c[5]=g*k;c[9]=-d*k;c[2]=-e*k;c[6]=l*f+p;c[10]=j-m*f;break;case "XZY":j=g*h;l=g*e;p=d*h;m=d*e;c[0]=h*k;c[4]=-f;c[8]=e*k;
  22301. c[1]=j*f+m;c[5]=g*k;c[9]=l*f-p;c[2]=p*f-l;c[6]=d*k;c[10]=m*f+j;break;default:j=g*k;l=g*f;p=d*k;m=d*f;c[0]=h*k;c[4]=-h*f;c[8]=e;c[1]=l+p*e;c[5]=j-m*e;c[9]=-d*h;c[2]=m-j*e;c[6]=p+l*e;c[10]=g*h}return this},setRotationFromQuaternion:function(a){var b=this.elements,c=a.x,d=a.y,e=a.z,f=a.w,g=c+c,h=d+d,k=e+e,a=c*g,j=c*h,c=c*k,l=d*h,d=d*k,e=e*k,g=f*g,h=f*h,f=f*k;b[0]=1-(l+e);b[4]=j-f;b[8]=c+h;b[1]=j+f;b[5]=1-(a+e);b[9]=d-g;b[2]=c-h;b[6]=d+g;b[10]=1-(a+l);return this},compose:function(a,b,c){var d=this.elements,
  22302. e=THREE.Matrix4.__m1,f=THREE.Matrix4.__m2;e.identity();e.setRotationFromQuaternion(b);f.makeScale(c.x,c.y,c.z);this.multiply(e,f);d[12]=a.x;d[13]=a.y;d[14]=a.z;return this},decompose:function(a,b,c){var d=this.elements,e=THREE.Matrix4.__v1,f=THREE.Matrix4.__v2,g=THREE.Matrix4.__v3;e.set(d[0],d[1],d[2]);f.set(d[4],d[5],d[6]);g.set(d[8],d[9],d[10]);a=a instanceof THREE.Vector3?a:new THREE.Vector3;b=b instanceof THREE.Quaternion?b:new THREE.Quaternion;c=c instanceof THREE.Vector3?c:new THREE.Vector3;
  22303. c.x=e.length();c.y=f.length();c.z=g.length();a.x=d[12];a.y=d[13];a.z=d[14];d=THREE.Matrix4.__m1;d.copy(this);d.elements[0]=d.elements[0]/c.x;d.elements[1]=d.elements[1]/c.x;d.elements[2]=d.elements[2]/c.x;d.elements[4]=d.elements[4]/c.y;d.elements[5]=d.elements[5]/c.y;d.elements[6]=d.elements[6]/c.y;d.elements[8]=d.elements[8]/c.z;d.elements[9]=d.elements[9]/c.z;d.elements[10]=d.elements[10]/c.z;b.setFromRotationMatrix(d);return[a,b,c]},extractPosition:function(a){var b=this.elements,a=a.elements;
  22304. b[12]=a[12];b[13]=a[13];b[14]=a[14];return this},extractRotation:function(a){var b=this.elements,a=a.elements,c=THREE.Matrix4.__v1,d=1/c.set(a[0],a[1],a[2]).length(),e=1/c.set(a[4],a[5],a[6]).length(),c=1/c.set(a[8],a[9],a[10]).length();b[0]=a[0]*d;b[1]=a[1]*d;b[2]=a[2]*d;b[4]=a[4]*e;b[5]=a[5]*e;b[6]=a[6]*e;b[8]=a[8]*c;b[9]=a[9]*c;b[10]=a[10]*c;return this},translate:function(a){var b=this.elements,c=a.x,d=a.y,a=a.z;b[12]=b[0]*c+b[4]*d+b[8]*a+b[12];b[13]=b[1]*c+b[5]*d+b[9]*a+b[13];b[14]=b[2]*c+b[6]*
  22305. d+b[10]*a+b[14];b[15]=b[3]*c+b[7]*d+b[11]*a+b[15];return this},rotateX:function(a){var b=this.elements,c=b[4],d=b[5],e=b[6],f=b[7],g=b[8],h=b[9],k=b[10],j=b[11],l=Math.cos(a),a=Math.sin(a);b[4]=l*c+a*g;b[5]=l*d+a*h;b[6]=l*e+a*k;b[7]=l*f+a*j;b[8]=l*g-a*c;b[9]=l*h-a*d;b[10]=l*k-a*e;b[11]=l*j-a*f;return this},rotateY:function(a){var b=this.elements,c=b[0],d=b[1],e=b[2],f=b[3],g=b[8],h=b[9],k=b[10],j=b[11],l=Math.cos(a),a=Math.sin(a);b[0]=l*c-a*g;b[1]=l*d-a*h;b[2]=l*e-a*k;b[3]=l*f-a*j;b[8]=l*g+a*c;b[9]=
  22306. l*h+a*d;b[10]=l*k+a*e;b[11]=l*j+a*f;return this},rotateZ:function(a){var b=this.elements,c=b[0],d=b[1],e=b[2],f=b[3],g=b[4],h=b[5],k=b[6],j=b[7],l=Math.cos(a),a=Math.sin(a);b[0]=l*c+a*g;b[1]=l*d+a*h;b[2]=l*e+a*k;b[3]=l*f+a*j;b[4]=l*g-a*c;b[5]=l*h-a*d;b[6]=l*k-a*e;b[7]=l*j-a*f;return this},rotateByAxis:function(a,b){var c=this.elements;if(a.x===1&&a.y===0&&a.z===0)return this.rotateX(b);if(a.x===0&&a.y===1&&a.z===0)return this.rotateY(b);if(a.x===0&&a.y===0&&a.z===1)return this.rotateZ(b);var d=a.x,
  22307. e=a.y,f=a.z,g=Math.sqrt(d*d+e*e+f*f),d=d/g,e=e/g,f=f/g,g=d*d,h=e*e,k=f*f,j=Math.cos(b),l=Math.sin(b),p=1-j,m=d*e*p,o=d*f*p,p=e*f*p,d=d*l,q=e*l,l=f*l,f=g+(1-g)*j,g=m+l,e=o-q,m=m-l,h=h+(1-h)*j,l=p+d,o=o+q,p=p-d,k=k+(1-k)*j,j=c[0],d=c[1],q=c[2],n=c[3],r=c[4],u=c[5],t=c[6],w=c[7],s=c[8],x=c[9],F=c[10],D=c[11];c[0]=f*j+g*r+e*s;c[1]=f*d+g*u+e*x;c[2]=f*q+g*t+e*F;c[3]=f*n+g*w+e*D;c[4]=m*j+h*r+l*s;c[5]=m*d+h*u+l*x;c[6]=m*q+h*t+l*F;c[7]=m*n+h*w+l*D;c[8]=o*j+p*r+k*s;c[9]=o*d+p*u+k*x;c[10]=o*q+p*t+k*F;c[11]=
  22308. o*n+p*w+k*D;return this},scale:function(a){var b=this.elements,c=a.x,d=a.y,a=a.z;b[0]=b[0]*c;b[4]=b[4]*d;b[8]=b[8]*a;b[1]=b[1]*c;b[5]=b[5]*d;b[9]=b[9]*a;b[2]=b[2]*c;b[6]=b[6]*d;b[10]=b[10]*a;b[3]=b[3]*c;b[7]=b[7]*d;b[11]=b[11]*a;return this},getMaxScaleOnAxis:function(){var a=this.elements;return Math.sqrt(Math.max(a[0]*a[0]+a[1]*a[1]+a[2]*a[2],Math.max(a[4]*a[4]+a[5]*a[5]+a[6]*a[6],a[8]*a[8]+a[9]*a[9]+a[10]*a[10])))},makeTranslation:function(a,b,c){this.set(1,0,0,a,0,1,0,b,0,0,1,c,0,0,0,1);return this},
  22309. makeRotationX:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(1,0,0,0,0,b,-a,0,0,a,b,0,0,0,0,1);return this},makeRotationY:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(b,0,a,0,0,1,0,0,-a,0,b,0,0,0,0,1);return this},makeRotationZ:function(a){var b=Math.cos(a),a=Math.sin(a);this.set(b,-a,0,0,a,b,0,0,0,0,1,0,0,0,0,1);return this},makeRotationAxis:function(a,b){var c=Math.cos(b),d=Math.sin(b),e=1-c,f=a.x,g=a.y,h=a.z,k=e*f,j=e*g;this.set(k*f+c,k*g-d*h,k*h+d*g,0,k*g+d*h,j*g+c,j*h-d*f,0,k*h-
  22310. d*g,j*h+d*f,e*h*h+c,0,0,0,0,1);return this},makeScale:function(a,b,c){this.set(a,0,0,0,0,b,0,0,0,0,c,0,0,0,0,1);return this},makeFrustum:function(a,b,c,d,e,f){var g=this.elements;g[0]=2*e/(b-a);g[4]=0;g[8]=(b+a)/(b-a);g[12]=0;g[1]=0;g[5]=2*e/(d-c);g[9]=(d+c)/(d-c);g[13]=0;g[2]=0;g[6]=0;g[10]=-(f+e)/(f-e);g[14]=-2*f*e/(f-e);g[3]=0;g[7]=0;g[11]=-1;g[15]=0;return this},makePerspective:function(a,b,c,d){var a=c*Math.tan(a*Math.PI/360),e=-a;return this.makeFrustum(e*b,a*b,e,a,c,d)},makeOrthographic:function(a,
  22311. b,c,d,e,f){var g=this.elements,h=b-a,k=c-d,j=f-e;g[0]=2/h;g[4]=0;g[8]=0;g[12]=-((b+a)/h);g[1]=0;g[5]=2/k;g[9]=0;g[13]=-((c+d)/k);g[2]=0;g[6]=0;g[10]=-2/j;g[14]=-((f+e)/j);g[3]=0;g[7]=0;g[11]=0;g[15]=1;return this},clone:function(){var a=this.elements;return new THREE.Matrix4(a[0],a[4],a[8],a[12],a[1],a[5],a[9],a[13],a[2],a[6],a[10],a[14],a[3],a[7],a[11],a[15])}};THREE.Matrix4.__v1=new THREE.Vector3;THREE.Matrix4.__v2=new THREE.Vector3;THREE.Matrix4.__v3=new THREE.Vector3;THREE.Matrix4.__m1=new THREE.Matrix4;
  22312. THREE.Matrix4.__m2=new THREE.Matrix4;
  22313. THREE.Object3D=function(){this.id=THREE.Object3DCount++;this.name="";this.parent=void 0;this.children=[];this.up=new THREE.Vector3(0,1,0);this.position=new THREE.Vector3;this.rotation=new THREE.Vector3;this.eulerOrder="XYZ";this.scale=new THREE.Vector3(1,1,1);this.flipSided=this.doubleSided=false;this.renderDepth=null;this.rotationAutoUpdate=true;this.matrix=new THREE.Matrix4;this.matrixWorld=new THREE.Matrix4;this.matrixRotationWorld=new THREE.Matrix4;this.matrixWorldNeedsUpdate=this.matrixAutoUpdate=
  22314. true;this.quaternion=new THREE.Quaternion;this.useQuaternion=false;this.boundRadius=0;this.boundRadiusScale=1;this.visible=true;this.receiveShadow=this.castShadow=false;this.frustumCulled=true;this._vector=new THREE.Vector3};
  22315. THREE.Object3D.prototype={constructor:THREE.Object3D,applyMatrix:function(a){this.matrix.multiply(a,this.matrix);this.scale.getScaleFromMatrix(this.matrix);this.rotation.getRotationFromMatrix(this.matrix,this.scale);this.position.getPositionFromMatrix(this.matrix)},translate:function(a,b){this.matrix.rotateAxis(b);this.position.addSelf(b.multiplyScalar(a))},translateX:function(a){this.translate(a,this._vector.set(1,0,0))},translateY:function(a){this.translate(a,this._vector.set(0,1,0))},translateZ:function(a){this.translate(a,
  22316. this._vector.set(0,0,1))},lookAt:function(a){this.matrix.lookAt(a,this.position,this.up);this.rotationAutoUpdate&&this.rotation.getRotationFromMatrix(this.matrix)},add:function(a){if(a===this)console.warn("THREE.Object3D.add: An object can't be added as a child of itself.");else if(a instanceof THREE.Object3D){a.parent!==void 0&&a.parent.remove(a);a.parent=this;this.children.push(a);for(var b=this;b.parent!==void 0;)b=b.parent;b!==void 0&&b instanceof THREE.Scene&&b.__addObject(a)}},remove:function(a){var b=
  22317. this.children.indexOf(a);if(b!==-1){a.parent=void 0;this.children.splice(b,1);for(b=this;b.parent!==void 0;)b=b.parent;b!==void 0&&b instanceof THREE.Scene&&b.__removeObject(a)}},getChildByName:function(a,b){var c,d,e;c=0;for(d=this.children.length;c<d;c++){e=this.children[c];if(e.name===a)return e;if(b){e=e.getChildByName(a,b);if(e!==void 0)return e}}},updateMatrix:function(){this.matrix.setPosition(this.position);this.useQuaternion?this.matrix.setRotationFromQuaternion(this.quaternion):this.matrix.setRotationFromEuler(this.rotation,
  22318. this.eulerOrder);if(this.scale.x!==1||this.scale.y!==1||this.scale.z!==1){this.matrix.scale(this.scale);this.boundRadiusScale=Math.max(this.scale.x,Math.max(this.scale.y,this.scale.z))}this.matrixWorldNeedsUpdate=true},updateMatrixWorld:function(a){this.matrixAutoUpdate&&this.updateMatrix();if(this.matrixWorldNeedsUpdate||a){this.parent?this.matrixWorld.multiply(this.parent.matrixWorld,this.matrix):this.matrixWorld.copy(this.matrix);this.matrixWorldNeedsUpdate=false;a=true}for(var b=0,c=this.children.length;b<
  22319. c;b++)this.children[b].updateMatrixWorld(a)}};THREE.Object3DCount=0;
  22320. THREE.Projector=function(){function a(){var a=g[f]=g[f]||new THREE.RenderableObject;f++;return a}function b(){var a=j[k]=j[k]||new THREE.RenderableVertex;k++;return a}function c(a,b){return b.z-a.z}function d(a,b){var c=0,d=1,e=a.z+a.w,f=b.z+b.w,g=-a.z+a.w,h=-b.z+b.w;if(e>=0&&f>=0&&g>=0&&h>=0)return true;if(e<0&&f<0||g<0&&h<0)return false;e<0?c=Math.max(c,e/(e-f)):f<0&&(d=Math.min(d,e/(e-f)));g<0?c=Math.max(c,g/(g-h)):h<0&&(d=Math.min(d,g/(g-h)));if(d<c)return false;a.lerpSelf(b,c);b.lerpSelf(a,1-
  22321. d);return true}var e,f,g=[],h,k,j=[],l,p,m=[],o,q=[],n,r,u=[],t,w,s=[],x={objects:[],sprites:[],lights:[],elements:[]},F=new THREE.Vector3,D=new THREE.Vector4,z=new THREE.Matrix4,v=new THREE.Matrix4,A=new THREE.Frustum,J=new THREE.Vector4,K=new THREE.Vector4;this.projectVector=function(a,b){b.matrixWorldInverse.getInverse(b.matrixWorld);z.multiply(b.projectionMatrix,b.matrixWorldInverse);z.multiplyVector3(a);return a};this.unprojectVector=function(a,b){b.projectionMatrixInverse.getInverse(b.projectionMatrix);
  22322. z.multiply(b.matrixWorld,b.projectionMatrixInverse);z.multiplyVector3(a);return a};this.pickingRay=function(a,b){var c;a.z=-1;c=new THREE.Vector3(a.x,a.y,1);this.unprojectVector(a,b);this.unprojectVector(c,b);c.subSelf(a).normalize();return new THREE.Ray(a,c)};this.projectGraph=function(b,d){f=0;x.objects.length=0;x.sprites.length=0;x.lights.length=0;var g=function(b){if(b.visible!==false){if((b instanceof THREE.Mesh||b instanceof THREE.Line)&&(b.frustumCulled===false||A.contains(b))){F.copy(b.matrixWorld.getPosition());
  22323. z.multiplyVector3(F);e=a();e.object=b;e.z=F.z;x.objects.push(e)}else if(b instanceof THREE.Sprite||b instanceof THREE.Particle){F.copy(b.matrixWorld.getPosition());z.multiplyVector3(F);e=a();e.object=b;e.z=F.z;x.sprites.push(e)}else b instanceof THREE.Light&&x.lights.push(b);for(var c=0,d=b.children.length;c<d;c++)g(b.children[c])}};g(b);d&&x.objects.sort(c);return x};this.projectScene=function(a,e,f){var g=e.near,G=e.far,i=false,F,U,C,Y,I,ea,fa,ia,O,Q,Z,$,ha,Ma,Ka;w=r=o=p=0;x.elements.length=0;if(e.parent===
  22324. void 0){console.warn("DEPRECATED: Camera hasn't been added to a Scene. Adding it...");a.add(e)}a.updateMatrixWorld();e.matrixWorldInverse.getInverse(e.matrixWorld);z.multiply(e.projectionMatrix,e.matrixWorldInverse);A.setFromMatrix(z);x=this.projectGraph(a,false);a=0;for(F=x.objects.length;a<F;a++){O=x.objects[a].object;Q=O.matrixWorld;k=0;if(O instanceof THREE.Mesh){Z=O.geometry;$=O.geometry.materials;Y=Z.vertices;ha=Z.faces;Ma=Z.faceVertexUvs;Z=O.matrixRotationWorld.extractRotation(Q);U=0;for(C=
  22325. Y.length;U<C;U++){h=b();h.positionWorld.copy(Y[U]);Q.multiplyVector3(h.positionWorld);h.positionScreen.copy(h.positionWorld);z.multiplyVector4(h.positionScreen);h.positionScreen.x=h.positionScreen.x/h.positionScreen.w;h.positionScreen.y=h.positionScreen.y/h.positionScreen.w;h.visible=h.positionScreen.z>g&&h.positionScreen.z<G}Y=0;for(U=ha.length;Y<U;Y++){C=ha[Y];if(C instanceof THREE.Face3){I=j[C.a];ea=j[C.b];fa=j[C.c];if(I.visible&&ea.visible&&fa.visible){i=(fa.positionScreen.x-I.positionScreen.x)*
  22326. (ea.positionScreen.y-I.positionScreen.y)-(fa.positionScreen.y-I.positionScreen.y)*(ea.positionScreen.x-I.positionScreen.x)<0;if(O.doubleSided||i!=O.flipSided){ia=m[p]=m[p]||new THREE.RenderableFace3;p++;l=ia;l.v1.copy(I);l.v2.copy(ea);l.v3.copy(fa)}else continue}else continue}else if(C instanceof THREE.Face4){I=j[C.a];ea=j[C.b];fa=j[C.c];ia=j[C.d];if(I.visible&&ea.visible&&fa.visible&&ia.visible){i=(ia.positionScreen.x-I.positionScreen.x)*(ea.positionScreen.y-I.positionScreen.y)-(ia.positionScreen.y-
  22327. I.positionScreen.y)*(ea.positionScreen.x-I.positionScreen.x)<0||(ea.positionScreen.x-fa.positionScreen.x)*(ia.positionScreen.y-fa.positionScreen.y)-(ea.positionScreen.y-fa.positionScreen.y)*(ia.positionScreen.x-fa.positionScreen.x)<0;if(O.doubleSided||i!=O.flipSided){Ka=q[o]=q[o]||new THREE.RenderableFace4;o++;l=Ka;l.v1.copy(I);l.v2.copy(ea);l.v3.copy(fa);l.v4.copy(ia)}else continue}else continue}l.normalWorld.copy(C.normal);!i&&(O.flipSided||O.doubleSided)&&l.normalWorld.negate();Z.multiplyVector3(l.normalWorld);
  22328. l.centroidWorld.copy(C.centroid);Q.multiplyVector3(l.centroidWorld);l.centroidScreen.copy(l.centroidWorld);z.multiplyVector3(l.centroidScreen);fa=C.vertexNormals;I=0;for(ea=fa.length;I<ea;I++){ia=l.vertexNormalsWorld[I];ia.copy(fa[I]);!i&&(O.flipSided||O.doubleSided)&&ia.negate();Z.multiplyVector3(ia)}I=0;for(ea=Ma.length;I<ea;I++)if(Ka=Ma[I][Y]){fa=0;for(ia=Ka.length;fa<ia;fa++)l.uvs[I][fa]=Ka[fa]}l.material=O.material;l.faceMaterial=C.materialIndex!==null?$[C.materialIndex]:null;l.z=l.centroidScreen.z;
  22329. x.elements.push(l)}}else if(O instanceof THREE.Line){v.multiply(z,Q);Y=O.geometry.vertices;I=b();I.positionScreen.copy(Y[0]);v.multiplyVector4(I.positionScreen);Q=O.type===THREE.LinePieces?2:1;U=1;for(C=Y.length;U<C;U++){I=b();I.positionScreen.copy(Y[U]);v.multiplyVector4(I.positionScreen);if(!((U+1)%Q>0)){ea=j[k-2];J.copy(I.positionScreen);K.copy(ea.positionScreen);if(d(J,K)){J.multiplyScalar(1/J.w);K.multiplyScalar(1/K.w);$=u[r]=u[r]||new THREE.RenderableLine;r++;n=$;n.v1.positionScreen.copy(J);
  22330. n.v2.positionScreen.copy(K);n.z=Math.max(J.z,K.z);n.material=O.material;x.elements.push(n)}}}}}a=0;for(F=x.sprites.length;a<F;a++){O=x.sprites[a].object;Q=O.matrixWorld;if(O instanceof THREE.Particle){D.set(Q.elements[12],Q.elements[13],Q.elements[14],1);z.multiplyVector4(D);D.z=D.z/D.w;if(D.z>0&&D.z<1){g=s[w]=s[w]||new THREE.RenderableParticle;w++;t=g;t.x=D.x/D.w;t.y=D.y/D.w;t.z=D.z;t.rotation=O.rotation.z;t.scale.x=O.scale.x*Math.abs(t.x-(D.x+e.projectionMatrix.elements[0])/(D.w+e.projectionMatrix.elements[12]));
  22331. t.scale.y=O.scale.y*Math.abs(t.y-(D.y+e.projectionMatrix.elements[5])/(D.w+e.projectionMatrix.elements[13]));t.material=O.material;x.elements.push(t)}}}f&&x.elements.sort(c);return x}};THREE.Quaternion=function(a,b,c,d){this.x=a||0;this.y=b||0;this.z=c||0;this.w=d!==void 0?d:1};
  22332. THREE.Quaternion.prototype={constructor:THREE.Quaternion,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w;return this},setFromEuler:function(a){var b=Math.PI/360,c=a.x*b,d=a.y*b,e=a.z*b,a=Math.cos(d),d=Math.sin(d),b=Math.cos(-e),e=Math.sin(-e),f=Math.cos(c),c=Math.sin(c),g=a*b,h=d*e;this.w=g*f-h*c;this.x=g*c+h*f;this.y=d*b*f+a*e*c;this.z=a*e*f-d*b*c;return this},setFromAxisAngle:function(a,b){var c=b/2,d=Math.sin(c);
  22333. this.x=a.x*d;this.y=a.y*d;this.z=a.z*d;this.w=Math.cos(c);return this},setFromRotationMatrix:function(a){var b=Math.pow(a.determinant(),1/3);this.w=Math.sqrt(Math.max(0,b+a.elements[0]+a.elements[5]+a.elements[10]))/2;this.x=Math.sqrt(Math.max(0,b+a.elements[0]-a.elements[5]-a.elements[10]))/2;this.y=Math.sqrt(Math.max(0,b-a.elements[0]+a.elements[5]-a.elements[10]))/2;this.z=Math.sqrt(Math.max(0,b-a.elements[0]-a.elements[5]+a.elements[10]))/2;this.x=a.elements[6]-a.elements[9]<0?-Math.abs(this.x):
  22334. Math.abs(this.x);this.y=a.elements[8]-a.elements[2]<0?-Math.abs(this.y):Math.abs(this.y);this.z=a.elements[1]-a.elements[4]<0?-Math.abs(this.z):Math.abs(this.z);this.normalize();return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x=this.x*-1;this.y=this.y*-1;this.z=this.z*-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a=
  22335. Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);if(a===0)this.w=this.z=this.y=this.x=0;else{a=1/a;this.x=this.x*a;this.y=this.y*a;this.z=this.z*a;this.w=this.w*a}return this},multiply:function(a,b){this.x=a.x*b.w+a.y*b.z-a.z*b.y+a.w*b.x;this.y=-a.x*b.z+a.y*b.w+a.z*b.x+a.w*b.y;this.z=a.x*b.y-a.y*b.x+a.z*b.w+a.w*b.z;this.w=-a.x*b.x-a.y*b.y-a.z*b.z+a.w*b.w;return this},multiplySelf:function(a){var b=this.x,c=this.y,d=this.z,e=this.w,f=a.x,g=a.y,h=a.z,a=a.w;this.x=b*a+e*f+c*h-d*g;this.y=
  22336. c*a+e*g+d*f-b*h;this.z=d*a+e*h+b*g-c*f;this.w=e*a-b*f-c*g-d*h;return this},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,f=this.x,g=this.y,h=this.z,k=this.w,j=k*c+g*e-h*d,l=k*d+h*c-f*e,p=k*e+f*d-g*c,c=-f*c-g*d-h*e;b.x=j*k+c*-f+l*-h-p*-g;b.y=l*k+c*-g+p*-f-j*-h;b.z=p*k+c*-h+j*-g-l*-f;return b},clone:function(){return new THREE.Quaternion(this.x,this.y,this.z,this.w)}};
  22337. THREE.Quaternion.slerp=function(a,b,c,d){var e=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;if(e<0){c.w=-b.w;c.x=-b.x;c.y=-b.y;c.z=-b.z;e=-e}else c.copy(b);if(Math.abs(e)>=1){c.w=a.w;c.x=a.x;c.y=a.y;c.z=a.z;return c}var f=Math.acos(e),e=Math.sqrt(1-e*e);if(Math.abs(e)<0.001){c.w=0.5*(a.w+b.w);c.x=0.5*(a.x+b.x);c.y=0.5*(a.y+b.y);c.z=0.5*(a.z+b.z);return c}b=Math.sin((1-d)*f)/e;d=Math.sin(d*f)/e;c.w=a.w*b+c.w*d;c.x=a.x*b+c.x*d;c.y=a.y*b+c.y*d;c.z=a.z*b+c.z*d;return c};THREE.Vertex=function(){console.warn("THREE.Vertex has been DEPRECATED. Use THREE.Vector3 instead.")};
  22338. THREE.Face3=function(a,b,c,d,e,f){this.a=a;this.b=b;this.c=c;this.normal=d instanceof THREE.Vector3?d:new THREE.Vector3;this.vertexNormals=d instanceof Array?d:[];this.color=e instanceof THREE.Color?e:new THREE.Color;this.vertexColors=e instanceof Array?e:[];this.vertexTangents=[];this.materialIndex=f;this.centroid=new THREE.Vector3};
  22339. THREE.Face3.prototype={constructor:THREE.Face3,clone:function(){var a=new THREE.Face3(this.a,this.b,this.c);a.normal.copy(this.normal);a.color.copy(this.color);a.centroid.copy(this.centroid);a.materialIndex=this.materialIndex;var b,c;b=0;for(c=this.vertexNormals.length;b<c;b++)a.vertexNormals[b]=this.vertexNormals[b].clone();b=0;for(c=this.vertexColors.length;b<c;b++)a.vertexColors[b]=this.vertexColors[b].clone();b=0;for(c=this.vertexTangents.length;b<c;b++)a.vertexTangents[b]=this.vertexTangents[b].clone();
  22340. return a}};THREE.Face4=function(a,b,c,d,e,f,g){this.a=a;this.b=b;this.c=c;this.d=d;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.color=f instanceof THREE.Color?f:new THREE.Color;this.vertexColors=f instanceof Array?f:[];this.vertexTangents=[];this.materialIndex=g;this.centroid=new THREE.Vector3};
  22341. THREE.Face4.prototype={constructor:THREE.Face4,clone:function(){var a=new THREE.Face4(this.a,this.b,this.c,this.d);a.normal.copy(this.normal);a.color.copy(this.color);a.centroid.copy(this.centroid);a.materialIndex=this.materialIndex;var b,c;b=0;for(c=this.vertexNormals.length;b<c;b++)a.vertexNormals[b]=this.vertexNormals[b].clone();b=0;for(c=this.vertexColors.length;b<c;b++)a.vertexColors[b]=this.vertexColors[b].clone();b=0;for(c=this.vertexTangents.length;b<c;b++)a.vertexTangents[b]=this.vertexTangents[b].clone();
  22342. return a}};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};THREE.UV.prototype={constructor:THREE.UV,set:function(a,b){this.u=a;this.v=b;return this},copy:function(a){this.u=a.u;this.v=a.v;return this},lerpSelf:function(a,b){this.u=this.u+(a.u-this.u)*b;this.v=this.v+(a.v-this.v)*b;return this},clone:function(){return new THREE.UV(this.u,this.v)}};
  22343. THREE.Geometry=function(){this.id=THREE.GeometryCount++;this.vertices=[];this.colors=[];this.materials=[];this.faces=[];this.faceUvs=[[]];this.faceVertexUvs=[[]];this.morphTargets=[];this.morphColors=[];this.morphNormals=[];this.skinWeights=[];this.skinIndices=[];this.boundingSphere=this.boundingBox=null;this.dynamic=this.hasTangents=false};
  22344. THREE.Geometry.prototype={constructor:THREE.Geometry,applyMatrix:function(a){var b=new THREE.Matrix4;b.extractRotation(a);for(var c=0,d=this.vertices.length;c<d;c++)a.multiplyVector3(this.vertices[c]);c=0;for(d=this.faces.length;c<d;c++){var e=this.faces[c];b.multiplyVector3(e.normal);for(var f=0,g=e.vertexNormals.length;f<g;f++)b.multiplyVector3(e.vertexNormals[f]);a.multiplyVector3(e.centroid)}},computeCentroids:function(){var a,b,c;a=0;for(b=this.faces.length;a<b;a++){c=this.faces[a];c.centroid.set(0,
  22345. 0,0);if(c instanceof THREE.Face3){c.centroid.addSelf(this.vertices[c.a]);c.centroid.addSelf(this.vertices[c.b]);c.centroid.addSelf(this.vertices[c.c]);c.centroid.divideScalar(3)}else if(c instanceof THREE.Face4){c.centroid.addSelf(this.vertices[c.a]);c.centroid.addSelf(this.vertices[c.b]);c.centroid.addSelf(this.vertices[c.c]);c.centroid.addSelf(this.vertices[c.d]);c.centroid.divideScalar(4)}}},computeFaceNormals:function(){var a,b,c,d,e,f,g=new THREE.Vector3,h=new THREE.Vector3;a=0;for(b=this.faces.length;a<
  22346. b;a++){c=this.faces[a];d=this.vertices[c.a];e=this.vertices[c.b];f=this.vertices[c.c];g.sub(f,e);h.sub(d,e);g.crossSelf(h);g.isZero()||g.normalize();c.normal.copy(g)}},computeVertexNormals:function(){var a,b,c,d;if(this.__tmpVertices===void 0){d=this.__tmpVertices=Array(this.vertices.length);a=0;for(b=this.vertices.length;a<b;a++)d[a]=new THREE.Vector3;a=0;for(b=this.faces.length;a<b;a++){c=this.faces[a];if(c instanceof THREE.Face3)c.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];
  22347. else if(c instanceof THREE.Face4)c.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3]}}else{d=this.__tmpVertices;a=0;for(b=this.vertices.length;a<b;a++)d[a].set(0,0,0)}a=0;for(b=this.faces.length;a<b;a++){c=this.faces[a];if(c instanceof THREE.Face3){d[c.a].addSelf(c.normal);d[c.b].addSelf(c.normal);d[c.c].addSelf(c.normal)}else if(c instanceof THREE.Face4){d[c.a].addSelf(c.normal);d[c.b].addSelf(c.normal);d[c.c].addSelf(c.normal);d[c.d].addSelf(c.normal)}}a=0;
  22348. for(b=this.vertices.length;a<b;a++)d[a].normalize();a=0;for(b=this.faces.length;a<b;a++){c=this.faces[a];if(c instanceof THREE.Face3){c.vertexNormals[0].copy(d[c.a]);c.vertexNormals[1].copy(d[c.b]);c.vertexNormals[2].copy(d[c.c])}else if(c instanceof THREE.Face4){c.vertexNormals[0].copy(d[c.a]);c.vertexNormals[1].copy(d[c.b]);c.vertexNormals[2].copy(d[c.c]);c.vertexNormals[3].copy(d[c.d])}}},computeMorphNormals:function(){var a,b,c,d,e;c=0;for(d=this.faces.length;c<d;c++){e=this.faces[c];e.__originalFaceNormal?
  22349. e.__originalFaceNormal.copy(e.normal):e.__originalFaceNormal=e.normal.clone();if(!e.__originalVertexNormals)e.__originalVertexNormals=[];a=0;for(b=e.vertexNormals.length;a<b;a++)e.__originalVertexNormals[a]?e.__originalVertexNormals[a].copy(e.vertexNormals[a]):e.__originalVertexNormals[a]=e.vertexNormals[a].clone()}var f=new THREE.Geometry;f.faces=this.faces;a=0;for(b=this.morphTargets.length;a<b;a++){if(!this.morphNormals[a]){this.morphNormals[a]={};this.morphNormals[a].faceNormals=[];this.morphNormals[a].vertexNormals=
  22350. [];var g=this.morphNormals[a].faceNormals,h=this.morphNormals[a].vertexNormals,k,j;c=0;for(d=this.faces.length;c<d;c++){e=this.faces[c];k=new THREE.Vector3;j=e instanceof THREE.Face3?{a:new THREE.Vector3,b:new THREE.Vector3,c:new THREE.Vector3}:{a:new THREE.Vector3,b:new THREE.Vector3,c:new THREE.Vector3,d:new THREE.Vector3};g.push(k);h.push(j)}}g=this.morphNormals[a];f.vertices=this.morphTargets[a].vertices;f.computeFaceNormals();f.computeVertexNormals();c=0;for(d=this.faces.length;c<d;c++){e=this.faces[c];
  22351. k=g.faceNormals[c];j=g.vertexNormals[c];k.copy(e.normal);if(e instanceof THREE.Face3){j.a.copy(e.vertexNormals[0]);j.b.copy(e.vertexNormals[1]);j.c.copy(e.vertexNormals[2])}else{j.a.copy(e.vertexNormals[0]);j.b.copy(e.vertexNormals[1]);j.c.copy(e.vertexNormals[2]);j.d.copy(e.vertexNormals[3])}}}c=0;for(d=this.faces.length;c<d;c++){e=this.faces[c];e.normal=e.__originalFaceNormal;e.vertexNormals=e.__originalVertexNormals}},computeTangents:function(){function a(a,b,c,d,e,f,I){h=a.vertices[b];k=a.vertices[c];
  22352. j=a.vertices[d];l=g[e];p=g[f];m=g[I];o=k.x-h.x;q=j.x-h.x;n=k.y-h.y;r=j.y-h.y;u=k.z-h.z;t=j.z-h.z;w=p.u-l.u;s=m.u-l.u;x=p.v-l.v;F=m.v-l.v;D=1/(w*F-s*x);J.set((F*o-x*q)*D,(F*n-x*r)*D,(F*u-x*t)*D);K.set((w*q-s*o)*D,(w*r-s*n)*D,(w*t-s*u)*D);v[b].addSelf(J);v[c].addSelf(J);v[d].addSelf(J);A[b].addSelf(K);A[c].addSelf(K);A[d].addSelf(K)}var b,c,d,e,f,g,h,k,j,l,p,m,o,q,n,r,u,t,w,s,x,F,D,z,v=[],A=[],J=new THREE.Vector3,K=new THREE.Vector3,R=new THREE.Vector3,P=new THREE.Vector3,E=new THREE.Vector3;b=0;for(c=
  22353. this.vertices.length;b<c;b++){v[b]=new THREE.Vector3;A[b]=new THREE.Vector3}b=0;for(c=this.faces.length;b<c;b++){f=this.faces[b];g=this.faceVertexUvs[0][b];if(f instanceof THREE.Face3)a(this,f.a,f.b,f.c,0,1,2);else if(f instanceof THREE.Face4){a(this,f.a,f.b,f.d,0,1,3);a(this,f.b,f.c,f.d,1,2,3)}}var M=["a","b","c","d"];b=0;for(c=this.faces.length;b<c;b++){f=this.faces[b];for(d=0;d<f.vertexNormals.length;d++){E.copy(f.vertexNormals[d]);e=f[M[d]];z=v[e];R.copy(z);R.subSelf(E.multiplyScalar(E.dot(z))).normalize();
  22354. P.cross(f.vertexNormals[d],z);e=P.dot(A[e]);e=e<0?-1:1;f.vertexTangents[d]=new THREE.Vector4(R.x,R.y,R.z,e)}}this.hasTangents=true},computeBoundingBox:function(){if(!this.boundingBox)this.boundingBox={min:new THREE.Vector3,max:new THREE.Vector3};if(this.vertices.length>0){var a;a=this.vertices[0];this.boundingBox.min.copy(a);this.boundingBox.max.copy(a);for(var b=this.boundingBox.min,c=this.boundingBox.max,d=1,e=this.vertices.length;d<e;d++){a=this.vertices[d];if(a.x<b.x)b.x=a.x;else if(a.x>c.x)c.x=
  22355. a.x;if(a.y<b.y)b.y=a.y;else if(a.y>c.y)c.y=a.y;if(a.z<b.z)b.z=a.z;else if(a.z>c.z)c.z=a.z}}else{this.boundingBox.min.set(0,0,0);this.boundingBox.max.set(0,0,0)}},computeBoundingSphere:function(){if(!this.boundingSphere)this.boundingSphere={radius:0};for(var a,b=0,c=0,d=this.vertices.length;c<d;c++){a=this.vertices[c].length();a>b&&(b=a)}this.boundingSphere.radius=b},mergeVertices:function(){var a={},b=[],c=[],d,e=Math.pow(10,4),f,g,h;f=0;for(g=this.vertices.length;f<g;f++){d=this.vertices[f];d=[Math.round(d.x*
  22356. e),Math.round(d.y*e),Math.round(d.z*e)].join("_");if(a[d]===void 0){a[d]=f;b.push(this.vertices[f]);c[f]=b.length-1}else c[f]=c[a[d]]}f=0;for(g=this.faces.length;f<g;f++){e=this.faces[f];if(e instanceof THREE.Face3){e.a=c[e.a];e.b=c[e.b];e.c=c[e.c]}else if(e instanceof THREE.Face4){e.a=c[e.a];e.b=c[e.b];e.c=c[e.c];e.d=c[e.d];d=[e.a,e.b,e.c,e.d];for(a=3;a>0;a--)if(d.indexOf(e["abcd"[a]])!=a){d.splice(a,1);this.faces[f]=new THREE.Face3(d[0],d[1],d[2]);e=0;for(d=this.faceVertexUvs.length;e<d;e++)(h=
  22357. this.faceVertexUvs[e][f])&&h.splice(a,1);break}}}c=this.vertices.length-b.length;this.vertices=b;return c}};THREE.GeometryCount=0;
  22358. THREE.Spline=function(a){function b(a,b,c,d,e,f,g){a=(c-a)*0.5;d=(d-b)*0.5;return(2*(b-c)+a+d)*g+(-3*(b-c)-2*a-d)*f+a*e+b}this.points=a;var c=[],d={x:0,y:0,z:0},e,f,g,h,k,j,l,p,m;this.initFromArray=function(a){this.points=[];for(var b=0;b<a.length;b++)this.points[b]={x:a[b][0],y:a[b][1],z:a[b][2]}};this.getPoint=function(a){e=(this.points.length-1)*a;f=Math.floor(e);g=e-f;c[0]=f===0?f:f-1;c[1]=f;c[2]=f>this.points.length-2?this.points.length-1:f+1;c[3]=f>this.points.length-3?this.points.length-1:
  22359. f+2;j=this.points[c[0]];l=this.points[c[1]];p=this.points[c[2]];m=this.points[c[3]];h=g*g;k=g*h;d.x=b(j.x,l.x,p.x,m.x,g,h,k);d.y=b(j.y,l.y,p.y,m.y,g,h,k);d.z=b(j.z,l.z,p.z,m.z,g,h,k);return d};this.getControlPointsArray=function(){var a,b,c=this.points.length,d=[];for(a=0;a<c;a++){b=this.points[a];d[a]=[b.x,b.y,b.z]}return d};this.getLength=function(a){var b,c,d,e=b=b=0,f=new THREE.Vector3,g=new THREE.Vector3,h=[],k=0;h[0]=0;a||(a=100);c=this.points.length*a;f.copy(this.points[0]);for(a=1;a<c;a++){b=
  22360. a/c;d=this.getPoint(b);g.copy(d);k=k+g.distanceTo(f);f.copy(d);b=(this.points.length-1)*b;b=Math.floor(b);if(b!=e){h[b]=k;e=b}}h[h.length]=k;return{chunks:h,total:k}};this.reparametrizeByArcLength=function(a){var b,c,d,e,f,g,h=[],k=new THREE.Vector3,j=this.getLength();h.push(k.copy(this.points[0]).clone());for(b=1;b<this.points.length;b++){c=j.chunks[b]-j.chunks[b-1];g=Math.ceil(a*c/j.total);e=(b-1)/(this.points.length-1);f=b/(this.points.length-1);for(c=1;c<g-1;c++){d=e+c*(1/g)*(f-e);d=this.getPoint(d);
  22361. h.push(k.copy(d).clone())}h.push(k.copy(this.points[b]).clone())}this.points=h}};THREE.Camera=function(){THREE.Object3D.call(this);this.matrixWorldInverse=new THREE.Matrix4;this.projectionMatrix=new THREE.Matrix4;this.projectionMatrixInverse=new THREE.Matrix4};THREE.Camera.prototype=new THREE.Object3D;THREE.Camera.prototype.constructor=THREE.Camera;THREE.Camera.prototype.lookAt=function(a){this.matrix.lookAt(this.position,a,this.up);this.rotationAutoUpdate&&this.rotation.getRotationFromMatrix(this.matrix)};
  22362. THREE.OrthographicCamera=function(a,b,c,d,e,f){THREE.Camera.call(this);this.left=a;this.right=b;this.top=c;this.bottom=d;this.near=e!==void 0?e:0.1;this.far=f!==void 0?f:2E3;this.updateProjectionMatrix()};THREE.OrthographicCamera.prototype=new THREE.Camera;THREE.OrthographicCamera.prototype.constructor=THREE.OrthographicCamera;THREE.OrthographicCamera.prototype.updateProjectionMatrix=function(){this.projectionMatrix.makeOrthographic(this.left,this.right,this.top,this.bottom,this.near,this.far)};
  22363. THREE.PerspectiveCamera=function(a,b,c,d){THREE.Camera.call(this);this.fov=a!==void 0?a:50;this.aspect=b!==void 0?b:1;this.near=c!==void 0?c:0.1;this.far=d!==void 0?d:2E3;this.updateProjectionMatrix()};THREE.PerspectiveCamera.prototype=new THREE.Camera;THREE.PerspectiveCamera.prototype.constructor=THREE.PerspectiveCamera;THREE.PerspectiveCamera.prototype.setLens=function(a,b){this.fov=2*Math.atan((b!==void 0?b:24)/(a*2))*(180/Math.PI);this.updateProjectionMatrix()};
  22364. THREE.PerspectiveCamera.prototype.setViewOffset=function(a,b,c,d,e,f){this.fullWidth=a;this.fullHeight=b;this.x=c;this.y=d;this.width=e;this.height=f;this.updateProjectionMatrix()};
  22365. THREE.PerspectiveCamera.prototype.updateProjectionMatrix=function(){if(this.fullWidth){var a=this.fullWidth/this.fullHeight,b=Math.tan(this.fov*Math.PI/360)*this.near,c=-b,d=a*c,a=Math.abs(a*b-d),c=Math.abs(b-c);this.projectionMatrix.makeFrustum(d+this.x*a/this.fullWidth,d+(this.x+this.width)*a/this.fullWidth,b-(this.y+this.height)*c/this.fullHeight,b-this.y*c/this.fullHeight,this.near,this.far)}else this.projectionMatrix.makePerspective(this.fov,this.aspect,this.near,this.far)};
  22366. THREE.Light=function(a){THREE.Object3D.call(this);this.color=new THREE.Color(a)};THREE.Light.prototype=new THREE.Object3D;THREE.Light.prototype.constructor=THREE.Light;THREE.Light.prototype.supr=THREE.Object3D.prototype;THREE.AmbientLight=function(a){THREE.Light.call(this,a)};THREE.AmbientLight.prototype=new THREE.Light;THREE.AmbientLight.prototype.constructor=THREE.AmbientLight;
  22367. THREE.DirectionalLight=function(a,b,c){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,1,0);this.target=new THREE.Object3D;this.intensity=b!==void 0?b:1;this.distance=c!==void 0?c:0;this.onlyShadow=this.castShadow=false;this.shadowCameraNear=50;this.shadowCameraFar=5E3;this.shadowCameraLeft=-500;this.shadowCameraTop=this.shadowCameraRight=500;this.shadowCameraBottom=-500;this.shadowCameraVisible=false;this.shadowBias=0;this.shadowDarkness=0.5;this.shadowMapHeight=this.shadowMapWidth=512;
  22368. this.shadowCascade=false;this.shadowCascadeOffset=new THREE.Vector3(0,0,-1E3);this.shadowCascadeCount=2;this.shadowCascadeBias=[0,0,0];this.shadowCascadeWidth=[512,512,512];this.shadowCascadeHeight=[512,512,512];this.shadowCascadeNearZ=[-1,0.99,0.998];this.shadowCascadeFarZ=[0.99,0.998,1];this.shadowCascadeArray=[];this.shadowMatrix=this.shadowCamera=this.shadowMapSize=this.shadowMap=null};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.DirectionalLight;
  22369. THREE.PointLight=function(a,b,c){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,0,0);this.intensity=b!==void 0?b:1;this.distance=c!==void 0?c:0};THREE.PointLight.prototype=new THREE.Light;THREE.PointLight.prototype.constructor=THREE.PointLight;
  22370. THREE.SpotLight=function(a,b,c,d,e){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,1,0);this.target=new THREE.Object3D;this.intensity=b!==void 0?b:1;this.distance=c!==void 0?c:0;this.angle=d!==void 0?d:Math.PI/2;this.exponent=e!==void 0?e:10;this.onlyShadow=this.castShadow=false;this.shadowCameraNear=50;this.shadowCameraFar=5E3;this.shadowCameraFov=50;this.shadowCameraVisible=false;this.shadowBias=0;this.shadowDarkness=0.5;this.shadowMapHeight=this.shadowMapWidth=512;this.shadowMatrix=
  22371. this.shadowCamera=this.shadowMapSize=this.shadowMap=null};THREE.SpotLight.prototype=new THREE.Light;THREE.SpotLight.prototype.constructor=THREE.SpotLight;THREE.Loader=function(a){this.statusDomElement=(this.showStatus=a)?THREE.Loader.prototype.addStatusElement():null;this.onLoadStart=function(){};this.onLoadProgress=function(){};this.onLoadComplete=function(){}};
  22372. THREE.Loader.prototype={constructor:THREE.Loader,crossOrigin:"anonymous",addStatusElement:function(){var a=document.createElement("div");a.style.position="absolute";a.style.right="0px";a.style.top="0px";a.style.fontSize="0.8em";a.style.textAlign="left";a.style.background="rgba(0,0,0,0.25)";a.style.color="#fff";a.style.width="120px";a.style.padding="0.5em 0.5em 0.5em 0.5em";a.style.zIndex=1E3;a.innerHTML="Loading ...";return a},updateProgress:function(a){var b="Loaded ",b=a.total?b+((100*a.loaded/
  22373. a.total).toFixed(0)+"%"):b+((a.loaded/1E3).toFixed(2)+" KB");this.statusDomElement.innerHTML=b},extractUrlBase:function(a){a=a.split("/");a.pop();return(a.length<1?".":a.join("/"))+"/"},initMaterials:function(a,b,c){a.materials=[];for(var d=0;d<b.length;++d)a.materials[d]=THREE.Loader.prototype.createMaterial(b[d],c)},hasNormals:function(a){var b,c,d=a.materials.length;for(c=0;c<d;c++){b=a.materials[c];if(b instanceof THREE.ShaderMaterial)return true}return false},createMaterial:function(a,b){function c(a){a=
  22374. Math.log(a)/Math.LN2;return Math.floor(a)==a}function d(a){a=Math.log(a)/Math.LN2;return Math.pow(2,Math.round(a))}function e(a,b){var e=new Image;e.onload=function(){if(!c(this.width)||!c(this.height)){var b=d(this.width),e=d(this.height);a.image.width=b;a.image.height=e;a.image.getContext("2d").drawImage(this,0,0,b,e)}else a.image=this;a.needsUpdate=true};e.crossOrigin=h.crossOrigin;e.src=b}function f(a,c,d,f,g,h){var k=document.createElement("canvas");a[c]=new THREE.Texture(k);a[c].sourceFile=
  22375. d;if(f){a[c].repeat.set(f[0],f[1]);if(f[0]!=1)a[c].wrapS=THREE.RepeatWrapping;if(f[1]!=1)a[c].wrapT=THREE.RepeatWrapping}g&&a[c].offset.set(g[0],g[1]);if(h){f={repeat:THREE.RepeatWrapping,mirror:THREE.MirroredRepeatWrapping};if(f[h[0]]!==void 0)a[c].wrapS=f[h[0]];if(f[h[1]]!==void 0)a[c].wrapT=f[h[1]]}e(a[c],b+"/"+d)}function g(a){return(a[0]*255<<16)+(a[1]*255<<8)+a[2]*255}var h=this,k="MeshLambertMaterial",j={color:15658734,opacity:1,map:null,lightMap:null,normalMap:null,wireframe:a.wireframe};
  22376. if(a.shading){var l=a.shading.toLowerCase();l==="phong"?k="MeshPhongMaterial":l==="basic"&&(k="MeshBasicMaterial")}if(a.blending!==void 0&&THREE[a.blending]!==void 0)j.blending=THREE[a.blending];if(a.transparent!==void 0||a.opacity<1)j.transparent=a.transparent;if(a.depthTest!==void 0)j.depthTest=a.depthTest;if(a.depthWrite!==void 0)j.depthWrite=a.depthWrite;if(a.vertexColors!==void 0)if(a.vertexColors=="face")j.vertexColors=THREE.FaceColors;else if(a.vertexColors)j.vertexColors=THREE.VertexColors;
  22377. if(a.colorDiffuse)j.color=g(a.colorDiffuse);else if(a.DbgColor)j.color=a.DbgColor;if(a.colorSpecular)j.specular=g(a.colorSpecular);if(a.colorAmbient)j.ambient=g(a.colorAmbient);if(a.transparency)j.opacity=a.transparency;if(a.specularCoef)j.shininess=a.specularCoef;a.mapDiffuse&&b&&f(j,"map",a.mapDiffuse,a.mapDiffuseRepeat,a.mapDiffuseOffset,a.mapDiffuseWrap);a.mapLight&&b&&f(j,"lightMap",a.mapLight,a.mapLightRepeat,a.mapLightOffset,a.mapLightWrap);a.mapNormal&&b&&f(j,"normalMap",a.mapNormal,a.mapNormalRepeat,
  22378. a.mapNormalOffset,a.mapNormalWrap);a.mapSpecular&&b&&f(j,"specularMap",a.mapSpecular,a.mapSpecularRepeat,a.mapSpecularOffset,a.mapSpecularWrap);if(a.mapNormal){k=THREE.ShaderUtils.lib.normal;l=THREE.UniformsUtils.clone(k.uniforms);l.tNormal.texture=j.normalMap;if(a.mapNormalFactor)l.uNormalScale.value=a.mapNormalFactor;if(j.map){l.tDiffuse.texture=j.map;l.enableDiffuse.value=true}if(j.specularMap){l.tSpecular.texture=j.specularMap;l.enableSpecular.value=true}if(j.lightMap){l.tAO.texture=j.lightMap;
  22379. l.enableAO.value=true}l.uDiffuseColor.value.setHex(j.color);l.uSpecularColor.value.setHex(j.specular);l.uAmbientColor.value.setHex(j.ambient);l.uShininess.value=j.shininess;if(j.opacity!==void 0)l.uOpacity.value=j.opacity;j=new THREE.ShaderMaterial({fragmentShader:k.fragmentShader,vertexShader:k.vertexShader,uniforms:l,lights:true,fog:true})}else j=new THREE[k](j);if(a.DbgName!==void 0)j.name=a.DbgName;return j}};THREE.BinaryLoader=function(a){THREE.Loader.call(this,a)};
  22380. THREE.BinaryLoader.prototype=new THREE.Loader;THREE.BinaryLoader.prototype.constructor=THREE.BinaryLoader;THREE.BinaryLoader.prototype.load=function(a,b,c,d){var c=c?c:this.extractUrlBase(a),d=d?d:this.extractUrlBase(a),e=this.showProgress?THREE.Loader.prototype.updateProgress:null;this.onLoadStart();this.loadAjaxJSON(this,a,b,c,d,e)};
  22381. THREE.BinaryLoader.prototype.loadAjaxJSON=function(a,b,c,d,e,f){var g=new XMLHttpRequest;g.onreadystatechange=function(){if(g.readyState==4)if(g.status==200||g.status==0){var h=JSON.parse(g.responseText);a.loadAjaxBuffers(h,c,e,d,f)}else console.error("THREE.BinaryLoader: Couldn't load ["+b+"] ["+g.status+"]")};g.open("GET",b,true);g.overrideMimeType&&g.overrideMimeType("text/plain; charset=x-user-defined");g.setRequestHeader("Content-Type","text/plain");g.send(null)};
  22382. THREE.BinaryLoader.prototype.loadAjaxBuffers=function(a,b,c,d,e){var f=new XMLHttpRequest,g=c+"/"+a.buffers,h=0;f.onreadystatechange=function(){if(f.readyState==4)f.status==200||f.status==0?THREE.BinaryLoader.prototype.createBinModel(f.response,b,d,a.materials):console.error("THREE.BinaryLoader: Couldn't load ["+g+"] ["+f.status+"]");else if(f.readyState==3){if(e){h==0&&(h=f.getResponseHeader("Content-Length"));e({total:h,loaded:f.responseText.length})}}else f.readyState==2&&(h=f.getResponseHeader("Content-Length"))};
  22383. f.open("GET",g,true);f.responseType="arraybuffer";f.send(null)};
  22384. THREE.BinaryLoader.prototype.createBinModel=function(a,b,c,d){var e=function(b){var c,e,k,j,l,p,m,o,q,n,r,u,t,w,s;function x(a){return a%4?4-a%4:0}function F(a,b){return(new Uint8Array(a,b,1))[0]}function D(a,b){return(new Uint32Array(a,b,1))[0]}function z(b,c){var d,e,f,g,h,i,k,j,l=new Uint32Array(a,c,3*b);for(d=0;d<b;d++){e=l[d*3];f=l[d*3+1];g=l[d*3+2];h=G[e*2];e=G[e*2+1];i=G[f*2];k=G[f*2+1];f=G[g*2];j=G[g*2+1];g=P.faceVertexUvs[0];var m=[];m.push(new THREE.UV(h,e));m.push(new THREE.UV(i,k));m.push(new THREE.UV(f,
  22385. j));g.push(m)}}function v(b,c){var d,e,f,g,h,i,k,j,l,m,n=new Uint32Array(a,c,4*b);for(d=0;d<b;d++){e=n[d*4];f=n[d*4+1];g=n[d*4+2];h=n[d*4+3];i=G[e*2];e=G[e*2+1];k=G[f*2];l=G[f*2+1];j=G[g*2];m=G[g*2+1];g=G[h*2];f=G[h*2+1];h=P.faceVertexUvs[0];var o=[];o.push(new THREE.UV(i,e));o.push(new THREE.UV(k,l));o.push(new THREE.UV(j,m));o.push(new THREE.UV(g,f));h.push(o)}}function A(b,c,d){for(var e,f,g,h,c=new Uint32Array(a,c,3*b),i=new Uint16Array(a,d,b),d=0;d<b;d++){e=c[d*3];f=c[d*3+1];g=c[d*3+2];h=i[d];
  22386. P.faces.push(new THREE.Face3(e,f,g,null,null,h))}}function J(b,c,d){for(var e,f,g,h,i,c=new Uint32Array(a,c,4*b),k=new Uint16Array(a,d,b),d=0;d<b;d++){e=c[d*4];f=c[d*4+1];g=c[d*4+2];h=c[d*4+3];i=k[d];P.faces.push(new THREE.Face4(e,f,g,h,null,null,i))}}function K(b,c,d,e){for(var f,g,h,i,k,j,l,c=new Uint32Array(a,c,3*b),d=new Uint32Array(a,d,3*b),m=new Uint16Array(a,e,b),e=0;e<b;e++){f=c[e*3];g=c[e*3+1];h=c[e*3+2];k=d[e*3];j=d[e*3+1];l=d[e*3+2];i=m[e];var n=M[j*3],o=M[j*3+1];j=M[j*3+2];var p=M[l*3],
  22387. q=M[l*3+1];l=M[l*3+2];P.faces.push(new THREE.Face3(f,g,h,[new THREE.Vector3(M[k*3],M[k*3+1],M[k*3+2]),new THREE.Vector3(n,o,j),new THREE.Vector3(p,q,l)],null,i))}}function R(b,c,d,e){for(var f,g,h,i,k,j,l,m,n,c=new Uint32Array(a,c,4*b),d=new Uint32Array(a,d,4*b),o=new Uint16Array(a,e,b),e=0;e<b;e++){f=c[e*4];g=c[e*4+1];h=c[e*4+2];i=c[e*4+3];j=d[e*4];l=d[e*4+1];m=d[e*4+2];n=d[e*4+3];k=o[e];var p=M[l*3],q=M[l*3+1];l=M[l*3+2];var r=M[m*3],s=M[m*3+1];m=M[m*3+2];var t=M[n*3],u=M[n*3+1];n=M[n*3+2];P.faces.push(new THREE.Face4(f,
  22388. g,h,i,[new THREE.Vector3(M[j*3],M[j*3+1],M[j*3+2]),new THREE.Vector3(p,q,l),new THREE.Vector3(r,s,m),new THREE.Vector3(t,u,n)],null,k))}}var P=this,E=0,M=[],G=[],i,T,U;THREE.Geometry.call(this);THREE.Loader.prototype.initMaterials(P,d,b);(function(a,b,c){for(var a=new Uint8Array(a,b,c),d="",e=0;e<c;e++)d=d+String.fromCharCode(a[b+e]);return d})(a,E,12);c=F(a,E+12);F(a,E+13);F(a,E+14);F(a,E+15);e=F(a,E+16);k=F(a,E+17);j=F(a,E+18);l=F(a,E+19);p=D(a,E+20);m=D(a,E+20+4);o=D(a,E+20+8);b=D(a,E+20+12);q=
  22389. D(a,E+20+16);n=D(a,E+20+20);r=D(a,E+20+24);u=D(a,E+20+28);t=D(a,E+20+32);w=D(a,E+20+36);s=D(a,E+20+40);E=E+c;c=e*3+l;U=e*4+l;i=b*c;T=q*(c+k*3);e=n*(c+j*3);l=r*(c+k*3+j*3);c=u*U;k=t*(U+k*4);j=w*(U+j*4);E=E+function(b){var b=new Float32Array(a,b,p*3),c,d,e,f;for(c=0;c<p;c++){d=b[c*3];e=b[c*3+1];f=b[c*3+2];P.vertices.push(new THREE.Vector3(d,e,f))}return p*3*Float32Array.BYTES_PER_ELEMENT}(E);E=E+function(b){if(m){var b=new Int8Array(a,b,m*3),c,d,e,f;for(c=0;c<m;c++){d=b[c*3];e=b[c*3+1];f=b[c*3+2];M.push(d/
  22390. 127,e/127,f/127)}}return m*3*Int8Array.BYTES_PER_ELEMENT}(E);E=E+x(m*3);E=E+function(b){if(o){var b=new Float32Array(a,b,o*2),c,d,e;for(c=0;c<o;c++){d=b[c*2];e=b[c*2+1];G.push(d,e)}}return o*2*Float32Array.BYTES_PER_ELEMENT}(E);i=E+i+x(b*2);T=i+T+x(q*2);e=T+e+x(n*2);l=e+l+x(r*2);c=l+c+x(u*2);k=c+k+x(t*2);j=k+j+x(w*2);(function(a){if(n){var b=a+n*Uint32Array.BYTES_PER_ELEMENT*3;A(n,a,b+n*Uint32Array.BYTES_PER_ELEMENT*3);z(n,b)}})(T);(function(a){if(r){var b=a+r*Uint32Array.BYTES_PER_ELEMENT*3,c=b+
  22391. r*Uint32Array.BYTES_PER_ELEMENT*3;K(r,a,b,c+r*Uint32Array.BYTES_PER_ELEMENT*3);z(r,c)}})(e);(function(a){if(w){var b=a+w*Uint32Array.BYTES_PER_ELEMENT*4;J(w,a,b+w*Uint32Array.BYTES_PER_ELEMENT*4);v(w,b)}})(k);(function(a){if(s){var b=a+s*Uint32Array.BYTES_PER_ELEMENT*4,c=b+s*Uint32Array.BYTES_PER_ELEMENT*4;R(s,a,b,c+s*Uint32Array.BYTES_PER_ELEMENT*4);v(s,c)}})(j);b&&A(b,E,E+b*Uint32Array.BYTES_PER_ELEMENT*3);(function(a){if(q){var b=a+q*Uint32Array.BYTES_PER_ELEMENT*3;K(q,a,b,b+q*Uint32Array.BYTES_PER_ELEMENT*
  22392. 3)}})(i);u&&J(u,l,l+u*Uint32Array.BYTES_PER_ELEMENT*4);(function(a){if(t){var b=a+t*Uint32Array.BYTES_PER_ELEMENT*4;R(t,a,b,b+t*Uint32Array.BYTES_PER_ELEMENT*4)}})(c);this.computeCentroids();this.computeFaceNormals();THREE.Loader.prototype.hasNormals(this)&&this.computeTangents()};e.prototype=new THREE.Geometry;e.prototype.constructor=e;b(new e(c))};THREE.JSONLoader=function(a){THREE.Loader.call(this,a)};THREE.JSONLoader.prototype=new THREE.Loader;THREE.JSONLoader.prototype.constructor=THREE.JSONLoader;
  22393. THREE.JSONLoader.prototype.load=function(a,b,c){c=c?c:this.extractUrlBase(a);this.onLoadStart();this.loadAjaxJSON(this,a,b,c)};
  22394. THREE.JSONLoader.prototype.loadAjaxJSON=function(a,b,c,d,e){var f=new XMLHttpRequest,g=0;f.onreadystatechange=function(){if(f.readyState===f.DONE)if(f.status===200||f.status===0){if(f.responseText){var h=JSON.parse(f.responseText);a.createModel(h,c,d)}else console.warn("THREE.JSONLoader: ["+b+"] seems to be unreachable or file there is empty");a.onLoadComplete()}else console.error("THREE.JSONLoader: Couldn't load ["+b+"] ["+f.status+"]");else if(f.readyState===f.LOADING){if(e){g===0&&(g=f.getResponseHeader("Content-Length"));
  22395. e({total:g,loaded:f.responseText.length})}}else f.readyState===f.HEADERS_RECEIVED&&(g=f.getResponseHeader("Content-Length"))};f.open("GET",b,true);f.overrideMimeType&&f.overrideMimeType("text/plain; charset=x-user-defined");f.setRequestHeader("Content-Type","text/plain");f.send(null)};
  22396. THREE.JSONLoader.prototype.createModel=function(a,b,c){var d=new THREE.Geometry,e=a.scale!==void 0?1/a.scale:1;this.initMaterials(d,a.materials,c);(function(b){var c,e,k,j,l,p,m,o,q,n,r,u,t,w,s=a.faces;p=a.vertices;var x=a.normals,F=a.colors,D=0;for(c=0;c<a.uvs.length;c++)a.uvs[c].length&&D++;for(c=0;c<D;c++){d.faceUvs[c]=[];d.faceVertexUvs[c]=[]}j=0;for(l=p.length;j<l;){m=new THREE.Vector3;m.x=p[j++]*b;m.y=p[j++]*b;m.z=p[j++]*b;d.vertices.push(m)}j=0;for(l=s.length;j<l;){b=s[j++];p=b&1;k=b&2;c=b&
  22397. 4;e=b&8;o=b&16;m=b&32;n=b&64;b=b&128;if(p){r=new THREE.Face4;r.a=s[j++];r.b=s[j++];r.c=s[j++];r.d=s[j++];p=4}else{r=new THREE.Face3;r.a=s[j++];r.b=s[j++];r.c=s[j++];p=3}if(k){k=s[j++];r.materialIndex=k}k=d.faces.length;if(c)for(c=0;c<D;c++){u=a.uvs[c];q=s[j++];w=u[q*2];q=u[q*2+1];d.faceUvs[c][k]=new THREE.UV(w,q)}if(e)for(c=0;c<D;c++){u=a.uvs[c];t=[];for(e=0;e<p;e++){q=s[j++];w=u[q*2];q=u[q*2+1];t[e]=new THREE.UV(w,q)}d.faceVertexUvs[c][k]=t}if(o){o=s[j++]*3;e=new THREE.Vector3;e.x=x[o++];e.y=x[o++];
  22398. e.z=x[o];r.normal=e}if(m)for(c=0;c<p;c++){o=s[j++]*3;e=new THREE.Vector3;e.x=x[o++];e.y=x[o++];e.z=x[o];r.vertexNormals.push(e)}if(n){m=s[j++];m=new THREE.Color(F[m]);r.color=m}if(b)for(c=0;c<p;c++){m=s[j++];m=new THREE.Color(F[m]);r.vertexColors.push(m)}d.faces.push(r)}})(e);(function(){var b,c,e,k;if(a.skinWeights){b=0;for(c=a.skinWeights.length;b<c;b=b+2){e=a.skinWeights[b];k=a.skinWeights[b+1];d.skinWeights.push(new THREE.Vector4(e,k,0,0))}}if(a.skinIndices){b=0;for(c=a.skinIndices.length;b<c;b=
  22399. b+2){e=a.skinIndices[b];k=a.skinIndices[b+1];d.skinIndices.push(new THREE.Vector4(e,k,0,0))}}d.bones=a.bones;d.animation=a.animation})();(function(b){if(a.morphTargets!==void 0){var c,e,k,j,l,p;c=0;for(e=a.morphTargets.length;c<e;c++){d.morphTargets[c]={};d.morphTargets[c].name=a.morphTargets[c].name;d.morphTargets[c].vertices=[];l=d.morphTargets[c].vertices;p=a.morphTargets[c].vertices;k=0;for(j=p.length;k<j;k=k+3){var m=new THREE.Vector3;m.x=p[k]*b;m.y=p[k+1]*b;m.z=p[k+2]*b;l.push(m)}}}if(a.morphColors!==
  22400. void 0){c=0;for(e=a.morphColors.length;c<e;c++){d.morphColors[c]={};d.morphColors[c].name=a.morphColors[c].name;d.morphColors[c].colors=[];j=d.morphColors[c].colors;l=a.morphColors[c].colors;b=0;for(k=l.length;b<k;b=b+3){p=new THREE.Color(16755200);p.setRGB(l[b],l[b+1],l[b+2]);j.push(p)}}}})(e);d.computeCentroids();d.computeFaceNormals();this.hasNormals(d)&&d.computeTangents();b(d)};
  22401. THREE.SceneLoader=function(){this.onLoadStart=function(){};this.onLoadProgress=function(){};this.onLoadComplete=function(){};this.callbackSync=function(){};this.callbackProgress=function(){}};THREE.SceneLoader.prototype.constructor=THREE.SceneLoader;
  22402. THREE.SceneLoader.prototype.load=function(a,b){var c=this,d=new XMLHttpRequest;d.onreadystatechange=function(){if(d.readyState==4)if(d.status==200||d.status==0){var e=JSON.parse(d.responseText);c.createScene(e,b,a)}else console.error("THREE.SceneLoader: Couldn't load ["+a+"] ["+d.status+"]")};d.open("GET",a,true);d.overrideMimeType&&d.overrideMimeType("text/plain; charset=x-user-defined");d.setRequestHeader("Content-Type","text/plain");d.send(null)};
  22403. THREE.SceneLoader.prototype.createScene=function(a,b,c){function d(a,b){return b=="relativeToHTML"?a:j+"/"+a}function e(){var a;for(m in E.objects)if(!C.objects[m]){u=E.objects[m];if(u.geometry!==void 0){if(J=C.geometries[u.geometry]){a=false;K=C.materials[u.materials[0]];(a=K instanceof THREE.ShaderMaterial)&&J.computeTangents();x=u.position;F=u.rotation;D=u.quaternion;z=u.scale;t=u.matrix;D=0;u.materials.length==0&&(K=new THREE.MeshFaceMaterial);u.materials.length>1&&(K=new THREE.MeshFaceMaterial);
  22404. a=new THREE.Mesh(J,K);a.name=m;if(t){a.matrixAutoUpdate=false;a.matrix.set(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8],t[9],t[10],t[11],t[12],t[13],t[14],t[15])}else{a.position.set(x[0],x[1],x[2]);if(D){a.quaternion.set(D[0],D[1],D[2],D[3]);a.useQuaternion=true}else a.rotation.set(F[0],F[1],F[2]);a.scale.set(z[0],z[1],z[2])}a.visible=u.visible;a.doubleSided=u.doubleSided;a.castShadow=u.castShadow;a.receiveShadow=u.receiveShadow;C.scene.add(a);C.objects[m]=a}}else{x=u.position;F=u.rotation;D=u.quaternion;
  22405. z=u.scale;D=0;a=new THREE.Object3D;a.name=m;a.position.set(x[0],x[1],x[2]);if(D){a.quaternion.set(D[0],D[1],D[2],D[3]);a.useQuaternion=true}else a.rotation.set(F[0],F[1],F[2]);a.scale.set(z[0],z[1],z[2]);a.visible=u.visible!==void 0?u.visible:false;C.scene.add(a);C.objects[m]=a;C.empties[m]=a}}}function f(a){return function(b){C.geometries[a]=b;e();G=G-1;k.onLoadComplete();h()}}function g(a){return function(b){C.geometries[a]=b}}function h(){k.callbackProgress({totalModels:T,totalTextures:U,loadedModels:T-
  22406. G,loadedTextures:U-i},C);k.onLoadProgress();G==0&&i==0&&b(C)}var k=this,j=THREE.Loader.prototype.extractUrlBase(c),l,p,m,o,q,n,r,u,t,w,s,x,F,D,z,v,A,J,K,R,P,E,M,G,i,T,U,C;E=a;c=new THREE.BinaryLoader;M=new THREE.JSONLoader;i=G=0;C={scene:new THREE.Scene,geometries:{},materials:{},textures:{},objects:{},cameras:{},lights:{},fogs:{},empties:{}};if(E.transform){a=E.transform.position;w=E.transform.rotation;v=E.transform.scale;a&&C.scene.position.set(a[0],a[1],a[2]);w&&C.scene.rotation.set(w[0],w[1],
  22407. w[2]);v&&C.scene.scale.set(v[0],v[1],v[2]);if(a||w||v){C.scene.updateMatrix();C.scene.updateMatrixWorld()}}a=function(){i=i-1;h();k.onLoadComplete()};for(q in E.cameras){v=E.cameras[q];v.type=="perspective"?R=new THREE.PerspectiveCamera(v.fov,v.aspect,v.near,v.far):v.type=="ortho"&&(R=new THREE.OrthographicCamera(v.left,v.right,v.top,v.bottom,v.near,v.far));x=v.position;w=v.target;v=v.up;R.position.set(x[0],x[1],x[2]);R.target=new THREE.Vector3(w[0],w[1],w[2]);v&&R.up.set(v[0],v[1],v[2]);C.cameras[q]=
  22408. R}for(o in E.lights){w=E.lights[o];q=w.color!==void 0?w.color:16777215;R=w.intensity!==void 0?w.intensity:1;if(w.type=="directional"){x=w.direction;s=new THREE.DirectionalLight(q,R);s.position.set(x[0],x[1],x[2]);s.position.normalize()}else if(w.type=="point"){x=w.position;s=w.distance;s=new THREE.PointLight(q,R,s);s.position.set(x[0],x[1],x[2])}else w.type=="ambient"&&(s=new THREE.AmbientLight(q));C.scene.add(s);C.lights[o]=s}for(n in E.fogs){o=E.fogs[n];o.type=="linear"?P=new THREE.Fog(0,o.near,
  22409. o.far):o.type=="exp2"&&(P=new THREE.FogExp2(0,o.density));v=o.color;P.color.setRGB(v[0],v[1],v[2]);C.fogs[n]=P}if(C.cameras&&E.defaults.camera)C.currentCamera=C.cameras[E.defaults.camera];if(C.fogs&&E.defaults.fog)C.scene.fog=C.fogs[E.defaults.fog];v=E.defaults.bgcolor;C.bgColor=new THREE.Color;C.bgColor.setRGB(v[0],v[1],v[2]);C.bgColorAlpha=E.defaults.bgalpha;for(l in E.geometries){n=E.geometries[l];if(n.type=="bin_mesh"||n.type=="ascii_mesh"){G=G+1;k.onLoadStart()}}T=G;for(l in E.geometries){n=
  22410. E.geometries[l];if(n.type=="cube"){J=new THREE.CubeGeometry(n.width,n.height,n.depth,n.segmentsWidth,n.segmentsHeight,n.segmentsDepth,null,n.flipped,n.sides);C.geometries[l]=J}else if(n.type=="plane"){J=new THREE.PlaneGeometry(n.width,n.height,n.segmentsWidth,n.segmentsHeight);C.geometries[l]=J}else if(n.type=="sphere"){J=new THREE.SphereGeometry(n.radius,n.segmentsWidth,n.segmentsHeight);C.geometries[l]=J}else if(n.type=="cylinder"){J=new THREE.CylinderGeometry(n.topRad,n.botRad,n.height,n.radSegs,
  22411. n.heightSegs);C.geometries[l]=J}else if(n.type=="torus"){J=new THREE.TorusGeometry(n.radius,n.tube,n.segmentsR,n.segmentsT);C.geometries[l]=J}else if(n.type=="icosahedron"){J=new THREE.IcosahedronGeometry(n.radius,n.subdivisions);C.geometries[l]=J}else if(n.type=="bin_mesh")c.load(d(n.url,E.urlBaseType),f(l));else if(n.type=="ascii_mesh")M.load(d(n.url,E.urlBaseType),f(l));else if(n.type=="embedded_mesh"){n=E.embeds[n.id];n.metadata=E.metadata;n&&M.createModel(n,g(l),"")}}for(r in E.textures){l=E.textures[r];
  22412. if(l.url instanceof Array){i=i+l.url.length;for(n=0;n<l.url.length;n++)k.onLoadStart()}else{i=i+1;k.onLoadStart()}}U=i;for(r in E.textures){l=E.textures[r];if(l.mapping!=void 0&&THREE[l.mapping]!=void 0)l.mapping=new THREE[l.mapping];if(l.url instanceof Array){n=[];for(P=0;P<l.url.length;P++)n[P]=d(l.url[P],E.urlBaseType);n=THREE.ImageUtils.loadTextureCube(n,l.mapping,a)}else{n=THREE.ImageUtils.loadTexture(d(l.url,E.urlBaseType),l.mapping,a);if(THREE[l.minFilter]!=void 0)n.minFilter=THREE[l.minFilter];
  22413. if(THREE[l.magFilter]!=void 0)n.magFilter=THREE[l.magFilter];if(l.repeat){n.repeat.set(l.repeat[0],l.repeat[1]);if(l.repeat[0]!=1)n.wrapS=THREE.RepeatWrapping;if(l.repeat[1]!=1)n.wrapT=THREE.RepeatWrapping}l.offset&&n.offset.set(l.offset[0],l.offset[1]);if(l.wrap){P={repeat:THREE.RepeatWrapping,mirror:THREE.MirroredRepeatWrapping};if(P[l.wrap[0]]!==void 0)n.wrapS=P[l.wrap[0]];if(P[l.wrap[1]]!==void 0)n.wrapT=P[l.wrap[1]]}}C.textures[r]=n}for(p in E.materials){t=E.materials[p];for(A in t.parameters)if(A==
  22414. "envMap"||A=="map"||A=="lightMap")t.parameters[A]=C.textures[t.parameters[A]];else if(A=="shading")t.parameters[A]=t.parameters[A]=="flat"?THREE.FlatShading:THREE.SmoothShading;else if(A=="blending")t.parameters[A]=THREE[t.parameters[A]]?THREE[t.parameters[A]]:THREE.NormalBlending;else if(A=="combine")t.parameters[A]=t.parameters[A]=="MixOperation"?THREE.MixOperation:THREE.MultiplyOperation;else if(A=="vertexColors")if(t.parameters[A]=="face")t.parameters[A]=THREE.FaceColors;else if(t.parameters[A])t.parameters[A]=
  22415. THREE.VertexColors;if(t.parameters.opacity!==void 0&&t.parameters.opacity<1)t.parameters.transparent=true;if(t.parameters.normalMap){r=THREE.ShaderUtils.lib.normal;a=THREE.UniformsUtils.clone(r.uniforms);l=t.parameters.color;n=t.parameters.specular;P=t.parameters.ambient;c=t.parameters.shininess;a.tNormal.texture=C.textures[t.parameters.normalMap];if(t.parameters.normalMapFactor)a.uNormalScale.value=t.parameters.normalMapFactor;if(t.parameters.map){a.tDiffuse.texture=t.parameters.map;a.enableDiffuse.value=
  22416. true}if(t.parameters.lightMap){a.tAO.texture=t.parameters.lightMap;a.enableAO.value=true}if(t.parameters.specularMap){a.tSpecular.texture=C.textures[t.parameters.specularMap];a.enableSpecular.value=true}a.uDiffuseColor.value.setHex(l);a.uSpecularColor.value.setHex(n);a.uAmbientColor.value.setHex(P);a.uShininess.value=c;if(t.parameters.opacity)a.uOpacity.value=t.parameters.opacity;K=new THREE.ShaderMaterial({fragmentShader:r.fragmentShader,vertexShader:r.vertexShader,uniforms:a,lights:true,fog:true})}else K=
  22417. new THREE[t.type](t.parameters);C.materials[p]=K}e();k.callbackSync(C);h()};
  22418. THREE.Material=function(a){a=a||{};this.id=THREE.MaterialCount++;this.name="";this.opacity=a.opacity!==void 0?a.opacity:1;this.transparent=a.transparent!==void 0?a.transparent:false;this.blending=a.blending!==void 0?a.blending:THREE.NormalBlending;this.blendSrc=a.blendSrc!==void 0?a.blendSrc:THREE.SrcAlphaFactor;this.blendDst=a.blendDst!==void 0?a.blendDst:THREE.OneMinusSrcAlphaFactor;this.blendEquation=a.blendEquation!==void 0?a.blendEquation:THREE.AddEquation;this.depthTest=a.depthTest!==void 0?
  22419. a.depthTest:true;this.depthWrite=a.depthWrite!==void 0?a.depthWrite:true;this.polygonOffset=a.polygonOffset!==void 0?a.polygonOffset:false;this.polygonOffsetFactor=a.polygonOffsetFactor!==void 0?a.polygonOffsetFactor:0;this.polygonOffsetUnits=a.polygonOffsetUnits!==void 0?a.polygonOffsetUnits:0;this.alphaTest=a.alphaTest!==void 0?a.alphaTest:0;this.overdraw=a.overdraw!==void 0?a.overdraw:false;this.needsUpdate=this.visible=true};THREE.MaterialCount=0;THREE.NoShading=0;THREE.FlatShading=1;
  22420. THREE.SmoothShading=2;THREE.NoColors=0;THREE.FaceColors=1;THREE.VertexColors=2;THREE.NoBlending=0;THREE.NormalBlending=1;THREE.AdditiveBlending=2;THREE.SubtractiveBlending=3;THREE.MultiplyBlending=4;THREE.AdditiveAlphaBlending=5;THREE.CustomBlending=6;THREE.AddEquation=100;THREE.SubtractEquation=101;THREE.ReverseSubtractEquation=102;THREE.ZeroFactor=200;THREE.OneFactor=201;THREE.SrcColorFactor=202;THREE.OneMinusSrcColorFactor=203;THREE.SrcAlphaFactor=204;THREE.OneMinusSrcAlphaFactor=205;
  22421. THREE.DstAlphaFactor=206;THREE.OneMinusDstAlphaFactor=207;THREE.DstColorFactor=208;THREE.OneMinusDstColorFactor=209;THREE.SrcAlphaSaturateFactor=210;
  22422. THREE.LineBasicMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.color=a.color!==void 0?new THREE.Color(a.color):new THREE.Color(16777215);this.linewidth=a.linewidth!==void 0?a.linewidth:1;this.linecap=a.linecap!==void 0?a.linecap:"round";this.linejoin=a.linejoin!==void 0?a.linejoin:"round";this.vertexColors=a.vertexColors?a.vertexColors:false;this.fog=a.fog!==void 0?a.fog:true};THREE.LineBasicMaterial.prototype=new THREE.Material;THREE.LineBasicMaterial.prototype.constructor=THREE.LineBasicMaterial;
  22423. THREE.MeshBasicMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.color=a.color!==void 0?new THREE.Color(a.color):new THREE.Color(16777215);this.map=a.map!==void 0?a.map:null;this.lightMap=a.lightMap!==void 0?a.lightMap:null;this.envMap=a.envMap!==void 0?a.envMap:null;this.combine=a.combine!==void 0?a.combine:THREE.MultiplyOperation;this.reflectivity=a.reflectivity!==void 0?a.reflectivity:1;this.refractionRatio=a.refractionRatio!==void 0?a.refractionRatio:0.98;this.fog=a.fog!==void 0?a.fog:
  22424. true;this.shading=a.shading!==void 0?a.shading:THREE.SmoothShading;this.wireframe=a.wireframe!==void 0?a.wireframe:false;this.wireframeLinewidth=a.wireframeLinewidth!==void 0?a.wireframeLinewidth:1;this.wireframeLinecap=a.wireframeLinecap!==void 0?a.wireframeLinecap:"round";this.wireframeLinejoin=a.wireframeLinejoin!==void 0?a.wireframeLinejoin:"round";this.vertexColors=a.vertexColors!==void 0?a.vertexColors:THREE.NoColors;this.skinning=a.skinning!==void 0?a.skinning:false;this.morphTargets=a.morphTargets!==
  22425. void 0?a.morphTargets:false};THREE.MeshBasicMaterial.prototype=new THREE.Material;THREE.MeshBasicMaterial.prototype.constructor=THREE.MeshBasicMaterial;
  22426. THREE.MeshLambertMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.color=a.color!==void 0?new THREE.Color(a.color):new THREE.Color(16777215);this.ambient=a.ambient!==void 0?new THREE.Color(a.ambient):new THREE.Color(16777215);this.emissive=a.emissive!==void 0?new THREE.Color(a.emissive):new THREE.Color(0);this.wrapAround=a.wrapAround!==void 0?a.wrapAround:false;this.wrapRGB=new THREE.Vector3(1,1,1);this.map=a.map!==void 0?a.map:null;this.lightMap=a.lightMap!==void 0?a.lightMap:null;this.envMap=
  22427. a.envMap!==void 0?a.envMap:null;this.combine=a.combine!==void 0?a.combine:THREE.MultiplyOperation;this.reflectivity=a.reflectivity!==void 0?a.reflectivity:1;this.refractionRatio=a.refractionRatio!==void 0?a.refractionRatio:0.98;this.fog=a.fog!==void 0?a.fog:true;this.shading=a.shading!==void 0?a.shading:THREE.SmoothShading;this.wireframe=a.wireframe!==void 0?a.wireframe:false;this.wireframeLinewidth=a.wireframeLinewidth!==void 0?a.wireframeLinewidth:1;this.wireframeLinecap=a.wireframeLinecap!==void 0?
  22428. a.wireframeLinecap:"round";this.wireframeLinejoin=a.wireframeLinejoin!==void 0?a.wireframeLinejoin:"round";this.vertexColors=a.vertexColors!==void 0?a.vertexColors:THREE.NoColors;this.skinning=a.skinning!==void 0?a.skinning:false;this.morphTargets=a.morphTargets!==void 0?a.morphTargets:false;this.morphNormals=a.morphNormals!==void 0?a.morphNormals:false};THREE.MeshLambertMaterial.prototype=new THREE.Material;THREE.MeshLambertMaterial.prototype.constructor=THREE.MeshLambertMaterial;
  22429. THREE.MeshPhongMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.color=a.color!==void 0?new THREE.Color(a.color):new THREE.Color(16777215);this.ambient=a.ambient!==void 0?new THREE.Color(a.ambient):new THREE.Color(16777215);this.emissive=a.emissive!==void 0?new THREE.Color(a.emissive):new THREE.Color(0);this.specular=a.specular!==void 0?new THREE.Color(a.specular):new THREE.Color(1118481);this.shininess=a.shininess!==void 0?a.shininess:30;this.metal=a.metal!==void 0?a.metal:false;this.perPixel=
  22430. a.perPixel!==void 0?a.perPixel:false;this.wrapAround=a.wrapAround!==void 0?a.wrapAround:false;this.wrapRGB=new THREE.Vector3(1,1,1);this.map=a.map!==void 0?a.map:null;this.lightMap=a.lightMap!==void 0?a.lightMap:null;this.envMap=a.envMap!==void 0?a.envMap:null;this.combine=a.combine!==void 0?a.combine:THREE.MultiplyOperation;this.reflectivity=a.reflectivity!==void 0?a.reflectivity:1;this.refractionRatio=a.refractionRatio!==void 0?a.refractionRatio:0.98;this.fog=a.fog!==void 0?a.fog:true;this.shading=
  22431. a.shading!==void 0?a.shading:THREE.SmoothShading;this.wireframe=a.wireframe!==void 0?a.wireframe:false;this.wireframeLinewidth=a.wireframeLinewidth!==void 0?a.wireframeLinewidth:1;this.wireframeLinecap=a.wireframeLinecap!==void 0?a.wireframeLinecap:"round";this.wireframeLinejoin=a.wireframeLinejoin!==void 0?a.wireframeLinejoin:"round";this.vertexColors=a.vertexColors!==void 0?a.vertexColors:THREE.NoColors;this.skinning=a.skinning!==void 0?a.skinning:false;this.morphTargets=a.morphTargets!==void 0?
  22432. a.morphTargets:false;this.morphNormals=a.morphNormals!==void 0?a.morphNormals:false};THREE.MeshPhongMaterial.prototype=new THREE.Material;THREE.MeshPhongMaterial.prototype.constructor=THREE.MeshPhongMaterial;THREE.MeshDepthMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.shading=a.shading!==void 0?a.shading:THREE.SmoothShading;this.wireframe=a.wireframe!==void 0?a.wireframe:false;this.wireframeLinewidth=a.wireframeLinewidth!==void 0?a.wireframeLinewidth:1};
  22433. THREE.MeshDepthMaterial.prototype=new THREE.Material;THREE.MeshDepthMaterial.prototype.constructor=THREE.MeshDepthMaterial;THREE.MeshNormalMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.shading=a.shading?a.shading:THREE.FlatShading;this.wireframe=a.wireframe?a.wireframe:false;this.wireframeLinewidth=a.wireframeLinewidth?a.wireframeLinewidth:1};THREE.MeshNormalMaterial.prototype=new THREE.Material;THREE.MeshNormalMaterial.prototype.constructor=THREE.MeshNormalMaterial;
  22434. THREE.MeshFaceMaterial=function(){};THREE.ParticleBasicMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.color=a.color!==void 0?new THREE.Color(a.color):new THREE.Color(16777215);this.map=a.map!==void 0?a.map:null;this.size=a.size!==void 0?a.size:1;this.sizeAttenuation=a.sizeAttenuation!==void 0?a.sizeAttenuation:true;this.vertexColors=a.vertexColors!==void 0?a.vertexColors:false;this.fog=a.fog!==void 0?a.fog:true};THREE.ParticleBasicMaterial.prototype=new THREE.Material;
  22435. THREE.ParticleBasicMaterial.prototype.constructor=THREE.ParticleBasicMaterial;THREE.ParticleCanvasMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.color=a.color!==void 0?new THREE.Color(a.color):new THREE.Color(16777215);this.program=a.program!==void 0?a.program:function(){}};THREE.ParticleCanvasMaterial.prototype=new THREE.Material;THREE.ParticleCanvasMaterial.prototype.constructor=THREE.ParticleCanvasMaterial;
  22436. THREE.ParticleDOMMaterial=function(a){THREE.Material.call(this);this.domElement=a};
  22437. THREE.ShaderMaterial=function(a){THREE.Material.call(this,a);a=a||{};this.fragmentShader=a.fragmentShader!==void 0?a.fragmentShader:"void main() {}";this.vertexShader=a.vertexShader!==void 0?a.vertexShader:"void main() {}";this.uniforms=a.uniforms!==void 0?a.uniforms:{};this.attributes=a.attributes;this.shading=a.shading!==void 0?a.shading:THREE.SmoothShading;this.wireframe=a.wireframe!==void 0?a.wireframe:false;this.wireframeLinewidth=a.wireframeLinewidth!==void 0?a.wireframeLinewidth:1;this.fog=
  22438. a.fog!==void 0?a.fog:false;this.lights=a.lights!==void 0?a.lights:false;this.vertexColors=a.vertexColors!==void 0?a.vertexColors:THREE.NoColors;this.skinning=a.skinning!==void 0?a.skinning:false;this.morphTargets=a.morphTargets!==void 0?a.morphTargets:false;this.morphNormals=a.morphNormals!==void 0?a.morphNormals:false};THREE.ShaderMaterial.prototype=new THREE.Material;THREE.ShaderMaterial.prototype.constructor=THREE.ShaderMaterial;
  22439. THREE.Texture=function(a,b,c,d,e,f,g,h){this.id=THREE.TextureCount++;this.image=a;this.mapping=b!==void 0?b:new THREE.UVMapping;this.wrapS=c!==void 0?c:THREE.ClampToEdgeWrapping;this.wrapT=d!==void 0?d:THREE.ClampToEdgeWrapping;this.magFilter=e!==void 0?e:THREE.LinearFilter;this.minFilter=f!==void 0?f:THREE.LinearMipMapLinearFilter;this.format=g!==void 0?g:THREE.RGBAFormat;this.type=h!==void 0?h:THREE.UnsignedByteType;this.offset=new THREE.Vector2(0,0);this.repeat=new THREE.Vector2(1,1);this.generateMipmaps=
  22440. true;this.needsUpdate=this.premultiplyAlpha=false;this.onUpdate=null};THREE.Texture.prototype={constructor:THREE.Texture,clone:function(){var a=new THREE.Texture(this.image,this.mapping,this.wrapS,this.wrapT,this.magFilter,this.minFilter,this.format,this.type);a.offset.copy(this.offset);a.repeat.copy(this.repeat);return a}};THREE.TextureCount=0;THREE.MultiplyOperation=0;THREE.MixOperation=1;THREE.UVMapping=function(){};THREE.CubeReflectionMapping=function(){};THREE.CubeRefractionMapping=function(){};
  22441. THREE.SphericalReflectionMapping=function(){};THREE.SphericalRefractionMapping=function(){};THREE.RepeatWrapping=0;THREE.ClampToEdgeWrapping=1;THREE.MirroredRepeatWrapping=2;THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLinearFilter=5;THREE.LinearFilter=6;THREE.LinearMipMapNearestFilter=7;THREE.LinearMipMapLinearFilter=8;THREE.ByteType=9;THREE.UnsignedByteType=10;THREE.ShortType=11;THREE.UnsignedShortType=12;THREE.IntType=13;THREE.UnsignedIntType=14;THREE.FloatType=15;
  22442. THREE.AlphaFormat=16;THREE.RGBFormat=17;THREE.RGBAFormat=18;THREE.LuminanceFormat=19;THREE.LuminanceAlphaFormat=20;THREE.DataTexture=function(a,b,c,d,e,f,g,h,k,j){THREE.Texture.call(this,null,f,g,h,k,j,d,e);this.image={data:a,width:b,height:c}};THREE.DataTexture.prototype=new THREE.Texture;THREE.DataTexture.prototype.constructor=THREE.DataTexture;
  22443. THREE.DataTexture.prototype.clone=function(){var a=new THREE.DataTexture(this.image.data,this.image.width,this.image.height,this.format,this.type,this.mapping,this.wrapS,this.wrapT,this.magFilter,this.minFilter);a.offset.copy(this.offset);a.repeat.copy(this.repeat);return a};THREE.Particle=function(a){THREE.Object3D.call(this);this.material=a};THREE.Particle.prototype=new THREE.Object3D;THREE.Particle.prototype.constructor=THREE.Particle;
  22444. THREE.ParticleSystem=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.material=b!==void 0?b:new THREE.ParticleBasicMaterial({color:Math.random()*16777215});this.sortParticles=false;if(this.geometry){this.geometry.boundingSphere||this.geometry.computeBoundingSphere();this.boundRadius=a.boundingSphere.radius}this.frustumCulled=false};THREE.ParticleSystem.prototype=new THREE.Object3D;THREE.ParticleSystem.prototype.constructor=THREE.ParticleSystem;
  22445. THREE.Line=function(a,b,c){THREE.Object3D.call(this);this.geometry=a;this.material=b!==void 0?b:new THREE.LineBasicMaterial({color:Math.random()*16777215});this.type=c!==void 0?c:THREE.LineStrip;this.geometry&&(this.geometry.boundingSphere||this.geometry.computeBoundingSphere())};THREE.LineStrip=0;THREE.LinePieces=1;THREE.Line.prototype=new THREE.Object3D;THREE.Line.prototype.constructor=THREE.Line;
  22446. THREE.Mesh=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.material=b!==void 0?b:new THREE.MeshBasicMaterial({color:Math.random()*16777215,wireframe:true});if(this.geometry){this.geometry.boundingSphere||this.geometry.computeBoundingSphere();this.boundRadius=a.boundingSphere.radius;if(this.geometry.morphTargets.length){this.morphTargetBase=-1;this.morphTargetForcedOrder=[];this.morphTargetInfluences=[];this.morphTargetDictionary={};for(var c=0;c<this.geometry.morphTargets.length;c++){this.morphTargetInfluences.push(0);
  22447. this.morphTargetDictionary[this.geometry.morphTargets[c].name]=c}}}};THREE.Mesh.prototype=new THREE.Object3D;THREE.Mesh.prototype.constructor=THREE.Mesh;THREE.Mesh.prototype.supr=THREE.Object3D.prototype;THREE.Mesh.prototype.getMorphTargetIndexByName=function(a){if(this.morphTargetDictionary[a]!==void 0)return this.morphTargetDictionary[a];console.log("THREE.Mesh.getMorphTargetIndexByName: morph target "+a+" does not exist. Returning 0.");return 0};
  22448. THREE.Bone=function(a){THREE.Object3D.call(this);this.skin=a;this.skinMatrix=new THREE.Matrix4};THREE.Bone.prototype=new THREE.Object3D;THREE.Bone.prototype.constructor=THREE.Bone;THREE.Bone.prototype.supr=THREE.Object3D.prototype;
  22449. THREE.Bone.prototype.update=function(a,b){this.matrixAutoUpdate&&(b=b|this.updateMatrix());if(b||this.matrixWorldNeedsUpdate){a?this.skinMatrix.multiply(a,this.matrix):this.skinMatrix.copy(this.matrix);this.matrixWorldNeedsUpdate=false;b=true}var c,d=this.children.length;for(c=0;c<d;c++)this.children[c].update(this.skinMatrix,b)};
  22450. THREE.SkinnedMesh=function(a,b){THREE.Mesh.call(this,a,b);this.identityMatrix=new THREE.Matrix4;this.bones=[];this.boneMatrices=[];var c,d,e,f,g,h;if(this.geometry.bones!==void 0){for(c=0;c<this.geometry.bones.length;c++){e=this.geometry.bones[c];f=e.pos;g=e.rotq;h=e.scl;d=this.addBone();d.name=e.name;d.position.set(f[0],f[1],f[2]);d.quaternion.set(g[0],g[1],g[2],g[3]);d.useQuaternion=true;h!==void 0?d.scale.set(h[0],h[1],h[2]):d.scale.set(1,1,1)}for(c=0;c<this.bones.length;c++){e=this.geometry.bones[c];
  22451. d=this.bones[c];e.parent===-1?this.add(d):this.bones[e.parent].add(d)}this.boneMatrices=new Float32Array(16*this.bones.length);this.pose()}};THREE.SkinnedMesh.prototype=new THREE.Mesh;THREE.SkinnedMesh.prototype.constructor=THREE.SkinnedMesh;THREE.SkinnedMesh.prototype.addBone=function(a){a===void 0&&(a=new THREE.Bone(this));this.bones.push(a);return a};
  22452. THREE.SkinnedMesh.prototype.updateMatrixWorld=function(a){this.matrixAutoUpdate&&this.updateMatrix();if(this.matrixWorldNeedsUpdate||a){this.parent?this.matrixWorld.multiply(this.parent.matrixWorld,this.matrix):this.matrixWorld.copy(this.matrix);this.matrixWorldNeedsUpdate=false}for(var a=0,b=this.children.length;a<b;a++){var c=this.children[a];c instanceof THREE.Bone?c.update(this.identityMatrix,false):c.updateMatrixWorld(true)}for(var b=this.bones.length,c=this.bones,d=this.boneMatrices,a=0;a<b;a++)c[a].skinMatrix.flattenToArrayOffset(d,
  22453. a*16)};
  22454. THREE.SkinnedMesh.prototype.pose=function(){this.updateMatrixWorld(true);for(var a,b=[],c=0;c<this.bones.length;c++){a=this.bones[c];var d=new THREE.Matrix4;d.getInverse(a.skinMatrix);b.push(d);a.skinMatrix.flattenToArrayOffset(this.boneMatrices,c*16)}if(this.geometry.skinVerticesA===void 0){this.geometry.skinVerticesA=[];this.geometry.skinVerticesB=[];for(a=0;a<this.geometry.skinIndices.length;a++){var c=this.geometry.vertices[a],e=this.geometry.skinIndices[a].x,f=this.geometry.skinIndices[a].y,d=
  22455. new THREE.Vector3(c.x,c.y,c.z);this.geometry.skinVerticesA.push(b[e].multiplyVector3(d));d=new THREE.Vector3(c.x,c.y,c.z);this.geometry.skinVerticesB.push(b[f].multiplyVector3(d));if(this.geometry.skinWeights[a].x+this.geometry.skinWeights[a].y!==1){c=(1-(this.geometry.skinWeights[a].x+this.geometry.skinWeights[a].y))*0.5;this.geometry.skinWeights[a].x=this.geometry.skinWeights[a].x+c;this.geometry.skinWeights[a].y=this.geometry.skinWeights[a].y+c}}}};
  22456. THREE.MorphAnimMesh=function(a,b){THREE.Mesh.call(this,a,b);this.duration=1E3;this.mirroredLoop=false;this.currentKeyframe=this.lastKeyframe=this.time=0;this.direction=1;this.directionBackwards=false;this.setFrameRange(0,this.geometry.morphTargets.length-1)};THREE.MorphAnimMesh.prototype=new THREE.Mesh;THREE.MorphAnimMesh.prototype.constructor=THREE.MorphAnimMesh;
  22457. THREE.MorphAnimMesh.prototype.setFrameRange=function(a,b){this.startKeyframe=a;this.endKeyframe=b;this.length=this.endKeyframe-this.startKeyframe+1};THREE.MorphAnimMesh.prototype.setDirectionForward=function(){this.direction=1;this.directionBackwards=false};THREE.MorphAnimMesh.prototype.setDirectionBackward=function(){this.direction=-1;this.directionBackwards=true};
  22458. THREE.MorphAnimMesh.prototype.parseAnimations=function(){var a=this.geometry;if(!a.animations)a.animations={};for(var b,c=a.animations,d=/([a-z]+)(\d+)/,e=0,f=a.morphTargets.length;e<f;e++){var g=a.morphTargets[e].name.match(d);if(g&&g.length>1){g=g[1];c[g]||(c[g]={start:Infinity,end:-Infinity});var h=c[g];if(e<h.start)h.start=e;if(e>h.end)h.end=e;b||(b=g)}}a.firstAnimation=b};
  22459. THREE.MorphAnimMesh.prototype.setAnimationLabel=function(a,b,c){if(!this.geometry.animations)this.geometry.animations={};this.geometry.animations[a]={start:b,end:c}};THREE.MorphAnimMesh.prototype.playAnimation=function(a,b){var c=this.geometry.animations[a];if(c){this.setFrameRange(c.start,c.end);this.duration=1E3*((c.end-c.start)/b);this.time=0}else console.warn("animation["+a+"] undefined")};
  22460. THREE.MorphAnimMesh.prototype.updateAnimation=function(a){var b=this.duration/this.length;this.time=this.time+this.direction*a;if(this.mirroredLoop){if(this.time>this.duration||this.time<0){this.direction=this.direction*-1;if(this.time>this.duration){this.time=this.duration;this.directionBackwards=true}if(this.time<0){this.time=0;this.directionBackwards=false}}}else{this.time=this.time%this.duration;if(this.time<0)this.time=this.time+this.duration}a=this.startKeyframe+THREE.Math.clamp(Math.floor(this.time/
  22461. b),0,this.length-1);if(a!==this.currentKeyframe){this.morphTargetInfluences[this.lastKeyframe]=0;this.morphTargetInfluences[this.currentKeyframe]=1;this.morphTargetInfluences[a]=0;this.lastKeyframe=this.currentKeyframe;this.currentKeyframe=a}b=this.time%b/b;this.directionBackwards&&(b=1-b);this.morphTargetInfluences[this.currentKeyframe]=b;this.morphTargetInfluences[this.lastKeyframe]=1-b};THREE.Ribbon=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.material=b};
  22462. THREE.Ribbon.prototype=new THREE.Object3D;THREE.Ribbon.prototype.constructor=THREE.Ribbon;THREE.LOD=function(){THREE.Object3D.call(this);this.LODs=[]};THREE.LOD.prototype=new THREE.Object3D;THREE.LOD.prototype.constructor=THREE.LOD;THREE.LOD.prototype.supr=THREE.Object3D.prototype;THREE.LOD.prototype.addLevel=function(a,b){b===void 0&&(b=0);for(var b=Math.abs(b),c=0;c<this.LODs.length;c++)if(b<this.LODs[c].visibleAtDistance)break;this.LODs.splice(c,0,{visibleAtDistance:b,object3D:a});this.add(a)};
  22463. THREE.LOD.prototype.update=function(a){if(this.LODs.length>1){a.matrixWorldInverse.getInverse(a.matrixWorld);a=a.matrixWorldInverse;a=-(a.elements[2]*this.matrixWorld.elements[12]+a.elements[6]*this.matrixWorld.elements[13]+a.elements[10]*this.matrixWorld.elements[14]+a.elements[14]);this.LODs[0].object3D.visible=true;for(var b=1;b<this.LODs.length;b++)if(a>=this.LODs[b].visibleAtDistance){this.LODs[b-1].object3D.visible=false;this.LODs[b].object3D.visible=true}else break;for(;b<this.LODs.length;b++)this.LODs[b].object3D.visible=
  22464. false}};
  22465. THREE.Sprite=function(a){THREE.Object3D.call(this);this.color=a.color!==void 0?new THREE.Color(a.color):new THREE.Color(16777215);this.map=a.map!==void 0?a.map:new THREE.Texture;this.blending=a.blending!==void 0?a.blending:THREE.NormalBlending;this.blendSrc=a.blendSrc!==void 0?a.blendSrc:THREE.SrcAlphaFactor;this.blendDst=a.blendDst!==void 0?a.blendDst:THREE.OneMinusSrcAlphaFactor;this.blendEquation=a.blendEquation!==void 0?a.blendEquation:THREE.AddEquation;this.useScreenCoordinates=a.useScreenCoordinates!==void 0?
  22466. a.useScreenCoordinates:true;this.mergeWith3D=a.mergeWith3D!==void 0?a.mergeWith3D:!this.useScreenCoordinates;this.affectedByDistance=a.affectedByDistance!==void 0?a.affectedByDistance:!this.useScreenCoordinates;this.scaleByViewport=a.scaleByViewport!==void 0?a.scaleByViewport:!this.affectedByDistance;this.alignment=a.alignment instanceof THREE.Vector2?a.alignment:THREE.SpriteAlignment.center;this.rotation3d=this.rotation;this.rotation=0;this.opacity=1;this.uvOffset=new THREE.Vector2(0,0);this.uvScale=
  22467. new THREE.Vector2(1,1)};THREE.Sprite.prototype=new THREE.Object3D;THREE.Sprite.prototype.constructor=THREE.Sprite;THREE.Sprite.prototype.updateMatrix=function(){this.matrix.setPosition(this.position);this.rotation3d.set(0,0,this.rotation);this.matrix.setRotationFromEuler(this.rotation3d);if(this.scale.x!==1||this.scale.y!==1){this.matrix.scale(this.scale);this.boundRadiusScale=Math.max(this.scale.x,this.scale.y)}this.matrixWorldNeedsUpdate=true};THREE.SpriteAlignment={};
  22468. THREE.SpriteAlignment.topLeft=new THREE.Vector2(1,-1);THREE.SpriteAlignment.topCenter=new THREE.Vector2(0,-1);THREE.SpriteAlignment.topRight=new THREE.Vector2(-1,-1);THREE.SpriteAlignment.centerLeft=new THREE.Vector2(1,0);THREE.SpriteAlignment.center=new THREE.Vector2(0,0);THREE.SpriteAlignment.centerRight=new THREE.Vector2(-1,0);THREE.SpriteAlignment.bottomLeft=new THREE.Vector2(1,1);THREE.SpriteAlignment.bottomCenter=new THREE.Vector2(0,1);
  22469. THREE.SpriteAlignment.bottomRight=new THREE.Vector2(-1,1);THREE.Scene=function(){THREE.Object3D.call(this);this.overrideMaterial=this.fog=null;this.matrixAutoUpdate=false;this.__objects=[];this.__lights=[];this.__objectsAdded=[];this.__objectsRemoved=[]};THREE.Scene.prototype=new THREE.Object3D;THREE.Scene.prototype.constructor=THREE.Scene;
  22470. THREE.Scene.prototype.__addObject=function(a){if(a instanceof THREE.Light)this.__lights.indexOf(a)===-1&&this.__lights.push(a);else if(!(a instanceof THREE.Camera||a instanceof THREE.Bone)&&this.__objects.indexOf(a)===-1){this.__objects.push(a);this.__objectsAdded.push(a);var b=this.__objectsRemoved.indexOf(a);b!==-1&&this.__objectsRemoved.splice(b,1)}for(b=0;b<a.children.length;b++)this.__addObject(a.children[b])};
  22471. THREE.Scene.prototype.__removeObject=function(a){if(a instanceof THREE.Light){var b=this.__lights.indexOf(a);b!==-1&&this.__lights.splice(b,1)}else if(!(a instanceof THREE.Camera)){b=this.__objects.indexOf(a);if(b!==-1){this.__objects.splice(b,1);this.__objectsRemoved.push(a);b=this.__objectsAdded.indexOf(a);b!==-1&&this.__objectsAdded.splice(b,1)}}for(b=0;b<a.children.length;b++)this.__removeObject(a.children[b])};
  22472. THREE.Fog=function(a,b,c){this.color=new THREE.Color(a);this.near=b!==void 0?b:1;this.far=c!==void 0?c:1E3};THREE.FogExp2=function(a,b){this.color=new THREE.Color(a);this.density=b!==void 0?b:2.5E-4};
  22473. THREE.DOMRenderer=function(){console.log("THREE.DOMRenderer",THREE.REVISION);var a,b,c,d,e,f,g,h=new THREE.Projector;g=function(a){for(var b=document.documentElement,c=0;c<a.length;c++)if(typeof b.style[a[c]]==="string")return a[c];return null}(["transform","MozTransform","WebkitTransform","msTransform","OTransform"]);this.domElement=document.createElement("div");this.setSize=function(a,b){c=a;d=b;e=c/2;f=d/2};this.render=function(c,d){var l,p,m,o,q,n;a=h.projectScene(c,d);b=a.elements;l=0;for(p=
  22474. b.length;l<p;l++){m=b[l];if(m instanceof THREE.RenderableParticle&&m.material instanceof THREE.ParticleDOMMaterial){o=m.material.domElement;q=m.x*e+e-(o.offsetWidth>>1);n=m.y*f+f-(o.offsetHeight>>1);o.style.left=q+"px";o.style.top=n+"px";o.style.zIndex=Math.abs(Math.floor((1-m.z)*d.far/d.near));g&&(o.style[g]="scale("+m.scale.x*e+","+m.scale.y*f+")")}}}};
  22475. THREE.CanvasRenderer=function(a){function b(a){if(t!=a)n.globalAlpha=t=a}function c(a){if(w!=a){switch(a){case THREE.NormalBlending:n.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:n.globalCompositeOperation="lighter"}w=a}}function d(a){if(s!=a)n.strokeStyle=s=a}function e(a){if(x!=a)n.fillStyle=x=a}console.log("THREE.CanvasRenderer",THREE.REVISION);var a=a||{},f=this,g,h,k,j=new THREE.Projector,l=a.canvas!==void 0?a.canvas:document.createElement("canvas"),p,m,o,q,n=l.getContext("2d"),
  22476. r=new THREE.Color(0),u=0,t=1,w=0,s=null,x=null,F=null,D=null,z=null,v,A,J,K,R=new THREE.RenderableVertex,P=new THREE.RenderableVertex,E,M,G,i,T,U,C,Y,I,ea,fa,ia,O=new THREE.Color,Q=new THREE.Color,Z=new THREE.Color,$=new THREE.Color,ha=new THREE.Color,Ma=[],Ka=[],Ra,La,Sa,Na,Kb,lb,gb,Lb,hb,Cb,Wa=new THREE.Rectangle,Ba=new THREE.Rectangle,xa=new THREE.Rectangle,$a=false,aa=new THREE.Color,Ta=new THREE.Color,Qa=new THREE.Color,oa=new THREE.Vector3,ib,Db,Sc,ab,pc,Bc,a=16;ib=document.createElement("canvas");
  22477. ib.width=ib.height=2;Db=ib.getContext("2d");Db.fillStyle="rgba(0,0,0,1)";Db.fillRect(0,0,2,2);Sc=Db.getImageData(0,0,2,2);ab=Sc.data;pc=document.createElement("canvas");pc.width=pc.height=a;Bc=pc.getContext("2d");Bc.translate(-a/2,-a/2);Bc.scale(a,a);a--;this.domElement=l;this.sortElements=this.sortObjects=this.autoClear=true;this.info={render:{vertices:0,faces:0}};this.setSize=function(a,b){p=a;m=b;o=Math.floor(p/2);q=Math.floor(m/2);l.width=p;l.height=m;Wa.set(-o,-q,o,q);Ba.set(-o,-q,o,q);t=1;w=
  22478. 0;z=D=F=x=s=null};this.setClearColor=function(a,b){r.copy(a);u=b!==void 0?b:1;Ba.set(-o,-q,o,q)};this.setClearColorHex=function(a,b){r.setHex(a);u=b!==void 0?b:1;Ba.set(-o,-q,o,q)};this.clear=function(){n.setTransform(1,0,0,-1,o,q);if(!Ba.isEmpty()){Ba.minSelf(Wa);Ba.inflate(2);u<1&&n.clearRect(Math.floor(Ba.getX()),Math.floor(Ba.getY()),Math.floor(Ba.getWidth()),Math.floor(Ba.getHeight()));if(u>0){c(THREE.NormalBlending);b(1);e("rgba("+Math.floor(r.r*255)+","+Math.floor(r.g*255)+","+Math.floor(r.b*
  22479. 255)+","+u+")");n.fillRect(Math.floor(Ba.getX()),Math.floor(Ba.getY()),Math.floor(Ba.getWidth()),Math.floor(Ba.getHeight()))}Ba.empty()}};this.render=function(a,l){function m(a){var b,c,d,e;aa.setRGB(0,0,0);Ta.setRGB(0,0,0);Qa.setRGB(0,0,0);b=0;for(c=a.length;b<c;b++){d=a[b];e=d.color;if(d instanceof THREE.AmbientLight){aa.r=aa.r+e.r;aa.g=aa.g+e.g;aa.b=aa.b+e.b}else if(d instanceof THREE.DirectionalLight){Ta.r=Ta.r+e.r;Ta.g=Ta.g+e.g;Ta.b=Ta.b+e.b}else if(d instanceof THREE.PointLight){Qa.r=Qa.r+e.r;
  22480. Qa.g=Qa.g+e.g;Qa.b=Qa.b+e.b}}}function p(a,b,c,d){var e,f,g,i,h,k;e=0;for(f=a.length;e<f;e++){g=a[e];i=g.color;if(g instanceof THREE.DirectionalLight){h=g.matrixWorld.getPosition();k=c.dot(h);if(!(k<=0)){k=k*g.intensity;d.r=d.r+i.r*k;d.g=d.g+i.g*k;d.b=d.b+i.b*k}}else if(g instanceof THREE.PointLight){h=g.matrixWorld.getPosition();k=c.dot(oa.sub(h,b).normalize());if(!(k<=0)){k=k*(g.distance==0?1:1-Math.min(b.distanceTo(h)/g.distance,1));if(k!=0){k=k*g.intensity;d.r=d.r+i.r*k;d.g=d.g+i.g*k;d.b=d.b+
  22481. i.b*k}}}}}function r(a,f,g){b(g.opacity);c(g.blending);var i,h,k,j,l,m;if(g instanceof THREE.ParticleBasicMaterial){if(g.map){j=g.map.image;l=j.width>>1;m=j.height>>1;g=f.scale.x*o;k=f.scale.y*q;i=g*l;h=k*m;xa.set(a.x-i,a.y-h,a.x+i,a.y+h);if(Wa.intersects(xa)){n.save();n.translate(a.x,a.y);n.rotate(-f.rotation);n.scale(g,-k);n.translate(-l,-m);n.drawImage(j,0,0);n.restore()}}}else if(g instanceof THREE.ParticleCanvasMaterial){i=f.scale.x*o;h=f.scale.y*q;xa.set(a.x-i,a.y-h,a.x+i,a.y+h);if(Wa.intersects(xa)){d(g.color.getContextStyle());
  22482. e(g.color.getContextStyle());n.save();n.translate(a.x,a.y);n.rotate(-f.rotation);n.scale(i,h);g.program(n);n.restore()}}}function s(a,e,f,g){b(g.opacity);c(g.blending);n.beginPath();n.moveTo(a.positionScreen.x,a.positionScreen.y);n.lineTo(e.positionScreen.x,e.positionScreen.y);n.closePath();if(g instanceof THREE.LineBasicMaterial){a=g.linewidth;if(F!=a)n.lineWidth=F=a;a=g.linecap;if(D!=a)n.lineCap=D=a;a=g.linejoin;if(z!=a)n.lineJoin=z=a;d(g.color.getContextStyle());n.stroke();xa.inflate(g.linewidth*
  22483. 2)}}function t(a,d,e,g,h,j,m,n){f.info.render.vertices=f.info.render.vertices+3;f.info.render.faces++;b(n.opacity);c(n.blending);E=a.positionScreen.x;M=a.positionScreen.y;G=d.positionScreen.x;i=d.positionScreen.y;T=e.positionScreen.x;U=e.positionScreen.y;x(E,M,G,i,T,U);if(n instanceof THREE.MeshBasicMaterial)if(n.map){if(n.map.mapping instanceof THREE.UVMapping){Na=m.uvs[0];ad(E,M,G,i,T,U,Na[g].u,Na[g].v,Na[h].u,Na[h].v,Na[j].u,Na[j].v,n.map)}}else if(n.envMap){if(n.envMap.mapping instanceof THREE.SphericalReflectionMapping){a=
  22484. l.matrixWorldInverse;oa.copy(m.vertexNormalsWorld[g]);Kb=(oa.x*a.elements[0]+oa.y*a.elements[4]+oa.z*a.elements[8])*0.5+0.5;lb=-(oa.x*a.elements[1]+oa.y*a.elements[5]+oa.z*a.elements[9])*0.5+0.5;oa.copy(m.vertexNormalsWorld[h]);gb=(oa.x*a.elements[0]+oa.y*a.elements[4]+oa.z*a.elements[8])*0.5+0.5;Lb=-(oa.x*a.elements[1]+oa.y*a.elements[5]+oa.z*a.elements[9])*0.5+0.5;oa.copy(m.vertexNormalsWorld[j]);hb=(oa.x*a.elements[0]+oa.y*a.elements[4]+oa.z*a.elements[8])*0.5+0.5;Cb=-(oa.x*a.elements[1]+oa.y*
  22485. a.elements[5]+oa.z*a.elements[9])*0.5+0.5;ad(E,M,G,i,T,U,Kb,lb,gb,Lb,hb,Cb,n.envMap)}}else n.wireframe?Mb(n.color,n.wireframeLinewidth,n.wireframeLinecap,n.wireframeLinejoin):Eb(n.color);else if(n instanceof THREE.MeshLambertMaterial)if($a)if(!n.wireframe&&n.shading==THREE.SmoothShading&&m.vertexNormalsWorld.length==3){Q.r=Z.r=$.r=aa.r;Q.g=Z.g=$.g=aa.g;Q.b=Z.b=$.b=aa.b;p(k,m.v1.positionWorld,m.vertexNormalsWorld[0],Q);p(k,m.v2.positionWorld,m.vertexNormalsWorld[1],Z);p(k,m.v3.positionWorld,m.vertexNormalsWorld[2],
  22486. $);Q.r=Math.max(0,Math.min(n.color.r*Q.r,1));Q.g=Math.max(0,Math.min(n.color.g*Q.g,1));Q.b=Math.max(0,Math.min(n.color.b*Q.b,1));Z.r=Math.max(0,Math.min(n.color.r*Z.r,1));Z.g=Math.max(0,Math.min(n.color.g*Z.g,1));Z.b=Math.max(0,Math.min(n.color.b*Z.b,1));$.r=Math.max(0,Math.min(n.color.r*$.r,1));$.g=Math.max(0,Math.min(n.color.g*$.g,1));$.b=Math.max(0,Math.min(n.color.b*$.b,1));ha.r=(Z.r+$.r)*0.5;ha.g=(Z.g+$.g)*0.5;ha.b=(Z.b+$.b)*0.5;Sa=Cc(Q,Z,$,ha);gc(E,M,G,i,T,U,0,0,1,0,0,1,Sa)}else{O.r=aa.r;O.g=
  22487. aa.g;O.b=aa.b;p(k,m.centroidWorld,m.normalWorld,O);O.r=Math.max(0,Math.min(n.color.r*O.r,1));O.g=Math.max(0,Math.min(n.color.g*O.g,1));O.b=Math.max(0,Math.min(n.color.b*O.b,1));n.wireframe?Mb(O,n.wireframeLinewidth,n.wireframeLinecap,n.wireframeLinejoin):Eb(O)}else n.wireframe?Mb(n.color,n.wireframeLinewidth,n.wireframeLinecap,n.wireframeLinejoin):Eb(n.color);else if(n instanceof THREE.MeshDepthMaterial){Ra=l.near;La=l.far;Q.r=Q.g=Q.b=1-ac(a.positionScreen.z,Ra,La);Z.r=Z.g=Z.b=1-ac(d.positionScreen.z,
  22488. Ra,La);$.r=$.g=$.b=1-ac(e.positionScreen.z,Ra,La);ha.r=(Z.r+$.r)*0.5;ha.g=(Z.g+$.g)*0.5;ha.b=(Z.b+$.b)*0.5;Sa=Cc(Q,Z,$,ha);gc(E,M,G,i,T,U,0,0,1,0,0,1,Sa)}else if(n instanceof THREE.MeshNormalMaterial){O.r=hc(m.normalWorld.x);O.g=hc(m.normalWorld.y);O.b=hc(m.normalWorld.z);n.wireframe?Mb(O,n.wireframeLinewidth,n.wireframeLinecap,n.wireframeLinejoin):Eb(O)}}function u(a,d,e,g,h,j,n,m,o){f.info.render.vertices=f.info.render.vertices+4;f.info.render.faces++;b(m.opacity);c(m.blending);if(m.map||m.envMap){t(a,
  22489. d,g,0,1,3,n,m,o);t(h,e,j,1,2,3,n,m,o)}else{E=a.positionScreen.x;M=a.positionScreen.y;G=d.positionScreen.x;i=d.positionScreen.y;T=e.positionScreen.x;U=e.positionScreen.y;C=g.positionScreen.x;Y=g.positionScreen.y;I=h.positionScreen.x;ea=h.positionScreen.y;fa=j.positionScreen.x;ia=j.positionScreen.y;if(m instanceof THREE.MeshBasicMaterial){w(E,M,G,i,T,U,C,Y);m.wireframe?Mb(m.color,m.wireframeLinewidth,m.wireframeLinecap,m.wireframeLinejoin):Eb(m.color)}else if(m instanceof THREE.MeshLambertMaterial)if($a)if(!m.wireframe&&
  22490. m.shading==THREE.SmoothShading&&n.vertexNormalsWorld.length==4){Q.r=Z.r=$.r=ha.r=aa.r;Q.g=Z.g=$.g=ha.g=aa.g;Q.b=Z.b=$.b=ha.b=aa.b;p(k,n.v1.positionWorld,n.vertexNormalsWorld[0],Q);p(k,n.v2.positionWorld,n.vertexNormalsWorld[1],Z);p(k,n.v4.positionWorld,n.vertexNormalsWorld[3],$);p(k,n.v3.positionWorld,n.vertexNormalsWorld[2],ha);Q.r=Math.max(0,Math.min(m.color.r*Q.r,1));Q.g=Math.max(0,Math.min(m.color.g*Q.g,1));Q.b=Math.max(0,Math.min(m.color.b*Q.b,1));Z.r=Math.max(0,Math.min(m.color.r*Z.r,1));Z.g=
  22491. Math.max(0,Math.min(m.color.g*Z.g,1));Z.b=Math.max(0,Math.min(m.color.b*Z.b,1));$.r=Math.max(0,Math.min(m.color.r*$.r,1));$.g=Math.max(0,Math.min(m.color.g*$.g,1));$.b=Math.max(0,Math.min(m.color.b*$.b,1));ha.r=Math.max(0,Math.min(m.color.r*ha.r,1));ha.g=Math.max(0,Math.min(m.color.g*ha.g,1));ha.b=Math.max(0,Math.min(m.color.b*ha.b,1));Sa=Cc(Q,Z,$,ha);x(E,M,G,i,C,Y);gc(E,M,G,i,C,Y,0,0,1,0,0,1,Sa);x(I,ea,T,U,fa,ia);gc(I,ea,T,U,fa,ia,1,0,1,1,0,1,Sa)}else{O.r=aa.r;O.g=aa.g;O.b=aa.b;p(k,n.centroidWorld,
  22492. n.normalWorld,O);O.r=Math.max(0,Math.min(m.color.r*O.r,1));O.g=Math.max(0,Math.min(m.color.g*O.g,1));O.b=Math.max(0,Math.min(m.color.b*O.b,1));w(E,M,G,i,T,U,C,Y);m.wireframe?Mb(O,m.wireframeLinewidth,m.wireframeLinecap,m.wireframeLinejoin):Eb(O)}else{w(E,M,G,i,T,U,C,Y);m.wireframe?Mb(m.color,m.wireframeLinewidth,m.wireframeLinecap,m.wireframeLinejoin):Eb(m.color)}else if(m instanceof THREE.MeshNormalMaterial){O.r=hc(n.normalWorld.x);O.g=hc(n.normalWorld.y);O.b=hc(n.normalWorld.z);w(E,M,G,i,T,U,C,
  22493. Y);m.wireframe?Mb(O,m.wireframeLinewidth,m.wireframeLinecap,m.wireframeLinejoin):Eb(O)}else if(m instanceof THREE.MeshDepthMaterial){Ra=l.near;La=l.far;Q.r=Q.g=Q.b=1-ac(a.positionScreen.z,Ra,La);Z.r=Z.g=Z.b=1-ac(d.positionScreen.z,Ra,La);$.r=$.g=$.b=1-ac(g.positionScreen.z,Ra,La);ha.r=ha.g=ha.b=1-ac(e.positionScreen.z,Ra,La);Sa=Cc(Q,Z,$,ha);x(E,M,G,i,C,Y);gc(E,M,G,i,C,Y,0,0,1,0,0,1,Sa);x(I,ea,T,U,fa,ia);gc(I,ea,T,U,fa,ia,1,0,1,1,0,1,Sa)}}}function x(a,b,c,d,e,f){n.beginPath();n.moveTo(a,b);n.lineTo(c,
  22494. d);n.lineTo(e,f);n.lineTo(a,b);n.closePath()}function w(a,b,c,d,e,f,g,i){n.beginPath();n.moveTo(a,b);n.lineTo(c,d);n.lineTo(e,f);n.lineTo(g,i);n.lineTo(a,b);n.closePath()}function Mb(a,b,c,e){if(F!=b)n.lineWidth=F=b;if(D!=c)n.lineCap=D=c;if(z!=e)n.lineJoin=z=e;d(a.getContextStyle());n.stroke();xa.inflate(b*2)}function Eb(a){e(a.getContextStyle());n.fill()}function ad(a,b,c,d,f,g,i,h,k,j,l,m,o){if(o.image.width!=0){if(o.needsUpdate==true||Ma[o.id]==void 0){var p=o.wrapS==THREE.RepeatWrapping,q=o.wrapT==
  22495. THREE.RepeatWrapping;Ma[o.id]=n.createPattern(o.image,p&&q?"repeat":p&&!q?"repeat-x":!p&&q?"repeat-y":"no-repeat");o.needsUpdate=false}e(Ma[o.id]);var p=o.offset.x/o.repeat.x,q=o.offset.y/o.repeat.y,Db=o.image.width*o.repeat.x,r=o.image.height*o.repeat.y,i=(i+p)*Db,h=(h+q)*r,c=c-a,d=d-b,f=f-a,g=g-b,k=(k+p)*Db-i,j=(j+q)*r-h,l=(l+p)*Db-i,m=(m+q)*r-h,p=k*m-l*j;if(p==0){if(Ka[o.id]===void 0){b=document.createElement("canvas");b.width=o.image.width;b.height=o.image.height;b=b.getContext("2d");b.drawImage(o.image,
  22496. 0,0);Ka[o.id]=b.getImageData(0,0,o.image.width,o.image.height).data}b=Ka[o.id];i=(Math.floor(i)+Math.floor(h)*o.image.width)*4;O.setRGB(b[i]/255,b[i+1]/255,b[i+2]/255);Eb(O)}else{p=1/p;o=(m*c-j*f)*p;j=(m*d-j*g)*p;c=(k*f-l*c)*p;d=(k*g-l*d)*p;a=a-o*i-c*h;i=b-j*i-d*h;n.save();n.transform(o,j,c,d,a,i);n.fill();n.restore()}}}function gc(a,b,c,d,e,f,g,i,h,k,j,l,m){var o,p;o=m.width-1;p=m.height-1;g=g*o;i=i*p;c=c-a;d=d-b;e=e-a;f=f-b;h=h*o-g;k=k*p-i;j=j*o-g;l=l*p-i;p=1/(h*l-j*k);o=(l*c-k*e)*p;k=(l*d-k*f)*
  22497. p;c=(h*e-j*c)*p;d=(h*f-j*d)*p;a=a-o*g-c*i;b=b-k*g-d*i;n.save();n.transform(o,k,c,d,a,b);n.clip();n.drawImage(m,0,0);n.restore()}function Cc(a,b,c,d){var e=~~(a.r*255),f=~~(a.g*255),a=~~(a.b*255),g=~~(b.r*255),i=~~(b.g*255),b=~~(b.b*255),h=~~(c.r*255),k=~~(c.g*255),c=~~(c.b*255),j=~~(d.r*255),l=~~(d.g*255),d=~~(d.b*255);ab[0]=e<0?0:e>255?255:e;ab[1]=f<0?0:f>255?255:f;ab[2]=a<0?0:a>255?255:a;ab[4]=g<0?0:g>255?255:g;ab[5]=i<0?0:i>255?255:i;ab[6]=b<0?0:b>255?255:b;ab[8]=h<0?0:h>255?255:h;ab[9]=k<0?0:
  22498. k>255?255:k;ab[10]=c<0?0:c>255?255:c;ab[12]=j<0?0:j>255?255:j;ab[13]=l<0?0:l>255?255:l;ab[14]=d<0?0:d>255?255:d;Db.putImageData(Sc,0,0);Bc.drawImage(ib,0,0);return pc}function ac(a,b,c){a=(a-b)/(c-b);return a*a*(3-2*a)}function hc(a){a=(a+1)*0.5;return a<0?0:a>1?1:a}function Nb(a,b){var c=b.x-a.x,d=b.y-a.y,e=c*c+d*d;if(e!=0){e=1/Math.sqrt(e);c=c*e;d=d*e;b.x=b.x+c;b.y=b.y+d;a.x=a.x-c;a.y=a.y-d}}var Dc,bd,Ha,eb;this.autoClear?this.clear():n.setTransform(1,0,0,-1,o,q);f.info.render.vertices=0;f.info.render.faces=
  22499. 0;g=j.projectScene(a,l,this.sortElements);h=g.elements;k=g.lights;($a=k.length>0)&&m(k);Dc=0;for(bd=h.length;Dc<bd;Dc++){Ha=h[Dc];eb=Ha.material;eb=eb instanceof THREE.MeshFaceMaterial?Ha.faceMaterial:eb;if(!(eb===void 0||eb.visible===false)){xa.empty();if(Ha instanceof THREE.RenderableParticle){v=Ha;v.x=v.x*o;v.y=v.y*q;r(v,Ha,eb,a)}else if(Ha instanceof THREE.RenderableLine){v=Ha.v1;A=Ha.v2;v.positionScreen.x=v.positionScreen.x*o;v.positionScreen.y=v.positionScreen.y*q;A.positionScreen.x=A.positionScreen.x*
  22500. o;A.positionScreen.y=A.positionScreen.y*q;xa.addPoint(v.positionScreen.x,v.positionScreen.y);xa.addPoint(A.positionScreen.x,A.positionScreen.y);Wa.intersects(xa)&&s(v,A,Ha,eb,a)}else if(Ha instanceof THREE.RenderableFace3){v=Ha.v1;A=Ha.v2;J=Ha.v3;v.positionScreen.x=v.positionScreen.x*o;v.positionScreen.y=v.positionScreen.y*q;A.positionScreen.x=A.positionScreen.x*o;A.positionScreen.y=A.positionScreen.y*q;J.positionScreen.x=J.positionScreen.x*o;J.positionScreen.y=J.positionScreen.y*q;if(eb.overdraw){Nb(v.positionScreen,
  22501. A.positionScreen);Nb(A.positionScreen,J.positionScreen);Nb(J.positionScreen,v.positionScreen)}xa.add3Points(v.positionScreen.x,v.positionScreen.y,A.positionScreen.x,A.positionScreen.y,J.positionScreen.x,J.positionScreen.y);Wa.intersects(xa)&&t(v,A,J,0,1,2,Ha,eb,a)}else if(Ha instanceof THREE.RenderableFace4){v=Ha.v1;A=Ha.v2;J=Ha.v3;K=Ha.v4;v.positionScreen.x=v.positionScreen.x*o;v.positionScreen.y=v.positionScreen.y*q;A.positionScreen.x=A.positionScreen.x*o;A.positionScreen.y=A.positionScreen.y*q;
  22502. J.positionScreen.x=J.positionScreen.x*o;J.positionScreen.y=J.positionScreen.y*q;K.positionScreen.x=K.positionScreen.x*o;K.positionScreen.y=K.positionScreen.y*q;R.positionScreen.copy(A.positionScreen);P.positionScreen.copy(K.positionScreen);if(eb.overdraw){Nb(v.positionScreen,A.positionScreen);Nb(A.positionScreen,K.positionScreen);Nb(K.positionScreen,v.positionScreen);Nb(J.positionScreen,R.positionScreen);Nb(J.positionScreen,P.positionScreen)}xa.addPoint(v.positionScreen.x,v.positionScreen.y);xa.addPoint(A.positionScreen.x,
  22503. A.positionScreen.y);xa.addPoint(J.positionScreen.x,J.positionScreen.y);xa.addPoint(K.positionScreen.x,K.positionScreen.y);Wa.intersects(xa)&&u(v,A,J,K,R,P,Ha,eb,a)}Ba.addRectangle(xa)}}n.setTransform(1,0,0,1,0,0)}};
  22504. THREE.SVGRenderer=function(){function a(a,b,c,d){var e,f,g,h,k,j;e=0;for(f=a.length;e<f;e++){g=a[e];h=g.color;if(g instanceof THREE.DirectionalLight){k=g.matrixWorld.getPosition();j=c.dot(k);if(!(j<=0)){j=j*g.intensity;d.r=d.r+h.r*j;d.g=d.g+h.g*j;d.b=d.b+h.b*j}}else if(g instanceof THREE.PointLight){k=g.matrixWorld.getPosition();j=c.dot(v.sub(k,b).normalize());if(!(j<=0)){j=j*(g.distance==0?1:1-Math.min(b.distanceTo(k)/g.distance,1));if(j!=0){j=j*g.intensity;d.r=d.r+h.r*j;d.g=d.g+h.g*j;d.b=d.b+h.b*
  22505. j}}}}}function b(a){if(A[a]==null){A[a]=document.createElementNS("http://www.w3.org/2000/svg","path");E==0&&A[a].setAttribute("shape-rendering","crispEdges")}return A[a]}function c(a){a=(a+1)*0.5;return a<0?0:a>1?1:a}console.log("THREE.SVGRenderer",THREE.REVISION);var d=this,e,f,g,h=new THREE.Projector,k=document.createElementNS("http://www.w3.org/2000/svg","svg"),j,l,p,m,o,q,n,r,u=new THREE.Rectangle,t=new THREE.Rectangle,w=false,s=new THREE.Color,x=new THREE.Color,F=new THREE.Color,D=new THREE.Color,
  22506. z,v=new THREE.Vector3,A=[],J=[],K,R,P,E=1;this.domElement=k;this.sortElements=this.sortObjects=this.autoClear=true;this.info={render:{vertices:0,faces:0}};this.setQuality=function(a){switch(a){case "high":E=1;break;case "low":E=0}};this.setSize=function(a,b){j=a;l=b;p=j/2;m=l/2;k.setAttribute("viewBox",-p+" "+-m+" "+j+" "+l);k.setAttribute("width",j);k.setAttribute("height",l);u.set(-p,-m,p,m)};this.clear=function(){for(;k.childNodes.length>0;)k.removeChild(k.childNodes[0])};this.render=function(j,
  22507. l){var i,v,A,C;this.autoClear&&this.clear();d.info.render.vertices=0;d.info.render.faces=0;e=h.projectScene(j,l,this.sortElements);f=e.elements;g=e.lights;P=R=0;if(w=g.length>0){x.setRGB(0,0,0);F.setRGB(0,0,0);D.setRGB(0,0,0);i=0;for(v=g.length;i<v;i++){C=g[i];A=C.color;if(C instanceof THREE.AmbientLight){x.r=x.r+A.r;x.g=x.g+A.g;x.b=x.b+A.b}else if(C instanceof THREE.DirectionalLight){F.r=F.r+A.r;F.g=F.g+A.g;F.b=F.b+A.b}else if(C instanceof THREE.PointLight){D.r=D.r+A.r;D.g=D.g+A.g;D.b=D.b+A.b}}}i=
  22508. 0;for(v=f.length;i<v;i++){A=f[i];C=A.material;C=C instanceof THREE.MeshFaceMaterial?A.faceMaterial:C;if(!(C===void 0||C.visible===false)){t.empty();if(A instanceof THREE.RenderableParticle){o=A;o.x=o.x*p;o.y=o.y*-m}else if(A instanceof THREE.RenderableLine){o=A.v1;q=A.v2;o.positionScreen.x=o.positionScreen.x*p;o.positionScreen.y=o.positionScreen.y*-m;q.positionScreen.x=q.positionScreen.x*p;q.positionScreen.y=q.positionScreen.y*-m;t.addPoint(o.positionScreen.x,o.positionScreen.y);t.addPoint(q.positionScreen.x,
  22509. q.positionScreen.y);if(u.intersects(t)){A=o;var Y=q,I=P++;if(J[I]==null){J[I]=document.createElementNS("http://www.w3.org/2000/svg","line");E==0&&J[I].setAttribute("shape-rendering","crispEdges")}K=J[I];K.setAttribute("x1",A.positionScreen.x);K.setAttribute("y1",A.positionScreen.y);K.setAttribute("x2",Y.positionScreen.x);K.setAttribute("y2",Y.positionScreen.y);if(C instanceof THREE.LineBasicMaterial){K.setAttribute("style","fill: none; stroke: "+C.color.getContextStyle()+"; stroke-width: "+C.linewidth+
  22510. "; stroke-opacity: "+C.opacity+"; stroke-linecap: "+C.linecap+"; stroke-linejoin: "+C.linejoin);k.appendChild(K)}}}else if(A instanceof THREE.RenderableFace3){o=A.v1;q=A.v2;n=A.v3;o.positionScreen.x=o.positionScreen.x*p;o.positionScreen.y=o.positionScreen.y*-m;q.positionScreen.x=q.positionScreen.x*p;q.positionScreen.y=q.positionScreen.y*-m;n.positionScreen.x=n.positionScreen.x*p;n.positionScreen.y=n.positionScreen.y*-m;t.addPoint(o.positionScreen.x,o.positionScreen.y);t.addPoint(q.positionScreen.x,
  22511. q.positionScreen.y);t.addPoint(n.positionScreen.x,n.positionScreen.y);if(u.intersects(t)){var Y=o,I=q,ea=n;d.info.render.vertices=d.info.render.vertices+3;d.info.render.faces++;K=b(R++);K.setAttribute("d","M "+Y.positionScreen.x+" "+Y.positionScreen.y+" L "+I.positionScreen.x+" "+I.positionScreen.y+" L "+ea.positionScreen.x+","+ea.positionScreen.y+"z");if(C instanceof THREE.MeshBasicMaterial)s.copy(C.color);else if(C instanceof THREE.MeshLambertMaterial)if(w){s.r=x.r;s.g=x.g;s.b=x.b;a(g,A.centroidWorld,
  22512. A.normalWorld,s);s.r=Math.max(0,Math.min(C.color.r*s.r,1));s.g=Math.max(0,Math.min(C.color.g*s.g,1));s.b=Math.max(0,Math.min(C.color.b*s.b,1))}else s.copy(C.color);else if(C instanceof THREE.MeshDepthMaterial){z=1-C.__2near/(C.__farPlusNear-A.z*C.__farMinusNear);s.setRGB(z,z,z)}else C instanceof THREE.MeshNormalMaterial&&s.setRGB(c(A.normalWorld.x),c(A.normalWorld.y),c(A.normalWorld.z));C.wireframe?K.setAttribute("style","fill: none; stroke: "+s.getContextStyle()+"; stroke-width: "+C.wireframeLinewidth+
  22513. "; stroke-opacity: "+C.opacity+"; stroke-linecap: "+C.wireframeLinecap+"; stroke-linejoin: "+C.wireframeLinejoin):K.setAttribute("style","fill: "+s.getContextStyle()+"; fill-opacity: "+C.opacity);k.appendChild(K)}}else if(A instanceof THREE.RenderableFace4){o=A.v1;q=A.v2;n=A.v3;r=A.v4;o.positionScreen.x=o.positionScreen.x*p;o.positionScreen.y=o.positionScreen.y*-m;q.positionScreen.x=q.positionScreen.x*p;q.positionScreen.y=q.positionScreen.y*-m;n.positionScreen.x=n.positionScreen.x*p;n.positionScreen.y=
  22514. n.positionScreen.y*-m;r.positionScreen.x=r.positionScreen.x*p;r.positionScreen.y=r.positionScreen.y*-m;t.addPoint(o.positionScreen.x,o.positionScreen.y);t.addPoint(q.positionScreen.x,q.positionScreen.y);t.addPoint(n.positionScreen.x,n.positionScreen.y);t.addPoint(r.positionScreen.x,r.positionScreen.y);if(u.intersects(t)){var Y=o,I=q,ea=n,fa=r;d.info.render.vertices=d.info.render.vertices+4;d.info.render.faces++;K=b(R++);K.setAttribute("d","M "+Y.positionScreen.x+" "+Y.positionScreen.y+" L "+I.positionScreen.x+
  22515. " "+I.positionScreen.y+" L "+ea.positionScreen.x+","+ea.positionScreen.y+" L "+fa.positionScreen.x+","+fa.positionScreen.y+"z");if(C instanceof THREE.MeshBasicMaterial)s.copy(C.color);else if(C instanceof THREE.MeshLambertMaterial)if(w){s.r=x.r;s.g=x.g;s.b=x.b;a(g,A.centroidWorld,A.normalWorld,s);s.r=Math.max(0,Math.min(C.color.r*s.r,1));s.g=Math.max(0,Math.min(C.color.g*s.g,1));s.b=Math.max(0,Math.min(C.color.b*s.b,1))}else s.copy(C.color);else if(C instanceof THREE.MeshDepthMaterial){z=1-C.__2near/
  22516. (C.__farPlusNear-A.z*C.__farMinusNear);s.setRGB(z,z,z)}else C instanceof THREE.MeshNormalMaterial&&s.setRGB(c(A.normalWorld.x),c(A.normalWorld.y),c(A.normalWorld.z));C.wireframe?K.setAttribute("style","fill: none; stroke: "+s.getContextStyle()+"; stroke-width: "+C.wireframeLinewidth+"; stroke-opacity: "+C.opacity+"; stroke-linecap: "+C.wireframeLinecap+"; stroke-linejoin: "+C.wireframeLinejoin):K.setAttribute("style","fill: "+s.getContextStyle()+"; fill-opacity: "+C.opacity);k.appendChild(K)}}}}}};
  22517. THREE.ShaderChunk={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );\n#endif",
  22518. envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube envMap;\nuniform float flipEnvMap;\nuniform int combine;\n#endif",envmap_fragment:"#ifdef USE_ENVMAP\n#ifdef DOUBLE_SIDED\nfloat flipNormal = ( -1.0 + 2.0 * float( gl_FrontFacing ) );\nvec4 cubeColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * vReflect.x, vReflect.yz ) );\n#else\nvec4 cubeColor = textureCube( envMap, vec3( flipEnvMap * vReflect.x, vReflect.yz ) );\n#endif\n#ifdef GAMMA_INPUT\ncubeColor.xyz *= cubeColor.xyz;\n#endif\nif ( combine == 1 ) {\ngl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, reflectivity );\n} else {\ngl_FragColor.xyz = gl_FragColor.xyz * cubeColor.xyz;\n}\n#endif",
  22519. envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refractionRatio;\nuniform bool useRefract;\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = mat3( objectMatrix[ 0 ].xyz, objectMatrix[ 1 ].xyz, objectMatrix[ 2 ].xyz ) * normal;\nif ( useRefract ) {\nvReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refractionRatio );\n} else {\nvReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );\n}\n#endif",
  22520. map_particle_pars_fragment:"#ifdef USE_MAP\nuniform sampler2D map;\n#endif",map_particle_fragment:"#ifdef USE_MAP\ngl_FragColor = gl_FragColor * texture2D( map, gl_PointCoord );\n#endif",map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform vec4 offsetRepeat;\n#endif",map_pars_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv * offsetRepeat.zw + offsetRepeat.xy;\n#endif",map_fragment:"#ifdef USE_MAP\n#ifdef GAMMA_INPUT\nvec4 texelColor = texture2D( map, vUv );\ntexelColor.xyz *= texelColor.xyz;\ngl_FragColor = gl_FragColor * texelColor;\n#else\ngl_FragColor = gl_FragColor * texture2D( map, vUv );\n#endif\n#endif",
  22521. lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\nvarying vec2 vUv2;\nuniform sampler2D lightMap;\n#endif",lightmap_pars_vertex:"#ifdef USE_LIGHTMAP\nvarying vec2 vUv2;\n#endif",lightmap_fragment:"#ifdef USE_LIGHTMAP\ngl_FragColor = gl_FragColor * texture2D( lightMap, vUv2 );\n#endif",lightmap_vertex:"#ifdef USE_LIGHTMAP\nvUv2 = uv2;\n#endif",lights_lambert_pars_vertex:"uniform vec3 ambient;\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\nuniform float pointLightDistance[ MAX_POINT_LIGHTS ];\n#endif\n#if MAX_SPOT_LIGHTS > 0\nuniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];\nuniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];\nuniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];\nuniform float spotLightDistance[ MAX_SPOT_LIGHTS ];\nuniform float spotLightAngle[ MAX_SPOT_LIGHTS ];\nuniform float spotLightExponent[ MAX_SPOT_LIGHTS ];\n#endif\n#ifdef WRAP_AROUND\nuniform vec3 wrapRGB;\n#endif",
  22522. lights_lambert_vertex:"vLightFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\nvLightBack = vec3( 0.0 );\n#endif\ntransformedNormal = normalize( transformedNormal );\n#if MAX_DIR_LIGHTS > 0\nfor( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nfloat dotProduct = dot( transformedNormal, dirVector );\nvec3 directionalLightWeighting = vec3( max( dotProduct, 0.0 ) );\n#ifdef DOUBLE_SIDED\nvec3 directionalLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );\n#ifdef WRAP_AROUND\nvec3 directionalLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );\n#endif\n#endif\n#ifdef WRAP_AROUND\nvec3 directionalLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );\ndirectionalLightWeighting = mix( directionalLightWeighting, directionalLightWeightingHalf, wrapRGB );\n#ifdef DOUBLE_SIDED\ndirectionalLightWeightingBack = mix( directionalLightWeightingBack, directionalLightWeightingHalfBack, wrapRGB );\n#endif\n#endif\nvLightFront += directionalLightColor[ i ] * directionalLightWeighting;\n#ifdef DOUBLE_SIDED\nvLightBack += directionalLightColor[ i ] * directionalLightWeightingBack;\n#endif\n}\n#endif\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 lVector = lPosition.xyz - mvPosition.xyz;\nfloat lDistance = 1.0;\nif ( pointLightDistance[ i ] > 0.0 )\nlDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );\nlVector = normalize( lVector );\nfloat dotProduct = dot( transformedNormal, lVector );\nvec3 pointLightWeighting = vec3( max( dotProduct, 0.0 ) );\n#ifdef DOUBLE_SIDED\nvec3 pointLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );\n#ifdef WRAP_AROUND\nvec3 pointLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );\n#endif\n#endif\n#ifdef WRAP_AROUND\nvec3 pointLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );\npointLightWeighting = mix( pointLightWeighting, pointLightWeightingHalf, wrapRGB );\n#ifdef DOUBLE_SIDED\npointLightWeightingBack = mix( pointLightWeightingBack, pointLightWeightingHalfBack, wrapRGB );\n#endif\n#endif\nvLightFront += pointLightColor[ i ] * pointLightWeighting * lDistance;\n#ifdef DOUBLE_SIDED\nvLightBack += pointLightColor[ i ] * pointLightWeightingBack * lDistance;\n#endif\n}\n#endif\n#if MAX_SPOT_LIGHTS > 0\nfor( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\nvec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );\nvec3 lVector = lPosition.xyz - mvPosition.xyz;\nlVector = normalize( lVector );\nfloat spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - mPosition.xyz ) );\nif ( spotEffect > spotLightAngle[ i ] ) {\nspotEffect = pow( spotEffect, spotLightExponent[ i ] );\nfloat lDistance = 1.0;\nif ( spotLightDistance[ i ] > 0.0 )\nlDistance = 1.0 - min( ( length( lVector ) / spotLightDistance[ i ] ), 1.0 );\nfloat dotProduct = dot( transformedNormal, lVector );\nvec3 spotLightWeighting = vec3( max( dotProduct, 0.0 ) );\n#ifdef DOUBLE_SIDED\nvec3 spotLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );\n#ifdef WRAP_AROUND\nvec3 spotLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );\n#endif\n#endif\n#ifdef WRAP_AROUND\nvec3 spotLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );\nspotLightWeighting = mix( spotLightWeighting, spotLightWeightingHalf, wrapRGB );\n#ifdef DOUBLE_SIDED\nspotLightWeightingBack = mix( spotLightWeightingBack, spotLightWeightingHalfBack, wrapRGB );\n#endif\n#endif\nvLightFront += spotLightColor[ i ] * spotLightWeighting * lDistance * spotEffect;\n#ifdef DOUBLE_SIDED\nvLightBack += spotLightColor[ i ] * spotLightWeightingBack * lDistance * spotEffect;\n#endif\n}\n}\n#endif\nvLightFront = vLightFront * diffuse + ambient * ambientLightColor + emissive;\n#ifdef DOUBLE_SIDED\nvLightBack = vLightBack * diffuse + ambient * ambientLightColor + emissive;\n#endif",
  22523. lights_phong_pars_vertex:"#ifndef PHONG_PER_PIXEL\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\nuniform float pointLightDistance[ MAX_POINT_LIGHTS ];\nvarying vec4 vPointLight[ MAX_POINT_LIGHTS ];\n#endif\n#if MAX_SPOT_LIGHTS > 0\nuniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];\nuniform float spotLightDistance[ MAX_SPOT_LIGHTS ];\nvarying vec4 vSpotLight[ MAX_SPOT_LIGHTS ];\n#endif\n#endif\n#if MAX_SPOT_LIGHTS > 0\nvarying vec3 vWorldPosition;\n#endif",lights_phong_vertex:"#ifndef PHONG_PER_PIXEL\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 lVector = lPosition.xyz - mvPosition.xyz;\nfloat lDistance = 1.0;\nif ( pointLightDistance[ i ] > 0.0 )\nlDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );\nvPointLight[ i ] = vec4( lVector, lDistance );\n}\n#endif\n#if MAX_SPOT_LIGHTS > 0\nfor( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\nvec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );\nvec3 lVector = lPosition.xyz - mvPosition.xyz;\nfloat lDistance = 1.0;\nif ( spotLightDistance[ i ] > 0.0 )\nlDistance = 1.0 - min( ( length( lVector ) / spotLightDistance[ i ] ), 1.0 );\nvSpotLight[ i ] = vec4( lVector, lDistance );\n}\n#endif\n#endif\n#if MAX_SPOT_LIGHTS > 0\nvWorldPosition = mPosition.xyz;\n#endif",
  22524. lights_phong_pars_fragment:"uniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\n#ifdef PHONG_PER_PIXEL\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\nuniform float pointLightDistance[ MAX_POINT_LIGHTS ];\n#else\nvarying vec4 vPointLight[ MAX_POINT_LIGHTS ];\n#endif\n#endif\n#if MAX_SPOT_LIGHTS > 0\nuniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];\nuniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];\nuniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];\nuniform float spotLightAngle[ MAX_SPOT_LIGHTS ];\nuniform float spotLightExponent[ MAX_SPOT_LIGHTS ];\n#ifdef PHONG_PER_PIXEL\nuniform float spotLightDistance[ MAX_SPOT_LIGHTS ];\n#else\nvarying vec4 vSpotLight[ MAX_SPOT_LIGHTS ];\n#endif\nvarying vec3 vWorldPosition;\n#endif\n#ifdef WRAP_AROUND\nuniform vec3 wrapRGB;\n#endif\nvarying vec3 vViewPosition;\nvarying vec3 vNormal;",
  22525. lights_phong_fragment:"vec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );\n#ifdef DOUBLE_SIDED\nnormal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );\n#endif\n#if MAX_POINT_LIGHTS > 0\nvec3 pointDiffuse = vec3( 0.0 );\nvec3 pointSpecular = vec3( 0.0 );\nfor ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\n#ifdef PHONG_PER_PIXEL\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 lVector = lPosition.xyz + vViewPosition.xyz;\nfloat lDistance = 1.0;\nif ( pointLightDistance[ i ] > 0.0 )\nlDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );\nlVector = normalize( lVector );\n#else\nvec3 lVector = normalize( vPointLight[ i ].xyz );\nfloat lDistance = vPointLight[ i ].w;\n#endif\nfloat dotProduct = dot( normal, lVector );\n#ifdef WRAP_AROUND\nfloat pointDiffuseWeightFull = max( dotProduct, 0.0 );\nfloat pointDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );\nvec3 pointDiffuseWeight = mix( vec3 ( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );\n#else\nfloat pointDiffuseWeight = max( dotProduct, 0.0 );\n#endif\npointDiffuse += diffuse * pointLightColor[ i ] * pointDiffuseWeight * lDistance;\nvec3 pointHalfVector = normalize( lVector + viewPosition );\nfloat pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );\nfloat pointSpecularWeight = max( pow( pointDotNormalHalf, shininess ), 0.0 );\n#ifdef PHYSICALLY_BASED_SHADING\nfloat specularNormalization = ( shininess + 2.0001 ) / 8.0;\nvec3 schlick = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( lVector, pointHalfVector ), 5.0 );\npointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * lDistance * specularNormalization;\n#else\npointSpecular += specular * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * lDistance;\n#endif\n}\n#endif\n#if MAX_SPOT_LIGHTS > 0\nvec3 spotDiffuse = vec3( 0.0 );\nvec3 spotSpecular = vec3( 0.0 );\nfor ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\n#ifdef PHONG_PER_PIXEL\nvec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );\nvec3 lVector = lPosition.xyz + vViewPosition.xyz;\nfloat lDistance = 1.0;\nif ( spotLightDistance[ i ] > 0.0 )\nlDistance = 1.0 - min( ( length( lVector ) / spotLightDistance[ i ] ), 1.0 );\nlVector = normalize( lVector );\n#else\nvec3 lVector = normalize( vSpotLight[ i ].xyz );\nfloat lDistance = vSpotLight[ i ].w;\n#endif\nfloat spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - vWorldPosition ) );\nif ( spotEffect > spotLightAngle[ i ] ) {\nspotEffect = pow( spotEffect, spotLightExponent[ i ] );\nfloat dotProduct = dot( normal, lVector );\n#ifdef WRAP_AROUND\nfloat spotDiffuseWeightFull = max( dotProduct, 0.0 );\nfloat spotDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );\nvec3 spotDiffuseWeight = mix( vec3 ( spotDiffuseWeightFull ), vec3( spotDiffuseWeightHalf ), wrapRGB );\n#else\nfloat spotDiffuseWeight = max( dotProduct, 0.0 );\n#endif\nspotDiffuse += diffuse * spotLightColor[ i ] * spotDiffuseWeight * lDistance * spotEffect;\nvec3 spotHalfVector = normalize( lVector + viewPosition );\nfloat spotDotNormalHalf = max( dot( normal, spotHalfVector ), 0.0 );\nfloat spotSpecularWeight = max( pow( spotDotNormalHalf, shininess ), 0.0 );\n#ifdef PHYSICALLY_BASED_SHADING\nfloat specularNormalization = ( shininess + 2.0001 ) / 8.0;\nvec3 schlick = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( lVector, spotHalfVector ), 5.0 );\nspotSpecular += schlick * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * lDistance * specularNormalization * spotEffect;\n#else\nspotSpecular += specular * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * lDistance * spotEffect;\n#endif\n}\n}\n#endif\n#if MAX_DIR_LIGHTS > 0\nvec3 dirDiffuse = vec3( 0.0 );\nvec3 dirSpecular = vec3( 0.0 );\nfor( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nfloat dotProduct = dot( normal, dirVector );\n#ifdef WRAP_AROUND\nfloat dirDiffuseWeightFull = max( dotProduct, 0.0 );\nfloat dirDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );\nvec3 dirDiffuseWeight = mix( vec3( dirDiffuseWeightFull ), vec3( dirDiffuseWeightHalf ), wrapRGB );\n#else\nfloat dirDiffuseWeight = max( dotProduct, 0.0 );\n#endif\ndirDiffuse += diffuse * directionalLightColor[ i ] * dirDiffuseWeight;\nvec3 dirHalfVector = normalize( dirVector + viewPosition );\nfloat dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );\nfloat dirSpecularWeight = max( pow( dirDotNormalHalf, shininess ), 0.0 );\n#ifdef PHYSICALLY_BASED_SHADING\nfloat specularNormalization = ( shininess + 2.0001 ) / 8.0;\nvec3 schlick = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( dirVector, dirHalfVector ), 5.0 );\ndirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;\n#else\ndirSpecular += specular * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight;\n#endif\n}\n#endif\nvec3 totalDiffuse = vec3( 0.0 );\nvec3 totalSpecular = vec3( 0.0 );\n#if MAX_DIR_LIGHTS > 0\ntotalDiffuse += dirDiffuse;\ntotalSpecular += dirSpecular;\n#endif\n#if MAX_POINT_LIGHTS > 0\ntotalDiffuse += pointDiffuse;\ntotalSpecular += pointSpecular;\n#endif\n#if MAX_SPOT_LIGHTS > 0\ntotalDiffuse += spotDiffuse;\ntotalSpecular += spotSpecular;\n#endif\n#ifdef METAL\ngl_FragColor.xyz = gl_FragColor.xyz * ( emissive + totalDiffuse + ambientLightColor * ambient + totalSpecular );\n#else\ngl_FragColor.xyz = gl_FragColor.xyz * ( emissive + totalDiffuse + ambientLightColor * ambient ) + totalSpecular;\n#endif",
  22526. color_pars_fragment:"#ifdef USE_COLOR\nvarying vec3 vColor;\n#endif",color_fragment:"#ifdef USE_COLOR\ngl_FragColor = gl_FragColor * vec4( vColor, opacity );\n#endif",color_pars_vertex:"#ifdef USE_COLOR\nvarying vec3 vColor;\n#endif",color_vertex:"#ifdef USE_COLOR\n#ifdef GAMMA_INPUT\nvColor = color * color;\n#else\nvColor = color;\n#endif\n#endif",skinning_pars_vertex:"#ifdef USE_SKINNING\nuniform mat4 boneGlobalMatrices[ MAX_BONES ];\n#endif",skinning_vertex:"#ifdef USE_SKINNING\ngl_Position = ( boneGlobalMatrices[ int( skinIndex.x ) ] * skinVertexA ) * skinWeight.x;\ngl_Position += ( boneGlobalMatrices[ int( skinIndex.y ) ] * skinVertexB ) * skinWeight.y;\ngl_Position = projectionMatrix * modelViewMatrix * gl_Position;\n#endif",
  22527. morphtarget_pars_vertex:"#ifdef USE_MORPHTARGETS\n#ifndef USE_MORPHNORMALS\nuniform float morphTargetInfluences[ 8 ];\n#else\nuniform float morphTargetInfluences[ 4 ];\n#endif\n#endif",morphtarget_vertex:"#ifdef USE_MORPHTARGETS\nvec3 morphed = vec3( 0.0 );\nmorphed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\nmorphed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\nmorphed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\nmorphed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\n#ifndef USE_MORPHNORMALS\nmorphed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\nmorphed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\nmorphed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\nmorphed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\n#endif\nmorphed += position;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( morphed, 1.0 );\n#endif",
  22528. default_vertex:"#ifndef USE_MORPHTARGETS\n#ifndef USE_SKINNING\ngl_Position = projectionMatrix * mvPosition;\n#endif\n#endif",morphnormal_vertex:"#ifdef USE_MORPHNORMALS\nvec3 morphedNormal = vec3( 0.0 );\nmorphedNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];\nmorphedNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];\nmorphedNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];\nmorphedNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];\nmorphedNormal += normal;\nvec3 transformedNormal = normalMatrix * morphedNormal;\n#else\nvec3 transformedNormal = normalMatrix * normal;\n#endif",
  22529. shadowmap_pars_fragment:"#ifdef USE_SHADOWMAP\nuniform sampler2D shadowMap[ MAX_SHADOWS ];\nuniform vec2 shadowMapSize[ MAX_SHADOWS ];\nuniform float shadowDarkness[ MAX_SHADOWS ];\nuniform float shadowBias[ MAX_SHADOWS ];\nvarying vec4 vShadowCoord[ MAX_SHADOWS ];\nfloat unpackDepth( const in vec4 rgba_depth ) {\nconst vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\nfloat depth = dot( rgba_depth, bit_shift );\nreturn depth;\n}\n#endif",shadowmap_fragment:"#ifdef USE_SHADOWMAP\n#ifdef SHADOWMAP_DEBUG\nvec3 frustumColors[3];\nfrustumColors[0] = vec3( 1.0, 0.5, 0.0 );\nfrustumColors[1] = vec3( 0.0, 1.0, 0.8 );\nfrustumColors[2] = vec3( 0.0, 0.5, 1.0 );\n#endif\n#ifdef SHADOWMAP_CASCADE\nint inFrustumCount = 0;\n#endif\nfloat fDepth;\nvec3 shadowColor = vec3( 1.0 );\nfor( int i = 0; i < MAX_SHADOWS; i ++ ) {\nvec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;\nbvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\nbool inFrustum = all( inFrustumVec );\n#ifdef SHADOWMAP_CASCADE\ninFrustumCount += int( inFrustum );\nbvec3 frustumTestVec = bvec3( inFrustum, inFrustumCount == 1, shadowCoord.z <= 1.0 );\n#else\nbvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n#endif\nbool frustumTest = all( frustumTestVec );\nif ( frustumTest ) {\nshadowCoord.z += shadowBias[ i ];\n#ifdef SHADOWMAP_SOFT\nfloat shadow = 0.0;\nconst float shadowDelta = 1.0 / 9.0;\nfloat xPixelOffset = 1.0 / shadowMapSize[ i ].x;\nfloat yPixelOffset = 1.0 / shadowMapSize[ i ].y;\nfloat dx0 = -1.25 * xPixelOffset;\nfloat dy0 = -1.25 * yPixelOffset;\nfloat dx1 = 1.25 * xPixelOffset;\nfloat dy1 = 1.25 * yPixelOffset;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\nif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\nshadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );\n#else\nvec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );\nfloat fDepth = unpackDepth( rgbaDepth );\nif ( fDepth < shadowCoord.z )\nshadowColor = shadowColor * vec3( 1.0 - shadowDarkness[ i ] );\n#endif\n}\n#ifdef SHADOWMAP_DEBUG\n#ifdef SHADOWMAP_CASCADE\nif ( inFrustum && inFrustumCount == 1 ) gl_FragColor.xyz *= frustumColors[ i ];\n#else\nif ( inFrustum ) gl_FragColor.xyz *= frustumColors[ i ];\n#endif\n#endif\n}\n#ifdef GAMMA_OUTPUT\nshadowColor *= shadowColor;\n#endif\ngl_FragColor.xyz = gl_FragColor.xyz * shadowColor;\n#endif",
  22530. shadowmap_pars_vertex:"#ifdef USE_SHADOWMAP\nvarying vec4 vShadowCoord[ MAX_SHADOWS ];\nuniform mat4 shadowMatrix[ MAX_SHADOWS ];\n#endif",shadowmap_vertex:"#ifdef USE_SHADOWMAP\nfor( int i = 0; i < MAX_SHADOWS; i ++ ) {\n#ifdef USE_MORPHTARGETS\nvShadowCoord[ i ] = shadowMatrix[ i ] * objectMatrix * vec4( morphed, 1.0 );\n#else\nvShadowCoord[ i ] = shadowMatrix[ i ] * objectMatrix * vec4( position, 1.0 );\n#endif\n}\n#endif",alphatest_fragment:"#ifdef ALPHATEST\nif ( gl_FragColor.a < ALPHATEST ) discard;\n#endif",
  22531. linear_to_gamma_fragment:"#ifdef GAMMA_OUTPUT\ngl_FragColor.xyz = sqrt( gl_FragColor.xyz );\n#endif"};
  22532. THREE.UniformsUtils={merge:function(a){var b,c,d,e={};for(b=0;b<a.length;b++){d=this.clone(a[b]);for(c in d)e[c]=d[c]}return e},clone:function(a){var b,c,d,e={};for(b in a){e[b]={};for(c in a[b]){d=a[b][c];e[b][c]=d instanceof THREE.Color||d instanceof THREE.Vector2||d instanceof THREE.Vector3||d instanceof THREE.Vector4||d instanceof THREE.Matrix4||d instanceof THREE.Texture?d.clone():d instanceof Array?d.slice():d}}return e}};
  22533. THREE.UniformsLib={common:{diffuse:{type:"c",value:new THREE.Color(15658734)},opacity:{type:"f",value:1},map:{type:"t",value:0,texture:null},offsetRepeat:{type:"v4",value:new THREE.Vector4(0,0,1,1)},lightMap:{type:"t",value:2,texture:null},envMap:{type:"t",value:1,texture:null},flipEnvMap:{type:"f",value:-1},useRefract:{type:"i",value:0},reflectivity:{type:"f",value:1},refractionRatio:{type:"f",value:0.98},combine:{type:"i",value:0},morphTargetInfluences:{type:"f",value:0}},fog:{fogDensity:{type:"f",
  22534. value:2.5E-4},fogNear:{type:"f",value:1},fogFar:{type:"f",value:2E3},fogColor:{type:"c",value:new THREE.Color(16777215)}},lights:{ambientLightColor:{type:"fv",value:[]},directionalLightDirection:{type:"fv",value:[]},directionalLightColor:{type:"fv",value:[]},pointLightColor:{type:"fv",value:[]},pointLightPosition:{type:"fv",value:[]},pointLightDistance:{type:"fv1",value:[]},spotLightColor:{type:"fv",value:[]},spotLightPosition:{type:"fv",value:[]},spotLightDirection:{type:"fv",value:[]},spotLightDistance:{type:"fv1",
  22535. value:[]},spotLightAngle:{type:"fv1",value:[]},spotLightExponent:{type:"fv1",value:[]}},particle:{psColor:{type:"c",value:new THREE.Color(15658734)},opacity:{type:"f",value:1},size:{type:"f",value:1},scale:{type:"f",value:1},map:{type:"t",value:0,texture:null},fogDensity:{type:"f",value:2.5E-4},fogNear:{type:"f",value:1},fogFar:{type:"f",value:2E3},fogColor:{type:"c",value:new THREE.Color(16777215)}},shadowmap:{shadowMap:{type:"tv",value:6,texture:[]},shadowMapSize:{type:"v2v",value:[]},shadowBias:{type:"fv1",
  22536. value:[]},shadowDarkness:{type:"fv1",value:[]},shadowMatrix:{type:"m4v",value:[]}}};
  22537. THREE.ShaderLib={depth:{uniforms:{mNear:{type:"f",value:1},mFar:{type:"f",value:2E3},opacity:{type:"f",value:1}},vertexShader:"void main() {\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"uniform float mNear;\nuniform float mFar;\nuniform float opacity;\nvoid main() {\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\nfloat color = 1.0 - smoothstep( mNear, mFar, depth );\ngl_FragColor = vec4( vec3( color ), opacity );\n}"},normal:{uniforms:{opacity:{type:"f",
  22538. value:1}},vertexShader:"varying vec3 vNormal;\nvoid main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalMatrix * normal;\ngl_Position = projectionMatrix * mvPosition;\n}",fragmentShader:"uniform float opacity;\nvarying vec3 vNormal;\nvoid main() {\ngl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );\n}"},basic:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.common,THREE.UniformsLib.fog,THREE.UniformsLib.shadowmap]),vertexShader:[THREE.ShaderChunk.map_pars_vertex,
  22539. THREE.ShaderChunk.lightmap_pars_vertex,THREE.ShaderChunk.envmap_pars_vertex,THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.skinning_pars_vertex,THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.shadowmap_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.ShaderChunk.map_vertex,THREE.ShaderChunk.lightmap_vertex,THREE.ShaderChunk.envmap_vertex,THREE.ShaderChunk.color_vertex,THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.morphtarget_vertex,
  22540. THREE.ShaderChunk.default_vertex,THREE.ShaderChunk.shadowmap_vertex,"}"].join("\n"),fragmentShader:["uniform vec3 diffuse;\nuniform float opacity;",THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_pars_fragment,THREE.ShaderChunk.lightmap_pars_fragment,THREE.ShaderChunk.envmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.shadowmap_pars_fragment,"void main() {\ngl_FragColor = vec4( diffuse, opacity );",THREE.ShaderChunk.map_fragment,THREE.ShaderChunk.alphatest_fragment,
  22541. THREE.ShaderChunk.lightmap_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.envmap_fragment,THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.linear_to_gamma_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n")},lambert:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.common,THREE.UniformsLib.fog,THREE.UniformsLib.lights,THREE.UniformsLib.shadowmap,{ambient:{type:"c",value:new THREE.Color(16777215)},emissive:{type:"c",value:new THREE.Color(0)},wrapRGB:{type:"v3",value:new THREE.Vector3(1,
  22542. 1,1)}}]),vertexShader:["varying vec3 vLightFront;\n#ifdef DOUBLE_SIDED\nvarying vec3 vLightBack;\n#endif",THREE.ShaderChunk.map_pars_vertex,THREE.ShaderChunk.lightmap_pars_vertex,THREE.ShaderChunk.envmap_pars_vertex,THREE.ShaderChunk.lights_lambert_pars_vertex,THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.skinning_pars_vertex,THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.shadowmap_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.ShaderChunk.map_vertex,
  22543. THREE.ShaderChunk.lightmap_vertex,THREE.ShaderChunk.envmap_vertex,THREE.ShaderChunk.color_vertex,THREE.ShaderChunk.morphnormal_vertex,"#ifndef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\n#endif",THREE.ShaderChunk.lights_lambert_vertex,THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.default_vertex,THREE.ShaderChunk.shadowmap_vertex,"}"].join("\n"),fragmentShader:["uniform float opacity;\nvarying vec3 vLightFront;\n#ifdef DOUBLE_SIDED\nvarying vec3 vLightBack;\n#endif",
  22544. THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_pars_fragment,THREE.ShaderChunk.lightmap_pars_fragment,THREE.ShaderChunk.envmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.shadowmap_pars_fragment,"void main() {\ngl_FragColor = vec4( vec3 ( 1.0 ), opacity );",THREE.ShaderChunk.map_fragment,THREE.ShaderChunk.alphatest_fragment,"#ifdef DOUBLE_SIDED\nif ( gl_FrontFacing )\ngl_FragColor.xyz *= vLightFront;\nelse\ngl_FragColor.xyz *= vLightBack;\n#else\ngl_FragColor.xyz *= vLightFront;\n#endif",
  22545. THREE.ShaderChunk.lightmap_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.envmap_fragment,THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.linear_to_gamma_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n")},phong:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.common,THREE.UniformsLib.fog,THREE.UniformsLib.lights,THREE.UniformsLib.shadowmap,{ambient:{type:"c",value:new THREE.Color(16777215)},emissive:{type:"c",value:new THREE.Color(0)},specular:{type:"c",value:new THREE.Color(1118481)},
  22546. shininess:{type:"f",value:30},wrapRGB:{type:"v3",value:new THREE.Vector3(1,1,1)}}]),vertexShader:["varying vec3 vViewPosition;\nvarying vec3 vNormal;",THREE.ShaderChunk.map_pars_vertex,THREE.ShaderChunk.lightmap_pars_vertex,THREE.ShaderChunk.envmap_pars_vertex,THREE.ShaderChunk.lights_phong_pars_vertex,THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.skinning_pars_vertex,THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.shadowmap_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  22547. THREE.ShaderChunk.map_vertex,THREE.ShaderChunk.lightmap_vertex,THREE.ShaderChunk.envmap_vertex,THREE.ShaderChunk.color_vertex,"#ifndef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\n#endif\nvViewPosition = -mvPosition.xyz;",THREE.ShaderChunk.morphnormal_vertex,"vNormal = transformedNormal;",THREE.ShaderChunk.lights_phong_vertex,THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.default_vertex,THREE.ShaderChunk.shadowmap_vertex,"}"].join("\n"),
  22548. fragmentShader:["uniform vec3 diffuse;\nuniform float opacity;\nuniform vec3 ambient;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;",THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_pars_fragment,THREE.ShaderChunk.lightmap_pars_fragment,THREE.ShaderChunk.envmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.lights_phong_pars_fragment,THREE.ShaderChunk.shadowmap_pars_fragment,"void main() {\ngl_FragColor = vec4( vec3 ( 1.0 ), opacity );",
  22549. THREE.ShaderChunk.map_fragment,THREE.ShaderChunk.alphatest_fragment,THREE.ShaderChunk.lights_phong_fragment,THREE.ShaderChunk.lightmap_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.envmap_fragment,THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.linear_to_gamma_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n")},particle_basic:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.particle,THREE.UniformsLib.shadowmap]),vertexShader:["uniform float size;\nuniform float scale;",
  22550. THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.shadowmap_pars_vertex,"void main() {",THREE.ShaderChunk.color_vertex,"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n#ifdef USE_SIZEATTENUATION\ngl_PointSize = size * ( scale / length( mvPosition.xyz ) );\n#else\ngl_PointSize = size;\n#endif\ngl_Position = projectionMatrix * mvPosition;",THREE.ShaderChunk.shadowmap_vertex,"}"].join("\n"),fragmentShader:["uniform vec3 psColor;\nuniform float opacity;",THREE.ShaderChunk.color_pars_fragment,
  22551. THREE.ShaderChunk.map_particle_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.shadowmap_pars_fragment,"void main() {\ngl_FragColor = vec4( psColor, opacity );",THREE.ShaderChunk.map_particle_fragment,THREE.ShaderChunk.alphatest_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n")},depthRGBA:{uniforms:{},vertexShader:[THREE.ShaderChunk.morphtarget_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  22552. THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.default_vertex,"}"].join("\n"),fragmentShader:"vec4 pack_depth( const in float depth ) {\nconst vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );\nconst vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );\nvec4 res = fract( depth * bit_shift );\nres -= res.xxyz * bit_mask;\nreturn res;\n}\nvoid main() {\ngl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );\n}"}};
  22553. THREE.WebGLRenderer=function(a){function b(a,b){var c=a.vertices.length,d=b.material;if(d.attributes){if(a.__webglCustomAttributesList===void 0)a.__webglCustomAttributesList=[];for(var e in d.attributes){var f=d.attributes[e];if(!f.__webglInitialized||f.createUniqueBuffers){f.__webglInitialized=true;var g=1;f.type==="v2"?g=2:f.type==="v3"?g=3:f.type==="v4"?g=4:f.type==="c"&&(g=3);f.size=g;f.array=new Float32Array(c*g);f.buffer=i.createBuffer();f.buffer.belongsToAttribute=e;f.needsUpdate=true}a.__webglCustomAttributesList.push(f)}}}
  22554. function c(a,b){if(a.material&&!(a.material instanceof THREE.MeshFaceMaterial))return a.material;if(b.materialIndex>=0)return a.geometry.materials[b.materialIndex]}function d(a){return a instanceof THREE.MeshBasicMaterial&&!a.envMap||a instanceof THREE.MeshDepthMaterial?false:a&&a.shading!==void 0&&a.shading===THREE.SmoothShading?THREE.SmoothShading:THREE.FlatShading}function e(a){return a.map||a.lightMap||a instanceof THREE.ShaderMaterial?true:false}function f(a,b,c){var d,e,f,g,h=a.vertices;g=h.length;
  22555. var k=a.colors,j=k.length,l=a.__vertexArray,m=a.__colorArray,n=a.__sortArray,o=a.verticesNeedUpdate,p=a.colorsNeedUpdate,q=a.__webglCustomAttributesList;if(c.sortParticles){xa.copy(Ba);xa.multiplySelf(c.matrixWorld);for(d=0;d<g;d++){e=h[d];$a.copy(e);xa.multiplyVector3($a);n[d]=[$a.z,d]}n.sort(function(a,b){return b[0]-a[0]});for(d=0;d<g;d++){e=h[n[d][1]];f=d*3;l[f]=e.x;l[f+1]=e.y;l[f+2]=e.z}for(d=0;d<j;d++){f=d*3;e=k[n[d][1]];m[f]=e.r;m[f+1]=e.g;m[f+2]=e.b}if(q){k=0;for(j=q.length;k<j;k++){h=q[k];
  22556. if(h.boundTo===void 0||h.boundTo==="vertices"){f=0;e=h.value.length;if(h.size===1)for(d=0;d<e;d++){g=n[d][1];h.array[d]=h.value[g]}else if(h.size===2)for(d=0;d<e;d++){g=n[d][1];g=h.value[g];h.array[f]=g.x;h.array[f+1]=g.y;f=f+2}else if(h.size===3)if(h.type==="c")for(d=0;d<e;d++){g=n[d][1];g=h.value[g];h.array[f]=g.r;h.array[f+1]=g.g;h.array[f+2]=g.b;f=f+3}else for(d=0;d<e;d++){g=n[d][1];g=h.value[g];h.array[f]=g.x;h.array[f+1]=g.y;h.array[f+2]=g.z;f=f+3}else if(h.size===4)for(d=0;d<e;d++){g=n[d][1];
  22557. g=h.value[g];h.array[f]=g.x;h.array[f+1]=g.y;h.array[f+2]=g.z;h.array[f+3]=g.w;f=f+4}}}}}else{if(o)for(d=0;d<g;d++){e=h[d];f=d*3;l[f]=e.x;l[f+1]=e.y;l[f+2]=e.z}if(p)for(d=0;d<j;d++){e=k[d];f=d*3;m[f]=e.r;m[f+1]=e.g;m[f+2]=e.b}if(q){k=0;for(j=q.length;k<j;k++){h=q[k];if(h.needsUpdate&&(h.boundTo===void 0||h.boundTo==="vertices")){e=h.value.length;f=0;if(h.size===1)for(d=0;d<e;d++)h.array[d]=h.value[d];else if(h.size===2)for(d=0;d<e;d++){g=h.value[d];h.array[f]=g.x;h.array[f+1]=g.y;f=f+2}else if(h.size===
  22558. 3)if(h.type==="c")for(d=0;d<e;d++){g=h.value[d];h.array[f]=g.r;h.array[f+1]=g.g;h.array[f+2]=g.b;f=f+3}else for(d=0;d<e;d++){g=h.value[d];h.array[f]=g.x;h.array[f+1]=g.y;h.array[f+2]=g.z;f=f+3}else if(h.size===4)for(d=0;d<e;d++){g=h.value[d];h.array[f]=g.x;h.array[f+1]=g.y;h.array[f+2]=g.z;h.array[f+3]=g.w;f=f+4}}}}}if(o||c.sortParticles){i.bindBuffer(i.ARRAY_BUFFER,a.__webglVertexBuffer);i.bufferData(i.ARRAY_BUFFER,l,b)}if(p||c.sortParticles){i.bindBuffer(i.ARRAY_BUFFER,a.__webglColorBuffer);i.bufferData(i.ARRAY_BUFFER,
  22559. m,b)}if(q){k=0;for(j=q.length;k<j;k++){h=q[k];if(h.needsUpdate||c.sortParticles){i.bindBuffer(i.ARRAY_BUFFER,h.buffer);i.bufferData(i.ARRAY_BUFFER,h.array,b)}}}}function g(a,b){return b.z-a.z}function h(a,b,c){if(a.length)for(var d=0,e=a.length;d<e;d++){ea=U=null;Y=I=O=ia=Ka=Ma=Q=-1;Ta=true;a[d].render(b,c,hb,Cb);ea=U=null;Y=I=O=ia=Ka=Ma=Q=-1;Ta=true}}function k(a,b,c,d,e,f,g,h){var i,k,j,l;if(b){k=a.length-1;l=b=-1}else{k=0;b=a.length;l=1}for(var m=k;m!==b;m=m+l){i=a[m];if(i.render){k=i.object;j=
  22560. i.buffer;if(h)i=h;else{i=i[c];if(!i)continue;g&&G.setBlending(i.blending,i.blendEquation,i.blendSrc,i.blendDst);G.setDepthTest(i.depthTest);G.setDepthWrite(i.depthWrite);u(i.polygonOffset,i.polygonOffsetFactor,i.polygonOffsetUnits)}G.setObjectFaces(k);j instanceof THREE.BufferGeometry?G.renderBufferDirect(d,e,f,i,j,k):G.renderBuffer(d,e,f,i,j,k)}}}function j(a,b,c,d,e,f,g){for(var h,i,k=0,j=a.length;k<j;k++){h=a[k];i=h.object;if(i.visible){if(g)h=g;else{h=h[b];if(!h)continue;f&&G.setBlending(h.blending,
  22561. h.blendEquation,h.blendSrc,h.blendDst);G.setDepthTest(h.depthTest);G.setDepthWrite(h.depthWrite);u(h.polygonOffset,h.polygonOffsetFactor,h.polygonOffsetUnits)}G.renderImmediateObject(c,d,e,h,i)}}}function l(a,b,c){a.push({buffer:b,object:c,opaque:null,transparent:null})}function p(a){for(var b in a.attributes)if(a.attributes[b].needsUpdate)return true;return false}function m(a){for(var b in a.attributes)a.attributes[b].needsUpdate=false}function o(a,b){for(var c=a.length-1;c>=0;c--)a[c].object===
  22562. b&&a.splice(c,1)}function q(a,b){for(var c=a.length-1;c>=0;c--)a[c]===b&&a.splice(c,1)}function n(a,b,c,d,e){if(!d.program||d.needsUpdate){G.initMaterial(d,b,c,e);d.needsUpdate=false}if(d.morphTargets&&!e.__webglMorphTargetInfluences){e.__webglMorphTargetInfluences=new Float32Array(G.maxMorphTargets);for(var f=0,g=G.maxMorphTargets;f<g;f++)e.__webglMorphTargetInfluences[f]=0}var h=false,f=d.program,g=f.uniforms,k=d.uniforms;if(f!==U){i.useProgram(f);U=f;h=true}if(d.id!==Y){Y=d.id;h=true}if(h||a!==
  22563. ea){i.uniformMatrix4fv(g.projectionMatrix,false,a._projectionMatrixArray);a!==ea&&(ea=a)}if(h){if(c&&d.fog){k.fogColor.value=c.color;if(c instanceof THREE.Fog){k.fogNear.value=c.near;k.fogFar.value=c.far}else if(c instanceof THREE.FogExp2)k.fogDensity.value=c.density}if(d instanceof THREE.MeshPhongMaterial||d instanceof THREE.MeshLambertMaterial||d.lights){if(Ta){for(var j,l=0,m=0,n=0,o,p,q,r=Qa,s=r.directional.colors,t=r.directional.positions,u=r.point.colors,v=r.point.positions,x=r.point.distances,
  22564. z=r.spot.colors,A=r.spot.positions,C=r.spot.distances,E=r.spot.directions,I=r.spot.angles,J=r.spot.exponents,K=0,Q=0,M=0,O=q=0,c=O=0,h=b.length;c<h;c++){j=b[c];if(!j.onlyShadow){o=j.color;p=j.intensity;q=j.distance;if(j instanceof THREE.AmbientLight)if(G.gammaInput){l=l+o.r*o.r;m=m+o.g*o.g;n=n+o.b*o.b}else{l=l+o.r;m=m+o.g;n=n+o.b}else if(j instanceof THREE.DirectionalLight){q=K*3;if(G.gammaInput){s[q]=o.r*o.r*p*p;s[q+1]=o.g*o.g*p*p;s[q+2]=o.b*o.b*p*p}else{s[q]=o.r*p;s[q+1]=o.g*p;s[q+2]=o.b*p}aa.copy(j.matrixWorld.getPosition());
  22565. aa.subSelf(j.target.matrixWorld.getPosition());aa.normalize();t[q]=aa.x;t[q+1]=aa.y;t[q+2]=aa.z;K=K+1}else if(j instanceof THREE.PointLight){O=Q*3;if(G.gammaInput){u[O]=o.r*o.r*p*p;u[O+1]=o.g*o.g*p*p;u[O+2]=o.b*o.b*p*p}else{u[O]=o.r*p;u[O+1]=o.g*p;u[O+2]=o.b*p}o=j.matrixWorld.getPosition();v[O]=o.x;v[O+1]=o.y;v[O+2]=o.z;x[Q]=q;Q=Q+1}else if(j instanceof THREE.SpotLight){O=M*3;if(G.gammaInput){z[O]=o.r*o.r*p*p;z[O+1]=o.g*o.g*p*p;z[O+2]=o.b*o.b*p*p}else{z[O]=o.r*p;z[O+1]=o.g*p;z[O+2]=o.b*p}o=j.matrixWorld.getPosition();
  22566. A[O]=o.x;A[O+1]=o.y;A[O+2]=o.z;C[M]=q;aa.copy(o);aa.subSelf(j.target.matrixWorld.getPosition());aa.normalize();E[O]=aa.x;E[O+1]=aa.y;E[O+2]=aa.z;I[M]=Math.cos(j.angle);J[M]=j.exponent;M=M+1}}}c=K*3;for(h=s.length;c<h;c++)s[c]=0;c=Q*3;for(h=u.length;c<h;c++)u[c]=0;c=M*3;for(h=z.length;c<h;c++)z[c]=0;r.directional.length=K;r.point.length=Q;r.spot.length=M;r.ambient[0]=l;r.ambient[1]=m;r.ambient[2]=n;Ta=false}c=Qa;k.ambientLightColor.value=c.ambient;k.directionalLightColor.value=c.directional.colors;
  22567. k.directionalLightDirection.value=c.directional.positions;k.pointLightColor.value=c.point.colors;k.pointLightPosition.value=c.point.positions;k.pointLightDistance.value=c.point.distances;k.spotLightColor.value=c.spot.colors;k.spotLightPosition.value=c.spot.positions;k.spotLightDistance.value=c.spot.distances;k.spotLightDirection.value=c.spot.directions;k.spotLightAngle.value=c.spot.angles;k.spotLightExponent.value=c.spot.exponents}if(d instanceof THREE.MeshBasicMaterial||d instanceof THREE.MeshLambertMaterial||
  22568. d instanceof THREE.MeshPhongMaterial){k.opacity.value=d.opacity;G.gammaInput?k.diffuse.value.copyGammaToLinear(d.color):k.diffuse.value=d.color;(k.map.texture=d.map)&&k.offsetRepeat.value.set(d.map.offset.x,d.map.offset.y,d.map.repeat.x,d.map.repeat.y);k.lightMap.texture=d.lightMap;k.envMap.texture=d.envMap;k.flipEnvMap.value=d.envMap instanceof THREE.WebGLRenderTargetCube?1:-1;k.reflectivity.value=d.reflectivity;k.refractionRatio.value=d.refractionRatio;k.combine.value=d.combine;k.useRefract.value=
  22569. d.envMap&&d.envMap.mapping instanceof THREE.CubeRefractionMapping}if(d instanceof THREE.LineBasicMaterial){k.diffuse.value=d.color;k.opacity.value=d.opacity}else if(d instanceof THREE.ParticleBasicMaterial){k.psColor.value=d.color;k.opacity.value=d.opacity;k.size.value=d.size;k.scale.value=D.height/2;k.map.texture=d.map}else if(d instanceof THREE.MeshPhongMaterial){k.shininess.value=d.shininess;if(G.gammaInput){k.ambient.value.copyGammaToLinear(d.ambient);k.emissive.value.copyGammaToLinear(d.emissive);
  22570. k.specular.value.copyGammaToLinear(d.specular)}else{k.ambient.value=d.ambient;k.emissive.value=d.emissive;k.specular.value=d.specular}d.wrapAround&&k.wrapRGB.value.copy(d.wrapRGB)}else if(d instanceof THREE.MeshLambertMaterial){if(G.gammaInput){k.ambient.value.copyGammaToLinear(d.ambient);k.emissive.value.copyGammaToLinear(d.emissive)}else{k.ambient.value=d.ambient;k.emissive.value=d.emissive}d.wrapAround&&k.wrapRGB.value.copy(d.wrapRGB)}else if(d instanceof THREE.MeshDepthMaterial){k.mNear.value=
  22571. a.near;k.mFar.value=a.far;k.opacity.value=d.opacity}else if(d instanceof THREE.MeshNormalMaterial)k.opacity.value=d.opacity;if(e.receiveShadow&&!d._shadowPass&&k.shadowMatrix){h=c=0;for(j=b.length;h<j;h++){l=b[h];if(l.castShadow&&(l instanceof THREE.SpotLight||l instanceof THREE.DirectionalLight&&!l.shadowCascade)){k.shadowMap.texture[c]=l.shadowMap;k.shadowMapSize.value[c]=l.shadowMapSize;k.shadowMatrix.value[c]=l.shadowMatrix;k.shadowDarkness.value[c]=l.shadowDarkness;k.shadowBias.value[c]=l.shadowBias;
  22572. c++}}}b=d.uniformsList;k=0;for(c=b.length;k<c;k++)if(l=f.uniforms[b[k][1]]){h=b[k][0];m=h.type;j=h.value;switch(m){case "i":i.uniform1i(l,j);break;case "f":i.uniform1f(l,j);break;case "v2":i.uniform2f(l,j.x,j.y);break;case "v3":i.uniform3f(l,j.x,j.y,j.z);break;case "v4":i.uniform4f(l,j.x,j.y,j.z,j.w);break;case "c":i.uniform3f(l,j.r,j.g,j.b);break;case "fv1":i.uniform1fv(l,j);break;case "fv":i.uniform3fv(l,j);break;case "v2v":if(!h._array)h._array=new Float32Array(2*j.length);m=0;for(n=j.length;m<
  22573. n;m++){r=m*2;h._array[r]=j[m].x;h._array[r+1]=j[m].y}i.uniform2fv(l,h._array);break;case "v3v":if(!h._array)h._array=new Float32Array(3*j.length);m=0;for(n=j.length;m<n;m++){r=m*3;h._array[r]=j[m].x;h._array[r+1]=j[m].y;h._array[r+2]=j[m].z}i.uniform3fv(l,h._array);break;case "v4v":if(!h._array)h._array=new Float32Array(4*j.length);m=0;for(n=j.length;m<n;m++){r=m*4;h._array[r]=j[m].x;h._array[r+1]=j[m].y;h._array[r+2]=j[m].z;h._array[r+3]=j[m].w}i.uniform4fv(l,h._array);break;case "m4":if(!h._array)h._array=
  22574. new Float32Array(16);j.flattenToArray(h._array);i.uniformMatrix4fv(l,false,h._array);break;case "m4v":if(!h._array)h._array=new Float32Array(16*j.length);m=0;for(n=j.length;m<n;m++)j[m].flattenToArrayOffset(h._array,m*16);i.uniformMatrix4fv(l,false,h._array);break;case "t":i.uniform1i(l,j);l=h.texture;if(!l)continue;if(l.image instanceof Array&&l.image.length===6){h=l;if(h.image.length===6)if(h.needsUpdate){if(!h.image.__webglTextureCube)h.image.__webglTextureCube=i.createTexture();i.activeTexture(i.TEXTURE0+
  22575. j);i.bindTexture(i.TEXTURE_CUBE_MAP,h.image.__webglTextureCube);j=[];for(l=0;l<6;l++){m=j;n=l;if(G.autoScaleCubemaps){r=h.image[l];t=ib;if(!(r.width<=t&&r.height<=t)){u=Math.max(r.width,r.height);s=Math.floor(r.width*t/u);t=Math.floor(r.height*t/u);u=document.createElement("canvas");u.width=s;u.height=t;u.getContext("2d").drawImage(r,0,0,r.width,r.height,0,0,s,t);r=u}}else r=h.image[l];m[n]=r}l=j[0];m=(l.width&l.width-1)===0&&(l.height&l.height-1)===0;n=F(h.format);r=F(h.type);w(i.TEXTURE_CUBE_MAP,
  22576. h,m);for(l=0;l<6;l++)i.texImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+l,0,n,n,r,j[l]);h.generateMipmaps&&m&&i.generateMipmap(i.TEXTURE_CUBE_MAP);h.needsUpdate=false;if(h.onUpdate)h.onUpdate()}else{i.activeTexture(i.TEXTURE0+j);i.bindTexture(i.TEXTURE_CUBE_MAP,h.image.__webglTextureCube)}}else if(l instanceof THREE.WebGLRenderTargetCube){h=l;i.activeTexture(i.TEXTURE0+j);i.bindTexture(i.TEXTURE_CUBE_MAP,h.__webglTexture)}else G.setTexture(l,j);break;case "tv":if(!h._array){h._array=[];m=0;for(n=h.texture.length;m<
  22577. n;m++)h._array[m]=j+m}i.uniform1iv(l,h._array);m=0;for(n=h.texture.length;m<n;m++)(l=h.texture[m])&&G.setTexture(l,h._array[m])}}if((d instanceof THREE.ShaderMaterial||d instanceof THREE.MeshPhongMaterial||d.envMap)&&g.cameraPosition!==null){b=a.matrixWorld.getPosition();i.uniform3f(g.cameraPosition,b.x,b.y,b.z)}(d instanceof THREE.MeshPhongMaterial||d instanceof THREE.MeshLambertMaterial||d instanceof THREE.ShaderMaterial||d.skinning)&&g.viewMatrix!==null&&i.uniformMatrix4fv(g.viewMatrix,false,a._viewMatrixArray);
  22578. d.skinning&&i.uniformMatrix4fv(g.boneGlobalMatrices,false,e.boneMatrices)}i.uniformMatrix4fv(g.modelViewMatrix,false,e._modelViewMatrix.elements);g.normalMatrix&&i.uniformMatrix3fv(g.normalMatrix,false,e._normalMatrix.elements);g.objectMatrix!==null&&i.uniformMatrix4fv(g.objectMatrix,false,e.matrixWorld.elements);return f}function r(a,b){a._modelViewMatrix.multiply(b.matrixWorldInverse,a.matrixWorld);a._normalMatrix.getInverse(a._modelViewMatrix);a._normalMatrix.transpose()}function u(a,b,c){if(Ra!==
  22579. a){a?i.enable(i.POLYGON_OFFSET_FILL):i.disable(i.POLYGON_OFFSET_FILL);Ra=a}if(a&&(La!==b||Sa!==c)){i.polygonOffset(b,c);La=b;Sa=c}}function t(a,b){var c;a==="fragment"?c=i.createShader(i.FRAGMENT_SHADER):a==="vertex"&&(c=i.createShader(i.VERTEX_SHADER));i.shaderSource(c,b);i.compileShader(c);if(!i.getShaderParameter(c,i.COMPILE_STATUS)){console.error(i.getShaderInfoLog(c));console.error(b);return null}return c}function w(a,b,c){if(c){i.texParameteri(a,i.TEXTURE_WRAP_S,F(b.wrapS));i.texParameteri(a,
  22580. i.TEXTURE_WRAP_T,F(b.wrapT));i.texParameteri(a,i.TEXTURE_MAG_FILTER,F(b.magFilter));i.texParameteri(a,i.TEXTURE_MIN_FILTER,F(b.minFilter))}else{i.texParameteri(a,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE);i.texParameteri(a,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE);i.texParameteri(a,i.TEXTURE_MAG_FILTER,x(b.magFilter));i.texParameteri(a,i.TEXTURE_MIN_FILTER,x(b.minFilter))}}function s(a,b){i.bindRenderbuffer(i.RENDERBUFFER,a);if(b.depthBuffer&&!b.stencilBuffer){i.renderbufferStorage(i.RENDERBUFFER,i.DEPTH_COMPONENT16,
  22581. b.width,b.height);i.framebufferRenderbuffer(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.RENDERBUFFER,a)}else if(b.depthBuffer&&b.stencilBuffer){i.renderbufferStorage(i.RENDERBUFFER,i.DEPTH_STENCIL,b.width,b.height);i.framebufferRenderbuffer(i.FRAMEBUFFER,i.DEPTH_STENCIL_ATTACHMENT,i.RENDERBUFFER,a)}else i.renderbufferStorage(i.RENDERBUFFER,i.RGBA4,b.width,b.height)}function x(a){switch(a){case THREE.NearestFilter:case THREE.NearestMipMapNearestFilter:case THREE.NearestMipMapLinearFilter:return i.NEAREST;default:return i.LINEAR}}
  22582. function F(a){switch(a){case THREE.RepeatWrapping:return i.REPEAT;case THREE.ClampToEdgeWrapping:return i.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return i.MIRRORED_REPEAT;case THREE.NearestFilter:return i.NEAREST;case THREE.NearestMipMapNearestFilter:return i.NEAREST_MIPMAP_NEAREST;case THREE.NearestMipMapLinearFilter:return i.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return i.LINEAR;case THREE.LinearMipMapNearestFilter:return i.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return i.LINEAR_MIPMAP_LINEAR;
  22583. case THREE.ByteType:return i.BYTE;case THREE.UnsignedByteType:return i.UNSIGNED_BYTE;case THREE.ShortType:return i.SHORT;case THREE.UnsignedShortType:return i.UNSIGNED_SHORT;case THREE.IntType:return i.INT;case THREE.UnsignedIntType:return i.UNSIGNED_INT;case THREE.FloatType:return i.FLOAT;case THREE.AlphaFormat:return i.ALPHA;case THREE.RGBFormat:return i.RGB;case THREE.RGBAFormat:return i.RGBA;case THREE.LuminanceFormat:return i.LUMINANCE;case THREE.LuminanceAlphaFormat:return i.LUMINANCE_ALPHA;
  22584. case THREE.AddEquation:return i.FUNC_ADD;case THREE.SubtractEquation:return i.FUNC_SUBTRACT;case THREE.ReverseSubtractEquation:return i.FUNC_REVERSE_SUBTRACT;case THREE.ZeroFactor:return i.ZERO;case THREE.OneFactor:return i.ONE;case THREE.SrcColorFactor:return i.SRC_COLOR;case THREE.OneMinusSrcColorFactor:return i.ONE_MINUS_SRC_COLOR;case THREE.SrcAlphaFactor:return i.SRC_ALPHA;case THREE.OneMinusSrcAlphaFactor:return i.ONE_MINUS_SRC_ALPHA;case THREE.DstAlphaFactor:return i.DST_ALPHA;case THREE.OneMinusDstAlphaFactor:return i.ONE_MINUS_DST_ALPHA;
  22585. case THREE.DstColorFactor:return i.DST_COLOR;case THREE.OneMinusDstColorFactor:return i.ONE_MINUS_DST_COLOR;case THREE.SrcAlphaSaturateFactor:return i.SRC_ALPHA_SATURATE}return 0}console.log("THREE.WebGLRenderer",THREE.REVISION);var a=a||{},D=a.canvas!==void 0?a.canvas:document.createElement("canvas"),z=a.precision!==void 0?a.precision:"highp",v=a.alpha!==void 0?a.alpha:true,A=a.premultipliedAlpha!==void 0?a.premultipliedAlpha:true,J=a.antialias!==void 0?a.antialias:false,K=a.stencil!==void 0?a.stencil:
  22586. true,R=a.preserveDrawingBuffer!==void 0?a.preserveDrawingBuffer:false,P=a.clearColor!==void 0?new THREE.Color(a.clearColor):new THREE.Color(0),E=a.clearAlpha!==void 0?a.clearAlpha:0,M=a.maxLights!==void 0?a.maxLights:4;this.domElement=D;this.context=null;this.autoUpdateScene=this.autoUpdateObjects=this.sortObjects=this.autoClearStencil=this.autoClearDepth=this.autoClearColor=this.autoClear=true;this.shadowMapEnabled=this.physicallyBasedShading=this.gammaOutput=this.gammaInput=false;this.shadowMapCullFrontFaces=
  22587. this.shadowMapSoft=this.shadowMapAutoUpdate=true;this.shadowMapCascade=this.shadowMapDebug=false;this.maxMorphTargets=8;this.maxMorphNormals=4;this.autoScaleCubemaps=true;this.renderPluginsPre=[];this.renderPluginsPost=[];this.info={memory:{programs:0,geometries:0,textures:0},render:{calls:0,vertices:0,faces:0,points:0}};var G=this,i,T=[],U=null,C=null,Y=-1,I=null,ea=null,fa=0,ia=-1,O=-1,Q=-1,Z=-1,$=-1,ha=-1,Ma=-1,Ka=-1,Ra=null,La=null,Sa=null,Na=null,Kb=0,lb=0,gb=0,Lb=0,hb=0,Cb=0,Wa=new THREE.Frustum,
  22588. Ba=new THREE.Matrix4,xa=new THREE.Matrix4,$a=new THREE.Vector4,aa=new THREE.Vector3,Ta=true,Qa={ambient:[0,0,0],directional:{length:0,colors:[],positions:[]},point:{length:0,colors:[],positions:[],distances:[]},spot:{length:0,colors:[],positions:[],distances:[],directions:[],angles:[],exponents:[]}};i=function(){var a;try{if(!(a=D.getContext("experimental-webgl",{alpha:v,premultipliedAlpha:A,antialias:J,stencil:K,preserveDrawingBuffer:R})))throw"Error creating WebGL context.";}catch(b){console.error(b)}return a}();
  22589. i.clearColor(0,0,0,1);i.clearDepth(1);i.clearStencil(0);i.enable(i.DEPTH_TEST);i.depthFunc(i.LEQUAL);i.frontFace(i.CCW);i.cullFace(i.BACK);i.enable(i.CULL_FACE);i.enable(i.BLEND);i.blendEquation(i.FUNC_ADD);i.blendFunc(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA);i.clearColor(P.r,P.g,P.b,E);this.context=i;var oa=i.getParameter(i.MAX_VERTEX_TEXTURE_IMAGE_UNITS);i.getParameter(i.MAX_TEXTURE_SIZE);var ib=i.getParameter(i.MAX_CUBE_MAP_TEXTURE_SIZE);this.getContext=function(){return i};this.supportsVertexTextures=
  22590. function(){return oa>0};this.setSize=function(a,b){D.width=a;D.height=b;this.setViewport(0,0,D.width,D.height)};this.setViewport=function(a,b,c,d){Kb=a;lb=b;gb=c;Lb=d;i.viewport(Kb,lb,gb,Lb)};this.setScissor=function(a,b,c,d){i.scissor(a,b,c,d)};this.enableScissorTest=function(a){a?i.enable(i.SCISSOR_TEST):i.disable(i.SCISSOR_TEST)};this.setClearColorHex=function(a,b){P.setHex(a);E=b;i.clearColor(P.r,P.g,P.b,E)};this.setClearColor=function(a,b){P.copy(a);E=b;i.clearColor(P.r,P.g,P.b,E)};this.getClearColor=
  22591. function(){return P};this.getClearAlpha=function(){return E};this.clear=function(a,b,c){var d=0;if(a===void 0||a)d=d|i.COLOR_BUFFER_BIT;if(b===void 0||b)d=d|i.DEPTH_BUFFER_BIT;if(c===void 0||c)d=d|i.STENCIL_BUFFER_BIT;i.clear(d)};this.clearTarget=function(a,b,c,d){this.setRenderTarget(a);this.clear(b,c,d)};this.addPostPlugin=function(a){a.init(this);this.renderPluginsPost.push(a)};this.addPrePlugin=function(a){a.init(this);this.renderPluginsPre.push(a)};this.deallocateObject=function(a){if(a.__webglInit){a.__webglInit=
  22592. false;delete a._modelViewMatrix;delete a._normalMatrix;delete a._normalMatrixArray;delete a._modelViewMatrixArray;delete a._objectMatrixArray;if(a instanceof THREE.Mesh)for(var b in a.geometry.geometryGroups){var c=a.geometry.geometryGroups[b];i.deleteBuffer(c.__webglVertexBuffer);i.deleteBuffer(c.__webglNormalBuffer);i.deleteBuffer(c.__webglTangentBuffer);i.deleteBuffer(c.__webglColorBuffer);i.deleteBuffer(c.__webglUVBuffer);i.deleteBuffer(c.__webglUV2Buffer);i.deleteBuffer(c.__webglSkinVertexABuffer);
  22593. i.deleteBuffer(c.__webglSkinVertexBBuffer);i.deleteBuffer(c.__webglSkinIndicesBuffer);i.deleteBuffer(c.__webglSkinWeightsBuffer);i.deleteBuffer(c.__webglFaceBuffer);i.deleteBuffer(c.__webglLineBuffer);var d=void 0,e=void 0;if(c.numMorphTargets){d=0;for(e=c.numMorphTargets;d<e;d++)i.deleteBuffer(c.__webglMorphTargetsBuffers[d])}if(c.numMorphNormals){d=0;for(e=c.numMorphNormals;d<e;d++)i.deleteBuffer(c.__webglMorphNormalsBuffers[d])}if(c.__webglCustomAttributesList){d=void 0;for(d in c.__webglCustomAttributesList)i.deleteBuffer(c.__webglCustomAttributesList[d].buffer)}G.info.memory.geometries--}else if(a instanceof
  22594. THREE.Ribbon){a=a.geometry;i.deleteBuffer(a.__webglVertexBuffer);i.deleteBuffer(a.__webglColorBuffer);G.info.memory.geometries--}else if(a instanceof THREE.Line){a=a.geometry;i.deleteBuffer(a.__webglVertexBuffer);i.deleteBuffer(a.__webglColorBuffer);G.info.memory.geometries--}else if(a instanceof THREE.ParticleSystem){a=a.geometry;i.deleteBuffer(a.__webglVertexBuffer);i.deleteBuffer(a.__webglColorBuffer);G.info.memory.geometries--}}};this.deallocateTexture=function(a){if(a.__webglInit){a.__webglInit=
  22595. false;i.deleteTexture(a.__webglTexture);G.info.memory.textures--}};this.deallocateRenderTarget=function(a){if(a&&a.__webglTexture){i.deleteTexture(a.__webglTexture);if(a instanceof THREE.WebGLRenderTargetCube)for(var b=0;b<6;b++){i.deleteFramebuffer(a.__webglFramebuffer[b]);i.deleteRenderbuffer(a.__webglRenderbuffer[b])}else{i.deleteFramebuffer(a.__webglFramebuffer);i.deleteRenderbuffer(a.__webglRenderbuffer)}}};this.updateShadowMap=function(a,b){U=null;Y=I=Ka=Ma=Q=-1;Ta=true;O=ia=-1;this.shadowMapPlugin.update(a,
  22596. b)};this.renderBufferImmediate=function(a,b,c){if(!a.__webglVertexBuffer)a.__webglVertexBuffer=i.createBuffer();if(!a.__webglNormalBuffer)a.__webglNormalBuffer=i.createBuffer();if(a.hasPos){i.bindBuffer(i.ARRAY_BUFFER,a.__webglVertexBuffer);i.bufferData(i.ARRAY_BUFFER,a.positionArray,i.DYNAMIC_DRAW);i.enableVertexAttribArray(b.attributes.position);i.vertexAttribPointer(b.attributes.position,3,i.FLOAT,false,0,0)}if(a.hasNormal){i.bindBuffer(i.ARRAY_BUFFER,a.__webglNormalBuffer);if(c===THREE.FlatShading){var d,
  22597. e,f,g,h,k,j,l,m,n,o=a.count*3;for(n=0;n<o;n=n+9){c=a.normalArray;d=c[n];e=c[n+1];f=c[n+2];g=c[n+3];k=c[n+4];l=c[n+5];h=c[n+6];j=c[n+7];m=c[n+8];d=(d+g+h)/3;e=(e+k+j)/3;f=(f+l+m)/3;c[n]=d;c[n+1]=e;c[n+2]=f;c[n+3]=d;c[n+4]=e;c[n+5]=f;c[n+6]=d;c[n+7]=e;c[n+8]=f}}i.bufferData(i.ARRAY_BUFFER,a.normalArray,i.DYNAMIC_DRAW);i.enableVertexAttribArray(b.attributes.normal);i.vertexAttribPointer(b.attributes.normal,3,i.FLOAT,false,0,0)}i.drawArrays(i.TRIANGLES,0,a.count);a.count=0};this.renderBufferDirect=function(a,
  22598. b,c,d,e,f){if(d.visible!==false){c=n(a,b,c,d,f);a=c.attributes;b=false;d=e.id*16777215+c.id*2+(d.wireframe?1:0);if(d!==I){I=d;b=true}if(f instanceof THREE.Mesh){f=e.offsets;d=0;for(c=f.length;d<c;++d){if(b){i.bindBuffer(i.ARRAY_BUFFER,e.vertexPositionBuffer);i.vertexAttribPointer(a.position,e.vertexPositionBuffer.itemSize,i.FLOAT,false,0,f[d].index*12);if(a.normal>=0&&e.vertexNormalBuffer){i.bindBuffer(i.ARRAY_BUFFER,e.vertexNormalBuffer);i.vertexAttribPointer(a.normal,e.vertexNormalBuffer.itemSize,
  22599. i.FLOAT,false,0,f[d].index*12)}if(a.uv>=0&&e.vertexUvBuffer)if(e.vertexUvBuffer){i.bindBuffer(i.ARRAY_BUFFER,e.vertexUvBuffer);i.vertexAttribPointer(a.uv,e.vertexUvBuffer.itemSize,i.FLOAT,false,0,f[d].index*8);i.enableVertexAttribArray(a.uv)}else i.disableVertexAttribArray(a.uv);if(a.color>=0&&e.vertexColorBuffer){i.bindBuffer(i.ARRAY_BUFFER,e.vertexColorBuffer);i.vertexAttribPointer(a.color,e.vertexColorBuffer.itemSize,i.FLOAT,false,0,f[d].index*16)}i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,e.vertexIndexBuffer)}i.drawElements(i.TRIANGLES,
  22600. f[d].count,i.UNSIGNED_SHORT,f[d].start*2);G.info.render.calls++;G.info.render.vertices=G.info.render.vertices+f[d].count;G.info.render.faces=G.info.render.faces+f[d].count/3}}}};this.renderBuffer=function(a,b,c,d,e,f){if(d.visible!==false){var g,h,c=n(a,b,c,d,f),b=c.attributes,a=false,c=e.id*16777215+c.id*2+(d.wireframe?1:0);if(c!==I){I=c;a=true}if(!d.morphTargets&&b.position>=0){if(a){i.bindBuffer(i.ARRAY_BUFFER,e.__webglVertexBuffer);i.vertexAttribPointer(b.position,3,i.FLOAT,false,0,0)}}else if(f.morphTargetBase){c=
  22601. d.program.attributes;if(f.morphTargetBase!==-1){i.bindBuffer(i.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[f.morphTargetBase]);i.vertexAttribPointer(c.position,3,i.FLOAT,false,0,0)}else if(c.position>=0){i.bindBuffer(i.ARRAY_BUFFER,e.__webglVertexBuffer);i.vertexAttribPointer(c.position,3,i.FLOAT,false,0,0)}if(f.morphTargetForcedOrder.length){g=0;var k=f.morphTargetForcedOrder;for(h=f.morphTargetInfluences;g<d.numSupportedMorphTargets&&g<k.length;){i.bindBuffer(i.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[k[g]]);
  22602. i.vertexAttribPointer(c["morphTarget"+g],3,i.FLOAT,false,0,0);if(d.morphNormals){i.bindBuffer(i.ARRAY_BUFFER,e.__webglMorphNormalsBuffers[k[g]]);i.vertexAttribPointer(c["morphNormal"+g],3,i.FLOAT,false,0,0)}f.__webglMorphTargetInfluences[g]=h[k[g]];g++}}else{var k=[],j=-1,l=0;h=f.morphTargetInfluences;var m,o=h.length;g=0;for(f.morphTargetBase!==-1&&(k[f.morphTargetBase]=true);g<d.numSupportedMorphTargets;){for(m=0;m<o;m++)if(!k[m]&&h[m]>j){l=m;j=h[l]}i.bindBuffer(i.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[l]);
  22603. i.vertexAttribPointer(c["morphTarget"+g],3,i.FLOAT,false,0,0);if(d.morphNormals){i.bindBuffer(i.ARRAY_BUFFER,e.__webglMorphNormalsBuffers[l]);i.vertexAttribPointer(c["morphNormal"+g],3,i.FLOAT,false,0,0)}f.__webglMorphTargetInfluences[g]=j;k[l]=1;j=-1;g++}}d.program.uniforms.morphTargetInfluences!==null&&i.uniform1fv(d.program.uniforms.morphTargetInfluences,f.__webglMorphTargetInfluences)}if(a){if(e.__webglCustomAttributesList){g=0;for(h=e.__webglCustomAttributesList.length;g<h;g++){c=e.__webglCustomAttributesList[g];
  22604. if(b[c.buffer.belongsToAttribute]>=0){i.bindBuffer(i.ARRAY_BUFFER,c.buffer);i.vertexAttribPointer(b[c.buffer.belongsToAttribute],c.size,i.FLOAT,false,0,0)}}}if(b.color>=0){i.bindBuffer(i.ARRAY_BUFFER,e.__webglColorBuffer);i.vertexAttribPointer(b.color,3,i.FLOAT,false,0,0)}if(b.normal>=0){i.bindBuffer(i.ARRAY_BUFFER,e.__webglNormalBuffer);i.vertexAttribPointer(b.normal,3,i.FLOAT,false,0,0)}if(b.tangent>=0){i.bindBuffer(i.ARRAY_BUFFER,e.__webglTangentBuffer);i.vertexAttribPointer(b.tangent,4,i.FLOAT,
  22605. false,0,0)}if(b.uv>=0)if(e.__webglUVBuffer){i.bindBuffer(i.ARRAY_BUFFER,e.__webglUVBuffer);i.vertexAttribPointer(b.uv,2,i.FLOAT,false,0,0);i.enableVertexAttribArray(b.uv)}else i.disableVertexAttribArray(b.uv);if(b.uv2>=0)if(e.__webglUV2Buffer){i.bindBuffer(i.ARRAY_BUFFER,e.__webglUV2Buffer);i.vertexAttribPointer(b.uv2,2,i.FLOAT,false,0,0);i.enableVertexAttribArray(b.uv2)}else i.disableVertexAttribArray(b.uv2);if(d.skinning&&b.skinVertexA>=0&&b.skinVertexB>=0&&b.skinIndex>=0&&b.skinWeight>=0){i.bindBuffer(i.ARRAY_BUFFER,
  22606. e.__webglSkinVertexABuffer);i.vertexAttribPointer(b.skinVertexA,4,i.FLOAT,false,0,0);i.bindBuffer(i.ARRAY_BUFFER,e.__webglSkinVertexBBuffer);i.vertexAttribPointer(b.skinVertexB,4,i.FLOAT,false,0,0);i.bindBuffer(i.ARRAY_BUFFER,e.__webglSkinIndicesBuffer);i.vertexAttribPointer(b.skinIndex,4,i.FLOAT,false,0,0);i.bindBuffer(i.ARRAY_BUFFER,e.__webglSkinWeightsBuffer);i.vertexAttribPointer(b.skinWeight,4,i.FLOAT,false,0,0)}}if(f instanceof THREE.Mesh){if(d.wireframe){d=d.wireframeLinewidth;if(d!==Na){i.lineWidth(d);
  22607. Na=d}a&&i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,e.__webglLineBuffer);i.drawElements(i.LINES,e.__webglLineCount,i.UNSIGNED_SHORT,0)}else{a&&i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,e.__webglFaceBuffer);i.drawElements(i.TRIANGLES,e.__webglFaceCount,i.UNSIGNED_SHORT,0)}G.info.render.calls++;G.info.render.vertices=G.info.render.vertices+e.__webglFaceCount;G.info.render.faces=G.info.render.faces+e.__webglFaceCount/3}else if(f instanceof THREE.Line){f=f.type===THREE.LineStrip?i.LINE_STRIP:i.LINES;d=d.linewidth;
  22608. if(d!==Na){i.lineWidth(d);Na=d}i.drawArrays(f,0,e.__webglLineCount);G.info.render.calls++}else if(f instanceof THREE.ParticleSystem){i.drawArrays(i.POINTS,0,e.__webglParticleCount);G.info.render.calls++;G.info.render.points=G.info.render.points+e.__webglParticleCount}else if(f instanceof THREE.Ribbon){i.drawArrays(i.TRIANGLE_STRIP,0,e.__webglVertexCount);G.info.render.calls++}}};this.render=function(a,b,c,d){var e,f,l,m,n=a.__lights,o=a.fog;Y=-1;Ta=true;if(b.parent===void 0){console.warn("DEPRECATED: Camera hasn't been added to a Scene. Adding it...");
  22609. a.add(b)}this.autoUpdateScene&&a.updateMatrixWorld();if(!b._viewMatrixArray)b._viewMatrixArray=new Float32Array(16);if(!b._projectionMatrixArray)b._projectionMatrixArray=new Float32Array(16);b.matrixWorldInverse.getInverse(b.matrixWorld);b.matrixWorldInverse.flattenToArray(b._viewMatrixArray);b.projectionMatrix.flattenToArray(b._projectionMatrixArray);Ba.multiply(b.projectionMatrix,b.matrixWorldInverse);Wa.setFromMatrix(Ba);this.autoUpdateObjects&&this.initWebGLObjects(a);h(this.renderPluginsPre,
  22610. a,b);G.info.render.calls=0;G.info.render.vertices=0;G.info.render.faces=0;G.info.render.points=0;this.setRenderTarget(c);(this.autoClear||d)&&this.clear(this.autoClearColor,this.autoClearDepth,this.autoClearStencil);m=a.__webglObjects;d=0;for(e=m.length;d<e;d++){f=m[d];l=f.object;f.render=false;if(l.visible&&(!(l instanceof THREE.Mesh||l instanceof THREE.ParticleSystem)||!l.frustumCulled||Wa.contains(l))){r(l,b);var p=f,q=p.object,s=p.buffer,t=void 0,t=t=void 0,t=q.material;if(t instanceof THREE.MeshFaceMaterial){t=
  22611. s.materialIndex;if(t>=0){t=q.geometry.materials[t];if(t.transparent){p.transparent=t;p.opaque=null}else{p.opaque=t;p.transparent=null}}}else if(t)if(t.transparent){p.transparent=t;p.opaque=null}else{p.opaque=t;p.transparent=null}f.render=true;if(this.sortObjects)if(l.renderDepth)f.z=l.renderDepth;else{$a.copy(l.matrixWorld.getPosition());Ba.multiplyVector3($a);f.z=$a.z}}}this.sortObjects&&m.sort(g);m=a.__webglObjectsImmediate;d=0;for(e=m.length;d<e;d++){f=m[d];l=f.object;if(l.visible){r(l,b);l=f.object.material;
  22612. if(l.transparent){f.transparent=l;f.opaque=null}else{f.opaque=l;f.transparent=null}}}if(a.overrideMaterial){d=a.overrideMaterial;this.setBlending(d.blending,d.blendEquation,d.blendSrc,d.blendDst);this.setDepthTest(d.depthTest);this.setDepthWrite(d.depthWrite);u(d.polygonOffset,d.polygonOffsetFactor,d.polygonOffsetUnits);k(a.__webglObjects,false,"",b,n,o,true,d);j(a.__webglObjectsImmediate,"",b,n,o,false,d)}else{this.setBlending(THREE.NormalBlending);k(a.__webglObjects,true,"opaque",b,n,o,false);j(a.__webglObjectsImmediate,
  22613. "opaque",b,n,o,false);k(a.__webglObjects,false,"transparent",b,n,o,true);j(a.__webglObjectsImmediate,"transparent",b,n,o,true)}h(this.renderPluginsPost,a,b);if(c&&c.generateMipmaps&&c.minFilter!==THREE.NearestFilter&&c.minFilter!==THREE.LinearFilter)if(c instanceof THREE.WebGLRenderTargetCube){i.bindTexture(i.TEXTURE_CUBE_MAP,c.__webglTexture);i.generateMipmap(i.TEXTURE_CUBE_MAP);i.bindTexture(i.TEXTURE_CUBE_MAP,null)}else{i.bindTexture(i.TEXTURE_2D,c.__webglTexture);i.generateMipmap(i.TEXTURE_2D);
  22614. i.bindTexture(i.TEXTURE_2D,null)}this.setDepthTest(true);this.setDepthWrite(true)};this.renderImmediateObject=function(a,b,c,d,e){var f=n(a,b,c,d,e);I=-1;G.setObjectFaces(e);e.immediateRenderCallback?e.immediateRenderCallback(f,i,Wa):e.render(function(a){G.renderBufferImmediate(a,f,d.shading)})};this.initWebGLObjects=function(a){if(!a.__webglObjects){a.__webglObjects=[];a.__webglObjectsImmediate=[];a.__webglSprites=[];a.__webglFlares=[]}for(;a.__objectsAdded.length;){var g=a.__objectsAdded[0],h=a,
  22615. k=void 0,j=void 0,n=void 0;if(!g.__webglInit){g.__webglInit=true;g._modelViewMatrix=new THREE.Matrix4;g._normalMatrix=new THREE.Matrix3;if(g instanceof THREE.Mesh){j=g.geometry;if(j instanceof THREE.Geometry){if(j.geometryGroups===void 0){var r=j,s=void 0,t=void 0,u=void 0,v=void 0,x=void 0,w=void 0,z=void 0,A={},C=r.morphTargets.length,E=r.morphNormals.length;r.geometryGroups={};s=0;for(t=r.faces.length;s<t;s++){u=r.faces[s];v=u.materialIndex;w=v!==void 0?v:-1;A[w]===void 0&&(A[w]={hash:w,counter:0});
  22616. z=A[w].hash+"_"+A[w].counter;r.geometryGroups[z]===void 0&&(r.geometryGroups[z]={faces3:[],faces4:[],materialIndex:v,vertices:0,numMorphTargets:C,numMorphNormals:E});x=u instanceof THREE.Face3?3:4;if(r.geometryGroups[z].vertices+x>65535){A[w].counter=A[w].counter+1;z=A[w].hash+"_"+A[w].counter;r.geometryGroups[z]===void 0&&(r.geometryGroups[z]={faces3:[],faces4:[],materialIndex:v,vertices:0,numMorphTargets:C,numMorphNormals:E})}u instanceof THREE.Face3?r.geometryGroups[z].faces3.push(s):r.geometryGroups[z].faces4.push(s);
  22617. r.geometryGroups[z].vertices=r.geometryGroups[z].vertices+x}r.geometryGroupsList=[];var I=void 0;for(I in r.geometryGroups){r.geometryGroups[I].id=fa++;r.geometryGroupsList.push(r.geometryGroups[I])}}for(k in j.geometryGroups){n=j.geometryGroups[k];if(!n.__webglVertexBuffer){var D=n;D.__webglVertexBuffer=i.createBuffer();D.__webglNormalBuffer=i.createBuffer();D.__webglTangentBuffer=i.createBuffer();D.__webglColorBuffer=i.createBuffer();D.__webglUVBuffer=i.createBuffer();D.__webglUV2Buffer=i.createBuffer();
  22618. D.__webglSkinVertexABuffer=i.createBuffer();D.__webglSkinVertexBBuffer=i.createBuffer();D.__webglSkinIndicesBuffer=i.createBuffer();D.__webglSkinWeightsBuffer=i.createBuffer();D.__webglFaceBuffer=i.createBuffer();D.__webglLineBuffer=i.createBuffer();var F=void 0,K=void 0;if(D.numMorphTargets){D.__webglMorphTargetsBuffers=[];F=0;for(K=D.numMorphTargets;F<K;F++)D.__webglMorphTargetsBuffers.push(i.createBuffer())}if(D.numMorphNormals){D.__webglMorphNormalsBuffers=[];F=0;for(K=D.numMorphNormals;F<K;F++)D.__webglMorphNormalsBuffers.push(i.createBuffer())}G.info.memory.geometries++;
  22619. var Q=n,J=g,O=J.geometry,M=Q.faces3,$=Q.faces4,P=M.length*3+$.length*4,Z=M.length*1+$.length*2,Y=M.length*3+$.length*4,R=c(J,Q),T=e(R),ea=d(R),ia=R.vertexColors?R.vertexColors:false;Q.__vertexArray=new Float32Array(P*3);if(ea)Q.__normalArray=new Float32Array(P*3);if(O.hasTangents)Q.__tangentArray=new Float32Array(P*4);if(ia)Q.__colorArray=new Float32Array(P*3);if(T){if(O.faceUvs.length>0||O.faceVertexUvs.length>0)Q.__uvArray=new Float32Array(P*2);if(O.faceUvs.length>1||O.faceVertexUvs.length>1)Q.__uv2Array=
  22620. new Float32Array(P*2)}if(J.geometry.skinWeights.length&&J.geometry.skinIndices.length){Q.__skinVertexAArray=new Float32Array(P*4);Q.__skinVertexBArray=new Float32Array(P*4);Q.__skinIndexArray=new Float32Array(P*4);Q.__skinWeightArray=new Float32Array(P*4)}Q.__faceArray=new Uint16Array(Z*3);Q.__lineArray=new Uint16Array(Y*2);var U=void 0,ha=void 0;if(Q.numMorphTargets){Q.__morphTargetsArrays=[];U=0;for(ha=Q.numMorphTargets;U<ha;U++)Q.__morphTargetsArrays.push(new Float32Array(P*3))}if(Q.numMorphNormals){Q.__morphNormalsArrays=
  22621. [];U=0;for(ha=Q.numMorphNormals;U<ha;U++)Q.__morphNormalsArrays.push(new Float32Array(P*3))}Q.__webglFaceCount=Z*3;Q.__webglLineCount=Y*2;if(R.attributes){if(Q.__webglCustomAttributesList===void 0)Q.__webglCustomAttributesList=[];var Ra=void 0;for(Ra in R.attributes){var Ma=R.attributes[Ra],aa={},Ka;for(Ka in Ma)aa[Ka]=Ma[Ka];if(!aa.__webglInitialized||aa.createUniqueBuffers){aa.__webglInitialized=true;var La=1;aa.type==="v2"?La=2:aa.type==="v3"?La=3:aa.type==="v4"?La=4:aa.type==="c"&&(La=3);aa.size=
  22622. La;aa.array=new Float32Array(P*La);aa.buffer=i.createBuffer();aa.buffer.belongsToAttribute=Ra;Ma.needsUpdate=true;aa.__original=Ma}Q.__webglCustomAttributesList.push(aa)}}Q.__inittedArrays=true;j.verticesNeedUpdate=true;j.morphTargetsNeedUpdate=true;j.elementsNeedUpdate=true;j.uvsNeedUpdate=true;j.normalsNeedUpdate=true;j.tangetsNeedUpdate=true;j.colorsNeedUpdate=true}}}}else if(g instanceof THREE.Ribbon){j=g.geometry;if(!j.__webglVertexBuffer){var Sa=j;Sa.__webglVertexBuffer=i.createBuffer();Sa.__webglColorBuffer=
  22623. i.createBuffer();G.info.memory.geometries++;var oa=j,xa=oa.vertices.length;oa.__vertexArray=new Float32Array(xa*3);oa.__colorArray=new Float32Array(xa*3);oa.__webglVertexCount=xa;j.verticesNeedUpdate=true;j.colorsNeedUpdate=true}}else if(g instanceof THREE.Line){j=g.geometry;if(!j.__webglVertexBuffer){var Ba=j;Ba.__webglVertexBuffer=i.createBuffer();Ba.__webglColorBuffer=i.createBuffer();G.info.memory.geometries++;var Na=j,Ta=g,Wa=Na.vertices.length;Na.__vertexArray=new Float32Array(Wa*3);Na.__colorArray=
  22624. new Float32Array(Wa*3);Na.__webglLineCount=Wa;b(Na,Ta);j.verticesNeedUpdate=true;j.colorsNeedUpdate=true}}else if(g instanceof THREE.ParticleSystem){j=g.geometry;if(!j.__webglVertexBuffer){var $a=j;$a.__webglVertexBuffer=i.createBuffer();$a.__webglColorBuffer=i.createBuffer();G.info.geometries++;var Qa=j,Kb=g,lb=Qa.vertices.length;Qa.__vertexArray=new Float32Array(lb*3);Qa.__colorArray=new Float32Array(lb*3);Qa.__sortArray=[];Qa.__webglParticleCount=lb;b(Qa,Kb);j.verticesNeedUpdate=true;j.colorsNeedUpdate=
  22625. true}}}if(!g.__webglActive){if(g instanceof THREE.Mesh){j=g.geometry;if(j instanceof THREE.BufferGeometry)l(h.__webglObjects,j,g);else for(k in j.geometryGroups){n=j.geometryGroups[k];l(h.__webglObjects,n,g)}}else if(g instanceof THREE.Ribbon||g instanceof THREE.Line||g instanceof THREE.ParticleSystem){j=g.geometry;l(h.__webglObjects,j,g)}else g instanceof THREE.ImmediateRenderObject||g.immediateRenderCallback?h.__webglObjectsImmediate.push({object:g,opaque:null,transparent:null}):g instanceof THREE.Sprite?
  22626. h.__webglSprites.push(g):g instanceof THREE.LensFlare&&h.__webglFlares.push(g);g.__webglActive=true}a.__objectsAdded.splice(0,1)}for(;a.__objectsRemoved.length;){var bb=a.__objectsRemoved[0],gb=a;bb instanceof THREE.Mesh||bb instanceof THREE.ParticleSystem||bb instanceof THREE.Ribbon||bb instanceof THREE.Line?o(gb.__webglObjects,bb):bb instanceof THREE.Sprite?q(gb.__webglSprites,bb):bb instanceof THREE.LensFlare?q(gb.__webglFlares,bb):(bb instanceof THREE.ImmediateRenderObject||bb.immediateRenderCallback)&&
  22627. o(gb.__webglObjectsImmediate,bb);bb.__webglActive=false;a.__objectsRemoved.splice(0,1)}for(var ib=0,Lb=a.__webglObjects.length;ib<Lb;ib++){var jb=a.__webglObjects[ib].object,ga=jb.geometry,hb=void 0,ic=void 0,Ua=void 0;if(jb instanceof THREE.Mesh)if(ga instanceof THREE.BufferGeometry){ga.verticesNeedUpdate=false;ga.elementsNeedUpdate=false;ga.uvsNeedUpdate=false;ga.normalsNeedUpdate=false;ga.colorsNeedUpdate=false}else{for(var Cb=0,nd=ga.geometryGroupsList.length;Cb<nd;Cb++){hb=ga.geometryGroupsList[Cb];
  22628. Ua=c(jb,hb);ic=Ua.attributes&&p(Ua);if(ga.verticesNeedUpdate||ga.morphTargetsNeedUpdate||ga.elementsNeedUpdate||ga.uvsNeedUpdate||ga.normalsNeedUpdate||ga.colorsNeedUpdate||ga.tangetsNeedUpdate||ic){var ca=hb,od=jb,Xa=i.DYNAMIC_DRAW,pd=!ga.dynamic,bc=Ua;if(ca.__inittedArrays){var cd=d(bc),Tc=bc.vertexColors?bc.vertexColors:false,dd=e(bc),Ec=cd===THREE.SmoothShading,H=void 0,S=void 0,fb=void 0,N=void 0,jc=void 0,Ob=void 0,kb=void 0,Fc=void 0,Fb=void 0,kc=void 0,lc=void 0,V=void 0,W=void 0,X=void 0,
  22629. ma=void 0,mb=void 0,nb=void 0,ob=void 0,qc=void 0,pb=void 0,qb=void 0,rb=void 0,rc=void 0,sb=void 0,tb=void 0,ub=void 0,sc=void 0,vb=void 0,wb=void 0,xb=void 0,tc=void 0,yb=void 0,zb=void 0,Ab=void 0,uc=void 0,Pb=void 0,Qb=void 0,Rb=void 0,Gc=void 0,Sb=void 0,Tb=void 0,Ub=void 0,Hc=void 0,ja=void 0,ed=void 0,Vb=void 0,mc=void 0,nc=void 0,Ea=void 0,fd=void 0,Ca=void 0,Da=void 0,Wb=void 0,Gb=void 0,wa=0,Aa=0,Hb=0,Ib=0,cb=0,Ja=0,na=0,Oa=0,ya=0,L=0,ba=0,B=0,Ya=void 0,Fa=ca.__vertexArray,vc=ca.__uvArray,
  22630. wc=ca.__uv2Array,db=ca.__normalArray,qa=ca.__tangentArray,Ga=ca.__colorArray,ra=ca.__skinVertexAArray,sa=ca.__skinVertexBArray,ta=ca.__skinIndexArray,ua=ca.__skinWeightArray,Uc=ca.__morphTargetsArrays,Vc=ca.__morphNormalsArrays,Wc=ca.__webglCustomAttributesList,y=void 0,Bb=ca.__faceArray,Za=ca.__lineArray,Pa=od.geometry,qd=Pa.elementsNeedUpdate,gd=Pa.uvsNeedUpdate,rd=Pa.normalsNeedUpdate,sd=Pa.tangetsNeedUpdate,td=Pa.colorsNeedUpdate,ud=Pa.morphTargetsNeedUpdate,cc=Pa.vertices,ka=ca.faces3,la=ca.faces4,
  22631. za=Pa.faces,Xc=Pa.faceVertexUvs[0],Yc=Pa.faceVertexUvs[1],dc=Pa.skinVerticesA,ec=Pa.skinVerticesB,fc=Pa.skinIndices,Xb=Pa.skinWeights,Yb=Pa.morphTargets,Ic=Pa.morphNormals;if(Pa.verticesNeedUpdate){H=0;for(S=ka.length;H<S;H++){N=za[ka[H]];V=cc[N.a];W=cc[N.b];X=cc[N.c];Fa[Aa]=V.x;Fa[Aa+1]=V.y;Fa[Aa+2]=V.z;Fa[Aa+3]=W.x;Fa[Aa+4]=W.y;Fa[Aa+5]=W.z;Fa[Aa+6]=X.x;Fa[Aa+7]=X.y;Fa[Aa+8]=X.z;Aa=Aa+9}H=0;for(S=la.length;H<S;H++){N=za[la[H]];V=cc[N.a];W=cc[N.b];X=cc[N.c];ma=cc[N.d];Fa[Aa]=V.x;Fa[Aa+1]=V.y;Fa[Aa+
  22632. 2]=V.z;Fa[Aa+3]=W.x;Fa[Aa+4]=W.y;Fa[Aa+5]=W.z;Fa[Aa+6]=X.x;Fa[Aa+7]=X.y;Fa[Aa+8]=X.z;Fa[Aa+9]=ma.x;Fa[Aa+10]=ma.y;Fa[Aa+11]=ma.z;Aa=Aa+12}i.bindBuffer(i.ARRAY_BUFFER,ca.__webglVertexBuffer);i.bufferData(i.ARRAY_BUFFER,Fa,Xa)}if(ud){Ea=0;for(fd=Yb.length;Ea<fd;Ea++){H=ba=0;for(S=ka.length;H<S;H++){Wb=ka[H];N=za[Wb];V=Yb[Ea].vertices[N.a];W=Yb[Ea].vertices[N.b];X=Yb[Ea].vertices[N.c];Ca=Uc[Ea];Ca[ba]=V.x;Ca[ba+1]=V.y;Ca[ba+2]=V.z;Ca[ba+3]=W.x;Ca[ba+4]=W.y;Ca[ba+5]=W.z;Ca[ba+6]=X.x;Ca[ba+7]=X.y;Ca[ba+
  22633. 8]=X.z;if(bc.morphNormals){if(Ec){Gb=Ic[Ea].vertexNormals[Wb];pb=Gb.a;qb=Gb.b;rb=Gb.c}else rb=qb=pb=Ic[Ea].faceNormals[Wb];Da=Vc[Ea];Da[ba]=pb.x;Da[ba+1]=pb.y;Da[ba+2]=pb.z;Da[ba+3]=qb.x;Da[ba+4]=qb.y;Da[ba+5]=qb.z;Da[ba+6]=rb.x;Da[ba+7]=rb.y;Da[ba+8]=rb.z}ba=ba+9}H=0;for(S=la.length;H<S;H++){Wb=la[H];N=za[Wb];V=Yb[Ea].vertices[N.a];W=Yb[Ea].vertices[N.b];X=Yb[Ea].vertices[N.c];ma=Yb[Ea].vertices[N.d];Ca=Uc[Ea];Ca[ba]=V.x;Ca[ba+1]=V.y;Ca[ba+2]=V.z;Ca[ba+3]=W.x;Ca[ba+4]=W.y;Ca[ba+5]=W.z;Ca[ba+6]=X.x;
  22634. Ca[ba+7]=X.y;Ca[ba+8]=X.z;Ca[ba+9]=ma.x;Ca[ba+10]=ma.y;Ca[ba+11]=ma.z;if(bc.morphNormals){if(Ec){Gb=Ic[Ea].vertexNormals[Wb];pb=Gb.a;qb=Gb.b;rb=Gb.c;rc=Gb.d}else rc=rb=qb=pb=Ic[Ea].faceNormals[Wb];Da=Vc[Ea];Da[ba]=pb.x;Da[ba+1]=pb.y;Da[ba+2]=pb.z;Da[ba+3]=qb.x;Da[ba+4]=qb.y;Da[ba+5]=qb.z;Da[ba+6]=rb.x;Da[ba+7]=rb.y;Da[ba+8]=rb.z;Da[ba+9]=rc.x;Da[ba+10]=rc.y;Da[ba+11]=rc.z}ba=ba+12}i.bindBuffer(i.ARRAY_BUFFER,ca.__webglMorphTargetsBuffers[Ea]);i.bufferData(i.ARRAY_BUFFER,Uc[Ea],Xa);if(bc.morphNormals){i.bindBuffer(i.ARRAY_BUFFER,
  22635. ca.__webglMorphNormalsBuffers[Ea]);i.bufferData(i.ARRAY_BUFFER,Vc[Ea],Xa)}}}if(Xb.length){H=0;for(S=ka.length;H<S;H++){N=za[ka[H]];vb=Xb[N.a];wb=Xb[N.b];xb=Xb[N.c];ua[L]=vb.x;ua[L+1]=vb.y;ua[L+2]=vb.z;ua[L+3]=vb.w;ua[L+4]=wb.x;ua[L+5]=wb.y;ua[L+6]=wb.z;ua[L+7]=wb.w;ua[L+8]=xb.x;ua[L+9]=xb.y;ua[L+10]=xb.z;ua[L+11]=xb.w;yb=fc[N.a];zb=fc[N.b];Ab=fc[N.c];ta[L]=yb.x;ta[L+1]=yb.y;ta[L+2]=yb.z;ta[L+3]=yb.w;ta[L+4]=zb.x;ta[L+5]=zb.y;ta[L+6]=zb.z;ta[L+7]=zb.w;ta[L+8]=Ab.x;ta[L+9]=Ab.y;ta[L+10]=Ab.z;ta[L+11]=
  22636. Ab.w;Pb=dc[N.a];Qb=dc[N.b];Rb=dc[N.c];ra[L]=Pb.x;ra[L+1]=Pb.y;ra[L+2]=Pb.z;ra[L+3]=1;ra[L+4]=Qb.x;ra[L+5]=Qb.y;ra[L+6]=Qb.z;ra[L+7]=1;ra[L+8]=Rb.x;ra[L+9]=Rb.y;ra[L+10]=Rb.z;ra[L+11]=1;Sb=ec[N.a];Tb=ec[N.b];Ub=ec[N.c];sa[L]=Sb.x;sa[L+1]=Sb.y;sa[L+2]=Sb.z;sa[L+3]=1;sa[L+4]=Tb.x;sa[L+5]=Tb.y;sa[L+6]=Tb.z;sa[L+7]=1;sa[L+8]=Ub.x;sa[L+9]=Ub.y;sa[L+10]=Ub.z;sa[L+11]=1;L=L+12}H=0;for(S=la.length;H<S;H++){N=za[la[H]];vb=Xb[N.a];wb=Xb[N.b];xb=Xb[N.c];tc=Xb[N.d];ua[L]=vb.x;ua[L+1]=vb.y;ua[L+2]=vb.z;ua[L+3]=
  22637. vb.w;ua[L+4]=wb.x;ua[L+5]=wb.y;ua[L+6]=wb.z;ua[L+7]=wb.w;ua[L+8]=xb.x;ua[L+9]=xb.y;ua[L+10]=xb.z;ua[L+11]=xb.w;ua[L+12]=tc.x;ua[L+13]=tc.y;ua[L+14]=tc.z;ua[L+15]=tc.w;yb=fc[N.a];zb=fc[N.b];Ab=fc[N.c];uc=fc[N.d];ta[L]=yb.x;ta[L+1]=yb.y;ta[L+2]=yb.z;ta[L+3]=yb.w;ta[L+4]=zb.x;ta[L+5]=zb.y;ta[L+6]=zb.z;ta[L+7]=zb.w;ta[L+8]=Ab.x;ta[L+9]=Ab.y;ta[L+10]=Ab.z;ta[L+11]=Ab.w;ta[L+12]=uc.x;ta[L+13]=uc.y;ta[L+14]=uc.z;ta[L+15]=uc.w;Pb=dc[N.a];Qb=dc[N.b];Rb=dc[N.c];Gc=dc[N.d];ra[L]=Pb.x;ra[L+1]=Pb.y;ra[L+2]=Pb.z;
  22638. ra[L+3]=1;ra[L+4]=Qb.x;ra[L+5]=Qb.y;ra[L+6]=Qb.z;ra[L+7]=1;ra[L+8]=Rb.x;ra[L+9]=Rb.y;ra[L+10]=Rb.z;ra[L+11]=1;ra[L+12]=Gc.x;ra[L+13]=Gc.y;ra[L+14]=Gc.z;ra[L+15]=1;Sb=ec[N.a];Tb=ec[N.b];Ub=ec[N.c];Hc=ec[N.d];sa[L]=Sb.x;sa[L+1]=Sb.y;sa[L+2]=Sb.z;sa[L+3]=1;sa[L+4]=Tb.x;sa[L+5]=Tb.y;sa[L+6]=Tb.z;sa[L+7]=1;sa[L+8]=Ub.x;sa[L+9]=Ub.y;sa[L+10]=Ub.z;sa[L+11]=1;sa[L+12]=Hc.x;sa[L+13]=Hc.y;sa[L+14]=Hc.z;sa[L+15]=1;L=L+16}if(L>0){i.bindBuffer(i.ARRAY_BUFFER,ca.__webglSkinVertexABuffer);i.bufferData(i.ARRAY_BUFFER,
  22639. ra,Xa);i.bindBuffer(i.ARRAY_BUFFER,ca.__webglSkinVertexBBuffer);i.bufferData(i.ARRAY_BUFFER,sa,Xa);i.bindBuffer(i.ARRAY_BUFFER,ca.__webglSkinIndicesBuffer);i.bufferData(i.ARRAY_BUFFER,ta,Xa);i.bindBuffer(i.ARRAY_BUFFER,ca.__webglSkinWeightsBuffer);i.bufferData(i.ARRAY_BUFFER,ua,Xa)}}if(td&&Tc){H=0;for(S=ka.length;H<S;H++){N=za[ka[H]];kb=N.vertexColors;Fc=N.color;if(kb.length===3&&Tc===THREE.VertexColors){sb=kb[0];tb=kb[1];ub=kb[2]}else ub=tb=sb=Fc;Ga[ya]=sb.r;Ga[ya+1]=sb.g;Ga[ya+2]=sb.b;Ga[ya+3]=
  22640. tb.r;Ga[ya+4]=tb.g;Ga[ya+5]=tb.b;Ga[ya+6]=ub.r;Ga[ya+7]=ub.g;Ga[ya+8]=ub.b;ya=ya+9}H=0;for(S=la.length;H<S;H++){N=za[la[H]];kb=N.vertexColors;Fc=N.color;if(kb.length===4&&Tc===THREE.VertexColors){sb=kb[0];tb=kb[1];ub=kb[2];sc=kb[3]}else sc=ub=tb=sb=Fc;Ga[ya]=sb.r;Ga[ya+1]=sb.g;Ga[ya+2]=sb.b;Ga[ya+3]=tb.r;Ga[ya+4]=tb.g;Ga[ya+5]=tb.b;Ga[ya+6]=ub.r;Ga[ya+7]=ub.g;Ga[ya+8]=ub.b;Ga[ya+9]=sc.r;Ga[ya+10]=sc.g;Ga[ya+11]=sc.b;ya=ya+12}if(ya>0){i.bindBuffer(i.ARRAY_BUFFER,ca.__webglColorBuffer);i.bufferData(i.ARRAY_BUFFER,
  22641. Ga,Xa)}}if(sd&&Pa.hasTangents){H=0;for(S=ka.length;H<S;H++){N=za[ka[H]];Fb=N.vertexTangents;mb=Fb[0];nb=Fb[1];ob=Fb[2];qa[na]=mb.x;qa[na+1]=mb.y;qa[na+2]=mb.z;qa[na+3]=mb.w;qa[na+4]=nb.x;qa[na+5]=nb.y;qa[na+6]=nb.z;qa[na+7]=nb.w;qa[na+8]=ob.x;qa[na+9]=ob.y;qa[na+10]=ob.z;qa[na+11]=ob.w;na=na+12}H=0;for(S=la.length;H<S;H++){N=za[la[H]];Fb=N.vertexTangents;mb=Fb[0];nb=Fb[1];ob=Fb[2];qc=Fb[3];qa[na]=mb.x;qa[na+1]=mb.y;qa[na+2]=mb.z;qa[na+3]=mb.w;qa[na+4]=nb.x;qa[na+5]=nb.y;qa[na+6]=nb.z;qa[na+7]=nb.w;
  22642. qa[na+8]=ob.x;qa[na+9]=ob.y;qa[na+10]=ob.z;qa[na+11]=ob.w;qa[na+12]=qc.x;qa[na+13]=qc.y;qa[na+14]=qc.z;qa[na+15]=qc.w;na=na+16}i.bindBuffer(i.ARRAY_BUFFER,ca.__webglTangentBuffer);i.bufferData(i.ARRAY_BUFFER,qa,Xa)}if(rd&&cd){H=0;for(S=ka.length;H<S;H++){N=za[ka[H]];jc=N.vertexNormals;Ob=N.normal;if(jc.length===3&&Ec)for(ja=0;ja<3;ja++){Vb=jc[ja];db[Ja]=Vb.x;db[Ja+1]=Vb.y;db[Ja+2]=Vb.z;Ja=Ja+3}else for(ja=0;ja<3;ja++){db[Ja]=Ob.x;db[Ja+1]=Ob.y;db[Ja+2]=Ob.z;Ja=Ja+3}}H=0;for(S=la.length;H<S;H++){N=
  22643. za[la[H]];jc=N.vertexNormals;Ob=N.normal;if(jc.length===4&&Ec)for(ja=0;ja<4;ja++){Vb=jc[ja];db[Ja]=Vb.x;db[Ja+1]=Vb.y;db[Ja+2]=Vb.z;Ja=Ja+3}else for(ja=0;ja<4;ja++){db[Ja]=Ob.x;db[Ja+1]=Ob.y;db[Ja+2]=Ob.z;Ja=Ja+3}}i.bindBuffer(i.ARRAY_BUFFER,ca.__webglNormalBuffer);i.bufferData(i.ARRAY_BUFFER,db,Xa)}if(gd&&Xc&&dd){H=0;for(S=ka.length;H<S;H++){fb=ka[H];N=za[fb];kc=Xc[fb];if(kc!==void 0)for(ja=0;ja<3;ja++){mc=kc[ja];vc[Hb]=mc.u;vc[Hb+1]=mc.v;Hb=Hb+2}}H=0;for(S=la.length;H<S;H++){fb=la[H];N=za[fb];kc=
  22644. Xc[fb];if(kc!==void 0)for(ja=0;ja<4;ja++){mc=kc[ja];vc[Hb]=mc.u;vc[Hb+1]=mc.v;Hb=Hb+2}}if(Hb>0){i.bindBuffer(i.ARRAY_BUFFER,ca.__webglUVBuffer);i.bufferData(i.ARRAY_BUFFER,vc,Xa)}}if(gd&&Yc&&dd){H=0;for(S=ka.length;H<S;H++){fb=ka[H];N=za[fb];lc=Yc[fb];if(lc!==void 0)for(ja=0;ja<3;ja++){nc=lc[ja];wc[Ib]=nc.u;wc[Ib+1]=nc.v;Ib=Ib+2}}H=0;for(S=la.length;H<S;H++){fb=la[H];N=za[fb];lc=Yc[fb];if(lc!==void 0)for(ja=0;ja<4;ja++){nc=lc[ja];wc[Ib]=nc.u;wc[Ib+1]=nc.v;Ib=Ib+2}}if(Ib>0){i.bindBuffer(i.ARRAY_BUFFER,
  22645. ca.__webglUV2Buffer);i.bufferData(i.ARRAY_BUFFER,wc,Xa)}}if(qd){H=0;for(S=ka.length;H<S;H++){N=za[ka[H]];Bb[cb]=wa;Bb[cb+1]=wa+1;Bb[cb+2]=wa+2;cb=cb+3;Za[Oa]=wa;Za[Oa+1]=wa+1;Za[Oa+2]=wa;Za[Oa+3]=wa+2;Za[Oa+4]=wa+1;Za[Oa+5]=wa+2;Oa=Oa+6;wa=wa+3}H=0;for(S=la.length;H<S;H++){N=za[la[H]];Bb[cb]=wa;Bb[cb+1]=wa+1;Bb[cb+2]=wa+3;Bb[cb+3]=wa+1;Bb[cb+4]=wa+2;Bb[cb+5]=wa+3;cb=cb+6;Za[Oa]=wa;Za[Oa+1]=wa+1;Za[Oa+2]=wa;Za[Oa+3]=wa+3;Za[Oa+4]=wa+1;Za[Oa+5]=wa+2;Za[Oa+6]=wa+2;Za[Oa+7]=wa+3;Oa=Oa+8;wa=wa+4}i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,
  22646. ca.__webglFaceBuffer);i.bufferData(i.ELEMENT_ARRAY_BUFFER,Bb,Xa);i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,ca.__webglLineBuffer);i.bufferData(i.ELEMENT_ARRAY_BUFFER,Za,Xa)}if(Wc){ja=0;for(ed=Wc.length;ja<ed;ja++){y=Wc[ja];if(y.__original.needsUpdate){B=0;if(y.size===1)if(y.boundTo===void 0||y.boundTo==="vertices"){H=0;for(S=ka.length;H<S;H++){N=za[ka[H]];y.array[B]=y.value[N.a];y.array[B+1]=y.value[N.b];y.array[B+2]=y.value[N.c];B=B+3}H=0;for(S=la.length;H<S;H++){N=za[la[H]];y.array[B]=y.value[N.a];y.array[B+
  22647. 1]=y.value[N.b];y.array[B+2]=y.value[N.c];y.array[B+3]=y.value[N.d];B=B+4}}else{if(y.boundTo==="faces"){H=0;for(S=ka.length;H<S;H++){Ya=y.value[ka[H]];y.array[B]=Ya;y.array[B+1]=Ya;y.array[B+2]=Ya;B=B+3}H=0;for(S=la.length;H<S;H++){Ya=y.value[la[H]];y.array[B]=Ya;y.array[B+1]=Ya;y.array[B+2]=Ya;y.array[B+3]=Ya;B=B+4}}}else if(y.size===2)if(y.boundTo===void 0||y.boundTo==="vertices"){H=0;for(S=ka.length;H<S;H++){N=za[ka[H]];V=y.value[N.a];W=y.value[N.b];X=y.value[N.c];y.array[B]=V.x;y.array[B+1]=V.y;
  22648. y.array[B+2]=W.x;y.array[B+3]=W.y;y.array[B+4]=X.x;y.array[B+5]=X.y;B=B+6}H=0;for(S=la.length;H<S;H++){N=za[la[H]];V=y.value[N.a];W=y.value[N.b];X=y.value[N.c];ma=y.value[N.d];y.array[B]=V.x;y.array[B+1]=V.y;y.array[B+2]=W.x;y.array[B+3]=W.y;y.array[B+4]=X.x;y.array[B+5]=X.y;y.array[B+6]=ma.x;y.array[B+7]=ma.y;B=B+8}}else{if(y.boundTo==="faces"){H=0;for(S=ka.length;H<S;H++){X=W=V=Ya=y.value[ka[H]];y.array[B]=V.x;y.array[B+1]=V.y;y.array[B+2]=W.x;y.array[B+3]=W.y;y.array[B+4]=X.x;y.array[B+5]=X.y;
  22649. B=B+6}H=0;for(S=la.length;H<S;H++){ma=X=W=V=Ya=y.value[la[H]];y.array[B]=V.x;y.array[B+1]=V.y;y.array[B+2]=W.x;y.array[B+3]=W.y;y.array[B+4]=X.x;y.array[B+5]=X.y;y.array[B+6]=ma.x;y.array[B+7]=ma.y;B=B+8}}}else if(y.size===3){var da;da=y.type==="c"?["r","g","b"]:["x","y","z"];if(y.boundTo===void 0||y.boundTo==="vertices"){H=0;for(S=ka.length;H<S;H++){N=za[ka[H]];V=y.value[N.a];W=y.value[N.b];X=y.value[N.c];y.array[B]=V[da[0]];y.array[B+1]=V[da[1]];y.array[B+2]=V[da[2]];y.array[B+3]=W[da[0]];y.array[B+
  22650. 4]=W[da[1]];y.array[B+5]=W[da[2]];y.array[B+6]=X[da[0]];y.array[B+7]=X[da[1]];y.array[B+8]=X[da[2]];B=B+9}H=0;for(S=la.length;H<S;H++){N=za[la[H]];V=y.value[N.a];W=y.value[N.b];X=y.value[N.c];ma=y.value[N.d];y.array[B]=V[da[0]];y.array[B+1]=V[da[1]];y.array[B+2]=V[da[2]];y.array[B+3]=W[da[0]];y.array[B+4]=W[da[1]];y.array[B+5]=W[da[2]];y.array[B+6]=X[da[0]];y.array[B+7]=X[da[1]];y.array[B+8]=X[da[2]];y.array[B+9]=ma[da[0]];y.array[B+10]=ma[da[1]];y.array[B+11]=ma[da[2]];B=B+12}}else if(y.boundTo===
  22651. "faces"){H=0;for(S=ka.length;H<S;H++){X=W=V=Ya=y.value[ka[H]];y.array[B]=V[da[0]];y.array[B+1]=V[da[1]];y.array[B+2]=V[da[2]];y.array[B+3]=W[da[0]];y.array[B+4]=W[da[1]];y.array[B+5]=W[da[2]];y.array[B+6]=X[da[0]];y.array[B+7]=X[da[1]];y.array[B+8]=X[da[2]];B=B+9}H=0;for(S=la.length;H<S;H++){ma=X=W=V=Ya=y.value[la[H]];y.array[B]=V[da[0]];y.array[B+1]=V[da[1]];y.array[B+2]=V[da[2]];y.array[B+3]=W[da[0]];y.array[B+4]=W[da[1]];y.array[B+5]=W[da[2]];y.array[B+6]=X[da[0]];y.array[B+7]=X[da[1]];y.array[B+
  22652. 8]=X[da[2]];y.array[B+9]=ma[da[0]];y.array[B+10]=ma[da[1]];y.array[B+11]=ma[da[2]];B=B+12}}}else if(y.size===4)if(y.boundTo===void 0||y.boundTo==="vertices"){H=0;for(S=ka.length;H<S;H++){N=za[ka[H]];V=y.value[N.a];W=y.value[N.b];X=y.value[N.c];y.array[B]=V.x;y.array[B+1]=V.y;y.array[B+2]=V.z;y.array[B+3]=V.w;y.array[B+4]=W.x;y.array[B+5]=W.y;y.array[B+6]=W.z;y.array[B+7]=W.w;y.array[B+8]=X.x;y.array[B+9]=X.y;y.array[B+10]=X.z;y.array[B+11]=X.w;B=B+12}H=0;for(S=la.length;H<S;H++){N=za[la[H]];V=y.value[N.a];
  22653. W=y.value[N.b];X=y.value[N.c];ma=y.value[N.d];y.array[B]=V.x;y.array[B+1]=V.y;y.array[B+2]=V.z;y.array[B+3]=V.w;y.array[B+4]=W.x;y.array[B+5]=W.y;y.array[B+6]=W.z;y.array[B+7]=W.w;y.array[B+8]=X.x;y.array[B+9]=X.y;y.array[B+10]=X.z;y.array[B+11]=X.w;y.array[B+12]=ma.x;y.array[B+13]=ma.y;y.array[B+14]=ma.z;y.array[B+15]=ma.w;B=B+16}}else if(y.boundTo==="faces"){H=0;for(S=ka.length;H<S;H++){X=W=V=Ya=y.value[ka[H]];y.array[B]=V.x;y.array[B+1]=V.y;y.array[B+2]=V.z;y.array[B+3]=V.w;y.array[B+4]=W.x;y.array[B+
  22654. 5]=W.y;y.array[B+6]=W.z;y.array[B+7]=W.w;y.array[B+8]=X.x;y.array[B+9]=X.y;y.array[B+10]=X.z;y.array[B+11]=X.w;B=B+12}H=0;for(S=la.length;H<S;H++){ma=X=W=V=Ya=y.value[la[H]];y.array[B]=V.x;y.array[B+1]=V.y;y.array[B+2]=V.z;y.array[B+3]=V.w;y.array[B+4]=W.x;y.array[B+5]=W.y;y.array[B+6]=W.z;y.array[B+7]=W.w;y.array[B+8]=X.x;y.array[B+9]=X.y;y.array[B+10]=X.z;y.array[B+11]=X.w;y.array[B+12]=ma.x;y.array[B+13]=ma.y;y.array[B+14]=ma.z;y.array[B+15]=ma.w;B=B+16}}i.bindBuffer(i.ARRAY_BUFFER,y.buffer);i.bufferData(i.ARRAY_BUFFER,
  22655. y.array,Xa)}}}if(pd){delete ca.__inittedArrays;delete ca.__colorArray;delete ca.__normalArray;delete ca.__tangentArray;delete ca.__uvArray;delete ca.__uv2Array;delete ca.__faceArray;delete ca.__vertexArray;delete ca.__lineArray;delete ca.__skinVertexAArray;delete ca.__skinVertexBArray;delete ca.__skinIndexArray;delete ca.__skinWeightArray}}}}ga.verticesNeedUpdate=false;ga.morphTargetsNeedUpdate=false;ga.elementsNeedUpdate=false;ga.uvsNeedUpdate=false;ga.normalsNeedUpdate=false;ga.colorsNeedUpdate=
  22656. false;ga.tangetsNeedUpdate=false;Ua.attributes&&m(Ua)}else if(jb instanceof THREE.Ribbon){if(ga.verticesNeedUpdate||ga.colorsNeedUpdate){var Zb=ga,hd=i.DYNAMIC_DRAW,xc=void 0,yc=void 0,Jc=void 0,$b=void 0,Kc=void 0,id=Zb.vertices,jd=Zb.colors,vd=id.length,wd=jd.length,Lc=Zb.__vertexArray,Mc=Zb.__colorArray,xd=Zb.colorsNeedUpdate;if(Zb.verticesNeedUpdate){for(xc=0;xc<vd;xc++){Jc=id[xc];$b=xc*3;Lc[$b]=Jc.x;Lc[$b+1]=Jc.y;Lc[$b+2]=Jc.z}i.bindBuffer(i.ARRAY_BUFFER,Zb.__webglVertexBuffer);i.bufferData(i.ARRAY_BUFFER,
  22657. Lc,hd)}if(xd){for(yc=0;yc<wd;yc++){Kc=jd[yc];$b=yc*3;Mc[$b]=Kc.r;Mc[$b+1]=Kc.g;Mc[$b+2]=Kc.b}i.bindBuffer(i.ARRAY_BUFFER,Zb.__webglColorBuffer);i.bufferData(i.ARRAY_BUFFER,Mc,hd)}}ga.verticesNeedUpdate=false;ga.colorsNeedUpdate=false}else if(jb instanceof THREE.Line){Ua=c(jb,hb);ic=Ua.attributes&&p(Ua);if(ga.verticesNeedUpdate||ga.colorsNeedUpdate||ic){var Jb=ga,Zc=i.DYNAMIC_DRAW,zc=void 0,Ac=void 0,Nc=void 0,va=void 0,Oc=void 0,kd=Jb.vertices,ld=Jb.colors,yd=kd.length,zd=ld.length,Pc=Jb.__vertexArray,
  22658. Qc=Jb.__colorArray,Ad=Jb.colorsNeedUpdate,$c=Jb.__webglCustomAttributesList,Rc=void 0,md=void 0,Ia=void 0,oc=void 0,Va=void 0,pa=void 0;if(Jb.verticesNeedUpdate){for(zc=0;zc<yd;zc++){Nc=kd[zc];va=zc*3;Pc[va]=Nc.x;Pc[va+1]=Nc.y;Pc[va+2]=Nc.z}i.bindBuffer(i.ARRAY_BUFFER,Jb.__webglVertexBuffer);i.bufferData(i.ARRAY_BUFFER,Pc,Zc)}if(Ad){for(Ac=0;Ac<zd;Ac++){Oc=ld[Ac];va=Ac*3;Qc[va]=Oc.r;Qc[va+1]=Oc.g;Qc[va+2]=Oc.b}i.bindBuffer(i.ARRAY_BUFFER,Jb.__webglColorBuffer);i.bufferData(i.ARRAY_BUFFER,Qc,Zc)}if($c){Rc=
  22659. 0;for(md=$c.length;Rc<md;Rc++){pa=$c[Rc];if(pa.needsUpdate&&(pa.boundTo===void 0||pa.boundTo==="vertices")){va=0;oc=pa.value.length;if(pa.size===1)for(Ia=0;Ia<oc;Ia++)pa.array[Ia]=pa.value[Ia];else if(pa.size===2)for(Ia=0;Ia<oc;Ia++){Va=pa.value[Ia];pa.array[va]=Va.x;pa.array[va+1]=Va.y;va=va+2}else if(pa.size===3)if(pa.type==="c")for(Ia=0;Ia<oc;Ia++){Va=pa.value[Ia];pa.array[va]=Va.r;pa.array[va+1]=Va.g;pa.array[va+2]=Va.b;va=va+3}else for(Ia=0;Ia<oc;Ia++){Va=pa.value[Ia];pa.array[va]=Va.x;pa.array[va+
  22660. 1]=Va.y;pa.array[va+2]=Va.z;va=va+3}else if(pa.size===4)for(Ia=0;Ia<oc;Ia++){Va=pa.value[Ia];pa.array[va]=Va.x;pa.array[va+1]=Va.y;pa.array[va+2]=Va.z;pa.array[va+3]=Va.w;va=va+4}i.bindBuffer(i.ARRAY_BUFFER,pa.buffer);i.bufferData(i.ARRAY_BUFFER,pa.array,Zc)}}}}ga.verticesNeedUpdate=false;ga.colorsNeedUpdate=false;Ua.attributes&&m(Ua)}else if(jb instanceof THREE.ParticleSystem){Ua=c(jb,hb);ic=Ua.attributes&&p(Ua);(ga.verticesNeedUpdate||ga.colorsNeedUpdate||jb.sortParticles||ic)&&f(ga,i.DYNAMIC_DRAW,
  22661. jb);ga.verticesNeedUpdate=false;ga.colorsNeedUpdate=false;Ua.attributes&&m(Ua)}}};this.initMaterial=function(a,b,c,d){var e,f,g;a instanceof THREE.MeshDepthMaterial?g="depth":a instanceof THREE.MeshNormalMaterial?g="normal":a instanceof THREE.MeshBasicMaterial?g="basic":a instanceof THREE.MeshLambertMaterial?g="lambert":a instanceof THREE.MeshPhongMaterial?g="phong":a instanceof THREE.LineBasicMaterial?g="basic":a instanceof THREE.ParticleBasicMaterial&&(g="particle_basic");if(g){var h=THREE.ShaderLib[g];
  22662. a.uniforms=THREE.UniformsUtils.clone(h.uniforms);a.vertexShader=h.vertexShader;a.fragmentShader=h.fragmentShader}var k,j,l,m,n;k=m=n=h=0;for(j=b.length;k<j;k++){l=b[k];if(!l.onlyShadow){l instanceof THREE.DirectionalLight&&m++;l instanceof THREE.PointLight&&n++;l instanceof THREE.SpotLight&&h++}}if(n+h+m<=M){j=m;l=n;m=h}else{j=Math.ceil(M*m/(n+m));m=l=M-j}var o=0,h=0;for(n=b.length;h<n;h++){k=b[h];if(k.castShadow){k instanceof THREE.SpotLight&&o++;k instanceof THREE.DirectionalLight&&!k.shadowCascade&&
  22663. o++}}var p=50;if(d!==void 0&&d instanceof THREE.SkinnedMesh)p=d.bones.length;var q;a:{n=a.fragmentShader;k=a.vertexShader;var h=a.uniforms,b=a.attributes,c={map:!!a.map,envMap:!!a.envMap,lightMap:!!a.lightMap,vertexColors:a.vertexColors,fog:c,useFog:a.fog,sizeAttenuation:a.sizeAttenuation,skinning:a.skinning,maxBones:p,morphTargets:a.morphTargets,morphNormals:a.morphNormals,maxMorphTargets:this.maxMorphTargets,maxMorphNormals:this.maxMorphNormals,maxDirLights:j,maxPointLights:l,maxSpotLights:m,maxShadows:o,
  22664. shadowMapEnabled:this.shadowMapEnabled&&d.receiveShadow,shadowMapSoft:this.shadowMapSoft,shadowMapDebug:this.shadowMapDebug,shadowMapCascade:this.shadowMapCascade,alphaTest:a.alphaTest,metal:a.metal,perPixel:a.perPixel,wrapAround:a.wrapAround,doubleSided:d&&d.doubleSided},r,d=[];if(g)d.push(g);else{d.push(n);d.push(k)}for(r in c){d.push(r);d.push(c[r])}g=d.join();r=0;for(d=T.length;r<d;r++)if(T[r].code===g){q=T[r].program;break a}r=i.createProgram();d=["precision "+z+" float;",oa>0?"#define VERTEX_TEXTURES":
  22665. "",G.gammaInput?"#define GAMMA_INPUT":"",G.gammaOutput?"#define GAMMA_OUTPUT":"",G.physicallyBasedShading?"#define PHYSICALLY_BASED_SHADING":"","#define MAX_DIR_LIGHTS "+c.maxDirLights,"#define MAX_POINT_LIGHTS "+c.maxPointLights,"#define MAX_SPOT_LIGHTS "+c.maxSpotLights,"#define MAX_SHADOWS "+c.maxShadows,"#define MAX_BONES "+c.maxBones,c.map?"#define USE_MAP":"",c.envMap?"#define USE_ENVMAP":"",c.lightMap?"#define USE_LIGHTMAP":"",c.vertexColors?"#define USE_COLOR":"",c.skinning?"#define USE_SKINNING":
  22666. "",c.morphTargets?"#define USE_MORPHTARGETS":"",c.morphNormals?"#define USE_MORPHNORMALS":"",c.perPixel?"#define PHONG_PER_PIXEL":"",c.wrapAround?"#define WRAP_AROUND":"",c.doubleSided?"#define DOUBLE_SIDED":"",c.shadowMapEnabled?"#define USE_SHADOWMAP":"",c.shadowMapSoft?"#define SHADOWMAP_SOFT":"",c.shadowMapDebug?"#define SHADOWMAP_DEBUG":"",c.shadowMapCascade?"#define SHADOWMAP_CASCADE":"",c.sizeAttenuation?"#define USE_SIZEATTENUATION":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\nattribute vec2 uv2;\n#ifdef USE_COLOR\nattribute vec3 color;\n#endif\n#ifdef USE_MORPHTARGETS\nattribute vec3 morphTarget0;\nattribute vec3 morphTarget1;\nattribute vec3 morphTarget2;\nattribute vec3 morphTarget3;\n#ifdef USE_MORPHNORMALS\nattribute vec3 morphNormal0;\nattribute vec3 morphNormal1;\nattribute vec3 morphNormal2;\nattribute vec3 morphNormal3;\n#else\nattribute vec3 morphTarget4;\nattribute vec3 morphTarget5;\nattribute vec3 morphTarget6;\nattribute vec3 morphTarget7;\n#endif\n#endif\n#ifdef USE_SKINNING\nattribute vec4 skinVertexA;\nattribute vec4 skinVertexB;\nattribute vec4 skinIndex;\nattribute vec4 skinWeight;\n#endif\n"].join("\n");
  22667. j=["precision "+z+" float;","#define MAX_DIR_LIGHTS "+c.maxDirLights,"#define MAX_POINT_LIGHTS "+c.maxPointLights,"#define MAX_SPOT_LIGHTS "+c.maxSpotLights,"#define MAX_SHADOWS "+c.maxShadows,c.alphaTest?"#define ALPHATEST "+c.alphaTest:"",G.gammaInput?"#define GAMMA_INPUT":"",G.gammaOutput?"#define GAMMA_OUTPUT":"",G.physicallyBasedShading?"#define PHYSICALLY_BASED_SHADING":"",c.useFog&&c.fog?"#define USE_FOG":"",c.useFog&&c.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",c.map?"#define USE_MAP":
  22668. "",c.envMap?"#define USE_ENVMAP":"",c.lightMap?"#define USE_LIGHTMAP":"",c.vertexColors?"#define USE_COLOR":"",c.metal?"#define METAL":"",c.perPixel?"#define PHONG_PER_PIXEL":"",c.wrapAround?"#define WRAP_AROUND":"",c.doubleSided?"#define DOUBLE_SIDED":"",c.shadowMapEnabled?"#define USE_SHADOWMAP":"",c.shadowMapSoft?"#define SHADOWMAP_SOFT":"",c.shadowMapDebug?"#define SHADOWMAP_DEBUG":"",c.shadowMapCascade?"#define SHADOWMAP_CASCADE":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");
  22669. i.attachShader(r,t("fragment",j+n));i.attachShader(r,t("vertex",d+k));i.linkProgram(r);i.getProgramParameter(r,i.LINK_STATUS)||console.error("Could not initialise shader\nVALIDATE_STATUS: "+i.getProgramParameter(r,i.VALIDATE_STATUS)+", gl error ["+i.getError()+"]");r.uniforms={};r.attributes={};var s,d=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","boneGlobalMatrices","morphTargetInfluences"];for(s in h)d.push(s);s=d;d=0;for(h=s.length;d<h;d++){n=
  22670. s[d];r.uniforms[n]=i.getUniformLocation(r,n)}d=["position","normal","uv","uv2","tangent","color","skinVertexA","skinVertexB","skinIndex","skinWeight"];for(s=0;s<c.maxMorphTargets;s++)d.push("morphTarget"+s);for(s=0;s<c.maxMorphNormals;s++)d.push("morphNormal"+s);for(q in b)d.push(q);q=d;s=0;for(b=q.length;s<b;s++){c=q[s];r.attributes[c]=i.getAttribLocation(r,c)}r.id=T.length;T.push({program:r,code:g});G.info.memory.programs=T.length;q=r}a.program=q;q=a.program.attributes;q.position>=0&&i.enableVertexAttribArray(q.position);
  22671. q.color>=0&&i.enableVertexAttribArray(q.color);q.normal>=0&&i.enableVertexAttribArray(q.normal);q.tangent>=0&&i.enableVertexAttribArray(q.tangent);if(a.skinning&&q.skinVertexA>=0&&q.skinVertexB>=0&&q.skinIndex>=0&&q.skinWeight>=0){i.enableVertexAttribArray(q.skinVertexA);i.enableVertexAttribArray(q.skinVertexB);i.enableVertexAttribArray(q.skinIndex);i.enableVertexAttribArray(q.skinWeight)}if(a.attributes)for(f in a.attributes)q[f]!==void 0&&q[f]>=0&&i.enableVertexAttribArray(q[f]);if(a.morphTargets){a.numSupportedMorphTargets=
  22672. 0;r="morphTarget";for(f=0;f<this.maxMorphTargets;f++){s=r+f;if(q[s]>=0){i.enableVertexAttribArray(q[s]);a.numSupportedMorphTargets++}}}if(a.morphNormals){a.numSupportedMorphNormals=0;r="morphNormal";for(f=0;f<this.maxMorphNormals;f++){s=r+f;if(q[s]>=0){i.enableVertexAttribArray(q[s]);a.numSupportedMorphNormals++}}}a.uniformsList=[];for(e in a.uniforms)a.uniformsList.push([a.uniforms[e],e])};this.setFaceCulling=function(a,b){if(a){!b||b==="ccw"?i.frontFace(i.CCW):i.frontFace(i.CW);a==="back"?i.cullFace(i.BACK):
  22673. a==="front"?i.cullFace(i.FRONT):i.cullFace(i.FRONT_AND_BACK);i.enable(i.CULL_FACE)}else i.disable(i.CULL_FACE)};this.setObjectFaces=function(a){if(ia!==a.doubleSided){a.doubleSided?i.disable(i.CULL_FACE):i.enable(i.CULL_FACE);ia=a.doubleSided}if(O!==a.flipSided){a.flipSided?i.frontFace(i.CW):i.frontFace(i.CCW);O=a.flipSided}};this.setDepthTest=function(a){if(Ma!==a){a?i.enable(i.DEPTH_TEST):i.disable(i.DEPTH_TEST);Ma=a}};this.setDepthWrite=function(a){if(Ka!==a){i.depthMask(a);Ka=a}};this.setBlending=
  22674. function(a,b,c,d){if(a!==Q){switch(a){case THREE.NoBlending:i.disable(i.BLEND);break;case THREE.AdditiveBlending:i.enable(i.BLEND);i.blendEquation(i.FUNC_ADD);i.blendFunc(i.SRC_ALPHA,i.ONE);break;case THREE.SubtractiveBlending:i.enable(i.BLEND);i.blendEquation(i.FUNC_ADD);i.blendFunc(i.ZERO,i.ONE_MINUS_SRC_COLOR);break;case THREE.MultiplyBlending:i.enable(i.BLEND);i.blendEquation(i.FUNC_ADD);i.blendFunc(i.ZERO,i.SRC_COLOR);break;case THREE.CustomBlending:i.enable(i.BLEND);break;default:i.enable(i.BLEND);
  22675. i.blendEquationSeparate(i.FUNC_ADD,i.FUNC_ADD);i.blendFuncSeparate(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA)}Q=a}if(a===THREE.CustomBlending){if(b!==Z){i.blendEquation(F(b));Z=b}if(c!==$||d!==ha){i.blendFunc(F(c),F(d));$=c;ha=d}}else ha=$=Z=null};this.setTexture=function(a,b){if(a.needsUpdate){if(!a.__webglInit){a.__webglInit=true;a.__webglTexture=i.createTexture();G.info.memory.textures++}i.activeTexture(i.TEXTURE0+b);i.bindTexture(i.TEXTURE_2D,a.__webglTexture);i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,
  22676. a.premultiplyAlpha);var c=a.image,d=(c.width&c.width-1)===0&&(c.height&c.height-1)===0,e=F(a.format),f=F(a.type);w(i.TEXTURE_2D,a,d);a instanceof THREE.DataTexture?i.texImage2D(i.TEXTURE_2D,0,e,c.width,c.height,0,e,f,c.data):i.texImage2D(i.TEXTURE_2D,0,e,e,f,a.image);a.generateMipmaps&&d&&i.generateMipmap(i.TEXTURE_2D);a.needsUpdate=false;if(a.onUpdate)a.onUpdate()}else{i.activeTexture(i.TEXTURE0+b);i.bindTexture(i.TEXTURE_2D,a.__webglTexture)}};this.setRenderTarget=function(a){var b=a instanceof
  22677. THREE.WebGLRenderTargetCube;if(a&&!a.__webglFramebuffer){if(a.depthBuffer===void 0)a.depthBuffer=true;if(a.stencilBuffer===void 0)a.stencilBuffer=true;a.__webglTexture=i.createTexture();var c=(a.width&a.width-1)===0&&(a.height&a.height-1)===0,d=F(a.format),e=F(a.type);if(b){a.__webglFramebuffer=[];a.__webglRenderbuffer=[];i.bindTexture(i.TEXTURE_CUBE_MAP,a.__webglTexture);w(i.TEXTURE_CUBE_MAP,a,c);for(var f=0;f<6;f++){a.__webglFramebuffer[f]=i.createFramebuffer();a.__webglRenderbuffer[f]=i.createRenderbuffer();
  22678. i.texImage2D(i.TEXTURE_CUBE_MAP_POSITIVE_X+f,0,d,a.width,a.height,0,d,e,null);var g=a,h=i.TEXTURE_CUBE_MAP_POSITIVE_X+f;i.bindFramebuffer(i.FRAMEBUFFER,a.__webglFramebuffer[f]);i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,h,g.__webglTexture,0);s(a.__webglRenderbuffer[f],a)}c&&i.generateMipmap(i.TEXTURE_CUBE_MAP)}else{a.__webglFramebuffer=i.createFramebuffer();a.__webglRenderbuffer=i.createRenderbuffer();i.bindTexture(i.TEXTURE_2D,a.__webglTexture);w(i.TEXTURE_2D,a,c);i.texImage2D(i.TEXTURE_2D,
  22679. 0,d,a.width,a.height,0,d,e,null);d=i.TEXTURE_2D;i.bindFramebuffer(i.FRAMEBUFFER,a.__webglFramebuffer);i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,d,a.__webglTexture,0);s(a.__webglRenderbuffer,a);c&&i.generateMipmap(i.TEXTURE_2D)}b?i.bindTexture(i.TEXTURE_CUBE_MAP,null):i.bindTexture(i.TEXTURE_2D,null);i.bindRenderbuffer(i.RENDERBUFFER,null);i.bindFramebuffer(i.FRAMEBUFFER,null)}if(a){b=b?a.__webglFramebuffer[a.activeCubeFace]:a.__webglFramebuffer;c=a.width;a=a.height;e=d=0}else{b=null;
  22680. c=gb;a=Lb;d=Kb;e=lb}if(b!==C){i.bindFramebuffer(i.FRAMEBUFFER,b);i.viewport(d,e,c,a);C=b}hb=c;Cb=a};this.shadowMapPlugin=new THREE.ShadowMapPlugin;this.addPrePlugin(this.shadowMapPlugin);this.addPostPlugin(new THREE.SpritePlugin);this.addPostPlugin(new THREE.LensFlarePlugin)};
  22681. THREE.WebGLRenderTarget=function(a,b,c){this.width=a;this.height=b;c=c||{};this.wrapS=c.wrapS!==void 0?c.wrapS:THREE.ClampToEdgeWrapping;this.wrapT=c.wrapT!==void 0?c.wrapT:THREE.ClampToEdgeWrapping;this.magFilter=c.magFilter!==void 0?c.magFilter:THREE.LinearFilter;this.minFilter=c.minFilter!==void 0?c.minFilter:THREE.LinearMipMapLinearFilter;this.offset=new THREE.Vector2(0,0);this.repeat=new THREE.Vector2(1,1);this.format=c.format!==void 0?c.format:THREE.RGBAFormat;this.type=c.type!==void 0?c.type:
  22682. THREE.UnsignedByteType;this.depthBuffer=c.depthBuffer!==void 0?c.depthBuffer:true;this.stencilBuffer=c.stencilBuffer!==void 0?c.stencilBuffer:true;this.generateMipmaps=true};
  22683. THREE.WebGLRenderTarget.prototype.clone=function(){var a=new THREE.WebGLRenderTarget(this.width,this.height);a.wrapS=this.wrapS;a.wrapT=this.wrapT;a.magFilter=this.magFilter;a.minFilter=this.minFilter;a.offset.copy(this.offset);a.repeat.copy(this.repeat);a.format=this.format;a.type=this.type;a.depthBuffer=this.depthBuffer;a.stencilBuffer=this.stencilBuffer;return a};THREE.WebGLRenderTargetCube=function(a,b,c){THREE.WebGLRenderTarget.call(this,a,b,c);this.activeCubeFace=0};
  22684. THREE.WebGLRenderTargetCube.prototype=new THREE.WebGLRenderTarget;THREE.WebGLRenderTargetCube.prototype.constructor=THREE.WebGLRenderTargetCube;THREE.RenderableVertex=function(){this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.visible=true};THREE.RenderableVertex.prototype.copy=function(a){this.positionWorld.copy(a.positionWorld);this.positionScreen.copy(a.positionScreen)};
  22685. THREE.RenderableFace3=function(){this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableVertex;this.v3=new THREE.RenderableVertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];this.faceMaterial=this.material=null;this.uvs=[[]];this.z=null};
  22686. THREE.RenderableFace4=function(){this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableVertex;this.v3=new THREE.RenderableVertex;this.v4=new THREE.RenderableVertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];this.faceMaterial=this.material=null;this.uvs=[[]];this.z=null};THREE.RenderableObject=function(){this.z=this.object=null};
  22687. THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null};THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableVertex;this.material=null};
  22688. THREE.ColorUtils={adjustHSV:function(a,b,c,d){var e=THREE.ColorUtils.__hsv;THREE.ColorUtils.rgbToHsv(a,e);e.h=THREE.Math.clamp(e.h+b,0,1);e.s=THREE.Math.clamp(e.s+c,0,1);e.v=THREE.Math.clamp(e.v+d,0,1);a.setHSV(e.h,e.s,e.v)},rgbToHsv:function(a,b){var c=a.r,d=a.g,e=a.b,f=Math.max(Math.max(c,d),e),g=Math.min(Math.min(c,d),e);if(g===f)g=c=0;else{var h=f-g,g=h/f,c=(c===f?(d-e)/h:d===f?2+(e-c)/h:4+(c-d)/h)/6;c<0&&(c=c+1);c>1&&(c=c-1)}b===void 0&&(b={h:0,s:0,v:0});b.h=c;b.s=g;b.v=f;return b}};
  22689. THREE.ColorUtils.__hsv={h:0,s:0,v:0};
  22690. THREE.GeometryUtils={merge:function(a,b){for(var c,d,e=a.vertices.length,f=b instanceof THREE.Mesh?b.geometry:b,g=a.vertices,h=f.vertices,k=a.faces,j=f.faces,l=a.faceVertexUvs[0],p=f.faceVertexUvs[0],m={},o=0;o<a.materials.length;o++)m[a.materials[o].id]=o;if(b instanceof THREE.Mesh){b.matrixAutoUpdate&&b.updateMatrix();c=b.matrix;d=new THREE.Matrix4;d.extractRotation(c,b.scale)}for(var o=0,q=h.length;o<q;o++){var n=h[o].clone();c&&c.multiplyVector3(n);g.push(n)}o=0;for(q=j.length;o<q;o++){var g=
  22691. j[o],r,u,t=g.vertexNormals,w=g.vertexColors;g instanceof THREE.Face3?r=new THREE.Face3(g.a+e,g.b+e,g.c+e):g instanceof THREE.Face4&&(r=new THREE.Face4(g.a+e,g.b+e,g.c+e,g.d+e));r.normal.copy(g.normal);d&&d.multiplyVector3(r.normal);h=0;for(n=t.length;h<n;h++){u=t[h].clone();d&&d.multiplyVector3(u);r.vertexNormals.push(u)}r.color.copy(g.color);h=0;for(n=w.length;h<n;h++){u=w[h];r.vertexColors.push(u.clone())}if(g.materialIndex!==void 0){h=f.materials[g.materialIndex];n=h.id;w=m[n];if(w===void 0){w=
  22692. a.materials.length;m[n]=w;a.materials.push(h)}r.materialIndex=w}r.centroid.copy(g.centroid);c&&c.multiplyVector3(r.centroid);k.push(r)}o=0;for(q=p.length;o<q;o++){c=p[o];d=[];h=0;for(n=c.length;h<n;h++)d.push(new THREE.UV(c[h].u,c[h].v));l.push(d)}},clone:function(a){var b=new THREE.Geometry,c,d=a.vertices,e=a.faces,f=a.faceVertexUvs[0];if(a.materials)b.materials=a.materials.slice();a=0;for(c=d.length;a<c;a++)b.vertices.push(d[a].clone());a=0;for(c=e.length;a<c;a++)b.faces.push(e[a].clone());a=0;
  22693. for(c=f.length;a<c;a++){for(var d=f[a],e=[],g=0,h=d.length;g<h;g++)e.push(new THREE.UV(d[g].u,d[g].v));b.faceVertexUvs[0].push(e)}return b},randomPointInTriangle:function(a,b,c){var d,e,f,g=new THREE.Vector3,h=THREE.GeometryUtils.__v1;d=THREE.GeometryUtils.random();e=THREE.GeometryUtils.random();if(d+e>1){d=1-d;e=1-e}f=1-d-e;g.copy(a);g.multiplyScalar(d);h.copy(b);h.multiplyScalar(e);g.addSelf(h);h.copy(c);h.multiplyScalar(f);g.addSelf(h);return g},randomPointInFace:function(a,b,c){var d,e,f;if(a instanceof
  22694. THREE.Face3){d=b.vertices[a.a];e=b.vertices[a.b];f=b.vertices[a.c];return THREE.GeometryUtils.randomPointInTriangle(d,e,f)}if(a instanceof THREE.Face4){d=b.vertices[a.a];e=b.vertices[a.b];f=b.vertices[a.c];var b=b.vertices[a.d],g;if(c)if(a._area1&&a._area2){c=a._area1;g=a._area2}else{c=THREE.GeometryUtils.triangleArea(d,e,b);g=THREE.GeometryUtils.triangleArea(e,f,b);a._area1=c;a._area2=g}else{c=THREE.GeometryUtils.triangleArea(d,e,b);g=THREE.GeometryUtils.triangleArea(e,f,b)}return THREE.GeometryUtils.random()*
  22695. (c+g)<c?THREE.GeometryUtils.randomPointInTriangle(d,e,b):THREE.GeometryUtils.randomPointInTriangle(e,f,b)}},randomPointsInGeometry:function(a,b){function c(a){function b(c,d){if(d<c)return c;var e=c+Math.floor((d-c)/2);return j[e]>a?b(c,e-1):j[e]<a?b(e+1,d):e}return b(0,j.length-1)}var d,e,f=a.faces,g=a.vertices,h=f.length,k=0,j=[],l,p,m,o;for(e=0;e<h;e++){d=f[e];if(d instanceof THREE.Face3){l=g[d.a];p=g[d.b];m=g[d.c];d._area=THREE.GeometryUtils.triangleArea(l,p,m)}else if(d instanceof THREE.Face4){l=
  22696. g[d.a];p=g[d.b];m=g[d.c];o=g[d.d];d._area1=THREE.GeometryUtils.triangleArea(l,p,o);d._area2=THREE.GeometryUtils.triangleArea(p,m,o);d._area=d._area1+d._area2}k=k+d._area;j[e]=k}d=[];for(e=0;e<b;e++){g=THREE.GeometryUtils.random()*k;g=c(g);d[e]=THREE.GeometryUtils.randomPointInFace(f[g],a,true)}return d},triangleArea:function(a,b,c){var d,e=THREE.GeometryUtils.__v1;e.sub(a,b);d=e.length();e.sub(a,c);a=e.length();e.sub(b,c);c=e.length();b=0.5*(d+a+c);return Math.sqrt(b*(b-d)*(b-a)*(b-c))},center:function(a){a.computeBoundingBox();
  22697. var b=a.boundingBox,c=new THREE.Vector3;c.add(b.min,b.max);c.multiplyScalar(-0.5);a.applyMatrix((new THREE.Matrix4).makeTranslation(c.x,c.y,c.z));a.computeBoundingBox();return c},normalizeUVs:function(a){for(var a=a.faceVertexUvs[0],b=0,c=a.length;b<c;b++)for(var d=a[b],e=0,f=d.length;e<f;e++){if(d[e].u!==1)d[e].u=d[e].u-Math.floor(d[e].u);if(d[e].v!==1)d[e].v=d[e].v-Math.floor(d[e].v)}},triangulateQuads:function(a){var b,c,d,e,f=[],g=[],h=[];b=0;for(c=a.faceUvs.length;b<c;b++)g[b]=[];b=0;for(c=a.faceVertexUvs.length;b<
  22698. c;b++)h[b]=[];b=0;for(c=a.faces.length;b<c;b++){d=a.faces[b];if(d instanceof THREE.Face4){e=d.a;var k=d.b,j=d.c,l=d.d,p=new THREE.Face3,m=new THREE.Face3;p.color.copy(d.color);m.color.copy(d.color);p.materialIndex=d.materialIndex;m.materialIndex=d.materialIndex;p.a=e;p.b=k;p.c=l;m.a=k;m.b=j;m.c=l;if(d.vertexColors.length===4){p.vertexColors[0]=d.vertexColors[0].clone();p.vertexColors[1]=d.vertexColors[1].clone();p.vertexColors[2]=d.vertexColors[3].clone();m.vertexColors[0]=d.vertexColors[1].clone();
  22699. m.vertexColors[1]=d.vertexColors[2].clone();m.vertexColors[2]=d.vertexColors[3].clone()}f.push(p,m);d=0;for(e=a.faceVertexUvs.length;d<e;d++)if(a.faceVertexUvs[d].length){p=a.faceVertexUvs[d][b];k=p[1];j=p[2];l=p[3];p=[p[0].clone(),k.clone(),l.clone()];k=[k.clone(),j.clone(),l.clone()];h[d].push(p,k)}d=0;for(e=a.faceUvs.length;d<e;d++)if(a.faceUvs[d].length){k=a.faceUvs[d][b];g[d].push(k,k)}}else{f.push(d);d=0;for(e=a.faceUvs.length;d<e;d++)g[d].push(a.faceUvs[d]);d=0;for(e=a.faceVertexUvs.length;d<
  22700. e;d++)h[d].push(a.faceVertexUvs[d])}}a.faces=f;a.faceUvs=g;a.faceVertexUvs=h;a.computeCentroids();a.computeFaceNormals();a.computeVertexNormals();a.hasTangents&&a.computeTangents()},explode:function(a){for(var b=[],c=0,d=a.faces.length;c<d;c++){var e=b.length,f=a.faces[c];if(f instanceof THREE.Face4){var g=f.a,h=f.b,k=f.c,g=a.vertices[g],h=a.vertices[h],k=a.vertices[k],j=a.vertices[f.d];b.push(g.clone());b.push(h.clone());b.push(k.clone());b.push(j.clone());f.a=e;f.b=e+1;f.c=e+2;f.d=e+3}else{g=f.a;
  22701. h=f.b;k=f.c;g=a.vertices[g];h=a.vertices[h];k=a.vertices[k];b.push(g.clone());b.push(h.clone());b.push(k.clone());f.a=e;f.b=e+1;f.c=e+2}}a.vertices=b;delete a.__tmpVertices},tessellate:function(a,b){var c,d,e,f,g,h,k,j,l,p,m,o,q,n,r,u,t,w,s,x=[],F=[];c=0;for(d=a.faceVertexUvs.length;c<d;c++)F[c]=[];c=0;for(d=a.faces.length;c<d;c++){e=a.faces[c];if(e instanceof THREE.Face3){f=e.a;g=e.b;h=e.c;j=a.vertices[f];l=a.vertices[g];p=a.vertices[h];o=j.distanceTo(l);q=l.distanceTo(p);m=j.distanceTo(p);if(o>
  22702. b||q>b||m>b){k=a.vertices.length;w=e.clone();s=e.clone();if(o>=q&&o>=m){j=j.clone();j.lerpSelf(l,0.5);w.a=f;w.b=k;w.c=h;s.a=k;s.b=g;s.c=h;if(e.vertexNormals.length===3){f=e.vertexNormals[0].clone();f.lerpSelf(e.vertexNormals[1],0.5);w.vertexNormals[1].copy(f);s.vertexNormals[0].copy(f)}if(e.vertexColors.length===3){f=e.vertexColors[0].clone();f.lerpSelf(e.vertexColors[1],0.5);w.vertexColors[1].copy(f);s.vertexColors[0].copy(f)}e=0}else if(q>=o&&q>=m){j=l.clone();j.lerpSelf(p,0.5);w.a=f;w.b=g;w.c=
  22703. k;s.a=k;s.b=h;s.c=f;if(e.vertexNormals.length===3){f=e.vertexNormals[1].clone();f.lerpSelf(e.vertexNormals[2],0.5);w.vertexNormals[2].copy(f);s.vertexNormals[0].copy(f);s.vertexNormals[1].copy(e.vertexNormals[2]);s.vertexNormals[2].copy(e.vertexNormals[0])}if(e.vertexColors.length===3){f=e.vertexColors[1].clone();f.lerpSelf(e.vertexColors[2],0.5);w.vertexColors[2].copy(f);s.vertexColors[0].copy(f);s.vertexColors[1].copy(e.vertexColors[2]);s.vertexColors[2].copy(e.vertexColors[0])}e=1}else{j=j.clone();
  22704. j.lerpSelf(p,0.5);w.a=f;w.b=g;w.c=k;s.a=k;s.b=g;s.c=h;if(e.vertexNormals.length===3){f=e.vertexNormals[0].clone();f.lerpSelf(e.vertexNormals[2],0.5);w.vertexNormals[2].copy(f);s.vertexNormals[0].copy(f)}if(e.vertexColors.length===3){f=e.vertexColors[0].clone();f.lerpSelf(e.vertexColors[2],0.5);w.vertexColors[2].copy(f);s.vertexColors[0].copy(f)}e=2}x.push(w,s);a.vertices.push(j);f=0;for(g=a.faceVertexUvs.length;f<g;f++)if(a.faceVertexUvs[f].length){j=a.faceVertexUvs[f][c];s=j[0];h=j[1];w=j[2];if(e===
  22705. 0){l=s.clone();l.lerpSelf(h,0.5);j=[s.clone(),l.clone(),w.clone()];h=[l.clone(),h.clone(),w.clone()]}else if(e===1){l=h.clone();l.lerpSelf(w,0.5);j=[s.clone(),h.clone(),l.clone()];h=[l.clone(),w.clone(),s.clone()]}else{l=s.clone();l.lerpSelf(w,0.5);j=[s.clone(),h.clone(),l.clone()];h=[l.clone(),h.clone(),w.clone()]}F[f].push(j,h)}}else{x.push(e);f=0;for(g=a.faceVertexUvs.length;f<g;f++)F[f].push(a.faceVertexUvs[f][c])}}else{f=e.a;g=e.b;h=e.c;k=e.d;j=a.vertices[f];l=a.vertices[g];p=a.vertices[h];m=
  22706. a.vertices[k];o=j.distanceTo(l);q=l.distanceTo(p);n=p.distanceTo(m);r=j.distanceTo(m);if(o>b||q>b||n>b||r>b){u=a.vertices.length;t=a.vertices.length+1;w=e.clone();s=e.clone();if(o>=q&&o>=n&&o>=r||n>=q&&n>=o&&n>=r){o=j.clone();o.lerpSelf(l,0.5);l=p.clone();l.lerpSelf(m,0.5);w.a=f;w.b=u;w.c=t;w.d=k;s.a=u;s.b=g;s.c=h;s.d=t;if(e.vertexNormals.length===4){f=e.vertexNormals[0].clone();f.lerpSelf(e.vertexNormals[1],0.5);g=e.vertexNormals[2].clone();g.lerpSelf(e.vertexNormals[3],0.5);w.vertexNormals[1].copy(f);
  22707. w.vertexNormals[2].copy(g);s.vertexNormals[0].copy(f);s.vertexNormals[3].copy(g)}if(e.vertexColors.length===4){f=e.vertexColors[0].clone();f.lerpSelf(e.vertexColors[1],0.5);g=e.vertexColors[2].clone();g.lerpSelf(e.vertexColors[3],0.5);w.vertexColors[1].copy(f);w.vertexColors[2].copy(g);s.vertexColors[0].copy(f);s.vertexColors[3].copy(g)}e=0}else{o=l.clone();o.lerpSelf(p,0.5);l=m.clone();l.lerpSelf(j,0.5);w.a=f;w.b=g;w.c=u;w.d=t;s.a=t;s.b=u;s.c=h;s.d=k;if(e.vertexNormals.length===4){f=e.vertexNormals[1].clone();
  22708. f.lerpSelf(e.vertexNormals[2],0.5);g=e.vertexNormals[3].clone();g.lerpSelf(e.vertexNormals[0],0.5);w.vertexNormals[2].copy(f);w.vertexNormals[3].copy(g);s.vertexNormals[0].copy(g);s.vertexNormals[1].copy(f)}if(e.vertexColors.length===4){f=e.vertexColors[1].clone();f.lerpSelf(e.vertexColors[2],0.5);g=e.vertexColors[3].clone();g.lerpSelf(e.vertexColors[0],0.5);w.vertexColors[2].copy(f);w.vertexColors[3].copy(g);s.vertexColors[0].copy(g);s.vertexColors[1].copy(f)}e=1}x.push(w,s);a.vertices.push(o,l);
  22709. f=0;for(g=a.faceVertexUvs.length;f<g;f++)if(a.faceVertexUvs[f].length){j=a.faceVertexUvs[f][c];s=j[0];h=j[1];w=j[2];j=j[3];if(e===0){l=s.clone();l.lerpSelf(h,0.5);p=w.clone();p.lerpSelf(j,0.5);s=[s.clone(),l.clone(),p.clone(),j.clone()];h=[l.clone(),h.clone(),w.clone(),p.clone()]}else{l=h.clone();l.lerpSelf(w,0.5);p=j.clone();p.lerpSelf(s,0.5);s=[s.clone(),h.clone(),l.clone(),p.clone()];h=[p.clone(),l.clone(),w.clone(),j.clone()]}F[f].push(s,h)}}else{x.push(e);f=0;for(g=a.faceVertexUvs.length;f<g;f++)F[f].push(a.faceVertexUvs[f][c])}}}a.faces=
  22710. x;a.faceVertexUvs=F}};THREE.GeometryUtils.random=THREE.Math.random16;THREE.GeometryUtils.__v1=new THREE.Vector3;
  22711. THREE.ImageUtils={crossOrigin:"anonymous",loadTexture:function(a,b,c){var d=new Image,e=new THREE.Texture(d,b);d.onload=function(){e.needsUpdate=true;c&&c(this)};d.crossOrigin=this.crossOrigin;d.src=a;return e},loadTextureCube:function(a,b,c){var d,e=[],f=new THREE.Texture(e,b),b=e.loadCount=0;for(d=a.length;b<d;++b){e[b]=new Image;e[b].onload=function(){e.loadCount=e.loadCount+1;if(e.loadCount===6)f.needsUpdate=true;c&&c(this)};e[b].crossOrigin=this.crossOrigin;e[b].src=a[b]}return f},getNormalMap:function(a,
  22712. b){var c=function(a){var b=Math.sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]);return[a[0]/b,a[1]/b,a[2]/b]},b=b|1,d=a.width,e=a.height,f=document.createElement("canvas");f.width=d;f.height=e;var g=f.getContext("2d");g.drawImage(a,0,0);for(var h=g.getImageData(0,0,d,e).data,k=g.createImageData(d,e),j=k.data,l=0;l<d;l++)for(var p=1;p<e;p++){var m=p-1<0?e-1:p-1,o=(p+1)%e,q=l-1<0?d-1:l-1,n=(l+1)%d,r=[],u=[0,0,h[(p*d+l)*4]/255*b];r.push([-1,0,h[(p*d+q)*4]/255*b]);r.push([-1,-1,h[(m*d+q)*4]/255*b]);r.push([0,-1,
  22713. h[(m*d+l)*4]/255*b]);r.push([1,-1,h[(m*d+n)*4]/255*b]);r.push([1,0,h[(p*d+n)*4]/255*b]);r.push([1,1,h[(o*d+n)*4]/255*b]);r.push([0,1,h[(o*d+l)*4]/255*b]);r.push([-1,1,h[(o*d+q)*4]/255*b]);m=[];q=r.length;for(o=0;o<q;o++){var n=r[o],t=r[(o+1)%q],n=[n[0]-u[0],n[1]-u[1],n[2]-u[2]],t=[t[0]-u[0],t[1]-u[1],t[2]-u[2]];m.push(c([n[1]*t[2]-n[2]*t[1],n[2]*t[0]-n[0]*t[2],n[0]*t[1]-n[1]*t[0]]))}r=[0,0,0];for(o=0;o<m.length;o++){r[0]=r[0]+m[o][0];r[1]=r[1]+m[o][1];r[2]=r[2]+m[o][2]}r[0]=r[0]/m.length;r[1]=r[1]/
  22714. m.length;r[2]=r[2]/m.length;u=(p*d+l)*4;j[u]=(r[0]+1)/2*255|0;j[u+1]=(r[1]+0.5)*255|0;j[u+2]=r[2]*255|0;j[u+3]=255}g.putImageData(k,0,0);return f},generateDataTexture:function(a,b,c){for(var d=a*b,e=new Uint8Array(3*d),f=Math.floor(c.r*255),g=Math.floor(c.g*255),c=Math.floor(c.b*255),h=0;h<d;h++){e[h*3]=f;e[h*3+1]=g;e[h*3+2]=c}a=new THREE.DataTexture(e,a,b,THREE.RGBFormat);a.needsUpdate=true;return a}};
  22715. THREE.SceneUtils={showHierarchy:function(a,b){THREE.SceneUtils.traverseHierarchy(a,function(a){a.visible=b})},traverseHierarchy:function(a,b){var c,d,e=a.children.length;for(d=0;d<e;d++){c=a.children[d];b(c);THREE.SceneUtils.traverseHierarchy(c,b)}},createMultiMaterialObject:function(a,b){var c,d=b.length,e=new THREE.Object3D;for(c=0;c<d;c++){var f=new THREE.Mesh(a,b[c]);e.add(f)}return e},cloneObject:function(a){var b;if(a instanceof THREE.MorphAnimMesh){b=new THREE.MorphAnimMesh(a.geometry,a.material);
  22716. b.duration=a.duration;b.mirroredLoop=a.mirroredLoop;b.time=a.time;b.lastKeyframe=a.lastKeyframe;b.currentKeyframe=a.currentKeyframe;b.direction=a.direction;b.directionBackwards=a.directionBackwards}else if(a instanceof THREE.SkinnedMesh)b=new THREE.SkinnedMesh(a.geometry,a.material);else if(a instanceof THREE.Mesh)b=new THREE.Mesh(a.geometry,a.material);else if(a instanceof THREE.Line)b=new THREE.Line(a.geometry,a.material,a.type);else if(a instanceof THREE.Ribbon)b=new THREE.Ribbon(a.geometry,a.material);
  22717. else if(a instanceof THREE.ParticleSystem){b=new THREE.ParticleSystem(a.geometry,a.material);b.sortParticles=a.sortParticles}else if(a instanceof THREE.Particle)b=new THREE.Particle(a.material);else if(a instanceof THREE.Sprite){b=new THREE.Sprite({});b.color.copy(a.color);b.map=a.map;b.blending=a.blending;b.useScreenCoordinates=a.useScreenCoordinates;b.mergeWith3D=a.mergeWith3D;b.affectedByDistance=a.affectedByDistance;b.scaleByViewport=a.scaleByViewport;b.alignment=a.alignment;b.rotation3d.copy(a.rotation3d);
  22718. b.rotation=a.rotation;b.opacity=a.opacity;b.uvOffset.copy(a.uvOffset);b.uvScale.copy(a.uvScale)}else if(a instanceof THREE.LOD)b=new THREE.LOD;else if(a instanceof THREE.MarchingCubes){b=new THREE.MarchingCubes(a.resolution,a.material);b.field.set(a.field);b.isolation=a.isolation}else a instanceof THREE.Object3D&&(b=new THREE.Object3D);b.name=a.name;b.parent=a.parent;b.up.copy(a.up);b.position.copy(a.position);b.rotation instanceof THREE.Vector3&&b.rotation.copy(a.rotation);b.eulerOrder=a.eulerOrder;
  22719. b.scale.copy(a.scale);b.dynamic=a.dynamic;b.doubleSided=a.doubleSided;b.flipSided=a.flipSided;b.renderDepth=a.renderDepth;b.rotationAutoUpdate=a.rotationAutoUpdate;b.matrix.copy(a.matrix);b.matrixWorld.copy(a.matrixWorld);b.matrixRotationWorld.copy(a.matrixRotationWorld);b.matrixAutoUpdate=a.matrixAutoUpdate;b.matrixWorldNeedsUpdate=a.matrixWorldNeedsUpdate;b.quaternion.copy(a.quaternion);b.useQuaternion=a.useQuaternion;b.boundRadius=a.boundRadius;b.boundRadiusScale=a.boundRadiusScale;b.visible=a.visible;
  22720. b.castShadow=a.castShadow;b.receiveShadow=a.receiveShadow;b.frustumCulled=a.frustumCulled;for(var c=0;c<a.children.length;c++){var d=THREE.SceneUtils.cloneObject(a.children[c]);b.children[c]=d;d.parent=b}if(a instanceof THREE.LOD)for(c=0;c<a.LODs.length;c++)b.LODs[c]={visibleAtDistance:a.LODs[c].visibleAtDistance,object3D:b.children[c]};return b},detach:function(a,b,c){a.applyMatrix(b.matrixWorld);b.remove(a);c.add(a)},attach:function(a,b,c){var d=new THREE.Matrix4;d.getInverse(c.matrixWorld);a.applyMatrix(d);
  22721. b.remove(a);c.add(a)}};
  22722. THREE.WebGLRenderer&&(THREE.ShaderUtils={lib:{fresnel:{uniforms:{mRefractionRatio:{type:"f",value:1.02},mFresnelBias:{type:"f",value:0.1},mFresnelPower:{type:"f",value:2},mFresnelScale:{type:"f",value:1},tCube:{type:"t",value:1,texture:null}},fragmentShader:"uniform samplerCube tCube;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main() {\nvec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\nvec4 refractedColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nrefractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;\nrefractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;\nrefractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;\nrefractedColor.a = 1.0;\ngl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );\n}",vertexShader:"uniform float mRefractionRatio;\nuniform float mFresnelBias;\nuniform float mFresnelScale;\nuniform float mFresnelPower;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = normalize ( mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal );\nvec3 I = mPosition.xyz - cameraPosition;\nvReflect = reflect( I, nWorld );\nvRefract[0] = refract( normalize( I ), nWorld, mRefractionRatio );\nvRefract[1] = refract( normalize( I ), nWorld, mRefractionRatio * 0.99 );\nvRefract[2] = refract( normalize( I ), nWorld, mRefractionRatio * 0.98 );\nvReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), nWorld ), mFresnelPower );\ngl_Position = projectionMatrix * mvPosition;\n}"},
  22723. normal:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.fog,THREE.UniformsLib.lights,THREE.UniformsLib.shadowmap,{enableAO:{type:"i",value:0},enableDiffuse:{type:"i",value:0},enableSpecular:{type:"i",value:0},enableReflection:{type:"i",value:0},tDiffuse:{type:"t",value:0,texture:null},tCube:{type:"t",value:1,texture:null},tNormal:{type:"t",value:2,texture:null},tSpecular:{type:"t",value:3,texture:null},tAO:{type:"t",value:4,texture:null},tDisplacement:{type:"t",value:5,texture:null},uNormalScale:{type:"f",
  22724. value:1},uDisplacementBias:{type:"f",value:0},uDisplacementScale:{type:"f",value:1},uDiffuseColor:{type:"c",value:new THREE.Color(16777215)},uSpecularColor:{type:"c",value:new THREE.Color(1118481)},uAmbientColor:{type:"c",value:new THREE.Color(16777215)},uShininess:{type:"f",value:30},uOpacity:{type:"f",value:1},uReflectivity:{type:"f",value:0.5},uOffset:{type:"v2",value:new THREE.Vector2(0,0)},uRepeat:{type:"v2",value:new THREE.Vector2(1,1)},wrapRGB:{type:"v3",value:new THREE.Vector3(1,1,1)}}]),
  22725. fragmentShader:["uniform vec3 uAmbientColor;\nuniform vec3 uDiffuseColor;\nuniform vec3 uSpecularColor;\nuniform float uShininess;\nuniform float uOpacity;\nuniform bool enableDiffuse;\nuniform bool enableSpecular;\nuniform bool enableAO;\nuniform bool enableReflection;\nuniform sampler2D tDiffuse;\nuniform sampler2D tNormal;\nuniform sampler2D tSpecular;\nuniform sampler2D tAO;\nuniform samplerCube tCube;\nuniform float uNormalScale;\nuniform float uReflectivity;\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nvarying vec4 vPointLight[ MAX_POINT_LIGHTS ];\n#endif\n#ifdef WRAP_AROUND\nuniform vec3 wrapRGB;\n#endif\nvarying vec3 vViewPosition;",
  22726. THREE.ShaderChunk.shadowmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,"void main() {\ngl_FragColor = vec4( vec3( 1.0 ), uOpacity );\nvec3 specularTex = vec3( 1.0 );\nvec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;\nnormalTex.xy *= uNormalScale;\nnormalTex = normalize( normalTex );\nif( enableDiffuse ) {\n#ifdef GAMMA_INPUT\nvec4 texelColor = texture2D( tDiffuse, vUv );\ntexelColor.xyz *= texelColor.xyz;\ngl_FragColor = gl_FragColor * texelColor;\n#else\ngl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );\n#endif\n}\nif( enableAO ) {\n#ifdef GAMMA_INPUT\nvec4 aoColor = texture2D( tAO, vUv );\naoColor.xyz *= aoColor.xyz;\ngl_FragColor.xyz = gl_FragColor.xyz * aoColor.xyz;\n#else\ngl_FragColor.xyz = gl_FragColor.xyz * texture2D( tAO, vUv ).xyz;\n#endif\n}\nif( enableSpecular )\nspecularTex = texture2D( tSpecular, vUv ).xyz;\nmat3 tsb = mat3( normalize( vTangent ), normalize( vBinormal ), normalize( vNormal ) );\nvec3 finalNormal = tsb * normalTex;\nvec3 normal = normalize( finalNormal );\nvec3 viewPosition = normalize( vViewPosition );\n#if MAX_POINT_LIGHTS > 0\nvec3 pointDiffuse = vec3( 0.0 );\nvec3 pointSpecular = vec3( 0.0 );\nfor ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\nvec3 pointVector = normalize( vPointLight[ i ].xyz );\nfloat pointDistance = vPointLight[ i ].w;\n#ifdef WRAP_AROUND\nfloat pointDiffuseWeightFull = max( dot( normal, pointVector ), 0.0 );\nfloat pointDiffuseWeightHalf = max( 0.5 * dot( normal, pointVector ) + 0.5, 0.0 );\nvec3 pointDiffuseWeight = mix( vec3 ( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );\n#else\nfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );\n#endif\npointDiffuse += pointDistance * pointLightColor[ i ] * uDiffuseColor * pointDiffuseWeight;\nvec3 pointHalfVector = normalize( pointVector + viewPosition );\nfloat pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );\nfloat pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, uShininess ), 0.0 );\n#ifdef PHYSICALLY_BASED_SHADING\nfloat specularNormalization = ( uShininess + 2.0001 ) / 8.0;\nvec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( pointVector, pointHalfVector ), 5.0 );\npointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * pointDistance * specularNormalization;\n#else\npointSpecular += pointDistance * pointLightColor[ i ] * uSpecularColor * pointSpecularWeight * pointDiffuseWeight;\n#endif\n}\n#endif\n#if MAX_DIR_LIGHTS > 0\nvec3 dirDiffuse = vec3( 0.0 );\nvec3 dirSpecular = vec3( 0.0 );\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\n#ifdef WRAP_AROUND\nfloat directionalLightWeightingFull = max( dot( normal, dirVector ), 0.0 );\nfloat directionalLightWeightingHalf = max( 0.5 * dot( normal, dirVector ) + 0.5, 0.0 );\nvec3 dirDiffuseWeight = mix( vec3( directionalLightWeightingFull ), vec3( directionalLightWeightingHalf ), wrapRGB );\n#else\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\n#endif\ndirDiffuse += directionalLightColor[ i ] * uDiffuseColor * dirDiffuseWeight;\nvec3 dirHalfVector = normalize( dirVector + viewPosition );\nfloat dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );\nfloat dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, uShininess ), 0.0 );\n#ifdef PHYSICALLY_BASED_SHADING\nfloat specularNormalization = ( uShininess + 2.0001 ) / 8.0;\nvec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( dirVector, dirHalfVector ), 5.0 );\ndirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;\n#else\ndirSpecular += directionalLightColor[ i ] * uSpecularColor * dirSpecularWeight * dirDiffuseWeight;\n#endif\n}\n#endif\nvec3 totalDiffuse = vec3( 0.0 );\nvec3 totalSpecular = vec3( 0.0 );\n#if MAX_DIR_LIGHTS > 0\ntotalDiffuse += dirDiffuse;\ntotalSpecular += dirSpecular;\n#endif\n#if MAX_POINT_LIGHTS > 0\ntotalDiffuse += pointDiffuse;\ntotalSpecular += pointSpecular;\n#endif\ngl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * uAmbientColor) + totalSpecular;\nif ( enableReflection ) {\nvec3 wPos = cameraPosition - vViewPosition;\nvec3 vReflect = reflect( normalize( wPos ), normal );\nvec4 cubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\n#ifdef GAMMA_INPUT\ncubeColor.xyz *= cubeColor.xyz;\n#endif\ngl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularTex.r * uReflectivity );\n}",
  22727. THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.linear_to_gamma_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n"),vertexShader:["attribute vec4 tangent;\nuniform vec2 uOffset;\nuniform vec2 uRepeat;\n#ifdef VERTEX_TEXTURES\nuniform sampler2D tDisplacement;\nuniform float uDisplacementScale;\nuniform float uDisplacementBias;\n#endif\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\nuniform float pointLightDistance[ MAX_POINT_LIGHTS ];\nvarying vec4 vPointLight[ MAX_POINT_LIGHTS ];\n#endif\nvarying vec3 vViewPosition;",
  22728. THREE.ShaderChunk.shadowmap_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvViewPosition = -mvPosition.xyz;\nvNormal = normalMatrix * normal;\nvTangent = normalMatrix * tangent.xyz;\nvBinormal = cross( vNormal, vTangent ) * tangent.w;\nvUv = uv * uRepeat + uOffset;\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 lVector = lPosition.xyz - mvPosition.xyz;\nfloat lDistance = 1.0;\nif ( pointLightDistance[ i ] > 0.0 )\nlDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );\nlVector = normalize( lVector );\nvPointLight[ i ] = vec4( lVector, lDistance );\n}\n#endif\n#ifdef VERTEX_TEXTURES\nvec3 dv = texture2D( tDisplacement, uv ).xyz;\nfloat df = uDisplacementScale * dv.x + uDisplacementBias;\nvec4 displacedPosition = vec4( normalize( vNormal.xyz ) * df, 0.0 ) + mvPosition;\ngl_Position = projectionMatrix * displacedPosition;\n#else\ngl_Position = projectionMatrix * mvPosition;\n#endif",
  22729. THREE.ShaderChunk.shadowmap_vertex,"}"].join("\n")},cube:{uniforms:{tCube:{type:"t",value:1,texture:null},tFlip:{type:"f",value:-1}},vertexShader:"varying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"uniform samplerCube tCube;\nuniform float tFlip;\nvarying vec3 vViewPosition;\nvoid main() {\nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( tFlip * wPos.x, wPos.yz ) );\n}"}}});
  22730. THREE.BufferGeometry=function(){this.id=THREE.GeometryCount++;this.vertexColorArray=this.vertexUvArray=this.vertexNormalArray=this.vertexPositionArray=this.vertexIndexArray=this.vertexColorBuffer=this.vertexUvBuffer=this.vertexNormalBuffer=this.vertexPositionBuffer=this.vertexIndexBuffer=null;this.dynamic=false;this.boundingSphere=this.boundingBox=null;this.morphTargets=[]};THREE.BufferGeometry.prototype={constructor:THREE.BufferGeometry,computeBoundingBox:function(){},computeBoundingSphere:function(){}};
  22731. THREE.Curve=function(){};THREE.Curve.prototype.getPoint=function(){console.log("Warning, getPoint() not implemented!");return null};THREE.Curve.prototype.getPointAt=function(a){return this.getPoint(this.getUtoTmapping(a))};THREE.Curve.prototype.getPoints=function(a){a||(a=5);var b,c=[];for(b=0;b<=a;b++)c.push(this.getPoint(b/a));return c};THREE.Curve.prototype.getSpacedPoints=function(a){a||(a=5);var b,c=[];for(b=0;b<=a;b++)c.push(this.getPointAt(b/a));return c};
  22732. THREE.Curve.prototype.getLength=function(){var a=this.getLengths();return a[a.length-1]};THREE.Curve.prototype.getLengths=function(a){a||(a=this.__arcLengthDivisions?this.__arcLengthDivisions:200);if(this.cacheArcLengths&&this.cacheArcLengths.length==a+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=false;var b=[],c,d=this.getPoint(0),e,f=0;b.push(0);for(e=1;e<=a;e++){c=this.getPoint(e/a);f=f+c.distanceTo(d);b.push(f);d=c}return this.cacheArcLengths=b};
  22733. THREE.Curve.prototype.updateArcLengths=function(){this.needsUpdate=true;this.getLengths()};THREE.Curve.prototype.getUtoTmapping=function(a,b){var c=this.getLengths(),d=0,e=c.length,f;f=b?b:a*c[e-1];for(var g=0,h=e-1,k;g<=h;){d=Math.floor(g+(h-g)/2);k=c[d]-f;if(k<0)g=d+1;else if(k>0)h=d-1;else{h=d;break}}d=h;if(c[d]==f)return d/(e-1);g=c[d];return c=(d+(f-g)/(c[d+1]-g))/(e-1)};THREE.Curve.prototype.getNormalVector=function(a){a=this.getTangent(a);return new THREE.Vector2(-a.y,a.x)};
  22734. THREE.Curve.prototype.getTangent=function(a){var b=a-1.0E-4,a=a+1.0E-4;b<0&&(b=0);a>1&&(a=1);b=this.getPoint(b);return this.getPoint(a).clone().subSelf(b).normalize()};THREE.Curve.prototype.getTangentAt=function(a){return this.getTangent(this.getUtoTmapping(a))};THREE.LineCurve=function(a,b){this.v1=a;this.v2=b};THREE.LineCurve.prototype=new THREE.Curve;THREE.LineCurve.prototype.constructor=THREE.LineCurve;
  22735. THREE.LineCurve.prototype.getPoint=function(a){var b=this.v2.clone().subSelf(this.v1);b.multiplyScalar(a).addSelf(this.v1);return b};THREE.LineCurve.prototype.getPointAt=function(a){return this.getPoint(a)};THREE.LineCurve.prototype.getTangent=function(){return this.v2.clone().subSelf(this.v1).normalize()};THREE.QuadraticBezierCurve=function(a,b,c){this.v0=a;this.v1=b;this.v2=c};THREE.QuadraticBezierCurve.prototype=new THREE.Curve;THREE.QuadraticBezierCurve.prototype.constructor=THREE.QuadraticBezierCurve;
  22736. THREE.QuadraticBezierCurve.prototype.getPoint=function(a){var b;b=THREE.Shape.Utils.b2(a,this.v0.x,this.v1.x,this.v2.x);a=THREE.Shape.Utils.b2(a,this.v0.y,this.v1.y,this.v2.y);return new THREE.Vector2(b,a)};THREE.QuadraticBezierCurve.prototype.getTangent=function(a){var b;b=THREE.Curve.Utils.tangentQuadraticBezier(a,this.v0.x,this.v1.x,this.v2.x);a=THREE.Curve.Utils.tangentQuadraticBezier(a,this.v0.y,this.v1.y,this.v2.y);b=new THREE.Vector2(b,a);b.normalize();return b};
  22737. THREE.CubicBezierCurve=function(a,b,c,d){this.v0=a;this.v1=b;this.v2=c;this.v3=d};THREE.CubicBezierCurve.prototype=new THREE.Curve;THREE.CubicBezierCurve.prototype.constructor=THREE.CubicBezierCurve;THREE.CubicBezierCurve.prototype.getPoint=function(a){var b;b=THREE.Shape.Utils.b3(a,this.v0.x,this.v1.x,this.v2.x,this.v3.x);a=THREE.Shape.Utils.b3(a,this.v0.y,this.v1.y,this.v2.y,this.v3.y);return new THREE.Vector2(b,a)};
  22738. THREE.CubicBezierCurve.prototype.getTangent=function(a){var b;b=THREE.Curve.Utils.tangentCubicBezier(a,this.v0.x,this.v1.x,this.v2.x,this.v3.x);a=THREE.Curve.Utils.tangentCubicBezier(a,this.v0.y,this.v1.y,this.v2.y,this.v3.y);b=new THREE.Vector2(b,a);b.normalize();return b};THREE.SplineCurve=function(a){this.points=a==void 0?[]:a};THREE.SplineCurve.prototype=new THREE.Curve;THREE.SplineCurve.prototype.constructor=THREE.SplineCurve;
  22739. THREE.SplineCurve.prototype.getPoint=function(a){var b=new THREE.Vector2,c=[],d=this.points,e;e=(d.length-1)*a;a=Math.floor(e);e=e-a;c[0]=a==0?a:a-1;c[1]=a;c[2]=a>d.length-2?d.length-1:a+1;c[3]=a>d.length-3?d.length-1:a+2;b.x=THREE.Curve.Utils.interpolate(d[c[0]].x,d[c[1]].x,d[c[2]].x,d[c[3]].x,e);b.y=THREE.Curve.Utils.interpolate(d[c[0]].y,d[c[1]].y,d[c[2]].y,d[c[3]].y,e);return b};
  22740. THREE.ArcCurve=function(a,b,c,d,e,f){this.aX=a;this.aY=b;this.aRadius=c;this.aStartAngle=d;this.aEndAngle=e;this.aClockwise=f};THREE.ArcCurve.prototype=new THREE.Curve;THREE.ArcCurve.prototype.constructor=THREE.ArcCurve;THREE.ArcCurve.prototype.getPoint=function(a){var b=this.aEndAngle-this.aStartAngle;this.aClockwise||(a=1-a);b=this.aStartAngle+a*b;a=this.aX+this.aRadius*Math.cos(b);b=this.aY+this.aRadius*Math.sin(b);return new THREE.Vector2(a,b)};
  22741. THREE.Curve.Utils={tangentQuadraticBezier:function(a,b,c,d){return 2*(1-a)*(c-b)+2*a*(d-c)},tangentCubicBezier:function(a,b,c,d,e){return-3*b*(1-a)*(1-a)+3*c*(1-a)*(1-a)-6*a*c*(1-a)+6*a*d*(1-a)-3*a*a*d+3*a*a*e},tangentSpline:function(a){return 6*a*a-6*a+(3*a*a-4*a+1)+(-6*a*a+6*a)+(3*a*a-2*a)},interpolate:function(a,b,c,d,e){var a=(c-a)*0.5,d=(d-b)*0.5,f=e*e;return(2*b-2*c+a+d)*e*f+(-3*b+3*c-2*a-d)*f+a*e+b}};
  22742. THREE.Curve.create=function(a,b){a.prototype=new THREE.Curve;a.prototype.constructor=a;a.prototype.getPoint=b;return a};THREE.LineCurve3=THREE.Curve.create(function(a,b){this.v1=a;this.v2=b},function(a){var b=new THREE.Vector3;b.sub(this.v2,this.v1);b.multiplyScalar(a);b.addSelf(this.v1);return b});
  22743. THREE.QuadraticBezierCurve3=THREE.Curve.create(function(a,b,c){this.v0=a;this.v1=b;this.v2=c},function(a){var b,c;b=THREE.Shape.Utils.b2(a,this.v0.x,this.v1.x,this.v2.x);c=THREE.Shape.Utils.b2(a,this.v0.y,this.v1.y,this.v2.y);a=THREE.Shape.Utils.b2(a,this.v0.z,this.v1.z,this.v2.z);return new THREE.Vector3(b,c,a)});
  22744. THREE.CubicBezierCurve3=THREE.Curve.create(function(a,b,c,d){this.v0=a;this.v1=b;this.v2=c;this.v3=d},function(a){var b,c;b=THREE.Shape.Utils.b3(a,this.v0.x,this.v1.x,this.v2.x,this.v3.x);c=THREE.Shape.Utils.b3(a,this.v0.y,this.v1.y,this.v2.y,this.v3.y);a=THREE.Shape.Utils.b3(a,this.v0.z,this.v1.z,this.v2.z,this.v3.z);return new THREE.Vector3(b,c,a)});
  22745. THREE.SplineCurve3=THREE.Curve.create(function(a){this.points=a==void 0?[]:a},function(a){var b=new THREE.Vector3,c=[],d=this.points,e,a=(d.length-1)*a;e=Math.floor(a);a=a-e;c[0]=e==0?e:e-1;c[1]=e;c[2]=e>d.length-2?d.length-1:e+1;c[3]=e>d.length-3?d.length-1:e+2;e=d[c[0]];var f=d[c[1]],g=d[c[2]],c=d[c[3]];b.x=THREE.Curve.Utils.interpolate(e.x,f.x,g.x,c.x,a);b.y=THREE.Curve.Utils.interpolate(e.y,f.y,g.y,c.y,a);b.z=THREE.Curve.Utils.interpolate(e.z,f.z,g.z,c.z,a);return b});
  22746. THREE.ClosedSplineCurve3=THREE.Curve.create(function(a){this.points=a==void 0?[]:a},function(a){var b=new THREE.Vector3,c=[],d=this.points,e;e=(d.length-0)*a;a=Math.floor(e);e=e-a;a=a+(a>0?0:(Math.floor(Math.abs(a)/d.length)+1)*d.length);c[0]=(a-1)%d.length;c[1]=a%d.length;c[2]=(a+1)%d.length;c[3]=(a+2)%d.length;b.x=THREE.Curve.Utils.interpolate(d[c[0]].x,d[c[1]].x,d[c[2]].x,d[c[3]].x,e);b.y=THREE.Curve.Utils.interpolate(d[c[0]].y,d[c[1]].y,d[c[2]].y,d[c[3]].y,e);b.z=THREE.Curve.Utils.interpolate(d[c[0]].z,
  22747. d[c[1]].z,d[c[2]].z,d[c[3]].z,e);return b});THREE.CurvePath=function(){this.curves=[];this.bends=[];this.autoClose=false};THREE.CurvePath.prototype=new THREE.Curve;THREE.CurvePath.prototype.constructor=THREE.CurvePath;THREE.CurvePath.prototype.add=function(a){this.curves.push(a)};THREE.CurvePath.prototype.checkConnection=function(){};
  22748. THREE.CurvePath.prototype.closePath=function(){var a=this.curves[0].getPoint(0),b=this.curves[this.curves.length-1].getPoint(1);a.equals(b)||this.curves.push(new THREE.LineCurve(b,a))};THREE.CurvePath.prototype.getPoint=function(a){for(var b=a*this.getLength(),c=this.getCurveLengths(),a=0;a<c.length;){if(c[a]>=b){b=c[a]-b;a=this.curves[a];b=1-b/a.getLength();return a.getPointAt(b)}a++}return null};THREE.CurvePath.prototype.getLength=function(){var a=this.getCurveLengths();return a[a.length-1]};
  22749. THREE.CurvePath.prototype.getCurveLengths=function(){if(this.cacheLengths&&this.cacheLengths.length==this.curves.length)return this.cacheLengths;var a=[],b=0,c,d=this.curves.length;for(c=0;c<d;c++){b=b+this.curves[c].getLength();a.push(b)}return this.cacheLengths=a};
  22750. THREE.CurvePath.prototype.getBoundingBox=function(){var a=this.getPoints(),b,c,d,e;b=c=Number.NEGATIVE_INFINITY;d=e=Number.POSITIVE_INFINITY;var f,g,h,k;k=new THREE.Vector2;g=0;for(h=a.length;g<h;g++){f=a[g];if(f.x>b)b=f.x;else if(f.x<d)d=f.x;if(f.y>c)c=f.y;else if(f.y<c)e=f.y;k.addSelf(f.x,f.y)}return{minX:d,minY:e,maxX:b,maxY:c,centroid:k.divideScalar(h)}};THREE.CurvePath.prototype.createPointsGeometry=function(a){return this.createGeometry(this.getPoints(a,true))};
  22751. THREE.CurvePath.prototype.createSpacedPointsGeometry=function(a){return this.createGeometry(this.getSpacedPoints(a,true))};THREE.CurvePath.prototype.createGeometry=function(a){for(var b=new THREE.Geometry,c=0;c<a.length;c++)b.vertices.push(new THREE.Vector3(a[c].x,a[c].y,0));return b};THREE.CurvePath.prototype.addWrapPath=function(a){this.bends.push(a)};
  22752. THREE.CurvePath.prototype.getTransformedPoints=function(a,b){var c=this.getPoints(a),d,e;if(!b)b=this.bends;d=0;for(e=b.length;d<e;d++)c=this.getWrapPoints(c,b[d]);return c};THREE.CurvePath.prototype.getTransformedSpacedPoints=function(a,b){var c=this.getSpacedPoints(a),d,e;if(!b)b=this.bends;d=0;for(e=b.length;d<e;d++)c=this.getWrapPoints(c,b[d]);return c};
  22753. THREE.CurvePath.prototype.getWrapPoints=function(a,b){var c=this.getBoundingBox(),d,e,f,g,h,k;d=0;for(e=a.length;d<e;d++){f=a[d];g=f.x;h=f.y;k=g/c.maxX;k=b.getUtoTmapping(k,g);g=b.getPoint(k);h=b.getNormalVector(k).multiplyScalar(h);f.x=g.x+h.x;f.y=g.y+h.y}return a};
  22754. THREE.EventTarget=function(){var a={};this.addEventListener=function(b,c){a[b]==void 0&&(a[b]=[]);a[b].indexOf(c)===-1&&a[b].push(c)};this.dispatchEvent=function(b){for(var c in a[b.type])a[b.type][c](b)};this.removeEventListener=function(b,c){var d=a[b].indexOf(c);d!==-1&&a[b].splice(d,1)}};THREE.Gyroscope=function(){THREE.Object3D.call(this)};THREE.Gyroscope.prototype=new THREE.Object3D;THREE.Gyroscope.prototype.constructor=THREE.Gyroscope;
  22755. THREE.Gyroscope.prototype.updateMatrixWorld=function(a){this.matrixAutoUpdate&&this.updateMatrix();if(this.matrixWorldNeedsUpdate||a){if(this.parent){this.matrixWorld.multiply(this.parent.matrixWorld,this.matrix);this.matrixWorld.decompose(this.translationWorld,this.rotationWorld,this.scaleWorld);this.matrix.decompose(this.translationObject,this.rotationObject,this.scaleObject);this.matrixWorld.compose(this.translationWorld,this.rotationObject,this.scaleWorld)}else this.matrixWorld.copy(this.matrix);
  22756. this.matrixWorldNeedsUpdate=false;a=true}for(var b=0,c=this.children.length;b<c;b++)this.children[b].updateMatrixWorld(a)};THREE.Gyroscope.prototype.translationWorld=new THREE.Vector3;THREE.Gyroscope.prototype.translationObject=new THREE.Vector3;THREE.Gyroscope.prototype.rotationWorld=new THREE.Quaternion;THREE.Gyroscope.prototype.rotationObject=new THREE.Quaternion;THREE.Gyroscope.prototype.scaleWorld=new THREE.Vector3;THREE.Gyroscope.prototype.scaleObject=new THREE.Vector3;
  22757. THREE.Path=function(a){THREE.CurvePath.call(this);this.actions=[];a&&this.fromPoints(a)};THREE.Path.prototype=new THREE.CurvePath;THREE.Path.prototype.constructor=THREE.Path;THREE.PathActions={MOVE_TO:"moveTo",LINE_TO:"lineTo",QUADRATIC_CURVE_TO:"quadraticCurveTo",BEZIER_CURVE_TO:"bezierCurveTo",CSPLINE_THRU:"splineThru",ARC:"arc"};THREE.Path.prototype.fromPoints=function(a){this.moveTo(a[0].x,a[0].y);for(var b=1,c=a.length;b<c;b++)this.lineTo(a[b].x,a[b].y)};
  22758. THREE.Path.prototype.moveTo=function(a,b){var c=Array.prototype.slice.call(arguments);this.actions.push({action:THREE.PathActions.MOVE_TO,args:c})};THREE.Path.prototype.lineTo=function(a,b){var c=Array.prototype.slice.call(arguments),d=this.actions[this.actions.length-1].args;this.curves.push(new THREE.LineCurve(new THREE.Vector2(d[d.length-2],d[d.length-1]),new THREE.Vector2(a,b)));this.actions.push({action:THREE.PathActions.LINE_TO,args:c})};
  22759. THREE.Path.prototype.quadraticCurveTo=function(a,b,c,d){var e=Array.prototype.slice.call(arguments),f=this.actions[this.actions.length-1].args;this.curves.push(new THREE.QuadraticBezierCurve(new THREE.Vector2(f[f.length-2],f[f.length-1]),new THREE.Vector2(a,b),new THREE.Vector2(c,d)));this.actions.push({action:THREE.PathActions.QUADRATIC_CURVE_TO,args:e})};
  22760. THREE.Path.prototype.bezierCurveTo=function(a,b,c,d,e,f){var g=Array.prototype.slice.call(arguments),h=this.actions[this.actions.length-1].args;this.curves.push(new THREE.CubicBezierCurve(new THREE.Vector2(h[h.length-2],h[h.length-1]),new THREE.Vector2(a,b),new THREE.Vector2(c,d),new THREE.Vector2(e,f)));this.actions.push({action:THREE.PathActions.BEZIER_CURVE_TO,args:g})};
  22761. THREE.Path.prototype.splineThru=function(a){var b=Array.prototype.slice.call(arguments),c=this.actions[this.actions.length-1].args,c=[new THREE.Vector2(c[c.length-2],c[c.length-1])];Array.prototype.push.apply(c,a);this.curves.push(new THREE.SplineCurve(c));this.actions.push({action:THREE.PathActions.CSPLINE_THRU,args:b})};
  22762. THREE.Path.prototype.arc=function(a,b,c,d,e,f){var g=Array.prototype.slice.call(arguments),h=this.actions[this.actions.length-1],h=new THREE.ArcCurve(h.x+a,h.y+b,c,d,e,f);this.curves.push(h);h=h.getPoint(f?1:0);g.push(h.x);g.push(h.y);this.actions.push({action:THREE.PathActions.ARC,args:g})};
  22763. THREE.Path.prototype.absarc=function(a,b,c,d,e,f){var g=Array.prototype.slice.call(arguments),h=new THREE.ArcCurve(a,b,c,d,e,f);this.curves.push(h);h=h.getPoint(f?1:0);g.push(h.x);g.push(h.y);this.actions.push({action:THREE.PathActions.ARC,args:g})};THREE.Path.prototype.getSpacedPoints=function(a){a||(a=40);for(var b=[],c=0;c<a;c++)b.push(this.getPoint(c/a));return b};
  22764. THREE.Path.prototype.getPoints=function(a,b){if(this.useSpacedPoints){console.log("tata");return this.getSpacedPoints(a,b)}var a=a||12,c=[],d,e,f,g,h,k,j,l,p,m,o,q,n;d=0;for(e=this.actions.length;d<e;d++){f=this.actions[d];g=f.action;f=f.args;switch(g){case THREE.PathActions.MOVE_TO:c.push(new THREE.Vector2(f[0],f[1]));break;case THREE.PathActions.LINE_TO:c.push(new THREE.Vector2(f[0],f[1]));break;case THREE.PathActions.QUADRATIC_CURVE_TO:h=f[2];k=f[3];p=f[0];m=f[1];if(c.length>0){g=c[c.length-1];
  22765. o=g.x;q=g.y}else{g=this.actions[d-1].args;o=g[g.length-2];q=g[g.length-1]}for(f=1;f<=a;f++){n=f/a;g=THREE.Shape.Utils.b2(n,o,p,h);n=THREE.Shape.Utils.b2(n,q,m,k);c.push(new THREE.Vector2(g,n))}break;case THREE.PathActions.BEZIER_CURVE_TO:h=f[4];k=f[5];p=f[0];m=f[1];j=f[2];l=f[3];if(c.length>0){g=c[c.length-1];o=g.x;q=g.y}else{g=this.actions[d-1].args;o=g[g.length-2];q=g[g.length-1]}for(f=1;f<=a;f++){n=f/a;g=THREE.Shape.Utils.b3(n,o,p,j,h);n=THREE.Shape.Utils.b3(n,q,m,l,k);c.push(new THREE.Vector2(g,
  22766. n))}break;case THREE.PathActions.CSPLINE_THRU:g=this.actions[d-1].args;n=[new THREE.Vector2(g[g.length-2],g[g.length-1])];g=a*f[0].length;n=n.concat(f[0]);n=new THREE.SplineCurve(n);for(f=1;f<=g;f++)c.push(n.getPointAt(f/g));break;case THREE.PathActions.ARC:h=f[0];k=f[1];j=f[2];p=f[3];m=!!f[5];l=f[4]-p;o=a*2;for(f=1;f<=o;f++){n=f/o;m||(n=1-n);n=p+n*l;g=h+j*Math.cos(n);n=k+j*Math.sin(n);c.push(new THREE.Vector2(g,n))}}}d=c[c.length-1];Math.abs(d.x-c[0].x)<1.0E-10&&Math.abs(d.y-c[0].y)<1.0E-10&&c.splice(c.length-
  22767. 1,1);b&&c.push(c[0]);return c};THREE.Path.prototype.transform=function(a,b){this.getBoundingBox();return this.getWrapPoints(this.getPoints(b),a)};THREE.Path.prototype.nltransform=function(a,b,c,d,e,f){var g=this.getPoints(),h,k,j,l,p;h=0;for(k=g.length;h<k;h++){j=g[h];l=j.x;p=j.y;j.x=a*l+b*p+c;j.y=d*p+e*l+f}return g};
  22768. THREE.Path.prototype.debug=function(a){var b=this.getBoundingBox();if(!a){a=document.createElement("canvas");a.setAttribute("width",b.maxX+100);a.setAttribute("height",b.maxY+100);document.body.appendChild(a)}b=a.getContext("2d");b.fillStyle="white";b.fillRect(0,0,a.width,a.height);b.strokeStyle="black";b.beginPath();var c,d,e,a=0;for(c=this.actions.length;a<c;a++){d=this.actions[a];e=d.args;d=d.action;d!=THREE.PathActions.CSPLINE_THRU&&b[d].apply(b,e)}b.stroke();b.closePath();b.strokeStyle="red";
  22769. d=this.getPoints();a=0;for(c=d.length;a<c;a++){e=d[a];b.beginPath();b.arc(e.x,e.y,1.5,0,Math.PI*2,false);b.stroke();b.closePath()}};
  22770. THREE.Path.prototype.toShapes=function(){var a,b,c,d,e=[],f=new THREE.Path;a=0;for(b=this.actions.length;a<b;a++){c=this.actions[a];d=c.args;c=c.action;if(c==THREE.PathActions.MOVE_TO&&f.actions.length!=0){e.push(f);f=new THREE.Path}f[c].apply(f,d)}f.actions.length!=0&&e.push(f);if(e.length==0)return[];var g;d=[];a=!THREE.Shape.Utils.isClockWise(e[0].getPoints());if(e.length==1){f=e[0];g=new THREE.Shape;g.actions=f.actions;g.curves=f.curves;d.push(g);return d}if(a){g=new THREE.Shape;a=0;for(b=e.length;a<
  22771. b;a++){f=e[a];if(THREE.Shape.Utils.isClockWise(f.getPoints())){g.actions=f.actions;g.curves=f.curves;d.push(g);g=new THREE.Shape}else g.holes.push(f)}}else{a=0;for(b=e.length;a<b;a++){f=e[a];if(THREE.Shape.Utils.isClockWise(f.getPoints())){g&&d.push(g);g=new THREE.Shape;g.actions=f.actions;g.curves=f.curves}else g.holes.push(f)}d.push(g)}return d};THREE.Shape=function(){THREE.Path.apply(this,arguments);this.holes=[]};THREE.Shape.prototype=new THREE.Path;THREE.Shape.prototype.constructor=THREE.Path;
  22772. THREE.Shape.prototype.extrude=function(a){return new THREE.ExtrudeGeometry(this,a)};THREE.Shape.prototype.getPointsHoles=function(a){var b,c=this.holes.length,d=[];for(b=0;b<c;b++)d[b]=this.holes[b].getTransformedPoints(a,this.bends);return d};THREE.Shape.prototype.getSpacedPointsHoles=function(a){var b,c=this.holes.length,d=[];for(b=0;b<c;b++)d[b]=this.holes[b].getTransformedSpacedPoints(a,this.bends);return d};
  22773. THREE.Shape.prototype.extractAllPoints=function(a){return{shape:this.getTransformedPoints(a),holes:this.getPointsHoles(a)}};THREE.Shape.prototype.extractPoints=function(a){return this.useSpacedPoints?this.extractAllSpacedPoints(a):this.extractAllPoints(a)};THREE.Shape.prototype.extractAllSpacedPoints=function(a){return{shape:this.getTransformedSpacedPoints(a),holes:this.getSpacedPointsHoles(a)}};
  22774. THREE.Shape.Utils={removeHoles:function(a,b){var c=a.concat(),d=c.concat(),e,f,g,h,k,j,l,p,m,o,q=[];for(k=0;k<b.length;k++){j=b[k];Array.prototype.push.apply(d,j);f=Number.POSITIVE_INFINITY;for(e=0;e<j.length;e++){m=j[e];o=[];for(p=0;p<c.length;p++){l=c[p];l=m.distanceToSquared(l);o.push(l);if(l<f){f=l;g=e;h=p}}}e=h-1>=0?h-1:c.length-1;f=g-1>=0?g-1:j.length-1;var n=[j[g],c[h],c[e]];p=THREE.FontUtils.Triangulate.area(n);var r=[j[g],j[f],c[h]];m=THREE.FontUtils.Triangulate.area(r);o=h;l=g;h=h+1;g=g+
  22775. -1;h<0&&(h=h+c.length);h=h%c.length;g<0&&(g=g+j.length);g=g%j.length;e=h-1>=0?h-1:c.length-1;f=g-1>=0?g-1:j.length-1;n=[j[g],c[h],c[e]];n=THREE.FontUtils.Triangulate.area(n);r=[j[g],j[f],c[h]];r=THREE.FontUtils.Triangulate.area(r);if(p+m>n+r){h=o;g=l;h<0&&(h=h+c.length);h=h%c.length;g<0&&(g=g+j.length);g=g%j.length;e=h-1>=0?h-1:c.length-1;f=g-1>=0?g-1:j.length-1}p=c.slice(0,h);m=c.slice(h);o=j.slice(g);l=j.slice(0,g);f=[j[g],j[f],c[h]];q.push([j[g],c[h],c[e]]);q.push(f);c=p.concat(o).concat(l).concat(m)}return{shape:c,
  22776. isolatedPts:q,allpoints:d}},triangulateShape:function(a,b){var c=THREE.Shape.Utils.removeHoles(a,b),d=c.allpoints,e=c.isolatedPts,c=THREE.FontUtils.Triangulate(c.shape,false),f,g,h,k,j={};f=0;for(g=d.length;f<g;f++){k=d[f].x+":"+d[f].y;j[k]!==void 0&&console.log("Duplicate point",k);j[k]=f}f=0;for(g=c.length;f<g;f++){h=c[f];for(d=0;d<3;d++){k=h[d].x+":"+h[d].y;k=j[k];k!==void 0&&(h[d]=k)}}f=0;for(g=e.length;f<g;f++){h=e[f];for(d=0;d<3;d++){k=h[d].x+":"+h[d].y;k=j[k];k!==void 0&&(h[d]=k)}}return c.concat(e)},
  22777. isClockWise:function(a){return THREE.FontUtils.Triangulate.area(a)<0},b2p0:function(a,b){var c=1-a;return c*c*b},b2p1:function(a,b){return 2*(1-a)*a*b},b2p2:function(a,b){return a*a*b},b2:function(a,b,c,d){return this.b2p0(a,b)+this.b2p1(a,c)+this.b2p2(a,d)},b3p0:function(a,b){var c=1-a;return c*c*c*b},b3p1:function(a,b){var c=1-a;return 3*c*c*a*b},b3p2:function(a,b){return 3*(1-a)*a*a*b},b3p3:function(a,b){return a*a*a*b},b3:function(a,b,c,d,e){return this.b3p0(a,b)+this.b3p1(a,c)+this.b3p2(a,d)+
  22778. this.b3p3(a,e)}};THREE.TextPath=function(a,b){THREE.Path.call(this);this.parameters=b||{};this.set(a)};THREE.TextPath.prototype.set=function(a,b){b=b||this.parameters;this.text=a;var c=b.curveSegments!==void 0?b.curveSegments:4,d=b.font!==void 0?b.font:"helvetiker",e=b.weight!==void 0?b.weight:"normal",f=b.style!==void 0?b.style:"normal";THREE.FontUtils.size=b.size!==void 0?b.size:100;THREE.FontUtils.divisions=c;THREE.FontUtils.face=d;THREE.FontUtils.weight=e;THREE.FontUtils.style=f};
  22779. THREE.TextPath.prototype.toShapes=function(){for(var a=THREE.FontUtils.drawText(this.text).paths,b=[],c=0,d=a.length;c<d;c++)Array.prototype.push.apply(b,a[c].toShapes());return b};
  22780. THREE.AnimationHandler=function(){var a=[],b={},c={update:function(b){for(var c=0;c<a.length;c++)a[c].update(b)},addToUpdate:function(b){a.indexOf(b)===-1&&a.push(b)},removeFromUpdate:function(b){b=a.indexOf(b);b!==-1&&a.splice(b,1)},add:function(a){b[a.name]!==void 0&&console.log("THREE.AnimationHandler.add: Warning! "+a.name+" already exists in library. Overwriting.");b[a.name]=a;if(a.initialized!==true){for(var c=0;c<a.hierarchy.length;c++){for(var d=0;d<a.hierarchy[c].keys.length;d++){if(a.hierarchy[c].keys[d].time<
  22781. 0)a.hierarchy[c].keys[d].time=0;if(a.hierarchy[c].keys[d].rot!==void 0&&!(a.hierarchy[c].keys[d].rot instanceof THREE.Quaternion)){var h=a.hierarchy[c].keys[d].rot;a.hierarchy[c].keys[d].rot=new THREE.Quaternion(h[0],h[1],h[2],h[3])}}if(a.hierarchy[c].keys.length&&a.hierarchy[c].keys[0].morphTargets!==void 0){h={};for(d=0;d<a.hierarchy[c].keys.length;d++)for(var k=0;k<a.hierarchy[c].keys[d].morphTargets.length;k++){var j=a.hierarchy[c].keys[d].morphTargets[k];h[j]=-1}a.hierarchy[c].usedMorphTargets=
  22782. h;for(d=0;d<a.hierarchy[c].keys.length;d++){var l={};for(j in h){for(k=0;k<a.hierarchy[c].keys[d].morphTargets.length;k++)if(a.hierarchy[c].keys[d].morphTargets[k]===j){l[j]=a.hierarchy[c].keys[d].morphTargetsInfluences[k];break}k===a.hierarchy[c].keys[d].morphTargets.length&&(l[j]=0)}a.hierarchy[c].keys[d].morphTargetsInfluences=l}}for(d=1;d<a.hierarchy[c].keys.length;d++)if(a.hierarchy[c].keys[d].time===a.hierarchy[c].keys[d-1].time){a.hierarchy[c].keys.splice(d,1);d--}for(d=0;d<a.hierarchy[c].keys.length;d++)a.hierarchy[c].keys[d].index=
  22783. d}d=parseInt(a.length*a.fps,10);a.JIT={};a.JIT.hierarchy=[];for(c=0;c<a.hierarchy.length;c++)a.JIT.hierarchy.push(Array(d));a.initialized=true}},get:function(a){if(typeof a==="string"){if(b[a])return b[a];console.log("THREE.AnimationHandler.get: Couldn't find animation "+a);return null}},parse:function(a){var b=[];if(a instanceof THREE.SkinnedMesh)for(var c=0;c<a.bones.length;c++)b.push(a.bones[c]);else d(a,b);return b}},d=function(a,b){b.push(a);for(var c=0;c<a.children.length;c++)d(a.children[c],
  22784. b)};c.LINEAR=0;c.CATMULLROM=1;c.CATMULLROM_FORWARD=2;return c}();THREE.Animation=function(a,b,c,d){this.root=a;this.data=THREE.AnimationHandler.get(b);this.hierarchy=THREE.AnimationHandler.parse(a);this.currentTime=0;this.timeScale=1;this.isPlaying=false;this.loop=this.isPaused=true;this.interpolationType=c!==void 0?c:THREE.AnimationHandler.LINEAR;this.JITCompile=d!==void 0?d:true;this.points=[];this.target=new THREE.Vector3};
  22785. THREE.Animation.prototype.play=function(a,b){if(!this.isPlaying){this.isPlaying=true;this.loop=a!==void 0?a:true;this.currentTime=b!==void 0?b:0;var c,d=this.hierarchy.length,e;for(c=0;c<d;c++){e=this.hierarchy[c];if(this.interpolationType!==THREE.AnimationHandler.CATMULLROM_FORWARD)e.useQuaternion=true;e.matrixAutoUpdate=true;if(e.animationCache===void 0){e.animationCache={};e.animationCache.prevKey={pos:0,rot:0,scl:0};e.animationCache.nextKey={pos:0,rot:0,scl:0};e.animationCache.originalMatrix=
  22786. e instanceof THREE.Bone?e.skinMatrix:e.matrix}var f=e.animationCache.prevKey;e=e.animationCache.nextKey;f.pos=this.data.hierarchy[c].keys[0];f.rot=this.data.hierarchy[c].keys[0];f.scl=this.data.hierarchy[c].keys[0];e.pos=this.getNextKeyWith("pos",c,1);e.rot=this.getNextKeyWith("rot",c,1);e.scl=this.getNextKeyWith("scl",c,1)}this.update(0)}this.isPaused=false;THREE.AnimationHandler.addToUpdate(this)};
  22787. THREE.Animation.prototype.pause=function(){this.isPaused?THREE.AnimationHandler.addToUpdate(this):THREE.AnimationHandler.removeFromUpdate(this);this.isPaused=!this.isPaused};
  22788. THREE.Animation.prototype.stop=function(){this.isPaused=this.isPlaying=false;THREE.AnimationHandler.removeFromUpdate(this);for(var a=0;a<this.hierarchy.length;a++)if(this.hierarchy[a].animationCache!==void 0){this.hierarchy[a]instanceof THREE.Bone?this.hierarchy[a].skinMatrix=this.hierarchy[a].animationCache.originalMatrix:this.hierarchy[a].matrix=this.hierarchy[a].animationCache.originalMatrix;delete this.hierarchy[a].animationCache}};
  22789. THREE.Animation.prototype.update=function(a){if(this.isPlaying){var b=["pos","rot","scl"],c,d,e,f,g,h,k,j,l=this.data.JIT.hierarchy,p,m;m=this.currentTime=this.currentTime+a*this.timeScale;p=this.currentTime=this.currentTime%this.data.length;j=parseInt(Math.min(p*this.data.fps,this.data.length*this.data.fps),10);for(var o=0,q=this.hierarchy.length;o<q;o++){a=this.hierarchy[o];k=a.animationCache;if(this.JITCompile&&l[o][j]!==void 0)if(a instanceof THREE.Bone){a.skinMatrix=l[o][j];a.matrixAutoUpdate=
  22790. false;a.matrixWorldNeedsUpdate=false}else{a.matrix=l[o][j];a.matrixAutoUpdate=false;a.matrixWorldNeedsUpdate=true}else{if(this.JITCompile)a instanceof THREE.Bone?a.skinMatrix=a.animationCache.originalMatrix:a.matrix=a.animationCache.originalMatrix;for(var n=0;n<3;n++){c=b[n];g=k.prevKey[c];h=k.nextKey[c];if(h.time<=m){if(p<m)if(this.loop){g=this.data.hierarchy[o].keys[0];for(h=this.getNextKeyWith(c,o,1);h.time<p;){g=h;h=this.getNextKeyWith(c,o,h.index+1)}}else{this.stop();return}else{do{g=h;h=this.getNextKeyWith(c,
  22791. o,h.index+1)}while(h.time<p)}k.prevKey[c]=g;k.nextKey[c]=h}a.matrixAutoUpdate=true;a.matrixWorldNeedsUpdate=true;d=(p-g.time)/(h.time-g.time);e=g[c];f=h[c];if(d<0||d>1){console.log("THREE.Animation.update: Warning! Scale out of bounds:"+d+" on bone "+o);d=d<0?0:1}if(c==="pos"){c=a.position;if(this.interpolationType===THREE.AnimationHandler.LINEAR){c.x=e[0]+(f[0]-e[0])*d;c.y=e[1]+(f[1]-e[1])*d;c.z=e[2]+(f[2]-e[2])*d}else if(this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===
  22792. THREE.AnimationHandler.CATMULLROM_FORWARD){this.points[0]=this.getPrevKeyWith("pos",o,g.index-1).pos;this.points[1]=e;this.points[2]=f;this.points[3]=this.getNextKeyWith("pos",o,h.index+1).pos;d=d*0.33+0.33;e=this.interpolateCatmullRom(this.points,d);c.x=e[0];c.y=e[1];c.z=e[2];if(this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD){d=this.interpolateCatmullRom(this.points,d*1.01);this.target.set(d[0],d[1],d[2]);this.target.subSelf(c);this.target.y=0;this.target.normalize();d=Math.atan2(this.target.x,
  22793. this.target.z);a.rotation.set(0,d,0)}}}else if(c==="rot")THREE.Quaternion.slerp(e,f,a.quaternion,d);else if(c==="scl"){c=a.scale;c.x=e[0]+(f[0]-e[0])*d;c.y=e[1]+(f[1]-e[1])*d;c.z=e[2]+(f[2]-e[2])*d}}}}if(this.JITCompile&&l[0][j]===void 0){this.hierarchy[0].updateMatrixWorld(true);for(o=0;o<this.hierarchy.length;o++)l[o][j]=this.hierarchy[o]instanceof THREE.Bone?this.hierarchy[o].skinMatrix.clone():this.hierarchy[o].matrix.clone()}}};
  22794. THREE.Animation.prototype.interpolateCatmullRom=function(a,b){var c=[],d=[],e,f,g,h,k,j;e=(a.length-1)*b;f=Math.floor(e);e=e-f;c[0]=f===0?f:f-1;c[1]=f;c[2]=f>a.length-2?f:f+1;c[3]=f>a.length-3?f:f+2;f=a[c[0]];h=a[c[1]];k=a[c[2]];j=a[c[3]];c=e*e;g=e*c;d[0]=this.interpolate(f[0],h[0],k[0],j[0],e,c,g);d[1]=this.interpolate(f[1],h[1],k[1],j[1],e,c,g);d[2]=this.interpolate(f[2],h[2],k[2],j[2],e,c,g);return d};
  22795. THREE.Animation.prototype.interpolate=function(a,b,c,d,e,f,g){a=(c-a)*0.5;d=(d-b)*0.5;return(2*(b-c)+a+d)*g+(-3*(b-c)-2*a-d)*f+a*e+b};THREE.Animation.prototype.getNextKeyWith=function(a,b,c){for(var d=this.data.hierarchy[b].keys,c=this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD?c<d.length-1?c:d.length-1:c%d.length;c<d.length;c++)if(d[c][a]!==void 0)return d[c];return this.data.hierarchy[b].keys[0]};
  22796. THREE.Animation.prototype.getPrevKeyWith=function(a,b,c){for(var d=this.data.hierarchy[b].keys,c=this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD?c>0?c:0:c>=0?c:c+d.length;c>=0;c--)if(d[c][a]!==void 0)return d[c];return this.data.hierarchy[b].keys[d.length-1]};
  22797. THREE.KeyFrameAnimation=function(a,b,c){this.root=a;this.data=THREE.AnimationHandler.get(b);this.hierarchy=THREE.AnimationHandler.parse(a);this.currentTime=0;this.timeScale=0.001;this.isPlaying=false;this.loop=this.isPaused=true;this.JITCompile=c!==void 0?c:true;a=0;for(b=this.hierarchy.length;a<b;a++){var c=this.data.hierarchy[a].sids,d=this.hierarchy[a];if(this.data.hierarchy[a].keys.length&&c){for(var e=0;e<c.length;e++){var f=c[e],g=this.getNextKeyWith(f,a,0);g&&g.apply(f)}d.matrixAutoUpdate=
  22798. false;this.data.hierarchy[a].node.updateMatrix();d.matrixWorldNeedsUpdate=true}}};
  22799. THREE.KeyFrameAnimation.prototype.play=function(a,b){if(!this.isPlaying){this.isPlaying=true;this.loop=a!==void 0?a:true;this.currentTime=b!==void 0?b:0;this.startTimeMs=b;this.startTime=1E7;this.endTime=-this.startTime;var c,d=this.hierarchy.length,e,f;for(c=0;c<d;c++){e=this.hierarchy[c];f=this.data.hierarchy[c];e.useQuaternion=true;if(f.animationCache===void 0){f.animationCache={};f.animationCache.prevKey=null;f.animationCache.nextKey=null;f.animationCache.originalMatrix=e instanceof THREE.Bone?
  22800. e.skinMatrix:e.matrix}e=this.data.hierarchy[c].keys;if(e.length){f.animationCache.prevKey=e[0];f.animationCache.nextKey=e[1];this.startTime=Math.min(e[0].time,this.startTime);this.endTime=Math.max(e[e.length-1].time,this.endTime)}}this.update(0)}this.isPaused=false;THREE.AnimationHandler.addToUpdate(this)};THREE.KeyFrameAnimation.prototype.pause=function(){this.isPaused?THREE.AnimationHandler.addToUpdate(this):THREE.AnimationHandler.removeFromUpdate(this);this.isPaused=!this.isPaused};
  22801. THREE.KeyFrameAnimation.prototype.stop=function(){this.isPaused=this.isPlaying=false;THREE.AnimationHandler.removeFromUpdate(this);for(var a=0;a<this.data.hierarchy.length;a++){var b=this.hierarchy[a],c=this.data.hierarchy[a];if(c.animationCache!==void 0){var d=c.animationCache.originalMatrix;if(b instanceof THREE.Bone){d.copy(b.skinMatrix);b.skinMatrix=d}else{d.copy(b.matrix);b.matrix=d}delete c.animationCache}}};
  22802. THREE.KeyFrameAnimation.prototype.update=function(a){if(this.isPlaying){var b,c,d,e,f=this.data.JIT.hierarchy,g,h,k;h=this.currentTime=this.currentTime+a*this.timeScale;g=this.currentTime=this.currentTime%this.data.length;if(g<this.startTimeMs)g=this.currentTime=this.startTimeMs+g;e=parseInt(Math.min(g*this.data.fps,this.data.length*this.data.fps),10);if((k=g<h)&&!this.loop){for(var a=0,j=this.hierarchy.length;a<j;a++){var l=this.data.hierarchy[a].keys,f=this.data.hierarchy[a].sids;d=l.length-1;e=
  22803. this.hierarchy[a];if(l.length){for(l=0;l<f.length;l++){g=f[l];(h=this.getPrevKeyWith(g,a,d))&&h.apply(g)}this.data.hierarchy[a].node.updateMatrix();e.matrixWorldNeedsUpdate=true}}this.stop()}else if(!(g<this.startTime)){a=0;for(j=this.hierarchy.length;a<j;a++){d=this.hierarchy[a];b=this.data.hierarchy[a];var l=b.keys,p=b.animationCache;if(this.JITCompile&&f[a][e]!==void 0)if(d instanceof THREE.Bone){d.skinMatrix=f[a][e];d.matrixWorldNeedsUpdate=false}else{d.matrix=f[a][e];d.matrixWorldNeedsUpdate=
  22804. true}else if(l.length){if(this.JITCompile&&p)d instanceof THREE.Bone?d.skinMatrix=p.originalMatrix:d.matrix=p.originalMatrix;b=p.prevKey;c=p.nextKey;if(b&&c){if(c.time<=h){if(k&&this.loop){b=l[0];for(c=l[1];c.time<g;){b=c;c=l[b.index+1]}}else if(!k)for(var m=l.length-1;c.time<g&&c.index!==m;){b=c;c=l[b.index+1]}p.prevKey=b;p.nextKey=c}c.time>=g?b.interpolate(c,g):b.interpolate(c,c.time)}this.data.hierarchy[a].node.updateMatrix();d.matrixWorldNeedsUpdate=true}}if(this.JITCompile&&f[0][e]===void 0){this.hierarchy[0].updateMatrixWorld(true);
  22805. for(a=0;a<this.hierarchy.length;a++)f[a][e]=this.hierarchy[a]instanceof THREE.Bone?this.hierarchy[a].skinMatrix.clone():this.hierarchy[a].matrix.clone()}}}};THREE.KeyFrameAnimation.prototype.getNextKeyWith=function(a,b,c){b=this.data.hierarchy[b].keys;for(c=c%b.length;c<b.length;c++)if(b[c].hasTarget(a))return b[c];return b[0]};
  22806. THREE.KeyFrameAnimation.prototype.getPrevKeyWith=function(a,b,c){b=this.data.hierarchy[b].keys;for(c=c>=0?c:c+b.length;c>=0;c--)if(b[c].hasTarget(a))return b[c];return b[b.length-1]};
  22807. THREE.CubeCamera=function(a,b,c){THREE.Object3D.call(this);var d=new THREE.PerspectiveCamera(90,1,a,b);d.up.set(0,-1,0);d.lookAt(new THREE.Vector3(1,0,0));this.add(d);var e=new THREE.PerspectiveCamera(90,1,a,b);e.up.set(0,-1,0);e.lookAt(new THREE.Vector3(-1,0,0));this.add(e);var f=new THREE.PerspectiveCamera(90,1,a,b);f.up.set(0,0,1);f.lookAt(new THREE.Vector3(0,1,0));this.add(f);var g=new THREE.PerspectiveCamera(90,1,a,b);g.up.set(0,0,-1);g.lookAt(new THREE.Vector3(0,-1,0));this.add(g);var h=new THREE.PerspectiveCamera(90,
  22808. 1,a,b);h.up.set(0,-1,0);h.lookAt(new THREE.Vector3(0,0,1));this.add(h);var k=new THREE.PerspectiveCamera(90,1,a,b);k.up.set(0,-1,0);k.lookAt(new THREE.Vector3(0,0,-1));this.add(k);this.renderTarget=new THREE.WebGLRenderTargetCube(c,c,{format:THREE.RGBFormat,magFilter:THREE.LinearFilter,minFilter:THREE.LinearFilter});this.updateCubeMap=function(a,b){var c=this.renderTarget,m=c.generateMipmaps;c.generateMipmaps=false;c.activeCubeFace=0;a.render(b,d,c);c.activeCubeFace=1;a.render(b,e,c);c.activeCubeFace=
  22809. 2;a.render(b,f,c);c.activeCubeFace=3;a.render(b,g,c);c.activeCubeFace=4;a.render(b,h,c);c.generateMipmaps=m;c.activeCubeFace=5;a.render(b,k,c)}};THREE.CubeCamera.prototype=new THREE.Object3D;THREE.CubeCamera.prototype.constructor=THREE.CubeCamera;
  22810. THREE.CombinedCamera=function(a,b,c,d,e,f,g){THREE.Camera.call(this);this.fov=c;this.left=-a/2;this.right=a/2;this.top=b/2;this.bottom=-b/2;this.cameraO=new THREE.OrthographicCamera(a/-2,a/2,b/2,b/-2,f,g);this.cameraP=new THREE.PerspectiveCamera(c,a/b,d,e);this.zoom=1;this.toPerspective()};THREE.CombinedCamera.prototype=new THREE.Camera;THREE.CombinedCamera.prototype.constructor=THREE.CombinedCamera;
  22811. THREE.CombinedCamera.prototype.toPerspective=function(){this.near=this.cameraP.near;this.far=this.cameraP.far;this.cameraP.fov=this.fov/this.zoom;this.cameraP.updateProjectionMatrix();this.projectionMatrix=this.cameraP.projectionMatrix;this.inPersepectiveMode=true;this.inOrthographicMode=false};
  22812. THREE.CombinedCamera.prototype.toOrthographic=function(){var a=this.cameraP.aspect,b=(this.cameraP.near+this.cameraP.far)/2,b=Math.tan(this.fov/2)*b,a=2*b*a/2,b=b/this.zoom,a=a/this.zoom;this.cameraO.left=-a;this.cameraO.right=a;this.cameraO.top=b;this.cameraO.bottom=-b;this.cameraO.updateProjectionMatrix();this.near=this.cameraO.near;this.far=this.cameraO.far;this.projectionMatrix=this.cameraO.projectionMatrix;this.inPersepectiveMode=false;this.inOrthographicMode=true};
  22813. THREE.CombinedCamera.prototype.setSize=function(a,b){this.cameraP.aspect=a/b;this.left=-a/2;this.right=a/2;this.top=b/2;this.bottom=-b/2};THREE.CombinedCamera.prototype.setFov=function(a){this.fov=a;this.inPersepectiveMode?this.toPerspective():this.toOrthographic()};THREE.CombinedCamera.prototype.updateProjectionMatrix=function(){if(this.inPersepectiveMode)this.toPerspective();else{this.toPerspective();this.toOrthographic()}};
  22814. THREE.CombinedCamera.prototype.setLens=function(a,b){var c=2*Math.atan((b!==void 0?b:24)/(a*2))*(180/Math.PI);this.setFov(c);return c};THREE.CombinedCamera.prototype.setZoom=function(a){this.zoom=a;this.inPersepectiveMode?this.toPerspective():this.toOrthographic()};THREE.CombinedCamera.prototype.toFrontView=function(){this.rotation.x=0;this.rotation.y=0;this.rotation.z=0;this.rotationAutoUpdate=false};
  22815. THREE.CombinedCamera.prototype.toBackView=function(){this.rotation.x=0;this.rotation.y=Math.PI;this.rotation.z=0;this.rotationAutoUpdate=false};THREE.CombinedCamera.prototype.toLeftView=function(){this.rotation.x=0;this.rotation.y=-Math.PI/2;this.rotation.z=0;this.rotationAutoUpdate=false};THREE.CombinedCamera.prototype.toRightView=function(){this.rotation.x=0;this.rotation.y=Math.PI/2;this.rotation.z=0;this.rotationAutoUpdate=false};
  22816. THREE.CombinedCamera.prototype.toTopView=function(){this.rotation.x=-Math.PI/2;this.rotation.y=0;this.rotation.z=0;this.rotationAutoUpdate=false};THREE.CombinedCamera.prototype.toBottomView=function(){this.rotation.x=Math.PI/2;this.rotation.y=0;this.rotation.z=0;this.rotationAutoUpdate=false};
  22817. THREE.FirstPersonControls=function(a,b){function c(a,b){return function(){b.apply(a,arguments)}}this.object=a;this.target=new THREE.Vector3(0,0,0);this.domElement=b!==void 0?b:document;this.movementSpeed=1;this.lookSpeed=0.005;this.noFly=false;this.lookVertical=true;this.autoForward=false;this.activeLook=true;this.heightSpeed=false;this.heightCoef=1;this.heightMin=0;this.constrainVertical=false;this.verticalMin=0;this.verticalMax=Math.PI;this.theta=this.phi=this.lon=this.lat=this.mouseY=this.mouseX=
  22818. this.autoSpeedFactor=0;this.mouseDragOn=this.freeze=this.moveRight=this.moveLeft=this.moveBackward=this.moveForward=false;if(this.domElement===document){this.viewHalfX=window.innerWidth/2;this.viewHalfY=window.innerHeight/2}else{this.viewHalfX=this.domElement.offsetWidth/2;this.viewHalfY=this.domElement.offsetHeight/2;this.domElement.setAttribute("tabindex",-1)}this.onMouseDown=function(a){this.domElement!==document&&this.domElement.focus();a.preventDefault();a.stopPropagation();if(this.activeLook)switch(a.button){case 0:this.moveForward=
  22819. true;break;case 2:this.moveBackward=true}this.mouseDragOn=true};this.onMouseUp=function(a){a.preventDefault();a.stopPropagation();if(this.activeLook)switch(a.button){case 0:this.moveForward=false;break;case 2:this.moveBackward=false}this.mouseDragOn=false};this.onMouseMove=function(a){if(this.domElement===document){this.mouseX=a.pageX-this.viewHalfX;this.mouseY=a.pageY-this.viewHalfY}else{this.mouseX=a.pageX-this.domElement.offsetLeft-this.viewHalfX;this.mouseY=a.pageY-this.domElement.offsetTop-this.viewHalfY}};
  22820. this.onKeyDown=function(a){switch(a.keyCode){case 38:case 87:this.moveForward=true;break;case 37:case 65:this.moveLeft=true;break;case 40:case 83:this.moveBackward=true;break;case 39:case 68:this.moveRight=true;break;case 82:this.moveUp=true;break;case 70:this.moveDown=true;break;case 81:this.freeze=!this.freeze}};this.onKeyUp=function(a){switch(a.keyCode){case 38:case 87:this.moveForward=false;break;case 37:case 65:this.moveLeft=false;break;case 40:case 83:this.moveBackward=false;break;case 39:case 68:this.moveRight=
  22821. false;break;case 82:this.moveUp=false;break;case 70:this.moveDown=false}};this.update=function(a){var b=0;if(!this.freeze){if(this.heightSpeed){b=THREE.Math.clamp(this.object.position.y,this.heightMin,this.heightMax)-this.heightMin;this.autoSpeedFactor=a*b*this.heightCoef}else this.autoSpeedFactor=0;b=a*this.movementSpeed;(this.moveForward||this.autoForward&&!this.moveBackward)&&this.object.translateZ(-(b+this.autoSpeedFactor));this.moveBackward&&this.object.translateZ(b);this.moveLeft&&this.object.translateX(-b);
  22822. this.moveRight&&this.object.translateX(b);this.moveUp&&this.object.translateY(b);this.moveDown&&this.object.translateY(-b);a=a*this.lookSpeed;this.activeLook||(a=0);this.lon=this.lon+this.mouseX*a;if(this.lookVertical)this.lat=this.lat-this.mouseY*a;this.lat=Math.max(-85,Math.min(85,this.lat));this.phi=(90-this.lat)*Math.PI/180;this.theta=this.lon*Math.PI/180;var b=this.target,c=this.object.position;b.x=c.x+100*Math.sin(this.phi)*Math.cos(this.theta);b.y=c.y+100*Math.cos(this.phi);b.z=c.z+100*Math.sin(this.phi)*
  22823. Math.sin(this.theta);b=1;this.constrainVertical&&(b=Math.PI/(this.verticalMax-this.verticalMin));this.lon=this.lon+this.mouseX*a;if(this.lookVertical)this.lat=this.lat-this.mouseY*a*b;this.lat=Math.max(-85,Math.min(85,this.lat));this.phi=(90-this.lat)*Math.PI/180;this.theta=this.lon*Math.PI/180;if(this.constrainVertical)this.phi=THREE.Math.mapLinear(this.phi,0,Math.PI,this.verticalMin,this.verticalMax);b=this.target;c=this.object.position;b.x=c.x+100*Math.sin(this.phi)*Math.cos(this.theta);b.y=c.y+
  22824. 100*Math.cos(this.phi);b.z=c.z+100*Math.sin(this.phi)*Math.sin(this.theta);this.object.lookAt(b)}};this.domElement.addEventListener("contextmenu",function(a){a.preventDefault()},false);this.domElement.addEventListener("mousemove",c(this,this.onMouseMove),false);this.domElement.addEventListener("mousedown",c(this,this.onMouseDown),false);this.domElement.addEventListener("mouseup",c(this,this.onMouseUp),false);this.domElement.addEventListener("keydown",c(this,this.onKeyDown),false);this.domElement.addEventListener("keyup",
  22825. c(this,this.onKeyUp),false)};
  22826. THREE.PathControls=function(a,b){function c(a){return(a=a*2)<1?0.5*a*a:-0.5*(--a*(a-2)-1)}function d(a,b){return function(){b.apply(a,arguments)}}function e(a,b,c,d){var e={name:c,fps:0.6,length:d,hierarchy:[]},f,g=b.getControlPointsArray(),h=b.getLength(),r=g.length,u=0;f=r-1;b={parent:-1,keys:[]};b.keys[0]={time:0,pos:g[0],rot:[0,0,0,1],scl:[1,1,1]};b.keys[f]={time:d,pos:g[f],rot:[0,0,0,1],scl:[1,1,1]};for(f=1;f<r-1;f++){u=d*h.chunks[f]/h.total;b.keys[f]={time:u,pos:g[f]}}e.hierarchy[0]=b;THREE.AnimationHandler.add(e);
  22827. return new THREE.Animation(a,c,THREE.AnimationHandler.CATMULLROM_FORWARD,false)}function f(a,b){var c,d,e=new THREE.Geometry;for(c=0;c<a.points.length*b;c++){d=c/(a.points.length*b);d=a.getPoint(d);e.vertices[c]=new THREE.Vector3(d.x,d.y,d.z)}return e}this.object=a;this.domElement=b!==void 0?b:document;this.id="PathControls"+THREE.PathControlsIdCounter++;this.duration=1E4;this.waypoints=[];this.useConstantSpeed=true;this.resamplingCoef=50;this.debugPath=new THREE.Object3D;this.debugDummy=new THREE.Object3D;
  22828. this.animationParent=new THREE.Object3D;this.lookSpeed=0.005;this.lookHorizontal=this.lookVertical=true;this.verticalAngleMap={srcRange:[0,2*Math.PI],dstRange:[0,2*Math.PI]};this.horizontalAngleMap={srcRange:[0,2*Math.PI],dstRange:[0,2*Math.PI]};this.target=new THREE.Object3D;this.theta=this.phi=this.lon=this.lat=this.mouseY=this.mouseX=0;if(this.domElement===document){this.viewHalfX=window.innerWidth/2;this.viewHalfY=window.innerHeight/2}else{this.viewHalfX=this.domElement.offsetWidth/2;this.viewHalfY=
  22829. this.domElement.offsetHeight/2;this.domElement.setAttribute("tabindex",-1)}var g=Math.PI*2,h=Math.PI/180;this.update=function(a){var b;if(this.lookHorizontal)this.lon=this.lon+this.mouseX*this.lookSpeed*a;if(this.lookVertical)this.lat=this.lat-this.mouseY*this.lookSpeed*a;this.lon=Math.max(0,Math.min(360,this.lon));this.lat=Math.max(-85,Math.min(85,this.lat));this.phi=(90-this.lat)*h;this.theta=this.lon*h;a=this.phi%g;this.phi=a>=0?a:a+g;b=this.verticalAngleMap.srcRange;a=this.verticalAngleMap.dstRange;
  22830. b=THREE.Math.mapLinear(this.phi,b[0],b[1],a[0],a[1]);var d=a[1]-a[0];this.phi=c((b-a[0])/d)*d+a[0];b=this.horizontalAngleMap.srcRange;a=this.horizontalAngleMap.dstRange;b=THREE.Math.mapLinear(this.theta,b[0],b[1],a[0],a[1]);d=a[1]-a[0];this.theta=c((b-a[0])/d)*d+a[0];a=this.target.position;a.x=100*Math.sin(this.phi)*Math.cos(this.theta);a.y=100*Math.cos(this.phi);a.z=100*Math.sin(this.phi)*Math.sin(this.theta);this.object.lookAt(this.target.position)};this.onMouseMove=function(a){if(this.domElement===
  22831. document){this.mouseX=a.pageX-this.viewHalfX;this.mouseY=a.pageY-this.viewHalfY}else{this.mouseX=a.pageX-this.domElement.offsetLeft-this.viewHalfX;this.mouseY=a.pageY-this.domElement.offsetTop-this.viewHalfY}};this.init=function(){this.spline=new THREE.Spline;this.spline.initFromArray(this.waypoints);this.useConstantSpeed&&this.spline.reparametrizeByArcLength(this.resamplingCoef);if(this.createDebugDummy){var a=new THREE.MeshLambertMaterial({color:30719}),b=new THREE.MeshLambertMaterial({color:65280}),
  22832. c=new THREE.CubeGeometry(10,10,20),g=new THREE.CubeGeometry(2,2,10);this.animationParent=new THREE.Mesh(c,a);a=new THREE.Mesh(g,b);a.position.set(0,10,0);this.animation=e(this.animationParent,this.spline,this.id,this.duration);this.animationParent.add(this.object);this.animationParent.add(this.target);this.animationParent.add(a)}else{this.animation=e(this.animationParent,this.spline,this.id,this.duration);this.animationParent.add(this.target);this.animationParent.add(this.object)}if(this.createDebugPath){var a=
  22833. this.debugPath,b=this.spline,g=f(b,10),c=f(b,10),h=new THREE.LineBasicMaterial({color:16711680,linewidth:3}),g=new THREE.Line(g,h),c=new THREE.ParticleSystem(c,new THREE.ParticleBasicMaterial({color:16755200,size:3}));g.scale.set(1,1,1);a.add(g);c.scale.set(1,1,1);a.add(c);for(var g=new THREE.SphereGeometry(1,16,8),h=new THREE.MeshBasicMaterial({color:65280}),o=0;o<b.points.length;o++){c=new THREE.Mesh(g,h);c.position.copy(b.points[o]);a.add(c)}}this.domElement.addEventListener("mousemove",d(this,
  22834. this.onMouseMove),false)}};THREE.PathControlsIdCounter=0;
  22835. THREE.FlyControls=function(a,b){function c(a,b){return function(){b.apply(a,arguments)}}this.object=a;this.domElement=b!==void 0?b:document;b&&this.domElement.setAttribute("tabindex",-1);this.movementSpeed=1;this.rollSpeed=0.005;this.autoForward=this.dragToLook=false;this.object.useQuaternion=true;this.tmpQuaternion=new THREE.Quaternion;this.mouseStatus=0;this.moveState={up:0,down:0,left:0,right:0,forward:0,back:0,pitchUp:0,pitchDown:0,yawLeft:0,yawRight:0,rollLeft:0,rollRight:0};this.moveVector=
  22836. new THREE.Vector3(0,0,0);this.rotationVector=new THREE.Vector3(0,0,0);this.handleEvent=function(a){if(typeof this[a.type]=="function")this[a.type](a)};this.keydown=function(a){if(!a.altKey){switch(a.keyCode){case 16:this.movementSpeedMultiplier=0.1;break;case 87:this.moveState.forward=1;break;case 83:this.moveState.back=1;break;case 65:this.moveState.left=1;break;case 68:this.moveState.right=1;break;case 82:this.moveState.up=1;break;case 70:this.moveState.down=1;break;case 38:this.moveState.pitchUp=
  22837. 1;break;case 40:this.moveState.pitchDown=1;break;case 37:this.moveState.yawLeft=1;break;case 39:this.moveState.yawRight=1;break;case 81:this.moveState.rollLeft=1;break;case 69:this.moveState.rollRight=1}this.updateMovementVector();this.updateRotationVector()}};this.keyup=function(a){switch(a.keyCode){case 16:this.movementSpeedMultiplier=1;break;case 87:this.moveState.forward=0;break;case 83:this.moveState.back=0;break;case 65:this.moveState.left=0;break;case 68:this.moveState.right=0;break;case 82:this.moveState.up=
  22838. 0;break;case 70:this.moveState.down=0;break;case 38:this.moveState.pitchUp=0;break;case 40:this.moveState.pitchDown=0;break;case 37:this.moveState.yawLeft=0;break;case 39:this.moveState.yawRight=0;break;case 81:this.moveState.rollLeft=0;break;case 69:this.moveState.rollRight=0}this.updateMovementVector();this.updateRotationVector()};this.mousedown=function(a){this.domElement!==document&&this.domElement.focus();a.preventDefault();a.stopPropagation();if(this.dragToLook)this.mouseStatus++;else switch(a.button){case 0:this.object.moveForward=
  22839. true;break;case 2:this.object.moveBackward=true}};this.mousemove=function(a){if(!this.dragToLook||this.mouseStatus>0){var b=this.getContainerDimensions(),c=b.size[0]/2,g=b.size[1]/2;this.moveState.yawLeft=-(a.pageX-b.offset[0]-c)/c;this.moveState.pitchDown=(a.pageY-b.offset[1]-g)/g;this.updateRotationVector()}};this.mouseup=function(a){a.preventDefault();a.stopPropagation();if(this.dragToLook){this.mouseStatus--;this.moveState.yawLeft=this.moveState.pitchDown=0}else switch(a.button){case 0:this.moveForward=
  22840. false;break;case 2:this.moveBackward=false}this.updateRotationVector()};this.update=function(a){var b=a*this.movementSpeed,a=a*this.rollSpeed;this.object.translateX(this.moveVector.x*b);this.object.translateY(this.moveVector.y*b);this.object.translateZ(this.moveVector.z*b);this.tmpQuaternion.set(this.rotationVector.x*a,this.rotationVector.y*a,this.rotationVector.z*a,1).normalize();this.object.quaternion.multiplySelf(this.tmpQuaternion);this.object.matrix.setPosition(this.object.position);this.object.matrix.setRotationFromQuaternion(this.object.quaternion);
  22841. this.object.matrixWorldNeedsUpdate=true};this.updateMovementVector=function(){var a=this.moveState.forward||this.autoForward&&!this.moveState.back?1:0;this.moveVector.x=-this.moveState.left+this.moveState.right;this.moveVector.y=-this.moveState.down+this.moveState.up;this.moveVector.z=-a+this.moveState.back};this.updateRotationVector=function(){this.rotationVector.x=-this.moveState.pitchDown+this.moveState.pitchUp;this.rotationVector.y=-this.moveState.yawRight+this.moveState.yawLeft;this.rotationVector.z=
  22842. -this.moveState.rollRight+this.moveState.rollLeft};this.getContainerDimensions=function(){return this.domElement!=document?{size:[this.domElement.offsetWidth,this.domElement.offsetHeight],offset:[this.domElement.offsetLeft,this.domElement.offsetTop]}:{size:[window.innerWidth,window.innerHeight],offset:[0,0]}};this.domElement.addEventListener("mousemove",c(this,this.mousemove),false);this.domElement.addEventListener("mousedown",c(this,this.mousedown),false);this.domElement.addEventListener("mouseup",
  22843. c(this,this.mouseup),false);this.domElement.addEventListener("keydown",c(this,this.keydown),false);this.domElement.addEventListener("keyup",c(this,this.keyup),false);this.updateMovementVector();this.updateRotationVector()};
  22844. THREE.RollControls=function(a,b){this.object=a;this.domElement=b!==void 0?b:document;this.mouseLook=true;this.autoForward=false;this.rollSpeed=this.movementSpeed=this.lookSpeed=1;this.constrainVertical=[-0.9,0.9];this.object.matrixAutoUpdate=false;this.forward=new THREE.Vector3(0,0,1);this.roll=0;var c=new THREE.Vector3,d=new THREE.Vector3,e=new THREE.Vector3,f=new THREE.Matrix4,g=false,h=1,k=0,j=0,l=0,p=0,m=0,o=window.innerWidth/2,q=window.innerHeight/2;this.update=function(a){if(this.mouseLook){var b=
  22845. a*this.lookSpeed;this.rotateHorizontally(b*p);this.rotateVertically(b*m)}b=a*this.movementSpeed;this.object.translateZ(-b*(k>0||this.autoForward&&!(k<0)?1:k));this.object.translateX(b*j);this.object.translateY(b*l);if(g)this.roll=this.roll+this.rollSpeed*a*h;if(this.forward.y>this.constrainVertical[1]){this.forward.y=this.constrainVertical[1];this.forward.normalize()}else if(this.forward.y<this.constrainVertical[0]){this.forward.y=this.constrainVertical[0];this.forward.normalize()}e.copy(this.forward);
  22846. d.set(0,1,0);c.cross(d,e).normalize();d.cross(e,c).normalize();this.object.matrix.elements[0]=c.x;this.object.matrix.elements[4]=d.x;this.object.matrix.elements[8]=e.x;this.object.matrix.elements[1]=c.y;this.object.matrix.elements[5]=d.y;this.object.matrix.elements[9]=e.y;this.object.matrix.elements[2]=c.z;this.object.matrix.elements[6]=d.z;this.object.matrix.elements[10]=e.z;f.identity();f.elements[0]=Math.cos(this.roll);f.elements[4]=-Math.sin(this.roll);f.elements[1]=Math.sin(this.roll);f.elements[5]=
  22847. Math.cos(this.roll);this.object.matrix.multiplySelf(f);this.object.matrixWorldNeedsUpdate=true;this.object.matrix.elements[12]=this.object.position.x;this.object.matrix.elements[13]=this.object.position.y;this.object.matrix.elements[14]=this.object.position.z};this.translateX=function(a){this.object.position.x=this.object.position.x+this.object.matrix.elements[0]*a;this.object.position.y=this.object.position.y+this.object.matrix.elements[1]*a;this.object.position.z=this.object.position.z+this.object.matrix.elements[2]*
  22848. a};this.translateY=function(a){this.object.position.x=this.object.position.x+this.object.matrix.elements[4]*a;this.object.position.y=this.object.position.y+this.object.matrix.elements[5]*a;this.object.position.z=this.object.position.z+this.object.matrix.elements[6]*a};this.translateZ=function(a){this.object.position.x=this.object.position.x-this.object.matrix.elements[8]*a;this.object.position.y=this.object.position.y-this.object.matrix.elements[9]*a;this.object.position.z=this.object.position.z-
  22849. this.object.matrix.elements[10]*a};this.rotateHorizontally=function(a){c.set(this.object.matrix.elements[0],this.object.matrix.elements[1],this.object.matrix.elements[2]);c.multiplyScalar(a);this.forward.subSelf(c);this.forward.normalize()};this.rotateVertically=function(a){d.set(this.object.matrix.elements[4],this.object.matrix.elements[5],this.object.matrix.elements[6]);d.multiplyScalar(a);this.forward.addSelf(d);this.forward.normalize()};this.domElement.addEventListener("contextmenu",function(a){a.preventDefault()},
  22850. false);this.domElement.addEventListener("mousemove",function(a){p=(a.clientX-o)/window.innerWidth;m=(a.clientY-q)/window.innerHeight},false);this.domElement.addEventListener("mousedown",function(a){a.preventDefault();a.stopPropagation();switch(a.button){case 0:k=1;break;case 2:k=-1}},false);this.domElement.addEventListener("mouseup",function(a){a.preventDefault();a.stopPropagation();switch(a.button){case 0:k=0;break;case 2:k=0}},false);this.domElement.addEventListener("keydown",function(a){switch(a.keyCode){case 38:case 87:k=
  22851. 1;break;case 37:case 65:j=-1;break;case 40:case 83:k=-1;break;case 39:case 68:j=1;break;case 81:g=true;h=1;break;case 69:g=true;h=-1;break;case 82:l=1;break;case 70:l=-1}},false);this.domElement.addEventListener("keyup",function(a){switch(a.keyCode){case 38:case 87:k=0;break;case 37:case 65:j=0;break;case 40:case 83:k=0;break;case 39:case 68:j=0;break;case 81:g=false;break;case 69:g=false;break;case 82:l=0;break;case 70:l=0}},false)};
  22852. THREE.TrackballControls=function(a,b){THREE.EventTarget.call(this);var c=this;this.object=a;this.domElement=b!==void 0?b:document;this.enabled=true;this.screen={width:window.innerWidth,height:window.innerHeight,offsetLeft:0,offsetTop:0};this.radius=(this.screen.width+this.screen.height)/4;this.rotateSpeed=1;this.zoomSpeed=1.2;this.panSpeed=0.3;this.staticMoving=this.noPan=this.noZoom=this.noRotate=false;this.dynamicDampingFactor=0.2;this.minDistance=0;this.maxDistance=Infinity;this.keys=[65,83,68];
  22853. this.target=new THREE.Vector3;var d=new THREE.Vector3,e=false,f=-1,g=new THREE.Vector3,h=new THREE.Vector3,k=new THREE.Vector3,j=new THREE.Vector2,l=new THREE.Vector2,p=new THREE.Vector2,m=new THREE.Vector2,o={type:"change"};this.handleEvent=function(a){if(typeof this[a.type]=="function")this[a.type](a)};this.getMouseOnScreen=function(a,b){return new THREE.Vector2((a-c.screen.offsetLeft)/c.radius*0.5,(b-c.screen.offsetTop)/c.radius*0.5)};this.getMouseProjectionOnBall=function(a,b){var d=new THREE.Vector3((a-
  22854. c.screen.width*0.5-c.screen.offsetLeft)/c.radius,(c.screen.height*0.5+c.screen.offsetTop-b)/c.radius,0),e=d.length();e>1?d.normalize():d.z=Math.sqrt(1-e*e);g.copy(c.object.position).subSelf(c.target);e=c.object.up.clone().setLength(d.y);e.addSelf(c.object.up.clone().crossSelf(g).setLength(d.x));e.addSelf(g.setLength(d.z));return e};this.rotateCamera=function(){var a=Math.acos(h.dot(k)/h.length()/k.length());if(a){var b=(new THREE.Vector3).cross(h,k).normalize(),d=new THREE.Quaternion,a=a*c.rotateSpeed;
  22855. d.setFromAxisAngle(b,-a);d.multiplyVector3(g);d.multiplyVector3(c.object.up);d.multiplyVector3(k);if(c.staticMoving)h=k;else{d.setFromAxisAngle(b,a*(c.dynamicDampingFactor-1));d.multiplyVector3(h)}}};this.zoomCamera=function(){var a=1+(l.y-j.y)*c.zoomSpeed;if(a!==1&&a>0){g.multiplyScalar(a);c.staticMoving?j=l:j.y=j.y+(l.y-j.y)*this.dynamicDampingFactor}};this.panCamera=function(){var a=m.clone().subSelf(p);if(a.lengthSq()){a.multiplyScalar(g.length()*c.panSpeed);var b=g.clone().crossSelf(c.object.up).setLength(a.x);
  22856. b.addSelf(c.object.up.clone().setLength(a.y));c.object.position.addSelf(b);c.target.addSelf(b);c.staticMoving?p=m:p.addSelf(a.sub(m,p).multiplyScalar(c.dynamicDampingFactor))}};this.checkDistances=function(){if(!c.noZoom||!c.noPan){c.object.position.lengthSq()>c.maxDistance*c.maxDistance&&c.object.position.setLength(c.maxDistance);g.lengthSq()<c.minDistance*c.minDistance&&c.object.position.add(c.target,g.setLength(c.minDistance))}};this.update=function(){g.copy(c.object.position).subSelf(c.target);
  22857. c.noRotate||c.rotateCamera();c.noZoom||c.zoomCamera();c.noPan||c.panCamera();c.object.position.add(c.target,g);c.checkDistances();c.object.lookAt(c.target);if(d.distanceTo(c.object.position)>0){c.dispatchEvent(o);d.copy(c.object.position)}};this.domElement.addEventListener("contextmenu",function(a){a.preventDefault()},false);this.domElement.addEventListener("mousemove",function(a){if(c.enabled){if(e){h=k=c.getMouseProjectionOnBall(a.clientX,a.clientY);j=l=c.getMouseOnScreen(a.clientX,a.clientY);p=
  22858. m=c.getMouseOnScreen(a.clientX,a.clientY);e=false}f!==-1&&(f===0&&!c.noRotate?k=c.getMouseProjectionOnBall(a.clientX,a.clientY):f===1&&!c.noZoom?l=c.getMouseOnScreen(a.clientX,a.clientY):f===2&&!c.noPan&&(m=c.getMouseOnScreen(a.clientX,a.clientY)))}},false);this.domElement.addEventListener("mousedown",function(a){if(c.enabled){a.preventDefault();a.stopPropagation();if(f===-1){f=a.button;f===0&&!c.noRotate?h=k=c.getMouseProjectionOnBall(a.clientX,a.clientY):f===1&&!c.noZoom?j=l=c.getMouseOnScreen(a.clientX,
  22859. a.clientY):this.noPan||(p=m=c.getMouseOnScreen(a.clientX,a.clientY))}}},false);this.domElement.addEventListener("mouseup",function(a){if(c.enabled){a.preventDefault();a.stopPropagation();f=-1}},false);window.addEventListener("keydown",function(a){if(c.enabled&&f===-1){a.keyCode===c.keys[0]&&!c.noRotate?f=0:a.keyCode===c.keys[1]&&!c.noZoom?f=1:a.keyCode===c.keys[2]&&!c.noPan&&(f=2);f!==-1&&(e=true)}},false);window.addEventListener("keyup",function(){c.enabled&&f!==-1&&(f=-1)},false)};
  22860. THREE.CubeGeometry=function(a,b,c,d,e,f,g,h){function k(a,b,c,g,h,k,l,m){var n,o=d||1,p=e||1,q=h/2,r=k/2,t=j.vertices.length;if(a==="x"&&b==="y"||a==="y"&&b==="x")n="z";else if(a==="x"&&b==="z"||a==="z"&&b==="x"){n="y";p=f||1}else if(a==="z"&&b==="y"||a==="y"&&b==="z"){n="x";o=f||1}var i=o+1,u=p+1,w=h/o,C=k/p,Y=new THREE.Vector3;Y[n]=l>0?1:-1;for(h=0;h<u;h++)for(k=0;k<i;k++){var I=new THREE.Vector3;I[a]=(k*w-q)*c;I[b]=(h*C-r)*g;I[n]=l;j.vertices.push(I)}for(h=0;h<p;h++)for(k=0;k<o;k++){a=new THREE.Face4(k+
  22861. i*h+t,k+i*(h+1)+t,k+1+i*(h+1)+t,k+1+i*h+t);a.normal.copy(Y);a.vertexNormals.push(Y.clone(),Y.clone(),Y.clone(),Y.clone());a.materialIndex=m;j.faces.push(a);j.faceVertexUvs[0].push([new THREE.UV(k/o,h/p),new THREE.UV(k/o,(h+1)/p),new THREE.UV((k+1)/o,(h+1)/p),new THREE.UV((k+1)/o,h/p)])}}THREE.Geometry.call(this);var j=this,l=a/2,p=b/2,m=c/2,o,q,n,r,u,t;if(g!==void 0){if(g instanceof Array)this.materials=g;else{this.materials=[];for(o=0;o<6;o++)this.materials.push(g)}o=0;r=1;q=2;u=3;n=4;t=5}else this.materials=
  22862. [];this.sides={px:true,nx:true,py:true,ny:true,pz:true,nz:true};if(h!=void 0)for(var w in h)this.sides[w]!==void 0&&(this.sides[w]=h[w]);this.sides.px&&k("z","y",-1,-1,c,b,l,o);this.sides.nx&&k("z","y",1,-1,c,b,-l,r);this.sides.py&&k("x","z",1,1,a,c,p,q);this.sides.ny&&k("x","z",1,-1,a,c,-p,u);this.sides.pz&&k("x","y",1,-1,a,b,m,n);this.sides.nz&&k("x","y",-1,-1,a,b,-m,t);this.computeCentroids();this.mergeVertices()};THREE.CubeGeometry.prototype=new THREE.Geometry;
  22863. THREE.CubeGeometry.prototype.constructor=THREE.CubeGeometry;
  22864. THREE.CylinderGeometry=function(a,b,c,d,e,f){THREE.Geometry.call(this);var a=a!==void 0?a:20,b=b!==void 0?b:20,c=c!==void 0?c:100,g=c/2,d=d||8,e=e||1,h,k,j=[],l=[];for(k=0;k<=e;k++){var p=[],m=[],o=k/e,q=o*(b-a)+a;for(h=0;h<=d;h++){var n=h/d,r=new THREE.Vector3;r.x=q*Math.sin(n*Math.PI*2);r.y=-o*c+g;r.z=q*Math.cos(n*Math.PI*2);this.vertices.push(r);p.push(this.vertices.length-1);m.push(new THREE.UV(n,o))}j.push(p);l.push(m)}for(k=0;k<e;k++)for(h=0;h<d;h++){var c=j[k][h],p=j[k+1][h],m=j[k+1][h+1],
  22865. o=j[k][h+1],q=this.vertices[c].clone().setY(0).normalize(),n=this.vertices[p].clone().setY(0).normalize(),r=this.vertices[m].clone().setY(0).normalize(),u=this.vertices[o].clone().setY(0).normalize(),t=l[k][h].clone(),w=l[k+1][h].clone(),s=l[k+1][h+1].clone(),x=l[k][h+1].clone();this.faces.push(new THREE.Face4(c,p,m,o,[q,n,r,u]));this.faceVertexUvs[0].push([t,w,s,x])}if(!f&&a>0){this.vertices.push(new THREE.Vector3(0,g,0));for(h=0;h<d;h++){c=j[0][h];p=j[0][h+1];m=this.vertices.length-1;q=new THREE.Vector3(0,
  22866. 1,0);n=new THREE.Vector3(0,1,0);r=new THREE.Vector3(0,1,0);t=l[0][h].clone();w=l[0][h+1].clone();s=new THREE.UV(w.u,0);this.faces.push(new THREE.Face3(c,p,m,[q,n,r]));this.faceVertexUvs[0].push([t,w,s])}}if(!f&&b>0){this.vertices.push(new THREE.Vector3(0,-g,0));for(h=0;h<d;h++){c=j[k][h+1];p=j[k][h];m=this.vertices.length-1;q=new THREE.Vector3(0,-1,0);n=new THREE.Vector3(0,-1,0);r=new THREE.Vector3(0,-1,0);t=l[k][h+1].clone();w=l[k][h].clone();s=new THREE.UV(w.u,1);this.faces.push(new THREE.Face3(c,
  22867. p,m,[q,n,r]));this.faceVertexUvs[0].push([t,w,s])}}this.computeCentroids();this.computeFaceNormals()};THREE.CylinderGeometry.prototype=new THREE.Geometry;THREE.CylinderGeometry.prototype.constructor=THREE.CylinderGeometry;THREE.ExtrudeGeometry=function(a,b){if(typeof a!=="undefined"){THREE.Geometry.call(this);a=a instanceof Array?a:[a];this.shapebb=a[a.length-1].getBoundingBox();this.addShapeList(a,b);this.computeCentroids();this.computeFaceNormals()}};THREE.ExtrudeGeometry.prototype=new THREE.Geometry;
  22868. THREE.ExtrudeGeometry.prototype.constructor=THREE.ExtrudeGeometry;THREE.ExtrudeGeometry.prototype.addShapeList=function(a,b){for(var c=a.length,d=0;d<c;d++)this.addShape(a[d],b)};
  22869. THREE.ExtrudeGeometry.prototype.addShape=function(a,b){function c(a,b,c){b||console.log("die");return b.clone().multiplyScalar(c).addSelf(a)}function d(a,b,c){var d=THREE.ExtrudeGeometry.__v1,e=THREE.ExtrudeGeometry.__v2,f=THREE.ExtrudeGeometry.__v3,g=THREE.ExtrudeGeometry.__v4,h=THREE.ExtrudeGeometry.__v5,i=THREE.ExtrudeGeometry.__v6;d.set(a.x-b.x,a.y-b.y);e.set(a.x-c.x,a.y-c.y);d=d.normalize();e=e.normalize();f.set(-d.y,d.x);g.set(e.y,-e.x);h.copy(a).addSelf(f);i.copy(a).addSelf(g);if(h.equals(i))return g.clone();
  22870. h.copy(b).addSelf(f);i.copy(c).addSelf(g);f=d.dot(g);g=i.subSelf(h).dot(g);if(f===0){console.log("Either infinite or no solutions!");g===0?console.log("Its finite solutions."):console.log("Too bad, no solutions.")}g=g/f;if(g<0){b=Math.atan2(b.y-a.y,b.x-a.x);a=Math.atan2(c.y-a.y,c.x-a.x);b>a&&(a=a+Math.PI*2);c=(b+a)/2;a=-Math.cos(c);c=-Math.sin(c);return new THREE.Vector2(a,c)}return d.multiplyScalar(g).addSelf(h).subSelf(a).clone()}function e(c,d){var e,f;for(I=c.length;--I>=0;){e=I;f=I-1;f<0&&(f=
  22871. c.length-1);for(var g=0,h=m+l*2,g=0;g<h;g++){var i=U*g,k=U*(g+1),j=d+e+i,i=d+f+i,n=d+f+k,k=d+e+k,o=c,p=g,q=h,j=j+J,i=i+J,n=n+J,k=k+J;A.faces.push(new THREE.Face4(j,i,n,k,null,null,t));j=O.generateSideWallUV(A,a,o,b,j,i,n,k,p,q);A.faceVertexUvs[0].push(j)}}}function f(a,b,c){A.vertices.push(new THREE.Vector3(a,b,c))}function g(c,d,e,f){c=c+J;d=d+J;e=e+J;A.faces.push(new THREE.Face3(c,d,e,null,null,u));c=f?O.generateBottomUV(A,a,b,c,d,e):O.generateTopUV(A,a,b,c,d,e);A.faceVertexUvs[0].push(c)}var h=
  22872. b.amount!==void 0?b.amount:100,k=b.bevelThickness!==void 0?b.bevelThickness:6,j=b.bevelSize!==void 0?b.bevelSize:k-2,l=b.bevelSegments!==void 0?b.bevelSegments:3,p=b.bevelEnabled!==void 0?b.bevelEnabled:true,m=b.steps!==void 0?b.steps:1,o=b.bendPath,q=b.extrudePath,n,r=false,u=b.material,t=b.extrudeMaterial,w,s,x,F;if(q){n=q.getSpacedPoints(m);r=true;p=false;w=new THREE.TubeGeometry.FrenetFrames(q,m,false);s=new THREE.Vector3;x=new THREE.Vector3;F=new THREE.Vector3}if(!p)j=k=l=0;var D,z,v,A=this,
  22873. J=this.vertices.length;o&&a.addWrapPath(o);var q=a.extractPoints(),o=q.shape,K=q.holes;if(q=!THREE.Shape.Utils.isClockWise(o)){o=o.reverse();z=0;for(v=K.length;z<v;z++){D=K[z];THREE.Shape.Utils.isClockWise(D)&&(K[z]=D.reverse())}q=false}var R=THREE.Shape.Utils.triangulateShape(o,K),P=o;z=0;for(v=K.length;z<v;z++){D=K[z];o=o.concat(D)}var E,M,G,i,T,U=o.length,C,Y=R.length,q=[],I=0;G=P.length;E=G-1;for(M=I+1;I<G;I++,E++,M++){E===G&&(E=0);M===G&&(M=0);q[I]=d(P[I],P[E],P[M])}var ea=[],fa,ia=q.concat();
  22874. z=0;for(v=K.length;z<v;z++){D=K[z];fa=[];I=0;G=D.length;E=G-1;for(M=I+1;I<G;I++,E++,M++){E===G&&(E=0);M===G&&(M=0);fa[I]=d(D[I],D[E],D[M])}ea.push(fa);ia=ia.concat(fa)}for(E=0;E<l;E++){G=E/l;i=k*(1-G);M=j*Math.sin(G*Math.PI/2);I=0;for(G=P.length;I<G;I++){T=c(P[I],q[I],M);f(T.x,T.y,-i)}z=0;for(v=K.length;z<v;z++){D=K[z];fa=ea[z];I=0;for(G=D.length;I<G;I++){T=c(D[I],fa[I],M);f(T.x,T.y,-i)}}}M=j;for(I=0;I<U;I++){T=p?c(o[I],ia[I],M):o[I];if(r){x.copy(w.normals[0]).multiplyScalar(T.x);s.copy(w.binormals[0]).multiplyScalar(T.y);
  22875. F.copy(n[0]).addSelf(x).addSelf(s);f(F.x,F.y,F.z)}else f(T.x,T.y,0)}for(G=1;G<=m;G++)for(I=0;I<U;I++){T=p?c(o[I],ia[I],M):o[I];if(r){x.copy(w.normals[G]).multiplyScalar(T.x);s.copy(w.binormals[G]).multiplyScalar(T.y);F.copy(n[G]).addSelf(x).addSelf(s);f(F.x,F.y,F.z)}else f(T.x,T.y,h/m*G)}for(E=l-1;E>=0;E--){G=E/l;i=k*(1-G);M=j*Math.sin(G*Math.PI/2);I=0;for(G=P.length;I<G;I++){T=c(P[I],q[I],M);f(T.x,T.y,h+i)}z=0;for(v=K.length;z<v;z++){D=K[z];fa=ea[z];I=0;for(G=D.length;I<G;I++){T=c(D[I],fa[I],M);
  22876. r?f(T.x,T.y+n[m-1].y,n[m-1].x+i):f(T.x,T.y,h+i)}}}var O=THREE.ExtrudeGeometry.WorldUVGenerator;(function(){if(p){var a;a=U*0;for(I=0;I<Y;I++){C=R[I];g(C[2]+a,C[1]+a,C[0]+a,true)}a=m+l*2;a=U*a;for(I=0;I<Y;I++){C=R[I];g(C[0]+a,C[1]+a,C[2]+a,false)}}else{for(I=0;I<Y;I++){C=R[I];g(C[2],C[1],C[0],true)}for(I=0;I<Y;I++){C=R[I];g(C[0]+U*m,C[1]+U*m,C[2]+U*m,false)}}})();(function(){var a=0;e(P,a);a=a+P.length;z=0;for(v=K.length;z<v;z++){D=K[z];e(D,a);a=a+D.length}})()};
  22877. THREE.ExtrudeGeometry.WorldUVGenerator={generateTopUV:function(a,b,c,d,e,f){b=a.vertices[e].x;e=a.vertices[e].y;c=a.vertices[f].x;f=a.vertices[f].y;return[new THREE.UV(a.vertices[d].x,1-a.vertices[d].y),new THREE.UV(b,1-e),new THREE.UV(c,1-f)]},generateBottomUV:function(a,b,c,d,e,f){return this.generateTopUV(a,b,c,d,e,f)},generateSideWallUV:function(a,b,c,d,e,f,g,h){var b=a.vertices[e].x,c=a.vertices[e].y,e=a.vertices[e].z,d=a.vertices[f].x,k=a.vertices[f].y,f=a.vertices[f].z,j=a.vertices[g].x,l=
  22878. a.vertices[g].y,g=a.vertices[g].z,p=a.vertices[h].x,m=a.vertices[h].y,a=a.vertices[h].z;return Math.abs(c-k)<0.01?[new THREE.UV(b,e),new THREE.UV(d,f),new THREE.UV(j,g),new THREE.UV(p,a)]:[new THREE.UV(c,e),new THREE.UV(k,f),new THREE.UV(l,g),new THREE.UV(m,a)]}};THREE.ExtrudeGeometry.__v1=new THREE.Vector2;THREE.ExtrudeGeometry.__v2=new THREE.Vector2;THREE.ExtrudeGeometry.__v3=new THREE.Vector2;THREE.ExtrudeGeometry.__v4=new THREE.Vector2;THREE.ExtrudeGeometry.__v5=new THREE.Vector2;
  22879. THREE.ExtrudeGeometry.__v6=new THREE.Vector2;
  22880. THREE.LatheGeometry=function(a,b,c){THREE.Geometry.call(this);for(var b=b||12,c=c||2*Math.PI,d=[],e=(new THREE.Matrix4).makeRotationZ(c/b),f=0;f<a.length;f++){d[f]=a[f].clone();this.vertices.push(d[f])}for(var g=b+1,c=0;c<g;c++)for(f=0;f<d.length;f++){d[f]=e.multiplyVector3(d[f].clone());this.vertices.push(d[f])}for(c=0;c<b;c++){d=0;for(e=a.length;d<e-1;d++){this.faces.push(new THREE.Face4(c*e+d,(c+1)%g*e+d,(c+1)%g*e+(d+1)%e,c*e+(d+1)%e));this.faceVertexUvs[0].push([new THREE.UV(1-c/b,d/e),new THREE.UV(1-
  22881. (c+1)/b,d/e),new THREE.UV(1-(c+1)/b,(d+1)/e),new THREE.UV(1-c/b,(d+1)/e)])}}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.LatheGeometry.prototype=new THREE.Geometry;THREE.LatheGeometry.prototype.constructor=THREE.LatheGeometry;
  22882. THREE.PlaneGeometry=function(a,b,c,d){THREE.Geometry.call(this);for(var e=a/2,f=b/2,c=c||1,d=d||1,g=c+1,h=d+1,k=a/c,j=b/d,l=new THREE.Vector3(0,1,0),a=0;a<h;a++)for(b=0;b<g;b++)this.vertices.push(new THREE.Vector3(b*k-e,0,a*j-f));for(a=0;a<d;a++)for(b=0;b<c;b++){e=new THREE.Face4(b+g*a,b+g*(a+1),b+1+g*(a+1),b+1+g*a);e.normal.copy(l);e.vertexNormals.push(l.clone(),l.clone(),l.clone(),l.clone());this.faces.push(e);this.faceVertexUvs[0].push([new THREE.UV(b/c,a/d),new THREE.UV(b/c,(a+1)/d),new THREE.UV((b+
  22883. 1)/c,(a+1)/d),new THREE.UV((b+1)/c,a/d)])}this.computeCentroids()};THREE.PlaneGeometry.prototype=new THREE.Geometry;THREE.PlaneGeometry.prototype.constructor=THREE.PlaneGeometry;
  22884. THREE.SphereGeometry=function(a,b,c,d,e,f,g){THREE.Geometry.call(this);var a=a||50,d=d!==void 0?d:0,e=e!==void 0?e:Math.PI*2,f=f!==void 0?f:0,g=g!==void 0?g:Math.PI,b=Math.max(3,Math.floor(b)||8),c=Math.max(2,Math.floor(c)||6),h,k,j=[],l=[];for(k=0;k<=c;k++){var p=[],m=[];for(h=0;h<=b;h++){var o=h/b,q=k/c,n=new THREE.Vector3;n.x=-a*Math.cos(d+o*e)*Math.sin(f+q*g);n.y=a*Math.cos(f+q*g);n.z=a*Math.sin(d+o*e)*Math.sin(f+q*g);this.vertices.push(n);p.push(this.vertices.length-1);m.push(new THREE.UV(o,
  22885. q))}j.push(p);l.push(m)}for(k=0;k<c;k++)for(h=0;h<b;h++){var d=j[k][h+1],e=j[k][h],f=j[k+1][h],g=j[k+1][h+1],p=this.vertices[d].clone().normalize(),m=this.vertices[e].clone().normalize(),o=this.vertices[f].clone().normalize(),q=this.vertices[g].clone().normalize(),n=l[k][h+1].clone(),r=l[k][h].clone(),u=l[k+1][h].clone(),t=l[k+1][h+1].clone();if(Math.abs(this.vertices[d].y)==a){this.faces.push(new THREE.Face3(d,f,g,[p,o,q]));this.faceVertexUvs[0].push([n,u,t])}else if(Math.abs(this.vertices[f].y)==
  22886. a){this.faces.push(new THREE.Face3(d,e,f,[p,m,o]));this.faceVertexUvs[0].push([n,r,u])}else{this.faces.push(new THREE.Face4(d,e,f,g,[p,m,o,q]));this.faceVertexUvs[0].push([n,r,u,t])}}this.computeCentroids();this.computeFaceNormals();this.boundingSphere={radius:a}};THREE.SphereGeometry.prototype=new THREE.Geometry;THREE.SphereGeometry.prototype.constructor=THREE.SphereGeometry;
  22887. THREE.TextGeometry=function(a,b){var c=(new THREE.TextPath(a,b)).toShapes();b.amount=b.height!==void 0?b.height:50;if(b.bevelThickness===void 0)b.bevelThickness=10;if(b.bevelSize===void 0)b.bevelSize=8;if(b.bevelEnabled===void 0)b.bevelEnabled=false;if(b.bend){var d=c[c.length-1].getBoundingBox().maxX;b.bendPath=new THREE.QuadraticBezierCurve(new THREE.Vector2(0,0),new THREE.Vector2(d/2,120),new THREE.Vector2(d,0))}THREE.ExtrudeGeometry.call(this,c,b)};THREE.TextGeometry.prototype=new THREE.ExtrudeGeometry;
  22888. THREE.TextGeometry.prototype.constructor=THREE.TextGeometry;
  22889. THREE.FontUtils={faces:{},face:"helvetiker",weight:"normal",style:"normal",size:150,divisions:10,getFace:function(){return this.faces[this.face][this.weight][this.style]},loadFace:function(a){var b=a.familyName.toLowerCase();this.faces[b]=this.faces[b]||{};this.faces[b][a.cssFontWeight]=this.faces[b][a.cssFontWeight]||{};this.faces[b][a.cssFontWeight][a.cssFontStyle]=a;return this.faces[b][a.cssFontWeight][a.cssFontStyle]=a},drawText:function(a){for(var b=this.getFace(),c=this.size/b.resolution,d=
  22890. 0,e=(""+a).split(""),f=e.length,g=[],a=0;a<f;a++){var h=new THREE.Path,h=this.extractGlyphPoints(e[a],b,c,d,h),d=d+h.offset;g.push(h.path)}return{paths:g,offset:d/2}},extractGlyphPoints:function(a,b,c,d,e){var f=[],g,h,k,j,l,p,m,o,q,n,r,u=b.glyphs[a]||b.glyphs["?"];if(u){if(u.o){b=u._cachedOutline||(u._cachedOutline=u.o.split(" "));j=b.length;for(a=0;a<j;){k=b[a++];switch(k){case "m":k=b[a++]*c+d;l=b[a++]*c;f.push(new THREE.Vector2(k,l));e.moveTo(k,l);break;case "l":k=b[a++]*c+d;l=b[a++]*c;f.push(new THREE.Vector2(k,
  22891. l));e.lineTo(k,l);break;case "q":k=b[a++]*c+d;l=b[a++]*c;o=b[a++]*c+d;q=b[a++]*c;e.quadraticCurveTo(o,q,k,l);if(g=f[f.length-1]){p=g.x;m=g.y;g=1;for(h=this.divisions;g<=h;g++){var t=g/h,w=THREE.Shape.Utils.b2(t,p,o,k),t=THREE.Shape.Utils.b2(t,m,q,l);f.push(new THREE.Vector2(w,t))}}break;case "b":k=b[a++]*c+d;l=b[a++]*c;o=b[a++]*c+d;q=b[a++]*-c;n=b[a++]*c+d;r=b[a++]*-c;e.bezierCurveTo(k,l,o,q,n,r);if(g=f[f.length-1]){p=g.x;m=g.y;g=1;for(h=this.divisions;g<=h;g++){t=g/h;w=THREE.Shape.Utils.b3(t,p,o,
  22892. n,k);t=THREE.Shape.Utils.b3(t,m,q,r,l);f.push(new THREE.Vector2(w,t))}}}}}return{offset:u.ha*c,points:f,path:e}}}};
  22893. (function(a){var b=function(a){for(var b=a.length,e=0,f=b-1,g=0;g<b;f=g++)e=e+(a[f].x*a[g].y-a[g].x*a[f].y);return e*0.5};a.Triangulate=function(a,d){var e=a.length;if(e<3)return null;var f=[],g=[],h=[],k,j,l;if(b(a)>0)for(j=0;j<e;j++)g[j]=j;else for(j=0;j<e;j++)g[j]=e-1-j;var p=2*e;for(j=e-1;e>2;){if(p--<=0){console.log("Warning, unable to triangulate polygon!");break}k=j;e<=k&&(k=0);j=k+1;e<=j&&(j=0);l=j+1;e<=l&&(l=0);var m;a:{m=a;var o=k,q=j,n=l,r=e,u=g,t=void 0,w=void 0,s=void 0,x=void 0,F=void 0,
  22894. D=void 0,z=void 0,v=void 0,A=void 0,w=m[u[o]].x,s=m[u[o]].y,x=m[u[q]].x,F=m[u[q]].y,D=m[u[n]].x,z=m[u[n]].y;if(1.0E-10>(x-w)*(z-s)-(F-s)*(D-w))m=false;else{for(t=0;t<r;t++)if(!(t==o||t==q||t==n)){var v=m[u[t]].x,A=m[u[t]].y,J=void 0,K=void 0,R=void 0,P=void 0,E=void 0,M=void 0,G=void 0,i=void 0,T=void 0,U=void 0,C=void 0,Y=void 0,J=R=E=void 0,J=D-x,K=z-F,R=w-D,P=s-z,E=x-w,M=F-s,G=v-w,i=A-s,T=v-x,U=A-F,C=v-D,Y=A-z,J=J*U-K*T,E=E*i-M*G,R=R*Y-P*C;if(J>=0&&R>=0&&E>=0){m=false;break a}}m=true}}if(m){f.push([a[g[k]],
  22895. a[g[j]],a[g[l]]]);h.push([g[k],g[j],g[l]]);k=j;for(l=j+1;l<e;k++,l++)g[k]=g[l];e--;p=2*e}}return d?h:f};a.Triangulate.area=b;return a})(THREE.FontUtils);self._typeface_js={faces:THREE.FontUtils.faces,loadFace:THREE.FontUtils.loadFace};
  22896. THREE.TorusGeometry=function(a,b,c,d,e){THREE.Geometry.call(this);this.radius=a||100;this.tube=b||40;this.segmentsR=c||8;this.segmentsT=d||6;this.arc=e||Math.PI*2;e=new THREE.Vector3;a=[];b=[];for(c=0;c<=this.segmentsR;c++)for(d=0;d<=this.segmentsT;d++){var f=d/this.segmentsT*this.arc,g=c/this.segmentsR*Math.PI*2;e.x=this.radius*Math.cos(f);e.y=this.radius*Math.sin(f);var h=new THREE.Vector3;h.x=(this.radius+this.tube*Math.cos(g))*Math.cos(f);h.y=(this.radius+this.tube*Math.cos(g))*Math.sin(f);h.z=
  22897. this.tube*Math.sin(g);this.vertices.push(h);a.push(new THREE.UV(d/this.segmentsT,1-c/this.segmentsR));b.push(h.clone().subSelf(e).normalize())}for(c=1;c<=this.segmentsR;c++)for(d=1;d<=this.segmentsT;d++){var e=(this.segmentsT+1)*c+d-1,f=(this.segmentsT+1)*(c-1)+d-1,g=(this.segmentsT+1)*(c-1)+d,h=(this.segmentsT+1)*c+d,k=new THREE.Face4(e,f,g,h,[b[e],b[f],b[g],b[h]]);k.normal.addSelf(b[e]);k.normal.addSelf(b[f]);k.normal.addSelf(b[g]);k.normal.addSelf(b[h]);k.normal.normalize();this.faces.push(k);
  22898. this.faceVertexUvs[0].push([a[e].clone(),a[f].clone(),a[g].clone(),a[h].clone()])}this.computeCentroids()};THREE.TorusGeometry.prototype=new THREE.Geometry;THREE.TorusGeometry.prototype.constructor=THREE.TorusGeometry;
  22899. THREE.TorusKnotGeometry=function(a,b,c,d,e,f,g){function h(a,b,c,d,e,f){var g=Math.cos(a);Math.cos(b);b=Math.sin(a);a=c/d*a;c=Math.cos(a);g=e*(2+c)*0.5*g;b=e*(2+c)*b*0.5;e=f*e*Math.sin(a)*0.5;return new THREE.Vector3(g,b,e)}THREE.Geometry.call(this);this.radius=a||200;this.tube=b||40;this.segmentsR=c||64;this.segmentsT=d||8;this.p=e||2;this.q=f||3;this.heightScale=g||1;this.grid=Array(this.segmentsR);c=new THREE.Vector3;d=new THREE.Vector3;e=new THREE.Vector3;for(a=0;a<this.segmentsR;++a){this.grid[a]=
  22900. Array(this.segmentsT);for(b=0;b<this.segmentsT;++b){var k=a/this.segmentsR*2*this.p*Math.PI,g=b/this.segmentsT*2*Math.PI,f=h(k,g,this.q,this.p,this.radius,this.heightScale),k=h(k+0.01,g,this.q,this.p,this.radius,this.heightScale);c.sub(k,f);d.add(k,f);e.cross(c,d);d.cross(e,c);e.normalize();d.normalize();k=-this.tube*Math.cos(g);g=this.tube*Math.sin(g);f.x=f.x+(k*d.x+g*e.x);f.y=f.y+(k*d.y+g*e.y);f.z=f.z+(k*d.z+g*e.z);this.grid[a][b]=this.vertices.push(new THREE.Vector3(f.x,f.y,f.z))-1}}for(a=0;a<
  22901. this.segmentsR;++a)for(b=0;b<this.segmentsT;++b){var e=(a+1)%this.segmentsR,f=(b+1)%this.segmentsT,c=this.grid[a][b],d=this.grid[e][b],e=this.grid[e][f],f=this.grid[a][f],g=new THREE.UV(a/this.segmentsR,b/this.segmentsT),k=new THREE.UV((a+1)/this.segmentsR,b/this.segmentsT),j=new THREE.UV((a+1)/this.segmentsR,(b+1)/this.segmentsT),l=new THREE.UV(a/this.segmentsR,(b+1)/this.segmentsT);this.faces.push(new THREE.Face4(c,d,e,f));this.faceVertexUvs[0].push([g,k,j,l])}this.computeCentroids();this.computeFaceNormals();
  22902. this.computeVertexNormals()};THREE.TorusKnotGeometry.prototype=new THREE.Geometry;THREE.TorusKnotGeometry.prototype.constructor=THREE.TorusKnotGeometry;
  22903. THREE.TubeGeometry=function(a,b,c,d,e,f){THREE.Geometry.call(this);this.path=a;this.segments=b||64;this.radius=c||1;this.segmentsRadius=d||8;this.closed=e||false;if(f)this.debug=new THREE.Object3D;this.grid=[];var g,h,f=this.segments+1,k,j,l,p=new THREE.Vector3,m,o,q,b=new THREE.TubeGeometry.FrenetFrames(a,b,e);m=b.tangents;o=b.normals;q=b.binormals;this.tangents=m;this.normals=o;this.binormals=q;for(b=0;b<f;b++){this.grid[b]=[];d=b/(f-1);l=a.getPointAt(d);d=m[b];g=o[b];h=q[b];if(this.debug){this.debug.add(new THREE.ArrowHelper(d,
  22904. l,c,255));this.debug.add(new THREE.ArrowHelper(g,l,c,16711680));this.debug.add(new THREE.ArrowHelper(h,l,c,65280))}for(d=0;d<this.segmentsRadius;d++){k=d/this.segmentsRadius*2*Math.PI;j=-this.radius*Math.cos(k);k=this.radius*Math.sin(k);p.copy(l);p.x=p.x+(j*g.x+k*h.x);p.y=p.y+(j*g.y+k*h.y);p.z=p.z+(j*g.z+k*h.z);this.grid[b][d]=this.vertices.push(new THREE.Vector3(p.x,p.y,p.z))-1}}for(b=0;b<this.segments;b++)for(d=0;d<this.segmentsRadius;d++){f=e?(b+1)%this.segments:b+1;p=(d+1)%this.segmentsRadius;
  22905. a=this.grid[b][d];c=this.grid[f][d];f=this.grid[f][p];p=this.grid[b][p];m=new THREE.UV(b/this.segments,d/this.segmentsRadius);o=new THREE.UV((b+1)/this.segments,d/this.segmentsRadius);q=new THREE.UV((b+1)/this.segments,(d+1)/this.segmentsRadius);g=new THREE.UV(b/this.segments,(d+1)/this.segmentsRadius);this.faces.push(new THREE.Face4(a,c,f,p));this.faceVertexUvs[0].push([m,o,q,g])}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.TubeGeometry.prototype=new THREE.Geometry;
  22906. THREE.TubeGeometry.prototype.constructor=THREE.TubeGeometry;
  22907. THREE.TubeGeometry.FrenetFrames=function(a,b,c){new THREE.Vector3;var d=new THREE.Vector3;new THREE.Vector3;var e=[],f=[],g=[],h=new THREE.Vector3,k=new THREE.Matrix4,b=b+1,j,l,p;this.tangents=e;this.normals=f;this.binormals=g;for(j=0;j<b;j++){l=j/(b-1);e[j]=a.getTangentAt(l);e[j].normalize()}f[0]=new THREE.Vector3;g[0]=new THREE.Vector3;a=Number.MAX_VALUE;j=Math.abs(e[0].x);l=Math.abs(e[0].y);p=Math.abs(e[0].z);if(j<=a){a=j;d.set(1,0,0)}if(l<=a){a=l;d.set(0,1,0)}p<=a&&d.set(0,0,1);h.cross(e[0],d).normalize();
  22908. f[0].cross(e[0],h);g[0].cross(e[0],f[0]);for(j=1;j<b;j++){f[j]=f[j-1].clone();g[j]=g[j-1].clone();h.cross(e[j-1],e[j]);if(h.length()>1.0E-4){h.normalize();d=Math.acos(e[j-1].dot(e[j]));k.makeRotationAxis(h,d).multiplyVector3(f[j])}g[j].cross(e[j],f[j])}if(c){d=Math.acos(f[0].dot(f[b-1]));d=d/(b-1);e[0].dot(h.cross(f[0],f[b-1]))>0&&(d=-d);for(j=1;j<b;j++){k.makeRotationAxis(e[j],d*j).multiplyVector3(f[j]);g[j].cross(e[j],f[j])}}};
  22909. THREE.PolyhedronGeometry=function(a,b,c,d){function e(a){var b=a.normalize().clone();b.index=k.vertices.push(b)-1;var c=Math.atan2(a.z,-a.x)/2/Math.PI+0.5,a=Math.atan2(-a.y,Math.sqrt(a.x*a.x+a.z*a.z))/Math.PI+0.5;b.uv=new THREE.UV(c,a);return b}function f(a,b,c,d){if(d<1){d=new THREE.Face3(a.index,b.index,c.index,[a.clone(),b.clone(),c.clone()]);d.centroid.addSelf(a).addSelf(b).addSelf(c).divideScalar(3);d.normal=d.centroid.clone().normalize();k.faces.push(d);d=Math.atan2(d.centroid.z,-d.centroid.x);
  22910. k.faceVertexUvs[0].push([h(a.uv,a,d),h(b.uv,b,d),h(c.uv,c,d)])}else{d=d-1;f(a,g(a,b),g(a,c),d);f(g(a,b),b,g(b,c),d);f(g(a,c),g(b,c),c,d);f(g(a,b),g(b,c),g(a,c),d)}}function g(a,b){p[a.index]||(p[a.index]=[]);p[b.index]||(p[b.index]=[]);var c=p[a.index][b.index];c===void 0&&(p[a.index][b.index]=p[b.index][a.index]=c=e((new THREE.Vector3).add(a,b).divideScalar(2)));return c}function h(a,b,c){c<0&&a.u===1&&(a=new THREE.UV(a.u-1,a.v));b.x===0&&b.z===0&&(a=new THREE.UV(c/2/Math.PI+0.5,a.v));return a}THREE.Geometry.call(this);
  22911. for(var c=c||1,d=d||0,k=this,j=0,l=a.length;j<l;j++)e(new THREE.Vector3(a[j][0],a[j][1],a[j][2]));for(var p=[],a=this.vertices,j=0,l=b.length;j<l;j++)f(a[b[j][0]],a[b[j][1]],a[b[j][2]],d);this.mergeVertices();j=0;for(l=this.vertices.length;j<l;j++)this.vertices[j].multiplyScalar(c);this.computeCentroids();this.boundingSphere={radius:c}};THREE.PolyhedronGeometry.prototype=new THREE.Geometry;THREE.PolyhedronGeometry.prototype.constructor=THREE.PolyhedronGeometry;
  22912. THREE.IcosahedronGeometry=function(a,b){var c=(1+Math.sqrt(5))/2;THREE.PolyhedronGeometry.call(this,[[-1,c,0],[1,c,0],[-1,-c,0],[1,-c,0],[0,-1,c],[0,1,c],[0,-1,-c],[0,1,-c],[c,0,-1],[c,0,1],[-c,0,-1],[-c,0,1]],[[0,11,5],[0,5,1],[0,1,7],[0,7,10],[0,10,11],[1,5,9],[5,11,4],[11,10,2],[10,7,6],[7,1,8],[3,9,4],[3,4,2],[3,2,6],[3,6,8],[3,8,9],[4,9,5],[2,4,11],[6,2,10],[8,6,7],[9,8,1]],a,b)};THREE.IcosahedronGeometry.prototype=new THREE.Geometry;THREE.IcosahedronGeometry.prototype.constructor=THREE.IcosahedronGeometry;
  22913. THREE.OctahedronGeometry=function(a,b){THREE.PolyhedronGeometry.call(this,[[1,0,0],[-1,0,0],[0,1,0],[0,-1,0],[0,0,1],[0,0,-1]],[[0,2,4],[0,4,3],[0,3,5],[0,5,2],[1,2,5],[1,5,3],[1,3,4],[1,4,2]],a,b)};THREE.OctahedronGeometry.prototype=new THREE.Geometry;THREE.OctahedronGeometry.prototype.constructor=THREE.OctahedronGeometry;THREE.TetrahedronGeometry=function(a,b){THREE.PolyhedronGeometry.call(this,[[1,1,1],[-1,-1,1],[-1,1,-1],[1,-1,-1]],[[2,1,0],[0,3,2],[1,3,0],[2,3,1]],a,b)};
  22914. THREE.TetrahedronGeometry.prototype=new THREE.Geometry;THREE.TetrahedronGeometry.prototype.constructor=THREE.TetrahedronGeometry;
  22915. THREE.ParametricGeometry=function(a,b,c){THREE.Geometry.call(this);var d=this.vertices,e=this.faces,f=this.faceVertexUvs[0],g,h,k,j,l=b+1;for(g=0;g<=b;g++){j=g/b;for(h=0;h<=a;h++){k=h/a;k=c(k,j);d.push(k)}}var p,m,o,q;for(g=0;g<b;g++)for(h=0;h<a;h++){c=g*l+h;d=g*l+h+1;j=(g+1)*l+h;k=(g+1)*l+h+1;p=new THREE.UV(g/a,h/b);m=new THREE.UV(g/a,(h+1)/b);o=new THREE.UV((g+1)/a,h/b);q=new THREE.UV((g+1)/a,(h+1)/b);e.push(new THREE.Face3(c,d,j));e.push(new THREE.Face3(d,k,j));f.push([p,m,o]);f.push([m,q,o])}console.log(this);
  22916. a=this.mergeVertices();console.log("removed ",a," vertices by merging");this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.ParametricGeometry.prototype=new THREE.Geometry;THREE.ParametricGeometry.prototype.constructor=THREE.ParametricGeometry;
  22917. THREE.AxisHelper=function(){THREE.Object3D.call(this);var a=new THREE.Geometry;a.vertices.push(new THREE.Vector3);a.vertices.push(new THREE.Vector3(0,100,0));var b=new THREE.CylinderGeometry(0,5,25,5,1),c;c=new THREE.Line(a,new THREE.LineBasicMaterial({color:16711680}));c.rotation.z=-Math.PI/2;this.add(c);c=new THREE.Mesh(b,new THREE.MeshBasicMaterial({color:16711680}));c.position.x=100;c.rotation.z=-Math.PI/2;this.add(c);c=new THREE.Line(a,new THREE.LineBasicMaterial({color:65280}));this.add(c);
  22918. c=new THREE.Mesh(b,new THREE.MeshBasicMaterial({color:65280}));c.position.y=100;this.add(c);c=new THREE.Line(a,new THREE.LineBasicMaterial({color:255}));c.rotation.x=Math.PI/2;this.add(c);c=new THREE.Mesh(b,new THREE.MeshBasicMaterial({color:255}));c.position.z=100;c.rotation.x=Math.PI/2;this.add(c)};THREE.AxisHelper.prototype=new THREE.Object3D;THREE.AxisHelper.prototype.constructor=THREE.AxisHelper;
  22919. THREE.ArrowHelper=function(a,b,c,d){THREE.Object3D.call(this);d===void 0&&(d=16776960);c===void 0&&(c=20);var e=new THREE.Geometry;e.vertices.push(new THREE.Vector3(0,0,0));e.vertices.push(new THREE.Vector3(0,1,0));this.line=new THREE.Line(e,new THREE.LineBasicMaterial({color:d}));this.add(this.line);e=new THREE.CylinderGeometry(0,0.05,0.25,5,1);this.cone=new THREE.Mesh(e,new THREE.MeshBasicMaterial({color:d}));this.cone.position.set(0,1,0);this.add(this.cone);if(b instanceof THREE.Vector3)this.position=
  22920. b;this.setDirection(a);this.setLength(c)};THREE.ArrowHelper.prototype=new THREE.Object3D;THREE.ArrowHelper.prototype.constructor=THREE.ArrowHelper;THREE.ArrowHelper.prototype.setDirection=function(a){var b=(new THREE.Vector3(0,1,0)).crossSelf(a),a=Math.acos((new THREE.Vector3(0,1,0)).dot(a.clone().normalize()));this.matrix=(new THREE.Matrix4).makeRotationAxis(b.normalize(),a);this.rotation.getRotationFromMatrix(this.matrix,this.scale)};
  22921. THREE.ArrowHelper.prototype.setLength=function(a){this.scale.set(a,a,a)};THREE.ArrowHelper.prototype.setColor=function(a){this.line.material.color.setHex(a);this.cone.material.color.setHex(a)};
  22922. THREE.CameraHelper=function(a){function b(a,b,d){c(a,d);c(b,d)}function c(a,b){d.lineGeometry.vertices.push(new THREE.Vector3);d.lineGeometry.colors.push(new THREE.Color(b));d.pointMap[a]===void 0&&(d.pointMap[a]=[]);d.pointMap[a].push(d.lineGeometry.vertices.length-1)}THREE.Object3D.call(this);var d=this;this.lineGeometry=new THREE.Geometry;this.lineMaterial=new THREE.LineBasicMaterial({color:16777215,vertexColors:THREE.FaceColors});this.pointMap={};b("n1","n2",16755200);b("n2","n4",16755200);b("n4",
  22923. "n3",16755200);b("n3","n1",16755200);b("f1","f2",16755200);b("f2","f4",16755200);b("f4","f3",16755200);b("f3","f1",16755200);b("n1","f1",16755200);b("n2","f2",16755200);b("n3","f3",16755200);b("n4","f4",16755200);b("p","n1",16711680);b("p","n2",16711680);b("p","n3",16711680);b("p","n4",16711680);b("u1","u2",43775);b("u2","u3",43775);b("u3","u1",43775);b("c","t",16777215);b("p","c",3355443);b("cn1","cn2",3355443);b("cn3","cn4",3355443);b("cf1","cf2",3355443);b("cf3","cf4",3355443);this.camera=a;this.update(a);
  22924. this.lines=new THREE.Line(this.lineGeometry,this.lineMaterial,THREE.LinePieces);this.add(this.lines)};THREE.CameraHelper.prototype=new THREE.Object3D;THREE.CameraHelper.prototype.constructor=THREE.CameraHelper;
  22925. THREE.CameraHelper.prototype.update=function(){function a(a,d,e,f){THREE.CameraHelper.__v.set(d,e,f);THREE.CameraHelper.__projector.unprojectVector(THREE.CameraHelper.__v,THREE.CameraHelper.__c);a=b.pointMap[a];if(a!==void 0){d=0;for(e=a.length;d<e;d++)b.lineGeometry.vertices[a[d]].copy(THREE.CameraHelper.__v)}}var b=this;THREE.CameraHelper.__c.projectionMatrix.copy(this.camera.projectionMatrix);a("c",0,0,-1);a("t",0,0,1);a("n1",-1,-1,-1);a("n2",1,-1,-1);a("n3",-1,1,-1);a("n4",1,1,-1);a("f1",-1,-1,
  22926. 1);a("f2",1,-1,1);a("f3",-1,1,1);a("f4",1,1,1);a("u1",0.7,1.1,-1);a("u2",-0.7,1.1,-1);a("u3",0,2,-1);a("cf1",-1,0,1);a("cf2",1,0,1);a("cf3",0,-1,1);a("cf4",0,1,1);a("cn1",-1,0,-1);a("cn2",1,0,-1);a("cn3",0,-1,-1);a("cn4",0,1,-1);this.lineGeometry.verticesNeedUpdate=true};THREE.CameraHelper.__projector=new THREE.Projector;THREE.CameraHelper.__v=new THREE.Vector3;THREE.CameraHelper.__c=new THREE.Camera;
  22927. THREE.SubdivisionModifier=function(a){this.subdivisions=a===void 0?1:a;this.useOldVertexColors=false;this.supportUVs=true;this.debug=false};THREE.SubdivisionModifier.prototype.constructor=THREE.SubdivisionModifier;THREE.SubdivisionModifier.prototype.modify=function(a){for(var b=this.subdivisions;b-- >0;)this.smooth(a)};
  22928. THREE.SubdivisionModifier.prototype.smooth=function(a){function b(){m.debug&&console.log.apply(console,arguments)}function c(){console&&console.log.apply(console,arguments)}function d(a,c,d,e,g,h,i){var k=new THREE.Face4(a,c,d,e,null,g.color,g.material);if(m.useOldVertexColors){k.vertexColors=[];for(var j,n,o,q=0;q<4;q++){o=h[q];j=new THREE.Color;j.setRGB(0,0,0);for(var r=0;r<o.length;r++){n=g.vertexColors[o[r]-1];j.r=j.r+n.r;j.g=j.g+n.g;j.b=j.b+n.b}j.r=j.r/o.length;j.g=j.g/o.length;j.b=j.b/o.length;
  22929. k.vertexColors[q]=j}}l.push(k);if(m.supportUVs){g=[f(a,""),f(c,i),f(d,i),f(e,i)];g[0]?g[1]?g[2]?g[3]?p.push(g):b("d :( ",e+":"+i):b("c :( ",d+":"+i):b("b :( ",c+":"+i):b("a :( ",a+":"+i)}}function e(a,b){return Math.min(a,b)+"_"+Math.max(a,b)}function f(a,d){var e=a+":"+d,f=t[e];if(!f){a>=w&&a<w+q.length?b("face pt"):b("edge pt");c("warning, UV not found for",e);return null}return f}function g(a,b,d){var e=a+":"+b;e in t?c("dup vertexNo",a,"oldFaceNo",b,"value",d,"key",e,t[e]):t[e]=d}function h(a,
  22930. b){R[a]===void 0&&(R[a]=[]);R[a].push(b)}function k(a,b,c){P[a]===void 0&&(P[a]={});P[a][b]=c}var j=[],l=[],p=[],m=this,o=a.vertices,q=a.faces,j=o.concat(),n=[],r={},u={},t={},w=o.length,s,x,F,D,z,v=a.faceVertexUvs[0],A;b("originalFaces, uvs, originalVerticesLength",q.length,v.length,w);if(m.supportUVs){s=0;for(x=v.length;s<x;s++){F=0;for(D=v[s].length;F<D;F++){A=q[s]["abcd".charAt(F)];g(A,s,v[s][F])}}}if(v.length==0)m.supportUVs=false;s=0;for(z in t)s++;if(!s){m.supportUVs=false;b("no uvs")}b("-- Original Faces + Vertices UVs completed",
  22931. t,"vs",v.length);s=0;for(x=q.length;s<x;s++){z=q[s];n.push(z.centroid);j.push(z.centroid);if(m.supportUVs){v=new THREE.UV;if(z instanceof THREE.Face3){v.u=f(z.a,s).u+f(z.b,s).u+f(z.c,s).u;v.v=f(z.a,s).v+f(z.b,s).v+f(z.c,s).v;v.u=v.u/3;v.v=v.v/3}else if(z instanceof THREE.Face4){v.u=f(z.a,s).u+f(z.b,s).u+f(z.c,s).u+f(z.d,s).u;v.v=f(z.a,s).v+f(z.b,s).v+f(z.c,s).v+f(z.d,s).v;v.u=v.u/4;v.v=v.v/4}g(w+s,"",v)}}b("-- added UVs for new Faces",t);x=function(a){function b(a,c){h[a]===void 0&&(h[a]=[]);h[a].push(c)}
  22932. var c,d,f,g,h={};c=0;for(d=a.faces.length;c<d;c++){f=a.faces[c];if(f instanceof THREE.Face3){g=e(f.a,f.b);b(g,c);g=e(f.b,f.c);b(g,c);g=e(f.c,f.a);b(g,c)}else if(f instanceof THREE.Face4){g=e(f.a,f.b);b(g,c);g=e(f.b,f.c);b(g,c);g=e(f.c,f.d);b(g,c);g=e(f.d,f.a);b(g,c)}}return h}(a);A=0;var J,K,R={},P={};for(s in x){v=x[s];J=s.split("_");K=J[0];J=J[1];h(K,[K,J]);h(J,[K,J]);F=0;for(D=v.length;F<D;F++){z=v[F];k(K,z,s);k(J,z,s)}v.length<2&&(u[s]=true)}b("vertexEdgeMap",R,"vertexFaceMap",P);for(s in x){v=
  22933. x[s];z=v[0];D=v[1];J=s.split("_");K=J[0];J=J[1];v=new THREE.Vector3;if(u[s]){v.addSelf(o[K]);v.addSelf(o[J]);v.multiplyScalar(0.5)}else{v.addSelf(n[z]);v.addSelf(n[D]);v.addSelf(o[K]);v.addSelf(o[J]);v.multiplyScalar(0.25)}r[s]=w+q.length+A;j.push(v);A++;if(m.supportUVs){v=new THREE.UV;v.u=f(K,z).u+f(J,z).u;v.v=f(K,z).v+f(J,z).v;v.u=v.u/2;v.v=v.v/2;g(r[s],z,v);if(!u[s]){v=new THREE.UV;v.u=f(K,D).u+f(J,D).u;v.v=f(K,D).v+f(J,D).v;v.u=v.u/2;v.v=v.v/2;g(r[s],D,v)}}}b("-- Step 2 done");var E,M;D=["123",
  22934. "12","2","23"];J=["123","23","3","31"];var G=["123","31","1","12"],i=["1234","12","2","23"],T=["1234","23","3","34"],U=["1234","34","4","41"],C=["1234","41","1","12"];s=0;for(x=n.length;s<x;s++){z=q[s];v=w+s;if(z instanceof THREE.Face3){A=e(z.a,z.b);K=e(z.b,z.c);E=e(z.c,z.a);d(v,r[A],z.b,r[K],z,D,s);d(v,r[K],z.c,r[E],z,J,s);d(v,r[E],z.a,r[A],z,G,s)}else if(z instanceof THREE.Face4){A=e(z.a,z.b);K=e(z.b,z.c);E=e(z.c,z.d);M=e(z.d,z.a);d(v,r[A],z.b,r[K],z,i,s);d(v,r[K],z.c,r[E],z,T,s);d(v,r[E],z.d,r[M],
  22935. z,U,s);d(v,r[M],z.a,r[A],z,C,s)}else b("face should be a face!",z)}r=new THREE.Vector3;z=new THREE.Vector3;s=0;for(x=o.length;s<x;s++)if(R[s]!==void 0){r.set(0,0,0);z.set(0,0,0);K=new THREE.Vector3(0,0,0);v=0;for(F in P[s]){r.addSelf(n[F]);v++}D=0;A=R[s].length;for(F=0;F<A;F++)u[e(R[s][F][0],R[s][F][1])]&&D++;if(D!=2){r.divideScalar(v);for(F=0;F<A;F++){v=R[s][F];v=o[v[0]].clone().addSelf(o[v[1]]).divideScalar(2);z.addSelf(v)}z.divideScalar(A);K.addSelf(o[s]);K.multiplyScalar(A-3);K.addSelf(r);K.addSelf(z.multiplyScalar(2));
  22936. K.divideScalar(A);j[s]=K}}a.vertices=j;a.faces=l;a.faceVertexUvs[0]=p;delete a.__tmpVertices;a.computeCentroids();a.computeFaceNormals();a.computeVertexNormals()};THREE.ImmediateRenderObject=function(){THREE.Object3D.call(this);this.render=function(){}};THREE.ImmediateRenderObject.prototype=new THREE.Object3D;THREE.ImmediateRenderObject.prototype.constructor=THREE.ImmediateRenderObject;
  22937. THREE.LensFlare=function(a,b,c,d,e){THREE.Object3D.call(this);this.lensFlares=[];this.positionScreen=new THREE.Vector3;this.customUpdateCallback=void 0;a!==void 0&&this.add(a,b,c,d,e)};THREE.LensFlare.prototype=new THREE.Object3D;THREE.LensFlare.prototype.constructor=THREE.LensFlare;THREE.LensFlare.prototype.supr=THREE.Object3D.prototype;
  22938. THREE.LensFlare.prototype.add=function(a,b,c,d,e,f){b===void 0&&(b=-1);c===void 0&&(c=0);f===void 0&&(f=1);e===void 0&&(e=new THREE.Color(16777215));if(d===void 0)d=THREE.NormalBlending;c=Math.min(c,Math.max(0,c));this.lensFlares.push({texture:a,size:b,distance:c,x:0,y:0,z:0,scale:1,rotation:1,opacity:f,color:e,blending:d})};
  22939. THREE.LensFlare.prototype.updateLensFlares=function(){var a,b=this.lensFlares.length,c,d=-this.positionScreen.x*2,e=-this.positionScreen.y*2;for(a=0;a<b;a++){c=this.lensFlares[a];c.x=this.positionScreen.x+d*c.distance;c.y=this.positionScreen.y+e*c.distance;c.wantedRotation=c.x*Math.PI*0.25;c.rotation=c.rotation+(c.wantedRotation-c.rotation)*0.25}};
  22940. THREE.MorphBlendMesh=function(a,b){THREE.Mesh.call(this,a,b);this.animationsMap={};this.animationsList=[];var c=this.geometry.morphTargets.length;this.createAnimation("__default",0,c-1,c/1);this.setAnimationWeight("__default",1)};THREE.MorphBlendMesh.prototype=new THREE.Mesh;THREE.MorphBlendMesh.prototype.constructor=THREE.MorphBlendMesh;
  22941. THREE.MorphBlendMesh.prototype.createAnimation=function(a,b,c,d){b={startFrame:b,endFrame:c,length:c-b+1,fps:d,duration:(c-b)/d,lastFrame:0,currentFrame:0,active:false,time:0,direction:1,weight:1,directionBackwards:false,mirroredLoop:false};this.animationsMap[a]=b;this.animationsList.push(b)};
  22942. THREE.MorphBlendMesh.prototype.autoCreateAnimations=function(a){for(var b=/([a-z]+)(\d+)/,c,d={},e=this.geometry,f=0,g=e.morphTargets.length;f<g;f++){var h=e.morphTargets[f].name.match(b);if(h&&h.length>1){var k=h[1];d[k]||(d[k]={start:Infinity,end:-Infinity});h=d[k];if(f<h.start)h.start=f;if(f>h.end)h.end=f;c||(c=k)}}for(k in d){h=d[k];this.createAnimation(k,h.start,h.end,a)}this.firstAnimation=c};
  22943. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward=function(a){if(a=this.animationsMap[a]){a.direction=1;a.directionBackwards=false}};THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward=function(a){if(a=this.animationsMap[a]){a.direction=-1;a.directionBackwards=true}};THREE.MorphBlendMesh.prototype.setAnimationFPS=function(a,b){var c=this.animationsMap[a];if(c){c.fps=b;c.duration=(c.end-c.start)/c.fps}};
  22944. THREE.MorphBlendMesh.prototype.setAnimationDuration=function(a,b){var c=this.animationsMap[a];if(c){c.duration=b;c.fps=(c.end-c.start)/c.duration}};THREE.MorphBlendMesh.prototype.setAnimationWeight=function(a,b){var c=this.animationsMap[a];if(c)c.weight=b};THREE.MorphBlendMesh.prototype.setAnimationTime=function(a,b){var c=this.animationsMap[a];if(c)c.time=b};THREE.MorphBlendMesh.prototype.getAnimationTime=function(a){var b=0;if(a=this.animationsMap[a])b=a.time;return b};
  22945. THREE.MorphBlendMesh.prototype.getAnimationDuration=function(a){var b=-1;if(a=this.animationsMap[a])b=a.duration;return b};THREE.MorphBlendMesh.prototype.playAnimation=function(a){var b=this.animationsMap[a];if(b){b.time=0;b.active=true}else console.warn("animation["+a+"] undefined")};THREE.MorphBlendMesh.prototype.stopAnimation=function(a){if(a=this.animationsMap[a])a.active=false};
  22946. THREE.MorphBlendMesh.prototype.update=function(a){for(var b=0,c=this.animationsList.length;b<c;b++){var d=this.animationsList[b];if(d.active){var e=d.duration/d.length;d.time=d.time+d.direction*a;if(d.mirroredLoop){if(d.time>d.duration||d.time<0){d.direction=d.direction*-1;if(d.time>d.duration){d.time=d.duration;d.directionBackwards=true}if(d.time<0){d.time=0;d.directionBackwards=false}}}else{d.time=d.time%d.duration;if(d.time<0)d.time=d.time+d.duration}var f=d.startFrame+THREE.Math.clamp(Math.floor(d.time/
  22947. e),0,d.length-1),g=d.weight;if(f!==d.currentFrame){this.morphTargetInfluences[d.lastFrame]=0;this.morphTargetInfluences[d.currentFrame]=1*g;this.morphTargetInfluences[f]=0;d.lastFrame=d.currentFrame;d.currentFrame=f}e=d.time%e/e;d.directionBackwards&&(e=1-e);this.morphTargetInfluences[d.currentFrame]=e*g;this.morphTargetInfluences[d.lastFrame]=(1-e)*g}}};
  22948. THREE.LensFlarePlugin=function(){function a(a){var c=b.createProgram(),d=b.createShader(b.FRAGMENT_SHADER),e=b.createShader(b.VERTEX_SHADER);b.shaderSource(d,a.fragmentShader);b.shaderSource(e,a.vertexShader);b.compileShader(d);b.compileShader(e);b.attachShader(c,d);b.attachShader(c,e);b.linkProgram(c);return c}var b,c,d,e,f,g,h,k,j,l,p,m,o;this.init=function(q){b=q.context;c=q;d=new Float32Array(16);e=new Uint16Array(6);q=0;d[q++]=-1;d[q++]=-1;d[q++]=0;d[q++]=0;d[q++]=1;d[q++]=-1;d[q++]=1;d[q++]=
  22949. 0;d[q++]=1;d[q++]=1;d[q++]=1;d[q++]=1;d[q++]=-1;d[q++]=1;d[q++]=0;d[q++]=1;q=0;e[q++]=0;e[q++]=1;e[q++]=2;e[q++]=0;e[q++]=2;e[q++]=3;f=b.createBuffer();g=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,f);b.bufferData(b.ARRAY_BUFFER,d,b.STATIC_DRAW);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,g);b.bufferData(b.ELEMENT_ARRAY_BUFFER,e,b.STATIC_DRAW);h=b.createTexture();k=b.createTexture();b.bindTexture(b.TEXTURE_2D,h);b.texImage2D(b.TEXTURE_2D,0,b.RGB,16,16,0,b.RGB,b.UNSIGNED_BYTE,null);b.texParameteri(b.TEXTURE_2D,
  22950. b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,b.NEAREST);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,b.NEAREST);b.bindTexture(b.TEXTURE_2D,k);b.texImage2D(b.TEXTURE_2D,0,b.RGBA,16,16,0,b.RGBA,b.UNSIGNED_BYTE,null);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,b.NEAREST);
  22951. b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,b.NEAREST);if(b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)<=0){j=false;l=a(THREE.ShaderFlares.lensFlare)}else{j=true;l=a(THREE.ShaderFlares.lensFlareVertexTexture)}p={};m={};p.vertex=b.getAttribLocation(l,"position");p.uv=b.getAttribLocation(l,"uv");m.renderType=b.getUniformLocation(l,"renderType");m.map=b.getUniformLocation(l,"map");m.occlusionMap=b.getUniformLocation(l,"occlusionMap");m.opacity=b.getUniformLocation(l,"opacity");m.color=b.getUniformLocation(l,
  22952. "color");m.scale=b.getUniformLocation(l,"scale");m.rotation=b.getUniformLocation(l,"rotation");m.screenPosition=b.getUniformLocation(l,"screenPosition");o=false};this.render=function(a,d,e,u){var a=a.__webglFlares,t=a.length;if(t){var w=new THREE.Vector3,s=u/e,x=e*0.5,F=u*0.5,D=16/u,z=new THREE.Vector2(D*s,D),v=new THREE.Vector3(1,1,0),A=new THREE.Vector2(1,1),J=m,D=p;b.useProgram(l);if(!o){b.enableVertexAttribArray(p.vertex);b.enableVertexAttribArray(p.uv);o=true}b.uniform1i(J.occlusionMap,0);b.uniform1i(J.map,
  22953. 1);b.bindBuffer(b.ARRAY_BUFFER,f);b.vertexAttribPointer(D.vertex,2,b.FLOAT,false,16,0);b.vertexAttribPointer(D.uv,2,b.FLOAT,false,16,8);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,g);b.disable(b.CULL_FACE);b.depthMask(false);var K,R,P,E,M;for(K=0;K<t;K++){D=16/u;z.set(D*s,D);E=a[K];w.set(E.matrixWorld.elements[12],E.matrixWorld.elements[13],E.matrixWorld.elements[14]);d.matrixWorldInverse.multiplyVector3(w);d.projectionMatrix.multiplyVector3(w);v.copy(w);A.x=v.x*x+x;A.y=v.y*F+F;if(j||A.x>0&&A.x<e&&A.y>0&&
  22954. A.y<u){b.activeTexture(b.TEXTURE1);b.bindTexture(b.TEXTURE_2D,h);b.copyTexImage2D(b.TEXTURE_2D,0,b.RGB,A.x-8,A.y-8,16,16,0);b.uniform1i(J.renderType,0);b.uniform2f(J.scale,z.x,z.y);b.uniform3f(J.screenPosition,v.x,v.y,v.z);b.disable(b.BLEND);b.enable(b.DEPTH_TEST);b.drawElements(b.TRIANGLES,6,b.UNSIGNED_SHORT,0);b.activeTexture(b.TEXTURE0);b.bindTexture(b.TEXTURE_2D,k);b.copyTexImage2D(b.TEXTURE_2D,0,b.RGBA,A.x-8,A.y-8,16,16,0);b.uniform1i(J.renderType,1);b.disable(b.DEPTH_TEST);b.activeTexture(b.TEXTURE1);
  22955. b.bindTexture(b.TEXTURE_2D,h);b.drawElements(b.TRIANGLES,6,b.UNSIGNED_SHORT,0);E.positionScreen.copy(v);E.customUpdateCallback?E.customUpdateCallback(E):E.updateLensFlares();b.uniform1i(J.renderType,2);b.enable(b.BLEND);R=0;for(P=E.lensFlares.length;R<P;R++){M=E.lensFlares[R];if(M.opacity>0.001&&M.scale>0.001){v.x=M.x;v.y=M.y;v.z=M.z;D=M.size*M.scale/u;z.x=D*s;z.y=D;b.uniform3f(J.screenPosition,v.x,v.y,v.z);b.uniform2f(J.scale,z.x,z.y);b.uniform1f(J.rotation,M.rotation);b.uniform1f(J.opacity,M.opacity);
  22956. b.uniform3f(J.color,M.color.r,M.color.g,M.color.b);c.setBlending(M.blending,M.blendEquation,M.blendSrc,M.blendDst);c.setTexture(M.texture,1);b.drawElements(b.TRIANGLES,6,b.UNSIGNED_SHORT,0)}}}}b.enable(b.CULL_FACE);b.enable(b.DEPTH_TEST);b.depthMask(true)}}};
  22957. THREE.ShadowMapPlugin=function(){var a,b,c,d,e=new THREE.Frustum,f=new THREE.Matrix4,g=new THREE.Vector3,h=new THREE.Vector3;this.init=function(e){a=e.context;b=e;var e=THREE.ShaderLib.depthRGBA,f=THREE.UniformsUtils.clone(e.uniforms);c=new THREE.ShaderMaterial({fragmentShader:e.fragmentShader,vertexShader:e.vertexShader,uniforms:f});d=new THREE.ShaderMaterial({fragmentShader:e.fragmentShader,vertexShader:e.vertexShader,uniforms:f,morphTargets:true});c._shadowPass=true;d._shadowPass=true};this.render=
  22958. function(a,c){b.shadowMapEnabled&&b.shadowMapAutoUpdate&&this.update(a,c)};this.update=function(k,j){var l,p,m,o,q,n,r,u,t,w=[];o=0;a.clearColor(1,1,1,1);a.disable(a.BLEND);a.enable(a.CULL_FACE);b.shadowMapCullFrontFaces?a.cullFace(a.FRONT):a.cullFace(a.BACK);b.setDepthTest(true);l=0;for(p=k.__lights.length;l<p;l++){m=k.__lights[l];if(m.castShadow)if(m instanceof THREE.DirectionalLight&&m.shadowCascade)for(q=0;q<m.shadowCascadeCount;q++){var s;if(m.shadowCascadeArray[q])s=m.shadowCascadeArray[q];
  22959. else{t=m;r=q;s=new THREE.DirectionalLight;s.isVirtual=true;s.onlyShadow=true;s.castShadow=true;s.shadowCameraNear=t.shadowCameraNear;s.shadowCameraFar=t.shadowCameraFar;s.shadowCameraLeft=t.shadowCameraLeft;s.shadowCameraRight=t.shadowCameraRight;s.shadowCameraBottom=t.shadowCameraBottom;s.shadowCameraTop=t.shadowCameraTop;s.shadowCameraVisible=t.shadowCameraVisible;s.shadowDarkness=t.shadowDarkness;s.shadowBias=t.shadowCascadeBias[r];s.shadowMapWidth=t.shadowCascadeWidth[r];s.shadowMapHeight=t.shadowCascadeHeight[r];
  22960. s.pointsWorld=[];s.pointsFrustum=[];u=s.pointsWorld;n=s.pointsFrustum;for(var x=0;x<8;x++){u[x]=new THREE.Vector3;n[x]=new THREE.Vector3}u=t.shadowCascadeNearZ[r];t=t.shadowCascadeFarZ[r];n[0].set(-1,-1,u);n[1].set(1,-1,u);n[2].set(-1,1,u);n[3].set(1,1,u);n[4].set(-1,-1,t);n[5].set(1,-1,t);n[6].set(-1,1,t);n[7].set(1,1,t);s.originalCamera=j;n=new THREE.Gyroscope;n.position=m.shadowCascadeOffset;n.add(s);n.add(s.target);j.add(n);m.shadowCascadeArray[q]=s;console.log("Created virtualLight",s)}r=m;u=
  22961. q;t=r.shadowCascadeArray[u];t.position.copy(r.position);t.target.position.copy(r.target.position);t.lookAt(t.target);t.shadowCameraVisible=r.shadowCameraVisible;t.shadowDarkness=r.shadowDarkness;t.shadowBias=r.shadowCascadeBias[u];n=r.shadowCascadeNearZ[u];r=r.shadowCascadeFarZ[u];t=t.pointsFrustum;t[0].z=n;t[1].z=n;t[2].z=n;t[3].z=n;t[4].z=r;t[5].z=r;t[6].z=r;t[7].z=r;w[o]=s;o++}else{w[o]=m;o++}}l=0;for(p=w.length;l<p;l++){m=w[l];if(!m.shadowMap){m.shadowMap=new THREE.WebGLRenderTarget(m.shadowMapWidth,
  22962. m.shadowMapHeight,{minFilter:THREE.LinearFilter,magFilter:THREE.LinearFilter,format:THREE.RGBAFormat});m.shadowMapSize=new THREE.Vector2(m.shadowMapWidth,m.shadowMapHeight);m.shadowMatrix=new THREE.Matrix4}if(!m.shadowCamera){if(m instanceof THREE.SpotLight)m.shadowCamera=new THREE.PerspectiveCamera(m.shadowCameraFov,m.shadowMapWidth/m.shadowMapHeight,m.shadowCameraNear,m.shadowCameraFar);else if(m instanceof THREE.DirectionalLight)m.shadowCamera=new THREE.OrthographicCamera(m.shadowCameraLeft,m.shadowCameraRight,
  22963. m.shadowCameraTop,m.shadowCameraBottom,m.shadowCameraNear,m.shadowCameraFar);else{console.error("Unsupported light type for shadow");continue}k.add(m.shadowCamera);b.autoUpdateScene&&k.updateMatrixWorld()}if(m.shadowCameraVisible&&!m.cameraHelper){m.cameraHelper=new THREE.CameraHelper(m.shadowCamera);m.shadowCamera.add(m.cameraHelper)}if(m.isVirtual&&s.originalCamera==j){q=j;o=m.shadowCamera;n=m.pointsFrustum;t=m.pointsWorld;g.set(Infinity,Infinity,Infinity);h.set(-Infinity,-Infinity,-Infinity);for(r=
  22964. 0;r<8;r++){u=t[r];u.copy(n[r]);THREE.ShadowMapPlugin.__projector.unprojectVector(u,q);o.matrixWorldInverse.multiplyVector3(u);if(u.x<g.x)g.x=u.x;if(u.x>h.x)h.x=u.x;if(u.y<g.y)g.y=u.y;if(u.y>h.y)h.y=u.y;if(u.z<g.z)g.z=u.z;if(u.z>h.z)h.z=u.z}o.left=g.x;o.right=h.x;o.top=h.y;o.bottom=g.y;o.updateProjectionMatrix()}o=m.shadowMap;n=m.shadowMatrix;q=m.shadowCamera;q.position.copy(m.matrixWorld.getPosition());q.lookAt(m.target.matrixWorld.getPosition());q.updateMatrixWorld();q.matrixWorldInverse.getInverse(q.matrixWorld);
  22965. if(m.cameraHelper)m.cameraHelper.lines.visible=m.shadowCameraVisible;m.shadowCameraVisible&&m.cameraHelper.update();n.set(0.5,0,0,0.5,0,0.5,0,0.5,0,0,0.5,0.5,0,0,0,1);n.multiplySelf(q.projectionMatrix);n.multiplySelf(q.matrixWorldInverse);if(!q._viewMatrixArray)q._viewMatrixArray=new Float32Array(16);if(!q._projectionMatrixArray)q._projectionMatrixArray=new Float32Array(16);q.matrixWorldInverse.flattenToArray(q._viewMatrixArray);q.projectionMatrix.flattenToArray(q._projectionMatrixArray);f.multiply(q.projectionMatrix,
  22966. q.matrixWorldInverse);e.setFromMatrix(f);b.setRenderTarget(o);b.clear();t=k.__webglObjects;m=0;for(o=t.length;m<o;m++){r=t[m];n=r.object;r.render=false;if(n.visible&&n.castShadow&&(!(n instanceof THREE.Mesh)||!n.frustumCulled||e.contains(n))){n._modelViewMatrix.multiply(q.matrixWorldInverse,n.matrixWorld);r.render=true}}m=0;for(o=t.length;m<o;m++){r=t[m];if(r.render){n=r.object;r=r.buffer;u=n.customDepthMaterial?n.customDepthMaterial:n.geometry.morphTargets.length?d:c;r instanceof THREE.BufferGeometry?
  22967. b.renderBufferDirect(q,k.__lights,null,u,r,n):b.renderBuffer(q,k.__lights,null,u,r,n)}}t=k.__webglObjectsImmediate;m=0;for(o=t.length;m<o;m++){r=t[m];n=r.object;if(n.visible&&n.castShadow){n._modelViewMatrix.multiply(q.matrixWorldInverse,n.matrixWorld);b.renderImmediateObject(q,k.__lights,null,c,n)}}}l=b.getClearColor();p=b.getClearAlpha();a.clearColor(l.r,l.g,l.b,p);a.enable(a.BLEND);b.shadowMapCullFrontFaces&&a.cullFace(a.BACK)}};THREE.ShadowMapPlugin.__projector=new THREE.Projector;
  22968. THREE.SpritePlugin=function(){function a(a,b){return b.z-a.z}var b,c,d,e,f,g,h,k,j,l;this.init=function(a){b=a.context;c=a;d=new Float32Array(16);e=new Uint16Array(6);a=0;d[a++]=-1;d[a++]=-1;d[a++]=0;d[a++]=1;d[a++]=1;d[a++]=-1;d[a++]=1;d[a++]=1;d[a++]=1;d[a++]=1;d[a++]=1;d[a++]=0;d[a++]=-1;d[a++]=1;d[a++]=0;a=d[a++]=0;e[a++]=0;e[a++]=1;e[a++]=2;e[a++]=0;e[a++]=2;e[a++]=3;f=b.createBuffer();g=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,f);b.bufferData(b.ARRAY_BUFFER,d,b.STATIC_DRAW);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,
  22969. g);b.bufferData(b.ELEMENT_ARRAY_BUFFER,e,b.STATIC_DRAW);var a=THREE.ShaderSprite.sprite,m=b.createProgram(),o=b.createShader(b.FRAGMENT_SHADER),q=b.createShader(b.VERTEX_SHADER);b.shaderSource(o,a.fragmentShader);b.shaderSource(q,a.vertexShader);b.compileShader(o);b.compileShader(q);b.attachShader(m,o);b.attachShader(m,q);b.linkProgram(m);h=m;k={};j={};k.position=b.getAttribLocation(h,"position");k.uv=b.getAttribLocation(h,"uv");j.uvOffset=b.getUniformLocation(h,"uvOffset");j.uvScale=b.getUniformLocation(h,
  22970. "uvScale");j.rotation=b.getUniformLocation(h,"rotation");j.scale=b.getUniformLocation(h,"scale");j.alignment=b.getUniformLocation(h,"alignment");j.color=b.getUniformLocation(h,"color");j.map=b.getUniformLocation(h,"map");j.opacity=b.getUniformLocation(h,"opacity");j.useScreenCoordinates=b.getUniformLocation(h,"useScreenCoordinates");j.affectedByDistance=b.getUniformLocation(h,"affectedByDistance");j.screenPosition=b.getUniformLocation(h,"screenPosition");j.modelViewMatrix=b.getUniformLocation(h,"modelViewMatrix");
  22971. j.projectionMatrix=b.getUniformLocation(h,"projectionMatrix");l=false};this.render=function(d,e,o,q){var d=d.__webglSprites,n=d.length;if(n){var r=k,u=j,t=q/o,o=o*0.5,w=q*0.5,s=true;b.useProgram(h);if(!l){b.enableVertexAttribArray(r.position);b.enableVertexAttribArray(r.uv);l=true}b.disable(b.CULL_FACE);b.enable(b.BLEND);b.depthMask(true);b.bindBuffer(b.ARRAY_BUFFER,f);b.vertexAttribPointer(r.position,2,b.FLOAT,false,16,0);b.vertexAttribPointer(r.uv,2,b.FLOAT,false,16,8);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,
  22972. g);b.uniformMatrix4fv(u.projectionMatrix,false,e._projectionMatrixArray);b.activeTexture(b.TEXTURE0);b.uniform1i(u.map,0);for(var x,F=[],r=0;r<n;r++){x=d[r];if(x.visible&&x.opacity!==0)if(x.useScreenCoordinates)x.z=-x.position.z;else{x._modelViewMatrix.multiply(e.matrixWorldInverse,x.matrixWorld);x.z=-x._modelViewMatrix.elements[14]}}d.sort(a);for(r=0;r<n;r++){x=d[r];if(x.visible&&x.opacity!==0&&x.map&&x.map.image&&x.map.image.width){if(x.useScreenCoordinates){b.uniform1i(u.useScreenCoordinates,1);
  22973. b.uniform3f(u.screenPosition,(x.position.x-o)/o,(w-x.position.y)/w,Math.max(0,Math.min(1,x.position.z)))}else{b.uniform1i(u.useScreenCoordinates,0);b.uniform1i(u.affectedByDistance,x.affectedByDistance?1:0);b.uniformMatrix4fv(u.modelViewMatrix,false,x._modelViewMatrix.elements)}e=x.map.image.width/(x.scaleByViewport?q:1);F[0]=e*t*x.scale.x;F[1]=e*x.scale.y;b.uniform2f(u.uvScale,x.uvScale.x,x.uvScale.y);b.uniform2f(u.uvOffset,x.uvOffset.x,x.uvOffset.y);b.uniform2f(u.alignment,x.alignment.x,x.alignment.y);
  22974. b.uniform1f(u.opacity,x.opacity);b.uniform3f(u.color,x.color.r,x.color.g,x.color.b);b.uniform1f(u.rotation,x.rotation);b.uniform2fv(u.scale,F);if(x.mergeWith3D&&!s){b.enable(b.DEPTH_TEST);s=true}else if(!x.mergeWith3D&&s){b.disable(b.DEPTH_TEST);s=false}c.setBlending(x.blending,x.blendEquation,x.blendSrc,x.blendDst);c.setTexture(x.map,0);b.drawElements(b.TRIANGLES,6,b.UNSIGNED_SHORT,0)}}b.enable(b.CULL_FACE);b.enable(b.DEPTH_TEST);b.depthMask(true)}}};
  22975. THREE.DepthPassPlugin=function(){this.enabled=false;this.renderTarget=null;var a,b,c,d,e=new THREE.Frustum,f=new THREE.Matrix4;this.init=function(e){a=e.context;b=e;var e=THREE.ShaderLib.depthRGBA,f=THREE.UniformsUtils.clone(e.uniforms);c=new THREE.ShaderMaterial({fragmentShader:e.fragmentShader,vertexShader:e.vertexShader,uniforms:f});d=new THREE.ShaderMaterial({fragmentShader:e.fragmentShader,vertexShader:e.vertexShader,uniforms:f,morphTargets:true});c._shadowPass=true;d._shadowPass=true};this.render=
  22976. function(a,b){this.enabled&&this.update(a,b)};this.update=function(g,h){var k,j,l,p,m,o;a.clearColor(1,1,1,1);a.disable(a.BLEND);b.setDepthTest(true);b.autoUpdateScene&&g.updateMatrixWorld();if(!h._viewMatrixArray)h._viewMatrixArray=new Float32Array(16);if(!h._projectionMatrixArray)h._projectionMatrixArray=new Float32Array(16);h.matrixWorldInverse.getInverse(h.matrixWorld);h.matrixWorldInverse.flattenToArray(h._viewMatrixArray);h.projectionMatrix.flattenToArray(h._projectionMatrixArray);f.multiply(h.projectionMatrix,
  22977. h.matrixWorldInverse);e.setFromMatrix(f);b.setRenderTarget(this.renderTarget);b.clear();o=g.__webglObjects;k=0;for(j=o.length;k<j;k++){l=o[k];m=l.object;l.render=false;if(m.visible&&(!(m instanceof THREE.Mesh)||!m.frustumCulled||e.contains(m))){m._modelViewMatrix.multiply(h.matrixWorldInverse,m.matrixWorld);l.render=true}}k=0;for(j=o.length;k<j;k++){l=o[k];if(l.render){m=l.object;l=l.buffer;b.setObjectFaces(m);p=m.customDepthMaterial?m.customDepthMaterial:m.geometry.morphTargets.length?d:c;l instanceof
  22978. THREE.BufferGeometry?b.renderBufferDirect(h,g.__lights,null,p,l,m):b.renderBuffer(h,g.__lights,null,p,l,m)}}o=g.__webglObjectsImmediate;k=0;for(j=o.length;k<j;k++){l=o[k];m=l.object;if(m.visible&&m.castShadow){m._modelViewMatrix.multiply(h.matrixWorldInverse,m.matrixWorld);b.renderImmediateObject(h,g.__lights,null,c,m)}}k=b.getClearColor();j=b.getClearAlpha();a.clearColor(k.r,k.g,k.b,j);a.enable(a.BLEND)}};
  22979. THREE.WebGLRenderer&&(THREE.AnaglyphWebGLRenderer=function(a){THREE.WebGLRenderer.call(this,a);this.autoUpdateScene=false;var b=this,c=this.setSize,d=this.render,e=new THREE.PerspectiveCamera,f=new THREE.PerspectiveCamera,g=new THREE.Matrix4,h=new THREE.Matrix4,k,j,l,p;e.matrixAutoUpdate=f.matrixAutoUpdate=false;var a={minFilter:THREE.LinearFilter,magFilter:THREE.NearestFilter,format:THREE.RGBAFormat},m=new THREE.WebGLRenderTarget(512,512,a),o=new THREE.WebGLRenderTarget(512,512,a),q=new THREE.PerspectiveCamera(53,
  22980. 1,1,1E4);q.position.z=2;var a=new THREE.ShaderMaterial({uniforms:{mapLeft:{type:"t",value:0,texture:m},mapRight:{type:"t",value:1,texture:o}},vertexShader:"varying vec2 vUv;\nvoid main() {\nvUv = vec2( uv.x, 1.0 - uv.y );\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"uniform sampler2D mapLeft;\nuniform sampler2D mapRight;\nvarying vec2 vUv;\nvoid main() {\nvec4 colorL, colorR;\nvec2 uv = vUv;\ncolorL = texture2D( mapLeft, uv );\ncolorR = texture2D( mapRight, uv );\ngl_FragColor = vec4( colorL.g * 0.7 + colorL.b * 0.3, colorR.g, colorR.b, colorL.a + colorR.a ) * 1.1;\n}"}),
  22981. n=new THREE.Scene,a=new THREE.Mesh(new THREE.PlaneGeometry(2,2),a);a.rotation.x=Math.PI/2;n.add(a);n.add(q);this.setSize=function(a,d){c.call(b,a,d);m.width=a;m.height=d;o.width=a;o.height=d};this.render=function(a,c){a.updateMatrixWorld();if(k!==c.aspect||j!==c.near||l!==c.far||p!==c.fov){k=c.aspect;j=c.near;l=c.far;p=c.fov;var t=c.projectionMatrix.clone(),w=125/30*0.5,s=w*j/125,x=j*Math.tan(p*Math.PI/360),F;g.elements[12]=w;h.elements[12]=-w;w=-x*k+s;F=x*k+s;t.elements[0]=2*j/(F-w);t.elements[8]=
  22982. (F+w)/(F-w);e.projectionMatrix.copy(t);w=-x*k-s;F=x*k-s;t.elements[0]=2*j/(F-w);t.elements[8]=(F+w)/(F-w);f.projectionMatrix.copy(t)}e.matrixWorld.copy(c.matrixWorld).multiplySelf(h);e.position.copy(c.position);e.near=c.near;e.far=c.far;d.call(b,a,e,m,true);f.matrixWorld.copy(c.matrixWorld).multiplySelf(g);f.position.copy(c.position);f.near=c.near;f.far=c.far;d.call(b,a,f,o,true);n.updateMatrixWorld();d.call(b,n,q)}});
  22983. THREE.WebGLRenderer&&(THREE.CrosseyedWebGLRenderer=function(a){THREE.WebGLRenderer.call(this,a);this.autoClear=false;var b=this,c=this.setSize,d=this.render,e,f,g=new THREE.PerspectiveCamera;g.target=new THREE.Vector3(0,0,0);var h=new THREE.PerspectiveCamera;h.target=new THREE.Vector3(0,0,0);b.separation=10;if(a&&a.separation!==void 0)b.separation=a.separation;this.setSize=function(a,d){c.call(b,a,d);e=a/2;f=d};this.render=function(a,c){this.clear();g.fov=c.fov;g.aspect=0.5*c.aspect;g.near=c.near;
  22984. g.far=c.far;g.updateProjectionMatrix();g.position.copy(c.position);g.target.copy(c.target);g.translateX(b.separation);g.lookAt(g.target);h.projectionMatrix=g.projectionMatrix;h.position.copy(c.position);h.target.copy(c.target);h.translateX(-b.separation);h.lookAt(h.target);this.setViewport(0,0,e,f);d.call(b,a,g);this.setViewport(e,0,e,f);d.call(b,a,h,false)}});
  22985. THREE.ShaderFlares={lensFlareVertexTexture:{vertexShader:"uniform vec3 screenPosition;\nuniform vec2 scale;\nuniform float rotation;\nuniform int renderType;\nuniform sampler2D occlusionMap;\nattribute vec2 position;\nattribute vec2 uv;\nvarying vec2 vUV;\nvarying float vVisibility;\nvoid main() {\nvUV = uv;\nvec2 pos = position;\nif( renderType == 2 ) {\nvec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) ) +\ntexture2D( occlusionMap, vec2( 0.5, 0.1 ) ) +\ntexture2D( occlusionMap, vec2( 0.9, 0.1 ) ) +\ntexture2D( occlusionMap, vec2( 0.9, 0.5 ) ) +\ntexture2D( occlusionMap, vec2( 0.9, 0.9 ) ) +\ntexture2D( occlusionMap, vec2( 0.5, 0.9 ) ) +\ntexture2D( occlusionMap, vec2( 0.1, 0.9 ) ) +\ntexture2D( occlusionMap, vec2( 0.1, 0.5 ) ) +\ntexture2D( occlusionMap, vec2( 0.5, 0.5 ) );\nvVisibility = ( visibility.r / 9.0 ) *\n( 1.0 - visibility.g / 9.0 ) *\n( visibility.b / 9.0 ) *\n( 1.0 - visibility.a / 9.0 );\npos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;\npos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;\n}\ngl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );\n}",fragmentShader:"precision mediump float;\nuniform sampler2D map;\nuniform float opacity;\nuniform int renderType;\nuniform vec3 color;\nvarying vec2 vUV;\nvarying float vVisibility;\nvoid main() {\nif( renderType == 0 ) {\ngl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );\n} else if( renderType == 1 ) {\ngl_FragColor = texture2D( map, vUV );\n} else {\nvec4 texture = texture2D( map, vUV );\ntexture.a *= opacity * vVisibility;\ngl_FragColor = texture;\ngl_FragColor.rgb *= color;\n}\n}"},
  22986. lensFlare:{vertexShader:"uniform vec3 screenPosition;\nuniform vec2 scale;\nuniform float rotation;\nuniform int renderType;\nattribute vec2 position;\nattribute vec2 uv;\nvarying vec2 vUV;\nvoid main() {\nvUV = uv;\nvec2 pos = position;\nif( renderType == 2 ) {\npos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;\npos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;\n}\ngl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );\n}",fragmentShader:"precision mediump float;\nuniform sampler2D map;\nuniform sampler2D occlusionMap;\nuniform float opacity;\nuniform int renderType;\nuniform vec3 color;\nvarying vec2 vUV;\nvoid main() {\nif( renderType == 0 ) {\ngl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );\n} else if( renderType == 1 ) {\ngl_FragColor = texture2D( map, vUV );\n} else {\nfloat visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a +\ntexture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a +\ntexture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a +\ntexture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;\nvisibility = ( 1.0 - visibility / 4.0 );\nvec4 texture = texture2D( map, vUV );\ntexture.a *= opacity * visibility;\ngl_FragColor = texture;\ngl_FragColor.rgb *= color;\n}\n}"}};
  22987. THREE.ShaderSprite={sprite:{vertexShader:"uniform int useScreenCoordinates;\nuniform int affectedByDistance;\nuniform vec3 screenPosition;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform float rotation;\nuniform vec2 scale;\nuniform vec2 alignment;\nuniform vec2 uvOffset;\nuniform vec2 uvScale;\nattribute vec2 position;\nattribute vec2 uv;\nvarying vec2 vUV;\nvoid main() {\nvUV = uvOffset + uv * uvScale;\nvec2 alignedPosition = position + alignment;\nvec2 rotatedPosition;\nrotatedPosition.x = ( cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y ) * scale.x;\nrotatedPosition.y = ( sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y ) * scale.y;\nvec4 finalPosition;\nif( useScreenCoordinates != 0 ) {\nfinalPosition = vec4( screenPosition.xy + rotatedPosition, screenPosition.z, 1.0 );\n} else {\nfinalPosition = projectionMatrix * modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\nfinalPosition.xy += rotatedPosition * ( affectedByDistance == 1 ? 1.0 : finalPosition.z );\n}\ngl_Position = finalPosition;\n}",
  22988. fragmentShader:"precision mediump float;\nuniform vec3 color;\nuniform sampler2D map;\nuniform float opacity;\nvarying vec2 vUV;\nvoid main() {\nvec4 texture = texture2D( map, vUV );\ngl_FragColor = vec4( color * texture.xyz, texture.a * opacity );\n}"}};
  22989. >>>>>>> dev
粤ICP备19079148号