var dom = {}; dom.addClass = function(elem, className) { if (elem.className === undefined) { elem.className = className; } else if (elem.className !== className) { var classes = elem.className.split(/ +/); if (classes.indexOf(className) == -1) { classes.push(className); elem.className = classes.join(' ').replace(/^\s+/, '').replace(/\s+$/, ''); } } } dom.removeClass = function(elem, className) { if (className) { if (elem.className === undefined) { // elem.className = className; }else if (elem.className === className) { elem.removeAttribute('class'); }else{ var classes = elem.className.split(/ +/); var index = classes.indexOf(className); if(index != -1){ classes.splice(index, 1); elem.className = classes.join(' '); } } }else{ elem.className = undefined; } } dom.hasClass = function(elem, className) { return new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)').test(elem.className) || false; } var fdage = {}; if (typeof define === "function" && define.amd) define(fdage); else if (typeof module === "object" && module.exports) module.exports = fdage; (function(fdage) { 'use strict'; function Archive(a) { this.files = []; for (a = new ByteStream(a); !a.empty(); ) { var b = {}; b.name = a.readCString(); b.type = a.readCString(); var c = a.readUint32() , d = a.readUint32() , e = a.readUint32(); b.data = a.readBytes(d); if (!(b.data.length < d)) { if (c & 1 && (b.data = this.decompress(b.data, e), null === b.data)) continue;this.files[b.name] = b } } } Archive.prototype.get = function(a) { return this.files[a] } ; Archive.prototype.extract = function(a) { var b = this.files[a]; delete this.files[a]; return b } ; Archive.prototype.checkSignature = function(a) { if (!a) return !1; var b = this.get(a.name + ".sig"); if (!b) return !1; b = JSON.parse(String.fromCharCode.apply(null , b.data)); if (!b) return !1; for (var c = 5381, d = 0; d < a.data.length; ++d) c = 33 * c + a.data[d] & 4294967295; a = new BigInt; 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); d = new BigInt; d.setBytes(b[0]); return d.powmod(65537, a).toInt32() != c ? !1 : !0 } ; Archive.prototype.decompress = function(a, b) { var c = new Uint8Array(b) , d = 0 , e = new Uint32Array(4096) , f = new Uint32Array(4096) , g = 256 , h = a.length , k = 0 , l = 1 , m = 0 , n = 1; c[d++] = a[0]; for (var r = 1; ; r++) { n = r + (r >> 1); if (n + 1 >= h) break; var m = a[n + 1] , n = a[n] , p = r & 1 ? m << 4 | n >> 4 : (m & 15) << 8 | n; if (p < g) if (256 > p) m = d, n = 1, c[d++] = p; else for (var m = d, n = f[p], p = e[p], q = p + n; p < q; ) c[d++] = c[p++]; else if (p == g) { m = d; n = l + 1; p = k; for (q = k + l; p < q; ) c[d++] = c[p++]; c[d++] = c[k] } else break; e[g] = k; f[g++] = l + 1; k = m; l = n; g = 4096 <= g ? 256 : g } return d == b ? c : null }; function BigInt(a) { this.digits = new Uint16Array(a || 0) } BigInt.prototype.setBytes = function(a, b) { var c = (a.length + 1) / 2 | 0; this.digits = new Uint16Array(c); if (b) for (var d = 0, c = a.length - 1; 0 <= c; c -= 2) this.digits[d++] = a[c] + (0 < c ? 256 * a[c - 1] : 0); else for (d = 0; d < c; ++d) this.digits[d] = a[2 * d] + 256 * a[2 * d + 1]; this.trim() } ; BigInt.prototype.toInt32 = function() { var a = 0; 0 < this.digits.length && (a = this.digits[0], 1 < this.digits.length && (a |= this.digits[1] << 16)); return a } ; BigInt.prototype.lessThan = function(a) { if (this.digits.length == a.digits.length) for (var b = this.digits.length - 1; 0 <= b; --b) { var c = this.digits[b] , d = a.digits[b]; if (c != d) return c < d } return this.digits.length < a.digits.length } ; BigInt.prototype.shiftRight = function() { for (var a = 0, b = this.digits, c = b.length - 1; 0 <= c; --c) { var d = b[c]; b[c] = d >> 1 | a << 15; a = d } this.trim() } ; BigInt.prototype.shiftLeft = function(a) { if (0 < a) { var b = a / 16 | 0; a %= 16; for (var c = 16 - a, d = this.digits.length + b + 1, e = new BigInt(d), f = 0; f < d; ++f) e.digits[f] = ((f < b || f >= this.digits.length + b ? 0 : this.digits[f - b]) << a | (f < b + 1 ? 0 : this.digits[f - b - 1]) >>> c) & 65535; e.trim(); return e } return new BigInt(this) } ; BigInt.prototype.bitCount = function() { var a = 0; if (0 < this.digits.length) for (var a = 16 * (this.digits.length - 1), b = this.digits[this.digits.length - 1]; b; ) b >>>= 1, ++a; return a } ; BigInt.prototype.sub = function(a) { var b = this.digits , c = a.digits , d = this.digits.length; a = a.digits.length; for (var e = 0, f = 0; f < d; ++f) { var g = b[f] , h = f < a ? c[f] : 0 , h = h + e , e = h > g ? 1 : 0 , g = g + (e << 16); b[f] = g - h & 65535 } this.trim() } ; BigInt.prototype.mul = function(a) { for (var b = new BigInt(this.digits.length + a.digits.length), c = b.digits, d = 0; d < this.digits.length; ++d) for (var e = this.digits[d], f = 0; f < a.digits.length; ++f) for (var g = e * a.digits[f], h = d + f; g; ) { var k = (g & 65535) + c[h]; c[h] = k & 65535; g >>>= 16; g += k >>> 16; ++h } b.trim(); return b } ; BigInt.prototype.mod = function(a) { if (0 >= this.digits.length || 0 >= a.digits.length) return new BigInt(0); var b = new BigInt(this.digits); if (!this.lessThan(a)) { for (var c = new BigInt(a.digits), c = c.shiftLeft(b.bitCount() - c.bitCount()); !b.lessThan(a); ) c.lessThan(b) && b.sub(c), c.shiftRight(); b.trim() } return b } ; BigInt.prototype.powmod = function(a, b) { for (var c = new BigInt([1]), d = this.mod(b); a; ) a & 1 && (c = c.mul(d).mod(b)), a >>>= 1, d = d.mul(d).mod(b); return c } ; BigInt.prototype.trim = function() { for (var a = this.digits.length; 0 < a && 0 == this.digits[a - 1]; ) --a; a != this.digits.length && (this.digits = this.digits.subarray(0, a)) } ; function Bounds(a) { for (var b = 0; b < a.length; ++b) { var c = a[b].bounds; if (void 0 === this.min) this.min = [c.min[0], c.min[1], c.min[2]], this.max = [c.max[0], c.max[1], c.max[2]]; else for (var d = 0; 3 > d; ++d) this.min[d] = Math.min(c.min[d], this.min[d]), this.max[d] = Math.max(c.max[d], this.max[d]) } this.min = this.min ? this.min : [0, 0, 0]; this.max = this.max ? this.max : [0, 0, 0]; 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])]; this.radius = [this.max[0] - this.center[0], this.max[1] - this.center[1], this.max[2] - this.center[2]] } ;function ByteStream(a) { this.bytes = new Uint8Array(a) } ByteStream.prototype.empty = function() { return 0 >= this.bytes.length } ; ByteStream.prototype.readCString = function() { for (var a = this.bytes, b = a.length, c = 0; c < b; ++c) if (0 == a[c]) return a = String.fromCharCode.apply(null , this.bytes.subarray(0, c)), this.bytes = this.bytes.subarray(c + 1), a; return null } ; ByteStream.prototype.asString = function() { for (var a = "", b = 0; b < this.bytes.length; ++b) a += String.fromCharCode(this.bytes[b]); return a } ; ByteStream.prototype.readBytes = function(a) { var b = this.bytes.subarray(0, a); this.bytes = this.bytes.subarray(a); return b } ; ByteStream.prototype.readUint32 = function() { var a = this.bytes , b = a[0] | a[1] << 8 | a[2] << 16 | a[3] << 24; this.bytes = a.subarray(4); return b } ; var prepareEmbedParams = function(a) { a = a || {}; if (document.location.search) for (var b = document.location.search.substring(1).split("&"), c = 0; c < b.length; ++c) { var d = b[c].split("="); a[d[0]] = d[1] } b = function(a) { if (a | 0) return !0; for (var b = "true True TRUE yes Yes YES".split(" "), c = 0; c < b.length; ++c) if (a === b[c]) return !0; return !1 } ; a.width = a.width || 800; a.height = a.height || 600; a.autoStart = b(a.autoStart); a.pagePreset = b(a.pagePreset); a.fullFrame = b(a.fullFrame) || b(a.bare); a.fullFrame = !a.pagePreset && a.fullFrame; return a } , embed = function(a, b) { var c; b = prepareEmbedParams(b); if (b.pagePreset) { c = new WebViewer(b.width,b.height,a); document.body.style.backgroundColor = "#d7e4da"; var d = document.createElement("div"); d.style.position = "relative"; d.style.backgroundColor = "#e4e7e4"; d.style.width = b.width + 12 + "px"; d.style.height = b.height + 6 + 16 + "px"; d.style.margin = "auto"; d.style.boxShadow = "3px 5px 12px 0px grey"; document.body.appendChild(d); var e = document.createElement("div"); e.style.position = "relative"; e.style.left = "6px"; e.style.top = "6px"; d.appendChild(e); e.appendChild(c.domRoot); if (!c.mobile) { d.style.resize = "both"; d.style.overflow = "hidden"; var f = [d.style.width, d.style.height] , g = function() { if (FullScreen.active()) d.style.resize = "none"; else if (d.style.resize = "both", f[0] != d.style.width || f[1] != d.style.height) f[0] = d.style.width, f[1] = d.style.height, c.resize(d.clientWidth - 12, d.clientHeight - 6 - 16); window.setTimeout(g, 100) } ; g() } } else { c = new WebViewer(b.fullFrame ? window.innerWidth : b.width,b.fullFrame ? window.innerHeight : b.height,a, b.root); if(!b.root) document.body.appendChild(c.domRoot); if(b.backgroundColor) fdage.backgroundColor = b.backgroundColor; if(b.ifPlain) fdage.ifPlain = true; b.fullFrame && (c.domRoot.style.position = "absolute", b.root || (c.domRoot.style.left = c.domRoot.style.top = 0), window.addEventListener("resize", function() { FullScreen.active() || c.resize(c.clientWidth,c.clientHeidht) })); } c.ui.setThumbnailURL(b.thumbnailURL); b.autoStart && c.loadScene(); return c } , fetchThumbnail = function(a, b, c, d) { var e = -1 == a.indexOf("?") ? "?" : "&"; Network.fetchBinaryIncremental(a + e + "thumb=1", function(a) { (a = (new Archive(a)).extract("thumbnail.jpg")) ? TextureCache.parseFile(a, b, d) : c && c(); return 0 }, c, 49152) } , fdage = "undefined" == typeof fdage ? {} : fdage; fdage.embed = embed; fdage.fetchThumbnail = fetchThumbnail; function Framebuffer(a, b) { this.gl = a; this.fbo = a.createFramebuffer(); a.bindFramebuffer(a.FRAMEBUFFER, this.fbo); b && (this.width = b.width, this.height = b.height, b.color0 && (this.color0 = b.color0, a.framebufferTexture2D(a.FRAMEBUFFER, a.COLOR_ATTACHMENT0, a.TEXTURE_2D, this.color0.id, 0), this.width = b.color0.desc.width, this.height = b.color0.desc.height), b.depth ? (this.depth = b.depth, a.framebufferTexture2D(a.FRAMEBUFFER, a.DEPTH_ATTACHMENT, a.TEXTURE_2D, this.depth.id, 0)) : (this.depthBuffer = b.depthBuffer, b.createDepth && !this.depthBuffer && (this.depthBuffer = Framebuffer.createDepthBuffer(a, this.width, this.height)), this.depthBuffer && (a.bindRenderbuffer(a.RENDERBUFFER, this.depthBuffer), a.framebufferRenderbuffer(a.FRAMEBUFFER, a.DEPTH_ATTACHMENT, a.RENDERBUFFER, this.depthBuffer), a.bindRenderbuffer(a.RENDERBUFFER, null )))); this.valid = b && b.ignoreStatus || a.checkFramebufferStatus(a.FRAMEBUFFER) == a.FRAMEBUFFER_COMPLETE; a.bindFramebuffer(a.FRAMEBUFFER, null ) } Framebuffer.createDepthBuffer = function(a, b, c) { var d = a.createRenderbuffer(); a.bindRenderbuffer(a.RENDERBUFFER, d); a.renderbufferStorage(a.RENDERBUFFER, a.DEPTH_COMPONENT16, b, c); a.bindRenderbuffer(a.RENDERBUFFER, null ); return d } ; Framebuffer.prototype.bind = function() { this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, this.fbo); this.gl.viewport(0, 0, this.width, this.height) } ; Framebuffer.bindNone = function(a) { a.bindFramebuffer(a.FRAMEBUFFER, null ) } ; var FullScreen = { support: function() { return !!(document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled) }, begin: function(a, b) { var c = a.requestFullscreen || a.webkitRequestFullScreen || a.mozRequestFullScreen || a.msRequestFullscreen; if (c) { var d = function() { FullScreen.active() || (document.removeEventListener("fullscreenchange", d), document.removeEventListener("webkitfullscreenchange", d), document.removeEventListener("mozfullscreenchange", d), document.removeEventListener("MSFullscreenChange", d)); b && b() } ; document.addEventListener("fullscreenchange", d); document.addEventListener("webkitfullscreenchange", d); document.addEventListener("mozfullscreenchange", d); document.addEventListener("MSFullscreenChange", d); c.bind(a)() } }, end: function() { var a = document.exitFullscreen || document.webkitExitFullscreen || document.mozCancelFullScreen || document.msExitFullscreen; a && a.bind(document)() }, active: function() { return !!(document.fullscreenElement || document.webkitIsFullScreen || document.mozFullScreenElement || document.msFullscreenElement) } }; function Input(a) { this.onTap = []; this.onSingleTap = []; this.onDoubleTap = []; this.onDrag = []; this.onZoom = []; this.onPan = []; this.onPan2 = []; this.onAnything = []; this.macHax = 0 <= navigator.platform.toUpperCase().indexOf("MAC"); a && this.attach(a) } Input.prototype.attach = function(a) { this.element = a; var b = function(a) { for (var b = 0; b < this.onAnything.length; ++b) this.onAnything[b](); a.preventDefault() } .bind(this); this.mouseStates = [{ pressed: !1, position: [0, 0], downPosition: [0, 0] }, { pressed: !1, position: [0, 0], downPosition: [0, 0] }, { pressed: !1, position: [0, 0], downPosition: [0, 0] }]; this.lastTapPos = [0, 0]; a = function(a) { if (a.target === this.element) { var d = this.mouseStates[a.button]; if (d) { d.pressed = !0; var e = this.element.getBoundingClientRect(); d.position[0] = d.downPosition[0] = a.clientX - e.left; d.position[1] = d.downPosition[1] = a.clientY - e.top; b(a) } } } .bind(this); this.element.addEventListener("mousedown", a); a = function(a) { var d = this.mouseStates[a.button]; if (d) { var e = this.element.getBoundingClientRect() , f = a.clientX - e.left , e = a.clientY - e.top; d.pressed = !1; d.position[0] = f; d.position[1] = e; 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])) { for (var g = 0; g < this.onTap.length; ++g) this.onTap[g](f, e); this.needSingleClick = !0; window.setTimeout(function(a, b) { if (this.needSingleClick) { for (var c = 0; c < this.onSingleTap.length; ++c) this.onSingleTap[c](a, b); this.needSingleClick = !1 } } .bind(this, f, e), 301); d = !1; if (void 0 !== this.doubleClickTimer && (g = 8 > Math.abs(f - this.lastTapPos[0]) + Math.abs(e - this.lastTapPos[1]), 300 > Date.now() - this.doubleClickTimer && g)) for (d = !0, this.needSingleClick = !1, g = 0; g < this.onDoubleTap.length; ++g) this.onDoubleTap[g](f, e); this.doubleClickTimer = Date.now(); d && (this.doubleClickTimer = -1E9); this.lastTapPos[0] = f; this.lastTapPos[1] = e } } b(a) } .bind(this); this.element.addEventListener("mouseup", a); a = function(a) { for (var d = !1, e = 0; 3 > e; ++e) { var f = this.mouseStates[e]; if (f.pressed) { var g = this.element.getBoundingClientRect() , d = a.clientX - g.left , g = a.clientY - g.top , h = d - f.position[0] , k = g - f.position[1]; f.position[0] = d; f.position[1] = g; if (1 <= e || a.ctrlKey) for (f = 0; f < this.onPan.length; ++f) this.onPan[f](h, k); else if (0 == e) if (a.shiftKey) for (f = 0; f < this.onPan2.length; ++f) this.onPan2[f](h, k); else for (f = 0; f < this.onDrag.length; ++f) this.onDrag[f](d, g, h, k); d = !0 } } d && b(a) } .bind(this); this.element.addEventListener("mousemove", a); a = function(a) { var d = 0; a.deltaY ? (d = -0.4 * a.deltaY, 1 == a.deltaMode ? d *= 16 : 2 == a.deltaMode && (d *= this.element.clientHeight)) : a.wheelDelta ? d = this.macHax && 120 == Math.abs(a.wheelDelta) ? 0.08 * a.wheelDelta : 0.4 * a.wheelDelta : a.detail && (d = -10 * a.detail); for (var e = 0; e < this.onZoom.length; ++e) this.onZoom[e](d); b(a) } .bind(this); this.element.addEventListener("mousewheel", a); this.element.addEventListener("DOMMouseScroll", a); this.element.addEventListener("wheel", a); a = function(a) { for (var b = 0; b < this.mouseStates.length; ++b) this.mouseStates[b].pressed = !1; a.preventDefault() } .bind(this); this.element.addEventListener("mouseleave", a); this.element.addEventListener("contextmenu", function(a) { a.preventDefault() }); this.touches = {}; this.tapPossible = !1; this.touchCountFloor = 0; a = function(a) { for (var d = this.element.getBoundingClientRect(), e = !1, f = 0; f < a.changedTouches.length; ++f) if (a.target === this.element) { var g = a.changedTouches[f] , e = { x: g.clientX - d.left, y: g.clientY - d.top }; e.startX = e.x; e.startY = e.y; this.touches[g.identifier] = e; e = !0 } this.tapPossible = 1 == a.touches.length; for (g = d = 0; g < this.touches.length; ++g) d++; d > this.touchCountFloor && (this.touchCountFloor = d); e && b(a) } .bind(this); this.element.addEventListener("touchstart", a); a = function(a) { for (var d = !1, e = 0; e < a.changedTouches.length; ++e) { var f = a.changedTouches[e] , g = this.touches[f.identifier]; if (g) { if (this.tapPossible) { var h = this.element.getBoundingClientRect() , d = f.clientX - h.left , h = f.clientY - h.top; if (24 > Math.max(Math.abs(d - g.startX), Math.abs(h - g.startY))) { for (e = 0; e < this.onTap.length; ++e) this.onTap[e](d, h); this.needSingleTap = !0; window.setTimeout(function(a, b) { if (this.needSingleTap) { for (var c = 0; c < this.onSingleTap.length; ++c) this.onSingleTap[c](a, b); this.needSingleTap = !1 } } .bind(this, d, h), 501); g = !1; if (void 0 !== this.doubleTapTimer) { var k = 24 > Math.max(Math.abs(d - this.lastTapPos[0]), Math.abs(h - this.lastTapPos[1])) , l = 500 > Date.now() - this.doubleTapTimer; if (k && l) for (g = !0, e = 0; e < this.onDoubleTap.length; ++e) this.onDoubleTap[e](d, h) } this.doubleTapTimer = Date.now(); g && (this.doubleTapTimer = -1E9); this.lastTapPos[0] = d; this.lastTapPos[1] = h } this.tapPossible = !1 } delete this.touches[f.identifier]; d = !0 } } for (f = e = 0; f < this.touches.length; ++f) e++; 0 >= e && (this.touchCountFloor = 0); d && b(a) } .bind(this); this.element.addEventListener("touchend", a); this.element.addEventListener("touchcancel", a); this.element.addEventListener("touchleave", a); a = function(a) { for (var d = [], e = 0; e < a.touches.length; ++e) a.touches[e].target === this.element && d.push(a.touches[e]); var f = this.element.getBoundingClientRect(); if (1 == d.length && 1 >= this.touchCountFloor) { var g = d[0] , h = this.touches[g.identifier]; if (h) { var k = g.clientX - f.left , g = g.clientY - f.top , f = k - h.x , l = g - h.y; h.x = k; h.y = g; for (e = 0; e < this.onDrag.length; ++e) this.onDrag[e](k, g, f, l, a.shiftKey) } } else if (2 == d.length && 2 >= this.touchCountFloor) { if (l = d[0], e = this.touches[l.identifier], g = d[1], h = this.touches[g.identifier], e && h) { var k = l.clientX - f.left , l = l.clientY - f.top , m = g.clientX - f.left , n = g.clientY - f.top , r = Math.sqrt((k - m) * (k - m) + (l - n) * (l - n)) , p = Math.sqrt((e.x - h.x) * (e.x - h.x) + (e.y - h.y) * (e.y - h.y)) , q = Math.abs(r - p) , f = (k - e.x + m - h.x) / 2 , g = (l - e.y + n - h.y) / 2 , u = Math.sqrt(f * f + g * g); e.x = k; e.y = l; h.x = m; h.y = n; if (0 < q) for (h = q / (q + u), e = 0; e < this.onZoom.length; ++e) this.onZoom[e](2 * (r - p) * h); if (0 < u) for (h = u / (q + u), e = 0; e < this.onDrag.length; ++e) this.onPan[e](f * h, g * h) } } else if (3 <= d.length) { for (e = p = r = m = l = 0; e < d.length; ++e) g = d[e], h = this.touches[g.identifier], k = g.clientX - f.left, g = g.clientY - f.top, r += k, p += g, h && (l += h.x, m += h.y, h.x = k, h.y = g); l /= d.length; m /= d.length; r /= d.length; p /= d.length; for (e = 0; e < this.onPan2.length; ++e) this.onPan2[e](r - l, p - m) } 0 < d.length && b(a) } .bind(this); this.element.addEventListener("touchmove", a) } ; function Lights(a, b) { this.rotation = this.shadowCount = this.count = 0; this.positions = []; this.directions = []; this.matrixWeights = []; this.matrix = Matrix.identity(); this.invMatrix = Matrix.identity(); for (var c in a) this[c] = a[c]; this.count = this.positions.length / 4; this.shadowCount = Math.min(3, this.shadowCount); this.positions = new Float32Array(this.positions); this.positionBuffer = new Float32Array(this.positions); this.directions = new Float32Array(this.directions); this.directionBuffer = new Float32Array(this.directions); this.modelViewBuffer = new Float32Array(16 * this.shadowCount); this.projectionBuffer = new Float32Array(16 * this.shadowCount); this.finalTransformBuffer = new Float32Array(16 * this.shadowCount); this.shadowTexelPadProjections = new Float32Array(4 * this.shadowCount); this.shadowsNeedUpdate = new Uint8Array(this.shadowCount); for (var d = 0; d < this.shadowsNeedUpdate.length; ++d) this.shadowsNeedUpdate[d] = 1; Matrix.rotation(this.matrix, this.rotation, 1); Matrix.transpose(this.invMatrix, this.matrix); for (d = 0; d < this.count; ++d) { c = this.positions.subarray(4 * d, 4 * d + 4); var e = this.directions.subarray(3 * d, 3 * d + 3); 1 == this.matrixWeights[d] ? (Matrix.mul4(c, this.matrix, c[0], c[1], c[2], c[3]), Matrix.mulVec(e, this.matrix, e[0], e[1], e[2])) : 2 == this.matrixWeights[d] && (Matrix.mul4(c, b.viewMatrix, c[0], c[1], c[2], c[3]), Matrix.mulVec(e, b.viewMatrix, e[0], e[1], e[2])) } } Lights.prototype.getLightPos = function(a) { return this.positionBuffer.subarray(4 * a, 4 * a + 4) } ; Lights.prototype.getLightDir = function(a) { return this.directionBuffer.subarray(3 * a, 3 * a + 3) } ; Lights.prototype.update = function(a, b) { var c = new Matrix.type(this.matrix); Matrix.rotation(this.matrix, this.rotation, 1); Matrix.transpose(this.invMatrix, this.matrix); var rM = Matrix.transpose(Matrix.empty(), a.modelMatrix); //当模型变换后这里也考虑上模型变换矩阵,这样光影才会跟着变 Matrix.mul(this.matrix, this.matrix, rM); for (var d = 0; d < this.count; ++d) { var e = this.positions.subarray(4 * d, 4 * d + 4) , f = this.directions.subarray(3 * d, 3 * d + 3) , g = this.getLightPos(d) , h = this.getLightDir(d); 1 == this.matrixWeights[d] ? (g[0] = e[0], g[1] = e[1], g[2] = e[2], g[3] = e[3], h[0] = f[0], h[1] = f[1], h[2] = f[2]) : 2 == this.matrixWeights[d] ? (Matrix.mul4(g, a.transform, e[0], e[1], e[2], e[3]), Matrix.mulVec(h, a.transform, f[0], f[1], f[2]), Matrix.mul4(g, this.matrix, g[0], g[1], g[2], g[3]), Matrix.mulVec(h, this.matrix, h[0], h[1], h[2])) : (Matrix.mul4(g, this.matrix, e[0], e[1], e[2], e[3]), Matrix.mulVec(h, this.matrix, f[0], f[1], f[2])); Vect.normalize(h, h) } 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) { l = this.getLightPos(d); m = this.getLightDir(d); 0.99 < Math.abs(m[1]) ? Vect.set(n, 1, 0, 0) : Vect.set(n, 0, 1, 0); Vect.cross(r, n, m); Vect.normalize(r, r); Vect.cross(n, m, r); Vect.normalize(n, n); 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); for (l = 0; 8 > l; ++l) e[0] = l & 1 ? b.max[0] : b.min[0], e[1] = l & 2 ? b.max[1] : b.min[1], e[2] = l & 4 ? b.max[2] : b.min[2], Matrix.mulPoint(e, this.matrix, 1.005 * e[0], 1.005 * e[1], 1.005 * e[2]), Matrix.mulPoint(e, g, e[0], e[1], e[2]), 0 == l ? (p[0] = q[0] = e[0], p[1] = q[1] = e[1], p[2] = q[2] = e[2]) : (p[0] = Math.min(p[0], e[0]), p[1] = Math.min(p[1], e[1]), p[2] = Math.min(p[2], e[2]), q[0] = Math.max(q[0], e[0]), q[1] = Math.max(q[1], e[1]), q[2] = Math.max(q[2], e[2])); var l = -p[2] , m = -q[2] , s = this.spot[3 * d]; 0 < s ? (l = Math.min(l, 1 / this.parameters[3 * d + 2]), m = Math.max(0.005 * l, m), Matrix.perspective(h, s, 1, m, l), d < this.shadowCount && (l = 2 * -Math.tan(0.00872664625 * s), this.shadowTexelPadProjections[4 * d + 0] = this.modelViewBuffer[16 * d + 2] * l, this.shadowTexelPadProjections[4 * d + 1] = this.modelViewBuffer[16 * d + 6] * l, this.shadowTexelPadProjections[4 * d + 2] = this.modelViewBuffer[16 * d + 10] * l, this.shadowTexelPadProjections[4 * d + 3] = this.modelViewBuffer[16 * d + 14] * l)) : (Matrix.ortho(h, p[0], q[0], p[1], q[1], m, l), d < this.shadowCount && (this.shadowTexelPadProjections[4 * d + 0] = this.shadowTexelPadProjections[4 * d + 1] = this.shadowTexelPadProjections[4 * d + 2] = 0, this.shadowTexelPadProjections[4 * d + 3] = Math.max(q[0] - p[0], q[1] - p[1]))); Matrix.mul(k, h, g); Matrix.mul(k, u, k); Matrix.copyToBuffer(this.modelViewBuffer, 16 * d, g); Matrix.copyToBuffer(this.projectionBuffer, 16 * d, h); Matrix.copyToBuffer(this.finalTransformBuffer, 16 * d, k) } e = !1; for (d = 0; d < c.length; ++d) if (c[d] != this.matrix[d]) { e = !0; break } for (d = 0; d < this.shadowCount; d++) if (e && 1 == this.matrixWeights[d]) this.shadowsNeedUpdate[d] = 1; else for (c = 16 * d; c < 16 * d + 16; ++c) if (f[c] != this.finalTransformBuffer[c]) { this.shadowsNeedUpdate[d] = 1; break } } ; function Material(a, b, c) { this.gl = a; this.name = c.name; var d = { mipmap: !0, aniso: a.hints.mobile ? 0 : 4 }; this.textures = { albedo: a.textureCache.fromFilesMergeAlpha(b.get(c.albedoTex), b.get(c.alphaTex), { mipmap: !0, aniso: a.hints.mobile ? 2 : 4 }), reflectivity: a.textureCache.fromFilesMergeAlpha(b.get(c.reflectivityTex), b.get(c.glossTex), d), normal: a.textureCache.fromFile(b.get(c.normalTex), d), extras: a.textureCache.fromFilesMergeAlpha(b.get(c.extrasTex), b.get(c.extrasTexA), d) }; this.strength = {}; this.strength.albedo = (c.strength&&c.strength.albedo )|| 100; //改 this.strength.reflectivity = (c.strength&&c.strength.reflectivity) || 100; //改 this.strength.normal = (c.strength&&c.strength.normal )|| 100; //改 this.strength.alpha = (c.strength&&c.strength.alpha) || 100; //改 this.strength.gloss = (c.strength&&c.strength.gloss) || 100; //改 if(c.blend==="add"&&c.alphaTex==void 0)this.strength.alpha=0;//改 this.extrasTexCoordRanges = {}; if (c.extrasTexCoordRanges) for (var e in c.extrasTexCoordRanges) this.extrasTexCoordRanges[e] = new Float32Array(c.extrasTexCoordRanges[e].scaleBias); this.textures.extras || (b = new Texture(a,{ width: 1, height: 1 }), b.loadArray(new Uint8Array([255, 255, 255, 255])), this.textures.extras = b); b = { none: function() { a.disable(a.BLEND) }, alpha: function() { a.enable(a.BLEND); a.blendFunc(a.SRC_ALPHA, a.ONE_MINUS_SRC_ALPHA) }, add: function() { a.enable(a.BLEND); a.blendFunc(a.ONE, a.ONE) } }; this.blend = b[c.blend] || b.none; this.alphaTest = c.alphaTest || 0; this.usesBlending = this.blend !== b.none; this.shadowAlphaTest = this.alphaTest; 0 >= this.shadowAlphaTest && this.blend === b.alpha && (this.shadowAlphaTest = 0.5); this.castShadows = this.blend !== b.add; this.horizonOcclude = c.horizonOcclude || 0; this.fresnel = new Float32Array(c.fresnel ? c.fresnel : [1, 1, 1]); this.emissiveIntensity = c.emissiveIntensity || 1; d = []; 0 < c.lightCount && d.push("#define LIGHT_COUNT " + c.lightCount); 0 < c.shadowCount && d.push("#define SHADOW_COUNT " + Math.min(c.lightCount, c.shadowCount)); 0 < c.alphaTest && d.push("#define ALPHA_TEST"); this.blend === b.alpha && d.push("#define TRANSPARENCY_DITHER"); a.hints.mobile && d.push("#define MOBILE"); c.useSkin && (d.push("#define SKIN"), this.skinParams = c.skinParams || { subdermisColor: [1, 1, 1], transColor: [1, 0, 0, 0.5], fresnelColor: [0.2, 0.2, 0.2, 0.5], fresnelOcc: 1, fresnelGlossMask: 1, transSky: 0.5, shadowBlur: 0.5, normalSmooth: 0.5 }, this.skinParams.fresnelIntegral = 1 / 3.14159 * (1 - 0.5 * this.skinParams.fresnelColor[3]), this.skinParams.transIntegral = 1 / 3.14159 * (1 - 0.5 * this.skinParams.transColor[3]), this.skinParams.transSky *= 1.25, this.skinParams.transIntegral *= 1.25, this.extrasTexCoordRanges.subdermisTex || d.push("#define SKIN_NO_SUBDERMIS_TEX"), this.extrasTexCoordRanges.translucencyTex || d.push("#define SKIN_NO_TRANSLUCENCY_TEX"), this.extrasTexCoordRanges.fuzzTex || d.push("#define SKIN_NO_FUZZ_TEX")); c.aniso && (d.push("#define ANISO"), this.anisoParams = c.anisoParams || { strength: 1, tangent: [1, 0, 0], integral: 0.5 }, this.extrasTexCoordRanges.anisoTex || d.push("#define ANISO_NO_DIR_TEX")); c.microfiber && (d.push("#define MICROFIBER"), this.microfiberParams = c.microfiberParams || { fresnelColor: [0.2, 0.2, 0.2, 0.5], fresnelOcc: 1, fresnelGlossMask: 1 }, this.microfiberParams.fresnelIntegral = 1 / 3.14159 * (1 - 0.5 * this.microfiberParams.fresnelColor[3]), this.extrasTexCoordRanges.fuzzTex || d.push("#define MICROFIBER_NO_FUZZ_TEX")); c.vertexColor && (d.push("#define VERTEX_COLOR"), c.vertexColorsRGB && d.push("#define VERTEX_COLOR_SRGB"), c.vertexColorAlpha && d.push("#define VERTEX_COLOR_ALPHA")); this.horizonSmoothing = c.horizonSmoothing || 0; 0 < this.horizonSmoothing && d.push("#define HORIZON_SMOOTHING"); c.unlitDiffuse && d.push("#define DIFFUSE_UNLIT"); this.extrasTexCoordRanges.emissiveTex && d.push("#define EMISSIVE"); c.tangentOrthogonalize && d.push("#define TSPACE_ORTHOGONALIZE"); c.tangentNormalize && d.push("#define TSPACE_RENORMALIZE"); c.tangentGenerateBitangent && d.push("#define TSPACE_COMPUTE_BITANGENT"); this.shader = a.shaderCache.fromURLs("matvert.glsl", "matfrag.glsl", d); // d.push("#define STRIPVIEW"); // this.stripShader = a.shaderCache.fromURLs("matvert.glsl", "matfrag.glsl", d); // this.wireShader = a.shaderCache.fromURLs("wirevert.glsl", "wirefrag.glsl"); this.blend === b.alpha && (this.prepassShader = a.shaderCache.fromURLs("alphaprepassvert.glsl", "alphaprepassfrag.glsl")) } Material.prototype.bind = function(a) { if (!this.complete()) return !1; 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; f.bind(); this.blend(); m.uniform1f(n.uAlbedoStrength, this.strength.albedo);//改 m.uniform1f(n.uReflecStrength, this.strength.reflectivity);//改 m.uniform1f(n.uNormalStrength, this.strength.normal);//改 m.uniform1f(n.uAlphaStrength, this.strength.alpha);//改 m.uniform1f(n.uGlossStrength, this.strength.gloss);//改 m.uniform1f(n.uModelBright, d.modelBright);//改 b.viewProjectionMatrix2 = Matrix.mul(Matrix.empty(), b.projectionMatrix, b.viewMatrix2); //必须要再乘一次,因为aaresolve时重新计算了projectionMatrix m.uniformMatrix4fv(n.uModelViewProjectionMatrix, !1, b.viewProjectionMatrix2); m.uniformMatrix4fv(n.uSkyMatrix, !1, c.matrix); q = Matrix.mulPoint(Vect.empty(), c.matrix, b.transform2[12], b.transform2[13], b.transform2[14]);//改 m.uniform3f(n.uCameraPosition, q[0], q[1], q[2]); m.uniform3fv(n.uFresnel, this.fresnel); m.uniform1f(n.uAlphaTest, this.alphaTest); m.uniform1f(n.uHorizonOcclude, this.horizonOcclude); m.uniform1f(n.uHorizonSmoothing, this.horizonSmoothing); m.uniform4fv(n.uDiffuseCoefficients, d.diffuseCoefficients); if (0 < c.count && (m.uniform4fv(n.uLightPositions, c.positionBuffer), m.uniform3fv(n.uLightDirections, c.directionBuffer), m.uniform3fv(n.uLightColors, c.colors), m.uniform3fv(n.uLightParams, c.parameters), m.uniform3fv(n.uLightSpot, c.spot), q = 0.392699 * a.postRender.sampleIndex, m.uniform2f(n.uShadowKernelRotation, 0.5 * Math.cos(q), 0.5 * Math.sin(q)), 0 < c.shadowCount)) { var q = e.depthTextures[0].desc.width , u = e.depthTextures[0].desc.height; m.uniform4f(n.uShadowMapSize, q, u, 1 / q, 1 / u); m.uniformMatrix4fv(n.uShadowMatrices, !1, c.finalTransformBuffer); m.uniform4fv(n.uShadowTexelPadProjections, c.shadowTexelPadProjections); e.bindDepthTexture(p.tDepth0, 0); e.bindDepthTexture(p.tDepth1, 1); e.bindDepthTexture(p.tDepth2, 2) } g && (m.uniform3fv(n.uSubdermisColor, g.subdermisColor), m.uniform4fv(n.uTransColor, g.transColor), m.uniform4fv(n.uFresnelColor, g.fresnelColor), m.uniform1f(n.uFresnelOcc, g.fresnelOcc), m.uniform1f(n.uFresnelGlossMask, g.fresnelGlossMask), m.uniform1f(n.uFresnelIntegral, g.fresnelIntegral), m.uniform1f(n.uTransIntegral, g.transIntegral), m.uniform1f(n.uTransSky, g.transSky), m.uniform1f(n.uSkinShadowBlur, 8 * Math.min(g.shadowBlur, 1)), m.uniform1f(n.uNormalSmooth, g.normalSmooth), (l = this.extrasTexCoordRanges.subdermisTex) && m.uniform4fv(n.uTexRangeSubdermis, l), (l = this.extrasTexCoordRanges.translucencyTex) && m.uniform4fv(n.uTexRangeTranslucency, l), (l = this.extrasTexCoordRanges.fuzzTex) && m.uniform4fv(n.uTexRangeFuzz, l)); k && (m.uniform4fv(n.uFresnelColor, k.fresnelColor), m.uniform1f(n.uFresnelOcc, k.fresnelOcc), m.uniform1f(n.uFresnelGlossMask, k.fresnelGlossMask), m.uniform1f(n.uFresnelIntegral, k.fresnelIntegral), (l = this.extrasTexCoordRanges.fuzzTex) && m.uniform4fv(n.uTexRangeFuzz, l)); h && (m.uniform3fv(n.uAnisoTangent, h.tangent), m.uniform1f(n.uAnisoStrength, h.strength), m.uniform1f(n.uAnisoIntegral, h.integral), (l = this.extrasTexCoordRanges.anisoTex) && m.uniform4fv(n.uTexRangeAniso, l)); if (l = this.extrasTexCoordRanges.emissiveTex) m.uniform4fv(n.uTexRangeEmissive, l), m.uniform1f(n.uEmissiveScale, this.emissiveIntensity); r.albedo.bind(p.tAlbedo); r.reflectivity.bind(p.tReflectivity); r.normal.bind(p.tNormal); r.extras.bind(p.tExtras); d.specularTexture.bind(p.tSkySpecular); // f === this.stripShader && (m.uniform1fv(n.uStrips, a.stripData.strips), //m.uniform2f(n.uStripRes, 2 / b.size[0], 2 / b.size[1])); return !0 } ; Material.prototype.bindAlphaPrepass = function(a) { if (!this.complete() || !this.prepassShader) return !1; var b = this.gl , c = this.prepassShader.params , d = this.prepassShader.samplers; this.prepassShader.bind(); b.uniform1f(c.uAlphaStrength, this.strength.alpha);//改 b.uniformMatrix4fv(c.uModelViewProjectionMatrix, !1, a.view.viewProjectionMatrix2); //改 this.textures.albedo.bind(d.tAlbedo); return !0 } ; /* Material.prototype.bindWire = function(a) { if (!this.complete()) return !1; var b = this.gl , c = this.wireShader.params , d = a.view; b.enable(b.BLEND); b.blendFunc(b.SRC_ALPHA, b.ONE_MINUS_SRC_ALPHA); b.depthMask(!1); this.wireShader.bind(); // var e = Matrix.mul(Matrix.empty(), d.projectionMatrix, d.viewMatrix); // b.uniformMatrix4fv(c.uModelViewProjectionMatrix, !1, e); b.uniformMatrix4fv(c.uModelViewProjectionMatrix, !1, d.viewProjectionMatrix2); //改 b.uniform4f(c.uStripParams, 2 / d.size[0], 2 / d.size[1], a.stripData.strips[3], a.stripData.strips[4]); return !0 } ; */ Material.prototype.complete = function() { 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() } ; var Matrix = { type: Float32Array, create: function(a, b, c, d, e, f, g, h, k, l, m, n, r, p, q, u) { var s = new Matrix.type(16); s[0] = a; s[4] = b; s[8] = c; s[12] = d; s[1] = e; s[5] = f; s[9] = g; s[13] = h; s[2] = k; s[6] = l; s[10] = m; s[14] = n; s[3] = r; s[7] = p; s[11] = q; s[15] = u; return s }, empty: function() { return new Matrix.type(16) }, identity: function() { var a = new Matrix.type(16); a[0] = 1; a[4] = 0; a[8] = 0; a[12] = 0; a[1] = 0; a[5] = 1; a[9] = 0; a[13] = 0; a[2] = 0; a[6] = 0; a[10] = 1; a[14] = 0; a[3] = 0; a[7] = 0; a[11] = 0; a[15] = 1; return a }, set: function(a, b, c, d, e, f, g, h, k, l, m, n, r, p, q, u, s) { a[0] = b; a[4] = c; a[8] = d; a[12] = e; a[1] = f; a[5] = g; a[9] = h; a[13] = k; a[2] = l; a[6] = m; a[10] = n; a[14] = r; a[3] = p; a[7] = q; a[11] = u; a[15] = s }, translation: function(a, b, c, d) { Matrix.set(a, 1, 0, 0, b, 0, 1, 0, c, 0, 0, 1, d, 0, 0, 0, 1); return a }, rotation: function(a, b, c) { a[0] = 1; a[4] = 0; a[8] = 0; a[12] = 0; a[1] = 0; a[5] = 1; a[9] = 0; a[13] = 0; a[2] = 0; a[6] = 0; a[10] = 1; a[14] = 0; a[3] = 0; a[7] = 0; a[11] = 0; a[15] = 1; var d = 0.0174532925 * b; b = Math.sin(d); d = Math.cos(d); switch (c) { case 0: a[5] = d; a[9] = -b; a[6] = b; a[10] = d; break; case 1: a[0] = d; a[8] = b; a[2] = -b; a[10] = d; break; case 2: a[0] = d, a[4] = -b, a[1] = b, a[5] = d } return a }, mul: function(a, b, c) { var d = b[0] , e = b[1] , f = b[2] , g = b[3] , h = b[4] , k = b[5] , l = b[6] , m = b[7] , n = b[8] , r = b[9] , p = b[10] , q = b[11] , u = b[12] , s = b[13] , z = b[14]; b = b[15]; var t = c[0] , v = c[1] , w = c[2] , x = c[3]; a[0] = t * d + v * h + w * n + x * u; a[1] = t * e + v * k + w * r + x * s; a[2] = t * f + v * l + w * p + x * z; a[3] = t * g + v * m + w * q + x * b; t = c[4]; v = c[5]; w = c[6]; x = c[7]; a[4] = t * d + v * h + w * n + x * u; a[5] = t * e + v * k + w * r + x * s; a[6] = t * f + v * l + w * p + x * z; a[7] = t * g + v * m + w * q + x * b; t = c[8]; v = c[9]; w = c[10]; x = c[11]; a[8] = t * d + v * h + w * n + x * u; a[9] = t * e + v * k + w * r + x * s; a[10] = t * f + v * l + w * p + x * z; a[11] = t * g + v * m + w * q + x * b; t = c[12]; v = c[13]; w = c[14]; x = c[15]; a[12] = t * d + v * h + w * n + x * u; a[13] = t * e + v * k + w * r + x * s; a[14] = t * f + v * l + w * p + x * z; a[15] = t * g + v * m + w * q + x * b; return a }, invert: function(a, b) { var c = b[0] , d = b[1] , e = b[2] , f = b[3] , g = b[4] , h = b[5] , k = b[6] , l = b[7] , m = b[8] , n = b[9] , r = b[10] , p = b[11] , q = b[12] , u = b[13] , s = b[14] , z = b[15] , t = c * h - d * g , v = c * k - e * g , w = c * l - f * g , x = d * k - e * h , A = d * l - f * h , B = e * l - f * k , C = m * u - n * q , D = m * s - r * q , E = m * z - p * q , F = n * s - r * u , G = n * z - p * u , H = r * z - p * s , y = t * H - v * G + w * F + x * E - A * D + B * C; if (!y) return null ; y = 1 / y; a[0] = (h * H - k * G + l * F) * y; a[1] = (e * G - d * H - f * F) * y; a[2] = (u * B - s * A + z * x) * y; a[3] = (r * A - n * B - p * x) * y; a[4] = (k * E - g * H - l * D) * y; a[5] = (c * H - e * E + f * D) * y; a[6] = (s * w - q * B - z * v) * y; a[7] = (m * B - r * w + p * v) * y; a[8] = (g * G - h * E + l * C) * y; a[9] = (d * E - c * G - f * C) * y; a[10] = (q * A - u * w + z * t) * y; a[11] = (n * w - m * A - p * t) * y; a[12] = (h * D - g * F - k * C) * y; a[13] = (c * F - d * D + e * C) * y; a[14] = (u * v - q * x - s * t) * y; a[15] = (m * x - n * v + r * t) * y; return a }, transpose: function(a, b) { a[0] = b[0]; a[4] = b[1]; a[8] = b[2]; a[12] = b[3]; a[1] = b[4]; a[5] = b[5]; a[9] = b[6]; a[13] = b[7]; a[2] = b[8]; a[6] = b[9]; a[10] = b[10]; a[14] = b[11]; a[3] = b[12]; a[7] = b[13]; a[11] = b[14]; a[15] = b[15]; return a }, mul4: function(a, b, c, d, e, f) { a[0] = b[0] * c + b[4] * d + b[8] * e + b[12] * f; a[1] = b[1] * c + b[5] * d + b[9] * e + b[13] * f; a[2] = b[2] * c + b[6] * d + b[10] * e + b[14] * f; a[3] = b[3] * c + b[7] * d + b[11] * e + b[15] * f; return a }, mulPoint: function(a, b, c, d, e) { a[0] = b[0] * c + b[4] * d + b[8] * e + b[12]; a[1] = b[1] * c + b[5] * d + b[9] * e + b[13]; a[2] = b[2] * c + b[6] * d + b[10] * e + b[14]; return a }, mulVec: function(a, b, c, d, e) { a[0] = b[0] * c + b[4] * d + b[8] * e; a[1] = b[1] * c + b[5] * d + b[9] * e; a[2] = b[2] * c + b[6] * d + b[10] * e; return a }, perspective: function(a, b, c, d, e, f) { f = f || 0; b = 1 / Math.tan(0.00872664625 * b); a[0] = b / c; a[1] = a[2] = a[3] = 0; a[5] = b; a[4] = a[6] = a[7] = 0; a[8] = a[9] = 0; a[10] = (e + d) / (d - e) - 3.0518044E-5 * f; a[11] = -1; a[14] = 2 * e * d / (d - e); a[12] = a[13] = a[15] = 0; return a }, perspectiveInfinite: function(a, b, c, d, e) { e = e || 0; b = 1 / Math.tan(0.00872664625 * b); a[0] = b / c; a[1] = a[2] = a[3] = 0; a[5] = b; a[4] = a[6] = a[7] = 0; a[8] = a[9] = 0; a[10] = a[11] = -1 - 3.0518044E-5 * e; a[14] = -2 * d; a[12] = a[13] = a[15] = 0; return a }, ortho: function(a, b, c, d, e, f, g, h) { var k = 1 / (c - b) , l = 1 / (e - d) , m = 1 / (g - f); a[0] = k + k; a[1] = a[2] = a[3] = 0; a[5] = l + l; a[4] = a[6] = a[7] = 0; a[12] = -(c + b) * k; a[13] = -(e + d) * l; a[10] = -(m + m) - 3.0518044E-5 * (h || 0); a[14] = -(g + f) * m; a[8] = a[9] = a[11] = 0; a[15] = 1; return a }, lookAt: function(a, b, c, d) { var e = a.subarray(0, 3) , f = a.subarray(4, 7) , g = a.subarray(8, 11); Vect.sub(g, b, c); Vect.cross(e, d, g); Vect.normalize(g, g); Vect.normalize(e, e); Vect.cross(f, g, e); 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) }, copy: function(a, b) { for (var c = 0; 16 > c; ++c) a[c] = b[c] }, copyToBuffer: function(a, b, c) { for (var d = 0; 16 > d; ++d) a[b + d] = c[d] } }; function Mesh(a, b, c) { this.gl = a; this.desc = b; this.stride = 32; if (this.vertexColor = b.vertexColor) this.stride += 4; c = new ByteStream(c.data); this.indexCount = b.indexCount; this.indexTypeSize = b.indexTypeSize; this.indexType = 4 == this.indexTypeSize ? a.UNSIGNED_INT : a.UNSIGNED_SHORT; this.indexBuffer = a.createBuffer(); a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, this.indexBuffer); var d = c.readBytes(this.indexCount * this.indexTypeSize); a.bufferData(a.ELEMENT_ARRAY_BUFFER, d, a.STATIC_DRAW); this.wireCount = b.wireCount; this.wireBuffer = a.createBuffer(); a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, this.wireBuffer); d = c.readBytes(this.wireCount * this.indexTypeSize); a.bufferData(a.ELEMENT_ARRAY_BUFFER, d, a.STATIC_DRAW); a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, null ); this.vertexCount = b.vertexCount; this.vertexBuffer = a.createBuffer(); a.bindBuffer(a.ARRAY_BUFFER, this.vertexBuffer); c = c.readBytes(this.vertexCount * this.stride); a.bufferData(a.ARRAY_BUFFER, c, a.STATIC_DRAW); a.bindBuffer(a.ARRAY_BUFFER, null ); this.bounds = void 0 === b.minBound || void 0 === b.maxBound ? { min: Vect.create(-10, -10, -10, 1), max: Vect.create(10, 10, -0, 1) } : { min: Vect.create(b.minBound[0], b.minBound[1], b.minBound[2], 1), max: Vect.create(b.maxBound[0], b.maxBound[1], b.maxBound[2], 1) }; 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]) } ;function MeshRenderable(a, b, c) { this.mesh = a; this.gl = this.mesh.gl; this.indexOffset = b.firstIndex * a.indexTypeSize; this.indexCount = b.indexCount; this.wireIndexOffset = b.firstWireIndex * a.indexTypeSize; this.wireIndexCount = b.wireIndexCount; this.material = c } MeshRenderable.prototype.draw = function(a) { var b = this.gl; if (this.material.bind(a)) { a = this.material.shader.attribs; var c = this.mesh.stride; this.mesh.desc.cullBackFaces ? (b.enable(b.CULL_FACE), b.cullFace(b.BACK)) : b.disable(b.CULL_FACE); b.bindBuffer(b.ELEMENT_ARRAY_BUFFER, this.mesh.indexBuffer); b.bindBuffer(b.ARRAY_BUFFER, this.mesh.vertexBuffer); b.enableVertexAttribArray(a.vPosition); b.enableVertexAttribArray(a.vTexCoord); b.enableVertexAttribArray(a.vTangent); b.enableVertexAttribArray(a.vBitangent); b.enableVertexAttribArray(a.vNormal); var d = this.mesh.vertexColor && void 0 !== a.vColor; d && b.enableVertexAttribArray(a.vColor); var e = 0; b.vertexAttribPointer(a.vPosition, 3, b.FLOAT, !1, c, e); e += 12; b.vertexAttribPointer(a.vTexCoord, 2, b.FLOAT, !1, c, e); e += 8; b.vertexAttribPointer(a.vTangent, 2, b.UNSIGNED_SHORT, !0, c, e); e += 4; b.vertexAttribPointer(a.vBitangent, 2, b.UNSIGNED_SHORT, !0, c, e); e += 4; b.vertexAttribPointer(a.vNormal, 2, b.UNSIGNED_SHORT, !0, c, e); d && b.vertexAttribPointer(a.vColor, 4, b.UNSIGNED_BYTE, !0, c, e + 4); b.drawElements(b.TRIANGLES, this.indexCount, this.mesh.indexType, this.indexOffset); b.disableVertexAttribArray(a.vPosition); b.disableVertexAttribArray(a.vTexCoord); b.disableVertexAttribArray(a.vTangent); b.disableVertexAttribArray(a.vBitangent); b.disableVertexAttribArray(a.vNormal); d && b.disableVertexAttribArray(a.vColor) } } ; MeshRenderable.prototype.drawShadow = function(a) { var b = this.gl; this.mesh.desc.cullBackFaces ? (b.enable(b.CULL_FACE), b.cullFace(b.BACK)) : b.disable(b.CULL_FACE); b.bindBuffer(b.ELEMENT_ARRAY_BUFFER, this.mesh.indexBuffer); b.bindBuffer(b.ARRAY_BUFFER, this.mesh.vertexBuffer); b.enableVertexAttribArray(a); b.vertexAttribPointer(a, 3, b.FLOAT, !1, this.mesh.stride, 0); b.drawElements(b.TRIANGLES, this.indexCount, this.mesh.indexType, this.indexOffset); b.disableVertexAttribArray(a) } ; MeshRenderable.prototype.drawAlphaShadow = function(a, b) { var c = this.gl; this.mesh.desc.cullBackFaces ? (c.enable(c.CULL_FACE), c.cullFace(c.BACK)) : c.disable(c.CULL_FACE); c.bindBuffer(c.ELEMENT_ARRAY_BUFFER, this.mesh.indexBuffer); c.bindBuffer(c.ARRAY_BUFFER, this.mesh.vertexBuffer); c.enableVertexAttribArray(a); c.enableVertexAttribArray(b); c.vertexAttribPointer(a, 3, c.FLOAT, !1, this.mesh.stride, 0); c.vertexAttribPointer(b, 2, c.FLOAT, !1, this.mesh.stride, 12); c.drawElements(c.TRIANGLES, this.indexCount, this.mesh.indexType, this.indexOffset); c.disableVertexAttribArray(a); c.disableVertexAttribArray(b) } ; MeshRenderable.prototype.drawAlphaPrepass = function(a) { var b = this.gl; if (this.material.bindAlphaPrepass(a)) { a = this.material.prepassShader.attribs; var c = this.mesh.stride; this.mesh.desc.cullBackFaces ? (b.enable(b.CULL_FACE), b.cullFace(b.BACK)) : b.disable(b.CULL_FACE); b.bindBuffer(b.ELEMENT_ARRAY_BUFFER, this.mesh.indexBuffer); b.bindBuffer(b.ARRAY_BUFFER, this.mesh.vertexBuffer); b.enableVertexAttribArray(a.vPosition); b.enableVertexAttribArray(a.vTexCoord); b.vertexAttribPointer(a.vPosition, 3, b.FLOAT, !1, c, 0); b.vertexAttribPointer(a.vTexCoord, 2, b.FLOAT, !1, c, 12); b.drawElements(b.TRIANGLES, this.indexCount, this.mesh.indexType, this.indexOffset); b.disableVertexAttribArray(a.vPosition); b.disableVertexAttribArray(a.vTexCoord) } } ; /* MeshRenderable.prototype.drawWire = function() { var a = this.material.wireShader.attribs , b = this.gl; b.enableVertexAttribArray(a.vPosition); b.bindBuffer(b.ELEMENT_ARRAY_BUFFER, this.mesh.wireBuffer); b.bindBuffer(b.ARRAY_BUFFER, this.mesh.vertexBuffer); b.vertexAttribPointer(a.vPosition, 3, b.FLOAT, !1, this.mesh.stride, 0); b.drawElements(b.LINES, this.wireIndexCount, this.mesh.indexType, this.wireIndexOffset); b.disableVertexAttribArray(a.vPosition) } ; */ MeshRenderable.prototype.complete = function() { return this.material.complete() } ; var Network = { fetchImage: function(a, b, c) { var d = new Image; d.onload = function() { 0 < d.width && 0 < d.height ? b(d) : c && c() } ; c && (req.onerror = function() { c() } ); d.src = a }, fetchText: function(a, b, c, d) { var e = new XMLHttpRequest; e.open("GET", a, !0); e.onload = function() { 200 == e.status ? b(e.responseText) : c && c() } ; c && (e.onerror = function() { c() } ); d && (e.onprogress = function(a) { d(a.loaded, a.total) } ); e.send() }, fetchBinary: function(a, b, c, d) { var e = new XMLHttpRequest; e.open("GET", a, !0); e.responseType = "arraybuffer"; e.onload = function() { 200 == e.status ? b(e.response) : c && c() } ; c && (e.onerror = function() { c() } ); d && (e.onprogress = function(a) { d(a.loaded, a.total) } ); e.send() }, fetchBinaryIncremental: function(a, b, c, d) { var e = new XMLHttpRequest; e.open("HEAD", a, !0); e.onload = function() { if (200 == e.status) { var f = e.getResponseHeader("Accept-Ranges"); if (f && "none" != f) { var g = e.getResponseHeader("Content-Length") | 0 , h = function(c, e) { var f = new XMLHttpRequest; f.open("GET", a, !0); f.setRequestHeader("Range", "bytes=" + c + "-" + e); f.responseType = "arraybuffer"; f.onload = function() { (206 == f.status || 200 == f.status) && b(f.response) && e < g && (c += d, e += d, e = e < g - 1 ? e : g - 1, h(c, e)) } ; f.send() } ; h(0, d - 1) } else c && c() } else c && c() } ; c && (req.onerror = function() { c() } ); e.send() } }; function PostRender(a, b, c) { this.gl = a; this.desc = b; b = []; 0 != this.desc.sharpen && b.push("#define SHARPEN"); (this.useBloom = 0 < this.desc.bloomColor[0] * this.desc.bloomColor[3] || 0 < this.desc.bloomColor[1] * this.desc.bloomColor[3] || 0 < this.desc.bloomColor[2] * this.desc.bloomColor[3]) && b.push("#define BLOOM"); 0 != this.desc.vignette[3] && b.push("#define VIGNETTE"); 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"); 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"); 0 != this.desc.grain && b.push("#define GRAIN"); 1 == this.desc.toneMap ? b.push("#define REINHARD") : 2 == this.desc.toneMap && b.push("#define HEJL"); this.desc.colorLUT && b.push("#define COLOR_LUT"); this.sampleCount = 1; this.sampleIndex = 0; c && (c = [], //改 this.gl.hints.mobile ? (this.sampleCount = 3, this.sampleOffsets = [[-0.4375, -0.5625], [0.625, -0.25], [-0.1875, 0.5]]) : (c.push("#define HIGHQ"), this.sampleCount = 16, this.sampleOffsets = [//逆时针 [-1, 0], [-0.866, -0.5], [-0.7071, -0.7071], [-0.5, -0.866], [0, -1], [0.5, -0.866], [ 0.7071, -0.7071], [0.866, -0.5], [1, 0], [ 0.866, 0.5], [ 0.7071, 0.7071], [ 0.5, 0.866], [0, 1], [-0.5, 0.866], [-0.7071, 0.7071], [-0.866, 0.5] ]), /* this.sampleOffsets = [ //先对称斜四个角,再对称正四个角,再其他 [-0.7071, -0.7071],[ 0.7071, 0.7071], [ 0.7071, -0.7071], [-0.7071, 0.7071], [-1, 0],[1, 0],[0, -1],[0, 1], [-0.866, -0.5],[ 0.866, 0.5], [-0.5, 0.866],[0.5, -0.866], [-0.5, -0.866], [ 0.5, 0.866], [-0.866, 0.5], [0.866, -0.5] ]), */ this.aaResolve = a.shaderCache.fromURLs("postvert.glsl", "aaresolve.glsl", c) ); this.samplesValid = new Uint8Array(16); this.shader = a.shaderCache.fromURLs("postvert.glsl", "postfrag.glsl", b); this.plainShader = a.shaderCache.fromURLs("postvert.glsl", "postfrag.glsl", ["#define SINGLECOLOR"]);//改 this.fullscreenTriangle = a.createBuffer(); a.bindBuffer(a.ARRAY_BUFFER, this.fullscreenTriangle); c = new Float32Array([0, 0, 2, 0, 0, 2]); a.bufferData(a.ARRAY_BUFFER, c, a.STATIC_DRAW); a.bindBuffer(a.ARRAY_BUFFER, null ); if (this.useBloom) { this.bloomTextures = []; this.bloomTargets = []; for (c = 0; 2 > c; ++c) b = { width: 256, height: 256, clamp: !0 }, this.bloomTextures[c] = new Texture(a,b), this.bloomTextures[c].loadArray(null , a.RGBA, a.ext.textureHalf && a.ext.textureHalfLinear ? a.ext.textureHalf.HALF_FLOAT_OES : a.UNSIGNED_BYTE), this.bloomTargets[c] = new Framebuffer(a,{ width: b.width, height: b.height, color0: this.bloomTextures[c] }); for (this.bloomSamples = 64; this.bloomSamples + 16 >= a.limits.fragmentUniforms; ) this.bloomSamples /= 2; this.bloomShader = a.shaderCache.fromURLs("postvert.glsl", "bloom.glsl", ["#define BLOOM_SAMPLES " + this.bloomSamples]) } a = new Uint8Array(16384); for (c = 0; 16384 > c; c++) { b = 255 * Math.random(); var d = 255 * Math.random(); a[c] = 0.5 * (b + d) } this.noiseTexture = new Texture(this.gl,{ width: 128, height: 128 }); this.noiseTexture.loadArray(a, this.gl.LUMINANCE); this.desc.colorLUT && (a = this.desc.colorLUT, this.colorLUT = new Texture(this.gl,{ width: a.length / 3 | 0, height: 1, clamp: !0 }), this.colorLUT.loadArray(new Uint8Array(a), this.gl.RGB)); this.blackTexture = new Texture(this.gl,{ width: 1, height: 1 }); this.blackTexture.loadArray(new Uint8Array([0, 0, 0, 0])); this.bloomResult = this.blackTexture } PostRender.prototype.prepareBloom = function(a) { if (this.useBloom && this.bloomShader.bind()) { var b = []; this.bloomTargets[0].bind(); a.bind(this.bloomShader.samplers.tInput); for (var c = 0, d = 0; d < this.bloomSamples; ++d) { var e = -1 + 2 * d / (this.bloomSamples - 1), f; f = 4 * e; f = Math.exp(-0.5 * f * f / 1) / 2.50662827463; c += f; b[4 * d + 0] = e * this.desc.bloomSize; b[4 * d + 1] = 0; b[4 * d + 2] = f; b[4 * d + 3] = 0 } for (d = 0; d < this.bloomSamples; ++d) b[4 * d + 2] /= c; this.gl.uniform4fv(this.bloomShader.params.uKernel, b); this.fillScreen(this.bloomShader.attribs.vCoord); this.bloomTargets[1].bind(); this.bloomTextures[0].bind(this.bloomShader.samplers.tInput); for (d = 0; d < this.bloomSamples; ++d) c = b[4 * d + 0], c *= a.desc.width / a.desc.height, b[4 * d + 0] = 0, b[4 * d + 1] = c; this.gl.uniform4fv(this.bloomShader.params.uKernel, b); this.fillScreen(this.bloomShader.attribs.vCoord); this.bloomResult = this.bloomTextures[1] } else this.bloomResult = this.blackTexture } ; PostRender.prototype.computeParams = function(a, b) { var c = this.desc , d = {}; d.scale = [c.contrast[0] * c.contrast[3], c.contrast[1] * c.contrast[3], c.contrast[2] * c.contrast[3]]; d.bias = [c.bias[0] * c.bias[3], c.bias[1] * c.bias[3], c.bias[2] * c.bias[3]]; 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]]; var e = [c.brightness[0] * c.brightness[3], c.brightness[1] * c.brightness[3], c.brightness[2] * c.brightness[3]]; d.scale = [d.scale[0] * e[0], d.scale[1] * e[1], d.scale[2] * e[2]]; d.bias = [d.bias[0] * e[0], d.bias[1] * e[1], d.bias[2] * e[2]]; d.saturation = [c.saturation[0] * c.saturation[3], c.saturation[1] * c.saturation[3], c.saturation[2] * c.saturation[3]]; d.bloomColor = [c.bloomColor[0] * c.bloomColor[3], c.bloomColor[1] * c.bloomColor[3], c.bloomColor[2] * c.bloomColor[3]]; d.sharpen = [c.sharpen, 0.25 * c.sharpen, c.sharpenLimit]; d.sharpenKernel = [1 / a, 0, 0, 1 / b]; e = a > b ? a : b; d.vignetteAspect = [a / e, b / e, 0.5 * a / e, 0.5 * b / e]; 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]; var e = 1 / this.noiseTexture.desc.width , f = 1 / this.noiseTexture.desc.height , g = 1 - c.grainSharpness; d.grainCoord = [e * a, f * b, 0.5 * g * e, 0.5 * g * f]; d.grainScaleBias = [2 * c.grain, -c.grain]; return d } ; PostRender.prototype.present = function(a, b, c, d) { 1 < this.sampleCount && this.allocAABuffers(a.desc.width, a.desc.height); d || this.prepareBloom(a); var e = d ? this.plainShader : this.shader; if (e.bind()) { d = this.gl; var f = e.samplers , g = e.params , h = this.computeParams(b, c); a.bind(f.tInput); this.bloomResult.bind(f.tBloom); this.noiseTexture.bind(f.tGrain); this.colorLUT && this.colorLUT.bind(f.tLUT); d.uniform3fv(g.uScale, h.scale); d.uniform3fv(g.uBias, h.bias); d.uniform3fv(g.uSaturation, h.saturation); d.uniform4fv(g.uSharpenKernel, h.sharpenKernel); d.uniform3fv(g.uSharpness, h.sharpen); d.uniform3fv(g.uBloomColor, h.bloomColor); d.uniform4fv(g.uVignetteAspect, h.vignetteAspect); d.uniform4fv(g.uVignette, h.vignette); d.uniform4fv(g.uGrainCoord, h.grainCoord); d.uniform2fv(g.uGrainScaleBias, h.grainScaleBias); if (this.aaResolve) { this.sampleFramebuffers[this.sampleIndex].bind(); this.fillScreen(e.attribs.vCoord); this.samplesValid[this.sampleIndex] = 1; Framebuffer.bindNone(d); d.viewport(0, 0, b, c); this.aaResolve.bind(); for (b = a = 0; b < this.sampleCount; ++b) a += this.samplesValid[b], this.sampleTextures[b].bind(this.aaResolve.samplers["tInput" + b]); a = 1 / a; 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]); this.fillScreen(this.aaResolve.attribs.vCoord); this.sampleIndex = (this.sampleIndex + 1) % this.sampleCount } else Framebuffer.bindNone(d), d.viewport(0, 0, b, c), this.fillScreen(e.attribs.vCoord) } } ; PostRender.prototype.allocAABuffers = function(a, b) { if (void 0 === this.sampleTextures || this.sampleTextures[0].desc.width != a || this.sampleTextures[0].desc.height != b) { this.sampleTextures = []; this.sampleFramebuffers = []; for (var c = 0; c < this.sampleCount; ++c) { var d = new Texture(this.gl,{ width: a, height: b, nofilter: !0 }); d.loadArray(); this.sampleTextures.push(d); this.sampleFramebuffers.push(new Framebuffer(this.gl,{ width: a, height: b, color0: d, ignoreStatus: !0 })) } this.discardAAHistory() } } ; PostRender.prototype.adjustProjectionForSupersampling = function(a) { if (1 < this.sampleCount) { var b = this.sampleOffsets[this.sampleIndex][0] / a.size[0] , c = this.sampleOffsets[this.sampleIndex][1] / a.size[1] , b = Matrix.translation(Matrix.empty(), b, c, 0); Matrix.mul(a.projectionMatrix, b, a.projectionMatrix) } } ; PostRender.prototype.discardAAHistory = function() { for (var a = this.sampleIndex = 0; a < this.samplesValid.length; ++a) this.samplesValid[a] = 0 } ; PostRender.prototype.fillScreen = function(a) { var b = this.gl; b.bindBuffer(b.ARRAY_BUFFER, this.fullscreenTriangle); b.enableVertexAttribArray(a); b.vertexAttribPointer(a, 2, b.FLOAT, !1, 0, 0); b.drawArrays(b.TRIANGLES, 0, 3); b.disableVertexAttribArray(a); b.bindBuffer(b.ARRAY_BUFFER, null ) } ; function Scene(a) { this.gl = a; this.name = "untitled"; this.meshes = []; this.meshRenderables = []; this.materials = {}; this.nextView = this.sky = this.view = null ; this.viewFade = 0; this.shadow = this.stripData = this.lights = null } Scene.prototype.checkFailure = function(data){ var failure = ""; if(!data.meshes.length) failure+="mesh数量为0 "; if(!data.materials.length) failure+="materials数量为0 "; return failure; } Scene.prototype.load = function(a) { var b = this.gl, c; c = a.extract("scene.json"); if (void 0 !== c) { //if (!a.checkSignature(c)) // return !1; c = (new ByteStream(c.data)).asString(); if (null == c || 0 >= c.length) return !1; c = JSON.parse(c) } else return !1; if(!(c.sky.backgroundColor instanceof Array)){//有可能是{0:..,1:..}的情况 c.sky.backgroundColor = [c.sky.backgroundColor[0],c.sky.backgroundColor[1],c.sky.backgroundColor[2],c.sky.backgroundColor[3]] } var failure = this.checkFailure(c); this.metaData = c.metaData; this.view = new View(c.mainCamera.view); this.sky = new Sky(this.gl,a,c.sky); this.lights = new Lights(c.lights,this.view); this.materials = {}; for (var d in c.materials) { var e = c.materials[d]; e.lightCount = this.lights.count; e.shadowCount = this.lights.shadowCount; this.materials[e.name] = new Material(this.gl,a,e) } if (c.meshes) for (e = 0; e < c.meshes.length; ++e) { d = c.meshes[e]; d = new Mesh(this.gl,d,a.extract(d.file)); this.meshes.push(d); for (var f = 0; f < d.desc.subMeshes.length; ++f) { var g = d.desc.subMeshes[f]; this.meshRenderables.push(new MeshRenderable(d,g,this.materials[g.material])) } } this.bounds = new Bounds(this.meshes); this.postRender = new PostRender(this.gl,c.mainCamera.post,!0); this.shadow = new ShadowCollector(b,this.lights.shadowCount); if(failure!="") return {failure:","+failure}; return !0 } ; Scene.prototype.update = function() { this.lights.update(this.view, this.bounds) } ; Scene.prototype.collectShadows = function(a) { this.shadow.collect(this, a) } ; Scene.prototype.draw = function() { var a = this.gl; this.sky.setClearColor(); a.clear(a.COLOR_BUFFER_BIT | a.DEPTH_BUFFER_BIT | a.STENCIL_BUFFER_BIT); a.enable(a.DEPTH_TEST); this.sky.draw(this); for (var b = 0; b < this.meshRenderables.length; ++b) this.meshRenderables[b].material.usesBlending || this.meshRenderables[b].draw(this); a.enable(a.POLYGON_OFFSET_FILL); a.polygonOffset(1, 1); a.colorMask(!1, !1, !1, !1); for (b = 0; b < this.meshRenderables.length; ++b) this.meshRenderables[b].drawAlphaPrepass(this); a.colorMask(!0, !0, !0, !0); a.disable(a.POLYGON_OFFSET_FILL); a.depthFunc(a.LEQUAL); a.depthMask(!1); for (b = 0; b < this.meshRenderables.length; ++b) this.meshRenderables[b].material.usesBlending && this.meshRenderables[b].draw(this); a.depthMask(!0); a.depthFunc(a.LESS); /* if (this.stripData.activeWireframe() && 0 < this.meshRenderables.length) { this.meshRenderables[0].material.bindWire(this); for (b = 0; b < this.meshRenderables.length; ++b) this.meshRenderables[b].drawWire(); } */ a.depthMask(!0) a.disable(a.BLEND) } ; Scene.prototype.complete = function() { if (!this.sky.complete() || !this.shadow.complete()) return !1; for (var a = 0; a < this.meshRenderables.length; ++a) if (!this.meshRenderables[a].complete()) return !1; return !0 } ; function Shader(a) { this.gl = a; this.program = null ; this.params = {}; this.samplers = {}; this.attribs = {} } Shader.prototype.build = function(a, b) { var c = this.gl; this.program = c.createProgram(); this.params = {}; this.samplers = {}; this.attribs = {}; var d = function(a) { for (var b = "", c = a.indexOf("\n"), d = 0; -1 != c; ) d++, b += d + ": ", b += a.substring(0, c + 1), a = a.substring(c + 1, a.length), c = a.indexOf("\n"); console.log(b) } , e = c.createShader(c.VERTEX_SHADER); c.shaderSource(e, a); c.compileShader(e); c.getShaderParameter(e, c.COMPILE_STATUS) || (console.log(c.getShaderInfoLog(e)), fdage.verboseErrors && d(a)); c.attachShader(this.program, e); e = c.createShader(c.FRAGMENT_SHADER); c.shaderSource(e, b); c.compileShader(e); c.getShaderParameter(e, c.COMPILE_STATUS) || (console.log(c.getShaderInfoLog(e)), fdage.verboseErrors && d(b)); c.attachShader(this.program, e); c.linkProgram(this.program); c.getProgramParameter(this.program, c.LINK_STATUS) || console.log(c.getProgramInfoLog(this.program)); for (var e = c.getProgramParameter(this.program, c.ACTIVE_UNIFORMS), f = 0, d = 0; d < e; ++d) { var g = c.getActiveUniform(this.program, d) , h = g.name , k = h.indexOf("["); 0 <= k && (h = h.substring(0, k)); k = c.getUniformLocation(this.program, g.name); g.type == c.SAMPLER_2D || g.type == c.SAMPLER_CUBE ? this.samplers[h] = { location: k, unit: f++ } : this.params[h] = k } e = c.getProgramParameter(this.program, c.ACTIVE_ATTRIBUTES); for (d = 0; d < e; ++d) f = c.getActiveAttrib(this.program, d), this.attribs[f.name] = c.getAttribLocation(this.program, f.name) } ; Shader.prototype.bind = function() { return this.program ? (this.gl.useProgram(this.program), !0) : !1 } ; Shader.prototype.complete = function() { return !!this.program } ; function ShaderCache(a) { this.gl = a; this.cache = [] } ShaderCache.prototype.fromURLs = function(a, b, c) { var d = ""; if (c) for (var e = 0; e < c.length; ++e) d = c[e] + "\n" + d; c = d + ":" + a + "|" + b; e = this.cache[c]; if (void 0 !== e) return e; var f = new Shader(this.gl) , g = null , h = null , k = function() { null != g && null != h && f.build(g, h) } ; this.fetch(a, function(a) { g = d + a; k() }); this.fetch(b, function(a) { h = d + a; k() }); return this.cache[c] = f } ; ShaderCache.prototype.fetch = function(a, b) { "undefined" != typeof ShaderTable ? void 0 !== ShaderTable[a] ? this.resolveIncludes(new String(ShaderTable[a]), b) : b("") : Network.fetchText("src/shader/" + a, function(a) { this.resolveIncludes(a, b) } .bind(this), function() { b("") }) } ; ShaderCache.prototype.resolveIncludes = function(a, b) { for (var c = [], d = !0, e = function(a, b, e, f, m) { d = !0; c.push({ offset: m, path: b.slice(1, b.length - 1) }); return "" } ; d; ) d = !1, a = a.replace(/#include\s((<[^>]+>)|("[^"]+"))/, e); if (0 < c.length) for (var f = c.length, e = 0; e < c.length; ++e) this.fetch(c[e].path, function(d) { this.src = d; if (0 >= --f) { for (d = c.length - 1; 0 <= d; --d) a = a.substring(0, c[d].offset) + c[d].src + a.substring(c[d].offset); b(a) } } .bind(c[e])); else b(a) } ; function ShadowCollector(a, b) { this.gl = a; this.shadowCount = b; this.desc = c; this.shaderSolid = a.shaderCache.fromURLs("shadowvert.glsl", "shadowfrag.glsl"); this.shaderAlphaTest = a.shaderCache.fromURLs("shadowvert.glsl", "shadowfrag.glsl", ["#define ALPHA_TEST 1"]); this.depthTextures = []; this.depthTargets = []; if (0 < this.shadowCount) { var c = { width: 2048, height: 2048, clamp: !0, mipmap: !1, nofilter: !0 }; a.hints.mobile && (c.width = c.height = 1536); for (var d = { width: c.width, height: c.height, depthBuffer: Framebuffer.createDepthBuffer(a, c.width, c.height) }, e = a.RGB, f = a.UNSIGNED_BYTE, g = 0; g < this.shadowCount; ++g) this.depthTextures[g] = new Texture(a,c), this.depthTextures[g].loadArray(null , e, f), d.color0 = this.depthTextures[g], this.depthTargets[g] = new Framebuffer(a,d) } } ShadowCollector.prototype.bindDepthTexture = function(a, b) { this.shadowCount > b && this.depthTextures[b].bind(a) } ; ShadowCollector.prototype.collect = function(a, b) { var c = this.gl , d = a.lights , e = d.shadowCount , f = d.modelViewBuffer , g = d.projectionBuffer , h = d.matrix; if (!(0 >= e)) { for (var k = Matrix.empty(), l = !1, m = 0; m < e; ++m) if (d.shadowsNeedUpdate[m]) { d.shadowsNeedUpdate[m] = 0; l = !0; Matrix.mul(k, f.subarray(16 * m, 16 * (m + 1)), h); Matrix.mul(k, g.subarray(16 * m, 16 * (m + 1)), k); this.depthTargets[m].bind(); c.clearColor(1, 1, 1, 1); c.clear(c.COLOR_BUFFER_BIT | c.DEPTH_BUFFER_BIT); var n = this.shaderSolid; n.bind(); c.uniformMatrix4fv(n.params.uViewProjection, !1, k); for (var r = 0; r < a.meshRenderables.length; ++r) { var p = a.meshRenderables[r] , q = p.material; p.mesh.desc.castShadows && q.castShadows && (0 < q.shadowAlphaTest || p.drawShadow(n.attribs.vPosition)) } n = this.shaderAlphaTest; n.bind(); c.uniformMatrix4fv(n.params.uViewProjection, !1, k); for (r = 0; r < a.meshRenderables.length; ++r) p = a.meshRenderables[r], q = p.material, p.mesh.desc.castShadows && q.castShadows && 0 < q.shadowAlphaTest && (q.textures.albedo.bind(n.samplers.tAlbedo), p.drawAlphaShadow(n.attribs.vPosition, n.attribs.vTexCoord)) } l && (b.bind(), c.enable(c.CULL_FACE), c.cullFace(c.BACK)) } } ; ShadowCollector.prototype.complete = function() { return this.shaderSolid.complete() && this.shaderAlphaTest.complete() } ; function Sky(a, b, c) { this.gl = a; var d = b.extract("sky.dat") || b.extract("sky.png"); if (void 0 !== d) { this.specularTexture = new Texture(a,{ width: 256, height: 2048, clamp: !0 }); b = d.data; for (var d = d.data.length, e = d / 4, f = new Uint8Array(d), g = 0, h = 0; g < d; ++h) f[g++] = b[h + 2 * e], f[g++] = b[h + e], f[g++] = b[h], f[g++] = b[h + 3 * e]; this.specularTexture.loadArray(f) } this.diffuseCoefficients = new Float32Array(c.diffuseCoefficients); this.modelBright = (c.modelBright!==void 0 ? c.modelBright : 1) this.backgroundMode = c.backgroundMode || 0; this.backgroundBrightness = c.backgroundBrightness || 1; this.backgroundColor = new Float32Array(c.backgroundColor); if (1 <= this.backgroundMode) if (this.backgroundShader = a.shaderCache.fromURLs("skyvert.glsl", 3 == this.backgroundMode ? "skySH.glsl" : "sky.glsl", ["#define SKYMODE " + this.backgroundMode]), this.vertexBuffer = a.createBuffer(), a.bindBuffer(a.ARRAY_BUFFER, this.vertexBuffer), c = 1 / 256, b = 0.5 / 256, d = 2.8 * b, e = 0.5 * b, c = new Float32Array([0, 1, 0, 0.49609375 + c, 0.49609375 + c, 1, 0, 0, 0.9921875 + c, 0.49609375 + c, 0, 0, 1, 0.49609375 + c, 0.9921875 + c, -1, 0, 0, 0 + c, 0.49609375 + c, 0, 0, -1, 0.49609375 + c, 0 + c, 0, -1, 0, 0.9921875 + c, 0 + c, 0, -1, 0, 0.9921875 + c, 0.9921875 + c, 0, -1, 0, 0 + c, 0.9921875 + c, 0, -1, 0, 0 + c, 0 + c, d, 1 - d, -d, 0.5 + b, 0.5 - b, d, 1 - d, d, 0.5 + b, 0.5 + b, -d, 1 - d, d, 0.5 - b, 0.5 + b, -d, 1 - d, -d, 0.5 - b, 0.5 - b, -d, 0, -1 + d, 0.5 - b, 0 + c + b, d, 0, -1 + d, 0.5 + b, 0 + c + b, 1 - d, 0, -d, 0.9921875 + c - b, 0.5 - b, 1 - d, 0, d, 0.9921875 + c - b, 0.5 + b, d, 0, 1 - d, 0.5 + b, 0.9921875 + c - b, -d, 0, 1 - d, 0.5 - b, 0.9921875 + c - b, -1 + d, 0, d, 0 + c + b, 0.5 + b, -1 + d, 0, -d, 0 + c + b, 0.5 - b, 1, 0, 0, 0.9921875 + c - e, 0.49609375 + c, 0, 0, 1, 0.49609375 + c, 0.9921875 + c - e, -1, 0, 0, 0 + c + e, 0.49609375 + c, 0, 0, -1, 0.49609375 + c, 0 + c + e, 0, 1, 0, 0.49609375 + c - e, 0.49609375 + c, 0, 1, 0, 0.49609375 + c, 0.49609375 + c - e, 0, 1, 0, 0.49609375 + c + e, 0.49609375 + c, 0, 1, 0, 0.49609375 + c, 0.49609375 + c + e]), a.bufferData(a.ARRAY_BUFFER, c, a.STATIC_DRAW), a.bindBuffer(a.ARRAY_BUFFER, null ), this.indexBuffer = a.createBuffer(), a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, this.indexBuffer), c = new Uint16Array([2, 1, 6, 3, 2, 7, 8, 4, 3, 4, 5, 1, 9, 14, 15, 17, 10, 16, 18, 19, 11, 20, 13, 12, 28, 12, 13, 13, 24, 28, 28, 24, 9, 9, 24, 14, 25, 9, 15, 25, 15, 21, 10, 25, 21, 10, 21, 16, 22, 26, 10, 22, 10, 17, 18, 11, 26, 22, 18, 26, 19, 23, 27, 19, 27, 11, 23, 20, 27, 27, 20, 12]), this.skyIndexCount = c.length, a.bufferData(a.ELEMENT_ARRAY_BUFFER, c, a.STATIC_DRAW), a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, null ), 3 == this.backgroundMode) for (this.backgroundCoefficients = new Float32Array(this.diffuseCoefficients), g = 0; g < this.backgroundCoefficients.length; ++g) this.backgroundCoefficients[g] *= this.backgroundBrightness; else { this.backgroundTexture = new Texture(a,{ width: 256, height: 256, clamp: !0 }); c = !1; var k; a.ext.textureHalf && a.ext.textureHalfLinear && (this.backgroundTexture.loadArray(null , a.RGB, a.ext.textureHalf.HALF_FLOAT_OES), k = new Framebuffer(a,{ color0: this.backgroundTexture }), c = k.valid); !c && a.ext.textureFloat && a.ext.textureFloatLinear && !a.hints.mobile && (this.backgroundTexture.loadArray(null , a.RGB, a.FLOAT), k = new Framebuffer(a,{ color0: this.backgroundTexture }), c = k.valid); c || (this.backgroundTexture.loadArray(), k = new Framebuffer(a,{ color0: this.backgroundTexture })); k.bind(); k = new Shader(a); 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);}"); k.bind(); a.uniform1f(k.params.b, 7 * Math.sqrt(this.backgroundBrightness)); this.specularTexture.bind(k.samplers.tex); c = a.createBuffer(); a.bindBuffer(a.ARRAY_BUFFER, c); c = new Float32Array([-1, -1, 0.5, 1, 3, -1, 0.5, 1, -1, 3, 0.5, 1]); a.bufferData(a.ARRAY_BUFFER, c, a.STATIC_DRAW); a.enableVertexAttribArray(k.attribs.p); a.vertexAttribPointer(k.attribs.p, 4, a.FLOAT, !1, 0, 0); a.drawArrays(a.TRIANGLES, 0, 3); a.disableVertexAttribArray(k.attribs.p) } } Sky.prototype.setClearColor = function() { if(fdage.backgroundColor){ var a = fdage.backgroundColor; this.gl.clearColor(a[0], a[1], a[2], 1); } else if (fdage.transparentBackground) this.gl.clearColor(0, 0, 0, 0); else if (1 > this.backgroundMode) { var a = this.backgroundColor; this.gl.clearColor(a[0], a[1], a[2], 1) } else this.gl.clearColor(0.0582, 0.06772, 0.07805, 1) } ; Sky.prototype.draw = function(a) { if (1 > this.backgroundMode || fdage.backgroundColor) return !1; if (this.complete()) { var b = this.gl , c = this.backgroundShader , d = a.view , e = a.lights.invMatrix; c.bind(); b.uniformMatrix4fv(c.params.uInverseSkyMatrix, !1, e); b.uniformMatrix4fv(c.params.uViewProjection, !1, d.viewProjectionMatrix); 3 == this.backgroundMode ? b.uniform4fv(c.params.uSkyCoefficients, this.backgroundCoefficients) : this.backgroundTexture.bind(c.samplers.tSkyTexture); a = 1.01; b.uniform1f(c.params.uAlpha, a); b.bindBuffer(b.ARRAY_BUFFER, this.vertexBuffer); b.enableVertexAttribArray(c.attribs.vPosition); b.vertexAttribPointer(c.attribs.vPosition, 3, b.FLOAT, !1, 20, 0); b.enableVertexAttribArray(c.attribs.vTexCoord); b.vertexAttribPointer(c.attribs.vTexCoord, 2, b.FLOAT, !1, 20, 12); b.bindBuffer(b.ELEMENT_ARRAY_BUFFER, this.indexBuffer); 1 > a && (b.enable(b.BLEND), b.blendFunc(b.SRC_ALPHA, b.ONE_MINUS_SRC_ALPHA)); b.depthMask(!1); b.disable(b.DEPTH_TEST); b.drawElements(b.TRIANGLES, this.skyIndexCount, b.UNSIGNED_SHORT, 0); b.enable(b.DEPTH_TEST); b.depthMask(!0); 1 > a && b.disable(b.BLEND); b.disableVertexAttribArray(c.attribs.vPosition); b.disableVertexAttribArray(c.attribs.vTexCoord) } } ; Sky.prototype.complete = function() { return this.backgroundShader && !this.backgroundShader.complete() ? !1 : this.specularTexture.complete() } ; function Texture(a, b) { this.gl = a; this.type = a.TEXTURE_2D; this.id = null ; b = b || {}; this.desc = { width: b.width || 1, height: b.height || 1, mipmap: b.mipmap, clamp: b.clamp, aniso: b.aniso, nofilter: b.nofilter } } Texture.prototype.loadImage = function(a, b) { var c = this.gl; a && a.width && a.height && (this.desc.width = a.width, this.desc.height = a.height); this.id = c.createTexture(); c.bindTexture(this.type, this.id); c.pixelStorei(c.UNPACK_FLIP_Y_WEBGL, !0); c.texImage2D(this.type, 0, b || c.RGBA, b || c.RGBA, c.UNSIGNED_BYTE, a); this.setParams(); c.bindTexture(this.type, null ) } ; Texture.prototype.loadArray = function(a, b, c) { var d = this.gl; this.id = d.createTexture(); d.bindTexture(this.type, this.id); d.pixelStorei(d.UNPACK_FLIP_Y_WEBGL, !0); d.texImage2D(this.type, 0, b || d.RGBA, this.desc.width, this.desc.height, 0, b || d.RGBA, c || d.UNSIGNED_BYTE, a || null ); this.setParams(); d.bindTexture(this.type, null ) } ; Texture.prototype.setParams = function() { var a = this.gl , b = function(a) { return 0 < a && 0 == (a & a - 1) } ; b(this.desc.width) && b(this.desc.height) || (this.desc.clamp = !0, this.desc.mipmap = !1); b = !this.desc.nofilter; this.desc.mipmap ? (a.generateMipmap(this.type), a.texParameteri(this.type, a.TEXTURE_MIN_FILTER, b ? a.LINEAR_MIPMAP_LINEAR : a.NEAREST_MIPMAP_NEAREST)) : a.texParameteri(this.type, a.TEXTURE_MIN_FILTER, b ? a.LINEAR : a.NEAREST); a.texParameteri(this.type, a.TEXTURE_MAG_FILTER, b ? a.LINEAR : a.NEAREST); this.desc.clamp && (a.texParameteri(this.type, a.TEXTURE_WRAP_S, a.CLAMP_TO_EDGE), a.texParameteri(this.type, a.TEXTURE_WRAP_T, a.CLAMP_TO_EDGE)); this.desc.aniso && a.ext.textureAniso && a.texParameteri(this.type, a.ext.textureAniso.TEXTURE_MAX_ANISOTROPY_EXT, this.desc.aniso) } ; Texture.prototype.rebuildMips = function() { this.desc.mipmap && (this.gl.bindTexture(this.type, this.id), this.gl.generateMipmap(this.type)) } ; Texture.prototype.bind = function(a) { if (a) { var b = this.gl; b.uniform1i(a.location, a.unit); b.activeTexture(b.TEXTURE0 + a.unit); b.bindTexture(this.type, this.id) } } ; Texture.prototype.destroy = function() { this.gl.deleteTexture(this.id); this.id = null } ; Texture.prototype.complete = function() { return !!this.id } ; function TextureCache(a) { this.gl = a; this.cache = [] } TextureCache.prototype.fromURL = function(a, b) { var c = this.cache[a]; if (void 0 !== c) return c; var d = new Texture(this.gl,b); Network.fetchImage(a, function(a) { d.loadImage(a) }); return this.cache[a] = d } ; TextureCache.prototype.fromFile = function(a, b) { if (!a) return null ; var c = this.cache[a.name]; if (void 0 !== c) return c; var d = new Texture(this.gl,b); this.cache[a.name] = d; TextureCache.parseFile(a, function(a) { d.loadImage(a) }); return d } ; TextureCache.prototype.fromFilesMergeAlpha = function(a, b, c) { if (!b) return this.fromFile(a, c); var d = a.name + "|" + b.name , e = this.cache[d]; if (void 0 !== e) return e; var f = this.gl; this.mergeShader || (this.mergeShader = new Shader(this.gl), 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; }"), this.mergeVerts = f.createBuffer(), f.bindBuffer(f.ARRAY_BUFFER, this.mergeVerts), e = new Float32Array([0, 0, 2, 0, 0, 2]), f.bufferData(f.ARRAY_BUFFER, e, f.STATIC_DRAW), f.bindBuffer(f.ARRAY_BUFFER, null )); var g = new Texture(this.gl,c); this.cache[d] = g; var h = 0 , k = 0 , l = this.mergeShader , m = this.mergeVerts , n = function() { if (h && k) { var a = h.width > k.width ? h.width : k.width , b = h.height > k.height ? h.height : k.height; g.desc.width = a; g.desc.height = b; if (a <= f.limits.viewportSizes[0] && b <= f.limits.viewportSizes[1]) g.loadArray(null ), (new Framebuffer(f,{ color0: g, ignoreStatus: !0 })).bind(), b = { clamp: !0 }, a = new Texture(f,b), a.loadImage(h, f.RGB), b = new Texture(f,b), b.loadImage(k, f.RGB), l.bind(), a.bind(l.samplers.tRGB), b.bind(l.samplers.tA), f.bindBuffer(f.ARRAY_BUFFER, m), f.enableVertexAttribArray(l.attribs.pos), f.vertexAttribPointer(l.attribs.pos, 2, f.FLOAT, !1, 0, 0), f.drawArrays(f.TRIANGLES, 0, 3), f.disableVertexAttribArray(l.attribs.pos), f.bindBuffer(f.ARRAY_BUFFER, null ), a.destroy(), b.destroy(), Framebuffer.bindNone(f), g.rebuildMips(); else { var c = document.createElement("canvas"); c.width = a; c.height = b; var d = c.getContext("2d"); d.drawImage(h, 0, 0); c = d.getImageData(0, 0, a, b); c = new Uint8Array(c.data.buffer,c.data.byteOffset,c.data.length); d.drawImage(k, 0, 0); d = d.getImageData(0, 0, a, b).data; a = a * b * 4; for (b = 0; b < a; b += 4) c[b + 3] = d[b]; g.loadArray(c) } } } ; TextureCache.parseFile(a, function(a) { h = a; n() }); TextureCache.parseFile(b, function(a) { k = a; n() }); return g } ; TextureCache.parseFile = function(a, b, c) { var d = c || new Image; if ("undefined" != typeof URL && "undefined" != typeof URL.createObjectURL) { a = new Blob([a.data],{ type: a.type }); var e = URL.createObjectURL(a); d.onload = function() { URL.revokeObjectURL(e); b && b(d) } ; d.src = e } else { a = new Blob([a.data],{ type: a.type }); var f = new FileReader; f.onload = function(a) { d.src = f.result } ; d.onload = function() { b && b(d) } ; f.readAsDataURL(a) } } ; function UI(a) { this.viewer = a; this.stripData = a.stripData; a = this.container = document.createElement("div"); a.id = "fdageUI"; a.style.position = "absolute"; a.style.overflow = "hidden"; a.style["-moz-user-select"] = "none"; a.style["-khtml-user-select"] = "none"; a.style["-webkit-user-select"] = "none"; a.style["-ms-user-select"] = "none"; this.viewer.domRoot.appendChild(a) } UI.prototype.setSize = function(a, b) { this.container.width = a | 0; this.container.height = b | 0; this.container.style.width = a + "px"; this.container.style.height = b + "px" } ; UI.prototype.clearView = function() { for (; this.container.hasChildNodes(); ) this.container.removeChild(this.container.childNodes[0]); delete this.progressBar; delete this.thumbnail; delete this.fadeThumbnail; delete this.playButton; delete this.helpOverlay } ; UI.prototype.bindInput = function(a) { a.onSingleTap.push(function(b, c) { //this.stripData.selectedStrip != this.stripData.STRIP_NONE && (b = 2 / a.element.clientWidth * b - 1, c = 1 - 2 / a.element.clientHeight * c, // this.stripData.selectStrip(b, c), // this.stripData.selectedStrip == this.stripData.STRIP_MENU && this.helpOverlay.active && this.helpOverlay.toggle(), this.refreshUI(), this.viewer.wake() } .bind(this)); a.onDoubleTap.push(function(a, c) { this.viewer.scene.view.reset(); this.viewer.wake() } .bind(this)) } ; UI.sanitize = function(a) { return a ? a.replace(/<|>|\(|\)|$|%|=/g, "") : a } ; UI.sanitizeURL = function(a) { return a ? 0 == a.indexOf("http://") || 0 == a.indexOf("https://") || 0 == a.indexOf("ftp://") ? encodeURI(a) : "http://" + encodeURI(a) : a } ; UI.prototype.showFailure = function(info) { this.container.innerHTML = ""; var errorCanvas = document.createElement('canvas'); var ra = this.container.width / this.container.height; errorCanvas.width = 100; errorCanvas.height = errorCanvas.height * ra | 0; errorCanvas.style.position = "absolute"; errorCanvas.style['z-index'] = "-1"; errorCanvas.style.width = errorCanvas.style.height = "100%"; var a = errorCanvas.getContext("2d"); 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) b.addColorStop(0, "rgb(0,0,0)"); b.addColorStop(1, "rgb(35,60,80)");//22,43,64 117,133,148 a.fillStyle = b; a.fillRect(0, 0, errorCanvas.width, errorCanvas.height); this.container.appendChild(errorCanvas); var errorDiv = document.createElement('div'); dom.addClass(errorDiv,"error"); errorDiv.style["background-image"] = "url(images/errorBG.png)"; var msg = '
转换模型时出错
' +'(错误信息:'+(info || "") + ')
' +'文件无效(ERROR)请检查您所上传的文件以确定其稳定性
' +'请再次上传您的模型
或者您也可以联系我们的客服、或点击下面的视频教程链接获取跟详细的上传解说
4Dweb将全程为您提供最优质的模型展示