4dageModelshow.js 181 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590
  1. var dom = {};
  2. dom.addClass = function(elem, className) {
  3. if (elem.className === undefined) {
  4. elem.className = className;
  5. } else if (elem.className !== className) {
  6. var classes = elem.className.split(/ +/);
  7. if (classes.indexOf(className) == -1) {
  8. classes.push(className);
  9. elem.className = classes.join(' ').replace(/^\s+/, '').replace(/\s+$/, '');
  10. }
  11. }
  12. }
  13. dom.removeClass = function(elem, className) {
  14. if (className) {
  15. if (elem.className === undefined) {
  16. // elem.className = className;
  17. }else if (elem.className === className) {
  18. elem.removeAttribute('class');
  19. }else{
  20. var classes = elem.className.split(/ +/);
  21. var index = classes.indexOf(className);
  22. if(index != -1){
  23. classes.splice(index, 1);
  24. elem.className = classes.join(' ');
  25. }
  26. }
  27. }else{
  28. elem.className = undefined;
  29. }
  30. }
  31. dom.hasClass = function(elem, className) {
  32. return new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)').test(elem.className) || false;
  33. }
  34. var fdage = {};
  35. if (typeof define === "function" && define.amd) define(fdage); else if (typeof module === "object" && module.exports) module.exports = fdage;
  36. (function(fdage) {
  37. 'use strict';
  38. function Archive(a) {
  39. this.files = [];
  40. for (a = new ByteStream(a); !a.empty(); ) {
  41. var b = {};
  42. b.name = a.readCString();
  43. b.type = a.readCString();
  44. var c = a.readUint32()
  45. , d = a.readUint32()
  46. , e = a.readUint32();
  47. b.data = a.readBytes(d);
  48. if (!(b.data.length < d)) {
  49. if (c & 1 && (b.data = this.decompress(b.data, e),
  50. null === b.data))
  51. continue;this.files[b.name] = b
  52. }
  53. }
  54. }
  55. Archive.prototype.get = function(a) {
  56. return this.files[a]
  57. }
  58. ;
  59. Archive.prototype.extract = function(a) {
  60. var b = this.files[a];
  61. delete this.files[a];
  62. return b
  63. }
  64. ;
  65. Archive.prototype.checkSignature = function(a) {
  66. if (!a)
  67. return !1;
  68. var b = this.get(a.name + ".sig");
  69. if (!b)
  70. return !1;
  71. b = JSON.parse(String.fromCharCode.apply(null , b.data));
  72. if (!b)
  73. return !1;
  74. for (var c = 5381, d = 0; d < a.data.length; ++d)
  75. c = 33 * c + a.data[d] & 4294967295;
  76. a = new BigInt;
  77. 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);
  78. d = new BigInt;
  79. d.setBytes(b[0]);
  80. return d.powmod(65537, a).toInt32() != c ? !1 : !0
  81. }
  82. ;
  83. Archive.prototype.decompress = function(a, b) {
  84. var c = new Uint8Array(b)
  85. , d = 0
  86. , e = new Uint32Array(4096)
  87. , f = new Uint32Array(4096)
  88. , g = 256
  89. , h = a.length
  90. , k = 0
  91. , l = 1
  92. , m = 0
  93. , n = 1;
  94. c[d++] = a[0];
  95. for (var r = 1; ; r++) {
  96. n = r + (r >> 1);
  97. if (n + 1 >= h)
  98. break;
  99. var m = a[n + 1]
  100. , n = a[n]
  101. , p = r & 1 ? m << 4 | n >> 4 : (m & 15) << 8 | n;
  102. if (p < g)
  103. if (256 > p)
  104. m = d,
  105. n = 1,
  106. c[d++] = p;
  107. else
  108. for (var m = d, n = f[p], p = e[p], q = p + n; p < q; )
  109. c[d++] = c[p++];
  110. else if (p == g) {
  111. m = d;
  112. n = l + 1;
  113. p = k;
  114. for (q = k + l; p < q; )
  115. c[d++] = c[p++];
  116. c[d++] = c[k]
  117. } else
  118. break;
  119. e[g] = k;
  120. f[g++] = l + 1;
  121. k = m;
  122. l = n;
  123. g = 4096 <= g ? 256 : g
  124. }
  125. return d == b ? c : null
  126. };
  127. function BigInt(a) {
  128. this.digits = new Uint16Array(a || 0)
  129. }
  130. BigInt.prototype.setBytes = function(a, b) {
  131. var c = (a.length + 1) / 2 | 0;
  132. this.digits = new Uint16Array(c);
  133. if (b)
  134. for (var d = 0, c = a.length - 1; 0 <= c; c -= 2)
  135. this.digits[d++] = a[c] + (0 < c ? 256 * a[c - 1] : 0);
  136. else
  137. for (d = 0; d < c; ++d)
  138. this.digits[d] = a[2 * d] + 256 * a[2 * d + 1];
  139. this.trim()
  140. }
  141. ;
  142. BigInt.prototype.toInt32 = function() {
  143. var a = 0;
  144. 0 < this.digits.length && (a = this.digits[0],
  145. 1 < this.digits.length && (a |= this.digits[1] << 16));
  146. return a
  147. }
  148. ;
  149. BigInt.prototype.lessThan = function(a) {
  150. if (this.digits.length == a.digits.length)
  151. for (var b = this.digits.length - 1; 0 <= b; --b) {
  152. var c = this.digits[b]
  153. , d = a.digits[b];
  154. if (c != d)
  155. return c < d
  156. }
  157. return this.digits.length < a.digits.length
  158. }
  159. ;
  160. BigInt.prototype.shiftRight = function() {
  161. for (var a = 0, b = this.digits, c = b.length - 1; 0 <= c; --c) {
  162. var d = b[c];
  163. b[c] = d >> 1 | a << 15;
  164. a = d
  165. }
  166. this.trim()
  167. }
  168. ;
  169. BigInt.prototype.shiftLeft = function(a) {
  170. if (0 < a) {
  171. var b = a / 16 | 0;
  172. a %= 16;
  173. for (var c = 16 - a, d = this.digits.length + b + 1, e = new BigInt(d), f = 0; f < d; ++f)
  174. 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;
  175. e.trim();
  176. return e
  177. }
  178. return new BigInt(this)
  179. }
  180. ;
  181. BigInt.prototype.bitCount = function() {
  182. var a = 0;
  183. if (0 < this.digits.length)
  184. for (var a = 16 * (this.digits.length - 1), b = this.digits[this.digits.length - 1]; b; )
  185. b >>>= 1,
  186. ++a;
  187. return a
  188. }
  189. ;
  190. BigInt.prototype.sub = function(a) {
  191. var b = this.digits
  192. , c = a.digits
  193. , d = this.digits.length;
  194. a = a.digits.length;
  195. for (var e = 0, f = 0; f < d; ++f) {
  196. var g = b[f]
  197. , h = f < a ? c[f] : 0
  198. , h = h + e
  199. , e = h > g ? 1 : 0
  200. , g = g + (e << 16);
  201. b[f] = g - h & 65535
  202. }
  203. this.trim()
  204. }
  205. ;
  206. BigInt.prototype.mul = function(a) {
  207. for (var b = new BigInt(this.digits.length + a.digits.length), c = b.digits, d = 0; d < this.digits.length; ++d)
  208. for (var e = this.digits[d], f = 0; f < a.digits.length; ++f)
  209. for (var g = e * a.digits[f], h = d + f; g; ) {
  210. var k = (g & 65535) + c[h];
  211. c[h] = k & 65535;
  212. g >>>= 16;
  213. g += k >>> 16;
  214. ++h
  215. }
  216. b.trim();
  217. return b
  218. }
  219. ;
  220. BigInt.prototype.mod = function(a) {
  221. if (0 >= this.digits.length || 0 >= a.digits.length)
  222. return new BigInt(0);
  223. var b = new BigInt(this.digits);
  224. if (!this.lessThan(a)) {
  225. for (var c = new BigInt(a.digits), c = c.shiftLeft(b.bitCount() - c.bitCount()); !b.lessThan(a); )
  226. c.lessThan(b) && b.sub(c),
  227. c.shiftRight();
  228. b.trim()
  229. }
  230. return b
  231. }
  232. ;
  233. BigInt.prototype.powmod = function(a, b) {
  234. for (var c = new BigInt([1]), d = this.mod(b); a; )
  235. a & 1 && (c = c.mul(d).mod(b)),
  236. a >>>= 1,
  237. d = d.mul(d).mod(b);
  238. return c
  239. }
  240. ;
  241. BigInt.prototype.trim = function() {
  242. for (var a = this.digits.length; 0 < a && 0 == this.digits[a - 1]; )
  243. --a;
  244. a != this.digits.length && (this.digits = this.digits.subarray(0, a))
  245. }
  246. ;
  247. function Bounds(a) {
  248. for (var b = 0; b < a.length; ++b) {
  249. var c = a[b].bounds;
  250. if (void 0 === this.min)
  251. this.min = [c.min[0], c.min[1], c.min[2]],
  252. this.max = [c.max[0], c.max[1], c.max[2]];
  253. else
  254. for (var d = 0; 3 > d; ++d)
  255. this.min[d] = Math.min(c.min[d], this.min[d]),
  256. this.max[d] = Math.max(c.max[d], this.max[d])
  257. }
  258. this.min = this.min ? this.min : [0, 0, 0];
  259. this.max = this.max ? this.max : [0, 0, 0];
  260. 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])];
  261. this.radius = [this.max[0] - this.center[0], this.max[1] - this.center[1], this.max[2] - this.center[2]]
  262. }
  263. ;function ByteStream(a) {
  264. this.bytes = new Uint8Array(a)
  265. }
  266. ByteStream.prototype.empty = function() {
  267. return 0 >= this.bytes.length
  268. }
  269. ;
  270. ByteStream.prototype.readCString = function() {
  271. for (var a = this.bytes, b = a.length, c = 0; c < b; ++c)
  272. if (0 == a[c])
  273. return a = String.fromCharCode.apply(null , this.bytes.subarray(0, c)),
  274. this.bytes = this.bytes.subarray(c + 1),
  275. a;
  276. return null
  277. }
  278. ;
  279. ByteStream.prototype.asString = function() {
  280. for (var a = "", b = 0; b < this.bytes.length; ++b)
  281. a += String.fromCharCode(this.bytes[b]);
  282. return a
  283. }
  284. ;
  285. ByteStream.prototype.readBytes = function(a) {
  286. var b = this.bytes.subarray(0, a);
  287. this.bytes = this.bytes.subarray(a);
  288. return b
  289. }
  290. ;
  291. ByteStream.prototype.readUint32 = function() {
  292. var a = this.bytes
  293. , b = a[0] | a[1] << 8 | a[2] << 16 | a[3] << 24;
  294. this.bytes = a.subarray(4);
  295. return b
  296. }
  297. ;
  298. var prepareEmbedParams = function(a) {
  299. a = a || {};
  300. if (document.location.search)
  301. for (var b = document.location.search.substring(1).split("&"), c = 0; c < b.length; ++c) {
  302. var d = b[c].split("=");
  303. a[d[0]] = d[1]
  304. }
  305. b = function(a) {
  306. if (a | 0)
  307. return !0;
  308. for (var b = "true True TRUE yes Yes YES".split(" "), c = 0; c < b.length; ++c)
  309. if (a === b[c])
  310. return !0;
  311. return !1
  312. }
  313. ;
  314. a.width = a.width || 800;
  315. a.height = a.height || 600;
  316. a.autoStart = b(a.autoStart);
  317. a.pagePreset = b(a.pagePreset);
  318. a.fullFrame = b(a.fullFrame) || b(a.bare);
  319. a.fullFrame = !a.pagePreset && a.fullFrame;
  320. return a
  321. }
  322. , embed = function(a, b) {
  323. var c;
  324. b = prepareEmbedParams(b);
  325. if (b.pagePreset) {
  326. c = new WebViewer(b.width,b.height,a);
  327. document.body.style.backgroundColor = "#d7e4da";
  328. var d = document.createElement("div");
  329. d.style.position = "relative";
  330. d.style.backgroundColor = "#e4e7e4";
  331. d.style.width = b.width + 12 + "px";
  332. d.style.height = b.height + 6 + 16 + "px";
  333. d.style.margin = "auto";
  334. d.style.boxShadow = "3px 5px 12px 0px grey";
  335. document.body.appendChild(d);
  336. var e = document.createElement("div");
  337. e.style.position = "relative";
  338. e.style.left = "6px";
  339. e.style.top = "6px";
  340. d.appendChild(e);
  341. e.appendChild(c.domRoot);
  342. if (!c.mobile) {
  343. d.style.resize = "both";
  344. d.style.overflow = "hidden";
  345. var f = [d.style.width, d.style.height]
  346. , g = function() {
  347. if (FullScreen.active())
  348. d.style.resize = "none";
  349. else if (d.style.resize = "both",
  350. f[0] != d.style.width || f[1] != d.style.height)
  351. f[0] = d.style.width,
  352. f[1] = d.style.height,
  353. c.resize(d.clientWidth - 12, d.clientHeight - 6 - 16);
  354. window.setTimeout(g, 100)
  355. }
  356. ;
  357. g()
  358. }
  359. } else {
  360. c = new WebViewer(b.fullFrame ? window.innerWidth : b.width,b.fullFrame ? window.innerHeight : b.height,a, b.root);
  361. if(!b.root) document.body.appendChild(c.domRoot);
  362. if(b.backgroundColor) fdage.backgroundColor = b.backgroundColor;
  363. if(b.ifPlain) fdage.ifPlain = true;
  364. b.fullFrame && (c.domRoot.style.position = "absolute",
  365. b.root || (c.domRoot.style.left = c.domRoot.style.top = 0),
  366. window.addEventListener("resize", function() {
  367. FullScreen.active() || c.resize(c.clientWidth,c.clientHeidht)
  368. }));
  369. }
  370. c.ui.setThumbnailURL(b.thumbnailURL);
  371. b.autoStart && c.loadScene();
  372. return c
  373. }
  374. , fetchThumbnail = function(a, b, c, d) {
  375. var e = -1 == a.indexOf("?") ? "?" : "&";
  376. Network.fetchBinaryIncremental(a + e + "thumb=1", function(a) {
  377. (a = (new Archive(a)).extract("thumbnail.jpg")) ? TextureCache.parseFile(a, b, d) : c && c();
  378. return 0
  379. }, c, 49152)
  380. }
  381. , fdage = "undefined" == typeof fdage ? {} : fdage;
  382. fdage.embed = embed;
  383. fdage.fetchThumbnail = fetchThumbnail;
  384. function Framebuffer(a, b) {
  385. this.gl = a;
  386. this.fbo = a.createFramebuffer();
  387. a.bindFramebuffer(a.FRAMEBUFFER, this.fbo);
  388. b && (this.width = b.width,
  389. this.height = b.height,
  390. b.color0 && (this.color0 = b.color0,
  391. a.framebufferTexture2D(a.FRAMEBUFFER, a.COLOR_ATTACHMENT0, a.TEXTURE_2D, this.color0.id, 0),
  392. this.width = b.color0.desc.width,
  393. this.height = b.color0.desc.height),
  394. b.depth ? (this.depth = b.depth,
  395. a.framebufferTexture2D(a.FRAMEBUFFER, a.DEPTH_ATTACHMENT, a.TEXTURE_2D, this.depth.id, 0)) : (this.depthBuffer = b.depthBuffer,
  396. b.createDepth && !this.depthBuffer && (this.depthBuffer = Framebuffer.createDepthBuffer(a, this.width, this.height)),
  397. this.depthBuffer && (a.bindRenderbuffer(a.RENDERBUFFER, this.depthBuffer),
  398. a.framebufferRenderbuffer(a.FRAMEBUFFER, a.DEPTH_ATTACHMENT, a.RENDERBUFFER, this.depthBuffer),
  399. a.bindRenderbuffer(a.RENDERBUFFER, null ))));
  400. this.valid = b && b.ignoreStatus || a.checkFramebufferStatus(a.FRAMEBUFFER) == a.FRAMEBUFFER_COMPLETE;
  401. a.bindFramebuffer(a.FRAMEBUFFER, null )
  402. }
  403. Framebuffer.createDepthBuffer = function(a, b, c) {
  404. var d = a.createRenderbuffer();
  405. a.bindRenderbuffer(a.RENDERBUFFER, d);
  406. a.renderbufferStorage(a.RENDERBUFFER, a.DEPTH_COMPONENT16, b, c);
  407. a.bindRenderbuffer(a.RENDERBUFFER, null );
  408. return d
  409. }
  410. ;
  411. Framebuffer.prototype.bind = function() {
  412. this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, this.fbo);
  413. this.gl.viewport(0, 0, this.width, this.height)
  414. }
  415. ;
  416. Framebuffer.bindNone = function(a) {
  417. a.bindFramebuffer(a.FRAMEBUFFER, null )
  418. }
  419. ;
  420. var FullScreen = {
  421. support: function() {
  422. return !!(document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled)
  423. },
  424. begin: function(a, b) {
  425. var c = a.requestFullscreen || a.webkitRequestFullScreen || a.mozRequestFullScreen || a.msRequestFullscreen;
  426. if (c) {
  427. var d = function() {
  428. FullScreen.active() || (document.removeEventListener("fullscreenchange", d),
  429. document.removeEventListener("webkitfullscreenchange", d),
  430. document.removeEventListener("mozfullscreenchange", d),
  431. document.removeEventListener("MSFullscreenChange", d));
  432. b && b()
  433. }
  434. ;
  435. document.addEventListener("fullscreenchange", d);
  436. document.addEventListener("webkitfullscreenchange", d);
  437. document.addEventListener("mozfullscreenchange", d);
  438. document.addEventListener("MSFullscreenChange", d);
  439. c.bind(a)()
  440. }
  441. },
  442. end: function() {
  443. var a = document.exitFullscreen || document.webkitExitFullscreen || document.mozCancelFullScreen || document.msExitFullscreen;
  444. a && a.bind(document)()
  445. },
  446. active: function() {
  447. return !!(document.fullscreenElement || document.webkitIsFullScreen || document.mozFullScreenElement || document.msFullscreenElement)
  448. }
  449. };
  450. function Input(a) {
  451. this.onTap = [];
  452. this.onSingleTap = [];
  453. this.onDoubleTap = [];
  454. this.onDrag = [];
  455. this.onZoom = [];
  456. this.onPan = [];
  457. this.onPan2 = [];
  458. this.onAnything = [];
  459. this.macHax = 0 <= navigator.platform.toUpperCase().indexOf("MAC");
  460. a && this.attach(a)
  461. }
  462. Input.prototype.attach = function(a) {
  463. this.element = a;
  464. var b = function(a) {
  465. for (var b = 0; b < this.onAnything.length; ++b)
  466. this.onAnything[b]();
  467. a.preventDefault()
  468. }
  469. .bind(this);
  470. this.mouseStates = [{
  471. pressed: !1,
  472. position: [0, 0],
  473. downPosition: [0, 0]
  474. }, {
  475. pressed: !1,
  476. position: [0, 0],
  477. downPosition: [0, 0]
  478. }, {
  479. pressed: !1,
  480. position: [0, 0],
  481. downPosition: [0, 0]
  482. }];
  483. this.lastTapPos = [0, 0];
  484. a = function(a) {
  485. if (a.target === this.element) {
  486. var d = this.mouseStates[a.button];
  487. if (d) {
  488. d.pressed = !0;
  489. var e = this.element.getBoundingClientRect();
  490. d.position[0] = d.downPosition[0] = a.clientX - e.left;
  491. d.position[1] = d.downPosition[1] = a.clientY - e.top;
  492. b(a)
  493. }
  494. }
  495. }
  496. .bind(this);
  497. this.element.addEventListener("mousedown", a);
  498. a = function(a) {
  499. var d = this.mouseStates[a.button];
  500. if (d) {
  501. var e = this.element.getBoundingClientRect()
  502. , f = a.clientX - e.left
  503. , e = a.clientY - e.top;
  504. d.pressed = !1;
  505. d.position[0] = f;
  506. d.position[1] = e;
  507. 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])) {
  508. for (var g = 0; g < this.onTap.length; ++g)
  509. this.onTap[g](f, e);
  510. this.needSingleClick = !0;
  511. window.setTimeout(function(a, b) {
  512. if (this.needSingleClick) {
  513. for (var c = 0; c < this.onSingleTap.length; ++c)
  514. this.onSingleTap[c](a, b);
  515. this.needSingleClick = !1
  516. }
  517. }
  518. .bind(this, f, e), 301);
  519. d = !1;
  520. if (void 0 !== this.doubleClickTimer && (g = 8 > Math.abs(f - this.lastTapPos[0]) + Math.abs(e - this.lastTapPos[1]),
  521. 300 > Date.now() - this.doubleClickTimer && g))
  522. for (d = !0,
  523. this.needSingleClick = !1,
  524. g = 0; g < this.onDoubleTap.length; ++g)
  525. this.onDoubleTap[g](f, e);
  526. this.doubleClickTimer = Date.now();
  527. d && (this.doubleClickTimer = -1E9);
  528. this.lastTapPos[0] = f;
  529. this.lastTapPos[1] = e
  530. }
  531. }
  532. b(a)
  533. }
  534. .bind(this);
  535. this.element.addEventListener("mouseup", a);
  536. a = function(a) {
  537. for (var d = !1, e = 0; 3 > e; ++e) {
  538. var f = this.mouseStates[e];
  539. if (f.pressed) {
  540. var g = this.element.getBoundingClientRect()
  541. , d = a.clientX - g.left
  542. , g = a.clientY - g.top
  543. , h = d - f.position[0]
  544. , k = g - f.position[1];
  545. f.position[0] = d;
  546. f.position[1] = g;
  547. if (1 <= e || a.ctrlKey)
  548. for (f = 0; f < this.onPan.length; ++f)
  549. this.onPan[f](h, k);
  550. else if (0 == e)
  551. if (a.shiftKey)
  552. for (f = 0; f < this.onPan2.length; ++f)
  553. this.onPan2[f](h, k);
  554. else
  555. for (f = 0; f < this.onDrag.length; ++f)
  556. this.onDrag[f](d, g, h, k);
  557. d = !0
  558. }
  559. }
  560. d && b(a)
  561. }
  562. .bind(this);
  563. this.element.addEventListener("mousemove", a);
  564. a = function(a) {
  565. var d = 0;
  566. a.deltaY ? (d = -0.4 * a.deltaY,
  567. 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);
  568. for (var e = 0; e < this.onZoom.length; ++e)
  569. this.onZoom[e](d);
  570. b(a)
  571. }
  572. .bind(this);
  573. this.element.addEventListener("mousewheel", a);
  574. this.element.addEventListener("DOMMouseScroll", a);
  575. this.element.addEventListener("wheel", a);
  576. a = function(a) {
  577. for (var b = 0; b < this.mouseStates.length; ++b)
  578. this.mouseStates[b].pressed = !1;
  579. a.preventDefault()
  580. }
  581. .bind(this);
  582. this.element.addEventListener("mouseleave", a);
  583. this.element.addEventListener("contextmenu", function(a) {
  584. a.preventDefault()
  585. });
  586. this.touches = {};
  587. this.tapPossible = !1;
  588. this.touchCountFloor = 0;
  589. a = function(a) {
  590. for (var d = this.element.getBoundingClientRect(), e = !1, f = 0; f < a.changedTouches.length; ++f)
  591. if (a.target === this.element) {
  592. var g = a.changedTouches[f]
  593. , e = {
  594. x: g.clientX - d.left,
  595. y: g.clientY - d.top
  596. };
  597. e.startX = e.x;
  598. e.startY = e.y;
  599. this.touches[g.identifier] = e;
  600. e = !0
  601. }
  602. this.tapPossible = 1 == a.touches.length;
  603. for (g = d = 0; g < this.touches.length; ++g)
  604. d++;
  605. d > this.touchCountFloor && (this.touchCountFloor = d);
  606. e && b(a)
  607. }
  608. .bind(this);
  609. this.element.addEventListener("touchstart", a);
  610. a = function(a) {
  611. for (var d = !1, e = 0; e < a.changedTouches.length; ++e) {
  612. var f = a.changedTouches[e]
  613. , g = this.touches[f.identifier];
  614. if (g) {
  615. if (this.tapPossible) {
  616. var h = this.element.getBoundingClientRect()
  617. , d = f.clientX - h.left
  618. , h = f.clientY - h.top;
  619. if (24 > Math.max(Math.abs(d - g.startX), Math.abs(h - g.startY))) {
  620. for (e = 0; e < this.onTap.length; ++e)
  621. this.onTap[e](d, h);
  622. this.needSingleTap = !0;
  623. window.setTimeout(function(a, b) {
  624. if (this.needSingleTap) {
  625. for (var c = 0; c < this.onSingleTap.length; ++c)
  626. this.onSingleTap[c](a, b);
  627. this.needSingleTap = !1
  628. }
  629. }
  630. .bind(this, d, h), 501);
  631. g = !1;
  632. if (void 0 !== this.doubleTapTimer) {
  633. var k = 24 > Math.max(Math.abs(d - this.lastTapPos[0]), Math.abs(h - this.lastTapPos[1]))
  634. , l = 500 > Date.now() - this.doubleTapTimer;
  635. if (k && l)
  636. for (g = !0,
  637. e = 0; e < this.onDoubleTap.length; ++e)
  638. this.onDoubleTap[e](d, h)
  639. }
  640. this.doubleTapTimer = Date.now();
  641. g && (this.doubleTapTimer = -1E9);
  642. this.lastTapPos[0] = d;
  643. this.lastTapPos[1] = h
  644. }
  645. this.tapPossible = !1
  646. }
  647. delete this.touches[f.identifier];
  648. d = !0
  649. }
  650. }
  651. for (f = e = 0; f < this.touches.length; ++f)
  652. e++;
  653. 0 >= e && (this.touchCountFloor = 0);
  654. d && b(a)
  655. }
  656. .bind(this);
  657. this.element.addEventListener("touchend", a);
  658. this.element.addEventListener("touchcancel", a);
  659. this.element.addEventListener("touchleave", a);
  660. a = function(a) {
  661. for (var d = [], e = 0; e < a.touches.length; ++e)
  662. a.touches[e].target === this.element && d.push(a.touches[e]);
  663. var f = this.element.getBoundingClientRect();
  664. if (1 == d.length && 1 >= this.touchCountFloor) {
  665. var g = d[0]
  666. , h = this.touches[g.identifier];
  667. if (h) {
  668. var k = g.clientX - f.left
  669. , g = g.clientY - f.top
  670. , f = k - h.x
  671. , l = g - h.y;
  672. h.x = k;
  673. h.y = g;
  674. for (e = 0; e < this.onDrag.length; ++e)
  675. this.onDrag[e](k, g, f, l, a.shiftKey)
  676. }
  677. } else if (2 == d.length && 2 >= this.touchCountFloor) {
  678. if (l = d[0],
  679. e = this.touches[l.identifier],
  680. g = d[1],
  681. h = this.touches[g.identifier],
  682. e && h) {
  683. var k = l.clientX - f.left
  684. , l = l.clientY - f.top
  685. , m = g.clientX - f.left
  686. , n = g.clientY - f.top
  687. , r = Math.sqrt((k - m) * (k - m) + (l - n) * (l - n))
  688. , p = Math.sqrt((e.x - h.x) * (e.x - h.x) + (e.y - h.y) * (e.y - h.y))
  689. , q = Math.abs(r - p)
  690. , f = (k - e.x + m - h.x) / 2
  691. , g = (l - e.y + n - h.y) / 2
  692. , u = Math.sqrt(f * f + g * g);
  693. e.x = k;
  694. e.y = l;
  695. h.x = m;
  696. h.y = n;
  697. if (0 < q)
  698. for (h = q / (q + u),
  699. e = 0; e < this.onZoom.length; ++e)
  700. this.onZoom[e](2 * (r - p) * h);
  701. if (0 < u)
  702. for (h = u / (q + u),
  703. e = 0; e < this.onDrag.length; ++e)
  704. this.onPan[e](f * h, g * h)
  705. }
  706. } else if (3 <= d.length) {
  707. for (e = p = r = m = l = 0; e < d.length; ++e)
  708. g = d[e],
  709. h = this.touches[g.identifier],
  710. k = g.clientX - f.left,
  711. g = g.clientY - f.top,
  712. r += k,
  713. p += g,
  714. h && (l += h.x,
  715. m += h.y,
  716. h.x = k,
  717. h.y = g);
  718. l /= d.length;
  719. m /= d.length;
  720. r /= d.length;
  721. p /= d.length;
  722. for (e = 0; e < this.onPan2.length; ++e)
  723. this.onPan2[e](r - l, p - m)
  724. }
  725. 0 < d.length && b(a)
  726. }
  727. .bind(this);
  728. this.element.addEventListener("touchmove", a)
  729. }
  730. ;
  731. function Lights(a, b) {
  732. this.rotation = this.shadowCount = this.count = 0;
  733. this.positions = [];
  734. this.directions = [];
  735. this.matrixWeights = [];
  736. this.matrix = Matrix.identity();
  737. this.invMatrix = Matrix.identity();
  738. for (var c in a)
  739. this[c] = a[c];
  740. this.count = this.positions.length / 4;
  741. this.shadowCount = Math.min(3, this.shadowCount);
  742. this.positions = new Float32Array(this.positions);
  743. this.positionBuffer = new Float32Array(this.positions);
  744. this.directions = new Float32Array(this.directions);
  745. this.directionBuffer = new Float32Array(this.directions);
  746. this.modelViewBuffer = new Float32Array(16 * this.shadowCount);
  747. this.projectionBuffer = new Float32Array(16 * this.shadowCount);
  748. this.finalTransformBuffer = new Float32Array(16 * this.shadowCount);
  749. this.shadowTexelPadProjections = new Float32Array(4 * this.shadowCount);
  750. this.shadowsNeedUpdate = new Uint8Array(this.shadowCount);
  751. for (var d = 0; d < this.shadowsNeedUpdate.length; ++d)
  752. this.shadowsNeedUpdate[d] = 1;
  753. Matrix.rotation(this.matrix, this.rotation, 1);
  754. Matrix.transpose(this.invMatrix, this.matrix);
  755. for (d = 0; d < this.count; ++d) {
  756. c = this.positions.subarray(4 * d, 4 * d + 4);
  757. var e = this.directions.subarray(3 * d, 3 * d + 3);
  758. 1 == this.matrixWeights[d] ? (Matrix.mul4(c, this.matrix, c[0], c[1], c[2], c[3]),
  759. 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]),
  760. Matrix.mulVec(e, b.viewMatrix, e[0], e[1], e[2]))
  761. }
  762. }
  763. Lights.prototype.getLightPos = function(a) {
  764. return this.positionBuffer.subarray(4 * a, 4 * a + 4)
  765. }
  766. ;
  767. Lights.prototype.getLightDir = function(a) {
  768. return this.directionBuffer.subarray(3 * a, 3 * a + 3)
  769. }
  770. ;
  771. Lights.prototype.update = function(a, b) {
  772. var c = new Matrix.type(this.matrix);
  773. Matrix.rotation(this.matrix, this.rotation, 1);
  774. Matrix.transpose(this.invMatrix, this.matrix);
  775. var rM = Matrix.transpose(Matrix.empty(), a.modelMatrix); //当模型变换后这里也考虑上模型变换矩阵,这样光影才会跟着变
  776. Matrix.mul(this.matrix, this.matrix, rM);
  777. for (var d = 0; d < this.count; ++d) {
  778. var e = this.positions.subarray(4 * d, 4 * d + 4)
  779. , f = this.directions.subarray(3 * d, 3 * d + 3)
  780. , g = this.getLightPos(d)
  781. , h = this.getLightDir(d);
  782. 1 == this.matrixWeights[d] ? (g[0] = e[0],
  783. g[1] = e[1],
  784. g[2] = e[2],
  785. g[3] = e[3],
  786. h[0] = f[0],
  787. h[1] = f[1],
  788. h[2] = f[2]) : 2 == this.matrixWeights[d] ? (Matrix.mul4(g, a.transform, e[0], e[1], e[2], e[3]),
  789. Matrix.mulVec(h, a.transform, f[0], f[1], f[2]),
  790. Matrix.mul4(g, this.matrix, g[0], g[1], g[2], g[3]),
  791. Matrix.mulVec(h, this.matrix, h[0], h[1], h[2])) : (Matrix.mul4(g, this.matrix, e[0], e[1], e[2], e[3]),
  792. Matrix.mulVec(h, this.matrix, f[0], f[1], f[2]));
  793. Vect.normalize(h, h)
  794. }
  795. for (var f = new Float32Array(this.finalTransformBuffer), g = Matrix.empty(), h = Matrix.empty(), k = Matrix.empty(), l = Vect.empty(), m = Vect.empty(), n = Vect.empty(), r = Vect.empty(), e = Vect.empty(), p = [], q = [], 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) {
  796. l = this.getLightPos(d);
  797. m = this.getLightDir(d);
  798. 0.99 < Math.abs(m[1]) ? Vect.set(n, 1, 0, 0) : Vect.set(n, 0, 1, 0);
  799. Vect.cross(r, n, m);
  800. Vect.normalize(r, r);
  801. Vect.cross(n, m, r);
  802. Vect.normalize(n, n);
  803. Matrix.set(g, r[0], r[1], r[2], -Vect.dot(r, l), n[0], n[1], n[2], -Vect.dot(n, l), m[0], m[1], m[2], -Vect.dot(m, l), 0, 0, 0, 1);
  804. for (l = 0; 8 > l; ++l)
  805. e[0] = l & 1 ? b.max[0] : b.min[0],
  806. e[1] = l & 2 ? b.max[1] : b.min[1],
  807. e[2] = l & 4 ? b.max[2] : b.min[2],
  808. Matrix.mulPoint(e, this.matrix, 1.005 * e[0], 1.005 * e[1], 1.005 * e[2]),
  809. Matrix.mulPoint(e, g, e[0], e[1], e[2]),
  810. 0 == l ? (p[0] = q[0] = e[0],
  811. p[1] = q[1] = e[1],
  812. p[2] = q[2] = e[2]) : (p[0] = Math.min(p[0], e[0]),
  813. p[1] = Math.min(p[1], e[1]),
  814. p[2] = Math.min(p[2], e[2]),
  815. q[0] = Math.max(q[0], e[0]),
  816. q[1] = Math.max(q[1], e[1]),
  817. q[2] = Math.max(q[2], e[2]));
  818. var l = -p[2]
  819. , m = -q[2]
  820. , s = this.spot[3 * d];
  821. 0 < s ? (l = Math.min(l, 1 / this.parameters[3 * d + 2]),
  822. m = Math.max(0.005 * l, m),
  823. Matrix.perspective(h, s, 1, m, l),
  824. d < this.shadowCount && (l = 2 * -Math.tan(0.00872664625 * s),
  825. this.shadowTexelPadProjections[4 * d + 0] = this.modelViewBuffer[16 * d + 2] * l,
  826. this.shadowTexelPadProjections[4 * d + 1] = this.modelViewBuffer[16 * d + 6] * l,
  827. this.shadowTexelPadProjections[4 * d + 2] = this.modelViewBuffer[16 * d + 10] * l,
  828. this.shadowTexelPadProjections[4 * d + 3] = this.modelViewBuffer[16 * d + 14] * l)) : (Matrix.ortho(h, p[0], q[0], p[1], q[1], m, l),
  829. d < this.shadowCount && (this.shadowTexelPadProjections[4 * d + 0] = this.shadowTexelPadProjections[4 * d + 1] = this.shadowTexelPadProjections[4 * d + 2] = 0,
  830. this.shadowTexelPadProjections[4 * d + 3] = Math.max(q[0] - p[0], q[1] - p[1])));
  831. Matrix.mul(k, h, g);
  832. Matrix.mul(k, u, k);
  833. Matrix.copyToBuffer(this.modelViewBuffer, 16 * d, g);
  834. Matrix.copyToBuffer(this.projectionBuffer, 16 * d, h);
  835. Matrix.copyToBuffer(this.finalTransformBuffer, 16 * d, k)
  836. }
  837. e = !1;
  838. for (d = 0; d < c.length; ++d)
  839. if (c[d] != this.matrix[d]) {
  840. e = !0;
  841. break
  842. }
  843. for (d = 0; d < this.shadowCount; d++)
  844. if (e && 1 == this.matrixWeights[d])
  845. this.shadowsNeedUpdate[d] = 1;
  846. else
  847. for (c = 16 * d; c < 16 * d + 16; ++c)
  848. if (f[c] != this.finalTransformBuffer[c]) {
  849. this.shadowsNeedUpdate[d] = 1;
  850. break
  851. }
  852. }
  853. ;
  854. function Material(a, b, c) {
  855. this.gl = a;
  856. this.name = c.name;
  857. var d = {
  858. mipmap: !0,
  859. aniso: a.hints.mobile ? 0 : 4
  860. };
  861. this.textures = {
  862. albedo: a.textureCache.fromFilesMergeAlpha(b.get(c.albedoTex), b.get(c.alphaTex), {
  863. mipmap: !0,
  864. aniso: a.hints.mobile ? 2 : 4
  865. }),
  866. reflectivity: a.textureCache.fromFilesMergeAlpha(b.get(c.reflectivityTex), b.get(c.glossTex), d),
  867. normal: a.textureCache.fromFile(b.get(c.normalTex), d),
  868. extras: a.textureCache.fromFilesMergeAlpha(b.get(c.extrasTex), b.get(c.extrasTexA), d)
  869. };
  870. this.strength = {};
  871. this.strength.albedo = (c.strength&&c.strength.albedo )|| 100; //改
  872. this.strength.reflectivity = (c.strength&&c.strength.reflectivity) || 100; //改
  873. this.strength.normal = (c.strength&&c.strength.normal )|| 100; //改
  874. this.strength.alpha = (c.strength&&c.strength.alpha) || 100; //改
  875. this.strength.gloss = (c.strength&&c.strength.gloss) || 100; //改
  876. if(c.blend==="add"&&c.alphaTex==void 0)this.strength.alpha=0;//改
  877. this.extrasTexCoordRanges = {};
  878. if (c.extrasTexCoordRanges)
  879. for (var e in c.extrasTexCoordRanges)
  880. this.extrasTexCoordRanges[e] = new Float32Array(c.extrasTexCoordRanges[e].scaleBias);
  881. this.textures.extras || (b = new Texture(a,{
  882. width: 1,
  883. height: 1
  884. }),
  885. b.loadArray(new Uint8Array([255, 255, 255, 255])),
  886. this.textures.extras = b);
  887. b = {
  888. none: function() {
  889. a.disable(a.BLEND)
  890. },
  891. alpha: function() {
  892. a.enable(a.BLEND);
  893. a.blendFunc(a.SRC_ALPHA, a.ONE_MINUS_SRC_ALPHA)
  894. },
  895. add: function() {
  896. a.enable(a.BLEND);
  897. a.blendFunc(a.ONE, a.ONE)
  898. }
  899. };
  900. this.blend = b[c.blend] || b.none;
  901. this.alphaTest = c.alphaTest || 0;
  902. this.usesBlending = this.blend !== b.none;
  903. this.shadowAlphaTest = this.alphaTest;
  904. 0 >= this.shadowAlphaTest && this.blend === b.alpha && (this.shadowAlphaTest = 0.5);
  905. this.castShadows = this.blend !== b.add;
  906. this.horizonOcclude = c.horizonOcclude || 0;
  907. this.fresnel = new Float32Array(c.fresnel ? c.fresnel : [1, 1, 1]);
  908. this.emissiveIntensity = c.emissiveIntensity || 1;
  909. d = [];
  910. 0 < c.lightCount && d.push("#define LIGHT_COUNT " + c.lightCount);
  911. 0 < c.shadowCount && d.push("#define SHADOW_COUNT " + Math.min(c.lightCount, c.shadowCount));
  912. 0 < c.alphaTest && d.push("#define ALPHA_TEST");
  913. this.blend === b.alpha && d.push("#define TRANSPARENCY_DITHER");
  914. a.hints.mobile && d.push("#define MOBILE");
  915. c.useSkin && (d.push("#define SKIN"),
  916. this.skinParams = c.skinParams || {
  917. subdermisColor: [1, 1, 1],
  918. transColor: [1, 0, 0, 0.5],
  919. fresnelColor: [0.2, 0.2, 0.2, 0.5],
  920. fresnelOcc: 1,
  921. fresnelGlossMask: 1,
  922. transSky: 0.5,
  923. shadowBlur: 0.5,
  924. normalSmooth: 0.5
  925. },
  926. this.skinParams.fresnelIntegral = 1 / 3.14159 * (1 - 0.5 * this.skinParams.fresnelColor[3]),
  927. this.skinParams.transIntegral = 1 / 3.14159 * (1 - 0.5 * this.skinParams.transColor[3]),
  928. this.skinParams.transSky *= 1.25,
  929. this.skinParams.transIntegral *= 1.25,
  930. this.extrasTexCoordRanges.subdermisTex || d.push("#define SKIN_NO_SUBDERMIS_TEX"),
  931. this.extrasTexCoordRanges.translucencyTex || d.push("#define SKIN_NO_TRANSLUCENCY_TEX"),
  932. this.extrasTexCoordRanges.fuzzTex || d.push("#define SKIN_NO_FUZZ_TEX"));
  933. c.aniso && (d.push("#define ANISO"),
  934. this.anisoParams = c.anisoParams || {
  935. strength: 1,
  936. tangent: [1, 0, 0],
  937. integral: 0.5
  938. },
  939. this.extrasTexCoordRanges.anisoTex || d.push("#define ANISO_NO_DIR_TEX"));
  940. c.microfiber && (d.push("#define MICROFIBER"),
  941. this.microfiberParams = c.microfiberParams || {
  942. fresnelColor: [0.2, 0.2, 0.2, 0.5],
  943. fresnelOcc: 1,
  944. fresnelGlossMask: 1
  945. },
  946. this.microfiberParams.fresnelIntegral = 1 / 3.14159 * (1 - 0.5 * this.microfiberParams.fresnelColor[3]),
  947. this.extrasTexCoordRanges.fuzzTex || d.push("#define MICROFIBER_NO_FUZZ_TEX"));
  948. c.vertexColor && (d.push("#define VERTEX_COLOR"),
  949. c.vertexColorsRGB && d.push("#define VERTEX_COLOR_SRGB"),
  950. c.vertexColorAlpha && d.push("#define VERTEX_COLOR_ALPHA"));
  951. this.horizonSmoothing = c.horizonSmoothing || 0;
  952. 0 < this.horizonSmoothing && d.push("#define HORIZON_SMOOTHING");
  953. c.unlitDiffuse && d.push("#define DIFFUSE_UNLIT");
  954. this.extrasTexCoordRanges.emissiveTex && d.push("#define EMISSIVE");
  955. c.tangentOrthogonalize && d.push("#define TSPACE_ORTHOGONALIZE");
  956. c.tangentNormalize && d.push("#define TSPACE_RENORMALIZE");
  957. c.tangentGenerateBitangent && d.push("#define TSPACE_COMPUTE_BITANGENT");
  958. this.shader = a.shaderCache.fromURLs("matvert.glsl", "matfrag.glsl", d);
  959. // d.push("#define STRIPVIEW");
  960. // this.stripShader = a.shaderCache.fromURLs("matvert.glsl", "matfrag.glsl", d);
  961. // this.wireShader = a.shaderCache.fromURLs("wirevert.glsl", "wirefrag.glsl");
  962. this.blend === b.alpha && (this.prepassShader = a.shaderCache.fromURLs("alphaprepassvert.glsl", "alphaprepassfrag.glsl"))
  963. }
  964. Material.prototype.bind = function(a) {
  965. if (!this.complete())
  966. return !1;
  967. var b = a.view, c = a.lights, d = a.sky, e = a.shadow, f = /* a.stripData.active() ? this.stripShader : */this.shader, g = this.skinParams, h = this.anisoParams, k = this.microfiberParams, l, m = this.gl, n = f.params, r = this.textures, p = f.samplers;
  968. f.bind();
  969. this.blend();
  970. m.uniform1f(n.uAlbedoStrength, this.strength.albedo);//改
  971. m.uniform1f(n.uReflecStrength, this.strength.reflectivity);//改
  972. m.uniform1f(n.uNormalStrength, this.strength.normal);//改
  973. m.uniform1f(n.uAlphaStrength, this.strength.alpha);//改
  974. m.uniform1f(n.uGlossStrength, this.strength.gloss);//改
  975. m.uniform1f(n.uModelBright, d.modelBright);//改
  976. b.viewProjectionMatrix2 = Matrix.mul(Matrix.empty(), b.projectionMatrix, b.viewMatrix2); //必须要再乘一次,因为aaresolve时重新计算了projectionMatrix
  977. m.uniformMatrix4fv(n.uModelViewProjectionMatrix, !1, b.viewProjectionMatrix2);
  978. m.uniformMatrix4fv(n.uSkyMatrix, !1, c.matrix);
  979. q = Matrix.mulPoint(Vect.empty(), c.matrix, b.transform2[12], b.transform2[13], b.transform2[14]);//改
  980. m.uniform3f(n.uCameraPosition, q[0], q[1], q[2]);
  981. m.uniform3fv(n.uFresnel, this.fresnel);
  982. m.uniform1f(n.uAlphaTest, this.alphaTest);
  983. m.uniform1f(n.uHorizonOcclude, this.horizonOcclude);
  984. m.uniform1f(n.uHorizonSmoothing, this.horizonSmoothing);
  985. m.uniform4fv(n.uDiffuseCoefficients, d.diffuseCoefficients);
  986. if (0 < c.count && (m.uniform4fv(n.uLightPositions, c.positionBuffer),
  987. m.uniform3fv(n.uLightDirections, c.directionBuffer),
  988. m.uniform3fv(n.uLightColors, c.colors),
  989. m.uniform3fv(n.uLightParams, c.parameters),
  990. m.uniform3fv(n.uLightSpot, c.spot),
  991. q = 0.392699 * a.postRender.sampleIndex,
  992. m.uniform2f(n.uShadowKernelRotation, 0.5 * Math.cos(q), 0.5 * Math.sin(q)),
  993. 0 < c.shadowCount)) {
  994. var q = e.depthTextures[0].desc.width
  995. , u = e.depthTextures[0].desc.height;
  996. m.uniform4f(n.uShadowMapSize, q, u, 1 / q, 1 / u);
  997. m.uniformMatrix4fv(n.uShadowMatrices, !1, c.finalTransformBuffer);
  998. m.uniform4fv(n.uShadowTexelPadProjections, c.shadowTexelPadProjections);
  999. e.bindDepthTexture(p.tDepth0, 0);
  1000. e.bindDepthTexture(p.tDepth1, 1);
  1001. e.bindDepthTexture(p.tDepth2, 2)
  1002. }
  1003. g && (m.uniform3fv(n.uSubdermisColor, g.subdermisColor),
  1004. m.uniform4fv(n.uTransColor, g.transColor),
  1005. m.uniform4fv(n.uFresnelColor, g.fresnelColor),
  1006. m.uniform1f(n.uFresnelOcc, g.fresnelOcc),
  1007. m.uniform1f(n.uFresnelGlossMask, g.fresnelGlossMask),
  1008. m.uniform1f(n.uFresnelIntegral, g.fresnelIntegral),
  1009. m.uniform1f(n.uTransIntegral, g.transIntegral),
  1010. m.uniform1f(n.uTransSky, g.transSky),
  1011. m.uniform1f(n.uSkinShadowBlur, 8 * Math.min(g.shadowBlur, 1)),
  1012. m.uniform1f(n.uNormalSmooth, g.normalSmooth),
  1013. (l = this.extrasTexCoordRanges.subdermisTex) && m.uniform4fv(n.uTexRangeSubdermis, l),
  1014. (l = this.extrasTexCoordRanges.translucencyTex) && m.uniform4fv(n.uTexRangeTranslucency, l),
  1015. (l = this.extrasTexCoordRanges.fuzzTex) && m.uniform4fv(n.uTexRangeFuzz, l));
  1016. k && (m.uniform4fv(n.uFresnelColor, k.fresnelColor),
  1017. m.uniform1f(n.uFresnelOcc, k.fresnelOcc),
  1018. m.uniform1f(n.uFresnelGlossMask, k.fresnelGlossMask),
  1019. m.uniform1f(n.uFresnelIntegral, k.fresnelIntegral),
  1020. (l = this.extrasTexCoordRanges.fuzzTex) && m.uniform4fv(n.uTexRangeFuzz, l));
  1021. h && (m.uniform3fv(n.uAnisoTangent, h.tangent),
  1022. m.uniform1f(n.uAnisoStrength, h.strength),
  1023. m.uniform1f(n.uAnisoIntegral, h.integral),
  1024. (l = this.extrasTexCoordRanges.anisoTex) && m.uniform4fv(n.uTexRangeAniso, l));
  1025. if (l = this.extrasTexCoordRanges.emissiveTex)
  1026. m.uniform4fv(n.uTexRangeEmissive, l),
  1027. m.uniform1f(n.uEmissiveScale, this.emissiveIntensity);
  1028. r.albedo.bind(p.tAlbedo);
  1029. r.reflectivity.bind(p.tReflectivity);
  1030. r.normal.bind(p.tNormal);
  1031. r.extras.bind(p.tExtras);
  1032. d.specularTexture.bind(p.tSkySpecular);
  1033. // f === this.stripShader && (m.uniform1fv(n.uStrips, a.stripData.strips),
  1034. //m.uniform2f(n.uStripRes, 2 / b.size[0], 2 / b.size[1]));
  1035. return !0
  1036. }
  1037. ;
  1038. Material.prototype.bindAlphaPrepass = function(a) {
  1039. if (!this.complete() || !this.prepassShader)
  1040. return !1;
  1041. var b = this.gl
  1042. , c = this.prepassShader.params
  1043. , d = this.prepassShader.samplers;
  1044. this.prepassShader.bind();
  1045. b.uniform1f(c.uAlphaStrength, this.strength.alpha);//改
  1046. b.uniformMatrix4fv(c.uModelViewProjectionMatrix, !1, a.view.viewProjectionMatrix2); //改
  1047. this.textures.albedo.bind(d.tAlbedo);
  1048. return !0
  1049. }
  1050. ;
  1051. /* Material.prototype.bindWire = function(a) {
  1052. if (!this.complete())
  1053. return !1;
  1054. var b = this.gl
  1055. , c = this.wireShader.params
  1056. , d = a.view;
  1057. b.enable(b.BLEND);
  1058. b.blendFunc(b.SRC_ALPHA, b.ONE_MINUS_SRC_ALPHA);
  1059. b.depthMask(!1);
  1060. this.wireShader.bind();
  1061. // var e = Matrix.mul(Matrix.empty(), d.projectionMatrix, d.viewMatrix);
  1062. // b.uniformMatrix4fv(c.uModelViewProjectionMatrix, !1, e);
  1063. b.uniformMatrix4fv(c.uModelViewProjectionMatrix, !1, d.viewProjectionMatrix2); //改
  1064. b.uniform4f(c.uStripParams, 2 / d.size[0], 2 / d.size[1], a.stripData.strips[3], a.stripData.strips[4]);
  1065. return !0
  1066. }
  1067. ; */
  1068. Material.prototype.complete = function() {
  1069. return /* this.wireShader.complete() && */this.shader.complete() /* && this.stripShader.complete() */ && (!this.prepassShader || this.prepassShader.complete()) && this.textures.albedo.complete() && this.textures.reflectivity.complete() && this.textures.normal.complete()
  1070. }
  1071. ;
  1072. var Matrix = {
  1073. type: Float32Array,
  1074. create: function(a, b, c, d, e, f, g, h, k, l, m, n, r, p, q, u) {
  1075. var s = new Matrix.type(16);
  1076. s[0] = a;
  1077. s[4] = b;
  1078. s[8] = c;
  1079. s[12] = d;
  1080. s[1] = e;
  1081. s[5] = f;
  1082. s[9] = g;
  1083. s[13] = h;
  1084. s[2] = k;
  1085. s[6] = l;
  1086. s[10] = m;
  1087. s[14] = n;
  1088. s[3] = r;
  1089. s[7] = p;
  1090. s[11] = q;
  1091. s[15] = u;
  1092. return s
  1093. },
  1094. empty: function() {
  1095. return new Matrix.type(16)
  1096. },
  1097. identity: function() {
  1098. var a = new Matrix.type(16);
  1099. a[0] = 1;
  1100. a[4] = 0;
  1101. a[8] = 0;
  1102. a[12] = 0;
  1103. a[1] = 0;
  1104. a[5] = 1;
  1105. a[9] = 0;
  1106. a[13] = 0;
  1107. a[2] = 0;
  1108. a[6] = 0;
  1109. a[10] = 1;
  1110. a[14] = 0;
  1111. a[3] = 0;
  1112. a[7] = 0;
  1113. a[11] = 0;
  1114. a[15] = 1;
  1115. return a
  1116. },
  1117. set: function(a, b, c, d, e, f, g, h, k, l, m, n, r, p, q, u, s) {
  1118. a[0] = b;
  1119. a[4] = c;
  1120. a[8] = d;
  1121. a[12] = e;
  1122. a[1] = f;
  1123. a[5] = g;
  1124. a[9] = h;
  1125. a[13] = k;
  1126. a[2] = l;
  1127. a[6] = m;
  1128. a[10] = n;
  1129. a[14] = r;
  1130. a[3] = p;
  1131. a[7] = q;
  1132. a[11] = u;
  1133. a[15] = s
  1134. },
  1135. translation: function(a, b, c, d) {
  1136. Matrix.set(a, 1, 0, 0, b, 0, 1, 0, c, 0, 0, 1, d, 0, 0, 0, 1);
  1137. return a
  1138. },
  1139. rotation: function(a, b, c) {
  1140. a[0] = 1;
  1141. a[4] = 0;
  1142. a[8] = 0;
  1143. a[12] = 0;
  1144. a[1] = 0;
  1145. a[5] = 1;
  1146. a[9] = 0;
  1147. a[13] = 0;
  1148. a[2] = 0;
  1149. a[6] = 0;
  1150. a[10] = 1;
  1151. a[14] = 0;
  1152. a[3] = 0;
  1153. a[7] = 0;
  1154. a[11] = 0;
  1155. a[15] = 1;
  1156. var d = 0.0174532925 * b;
  1157. b = Math.sin(d);
  1158. d = Math.cos(d);
  1159. switch (c) {
  1160. case 0:
  1161. a[5] = d;
  1162. a[9] = -b;
  1163. a[6] = b;
  1164. a[10] = d;
  1165. break;
  1166. case 1:
  1167. a[0] = d;
  1168. a[8] = b;
  1169. a[2] = -b;
  1170. a[10] = d;
  1171. break;
  1172. case 2:
  1173. a[0] = d,
  1174. a[4] = -b,
  1175. a[1] = b,
  1176. a[5] = d
  1177. }
  1178. return a
  1179. },
  1180. mul: function(a, b, c) {
  1181. var d = b[0]
  1182. , e = b[1]
  1183. , f = b[2]
  1184. , g = b[3]
  1185. , h = b[4]
  1186. , k = b[5]
  1187. , l = b[6]
  1188. , m = b[7]
  1189. , n = b[8]
  1190. , r = b[9]
  1191. , p = b[10]
  1192. , q = b[11]
  1193. , u = b[12]
  1194. , s = b[13]
  1195. , z = b[14];
  1196. b = b[15];
  1197. var t = c[0]
  1198. , v = c[1]
  1199. , w = c[2]
  1200. , x = c[3];
  1201. a[0] = t * d + v * h + w * n + x * u;
  1202. a[1] = t * e + v * k + w * r + x * s;
  1203. a[2] = t * f + v * l + w * p + x * z;
  1204. a[3] = t * g + v * m + w * q + x * b;
  1205. t = c[4];
  1206. v = c[5];
  1207. w = c[6];
  1208. x = c[7];
  1209. a[4] = t * d + v * h + w * n + x * u;
  1210. a[5] = t * e + v * k + w * r + x * s;
  1211. a[6] = t * f + v * l + w * p + x * z;
  1212. a[7] = t * g + v * m + w * q + x * b;
  1213. t = c[8];
  1214. v = c[9];
  1215. w = c[10];
  1216. x = c[11];
  1217. a[8] = t * d + v * h + w * n + x * u;
  1218. a[9] = t * e + v * k + w * r + x * s;
  1219. a[10] = t * f + v * l + w * p + x * z;
  1220. a[11] = t * g + v * m + w * q + x * b;
  1221. t = c[12];
  1222. v = c[13];
  1223. w = c[14];
  1224. x = c[15];
  1225. a[12] = t * d + v * h + w * n + x * u;
  1226. a[13] = t * e + v * k + w * r + x * s;
  1227. a[14] = t * f + v * l + w * p + x * z;
  1228. a[15] = t * g + v * m + w * q + x * b;
  1229. return a
  1230. },
  1231. invert: function(a, b) {
  1232. var c = b[0]
  1233. , d = b[1]
  1234. , e = b[2]
  1235. , f = b[3]
  1236. , g = b[4]
  1237. , h = b[5]
  1238. , k = b[6]
  1239. , l = b[7]
  1240. , m = b[8]
  1241. , n = b[9]
  1242. , r = b[10]
  1243. , p = b[11]
  1244. , q = b[12]
  1245. , u = b[13]
  1246. , s = b[14]
  1247. , z = b[15]
  1248. , t = c * h - d * g
  1249. , v = c * k - e * g
  1250. , w = c * l - f * g
  1251. , x = d * k - e * h
  1252. , A = d * l - f * h
  1253. , B = e * l - f * k
  1254. , C = m * u - n * q
  1255. , D = m * s - r * q
  1256. , E = m * z - p * q
  1257. , F = n * s - r * u
  1258. , G = n * z - p * u
  1259. , H = r * z - p * s
  1260. , y = t * H - v * G + w * F + x * E - A * D + B * C;
  1261. if (!y)
  1262. return null ;
  1263. y = 1 / y;
  1264. a[0] = (h * H - k * G + l * F) * y;
  1265. a[1] = (e * G - d * H - f * F) * y;
  1266. a[2] = (u * B - s * A + z * x) * y;
  1267. a[3] = (r * A - n * B - p * x) * y;
  1268. a[4] = (k * E - g * H - l * D) * y;
  1269. a[5] = (c * H - e * E + f * D) * y;
  1270. a[6] = (s * w - q * B - z * v) * y;
  1271. a[7] = (m * B - r * w + p * v) * y;
  1272. a[8] = (g * G - h * E + l * C) * y;
  1273. a[9] = (d * E - c * G - f * C) * y;
  1274. a[10] = (q * A - u * w + z * t) * y;
  1275. a[11] = (n * w - m * A - p * t) * y;
  1276. a[12] = (h * D - g * F - k * C) * y;
  1277. a[13] = (c * F - d * D + e * C) * y;
  1278. a[14] = (u * v - q * x - s * t) * y;
  1279. a[15] = (m * x - n * v + r * t) * y;
  1280. return a
  1281. },
  1282. transpose: function(a, b) {
  1283. a[0] = b[0];
  1284. a[4] = b[1];
  1285. a[8] = b[2];
  1286. a[12] = b[3];
  1287. a[1] = b[4];
  1288. a[5] = b[5];
  1289. a[9] = b[6];
  1290. a[13] = b[7];
  1291. a[2] = b[8];
  1292. a[6] = b[9];
  1293. a[10] = b[10];
  1294. a[14] = b[11];
  1295. a[3] = b[12];
  1296. a[7] = b[13];
  1297. a[11] = b[14];
  1298. a[15] = b[15];
  1299. return a
  1300. },
  1301. mul4: function(a, b, c, d, e, f) {
  1302. a[0] = b[0] * c + b[4] * d + b[8] * e + b[12] * f;
  1303. a[1] = b[1] * c + b[5] * d + b[9] * e + b[13] * f;
  1304. a[2] = b[2] * c + b[6] * d + b[10] * e + b[14] * f;
  1305. a[3] = b[3] * c + b[7] * d + b[11] * e + b[15] * f;
  1306. return a
  1307. },
  1308. mulPoint: function(a, b, c, d, e) {
  1309. a[0] = b[0] * c + b[4] * d + b[8] * e + b[12];
  1310. a[1] = b[1] * c + b[5] * d + b[9] * e + b[13];
  1311. a[2] = b[2] * c + b[6] * d + b[10] * e + b[14];
  1312. return a
  1313. },
  1314. mulVec: function(a, b, c, d, e) {
  1315. a[0] = b[0] * c + b[4] * d + b[8] * e;
  1316. a[1] = b[1] * c + b[5] * d + b[9] * e;
  1317. a[2] = b[2] * c + b[6] * d + b[10] * e;
  1318. return a
  1319. },
  1320. perspective: function(a, b, c, d, e, f) {
  1321. f = f || 0;
  1322. b = 1 / Math.tan(0.00872664625 * b);
  1323. a[0] = b / c;
  1324. a[1] = a[2] = a[3] = 0;
  1325. a[5] = b;
  1326. a[4] = a[6] = a[7] = 0;
  1327. a[8] = a[9] = 0;
  1328. a[10] = (e + d) / (d - e) - 3.0518044E-5 * f;
  1329. a[11] = -1;
  1330. a[14] = 2 * e * d / (d - e);
  1331. a[12] = a[13] = a[15] = 0;
  1332. return a
  1333. },
  1334. perspectiveInfinite: function(a, b, c, d, e) {
  1335. e = e || 0;
  1336. b = 1 / Math.tan(0.00872664625 * b);
  1337. a[0] = b / c;
  1338. a[1] = a[2] = a[3] = 0;
  1339. a[5] = b;
  1340. a[4] = a[6] = a[7] = 0;
  1341. a[8] = a[9] = 0;
  1342. a[10] = a[11] = -1 - 3.0518044E-5 * e;
  1343. a[14] = -2 * d;
  1344. a[12] = a[13] = a[15] = 0;
  1345. return a
  1346. },
  1347. ortho: function(a, b, c, d, e, f, g, h) {
  1348. var k = 1 / (c - b)
  1349. , l = 1 / (e - d)
  1350. , m = 1 / (g - f);
  1351. a[0] = k + k;
  1352. a[1] = a[2] = a[3] = 0;
  1353. a[5] = l + l;
  1354. a[4] = a[6] = a[7] = 0;
  1355. a[12] = -(c + b) * k;
  1356. a[13] = -(e + d) * l;
  1357. a[10] = -(m + m) - 3.0518044E-5 * (h || 0);
  1358. a[14] = -(g + f) * m;
  1359. a[8] = a[9] = a[11] = 0;
  1360. a[15] = 1;
  1361. return a
  1362. },
  1363. lookAt: function(a, b, c, d) {
  1364. var e = a.subarray(0, 3)
  1365. , f = a.subarray(4, 7)
  1366. , g = a.subarray(8, 11);
  1367. Vect.sub(g, b, c);
  1368. Vect.cross(e, d, g);
  1369. Vect.normalize(g, g);
  1370. Vect.normalize(e, e);
  1371. Vect.cross(f, g, e);
  1372. 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)
  1373. },
  1374. copy: function(a, b) {
  1375. for (var c = 0; 16 > c; ++c)
  1376. a[c] = b[c]
  1377. },
  1378. copyToBuffer: function(a, b, c) {
  1379. for (var d = 0; 16 > d; ++d)
  1380. a[b + d] = c[d]
  1381. }
  1382. };
  1383. function Mesh(a, b, c) {
  1384. this.gl = a;
  1385. this.desc = b;
  1386. this.stride = 32;
  1387. if (this.vertexColor = b.vertexColor)
  1388. this.stride += 4;
  1389. c = new ByteStream(c.data);
  1390. this.indexCount = b.indexCount;
  1391. this.indexTypeSize = b.indexTypeSize;
  1392. this.indexType = 4 == this.indexTypeSize ? a.UNSIGNED_INT : a.UNSIGNED_SHORT;
  1393. this.indexBuffer = a.createBuffer();
  1394. a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
  1395. var d = c.readBytes(this.indexCount * this.indexTypeSize);
  1396. a.bufferData(a.ELEMENT_ARRAY_BUFFER, d, a.STATIC_DRAW);
  1397. this.wireCount = b.wireCount;
  1398. this.wireBuffer = a.createBuffer();
  1399. a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, this.wireBuffer);
  1400. d = c.readBytes(this.wireCount * this.indexTypeSize);
  1401. a.bufferData(a.ELEMENT_ARRAY_BUFFER, d, a.STATIC_DRAW);
  1402. a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, null );
  1403. this.vertexCount = b.vertexCount;
  1404. this.vertexBuffer = a.createBuffer();
  1405. a.bindBuffer(a.ARRAY_BUFFER, this.vertexBuffer);
  1406. c = c.readBytes(this.vertexCount * this.stride);
  1407. a.bufferData(a.ARRAY_BUFFER, c, a.STATIC_DRAW);
  1408. a.bindBuffer(a.ARRAY_BUFFER, null );
  1409. this.bounds = void 0 === b.minBound || void 0 === b.maxBound ? {
  1410. min: Vect.create(-10, -10, -10, 1),
  1411. max: Vect.create(10, 10, -0, 1)
  1412. } : {
  1413. min: Vect.create(b.minBound[0], b.minBound[1], b.minBound[2], 1),
  1414. max: Vect.create(b.maxBound[0], b.maxBound[1], b.maxBound[2], 1)
  1415. };
  1416. 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])
  1417. }
  1418. ;function MeshRenderable(a, b, c) {
  1419. this.mesh = a;
  1420. this.gl = this.mesh.gl;
  1421. this.indexOffset = b.firstIndex * a.indexTypeSize;
  1422. this.indexCount = b.indexCount;
  1423. this.wireIndexOffset = b.firstWireIndex * a.indexTypeSize;
  1424. this.wireIndexCount = b.wireIndexCount;
  1425. this.material = c
  1426. }
  1427. MeshRenderable.prototype.draw = function(a) {
  1428. var b = this.gl;
  1429. if (this.material.bind(a)) {
  1430. a = this.material.shader.attribs;
  1431. var c = this.mesh.stride;
  1432. this.mesh.desc.cullBackFaces ? (b.enable(b.CULL_FACE),
  1433. b.cullFace(b.BACK)) : b.disable(b.CULL_FACE);
  1434. b.bindBuffer(b.ELEMENT_ARRAY_BUFFER, this.mesh.indexBuffer);
  1435. b.bindBuffer(b.ARRAY_BUFFER, this.mesh.vertexBuffer);
  1436. b.enableVertexAttribArray(a.vPosition);
  1437. b.enableVertexAttribArray(a.vTexCoord);
  1438. b.enableVertexAttribArray(a.vTangent);
  1439. b.enableVertexAttribArray(a.vBitangent);
  1440. b.enableVertexAttribArray(a.vNormal);
  1441. var d = this.mesh.vertexColor && void 0 !== a.vColor;
  1442. d && b.enableVertexAttribArray(a.vColor);
  1443. var e = 0;
  1444. b.vertexAttribPointer(a.vPosition, 3, b.FLOAT, !1, c, e);
  1445. e += 12;
  1446. b.vertexAttribPointer(a.vTexCoord, 2, b.FLOAT, !1, c, e);
  1447. e += 8;
  1448. b.vertexAttribPointer(a.vTangent, 2, b.UNSIGNED_SHORT, !0, c, e);
  1449. e += 4;
  1450. b.vertexAttribPointer(a.vBitangent, 2, b.UNSIGNED_SHORT, !0, c, e);
  1451. e += 4;
  1452. b.vertexAttribPointer(a.vNormal, 2, b.UNSIGNED_SHORT, !0, c, e);
  1453. d && b.vertexAttribPointer(a.vColor, 4, b.UNSIGNED_BYTE, !0, c, e + 4);
  1454. b.drawElements(b.TRIANGLES, this.indexCount, this.mesh.indexType, this.indexOffset);
  1455. b.disableVertexAttribArray(a.vPosition);
  1456. b.disableVertexAttribArray(a.vTexCoord);
  1457. b.disableVertexAttribArray(a.vTangent);
  1458. b.disableVertexAttribArray(a.vBitangent);
  1459. b.disableVertexAttribArray(a.vNormal);
  1460. d && b.disableVertexAttribArray(a.vColor)
  1461. }
  1462. }
  1463. ;
  1464. MeshRenderable.prototype.drawShadow = function(a) {
  1465. var b = this.gl;
  1466. this.mesh.desc.cullBackFaces ? (b.enable(b.CULL_FACE),
  1467. b.cullFace(b.BACK)) : b.disable(b.CULL_FACE);
  1468. b.bindBuffer(b.ELEMENT_ARRAY_BUFFER, this.mesh.indexBuffer);
  1469. b.bindBuffer(b.ARRAY_BUFFER, this.mesh.vertexBuffer);
  1470. b.enableVertexAttribArray(a);
  1471. b.vertexAttribPointer(a, 3, b.FLOAT, !1, this.mesh.stride, 0);
  1472. b.drawElements(b.TRIANGLES, this.indexCount, this.mesh.indexType, this.indexOffset);
  1473. b.disableVertexAttribArray(a)
  1474. }
  1475. ;
  1476. MeshRenderable.prototype.drawAlphaShadow = function(a, b) {
  1477. var c = this.gl;
  1478. this.mesh.desc.cullBackFaces ? (c.enable(c.CULL_FACE),
  1479. c.cullFace(c.BACK)) : c.disable(c.CULL_FACE);
  1480. c.bindBuffer(c.ELEMENT_ARRAY_BUFFER, this.mesh.indexBuffer);
  1481. c.bindBuffer(c.ARRAY_BUFFER, this.mesh.vertexBuffer);
  1482. c.enableVertexAttribArray(a);
  1483. c.enableVertexAttribArray(b);
  1484. c.vertexAttribPointer(a, 3, c.FLOAT, !1, this.mesh.stride, 0);
  1485. c.vertexAttribPointer(b, 2, c.FLOAT, !1, this.mesh.stride, 12);
  1486. c.drawElements(c.TRIANGLES, this.indexCount, this.mesh.indexType, this.indexOffset);
  1487. c.disableVertexAttribArray(a);
  1488. c.disableVertexAttribArray(b)
  1489. }
  1490. ;
  1491. MeshRenderable.prototype.drawAlphaPrepass = function(a) {
  1492. var b = this.gl;
  1493. if (this.material.bindAlphaPrepass(a)) {
  1494. a = this.material.prepassShader.attribs;
  1495. var c = this.mesh.stride;
  1496. this.mesh.desc.cullBackFaces ? (b.enable(b.CULL_FACE),
  1497. b.cullFace(b.BACK)) : b.disable(b.CULL_FACE);
  1498. b.bindBuffer(b.ELEMENT_ARRAY_BUFFER, this.mesh.indexBuffer);
  1499. b.bindBuffer(b.ARRAY_BUFFER, this.mesh.vertexBuffer);
  1500. b.enableVertexAttribArray(a.vPosition);
  1501. b.enableVertexAttribArray(a.vTexCoord);
  1502. b.vertexAttribPointer(a.vPosition, 3, b.FLOAT, !1, c, 0);
  1503. b.vertexAttribPointer(a.vTexCoord, 2, b.FLOAT, !1, c, 12);
  1504. b.drawElements(b.TRIANGLES, this.indexCount, this.mesh.indexType, this.indexOffset);
  1505. b.disableVertexAttribArray(a.vPosition);
  1506. b.disableVertexAttribArray(a.vTexCoord)
  1507. }
  1508. }
  1509. ;
  1510. /* MeshRenderable.prototype.drawWire = function() {
  1511. var a = this.material.wireShader.attribs
  1512. , b = this.gl;
  1513. b.enableVertexAttribArray(a.vPosition);
  1514. b.bindBuffer(b.ELEMENT_ARRAY_BUFFER, this.mesh.wireBuffer);
  1515. b.bindBuffer(b.ARRAY_BUFFER, this.mesh.vertexBuffer);
  1516. b.vertexAttribPointer(a.vPosition, 3, b.FLOAT, !1, this.mesh.stride, 0);
  1517. b.drawElements(b.LINES, this.wireIndexCount, this.mesh.indexType, this.wireIndexOffset);
  1518. b.disableVertexAttribArray(a.vPosition)
  1519. }
  1520. ; */
  1521. MeshRenderable.prototype.complete = function() {
  1522. return this.material.complete()
  1523. }
  1524. ;
  1525. var Network = {
  1526. fetchImage: function(a, b, c) {
  1527. var d = new Image;
  1528. d.onload = function() {
  1529. 0 < d.width && 0 < d.height ? b(d) : c && c()
  1530. }
  1531. ;
  1532. c && (req.onerror = function() {
  1533. c()
  1534. }
  1535. );
  1536. d.src = a
  1537. },
  1538. fetchText: function(a, b, c, d) {
  1539. var e = new XMLHttpRequest;
  1540. e.open("GET", a, !0);
  1541. e.onload = function() {
  1542. 200 == e.status ? b(e.responseText) : c && c()
  1543. }
  1544. ;
  1545. c && (e.onerror = function() {
  1546. c()
  1547. }
  1548. );
  1549. d && (e.onprogress = function(a) {
  1550. d(a.loaded, a.total)
  1551. }
  1552. );
  1553. e.send()
  1554. },
  1555. fetchBinary: function(a, b, c, d) {
  1556. var e = new XMLHttpRequest;
  1557. e.open("GET", a, !0);
  1558. e.responseType = "arraybuffer";
  1559. e.onload = function() {
  1560. 200 == e.status ? b(e.response) : c && c()
  1561. }
  1562. ;
  1563. c && (e.onerror = function() {
  1564. c()
  1565. }
  1566. );
  1567. d && (e.onprogress = function(a) {
  1568. d(a.loaded, a.total)
  1569. }
  1570. );
  1571. e.send()
  1572. },
  1573. fetchBinaryIncremental: function(a, b, c, d) {
  1574. var e = new XMLHttpRequest;
  1575. e.open("HEAD", a, !0);
  1576. e.onload = function() {
  1577. if (200 == e.status) {
  1578. var f = e.getResponseHeader("Accept-Ranges");
  1579. if (f && "none" != f) {
  1580. var g = e.getResponseHeader("Content-Length") | 0
  1581. , h = function(c, e) {
  1582. var f = new XMLHttpRequest;
  1583. f.open("GET", a, !0);
  1584. f.setRequestHeader("Range", "bytes=" + c + "-" + e);
  1585. f.responseType = "arraybuffer";
  1586. f.onload = function() {
  1587. (206 == f.status || 200 == f.status) && b(f.response) && e < g && (c += d,
  1588. e += d,
  1589. e = e < g - 1 ? e : g - 1,
  1590. h(c, e))
  1591. }
  1592. ;
  1593. f.send()
  1594. }
  1595. ;
  1596. h(0, d - 1)
  1597. } else
  1598. c && c()
  1599. } else
  1600. c && c()
  1601. }
  1602. ;
  1603. c && (req.onerror = function() {
  1604. c()
  1605. }
  1606. );
  1607. e.send()
  1608. }
  1609. };
  1610. function PostRender(a, b, c) {
  1611. this.gl = a;
  1612. this.desc = b;
  1613. b = [];
  1614. 0 != this.desc.sharpen && b.push("#define SHARPEN");
  1615. (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");
  1616. 0 != this.desc.vignette[3] && b.push("#define VIGNETTE");
  1617. 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");
  1618. 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");
  1619. 0 != this.desc.grain && b.push("#define GRAIN");
  1620. 1 == this.desc.toneMap ? b.push("#define REINHARD") : 2 == this.desc.toneMap && b.push("#define HEJL");
  1621. this.desc.colorLUT && b.push("#define COLOR_LUT");
  1622. this.sampleCount = 1;
  1623. this.sampleIndex = 0;
  1624. c && (c = [], //改
  1625. this.gl.hints.mobile ? (this.sampleCount = 3,
  1626. this.sampleOffsets = [[-0.4375, -0.5625], [0.625, -0.25], [-0.1875, 0.5]]) : (c.push("#define HIGHQ"),
  1627. this.sampleCount = 16,
  1628. this.sampleOffsets = [//逆时针
  1629. [-1, 0], [-0.866, -0.5], [-0.7071, -0.7071], [-0.5, -0.866],
  1630. [0, -1], [0.5, -0.866], [ 0.7071, -0.7071], [0.866, -0.5],
  1631. [1, 0], [ 0.866, 0.5], [ 0.7071, 0.7071], [ 0.5, 0.866],
  1632. [0, 1], [-0.5, 0.866], [-0.7071, 0.7071], [-0.866, 0.5]
  1633. ]),
  1634. /* this.sampleOffsets = [ //先对称斜四个角,再对称正四个角,再其他
  1635. [-0.7071, -0.7071],[ 0.7071, 0.7071], [ 0.7071, -0.7071], [-0.7071, 0.7071],
  1636. [-1, 0],[1, 0],[0, -1],[0, 1],
  1637. [-0.866, -0.5],[ 0.866, 0.5], [-0.5, 0.866],[0.5, -0.866],
  1638. [-0.5, -0.866], [ 0.5, 0.866], [-0.866, 0.5], [0.866, -0.5]
  1639. ]), */
  1640. this.aaResolve = a.shaderCache.fromURLs("postvert.glsl", "aaresolve.glsl", c)
  1641. );
  1642. this.samplesValid = new Uint8Array(16);
  1643. this.shader = a.shaderCache.fromURLs("postvert.glsl", "postfrag.glsl", b);
  1644. this.plainShader = a.shaderCache.fromURLs("postvert.glsl", "postfrag.glsl", ["#define SINGLECOLOR"]);//改
  1645. this.fullscreenTriangle = a.createBuffer();
  1646. a.bindBuffer(a.ARRAY_BUFFER, this.fullscreenTriangle);
  1647. c = new Float32Array([0, 0, 2, 0, 0, 2]);
  1648. a.bufferData(a.ARRAY_BUFFER, c, a.STATIC_DRAW);
  1649. a.bindBuffer(a.ARRAY_BUFFER, null );
  1650. if (this.useBloom) {
  1651. this.bloomTextures = [];
  1652. this.bloomTargets = [];
  1653. for (c = 0; 2 > c; ++c)
  1654. b = {
  1655. width: 256,
  1656. height: 256,
  1657. clamp: !0
  1658. },
  1659. this.bloomTextures[c] = new Texture(a,b),
  1660. this.bloomTextures[c].loadArray(null , a.RGBA, a.ext.textureHalf && a.ext.textureHalfLinear ? a.ext.textureHalf.HALF_FLOAT_OES : a.UNSIGNED_BYTE),
  1661. this.bloomTargets[c] = new Framebuffer(a,{
  1662. width: b.width,
  1663. height: b.height,
  1664. color0: this.bloomTextures[c]
  1665. });
  1666. for (this.bloomSamples = 64; this.bloomSamples + 16 >= a.limits.fragmentUniforms; )
  1667. this.bloomSamples /= 2;
  1668. this.bloomShader = a.shaderCache.fromURLs("postvert.glsl", "bloom.glsl", ["#define BLOOM_SAMPLES " + this.bloomSamples])
  1669. }
  1670. a = new Uint8Array(16384);
  1671. for (c = 0; 16384 > c; c++) {
  1672. b = 255 * Math.random();
  1673. var d = 255 * Math.random();
  1674. a[c] = 0.5 * (b + d)
  1675. }
  1676. this.noiseTexture = new Texture(this.gl,{
  1677. width: 128,
  1678. height: 128
  1679. });
  1680. this.noiseTexture.loadArray(a, this.gl.LUMINANCE);
  1681. this.desc.colorLUT && (a = this.desc.colorLUT,
  1682. this.colorLUT = new Texture(this.gl,{
  1683. width: a.length / 3 | 0,
  1684. height: 1,
  1685. clamp: !0
  1686. }),
  1687. this.colorLUT.loadArray(new Uint8Array(a), this.gl.RGB));
  1688. this.blackTexture = new Texture(this.gl,{
  1689. width: 1,
  1690. height: 1
  1691. });
  1692. this.blackTexture.loadArray(new Uint8Array([0, 0, 0, 0]));
  1693. this.bloomResult = this.blackTexture
  1694. }
  1695. PostRender.prototype.prepareBloom = function(a) {
  1696. if (this.useBloom && this.bloomShader.bind()) {
  1697. var b = [];
  1698. this.bloomTargets[0].bind();
  1699. a.bind(this.bloomShader.samplers.tInput);
  1700. for (var c = 0, d = 0; d < this.bloomSamples; ++d) {
  1701. var e = -1 + 2 * d / (this.bloomSamples - 1), f;
  1702. f = 4 * e;
  1703. f = Math.exp(-0.5 * f * f / 1) / 2.50662827463;
  1704. c += f;
  1705. b[4 * d + 0] = e * this.desc.bloomSize;
  1706. b[4 * d + 1] = 0;
  1707. b[4 * d + 2] = f;
  1708. b[4 * d + 3] = 0
  1709. }
  1710. for (d = 0; d < this.bloomSamples; ++d)
  1711. b[4 * d + 2] /= c;
  1712. this.gl.uniform4fv(this.bloomShader.params.uKernel, b);
  1713. this.fillScreen(this.bloomShader.attribs.vCoord);
  1714. this.bloomTargets[1].bind();
  1715. this.bloomTextures[0].bind(this.bloomShader.samplers.tInput);
  1716. for (d = 0; d < this.bloomSamples; ++d)
  1717. c = b[4 * d + 0],
  1718. c *= a.desc.width / a.desc.height,
  1719. b[4 * d + 0] = 0,
  1720. b[4 * d + 1] = c;
  1721. this.gl.uniform4fv(this.bloomShader.params.uKernel, b);
  1722. this.fillScreen(this.bloomShader.attribs.vCoord);
  1723. this.bloomResult = this.bloomTextures[1]
  1724. } else
  1725. this.bloomResult = this.blackTexture
  1726. }
  1727. ;
  1728. PostRender.prototype.computeParams = function(a, b) {
  1729. var c = this.desc
  1730. , d = {};
  1731. d.scale = [c.contrast[0] * c.contrast[3], c.contrast[1] * c.contrast[3], c.contrast[2] * c.contrast[3]];
  1732. d.bias = [c.bias[0] * c.bias[3], c.bias[1] * c.bias[3], c.bias[2] * c.bias[3]];
  1733. 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]];
  1734. var e = [c.brightness[0] * c.brightness[3], c.brightness[1] * c.brightness[3], c.brightness[2] * c.brightness[3]];
  1735. d.scale = [d.scale[0] * e[0], d.scale[1] * e[1], d.scale[2] * e[2]];
  1736. d.bias = [d.bias[0] * e[0], d.bias[1] * e[1], d.bias[2] * e[2]];
  1737. d.saturation = [c.saturation[0] * c.saturation[3], c.saturation[1] * c.saturation[3], c.saturation[2] * c.saturation[3]];
  1738. d.bloomColor = [c.bloomColor[0] * c.bloomColor[3], c.bloomColor[1] * c.bloomColor[3], c.bloomColor[2] * c.bloomColor[3]];
  1739. d.sharpen = [c.sharpen, 0.25 * c.sharpen, c.sharpenLimit];
  1740. d.sharpenKernel = [1 / a, 0, 0, 1 / b];
  1741. e = a > b ? a : b;
  1742. d.vignetteAspect = [a / e, b / e, 0.5 * a / e, 0.5 * b / e];
  1743. 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];
  1744. var e = 1 / this.noiseTexture.desc.width
  1745. , f = 1 / this.noiseTexture.desc.height
  1746. , g = 1 - c.grainSharpness;
  1747. d.grainCoord = [e * a, f * b, 0.5 * g * e, 0.5 * g * f];
  1748. d.grainScaleBias = [2 * c.grain, -c.grain];
  1749. return d
  1750. }
  1751. ;
  1752. PostRender.prototype.present = function(a, b, c, d) {
  1753. 1 < this.sampleCount && this.allocAABuffers(a.desc.width, a.desc.height);
  1754. d || this.prepareBloom(a);
  1755. var e = d ? this.plainShader : this.shader;
  1756. if (e.bind()) {
  1757. d = this.gl;
  1758. var f = e.samplers
  1759. , g = e.params
  1760. , h = this.computeParams(b, c);
  1761. a.bind(f.tInput);
  1762. this.bloomResult.bind(f.tBloom);
  1763. this.noiseTexture.bind(f.tGrain);
  1764. this.colorLUT && this.colorLUT.bind(f.tLUT);
  1765. d.uniform3fv(g.uScale, h.scale);
  1766. d.uniform3fv(g.uBias, h.bias);
  1767. d.uniform3fv(g.uSaturation, h.saturation);
  1768. d.uniform4fv(g.uSharpenKernel, h.sharpenKernel);
  1769. d.uniform3fv(g.uSharpness, h.sharpen);
  1770. d.uniform3fv(g.uBloomColor, h.bloomColor);
  1771. d.uniform4fv(g.uVignetteAspect, h.vignetteAspect);
  1772. d.uniform4fv(g.uVignette, h.vignette);
  1773. d.uniform4fv(g.uGrainCoord, h.grainCoord);
  1774. d.uniform2fv(g.uGrainScaleBias, h.grainScaleBias);
  1775. if (this.aaResolve) {
  1776. this.sampleFramebuffers[this.sampleIndex].bind();
  1777. this.fillScreen(e.attribs.vCoord);
  1778. this.samplesValid[this.sampleIndex] = 1;
  1779. Framebuffer.bindNone(d);
  1780. d.viewport(0, 0, b, c);
  1781. this.aaResolve.bind();
  1782. for (b = a = 0; b < this.sampleCount; ++b)
  1783. a += this.samplesValid[b],
  1784. this.sampleTextures[b].bind(this.aaResolve.samplers["tInput" + b]);
  1785. a = 1 / a;
  1786. d.uniformMatrix4fv(this.aaResolve.params.uSamplesValid, !1,[this.samplesValid[0] ? a : 0, this.samplesValid[1] ? a : 0, this.samplesValid[2] ? a : 0, this.samplesValid[3] ? a : 0,this.samplesValid[4] ? a : 0,this.samplesValid[5] ? a : 0,this.samplesValid[6] ? a : 0,this.samplesValid[7] ? a : 0,this.samplesValid[8] ? a : 0,this.samplesValid[9] ? a : 0,this.samplesValid[10] ? a : 0,this.samplesValid[11] ? a : 0,this.samplesValid[12] ? a : 0,this.samplesValid[13] ? a : 0,this.samplesValid[14] ? a : 0,this.samplesValid[15] ? a : 0]);
  1787. this.fillScreen(this.aaResolve.attribs.vCoord);
  1788. this.sampleIndex = (this.sampleIndex + 1) % this.sampleCount
  1789. } else
  1790. Framebuffer.bindNone(d),
  1791. d.viewport(0, 0, b, c),
  1792. this.fillScreen(e.attribs.vCoord)
  1793. }
  1794. }
  1795. ;
  1796. PostRender.prototype.allocAABuffers = function(a, b) {
  1797. if (void 0 === this.sampleTextures || this.sampleTextures[0].desc.width != a || this.sampleTextures[0].desc.height != b) {
  1798. this.sampleTextures = [];
  1799. this.sampleFramebuffers = [];
  1800. for (var c = 0; c < this.sampleCount; ++c) {
  1801. var d = new Texture(this.gl,{
  1802. width: a,
  1803. height: b,
  1804. nofilter: !0
  1805. });
  1806. d.loadArray();
  1807. this.sampleTextures.push(d);
  1808. this.sampleFramebuffers.push(new Framebuffer(this.gl,{
  1809. width: a,
  1810. height: b,
  1811. color0: d,
  1812. ignoreStatus: !0
  1813. }))
  1814. }
  1815. this.discardAAHistory()
  1816. }
  1817. }
  1818. ;
  1819. PostRender.prototype.adjustProjectionForSupersampling = function(a) {
  1820. if (1 < this.sampleCount) {
  1821. var b = this.sampleOffsets[this.sampleIndex][0] / a.size[0]
  1822. , c = this.sampleOffsets[this.sampleIndex][1] / a.size[1]
  1823. , b = Matrix.translation(Matrix.empty(), b, c, 0);
  1824. Matrix.mul(a.projectionMatrix, b, a.projectionMatrix)
  1825. }
  1826. }
  1827. ;
  1828. PostRender.prototype.discardAAHistory = function() {
  1829. for (var a = this.sampleIndex = 0; a < this.samplesValid.length; ++a)
  1830. this.samplesValid[a] = 0
  1831. }
  1832. ;
  1833. PostRender.prototype.fillScreen = function(a) {
  1834. var b = this.gl;
  1835. b.bindBuffer(b.ARRAY_BUFFER, this.fullscreenTriangle);
  1836. b.enableVertexAttribArray(a);
  1837. b.vertexAttribPointer(a, 2, b.FLOAT, !1, 0, 0);
  1838. b.drawArrays(b.TRIANGLES, 0, 3);
  1839. b.disableVertexAttribArray(a);
  1840. b.bindBuffer(b.ARRAY_BUFFER, null )
  1841. }
  1842. ;
  1843. function Scene(a) {
  1844. this.gl = a;
  1845. this.name = "untitled";
  1846. this.meshes = [];
  1847. this.meshRenderables = [];
  1848. this.materials = {};
  1849. this.nextView = this.sky = this.view = null ;
  1850. this.viewFade = 0;
  1851. this.shadow = this.stripData = this.lights = null
  1852. }
  1853. Scene.prototype.checkFailure = function(data){
  1854. var failure = "";
  1855. if(!data.meshes.length) failure+="mesh数量为0 ";
  1856. if(!data.materials.length) failure+="materials数量为0 ";
  1857. return failure;
  1858. }
  1859. Scene.prototype.load = function(a) {
  1860. var b = this.gl, c;
  1861. c = a.extract("scene.json");
  1862. if (void 0 !== c) {
  1863. //if (!a.checkSignature(c))
  1864. // return !1;
  1865. c = (new ByteStream(c.data)).asString();
  1866. if (null == c || 0 >= c.length)
  1867. return !1;
  1868. c = JSON.parse(c)
  1869. } else
  1870. return !1;
  1871. if(!(c.sky.backgroundColor instanceof Array)){//有可能是{0:..,1:..}的情况
  1872. c.sky.backgroundColor = [c.sky.backgroundColor[0],c.sky.backgroundColor[1],c.sky.backgroundColor[2],c.sky.backgroundColor[3]]
  1873. }
  1874. var failure = this.checkFailure(c);
  1875. this.metaData = c.metaData;
  1876. this.view = new View(c.mainCamera.view);
  1877. this.sky = new Sky(this.gl,a,c.sky);
  1878. this.lights = new Lights(c.lights,this.view);
  1879. this.materials = {};
  1880. for (var d in c.materials) {
  1881. var e = c.materials[d];
  1882. e.lightCount = this.lights.count;
  1883. e.shadowCount = this.lights.shadowCount;
  1884. this.materials[e.name] = new Material(this.gl,a,e)
  1885. }
  1886. if (c.meshes)
  1887. for (e = 0; e < c.meshes.length; ++e) {
  1888. d = c.meshes[e];
  1889. d = new Mesh(this.gl,d,a.extract(d.file));
  1890. this.meshes.push(d);
  1891. for (var f = 0; f < d.desc.subMeshes.length; ++f) {
  1892. var g = d.desc.subMeshes[f];
  1893. this.meshRenderables.push(new MeshRenderable(d,g,this.materials[g.material]))
  1894. }
  1895. }
  1896. this.bounds = new Bounds(this.meshes);
  1897. this.postRender = new PostRender(this.gl,c.mainCamera.post,!0);
  1898. this.shadow = new ShadowCollector(b,this.lights.shadowCount);
  1899. if(failure!="") return {failure:","+failure};
  1900. return !0
  1901. }
  1902. ;
  1903. Scene.prototype.update = function() {
  1904. this.lights.update(this.view, this.bounds)
  1905. }
  1906. ;
  1907. Scene.prototype.collectShadows = function(a) {
  1908. this.shadow.collect(this, a)
  1909. }
  1910. ;
  1911. Scene.prototype.draw = function() {
  1912. var a = this.gl;
  1913. this.sky.setClearColor();
  1914. a.clear(a.COLOR_BUFFER_BIT | a.DEPTH_BUFFER_BIT | a.STENCIL_BUFFER_BIT);
  1915. a.enable(a.DEPTH_TEST);
  1916. this.sky.draw(this);
  1917. for (var b = 0; b < this.meshRenderables.length; ++b)
  1918. this.meshRenderables[b].material.usesBlending || this.meshRenderables[b].draw(this);
  1919. a.enable(a.POLYGON_OFFSET_FILL);
  1920. a.polygonOffset(1, 1);
  1921. a.colorMask(!1, !1, !1, !1);
  1922. for (b = 0; b < this.meshRenderables.length; ++b)
  1923. this.meshRenderables[b].drawAlphaPrepass(this);
  1924. a.colorMask(!0, !0, !0, !0);
  1925. a.disable(a.POLYGON_OFFSET_FILL);
  1926. a.depthFunc(a.LEQUAL);
  1927. a.depthMask(!1);
  1928. for (b = 0; b < this.meshRenderables.length; ++b)
  1929. this.meshRenderables[b].material.usesBlending && this.meshRenderables[b].draw(this);
  1930. a.depthMask(!0);
  1931. a.depthFunc(a.LESS);
  1932. /* if (this.stripData.activeWireframe() && 0 < this.meshRenderables.length) {
  1933. this.meshRenderables[0].material.bindWire(this);
  1934. for (b = 0; b < this.meshRenderables.length; ++b)
  1935. this.meshRenderables[b].drawWire();
  1936. } */
  1937. a.depthMask(!0)
  1938. a.disable(a.BLEND)
  1939. }
  1940. ;
  1941. Scene.prototype.complete = function() {
  1942. if (!this.sky.complete() || !this.shadow.complete())
  1943. return !1;
  1944. for (var a = 0; a < this.meshRenderables.length; ++a)
  1945. if (!this.meshRenderables[a].complete())
  1946. return !1;
  1947. return !0
  1948. }
  1949. ;
  1950. function Shader(a) {
  1951. this.gl = a;
  1952. this.program = null ;
  1953. this.params = {};
  1954. this.samplers = {};
  1955. this.attribs = {}
  1956. }
  1957. Shader.prototype.build = function(a, b) {
  1958. var c = this.gl;
  1959. this.program = c.createProgram();
  1960. this.params = {};
  1961. this.samplers = {};
  1962. this.attribs = {};
  1963. var d = function(a) {
  1964. for (var b = "", c = a.indexOf("\n"), d = 0; -1 != c; )
  1965. d++,
  1966. b += d + ": ",
  1967. b += a.substring(0, c + 1),
  1968. a = a.substring(c + 1, a.length),
  1969. c = a.indexOf("\n");
  1970. console.log(b)
  1971. }
  1972. , e = c.createShader(c.VERTEX_SHADER);
  1973. c.shaderSource(e, a);
  1974. c.compileShader(e);
  1975. c.getShaderParameter(e, c.COMPILE_STATUS) || (console.log(c.getShaderInfoLog(e)),
  1976. fdage.verboseErrors && d(a));
  1977. c.attachShader(this.program, e);
  1978. e = c.createShader(c.FRAGMENT_SHADER);
  1979. c.shaderSource(e, b);
  1980. c.compileShader(e);
  1981. c.getShaderParameter(e, c.COMPILE_STATUS) || (console.log(c.getShaderInfoLog(e)),
  1982. fdage.verboseErrors && d(b));
  1983. c.attachShader(this.program, e);
  1984. c.linkProgram(this.program);
  1985. c.getProgramParameter(this.program, c.LINK_STATUS) || console.log(c.getProgramInfoLog(this.program));
  1986. for (var e = c.getProgramParameter(this.program, c.ACTIVE_UNIFORMS), f = 0, d = 0; d < e; ++d) {
  1987. var g = c.getActiveUniform(this.program, d)
  1988. , h = g.name
  1989. , k = h.indexOf("[");
  1990. 0 <= k && (h = h.substring(0, k));
  1991. k = c.getUniformLocation(this.program, g.name);
  1992. g.type == c.SAMPLER_2D || g.type == c.SAMPLER_CUBE ? this.samplers[h] = {
  1993. location: k,
  1994. unit: f++
  1995. } : this.params[h] = k
  1996. }
  1997. e = c.getProgramParameter(this.program, c.ACTIVE_ATTRIBUTES);
  1998. for (d = 0; d < e; ++d)
  1999. f = c.getActiveAttrib(this.program, d),
  2000. this.attribs[f.name] = c.getAttribLocation(this.program, f.name)
  2001. }
  2002. ;
  2003. Shader.prototype.bind = function() {
  2004. return this.program ? (this.gl.useProgram(this.program),
  2005. !0) : !1
  2006. }
  2007. ;
  2008. Shader.prototype.complete = function() {
  2009. return !!this.program
  2010. }
  2011. ;
  2012. function ShaderCache(a) {
  2013. this.gl = a;
  2014. this.cache = []
  2015. }
  2016. ShaderCache.prototype.fromURLs = function(a, b, c) {
  2017. var d = "";
  2018. if (c)
  2019. for (var e = 0; e < c.length; ++e)
  2020. d = c[e] + "\n" + d;
  2021. c = d + ":" + a + "|" + b;
  2022. e = this.cache[c];
  2023. if (void 0 !== e)
  2024. return e;
  2025. var f = new Shader(this.gl)
  2026. , g = null
  2027. , h = null
  2028. , k = function() {
  2029. null != g && null != h && f.build(g, h)
  2030. }
  2031. ;
  2032. this.fetch(a, function(a) {
  2033. g = d + a;
  2034. k()
  2035. });
  2036. this.fetch(b, function(a) {
  2037. h = d + a;
  2038. k()
  2039. });
  2040. return this.cache[c] = f
  2041. }
  2042. ;
  2043. ShaderCache.prototype.fetch = function(a, b) {
  2044. "undefined" != typeof ShaderTable ? void 0 !== ShaderTable[a] ? this.resolveIncludes(new String(ShaderTable[a]), b) : b("") : Network.fetchText("src/shader/" + a, function(a) {
  2045. this.resolveIncludes(a, b)
  2046. }
  2047. .bind(this), function() {
  2048. b("")
  2049. })
  2050. }
  2051. ;
  2052. ShaderCache.prototype.resolveIncludes = function(a, b) {
  2053. for (var c = [], d = !0, e = function(a, b, e, f, m) {
  2054. d = !0;
  2055. c.push({
  2056. offset: m,
  2057. path: b.slice(1, b.length - 1)
  2058. });
  2059. return ""
  2060. }
  2061. ; d; )
  2062. d = !1,
  2063. a = a.replace(/#include\s((<[^>]+>)|("[^"]+"))/, e);
  2064. if (0 < c.length)
  2065. for (var f = c.length, e = 0; e < c.length; ++e)
  2066. this.fetch(c[e].path, function(d) {
  2067. this.src = d;
  2068. if (0 >= --f) {
  2069. for (d = c.length - 1; 0 <= d; --d)
  2070. a = a.substring(0, c[d].offset) + c[d].src + a.substring(c[d].offset);
  2071. b(a)
  2072. }
  2073. }
  2074. .bind(c[e]));
  2075. else
  2076. b(a)
  2077. }
  2078. ;
  2079. function ShadowCollector(a, b) {
  2080. this.gl = a;
  2081. this.shadowCount = b;
  2082. this.desc = c;
  2083. this.shaderSolid = a.shaderCache.fromURLs("shadowvert.glsl", "shadowfrag.glsl");
  2084. this.shaderAlphaTest = a.shaderCache.fromURLs("shadowvert.glsl", "shadowfrag.glsl", ["#define ALPHA_TEST 1"]);
  2085. this.depthTextures = [];
  2086. this.depthTargets = [];
  2087. if (0 < this.shadowCount) {
  2088. var c = {
  2089. width: 2048,
  2090. height: 2048,
  2091. clamp: !0,
  2092. mipmap: !1,
  2093. nofilter: !0
  2094. };
  2095. a.hints.mobile && (c.width = c.height = 1536);
  2096. for (var d = {
  2097. width: c.width,
  2098. height: c.height,
  2099. depthBuffer: Framebuffer.createDepthBuffer(a, c.width, c.height)
  2100. }, e = a.RGB, f = a.UNSIGNED_BYTE, g = 0; g < this.shadowCount; ++g)
  2101. this.depthTextures[g] = new Texture(a,c),
  2102. this.depthTextures[g].loadArray(null , e, f),
  2103. d.color0 = this.depthTextures[g],
  2104. this.depthTargets[g] = new Framebuffer(a,d)
  2105. }
  2106. }
  2107. ShadowCollector.prototype.bindDepthTexture = function(a, b) {
  2108. this.shadowCount > b && this.depthTextures[b].bind(a)
  2109. }
  2110. ;
  2111. ShadowCollector.prototype.collect = function(a, b) {
  2112. var c = this.gl
  2113. , d = a.lights
  2114. , e = d.shadowCount
  2115. , f = d.modelViewBuffer
  2116. , g = d.projectionBuffer
  2117. , h = d.matrix;
  2118. if (!(0 >= e)) {
  2119. for (var k = Matrix.empty(), l = !1, m = 0; m < e; ++m)
  2120. if (d.shadowsNeedUpdate[m]) {
  2121. d.shadowsNeedUpdate[m] = 0;
  2122. l = !0;
  2123. Matrix.mul(k, f.subarray(16 * m, 16 * (m + 1)), h);
  2124. Matrix.mul(k, g.subarray(16 * m, 16 * (m + 1)), k);
  2125. this.depthTargets[m].bind();
  2126. c.clearColor(1, 1, 1, 1);
  2127. c.clear(c.COLOR_BUFFER_BIT | c.DEPTH_BUFFER_BIT);
  2128. var n = this.shaderSolid;
  2129. n.bind();
  2130. c.uniformMatrix4fv(n.params.uViewProjection, !1, k);
  2131. for (var r = 0; r < a.meshRenderables.length; ++r) {
  2132. var p = a.meshRenderables[r]
  2133. , q = p.material;
  2134. p.mesh.desc.castShadows && q.castShadows && (0 < q.shadowAlphaTest || p.drawShadow(n.attribs.vPosition))
  2135. }
  2136. n = this.shaderAlphaTest;
  2137. n.bind();
  2138. c.uniformMatrix4fv(n.params.uViewProjection, !1, k);
  2139. for (r = 0; r < a.meshRenderables.length; ++r)
  2140. p = a.meshRenderables[r],
  2141. q = p.material,
  2142. p.mesh.desc.castShadows && q.castShadows && 0 < q.shadowAlphaTest && (q.textures.albedo.bind(n.samplers.tAlbedo),
  2143. p.drawAlphaShadow(n.attribs.vPosition, n.attribs.vTexCoord))
  2144. }
  2145. l && (b.bind(),
  2146. c.enable(c.CULL_FACE),
  2147. c.cullFace(c.BACK))
  2148. }
  2149. }
  2150. ;
  2151. ShadowCollector.prototype.complete = function() {
  2152. return this.shaderSolid.complete() && this.shaderAlphaTest.complete()
  2153. }
  2154. ;
  2155. function Sky(a, b, c) {
  2156. this.gl = a;
  2157. var d = b.extract("sky.dat") || b.extract("sky.png");
  2158. if (void 0 !== d) {
  2159. this.specularTexture = new Texture(a,{
  2160. width: 256,
  2161. height: 2048,
  2162. clamp: !0
  2163. });
  2164. b = d.data;
  2165. for (var d = d.data.length, e = d / 4, f = new Uint8Array(d), g = 0, h = 0; g < d; ++h)
  2166. f[g++] = b[h + 2 * e],
  2167. f[g++] = b[h + e],
  2168. f[g++] = b[h],
  2169. f[g++] = b[h + 3 * e];
  2170. this.specularTexture.loadArray(f)
  2171. }
  2172. this.diffuseCoefficients = new Float32Array(c.diffuseCoefficients);
  2173. this.modelBright = (c.modelBright!==void 0 ? c.modelBright : 1)
  2174. this.backgroundMode = c.backgroundMode || 0;
  2175. this.backgroundBrightness = c.backgroundBrightness || 1;
  2176. this.backgroundColor = new Float32Array(c.backgroundColor);
  2177. if (1 <= this.backgroundMode)
  2178. if (this.backgroundShader = a.shaderCache.fromURLs("skyvert.glsl", 3 == this.backgroundMode ? "skySH.glsl" : "sky.glsl", ["#define SKYMODE " + this.backgroundMode]),
  2179. this.vertexBuffer = a.createBuffer(),
  2180. a.bindBuffer(a.ARRAY_BUFFER, this.vertexBuffer),
  2181. c = 1 / 256,
  2182. b = 0.5 / 256,
  2183. d = 2.8 * b,
  2184. e = 0.5 * b,
  2185. 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]),
  2186. a.bufferData(a.ARRAY_BUFFER, c, a.STATIC_DRAW),
  2187. a.bindBuffer(a.ARRAY_BUFFER, null ),
  2188. this.indexBuffer = a.createBuffer(),
  2189. a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, this.indexBuffer),
  2190. 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]),
  2191. this.skyIndexCount = c.length,
  2192. a.bufferData(a.ELEMENT_ARRAY_BUFFER, c, a.STATIC_DRAW),
  2193. a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, null ),
  2194. 3 == this.backgroundMode)
  2195. for (this.backgroundCoefficients = new Float32Array(this.diffuseCoefficients),
  2196. g = 0; g < this.backgroundCoefficients.length; ++g)
  2197. this.backgroundCoefficients[g] *= this.backgroundBrightness;
  2198. else {
  2199. this.backgroundTexture = new Texture(a,{
  2200. width: 256,
  2201. height: 256,
  2202. clamp: !0
  2203. });
  2204. c = !1;
  2205. var k;
  2206. a.ext.textureHalf && a.ext.textureHalfLinear && (this.backgroundTexture.loadArray(null , a.RGB, a.ext.textureHalf.HALF_FLOAT_OES),
  2207. k = new Framebuffer(a,{
  2208. color0: this.backgroundTexture
  2209. }),
  2210. c = k.valid);
  2211. !c && a.ext.textureFloat && a.ext.textureFloatLinear && !a.hints.mobile && (this.backgroundTexture.loadArray(null , a.RGB, a.FLOAT),
  2212. k = new Framebuffer(a,{
  2213. color0: this.backgroundTexture
  2214. }),
  2215. c = k.valid);
  2216. c || (this.backgroundTexture.loadArray(),
  2217. k = new Framebuffer(a,{
  2218. color0: this.backgroundTexture
  2219. }));
  2220. k.bind();
  2221. k = new Shader(a);
  2222. 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);}");
  2223. k.bind();
  2224. a.uniform1f(k.params.b, 7 * Math.sqrt(this.backgroundBrightness));
  2225. this.specularTexture.bind(k.samplers.tex);
  2226. c = a.createBuffer();
  2227. a.bindBuffer(a.ARRAY_BUFFER, c);
  2228. c = new Float32Array([-1, -1, 0.5, 1, 3, -1, 0.5, 1, -1, 3, 0.5, 1]);
  2229. a.bufferData(a.ARRAY_BUFFER, c, a.STATIC_DRAW);
  2230. a.enableVertexAttribArray(k.attribs.p);
  2231. a.vertexAttribPointer(k.attribs.p, 4, a.FLOAT, !1, 0, 0);
  2232. a.drawArrays(a.TRIANGLES, 0, 3);
  2233. a.disableVertexAttribArray(k.attribs.p)
  2234. }
  2235. }
  2236. Sky.prototype.setClearColor = function() {
  2237. if(fdage.backgroundColor){
  2238. var a = fdage.backgroundColor;
  2239. this.gl.clearColor(a[0], a[1], a[2], 1);
  2240. }
  2241. else if (fdage.transparentBackground)
  2242. this.gl.clearColor(0, 0, 0, 0);
  2243. else if (1 > this.backgroundMode) {
  2244. var a = this.backgroundColor;
  2245. this.gl.clearColor(a[0], a[1], a[2], 1)
  2246. } else
  2247. this.gl.clearColor(0.0582, 0.06772, 0.07805, 1)
  2248. }
  2249. ;
  2250. Sky.prototype.draw = function(a) {
  2251. if (1 > this.backgroundMode || fdage.backgroundColor)
  2252. return !1;
  2253. if (this.complete()) {
  2254. var b = this.gl
  2255. , c = this.backgroundShader
  2256. , d = a.view
  2257. , e = a.lights.invMatrix;
  2258. c.bind();
  2259. b.uniformMatrix4fv(c.params.uInverseSkyMatrix, !1, e);
  2260. b.uniformMatrix4fv(c.params.uViewProjection, !1, d.viewProjectionMatrix);
  2261. 3 == this.backgroundMode ? b.uniform4fv(c.params.uSkyCoefficients, this.backgroundCoefficients) : this.backgroundTexture.bind(c.samplers.tSkyTexture);
  2262. a = 1.01;
  2263. b.uniform1f(c.params.uAlpha, a);
  2264. b.bindBuffer(b.ARRAY_BUFFER, this.vertexBuffer);
  2265. b.enableVertexAttribArray(c.attribs.vPosition);
  2266. b.vertexAttribPointer(c.attribs.vPosition, 3, b.FLOAT, !1, 20, 0);
  2267. b.enableVertexAttribArray(c.attribs.vTexCoord);
  2268. b.vertexAttribPointer(c.attribs.vTexCoord, 2, b.FLOAT, !1, 20, 12);
  2269. b.bindBuffer(b.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
  2270. 1 > a && (b.enable(b.BLEND),
  2271. b.blendFunc(b.SRC_ALPHA, b.ONE_MINUS_SRC_ALPHA));
  2272. b.depthMask(!1);
  2273. b.disable(b.DEPTH_TEST);
  2274. b.drawElements(b.TRIANGLES, this.skyIndexCount, b.UNSIGNED_SHORT, 0);
  2275. b.enable(b.DEPTH_TEST);
  2276. b.depthMask(!0);
  2277. 1 > a && b.disable(b.BLEND);
  2278. b.disableVertexAttribArray(c.attribs.vPosition);
  2279. b.disableVertexAttribArray(c.attribs.vTexCoord)
  2280. }
  2281. }
  2282. ;
  2283. Sky.prototype.complete = function() {
  2284. return this.backgroundShader && !this.backgroundShader.complete() ? !1 : this.specularTexture.complete()
  2285. }
  2286. ;
  2287. function Texture(a, b) {
  2288. this.gl = a;
  2289. this.type = a.TEXTURE_2D;
  2290. this.id = null ;
  2291. b = b || {};
  2292. this.desc = {
  2293. width: b.width || 1,
  2294. height: b.height || 1,
  2295. mipmap: b.mipmap,
  2296. clamp: b.clamp,
  2297. aniso: b.aniso,
  2298. nofilter: b.nofilter
  2299. }
  2300. }
  2301. Texture.prototype.loadImage = function(a, b) {
  2302. var c = this.gl;
  2303. a && a.width && a.height && (this.desc.width = a.width,
  2304. this.desc.height = a.height);
  2305. this.id = c.createTexture();
  2306. c.bindTexture(this.type, this.id);
  2307. c.pixelStorei(c.UNPACK_FLIP_Y_WEBGL, !0);
  2308. c.texImage2D(this.type, 0, b || c.RGBA, b || c.RGBA, c.UNSIGNED_BYTE, a);
  2309. this.setParams();
  2310. c.bindTexture(this.type, null )
  2311. }
  2312. ;
  2313. Texture.prototype.loadArray = function(a, b, c) {
  2314. var d = this.gl;
  2315. this.id = d.createTexture();
  2316. d.bindTexture(this.type, this.id);
  2317. d.pixelStorei(d.UNPACK_FLIP_Y_WEBGL, !0);
  2318. d.texImage2D(this.type, 0, b || d.RGBA, this.desc.width, this.desc.height, 0, b || d.RGBA, c || d.UNSIGNED_BYTE, a || null );
  2319. this.setParams();
  2320. d.bindTexture(this.type, null )
  2321. }
  2322. ;
  2323. Texture.prototype.setParams = function() {
  2324. var a = this.gl
  2325. , b = function(a) {
  2326. return 0 < a && 0 == (a & a - 1)
  2327. }
  2328. ;
  2329. b(this.desc.width) && b(this.desc.height) || (this.desc.clamp = !0,
  2330. this.desc.mipmap = !1);
  2331. b = !this.desc.nofilter;
  2332. this.desc.mipmap ? (a.generateMipmap(this.type),
  2333. 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);
  2334. a.texParameteri(this.type, a.TEXTURE_MAG_FILTER, b ? a.LINEAR : a.NEAREST);
  2335. this.desc.clamp && (a.texParameteri(this.type, a.TEXTURE_WRAP_S, a.CLAMP_TO_EDGE),
  2336. a.texParameteri(this.type, a.TEXTURE_WRAP_T, a.CLAMP_TO_EDGE));
  2337. this.desc.aniso && a.ext.textureAniso && a.texParameteri(this.type, a.ext.textureAniso.TEXTURE_MAX_ANISOTROPY_EXT, this.desc.aniso)
  2338. }
  2339. ;
  2340. Texture.prototype.rebuildMips = function() {
  2341. this.desc.mipmap && (this.gl.bindTexture(this.type, this.id),
  2342. this.gl.generateMipmap(this.type))
  2343. }
  2344. ;
  2345. Texture.prototype.bind = function(a) {
  2346. if (a) {
  2347. var b = this.gl;
  2348. b.uniform1i(a.location, a.unit);
  2349. b.activeTexture(b.TEXTURE0 + a.unit);
  2350. b.bindTexture(this.type, this.id)
  2351. }
  2352. }
  2353. ;
  2354. Texture.prototype.destroy = function() {
  2355. this.gl.deleteTexture(this.id);
  2356. this.id = null
  2357. }
  2358. ;
  2359. Texture.prototype.complete = function() {
  2360. return !!this.id
  2361. }
  2362. ;
  2363. function TextureCache(a) {
  2364. this.gl = a;
  2365. this.cache = []
  2366. }
  2367. TextureCache.prototype.fromURL = function(a, b) {
  2368. var c = this.cache[a];
  2369. if (void 0 !== c)
  2370. return c;
  2371. var d = new Texture(this.gl,b);
  2372. Network.fetchImage(a, function(a) {
  2373. d.loadImage(a)
  2374. });
  2375. return this.cache[a] = d
  2376. }
  2377. ;
  2378. TextureCache.prototype.fromFile = function(a, b) {
  2379. if (!a)
  2380. return null ;
  2381. var c = this.cache[a.name];
  2382. if (void 0 !== c)
  2383. return c;
  2384. var d = new Texture(this.gl,b);
  2385. this.cache[a.name] = d;
  2386. TextureCache.parseFile(a, function(a) {
  2387. d.loadImage(a)
  2388. });
  2389. return d
  2390. }
  2391. ;
  2392. TextureCache.prototype.fromFilesMergeAlpha = function(a, b, c) {
  2393. if (!b)
  2394. return this.fromFile(a, c);
  2395. var d = a.name + "|" + b.name
  2396. , e = this.cache[d];
  2397. if (void 0 !== e)
  2398. return e;
  2399. var f = this.gl;
  2400. this.mergeShader || (this.mergeShader = new Shader(this.gl),
  2401. this.mergeShader.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 tRGB,tA; void main(){ gl_FragColor.xyz=texture2D(tRGB,c).xyz; gl_FragColor.w=texture2D(tA,c).x; }"),
  2402. this.mergeVerts = f.createBuffer(),
  2403. f.bindBuffer(f.ARRAY_BUFFER, this.mergeVerts),
  2404. e = new Float32Array([0, 0, 2, 0, 0, 2]),
  2405. f.bufferData(f.ARRAY_BUFFER, e, f.STATIC_DRAW),
  2406. f.bindBuffer(f.ARRAY_BUFFER, null ));
  2407. var g = new Texture(this.gl,c);
  2408. this.cache[d] = g;
  2409. var h = 0
  2410. , k = 0
  2411. , l = this.mergeShader
  2412. , m = this.mergeVerts
  2413. , n = function() {
  2414. if (h && k) {
  2415. var a = h.width > k.width ? h.width : k.width
  2416. , b = h.height > k.height ? h.height : k.height;
  2417. g.desc.width = a;
  2418. g.desc.height = b;
  2419. if (a <= f.limits.viewportSizes[0] && b <= f.limits.viewportSizes[1])
  2420. g.loadArray(null ),
  2421. (new Framebuffer(f,{
  2422. color0: g,
  2423. ignoreStatus: !0
  2424. })).bind(),
  2425. b = {
  2426. clamp: !0
  2427. },
  2428. a = new Texture(f,b),
  2429. a.loadImage(h, f.RGB),
  2430. b = new Texture(f,b),
  2431. b.loadImage(k, f.RGB),
  2432. l.bind(),
  2433. a.bind(l.samplers.tRGB),
  2434. b.bind(l.samplers.tA),
  2435. f.bindBuffer(f.ARRAY_BUFFER, m),
  2436. f.enableVertexAttribArray(l.attribs.pos),
  2437. f.vertexAttribPointer(l.attribs.pos, 2, f.FLOAT, !1, 0, 0),
  2438. f.drawArrays(f.TRIANGLES, 0, 3),
  2439. f.disableVertexAttribArray(l.attribs.pos),
  2440. f.bindBuffer(f.ARRAY_BUFFER, null ),
  2441. a.destroy(),
  2442. b.destroy(),
  2443. Framebuffer.bindNone(f),
  2444. g.rebuildMips();
  2445. else {
  2446. var c = document.createElement("canvas");
  2447. c.width = a;
  2448. c.height = b;
  2449. var d = c.getContext("2d");
  2450. d.drawImage(h, 0, 0);
  2451. c = d.getImageData(0, 0, a, b);
  2452. c = new Uint8Array(c.data.buffer,c.data.byteOffset,c.data.length);
  2453. d.drawImage(k, 0, 0);
  2454. d = d.getImageData(0, 0, a, b).data;
  2455. a = a * b * 4;
  2456. for (b = 0; b < a; b += 4)
  2457. c[b + 3] = d[b];
  2458. g.loadArray(c)
  2459. }
  2460. }
  2461. }
  2462. ;
  2463. TextureCache.parseFile(a, function(a) {
  2464. h = a;
  2465. n()
  2466. });
  2467. TextureCache.parseFile(b, function(a) {
  2468. k = a;
  2469. n()
  2470. });
  2471. return g
  2472. }
  2473. ;
  2474. TextureCache.parseFile = function(a, b, c) {
  2475. var d = c || new Image;
  2476. if ("undefined" != typeof URL && "undefined" != typeof URL.createObjectURL) {
  2477. a = new Blob([a.data],{
  2478. type: a.type
  2479. });
  2480. var e = URL.createObjectURL(a);
  2481. d.onload = function() {
  2482. URL.revokeObjectURL(e);
  2483. b && b(d)
  2484. }
  2485. ;
  2486. d.src = e
  2487. } else {
  2488. a = new Blob([a.data],{
  2489. type: a.type
  2490. });
  2491. var f = new FileReader;
  2492. f.onload = function(a) {
  2493. d.src = f.result
  2494. }
  2495. ;
  2496. d.onload = function() {
  2497. b && b(d)
  2498. }
  2499. ;
  2500. f.readAsDataURL(a)
  2501. }
  2502. }
  2503. ;
  2504. function UI(a) {
  2505. this.viewer = a;
  2506. this.stripData = a.stripData;
  2507. a = this.container = document.createElement("div");
  2508. a.id = "fdageUI";
  2509. a.style.position = "absolute";
  2510. a.style.overflow = "hidden";
  2511. a.style["-moz-user-select"] = "none";
  2512. a.style["-khtml-user-select"] = "none";
  2513. a.style["-webkit-user-select"] = "none";
  2514. a.style["-ms-user-select"] = "none";
  2515. this.viewer.domRoot.appendChild(a)
  2516. }
  2517. UI.prototype.setSize = function(a, b) {
  2518. this.container.width = a | 0;
  2519. this.container.height = b | 0;
  2520. this.container.style.width = a + "px";
  2521. this.container.style.height = b + "px"
  2522. }
  2523. ;
  2524. UI.prototype.clearView = function() {
  2525. for (; this.container.hasChildNodes(); )
  2526. this.container.removeChild(this.container.childNodes[0]);
  2527. delete this.progressBar;
  2528. delete this.thumbnail;
  2529. delete this.fadeThumbnail;
  2530. delete this.playButton;
  2531. delete this.helpOverlay
  2532. }
  2533. ;
  2534. UI.prototype.bindInput = function(a) {
  2535. a.onSingleTap.push(function(b, c) {
  2536. //this.stripData.selectedStrip != this.stripData.STRIP_NONE && (b = 2 / a.element.clientWidth * b - 1,
  2537. c = 1 - 2 / a.element.clientHeight * c,
  2538. // this.stripData.selectStrip(b, c),
  2539. // this.stripData.selectedStrip == this.stripData.STRIP_MENU && this.helpOverlay.active && this.helpOverlay.toggle(),
  2540. this.refreshUI(),
  2541. this.viewer.wake()
  2542. }
  2543. .bind(this));
  2544. a.onDoubleTap.push(function(a, c) {
  2545. this.viewer.scene.view.reset();
  2546. this.viewer.wake()
  2547. }
  2548. .bind(this))
  2549. }
  2550. ;
  2551. UI.sanitize = function(a) {
  2552. return a ? a.replace(/<|>|\(|\)|$|%|=/g, "") : a
  2553. }
  2554. ;
  2555. UI.sanitizeURL = function(a) {
  2556. return a ? 0 == a.indexOf("http://") || 0 == a.indexOf("https://") || 0 == a.indexOf("ftp://") ? encodeURI(a) : "http://" + encodeURI(a) : a
  2557. }
  2558. ;
  2559. UI.prototype.showFailure = function(info) {
  2560. this.container.innerHTML = "";
  2561. var errorCanvas = document.createElement('canvas');
  2562. var ra = this.container.width / this.container.height;
  2563. errorCanvas.width = 100;
  2564. errorCanvas.height = errorCanvas.height * ra | 0;
  2565. errorCanvas.style.position = "absolute";
  2566. errorCanvas.style['z-index'] = "-1";
  2567. errorCanvas.style.width = errorCanvas.style.height = "100%";
  2568. var a = errorCanvas.getContext("2d");
  2569. 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)
  2570. b.addColorStop(0, "rgb(0,0,0)");
  2571. b.addColorStop(1, "rgb(35,60,80)");//22,43,64 117,133,148
  2572. a.fillStyle = b;
  2573. a.fillRect(0, 0, errorCanvas.width, errorCanvas.height);
  2574. this.container.appendChild(errorCanvas);
  2575. var errorDiv = document.createElement('div');
  2576. dom.addClass(errorDiv,"error");
  2577. errorDiv.style["background-image"] = "url(images/errorBG.png)";
  2578. var msg = '<div class="errorInfo"><p style="font-size:1.5em; font-weight:lighter">转换模型时出错</p>'
  2579. +'<p style="font-size:1em;line-height:1.5em;margin-top:30px">(错误信息:'+(info || "") + ')</p>'
  2580. +'<p style="font-size:1.5em;font-weight:bold;margin-top">文件无效(ERROR)请检查您所上传的文件以确定其稳定性</p>'
  2581. +'<p style="font-size:0.8em;line-height:1.5em; margin-top:50px">请再次上传您的模型<br>或者您也可以联系我们的客服、或点击下面的视频教程链接获取跟详细的上传解说<br>4Dweb将全程为您提供最优质的模型展示</p></div>'
  2582. errorDiv.innerHTML = msg;
  2583. this.container.appendChild(errorDiv);
  2584. }
  2585. ;
  2586. UI.prototype.showPreview = function () {
  2587. this.clearView();
  2588. this.thumbnail = document.createElement("canvas");
  2589. var a = this.container.width / this.container.height;
  2590. this.thumbnail.height = 100;
  2591. this.thumbnail.width = this.thumbnail.height * a | 0;
  2592. this.thumbnail.style.width = this.thumbnail.style.height = "100%";
  2593. var a = this.thumbnail.getContext("2d"),
  2594. b = a.fillStyle = a.createRadialGradient(this.thumbnail.width / 2, this.thumbnail.height / 2, (this.thumbnail.width + this.thumbnail.height) / 2, this.thumbnail.width / 2, 0, 0);
  2595. b.addColorStop(0, "rgb(22,43,64)");
  2596. b.addColorStop(1, "rgb(117,133,148)");
  2597. a.fillStyle = b;
  2598. a.fillRect(0, 0, this.thumbnail.width, this.thumbnail.height);
  2599. this.container.appendChild(this.thumbnail);
  2600. fetchThumbnail(this.viewer.sceneURL, function (a) {
  2601. this.loadingImageURL || this.setThumbnail(a)
  2602. }
  2603. .bind(this))
  2604. };
  2605. ;
  2606. UI.prototype.setThumbnailURL = function(a) {
  2607. (this.loadingImageURL = a) && Network.fetchImage(this.loadingImageURL, this.setThumbnail.bind(this))
  2608. }
  2609. ;
  2610. UI.prototype.setThumbnail = function(a) {
  2611. if (this.thumbnail) {
  2612. var b = this.thumbnail.getContext("2d")
  2613. , c = this.thumbnail.width
  2614. , d = this.thumbnail.height
  2615. , e = d / a.height;
  2616. b.drawImage(a, (c - a.width * e) / 2, 0, a.width * e, d);
  2617. var f;
  2618. try {
  2619. f = b.getImageData(0, 0, c, d)
  2620. } catch (g) {
  2621. return
  2622. }
  2623. a = b.createImageData(c, d);
  2624. for (e = 0; 3 > e; ++e) {
  2625. for (var h = f.data, k = a.data, l = 0, m = 0; m < d; ++m)
  2626. for (var n = 0; n < c; ++n) {
  2627. for (var r = 0, p = 0, q = 0, u = -2; 2 >= u; ++u)
  2628. for (var s = m + u, s = 0 > s ? 0 : s >= d ? d - 1 : s, z = -2; 2 >= z; ++z)
  2629. var t = n + z
  2630. , t = 0 > t ? 0 : t >= c ? c - 1 : t
  2631. , t = 4 * (s * c + t)
  2632. , r = r + h[t]
  2633. , p = p + h[t + 1]
  2634. , q = q + h[t + 2];
  2635. k[l++] = r / 25;
  2636. k[l++] = p / 25;
  2637. k[l++] = q / 25;
  2638. k[l++] = 255
  2639. }
  2640. h = f;
  2641. f = a;
  2642. a = h
  2643. }
  2644. b.putImageData(f, 0, 0)
  2645. }
  2646. }
  2647. ;
  2648. UI.prototype.showActiveView = function () { //改
  2649. var a = this.thumbnail;
  2650. var d,g,e,f,h;
  2651. this.clearView();
  2652. a && (this.fadeThumbnail = a, this.fadeThumbnail.style.opacity = 1, this.container.appendChild(this.fadeThumbnail));
  2653. void 0 === fdage.largeUI && (fdage.largeUI = this.viewer.mobile);
  2654. 450 > this.container.width && (fdage.largeUI = !1);
  2655. var b = FullScreen.support(),
  2656. a = 1;
  2657. window.devicePixelRatio && (2 < window.devicePixelRatio ? a = 4 : 1 < window.devicePixelRatio && (a = 2));
  2658. fdage.largeUI && 4 > a && (a *= 2);
  2659. var c = fdage.largeUI ? 0.3 : 0.5;
  2660. this.helpOverlay = document.createElement("div");
  2661. this.helpOverlay.style.pointerEvents = "none";
  2662. this.container.appendChild(this.helpOverlay);
  2663. this.hideSigOnHelp = d = 450 > this.container.width;
  2664. this.hideSigOnStrips = !0;
  2665. g = [8, 8];
  2666. d ? (e = 198 + 2 * g[0], f = 258 + 2 * g[1]) : (e = 354 + 2 * g[0], f = 218 + 2 * g[1]);
  2667. h = document.createElement("div");
  2668. h.style.position = "absolute";
  2669. h.style.width = h.style.height = "100%";
  2670. this.helpOverlay.contents = h;
  2671. h = document.createElement("div");
  2672. h.style.position = "absolute";
  2673. h.style.right = fdage.largeUI ? "85px" : "45px";
  2674. h.style.top = fdage.largeUI ? "20px":"12px";
  2675. h.style.width = e + "px";
  2676. h.style.height = f + "px";
  2677. this.helpOverlay.contents.appendChild(h);
  2678. f = document.createElement("div");
  2679. f.style.position = "absolute";
  2680. f.style.width = "100%";
  2681. f.style.height = "100%";
  2682. f.style.backgroundColor = "black";
  2683. f.style.opacity = "0.65";
  2684. f.style.borderRadius = "16px";
  2685. h.appendChild(f);
  2686. f = document.createElement('a');
  2687. f.innerText = "x";
  2688. f['fontFamilly'] = "Open Sans";
  2689. f.style.position = "absolute";
  2690. f.style.color = "#FFFFFF";
  2691. f.style.fontWeight = "bolder";
  2692. f.style.backgroundColor =
  2693. "rgba(0,0,0,0.0)";
  2694. f.style.border = "0px";
  2695. f.style.outline = "0px";
  2696. f.style.fontSize = fdage.largeUI ? "16pt" : "10pt";
  2697. f.style.right = fdage.largeUI ? "-9px" : "4px";
  2698. f.style.top = fdage.largeUI ? "3px" : "7px";
  2699. f.style.width = f.style.height = fdage.largeUI ? "32px" : "16px";
  2700. f.style.pointerEvents = "auto";
  2701. f.style.cursor = "pointer";
  2702. f.onclick = function (a) {
  2703. this.helpOverlay.toggle();
  2704. this.refreshUI()
  2705. }
  2706. .bind(this, f);
  2707. h.appendChild(f);
  2708. f = document.createElement("center");//5个图标
  2709. f.style.position = "absolute";
  2710. f.style.left = g[0] - 4 + "px";
  2711. f.style.right =
  2712. g[0] + 4 + "px";
  2713. f.style.top = f.style.bottom = g[1] + "px";
  2714. f.style.paddingTop = "8px";
  2715. d || (f.style.paddingRight = "8px");
  2716. h.appendChild(f);
  2717. h = f;
  2718. g = (this.viewer.mobile ? "M" : "PC") + (2 < a ? 4 : 2) + "x.png";
  2719. f = document.createElement("img");
  2720. f.src = fdage.dataLocale + "helprotate" + g;
  2721. f.style.width = "66px";
  2722. f.style.height = "90px";
  2723. h.appendChild(f);
  2724. f = document.createElement("img");
  2725. f.src = fdage.dataLocale + "helpzoom" + g;
  2726. f.style.width = "66px";
  2727. f.style.height = "90px";
  2728. h.appendChild(f);
  2729. f = document.createElement("img");
  2730. f.src = fdage.dataLocale + "helpmove" +
  2731. g;
  2732. f.style.width = "66px";
  2733. f.style.height = "90px";
  2734. h.appendChild(f);
  2735. f = document.createElement("img");
  2736. f.src = fdage.dataLocale + "helpreset" + g;
  2737. f.style.width = "66px";
  2738. f.style.height = "90px";
  2739. h.appendChild(f);
  2740. f = document.createElement("img");
  2741. f.src = fdage.dataLocale + "helplights" + g;
  2742. f.style.position = "relative";
  2743. d || (f.style.left = "8px");
  2744. f.style.width = "66px";
  2745. f.style.height = "90px";
  2746. h.appendChild(f);
  2747. g = document.createElement("a");
  2748. //g.href = "http://www.fdage.co/viewer?utm_source=inapp&utm_medium=menu&utm_campaign=viewer";
  2749. g.href = "http://www.4dage.com";
  2750. g.target = "_blank";
  2751. g.style.pointerEvents = "auto";
  2752. h.appendChild(g);
  2753. f = document.createElement("img");
  2754. //f.src = fdage.dataLocale + "helptitle.png";
  2755. f.src = fdage.dataLocale + "logo2.png";
  2756. f.style.position = "absolute";
  2757. f.style.left = 0.5 * e - (d ? 65 : 116) + "px";
  2758. f.style.bottom = d ? "8px" : "12px";
  2759. f.style.width = d ? "116px" : "232px";
  2760. g.appendChild(f);
  2761. e = document.createElement("div");
  2762. e.style.position = "absolute";
  2763. e.style.left = 0;
  2764. e.style.right = d ? "30px" : "128px";
  2765. e.style.bottom = d ? "-4px" : "4px";
  2766. e.style.textAlign = "right";
  2767. e.style.fontFamilly = "Open Sans Arial";
  2768. h.appendChild(e);
  2769. d = document.createElement("font");
  2770. d.style.fontSize =
  2771. "9pt";
  2772. d.style.fontFamily = "Open Sans Arial";
  2773. e.appendChild(d);
  2774. /* g = document.createElement("a");
  2775. g.style.color = "rgb(255, 118, 118)";
  2776. g.style.textDecoration = "none";
  2777. g.style.pointerEvents = "auto";
  2778. g.innerHTML = "www.4dage.com";
  2779. g.href = "http://www.4dage.com"; //暂时写这个
  2780. g.target = "_blank"; */
  2781. /*g.onmouseover = function (a) {
  2782. this.style.textDecoration = "underline";
  2783. a.targetOpacity = 0.65
  2784. }
  2785. .bind(g, k);
  2786. g.onmouseout = function (a) {
  2787. this.style.textDecoration = "none";
  2788. a.targetOpacity = 0
  2789. }
  2790. .bind(g, k);*/
  2791. d.appendChild(g);
  2792. this.helpOverlay.active = !1;
  2793. this.helpOverlay.toggle = function (a) {
  2794. this.active ? this.removeChild(this.contents) : this.appendChild(this.contents);
  2795. this.active = !this.active
  2796. }
  2797. .bind(this.helpOverlay, this.viewer);
  2798. this.menuCluster = document.createElement("div");
  2799. this.menuCluster.style.position = "absolute";
  2800. this.menuCluster.style.right = fdage.largeUI ? "4px" : "0px";
  2801. this.menuCluster.style.top = fdage.largeUI ? "20px" : "10px";
  2802. fdage.largeUI ? (this.menuCluster.style.width = "72px", this.menuCluster.style.height = "64px") : (this.menuCluster.style.width =
  2803. "36px", this.menuCluster.style.height = "36px");
  2804. h = document.createElement("div");
  2805. h.style.left = h.style.top = "0px";
  2806. h.style.width = h.style.height = "100%";
  2807. this.menuCluster.contents = h;
  2808. this.menuCluster.appendChild(h);
  2809. d = 0;
  2810. e = function (a, name, cla, c, d, e) {//改
  2811. var f = document.createElement("div");
  2812. dom.addClass(f,"controlBtn");
  2813. dom.addClass(f,cla);
  2814. f.title = name;
  2815. if(fdage.largeUI)dom.addClass(f,"largeUI");
  2816. a.appendChild(f);
  2817. return f
  2818. };
  2819. b && (b = e(this.menuCluster.contents, "全屏","fullscreen", "fullscreen" + a + "x.png", d++, c), b.onclick = function (a) {
  2820. FullScreen.active() ? FullScreen.end() : FullScreen.begin(this.viewer.domRoot,
  2821. this.viewer.fullscreenChange.bind(this.viewer));
  2822. if(dom.hasClass(a,"full")){
  2823. dom.removeClass(a,"full");
  2824. }else{
  2825. dom.addClass(a,"full");
  2826. }
  2827. //a.style.opacity = c;
  2828. this.refreshUI()
  2829. }.bind(this, b));
  2830. /* b = e(this.menuCluster.contents, "Layer Views", "strips" + a + "x.png", d++, c);
  2831. b.onclick = function (a) {
  2832. this.stripData.toggleMenu();
  2833. this.helpOverlay.active && this.helpOverlay.toggle();
  2834. this.viewer.wake();
  2835. this.refreshUI()
  2836. }
  2837. .bind(this, b);*/
  2838. b = e(this.menuCluster.contents, "操作方式说明","tips", "help" + a + "x.png", d++, c);
  2839. b.onclick = function (a) {
  2840. //this.stripData.selectedStrip == this.stripData.STRIP_MENU && this.stripData.toggleMenu();
  2841. this.helpOverlay.toggle();
  2842. this.refreshUI()
  2843. }
  2844. .bind(this, b);
  2845. this.container.appendChild(this.menuCluster);
  2846. this.menuCluster.active = !0;
  2847. this.menuCluster.toggle = function () {
  2848. this.active ? this.removeChild(this.contents) : this.appendChild(this.contents);
  2849. this.active = !this.active
  2850. }
  2851. .bind(this.menuCluster);
  2852. 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 =
  2853. "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 () {
  2854. this.style.opacity = 1
  2855. }
  2856. .bind(f), f.onmouseout = function () {
  2857. this.style.opacity = 0.5
  2858. }
  2859. .bind(f), g.appendChild(f), this.hostLogo = g) : this.hostLogo = f, d = new XMLHttpRequest, d.open("HEAD", f.src, !0), d.onload = function () {
  2860. this.container.appendChild(this.hostLogo)
  2861. }
  2862. .bind(this), d.send());
  2863. this.sceneStats = document.createElement("text");
  2864. this.sceneStats.style.position =
  2865. "absolute";
  2866. this.sceneStats.style.left = "9px";
  2867. this.sceneStats.style.bottom = "8px";
  2868. this.sceneStats.style.color = "gray";
  2869. this.sceneStats.style.fontFamily = "Open Sans Arial";
  2870. this.sceneStats.style.fontSize = "75%";
  2871. for (d = b = a = 0; d < this.viewer.scene.meshes.length; ++d)
  2872. e = this.viewer.scene.meshes[d], a += e.indexCount / 3, b += e.vertexCount;
  2873. this.sceneStats.innerHTML = "Triangles: " + (a | 0).toLocaleString() + "<br>Vertices: " + (b | 0).toLocaleString();
  2874. fdage.showFrameTime && (this.frameTimer = document.createElement("text"), this.frameTimer.style.position =
  2875. "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);
  2876. //this.animateStrips()
  2877. };
  2878. ;
  2879. UI.prototype.refreshUI = function() {
  2880. if (this.sigCluster) {
  2881. var a = !1
  2882. , b = this.stripData.selectedStrip == this.stripData.STRIP_MENU;
  2883. this.hideSigOnStrips && (a = a || b);
  2884. this.hideSigOnHelp && (a = a || this.helpOverlay.active);
  2885. this.sigCluster.active == a && this.sigCluster.toggle()
  2886. }
  2887. }
  2888. ;
  2889. UI.prototype.signalLoadProgress = function(a, b) {
  2890. if (this.thumbnail) {
  2891. if (!this.progressBar) {
  2892. var c = document.createElement("div");
  2893. c.style.backgroundColor = "rgb(240,240,240)";
  2894. c.style.opacity = 0.9;
  2895. c.style.position = "absolute";
  2896. c.style.left = "20%";
  2897. c.style.width = "60%";
  2898. c.style.bottom = "30%";
  2899. c.style.height = "4px";
  2900. c.style["border-radius"] = "2px";
  2901. this.progressBar = document.createElement("div");
  2902. this.progressBar.style.backgroundColor = "#00ccff";
  2903. this.progressBar.style.position = "absolute";
  2904. this.progressBar.style.left = this.progressBar.style.bottom = "0px";
  2905. this.progressBar.style.height = "100%";
  2906. this.progressBar.style.width = "0px";
  2907. this.progressBar.style["border-radius"] = "2px";
  2908. c.appendChild(this.progressBar);
  2909. this.container.appendChild(c);
  2910. this.playButton && (this.container.removeChild(this.playButton),
  2911. delete this.playButton)
  2912. }
  2913. this.progressBar.style.width = 0 >= b ? (100 * a / (2097152 + a) | 0) + "%" : (100 * a / b | 0) + "%"
  2914. }
  2915. }
  2916. ;
  2917. UI.prototype.animating = function() {
  2918. return !!this.fadeThumbnail || !!this.frameTimer
  2919. }
  2920. ;
  2921. UI.prototype.animate = function() {
  2922. this.fadeThumbnail && (this.fadeThumbnailTimer = this.fadeThumbnailTimer || Date.now(),
  2923. this.fadeThumbnail.style.opacity = 1 - 0.0015 * (Date.now() - this.fadeThumbnailTimer),
  2924. 0.01 > this.fadeThumbnail.style.opacity && (this.container.removeChild(this.fadeThumbnail),
  2925. delete this.fadeThumbnail,
  2926. delete this.fadeThumbnailTimer));
  2927. if (this.frameTimer && (this.frameCount++,
  2928. 60 <= this.frameCount)) {
  2929. var a = (new Date).getTime();
  2930. if (void 0 !== this.frameTime) {
  2931. var b = (a - this.frameTime) / this.frameCount
  2932. , b = Math.floor(100 * b) / 100;
  2933. this.frameTimer.innerHTML = b + " ms";
  2934. this.frameTimer.style.color = 32 > b ? "green" : "red"
  2935. }
  2936. this.frameCount = 0;
  2937. this.frameTime = a
  2938. }
  2939. this.sceneStats && (a = !!this.sceneStats.parentElement,
  2940. b = this.stripData && this.stripData.active(),
  2941. a && !b ? (this.container.removeChild(this.sceneStats),
  2942. this.hostLogo && this.container.appendChild(this.hostLogo)) : !a && b && (this.container.appendChild(this.sceneStats),
  2943. this.hostLogo && this.container.removeChild(this.hostLogo)));
  2944. this.refreshUI();
  2945. }
  2946. ;
  2947. var Vect = {
  2948. type: Float32Array,
  2949. create: function(a, b, c, d) {
  2950. var e = new Vect.type(4);
  2951. e[0] = a;
  2952. e[1] = b;
  2953. e[2] = c;
  2954. e[3] = d;
  2955. return e
  2956. },
  2957. empty: function() {
  2958. return new Vect.type(4)
  2959. },
  2960. set: function(a, b, c, d, e) {
  2961. a[0] = b;
  2962. a[1] = c;
  2963. a[2] = d;
  2964. a[3] = e
  2965. },
  2966. copy: function(a, b) {
  2967. a[0] = b[0];
  2968. a[1] = b[1];
  2969. a[2] = b[2];
  2970. a[3] = b[3]
  2971. },
  2972. add: function(a, b, c) {
  2973. a[0] = b[0] + c[0];
  2974. a[1] = b[1] + c[1];
  2975. a[2] = b[2] + c[2];
  2976. a[3] = b[3] + c[3];
  2977. return a
  2978. },
  2979. sub: function(a, b, c) {
  2980. a[0] = b[0] - c[0];
  2981. a[1] = b[1] - c[1];
  2982. a[2] = b[2] - c[2];
  2983. a[3] = b[3] - c[3];
  2984. return a
  2985. },
  2986. scale: function(a, b, c) {
  2987. a[0] = c[0] * b;
  2988. a[1] = c[1] * b;
  2989. a[2] = c[2] * b;
  2990. a[3] = c[3] * b;
  2991. return a
  2992. },
  2993. mul: function(a, b, c) {
  2994. a[0] = b[0] * c[0];
  2995. a[1] = b[1] * c[1];
  2996. a[2] = b[2] * c[2];
  2997. a[3] = b[3] * c[3];
  2998. return a
  2999. },
  3000. mad: function(a, b, c, d) {
  3001. a[0] = b[0] * c[0] + d[0];
  3002. a[1] = b[1] * c[1] + d[1];
  3003. a[2] = b[2] * c[2] + d[2];
  3004. a[3] = b[3] * c[3] + d[3];
  3005. return a
  3006. },
  3007. smad: function(a, b, c, d) {
  3008. a[0] = b * c[0] + d[0];
  3009. a[1] = b * c[1] + d[1];
  3010. a[2] = b * c[2] + d[2];
  3011. a[3] = b * c[3] + d[3];
  3012. return a
  3013. },
  3014. negate: function(a, b) {
  3015. a[0] = -b[0];
  3016. a[1] = -b[1];
  3017. a[2] = -b[2];
  3018. return a
  3019. },
  3020. negate4: function(a, b) {
  3021. a[0] = -b[0];
  3022. a[1] = -b[1];
  3023. a[2] = -b[2];
  3024. a[3] = -b[3];
  3025. return a
  3026. },
  3027. length: function(a) {
  3028. var b = a[0]
  3029. , c = a[1];
  3030. a = a[2];
  3031. return Math.sqrt(b * b + c * c + a * a)
  3032. },
  3033. dot: function(a, b) {
  3034. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]
  3035. },
  3036. dot4: function(a, b) {
  3037. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]
  3038. },
  3039. normalize: function(a, b) {
  3040. var c = b[0]
  3041. , d = b[1]
  3042. , e = b[2]
  3043. , f = Math.sqrt(c * c + d * d + e * e);
  3044. if (0 == f)
  3045. return Vect.set(a, 0, 0, 0, 0);
  3046. f = 1 / f;
  3047. a[0] = c * f;
  3048. a[1] = d * f;
  3049. a[2] = e * f;
  3050. return a
  3051. },
  3052. cross: function(a, b, c) {
  3053. a[0] = b[1] * c[2];
  3054. a[0] += -b[2] * c[1];
  3055. a[1] = b[2] * c[0] - b[0] * c[2];
  3056. a[2] = b[0] * c[1] - b[1] * c[0];
  3057. return a
  3058. },
  3059. lerp: function(a, b, c, d) {
  3060. var e = 1 - d;
  3061. a[0] = b[0] * e + c[0] * d;
  3062. a[1] = b[1] * e + c[1] * d;
  3063. a[2] = b[2] * e + c[2] * d;
  3064. return a
  3065. },
  3066. lerp4: function(a, b, c, d) {
  3067. var e = 1 - d;
  3068. a[0] = b[0] * e + c[0] * d;
  3069. a[1] = b[1] * e + c[1] * d;
  3070. a[2] = b[2] * e + c[2] * d;
  3071. a[3] = b[3] * e + c[3] * d;
  3072. return a
  3073. },
  3074. min: function(a, b, c) {
  3075. a[0] = Math.min(b[0], c[0]);
  3076. a[1] = Math.min(b[1], c[1]);
  3077. a[2] = Math.min(b[2], c[2]);
  3078. a[3] = Math.min(b[3], c[3]);
  3079. return a
  3080. },
  3081. max: function(a, b, c) {
  3082. a[0] = Math.max(b[0], c[0]);
  3083. a[1] = Math.max(b[1], c[1]);
  3084. a[2] = Math.max(b[2], c[2]);
  3085. a[3] = Math.max(b[3], c[3]);
  3086. return a
  3087. },
  3088. projectOnPlane: function(a, b, c, d) {
  3089. var e = Vect.empty();
  3090. Vect.sub(e, b, c);
  3091. c = Vect.dot(e, d);
  3092. smad(a, -c, normal, b);
  3093. return a
  3094. }
  3095. };
  3096. function View(a) {
  3097. this.pivot = [0, 0, 0];
  3098. this.rotation = [0, 0];
  3099. this.radius = 1;
  3100. this.nearPlane = 0.3;
  3101. this.fov = 45;
  3102. this.size = [1, 1];
  3103. this.transform = Matrix.empty();
  3104. this.transform2 = Matrix.empty(); //改
  3105. this.viewMatrix = Matrix.empty();
  3106. this.viewMatrix2 = Matrix.empty(); //改
  3107. this.projectionMatrix = Matrix.empty();
  3108. this.viewProjectionMatrix = Matrix.empty();
  3109. this.viewProjectionMatrix2 = Matrix.empty();//改
  3110. this.projectionOffset = [0, 0];
  3111. a ? this.loadView(a, !0) : (this.saveResetView(),
  3112. this.updateView(),
  3113. this.updateProjection(),
  3114. this.modelMatrix = a.modelMatrix || Matrix.translation(Matrix.empty(),0,0,0) //改
  3115. )
  3116. }
  3117. ;
  3118. View.prototype.saveResetView = function() {
  3119. this.resetDesc = {
  3120. angles: [this.rotation[0], this.rotation[1]],
  3121. pivot: [this.pivot[0], this.pivot[1], this.pivot[2]],
  3122. limits: this.limits,
  3123. orbitRadius: this.radius,
  3124. fov: this.fov
  3125. }
  3126. }
  3127. ;
  3128. View.prototype.loadView = function(a, b) {
  3129. a && (this.rotation[0] = a.angles[0],
  3130. this.rotation[1] = a.angles[1],
  3131. this.pivot[0] = a.pivot[0], //相机初始焦点
  3132. this.pivot[1] = a.pivot[1],
  3133. this.pivot[2] = a.pivot[2],
  3134. this.modelMatrix = this.modelMatrix || a.modelMatrix|| Matrix.translation(Matrix.empty(),0,0,0), //改
  3135. this.radius = a.orbitRadius,
  3136. this.fov = a.fov,
  3137. this.limits = a.limits,
  3138. b && this.saveResetView(),
  3139. this.updateView(),
  3140. this.updateProjection())
  3141. }
  3142. ;
  3143. View.prototype.reset = function() {
  3144. this.loadView(this.resetDesc)
  3145. }
  3146. ;
  3147. /* View.prototype.updateView = function() {
  3148. Matrix.translation(this.transform, 0, 0, this.radius);
  3149. var a = Matrix.rotation(Matrix.empty(), this.rotation[0], 0)
  3150. , b = Matrix.rotation(Matrix.empty(), this.rotation[1], 1);
  3151. Matrix.mul(a, b, a);
  3152. Matrix.mul(this.transform, a, this.transform);
  3153. this.transform[12] += this.pivot[0];
  3154. this.transform[13] += this.pivot[1];
  3155. this.transform[14] += this.pivot[2];
  3156. Matrix.invert(this.viewMatrix, this.transform);
  3157. Matrix.mul(this.viewProjectionMatrix, this.viewMatrix, this.projectionMatrix)
  3158. }
  3159. ; */
  3160. View.prototype.updateView = function() {
  3161. //var M = Matrix.translation(Matrix.empty(),0.3,0,0);
  3162. //var p = Matrix.mul(Matrix.empty(), M, b.viewProjectionMatrix);
  3163. if (void 0 !== this.limits) {
  3164. if (this.limits.angles) {
  3165. var a = this.limits.angles.x
  3166. , b = this.limits.angles.y;
  3167. if (void 0 !== a) {
  3168. var c = this.rotation[0] - a.offset
  3169. , a = Math.min(Math.max(c, a.min), a.max);
  3170. this.rotation[0] += a - c
  3171. }
  3172. void 0 !== b && (c = this.rotation[1] - b.offset,
  3173. a = Math.min(Math.max(c, b.min), b.max),
  3174. this.rotation[1] += a - c)
  3175. }
  3176. void 0 !== this.limits.orbitRadius && (b = this.limits.orbitRadius.min,
  3177. c = this.limits.orbitRadius.max,
  3178. void 0 !== b && (this.radius = Math.max(this.radius, b)),
  3179. void 0 !== c && (this.radius = Math.min(this.radius, c)));
  3180. void 0 !== this.limits.pan && (b = this.limits.pan,
  3181. c = this.resetDesc.pivot,
  3182. b.x && (this.pivot[0] = c[0]),
  3183. b.y && (this.pivot[1] = c[1]),
  3184. b.z && (this.pivot[2] = c[2]))
  3185. }
  3186. Matrix.translation(this.transform, 0, 0, this.radius);
  3187. b = Matrix.rotation(Matrix.empty(), this.rotation[0], 0); //drag
  3188. c = Matrix.rotation(Matrix.empty(), this.rotation[1], 1);
  3189. Matrix.mul(b, c, b);
  3190. Matrix.mul(this.transform, b, this.transform);
  3191. Matrix.mul(this.transform2, this.modelMatrix, this.transform);//改
  3192. this.transform[12] += this.pivot[0]; //平移onpan
  3193. this.transform[13] += this.pivot[1];
  3194. this.transform[14] += this.pivot[2];
  3195. this.transform2[12] += this.pivot[0]; //平移onpan
  3196. this.transform2[13] += this.pivot[1];
  3197. this.transform2[14] += this.pivot[2];
  3198. Matrix.invert(this.viewMatrix, this.transform);
  3199. Matrix.invert(this.viewMatrix2, this.transform2);//改
  3200. //Matrix.mul(this.viewProjectionMatrix, this.viewMatrix, this.projectionMatrix)
  3201. //Matrix.mul(this.viewProjectionMatrix2, this.viewMatrix2, this.projectionMatrix)//改 updateProjection又会乘一次
  3202. }
  3203. ;
  3204. View.prototype.offsetProjection = function(a, b) {
  3205. this.projectionOffset[0] = a;
  3206. this.projectionOffset[1] = b
  3207. }
  3208. ;
  3209. View.prototype.updateProjection = function(a) {
  3210. Matrix.perspectiveInfinite(this.projectionMatrix, this.fov, this.size[0] / this.size[1], this.nearPlane, a);
  3211. this.projectionMatrix[8] = this.projectionOffset[0];
  3212. this.projectionMatrix[9] = this.projectionOffset[1];
  3213. Matrix.mul(this.viewProjectionMatrix, this.projectionMatrix, this.viewMatrix)
  3214. Matrix.mul(this.viewProjectionMatrix2, this.projectionMatrix, this.viewMatrix2)//改
  3215. }
  3216. ;
  3217. function WebViewer(a, b, c, d) {
  3218. this.mobile = /Android|iPhone|iPod|iPad|Windows Phone|IEMobile|BlackBerry|webOS/.test(navigator.userAgent);
  3219. this.domRoot = d || document.createElement("div");
  3220. if(d){
  3221. a = this.domRoot.clientWidth;
  3222. b = this.domRoot.clientHeight;
  3223. }else{
  3224. this.domRoot.style.width = a + "px";
  3225. this.domRoot.style.height = b + "px";
  3226. }
  3227. this.initCanvas(a, b);
  3228. this.scene = this.input = null ;
  3229. this.sceneURL = c;
  3230. this.sleepCounter = 8;
  3231. this.onLoad = null ;
  3232. //this.stripData = new StripData;
  3233. this.ui = new UI(this);
  3234. this.ui.setSize(a, b);
  3235. this.ui.showPreview()
  3236. }
  3237. WebViewer.prototype.initCanvas = function(a, b) {
  3238. this.canvas && this.canvas.parentNode && this.canvas.parentNode.removeChild(this.canvas);
  3239. this.canvas = document.createElement("canvas");
  3240. this.canvas.width = (window.devicePixelRatio||1) * a;//改
  3241. this.canvas.height = (window.devicePixelRatio||1) * b;
  3242. this.canvas.style.width = a + "px";
  3243. this.canvas.style.height = b + "px";
  3244. this.canvas.style.position = "absolute";
  3245. //this.canvas.style["z-index"] = "-10";
  3246. this.domRoot.appendChild(this.canvas)
  3247. }
  3248. ;
  3249. WebViewer.prototype.initGL = function() {
  3250. var a = {
  3251. alpha: !1,
  3252. depth: !1,
  3253. stencil: !1,
  3254. antialias: !1,
  3255. premultipliedAlpha: !1,
  3256. preserveDrawingBuffer: !1
  3257. }
  3258. , a = this.gl = this.canvas.getContext("webgl", a) || this.canvas.getContext("experimental-webgl", a);
  3259. if (!this.gl) {
  3260. var $u = window.location.href;
  3261. var arrUrl = $u.split("/");
  3262. var $p = arrUrl[arrUrl.length - 1];
  3263. var pn = $p.split(".")[0];
  3264. window.location.href = pn + "dd.html";
  3265. }
  3266. /*return this.ui.showFailure('Please <a href="http://get.webgl.org/" target=_blank>check<a/> to ensure your browser has support for WebGL.'),!1;*/
  3267. this.canvas.addEventListener("webglcontextlost", function(a) {
  3268. a.preventDefault()
  3269. }
  3270. .bind(this), !1);
  3271. this.canvas.addEventListener("webglcontextrestored", function(a) {
  3272. this.loadScene(this.sceneURL)
  3273. }
  3274. .bind(this), !1);
  3275. a.ext = {
  3276. textureAniso: a.getExtension("EXT_texture_filter_anisotropic") || a.getExtension("WEBKIT_EXT_texture_filter_anisotropic") || a.getExtension("MOZ_EXT_texture_filter_anisotropic"),
  3277. textureFloat: a.getExtension("OES_texture_float"),
  3278. textureFloatLinear: a.getExtension("OES_texture_float_linear"),
  3279. textureHalf: a.getExtension("OES_texture_half_float"),
  3280. textureHalfLinear: a.getExtension("OES_texture_half_float_linear"),
  3281. textureDepth: a.getExtension("WEBGL_depth_texture"),
  3282. colorBufferFloat: a.getExtension("WEBGL_color_buffer_float"),
  3283. colorBufferHalf: a.getExtension("EXT_color_buffer_half_float"),
  3284. index32bit: a.getExtension("OES_element_index_uint"),
  3285. loseContext: a.getExtension("WEBGL_lose_context"),
  3286. derivatives: a.getExtension("OES_standard_derivatives")
  3287. };
  3288. a.limits = {
  3289. textureSize: a.getParameter(a.MAX_TEXTURE_SIZE),
  3290. varyings: a.getParameter(a.MAX_VARYING_VECTORS),
  3291. vertexAttribs: a.getParameter(a.MAX_VERTEX_ATTRIBS),
  3292. vertexUniforms: a.getParameter(a.MAX_VERTEX_UNIFORM_VECTORS),
  3293. fragmentUniforms: a.getParameter(a.MAX_FRAGMENT_UNIFORM_VECTORS),
  3294. viewportSizes: a.getParameter(a.MAX_VIEWPORT_DIMS),
  3295. vendor: a.getParameter(a.VENDOR),
  3296. version: a.getParameter(a.VERSION)
  3297. };
  3298. a.hints = {
  3299. mobile: this.mobile
  3300. };
  3301. a.enable(a.DEPTH_TEST);
  3302. a.shaderCache = new ShaderCache(a);
  3303. a.textureCache = new TextureCache(a);
  3304. this.allocBacking();
  3305. return !0
  3306. }
  3307. ;
  3308. WebViewer.prototype.allocBacking = function() {
  3309. var a = this.gl
  3310. , b = !1
  3311. , c = {
  3312. width: this.canvas.width,
  3313. height: this.canvas.height,
  3314. nofilter: !0
  3315. };
  3316. this.mainColor = new Texture(a,c);
  3317. a.ext.textureHalf && a.ext.textureHalfLinear && (this.mainColor.loadArray(null , a.RGBA, a.ext.textureHalf.HALF_FLOAT_OES),
  3318. this.mainBuffer = new Framebuffer(a,{
  3319. color0: this.mainColor,
  3320. createDepth: !0
  3321. }),
  3322. b = this.mainBuffer.valid);
  3323. !b && a.ext.textureFloat && a.ext.textureFloatLinear && !a.hints.mobile && (this.mainColor.loadArray(null , a.RGBA, a.FLOAT),
  3324. this.mainBuffer = new Framebuffer(a,{
  3325. color0: this.mainColor,
  3326. createDepth: !0
  3327. }),
  3328. b = this.mainBuffer.valid);
  3329. for (; !b; )
  3330. this.mainColor = new Texture(a,c),
  3331. this.mainColor.loadArray(null , a.RGBA, a.UNSIGNED_BYTE),
  3332. this.mainBuffer = new Framebuffer(a,{
  3333. color0: this.mainColor,
  3334. createDepth: !0
  3335. }),
  3336. b = this.mainBuffer.valid,
  3337. c.width /= 2,
  3338. c.height /= 2
  3339. }
  3340. ;
  3341. WebViewer.prototype.loadScene = function(a) {
  3342. this.sceneURL = a || this.sceneURL;
  3343. this.scene = this.input = null ;
  3344. if (this.initGL() && this.sceneURL) {
  3345. var b = this.ui.signalLoadProgress.bind(this.ui);
  3346. a = function(a) {
  3347. b(1, 1);
  3348. this.scene = new Scene(this.gl);
  3349. //this.scene.modelMatrix = this.scene.modelMatrix || Matrix.translation(Matrix.empty(),0,0,0); //改。这是model旋转位移的matrix
  3350. this.scene.stripData = this.stripData;
  3351. var file = new Archive(a); //改
  3352. var load = this.scene.load(file);
  3353. if (load === true)
  3354. if (2070 >= this.scene.metaData.tbVersion)
  3355. this.ui.showFailure("模型文件版本过低");
  3356. else {
  3357. if (this.bindInput(),
  3358. this.requestFrame(this.updateLoad.bind(this)),
  3359. this.onLoad)
  3360. this.onLoad()
  3361. }
  3362. else
  3363. this.ui.showFailure("模型文件无法读取或无效"+(load.failure?load.failure:""))
  3364. }
  3365. .bind(this);
  3366. var c = function() {
  3367. this.ui.showFailure("模型文件 (" + this.sceneURL + ") 无法获取.")
  3368. }
  3369. .bind(this);
  3370. Network.fetchBinary(this.sceneURL, a, c, b)
  3371. }
  3372. }
  3373. ;
  3374. WebViewer.prototype.unload = function() {
  3375. delete this.scene;
  3376. delete this.input;
  3377. delete this.ui;
  3378. delete this.mainColor;
  3379. delete this.mainBuffer;
  3380. delete this.gl;
  3381. var a = this.domRoot.clientWidth
  3382. , b = this.domRoot.clientHeight;
  3383. this.initCanvas(a, b);
  3384. this.ui = new UI(this);
  3385. this.ui.setSize(a, b);
  3386. this.ui.showPreview();
  3387. this.cancelFrame()
  3388. }
  3389. ;
  3390. WebViewer.prototype.bindInput = function() {
  3391. this.input = new Input(this.ui.container);
  3392. var a = function() {
  3393. this.wake();
  3394. this.scene.postRender.discardAAHistory()
  3395. }
  3396. .bind(this);
  3397. this.input.onDrag.push(function(b, c, d, e) {
  3398. b = 1 - 2.2 / (Math.sqrt(d * d + e * e) + 2.2);
  3399. c = this.scene.view;
  3400. c.rotation[1] -= 0.4 * d * b;
  3401. c.rotation[0] -= 0.4 * e * b;
  3402. c.rotation[0] = 90 < c.rotation[0] ? 90 : c.rotation[0];
  3403. c.rotation[0] = -90 > c.rotation[0] ? -90 : c.rotation[0];
  3404. c.updateView();
  3405. a()
  3406. }
  3407. .bind(this));
  3408. this.input.onPan.push(function(b, c) {
  3409. var d = this.scene.view
  3410. , e = d.fov / 45 * 0.8 * (d.radius / this.domRoot.clientHeight)
  3411. , f = -b * e
  3412. , e = c * e;
  3413. d.pivot[0] += f * d.transform2[0] + e * d.transform2[4]; //改
  3414. d.pivot[1] += f * d.transform2[1] + e * d.transform2[5];
  3415. d.pivot[2] += f * d.transform2[2] + e * d.transform2[6];
  3416. d.updateView();
  3417. a()
  3418. }
  3419. .bind(this));
  3420. this.input.onPan2.push(function(b, c) {
  3421. var d = 1 - 2.2 / (Math.sqrt(b * b + c * c) + 2.2);
  3422. this.scene.lights.rotation -= 0.4 * b * d;
  3423. a()
  3424. }
  3425. .bind(this));
  3426. this.input.onZoom.push(function(b) {
  3427. var c = this.scene.view;
  3428. c.radius *= 1 - 0.002 * b;
  3429. c.radius = 0.001 > c.radius ? 0.001 : c.radius;
  3430. c.radius = 1E3 < c.radius ? 1E3 : c.radius;
  3431. c.updateView();
  3432. a()
  3433. }
  3434. .bind(this));
  3435. this.ui.bindInput(this.input)
  3436. }
  3437. ;
  3438. WebViewer.prototype.wake = function(a) {
  3439. this.sleepCounter = a || ((this.gl.hints.mobile)? 4:16);
  3440. this.requestFrame(this.update.bind(this))
  3441. }
  3442. ;
  3443. WebViewer.prototype.requestFrame = function(a) {
  3444. var b = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
  3445. if (!this.frameRequestPending) {
  3446. var c = function() {
  3447. this.frameRequestPending = 0;
  3448. a()
  3449. }
  3450. .bind(this);
  3451. this.frameRequestPending = b(c, this.canvas)
  3452. }
  3453. }
  3454. ;
  3455. WebViewer.prototype.cancelFrame = function() {
  3456. this.frameRequestPending && (window.cancelAnimationFrame || window.mozCancelAnimationFrame || window.webkitCancelAnimationFrame || window.msCancelAnimationFrame)(this.frameRequestPending)
  3457. }
  3458. ;
  3459. WebViewer.prototype.fullscreenChange = function() {
  3460. FullScreen.active() ? (this.oldRootWidth = this.domRoot.style.width,
  3461. this.oldRootHeight = this.domRoot.style.height,
  3462. this.domRoot.style.width = "100%",
  3463. this.domRoot.style.height = "100%") : (this.domRoot.style.width = this.oldRootWidth,
  3464. this.domRoot.style.height = this.oldRootHeight);
  3465. this.wake()
  3466. }
  3467. ;
  3468. WebViewer.prototype.resize = function(a, b) {
  3469. a && b ? (this.domRoot.style.width = a + "px",
  3470. this.domRoot.style.height = b + "px") : (a = this.domRoot.clientWidth,
  3471. b = this.domRoot.clientHeight);
  3472. this.canvas.width = (window.devicePixelRatio||1) * a;//改
  3473. this.canvas.height = (window.devicePixelRatio||1) * b;
  3474. this.canvas.style.width = a + "px";
  3475. this.canvas.style.height = b + "px";
  3476. this.ui.setSize(a, b);
  3477. this.allocBacking();
  3478. this.wake()
  3479. }
  3480. ;
  3481. WebViewer.prototype.updateLoad = function() {
  3482. this.scene.complete() ? (this.ui.showActiveView(),
  3483. this.requestFrame(this.update.bind(this))) : this.requestFrame(this.updateLoad.bind(this));
  3484. this.ui.animate()
  3485. }
  3486. ;
  3487. WebViewer.prototype.update = function() {
  3488. if (0 < this.sleepCounter || this.ui.animating())
  3489. this.ui.animate(),
  3490. this.scene.update(),
  3491. this.drawScene(),
  3492. this.requestFrame(this.update.bind(this));
  3493. this.sleepCounter--
  3494. }
  3495. ;
  3496. WebViewer.prototype.drawScene = function() {
  3497. this.gl.isContextLost() || (this.domRoot.clientWidth == this.canvas.clientWidth && this.domRoot.clientHeight == this.canvas.clientHeight || this.resize(),
  3498. this.scene.view.size = [this.mainBuffer.width, this.mainBuffer.height],
  3499. this.scene.view.updateProjection(),
  3500. this.scene.postRender.adjustProjectionForSupersampling(this.scene.view),
  3501. this.scene.collectShadows(this.mainBuffer),
  3502. this.mainBuffer.bind(),
  3503. this.scene.draw(),
  3504. this.scene.postRender.present(this.mainColor, this.canvas.width, this.canvas.height, fdage.ifPlain))//改
  3505. }
  3506. ;
  3507. fdage = "undefined" == typeof fdage ? {} : fdage;
  3508. fdage.WebViewer = WebViewer;
  3509. fdage.dataLocale = "images/";
  3510. var ShaderTable = {
  3511. "aaresolve.glsl":"precision mediump float;uniform sampler2D tInput0;uniform sampler2D tInput1;uniform sampler2D tInput2; \n#ifdef HIGHQ\n uniform sampler2D tInput3;uniform sampler2D tInput4;uniform sampler2D tInput5;uniform sampler2D tInput6;uniform sampler2D tInput7;uniform sampler2D tInput8;uniform sampler2D tInput9;uniform sampler2D tInput10;uniform sampler2D tInput11;uniform sampler2D tInput12;uniform sampler2D tInput13;uniform sampler2D tInput14;uniform sampler2D tInput15; \n#endif\n uniform mat4 uSamplesValid;varying highp vec2 d;void main(void){vec4 e0=texture2D(tInput0,d); vec4 e1=texture2D(tInput1,d);vec4 e2=texture2D(tInput2,d);\n#ifdef HIGHQ\n vec4 e3=texture2D(tInput3,d);vec4 e4=texture2D(tInput4,d);vec4 e5=texture2D(tInput5,d);vec4 e6=texture2D(tInput6,d);vec4 e7=texture2D(tInput7,d);vec4 e8=texture2D(tInput8,d);vec4 e9=texture2D(tInput9,d);vec4 e10=texture2D(tInput10,d);vec4 e11=texture2D(tInput11,d);vec4 e12=texture2D(tInput12,d);vec4 e13=texture2D(tInput13,d);vec4 e14=texture2D(tInput14,d);vec4 e15=texture2D(tInput15,d);\ngl_FragColor=e0*uSamplesValid[0][0]+e1*uSamplesValid[0][1]+e2*uSamplesValid[0][2]+e3*uSamplesValid[0][3]+e4*uSamplesValid[1][0]+e5*uSamplesValid[1][1]+e6*uSamplesValid[1][2]+e7*uSamplesValid[1][3]+e8*uSamplesValid[2][0]+e9*uSamplesValid[2][1]+e10*uSamplesValid[2][2]+e11*uSamplesValid[2][3]+e12*uSamplesValid[3][0]+e13*uSamplesValid[3][1]+e14*uSamplesValid[3][2]+e15*uSamplesValid[3][3];\n#else\n gl_FragColor=e0*uSamplesValid[0][0]+e1*uSamplesValid[0][1]+e2*uSamplesValid[0][2];\n#endif\n}",
  3512. // "alphaprepassfrag.glsl": "precision mediump float;\n#include <matdither.glsl>\nuniform sampler2D tAlbedo;varying mediump vec2 j;void main(){float k=texture2D(tAlbedo,j).a;if(k<=l(j.x)){discard;}gl_FragColor=vec4(0.0);}",
  3513. "alphaprepassfrag.glsl": "precision mediump float;\n#include <matdither.glsl>\nuniform sampler2D tAlbedo;uniform float uAlphaStrength;varying mediump vec2 j;void main(){float k=texture2D(tAlbedo,j).a * uAlphaStrength / 100.0;if(k<=l(j.x)){discard;}gl_FragColor=vec4(0.0);}",
  3514. "alphaprepassvert.glsl": "precision highp float;uniform mat4 uModelViewProjectionMatrix;attribute vec3 vPosition;attribute vec2 vTexCoord;varying mediump vec2 j;vec4 m(mat4 o,vec3 p){return o[0]*p.x+(o[1]*p.y+(o[2]*p.z+o[3]));}void main(void){gl_Position=m(uModelViewProjectionMatrix,vPosition.xyz);j=vTexCoord;}",
  3515. "bloom.glsl": "precision mediump float;uniform sampler2D tInput;uniform vec4 uKernel[BLOOM_SAMPLES];varying highp vec2 d;void main(void){vec3 c=vec3(0.0,0.0,0.0);for(int u=0;u<BLOOM_SAMPLES;++u){vec3 v=uKernel[u].xyz;c+=texture2D(tInput,d+v.xy).xyz*v.z;}gl_FragColor.xyz=c;gl_FragColor.w=0.0;}",
  3516. "bloomshrink.glsl": "precision highp float;uniform sampler2D tInput;varying highp vec2 d;void main(void){float A=0.25/256.0;gl_FragColor=0.25*(texture2D(tInput,d+vec2(A,A))+texture2D(tInput,d+vec2(A,-A))+texture2D(tInput,d+vec2(-A,A))+texture2D(tInput,d+vec2(-A,-A)));}",
  3517. "matdither.glsl": "float l(highp float B){highp float C=0.5*fract(gl_FragCoord.x*0.5)+0.5*fract(gl_FragCoord.y*0.5);return 0.4+0.6*fract(C+3.141592e6*B);}",
  3518. // "matfrag.glsl": "\n#extension GL_OES_standard_derivatives : enable\nprecision mediump float;varying highp vec3 D;varying mediump vec2 j;varying mediump vec3 E;varying mediump vec3 F;varying mediump vec3 G;\n#ifdef VERTEX_COLOR\nvarying lowp vec4 H;\n#endif\n#ifdef TEXCOORD_SECONDARY\nvarying mediump vec2 I;\n#endif\nuniform sampler2D tAlbedo;uniform sampler2D tReflectivity;uniform sampler2D tNormal;uniform sampler2D tExtras;uniform sampler2D tSkySpecular;uniform vec4 uDiffuseCoefficients[9];uniform vec3 uCameraPosition;uniform vec3 uFresnel;uniform float uAlphaTest;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 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 J=texture2D(tAlbedo,j);vec3 K=L(J.xyz);float k=J.w;\n#ifdef VERTEX_COLOR\n{vec3 M=H.xyz;\n#ifdef VERTEX_COLOR_SRGB\nM=M*(M*(M*0.305306011+vec3(0.682171111))+vec3(0.012522878));\n#endif\nK*=M;\n#ifdef VERTEX_COLOR_ALPHA\nk*=H.w;\n#endif\n}\n#endif\n#ifdef ALPHA_TEST\nif(k<uAlphaTest){discard;}\n#endif\n#ifdef TRANSPARENCY_DITHER\nk=(k>l(j.x))?1.0:k;\n#endif\nvec3 N=O(texture2D(tNormal,j).xyz);\n#ifdef ANISO\n#ifdef ANISO_NO_DIR_TEX\nvec3 P=Q(uAnisoTangent);\n#else\nJ=R(j,uTexRangeAniso);vec3 P=2.0*J.xyz-vec3(1.0);P=Q(P);\n#endif\nP=P-N*dot(P,N);P=normalize(P);vec3 S=P*uAnisoStrength;\n#endif\nvec3 T=normalize(uCameraPosition-D);J=texture2D(tReflectivity,j);vec3 U=L(J.xyz);float V=J.w;float W=V;\n#ifdef HORIZON_SMOOTHING\nfloat X=dot(T,N);X=uHorizonSmoothing-X*uHorizonSmoothing;V=mix(V,1.0,X*X);\n#endif\n#ifdef STRIPVIEW\nY Z;dc(Z,V,U);\n#endif\nfloat dd=1.0;\n#ifdef AMBIENT_OCCLUSION\n#ifdef AMBIENT_OCCLUSION_SECONDARY_UV\ndd=R(I,uTexRangeAO).x;\n#else\ndd=R(j,uTexRangeAO).x;\n#endif\ndd*=dd;\n#endif\n#if defined(SKIN)\nde df;dh(df);df.di*=dd;\n#elif defined(MICROFIBER)\ndj dk;dl(dk,N);dk.dm*=dd;\n#else\nvec3 dn=du(N);dn*=dd;\n#endif\nvec3 dv=reflect(-T,N);\n#ifdef ANISO\nvec3 rt=dv-(0.5*S*dot(dv,P));vec3 dA=dB(rt,mix(V,0.5*V,uAnisoStrength));\n#else\nvec3 dA=dB(dv,V);\n#endif\ndA*=dC(dv,G);\n#ifdef LIGHT_COUNT\nhighp float dD=10.0/log2(V*0.968+0.03);dD*=dD;float dE=dD*(1.0/(8.0*3.1415926))+(4.0/(8.0*3.1415926));dE=min(dE,1.0e3);\n#ifdef SHADOW_COUNT\ndF dG;dH(dG,SHADOW_KERNEL);\n#ifdef SKIN\ndF dI;dH(dI,SHADOW_KERNEL+SHADOW_KERNEL*df.dJ);\n#endif\n#endif\n#ifdef ANISO\ndE*=uAnisoIntegral;\n#endif\nfor(int u=0;u<LIGHT_COUNT;++u){vec3 dK=uLightPositions[u].xyz-D*uLightPositions[u].w;float dL=inversesqrt(dot(dK,dK));dK*=dL;float a=saturate(uLightParams[u].z/dL);a=1.0+a*(uLightParams[u].x+uLightParams[u].y*a);float s=saturate(dot(dK,uLightDirections[u]));s=saturate(uLightSpot[u].y-uLightSpot[u].z*(1.0-s*s));vec3 dM=(a*s)*uLightColors[u].xyz;\n#if defined(SKIN)\n#ifdef SHADOW_COUNT\ndN(df,dG.dO[u],dI.dO[u],dK,N,dM);\n#else\ndN(df,1.0,1.0,dK,N,dM);\n#endif\n#elif defined(MICROFIBER)\n#ifdef SHADOW_COUNT\ndP(dk,dG.dO[u],dK,N,dM);\n#else\ndP(dk,1.0,dK,N,dM);\n#endif\n#else\nfloat dQ=saturate((1.0/3.1415926)*dot(dK,N));\n#ifdef SHADOW_COUNT\ndQ*=dG.dO[u];\n#endif\ndn+=dQ*dM;\n#endif\nvec3 dR=dK+T;\n#ifdef ANISO\ndR=dR-(S*dot(dR,P));\n#endif\ndR=normalize(dR);float dS=dE*pow(saturate(dot(dR,N)),dD);\n#ifdef SHADOW_COUNT\ndS*=dG.dO[u];\n#endif\ndA+=dS*dM;}\n#endif\n#if defined(SKIN)\nvec3 dn,diff_extra;dT(dn,diff_extra,df,T,N,V);\n#elif defined(MICROFIBER)\nvec3 dn,diff_extra;dU(dn,diff_extra,dk,T,N,V);\n#endif\ndA*=dV(T,N,U,V*V);\n#ifdef DIFFUSE_UNLIT\ngl_FragColor.xyz=K+dA;\n#else\ngl_FragColor.xyz=dn*K+dA;\n#endif\n#if defined(SKIN) || defined(MICROFIBER)\ngl_FragColor.xyz+=diff_extra;\n#endif\n#ifdef EMISSIVE\n#ifdef EMISSIVE_SECONDARY_UV\nvec2 dW=I;\n#else\nvec2 dW=j;\n#endif\ngl_FragColor.xyz+=uEmissiveScale*L(R(dW,uTexRangeEmissive).xyz);\n#endif\n#ifdef STRIPVIEW\ngl_FragColor.xyz=dX(Z,N,K,U,W,dn,dA,gl_FragColor.xyz);\n#endif\n#ifdef NOBLEND\ngl_FragColor.w=1.0;\n#else\ngl_FragColor.w=k;\n#endif\n}",
  3519. //"matfrag.glsl": "\n#extension GL_OES_standard_derivatives : enable\nprecision mediump float;varying highp vec3 D;varying mediump vec2 j;varying mediump vec3 E;varying mediump vec3 F;varying mediump vec3 G;\n#ifdef VERTEX_COLOR\nvarying lowp vec4 H;\n#endif\n#ifdef TEXCOORD_SECONDARY\nvarying mediump vec2 I;\n#endif\nuniform sampler2D tAlbedo;uniform sampler2D tReflectivity;uniform sampler2D tNormal;uniform sampler2D tExtras;uniform sampler2D tSkySpecular; uniform float uAlbedoStrength; uniform float uReflecStrength; uniform float uAlphaStrength; uniform float uNormalStrength; uniform float uGlossStrength; uniform vec4 uDiffuseCoefficients[9];uniform vec3 uCameraPosition;uniform vec3 uFresnel;uniform float uAlphaTest;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 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 J=texture2D(tAlbedo,j); J.xyz = (uAlbedoStrength/100.0)*J.xyz; J.w *= (uAlphaStrength/100.0); vec3 K=L(J.xyz); float k=J.w;\n#ifdef VERTEX_COLOR\n{vec3 M=H.xyz;\n#ifdef VERTEX_COLOR_SRGB\nM=M*(M*(M*0.305306011+vec3(0.682171111))+vec3(0.012522878));\n#endif\nK*=M;\n#ifdef VERTEX_COLOR_ALPHA\nk*=H.w;\n#endif\n}\n#endif\n#ifdef ALPHA_TEST\nif(k<uAlphaTest){discard;}\n#endif\n#ifdef TRANSPARENCY_DITHER\nk=(k>l(j.x))?1.0:k;\n#endif\n vec3 N0 = texture2D(tNormal,j).xyz; vec3 N=On(texture2D(tNormal,j).xyz,uNormalStrength/100.0); \n#ifdef ANISO\n#ifdef ANISO_NO_DIR_TEX\nvec3 P=Q(uAnisoTangent);\n#else\nJ=R(j,uTexRangeAniso);vec3 P=2.0*J.xyz-vec3(1.0);P=Q(P);\n#endif\nP=P-N*dot(P,N);P=normalize(P);vec3 S=P*uAnisoStrength;\n#endif\nvec3 T=normalize(uCameraPosition-D);J=texture2D(tReflectivity,j); J.xyz = (uReflecStrength/100.0)*J.xyz; J.w *= (uGlossStrength/100.0); vec3 U=L(J.xyz);float V=J.w;float W=V;\n#ifdef HORIZON_SMOOTHING\nfloat X=dot(T,N);X=uHorizonSmoothing-X*uHorizonSmoothing;V=mix(V,1.0,X*X);\n#endif\n#ifdef STRIPVIEW\nY Z;dc(Z,V,U);\n#endif\nfloat dd=1.0;\n#ifdef AMBIENT_OCCLUSION\n#ifdef AMBIENT_OCCLUSION_SECONDARY_UV\ndd=R(I,uTexRangeAO).x;\n#else\ndd=R(j,uTexRangeAO).x;\n#endif\ndd*=dd;\n#endif\n#if defined(SKIN)\nde df;dh(df);df.di*=dd;\n#elif defined(MICROFIBER)\ndj dk;dl(dk,N);dk.dm*=dd;\n#else\nvec3 dn=du(N);dn*=dd;\n#endif\nvec3 dv=reflect(-T,N);\n#ifdef ANISO\nvec3 rt=dv-(0.5*S*dot(dv,P));vec3 dA=dB(rt,mix(V,0.5*V,uAnisoStrength));\n#else\nvec3 dA=dB(dv,V);\n#endif\ndA*=dC(dv,G);\n#ifdef LIGHT_COUNT\nhighp float dD=10.0/log2(V*0.968+0.03);dD*=dD;float dE=dD*(1.0/(8.0*3.1415926))+(4.0/(8.0*3.1415926));dE=min(dE,1.0e3);\n#ifdef SHADOW_COUNT\ndF dG;dH(dG,SHADOW_KERNEL);\n#ifdef SKIN\ndF dI;dH(dI,SHADOW_KERNEL+SHADOW_KERNEL*df.dJ);\n#endif\n#endif\n#ifdef ANISO\ndE*=uAnisoIntegral;\n#endif\nfor(int u=0;u<LIGHT_COUNT;++u){vec3 dK=uLightPositions[u].xyz-D*uLightPositions[u].w;float dL=inversesqrt(dot(dK,dK));dK*=dL;float a=saturate(uLightParams[u].z/dL);a=1.0+a*(uLightParams[u].x+uLightParams[u].y*a);float s=saturate(dot(dK,uLightDirections[u]));s=saturate(uLightSpot[u].y-uLightSpot[u].z*(1.0-s*s));vec3 dM=(a*s)*uLightColors[u].xyz;\n#if defined(SKIN)\n#ifdef SHADOW_COUNT\ndN(df,dG.dO[u],dI.dO[u],dK,N,dM);\n#else\ndN(df,1.0,1.0,dK,N,dM);\n#endif\n#elif defined(MICROFIBER)\n#ifdef SHADOW_COUNT\ndP(dk,dG.dO[u],dK,N,dM);\n#else\ndP(dk,1.0,dK,N,dM);\n#endif\n#else\nfloat dQ=saturate((1.0/3.1415926)*dot(dK,N));\n#ifdef SHADOW_COUNT\ndQ*=dG.dO[u];\n#endif\ndn+=dQ*dM;\n#endif\nvec3 dR=dK+T;\n#ifdef ANISO\ndR=dR-(S*dot(dR,P));\n#endif\ndR=normalize(dR);float dS=dE*pow(saturate(dot(dR,N)),dD);\n#ifdef SHADOW_COUNT\ndS*=dG.dO[u];\n#endif\ndA+=dS*dM;}\n#endif\n#if defined(SKIN)\nvec3 dn,diff_extra;dT(dn,diff_extra,df,T,N,V);\n#elif defined(MICROFIBER)\nvec3 dn,diff_extra;dU(dn,diff_extra,dk,T,N,V);\n#endif\ndA*=dV(T,N,U,V*V);\n#ifdef DIFFUSE_UNLIT\ngl_FragColor.xyz=K+dA;\n#else\ngl_FragColor.xyz=dn*K+dA;\n#endif\n#if defined(SKIN) || defined(MICROFIBER)\ngl_FragColor.xyz+=diff_extra;\n#endif\n#ifdef EMISSIVE\n#ifdef EMISSIVE_SECONDARY_UV\nvec2 dW=I;\n#else\nvec2 dW=j;\n#endif\ngl_FragColor.xyz+=uEmissiveScale*L(R(dW,uTexRangeEmissive).xyz);\n#endif\n#ifdef STRIPVIEW\ngl_FragColor.xyz=dX(Z,N,K,U,W,dn,dA,gl_FragColor.xyz);\n#endif\n#ifdef NOBLEND\ngl_FragColor.w=1.0;\n#else\ngl_FragColor.w=k;\n#endif\n}",
  3520. "matfrag.glsl": "\n#extension GL_OES_standard_derivatives : enable\nprecision mediump float;varying highp vec3 D;varying mediump vec2 j;varying mediump vec3 E;varying mediump vec3 F;varying mediump vec3 G;\n#ifdef VERTEX_COLOR\nvarying lowp vec4 H;\n#endif\n#ifdef TEXCOORD_SECONDARY\nvarying mediump vec2 I;\n#endif\nuniform sampler2D tAlbedo;uniform sampler2D tReflectivity;uniform sampler2D tNormal;uniform sampler2D tExtras;uniform sampler2D tSkySpecular; uniform float uAlbedoStrength; uniform float uReflecStrength; uniform float uAlphaStrength; uniform float uNormalStrength; uniform float uGlossStrength;uniform float uModelBright; uniform vec4 uDiffuseCoefficients[9];uniform vec3 uCameraPosition;uniform vec3 uFresnel;uniform float uAlphaTest;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 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 J=texture2D(tAlbedo,j); J.xyz = (uAlbedoStrength/100.0)*J.xyz; J.w *= (uAlphaStrength/100.0); vec3 K=L(J.xyz); float k=J.w;\n#ifdef VERTEX_COLOR\n{vec3 M=H.xyz;\n#ifdef VERTEX_COLOR_SRGB\nM=M*(M*(M*0.305306011+vec3(0.682171111))+vec3(0.012522878));\n#endif\nK*=M;\n#ifdef VERTEX_COLOR_ALPHA\nk*=H.w;\n#endif\n}\n#endif\n#ifdef ALPHA_TEST\nif(k<uAlphaTest){discard;}\n#endif\n#ifdef TRANSPARENCY_DITHER\nk=(k>l(j.x))?1.0:k;\n#endif\n vec3 N0 = texture2D(tNormal,j).xyz; vec3 N=On(texture2D(tNormal,j).xyz,uNormalStrength/100.0); \n#ifdef ANISO\n#ifdef ANISO_NO_DIR_TEX\nvec3 P=Q(uAnisoTangent);\n#else\nJ=R(j,uTexRangeAniso);vec3 P=2.0*J.xyz-vec3(1.0);P=Q(P);\n#endif\nP=P-N*dot(P,N);P=normalize(P);vec3 S=P*uAnisoStrength;\n#endif\nvec3 T=normalize(uCameraPosition-D);J=texture2D(tReflectivity,j); J.xyz = (uReflecStrength/100.0)*J.xyz; J.w *= (uGlossStrength/100.0); vec3 U=L(J.xyz);float V=J.w;float W=V;\n#ifdef HORIZON_SMOOTHING\nfloat X=dot(T,N);X=uHorizonSmoothing-X*uHorizonSmoothing;V=mix(V,1.0,X*X);\n#endif\n#ifdef STRIPVIEW\nY Z;dc(Z,V,U);\n#endif\nfloat dd=1.0;\n#ifdef AMBIENT_OCCLUSION\n#ifdef AMBIENT_OCCLUSION_SECONDARY_UV\ndd=R(I,uTexRangeAO).x;\n#else\ndd=R(j,uTexRangeAO).x;\n#endif\ndd*=dd;\n#endif\n#if defined(SKIN)\nde df;dh(df);df.di*=dd;\n#elif defined(MICROFIBER)\ndj dk;dl(dk,N);dk.dm*=dd;\n#else\nvec3 dn=du(N);dn*=dd;\n#endif\nvec3 dv=reflect(-T,N);\n#ifdef ANISO\nvec3 rt=dv-(0.5*S*dot(dv,P));vec3 dA=dB(rt,mix(V,0.5*V,uAnisoStrength));\n#else\nvec3 dA=dB(dv,V);\n#endif\ndA*=dC(dv,G);\n#ifdef LIGHT_COUNT\nhighp float dD=10.0/log2(V*0.968+0.03);dD*=dD;float dE=dD*(1.0/(8.0*3.1415926))+(4.0/(8.0*3.1415926));dE=min(dE,1.0e3);\n#ifdef SHADOW_COUNT\ndF dG;dH(dG,SHADOW_KERNEL);\n#ifdef SKIN\ndF dI;dH(dI,SHADOW_KERNEL+SHADOW_KERNEL*df.dJ);\n#endif\n#endif\n#ifdef ANISO\ndE*=uAnisoIntegral;\n#endif\nfor(int u=0;u<LIGHT_COUNT;++u){vec3 dK=uLightPositions[u].xyz-D*uLightPositions[u].w;float dL=inversesqrt(dot(dK,dK));dK*=dL;float a=saturate(uLightParams[u].z/dL);a=1.0+a*(uLightParams[u].x+uLightParams[u].y*a);float s=saturate(dot(dK,uLightDirections[u]));s=saturate(uLightSpot[u].y-uLightSpot[u].z*(1.0-s*s));vec3 dM=(a*s)*uLightColors[u].xyz;\n#if defined(SKIN)\n#ifdef SHADOW_COUNT\ndN(df,dG.dO[u],dI.dO[u],dK,N,dM);\n#else\ndN(df,1.0,1.0,dK,N,dM);\n#endif\n#elif defined(MICROFIBER)\n#ifdef SHADOW_COUNT\ndP(dk,dG.dO[u],dK,N,dM);\n#else\ndP(dk,1.0,dK,N,dM);\n#endif\n#else\nfloat dQ=saturate((1.0/3.1415926)*dot(dK,N));\n#ifdef SHADOW_COUNT\ndQ*=dG.dO[u];\n#endif\ndn+=dQ*dM;\n#endif\nvec3 dR=dK+T;\n#ifdef ANISO\ndR=dR-(S*dot(dR,P));\n#endif\ndR=normalize(dR);float dS=dE*pow(saturate(dot(dR,N)),dD);\n#ifdef SHADOW_COUNT\ndS*=dG.dO[u];\n#endif\ndA+=dS*dM;}\n#endif\n#if defined(SKIN)\nvec3 dn,diff_extra;dT(dn,diff_extra,df,T,N,V);\n#elif defined(MICROFIBER)\nvec3 dn,diff_extra;dU(dn,diff_extra,dk,T,N,V);\n#endif\ndA*=dV(T,N,U,V*V);\n#ifdef DIFFUSE_UNLIT\ngl_FragColor.xyz=K+dA;\n#else\ngl_FragColor.xyz=dn*K+dA;\n#endif\n#if defined(SKIN) || defined(MICROFIBER)\ngl_FragColor.xyz+=diff_extra;\n#endif\n#ifdef EMISSIVE\n#ifdef EMISSIVE_SECONDARY_UV\nvec2 dW=I;\n#else\nvec2 dW=j;\n#endif\ngl_FragColor.xyz+=uEmissiveScale*L(R(dW,uTexRangeEmissive).xyz);\n#endif\n#ifdef STRIPVIEW\ngl_FragColor.xyz=dX(Z,N,K,U,W,dn,dA,gl_FragColor.xyz);\n#endif\n#ifdef NOBLEND\ngl_FragColor.w=1.0;\n#else\ngl_FragColor.w=k;\n#endif\n gl_FragColor.xyz*=uModelBright; }",
  3521. "matlighting.glsl": "float dY(float dZ,float ec){return saturate(-dZ*ec+dZ+ec);}vec3 ed(float dZ,vec3 ec){return saturate(-dZ*ec+vec3(dZ)+ec);}float ee(float ec){return-0.31830988618379*ec+0.31830988618379;}vec3 ef(vec3 ec){return-0.31830988618379*ec+vec3(0.31830988618379);}vec3 dV(vec3 T,vec3 N,vec3 U,float eh){float ei=1.0-saturate(dot(T,N));float ej=ei*ei;ei*=ej*ej;ei*=eh;return(U-ei*U)+ei*uFresnel;}vec2 ek(vec2 el,vec2 ec){el=1.0-el;vec2 em=el*el;em*=em;el=mix(em,el*0.4,ec);return el;}vec3 du(vec3 en){\n#define c(n) uDiffuseCoefficients[n].xyz\nvec3 C=(c(0)+en.y*((c(1)+c(4)*en.x)+c(5)*en.z))+en.x*(c(3)+c(7)*en.z)+c(2)*en.z;\n#undef c\nvec3 sqr=en*en;C+=uDiffuseCoefficients[6].xyz*(3.0*sqr.z-1.0);C+=uDiffuseCoefficients[8].xyz*(sqr.x-sqr.y);return C;}void eo(inout vec3 eu,inout vec3 ev,inout vec3 eA,vec3 en){eu=uDiffuseCoefficients[0].xyz;ev=uDiffuseCoefficients[1].xyz*en.y;ev+=uDiffuseCoefficients[2].xyz*en.z;ev+=uDiffuseCoefficients[3].xyz*en.x;vec3 swz=en.yyz*en.xzx;eA=uDiffuseCoefficients[4].xyz*swz.x;eA+=uDiffuseCoefficients[5].xyz*swz.y;eA+=uDiffuseCoefficients[7].xyz*swz.z;vec3 sqr=en*en;eA+=uDiffuseCoefficients[6].xyz*(3.0*sqr.z-1.0);eA+=uDiffuseCoefficients[8].xyz*(sqr.x-sqr.y);}vec3 eB(vec3 eu,vec3 ev,vec3 eA,vec3 eC,float ec){eC=mix(vec3(1.0),eC,ec);return(eu+ev*eC.x)+eA*eC.z;}vec3 eD(vec3 eu,vec3 ev,vec3 eA,vec3 eC,vec3 eE){vec3 eF=mix(vec3(1.0),eC.yyy,eE);vec3 eG=mix(vec3(1.0),eC.zzz,eE);return(eu+ev*eF)+eA*eG;}vec3 dB(vec3 en,float V){en/=dot(vec3(1.0),abs(en));vec2 eH=abs(en.zx)-vec2(1.0,1.0);vec2 eI=vec2(en.x<0.0?eH.x:-eH.x,en.z<0.0?eH.y:-eH.y);vec2 eJ=(en.y<0.0)?eI:en.xz;eJ=vec2(0.5*(254.0/256.0),0.125*0.5*(254.0/256.0))*eJ+vec2(0.5,0.125*0.5);float eK=fract(7.0*V);eJ.y+=0.125*(7.0*V-eK);vec2 eL=eJ+vec2(0.0,0.125);vec4 eM=mix(texture2D(tSkySpecular,eJ),texture2D(tSkySpecular,eL),eK);vec3 r=eM.xyz*(7.0*eM.w);return r*r;}float dC(vec3 en,vec3 eN){float eO=dot(en,eN);eO=saturate(1.0+uHorizonOcclude*eO);return eO*eO;}",
  3522. "matmicrofiber.glsl": "\n#ifdef MICROFIBER\nuniform vec4 uTexRangeFuzz;uniform float uFresnelIntegral;uniform vec4 uFresnelColor;uniform float uFresnelOcc;uniform float uFresnelGlossMask;struct dj{vec3 dm;vec3 dQ;vec3 eP;vec3 eQ;vec3 eR;};void dl(out dj s,vec3 N){s.dm=s.dQ=du(N);s.eP=vec3(0.0);s.eQ=uFresnelColor.rgb;s.eR=uFresnelColor.aaa*vec3(1.0,0.5,0.25);\n#ifndef MICROFIBER_NO_FUZZ_TEX\nvec4 J=R(j,uTexRangeFuzz);s.eQ*=L(J.rgb);\n#endif\n}void dP(inout dj s,float eS,vec3 dK,vec3 N,vec3 dM){float dZ=dot(dK,N);float dQ=saturate((1.0/3.1415926)*dZ);float eT=dY(dZ,s.eR.z);\n#ifdef SHADOW_COUNT\ndQ*=eS;float eU=mix(1.0,eS,uFresnelOcc);float eP=eT*eU;\n#else \nfloat eP=eT;\n#endif\ns.eP=eP*dM+s.eP;s.dQ=dQ*dM+s.dQ;}void dU(out vec3 dn,out vec3 diff_extra,inout dj s,vec3 T,vec3 N,float V){s.eP*=uFresnelIntegral;float el=dot(T,N);vec2 eV=ek(vec2(el,el),s.eR.xy);s.eP=s.dm*eV.x+(s.eP*eV.y);s.eP*=s.eQ;float eW=saturate(1.0+-uFresnelGlossMask*V);s.eP*=eW*eW;dn=s.dQ;diff_extra=s.eP;}\n#endif\n",
  3523. "matsampling.glsl": "vec3 L(vec3 c){return c*c;}vec3 On(vec3 n,float s){vec3 eX=E;vec3 eY=F;vec3 eZ=gl_FrontFacing?G:-G;\n#ifdef TSPACE_RENORMALIZE\neZ=normalize(eZ);\n#endif\n#ifdef TSPACE_ORTHOGONALIZE\neX-=dot(eX,eZ)*eZ;\n#endif\n#ifdef TSPACE_RENORMALIZE\neX=normalize(eX);\n#endif\n#ifdef TSPACE_ORTHOGONALIZE\neY=(eY-dot(eY,eZ)*eZ)-dot(eY,eX)*eX;\n#endif\n#ifdef TSPACE_RENORMALIZE\neY=normalize(eY);\n#endif\n#ifdef TSPACE_COMPUTE_BITANGENT\nvec3 fc=cross(eZ,eX);eY=dot(fc,eY)<0.0?-fc:fc;\n#endif\n n=2.0*n-vec3(1.0); n.x*=s;n.y*=s;if(n.z>=0.0){n.z=1.0-(1.0-n.z)*s;}else if(s==0.0){n.z=1.0;}else{n.z=(1.0+n.z)*s-1.0;}return normalize(eX*n.x+eY*n.y+eZ*n.z);}vec3 O(vec3 n){vec3 eX=E;vec3 eY=F;vec3 eZ=gl_FrontFacing?G:-G;\n#ifdef TSPACE_RENORMALIZE\neZ=normalize(eZ);\n#endif\n#ifdef TSPACE_ORTHOGONALIZE\neX-=dot(eX,eZ)*eZ;\n#endif\n#ifdef TSPACE_RENORMALIZE\neX=normalize(eX);\n#endif\n#ifdef TSPACE_ORTHOGONALIZE\neY=(eY-dot(eY,eZ)*eZ)-dot(eY,eX)*eX;\n#endif\n#ifdef TSPACE_RENORMALIZE\neY=normalize(eY);\n#endif\n#ifdef TSPACE_COMPUTE_BITANGENT\nvec3 fc=cross(eZ,eX);eY=dot(fc,eY)<0.0?-fc:fc;\n#endif\nn=2.0*n-vec3(1.0);return normalize(eX*n.x+eY*n.y+eZ*n.z);}vec3 Q(vec3 t){vec3 eZ=gl_FrontFacing?G:-G;return normalize(E*t.x+F*t.y+eZ*t.z);}vec4 R(vec2 fd,vec4 fe){\n#if GL_OES_standard_derivatives\nvec2 ff=fract(fd);vec2 fh=fwidth(ff);float fi=(fh.x+fh.y)>0.5?-6.0:0.0;return texture2D(tExtras,ff*fe.xy+fe.zw,fi);\n#else\nreturn texture2D(tExtras,fract(fd)*fe.xy+fe.zw);\n#endif\n}vec3 fj(sampler2D fk,vec2 fl,float fm){vec3 n=texture2D(fk,fl,fm*4.0).xyz;return O(n);}",
  3524. // "matsampling.glsl": "vec3 L(vec3 c){return c*c;}vec3 O(vec3 n){vec3 eX=E;vec3 eY=F;vec3 eZ=gl_FrontFacing?G:-G;\n#ifdef TSPACE_RENORMALIZE\neZ=normalize(eZ);\n#endif\n#ifdef TSPACE_ORTHOGONALIZE\neX-=dot(eX,eZ)*eZ;\n#endif\n#ifdef TSPACE_RENORMALIZE\neX=normalize(eX);\n#endif\n#ifdef TSPACE_ORTHOGONALIZE\neY=(eY-dot(eY,eZ)*eZ)-dot(eY,eX)*eX;\n#endif\n#ifdef TSPACE_RENORMALIZE\neY=normalize(eY);\n#endif\n#ifdef TSPACE_COMPUTE_BITANGENT\nvec3 fc=cross(eZ,eX);eY=dot(fc,eY)<0.0?-fc:fc;\n#endif\nn=2.0*n-vec3(1.0);return normalize(eX*n.x+eY*n.y+eZ*n.z);}vec3 Q(vec3 t){vec3 eZ=gl_FrontFacing?G:-G;return normalize(E*t.x+F*t.y+eZ*t.z);}vec4 R(vec2 fd,vec4 fe){\n#if GL_OES_standard_derivatives\nvec2 ff=fract(fd);vec2 fh=fwidth(ff);float fi=(fh.x+fh.y)>0.5?-6.0:0.0;return texture2D(tExtras,ff*fe.xy+fe.zw,fi);\n#else\nreturn texture2D(tExtras,fract(fd)*fe.xy+fe.zw);\n#endif\n}vec3 fj(sampler2D fk,vec2 fl,float fm, float strength){vec3 n=texture2D(fk,fl,fm*4.0).xyz; float s=strength/100.0; n.x*=s; n.y*=s; n.z*=s;return O(n);}",
  3525. "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 m(highp mat4 o,highp vec3 p){return o[0]*p.x+(o[1]*p.y+(o[2]*p.z+o[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 vec4 uShadowMapSize;uniform highp mat4 uShadowMatrices[SHADOW_COUNT];uniform highp vec4 uShadowTexelPadProjections[SHADOW_COUNT];highp float fn(highp vec3 C){return(C.x+C.y*(1.0/255.0))+C.z*(1.0/65025.0);}float fo(sampler2D fu,highp vec2 fd,highp float fv){\n#ifndef MOBILE\nhighp vec2 c=fd*uShadowMapSize.xy;highp vec2 a=floor(c)*uShadowMapSize.zw,b=ceil(c)*uShadowMapSize.zw;vec4 fA;fA.x=fv<fn(texture2D(fu,a).xyz)?1.0:0.0;fA.y=fv<fn(texture2D(fu,vec2(b.x,a.y)).xyz)?1.0:0.0;fA.z=fv<fn(texture2D(fu,vec2(a.x,b.y)).xyz)?1.0:0.0;fA.w=fv<fn(texture2D(fu,b).xyz)?1.0:0.0;highp vec2 w=c-a*uShadowMapSize.xy;vec2 t=(w.y*fA.zw+fA.xy)-w.y*fA.xy;return(w.x*t.y+t.x)-w.x*t.x;\n#else\nhighp float C=fn(texture2D(fu,fd.xy).xyz);return fv<C?1.0:0.0;\n#endif\n}float fB(sampler2D fu,highp vec3 fd,float fC){highp vec2 v=uShadowKernelRotation*fC;float s;s=fo(fu,fd.xy+v,fd.z);s+=fo(fu,fd.xy-v,fd.z);s+=fo(fu,fd.xy+vec2(-v.y,v.x),fd.z);s+=fo(fu,fd.xy+vec2(v.y,-v.x),fd.z);s*=0.25;return s*s;}struct dF{float dO[LIGHT_COUNT];};void dH(out dF ss,float fC){highp vec3 fD[SHADOW_COUNT];vec3 eZ=gl_FrontFacing?G:-G;for(int u=0;u<SHADOW_COUNT;++u){vec4 fE=uShadowTexelPadProjections[u];float fF=fE.x*D.x+(fE.y*D.y+(fE.z*D.z+fE.w));\n#ifdef MOBILE\nfF*=.001+fC;\n#else\nfF*=.0005+0.5*fC;\n#endif\nhighp vec4 fG=m(uShadowMatrices[u],D+fF*eZ);fD[u]=fG.xyz/fG.w;}\n#if SHADOW_COUNT > 0\nss.dO[0]=fB(tDepth0,fD[0],fC);\n#endif\n#if SHADOW_COUNT > 1\nss.dO[1]=fB(tDepth1,fD[1],fC);\n#endif\n#if SHADOW_COUNT > 2\nss.dO[2]=fB(tDepth2,fD[2],fC);\n#endif\nfor(int u=SHADOW_COUNT;u<LIGHT_COUNT;++u){ss.dO[u]=1.0;}}\n#endif\n",
  3526. "matskin.glsl": "\n#ifdef SKIN\nuniform vec4 uTexRangeSubdermis;uniform vec4 uTexRangeTranslucency;uniform vec4 uTexRangeFuzz;uniform vec3 uSubdermisColor;uniform vec4 uTransColor;uniform vec4 uFresnelColor;uniform float uFresnelOcc;uniform float uFresnelGlossMask;uniform float uTransSky;uniform float uFresnelIntegral;uniform float uTransIntegral;uniform float uSkinShadowBlur;uniform float uNormalSmooth;struct de{vec3 fH;vec3 fI,fJ,fK,eP;vec3 di,dm,fL;vec3 fM;vec3 fN;vec3 fO;vec3 fP;float fQ;float fR;float dJ;};void dh(out de s){vec4 J;\n#ifdef SKIN_NO_SUBDERMIS_TEX\ns.fH=uSubdermisColor;s.fR=1.0;\n#else \nJ=R(j,uTexRangeSubdermis);s.fH=L(J.xyz);s.fR=J.w*J.w;\n#endif\ns.fP=uTransColor.rgb;s.fQ=uTransColor.a;\n#ifndef SKIN_NO_TRANSLUCENCY_TEX\nJ=R(j,uTexRangeTranslucency);s.fP*=L(J.xyz);\n#endif\n s.fM=fj(tNormal,j,uNormalSmooth*s.fR); vec3 fS,fT,fU;eo(fS,fT,fU,s.fM);s.dm=s.fI=fS+fT+fU;s.di=eD(fS,fT,fU,vec3(1.0,0.6667,0.25),s.fH);vec3 fV,fW,fX;eo(fV,fW,fX,-s.fM);s.fL=eB(fV,fW,fX,vec3(1.0,0.4444,0.0625),s.fQ);s.fL*=uTransSky;s.fJ=s.fK=s.eP=vec3(0.0);s.dJ=uSkinShadowBlur*s.fR;s.fH*=0.5;s.fQ*=0.5;s.fN=uFresnelColor.rgb;s.fO=uFresnelColor.aaa*vec3(1.0,0.5,0.25);\n#ifndef SKIN_NO_FUZZ_TEX\nJ=R(j,uTexRangeFuzz);s.fN*=L(J.rgb);\n#endif\n}void dN(inout de s,float eS,float fY,vec3 dK,vec3 N,vec3 dM){float dZ=dot(dK,N);float fZ=dot(dK,s.fM);float dQ=saturate((1.0/3.1415926)*dZ);vec3 hc=ed(fZ,s.fH);float hd=dY(-fZ,s.fQ);vec3 fK=vec3(hd*hd);\n#ifdef SHADOW_COUNT\nfloat he=fY;vec3 hf=vec3(fY);float hh=saturate(eS-2.0*(fY*fY));hf+=hh*s.fH;\n#endif\nfloat eT=dY(fZ,s.fO.z);\n#ifdef SHADOW_COUNT\nvec3 eU=mix(vec3(1.0),hf,uFresnelOcc);vec3 eP=eT*eU;\n#else\nvec3 eP=vec3(eT);\n#endif\n#ifdef SHADOW_COUNT\nhc*=hf;fK*=he;dQ*=eS;\n#endif\ns.eP=eP*dM+s.eP;s.fK=fK*dM+s.fK;s.fJ=hc*dM+s.fJ;s.fI=dQ*dM+s.fI;}void dT(out vec3 dn,out vec3 diff_extra,inout de s,vec3 T,vec3 N,float V){s.eP*=uFresnelIntegral;float el=dot(T,N);vec2 eV=ek(vec2(el,el),s.fO.xy);s.eP=s.dm*eV.x+(s.eP*eV.y);s.eP*=s.fN;float eW=saturate(1.0+-uFresnelGlossMask*V);s.eP*=eW*eW;s.fJ=s.fJ*ef(s.fH)+s.di;s.fK=s.fK*uTransIntegral+s.fL;s.fK*=s.fP;dn=mix(s.fI,s.fJ,s.fR);diff_extra=(s.eP+s.fK)*s.fR;}\n#endif\n",
  3527. // "matskin.glsl": "\n#ifdef SKIN\nuniform vec4 uTexRangeSubdermis;uniform vec4 uTexRangeTranslucency;uniform vec4 uTexRangeFuzz;uniform vec3 uSubdermisColor;uniform vec4 uTransColor;uniform vec4 uFresnelColor;uniform float uFresnelOcc;uniform float uFresnelGlossMask;uniform float uTransSky;uniform float uFresnelIntegral;uniform float uTransIntegral;uniform float uSkinShadowBlur;uniform float uNormalSmooth;struct de{vec3 fH;vec3 fI,fJ,fK,eP;vec3 di,dm,fL;vec3 fM;vec3 fN;vec3 fO;vec3 fP;float fQ;float fR;float dJ;};void dh(out de s){vec4 J;\n#ifdef SKIN_NO_SUBDERMIS_TEX\ns.fH=uSubdermisColor;s.fR=1.0;\n#else \nJ=R(j,uTexRangeSubdermis);s.fH=L(J.xyz);s.fR=J.w*J.w;\n#endif\ns.fP=uTransColor.rgb;s.fQ=uTransColor.a;\n#ifndef SKIN_NO_TRANSLUCENCY_TEX\nJ=R(j,uTexRangeTranslucency);s.fP*=L(J.xyz);\n#endif\n s.fM=fj(tNormal,j,uNormalSmooth*s.fR,uNormalStrength); vec3 fS,fT,fU;eo(fS,fT,fU,s.fM);s.dm=s.fI=fS+fT+fU;s.di=eD(fS,fT,fU,vec3(1.0,0.6667,0.25),s.fH);vec3 fV,fW,fX;eo(fV,fW,fX,-s.fM);s.fL=eB(fV,fW,fX,vec3(1.0,0.4444,0.0625),s.fQ);s.fL*=uTransSky;s.fJ=s.fK=s.eP=vec3(0.0);s.dJ=uSkinShadowBlur*s.fR;s.fH*=0.5;s.fQ*=0.5;s.fN=uFresnelColor.rgb;s.fO=uFresnelColor.aaa*vec3(1.0,0.5,0.25);\n#ifndef SKIN_NO_FUZZ_TEX\nJ=R(j,uTexRangeFuzz);s.fN*=L(J.rgb);\n#endif\n}void dN(inout de s,float eS,float fY,vec3 dK,vec3 N,vec3 dM){float dZ=dot(dK,N);float fZ=dot(dK,s.fM);float dQ=saturate((1.0/3.1415926)*dZ);vec3 hc=ed(fZ,s.fH);float hd=dY(-fZ,s.fQ);vec3 fK=vec3(hd*hd);\n#ifdef SHADOW_COUNT\nfloat he=fY;vec3 hf=vec3(fY);float hh=saturate(eS-2.0*(fY*fY));hf+=hh*s.fH;\n#endif\nfloat eT=dY(fZ,s.fO.z);\n#ifdef SHADOW_COUNT\nvec3 eU=mix(vec3(1.0),hf,uFresnelOcc);vec3 eP=eT*eU;\n#else\nvec3 eP=vec3(eT);\n#endif\n#ifdef SHADOW_COUNT\nhc*=hf;fK*=he;dQ*=eS;\n#endif\ns.eP=eP*dM+s.eP;s.fK=fK*dM+s.fK;s.fJ=hc*dM+s.fJ;s.fI=dQ*dM+s.fI;}void dT(out vec3 dn,out vec3 diff_extra,inout de s,vec3 T,vec3 N,float V){s.eP*=uFresnelIntegral;float el=dot(T,N);vec2 eV=ek(vec2(el,el),s.fO.xy);s.eP=s.dm*eV.x+(s.eP*eV.y);s.eP*=s.fN;float eW=saturate(1.0+-uFresnelGlossMask*V);s.eP*=eW*eW;s.fJ=s.fJ*ef(s.fH)+s.di;s.fK=s.fK*uTransIntegral+s.fL;s.fK*=s.fP;dn=mix(s.fI,s.fJ,s.fR);diff_extra=(s.eP+s.fK)*s.fR;}\n#endif\n",
  3528. "matstrips.glsl": "\n#ifdef STRIPVIEW\nuniform float uStrips[5];uniform vec2 uStripRes;struct Y{float hi[5];float bg;};void dc(out Y hj,inout float V,inout vec3 U){highp vec2 fd=gl_FragCoord.xy*uStripRes-vec2(1.0,1.0);fd.x+=0.25*fd.y;hj.hi[0]=step(fd.x,uStrips[0]);hj.hi[1]=step(fd.x,uStrips[1]);hj.hi[2]=step(fd.x,uStrips[2]);hj.hi[3]=step(fd.x,uStrips[3]);hj.hi[4]=step(fd.x,uStrips[4]);hj.bg=1.0-hj.hi[4];hj.hi[4]-=hj.hi[3];hj.hi[3]-=hj.hi[2];hj.hi[2]-=hj.hi[1];hj.hi[1]-=hj.hi[0];bool hk=hj.hi[4]>0.0;V=hk?0.5:V;U=hk?vec3(0.1):U;}vec3 dX(Y hj,vec3 N,vec3 K,vec3 U,float V,vec3 dn,vec3 dA,vec3 hl){return hj.hi[0]*(N*0.5+vec3(0.5))+hj.hi[1]*K+hj.hi[2]*U+vec3(hj.hi[3]*V)+hj.hi[4]*(vec3(0.12)+0.3*dn+dA)+hj.bg*hl;}\n#endif\n",
  3529. "matvert.glsl": "precision highp float;uniform mat4 uModelViewProjectionMatrix;uniform mat4 uSkyMatrix;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 D;varying mediump vec2 j;varying mediump vec3 E;varying mediump vec3 F;varying mediump vec3 G;\n#ifdef VERTEX_COLOR\nvarying lowp vec4 H;\n#endif\n#ifdef TEXCOORD_SECONDARY\nvarying mediump vec2 I;\n#endif\nvec3 hm(vec2 hn){bool ho=(hn.y>(32767.1/65535.0));hn.y=ho?(hn.y-(32768.0/65535.0)):hn.y;vec3 r;r.xy=(2.0*65535.0/32767.0)*hn-vec2(1.0);r.z=sqrt(clamp(1.0-dot(r.xy,r.xy),0.0,1.0));r.z=ho?-r.z:r.z;return r;}vec4 m(mat4 o,vec3 p){return o[0]*p.x+(o[1]*p.y+(o[2]*p.z+o[3]));}vec3 hu(mat4 o,vec3 hn){return o[0].xyz*hn.x+o[1].xyz*hn.y+o[2].xyz*hn.z;}void main(void){gl_Position=m(uModelViewProjectionMatrix,vPosition.xyz);j=vTexCoord;E=hu(uSkyMatrix,hm(vTangent));F=hu(uSkyMatrix,hm(vBitangent));G=hu(uSkyMatrix,hm(vNormal));D=m(uSkyMatrix,vPosition.xyz).xyz;\n#ifdef VERTEX_COLOR\nH=vColor;\n#endif\n#ifdef TEXCOORD_SECONDARY\nI=vTexCoord2;\n#endif\n}",
  3530. // "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 d;vec3 hv(vec3 c){vec3 hA=sqrt(c);return(hA-hA*c)+c*(0.4672*c+vec3(0.5328));}void main(void){vec4 hB=texture2D(tInput,d);vec3 c=hB.xyz;\n#ifdef SHARPEN\nvec3 fA=texture2D(tInput,d+uSharpenKernel.xy).xyz;fA+=texture2D(tInput,d-uSharpenKernel.xy).xyz;fA+=texture2D(tInput,d+uSharpenKernel.zw).xyz;fA+=texture2D(tInput,d-uSharpenKernel.zw).xyz;vec3 hC=uSharpness.x*c-uSharpness.y*fA;c+=clamp(hC,-uSharpness.z,uSharpness.z);\n#endif\n#ifdef BLOOM\nc+=uBloomColor*texture2D(tBloom,d).xyz;\n#endif\n#ifdef VIGNETTE\nvec2 hD=d*uVignetteAspect.xy-uVignetteAspect.zw;vec3 hn=clamp(vec3(1.0,1.0,1.0)-uVignette.xyz*dot(hD,hD),0.0,1.0);vec3 hE=hn*hn;hE*=hn;c*=mix(hn,hE,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 hF=uGrainScaleBias.x*texture2D(tGrain,d*uGrainCoord.xy+uGrainCoord.zw).x+uGrainScaleBias.y;c+=c*hF;\n#endif\n#ifdef REINHARD\n{c*=1.8;float hG=dot(c,vec3(0.3333));c=clamp(c/(1.0+hG),0.0,1.0);}\n#elif defined(HEJL)\n{const highp float hH=0.22,hI=0.3,hJ=.1,hK=0.2,hL=.01,hM=0.3;const highp float hN=1.25;highp vec3 dR=max(vec3(0.0),c-vec3(.004));c=(dR*((hN*hH)*dR+hN*vec3(hJ*hI,hJ*hI,hJ*hI))+hN*vec3(hK*hL,hK*hL,hK*hL))/(dR*(hH*dR+vec3(hI,hI,hI))+vec3(hK*hM,hK*hM,hK*hM))-hN*vec3(hL/hM,hL/hM,hL/hM);}\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=hv(c);gl_FragColor.w=hB.w;}",
  3531. /* 原本背景为单色时显示和指定颜色有微差,现在改掉了 */ "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 d;vec3 hv(vec3 c){vec3 hA=sqrt(c);return(hA-hA*c)+c*(0.4672*c+vec3(0.5328));}void main(void){vec4 hB=texture2D(tInput,d);vec3 c=hB.xyz;\n#ifdef SHARPEN\nvec3 fA=texture2D(tInput,d+uSharpenKernel.xy).xyz;fA+=texture2D(tInput,d-uSharpenKernel.xy).xyz;fA+=texture2D(tInput,d+uSharpenKernel.zw).xyz;fA+=texture2D(tInput,d-uSharpenKernel.zw).xyz;vec3 hC=uSharpness.x*c-uSharpness.y*fA;c+=clamp(hC,-uSharpness.z,uSharpness.z);\n#endif\n#ifdef BLOOM\nc+=uBloomColor*texture2D(tBloom,d).xyz;\n#endif\n#ifdef VIGNETTE\nvec2 hD=d*uVignetteAspect.xy-uVignetteAspect.zw;vec3 hn=clamp(vec3(1.0,1.0,1.0)-uVignette.xyz*dot(hD,hD),0.0,1.0);vec3 hE=hn*hn;hE*=hn;c*=mix(hn,hE,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 hF=uGrainScaleBias.x*texture2D(tGrain,d*uGrainCoord.xy+uGrainCoord.zw).x+uGrainScaleBias.y;c+=c*hF;\n#endif\n#ifdef REINHARD\n{c*=1.8;float hG=dot(c,vec3(0.3333));c=clamp(c/(1.0+hG),0.0,1.0);}\n#elif defined(HEJL)\n{const highp float hH=0.22,hI=0.3,hJ=.1,hK=0.2,hL=.01,hM=0.3;const highp float hN=1.25;highp vec3 dR=max(vec3(0.0),c-vec3(.004));c=(dR*((hN*hH)*dR+hN*vec3(hJ*hI,hJ*hI,hJ*hI))+hN*vec3(hK*hL,hK*hL,hK*hL))/(dR*(hH*dR+vec3(hI,hI,hI))+vec3(hK*hM,hK*hM,hK*hM))-hN*vec3(hL/hM,hL/hM,hL/hM);}\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\n #ifdef SINGLECOLOR \n gl_FragColor=hB; \n#else\n gl_FragColor.xyz=hv(c); gl_FragColor.w=hB.w;\n#endif\n}",
  3532. "postvert.glsl": "precision highp float;attribute vec2 vCoord;varying vec2 d;void main(void){d=vCoord;gl_Position.xy=2.0*vCoord-vec2(1.0,1.0);gl_Position.zw=vec2(0.0,1.0);}",
  3533. "shadowfrag.glsl": "precision highp float;varying vec2 hO;\n#ifdef ALPHA_TEST\nvarying mediump vec2 j;uniform sampler2D tAlbedo;\n#endif\nvec3 hP(float hn){vec4 hQ=vec4(1.0,255.0,65025.0,16581375.0)*hn;hQ=fract(hQ);hQ.xyz-=hQ.yzw*(1.0/255.0);return hQ.xyz;}void main(void){\n#ifdef ALPHA_TEST\nfloat k=texture2D(tAlbedo,j).a;if(k<0.5){discard;}\n#endif\ngl_FragColor.xyz=hP((hO.x/hO.y)*0.5+0.5);gl_FragColor.w=0.0;}",
  3534. "shadowvert.glsl": "precision highp float;attribute vec3 vPosition;attribute vec2 vTexCoord;uniform mat4 uViewProjection;varying vec2 hO;\n#ifdef ALPHA_TEST\nvarying mediump vec2 j;\n#endif\nvec4 m(mat4 o,vec3 p){return o[0]*p.x+(o[1]*p.y+(o[2]*p.z+o[3]));}void main(void){gl_Position=m(uViewProjection,vPosition);hO=gl_Position.zw;\n#ifdef ALPHA_TEST\nj=vTexCoord;\n#endif\n}",
  3535. "sky.glsl": "precision highp float;uniform sampler2D tSkyTexture;uniform float uAlpha;varying vec2 j;void main(void){vec3 r=texture2D(tSkyTexture,j).xyz;gl_FragColor.xyz=r*r;gl_FragColor.w=uAlpha;}",
  3536. "skySH.glsl": "precision mediump float;uniform vec4 uSkyCoefficients[9];uniform float uAlpha;varying vec3 hR;void main(void){vec3 C=normalize(hR);vec3 r=uSkyCoefficients[0].xyz;r+=uSkyCoefficients[1].xyz*C.y;r+=uSkyCoefficients[2].xyz*C.z;r+=uSkyCoefficients[3].xyz*C.x;vec3 swz=C.yyz*C.xzx;r+=uSkyCoefficients[4].xyz*swz.x;r+=uSkyCoefficients[5].xyz*swz.y;r+=uSkyCoefficients[7].xyz*swz.z;vec3 sqr=C*C;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;}",
  3537. "skyvert.glsl": "precision highp float;uniform mat4 uInverseSkyMatrix;uniform mat4 uViewProjection;attribute vec3 vPosition;attribute vec2 vTexCoord;\n#if SKYMODE == 3\nvarying vec3 hR;\n#else\nvarying vec2 j;\n#endif\nvec4 m(mat4 o,vec3 p){return o[0]*p.x+(o[1]*p.y+(o[2]*p.z+o[3]));}vec4 hu(mat4 o,vec3 hn){return o[0]*hn.x+o[1]*hn.y+o[2]*hn.z;}void main(void){vec3 p=m(uInverseSkyMatrix,vPosition).xyz;gl_Position=hu(uViewProjection,p);gl_Position.z-=(1.0/65535.0)*gl_Position.w;\n#if SKYMODE == 3\nhR=vPosition;hR.xy+=1e-20*vTexCoord;\n#else\nj=vTexCoord;\n#endif\n}",
  3538. "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);}",
  3539. "wirevert.glsl": "precision highp float;uniform mat4 uModelViewProjectionMatrix;attribute vec3 vPosition;vec4 m(mat4 o,vec3 p){return o[0]*p.x+(o[1]*p.y+(o[2]*p.z+o[3]));}void main(void){gl_Position=m(uModelViewProjectionMatrix,vPosition);gl_Position.z+=-0.00005*gl_Position.w;}",
  3540. nil: ""
  3541. };
  3542. })(fdage);