stratux/web/js/j3di-all.min.js

3 wiersze
32 KiB
JavaScript

function initWebGL(t){var r=document.getElementById(t);return gl=WebGLUtils.setupWebGL(r)}function log(t){window.console&&window.console.log&&window.console.log(t)}function simpleSetup(t,r,i,e,a,m){var n=loadShader(t,r),x=loadShader(t,i),s=t.createProgram();t.attachShader(s,n),t.attachShader(s,x);for(var o=0;o<e.length;++o)t.bindAttribLocation(s,o,e[o]);t.linkProgram(s);var h=t.getProgramParameter(s,t.LINK_STATUS);if(!h&&!t.isContextLost()){var $=t.getProgramInfoLog(s);return log("Error in program linking:"+$),t.deleteProgram(s),t.deleteProgram(x),t.deleteProgram(n),null}return t.useProgram(s),t.clearColor(a[0],a[1],a[2],a[3]),t.clearDepth(m),t.enable(t.DEPTH_TEST),t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),s}function loadShader(t,r){var i=document.getElementById(r);return i?loadShaderScript(t,i.text,i.type):(log("*** Error: shader script '"+r+"' not found"),null)}function loadShaderVertexScript(t,r){return loadShaderScript(t,r,"x-shader/x-vertex")}function loadShaderFragmentScript(t,r){return loadShaderScript(t,r,"x-shader/x-fragment")}function loadShaderScript(t,r,i){if(!r)return log("*** Error: shader script missing"),null;if("x-shader/x-vertex"==i)var e=t.VERTEX_SHADER;else{if("x-shader/x-fragment"!=i)return log("*** Error: shader script of undefined type '"+i+"'"),null;var e=t.FRAGMENT_SHADER}var a=t.createShader(e);t.shaderSource(a,r),t.compileShader(a);var m=t.getShaderParameter(a,t.COMPILE_STATUS);if(!m&&!t.isContextLost()){var n=t.getShaderInfoLog(a);return log("*** Error compiling shader: "+n),t.deleteShader(a),null}return a}function clearLoadingObjects(){for(var t=0;t<g_loadingObjects.length;++t)g_loadingObjects[t].onreadystatechange=void 0;g_loadingObjects=[]}function loadObj(t,r){var i={loaded:!1};i.ctx=t;var e=new XMLHttpRequest;return e.obj=i,g_loadingObjects.push(e),e.onreadystatechange=function(){processLoadObj(e)},e.open("GET",r,!0),e.send(null),i}function processLoadObj(t){log("req="+t),4==t.readyState&&(g_loadingObjects.splice(g_loadingObjects.indexOf(t),1),doLoadObj(t.obj,t.responseText))}function doLoadObj(t,r){vertexArray=[],normalArray=[],textureArray=[],indexArray=[];var i=[],e=[],a=[],m={},n=0,x={},s=[-1,0];x._unnamed=s;var o=r.split("\n");for(var h in o){var $=o[h].replace(/[ \t]+/g," ").replace(/\s\s*$/,"");if("#"!=$[0]){var u=$.split(" ");if("g"==u[0])s=[indexArray.length,0],x[u[1]]=s;else if("v"==u[0])i.push(parseFloat(u[1])),i.push(parseFloat(u[2])),i.push(parseFloat(u[3]));else if("vt"==u[0])a.push(parseFloat(u[1])),a.push(parseFloat(u[2]));else if("vn"==u[0])e.push(parseFloat(u[1])),e.push(parseFloat(u[2])),e.push(parseFloat(u[3]));else if("f"==u[0]){if(4!=u.length){log("*** Error: face '"+$+"' not handled");continue}for(var f=1;4>f;++f){if(!(u[f]in m)){var l,c,d,g=u[f].split("/");if(1==g.length)l=parseInt(g[0])-1,c=l,d=l;else{if(!(g.length=3))return t.ctx.console.log("*** Error: did not understand face '"+u[f]+"'"),null;l=parseInt(g[0])-1,d=parseInt(g[1])-1,c=parseInt(g[2])-1}var p=0,v=0,A=0;3*l+2<i.length&&(p=i[3*l],v=i[3*l+1],A=i[3*l+2]),vertexArray.push(p),vertexArray.push(v),vertexArray.push(A),p=0,v=0,2*d+1<a.length&&(p=a[2*d],v=a[2*d+1]),textureArray.push(p),textureArray.push(v),p=0,v=0,A=1,3*c+2<e.length&&(p=e[3*c],v=e[3*c+1],A=e[3*c+2]),normalArray.push(p),normalArray.push(v),normalArray.push(A),m[u[f]]=n++}indexArray.push(m[u[f]]),s[1]++}}}}t.normalObject=t.ctx.createBuffer(),t.ctx.bindBuffer(t.ctx.ARRAY_BUFFER,t.normalObject),t.ctx.bufferData(t.ctx.ARRAY_BUFFER,new Float32Array(normalArray),t.ctx.STATIC_DRAW),t.texCoordObject=t.ctx.createBuffer(),t.ctx.bindBuffer(t.ctx.ARRAY_BUFFER,t.texCoordObject),t.ctx.bufferData(t.ctx.ARRAY_BUFFER,new Float32Array(textureArray),t.ctx.STATIC_DRAW),t.vertexObject=t.ctx.createBuffer(),t.ctx.bindBuffer(t.ctx.ARRAY_BUFFER,t.vertexObject),t.ctx.bufferData(t.ctx.ARRAY_BUFFER,new Float32Array(vertexArray),t.ctx.STATIC_DRAW),t.numIndices=indexArray.length,t.indexObject=t.ctx.createBuffer(),t.ctx.bindBuffer(t.ctx.ELEMENT_ARRAY_BUFFER,t.indexObject),t.ctx.bufferData(t.ctx.ELEMENT_ARRAY_BUFFER,new Uint16Array(indexArray),t.ctx.STREAM_DRAW),t.groups=x,t.loaded=!0}function clearLoadingImages(){for(var t=0;t<g_loadingImages.length;++t)g_loadingImages[t].onload=void 0;g_loadingImages=[]}function loadImageTexture(t,r){var i=t.createTexture();t.bindTexture(t.TEXTURE_2D,i),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,null);var e=new Image;return g_loadingImages.push(e),e.onload=function(){doLoadImageTexture(t,e,i)},e.src=r,i}function doLoadImageTexture(t,r,i){g_loadingImages.splice(g_loadingImages.indexOf(r),1),t.bindTexture(t.TEXTURE_2D,i),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.bindTexture(t.TEXTURE_2D,null)}WebGLUtils=function(){var t=function(t){return'<table style="background-color: #8CE; width: 100%; height: 100%;"><tr><td align="center"><div style="display: table-cell; vertical-align: middle;"><div style="">'+t+"</div></div></td></tr></table>"},r='This page requires a browser that supports WebGL.<br/><a href="http://get.webgl.org">Click here to upgrade your browser.</a>',i='It doesn\'t appear your computer can support WebGL.<br/><a href="http://get.webgl.org/troubleshooting/">Click here for more information.</a>',e=function(e,m){function n(r){var i=e.parentNode;i&&(i.innerHTML=t(r))}if(!window.WebGLRenderingContext)return n(r),null;var x=a(e,m);return x||n(i),x},a=function(t,r){for(var i=["webgl","experimental-webgl","webkit-3d","moz-webgl"],e=null,a=0;a<i.length;++a){try{e=t.getContext(i[a],r)}catch(m){}if(e)break}return e};return{create3DContext:a,setupWebGL:e}}(),window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(t){return window.setTimeout(t,1e3/60)}}(),window.cancelAnimFrame=function(){return window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||window.clearTimeout}(),WebGLDebugUtils=function(){function t(t){if(null==f){f={},l={};for(var r in t)"number"==typeof t[r]&&(f[t[r]]=r,l[r]=t[r])}}function r(){if(null==f)throw"WebGLDebugUtils.init(ctx) not called"}function i(t){return r(),void 0!==f[t]}function e(t){r();var i=f[t];return void 0!==i?"gl."+i:"/*UNKNOWN WebGL ENUM*/ 0x"+t.toString(16)}function a(t,r,i,a){var m=u[t];if(void 0!==m){var m=m[r];if(void 0!==m&&m[i]){if("object"==typeof m[i]&&void 0!==m[i].enumBitwiseOr){for(var n=m[i].enumBitwiseOr,x=0,s=[],o=0;o<n.length;++o){var h=l[n[o]];0!==(a&h)&&(x|=h,s.push(e(h)))}return x===a?s.join(" | "):e(a)}return e(a)}}return null===a?"null":void 0===a?"undefined":a.toString()}function m(t,r){for(var i="",e=r.length,m=0;e>m;++m)i+=(0==m?"":", ")+a(t,e,m,r[m]);return i}function n(t,r,i){t.__defineGetter__(i,function(){return r[i]}),t.__defineSetter__(i,function(t){r[i]=t})}function x(r,i,m,s){function o(t,r){return function(){m&&m(r,arguments);var e=t[r].apply(t,arguments),a=s.getError();return 0!=a&&(h[a]=!0,i(a,r,arguments)),e}}s=s||r,t(r),i=i||function(t,r,i){for(var m="",n=i.length,x=0;n>x;++x)m+=(0==x?"":", ")+a(r,n,x,i[x]);$("WebGL error "+e(t)+" in "+r+"("+m+")")};var h={},u={};for(var f in r)if("function"==typeof r[f])if("getExtension"!=f)u[f]=o(r,f);else{var l=o(r,f);u[f]=function(){var t=l.apply(r,arguments);return x(t,i,m,s)}}else n(u,r,f);return u.getError=function(){for(var t in h)if(h.hasOwnProperty(t)&&h[t])return h[t]=!1,t;return r.NO_ERROR},u}function s(t){var r=t.getParameter(t.MAX_VERTEX_ATTRIBS),i=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,i);for(var e=0;r>e;++e)t.disableVertexAttribArray(e),t.vertexAttribPointer(e,4,t.FLOAT,!1,0,0),t.vertexAttrib1f(e,0);t.deleteBuffer(i);for(var a=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),e=0;a>e;++e)t.activeTexture(t.TEXTURE0+e),t.bindTexture(t.TEXTURE_CUBE_MAP,null),t.bindTexture(t.TEXTURE_2D,null);for(t.activeTexture(t.TEXTURE0),t.useProgram(null),t.bindBuffer(t.ARRAY_BUFFER,null),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,null),t.bindFramebuffer(t.FRAMEBUFFER,null),t.bindRenderbuffer(t.RENDERBUFFER,null),t.disable(t.BLEND),t.disable(t.CULL_FACE),t.disable(t.DEPTH_TEST),t.disable(t.DITHER),t.disable(t.SCISSOR_TEST),t.blendColor(0,0,0,0),t.blendEquation(t.FUNC_ADD),t.blendFunc(t.ONE,t.ZERO),t.clearColor(0,0,0,0),t.clearDepth(1),t.clearStencil(-1),t.colorMask(!0,!0,!0,!0),t.cullFace(t.BACK),t.depthFunc(t.LESS),t.depthMask(!0),t.depthRange(0,1),t.frontFace(t.CCW),t.hint(t.GENERATE_MIPMAP_HINT,t.DONT_CARE),t.lineWidth(1),t.pixelStorei(t.PACK_ALIGNMENT,4),t.pixelStorei(t.UNPACK_ALIGNMENT,4),t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,!1),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),t.UNPACK_COLORSPACE_CONVERSION_WEBGL&&t.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,t.BROWSER_DEFAULT_WEBGL),t.polygonOffset(0,0),t.sampleCoverage(1,!1),t.scissor(0,0,t.canvas.width,t.canvas.height),t.stencilFunc(t.ALWAYS,0,4294967295),t.stencilMask(4294967295),t.stencilOp(t.KEEP,t.KEEP,t.KEEP),t.viewport(0,0,t.canvas.width,t.canvas.height),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT|t.STENCIL_BUFFER_BIT);t.getError(););}function o(t){function r(t){return"function"==typeof t?t:function(r){t.handleEvent(r)}}function i(t){var r=t.addEventListener;t.addEventListener=function(i,e){switch(i){case"webglcontextlost":I(e);break;case"webglcontextrestored":y(e);break;default:r.apply(t,arguments)}}}function e(){for(var t=Object.keys(E),r=0;r<t.length;++r)delete E[t]}function a(){++v,d||p==v&&t.loseContext()}function m(t,r){var i=t[r];return function(){if(a(),!d){var r=i.apply(t,arguments);return r}}}function x(){for(var t=0;t<g.length;++t){var r=g[t];r instanceof WebGLBuffer?$.deleteBuffer(r):r instanceof WebGLFramebuffer?$.deleteFramebuffer(r):r instanceof WebGLProgram?$.deleteProgram(r):r instanceof WebGLRenderbuffer?$.deleteRenderbuffer(r):r instanceof WebGLShader?$.deleteShader(r):r instanceof WebGLTexture&&$.deleteTexture(r)}}function o(t){return{statusMessage:t,preventDefault:function(){A=!0}}}function h(t){for(var r in t)"function"==typeof t[r]?u[r]=m(t,r):n(u,t,r);u.getError=function(){if(a(),!d)for(var t;t=$.getError();)E[t]=!0;for(var t in E)if(E[t])return delete E[t],t;return u.NO_ERROR};for(var i=["createBuffer","createFramebuffer","createProgram","createRenderbuffer","createShader","createTexture"],e=0;e<i.length;++e){var x=i[e];u[x]=function(r){return function(){if(a(),d)return null;var i=r.apply(t,arguments);return i.__webglDebugContextLostId__=c,g.push(i),i}}(t[x])}for(var s=["getActiveAttrib","getActiveUniform","getBufferParameter","getContextAttributes","getAttachedShaders","getFramebufferAttachmentParameter","getParameter","getProgramParameter","getProgramInfoLog","getRenderbufferParameter","getShaderParameter","getShaderInfoLog","getShaderSource","getTexParameter","getUniform","getUniformLocation","getVertexAttrib"],e=0;e<s.length;++e){var x=s[e];u[x]=function(r){return function(){return a(),d?null:r.apply(t,arguments)}}(u[x])}for(var o=["isBuffer","isEnabled","isFramebuffer","isProgram","isRenderbuffer","isShader","isTexture"],e=0;e<o.length;++e){var x=o[e];u[x]=function(r){return function(){return a(),d?!1:r.apply(t,arguments)}}(u[x])}return u.checkFramebufferStatus=function(r){return function(){return a(),d?u.FRAMEBUFFER_UNSUPPORTED:r.apply(t,arguments)}}(u.checkFramebufferStatus),u.getAttribLocation=function(r){return function(){return a(),d?-1:r.apply(t,arguments)}}(u.getAttribLocation),u.getVertexAttribOffset=function(r){return function(){return a(),d?0:r.apply(t,arguments)}}(u.getVertexAttribOffset),u.isContextLost=function(){return d},u}var $,u,f=[],l=[],u={},c=1,d=!1,g=[],p=0,v=0,A=!1,b=0,E={};t.getContext=function(r){return function(){var i=r.apply(t,arguments);if(i instanceof WebGLRenderingContext){if(i!=$){if($)throw"got different context";$=i,u=h($)}return u}return i}}(t.getContext);var I=function(t){f.push(r(t))},y=function(t){l.push(r(t))};return i(t),t.loseContext=function(){if(!d){for(d=!0,p=0,++c;$.getError(););e(),E[$.CONTEXT_LOST_WEBGL]=!0;var r=o("context lost"),i=f.slice();setTimeout(function(){for(var e=0;e<i.length;++e)i[e](r);b>=0&&setTimeout(function(){t.restoreContext()},b)},0)}},t.restoreContext=function(){d&&l.length&&setTimeout(function(){if(!A)throw"can not restore. webglcontestlost listener did not call event.preventDefault";x(),s($),d=!1,v=0,A=!1;for(var t=l.slice(),r=o("context restored"),i=0;i<t.length;++i)t[i](r)},0)},t.loseContextInNCalls=function(t){if(d)throw"You can not ask a lost contet to be lost";p=v+t},t.getNumCalls=function(){return v},t.setRestoreTimeout=function(t){b=t},t}var h=function(t){window.console&&window.console.log&&window.console.log(t)},$=function(t){window.console&&window.console.error?window.console.error(t):h(t)},u={enable:{1:{0:!0}},disable:{1:{0:!0}},getParameter:{1:{0:!0}},drawArrays:{3:{0:!0}},drawElements:{4:{0:!0,2:!0}},createShader:{1:{0:!0}},getShaderParameter:{2:{1:!0}},getProgramParameter:{2:{1:!0}},getShaderPrecisionFormat:{2:{0:!0,1:!0}},getVertexAttrib:{2:{1:!0}},vertexAttribPointer:{6:{2:!0}},bindTexture:{2:{0:!0}},activeTexture:{1:{0:!0}},getTexParameter:{2:{0:!0,1:!0}},texParameterf:{3:{0:!0,1:!0}},texParameteri:{3:{0:!0,1:!0,2:!0}},texImage2D:{9:{0:!0,2:!0,6:!0,7:!0},6:{0:!0,2:!0,3:!0,4:!0}},texSubImage2D:{9:{0:!0,6:!0,7:!0},7:{0:!0,4:!0,5:!0}},copyTexImage2D:{8:{0:!0,2:!0}},copyTexSubImage2D:{8:{0:!0}},generateMipmap:{1:{0:!0}},compressedTexImage2D:{7:{0:!0,2:!0}},compressedTexSubImage2D:{8:{0:!0,6:!0}},bindBuffer:{2:{0:!0}},bufferData:{3:{0:!0,2:!0}},bufferSubData:{3:{0:!0}},getBufferParameter:{2:{0:!0,1:!0}},pixelStorei:{2:{0:!0,1:!0}},readPixels:{7:{4:!0,5:!0}},bindRenderbuffer:{2:{0:!0}},bindFramebuffer:{2:{0:!0}},checkFramebufferStatus:{1:{0:!0}},framebufferRenderbuffer:{4:{0:!0,1:!0,2:!0}},framebufferTexture2D:{5:{0:!0,1:!0,2:!0}},getFramebufferAttachmentParameter:{3:{0:!0,1:!0,2:!0}},getRenderbufferParameter:{2:{0:!0,1:!0}},renderbufferStorage:{4:{0:!0,1:!0}},clear:{1:{0:{enumBitwiseOr:["COLOR_BUFFER_BIT","DEPTH_BUFFER_BIT","STENCIL_BUFFER_BIT"]}}},depthFunc:{1:{0:!0}},blendFunc:{2:{0:!0,1:!0}},blendFuncSeparate:{4:{0:!0,1:!0,2:!0,3:!0}},blendEquation:{1:{0:!0}},blendEquationSeparate:{2:{0:!0,1:!0}},stencilFunc:{3:{0:!0}},stencilFuncSeparate:{4:{0:!0,1:!0}},stencilMaskSeparate:{2:{0:!0}},stencilOp:{3:{0:!0,1:!0,2:!0}},stencilOpSeparate:{4:{0:!0,1:!0,2:!0,3:!0}},cullFace:{1:{0:!0}},frontFace:{1:{0:!0}},drawArraysInstancedANGLE:{4:{0:!0}},drawElementsInstancedANGLE:{5:{0:!0,2:!0}},blendEquationEXT:{1:{0:!0}}},f=null,l=null;return{init:t,mightBeEnum:i,glEnumToString:e,glFunctionArgToString:a,glFunctionArgsToString:m,makeDebugContext:x,makeLostContextSimulatingCanvas:o,resetToInitialState:s}}();var g_loadingObjects=[],g_loadingImages=[];Framerate=function(t){this.numFramerates=10,this.framerateUpdateInterval=500,this.id=t,this.renderTime=-1,this.framerates=[],self=this;var r=function(){self.updateFramerate()};setInterval(r,this.framerateUpdateInterval)},Framerate.prototype.updateFramerate=function(){for(var t=0,r=0;r<this.framerates.length;++r)t+=this.framerates[r];var i=t/this.framerates.length;i=Math.round(i),document.getElementById(this.id).innerHTML="Framerate:"+i+"fps"},Framerate.prototype.snapshot=function(){if(this.renderTime<0)this.renderTime=(new Date).getTime();else{var t=(new Date).getTime(),r=t-this.renderTime;if(0==r)return;var i=1e3/r;for(this.framerates.push(i);this.framerates.length>this.numFramerates;)this.framerates.shift();this.renderTime=t}},J3DIHasCSSMatrix=!1,J3DIHasCSSMatrixCopy=!1,J3DIMatrix4=function(t){if(this.$matrix=J3DIHasCSSMatrix?new WebKitCSSMatrix:new Object,"object"==typeof t){if("length"in t&&t.length>=16)return void this.load(t);if(t instanceof J3DIMatrix4)return void this.load(t)}this.makeIdentity()},J3DIMatrix4.prototype.load=function(){if(1==arguments.length&&"object"==typeof arguments[0]){var t;if(arguments[0]instanceof J3DIMatrix4)return t=arguments[0].$matrix,this.$matrix.m11=t.m11,this.$matrix.m12=t.m12,this.$matrix.m13=t.m13,this.$matrix.m14=t.m14,this.$matrix.m21=t.m21,this.$matrix.m22=t.m22,this.$matrix.m23=t.m23,this.$matrix.m24=t.m24,this.$matrix.m31=t.m31,this.$matrix.m32=t.m32,this.$matrix.m33=t.m33,this.$matrix.m34=t.m34,this.$matrix.m41=t.m41,this.$matrix.m42=t.m42,this.$matrix.m43=t.m43,void(this.$matrix.m44=t.m44);if(t=arguments[0],"length"in t&&t.length>=16)return this.$matrix.m11=t[0],this.$matrix.m12=t[1],this.$matrix.m13=t[2],this.$matrix.m14=t[3],this.$matrix.m21=t[4],this.$matrix.m22=t[5],this.$matrix.m23=t[6],this.$matrix.m24=t[7],this.$matrix.m31=t[8],this.$matrix.m32=t[9],this.$matrix.m33=t[10],this.$matrix.m34=t[11],this.$matrix.m41=t[12],this.$matrix.m42=t[13],this.$matrix.m43=t[14],void(this.$matrix.m44=t[15])}this.makeIdentity()},J3DIMatrix4.prototype.getAsArray=function(){return[this.$matrix.m11,this.$matrix.m12,this.$matrix.m13,this.$matrix.m14,this.$matrix.m21,this.$matrix.m22,this.$matrix.m23,this.$matrix.m24,this.$matrix.m31,this.$matrix.m32,this.$matrix.m33,this.$matrix.m34,this.$matrix.m41,this.$matrix.m42,this.$matrix.m43,this.$matrix.m44]},J3DIMatrix4.prototype.getAsFloat32Array=function(){if(J3DIHasCSSMatrixCopy){var t=new Float32Array(16);return this.$matrix.copy(t),t}return new Float32Array(this.getAsArray())},J3DIMatrix4.prototype.setUniform=function(t,r,i){void 0==J3DIMatrix4.setUniformArray&&(J3DIMatrix4.setUniformWebGLArray=new Float32Array(16),J3DIMatrix4.setUniformArray=new Array(16)),J3DIHasCSSMatrixCopy?this.$matrix.copy(J3DIMatrix4.setUniformWebGLArray):(J3DIMatrix4.setUniformArray[0]=this.$matrix.m11,J3DIMatrix4.setUniformArray[1]=this.$matrix.m12,J3DIMatrix4.setUniformArray[2]=this.$matrix.m13,J3DIMatrix4.setUniformArray[3]=this.$matrix.m14,J3DIMatrix4.setUniformArray[4]=this.$matrix.m21,J3DIMatrix4.setUniformArray[5]=this.$matrix.m22,J3DIMatrix4.setUniformArray[6]=this.$matrix.m23,J3DIMatrix4.setUniformArray[7]=this.$matrix.m24,J3DIMatrix4.setUniformArray[8]=this.$matrix.m31,J3DIMatrix4.setUniformArray[9]=this.$matrix.m32,J3DIMatrix4.setUniformArray[10]=this.$matrix.m33,J3DIMatrix4.setUniformArray[11]=this.$matrix.m34,J3DIMatrix4.setUniformArray[12]=this.$matrix.m41,J3DIMatrix4.setUniformArray[13]=this.$matrix.m42,J3DIMatrix4.setUniformArray[14]=this.$matrix.m43,J3DIMatrix4.setUniformArray[15]=this.$matrix.m44,J3DIMatrix4.setUniformWebGLArray.set(J3DIMatrix4.setUniformArray)),t.uniformMatrix4fv(r,i,J3DIMatrix4.setUniformWebGLArray)},J3DIMatrix4.prototype.makeIdentity=function(){this.$matrix.m11=1,this.$matrix.m12=0,this.$matrix.m13=0,this.$matrix.m14=0,this.$matrix.m21=0,this.$matrix.m22=1,this.$matrix.m23=0,this.$matrix.m24=0,this.$matrix.m31=0,this.$matrix.m32=0,this.$matrix.m33=1,this.$matrix.m34=0,this.$matrix.m41=0,this.$matrix.m42=0,this.$matrix.m43=0,this.$matrix.m44=1},J3DIMatrix4.prototype.transpose=function(){var t=this.$matrix.m12;this.$matrix.m12=this.$matrix.m21,this.$matrix.m21=t,t=this.$matrix.m13,this.$matrix.m13=this.$matrix.m31,this.$matrix.m31=t,t=this.$matrix.m14,this.$matrix.m14=this.$matrix.m41,this.$matrix.m41=t,t=this.$matrix.m23,this.$matrix.m23=this.$matrix.m32,this.$matrix.m32=t,t=this.$matrix.m24,this.$matrix.m24=this.$matrix.m42,this.$matrix.m42=t,t=this.$matrix.m34,this.$matrix.m34=this.$matrix.m43,this.$matrix.m43=t},J3DIMatrix4.prototype.invert=function(){if(J3DIHasCSSMatrix)return void(this.$matrix=this.$matrix.inverse());var t=this._determinant4x4();return Math.abs(t)<1e-8?null:(this._makeAdjoint(),this.$matrix.m11/=t,this.$matrix.m12/=t,this.$matrix.m13/=t,this.$matrix.m14/=t,this.$matrix.m21/=t,this.$matrix.m22/=t,this.$matrix.m23/=t,this.$matrix.m24/=t,this.$matrix.m31/=t,this.$matrix.m32/=t,this.$matrix.m33/=t,this.$matrix.m34/=t,this.$matrix.m41/=t,this.$matrix.m42/=t,this.$matrix.m43/=t,void(this.$matrix.m44/=t))},J3DIMatrix4.prototype.translate=function(t,r,i){if("object"==typeof t&&"length"in t){var e=t;t=e[0],r=e[1],i=e[2]}else void 0==t&&(t=0),void 0==r&&(r=0),void 0==i&&(i=0);if(J3DIHasCSSMatrix)return void(this.$matrix=this.$matrix.translate(t,r,i));var a=new J3DIMatrix4;a.$matrix.m41=t,a.$matrix.m42=r,a.$matrix.m43=i,this.multiply(a)},J3DIMatrix4.prototype.scale=function(t,r,i){if("object"==typeof t&&"length"in t){var e=t;t=e[0],r=e[1],i=e[2]}else void 0==t&&(t=1),void 0==i?void 0==r?(r=t,i=t):i=1:void 0==r&&(r=t);if(J3DIHasCSSMatrix)return void(this.$matrix=this.$matrix.scale(t,r,i));var a=new J3DIMatrix4;a.$matrix.m11=t,a.$matrix.m22=r,a.$matrix.m33=i,this.multiply(a)},J3DIMatrix4.prototype.rotate=function(t,r,i,e){if("object"==typeof r&&"length"in r){var a=r;r=a[0],i=a[1],e=a[2]}else if(1==arguments.length)r=0,i=0,e=1;else if(3==arguments.length)return this.rotate(t,1,0,0),this.rotate(r,0,1,0),void this.rotate(i,0,0,1);if(J3DIHasCSSMatrix)return void(this.$matrix=this.$matrix.rotateAxisAngle(r,i,e,t));t=t/180*Math.PI,t/=2;var m=Math.sin(t),n=Math.cos(t),x=m*m,s=Math.sqrt(r*r+i*i+e*e);0==s?(r=0,i=0,e=1):1!=s&&(r/=s,i/=s,e/=s);var o=new J3DIMatrix4;if(1==r&&0==i&&0==e)o.$matrix.m11=1,o.$matrix.m12=0,o.$matrix.m13=0,o.$matrix.m21=0,o.$matrix.m22=1-2*x,o.$matrix.m23=2*m*n,o.$matrix.m31=0,o.$matrix.m32=-2*m*n,o.$matrix.m33=1-2*x,o.$matrix.m14=o.$matrix.m24=o.$matrix.m34=0,o.$matrix.m41=o.$matrix.m42=o.$matrix.m43=0,o.$matrix.m44=1;else if(0==r&&1==i&&0==e)o.$matrix.m11=1-2*x,o.$matrix.m12=0,o.$matrix.m13=-2*m*n,o.$matrix.m21=0,o.$matrix.m22=1,o.$matrix.m23=0,o.$matrix.m31=2*m*n,o.$matrix.m32=0,o.$matrix.m33=1-2*x,o.$matrix.m14=o.$matrix.m24=o.$matrix.m34=0,o.$matrix.m41=o.$matrix.m42=o.$matrix.m43=0,o.$matrix.m44=1;else if(0==r&&0==i&&1==e)o.$matrix.m11=1-2*x,o.$matrix.m12=2*m*n,o.$matrix.m13=0,o.$matrix.m21=-2*m*n,o.$matrix.m22=1-2*x,o.$matrix.m23=0,o.$matrix.m31=0,o.$matrix.m32=0,o.$matrix.m33=1,o.$matrix.m14=o.$matrix.m24=o.$matrix.m34=0,o.$matrix.m41=o.$matrix.m42=o.$matrix.m43=0,o.$matrix.m44=1;else{var h=r*r,$=i*i,u=e*e;o.$matrix.m11=1-2*($+u)*x,o.$matrix.m12=2*(r*i*x+e*m*n),o.$matrix.m13=2*(r*e*x-i*m*n),o.$matrix.m21=2*(i*r*x-e*m*n),o.$matrix.m22=1-2*(u+h)*x,o.$matrix.m23=2*(i*e*x+r*m*n),o.$matrix.m31=2*(e*r*x+i*m*n),o.$matrix.m32=2*(e*i*x-r*m*n),o.$matrix.m33=1-2*(h+$)*x,o.$matrix.m14=o.$matrix.m24=o.$matrix.m34=0,o.$matrix.m41=o.$matrix.m42=o.$matrix.m43=0,o.$matrix.m44=1}this.multiply(o)},J3DIMatrix4.prototype.multiply=function(t){if(J3DIHasCSSMatrix)return void(this.$matrix=this.$matrix.multiply(t.$matrix));var r=t.$matrix.m11*this.$matrix.m11+t.$matrix.m12*this.$matrix.m21+t.$matrix.m13*this.$matrix.m31+t.$matrix.m14*this.$matrix.m41,i=t.$matrix.m11*this.$matrix.m12+t.$matrix.m12*this.$matrix.m22+t.$matrix.m13*this.$matrix.m32+t.$matrix.m14*this.$matrix.m42,e=t.$matrix.m11*this.$matrix.m13+t.$matrix.m12*this.$matrix.m23+t.$matrix.m13*this.$matrix.m33+t.$matrix.m14*this.$matrix.m43,a=t.$matrix.m11*this.$matrix.m14+t.$matrix.m12*this.$matrix.m24+t.$matrix.m13*this.$matrix.m34+t.$matrix.m14*this.$matrix.m44,m=t.$matrix.m21*this.$matrix.m11+t.$matrix.m22*this.$matrix.m21+t.$matrix.m23*this.$matrix.m31+t.$matrix.m24*this.$matrix.m41,n=t.$matrix.m21*this.$matrix.m12+t.$matrix.m22*this.$matrix.m22+t.$matrix.m23*this.$matrix.m32+t.$matrix.m24*this.$matrix.m42,x=t.$matrix.m21*this.$matrix.m13+t.$matrix.m22*this.$matrix.m23+t.$matrix.m23*this.$matrix.m33+t.$matrix.m24*this.$matrix.m43,s=t.$matrix.m21*this.$matrix.m14+t.$matrix.m22*this.$matrix.m24+t.$matrix.m23*this.$matrix.m34+t.$matrix.m24*this.$matrix.m44,o=t.$matrix.m31*this.$matrix.m11+t.$matrix.m32*this.$matrix.m21+t.$matrix.m33*this.$matrix.m31+t.$matrix.m34*this.$matrix.m41,h=t.$matrix.m31*this.$matrix.m12+t.$matrix.m32*this.$matrix.m22+t.$matrix.m33*this.$matrix.m32+t.$matrix.m34*this.$matrix.m42,$=t.$matrix.m31*this.$matrix.m13+t.$matrix.m32*this.$matrix.m23+t.$matrix.m33*this.$matrix.m33+t.$matrix.m34*this.$matrix.m43,u=t.$matrix.m31*this.$matrix.m14+t.$matrix.m32*this.$matrix.m24+t.$matrix.m33*this.$matrix.m34+t.$matrix.m34*this.$matrix.m44,f=t.$matrix.m41*this.$matrix.m11+t.$matrix.m42*this.$matrix.m21+t.$matrix.m43*this.$matrix.m31+t.$matrix.m44*this.$matrix.m41,l=t.$matrix.m41*this.$matrix.m12+t.$matrix.m42*this.$matrix.m22+t.$matrix.m43*this.$matrix.m32+t.$matrix.m44*this.$matrix.m42,c=t.$matrix.m41*this.$matrix.m13+t.$matrix.m42*this.$matrix.m23+t.$matrix.m43*this.$matrix.m33+t.$matrix.m44*this.$matrix.m43,d=t.$matrix.m41*this.$matrix.m14+t.$matrix.m42*this.$matrix.m24+t.$matrix.m43*this.$matrix.m34+t.$matrix.m44*this.$matrix.m44;this.$matrix.m11=r,this.$matrix.m12=i,this.$matrix.m13=e,this.$matrix.m14=a,this.$matrix.m21=m,this.$matrix.m22=n,this.$matrix.m23=x,this.$matrix.m24=s,this.$matrix.m31=o,this.$matrix.m32=h,this.$matrix.m33=$,this.$matrix.m34=u,this.$matrix.m41=f,this.$matrix.m42=l,this.$matrix.m43=c,this.$matrix.m44=d},J3DIMatrix4.prototype.divide=function(t){this.$matrix.m11/=t,this.$matrix.m12/=t,this.$matrix.m13/=t,this.$matrix.m14/=t,this.$matrix.m21/=t,this.$matrix.m22/=t,this.$matrix.m23/=t,this.$matrix.m24/=t,this.$matrix.m31/=t,this.$matrix.m32/=t,this.$matrix.m33/=t,this.$matrix.m34/=t,this.$matrix.m41/=t,this.$matrix.m42/=t,this.$matrix.m43/=t,this.$matrix.m44/=t},J3DIMatrix4.prototype.ortho=function(t,r,i,e,a,m){var n=(t+r)/(t-r),x=(e+i)/(e-i),s=(m+a)/(m-a),o=new J3DIMatrix4;o.$matrix.m11=2/(t-r),o.$matrix.m12=0,o.$matrix.m13=0,o.$matrix.m14=0,o.$matrix.m21=0,o.$matrix.m22=2/(e-i),o.$matrix.m23=0,o.$matrix.m24=0,o.$matrix.m31=0,o.$matrix.m32=0,o.$matrix.m33=-2/(m-a),o.$matrix.m34=0,o.$matrix.m41=n,o.$matrix.m42=x,o.$matrix.m43=s,o.$matrix.m44=1,this.multiply(o)},J3DIMatrix4.prototype.frustum=function(t,r,i,e,a,m){var n=new J3DIMatrix4,x=(r+t)/(r-t),s=(e+i)/(e-i),o=-(m+a)/(m-a),h=-(2*m*a)/(m-a);n.$matrix.m11=2*a/(r-t),n.$matrix.m12=0,n.$matrix.m13=0,n.$matrix.m14=0,n.$matrix.m21=0,n.$matrix.m22=2*a/(e-i),n.$matrix.m23=0,n.$matrix.m24=0,n.$matrix.m31=x,n.$matrix.m32=s,n.$matrix.m33=o,n.$matrix.m34=-1,n.$matrix.m41=0,n.$matrix.m42=0,n.$matrix.m43=h,n.$matrix.m44=0,this.multiply(n)},J3DIMatrix4.prototype.perspective=function(t,r,i,e){var a=Math.tan(t*Math.PI/360)*i,m=-a,n=r*m,x=r*a;this.frustum(n,x,m,a,i,e)},J3DIMatrix4.prototype.lookat=function(t,r,i,e,a,m,n,x,s){if("object"==typeof i&&"length"in i){var o=i;n=o[0],x=o[1],s=o[2],o=r,e=o[0],a=o[1],m=o[2],o=t,t=o[0],r=o[1],i=o[2]}var h=new J3DIMatrix4,$=t-e,u=r-a,f=i-m,l=Math.sqrt($*$+u*u+f*f);l&&($/=l,u/=l,f/=l);var c=n,d=x,g=s;xx=d*f-g*u,xy=-c*f+g*$,xz=c*u-d*$,c=u*xz-f*xy,d=-$*xz+f*xx,c=$*xy-u*xx,l=Math.sqrt(xx*xx+xy*xy+xz*xz),l&&(xx/=l,xy/=l,xz/=l),l=Math.sqrt(c*c+d*d+g*g),l&&(c/=l,d/=l,g/=l),h.$matrix.m11=xx,h.$matrix.m12=xy,h.$matrix.m13=xz,h.$matrix.m14=0,h.$matrix.m21=c,h.$matrix.m22=d,h.$matrix.m23=g,h.$matrix.m24=0,h.$matrix.m31=$,h.$matrix.m32=u,h.$matrix.m33=f,h.$matrix.m34=0,h.$matrix.m41=0,h.$matrix.m42=0,h.$matrix.m43=0,h.$matrix.m44=1,h.translate(-t,-r,-i),this.multiply(h)},J3DIMatrix4.prototype.decompose=function(t,r,e,a,m){if(0==this.$matrix.m44)return!1;var n,x,s,o,h,n=void 0!=t&&"length"in t?t:new J3DIVector3,x=void 0!=r&&"length"in r?r:new J3DIVector3,s=void 0!=e&&"length"in e?e:new J3DIVector3,o=void 0!=a&&"length"in a?a:new J3DIVector3,h=void 0!=m&&"length"in m?m:new Array(4),$=new J3DIMatrix4(this);$.divide($.$matrix.m44);var u=new J3DIMatrix4($);if(u.$matrix.m14=0,u.$matrix.m24=0,u.$matrix.m34=0,u.$matrix.m44=1,0==u._determinant4x4())return!1;if(0!=$.$matrix.m14||0!=$.$matrix.m24||0!=$.$matrix.m34){var f=[$.$matrix.m14,$.$matrix.m24,$.$matrix.m34,$.$matrix.m44],l=new J3DIMatrix4(u);l.invert();var c=new J3DIMatrix4(l);c.transpose(),c.multVecMatrix(h,f),$.$matrix.m14=$.$matrix.m24=$.$matrix.m34=0,$.$matrix.m44=1}else h[0]=h[1]=h[2]=0,h[3]=1;n[0]=$.$matrix.m41,$.$matrix.m41=0,n[1]=$.$matrix.m42,$.$matrix.m42=0,n[2]=$.$matrix.m43,$.$matrix.m43=0;var d=new J3DIVector3($.$matrix.m11,$.$matrix.m12,$.$matrix.m13),g=new J3DIVector3($.$matrix.m21,$.$matrix.m22,$.$matrix.m23),p=new J3DIVector3($.$matrix.m31,$.$matrix.m32,$.$matrix.m33);s[0]=d.vectorLength(),d.divide(s[0]),o[0]=d.dot(g),g.combine(d,1,-o[0]),s[1]=g.vectorLength(),g.divide(s[1]),o[0]/=s[1],o[1]=g.dot(p),p.combine(d,1,-o[1]),o[2]=g.dot(p),p.combine(g,1,-o[2]),s[2]=p.vectorLength(),p.divide(s[2]),o[1]/=s[2],o[2]/=s[2];var v=new J3DIVector3(g);if(v.cross(p),d.dot(v)<0)for(i=0;3>i;i++)s[i]*=-1,row[0][i]*=-1,row[1][i]*=-1,row[2][i]*=-1;if(x[1]=Math.asin(p[0]),0!=Math.cos(x[1]))x[0]=Math.atan2(-p[1],p[2]),x[2]=Math.atan2(-g[0],d[0]);else{x[2]=0;var A=Math.sin(x[1]);x[0]=0>A?Math.acos((d[2]+g[1])/(1-A))+x[2]:Math.asin((g[2]+d[1])/(A+1))-x[2]}var b=180/Math.PI;return x[0]*=b,x[1]*=b,x[2]*=b,!0},J3DIMatrix4.prototype._determinant2x2=function(t,r,i,e){return t*e-r*i},J3DIMatrix4.prototype._determinant3x3=function(t,r,i,e,a,m,n,x,s){return t*this._determinant2x2(a,m,x,s)-e*this._determinant2x2(r,i,x,s)+n*this._determinant2x2(r,i,a,m)},J3DIMatrix4.prototype._determinant4x4=function(){var t=this.$matrix.m11,r=this.$matrix.m12,i=this.$matrix.m13,e=this.$matrix.m14,a=this.$matrix.m21,m=this.$matrix.m22,n=this.$matrix.m23,x=this.$matrix.m24,s=this.$matrix.m31,o=this.$matrix.m32,h=this.$matrix.m33,$=this.$matrix.m34,u=this.$matrix.m41,f=this.$matrix.m42,l=this.$matrix.m43,c=this.$matrix.m44;return t*this._determinant3x3(m,o,f,n,h,l,x,$,c)-r*this._determinant3x3(a,s,u,n,h,l,x,$,c)+i*this._determinant3x3(a,s,u,m,o,f,x,$,c)-e*this._determinant3x3(a,s,u,m,o,f,n,h,l)},J3DIMatrix4.prototype._makeAdjoint=function(){var t=this.$matrix.m11,r=this.$matrix.m12,i=this.$matrix.m13,e=this.$matrix.m14,a=this.$matrix.m21,m=this.$matrix.m22,n=this.$matrix.m23,x=this.$matrix.m24,s=this.$matrix.m31,o=this.$matrix.m32,h=this.$matrix.m33,$=this.$matrix.m34,u=this.$matrix.m41,f=this.$matrix.m42,l=this.$matrix.m43,c=this.$matrix.m44;this.$matrix.m11=this._determinant3x3(m,o,f,n,h,l,x,$,c),this.$matrix.m21=-this._determinant3x3(a,s,u,n,h,l,x,$,c),this.$matrix.m31=this._determinant3x3(a,s,u,m,o,f,x,$,c),this.$matrix.m41=-this._determinant3x3(a,s,u,m,o,f,n,h,l),this.$matrix.m12=-this._determinant3x3(r,o,f,i,h,l,e,$,c),this.$matrix.m22=this._determinant3x3(t,s,u,i,h,l,e,$,c),this.$matrix.m32=-this._determinant3x3(t,s,u,r,o,f,e,$,c),this.$matrix.m42=this._determinant3x3(t,s,u,r,o,f,i,h,l),this.$matrix.m13=this._determinant3x3(r,m,f,i,n,l,e,x,c),this.$matrix.m23=-this._determinant3x3(t,a,u,i,n,l,e,x,c),this.$matrix.m33=this._determinant3x3(t,a,u,r,m,f,e,x,c),this.$matrix.m43=-this._determinant3x3(t,a,u,r,m,f,i,n,l),this.$matrix.m14=-this._determinant3x3(r,m,o,i,n,h,e,x,$),this.$matrix.m24=this._determinant3x3(t,a,s,i,n,h,e,x,$),this.$matrix.m34=-this._determinant3x3(t,a,s,r,m,o,e,x,$),this.$matrix.m44=this._determinant3x3(t,a,s,r,m,o,i,n,h)},J3DIVector3=function(t,r,i){this.load(t,r,i)},J3DIVector3.prototype.load=function(t,r,i){"object"==typeof t&&"length"in t?(this[0]=t[0],this[1]=t[1],this[2]=t[2]):"number"==typeof t?(this[0]=t,this[1]=r,this[2]=i):(this[0]=0,this[1]=0,this[2]=0)},J3DIVector3.prototype.getAsArray=function(){return[this[0],this[1],this[2]]},J3DIVector3.prototype.getAsFloat32Array=function(){return new Float32Array(this.getAsArray())},J3DIVector3.prototype.vectorLength=function(){return Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2])},J3DIVector3.prototype.divide=function(t){this[0]/=t,this[1]/=t,this[2]/=t},J3DIVector3.prototype.cross=function(t){var r=this[1]*t[2]-this[2]*t[1],i=-this[0]*t[2]+this[2]*t[0];this[2]=this[0]*t[1]-this[1]*t[0],this[0]=r,this[1]=i},J3DIVector3.prototype.dot=function(t){return this[0]*t[0]+this[1]*t[1]+this[2]*t[2]},J3DIVector3.prototype.combine=function(t,r,i){this[0]=r*this[0]+i*t[0],this[1]=r*this[1]+i*t[1],this[2]=r*this[2]+i*t[2]},J3DIVector3.prototype.multVecMatrix=function(t){var r=this[0],i=this[1],e=this[2];this[0]=t.$matrix.m41+r*t.$matrix.m11+i*t.$matrix.m21+e*t.$matrix.m31,this[1]=t.$matrix.m42+r*t.$matrix.m12+i*t.$matrix.m22+e*t.$matrix.m32,this[2]=t.$matrix.m43+r*t.$matrix.m13+i*t.$matrix.m23+e*t.$matrix.m33;
var a=t.$matrix.m44+r*t.$matrix.m14+i*t.$matrix.m24+e*t.$matrix.m34;1!=a&&0!=a&&(this[0]/=a,this[1]/=a,this[2]/=a)},J3DIVector3.prototype.toString=function(){return"["+this[0]+","+this[1]+","+this[2]+"]"};