Fdage1.js 341 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181
  1. fdage = {};
  2. (function(fdage) {
  3. 'use strict';
  4. function AnimatedObject(a, b, c) {
  5. this.name = b.partName;
  6. this.animatedProperties = [];
  7. this.sceneObjectType = b.sceneObjectType;
  8. this.skinningRigIndex = b.skinningRigIndex;
  9. this.id = c;
  10. this.mesh = this.skinningRig = 0;
  11. this.materialIndex = this.lightIndex = this.meshIndex = -1;
  12. this.emissiveProperty = this.offsetVProperty = this.offsetUProperty = this.material = 0;
  13. this.debugMe = b.debugMe;
  14. this.debugString = "";
  15. this.hasTransform = !1;
  16. this.modelPartIndex = b.modelPartIndex;
  17. this.modelPartFPS = b.modelPartFPS;
  18. this.modelPartScale = b.modelPartScale;
  19. this.parentIndex = b.parentIndex;
  20. this.startTime = b.startTime;
  21. this.endTime = b.endTime;
  22. this.animationLength = this.endTime - this.startTime; //时长
  23. this.totalFrames = b.totalFrames;
  24. 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;
  25. if (b.animatedProperties) {
  26. c = b.animatedProperties.length;
  27. for (var d = 0; d < c; ++d) {
  28. var e = b.animatedProperties[d]
  29. , f = new AnimatedProperty;//创建属性
  30. f.name = e.name;
  31. this.animatedProperties.push(f);
  32. "Red" != f.name || this.redProperty || (this.redProperty = f);
  33. "Green" != f.name || this.greenProperty || (this.greenProperty = f);
  34. "Blue" != f.name || this.blueProperty || (this.blueProperty = f);
  35. "Brightness" != f.name || this.brightnessProperty || (this.brightnessProperty = f);
  36. "Distance" != f.name || this.distanceProperty || (this.distanceProperty = f);
  37. "Spot Angle" != f.name || this.spotAngleProperty || (this.spotAngleProperty = f);
  38. "Spot Sharpness" != f.name || this.spotSharpnessProperty || (this.spotSharpnessProperty = f);
  39. "Opacity" != f.name || this.opacityProperty || (this.opacityProperty = f);
  40. "Sky Illumination" != f.name || this.skyIllumProperty || (this.skyIllumProperty = f);
  41. "Light Illumination" != f.name || this.lightIllumProperty || (this.lightIllumProperty = f);
  42. "Dispersion" != f.name || this.dispersionProperty || (this.dispersionProperty = f);
  43. "Visible" != f.name || this.visibleProperty || (this.visibleProperty = f);
  44. "Spin Rate" == f.name && (this.spinProperty = f);
  45. //材质:
  46. "OffsetU" == f.name && (this.offsetUProperty = f);
  47. "OffsetV" == f.name && (this.offsetVProperty = f);
  48. "EmissiveIntensity" == f.name && (this.emissiveProperty = f)
  49. }
  50. }
  51. this.keyframesSharedBufferUShorts = this.keyframesSharedBufferFloats = this.keyFramesByteStream = 0;
  52. if (a = a.get(b.file)){
  53. this.keyFramesByteStream = new ByteStream(a.data);
  54. this.unPackKeyFrames();//为属性获取key
  55. }
  56. this.animatedLocalTransform = new AnimatedTransform(this);//为属性和object创建用于计算transform和矩阵的这么个东西
  57. this.hasTransform = this.animatedLocalTransform.hasTranslation || this.animatedLocalTransform.hasRotation || this.animatedLocalTransform.hasScale;
  58. this.cachedWorldTransform0 = Matrix.identity();
  59. this.cachedWorldTransform1 = Matrix.identity();
  60. this.cachedWorldTransform2 = Matrix.identity();
  61. this.cachedWorldTransform3 = Matrix.identity();
  62. this.cachedFrame3 = this.cachedFrame2 = this.cachedFrame1 = this.cachedFrame0 = -10;
  63. this.cachedFrameUse3 = this.cachedFrameUse2 = this.cachedFrameUse1 = this.cachedFrameUse0 = 0;
  64. this.useFixedLocalTransform = this.useFixedWorldTransform = !1
  65. }
  66. AnimatedObject.prototype.setFixedWorldTransform = function(a) {
  67. this.useFixedWorldTransform = !0;
  68. Matrix.copy(this.cachedWorldTransform0, a)
  69. }
  70. ;
  71. AnimatedObject.prototype.setFixedLocalTransform = function(a) {
  72. this.useFixedLocalTransform = !0;
  73. this.animatedLocalTransform.lockTransform = !0;
  74. Matrix.copy(this.animatedLocalTransform.cachedmatrix0, a)
  75. }
  76. ;
  77. AnimatedObject.prototype.getCachedWorldTransform = function(a) {
  78. 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
  79. }
  80. ;
  81. AnimatedObject.prototype.getFreeCachedWorldTransform = function(a) {
  82. if (this.useFixedWorldTransform)
  83. return 0;
  84. this.cachedFrameUse0--;
  85. this.cachedFrameUse1--;
  86. this.cachedFrameUse2--;
  87. this.cachedFrameUse3--;
  88. if (this.cachedFrameUse0 <= this.cachedFrameUse1 && this.cachedFrameUse0 <= this.cachedFrameUse2 && this.cachedFrameUse0 <= this.cachedFrameUse3)
  89. return this.cachedFrame0 = a,
  90. this.cachedFrameUse0 = 0,
  91. this.cachedWorldTransform0;
  92. if (this.cachedFrameUse1 <= this.cachedFrameUse0 && this.cachedFrameUse1 <= this.cachedFrameUse2 && this.cachedFrameUse1 <= this.cachedFrameUse3)
  93. return this.cachedFrame1 = a,
  94. this.cachedFrameUse1 = 0,
  95. this.cachedWorldTransform1;
  96. if (this.cachedFrameUse2 <= this.cachedFrameUse0 && this.cachedFrameUse2 <= this.cachedFrameUse1 && this.cachedFrameUse2 <= this.cachedFrameUse3)
  97. return this.cachedFrame2 = a,
  98. this.cachedFrameUse2 = 0,
  99. this.cachedWorldTransform2;
  100. this.cachedFrame3 = a;
  101. this.cachedFrameUse3 = 0;
  102. return this.cachedWorldTransform3
  103. }
  104. ;
  105. //解压关键帧
  106. AnimatedObject.prototype.unPackKeyFrames = function() {
  107. if (this.keyFramesByteStream) {
  108. var a = new Float32Array(this.keyFramesByteStream.bytes.buffer);
  109. var b = new Uint32Array(this.keyFramesByteStream.bytes.buffer);
  110. var c = new Uint16Array(this.keyFramesByteStream.bytes.buffer);
  111. var d = new Uint8Array(this.keyFramesByteStream.bytes.buffer);
  112. this.keyframesSharedBufferFloats = a;
  113. this.keyframesSharedBufferUShorts = b;
  114. //var a = 0, b = b[0], a = 1 + b, b = this.animatedProperties.length;
  115. var a = 1 + b[0], b = this.animatedProperties.length;
  116. console.log("\r objectName: "+this.name + "的key: "+this.keyframesSharedBufferFloats.slice(1+b))
  117. for (var e = 0; e < b; e++) {
  118. var f = this.animatedProperties[e];
  119. var g = 2 + 2 * e;
  120. var h = 2 * g;
  121. //关键帧的起始索引
  122. f.keyframeBufferStartIndexFloat = a;
  123. //关键帧的个数
  124. f.numKeyframes = c[g];
  125. //关键帧的压缩类型
  126. f.keyframePackingType = d[h + 2];
  127. //插值类型
  128. f.interpolationType = d[h + 3];//没有用到!
  129. f.indexFloatSkip = 0;
  130. f.indexUShortSkip = 0;
  131. console.log("prName: " + f.name +" ,起始索引"+f.keyframeBufferStartIndexFloat+" ,个数:"+f.numKeyframes)
  132. if(0 < f.numKeyframes)
  133. {
  134. if(0 == f.keyframePackingType)
  135. {
  136. f.bytesPerKeyFrame = 16;
  137. f.indexFloatSkip = 4;
  138. f.indexUShortSkip = 8;
  139. f.valueOffsetFloat = 0;
  140. f.weighInOffsetFloat = 1;
  141. f.weighOutOffsetFloat = 2;
  142. f.frameIndexOffsetUShort = 6;
  143. f.interpolationOffsetUShort = 7;
  144. }
  145. else if(1 == f.keyframePackingType)
  146. {
  147. f.bytesPerKeyFrame = 8;
  148. f.indexFloatSkip = 2;
  149. f.indexUShortSkip = 4;
  150. f.valueOffsetFloat = 0;
  151. f.weighInOffsetFloat = 0;
  152. f.weighOutOffsetFloat = 0;
  153. f.frameIndexOffsetUShort = 2;
  154. f.interpolationOffsetUShort = 3;
  155. }
  156. else if(2 == f.keyframePackingType)//通常是2 对应float
  157. {
  158. f.bytesPerKeyFrame = 4,
  159. f.indexFloatSkip = 1,
  160. f.indexUShortSkip = 2,
  161. f.valueOffsetFloat = 0,
  162. f.weighInOffsetFloat = 0,
  163. f.weighOutOffsetFloat = 0,
  164. f.frameIndexOffsetUShort = 0,
  165. f.interpolationOffsetUShort = 0
  166. }
  167. }
  168. a += f.numKeyframes * f.indexFloatSkip;
  169. }
  170. }
  171. }
  172. ;
  173. AnimatedObject.prototype.setupSkinningRig = function(a, b, c, d) {
  174. var e = Matrix.identity()
  175. , f = Matrix.identity()
  176. , g = a.animatedObjects[b]
  177. , h = c * g.modelPartFPS
  178. , h = h - Math.floor(h);
  179. c = Math.floor(a.getObjectAnimationFramePercent(g, c));
  180. var g = c + 1
  181. , k = 1 - h
  182. , l = d.skinningClusters.length;
  183. if (0 < l)
  184. for (var n = 0; n < l; n++) {
  185. var m = d.skinningClusters[n];
  186. m.solveClusterTransformAtFrame(a, b, c, e);
  187. m.solveClusterTransformAtFrame(a, b, g, f);
  188. for (var m = m.matrix, p = 0; 16 > p; p++)
  189. m[p] = e[p] * k + f[p] * h
  190. }
  191. }
  192. ;
  193. AnimatedObject.prototype.evaluateLocalTransformAtFramePercent = function(a, b, c, d) {
  194. if (this.useFixedLocalTransform)
  195. Matrix.copy(b, this.animatedLocalTransform.cachedmatrix0);
  196. else {
  197. var e = 0;
  198. d && (e = this.animatedLocalTransform.getCachedTransform(a));
  199. if(e){
  200. Matrix.copy(b, e)
  201. }else{
  202. if(e = this.animatedLocalTransform.getFreeCachedTransform(a)){
  203. this.animatedLocalTransform.evaluateMatrix(e, this.totalFrames, a, c);
  204. Matrix.copy(b, e);
  205. }else{//为什么要先用FreeCached的
  206. this.animatedLocalTransform.evaluateMatrix(b, this.totalFrames, a, c);
  207. }
  208. if(0 != this.turnTableSpin ){
  209. a = Matrix.rotation(Matrix.empty(), this.turnTableSpin, 1);
  210. Matrix.mul(b, b, a)
  211. }
  212. }
  213. }
  214. }
  215. ;
  216. AnimatedObject.prototype.hasAnimatedTransform = function() {
  217. var a = this.animatedLocalTransform;
  218. 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
  219. }
  220. ;
  221. function AnimatedProperty() {
  222. this.currentValue = 0;
  223. this.keyframeBufferStartIndexFloat = -1;
  224. this.lastValue = this.interpolationOffsetUShort = this.frameIndexOffsetUShort = this.weighOutOffsetFloat = this.weighInOffsetFloat = this.valueOffsetFloat = this.indexUShortSkip = this.indexFloatSkip = this.interpolationType = this.bytesPerKeyFrame = this.keyframePackingType = 0;
  225. this.lastFramePercent = -10;
  226. this.enable = !0;
  227. this.name = "NONE";
  228. this.splineKF0 = new KeyFrame(0,0);
  229. this.splineKF1 = new KeyFrame(0,0);
  230. this.splineKF2 = new KeyFrame(0,0);
  231. this.splineKF3 = new KeyFrame(0,0);
  232. this.debugMe = !0;
  233. this.debugString = "";
  234. this.lastSearchIndex = 1;
  235. this.savedSearchIndex = 0;
  236. this.splineKF0.frameIndex = 0;
  237. this.splineKF1.frameIndex = 1;
  238. this.splineKF2.frameIndex = 2;
  239. this.splineKF3.frameIndex = 3;
  240. this.numKeyframes = 0
  241. }
  242. AnimatedProperty.prototype.evaluateCurve = function(a, b) {
  243. var c = this.splineKF1.frameIndex
  244. , d = this.splineKF2.frameIndex
  245. , e = this.splineKF1.value
  246. , f = this.splineKF2.value
  247. , g = c - (this.splineKF2.frameIndex - this.splineKF0.frameIndex)
  248. , h = d - (this.splineKF1.frameIndex - this.splineKF3.frameIndex)
  249. , k = e - (this.splineKF2.value - this.splineKF0.value) * this.splineKF1.weighOut
  250. , l = f - (this.splineKF1.value - this.splineKF3.value) * this.splineKF2.weighIn;
  251. 3 == this.splineKF1.interpolation && (g = c - (this.splineKF2.frameIndex - this.splineKF1.frameIndex),
  252. k = e - this.splineKF1.weighOut);
  253. 3 == this.splineKF2.interpolation && (h = d - (this.splineKF1.frameIndex - this.splineKF2.frameIndex),
  254. l = f + this.splineKF2.weighIn);
  255. g = (a - g) / (c - g);
  256. c = (a - c) / (d - c);
  257. d = (a - d) / (h - d);
  258. h = e * (1 - c) + f * c;
  259. return ((k * (1 - g) + e * g) * (1 - c) + h * c) * (1 - c) + ((f * (1 - d) + l * d) * c + h * (1 - c)) * c
  260. }
  261. ;
  262. AnimatedProperty.prototype.evaluate = function(a, b, c) {//获取关键帧?
  263. /* if(this.name != "Rotation X" && this.name != "Rotation Y" && this.name != "Rotation Z"
  264. && this.name != "Translation X" && this.name != "Translation Y" && this.name != "Translation Z"
  265. && this.name != "Scale X" && this.name != "Scale Y" && this.name != "Scale Z"
  266. && this.numKeyframes > 1
  267. ){
  268. console.log(this.name + " : "+ this.numKeyframes)
  269. } */ //大部分多个frame的只有运动属性
  270. if (!c)
  271. return b;
  272. if (0 == this.numKeyframes)
  273. return this.lastValue = b; //b是默认值吗 通常是0
  274. if (1 == this.numKeyframes)
  275. return this.lastValue = 2 == this.keyframePackingType ?
  276. c.keyframesSharedBufferFloats[this.keyframeBufferStartIndexFloat] :
  277. c.keyframesSharedBufferFloats[this.keyframeBufferStartIndexFloat + this.valueOffsetFloat];
  278. if (this.lastFramePercent == a)
  279. return this.lastValue;
  280. var d = this.keyframeBufferStartIndexFloat
  281. , e = 2 * this.keyframeBufferStartIndexFloat;
  282. this.lastValue = b;
  283. this.lastFramePercent = a;
  284. if (2 == this.keyframePackingType) {//注 frame范围是0到numKeyframes-1
  285. b = Math.floor(a);
  286. var f = a - b;
  287. a >= this.numKeyframes && (b -= Math.floor(a / this.numKeyframes) * this.numKeyframes); //确保不大于
  288. if (b >= this.numKeyframes - 1)//由于上面那行操作,这种情况b应该只可能是等于最后一帧
  289. return this.lastValue = c.keyframesSharedBufferFloats[d + (this.numKeyframes - 1)];
  290. if (0 > b)
  291. return this.lastValue = c.keyframesSharedBufferFloats[d];
  292. if (0 == f)
  293. return this.lastValue = c.keyframesSharedBufferFloats[d + b];
  294. //a = e = c.keyframesSharedBufferFloats[d + b];
  295. e = c.keyframesSharedBufferFloats[d + b];
  296. b++;
  297. b >= this.numKeyframes && (b -= this.numKeyframes);
  298. 0 <= b && b < this.numKeyframes ? //线性插值 例如frame(8.8) = frame(8)*0.2+frame(9)*0.8
  299. a = e * (1 - f) + c.keyframesSharedBufferFloats[d + b] * f :
  300. c.debugString += "<br>bad lerp frame " + b + " of " + this.numKeyframes;
  301. return this.lastValue = a
  302. }
  303. //没见过运行到下面的:
  304. var g = this.numKeyframes
  305. , f = c.keyframesSharedBufferUShorts[e + this.frameIndexOffsetUShort];
  306. if (a >= c.keyframesSharedBufferUShorts[e + (g - 1) * this.indexUShortSkip + this.frameIndexOffsetUShort])
  307. return this.lastValue = c.keyframesSharedBufferFloats[d + (g - 1) * this.indexFloatSkip + this.valueOffsetFloat];
  308. if (a < f)
  309. return this.lastValue = c.keyframesSharedBufferFloats[d + this.valueOffsetFloat];
  310. this.lastSearchIndex < this.numKeyframes &&
  311. a > c.keyframesSharedBufferUShorts[e + this.lastSearchIndex * this.indexUShortSkip + this.frameIndexOffsetUShort]
  312. && (this.lastSearchIndex = 1);
  313. for (var h = this.lastSearchIndex; h < g; h++) {
  314. var f = d + h * this.indexFloatSkip
  315. , k = d + (h - 1) * this.indexFloatSkip
  316. , l = e + h * this.indexUShortSkip
  317. , n = e + (h - 1) * this.indexUShortSkip;
  318. if (a >= c.keyframesSharedBufferUShorts[n + this.frameIndexOffsetUShort] && a <= c.keyframesSharedBufferUShorts[l + this.frameIndexOffsetUShort]) {
  319. this.lastSearchIndex = h;
  320. var m = c.keyframesSharedBufferUShorts[n + this.interpolationOffsetUShort];
  321. if (2 == m) {
  322. this.lastValue = a = a >= c.keyframesSharedBufferUShorts[l + this.frameIndexOffsetUShort] ?
  323. c.keyframesSharedBufferFloats[f + this.valueOffsetFloat]
  324. : c.keyframesSharedBufferFloats[k + this.valueOffsetFloat];
  325. break
  326. }
  327. if (0 == m) {
  328. d = c.keyframesSharedBufferUShorts[n + this.frameIndexOffsetUShort];
  329. b = c.keyframesSharedBufferFloats[k + this.valueOffsetFloat];
  330. e = c.keyframesSharedBufferFloats[f + this.valueOffsetFloat];
  331. f = (a - d) / (c.keyframesSharedBufferUShorts[l + this.frameIndexOffsetUShort] - d);
  332. this.lastValue = a = b * (1 - f) + e * f;
  333. break
  334. }
  335. if (1 == m || 3 == m) {
  336. var p = m = !1
  337. , r = 0
  338. , s = c.keyframesSharedBufferFloats[k + this.valueOffsetFloat]
  339. , u = c.keyframesSharedBufferFloats[f + this.valueOffsetFloat]
  340. , q = 0
  341. , x = 0
  342. , n = c.keyframesSharedBufferUShorts[n + this.frameIndexOffsetUShort]
  343. , l = c.keyframesSharedBufferUShorts[l + this.frameIndexOffsetUShort]
  344. , w = 0
  345. , v = 1
  346. , t = 1
  347. , y = 1
  348. , E = 1
  349. , F = 1
  350. , A = 1
  351. , B = 1
  352. , z = 1;
  353. 0 != this.weighInOffsetFloat && (t = c.keyframesSharedBufferFloats[k + this.weighInOffsetFloat],
  354. y = c.keyframesSharedBufferFloats[f + this.weighInOffsetFloat],
  355. A = c.keyframesSharedBufferFloats[k + this.weighOutOffsetFloat],
  356. B = c.keyframesSharedBufferFloats[f + this.weighOutOffsetFloat]);
  357. 1 < h && (m = !0,
  358. r = c.keyframesSharedBufferFloats[d + (h - 2) * this.indexFloatSkip + this.valueOffsetFloat],
  359. x = c.keyframesSharedBufferUShorts[e + (h - 2) * this.indexUShortSkip + this.frameIndexOffsetUShort],
  360. 0 != this.weighInOffsetFloat && (v = c.keyframesSharedBufferFloats[d + (h - 2) * this.indexFloatSkip + this.weighInOffsetFloat],
  361. F = c.keyframesSharedBufferFloats[d + (h - 2) * this.indexFloatSkip + this.weighOutOffsetFloat]));
  362. h < g - 1 && (p = !0,
  363. q = c.keyframesSharedBufferFloats[d + (h + 1) * this.indexFloatSkip + this.valueOffsetFloat],
  364. w = c.keyframesSharedBufferUShorts[e + (h + 1) * this.indexUShortSkip + this.frameIndexOffsetUShort],
  365. 0 != this.weighInOffsetFloat && (E = c.keyframesSharedBufferFloats[d + (h + 1) * this.indexFloatSkip + this.weighInOffsetFloat],
  366. z = c.keyframesSharedBufferFloats[d + (h + 1) * this.indexFloatSkip + this.weighOutOffsetFloat]));
  367. m && p ? (this.splineKF0.value = r,
  368. this.splineKF1.value = s,
  369. this.splineKF2.value = u,
  370. this.splineKF3.value = q,
  371. this.splineKF0.frameIndex = x,
  372. this.splineKF1.frameIndex = n,
  373. this.splineKF2.frameIndex = l,
  374. this.splineKF3.frameIndex = w,
  375. this.splineKF0.weighIn = v,
  376. this.splineKF0.weighOut = F,
  377. this.splineKF1.weighIn = t,
  378. this.splineKF1.weighOut = A,
  379. this.splineKF2.weighIn = y,
  380. this.splineKF2.weighOut = B,
  381. this.splineKF3.weighIn = E,
  382. this.splineKF3.weighOut = z) : (this.splineKF0.value = s,
  383. this.splineKF1.value = s,
  384. this.splineKF2.value = u,
  385. this.splineKF3.value = u,
  386. this.splineKF0.frameIndex = n,
  387. this.splineKF1.frameIndex = n,
  388. this.splineKF2.frameIndex = l,
  389. this.splineKF3.frameIndex = l,
  390. this.splineKF1.weighIn = t,
  391. this.splineKF2.weighIn = y,
  392. this.splineKF1.weighOut = A,
  393. this.splineKF2.weighOut = B,
  394. p ? (this.splineKF3.value = q,
  395. this.splineKF3.frameIndex = w,
  396. this.splineKF3.weighIn = E,
  397. this.splineKF3.weighOut = z) : (this.splineKF3.frameIndex++,
  398. this.splineKF3.value = this.splineKF1.value,
  399. this.splineKF3.weighIn = 1,
  400. this.splineKF3.weighOut = 1),
  401. m ? (this.splineKF0.value = r,
  402. this.splineKF0.frameIndex = x,
  403. this.splineKF0.weighIn = v,
  404. this.splineKF0.weighOut = F) : (this.splineKF0.value = this.splineKF2.value,
  405. this.splineKF0.weighIn = 1,
  406. this.splineKF0.weighOut = 1,
  407. 0 < this.splineKF0.frameIndex ? this.splineKF0.frameIndex-- : (this.splineKF1.frameIndex++,
  408. this.splineKF2.frameIndex++,
  409. this.splineKF3.frameIndex++,
  410. a++)));
  411. this.lastValue = a = this.evaluateCurve(a, b);
  412. break
  413. }
  414. }
  415. }
  416. return this.lastValue
  417. }
  418. ;
  419. function AnimatedTransform(a) {
  420. var b = a.animatedProperties;
  421. this.TX = this.TY = this.TZ = this.RX = this.RY = this.RZ = this.SX = this.SY = this.SZ = 0;
  422. this.hostObject = a;
  423. this.matrix = Matrix.identity();
  424. this.cachedmatrix0 = Matrix.identity();
  425. this.cachedmatrix1 = Matrix.identity();
  426. this.cachedmatrix2 = Matrix.identity();
  427. this.cachedmatrix3 = Matrix.identity();
  428. this.cachedFrame3 = this.cachedFrame2 = this.cachedFrame1 = this.cachedFrame0 = -1;
  429. this.cachedFrameUse3 = this.cachedFrameUse2 = this.cachedFrameUse1 = this.cachedFrameUse0 = 0;
  430. this.debugString = "";
  431. for (a = 0; a < b.length; a++) {
  432. var c = b[a];
  433. "Translation X" == c.name ? this.TX = c : "Translation Y" == c.name ? this.TY = c : "Translation Z" == c.name ? this.TZ = c : "Rotation X" == c.name ? this.RX = c : "Rotation Y" == c.name ? this.RY = c : "Rotation Z" == c.name ? this.RZ = c : "Scale X" == c.name ? this.SX = c : "Scale Y" == c.name ? this.SY = c : "Scale Z" == c.name && (this.SZ = c)
  434. }
  435. this.hasTranslation = this.TX && this.TY && this.TZ;
  436. this.hasRotation = this.RX && this.RY && this.RZ;
  437. this.hasScale = this.SX && this.SY && this.SZ;
  438. this.lockTransform = !1
  439. }
  440. AnimatedTransform.prototype.getTRSValue = function(a, b, c) {
  441. if (!b)
  442. return c;
  443. b.evaluate(a, c, this.hostObject);
  444. "" != b.debugString && (this.debugString += b.debugString);
  445. return b.lastValue
  446. }
  447. ;
  448. AnimatedTransform.prototype.evaluateMatrix = function(a, b, c, d) {
  449. if (this.lockTransform)
  450. Matrix.copy(a, this.cachedmatrix0);
  451. else {
  452. var e = 0
  453. , f = b = 0
  454. , e = f = b = 0
  455. , e = f = b = 1;
  456. if(this.hasRotation){
  457. e = this.getTRSValue(c, this.RX, 0);
  458. b = this.getTRSValue(c, this.RY, 0);
  459. f = this.getTRSValue(c, this.RZ, 0);
  460. if(d){//为什么有两种旋转方式? 是坐标系不同?
  461. this.matrix = Matrix.rotation(Matrix.empty(), f, 2);
  462. d = Matrix.rotation(Matrix.empty(), e, 0);
  463. Matrix.mul(d, d, this.matrix);
  464. this.matrix = Matrix.rotation(Matrix.empty(), b, 1)
  465. }else{
  466. this.matrix = Matrix.rotation(Matrix.empty(), e, 0);
  467. d = Matrix.rotation(Matrix.empty(), b, 1);
  468. Matrix.mul(d, d, this.matrix);
  469. this.matrix = Matrix.rotation(Matrix.empty(), f, 2)
  470. }
  471. Matrix.mul(this.matrix, this.matrix, d)
  472. } else Matrix.copy(this.matrix, Matrix.identity());
  473. if(this.hasTranslation){
  474. b = this.getTRSValue(c, this.TX, 0);
  475. f = this.getTRSValue(c, this.TY, 0);
  476. e = this.getTRSValue(c, this.TZ, 0);
  477. this.matrix[12] = b;
  478. this.matrix[13] = f;
  479. this.matrix[14] = e;
  480. }
  481. if(this.hasScale){
  482. b = this.getTRSValue(c, this.SX, 1),
  483. f = this.getTRSValue(c, this.SY, 1),
  484. e = this.getTRSValue(c, this.SZ, 1);
  485. this.matrix[0] *= b,
  486. this.matrix[4] *= f,
  487. this.matrix[8] *= e,
  488. this.matrix[1] *= b,
  489. this.matrix[5] *= f,
  490. this.matrix[9] *= e,
  491. this.matrix[2] *= b,
  492. this.matrix[6] *= f,
  493. this.matrix[10] *= e,
  494. this.matrix[3] *= b,
  495. this.matrix[7] *= f,
  496. this.matrix[11] *= e
  497. }
  498. Matrix.copy(a, this.matrix)
  499. }
  500. }
  501. ;
  502. AnimatedTransform.prototype.clearCachedTransforms = function() {
  503. this.cachedFrame3 = this.cachedFrame2 = this.cachedFrame1 = this.cachedFrame0 = -1;
  504. this.cachedFrameUse3 = this.cachedFrameUse2 = this.cachedFrameUse1 = this.cachedFrameUse0 = 0;
  505. this.TX && (this.TX.lastFramePercent = -10);
  506. this.TY && (this.TY.lastFramePercent = -10);
  507. this.TZ && (this.TZ.lastFramePercent = -10);
  508. this.RX && (this.RX.lastFramePercent = -10);
  509. this.RY && (this.RY.lastFramePercent = -10);
  510. this.RZ && (this.RZ.lastFramePercent = -10);
  511. this.SX && (this.SX.lastFramePercent = -10);
  512. this.SY && (this.SY.lastFramePercent = -10);
  513. this.SZ && (this.SZ.lastFramePercent = -10);
  514. this.lockTransform = !1
  515. }
  516. ;
  517. AnimatedTransform.prototype.getCachedTransform = function(a) {
  518. 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
  519. }
  520. ;
  521. AnimatedTransform.prototype.getFreeCachedTransform = function(a) {//为什么是三个? 每次都用最小的那个,然后变成最大的
  522. if (this.lockTransform)
  523. return 0;
  524. this.cachedFrameUse0--;
  525. this.cachedFrameUse1--;
  526. this.cachedFrameUse2--;
  527. this.cachedFrameUse3--;
  528. if (this.cachedFrameUse0 <= this.cachedFrameUse1 && this.cachedFrameUse0 <= this.cachedFrameUse2 && this.cachedFrameUse0 <= this.cachedFrameUse3 || this.cachedFrame0 == a)
  529. return this.cachedFrame0 = a,
  530. this.cachedFrameUse0 = 0,
  531. this.cachedmatrix0;
  532. if (this.cachedFrameUse1 <= this.cachedFrameUse0 && this.cachedFrameUse1 <= this.cachedFrameUse2 && this.cachedFrameUse1 <= this.cachedFrameUse3 || this.cachedFrame1 == a)
  533. return this.cachedFrame1 = a,
  534. this.cachedFrameUse1 = 0,
  535. this.cachedmatrix1;
  536. if (this.cachedFrameUse2 <= this.cachedFrameUse0 && this.cachedFrameUse2 <= this.cachedFrameUse1 && this.cachedFrameUse2 <= this.cachedFrameUse3 || this.cachedFrame2 == a)
  537. return this.cachedFrame2 = a,
  538. this.cachedFrameUse2 = 0,
  539. this.cachedmatrix2;
  540. this.cachedFrame3 = a;
  541. this.cachedFrameUse3 = 0;
  542. return this.cachedmatrix3
  543. }
  544. ;
  545. function Animation(a, b) {
  546. this.originalFPS = 1;
  547. this.name = b.name;
  548. this.totalSeconds = b.length;
  549. this.originalFPS = b.originalFPS;
  550. this.totalFrames = b.totalFrames;
  551. this.expectedNumAnimatedObjects = b.numAnimatedObjects;
  552. this.animatedObjects = [];
  553. this.sceneTransform = Matrix.identity();
  554. this.debugString = "";
  555. if (b.animatedObjects)
  556. for (var c = b.animatedObjects.length, d = 0; d < c; ++d) {
  557. var e = new AnimatedObject(a,b.animatedObjects[d],d);
  558. this.animatedObjects.push(e);
  559. this.debugString += e.debugString
  560. }
  561. this.meshObjects = [];
  562. this.lightObjects = [];
  563. this.materialObjects = [];
  564. this.turnTableObjects = [];
  565. this.cameraObjects = []
  566. }
  567. Animation.prototype.evaluateModelPartTransformAtFrame = function(a, b, c, d) {
  568. Matrix.copy(c, Matrix.identity());
  569. for (var e = 0; 100 > e; e++) {
  570. var f = this.animatedObjects[a];
  571. if (a == f.parentIndex)
  572. break;
  573. if (f.useFixedWorldTransform) {
  574. Matrix.mul(c, f.cachedWorldTransform0, c);
  575. break
  576. } else {
  577. var g = 0;
  578. d && (g = f.getCachedWorldTransform(b));
  579. if (g) {
  580. Matrix.mul(c, g, c);
  581. break
  582. }else{
  583. g = Matrix.identity();
  584. f.evaluateLocalTransformAtFramePercent(b, g, !1, d);
  585. Matrix.mul(c, g, c);
  586. a == f.parentIndex && (e = 100);
  587. a = f.parentIndex;
  588. }
  589. }
  590. }
  591. }
  592. ;
  593. Animation.prototype.lerpModelPartTransform = function(a, b, c, d) {//?
  594. var e = this.animatedObjects[a];
  595. if (e.useFixedWorldTransform)
  596. Matrix.copy(c, e.cachedWorldTransform0);
  597. else {
  598. var f = b * e.modelPartFPS
  599. , f = f - Math.floor(f)
  600. , g = Math.floor(this.getObjectAnimationFramePercent(e, b))
  601. , h = g + 1
  602. , k = b = 0;
  603. d && (b = e.getCachedWorldTransform(g),
  604. k = e.getCachedWorldTransform(h));
  605. b || ((b = e.getFreeCachedWorldTransform(g)) || (b = Matrix.identity()),
  606. this.evaluateModelPartTransformAtFrame(a, g, b, d));
  607. k || ((k = e.getFreeCachedWorldTransform(h)) || (k = Matrix.identity()),
  608. this.evaluateModelPartTransformAtFrame(a, h, k, d));
  609. a = 1 - f;
  610. for (d = 0; 16 > d; d++)
  611. c[d] = b[d] * a + k[d] * f
  612. }
  613. }
  614. ;
  615. Animation.prototype.getModelPartTransform = function(a, b, c, d) {
  616. this.lerpModelPartTransform(a, b, c, d)
  617. }
  618. ;
  619. Animation.prototype.getAnimatedLocalTransform = function(a, b, c, d) {
  620. a = this.animatedObjects[a];
  621. var e = this.animatedObjects[a.parentIndex]
  622. , f = e.modelPartIndex != e.id
  623. , g = Matrix.identity();
  624. this.getModelPartTransform(a.modelPartIndex, b, g, d);
  625. if (f) { //why?
  626. var f = Matrix.identity()
  627. , h = Matrix.identity();
  628. this.getModelPartTransform(e.modelPartIndex, b, f, d);
  629. Matrix.invert(h, f);
  630. Matrix.mul(c, h, g);
  631. c[12] *= a.modelPartScale;
  632. c[13] *= a.modelPartScale;
  633. c[14] *= a.modelPartScale
  634. } else
  635. Matrix.copy(c, g)
  636. }
  637. ;
  638. Animation.prototype.isVisibleAtFramePercent = function(a, b) {
  639. for (var c = a, d = 0, e = 0; 100 > e; e++) {
  640. d = this.animatedObjects[c];
  641. if (d.visibleProperty) {
  642. d.visibleProperty.evaluate(b, 1, d);
  643. if ("" != d.debugString || "" != d.visibleProperty.debugString)
  644. return this.debugString += d.debugString,
  645. this.debugString += d.visibleProperty.debugString,
  646. !1;
  647. if (0 == d.visibleProperty.lastValue)
  648. return !1
  649. }
  650. c == d.parentIndex && (e = 100);
  651. c = d.parentIndex
  652. }
  653. return !0
  654. }
  655. ;
  656. Animation.prototype.getWorldTransform = function(a, b, c, d, e) {
  657. a = this.animatedObjects[a];
  658. if (a.useFixedWorldTransform)
  659. Matrix.copy(c, a.cachedWorldTransform0);
  660. else {
  661. var f = this.getObjectAnimationFramePercent(a, b)
  662. , g = Matrix.identity();
  663. a.evaluateLocalTransformAtFramePercent(f, g, !0, e);//获得g
  664. if (f = a.modelPartIndex != a.id) {//如果modelPart节点不是自己 获取AnimatedLocalTransform
  665. var f = Matrix.identity()
  666. , h = Matrix.identity();
  667. Matrix.copy(h, g);
  668. this.getAnimatedLocalTransform(a.id, b, f);//获取f
  669. Matrix.mul(g, f, h)
  670. }
  671. Matrix.copy(c, g);
  672. if (a.parentIndex != a.id)//如果有父节点 获取父节点的LocalTransform
  673. for (var k = a.parentIndex, l = 0; 100 > l; l++)
  674. a = this.animatedObjects[k],
  675. f = this.getObjectAnimationFramePercent(a, b),
  676. g = Matrix.identity(),
  677. a.evaluateLocalTransformAtFramePercent(f, g, !0, e),//获取g
  678. (f = a.modelPartIndex != a.id) ? (f = Matrix.identity(),//如果父节点的modelPart不是父节点
  679. this.getAnimatedLocalTransform(a.id, b, f),
  680. h = Matrix.identity(),
  681. Matrix.mul(h, g, c), //结果f*g*c
  682. Matrix.mul(c, f, h)) : (h = Matrix.identity(),//否则结果 g*c 即少乘了个AnimatedLocalTransform
  683. Matrix.copy(h, c),
  684. Matrix.mul(c, g, h)),
  685. k == a.parentIndex && (l = 100), //如果父节点的父节点是父节点,结束 即继续搜寻父节点
  686. k = a.parentIndex;
  687. c[12] *= d;
  688. c[13] *= d;
  689. c[14] *= d
  690. }
  691. }
  692. ;
  693. Animation.prototype.hasParentInHierarchy = function(a, b) {
  694. for (var c = a.parentIndex, d = 0; 100 > d; d++) {
  695. a = this.animatedObjects[c];
  696. if (a.id == b)
  697. return !0;
  698. c == a.parentIndex && (d = 100);
  699. c = a.parentIndex
  700. }
  701. return !1
  702. }
  703. ;
  704. Animation.prototype.hasParentTypeInHierarchy = function(a, b) {
  705. for (var c = a.parentIndex, d = 0; 100 > d; d++) {
  706. a = this.animatedObjects[c];
  707. if (a.sceneObjectType == b)
  708. return !0;
  709. c == a.parentIndex && (d = 100);
  710. c = a.parentIndex
  711. }
  712. return !1
  713. }
  714. ;
  715. Animation.prototype.searchAnimationUpHierarchy = function(a) {
  716. for (var b = a.id, c = 0; 100 > c; c++) {
  717. a = this.animatedObjects[b];
  718. if (a.animatedLocalTransform && (a.hasAnimatedTransform() || a.id != a.modelPartIndex && this.searchAnimationUpHierarchy(this.animatedObjects[a.modelPartIndex])))
  719. return !0;
  720. b == a.parentIndex && (c = 100);
  721. b = a.parentIndex
  722. }
  723. return !1
  724. }
  725. ;
  726. Animation.prototype.hasAnimationInHierarchy = function(a) {//是否有层级?
  727. 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
  728. }
  729. ;
  730. Animation.prototype.getObjectAnimationFramePercent = function(a, b) {
  731. if (0 == this.totalFrames || 0 == a.animationLength)
  732. return 0;
  733. if (a.endTime == this.totalSeconds)
  734. return b * a.modelPartFPS;
  735. var c = b / a.animationLength
  736. , c = Math.floor(c);
  737. b -= a.animationLength * c; //应该是为了确保totalSeconds不大于AnimatedObject的animationLength
  738. c = b * a.modelPartFPS;
  739. c >= a.totalFrames + 1 && (c = a.totalFrames);
  740. return c
  741. }
  742. ;
  743. function Archive(a) {
  744. this.files = [];
  745. for (a = new ByteStream(a); !a.empty(); ) {
  746. var b = {};
  747. b.name = a.readCString();
  748. b.type = a.readCString();
  749. var c = a.readUint32()
  750. , d = a.readUint32()
  751. , e = a.readUint32();
  752. b.data = a.readBytes(d);
  753. if (!(b.data.length < d)) {
  754. if (c & 1 && (b.data = this.decompress(b.data, e),
  755. null === b.data))
  756. continue;
  757. this.files[b.name] = b
  758. }
  759. }
  760. }
  761. ;
  762. Archive.prototype.get = function(a) {
  763. return this.files[a]
  764. }
  765. ;
  766. Archive.prototype.extract = function(a) {
  767. var b = this.files[a];
  768. delete this.files[a];
  769. return b
  770. }
  771. ;
  772. Archive.prototype.checkSignature = function(a) {
  773. if (!a)
  774. return !1;
  775. var b = this.get(a.name + ".sig");
  776. if (!b)
  777. return !1;
  778. b = JSON.parse(String.fromCharCode.apply(null, b.data));
  779. if (!b)
  780. return !1;
  781. for (var c = 5381, d = 0; d < a.data.length; ++d)
  782. c = 33 * c + a.data[d] & 4294967295;
  783. a = new BigInt;
  784. 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);
  785. d = new BigInt;
  786. d.setBytes(b[0]);
  787. return d.powmod(65537, a).toInt32() != c ? !1 : !0
  788. }
  789. ;
  790. Archive.prototype.decompress = function(a, b) {
  791. var c = new Uint8Array(b)
  792. , d = 0
  793. , e = new Uint32Array(4096)
  794. , f = new Uint32Array(4096)
  795. , g = 256
  796. , h = a.length
  797. , k = 0
  798. , l = 1
  799. , n = 0
  800. , m = 1;
  801. c[d++] = a[0];
  802. for (var p = 1; ; p++) {
  803. m = p + (p >> 1);
  804. if (m + 1 >= h)
  805. break;
  806. var n = a[m + 1]
  807. , m = a[m]
  808. , r = p & 1 ? n << 4 | m >> 4 : (n & 15) << 8 | m;
  809. if (r < g)
  810. if (256 > r)
  811. n = d,
  812. m = 1,
  813. c[d++] = r;
  814. else
  815. for (var n = d, m = f[r], r = e[r], s = r + m; r < s; )
  816. c[d++] = c[r++];
  817. else if (r == g) {
  818. n = d;
  819. m = l + 1;
  820. r = k;
  821. for (s = k + l; r < s; )
  822. c[d++] = c[r++];
  823. c[d++] = c[k]
  824. } else
  825. break;
  826. e[g] = k;
  827. f[g++] = l + 1;
  828. k = n;
  829. l = m;
  830. g = 4096 <= g ? 256 : g
  831. }
  832. return d == b ? c : null
  833. }
  834. ;
  835. function BigInt(a) {
  836. this.digits = new Uint16Array(a || 0)
  837. }
  838. BigInt.prototype.setBytes = function(a, b) {
  839. var c = (a.length + 1) / 2 | 0;
  840. this.digits = new Uint16Array(c);
  841. if (b)
  842. for (var d = 0, c = a.length - 1; 0 <= c; c -= 2)
  843. this.digits[d++] = a[c] + (0 < c ? 256 * a[c - 1] : 0);
  844. else
  845. for (d = 0; d < c; ++d)
  846. this.digits[d] = a[2 * d] + 256 * a[2 * d + 1];
  847. this.trim()
  848. }
  849. ;
  850. BigInt.prototype.toInt32 = function() {
  851. var a = 0;
  852. 0 < this.digits.length && (a = this.digits[0],
  853. 1 < this.digits.length && (a |= this.digits[1] << 16));
  854. return a
  855. }
  856. ;
  857. BigInt.prototype.lessThan = function(a) {
  858. if (this.digits.length == a.digits.length)
  859. for (var b = this.digits.length - 1; 0 <= b; --b) {
  860. var c = this.digits[b]
  861. , d = a.digits[b];
  862. if (c != d)
  863. return c < d
  864. }
  865. return this.digits.length < a.digits.length
  866. }
  867. ;
  868. BigInt.prototype.shiftRight = function() {
  869. for (var a = 0, b = this.digits, c = b.length - 1; 0 <= c; --c) {
  870. var d = b[c];
  871. b[c] = d >> 1 | a << 15;
  872. a = d
  873. }
  874. this.trim()
  875. }
  876. ;
  877. BigInt.prototype.shiftLeft = function(a) {
  878. if (0 < a) {
  879. var b = a / 16 | 0;
  880. a %= 16;
  881. for (var c = 16 - a, d = this.digits.length + b + 1, e = new BigInt(d), f = 0; f < d; ++f)
  882. e.digits[f] = ((f < b || f >= this.digits.length + b ? 0 : this.digits[f - b]) << a | (f < b + 1 ? 0 : this.digits[f - b - 1]) >>> c) & 65535;
  883. e.trim();
  884. return e
  885. }
  886. return new BigInt(this)
  887. }
  888. ;
  889. BigInt.prototype.bitCount = function() {
  890. var a = 0;
  891. if (0 < this.digits.length)
  892. for (var a = 16 * (this.digits.length - 1), b = this.digits[this.digits.length - 1]; b; )
  893. b >>>= 1,
  894. ++a;
  895. return a
  896. }
  897. ;
  898. BigInt.prototype.sub = function(a) {
  899. var b = this.digits
  900. , c = a.digits
  901. , d = this.digits.length;
  902. a = a.digits.length;
  903. for (var e = 0, f = 0; f < d; ++f) {
  904. var g = b[f]
  905. , h = f < a ? c[f] : 0
  906. , h = h + e
  907. , e = h > g ? 1 : 0
  908. , g = g + (e << 16);
  909. b[f] = g - h & 65535
  910. }
  911. this.trim()
  912. }
  913. ;
  914. BigInt.prototype.mul = function(a) {
  915. for (var b = new BigInt(this.digits.length + a.digits.length), c = b.digits, d = 0; d < this.digits.length; ++d)
  916. for (var e = this.digits[d], f = 0; f < a.digits.length; ++f)
  917. for (var g = e * a.digits[f], h = d + f; g; ) {
  918. var k = (g & 65535) + c[h];
  919. c[h] = k & 65535;
  920. g >>>= 16;
  921. g += k >>> 16;
  922. ++h
  923. }
  924. b.trim();
  925. return b
  926. }
  927. ;
  928. BigInt.prototype.mod = function(a) {
  929. if (0 >= this.digits.length || 0 >= a.digits.length)
  930. return new BigInt(0);
  931. var b = new BigInt(this.digits);
  932. if (!this.lessThan(a)) {
  933. for (var c = new BigInt(a.digits), c = c.shiftLeft(b.bitCount() - c.bitCount()); !b.lessThan(a); )
  934. c.lessThan(b) && b.sub(c),
  935. c.shiftRight();
  936. b.trim()
  937. }
  938. return b
  939. }
  940. ;
  941. BigInt.prototype.powmod = function(a, b) {
  942. for (var c = new BigInt([1]), d = this.mod(b); a; )
  943. a & 1 && (c = c.mul(d).mod(b)),
  944. a >>>= 1,
  945. d = d.mul(d).mod(b);
  946. return c
  947. }
  948. ;
  949. BigInt.prototype.trim = function() {
  950. for (var a = this.digits.length; 0 < a && 0 == this.digits[a - 1]; )
  951. --a;
  952. a != this.digits.length && (this.digits = this.digits.subarray(0, a))
  953. }
  954. ;
  955. function Bounds(a) {
  956. for (var b = 0; b < a.length; ++b) {
  957. var c = a[b].bounds;
  958. if (void 0 === this.min)
  959. this.min = [c.min[0], c.min[1], c.min[2]],
  960. this.max = [c.max[0], c.max[1], c.max[2]];
  961. else
  962. for (var d = 0; 3 > d; ++d)
  963. this.min[d] = Math.min(c.min[d], this.min[d]),
  964. this.max[d] = Math.max(c.max[d], this.max[d])
  965. }
  966. this.min = this.min ? this.min : [0, 0, 0];
  967. this.max = this.max ? this.max : [0, 0, 0];
  968. 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])];
  969. this.radius = [this.max[0] - this.center[0], this.max[1] - this.center[1], this.max[2] - this.center[2]];
  970. this.radiusDiagonal = Math.sqrt(this.radius[0] * this.radius[0] + this.radius[1] * this.radius[1] + this.radius[2] * this.radius[2])
  971. }
  972. ;function Button(a) {
  973. this.name = "none";
  974. this.text = "default text";
  975. this.title = "none";
  976. this.debugString = this.imagePath = "";
  977. this.controlRect = new ControlRect(a);
  978. this.defaultAlpha = 0.5;
  979. this.focusAlpha = 1;
  980. this.updateAlphas = !0;
  981. 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
  982. }
  983. Button.prototype.setBackground3x1 = function(a, b, c, d, e, f, g) {
  984. this.backgroundOffsetX = b;
  985. this.backgroundOffsetY = c;
  986. this.edgePixelsX = g;
  987. this.backgroundLeft = a.addImage(d);
  988. this.backgroundMiddle = a.addImage(e);
  989. this.backgroundRight = a.addImage(f);
  990. this.backgroundLeft.linkedControl.style.zIndex = "0";
  991. this.backgroundMiddle.linkedControl.style.zIndex = "0";
  992. this.backgroundRight.linkedControl.style.zIndex = "0";
  993. this.setOpacity(this.defaultAlpha)
  994. }
  995. ;
  996. Button.prototype.setBackground3x3 = function(a, b, c, d, e, f, g, h, k, l, n, m, p, r) {
  997. this.backgroundOffsetX = b;
  998. this.backgroundOffsetY = c;
  999. this.edgePixelsX = p;
  1000. this.edgePixelsY = r;
  1001. this.backgroundTopLeft = a.addImage(d);
  1002. this.backgroundMiddleLeft = a.addImage(g);
  1003. this.backgroundBottomLeft = a.addImage(l);
  1004. this.backgroundTopMiddle = a.addImage(e);
  1005. this.backgroundMiddleMiddle = a.addImage(h);
  1006. this.backgroundBottomMiddle = a.addImage(n);
  1007. this.backgroundTopRight = a.addImage(f);
  1008. this.backgroundMiddleRight = a.addImage(k);
  1009. this.backgroundBottomRight = a.addImage(m);
  1010. this.backgroundTopLeft.linkedControl.style.zIndex = "0";
  1011. this.backgroundTopRight.linkedControl.style.zIndex = "0";
  1012. this.backgroundTopMiddle.linkedControl.style.zIndex = "0";
  1013. this.backgroundMiddleLeft.linkedControl.style.zIndex = "0";
  1014. this.backgroundMiddleRight.linkedControl.style.zIndex = "0";
  1015. this.backgroundMiddleMiddle.linkedControl.style.zIndex = "0";
  1016. this.backgroundBottomLeft.linkedControl.style.zIndex = "0";
  1017. this.backgroundBottomRight.linkedControl.style.zIndex = "0";
  1018. this.backgroundBottomMiddle.linkedControl.style.zIndex = "0";
  1019. this.setOpacity(this.defaultAlpha)
  1020. }
  1021. ;
  1022. Button.prototype.alignBackground = function() {
  1023. var a = this.controlRect
  1024. , b = a.guiScreen
  1025. , c = b.left * (1 - a.getScreenXPercent())
  1026. , d = b.bottom * (1 - a.getScreenYPercent())
  1027. , e = b.width * a.getScreenWidthPercent()
  1028. , a = b.height * a.getScreenHeightPercent()
  1029. , d = d + this.backgroundOffsetY
  1030. , c = c + this.backgroundOffsetX;
  1031. if (this.backgroundTopLeft && this.backgroundTopRight && this.backgroundTopMiddle && this.backgroundMiddleLeft && this.backgroundMiddleRight && this.backgroundMiddleMiddle && this.backgroundBottomLeft && this.backgroundBottomRight && this.backgroundBottomMiddle) {
  1032. var b = e - 2 * this.edgePixelsX
  1033. , f = a - 2 * this.edgePixelsY;
  1034. this.backgroundTopLeft.linkedControl.style.height = this.edgePixelsY + "px";
  1035. this.backgroundTopMiddle.linkedControl.style.height = this.edgePixelsY + "px";
  1036. this.backgroundTopRight.linkedControl.style.height = this.edgePixelsY + "px";
  1037. this.backgroundBottomLeft.linkedControl.style.height = this.edgePixelsY + "px";
  1038. this.backgroundBottomMiddle.linkedControl.style.height = this.edgePixelsY + "px";
  1039. this.backgroundBottomRight.linkedControl.style.height = this.edgePixelsY + "px";
  1040. this.backgroundMiddleLeft.linkedControl.style.height = f + "px";
  1041. this.backgroundMiddleMiddle.linkedControl.style.height = f + "px";
  1042. this.backgroundMiddleRight.linkedControl.style.height = f + "px";
  1043. this.backgroundTopLeft.linkedControl.style.width = this.edgePixelsX + "px";
  1044. this.backgroundBottomLeft.linkedControl.style.width = this.edgePixelsX + "px";
  1045. this.backgroundMiddleLeft.linkedControl.style.width = this.edgePixelsX + "px";
  1046. this.backgroundTopRight.linkedControl.style.width = this.edgePixelsX + "px";
  1047. this.backgroundBottomRight.linkedControl.style.width = this.edgePixelsX + "px";
  1048. this.backgroundMiddleRight.linkedControl.style.width = this.edgePixelsX + "px";
  1049. this.backgroundTopMiddle.linkedControl.style.width = b + "px";
  1050. this.backgroundBottomMiddle.linkedControl.style.width = b + "px";
  1051. this.backgroundMiddleMiddle.linkedControl.style.width = b + "px";
  1052. this.backgroundTopLeft.linkedControl.style.left = c + "px";
  1053. this.backgroundBottomLeft.linkedControl.style.left = c + "px";
  1054. this.backgroundMiddleLeft.linkedControl.style.left = c + "px";
  1055. c += this.edgePixelsX;
  1056. this.backgroundTopMiddle.linkedControl.style.left = c + "px";
  1057. this.backgroundBottomMiddle.linkedControl.style.left = c + "px";
  1058. this.backgroundMiddleMiddle.linkedControl.style.left = c + "px";
  1059. c += b;
  1060. this.backgroundTopRight.linkedControl.style.left = c + "px";
  1061. this.backgroundBottomRight.linkedControl.style.left = c + "px";
  1062. this.backgroundMiddleRight.linkedControl.style.left = c + "px";
  1063. this.backgroundBottomLeft.linkedControl.style.bottom = d + "px";
  1064. this.backgroundBottomMiddle.linkedControl.style.bottom = d + "px";
  1065. this.backgroundBottomRight.linkedControl.style.bottom = d + "px";
  1066. d += this.edgePixelsY;
  1067. this.backgroundMiddleLeft.linkedControl.style.bottom = d + "px";
  1068. this.backgroundMiddleRight.linkedControl.style.bottom = d + "px";
  1069. this.backgroundMiddleMiddle.linkedControl.style.bottom = d + "px";
  1070. d += f;
  1071. this.backgroundTopLeft.linkedControl.style.bottom = d + "px";
  1072. this.backgroundTopMiddle.linkedControl.style.bottom = d + "px";
  1073. this.backgroundTopRight.linkedControl.style.bottom = d + "px"
  1074. }
  1075. this.backgroundLeft && this.backgroundRight && this.backgroundMiddle && (e -= 2 * this.edgePixelsX,
  1076. this.backgroundLeft.linkedControl.style.bottom = d + "px",
  1077. this.backgroundMiddle.linkedControl.style.bottom = d + "px",
  1078. this.backgroundRight.linkedControl.style.bottom = d + "px",
  1079. this.backgroundLeft.linkedControl.style.height = a + "px",
  1080. this.backgroundMiddle.linkedControl.style.height = a + "px",
  1081. this.backgroundRight.linkedControl.style.height = a + "px",
  1082. this.backgroundLeft.linkedControl.style.width = this.edgePixelsX + "px",
  1083. this.backgroundMiddle.linkedControl.style.width = e + "px",
  1084. this.backgroundRight.linkedControl.style.width = this.edgePixelsX + "px",
  1085. this.backgroundLeft.linkedControl.style.left = c + "px",
  1086. c += this.edgePixelsX,
  1087. this.backgroundMiddle.linkedControl.style.left = c + "px",
  1088. this.backgroundRight.linkedControl.style.left = c + e + "px")
  1089. }
  1090. ;
  1091. Button.prototype.setOpacity = function(a) {
  1092. this.controlRect.linkedControl.style.opacity = a;
  1093. this.backgroundLeft && (this.backgroundLeft.linkedControl.style.opacity = a);
  1094. this.backgroundRight && (this.backgroundRight.linkedControl.style.opacity = a);
  1095. this.backgroundMiddle && (this.backgroundMiddle.linkedControl.style.opacity = a);
  1096. this.backgroundTopLeft && (this.backgroundTopLeft.linkedControl.style.opacity = a);
  1097. this.backgroundTopRight && (this.backgroundTopRight.linkedControl.style.opacity = a);
  1098. this.backgroundTopMiddle && (this.backgroundTopMiddle.linkedControl.style.opacity = a);
  1099. this.backgroundMiddleLeft && (this.backgroundMiddleLeft.linkedControl.style.opacity = a);
  1100. this.backgroundMiddleRight && (this.backgroundMiddleRight.linkedControl.style.opacity = a);
  1101. this.backgroundMiddleMiddle && (this.backgroundMiddleMiddle.linkedControl.style.opacity = a);
  1102. this.backgroundBottomLeft && (this.backgroundBottomLeft.linkedControl.style.opacity = a);
  1103. this.backgroundBottomRight && (this.backgroundBottomRight.linkedControl.style.opacity = a);
  1104. this.backgroundBottomMiddle && (this.backgroundBottomMiddle.linkedControl.style.opacity = a)
  1105. }
  1106. ;
  1107. Button.prototype.setBackgroundVisible = function(a) {
  1108. this.backgroundLeft && this.backgroundLeft.showControl(a);
  1109. this.backgroundRight && this.backgroundRight.showControl(a);
  1110. this.backgroundMiddle && this.backgroundMiddle.showControl(a);
  1111. this.backgroundTopLeft && this.backgroundTopLeft.showControl(a);
  1112. this.backgroundTopRight && this.backgroundTopRight.showControl(a);
  1113. this.backgroundTopMiddle && this.backgroundTopMiddle.showControl(a);
  1114. this.backgroundMiddleLeft && this.backgroundMiddleLeft.showControl(a);
  1115. this.backgroundMiddleRight && this.backgroundMiddleRight.showControl(a);
  1116. this.backgroundMiddleMiddle && this.backgroundMiddleMiddle.showControl(a);
  1117. this.backgroundBottomLeft && this.backgroundBottomLeft.showControl(a);
  1118. this.backgroundBottomRight && this.backgroundBottomRight.showControl(a);
  1119. this.backgroundBottomMiddle && this.backgroundBottomMiddle.showControl(a)
  1120. }
  1121. ;
  1122. Button.prototype.setVisible = function(a) {
  1123. this.controlRect.showControl(a);
  1124. this.setBackgroundVisible(a)
  1125. }
  1126. ;
  1127. Button.prototype.linkControl = function(a) {
  1128. this.controlRect.linkedControl = a;
  1129. a.onmouseover = function() {
  1130. this.updateAlphas && (this.setOpacity(this.focusAlpha),
  1131. this.controlRect.mouseOver = !0,
  1132. this.linkedBackground && this.linkedBackground.setOpacity(this.focusAlpha))
  1133. }
  1134. .bind(this);
  1135. a.onmouseout = function() {
  1136. this.updateAlphas && (this.setOpacity(this.defaultAlpha),
  1137. this.controlRect.mouseOver = !1,
  1138. this.linkedBackground && this.linkedBackground.setOpacity(this.defaultAlpha))
  1139. }
  1140. .bind(this)
  1141. }
  1142. ;
  1143. function ByteStream(a) {
  1144. this.bytes = new Uint8Array(a)
  1145. }
  1146. ByteStream.prototype.empty = function() {
  1147. return 0 >= this.bytes.length
  1148. }
  1149. ;
  1150. ByteStream.prototype.readCString = function() {
  1151. for (var a = this.bytes, b = a.length, c = 0; c < b; ++c)
  1152. if (0 == a[c])
  1153. return a = String.fromCharCode.apply(null, this.bytes.subarray(0, c)),
  1154. this.bytes = this.bytes.subarray(c + 1),
  1155. a;
  1156. return null
  1157. }
  1158. ;
  1159. ByteStream.prototype.asString = function() {
  1160. for (var a = "", b = 0; b < this.bytes.length; ++b)
  1161. a += String.fromCharCode(this.bytes[b]);
  1162. return a
  1163. }
  1164. ;
  1165. ByteStream.prototype.readBytes = function(a) {
  1166. var b = this.bytes.subarray(0, a);
  1167. this.bytes = this.bytes.subarray(a);
  1168. return b
  1169. }
  1170. ;
  1171. ByteStream.prototype.readUint32 = function() {
  1172. var a = this.bytes
  1173. , b = a[0] | a[1] << 8 | a[2] << 16 | a[3] << 24;
  1174. this.bytes = a.subarray(4);
  1175. return b
  1176. }
  1177. ;
  1178. ByteStream.prototype.readUint8 = function() {
  1179. var a = this.bytes
  1180. , b = a[0];
  1181. this.bytes = a.subarray(1);
  1182. return b
  1183. }
  1184. ;
  1185. ByteStream.prototype.readUint16 = function() {
  1186. var a = this.bytes
  1187. , b = a[0] | a[1] << 8;
  1188. this.bytes = a.subarray(2);
  1189. return b
  1190. }
  1191. ;
  1192. ByteStream.prototype.readFloat32 = function() {
  1193. var a = new Uint8Array(this.bytes)
  1194. , a = new Float32Array(a.buffer);
  1195. this.bytes = this.bytes.subarray(4);
  1196. return a[0]
  1197. }
  1198. ;
  1199. ByteStream.prototype.seekUint32 = function(a) {
  1200. a = this.bytes.subarray(4 * a);
  1201. return a[0] | a[1] << 8 | a[2] << 16 | a[3] << 24
  1202. }
  1203. ;
  1204. ByteStream.prototype.seekFloat32 = function(a) {
  1205. a = new Uint8Array(this.bytes.subarray(4 * a));
  1206. return (new Float32Array(a.buffer))[0]
  1207. }
  1208. ;
  1209. ByteStream.prototype.getMatrix = function(a) {
  1210. return new Float32Array(this.bytes.buffer,64 * a,16)
  1211. }
  1212. ;
  1213. function ControlRect(a) {
  1214. this.name = "none";
  1215. this.title = "frame";
  1216. this.yPercent = this.xPercent = 0;
  1217. this.heightPercent = this.widthPercent = 1;
  1218. this.debugString = "";
  1219. this.parentControlRect = 0;
  1220. this.childControlRects = [];
  1221. this.clicked = this.mouseDown = this.mouseOver = !1;
  1222. this.localMouseYPercent = this.localMouseXPercent = 0;
  1223. this.enabled = this.visible = !0;
  1224. this.opacity = 1;
  1225. this.guiScreen = a;
  1226. this.id = this.callBack = this.linkedControl = 0
  1227. }
  1228. ControlRect.prototype.getScreenWidth = function() {
  1229. if (this.linkedControl)
  1230. return this.guiScreen.width * this.getScreenWidthPercent()
  1231. }
  1232. ;
  1233. ControlRect.prototype.getScreenHeight = function() {
  1234. if (this.linkedControl)
  1235. return this.guiScreen.height * this.getScreenHeightPercent()
  1236. }
  1237. ;
  1238. ControlRect.prototype.updateElement = function() {
  1239. var a = this.linkedControl;
  1240. if (a) {
  1241. var b = this.guiScreen.left * (1 - this.getScreenXPercent())
  1242. , c = this.guiScreen.bottom * (1 - this.getScreenYPercent())
  1243. , d = this.guiScreen.width * this.getScreenWidthPercent()
  1244. , e = this.guiScreen.height * this.getScreenHeightPercent();
  1245. a.style.left = b + "px";
  1246. a.style.bottom = c + "px";
  1247. a.style.width = d + "px";
  1248. a.style.height = e + "px"
  1249. }
  1250. }
  1251. ;
  1252. ControlRect.prototype.updateElement = function() {
  1253. var a = this.linkedControl;
  1254. if (a) {
  1255. var b = this.guiScreen.left * (1 - this.getScreenXPercent())
  1256. , c = this.guiScreen.bottom * (1 - this.getScreenYPercent())
  1257. , d = this.guiScreen.width * this.getScreenWidthPercent()
  1258. , e = this.guiScreen.height * this.getScreenHeightPercent();
  1259. a.style.left = b + "px";
  1260. a.style.bottom = c + "px";
  1261. a.style.width = d + "px";
  1262. a.style.height = e + "px"
  1263. }
  1264. }
  1265. ;
  1266. ControlRect.prototype.updateChildElements = function() {
  1267. this.updateElement();
  1268. for (var a = 0; a < this.childControlRects.length; a++)
  1269. this.childControlRects[a].updateChildElements()
  1270. }
  1271. ;
  1272. ControlRect.prototype.set = function(a, b, c, d) {
  1273. this.xPercent = a;
  1274. this.yPercent = b;
  1275. this.widthPercent = c;
  1276. this.heightPercent = d
  1277. }
  1278. ;
  1279. ControlRect.prototype.linkControl = function(a) {
  1280. this.linkedControl = a;
  1281. a.onmouseover = function() {
  1282. this.mouseOver = !0
  1283. }
  1284. .bind(this);
  1285. a.onmouseout = function() {
  1286. this.mouseOver = !1
  1287. }
  1288. .bind(this);
  1289. a.onmousedown = function() {
  1290. this.mouseDown = !0
  1291. }
  1292. .bind(this);
  1293. a.onmouseup = function() {
  1294. this.mouseDown = !1
  1295. }
  1296. .bind(this);
  1297. a.onclick = function() {
  1298. this.callBack && this.callBack(this);
  1299. this.clicked = !0
  1300. }
  1301. .bind(this)
  1302. }
  1303. ;
  1304. ControlRect.prototype.showControl = function(a) {
  1305. this.visible = a;
  1306. this.linkedControl && (this.linkedControl.style.display = a ? "block" : "none")
  1307. }
  1308. ;
  1309. ControlRect.prototype.setOpacity = function(a) {
  1310. this.opacity = a;
  1311. this.linkedControl && (this.linkedControl.style.opacity = a)
  1312. }
  1313. ;
  1314. ControlRect.prototype.hasChildControlRect = function(a) {
  1315. for (var b = 0; b < this.childControlRects.length; b++)
  1316. if (this.childControlRects[b] == a)
  1317. return !0;
  1318. return !1
  1319. }
  1320. ;
  1321. ControlRect.prototype.registerChildControlRect = function(a) {
  1322. this.hasChildControlRect(a) || (this.childControlRects.push(a),
  1323. a.parentControlRect = this)
  1324. }
  1325. ;
  1326. ControlRect.prototype.getScreenWidthPercent = function() {
  1327. var a = this.widthPercent;
  1328. this.parentControlRect && (a *= this.parentControlRect.getScreenWidthPercent());
  1329. return a
  1330. }
  1331. ;
  1332. ControlRect.prototype.getScreenHeightPercent = function() {
  1333. var a = this.heightPercent;
  1334. this.parentControlRect && (a *= this.parentControlRect.getScreenHeightPercent());
  1335. return a
  1336. }
  1337. ;
  1338. ControlRect.prototype.getScreenXPercent = function() {
  1339. var a = this.xPercent;
  1340. this.parentControlRect && (a *= this.parentControlRect.getScreenWidthPercent(),
  1341. a += this.parentControlRect.getScreenXPercent());
  1342. return a
  1343. }
  1344. ;
  1345. ControlRect.prototype.getScreenYPercent = function() {
  1346. var a = this.yPercent;
  1347. this.parentControlRect && (a *= this.parentControlRect.getScreenHeightPercent(),
  1348. a += this.parentControlRect.getScreenYPercent());
  1349. return a
  1350. }
  1351. ;
  1352. var prepareEmbedParams = function(a) {
  1353. a = a || {};
  1354. if (document.location.search)
  1355. for (var b = document.location.search.substring(1).split("&"), c = 0; c < b.length; ++c) {
  1356. var d = b[c].split("=");
  1357. a[d[0]] = d[1]
  1358. }
  1359. b = function(a) {
  1360. if (a | 0)
  1361. return !0;
  1362. for (var c = "true True TRUE yes Yes YES".split(" "), b = 0; b < c.length; ++b)
  1363. if (a === c[b])
  1364. return !0;
  1365. return !1
  1366. }
  1367. ;
  1368. a.width = a.width || 800;
  1369. a.height = a.height || 600;
  1370. a.autoStart = b(a.autoStart);
  1371. a.pagePreset = b(a.pagePreset);
  1372. a.fullFrame = b(a.fullFrame) || b(a.bare);
  1373. a.fullFrame = !a.pagePreset && a.fullFrame;
  1374. return a
  1375. }
  1376. , embed = function(a, b) {
  1377. var c;
  1378. b = prepareEmbedParams(b);
  1379. var d = b.thumbnailURL;
  1380. if (b.pagePreset) {
  1381. c = new WebViewer(b.width,b.height,a,!!d);
  1382. document.body.style.backgroundColor = "#d7e4da";
  1383. var e = document.createElement("div");
  1384. e.id = 'main'; //xst
  1385. e.style.position = "relative";
  1386. e.style.backgroundColor = "#e4e7e4";
  1387. e.style.width = b.width + 12 + "px";
  1388. e.style.height = b.height + 6 + 16 + "px";
  1389. e.style.margin = "auto";
  1390. e.style.boxShadow = "3px 5px 12px 0px grey";
  1391. document.body.appendChild(e);
  1392. var f = document.createElement("div");
  1393. f.style.position = "relative";
  1394. f.style.left = "6px";
  1395. f.style.top = "6px";
  1396. e.appendChild(f);
  1397. f.appendChild(c.domRoot);
  1398. if (!c.mobile) {
  1399. e.style.resize = "both";
  1400. e.style.overflow = "hidden";
  1401. var g = [e.style.width, e.style.height]
  1402. , h = function() {
  1403. if (FullScreen.active())
  1404. e.style.resize = "none";
  1405. else if (e.style.resize = "both",
  1406. g[0] != e.style.width || g[1] != e.style.height)
  1407. g[0] = e.style.width,
  1408. g[1] = e.style.height,
  1409. c.resize(e.clientWidth - 12, e.clientHeight - 6 - 16);
  1410. window.setTimeout(h, 100)
  1411. };
  1412. h()
  1413. }
  1414. } else
  1415. c = new WebViewer(b.fullFrame ? window.innerWidth : b.width,b.fullFrame ? window.innerHeight : b.height,a,!!d, b.domRoot),//改
  1416. //document.body.appendChild(c.domRoot),
  1417. b.fullFrame && (c.domRoot.style.position = "absolute",
  1418. c.domRoot.style.left = c.domRoot.style.top = 0,
  1419. window.addEventListener("resize", function() {
  1420. FullScreen.active() || c.resize(window.innerWidth, window.innerHeight)
  1421. }));
  1422. window.webview = c;//xzw add
  1423. c.ui.setThumbnailURL(d);
  1424. b.autoStart && c.loadScene();
  1425. return c
  1426. }
  1427. , fetchThumbnail = function(a, b, c, d) {
  1428. var e = !1
  1429. , f = a + (-1 == a.indexOf("?") ? "?" : "&") + "thumb=1"
  1430. , g = function(a) {
  1431. (a = (new Archive(a)).extract("thumbnail.jpg")) ? TextureCache.parseFile(a, b, d) : e ? c && c() : (e = !0,
  1432. Network.fetchBinaryIncremental(f, g, c, 394240));
  1433. return 0
  1434. };
  1435. Network.fetchBinaryIncremental(f, g, c, 65536)
  1436. }
  1437. , fdage = "undefined" == typeof fdage ? {} : fdage;
  1438. fdage.embed = embed;
  1439. fdage.fetchThumbnail = fetchThumbnail;
  1440. function Fog(a, b) {
  1441. this.desc = b;
  1442. this.gl = a;
  1443. this.iblShader = a.shaderCache.fromURLs("fogvert.glsl", "fogfrag.glsl", ["#define FOG_IBL"]);
  1444. var c = ["#define FOG_DIR"];
  1445. this.dirShader = a.shaderCache.fromURLs("fogvert.glsl", "fogfrag.glsl", c);
  1446. c.push("#define FOG_SHADOWS");
  1447. this.dirShaderShadow = a.shaderCache.fromURLs("fogvert.glsl", "fogfrag.glsl", c);
  1448. c = ["#define FOG_SPOT"];
  1449. this.spotShader = a.shaderCache.fromURLs("fogvert.glsl", "fogfrag.glsl", c);
  1450. c.push("#define FOG_SHADOWS");
  1451. this.spotShaderShadow = a.shaderCache.fromURLs("fogvert.glsl", "fogfrag.glsl", c);
  1452. c = ["#define FOG_OMNI"];
  1453. this.omniShaderShadow = this.omniShader = a.shaderCache.fromURLs("fogvert.glsl", "fogfrag.glsl", c);
  1454. this.fullscreenTriangle = a.createBuffer();
  1455. a.bindBuffer(a.ARRAY_BUFFER, this.fullscreenTriangle);
  1456. c = new Float32Array([0, 0, 2, 0, 0, 2]);
  1457. a.bufferData(a.ARRAY_BUFFER, c, a.STATIC_DRAW);
  1458. a.bindBuffer(a.ARRAY_BUFFER, null)
  1459. }
  1460. Fog.prototype.draw = function(a, b) {
  1461. var c = this.gl
  1462. , d = a.view
  1463. , e = d.projectionMatrix
  1464. , f = Matrix.empty();
  1465. Matrix.mul(f, d.viewMatrix, d.projectionMatrix);
  1466. Matrix.invert(f, d.viewProjectionMatrix);
  1467. f = [e[10] + e[11], -e[14], -2 * e[11]];
  1468. e = [-2 / e[0], -2 / e[5], (1 - e[8]) / e[0], (1 - e[9]) / e[5]];
  1469. c.enable(c.BLEND);
  1470. c.blendFunc(c.ONE, c.ONE_MINUS_SRC_ALPHA);
  1471. for (var g = 0; g < a.lights.count + 1; ++g) {
  1472. var h = g - 1, k = h < a.lights.shadowCount, l;
  1473. l = 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;
  1474. l.bind();
  1475. var n = l.params;
  1476. c.uniform3fv(n.uDepthToZ, f);
  1477. c.uniform4fv(n.uUnproject, e);
  1478. c.uniformMatrix4fv(n.uInvViewMatrix, !1, d.transform);
  1479. c.uniform1f(n.uFogInvDistance, 1 / this.desc.distance);
  1480. c.uniform1f(n.uFogOpacity, this.desc.opacity * (1 - a.stripData.activeFade()));
  1481. c.uniform1f(n.uFogDispersion, 1 - this.desc.dispersion);
  1482. var m = [0, 0, 0];
  1483. m[this.desc.type] = 1;
  1484. c.uniform3fv(n.uFogType, m);
  1485. c.uniform3fv(n.uFogColor, this.desc.color);
  1486. c.uniform1f(n.uFogIllum, 0 == g ? this.desc.skyIllum : this.desc.lightIllum);
  1487. c.uniformMatrix4fv(n.uLightMatrix, !1, a.lights.invMatrix);
  1488. if (0 == g) {
  1489. h = new Float32Array(a.sky.diffuseCoefficients);
  1490. for (k = 4; 16 > k; ++k)
  1491. h[k] *= 1 - this.desc.dispersion;
  1492. for (k = 16; 36 > k; ++k)
  1493. h[k] *= 1 - this.desc.dispersion * this.desc.dispersion;
  1494. c.uniform4fv(n.uFogLightSphere, h)
  1495. } else {
  1496. var p = a.lights.getLightPos(h)
  1497. , p = Matrix.mul4(Vect.empty(), a.lights.invMatrix, p[0], p[1], p[2], p[3])
  1498. , m = a.lights.getLightDir(h)
  1499. , m = Matrix.mulVec(Vect.empty(), a.lights.invMatrix, m[0], m[1], m[2]);
  1500. c.uniform4fv(n.uLightPosition, p);
  1501. c.uniform3fv(n.uLightColor, a.lights.getColor(h));
  1502. var p = 0.01745329251 * a.lights.spot[3 * h]
  1503. , r = Math.cos(0.5 * p);
  1504. c.uniform4fv(n.uSpotParams, [-m[0], -m[1], -m[2], 0 < p ? r * r : 0]);
  1505. c.uniform4fv(n.uLightAttenuation, [a.lights.parameters[3 * h + 0], a.lights.parameters[3 * h + 1], a.lights.parameters[3 * h + 2], r]);
  1506. k && (k = Matrix.mul(Matrix.empty(), a.lights.finalTransformBuffer.subarray(16 * h), a.lights.matrix),
  1507. c.uniformMatrix4fv(n.uShadowProj, !1, k),
  1508. a.shadow.depthTextures[h].bind(l.samplers.uShadowMap),
  1509. h = 0,
  1510. 1 < a.postRender.sampleCount && (h = a.postRender.currentSample() / a.postRender.sampleCount),
  1511. c.uniform1f(n.uDitherOffset, h),
  1512. c.uniform3fv(n.uAABBMin, a.bounds.min),
  1513. c.uniform3fv(n.uAABBMax, a.bounds.max),
  1514. h = Vect.lerp(Vect.empty(), a.bounds.min, a.bounds.max, 0.5),
  1515. k = Vect.distance(h, a.bounds.min),
  1516. c.uniform4f(n.uCylinder, h[0], h[1], h[2], k * k))
  1517. }
  1518. b.bind(l.samplers.tDepth);
  1519. l = l.attribs.vCoord;
  1520. c.bindBuffer(c.ARRAY_BUFFER, this.fullscreenTriangle);
  1521. c.enableVertexAttribArray(l);
  1522. c.vertexAttribPointer(l, 2, c.FLOAT, !1, 0, 0);
  1523. c.drawArrays(c.TRIANGLES, 0, 3);
  1524. c.disableVertexAttribArray(l);
  1525. c.bindBuffer(c.ARRAY_BUFFER, null)
  1526. }
  1527. c.disable(c.BLEND)
  1528. }
  1529. ;
  1530. Fog.prototype.complete = function() {
  1531. return this.iblShader.complete() && this.dirShader.complete() && this.dirShaderShadow.complete() && this.spotShader.complete() && this.spotShaderShadow.complete() && this.omniShader.complete() && this.omniShaderShadow.complete()
  1532. }
  1533. ;
  1534. function Framebuffer(a, b) {
  1535. this.gl = a;
  1536. this.fbo = a.createFramebuffer();
  1537. a.bindFramebuffer(a.FRAMEBUFFER, this.fbo);
  1538. b && (this.width = b.width,
  1539. this.height = b.height,
  1540. b.color0 && (this.color0 = b.color0,
  1541. a.framebufferTexture2D(a.FRAMEBUFFER, a.COLOR_ATTACHMENT0, a.TEXTURE_2D, this.color0.id, 0),
  1542. this.width = b.color0.desc.width,
  1543. this.height = b.color0.desc.height),
  1544. b.depth ? (this.depth = b.depth,
  1545. a.framebufferTexture2D(a.FRAMEBUFFER, a.DEPTH_ATTACHMENT, a.TEXTURE_2D, this.depth.id, 0)) : (this.depthBuffer = b.depthBuffer,
  1546. b.createDepth && !this.depthBuffer && (this.depthBuffer = Framebuffer.createDepthBuffer(a, this.width, this.height)),
  1547. this.depthBuffer && (a.bindRenderbuffer(a.RENDERBUFFER, this.depthBuffer),
  1548. a.framebufferRenderbuffer(a.FRAMEBUFFER, a.DEPTH_ATTACHMENT, a.RENDERBUFFER, this.depthBuffer),
  1549. a.bindRenderbuffer(a.RENDERBUFFER, null))));
  1550. this.valid = b && b.ignoreStatus || a.checkFramebufferStatus(a.FRAMEBUFFER) == a.FRAMEBUFFER_COMPLETE;
  1551. a.bindFramebuffer(a.FRAMEBUFFER, null)
  1552. }
  1553. Framebuffer.createDepthBuffer = function(a, b, c) {
  1554. var d = a.createRenderbuffer();
  1555. a.bindRenderbuffer(a.RENDERBUFFER, d);
  1556. a.renderbufferStorage(a.RENDERBUFFER, a.DEPTH_COMPONENT16, b, c);
  1557. a.bindRenderbuffer(a.RENDERBUFFER, null);
  1558. return d
  1559. }
  1560. ;
  1561. Framebuffer.prototype.bind = function() {
  1562. this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, this.fbo);
  1563. this.gl.viewport(0, 0, this.width, this.height)
  1564. }
  1565. ;
  1566. Framebuffer.bindNone = function(a) {
  1567. a.bindFramebuffer(a.FRAMEBUFFER, null)
  1568. }
  1569. ;
  1570. var FullScreen = {
  1571. support: function() {
  1572. return !!(document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled)
  1573. },
  1574. begin: function(a, b) {
  1575. var c = a.requestFullscreen || a.webkitRequestFullScreen || a.mozRequestFullScreen || a.msRequestFullscreen;
  1576. if (c) {
  1577. var d = function() {
  1578. FullScreen.active() || (document.removeEventListener("fullscreenchange", d),
  1579. document.removeEventListener("webkitfullscreenchange", d),
  1580. document.removeEventListener("mozfullscreenchange", d),
  1581. document.removeEventListener("MSFullscreenChange", d));
  1582. b && b()
  1583. };
  1584. document.addEventListener("fullscreenchange", d);
  1585. document.addEventListener("webkitfullscreenchange", d);
  1586. document.addEventListener("mozfullscreenchange", d);
  1587. document.addEventListener("MSFullscreenChange", d);
  1588. c.bind(a)()
  1589. }
  1590. },
  1591. end: function() {
  1592. var a = document.exitFullscreen || document.webkitExitFullscreen || document.mozCancelFullScreen || document.msExitFullscreen;
  1593. a && a.bind(document)()
  1594. },
  1595. active: function() {
  1596. return !!(document.fullscreenElement || document.webkitIsFullScreen || document.mozFullScreenElement || document.msFullscreenElement)
  1597. }
  1598. };
  1599. function GUIManager(a) {
  1600. this.init = !1;
  1601. this.ui = a;
  1602. this.bottom = this.left = this.height = this.width = 0;
  1603. this.clicked = this.mouseDown = !1;
  1604. this.playbackControls = 0;
  1605. a = 1;
  1606. window.devicePixelRatio && (2 < window.devicePixelRatio ? a = 4 : 1 < window.devicePixelRatio && (a = 2));
  1607. this.imageSetNumber = a
  1608. }
  1609. GUIManager.prototype.setSize = function(a, b) {
  1610. this.width = a;
  1611. this.height = b;
  1612. this.left = -a;
  1613. this.bottom = -b;
  1614. this.playbackControls && this.playbackControls.resize(this)
  1615. }
  1616. ;
  1617. GUIManager.prototype.setupActiveView = function(a) {
  1618. this.init || (this.init = !0,
  1619. this.ui = a,
  1620. a.viewer.scene.sceneAnimator && (this.playbackControls = new PlaybackControls(this),
  1621. this.playbackControls.resize(this)))
  1622. }
  1623. ;
  1624. GUIManager.prototype.updateElement = function(a) {
  1625. var b = a.linkedControl;
  1626. if (b) {
  1627. var c = this.left * (1 - a.getScreenXPercent())
  1628. , d = this.bottom * (1 - a.getScreenYPercent())
  1629. , e = this.width * a.getScreenWidthPercent();
  1630. a = this.height * a.getScreenHeightPercent();
  1631. b.style.left = c + "px";
  1632. b.style.bottom = d + "px";
  1633. b.style.width = e + "px";
  1634. b.style.height = a + "px"
  1635. }
  1636. }
  1637. ;
  1638. function GUIRegion(a) {
  1639. this.debugString = "GUIRegion";
  1640. this.name = "Default";
  1641. this.controlRect = new ControlRect(a);
  1642. this.yPercent = this.xPercent = 0;
  1643. this.heightPercent = this.widthPercent = 1;
  1644. this.guiScreen = a
  1645. }
  1646. GUIRegion.prototype.addImageElement = function(a, b) {
  1647. var c = this.guiScreen.ui.menuCluster.contents
  1648. , d = document.createElement("input");
  1649. a.linkControl(d);
  1650. this.guiScreen.updateElement(a);
  1651. d.type = "image";
  1652. d.src = fdage.dataLocale + b;
  1653. d.style.position = "absolute";
  1654. d.style.border = "none";
  1655. d.style.outline = "0px";
  1656. d.style.zIndex = "1";
  1657. d.title = b;
  1658. d.style.opacity = a.opacity;
  1659. var e = new XMLHttpRequest;
  1660. e.open("HEAD", d.src, !0);
  1661. e.onload = function(a) {
  1662. a.appendChild(this)
  1663. }
  1664. .bind(d, c);
  1665. e.send();
  1666. return d
  1667. }
  1668. ;
  1669. GUIRegion.prototype.addImage = function(a) {
  1670. var b = new ControlRect(this.guiScreen);
  1671. this.addImageElement(b, a);
  1672. return b
  1673. }
  1674. ;
  1675. GUIRegion.prototype.addTextButton = function(a, b, c, d, e, f) {
  1676. var g = new Button(this.guiScreen);
  1677. g.name = "none";
  1678. g.text = a;
  1679. g.controlRect.set(b, c, d, e);
  1680. g.controlRect.opacity = f;
  1681. this.controlRect.registerChildControlRect(g.controlRect);
  1682. b = this.guiScreen.ui.menuCluster.contents;
  1683. c = document.createElement("text");
  1684. c.style.color = "white";
  1685. c.style.fontFamily = "Arial";
  1686. c.style.fontSize = fdage.largeUI ? "14px" : "12px";
  1687. c.style.textShadow = "2px 2px 3px #000000";
  1688. b.appendChild(c);
  1689. g.controlRect.linkControl(c);
  1690. this.guiScreen.updateElement(g.controlRect);
  1691. c.type = "text";
  1692. c.name = "text";
  1693. c.style.position = "absolute";
  1694. c.style.border = "none";
  1695. c.style.outline = "0px";
  1696. c.style.zIndex = "2";
  1697. c.innerHTML = a;
  1698. c.style.opacity = g.controlRect.opacity;
  1699. g.linkControl(c);
  1700. return g
  1701. }
  1702. ;
  1703. function GUIScreen(a) {
  1704. this.init = !1;
  1705. this.ui = a;
  1706. this.bottom = this.left = this.height = this.width = 0;
  1707. this.clicked = this.mouseDown = !1;
  1708. this.playbackControls = 0;
  1709. a = 1;
  1710. window.devicePixelRatio && (2 < window.devicePixelRatio ? a = 4 : 1 < window.devicePixelRatio && (a = 2));
  1711. this.imageSetNumber = a
  1712. }
  1713. GUIScreen.prototype.setSize = function(a, b) {
  1714. this.width = a;
  1715. this.height = b;
  1716. this.left = -a;
  1717. this.bottom = -b;
  1718. this.playbackControls && this.playbackControls.resize(this)
  1719. }
  1720. ;
  1721. GUIScreen.prototype.setupActiveView = function(a) {
  1722. this.init || (this.init = !0,
  1723. this.ui = a,
  1724. a.viewer.scene.sceneAnimator && (this.playbackControls = new PlaybackControls(this),
  1725. this.playbackControls.resize(this)))
  1726. }
  1727. ;
  1728. GUIScreen.prototype.updateElement = function(a) {
  1729. var b = a.linkedControl;
  1730. if (b) {
  1731. var c = this.left * (1 - a.getScreenXPercent())
  1732. , d = this.bottom * (1 - a.getScreenYPercent())
  1733. , e = this.width * a.getScreenWidthPercent();
  1734. a = this.height * a.getScreenHeightPercent();
  1735. b.style.left = c + "px";
  1736. b.style.bottom = d + "px";
  1737. b.style.width = e + "px";
  1738. b.style.height = a + "px"
  1739. }
  1740. }
  1741. ;
  1742. function Input(a) {
  1743. this.onTap = [];
  1744. this.onSingleTap = [];
  1745. this.onDoubleTap = [];
  1746. this.onDrag = [];
  1747. this.onZoom = [];
  1748. this.onPan = [];
  1749. this.onPan2 = [];
  1750. this.onAnything = [];
  1751. this.mouseDownCount = 0;
  1752. this.macHax = 0 <= navigator.platform.toUpperCase().indexOf("MAC");
  1753. a && this.attach(a)
  1754. }
  1755. Input.prototype.attach = function(a) {
  1756. this.element = a;
  1757. var b = function(a) {
  1758. for (var b = 0; b < this.onAnything.length; ++b)
  1759. this.onAnything[b]();
  1760. a.preventDefault()
  1761. }
  1762. .bind(this);
  1763. this.mouseStates = [{
  1764. pressed: !1,
  1765. position: [0, 0],
  1766. downPosition: [0, 0]
  1767. }, {
  1768. pressed: !1,
  1769. position: [0, 0],
  1770. downPosition: [0, 0]
  1771. }, {
  1772. pressed: !1,
  1773. position: [0, 0],
  1774. downPosition: [0, 0]
  1775. }];
  1776. this.lastTapPos = [0, 0];
  1777. a = function(a) {
  1778. if (a.target === this.element) {
  1779. this.mouseDownCount++;
  1780. var d = this.mouseStates[a.button];
  1781. if (d) {
  1782. d.pressed = !0;
  1783. var e = this.element.getBoundingClientRect();
  1784. d.position[0] = d.downPosition[0] = a.clientX - e.left;
  1785. d.position[1] = d.downPosition[1] = a.clientY - e.top;
  1786. b(a)
  1787. }
  1788. }
  1789. }
  1790. .bind(this);
  1791. this.element.addEventListener("mousedown", a);
  1792. a = function(a) {
  1793. var d = this.mouseStates[a.button];
  1794. if (d) {
  1795. var e = this.element.getBoundingClientRect()
  1796. , f = a.clientX - e.left
  1797. , e = a.clientY - e.top;
  1798. d.pressed = !1;
  1799. d.position[0] = f;
  1800. d.position[1] = e;
  1801. 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])) {
  1802. for (var g = 0; g < this.onTap.length; ++g)
  1803. this.onTap[g](f, e);
  1804. this.needSingleClick = !0;
  1805. window.setTimeout(function(a, c) {
  1806. if (this.needSingleClick) {
  1807. for (var b = 0; b < this.onSingleTap.length; ++b)
  1808. this.onSingleTap[b](a, c);
  1809. this.needSingleClick = !1
  1810. }
  1811. }
  1812. .bind(this, f, e), 301);
  1813. d = !1;
  1814. if (void 0 !== this.doubleClickTimer && (g = 8 > Math.abs(f - this.lastTapPos[0]) + Math.abs(e - this.lastTapPos[1]),
  1815. 300 > Date.now() - this.doubleClickTimer && g))
  1816. for (d = !0,
  1817. this.needSingleClick = !1,
  1818. g = 0; g < this.onDoubleTap.length; ++g)
  1819. this.onDoubleTap[g](f, e);
  1820. this.doubleClickTimer = Date.now();
  1821. d && (this.doubleClickTimer = -1E9);
  1822. this.lastTapPos[0] = f;
  1823. this.lastTapPos[1] = e
  1824. }
  1825. }
  1826. b(a)
  1827. }
  1828. .bind(this);
  1829. this.element.addEventListener("mouseup", a);
  1830. a = function(a) {
  1831. for (var d = !1, e = this.element.getBoundingClientRect(), f = 0; 3 > f; ++f) {
  1832. var g = this.mouseStates[f];
  1833. if (g.pressed) {
  1834. var d = a.clientX - e.left
  1835. , h = a.clientY - e.top
  1836. , k = d - g.position[0]
  1837. , l = h - g.position[1];
  1838. g.position[0] = d;
  1839. g.position[1] = h;
  1840. if (2 == f && a.altKey)
  1841. for (g = 0; g < this.onZoom.length; ++g)
  1842. this.onZoom[g](2 * l);
  1843. else if (1 <= f || a.ctrlKey)
  1844. for (g = 0; g < this.onPan.length; ++g)
  1845. this.onPan[g](k, l);
  1846. else if (0 == f)
  1847. if (a.shiftKey)
  1848. for (g = 0; g < this.onPan2.length; ++g)
  1849. this.onPan2[g](k, l);
  1850. else
  1851. for (g = 0; g < this.onDrag.length; ++g)
  1852. this.onDrag[g](d, h, k, l);
  1853. d = !0
  1854. }
  1855. }
  1856. d && b(a)
  1857. }
  1858. .bind(this);
  1859. this.element.addEventListener("mousemove", a);
  1860. a = function(a) {
  1861. var d = 0;
  1862. a.deltaY ? (d = -0.4 * a.deltaY,
  1863. 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);
  1864. for (var e = 0; e < this.onZoom.length; ++e)
  1865. this.onZoom[e](d);
  1866. b(a)
  1867. }.bind(this);
  1868. this.element.addEventListener("mousewheel", a);
  1869. this.element.addEventListener("DOMMouseScroll", a);
  1870. this.element.addEventListener("wheel", a);
  1871. a = function(a) {
  1872. for (var b = 0; b < this.mouseStates.length; ++b)
  1873. this.mouseStates[b].pressed = !1;
  1874. a.preventDefault()
  1875. }
  1876. .bind(this);
  1877. this.element.addEventListener("mouseleave", a);
  1878. this.element.addEventListener("contextmenu", function(a) {
  1879. a.preventDefault()
  1880. });
  1881. this.touches = {};
  1882. this.tapPossible = !1;
  1883. this.touchCountFloor = 0;
  1884. a = function(a) {
  1885. for (var d = this.element.getBoundingClientRect(), e = !1, f = 0; f < a.changedTouches.length; ++f)
  1886. if (a.target === this.element) {
  1887. var g = a.changedTouches[f]
  1888. , e = {
  1889. x: g.clientX - d.left,
  1890. y: g.clientY - d.top
  1891. };
  1892. e.startX = e.x;
  1893. e.startY = e.y;
  1894. this.touches[g.identifier] = e;
  1895. e = !0
  1896. }
  1897. this.tapPossible = 1 == a.touches.length;
  1898. for (g = d = 0; g < this.touches.length; ++g)
  1899. d++;
  1900. d > this.touchCountFloor && (this.touchCountFloor = d);
  1901. e && b(a)
  1902. }
  1903. .bind(this);
  1904. this.element.addEventListener("touchstart", a);
  1905. a = function(a) {
  1906. for (var d = !1, e = 0; e < a.changedTouches.length; ++e) {
  1907. var f = a.changedTouches[e]
  1908. , g = this.touches[f.identifier];
  1909. if (g) {
  1910. if (this.tapPossible) {
  1911. var h = this.element.getBoundingClientRect()
  1912. , d = f.clientX - h.left
  1913. , h = f.clientY - h.top;
  1914. if (24 > Math.max(Math.abs(d - g.startX), Math.abs(h - g.startY))) {
  1915. for (e = 0; e < this.onTap.length; ++e)
  1916. this.onTap[e](d, h);
  1917. this.needSingleTap = !0;
  1918. window.setTimeout(function(a, b) {
  1919. if (this.needSingleTap) {
  1920. for (var c = 0; c < this.onSingleTap.length; ++c)
  1921. this.onSingleTap[c](a, b);
  1922. this.needSingleTap = !1
  1923. }
  1924. }
  1925. .bind(this, d, h), 501);
  1926. g = !1;
  1927. if (void 0 !== this.doubleTapTimer) {
  1928. var k = 24 > Math.max(Math.abs(d - this.lastTapPos[0]), Math.abs(h - this.lastTapPos[1]))
  1929. , l = 500 > Date.now() - this.doubleTapTimer;
  1930. if (k && l)
  1931. for (g = !0,
  1932. e = 0; e < this.onDoubleTap.length; ++e)
  1933. this.onDoubleTap[e](d, h)
  1934. }
  1935. this.doubleTapTimer = Date.now();
  1936. g && (this.doubleTapTimer = -1E9);
  1937. this.lastTapPos[0] = d;
  1938. this.lastTapPos[1] = h
  1939. }
  1940. this.tapPossible = !1
  1941. }
  1942. delete this.touches[f.identifier];
  1943. d = !0
  1944. }
  1945. }
  1946. for (f = e = 0; f < this.touches.length; ++f)
  1947. e++;
  1948. 0 >= e && (this.touchCountFloor = 0);
  1949. d && b(a)
  1950. }
  1951. .bind(this);
  1952. this.element.addEventListener("touchend", a);
  1953. this.element.addEventListener("touchcancel", a);
  1954. this.element.addEventListener("touchleave", a);
  1955. a = function(a) {
  1956. for (var d = [], e = 0; e < a.touches.length; ++e)
  1957. a.touches[e].target === this.element && d.push(a.touches[e]);
  1958. var f = this.element.getBoundingClientRect();
  1959. if (1 == d.length && 1 >= this.touchCountFloor) {
  1960. var g = d[0]
  1961. , h = this.touches[g.identifier];
  1962. if (h) {
  1963. var k = g.clientX - f.left
  1964. , g = g.clientY - f.top
  1965. , f = k - h.x
  1966. , l = g - h.y;
  1967. h.x = k;
  1968. h.y = g;
  1969. for (e = 0; e < this.onDrag.length; ++e)
  1970. this.onDrag[e](k, g, f, l, a.shiftKey)
  1971. }
  1972. } else if (2 == d.length && 2 >= this.touchCountFloor) {
  1973. if (l = d[0],
  1974. e = this.touches[l.identifier],
  1975. g = d[1],
  1976. h = this.touches[g.identifier],
  1977. e && h) {
  1978. var k = l.clientX - f.left
  1979. , l = l.clientY - f.top
  1980. , n = g.clientX - f.left
  1981. , m = g.clientY - f.top
  1982. , p = Math.sqrt((k - n) * (k - n) + (l - m) * (l - m))
  1983. , r = Math.sqrt((e.x - h.x) * (e.x - h.x) + (e.y - h.y) * (e.y - h.y))
  1984. , s = Math.abs(p - r)
  1985. , f = (k - e.x + n - h.x) / 2
  1986. , g = (l - e.y + m - h.y) / 2
  1987. , u = Math.sqrt(f * f + g * g);
  1988. e.x = k;
  1989. e.y = l;
  1990. h.x = n;
  1991. h.y = m;
  1992. if (0 < s)
  1993. for (h = s / (s + u),
  1994. e = 0; e < this.onZoom.length; ++e)
  1995. this.onZoom[e](2 * (p - r) * h);
  1996. if (0 < u)
  1997. for (h = u / (s + u),
  1998. e = 0; e < this.onDrag.length; ++e)
  1999. this.onPan[e](f * h, g * h)
  2000. }
  2001. } else if (3 <= d.length) {
  2002. for (e = r = p = n = l = 0; e < d.length; ++e)
  2003. g = d[e],
  2004. h = this.touches[g.identifier],
  2005. k = g.clientX - f.left,
  2006. g = g.clientY - f.top,
  2007. p += k,
  2008. r += g,
  2009. h && (l += h.x,
  2010. n += h.y,
  2011. h.x = k,
  2012. h.y = g);
  2013. l /= d.length;
  2014. n /= d.length;
  2015. p /= d.length;
  2016. r /= d.length;
  2017. for (e = 0; e < this.onPan2.length; ++e)
  2018. this.onPan2[e](p - l, r - n)
  2019. }
  2020. 0 < d.length && b(a)
  2021. }
  2022. .bind(this);
  2023. this.element.addEventListener("touchmove", a)
  2024. }
  2025. ;
  2026. function KeyFrame(a, b) {
  2027. a && b ? (this.frameIndex = b.frameIndex,
  2028. this.value = b.value,
  2029. this.interpolation = b.interpolation,
  2030. this.weighIn = b.weighIn,
  2031. this.weighOut = b.weighOut) : (this.interpolation = this.value = this.frameIndex = 0,
  2032. this.weighOut = this.weighIn = 1)
  2033. }
  2034. ;function Lights(a, b) {
  2035. this.rotation = this.shadowCount = this.count = 0;
  2036. this.positions = [];
  2037. this.directions = [];
  2038. this.matrixWeights = [];
  2039. this.matrix = Matrix.identity();
  2040. this.invMatrix = Matrix.identity();
  2041. this.defaultmatrix = Matrix.identity();
  2042. this.defaultviewmatrix = Matrix.identity();
  2043. for (var c in a)
  2044. this[c] = a[c];
  2045. this.count = this.positions.length / 4;
  2046. this.count = Math.min(6, this.count);
  2047. this.shadowCount = Math.min(3, this.shadowCount);
  2048. this.positions = new Float32Array(this.positions);
  2049. this.positionBuffer = new Float32Array(this.positions);
  2050. this.directions = new Float32Array(this.directions);
  2051. this.directionBuffer = new Float32Array(this.directions);
  2052. this.colors = new Float32Array(this.colors);
  2053. this.colorsBuffer = new Float32Array(this.colors);
  2054. this.modelViewBuffer = new Float32Array(16 * this.shadowCount);
  2055. this.projectionBuffer = new Float32Array(16 * this.shadowCount);
  2056. this.finalTransformBuffer = new Float32Array(16 * this.shadowCount);
  2057. this.inverseTransformBuffer = new Float32Array(16 * this.shadowCount);
  2058. this.shadowTexelPadProjections = new Float32Array(4 * this.shadowCount);
  2059. this.shadowsNeedUpdate = new Uint8Array(this.shadowCount);
  2060. for (var d = 0; d < this.shadowsNeedUpdate.length; ++d)
  2061. this.shadowsNeedUpdate[d] = 1;
  2062. Matrix.rotation(this.matrix, this.rotation, 1);
  2063. Matrix.transpose(this.invMatrix, this.matrix);
  2064. Matrix.copy(this.defaultmatrix, this.matrix);
  2065. Matrix.copy(this.defaultviewmatrix, b.viewMatrix);
  2066. for (d = 0; d < this.count; ++d) {
  2067. c = this.positions.subarray(4 * d, 4 * d + 4);
  2068. var e = this.directions.subarray(3 * d, 3 * d + 3);
  2069. 1 == this.matrixWeights[d] ? (Matrix.mul4(c, this.matrix, c[0], c[1], c[2], c[3]),
  2070. Matrix.mulVec(e, this.matrix, e[0], e[1], e[2])) : 2 == this.matrixWeights[d] && (Matrix.mul4(c, b.viewMatrix, c[0], c[1], c[2], c[3]),
  2071. Matrix.mulVec(e, b.viewMatrix, e[0], e[1], e[2]))
  2072. }
  2073. }
  2074. Lights.prototype.getLightPos = function(a) {
  2075. return this.positionBuffer.subarray(4 * a, 4 * a + 4)
  2076. }
  2077. ;
  2078. Lights.prototype.setLightDistance = function(a, b) {
  2079. 0 >= b && (b = 1E-5);
  2080. this.parameters[3 * a + 2] = 1 / b
  2081. }
  2082. ;
  2083. Lights.prototype.setLightSpotAngle = function(a, b) {
  2084. 0 >= b && (b = 1E-6);
  2085. this.spot[3 * a] = b;
  2086. var c = Math.sin(3.1415926 / 180 * b / 2);
  2087. this.spot[3 * a + 2] = 1 / (c * c) * this.spot[3 * a + 1]
  2088. }
  2089. ;
  2090. Lights.prototype.setLightSpotSharpness = function(a, b) {
  2091. this.spot[3 * a + 1] = b;
  2092. this.setLightSpotAngle(this.spot[3 * a])
  2093. }
  2094. ;
  2095. Lights.prototype.setLightPos = function(a, b) {
  2096. this.positions[4 * a + 0] = b[0];
  2097. this.positions[4 * a + 1] = b[1];
  2098. this.positions[4 * a + 2] = b[2];
  2099. var c = this.positions.subarray(4 * a, 4 * a + 4);
  2100. 1 == this.matrixWeights[a] ? Matrix.mul4(c, this.defaultmatrix, b[0], b[1], b[2], c[3]) : 2 == this.matrixWeights[a] && Matrix.mul4(c, this.defaultviewmatrix, b[0], b[1], b[2], c[3])
  2101. }
  2102. ;
  2103. Lights.prototype.setLightDir = function(a, b) {
  2104. this.directions[3 * a + 0] = b[0];
  2105. this.directions[3 * a + 1] = b[1];
  2106. this.directions[3 * a + 2] = b[2];
  2107. var c = this.directions.subarray(3 * a, 3 * a + 3);
  2108. 1 == this.matrixWeights[a] ? Matrix.mulVec(c, this.defaultmatrix, b[0], b[1], b[2]) : 2 == this.matrixWeights[a] && Matrix.mulVec(c, this.defaultviewmatrix, b[0], b[1], b[2])
  2109. }
  2110. ;
  2111. Lights.prototype.getLightColor = function(a) {
  2112. return this.colors.subarray(3 * a, 3 * a + 3)
  2113. }
  2114. ;
  2115. Lights.prototype.setLightColor = function(a, b) {
  2116. this.colors[3 * a + 0] = b[0];
  2117. this.colors[3 * a + 1] = b[1];
  2118. this.colors[3 * a + 2] = b[2]
  2119. }
  2120. ;
  2121. Lights.prototype.getLightDir = function(a) {
  2122. return this.directionBuffer.subarray(3 * a, 3 * a + 3)
  2123. }
  2124. ;
  2125. Lights.prototype.getColor = function(a) {
  2126. a *= 3;
  2127. return [this.colors[a], this.colors[a + 1], this.colors[a + 2]]
  2128. }
  2129. ;
  2130. Lights.prototype.update = function(a, b) {
  2131. var c = new Matrix.type(this.matrix);
  2132. Matrix.rotation(this.matrix, this.rotation, 1);
  2133. Matrix.transpose(this.invMatrix, this.matrix);
  2134. for (var d = 0; d < this.count; ++d) {
  2135. var e = this.positions.subarray(4 * d, 4 * d + 4)
  2136. , f = this.directions.subarray(3 * d, 3 * d + 3)
  2137. , g = this.getLightPos(d)
  2138. , h = this.getLightDir(d);
  2139. 1 == this.matrixWeights[d] ? (g[0] = e[0],
  2140. g[1] = e[1],
  2141. g[2] = e[2],
  2142. g[3] = e[3],
  2143. h[0] = f[0],
  2144. h[1] = f[1],
  2145. h[2] = f[2]) : 2 == this.matrixWeights[d] ? (Matrix.mul4(g, a.transform, e[0], e[1], e[2], e[3]),
  2146. Matrix.mulVec(h, a.transform, f[0], f[1], f[2]),
  2147. Matrix.mul4(g, this.matrix, g[0], g[1], g[2], g[3]),
  2148. Matrix.mulVec(h, this.matrix, h[0], h[1], h[2])) : (Matrix.mul4(g, this.matrix, e[0], e[1], e[2], e[3]),
  2149. Matrix.mulVec(h, this.matrix, f[0], f[1], f[2]));
  2150. Vect.normalize(h, h)
  2151. }
  2152. for (var f = new Float32Array(this.finalTransformBuffer), g = Matrix.empty(), h = Matrix.empty(), k = Matrix.empty(), l = Vect.empty(), n = Vect.empty(), m = 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) {
  2153. l = this.getLightPos(d);
  2154. n = this.getLightDir(d);
  2155. 0.99 < Math.abs(n[1]) ? Vect.set(m, 1, 0, 0) : Vect.set(m, 0, 1, 0);
  2156. Vect.cross(p, m, n);
  2157. Vect.normalize(p, p);
  2158. Vect.cross(m, n, p);
  2159. Vect.normalize(m, m);
  2160. Matrix.set(g, p[0], p[1], p[2], -Vect.dot(p, l), m[0], m[1], m[2], -Vect.dot(m, l), n[0], n[1], n[2], -Vect.dot(n, l), 0, 0, 0, 1);
  2161. for (l = 0; 8 > l; ++l)
  2162. e[0] = l & 1 ? b.max[0] : b.min[0],
  2163. e[1] = l & 2 ? b.max[1] : b.min[1],
  2164. e[2] = l & 4 ? b.max[2] : b.min[2],
  2165. Matrix.mulPoint(e, this.matrix, 1.005 * e[0], 1.005 * e[1], 1.005 * e[2]),
  2166. Matrix.mulPoint(e, g, e[0], e[1], e[2]),
  2167. 0 == l ? (r[0] = s[0] = e[0],
  2168. r[1] = s[1] = e[1],
  2169. r[2] = s[2] = e[2]) : (r[0] = Math.min(r[0], e[0]),
  2170. r[1] = Math.min(r[1], e[1]),
  2171. r[2] = Math.min(r[2], e[2]),
  2172. s[0] = Math.max(s[0], e[0]),
  2173. s[1] = Math.max(s[1], e[1]),
  2174. s[2] = Math.max(s[2], e[2]));
  2175. var l = -r[2]
  2176. , n = -s[2]
  2177. , q = this.spot[3 * d];
  2178. 0 < q ? (l = Math.min(l, 1 / this.parameters[3 * d + 2]),
  2179. n = Math.max(0.04 * l, n),
  2180. Matrix.perspective(h, q, 1, n, l),
  2181. d < this.shadowCount && (l = 2 * -Math.tan(0.00872664625 * q),
  2182. this.shadowTexelPadProjections[4 * d + 0] = this.modelViewBuffer[16 * d + 2] * l,
  2183. this.shadowTexelPadProjections[4 * d + 1] = this.modelViewBuffer[16 * d + 6] * l,
  2184. this.shadowTexelPadProjections[4 * d + 2] = this.modelViewBuffer[16 * d + 10] * l,
  2185. this.shadowTexelPadProjections[4 * d + 3] = this.modelViewBuffer[16 * d + 14] * l)) : (Matrix.ortho(h, r[0], s[0], r[1], s[1], n, l),
  2186. d < this.shadowCount && (this.shadowTexelPadProjections[4 * d + 0] = this.shadowTexelPadProjections[4 * d + 1] = this.shadowTexelPadProjections[4 * d + 2] = 0,
  2187. this.shadowTexelPadProjections[4 * d + 3] = Math.max(s[0] - r[0], s[1] - r[1])));
  2188. Matrix.mul(k, h, g);
  2189. Matrix.mul(k, u, k);
  2190. Matrix.copyToBuffer(this.modelViewBuffer, 16 * d, g);
  2191. Matrix.copyToBuffer(this.projectionBuffer, 16 * d, h);
  2192. Matrix.copyToBuffer(this.finalTransformBuffer, 16 * d, k);
  2193. Matrix.invert(k, k);
  2194. Matrix.copyToBuffer(this.inverseTransformBuffer, 16 * d, k)
  2195. }
  2196. e = !1;
  2197. for (d = 0; d < c.length; ++d)
  2198. if (c[d] != this.matrix[d]) {
  2199. e = !0;
  2200. break
  2201. }
  2202. for (d = 0; d < this.shadowCount; d++)
  2203. if (e && 1 == this.matrixWeights[d])
  2204. this.shadowsNeedUpdate[d] = 1;
  2205. else
  2206. for (c = 16 * d; c < 16 * d + 16; ++c)
  2207. if (f[c] != this.finalTransformBuffer[c]) {
  2208. this.shadowsNeedUpdate[d] = 1;
  2209. break
  2210. }
  2211. }
  2212. ;
  2213. Lights.prototype.flagUpdateAnimatedLighting = function() {
  2214. for (var a = 0; a < this.shadowCount; a++)
  2215. this.shadowsNeedUpdate[a] = 1
  2216. }
  2217. ;
  2218. function ListBox(a) {
  2219. this.name = "none";
  2220. this.text = "default text";
  2221. this.title = "none";
  2222. this.debugString = this.imagePath = "";
  2223. this.controlRect = new ControlRect(a);
  2224. this.textEntries = [];
  2225. this.textOffsetsX = [];
  2226. this.textOffsetsY = [];
  2227. this.buttons = [];
  2228. this.listBoxEntryHeight = 20;
  2229. this.selectedItemText = "";
  2230. this.selectedIndex = -1;
  2231. this.localPixelsY = 0;
  2232. this.localPixelsX = 100;
  2233. this.labelPixelDrop = 0;
  2234. this.labelPixelInset = 10;
  2235. this.labelTextHeight = 16;
  2236. this.closed = !1;
  2237. this.defaultButtonText = this.spacerMiddle = this.spacerRight = this.spacerLeft = this.spacerControl = 0;
  2238. this.listBoxButtons = [];
  2239. this.listBoxRegion = new GUIRegion(a);
  2240. this.guiScreen = a;
  2241. this.lastMouseOverIndex = -1;
  2242. this.selectionChangedCallback = 0;
  2243. this.debugString = ""
  2244. }
  2245. ListBox.prototype.linkControl = function(a) {
  2246. this.controlRect.linkControl(a)
  2247. }
  2248. ;
  2249. ListBox.prototype.spawnControl = function(a, b, c, d, e, f) {
  2250. var g = this.guiScreen.imageSetNumber
  2251. , h = "backgroundTopLE" + g + "x.png"
  2252. , k = "backgroundTopM" + g + "x.png"
  2253. , l = "backgroundTopRE" + g + "x.png"
  2254. , n = "backgroundMiddleLE" + g + "x.png"
  2255. , m = "backgroundMiddleM" + g + "x.png"
  2256. , p = "backgroundMiddleRE" + g + "x.png"
  2257. , r = "backgroundBottomLE" + g + "x.png"
  2258. , s = "backgroundBottomM" + g + "x.png"
  2259. , u = "backgroundBottomRE" + g + "x.png"
  2260. , q = 3 * g
  2261. , x = "backgroundLE" + g + "x.png"
  2262. , w = "backgroundM" + g + "x.png"
  2263. , v = "backgroundRE" + g + "x.png"
  2264. , t = 2 * g
  2265. , y = "spacerLE" + g + "x.png"
  2266. , E = "spacerM" + g + "x.png"
  2267. , F = "spacerRE" + g + "x.png"
  2268. , g = 2 * g
  2269. , A = this.controlRect.guiScreen.width
  2270. , B = this.controlRect.guiScreen.height;
  2271. if (e) {
  2272. e = this.textEntries.length;
  2273. var z = c;
  2274. for (c = 0; c < e; c++) {
  2275. var C = 8 * (this.textEntries[c] ? this.textEntries[c].length : 0);
  2276. z < C && (z = C)
  2277. }
  2278. c = z + f
  2279. }
  2280. e = this.textEntries.length + 1;
  2281. f = 1 / e;
  2282. this.localPixelsX = c;
  2283. this.listBoxEntryHeight = d;
  2284. this.localPixelsY = (this.textEntries.length + 1) * this.listBoxEntryHeight;
  2285. c = 8 / this.localPixelsY;
  2286. d = 6 / this.localPixelsX;
  2287. z = 4 / this.localPixelsX;
  2288. C = f - c / 4;
  2289. this.labelTextHeight = fdage.largeUI ? 20 : 16;
  2290. this.labelPixelDrop = (this.listBoxEntryHeight - this.labelTextHeight) / 2;
  2291. this.listBoxRegion.controlRect.widthPercent = this.localPixelsX / A;
  2292. this.listBoxRegion.controlRect.heightPercent = this.localPixelsY / B;
  2293. this.listBoxRegion.controlRect.xPercent = a / A;
  2294. this.listBoxRegion.controlRect.yPercent = b / B;
  2295. this.openBackground = this.listBoxRegion.addTextButton("", 0, 0, 1, 1 + c, 1);
  2296. this.openBackground.setBackground3x3(this.listBoxRegion, 0, 0, h, k, l, n, m, p, r, s, u, q, q);
  2297. this.closedBackground = this.listBoxRegion.addTextButton("", 0, 0, 1, f, 1);
  2298. this.closedBackground.setBackground3x1(this.listBoxRegion, 0, 0, x, w, v, t);
  2299. a = this.labelPixelInset + this.textOffsetsX[0];
  2300. b = this.labelPixelDrop + this.textOffsetsY[0];
  2301. b /= this.localPixelsY;
  2302. a /= this.localPixelsX;
  2303. this.defaultButton = this.listBoxRegion.addTextButton("Selected", a, -b, 1, f, 0.5);
  2304. this.selectedIndex = 0;
  2305. this.defaultButton.controlRect.linkedControl.innerHTML = this.textEntries[this.selectedIndex];
  2306. this.defaultButton.linkedBackground = this.closedBackground;
  2307. this.spacerControl = this.listBoxRegion.addTextButton("", d, C, 1 - (d + z), c, 1);
  2308. this.spacerControl.defaultAlpha = 1;
  2309. this.spacerControl.setBackground3x1(this.listBoxRegion, 0, 0, y, E, F, g);
  2310. this.spacerControl.setVisible(!1);
  2311. this.spacerControl.linkedBackground = this.openBackground;
  2312. for (c = 1; c < e; c++)
  2313. a = this.labelPixelInset + this.textOffsetsX[c - 1],
  2314. b = this.labelPixelDrop + this.textOffsetsY[c - 1] - 4,
  2315. a /= this.localPixelsX,
  2316. b /= this.localPixelsY,
  2317. y = this.listBoxRegion.addTextButton(this.textEntries[c - 1], a, f * c - b, 1 - a, f, 0.5),
  2318. this.listBoxButtons.push(y),
  2319. y.linkedBackground = this.openBackground;
  2320. this.showList(!1);
  2321. this.setupCallbacks()
  2322. }
  2323. ;
  2324. ListBox.prototype.setControl = function(a, b, c, d, e, f) {
  2325. var g = this.controlRect.guiScreen.width
  2326. , h = this.controlRect.guiScreen.height;
  2327. if (e) {
  2328. e = this.textEntries.length;
  2329. for (var k = 0; k < e; k++) {
  2330. var l = 8 * (this.textEntries[k] ? this.textEntries[k].length : 0);
  2331. c < l && (c = l)
  2332. }
  2333. c += f
  2334. }
  2335. this.localPixelsX = c;
  2336. this.listBoxEntryHeight = d;
  2337. this.localPixelsY = (this.textEntries.length + 1) * this.listBoxEntryHeight;
  2338. this.listBoxRegion.controlRect.widthPercent = this.localPixelsX / g;
  2339. this.listBoxRegion.controlRect.heightPercent = this.localPixelsY / h;
  2340. this.listBoxRegion.controlRect.xPercent = a / g;
  2341. this.listBoxRegion.controlRect.yPercent = b / h;
  2342. this.listBoxRegion.controlRect.updateChildElements();
  2343. this.spacerControl.alignBackground();
  2344. this.openBackground.alignBackground();
  2345. this.closedBackground.alignBackground()
  2346. }
  2347. ;
  2348. ListBox.prototype.addItem = function(a, b, c) {
  2349. this.textEntries.push(a);
  2350. this.textOffsetsX.push(b);
  2351. this.textOffsetsY.push(c)
  2352. }
  2353. ;
  2354. ListBox.prototype.showList = function(a) {
  2355. for (var b = this.listBoxButtons.length, c = 0; c < b; c++)
  2356. this.listBoxButtons[c].setVisible(a);
  2357. this.closed = !a;
  2358. this.spacerControl && this.spacerControl.setVisible(a);
  2359. this.openBackground && this.openBackground.setVisible(a);
  2360. this.closedBackground && this.closedBackground.setVisible(!a);
  2361. a ? (this.defaultButton.linkedBackground = this.openBackground,
  2362. this.openBackground.setOpacity(1),
  2363. this.closedBackground.setOpacity(0.5)) : this.defaultButton.linkedBackground = this.closedBackground
  2364. }
  2365. ;
  2366. ListBox.prototype.selectItem = function(a) {
  2367. this.selectedItemText = this.textEntries[a];
  2368. this.selectedIndex = a;
  2369. this.defaultButton.controlRect.linkedControl.innerHTML = this.textEntries[this.selectedIndex];
  2370. a = (this.labelTextHeight - this.listBoxEntryHeight + 3) / this.localPixelsY;
  2371. this.defaultButton.controlRect.xPercent = (this.labelPixelInset + this.textOffsetsX[this.selectedIndex]) / this.localPixelsX;
  2372. this.defaultButton.controlRect.yPercent = a;
  2373. this.defaultButton.controlRect.updateElement()
  2374. }
  2375. ;
  2376. ListBox.prototype.setupCallbacks = function() {
  2377. var a = function(a) {
  2378. if (this.closed) {
  2379. var b = this.closedBackground.controlRect.linkedControl
  2380. , b = b.getBoundingClientRect()
  2381. , c = a.clientX - b.left;
  2382. a = a.clientY - b.top;
  2383. c /= b.width;
  2384. b = a / b.height;
  2385. 0 <= c && 1 >= c && 0 <= b && 1 >= b ? this.closedBackground.setOpacity(1) : this.closedBackground.setOpacity(0.5)
  2386. } else
  2387. b = this.openBackground.controlRect.linkedControl,
  2388. b = b.getBoundingClientRect(),
  2389. c = a.clientX - b.left,
  2390. a = a.clientY - b.top,
  2391. c /= b.width,
  2392. b = a / b.height,
  2393. 0 <= c && 1 >= c && 0 <= b && 1 >= b ? this.openBackground.setOpacity(1) : this.openBackground.setOpacity(0.5)
  2394. }
  2395. .bind(this);
  2396. this.defaultButton.controlRect.linkedControl.onclick = function() {
  2397. this.closed ? this.showList(!0) : (this.showList(this.closed),
  2398. this.closedBackground.setOpacity(1),
  2399. this.defaultButton.setOpacity(1))
  2400. }
  2401. .bind(this);
  2402. for (var b = function(a) {
  2403. this.selectItem(a.id);
  2404. this.showList(!1);
  2405. this.defaultButton.setOpacity(0.5);
  2406. this.selectionChangedCallback && this.selectionChangedCallback(this)
  2407. }
  2408. .bind(this), c = function(a) {
  2409. a = this.listBoxButtons.length;
  2410. for (var b = 0; b < a; b++)
  2411. this.listBoxButtons[b].controlRect.mouseOver && (this.selectItem(b),
  2412. b = a,
  2413. this.selectionChangedCallback && this.selectionChangedCallback(this));
  2414. this.showList(!1)
  2415. }
  2416. .bind(this), d = this.listBoxButtons.length, e = 0; e < d; e++)
  2417. this.listBoxButtons[e].controlRect.callBack = b,
  2418. this.listBoxButtons[e].controlRect.id = e,
  2419. this.listBoxButtons[e].controlRect.linkedControl.addEventListener("mousemove", a);
  2420. this.guiScreen.ui.viewer.input.element.addEventListener("mousemove", a);
  2421. this.openBackground.controlRect.linkedControl.addEventListener("mousemove", a);
  2422. this.closedBackground.controlRect.linkedControl.addEventListener("mousemove", a);
  2423. this.guiScreen.ui.viewer.input.element.addEventListener("mousedown", c)
  2424. }
  2425. ;
  2426. function Material(a, b, c) {
  2427. this.gl = a;
  2428. this.name = c.name;
  2429. var d = {
  2430. mipmap: !0,
  2431. aniso: a.hints.mobile ? 0 : 4,
  2432. clamp: !!c.textureWrapClamp,
  2433. mirror: !!c.textureWrapMirror
  2434. }
  2435. , e = {
  2436. mipmap: d.mipmap,
  2437. clamp: d.clamp,
  2438. mirror: d.mirror,
  2439. nofilter: c.textureFilterNearest || !1
  2440. };
  2441. e.nofilter || (e.aniso = a.hints.mobile ? 2 : 4);
  2442. this.textures = {
  2443. albedo: a.textureCache.fromFilesMergeAlpha(b.get(c.albedoTex), b.get(c.alphaTex), e),
  2444. reflectivity: a.textureCache.fromFilesMergeAlpha(b.get(c.reflectivityTex), b.get(c.glossTex), d),
  2445. normal: a.textureCache.fromFile(b.get(c.normalTex), d),
  2446. extras: a.textureCache.fromFilesMergeAlpha(b.get(c.extrasTex), b.get(c.extrasTexA), d)
  2447. };
  2448. this.extrasTexCoordRanges = {};
  2449. if (c.extrasTexCoordRanges)
  2450. for (var f in c.extrasTexCoordRanges)
  2451. this.extrasTexCoordRanges[f] = new Float32Array(c.extrasTexCoordRanges[f].scaleBias);
  2452. this.textures.extras || (b = new Texture(a,{
  2453. width: 1,
  2454. height: 1
  2455. }),
  2456. b.loadArray(new Uint8Array([255, 255, 255, 255])),
  2457. this.textures.extras = b);
  2458. var g = c.blendTint || [1, 1, 1];
  2459. b = {
  2460. none: function() {
  2461. a.disable(a.BLEND)
  2462. },
  2463. alpha: function() {
  2464. a.enable(a.BLEND);
  2465. a.blendFuncSeparate(a.SRC_ALPHA, a.ONE_MINUS_SRC_ALPHA, a.ONE_MINUS_DST_ALPHA, a.ONE)
  2466. },
  2467. add: function() {
  2468. a.enable(a.BLEND);
  2469. a.blendColor(g[0], g[1], g[2], 1);
  2470. a.blendFunc(a.ONE, a.CONSTANT_COLOR)
  2471. }
  2472. };
  2473. this.blend = b[c.blend] || b.none;
  2474. this.alphaTest = c.alphaTest || 0;
  2475. this.usesBlending = this.blend !== b.none;
  2476. this.usesRefraction = !!c.refraction;
  2477. this.shadowAlphaTest = this.alphaTest;
  2478. 0 >= this.shadowAlphaTest && this.blend === b.alpha && (this.shadowAlphaTest = 0.5);
  2479. this.castShadows = this.blend !== b.add;
  2480. this.horizonOcclude = c.horizonOcclude || 0;
  2481. this.fresnel = new Float32Array(c.fresnel ? c.fresnel : [1, 1, 1]);
  2482. this.emissiveIntensity = c.emissiveIntensity || 1;
  2483. d = [];
  2484. e = !1;
  2485. 0 < c.lightCount && d.push("#define LIGHT_COUNT " + c.lightCount);
  2486. 0 < c.shadowCount && (f = Math.min(c.lightCount, c.shadowCount),
  2487. this.usesRefraction && 8 >= a.limits.textureCount && (f = 2 < f ? 2 : f),
  2488. d.push("#define SHADOW_COUNT " + f));
  2489. 0 < c.alphaTest && d.push("#define ALPHA_TEST");
  2490. this.blend === b.alpha ? d.push("#define TRANSPARENCY_DITHER") : this.blend === b.none && d.push("#define NOBLEND");
  2491. a.hints.mobile && d.push("#define MOBILE");
  2492. a.ext.textureDepth && d.push("#define SHADOW_NATIVE_DEPTH");
  2493. f = function(a) {
  2494. return 1 / (2 / 3 * 3.1415962 * (a * a + a + 1))
  2495. }
  2496. ;
  2497. c.useSkin && (d.push("#define SKIN"),
  2498. this.skinParams = c.skinParams || {
  2499. subdermisColor: [1, 1, 1],
  2500. transColor: [1, 0, 0, 1],
  2501. fresnelColor: [0.2, 0.2, 0.2, 0.5],
  2502. fresnelOcc: 1,
  2503. fresnelGlossMask: 1,
  2504. transSky: 0.5,
  2505. shadowBlur: 0.5,
  2506. normalSmooth: 0.5,
  2507. transScatter: 0,
  2508. transDepth: 0,
  2509. millimeterScale: 1
  2510. },
  2511. this.extrasTexCoordRanges.subdermisTex || d.push("#define SKIN_NO_SUBDERMIS_TEX"),
  2512. this.extrasTexCoordRanges.translucencyTex || d.push("#define SKIN_NO_TRANSLUCENCY_TEX"),
  2513. this.extrasTexCoordRanges.fuzzTex || d.push("#define SKIN_NO_FUZZ_TEX"),
  2514. void 0 === this.skinParams.version && (this.skinParams.version = 1),
  2515. 2 == this.skinParams.version ? (d.push("#define SKIN_VERSION_2"),
  2516. this.skinParams.shadowBlur *= 4,
  2517. this.skinParams.shadowBlur = Math.min(this.skinParams.shadowBlur, 40),
  2518. this.skinParams.transIntegral = f(0.5 * this.skinParams.transScatter),
  2519. this.skinParams.fresnelIntegral = 1 / 3.14159 * (1 - 0.5 * this.skinParams.fresnelColor[3]),
  2520. this.skinParams.transSky = 0) : (d.push("#define SKIN_VERSION_1"),
  2521. this.skinParams.shadowBlur = 8 * Math.min(this.skinParams.shadowBlur, 1),
  2522. this.skinParams.transDepth = 0,
  2523. this.skinParams.transScatter = this.skinParams.transColor[3],
  2524. this.skinParams.transIntegral = 1 / 3.14159 * (1 - 0.5 * this.skinParams.transScatter),
  2525. this.skinParams.fresnelIntegral = 1 / 3.14159 * (1 - 0.5 * this.skinParams.fresnelColor[3]),
  2526. this.skinParams.transSky *= 1.25,
  2527. this.skinParams.transIntegral *= 1.25));
  2528. c.aniso && (d.push("#define ANISO"),
  2529. this.anisoParams = c.anisoParams || {
  2530. strength: 1,
  2531. tangent: [1, 0, 0],
  2532. integral: 0.5
  2533. },
  2534. this.extrasTexCoordRanges.anisoTex || d.push("#define ANISO_NO_DIR_TEX"));
  2535. c.microfiber && (d.push("#define MICROFIBER"),
  2536. this.microfiberParams = c.microfiberParams || {
  2537. fresnelColor: [0.2, 0.2, 0.2, 0.5],
  2538. fresnelOcc: 1,
  2539. fresnelGlossMask: 1
  2540. },
  2541. this.microfiberParams.fresnelIntegral = 1 / 3.14159 * (1 - 0.5 * this.microfiberParams.fresnelColor[3]),
  2542. this.extrasTexCoordRanges.fuzzTex || d.push("#define MICROFIBER_NO_FUZZ_TEX"));
  2543. c.refraction && (d.push("#define REFRACTION"),
  2544. this.refractionParams = c.refractionParams || {
  2545. distantBackground: !1,
  2546. tint: [1, 1, 1],
  2547. useAlbedoTint: !1,
  2548. IOR: 1.5
  2549. },
  2550. this.extrasTexCoordRanges.refractionMaskTex || d.push("#define REFRACTION_NO_MASK_TEX"));
  2551. c.vertexColor && (d.push("#define VERTEX_COLOR"),
  2552. c.vertexColorsRGB && d.push("#define VERTEX_COLOR_SRGB"),
  2553. c.vertexColorAlpha && d.push("#define VERTEX_COLOR_ALPHA"));
  2554. this.horizonSmoothing = c.horizonSmoothing || 0;
  2555. 0 < this.horizonSmoothing && d.push("#define HORIZON_SMOOTHING");
  2556. c.unlitDiffuse && d.push("#define DIFFUSE_UNLIT");
  2557. this.extrasTexCoordRanges.emissiveTex && (d.push("#define EMISSIVE"),
  2558. c.emissiveSecondaryUV && (d.push("#define EMISSIVE_SECONDARY_UV"),
  2559. e = !0));
  2560. this.extrasTexCoordRanges.aoTex && (d.push("#define AMBIENT_OCCLUSION"),
  2561. c.aoSecondaryUV && (d.push("#define AMBIENT_OCCLUSION_SECONDARY_UV"),
  2562. e = !0));
  2563. c.tangentOrthogonalize && d.push("#define TSPACE_ORTHOGONALIZE");
  2564. c.tangentNormalize && d.push("#define TSPACE_RENORMALIZE");
  2565. c.tangentGenerateBitangent && d.push("#define TSPACE_COMPUTE_BITANGENT");
  2566. e && d.push("#define TEXCOORD_SECONDARY");
  2567. this.vOffset = this.uOffset = 0;
  2568. d.push("#define UV_OFFSET ");
  2569. this.shader = a.shaderCache.fromURLs("matvert.glsl", "matfrag.glsl", d);
  2570. d.push("#define STRIPVIEW");
  2571. this.stripShader = a.shaderCache.fromURLs("matvert.glsl", "matfrag.glsl", d);
  2572. this.wireShader = a.shaderCache.fromURLs("wirevert.glsl", "wirefrag.glsl");
  2573. this.blend === b.alpha && (this.prepassShader = a.shaderCache.fromURLs("alphaprepassvert.glsl", "alphaprepassfrag.glsl"))
  2574. }
  2575. Material.prototype.bind = function(a, b) {
  2576. if (!this.complete())
  2577. return !1;
  2578. var c = 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, l = this.microfiberParams, n, m = this.gl, p = g.params, r = this.textures, s = g.samplers;
  2579. g.bind();
  2580. this.blend();
  2581. var u = b.mesh.displayMatrix
  2582. , q = Matrix.mul(Matrix.empty(), c.viewMatrix, u)
  2583. , x = Matrix.mul(Matrix.empty(), c.projectionMatrix, c.viewMatrix)
  2584. , q = Matrix.mul(Matrix.empty(), c.projectionMatrix, q)
  2585. , u = Matrix.mul(Matrix.empty(), d.matrix, u);
  2586. m.uniformMatrix4fv(p.uModelViewProjectionMatrix, !1, q);
  2587. m.uniformMatrix4fv(p.uSkyMatrix, !1, u);
  2588. u = Matrix.mulPoint(Vect.empty(), d.matrix, c.transform[12], c.transform[13], c.transform[14]);
  2589. m.uniform3f(p.uCameraPosition, u[0], u[1], u[2]);
  2590. m.uniform3fv(p.uFresnel, this.fresnel);
  2591. m.uniform1f(p.uAlphaTest, this.alphaTest);
  2592. m.uniform1f(p.uHorizonOcclude, this.horizonOcclude);
  2593. m.uniform1f(p.uHorizonSmoothing, this.horizonSmoothing);
  2594. m.uniform4fv(p.uDiffuseCoefficients, e.diffuseCoefficients);
  2595. 0 < d.count && (m.uniform4fv(p.uLightPositions, d.positionBuffer),
  2596. m.uniform3fv(p.uLightDirections, d.directionBuffer),
  2597. m.uniform3fv(p.uLightColors, d.colors),
  2598. m.uniform3fv(p.uLightParams, d.parameters),
  2599. m.uniform3fv(p.uLightSpot, d.spot),
  2600. u = 0.392699 * a.postRender.currentSample(),
  2601. m.uniform2f(p.uShadowKernelRotation, 0.5 * Math.cos(u), 0.5 * Math.sin(u)),
  2602. 0 < d.shadowCount && (u = f.depthTextures[0].desc.width,
  2603. m.uniform2f(p.uShadowMapSize, u, 1 / u),
  2604. m.uniformMatrix4fv(p.uShadowMatrices, !1, d.finalTransformBuffer),
  2605. m.uniformMatrix4fv(p.uInvShadowMatrices, !1, d.inverseTransformBuffer),
  2606. m.uniform4fv(p.uShadowTexelPadProjections, d.shadowTexelPadProjections),
  2607. f.bindDepthTexture(s.tDepth0, 0),
  2608. f.bindDepthTexture(s.tDepth1, 1),
  2609. f.bindDepthTexture(s.tDepth2, 2)));
  2610. h && (m.uniform3fv(p.uSubdermisColor, h.subdermisColor),
  2611. m.uniform4fv(p.uTransColor, h.transColor),
  2612. m.uniform1f(p.uTransScatter, h.transScatter),
  2613. m.uniform4fv(p.uFresnelColor, h.fresnelColor),
  2614. m.uniform1f(p.uFresnelOcc, h.fresnelOcc),
  2615. m.uniform1f(p.uFresnelGlossMask, h.fresnelGlossMask),
  2616. m.uniform1f(p.uFresnelIntegral, h.fresnelIntegral),
  2617. m.uniform1f(p.uTransIntegral, h.transIntegral),
  2618. m.uniform1f(p.uSkinTransDepth, h.transDepth),
  2619. m.uniform1f(p.uTransSky, h.transSky),
  2620. m.uniform1f(p.uSkinShadowBlur, h.shadowBlur),
  2621. m.uniform1f(p.uNormalSmooth, h.normalSmooth),
  2622. (n = this.extrasTexCoordRanges.subdermisTex) && m.uniform4fv(p.uTexRangeSubdermis, n),
  2623. (n = this.extrasTexCoordRanges.translucencyTex) && m.uniform4fv(p.uTexRangeTranslucency, n),
  2624. (n = this.extrasTexCoordRanges.fuzzTex) && m.uniform4fv(p.uTexRangeFuzz, n));
  2625. l && (m.uniform4fv(p.uFresnelColor, l.fresnelColor),
  2626. m.uniform1f(p.uFresnelOcc, l.fresnelOcc),
  2627. m.uniform1f(p.uFresnelGlossMask, l.fresnelGlossMask),
  2628. m.uniform1f(p.uFresnelIntegral, l.fresnelIntegral),
  2629. (n = this.extrasTexCoordRanges.fuzzTex) && m.uniform4fv(p.uTexRangeFuzz, n));
  2630. k && (m.uniform3fv(p.uAnisoTangent, k.tangent),
  2631. m.uniform1f(p.uAnisoStrength, k.strength),
  2632. m.uniform1f(p.uAnisoIntegral, k.integral),
  2633. (n = this.extrasTexCoordRanges.anisoTex) && m.uniform4fv(p.uTexRangeAniso, n));
  2634. this.usesRefraction && (a.refractionSurface && a.refractionSurface.bind(s.tRefraction),
  2635. d = Matrix.mul(Matrix.empty(), x, d.invMatrix),
  2636. m.uniformMatrix4fv(p.uRefractionViewProjection, !1, d),
  2637. m.uniform1f(p.uRefractionRayDistance, this.refractionParams.distantBackground ? 1E10 : 4 * b.mesh.bounds.maxExtent),
  2638. m.uniform3fv(p.uRefractionTint, this.refractionParams.tint),
  2639. m.uniform1f(p.uRefractionAlbedoTint, this.refractionParams.useAlbedoTint ? 1 : 0),
  2640. m.uniform1f(p.uRefractionIOREntry, 1 / this.refractionParams.IOR),
  2641. (n = this.extrasTexCoordRanges.refractionMaskTex) && m.uniform4fv(p.uTexRangeRefraction, n));
  2642. if (n = this.extrasTexCoordRanges.emissiveTex)
  2643. m.uniform4fv(p.uTexRangeEmissive, n),
  2644. m.uniform1f(p.uEmissiveScale, this.emissiveIntensity);
  2645. (n = this.extrasTexCoordRanges.aoTex) && m.uniform4fv(p.uTexRangeAO, n);
  2646. r.albedo.bind(s.tAlbedo);
  2647. r.reflectivity.bind(s.tReflectivity);
  2648. r.normal.bind(s.tNormal);
  2649. r.extras.bind(s.tExtras);
  2650. e.specularTexture.bind(s.tSkySpecular);
  2651. g === this.stripShader && (m.uniform1fv(p.uStrips, a.stripData.strips),
  2652. m.uniform2f(p.uStripRes, 2 / c.size[0], 2 / c.size[1]));
  2653. m.uniform2f(p.uUVOffset, this.uOffset, this.vOffset);
  2654. return !0
  2655. }
  2656. ;
  2657. Material.prototype.bindAlphaPrepass = function(a, b) {
  2658. if (!this.complete() || !this.prepassShader)
  2659. return !1;
  2660. var c = this.gl
  2661. , d = this.prepassShader.params
  2662. , e = this.prepassShader.samplers;
  2663. this.prepassShader.bind();
  2664. var f = Matrix.mul(Matrix.empty(), a.view.viewMatrix, b.mesh.displayMatrix)
  2665. , f = Matrix.mul(Matrix.empty(), a.view.projectionMatrix, f);
  2666. c.uniformMatrix4fv(d.uModelViewProjectionMatrix, !1, f);
  2667. c.uniform2f(d.uUVOffset, this.uOffset, this.vOffset);
  2668. this.textures.albedo.bind(e.tAlbedo);
  2669. return !0
  2670. }
  2671. ;
  2672. Material.prototype.bindWire = function(a, b) {
  2673. if (!this.complete())
  2674. return !1;
  2675. var c = this.gl
  2676. , d = this.wireShader.params
  2677. , e = a.view;
  2678. c.enable(c.BLEND);
  2679. c.blendFunc(c.SRC_ALPHA, c.ONE_MINUS_SRC_ALPHA);
  2680. c.depthMask(!1);
  2681. this.wireShader.bind();
  2682. var f = Matrix.mul(Matrix.empty(), a.view.viewMatrix, b.mesh.displayMatrix)
  2683. , f = Matrix.mul(Matrix.empty(), a.view.projectionMatrix, f);
  2684. c.uniformMatrix4fv(d.uModelViewProjectionMatrix, !1, f);
  2685. c.uniform4f(d.uStripParams, 2 / e.size[0], 2 / e.size[1], a.stripData.strips[3], a.stripData.strips[4]);
  2686. return !0
  2687. }
  2688. ;
  2689. Material.prototype.complete = function() {
  2690. 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()
  2691. }
  2692. ;
  2693. var Matrix = {
  2694. type: Float32Array,
  2695. create: function(a, b, c, d, e, f, g, h, k, l, n, m, p, r, s, u) {
  2696. var q = new Matrix.type(16);
  2697. q[0] = a;
  2698. q[4] = b;
  2699. q[8] = c;
  2700. q[12] = d;
  2701. q[1] = e;
  2702. q[5] = f;
  2703. q[9] = g;
  2704. q[13] = h;
  2705. q[2] = k;
  2706. q[6] = l;
  2707. q[10] = n;
  2708. q[14] = m;
  2709. q[3] = p;
  2710. q[7] = r;
  2711. q[11] = s;
  2712. q[15] = u;
  2713. return q
  2714. },
  2715. empty: function() {
  2716. return new Matrix.type(16)
  2717. },
  2718. identity: function() {
  2719. var a = new Matrix.type(16);
  2720. a[0] = 1;
  2721. a[4] = 0;
  2722. a[8] = 0;
  2723. a[12] = 0;
  2724. a[1] = 0;
  2725. a[5] = 1;
  2726. a[9] = 0;
  2727. a[13] = 0;
  2728. a[2] = 0;
  2729. a[6] = 0;
  2730. a[10] = 1;
  2731. a[14] = 0;
  2732. a[3] = 0;
  2733. a[7] = 0;
  2734. a[11] = 0;
  2735. a[15] = 1;
  2736. return a
  2737. },
  2738. set: function(a, b, c, d, e, f, g, h, k, l, n, m, p, r, s, u, q) {
  2739. a[0] = b;
  2740. a[4] = c;
  2741. a[8] = d;
  2742. a[12] = e;
  2743. a[1] = f;
  2744. a[5] = g;
  2745. a[9] = h;
  2746. a[13] = k;
  2747. a[2] = l;
  2748. a[6] = n;
  2749. a[10] = m;
  2750. a[14] = p;
  2751. a[3] = r;
  2752. a[7] = s;
  2753. a[11] = u;
  2754. a[15] = q
  2755. },
  2756. translation: function(a, b, c, d) {
  2757. Matrix.set(a, 1, 0, 0, b, 0, 1, 0, c, 0, 0, 1, d, 0, 0, 0, 1);
  2758. return a
  2759. },
  2760. rotation: function(a, b, c) {
  2761. a[0] = 1;
  2762. a[4] = 0;
  2763. a[8] = 0;
  2764. a[12] = 0;
  2765. a[1] = 0;
  2766. a[5] = 1;
  2767. a[9] = 0;
  2768. a[13] = 0;
  2769. a[2] = 0;
  2770. a[6] = 0;
  2771. a[10] = 1;
  2772. a[14] = 0;
  2773. a[3] = 0;
  2774. a[7] = 0;
  2775. a[11] = 0;
  2776. a[15] = 1;
  2777. var d = 0.0174532925 * b;
  2778. b = Math.sin(d);
  2779. d = Math.cos(d);
  2780. switch (c) {
  2781. case 0:
  2782. a[5] = d;
  2783. a[9] = -b;
  2784. a[6] = b;
  2785. a[10] = d;
  2786. break;
  2787. case 1:
  2788. a[0] = d;
  2789. a[8] = b;
  2790. a[2] = -b;
  2791. a[10] = d;
  2792. break;
  2793. case 2:
  2794. a[0] = d,
  2795. a[4] = -b,
  2796. a[1] = b,
  2797. a[5] = d
  2798. }
  2799. return a
  2800. },
  2801. mul: function(a, b, c) {
  2802. var d = b[0]
  2803. , e = b[1]
  2804. , f = b[2]
  2805. , g = b[3]
  2806. , h = b[4]
  2807. , k = b[5]
  2808. , l = b[6]
  2809. , n = b[7]
  2810. , m = b[8]
  2811. , p = b[9]
  2812. , r = b[10]
  2813. , s = b[11]
  2814. , u = b[12]
  2815. , q = b[13]
  2816. , x = b[14];
  2817. b = b[15];
  2818. var w = c[0]
  2819. , v = c[1]
  2820. , t = c[2]
  2821. , y = c[3];
  2822. a[0] = w * d + v * h + t * m + y * u;
  2823. a[1] = w * e + v * k + t * p + y * q;
  2824. a[2] = w * f + v * l + t * r + y * x;
  2825. a[3] = w * g + v * n + t * s + y * b;
  2826. w = c[4];
  2827. v = c[5];
  2828. t = c[6];
  2829. y = c[7];
  2830. a[4] = w * d + v * h + t * m + y * u;
  2831. a[5] = w * e + v * k + t * p + y * q;
  2832. a[6] = w * f + v * l + t * r + y * x;
  2833. a[7] = w * g + v * n + t * s + y * b;
  2834. w = c[8];
  2835. v = c[9];
  2836. t = c[10];
  2837. y = c[11];
  2838. a[8] = w * d + v * h + t * m + y * u;
  2839. a[9] = w * e + v * k + t * p + y * q;
  2840. a[10] = w * f + v * l + t * r + y * x;
  2841. a[11] = w * g + v * n + t * s + y * b;
  2842. w = c[12];
  2843. v = c[13];
  2844. t = c[14];
  2845. y = c[15];
  2846. a[12] = w * d + v * h + t * m + y * u;
  2847. a[13] = w * e + v * k + t * p + y * q;
  2848. a[14] = w * f + v * l + t * r + y * x;
  2849. a[15] = w * g + v * n + t * s + y * b;
  2850. return a
  2851. },
  2852. invert: function(a, b) {
  2853. var c = b[0]
  2854. , d = b[1]
  2855. , e = b[2]
  2856. , f = b[3]
  2857. , g = b[4]
  2858. , h = b[5]
  2859. , k = b[6]
  2860. , l = b[7]
  2861. , n = b[8]
  2862. , m = b[9]
  2863. , p = b[10]
  2864. , r = b[11]
  2865. , s = b[12]
  2866. , u = b[13]
  2867. , q = b[14]
  2868. , x = b[15]
  2869. , w = c * h - d * g
  2870. , v = c * k - e * g
  2871. , t = c * l - f * g
  2872. , y = d * k - e * h
  2873. , E = d * l - f * h
  2874. , F = e * l - f * k
  2875. , A = n * u - m * s
  2876. , B = n * q - p * s
  2877. , z = n * x - r * s
  2878. , C = m * q - p * u
  2879. , G = m * x - r * u
  2880. , H = p * x - r * q
  2881. , D = w * H - v * G + t * C + y * z - E * B + F * A;
  2882. if (!D)
  2883. return null;
  2884. D = 1 / D;
  2885. a[0] = (h * H - k * G + l * C) * D;
  2886. a[1] = (e * G - d * H - f * C) * D;
  2887. a[2] = (u * F - q * E + x * y) * D;
  2888. a[3] = (p * E - m * F - r * y) * D;
  2889. a[4] = (k * z - g * H - l * B) * D;
  2890. a[5] = (c * H - e * z + f * B) * D;
  2891. a[6] = (q * t - s * F - x * v) * D;
  2892. a[7] = (n * F - p * t + r * v) * D;
  2893. a[8] = (g * G - h * z + l * A) * D;
  2894. a[9] = (d * z - c * G - f * A) * D;
  2895. a[10] = (s * E - u * t + x * w) * D;
  2896. a[11] = (m * t - n * E - r * w) * D;
  2897. a[12] = (h * B - g * C - k * A) * D;
  2898. a[13] = (c * C - d * B + e * A) * D;
  2899. a[14] = (u * v - s * y - q * w) * D;
  2900. a[15] = (n * y - m * v + p * w) * D;
  2901. return a
  2902. },
  2903. transpose: function(a, b) {
  2904. a[0] = b[0];
  2905. a[4] = b[1];
  2906. a[8] = b[2];
  2907. a[12] = b[3];
  2908. a[1] = b[4];
  2909. a[5] = b[5];
  2910. a[9] = b[6];
  2911. a[13] = b[7];
  2912. a[2] = b[8];
  2913. a[6] = b[9];
  2914. a[10] = b[10];
  2915. a[14] = b[11];
  2916. a[3] = b[12];
  2917. a[7] = b[13];
  2918. a[11] = b[14];
  2919. a[15] = b[15];
  2920. return a
  2921. },
  2922. mul4: function(a, b, c, d, e, f) {
  2923. a[0] = b[0] * c + b[4] * d + b[8] * e + b[12] * f;
  2924. a[1] = b[1] * c + b[5] * d + b[9] * e + b[13] * f;
  2925. a[2] = b[2] * c + b[6] * d + b[10] * e + b[14] * f;
  2926. a[3] = b[3] * c + b[7] * d + b[11] * e + b[15] * f;
  2927. return a
  2928. },
  2929. mulPoint: function(a, b, c, d, e) {
  2930. a[0] = b[0] * c + b[4] * d + b[8] * e + b[12];
  2931. a[1] = b[1] * c + b[5] * d + b[9] * e + b[13];
  2932. a[2] = b[2] * c + b[6] * d + b[10] * e + b[14];
  2933. return a
  2934. },
  2935. mulVec: function(a, b, c, d, e) {
  2936. a[0] = b[0] * c + b[4] * d + b[8] * e;
  2937. a[1] = b[1] * c + b[5] * d + b[9] * e;
  2938. a[2] = b[2] * c + b[6] * d + b[10] * e;
  2939. return a
  2940. },
  2941. perspective: function(a, b, c, d, e, f) {
  2942. f = f || 0;
  2943. b = 1 / Math.tan(0.00872664625 * b);
  2944. a[0] = b / c;
  2945. a[1] = a[2] = a[3] = 0;
  2946. a[5] = b;
  2947. a[4] = a[6] = a[7] = 0;
  2948. a[8] = a[9] = 0;
  2949. a[10] = (e + d) / (d - e) - 3.0518044E-5 * f;
  2950. a[11] = -1;
  2951. a[14] = 2 * e * d / (d - e);
  2952. a[12] = a[13] = a[15] = 0;
  2953. return a
  2954. },
  2955. perspectiveInfinite: function(a, b, c, d, e) {
  2956. e = e || 0;
  2957. b = 1 / Math.tan(0.00872664625 * b);
  2958. a[0] = b / c;
  2959. a[1] = a[2] = a[3] = 0;
  2960. a[5] = b;
  2961. a[4] = a[6] = a[7] = 0;
  2962. a[8] = a[9] = 0;
  2963. a[10] = a[11] = -1 - 3.0518044E-5 * e;
  2964. a[14] = -2 * d;
  2965. a[12] = a[13] = a[15] = 0;
  2966. return a
  2967. },
  2968. ortho: function(a, b, c, d, e, f, g, h) {
  2969. var k = 1 / (c - b)
  2970. , l = 1 / (e - d)
  2971. , n = 1 / (g - f);
  2972. a[0] = k + k;
  2973. a[1] = a[2] = a[3] = 0;
  2974. a[5] = l + l;
  2975. a[4] = a[6] = a[7] = 0;
  2976. a[12] = -(c + b) * k;
  2977. a[13] = -(e + d) * l;
  2978. a[10] = -(n + n) - 3.0518044E-5 * (h || 0);
  2979. a[14] = -(g + f) * n;
  2980. a[8] = a[9] = a[11] = 0;
  2981. a[15] = 1;
  2982. return a
  2983. },
  2984. lookAt: function(a, b, c, d) {
  2985. var e = a.subarray(0, 3)
  2986. , f = a.subarray(4, 7)
  2987. , g = a.subarray(8, 11);
  2988. Vect.sub(g, b, c);
  2989. Vect.cross(e, d, g);
  2990. Vect.normalize(g, g);
  2991. Vect.normalize(e, e);
  2992. Vect.cross(f, g, e);
  2993. Matrix.set(a, e[0], e[1], e[2], -Vect.dot(e, b), f[0], f[1], f[2], -Vect.dot(f, b), g[0], g[1], g[2], -Vect.dot(g, b), 0, 0, 0, 1)
  2994. },
  2995. copy: function(a, b) {
  2996. for (var c = 0; 16 > c; ++c)
  2997. a[c] = b[c]
  2998. },
  2999. copyToBuffer: function(a, b, c) {
  3000. for (var d = 0; 16 > d; ++d)
  3001. a[b + d] = c[d]
  3002. }
  3003. };
  3004. function byteToFloat(array) {
  3005. var Uint32 = array[0] | array[1] << 8 | array[2] << 16 | array[3] << 24;
  3006. var sign = (Uint32 & 0x80000000) ? -1 : 1;
  3007. var exponent = ((Uint32 >> 23) & 0xFF) - 127;
  3008. var significand = (Uint32 & ~(-1 << 23));
  3009. if (exponent == 128)
  3010. return sign * ((significand) ? Number.NaN : Number.POSITIVE_INFINITY);
  3011. if (exponent == -127) {
  3012. if (significand == 0) return sign * 0.0;
  3013. exponent = -126;
  3014. significand /= (1 << 22);
  3015. } else significand = (significand | (1 << 23)) / (1 << 23);
  3016. return sign * significand * Math.pow(2, exponent);
  3017. }
  3018. function Floattobyte(f) {
  3019. var buffer = new ArrayBuffer(4);
  3020. var viewX = new DataView(buffer);
  3021. viewX.setFloat32(0, f);
  3022. var result = [];
  3023. result[3] = viewX.getUint8(0);
  3024. result[2] = viewX.getUint8(1);
  3025. result[1] = viewX.getUint8(2);
  3026. result[0] = viewX.getUint8(3);
  3027. return result;
  3028. }
  3029. function Mesh(a, b, c) {
  3030. this.gl = a;
  3031. this.desc = b;
  3032. var d = b.isDynamicMesh;
  3033. this.numSubMeshes = this.dynamicVertexData = 0;
  3034. this.displayMatrix = Matrix.identity();
  3035. this.name = b.name;
  3036. /*
  3037. if(b.name == 'tou001')
  3038. {
  3039. var indexCount = this.desc.indexCount;
  3040. var indexTypeSize = this.desc.indexTypeSize;
  3041. var start = indexCount*indexTypeSize;
  3042. for(var i = start;i<c.data.length;i+=32)
  3043. {
  3044. var itemX = byteToFloat([c.data[i], c.data[i+1],c.data[i+2],c.data[i+3]])
  3045. itemX = itemX*2.59928-0.021;
  3046. var bx = Floattobyte(itemX);
  3047. c.data[i] = bx[0];
  3048. c.data[i+1] = bx[1];
  3049. c.data[i+2] = bx[2];
  3050. c.data[i+3] = bx[3];
  3051. var itemY = byteToFloat([c.data[i+4], c.data[i+5],c.data[i+6],c.data[i+7]])
  3052. itemY = itemY*2.59928-0.031;
  3053. bx = Floattobyte(itemY);
  3054. c.data[i+4] = bx[0];
  3055. c.data[i+5] = bx[1];
  3056. c.data[i+6] = bx[2];
  3057. c.data[i+7] = bx[3];
  3058. var itemZ = byteToFloat([c.data[i+8], c.data[i+9],c.data[i+10],c.data[i+11]])
  3059. itemZ = itemZ*2.59928-0.051;
  3060. bx = Floattobyte(itemZ);
  3061. c.data[i+8] = bx[0];
  3062. c.data[i+9] = bx[1];
  3063. c.data[i+10] = bx[2];
  3064. c.data[i+11] = bx[3];
  3065. }
  3066. }
  3067. */
  3068. this.modelMatrix = Matrix.identity();
  3069. this.origin = b.transform ? Vect.create(b.transform[12], b.transform[13], b.transform[14], 1) : Vect.create(0, 5, 0, 1);
  3070. this.stride = 32;
  3071. if (this.vertexColor = b.vertexColor)
  3072. this.stride += 4;
  3073. if (this.secondaryTexCoord = b.secondaryTexCoord)
  3074. this.stride += 8;
  3075. c = new ByteStream(c.data);
  3076. this.indexCount = b.indexCount;
  3077. this.indexTypeSize = b.indexTypeSize;
  3078. this.indexType = 4 == this.indexTypeSize ? a.UNSIGNED_INT : a.UNSIGNED_SHORT;
  3079. this.indexBuffer = a.createBuffer();
  3080. a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
  3081. var e = c.readBytes(this.indexCount * this.indexTypeSize);
  3082. a.bufferData(a.ELEMENT_ARRAY_BUFFER, e, a.STATIC_DRAW);
  3083. this.wireCount = b.wireCount;
  3084. this.wireBuffer = a.createBuffer();
  3085. a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, this.wireBuffer);
  3086. e = c.readBytes(this.wireCount * this.indexTypeSize);
  3087. a.bufferData(a.ELEMENT_ARRAY_BUFFER, e, a.STATIC_DRAW);
  3088. a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, null);
  3089. this.vertexCount = b.vertexCount;
  3090. this.vertexBuffer = a.createBuffer();
  3091. a.bindBuffer(a.ARRAY_BUFFER, this.vertexBuffer);
  3092. c = c.readBytes(this.vertexCount * this.stride);
  3093. d ? (this.dynamicVertexData = new Uint8Array(c),
  3094. a.bufferData(a.ARRAY_BUFFER, c, a.DYNAMIC_DRAW)) : a.bufferData(a.ARRAY_BUFFER, c, a.STATIC_DRAW);
  3095. a.bindBuffer(a.ARRAY_BUFFER, null);
  3096. this.bounds = void 0 === b.minBound || void 0 === b.maxBound ? {
  3097. min: Vect.create(-10, -10, -10, 1),
  3098. max: Vect.create(10, 10, -0, 1)
  3099. } : {
  3100. min: Vect.create(b.minBound[0], b.minBound[1], b.minBound[2], 1),
  3101. max: Vect.create(b.maxBound[0], b.maxBound[1], b.maxBound[2], 1)
  3102. };
  3103. this.bounds.maxExtent = Math.max(Math.max(b.maxBound[0] - b.minBound[0], b.maxBound[1] - b.minBound[1]), b.maxBound[2] - b.minBound[2]);
  3104. this.bounds.averageExtent = (b.maxBound[0] - b.minBound[0] + (b.maxBound[1] - b.minBound[1]) + (b.maxBound[2] - b.minBound[2])) / 3
  3105. //八猴子面法线会导致数据量增大,因为同一个点在不同面法线不同,导致在不同面要重用一次vertex坐标。
  3106. }
  3107. ;function MeshRenderable(a, b, c) {
  3108. this.mesh = a;
  3109. this.gl = this.mesh.gl;
  3110. this.indexOffset = b.firstIndex * a.indexTypeSize;
  3111. this.indexCount = b.indexCount;
  3112. this.wireIndexOffset = b.firstWireIndex * a.indexTypeSize;
  3113. this.wireIndexCount = b.wireIndexCount;
  3114. this.material = c;
  3115. this.visible = !0
  3116. }
  3117. MeshRenderable.prototype.draw = function(a) {
  3118. var b = this.gl;
  3119. if (this.material.bind(a, this)) {
  3120. a = this.material.shader.attribs;
  3121. var c = this.mesh.stride;
  3122. this.mesh.desc.cullBackFaces ? (b.enable(b.CULL_FACE),
  3123. b.cullFace(b.BACK)) : b.disable(b.CULL_FACE);
  3124. b.bindBuffer(b.ELEMENT_ARRAY_BUFFER, this.mesh.indexBuffer);
  3125. b.bindBuffer(b.ARRAY_BUFFER, this.mesh.vertexBuffer);
  3126. b.enableVertexAttribArray(a.vPosition);
  3127. b.enableVertexAttribArray(a.vTexCoord);
  3128. b.enableVertexAttribArray(a.vTangent);
  3129. b.enableVertexAttribArray(a.vBitangent);
  3130. b.enableVertexAttribArray(a.vNormal);
  3131. var d = this.mesh.vertexColor && void 0 !== a.vColor;
  3132. d && b.enableVertexAttribArray(a.vColor);
  3133. var e = this.mesh.secondaryTexCoord && void 0 !== a.vTexCoord2;
  3134. e && b.enableVertexAttribArray(a.vTexCoord2);
  3135. var f = 0;
  3136. b.vertexAttribPointer(a.vPosition, 3, b.FLOAT, !1, c, f);
  3137. f += 12;
  3138. b.vertexAttribPointer(a.vTexCoord, 2, b.FLOAT, !1, c, f);
  3139. f += 8;
  3140. this.mesh.secondaryTexCoord && (e && b.vertexAttribPointer(a.vTexCoord2, 2, b.FLOAT, !1, c, f),
  3141. f += 8);
  3142. b.vertexAttribPointer(a.vTangent, 2, b.UNSIGNED_SHORT, !0, c, f);
  3143. f += 4;
  3144. b.vertexAttribPointer(a.vBitangent, 2, b.UNSIGNED_SHORT, !0, c, f);
  3145. f += 4;
  3146. b.vertexAttribPointer(a.vNormal, 2, b.UNSIGNED_SHORT, !0, c, f);
  3147. d && b.vertexAttribPointer(a.vColor, 4, b.UNSIGNED_BYTE, !0, c, f + 4);
  3148. b.drawElements(b.TRIANGLES, this.indexCount, this.mesh.indexType, this.indexOffset);
  3149. b.disableVertexAttribArray(a.vPosition);
  3150. b.disableVertexAttribArray(a.vTexCoord);
  3151. b.disableVertexAttribArray(a.vTangent);
  3152. b.disableVertexAttribArray(a.vBitangent);
  3153. b.disableVertexAttribArray(a.vNormal);
  3154. d && b.disableVertexAttribArray(a.vColor);
  3155. e && b.disableVertexAttribArray(a.vTexCoord2)
  3156. }
  3157. }
  3158. ;
  3159. MeshRenderable.prototype.drawShadow = function(a) {
  3160. var b = this.gl;
  3161. this.mesh.desc.cullBackFaces ? (b.enable(b.CULL_FACE),
  3162. b.cullFace(b.BACK)) : b.disable(b.CULL_FACE);
  3163. b.bindBuffer(b.ELEMENT_ARRAY_BUFFER, this.mesh.indexBuffer);
  3164. b.bindBuffer(b.ARRAY_BUFFER, this.mesh.vertexBuffer);
  3165. b.enableVertexAttribArray(a);
  3166. b.vertexAttribPointer(a, 3, b.FLOAT, !1, this.mesh.stride, 0);
  3167. b.drawElements(b.TRIANGLES, this.indexCount, this.mesh.indexType, this.indexOffset);
  3168. b.disableVertexAttribArray(a)
  3169. }
  3170. ;
  3171. MeshRenderable.prototype.drawAlphaShadow = function(a, b) {
  3172. var c = this.gl;
  3173. this.mesh.desc.cullBackFaces ? (c.enable(c.CULL_FACE),
  3174. c.cullFace(c.BACK)) : c.disable(c.CULL_FACE);
  3175. c.bindBuffer(c.ELEMENT_ARRAY_BUFFER, this.mesh.indexBuffer);
  3176. c.bindBuffer(c.ARRAY_BUFFER, this.mesh.vertexBuffer);
  3177. c.enableVertexAttribArray(a);
  3178. c.enableVertexAttribArray(b);
  3179. c.vertexAttribPointer(a, 3, c.FLOAT, !1, this.mesh.stride, 0);
  3180. c.vertexAttribPointer(b, 2, c.FLOAT, !1, this.mesh.stride, 12);
  3181. c.drawElements(c.TRIANGLES, this.indexCount, this.mesh.indexType, this.indexOffset);
  3182. c.disableVertexAttribArray(a);
  3183. c.disableVertexAttribArray(b)
  3184. }
  3185. ;
  3186. MeshRenderable.prototype.drawAlphaPrepass = function(a) {
  3187. var b = this.gl;
  3188. if (this.material.bindAlphaPrepass(a, this)) {
  3189. a = this.material.prepassShader.attribs;
  3190. var c = this.mesh.stride;
  3191. this.mesh.desc.cullBackFaces ? (b.enable(b.CULL_FACE),
  3192. b.cullFace(b.BACK)) : b.disable(b.CULL_FACE);
  3193. b.bindBuffer(b.ELEMENT_ARRAY_BUFFER, this.mesh.indexBuffer);
  3194. b.bindBuffer(b.ARRAY_BUFFER, this.mesh.vertexBuffer);
  3195. b.enableVertexAttribArray(a.vPosition);
  3196. b.enableVertexAttribArray(a.vTexCoord);
  3197. b.vertexAttribPointer(a.vPosition, 3, b.FLOAT, !1, c, 0);
  3198. b.vertexAttribPointer(a.vTexCoord, 2, b.FLOAT, !1, c, 12);
  3199. b.drawElements(b.TRIANGLES, this.indexCount, this.mesh.indexType, this.indexOffset);
  3200. b.disableVertexAttribArray(a.vPosition);
  3201. b.disableVertexAttribArray(a.vTexCoord)
  3202. }
  3203. }
  3204. ;
  3205. MeshRenderable.prototype.drawWire = function(a) {
  3206. var b = this.material.wireShader.attribs
  3207. , c = this.gl;
  3208. this.material.bindWire(a, this) && (c.enableVertexAttribArray(b.vPosition),
  3209. c.bindBuffer(c.ELEMENT_ARRAY_BUFFER, this.mesh.wireBuffer),
  3210. c.bindBuffer(c.ARRAY_BUFFER, this.mesh.vertexBuffer),
  3211. c.vertexAttribPointer(b.vPosition, 3, c.FLOAT, !1, this.mesh.stride, 0),
  3212. c.drawElements(c.LINES, this.wireIndexCount, this.mesh.indexType, this.wireIndexOffset),
  3213. c.disableVertexAttribArray(b.vPosition))
  3214. }
  3215. ;
  3216. MeshRenderable.prototype.complete = function() {
  3217. return this.material.complete()
  3218. }
  3219. ;
  3220. var Network = {
  3221. fetchImage: function(a, b, c) {
  3222. var d = new Image;
  3223. d.crossOrigin = "Anonymous";
  3224. d.onload = function() {
  3225. 0 < d.width && 0 < d.height ? b(d) : c && c()
  3226. }
  3227. ;
  3228. c && (req.onerror = function() {
  3229. c()
  3230. }
  3231. );
  3232. d.src = a
  3233. },
  3234. fetchText: function(a, b, c, d) {
  3235. var e = new XMLHttpRequest;
  3236. e.open("GET", a, !0);
  3237. e.onload = function() {
  3238. 200 == e.status ? b(e.responseText) : c && c()
  3239. }
  3240. ;
  3241. c && (e.onerror = function() {
  3242. c()
  3243. }
  3244. );
  3245. d && (e.onprogress = function(a) {
  3246. d(a.loaded, a.total)
  3247. }
  3248. );
  3249. e.send()
  3250. },
  3251. fetchBinary: function(a, b, c, d) {
  3252. var e = new XMLHttpRequest;
  3253. e.open("GET", a, !0);
  3254. e.responseType = "arraybuffer";
  3255. e.onload = function() {
  3256. 200 == e.status ? b(e.response) : c && c()
  3257. }
  3258. ;
  3259. c && (e.onerror = function() {
  3260. c()
  3261. }
  3262. );
  3263. d && (e.onprogress = function(a) {
  3264. d(a.loaded, a.total)
  3265. }
  3266. );
  3267. e.send()
  3268. },
  3269. fetchBinaryIncremental: function(a, b, c, d) {
  3270. var e = new XMLHttpRequest;
  3271. e.open("HEAD", a, !0);
  3272. e.onload = function() {
  3273. if (200 == e.status) {//许钟文改 跨域
  3274. //var f = e.getResponseHeader("Accept-Ranges");
  3275. //if (f && "none" != f) {
  3276. var g = e.getResponseHeader("Content-Length") | 0
  3277. , h = function(c, e) {
  3278. var f = new XMLHttpRequest;
  3279. f.open("GET", a, !0);
  3280. f.setRequestHeader("Range", "bytes=" + c + "-" + e);
  3281. f.responseType = "arraybuffer";
  3282. f.onload = function() {
  3283. (206 == f.status || 200 == f.status) && b(f.response) && e < g && (c += d,
  3284. e += d,
  3285. e = e < g - 1 ? e : g - 1,
  3286. h(c, e))
  3287. }
  3288. ;
  3289. f.send()
  3290. };
  3291. h(0, d - 1)
  3292. /* } else
  3293. c && c() */
  3294. } else
  3295. c && c()
  3296. }
  3297. ;
  3298. c && (e.onerror = function() {
  3299. c()
  3300. }
  3301. );
  3302. e.send()
  3303. }
  3304. };
  3305. function PlaybackControls(a) {
  3306. this.debugString = "";
  3307. this.init = !1;
  3308. this.speedList = this.cameraList = this.animationList = this.playButton = this.timelineSlider = this.playbackRegion = this.previousFrameButton = this.nextFrameButton = this.pauseButton = this.playButton = 0;
  3309. this.visible = !1;
  3310. this.backgroundRegion = this.screenButton = 0;
  3311. this.guiScreen = a;
  3312. this.playbackRegion = new GUIRegion(a);
  3313. this.idealSliderWidth = 650;
  3314. this.totalListBoxPixelsX = 0;
  3315. this.minWidth = 500;
  3316. this.compactMode = !1;
  3317. this.ui = a.ui;
  3318. var b = "animationpause" + a.imageSetNumber + "x.png"
  3319. , c = "animationplay" + a.imageSetNumber + "x.png"
  3320. , d = "timelineLE" + a.imageSetNumber + "x.png"
  3321. , e = "timelineM" + a.imageSetNumber + "x.png"
  3322. , f = "timelineRE" + a.imageSetNumber + "x.png"
  3323. , g = a.ui.viewer.scene.sceneAnimator.animations.length;
  3324. if (0 != g) {
  3325. var h = this.idealSliderWidth;
  3326. this.bottomOffset = 85;
  3327. this.centerOffset = 60;
  3328. var k = a.width / 2 + this.centerOffset
  3329. , l = k - h / 2
  3330. , k = k + h / 2
  3331. , n = l - 14 - 32
  3332. , m = k - n
  3333. , p = 32 / a.height
  3334. , r = this.bottomOffset / a.height
  3335. , s = this.playbackRegion;
  3336. s.controlRect.widthPercent = m / a.width;
  3337. s.controlRect.heightPercent = p;
  3338. s.controlRect.xPercent = n / a.width;
  3339. s.controlRect.yPercent = r;
  3340. p = 32 / m;
  3341. this.pauseButton = new Button(this.guiScreen);
  3342. this.pauseButton.controlRect.set(0, 0.125, p, 0.75);
  3343. this.pauseButton.controlRect.opacity = 0.5;
  3344. s.controlRect.registerChildControlRect(this.pauseButton.controlRect);
  3345. this.pauseButton.linkControl(s.addImageElement(this.pauseButton.controlRect, b));
  3346. this.playButton = new Button(this.guiScreen);
  3347. this.playButton.controlRect.set(0, 0.125, p, 0.75);
  3348. this.playButton.controlRect.opacity = 0.5;
  3349. s.controlRect.registerChildControlRect(this.playButton.controlRect);
  3350. this.playButton.linkControl(s.addImageElement(this.playButton.controlRect, c));
  3351. b = h / m;
  3352. m = (l - n) / m;
  3353. this.timelineSlider = new TimelineSlider(this.guiScreen,s);
  3354. this.timelineSlider.controlRect.set(m, 0.03125, b, 1);
  3355. s.controlRect.registerChildControlRect(this.timelineSlider.controlRect);
  3356. this.timelineSlider.setBackground3x1(s, d, e, f);
  3357. this.pauseButton.controlRect.showControl(!a.ui.viewer.scene.sceneAnimator.paused);
  3358. this.playButton.controlRect.showControl(a.ui.viewer.scene.sceneAnimator.paused);
  3359. d = k + 14;
  3360. e = this.bottomOffset + 4;
  3361. f = a.ui.viewer.scene.sceneAnimator.animations[0].cameraObjects.length;
  3362. a.ui.viewer.scene.sceneAnimator.selectDefaultCamera();
  3363. a.ui.viewer.scene.sceneAnimator.setViewFromSelectedCamera();
  3364. this.maxListPixelsX = 0;
  3365. if (1 < f) {
  3366. this.cameraList = new ListBox(a);
  3367. for (m = 0; m < f; m++)
  3368. this.cameraList.addItem(a.ui.viewer.scene.sceneAnimator.animations[0].cameraObjects[m].name, 0, 0);
  3369. this.cameraList.spawnControl(d, e, 10, 24, !0, 8);
  3370. this.cameraList.selectItem(a.ui.viewer.scene.sceneAnimator.selectedCameraIndex);
  3371. this.maxListPixelsX = this.cameraList.localPixelsX;
  3372. this.totalListBoxPixelsX += this.cameraList.localPixelsX + 14
  3373. }
  3374. if (1 < g) {
  3375. this.animationList = new ListBox(a);
  3376. for (m = 0; m < g; m++)
  3377. this.animationList.addItem(a.ui.viewer.scene.sceneAnimator.animations[m].name, 0, 0);
  3378. this.animationList.spawnControl(d, e, 10, 24, !0, 8);
  3379. this.maxListPixelsX < this.animationList.localPixelsX && (this.maxListPixelsX = this.animationList.localPixelsX);
  3380. this.totalListBoxPixelsX += this.animationList.localPixelsX + 14;
  3381. this.animationList.selectItem(a.ui.viewer.scene.sceneAnimator.selectedAnimationIndex)
  3382. }
  3383. d = n - 44 - 14;
  3384. m = k - d + this.totalListBoxPixelsX;
  3385. this.speedList = new ListBox(a);
  3386. this.speedList.addItem("4.0x", 4, 0);
  3387. this.speedList.addItem("2.0x", 4, 0);
  3388. this.speedList.addItem("1.0x", 4, 0);
  3389. this.speedList.addItem("0.5x", 4, 0);
  3390. this.speedList.addItem("0.25x", -2, 0);
  3391. this.speedList.spawnControl(d, e, 44, 24, !1, 0);
  3392. this.speedList.selectItem(2);
  3393. m > a.width && (this.idealSliderWidth = a.width - (118 + (this.totalListBoxPixelsX + 14)) - this.centerOffset,
  3394. a = 0,
  3395. this.cameraList && a++,
  3396. this.animationList && a++,
  3397. 1 == a && (this.idealSliderWidth += 56,
  3398. this.centerOffset -= 14),
  3399. 2 == a && (this.idealSliderWidth += 63,
  3400. this.centerOffset -= 63));
  3401. this.setupCallbacks()
  3402. }
  3403. }
  3404. PlaybackControls.prototype.resize = function(a) {
  3405. a.ui.viewer.scene.sceneAnimator.showPlayControls || (a.width = 1,
  3406. a.height = 1);
  3407. this.compactMode = a.width < this.minWidth;
  3408. var b = this.bottomOffset
  3409. , c = this.bottomOffset + 4
  3410. , d = 0;
  3411. 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);
  3412. var e = a.width - d - 72;
  3413. 0 == d && (e -= 14);
  3414. var f = 116
  3415. , g = f + e + 14;
  3416. this.compactMode && (f = 58,
  3417. e += 44 + d,
  3418. 0 < d && (b += 32),
  3419. !d && (c += 32));
  3420. var d = 32 / e
  3421. , h = d + 14 / e
  3422. , k = 1 - h
  3423. , l = this.playbackRegion;
  3424. l.controlRect.widthPercent = e / a.width;
  3425. l.controlRect.heightPercent = 32 / a.height;
  3426. l.controlRect.xPercent = f / a.width;
  3427. l.controlRect.yPercent = b / a.height;
  3428. this.pauseButton.controlRect.set(0, 0.125, d, 0.75);
  3429. this.playButton.controlRect.set(0, 0.125, d, 0.75);
  3430. this.timelineSlider.controlRect.set(h, 0.03125, k, 1);
  3431. this.timelineSlider.setSize(e - 46, 32);
  3432. l.controlRect.updateElement();
  3433. l.controlRect.updateChildElements();
  3434. this.speedList.setControl(58, c, 44, 24, !1);
  3435. this.cameraList && (this.cameraList.setControl(g, c, 10, 24, !0, 8),
  3436. g += this.cameraList.localPixelsX + 14);
  3437. this.animationList && this.animationList.setControl(g, c, 10, 24, !0, 8);
  3438. this.timelineSlider.backgroundControl.alignBackground()
  3439. }
  3440. ;
  3441. PlaybackControls.prototype.setupCallbacks = function() {
  3442. var a = function(a) {
  3443. "0.01x" == this.speedList.selectedItemText && this.ui.viewer.scene.sceneAnimator.setPlaybackSpeed(0.01);
  3444. "0.05x" == this.speedList.selectedItemText && this.ui.viewer.scene.sceneAnimator.setPlaybackSpeed(0.05);
  3445. "0.25x" == this.speedList.selectedItemText && this.ui.viewer.scene.sceneAnimator.setPlaybackSpeed(0.25);
  3446. "0.5x" == this.speedList.selectedItemText && this.ui.viewer.scene.sceneAnimator.setPlaybackSpeed(0.5);
  3447. "1.0x" == this.speedList.selectedItemText && this.ui.viewer.scene.sceneAnimator.setPlaybackSpeed(1);
  3448. "2.0x" == this.speedList.selectedItemText && this.ui.viewer.scene.sceneAnimator.setPlaybackSpeed(2);
  3449. "4.0x" == this.speedList.selectedItemText && this.ui.viewer.scene.sceneAnimator.setPlaybackSpeed(4)
  3450. }
  3451. .bind(this)
  3452. , b = function(a) {
  3453. this.ui.viewer.scene.sceneAnimator.selectCamera(this.cameraList.selectedIndex);
  3454. this.ui.viewer.wake()
  3455. }
  3456. .bind(this)
  3457. , c = function(a) {
  3458. this.ui.viewer.scene.sceneAnimator.selectAnimation(this.animationList.selectedIndex);
  3459. this.ui.viewer.wake()
  3460. }
  3461. .bind(this);
  3462. this.speedList && (this.speedList.selectionChangedCallback = a);
  3463. this.cameraList && (this.cameraList.selectionChangedCallback = b);
  3464. this.animationList && (this.animationList.selectionChangedCallback = c);
  3465. this.playButton.controlRect.linkedControl.onclick = function() {
  3466. this.ui.viewer.scene.sceneAnimator.pause(!1);
  3467. this.playButton.controlRect.showControl(!1);
  3468. this.pauseButton.controlRect.showControl(!0);
  3469. this.ui.viewer.wake()
  3470. }
  3471. .bind(this);
  3472. this.pauseButton.controlRect.linkedControl.onclick = function() {
  3473. this.ui.viewer.scene.sceneAnimator.pause(!0);
  3474. this.playButton.controlRect.showControl(!0);
  3475. this.pauseButton.controlRect.showControl(!1)
  3476. }
  3477. .bind(this)
  3478. }
  3479. ;
  3480. function PostRender(a, b, c) {
  3481. this.gl = a;
  3482. this.desc = b;
  3483. b = [];
  3484. 0 != this.desc.sharpen && b.push("#define SHARPEN");
  3485. (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]) && b.push("#define BLOOM");
  3486. 0 != this.desc.vignette[3] && b.push("#define VIGNETTE");
  3487. 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] || b.push("#define SATURATION");
  3488. 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] || b.push("#define CONTRAST");
  3489. 0 != this.desc.grain && b.push("#define GRAIN");
  3490. 1 == this.desc.toneMap ? b.push("#define REINHARD") : 2 == this.desc.toneMap && b.push("#define HEJL");
  3491. this.desc.colorLUT && b.push("#define COLOR_LUT");
  3492. this.sampleIndex = 0;
  3493. this.sampleCount = 1;
  3494. c && (this.sampleCount = 4,
  3495. this.sampleOffsets = [[-0.5, -0.5], [0.5, -0.5], [-0.5, 0.5], [0.5, 0.5]]);
  3496. this.aaShader = a.shaderCache.fromURLs("postvert.glsl", "postaa.glsl");
  3497. this.shader = a.shaderCache.fromURLs("postvert.glsl", "postfrag.glsl", b);
  3498. this.plainShader = a.shaderCache.fromURLs("postvert.glsl", "postfrag.glsl", []);
  3499. this.fullscreenTriangle = a.createBuffer();
  3500. a.bindBuffer(a.ARRAY_BUFFER, this.fullscreenTriangle);
  3501. c = new Float32Array([0, 0, 2, 0, 0, 2]);
  3502. a.bufferData(a.ARRAY_BUFFER, c, a.STATIC_DRAW);
  3503. a.bindBuffer(a.ARRAY_BUFFER, null);
  3504. if (this.useBloom) {
  3505. this.bloomTextures = [];
  3506. this.bloomTargets = [];
  3507. for (c = 0; 2 > c; ++c)
  3508. b = {
  3509. width: 256,
  3510. height: 256,
  3511. clamp: !0
  3512. },
  3513. this.bloomTextures[c] = new Texture(a,b),
  3514. this.bloomTextures[c].loadArray(null, a.RGBA, a.ext.textureHalf && a.ext.textureHalfLinear ? a.ext.textureHalf.HALF_FLOAT_OES : a.UNSIGNED_BYTE),
  3515. this.bloomTargets[c] = new Framebuffer(a,{
  3516. width: b.width,
  3517. height: b.height,
  3518. color0: this.bloomTextures[c]
  3519. });
  3520. for (this.bloomSamples = 64; this.bloomSamples + 16 >= a.limits.fragmentUniforms; )
  3521. this.bloomSamples /= 2;
  3522. this.bloomShader = a.shaderCache.fromURLs("postvert.glsl", "bloom.glsl", ["#define BLOOM_SAMPLES " + this.bloomSamples]);
  3523. this.shrinkShader = a.shaderCache.fromURLs("postvert.glsl", "bloomshrink.glsl")
  3524. }
  3525. a = new Uint8Array(16384);
  3526. for (c = 0; 16384 > c; c++) {
  3527. b = 255 * Math.random();
  3528. var d = 255 * Math.random();
  3529. a[c] = 0.5 * (b + d)
  3530. }
  3531. this.noiseTexture = new Texture(this.gl,{
  3532. width: 128,
  3533. height: 128
  3534. });
  3535. this.noiseTexture.loadArray(a, this.gl.LUMINANCE);
  3536. this.desc.colorLUT && (a = this.desc.colorLUT,
  3537. this.colorLUT = new Texture(this.gl,{
  3538. width: a.length / 3 | 0,
  3539. height: 1,
  3540. clamp: !0
  3541. }),
  3542. this.colorLUT.loadArray(new Uint8Array(a), this.gl.RGB));
  3543. this.blackTexture = new Texture(this.gl,{
  3544. width: 1,
  3545. height: 1
  3546. });
  3547. this.blackTexture.loadArray(new Uint8Array([0, 0, 0, 0]));
  3548. this.bloomResult = this.blackTexture
  3549. }
  3550. PostRender.prototype.prepareBloom = function(a) {
  3551. if (this.useBloom && this.bloomShader.complete() && this.shrinkShader.complete()) {
  3552. this.shrinkShader.bind();
  3553. this.bloomTargets[1].bind();
  3554. a.bind(this.shrinkShader.samplers.tInput);
  3555. this.fillScreen(this.shrinkShader.attribs.vCoord);
  3556. this.bloomShader.bind();
  3557. var b = [];
  3558. this.bloomTargets[0].bind();
  3559. this.bloomTextures[1].bind(this.bloomShader.samplers.tInput);
  3560. for (var c = 0, d = 0; d < this.bloomSamples; ++d) {
  3561. var e = -1 + 2 * d / (this.bloomSamples - 1), f;
  3562. f = 4 * e;
  3563. f = Math.exp(-0.5 * f * f / 1) / 2.50662827463;
  3564. c += f;
  3565. b[4 * d + 0] = e * this.desc.bloomSize;
  3566. b[4 * d + 1] = 0;
  3567. b[4 * d + 2] = f;
  3568. b[4 * d + 3] = 0
  3569. }
  3570. for (d = 0; d < this.bloomSamples; ++d)
  3571. b[4 * d + 2] /= c;
  3572. this.gl.uniform4fv(this.bloomShader.params.uKernel, b);
  3573. this.fillScreen(this.bloomShader.attribs.vCoord);
  3574. this.bloomTargets[1].bind();
  3575. this.bloomTextures[0].bind(this.bloomShader.samplers.tInput);
  3576. for (d = 0; d < this.bloomSamples; ++d)
  3577. c = b[4 * d + 0],
  3578. c *= a.desc.width / a.desc.height,
  3579. b[4 * d + 0] = 0,
  3580. b[4 * d + 1] = c;
  3581. this.gl.uniform4fv(this.bloomShader.params.uKernel, b);
  3582. this.fillScreen(this.bloomShader.attribs.vCoord);
  3583. this.bloomResult = this.bloomTextures[1]
  3584. } else
  3585. this.bloomResult = this.blackTexture
  3586. }
  3587. ;
  3588. PostRender.prototype.computeParams = function(a, b) {
  3589. var c = this.desc
  3590. , d = {};
  3591. d.scale = [c.contrast[0] * c.contrast[3], c.contrast[1] * c.contrast[3], c.contrast[2] * c.contrast[3]];
  3592. d.bias = [c.bias[0] * c.bias[3], c.bias[1] * c.bias[3], c.bias[2] * c.bias[3]];
  3593. 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]];
  3594. var e = [c.brightness[0] * c.brightness[3], c.brightness[1] * c.brightness[3], c.brightness[2] * c.brightness[3]];
  3595. d.scale = [d.scale[0] * e[0], d.scale[1] * e[1], d.scale[2] * e[2]];
  3596. d.bias = [d.bias[0] * e[0], d.bias[1] * e[1], d.bias[2] * e[2]];
  3597. d.saturation = [c.saturation[0] * c.saturation[3], c.saturation[1] * c.saturation[3], c.saturation[2] * c.saturation[3]];
  3598. d.bloomColor = [c.bloomColor[0] * c.bloomColor[3], c.bloomColor[1] * c.bloomColor[3], c.bloomColor[2] * c.bloomColor[3]];
  3599. d.sharpen = [c.sharpen, 0.25 * c.sharpen, c.sharpenLimit];
  3600. d.sharpenKernel = [1 / a, 0, 0, 1 / b];
  3601. e = a > b ? a : b;
  3602. d.vignetteAspect = [a / e, b / e, 0.5 * a / e, 0.5 * b / e];
  3603. d.vignette = [2 * (1 - c.vignette[0]) * c.vignette[3], 2 * (1 - c.vignette[1]) * c.vignette[3], 2 * (1 - c.vignette[2]) * c.vignette[3], c.vignetteCurve];
  3604. var e = 1 / this.noiseTexture.desc.width
  3605. , f = 1 / this.noiseTexture.desc.height
  3606. , g = 1 - c.grainSharpness;
  3607. d.grainCoord = [e * a, f * b, 0.5 * g * e, 0.5 * g * f];
  3608. d.grainScaleBias = [2 * c.grain, -c.grain];
  3609. return d
  3610. }
  3611. ;
  3612. PostRender.prototype.present = function(a, b, c, d) {
  3613. d || this.prepareBloom(a);
  3614. 1 < this.sampleCount && this.allocAABuffer(b, c);
  3615. d = d ? this.plainShader : this.shader;
  3616. if (d.bind()) {
  3617. var e = this.gl
  3618. , f = d.samplers
  3619. , g = d.params
  3620. , h = this.computeParams(b, c);
  3621. a.bind(f.tInput);
  3622. this.bloomResult.bind(f.tBloom);
  3623. this.noiseTexture.bind(f.tGrain);
  3624. this.colorLUT && this.colorLUT.bind(f.tLUT);
  3625. e.uniform3fv(g.uScale, h.scale);
  3626. e.uniform3fv(g.uBias, h.bias);
  3627. e.uniform3fv(g.uSaturation, h.saturation);
  3628. e.uniform4fv(g.uSharpenKernel, h.sharpenKernel);
  3629. e.uniform3fv(g.uSharpness, h.sharpen);
  3630. e.uniform3fv(g.uBloomColor, h.bloomColor);
  3631. e.uniform4fv(g.uVignetteAspect, h.vignetteAspect);
  3632. e.uniform4fv(g.uVignette, h.vignette);
  3633. e.uniform4fv(g.uGrainCoord, h.grainCoord);
  3634. e.uniform2fv(g.uGrainScaleBias, h.grainScaleBias);
  3635. if (a = 1 < this.sampleCount && 0 <= this.sampleIndex) {
  3636. var k = 1 / (1 + this.sampleIndex);
  3637. this.sampleIndex += 1;
  3638. 1 > k && (e.enable(e.BLEND),
  3639. e.blendColor(k, k, k, k),
  3640. e.blendFunc(e.CONSTANT_ALPHA, e.ONE_MINUS_CONSTANT_ALPHA));
  3641. this.aaTarget.bind()
  3642. } else
  3643. Framebuffer.bindNone(e),
  3644. 1 < this.sampleCount && (this.sampleIndex += 1);
  3645. e.viewport(0, 0, b, c);
  3646. this.fillScreen(d.attribs.vCoord);
  3647. a && (1 > k && e.disable(e.BLEND),
  3648. Framebuffer.bindNone(e),
  3649. this.aaShader.bind(),
  3650. this.aaBuffer.bind(this.aaShader.samplers.tInput),
  3651. this.fillScreen(this.aaShader.attribs.vCoord))
  3652. }
  3653. }
  3654. ;
  3655. PostRender.prototype.allocAABuffer = function(a, b) {
  3656. this.aaBuffer && this.aaBuffer.desc.width == a && this.aaBuffer.desc.height == b || (this.aaBuffer && this.aaBuffer.destroy(),
  3657. this.aaBuffer = new Texture(this.gl,{
  3658. width: a,
  3659. height: b,
  3660. clamp: !0
  3661. }),
  3662. this.aaBuffer.loadArray(),
  3663. this.aaTarget = new Framebuffer(this.gl,{
  3664. color0: this.aaBuffer,
  3665. ignoreStatus: !0
  3666. }))
  3667. }
  3668. ;
  3669. PostRender.prototype.adjustProjectionForSupersampling = function(a) {
  3670. if (1 < this.sampleCount) {
  3671. var b = this.currentSample()
  3672. , c = this.sampleOffsets[b][0] / a.size[0]
  3673. , b = this.sampleOffsets[b][1] / a.size[1]
  3674. , c = Matrix.translation(Matrix.empty(), c, b, 0);
  3675. Matrix.mul(a.projectionMatrix, c, a.projectionMatrix)
  3676. }
  3677. }
  3678. ;
  3679. PostRender.prototype.discardAAHistory = function() {
  3680. this.sampleIndex = -1
  3681. }
  3682. ;
  3683. PostRender.prototype.currentSample = function() {
  3684. return (0 > this.sampleIndex ? 0 : this.sampleIndex) % this.sampleCount
  3685. }
  3686. ;
  3687. PostRender.prototype.fillScreen = function(a) {
  3688. var b = this.gl;
  3689. b.bindBuffer(b.ARRAY_BUFFER, this.fullscreenTriangle);
  3690. b.enableVertexAttribArray(a);
  3691. b.vertexAttribPointer(a, 2, b.FLOAT, !1, 0, 0);
  3692. b.drawArrays(b.TRIANGLES, 0, 3);
  3693. b.disableVertexAttribArray(a);
  3694. b.bindBuffer(b.ARRAY_BUFFER, null)
  3695. }
  3696. ;
  3697. PostRender.prototype.blitTexture = function(a) {
  3698. this.aaShader.bind();
  3699. a.bind(this.aaShader.samplers.tInput);
  3700. this.fillScreen(this.aaShader.attribs.vCoord)
  3701. }
  3702. ;
  3703. function Scene(a) {
  3704. this.gl = a;
  3705. this.name = "untitled";
  3706. this.meshes = [];
  3707. this.meshRenderables = [];
  3708. this.materials = {};
  3709. this.sky = this.view = null;
  3710. this.selectedPartIndex = 0;
  3711. this.soloPart = !1;
  3712. this.miscnotes = "";
  3713. this.nextView = null;
  3714. this.viewFade = 0;
  3715. this.refractionSurface = this.shadow = this.stripData = this.lights = null;
  3716. this.sceneAnimator = this.frameCounter = 0;
  3717. this.sceneLoaded = !1;
  3718. this.debugString = ""
  3719. }
  3720. Scene.prototype.load = function(a) {
  3721. var b = this.gl, c, d = a.extract("scene.json");
  3722. if (void 0 !== d) {
  3723. /* if (!a.checkSignature(d))
  3724. return !1; */
  3725. d = (new ByteStream(d.data)).asString();
  3726. if (null == d || 0 >= d.length)
  3727. return !1;
  3728. try {
  3729. c = JSON.parse(d)
  3730. } catch (e) {
  3731. return console.error(e),
  3732. !1
  3733. }
  3734. } else
  3735. return !1;
  3736. this.metaData = c.metaData;
  3737. this.view = new View(c.mainCamera.view);
  3738. this.sky = new Sky(this.gl,a,c.sky);
  3739. this.lights = new Lights(c.lights,this.view);
  3740. this.materialsList = [];
  3741. this.materials = {};
  3742. for (var f in c.materials) {
  3743. var g = c.materials[f];
  3744. g.lightCount = this.lights.count;
  3745. g.shadowCount = this.lights.shadowCount;
  3746. d = new Material(this.gl,a,g);
  3747. this.materials[g.name] = d;
  3748. this.materialsList.push(d)
  3749. }
  3750. if (c.meshes)
  3751. for (g = 0; g < c.meshes.length; ++g) {
  3752. f = c.meshes[g];
  3753. f = new Mesh(this.gl,f,a.extract(f.file));
  3754. this.meshes.push(f);
  3755. for (var h = 0; h < f.desc.subMeshes.length; ++h) {
  3756. var k = f.desc.subMeshes[h];
  3757. if (d = this.materials[k.material])
  3758. f.numSubMeshes++,
  3759. this.meshRenderables.push(new MeshRenderable(f,k,d))
  3760. }
  3761. }
  3762. this.bounds = new Bounds(this.meshes);
  3763. this.postRender = new PostRender(this.gl,c.mainCamera.post,!0);
  3764. this.shadow = new ShadowCollector(b,this.lights.shadowCount);
  3765. this.cameras = c.Cameras;
  3766. c.AnimData && (this.sceneAnimator = new SceneAnimator(this,a,c.AnimData));
  3767. c.fog && (this.fog = new Fog(b,c.fog));
  3768. c.shadowFloor && (this.shadowFloor = new ShadowFloor(b,c.shadowFloor,this.shadow,this.lights));
  3769. return this.sceneLoaded = !0
  3770. }
  3771. ;
  3772. Scene.prototype.update = function() {
  3773. this.sceneAnimator && (this.frameCounter++,
  3774. this.lights.flagUpdateAnimatedLighting(),
  3775. this.sceneAnimator.drawAnimated && (1 == this.frameCounter ? this.sceneAnimator.resetPlayback() : this.sceneAnimator.updateAnimationPlayback()));
  3776. this.lights.update(this.view, this.bounds)
  3777. }
  3778. ;
  3779. Scene.prototype.collectShadows = function(a) {
  3780. this.shadow.collect(this, a)
  3781. }
  3782. ;
  3783. Scene.prototype.draw = function(a) {
  3784. var b = this.gl;
  3785. if (this.sceneLoaded) {
  3786. this.sky.setClearColor();
  3787. b.clear(b.COLOR_BUFFER_BIT | b.DEPTH_BUFFER_BIT | b.STENCIL_BUFFER_BIT);
  3788. b.enable(b.DEPTH_TEST);
  3789. this.sky.draw(this);
  3790. this.shadowFloor && this.shadowFloor.draw(this);
  3791. for (var c = 0; c < this.meshRenderables.length; ++c)
  3792. this.meshRenderables[c].material.usesBlending || this.meshRenderables[c].material.usesRefraction || !this.meshRenderables[c].visible || this.meshRenderables[c].draw(this);
  3793. b.enable(b.POLYGON_OFFSET_FILL);
  3794. b.polygonOffset(1, 1);
  3795. b.colorMask(!1, !1, !1, !1);
  3796. for (c = 0; c < this.meshRenderables.length; ++c)
  3797. this.meshRenderables[c].drawAlphaPrepass(this);
  3798. b.colorMask(!0, !0, !0, !0);
  3799. b.disable(b.POLYGON_OFFSET_FILL);
  3800. b.depthFunc(b.LEQUAL);
  3801. b.depthMask(!1);
  3802. for (c = 0; c < this.meshRenderables.length; ++c)
  3803. this.meshRenderables[c].material.usesBlending && this.meshRenderables[c].visible && this.meshRenderables[c].draw(this);
  3804. b.disable(b.BLEND);
  3805. b.depthMask(!0);
  3806. b.depthFunc(b.LESS);
  3807. for (var d = !1, c = 0; c < this.meshRenderables.length; ++c)
  3808. if (this.meshRenderables[c].material.usesRefraction) {
  3809. d = !0;
  3810. break
  3811. }
  3812. if (d)
  3813. for (this.refractionSurface && this.refractionSurface.desc.width == a.color0.desc.width && this.refractionSurface.desc.height == a.color0.desc.height || (this.refractionSurface = new Texture(b,a.color0.desc),
  3814. this.refractionSurface.loadArray(null, a.color0.format, a.color0.componentType),
  3815. this.refractionBuffer = new Framebuffer(this.gl,{
  3816. color0: this.refractionSurface
  3817. })),
  3818. this.refractionBuffer.bind(),
  3819. this.postRender.blitTexture(a.color0),
  3820. a.bind(),
  3821. c = 0; c < this.meshRenderables.length; ++c)
  3822. this.meshRenderables[c].material.usesRefraction && this.meshRenderables[c].visible && this.meshRenderables[c].draw(this);
  3823. if (this.stripData.activeWireframe() && 0 < this.meshRenderables.length) {
  3824. for (c = 0; c < this.meshRenderables.length; ++c)
  3825. this.meshRenderables[c].visible && this.meshRenderables[c].drawWire(this);
  3826. b.depthMask(!0)
  3827. }
  3828. b.disable(b.BLEND)
  3829. }
  3830. }
  3831. ;
  3832. Scene.prototype.drawSecondary = function(a) {
  3833. this.fog && this.fog.draw(this, a)
  3834. }
  3835. ;
  3836. Scene.prototype.complete = function() {
  3837. if (!this.sky.complete() || !this.shadow.complete() || this.fog && !this.fog.complete() || this.shadowFloor && !this.shadowFloor.complete())
  3838. return !1;
  3839. for (var a = 0; a < this.meshRenderables.length; ++a)
  3840. if (!this.meshRenderables[a].complete())
  3841. return !1;
  3842. return !0
  3843. }
  3844. ;
  3845. function SceneAnimator(a, b, c) {
  3846. this.scene = a;
  3847. this.animations = [];
  3848. this.skinningRigs = [];
  3849. this.meshIDs = [];
  3850. this.lightIDs = [];
  3851. this.materialIDs = [];
  3852. this.views = [];
  3853. this.viewYawOffsets = [];
  3854. this.viewPitchOffsets = [];
  3855. this.cameraObjectIndices = [];
  3856. this.cameraChildrenIndices = [];
  3857. this.subMeshObjectIndices = [];
  3858. this.subMeshLiveIndices = [];
  3859. this.scene = a;
  3860. this.selectedCameraIndex = -1;
  3861. this.selectedAnimationIndex = 0;
  3862. this.debugString = "";
  3863. this.scenePlaybackSpeed = this.playbackSpeed = 1;
  3864. this.animationProgress = this.totalSeconds = 0; //进行到的时间
  3865. this.paused = this.autoAdvanceNextAnimation = !1;
  3866. this.animateVisibility = this.drawAnimated = this.linkSceneObjects = this.loadSkinningRigs = this.animateMaterials = this.animateTurntables = this.enableSkinning = this.animateMeshes = this.animateLights = this.playAnimations = this.loadAnimations = !0;
  3867. this.showDebugInfo = !1;
  3868. this.loopCount = 0;
  3869. this.loopTurntables = this.lockPlayback = !1;
  3870. this.fogObjectIndex = -1;
  3871. this.unitScaleSkinnedMeshes = !0;
  3872. this.sceneScale = c.sceneScale;
  3873. this.defaultCameraGlobalIndex = c.selectedCamera;
  3874. this.selectedAnimationIndex = c.selectedAnimation;
  3875. this.autoPlayAnims = c.autoPlayAnims;
  3876. this.showPlayControls = c.showPlayControls;
  3877. c.scenePlaybackSpeed && (this.scenePlaybackSpeed = c.scenePlaybackSpeed,
  3878. 0 == this.scenePlaybackSpeed && (this.scenePlaybackSpeed = 1));
  3879. this.autoPlayAnims || (this.paused = !0);
  3880. if (this.loadAnimations) {
  3881. if (c.meshIDs)
  3882. for (var d = c.meshIDs.length, e = 0; e < d; ++e) {
  3883. var f = c.meshIDs[e].partIndex;
  3884. this.meshIDs.push(f)
  3885. }
  3886. if (c.lightIDs)
  3887. for (d = c.lightIDs.length,
  3888. e = 0; e < d; ++e)
  3889. f = c.lightIDs[e],
  3890. f = f.partIndex,
  3891. this.lightIDs.push(f);
  3892. if (c.materialIDs)
  3893. for (d = c.materialIDs.length,
  3894. e = 0; e < d; ++e)
  3895. f = c.materialIDs[e],
  3896. f = f.partIndex,
  3897. this.materialIDs.push(f);
  3898. this.numMatricesInTable = c.numMatrices;
  3899. e = b.get("MatTable.bin");
  3900. f = new ByteStream(e.data);
  3901. e || (this.numMatricesInTable = 0,
  3902. this.debugString += "<br>No mattable?");
  3903. if (c.skinningRigs && this.loadSkinningRigs)
  3904. {
  3905. d = c.skinningRigs.length;
  3906. for (e = 0; e < d; ++e) {
  3907. var g = new SkinningRig(b,c.skinningRigs[e],f);
  3908. if("" == g.debugString)
  3909. {
  3910. this.skinningRigs.push(g)
  3911. }
  3912. else
  3913. {
  3914. this.debugString += "<br>Error loading skinning rig " + e + " :" + g.debugString;
  3915. this.debugString += "<br>Skipping the rest";
  3916. e = d;
  3917. }
  3918. }
  3919. }
  3920. if (c.animations)
  3921. {
  3922. f = c.animations.length;
  3923. for (e = 0; e < f; ++e)
  3924. {
  3925. d = new Animation(b,c.animations[e]);
  3926. this.animations.push(d);
  3927. }
  3928. }
  3929. this.startMS = Date.now(); //(现在时刻-已经播放的时间)
  3930. f = this.animations.length;
  3931. if (this.linkSceneObjects && 0 != f) {
  3932. for (e = 0; e < f; e++)
  3933. {
  3934. b = this.animations[e];
  3935. d = b.animatedObjects.length;
  3936. for (c = 0; c < d; c++)
  3937. {
  3938. g = b.animatedObjects[c];
  3939. if("LightSO" == g.sceneObjectType)
  3940. {
  3941. g.lightIndex = this.findLightIndexByPartIndex(c);
  3942. if(-1 != g.lightIndex)
  3943. {
  3944. b.lightObjects.push(g);
  3945. }
  3946. else
  3947. {
  3948. this.debugString += "<br> got light not in scene " + g.name;
  3949. }
  3950. }
  3951. if("FogSO" == g.sceneObjectType)
  3952. {
  3953. this.fogObjectIndex = c;
  3954. }
  3955. if("SubMeshSO" == g.sceneObjectType && 0 == e)
  3956. {
  3957. this.subMeshObjectIndices.push(c);
  3958. this.subMeshLiveIndices.push(-1);
  3959. }
  3960. if("Material" == g.sceneObjectType)
  3961. {
  3962. g.materialIndex = this.findMaterialIndexByPartIndex(c);
  3963. if(-1 == g.materialIndex)
  3964. {
  3965. this.debugString += "<br> can't find material index for object " + c
  3966. }
  3967. else
  3968. {
  3969. b.materialObjects.push(g)
  3970. }
  3971. }
  3972. if("TurnTableSO" == g.sceneObjectType)
  3973. {
  3974. b.turnTableObjects.push(g);
  3975. }
  3976. if("MeshSO" == g.sceneObjectType)//如果是MeshSO,就是deformer(蒙皮)?
  3977. {
  3978. g.meshIndex = this.findMeshIndexByPartIndex(this.scene.meshes, c);
  3979. if(-1 == g.meshIndex)
  3980. {
  3981. this.debugString += "<br> can't find mesh index for object " + c;
  3982. this.logObjectInfo(c, 0);
  3983. }
  3984. else{
  3985. b.meshObjects.push(g);
  3986. g.mesh = this.scene.meshes[g.meshIndex];
  3987. if(-1 != g.skinningRigIndex && g.mesh && g.skinningRigIndex < this.skinningRigs.length)
  3988. {
  3989. g.skinningRig = this.skinningRigs[g.skinningRigIndex];
  3990. if(!g.skinningRig.isRigidSkin)
  3991. {
  3992. if(g.mesh.dynamicVertexData)
  3993. {
  3994. g.skinningRig.useOriginalMeshVertices(g.mesh);
  3995. }
  3996. else
  3997. {
  3998. this.debugString += "Skinning object - but mesh is not dynamic";
  3999. this.debugString += "<br>Rig index " + g.skinningRigIndex;
  4000. this.debugString += " not tagged as rigid";
  4001. }
  4002. }
  4003. }
  4004. }
  4005. }
  4006. "CameraSO" == g.sceneObjectType && b.cameraObjects.push(g);
  4007. }
  4008. }
  4009. b = this.animations[0];
  4010. c = b.cameraObjects.length;
  4011. for (e = 0; e < c; e++)
  4012. {
  4013. if (f = b.cameraObjects[e],d = this.scene.cameras[f.name]) {
  4014. if (d = d.view)
  4015. d = new View(d),
  4016. this.cameraObjectIndices.push(f.id),
  4017. this.views.push(d),
  4018. this.viewYawOffsets.push(0),
  4019. this.viewPitchOffsets.push(0)
  4020. } else
  4021. this.debugString += "<br>no camDesc for " + f.name,
  4022. this.views.push(a.view);
  4023. }
  4024. a = this.scene.meshes.length;
  4025. f = this.subMeshObjectIndices.length;
  4026. for (e = d = 0; e < a; e++)
  4027. {
  4028. g = this.scene.meshes[e];
  4029. for (c = 0; c < f; c++) {
  4030. var h = this.subMeshObjectIndices[c]
  4031. , k = b.animatedObjects[h]
  4032. , l = b.animatedObjects[k.parentIndex];
  4033. if(!l.mesh)
  4034. {
  4035. this.debugString += "<br>submesh parent object has no mesh?";
  4036. this.debugString += "<br>obj.name " + k.name;
  4037. this.debugString += "<br>parent.name " + l.name;
  4038. this.debugString += "<br>submesh index " + c;
  4039. this.debugString += "<br>obj.index " + h;
  4040. }
  4041. if (l.mesh == g) {
  4042. for (h = 0; h < g.numSubMeshes; h++)
  4043. {
  4044. this.subMeshLiveIndices[c + (g.numSubMeshes - 1 - h)] = d;
  4045. d++;
  4046. }
  4047. c = f
  4048. }
  4049. }
  4050. }
  4051. for (e = 0; e < f; e++)
  4052. {
  4053. if(-1 == this.subMeshLiveIndices[e])
  4054. {
  4055. this.debugString += "<br>Missing mesh? Unused submesh " + e + " of " + f;
  4056. }
  4057. }
  4058. this.showDebugInfo = this.stopEverything = this.runDebugMode = !1;
  4059. this.selectDefaultCamera();
  4060. this.findCameraChildren();
  4061. this.findFixedTransforms();
  4062. if(this.runDebugMode)
  4063. {
  4064. this.setAnimationProgress(0, !0);
  4065. if("" != this.debugString)
  4066. {
  4067. this.stopEverything = !0;
  4068. }
  4069. else
  4070. {
  4071. this.checkDebug();
  4072. }
  4073. }
  4074. }
  4075. }
  4076. else
  4077. {
  4078. this.debugString += "<br>Skip loading animation data";
  4079. }
  4080. }
  4081. SceneAnimator.prototype.logTimes = function() {
  4082. this.debugString += "<br>Times";
  4083. var a = this.animations[0]
  4084. , b = a.animatedObjects.length;
  4085. this.debugString += "<br>Animation totalSeconds " + a.totalSeconds;
  4086. this.debugString += "<br>Animation totalFrames " + a.totalFrames;
  4087. this.debugString += "<br>Animation totalObjects " + b;
  4088. for (var c = 0; c < b; c++) {
  4089. var d = a.animatedObjects[c];
  4090. this.debugString += "<br>Object: " + c;
  4091. this.debugString += " End: " + d.endTime;
  4092. this.debugString += " Length: " + d.animationLength;
  4093. this.debugString += " Frames: " + d.totalFrames
  4094. }
  4095. }
  4096. ;
  4097. SceneAnimator.prototype.flagAllForDebugging = function() {
  4098. for (var a = this.animations.length, b = 0; b < a; b++)
  4099. {
  4100. var c = this.animations[b];
  4101. var d = c.animatedObjects.length;
  4102. for (var e = 0; e < d; e++)
  4103. {
  4104. c.animatedObjects[e].debugMe = !0;
  4105. }
  4106. }
  4107. }
  4108. ;
  4109. SceneAnimator.prototype.checkDebug = function() {
  4110. this.debugString = "<br>--------------------------------------Debug Info:";
  4111. this.debugString += "<br>this.selectedAnimationIndex :" + this.selectedAnimationIndex;
  4112. var a = this.animations[this.selectedAnimationIndex]
  4113. , b = a.animatedObjects.length;
  4114. this.debugString += "<br>numAnimatedObjects :" + b;
  4115. "" != a.debugString && (this.debugString += "<br>--------------------------------------------------Got animation bug info:",
  4116. this.debugString += a.debugString,
  4117. this.showDebugInfo = this.stopEverything = !0,
  4118. a.debugString = "");
  4119. for (var c = 0; c < b; c++) {
  4120. var d = a.animatedObjects[c];
  4121. if ("" != d.debugString || "" != d.animatedLocalTransform.debugString)
  4122. {
  4123. this.debugString += "<br>--------------------------------------------------Got object bug info:";
  4124. this.debugString += d.debugString;
  4125. this.debugString += d.animatedLocalTransform.debugString;
  4126. this.showDebugInfo = this.stopEverything = !0;
  4127. d.debugString = "";
  4128. d.animatedLocalTransform.debugString = "";
  4129. }
  4130. if(d.skinningRig && "" != d.skinningRig.debugString)
  4131. {
  4132. this.debugString += "<br>--------------------------------------------------Got skin rig info:";
  4133. this.debugString += d.skinningRig.debugString;
  4134. d.skinningRig.debugString = "";
  4135. this.showDebugInfo = this.stopEverything = !0;
  4136. }
  4137. }
  4138. this.debugString += "<br>--------------------------------------Done Debug Info:"
  4139. }
  4140. ;
  4141. SceneAnimator.prototype.logObjectInfo = function(a, b) {
  4142. var c = this.animations[this.selectedAnimationIndex]
  4143. , d = b * c.originalFPS;
  4144. if (a >= c.animatedObjects.length)
  4145. {
  4146. this.debugString += "object index " + a + " exceeds " + c.animatedObjects.length;
  4147. }
  4148. else {
  4149. var e = c.animatedObjects[a]
  4150. , f = c.animatedObjects[e.modelPartIndex]
  4151. , g = c.getObjectAnimationFramePercent(e, b)
  4152. , h = c.getObjectAnimationFramePercent(f, b);
  4153. this.debugString = "";
  4154. this.debugString += "<br>Object Name: " + e.name;
  4155. this.debugString += "<br>Object Type: " + e.sceneObjectType;
  4156. this.debugString += "<br>Object Index: " + e.id;
  4157. this.debugString += "<br>Part Index: " + e.modelPartIndex;
  4158. this.debugString += "<br>Part Scale: " + e.modelPartScale;
  4159. this.debugString += "<br>Mesh Index: " + e.meshIndex;
  4160. this.debugString += "<br>Light Index: " + e.lightIndex;
  4161. this.debugString += "<br>Deformer Index: " + e.skinningRigIndex;
  4162. this.debugString += "<br>Parent Index: " + e.parentIndex;
  4163. this.debugString += "<br>Scene time " + b;
  4164. this.debugString += "<br>Scene framepercent " + d;
  4165. this.debugString += "<br>Object looped framepercent " + g;
  4166. this.debugString += "<br>Model looped framepercent " + h;
  4167. this.debugString += "<br>Object Anim length " + e.animationLength;
  4168. this.debugString += "<br>Object Total frames " + e.totalFrames;
  4169. this.debugString += "<br>Object FPS " + e.modelPartFPS;
  4170. this.debugString += "<br>Model Part Anim length " + f.animationLength;
  4171. this.debugString += "<br>Model total frames " + f.totalFrames;
  4172. this.debugString += "<br>Model Part FPS " + f.modelPartFPS;
  4173. d = Matrix.identity();
  4174. c.getWorldTransform(e.id, b, d, this.sceneScale, !0);
  4175. this.debugString += e.debugString;
  4176. var c = d[0]
  4177. , e = d[1]
  4178. , f = d[2]
  4179. , g = d[4]
  4180. , h = d[5]
  4181. , k = d[6]
  4182. , l = d[8]
  4183. , n = d[9]
  4184. , d = d[10];
  4185. Math.sqrt(c * c + e * e + f * f);
  4186. Math.sqrt(g * g + h * h + k * k);
  4187. Math.sqrt(l * l + n * n + d * d)
  4188. }
  4189. }
  4190. ;
  4191. SceneAnimator.prototype.resetPlayback = function() {
  4192. this.startMS = Date.now();
  4193. this.animationProgress = this.totalSeconds = 0;
  4194. this.setAnimationProgress(0, !0)
  4195. }
  4196. ;
  4197. SceneAnimator.prototype.pause = function(a) {
  4198. this.paused = a;
  4199. this.startMS = Date.now() - 1E3 * this.totalSeconds / (this.playbackSpeed * this.scenePlaybackSpeed)
  4200. }
  4201. ;
  4202. SceneAnimator.prototype.setAnimationProgress = function(a, b) {
  4203. var c = this.animations[this.selectedAnimationIndex];
  4204. this.animationProgress = a;
  4205. this.totalSeconds = c.totalSeconds * this.animationProgress;
  4206. this.totalSeconds -= 1 / c.originalFPS;
  4207. 0 > this.totalSeconds && (this.totalSeconds = 0);
  4208. this.startMS = Date.now() - 1E3 * this.totalSeconds / (this.playbackSpeed * this.scenePlaybackSpeed);
  4209. b && this.updateScene()
  4210. }
  4211. ;
  4212. SceneAnimator.prototype.setPlaybackSpeed = function(a) {
  4213. this.playbackSpeed = a;
  4214. this.startMS = Date.now() - 1E3 * this.totalSeconds / (this.playbackSpeed * this.scenePlaybackSpeed)
  4215. }
  4216. ;
  4217. SceneAnimator.prototype.resetCustomView = function() {
  4218. 0 <= this.selectedCameraIndex && this.selectedCameraIndex < this.views.length && (this.viewYawOffsets[this.selectedCameraIndex] = 0,
  4219. this.viewPitchOffsets[this.selectedCameraIndex] = 0,
  4220. this.scene.view.rotation[1] = this.views[this.selectedCameraIndex].rotation[1],
  4221. this.scene.view.rotation[0] = this.views[this.selectedCameraIndex].rotation[0],
  4222. this.setViewFromSelectedCamera())
  4223. }
  4224. ;
  4225. SceneAnimator.prototype.updateUserCamera = function() {
  4226. this.clearCacheForCameraChildren();
  4227. if (0 <= this.selectedCameraIndex && this.selectedCameraIndex < this.views.length && this.selectedAnimationIndex < this.animations.length) {
  4228. var a = this.cameraObjectIndices[this.selectedCameraIndex]
  4229. , b = this.animations[this.selectedAnimationIndex];
  4230. if (a < b.animatedObjects.length) {
  4231. var c = this.views[this.selectedCameraIndex]
  4232. , d = this.scene.view.rotation[1]
  4233. , e = this.scene.view.rotation[0]
  4234. , f = e - c.rotation[0];
  4235. this.viewYawOffsets[this.selectedCameraIndex] = d - c.rotation[1];
  4236. this.viewPitchOffsets[this.selectedCameraIndex] = f;
  4237. c = b.animatedObjects[a];
  4238. b.getObjectAnimationFramePercent(c, this.totalSeconds);
  4239. var f = Matrix.identity()
  4240. , g = Matrix.identity();
  4241. c.useFixedWorldTransform = !1;
  4242. c.useFixedLocalTransform = !1;
  4243. c.animatedLocalTransform.lockTransform = !1;
  4244. c.animatedLocalTransform.clearCachedTransforms();
  4245. c.cachedFrame0 = -1;
  4246. c.cachedFrame1 = -1;
  4247. c.cachedFrame2 = -1;
  4248. c.cachedFrame3 = -1;
  4249. c.cachedFrameUse0 = 0;
  4250. c.cachedFrameUse1 = 0;
  4251. c.cachedFrameUse2 = 0;
  4252. c.cachedFrameUse3 = 0;
  4253. b.getWorldTransform(a, this.totalSeconds, g, this.sceneScale, !1);
  4254. var a = g[0]
  4255. , h = g[1]
  4256. , k = g[2]
  4257. , l = g[4]
  4258. , n = g[5]
  4259. , m = g[6]
  4260. , p = g[8]
  4261. , r = g[9]
  4262. , s = g[10]
  4263. , a = Math.sqrt(a * a + h * h + k * k)
  4264. , l = Math.sqrt(l * l + n * n + m * m)
  4265. , n = Math.sqrt(p * p + r * r + s * s)
  4266. , m = -(this.scene.view.pivot[0] - g[12])
  4267. , h = -(this.scene.view.pivot[1] - g[13])
  4268. , g = -(this.scene.view.pivot[2] - g[14]);
  4269. 0 >= m * p + h * r + g * s && (d += 180);
  4270. d = Matrix.rotation(Matrix.empty(), d, 1);
  4271. e = Matrix.rotation(Matrix.empty(), e, 0);
  4272. Matrix.mul(f, d, e);
  4273. e = Math.sqrt(m * m + h * h + g * g);
  4274. d = this.scene.view.pivot[1] + f[9] * e;
  4275. g = this.scene.view.pivot[2] + f[10] * e;
  4276. f[12] = this.scene.view.pivot[0] + f[8] * e;
  4277. f[13] = d;
  4278. f[14] = g;
  4279. e = Matrix.identity();
  4280. b.getWorldTransform(c.parentIndex, this.totalSeconds, e, this.sceneScale, !1);
  4281. b = Matrix.identity();
  4282. Matrix.invert(b, e);
  4283. e = Matrix.identity();
  4284. Matrix.mul(e, b, f);
  4285. e[12] /= this.sceneScale;
  4286. e[13] /= this.sceneScale;
  4287. e[14] /= this.sceneScale;
  4288. f[0] *= a;
  4289. f[1] *= a;
  4290. f[2] *= a;
  4291. f[4] *= l;
  4292. f[5] *= l;
  4293. f[6] *= l;
  4294. f[8] *= n;
  4295. f[9] *= n;
  4296. f[10] *= n;
  4297. c.setFixedWorldTransform(f);
  4298. c.setFixedLocalTransform(e)
  4299. }
  4300. }
  4301. }
  4302. ;
  4303. SceneAnimator.prototype.setViewFromSelectedCamera = function() {
  4304. if (0 <= this.selectedCameraIndex && this.selectedCameraIndex < this.views.length) {
  4305. var a = this.views[this.selectedCameraIndex]
  4306. , b = this.scene.view
  4307. , c = this.viewYawOffsets[this.selectedCameraIndex]
  4308. , d = this.viewPitchOffsets[this.selectedCameraIndex];
  4309. b.pivot[0] = a.pivot[0];
  4310. b.pivot[1] = a.pivot[1];
  4311. b.pivot[2] = a.pivot[2];
  4312. b.rotation[0] = a.rotation[0] + d;
  4313. b.rotation[1] = a.rotation[1] + c;
  4314. b.radius = a.radius;
  4315. b.nearPlane = a.nearPlane;
  4316. b.fov = a.fov;
  4317. b.saveResetView();
  4318. b.updateProjection();
  4319. b.updateView()
  4320. }
  4321. }
  4322. ;
  4323. SceneAnimator.prototype.selectDefaultCamera = function() {
  4324. if (-1 != this.defaultCameraGlobalIndex && 0 < this.animations.length)
  4325. for (var a = this.animations[0], b = a.cameraObjects.length, c = 0; c < b; c++)
  4326. if (a.cameraObjects[c].id == this.defaultCameraGlobalIndex) {
  4327. this.selectedCameraIndex = c;
  4328. return
  4329. }
  4330. this.selectedCameraIndex = 0
  4331. }
  4332. ;
  4333. SceneAnimator.prototype.updateAnimationPlayback = function() {
  4334. if (!this.stopEverything || !this.runDebugMode) {
  4335. var a = this.animations[this.selectedAnimationIndex];
  4336. this.updateUserCamera();
  4337. if (this.paused || !this.playAnimations)
  4338. this.startMS = 0 < this.playbackSpeed ? Date.now() - 1E3 * this.totalSeconds / (this.playbackSpeed * this.scenePlaybackSpeed) : Date.now() - 1E3 * this.totalSeconds,
  4339. this.refreshTransformsOnly(),
  4340. this.runDebugMode && this.checkDebug(),
  4341. a = this.scene.view,
  4342. a.saveResetView(),
  4343. a.updateProjection(),
  4344. a.updateView();
  4345. else {
  4346. this.lockPlayback && 0 < this.playbackSpeed && (this.startMS = Date.now() - 1E3 * this.totalSeconds / (this.playbackSpeed * this.scenePlaybackSpeed));
  4347. var b = (Date.now() - this.startMS) / 1E3 * this.playbackSpeed * this.scenePlaybackSpeed;
  4348. this.totalSeconds = (Date.now() - this.startMS) / 1E3 * this.playbackSpeed * this.scenePlaybackSpeed;
  4349. var c = b / a.totalSeconds
  4350. , b = Math.floor(c)
  4351. , c = c - b;
  4352. b != this.loopCount && (this.loopCount++,
  4353. this.loopTurntables && this.rolloverTurntables(),
  4354. this.autoAdvanceNextAnimation && (this.nextAnimation(),
  4355. this.resetPlayback()));
  4356. this.totalSeconds = a.totalSeconds * c;
  4357. this.animationProgress = this.totalSeconds / a.totalSeconds - Math.floor(this.totalSeconds / a.totalSeconds);
  4358. this.updateScene();
  4359. this.runDebugMode && this.checkDebug()
  4360. }
  4361. }
  4362. }
  4363. ;
  4364. SceneAnimator.prototype.updateScene = function() {
  4365. this.lastSceneFramePercent = this.totalSeconds * this.animations[this.selectedAnimationIndex].originalFPS;
  4366. 0 != this.fogObjectIndex && this.updateFog();
  4367. this.animateTurntables && this.updateTurntables();
  4368. this.animateMeshes && this.poseMeshes();
  4369. this.animateLights && this.updateLights();
  4370. this.animateMaterials && this.updateMaterials();
  4371. this.animateVisibility && this.updateVisibility()
  4372. }
  4373. ;
  4374. SceneAnimator.prototype.findCameraChildren = function() {
  4375. for (var a = this.animations[0], b = a.animatedObjects.length, c = 0; c < b; c++)
  4376. a.hasParentTypeInHierarchy(a.animatedObjects[c], "CameraSO") && this.cameraChildrenIndices.push(c)
  4377. }
  4378. ;
  4379. SceneAnimator.prototype.findFixedTransforms = function() {
  4380. for (var a = this.animations.length, b = 0; b < a; b++)
  4381. for (var c = this.animations[b], d = c.animatedObjects.length, e = 0; e < d; e++) {
  4382. var f = c.animatedObjects[e];
  4383. if (!f.useFixedWorldTransform && !c.hasAnimationInHierarchy(f))
  4384. if ("Material" == f.sceneObjectType)
  4385. f.setFixedWorldTransform(Matrix.identity()),
  4386. f.setFixedLocalTransform(Matrix.identity());
  4387. else {
  4388. var g = Matrix.identity()
  4389. , h = Matrix.identity();
  4390. c.hasParentTypeInHierarchy(f, "SceneRootSO") ? (c.getWorldTransform(f.id, 0, g, this.sceneScale, !1),
  4391. f.evaluateLocalTransformAtFramePercent(0, h, !0, !1)) : (c.evaluateModelPartTransformAtFrame(f.id, 0, g, !1),
  4392. f.evaluateLocalTransformAtFramePercent(0, h, !1, !1));
  4393. f.setFixedWorldTransform(g);
  4394. f.setFixedLocalTransform(h)
  4395. }
  4396. }
  4397. }
  4398. ;
  4399. SceneAnimator.prototype.clearCacheForCameraChildren = function() {
  4400. for (var a = this.animations[this.selectedAnimationIndex], b = this.cameraChildrenIndices.length, c = 0; c < b; c++) {
  4401. var d = a.animatedObjects[this.cameraChildrenIndices[c]];
  4402. d.useFixedWorldTransform = !1;
  4403. d.useFixedLocalTransform = !1;
  4404. d.cachedFrame0 = -10;
  4405. d.cachedFrame1 = -10;
  4406. d.cachedFrame2 = -10;
  4407. d.cachedFrame3 = -10;
  4408. d.cachedFrameUse0 = 0;
  4409. d.cachedFrameUse1 = 0;
  4410. d.cachedFrameUse2 = 0;
  4411. d.cachedFrameUse3 = 0;
  4412. d.animatedLocalTransform.clearCachedTransforms();
  4413. d.animatedLocalTransform.lockTransform = !1
  4414. }
  4415. }
  4416. ;
  4417. SceneAnimator.prototype.refreshTransformsOnly = function() {
  4418. for (var a = this.animations[this.selectedAnimationIndex], b = a.meshObjects.length, c = 0; c < b; c++) {
  4419. var d = a.meshObjects[c];
  4420. a.getWorldTransform(d.id, this.totalSeconds, d.mesh.displayMatrix, this.sceneScale, !0);
  4421. if (this.enableSkinning && d.skinningRig && this.unitScaleSkinnedMeshes && !d.skinningRig.isRigidSkin) {
  4422. var d = d.mesh.displayMatrix
  4423. , e = d[0]
  4424. , f = d[1]
  4425. , g = d[2]
  4426. , h = d[4]
  4427. , k = d[5]
  4428. , l = d[6]
  4429. , n = d[8]
  4430. , m = d[9]
  4431. , p = d[10]
  4432. , e = Math.sqrt(e * e + f * f + g * g)
  4433. , h = Math.sqrt(h * h + k * k + l * l)
  4434. , n = Math.sqrt(n * n + m * m + p * p)
  4435. , n = (e + h + n) / 2;
  4436. d[0] /= n;
  4437. d[1] /= n;
  4438. d[2] /= n;
  4439. d[4] /= n;
  4440. d[5] /= n;
  4441. d[6] /= n;
  4442. d[8] /= n;
  4443. d[9] /= n;
  4444. d[10] /= n
  4445. }
  4446. }
  4447. if (this.animateLights)
  4448. for (b = a.lightObjects.length,
  4449. c = 0; c < b; c++)
  4450. d = a.lightObjects[c],
  4451. d.useFixedWorldTransform || (n = this.scene.lights.getLightPos(d.lightIndex),
  4452. m = this.scene.lights.getLightDir(d.lightIndex),
  4453. p = Matrix.identity(),
  4454. a.getWorldTransform(d.id, this.totalSeconds, p, this.sceneScale, !0),
  4455. m[0] = p[8],
  4456. m[1] = p[9],
  4457. m[2] = p[10],
  4458. 0 != n[3] && (n[0] = p[12],
  4459. n[1] = p[13],
  4460. n[2] = p[14],
  4461. this.scene.lights.setLightPos(d.lightIndex, n)),
  4462. this.scene.lights.setLightDir(d.lightIndex, m))
  4463. }
  4464. ;
  4465. SceneAnimator.prototype.findMeshIndexByPartIndex = function(a, b) {
  4466. for (var c = 0; c < this.meshIDs.length; ++c)
  4467. if (b == this.meshIDs[c])
  4468. return c;
  4469. return -1
  4470. }
  4471. ;
  4472. SceneAnimator.prototype.findLightIndexByPartIndex = function(a) {
  4473. for (var b = 0; b < this.lightIDs.length; b++)
  4474. if (a == this.lightIDs[b])
  4475. return b;
  4476. return -1
  4477. }
  4478. ;
  4479. SceneAnimator.prototype.findMaterialIndexByPartIndex = function(a) {
  4480. for (var b = 0; b < this.materialIDs.length; b++)
  4481. if (a == this.materialIDs[b])
  4482. return b;
  4483. return -1
  4484. }
  4485. ;
  4486. SceneAnimator.prototype.nextAnimation = function() {
  4487. this.selectedAnimationIndex++;
  4488. this.selectedAnimationIndex >= this.animations.length && (this.selectedAnimationIndex = 0)
  4489. }
  4490. ;
  4491. SceneAnimator.prototype.selectAnimation = function(a) {
  4492. 0 <= a && a < this.animations.length && (this.selectedAnimationIndex = a);
  4493. this.paused && this.setAnimationProgress(this.animationProgress, !0)
  4494. }
  4495. ;
  4496. SceneAnimator.prototype.selectCamera = function(a) {
  4497. -1 != a && this.selectedCameraIndex != a && (this.selectedCameraIndex = a,
  4498. this.setViewFromSelectedCamera())
  4499. }
  4500. ;
  4501. SceneAnimator.prototype.getAnimatedCamera = function() {
  4502. if (0 <= this.selectedCameraIndex && this.selectedAnimationIndex < this.animations.length) {
  4503. var a = this.animations[this.selectedAnimationIndex];
  4504. if (this.selectedCameraIndex < a.cameraObjects.length)
  4505. return a.cameraObjects[this.selectedCameraIndex]
  4506. }
  4507. }
  4508. ;
  4509. SceneAnimator.prototype.poseMeshes = function() {//mesh形变/位移等
  4510. for (var a = this.animations[this.selectedAnimationIndex], b = a.meshObjects.length, c = 0; c < b; c++) {
  4511. var d = a.meshObjects[c];
  4512. if (this.enableSkinning && d.skinningRig)
  4513. if (d.skinningRig.isRigidSkin)
  4514. a.getWorldTransform(d.id, this.totalSeconds, d.mesh.displayMatrix, this.sceneScale, !0);
  4515. else {
  4516. d.setupSkinningRig(a, d.modelPartIndex, this.totalSeconds, d.skinningRig);
  4517. a.getWorldTransform(d.id, this.totalSeconds, d.mesh.displayMatrix, this.sceneScale, !0);
  4518. var e = d.modelPartScale * this.sceneScale;
  4519. if (this.unitScaleSkinnedMeshes) { //在播放动画时,这段去掉和加上效果一致(目前没发现差别)原因应该是矩阵各项除以一个数,相当于效果缩小这个倍数,而后倍数乘给e,所以deformMesh时又放大了。
  4520. var f = d.mesh.displayMatrix
  4521. , g = f[0]
  4522. , h = f[1]
  4523. , k = f[2]
  4524. , l = f[4]
  4525. , n = f[5]
  4526. , m = f[6]
  4527. , p = f[8]
  4528. , r = f[9]
  4529. , s = f[10]
  4530. , g = Math.sqrt(g * g + h * h + k * k)
  4531. , l = Math.sqrt(l * l + n * n + m * m)
  4532. , p = Math.sqrt(p * p + r * r + s * s)
  4533. , p = (g + l + p) / 2; //但是不明白为什么静止时需要displayMatrix这些项 除以这么个数
  4534. f[0] /= p;
  4535. f[1] /= p;
  4536. f[2] /= p;
  4537. f[4] /= p;
  4538. f[5] /= p;
  4539. f[6] /= p;
  4540. f[8] /= p;
  4541. f[9] /= p;
  4542. f[10] /= p;
  4543. e *= p
  4544. }
  4545. d.skinningRig.deformMesh(d.mesh, e)
  4546. }
  4547. else
  4548. a.getWorldTransform(d.id, this.totalSeconds, d.mesh.displayMatrix, this.sceneScale, !0)
  4549. }
  4550. }
  4551. ;
  4552. SceneAnimator.prototype.updateLights = function() {
  4553. for (var a = this.animations[this.selectedAnimationIndex], b = this.totalSeconds * a.originalFPS, c = a.lightObjects.length, d = 0; d < c; d++) {
  4554. var e = a.lightObjects[d]
  4555. , f = this.scene.lights.getLightPos(e.lightIndex)
  4556. , g = this.scene.lights.getLightDir(e.lightIndex)
  4557. , h = this.scene.lights.getLightColor(e.lightIndex)
  4558. , k = Matrix.identity()
  4559. , l = 1;
  4560. e.useFixedWorldTransform || a.getWorldTransform(e.id, this.totalSeconds, k, this.sceneScale, !0);
  4561. e.redProperty && (e.redProperty.evaluate(b, h[0], e),
  4562. h[0] = e.redProperty.lastValue);
  4563. e.greenProperty && (e.greenProperty.evaluate(b, h[1], e),
  4564. h[1] = e.greenProperty.lastValue);
  4565. e.blueProperty && (e.blueProperty.evaluate(b, h[2], e),
  4566. h[2] = e.blueProperty.lastValue);
  4567. e.brightnessProperty && (e.brightnessProperty.evaluate(b, l, e),
  4568. l = e.brightnessProperty.lastValue);
  4569. h[0] *= l;
  4570. h[1] *= l;
  4571. h[2] *= l;
  4572. 0 != f[3] && (e.useFixedWorldTransform || (f[0] = k[12],
  4573. f[1] = k[13],
  4574. f[2] = k[14],
  4575. this.scene.lights.setLightPos(e.lightIndex, f)),
  4576. e.spotAngleProperty && 0 < this.scene.lights.spot[3 * e.lightIndex] && (f = 0,
  4577. e.spotAngleProperty.evaluate(b, f, e),
  4578. f = e.spotAngleProperty.lastValue,
  4579. this.scene.lights.setLightSpotAngle(e.lightIndex, f)),
  4580. e.spotSharpnessProperty && (f = 0,
  4581. e.spotSharpnessProperty.evaluate(b, f, e),
  4582. f = e.spotSharpnessProperty.lastValue,
  4583. this.scene.lights.setLightSpotSharpness(e.lightIndex, f)),
  4584. e.distanceProperty && (f = 1,
  4585. e.distanceProperty.evaluate(b, f, e),
  4586. f = e.distanceProperty.lastValue * this.sceneScale,
  4587. this.scene.lights.setLightDistance(e.lightIndex, f)));
  4588. e.useFixedWorldTransform || (g[0] = k[8],
  4589. g[1] = k[9],
  4590. g[2] = k[10],
  4591. this.scene.lights.setLightDir(e.lightIndex, g));
  4592. this.scene.lights.setLightColor(e.lightIndex, h)
  4593. }
  4594. }
  4595. ;
  4596. SceneAnimator.prototype.updateTurntables = function() {
  4597. for (var a = this.animations[this.selectedAnimationIndex], b = this.totalSeconds * a.originalFPS, c = a.turnTableObjects.length, d = 0; d < c; d++) {
  4598. var e = a.turnTableObjects[d];
  4599. e.spinProperty.evaluate(b, 0, e);
  4600. e.turnTableSpin = e.turnTableSpinOffset + e.spinProperty.lastValue * this.totalSeconds
  4601. }
  4602. }
  4603. ;
  4604. SceneAnimator.prototype.rolloverTurntables = function() {
  4605. for (var a = this.animations[this.selectedAnimationIndex], b = a.turnTableObjects.length, c = 0; c < b; c++) {
  4606. var d = a.turnTableObjects[c];
  4607. d.turnTableSpinOffset = d.turnTableSpin
  4608. }
  4609. }
  4610. ;
  4611. SceneAnimator.prototype.updateMaterials = function() {
  4612. for (var a = this.animations[this.selectedAnimationIndex], b = this.totalSeconds * a.originalFPS, c = a.materialObjects.length, d = 0; d < c; d++) {
  4613. var e = a.materialObjects[d];
  4614. e.offsetUProperty && (e.offsetUProperty.evaluate(b, 0, e),
  4615. this.scene.materialsList[e.materialIndex].uOffset = e.offsetUProperty.lastValue);
  4616. e.offsetVProperty && (e.offsetVProperty.evaluate(b, 0, e),
  4617. this.scene.materialsList[e.materialIndex].vOffset = e.offsetVProperty.lastValue);
  4618. e.emissiveProperty && 1 < e.emissiveProperty.numKeyframes && (e.emissiveProperty.evaluate(b, 0, e),
  4619. this.scene.materialsList[e.materialIndex].emissiveIntensity = e.emissiveProperty.lastValue)
  4620. }
  4621. }
  4622. ;
  4623. SceneAnimator.prototype.updateFog = function() {
  4624. var a = this.animations[this.selectedAnimationIndex]
  4625. , b = this.totalSeconds * a.originalFPS;
  4626. 0 <= this.fogObjectIndex && this.fogObjectIndex < a.animatedObjects.length && this.scene.fog && (a = a.animatedObjects[this.fogObjectIndex],
  4627. a.redProperty && (this.scene.fog.desc.color[0] = a.redProperty.evaluate(b, this.scene.fog.desc.color[0], a)),
  4628. a.greenProperty && (this.scene.fog.desc.color[1] = a.greenProperty.evaluate(b, this.scene.fog.desc.color[1], a)),
  4629. a.blueProperty && (this.scene.fog.desc.color[2] = a.blueProperty.evaluate(b, this.scene.fog.desc.color[2], a)),
  4630. a.distanceProperty && (this.scene.fog.desc.distance = a.distanceProperty.evaluate(b, this.scene.fog.desc.distance, a)),
  4631. a.opacityProperty && (this.scene.fog.desc.opacity = a.opacityProperty.evaluate(b, this.scene.fog.desc.opacity, a)),
  4632. a.skyIllumProperty && (this.scene.fog.desc.skyIllum = a.skyIllumProperty.evaluate(b, this.scene.fog.desc.skyIllum, a)),
  4633. a.lightIllumProperty && (this.scene.fog.desc.lightIllum = a.lightIllumProperty.evaluate(b, this.scene.fog.desc.lightIllum, a)),
  4634. a.dispersionProperty && (this.scene.fog.desc.dispersion = a.dispersionProperty.evaluate(b, this.scene.fog.desc.dispersion, a)))
  4635. }
  4636. ;
  4637. SceneAnimator.prototype.updateVisibility = function() {
  4638. for (var a = this.animations[this.selectedAnimationIndex], b = this.subMeshObjectIndices.length, c = 0; c < b; c++) {
  4639. var d = this.subMeshLiveIndices[c];
  4640. if (-1 != d) {
  4641. var e = this.subMeshObjectIndices[c]
  4642. , d = this.scene.meshRenderables[d]
  4643. , f = a.getObjectAnimationFramePercent(a.animatedObjects[e], this.totalSeconds);
  4644. d.visible = a.isVisibleAtFramePercent(e, f)
  4645. }
  4646. }
  4647. }
  4648. ;
  4649. function Shader(a) {
  4650. this.gl = a;
  4651. this.program = null;
  4652. this.params = {};
  4653. this.samplers = {};
  4654. this.attribs = {}
  4655. }
  4656. Shader.prototype.build = function(a, b) {
  4657. var c = this.gl;
  4658. this.program = c.createProgram();
  4659. this.params = {};
  4660. this.samplers = {};
  4661. this.attribs = {};
  4662. var d = function(a) {
  4663. for (var b = "", c = a.indexOf("\n"), d = 0; -1 != c; )
  4664. d++,
  4665. b += d + ": ",
  4666. b += a.substring(0, c + 1),
  4667. a = a.substring(c + 1, a.length),
  4668. c = a.indexOf("\n");
  4669. console.log(b)
  4670. }
  4671. , e = c.createShader(c.VERTEX_SHADER);
  4672. c.shaderSource(e, a);
  4673. c.compileShader(e);
  4674. c.getShaderParameter(e, c.COMPILE_STATUS) || (console.log(c.getShaderInfoLog(e)),
  4675. fdage.verboseErrors && d(a));
  4676. c.attachShader(this.program, e);
  4677. e = c.createShader(c.FRAGMENT_SHADER);
  4678. c.shaderSource(e, b);
  4679. c.compileShader(e);
  4680. c.getShaderParameter(e, c.COMPILE_STATUS) || (console.log(c.getShaderInfoLog(e)),
  4681. fdage.verboseErrors && d(b));
  4682. c.attachShader(this.program, e);
  4683. c.linkProgram(this.program);
  4684. c.getProgramParameter(this.program, c.LINK_STATUS) || console.log(c.getProgramInfoLog(this.program));
  4685. for (var e = c.getProgramParameter(this.program, c.ACTIVE_UNIFORMS), f = 0, d = 0; d < e; ++d) {
  4686. var g = c.getActiveUniform(this.program, d)
  4687. , h = g.name
  4688. , k = h.indexOf("[");
  4689. 0 <= k && (h = h.substring(0, k));
  4690. k = c.getUniformLocation(this.program, g.name);
  4691. g.type == c.SAMPLER_2D || g.type == c.SAMPLER_CUBE ? this.samplers[h] = {
  4692. location: k,
  4693. unit: f++
  4694. } : this.params[h] = k
  4695. }
  4696. e = c.getProgramParameter(this.program, c.ACTIVE_ATTRIBUTES);
  4697. for (d = 0; d < e; ++d)
  4698. f = c.getActiveAttrib(this.program, d),
  4699. this.attribs[f.name] = c.getAttribLocation(this.program, f.name)
  4700. }
  4701. ;
  4702. Shader.prototype.bind = function() {
  4703. return this.program ? (this.gl.useProgram(this.program),
  4704. !0) : !1
  4705. }
  4706. ;
  4707. Shader.prototype.complete = function() {
  4708. return !!this.program
  4709. }
  4710. ;
  4711. function ShaderCache(a) {
  4712. this.gl = a;
  4713. this.cache = []
  4714. }
  4715. ShaderCache.prototype.fromURLs = function(a, b, c) {
  4716. var d = "";
  4717. if (c)
  4718. for (var e = 0; e < c.length; ++e)
  4719. d = c[e] + "\n" + d;
  4720. c = d + ":" + a + "|" + b;
  4721. e = this.cache[c];
  4722. if (void 0 !== e)
  4723. return e;
  4724. var f = new Shader(this.gl)
  4725. , g = null
  4726. , h = null
  4727. , k = function() {
  4728. null != g && null != h && f.build(g, h)
  4729. };
  4730. this.fetch(a, function(a) {
  4731. g = d + a;
  4732. k()
  4733. });
  4734. this.fetch(b, function(a) {
  4735. h = d + a;
  4736. k()
  4737. });
  4738. return this.cache[c] = f
  4739. }
  4740. ;
  4741. ShaderCache.prototype.fetch = function(a, b) {
  4742. "undefined" != typeof ShaderTable ? void 0 !== ShaderTable[a] ? this.resolveIncludes(new String(ShaderTable[a]), b) : b("") : Network.fetchText("src/shader/" + a, function(a) {
  4743. this.resolveIncludes(a, b)
  4744. }
  4745. .bind(this), function() {
  4746. b("")
  4747. })
  4748. }
  4749. ;
  4750. ShaderCache.prototype.resolveIncludes = function(a, b) {
  4751. for (var c = [], d = !0, e = function(a, b, e, f, n) {
  4752. d = !0;
  4753. c.push({
  4754. offset: n,
  4755. path: b.slice(1, b.length - 1)
  4756. });
  4757. return ""
  4758. }; d; )
  4759. d = !1,
  4760. a = a.replace(/#include\s((<[^>]+>)|("[^"]+"))/, e);
  4761. if (0 < c.length)
  4762. for (var f = c.length, e = 0; e < c.length; ++e)
  4763. this.fetch(c[e].path, function(d) {
  4764. this.src = d;
  4765. if (0 >= --f) {
  4766. for (d = c.length - 1; 0 <= d; --d)
  4767. a = a.substring(0, c[d].offset) + c[d].src + a.substring(c[d].offset);
  4768. b(a)
  4769. }
  4770. }
  4771. .bind(c[e]));
  4772. else
  4773. b(a)
  4774. }
  4775. ;
  4776. function ShadowCollector(a, b) {
  4777. this.gl = a;
  4778. this.shadowCount = b;
  4779. this.nativeDepth = !!a.ext.textureDepth;
  4780. this.desc = c;
  4781. c = this.nativeDepth ? ["#define SHADOW_NATIVE_DEPTH"] : [];
  4782. this.shaderSolid = a.shaderCache.fromURLs("shadowvert.glsl", "shadowfrag.glsl", c);
  4783. c.push("#define ALPHA_TEST 1");
  4784. this.shaderAlphaTest = a.shaderCache.fromURLs("shadowvert.glsl", "shadowfrag.glsl", c);
  4785. this.depthTextures = [];
  4786. this.depthTargets = [];
  4787. if (0 < this.shadowCount) {
  4788. var c = {
  4789. width: 2048,
  4790. height: 2048,
  4791. clamp: !0,
  4792. mipmap: !1,
  4793. nofilter: !0
  4794. };
  4795. a.hints.mobile && (c.width = c.height = 1536);
  4796. var d = {
  4797. width: c.width,
  4798. height: c.height
  4799. }, e, f;
  4800. this.nativeDepth ? (e = a.DEPTH_COMPONENT,
  4801. f = a.UNSIGNED_SHORT) : (d.depthBuffer = Framebuffer.createDepthBuffer(a, c.width, c.height),
  4802. e = a.RGB,
  4803. f = a.UNSIGNED_BYTE);
  4804. for (var g = 0; g < this.shadowCount; ++g)
  4805. this.depthTextures[g] = new Texture(a,c),
  4806. this.depthTextures[g].loadArray(null, e, f),
  4807. this.nativeDepth ? d.depth = this.depthTextures[g] : d.color0 = this.depthTextures[g],
  4808. this.depthTargets[g] = new Framebuffer(a,d)
  4809. }
  4810. }
  4811. ShadowCollector.prototype.bindDepthTexture = function(a, b) {
  4812. this.shadowCount > b && this.depthTextures[b].bind(a)
  4813. }
  4814. ;
  4815. ShadowCollector.prototype.collect = function(a, b) {
  4816. for (var c = this.gl, d = a.lights, e = d.shadowCount, f = d.modelViewBuffer, g = d.projectionBuffer, h = d.matrix, k = 0 != a.sceneAnimator, l = Matrix.empty(), n = !1, m = 0; m < e; ++m)
  4817. if (d.shadowsNeedUpdate[m]) {
  4818. d.shadowsNeedUpdate[m] = 0;
  4819. n = !0;
  4820. Matrix.mul(l, f.subarray(16 * m, 16 * (m + 1)), h);
  4821. Matrix.mul(l, g.subarray(16 * m, 16 * (m + 1)), l);
  4822. this.depthTargets[m].bind();
  4823. c.clearColor(1, 1, 1, 1);
  4824. c.clear(c.COLOR_BUFFER_BIT | c.DEPTH_BUFFER_BIT);
  4825. var p = this.shaderSolid;
  4826. p.bind();
  4827. c.uniformMatrix4fv(p.params.uViewProjection, !1, l);
  4828. c.uniformMatrix4fv(p.params.uMeshTransform, !1, Matrix.identity());
  4829. for (var r = 0; r < a.meshRenderables.length; ++r) {
  4830. var s = a.meshRenderables[r]
  4831. , u = s.material;
  4832. !s.mesh.desc.castShadows || !u.castShadows || 0 < u.shadowAlphaTest || (k && c.uniformMatrix4fv(p.params.uMeshTransform, !1, s.mesh.displayMatrix),
  4833. s.drawShadow(p.attribs.vPosition))
  4834. }
  4835. p = this.shaderAlphaTest;
  4836. p.bind();
  4837. c.uniformMatrix4fv(p.params.uViewProjection, !1, l);
  4838. c.uniformMatrix4fv(p.params.uMeshTransform, !1, Matrix.identity());
  4839. for (r = 0; r < a.meshRenderables.length; ++r)
  4840. s = a.meshRenderables[r],
  4841. u = s.material,
  4842. s.mesh.desc.castShadows && u.castShadows && 0 < u.shadowAlphaTest && (u.textures.albedo.bind(p.samplers.tAlbedo),
  4843. k && (c.uniform2f(p.params.uUVOffset, u.uOffset, u.vOffset),
  4844. c.uniformMatrix4fv(p.params.uMeshTransform, !1, s.mesh.displayMatrix)),
  4845. s.drawAlphaShadow(p.attribs.vPosition, p.attribs.vTexCoord))
  4846. }
  4847. n && (b.bind(),
  4848. c.enable(c.CULL_FACE),
  4849. c.cullFace(c.BACK))
  4850. }
  4851. ;
  4852. ShadowCollector.prototype.complete = function() {
  4853. return this.shaderSolid.complete() && this.shaderAlphaTest.complete()
  4854. }
  4855. ;
  4856. function ShadowFloor(a, b, c, d) {
  4857. this.gl = a;
  4858. this.desc = b;
  4859. this.lightCount = d.count;
  4860. this.shadowCount = c.shadowCount;
  4861. b = this.nativeDepth ? ["#define SHADOW_NATIVE_DEPTH"] : [];
  4862. b.push("#define LIGHT_COUNT " + this.lightCount);
  4863. b.push("#define SHADOW_COUNT " + this.shadowCount);
  4864. a.hints.mobile && b.push("#define MOBILE");
  4865. this.shader = a.shaderCache.fromURLs("shadowfloorvert.glsl", "shadowfloorfrag.glsl", b);
  4866. b = new Float32Array([-1, 0, -1, -1, 0, 1, 1, 0, 1, -1, 0, -1, 1, 0, 1, 1, 0, -1]);
  4867. this.quadGeom = a.createBuffer();
  4868. a.bindBuffer(a.ARRAY_BUFFER, this.quadGeom);
  4869. a.bufferData(a.ARRAY_BUFFER, b, a.STATIC_DRAW);
  4870. a.bindBuffer(a.ARRAY_BUFFER, null)
  4871. }
  4872. ShadowFloor.prototype.draw = function(a) {
  4873. var b = a.view
  4874. , c = a.lights
  4875. , d = a.shadow
  4876. , e = this.gl
  4877. , f = this.shader.params
  4878. , g = this.shader.samplers;
  4879. this.shader.bind();
  4880. b = Matrix.mul(Matrix.empty(), b.projectionMatrix, b.viewMatrix);
  4881. Matrix.mul(b, b, this.desc.transform);
  4882. e.uniformMatrix4fv(f.uModelViewProjectionMatrix, !1, b);
  4883. b = Matrix.mul(Matrix.empty(), c.matrix, this.desc.transform);
  4884. e.uniformMatrix4fv(f.uModelSkyMatrix, !1, b);
  4885. 0 < c.count && (e.uniform4fv(f.uLightPositions, c.positionBuffer),
  4886. e.uniform3fv(f.uLightDirections, c.directionBuffer),
  4887. e.uniform3fv(f.uLightColors, c.colors),
  4888. e.uniform3fv(f.uLightParams, c.parameters),
  4889. e.uniform3fv(f.uLightSpot, c.spot),
  4890. a = 0.392699 * a.postRender.currentSample(),
  4891. e.uniform2f(f.uShadowKernelRotation, 0.5 * Math.cos(a), 0.5 * Math.sin(a)),
  4892. 0 < c.shadowCount && (a = d.depthTextures[0].desc.width,
  4893. e.uniform2f(f.uShadowMapSize, a, 1 / a),
  4894. e.uniformMatrix4fv(f.uShadowMatrices, !1, c.finalTransformBuffer),
  4895. e.uniformMatrix4fv(f.uInvShadowMatrices, !1, c.inverseTransformBuffer),
  4896. e.uniform4fv(f.uShadowTexelPadProjections, c.shadowTexelPadProjections),
  4897. d.bindDepthTexture(g.tDepth0, 0),
  4898. d.bindDepthTexture(g.tDepth1, 1),
  4899. d.bindDepthTexture(g.tDepth2, 2)));
  4900. e.uniform3f(f.uShadowCatcherParams, this.desc.simple ? 1 : 0, this.desc.alpha, this.desc.edgeFade);
  4901. e.depthMask(!1);
  4902. e.enable(e.BLEND);
  4903. e.blendFunc(e.ZERO, e.SRC_COLOR);
  4904. c = this.shader.attribs.vPosition;
  4905. e.bindBuffer(e.ARRAY_BUFFER, this.quadGeom);
  4906. e.enableVertexAttribArray(c);
  4907. e.vertexAttribPointer(c, 3, e.FLOAT, !1, 0, 0);
  4908. e.drawArrays(e.TRIANGLES, 0, 6);
  4909. e.disableVertexAttribArray(c);
  4910. e.bindBuffer(e.ARRAY_BUFFER, null);
  4911. e.disable(e.BLEND);
  4912. e.depthMask(!0)
  4913. }
  4914. ;
  4915. ShadowFloor.prototype.complete = function() {
  4916. return this.shader.complete()
  4917. }
  4918. ;
  4919. function Skin(a) {
  4920. this.numVertices = a.vertexCount;
  4921. this.vertices = new Float32Array(a.vertexCount);
  4922. a.vertexBuffer || (this.numVertices = 0)
  4923. }
  4924. ;function SkinningCluster() {
  4925. this.associateObjectIndex = this.linkObjectIndex = this.linkMode = 0; //linkObjectIndex直接对应animatedObject里的顺序
  4926. this.vertexIndices = [];
  4927. this.vertexWeights = [];
  4928. this.matrix = Matrix.identity();//一直在变,一至多个变型器(如骨骼)的运动带动其他顶点变化。
  4929. this.defaultAssociateWorldTransform = this.defaultClusterWorldTransform = this.defaultClusterBaseTransform = 0;
  4930. this.defaultClusterWorldTransformInvert = Matrix.identity();
  4931. this.defaultAssociateWorldTransformInvert = Matrix.identity();
  4932. this.debugString = ""
  4933. }
  4934. SkinningCluster.prototype.solveAdditiveClusterTransform = function(a, b, c) {
  4935. b = Matrix.identity();
  4936. var d = Matrix.identity()
  4937. , e = Matrix.identity();
  4938. Matrix.mul(b, a, this.defaultClusterBaseTransform);
  4939. Matrix.mul(d, this.defaultAssociateWorldTransformInvert, b);
  4940. Matrix.mul(e, this.defaultAssociateWorldTransformInvert, d);
  4941. Matrix.mul(c, this.defaultClusterWorldTransformInvert, e)
  4942. }
  4943. ;
  4944. SkinningCluster.prototype.solveSimpleClusterTransform = function(a, b, c) {
  4945. var d = Matrix.identity()
  4946. , e = Matrix.identity();
  4947. Matrix.invert(e, b);
  4948. Matrix.mul(d, e, a);
  4949. Matrix.mul(c, d, this.defaultClusterBaseTransform)
  4950. }
  4951. ;
  4952. SkinningCluster.prototype.solveClusterTransformAtFrame = function(a, b, c, d) {
  4953. if (1 == this.linkMode) {
  4954. var e = Matrix.identity();
  4955. b = Matrix.identity();
  4956. a.evaluateModelPartTransformAtFrame(this.linkObjectIndex, c, e, !1);
  4957. a.evaluateModelPartTransformAtFrame(this.associateObjectIndex, c, b, !1);
  4958. this.solveAdditiveClusterTransform(e, b, d)
  4959. } else {
  4960. var e = Matrix.identity()
  4961. , f = Matrix.identity();
  4962. a.evaluateModelPartTransformAtFrame(this.linkObjectIndex, c, e, !1);
  4963. a.evaluateModelPartTransformAtFrame(b, c, f, !1);
  4964. this.solveSimpleClusterTransform(e, f, d)
  4965. }
  4966. }
  4967. ;
  4968. function SkinningRig(a, b, c) {
  4969. this.debugString = "";
  4970. this.skinningClusters = [];
  4971. this.srcVFile = b.file;
  4972. if (a = a.get(this.srcVFile))
  4973. if (a.data) {
  4974. this.rigByteStream = new ByteStream(a.data);
  4975. a = new Uint32Array(this.rigByteStream.bytes.buffer,0,this.rigByteStream.bytes.length / 4);
  4976. this.expectedNumClusters = a[0];
  4977. this.expectedNumVertices = a[1];
  4978. this.numClusterLinks = a[2];
  4979. this.originalObjectIndex = a[3];
  4980. this.isRigidSkin = a[4];
  4981. this.tangentMethod = a[5];
  4982. b = 6 + 7 * this.expectedNumClusters;
  4983. for (var d = 0; d < this.expectedNumClusters; d++) {
  4984. var e = new SkinningCluster;
  4985. this.skinningClusters.push(e);
  4986. var f = 6 + 7 * d;
  4987. e.linkMode = a[f + 1];
  4988. e.linkObjectIndex = a[f + 2];
  4989. e.associateObjectIndex = a[f + 3];
  4990. var g = a[f + 5];
  4991. e.defaultClusterWorldTransform = c.getMatrix(a[f + 4]);
  4992. e.defaultClusterBaseTransform = c.getMatrix(g);
  4993. Matrix.invert(e.defaultClusterWorldTransformInvert, e.defaultClusterWorldTransform);
  4994. 1 == e.linkMode && (e.defaultAssociateWorldTransform = c.getMatrix(a[f + 6]),
  4995. Matrix.invert(e.defaultAssociateWorldTransformInvert, e.defaultAssociateWorldTransform))
  4996. }
  4997. c = 4 * b;
  4998. b = c + this.expectedNumVertices;
  4999. a = b + 2 * this.numClusterLinks;
  5000. b = new Uint8Array(this.rigByteStream.bytes.subarray(b));//去掉前面b个
  5001. a = new Uint8Array(this.rigByteStream.bytes.subarray(a));
  5002. this.linkMapCount = new Uint8Array(this.rigByteStream.bytes.buffer,c,this.expectedNumVertices);//这三个Map是mapping的意思?
  5003. this.linkMapClusterIndices = new Uint16Array(b.buffer); //linkMapClusterIndices后面会多出很多很大的数字,那些是linkMapWeights的部分.....
  5004. this.linkMapWeights = new Float32Array(a.buffer)
  5005. /*newnote:
  5006. linkMapCount 存储了每个vertex受几个cluster控制
  5007. numClusterLinks 表示所有vertex所受控制个数之和 比如点1受2个,点2受1个,那么之和是2+1=3个。 这个数就是linkMapWeights的length
  5008. linkMapWeights 则存储了每个vertex所受到cluster控制的weight(权重)
  5009. linkMapClusterIndices 存储了vertex所受到cluster的序号 比如点1受的是第1个cluster和第二个cluster,则数据为 [0, 1, .... linkMapClusterIndices末尾数据多余,可用长度为numClusterLinks
  5010. */
  5011. } else
  5012. this.debugString += "<br>No data in " + this.srcVFile;
  5013. else
  5014. this.debugString += "<br>Error loading buffer for skinning rig " + this.srcVFile
  5015. }
  5016. SkinningRig.prototype.unpackUnitVectors = function(a, b, c, d) {
  5017. for (var e = 0; e < c; e++) {
  5018. var f = b[d * e]
  5019. , g = b[d * e + 1]
  5020. , h = 32768 <= g;
  5021. h && (g -= 32768);
  5022. var f = f / 32767.4 * 2 - 1
  5023. , g = g / 32767.4 * 2 - 1
  5024. , k = 1 - (f * f + g * g)
  5025. , k = Math.sqrt(k)
  5026. , k = isNaN(k) ? 0 : k;
  5027. h && (k = -k);
  5028. a[3 * e] = f;
  5029. a[3 * e + 1] = g;
  5030. a[3 * e + 2] = k
  5031. }
  5032. }
  5033. ;
  5034. SkinningRig.prototype.copyOriginalVertices = function(a) {
  5035. if (!this.unTransformedVertices)
  5036. if (this.unTransformedVertices = new Float32Array(3 * a.vertexCount),
  5037. this.unTransformedNormals = new Float32Array(3 * a.vertexCount),
  5038. this.unTransformedTangents = new Float32Array(3 * a.vertexCount),
  5039. this.unTransformedBiTangents = new Float32Array(3 * a.vertexCount),
  5040. this.skinVertexWeights = new Float32Array(a.vertexCount),
  5041. this.skinVertexTransform4x3 = new Float32Array(12),
  5042. a.dynamicVertexData) {
  5043. var b = new Float32Array(a.dynamicVertexData.buffer);
  5044. new Uint8Array(a.dynamicVertexData.buffer);
  5045. var c = 0
  5046. , d = c
  5047. , c = c + 12 + 8;
  5048. a.secondaryTexCoord && (c += 8);
  5049. var e = c
  5050. , f = c += 4
  5051. , c = c + 4
  5052. , g = a.stride / 2
  5053. , c = new Uint8Array(a.dynamicVertexData.subarray(c))
  5054. , c = new Uint16Array(c.buffer)
  5055. , e = new Uint8Array(a.dynamicVertexData.subarray(e))
  5056. , e = new Uint16Array(e.buffer)
  5057. , f = new Uint8Array(a.dynamicVertexData.subarray(f))
  5058. , f = new Uint16Array(f.buffer);
  5059. this.unpackUnitVectors(this.unTransformedNormals, c, a.vertexCount, g);
  5060. this.unpackUnitVectors(this.unTransformedTangents, e, a.vertexCount, g);
  5061. this.unpackUnitVectors(this.unTransformedBiTangents, f, a.vertexCount, g);
  5062. for (g = 0; g < a.vertexCount; g++)
  5063. f = (a.stride * g + d) / 4,
  5064. this.unTransformedVertices[3 * g] = b[f],
  5065. this.unTransformedVertices[3 * g + 1] = b[f + 1],
  5066. this.unTransformedVertices[3 * g + 2] = b[f + 2]
  5067. } else
  5068. this.debugString += "<br>Can't init skinning rig - mesh buffer is not dynamic - rigid is " + this.isRigidSkin
  5069. }
  5070. ;
  5071. SkinningRig.prototype.useOriginalMeshVertices = function(a) {
  5072. this.isRigidSkin ? this.debugString += "<br>useOriginalMeshVertices for rigid skin?" : this.copyOriginalVertices(a)
  5073. }
  5074. ;
  5075. SkinningRig.prototype.deformMeshVertices = function(a, b) {//变形! b是什么
  5076. if (0 != this.skinningClusters.length && this.unTransformedVertices) {
  5077. var c = a.stride / 4
  5078. , d = new Float32Array(a.dynamicVertexData.buffer)
  5079. , e = new Uint16Array(a.dynamicVertexData.buffer);
  5080. new Uint8Array(a.dynamicVertexData.buffer);
  5081. var f;
  5082. f = 20;
  5083. a.secondaryTexCoord && (f += 8);
  5084. var g = f
  5085. , h = f += 4;
  5086. f += 4;
  5087. for (var k = this.unTransformedVertices.length / 3, l = 0, n = 0; n < k; ++n) {
  5088. var m = n
  5089. , p = (m * a.stride + g) / 2
  5090. , r = (m * a.stride + h) / 2
  5091. , s = (m * a.stride + f) / 2
  5092. , u = this.linkMapCount[m]
  5093. , q = this.skinVertexTransform4x3;
  5094. this.skinVertexWeights[m] = 0;
  5095. q[0] = 0;
  5096. q[1] = 0;
  5097. q[2] = 0;
  5098. q[3] = 0;
  5099. q[4] = 0;
  5100. q[5] = 0;
  5101. q[6] = 0;
  5102. q[7] = 0;
  5103. q[8] = 0;
  5104. q[9] = 0;
  5105. q[10] = 0;
  5106. q[11] = 0;
  5107. var x = this.linkMapWeights[l];
  5108. if (1 == u && 1 == x) {
  5109. var w = this.linkMapClusterIndices[l]
  5110. , w = this.skinningClusters[w]
  5111. , v = w.matrix;
  5112. q[0] = v[0];
  5113. q[1] = v[1];
  5114. q[2] = v[2];
  5115. q[3] = v[4];
  5116. q[4] = v[5];
  5117. q[5] = v[6];
  5118. q[6] = v[8];
  5119. q[7] = v[9];
  5120. q[8] = v[10];
  5121. q[9] = v[12];
  5122. q[10] = v[13];
  5123. q[11] = v[14];
  5124. this.skinVertexWeights[m] = 1
  5125. } else
  5126. for (var t = this.skinVertexWeights[m] = 0; t < u; t++){
  5127. x = this.linkMapWeights[l + t];
  5128. w = this.linkMapClusterIndices[l + t];
  5129. if(w < this.skinningClusters.length){
  5130. w = this.skinningClusters[w];
  5131. v = w.matrix,
  5132. q[0] += x * v[0] //少了最底下一排的 v[15]应该都是1
  5133. q[1] += x * v[1],
  5134. q[2] += x * v[2],
  5135. q[3] += x * v[4],
  5136. q[4] += x * v[5],
  5137. q[5] += x * v[6],
  5138. q[6] += x * v[8],
  5139. q[7] += x * v[9],
  5140. q[8] += x * v[10],
  5141. q[9] += x * v[12],
  5142. q[10] += x * v[13],
  5143. q[11] += x * v[14],
  5144. this.skinVertexWeights[m] += x;
  5145. 1 == w.linkMode && (this.skinVertexWeights[m] = 1) // 应该代表当前点所有权重之和. 在下方有用到 如果强行为1,相当于取消乘以G
  5146. };
  5147. }
  5148. l += this.linkMapCount[n];
  5149. if (0 < this.skinVertexWeights[m]) {
  5150. var y = this.unTransformedVertices[3 * n + 0]
  5151. , E = this.unTransformedVertices[3 * n + 1]
  5152. , F = this.unTransformedVertices[3 * n + 2]
  5153. , A = this.unTransformedNormals[3 * n + 0]
  5154. , B = this.unTransformedNormals[3 * n + 1]
  5155. , z = this.unTransformedNormals[3 * n + 2]
  5156. , w = this.unTransformedTangents[3 * n + 0]
  5157. , v = this.unTransformedTangents[3 * n + 1]
  5158. , C = this.unTransformedTangents[3 * n + 2]
  5159. , u = this.unTransformedBiTangents[3 * n + 0]
  5160. , q = this.unTransformedBiTangents[3 * n + 1]
  5161. , x = this.unTransformedBiTangents[3 * n + 2]
  5162. , t = this.skinVertexTransform4x3
  5163. , G = 1;
  5164. 0 < this.skinVertexWeights[m] && (G = 1 / this.skinVertexWeights[m]);//这个t(也就是上面的q - -) 乘以G估计是限制总weight为1的作用
  5165. //d的计算:
  5166. d[c * n] = G * (y * t[0] + E * t[3] + F * t[6] + t[9]) * b; //新的x 原本矩阵计算是 newX = t[0]*x + t[4]*y + t[8]*z + t[12]*w, 不过这边w是1, 且矩阵最后一排省略了所以index不同
  5167. d[c * n + 1] = G * (y * t[1] + E * t[4] + F * t[7] + t[10]) * b;
  5168. d[c * n + 2] = G * (y * t[2] + E * t[5] + F * t[8] + t[11]) * b;
  5169. //e的计算: 将三个数压缩成两个
  5170. y = A * t[0] + B * t[3] + z * t[6];
  5171. m = A * t[1] + B * t[4] + z * t[7];
  5172. A = A * t[2] + B * t[5] + z * t[8];
  5173. B = w * t[0] + v * t[3] + C * t[6];
  5174. z = w * t[1] + v * t[4] + C * t[7];
  5175. w = w * t[2] + v * t[5] + C * t[8];
  5176. v = u * t[0] + q * t[3] + x * t[6];
  5177. C = u * t[1] + q * t[4] + x * t[7];
  5178. u = u * t[2] + q * t[5] + x * t[8];
  5179. q = Math.sqrt(y * y + m * m + A * A); //完整的复原算法!
  5180. y /= q;//归一
  5181. m /= q;
  5182. A /= q;
  5183. q = 32767.4 * (y / 2 + 0.5);
  5184. x = 32767.4 * (m / 2 + 0.5);
  5185. 0 > A && (x += 32768);
  5186. e[s] = Math.floor(q);
  5187. e[s + 1] = Math.floor(x);
  5188. q = Math.sqrt(B * B + z * z + w * w);
  5189. B /= q;
  5190. z /= q;
  5191. w /= q;
  5192. q = 32767.4 * (B / 2 + 0.5);
  5193. x = 32767.4 * (z / 2 + 0.5);
  5194. 0 > w && (x += 32768);
  5195. e[p] = Math.floor(q);
  5196. e[p + 1] = Math.floor(x);
  5197. q = Math.sqrt(v * v + C * C + u * u);
  5198. v /= q;
  5199. C /= q;
  5200. u /= q;
  5201. q = 32767.4 * (v / 2 + 0.5);
  5202. x = 32767.4 * (C / 2 + 0.5);
  5203. 0 > u && (x += 32768);
  5204. e[r] = Math.floor(q);
  5205. e[r + 1] = Math.floor(x)
  5206. } else
  5207. y = this.unTransformedVertices[3 * n + 0],
  5208. E = this.unTransformedVertices[3 * n + 1],
  5209. F = this.unTransformedVertices[3 * n + 2],
  5210. d[c * n] = y * b,
  5211. d[c * n + 1] = E * b,
  5212. d[c * n + 2] = F * b
  5213. }
  5214. }
  5215. }
  5216. ;
  5217. SkinningRig.prototype.deformMesh = function(a, b) {
  5218. if (0 != this.skinningClusters.length && !this.isRigidSkin) {
  5219. this.deformMeshVertices(a, b);
  5220. var c = a.gl;
  5221. c.bindBuffer(c.ARRAY_BUFFER, a.vertexBuffer);
  5222. c.bufferData(c.ARRAY_BUFFER, a.dynamicVertexData, c.DYNAMIC_DRAW);
  5223. c.bindBuffer(c.ARRAY_BUFFER, null)
  5224. }
  5225. }
  5226. ;
  5227. function Sky(a, b, c) {
  5228. this.gl = a;
  5229. var d = b.extract("sky.dat") || b.extract("sky.png");
  5230. if (void 0 !== d) {
  5231. this.specularTexture = new Texture(a,{
  5232. width: 256,
  5233. height: 2048,
  5234. clamp: !0
  5235. });
  5236. b = d.data;
  5237. for (var d = d.data.length, e = d / 4, f = new Uint8Array(d), g = 0, h = 0; g < d; ++h)
  5238. f[g++] = b[h + 2 * e],
  5239. f[g++] = b[h + e],
  5240. f[g++] = b[h],
  5241. f[g++] = b[h + 3 * e];
  5242. this.specularTexture.loadArray(f)
  5243. }
  5244. this.diffuseCoefficients = new Float32Array(c.diffuseCoefficients);
  5245. this.backgroundMode = c.backgroundMode || 0;
  5246. this.backgroundBrightness = c.backgroundBrightness || 1;
  5247. this.backgroundColor = new Float32Array(c.backgroundColor);
  5248. if (1 <= this.backgroundMode)
  5249. if (this.backgroundShader = a.shaderCache.fromURLs("skyvert.glsl", 3 == this.backgroundMode ? "skySH.glsl" : "sky.glsl", ["#define SKYMODE " + this.backgroundMode]),
  5250. this.vertexBuffer = a.createBuffer(),
  5251. a.bindBuffer(a.ARRAY_BUFFER, this.vertexBuffer),
  5252. c = 1 / 256,
  5253. b = 0.5 / 256,
  5254. d = 2.8 * b,
  5255. e = 0.5 * b,
  5256. c = new Float32Array([0, 1, 0, 0.49609375 + c, 0.49609375 + c, 1, 0, 0, 0.9921875 + c, 0.49609375 + c, 0, 0, 1, 0.49609375 + c, 0.9921875 + c, -1, 0, 0, 0 + c, 0.49609375 + c, 0, 0, -1, 0.49609375 + c, 0 + c, 0, -1, 0, 0.9921875 + c, 0 + c, 0, -1, 0, 0.9921875 + c, 0.9921875 + c, 0, -1, 0, 0 + c, 0.9921875 + c, 0, -1, 0, 0 + c, 0 + c, d, 1 - d, -d, 0.5 + b, 0.5 - b, d, 1 - d, d, 0.5 + b, 0.5 + b, -d, 1 - d, d, 0.5 - b, 0.5 + b, -d, 1 - d, -d, 0.5 - b, 0.5 - b, -d, 0, -1 + d, 0.5 - b, 0 + c + b, d, 0, -1 + d, 0.5 + b, 0 + c + b, 1 - d, 0, -d, 0.9921875 + c - b, 0.5 - b, 1 - d, 0, d, 0.9921875 + c - b, 0.5 + b, d, 0, 1 - d, 0.5 + b, 0.9921875 + c - b, -d, 0, 1 - d, 0.5 - b, 0.9921875 + c - b, -1 + d, 0, d, 0 + c + b, 0.5 + b, -1 + d, 0, -d, 0 + c + b, 0.5 - b, 1, 0, 0, 0.9921875 + c - e, 0.49609375 + c, 0, 0, 1, 0.49609375 + c, 0.9921875 + c - e, -1, 0, 0, 0 + c + e, 0.49609375 + c, 0, 0, -1, 0.49609375 + c, 0 + c + e, 0, 1, 0, 0.49609375 + c - e, 0.49609375 + c, 0, 1, 0, 0.49609375 + c, 0.49609375 + c - e, 0, 1, 0, 0.49609375 + c + e, 0.49609375 + c, 0, 1, 0, 0.49609375 + c, 0.49609375 + c + e]),
  5257. a.bufferData(a.ARRAY_BUFFER, c, a.STATIC_DRAW),
  5258. a.bindBuffer(a.ARRAY_BUFFER, null),
  5259. this.indexBuffer = a.createBuffer(),
  5260. a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, this.indexBuffer),
  5261. c = 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]),
  5262. this.skyIndexCount = c.length,
  5263. a.bufferData(a.ELEMENT_ARRAY_BUFFER, c, a.STATIC_DRAW),
  5264. a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, null),
  5265. 3 == this.backgroundMode)
  5266. for (this.backgroundCoefficients = new Float32Array(this.diffuseCoefficients),
  5267. g = 0; g < this.backgroundCoefficients.length; ++g)
  5268. this.backgroundCoefficients[g] *= this.backgroundBrightness;
  5269. else {
  5270. this.backgroundTexture = new Texture(a,{
  5271. width: 256,
  5272. height: 256,
  5273. clamp: !0
  5274. });
  5275. c = !1;
  5276. var k;
  5277. a.ext.textureHalf && a.ext.textureHalfLinear && (this.backgroundTexture.loadArray(null, a.RGB, a.ext.textureHalf.HALF_FLOAT_OES),
  5278. k = new Framebuffer(a,{
  5279. color0: this.backgroundTexture
  5280. }),
  5281. c = k.valid);
  5282. !c && a.ext.textureFloat && a.ext.textureFloatLinear && !a.hints.mobile && (this.backgroundTexture.loadArray(null, a.RGB, a.FLOAT),
  5283. k = new Framebuffer(a,{
  5284. color0: this.backgroundTexture
  5285. }),
  5286. c = k.valid);
  5287. c || (this.backgroundTexture.loadArray(),
  5288. k = new Framebuffer(a,{
  5289. color0: this.backgroundTexture
  5290. }));
  5291. k.bind();
  5292. k = new Shader(a);
  5293. 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);}");
  5294. k.bind();
  5295. a.uniform1f(k.params.b, 7 * Math.sqrt(this.backgroundBrightness));
  5296. this.specularTexture.bind(k.samplers.tex);
  5297. c = a.createBuffer();
  5298. a.bindBuffer(a.ARRAY_BUFFER, c);
  5299. c = new Float32Array([-1, -1, 0.5, 1, 3, -1, 0.5, 1, -1, 3, 0.5, 1]);
  5300. a.bufferData(a.ARRAY_BUFFER, c, a.STATIC_DRAW);
  5301. a.enableVertexAttribArray(k.attribs.p);
  5302. a.vertexAttribPointer(k.attribs.p, 4, a.FLOAT, !1, 0, 0);
  5303. a.drawArrays(a.TRIANGLES, 0, 3);
  5304. a.disableVertexAttribArray(k.attribs.p)
  5305. }
  5306. }
  5307. Sky.prototype.setClearColor = function() {
  5308. if (fdage.transparentBackground)
  5309. this.gl.clearColor(0, 0, 0, 0);
  5310. else if (1 > this.backgroundMode) {
  5311. var a = this.backgroundColor;
  5312. this.gl.clearColor(a[0], a[1], a[2], 1)
  5313. } else
  5314. this.gl.clearColor(0.0582, 0.06772, 0.07805, 1)
  5315. }
  5316. ;
  5317. Sky.prototype.draw = function(a) {
  5318. if (1 > this.backgroundMode || fdage.transparentBackground)
  5319. return !1;
  5320. if (this.complete()) {
  5321. var b = this.gl
  5322. , c = this.backgroundShader
  5323. , d = a.view
  5324. , e = a.lights.invMatrix;
  5325. c.bind();
  5326. b.uniformMatrix4fv(c.params.uInverseSkyMatrix, !1, e);
  5327. b.uniformMatrix4fv(c.params.uViewProjection, !1, d.viewProjectionMatrix);
  5328. 3 == this.backgroundMode ? b.uniform4fv(c.params.uSkyCoefficients, this.backgroundCoefficients) : this.backgroundTexture.bind(c.samplers.tSkyTexture);
  5329. a = 0.07 + 0.94 * (1 - a.stripData.activeFade());
  5330. b.uniform1f(c.params.uAlpha, a);
  5331. b.bindBuffer(b.ARRAY_BUFFER, this.vertexBuffer);
  5332. b.enableVertexAttribArray(c.attribs.vPosition);
  5333. b.vertexAttribPointer(c.attribs.vPosition, 3, b.FLOAT, !1, 20, 0);
  5334. b.enableVertexAttribArray(c.attribs.vTexCoord);
  5335. b.vertexAttribPointer(c.attribs.vTexCoord, 2, b.FLOAT, !1, 20, 12);
  5336. b.bindBuffer(b.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
  5337. 1 > a && (b.enable(b.BLEND),
  5338. b.blendFunc(b.SRC_ALPHA, b.ONE_MINUS_SRC_ALPHA));
  5339. b.depthMask(!1);
  5340. b.disable(b.DEPTH_TEST);
  5341. b.drawElements(b.TRIANGLES, this.skyIndexCount, b.UNSIGNED_SHORT, 0);
  5342. b.enable(b.DEPTH_TEST);
  5343. b.depthMask(!0);
  5344. 1 > a && b.disable(b.BLEND);
  5345. b.disableVertexAttribArray(c.attribs.vPosition);
  5346. b.disableVertexAttribArray(c.attribs.vTexCoord)
  5347. }
  5348. }
  5349. ;
  5350. Sky.prototype.complete = function() {
  5351. return this.backgroundShader && !this.backgroundShader.complete() ? !1 : this.specularTexture.complete()
  5352. }
  5353. ;
  5354. function StripData() {
  5355. this.STRIP_NONE = -2;
  5356. this.STRIP_MENU = -1;
  5357. this.stripCount = 5;
  5358. this.strips = [0, 0, 0, 0, 0];
  5359. this.labels = ["Normals", "Albedo", "Reflectivity", "Gloss", "Topology"];
  5360. this.stripSlant = 0.25;
  5361. this.selectedStrip = this.STRIP_NONE;
  5362. this.animationActive = !1;
  5363. this.timestamp = Date.now();
  5364. this.update(!0)
  5365. }
  5366. StripData.expDecay = function(a, b) {
  5367. return Math.exp(-0.69314718 / a * b)
  5368. }
  5369. ;
  5370. StripData.prototype.update = function(a) {
  5371. var b = 0.001 * (Date.now() - this.timestamp);
  5372. this.timestamp = Date.now();
  5373. for (var c = !1, d = 0; d < this.stripCount; ++d) {
  5374. var e = 0
  5375. , e = this.selectedStrip == this.STRIP_MENU ? -0.9 + 0.3 * (d + 1) : 0 > this.selectedStrip || d < this.selectedStrip ? -2 : 2;
  5376. if (a)
  5377. this.strips[d] = e;
  5378. else {
  5379. var f = e - this.strips[d]
  5380. , f = f * StripData.expDecay(0.05, b);
  5381. this.animationActive && (this.strips[d] = e - f);
  5382. c = c || 0.001 < Math.abs(f)
  5383. }
  5384. }
  5385. this.animationActive = c
  5386. }
  5387. ;
  5388. StripData.prototype.active = function() {
  5389. return this.selectedStrip >= this.STRIP_MENU
  5390. }
  5391. ;
  5392. StripData.prototype.activeFade = function() {
  5393. var a = (this.strips[this.stripCount - 1] - -2) / (-0.9 + 0.3 * this.stripCount - -2)
  5394. , a = 1 < a ? 1 : a;
  5395. return 0 > a ? 0 : a
  5396. }
  5397. ;
  5398. StripData.prototype.activeWireframe = function() {
  5399. return this.active() && 0.01 < Math.abs(this.strips[4] - this.strips[3])
  5400. }
  5401. ;
  5402. StripData.prototype.toggleMenu = function() {
  5403. this.selectedStrip = this.selectedStrip == this.STRIP_MENU ? this.STRIP_NONE : this.STRIP_MENU
  5404. }
  5405. ;
  5406. StripData.prototype.selectStrip = function(a, b) {
  5407. if (this.selectedStrip == this.STRIP_MENU) {
  5408. var c = a + b * this.stripSlant;
  5409. this.selectedStrip = this.STRIP_NONE;
  5410. for (var d = 0; d < this.stripCount; ++d)
  5411. if (c < this.strips[d]) {
  5412. this.selectedStrip = d;
  5413. break
  5414. }
  5415. } else
  5416. this.selectedStrip = this.STRIP_MENU
  5417. }
  5418. ;
  5419. function Texture(a, b) {
  5420. this.gl = a;
  5421. this.id = null;
  5422. this.type = a.TEXTURE_2D;
  5423. this.format = a.RGBA;
  5424. this.componentType = a.UNSIGNED_BYTE;
  5425. b = b || {};
  5426. this.desc = {
  5427. width: b.width || 1,
  5428. height: b.height || 1,
  5429. mipmap: b.mipmap,
  5430. clamp: b.clamp,
  5431. mirror: b.mirror,
  5432. aniso: b.aniso,
  5433. nofilter: b.nofilter
  5434. }
  5435. }
  5436. Texture.prototype.loadImage = function(a, b) {
  5437. var c = this.gl;
  5438. a && a.width && a.height && (this.desc.width = a.width,
  5439. this.desc.height = a.height);
  5440. this.id = c.createTexture();
  5441. c.bindTexture(this.type, this.id);
  5442. this.format = b || c.RGBA;
  5443. this.componentType = c.UNSIGNED_BYTE;
  5444. c.pixelStorei(c.UNPACK_FLIP_Y_WEBGL, !0);
  5445. c.texImage2D(this.type, 0, this.format, this.format, this.componentType, a);
  5446. this.setParams();
  5447. c.bindTexture(this.type, null)
  5448. }
  5449. ;
  5450. Texture.prototype.loadArray = function(a, b, c) {
  5451. var d = this.gl;
  5452. this.id = d.createTexture();
  5453. d.bindTexture(this.type, this.id);
  5454. this.format = b || d.RGBA;
  5455. this.componentType = c || d.UNSIGNED_BYTE;
  5456. //d.pixelStorei(d.UNPACK_FLIP_Y_WEBGL, !0);
  5457. d.pixelStorei(d.UNPACK_ALIGNMENT, !0);
  5458. d.texImage2D(this.type, 0, this.format, this.desc.width, this.desc.height, 0, this.format, this.componentType, a || null);
  5459. this.setParams();
  5460. d.bindTexture(this.type, null)
  5461. }
  5462. ;
  5463. Texture.prototype.setParams = function() {
  5464. var a = this.gl
  5465. , b = function(a) {
  5466. return 0 < a && 0 == (a & a - 1)
  5467. };
  5468. b(this.desc.width) && b(this.desc.height) || (this.desc.clamp = !0,
  5469. this.desc.mipmap = !1);
  5470. b = !this.desc.nofilter;
  5471. this.desc.mipmap ? (a.generateMipmap(this.type),
  5472. a.texParameteri(this.type, a.TEXTURE_MIN_FILTER, b ? a.LINEAR_MIPMAP_LINEAR : a.NEAREST_MIPMAP_NEAREST)) : a.texParameteri(this.type, a.TEXTURE_MIN_FILTER, b ? a.LINEAR : a.NEAREST);
  5473. a.texParameteri(this.type, a.TEXTURE_MAG_FILTER, b ? a.LINEAR : a.NEAREST);
  5474. if (this.desc.clamp || this.desc.mirror)
  5475. b = this.desc.clamp ? a.CLAMP_TO_EDGE : a.MIRRORED_REPEAT,
  5476. a.texParameteri(this.type, a.TEXTURE_WRAP_S, b),
  5477. a.texParameteri(this.type, a.TEXTURE_WRAP_T, b);
  5478. this.desc.aniso && a.ext.textureAniso && a.texParameteri(this.type, a.ext.textureAniso.TEXTURE_MAX_ANISOTROPY_EXT, this.desc.aniso)
  5479. }
  5480. ;
  5481. Texture.prototype.rebuildMips = function() {
  5482. this.desc.mipmap && (this.gl.bindTexture(this.type, this.id),
  5483. this.gl.generateMipmap(this.type))
  5484. }
  5485. ;
  5486. Texture.prototype.copyColorBuffer = function() {
  5487. this.gl.bindTexture(this.type, this.id);
  5488. this.gl.copyTexSubImage2D(this.type, 0, 0, 0, 0, 0, this.desc.width, this.desc.height)
  5489. }
  5490. ;
  5491. Texture.prototype.bind = function(a) {
  5492. if (a) {
  5493. var b = this.gl;
  5494. b.uniform1i(a.location, a.unit);
  5495. b.activeTexture(b.TEXTURE0 + a.unit);
  5496. b.bindTexture(this.type, this.id)
  5497. }
  5498. }
  5499. ;
  5500. Texture.prototype.destroy = function() {
  5501. this.gl.deleteTexture(this.id);
  5502. this.id = null
  5503. }
  5504. ;
  5505. Texture.prototype.complete = function() {
  5506. return !!this.id
  5507. }
  5508. ;
  5509. function TextureCache(a) {
  5510. this.gl = a;
  5511. this.cache = []
  5512. }
  5513. TextureCache.prototype.fromURL = function(a, b) {
  5514. var c = this.cache[a];
  5515. if (void 0 !== c)
  5516. return c;
  5517. var d = new Texture(this.gl,b);
  5518. Network.fetchImage(a, function(a) {
  5519. d.loadImage(a)
  5520. });
  5521. return this.cache[a] = d
  5522. }
  5523. ;
  5524. TextureCache.prototype.fromFile = function(a, b) {
  5525. if (!a)
  5526. return null;
  5527. var c = this.cache[a.name];
  5528. if (void 0 !== c)
  5529. return c;
  5530. var d = new Texture(this.gl,b);
  5531. this.cache[a.name] = d;
  5532. TextureCache.parseFile(a, function(a) {
  5533. d.loadImage(a);
  5534. TextureCache.closeImage(a)
  5535. });
  5536. return d
  5537. }
  5538. ;
  5539. TextureCache.prototype.fromFilesMergeAlpha = function(a, b, c) {
  5540. if (!b)
  5541. return this.fromFile(a, c);
  5542. var d = a.name + "|" + b.name
  5543. , e = this.cache[d];
  5544. if (void 0 !== e)
  5545. return e;
  5546. var f = this.gl;
  5547. this.blitShader || (this.blitShader = new Shader(this.gl),
  5548. 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; }"),
  5549. this.mergeVerts = f.createBuffer(),
  5550. f.bindBuffer(f.ARRAY_BUFFER, this.mergeVerts),
  5551. e = new Float32Array([0, 0, 2, 0, 0, 2]),
  5552. f.bufferData(f.ARRAY_BUFFER, e, f.STATIC_DRAW),
  5553. f.bindBuffer(f.ARRAY_BUFFER, null));
  5554. var g = function(a) {
  5555. this.blitShader.bind();
  5556. a.bind(this.blitShader.samplers.tTex);
  5557. f.bindBuffer(f.ARRAY_BUFFER, this.mergeVerts);
  5558. f.enableVertexAttribArray(this.blitShader.attribs.pos);
  5559. f.vertexAttribPointer(this.blitShader.attribs.pos, 2, f.FLOAT, !1, 0, 0);
  5560. f.drawArrays(f.TRIANGLES, 0, 3);
  5561. f.disableVertexAttribArray(this.blitShader.attribs.pos);
  5562. f.bindBuffer(f.ARRAY_BUFFER, null)
  5563. }
  5564. .bind(this)
  5565. , h = new Texture(this.gl,c);
  5566. this.cache[d] = h;
  5567. var k = 0
  5568. , l = 0
  5569. , n = function() {
  5570. if (k && l) {
  5571. var a, b;
  5572. l.width * l.height > k.width * k.height ? (a = l.width,
  5573. b = l.height) : (a = k.width,
  5574. b = k.height);
  5575. h.desc.width = a;
  5576. h.desc.height = b;
  5577. if (a <= f.limits.viewportSizes[0] && b <= f.limits.viewportSizes[1]) {
  5578. var c = {
  5579. clamp: !0
  5580. };
  5581. k.width == a && k.height == b ? (h.loadImage(k, f.RGBA),
  5582. a = new Framebuffer(f,{
  5583. color0: h,
  5584. ignoreStatus: !0
  5585. }),
  5586. TextureCache.closeImage(k)) : (b = new Texture(f,c),
  5587. b.loadImage(k, f.RGB),
  5588. TextureCache.closeImage(k),
  5589. h.loadArray(null),
  5590. a = new Framebuffer(f,{
  5591. color0: h,
  5592. ignoreStatus: !0
  5593. }),
  5594. a.bind(),
  5595. g(b),
  5596. b.destroy());
  5597. b = new Texture(f,c);
  5598. b.loadImage(l, f.RGB);
  5599. TextureCache.closeImage(l);
  5600. a.bind();
  5601. f.colorMask(!1, !1, !1, !0);
  5602. g(b);
  5603. f.colorMask(!0, !0, !0, !0);
  5604. b.destroy();
  5605. Framebuffer.bindNone(f);
  5606. h.rebuildMips()
  5607. } else {
  5608. c = document.createElement("canvas");
  5609. c.width = a;
  5610. c.height = b;
  5611. var d = c.getContext("2d");
  5612. d.drawImage(k, 0, 0);
  5613. TextureCache.closeImage(k);
  5614. c = d.getImageData(0, 0, a, b);
  5615. c = new Uint8Array(c.data.buffer,c.data.byteOffset,c.data.length);
  5616. d.drawImage(l, 0, 0);
  5617. TextureCache.closeImage(l);
  5618. d = d.getImageData(0, 0, a, b).data;
  5619. a = a * b * 4;
  5620. for (b = 0; b < a; b += 4)
  5621. c[b + 3] = d[b];
  5622. h.loadArray(c)
  5623. }
  5624. TextureCache.closeImage(l)
  5625. }
  5626. }
  5627. .bind(this);
  5628. TextureCache.parseFile(a, function(a) {
  5629. k = a;
  5630. n()
  5631. });
  5632. TextureCache.parseFile(b, function(a) {
  5633. l = a;
  5634. n()
  5635. });
  5636. return h
  5637. }
  5638. ;
  5639. TextureCache.parseFile = function(a, b, c) {
  5640. var d = c || new Image;
  5641. if ("undefined" != typeof URL && "undefined" != typeof URL.createObjectURL) {
  5642. a = new Blob([a.data],{
  5643. type: a.type
  5644. });
  5645. var e = URL.createObjectURL(a);
  5646. d.onload = function() {
  5647. URL.revokeObjectURL(e);
  5648. b && b(d)
  5649. }
  5650. ;
  5651. d.src = e
  5652. } else {
  5653. a = new Blob([a.data],{
  5654. type: a.type
  5655. });
  5656. var f = new FileReader;
  5657. f.onload = function(a) {
  5658. d.src = f.result
  5659. }
  5660. ;
  5661. d.onload = function() {
  5662. b && b(d)
  5663. }
  5664. ;
  5665. f.readAsDataURL(a)
  5666. }
  5667. }
  5668. ;
  5669. TextureCache.closeImage = function(a) {
  5670. a && 256 < a.width * a.height && (a.onload = null,
  5671. a.onerror = null,
  5672. a.src = "data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs%3D")
  5673. }
  5674. ;
  5675. function TimelineSlider(a, b) {
  5676. this.name = "none";
  5677. this.debugString = "";
  5678. this.knobControlRect = new ControlRect(a);
  5679. this.controlRect = new ControlRect(a);
  5680. var c = document.createElement("div");
  5681. c.id = "sliderUI";
  5682. c.style.position = "absolute";
  5683. c.style.overflow = "hidden";
  5684. c.style["-moz-user-select"] = "none";
  5685. c.style["-khtml-user-select"] = "none";
  5686. c.style["-webkit-user-select"] = "none";
  5687. c.style["-ms-user-select"] = "none";
  5688. this.controlRect.linkedControl = c;
  5689. this.backgroundControl = 0;
  5690. this.controlRect.registerChildControlRect(this.knobControlRect);
  5691. this.knobControlRect.setOpacity(0.65);
  5692. this.sliderPercent = this.pixelsY = this.pixelsX = 0;
  5693. this.draggingSlider = !1;
  5694. this.guiScreen = a;
  5695. b.addImageElement(this.knobControlRect, "animationknob" + a.imageSetNumber + "x.png")
  5696. }
  5697. TimelineSlider.prototype.setBackground3x1 = function(a, b, c, d) {
  5698. var e = 8 / this.controlRect.getScreenHeight();
  5699. this.backgroundControl = a.addTextButton("", 0, (1 - e) / 2, 1, e, 1);
  5700. this.backgroundControl.defaultAlpha = 1;
  5701. this.backgroundControl.setBackground3x1(a, 0, 0, b, c, d, 4);
  5702. this.backgroundControl.controlRect.xPercent = this.controlRect.xPercent;
  5703. this.backgroundControl.controlRect.widthPercent = this.controlRect.widthPercent;
  5704. this.controlRect.linkedControl.style.zIndex = "3";
  5705. this.setupCallbacks()
  5706. }
  5707. ;
  5708. TimelineSlider.prototype.setSize = function(a, b) {
  5709. this.pixelsX = a;
  5710. this.pixelsY = b;
  5711. var c = 24 / b;
  5712. this.knobWidthPercent = 24 / a;
  5713. this.knobControlRect.xPercent = 0.5 - this.knobWidthPercent / 2;
  5714. this.knobControlRect.yPercent = (1 - c) / 2 + -1 / b;
  5715. this.knobControlRect.widthPercent = this.knobWidthPercent;
  5716. this.knobControlRect.heightPercent = c;
  5717. this.controlRect.updateElement();
  5718. this.backgroundControl.controlRect.xPercent = this.controlRect.xPercent;
  5719. this.backgroundControl.controlRect.widthPercent = this.controlRect.widthPercent;
  5720. this.backgroundControl.controlRect.updateElement()
  5721. }
  5722. ;
  5723. TimelineSlider.prototype.setSliderPercent = function(a) {
  5724. 0 > a && (a = 0);
  5725. 1 < a && (a = 1);
  5726. this.sliderPercent = a;
  5727. this.knobControlRect.xPercent = a - this.knobWidthPercent / 2;
  5728. this.knobControlRect.updateElement()
  5729. }
  5730. ;
  5731. TimelineSlider.prototype.setupCallbacks = function() {
  5732. var a = function(a) {
  5733. if (this.draggingSlider) {
  5734. var b = this.backgroundControl.controlRect.linkedControl.getBoundingClientRect();
  5735. this.setSliderPercent((a.clientX - b.left) / b.width);
  5736. this.guiScreen.ui.viewer.scene.sceneAnimator.setAnimationProgress(this.sliderPercent, !0);
  5737. this.guiScreen.ui.viewer.scene.sceneAnimator.paused && (this.guiScreen.ui.viewer.scene.postRender.discardAAHistory(),
  5738. this.guiScreen.ui.viewer.reDrawScene())
  5739. }
  5740. }
  5741. .bind(this)
  5742. , b = function(a) {
  5743. this.draggingSlider = !0;
  5744. var b = this.backgroundControl.controlRect.linkedControl.getBoundingClientRect();
  5745. this.setSliderPercent((a.clientX - b.left) / b.width);
  5746. this.guiScreen.ui.viewer.scene.sceneAnimator.setAnimationProgress(this.sliderPercent, !0);
  5747. this.guiScreen.ui.viewer.scene.sceneAnimator.lockPlayback = !0;
  5748. this.guiScreen.ui.viewer.scene.sceneAnimator.paused && (this.guiScreen.ui.viewer.scene.postRender.discardAAHistory(),
  5749. this.guiScreen.ui.viewer.reDrawScene())
  5750. }
  5751. .bind(this)
  5752. , c = function(a) {
  5753. this.draggingSlider = !1;
  5754. this.guiScreen.ui.viewer.scene.sceneAnimator.lockPlayback = !1
  5755. }
  5756. .bind(this);
  5757. this.guiScreen.ui.viewer.input.element.addEventListener("mousemove", a);
  5758. this.guiScreen.ui.viewer.input.element.addEventListener("mouseup", c);
  5759. this.backgroundControl.controlRect.linkedControl.addEventListener("mousemove", a);
  5760. this.backgroundControl.controlRect.linkedControl.addEventListener("mousedown", b);
  5761. this.backgroundControl.controlRect.linkedControl.addEventListener("mouseup", c);
  5762. this.controlRect.linkedControl.addEventListener("mouseup", c)
  5763. }
  5764. ;
  5765. function UI(a) {
  5766. this.viewer = a;
  5767. this.stripData = a.stripData;
  5768. a = this.container = document.createElement("div");
  5769. a.id = "fdageUI"; //xst
  5770. a.style.position = "absolute";
  5771. a.style.overflow = "hidden";
  5772. a.style["-moz-user-select"] = "none";
  5773. a.style["-khtml-user-select"] = "none";
  5774. a.style["-webkit-user-select"] = "none";
  5775. a.style["-ms-user-select"] = "none";
  5776. this.viewer.domRoot.appendChild(a)
  5777. this.guiScreen = new GUIScreen(this)
  5778. }
  5779. UI.prototype.setSize = function(a, b) {
  5780. this.container.width = a | 0;
  5781. this.container.height = b | 0;
  5782. this.container.style.width = a + "px";
  5783. this.container.style.height = b + "px";
  5784. this.guiScreen.setSize(this.container.width, this.container.height)
  5785. }
  5786. ;
  5787. UI.prototype.clearView = function() {
  5788. for (; this.container.hasChildNodes(); )
  5789. this.container.removeChild(this.container.childNodes[0]);
  5790. delete this.progressBar;
  5791. delete this.thumbnail;
  5792. delete this.fadeThumbnail;
  5793. delete this.playButton;
  5794. delete this.helpOverlay
  5795. }
  5796. ;
  5797. UI.prototype.bindInput = function(a) {
  5798. a.onSingleTap.push(function(b, c) {
  5799. this.stripData.selectedStrip != this.stripData.STRIP_NONE && (b = 2 / a.element.clientWidth * b - 1,
  5800. c = 1 - 2 / a.element.clientHeight * c,
  5801. this.stripData.selectStrip(b, c),
  5802. this.stripData.selectedStrip == this.stripData.STRIP_MENU && this.helpOverlay.active && this.helpOverlay.toggle(),
  5803. this.refreshUI(),
  5804. this.viewer.wake())
  5805. }
  5806. .bind(this))
  5807. }
  5808. ;
  5809. UI.sanitize = function(a) {
  5810. return a ? a.replace(/<|>|\(|\)|$|%|=/g, "") : a
  5811. }
  5812. ;
  5813. UI.sanitizeURL = function(a) {
  5814. return a ? 0 == a.indexOf("http://") || 0 == a.indexOf("https://") || 0 == a.indexOf("ftp://") ? encodeURI(a) : "http://" + encodeURI(a) : a
  5815. }
  5816. ;
  5817. UI.prototype.showFailure = function(info,w) {//许钟文改
  5818. this.container.innerHTML = "";
  5819. var errorCanvas = document.createElement('canvas');
  5820. var ra = this.container.width / this.container.height;
  5821. errorCanvas.width = 100;
  5822. errorCanvas.height = errorCanvas.height * ra | 0;
  5823. errorCanvas.style.position = "absolute";
  5824. errorCanvas.style['z-index'] = "0";
  5825. errorCanvas.style.width = errorCanvas.style.height = "100%";
  5826. var a = errorCanvas.getContext("2d");
  5827. var b = a.fillStyle = a.createRadialGradient(errorCanvas.width / 2, errorCanvas.height / 2, (errorCanvas.width + errorCanvas.height) / 2, errorCanvas.width / 2, errorCanvas.height/2, 0);//(xStart, yStart, radiusStart, xEnd, yEnd, radiusEnd)
  5828. b.addColorStop(0, "rgb(0,0,0)");
  5829. b.addColorStop(1, "rgb(35,60,80)");//22,43,64 117,133,148
  5830. a.fillStyle = b;
  5831. a.fillRect(0, 0, errorCanvas.width, errorCanvas.height);
  5832. this.container.appendChild(errorCanvas);
  5833. var errorDiv = document.createElement('div');
  5834. errorDiv.classList.add('error');
  5835. errorDiv.style["background-image"] = "url(images/errorBG.png)";
  5836. var msg = '<div class="errorInfo"><p style="font-size:1.5em; font-weight:lighter">转换模型时出错</p>'
  5837. +'<p style="font-size:1.3em;letter-spacing:2px;font-weight:bold;line-height:1.5em;margin-top:30px">错误信息: '+(info || "文件无效(ERROR)请检查您所上传的文件以确定其稳定性") + '</p>'
  5838. +'<p style="font-size:0.8em;line-height:1.5em; margin-top:50px">您可以联系我们的客服、或点击<a href="http://www.4dageweb.com/tutorial.html" style="color: #a6ccea;">视频教程</a>获取更详细的上传解说<br>4Dweb将全程为您提供最优质的模型展示</p></div>'
  5839. errorDiv.innerHTML = msg;
  5840. this.container.appendChild(errorDiv);
  5841. /* function reportError(uuid)
  5842. {
  5843. var inputdata={};
  5844. inputdata.uuid = uuid;
  5845. $.ajax({
  5846. url: "http://www.4dage.com/FdageModel/setModelError",
  5847. type: 'POST',
  5848. async:true,
  5849. dataType:"jsonp",
  5850. data : inputdata,
  5851. success: function(data){
  5852. },
  5853. error: function (msg) {
  5854. console.log("model error");
  5855. }
  5856. });
  5857. }
  5858. reportError(w.sceneURL); */
  5859. }
  5860. ;
  5861. UI.prototype.showPreview = function(a) {
  5862. this.clearView();
  5863. this.thumbnail = document.createElement("canvas");
  5864. var b = this.container.width / this.container.height;
  5865. this.thumbnail.height = this.viewer.mobile ? 200 : 300;
  5866. this.thumbnail.width = this.thumbnail.height * b | 0;
  5867. this.thumbnail.style.width = this.thumbnail.style.height = "100%";
  5868. var b = this.thumbnail.getContext("2d")
  5869. , c = b.fillStyle = b.createRadialGradient(this.thumbnail.width / 2, this.thumbnail.height / 2, (this.thumbnail.width + this.thumbnail.height) / 2, this.thumbnail.width / 2, 0, 0);
  5870. c.addColorStop(0, "rgb(0,0,0)");
  5871. c.addColorStop(1, "rgb(150,150,150)");
  5872. b.fillStyle = c;
  5873. b.fillRect(0, 0, this.thumbnail.width, this.thumbnail.height);
  5874. this.container.appendChild(this.thumbnail);
  5875. /* this.playButton = document.createElement("input"); //许钟文改
  5876. this.playButton.type = "image";
  5877. this.playButton.src = fdage.dataLocale + "play.png";
  5878. this.playButton.style.position = "absolute";
  5879. this.playButton.style.left = "50%";
  5880. this.playButton.style.top = "50%";
  5881. this.playButton.style["-webkit-transform"] = this.playButton.style.transform = "translate(-50%,-50%) scale(0.5,0.5)";
  5882. this.playButton.style.opacity = 0.5;
  5883. this.playButton.style.outline = "0px";
  5884. this.playButton.onclick = function() {
  5885. this.viewer.loadScene(this.viewer.sceneURL);
  5886. this.container.removeChild(this.playButton);
  5887. delete this.playButton
  5888. }
  5889. .bind(this);
  5890. this.container.appendChild(this.playButton); */
  5891. a || fetchThumbnail(this.viewer.sceneURL, function(a) {
  5892. this.loadingImageURL || this.setThumbnail(a)
  5893. }
  5894. .bind(this))
  5895. }
  5896. ;
  5897. UI.prototype.setThumbnailURL = function(a) {
  5898. (this.loadingImageURL = a) && Network.fetchImage(this.loadingImageURL, this.setThumbnail.bind(this))
  5899. }
  5900. ;
  5901. UI.prototype.setThumbnail = function(a) {
  5902. if (this.thumbnail)
  5903. if (a.height >= this.container.height) {
  5904. var b = this.container.height / a.height;
  5905. a.style.position = "absolute";
  5906. a.style.outline = "0px";
  5907. a.style.left = "50%";
  5908. a.style.top = "50%";
  5909. a.style["-webkit-transform"] = a.style.transform = "translate(-50%,-50%) scale(" + b + "," + b + ")";
  5910. this.container.replaceChild(a, this.thumbnail);
  5911. this.thumbnail = a
  5912. } else {
  5913. var c = this.thumbnail.getContext("2d")
  5914. , d = this.thumbnail.width
  5915. , e = this.thumbnail.height
  5916. , b = e / a.height;
  5917. c.drawImage(a, (d - a.width * b) / 2, 0, a.width * b, e);
  5918. var f;
  5919. try {
  5920. f = c.getImageData(0, 0, d, e)
  5921. } catch (g) {
  5922. return
  5923. }
  5924. a = c.createImageData(d, e);
  5925. for (var h = 0; 2 > h; ++h) {
  5926. for (var b = f.data, k = a.data, l = 0, n = 0; n < e; ++n)
  5927. for (var m = 0; m < d; ++m) {
  5928. for (var p = 0, r = 0, s = 0, u = -2; 2 >= u; ++u)
  5929. for (var q = n + u, q = 0 > q ? 0 : q >= e ? e - 1 : q, x = -2; 2 >= x; ++x)
  5930. var w = m + x
  5931. , w = 0 > w ? 0 : w >= d ? d - 1 : w
  5932. , w = 4 * (q * d + w)
  5933. , p = p + b[w]
  5934. , r = r + b[w + 1]
  5935. , s = s + b[w + 2];
  5936. k[l++] = p / 25;
  5937. k[l++] = r / 25;
  5938. k[l++] = s / 25;
  5939. k[l++] = 255
  5940. }
  5941. b = f;
  5942. f = a;
  5943. a = b
  5944. }
  5945. c.putImageData(f, 0, 0)
  5946. }
  5947. }
  5948. ;
  5949. UI.prototype.showActiveView = function() {//许钟文改
  5950. var a = this.thumbnail;
  5951. this.clearView();
  5952. a && (this.fadeThumbnail = a,
  5953. this.fadeThumbnail.style.opacity = 1,
  5954. this.container.appendChild(this.fadeThumbnail));
  5955. if (!fdage.noUserInterface) {
  5956. void 0 === fdage.largeUI && (fdage.largeUI = this.viewer.mobile);
  5957. 450 > this.container.width && (fdage.largeUI = !1);
  5958. var b = FullScreen.support()
  5959. , b = !0
  5960. , a = 1;
  5961. window.devicePixelRatio && (2 < window.devicePixelRatio ? a = 4 : 1 < window.devicePixelRatio && (a = 2));
  5962. fdage.largeUI && 4 > a && (a *= 2);
  5963. var c = fdage.largeUI ? 0.3 : 0.5;
  5964. this.stripText = [];
  5965. for (var d = 0; d < this.stripData.labels.length; ++d) {
  5966. this.stripText[d] = document.createElement("div");
  5967. this.stripText[d].style.position = "absolute";
  5968. this.stripText[d].style.cursor = "pointer";
  5969. this.stripText[d].style.pointerEvents = "none";
  5970. this.container.appendChild(this.stripText[d]);
  5971. var e = document.createElement("div");
  5972. e.style.color = "white";
  5973. e.style.opacity = 0.5;
  5974. e.style.fontFamily = "Arial";
  5975. e.style.textShadow = "2px 2px 3px #000000";
  5976. e.innerHTML = this.stripData.labels[d];
  5977. this.stripText[d].appendChild(e);
  5978. this.stripText[d].txt = e;
  5979. e = document.createElement("div");
  5980. e.style.width = "10000px";
  5981. e.style.height = "2px";
  5982. e.style.backgroundColor = "#AAAAAA";
  5983. e.style.opacity = 1;
  5984. e.style.position = "absolute";
  5985. e.style.left = e.style.top = "-1px";
  5986. this.stripText[d].appendChild(e);
  5987. this.stripText[d].line = e
  5988. }
  5989. this.sigCluster = document.createElement("div");
  5990. this.sigCluster.style.position = "absolute";
  5991. this.sigCluster.style.right = fdage.largeUI ? "12px" : "9px";
  5992. this.sigCluster.style.left = "0px";
  5993. this.sigCluster.style.top = "6px";
  5994. this.sigCluster.style.height = fdage.largeUI ? "64px" : "32px";
  5995. this.logo = document.createElement("div");
  5996. this.logo.style.position = "absolute";
  5997. this.logo.style.right = fdage.largeUI ? "-4px" : "1px";
  5998. this.logo.style.top = fdage.largeUI ? "0px" : "4px";
  5999. this.logo.title = "Made with fdage Toolbag";
  6000. var f = document.createElement("input");
  6001. f.type = "image";
  6002. f.src = 'images/4dageLogo.png'//fdage.dataLocale + "logo" + a + "x.png";
  6003. f.style.border = "none";
  6004. f.style.width = f.style.height = fdage.largeUI ? "72px" : "36px";
  6005. f.style.border = "0px";
  6006. f.style.outline = "0px";
  6007. f.style.opacity = c;
  6008. f.onmouseover = function() {
  6009. this.style.opacity = 1
  6010. }
  6011. .bind(f);
  6012. f.onmouseout = function() {
  6013. this.style.opacity = c
  6014. }
  6015. .bind(f);
  6016. f.onclick = function(a) {
  6017. window.open("http://www.4dage.com", "_blank");
  6018. this.style.opacity = c
  6019. }
  6020. .bind(f, this);
  6021. d = new XMLHttpRequest;
  6022. d.open("HEAD", f.src, !0);
  6023. d.onload = function(a) {
  6024. this.logo.appendChild(a)
  6025. }
  6026. .bind(this, f);
  6027. d.send();
  6028. this.sigCluster.appendChild(this.logo);
  6029. /*d = this.viewer.scene.metaData;
  6030. d.title = UI.sanitize(d.title);
  6031. d.subtitle = UI.sanitize(d.subtitle);
  6032. d.author = UI.sanitize(d.author);
  6033. d.link = UI.sanitizeURL(d.link);
  6034. var g = d.title && 0 < d.title.length
  6035. , e = d.subtitle && 0 < d.subtitle.length
  6036. , f = d.author && 0 < d.author.length
  6037. , h = d.link && 0 < d.link.length;
  6038. if (g || e || f) {
  6039. g || (d.title = "Art");
  6040. var k = !g && !e
  6041. , l = document.createElement("div");
  6042. l.style.position = "absolute";
  6043. l.style.right = fdage.largeUI ? "74px" : "46px";
  6044. l.style.top = "5px";
  6045. l.style.width = "1px";
  6046. l.style.height = fdage.largeUI ? k ? "21px" : "35px" : k ? "18px" : "31px";
  6047. l.style.opacity = 0.25;
  6048. l.style.backgroundColor = "white";
  6049. this.sigCluster.appendChild(l);
  6050. this.sigCluster.line = l;
  6051. k = document.createElement("a");
  6052. h && (k.href = d.link);
  6053. k.style.position = "absolute";
  6054. k.style.right = fdage.largeUI ? "86px" : "58px";
  6055. k.style.top = "6px";
  6056. k.style.textAlign = "right";
  6057. k.style.color = "white";
  6058. k.style.fontFamily = "Arial";
  6059. k.style.fontSize = fdage.largeUI ? "14px" : "12px";
  6060. k.style.textDecoration = "none";
  6061. k.target = "_blank";
  6062. l = document.createElement("font");
  6063. l.style.color = "#FFFFFF";
  6064. l.style.opacity = 0.5;
  6065. l.style.textDecoration = "none";
  6066. l.style.textShadow = "1px 1px 2px rgba(0,0,0,0.7)";
  6067. l.innerHTML = d.title;
  6068. f && (l.innerHTML = g && !e ? l.innerHTML + "<br>by " : l.innerHTML + " by ");
  6069. k.appendChild(l);
  6070. g = document.createElement("font");
  6071. g.style.color = "#FF0044";
  6072. g.style.opacity = 1;
  6073. g.style.textShadow = "1px 1px 2px rgba(0,0,0,0.35)";
  6074. g.innerHTML = d.author;
  6075. k.appendChild(g);
  6076. f = document.createElement("font");
  6077. f.style.color = "#FFFFFF";
  6078. f.style.opacity = 0.5;
  6079. f.style.textShadow = "1px 1px 2px rgba(0,0,0,0.7)";
  6080. e && (f.innerHTML = "<br>",
  6081. f.innerHTML += d.subtitle);
  6082. k.appendChild(f);
  6083. h && (k.onmouseover = function(a, b, c) {
  6084. a.style.opacity = c.style.opacity = 1;
  6085. b.style.textDecoration = "underline"
  6086. }
  6087. .bind(k, l, g, f),
  6088. k.onmouseout = function(a, b, c) {
  6089. a.style.opacity = c.style.opacity = 0.5;
  6090. b.style.textDecoration = "none"
  6091. }
  6092. .bind(k, l, g, f));
  6093. this.sigCluster.appendChild(k);
  6094. this.sigCluster.sceneTitle = k
  6095. }*/
  6096. this.container.appendChild(this.sigCluster);
  6097. this.sigCluster.active = !0;
  6098. this.sigCluster.toggle = function() {
  6099. this.sceneTitle && this.line && (this.active ? (this.removeChild(this.sceneTitle),
  6100. this.removeChild(this.line)) : (this.appendChild(this.sceneTitle),
  6101. this.appendChild(this.line)));
  6102. this.active = !this.active
  6103. }
  6104. .bind(this.sigCluster);
  6105. /* this.helpOverlay = document.createElement("div");
  6106. this.helpOverlay.style.pointerEvents = "none";
  6107. this.container.appendChild(this.helpOverlay);
  6108. this.hideSigOnHelp = d = 450 > this.container.width;
  6109. this.hideSigOnStrips = !0;
  6110. g = [8, 8];
  6111. d ? (e = 198 + 2 * g[0],
  6112. f = 258 + 2 * g[1]) : (e = 354 + 2 * g[0],
  6113. f = 218 + 2 * g[1]);
  6114. h = document.createElement("div");
  6115. h.style.position = "absolute";
  6116. h.style.width = h.style.height = "100%";
  6117. this.helpOverlay.contents = h;
  6118. h = document.createElement("div");
  6119. h.style.position = "absolute";
  6120. h.style.right = fdage.largeUI ? "92px" : "54px";
  6121. h.style.top = d ? "16px" : "48px";
  6122. h.style.width = e + "px";
  6123. h.style.height = f + "px";
  6124. this.helpOverlay.contents.appendChild(h);
  6125. f = document.createElement("div");
  6126. f.style.position = "absolute";
  6127. f.style.width = "100%";
  6128. f.style.height = "100%";
  6129. f.style.backgroundColor = "black";
  6130. f.style.opacity = "0.65";
  6131. f.style.borderRadius = "16px";
  6132. h.appendChild(f);
  6133. f = document.createElement("input");
  6134. f.type = "button";
  6135. f.value = "x";
  6136. f.style.position = "absolute";
  6137. f.style.color = "#FFFFFF";
  6138. f.style.fontWeight = "bolder";
  6139. f.style.backgroundColor = "rgba(0,0,0,0.0)";
  6140. f.style.border = "0px";
  6141. f.style.outline = "0px";
  6142. f.style.fontSize = fdage.largeUI ? "16pt" : "10pt";
  6143. f.style.right = fdage.largeUI ? "2px" : "8px";
  6144. f.style.top = fdage.largeUI ? "0px" : "4px";
  6145. f.style.width = f.style.height = fdage.largeUI ? "32px" : "16px";
  6146. f.style.pointerEvents = "auto";
  6147. f.style.cursor = "pointer";
  6148. f.onclick = function(a) {
  6149. this.helpOverlay.toggle();
  6150. this.refreshUI()
  6151. }
  6152. .bind(this, f);
  6153. h.appendChild(f);
  6154. f = document.createElement("center");
  6155. f.style.position = "absolute";
  6156. f.style.left = g[0] - 4 + "px";
  6157. f.style.right = g[0] + 4 + "px";
  6158. f.style.top = f.style.bottom = g[1] + "px";
  6159. f.style.paddingTop = "8px";
  6160. d || (f.style.paddingRight = "8px");
  6161. h.appendChild(f);
  6162. h = f;
  6163. g = (this.viewer.mobile ? "M" : "PC") + (2 < a ? 4 : 2) + "x.png";
  6164. f = document.createElement("img");
  6165. f.src = fdage.dataLocale + "helprotate" + g;
  6166. f.style.width = "66px";
  6167. f.style.height = "90px";
  6168. h.appendChild(f);
  6169. f = document.createElement("img");
  6170. f.src = fdage.dataLocale + "helpzoom" + g;
  6171. f.style.width = "66px";
  6172. f.style.height = "90px";
  6173. h.appendChild(f);
  6174. f = document.createElement("img");
  6175. f.src = fdage.dataLocale + "helpmove" + g;
  6176. f.style.width = "66px";
  6177. f.style.height = "90px";
  6178. h.appendChild(f);
  6179. f = document.createElement("img");
  6180. f.src = fdage.dataLocale + "helpreset" + g;
  6181. f.style.width = "66px";
  6182. f.style.height = "90px";
  6183. h.appendChild(f);
  6184. f = document.createElement("img");
  6185. f.src = fdage.dataLocale + "helplights" + g;
  6186. f.style.position = "relative";
  6187. d || (f.style.left = "8px");
  6188. f.style.width = "66px";
  6189. f.style.height = "90px";
  6190. h.appendChild(f);
  6191. g = document.createElement("a");
  6192. g.href = "http://www.fdage.co/viewer?utm_source=inapp&utm_medium=menu&utm_campaign=viewer";
  6193. g.target = "_blank";
  6194. g.style.pointerEvents = "auto";
  6195. h.appendChild(g);
  6196. k = document.createElement("img");
  6197. k.src = fdage.dataLocale + "helpshadow.png";
  6198. k.style.position = "absolute";
  6199. k.style.left = 0.5 * e - (d ? 65 : 116) + "px";
  6200. k.style.bottom = d ? "6px" : "8px";
  6201. k.style.width = d ? "116px" : "232px";
  6202. k.style.opacity = 0;
  6203. g.appendChild(k);
  6204. k.targetOpacity = 0;
  6205. g.onmouseover = function() {
  6206. this.targetOpacity = 0.65
  6207. }
  6208. .bind(k);
  6209. g.onmouseout = function() {
  6210. this.targetOpacity = 0
  6211. }
  6212. .bind(k);
  6213. window.setInterval(function() {
  6214. this.style.opacity = 0.1 * this.targetOpacity + 0.9 * this.style.opacity
  6215. }
  6216. .bind(k), 20);
  6217. f = document.createElement("img");
  6218. f.src = fdage.dataLocale + "helptitle.png";
  6219. f.style.position = "absolute";
  6220. f.style.left = 0.5 * e - (d ? 65 : 116) + "px";
  6221. f.style.bottom = d ? "8px" : "12px";
  6222. f.style.width = d ? "116px" : "232px";
  6223. g.appendChild(f);
  6224. e = document.createElement("div");
  6225. e.style.position = "absolute";
  6226. e.style.left = 0;
  6227. e.style.right = d ? "30px" : "108px";
  6228. e.style.bottom = d ? "-4px" : "4px";
  6229. e.style.textAlign = "right";
  6230. e.style.fontFamilly = "Arial";
  6231. h.appendChild(e);
  6232. d = document.createElement("font");
  6233. d.style.fontSize = "9pt";
  6234. d.style.fontFamily = "Arial";
  6235. e.appendChild(d);
  6236. g = document.createElement("a");
  6237. g.style.color = "#FF0044";
  6238. g.style.textDecoration = "none";
  6239. g.style.pointerEvents = "auto";
  6240. g.innerHTML = "www.fdage.co/viewer";
  6241. g.href = "http://www.fdage.co/viewer?utm_source=inapp&utm_medium=menu&utm_campaign=viewer";
  6242. g.target = "_blank";
  6243. g.onmouseover = function(a) {
  6244. this.style.textDecoration = "underline";
  6245. a.targetOpacity = 0.65
  6246. }
  6247. .bind(g, k);
  6248. g.onmouseout = function(a) {
  6249. this.style.textDecoration = "none";
  6250. a.targetOpacity = 0
  6251. }
  6252. .bind(g, k);
  6253. d.appendChild(g);
  6254. this.helpOverlay.active = !1;
  6255. this.helpOverlay.toggle = function(a) {
  6256. this.active ? this.removeChild(this.contents) : this.appendChild(this.contents);
  6257. this.active = !this.active
  6258. }
  6259. .bind(this.helpOverlay, this.viewer); */
  6260. this.menuCluster = document.createElement("div");
  6261. this.menuCluster.style.position = "absolute";
  6262. this.menuCluster.style.right = fdage.largeUI ? "4px" : "8px";
  6263. this.menuCluster.style.top = fdage.largeUI ? "70px" : "40px";
  6264. fdage.largeUI ? (this.menuCluster.style.width = "72px",
  6265. this.menuCluster.style.height = "64px") : (this.menuCluster.style.width = "36px",
  6266. this.menuCluster.style.height = "36px");
  6267. var h = document.createElement("div");
  6268. h.style.left = h.style.top = "0px";
  6269. h.style.width = h.style.height = "100%";
  6270. this.menuCluster.contents = h;
  6271. this.menuCluster.appendChild(h);
  6272. d = 0;
  6273. e = function(a, b, c, d, e) {
  6274. var f = document.createElement("input");
  6275. f.type = "image";
  6276. f.src = fdage.dataLocale + c;
  6277. f.style.position = "absolute";
  6278. f.style.left = "0px";
  6279. f.style.bottom = -100 * d + "%";
  6280. f.style.border = "none";
  6281. f.style.outline = "0px";
  6282. f.title = b;
  6283. f.style.opacity = e;
  6284. fdage.largeUI ? (f.style.width = "64px",
  6285. f.style.height = "48px") : (f.style.width = "32px",
  6286. f.style.height = "24px");
  6287. f.onmouseover = function(a) {
  6288. this.style.opacity = a
  6289. }
  6290. .bind(f, 1);
  6291. f.onmouseout = function(a) {
  6292. this.style.opacity = a
  6293. }
  6294. .bind(f, e);
  6295. f.onmouseup = function(a) {
  6296. this.style.opacity = a
  6297. }
  6298. .bind(f, e);
  6299. b = new XMLHttpRequest;
  6300. b.open("HEAD", f.src, !0);
  6301. b.onload = function(a) {
  6302. a.appendChild(this)
  6303. }
  6304. .bind(f, a);
  6305. b.send();
  6306. return f
  6307. }
  6308. ;
  6309. /* b && (b = e(this.menuCluster.contents, "Full Screen", "fullscreen" + a + "x.png", d++, c),
  6310. b.onclick = function(a) {
  6311. FullScreen.active() ? FullScreen.end() : FullScreen.begin(this.viewer.domRoot, this.viewer.fullscreenChange.bind(this.viewer));
  6312. a.style.opacity = c;
  6313. this.refreshUI()
  6314. }
  6315. .bind(this, b));
  6316. b = e(this.menuCluster.contents, "Layer Views", "strips" + a + "x.png", d++, c);
  6317. b.onclick = function(a) {
  6318. this.stripData.toggleMenu();
  6319. this.helpOverlay.active && this.helpOverlay.toggle();
  6320. this.viewer.wake();
  6321. this.refreshUI()
  6322. }
  6323. .bind(this, b);
  6324. b = e(this.menuCluster.contents, "Help", "help" + a + "x.png", d++, c);
  6325. b.onclick = function(a) {
  6326. this.stripData.selectedStrip == this.stripData.STRIP_MENU && this.stripData.toggleMenu();
  6327. this.helpOverlay.toggle();
  6328. this.refreshUI()
  6329. }
  6330. .bind(this, b); */
  6331. this.guiScreen && this.guiScreen.setupActiveView(this);
  6332. this.container.appendChild(this.menuCluster);
  6333. this.menuCluster.active = !0;
  6334. this.menuCluster.toggle = function() {
  6335. this.active ? this.removeChild(this.contents) : this.appendChild(this.contents);
  6336. this.active = !this.active
  6337. }
  6338. .bind(this.menuCluster);
  6339. /* void 0 !== fdage.hostImage && (fdage.hostURL && (g = document.createElement("a"),
  6340. g.href = fdage.hostURL,
  6341. g.target = "_blank"),
  6342. f = document.createElement("img"),
  6343. f.src = fdage.hostImage,
  6344. f.style.position = "absolute",
  6345. f.style.top = "4px",
  6346. f.style.left = "4px",
  6347. f.style.opacity = 0.65,
  6348. f.style["-webkit-transform"] = f.style.transform = "translate(-50%,-50%) scale(0.5,0.5) translate(50%,50%)",
  6349. fdage.hostURL ? (f.onmouseover = function() {
  6350. this.style.opacity = 1
  6351. }
  6352. .bind(f),
  6353. f.onmouseout = function() {
  6354. this.style.opacity = 0.5
  6355. }
  6356. .bind(f),
  6357. g.appendChild(f),
  6358. this.hostLogo = g) : this.hostLogo = f,
  6359. d = new XMLHttpRequest,
  6360. d.open("HEAD", f.src, !0),
  6361. d.onload = function() {
  6362. this.container.appendChild(this.hostLogo)
  6363. }
  6364. .bind(this),
  6365. d.send()); */
  6366. this.sceneStats = document.createElement("text");
  6367. this.sceneStats.style.position = "absolute";
  6368. this.sceneStats.style.left = "9px";
  6369. this.sceneStats.style.bottom = "8px";
  6370. this.sceneStats.style.color = "gray";
  6371. this.sceneStats.style.fontFamily = "Arial";
  6372. this.sceneStats.style.fontSize = "75%";
  6373. for (d = b = a = 0; d < this.viewer.scene.meshes.length; ++d)
  6374. e = this.viewer.scene.meshes[d],
  6375. a += e.indexCount / 3,
  6376. b += e.vertexCount;
  6377. this.sceneStats.innerHTML = "Triangles: " + (a | 0).toLocaleString() + "<br>Vertices: " + (b | 0).toLocaleString();
  6378. fdage.showFrameTime && (this.frameTimer = document.createElement("text"),
  6379. this.frameTimer.style.position = "absolute",
  6380. this.frameTimer.style.left = this.frameTimer.style.top = "5px",
  6381. this.frameTimer.style.color = "gray",
  6382. this.frameTimer.style.fontSize = "75%",
  6383. this.container.appendChild(this.frameTimer),
  6384. this.frameTimer.innerHTML = "--",
  6385. this.frameCount = 1E20);
  6386. this.animateStrips()
  6387. }
  6388. }
  6389. ;
  6390. UI.prototype.refreshUI = function() {
  6391. if (this.sigCluster) {
  6392. var a = !1
  6393. , b = this.stripData.selectedStrip == this.stripData.STRIP_MENU;
  6394. this.hideSigOnStrips && (a = a || b);
  6395. this.hideSigOnHelp && (a = a || this.helpOverlay.active);
  6396. this.sigCluster.active == a && this.sigCluster.toggle()
  6397. }
  6398. }
  6399. ;
  6400. UI.prototype.signalLoadProgress = function(a, b) {
  6401. if (this.thumbnail) {
  6402. if (!this.progressBar) {
  6403. var c = document.createElement("div");
  6404. c.style.backgroundColor = "rgb(30,30,30)";
  6405. c.style.opacity = 0.5;
  6406. c.style.position = "absolute";
  6407. c.style.left = "20%";
  6408. c.style.width = "60%";
  6409. c.style.bottom = "30%";
  6410. c.style.height = "2px";
  6411. this.progressBar = document.createElement("div");
  6412. this.progressBar.style.backgroundColor = "white";
  6413. this.progressBar.style.position = "absolute";
  6414. this.progressBar.style.left = this.progressBar.style.bottom = "0px";
  6415. this.progressBar.style.height = "100%";
  6416. this.progressBar.style.width = "0px";
  6417. c.appendChild(this.progressBar);
  6418. this.container.appendChild(c);
  6419. //this.playButton && (this.container.removeChild(this.playButton), //xst
  6420. //delete this.playButton) //xst
  6421. }
  6422. this.progressBar.style.width = 0 >= b ? (100 * a / (2097152 + a) | 0) + "%" : (100 * a / b | 0) + "%"
  6423. }
  6424. }
  6425. ;
  6426. UI.prototype.animating = function() {
  6427. return !!this.fadeThumbnail || !!this.frameTimer
  6428. }
  6429. ;
  6430. UI.prototype.animate = function() {
  6431. this.fadeThumbnail && (this.fadeThumbnailTimer = this.fadeThumbnailTimer || Date.now(),
  6432. this.fadeThumbnail.style.opacity = 1 - 0.0015 * (Date.now() - this.fadeThumbnailTimer),
  6433. 0.01 > this.fadeThumbnail.style.opacity && (this.container.removeChild(this.fadeThumbnail),
  6434. delete this.fadeThumbnail,
  6435. delete this.fadeThumbnailTimer));
  6436. if (this.frameTimer && (this.frameCount++,
  6437. 60 <= this.frameCount)) {
  6438. var a = (new Date).getTime();
  6439. if (void 0 !== this.frameTime) {
  6440. var b = (a - this.frameTime) / this.frameCount
  6441. , b = Math.floor(100 * b) / 100;
  6442. this.frameTimer.innerHTML = b + " ms";
  6443. this.frameTimer.style.color = 32 > b ? "green" : "red"
  6444. }
  6445. this.frameCount = 0;
  6446. this.frameTime = a
  6447. }
  6448. this.guiScreen && this.guiScreen.playbackControls && (a = this.guiScreen.playbackControls.timelineSlider,
  6449. a.draggingSlider ? this.viewer.scene.sceneAnimator.setAnimationProgress(a.sliderPercent, !0) : a.setSliderPercent(this.viewer.scene.sceneAnimator.animationProgress));
  6450. if (this.sceneStats) {
  6451. for (var c = b = a = 0; c < this.viewer.scene.meshes.length; ++c)
  6452. var d = this.viewer.scene.meshes[c]
  6453. , a = a + d.indexCount / 3
  6454. , b = b + d.vertexCount;
  6455. this.sceneStats.innerHTML = "Triangles: " + (a | 0).toLocaleString() + "<br>Vertices: " + (b | 0).toLocaleString();
  6456. this.viewer.scene.sceneAnimator && this.viewer.scene.sceneAnimator.showPlayControls && (this.sceneStats.innerHTML += "<br><br><br><br>");
  6457. a = !!this.sceneStats.parentElement;
  6458. b = this.stripData.active() || !1;
  6459. a && !b ? (this.container.removeChild(this.sceneStats),
  6460. this.hostLogo && this.container.appendChild(this.hostLogo)) : !a && b && (this.container.appendChild(this.sceneStats),
  6461. this.hostLogo && this.container.removeChild(this.hostLogo))
  6462. }
  6463. this.refreshUI();
  6464. if (this.stripData.animationActive || this.stripData.active())
  6465. this.animateStrips(),
  6466. this.stripData.animationActive && this.viewer.wake()
  6467. }
  6468. ;
  6469. UI.prototype.animateStrips = function() {
  6470. if (this.stripText)
  6471. for (var a = Math.atan(this.viewer.canvas.height / this.viewer.canvas.width / this.stripData.stripSlant), b = 0; b < this.stripData.labels.length; ++b) {
  6472. var c = this.stripData.strips[b]
  6473. , c = c - this.stripData.stripSlant
  6474. , c = 0.5 + 0.5 * c;
  6475. b == this.stripData.selectedStrip ? (this.stripText[b].style["-ms-transform"] = this.stripText[b].style["-webkit-transform"] = this.stripText[b].style.transform = "none",
  6476. this.stripText[b].style.top = "4px",
  6477. this.stripText[b].style.left = "0px",
  6478. this.stripText[b].style.width = "150px",
  6479. this.stripText[b].txt.style.textAlign = "center",
  6480. this.stripText[b].txt.style.background = "rgba(0, 0, 0, 0.75)",
  6481. this.stripText[b].txt.style.background = "-webkit-linear-gradient(left, rgba(0,0,0,0.75), rgba(0,0,0,0))",
  6482. this.stripText[b].txt.style.background = "-o-linear-gradient(left, rgba(0,0,0,0.75), rgba(0,0,0,0))",
  6483. this.stripText[b].txt.style.background = "-moz-linear-gradient(left, rgba(0,0,0,0.75), rgba(0,0,0,0))",
  6484. this.stripText[b].txt.style.background = "linear-gradient(left, rgba(0,0,0,0.75), rgba(0,0,0,0))",
  6485. this.stripText[b].txt.style.paddingLeft = "32px",
  6486. this.stripText[b].txt.style.paddingTop = "6px",
  6487. this.stripText[b].txt.style.paddingBottom = "4px",
  6488. this.stripText[b].txt.style.textShadow = "1px 1px 2px rgba(0,0,0,0.7)",
  6489. this.stripText[b].line.style.opacity = 0.5,
  6490. this.stripText[b].line.style.top = "100%",
  6491. this.stripText[b].line.style.width = "100%",
  6492. this.stripText[b].line.style.height = "1px") : (this.stripText[b].style["-ms-transform"] = this.stripText[b].style["-webkit-transform"] = this.stripText[b].style.transform = "translate(-50%, -50%) rotate(" + a + "rad) translate(50%, 50%)",
  6493. this.stripText[b].style.left = 100 * c + "%",
  6494. this.stripText[b].style.top = "0px",
  6495. this.stripText[b].style.width = "85px",
  6496. this.stripText[b].txt.style.textAlign = "left",
  6497. this.stripText[b].txt.style.background = "none",
  6498. this.stripText[b].txt.style.paddingLeft = "8px",
  6499. this.stripText[b].txt.style.paddingTop = "6px",
  6500. this.stripText[b].txt.style.paddingBottom = "4px",
  6501. this.stripText[b].txt.style.textShadow = "2px 0px 3px rgba(0,0,0,0.7)",
  6502. this.stripText[b].line.style.opacity = 1,
  6503. this.stripText[b].line.style.top = "-1px",
  6504. this.stripText[b].line.style.width = "10000px",
  6505. this.stripText[b].line.style.height = "2px")
  6506. }
  6507. }
  6508. ;
  6509. var Vect = {
  6510. type: Float32Array,
  6511. create: function(a, b, c, d) {
  6512. var e = new Vect.type(4);
  6513. e[0] = a;
  6514. e[1] = b;
  6515. e[2] = c;
  6516. e[3] = d;
  6517. return e
  6518. },
  6519. empty: function() {
  6520. return new Vect.type(4)
  6521. },
  6522. set: function(a, b, c, d, e) {
  6523. a[0] = b;
  6524. a[1] = c;
  6525. a[2] = d;
  6526. a[3] = e
  6527. },
  6528. copy: function(a, b) {
  6529. a[0] = b[0];
  6530. a[1] = b[1];
  6531. a[2] = b[2];
  6532. a[3] = b[3]
  6533. },
  6534. add: function(a, b, c) {
  6535. a[0] = b[0] + c[0];
  6536. a[1] = b[1] + c[1];
  6537. a[2] = b[2] + c[2];
  6538. a[3] = b[3] + c[3];
  6539. return a
  6540. },
  6541. sub: function(a, b, c) {
  6542. a[0] = b[0] - c[0];
  6543. a[1] = b[1] - c[1];
  6544. a[2] = b[2] - c[2];
  6545. a[3] = b[3] - c[3];
  6546. return a
  6547. },
  6548. scale: function(a, b, c) {
  6549. a[0] = c[0] * b;
  6550. a[1] = c[1] * b;
  6551. a[2] = c[2] * b;
  6552. a[3] = c[3] * b;
  6553. return a
  6554. },
  6555. mul: function(a, b, c) {
  6556. a[0] = b[0] * c[0];
  6557. a[1] = b[1] * c[1];
  6558. a[2] = b[2] * c[2];
  6559. a[3] = b[3] * c[3];
  6560. return a
  6561. },
  6562. mad: function(a, b, c, d) {
  6563. a[0] = b[0] * c[0] + d[0];
  6564. a[1] = b[1] * c[1] + d[1];
  6565. a[2] = b[2] * c[2] + d[2];
  6566. a[3] = b[3] * c[3] + d[3];
  6567. return a
  6568. },
  6569. smad: function(a, b, c, d) {
  6570. a[0] = b * c[0] + d[0];
  6571. a[1] = b * c[1] + d[1];
  6572. a[2] = b * c[2] + d[2];
  6573. a[3] = b * c[3] + d[3];
  6574. return a
  6575. },
  6576. negate: function(a, b) {
  6577. a[0] = -b[0];
  6578. a[1] = -b[1];
  6579. a[2] = -b[2];
  6580. return a
  6581. },
  6582. negate4: function(a, b) {
  6583. a[0] = -b[0];
  6584. a[1] = -b[1];
  6585. a[2] = -b[2];
  6586. a[3] = -b[3];
  6587. return a
  6588. },
  6589. length: function(a) {
  6590. var b = a[0]
  6591. , c = a[1];
  6592. a = a[2];
  6593. return Math.sqrt(b * b + c * c + a * a)
  6594. },
  6595. distance: function(a, b) {
  6596. var c = a[0] - b[0]
  6597. , d = a[1] - b[1]
  6598. , e = a[2] - b[2];
  6599. return Math.sqrt(c * c + d * d + e * e)
  6600. },
  6601. dot: function(a, b) {
  6602. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]
  6603. },
  6604. dot4: function(a, b) {
  6605. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]
  6606. },
  6607. normalize: function(a, b) {
  6608. var c = b[0]
  6609. , d = b[1]
  6610. , e = b[2]
  6611. , f = Math.sqrt(c * c + d * d + e * e);
  6612. if (0 == f)
  6613. return Vect.set(a, 0, 0, 0, 0);
  6614. f = 1 / f;
  6615. a[0] = c * f;
  6616. a[1] = d * f;
  6617. a[2] = e * f;
  6618. return a
  6619. },
  6620. cross: function(a, b, c) {
  6621. a[0] = b[1] * c[2];
  6622. a[0] += -b[2] * c[1];
  6623. a[1] = b[2] * c[0] - b[0] * c[2];
  6624. a[2] = b[0] * c[1] - b[1] * c[0];
  6625. return a
  6626. },
  6627. lerp: function(a, b, c, d) {
  6628. var e = 1 - d;
  6629. a[0] = b[0] * e + c[0] * d;
  6630. a[1] = b[1] * e + c[1] * d;
  6631. a[2] = b[2] * e + c[2] * d;
  6632. return a
  6633. },
  6634. lerp4: function(a, b, c, d) {
  6635. var e = 1 - d;
  6636. a[0] = b[0] * e + c[0] * d;
  6637. a[1] = b[1] * e + c[1] * d;
  6638. a[2] = b[2] * e + c[2] * d;
  6639. a[3] = b[3] * e + c[3] * d;
  6640. return a
  6641. },
  6642. min: function(a, b, c) {
  6643. a[0] = Math.min(b[0], c[0]);
  6644. a[1] = Math.min(b[1], c[1]);
  6645. a[2] = Math.min(b[2], c[2]);
  6646. a[3] = Math.min(b[3], c[3]);
  6647. return a
  6648. },
  6649. max: function(a, b, c) {
  6650. a[0] = Math.max(b[0], c[0]);
  6651. a[1] = Math.max(b[1], c[1]);
  6652. a[2] = Math.max(b[2], c[2]);
  6653. a[3] = Math.max(b[3], c[3]);
  6654. return a
  6655. },
  6656. projectOnPlane: function(a, b, c, d) {
  6657. var e = Vect.empty();
  6658. Vect.sub(e, b, c);
  6659. c = Vect.dot(e, d);
  6660. smad(a, -c, normal, b);
  6661. return a
  6662. }
  6663. };
  6664. function View(a) {
  6665. this.pivot = [0, 0, 0];
  6666. this.rotation = [0, 0];
  6667. this.radius = 1;
  6668. this.nearPlane = 0.3;
  6669. this.fov = 45;
  6670. this.size = [1, 1];
  6671. this.transform = Matrix.empty();
  6672. this.viewMatrix = Matrix.empty();
  6673. this.projectionMatrix = Matrix.empty();
  6674. this.viewProjectionMatrix = Matrix.empty();
  6675. a ? this.loadView(a, !0) : (this.saveResetView(),
  6676. this.updateView(),
  6677. this.updateProjection())
  6678. }
  6679. View.prototype.saveResetView = function() {
  6680. this.resetDesc = {
  6681. angles: [this.rotation[0], this.rotation[1]],
  6682. pivot: [this.pivot[0], this.pivot[1], this.pivot[2]],
  6683. limits: this.limits,
  6684. orbitRadius: this.radius,
  6685. fov: this.fov
  6686. }
  6687. }
  6688. ;
  6689. View.prototype.loadView = function(a, b) {
  6690. a && (this.rotation[0] = a.angles[0],
  6691. this.rotation[1] = a.angles[1],
  6692. this.pivot[0] = a.pivot[0],
  6693. this.pivot[1] = a.pivot[1],
  6694. this.pivot[2] = a.pivot[2],
  6695. this.radius = a.orbitRadius,
  6696. this.fov = a.fov,
  6697. this.limits = a.limits,
  6698. b && this.saveResetView(),
  6699. this.updateView(),
  6700. this.updateProjection())
  6701. }
  6702. ;
  6703. View.prototype.reset = function() {
  6704. this.loadView(this.resetDesc)
  6705. }
  6706. ;
  6707. View.prototype.updateView = function() {
  6708. if (void 0 !== this.limits) {
  6709. if (this.limits.angles) {
  6710. var a = this.limits.angles.x
  6711. , b = this.limits.angles.y;
  6712. if (void 0 !== a) {
  6713. var c = this.rotation[0] - a.offset
  6714. , a = Math.min(Math.max(c, a.min), a.max);
  6715. this.rotation[0] += a - c
  6716. }
  6717. void 0 !== b && (c = this.rotation[1] - b.offset,
  6718. a = Math.min(Math.max(c, b.min), b.max),
  6719. this.rotation[1] += a - c)
  6720. }
  6721. void 0 !== this.limits.orbitRadius && (b = this.limits.orbitRadius.min,
  6722. c = this.limits.orbitRadius.max,
  6723. void 0 !== b && (this.radius = Math.max(this.radius, b)),
  6724. void 0 !== c && (this.radius = Math.min(this.radius, c)));
  6725. void 0 !== this.limits.pan && (b = this.limits.pan,
  6726. c = this.resetDesc.pivot,
  6727. b.x && (this.pivot[0] = c[0]),
  6728. b.y && (this.pivot[1] = c[1]),
  6729. b.z && (this.pivot[2] = c[2]))
  6730. }
  6731. Matrix.translation(this.transform, 0, 0, this.radius);
  6732. b = Matrix.rotation(Matrix.empty(), this.rotation[0], 0);
  6733. c = Matrix.rotation(Matrix.empty(), this.rotation[1], 1);
  6734. Matrix.mul(b, c, b);
  6735. Matrix.mul(this.transform, b, this.transform);
  6736. this.transform[12] += this.pivot[0];
  6737. this.transform[13] += this.pivot[1];
  6738. this.transform[14] += this.pivot[2];
  6739. Matrix.invert(this.viewMatrix, this.transform);
  6740. Matrix.mul(this.viewProjectionMatrix, this.viewMatrix, this.projectionMatrix)
  6741. }
  6742. ;
  6743. View.prototype.updateProjection = function(a) {
  6744. Matrix.perspectiveInfinite(this.projectionMatrix, this.fov, this.size[0] / this.size[1], this.nearPlane, a);
  6745. Matrix.mul(this.viewProjectionMatrix, this.projectionMatrix, this.viewMatrix)
  6746. }
  6747. ;
  6748. function WebViewer(a, b, c, d, domRoot) {
  6749. this.mobile = !!/Android|iPhone|iPod|iPad|Windows Phone|IEMobile|BlackBerry|webOS/.test(navigator.userAgent);
  6750. this.mobileFast = !!/iPhone|iPad/.test(navigator.userAgent);
  6751. var e;
  6752. if (e = !this.mobile)
  6753. a: {
  6754. e = document.createElement("canvas");
  6755. e.width = e.height = 16;
  6756. if (e = e.getContext("webgl", {}) || e.getContext("experimental-webgl", {})) {
  6757. var f = e.getExtension("WEBGL_debug_renderer_info");
  6758. if (f) {
  6759. e = e.getParameter(f.UNMASKED_RENDERER_WEBGL);
  6760. e = !!/Intel|INTEL/.test(e);
  6761. break a
  6762. }
  6763. }
  6764. e = !1
  6765. }
  6766. this.desktopSlow = e;
  6767. //this.domRoot = document.createElement("div");
  6768. this.domRoot = domRoot;
  6769. this.domRoot.style.width = a + "px";
  6770. this.domRoot.style.height = b + "px";
  6771. this.initCanvas(a, b);
  6772. this.scene = this.input = null;
  6773. this.sceneURL = c;
  6774. this.sleepCounter = 8;
  6775. this.onLoad = null;
  6776. this.stripData = new StripData;
  6777. this.ui = new UI(this);
  6778. this.ui.setSize(a, b);
  6779. this.ui.showPreview(d)
  6780. }
  6781. WebViewer.prototype.initCanvas = function(a, b) {
  6782. this.canvas && this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
  6783. this.canvas = document.createElement("canvas");
  6784. this.pixelRatio = window.devicePixelRatio || 1;
  6785. if (this.mobile) {
  6786. var c = this.mobileFast ? 1.5 : 1;
  6787. this.pixelRatio = this.pixelRatio > c ? c : this.pixelRatio
  6788. } else
  6789. this.desktopSlow && (this.pixelRatio = 1);
  6790. this.canvas.width = a * this.pixelRatio;
  6791. this.canvas.height = b * this.pixelRatio;
  6792. this.canvas.style.width = a + "px";
  6793. this.canvas.style.height = b + "px";
  6794. this.canvas.style.position = "absolute";
  6795. this.canvas.style.left = '0';
  6796. this.domRoot.appendChild(this.canvas)
  6797. }
  6798. ;
  6799. WebViewer.prototype.initGL = function() {
  6800. var a = {
  6801. alpha: !!fdage.transparentBackground,
  6802. depth: !1,
  6803. stencil: !1,
  6804. antialias: !1,
  6805. premultipliedAlpha: !!fdage.transparentBackground,
  6806. preserveDrawingBuffer: !1
  6807. }
  6808. , a = this.gl = this.canvas.getContext("webgl", a) || this.canvas.getContext("experimental-webgl", a);
  6809. if (!this.gl)//许钟文改
  6810. return this.ui.showFailure('webgl出错。</br>建议您将浏览器升级至最新版本,以获最好的体验。<br><span style="font-size:0.8em">获知更多webgl浏览器信息请<a href="webglInfo.html" style="color: #a6ccea;">点击此处</a></span>',this),
  6811. !1;
  6812. this.canvas.addEventListener("webglcontextlost", function(a) {
  6813. a.preventDefault()
  6814. }
  6815. .bind(this), !1);
  6816. this.canvas.addEventListener("webglcontextrestored", function(a) {
  6817. this.loadScene(this.sceneURL)
  6818. }
  6819. .bind(this), !1);
  6820. a.ext = {
  6821. textureAniso: a.getExtension("EXT_texture_filter_anisotropic") || a.getExtension("WEBKIT_EXT_texture_filter_anisotropic") || a.getExtension("MOZ_EXT_texture_filter_anisotropic"),
  6822. textureFloat: a.getExtension("OES_texture_float"),
  6823. textureFloatLinear: a.getExtension("OES_texture_float_linear"),
  6824. textureHalf: a.getExtension("OES_texture_half_float"),
  6825. textureHalfLinear: a.getExtension("OES_texture_half_float_linear"),
  6826. textureDepth: a.getExtension("WEBGL_depth_texture"),
  6827. colorBufferFloat: a.getExtension("WEBGL_color_buffer_float"),
  6828. colorBufferHalf: a.getExtension("EXT_color_buffer_half_float"),
  6829. index32bit: a.getExtension("OES_element_index_uint"),
  6830. loseContext: a.getExtension("WEBGL_lose_context"),
  6831. derivatives: a.getExtension("OES_standard_derivatives"),
  6832. renderInfo: a.getExtension("WEBGL_debug_renderer_info")
  6833. };
  6834. a.limits = {
  6835. textureSize: a.getParameter(a.MAX_TEXTURE_SIZE),
  6836. textureCount: a.getParameter(a.MAX_TEXTURE_IMAGE_UNITS),
  6837. varyings: a.getParameter(a.MAX_VARYING_VECTORS),
  6838. vertexAttribs: a.getParameter(a.MAX_VERTEX_ATTRIBS),
  6839. vertexUniforms: a.getParameter(a.MAX_VERTEX_UNIFORM_VECTORS),
  6840. fragmentUniforms: a.getParameter(a.MAX_FRAGMENT_UNIFORM_VECTORS),
  6841. viewportSizes: a.getParameter(a.MAX_VIEWPORT_DIMS),
  6842. vendor: a.getParameter(a.VENDOR),
  6843. version: a.getParameter(a.VERSION)
  6844. };
  6845. a.hints = {
  6846. mobile: this.mobile,
  6847. pixelRatio: this.pixelRatio
  6848. };
  6849. a.enable(a.DEPTH_TEST);
  6850. a.shaderCache = new ShaderCache(a);
  6851. a.textureCache = new TextureCache(a);
  6852. this.allocBacking();
  6853. return !0
  6854. }
  6855. ;
  6856. WebViewer.prototype.allocBacking = function() {
  6857. var a = this.gl
  6858. , b = !1
  6859. , c = {
  6860. width: this.canvas.width,
  6861. height: this.canvas.height
  6862. };
  6863. this.mainColor = new Texture(a,c);
  6864. this.mainDepth = null;
  6865. a.ext.textureDepth && (this.mainDepth = new Texture(a,{
  6866. width: this.canvas.width,
  6867. height: this.canvas.height,
  6868. nofilter: !0
  6869. }),
  6870. this.mainDepth.loadArray(null, a.DEPTH_COMPONENT, a.UNSIGNED_INT));
  6871. a.ext.textureHalf && a.ext.textureHalfLinear && (this.mainColor.loadArray(null, a.RGBA, a.ext.textureHalf.HALF_FLOAT_OES),
  6872. this.mainBuffer = new Framebuffer(a,{
  6873. color0: this.mainColor,
  6874. depth: this.mainDepth,
  6875. createDepth: !this.mainDepth
  6876. }),
  6877. b = this.mainBuffer.valid);
  6878. !b && a.ext.textureFloat && a.ext.textureFloatLinear && !a.hints.mobile && (this.mainColor.loadArray(null, a.RGBA, a.FLOAT),
  6879. this.mainBuffer = new Framebuffer(a,{
  6880. color0: this.mainColor,
  6881. depth: this.mainDepth,
  6882. createDepth: !this.mainDepth
  6883. }),
  6884. b = this.mainBuffer.valid);
  6885. for (; !b; )
  6886. this.mainColor = new Texture(a,c),
  6887. this.mainColor.loadArray(null, a.RGBA, a.UNSIGNED_BYTE),
  6888. this.mainBuffer = new Framebuffer(a,{
  6889. color0: this.mainColor,
  6890. depth: this.mainDepth,
  6891. createDepth: !this.mainDepth
  6892. }),
  6893. b = this.mainBuffer.valid,
  6894. c.width /= 2,
  6895. c.height /= 2,
  6896. this.mainDepth && (this.mainDepth.destroy(),
  6897. this.mainDepth = null);
  6898. this.mainBufferNoDepth = new Framebuffer(a,{
  6899. color0: this.mainColor
  6900. })
  6901. }
  6902. ;
  6903. WebViewer.prototype.loadScene = function(a) {//许钟文改
  6904. this.sceneURL = a || this.sceneURL;
  6905. this.scene = this.input = null;
  6906. if (this.initGL() && this.sceneURL) {
  6907. var b = this.ui.signalLoadProgress.bind(this.ui);
  6908. a = function(a) {
  6909. b(1, 1);
  6910. this.scene = new Scene(this.gl);
  6911. this.scene.stripData = this.stripData;
  6912. if (this.scene.load(new Archive(a)))
  6913. if (2070 >= this.scene.metaData.tbVersion) this.ui.showFailure("模型文件版本过低",this);
  6914. else {
  6915. if(this.bindInput(), this.requestFrame(this.updateLoad.bind(this)), this.onLoad) this.onLoad()
  6916. }
  6917. else this.ui.showFailure("模型文件无法读取或无效" /*+ (load.failure?load.failure:"") */,this)
  6918. }.bind(this);
  6919. var c = function() {
  6920. this.ui.showFailure("模型文件 (" + this.sceneURL + ") 无法获取.",this)
  6921. }.bind(this);
  6922. Network.fetchBinary(this.sceneURL, a, c, b)
  6923. }
  6924. }
  6925. ;
  6926. WebViewer.prototype.unload = function() {
  6927. delete this.scene;
  6928. delete this.input;
  6929. delete this.ui;
  6930. delete this.mainColor;
  6931. delete this.mainBuffer;
  6932. delete this.gl;
  6933. var a = this.domRoot.clientWidth
  6934. , b = this.domRoot.clientHeight;
  6935. this.initCanvas(a, b);
  6936. this.ui = new UI(this);
  6937. this.ui.setSize(a, b);
  6938. this.ui.showPreview();
  6939. this.cancelFrame()
  6940. }
  6941. ;
  6942. WebViewer.prototype.clear = function() {//许钟文加 清除数据和画面
  6943. delete this.scene;
  6944. delete this.input;
  6945. delete this.ui;
  6946. delete this.mainColor;
  6947. delete this.mainBuffer;
  6948. delete this.gl;
  6949. delete this.mainBufferNoDepth;
  6950. delete this.canvas;
  6951. delete this.mainDepth;
  6952. this.cancelFrame()
  6953. }
  6954. WebViewer.prototype.bindInput = function() {
  6955. this.input = new Input(this.ui.container);
  6956. this.input.onDrag.push(function(a, b, c, d) {
  6957. a = 1 - 2.2 / (Math.sqrt(c * c + d * d) + 2.2);
  6958. b = this.scene.view;
  6959. b.rotation[1] -= 0.4 * c * a;
  6960. b.rotation[0] -= 0.4 * d * a;
  6961. b.rotation[0] = 90 < b.rotation[0] ? 90 : b.rotation[0];
  6962. b.rotation[0] = -90 > b.rotation[0] ? -90 : b.rotation[0];
  6963. b.updateView();
  6964. this.wake()
  6965. }
  6966. .bind(this));
  6967. this.input.onPan.push(function(a, b) {
  6968. var c = this.scene.view
  6969. , d = c.fov / 45 * 0.8 * (c.radius / this.domRoot.clientHeight)
  6970. , e = -a * d
  6971. , d = b * d;
  6972. c.pivot[0] += e * c.transform[0] + d * c.transform[4];
  6973. c.pivot[1] += e * c.transform[1] + d * c.transform[5];
  6974. c.pivot[2] += e * c.transform[2] + d * c.transform[6];
  6975. c.updateView();
  6976. this.wake()
  6977. }
  6978. .bind(this));
  6979. this.input.onPan2.push(function(a, b) {
  6980. var c = 1 - 2.2 / (Math.sqrt(a * a + b * b) + 2.2);
  6981. this.scene.lights.rotation -= 0.4 * a * c;
  6982. this.wake()
  6983. }
  6984. .bind(this));
  6985. this.input.onZoom.push(function(a) {
  6986. var b = this.scene.view;
  6987. b.radius *= 1 - 0.002 * a;
  6988. b.radius = 0.001 > b.radius ? 0.001 : b.radius;
  6989. b.radius = 1E3 < b.radius ? 1E3 : b.radius;
  6990. b.updateView();
  6991. this.wake()
  6992. }
  6993. .bind(this));
  6994. this.input.onDoubleTap.push(function(a, b) {
  6995. this.scene.view.reset();
  6996. this.scene.sceneAnimator && this.scene.sceneAnimator.resetCustomView();
  6997. this.wake()
  6998. }
  6999. .bind(this));
  7000. this.ui.bindInput(this.input)
  7001. }
  7002. ;
  7003. WebViewer.prototype.wake = function(a) {
  7004. a = a || 16;
  7005. this.sleepCounter = this.sleepCounter < a ? a : this.sleepCounter;
  7006. this.scene.postRender.discardAAHistory();
  7007. this.requestFrame(this.update.bind(this))
  7008. }
  7009. ;
  7010. WebViewer.prototype.requestFrame = function(a) {
  7011. var b = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
  7012. if (!this.frameRequestPending) {
  7013. var c = function() {
  7014. this.frameRequestPending = 0;
  7015. a()
  7016. }
  7017. .bind(this);
  7018. this.frameRequestPending = b(c, this.canvas)
  7019. }
  7020. }
  7021. ;
  7022. WebViewer.prototype.cancelFrame = function() {
  7023. this.frameRequestPending && (window.cancelAnimationFrame || window.mozCancelAnimationFrame || window.webkitCancelAnimationFrame || window.msCancelAnimationFrame)(this.frameRequestPending)
  7024. }
  7025. ;
  7026. WebViewer.prototype.fullscreenChange = function() {
  7027. FullScreen.active() ? (this.oldRootWidth = this.domRoot.style.width,
  7028. this.oldRootHeight = this.domRoot.style.height,
  7029. this.domRoot.style.width = "100%",
  7030. this.domRoot.style.height = "100%") : (this.domRoot.style.width = this.oldRootWidth,
  7031. this.domRoot.style.height = this.oldRootHeight);
  7032. this.wake()
  7033. }
  7034. ;
  7035. WebViewer.prototype.resize = function(a, b) {
  7036. a && b ? (this.domRoot.style.width = a + "px",
  7037. this.domRoot.style.height = b + "px") : (a = this.domRoot.clientWidth,
  7038. b = this.domRoot.clientHeight);
  7039. this.canvas.width = a * this.pixelRatio;
  7040. this.canvas.height = b * this.pixelRatio;
  7041. this.canvas.style.width = a + "px";
  7042. this.canvas.style.height = b + "px";
  7043. this.ui.setSize(a, b);
  7044. this.allocBacking();
  7045. this.wake()
  7046. }
  7047. ;
  7048. WebViewer.prototype.updateLoad = function() {
  7049. this.scene.complete() ? this.start() : this.requestFrame(this.updateLoad.bind(this));
  7050. this.ui.animate()
  7051. }
  7052. ;
  7053. WebViewer.prototype.start = function() {
  7054. this.scene.view.updateView();
  7055. this.ui.showActiveView();
  7056. this.requestFrame(this.update.bind(this))
  7057. }
  7058. ;
  7059. WebViewer.prototype.update = function() {
  7060. var a = this.scene.sceneAnimator && !this.scene.sceneAnimator.paused;
  7061. if (0 < this.sleepCounter || this.ui.animating() || a || this.stripData.animationActive)
  7062. this.stripData.update(),
  7063. this.ui.animate(),
  7064. this.scene.update(),
  7065. this.drawScene(),
  7066. this.requestFrame(this.update.bind(this));
  7067. a ? this.scene.postRender.discardAAHistory() : this.sleepCounter--
  7068. }
  7069. ;
  7070. WebViewer.prototype.reDrawScene = function() {
  7071. this.stripData.update();
  7072. this.ui.animate();
  7073. this.scene.update();
  7074. this.drawScene();
  7075. this.requestFrame(this.update.bind(this));
  7076. this.scene.postRender.discardAAHistory()
  7077. }
  7078. ;
  7079. WebViewer.prototype.drawScene = function() {
  7080. this.gl.isContextLost() || (this.domRoot.clientWidth == this.canvas.clientWidth && this.domRoot.clientHeight == this.canvas.clientHeight || this.resize(),
  7081. this.scene.view.size = [this.mainBuffer.width, this.mainBuffer.height],
  7082. this.scene.view.updateProjection(),
  7083. this.scene.postRender.adjustProjectionForSupersampling(this.scene.view),
  7084. this.scene.collectShadows(this.mainBuffer),
  7085. this.mainBuffer.bind(),
  7086. this.scene.draw(this.mainBuffer),
  7087. this.mainDepth && (this.mainBufferNoDepth.bind(),
  7088. this.scene.drawSecondary(this.mainDepth)),
  7089. this.scene.postRender.present(this.mainColor, this.canvas.width, this.canvas.height, this.stripData.active()))
  7090. }
  7091. ;
  7092. fdage = "undefined" == typeof fdage ? {} : fdage;
  7093. fdage.WebViewer = WebViewer;
  7094. fdage.dataLocale = (0 == window.location.protocol.indexOf("https") ? "https:" : "http:") + "//viewer.fdage.co/main/data/";
  7095. var ShaderTable = {
  7096. "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);}",
  7097. "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;}",
  7098. "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;}",
  7099. "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)));}",
  7100. "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}",
  7101. "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);}",
  7102. "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);}",
  7103. "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}",
  7104. "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;}",
  7105. "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",
  7106. "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);}",
  7107. "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",
  7108. "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",
  7109. "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",
  7110. "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}",
  7111. "postaa.glsl": "precision mediump float;uniform sampler2D tInput;varying vec2 j;void main(void){gl_FragColor=texture2D(tInput,j);}",
  7112. "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#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;}",
  7113. "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);}",
  7114. "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;}",
  7115. "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);}",
  7116. "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;}",
  7117. "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}",
  7118. "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;}",
  7119. "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;}",
  7120. "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}",
  7121. "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);}",
  7122. "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;}",
  7123. nil: ""
  7124. };
  7125. }
  7126. )(fdage);