// GLOW.js r1.1 - http://github.com/empaempa/GLOW var GLOW=function(){function b(a,c,b){this.flags=a;this.callback=c;this.context=b}var a={},c={},f=-1,e=[];b.prototype.dispatch=function(a,c){this.flags===a&&(this.context?this.callback.call(this.context,c):this.callback(c))};a.LOGS=1;a.WARNINGS=2;a.ERRORS=4;a.logFlags=a.ERRORS;a.currentContext={};a.registerContext=function(b){c[b.id]=b;a.enableContext(b)};a.getContextById=function(b){if(c[b])return c[b];GLOW.error("Couldn't find context id "+b+", returning current with id "+a.currentContext.id);return a.currentContext}; a.enableContext=function(c){a.currentContext=typeof c==="string"?getContextById(c):c;GL=a.GL=a.currentContext.GL};a.uniqueId=function(){return++f};a.log=function(c){a.logFlags&a.LOGS&&console.log(c);a.dispatch(a.LOGS,c)};a.warn=function(c){a.logFlags&a.WARNINGS&&console.warn(c);a.dispatch(a.WARNINGS,c)};a.error=function(c){a.logFlags&a.ERRORS&&console.error(c);a.dispatch(a.ERRORS,c)};a.addEventListener=function(a,c,f){e.push(new b(a,c,f));return e[e.length-1]};a.removeEventListener=function(c){c= e.indexOf(c);c!==-1?e.splice(c,1):a.warn("GLOW.removeEventListener: Couldn't find listener object")};a.dispatch=function(a,c){for(var b=e.length;b--;)e[b].dispatch(a,c)};return a}(),GL={}; GLOW.Context=function(){function b(a){a===void 0&&(a={});this.id=a.id!==void 0?a.id:GLOW.uniqueId();this.alpha=a.alpha!==void 0?a.alpha:!0;this.depth=a.depth!==void 0?a.depth:!0;this.antialias=a.antialias!==void 0?a.antialias:!0;this.stencil=a.stencil!==void 0?a.stencil:!1;this.premultipliedAlpha=a.premultipliedAlpha!==void 0?a.premultipliedAlpha:!0;this.preserveDrawingBuffer=a.preserveDrawingBuffer!==void 0?a.preserveDrawingBuffer:!1;this.width=a.width!==void 0?a.width:window.innerWidth;this.height= a.height!==void 0?a.height:window.innerHeight;this.cache=new GLOW.Cache;this.debug=a.debug!==void 0?a.debug:!1;if(a.context)this.GL=a.context,GLOW.registerContext(this);else{try{this.domElement=document.createElement("canvas");if(this.debug&&window.WebGLDebugUtils)this.domElement=WebGLDebugUtils.makeLostContextSimulatingCanvas(this.domElement);this.GL=this.domElement.getContext("experimental-webgl",{alpha:this.alpha,depth:this.depth,antialias:this.antialias,stencil:this.stencil,premultipliedAlpha:this.premultipliedAlpha, preserveDrawingBuffer:this.preserveDrawingBuffer})}catch(c){GLOW.error("GLOW.Context.construct: "+c)}if(this.GL!==null){GLOW.registerContext(this);this.domElement.width=this.width;this.domElement.height=this.height;this.viewport=a.viewport?{x:a.viewport.x!==void 0?a.viewport.x:0,y:a.viewport.y!==void 0?a.viewport.y:0,width:a.viewport.width!==void 0?a.viewport.width:this.width,height:a.viewport.height!==void 0?a.viewport.height:this.height}:{x:0,y:0,width:this.width,height:this.height};if(a.clear){if(this.clearSettings= {r:a.clear.red!==void 0?a.clear.red:0,g:a.clear.green!==void 0?a.clear.green:0,b:a.clear.blue!==void 0?a.clear.blue:0,a:a.clear.alpha!==void 0?a.clear.alpha:1,depth:a.clear.depth!==void 0?a.clear.depth:1,bits:a.clear.bits!==void 0?a.clear.bits:-1},this.clearSettings.bits===-1)this.clearSettings.bits=GL.COLOR_BUFFER_BIT,this.clearSettings.bits|=this.depth?GL.DEPTH_BUFFER_BIT:0,this.clearSettings.bits|=this.stencil?GL.STENCIL_BUFFER_BIT:0}else this.clearSettings={r:0,g:0,b:0,a:1,depth:1,bits:0},this.clearSettings.bits= GL.COLOR_BUFFER_BIT,this.clearSettings.bits|=this.depth?GL.DEPTH_BUFFER_BIT:0,this.clearSettings.bits|=this.stencil?GL.STENCIL_BUFFER_BIT:0;this.enableCulling(!0,{frontFace:GL.CCW,cullFace:GL.BACK});this.enableDepthTest(!0,{func:GL.LEQUAL,write:!0,zNear:0,zFar:1});this.enableBlend(!1);this.setViewport();this.clear()}else GLOW.error("GLOW.Context.construct: unable to initialize WebGL")}}b.prototype.setupClear=function(a){if(a!==void 0)this.clearSettings.r=a.red!==void 0?Math.min(1,Math.max(0,a.red)): this.clearSettings.r,this.clearSettings.g=a.green!==void 0?Math.min(1,Math.max(0,a.green)):this.clearSettings.g,this.clearSettings.b=a.blue!==void 0?Math.min(1,Math.max(0,a.blue)):this.clearSettings.b,this.clearSettings.a=a.alpha!==void 0?Math.min(1,Math.max(0,a.alpha)):this.clearSettings.a,this.clearSettings.depth=a.depth!==void 0?Math.min(1,Math.max(0,a.depth)):this.clearSettings.depth,this.clearSettings.bits=a.bits!==void 0?a.bits:this.clearSettings.bits;GL.clearColor(this.clearSettings.r,this.clearSettings.g, this.clearSettings.b,this.clearSettings.a);GL.clearDepth(this.clearSettings.depth);return this};b.prototype.clear=function(a){this.setupClear(a);GL.clear(this.clearSettings.bits);return this};b.prototype.enableBlend=function(a,c){a?(GL.enable(GL.BLEND),c&&this.setupBlend(c)):GL.disable(GL.BLEND);return this};b.prototype.setupBlend=function(a){a.equationRGB?(a.equationAlpha&&GL.blendEquationSeparate(a.equationRGB,a.equationAlpha),a.srcRGB&&GL.blendFuncSeparate(a.srcRGB,a.dstRGB,a.srcAlpha,a.dstAlpha)): (a.equation&&GL.blendEquation(a.equation),a.src&&GL.blendFunc(a.src,a.dst));return this};b.prototype.enableDepthTest=function(a,c){a?(GL.enable(GL.DEPTH_TEST),c&&this.setupDepthTest(c)):GL.disable(GL.DEPTH_TEST);return this};b.prototype.setupDepthTest=function(a){a.func!==void 0&&GL.depthFunc(a.func);a.write!==void 0&&GL.depthMask(a.write);a.zNear!==void 0&&a.zFar!==void 0&&a.zNear<=a.zFar&&GL.depthRange(Math.max(0,Math.min(1,a.zNear)),Math.max(0,Math.min(1,a.zFar)));return this};b.prototype.enablePolygonOffset= function(a,c){a?(GL.enable(GL.POLYGON_OFFSET_FILL),c&&this.setupPolygonOffset(c)):GL.disable(GL.POLYGON_OFFSET_FILL);return this};b.prototype.setupPolygonOffset=function(a){a.factor&&a.units&&GL.polygonOffset(a.factor,a.units)};b.prototype.enableStencilTest=function(a,c){a?(GL.enable(GL.STENCIL_TEST),c&&this.setupStencilTest(c)):GL.disable(GL.STENCIL_TEST);return this};b.prototype.setupStencilTest=function(a){a.func&&a.funcFace?GL.stencilFuncSeparate(a.funcFace,a.func,a.funcRef,a.funcMask):a.func&& GL.stencilFunc(a.func,a.funcRef,a.funcMask);a.mask&&a.maskFace?GL.stencilMaskSeparate(a.maskFace,a.mask):a.mask&&GL.stencilMask(a.mask);a.opFail&&a.opFace?GL.stencilOpSeparate(a.opFace,a.opFail,a.opZfail,a.opZpass):a.opFail&&GL.stencilOp(a.opFail,a.opZfail,a.opZpass);return this};b.prototype.enableCulling=function(a,c){a?(GL.enable(GL.CULL_FACE),c&&this.setupCulling(c)):GL.disable(GL.CULL_FACE);return this};b.prototype.setupCulling=function(a){try{a.frontFace&&GL.frontFace(a.frontFace),a.cullFace&& GL.cullFace(a.cullFace)}catch(c){GLOW.error("GLOW.Context.setupCulling: "+c)}return this};b.prototype.enableScissor=function(a,c){a?(GL.enable(GL.SCISSOR_TEST),c&&this.setupScissor(c)):GL.disable(GL.SCISSOR_TEST);return this};b.prototype.setupScissor=function(a){try{GL.scissor(a.x,a.y,a.width,a.height)}catch(c){GLOW.error("GLOW.Context.setupScissorTest: "+c)}return this};b.prototype.setViewport=function(){this.setupViewport()};b.prototype.setupViewport=function(a){if(a)this.viewport.x=a.x!==void 0? a.x:this.viewport.x,this.viewport.y=a.y!==void 0?a.y:this.viewport.y,this.viewport.width=a.width!==void 0?a.width:this.viewport.width,this.viewport.height=a.height!==void 0?a.height:this.viewport.height;GL.viewport(this.viewport.x,this.viewport.y,this.viewport.width,this.viewport.height);return this};b.prototype.availableExtensions=function(){return GL.getSupportedExtensions()};b.prototype.enableExtension=function(a){for(var c=GL.getSupportedExtensions(),b=0,e=c.length;b255){GLOW.warn("GLOW.Compiler.interleaveAttributes: Stride owerflow, moving attributes to new interleave index. Please check your interleave setup!");l=j.length;for(j[l]=[];h0)for(;l<=k;l++)GL.enableVertexAttribArray(l);else for(l--;l>k;l--)GL.disableVertexAttribArray(l);if(c.active){for(c= h.length;c--;)if(j=h[c],j.interleaved===!1&&b[j.locationNumber]!==j.id)b[j.locationNumber]=j.id,j.bind();for(c=g.length;c--;){h=g[c];k=h.attributes;l=k.length;for(m=!1;l--;){j=k[l];if(b[j.locationNumber]===j.id){m=!0;break}b[j.locationNumber]=j.id}m||h.bind()}for(c=i.length;c--;)if(b=i[c],e[b.locationNumber]!==b.id)e[b.locationNumber]=b.id,b.load()}else{for(c=h.length;c--;)h[c].interleaved===!1&&h[c].bind();for(c=g.length;c--;)g[c].bind();for(c=i.length;c--;)i[c].load()}a.elements.draw()};b.prototype.clone= function(a){return new GLOW.Shader({use:this.compiledData,except:a})};b.prototype.applyUniformData=function(a,c){if(this.compiledData.uniforms[a]!==void 0){this[a]=c;this.compiledData.uniforms[a].data=c;for(var b=this.compiledData.uniformArray.length;b--;)if(this.compiledData.uniformArray[b].name===a){this.compiledData.uniformArray[b].data=c;break}}};b.prototype.dispose=function(a,c,b){var e,h,g;for(e in this.compiledData.uniforms)delete this[e];for(h in this.compiledData.attributes)delete this[h]; for(g in this.compiledData.interleavedAttributes)delete this[g];delete this.program;delete this.elements;delete this.uniforms;delete this.attributes;delete this.interleavedAttributes;this.compiledData.dispose(a,c,b);delete this.compiledData};return b}(); GLOW.Elements=function(){function b(a,c,b,e){this.id=GLOW.uniqueId();this.type=c!==void 0?c:GL.TRIANGLES;this.offset=e!==void 0?e:0;typeof a==="number"||a===void 0?this.length=a:(a instanceof Uint16Array||(a=new Uint16Array(a)),this.length=a.length,this.elements=GL.createBuffer(),GL.bindBuffer(GL.ELEMENT_ARRAY_BUFFER,this.elements),GL.bufferData(GL.ELEMENT_ARRAY_BUFFER,a,b?b:GL.STATIC_DRAW))}b.prototype.draw=function(){this.elements!==void 0?(GLOW.currentContext.cache.elementsCached(this)||GL.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, this.elements),GL.drawElements(this.type,this.length,GL.UNSIGNED_SHORT,this.offset)):GL.drawArrays(this.type,this.offset,this.length)};b.prototype.clone=function(a){a=a||{};return new GLOW.Elements(a.data||this.data,a.type||this.type,a.usage,a.offset||this.offset)};b.prototype.dispose=function(){this.elements!==void 0&&(GL.deleteBuffer(this.elements),delete this.elements)};return b}(); GLOW.Uniform=function(){function b(){f[GL.INT]=function(){GL.uniform1iv(this.location,this.getNativeValue())};f[GL.FLOAT]=function(){GL.uniform1fv(this.location,this.getNativeValue())};f[GL.INT_VEC2]=function(){GL.uniform2iv(this.location,this.getNativeValue())};f[GL.INT_VEC3]=function(){GL.uniform3iv(this.location,this.getNativeValue())};f[GL.INT_VEC4]=function(){GL.uniform4iv(this.location,this.getNativeValue())};f[GL.BOOL]=function(){GL.uniform1iv(this.location,this.getNativeValue())};f[GL.BOOL_VEC2]= function(){GL.uniform2iv(this.location,this.getNativeValue())};f[GL.BOOL_VEC3]=function(){GL.uniform3iv(this.location,this.getNativeValue())};f[GL.BOOL_VEC4]=function(){GL.uniform4iv(this.location,this.getNativeValue())};f[GL.FLOAT_VEC2]=function(){GL.uniform2fv(this.location,this.getNativeValue())};f[GL.FLOAT_VEC3]=function(){GL.uniform3fv(this.location,this.getNativeValue())};f[GL.FLOAT_VEC4]=function(){GL.uniform4fv(this.location,this.getNativeValue())};f[GL.FLOAT_MAT2]=function(){GL.uniformMatrix2fv(this.location, !1,this.getNativeValue())};f[GL.FLOAT_MAT3]=function(){GL.uniformMatrix3fv(this.location,!1,this.getNativeValue())};f[GL.FLOAT_MAT4]=function(){GL.uniformMatrix4fv(this.location,!1,this.getNativeValue())};f[GL.SAMPLER_2D]=function(){this.data.texture!==void 0&&this.textureUnit!==-1&&!GLOW.currentContext.cache.textureCached(this.textureUnit,this.data)&&(GL.uniform1i(this.location,this.textureUnit),GL.activeTexture(GL.TEXTURE0+this.textureUnit),GL.bindTexture(GL.TEXTURE_2D,this.data.texture),this.data.autoUpdate&& this.data.updateTexture(this.data.autoUpdate))};f[GL.SAMPLER_CUBE]=function(){this.data.texture!==void 0&&this.textureUnit!==-1&&!GLOW.currentContext.cache.textureCached(this.textureUnit,this.data)&&(GL.uniform1i(this.location,this.textureUnit),GL.activeTexture(GL.TEXTURE0+this.textureUnit),GL.bindTexture(GL.TEXTURE_CUBE_MAP,this.data.texture),this.data.autoUpdate&&this.data.updateTexture(this.data.autoUpdate))}}function a(a,h){c||(c=!0,b());this.id=GLOW.uniqueId();this.data=h;this.name=a.name;this.length= a.length;this.type=a.type;this.location=a.location;this.locationNumber=a.locationNumber;this.textureUnit=a.textureUnit!==void 0?a.textureUnit:-1;this.load=a.loadFunction||f[this.type]}var c=!1,f=[];a.prototype.getNativeValue=function(){return this.data.value};a.prototype.clone=function(a){return new GLOW.Uniform(this,a||this.data)};a.prototype.dispose=function(a){this.data!==void 0&&this.type===GL.SAMPLER_2D&&a&&this.data.dispose();delete this.data;delete this.load;delete this.location};return a}(); GLOW.Attribute=function(){function b(b,e,h,g){a||(a=!0,c[GL.INT]=1,c[GL.INT_VEC2]=2,c[GL.INT_VEC3]=3,c[GL.INT_VEC4]=4,c[GL.BOOL]=1,c[GL.BOOL_VEC2]=2,c[GL.BOOL_VEC3]=3,c[GL.BOOL_VEC4]=4,c[GL.FLOAT]=1,c[GL.FLOAT_VEC2]=2,c[GL.FLOAT_VEC3]=3,c[GL.FLOAT_VEC4]=4,c[GL.FLOAT_MAT2]=4,c[GL.FLOAT_MAT3]=9,c[GL.FLOAT_MAT4]=16);this.id=GLOW.uniqueId();this.data=e;this.location=b.location;this.locationNumber=b.locationNumber;this.offset=this.stride=0;this.usage=h!==void 0?h:GL.STATIC_DRAW;this.interleaved=g!==void 0? g:!1;this.size=c[b.type];this.name=b.name;this.type=b.type;this.data&&(this.data.length/this.size>65536&&GLOW.warn("GLOW.Attribute.constructor: Unreachable attribute? Please activate GL.drawArrays or split into multiple shaders. Indexed elements cannot reach attribute data beyond 65535."),this.interleaved===!1&&this.bufferData(this.data,this.usage))}var a=!1,c=[];b.prototype.setupInterleave=function(a,b){this.interleaved=!0;this.offset=a;this.stride=b};b.prototype.bufferData=function(a,b){if(a!== void 0&&this.data!==a)this.data=a;if(b!==void 0&&this.usage!==b)this.usage=b;if(this.buffer===void 0)this.buffer=GL.createBuffer();if(this.data.constructor.toString().indexOf(" Array()")!==-1)this.data=new Float32Array(this.data);GL.bindBuffer(GL.ARRAY_BUFFER,this.buffer);GL.bufferData(GL.ARRAY_BUFFER,this.data,this.usage)};b.prototype.bufferSubData=function(a,b){b===void 0&&(b=0);this.buffer===void 0&&GLOW.error("GLOWAttribute.prototype.bufferSubData: call bufferData first");a.constructor.toString().indexOf(" Array()")!== -1&&(a=new Float32Array(a));GL.bindBuffer(GL.ARRAY_BUFFER,this.buffer);GL.bufferSubData(GL.ARRAY_BUFFER,b,a)};b.prototype.bind=function(){this.interleaved===!1&&GL.bindBuffer(GL.ARRAY_BUFFER,this.buffer);GL.vertexAttribPointer(this.location,this.size,GL.FLOAT,!1,this.stride,this.offset)};b.prototype.clone=function(a){if(this.interleaved)GLOW.error("GLOW.Attribute.clone: Cannot clone interleaved attribute. Please check your interleave setup.");else return a=a||{},new GLOW.Attribute(this,a.data||this.data, a.usage||this.usage,a.interleaved||this.interleaved)};b.prototype.dispose=function(){this.buffer&&(GL.deleteBuffer(this.buffer),delete this.buffer);delete this.data};return b}(); GLOW.InterleavedAttributes=function(){function b(a){this.id=GLOW.uniqueId();this.attributes=a;var b,f=a[0].data.length/a[0].size,e,h=a.length,g,i,j,k=[],l,m=[];for(e=0;e0?this.multiplyScalar(1/a):this.set(0,0,0);return this};b.prototype.setPositionFromMatrix=function(a){a=a.value;this.value[0]=a[12];this.value[1]=a[13];this.value[2]=a[14]};b.prototype.setLength=function(a){return this.normalize().multiplyScalar(a)};b.prototype.isZero=function(){return Math.abs(this.value[0])< 1.0E-4&&Math.abs(this.value[1])<1.0E-4&&Math.abs(this.value[2])<1.0E-4};b.prototype.clone=function(){return new GLOW.Vector3(this.value[0],this.value[1],this.value[2])};return b}(); GLOW.Vector4=function(){function b(a,b,f,e){this.value=new Float32Array(4);this.value[0]=a!==void 0?a:0;this.value[1]=b!==void 0?b:0;this.value[2]=f!==void 0?f:0;this.value[3]=e!==void 0?e:0}b.prototype.set=function(a,b,f,e){this.value[0]=a;this.value[1]=b;this.value[2]=f;this.value[3]=e;return this};b.prototype.copy=function(a){this.value[0]=a.value[0];this.value[1]=a.value[1];this.value[2]=a.value[2];this.value[3]=a.value[3];return this};b.prototype.add=function(a,b){this.value[0]=a.value[0]+b.value[0]; this.value[1]=a.value[1]+b.value[1];this.value[2]=a.value[2]+b.value[2];this.value[3]=a.value[3]+b.value[3];return this};b.prototype.addSelf=function(a){this.value[0]+=a.value[0];this.value[1]+=a.value[1];this.value[2]+=a.value[2];this.value[3]+=a.value[3];return this};b.prototype.sub=function(a,b){this.value[0]=a.value[0]-b.value[0];this.value[1]=a.value[1]-b.value[1];this.value[2]=a.value[2]-b.value[2];this.value[3]=a.value[3]-b.value[3];return this};b.prototype.subSelf=function(a){this.value[0]-= a.value[0];this.value[1]-=a.value[1];this.value[2]-=a.value[2];this.value[3]-=a.value[3];return this};b.prototype.multiplyScalar=function(a){this.value[0]*=a;this.value[1]*=a;this.value[2]*=a;this.value[3]*=a;return this};b.prototype.divideScalar=function(a){this.value[0]/=a;this.value[1]/=a;this.value[2]/=a;this.value[3]/=a;return this};b.prototype.normalize=function(){var a=Math.sqrt(this.value[0]*this.value[0]+this.value[1]*this.value[1]+this.value[2]*this.value[2]+this.value[3]*this.value[3]); a>0?this.multiplyScalar(1/a):this.set(0,0,0,1);return this};b.prototype.lerpSelf=function(a,b){this.value[0]+=(a.x-this.value[0])*b;this.value[1]+=(a.y-this.value[1])*b;this.value[2]+=(a.z-this.value[2])*b;this.value[3]+=(a.w-this.value[3])*b;return this};b.prototype.lengthOfXYZ=function(){return Math.sqrt(this.value[0]*this.value[0]+this.value[1]*this.value[1]+this.value[2]*this.value[2])};b.prototype.clone=function(){return new GLOW.Vector4(this.value[0],this.value[1],this.value[2],this.value[3])}; return b}(); GLOW.Quaternion=function(){function b(a,b,f,e){this.value=new Float32Array(4);this.value[0]=a!==void 0?a:0;this.value[1]=b!==void 0?b:0;this.value[2]=f!==void 0?f:0;this.value[3]=e!==void 0?e:0}b.prototype.set=function(a,b,f,e){this.value[0]=a;this.value[1]=b;this.value[2]=f;this.value[3]=e;return this};b.prototype.copy=function(a){this.value[0]=a.value[0];this.value[1]=a.value[1];this.value[2]=a.value[2];this.value[3]=a.value[3];return this};b.prototype.add=function(a,b){this.value[0]=a.value[0]+ b.value[0];this.value[1]=a.value[1]+b.value[1];this.value[2]=a.value[2]+b.value[2];this.value[3]=a.value[3]+b.value[3];return this};b.prototype.addSelf=function(a){this.value[0]+=a.value[0];this.value[1]+=a.value[1];this.value[2]+=a.value[2];this.value[3]+=a.value[3];return this};b.prototype.sub=function(a,b){this.value[0]=a.value[0]-b.value[0];this.value[1]=a.value[1]-b.value[1];this.value[2]=a.value[2]-b.value[2];this.value[3]=a.value[3]-b.value[3];return this};b.prototype.subSelf=function(a){this.value[0]-= a.value[0];this.value[1]-=a.value[1];this.value[2]-=a.value[2];this.value[3]-=a.value[3];return this};b.prototype.multiplyScalar=function(a){this.value[0]*=a;this.value[1]*=a;this.value[2]*=a;this.value[3]*=a;return this};b.prototype.divideScalar=function(a){this.value[0]/=a;this.value[1]/=a;this.value[2]/=a;this.value[3]/=a;return this};b.prototype.normalize=function(){var a=Math.sqrt(this.value[0]*this.value[0]+this.value[1]*this.value[1]+this.value[2]*this.value[2]+this.value[3]*this.value[3]); a>0?this.multiplyScalar(1/a):this.set(0,0,0,1);return this};b.prototype.lerpSelf=function(a,b){this.value[0]+=(a.x-this.value[0])*b;this.value[1]+=(a.y-this.value[1])*b;this.value[2]+=(a.z-this.value[2])*b;this.value[3]+=(a.w-this.value[3])*b;return this};b.prototype.clone=function(){return new GLOW.Quaternion(this.value[0],this.value[1],this.value[2],this.value[3])};return b}(); GLOW.Matrix3=function(){function b(){this.value=new Float32Array(9);this.identity()}b.prototype.set=function(a,b,f,e,h,g,i,j,k){this.value[0]=a;this.value[3]=b;this.value[6]=f;this.value[1]=e;this.value[4]=h;this.value[7]=g;this.value[2]=i;this.value[5]=j;this.value[8]=k;return this};b.prototype.identity=function(){this.set(1,0,0,0,1,0,0,0,1);return this};b.prototype.extractFromMatrix4=function(a){this.set(a.value[0],a.value[4],a.value[8],a.value[1],a.value[5],a.value[9],a.value[2],a.value[6],a.value[10]); return this};b.prototype.multiplyVector3=function(a){var b=a.value[0],f=a.value[1],e=a.value[2];a.value[0]=this.value[0]*b+this.value[3]*f+this.value[6]*e;a.value[1]=this.value[1]*b+this.value[4]*f+this.value[7]*e;a.value[2]=this.value[2]*b+this.value[5]*f+this.value[8]*e;return a};b.prototype.scale=function(a,b,f){var e;b!==void 0&&f!==void 0?e=a:(e=a.value[0],b=a.value[1],f=a.value[2]);this.value[0]*=e;this.value[3]*=b;this.value[6]*=f;this.value[1]*=e;this.value[4]*=b;this.value[7]*=f;this.value[2]*= e;this.value[5]*=b;this.value[8]*=f;return this};return b}(); GLOW.Matrix4=function(){function b(){this.value=new Float32Array(16);this.rotation=new GLOW.Vector3;this.position=new GLOW.Vector3;this.columnX=new GLOW.Vector3;this.columnY=new GLOW.Vector3;this.columnZ=new GLOW.Vector3;this.identity()}b.prototype.set=function(a,b,f,e,h,g,i,j,k,l,m,n,o,p,r,q){this.value[0]=a;this.value[4]=b;this.value[8]=f;this.value[12]=e;this.value[1]=h;this.value[5]=g;this.value[9]=i;this.value[13]=j;this.value[2]=k;this.value[6]=l;this.value[10]=m;this.value[14]=n;this.value[3]= o;this.value[7]=p;this.value[11]=r;this.value[15]=q;return this};b.prototype.identity=function(){this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);return this};b.prototype.copy=function(a){a=a.value;this.set(a[0],a[4],a[8],a[12],a[1],a[5],a[9],a[13],a[2],a[6],a[10],a[14],a[3],a[7],a[11],a[15]);return this};b.prototype.lookAt=function(a,b){var f=GLOW.Matrix4.tempVector3A,e=GLOW.Matrix4.tempVector3B,h=GLOW.Matrix4.tempVector3C,g=this.getPosition();g.value[0]=this.value[12];g.value[1]=this.value[13];g.value[2]= this.value[14];h.sub(g,a).normalize();h.length()===0&&(h.value[3]=1);f.cross(b,h).normalize();f.length()===0&&(h.value[0]+=1.0E-4,f.cross(b,h).normalize());e.cross(h,f).normalize();f=f.value;e=e.value;h=h.value;this.value[0]=f[0];this.value[4]=e[0];this.value[8]=h[0];this.value[1]=f[1];this.value[5]=e[1];this.value[9]=h[1];this.value[2]=f[2];this.value[6]=e[2];this.value[10]=h[2];return this};b.prototype.multiplyVector3=function(a){var b=a.value[0],f=a.value[1],e=a.value[2],h=1/(this.value[3]*b+this.value[7]* f+this.value[11]*e+this.value[15]);a.value[0]=(this.value[0]*b+this.value[4]*f+this.value[8]*e+this.value[12])*h;a.value[1]=(this.value[1]*b+this.value[5]*f+this.value[9]*e+this.value[13])*h;a.value[2]=(this.value[2]*b+this.value[6]*f+this.value[10]*e+this.value[14])*h;return a};b.prototype.multiplyVector4=function(a){var b=a.value[0],f=a.value[1],e=a.value[2],h=a.value[3];a.value[0]=this.value[0]*b+this.value[4]*f+this.value[8]*e+this.value[12]*h;a.value[1]=this.value[1]*b+this.value[5]*f+this.value[9]* e+this.value[13]*h;a.value[2]=this.value[2]*b+this.value[6]*f+this.value[10]*e+this.value[14]*h;a.value[3]=this.value[3]*b+this.value[7]*f+this.value[11]*e+this.value[15]*h;return a};b.prototype.rotateAxis=function(a){var b=a.value[0],f=a.value[1],e=a.value[2];a.value[0]=b*this.value[0]+f*this.value[4]+e*this.value[8];a.value[1]=b*this.value[1]+f*this.value[5]+e*this.value[9];a.value[2]=b*this.value[2]+f*this.value[6]+e*this.value[10];a.normalize();return a};b.prototype.crossVector=function(a){var b= GLOW.Vector4(),f=a.value[0],e=a.value[1],h=a.value[2],a=a.value[3];b.value[0]=this.value[0]*f+this.value[4]*e+this.value[8]*h+this.value[12]*a;b.value[1]=this.value[1]*f+this.value[5]*e+this.value[9]*h+this.value[13]*a;b.value[2]=this.value[2]*f+this.value[6]*e+this.value[10]*h+this.value[14]*a;b.value[3]=a?this.value[3]*f+this.value[7]*e+this.value[11]*h+this.value[15]*a:1;return b};b.prototype.multiply=function(a,b){var a=a.value,b=b.value,f=a[0],e=a[4],h=a[8],g=a[12],i=a[1],j=a[5],k=a[9],l=a[13], m=a[2],n=a[6],o=a[10],p=a[14],r=a[3],q=a[7],s=a[11],t=a[15],w=b[0],u=b[4],v=b[8],y=b[12],x=b[1],z=b[5],A=b[9],B=b[13],C=b[2],D=b[6],E=b[10],F=b[14];this.value[0]=f*w+e*x+h*C;this.value[4]=f*u+e*z+h*D;this.value[8]=f*v+e*A+h*E;this.value[12]=f*y+e*B+h*F+g;this.value[1]=i*w+j*x+k*C;this.value[5]=i*u+j*z+k*D;this.value[9]=i*v+j*A+k*E;this.value[13]=i*y+j*B+k*F+l;this.value[2]=m*w+n*x+o*C;this.value[6]=m*u+n*z+o*D;this.value[10]=m*v+n*A+o*E;this.value[14]=m*y+n*B+o*F+p;this.value[3]=r*w+q*x+s*C;this.value[7]= r*u+q*z+s*D;this.value[11]=r*v+q*A+s*E;this.value[15]=r*y+q*B+s*F+t;return this};b.prototype.multiplySelf=function(a){this.multiply(this,a);return this};b.prototype.multiplyScalar=function(a){this.value[0]*=a;this.value[4]*=a;this.value[8]*=a;this.value[12]*=a;this.value[1]*=a;this.value[5]*=a;this.value[9]*=a;this.value[13]*=a;this.value[2]*=a;this.value[6]*=a;this.value[10]*=a;this.value[14]*=a;this.value[3]*=a;this.value[7]*=a;this.value[11]*=a;this.value[15]*=a;return this};b.prototype.determinant= function(){var a=this.value[0],b=this.value[4],f=this.value[8],e=this.value[12],h=this.value[1],g=this.value[5],i=this.value[9],j=this.value[13],k=this.value[2],l=this.value[6],m=this.value[10],n=this.value[14],o=this.value[3],p=this.value[7],r=this.value[11],q=this.value[15];return e*i*l*o-f*j*l*o-e*g*m*o+b*j*m*o+f*g*n*o-b*i*n*o-e*i*k*p+f*j*k*p+e*h*m*p-a*j*m*p-f*h*n*p+a*i*n*p+e*g*k*r-b*j*k*r-e*h*l*r+a*j*l*r+b*h*n*r-a*g*n*r-f*g*k*q+b*i*k*q+f*h*l*q-a*i*l*q-b*h*m*q+a*g*m*q};b.prototype.transpose=function(){var a; a=this.value[1];this.value[1]=this.value[4];this.value[4]=a;a=this.value[2];this.value[2]=this.value[8];this.value[8]=a;a=this.value[6];this.value[6]=this.value[9];this.value[9]=a;a=this.value[3];this.value[3]=this.value[12];this.value[12]=a;a=this.value[7];this.value[7]=this.value[13];this.value[13]=a;a=this.value[11];this.value[11]=this.value[14];this.value[11]=a;return this};b.prototype.clone=function(){var a=new GLOW.Matrix4;a.value=new Float32Array(this.value);return a};b.prototype.setPosition= function(a,b,f){var e;b!==void 0&&f!==void 0?e=a:(e=a.value[0],b=a.value[1],f=a.value[2]);this.value[12]=e;this.value[13]=b;this.value[14]=f;return this};b.prototype.addPosition=function(a,b,f){var e;b!==void 0&&f!==void 0?e=a:(e=a.value[0],b=a.value[1],f=a.value[2]);this.value[12]+=e;this.value[13]+=b;this.value[14]+=f};b.prototype.setRotation=function(a,b,f){var e;b!==void 0&&f!==void 0?e=a:(e=a.value[0],b=a.value[1],f=a.value[2]);var a=Math.cos(b),b=Math.sin(b),h=Math.cos(f),f=Math.sin(f),g=Math.cos(e); e=Math.sin(e);this.value[0]=a*h;this.value[4]=b*e-a*f*g;this.value[8]=a*f*e+b*g;this.value[1]=f;this.value[5]=h*g;this.value[9]=-h*e;this.value[2]=-b*h;this.value[6]=b*f*g+a*e;this.value[10]=-b*f*e+a*g;return this};b.prototype.getRotation=function(){var a=this.value,b=this.rotation.value;if(a[1]>0.998)return b[0]=0,b[1]=Math.atan2(a[8],a[10]),b[2]=Math.PI/2,this.rotation;else if(a[1]<-0.998)return b[0]=0,b[1]=Math.atan2(a[8],a[10]),b[2]=-Math.PI/2,this.rotation;b[0]=Math.atan2(-a[9],a[5]);b[1]=Math.atan2(-a[2], a[0]);b[2]=Math.asin(a[1]);return this.rotation};b.prototype.addRotation=function(a,b,f){var e;b!==void 0&&f!==void 0?e=a:(e=a.value[0],b=a.value[1],f=a.value[2]);this.rotation.value[0]+=e;this.rotation.value[1]+=b;this.rotation.value[2]+=f;this.setRotation(this.rotation.value[0],this.rotation.value[1],this.rotation.value[2])};b.prototype.setQuaternion=function(a){var b=this.value,f=a.value,a=f[0],e=f[1],h=f[2],f=f[3],g=a*a,i=e*e,j=h*h;b[0]=1-2*i-2*j;b[1]=2*a*e-2*h*f;b[2]=2*a*h+2*e*f;b[4]=2*a*e+2* h*f;b[5]=1-2*g-2*j;b[6]=2*e*h-2*a*f;b[8]=2*a*h-2*e*f;b[9]=2*e*h+2*a*f;b[10]=1-2*g-2*i;return this};b.prototype.getPosition=function(){this.position.set(this.value[12],this.value[13],this.value[14]);return this.position};b.prototype.getColumnX=function(){this.columnX.set(this.value[0],this.value[1],this.value[2]);return this.columnX};b.prototype.getColumnY=function(){this.columnY.set(this.value[4],this.value[5],this.value[6]);return this.columnY};b.prototype.getColumnZ=function(){this.columnZ.set(this.value[8], this.value[9],this.value[10]);return this.columnZ};b.prototype.scale=function(a,b,f){var e;b!==void 0&&f!==void 0?e=a:(e=a.value[0],b=a.value[1],f=a.value[2]);this.value[0]*=e;this.value[4]*=b;this.value[8]*=f;this.value[1]*=e;this.value[5]*=b;this.value[9]*=f;this.value[2]*=e;this.value[6]*=b;this.value[10]*=f;this.value[3]*=e;this.value[7]*=b;this.value[11]*=f;return this};b.prototype.invert=function(){GLOW.Matrix4.makeInverse(this,this);return this};return b}(); GLOW.Matrix4.makeInverse=function(b,a){a===void 0&&(a=new GLOW.Matrix4);var c=b.value,f=a.value,e=c[0],h=c[4],g=c[8],i=c[12],j=c[1],k=c[5],l=c[9],m=c[13],n=c[2],o=c[6],p=c[10],r=c[14],q=c[3],s=c[7],t=c[11],c=c[15];f[0]=l*r*s-m*p*s+m*o*t-k*r*t-l*o*c+k*p*c;f[1]=m*p*q-l*r*q-m*n*t+j*r*t+l*n*c-j*p*c;f[2]=k*r*q-m*o*q+m*n*s-j*r*s-k*n*c+j*o*c;f[3]=l*o*q-k*p*q-l*n*s+j*p*s+k*n*t-j*o*t;f[4]=i*p*s-g*r*s-i*o*t+h*r*t+g*o*c-h*p*c;f[5]=g*r*q-i*p*q+i*n*t-e*r*t-g*n*c+e*p*c;f[6]=i*o*q-h*r*q-i*n*s+e*r*s+h*n*c-e*o*c; f[7]=h*p*q-g*o*q+g*n*s-e*p*s-h*n*t+e*o*t;f[8]=g*m*s-i*l*s+i*k*t-h*m*t-g*k*c+h*l*c;f[9]=i*l*q-g*m*q-i*j*t+e*m*t+g*j*c-e*l*c;f[10]=g*m*q-i*k*q+i*j*s-e*m*s-h*j*c+e*k*c;f[11]=g*k*q-h*l*q-g*j*s+e*l*s+h*j*t-e*k*t;f[12]=i*l*o-g*m*o-i*k*p+h*m*p+g*k*r-h*l*r;f[13]=g*m*n-i*l*n+i*j*p-e*m*p-g*j*r+e*l*r;f[14]=i*k*n-h*m*n-i*j*o+e*m*o+h*j*r-e*k*r;f[15]=h*l*n-g*k*n+g*j*o-e*l*o-h*j*p+e*k*p;a.multiplyScalar(1/b.determinant());return a}; GLOW.Matrix4.makeFrustum=function(b,a,c,f,e,h,g){var i,g=g||new GLOW.Matrix4;i=g.value;i[0]=2*e/(a-b);i[4]=0;i[8]=(a+b)/(a-b);i[12]=0;i[1]=0;i[5]=2*e/(f-c);i[9]=(f+c)/(f-c);i[13]=0;i[2]=0;i[6]=0;i[10]=-(h+e)/(h-e);i[14]=-2*h*e/(h-e);i[3]=0;i[7]=0;i[11]=-1;i[15]=0;return g};GLOW.Matrix4.makeProjection=function(b,a,c,f,e){var h,b=c*Math.tan(b*Math.PI/360);h=-b;return GLOW.Matrix4.makeFrustum(h*a,b*a,h,b,c,f,e)}; GLOW.Matrix4.makeOrtho=function(b,a,c,f,e,h,g){var i,j,k,l,g=g||new GLOW.Matrix4;j=Math.abs(a-b);k=Math.abs(c-f);l=Math.abs(h-e);i=g.value;i[0]=2/j;i[4]=0;i[8]=0;i[12]=-((a+b)/j);i[1]=0;i[5]=2/k;i[9]=0;i[13]=-((c+f)/k);i[2]=0;i[6]=0;i[10]=-2/l;i[14]=-((h+e)/l);i[3]=0;i[7]=0;i[11]=0;i[15]=1;return g};GLOW.Matrix4.tempVector3A=new GLOW.Vector3;GLOW.Matrix4.tempVector3B=new GLOW.Vector3;GLOW.Matrix4.tempVector3C=new GLOW.Vector3;GLOW.Matrix4.tempVector3D=new GLOW.Vector3; GLOW.Color=function(){function b(a,b,f){this.value=new Float32Array(3);b===void 0&&f===void 0?this.setHex(a||0):this.setRGB(a,b,f)}b.prototype.setRGB=function(a,b,f){this.value[0]=a!==void 0?a/255:1;this.value[1]=b!==void 0?b/255:1;this.value[2]=f!==void 0?f/255:1;return this};b.prototype.setHex=function(a){this.value[0]=((a&16711680)>>16)/255;this.value[1]=((a&65280)>>8)/255;this.value[2]=(a&255)/255;return this};b.prototype.multiplyScalar=function(a){this.value[0]*=a;this.value[1]*=a;this.value[2]*= a;return this};b.prototype.mix=function(a,b){var f=1-b;this.value[0]=this.value[0]*f+a.value[0]*b;this.value[1]=this.value[1]*f+a.value[1]*b;this.value[2]=this.value[2]*f+a.value[2]*b;return this};b.prototype.copy=function(a){this.value[0]=a.value[0];this.value[1]=a.value[1];this.value[2]=a.value[2];return this};b.prototype.setHSV=function(a,b,f){var e,h,g,i,j,k;if(f==0)e=h=g=0;else switch(i=Math.floor(a*6),j=a*6-i,a=f*(1-b),k=f*(1-b*j),b=f*(1-b*(1-j)),i){case 1:e=k;h=f;g=a;break;case 2:e=a;h=f;g= b;break;case 3:e=a;h=k;g=f;break;case 4:e=b;h=a;g=f;break;case 5:e=f;h=a;g=k;break;case 6:case 0:e=f,h=b,g=a}this.value[0]=e;this.value[1]=h;this.value[2]=g;return this};return b}(); GLOW.Geometry={randomVector3Array:function(b,a){var a=a!==void 0?a:1,c,f=[],e=a*2;for(c=0;c-1)f[h].indexOf("Fragment")>-1&&(b=e, e="");else{var g=f[h];g.indexOf("//")>-1&&(g=g.substring(0,g.indexOf("//")));g.indexOf(";")===-1&&(g+="\n");e+=g}f=e;a===""&&(typeof GL==="object"&&typeof GL.getShaderPrecisionFormat==="function"?(e=GL.getShaderPrecisionFormat(GL.FRAGMENT_SHADER,GL.HIGH_FLOAT),a=e.rangeMax>=62&&e.rangeMin>=62&&e.precision>=16?"precision highp float;":"precision mediump float;"):a="#ifdef GL_FRAGMENT_PRECISION_HIGH\n#if GL_FRAGMENT_PRECISION_HIGH == 1\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n#else\nprecision mediump float;\n#endif"); this.scope.parameters[this.parametersProperty]={fragmentShader:a+"\n"+f,vertexShader:b};this.scope.handleLoadedItem()}};b.prototype.onLoadError=function(a){GLOW.error("GLOW.Load.onLoadError: Error "+a.target.status)};b.prototype.parseThreeJS=function(a){var b={},e=a.scale!==void 0?1/a.scale:1;(function(e){if(a.version===void 0||a.version!=2)GLOW.error("Deprecated file format.");else{var g,i,j,k,l,m,n,o,p,r,q,s,t,w,u=a.faces;m=a.vertices;var v=a.normals,y=a.colors,x=0;for(g=0;g65533){o-=3; break}c[j]=j++;c[j]=j++;c[j]=j++;for(k in a){i=e[k];size=a[k];for(n=0;n<3;n++){l=0;for(m=size;l