4dage222.js 311 KB

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