marmoset.js 334 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869
  1. /*
  2. (Built: Tue, Jun 25, 2019 7:21:34 PM)
  3. Marmoset Viewer Code and Tools
  4. Copyright (c) Marmoset LLC.
  5. All rights reserved.
  6. Redistribution and use of this software are permitted provided
  7. that the software remains whole and unmodified and this copyright
  8. notice remains attached. Use or inclusion of any portion of this
  9. code in other software programs is prohibited, excepting simple
  10. embedding of this file in web applications. This software, or any
  11. derivatives thereof, may not be resold, rented, leased, or
  12. distributed on any other for-charge basis.
  13. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
  14. IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  15. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16. */
  17. marmoset = {};
  18. (function(marmoset) {
  19. 'use strict';
  20. function AnimatedObject(a, c, b) {
  21. this.name = c.partName;
  22. this.animatedProperties = [];
  23. this.sceneObjectType = c.sceneObjectType;
  24. this.skinningRigIndex = c.skinningRigIndex;
  25. this.id = b;
  26. this.mesh = this.skinningRig = 0;
  27. this.materialIndex = this.lightIndex = this.meshIndex = -1;
  28. this.emissiveProperty = this.offsetVProperty = this.offsetUProperty = this.material = 0;
  29. this.debugMe = c.debugMe;
  30. this.debugString = "";
  31. this.hasTransform = !1;
  32. this.modelPartIndex = c.modelPartIndex;
  33. this.modelPartFPS = c.modelPartFPS;
  34. this.modelPartScale = c.modelPartScale;
  35. this.parentIndex = c.parentIndex;
  36. this.startTime = c.startTime;
  37. this.endTime = c.endTime;
  38. this.animationLength = this.endTime - this.startTime;
  39. this.totalFrames = c.totalFrames;
  40. this.turnTableSpinOffset = this.turnTableSpin = this.spinProperty = this.dispersionProperty = this.lightIllumProperty = this.skyIllumProperty = this.opacityProperty = this.spotSharpnessProperty = this.spotAngleProperty = this.distanceProperty = this.brightnessProperty = this.blueProperty = this.greenProperty = this.redProperty = this.visibleProperty = 0;
  41. if (c.animatedProperties) {
  42. b = c.animatedProperties.length;
  43. for (var d = 0; d < b; ++d) {
  44. var e = c.animatedProperties[d]
  45. , f = new AnimatedProperty;
  46. f.name = e.name;
  47. this.animatedProperties.push(f);
  48. "Red" != f.name || this.redProperty || (this.redProperty = f);
  49. "Green" != f.name || this.greenProperty || (this.greenProperty = f);
  50. "Blue" != f.name || this.blueProperty || (this.blueProperty = f);
  51. "Brightness" != f.name || this.brightnessProperty || (this.brightnessProperty = f);
  52. "Distance" != f.name || this.distanceProperty || (this.distanceProperty = f);
  53. "Spot Angle" != f.name || this.spotAngleProperty || (this.spotAngleProperty = f);
  54. "Spot Sharpness" != f.name || this.spotSharpnessProperty || (this.spotSharpnessProperty = f);
  55. "Opacity" != f.name || this.opacityProperty || (this.opacityProperty = f);
  56. "Sky Illumination" != f.name || this.skyIllumProperty || (this.skyIllumProperty = f);
  57. "Light Illumination" != f.name || this.lightIllumProperty || (this.lightIllumProperty = f);
  58. "Dispersion" != f.name || this.dispersionProperty || (this.dispersionProperty = f);
  59. "Visible" != f.name || this.visibleProperty || (this.visibleProperty = f);
  60. "Spin Rate" == f.name && (this.spinProperty = f);
  61. "OffsetU" == f.name && (this.offsetUProperty = f);
  62. "OffsetV" == f.name && (this.offsetVProperty = f);
  63. "EmissiveIntensity" == f.name && (this.emissiveProperty = f)
  64. }
  65. }
  66. this.keyframesSharedBufferUShorts = this.keyframesSharedBufferFloats = this.keyFramesByteStream = 0;
  67. if (a = a.get(c.file))
  68. this.keyFramesByteStream = new ByteStream(a.data),
  69. this.unPackKeyFrames();
  70. this.animatedLocalTransform = new AnimatedTransform(this);
  71. this.hasTransform = this.animatedLocalTransform.hasTranslation || this.animatedLocalTransform.hasRotation || this.animatedLocalTransform.hasScale;
  72. this.cachedWorldTransform0 = Matrix.identity();
  73. this.cachedWorldTransform1 = Matrix.identity();
  74. this.cachedWorldTransform2 = Matrix.identity();
  75. this.cachedWorldTransform3 = Matrix.identity();
  76. this.cachedFrame3 = this.cachedFrame2 = this.cachedFrame1 = this.cachedFrame0 = -10;
  77. this.cachedFrameUse3 = this.cachedFrameUse2 = this.cachedFrameUse1 = this.cachedFrameUse0 = 0;
  78. this.useFixedLocalTransform = this.useFixedWorldTransform = !1
  79. }
  80. AnimatedObject.prototype.setFixedWorldTransform = function(a) {
  81. this.useFixedWorldTransform = !0;
  82. Matrix.copy(this.cachedWorldTransform0, a)
  83. }
  84. ;
  85. AnimatedObject.prototype.setFixedLocalTransform = function(a) {
  86. this.useFixedLocalTransform = !0;
  87. this.animatedLocalTransform.lockTransform = !0;
  88. Matrix.copy(this.animatedLocalTransform.cachedmatrix0, a)
  89. }
  90. ;
  91. AnimatedObject.prototype.getCachedWorldTransform = function(a) {
  92. return this.useFixedWorldTransform ? 0 : a == this.cachedFrame0 ? this.cachedmatrix0 : a == this.cachedFrame1 ? this.cachedmatrix1 : a == this.cachedFrame2 ? this.cachedmatrix2 : a == this.cachedFrame3 ? this.cachedmatrix3 : 0
  93. }
  94. ;
  95. AnimatedObject.prototype.getFreeCachedWorldTransform = function(a) {
  96. if (this.useFixedWorldTransform)
  97. return 0;
  98. this.cachedFrameUse0--;
  99. this.cachedFrameUse1--;
  100. this.cachedFrameUse2--;
  101. this.cachedFrameUse3--;
  102. if (this.cachedFrameUse0 <= this.cachedFrameUse1 && this.cachedFrameUse0 <= this.cachedFrameUse2 && this.cachedFrameUse0 <= this.cachedFrameUse3)
  103. return this.cachedFrame0 = a,
  104. this.cachedFrameUse0 = 0,
  105. this.cachedWorldTransform0;
  106. if (this.cachedFrameUse1 <= this.cachedFrameUse0 && this.cachedFrameUse1 <= this.cachedFrameUse2 && this.cachedFrameUse1 <= this.cachedFrameUse3)
  107. return this.cachedFrame1 = a,
  108. this.cachedFrameUse1 = 0,
  109. this.cachedWorldTransform1;
  110. if (this.cachedFrameUse2 <= this.cachedFrameUse0 && this.cachedFrameUse2 <= this.cachedFrameUse1 && this.cachedFrameUse2 <= this.cachedFrameUse3)
  111. return this.cachedFrame2 = a,
  112. this.cachedFrameUse2 = 0,
  113. this.cachedWorldTransform2;
  114. this.cachedFrame3 = a;
  115. this.cachedFrameUse3 = 0;
  116. return this.cachedWorldTransform3
  117. }
  118. ;
  119. AnimatedObject.prototype.unPackKeyFrames = function() {
  120. if (this.keyFramesByteStream) {
  121. var a = new Float32Array(this.keyFramesByteStream.bytes.buffer)
  122. , c = new Uint32Array(this.keyFramesByteStream.bytes.buffer)
  123. , b = new Uint16Array(this.keyFramesByteStream.bytes.buffer)
  124. , d = new Uint8Array(this.keyFramesByteStream.bytes.buffer);
  125. this.keyframesSharedBufferFloats = a;
  126. this.keyframesSharedBufferUShorts = c;
  127. for (var a = 0, c = c[0], a = 1 + c, c = this.animatedProperties.length, e = 0; e < c; e++) {
  128. var f = this.animatedProperties[e]
  129. , g = 2 + 2 * e
  130. , h = 2 * g;
  131. f.keyframeBufferStartIndexFloat = a;
  132. f.numKeyframes = b[g];
  133. f.keyframePackingType = d[h + 2];
  134. f.interpolationType = d[h + 3];
  135. f.indexFloatSkip = 0;
  136. f.indexUShortSkip = 0;
  137. 0 < f.numKeyframes && (0 == f.keyframePackingType ? (f.bytesPerKeyFrame = 16,
  138. f.indexFloatSkip = 4,
  139. f.indexUShortSkip = 8,
  140. f.valueOffsetFloat = 0,
  141. f.weighInOffsetFloat = 1,
  142. f.weighOutOffsetFloat = 2,
  143. f.frameIndexOffsetUShort = 6,
  144. f.interpolationOffsetUShort = 7) : 1 == f.keyframePackingType ? (f.bytesPerKeyFrame = 8,
  145. f.indexFloatSkip = 2,
  146. f.indexUShortSkip = 4,
  147. f.valueOffsetFloat = 0,
  148. f.weighInOffsetFloat = 0,
  149. f.weighOutOffsetFloat = 0,
  150. f.frameIndexOffsetUShort = 2,
  151. f.interpolationOffsetUShort = 3) : 2 == f.keyframePackingType && (f.bytesPerKeyFrame = 4,
  152. f.indexFloatSkip = 1,
  153. f.indexUShortSkip = 2,
  154. f.valueOffsetFloat = 0,
  155. f.weighInOffsetFloat = 0,
  156. f.weighOutOffsetFloat = 0,
  157. f.frameIndexOffsetUShort = 0,
  158. f.interpolationOffsetUShort = 0));
  159. a += f.numKeyframes * f.indexFloatSkip
  160. }
  161. }
  162. }
  163. ;
  164. AnimatedObject.prototype.setupSkinningRig = function(a, c, b, d) {
  165. var e = Matrix.identity()
  166. , f = Matrix.identity()
  167. , g = a.animatedObjects[c]
  168. , h = b * g.modelPartFPS
  169. , h = h - Math.floor(h);
  170. b = Math.floor(a.getObjectAnimationFramePercent(g, b));
  171. var g = b + 1
  172. , k = 1 - h
  173. , n = d.skinningClusters.length;
  174. if (0 < n)
  175. for (var m = 0; m < n; m++) {
  176. var l = d.skinningClusters[m];
  177. l.solveClusterTransformAtFrame(a, c, b, e);
  178. l.solveClusterTransformAtFrame(a, c, g, f);
  179. for (var l = l.matrix, p = 0; 16 > p; p++)
  180. l[p] = e[p] * k + f[p] * h
  181. }
  182. }
  183. ;
  184. AnimatedObject.prototype.evaluateLocalTransformAtFramePercent = function(a, c, b, d) {
  185. if (this.useFixedLocalTransform)
  186. Matrix.copy(c, this.animatedLocalTransform.cachedmatrix0);
  187. else {
  188. var e = 0;
  189. d && (e = this.animatedLocalTransform.getCachedTransform(a));
  190. e ? Matrix.copy(c, e) : ((e = this.animatedLocalTransform.getFreeCachedTransform(a)) ? (this.animatedLocalTransform.evaluateMatrix(e, this.totalFrames, a, b),
  191. Matrix.copy(c, e)) : this.animatedLocalTransform.evaluateMatrix(c, this.totalFrames, a, b),
  192. 0 != this.turnTableSpin && (a = Matrix.rotation(Matrix.empty(), this.turnTableSpin, 1),
  193. Matrix.mul(c, c, a)))
  194. }
  195. }
  196. ;
  197. AnimatedObject.prototype.hasAnimatedTransform = function() {
  198. var a = this.animatedLocalTransform;
  199. return a.TX && 1 < a.TX.numKeyframes || a.TY && 1 < a.TY.numKeyframes || a.TZ && 1 < a.TZ.numKeyframes || a.RX && 1 < a.RX.numKeyframes || a.RY && 1 < a.RY.numKeyframes || a.RZ && 1 < a.RZ.numKeyframes || a.SX && 1 < a.SX.numKeyframes || a.SY && 1 < a.SY.numKeyframes || a.SZ && 1 < a.SZ.numKeyframes ? !0 : !1
  200. }
  201. ;
  202. function AnimatedProperty() {
  203. this.currentValue = 0;
  204. this.keyframeBufferStartIndexFloat = -1;
  205. this.lastValue = this.interpolationOffsetUShort = this.frameIndexOffsetUShort = this.weighOutOffsetFloat = this.weighInOffsetFloat = this.valueOffsetFloat = this.indexUShortSkip = this.indexFloatSkip = this.interpolationType = this.bytesPerKeyFrame = this.keyframePackingType = 0;
  206. this.lastFramePercent = -10;
  207. this.enable = !0;
  208. this.name = "NONE";
  209. this.splineKF0 = new KeyFrame(0,0);
  210. this.splineKF1 = new KeyFrame(0,0);
  211. this.splineKF2 = new KeyFrame(0,0);
  212. this.splineKF3 = new KeyFrame(0,0);
  213. this.debugMe = !0;
  214. this.debugString = "";
  215. this.lastSearchIndex = 1;
  216. this.savedSearchIndex = 0;
  217. this.splineKF0.frameIndex = 0;
  218. this.splineKF1.frameIndex = 1;
  219. this.splineKF2.frameIndex = 2;
  220. this.splineKF3.frameIndex = 3;
  221. this.numKeyframes = 0
  222. }
  223. AnimatedProperty.prototype.evaluateCurve = function(a, c) {
  224. var b = this.splineKF1.frameIndex
  225. , d = this.splineKF2.frameIndex
  226. , e = this.splineKF1.value
  227. , f = this.splineKF2.value
  228. , g = b - (this.splineKF2.frameIndex - this.splineKF0.frameIndex)
  229. , h = d - (this.splineKF1.frameIndex - this.splineKF3.frameIndex)
  230. , k = e - (this.splineKF2.value - this.splineKF0.value) * this.splineKF1.weighOut
  231. , n = f - (this.splineKF1.value - this.splineKF3.value) * this.splineKF2.weighIn;
  232. 3 == this.splineKF1.interpolation && (g = b - (this.splineKF2.frameIndex - this.splineKF1.frameIndex),
  233. k = e - this.splineKF1.weighOut);
  234. 3 == this.splineKF2.interpolation && (h = d - (this.splineKF1.frameIndex - this.splineKF2.frameIndex),
  235. n = f + this.splineKF2.weighIn);
  236. g = (a - g) / (b - g);
  237. b = (a - b) / (d - b);
  238. d = (a - d) / (h - d);
  239. h = e * (1 - b) + f * b;
  240. return ((k * (1 - g) + e * g) * (1 - b) + h * b) * (1 - b) + ((f * (1 - d) + n * d) * b + h * (1 - b)) * b
  241. }
  242. ;
  243. AnimatedProperty.prototype.evaluate = function(a, c, b) {
  244. if (!b)
  245. return c;
  246. if (0 == this.numKeyframes)
  247. return this.lastValue = c;
  248. if (1 == this.numKeyframes)
  249. return this.lastValue = 2 == this.keyframePackingType ? b.keyframesSharedBufferFloats[this.keyframeBufferStartIndexFloat] : b.keyframesSharedBufferFloats[this.keyframeBufferStartIndexFloat + this.valueOffsetFloat];
  250. if (this.lastFramePercent == a)
  251. return this.lastValue;
  252. var d = this.keyframeBufferStartIndexFloat
  253. , e = 2 * this.keyframeBufferStartIndexFloat;
  254. this.lastValue = c;
  255. this.lastFramePercent = a;
  256. if (2 == this.keyframePackingType) {
  257. c = Math.floor(a);
  258. var f = a - c;
  259. a >= this.numKeyframes && (c -= Math.floor(a / this.numKeyframes) * this.numKeyframes);
  260. if (c >= this.numKeyframes - 1)
  261. return this.lastValue = b.keyframesSharedBufferFloats[d + (this.numKeyframes - 1)];
  262. if (0 > c)
  263. return this.lastValue = b.keyframesSharedBufferFloats[d];
  264. if (0 == f)
  265. return this.lastValue = b.keyframesSharedBufferFloats[d + c];
  266. a = e = b.keyframesSharedBufferFloats[d + c];
  267. c++;
  268. c >= this.numKeyframes && (c -= this.numKeyframes);
  269. 0 <= c && c < this.numKeyframes ? a = e * (1 - f) + b.keyframesSharedBufferFloats[d + c] * f : b.debugString += "<br>bad lerp frame " + c + " of " + this.numKeyframes;
  270. return this.lastValue = a
  271. }
  272. var g = this.numKeyframes
  273. , f = b.keyframesSharedBufferUShorts[e + this.frameIndexOffsetUShort];
  274. if (a >= b.keyframesSharedBufferUShorts[e + (g - 1) * this.indexUShortSkip + this.frameIndexOffsetUShort])
  275. return this.lastValue = b.keyframesSharedBufferFloats[d + (g - 1) * this.indexFloatSkip + this.valueOffsetFloat];
  276. if (a < f)
  277. return this.lastValue = b.keyframesSharedBufferFloats[d + this.valueOffsetFloat];
  278. this.lastSearchIndex < this.numKeyframes && a > b.keyframesSharedBufferUShorts[e + this.lastSearchIndex * this.indexUShortSkip + this.frameIndexOffsetUShort] && (this.lastSearchIndex = 1);
  279. for (var h = this.lastSearchIndex; h < g; h++) {
  280. var f = d + h * this.indexFloatSkip
  281. , k = d + (h - 1) * this.indexFloatSkip
  282. , n = e + h * this.indexUShortSkip
  283. , m = e + (h - 1) * this.indexUShortSkip;
  284. if (a >= b.keyframesSharedBufferUShorts[m + this.frameIndexOffsetUShort] && a <= b.keyframesSharedBufferUShorts[n + this.frameIndexOffsetUShort]) {
  285. this.lastSearchIndex = h;
  286. var l = b.keyframesSharedBufferUShorts[m + this.interpolationOffsetUShort];
  287. if (2 == l) {
  288. this.lastValue = a = a >= b.keyframesSharedBufferUShorts[n + this.frameIndexOffsetUShort] ? b.keyframesSharedBufferFloats[f + this.valueOffsetFloat] : b.keyframesSharedBufferFloats[k + this.valueOffsetFloat];
  289. break
  290. }
  291. if (0 == l) {
  292. d = b.keyframesSharedBufferUShorts[m + this.frameIndexOffsetUShort];
  293. c = b.keyframesSharedBufferFloats[k + this.valueOffsetFloat];
  294. e = b.keyframesSharedBufferFloats[f + this.valueOffsetFloat];
  295. f = (a - d) / (b.keyframesSharedBufferUShorts[n + this.frameIndexOffsetUShort] - d);
  296. this.lastValue = a = c * (1 - f) + e * f;
  297. break
  298. }
  299. if (1 == l || 3 == l) {
  300. var p = l = !1
  301. , r = 0
  302. , s = b.keyframesSharedBufferFloats[k + this.valueOffsetFloat]
  303. , u = b.keyframesSharedBufferFloats[f + this.valueOffsetFloat]
  304. , q = 0
  305. , x = 0
  306. , m = b.keyframesSharedBufferUShorts[m + this.frameIndexOffsetUShort]
  307. , n = b.keyframesSharedBufferUShorts[n + this.frameIndexOffsetUShort]
  308. , w = 0
  309. , v = 1
  310. , t = 1
  311. , y = 1
  312. , E = 1
  313. , F = 1
  314. , A = 1
  315. , B = 1
  316. , z = 1;
  317. 0 != this.weighInOffsetFloat && (t = b.keyframesSharedBufferFloats[k + this.weighInOffsetFloat],
  318. y = b.keyframesSharedBufferFloats[f + this.weighInOffsetFloat],
  319. A = b.keyframesSharedBufferFloats[k + this.weighOutOffsetFloat],
  320. B = b.keyframesSharedBufferFloats[f + this.weighOutOffsetFloat]);
  321. 1 < h && (l = !0,
  322. r = b.keyframesSharedBufferFloats[d + (h - 2) * this.indexFloatSkip + this.valueOffsetFloat],
  323. x = b.keyframesSharedBufferUShorts[e + (h - 2) * this.indexUShortSkip + this.frameIndexOffsetUShort],
  324. 0 != this.weighInOffsetFloat && (v = b.keyframesSharedBufferFloats[d + (h - 2) * this.indexFloatSkip + this.weighInOffsetFloat],
  325. F = b.keyframesSharedBufferFloats[d + (h - 2) * this.indexFloatSkip + this.weighOutOffsetFloat]));
  326. h < g - 1 && (p = !0,
  327. q = b.keyframesSharedBufferFloats[d + (h + 1) * this.indexFloatSkip + this.valueOffsetFloat],
  328. w = b.keyframesSharedBufferUShorts[e + (h + 1) * this.indexUShortSkip + this.frameIndexOffsetUShort],
  329. 0 != this.weighInOffsetFloat && (E = b.keyframesSharedBufferFloats[d + (h + 1) * this.indexFloatSkip + this.weighInOffsetFloat],
  330. z = b.keyframesSharedBufferFloats[d + (h + 1) * this.indexFloatSkip + this.weighOutOffsetFloat]));
  331. l && p ? (this.splineKF0.value = r,
  332. this.splineKF1.value = s,
  333. this.splineKF2.value = u,
  334. this.splineKF3.value = q,
  335. this.splineKF0.frameIndex = x,
  336. this.splineKF1.frameIndex = m,
  337. this.splineKF2.frameIndex = n,
  338. this.splineKF3.frameIndex = w,
  339. this.splineKF0.weighIn = v,
  340. this.splineKF0.weighOut = F,
  341. this.splineKF1.weighIn = t,
  342. this.splineKF1.weighOut = A,
  343. this.splineKF2.weighIn = y,
  344. this.splineKF2.weighOut = B,
  345. this.splineKF3.weighIn = E,
  346. this.splineKF3.weighOut = z) : (this.splineKF0.value = s,
  347. this.splineKF1.value = s,
  348. this.splineKF2.value = u,
  349. this.splineKF3.value = u,
  350. this.splineKF0.frameIndex = m,
  351. this.splineKF1.frameIndex = m,
  352. this.splineKF2.frameIndex = n,
  353. this.splineKF3.frameIndex = n,
  354. this.splineKF1.weighIn = t,
  355. this.splineKF2.weighIn = y,
  356. this.splineKF1.weighOut = A,
  357. this.splineKF2.weighOut = B,
  358. p ? (this.splineKF3.value = q,
  359. this.splineKF3.frameIndex = w,
  360. this.splineKF3.weighIn = E,
  361. this.splineKF3.weighOut = z) : (this.splineKF3.frameIndex++,
  362. this.splineKF3.value = this.splineKF1.value,
  363. this.splineKF3.weighIn = 1,
  364. this.splineKF3.weighOut = 1),
  365. l ? (this.splineKF0.value = r,
  366. this.splineKF0.frameIndex = x,
  367. this.splineKF0.weighIn = v,
  368. this.splineKF0.weighOut = F) : (this.splineKF0.value = this.splineKF2.value,
  369. this.splineKF0.weighIn = 1,
  370. this.splineKF0.weighOut = 1,
  371. 0 < this.splineKF0.frameIndex ? this.splineKF0.frameIndex-- : (this.splineKF1.frameIndex++,
  372. this.splineKF2.frameIndex++,
  373. this.splineKF3.frameIndex++,
  374. a++)));
  375. this.lastValue = a = this.evaluateCurve(a, c);
  376. break
  377. }
  378. }
  379. }
  380. return this.lastValue
  381. }
  382. ;
  383. function AnimatedTransform(a) {
  384. var c = a.animatedProperties;
  385. this.TX = this.TY = this.TZ = this.RX = this.RY = this.RZ = this.SX = this.SY = this.SZ = 0;
  386. this.hostObject = a;
  387. this.matrix = Matrix.identity();
  388. this.cachedmatrix0 = Matrix.identity();
  389. this.cachedmatrix1 = Matrix.identity();
  390. this.cachedmatrix2 = Matrix.identity();
  391. this.cachedmatrix3 = Matrix.identity();
  392. this.cachedFrame3 = this.cachedFrame2 = this.cachedFrame1 = this.cachedFrame0 = -1;
  393. this.cachedFrameUse3 = this.cachedFrameUse2 = this.cachedFrameUse1 = this.cachedFrameUse0 = 0;
  394. this.debugString = "";
  395. for (a = 0; a < c.length; a++) {
  396. var b = c[a];
  397. "Translation X" == b.name ? this.TX = b : "Translation Y" == b.name ? this.TY = b : "Translation Z" == b.name ? this.TZ = b : "Rotation X" == b.name ? this.RX = b : "Rotation Y" == b.name ? this.RY = b : "Rotation Z" == b.name ? this.RZ = b : "Scale X" == b.name ? this.SX = b : "Scale Y" == b.name ? this.SY = b : "Scale Z" == b.name && (this.SZ = b)
  398. }
  399. this.hasTranslation = this.TX && this.TY && this.TZ;
  400. this.hasRotation = this.RX && this.RY && this.RZ;
  401. this.hasScale = this.SX && this.SY && this.SZ;
  402. this.lockTransform = !1
  403. }
  404. AnimatedTransform.prototype.getTRSValue = function(a, c, b) {
  405. if (!c)
  406. return b;
  407. c.evaluate(a, b, this.hostObject);
  408. "" != c.debugString && (this.debugString += c.debugString);
  409. return c.lastValue
  410. }
  411. ;
  412. AnimatedTransform.prototype.evaluateMatrix = function(a, c, b, d) {
  413. if (this.lockTransform)
  414. Matrix.copy(a, this.cachedmatrix0);
  415. else {
  416. var e = 0
  417. , f = c = 0
  418. , e = f = c = 0
  419. , e = f = c = 1;
  420. this.hasRotation ? (e = this.getTRSValue(b, this.RX, 0),
  421. c = this.getTRSValue(b, this.RY, 0),
  422. f = this.getTRSValue(b, this.RZ, 0),
  423. d ? (this.matrix = Matrix.rotation(Matrix.empty(), f, 2),
  424. d = Matrix.rotation(Matrix.empty(), e, 0),
  425. Matrix.mul(d, d, this.matrix),
  426. this.matrix = Matrix.rotation(Matrix.empty(), c, 1)) : (this.matrix = Matrix.rotation(Matrix.empty(), e, 0),
  427. d = Matrix.rotation(Matrix.empty(), c, 1),
  428. Matrix.mul(d, d, this.matrix),
  429. this.matrix = Matrix.rotation(Matrix.empty(), f, 2)),
  430. Matrix.mul(this.matrix, this.matrix, d)) : Matrix.copy(this.matrix, Matrix.identity());
  431. this.hasTranslation && (c = this.getTRSValue(b, this.TX, 0),
  432. f = this.getTRSValue(b, this.TY, 0),
  433. e = this.getTRSValue(b, this.TZ, 0),
  434. this.matrix[12] = c,
  435. this.matrix[13] = f,
  436. this.matrix[14] = e);
  437. this.hasScale && (c = this.getTRSValue(b, this.SX, 1),
  438. f = this.getTRSValue(b, this.SY, 1),
  439. e = this.getTRSValue(b, this.SZ, 1),
  440. this.matrix[0] *= c,
  441. this.matrix[4] *= f,
  442. this.matrix[8] *= e,
  443. this.matrix[1] *= c,
  444. this.matrix[5] *= f,
  445. this.matrix[9] *= e,
  446. this.matrix[2] *= c,
  447. this.matrix[6] *= f,
  448. this.matrix[10] *= e,
  449. this.matrix[3] *= c,
  450. this.matrix[7] *= f,
  451. this.matrix[11] *= e);
  452. Matrix.copy(a, this.matrix)
  453. }
  454. }
  455. ;
  456. AnimatedTransform.prototype.clearCachedTransforms = function() {
  457. this.cachedFrame3 = this.cachedFrame2 = this.cachedFrame1 = this.cachedFrame0 = -1;
  458. this.cachedFrameUse3 = this.cachedFrameUse2 = this.cachedFrameUse1 = this.cachedFrameUse0 = 0;
  459. this.TX && (this.TX.lastFramePercent = -10);
  460. this.TY && (this.TY.lastFramePercent = -10);
  461. this.TZ && (this.TZ.lastFramePercent = -10);
  462. this.RX && (this.RX.lastFramePercent = -10);
  463. this.RY && (this.RY.lastFramePercent = -10);
  464. this.RZ && (this.RZ.lastFramePercent = -10);
  465. this.SX && (this.SX.lastFramePercent = -10);
  466. this.SY && (this.SY.lastFramePercent = -10);
  467. this.SZ && (this.SZ.lastFramePercent = -10);
  468. this.lockTransform = !1
  469. }
  470. ;
  471. AnimatedTransform.prototype.getCachedTransform = function(a) {
  472. return this.lockTransform ? 0 : this.cachedFrame0 == a ? this.cachedmatrix0 : this.cachedFrame1 == a ? this.cachedmatrix1 : this.cachedFrame2 == a ? this.cachedmatrix2 : this.cachedFrame3 == a ? this.cachedmatrix3 : 0
  473. }
  474. ;
  475. AnimatedTransform.prototype.getFreeCachedTransform = function(a) {
  476. if (this.lockTransform)
  477. return 0;
  478. this.cachedFrameUse0--;
  479. this.cachedFrameUse1--;
  480. this.cachedFrameUse2--;
  481. this.cachedFrameUse3--;
  482. if (this.cachedFrameUse0 <= this.cachedFrameUse1 && this.cachedFrameUse0 <= this.cachedFrameUse2 && this.cachedFrameUse0 <= this.cachedFrameUse3 || this.cachedFrame0 == a)
  483. return this.cachedFrame0 = a,
  484. this.cachedFrameUse0 = 0,
  485. this.cachedmatrix0;
  486. if (this.cachedFrameUse1 <= this.cachedFrameUse0 && this.cachedFrameUse1 <= this.cachedFrameUse2 && this.cachedFrameUse1 <= this.cachedFrameUse3 || this.cachedFrame1 == a)
  487. return this.cachedFrame1 = a,
  488. this.cachedFrameUse1 = 0,
  489. this.cachedmatrix1;
  490. if (this.cachedFrameUse2 <= this.cachedFrameUse0 && this.cachedFrameUse2 <= this.cachedFrameUse1 && this.cachedFrameUse2 <= this.cachedFrameUse3 || this.cachedFrame2 == a)
  491. return this.cachedFrame2 = a,
  492. this.cachedFrameUse2 = 0,
  493. this.cachedmatrix2;
  494. this.cachedFrame3 = a;
  495. this.cachedFrameUse3 = 0;
  496. return this.cachedmatrix3
  497. }
  498. ;
  499. function Animation(a, c) {
  500. this.originalFPS = 1;
  501. this.name = c.name;
  502. this.totalSeconds = c.length;
  503. this.originalFPS = c.originalFPS;
  504. this.totalFrames = c.totalFrames;
  505. this.expectedNumAnimatedObjects = c.numAnimatedObjects;
  506. this.animatedObjects = [];
  507. this.sceneTransform = Matrix.identity();
  508. this.debugString = "";
  509. if (c.animatedObjects)
  510. for (var b = c.animatedObjects.length, d = 0; d < b; ++d) {
  511. var e = new AnimatedObject(a,c.animatedObjects[d],d);
  512. this.animatedObjects.push(e);
  513. this.debugString += e.debugString
  514. }
  515. this.meshObjects = [];
  516. this.lightObjects = [];
  517. this.materialObjects = [];
  518. this.turnTableObjects = [];
  519. this.cameraObjects = []
  520. }
  521. Animation.prototype.evaluateModelPartTransformAtFrame = function(a, c, b, d) {
  522. Matrix.copy(b, Matrix.identity());
  523. for (var e = 0; 100 > e; e++) {
  524. var f = this.animatedObjects[a];
  525. if (a == f.parentIndex)
  526. break;
  527. if (f.useFixedWorldTransform) {
  528. Matrix.mul(b, f.cachedWorldTransform0, b);
  529. break
  530. } else {
  531. var g = 0;
  532. d && (g = f.getCachedWorldTransform(c));
  533. if (g) {
  534. Matrix.mul(b, g, b);
  535. break
  536. } else
  537. g = Matrix.identity(),
  538. f.evaluateLocalTransformAtFramePercent(c, g, !1, d),
  539. Matrix.mul(b, g, b),
  540. a == f.parentIndex && (e = 100),
  541. a = f.parentIndex
  542. }
  543. }
  544. }
  545. ;
  546. Animation.prototype.lerpModelPartTransform = function(a, c, b, d) {
  547. var e = this.animatedObjects[a];
  548. if (e.useFixedWorldTransform)
  549. Matrix.copy(b, e.cachedWorldTransform0);
  550. else {
  551. var f = c * e.modelPartFPS
  552. , f = f - Math.floor(f)
  553. , g = Math.floor(this.getObjectAnimationFramePercent(e, c))
  554. , h = g + 1
  555. , k = c = 0;
  556. d && (c = e.getCachedWorldTransform(g),
  557. k = e.getCachedWorldTransform(h));
  558. c || ((c = e.getFreeCachedWorldTransform(g)) || (c = Matrix.identity()),
  559. this.evaluateModelPartTransformAtFrame(a, g, c, d));
  560. k || ((k = e.getFreeCachedWorldTransform(h)) || (k = Matrix.identity()),
  561. this.evaluateModelPartTransformAtFrame(a, h, k, d));
  562. a = 1 - f;
  563. for (d = 0; 16 > d; d++)
  564. b[d] = c[d] * a + k[d] * f
  565. }
  566. }
  567. ;
  568. Animation.prototype.getModelPartTransform = function(a, c, b, d) {
  569. this.lerpModelPartTransform(a, c, b, d)
  570. }
  571. ;
  572. Animation.prototype.getAnimatedLocalTransform = function(a, c, b, d) {
  573. a = this.animatedObjects[a];
  574. var e = this.animatedObjects[a.parentIndex]
  575. , f = e.modelPartIndex != e.id
  576. , g = Matrix.identity();
  577. this.getModelPartTransform(a.modelPartIndex, c, g, d);
  578. if (f) {
  579. var f = Matrix.identity()
  580. , h = Matrix.identity();
  581. this.getModelPartTransform(e.modelPartIndex, c, f, d);
  582. Matrix.invert(h, f);
  583. Matrix.mul(b, h, g);
  584. b[12] *= a.modelPartScale;
  585. b[13] *= a.modelPartScale;
  586. b[14] *= a.modelPartScale
  587. } else
  588. Matrix.copy(b, g)
  589. }
  590. ;
  591. Animation.prototype.isVisibleAtFramePercent = function(a, c) {
  592. for (var b = a, d = 0, e = 0; 100 > e; e++) {
  593. d = this.animatedObjects[b];
  594. if (d.visibleProperty) {
  595. d.visibleProperty.evaluate(c, 1, d);
  596. if ("" != d.debugString || "" != d.visibleProperty.debugString)
  597. return this.debugString += d.debugString,
  598. this.debugString += d.visibleProperty.debugString,
  599. !1;
  600. if (0 == d.visibleProperty.lastValue)
  601. return !1
  602. }
  603. b == d.parentIndex && (e = 100);
  604. b = d.parentIndex
  605. }
  606. return !0
  607. }
  608. ;
  609. Animation.prototype.getWorldTransform = function(a, c, b, d, e) {
  610. a = this.animatedObjects[a];
  611. if (a.useFixedWorldTransform)
  612. Matrix.copy(b, a.cachedWorldTransform0);
  613. else {
  614. var f = this.getObjectAnimationFramePercent(a, c)
  615. , g = Matrix.identity();
  616. a.evaluateLocalTransformAtFramePercent(f, g, !0, e);
  617. if (f = a.modelPartIndex != a.id) {
  618. var f = Matrix.identity()
  619. , h = Matrix.identity();
  620. Matrix.copy(h, g);
  621. this.getAnimatedLocalTransform(a.id, c, f);
  622. Matrix.mul(g, f, h)
  623. }
  624. Matrix.copy(b, g);
  625. if (a.parentIndex != a.id)
  626. for (var k = a.parentIndex, n = 0; 100 > n; n++)
  627. a = this.animatedObjects[k],
  628. f = this.getObjectAnimationFramePercent(a, c),
  629. g = Matrix.identity(),
  630. a.evaluateLocalTransformAtFramePercent(f, g, !0, e),
  631. (f = a.modelPartIndex != a.id) ? (f = Matrix.identity(),
  632. this.getAnimatedLocalTransform(a.id, c, f),
  633. h = Matrix.identity(),
  634. Matrix.mul(h, g, b),
  635. Matrix.mul(b, f, h)) : (h = Matrix.identity(),
  636. Matrix.copy(h, b),
  637. Matrix.mul(b, g, h)),
  638. k == a.parentIndex && (n = 100),
  639. k = a.parentIndex;
  640. b[12] *= d;
  641. b[13] *= d;
  642. b[14] *= d
  643. }
  644. }
  645. ;
  646. Animation.prototype.hasParentInHierarchy = function(a, c) {
  647. for (var b = a.parentIndex, d = 0; 100 > d; d++) {
  648. a = this.animatedObjects[b];
  649. if (a.id == c)
  650. return !0;
  651. b == a.parentIndex && (d = 100);
  652. b = a.parentIndex
  653. }
  654. return !1
  655. }
  656. ;
  657. Animation.prototype.hasParentTypeInHierarchy = function(a, c) {
  658. for (var b = a.parentIndex, d = 0; 100 > d; d++) {
  659. a = this.animatedObjects[b];
  660. if (a.sceneObjectType == c)
  661. return !0;
  662. b == a.parentIndex && (d = 100);
  663. b = a.parentIndex
  664. }
  665. return !1
  666. }
  667. ;
  668. Animation.prototype.searchAnimationUpHierarchy = function(a) {
  669. for (var c = a.id, b = 0; 100 > b; b++) {
  670. a = this.animatedObjects[c];
  671. if (a.animatedLocalTransform && (a.hasAnimatedTransform() || a.id != a.modelPartIndex && this.searchAnimationUpHierarchy(this.animatedObjects[a.modelPartIndex])))
  672. return !0;
  673. c == a.parentIndex && (b = 100);
  674. c = a.parentIndex
  675. }
  676. return !1
  677. }
  678. ;
  679. Animation.prototype.hasAnimationInHierarchy = function(a) {
  680. return this.searchAnimationUpHierarchy(a) || a.id != a.modelPartIndex && this.searchAnimationUpHierarchy(this.animatedObjects[a.modelPartIndex]) || this.hasParentTypeInHierarchy(a, "TurnTableSO") || this.hasParentTypeInHierarchy(a, "CameraSO") || "CameraSO" == a.sceneObjectType ? !0 : !1
  681. }
  682. ;
  683. Animation.prototype.getObjectAnimationFramePercent = function(a, c) {
  684. if (0 == this.totalFrames || 0 == a.animationLength)
  685. return 0;
  686. if (a.endTime == this.totalSeconds)
  687. return c * a.modelPartFPS;
  688. var b = c / a.animationLength
  689. , b = Math.floor(b);
  690. c -= a.animationLength * b;
  691. b = c * a.modelPartFPS;
  692. b >= a.totalFrames + 1 && (b = a.totalFrames);
  693. return b
  694. }
  695. ;
  696. //资源解压
  697. function Archive(a) {
  698. this.files = [];
  699. for (a = new ByteStream(a); !a.empty(); ) {
  700. var c = {};
  701. c.name = a.readCString();
  702. c.type = a.readCString();
  703. var b = a.readUint32() //Flag
  704. , d = a.readUint32() //Index
  705. , e = a.readUint32(); //Size
  706. c.data = a.readBytes(d);
  707. if (!(c.data.length < d)) {
  708. if (b & 1 && (c.data = this.decompress(c.data, e),
  709. null === c.data))
  710. continue;
  711. this.files[c.name] = c
  712. }
  713. }
  714. console.log(this.files)
  715. }
  716. Archive.prototype.get = function(a) {
  717. return this.files[a]
  718. }
  719. ;
  720. Archive.prototype.extract = function(a) {
  721. var c = this.files[a];
  722. delete this.files[a];
  723. return c
  724. }
  725. ;
  726. Archive.prototype.checkSignature = function(a) {
  727. if (!a)
  728. return !1;
  729. var c = this.get(a.name + ".sig");
  730. if (!c)
  731. return !1;
  732. c = JSON.parse(String.fromCharCode.apply(null, c.data));
  733. if (!c)
  734. return !1;
  735. for (var b = 5381, d = 0; d < a.data.length; ++d)
  736. b = 33 * b + a.data[d] & 4294967295;
  737. a = new BigInt;
  738. a.setBytes([0, 233, 33, 170, 116, 86, 29, 195, 228, 46, 189, 3, 185, 31, 245, 19, 159, 105, 73, 190, 158, 80, 175, 38, 210, 116, 221, 229, 171, 134, 104, 144, 140, 5, 99, 255, 208, 78, 248, 215, 172, 44, 79, 83, 5, 244, 152, 19, 92, 137, 112, 10, 101, 142, 209, 100, 244, 92, 190, 125, 28, 0, 185, 54, 143, 247, 49, 37, 15, 254, 142, 180, 185, 232, 50, 219, 11, 186, 106, 116, 78, 212, 10, 105, 53, 26, 14, 181, 80, 47, 87, 213, 182, 19, 126, 151, 86, 109, 182, 224, 37, 135, 80, 59, 22, 93, 125, 68, 214, 106, 209, 152, 235, 157, 249, 245, 48, 76, 203, 0, 0, 95, 200, 246, 243, 229, 85, 79, 169], !0);
  739. d = new BigInt;
  740. d.setBytes(c[0]);
  741. return d.powmod(65537, a).toInt32() != b ? !1 : !0
  742. }
  743. ;
  744. Archive.prototype.decompress = function(a, c) {
  745. var b = new Uint8Array(c)
  746. , d = 0
  747. , e = new Uint32Array(4096)
  748. , f = new Uint32Array(4096)
  749. , g = 256
  750. , h = a.length
  751. , k = 0
  752. , n = 1
  753. , m = 0
  754. , l = 1;
  755. b[d++] = a[0];
  756. for (var p = 1; ; p++) {
  757. l = p + (p >> 1);
  758. if (l + 1 >= h)
  759. break;
  760. var m = a[l + 1]
  761. , l = a[l]
  762. , r = p & 1 ? m << 4 | l >> 4 : (m & 15) << 8 | l;
  763. if (r < g)
  764. if (256 > r)
  765. m = d,
  766. l = 1,
  767. b[d++] = r;
  768. else
  769. for (var m = d, l = f[r], r = e[r], s = r + l; r < s; )
  770. b[d++] = b[r++];
  771. else if (r == g) {
  772. m = d;
  773. l = n + 1;
  774. r = k;
  775. for (s = k + n; r < s; )
  776. b[d++] = b[r++];
  777. b[d++] = b[k]
  778. } else
  779. break;
  780. e[g] = k;
  781. f[g++] = n + 1;
  782. k = m;
  783. n = l;
  784. g = 4096 <= g ? 256 : g
  785. }
  786. return d == c ? b : null
  787. }
  788. ;
  789. function BigInt(a) {
  790. this.digits = new Uint16Array(a || 0)
  791. }
  792. BigInt.prototype.setBytes = function(a, c) {
  793. var b = (a.length + 1) / 2 | 0;
  794. this.digits = new Uint16Array(b);
  795. if (c)
  796. for (var d = 0, b = a.length - 1; 0 <= b; b -= 2)
  797. this.digits[d++] = a[b] + (0 < b ? 256 * a[b - 1] : 0);
  798. else
  799. for (d = 0; d < b; ++d)
  800. this.digits[d] = a[2 * d] + 256 * a[2 * d + 1];
  801. this.trim()
  802. }
  803. ;
  804. BigInt.prototype.toInt32 = function() {
  805. var a = 0;
  806. 0 < this.digits.length && (a = this.digits[0],
  807. 1 < this.digits.length && (a |= this.digits[1] << 16));
  808. return a
  809. }
  810. ;
  811. BigInt.prototype.lessThan = function(a) {
  812. if (this.digits.length == a.digits.length)
  813. for (var c = this.digits.length - 1; 0 <= c; --c) {
  814. var b = this.digits[c]
  815. , d = a.digits[c];
  816. if (b != d)
  817. return b < d
  818. }
  819. return this.digits.length < a.digits.length
  820. }
  821. ;
  822. BigInt.prototype.shiftRight = function() {
  823. for (var a = 0, c = this.digits, b = c.length - 1; 0 <= b; --b) {
  824. var d = c[b];
  825. c[b] = d >> 1 | a << 15;
  826. a = d
  827. }
  828. this.trim()
  829. }
  830. ;
  831. BigInt.prototype.shiftLeft = function(a) {
  832. if (0 < a) {
  833. var c = a / 16 | 0;
  834. a %= 16;
  835. for (var b = 16 - a, d = this.digits.length + c + 1, e = new BigInt(d), f = 0; f < d; ++f)
  836. e.digits[f] = ((f < c || f >= this.digits.length + c ? 0 : this.digits[f - c]) << a | (f < c + 1 ? 0 : this.digits[f - c - 1]) >>> b) & 65535;
  837. e.trim();
  838. return e
  839. }
  840. return new BigInt(this)
  841. }
  842. ;
  843. BigInt.prototype.bitCount = function() {
  844. var a = 0;
  845. if (0 < this.digits.length)
  846. for (var a = 16 * (this.digits.length - 1), c = this.digits[this.digits.length - 1]; c; )
  847. c >>>= 1,
  848. ++a;
  849. return a
  850. }
  851. ;
  852. BigInt.prototype.sub = function(a) {
  853. var c = this.digits
  854. , b = a.digits
  855. , d = this.digits.length;
  856. a = a.digits.length;
  857. for (var e = 0, f = 0; f < d; ++f) {
  858. var g = c[f]
  859. , h = f < a ? b[f] : 0
  860. , h = h + e
  861. , e = h > g ? 1 : 0
  862. , g = g + (e << 16);
  863. c[f] = g - h & 65535
  864. }
  865. this.trim()
  866. }
  867. ;
  868. BigInt.prototype.mul = function(a) {
  869. for (var c = new BigInt(this.digits.length + a.digits.length), b = c.digits, d = 0; d < this.digits.length; ++d)
  870. for (var e = this.digits[d], f = 0; f < a.digits.length; ++f)
  871. for (var g = e * a.digits[f], h = d + f; g; ) {
  872. var k = (g & 65535) + b[h];
  873. b[h] = k & 65535;
  874. g >>>= 16;
  875. g += k >>> 16;
  876. ++h
  877. }
  878. c.trim();
  879. return c
  880. }
  881. ;
  882. BigInt.prototype.mod = function(a) {
  883. if (0 >= this.digits.length || 0 >= a.digits.length)
  884. return new BigInt(0);
  885. var c = new BigInt(this.digits);
  886. if (!this.lessThan(a)) {
  887. for (var b = new BigInt(a.digits), b = b.shiftLeft(c.bitCount() - b.bitCount()); !c.lessThan(a); )
  888. b.lessThan(c) && c.sub(b),
  889. b.shiftRight();
  890. c.trim()
  891. }
  892. return c
  893. }
  894. ;
  895. BigInt.prototype.powmod = function(a, c) {
  896. for (var b = new BigInt([1]), d = this.mod(c); a; )
  897. a & 1 && (b = b.mul(d).mod(c)),
  898. a >>>= 1,
  899. d = d.mul(d).mod(c);
  900. return b
  901. }
  902. ;
  903. BigInt.prototype.trim = function() {
  904. for (var a = this.digits.length; 0 < a && 0 == this.digits[a - 1]; )
  905. --a;
  906. a != this.digits.length && (this.digits = this.digits.subarray(0, a))
  907. }
  908. ;
  909. function Bounds(a) {
  910. for (var c = 0; c < a.length; ++c) {
  911. var b = a[c].bounds;
  912. if (void 0 === this.min)
  913. this.min = [b.min[0], b.min[1], b.min[2]],
  914. this.max = [b.max[0], b.max[1], b.max[2]];
  915. else
  916. for (var d = 0; 3 > d; ++d)
  917. this.min[d] = Math.min(b.min[d], this.min[d]),
  918. this.max[d] = Math.max(b.max[d], this.max[d])
  919. }
  920. this.min = this.min ? this.min : [0, 0, 0];
  921. this.max = this.max ? this.max : [0, 0, 0];
  922. this.center = [0.5 * (this.min[0] + this.max[0]), 0.5 * (this.min[1] + this.max[1]), 0.5 * (this.min[2] + this.max[2])];
  923. this.radius = [this.max[0] - this.center[0], this.max[1] - this.center[1], this.max[2] - this.center[2]];
  924. this.radiusDiagonal = Math.sqrt(this.radius[0] * this.radius[0] + this.radius[1] * this.radius[1] + this.radius[2] * this.radius[2])
  925. }
  926. ;function Button(a) {
  927. this.name = "none";
  928. this.text = "default text";
  929. this.title = "none";
  930. this.debugString = this.imagePath = "";
  931. this.controlRect = new ControlRect(a);
  932. this.defaultAlpha = 0.5;
  933. this.focusAlpha = 1;
  934. this.updateAlphas = !0;
  935. this.linkedBackground = this.backgroundOffsetY = this.backgroundOffsetX = this.edgePixelsY = this.edgePixelsX = this.backgroundBottomMiddle = this.backgroundBottomRight = this.backgroundBottomLeft = this.backgroundMiddleMiddle = this.backgroundMiddleRight = this.backgroundMiddleLeft = this.backgroundTopMiddle = this.backgroundTopRight = this.backgroundTopLeft = this.backgroundMiddle = this.backgroundRight = this.backgroundLeft = 0
  936. }
  937. Button.prototype.setBackground3x1 = function(a, c, b, d, e, f, g) {
  938. this.backgroundOffsetX = c;
  939. this.backgroundOffsetY = b;
  940. this.edgePixelsX = g;
  941. this.backgroundLeft = a.addImage(d);
  942. this.backgroundMiddle = a.addImage(e);
  943. this.backgroundRight = a.addImage(f);
  944. this.backgroundLeft.linkedControl.style.zIndex = "0";
  945. this.backgroundMiddle.linkedControl.style.zIndex = "0";
  946. this.backgroundRight.linkedControl.style.zIndex = "0";
  947. this.setOpacity(this.defaultAlpha)
  948. }
  949. ;
  950. Button.prototype.setBackground3x3 = function(a, c, b, d, e, f, g, h, k, n, m, l, p, r) {
  951. this.backgroundOffsetX = c;
  952. this.backgroundOffsetY = b;
  953. this.edgePixelsX = p;
  954. this.edgePixelsY = r;
  955. this.backgroundTopLeft = a.addImage(d);
  956. this.backgroundMiddleLeft = a.addImage(g);
  957. this.backgroundBottomLeft = a.addImage(n);
  958. this.backgroundTopMiddle = a.addImage(e);
  959. this.backgroundMiddleMiddle = a.addImage(h);
  960. this.backgroundBottomMiddle = a.addImage(m);
  961. this.backgroundTopRight = a.addImage(f);
  962. this.backgroundMiddleRight = a.addImage(k);
  963. this.backgroundBottomRight = a.addImage(l);
  964. this.backgroundTopLeft.linkedControl.style.zIndex = "0";
  965. this.backgroundTopRight.linkedControl.style.zIndex = "0";
  966. this.backgroundTopMiddle.linkedControl.style.zIndex = "0";
  967. this.backgroundMiddleLeft.linkedControl.style.zIndex = "0";
  968. this.backgroundMiddleRight.linkedControl.style.zIndex = "0";
  969. this.backgroundMiddleMiddle.linkedControl.style.zIndex = "0";
  970. this.backgroundBottomLeft.linkedControl.style.zIndex = "0";
  971. this.backgroundBottomRight.linkedControl.style.zIndex = "0";
  972. this.backgroundBottomMiddle.linkedControl.style.zIndex = "0";
  973. this.setOpacity(this.defaultAlpha)
  974. }
  975. ;
  976. Button.prototype.alignBackground = function() {
  977. var a = this.controlRect
  978. , c = a.guiScreen
  979. , b = c.left * (1 - a.getScreenXPercent())
  980. , d = c.bottom * (1 - a.getScreenYPercent())
  981. , e = c.width * a.getScreenWidthPercent()
  982. , a = c.height * a.getScreenHeightPercent()
  983. , d = d + this.backgroundOffsetY
  984. , b = b + this.backgroundOffsetX;
  985. if (this.backgroundTopLeft && this.backgroundTopRight && this.backgroundTopMiddle && this.backgroundMiddleLeft && this.backgroundMiddleRight && this.backgroundMiddleMiddle && this.backgroundBottomLeft && this.backgroundBottomRight && this.backgroundBottomMiddle) {
  986. var c = e - 2 * this.edgePixelsX
  987. , f = a - 2 * this.edgePixelsY;
  988. this.backgroundTopLeft.linkedControl.style.height = this.edgePixelsY + "px";
  989. this.backgroundTopMiddle.linkedControl.style.height = this.edgePixelsY + "px";
  990. this.backgroundTopRight.linkedControl.style.height = this.edgePixelsY + "px";
  991. this.backgroundBottomLeft.linkedControl.style.height = this.edgePixelsY + "px";
  992. this.backgroundBottomMiddle.linkedControl.style.height = this.edgePixelsY + "px";
  993. this.backgroundBottomRight.linkedControl.style.height = this.edgePixelsY + "px";
  994. this.backgroundMiddleLeft.linkedControl.style.height = f + "px";
  995. this.backgroundMiddleMiddle.linkedControl.style.height = f + "px";
  996. this.backgroundMiddleRight.linkedControl.style.height = f + "px";
  997. this.backgroundTopLeft.linkedControl.style.width = this.edgePixelsX + "px";
  998. this.backgroundBottomLeft.linkedControl.style.width = this.edgePixelsX + "px";
  999. this.backgroundMiddleLeft.linkedControl.style.width = this.edgePixelsX + "px";
  1000. this.backgroundTopRight.linkedControl.style.width = this.edgePixelsX + "px";
  1001. this.backgroundBottomRight.linkedControl.style.width = this.edgePixelsX + "px";
  1002. this.backgroundMiddleRight.linkedControl.style.width = this.edgePixelsX + "px";
  1003. this.backgroundTopMiddle.linkedControl.style.width = c + "px";
  1004. this.backgroundBottomMiddle.linkedControl.style.width = c + "px";
  1005. this.backgroundMiddleMiddle.linkedControl.style.width = c + "px";
  1006. this.backgroundTopLeft.linkedControl.style.left = b + "px";
  1007. this.backgroundBottomLeft.linkedControl.style.left = b + "px";
  1008. this.backgroundMiddleLeft.linkedControl.style.left = b + "px";
  1009. b += this.edgePixelsX;
  1010. this.backgroundTopMiddle.linkedControl.style.left = b + "px";
  1011. this.backgroundBottomMiddle.linkedControl.style.left = b + "px";
  1012. this.backgroundMiddleMiddle.linkedControl.style.left = b + "px";
  1013. b += c;
  1014. this.backgroundTopRight.linkedControl.style.left = b + "px";
  1015. this.backgroundBottomRight.linkedControl.style.left = b + "px";
  1016. this.backgroundMiddleRight.linkedControl.style.left = b + "px";
  1017. this.backgroundBottomLeft.linkedControl.style.bottom = d + "px";
  1018. this.backgroundBottomMiddle.linkedControl.style.bottom = d + "px";
  1019. this.backgroundBottomRight.linkedControl.style.bottom = d + "px";
  1020. d += this.edgePixelsY;
  1021. this.backgroundMiddleLeft.linkedControl.style.bottom = d + "px";
  1022. this.backgroundMiddleRight.linkedControl.style.bottom = d + "px";
  1023. this.backgroundMiddleMiddle.linkedControl.style.bottom = d + "px";
  1024. d += f;
  1025. this.backgroundTopLeft.linkedControl.style.bottom = d + "px";
  1026. this.backgroundTopMiddle.linkedControl.style.bottom = d + "px";
  1027. this.backgroundTopRight.linkedControl.style.bottom = d + "px"
  1028. }
  1029. this.backgroundLeft && this.backgroundRight && this.backgroundMiddle && (e -= 2 * this.edgePixelsX,
  1030. this.backgroundLeft.linkedControl.style.bottom = d + "px",
  1031. this.backgroundMiddle.linkedControl.style.bottom = d + "px",
  1032. this.backgroundRight.linkedControl.style.bottom = d + "px",
  1033. this.backgroundLeft.linkedControl.style.height = a + "px",
  1034. this.backgroundMiddle.linkedControl.style.height = a + "px",
  1035. this.backgroundRight.linkedControl.style.height = a + "px",
  1036. this.backgroundLeft.linkedControl.style.width = this.edgePixelsX + "px",
  1037. this.backgroundMiddle.linkedControl.style.width = e + "px",
  1038. this.backgroundRight.linkedControl.style.width = this.edgePixelsX + "px",
  1039. this.backgroundLeft.linkedControl.style.left = b + "px",
  1040. b += this.edgePixelsX,
  1041. this.backgroundMiddle.linkedControl.style.left = b + "px",
  1042. this.backgroundRight.linkedControl.style.left = b + e + "px")
  1043. }
  1044. ;
  1045. Button.prototype.setOpacity = function(a) {
  1046. this.controlRect.linkedControl.style.opacity = a;
  1047. this.backgroundLeft && (this.backgroundLeft.linkedControl.style.opacity = a);
  1048. this.backgroundRight && (this.backgroundRight.linkedControl.style.opacity = a);
  1049. this.backgroundMiddle && (this.backgroundMiddle.linkedControl.style.opacity = a);
  1050. this.backgroundTopLeft && (this.backgroundTopLeft.linkedControl.style.opacity = a);
  1051. this.backgroundTopRight && (this.backgroundTopRight.linkedControl.style.opacity = a);
  1052. this.backgroundTopMiddle && (this.backgroundTopMiddle.linkedControl.style.opacity = a);
  1053. this.backgroundMiddleLeft && (this.backgroundMiddleLeft.linkedControl.style.opacity = a);
  1054. this.backgroundMiddleRight && (this.backgroundMiddleRight.linkedControl.style.opacity = a);
  1055. this.backgroundMiddleMiddle && (this.backgroundMiddleMiddle.linkedControl.style.opacity = a);
  1056. this.backgroundBottomLeft && (this.backgroundBottomLeft.linkedControl.style.opacity = a);
  1057. this.backgroundBottomRight && (this.backgroundBottomRight.linkedControl.style.opacity = a);
  1058. this.backgroundBottomMiddle && (this.backgroundBottomMiddle.linkedControl.style.opacity = a)
  1059. }
  1060. ;
  1061. Button.prototype.setBackgroundVisible = function(a) {
  1062. this.backgroundLeft && this.backgroundLeft.showControl(a);
  1063. this.backgroundRight && this.backgroundRight.showControl(a);
  1064. this.backgroundMiddle && this.backgroundMiddle.showControl(a);
  1065. this.backgroundTopLeft && this.backgroundTopLeft.showControl(a);
  1066. this.backgroundTopRight && this.backgroundTopRight.showControl(a);
  1067. this.backgroundTopMiddle && this.backgroundTopMiddle.showControl(a);
  1068. this.backgroundMiddleLeft && this.backgroundMiddleLeft.showControl(a);
  1069. this.backgroundMiddleRight && this.backgroundMiddleRight.showControl(a);
  1070. this.backgroundMiddleMiddle && this.backgroundMiddleMiddle.showControl(a);
  1071. this.backgroundBottomLeft && this.backgroundBottomLeft.showControl(a);
  1072. this.backgroundBottomRight && this.backgroundBottomRight.showControl(a);
  1073. this.backgroundBottomMiddle && this.backgroundBottomMiddle.showControl(a)
  1074. }
  1075. ;
  1076. Button.prototype.setVisible = function(a) {
  1077. this.controlRect.showControl(a);
  1078. this.setBackgroundVisible(a)
  1079. }
  1080. ;
  1081. Button.prototype.linkControl = function(a) {
  1082. this.controlRect.linkedControl = a;
  1083. a.onmouseover = function() {
  1084. this.updateAlphas && (this.setOpacity(this.focusAlpha),
  1085. this.controlRect.mouseOver = !0,
  1086. this.linkedBackground && this.linkedBackground.setOpacity(this.focusAlpha))
  1087. }
  1088. .bind(this);
  1089. a.onmouseout = function() {
  1090. this.updateAlphas && (this.setOpacity(this.defaultAlpha),
  1091. this.controlRect.mouseOver = !1,
  1092. this.linkedBackground && this.linkedBackground.setOpacity(this.defaultAlpha))
  1093. }
  1094. .bind(this)
  1095. }
  1096. ;
  1097. function ByteStream(a) {
  1098. this.bytes = new Uint8Array(a)
  1099. }
  1100. ByteStream.prototype.empty = function() {
  1101. return 0 >= this.bytes.length
  1102. }
  1103. ;
  1104. ByteStream.prototype.readCString = function() {
  1105. for (var a = this.bytes, c = a.length, b = 0; b < c; ++b)
  1106. if (0 == a[b])
  1107. return a = String.fromCharCode.apply(null, this.bytes.subarray(0, b)),
  1108. this.bytes = this.bytes.subarray(b + 1),
  1109. a;
  1110. return null
  1111. }
  1112. ;
  1113. ByteStream.prototype.asString = function() {
  1114. for (var a = "", c = 0; c < this.bytes.length; ++c)
  1115. a += String.fromCharCode(this.bytes[c]);
  1116. return a
  1117. }
  1118. ;
  1119. ByteStream.prototype.readBytes = function(a) {
  1120. var c = this.bytes.subarray(0, a);
  1121. this.bytes = this.bytes.subarray(a);
  1122. return c
  1123. }
  1124. ;
  1125. ByteStream.prototype.readUint32 = function() {
  1126. var a = this.bytes
  1127. , c = a[0] | a[1] << 8 | a[2] << 16 | a[3] << 24;
  1128. this.bytes = a.subarray(4);
  1129. return c
  1130. }
  1131. ;
  1132. ByteStream.prototype.readUint8 = function() {
  1133. var a = this.bytes
  1134. , c = a[0];
  1135. this.bytes = a.subarray(1);
  1136. return c
  1137. }
  1138. ;
  1139. ByteStream.prototype.readUint16 = function() {
  1140. var a = this.bytes
  1141. , c = a[0] | a[1] << 8;
  1142. this.bytes = a.subarray(2);
  1143. return c
  1144. }
  1145. ;
  1146. ByteStream.prototype.readFloat32 = function() {
  1147. var a = new Uint8Array(this.bytes)
  1148. , a = new Float32Array(a.buffer);
  1149. this.bytes = this.bytes.subarray(4);
  1150. return a[0]
  1151. }
  1152. ;
  1153. ByteStream.prototype.seekUint32 = function(a) {
  1154. a = this.bytes.subarray(4 * a);
  1155. return a[0] | a[1] << 8 | a[2] << 16 | a[3] << 24
  1156. }
  1157. ;
  1158. ByteStream.prototype.seekFloat32 = function(a) {
  1159. a = new Uint8Array(this.bytes.subarray(4 * a));
  1160. return (new Float32Array(a.buffer))[0]
  1161. }
  1162. ;
  1163. ByteStream.prototype.getMatrix = function(a) {
  1164. return new Float32Array(this.bytes.buffer,64 * a,16)
  1165. }
  1166. ;
  1167. function ControlRect(a) {
  1168. this.name = "none";
  1169. this.title = "frame";
  1170. this.yPercent = this.xPercent = 0;
  1171. this.heightPercent = this.widthPercent = 1;
  1172. this.debugString = "";
  1173. this.parentControlRect = 0;
  1174. this.childControlRects = [];
  1175. this.clicked = this.mouseDown = this.mouseOver = !1;
  1176. this.localMouseYPercent = this.localMouseXPercent = 0;
  1177. this.enabled = this.visible = !0;
  1178. this.opacity = 1;
  1179. this.guiScreen = a;
  1180. this.id = this.callBack = this.linkedControl = 0
  1181. }
  1182. ControlRect.prototype.getScreenWidth = function() {
  1183. if (this.linkedControl)
  1184. return this.guiScreen.width * this.getScreenWidthPercent()
  1185. }
  1186. ;
  1187. ControlRect.prototype.getScreenHeight = function() {
  1188. if (this.linkedControl)
  1189. return this.guiScreen.height * this.getScreenHeightPercent()
  1190. }
  1191. ;
  1192. ControlRect.prototype.updateElement = function() {
  1193. var a = this.linkedControl;
  1194. if (a) {
  1195. var c = this.guiScreen.left * (1 - this.getScreenXPercent())
  1196. , b = this.guiScreen.bottom * (1 - this.getScreenYPercent())
  1197. , d = this.guiScreen.width * this.getScreenWidthPercent()
  1198. , e = this.guiScreen.height * this.getScreenHeightPercent();
  1199. a.style.left = c + "px";
  1200. a.style.bottom = b + "px";
  1201. a.style.width = d + "px";
  1202. a.style.height = e + "px"
  1203. }
  1204. }
  1205. ;
  1206. ControlRect.prototype.updateElement = function() {
  1207. var a = this.linkedControl;
  1208. if (a) {
  1209. var c = this.guiScreen.left * (1 - this.getScreenXPercent())
  1210. , b = this.guiScreen.bottom * (1 - this.getScreenYPercent())
  1211. , d = this.guiScreen.width * this.getScreenWidthPercent()
  1212. , e = this.guiScreen.height * this.getScreenHeightPercent();
  1213. a.style.left = c + "px";
  1214. a.style.bottom = b + "px";
  1215. a.style.width = d + "px";
  1216. a.style.height = e + "px"
  1217. }
  1218. }
  1219. ;
  1220. ControlRect.prototype.updateChildElements = function() {
  1221. this.updateElement();
  1222. for (var a = 0; a < this.childControlRects.length; a++)
  1223. this.childControlRects[a].updateChildElements()
  1224. }
  1225. ;
  1226. ControlRect.prototype.set = function(a, c, b, d) {
  1227. this.xPercent = a;
  1228. this.yPercent = c;
  1229. this.widthPercent = b;
  1230. this.heightPercent = d
  1231. }
  1232. ;
  1233. ControlRect.prototype.linkControl = function(a) {
  1234. this.linkedControl = a;
  1235. a.onmouseover = function() {
  1236. this.mouseOver = !0
  1237. }
  1238. .bind(this);
  1239. a.onmouseout = function() {
  1240. this.mouseOver = !1
  1241. }
  1242. .bind(this);
  1243. a.onmousedown = function() {
  1244. this.mouseDown = !0
  1245. }
  1246. .bind(this);
  1247. a.onmouseup = function() {
  1248. this.mouseDown = !1
  1249. }
  1250. .bind(this);
  1251. a.onclick = function() {
  1252. this.callBack && this.callBack(this);
  1253. this.clicked = !0
  1254. }
  1255. .bind(this)
  1256. }
  1257. ;
  1258. ControlRect.prototype.showControl = function(a) {
  1259. this.visible = a;
  1260. this.linkedControl && (this.linkedControl.style.display = a ? "block" : "none")
  1261. }
  1262. ;
  1263. ControlRect.prototype.setOpacity = function(a) {
  1264. this.opacity = a;
  1265. this.linkedControl && (this.linkedControl.style.opacity = a)
  1266. }
  1267. ;
  1268. ControlRect.prototype.hasChildControlRect = function(a) {
  1269. for (var c = 0; c < this.childControlRects.length; c++)
  1270. if (this.childControlRects[c] == a)
  1271. return !0;
  1272. return !1
  1273. }
  1274. ;
  1275. ControlRect.prototype.registerChildControlRect = function(a) {
  1276. this.hasChildControlRect(a) || (this.childControlRects.push(a),
  1277. a.parentControlRect = this)
  1278. }
  1279. ;
  1280. ControlRect.prototype.getScreenWidthPercent = function() {
  1281. var a = this.widthPercent;
  1282. this.parentControlRect && (a *= this.parentControlRect.getScreenWidthPercent());
  1283. return a
  1284. }
  1285. ;
  1286. ControlRect.prototype.getScreenHeightPercent = function() {
  1287. var a = this.heightPercent;
  1288. this.parentControlRect && (a *= this.parentControlRect.getScreenHeightPercent());
  1289. return a
  1290. }
  1291. ;
  1292. ControlRect.prototype.getScreenXPercent = function() {
  1293. var a = this.xPercent;
  1294. this.parentControlRect && (a *= this.parentControlRect.getScreenWidthPercent(),
  1295. a += this.parentControlRect.getScreenXPercent());
  1296. return a
  1297. }
  1298. ;
  1299. ControlRect.prototype.getScreenYPercent = function() {
  1300. var a = this.yPercent;
  1301. this.parentControlRect && (a *= this.parentControlRect.getScreenHeightPercent(),
  1302. a += this.parentControlRect.getScreenYPercent());
  1303. return a
  1304. }
  1305. ;
  1306. var prepareEmbedParams = function(a) {
  1307. a = a || {};
  1308. if (document.location.search)
  1309. for (var c = document.location.search.substring(1).split("&"), b = 0; b < c.length; ++b) {
  1310. var d = c[b].split("=");
  1311. a[d[0]] = d[1]
  1312. }
  1313. c = function(a) {
  1314. if (a | 0)
  1315. return !0;
  1316. for (var b = "true True TRUE yes Yes YES".split(" "), c = 0; c < b.length; ++c)
  1317. if (a === b[c])
  1318. return !0;
  1319. return !1
  1320. }
  1321. ;
  1322. a.width = a.width || 800;
  1323. a.height = a.height || 600;
  1324. a.autoStart = c(a.autoStart);
  1325. a.pagePreset = c(a.pagePreset);
  1326. a.fullFrame = c(a.fullFrame) || c(a.bare);
  1327. a.fullFrame = !a.pagePreset && a.fullFrame;
  1328. return a
  1329. }
  1330. , embed = function(a, c) {
  1331. var b;
  1332. c = prepareEmbedParams(c);
  1333. var d = c.thumbnailURL;
  1334. if (c.pagePreset) {
  1335. b = new WebViewer(c.width,c.height,a,!!d);
  1336. document.body.style.backgroundColor = "#d7e4da";
  1337. var e = document.createElement("div");
  1338. e.style.position = "relative";
  1339. e.style.backgroundColor = "#e4e7e4";
  1340. e.style.width = c.width + 12 + "px";
  1341. e.style.height = c.height + 6 + 16 + "px";
  1342. e.style.margin = "auto";
  1343. e.style.boxShadow = "3px 5px 12px 0px grey";
  1344. document.body.appendChild(e);
  1345. var f = document.createElement("div");
  1346. f.style.position = "relative";
  1347. f.style.left = "6px";
  1348. f.style.top = "6px";
  1349. e.appendChild(f);
  1350. f.appendChild(b.domRoot);
  1351. if (!b.mobile) {
  1352. e.style.resize = "both";
  1353. e.style.overflow = "hidden";
  1354. var g = [e.style.width, e.style.height]
  1355. , h = function() {
  1356. if (FullScreen.active())
  1357. e.style.resize = "none";
  1358. else if (e.style.resize = "both",
  1359. g[0] != e.style.width || g[1] != e.style.height)
  1360. g[0] = e.style.width,
  1361. g[1] = e.style.height,
  1362. b.resize(e.clientWidth - 12, e.clientHeight - 6 - 16);
  1363. window.setTimeout(h, 100)
  1364. };
  1365. h()
  1366. }
  1367. } else
  1368. b = new WebViewer(c.fullFrame ? window.innerWidth : c.width,c.fullFrame ? window.innerHeight : c.height,a,!!d),
  1369. document.body.appendChild(b.domRoot),
  1370. c.fullFrame && (b.domRoot.style.position = "absolute",
  1371. b.domRoot.style.left = b.domRoot.style.top = 0,
  1372. window.addEventListener("resize", function() {
  1373. FullScreen.active() || b.resize(window.innerWidth, window.innerHeight)
  1374. }));
  1375. b.ui.setThumbnailURL(d);
  1376. c.autoStart && b.loadScene();
  1377. return b
  1378. }
  1379. , fetchThumbnail = function(a, c, b, d) {
  1380. var e = !1
  1381. , f = a + (-1 == a.indexOf("?") ? "?" : "&") + "thumb=1"
  1382. , g = function(a) {
  1383. (a = (new Archive(a)).extract("thumbnail.jpg")) ? TextureCache.parseFile(a, c, d) : e ? b && b() : (e = !0,
  1384. Network.fetchBinaryIncremental(f, g, b, 394240));
  1385. return 0
  1386. };
  1387. Network.fetchBinaryIncremental(f, g, b, 65536)
  1388. }
  1389. , marmoset = "undefined" == typeof marmoset ? {} : marmoset;
  1390. marmoset.embed = embed;
  1391. marmoset.fetchThumbnail = fetchThumbnail;
  1392. function Fog(a, c) {
  1393. this.desc = c;
  1394. this.gl = a;
  1395. this.iblShader = a.shaderCache.fromURLs("fogvert.glsl", "fogfrag.glsl", ["#define FOG_IBL"]);
  1396. var b = ["#define FOG_DIR"];
  1397. this.dirShader = a.shaderCache.fromURLs("fogvert.glsl", "fogfrag.glsl", b);
  1398. b.push("#define FOG_SHADOWS");
  1399. this.dirShaderShadow = a.shaderCache.fromURLs("fogvert.glsl", "fogfrag.glsl", b);
  1400. b = ["#define FOG_SPOT"];
  1401. this.spotShader = a.shaderCache.fromURLs("fogvert.glsl", "fogfrag.glsl", b);
  1402. b.push("#define FOG_SHADOWS");
  1403. this.spotShaderShadow = a.shaderCache.fromURLs("fogvert.glsl", "fogfrag.glsl", b);
  1404. b = ["#define FOG_OMNI"];
  1405. this.omniShaderShadow = this.omniShader = a.shaderCache.fromURLs("fogvert.glsl", "fogfrag.glsl", b);
  1406. this.fullscreenTriangle = a.createBuffer();
  1407. a.bindBuffer(a.ARRAY_BUFFER, this.fullscreenTriangle);
  1408. b = new Float32Array([0, 0, 2, 0, 0, 2]);
  1409. a.bufferData(a.ARRAY_BUFFER, b, a.STATIC_DRAW);
  1410. a.bindBuffer(a.ARRAY_BUFFER, null)
  1411. }
  1412. Fog.prototype.draw = function(a, c) {
  1413. var b = this.gl
  1414. , d = a.view
  1415. , e = d.projectionMatrix
  1416. , f = Matrix.empty();
  1417. Matrix.mul(f, d.viewMatrix, d.projectionMatrix);
  1418. Matrix.invert(f, d.viewProjectionMatrix);
  1419. f = [e[10] + e[11], -e[14], -2 * e[11]];
  1420. e = [-2 / e[0], -2 / e[5], (1 - e[8]) / e[0], (1 - e[9]) / e[5]];
  1421. b.enable(b.BLEND);
  1422. b.blendFunc(b.ONE, b.ONE_MINUS_SRC_ALPHA);
  1423. for (var g = 0; g < a.lights.count + 1; ++g) {
  1424. var h = g - 1, k = h < a.lights.shadowCount, n;
  1425. n = 0 == g ? this.iblShader : 0 < a.lights.spot[3 * h] ? k ? this.spotShaderShadow : this.spotShader : 0 < a.lights.getLightPos(h)[3] ? this.omniShader : k ? this.dirShaderShadow : this.dirShader;
  1426. n.bind();
  1427. var m = n.params;
  1428. b.uniform3fv(m.uDepthToZ, f);
  1429. b.uniform4fv(m.uUnproject, e);
  1430. b.uniformMatrix4fv(m.uInvViewMatrix, !1, d.transform);
  1431. b.uniform1f(m.uFogInvDistance, 1 / this.desc.distance);
  1432. b.uniform1f(m.uFogOpacity, this.desc.opacity * (1 - a.stripData.activeFade()));
  1433. b.uniform1f(m.uFogDispersion, 1 - this.desc.dispersion);
  1434. var l = [0, 0, 0];
  1435. l[this.desc.type] = 1;
  1436. b.uniform3fv(m.uFogType, l);
  1437. b.uniform3fv(m.uFogColor, this.desc.color);
  1438. b.uniform1f(m.uFogIllum, 0 == g ? this.desc.skyIllum : this.desc.lightIllum);
  1439. b.uniformMatrix4fv(m.uLightMatrix, !1, a.lights.invMatrix);
  1440. if (0 == g) {
  1441. h = new Float32Array(a.sky.diffuseCoefficients);
  1442. for (k = 4; 16 > k; ++k)
  1443. h[k] *= 1 - this.desc.dispersion;
  1444. for (k = 16; 36 > k; ++k)
  1445. h[k] *= 1 - this.desc.dispersion * this.desc.dispersion;
  1446. b.uniform4fv(m.uFogLightSphere, h)
  1447. } else {
  1448. var p = a.lights.getLightPos(h)
  1449. , p = Matrix.mul4(Vect.empty(), a.lights.invMatrix, p[0], p[1], p[2], p[3])
  1450. , l = a.lights.getLightDir(h)
  1451. , l = Matrix.mulVec(Vect.empty(), a.lights.invMatrix, l[0], l[1], l[2]);
  1452. b.uniform4fv(m.uLightPosition, p);
  1453. b.uniform3fv(m.uLightColor, a.lights.getColor(h));
  1454. var p = 0.01745329251 * a.lights.spot[3 * h]
  1455. , r = Math.cos(0.5 * p);
  1456. b.uniform4fv(m.uSpotParams, [-l[0], -l[1], -l[2], 0 < p ? r * r : 0]);
  1457. b.uniform4fv(m.uLightAttenuation, [a.lights.parameters[3 * h + 0], a.lights.parameters[3 * h + 1], a.lights.parameters[3 * h + 2], r]);
  1458. k && (k = Matrix.mul(Matrix.empty(), a.lights.finalTransformBuffer.subarray(16 * h), a.lights.matrix),
  1459. b.uniformMatrix4fv(m.uShadowProj, !1, k),
  1460. a.shadow.depthTextures[h].bind(n.samplers.uShadowMap),
  1461. h = 0,
  1462. 1 < a.postRender.sampleCount && (h = a.postRender.currentSample() / a.postRender.sampleCount),
  1463. b.uniform1f(m.uDitherOffset, h),
  1464. b.uniform3fv(m.uAABBMin, a.bounds.min),
  1465. b.uniform3fv(m.uAABBMax, a.bounds.max),
  1466. h = Vect.lerp(Vect.empty(), a.bounds.min, a.bounds.max, 0.5),
  1467. k = Vect.distance(h, a.bounds.min),
  1468. b.uniform4f(m.uCylinder, h[0], h[1], h[2], k * k))
  1469. }
  1470. c.bind(n.samplers.tDepth);
  1471. n = n.attribs.vCoord;
  1472. b.bindBuffer(b.ARRAY_BUFFER, this.fullscreenTriangle);
  1473. b.enableVertexAttribArray(n);
  1474. b.vertexAttribPointer(n, 2, b.FLOAT, !1, 0, 0);
  1475. b.drawArrays(b.TRIANGLES, 0, 3);
  1476. b.disableVertexAttribArray(n);
  1477. b.bindBuffer(b.ARRAY_BUFFER, null)
  1478. }
  1479. b.disable(b.BLEND)
  1480. }
  1481. ;
  1482. Fog.prototype.complete = function() {
  1483. return this.iblShader.complete() && this.dirShader.complete() && this.dirShaderShadow.complete() && this.spotShader.complete() && this.spotShaderShadow.complete() && this.omniShader.complete() && this.omniShaderShadow.complete()
  1484. }
  1485. ;
  1486. function Framebuffer(a, c) {
  1487. this.gl = a;
  1488. this.fbo = a.createFramebuffer();
  1489. a.bindFramebuffer(a.FRAMEBUFFER, this.fbo);
  1490. c && (this.width = c.width,
  1491. this.height = c.height,
  1492. c.color0 && (this.color0 = c.color0,
  1493. a.framebufferTexture2D(a.FRAMEBUFFER, a.COLOR_ATTACHMENT0, a.TEXTURE_2D, this.color0.id, 0),
  1494. this.width = c.color0.desc.width,
  1495. this.height = c.color0.desc.height),
  1496. c.depth ? (this.depth = c.depth,
  1497. a.framebufferTexture2D(a.FRAMEBUFFER, a.DEPTH_ATTACHMENT, a.TEXTURE_2D, this.depth.id, 0)) : (this.depthBuffer = c.depthBuffer,
  1498. c.createDepth && !this.depthBuffer && (this.depthBuffer = Framebuffer.createDepthBuffer(a, this.width, this.height)),
  1499. this.depthBuffer && (a.bindRenderbuffer(a.RENDERBUFFER, this.depthBuffer),
  1500. a.framebufferRenderbuffer(a.FRAMEBUFFER, a.DEPTH_ATTACHMENT, a.RENDERBUFFER, this.depthBuffer),
  1501. a.bindRenderbuffer(a.RENDERBUFFER, null))));
  1502. this.valid = c && c.ignoreStatus || a.checkFramebufferStatus(a.FRAMEBUFFER) == a.FRAMEBUFFER_COMPLETE;
  1503. a.bindFramebuffer(a.FRAMEBUFFER, null)
  1504. }
  1505. Framebuffer.createDepthBuffer = function(a, c, b) {
  1506. var d = a.createRenderbuffer();
  1507. a.bindRenderbuffer(a.RENDERBUFFER, d);
  1508. a.renderbufferStorage(a.RENDERBUFFER, a.DEPTH_COMPONENT16, c, b);
  1509. a.bindRenderbuffer(a.RENDERBUFFER, null);
  1510. return d
  1511. }
  1512. ;
  1513. Framebuffer.prototype.bind = function() {
  1514. this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, this.fbo);
  1515. this.gl.viewport(0, 0, this.width, this.height)
  1516. }
  1517. ;
  1518. Framebuffer.bindNone = function(a) {
  1519. a.bindFramebuffer(a.FRAMEBUFFER, null)
  1520. }
  1521. ;
  1522. var FullScreen = {
  1523. support: function() {
  1524. return !!(document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled)
  1525. },
  1526. begin: function(a, c) {
  1527. var b = a.requestFullscreen || a.webkitRequestFullScreen || a.mozRequestFullScreen || a.msRequestFullscreen;
  1528. if (b) {
  1529. var d = function() {
  1530. FullScreen.active() || (document.removeEventListener("fullscreenchange", d),
  1531. document.removeEventListener("webkitfullscreenchange", d),
  1532. document.removeEventListener("mozfullscreenchange", d),
  1533. document.removeEventListener("MSFullscreenChange", d));
  1534. c && c()
  1535. };
  1536. document.addEventListener("fullscreenchange", d);
  1537. document.addEventListener("webkitfullscreenchange", d);
  1538. document.addEventListener("mozfullscreenchange", d);
  1539. document.addEventListener("MSFullscreenChange", d);
  1540. b.bind(a)()
  1541. }
  1542. },
  1543. end: function() {
  1544. var a = document.exitFullscreen || document.webkitExitFullscreen || document.mozCancelFullScreen || document.msExitFullscreen;
  1545. a && a.bind(document)()
  1546. },
  1547. active: function() {
  1548. return !!(document.fullscreenElement || document.webkitIsFullScreen || document.mozFullScreenElement || document.msFullscreenElement)
  1549. }
  1550. };
  1551. function GUIManager(a) {
  1552. this.init = !1;
  1553. this.ui = a;
  1554. this.bottom = this.left = this.height = this.width = 0;
  1555. this.clicked = this.mouseDown = !1;
  1556. this.playbackControls = 0;
  1557. a = 1;
  1558. window.devicePixelRatio && (2 < window.devicePixelRatio ? a = 4 : 1 < window.devicePixelRatio && (a = 2));
  1559. this.imageSetNumber = a
  1560. }
  1561. GUIManager.prototype.setSize = function(a, c) {
  1562. this.width = a;
  1563. this.height = c;
  1564. this.left = -a;
  1565. this.bottom = -c;
  1566. this.playbackControls && this.playbackControls.resize(this)
  1567. }
  1568. ;
  1569. GUIManager.prototype.setupActiveView = function(a) {
  1570. this.init || (this.init = !0,
  1571. this.ui = a,
  1572. a.viewer.scene.sceneAnimator && (this.playbackControls = new PlaybackControls(this),
  1573. this.playbackControls.resize(this)))
  1574. }
  1575. ;
  1576. GUIManager.prototype.updateElement = function(a) {
  1577. var c = a.linkedControl;
  1578. if (c) {
  1579. var b = this.left * (1 - a.getScreenXPercent())
  1580. , d = this.bottom * (1 - a.getScreenYPercent())
  1581. , e = this.width * a.getScreenWidthPercent();
  1582. a = this.height * a.getScreenHeightPercent();
  1583. c.style.left = b + "px";
  1584. c.style.bottom = d + "px";
  1585. c.style.width = e + "px";
  1586. c.style.height = a + "px"
  1587. }
  1588. }
  1589. ;
  1590. function GUIRegion(a) {
  1591. this.debugString = "GUIRegion";
  1592. this.name = "Default";
  1593. this.controlRect = new ControlRect(a);
  1594. this.yPercent = this.xPercent = 0;
  1595. this.heightPercent = this.widthPercent = 1;
  1596. this.guiScreen = a
  1597. }
  1598. GUIRegion.prototype.addImageElement = function(a, c) {
  1599. var b = this.guiScreen.ui.menuCluster.contents
  1600. , d = document.createElement("input");
  1601. a.linkControl(d);
  1602. this.guiScreen.updateElement(a);
  1603. d.type = "image";
  1604. d.src = marmoset.dataLocale + c;
  1605. d.style.position = "absolute";
  1606. d.style.border = "none";
  1607. d.style.outline = "0px";
  1608. d.style.zIndex = "1";
  1609. d.title = c;
  1610. d.style.opacity = a.opacity;
  1611. var e = new XMLHttpRequest;
  1612. e.open("HEAD", d.src, !0);
  1613. e.onload = function(a) {
  1614. a.appendChild(this)
  1615. }
  1616. .bind(d, b);
  1617. e.send();
  1618. return d
  1619. }
  1620. ;
  1621. GUIRegion.prototype.addImage = function(a) {
  1622. var c = new ControlRect(this.guiScreen);
  1623. this.addImageElement(c, a);
  1624. return c
  1625. }
  1626. ;
  1627. GUIRegion.prototype.addTextButton = function(a, c, b, d, e, f) {
  1628. var g = new Button(this.guiScreen);
  1629. g.name = "none";
  1630. g.text = a;
  1631. g.controlRect.set(c, b, d, e);
  1632. g.controlRect.opacity = f;
  1633. this.controlRect.registerChildControlRect(g.controlRect);
  1634. c = this.guiScreen.ui.menuCluster.contents;
  1635. b = document.createElement("text");
  1636. b.style.color = "white";
  1637. b.style.fontFamily = "Arial";
  1638. b.style.fontSize = marmoset.largeUI ? "14px" : "12px";
  1639. b.style.textShadow = "2px 2px 3px #000000";
  1640. c.appendChild(b);
  1641. g.controlRect.linkControl(b);
  1642. this.guiScreen.updateElement(g.controlRect);
  1643. b.type = "text";
  1644. b.name = "text";
  1645. b.style.position = "absolute";
  1646. b.style.border = "none";
  1647. b.style.outline = "0px";
  1648. b.style.zIndex = "2";
  1649. b.innerHTML = a;
  1650. b.style.opacity = g.controlRect.opacity;
  1651. g.linkControl(b);
  1652. return g
  1653. }
  1654. ;
  1655. function GUIScreen(a) {
  1656. this.init = !1;
  1657. this.ui = a;
  1658. this.bottom = this.left = this.height = this.width = 0;
  1659. this.clicked = this.mouseDown = !1;
  1660. this.playbackControls = 0;
  1661. a = 1;
  1662. window.devicePixelRatio && (2 < window.devicePixelRatio ? a = 4 : 1 < window.devicePixelRatio && (a = 2));
  1663. this.imageSetNumber = a
  1664. }
  1665. GUIScreen.prototype.setSize = function(a, c) {
  1666. this.width = a;
  1667. this.height = c;
  1668. this.left = -a;
  1669. this.bottom = -c;
  1670. this.playbackControls && this.playbackControls.resize(this)
  1671. }
  1672. ;
  1673. GUIScreen.prototype.setupActiveView = function(a) {
  1674. this.init || (this.init = !0,
  1675. this.ui = a,
  1676. a.viewer.scene.sceneAnimator && (this.playbackControls = new PlaybackControls(this),
  1677. this.playbackControls.resize(this)))
  1678. }
  1679. ;
  1680. GUIScreen.prototype.updateElement = function(a) {
  1681. var c = a.linkedControl;
  1682. if (c) {
  1683. var b = this.left * (1 - a.getScreenXPercent())
  1684. , d = this.bottom * (1 - a.getScreenYPercent())
  1685. , e = this.width * a.getScreenWidthPercent();
  1686. a = this.height * a.getScreenHeightPercent();
  1687. c.style.left = b + "px";
  1688. c.style.bottom = d + "px";
  1689. c.style.width = e + "px";
  1690. c.style.height = a + "px"
  1691. }
  1692. }
  1693. ;
  1694. function Input(a) {
  1695. this.onTap = [];
  1696. this.onSingleTap = [];
  1697. this.onDoubleTap = [];
  1698. this.onDrag = [];
  1699. this.onZoom = [];
  1700. this.onPan = [];
  1701. this.onPan2 = [];
  1702. this.onAnything = [];
  1703. this.mouseDownCount = 0;
  1704. this.macHax = 0 <= navigator.platform.toUpperCase().indexOf("MAC");
  1705. a && this.attach(a)
  1706. }
  1707. Input.prototype.attach = function(a) {
  1708. this.element = a;
  1709. var c = function(a) {
  1710. for (var c = 0; c < this.onAnything.length; ++c)
  1711. this.onAnything[c]();
  1712. a.preventDefault()
  1713. }
  1714. .bind(this);
  1715. this.mouseStates = [{
  1716. pressed: !1,
  1717. position: [0, 0],
  1718. downPosition: [0, 0]
  1719. }, {
  1720. pressed: !1,
  1721. position: [0, 0],
  1722. downPosition: [0, 0]
  1723. }, {
  1724. pressed: !1,
  1725. position: [0, 0],
  1726. downPosition: [0, 0]
  1727. }];
  1728. this.lastTapPos = [0, 0];
  1729. a = function(a) {
  1730. if (a.target === this.element) {
  1731. this.mouseDownCount++;
  1732. var d = this.mouseStates[a.button];
  1733. if (d) {
  1734. d.pressed = !0;
  1735. var e = this.element.getBoundingClientRect();
  1736. d.position[0] = d.downPosition[0] = a.clientX - e.left;
  1737. d.position[1] = d.downPosition[1] = a.clientY - e.top;
  1738. c(a)
  1739. }
  1740. }
  1741. }
  1742. .bind(this);
  1743. this.element.addEventListener("mousedown", a);
  1744. a = function(a) {
  1745. var d = this.mouseStates[a.button];
  1746. if (d) {
  1747. var e = this.element.getBoundingClientRect()
  1748. , f = a.clientX - e.left
  1749. , e = a.clientY - e.top;
  1750. d.pressed = !1;
  1751. d.position[0] = f;
  1752. d.position[1] = e;
  1753. if (0 == a.button && a.target == this.element && 10 > Math.abs(d.position[0] - d.downPosition[0]) + Math.abs(d.position[1] - d.downPosition[1])) {
  1754. for (var g = 0; g < this.onTap.length; ++g)
  1755. this.onTap[g](f, e);
  1756. this.needSingleClick = !0;
  1757. window.setTimeout(function(a, b) {
  1758. if (this.needSingleClick) {
  1759. for (var c = 0; c < this.onSingleTap.length; ++c)
  1760. this.onSingleTap[c](a, b);
  1761. this.needSingleClick = !1
  1762. }
  1763. }
  1764. .bind(this, f, e), 301);
  1765. d = !1;
  1766. if (void 0 !== this.doubleClickTimer && (g = 8 > Math.abs(f - this.lastTapPos[0]) + Math.abs(e - this.lastTapPos[1]),
  1767. 300 > Date.now() - this.doubleClickTimer && g))
  1768. for (d = !0,
  1769. this.needSingleClick = !1,
  1770. g = 0; g < this.onDoubleTap.length; ++g)
  1771. this.onDoubleTap[g](f, e);
  1772. this.doubleClickTimer = Date.now();
  1773. d && (this.doubleClickTimer = -1E9);
  1774. this.lastTapPos[0] = f;
  1775. this.lastTapPos[1] = e
  1776. }
  1777. }
  1778. c(a)
  1779. }
  1780. .bind(this);
  1781. this.element.addEventListener("mouseup", a);
  1782. a = function(a) {
  1783. for (var d = !1, e = this.element.getBoundingClientRect(), f = 0; 3 > f; ++f) {
  1784. var g = this.mouseStates[f];
  1785. if (g.pressed) {
  1786. var d = a.clientX - e.left
  1787. , h = a.clientY - e.top
  1788. , k = d - g.position[0]
  1789. , n = h - g.position[1];
  1790. g.position[0] = d;
  1791. g.position[1] = h;
  1792. if (2 == f && a.altKey)
  1793. for (g = 0; g < this.onZoom.length; ++g)
  1794. this.onZoom[g](2 * n);
  1795. else if (1 <= f || a.ctrlKey)
  1796. for (g = 0; g < this.onPan.length; ++g)
  1797. this.onPan[g](k, n);
  1798. else if (0 == f)
  1799. if (a.shiftKey)
  1800. for (g = 0; g < this.onPan2.length; ++g)
  1801. this.onPan2[g](k, n);
  1802. else
  1803. for (g = 0; g < this.onDrag.length; ++g)
  1804. this.onDrag[g](d, h, k, n);
  1805. d = !0
  1806. }
  1807. }
  1808. d && c(a)
  1809. }
  1810. .bind(this);
  1811. this.element.addEventListener("mousemove", a);
  1812. a = function(a) {
  1813. var d = 0;
  1814. a.deltaY ? (d = -0.4 * a.deltaY,
  1815. 1 == a.deltaMode ? d *= 16 : 2 == a.deltaMode && (d *= this.element.clientHeight)) : a.wheelDelta ? d = this.macHax && 120 == Math.abs(a.wheelDelta) ? 0.08 * a.wheelDelta : 0.4 * a.wheelDelta : a.detail && (d = -10 * a.detail);
  1816. for (var e = 0; e < this.onZoom.length; ++e)
  1817. this.onZoom[e](d);
  1818. c(a)
  1819. }
  1820. .bind(this);
  1821. this.element.addEventListener("mousewheel", a);
  1822. this.element.addEventListener("DOMMouseScroll", a);
  1823. this.element.addEventListener("wheel", a);
  1824. a = function(a) {
  1825. for (var c = 0; c < this.mouseStates.length; ++c)
  1826. this.mouseStates[c].pressed = !1;
  1827. a.preventDefault()
  1828. }
  1829. .bind(this);
  1830. this.element.addEventListener("mouseleave", a);
  1831. this.element.addEventListener("contextmenu", function(a) {
  1832. a.preventDefault()
  1833. });
  1834. this.touches = {};
  1835. this.tapPossible = !1;
  1836. this.touchCountFloor = 0;
  1837. a = function(a) {
  1838. for (var d = this.element.getBoundingClientRect(), e = !1, f = 0; f < a.changedTouches.length; ++f)
  1839. if (a.target === this.element) {
  1840. var g = a.changedTouches[f]
  1841. , e = {
  1842. x: g.clientX - d.left,
  1843. y: g.clientY - d.top
  1844. };
  1845. e.startX = e.x;
  1846. e.startY = e.y;
  1847. this.touches[g.identifier] = e;
  1848. e = !0
  1849. }
  1850. this.tapPossible = 1 == a.touches.length;
  1851. for (g = d = 0; g < this.touches.length; ++g)
  1852. d++;
  1853. d > this.touchCountFloor && (this.touchCountFloor = d);
  1854. e && c(a)
  1855. }
  1856. .bind(this);
  1857. this.element.addEventListener("touchstart", a);
  1858. a = function(a) {
  1859. for (var d = !1, e = 0; e < a.changedTouches.length; ++e) {
  1860. var f = a.changedTouches[e]
  1861. , g = this.touches[f.identifier];
  1862. if (g) {
  1863. if (this.tapPossible) {
  1864. var h = this.element.getBoundingClientRect()
  1865. , d = f.clientX - h.left
  1866. , h = f.clientY - h.top;
  1867. if (24 > Math.max(Math.abs(d - g.startX), Math.abs(h - g.startY))) {
  1868. for (e = 0; e < this.onTap.length; ++e)
  1869. this.onTap[e](d, h);
  1870. this.needSingleTap = !0;
  1871. window.setTimeout(function(a, b) {
  1872. if (this.needSingleTap) {
  1873. for (var c = 0; c < this.onSingleTap.length; ++c)
  1874. this.onSingleTap[c](a, b);
  1875. this.needSingleTap = !1
  1876. }
  1877. }
  1878. .bind(this, d, h), 501);
  1879. g = !1;
  1880. if (void 0 !== this.doubleTapTimer) {
  1881. var k = 24 > Math.max(Math.abs(d - this.lastTapPos[0]), Math.abs(h - this.lastTapPos[1]))
  1882. , n = 500 > Date.now() - this.doubleTapTimer;
  1883. if (k && n)
  1884. for (g = !0,
  1885. e = 0; e < this.onDoubleTap.length; ++e)
  1886. this.onDoubleTap[e](d, h)
  1887. }
  1888. this.doubleTapTimer = Date.now();
  1889. g && (this.doubleTapTimer = -1E9);
  1890. this.lastTapPos[0] = d;
  1891. this.lastTapPos[1] = h
  1892. }
  1893. this.tapPossible = !1
  1894. }
  1895. delete this.touches[f.identifier];
  1896. d = !0
  1897. }
  1898. }
  1899. for (f = e = 0; f < this.touches.length; ++f)
  1900. e++;
  1901. 0 >= e && (this.touchCountFloor = 0);
  1902. d && c(a)
  1903. }
  1904. .bind(this);
  1905. this.element.addEventListener("touchend", a);
  1906. this.element.addEventListener("touchcancel", a);
  1907. this.element.addEventListener("touchleave", a);
  1908. a = function(a) {
  1909. for (var d = [], e = 0; e < a.touches.length; ++e)
  1910. a.touches[e].target === this.element && d.push(a.touches[e]);
  1911. var f = this.element.getBoundingClientRect();
  1912. if (1 == d.length && 1 >= this.touchCountFloor) {
  1913. var g = d[0]
  1914. , h = this.touches[g.identifier];
  1915. if (h) {
  1916. var k = g.clientX - f.left
  1917. , g = g.clientY - f.top
  1918. , f = k - h.x
  1919. , n = g - h.y;
  1920. h.x = k;
  1921. h.y = g;
  1922. for (e = 0; e < this.onDrag.length; ++e)
  1923. this.onDrag[e](k, g, f, n, a.shiftKey)
  1924. }
  1925. } else if (2 == d.length && 2 >= this.touchCountFloor) {
  1926. if (n = d[0],
  1927. e = this.touches[n.identifier],
  1928. g = d[1],
  1929. h = this.touches[g.identifier],
  1930. e && h) {
  1931. var k = n.clientX - f.left
  1932. , n = n.clientY - f.top
  1933. , m = g.clientX - f.left
  1934. , l = g.clientY - f.top
  1935. , p = Math.sqrt((k - m) * (k - m) + (n - l) * (n - l))
  1936. , r = Math.sqrt((e.x - h.x) * (e.x - h.x) + (e.y - h.y) * (e.y - h.y))
  1937. , s = Math.abs(p - r)
  1938. , f = (k - e.x + m - h.x) / 2
  1939. , g = (n - e.y + l - h.y) / 2
  1940. , u = Math.sqrt(f * f + g * g);
  1941. e.x = k;
  1942. e.y = n;
  1943. h.x = m;
  1944. h.y = l;
  1945. if (0 < s)
  1946. for (h = s / (s + u),
  1947. e = 0; e < this.onZoom.length; ++e)
  1948. this.onZoom[e](2 * (p - r) * h);
  1949. if (0 < u)
  1950. for (h = u / (s + u),
  1951. e = 0; e < this.onDrag.length; ++e)
  1952. this.onPan[e](f * h, g * h)
  1953. }
  1954. } else if (3 <= d.length) {
  1955. for (e = r = p = m = n = 0; e < d.length; ++e)
  1956. g = d[e],
  1957. h = this.touches[g.identifier],
  1958. k = g.clientX - f.left,
  1959. g = g.clientY - f.top,
  1960. p += k,
  1961. r += g,
  1962. h && (n += h.x,
  1963. m += h.y,
  1964. h.x = k,
  1965. h.y = g);
  1966. n /= d.length;
  1967. m /= d.length;
  1968. p /= d.length;
  1969. r /= d.length;
  1970. for (e = 0; e < this.onPan2.length; ++e)
  1971. this.onPan2[e](p - n, r - m)
  1972. }
  1973. 0 < d.length && c(a)
  1974. }
  1975. .bind(this);
  1976. this.element.addEventListener("touchmove", a)
  1977. }
  1978. ;
  1979. function KeyFrame(a, c) {
  1980. a && c ? (this.frameIndex = c.frameIndex,
  1981. this.value = c.value,
  1982. this.interpolation = c.interpolation,
  1983. this.weighIn = c.weighIn,
  1984. this.weighOut = c.weighOut) : (this.interpolation = this.value = this.frameIndex = 0,
  1985. this.weighOut = this.weighIn = 1)
  1986. }
  1987. ;function Lights(a, c) {
  1988. this.rotation = this.shadowCount = this.count = 0;
  1989. this.positions = [];
  1990. this.directions = [];
  1991. this.matrixWeights = [];
  1992. this.matrix = Matrix.identity();
  1993. this.invMatrix = Matrix.identity();
  1994. this.defaultmatrix = Matrix.identity();
  1995. this.defaultviewmatrix = Matrix.identity();
  1996. for (var b in a)
  1997. this[b] = a[b];
  1998. this.count = this.positions.length / 4;
  1999. this.count = Math.min(6, this.count);
  2000. this.shadowCount = Math.min(3, this.shadowCount);
  2001. this.positions = new Float32Array(this.positions);
  2002. this.positionBuffer = new Float32Array(this.positions);
  2003. this.directions = new Float32Array(this.directions);
  2004. this.directionBuffer = new Float32Array(this.directions);
  2005. this.colors = new Float32Array(this.colors);
  2006. this.colorsBuffer = new Float32Array(this.colors);
  2007. this.modelViewBuffer = new Float32Array(16 * this.shadowCount);
  2008. this.projectionBuffer = new Float32Array(16 * this.shadowCount);
  2009. this.finalTransformBuffer = new Float32Array(16 * this.shadowCount);
  2010. this.inverseTransformBuffer = new Float32Array(16 * this.shadowCount);
  2011. this.shadowTexelPadProjections = new Float32Array(4 * this.shadowCount);
  2012. this.shadowsNeedUpdate = new Uint8Array(this.shadowCount);
  2013. for (var d = 0; d < this.shadowsNeedUpdate.length; ++d)
  2014. this.shadowsNeedUpdate[d] = 1;
  2015. Matrix.rotation(this.matrix, this.rotation, 1);
  2016. Matrix.transpose(this.invMatrix, this.matrix);
  2017. Matrix.copy(this.defaultmatrix, this.matrix);
  2018. Matrix.copy(this.defaultviewmatrix, c.viewMatrix);
  2019. for (d = 0; d < this.count; ++d) {
  2020. b = this.positions.subarray(4 * d, 4 * d + 4);
  2021. var e = this.directions.subarray(3 * d, 3 * d + 3);
  2022. 1 == this.matrixWeights[d] ? (Matrix.mul4(b, this.matrix, b[0], b[1], b[2], b[3]),
  2023. Matrix.mulVec(e, this.matrix, e[0], e[1], e[2])) : 2 == this.matrixWeights[d] && (Matrix.mul4(b, c.viewMatrix, b[0], b[1], b[2], b[3]),
  2024. Matrix.mulVec(e, c.viewMatrix, e[0], e[1], e[2]))
  2025. }
  2026. }
  2027. Lights.prototype.getLightPos = function(a) {
  2028. return this.positionBuffer.subarray(4 * a, 4 * a + 4)
  2029. }
  2030. ;
  2031. Lights.prototype.setLightDistance = function(a, c) {
  2032. 0 >= c && (c = 1E-5);
  2033. this.parameters[3 * a + 2] = 1 / c
  2034. }
  2035. ;
  2036. Lights.prototype.setLightSpotAngle = function(a, c) {
  2037. 0 >= c && (c = 1E-6);
  2038. this.spot[3 * a] = c;
  2039. var b = Math.sin(3.1415926 / 180 * c / 2);
  2040. this.spot[3 * a + 2] = 1 / (b * b) * this.spot[3 * a + 1]
  2041. }
  2042. ;
  2043. Lights.prototype.setLightSpotSharpness = function(a, c) {
  2044. this.spot[3 * a + 1] = c;
  2045. this.setLightSpotAngle(this.spot[3 * a])
  2046. }
  2047. ;
  2048. Lights.prototype.setLightPos = function(a, c) {
  2049. this.positions[4 * a + 0] = c[0];
  2050. this.positions[4 * a + 1] = c[1];
  2051. this.positions[4 * a + 2] = c[2];
  2052. var b = this.positions.subarray(4 * a, 4 * a + 4);
  2053. 1 == this.matrixWeights[a] ? Matrix.mul4(b, this.defaultmatrix, c[0], c[1], c[2], b[3]) : 2 == this.matrixWeights[a] && Matrix.mul4(b, this.defaultviewmatrix, c[0], c[1], c[2], b[3])
  2054. }
  2055. ;
  2056. Lights.prototype.setLightDir = function(a, c) {
  2057. this.directions[3 * a + 0] = c[0];
  2058. this.directions[3 * a + 1] = c[1];
  2059. this.directions[3 * a + 2] = c[2];
  2060. var b = this.directions.subarray(3 * a, 3 * a + 3);
  2061. 1 == this.matrixWeights[a] ? Matrix.mulVec(b, this.defaultmatrix, c[0], c[1], c[2]) : 2 == this.matrixWeights[a] && Matrix.mulVec(b, this.defaultviewmatrix, c[0], c[1], c[2])
  2062. }
  2063. ;
  2064. Lights.prototype.getLightColor = function(a) {
  2065. return this.colors.subarray(3 * a, 3 * a + 3)
  2066. }
  2067. ;
  2068. Lights.prototype.setLightColor = function(a, c) {
  2069. this.colors[3 * a + 0] = c[0];
  2070. this.colors[3 * a + 1] = c[1];
  2071. this.colors[3 * a + 2] = c[2]
  2072. }
  2073. ;
  2074. Lights.prototype.getLightDir = function(a) {
  2075. return this.directionBuffer.subarray(3 * a, 3 * a + 3)
  2076. }
  2077. ;
  2078. Lights.prototype.getColor = function(a) {
  2079. a *= 3;
  2080. return [this.colors[a], this.colors[a + 1], this.colors[a + 2]]
  2081. }
  2082. ;
  2083. Lights.prototype.update = function(a, c) {
  2084. var b = new Matrix.type(this.matrix);
  2085. Matrix.rotation(this.matrix, this.rotation, 1);
  2086. Matrix.transpose(this.invMatrix, this.matrix);
  2087. for (var d = 0; d < this.count; ++d) {
  2088. var e = this.positions.subarray(4 * d, 4 * d + 4)
  2089. , f = this.directions.subarray(3 * d, 3 * d + 3)
  2090. , g = this.getLightPos(d)
  2091. , h = this.getLightDir(d);
  2092. 1 == this.matrixWeights[d] ? (g[0] = e[0],
  2093. g[1] = e[1],
  2094. g[2] = e[2],
  2095. g[3] = e[3],
  2096. h[0] = f[0],
  2097. h[1] = f[1],
  2098. h[2] = f[2]) : 2 == this.matrixWeights[d] ? (Matrix.mul4(g, a.transform, e[0], e[1], e[2], e[3]),
  2099. Matrix.mulVec(h, a.transform, f[0], f[1], f[2]),
  2100. Matrix.mul4(g, this.matrix, g[0], g[1], g[2], g[3]),
  2101. Matrix.mulVec(h, this.matrix, h[0], h[1], h[2])) : (Matrix.mul4(g, this.matrix, e[0], e[1], e[2], e[3]),
  2102. Matrix.mulVec(h, this.matrix, f[0], f[1], f[2]));
  2103. Vect.normalize(h, h)
  2104. }
  2105. for (var f = new Float32Array(this.finalTransformBuffer), g = Matrix.empty(), h = Matrix.empty(), k = Matrix.empty(), n = Vect.empty(), m = Vect.empty(), l = Vect.empty(), p = Vect.empty(), e = Vect.empty(), r = [], s = [], u = Matrix.create(0.5, 0, 0, 0.5, 0, 0.5, 0, 0.5, 0, 0, 0.5, 0.5, 0, 0, 0, 1), d = 0; d < this.count; ++d) {
  2106. n = this.getLightPos(d);
  2107. m = this.getLightDir(d);
  2108. 0.99 < Math.abs(m[1]) ? Vect.set(l, 1, 0, 0) : Vect.set(l, 0, 1, 0);
  2109. Vect.cross(p, l, m);
  2110. Vect.normalize(p, p);
  2111. Vect.cross(l, m, p);
  2112. Vect.normalize(l, l);
  2113. Matrix.set(g, p[0], p[1], p[2], -Vect.dot(p, n), l[0], l[1], l[2], -Vect.dot(l, n), m[0], m[1], m[2], -Vect.dot(m, n), 0, 0, 0, 1);
  2114. for (n = 0; 8 > n; ++n)
  2115. e[0] = n & 1 ? c.max[0] : c.min[0],
  2116. e[1] = n & 2 ? c.max[1] : c.min[1],
  2117. e[2] = n & 4 ? c.max[2] : c.min[2],
  2118. Matrix.mulPoint(e, this.matrix, 1.005 * e[0], 1.005 * e[1], 1.005 * e[2]),
  2119. Matrix.mulPoint(e, g, e[0], e[1], e[2]),
  2120. 0 == n ? (r[0] = s[0] = e[0],
  2121. r[1] = s[1] = e[1],
  2122. r[2] = s[2] = e[2]) : (r[0] = Math.min(r[0], e[0]),
  2123. r[1] = Math.min(r[1], e[1]),
  2124. r[2] = Math.min(r[2], e[2]),
  2125. s[0] = Math.max(s[0], e[0]),
  2126. s[1] = Math.max(s[1], e[1]),
  2127. s[2] = Math.max(s[2], e[2]));
  2128. var n = -r[2]
  2129. , m = -s[2]
  2130. , q = this.spot[3 * d];
  2131. 0 < q ? (n = Math.min(n, 1 / this.parameters[3 * d + 2]),
  2132. m = Math.max(0.04 * n, m),
  2133. Matrix.perspective(h, q, 1, m, n),
  2134. d < this.shadowCount && (n = 2 * -Math.tan(0.00872664625 * q),
  2135. this.shadowTexelPadProjections[4 * d + 0] = this.modelViewBuffer[16 * d + 2] * n,
  2136. this.shadowTexelPadProjections[4 * d + 1] = this.modelViewBuffer[16 * d + 6] * n,
  2137. this.shadowTexelPadProjections[4 * d + 2] = this.modelViewBuffer[16 * d + 10] * n,
  2138. this.shadowTexelPadProjections[4 * d + 3] = this.modelViewBuffer[16 * d + 14] * n)) : (Matrix.ortho(h, r[0], s[0], r[1], s[1], m, n),
  2139. d < this.shadowCount && (this.shadowTexelPadProjections[4 * d + 0] = this.shadowTexelPadProjections[4 * d + 1] = this.shadowTexelPadProjections[4 * d + 2] = 0,
  2140. this.shadowTexelPadProjections[4 * d + 3] = Math.max(s[0] - r[0], s[1] - r[1])));
  2141. Matrix.mul(k, h, g);
  2142. Matrix.mul(k, u, k);
  2143. Matrix.copyToBuffer(this.modelViewBuffer, 16 * d, g);
  2144. Matrix.copyToBuffer(this.projectionBuffer, 16 * d, h);
  2145. Matrix.copyToBuffer(this.finalTransformBuffer, 16 * d, k);
  2146. Matrix.invert(k, k);
  2147. Matrix.copyToBuffer(this.inverseTransformBuffer, 16 * d, k)
  2148. }
  2149. e = !1;
  2150. for (d = 0; d < b.length; ++d)
  2151. if (b[d] != this.matrix[d]) {
  2152. e = !0;
  2153. break
  2154. }
  2155. for (d = 0; d < this.shadowCount; d++)
  2156. if (e && 1 == this.matrixWeights[d])
  2157. this.shadowsNeedUpdate[d] = 1;
  2158. else
  2159. for (b = 16 * d; b < 16 * d + 16; ++b)
  2160. if (f[b] != this.finalTransformBuffer[b]) {
  2161. this.shadowsNeedUpdate[d] = 1;
  2162. break
  2163. }
  2164. }
  2165. ;
  2166. Lights.prototype.flagUpdateAnimatedLighting = function() {
  2167. for (var a = 0; a < this.shadowCount; a++)
  2168. this.shadowsNeedUpdate[a] = 1
  2169. }
  2170. ;
  2171. function ListBox(a) {
  2172. this.name = "none";
  2173. this.text = "default text";
  2174. this.title = "none";
  2175. this.debugString = this.imagePath = "";
  2176. this.controlRect = new ControlRect(a);
  2177. this.textEntries = [];
  2178. this.textOffsetsX = [];
  2179. this.textOffsetsY = [];
  2180. this.buttons = [];
  2181. this.listBoxEntryHeight = 20;
  2182. this.selectedItemText = "";
  2183. this.selectedIndex = -1;
  2184. this.localPixelsY = 0;
  2185. this.localPixelsX = 100;
  2186. this.labelPixelDrop = 0;
  2187. this.labelPixelInset = 10;
  2188. this.labelTextHeight = 16;
  2189. this.closed = !1;
  2190. this.defaultButtonText = this.spacerMiddle = this.spacerRight = this.spacerLeft = this.spacerControl = 0;
  2191. this.listBoxButtons = [];
  2192. this.listBoxRegion = new GUIRegion(a);
  2193. this.guiScreen = a;
  2194. this.lastMouseOverIndex = -1;
  2195. this.selectionChangedCallback = 0;
  2196. this.debugString = ""
  2197. }
  2198. ListBox.prototype.linkControl = function(a) {
  2199. this.controlRect.linkControl(a)
  2200. }
  2201. ;
  2202. ListBox.prototype.spawnControl = function(a, c, b, d, e, f) {
  2203. var g = this.guiScreen.imageSetNumber
  2204. , h = "backgroundTopLE" + g + "x.png"
  2205. , k = "backgroundTopM" + g + "x.png"
  2206. , n = "backgroundTopRE" + g + "x.png"
  2207. , m = "backgroundMiddleLE" + g + "x.png"
  2208. , l = "backgroundMiddleM" + g + "x.png"
  2209. , p = "backgroundMiddleRE" + g + "x.png"
  2210. , r = "backgroundBottomLE" + g + "x.png"
  2211. , s = "backgroundBottomM" + g + "x.png"
  2212. , u = "backgroundBottomRE" + g + "x.png"
  2213. , q = 3 * g
  2214. , x = "backgroundLE" + g + "x.png"
  2215. , w = "backgroundM" + g + "x.png"
  2216. , v = "backgroundRE" + g + "x.png"
  2217. , t = 2 * g
  2218. , y = "spacerLE" + g + "x.png"
  2219. , E = "spacerM" + g + "x.png"
  2220. , F = "spacerRE" + g + "x.png"
  2221. , g = 2 * g
  2222. , A = this.controlRect.guiScreen.width
  2223. , B = this.controlRect.guiScreen.height;
  2224. if (e) {
  2225. e = this.textEntries.length;
  2226. var z = b;
  2227. for (b = 0; b < e; b++) {
  2228. var C = 8 * (this.textEntries[b] ? this.textEntries[b].length : 0);
  2229. z < C && (z = C)
  2230. }
  2231. b = z + f
  2232. }
  2233. e = this.textEntries.length + 1;
  2234. f = 1 / e;
  2235. this.localPixelsX = b;
  2236. this.listBoxEntryHeight = d;
  2237. this.localPixelsY = (this.textEntries.length + 1) * this.listBoxEntryHeight;
  2238. b = 8 / this.localPixelsY;
  2239. d = 6 / this.localPixelsX;
  2240. z = 4 / this.localPixelsX;
  2241. C = f - b / 4;
  2242. this.labelTextHeight = marmoset.largeUI ? 20 : 16;
  2243. this.labelPixelDrop = (this.listBoxEntryHeight - this.labelTextHeight) / 2;
  2244. this.listBoxRegion.controlRect.widthPercent = this.localPixelsX / A;
  2245. this.listBoxRegion.controlRect.heightPercent = this.localPixelsY / B;
  2246. this.listBoxRegion.controlRect.xPercent = a / A;
  2247. this.listBoxRegion.controlRect.yPercent = c / B;
  2248. this.openBackground = this.listBoxRegion.addTextButton("", 0, 0, 1, 1 + b, 1);
  2249. this.openBackground.setBackground3x3(this.listBoxRegion, 0, 0, h, k, n, m, l, p, r, s, u, q, q);
  2250. this.closedBackground = this.listBoxRegion.addTextButton("", 0, 0, 1, f, 1);
  2251. this.closedBackground.setBackground3x1(this.listBoxRegion, 0, 0, x, w, v, t);
  2252. a = this.labelPixelInset + this.textOffsetsX[0];
  2253. c = this.labelPixelDrop + this.textOffsetsY[0];
  2254. c /= this.localPixelsY;
  2255. a /= this.localPixelsX;
  2256. this.defaultButton = this.listBoxRegion.addTextButton("Selected", a, -c, 1, f, 0.5);
  2257. this.selectedIndex = 0;
  2258. this.defaultButton.controlRect.linkedControl.innerHTML = this.textEntries[this.selectedIndex];
  2259. this.defaultButton.linkedBackground = this.closedBackground;
  2260. this.spacerControl = this.listBoxRegion.addTextButton("", d, C, 1 - (d + z), b, 1);
  2261. this.spacerControl.defaultAlpha = 1;
  2262. this.spacerControl.setBackground3x1(this.listBoxRegion, 0, 0, y, E, F, g);
  2263. this.spacerControl.setVisible(!1);
  2264. this.spacerControl.linkedBackground = this.openBackground;
  2265. for (b = 1; b < e; b++)
  2266. a = this.labelPixelInset + this.textOffsetsX[b - 1],
  2267. c = this.labelPixelDrop + this.textOffsetsY[b - 1] - 4,
  2268. a /= this.localPixelsX,
  2269. c /= this.localPixelsY,
  2270. y = this.listBoxRegion.addTextButton(this.textEntries[b - 1], a, f * b - c, 1 - a, f, 0.5),
  2271. this.listBoxButtons.push(y),
  2272. y.linkedBackground = this.openBackground;
  2273. this.showList(!1);
  2274. this.setupCallbacks()
  2275. }
  2276. ;
  2277. ListBox.prototype.setControl = function(a, c, b, d, e, f) {
  2278. var g = this.controlRect.guiScreen.width
  2279. , h = this.controlRect.guiScreen.height;
  2280. if (e) {
  2281. e = this.textEntries.length;
  2282. for (var k = 0; k < e; k++) {
  2283. var n = 8 * (this.textEntries[k] ? this.textEntries[k].length : 0);
  2284. b < n && (b = n)
  2285. }
  2286. b += f
  2287. }
  2288. this.localPixelsX = b;
  2289. this.listBoxEntryHeight = d;
  2290. this.localPixelsY = (this.textEntries.length + 1) * this.listBoxEntryHeight;
  2291. this.listBoxRegion.controlRect.widthPercent = this.localPixelsX / g;
  2292. this.listBoxRegion.controlRect.heightPercent = this.localPixelsY / h;
  2293. this.listBoxRegion.controlRect.xPercent = a / g;
  2294. this.listBoxRegion.controlRect.yPercent = c / h;
  2295. this.listBoxRegion.controlRect.updateChildElements();
  2296. this.spacerControl.alignBackground();
  2297. this.openBackground.alignBackground();
  2298. this.closedBackground.alignBackground()
  2299. }
  2300. ;
  2301. ListBox.prototype.addItem = function(a, c, b) {
  2302. this.textEntries.push(a);
  2303. this.textOffsetsX.push(c);
  2304. this.textOffsetsY.push(b)
  2305. }
  2306. ;
  2307. ListBox.prototype.showList = function(a) {
  2308. for (var c = this.listBoxButtons.length, b = 0; b < c; b++)
  2309. this.listBoxButtons[b].setVisible(a);
  2310. this.closed = !a;
  2311. this.spacerControl && this.spacerControl.setVisible(a);
  2312. this.openBackground && this.openBackground.setVisible(a);
  2313. this.closedBackground && this.closedBackground.setVisible(!a);
  2314. a ? (this.defaultButton.linkedBackground = this.openBackground,
  2315. this.openBackground.setOpacity(1),
  2316. this.closedBackground.setOpacity(0.5)) : this.defaultButton.linkedBackground = this.closedBackground
  2317. }
  2318. ;
  2319. ListBox.prototype.selectItem = function(a) {
  2320. this.selectedItemText = this.textEntries[a];
  2321. this.selectedIndex = a;
  2322. this.defaultButton.controlRect.linkedControl.innerHTML = this.textEntries[this.selectedIndex];
  2323. a = (this.labelTextHeight - this.listBoxEntryHeight + 3) / this.localPixelsY;
  2324. this.defaultButton.controlRect.xPercent = (this.labelPixelInset + this.textOffsetsX[this.selectedIndex]) / this.localPixelsX;
  2325. this.defaultButton.controlRect.yPercent = a;
  2326. this.defaultButton.controlRect.updateElement()
  2327. }
  2328. ;
  2329. ListBox.prototype.setupCallbacks = function() {
  2330. var a = function(a) {
  2331. if (this.closed) {
  2332. var b = this.closedBackground.controlRect.linkedControl
  2333. , b = b.getBoundingClientRect()
  2334. , c = a.clientX - b.left;
  2335. a = a.clientY - b.top;
  2336. c /= b.width;
  2337. b = a / b.height;
  2338. 0 <= c && 1 >= c && 0 <= b && 1 >= b ? this.closedBackground.setOpacity(1) : this.closedBackground.setOpacity(0.5)
  2339. } else
  2340. b = this.openBackground.controlRect.linkedControl,
  2341. b = b.getBoundingClientRect(),
  2342. c = a.clientX - b.left,
  2343. a = a.clientY - b.top,
  2344. c /= b.width,
  2345. b = a / b.height,
  2346. 0 <= c && 1 >= c && 0 <= b && 1 >= b ? this.openBackground.setOpacity(1) : this.openBackground.setOpacity(0.5)
  2347. }
  2348. .bind(this);
  2349. this.defaultButton.controlRect.linkedControl.onclick = function() {
  2350. this.closed ? this.showList(!0) : (this.showList(this.closed),
  2351. this.closedBackground.setOpacity(1),
  2352. this.defaultButton.setOpacity(1))
  2353. }
  2354. .bind(this);
  2355. for (var c = function(a) {
  2356. this.selectItem(a.id);
  2357. this.showList(!1);
  2358. this.defaultButton.setOpacity(0.5);
  2359. this.selectionChangedCallback && this.selectionChangedCallback(this)
  2360. }
  2361. .bind(this), b = function(a) {
  2362. a = this.listBoxButtons.length;
  2363. for (var b = 0; b < a; b++)
  2364. this.listBoxButtons[b].controlRect.mouseOver && (this.selectItem(b),
  2365. b = a,
  2366. this.selectionChangedCallback && this.selectionChangedCallback(this));
  2367. this.showList(!1)
  2368. }
  2369. .bind(this), d = this.listBoxButtons.length, e = 0; e < d; e++)
  2370. this.listBoxButtons[e].controlRect.callBack = c,
  2371. this.listBoxButtons[e].controlRect.id = e,
  2372. this.listBoxButtons[e].controlRect.linkedControl.addEventListener("mousemove", a);
  2373. this.guiScreen.ui.viewer.input.element.addEventListener("mousemove", a);
  2374. this.openBackground.controlRect.linkedControl.addEventListener("mousemove", a);
  2375. this.closedBackground.controlRect.linkedControl.addEventListener("mousemove", a);
  2376. this.guiScreen.ui.viewer.input.element.addEventListener("mousedown", b)
  2377. }
  2378. ;
  2379. function Material(a, c, b) {
  2380. this.gl = a;
  2381. this.name = b.name;
  2382. var d = {
  2383. mipmap: !0,
  2384. aniso: a.hints.mobile ? 0 : 4,
  2385. clamp: !!b.textureWrapClamp,
  2386. mirror: !!b.textureWrapMirror
  2387. }
  2388. , e = {
  2389. mipmap: d.mipmap,
  2390. clamp: d.clamp,
  2391. mirror: d.mirror,
  2392. nofilter: b.textureFilterNearest || !1
  2393. };
  2394. e.nofilter || (e.aniso = a.hints.mobile ? 2 : 4);
  2395. this.textures = {
  2396. albedo: a.textureCache.fromFilesMergeAlpha(c.get(b.albedoTex), c.get(b.alphaTex), e),
  2397. reflectivity: a.textureCache.fromFilesMergeAlpha(c.get(b.reflectivityTex), c.get(b.glossTex), d),
  2398. normal: a.textureCache.fromFile(c.get(b.normalTex), d),
  2399. extras: a.textureCache.fromFilesMergeAlpha(c.get(b.extrasTex), c.get(b.extrasTexA), d)
  2400. };
  2401. this.extrasTexCoordRanges = {};
  2402. if (b.extrasTexCoordRanges)
  2403. for (var f in b.extrasTexCoordRanges)
  2404. this.extrasTexCoordRanges[f] = new Float32Array(b.extrasTexCoordRanges[f].scaleBias);
  2405. this.textures.extras || (c = new Texture(a,{
  2406. width: 1,
  2407. height: 1
  2408. }),
  2409. c.loadArray(new Uint8Array([255, 255, 255, 255])),
  2410. this.textures.extras = c);
  2411. var g = b.blendTint || [1, 1, 1];
  2412. c = {
  2413. none: function() {
  2414. a.disable(a.BLEND)
  2415. },
  2416. alpha: function() {
  2417. a.enable(a.BLEND);
  2418. a.blendFuncSeparate(a.SRC_ALPHA, a.ONE_MINUS_SRC_ALPHA, a.ONE_MINUS_DST_ALPHA, a.ONE)
  2419. },
  2420. add: function() {
  2421. a.enable(a.BLEND);
  2422. a.blendColor(g[0], g[1], g[2], 1);
  2423. a.blendFunc(a.ONE, a.CONSTANT_COLOR)
  2424. }
  2425. };
  2426. this.blend = c[b.blend] || c.none;
  2427. this.alphaTest = b.alphaTest || 0;
  2428. this.usesBlending = this.blend !== c.none;
  2429. this.usesRefraction = !!b.refraction;
  2430. this.shadowAlphaTest = this.alphaTest;
  2431. 0 >= this.shadowAlphaTest && this.blend === c.alpha && (this.shadowAlphaTest = 0.5);
  2432. this.castShadows = this.blend !== c.add;
  2433. this.horizonOcclude = b.horizonOcclude || 0;
  2434. this.fresnel = new Float32Array(b.fresnel ? b.fresnel : [1, 1, 1]);
  2435. this.emissiveIntensity = b.emissiveIntensity || 1;
  2436. d = [];
  2437. e = !1;
  2438. 0 < b.lightCount && d.push("#define LIGHT_COUNT " + b.lightCount);
  2439. 0 < b.shadowCount && (f = Math.min(b.lightCount, b.shadowCount),
  2440. this.usesRefraction && 8 >= a.limits.textureCount && (f = 2 < f ? 2 : f),
  2441. d.push("#define SHADOW_COUNT " + f));
  2442. 0 < b.alphaTest && d.push("#define ALPHA_TEST");
  2443. this.blend === c.alpha ? d.push("#define TRANSPARENCY_DITHER") : this.blend === c.none && d.push("#define NOBLEND");
  2444. a.hints.mobile && d.push("#define MOBILE");
  2445. a.ext.textureDepth && d.push("#define SHADOW_NATIVE_DEPTH");
  2446. f = function(a) {
  2447. return 1 / (2 / 3 * 3.1415962 * (a * a + a + 1))
  2448. }
  2449. ;
  2450. b.useSkin && (d.push("#define SKIN"),
  2451. this.skinParams = b.skinParams || {
  2452. subdermisColor: [1, 1, 1],
  2453. transColor: [1, 0, 0, 1],
  2454. fresnelColor: [0.2, 0.2, 0.2, 0.5],
  2455. fresnelOcc: 1,
  2456. fresnelGlossMask: 1,
  2457. transSky: 0.5,
  2458. shadowBlur: 0.5,
  2459. normalSmooth: 0.5,
  2460. transScatter: 0,
  2461. transDepth: 0,
  2462. millimeterScale: 1
  2463. },
  2464. this.extrasTexCoordRanges.subdermisTex || d.push("#define SKIN_NO_SUBDERMIS_TEX"),
  2465. this.extrasTexCoordRanges.translucencyTex || d.push("#define SKIN_NO_TRANSLUCENCY_TEX"),
  2466. this.extrasTexCoordRanges.fuzzTex || d.push("#define SKIN_NO_FUZZ_TEX"),
  2467. void 0 === this.skinParams.version && (this.skinParams.version = 1),
  2468. 2 == this.skinParams.version ? (d.push("#define SKIN_VERSION_2"),
  2469. this.skinParams.shadowBlur *= 4,
  2470. this.skinParams.shadowBlur = Math.min(this.skinParams.shadowBlur, 40),
  2471. this.skinParams.transIntegral = f(0.5 * this.skinParams.transScatter),
  2472. this.skinParams.fresnelIntegral = 1 / 3.14159 * (1 - 0.5 * this.skinParams.fresnelColor[3]),
  2473. this.skinParams.transSky = 0) : (d.push("#define SKIN_VERSION_1"),
  2474. this.skinParams.shadowBlur = 8 * Math.min(this.skinParams.shadowBlur, 1),
  2475. this.skinParams.transDepth = 0,
  2476. this.skinParams.transScatter = this.skinParams.transColor[3],
  2477. this.skinParams.transIntegral = 1 / 3.14159 * (1 - 0.5 * this.skinParams.transScatter),
  2478. this.skinParams.fresnelIntegral = 1 / 3.14159 * (1 - 0.5 * this.skinParams.fresnelColor[3]),
  2479. this.skinParams.transSky *= 1.25,
  2480. this.skinParams.transIntegral *= 1.25));
  2481. b.aniso && (d.push("#define ANISO"),
  2482. this.anisoParams = b.anisoParams || {
  2483. strength: 1,
  2484. tangent: [1, 0, 0],
  2485. integral: 0.5
  2486. },
  2487. this.extrasTexCoordRanges.anisoTex || d.push("#define ANISO_NO_DIR_TEX"));
  2488. b.microfiber && (d.push("#define MICROFIBER"),
  2489. this.microfiberParams = b.microfiberParams || {
  2490. fresnelColor: [0.2, 0.2, 0.2, 0.5],
  2491. fresnelOcc: 1,
  2492. fresnelGlossMask: 1
  2493. },
  2494. this.microfiberParams.fresnelIntegral = 1 / 3.14159 * (1 - 0.5 * this.microfiberParams.fresnelColor[3]),
  2495. this.extrasTexCoordRanges.fuzzTex || d.push("#define MICROFIBER_NO_FUZZ_TEX"));
  2496. b.refraction && (d.push("#define REFRACTION"),
  2497. this.refractionParams = b.refractionParams || {
  2498. distantBackground: !1,
  2499. tint: [1, 1, 1],
  2500. useAlbedoTint: !1,
  2501. IOR: 1.5
  2502. },
  2503. this.extrasTexCoordRanges.refractionMaskTex || d.push("#define REFRACTION_NO_MASK_TEX"));
  2504. b.vertexColor && (d.push("#define VERTEX_COLOR"),
  2505. b.vertexColorsRGB && d.push("#define VERTEX_COLOR_SRGB"),
  2506. b.vertexColorAlpha && d.push("#define VERTEX_COLOR_ALPHA"));
  2507. this.horizonSmoothing = b.horizonSmoothing || 0;
  2508. 0 < this.horizonSmoothing && d.push("#define HORIZON_SMOOTHING");
  2509. b.unlitDiffuse && d.push("#define DIFFUSE_UNLIT");
  2510. this.extrasTexCoordRanges.emissiveTex && (d.push("#define EMISSIVE"),
  2511. b.emissiveSecondaryUV && (d.push("#define EMISSIVE_SECONDARY_UV"),
  2512. e = !0));
  2513. this.extrasTexCoordRanges.aoTex && (d.push("#define AMBIENT_OCCLUSION"),
  2514. b.aoSecondaryUV && (d.push("#define AMBIENT_OCCLUSION_SECONDARY_UV"),
  2515. e = !0));
  2516. b.tangentOrthogonalize && d.push("#define TSPACE_ORTHOGONALIZE");
  2517. b.tangentNormalize && d.push("#define TSPACE_RENORMALIZE");
  2518. b.tangentGenerateBitangent && d.push("#define TSPACE_COMPUTE_BITANGENT");
  2519. e && d.push("#define TEXCOORD_SECONDARY");
  2520. this.vOffset = this.uOffset = 0;
  2521. d.push("#define UV_OFFSET ");
  2522. this.shader = a.shaderCache.fromURLs("matvert.glsl", "matfrag.glsl", d);
  2523. d.push("#define STRIPVIEW");
  2524. this.stripShader = a.shaderCache.fromURLs("matvert.glsl", "matfrag.glsl", d);
  2525. this.wireShader = a.shaderCache.fromURLs("wirevert.glsl", "wirefrag.glsl");
  2526. this.blend === c.alpha && (this.prepassShader = a.shaderCache.fromURLs("alphaprepassvert.glsl", "alphaprepassfrag.glsl"))
  2527. }
  2528. Material.prototype.bind = function(a, c) {
  2529. if (!this.complete())
  2530. return !1;
  2531. var b = a.view, d = a.lights, e = a.sky, f = a.shadow, g = a.stripData.active() ? this.stripShader : this.shader, h = this.skinParams, k = this.anisoParams, n = this.microfiberParams, m, l = this.gl, p = g.params, r = this.textures, s = g.samplers;
  2532. g.bind();
  2533. this.blend();
  2534. var u = c.mesh.displayMatrix
  2535. , q = Matrix.mul(Matrix.empty(), b.viewMatrix, u)
  2536. , x = Matrix.mul(Matrix.empty(), b.projectionMatrix, b.viewMatrix)
  2537. , q = Matrix.mul(Matrix.empty(), b.projectionMatrix, q)
  2538. , u = Matrix.mul(Matrix.empty(), d.matrix, u);
  2539. l.uniformMatrix4fv(p.uModelViewProjectionMatrix, !1, q);
  2540. l.uniformMatrix4fv(p.uSkyMatrix, !1, u);
  2541. u = Matrix.mulPoint(Vect.empty(), d.matrix, b.transform[12], b.transform[13], b.transform[14]);
  2542. l.uniform3f(p.uCameraPosition, u[0], u[1], u[2]);
  2543. l.uniform3fv(p.uFresnel, this.fresnel);
  2544. l.uniform1f(p.uAlphaTest, this.alphaTest);
  2545. l.uniform1f(p.uHorizonOcclude, this.horizonOcclude);
  2546. l.uniform1f(p.uHorizonSmoothing, this.horizonSmoothing);
  2547. l.uniform4fv(p.uDiffuseCoefficients, e.diffuseCoefficients);
  2548. 0 < d.count && (l.uniform4fv(p.uLightPositions, d.positionBuffer),
  2549. l.uniform3fv(p.uLightDirections, d.directionBuffer),
  2550. l.uniform3fv(p.uLightColors, d.colors),
  2551. l.uniform3fv(p.uLightParams, d.parameters),
  2552. l.uniform3fv(p.uLightSpot, d.spot),
  2553. u = 0.392699 * a.postRender.currentSample(),
  2554. l.uniform2f(p.uShadowKernelRotation, 0.5 * Math.cos(u), 0.5 * Math.sin(u)),
  2555. 0 < d.shadowCount && (u = f.depthTextures[0].desc.width,
  2556. l.uniform2f(p.uShadowMapSize, u, 1 / u),
  2557. l.uniformMatrix4fv(p.uShadowMatrices, !1, d.finalTransformBuffer),
  2558. l.uniformMatrix4fv(p.uInvShadowMatrices, !1, d.inverseTransformBuffer),
  2559. l.uniform4fv(p.uShadowTexelPadProjections, d.shadowTexelPadProjections),
  2560. f.bindDepthTexture(s.tDepth0, 0),
  2561. f.bindDepthTexture(s.tDepth1, 1),
  2562. f.bindDepthTexture(s.tDepth2, 2)));
  2563. h && (l.uniform3fv(p.uSubdermisColor, h.subdermisColor),
  2564. l.uniform4fv(p.uTransColor, h.transColor),
  2565. l.uniform1f(p.uTransScatter, h.transScatter),
  2566. l.uniform4fv(p.uFresnelColor, h.fresnelColor),
  2567. l.uniform1f(p.uFresnelOcc, h.fresnelOcc),
  2568. l.uniform1f(p.uFresnelGlossMask, h.fresnelGlossMask),
  2569. l.uniform1f(p.uFresnelIntegral, h.fresnelIntegral),
  2570. l.uniform1f(p.uTransIntegral, h.transIntegral),
  2571. l.uniform1f(p.uSkinTransDepth, h.transDepth),
  2572. l.uniform1f(p.uTransSky, h.transSky),
  2573. l.uniform1f(p.uSkinShadowBlur, h.shadowBlur),
  2574. l.uniform1f(p.uNormalSmooth, h.normalSmooth),
  2575. (m = this.extrasTexCoordRanges.subdermisTex) && l.uniform4fv(p.uTexRangeSubdermis, m),
  2576. (m = this.extrasTexCoordRanges.translucencyTex) && l.uniform4fv(p.uTexRangeTranslucency, m),
  2577. (m = this.extrasTexCoordRanges.fuzzTex) && l.uniform4fv(p.uTexRangeFuzz, m));
  2578. n && (l.uniform4fv(p.uFresnelColor, n.fresnelColor),
  2579. l.uniform1f(p.uFresnelOcc, n.fresnelOcc),
  2580. l.uniform1f(p.uFresnelGlossMask, n.fresnelGlossMask),
  2581. l.uniform1f(p.uFresnelIntegral, n.fresnelIntegral),
  2582. (m = this.extrasTexCoordRanges.fuzzTex) && l.uniform4fv(p.uTexRangeFuzz, m));
  2583. k && (l.uniform3fv(p.uAnisoTangent, k.tangent),
  2584. l.uniform1f(p.uAnisoStrength, k.strength),
  2585. l.uniform1f(p.uAnisoIntegral, k.integral),
  2586. (m = this.extrasTexCoordRanges.anisoTex) && l.uniform4fv(p.uTexRangeAniso, m));
  2587. this.usesRefraction && (a.refractionSurface && a.refractionSurface.bind(s.tRefraction),
  2588. d = Matrix.mul(Matrix.empty(), x, d.invMatrix),
  2589. l.uniformMatrix4fv(p.uRefractionViewProjection, !1, d),
  2590. l.uniform1f(p.uRefractionRayDistance, this.refractionParams.distantBackground ? 1E10 : 4 * c.mesh.bounds.maxExtent),
  2591. l.uniform3fv(p.uRefractionTint, this.refractionParams.tint),
  2592. l.uniform1f(p.uRefractionAlbedoTint, this.refractionParams.useAlbedoTint ? 1 : 0),
  2593. l.uniform1f(p.uRefractionIOREntry, 1 / this.refractionParams.IOR),
  2594. (m = this.extrasTexCoordRanges.refractionMaskTex) && l.uniform4fv(p.uTexRangeRefraction, m));
  2595. if (m = this.extrasTexCoordRanges.emissiveTex)
  2596. l.uniform4fv(p.uTexRangeEmissive, m),
  2597. l.uniform1f(p.uEmissiveScale, this.emissiveIntensity);
  2598. (m = this.extrasTexCoordRanges.aoTex) && l.uniform4fv(p.uTexRangeAO, m);
  2599. r.albedo.bind(s.tAlbedo);
  2600. r.reflectivity.bind(s.tReflectivity);
  2601. r.normal.bind(s.tNormal);
  2602. r.extras.bind(s.tExtras);
  2603. e.specularTexture.bind(s.tSkySpecular);
  2604. g === this.stripShader && (l.uniform1fv(p.uStrips, a.stripData.strips),
  2605. l.uniform2f(p.uStripRes, 2 / b.size[0], 2 / b.size[1]));
  2606. l.uniform2f(p.uUVOffset, this.uOffset, this.vOffset);
  2607. return !0
  2608. }
  2609. ;
  2610. Material.prototype.bindAlphaPrepass = function(a, c) {
  2611. if (!this.complete() || !this.prepassShader)
  2612. return !1;
  2613. var b = this.gl
  2614. , d = this.prepassShader.params
  2615. , e = this.prepassShader.samplers;
  2616. this.prepassShader.bind();
  2617. var f = Matrix.mul(Matrix.empty(), a.view.viewMatrix, c.mesh.displayMatrix)
  2618. , f = Matrix.mul(Matrix.empty(), a.view.projectionMatrix, f);
  2619. b.uniformMatrix4fv(d.uModelViewProjectionMatrix, !1, f);
  2620. b.uniform2f(d.uUVOffset, this.uOffset, this.vOffset);
  2621. this.textures.albedo.bind(e.tAlbedo);
  2622. return !0
  2623. }
  2624. ;
  2625. Material.prototype.bindWire = function(a, c) {
  2626. if (!this.complete())
  2627. return !1;
  2628. var b = this.gl
  2629. , d = this.wireShader.params
  2630. , e = a.view;
  2631. b.enable(b.BLEND);
  2632. b.blendFunc(b.SRC_ALPHA, b.ONE_MINUS_SRC_ALPHA);
  2633. b.depthMask(!1);
  2634. this.wireShader.bind();
  2635. var f = Matrix.mul(Matrix.empty(), a.view.viewMatrix, c.mesh.displayMatrix)
  2636. , f = Matrix.mul(Matrix.empty(), a.view.projectionMatrix, f);
  2637. b.uniformMatrix4fv(d.uModelViewProjectionMatrix, !1, f);
  2638. b.uniform4f(d.uStripParams, 2 / e.size[0], 2 / e.size[1], a.stripData.strips[3], a.stripData.strips[4]);
  2639. return !0
  2640. }
  2641. ;
  2642. Material.prototype.complete = function() {
  2643. return this.wireShader.complete() && this.shader.complete() && this.stripShader.complete() && (!this.prepassShader || this.prepassShader.complete()) && (!this.refractionShader || this.refractionShader.complete()) && this.textures.albedo.complete() && this.textures.reflectivity.complete() && this.textures.normal.complete()
  2644. }
  2645. ;
  2646. var Matrix = {
  2647. type: Float32Array,
  2648. create: function(a, c, b, d, e, f, g, h, k, n, m, l, p, r, s, u) {
  2649. var q = new Matrix.type(16);
  2650. q[0] = a;
  2651. q[4] = c;
  2652. q[8] = b;
  2653. q[12] = d;
  2654. q[1] = e;
  2655. q[5] = f;
  2656. q[9] = g;
  2657. q[13] = h;
  2658. q[2] = k;
  2659. q[6] = n;
  2660. q[10] = m;
  2661. q[14] = l;
  2662. q[3] = p;
  2663. q[7] = r;
  2664. q[11] = s;
  2665. q[15] = u;
  2666. return q
  2667. },
  2668. empty: function() {
  2669. return new Matrix.type(16)
  2670. },
  2671. identity: function() {
  2672. var a = new Matrix.type(16);
  2673. a[0] = 1;
  2674. a[4] = 0;
  2675. a[8] = 0;
  2676. a[12] = 0;
  2677. a[1] = 0;
  2678. a[5] = 1;
  2679. a[9] = 0;
  2680. a[13] = 0;
  2681. a[2] = 0;
  2682. a[6] = 0;
  2683. a[10] = 1;
  2684. a[14] = 0;
  2685. a[3] = 0;
  2686. a[7] = 0;
  2687. a[11] = 0;
  2688. a[15] = 1;
  2689. return a
  2690. },
  2691. set: function(a, c, b, d, e, f, g, h, k, n, m, l, p, r, s, u, q) {
  2692. a[0] = c;
  2693. a[4] = b;
  2694. a[8] = d;
  2695. a[12] = e;
  2696. a[1] = f;
  2697. a[5] = g;
  2698. a[9] = h;
  2699. a[13] = k;
  2700. a[2] = n;
  2701. a[6] = m;
  2702. a[10] = l;
  2703. a[14] = p;
  2704. a[3] = r;
  2705. a[7] = s;
  2706. a[11] = u;
  2707. a[15] = q
  2708. },
  2709. translation: function(a, c, b, d) {
  2710. Matrix.set(a, 1, 0, 0, c, 0, 1, 0, b, 0, 0, 1, d, 0, 0, 0, 1);
  2711. return a
  2712. },
  2713. rotation: function(a, c, b) {
  2714. a[0] = 1;
  2715. a[4] = 0;
  2716. a[8] = 0;
  2717. a[12] = 0;
  2718. a[1] = 0;
  2719. a[5] = 1;
  2720. a[9] = 0;
  2721. a[13] = 0;
  2722. a[2] = 0;
  2723. a[6] = 0;
  2724. a[10] = 1;
  2725. a[14] = 0;
  2726. a[3] = 0;
  2727. a[7] = 0;
  2728. a[11] = 0;
  2729. a[15] = 1;
  2730. var d = 0.0174532925 * c;
  2731. c = Math.sin(d);
  2732. d = Math.cos(d);
  2733. switch (b) {
  2734. case 0:
  2735. a[5] = d;
  2736. a[9] = -c;
  2737. a[6] = c;
  2738. a[10] = d;
  2739. break;
  2740. case 1:
  2741. a[0] = d;
  2742. a[8] = c;
  2743. a[2] = -c;
  2744. a[10] = d;
  2745. break;
  2746. case 2:
  2747. a[0] = d,
  2748. a[4] = -c,
  2749. a[1] = c,
  2750. a[5] = d
  2751. }
  2752. return a
  2753. },
  2754. mul: function(a, c, b) {
  2755. var d = c[0]
  2756. , e = c[1]
  2757. , f = c[2]
  2758. , g = c[3]
  2759. , h = c[4]
  2760. , k = c[5]
  2761. , n = c[6]
  2762. , m = c[7]
  2763. , l = c[8]
  2764. , p = c[9]
  2765. , r = c[10]
  2766. , s = c[11]
  2767. , u = c[12]
  2768. , q = c[13]
  2769. , x = c[14];
  2770. c = c[15];
  2771. var w = b[0]
  2772. , v = b[1]
  2773. , t = b[2]
  2774. , y = b[3];
  2775. a[0] = w * d + v * h + t * l + y * u;
  2776. a[1] = w * e + v * k + t * p + y * q;
  2777. a[2] = w * f + v * n + t * r + y * x;
  2778. a[3] = w * g + v * m + t * s + y * c;
  2779. w = b[4];
  2780. v = b[5];
  2781. t = b[6];
  2782. y = b[7];
  2783. a[4] = w * d + v * h + t * l + y * u;
  2784. a[5] = w * e + v * k + t * p + y * q;
  2785. a[6] = w * f + v * n + t * r + y * x;
  2786. a[7] = w * g + v * m + t * s + y * c;
  2787. w = b[8];
  2788. v = b[9];
  2789. t = b[10];
  2790. y = b[11];
  2791. a[8] = w * d + v * h + t * l + y * u;
  2792. a[9] = w * e + v * k + t * p + y * q;
  2793. a[10] = w * f + v * n + t * r + y * x;
  2794. a[11] = w * g + v * m + t * s + y * c;
  2795. w = b[12];
  2796. v = b[13];
  2797. t = b[14];
  2798. y = b[15];
  2799. a[12] = w * d + v * h + t * l + y * u;
  2800. a[13] = w * e + v * k + t * p + y * q;
  2801. a[14] = w * f + v * n + t * r + y * x;
  2802. a[15] = w * g + v * m + t * s + y * c;
  2803. return a
  2804. },
  2805. invert: function(a, c) {
  2806. var b = c[0]
  2807. , d = c[1]
  2808. , e = c[2]
  2809. , f = c[3]
  2810. , g = c[4]
  2811. , h = c[5]
  2812. , k = c[6]
  2813. , n = c[7]
  2814. , m = c[8]
  2815. , l = c[9]
  2816. , p = c[10]
  2817. , r = c[11]
  2818. , s = c[12]
  2819. , u = c[13]
  2820. , q = c[14]
  2821. , x = c[15]
  2822. , w = b * h - d * g
  2823. , v = b * k - e * g
  2824. , t = b * n - f * g
  2825. , y = d * k - e * h
  2826. , E = d * n - f * h
  2827. , F = e * n - f * k
  2828. , A = m * u - l * s
  2829. , B = m * q - p * s
  2830. , z = m * x - r * s
  2831. , C = l * q - p * u
  2832. , G = l * x - r * u
  2833. , H = p * x - r * q
  2834. , D = w * H - v * G + t * C + y * z - E * B + F * A;
  2835. if (!D)
  2836. return null;
  2837. D = 1 / D;
  2838. a[0] = (h * H - k * G + n * C) * D;
  2839. a[1] = (e * G - d * H - f * C) * D;
  2840. a[2] = (u * F - q * E + x * y) * D;
  2841. a[3] = (p * E - l * F - r * y) * D;
  2842. a[4] = (k * z - g * H - n * B) * D;
  2843. a[5] = (b * H - e * z + f * B) * D;
  2844. a[6] = (q * t - s * F - x * v) * D;
  2845. a[7] = (m * F - p * t + r * v) * D;
  2846. a[8] = (g * G - h * z + n * A) * D;
  2847. a[9] = (d * z - b * G - f * A) * D;
  2848. a[10] = (s * E - u * t + x * w) * D;
  2849. a[11] = (l * t - m * E - r * w) * D;
  2850. a[12] = (h * B - g * C - k * A) * D;
  2851. a[13] = (b * C - d * B + e * A) * D;
  2852. a[14] = (u * v - s * y - q * w) * D;
  2853. a[15] = (m * y - l * v + p * w) * D;
  2854. return a
  2855. },
  2856. transpose: function(a, c) {
  2857. a[0] = c[0];
  2858. a[4] = c[1];
  2859. a[8] = c[2];
  2860. a[12] = c[3];
  2861. a[1] = c[4];
  2862. a[5] = c[5];
  2863. a[9] = c[6];
  2864. a[13] = c[7];
  2865. a[2] = c[8];
  2866. a[6] = c[9];
  2867. a[10] = c[10];
  2868. a[14] = c[11];
  2869. a[3] = c[12];
  2870. a[7] = c[13];
  2871. a[11] = c[14];
  2872. a[15] = c[15];
  2873. return a
  2874. },
  2875. mul4: function(a, c, b, d, e, f) {
  2876. a[0] = c[0] * b + c[4] * d + c[8] * e + c[12] * f;
  2877. a[1] = c[1] * b + c[5] * d + c[9] * e + c[13] * f;
  2878. a[2] = c[2] * b + c[6] * d + c[10] * e + c[14] * f;
  2879. a[3] = c[3] * b + c[7] * d + c[11] * e + c[15] * f;
  2880. return a
  2881. },
  2882. mulPoint: function(a, c, b, d, e) {
  2883. a[0] = c[0] * b + c[4] * d + c[8] * e + c[12];
  2884. a[1] = c[1] * b + c[5] * d + c[9] * e + c[13];
  2885. a[2] = c[2] * b + c[6] * d + c[10] * e + c[14];
  2886. return a
  2887. },
  2888. mulVec: function(a, c, b, d, e) {
  2889. a[0] = c[0] * b + c[4] * d + c[8] * e;
  2890. a[1] = c[1] * b + c[5] * d + c[9] * e;
  2891. a[2] = c[2] * b + c[6] * d + c[10] * e;
  2892. return a
  2893. },
  2894. perspective: function(a, c, b, d, e, f) {
  2895. f = f || 0;
  2896. c = 1 / Math.tan(0.00872664625 * c);
  2897. a[0] = c / b;
  2898. a[1] = a[2] = a[3] = 0;
  2899. a[5] = c;
  2900. a[4] = a[6] = a[7] = 0;
  2901. a[8] = a[9] = 0;
  2902. a[10] = (e + d) / (d - e) - 3.0518044E-5 * f;
  2903. a[11] = -1;
  2904. a[14] = 2 * e * d / (d - e);
  2905. a[12] = a[13] = a[15] = 0;
  2906. return a
  2907. },
  2908. perspectiveInfinite: function(a, c, b, d, e) {
  2909. e = e || 0;
  2910. c = 1 / Math.tan(0.00872664625 * c);
  2911. a[0] = c / b;
  2912. a[1] = a[2] = a[3] = 0;
  2913. a[5] = c;
  2914. a[4] = a[6] = a[7] = 0;
  2915. a[8] = a[9] = 0;
  2916. a[10] = a[11] = -1 - 3.0518044E-5 * e;
  2917. a[14] = -2 * d;
  2918. a[12] = a[13] = a[15] = 0;
  2919. return a
  2920. },
  2921. ortho: function(a, c, b, d, e, f, g, h) {
  2922. var k = 1 / (b - c)
  2923. , n = 1 / (e - d)
  2924. , m = 1 / (g - f);
  2925. a[0] = k + k;
  2926. a[1] = a[2] = a[3] = 0;
  2927. a[5] = n + n;
  2928. a[4] = a[6] = a[7] = 0;
  2929. a[12] = -(b + c) * k;
  2930. a[13] = -(e + d) * n;
  2931. a[10] = -(m + m) - 3.0518044E-5 * (h || 0);
  2932. a[14] = -(g + f) * m;
  2933. a[8] = a[9] = a[11] = 0;
  2934. a[15] = 1;
  2935. return a
  2936. },
  2937. lookAt: function(a, c, b, d) {
  2938. var e = a.subarray(0, 3)
  2939. , f = a.subarray(4, 7)
  2940. , g = a.subarray(8, 11);
  2941. Vect.sub(g, c, b);
  2942. Vect.cross(e, d, g);
  2943. Vect.normalize(g, g);
  2944. Vect.normalize(e, e);
  2945. Vect.cross(f, g, e);
  2946. Matrix.set(a, e[0], e[1], e[2], -Vect.dot(e, c), f[0], f[1], f[2], -Vect.dot(f, c), g[0], g[1], g[2], -Vect.dot(g, c), 0, 0, 0, 1)
  2947. },
  2948. copy: function(a, c) {
  2949. for (var b = 0; 16 > b; ++b)
  2950. a[b] = c[b]
  2951. },
  2952. copyToBuffer: function(a, c, b) {
  2953. for (var d = 0; 16 > d; ++d)
  2954. a[c + d] = b[d]
  2955. }
  2956. };
  2957. function Mesh(a, c, b) {
  2958. this.gl = a;
  2959. this.desc = c;
  2960. var d = c.isDynamicMesh;
  2961. this.numSubMeshes = this.dynamicVertexData = 0;
  2962. this.displayMatrix = Matrix.identity();
  2963. this.name = c.name;
  2964. this.modelMatrix = Matrix.identity();
  2965. this.origin = c.transform ? Vect.create(c.transform[12], c.transform[13], c.transform[14], 1) : Vect.create(0, 5, 0, 1);
  2966. this.stride = 32;
  2967. if (this.vertexColor = c.vertexColor)
  2968. this.stride += 4;
  2969. if (this.secondaryTexCoord = c.secondaryTexCoord)
  2970. this.stride += 8;
  2971. b = new ByteStream(b.data);
  2972. this.indexCount = c.indexCount;
  2973. this.indexTypeSize = c.indexTypeSize;
  2974. this.indexType = 4 == this.indexTypeSize ? a.UNSIGNED_INT : a.UNSIGNED_SHORT;
  2975. this.indexBuffer = a.createBuffer();
  2976. a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
  2977. var e = b.readBytes(this.indexCount * this.indexTypeSize);
  2978. a.bufferData(a.ELEMENT_ARRAY_BUFFER, e, a.STATIC_DRAW);
  2979. this.wireCount = c.wireCount;
  2980. this.wireBuffer = a.createBuffer();
  2981. a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, this.wireBuffer);
  2982. e = b.readBytes(this.wireCount * this.indexTypeSize);
  2983. a.bufferData(a.ELEMENT_ARRAY_BUFFER, e, a.STATIC_DRAW);
  2984. a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, null);
  2985. this.vertexCount = c.vertexCount;
  2986. this.vertexBuffer = a.createBuffer();
  2987. a.bindBuffer(a.ARRAY_BUFFER, this.vertexBuffer);
  2988. b = b.readBytes(this.vertexCount * this.stride);
  2989. d ? (this.dynamicVertexData = new Uint8Array(b),
  2990. a.bufferData(a.ARRAY_BUFFER, b, a.DYNAMIC_DRAW)) : a.bufferData(a.ARRAY_BUFFER, b, a.STATIC_DRAW);
  2991. a.bindBuffer(a.ARRAY_BUFFER, null);
  2992. this.bounds = void 0 === c.minBound || void 0 === c.maxBound ? {
  2993. min: Vect.create(-10, -10, -10, 1),
  2994. max: Vect.create(10, 10, -0, 1)
  2995. } : {
  2996. min: Vect.create(c.minBound[0], c.minBound[1], c.minBound[2], 1),
  2997. max: Vect.create(c.maxBound[0], c.maxBound[1], c.maxBound[2], 1)
  2998. };
  2999. this.bounds.maxExtent = Math.max(Math.max(c.maxBound[0] - c.minBound[0], c.maxBound[1] - c.minBound[1]), c.maxBound[2] - c.minBound[2]);
  3000. this.bounds.averageExtent = (c.maxBound[0] - c.minBound[0] + (c.maxBound[1] - c.minBound[1]) + (c.maxBound[2] - c.minBound[2])) / 3
  3001. }
  3002. ;function MeshRenderable(a, c, b) {
  3003. this.mesh = a;
  3004. this.gl = this.mesh.gl;
  3005. this.indexOffset = c.firstIndex * a.indexTypeSize;
  3006. this.indexCount = c.indexCount;
  3007. this.wireIndexOffset = c.firstWireIndex * a.indexTypeSize;
  3008. this.wireIndexCount = c.wireIndexCount;
  3009. this.material = b;
  3010. this.visible = !0
  3011. }
  3012. MeshRenderable.prototype.draw = function(a) {
  3013. var c = this.gl;
  3014. if (this.material.bind(a, this)) {
  3015. a = this.material.shader.attribs;
  3016. var b = this.mesh.stride;
  3017. this.mesh.desc.cullBackFaces ? (c.enable(c.CULL_FACE),
  3018. c.cullFace(c.BACK)) : c.disable(c.CULL_FACE);
  3019. c.bindBuffer(c.ELEMENT_ARRAY_BUFFER, this.mesh.indexBuffer);
  3020. c.bindBuffer(c.ARRAY_BUFFER, this.mesh.vertexBuffer);
  3021. c.enableVertexAttribArray(a.vPosition);
  3022. c.enableVertexAttribArray(a.vTexCoord);
  3023. c.enableVertexAttribArray(a.vTangent);
  3024. c.enableVertexAttribArray(a.vBitangent);
  3025. c.enableVertexAttribArray(a.vNormal);
  3026. var d = this.mesh.vertexColor && void 0 !== a.vColor;
  3027. d && c.enableVertexAttribArray(a.vColor);
  3028. var e = this.mesh.secondaryTexCoord && void 0 !== a.vTexCoord2;
  3029. e && c.enableVertexAttribArray(a.vTexCoord2);
  3030. var f = 0;
  3031. c.vertexAttribPointer(a.vPosition, 3, c.FLOAT, !1, b, f);
  3032. f += 12;
  3033. c.vertexAttribPointer(a.vTexCoord, 2, c.FLOAT, !1, b, f);
  3034. f += 8;
  3035. this.mesh.secondaryTexCoord && (e && c.vertexAttribPointer(a.vTexCoord2, 2, c.FLOAT, !1, b, f),
  3036. f += 8);
  3037. c.vertexAttribPointer(a.vTangent, 2, c.UNSIGNED_SHORT, !0, b, f);
  3038. f += 4;
  3039. c.vertexAttribPointer(a.vBitangent, 2, c.UNSIGNED_SHORT, !0, b, f);
  3040. f += 4;
  3041. c.vertexAttribPointer(a.vNormal, 2, c.UNSIGNED_SHORT, !0, b, f);
  3042. d && c.vertexAttribPointer(a.vColor, 4, c.UNSIGNED_BYTE, !0, b, f + 4);
  3043. c.drawElements(c.TRIANGLES, this.indexCount, this.mesh.indexType, this.indexOffset);
  3044. c.disableVertexAttribArray(a.vPosition);
  3045. c.disableVertexAttribArray(a.vTexCoord);
  3046. c.disableVertexAttribArray(a.vTangent);
  3047. c.disableVertexAttribArray(a.vBitangent);
  3048. c.disableVertexAttribArray(a.vNormal);
  3049. d && c.disableVertexAttribArray(a.vColor);
  3050. e && c.disableVertexAttribArray(a.vTexCoord2)
  3051. }
  3052. }
  3053. ;
  3054. MeshRenderable.prototype.drawShadow = function(a) {
  3055. var c = this.gl;
  3056. this.mesh.desc.cullBackFaces ? (c.enable(c.CULL_FACE),
  3057. c.cullFace(c.BACK)) : c.disable(c.CULL_FACE);
  3058. c.bindBuffer(c.ELEMENT_ARRAY_BUFFER, this.mesh.indexBuffer);
  3059. c.bindBuffer(c.ARRAY_BUFFER, this.mesh.vertexBuffer);
  3060. c.enableVertexAttribArray(a);
  3061. c.vertexAttribPointer(a, 3, c.FLOAT, !1, this.mesh.stride, 0);
  3062. c.drawElements(c.TRIANGLES, this.indexCount, this.mesh.indexType, this.indexOffset);
  3063. c.disableVertexAttribArray(a)
  3064. }
  3065. ;
  3066. MeshRenderable.prototype.drawAlphaShadow = function(a, c) {
  3067. var b = this.gl;
  3068. this.mesh.desc.cullBackFaces ? (b.enable(b.CULL_FACE),
  3069. b.cullFace(b.BACK)) : b.disable(b.CULL_FACE);
  3070. b.bindBuffer(b.ELEMENT_ARRAY_BUFFER, this.mesh.indexBuffer);
  3071. b.bindBuffer(b.ARRAY_BUFFER, this.mesh.vertexBuffer);
  3072. b.enableVertexAttribArray(a);
  3073. b.enableVertexAttribArray(c);
  3074. b.vertexAttribPointer(a, 3, b.FLOAT, !1, this.mesh.stride, 0);
  3075. b.vertexAttribPointer(c, 2, b.FLOAT, !1, this.mesh.stride, 12);
  3076. b.drawElements(b.TRIANGLES, this.indexCount, this.mesh.indexType, this.indexOffset);
  3077. b.disableVertexAttribArray(a);
  3078. b.disableVertexAttribArray(c)
  3079. }
  3080. ;
  3081. MeshRenderable.prototype.drawAlphaPrepass = function(a) {
  3082. var c = this.gl;
  3083. if (this.material.bindAlphaPrepass(a, this)) {
  3084. a = this.material.prepassShader.attribs;
  3085. var b = this.mesh.stride;
  3086. this.mesh.desc.cullBackFaces ? (c.enable(c.CULL_FACE),
  3087. c.cullFace(c.BACK)) : c.disable(c.CULL_FACE);
  3088. c.bindBuffer(c.ELEMENT_ARRAY_BUFFER, this.mesh.indexBuffer);
  3089. c.bindBuffer(c.ARRAY_BUFFER, this.mesh.vertexBuffer);
  3090. c.enableVertexAttribArray(a.vPosition);
  3091. c.enableVertexAttribArray(a.vTexCoord);
  3092. c.vertexAttribPointer(a.vPosition, 3, c.FLOAT, !1, b, 0);
  3093. c.vertexAttribPointer(a.vTexCoord, 2, c.FLOAT, !1, b, 12);
  3094. c.drawElements(c.TRIANGLES, this.indexCount, this.mesh.indexType, this.indexOffset);
  3095. c.disableVertexAttribArray(a.vPosition);
  3096. c.disableVertexAttribArray(a.vTexCoord)
  3097. }
  3098. }
  3099. ;
  3100. MeshRenderable.prototype.drawWire = function(a) {
  3101. var c = this.material.wireShader.attribs
  3102. , b = this.gl;
  3103. this.material.bindWire(a, this) && (b.enableVertexAttribArray(c.vPosition),
  3104. b.bindBuffer(b.ELEMENT_ARRAY_BUFFER, this.mesh.wireBuffer),
  3105. b.bindBuffer(b.ARRAY_BUFFER, this.mesh.vertexBuffer),
  3106. b.vertexAttribPointer(c.vPosition, 3, b.FLOAT, !1, this.mesh.stride, 0),
  3107. b.drawElements(b.LINES, this.wireIndexCount, this.mesh.indexType, this.wireIndexOffset),
  3108. b.disableVertexAttribArray(c.vPosition))
  3109. }
  3110. ;
  3111. MeshRenderable.prototype.complete = function() {
  3112. return this.material.complete()
  3113. }
  3114. ;
  3115. var Network = {
  3116. fetchImage: function(a, c, b) {
  3117. var d = new Image;
  3118. d.crossOrigin = "Anonymous";
  3119. d.onload = function() {
  3120. 0 < d.width && 0 < d.height ? c(d) : b && b()
  3121. }
  3122. ;
  3123. b && (req.onerror = function() {
  3124. b()
  3125. }
  3126. );
  3127. d.src = a
  3128. },
  3129. fetchText: function(a, c, b, d) {
  3130. var e = new XMLHttpRequest;
  3131. e.open("GET", a, !0);
  3132. e.onload = function() {
  3133. 200 == e.status ? c(e.responseText) : b && b()
  3134. }
  3135. ;
  3136. b && (e.onerror = function() {
  3137. b()
  3138. }
  3139. );
  3140. d && (e.onprogress = function(a) {
  3141. d(a.loaded, a.total)
  3142. }
  3143. );
  3144. e.send()
  3145. },
  3146. fetchBinary: function(a, c, b, d) {
  3147. var e = new XMLHttpRequest;
  3148. e.open("GET", a, !0);
  3149. e.responseType = "arraybuffer";
  3150. e.onload = function() {
  3151. 200 == e.status ? c(e.response) : b && b()
  3152. }
  3153. ;
  3154. b && (e.onerror = function() {
  3155. b()
  3156. }
  3157. );
  3158. d && (e.onprogress = function(a) {
  3159. d(a.loaded, a.total)
  3160. }
  3161. );
  3162. e.send()
  3163. },
  3164. fetchBinaryIncremental: function(a, c, b, d) {
  3165. var e = new XMLHttpRequest;
  3166. e.open("HEAD", a, !0);
  3167. e.onload = function() {
  3168. if (200 == e.status) {
  3169. var f = e.getResponseHeader("Accept-Ranges");
  3170. if (f && "none" != f) {
  3171. var g = e.getResponseHeader("Content-Length") | 0
  3172. , h = function(b, e) {
  3173. var f = new XMLHttpRequest;
  3174. f.open("GET", a, !0);
  3175. f.setRequestHeader("Range", "bytes=" + b + "-" + e);
  3176. f.responseType = "arraybuffer";
  3177. f.onload = function() {
  3178. (206 == f.status || 200 == f.status) && c(f.response) && e < g && (b += d,
  3179. e += d,
  3180. e = e < g - 1 ? e : g - 1,
  3181. h(b, e))
  3182. }
  3183. ;
  3184. f.send()
  3185. };
  3186. h(0, d - 1)
  3187. } else
  3188. b && b()
  3189. } else
  3190. b && b()
  3191. }
  3192. ;
  3193. b && (e.onerror = function() {
  3194. b()
  3195. }
  3196. );
  3197. e.send()
  3198. }
  3199. };
  3200. function PlaybackControls(a) {
  3201. this.debugString = "";
  3202. this.init = !1;
  3203. this.speedList = this.cameraList = this.animationList = this.playButton = this.timelineSlider = this.playbackRegion = this.previousFrameButton = this.nextFrameButton = this.pauseButton = this.playButton = 0;
  3204. this.visible = !1;
  3205. this.backgroundRegion = this.screenButton = 0;
  3206. this.guiScreen = a;
  3207. this.playbackRegion = new GUIRegion(a);
  3208. this.idealSliderWidth = 650;
  3209. this.totalListBoxPixelsX = 0;
  3210. this.minWidth = 500;
  3211. this.compactMode = !1;
  3212. this.ui = a.ui;
  3213. var c = "animationpause" + a.imageSetNumber + "x.png"
  3214. , b = "animationplay" + a.imageSetNumber + "x.png"
  3215. , d = "timelineLE" + a.imageSetNumber + "x.png"
  3216. , e = "timelineM" + a.imageSetNumber + "x.png"
  3217. , f = "timelineRE" + a.imageSetNumber + "x.png"
  3218. , g = a.ui.viewer.scene.sceneAnimator.animations.length;
  3219. if (0 != g) {
  3220. var h = this.idealSliderWidth;
  3221. this.bottomOffset = 85;
  3222. this.centerOffset = 60;
  3223. var k = a.width / 2 + this.centerOffset
  3224. , n = k - h / 2
  3225. , k = k + h / 2
  3226. , m = n - 14 - 32
  3227. , l = k - m
  3228. , p = 32 / a.height
  3229. , r = this.bottomOffset / a.height
  3230. , s = this.playbackRegion;
  3231. s.controlRect.widthPercent = l / a.width;
  3232. s.controlRect.heightPercent = p;
  3233. s.controlRect.xPercent = m / a.width;
  3234. s.controlRect.yPercent = r;
  3235. p = 32 / l;
  3236. this.pauseButton = new Button(this.guiScreen);
  3237. this.pauseButton.controlRect.set(0, 0.125, p, 0.75);
  3238. this.pauseButton.controlRect.opacity = 0.5;
  3239. s.controlRect.registerChildControlRect(this.pauseButton.controlRect);
  3240. this.pauseButton.linkControl(s.addImageElement(this.pauseButton.controlRect, c));
  3241. this.playButton = new Button(this.guiScreen);
  3242. this.playButton.controlRect.set(0, 0.125, p, 0.75);
  3243. this.playButton.controlRect.opacity = 0.5;
  3244. s.controlRect.registerChildControlRect(this.playButton.controlRect);
  3245. this.playButton.linkControl(s.addImageElement(this.playButton.controlRect, b));
  3246. c = h / l;
  3247. l = (n - m) / l;
  3248. this.timelineSlider = new TimelineSlider(this.guiScreen,s);
  3249. this.timelineSlider.controlRect.set(l, 0.03125, c, 1);
  3250. s.controlRect.registerChildControlRect(this.timelineSlider.controlRect);
  3251. this.timelineSlider.setBackground3x1(s, d, e, f);
  3252. this.pauseButton.controlRect.showControl(!a.ui.viewer.scene.sceneAnimator.paused);
  3253. this.playButton.controlRect.showControl(a.ui.viewer.scene.sceneAnimator.paused);
  3254. d = k + 14;
  3255. e = this.bottomOffset + 4;
  3256. f = a.ui.viewer.scene.sceneAnimator.animations[0].cameraObjects.length;
  3257. a.ui.viewer.scene.sceneAnimator.selectDefaultCamera();
  3258. a.ui.viewer.scene.sceneAnimator.setViewFromSelectedCamera();
  3259. this.maxListPixelsX = 0;
  3260. if (1 < f) {
  3261. this.cameraList = new ListBox(a);
  3262. for (l = 0; l < f; l++)
  3263. this.cameraList.addItem(a.ui.viewer.scene.sceneAnimator.animations[0].cameraObjects[l].name, 0, 0);
  3264. this.cameraList.spawnControl(d, e, 10, 24, !0, 8);
  3265. this.cameraList.selectItem(a.ui.viewer.scene.sceneAnimator.selectedCameraIndex);
  3266. this.maxListPixelsX = this.cameraList.localPixelsX;
  3267. this.totalListBoxPixelsX += this.cameraList.localPixelsX + 14
  3268. }
  3269. if (1 < g) {
  3270. this.animationList = new ListBox(a);
  3271. for (l = 0; l < g; l++)
  3272. this.animationList.addItem(a.ui.viewer.scene.sceneAnimator.animations[l].name, 0, 0);
  3273. this.animationList.spawnControl(d, e, 10, 24, !0, 8);
  3274. this.maxListPixelsX < this.animationList.localPixelsX && (this.maxListPixelsX = this.animationList.localPixelsX);
  3275. this.totalListBoxPixelsX += this.animationList.localPixelsX + 14;
  3276. this.animationList.selectItem(a.ui.viewer.scene.sceneAnimator.selectedAnimationIndex)
  3277. }
  3278. d = m - 44 - 14;
  3279. l = k - d + this.totalListBoxPixelsX;
  3280. this.speedList = new ListBox(a);
  3281. this.speedList.addItem("4.0x", 4, 0);
  3282. this.speedList.addItem("2.0x", 4, 0);
  3283. this.speedList.addItem("1.0x", 4, 0);
  3284. this.speedList.addItem("0.5x", 4, 0);
  3285. this.speedList.addItem("0.25x", -2, 0);
  3286. this.speedList.spawnControl(d, e, 44, 24, !1, 0);
  3287. this.speedList.selectItem(2);
  3288. l > a.width && (this.idealSliderWidth = a.width - (118 + (this.totalListBoxPixelsX + 14)) - this.centerOffset,
  3289. a = 0,
  3290. this.cameraList && a++,
  3291. this.animationList && a++,
  3292. 1 == a && (this.idealSliderWidth += 56,
  3293. this.centerOffset -= 14),
  3294. 2 == a && (this.idealSliderWidth += 63,
  3295. this.centerOffset -= 63));
  3296. this.setupCallbacks()
  3297. }
  3298. }
  3299. PlaybackControls.prototype.resize = function(a) {
  3300. a.ui.viewer.scene.sceneAnimator.showPlayControls || (a.width = 1,
  3301. a.height = 1);
  3302. this.compactMode = a.width < this.minWidth;
  3303. var c = this.bottomOffset
  3304. , b = this.bottomOffset + 4
  3305. , d = 0;
  3306. this.cameraList && this.animationList ? d += 42 + this.cameraList.localPixelsX + this.animationList.localPixelsX : this.cameraList ? d += 28 + this.cameraList.localPixelsX : this.animationList && (d += 28 + this.animationList.localPixelsX);
  3307. var e = a.width - d - 72;
  3308. 0 == d && (e -= 14);
  3309. var f = 116
  3310. , g = f + e + 14;
  3311. this.compactMode && (f = 58,
  3312. e += 44 + d,
  3313. 0 < d && (c += 32),
  3314. !d && (b += 32));
  3315. var d = 32 / e
  3316. , h = d + 14 / e
  3317. , k = 1 - h
  3318. , n = this.playbackRegion;
  3319. n.controlRect.widthPercent = e / a.width;
  3320. n.controlRect.heightPercent = 32 / a.height;
  3321. n.controlRect.xPercent = f / a.width;
  3322. n.controlRect.yPercent = c / a.height;
  3323. this.pauseButton.controlRect.set(0, 0.125, d, 0.75);
  3324. this.playButton.controlRect.set(0, 0.125, d, 0.75);
  3325. this.timelineSlider.controlRect.set(h, 0.03125, k, 1);
  3326. this.timelineSlider.setSize(e - 46, 32);
  3327. n.controlRect.updateElement();
  3328. n.controlRect.updateChildElements();
  3329. this.speedList.setControl(58, b, 44, 24, !1);
  3330. this.cameraList && (this.cameraList.setControl(g, b, 10, 24, !0, 8),
  3331. g += this.cameraList.localPixelsX + 14);
  3332. this.animationList && this.animationList.setControl(g, b, 10, 24, !0, 8);
  3333. this.timelineSlider.backgroundControl.alignBackground()
  3334. }
  3335. ;
  3336. PlaybackControls.prototype.setupCallbacks = function() {
  3337. var a = function(a) {
  3338. "0.01x" == this.speedList.selectedItemText && this.ui.viewer.scene.sceneAnimator.setPlaybackSpeed(0.01);
  3339. "0.05x" == this.speedList.selectedItemText && this.ui.viewer.scene.sceneAnimator.setPlaybackSpeed(0.05);
  3340. "0.25x" == this.speedList.selectedItemText && this.ui.viewer.scene.sceneAnimator.setPlaybackSpeed(0.25);
  3341. "0.5x" == this.speedList.selectedItemText && this.ui.viewer.scene.sceneAnimator.setPlaybackSpeed(0.5);
  3342. "1.0x" == this.speedList.selectedItemText && this.ui.viewer.scene.sceneAnimator.setPlaybackSpeed(1);
  3343. "2.0x" == this.speedList.selectedItemText && this.ui.viewer.scene.sceneAnimator.setPlaybackSpeed(2);
  3344. "4.0x" == this.speedList.selectedItemText && this.ui.viewer.scene.sceneAnimator.setPlaybackSpeed(4)
  3345. }
  3346. .bind(this)
  3347. , c = function(a) {
  3348. this.ui.viewer.scene.sceneAnimator.selectCamera(this.cameraList.selectedIndex);
  3349. this.ui.viewer.wake()
  3350. }
  3351. .bind(this)
  3352. , b = function(a) {
  3353. this.ui.viewer.scene.sceneAnimator.selectAnimation(this.animationList.selectedIndex);
  3354. this.ui.viewer.wake()
  3355. }
  3356. .bind(this);
  3357. this.speedList && (this.speedList.selectionChangedCallback = a);
  3358. this.cameraList && (this.cameraList.selectionChangedCallback = c);
  3359. this.animationList && (this.animationList.selectionChangedCallback = b);
  3360. this.playButton.controlRect.linkedControl.onclick = function() {
  3361. this.ui.viewer.scene.sceneAnimator.pause(!1);
  3362. this.playButton.controlRect.showControl(!1);
  3363. this.pauseButton.controlRect.showControl(!0);
  3364. this.ui.viewer.wake()
  3365. }
  3366. .bind(this);
  3367. this.pauseButton.controlRect.linkedControl.onclick = function() {
  3368. this.ui.viewer.scene.sceneAnimator.pause(!0);
  3369. this.playButton.controlRect.showControl(!0);
  3370. this.pauseButton.controlRect.showControl(!1)
  3371. }
  3372. .bind(this)
  3373. }
  3374. ;
  3375. function PostRender(a, c, b) {
  3376. this.gl = a;
  3377. this.desc = c;
  3378. c = [];
  3379. 0 != this.desc.sharpen && c.push("#define SHARPEN");
  3380. (this.useBloom = 0 < this.desc.bloomColor[0] * this.desc.bloomColor[3] || 0 < this.desc.bloomColor[1] * this.desc.bloomColor[3] || 0 < this.desc.bloomColor[2] * this.desc.bloomColor[3]) && c.push("#define BLOOM");
  3381. 0 != this.desc.vignette[3] && c.push("#define VIGNETTE");
  3382. 1 == this.desc.saturation[0] * this.desc.saturation[3] && 1 == this.desc.saturation[1] * this.desc.saturation[3] && 1 == this.desc.saturation[2] * this.desc.saturation[3] || c.push("#define SATURATION");
  3383. 1 == this.desc.contrast[0] * this.desc.contrast[3] && 1 == this.desc.contrast[1] * this.desc.contrast[3] && 1 == this.desc.contrast[2] * this.desc.contrast[3] && 1 == this.desc.brightness[0] * this.desc.brightness[3] && 1 == this.desc.brightness[1] * this.desc.brightness[3] && 1 == this.desc.brightness[2] * this.desc.brightness[3] || c.push("#define CONTRAST");
  3384. 0 != this.desc.grain && c.push("#define GRAIN");
  3385. 1 == this.desc.toneMap ? c.push("#define REINHARD") : 2 == this.desc.toneMap ? c.push("#define HEJL") : 3 == this.desc.toneMap && c.push("#define ACES");
  3386. this.desc.colorLUT && c.push("#define COLOR_LUT");
  3387. this.sampleIndex = 0;
  3388. this.sampleCount = 1;
  3389. b && (this.sampleCount = 4,
  3390. this.sampleOffsets = [[-0.5, -0.5], [0.5, -0.5], [-0.5, 0.5], [0.5, 0.5]]);
  3391. this.aaShader = a.shaderCache.fromURLs("postvert.glsl", "postaa.glsl");
  3392. this.shader = a.shaderCache.fromURLs("postvert.glsl", "postfrag.glsl", c);
  3393. this.plainShader = a.shaderCache.fromURLs("postvert.glsl", "postfrag.glsl", []);
  3394. this.fullscreenTriangle = a.createBuffer();
  3395. a.bindBuffer(a.ARRAY_BUFFER, this.fullscreenTriangle);
  3396. b = new Float32Array([0, 0, 2, 0, 0, 2]);
  3397. a.bufferData(a.ARRAY_BUFFER, b, a.STATIC_DRAW);
  3398. a.bindBuffer(a.ARRAY_BUFFER, null);
  3399. if (this.useBloom) {
  3400. this.bloomTextures = [];
  3401. this.bloomTargets = [];
  3402. for (b = 0; 2 > b; ++b)
  3403. c = {
  3404. width: 256,
  3405. height: 256,
  3406. clamp: !0
  3407. },
  3408. this.bloomTextures[b] = new Texture(a,c),
  3409. this.bloomTextures[b].loadArray(null, a.RGBA, a.ext.textureHalf && a.ext.textureHalfLinear ? a.ext.textureHalf.HALF_FLOAT_OES : a.UNSIGNED_BYTE),
  3410. this.bloomTargets[b] = new Framebuffer(a,{
  3411. width: c.width,
  3412. height: c.height,
  3413. color0: this.bloomTextures[b]
  3414. });
  3415. for (this.bloomSamples = 64; this.bloomSamples + 16 >= a.limits.fragmentUniforms; )
  3416. this.bloomSamples /= 2;
  3417. this.bloomShader = a.shaderCache.fromURLs("postvert.glsl", "bloom.glsl", ["#define BLOOM_SAMPLES " + this.bloomSamples]);
  3418. this.shrinkShader = a.shaderCache.fromURLs("postvert.glsl", "bloomshrink.glsl")
  3419. }
  3420. a = new Uint8Array(16384);
  3421. for (b = 0; 16384 > b; b++) {
  3422. c = 255 * Math.random();
  3423. var d = 255 * Math.random();
  3424. a[b] = 0.5 * (c + d)
  3425. }
  3426. this.noiseTexture = new Texture(this.gl,{
  3427. width: 128,
  3428. height: 128
  3429. });
  3430. this.noiseTexture.loadArray(a, this.gl.LUMINANCE);
  3431. this.desc.colorLUT && (a = this.desc.colorLUT,
  3432. this.colorLUT = new Texture(this.gl,{
  3433. width: a.length / 3 | 0,
  3434. height: 1,
  3435. clamp: !0
  3436. }),
  3437. this.colorLUT.loadArray(new Uint8Array(a), this.gl.RGB));
  3438. this.blackTexture = new Texture(this.gl,{
  3439. width: 1,
  3440. height: 1
  3441. });
  3442. this.blackTexture.loadArray(new Uint8Array([0, 0, 0, 0]));
  3443. this.bloomResult = this.blackTexture
  3444. }
  3445. PostRender.prototype.prepareBloom = function(a) {
  3446. if (this.useBloom && this.bloomShader.complete() && this.shrinkShader.complete()) {
  3447. this.shrinkShader.bind();
  3448. this.bloomTargets[1].bind();
  3449. a.bind(this.shrinkShader.samplers.tInput);
  3450. this.fillScreen(this.shrinkShader.attribs.vCoord);
  3451. this.bloomShader.bind();
  3452. var c = [];
  3453. this.bloomTargets[0].bind();
  3454. this.bloomTextures[1].bind(this.bloomShader.samplers.tInput);
  3455. for (var b = 0, d = 0; d < this.bloomSamples; ++d) {
  3456. var e = -1 + 2 * d / (this.bloomSamples - 1), f;
  3457. f = 4 * e;
  3458. f = Math.exp(-0.5 * f * f / 1) / 2.50662827463;
  3459. b += f;
  3460. c[4 * d + 0] = e * this.desc.bloomSize;
  3461. c[4 * d + 1] = 0;
  3462. c[4 * d + 2] = f;
  3463. c[4 * d + 3] = 0
  3464. }
  3465. for (d = 0; d < this.bloomSamples; ++d)
  3466. c[4 * d + 2] /= b;
  3467. this.gl.uniform4fv(this.bloomShader.params.uKernel, c);
  3468. this.fillScreen(this.bloomShader.attribs.vCoord);
  3469. this.bloomTargets[1].bind();
  3470. this.bloomTextures[0].bind(this.bloomShader.samplers.tInput);
  3471. for (d = 0; d < this.bloomSamples; ++d)
  3472. b = c[4 * d + 0],
  3473. b *= a.desc.width / a.desc.height,
  3474. c[4 * d + 0] = 0,
  3475. c[4 * d + 1] = b;
  3476. this.gl.uniform4fv(this.bloomShader.params.uKernel, c);
  3477. this.fillScreen(this.bloomShader.attribs.vCoord);
  3478. this.bloomResult = this.bloomTextures[1]
  3479. } else
  3480. this.bloomResult = this.blackTexture
  3481. }
  3482. ;
  3483. PostRender.prototype.computeParams = function(a, c) {
  3484. var b = this.desc
  3485. , d = {};
  3486. d.scale = [b.contrast[0] * b.contrast[3], b.contrast[1] * b.contrast[3], b.contrast[2] * b.contrast[3]];
  3487. d.bias = [b.bias[0] * b.bias[3], b.bias[1] * b.bias[3], b.bias[2] * b.bias[3]];
  3488. d.bias = [-d.bias[0] * d.scale[0] + d.bias[0], -d.bias[1] * d.scale[1] + d.bias[1], -d.bias[2] * d.scale[2] + d.bias[2]];
  3489. var e = [b.brightness[0] * b.brightness[3], b.brightness[1] * b.brightness[3], b.brightness[2] * b.brightness[3]];
  3490. d.scale = [d.scale[0] * e[0], d.scale[1] * e[1], d.scale[2] * e[2]];
  3491. d.bias = [d.bias[0] * e[0], d.bias[1] * e[1], d.bias[2] * e[2]];
  3492. d.saturation = [b.saturation[0] * b.saturation[3], b.saturation[1] * b.saturation[3], b.saturation[2] * b.saturation[3]];
  3493. d.bloomColor = [b.bloomColor[0] * b.bloomColor[3], b.bloomColor[1] * b.bloomColor[3], b.bloomColor[2] * b.bloomColor[3]];
  3494. d.sharpen = [b.sharpen, 0.25 * b.sharpen, b.sharpenLimit];
  3495. d.sharpenKernel = [1 / a, 0, 0, 1 / c];
  3496. e = a > c ? a : c;
  3497. d.vignetteAspect = [a / e, c / e, 0.5 * a / e, 0.5 * c / e];
  3498. d.vignette = [2 * (1 - b.vignette[0]) * b.vignette[3], 2 * (1 - b.vignette[1]) * b.vignette[3], 2 * (1 - b.vignette[2]) * b.vignette[3], b.vignetteCurve];
  3499. var e = 1 / this.noiseTexture.desc.width
  3500. , f = 1 / this.noiseTexture.desc.height
  3501. , g = 1 - b.grainSharpness;
  3502. d.grainCoord = [e * a, f * c, 0.5 * g * e, 0.5 * g * f];
  3503. d.grainScaleBias = [2 * b.grain, -b.grain];
  3504. return d
  3505. }
  3506. ;
  3507. PostRender.prototype.present = function(a, c, b, d) {
  3508. d || this.prepareBloom(a);
  3509. 1 < this.sampleCount && this.allocAABuffer(c, b);
  3510. d = d ? this.plainShader : this.shader;
  3511. if (d.bind()) {
  3512. var e = this.gl
  3513. , f = d.samplers
  3514. , g = d.params
  3515. , h = this.computeParams(c, b);
  3516. a.bind(f.tInput);
  3517. this.bloomResult.bind(f.tBloom);
  3518. this.noiseTexture.bind(f.tGrain);
  3519. this.colorLUT && this.colorLUT.bind(f.tLUT);
  3520. e.uniform3fv(g.uScale, h.scale);
  3521. e.uniform3fv(g.uBias, h.bias);
  3522. e.uniform3fv(g.uSaturation, h.saturation);
  3523. e.uniform4fv(g.uSharpenKernel, h.sharpenKernel);
  3524. e.uniform3fv(g.uSharpness, h.sharpen);
  3525. e.uniform3fv(g.uBloomColor, h.bloomColor);
  3526. e.uniform4fv(g.uVignetteAspect, h.vignetteAspect);
  3527. e.uniform4fv(g.uVignette, h.vignette);
  3528. e.uniform4fv(g.uGrainCoord, h.grainCoord);
  3529. e.uniform2fv(g.uGrainScaleBias, h.grainScaleBias);
  3530. if (a = 1 < this.sampleCount && 0 <= this.sampleIndex) {
  3531. var k = 1 / (1 + this.sampleIndex);
  3532. this.sampleIndex += 1;
  3533. 1 > k && (e.enable(e.BLEND),
  3534. e.blendColor(k, k, k, k),
  3535. e.blendFunc(e.CONSTANT_ALPHA, e.ONE_MINUS_CONSTANT_ALPHA));
  3536. this.aaTarget.bind()
  3537. } else
  3538. Framebuffer.bindNone(e),
  3539. 1 < this.sampleCount && (this.sampleIndex += 1);
  3540. e.viewport(0, 0, c, b);
  3541. this.fillScreen(d.attribs.vCoord);
  3542. a && (1 > k && e.disable(e.BLEND),
  3543. Framebuffer.bindNone(e),
  3544. this.aaShader.bind(),
  3545. this.aaBuffer.bind(this.aaShader.samplers.tInput),
  3546. this.fillScreen(this.aaShader.attribs.vCoord))
  3547. }
  3548. }
  3549. ;
  3550. PostRender.prototype.allocAABuffer = function(a, c) {
  3551. this.aaBuffer && this.aaBuffer.desc.width == a && this.aaBuffer.desc.height == c || (this.aaBuffer && this.aaBuffer.destroy(),
  3552. this.aaBuffer = new Texture(this.gl,{
  3553. width: a,
  3554. height: c,
  3555. clamp: !0
  3556. }),
  3557. this.aaBuffer.loadArray(),
  3558. this.aaTarget = new Framebuffer(this.gl,{
  3559. color0: this.aaBuffer,
  3560. ignoreStatus: !0
  3561. }))
  3562. }
  3563. ;
  3564. PostRender.prototype.adjustProjectionForSupersampling = function(a) {
  3565. if (1 < this.sampleCount) {
  3566. var c = this.currentSample()
  3567. , b = this.sampleOffsets[c][0] / a.size[0]
  3568. , c = this.sampleOffsets[c][1] / a.size[1]
  3569. , b = Matrix.translation(Matrix.empty(), b, c, 0);
  3570. Matrix.mul(a.projectionMatrix, b, a.projectionMatrix)
  3571. }
  3572. }
  3573. ;
  3574. PostRender.prototype.discardAAHistory = function() {
  3575. this.sampleIndex = -1
  3576. }
  3577. ;
  3578. PostRender.prototype.currentSample = function() {
  3579. return (0 > this.sampleIndex ? 0 : this.sampleIndex) % this.sampleCount
  3580. }
  3581. ;
  3582. PostRender.prototype.fillScreen = function(a) {
  3583. var c = this.gl;
  3584. c.bindBuffer(c.ARRAY_BUFFER, this.fullscreenTriangle);
  3585. c.enableVertexAttribArray(a);
  3586. c.vertexAttribPointer(a, 2, c.FLOAT, !1, 0, 0);
  3587. c.drawArrays(c.TRIANGLES, 0, 3);
  3588. c.disableVertexAttribArray(a);
  3589. c.bindBuffer(c.ARRAY_BUFFER, null)
  3590. }
  3591. ;
  3592. PostRender.prototype.blitTexture = function(a) {
  3593. this.aaShader.bind();
  3594. a.bind(this.aaShader.samplers.tInput);
  3595. this.fillScreen(this.aaShader.attribs.vCoord)
  3596. }
  3597. ;
  3598. function Scene(a) {
  3599. this.gl = a;
  3600. this.name = "untitled";
  3601. this.meshes = [];
  3602. this.meshRenderables = [];
  3603. this.materials = {};
  3604. this.sky = this.view = null;
  3605. this.selectedPartIndex = 0;
  3606. this.soloPart = !1;
  3607. this.miscnotes = "";
  3608. this.nextView = null;
  3609. this.viewFade = 0;
  3610. this.refractionSurface = this.shadow = this.stripData = this.lights = null;
  3611. this.sceneAnimator = this.frameCounter = 0;
  3612. this.sceneLoaded = !1;
  3613. this.debugString = ""
  3614. }
  3615. Scene.prototype.load = function(a) {
  3616. var c = this.gl, b, d = a.extract("scene.json");
  3617. if (void 0 !== d) {
  3618. /*
  3619. if (!a.checkSignature(d))
  3620. return !1;
  3621. */
  3622. d = (new ByteStream(d.data)).asString();
  3623. if (null == d || 0 >= d.length)
  3624. return !1;
  3625. try {
  3626. b = JSON.parse(d)
  3627. } catch (e) {
  3628. return console.error(e),
  3629. !1
  3630. }
  3631. } else
  3632. return !1;
  3633. window.assets = a;
  3634. window.sceneInfo = b;
  3635. this.metaData = b.metaData;
  3636. this.view = new View(b.mainCamera.view);
  3637. this.sky = new Sky(this.gl,a,b.sky);
  3638. this.lights = new Lights(b.lights,this.view);
  3639. this.materialsList = [];
  3640. this.materials = {};
  3641. for (var f in b.materials) {
  3642. var g = b.materials[f];
  3643. g.lightCount = this.lights.count;
  3644. g.shadowCount = this.lights.shadowCount;
  3645. d = new Material(this.gl,a,g);
  3646. this.materials[g.name] = d;
  3647. this.materialsList.push(d)
  3648. }
  3649. if (b.meshes)
  3650. for (g = 0; g < b.meshes.length; ++g) {
  3651. f = b.meshes[g];
  3652. f = new Mesh(this.gl,f,a.extract(f.file));
  3653. this.meshes.push(f);
  3654. for (var h = 0; h < f.desc.subMeshes.length; ++h) {
  3655. var k = f.desc.subMeshes[h];
  3656. if (d = this.materials[k.material])
  3657. f.numSubMeshes++,
  3658. this.meshRenderables.push(new MeshRenderable(f,k,d))
  3659. }
  3660. }
  3661. this.bounds = new Bounds(this.meshes);
  3662. this.postRender = new PostRender(this.gl,b.mainCamera.post,!0);
  3663. this.shadow = new ShadowCollector(c,this.lights.shadowCount);
  3664. this.cameras = b.Cameras;
  3665. b.AnimData && (this.sceneAnimator = new SceneAnimator(this,a,b.AnimData));
  3666. b.fog && (this.fog = new Fog(c,b.fog));
  3667. b.shadowFloor && (this.shadowFloor = new ShadowFloor(c,b.shadowFloor,this.shadow,this.lights));
  3668. return this.sceneLoaded = !0
  3669. }
  3670. ;
  3671. Scene.prototype.update = function() {
  3672. this.sceneAnimator && (this.frameCounter++,
  3673. this.lights.flagUpdateAnimatedLighting(),
  3674. this.sceneAnimator.drawAnimated && (1 == this.frameCounter ? this.sceneAnimator.resetPlayback() : this.sceneAnimator.updateAnimationPlayback()));
  3675. this.lights.update(this.view, this.bounds)
  3676. }
  3677. ;
  3678. Scene.prototype.collectShadows = function(a) {
  3679. this.shadow.collect(this, a)
  3680. }
  3681. ;
  3682. Scene.prototype.draw = function(a) {
  3683. var c = this.gl;
  3684. if (this.sceneLoaded) {
  3685. this.sky.setClearColor();
  3686. c.clear(c.COLOR_BUFFER_BIT | c.DEPTH_BUFFER_BIT | c.STENCIL_BUFFER_BIT);
  3687. c.enable(c.DEPTH_TEST);
  3688. this.sky.draw(this);
  3689. this.shadowFloor && this.shadowFloor.draw(this);
  3690. for (var b = 0; b < this.meshRenderables.length; ++b)
  3691. this.meshRenderables[b].material.usesBlending || this.meshRenderables[b].material.usesRefraction || !this.meshRenderables[b].visible || this.meshRenderables[b].draw(this);
  3692. c.enable(c.POLYGON_OFFSET_FILL);
  3693. c.polygonOffset(1, 1);
  3694. c.colorMask(!1, !1, !1, !1);
  3695. for (b = 0; b < this.meshRenderables.length; ++b)
  3696. this.meshRenderables[b].drawAlphaPrepass(this);
  3697. c.colorMask(!0, !0, !0, !0);
  3698. c.disable(c.POLYGON_OFFSET_FILL);
  3699. c.depthFunc(c.LEQUAL);
  3700. c.depthMask(!1);
  3701. for (b = 0; b < this.meshRenderables.length; ++b)
  3702. this.meshRenderables[b].material.usesBlending && this.meshRenderables[b].visible && this.meshRenderables[b].draw(this);
  3703. c.disable(c.BLEND);
  3704. c.depthMask(!0);
  3705. c.depthFunc(c.LESS);
  3706. for (var d = !1, b = 0; b < this.meshRenderables.length; ++b)
  3707. if (this.meshRenderables[b].material.usesRefraction) {
  3708. d = !0;
  3709. break
  3710. }
  3711. if (d)
  3712. for (this.refractionSurface && this.refractionSurface.desc.width == a.color0.desc.width && this.refractionSurface.desc.height == a.color0.desc.height || (this.refractionSurface = new Texture(c,a.color0.desc),
  3713. this.refractionSurface.loadArray(null, a.color0.format, a.color0.componentType),
  3714. this.refractionBuffer = new Framebuffer(this.gl,{
  3715. color0: this.refractionSurface
  3716. })),
  3717. this.refractionBuffer.bind(),
  3718. this.postRender.blitTexture(a.color0),
  3719. a.bind(),
  3720. b = 0; b < this.meshRenderables.length; ++b)
  3721. this.meshRenderables[b].material.usesRefraction && this.meshRenderables[b].visible && this.meshRenderables[b].draw(this);
  3722. if (this.stripData.activeWireframe() && 0 < this.meshRenderables.length) {
  3723. for (b = 0; b < this.meshRenderables.length; ++b)
  3724. this.meshRenderables[b].visible && this.meshRenderables[b].drawWire(this);
  3725. c.depthMask(!0)
  3726. }
  3727. c.disable(c.BLEND)
  3728. }
  3729. }
  3730. ;
  3731. Scene.prototype.drawSecondary = function(a) {
  3732. this.fog && this.fog.draw(this, a)
  3733. }
  3734. ;
  3735. Scene.prototype.complete = function() {
  3736. if (!this.sky.complete() || !this.shadow.complete() || this.fog && !this.fog.complete() || this.shadowFloor && !this.shadowFloor.complete())
  3737. return !1;
  3738. for (var a = 0; a < this.meshRenderables.length; ++a)
  3739. if (!this.meshRenderables[a].complete())
  3740. return !1;
  3741. return !0
  3742. }
  3743. ;
  3744. function SceneAnimator(a, c, b) {
  3745. this.scene = a;
  3746. this.animations = [];
  3747. this.skinningRigs = [];
  3748. this.meshIDs = [];
  3749. this.lightIDs = [];
  3750. this.materialIDs = [];
  3751. this.views = [];
  3752. this.viewYawOffsets = [];
  3753. this.viewPitchOffsets = [];
  3754. this.cameraObjectIndices = [];
  3755. this.cameraChildrenIndices = [];
  3756. this.subMeshObjectIndices = [];
  3757. this.subMeshLiveIndices = [];
  3758. this.scene = a;
  3759. this.selectedCameraIndex = -1;
  3760. this.selectedAnimationIndex = 0;
  3761. this.debugString = "";
  3762. this.scenePlaybackSpeed = this.playbackSpeed = 1;
  3763. this.animationProgress = this.totalSeconds = 0;
  3764. this.paused = this.autoAdvanceNextAnimation = !1;
  3765. this.animateVisibility = this.drawAnimated = this.linkSceneObjects = this.loadSkinningRigs = this.animateMaterials = this.animateTurntables = this.enableSkinning = this.animateMeshes = this.animateLights = this.playAnimations = this.loadAnimations = !0;
  3766. this.showDebugInfo = !1;
  3767. this.loopCount = 0;
  3768. this.loopTurntables = this.lockPlayback = !1;
  3769. this.fogObjectIndex = -1;
  3770. this.unitScaleSkinnedMeshes = !0;
  3771. this.sceneScale = b.sceneScale;
  3772. this.defaultCameraGlobalIndex = b.selectedCamera;
  3773. this.selectedAnimationIndex = b.selectedAnimation;
  3774. this.autoPlayAnims = b.autoPlayAnims;
  3775. this.showPlayControls = b.showPlayControls;
  3776. b.scenePlaybackSpeed && (this.scenePlaybackSpeed = b.scenePlaybackSpeed,
  3777. 0 == this.scenePlaybackSpeed && (this.scenePlaybackSpeed = 1));
  3778. this.autoPlayAnims || (this.paused = !0);
  3779. if (this.loadAnimations) {
  3780. if (b.meshIDs)
  3781. for (var d = b.meshIDs.length, e = 0; e < d; ++e) {
  3782. var f = b.meshIDs[e].partIndex;
  3783. this.meshIDs.push(f)
  3784. }
  3785. if (b.lightIDs)
  3786. for (d = b.lightIDs.length,
  3787. e = 0; e < d; ++e)
  3788. f = b.lightIDs[e],
  3789. f = f.partIndex,
  3790. this.lightIDs.push(f);
  3791. if (b.materialIDs)
  3792. for (d = b.materialIDs.length,
  3793. e = 0; e < d; ++e)
  3794. f = b.materialIDs[e],
  3795. f = f.partIndex,
  3796. this.materialIDs.push(f);
  3797. this.numMatricesInTable = b.numMatrices;
  3798. e = c.get("MatTable.bin");
  3799. f = new ByteStream(e.data);
  3800. e || (this.numMatricesInTable = 0,
  3801. this.debugString += "<br>No mattable?");
  3802. if (b.skinningRigs && this.loadSkinningRigs)
  3803. for (d = b.skinningRigs.length,
  3804. e = 0; e < d; ++e) {
  3805. var g = new SkinningRig(c,b.skinningRigs[e],f);
  3806. "" == g.debugString ? this.skinningRigs.push(g) : (this.debugString += "<br>Error loading skinning rig " + e + " :" + g.debugString,
  3807. this.debugString += "<br>Skipping the rest",
  3808. e = d)
  3809. }
  3810. if (b.animations)
  3811. for (f = b.animations.length,
  3812. e = 0; e < f; ++e)
  3813. d = new Animation(c,b.animations[e]),
  3814. this.animations.push(d);
  3815. this.startMS = Date.now();
  3816. f = this.animations.length;
  3817. if (this.linkSceneObjects && 0 != f) {
  3818. for (e = 0; e < f; e++)
  3819. for (c = this.animations[e],
  3820. d = c.animatedObjects.length,
  3821. b = 0; b < d; b++)
  3822. g = c.animatedObjects[b],
  3823. "LightSO" == g.sceneObjectType && (g.lightIndex = this.findLightIndexByPartIndex(b),
  3824. -1 != g.lightIndex ? c.lightObjects.push(g) : this.debugString += "<br> got light not in scene " + g.name),
  3825. "FogSO" == g.sceneObjectType && (this.fogObjectIndex = b),
  3826. "SubMeshSO" == g.sceneObjectType && 0 == e && (this.subMeshObjectIndices.push(b),
  3827. this.subMeshLiveIndices.push(-1)),
  3828. "Material" == g.sceneObjectType && (g.materialIndex = this.findMaterialIndexByPartIndex(b),
  3829. -1 == g.materialIndex ? this.debugString += "<br> can't find material index for object " + b : c.materialObjects.push(g)),
  3830. "TurnTableSO" == g.sceneObjectType && c.turnTableObjects.push(g),
  3831. "MeshSO" == g.sceneObjectType && (g.meshIndex = this.findMeshIndexByPartIndex(this.scene.meshes, b),
  3832. -1 == g.meshIndex ? (this.debugString += "<br> can't find mesh index for object " + b,
  3833. this.logObjectInfo(b, 0)) : (c.meshObjects.push(g),
  3834. g.mesh = this.scene.meshes[g.meshIndex],
  3835. -1 != g.skinningRigIndex && g.mesh && g.skinningRigIndex < this.skinningRigs.length && (g.skinningRig = this.skinningRigs[g.skinningRigIndex],
  3836. g.skinningRig.isRigidSkin || (g.mesh.dynamicVertexData ? g.skinningRig.useOriginalMeshVertices(g.mesh) : (this.debugString += "Skinning object - but mesh is not dynamic",
  3837. this.debugString += "<br>Rig index " + g.skinningRigIndex,
  3838. this.debugString += " not tagged as rigid"))))),
  3839. "CameraSO" == g.sceneObjectType && c.cameraObjects.push(g);
  3840. c = this.animations[0];
  3841. b = c.cameraObjects.length;
  3842. for (e = 0; e < b; e++)
  3843. if (f = c.cameraObjects[e],
  3844. d = this.scene.cameras[f.name]) {
  3845. if (d = d.view)
  3846. d = new View(d),
  3847. this.cameraObjectIndices.push(f.id),
  3848. this.views.push(d),
  3849. this.viewYawOffsets.push(0),
  3850. this.viewPitchOffsets.push(0)
  3851. } else
  3852. this.debugString += "<br>no camDesc for " + f.name,
  3853. this.views.push(a.view);
  3854. a = this.scene.meshes.length;
  3855. f = this.subMeshObjectIndices.length;
  3856. for (e = d = 0; e < a; e++)
  3857. for (g = this.scene.meshes[e],
  3858. b = 0; b < f; b++) {
  3859. var h = this.subMeshObjectIndices[b]
  3860. , k = c.animatedObjects[h]
  3861. , n = c.animatedObjects[k.parentIndex];
  3862. n.mesh || (this.debugString += "<br>submesh parent object has no mesh?",
  3863. this.debugString += "<br>obj.name " + k.name,
  3864. this.debugString += "<br>parent.name " + n.name,
  3865. this.debugString += "<br>submesh index " + b,
  3866. this.debugString += "<br>obj.index " + h);
  3867. if (n.mesh == g) {
  3868. for (h = 0; h < g.numSubMeshes; h++)
  3869. this.subMeshLiveIndices[b + (g.numSubMeshes - 1 - h)] = d,
  3870. d++;
  3871. b = f
  3872. }
  3873. }
  3874. for (e = 0; e < f; e++)
  3875. -1 == this.subMeshLiveIndices[e] && (this.debugString += "<br>Missing mesh? Unused submesh " + e + " of " + f);
  3876. this.showDebugInfo = this.stopEverything = this.runDebugMode = !1;
  3877. this.selectDefaultCamera();
  3878. this.findCameraChildren();
  3879. this.findFixedTransforms();
  3880. this.runDebugMode && (this.setAnimationProgress(0, !0),
  3881. "" != this.debugString ? this.stopEverything = !0 : this.checkDebug())
  3882. }
  3883. } else
  3884. this.debugString += "<br>Skip loading animation data"
  3885. }
  3886. SceneAnimator.prototype.logTimes = function() {
  3887. this.debugString += "<br>Times";
  3888. var a = this.animations[0]
  3889. , c = a.animatedObjects.length;
  3890. this.debugString += "<br>Animation totalSeconds " + a.totalSeconds;
  3891. this.debugString += "<br>Animation totalFrames " + a.totalFrames;
  3892. this.debugString += "<br>Animation totalObjects " + c;
  3893. for (var b = 0; b < c; b++) {
  3894. var d = a.animatedObjects[b];
  3895. this.debugString += "<br>Object: " + b;
  3896. this.debugString += " End: " + d.endTime;
  3897. this.debugString += " Length: " + d.animationLength;
  3898. this.debugString += " Frames: " + d.totalFrames
  3899. }
  3900. }
  3901. ;
  3902. SceneAnimator.prototype.flagAllForDebugging = function() {
  3903. for (var a = this.animations.length, c = 0; c < a; c++)
  3904. for (var b = this.animations[c], d = b.animatedObjects.length, e = 0; e < d; e++)
  3905. b.animatedObjects[e].debugMe = !0
  3906. }
  3907. ;
  3908. SceneAnimator.prototype.checkDebug = function() {
  3909. this.debugString = "<br>--------------------------------------Debug Info:";
  3910. this.debugString += "<br>this.selectedAnimationIndex :" + this.selectedAnimationIndex;
  3911. var a = this.animations[this.selectedAnimationIndex]
  3912. , c = a.animatedObjects.length;
  3913. this.debugString += "<br>numAnimatedObjects :" + c;
  3914. "" != a.debugString && (this.debugString += "<br>--------------------------------------------------Got animation bug info:",
  3915. this.debugString += a.debugString,
  3916. this.showDebugInfo = this.stopEverything = !0,
  3917. a.debugString = "");
  3918. for (var b = 0; b < c; b++) {
  3919. var d = a.animatedObjects[b];
  3920. if ("" != d.debugString || "" != d.animatedLocalTransform.debugString)
  3921. this.debugString += "<br>--------------------------------------------------Got object bug info:",
  3922. this.debugString += d.debugString,
  3923. this.debugString += d.animatedLocalTransform.debugString,
  3924. this.showDebugInfo = this.stopEverything = !0,
  3925. d.debugString = "",
  3926. d.animatedLocalTransform.debugString = "";
  3927. d.skinningRig && "" != d.skinningRig.debugString && (this.debugString += "<br>--------------------------------------------------Got skin rig info:",
  3928. this.debugString += d.skinningRig.debugString,
  3929. d.skinningRig.debugString = "",
  3930. this.showDebugInfo = this.stopEverything = !0)
  3931. }
  3932. this.debugString += "<br>--------------------------------------Done Debug Info:"
  3933. }
  3934. ;
  3935. SceneAnimator.prototype.logObjectInfo = function(a, c) {
  3936. var b = this.animations[this.selectedAnimationIndex]
  3937. , d = c * b.originalFPS;
  3938. if (a >= b.animatedObjects.length)
  3939. this.debugString += "object index " + a + " exceeds " + b.animatedObjects.length;
  3940. else {
  3941. var e = b.animatedObjects[a]
  3942. , f = b.animatedObjects[e.modelPartIndex]
  3943. , g = b.getObjectAnimationFramePercent(e, c)
  3944. , h = b.getObjectAnimationFramePercent(f, c);
  3945. this.debugString = "";
  3946. this.debugString += "<br>Object Name: " + e.name;
  3947. this.debugString += "<br>Object Type: " + e.sceneObjectType;
  3948. this.debugString += "<br>Object Index: " + e.id;
  3949. this.debugString += "<br>Part Index: " + e.modelPartIndex;
  3950. this.debugString += "<br>Part Scale: " + e.modelPartScale;
  3951. this.debugString += "<br>Mesh Index: " + e.meshIndex;
  3952. this.debugString += "<br>Light Index: " + e.lightIndex;
  3953. this.debugString += "<br>Deformer Index: " + e.skinningRigIndex;
  3954. this.debugString += "<br>Parent Index: " + e.parentIndex;
  3955. this.debugString += "<br>Scene time " + c;
  3956. this.debugString += "<br>Scene framepercent " + d;
  3957. this.debugString += "<br>Object looped framepercent " + g;
  3958. this.debugString += "<br>Model looped framepercent " + h;
  3959. this.debugString += "<br>Object Anim length " + e.animationLength;
  3960. this.debugString += "<br>Object Total frames " + e.totalFrames;
  3961. this.debugString += "<br>Object FPS " + e.modelPartFPS;
  3962. this.debugString += "<br>Model Part Anim length " + f.animationLength;
  3963. this.debugString += "<br>Model total frames " + f.totalFrames;
  3964. this.debugString += "<br>Model Part FPS " + f.modelPartFPS;
  3965. d = Matrix.identity();
  3966. b.getWorldTransform(e.id, c, d, this.sceneScale, !0);
  3967. this.debugString += e.debugString;
  3968. var b = d[0]
  3969. , e = d[1]
  3970. , f = d[2]
  3971. , g = d[4]
  3972. , h = d[5]
  3973. , k = d[6]
  3974. , n = d[8]
  3975. , m = d[9]
  3976. , d = d[10];
  3977. Math.sqrt(b * b + e * e + f * f);
  3978. Math.sqrt(g * g + h * h + k * k);
  3979. Math.sqrt(n * n + m * m + d * d)
  3980. }
  3981. }
  3982. ;
  3983. SceneAnimator.prototype.resetPlayback = function() {
  3984. this.startMS = Date.now();
  3985. this.animationProgress = this.totalSeconds = 0;
  3986. this.setAnimationProgress(0, !0)
  3987. }
  3988. ;
  3989. SceneAnimator.prototype.pause = function(a) {
  3990. this.paused = a;
  3991. this.startMS = Date.now() - 1E3 * this.totalSeconds / (this.playbackSpeed * this.scenePlaybackSpeed)
  3992. }
  3993. ;
  3994. SceneAnimator.prototype.setAnimationProgress = function(a, c) {
  3995. var b = this.animations[this.selectedAnimationIndex];
  3996. this.animationProgress = a;
  3997. this.totalSeconds = b.totalSeconds * this.animationProgress;
  3998. this.totalSeconds -= 1 / b.originalFPS;
  3999. 0 > this.totalSeconds && (this.totalSeconds = 0);
  4000. this.startMS = Date.now() - 1E3 * this.totalSeconds / (this.playbackSpeed * this.scenePlaybackSpeed);
  4001. c && this.updateScene()
  4002. }
  4003. ;
  4004. SceneAnimator.prototype.setPlaybackSpeed = function(a) {
  4005. this.playbackSpeed = a;
  4006. this.startMS = Date.now() - 1E3 * this.totalSeconds / (this.playbackSpeed * this.scenePlaybackSpeed)
  4007. }
  4008. ;
  4009. SceneAnimator.prototype.resetCustomView = function() {
  4010. 0 <= this.selectedCameraIndex && this.selectedCameraIndex < this.views.length && (this.viewYawOffsets[this.selectedCameraIndex] = 0,
  4011. this.viewPitchOffsets[this.selectedCameraIndex] = 0,
  4012. this.scene.view.rotation[1] = this.views[this.selectedCameraIndex].rotation[1],
  4013. this.scene.view.rotation[0] = this.views[this.selectedCameraIndex].rotation[0],
  4014. this.setViewFromSelectedCamera())
  4015. }
  4016. ;
  4017. SceneAnimator.prototype.updateUserCamera = function() {
  4018. this.clearCacheForCameraChildren();
  4019. if (0 <= this.selectedCameraIndex && this.selectedCameraIndex < this.views.length && this.selectedAnimationIndex < this.animations.length) {
  4020. var a = this.cameraObjectIndices[this.selectedCameraIndex]
  4021. , c = this.animations[this.selectedAnimationIndex];
  4022. if (a < c.animatedObjects.length) {
  4023. var b = this.views[this.selectedCameraIndex]
  4024. , d = this.scene.view.rotation[1]
  4025. , e = this.scene.view.rotation[0]
  4026. , f = e - b.rotation[0];
  4027. this.viewYawOffsets[this.selectedCameraIndex] = d - b.rotation[1];
  4028. this.viewPitchOffsets[this.selectedCameraIndex] = f;
  4029. b = c.animatedObjects[a];
  4030. c.getObjectAnimationFramePercent(b, this.totalSeconds);
  4031. var f = Matrix.identity()
  4032. , g = Matrix.identity();
  4033. b.useFixedWorldTransform = !1;
  4034. b.useFixedLocalTransform = !1;
  4035. b.animatedLocalTransform.lockTransform = !1;
  4036. b.animatedLocalTransform.clearCachedTransforms();
  4037. b.cachedFrame0 = -1;
  4038. b.cachedFrame1 = -1;
  4039. b.cachedFrame2 = -1;
  4040. b.cachedFrame3 = -1;
  4041. b.cachedFrameUse0 = 0;
  4042. b.cachedFrameUse1 = 0;
  4043. b.cachedFrameUse2 = 0;
  4044. b.cachedFrameUse3 = 0;
  4045. c.getWorldTransform(a, this.totalSeconds, g, this.sceneScale, !1);
  4046. var a = g[0]
  4047. , h = g[1]
  4048. , k = g[2]
  4049. , n = g[4]
  4050. , m = g[5]
  4051. , l = g[6]
  4052. , p = g[8]
  4053. , r = g[9]
  4054. , s = g[10]
  4055. , a = Math.sqrt(a * a + h * h + k * k)
  4056. , n = Math.sqrt(n * n + m * m + l * l)
  4057. , m = Math.sqrt(p * p + r * r + s * s)
  4058. , l = -(this.scene.view.pivot[0] - g[12])
  4059. , h = -(this.scene.view.pivot[1] - g[13])
  4060. , g = -(this.scene.view.pivot[2] - g[14]);
  4061. 0 >= l * p + h * r + g * s && (d += 180);
  4062. d = Matrix.rotation(Matrix.empty(), d, 1);
  4063. e = Matrix.rotation(Matrix.empty(), e, 0);
  4064. Matrix.mul(f, d, e);
  4065. e = Math.sqrt(l * l + h * h + g * g);
  4066. d = this.scene.view.pivot[1] + f[9] * e;
  4067. g = this.scene.view.pivot[2] + f[10] * e;
  4068. f[12] = this.scene.view.pivot[0] + f[8] * e;
  4069. f[13] = d;
  4070. f[14] = g;
  4071. e = Matrix.identity();
  4072. c.getWorldTransform(b.parentIndex, this.totalSeconds, e, this.sceneScale, !1);
  4073. c = Matrix.identity();
  4074. Matrix.invert(c, e);
  4075. e = Matrix.identity();
  4076. Matrix.mul(e, c, f);
  4077. e[12] /= this.sceneScale;
  4078. e[13] /= this.sceneScale;
  4079. e[14] /= this.sceneScale;
  4080. f[0] *= a;
  4081. f[1] *= a;
  4082. f[2] *= a;
  4083. f[4] *= n;
  4084. f[5] *= n;
  4085. f[6] *= n;
  4086. f[8] *= m;
  4087. f[9] *= m;
  4088. f[10] *= m;
  4089. b.setFixedWorldTransform(f);
  4090. b.setFixedLocalTransform(e)
  4091. }
  4092. }
  4093. }
  4094. ;
  4095. SceneAnimator.prototype.setViewFromSelectedCamera = function() {
  4096. if (0 <= this.selectedCameraIndex && this.selectedCameraIndex < this.views.length) {
  4097. var a = this.views[this.selectedCameraIndex]
  4098. , c = this.scene.view
  4099. , b = this.viewYawOffsets[this.selectedCameraIndex]
  4100. , d = this.viewPitchOffsets[this.selectedCameraIndex];
  4101. c.pivot[0] = a.pivot[0];
  4102. c.pivot[1] = a.pivot[1];
  4103. c.pivot[2] = a.pivot[2];
  4104. c.rotation[0] = a.rotation[0] + d;
  4105. c.rotation[1] = a.rotation[1] + b;
  4106. c.radius = a.radius;
  4107. c.nearPlane = a.nearPlane;
  4108. c.fov = a.fov;
  4109. c.limits = a.limits;
  4110. c.saveResetView();
  4111. c.updateProjection();
  4112. c.updateView()
  4113. }
  4114. }
  4115. ;
  4116. SceneAnimator.prototype.selectDefaultCamera = function() {
  4117. if (-1 != this.defaultCameraGlobalIndex && 0 < this.animations.length)
  4118. for (var a = this.animations[0], c = a.cameraObjects.length, b = 0; b < c; b++)
  4119. if (a.cameraObjects[b].id == this.defaultCameraGlobalIndex) {
  4120. this.selectedCameraIndex = b;
  4121. return
  4122. }
  4123. this.selectedCameraIndex = 0
  4124. }
  4125. ;
  4126. SceneAnimator.prototype.updateAnimationPlayback = function() {
  4127. if (!this.stopEverything || !this.runDebugMode) {
  4128. var a = this.animations[this.selectedAnimationIndex];
  4129. this.updateUserCamera();
  4130. if (this.paused || !this.playAnimations)
  4131. this.startMS = 0 < this.playbackSpeed ? Date.now() - 1E3 * this.totalSeconds / (this.playbackSpeed * this.scenePlaybackSpeed) : Date.now() - 1E3 * this.totalSeconds,
  4132. this.refreshTransformsOnly(),
  4133. this.runDebugMode && this.checkDebug(),
  4134. a = this.scene.view,
  4135. a.saveResetView(),
  4136. a.updateProjection(),
  4137. a.updateView();
  4138. else {
  4139. this.lockPlayback && 0 < this.playbackSpeed && (this.startMS = Date.now() - 1E3 * this.totalSeconds / (this.playbackSpeed * this.scenePlaybackSpeed));
  4140. var c = (Date.now() - this.startMS) / 1E3 * this.playbackSpeed * this.scenePlaybackSpeed;
  4141. this.totalSeconds = (Date.now() - this.startMS) / 1E3 * this.playbackSpeed * this.scenePlaybackSpeed;
  4142. var b = c / a.totalSeconds
  4143. , c = Math.floor(b)
  4144. , b = b - c;
  4145. c != this.loopCount && (this.loopCount++,
  4146. this.loopTurntables && this.rolloverTurntables(),
  4147. this.autoAdvanceNextAnimation && (this.nextAnimation(),
  4148. this.resetPlayback()));
  4149. this.totalSeconds = a.totalSeconds * b;
  4150. this.animationProgress = this.totalSeconds / a.totalSeconds - Math.floor(this.totalSeconds / a.totalSeconds);
  4151. this.updateScene();
  4152. this.runDebugMode && this.checkDebug()
  4153. }
  4154. }
  4155. }
  4156. ;
  4157. SceneAnimator.prototype.updateScene = function() {
  4158. this.lastSceneFramePercent = this.totalSeconds * this.animations[this.selectedAnimationIndex].originalFPS;
  4159. 0 != this.fogObjectIndex && this.updateFog();
  4160. this.animateTurntables && this.updateTurntables();
  4161. this.animateMeshes && this.poseMeshes();
  4162. this.animateLights && this.updateLights();
  4163. this.animateMaterials && this.updateMaterials();
  4164. this.animateVisibility && this.updateVisibility()
  4165. }
  4166. ;
  4167. SceneAnimator.prototype.findCameraChildren = function() {
  4168. for (var a = this.animations[0], c = a.animatedObjects.length, b = 0; b < c; b++)
  4169. a.hasParentTypeInHierarchy(a.animatedObjects[b], "CameraSO") && this.cameraChildrenIndices.push(b)
  4170. }
  4171. ;
  4172. SceneAnimator.prototype.findFixedTransforms = function() {
  4173. for (var a = this.animations.length, c = 0; c < a; c++)
  4174. for (var b = this.animations[c], d = b.animatedObjects.length, e = 0; e < d; e++) {
  4175. var f = b.animatedObjects[e];
  4176. if (!f.useFixedWorldTransform && !b.hasAnimationInHierarchy(f))
  4177. if ("Material" == f.sceneObjectType)
  4178. f.setFixedWorldTransform(Matrix.identity()),
  4179. f.setFixedLocalTransform(Matrix.identity());
  4180. else {
  4181. var g = Matrix.identity()
  4182. , h = Matrix.identity();
  4183. b.hasParentTypeInHierarchy(f, "SceneRootSO") ? (b.getWorldTransform(f.id, 0, g, this.sceneScale, !1),
  4184. f.evaluateLocalTransformAtFramePercent(0, h, !0, !1)) : (b.evaluateModelPartTransformAtFrame(f.id, 0, g, !1),
  4185. f.evaluateLocalTransformAtFramePercent(0, h, !1, !1));
  4186. f.setFixedWorldTransform(g);
  4187. f.setFixedLocalTransform(h)
  4188. }
  4189. }
  4190. }
  4191. ;
  4192. SceneAnimator.prototype.clearCacheForCameraChildren = function() {
  4193. for (var a = this.animations[this.selectedAnimationIndex], c = this.cameraChildrenIndices.length, b = 0; b < c; b++) {
  4194. var d = a.animatedObjects[this.cameraChildrenIndices[b]];
  4195. d.useFixedWorldTransform = !1;
  4196. d.useFixedLocalTransform = !1;
  4197. d.cachedFrame0 = -10;
  4198. d.cachedFrame1 = -10;
  4199. d.cachedFrame2 = -10;
  4200. d.cachedFrame3 = -10;
  4201. d.cachedFrameUse0 = 0;
  4202. d.cachedFrameUse1 = 0;
  4203. d.cachedFrameUse2 = 0;
  4204. d.cachedFrameUse3 = 0;
  4205. d.animatedLocalTransform.clearCachedTransforms();
  4206. d.animatedLocalTransform.lockTransform = !1
  4207. }
  4208. }
  4209. ;
  4210. SceneAnimator.prototype.refreshTransformsOnly = function() {
  4211. for (var a = this.animations[this.selectedAnimationIndex], c = a.meshObjects.length, b = 0; b < c; b++) {
  4212. var d = a.meshObjects[b];
  4213. a.getWorldTransform(d.id, this.totalSeconds, d.mesh.displayMatrix, this.sceneScale, !0);
  4214. if (this.enableSkinning && d.skinningRig && this.unitScaleSkinnedMeshes && !d.skinningRig.isRigidSkin) {
  4215. var d = d.mesh.displayMatrix
  4216. , e = d[0]
  4217. , f = d[1]
  4218. , g = d[2]
  4219. , h = d[4]
  4220. , k = d[5]
  4221. , n = d[6]
  4222. , m = d[8]
  4223. , l = d[9]
  4224. , p = d[10]
  4225. , e = Math.sqrt(e * e + f * f + g * g)
  4226. , h = Math.sqrt(h * h + k * k + n * n)
  4227. , m = Math.sqrt(m * m + l * l + p * p)
  4228. , m = (e + h + m) / 2;
  4229. d[0] /= m;
  4230. d[1] /= m;
  4231. d[2] /= m;
  4232. d[4] /= m;
  4233. d[5] /= m;
  4234. d[6] /= m;
  4235. d[8] /= m;
  4236. d[9] /= m;
  4237. d[10] /= m
  4238. }
  4239. }
  4240. if (this.animateLights)
  4241. for (c = a.lightObjects.length,
  4242. b = 0; b < c; b++)
  4243. d = a.lightObjects[b],
  4244. d.useFixedWorldTransform || (m = this.scene.lights.getLightPos(d.lightIndex),
  4245. l = this.scene.lights.getLightDir(d.lightIndex),
  4246. p = Matrix.identity(),
  4247. a.getWorldTransform(d.id, this.totalSeconds, p, this.sceneScale, !0),
  4248. l[0] = p[8],
  4249. l[1] = p[9],
  4250. l[2] = p[10],
  4251. 0 != m[3] ? (m[0] = p[12],
  4252. m[1] = p[13],
  4253. m[2] = p[14],
  4254. this.scene.lights.setLightPos(d.lightIndex, m)) : this.scene.lights.setLightPos(d.lightIndex, l),
  4255. this.scene.lights.setLightDir(d.lightIndex, l))
  4256. }
  4257. ;
  4258. SceneAnimator.prototype.findMeshIndexByPartIndex = function(a, c) {
  4259. for (var b = 0; b < this.meshIDs.length; ++b)
  4260. if (c == this.meshIDs[b])
  4261. return b;
  4262. return -1
  4263. }
  4264. ;
  4265. SceneAnimator.prototype.findLightIndexByPartIndex = function(a) {
  4266. for (var c = 0; c < this.lightIDs.length; c++)
  4267. if (a == this.lightIDs[c])
  4268. return c;
  4269. return -1
  4270. }
  4271. ;
  4272. SceneAnimator.prototype.findMaterialIndexByPartIndex = function(a) {
  4273. for (var c = 0; c < this.materialIDs.length; c++)
  4274. if (a == this.materialIDs[c])
  4275. return c;
  4276. return -1
  4277. }
  4278. ;
  4279. SceneAnimator.prototype.nextAnimation = function() {
  4280. this.selectedAnimationIndex++;
  4281. this.selectedAnimationIndex >= this.animations.length && (this.selectedAnimationIndex = 0)
  4282. }
  4283. ;
  4284. SceneAnimator.prototype.selectAnimation = function(a) {
  4285. 0 <= a && a < this.animations.length && (this.selectedAnimationIndex = a);
  4286. this.paused && this.setAnimationProgress(this.animationProgress, !0)
  4287. }
  4288. ;
  4289. SceneAnimator.prototype.selectCamera = function(a) {
  4290. -1 != a && this.selectedCameraIndex != a && (this.selectedCameraIndex = a,
  4291. this.setViewFromSelectedCamera())
  4292. }
  4293. ;
  4294. SceneAnimator.prototype.getAnimatedCamera = function() {
  4295. if (0 <= this.selectedCameraIndex && this.selectedAnimationIndex < this.animations.length) {
  4296. var a = this.animations[this.selectedAnimationIndex];
  4297. if (this.selectedCameraIndex < a.cameraObjects.length)
  4298. return a.cameraObjects[this.selectedCameraIndex]
  4299. }
  4300. }
  4301. ;
  4302. SceneAnimator.prototype.poseMeshes = function() {
  4303. for (var a = this.animations[this.selectedAnimationIndex], c = a.meshObjects.length, b = 0; b < c; b++) {
  4304. var d = a.meshObjects[b];
  4305. if (this.enableSkinning && d.skinningRig)
  4306. if (d.skinningRig.isRigidSkin)
  4307. a.getWorldTransform(d.id, this.totalSeconds, d.mesh.displayMatrix, this.sceneScale, !0);
  4308. else {
  4309. d.setupSkinningRig(a, d.modelPartIndex, this.totalSeconds, d.skinningRig);
  4310. a.getWorldTransform(d.id, this.totalSeconds, d.mesh.displayMatrix, this.sceneScale, !0);
  4311. var e = d.modelPartScale * this.sceneScale;
  4312. if (this.unitScaleSkinnedMeshes) {
  4313. var f = d.mesh.displayMatrix
  4314. , g = f[0]
  4315. , h = f[1]
  4316. , k = f[2]
  4317. , n = f[4]
  4318. , m = f[5]
  4319. , l = f[6]
  4320. , p = f[8]
  4321. , r = f[9]
  4322. , s = f[10]
  4323. , g = Math.sqrt(g * g + h * h + k * k)
  4324. , n = Math.sqrt(n * n + m * m + l * l)
  4325. , p = Math.sqrt(p * p + r * r + s * s)
  4326. , p = (g + n + p) / 2;
  4327. f[0] /= p;
  4328. f[1] /= p;
  4329. f[2] /= p;
  4330. f[4] /= p;
  4331. f[5] /= p;
  4332. f[6] /= p;
  4333. f[8] /= p;
  4334. f[9] /= p;
  4335. f[10] /= p;
  4336. e *= p
  4337. }
  4338. d.skinningRig.deformMesh(d.mesh, e)
  4339. }
  4340. else
  4341. a.getWorldTransform(d.id, this.totalSeconds, d.mesh.displayMatrix, this.sceneScale, !0)
  4342. }
  4343. }
  4344. ;
  4345. SceneAnimator.prototype.updateLights = function() {
  4346. for (var a = this.animations[this.selectedAnimationIndex], c = this.totalSeconds * a.originalFPS, b = a.lightObjects.length, d = 0; d < b; d++) {
  4347. var e = a.lightObjects[d]
  4348. , f = this.scene.lights.getLightPos(e.lightIndex)
  4349. , g = this.scene.lights.getLightDir(e.lightIndex)
  4350. , h = this.scene.lights.getLightColor(e.lightIndex)
  4351. , k = Matrix.identity()
  4352. , n = 1;
  4353. e.useFixedWorldTransform || a.getWorldTransform(e.id, this.totalSeconds, k, this.sceneScale, !0);
  4354. e.redProperty && (e.redProperty.evaluate(c, h[0], e),
  4355. h[0] = e.redProperty.lastValue);
  4356. e.greenProperty && (e.greenProperty.evaluate(c, h[1], e),
  4357. h[1] = e.greenProperty.lastValue);
  4358. e.blueProperty && (e.blueProperty.evaluate(c, h[2], e),
  4359. h[2] = e.blueProperty.lastValue);
  4360. e.brightnessProperty && (e.brightnessProperty.evaluate(c, n, e),
  4361. n = e.brightnessProperty.lastValue);
  4362. h[0] *= n;
  4363. h[1] *= n;
  4364. h[2] *= n;
  4365. 0 != f[3] ? (e.useFixedWorldTransform || (f[0] = k[12],
  4366. f[1] = k[13],
  4367. f[2] = k[14],
  4368. this.scene.lights.setLightPos(e.lightIndex, f)),
  4369. e.spotAngleProperty && 0 < this.scene.lights.spot[3 * e.lightIndex] && (f = 0,
  4370. e.spotAngleProperty.evaluate(c, f, e),
  4371. f = e.spotAngleProperty.lastValue,
  4372. this.scene.lights.setLightSpotAngle(e.lightIndex, f)),
  4373. e.spotSharpnessProperty && (f = 0,
  4374. e.spotSharpnessProperty.evaluate(c, f, e),
  4375. f = e.spotSharpnessProperty.lastValue,
  4376. this.scene.lights.setLightSpotSharpness(e.lightIndex, f)),
  4377. e.distanceProperty && (f = 1,
  4378. e.distanceProperty.evaluate(c, f, e),
  4379. f = e.distanceProperty.lastValue * this.sceneScale,
  4380. this.scene.lights.setLightDistance(e.lightIndex, f))) : this.scene.lights.setLightPos(e.lightIndex, g);
  4381. e.useFixedWorldTransform || (g[0] = k[8],
  4382. g[1] = k[9],
  4383. g[2] = k[10],
  4384. this.scene.lights.setLightDir(e.lightIndex, g));
  4385. this.scene.lights.setLightColor(e.lightIndex, h)
  4386. }
  4387. }
  4388. ;
  4389. SceneAnimator.prototype.updateTurntables = function() {
  4390. for (var a = this.animations[this.selectedAnimationIndex], c = this.totalSeconds * a.originalFPS, b = a.turnTableObjects.length, d = 0; d < b; d++) {
  4391. var e = a.turnTableObjects[d];
  4392. e.spinProperty.evaluate(c, 0, e);
  4393. e.turnTableSpin = e.turnTableSpinOffset + e.spinProperty.lastValue * this.totalSeconds
  4394. }
  4395. }
  4396. ;
  4397. SceneAnimator.prototype.rolloverTurntables = function() {
  4398. for (var a = this.animations[this.selectedAnimationIndex], c = a.turnTableObjects.length, b = 0; b < c; b++) {
  4399. var d = a.turnTableObjects[b];
  4400. d.turnTableSpinOffset = d.turnTableSpin
  4401. }
  4402. }
  4403. ;
  4404. SceneAnimator.prototype.updateMaterials = function() {
  4405. for (var a = this.animations[this.selectedAnimationIndex], c = this.totalSeconds * a.originalFPS, b = a.materialObjects.length, d = 0; d < b; d++) {
  4406. var e = a.materialObjects[d];
  4407. e.offsetUProperty && (e.offsetUProperty.evaluate(c, 0, e),
  4408. this.scene.materialsList[e.materialIndex].uOffset = e.offsetUProperty.lastValue);
  4409. e.offsetVProperty && (e.offsetVProperty.evaluate(c, 0, e),
  4410. this.scene.materialsList[e.materialIndex].vOffset = e.offsetVProperty.lastValue);
  4411. e.emissiveProperty && 1 < e.emissiveProperty.numKeyframes && (e.emissiveProperty.evaluate(c, 0, e),
  4412. this.scene.materialsList[e.materialIndex].emissiveIntensity = e.emissiveProperty.lastValue)
  4413. }
  4414. }
  4415. ;
  4416. SceneAnimator.prototype.updateFog = function() {
  4417. var a = this.animations[this.selectedAnimationIndex]
  4418. , c = this.totalSeconds * a.originalFPS;
  4419. 0 <= this.fogObjectIndex && this.fogObjectIndex < a.animatedObjects.length && this.scene.fog && (a = a.animatedObjects[this.fogObjectIndex],
  4420. a.redProperty && (this.scene.fog.desc.color[0] = a.redProperty.evaluate(c, this.scene.fog.desc.color[0], a)),
  4421. a.greenProperty && (this.scene.fog.desc.color[1] = a.greenProperty.evaluate(c, this.scene.fog.desc.color[1], a)),
  4422. a.blueProperty && (this.scene.fog.desc.color[2] = a.blueProperty.evaluate(c, this.scene.fog.desc.color[2], a)),
  4423. a.distanceProperty && (this.scene.fog.desc.distance = a.distanceProperty.evaluate(c, this.scene.fog.desc.distance, a)),
  4424. a.opacityProperty && (this.scene.fog.desc.opacity = a.opacityProperty.evaluate(c, this.scene.fog.desc.opacity, a)),
  4425. a.skyIllumProperty && (this.scene.fog.desc.skyIllum = a.skyIllumProperty.evaluate(c, this.scene.fog.desc.skyIllum, a)),
  4426. a.lightIllumProperty && (this.scene.fog.desc.lightIllum = a.lightIllumProperty.evaluate(c, this.scene.fog.desc.lightIllum, a)),
  4427. a.dispersionProperty && (this.scene.fog.desc.dispersion = a.dispersionProperty.evaluate(c, this.scene.fog.desc.dispersion, a)))
  4428. }
  4429. ;
  4430. SceneAnimator.prototype.updateVisibility = function() {
  4431. for (var a = this.animations[this.selectedAnimationIndex], c = this.subMeshObjectIndices.length, b = 0; b < c; b++) {
  4432. var d = this.subMeshLiveIndices[b];
  4433. if (-1 != d) {
  4434. var e = this.subMeshObjectIndices[b]
  4435. , d = this.scene.meshRenderables[d]
  4436. , f = a.getObjectAnimationFramePercent(a.animatedObjects[e], this.totalSeconds);
  4437. d.visible = a.isVisibleAtFramePercent(e, f)
  4438. }
  4439. }
  4440. }
  4441. ;
  4442. function Shader(a) {
  4443. this.gl = a;
  4444. this.program = null;
  4445. this.params = {};
  4446. this.samplers = {};
  4447. this.attribs = {}
  4448. }
  4449. Shader.prototype.build = function(a, c) {
  4450. var b = this.gl;
  4451. this.program = b.createProgram();
  4452. this.params = {};
  4453. this.samplers = {};
  4454. this.attribs = {};
  4455. var d = function(a) {
  4456. for (var b = "", c = a.indexOf("\n"), d = 0; -1 != c; )
  4457. d++,
  4458. b += d + ": ",
  4459. b += a.substring(0, c + 1),
  4460. a = a.substring(c + 1, a.length),
  4461. c = a.indexOf("\n");
  4462. console.log(b)
  4463. }
  4464. , e = b.createShader(b.VERTEX_SHADER);
  4465. b.shaderSource(e, a);
  4466. b.compileShader(e);
  4467. b.getShaderParameter(e, b.COMPILE_STATUS) || (console.log(b.getShaderInfoLog(e)),
  4468. marmoset.verboseErrors && d(a));
  4469. b.attachShader(this.program, e);
  4470. e = b.createShader(b.FRAGMENT_SHADER);
  4471. b.shaderSource(e, c);
  4472. b.compileShader(e);
  4473. b.getShaderParameter(e, b.COMPILE_STATUS) || (console.log(b.getShaderInfoLog(e)),
  4474. marmoset.verboseErrors && d(c));
  4475. b.attachShader(this.program, e);
  4476. b.linkProgram(this.program);
  4477. b.getProgramParameter(this.program, b.LINK_STATUS) || console.log(b.getProgramInfoLog(this.program));
  4478. for (var e = b.getProgramParameter(this.program, b.ACTIVE_UNIFORMS), f = 0, d = 0; d < e; ++d) {
  4479. var g = b.getActiveUniform(this.program, d)
  4480. , h = g.name
  4481. , k = h.indexOf("[");
  4482. 0 <= k && (h = h.substring(0, k));
  4483. k = b.getUniformLocation(this.program, g.name);
  4484. g.type == b.SAMPLER_2D || g.type == b.SAMPLER_CUBE ? this.samplers[h] = {
  4485. location: k,
  4486. unit: f++
  4487. } : this.params[h] = k
  4488. }
  4489. e = b.getProgramParameter(this.program, b.ACTIVE_ATTRIBUTES);
  4490. for (d = 0; d < e; ++d)
  4491. f = b.getActiveAttrib(this.program, d),
  4492. this.attribs[f.name] = b.getAttribLocation(this.program, f.name)
  4493. }
  4494. ;
  4495. Shader.prototype.bind = function() {
  4496. return this.program ? (this.gl.useProgram(this.program),
  4497. !0) : !1
  4498. }
  4499. ;
  4500. Shader.prototype.complete = function() {
  4501. return !!this.program
  4502. }
  4503. ;
  4504. function ShaderCache(a) {
  4505. this.gl = a;
  4506. this.cache = []
  4507. }
  4508. ShaderCache.prototype.fromURLs = function(a, c, b) {
  4509. var d = "";
  4510. if (b)
  4511. for (var e = 0; e < b.length; ++e)
  4512. d = b[e] + "\n" + d;
  4513. b = d + ":" + a + "|" + c;
  4514. e = this.cache[b];
  4515. if (void 0 !== e)
  4516. return e;
  4517. var f = new Shader(this.gl)
  4518. , g = null
  4519. , h = null
  4520. , k = function() {
  4521. null != g && null != h && f.build(g, h)
  4522. };
  4523. this.fetch(a, function(a) {
  4524. g = d + a;
  4525. k()
  4526. });
  4527. this.fetch(c, function(a) {
  4528. h = d + a;
  4529. k()
  4530. });
  4531. return this.cache[b] = f
  4532. }
  4533. ;
  4534. ShaderCache.prototype.fetch = function(a, c) {
  4535. "undefined" != typeof ShaderTable ? void 0 !== ShaderTable[a] ? this.resolveIncludes(new String(ShaderTable[a]), c) : c("") : Network.fetchText("src/shader/" + a, function(a) {
  4536. this.resolveIncludes(a, c)
  4537. }
  4538. .bind(this), function() {
  4539. c("")
  4540. })
  4541. }
  4542. ;
  4543. ShaderCache.prototype.resolveIncludes = function(a, c) {
  4544. for (var b = [], d = !0, e = function(a, c, e, f, m) {
  4545. d = !0;
  4546. b.push({
  4547. offset: m,
  4548. path: c.slice(1, c.length - 1)
  4549. });
  4550. return ""
  4551. }; d; )
  4552. d = !1,
  4553. a = a.replace(/#include\s((<[^>]+>)|("[^"]+"))/, e);
  4554. if (0 < b.length)
  4555. for (var f = b.length, e = 0; e < b.length; ++e)
  4556. this.fetch(b[e].path, function(d) {
  4557. this.src = d;
  4558. if (0 >= --f) {
  4559. for (d = b.length - 1; 0 <= d; --d)
  4560. a = a.substring(0, b[d].offset) + b[d].src + a.substring(b[d].offset);
  4561. c(a)
  4562. }
  4563. }
  4564. .bind(b[e]));
  4565. else
  4566. c(a)
  4567. }
  4568. ;
  4569. function ShadowCollector(a, c) {
  4570. this.gl = a;
  4571. this.shadowCount = c;
  4572. this.nativeDepth = !!a.ext.textureDepth;
  4573. this.desc = b;
  4574. b = this.nativeDepth ? ["#define SHADOW_NATIVE_DEPTH"] : [];
  4575. this.shaderSolid = a.shaderCache.fromURLs("shadowvert.glsl", "shadowfrag.glsl", b);
  4576. b.push("#define ALPHA_TEST 1");
  4577. this.shaderAlphaTest = a.shaderCache.fromURLs("shadowvert.glsl", "shadowfrag.glsl", b);
  4578. this.depthTextures = [];
  4579. this.depthTargets = [];
  4580. if (0 < this.shadowCount) {
  4581. var b = {
  4582. width: 2048,
  4583. height: 2048,
  4584. clamp: !0,
  4585. mipmap: !1,
  4586. nofilter: !0
  4587. };
  4588. a.hints.mobile && (b.width = b.height = 1536);
  4589. var d = {
  4590. width: b.width,
  4591. height: b.height
  4592. }, e, f;
  4593. this.nativeDepth ? (e = a.DEPTH_COMPONENT,
  4594. f = a.UNSIGNED_SHORT) : (d.depthBuffer = Framebuffer.createDepthBuffer(a, b.width, b.height),
  4595. e = a.RGB,
  4596. f = a.UNSIGNED_BYTE);
  4597. for (var g = 0; g < this.shadowCount; ++g)
  4598. this.depthTextures[g] = new Texture(a,b),
  4599. this.depthTextures[g].loadArray(null, e, f),
  4600. this.nativeDepth ? d.depth = this.depthTextures[g] : d.color0 = this.depthTextures[g],
  4601. this.depthTargets[g] = new Framebuffer(a,d)
  4602. }
  4603. }
  4604. ShadowCollector.prototype.bindDepthTexture = function(a, c) {
  4605. this.shadowCount > c && this.depthTextures[c].bind(a)
  4606. }
  4607. ;
  4608. ShadowCollector.prototype.collect = function(a, c) {
  4609. for (var b = this.gl, d = a.lights, e = d.shadowCount, f = d.modelViewBuffer, g = d.projectionBuffer, h = d.matrix, k = 0 != a.sceneAnimator, n = Matrix.empty(), m = !1, l = 0; l < e; ++l)
  4610. if (d.shadowsNeedUpdate[l]) {
  4611. d.shadowsNeedUpdate[l] = 0;
  4612. m = !0;
  4613. Matrix.mul(n, f.subarray(16 * l, 16 * (l + 1)), h);
  4614. Matrix.mul(n, g.subarray(16 * l, 16 * (l + 1)), n);
  4615. this.depthTargets[l].bind();
  4616. b.clearColor(1, 1, 1, 1);
  4617. b.clear(b.COLOR_BUFFER_BIT | b.DEPTH_BUFFER_BIT);
  4618. var p = this.shaderSolid;
  4619. p.bind();
  4620. b.uniformMatrix4fv(p.params.uViewProjection, !1, n);
  4621. b.uniformMatrix4fv(p.params.uMeshTransform, !1, Matrix.identity());
  4622. for (var r = 0; r < a.meshRenderables.length; ++r) {
  4623. var s = a.meshRenderables[r]
  4624. , u = s.material;
  4625. !s.mesh.desc.castShadows || !u.castShadows || 0 < u.shadowAlphaTest || (k && b.uniformMatrix4fv(p.params.uMeshTransform, !1, s.mesh.displayMatrix),
  4626. s.drawShadow(p.attribs.vPosition))
  4627. }
  4628. p = this.shaderAlphaTest;
  4629. p.bind();
  4630. b.uniformMatrix4fv(p.params.uViewProjection, !1, n);
  4631. b.uniformMatrix4fv(p.params.uMeshTransform, !1, Matrix.identity());
  4632. for (r = 0; r < a.meshRenderables.length; ++r)
  4633. s = a.meshRenderables[r],
  4634. u = s.material,
  4635. s.mesh.desc.castShadows && u.castShadows && 0 < u.shadowAlphaTest && (u.textures.albedo.bind(p.samplers.tAlbedo),
  4636. k && (b.uniform2f(p.params.uUVOffset, u.uOffset, u.vOffset),
  4637. b.uniformMatrix4fv(p.params.uMeshTransform, !1, s.mesh.displayMatrix)),
  4638. s.drawAlphaShadow(p.attribs.vPosition, p.attribs.vTexCoord))
  4639. }
  4640. m && (c.bind(),
  4641. b.enable(b.CULL_FACE),
  4642. b.cullFace(b.BACK))
  4643. }
  4644. ;
  4645. ShadowCollector.prototype.complete = function() {
  4646. return this.shaderSolid.complete() && this.shaderAlphaTest.complete()
  4647. }
  4648. ;
  4649. function ShadowFloor(a, c, b, d) {
  4650. this.gl = a;
  4651. this.desc = c;
  4652. this.lightCount = d.count;
  4653. this.shadowCount = b.shadowCount;
  4654. c = this.nativeDepth ? ["#define SHADOW_NATIVE_DEPTH"] : [];
  4655. c.push("#define LIGHT_COUNT " + this.lightCount);
  4656. c.push("#define SHADOW_COUNT " + this.shadowCount);
  4657. a.hints.mobile && c.push("#define MOBILE");
  4658. this.shader = a.shaderCache.fromURLs("shadowfloorvert.glsl", "shadowfloorfrag.glsl", c);
  4659. c = new Float32Array([-1, 0, -1, -1, 0, 1, 1, 0, 1, -1, 0, -1, 1, 0, 1, 1, 0, -1]);
  4660. this.quadGeom = a.createBuffer();
  4661. a.bindBuffer(a.ARRAY_BUFFER, this.quadGeom);
  4662. a.bufferData(a.ARRAY_BUFFER, c, a.STATIC_DRAW);
  4663. a.bindBuffer(a.ARRAY_BUFFER, null)
  4664. }
  4665. ShadowFloor.prototype.draw = function(a) {
  4666. var c = a.view
  4667. , b = a.lights
  4668. , d = a.shadow
  4669. , e = this.gl
  4670. , f = this.shader.params
  4671. , g = this.shader.samplers;
  4672. this.shader.bind();
  4673. c = Matrix.mul(Matrix.empty(), c.projectionMatrix, c.viewMatrix);
  4674. Matrix.mul(c, c, this.desc.transform);
  4675. e.uniformMatrix4fv(f.uModelViewProjectionMatrix, !1, c);
  4676. c = Matrix.mul(Matrix.empty(), b.matrix, this.desc.transform);
  4677. e.uniformMatrix4fv(f.uModelSkyMatrix, !1, c);
  4678. 0 < b.count && (e.uniform4fv(f.uLightPositions, b.positionBuffer),
  4679. e.uniform3fv(f.uLightDirections, b.directionBuffer),
  4680. e.uniform3fv(f.uLightColors, b.colors),
  4681. e.uniform3fv(f.uLightParams, b.parameters),
  4682. e.uniform3fv(f.uLightSpot, b.spot),
  4683. a = 0.392699 * a.postRender.currentSample(),
  4684. e.uniform2f(f.uShadowKernelRotation, 0.5 * Math.cos(a), 0.5 * Math.sin(a)),
  4685. 0 < b.shadowCount && (a = d.depthTextures[0].desc.width,
  4686. e.uniform2f(f.uShadowMapSize, a, 1 / a),
  4687. e.uniformMatrix4fv(f.uShadowMatrices, !1, b.finalTransformBuffer),
  4688. e.uniformMatrix4fv(f.uInvShadowMatrices, !1, b.inverseTransformBuffer),
  4689. e.uniform4fv(f.uShadowTexelPadProjections, b.shadowTexelPadProjections),
  4690. d.bindDepthTexture(g.tDepth0, 0),
  4691. d.bindDepthTexture(g.tDepth1, 1),
  4692. d.bindDepthTexture(g.tDepth2, 2)));
  4693. e.uniform3f(f.uShadowCatcherParams, this.desc.simple ? 1 : 0, this.desc.alpha, this.desc.edgeFade);
  4694. e.depthMask(!1);
  4695. e.enable(e.BLEND);
  4696. e.blendFunc(e.ZERO, e.SRC_COLOR);
  4697. b = this.shader.attribs.vPosition;
  4698. e.bindBuffer(e.ARRAY_BUFFER, this.quadGeom);
  4699. e.enableVertexAttribArray(b);
  4700. e.vertexAttribPointer(b, 3, e.FLOAT, !1, 0, 0);
  4701. e.drawArrays(e.TRIANGLES, 0, 6);
  4702. e.disableVertexAttribArray(b);
  4703. e.bindBuffer(e.ARRAY_BUFFER, null);
  4704. e.disable(e.BLEND);
  4705. e.depthMask(!0)
  4706. }
  4707. ;
  4708. ShadowFloor.prototype.complete = function() {
  4709. return this.shader.complete()
  4710. }
  4711. ;
  4712. function Skin(a) {
  4713. this.numVertices = a.vertexCount;
  4714. this.vertices = new Float32Array(a.vertexCount);
  4715. a.vertexBuffer || (this.numVertices = 0)
  4716. }
  4717. ;function SkinningCluster() {
  4718. this.associateObjectIndex = this.linkObjectIndex = this.linkMode = 0;
  4719. this.vertexIndices = [];
  4720. this.vertexWeights = [];
  4721. this.matrix = Matrix.identity();
  4722. this.defaultAssociateWorldTransform = this.defaultClusterWorldTransform = this.defaultClusterBaseTransform = 0;
  4723. this.defaultClusterWorldTransformInvert = Matrix.identity();
  4724. this.defaultAssociateWorldTransformInvert = Matrix.identity();
  4725. this.debugString = ""
  4726. }
  4727. SkinningCluster.prototype.solveAdditiveClusterTransform = function(a, c, b) {
  4728. c = Matrix.identity();
  4729. var d = Matrix.identity()
  4730. , e = Matrix.identity();
  4731. Matrix.mul(c, a, this.defaultClusterBaseTransform);
  4732. Matrix.mul(d, this.defaultAssociateWorldTransformInvert, c);
  4733. Matrix.mul(e, this.defaultAssociateWorldTransformInvert, d);
  4734. Matrix.mul(b, this.defaultClusterWorldTransformInvert, e)
  4735. }
  4736. ;
  4737. SkinningCluster.prototype.solveSimpleClusterTransform = function(a, c, b) {
  4738. var d = Matrix.identity()
  4739. , e = Matrix.identity();
  4740. Matrix.invert(e, c);
  4741. Matrix.mul(d, e, a);
  4742. Matrix.mul(b, d, this.defaultClusterBaseTransform)
  4743. }
  4744. ;
  4745. SkinningCluster.prototype.solveClusterTransformAtFrame = function(a, c, b, d) {
  4746. if (1 == this.linkMode) {
  4747. var e = Matrix.identity();
  4748. c = Matrix.identity();
  4749. a.evaluateModelPartTransformAtFrame(this.linkObjectIndex, b, e, !1);
  4750. a.evaluateModelPartTransformAtFrame(this.associateObjectIndex, b, c, !1);
  4751. this.solveAdditiveClusterTransform(e, c, d)
  4752. } else {
  4753. var e = Matrix.identity()
  4754. , f = Matrix.identity();
  4755. a.evaluateModelPartTransformAtFrame(this.linkObjectIndex, b, e, !1);
  4756. a.evaluateModelPartTransformAtFrame(c, b, f, !1);
  4757. this.solveSimpleClusterTransform(e, f, d)
  4758. }
  4759. }
  4760. ;
  4761. function SkinningRig(a, c, b) {
  4762. this.debugString = "";
  4763. this.skinningClusters = [];
  4764. this.srcVFile = c.file;
  4765. if (a = a.get(this.srcVFile))
  4766. if (a.data) {
  4767. this.rigByteStream = new ByteStream(a.data);
  4768. a = new Uint32Array(this.rigByteStream.bytes.buffer,0,this.rigByteStream.bytes.length / 4);
  4769. this.expectedNumClusters = a[0];
  4770. this.expectedNumVertices = a[1];
  4771. this.numClusterLinks = a[2];
  4772. this.originalObjectIndex = a[3];
  4773. this.isRigidSkin = a[4];
  4774. this.tangentMethod = a[5];
  4775. c = 6 + 7 * this.expectedNumClusters;
  4776. for (var d = 0; d < this.expectedNumClusters; d++) {
  4777. var e = new SkinningCluster;
  4778. this.skinningClusters.push(e);
  4779. var f = 6 + 7 * d;
  4780. e.linkMode = a[f + 1];
  4781. e.linkObjectIndex = a[f + 2];
  4782. e.associateObjectIndex = a[f + 3];
  4783. var g = a[f + 5];
  4784. e.defaultClusterWorldTransform = b.getMatrix(a[f + 4]);
  4785. e.defaultClusterBaseTransform = b.getMatrix(g);
  4786. Matrix.invert(e.defaultClusterWorldTransformInvert, e.defaultClusterWorldTransform);
  4787. 1 == e.linkMode && (e.defaultAssociateWorldTransform = b.getMatrix(a[f + 6]),
  4788. Matrix.invert(e.defaultAssociateWorldTransformInvert, e.defaultAssociateWorldTransform))
  4789. }
  4790. b = 4 * c;
  4791. c = b + this.expectedNumVertices;
  4792. a = c + 2 * this.numClusterLinks;
  4793. c = new Uint8Array(this.rigByteStream.bytes.subarray(c));
  4794. a = new Uint8Array(this.rigByteStream.bytes.subarray(a));
  4795. this.linkMapCount = new Uint8Array(this.rigByteStream.bytes.buffer,b,this.expectedNumVertices);
  4796. this.linkMapClusterIndices = new Uint16Array(c.buffer);
  4797. this.linkMapWeights = new Float32Array(a.buffer)
  4798. } else
  4799. this.debugString += "<br>No data in " + this.srcVFile;
  4800. else
  4801. this.debugString += "<br>Error loading buffer for skinning rig " + this.srcVFile
  4802. }
  4803. SkinningRig.prototype.unpackUnitVectors = function(a, c, b, d) {
  4804. for (var e = 0; e < b; e++) {
  4805. var f = c[d * e]
  4806. , g = c[d * e + 1]
  4807. , h = 32768 <= g;
  4808. h && (g -= 32768);
  4809. var f = f / 32767.4 * 2 - 1
  4810. , g = g / 32767.4 * 2 - 1
  4811. , k = 1 - (f * f + g * g)
  4812. , k = Math.sqrt(k)
  4813. , k = isNaN(k) ? 0 : k;
  4814. h && (k = -k);
  4815. a[3 * e] = f;
  4816. a[3 * e + 1] = g;
  4817. a[3 * e + 2] = k
  4818. }
  4819. }
  4820. ;
  4821. SkinningRig.prototype.copyOriginalVertices = function(a) {
  4822. if (!this.unTransformedVertices)
  4823. if (this.unTransformedVertices = new Float32Array(3 * a.vertexCount),
  4824. this.unTransformedNormals = new Float32Array(3 * a.vertexCount),
  4825. this.unTransformedTangents = new Float32Array(3 * a.vertexCount),
  4826. this.unTransformedBiTangents = new Float32Array(3 * a.vertexCount),
  4827. this.skinVertexWeights = new Float32Array(a.vertexCount),
  4828. this.skinVertexTransform4x3 = new Float32Array(12),
  4829. a.dynamicVertexData) {
  4830. var c = new Float32Array(a.dynamicVertexData.buffer);
  4831. new Uint8Array(a.dynamicVertexData.buffer);
  4832. var b = 0
  4833. , d = b
  4834. , b = b + 12 + 8;
  4835. a.secondaryTexCoord && (b += 8);
  4836. var e = b
  4837. , f = b += 4
  4838. , b = b + 4
  4839. , g = a.stride / 2
  4840. , b = new Uint8Array(a.dynamicVertexData.subarray(b))
  4841. , b = new Uint16Array(b.buffer)
  4842. , e = new Uint8Array(a.dynamicVertexData.subarray(e))
  4843. , e = new Uint16Array(e.buffer)
  4844. , f = new Uint8Array(a.dynamicVertexData.subarray(f))
  4845. , f = new Uint16Array(f.buffer);
  4846. this.unpackUnitVectors(this.unTransformedNormals, b, a.vertexCount, g);
  4847. this.unpackUnitVectors(this.unTransformedTangents, e, a.vertexCount, g);
  4848. this.unpackUnitVectors(this.unTransformedBiTangents, f, a.vertexCount, g);
  4849. for (g = 0; g < a.vertexCount; g++)
  4850. f = (a.stride * g + d) / 4,
  4851. this.unTransformedVertices[3 * g] = c[f],
  4852. this.unTransformedVertices[3 * g + 1] = c[f + 1],
  4853. this.unTransformedVertices[3 * g + 2] = c[f + 2]
  4854. } else
  4855. this.debugString += "<br>Can't init skinning rig - mesh buffer is not dynamic - rigid is " + this.isRigidSkin
  4856. }
  4857. ;
  4858. SkinningRig.prototype.useOriginalMeshVertices = function(a) {
  4859. this.isRigidSkin ? this.debugString += "<br>useOriginalMeshVertices for rigid skin?" : this.copyOriginalVertices(a)
  4860. }
  4861. ;
  4862. SkinningRig.prototype.deformMeshVertices = function(a, c) {
  4863. if (0 != this.skinningClusters.length && this.unTransformedVertices) {
  4864. var b = a.stride / 4
  4865. , d = new Float32Array(a.dynamicVertexData.buffer)
  4866. , e = new Uint16Array(a.dynamicVertexData.buffer);
  4867. new Uint8Array(a.dynamicVertexData.buffer);
  4868. var f;
  4869. f = 20;
  4870. a.secondaryTexCoord && (f += 8);
  4871. var g = f
  4872. , h = f += 4;
  4873. f += 4;
  4874. for (var k = this.unTransformedVertices.length / 3, n = 0, m = 0; m < k; ++m) {
  4875. var l = m
  4876. , p = (l * a.stride + g) / 2
  4877. , r = (l * a.stride + h) / 2
  4878. , s = (l * a.stride + f) / 2
  4879. , u = this.linkMapCount[l]
  4880. , q = this.skinVertexTransform4x3;
  4881. this.skinVertexWeights[l] = 0;
  4882. q[0] = 0;
  4883. q[1] = 0;
  4884. q[2] = 0;
  4885. q[3] = 0;
  4886. q[4] = 0;
  4887. q[5] = 0;
  4888. q[6] = 0;
  4889. q[7] = 0;
  4890. q[8] = 0;
  4891. q[9] = 0;
  4892. q[10] = 0;
  4893. q[11] = 0;
  4894. var x = this.linkMapWeights[n];
  4895. if (1 == u && 1 == x) {
  4896. var w = this.linkMapClusterIndices[n]
  4897. , w = this.skinningClusters[w]
  4898. , v = w.matrix;
  4899. q[0] = v[0];
  4900. q[1] = v[1];
  4901. q[2] = v[2];
  4902. q[3] = v[4];
  4903. q[4] = v[5];
  4904. q[5] = v[6];
  4905. q[6] = v[8];
  4906. q[7] = v[9];
  4907. q[8] = v[10];
  4908. q[9] = v[12];
  4909. q[10] = v[13];
  4910. q[11] = v[14];
  4911. this.skinVertexWeights[l] = 1
  4912. } else
  4913. for (var t = this.skinVertexWeights[l] = 0; t < u; t++)
  4914. x = this.linkMapWeights[n + t],
  4915. w = this.linkMapClusterIndices[n + t],
  4916. w < this.skinningClusters.length && (w = this.skinningClusters[w],
  4917. v = w.matrix,
  4918. q[0] += x * v[0],
  4919. q[1] += x * v[1],
  4920. q[2] += x * v[2],
  4921. q[3] += x * v[4],
  4922. q[4] += x * v[5],
  4923. q[5] += x * v[6],
  4924. q[6] += x * v[8],
  4925. q[7] += x * v[9],
  4926. q[8] += x * v[10],
  4927. q[9] += x * v[12],
  4928. q[10] += x * v[13],
  4929. q[11] += x * v[14],
  4930. this.skinVertexWeights[l] += x,
  4931. 1 == w.linkMode && (this.skinVertexWeights[l] = 1));
  4932. n += this.linkMapCount[m];
  4933. if (0 < this.skinVertexWeights[l]) {
  4934. var y = this.unTransformedVertices[3 * m + 0]
  4935. , E = this.unTransformedVertices[3 * m + 1]
  4936. , F = this.unTransformedVertices[3 * m + 2]
  4937. , A = this.unTransformedNormals[3 * m + 0]
  4938. , B = this.unTransformedNormals[3 * m + 1]
  4939. , z = this.unTransformedNormals[3 * m + 2]
  4940. , w = this.unTransformedTangents[3 * m + 0]
  4941. , v = this.unTransformedTangents[3 * m + 1]
  4942. , C = this.unTransformedTangents[3 * m + 2]
  4943. , u = this.unTransformedBiTangents[3 * m + 0]
  4944. , q = this.unTransformedBiTangents[3 * m + 1]
  4945. , x = this.unTransformedBiTangents[3 * m + 2]
  4946. , t = this.skinVertexTransform4x3
  4947. , G = 1;
  4948. 0 < this.skinVertexWeights[l] && (G = 1 / this.skinVertexWeights[l]);
  4949. d[b * m] = G * (y * t[0] + E * t[3] + F * t[6] + t[9]) * c;
  4950. d[b * m + 1] = G * (y * t[1] + E * t[4] + F * t[7] + t[10]) * c;
  4951. d[b * m + 2] = G * (y * t[2] + E * t[5] + F * t[8] + t[11]) * c;
  4952. y = A * t[0] + B * t[3] + z * t[6];
  4953. l = A * t[1] + B * t[4] + z * t[7];
  4954. A = A * t[2] + B * t[5] + z * t[8];
  4955. B = w * t[0] + v * t[3] + C * t[6];
  4956. z = w * t[1] + v * t[4] + C * t[7];
  4957. w = w * t[2] + v * t[5] + C * t[8];
  4958. v = u * t[0] + q * t[3] + x * t[6];
  4959. C = u * t[1] + q * t[4] + x * t[7];
  4960. u = u * t[2] + q * t[5] + x * t[8];
  4961. q = Math.sqrt(y * y + l * l + A * A);
  4962. y /= q;
  4963. l /= q;
  4964. A /= q;
  4965. q = 32767.4 * (y / 2 + 0.5);
  4966. x = 32767.4 * (l / 2 + 0.5);
  4967. 0 > A && (x += 32768);
  4968. e[s] = Math.floor(q);
  4969. e[s + 1] = Math.floor(x);
  4970. q = Math.sqrt(B * B + z * z + w * w);
  4971. B /= q;
  4972. z /= q;
  4973. w /= q;
  4974. q = 32767.4 * (B / 2 + 0.5);
  4975. x = 32767.4 * (z / 2 + 0.5);
  4976. 0 > w && (x += 32768);
  4977. e[p] = Math.floor(q);
  4978. e[p + 1] = Math.floor(x);
  4979. q = Math.sqrt(v * v + C * C + u * u);
  4980. v /= q;
  4981. C /= q;
  4982. u /= q;
  4983. q = 32767.4 * (v / 2 + 0.5);
  4984. x = 32767.4 * (C / 2 + 0.5);
  4985. 0 > u && (x += 32768);
  4986. e[r] = Math.floor(q);
  4987. e[r + 1] = Math.floor(x)
  4988. } else
  4989. y = this.unTransformedVertices[3 * m + 0],
  4990. E = this.unTransformedVertices[3 * m + 1],
  4991. F = this.unTransformedVertices[3 * m + 2],
  4992. d[b * m] = y * c,
  4993. d[b * m + 1] = E * c,
  4994. d[b * m + 2] = F * c
  4995. }
  4996. }
  4997. }
  4998. ;
  4999. SkinningRig.prototype.deformMesh = function(a, c) {
  5000. if (0 != this.skinningClusters.length && !this.isRigidSkin) {
  5001. this.deformMeshVertices(a, c);
  5002. var b = a.gl;
  5003. b.bindBuffer(b.ARRAY_BUFFER, a.vertexBuffer);
  5004. b.bufferData(b.ARRAY_BUFFER, a.dynamicVertexData, b.DYNAMIC_DRAW);
  5005. b.bindBuffer(b.ARRAY_BUFFER, null)
  5006. }
  5007. }
  5008. ;
  5009. function Sky(a, c, b) {
  5010. this.gl = a;
  5011. var d = c.extract("sky.dat") || c.extract("sky.png");
  5012. if (void 0 !== d) {
  5013. this.specularTexture = new Texture(a,{
  5014. width: 256,
  5015. height: 2048,
  5016. clamp: !0
  5017. });
  5018. c = d.data;
  5019. for (var d = d.data.length, e = d / 4, f = new Uint8Array(d), g = 0, h = 0; g < d; ++h)
  5020. f[g++] = c[h + 2 * e],
  5021. f[g++] = c[h + e],
  5022. f[g++] = c[h],
  5023. f[g++] = c[h + 3 * e];
  5024. this.specularTexture.loadArray(f)
  5025. }
  5026. this.diffuseCoefficients = new Float32Array(b.diffuseCoefficients);
  5027. this.backgroundMode = b.backgroundMode || 0;
  5028. this.backgroundBrightness = b.backgroundBrightness || 1;
  5029. this.backgroundColor = new Float32Array(b.backgroundColor);
  5030. if (1 <= this.backgroundMode)
  5031. if (this.backgroundShader = a.shaderCache.fromURLs("skyvert.glsl", 3 == this.backgroundMode ? "skySH.glsl" : "sky.glsl", ["#define SKYMODE " + this.backgroundMode]),
  5032. this.vertexBuffer = a.createBuffer(),
  5033. a.bindBuffer(a.ARRAY_BUFFER, this.vertexBuffer),
  5034. b = 1 / 256,
  5035. c = 0.5 / 256,
  5036. d = 2.8 * c,
  5037. e = 0.5 * c,
  5038. b = new Float32Array([0, 1, 0, 0.49609375 + b, 0.49609375 + b, 1, 0, 0, 0.9921875 + b, 0.49609375 + b, 0, 0, 1, 0.49609375 + b, 0.9921875 + b, -1, 0, 0, 0 + b, 0.49609375 + b, 0, 0, -1, 0.49609375 + b, 0 + b, 0, -1, 0, 0.9921875 + b, 0 + b, 0, -1, 0, 0.9921875 + b, 0.9921875 + b, 0, -1, 0, 0 + b, 0.9921875 + b, 0, -1, 0, 0 + b, 0 + b, d, 1 - d, -d, 0.5 + c, 0.5 - c, d, 1 - d, d, 0.5 + c, 0.5 + c, -d, 1 - d, d, 0.5 - c, 0.5 + c, -d, 1 - d, -d, 0.5 - c, 0.5 - c, -d, 0, -1 + d, 0.5 - c, 0 + b + c, d, 0, -1 + d, 0.5 + c, 0 + b + c, 1 - d, 0, -d, 0.9921875 + b - c, 0.5 - c, 1 - d, 0, d, 0.9921875 + b - c, 0.5 + c, d, 0, 1 - d, 0.5 + c, 0.9921875 + b - c, -d, 0, 1 - d, 0.5 - c, 0.9921875 + b - c, -1 + d, 0, d, 0 + b + c, 0.5 + c, -1 + d, 0, -d, 0 + b + c, 0.5 - c, 1, 0, 0, 0.9921875 + b - e, 0.49609375 + b, 0, 0, 1, 0.49609375 + b, 0.9921875 + b - e, -1, 0, 0, 0 + b + e, 0.49609375 + b, 0, 0, -1, 0.49609375 + b, 0 + b + e, 0, 1, 0, 0.49609375 + b - e, 0.49609375 + b, 0, 1, 0, 0.49609375 + b, 0.49609375 + b - e, 0, 1, 0, 0.49609375 + b + e, 0.49609375 + b, 0, 1, 0, 0.49609375 + b, 0.49609375 + b + e]),
  5039. a.bufferData(a.ARRAY_BUFFER, b, a.STATIC_DRAW),
  5040. a.bindBuffer(a.ARRAY_BUFFER, null),
  5041. this.indexBuffer = a.createBuffer(),
  5042. a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, this.indexBuffer),
  5043. b = new Uint16Array([2, 1, 6, 3, 2, 7, 8, 4, 3, 4, 5, 1, 9, 14, 15, 17, 10, 16, 18, 19, 11, 20, 13, 12, 28, 12, 13, 13, 24, 28, 28, 24, 9, 9, 24, 14, 25, 9, 15, 25, 15, 21, 10, 25, 21, 10, 21, 16, 22, 26, 10, 22, 10, 17, 18, 11, 26, 22, 18, 26, 19, 23, 27, 19, 27, 11, 23, 20, 27, 27, 20, 12]),
  5044. this.skyIndexCount = b.length,
  5045. a.bufferData(a.ELEMENT_ARRAY_BUFFER, b, a.STATIC_DRAW),
  5046. a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, null),
  5047. 3 == this.backgroundMode)
  5048. for (this.backgroundCoefficients = new Float32Array(this.diffuseCoefficients),
  5049. g = 0; g < this.backgroundCoefficients.length; ++g)
  5050. this.backgroundCoefficients[g] *= this.backgroundBrightness;
  5051. else {
  5052. this.backgroundTexture = new Texture(a,{
  5053. width: 256,
  5054. height: 256,
  5055. clamp: !0
  5056. });
  5057. b = !1;
  5058. var k;
  5059. a.ext.textureHalf && a.ext.textureHalfLinear && (this.backgroundTexture.loadArray(null, a.RGB, a.ext.textureHalf.HALF_FLOAT_OES),
  5060. k = new Framebuffer(a,{
  5061. color0: this.backgroundTexture
  5062. }),
  5063. b = k.valid);
  5064. !b && a.ext.textureFloat && a.ext.textureFloatLinear && !a.hints.mobile && (this.backgroundTexture.loadArray(null, a.RGB, a.FLOAT),
  5065. k = new Framebuffer(a,{
  5066. color0: this.backgroundTexture
  5067. }),
  5068. b = k.valid);
  5069. b || (this.backgroundTexture.loadArray(),
  5070. k = new Framebuffer(a,{
  5071. color0: this.backgroundTexture
  5072. }));
  5073. k.bind();
  5074. k = new Shader(a);
  5075. k.build("precision highp float; varying vec2 tc; attribute vec4 p; void main(){ gl_Position=p; tc=vec2(0.5,0.5/8.0)*p.xy+vec2(0.5,6.5/8.0); }", "precision highp float; varying vec2 tc; uniform sampler2D tex; uniform float b; void main(){vec4 s=texture2D(tex,tc); gl_FragColor.xyz=s.xyz*(b*s.w);}");
  5076. k.bind();
  5077. a.uniform1f(k.params.b, 7 * Math.sqrt(this.backgroundBrightness));
  5078. this.specularTexture.bind(k.samplers.tex);
  5079. b = a.createBuffer();
  5080. a.bindBuffer(a.ARRAY_BUFFER, b);
  5081. b = new Float32Array([-1, -1, 0.5, 1, 3, -1, 0.5, 1, -1, 3, 0.5, 1]);
  5082. a.bufferData(a.ARRAY_BUFFER, b, a.STATIC_DRAW);
  5083. a.enableVertexAttribArray(k.attribs.p);
  5084. a.vertexAttribPointer(k.attribs.p, 4, a.FLOAT, !1, 0, 0);
  5085. a.drawArrays(a.TRIANGLES, 0, 3);
  5086. a.disableVertexAttribArray(k.attribs.p)
  5087. }
  5088. }
  5089. Sky.prototype.setClearColor = function() {
  5090. if (marmoset.transparentBackground)
  5091. this.gl.clearColor(0, 0, 0, 0);
  5092. else if (1 > this.backgroundMode) {
  5093. var a = this.backgroundColor;
  5094. this.gl.clearColor(a[0], a[1], a[2], 1)
  5095. } else
  5096. this.gl.clearColor(0.0582, 0.06772, 0.07805, 1)
  5097. }
  5098. ;
  5099. Sky.prototype.draw = function(a) {
  5100. if (1 > this.backgroundMode || marmoset.transparentBackground)
  5101. return !1;
  5102. if (this.complete()) {
  5103. var c = this.gl
  5104. , b = this.backgroundShader
  5105. , d = a.view
  5106. , e = a.lights.invMatrix;
  5107. b.bind();
  5108. c.uniformMatrix4fv(b.params.uInverseSkyMatrix, !1, e);
  5109. c.uniformMatrix4fv(b.params.uViewProjection, !1, d.viewProjectionMatrix);
  5110. 3 == this.backgroundMode ? c.uniform4fv(b.params.uSkyCoefficients, this.backgroundCoefficients) : this.backgroundTexture.bind(b.samplers.tSkyTexture);
  5111. a = 0.07 + 0.94 * (1 - a.stripData.activeFade());
  5112. c.uniform1f(b.params.uAlpha, a);
  5113. c.bindBuffer(c.ARRAY_BUFFER, this.vertexBuffer);
  5114. c.enableVertexAttribArray(b.attribs.vPosition);
  5115. c.vertexAttribPointer(b.attribs.vPosition, 3, c.FLOAT, !1, 20, 0);
  5116. c.enableVertexAttribArray(b.attribs.vTexCoord);
  5117. c.vertexAttribPointer(b.attribs.vTexCoord, 2, c.FLOAT, !1, 20, 12);
  5118. c.bindBuffer(c.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
  5119. 1 > a && (c.enable(c.BLEND),
  5120. c.blendFunc(c.SRC_ALPHA, c.ONE_MINUS_SRC_ALPHA));
  5121. c.depthMask(!1);
  5122. c.disable(c.DEPTH_TEST);
  5123. c.drawElements(c.TRIANGLES, this.skyIndexCount, c.UNSIGNED_SHORT, 0);
  5124. c.enable(c.DEPTH_TEST);
  5125. c.depthMask(!0);
  5126. 1 > a && c.disable(c.BLEND);
  5127. c.disableVertexAttribArray(b.attribs.vPosition);
  5128. c.disableVertexAttribArray(b.attribs.vTexCoord)
  5129. }
  5130. }
  5131. ;
  5132. Sky.prototype.complete = function() {
  5133. return this.backgroundShader && !this.backgroundShader.complete() ? !1 : this.specularTexture.complete()
  5134. }
  5135. ;
  5136. function StripData() {
  5137. this.STRIP_NONE = -2;
  5138. this.STRIP_MENU = -1;
  5139. this.stripCount = 5;
  5140. this.strips = [0, 0, 0, 0, 0];
  5141. this.labels = ["Normals", "Albedo", "Reflectivity", "Gloss", "Topology"];
  5142. this.stripSlant = 0.25;
  5143. this.selectedStrip = this.STRIP_NONE;
  5144. this.animationActive = !1;
  5145. this.timestamp = Date.now();
  5146. this.update(!0)
  5147. }
  5148. StripData.expDecay = function(a, c) {
  5149. return Math.exp(-0.69314718 / a * c)
  5150. }
  5151. ;
  5152. StripData.prototype.update = function(a) {
  5153. var c = 0.001 * (Date.now() - this.timestamp);
  5154. this.timestamp = Date.now();
  5155. for (var b = !1, d = 0; d < this.stripCount; ++d) {
  5156. var e = 0
  5157. , e = this.selectedStrip == this.STRIP_MENU ? -0.9 + 0.3 * (d + 1) : 0 > this.selectedStrip || d < this.selectedStrip ? -2 : 2;
  5158. if (a)
  5159. this.strips[d] = e;
  5160. else {
  5161. var f = e - this.strips[d]
  5162. , f = f * StripData.expDecay(0.05, c);
  5163. this.animationActive && (this.strips[d] = e - f);
  5164. b = b || 0.001 < Math.abs(f)
  5165. }
  5166. }
  5167. this.animationActive = b
  5168. }
  5169. ;
  5170. StripData.prototype.active = function() {
  5171. return this.selectedStrip >= this.STRIP_MENU
  5172. }
  5173. ;
  5174. StripData.prototype.activeFade = function() {
  5175. var a = (this.strips[this.stripCount - 1] - -2) / (-0.9 + 0.3 * this.stripCount - -2)
  5176. , a = 1 < a ? 1 : a;
  5177. return 0 > a ? 0 : a
  5178. }
  5179. ;
  5180. StripData.prototype.activeWireframe = function() {
  5181. return this.active() && 0.01 < Math.abs(this.strips[4] - this.strips[3])
  5182. }
  5183. ;
  5184. StripData.prototype.toggleMenu = function() {
  5185. this.selectedStrip = this.selectedStrip == this.STRIP_MENU ? this.STRIP_NONE : this.STRIP_MENU
  5186. }
  5187. ;
  5188. StripData.prototype.selectStrip = function(a, c) {
  5189. if (this.selectedStrip == this.STRIP_MENU) {
  5190. var b = a + c * this.stripSlant;
  5191. this.selectedStrip = this.STRIP_NONE;
  5192. for (var d = 0; d < this.stripCount; ++d)
  5193. if (b < this.strips[d]) {
  5194. this.selectedStrip = d;
  5195. break
  5196. }
  5197. } else
  5198. this.selectedStrip = this.STRIP_MENU
  5199. }
  5200. ;
  5201. function Texture(a, c) {
  5202. this.gl = a;
  5203. this.id = null;
  5204. this.type = a.TEXTURE_2D;
  5205. this.format = a.RGBA;
  5206. this.componentType = a.UNSIGNED_BYTE;
  5207. c = c || {};
  5208. this.desc = {
  5209. width: c.width || 1,
  5210. height: c.height || 1,
  5211. mipmap: c.mipmap,
  5212. clamp: c.clamp,
  5213. mirror: c.mirror,
  5214. aniso: c.aniso,
  5215. nofilter: c.nofilter
  5216. }
  5217. }
  5218. Texture.prototype.loadImage = function(a, c) {
  5219. var b = this.gl;
  5220. a && a.width && a.height && (this.desc.width = a.width,
  5221. this.desc.height = a.height);
  5222. this.id = b.createTexture();
  5223. b.bindTexture(this.type, this.id);
  5224. this.format = c || b.RGBA;
  5225. this.componentType = b.UNSIGNED_BYTE;
  5226. b.pixelStorei(b.UNPACK_FLIP_Y_WEBGL, !0);
  5227. b.texImage2D(this.type, 0, this.format, this.format, this.componentType, a);
  5228. this.setParams();
  5229. b.bindTexture(this.type, null)
  5230. }
  5231. ;
  5232. Texture.prototype.loadArray = function(a, c, b) {
  5233. var d = this.gl;
  5234. this.id = d.createTexture();
  5235. d.bindTexture(this.type, this.id);
  5236. this.format = c || d.RGBA;
  5237. this.componentType = b || d.UNSIGNED_BYTE;
  5238. d.pixelStorei(d.UNPACK_FLIP_Y_WEBGL, !0);
  5239. d.texImage2D(this.type, 0, this.format, this.desc.width, this.desc.height, 0, this.format, this.componentType, a || null);
  5240. this.setParams();
  5241. d.bindTexture(this.type, null)
  5242. }
  5243. ;
  5244. Texture.prototype.setParams = function() {
  5245. var a = this.gl
  5246. , c = function(a) {
  5247. return 0 < a && 0 == (a & a - 1)
  5248. };
  5249. c(this.desc.width) && c(this.desc.height) || (this.desc.clamp = !0,
  5250. this.desc.mipmap = !1);
  5251. c = !this.desc.nofilter;
  5252. this.desc.mipmap ? (a.generateMipmap(this.type),
  5253. a.texParameteri(this.type, a.TEXTURE_MIN_FILTER, c ? a.LINEAR_MIPMAP_LINEAR : a.NEAREST_MIPMAP_NEAREST)) : a.texParameteri(this.type, a.TEXTURE_MIN_FILTER, c ? a.LINEAR : a.NEAREST);
  5254. a.texParameteri(this.type, a.TEXTURE_MAG_FILTER, c ? a.LINEAR : a.NEAREST);
  5255. if (this.desc.clamp || this.desc.mirror)
  5256. c = this.desc.clamp ? a.CLAMP_TO_EDGE : a.MIRRORED_REPEAT,
  5257. a.texParameteri(this.type, a.TEXTURE_WRAP_S, c),
  5258. a.texParameteri(this.type, a.TEXTURE_WRAP_T, c);
  5259. this.desc.aniso && a.ext.textureAniso && a.texParameteri(this.type, a.ext.textureAniso.TEXTURE_MAX_ANISOTROPY_EXT, this.desc.aniso)
  5260. }
  5261. ;
  5262. Texture.prototype.rebuildMips = function() {
  5263. this.desc.mipmap && (this.gl.bindTexture(this.type, this.id),
  5264. this.gl.generateMipmap(this.type))
  5265. }
  5266. ;
  5267. Texture.prototype.copyColorBuffer = function() {
  5268. this.gl.bindTexture(this.type, this.id);
  5269. this.gl.copyTexSubImage2D(this.type, 0, 0, 0, 0, 0, this.desc.width, this.desc.height)
  5270. }
  5271. ;
  5272. Texture.prototype.bind = function(a) {
  5273. if (a) {
  5274. var c = this.gl;
  5275. c.uniform1i(a.location, a.unit);
  5276. c.activeTexture(c.TEXTURE0 + a.unit);
  5277. c.bindTexture(this.type, this.id)
  5278. }
  5279. }
  5280. ;
  5281. Texture.prototype.destroy = function() {
  5282. this.gl.deleteTexture(this.id);
  5283. this.id = null
  5284. }
  5285. ;
  5286. Texture.prototype.complete = function() {
  5287. return !!this.id
  5288. }
  5289. ;
  5290. function TextureCache(a) {
  5291. this.gl = a;
  5292. this.cache = []
  5293. }
  5294. TextureCache.prototype.fromURL = function(a, c) {
  5295. var b = this.cache[a];
  5296. if (void 0 !== b)
  5297. return b;
  5298. var d = new Texture(this.gl,c);
  5299. Network.fetchImage(a, function(a) {
  5300. d.loadImage(a)
  5301. });
  5302. return this.cache[a] = d
  5303. }
  5304. ;
  5305. TextureCache.prototype.fromFile = function(a, c) {
  5306. if (!a)
  5307. return null;
  5308. var b = this.cache[a.name];
  5309. if (void 0 !== b)
  5310. return b;
  5311. var d = new Texture(this.gl,c);
  5312. this.cache[a.name] = d;
  5313. TextureCache.parseFile(a, function(a) {
  5314. d.loadImage(a);
  5315. TextureCache.closeImage(a)
  5316. });
  5317. return d
  5318. }
  5319. ;
  5320. TextureCache.prototype.fromFilesMergeAlpha = function(a, c, b) {
  5321. if (!c)
  5322. return this.fromFile(a, b);
  5323. var d = a.name + "|" + c.name
  5324. , e = this.cache[d];
  5325. if (void 0 !== e)
  5326. return e;
  5327. var f = this.gl;
  5328. this.blitShader || (this.blitShader = new Shader(this.gl),
  5329. this.blitShader.build("precision highp float; varying vec2 c; attribute vec2 pos; void main(){ gl_Position.xy = 2.0*pos-vec2(1.0); gl_Position.zw = vec2(0.5,1.0); c=pos; }", "precision highp float; varying vec2 c; uniform sampler2D tTex; void main(){ gl_FragColor=texture2D(tTex,c).rgbr; }"),
  5330. this.mergeVerts = f.createBuffer(),
  5331. f.bindBuffer(f.ARRAY_BUFFER, this.mergeVerts),
  5332. e = new Float32Array([0, 0, 2, 0, 0, 2]),
  5333. f.bufferData(f.ARRAY_BUFFER, e, f.STATIC_DRAW),
  5334. f.bindBuffer(f.ARRAY_BUFFER, null));
  5335. var g = function(a) {
  5336. this.blitShader.bind();
  5337. a.bind(this.blitShader.samplers.tTex);
  5338. f.bindBuffer(f.ARRAY_BUFFER, this.mergeVerts);
  5339. f.enableVertexAttribArray(this.blitShader.attribs.pos);
  5340. f.vertexAttribPointer(this.blitShader.attribs.pos, 2, f.FLOAT, !1, 0, 0);
  5341. f.drawArrays(f.TRIANGLES, 0, 3);
  5342. f.disableVertexAttribArray(this.blitShader.attribs.pos);
  5343. f.bindBuffer(f.ARRAY_BUFFER, null)
  5344. }
  5345. .bind(this)
  5346. , h = new Texture(this.gl,b);
  5347. this.cache[d] = h;
  5348. var k = 0
  5349. , n = 0
  5350. , m = function() {
  5351. if (k && n) {
  5352. var a, b;
  5353. n.width * n.height > k.width * k.height ? (a = n.width,
  5354. b = n.height) : (a = k.width,
  5355. b = k.height);
  5356. h.desc.width = a;
  5357. h.desc.height = b;
  5358. if (a <= f.limits.viewportSizes[0] && b <= f.limits.viewportSizes[1]) {
  5359. var c = {
  5360. clamp: !0
  5361. };
  5362. k.width == a && k.height == b ? (h.loadImage(k, f.RGBA),
  5363. a = new Framebuffer(f,{
  5364. color0: h,
  5365. ignoreStatus: !0
  5366. }),
  5367. TextureCache.closeImage(k)) : (b = new Texture(f,c),
  5368. b.loadImage(k, f.RGB),
  5369. TextureCache.closeImage(k),
  5370. h.loadArray(null),
  5371. a = new Framebuffer(f,{
  5372. color0: h,
  5373. ignoreStatus: !0
  5374. }),
  5375. a.bind(),
  5376. g(b),
  5377. b.destroy());
  5378. b = new Texture(f,c);
  5379. b.loadImage(n, f.RGB);
  5380. TextureCache.closeImage(n);
  5381. a.bind();
  5382. f.colorMask(!1, !1, !1, !0);
  5383. g(b);
  5384. f.colorMask(!0, !0, !0, !0);
  5385. b.destroy();
  5386. Framebuffer.bindNone(f);
  5387. h.rebuildMips()
  5388. } else {
  5389. c = document.createElement("canvas");
  5390. c.width = a;
  5391. c.height = b;
  5392. var d = c.getContext("2d");
  5393. d.drawImage(k, 0, 0);
  5394. TextureCache.closeImage(k);
  5395. c = d.getImageData(0, 0, a, b);
  5396. c = new Uint8Array(c.data.buffer,c.data.byteOffset,c.data.length);
  5397. d.drawImage(n, 0, 0);
  5398. TextureCache.closeImage(n);
  5399. d = d.getImageData(0, 0, a, b).data;
  5400. a = a * b * 4;
  5401. for (b = 0; b < a; b += 4)
  5402. c[b + 3] = d[b];
  5403. h.loadArray(c)
  5404. }
  5405. TextureCache.closeImage(n)
  5406. }
  5407. }
  5408. .bind(this);
  5409. TextureCache.parseFile(a, function(a) {
  5410. k = a;
  5411. m()
  5412. });
  5413. TextureCache.parseFile(c, function(a) {
  5414. n = a;
  5415. m()
  5416. });
  5417. return h
  5418. }
  5419. ;
  5420. TextureCache.parseFile = function(a, c, b) {
  5421. var d = b || new Image;
  5422. if ("undefined" != typeof URL && "undefined" != typeof URL.createObjectURL) {
  5423. a = new Blob([a.data],{
  5424. type: a.type
  5425. });
  5426. var e = URL.createObjectURL(a);
  5427. d.onload = function() {
  5428. URL.revokeObjectURL(e);
  5429. c && c(d)
  5430. }
  5431. ;
  5432. d.src = e
  5433. } else {
  5434. a = new Blob([a.data],{
  5435. type: a.type
  5436. });
  5437. var f = new FileReader;
  5438. f.onload = function(a) {
  5439. d.src = f.result
  5440. }
  5441. ;
  5442. d.onload = function() {
  5443. c && c(d)
  5444. }
  5445. ;
  5446. f.readAsDataURL(a)
  5447. }
  5448. }
  5449. ;
  5450. TextureCache.closeImage = function(a) {
  5451. a && 256 < a.width * a.height && (a.onload = null,
  5452. a.onerror = null,
  5453. a.src = "data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs%3D")
  5454. }
  5455. ;
  5456. function TimelineSlider(a, c) {
  5457. this.name = "none";
  5458. this.debugString = "";
  5459. this.knobControlRect = new ControlRect(a);
  5460. this.controlRect = new ControlRect(a);
  5461. var b = document.createElement("div");
  5462. b.id = "sliderUI";
  5463. b.style.position = "absolute";
  5464. b.style.overflow = "hidden";
  5465. b.style["-moz-user-select"] = "none";
  5466. b.style["-khtml-user-select"] = "none";
  5467. b.style["-webkit-user-select"] = "none";
  5468. b.style["-ms-user-select"] = "none";
  5469. this.controlRect.linkedControl = b;
  5470. this.backgroundControl = 0;
  5471. this.controlRect.registerChildControlRect(this.knobControlRect);
  5472. this.knobControlRect.setOpacity(0.65);
  5473. this.sliderPercent = this.pixelsY = this.pixelsX = 0;
  5474. this.draggingSlider = !1;
  5475. this.guiScreen = a;
  5476. c.addImageElement(this.knobControlRect, "animationknob" + a.imageSetNumber + "x.png")
  5477. }
  5478. TimelineSlider.prototype.setBackground3x1 = function(a, c, b, d) {
  5479. var e = 8 / this.controlRect.getScreenHeight();
  5480. this.backgroundControl = a.addTextButton("", 0, (1 - e) / 2, 1, e, 1);
  5481. this.backgroundControl.defaultAlpha = 1;
  5482. this.backgroundControl.setBackground3x1(a, 0, 0, c, b, d, 4);
  5483. this.backgroundControl.controlRect.xPercent = this.controlRect.xPercent;
  5484. this.backgroundControl.controlRect.widthPercent = this.controlRect.widthPercent;
  5485. this.controlRect.linkedControl.style.zIndex = "3";
  5486. this.setupCallbacks()
  5487. }
  5488. ;
  5489. TimelineSlider.prototype.setSize = function(a, c) {
  5490. this.pixelsX = a;
  5491. this.pixelsY = c;
  5492. var b = 24 / c;
  5493. this.knobWidthPercent = 24 / a;
  5494. this.knobControlRect.xPercent = 0.5 - this.knobWidthPercent / 2;
  5495. this.knobControlRect.yPercent = (1 - b) / 2 + -1 / c;
  5496. this.knobControlRect.widthPercent = this.knobWidthPercent;
  5497. this.knobControlRect.heightPercent = b;
  5498. this.controlRect.updateElement();
  5499. this.backgroundControl.controlRect.xPercent = this.controlRect.xPercent;
  5500. this.backgroundControl.controlRect.widthPercent = this.controlRect.widthPercent;
  5501. this.backgroundControl.controlRect.updateElement()
  5502. }
  5503. ;
  5504. TimelineSlider.prototype.setSliderPercent = function(a) {
  5505. 0 > a && (a = 0);
  5506. 1 < a && (a = 1);
  5507. this.sliderPercent = a;
  5508. this.knobControlRect.xPercent = a - this.knobWidthPercent / 2;
  5509. this.knobControlRect.updateElement()
  5510. }
  5511. ;
  5512. TimelineSlider.prototype.setupCallbacks = function() {
  5513. var a = function(a) {
  5514. if (this.draggingSlider) {
  5515. var b = this.backgroundControl.controlRect.linkedControl.getBoundingClientRect();
  5516. this.setSliderPercent((a.clientX - b.left) / b.width);
  5517. this.guiScreen.ui.viewer.scene.sceneAnimator.setAnimationProgress(this.sliderPercent, !0);
  5518. this.guiScreen.ui.viewer.scene.sceneAnimator.paused && (this.guiScreen.ui.viewer.scene.postRender.discardAAHistory(),
  5519. this.guiScreen.ui.viewer.reDrawScene())
  5520. }
  5521. }
  5522. .bind(this)
  5523. , c = function(a) {
  5524. this.draggingSlider = !0;
  5525. var b = this.backgroundControl.controlRect.linkedControl.getBoundingClientRect();
  5526. this.setSliderPercent((a.clientX - b.left) / b.width);
  5527. this.guiScreen.ui.viewer.scene.sceneAnimator.setAnimationProgress(this.sliderPercent, !0);
  5528. this.guiScreen.ui.viewer.scene.sceneAnimator.lockPlayback = !0;
  5529. this.guiScreen.ui.viewer.scene.sceneAnimator.paused && (this.guiScreen.ui.viewer.scene.postRender.discardAAHistory(),
  5530. this.guiScreen.ui.viewer.reDrawScene())
  5531. }
  5532. .bind(this)
  5533. , b = function(a) {
  5534. this.draggingSlider = !1;
  5535. this.guiScreen.ui.viewer.scene.sceneAnimator.lockPlayback = !1
  5536. }
  5537. .bind(this);
  5538. this.guiScreen.ui.viewer.input.element.addEventListener("mousemove", a);
  5539. this.guiScreen.ui.viewer.input.element.addEventListener("mouseup", b);
  5540. this.backgroundControl.controlRect.linkedControl.addEventListener("mousemove", a);
  5541. this.backgroundControl.controlRect.linkedControl.addEventListener("mousedown", c);
  5542. this.backgroundControl.controlRect.linkedControl.addEventListener("mouseup", b);
  5543. this.controlRect.linkedControl.addEventListener("mouseup", b)
  5544. }
  5545. ;
  5546. function UI(a) {
  5547. this.viewer = a;
  5548. this.stripData = a.stripData;
  5549. a = this.container = document.createElement("div");
  5550. a.id = "marmosetUI";
  5551. a.style.position = "absolute";
  5552. a.style.overflow = "hidden";
  5553. a.style["-moz-user-select"] = "none";
  5554. a.style["-khtml-user-select"] = "none";
  5555. a.style["-webkit-user-select"] = "none";
  5556. a.style["-ms-user-select"] = "none";
  5557. this.viewer.domRoot.appendChild(a);
  5558. this.guiScreen = new GUIScreen(this)
  5559. }
  5560. UI.prototype.setSize = function(a, c) {
  5561. this.container.width = a | 0;
  5562. this.container.height = c | 0;
  5563. this.container.style.width = a + "px";
  5564. this.container.style.height = c + "px";
  5565. this.guiScreen.setSize(this.container.width, this.container.height)
  5566. }
  5567. ;
  5568. UI.prototype.clearView = function() {
  5569. for (; this.container.hasChildNodes(); )
  5570. this.container.removeChild(this.container.childNodes[0]);
  5571. delete this.progressBar;
  5572. delete this.thumbnail;
  5573. delete this.fadeThumbnail;
  5574. delete this.playButton;
  5575. delete this.helpOverlay
  5576. }
  5577. ;
  5578. UI.prototype.bindInput = function(a) {
  5579. a.onSingleTap.push(function(c, b) {
  5580. this.stripData.selectedStrip != this.stripData.STRIP_NONE && (c = 2 / a.element.clientWidth * c - 1,
  5581. b = 1 - 2 / a.element.clientHeight * b,
  5582. this.stripData.selectStrip(c, b),
  5583. this.stripData.selectedStrip == this.stripData.STRIP_MENU && this.helpOverlay.active && this.helpOverlay.toggle(),
  5584. this.refreshUI(),
  5585. this.viewer.wake())
  5586. }
  5587. .bind(this))
  5588. }
  5589. ;
  5590. UI.sanitize = function(a) {
  5591. return a ? a.replace(/<|>|\(|\)|$|%|=/g, "") : a
  5592. }
  5593. ;
  5594. UI.sanitizeURL = function(a) {
  5595. return a ? 0 == a.indexOf("http://") || 0 == a.indexOf("https://") || 0 == a.indexOf("ftp://") ? encodeURI(a) : "http://" + encodeURI(a) : a
  5596. }
  5597. ;
  5598. UI.prototype.showFailure = function(a) {
  5599. this.container.innerHTML = '<br><br><br><p style="text-align:center;color:#aaaaaa"><b>Marmoset Viewer could not initialize.</b><br><i>' + (a || "") + "</i>"
  5600. }
  5601. ;
  5602. UI.prototype.showPreview = function(a) {
  5603. this.clearView();
  5604. this.thumbnail = document.createElement("canvas");
  5605. var c = this.container.width / this.container.height;
  5606. this.thumbnail.height = this.viewer.mobile ? 200 : 300;
  5607. this.thumbnail.width = this.thumbnail.height * c | 0;
  5608. this.thumbnail.style.width = this.thumbnail.style.height = "100%";
  5609. var c = this.thumbnail.getContext("2d")
  5610. , b = c.fillStyle = c.createRadialGradient(this.thumbnail.width / 2, this.thumbnail.height / 2, (this.thumbnail.width + this.thumbnail.height) / 2, this.thumbnail.width / 2, 0, 0);
  5611. b.addColorStop(0, "rgb(0,0,0)");
  5612. b.addColorStop(1, "rgb(150,150,150)");
  5613. c.fillStyle = b;
  5614. c.fillRect(0, 0, this.thumbnail.width, this.thumbnail.height);
  5615. this.container.appendChild(this.thumbnail);
  5616. this.playButton = document.createElement("input");
  5617. this.playButton.type = "image";
  5618. this.playButton.src = marmoset.dataLocale + "play.png";
  5619. this.playButton.style.position = "absolute";
  5620. this.playButton.style.left = "50%";
  5621. this.playButton.style.top = "50%";
  5622. this.playButton.style["-webkit-transform"] = this.playButton.style.transform = "translate(-50%,-50%) scale(0.5,0.5)";
  5623. this.playButton.style.opacity = 0.5;
  5624. this.playButton.style.outline = "0px";
  5625. this.playButton.onclick = function() {
  5626. this.viewer.loadScene(this.viewer.sceneURL);
  5627. this.container.removeChild(this.playButton);
  5628. delete this.playButton
  5629. }
  5630. .bind(this);
  5631. this.container.appendChild(this.playButton);
  5632. a || fetchThumbnail(this.viewer.sceneURL, function(a) {
  5633. this.loadingImageURL || this.setThumbnail(a)
  5634. }
  5635. .bind(this))
  5636. }
  5637. ;
  5638. UI.prototype.setThumbnailURL = function(a) {
  5639. (this.loadingImageURL = a) && Network.fetchImage(this.loadingImageURL, this.setThumbnail.bind(this))
  5640. }
  5641. ;
  5642. UI.prototype.setThumbnail = function(a) {
  5643. if (this.thumbnail)
  5644. if (a.height >= this.container.height) {
  5645. var c = this.container.height / a.height;
  5646. a.style.position = "absolute";
  5647. a.style.outline = "0px";
  5648. a.style.left = "50%";
  5649. a.style.top = "50%";
  5650. a.style["-webkit-transform"] = a.style.transform = "translate(-50%,-50%) scale(" + c + "," + c + ")";
  5651. this.container.replaceChild(a, this.thumbnail);
  5652. this.thumbnail = a
  5653. } else {
  5654. var b = this.thumbnail.getContext("2d")
  5655. , d = this.thumbnail.width
  5656. , e = this.thumbnail.height
  5657. , c = e / a.height;
  5658. b.drawImage(a, (d - a.width * c) / 2, 0, a.width * c, e);
  5659. var f;
  5660. try {
  5661. f = b.getImageData(0, 0, d, e)
  5662. } catch (g) {
  5663. return
  5664. }
  5665. a = b.createImageData(d, e);
  5666. for (var h = 0; 2 > h; ++h) {
  5667. for (var c = f.data, k = a.data, n = 0, m = 0; m < e; ++m)
  5668. for (var l = 0; l < d; ++l) {
  5669. for (var p = 0, r = 0, s = 0, u = -2; 2 >= u; ++u)
  5670. for (var q = m + u, q = 0 > q ? 0 : q >= e ? e - 1 : q, x = -2; 2 >= x; ++x)
  5671. var w = l + x
  5672. , w = 0 > w ? 0 : w >= d ? d - 1 : w
  5673. , w = 4 * (q * d + w)
  5674. , p = p + c[w]
  5675. , r = r + c[w + 1]
  5676. , s = s + c[w + 2];
  5677. k[n++] = p / 25;
  5678. k[n++] = r / 25;
  5679. k[n++] = s / 25;
  5680. k[n++] = 255
  5681. }
  5682. c = f;
  5683. f = a;
  5684. a = c
  5685. }
  5686. b.putImageData(f, 0, 0)
  5687. }
  5688. }
  5689. ;
  5690. UI.prototype.showActiveView = function() {
  5691. var a = this.thumbnail;
  5692. this.clearView();
  5693. a && (this.fadeThumbnail = a,
  5694. this.fadeThumbnail.style.opacity = 1,
  5695. this.container.appendChild(this.fadeThumbnail));
  5696. if (!marmoset.noUserInterface) {
  5697. void 0 === marmoset.largeUI && (marmoset.largeUI = this.viewer.mobile);
  5698. 450 > this.container.width && (marmoset.largeUI = !1);
  5699. a = 1;
  5700. window.devicePixelRatio && (2 < window.devicePixelRatio ? a = 4 : 1 < window.devicePixelRatio && (a = 2));
  5701. marmoset.largeUI && 4 > a && (a *= 2);
  5702. var c = marmoset.largeUI ? 0.3 : 0.5;
  5703. this.stripText = [];
  5704. for (var b = 0; b < this.stripData.labels.length; ++b) {
  5705. this.stripText[b] = document.createElement("div");
  5706. this.stripText[b].style.position = "absolute";
  5707. this.stripText[b].style.cursor = "pointer";
  5708. this.stripText[b].style.pointerEvents = "none";
  5709. this.container.appendChild(this.stripText[b]);
  5710. var d = document.createElement("div");
  5711. d.style.color = "white";
  5712. d.style.opacity = 0.5;
  5713. d.style.fontFamily = "Arial";
  5714. d.style.textShadow = "2px 2px 3px #000000";
  5715. d.innerHTML = this.stripData.labels[b];
  5716. this.stripText[b].appendChild(d);
  5717. this.stripText[b].txt = d;
  5718. d = document.createElement("div");
  5719. d.style.width = "10000px";
  5720. d.style.height = "2px";
  5721. d.style.backgroundColor = "#AAAAAA";
  5722. d.style.opacity = 1;
  5723. d.style.position = "absolute";
  5724. d.style.left = d.style.top = "-1px";
  5725. this.stripText[b].appendChild(d);
  5726. this.stripText[b].line = d
  5727. }
  5728. this.sigCluster = document.createElement("div");
  5729. this.sigCluster.style.position = "absolute";
  5730. this.sigCluster.style.right = marmoset.largeUI ? "12px" : "9px";
  5731. this.sigCluster.style.left = "0px";
  5732. this.sigCluster.style.top = "6px";
  5733. this.sigCluster.style.height = marmoset.largeUI ? "64px" : "32px";
  5734. this.logo = document.createElement("div");
  5735. this.logo.style.position = "absolute";
  5736. this.logo.style.right = marmoset.largeUI ? "-4px" : "1px";
  5737. this.logo.style.top = marmoset.largeUI ? "0px" : "4px";
  5738. this.logo.title = "Made with Marmoset Toolbag";
  5739. var e = document.createElement("input");
  5740. e.type = "image";
  5741. e.src = marmoset.dataLocale + "logo" + a + "x.png";
  5742. e.style.border = "none";
  5743. e.style.width = e.style.height = marmoset.largeUI ? "72px" : "36px";
  5744. e.style.border = "0px";
  5745. e.style.outline = "0px";
  5746. e.style.opacity = c;
  5747. e.onmouseover = function() {
  5748. this.style.opacity = 1
  5749. }
  5750. .bind(e);
  5751. e.onmouseout = function() {
  5752. this.style.opacity = c
  5753. }
  5754. .bind(e);
  5755. e.onclick = function(a) {
  5756. window.open("http://www.marmoset.co/viewer?utm_source=inapp&utm_medium=menu&utm_campaign=viewer", "_blank");
  5757. this.style.opacity = c
  5758. }
  5759. .bind(e, this);
  5760. b = new XMLHttpRequest;
  5761. b.open("HEAD", e.src, !0);
  5762. b.onload = function(a) {
  5763. this.logo.appendChild(a)
  5764. }
  5765. .bind(this, e);
  5766. b.send();
  5767. this.sigCluster.appendChild(this.logo);
  5768. b = this.viewer.scene.metaData;
  5769. b.title = UI.sanitize(b.title);
  5770. b.subtitle = UI.sanitize(b.subtitle);
  5771. b.author = UI.sanitize(b.author);
  5772. b.link = UI.sanitizeURL(b.link);
  5773. var f = b.title && 0 < b.title.length
  5774. , d = b.subtitle && 0 < b.subtitle.length
  5775. , e = b.author && 0 < b.author.length
  5776. , g = b.link && 0 < b.link.length;
  5777. if (f || d || e) {
  5778. f || (b.title = "Art");
  5779. var h = !f && !d
  5780. , k = document.createElement("div");
  5781. k.style.position = "absolute";
  5782. k.style.right = marmoset.largeUI ? "74px" : "46px";
  5783. k.style.top = "5px";
  5784. k.style.width = "1px";
  5785. k.style.height = marmoset.largeUI ? h ? "21px" : "35px" : h ? "18px" : "31px";
  5786. k.style.opacity = 0.25;
  5787. k.style.backgroundColor = "white";
  5788. this.sigCluster.appendChild(k);
  5789. this.sigCluster.line = k;
  5790. h = document.createElement("a");
  5791. g && (h.href = b.link);
  5792. h.style.position = "absolute";
  5793. h.style.right = marmoset.largeUI ? "86px" : "58px";
  5794. h.style.top = "6px";
  5795. h.style.textAlign = "right";
  5796. h.style.color = "white";
  5797. h.style.fontFamily = "Arial";
  5798. h.style.fontSize = marmoset.largeUI ? "14px" : "12px";
  5799. h.style.textDecoration = "none";
  5800. h.target = "_blank";
  5801. k = document.createElement("font");
  5802. k.style.color = "#FFFFFF";
  5803. k.style.opacity = 0.5;
  5804. k.style.textDecoration = "none";
  5805. k.style.textShadow = "1px 1px 2px rgba(0,0,0,0.7)";
  5806. k.innerHTML = b.title;
  5807. e && (k.innerHTML = f && !d ? k.innerHTML + "<br>by " : k.innerHTML + " by ");
  5808. h.appendChild(k);
  5809. f = document.createElement("font");
  5810. f.style.color = "#FF0044";
  5811. f.style.opacity = 1;
  5812. f.style.textShadow = "1px 1px 2px rgba(0,0,0,0.35)";
  5813. f.innerHTML = b.author;
  5814. h.appendChild(f);
  5815. e = document.createElement("font");
  5816. e.style.color = "#FFFFFF";
  5817. e.style.opacity = 0.5;
  5818. e.style.textShadow = "1px 1px 2px rgba(0,0,0,0.7)";
  5819. d && (e.innerHTML = "<br>",
  5820. e.innerHTML += b.subtitle);
  5821. h.appendChild(e);
  5822. g && (h.onmouseover = function(a, b, c) {
  5823. a.style.opacity = c.style.opacity = 1;
  5824. b.style.textDecoration = "underline"
  5825. }
  5826. .bind(h, k, f, e),
  5827. h.onmouseout = function(a, b, c) {
  5828. a.style.opacity = c.style.opacity = 0.5;
  5829. b.style.textDecoration = "none"
  5830. }
  5831. .bind(h, k, f, e));
  5832. this.sigCluster.appendChild(h);
  5833. this.sigCluster.sceneTitle = h
  5834. }
  5835. this.container.appendChild(this.sigCluster);
  5836. this.sigCluster.active = !0;
  5837. this.sigCluster.toggle = function() {
  5838. this.sceneTitle && this.line && (this.active ? (this.removeChild(this.sceneTitle),
  5839. this.removeChild(this.line)) : (this.appendChild(this.sceneTitle),
  5840. this.appendChild(this.line)));
  5841. this.active = !this.active
  5842. }
  5843. .bind(this.sigCluster);
  5844. this.helpOverlay = document.createElement("div");
  5845. this.helpOverlay.style.pointerEvents = "none";
  5846. this.container.appendChild(this.helpOverlay);
  5847. this.hideSigOnHelp = b = 450 > this.container.width;
  5848. this.hideSigOnStrips = !0;
  5849. f = [8, 8];
  5850. b ? (d = 198 + 2 * f[0],
  5851. e = 258 + 2 * f[1]) : (d = 354 + 2 * f[0],
  5852. e = 218 + 2 * f[1]);
  5853. g = document.createElement("div");
  5854. g.style.position = "absolute";
  5855. g.style.width = g.style.height = "100%";
  5856. this.helpOverlay.contents = g;
  5857. g = document.createElement("div");
  5858. g.style.position = "absolute";
  5859. g.style.right = marmoset.largeUI ? "92px" : "54px";
  5860. g.style.top = b ? "16px" : "48px";
  5861. g.style.width = d + "px";
  5862. g.style.height = e + "px";
  5863. this.helpOverlay.contents.appendChild(g);
  5864. e = document.createElement("div");
  5865. e.style.position = "absolute";
  5866. e.style.width = "100%";
  5867. e.style.height = "100%";
  5868. e.style.backgroundColor = "black";
  5869. e.style.opacity = "0.65";
  5870. e.style.borderRadius = "16px";
  5871. g.appendChild(e);
  5872. e = document.createElement("input");
  5873. e.type = "button";
  5874. e.value = "x";
  5875. e.style.position = "absolute";
  5876. e.style.color = "#FFFFFF";
  5877. e.style.fontWeight = "bolder";
  5878. e.style.backgroundColor = "rgba(0,0,0,0.0)";
  5879. e.style.border = "0px";
  5880. e.style.outline = "0px";
  5881. e.style.fontSize = marmoset.largeUI ? "16pt" : "10pt";
  5882. e.style.right = marmoset.largeUI ? "2px" : "8px";
  5883. e.style.top = marmoset.largeUI ? "0px" : "4px";
  5884. e.style.width = e.style.height = marmoset.largeUI ? "32px" : "16px";
  5885. e.style.pointerEvents = "auto";
  5886. e.style.cursor = "pointer";
  5887. e.onclick = function(a) {
  5888. this.helpOverlay.toggle();
  5889. this.refreshUI()
  5890. }
  5891. .bind(this, e);
  5892. g.appendChild(e);
  5893. e = document.createElement("center");
  5894. e.style.position = "absolute";
  5895. e.style.left = f[0] - 4 + "px";
  5896. e.style.right = f[0] + 4 + "px";
  5897. e.style.top = e.style.bottom = f[1] + "px";
  5898. e.style.paddingTop = "8px";
  5899. b || (e.style.paddingRight = "8px");
  5900. g.appendChild(e);
  5901. g = e;
  5902. f = (this.viewer.mobile ? "M" : "PC") + (2 < a ? 4 : 2) + "x.png";
  5903. e = document.createElement("img");
  5904. e.src = marmoset.dataLocale + "helprotate" + f;
  5905. e.style.width = "66px";
  5906. e.style.height = "90px";
  5907. g.appendChild(e);
  5908. e = document.createElement("img");
  5909. e.src = marmoset.dataLocale + "helpzoom" + f;
  5910. e.style.width = "66px";
  5911. e.style.height = "90px";
  5912. g.appendChild(e);
  5913. e = document.createElement("img");
  5914. e.src = marmoset.dataLocale + "helpmove" + f;
  5915. e.style.width = "66px";
  5916. e.style.height = "90px";
  5917. g.appendChild(e);
  5918. e = document.createElement("img");
  5919. e.src = marmoset.dataLocale + "helpreset" + f;
  5920. e.style.width = "66px";
  5921. e.style.height = "90px";
  5922. g.appendChild(e);
  5923. e = document.createElement("img");
  5924. e.src = marmoset.dataLocale + "helplights" + f;
  5925. e.style.position = "relative";
  5926. b || (e.style.left = "8px");
  5927. e.style.width = "66px";
  5928. e.style.height = "90px";
  5929. g.appendChild(e);
  5930. f = document.createElement("a");
  5931. f.href = "http://www.marmoset.co/viewer?utm_source=inapp&utm_medium=menu&utm_campaign=viewer";
  5932. f.target = "_blank";
  5933. f.style.pointerEvents = "auto";
  5934. g.appendChild(f);
  5935. h = document.createElement("img");
  5936. h.src = marmoset.dataLocale + "helpshadow.png";
  5937. h.style.position = "absolute";
  5938. h.style.left = 0.5 * d - (b ? 65 : 116) + "px";
  5939. h.style.bottom = b ? "6px" : "8px";
  5940. h.style.width = b ? "116px" : "232px";
  5941. h.style.opacity = 0;
  5942. f.appendChild(h);
  5943. h.targetOpacity = 0;
  5944. f.onmouseover = function() {
  5945. this.targetOpacity = 0.65
  5946. }
  5947. .bind(h);
  5948. f.onmouseout = function() {
  5949. this.targetOpacity = 0
  5950. }
  5951. .bind(h);
  5952. window.setInterval(function() {
  5953. this.style.opacity = 0.1 * this.targetOpacity + 0.9 * this.style.opacity
  5954. }
  5955. .bind(h), 20);
  5956. e = document.createElement("img");
  5957. e.src = marmoset.dataLocale + "helptitle.png";
  5958. e.style.position = "absolute";
  5959. e.style.left = 0.5 * d - (b ? 65 : 116) + "px";
  5960. e.style.bottom = b ? "8px" : "12px";
  5961. e.style.width = b ? "116px" : "232px";
  5962. f.appendChild(e);
  5963. d = document.createElement("div");
  5964. d.style.position = "absolute";
  5965. d.style.left = 0;
  5966. d.style.right = b ? "30px" : "108px";
  5967. d.style.bottom = b ? "-4px" : "4px";
  5968. d.style.textAlign = "right";
  5969. d.style.fontFamilly = "Arial";
  5970. g.appendChild(d);
  5971. b = document.createElement("font");
  5972. b.style.fontSize = "9pt";
  5973. b.style.fontFamily = "Arial";
  5974. d.appendChild(b);
  5975. f = document.createElement("a");
  5976. f.style.color = "#FF0044";
  5977. f.style.textDecoration = "none";
  5978. f.style.pointerEvents = "auto";
  5979. f.innerHTML = "www.marmoset.co/viewer";
  5980. f.href = "http://www.marmoset.co/viewer?utm_source=inapp&utm_medium=menu&utm_campaign=viewer";
  5981. f.target = "_blank";
  5982. f.onmouseover = function(a) {
  5983. this.style.textDecoration = "underline";
  5984. a.targetOpacity = 0.65
  5985. }
  5986. .bind(f, h);
  5987. f.onmouseout = function(a) {
  5988. this.style.textDecoration = "none";
  5989. a.targetOpacity = 0
  5990. }
  5991. .bind(f, h);
  5992. b.appendChild(f);
  5993. this.helpOverlay.active = !1;
  5994. this.helpOverlay.toggle = function(a) {
  5995. this.active ? this.removeChild(this.contents) : this.appendChild(this.contents);
  5996. this.active = !this.active
  5997. }
  5998. .bind(this.helpOverlay, this.viewer);
  5999. this.menuCluster = document.createElement("div");
  6000. this.menuCluster.style.position = "absolute";
  6001. this.menuCluster.style.right = marmoset.largeUI ? "4px" : "8px";
  6002. this.menuCluster.style.top = marmoset.largeUI ? "70px" : "40px";
  6003. marmoset.largeUI ? (this.menuCluster.style.width = "72px",
  6004. this.menuCluster.style.height = "64px") : (this.menuCluster.style.width = "36px",
  6005. this.menuCluster.style.height = "36px");
  6006. g = document.createElement("div");
  6007. g.style.left = g.style.top = "0px";
  6008. g.style.width = g.style.height = "100%";
  6009. this.menuCluster.contents = g;
  6010. this.menuCluster.appendChild(g);
  6011. b = 0;
  6012. d = function(a, b, c, d, e) {
  6013. var f = document.createElement("input");
  6014. f.type = "image";
  6015. f.src = marmoset.dataLocale + c;
  6016. f.style.position = "absolute";
  6017. f.style.left = "0px";
  6018. f.style.bottom = -100 * d + "%";
  6019. f.style.border = "none";
  6020. f.style.outline = "0px";
  6021. f.title = b;
  6022. f.style.opacity = e;
  6023. marmoset.largeUI ? (f.style.width = "64px",
  6024. f.style.height = "48px") : (f.style.width = "32px",
  6025. f.style.height = "24px");
  6026. f.onmouseover = function(a) {
  6027. this.style.opacity = a
  6028. }
  6029. .bind(f, 1);
  6030. f.onmouseout = function(a) {
  6031. this.style.opacity = a
  6032. }
  6033. .bind(f, e);
  6034. f.onmouseup = function(a) {
  6035. this.style.opacity = a
  6036. }
  6037. .bind(f, e);
  6038. b = new XMLHttpRequest;
  6039. b.open("HEAD", f.src, !0);
  6040. b.onload = function(a) {
  6041. a.appendChild(this)
  6042. }
  6043. .bind(f, a);
  6044. b.send();
  6045. return f
  6046. }
  6047. ;
  6048. FullScreen.support() && (g = d(this.menuCluster.contents, "Full Screen", "fullscreen" + a + "x.png", b++, c),
  6049. g.onclick = function(a) {
  6050. FullScreen.active() ? FullScreen.end() : FullScreen.begin(this.viewer.domRoot, this.viewer.fullscreenChange.bind(this.viewer));
  6051. a.style.opacity = c;
  6052. this.refreshUI()
  6053. }
  6054. .bind(this, g));
  6055. g = d(this.menuCluster.contents, "Layer Views", "strips" + a + "x.png", b++, c);
  6056. g.onclick = function(a) {
  6057. this.stripData.toggleMenu();
  6058. this.helpOverlay.active && this.helpOverlay.toggle();
  6059. this.viewer.wake();
  6060. this.refreshUI()
  6061. }
  6062. .bind(this, g);
  6063. g = d(this.menuCluster.contents, "Help", "help" + a + "x.png", b++, c);
  6064. g.onclick = function(a) {
  6065. this.stripData.selectedStrip == this.stripData.STRIP_MENU && this.stripData.toggleMenu();
  6066. this.helpOverlay.toggle();
  6067. this.refreshUI()
  6068. }
  6069. .bind(this, g);
  6070. this.guiScreen && this.guiScreen.setupActiveView(this);
  6071. this.container.appendChild(this.menuCluster);
  6072. this.menuCluster.active = !0;
  6073. this.menuCluster.toggle = function() {
  6074. this.active ? this.removeChild(this.contents) : this.appendChild(this.contents);
  6075. this.active = !this.active
  6076. }
  6077. .bind(this.menuCluster);
  6078. void 0 !== marmoset.hostImage && (marmoset.hostURL && (f = document.createElement("a"),
  6079. f.href = marmoset.hostURL,
  6080. f.target = "_blank"),
  6081. e = document.createElement("img"),
  6082. e.src = marmoset.hostImage,
  6083. e.style.position = "absolute",
  6084. e.style.top = "4px",
  6085. e.style.left = "4px",
  6086. e.style.opacity = 0.65,
  6087. e.style["-webkit-transform"] = e.style.transform = "translate(-50%,-50%) scale(0.5,0.5) translate(50%,50%)",
  6088. marmoset.hostURL ? (e.onmouseover = function() {
  6089. this.style.opacity = 1
  6090. }
  6091. .bind(e),
  6092. e.onmouseout = function() {
  6093. this.style.opacity = 0.5
  6094. }
  6095. .bind(e),
  6096. f.appendChild(e),
  6097. this.hostLogo = f) : this.hostLogo = e,
  6098. b = new XMLHttpRequest,
  6099. b.open("HEAD", e.src, !0),
  6100. b.onload = function() {
  6101. this.container.appendChild(this.hostLogo)
  6102. }
  6103. .bind(this),
  6104. b.send());
  6105. this.sceneStats = document.createElement("text");
  6106. this.sceneStats.style.position = "absolute";
  6107. this.sceneStats.style.left = "9px";
  6108. this.sceneStats.style.bottom = "8px";
  6109. this.sceneStats.style.color = "gray";
  6110. this.sceneStats.style.fontFamily = "Arial";
  6111. this.sceneStats.style.fontSize = "75%";
  6112. for (d = b = a = 0; d < this.viewer.scene.meshes.length; ++d)
  6113. g = this.viewer.scene.meshes[d],
  6114. a += g.indexCount / 3,
  6115. b += g.vertexCount;
  6116. this.sceneStats.innerHTML = "Triangles: " + (a | 0).toLocaleString() + "<br>Vertices: " + (b | 0).toLocaleString();
  6117. marmoset.showFrameTime && (this.frameTimer = document.createElement("text"),
  6118. this.frameTimer.style.position = "absolute",
  6119. this.frameTimer.style.left = this.frameTimer.style.top = "5px",
  6120. this.frameTimer.style.color = "gray",
  6121. this.frameTimer.style.fontSize = "75%",
  6122. this.container.appendChild(this.frameTimer),
  6123. this.frameTimer.innerHTML = "--",
  6124. this.frameCount = 1E20);
  6125. this.animateStrips()
  6126. }
  6127. }
  6128. ;
  6129. UI.prototype.refreshUI = function() {
  6130. if (this.sigCluster) {
  6131. var a = !1
  6132. , c = this.stripData.selectedStrip == this.stripData.STRIP_MENU;
  6133. this.hideSigOnStrips && (a = a || c);
  6134. this.hideSigOnHelp && (a = a || this.helpOverlay.active);
  6135. this.sigCluster.active == a && this.sigCluster.toggle()
  6136. }
  6137. }
  6138. ;
  6139. UI.prototype.signalLoadProgress = function(a, c) {
  6140. if (this.thumbnail) {
  6141. if (!this.progressBar) {
  6142. var b = document.createElement("div");
  6143. b.style.backgroundColor = "rgb(30,30,30)";
  6144. b.style.opacity = 0.5;
  6145. b.style.position = "absolute";
  6146. b.style.left = "20%";
  6147. b.style.width = "60%";
  6148. b.style.bottom = "30%";
  6149. b.style.height = "2px";
  6150. this.progressBar = document.createElement("div");
  6151. this.progressBar.style.backgroundColor = "white";
  6152. this.progressBar.style.position = "absolute";
  6153. this.progressBar.style.left = this.progressBar.style.bottom = "0px";
  6154. this.progressBar.style.height = "100%";
  6155. this.progressBar.style.width = "0px";
  6156. b.appendChild(this.progressBar);
  6157. this.container.appendChild(b);
  6158. this.playButton && (this.container.removeChild(this.playButton),
  6159. delete this.playButton)
  6160. }
  6161. this.progressBar.style.width = 0 >= c ? (100 * a / (2097152 + a) | 0) + "%" : (100 * a / c | 0) + "%"
  6162. }
  6163. }
  6164. ;
  6165. UI.prototype.animating = function() {
  6166. return !!this.fadeThumbnail || !!this.frameTimer
  6167. }
  6168. ;
  6169. UI.prototype.animate = function() {
  6170. this.fadeThumbnail && (this.fadeThumbnailTimer = this.fadeThumbnailTimer || Date.now(),
  6171. this.fadeThumbnail.style.opacity = 1 - 0.0015 * (Date.now() - this.fadeThumbnailTimer),
  6172. 0.01 > this.fadeThumbnail.style.opacity && (this.container.removeChild(this.fadeThumbnail),
  6173. delete this.fadeThumbnail,
  6174. delete this.fadeThumbnailTimer));
  6175. if (this.frameTimer && (this.frameCount++,
  6176. 60 <= this.frameCount)) {
  6177. var a = (new Date).getTime();
  6178. if (void 0 !== this.frameTime) {
  6179. var c = (a - this.frameTime) / this.frameCount
  6180. , c = Math.floor(100 * c) / 100;
  6181. this.frameTimer.innerHTML = c + " ms";
  6182. this.frameTimer.style.color = 32 > c ? "green" : "red"
  6183. }
  6184. this.frameCount = 0;
  6185. this.frameTime = a
  6186. }
  6187. this.guiScreen && this.guiScreen.playbackControls && (a = this.guiScreen.playbackControls.timelineSlider,
  6188. a.draggingSlider ? this.viewer.scene.sceneAnimator.setAnimationProgress(a.sliderPercent, !0) : a.setSliderPercent(this.viewer.scene.sceneAnimator.animationProgress));
  6189. if (this.sceneStats) {
  6190. for (var b = c = a = 0; b < this.viewer.scene.meshes.length; ++b)
  6191. var d = this.viewer.scene.meshes[b]
  6192. , a = a + d.indexCount / 3
  6193. , c = c + d.vertexCount;
  6194. this.sceneStats.innerHTML = "Triangles: " + (a | 0).toLocaleString() + "<br>Vertices: " + (c | 0).toLocaleString();
  6195. this.viewer.scene.sceneAnimator && this.viewer.scene.sceneAnimator.showPlayControls && (this.sceneStats.innerHTML += "<br><br><br><br>");
  6196. a = !!this.sceneStats.parentElement;
  6197. c = this.stripData.active() || !1;
  6198. a && !c ? (this.container.removeChild(this.sceneStats),
  6199. this.hostLogo && this.container.appendChild(this.hostLogo)) : !a && c && (this.container.appendChild(this.sceneStats),
  6200. this.hostLogo && this.container.removeChild(this.hostLogo))
  6201. }
  6202. this.refreshUI();
  6203. if (this.stripData.animationActive || this.stripData.active())
  6204. this.animateStrips(),
  6205. this.stripData.animationActive && this.viewer.wake()
  6206. }
  6207. ;
  6208. UI.prototype.animateStrips = function() {
  6209. if (this.stripText)
  6210. for (var a = Math.atan(this.viewer.canvas.height / this.viewer.canvas.width / this.stripData.stripSlant), c = 0; c < this.stripData.labels.length; ++c) {
  6211. var b = this.stripData.strips[c]
  6212. , b = b - this.stripData.stripSlant
  6213. , b = 0.5 + 0.5 * b;
  6214. c == this.stripData.selectedStrip ? (this.stripText[c].style["-ms-transform"] = this.stripText[c].style["-webkit-transform"] = this.stripText[c].style.transform = "none",
  6215. this.stripText[c].style.top = "4px",
  6216. this.stripText[c].style.left = "0px",
  6217. this.stripText[c].style.width = "150px",
  6218. this.stripText[c].txt.style.textAlign = "center",
  6219. this.stripText[c].txt.style.background = "rgba(0, 0, 0, 0.75)",
  6220. this.stripText[c].txt.style.background = "-webkit-linear-gradient(left, rgba(0,0,0,0.75), rgba(0,0,0,0))",
  6221. this.stripText[c].txt.style.background = "-o-linear-gradient(left, rgba(0,0,0,0.75), rgba(0,0,0,0))",
  6222. this.stripText[c].txt.style.background = "-moz-linear-gradient(left, rgba(0,0,0,0.75), rgba(0,0,0,0))",
  6223. this.stripText[c].txt.style.background = "linear-gradient(left, rgba(0,0,0,0.75), rgba(0,0,0,0))",
  6224. this.stripText[c].txt.style.paddingLeft = "32px",
  6225. this.stripText[c].txt.style.paddingTop = "6px",
  6226. this.stripText[c].txt.style.paddingBottom = "4px",
  6227. this.stripText[c].txt.style.textShadow = "1px 1px 2px rgba(0,0,0,0.7)",
  6228. this.stripText[c].line.style.opacity = 0.5,
  6229. this.stripText[c].line.style.top = "100%",
  6230. this.stripText[c].line.style.width = "100%",
  6231. this.stripText[c].line.style.height = "1px") : (this.stripText[c].style["-ms-transform"] = this.stripText[c].style["-webkit-transform"] = this.stripText[c].style.transform = "translate(-50%, -50%) rotate(" + a + "rad) translate(50%, 50%)",
  6232. this.stripText[c].style.left = 100 * b + "%",
  6233. this.stripText[c].style.top = "0px",
  6234. this.stripText[c].style.width = "85px",
  6235. this.stripText[c].txt.style.textAlign = "left",
  6236. this.stripText[c].txt.style.background = "none",
  6237. this.stripText[c].txt.style.paddingLeft = "8px",
  6238. this.stripText[c].txt.style.paddingTop = "6px",
  6239. this.stripText[c].txt.style.paddingBottom = "4px",
  6240. this.stripText[c].txt.style.textShadow = "2px 0px 3px rgba(0,0,0,0.7)",
  6241. this.stripText[c].line.style.opacity = 1,
  6242. this.stripText[c].line.style.top = "-1px",
  6243. this.stripText[c].line.style.width = "10000px",
  6244. this.stripText[c].line.style.height = "2px")
  6245. }
  6246. }
  6247. ;
  6248. var Vect = {
  6249. type: Float32Array,
  6250. create: function(a, c, b, d) {
  6251. var e = new Vect.type(4);
  6252. e[0] = a;
  6253. e[1] = c;
  6254. e[2] = b;
  6255. e[3] = d;
  6256. return e
  6257. },
  6258. empty: function() {
  6259. return new Vect.type(4)
  6260. },
  6261. set: function(a, c, b, d, e) {
  6262. a[0] = c;
  6263. a[1] = b;
  6264. a[2] = d;
  6265. a[3] = e
  6266. },
  6267. copy: function(a, c) {
  6268. a[0] = c[0];
  6269. a[1] = c[1];
  6270. a[2] = c[2];
  6271. a[3] = c[3]
  6272. },
  6273. add: function(a, c, b) {
  6274. a[0] = c[0] + b[0];
  6275. a[1] = c[1] + b[1];
  6276. a[2] = c[2] + b[2];
  6277. a[3] = c[3] + b[3];
  6278. return a
  6279. },
  6280. sub: function(a, c, b) {
  6281. a[0] = c[0] - b[0];
  6282. a[1] = c[1] - b[1];
  6283. a[2] = c[2] - b[2];
  6284. a[3] = c[3] - b[3];
  6285. return a
  6286. },
  6287. scale: function(a, c, b) {
  6288. a[0] = b[0] * c;
  6289. a[1] = b[1] * c;
  6290. a[2] = b[2] * c;
  6291. a[3] = b[3] * c;
  6292. return a
  6293. },
  6294. mul: function(a, c, b) {
  6295. a[0] = c[0] * b[0];
  6296. a[1] = c[1] * b[1];
  6297. a[2] = c[2] * b[2];
  6298. a[3] = c[3] * b[3];
  6299. return a
  6300. },
  6301. mad: function(a, c, b, d) {
  6302. a[0] = c[0] * b[0] + d[0];
  6303. a[1] = c[1] * b[1] + d[1];
  6304. a[2] = c[2] * b[2] + d[2];
  6305. a[3] = c[3] * b[3] + d[3];
  6306. return a
  6307. },
  6308. smad: function(a, c, b, d) {
  6309. a[0] = c * b[0] + d[0];
  6310. a[1] = c * b[1] + d[1];
  6311. a[2] = c * b[2] + d[2];
  6312. a[3] = c * b[3] + d[3];
  6313. return a
  6314. },
  6315. negate: function(a, c) {
  6316. a[0] = -c[0];
  6317. a[1] = -c[1];
  6318. a[2] = -c[2];
  6319. return a
  6320. },
  6321. negate4: function(a, c) {
  6322. a[0] = -c[0];
  6323. a[1] = -c[1];
  6324. a[2] = -c[2];
  6325. a[3] = -c[3];
  6326. return a
  6327. },
  6328. length: function(a) {
  6329. var c = a[0]
  6330. , b = a[1];
  6331. a = a[2];
  6332. return Math.sqrt(c * c + b * b + a * a)
  6333. },
  6334. distance: function(a, c) {
  6335. var b = a[0] - c[0]
  6336. , d = a[1] - c[1]
  6337. , e = a[2] - c[2];
  6338. return Math.sqrt(b * b + d * d + e * e)
  6339. },
  6340. dot: function(a, c) {
  6341. return a[0] * c[0] + a[1] * c[1] + a[2] * c[2]
  6342. },
  6343. dot4: function(a, c) {
  6344. return a[0] * c[0] + a[1] * c[1] + a[2] * c[2] + a[3] * c[3]
  6345. },
  6346. normalize: function(a, c) {
  6347. var b = c[0]
  6348. , d = c[1]
  6349. , e = c[2]
  6350. , f = Math.sqrt(b * b + d * d + e * e);
  6351. if (0 == f)
  6352. return Vect.set(a, 0, 0, 0, 0);
  6353. f = 1 / f;
  6354. a[0] = b * f;
  6355. a[1] = d * f;
  6356. a[2] = e * f;
  6357. return a
  6358. },
  6359. cross: function(a, c, b) {
  6360. a[0] = c[1] * b[2];
  6361. a[0] += -c[2] * b[1];
  6362. a[1] = c[2] * b[0] - c[0] * b[2];
  6363. a[2] = c[0] * b[1] - c[1] * b[0];
  6364. return a
  6365. },
  6366. lerp: function(a, c, b, d) {
  6367. var e = 1 - d;
  6368. a[0] = c[0] * e + b[0] * d;
  6369. a[1] = c[1] * e + b[1] * d;
  6370. a[2] = c[2] * e + b[2] * d;
  6371. return a
  6372. },
  6373. lerp4: function(a, c, b, d) {
  6374. var e = 1 - d;
  6375. a[0] = c[0] * e + b[0] * d;
  6376. a[1] = c[1] * e + b[1] * d;
  6377. a[2] = c[2] * e + b[2] * d;
  6378. a[3] = c[3] * e + b[3] * d;
  6379. return a
  6380. },
  6381. min: function(a, c, b) {
  6382. a[0] = Math.min(c[0], b[0]);
  6383. a[1] = Math.min(c[1], b[1]);
  6384. a[2] = Math.min(c[2], b[2]);
  6385. a[3] = Math.min(c[3], b[3]);
  6386. return a
  6387. },
  6388. max: function(a, c, b) {
  6389. a[0] = Math.max(c[0], b[0]);
  6390. a[1] = Math.max(c[1], b[1]);
  6391. a[2] = Math.max(c[2], b[2]);
  6392. a[3] = Math.max(c[3], b[3]);
  6393. return a
  6394. },
  6395. projectOnPlane: function(a, c, b, d) {
  6396. var e = Vect.empty();
  6397. Vect.sub(e, c, b);
  6398. b = Vect.dot(e, d);
  6399. smad(a, -b, normal, c);
  6400. return a
  6401. }
  6402. };
  6403. function View(a) {
  6404. this.pivot = [0, 0, 0];
  6405. this.rotation = [0, 0];
  6406. this.radius = 1;
  6407. this.nearPlane = 0.3;
  6408. this.fov = 45;
  6409. this.size = [1, 1];
  6410. this.transform = Matrix.empty();
  6411. this.viewMatrix = Matrix.empty();
  6412. this.projectionMatrix = Matrix.empty();
  6413. this.viewProjectionMatrix = Matrix.empty();
  6414. a ? this.loadView(a, !0) : (this.saveResetView(),
  6415. this.updateView(),
  6416. this.updateProjection())
  6417. }
  6418. View.prototype.saveResetView = function() {
  6419. this.resetDesc = {
  6420. angles: [this.rotation[0], this.rotation[1]],
  6421. pivot: [this.pivot[0], this.pivot[1], this.pivot[2]],
  6422. limits: this.limits,
  6423. orbitRadius: this.radius,
  6424. fov: this.fov
  6425. }
  6426. }
  6427. ;
  6428. View.prototype.loadView = function(a, c) {
  6429. a && (this.rotation[0] = a.angles[0],
  6430. this.rotation[1] = a.angles[1],
  6431. this.pivot[0] = a.pivot[0],
  6432. this.pivot[1] = a.pivot[1],
  6433. this.pivot[2] = a.pivot[2],
  6434. this.radius = a.orbitRadius,
  6435. this.fov = a.fov,
  6436. this.limits = a.limits,
  6437. c && this.saveResetView(),
  6438. this.updateView(),
  6439. this.updateProjection())
  6440. }
  6441. ;
  6442. View.prototype.reset = function() {
  6443. this.loadView(this.resetDesc)
  6444. }
  6445. ;
  6446. View.prototype.updateView = function() {
  6447. if (void 0 !== this.limits) {
  6448. if (this.limits.angles) {
  6449. var a = this.limits.angles.x
  6450. , c = this.limits.angles.y;
  6451. if (void 0 !== a) {
  6452. var b = this.rotation[0] - a.offset
  6453. , a = Math.min(Math.max(b, a.min), a.max);
  6454. this.rotation[0] += a - b
  6455. }
  6456. void 0 !== c && (b = this.rotation[1] - c.offset,
  6457. a = Math.min(Math.max(b, c.min), c.max),
  6458. this.rotation[1] += a - b)
  6459. }
  6460. void 0 !== this.limits.orbitRadius && (c = this.limits.orbitRadius.min,
  6461. b = this.limits.orbitRadius.max,
  6462. void 0 !== c && (this.radius = Math.max(this.radius, c)),
  6463. void 0 !== b && (this.radius = Math.min(this.radius, b)));
  6464. void 0 !== this.limits.pan && (c = this.limits.pan,
  6465. b = this.resetDesc.pivot,
  6466. c.x && (this.pivot[0] = b[0]),
  6467. c.y && (this.pivot[1] = b[1]),
  6468. c.z && (this.pivot[2] = b[2]))
  6469. }
  6470. Matrix.translation(this.transform, 0, 0, this.radius);
  6471. c = Matrix.rotation(Matrix.empty(), this.rotation[0], 0);
  6472. b = Matrix.rotation(Matrix.empty(), this.rotation[1], 1);
  6473. Matrix.mul(c, b, c);
  6474. Matrix.mul(this.transform, c, this.transform);
  6475. this.transform[12] += this.pivot[0];
  6476. this.transform[13] += this.pivot[1];
  6477. this.transform[14] += this.pivot[2];
  6478. Matrix.invert(this.viewMatrix, this.transform);
  6479. Matrix.mul(this.viewProjectionMatrix, this.viewMatrix, this.projectionMatrix)
  6480. }
  6481. ;
  6482. View.prototype.updateProjection = function(a) {
  6483. Matrix.perspectiveInfinite(this.projectionMatrix, this.fov, this.size[0] / this.size[1], this.nearPlane, a);
  6484. Matrix.mul(this.viewProjectionMatrix, this.projectionMatrix, this.viewMatrix)
  6485. }
  6486. ;
  6487. function WebViewer(a, c, b, d) {
  6488. this.mobile = !!/Android|iPhone|iPod|iPad|Windows Phone|IEMobile|BlackBerry|webOS/.test(navigator.userAgent);
  6489. this.mobileFast = !!/iPhone|iPad/.test(navigator.userAgent);
  6490. var e;
  6491. if (e = !this.mobile)
  6492. a: {
  6493. e = document.createElement("canvas");
  6494. e.width = e.height = 16;
  6495. if (e = e.getContext("webgl", {}) || e.getContext("experimental-webgl", {})) {
  6496. var f = e.getExtension("WEBGL_debug_renderer_info");
  6497. if (f) {
  6498. e = e.getParameter(f.UNMASKED_RENDERER_WEBGL);
  6499. e = !!/Intel|INTEL/.test(e);
  6500. break a
  6501. }
  6502. }
  6503. e = !1
  6504. }
  6505. this.desktopSlow = e;
  6506. this.domRoot = document.createElement("div");
  6507. this.domRoot.style.width = a + "px";
  6508. this.domRoot.style.height = c + "px";
  6509. this.initCanvas(a, c);
  6510. this.scene = this.input = null;
  6511. this.sceneURL = b;
  6512. this.sleepCounter = 8;
  6513. this.onLoad = null;
  6514. this.stripData = new StripData;
  6515. this.ui = new UI(this);
  6516. this.ui.setSize(a, c);
  6517. this.ui.showPreview(d)
  6518. }
  6519. WebViewer.prototype.initCanvas = function(a, c) {
  6520. this.canvas && this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
  6521. this.canvas = document.createElement("canvas");
  6522. this.pixelRatio = window.devicePixelRatio || 1;
  6523. if (this.mobile) {
  6524. var b = this.mobileFast ? 1.5 : 1;
  6525. this.pixelRatio = this.pixelRatio > b ? b : this.pixelRatio
  6526. } else
  6527. this.desktopSlow && (this.pixelRatio = 1);
  6528. this.canvas.width = a * this.pixelRatio;
  6529. this.canvas.height = c * this.pixelRatio;
  6530. this.canvas.style.width = a + "px";
  6531. this.canvas.style.height = c + "px";
  6532. this.canvas.style.position = "absolute";
  6533. this.domRoot.appendChild(this.canvas)
  6534. }
  6535. ;
  6536. WebViewer.prototype.initGL = function() {
  6537. var a = {
  6538. alpha: !!marmoset.transparentBackground,
  6539. depth: !1,
  6540. stencil: !1,
  6541. antialias: !1,
  6542. premultipliedAlpha: !!marmoset.transparentBackground,
  6543. preserveDrawingBuffer: !1
  6544. }
  6545. , a = this.gl = this.canvas.getContext("webgl", a) || this.canvas.getContext("experimental-webgl", a);
  6546. if (!this.gl)
  6547. return this.ui.showFailure('Please <a href="http://get.webgl.org/" target=_blank>check<a/> to ensure your browser has support for WebGL.'),
  6548. !1;
  6549. this.canvas.addEventListener("webglcontextlost", function(a) {
  6550. a.preventDefault()
  6551. }
  6552. .bind(this), !1);
  6553. this.canvas.addEventListener("webglcontextrestored", function(a) {
  6554. this.loadScene(this.sceneURL)
  6555. }
  6556. .bind(this), !1);
  6557. a.ext = {
  6558. textureAniso: a.getExtension("EXT_texture_filter_anisotropic") || a.getExtension("WEBKIT_EXT_texture_filter_anisotropic") || a.getExtension("MOZ_EXT_texture_filter_anisotropic"),
  6559. textureFloat: a.getExtension("OES_texture_float"),
  6560. textureFloatLinear: a.getExtension("OES_texture_float_linear"),
  6561. textureHalf: a.getExtension("OES_texture_half_float"),
  6562. textureHalfLinear: a.getExtension("OES_texture_half_float_linear"),
  6563. textureDepth: a.getExtension("WEBGL_depth_texture"),
  6564. colorBufferFloat: a.getExtension("WEBGL_color_buffer_float"),
  6565. colorBufferHalf: a.getExtension("EXT_color_buffer_half_float"),
  6566. index32bit: a.getExtension("OES_element_index_uint"),
  6567. loseContext: a.getExtension("WEBGL_lose_context"),
  6568. derivatives: a.getExtension("OES_standard_derivatives"),
  6569. renderInfo: a.getExtension("WEBGL_debug_renderer_info")
  6570. };
  6571. a.limits = {
  6572. textureSize: a.getParameter(a.MAX_TEXTURE_SIZE),
  6573. textureCount: a.getParameter(a.MAX_TEXTURE_IMAGE_UNITS),
  6574. varyings: a.getParameter(a.MAX_VARYING_VECTORS),
  6575. vertexAttribs: a.getParameter(a.MAX_VERTEX_ATTRIBS),
  6576. vertexUniforms: a.getParameter(a.MAX_VERTEX_UNIFORM_VECTORS),
  6577. fragmentUniforms: a.getParameter(a.MAX_FRAGMENT_UNIFORM_VECTORS),
  6578. viewportSizes: a.getParameter(a.MAX_VIEWPORT_DIMS),
  6579. vendor: a.getParameter(a.VENDOR),
  6580. version: a.getParameter(a.VERSION)
  6581. };
  6582. a.hints = {
  6583. mobile: this.mobile,
  6584. pixelRatio: this.pixelRatio
  6585. };
  6586. a.enable(a.DEPTH_TEST);
  6587. a.shaderCache = new ShaderCache(a);
  6588. a.textureCache = new TextureCache(a);
  6589. this.allocBacking();
  6590. return !0
  6591. }
  6592. ;
  6593. WebViewer.prototype.allocBacking = function() {
  6594. var a = this.gl
  6595. , c = !1
  6596. , b = {
  6597. width: this.canvas.width,
  6598. height: this.canvas.height
  6599. };
  6600. this.mainColor = new Texture(a,b);
  6601. this.mainDepth = null;
  6602. a.ext.textureDepth && (this.mainDepth = new Texture(a,{
  6603. width: this.canvas.width,
  6604. height: this.canvas.height,
  6605. nofilter: !0
  6606. }),
  6607. this.mainDepth.loadArray(null, a.DEPTH_COMPONENT, a.UNSIGNED_INT));
  6608. a.ext.textureHalf && a.ext.textureHalfLinear && (this.mainColor.loadArray(null, a.RGBA, a.ext.textureHalf.HALF_FLOAT_OES),
  6609. this.mainBuffer = new Framebuffer(a,{
  6610. color0: this.mainColor,
  6611. depth: this.mainDepth,
  6612. createDepth: !this.mainDepth
  6613. }),
  6614. c = this.mainBuffer.valid);
  6615. !c && a.ext.textureFloat && a.ext.textureFloatLinear && !a.hints.mobile && (this.mainColor.loadArray(null, a.RGBA, a.FLOAT),
  6616. this.mainBuffer = new Framebuffer(a,{
  6617. color0: this.mainColor,
  6618. depth: this.mainDepth,
  6619. createDepth: !this.mainDepth
  6620. }),
  6621. c = this.mainBuffer.valid);
  6622. for (; !c; )
  6623. this.mainColor = new Texture(a,b),
  6624. this.mainColor.loadArray(null, a.RGBA, a.UNSIGNED_BYTE),
  6625. this.mainBuffer = new Framebuffer(a,{
  6626. color0: this.mainColor,
  6627. depth: this.mainDepth,
  6628. createDepth: !this.mainDepth
  6629. }),
  6630. c = this.mainBuffer.valid,
  6631. b.width /= 2,
  6632. b.height /= 2,
  6633. this.mainDepth && (this.mainDepth.destroy(),
  6634. this.mainDepth = null);
  6635. this.mainBufferNoDepth = new Framebuffer(a,{
  6636. color0: this.mainColor
  6637. })
  6638. }
  6639. ;
  6640. WebViewer.prototype.loadScene = function(a) {
  6641. this.sceneURL = a || this.sceneURL;
  6642. this.scene = this.input = null;
  6643. if (this.initGL() && this.sceneURL) {
  6644. var c = this.ui.signalLoadProgress.bind(this.ui);
  6645. a = function(a) {
  6646. c(1, 1);
  6647. this.scene = new Scene(this.gl);
  6648. this.scene.stripData = this.stripData;
  6649. if (this.scene.load(new Archive(a)))
  6650. if (2070 >= this.scene.metaData.tbVersion)
  6651. this.ui.showFailure("This .mview file is from an out-of-date beta version of Toolbag. Please re-export it with the new version. Thanks!");
  6652. else {
  6653. if (this.bindInput(),
  6654. this.requestFrame(this.updateLoad.bind(this)),
  6655. this.onLoad)
  6656. this.onLoad()
  6657. }
  6658. else
  6659. this.ui.showFailure("Package file could not be read or is invalid.")
  6660. }
  6661. .bind(this);
  6662. var b = function() {
  6663. this.ui.showFailure("Package file (" + this.sceneURL + ") could not be retrieved.")
  6664. }
  6665. .bind(this);
  6666. Network.fetchBinary(this.sceneURL, a, b, c)
  6667. }
  6668. }
  6669. ;
  6670. WebViewer.prototype.unload = function() {
  6671. delete this.scene;
  6672. delete this.input;
  6673. delete this.ui;
  6674. delete this.mainColor;
  6675. delete this.mainBuffer;
  6676. delete this.gl;
  6677. var a = this.domRoot.clientWidth
  6678. , c = this.domRoot.clientHeight;
  6679. this.initCanvas(a, c);
  6680. this.ui = new UI(this);
  6681. this.ui.setSize(a, c);
  6682. this.ui.showPreview();
  6683. this.cancelFrame()
  6684. }
  6685. ;
  6686. WebViewer.prototype.bindInput = function() {
  6687. this.input = new Input(this.ui.container);
  6688. this.input.onDrag.push(function(a, c, b, d) {
  6689. a = 1 - 2.2 / (Math.sqrt(b * b + d * d) + 2.2);
  6690. c = this.scene.view;
  6691. c.rotation[1] -= 0.4 * b * a;
  6692. c.rotation[0] -= 0.4 * d * a;
  6693. c.rotation[0] = 90 < c.rotation[0] ? 90 : c.rotation[0];
  6694. c.rotation[0] = -90 > c.rotation[0] ? -90 : c.rotation[0];
  6695. c.updateView();
  6696. this.wake()
  6697. }
  6698. .bind(this));
  6699. this.input.onPan.push(function(a, c) {
  6700. var b = this.scene.view
  6701. , d = b.fov / 45 * 0.8 * (b.radius / this.domRoot.clientHeight)
  6702. , e = -a * d
  6703. , d = c * d;
  6704. b.pivot[0] += e * b.transform[0] + d * b.transform[4];
  6705. b.pivot[1] += e * b.transform[1] + d * b.transform[5];
  6706. b.pivot[2] += e * b.transform[2] + d * b.transform[6];
  6707. b.updateView();
  6708. this.wake()
  6709. }
  6710. .bind(this));
  6711. this.input.onPan2.push(function(a, c) {
  6712. var b = 1 - 2.2 / (Math.sqrt(a * a + c * c) + 2.2);
  6713. this.scene.lights.rotation -= 0.4 * a * b;
  6714. this.wake()
  6715. }
  6716. .bind(this));
  6717. this.input.onZoom.push(function(a) {
  6718. var c = this.scene.view;
  6719. c.radius *= 1 - 0.002 * a;
  6720. c.radius = 0.001 > c.radius ? 0.001 : c.radius;
  6721. c.radius = 1E3 < c.radius ? 1E3 : c.radius;
  6722. c.updateView();
  6723. this.wake()
  6724. }
  6725. .bind(this));
  6726. this.input.onDoubleTap.push(function(a, c) {
  6727. this.scene.view.reset();
  6728. this.scene.sceneAnimator && this.scene.sceneAnimator.resetCustomView();
  6729. this.wake()
  6730. }
  6731. .bind(this));
  6732. this.ui.bindInput(this.input)
  6733. }
  6734. ;
  6735. WebViewer.prototype.wake = function(a) {
  6736. a = a || 16;
  6737. this.sleepCounter = this.sleepCounter < a ? a : this.sleepCounter;
  6738. this.scene.postRender.discardAAHistory();
  6739. this.requestFrame(this.update.bind(this))
  6740. }
  6741. ;
  6742. WebViewer.prototype.requestFrame = function(a) {
  6743. var c = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
  6744. if (!this.frameRequestPending) {
  6745. var b = function() {
  6746. this.frameRequestPending = 0;
  6747. a()
  6748. }
  6749. .bind(this);
  6750. this.frameRequestPending = c(b, this.canvas)
  6751. }
  6752. }
  6753. ;
  6754. WebViewer.prototype.cancelFrame = function() {
  6755. this.frameRequestPending && (window.cancelAnimationFrame || window.mozCancelAnimationFrame || window.webkitCancelAnimationFrame || window.msCancelAnimationFrame)(this.frameRequestPending)
  6756. }
  6757. ;
  6758. WebViewer.prototype.fullscreenChange = function() {
  6759. FullScreen.active() ? (this.oldRootWidth = this.domRoot.style.width,
  6760. this.oldRootHeight = this.domRoot.style.height,
  6761. this.domRoot.style.width = "100%",
  6762. this.domRoot.style.height = "100%") : (this.domRoot.style.width = this.oldRootWidth,
  6763. this.domRoot.style.height = this.oldRootHeight);
  6764. this.wake()
  6765. }
  6766. ;
  6767. WebViewer.prototype.resize = function(a, c) {
  6768. a && c ? (this.domRoot.style.width = a + "px",
  6769. this.domRoot.style.height = c + "px") : (a = this.domRoot.clientWidth,
  6770. c = this.domRoot.clientHeight);
  6771. this.canvas.width = a * this.pixelRatio;
  6772. this.canvas.height = c * this.pixelRatio;
  6773. this.canvas.style.width = a + "px";
  6774. this.canvas.style.height = c + "px";
  6775. this.ui.setSize(a, c);
  6776. this.allocBacking();
  6777. this.wake()
  6778. }
  6779. ;
  6780. WebViewer.prototype.updateLoad = function() {
  6781. this.scene.complete() ? this.start() : this.requestFrame(this.updateLoad.bind(this));
  6782. this.ui.animate()
  6783. }
  6784. ;
  6785. WebViewer.prototype.start = function() {
  6786. this.scene.view.updateView();
  6787. this.ui.showActiveView();
  6788. this.requestFrame(this.update.bind(this))
  6789. }
  6790. ;
  6791. WebViewer.prototype.update = function() {
  6792. var a = this.scene.sceneAnimator && !this.scene.sceneAnimator.paused;
  6793. if (0 < this.sleepCounter || this.ui.animating() || a || this.stripData.animationActive)
  6794. this.stripData.update(),
  6795. this.ui.animate(),
  6796. this.scene.update(),
  6797. this.drawScene(),
  6798. this.requestFrame(this.update.bind(this));
  6799. a ? this.scene.postRender.discardAAHistory() : this.sleepCounter--
  6800. }
  6801. ;
  6802. WebViewer.prototype.reDrawScene = function() {
  6803. this.stripData.update();
  6804. this.ui.animate();
  6805. this.scene.update();
  6806. this.drawScene();
  6807. this.requestFrame(this.update.bind(this));
  6808. this.scene.postRender.discardAAHistory()
  6809. }
  6810. ;
  6811. WebViewer.prototype.drawScene = function() {
  6812. this.gl.isContextLost() || (this.domRoot.clientWidth == this.canvas.clientWidth && this.domRoot.clientHeight == this.canvas.clientHeight || this.resize(),
  6813. this.scene.view.size = [this.mainBuffer.width, this.mainBuffer.height],
  6814. this.scene.view.updateProjection(),
  6815. this.scene.postRender.adjustProjectionForSupersampling(this.scene.view),
  6816. this.scene.collectShadows(this.mainBuffer),
  6817. this.mainBuffer.bind(),
  6818. this.scene.draw(this.mainBuffer),
  6819. this.mainDepth && (this.mainBufferNoDepth.bind(),
  6820. this.scene.drawSecondary(this.mainDepth)),
  6821. this.scene.postRender.present(this.mainColor, this.canvas.width, this.canvas.height, this.stripData.active()))
  6822. }
  6823. ;
  6824. marmoset = "undefined" == typeof marmoset ? {} : marmoset;
  6825. marmoset.WebViewer = WebViewer;
  6826. marmoset.dataLocale = (0 == window.location.protocol.indexOf("https") ? "https:" : "http:") + "//viewer.marmoset.co/main/data/";
  6827. var ShaderTable = {
  6828. "alphaprepassfrag.glsl": "precision mediump float;\n#include <matdither.glsl>\nuniform sampler2D tAlbedo;varying mediump vec2 d;void main(){float e=texture2D(tAlbedo,d).a;if(e<=f(d.x)){discard;}gl_FragColor=vec4(0.0);}",
  6829. "alphaprepassvert.glsl": "precision highp float;uniform mat4 uModelViewProjectionMatrix;uniform vec2 uUVOffset;attribute vec3 vPosition;attribute vec2 vTexCoord;varying mediump vec2 d;vec4 h(mat4 i,vec3 p){return i[0]*p.x+(i[1]*p.y+(i[2]*p.z+i[3]));}void main(void){gl_Position=h(uModelViewProjectionMatrix,vPosition.xyz);d=vTexCoord+uUVOffset;}",
  6830. "bloom.glsl": "precision mediump float;uniform sampler2D tInput;uniform vec4 uKernel[BLOOM_SAMPLES];varying highp vec2 j;void main(void){vec3 c=vec3(0.0,0.0,0.0);for(int k=0;k<BLOOM_SAMPLES;++k){vec3 l=uKernel[k].xyz;vec3 m=texture2D(tInput,j+l.xy).xyz;m=max(m,vec3(0.0,0.0,0.0));c+=m*l.z;}gl_FragColor.xyz=c;gl_FragColor.w=0.0;}",
  6831. "bloomshrink.glsl": "precision highp float;uniform sampler2D tInput;varying highp vec2 j;void main(void){float o=0.25/256.0;gl_FragColor=0.25*(texture2D(tInput,j+vec2(o,o))+texture2D(tInput,j+vec2(o,-o))+texture2D(tInput,j+vec2(-o,o))+texture2D(tInput,j+vec2(-o,-o)));}",
  6832. "fogfrag.glsl": "precision highp float;uniform sampler2D tDepth;uniform vec3 uDepthToZ;uniform vec4 uUnproject;uniform mat4 uInvViewMatrix;uniform float uFogInvDistance;uniform float uFogOpacity;uniform float uFogDispersion;uniform vec3 uFogType;uniform vec3 uFogColor;uniform float uFogIllum;uniform mat4 uLightMatrix;\n#ifdef FOG_IBL\nuniform vec4 uFogLightSphere[9];\n#else\nuniform vec4 uSpotParams;uniform vec4 uLightPosition;uniform vec3 uLightColor;uniform vec4 uLightAttenuation;\n#ifdef FOG_SHADOWS\nuniform mat4 uShadowProj;uniform sampler2D uShadowMap;uniform float uDitherOffset;uniform vec4 uCylinder;\n#endif\n#endif\nvec4 h(mat4 i,vec3 p){return i[0]*p.x+(i[1]*p.y+(i[2]*p.z+i[3]));}vec3 u(mat4 i,vec3 v){return i[0].xyz*v.x+i[1].xyz*v.y+i[2].xyz*v.z;}float A(float B){B*=uFogInvDistance;float C=uFogType.x*min(B,1.0)+(uFogType.y-uFogType.y/(1.0+16.0*B*B))+(uFogType.z-uFogType.z*exp(-3.0*B));return C*uFogOpacity;}\n#ifdef FOG_SHADOWS\nfloat D(vec3 E){vec4 p=h(uShadowProj,E);vec3 F=p.xyz/p.w;vec4 G=texture2D(uShadowMap,F.xy);float H=(G.x+G.y*(1.0/255.0))+G.z*(1.0/65025.0);return F.z<H || H>=1.0?1.0:0.0;}float f(vec2 I){return fract(sin(dot(I,vec2(12.9898,78.233)))*43758.5453+uDitherOffset);}void J(vec3 K,vec3 L,out float M,out float N){vec3 v=uSpotParams.xyz,p=uCylinder.xyz;vec3 O=L-dot(L,v)*v;vec3 P=(K-p)-dot(K-p,v)*v;float a=dot(O,O);float b=2.0*dot(O,P);float c=dot(P,P)-uCylinder.w;float Q=b*b-4.0*a*c;if(Q>=0.0){Q=sqrt(Q);M=(-b-Q)/(2.0*a);N=(-b+Q)/(2.0*a);}else {M=N=0.0;}}\n#endif\nvarying vec2 j;void main(void){vec3 R=uInvViewMatrix[3].xyz;float H=texture2D(tDepth,j).x;H=min(H,0.9999);vec3 S;S.z=uDepthToZ.y/(uDepthToZ.z*H+uDepthToZ.x);S.xy=S.z*(j*uUnproject.xy+uUnproject.zw);S=h(uInvViewMatrix,S).xyz;vec3 T;T.xy=(j*uUnproject.xy+uUnproject.zw);T.z=1.0;T=normalize(u(uInvViewMatrix,-T).xyz);vec3 U=uFogColor;\n#if defined(FOG_IBL)\nvec3 G=u(uLightMatrix,T);vec3 V=uFogLightSphere[0].xyz;V+=uFogLightSphere[1].xyz*G.y;V+=uFogLightSphere[2].xyz*G.z;V+=uFogLightSphere[3].xyz*G.x;vec3 swz=G.yyz*G.xzx;V+=uFogLightSphere[4].xyz*swz.x;V+=uFogLightSphere[5].xyz*swz.y;V+=uFogLightSphere[7].xyz*swz.z;vec3 sqr=G*G;V+=uFogLightSphere[6].xyz*(3.0*sqr.z-1.0);V+=uFogLightSphere[8].xyz*(sqr.x-sqr.y);U=mix(U,U*V,uFogIllum);float C=A(length(S-R));gl_FragColor.xyz=U*C;gl_FragColor.w=C;return;\n#else\n#if defined(FOG_SPOT) || defined(FOG_OMNI)\nfloat W=0.0,X=0.0;{float r=1.0/(uLightAttenuation.z);float a=1.0;float b=2.0*dot(T,R-uLightPosition.xyz);float c=dot(uLightPosition.xyz,uLightPosition.xyz)+dot(R,R)+-2.0*dot(uLightPosition.xyz,R)+-r*r;float Q=b*b-4.0*a*c;if(Q>=0.0){Q=sqrt(Q);W=(-b-Q)/(2.0*a);X=(-b+Q)/(2.0*a);}}\n#if defined(FOG_SPOT)\n{float Y=uSpotParams.w,Z=1.0-Y;vec3 v=T;vec3 dc=uSpotParams.xyz;vec3 dd=R-uLightPosition.xyz;vec3 de=v-dot(v,dc)*dc,df=dd-dot(dd,dc)*dc;float a=Y*dot(de,de)-Z*dot(v,dc)*dot(v,dc);float b=2.0*Y*dot(de,df)-2.0*Z*dot(v,dc)*dot(dd,dc);float c=Y*dot(df,df)-Z*dot(dd,dc)*dot(dd,dc);float Q=b*b-4.0*a*c;if(Q>=0.0){float dh=(-b-sqrt(Q))/(2.0*a);float di=(-b+sqrt(Q))/(2.0*a);if(di<dh){float de=dh;dh=di;di=de;}bool dj=dot(-uLightPosition.xyz+R+T*dh,uSpotParams.xyz)<=0.0;bool dk=dot(-uLightPosition.xyz+R+T*di,uSpotParams.xyz)<=0.0;if(!dj ||!dk){if(dj){dh=di;di=X;}else if(dk){di=dh;dh=W;}W=max(W,dh);X=min(X,di);}else {X=W=0.0;}}else {X=W=0.0;}}\n#endif\nfloat tx=dot(T,S-R);W=clamp(W,0.0,tx);X=clamp(X,0.0,tx);float dl=0.0;if(X>W){\n#ifdef FOG_SHADOWS\n#ifdef MOBILE\n#define SAMPLES 16\n#else\n#define SAMPLES 32\n#endif\nfloat dm=f(j)*(X-W)/float(SAMPLES-2);\n#else\n#define SAMPLES 8\nfloat dm=0.0;\n#endif\nfor(int k=0;k<SAMPLES;++k){float t=W+(X-W)*float(k)/float(SAMPLES-1);vec3 p=R+(t+dm)*T;float a=clamp(length(p-uLightPosition.xyz)*uLightAttenuation.z,0.0,1.0);a=1.0+uLightAttenuation.x*a+uLightAttenuation.y*a*a;\n#ifdef FOG_SHADOWS\na*=D(p);\n#endif\ndl+=a-a*A(t);}dl*=1.0/float(SAMPLES);dl*=(X-W)*uLightAttenuation.z;dl*=A(X-W);}U*=dl*uFogIllum;\n#elif defined(FOG_DIR)\nfloat C=A(dot(T,S-R));\n#ifdef FOG_SHADOWS\nfloat W,X;J(R,T,W,X);float tx=dot(T,S-R);W=clamp(W,0.0,tx);X=clamp(X,0.0,tx);if(X>W){\n#ifdef MOBILE\n#define SAMPLES 16\n#else\n#define SAMPLES 32\n#endif\nfloat dl=0.0;float dm=f(j)*(X-W)/float(SAMPLES-2);float dn=(X-W)*(1.0/float(SAMPLES));for(int k=0;k<SAMPLES;++k){float t=W+float(k)*dn+dm;vec3 p=R+t*T;float s=D(p);C-=(1.0-s)*(A(t+dn)-A(t));}}\n#endif\nfloat du=0.5+0.5*dot(T,-uSpotParams.xyz);du=1.0+uFogDispersion*(2.0*du*du-1.0);U*=(0.1*C)*(du*uFogIllum);\n#endif\ngl_FragColor.xyz=U*uLightColor;gl_FragColor.w=0.0;\n#endif\n}",
  6833. "fogvert.glsl": "precision highp float;attribute vec2 vCoord;varying vec2 j;void main(void){j=vCoord;gl_Position.xy=2.0*vCoord-vec2(1.0,1.0);gl_Position.zw=vec2(0.0,1.0);}",
  6834. "matdither.glsl": "float f(highp float I){highp float G=0.5*fract(gl_FragCoord.x*0.5)+0.5*fract(gl_FragCoord.y*0.5);return 0.4+0.6*fract(G+3.141592e6*I);}",
  6835. "matfrag.glsl": "\n#extension GL_OES_standard_derivatives : enable\nprecision mediump float;varying highp vec3 dv;varying mediump vec2 d;varying mediump vec3 dA;varying mediump vec3 dB;varying mediump vec3 dC;\n#ifdef VERTEX_COLOR\nvarying lowp vec4 dD;\n#endif\n#ifdef TEXCOORD_SECONDARY\nvarying mediump vec2 dE;\n#endif\nuniform sampler2D tAlbedo;uniform sampler2D tReflectivity;uniform sampler2D tNormal;uniform sampler2D tExtras;uniform sampler2D tSkySpecular;\n#ifdef REFRACTION\nuniform sampler2D tRefraction;\n#endif\nuniform vec4 uDiffuseCoefficients[9];uniform vec3 uCameraPosition;uniform float uAlphaTest;uniform vec3 uFresnel;uniform float uHorizonOcclude;uniform float uHorizonSmoothing;\n#ifdef EMISSIVE\nuniform float uEmissiveScale;uniform vec4 uTexRangeEmissive;\n#endif\n#ifdef AMBIENT_OCCLUSION\nuniform vec4 uTexRangeAO;\n#endif\n#ifdef REFRACTION\nuniform float uRefractionIOREntry;uniform float uRefractionRayDistance;uniform vec3 uRefractionTint;uniform float uRefractionAlbedoTint;uniform mat4 uRefractionViewProjection;uniform vec4 uTexRangeRefraction;\n#endif\n#ifdef LIGHT_COUNT\nuniform vec4 uLightPositions[LIGHT_COUNT];uniform vec3 uLightDirections[LIGHT_COUNT];uniform vec3 uLightColors[LIGHT_COUNT];uniform vec3 uLightParams[LIGHT_COUNT];uniform vec3 uLightSpot[LIGHT_COUNT];\n#endif\n#ifdef ANISO\nuniform float uAnisoStrength;uniform vec3 uAnisoTangent;uniform float uAnisoIntegral;uniform vec4 uTexRangeAniso;\n#endif\n#define saturate(x) clamp( x, 0.0, 1.0 )\n#include <matsampling.glsl>\n#include <matlighting.glsl>\n#include <matshadows.glsl>\n#include <matskin.glsl>\n#include <matmicrofiber.glsl>\n#include <matstrips.glsl>\n#ifdef TRANSPARENCY_DITHER\n#include <matdither.glsl>\n#endif\nvoid main(void){vec4 m=texture2D(tAlbedo,d);vec3 dF=dG(m.xyz);float e=m.w;\n#ifdef VERTEX_COLOR\n{vec3 dH=dD.xyz;\n#ifdef VERTEX_COLOR_SRGB\ndH=dH*(dH*(dH*0.305306011+vec3(0.682171111))+vec3(0.012522878));\n#endif\ndF*=dH;\n#ifdef VERTEX_COLOR_ALPHA\ne*=dD.w;\n#endif\n}\n#endif\n#ifdef ALPHA_TEST\nif(e<uAlphaTest){discard;}\n#endif\n#ifdef TRANSPARENCY_DITHER\ne=(e>f(d.x))?1.0:e;\n#endif\nvec3 dI=dJ(texture2D(tNormal,d).xyz);\n#ifdef ANISO\n#ifdef ANISO_NO_DIR_TEX\nvec3 dK=dL(uAnisoTangent);\n#else\nm=dM(d,uTexRangeAniso);vec3 dK=2.0*m.xyz-vec3(1.0);dK=dL(dK);\n#endif\ndK=dK-dI*dot(dK,dI);dK=normalize(dK);vec3 dN=dK*uAnisoStrength;\n#endif\nvec3 dO=normalize(uCameraPosition-dv);m=texture2D(tReflectivity,d);vec3 dP=dG(m.xyz);float dQ=m.w;float dR=dQ;\n#ifdef HORIZON_SMOOTHING\nfloat dS=dot(dO,dI);dS=uHorizonSmoothing-dS*uHorizonSmoothing;dQ=mix(dQ,1.0,dS*dS);\n#endif\n#ifdef STRIPVIEW\ndT dU;dV(dU,dQ,dP);\n#endif\nfloat dW=1.0;\n#ifdef AMBIENT_OCCLUSION\n#ifdef AMBIENT_OCCLUSION_SECONDARY_UV\ndW=dM(dE,uTexRangeAO).x;\n#else\ndW=dM(d,uTexRangeAO).x;\n#endif\ndW*=dW;\n#endif\n#if defined(SKIN)\ndX dY;dZ(dY);dY.ec*=dW;\n#elif defined(MICROFIBER)\ned ee;ef(ee,dI);ee.eh*=dW;\n#else\nvec3 ei=ej(dI);ei*=dW;\n#endif\nvec3 ek=reflect(-dO,dI);\n#ifdef ANISO\nvec3 rt=ek-(0.5*dN*dot(ek,dK));vec3 el=em(rt,mix(dQ,0.5*dQ,uAnisoStrength));\n#else\nvec3 el=em(ek,dQ);\n#endif\nel*=en(ek,dC);\n#ifdef LIGHT_COUNT\nhighp float eo=10.0/log2(dQ*0.968+0.03);eo*=eo;float eu=eo*(1.0/(8.0*3.1415926))+(4.0/(8.0*3.1415926));eu=min(eu,1.0e3);\n#ifdef SHADOW_COUNT\nev eA;\n#ifdef SKIN\n#ifdef SKIN_VERSION_1\neB(eA,SHADOW_KERNEL+SHADOW_KERNEL*dY.eC);\n#else\neD eE;float eF=SHADOW_KERNEL+SHADOW_KERNEL*dY.eC;eG(eE,eF);eB(eA,eF);\n#endif\n#else\neB(eA,SHADOW_KERNEL);\n#endif\n#endif\n#ifdef ANISO\neu*=uAnisoIntegral;\n#endif\nfor(int k=0;k<LIGHT_COUNT;++k){vec3 eH=uLightPositions[k].xyz-dv*uLightPositions[k].w;float eI=inversesqrt(dot(eH,eH));eH*=eI;float a=saturate(uLightParams[k].z/eI);a=1.0+a*(uLightParams[k].x+uLightParams[k].y*a);float s=saturate(dot(eH,uLightDirections[k]));s=saturate(uLightSpot[k].y-uLightSpot[k].z*(1.0-s*s));vec3 eJ=(a*s)*uLightColors[k].xyz;\n#if defined(SKIN)\n#ifdef SHADOW_COUNT\n#ifdef SKIN_VERSION_1\neK(dY,eA.eL[k],1.0,eH,dI,eJ);\n#else\neK(dY,eA.eL[k],eE.eE[k],eH,dI,eJ);\n#endif\n#else\neK(dY,1.0,0.0,eH,dI,eJ);\n#endif\n#elif defined(MICROFIBER)\n#ifdef SHADOW_COUNT\neM(ee,eA.eL[k],eH,dI,eJ);\n#else\neM(ee,1.0,eH,dI,eJ);\n#endif\n#else\nfloat eN=saturate((1.0/3.1415926)*dot(eH,dI));\n#ifdef SHADOW_COUNT\neN*=eA.eL[k];\n#endif\nei+=eN*eJ;\n#endif\nvec3 eO=eH+dO;\n#ifdef ANISO\neO=eO-(dN*dot(eO,dK));\n#endif\neO=normalize(eO);float eP=eu*pow(saturate(dot(eO,dI)),eo);\n#ifdef SHADOW_COUNT\neP*=eA.eL[k];\n#endif\nel+=eP*eJ;}\n#endif\n#if defined(SKIN)\nvec3 ei,diff_extra;eQ(ei,diff_extra,dY,dO,dI,dQ);\n#elif defined(MICROFIBER)\nvec3 ei,diff_extra;eR(ei,diff_extra,ee,dO,dI,dQ);\n#endif\nvec3 eS=eT(dO,dI,dP,dQ*dQ);el*=eS;\n#ifdef REFRACTION\nvec4 eU;{vec3 G=refract(-dO,dI,uRefractionIOREntry);G=dv+G*uRefractionRayDistance;vec4 eV=uRefractionViewProjection[0]*G.x+(uRefractionViewProjection[1]*G.y+(uRefractionViewProjection[2]*G.z+uRefractionViewProjection[3]));vec2 c=eV.xy/eV.w;c=0.5*c+vec2(0.5,0.5);vec2 i=mod(floor(c),2.0);c=fract(c);c.x=i.x>0.0?1.0-c.x:c.x;c.y=i.y>0.0?1.0-c.y:c.y;eU.rgb=texture2D(tRefraction,c).xyz;eU.rgb=mix(eU.rgb,eU.rgb*dF,uRefractionAlbedoTint);eU.rgb=eU.rgb-eU.rgb*eS;eU.rgb*=uRefractionTint;\n#ifdef REFRACTION_NO_MASK_TEX\neU.a=1.0;\n#else\neU.a=dM(d,uTexRangeRefraction).x;\n#endif\n}\n#endif\n#ifdef DIFFUSE_UNLIT\ngl_FragColor.xyz=dF;\n#else\ngl_FragColor.xyz=ei*dF;\n#endif\n#ifdef REFRACTION\ngl_FragColor.xyz=mix(gl_FragColor.xyz,eU.rgb,eU.a);\n#endif\ngl_FragColor.xyz+=el;\n#if defined(SKIN) || defined(MICROFIBER)\ngl_FragColor.xyz+=diff_extra;\n#endif\n#ifdef EMISSIVE\n#ifdef EMISSIVE_SECONDARY_UV\nvec2 eW=dE;\n#else\nvec2 eW=d;\n#endif\ngl_FragColor.xyz+=uEmissiveScale*dG(dM(eW,uTexRangeEmissive).xyz);\n#endif\n#ifdef STRIPVIEW\ngl_FragColor.xyz=eX(dU,dI,dF,dP,dR,ei,el,gl_FragColor.xyz);\n#endif\n#ifdef NOBLEND\ngl_FragColor.w=1.0;\n#else\ngl_FragColor.w=e;\n#endif\n}",
  6836. "matlighting.glsl": "vec3 eY(vec3 eZ,float fc){return exp(-0.5*fc/(eZ*eZ))/(eZ*2.5066283);}vec3 fd(vec3 eZ){return vec3(1.0,1.0,1.0)/(eZ*2.5066283);}vec3 fe(vec3 ff){return vec3(-0.5,-0.5,-0.5)/(ff);}vec3 fh(vec3 fi,float fc){return exp(fi*fc);}\n#define SAMPLE_COUNT 21.0\n#define SAMPLE_HALF 10.0\n#define GAUSS_SPREAD 0.05\nvec3 fj(float fk,float fl,vec3 fm){vec3 fn=vec3(fl,fl,fl);fn=0.8*fn+vec3(0.2);vec3 fo=cos(fn*3.14159);vec3 fu=cos(fn*3.14159*0.5);fu*=fu;fu*=fu;fu*=fu;fn=fn+0.05*fo*fu*fm;fu*=fu;fu*=fu;fu*=fu;fn=fn+0.1*fo*fu*fm;fn=saturate(fn);fn*=fn*1.2;return fn;}vec3 fv(vec3 fm){return vec3(1.0,1.0,1.0)/3.1415926;}float fA(float fk,float fm){return saturate(-fk*fm+fk+fm);}vec3 fB(float fk,vec3 fm){return saturate(-fk*fm+vec3(fk)+fm);}float fC(float fm){return-0.31830988618379*fm+0.31830988618379;}vec3 fD(vec3 fm){return-0.31830988618379*fm+vec3(0.31830988618379);}vec3 eT(vec3 dO,vec3 dI,vec3 dP,float fE){float C=1.0-saturate(dot(dO,dI));float fF=C*C;C*=fF*fF;C*=fE;return(dP-C*dP)+C*uFresnel;}vec2 fG(vec2 fH,vec2 fm){fH=1.0-fH;vec2 fI=fH*fH;fI*=fI;fH=mix(fI,fH*0.4,fm);return fH;}vec3 ej(vec3 fJ){\n#define c(n) uDiffuseCoefficients[n].xyz\nvec3 G=(c(0)+fJ.y*((c(1)+c(4)*fJ.x)+c(5)*fJ.z))+fJ.x*(c(3)+c(7)*fJ.z)+c(2)*fJ.z;\n#undef c\nvec3 sqr=fJ*fJ;G+=uDiffuseCoefficients[6].xyz*(3.0*sqr.z-1.0);G+=uDiffuseCoefficients[8].xyz*(sqr.x-sqr.y);return G;}void fK(inout vec3 fL,inout vec3 fM,inout vec3 fN,vec3 fJ){fL=uDiffuseCoefficients[0].xyz;fM=uDiffuseCoefficients[1].xyz*fJ.y;fM+=uDiffuseCoefficients[2].xyz*fJ.z;fM+=uDiffuseCoefficients[3].xyz*fJ.x;vec3 swz=fJ.yyz*fJ.xzx;fN=uDiffuseCoefficients[4].xyz*swz.x;fN+=uDiffuseCoefficients[5].xyz*swz.y;fN+=uDiffuseCoefficients[7].xyz*swz.z;vec3 sqr=fJ*fJ;fN+=uDiffuseCoefficients[6].xyz*(3.0*sqr.z-1.0);fN+=uDiffuseCoefficients[8].xyz*(sqr.x-sqr.y);}vec3 fO(vec3 fL,vec3 fM,vec3 fN,vec3 fP,float fm){fP=mix(vec3(1.0),fP,fm);return(fL+fM*fP.x)+fN*fP.z;}vec3 fQ(vec3 fL,vec3 fM,vec3 fN,vec3 fP,vec3 fR){vec3 fS=mix(vec3(1.0),fP.yyy,fR);vec3 fT=mix(vec3(1.0),fP.zzz,fR);return(fL+fM*fS)+fN*fT;}vec3 em(vec3 fJ,float dQ){fJ/=dot(vec3(1.0),abs(fJ));vec2 fU=abs(fJ.zx)-vec2(1.0,1.0);vec2 fV=vec2(fJ.x<0.0?fU.x:-fU.x,fJ.z<0.0?fU.y:-fU.y);vec2 fW=(fJ.y<0.0)?fV:fJ.xz;fW=vec2(0.5*(254.0/256.0),0.125*0.5*(254.0/256.0))*fW+vec2(0.5,0.125*0.5);float fX=fract(7.0*dQ);fW.y+=0.125*(7.0*dQ-fX);vec2 fY=fW+vec2(0.0,0.125);vec4 fZ=mix(texture2D(tSkySpecular,fW),texture2D(tSkySpecular,fY),fX);vec3 r=fZ.xyz*(7.0*fZ.w);return r*r;}float en(vec3 fJ,vec3 hc){float hd=dot(fJ,hc);hd=saturate(1.0+uHorizonOcclude*hd);return hd*hd;}",
  6837. "matmicrofiber.glsl": "\n#ifdef MICROFIBER\nuniform vec4 uTexRangeFuzz;uniform vec4 uFresnelColor;uniform float uFresnelIntegral;uniform float uFresnelOcc;uniform float uFresnelGlossMask;struct ed{vec3 eh;vec3 eN;vec3 he;vec3 hf;vec3 hh;};void ef(out ed s,vec3 dI){s.eh=s.eN=ej(dI);s.he=vec3(0.0);s.hf=uFresnelColor.rgb;s.hh=uFresnelColor.aaa*vec3(1.0,0.5,0.25);\n#ifndef MICROFIBER_NO_FUZZ_TEX\nvec4 m=dM(d,uTexRangeFuzz);s.hf*=dG(m.rgb);\n#endif\n}void eM(inout ed s,float hi,vec3 eH,vec3 dI,vec3 eJ){float fk=dot(eH,dI);float eN=saturate((1.0/3.1415926)*fk);float hj=fA(fk,s.hh.z);\n#ifdef SHADOW_COUNT\neN*=hi;float hk=mix(1.0,hi,uFresnelOcc);float he=hj*hk;\n#else \nfloat he=hj;\n#endif\ns.he=he*eJ+s.he;s.eN=eN*eJ+s.eN;}void eR(out vec3 ei,out vec3 diff_extra,inout ed s,vec3 dO,vec3 dI,float dQ){s.he*=uFresnelIntegral;float fH=dot(dO,dI);vec2 hl=fG(vec2(fH,fH),s.hh.xy);s.he=s.eh*hl.x+(s.he*hl.y);s.he*=s.hf;float hm=saturate(1.0+-uFresnelGlossMask*dQ);s.he*=hm*hm;ei=s.eN;diff_extra=s.he;}\n#endif\n",
  6838. "matsampling.glsl": "vec3 dG(vec3 c){return c*c;}vec3 dJ(vec3 n){vec3 hn=dA;vec3 ho=dB;vec3 hu=gl_FrontFacing?dC:-dC;\n#ifdef TSPACE_RENORMALIZE\nhu=normalize(hu);\n#endif\n#ifdef TSPACE_ORTHOGONALIZE\nhn-=dot(hn,hu)*hu;\n#endif\n#ifdef TSPACE_RENORMALIZE\nhn=normalize(hn);\n#endif\n#ifdef TSPACE_ORTHOGONALIZE\nho=(ho-dot(ho,hu)*hu)-dot(ho,hn)*hn;\n#endif\n#ifdef TSPACE_RENORMALIZE\nho=normalize(ho);\n#endif\n#ifdef TSPACE_COMPUTE_BITANGENT\nvec3 hv=cross(hu,hn);ho=dot(hv,ho)<0.0?-hv:hv;\n#endif\nn=2.0*n-vec3(1.0);return normalize(hn*n.x+ho*n.y+hu*n.z);}vec3 dL(vec3 t){vec3 hu=gl_FrontFacing?dC:-dC;return normalize(dA*t.x+dB*t.y+hu*t.z);}vec4 dM(vec2 hA,vec4 hB){\n#if GL_OES_standard_derivatives\nvec2 hC=fract(hA);vec2 hD=fwidth(hC);float hE=(hD.x+hD.y)>0.5?-6.0:0.0;return texture2D(tExtras,hC*hB.xy+hB.zw,hE);\n#else\nreturn texture2D(tExtras,fract(hA)*hB.xy+hB.zw);\n#endif\n}vec3 hF(sampler2D hG,vec2 hH,float hI){vec3 n=texture2D(hG,hH,hI*2.5).xyz;return dJ(n);}",
  6839. "matshadows.glsl": "\n#ifdef SHADOW_COUNT\n#ifdef MOBILE\n#define SHADOW_KERNEL (4.0/1536.0)\n#else\n#define SHADOW_KERNEL (4.0/2048.0)\n#endif\nhighp vec4 h(highp mat4 i,highp vec3 p){return i[0]*p.x+(i[1]*p.y+(i[2]*p.z+i[3]));}uniform sampler2D tDepth0;\n#if SHADOW_COUNT > 1\nuniform sampler2D tDepth1;\n#if SHADOW_COUNT > 2\nuniform sampler2D tDepth2;\n#endif\n#endif\nuniform highp vec2 uShadowKernelRotation;uniform highp vec2 uShadowMapSize;uniform highp mat4 uShadowMatrices[SHADOW_COUNT];uniform highp vec4 uShadowTexelPadProjections[SHADOW_COUNT];\n#ifndef MOBILE\nuniform highp mat4 uInvShadowMatrices[SHADOW_COUNT];\n#endif\nhighp float hJ(highp vec3 G){\n#ifdef SHADOW_NATIVE_DEPTH\nreturn G.x;\n#else\nreturn(G.x+G.y*(1.0/255.0))+G.z*(1.0/65025.0);\n#endif\n}\n#ifndef SHADOW_COMPARE\n#define SHADOW_COMPARE(a,b) ((a) < (b) ? 1.0 : 0.0)\n#endif\n#ifndef SHADOW_CLIP\n#define SHADOW_CLIP(c,v) v\n#endif\nfloat hK(sampler2D hL,highp vec2 hA,highp float H){\n#ifndef MOBILE\nhighp vec2 c=hA*uShadowMapSize.x;highp vec2 a=floor(c)*uShadowMapSize.y,b=ceil(c)*uShadowMapSize.y;highp vec4 eE;eE.x=hJ(texture2D(hL,a).xyz);eE.y=hJ(texture2D(hL,vec2(b.x,a.y)).xyz);eE.z=hJ(texture2D(hL,vec2(a.x,b.y)).xyz);eE.w=hJ(texture2D(hL,b).xyz);highp vec4 hM;hM.x=SHADOW_COMPARE(H,eE.x);hM.y=SHADOW_COMPARE(H,eE.y);hM.z=SHADOW_COMPARE(H,eE.z);hM.w=SHADOW_COMPARE(H,eE.w);highp vec2 w=c-a*uShadowMapSize.x;vec2 s=(w.y*hM.zw+hM.xy)-w.y*hM.xy;return(w.x*s.y+s.x)-w.x*s.x;\n#else\nhighp float G=hJ(texture2D(hL,hA.xy).xyz);return SHADOW_COMPARE(H,G);\n#endif\n}highp float hN(sampler2D hL,highp vec3 hA,float hO){highp vec2 l=uShadowKernelRotation*hO;float s;s=hK(hL,hA.xy+l,hA.z);s+=hK(hL,hA.xy-l,hA.z);s+=hK(hL,hA.xy+vec2(-l.y,l.x),hA.z);s+=hK(hL,hA.xy+vec2(l.y,-l.x),hA.z);s*=0.25;return s*s;}struct ev{float eL[LIGHT_COUNT];};void eB(out ev ss,float hO){highp vec3 hP[SHADOW_COUNT];vec3 hu=gl_FrontFacing?dC:-dC;for(int k=0;k<SHADOW_COUNT;++k){vec4 hQ=uShadowTexelPadProjections[k];float hR=hQ.x*dv.x+(hQ.y*dv.y+(hQ.z*dv.z+hQ.w));\n#ifdef MOBILE\nhR*=.001+hO;\n#else\nhR*=.0005+0.5*hO;\n#endif\nhighp vec4 hS=h(uShadowMatrices[k],dv+hR*hu);hP[k]=hS.xyz/hS.w;}float m;\n#if SHADOW_COUNT > 0\nm=hN(tDepth0,hP[0],hO);ss.eL[0]=SHADOW_CLIP(hP[0].xy,m);\n#endif\n#if SHADOW_COUNT > 1\nm=hN(tDepth1,hP[1],hO);ss.eL[1]=SHADOW_CLIP(hP[1].xy,m);\n#endif\n#if SHADOW_COUNT > 2\nm=hN(tDepth2,hP[2],hO);ss.eL[2]=SHADOW_CLIP(hP[2].xy,m);\n#endif\nfor(int k=SHADOW_COUNT;k<LIGHT_COUNT;++k){ss.eL[k]=1.0;}}struct eD{highp float eE[LIGHT_COUNT];};\n#ifdef MOBILE\nvoid eG(out eD ss,float hO){for(int k=0;k<LIGHT_COUNT;++k){ss.eE[k]=1.0;}}\n#else\nhighp vec4 hT(sampler2D hL,highp vec2 hA,highp mat4 hU){highp vec4 E;E.xy=hA;\n#ifndef MOBILE\nhighp vec2 c=hA*uShadowMapSize.x;highp vec2 a=floor(c)*uShadowMapSize.y,b=ceil(c)*uShadowMapSize.y;highp vec4 hM;hM.x=hJ(texture2D(hL,a).xyz);hM.y=hJ(texture2D(hL,vec2(b.x,a.y)).xyz);hM.z=hJ(texture2D(hL,vec2(a.x,b.y)).xyz);hM.w=hJ(texture2D(hL,b).xyz);highp vec2 w=c-a*uShadowMapSize.x;vec2 s=(w.y*hM.zw+hM.xy)-w.y*hM.xy;E.z=(w.x*s.y+s.x)-w.x*s.x;\n#else \nE.z=hJ(texture2D(hL,hA.xy).xyz);\n#endif\nE=h(hU,E.xyz);E.xyz/=E.w;return E;}void eG(out eD ss,float hO){highp vec3 hV[SHADOW_COUNT];vec3 hu=gl_FrontFacing?dC:-dC;hu*=0.6;for(int k=0;k<SHADOW_COUNT;++k){vec4 hQ=uShadowTexelPadProjections[k];float hR=hQ.x*dv.x+(hQ.y*dv.y+(hQ.z*dv.z+hQ.w));\n#ifdef MOBILE\nhR*=.001+hO;\n#else\nhR*=.0005+0.5*hO;\n#endif\nhighp vec4 hS=h(uShadowMatrices[k],dv-hR*hu);hV[k]=hS.xyz/hS.w;}highp vec4 hW;\n#if SHADOW_COUNT > 0\nhW=hT(tDepth0,hV[0].xy,uInvShadowMatrices[0]);ss.eE[0]=length(dv.xyz-hW.xyz);\n#endif\n#if SHADOW_COUNT > 1\nhW=hT(tDepth1,hV[1].xy,uInvShadowMatrices[1]);ss.eE[1]=length(dv.xyz-hW.xyz);\n#endif\n#if SHADOW_COUNT > 2\nhW=hT(tDepth2,hV[2].xy,uInvShadowMatrices[2]);ss.eE[2]=length(dv.xyz-hW.xyz);\n#endif\nfor(int k=SHADOW_COUNT;k<LIGHT_COUNT;++k){ss.eE[k]=1.0;}}\n#endif\n#endif\n",
  6840. "matskin.glsl": "\n#ifdef SKIN\n#ifndef SKIN_NO_SUBDERMIS_TEX\nuniform vec4 uTexRangeSubdermis;\n#endif\n#ifndef SKIN_NO_TRANSLUCENCY_TEX\nuniform vec4 uTexRangeTranslucency;\n#endif\n#ifndef SKIN_NO_FUZZ_TEX\nuniform vec4 uTexRangeFuzz;\n#endif\nuniform vec4 uTransColor;uniform vec4 uFresnelColor;uniform vec3 uSubdermisColor;uniform float uTransScatter;uniform float uFresnelOcc;uniform float uFresnelGlossMask;uniform float uTransSky;uniform float uFresnelIntegral;uniform float uTransIntegral;uniform float uSkinTransDepth;uniform float uSkinShadowBlur;uniform float uNormalSmooth;struct dX{vec3 hX;vec3 hY,hZ,ic,he;vec3 ec,eh,id;vec3 ie;vec3 ih;vec3 ii;vec3 ij;float ik;float il;float im;float eC;};void dZ(out dX s){vec4 m;\n#ifdef SKIN_NO_SUBDERMIS_TEX\ns.hX=uSubdermisColor;s.im=1.0;\n#else \nm=dM(d,uTexRangeSubdermis);s.hX=dG(m.xyz);s.im=m.w*m.w;\n#endif\ns.ij=uTransColor.rgb;s.ik=uTransScatter;\n#ifdef SKIN_VERSION_1\ns.eC=uSkinShadowBlur*s.im;\n#else \ns.il=max(max(s.ij.r,s.ij.g),s.ij.b)*uTransColor.a;float io=max(s.hX.r,max(s.hX.g,s.hX.b));io=1.0-io;io*=io;io*=io;io*=io;io=1.0-(io*io);s.im*=io;s.eC=uSkinShadowBlur*s.im*dot(s.hX.rgb,vec3(0.333,0.334,0.333));\n#endif\n#ifndef SKIN_NO_TRANSLUCENCY_TEX\nm=dM(d,uTexRangeTranslucency);s.ij*=dG(m.xyz);\n#endif\ns.ie=hF(tNormal,d,uNormalSmooth*s.im);vec3 iu,iv,iA;fK(iu,iv,iA,s.ie);s.eh=s.hY=iu+iv+iA;\n#ifdef SKIN_VERSION_1 \ns.ec=fQ(iu,iv,iA,vec3(1.0,0.6667,0.25),s.hX);\n#else\ns.ec=fQ(iu,iv,iA,vec3(1.0,0.6667,0.25),s.hX*0.2+vec3(0.1));\n#endif\n#ifdef SKIN_VERSION_1\nvec3 iB,iC,iD;fK(iB,iC,iD,-s.ie);s.id=fO(iB,iC,iD,vec3(1.0,0.4444,0.0625),s.ik);s.id*=uTransSky;\n#else \ns.id=vec3(0.0);\n#endif\ns.hZ=s.ic=s.he=vec3(0.0);s.hX*=0.5;s.ik*=0.5;s.ih=uFresnelColor.rgb;s.ii=uFresnelColor.aaa*vec3(1.0,0.5,0.25);\n#ifndef SKIN_NO_FUZZ_TEX\nm=dM(d,uTexRangeFuzz);s.ih*=dG(m.rgb);\n#endif\n}void eK(inout dX s,float iE,float iF,vec3 eH,vec3 dI,vec3 eJ){float fk=dot(eH,dI);float fl=dot(eH,s.ie);float eN=saturate((1.0/3.1415926)*fk);float hi=iE*iE;hi*=hi;hi=saturate(6.0*hi);\n#ifdef SKIN_VERSION_1 \nvec3 iG=fB(fl,s.hX);\n#else \nvec3 iG=fj(fk,fl,s.hX);\n#endif\nfloat iH=fA(-fl,s.ik);vec3 ic=vec3(iH*iH);\n#ifdef SKIN_VERSION_1\n#ifdef SHADOW_COUNT\nvec3 iI=vec3(iE);float iJ=saturate(hi-2.0*(iE*iE));iI+=iJ*s.hX;float iK=iE;\n#endif\n#else\n#ifdef SHADOW_COUNT\nvec3 iI;highp vec3 iL=(0.995*s.hX)+vec3(0.005,0.005,0.005);highp vec3 iM=vec3(1.0)-iL;iL=mix(iL,iM,iE);float iN=sqrt(iE);vec3 iO=2.0*vec3(1.0-iN);iN=1.0-iN;iN=(1.0-iN*iN);iI=saturate(pow(iL*iN,iO));highp float iP=0.35/(uSkinTransDepth+0.001);highp float iQ=saturate(iF*iP);iQ=saturate(1.0-iQ);iQ*=iQ;highp vec3 iR=vec3((-3.0*iQ)+3.15);highp vec3 iS=(0.9975*s.ij)+vec3(0.0025,0.0025,0.0025);highp float io=saturate(10.0*dot(iS,iS));vec3 iK=pow(iS*iQ,iR)*io;\n#else \nic=vec3(0.0);\n#endif\n#endif\nfloat hj=fA(fl,s.ii.z);\n#ifdef SHADOW_COUNT\nvec3 hk=mix(vec3(1.0),iI,uFresnelOcc);vec3 he=hj*hk;\n#else\nvec3 he=vec3(hj);\n#endif\n#ifdef SHADOW_COUNT\niG*=iI;eN*=hi;ic*=iK;\n#endif\ns.he=he*eJ+s.he;s.ic=ic*eJ+s.ic;s.hZ=iG*eJ+s.hZ;s.hY=eN*eJ+s.hY;}void eQ(out vec3 ei,out vec3 diff_extra,inout dX s,vec3 dO,vec3 dI,float dQ){s.he*=uFresnelIntegral;float fH=dot(dO,dI);vec2 hl=fG(vec2(fH,fH),s.ii.xy);s.he=s.eh*hl.x+(s.he*hl.y);s.he*=s.ih;float hm=saturate(1.0+-uFresnelGlossMask*dQ);s.he*=hm*hm;s.ic=s.ic*uTransIntegral;\n#ifdef SKIN_VERSION_1\ns.hZ=(s.hZ*fD(s.hX))+s.ec;\n#else\ns.hZ=(s.hZ*fv(s.hX))+s.ec;\n#endif\nei=mix(s.hY,s.hZ,s.im);\n#ifdef SKIN_VERSION_1\ns.ic=(s.ic+s.id)*s.ij;diff_extra=(s.he+s.ic)*s.im;\n#else\nei+=s.ic*s.il;diff_extra=s.he*s.im;\n#endif\n}\n#endif\n",
  6841. "matstrips.glsl": "\n#ifdef STRIPVIEW\nuniform float uStrips[5];uniform vec2 uStripRes;struct dT{float io[5];float bg;};void dV(out dT iT,inout float dQ,inout vec3 dP){highp vec2 hA=gl_FragCoord.xy*uStripRes-vec2(1.0,1.0);hA.x+=0.25*hA.y;iT.io[0]=step(hA.x,uStrips[0]);iT.io[1]=step(hA.x,uStrips[1]);iT.io[2]=step(hA.x,uStrips[2]);iT.io[3]=step(hA.x,uStrips[3]);iT.io[4]=step(hA.x,uStrips[4]);iT.bg=1.0-iT.io[4];iT.io[4]-=iT.io[3];iT.io[3]-=iT.io[2];iT.io[2]-=iT.io[1];iT.io[1]-=iT.io[0];bool iU=iT.io[4]>0.0;dQ=iU?0.5:dQ;dP=iU?vec3(0.1):dP;}vec3 eX(dT iT,vec3 dI,vec3 dF,vec3 dP,float dQ,vec3 ei,vec3 el,vec3 iV){return iT.io[0]*(dI*0.5+vec3(0.5))+iT.io[1]*dF+iT.io[2]*dP+vec3(iT.io[3]*dQ)+iT.io[4]*(vec3(0.12)+0.3*ei+el)+iT.bg*iV;}\n#endif\n",
  6842. "matvert.glsl": "precision highp float;uniform mat4 uModelViewProjectionMatrix;uniform mat4 uSkyMatrix;uniform vec2 uUVOffset;attribute vec3 vPosition;attribute vec2 vTexCoord;attribute vec2 vTangent;attribute vec2 vBitangent;attribute vec2 vNormal;\n#ifdef VERTEX_COLOR\nattribute vec4 vColor;\n#endif\n#ifdef TEXCOORD_SECONDARY\nattribute vec2 vTexCoord2;\n#endif\nvarying highp vec3 dv;varying mediump vec2 d;varying mediump vec3 dA;varying mediump vec3 dB;varying mediump vec3 dC;\n#ifdef VERTEX_COLOR\nvarying lowp vec4 dD;\n#endif\n#ifdef TEXCOORD_SECONDARY\nvarying mediump vec2 dE;\n#endif\nvec3 iW(vec2 v){bool iX=(v.y>(32767.1/65535.0));v.y=iX?(v.y-(32768.0/65535.0)):v.y;vec3 r;r.xy=(2.0*65535.0/32767.0)*v-vec2(1.0);r.z=sqrt(clamp(1.0-dot(r.xy,r.xy),0.0,1.0));r.z=iX?-r.z:r.z;return r;}vec4 h(mat4 i,vec3 p){return i[0]*p.x+(i[1]*p.y+(i[2]*p.z+i[3]));}vec3 u(mat4 i,vec3 v){return i[0].xyz*v.x+i[1].xyz*v.y+i[2].xyz*v.z;}void main(void){gl_Position=h(uModelViewProjectionMatrix,vPosition.xyz);d=vTexCoord+uUVOffset;dA=u(uSkyMatrix,iW(vTangent));dB=u(uSkyMatrix,iW(vBitangent));dC=u(uSkyMatrix,iW(vNormal));dv=h(uSkyMatrix,vPosition.xyz).xyz;\n#ifdef VERTEX_COLOR\ndD=vColor;\n#endif\n#ifdef TEXCOORD_SECONDARY\ndE=vTexCoord2;\n#endif\n}",
  6843. "postaa.glsl": "precision mediump float;uniform sampler2D tInput;varying vec2 j;void main(void){gl_FragColor=texture2D(tInput,j);}",
  6844. "postfrag.glsl": "precision mediump float;uniform sampler2D tInput;\n#ifdef BLOOM\nuniform sampler2D tBloom;\n#endif\n#ifdef GRAIN\nuniform sampler2D tGrain;\n#endif\n#ifdef COLOR_LUT\nuniform sampler2D tLUT;\n#endif\nuniform vec3 uScale;uniform vec3 uBias;uniform vec3 uSaturation;uniform vec4 uSharpenKernel;uniform vec3 uSharpness;uniform vec3 uBloomColor;uniform vec4 uVignetteAspect;uniform vec4 uVignette;uniform vec4 uGrainCoord;uniform vec2 uGrainScaleBias;varying vec2 j;vec3 iY(vec3 c){vec3 iZ=sqrt(c);return(iZ-iZ*c)+c*(0.4672*c+vec3(0.5328));}void main(void){vec4 jc=texture2D(tInput,j);vec3 c=jc.xyz;\n#ifdef SHARPEN\nvec3 hM=texture2D(tInput,j+uSharpenKernel.xy).xyz;hM+=texture2D(tInput,j-uSharpenKernel.xy).xyz;hM+=texture2D(tInput,j+uSharpenKernel.zw).xyz;hM+=texture2D(tInput,j-uSharpenKernel.zw).xyz;vec3 jd=uSharpness.x*c-uSharpness.y*hM;c+=clamp(jd,-uSharpness.z,uSharpness.z);\n#endif\n#ifdef BLOOM\nc+=uBloomColor*texture2D(tBloom,j).xyz;\n#endif\n#ifdef VIGNETTE\nvec2 je=j*uVignetteAspect.xy-uVignetteAspect.zw;vec3 v=clamp(vec3(1.0,1.0,1.0)-uVignette.xyz*dot(je,je),0.0,1.0);vec3 jf=v*v;jf*=v;c*=mix(v,jf,uVignette.w);\n#endif\n#ifdef SATURATION\nfloat gray=dot(c,vec3(0.3,0.59,0.11));c=mix(vec3(gray,gray,gray),c,uSaturation);\n#endif\n#ifdef CONTRAST\nc=c*uScale+uBias;\n#endif\n#ifdef GRAIN\nfloat jh=uGrainScaleBias.x*texture2D(tGrain,j*uGrainCoord.xy+uGrainCoord.zw).x+uGrainScaleBias.y;c+=c*jh;\n#endif\n#ifdef REINHARD\n{c*=1.8;float ji=dot(c,vec3(0.3333));c=clamp(c/(1.0+ji),0.0,1.0);}\n#elif defined(HEJL)\n{const highp float jj=0.22,jk=0.3,jl=.1,jm=0.2,jn=.01,jo=0.3;const highp float ju=1.25;highp vec3 eO=max(vec3(0.0),c-vec3(.004));c=(eO*((ju*jj)*eO+ju*vec3(jl*jk,jl*jk,jl*jk))+ju*vec3(jm*jn,jm*jn,jm*jn))/(eO*(jj*eO+vec3(jk,jk,jk))+vec3(jm*jo,jm*jo,jm*jo))-ju*vec3(jn/jo,jn/jo,jn/jo);}\n#elif defined(ACES)\n{vec3 a=c*(c+0.0245786)-0.000090537;vec3 b=c*(0.983729*c+0.4329510)+0.238081;c=a/b;}\n#endif\n#ifdef COLOR_LUT\nc=clamp(c,0.0,1.0);c=(255.0/256.0)*c+vec3(0.5/256.0);c.x=texture2D(tLUT,c.xx).x;c.y=texture2D(tLUT,c.yy).y;c.z=texture2D(tLUT,c.zz).z;c*=c;\n#endif\ngl_FragColor.xyz=iY(c);gl_FragColor.w=jc.w;}",
  6845. "postvert.glsl": "precision highp float;attribute vec2 vCoord;varying vec2 j;void main(void){j=vCoord;gl_Position.xy=2.0*vCoord-vec2(1.0,1.0);gl_Position.zw=vec2(0.0,1.0);}",
  6846. "shadowfloorfrag.glsl": "precision mediump float;varying highp vec3 dv;varying mediump vec2 jv;varying mediump vec3 dC;uniform vec3 uShadowCatcherParams;\n#ifdef LIGHT_COUNT\nuniform vec4 uLightPositions[LIGHT_COUNT];uniform vec3 uLightDirections[LIGHT_COUNT];uniform vec3 uLightColors[LIGHT_COUNT];uniform vec3 uLightParams[LIGHT_COUNT];uniform vec3 uLightSpot[LIGHT_COUNT];\n#endif\n#define saturate(x) clamp( x, 0.0, 1.0 )\n#define SHADOW_COMPARE(a,b) ((a) < (b) || (b) >= 1.0 ? 1.0 : 0.0)\n#define SHADOW_CLIP(c,v) ((c.x<0.0 || c.x>1.0 || c.y<0.0 || c.y>1.0) ? 1.0 : v)\n#include <matshadows.glsl>\nvoid main(void){ev eA;eB(eA,SHADOW_KERNEL);vec3 jA=vec3(0.0,0.0,0.0);vec3 jB=vec3(0.0,0.0,0.0);for(int k=0;k<SHADOW_COUNT;++k){vec3 eH=uLightPositions[k].xyz-dv*uLightPositions[k].w;float eI=inversesqrt(dot(eH,eH));eH*=eI;float a=saturate(uLightParams[k].z/eI);a=1.0+a*(uLightParams[k].x+uLightParams[k].y*a);float s=saturate(dot(eH,uLightDirections[k]));s=saturate(uLightSpot[k].y-uLightSpot[k].z*(1.0-s*s));vec3 jC=mix(uLightColors[k].xyz,vec3(1.0,1.0,1.0),uShadowCatcherParams.x);vec3 jD=(a*s)*jC;jD*=saturate(dot(eH,dC));jB+=jD;jA+=jD*eA.eL[k];}float jE=1.0e-4;vec3 r=(jA+jE)/(jB+jE);float jF=saturate(dot(jv,jv))*uShadowCatcherParams.z;r=mix(r,vec3(1.0,1.0,1.0),jF);r=mix(vec3(1.0,1.0,1.0),r,uShadowCatcherParams.y);gl_FragColor.xyz=r;gl_FragColor.w=1.0;}",
  6847. "shadowfloorvert.glsl": "precision highp float;uniform mat4 uModelViewProjectionMatrix;uniform mat4 uModelSkyMatrix;uniform float uScale;attribute vec3 vPosition;varying highp vec3 dv;varying mediump vec2 jv;varying mediump vec3 dC;vec4 h(mat4 i,vec3 p){return i[0]*p.x+(i[1]*p.y+(i[2]*p.z+i[3]));}void main(void){jv=vPosition.xz;dC=normalize(uModelSkyMatrix[1].xyz);dv=h(uModelSkyMatrix,vPosition).xyz;gl_Position=h(uModelViewProjectionMatrix,vPosition);}",
  6848. "shadowfrag.glsl": "precision highp float;varying vec2 jG;\n#ifdef ALPHA_TEST\nvarying mediump vec2 d;uniform sampler2D tAlbedo;\n#endif\nvec3 jH(float v){vec4 jI=vec4(1.0,255.0,65025.0,16581375.0)*v;jI=fract(jI);jI.xyz-=jI.yzw*(1.0/255.0);return jI.xyz;}void main(void){\n#ifdef ALPHA_TEST\nfloat e=texture2D(tAlbedo,d).a;if(e<0.5){discard;}\n#endif\n#ifdef SHADOW_NATIVE_DEPTH\ngl_FragColor.xyz=vec3(0.0,0.0,0.0);\n#else\ngl_FragColor.xyz=jH((jG.x/jG.y)*0.5+0.5);\n#endif\ngl_FragColor.w=0.0;}",
  6849. "shadowvert.glsl": "precision highp float;attribute vec3 vPosition;attribute vec2 vTexCoord;uniform mat4 uMeshTransform;uniform mat4 uViewProjection;varying vec2 jG;\n#ifdef ALPHA_TEST\nvarying mediump vec2 d;uniform vec2 uUVOffset;\n#endif\nvec4 h(mat4 i,vec3 p){return i[0]*p.x+(i[1]*p.y+(i[2]*p.z+i[3]));}void main(void){vec3 p=h(uMeshTransform,vPosition).xyz;gl_Position=h(uViewProjection,p);jG=gl_Position.zw;\n#ifdef ALPHA_TEST\nd=vTexCoord+uUVOffset;\n#endif\n}",
  6850. "sky.glsl": "precision highp float;uniform sampler2D tSkyTexture;uniform float uAlpha;varying vec2 d;void main(void){vec3 r=texture2D(tSkyTexture,d).xyz;gl_FragColor.xyz=r*r;gl_FragColor.w=uAlpha;}",
  6851. "skySH.glsl": "precision mediump float;uniform vec4 uSkyCoefficients[9];uniform float uAlpha;varying vec3 jJ;void main(void){vec3 G=normalize(jJ);vec3 r=uSkyCoefficients[0].xyz;r+=uSkyCoefficients[1].xyz*G.y;r+=uSkyCoefficients[2].xyz*G.z;r+=uSkyCoefficients[3].xyz*G.x;vec3 swz=G.yyz*G.xzx;r+=uSkyCoefficients[4].xyz*swz.x;r+=uSkyCoefficients[5].xyz*swz.y;r+=uSkyCoefficients[7].xyz*swz.z;vec3 sqr=G*G;r+=uSkyCoefficients[6].xyz*(3.0*sqr.z-1.0);r+=uSkyCoefficients[8].xyz*(sqr.x-sqr.y);gl_FragColor.xyz=r;gl_FragColor.w=uAlpha;}",
  6852. "skyvert.glsl": "precision highp float;uniform mat4 uInverseSkyMatrix;uniform mat4 uViewProjection;attribute vec3 vPosition;attribute vec2 vTexCoord;\n#if SKYMODE == 3\nvarying vec3 jJ;\n#else\nvarying vec2 d;\n#endif\nvec4 h(mat4 i,vec3 p){return i[0]*p.x+(i[1]*p.y+(i[2]*p.z+i[3]));}vec4 u(mat4 i,vec3 v){return i[0]*v.x+i[1]*v.y+i[2]*v.z;}void main(void){vec3 p=h(uInverseSkyMatrix,vPosition).xyz;gl_Position=u(uViewProjection,p);gl_Position.z-=(1.0/65535.0)*gl_Position.w;\n#if SKYMODE == 3\njJ=vPosition;jJ.xy+=1e-20*vTexCoord;\n#else\nd=vTexCoord;\n#endif\n}",
  6853. "wirefrag.glsl": "precision highp float;uniform vec4 uStripParams;void main(void){vec2 c=gl_FragCoord.xy*uStripParams.xy-vec2(1.0,1.0);c.x+=0.25*c.y;float a=c.x<uStripParams.z?0.0:0.9;a=c.x<uStripParams.w?a:0.0;gl_FragColor=vec4(0.0,0.0,0.0,a);}",
  6854. "wirevert.glsl": "precision highp float;uniform mat4 uModelViewProjectionMatrix;attribute vec3 vPosition;vec4 h(mat4 i,vec3 p){return i[0]*p.x+(i[1]*p.y+(i[2]*p.z+i[3]));}void main(void){gl_Position=h(uModelViewProjectionMatrix,vPosition);gl_Position.z+=-0.00005*gl_Position.w;}",
  6855. nil: ""
  6856. };
  6857. }
  6858. )(marmoset);