Browse Source

Small optimizations: skipped flattening in 3x3 matrix inversion and uploading camera position uniform only for materials where it's used.

alteredq 14 years ago
parent
commit
56fcd26ef3
5 changed files with 127 additions and 118 deletions
  1. 35 35
      build/Three.js
  2. 35 35
      build/ThreeDebug.js
  3. 35 35
      build/ThreeExtras.js
  4. 11 12
      src/core/Matrix4.js
  5. 11 1
      src/renderers/WebGLRenderer.js

+ 35 - 35
build/Three.js

@@ -38,7 +38,7 @@ m=i*j,p=i*b;this.set(m*j+e,m*b-g*s,m*s+g*b,0,m*b+g*s,p*b+e,p*s-g*j,0,m*s-g*b,p*s
 THREE.Matrix4.scaleMatrix=function(a,c,e){var g=new THREE.Matrix4;g.setScale(a,c,e);return g};THREE.Matrix4.rotationXMatrix=function(a){var c=new THREE.Matrix4;c.setRotX(a);return c};THREE.Matrix4.rotationYMatrix=function(a){var c=new THREE.Matrix4;c.setRotY(a);return c};THREE.Matrix4.rotationZMatrix=function(a){var c=new THREE.Matrix4;c.setRotZ(a);return c};THREE.Matrix4.rotationAxisAngleMatrix=function(a,c){var e=new THREE.Matrix4;e.setRotAxis(a,c);return e};
 THREE.Matrix4.makeInvert=function(a){var c=a.n11,e=a.n12,g=a.n13,i=a.n14,j=a.n21,b=a.n22,s=a.n23,m=a.n24,p=a.n31,q=a.n32,z=a.n33,w=a.n34,y=a.n41,F=a.n42,K=a.n43,L=a.n44,d=new THREE.Matrix4;d.n11=s*w*F-m*z*F+m*q*K-b*w*K-s*q*L+b*z*L;d.n12=i*z*F-g*w*F-i*q*K+e*w*K+g*q*L-e*z*L;d.n13=g*m*F-i*s*F+i*b*K-e*m*K-g*b*L+e*s*L;d.n14=i*s*q-g*m*q-i*b*z+e*m*z+g*b*w-e*s*w;d.n21=m*z*y-s*w*y-m*p*K+j*w*K+s*p*L-j*z*L;d.n22=g*w*y-i*z*y+i*p*K-c*w*K-g*p*L+c*z*L;d.n23=i*s*y-g*m*y-i*j*K+c*m*K+g*j*L-c*s*L;d.n24=g*m*p-i*s*p+
 i*j*z-c*m*z-g*j*w+c*s*w;d.n31=b*w*y-m*q*y+m*p*F-j*w*F-b*p*L+j*q*L;d.n32=i*q*y-e*w*y-i*p*F+c*w*F+e*p*L-c*q*L;d.n33=g*m*y-i*b*y+i*j*F-c*m*F-e*j*L+c*b*L;d.n34=i*b*p-e*m*p-i*j*q+c*m*q+e*j*w-c*b*w;d.n41=s*q*y-b*z*y-s*p*F+j*z*F+b*p*K-j*q*K;d.n42=e*z*y-g*q*y+g*p*F-c*z*F-e*p*K+c*q*K;d.n43=g*b*y-e*s*y-g*j*F+c*s*F+e*j*K-c*b*K;d.n44=e*s*p-g*b*p+g*j*q-c*s*q-e*j*z+c*b*z;d.multiplyScalar(1/a.determinant());return d};
-THREE.Matrix4.makeInvert3x3=function(a){var c=a.flatten();a=a.m33;var e=a.m,g=c[10]*c[5]-c[6]*c[9],i=-c[10]*c[1]+c[2]*c[9],j=c[6]*c[1]-c[2]*c[5],b=-c[10]*c[4]+c[6]*c[8],s=c[10]*c[0]-c[2]*c[8],m=-c[6]*c[0]+c[2]*c[4],p=c[9]*c[4]-c[5]*c[8],q=-c[9]*c[0]+c[1]*c[8],z=c[5]*c[0]-c[1]*c[4];c=c[0]*g+c[1]*b+c[2]*p;if(c==0)throw"matrix not invertible";c=1/c;e[0]=c*g;e[1]=c*i;e[2]=c*j;e[3]=c*b;e[4]=c*s;e[5]=c*m;e[6]=c*p;e[7]=c*q;e[8]=c*z;return a};
+THREE.Matrix4.makeInvert3x3=function(a){var c=a.m33,e=c.m,g=a.n33*a.n22-a.n32*a.n23,i=-a.n33*a.n21+a.n31*a.n23,j=a.n32*a.n21-a.n31*a.n22,b=-a.n33*a.n12+a.n32*a.n13,s=a.n33*a.n11-a.n31*a.n13,m=-a.n32*a.n11+a.n31*a.n12,p=a.n23*a.n12-a.n22*a.n13,q=-a.n23*a.n11+a.n21*a.n13,z=a.n22*a.n11-a.n21*a.n12;a=a.n11*g+a.n21*b+a.n31*p;if(a==0)throw"matrix not invertible";a=1/a;e[0]=a*g;e[1]=a*i;e[2]=a*j;e[3]=a*b;e[4]=a*s;e[5]=a*m;e[6]=a*p;e[7]=a*q;e[8]=a*z;return c};
 THREE.Matrix4.makeFrustum=function(a,c,e,g,i,j){var b,s,m;b=new THREE.Matrix4;s=2*i/(c-a);m=2*i/(g-e);a=(c+a)/(c-a);e=(g+e)/(g-e);g=-(j+i)/(j-i);i=-2*j*i/(j-i);b.n11=s;b.n12=0;b.n13=a;b.n14=0;b.n21=0;b.n22=m;b.n23=e;b.n24=0;b.n31=0;b.n32=0;b.n33=g;b.n34=i;b.n41=0;b.n42=0;b.n43=-1;b.n44=0;return b};THREE.Matrix4.makePerspective=function(a,c,e,g){var i;a=e*Math.tan(a*Math.PI/360);i=-a;return THREE.Matrix4.makeFrustum(i*c,a*c,i,a,e,g)};
 THREE.Matrix4.makeOrtho=function(a,c,e,g,i,j){var b,s,m,p;b=new THREE.Matrix4;s=c-a;m=e-g;p=j-i;a=(c+a)/s;e=(e+g)/m;i=(j+i)/p;b.n11=2/s;b.n12=0;b.n13=0;b.n14=-a;b.n21=0;b.n22=2/m;b.n23=0;b.n24=-e;b.n31=0;b.n32=0;b.n33=-2/p;b.n34=-i;b.n41=0;b.n42=0;b.n43=0;b.n44=1;return b};THREE.Matrix4.__tmpVec1=new THREE.Vector3;THREE.Matrix4.__tmpVec2=new THREE.Vector3;THREE.Matrix4.__tmpVec3=new THREE.Vector3;
 THREE.Vertex=function(a,c){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=c||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.tangent=new THREE.Vector4;this.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}};
@@ -176,40 +176,40 @@ c(d,THREE.ShaderLib.particle_basic);var l,t,o,r;k=o=r=0;for(l=n.length;k<l;k++){
 l.maxDirLights,"#define MAX_POINT_LIGHTS "+l.maxPointLights,l.fog?"#define USE_FOG":"",l.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",l.map?"#define USE_MAP":"",l.env_map?"#define USE_ENVMAP":"",l.light_map?"#define USE_LIGHTMAP":"",l.vertex_colors?"#define USE_COLOR":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");l=[b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+l.maxDirLights,"#define MAX_POINT_LIGHTS "+
 l.maxPointLights,l.map?"#define USE_MAP":"",l.env_map?"#define USE_ENVMAP":"",l.light_map?"#define USE_LIGHTMAP":"",l.vertex_colors?"#define USE_COLOR":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec3 color;\nattribute vec2 uv;\nattribute vec2 uv2;\n"].join("\n");b.attachShader(h,g("fragment",k+r));b.attachShader(h,
 g("vertex",l+n));b.linkProgram(h);b.getProgramParameter(h,b.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+b.getProgramParameter(h,b.VALIDATE_STATUS)+", gl error ["+b.getError()+"]");h.uniforms={};h.attributes={};d.program=h;h=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(f in d.uniforms)h.push(f);f=d.program;r=0;for(n=h.length;r<n;r++){k=h[r];f.uniforms[k]=b.getUniformLocation(f,k)}d=d.program;f=["position","normal",
-"uv","uv2","tangent","color"];h=0;for(r=f.length;h<r;h++){n=f[h];d.attributes[n]=b.getAttribLocation(d,n)}}};this.setProgram=function(d,n,h,f,k){this.initMaterial(f,n,h);var l=f.program;if(l!=s){b.useProgram(l);s=l}this.loadCamera(l,d);this.loadMatrices(l,k);if(f instanceof THREE.MeshPhongMaterial||f instanceof THREE.MeshLambertMaterial){this.setupLights(l,n);n=this.lights;f.uniforms.enableLighting.value=n.directional.length+n.point.length;f.uniforms.ambientLightColor.value=n.ambient;f.uniforms.directionalLightColor.value=
-n.directional.colors;f.uniforms.directionalLightDirection.value=n.directional.positions;f.uniforms.pointLightColor.value=n.point.colors;f.uniforms.pointLightPosition.value=n.point.positions}if(f instanceof THREE.MeshBasicMaterial||f instanceof THREE.MeshLambertMaterial||f instanceof THREE.MeshPhongMaterial){f.uniforms.diffuse.value.setRGB(f.color.r*f.opacity,f.color.g*f.opacity,f.color.b*f.opacity);f.uniforms.opacity.value=f.opacity;f.uniforms.map.texture=f.map;f.uniforms.light_map.texture=f.light_map;
-f.uniforms.env_map.texture=f.env_map;f.uniforms.reflectivity.value=f.reflectivity;f.uniforms.refraction_ratio.value=f.refraction_ratio;f.uniforms.combine.value=f.combine;f.uniforms.useRefract.value=f.env_map&&f.env_map.mapping instanceof THREE.CubeRefractionMapping;if(h){f.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){f.uniforms.fogNear.value=h.near;f.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)f.uniforms.fogDensity.value=h.density}}if(f instanceof THREE.LineBasicMaterial){f.uniforms.diffuse.value.setRGB(f.color.r*
-f.opacity,f.color.g*f.opacity,f.color.b*f.opacity);f.uniforms.opacity.value=f.opacity;if(h){f.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){f.uniforms.fogNear.value=h.near;f.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)f.uniforms.fogDensity.value=h.density}}if(f instanceof THREE.ParticleBasicMaterial){f.uniforms.psColor.value.setRGB(f.color.r*f.opacity,f.color.g*f.opacity,f.color.b*f.opacity);f.uniforms.opacity.value=f.opacity;f.uniforms.size.value=f.size;
-f.uniforms.map.texture=f.map;if(h){f.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){f.uniforms.fogNear.value=h.near;f.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)f.uniforms.fogDensity.value=h.density}}if(f instanceof THREE.MeshPhongMaterial){f.uniforms.ambient.value.setRGB(f.ambient.r,f.ambient.g,f.ambient.b);f.uniforms.specular.value.setRGB(f.specular.r,f.specular.g,f.specular.b);f.uniforms.shininess.value=f.shininess}if(f instanceof THREE.MeshDepthMaterial){f.uniforms.mNear.value=
-d.near;f.uniforms.mFar.value=d.far;f.uniforms.opacity.value=f.opacity}if(f instanceof THREE.MeshNormalMaterial)f.uniforms.opacity.value=f.opacity;d=f.uniforms;for(var t in d)if(k=l.uniforms[t]){f=d[t];n=f.type;h=f.value;if(n=="i")b.uniform1i(k,h);else if(n=="f")b.uniform1f(k,h);else if(n=="fv1")b.uniform1fv(k,h);else if(n=="fv")b.uniform3fv(k,h);else if(n=="v2")b.uniform2f(k,h.x,h.y);else if(n=="v3")b.uniform3f(k,h.x,h.y,h.z);else if(n=="c")b.uniform3f(k,h.r,h.g,h.b);else if(n=="t"){b.uniform1i(k,
-h);if(f=f.texture)if(f.image instanceof Array&&f.image.length==6){f=f;h=h;if(f.image.length==6){if(!f.image.__webGLTextureCube&&!f.image.__cubeMapInitialized&&f.image.loadCount==6){f.image.__webGLTextureCube=b.createTexture();b.bindTexture(b.TEXTURE_CUBE_MAP,f.image.__webGLTextureCube);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_MAG_FILTER,b.LINEAR);b.texParameteri(b.TEXTURE_CUBE_MAP,
-b.TEXTURE_MIN_FILTER,b.LINEAR_MIPMAP_LINEAR);for(n=0;n<6;++n)b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X+n,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,f.image[n]);b.generateMipmap(b.TEXTURE_CUBE_MAP);b.bindTexture(b.TEXTURE_CUBE_MAP,null);f.image.__cubeMapInitialized=true}b.activeTexture(b.TEXTURE0+h);b.bindTexture(b.TEXTURE_CUBE_MAP,f.image.__webGLTextureCube)}}else{f=f;h=h;if(!f.__webGLTexture&&f.image.loaded){f.__webGLTexture=b.createTexture();b.bindTexture(b.TEXTURE_2D,f.__webGLTexture);b.texImage2D(b.TEXTURE_2D,
-0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,f.image);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,i(f.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,i(f.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,i(f.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,i(f.min_filter));b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}b.activeTexture(b.TEXTURE0+h);b.bindTexture(b.TEXTURE_2D,f.__webGLTexture)}}}return l};this.renderBuffer=function(d,n,h,f,k,l){d=this.setProgram(d,
-n,h,f,l).attributes;b.bindBuffer(b.ARRAY_BUFFER,k.__webGLVertexBuffer);b.vertexAttribPointer(d.position,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.position);if(d.color>=0){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLColorBuffer);b.vertexAttribPointer(d.color,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.color)}if(d.normal>=0){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLNormalBuffer);b.vertexAttribPointer(d.normal,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.normal)}if(d.tangent>=0){b.bindBuffer(b.ARRAY_BUFFER,
-k.__webGLTangentBuffer);b.vertexAttribPointer(d.tangent,4,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.tangent)}if(d.uv>=0)if(k.__webGLUVBuffer){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLUVBuffer);b.vertexAttribPointer(d.uv,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.uv)}else b.disableVertexAttribArray(d.uv);if(d.uv2>=0)if(k.__webGLUV2Buffer){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLUV2Buffer);b.vertexAttribPointer(d.uv2,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.uv2)}else b.disableVertexAttribArray(d.uv2);
-if(l instanceof THREE.Mesh)if(f.wireframe){b.lineWidth(f.wireframe_linewidth);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,k.__webGLLineBuffer);b.drawElements(b.LINES,k.__webGLLineCount,b.UNSIGNED_SHORT,0)}else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,k.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,k.__webGLFaceCount,b.UNSIGNED_SHORT,0)}else if(l instanceof THREE.Line){l=l.type==THREE.LineStrip?b.LINE_STRIP:b.LINES;b.lineWidth(f.linewidth);b.drawArrays(l,0,k.__webGLLineCount)}else l instanceof THREE.ParticleSystem&&
-b.drawArrays(b.POINTS,0,k.__webGLParticleCount)};this.renderPass=function(d,n,h,f,k,l,t){var o,r,v,x,u;v=0;for(x=f.materials.length;v<x;v++){o=f.materials[v];if(o instanceof THREE.MeshFaceMaterial){o=0;for(r=k.materials.length;o<r;o++)if((u=k.materials[o])&&u.blending==l&&u.opacity<1==t){this.setBlending(u.blending);this.setDepthTest(u.depth_test);this.renderBuffer(d,n,h,u,k,f)}}else if((u=o)&&u.blending==l&&u.opacity<1==t){this.setBlending(u.blending);this.setDepthTest(u.depth_test);this.renderBuffer(d,
-n,h,u,k,f)}}};this.renderPassImmediate=function(d,n,h,f,k,l){var t,o,r,v;t=0;for(o=f.materials.length;t<o;t++)if((r=f.materials[t])&&r.blending==k&&r.opacity<1==l){this.setBlending(r.blending);this.setDepthTest(r.depth_test);v=this.setProgram(d,n,h,r,f);f.render(function(x){var u=v;if(!x.__webGLVertexBuffer)x.__webGLVertexBuffer=b.createBuffer();if(!x.__webGLNormalBuffer)x.__webGLNormalBuffer=b.createBuffer();if(x.hasPos){b.bindBuffer(b.ARRAY_BUFFER,x.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,
-x.positionArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(u.attributes.position);b.vertexAttribPointer(u.attributes.position,3,b.FLOAT,false,0,0)}if(x.hasNormal){b.bindBuffer(b.ARRAY_BUFFER,x.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,x.normalArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(u.attributes.normal);b.vertexAttribPointer(u.attributes.normal,3,b.FLOAT,false,0,0)}b.drawArrays(b.TRIANGLES,0,x.count);x.count=0})}};this.render=function(d,n,h,f){var k,l,t,o,r=d.lights,v=d.fog;n.autoUpdateMatrix&&
-n.updateMatrix();n.matrix.flattenToArray(w);n.projectionMatrix.flattenToArray(z);q.multiply(n.projectionMatrix,n.matrix);p[0].set(q.n41-q.n11,q.n42-q.n12,q.n43-q.n13,q.n44-q.n14);p[1].set(q.n41+q.n11,q.n42+q.n12,q.n43+q.n13,q.n44+q.n14);p[2].set(q.n41+q.n21,q.n42+q.n22,q.n43+q.n23,q.n44+q.n24);p[3].set(q.n41-q.n21,q.n42-q.n22,q.n43-q.n23,q.n44-q.n24);p[4].set(q.n41-q.n31,q.n42-q.n32,q.n43-q.n33,q.n44-q.n34);p[5].set(q.n41+q.n31,q.n42+q.n32,q.n43+q.n33,q.n44+q.n34);for(k=0;k<5;k++){o=p[k];o.divideScalar(Math.sqrt(o.x*
-o.x+o.y*o.y+o.z*o.z))}this.initWebGLObjects(d,n);f=f!==undefined?f:true;if(h&&!h.__webGLFramebuffer){h.__webGLFramebuffer=b.createFramebuffer();h.__webGLRenderbuffer=b.createRenderbuffer();h.__webGLTexture=b.createTexture();b.bindRenderbuffer(b.RENDERBUFFER,h.__webGLRenderbuffer);b.renderbufferStorage(b.RENDERBUFFER,b.DEPTH_COMPONENT16,h.width,h.height);b.bindTexture(b.TEXTURE_2D,h.__webGLTexture);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,i(h.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,
-i(h.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,i(h.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,i(h.min_filter));b.texImage2D(b.TEXTURE_2D,0,i(h.format),h.width,h.height,0,i(h.format),i(h.type),null);b.bindFramebuffer(b.FRAMEBUFFER,h.__webGLFramebuffer);b.framebufferTexture2D(b.FRAMEBUFFER,b.COLOR_ATTACHMENT0,b.TEXTURE_2D,h.__webGLTexture,0);b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,h.__webGLRenderbuffer);b.bindTexture(b.TEXTURE_2D,
-null);b.bindRenderbuffer(b.RENDERBUFFER,null);b.bindFramebuffer(b.FRAMEBUFFER,null)}if(h){k=h.__webGLFramebuffer;o=h.width;t=h.height}else{k=null;o=j.width;t=j.height}if(k!=m){b.bindFramebuffer(b.FRAMEBUFFER,k);b.viewport(0,0,o,t);f&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);m=k}this.autoClear&&this.clear();k=d.__webGLObjects.length;for(f=0;f<k;f++){t=d.__webGLObjects[f];o=t.object;if(l=o.visible){if(!(l=!(o instanceof THREE.Mesh)))a:{l=void 0;for(var x=o.matrix,u=-o.geometry.boundingSphere.radius*
-Math.max(o.scale.x,Math.max(o.scale.y,o.scale.z)),A=0;A<6;A++){l=p[A].x*x.n14+p[A].y*x.n24+p[A].z*x.n34+p[A].w;if(l<=u){l=false;break a}}l=true}l=l}if(l){if(o.autoUpdateMatrix){o.updateMatrix();o.matrix.flattenToArray(o._objectMatrixArray)}this.setupMatrices(o,n);t.render=true}else t.render=false}l=d.__webGLObjectsImmediate.length;for(f=0;f<l;f++){o=d.__webGLObjectsImmediate[f].object;if(o.visible){if(o.autoUpdateMatrix){o.updateMatrix();o.matrix.flattenToArray(o._objectMatrixArray)}this.setupMatrices(o,
-n)}}for(f=0;f<k;f++){t=d.__webGLObjects[f];if(t.render){o=t.object;t=t.buffer;e(o);this.renderPass(n,r,v,o,t,THREE.NormalBlending,false)}}for(f=0;f<l;f++){o=d.__webGLObjectsImmediate[f].object;if(o.visible){e(o);this.renderPassImmediate(n,r,v,o,THREE.NormalBlending,false)}}for(f=0;f<k;f++){t=d.__webGLObjects[f];if(t.render){o=t.object;t=t.buffer;e(o);this.renderPass(n,r,v,o,t,THREE.AdditiveBlending,false);this.renderPass(n,r,v,o,t,THREE.SubtractiveBlending,false);this.renderPass(n,r,v,o,t,THREE.AdditiveBlending,
-true);this.renderPass(n,r,v,o,t,THREE.SubtractiveBlending,true);this.renderPass(n,r,v,o,t,THREE.NormalBlending,true);this.renderPass(n,r,v,o,t,THREE.BillboardBlending,false)}}for(f=0;f<l;f++){o=d.__webGLObjectsImmediate[f].object;if(o.visible){e(o);this.renderPassImmediate(n,r,v,o,THREE.NormalBlending,true)}}if(h&&h.min_filter!==THREE.NearestFilter&&h.min_filter!==THREE.LinearFilter){b.bindTexture(b.TEXTURE_2D,h.__webGLTexture);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}};this.initWebGLObjects=
-function(d,n){function h(u,A,B,N){if(u[A]==undefined){d.__webGLObjects.push({buffer:B,object:N});u[A]=1}}function f(u,A,B){if(u[A]==undefined){d.__webGLObjectsImmediate.push({object:B});u[A]=1}}var k,l,t,o,r,v,x;if(!d.__webGLObjects){d.__webGLObjects=[];d.__webGLObjectsMap={};d.__webGLObjectsImmediate=[]}k=0;for(l=d.objects.length;k<l;k++){t=d.objects[k];r=t.geometry;if(d.__webGLObjectsMap[t.id]==undefined){d.__webGLObjectsMap[t.id]={};t._modelViewMatrix=new THREE.Matrix4;t._normalMatrixArray=new Float32Array(9);
-t._modelViewMatrixArray=new Float32Array(16);t._objectMatrixArray=new Float32Array(16);t.matrix.flattenToArray(t._objectMatrixArray)}x=d.__webGLObjectsMap[t.id];if(t instanceof THREE.Mesh){for(o in r.geometryChunks){v=r.geometryChunks[o];if(!v.__webGLVertexBuffer){this.createMeshBuffers(v);this.initMeshBuffers(v,t);r.__dirtyVertices=true;r.__dirtyElements=true;r.__dirtyUvs=true;r.__dirtyNormals=true;r.__dirtyTangents=true;r.__dirtyColors=true}if(r.__dirtyVertices||r.__dirtyElements||r.__dirtyUvs||
-r.__dirtyNormals||r.__dirtyColors||r.__dirtyTangents)this.setMeshBuffers(v,t,b.DYNAMIC_DRAW);h(x,o,v,t)}r.__dirtyVertices=false;r.__dirtyElements=false;r.__dirtyUvs=false;r.__dirtyNormals=false;r.__dirtyTangents=false;r.__dirtyColors=false}else if(t instanceof THREE.Line){if(!r.__webGLVertexBuffer){this.createLineBuffers(r);this.initLineBuffers(r);r.__dirtyVertices=true;r.__dirtyColors=true}if(r.__dirtyVertices||r.__dirtyColors)this.setLineBuffers(r,b.DYNAMIC_DRAW);h(x,0,r,t);r.__dirtyVertices=false;
-r.__dirtyColors=false}else if(t instanceof THREE.ParticleSystem){if(!r.__webGLVertexBuffer){this.createParticleBuffers(r);this.initParticleBuffers(r);r.__dirtyVertices=true;r.__dirtyColors=true}if(r.__dirtyVertices||r.__dirtyColors||t.sortParticles)this.setParticleBuffers(r,b.DYNAMIC_DRAW,t,n);h(x,0,r,t);r.__dirtyVertices=false;r.__dirtyColors=false}else t instanceof THREE.MarchingCubes&&f(x,0,t)}};this.removeObject=function(d,n){var h,f;for(h=d.__webGLObjects.length-1;h>=0;h--){f=d.__webGLObjects[h].object;
-n==f&&d.__webGLObjects.splice(h,1)}};this.setupMatrices=function(d,n){d._modelViewMatrix.multiplyToArray(n.matrix,d.matrix,d._modelViewMatrixArray);d._normalMatrix=THREE.Matrix4.makeInvert3x3(d._modelViewMatrix).transposeIntoArray(d._normalMatrixArray)};this.loadMatrices=function(d,n){b.uniformMatrix4fv(d.uniforms.viewMatrix,false,w);b.uniformMatrix4fv(d.uniforms.projectionMatrix,false,z);b.uniformMatrix4fv(d.uniforms.modelViewMatrix,false,n._modelViewMatrixArray);b.uniformMatrix3fv(d.uniforms.normalMatrix,
-false,n._normalMatrixArray);b.uniformMatrix4fv(d.uniforms.objectMatrix,false,n._objectMatrixArray)};this.loadCamera=function(d,n){b.uniform3f(d.uniforms.cameraPosition,n.position.x,n.position.y,n.position.z)};this.setDepthTest=function(d){d?b.enable(b.DEPTH_TEST):b.disable(b.DEPTH_TEST)};this.setBlending=function(d){switch(d){case THREE.AdditiveBlending:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE);break;case THREE.SubtractiveBlending:b.blendFunc(b.DST_COLOR,b.ZERO);break;case THREE.BillboardBlending:b.blendEquation(b.FUNC_ADD);
-b.blendFunc(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA);break;default:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(d,n){if(d){!n||n=="ccw"?b.frontFace(b.CCW):b.frontFace(b.CW);if(d=="back")b.cullFace(b.BACK);else d=="front"?b.cullFace(b.FRONT):b.cullFace(b.FRONT_AND_BACK);b.enable(b.CULL_FACE)}else b.disable(b.CULL_FACE)};this.supportsVertexTextures=function(){return b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}};
-THREE.Snippets={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );\n#endif",
-envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube env_map;\nuniform int combine;\n#endif",envmap_fragment:"#ifdef USE_ENVMAP\nvec4 cubeColor = textureCube( env_map, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = vec4( mix( gl_FragColor.xyz, cubeColor.xyz, reflectivity ), opacity );\n} else {\ngl_FragColor = gl_FragColor * cubeColor;\n}\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refraction_ratio;\nuniform bool useRefract;\n#endif",
-envmap_vertex:"#ifdef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nif ( useRefract ) {\nvReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refraction_ratio );\n} else {\nvReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );\n}\n#endif",map_particle_pars_fragment:"#ifdef USE_MAP\nuniform sampler2D map;\n#endif",
-map_particle_fragment:"#ifdef USE_MAP\ngl_FragColor = gl_FragColor * texture2D( map, gl_PointCoord );\n#endif",map_pars_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\n#endif",map_fragment:"#ifdef USE_MAP\ngl_FragColor = gl_FragColor * texture2D( map, vUv );\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv;\n#endif",lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\nvarying vec2 vUv2;\nuniform sampler2D light_map;\n#endif",lightmap_pars_vertex:"#ifdef USE_LIGHTMAP\nvarying vec2 vUv2;\n#endif",
-lightmap_fragment:"#ifdef USE_LIGHTMAP\ngl_FragColor = gl_FragColor * texture2D( light_map, vUv2 );\n#endif",lightmap_vertex:"#ifdef USE_LIGHTMAP\nvUv2 = uv2;\n#endif",lights_pars_vertex:"uniform bool enableLighting;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n#ifdef PHONG\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\n#endif",
+"uv","uv2","tangent","color"];h=0;for(r=f.length;h<r;h++){n=f[h];d.attributes[n]=b.getAttribLocation(d,n)}}};this.setProgram=function(d,n,h,f,k){this.initMaterial(f,n,h);var l=f.program;if(l!=s){b.useProgram(l);s=l}if(f instanceof THREE.MeshShaderMaterial||f instanceof THREE.MeshPhongMaterial||f.env_map)this.loadCamera(l,d);this.loadMatrices(l,k);if(f instanceof THREE.MeshPhongMaterial||f instanceof THREE.MeshLambertMaterial){this.setupLights(l,n);n=this.lights;f.uniforms.enableLighting.value=n.directional.length+
+n.point.length;f.uniforms.ambientLightColor.value=n.ambient;f.uniforms.directionalLightColor.value=n.directional.colors;f.uniforms.directionalLightDirection.value=n.directional.positions;f.uniforms.pointLightColor.value=n.point.colors;f.uniforms.pointLightPosition.value=n.point.positions}if(f instanceof THREE.MeshBasicMaterial||f instanceof THREE.MeshLambertMaterial||f instanceof THREE.MeshPhongMaterial){f.uniforms.diffuse.value.setRGB(f.color.r*f.opacity,f.color.g*f.opacity,f.color.b*f.opacity);
+f.uniforms.opacity.value=f.opacity;f.uniforms.map.texture=f.map;f.uniforms.light_map.texture=f.light_map;f.uniforms.env_map.texture=f.env_map;f.uniforms.reflectivity.value=f.reflectivity;f.uniforms.refraction_ratio.value=f.refraction_ratio;f.uniforms.combine.value=f.combine;f.uniforms.useRefract.value=f.env_map&&f.env_map.mapping instanceof THREE.CubeRefractionMapping;if(h){f.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){f.uniforms.fogNear.value=h.near;f.uniforms.fogFar.value=
+h.far}else if(h instanceof THREE.FogExp2)f.uniforms.fogDensity.value=h.density}}if(f instanceof THREE.LineBasicMaterial){f.uniforms.diffuse.value.setRGB(f.color.r*f.opacity,f.color.g*f.opacity,f.color.b*f.opacity);f.uniforms.opacity.value=f.opacity;if(h){f.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){f.uniforms.fogNear.value=h.near;f.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)f.uniforms.fogDensity.value=h.density}}if(f instanceof THREE.ParticleBasicMaterial){f.uniforms.psColor.value.setRGB(f.color.r*
+f.opacity,f.color.g*f.opacity,f.color.b*f.opacity);f.uniforms.opacity.value=f.opacity;f.uniforms.size.value=f.size;f.uniforms.map.texture=f.map;if(h){f.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){f.uniforms.fogNear.value=h.near;f.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)f.uniforms.fogDensity.value=h.density}}if(f instanceof THREE.MeshPhongMaterial){f.uniforms.ambient.value.setRGB(f.ambient.r,f.ambient.g,f.ambient.b);f.uniforms.specular.value.setRGB(f.specular.r,
+f.specular.g,f.specular.b);f.uniforms.shininess.value=f.shininess}if(f instanceof THREE.MeshDepthMaterial){f.uniforms.mNear.value=d.near;f.uniforms.mFar.value=d.far;f.uniforms.opacity.value=f.opacity}if(f instanceof THREE.MeshNormalMaterial)f.uniforms.opacity.value=f.opacity;d=f.uniforms;for(var t in d)if(k=l.uniforms[t]){f=d[t];n=f.type;h=f.value;if(n=="i")b.uniform1i(k,h);else if(n=="f")b.uniform1f(k,h);else if(n=="fv1")b.uniform1fv(k,h);else if(n=="fv")b.uniform3fv(k,h);else if(n=="v2")b.uniform2f(k,
+h.x,h.y);else if(n=="v3")b.uniform3f(k,h.x,h.y,h.z);else if(n=="c")b.uniform3f(k,h.r,h.g,h.b);else if(n=="t"){b.uniform1i(k,h);if(f=f.texture)if(f.image instanceof Array&&f.image.length==6){f=f;h=h;if(f.image.length==6){if(!f.image.__webGLTextureCube&&!f.image.__cubeMapInitialized&&f.image.loadCount==6){f.image.__webGLTextureCube=b.createTexture();b.bindTexture(b.TEXTURE_CUBE_MAP,f.image.__webGLTextureCube);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,
+b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_MAG_FILTER,b.LINEAR);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_MIN_FILTER,b.LINEAR_MIPMAP_LINEAR);for(n=0;n<6;++n)b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X+n,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,f.image[n]);b.generateMipmap(b.TEXTURE_CUBE_MAP);b.bindTexture(b.TEXTURE_CUBE_MAP,null);f.image.__cubeMapInitialized=true}b.activeTexture(b.TEXTURE0+h);b.bindTexture(b.TEXTURE_CUBE_MAP,f.image.__webGLTextureCube)}}else{f=f;h=h;if(!f.__webGLTexture&&
+f.image.loaded){f.__webGLTexture=b.createTexture();b.bindTexture(b.TEXTURE_2D,f.__webGLTexture);b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,f.image);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,i(f.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,i(f.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,i(f.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,i(f.min_filter));b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}b.activeTexture(b.TEXTURE0+
+h);b.bindTexture(b.TEXTURE_2D,f.__webGLTexture)}}}return l};this.renderBuffer=function(d,n,h,f,k,l){d=this.setProgram(d,n,h,f,l).attributes;b.bindBuffer(b.ARRAY_BUFFER,k.__webGLVertexBuffer);b.vertexAttribPointer(d.position,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.position);if(d.color>=0){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLColorBuffer);b.vertexAttribPointer(d.color,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.color)}if(d.normal>=0){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLNormalBuffer);
+b.vertexAttribPointer(d.normal,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.normal)}if(d.tangent>=0){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLTangentBuffer);b.vertexAttribPointer(d.tangent,4,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.tangent)}if(d.uv>=0)if(k.__webGLUVBuffer){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLUVBuffer);b.vertexAttribPointer(d.uv,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.uv)}else b.disableVertexAttribArray(d.uv);if(d.uv2>=0)if(k.__webGLUV2Buffer){b.bindBuffer(b.ARRAY_BUFFER,
+k.__webGLUV2Buffer);b.vertexAttribPointer(d.uv2,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.uv2)}else b.disableVertexAttribArray(d.uv2);if(l instanceof THREE.Mesh)if(f.wireframe){b.lineWidth(f.wireframe_linewidth);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,k.__webGLLineBuffer);b.drawElements(b.LINES,k.__webGLLineCount,b.UNSIGNED_SHORT,0)}else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,k.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,k.__webGLFaceCount,b.UNSIGNED_SHORT,0)}else if(l instanceof THREE.Line){l=
+l.type==THREE.LineStrip?b.LINE_STRIP:b.LINES;b.lineWidth(f.linewidth);b.drawArrays(l,0,k.__webGLLineCount)}else l instanceof THREE.ParticleSystem&&b.drawArrays(b.POINTS,0,k.__webGLParticleCount)};this.renderPass=function(d,n,h,f,k,l,t){var o,r,v,x,u;v=0;for(x=f.materials.length;v<x;v++){o=f.materials[v];if(o instanceof THREE.MeshFaceMaterial){o=0;for(r=k.materials.length;o<r;o++)if((u=k.materials[o])&&u.blending==l&&u.opacity<1==t){this.setBlending(u.blending);this.setDepthTest(u.depth_test);this.renderBuffer(d,
+n,h,u,k,f)}}else if((u=o)&&u.blending==l&&u.opacity<1==t){this.setBlending(u.blending);this.setDepthTest(u.depth_test);this.renderBuffer(d,n,h,u,k,f)}}};this.renderPassImmediate=function(d,n,h,f,k,l){var t,o,r,v;t=0;for(o=f.materials.length;t<o;t++)if((r=f.materials[t])&&r.blending==k&&r.opacity<1==l){this.setBlending(r.blending);this.setDepthTest(r.depth_test);v=this.setProgram(d,n,h,r,f);f.render(function(x){var u=v;if(!x.__webGLVertexBuffer)x.__webGLVertexBuffer=b.createBuffer();if(!x.__webGLNormalBuffer)x.__webGLNormalBuffer=
+b.createBuffer();if(x.hasPos){b.bindBuffer(b.ARRAY_BUFFER,x.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,x.positionArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(u.attributes.position);b.vertexAttribPointer(u.attributes.position,3,b.FLOAT,false,0,0)}if(x.hasNormal){b.bindBuffer(b.ARRAY_BUFFER,x.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,x.normalArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(u.attributes.normal);b.vertexAttribPointer(u.attributes.normal,3,b.FLOAT,false,0,0)}b.drawArrays(b.TRIANGLES,
+0,x.count);x.count=0})}};this.render=function(d,n,h,f){var k,l,t,o,r=d.lights,v=d.fog;n.autoUpdateMatrix&&n.updateMatrix();n.matrix.flattenToArray(w);n.projectionMatrix.flattenToArray(z);q.multiply(n.projectionMatrix,n.matrix);p[0].set(q.n41-q.n11,q.n42-q.n12,q.n43-q.n13,q.n44-q.n14);p[1].set(q.n41+q.n11,q.n42+q.n12,q.n43+q.n13,q.n44+q.n14);p[2].set(q.n41+q.n21,q.n42+q.n22,q.n43+q.n23,q.n44+q.n24);p[3].set(q.n41-q.n21,q.n42-q.n22,q.n43-q.n23,q.n44-q.n24);p[4].set(q.n41-q.n31,q.n42-q.n32,q.n43-q.n33,
+q.n44-q.n34);p[5].set(q.n41+q.n31,q.n42+q.n32,q.n43+q.n33,q.n44+q.n34);for(k=0;k<5;k++){o=p[k];o.divideScalar(Math.sqrt(o.x*o.x+o.y*o.y+o.z*o.z))}this.initWebGLObjects(d,n);f=f!==undefined?f:true;if(h&&!h.__webGLFramebuffer){h.__webGLFramebuffer=b.createFramebuffer();h.__webGLRenderbuffer=b.createRenderbuffer();h.__webGLTexture=b.createTexture();b.bindRenderbuffer(b.RENDERBUFFER,h.__webGLRenderbuffer);b.renderbufferStorage(b.RENDERBUFFER,b.DEPTH_COMPONENT16,h.width,h.height);b.bindTexture(b.TEXTURE_2D,
+h.__webGLTexture);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,i(h.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,i(h.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,i(h.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,i(h.min_filter));b.texImage2D(b.TEXTURE_2D,0,i(h.format),h.width,h.height,0,i(h.format),i(h.type),null);b.bindFramebuffer(b.FRAMEBUFFER,h.__webGLFramebuffer);b.framebufferTexture2D(b.FRAMEBUFFER,b.COLOR_ATTACHMENT0,b.TEXTURE_2D,h.__webGLTexture,0);
+b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,h.__webGLRenderbuffer);b.bindTexture(b.TEXTURE_2D,null);b.bindRenderbuffer(b.RENDERBUFFER,null);b.bindFramebuffer(b.FRAMEBUFFER,null)}if(h){k=h.__webGLFramebuffer;o=h.width;t=h.height}else{k=null;o=j.width;t=j.height}if(k!=m){b.bindFramebuffer(b.FRAMEBUFFER,k);b.viewport(0,0,o,t);f&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);m=k}this.autoClear&&this.clear();k=d.__webGLObjects.length;for(f=0;f<k;f++){t=d.__webGLObjects[f];
+o=t.object;if(l=o.visible){if(!(l=!(o instanceof THREE.Mesh)))a:{l=void 0;for(var x=o.matrix,u=-o.geometry.boundingSphere.radius*Math.max(o.scale.x,Math.max(o.scale.y,o.scale.z)),A=0;A<6;A++){l=p[A].x*x.n14+p[A].y*x.n24+p[A].z*x.n34+p[A].w;if(l<=u){l=false;break a}}l=true}l=l}if(l){if(o.autoUpdateMatrix){o.updateMatrix();o.matrix.flattenToArray(o._objectMatrixArray)}this.setupMatrices(o,n);t.render=true}else t.render=false}l=d.__webGLObjectsImmediate.length;for(f=0;f<l;f++){o=d.__webGLObjectsImmediate[f].object;
+if(o.visible){if(o.autoUpdateMatrix){o.updateMatrix();o.matrix.flattenToArray(o._objectMatrixArray)}this.setupMatrices(o,n)}}for(f=0;f<k;f++){t=d.__webGLObjects[f];if(t.render){o=t.object;t=t.buffer;e(o);this.renderPass(n,r,v,o,t,THREE.NormalBlending,false)}}for(f=0;f<l;f++){o=d.__webGLObjectsImmediate[f].object;if(o.visible){e(o);this.renderPassImmediate(n,r,v,o,THREE.NormalBlending,false)}}for(f=0;f<k;f++){t=d.__webGLObjects[f];if(t.render){o=t.object;t=t.buffer;e(o);this.renderPass(n,r,v,o,t,THREE.AdditiveBlending,
+false);this.renderPass(n,r,v,o,t,THREE.SubtractiveBlending,false);this.renderPass(n,r,v,o,t,THREE.AdditiveBlending,true);this.renderPass(n,r,v,o,t,THREE.SubtractiveBlending,true);this.renderPass(n,r,v,o,t,THREE.NormalBlending,true);this.renderPass(n,r,v,o,t,THREE.BillboardBlending,false)}}for(f=0;f<l;f++){o=d.__webGLObjectsImmediate[f].object;if(o.visible){e(o);this.renderPassImmediate(n,r,v,o,THREE.NormalBlending,true)}}if(h&&h.min_filter!==THREE.NearestFilter&&h.min_filter!==THREE.LinearFilter){b.bindTexture(b.TEXTURE_2D,
+h.__webGLTexture);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}};this.initWebGLObjects=function(d,n){function h(u,A,B,N){if(u[A]==undefined){d.__webGLObjects.push({buffer:B,object:N});u[A]=1}}function f(u,A,B){if(u[A]==undefined){d.__webGLObjectsImmediate.push({object:B});u[A]=1}}var k,l,t,o,r,v,x;if(!d.__webGLObjects){d.__webGLObjects=[];d.__webGLObjectsMap={};d.__webGLObjectsImmediate=[]}k=0;for(l=d.objects.length;k<l;k++){t=d.objects[k];r=t.geometry;if(d.__webGLObjectsMap[t.id]==
+undefined){d.__webGLObjectsMap[t.id]={};t._modelViewMatrix=new THREE.Matrix4;t._normalMatrixArray=new Float32Array(9);t._modelViewMatrixArray=new Float32Array(16);t._objectMatrixArray=new Float32Array(16);t.matrix.flattenToArray(t._objectMatrixArray)}x=d.__webGLObjectsMap[t.id];if(t instanceof THREE.Mesh){for(o in r.geometryChunks){v=r.geometryChunks[o];if(!v.__webGLVertexBuffer){this.createMeshBuffers(v);this.initMeshBuffers(v,t);r.__dirtyVertices=true;r.__dirtyElements=true;r.__dirtyUvs=true;r.__dirtyNormals=
+true;r.__dirtyTangents=true;r.__dirtyColors=true}if(r.__dirtyVertices||r.__dirtyElements||r.__dirtyUvs||r.__dirtyNormals||r.__dirtyColors||r.__dirtyTangents)this.setMeshBuffers(v,t,b.DYNAMIC_DRAW);h(x,o,v,t)}r.__dirtyVertices=false;r.__dirtyElements=false;r.__dirtyUvs=false;r.__dirtyNormals=false;r.__dirtyTangents=false;r.__dirtyColors=false}else if(t instanceof THREE.Line){if(!r.__webGLVertexBuffer){this.createLineBuffers(r);this.initLineBuffers(r);r.__dirtyVertices=true;r.__dirtyColors=true}if(r.__dirtyVertices||
+r.__dirtyColors)this.setLineBuffers(r,b.DYNAMIC_DRAW);h(x,0,r,t);r.__dirtyVertices=false;r.__dirtyColors=false}else if(t instanceof THREE.ParticleSystem){if(!r.__webGLVertexBuffer){this.createParticleBuffers(r);this.initParticleBuffers(r);r.__dirtyVertices=true;r.__dirtyColors=true}if(r.__dirtyVertices||r.__dirtyColors||t.sortParticles)this.setParticleBuffers(r,b.DYNAMIC_DRAW,t,n);h(x,0,r,t);r.__dirtyVertices=false;r.__dirtyColors=false}else t instanceof THREE.MarchingCubes&&f(x,0,t)}};this.removeObject=
+function(d,n){var h,f;for(h=d.__webGLObjects.length-1;h>=0;h--){f=d.__webGLObjects[h].object;n==f&&d.__webGLObjects.splice(h,1)}};this.setupMatrices=function(d,n){d._modelViewMatrix.multiplyToArray(n.matrix,d.matrix,d._modelViewMatrixArray);d._normalMatrix=THREE.Matrix4.makeInvert3x3(d._modelViewMatrix).transposeIntoArray(d._normalMatrixArray)};this.loadMatrices=function(d,n){b.uniformMatrix4fv(d.uniforms.viewMatrix,false,w);b.uniformMatrix4fv(d.uniforms.projectionMatrix,false,z);b.uniformMatrix4fv(d.uniforms.modelViewMatrix,
+false,n._modelViewMatrixArray);b.uniformMatrix3fv(d.uniforms.normalMatrix,false,n._normalMatrixArray);b.uniformMatrix4fv(d.uniforms.objectMatrix,false,n._objectMatrixArray)};this.loadCamera=function(d,n){b.uniform3f(d.uniforms.cameraPosition,n.position.x,n.position.y,n.position.z)};this.setDepthTest=function(d){d?b.enable(b.DEPTH_TEST):b.disable(b.DEPTH_TEST)};this.setBlending=function(d){switch(d){case THREE.AdditiveBlending:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE);break;case THREE.SubtractiveBlending:b.blendFunc(b.DST_COLOR,
+b.ZERO);break;case THREE.BillboardBlending:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA);break;default:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(d,n){if(d){!n||n=="ccw"?b.frontFace(b.CCW):b.frontFace(b.CW);if(d=="back")b.cullFace(b.BACK);else d=="front"?b.cullFace(b.FRONT):b.cullFace(b.FRONT_AND_BACK);b.enable(b.CULL_FACE)}else b.disable(b.CULL_FACE)};this.supportsVertexTextures=function(){return b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>
+0}};
+THREE.Snippets={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );\n#endif",envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube env_map;\nuniform int combine;\n#endif",
+envmap_fragment:"#ifdef USE_ENVMAP\nvec4 cubeColor = textureCube( env_map, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = vec4( mix( gl_FragColor.xyz, cubeColor.xyz, reflectivity ), opacity );\n} else {\ngl_FragColor = gl_FragColor * cubeColor;\n}\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refraction_ratio;\nuniform bool useRefract;\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nif ( useRefract ) {\nvReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refraction_ratio );\n} else {\nvReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );\n}\n#endif",
+map_particle_pars_fragment:"#ifdef USE_MAP\nuniform sampler2D map;\n#endif",map_particle_fragment:"#ifdef USE_MAP\ngl_FragColor = gl_FragColor * texture2D( map, gl_PointCoord );\n#endif",map_pars_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\n#endif",map_fragment:"#ifdef USE_MAP\ngl_FragColor = gl_FragColor * texture2D( map, vUv );\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv;\n#endif",lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\nvarying vec2 vUv2;\nuniform sampler2D light_map;\n#endif",
+lightmap_pars_vertex:"#ifdef USE_LIGHTMAP\nvarying vec2 vUv2;\n#endif",lightmap_fragment:"#ifdef USE_LIGHTMAP\ngl_FragColor = gl_FragColor * texture2D( light_map, vUv2 );\n#endif",lightmap_vertex:"#ifdef USE_LIGHTMAP\nvUv2 = uv2;\n#endif",lights_pars_vertex:"uniform bool enableLighting;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n#ifdef PHONG\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\n#endif",
 lights_vertex:"if ( !enableLighting ) {\nvLightWeighting = vec3( 1.0 );\n} else {\nvLightWeighting = ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nfloat directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );\nvLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;\n}\n#endif\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 pointLightVector = normalize( lPosition.xyz - mvPosition.xyz );\nfloat pointLightWeighting = max( dot( transformedNormal, pointLightVector ), 0.0 );\nvLightWeighting += pointLightColor[ i ] * pointLightWeighting;\n#ifdef PHONG\nvPointLightVector[ i ] = pointLightVector;\n#endif\n}\n#endif\n}",
 lights_pars_fragment:"#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\nvarying vec3 vViewPosition;\nvarying vec3 vNormal;",lights_fragment:"vec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );\nvec4 mColor = vec4( diffuse, opacity );\nvec4 mSpecular = vec4( specular, opacity );\n#if MAX_POINT_LIGHTS > 0\nvec4 pointDiffuse  = vec4( 0.0 );\nvec4 pointSpecular = vec4( 0.0 );\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec3 pointVector = normalize( vPointLightVector[ i ] );\nvec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );\nfloat pointDotNormalHalf = dot( normal, pointHalfVector );\nfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );\nfloat pointSpecularWeight = 0.0;\nif ( pointDotNormalHalf >= 0.0 )\npointSpecularWeight = pow( pointDotNormalHalf, shininess );\npointDiffuse  += mColor * pointDiffuseWeight;\npointSpecular += mSpecular * pointSpecularWeight;\n}\n#endif\n#if MAX_DIR_LIGHTS > 0\nvec4 dirDiffuse  = vec4( 0.0 );\nvec4 dirSpecular = vec4( 0.0 );\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nvec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );\nfloat dirDotNormalHalf = dot( normal, dirHalfVector );\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\nfloat dirSpecularWeight = 0.0;\nif ( dirDotNormalHalf >= 0.0 )\ndirSpecularWeight = pow( dirDotNormalHalf, shininess );\ndirDiffuse  += mColor * dirDiffuseWeight;\ndirSpecular += mSpecular * dirSpecularWeight;\n}\n#endif\nvec4 totalLight = vec4( ambient, opacity );\n#if MAX_DIR_LIGHTS > 0\ntotalLight += dirDiffuse + dirSpecular;\n#endif\n#if MAX_POINT_LIGHTS > 0\ntotalLight += pointDiffuse + pointSpecular;\n#endif\ngl_FragColor = gl_FragColor * totalLight;",
 color_pars_fragment:"#ifdef USE_COLOR\nvarying vec3 vColor;\n#endif",color_fragment:"#ifdef USE_COLOR\ngl_FragColor = gl_FragColor * vec4( vColor, opacity );\n#endif",color_pars_vertex:"#ifdef USE_COLOR\nvarying vec3 vColor;\n#endif",color_vertex:"#ifdef USE_COLOR\nvColor = color;\n#endif"};

+ 35 - 35
build/ThreeDebug.js

@@ -38,7 +38,7 @@ n=i*j,l=i*b;this.set(n*j+e,n*b-g*s,n*s+g*b,0,n*b+g*s,l*b+e,l*s-g*j,0,n*s-g*b,l*s
 THREE.Matrix4.scaleMatrix=function(a,c,e){var g=new THREE.Matrix4;g.setScale(a,c,e);return g};THREE.Matrix4.rotationXMatrix=function(a){var c=new THREE.Matrix4;c.setRotX(a);return c};THREE.Matrix4.rotationYMatrix=function(a){var c=new THREE.Matrix4;c.setRotY(a);return c};THREE.Matrix4.rotationZMatrix=function(a){var c=new THREE.Matrix4;c.setRotZ(a);return c};THREE.Matrix4.rotationAxisAngleMatrix=function(a,c){var e=new THREE.Matrix4;e.setRotAxis(a,c);return e};
 THREE.Matrix4.makeInvert=function(a){var c=a.n11,e=a.n12,g=a.n13,i=a.n14,j=a.n21,b=a.n22,s=a.n23,n=a.n24,l=a.n31,q=a.n32,z=a.n33,w=a.n34,y=a.n41,F=a.n42,K=a.n43,L=a.n44,d=new THREE.Matrix4;d.n11=s*w*F-n*z*F+n*q*K-b*w*K-s*q*L+b*z*L;d.n12=i*z*F-g*w*F-i*q*K+e*w*K+g*q*L-e*z*L;d.n13=g*n*F-i*s*F+i*b*K-e*n*K-g*b*L+e*s*L;d.n14=i*s*q-g*n*q-i*b*z+e*n*z+g*b*w-e*s*w;d.n21=n*z*y-s*w*y-n*l*K+j*w*K+s*l*L-j*z*L;d.n22=g*w*y-i*z*y+i*l*K-c*w*K-g*l*L+c*z*L;d.n23=i*s*y-g*n*y-i*j*K+c*n*K+g*j*L-c*s*L;d.n24=g*n*l-i*s*l+
 i*j*z-c*n*z-g*j*w+c*s*w;d.n31=b*w*y-n*q*y+n*l*F-j*w*F-b*l*L+j*q*L;d.n32=i*q*y-e*w*y-i*l*F+c*w*F+e*l*L-c*q*L;d.n33=g*n*y-i*b*y+i*j*F-c*n*F-e*j*L+c*b*L;d.n34=i*b*l-e*n*l-i*j*q+c*n*q+e*j*w-c*b*w;d.n41=s*q*y-b*z*y-s*l*F+j*z*F+b*l*K-j*q*K;d.n42=e*z*y-g*q*y+g*l*F-c*z*F-e*l*K+c*q*K;d.n43=g*b*y-e*s*y-g*j*F+c*s*F+e*j*K-c*b*K;d.n44=e*s*l-g*b*l+g*j*q-c*s*q-e*j*z+c*b*z;d.multiplyScalar(1/a.determinant());return d};
-THREE.Matrix4.makeInvert3x3=function(a){var c=a.flatten();a=a.m33;var e=a.m,g=c[10]*c[5]-c[6]*c[9],i=-c[10]*c[1]+c[2]*c[9],j=c[6]*c[1]-c[2]*c[5],b=-c[10]*c[4]+c[6]*c[8],s=c[10]*c[0]-c[2]*c[8],n=-c[6]*c[0]+c[2]*c[4],l=c[9]*c[4]-c[5]*c[8],q=-c[9]*c[0]+c[1]*c[8],z=c[5]*c[0]-c[1]*c[4];c=c[0]*g+c[1]*b+c[2]*l;if(c==0)throw"matrix not invertible";c=1/c;e[0]=c*g;e[1]=c*i;e[2]=c*j;e[3]=c*b;e[4]=c*s;e[5]=c*n;e[6]=c*l;e[7]=c*q;e[8]=c*z;return a};
+THREE.Matrix4.makeInvert3x3=function(a){var c=a.m33,e=c.m,g=a.n33*a.n22-a.n32*a.n23,i=-a.n33*a.n21+a.n31*a.n23,j=a.n32*a.n21-a.n31*a.n22,b=-a.n33*a.n12+a.n32*a.n13,s=a.n33*a.n11-a.n31*a.n13,n=-a.n32*a.n11+a.n31*a.n12,l=a.n23*a.n12-a.n22*a.n13,q=-a.n23*a.n11+a.n21*a.n13,z=a.n22*a.n11-a.n21*a.n12;a=a.n11*g+a.n21*b+a.n31*l;if(a==0)throw"matrix not invertible";a=1/a;e[0]=a*g;e[1]=a*i;e[2]=a*j;e[3]=a*b;e[4]=a*s;e[5]=a*n;e[6]=a*l;e[7]=a*q;e[8]=a*z;return c};
 THREE.Matrix4.makeFrustum=function(a,c,e,g,i,j){var b,s,n;b=new THREE.Matrix4;s=2*i/(c-a);n=2*i/(g-e);a=(c+a)/(c-a);e=(g+e)/(g-e);g=-(j+i)/(j-i);i=-2*j*i/(j-i);b.n11=s;b.n12=0;b.n13=a;b.n14=0;b.n21=0;b.n22=n;b.n23=e;b.n24=0;b.n31=0;b.n32=0;b.n33=g;b.n34=i;b.n41=0;b.n42=0;b.n43=-1;b.n44=0;return b};THREE.Matrix4.makePerspective=function(a,c,e,g){var i;a=e*Math.tan(a*Math.PI/360);i=-a;return THREE.Matrix4.makeFrustum(i*c,a*c,i,a,e,g)};
 THREE.Matrix4.makeOrtho=function(a,c,e,g,i,j){var b,s,n,l;b=new THREE.Matrix4;s=c-a;n=e-g;l=j-i;a=(c+a)/s;e=(e+g)/n;i=(j+i)/l;b.n11=2/s;b.n12=0;b.n13=0;b.n14=-a;b.n21=0;b.n22=2/n;b.n23=0;b.n24=-e;b.n31=0;b.n32=0;b.n33=-2/l;b.n34=-i;b.n41=0;b.n42=0;b.n43=0;b.n44=1;return b};THREE.Matrix4.__tmpVec1=new THREE.Vector3;THREE.Matrix4.__tmpVec2=new THREE.Vector3;THREE.Matrix4.__tmpVec3=new THREE.Vector3;
 THREE.Vertex=function(a,c){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=c||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.tangent=new THREE.Vector4;this.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}};
@@ -176,40 +176,40 @@ c(d,THREE.ShaderLib.particle_basic);var m,t,p,r;k=p=r=0;for(m=o.length;k<m;k++){
 m.maxDirLights,"#define MAX_POINT_LIGHTS "+m.maxPointLights,m.fog?"#define USE_FOG":"",m.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",m.map?"#define USE_MAP":"",m.env_map?"#define USE_ENVMAP":"",m.light_map?"#define USE_LIGHTMAP":"",m.vertex_colors?"#define USE_COLOR":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");m=[b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+m.maxDirLights,"#define MAX_POINT_LIGHTS "+
 m.maxPointLights,m.map?"#define USE_MAP":"",m.env_map?"#define USE_ENVMAP":"",m.light_map?"#define USE_LIGHTMAP":"",m.vertex_colors?"#define USE_COLOR":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec3 color;\nattribute vec2 uv;\nattribute vec2 uv2;\n"].join("\n");b.attachShader(h,g("fragment",k+r));b.attachShader(h,
 g("vertex",m+o));b.linkProgram(h);b.getProgramParameter(h,b.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+b.getProgramParameter(h,b.VALIDATE_STATUS)+", gl error ["+b.getError()+"]");h.uniforms={};h.attributes={};d.program=h;h=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(f in d.uniforms)h.push(f);f=d.program;r=0;for(o=h.length;r<o;r++){k=h[r];f.uniforms[k]=b.getUniformLocation(f,k)}d=d.program;f=["position","normal",
-"uv","uv2","tangent","color"];h=0;for(r=f.length;h<r;h++){o=f[h];d.attributes[o]=b.getAttribLocation(d,o)}}};this.setProgram=function(d,o,h,f,k){this.initMaterial(f,o,h);var m=f.program;if(m!=s){b.useProgram(m);s=m}this.loadCamera(m,d);this.loadMatrices(m,k);if(f instanceof THREE.MeshPhongMaterial||f instanceof THREE.MeshLambertMaterial){this.setupLights(m,o);o=this.lights;f.uniforms.enableLighting.value=o.directional.length+o.point.length;f.uniforms.ambientLightColor.value=o.ambient;f.uniforms.directionalLightColor.value=
-o.directional.colors;f.uniforms.directionalLightDirection.value=o.directional.positions;f.uniforms.pointLightColor.value=o.point.colors;f.uniforms.pointLightPosition.value=o.point.positions}if(f instanceof THREE.MeshBasicMaterial||f instanceof THREE.MeshLambertMaterial||f instanceof THREE.MeshPhongMaterial){f.uniforms.diffuse.value.setRGB(f.color.r*f.opacity,f.color.g*f.opacity,f.color.b*f.opacity);f.uniforms.opacity.value=f.opacity;f.uniforms.map.texture=f.map;f.uniforms.light_map.texture=f.light_map;
-f.uniforms.env_map.texture=f.env_map;f.uniforms.reflectivity.value=f.reflectivity;f.uniforms.refraction_ratio.value=f.refraction_ratio;f.uniforms.combine.value=f.combine;f.uniforms.useRefract.value=f.env_map&&f.env_map.mapping instanceof THREE.CubeRefractionMapping;if(h){f.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){f.uniforms.fogNear.value=h.near;f.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)f.uniforms.fogDensity.value=h.density}}if(f instanceof THREE.LineBasicMaterial){f.uniforms.diffuse.value.setRGB(f.color.r*
-f.opacity,f.color.g*f.opacity,f.color.b*f.opacity);f.uniforms.opacity.value=f.opacity;if(h){f.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){f.uniforms.fogNear.value=h.near;f.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)f.uniforms.fogDensity.value=h.density}}if(f instanceof THREE.ParticleBasicMaterial){f.uniforms.psColor.value.setRGB(f.color.r*f.opacity,f.color.g*f.opacity,f.color.b*f.opacity);f.uniforms.opacity.value=f.opacity;f.uniforms.size.value=f.size;
-f.uniforms.map.texture=f.map;if(h){f.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){f.uniforms.fogNear.value=h.near;f.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)f.uniforms.fogDensity.value=h.density}}if(f instanceof THREE.MeshPhongMaterial){f.uniforms.ambient.value.setRGB(f.ambient.r,f.ambient.g,f.ambient.b);f.uniforms.specular.value.setRGB(f.specular.r,f.specular.g,f.specular.b);f.uniforms.shininess.value=f.shininess}if(f instanceof THREE.MeshDepthMaterial){f.uniforms.mNear.value=
-d.near;f.uniforms.mFar.value=d.far;f.uniforms.opacity.value=f.opacity}if(f instanceof THREE.MeshNormalMaterial)f.uniforms.opacity.value=f.opacity;d=f.uniforms;for(var t in d)if(k=m.uniforms[t]){f=d[t];o=f.type;h=f.value;if(o=="i")b.uniform1i(k,h);else if(o=="f")b.uniform1f(k,h);else if(o=="fv1")b.uniform1fv(k,h);else if(o=="fv")b.uniform3fv(k,h);else if(o=="v2")b.uniform2f(k,h.x,h.y);else if(o=="v3")b.uniform3f(k,h.x,h.y,h.z);else if(o=="c")b.uniform3f(k,h.r,h.g,h.b);else if(o=="t"){b.uniform1i(k,
-h);if(f=f.texture)if(f.image instanceof Array&&f.image.length==6){f=f;h=h;if(f.image.length==6){if(!f.image.__webGLTextureCube&&!f.image.__cubeMapInitialized&&f.image.loadCount==6){f.image.__webGLTextureCube=b.createTexture();b.bindTexture(b.TEXTURE_CUBE_MAP,f.image.__webGLTextureCube);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_MAG_FILTER,b.LINEAR);b.texParameteri(b.TEXTURE_CUBE_MAP,
-b.TEXTURE_MIN_FILTER,b.LINEAR_MIPMAP_LINEAR);for(o=0;o<6;++o)b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X+o,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,f.image[o]);b.generateMipmap(b.TEXTURE_CUBE_MAP);b.bindTexture(b.TEXTURE_CUBE_MAP,null);f.image.__cubeMapInitialized=true}b.activeTexture(b.TEXTURE0+h);b.bindTexture(b.TEXTURE_CUBE_MAP,f.image.__webGLTextureCube)}}else{f=f;h=h;if(!f.__webGLTexture&&f.image.loaded){f.__webGLTexture=b.createTexture();b.bindTexture(b.TEXTURE_2D,f.__webGLTexture);b.texImage2D(b.TEXTURE_2D,
-0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,f.image);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,i(f.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,i(f.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,i(f.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,i(f.min_filter));b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}b.activeTexture(b.TEXTURE0+h);b.bindTexture(b.TEXTURE_2D,f.__webGLTexture)}}}return m};this.renderBuffer=function(d,o,h,f,k,m){d=this.setProgram(d,
-o,h,f,m).attributes;b.bindBuffer(b.ARRAY_BUFFER,k.__webGLVertexBuffer);b.vertexAttribPointer(d.position,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.position);if(d.color>=0){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLColorBuffer);b.vertexAttribPointer(d.color,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.color)}if(d.normal>=0){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLNormalBuffer);b.vertexAttribPointer(d.normal,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.normal)}if(d.tangent>=0){b.bindBuffer(b.ARRAY_BUFFER,
-k.__webGLTangentBuffer);b.vertexAttribPointer(d.tangent,4,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.tangent)}if(d.uv>=0)if(k.__webGLUVBuffer){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLUVBuffer);b.vertexAttribPointer(d.uv,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.uv)}else b.disableVertexAttribArray(d.uv);if(d.uv2>=0)if(k.__webGLUV2Buffer){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLUV2Buffer);b.vertexAttribPointer(d.uv2,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.uv2)}else b.disableVertexAttribArray(d.uv2);
-if(m instanceof THREE.Mesh)if(f.wireframe){b.lineWidth(f.wireframe_linewidth);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,k.__webGLLineBuffer);b.drawElements(b.LINES,k.__webGLLineCount,b.UNSIGNED_SHORT,0)}else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,k.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,k.__webGLFaceCount,b.UNSIGNED_SHORT,0)}else if(m instanceof THREE.Line){m=m.type==THREE.LineStrip?b.LINE_STRIP:b.LINES;b.lineWidth(f.linewidth);b.drawArrays(m,0,k.__webGLLineCount)}else m instanceof THREE.ParticleSystem&&
-b.drawArrays(b.POINTS,0,k.__webGLParticleCount)};this.renderPass=function(d,o,h,f,k,m,t){var p,r,v,x,u;v=0;for(x=f.materials.length;v<x;v++){p=f.materials[v];if(p instanceof THREE.MeshFaceMaterial){p=0;for(r=k.materials.length;p<r;p++)if((u=k.materials[p])&&u.blending==m&&u.opacity<1==t){this.setBlending(u.blending);this.setDepthTest(u.depth_test);this.renderBuffer(d,o,h,u,k,f)}}else if((u=p)&&u.blending==m&&u.opacity<1==t){this.setBlending(u.blending);this.setDepthTest(u.depth_test);this.renderBuffer(d,
-o,h,u,k,f)}}};this.renderPassImmediate=function(d,o,h,f,k,m){var t,p,r,v;t=0;for(p=f.materials.length;t<p;t++)if((r=f.materials[t])&&r.blending==k&&r.opacity<1==m){this.setBlending(r.blending);this.setDepthTest(r.depth_test);v=this.setProgram(d,o,h,r,f);f.render(function(x){var u=v;if(!x.__webGLVertexBuffer)x.__webGLVertexBuffer=b.createBuffer();if(!x.__webGLNormalBuffer)x.__webGLNormalBuffer=b.createBuffer();if(x.hasPos){b.bindBuffer(b.ARRAY_BUFFER,x.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,
-x.positionArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(u.attributes.position);b.vertexAttribPointer(u.attributes.position,3,b.FLOAT,false,0,0)}if(x.hasNormal){b.bindBuffer(b.ARRAY_BUFFER,x.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,x.normalArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(u.attributes.normal);b.vertexAttribPointer(u.attributes.normal,3,b.FLOAT,false,0,0)}b.drawArrays(b.TRIANGLES,0,x.count);x.count=0})}};this.render=function(d,o,h,f){var k,m,t,p,r=d.lights,v=d.fog;o.autoUpdateMatrix&&
-o.updateMatrix();o.matrix.flattenToArray(w);o.projectionMatrix.flattenToArray(z);q.multiply(o.projectionMatrix,o.matrix);l[0].set(q.n41-q.n11,q.n42-q.n12,q.n43-q.n13,q.n44-q.n14);l[1].set(q.n41+q.n11,q.n42+q.n12,q.n43+q.n13,q.n44+q.n14);l[2].set(q.n41+q.n21,q.n42+q.n22,q.n43+q.n23,q.n44+q.n24);l[3].set(q.n41-q.n21,q.n42-q.n22,q.n43-q.n23,q.n44-q.n24);l[4].set(q.n41-q.n31,q.n42-q.n32,q.n43-q.n33,q.n44-q.n34);l[5].set(q.n41+q.n31,q.n42+q.n32,q.n43+q.n33,q.n44+q.n34);for(k=0;k<5;k++){p=l[k];p.divideScalar(Math.sqrt(p.x*
-p.x+p.y*p.y+p.z*p.z))}this.initWebGLObjects(d,o);f=f!==undefined?f:true;if(h&&!h.__webGLFramebuffer){h.__webGLFramebuffer=b.createFramebuffer();h.__webGLRenderbuffer=b.createRenderbuffer();h.__webGLTexture=b.createTexture();b.bindRenderbuffer(b.RENDERBUFFER,h.__webGLRenderbuffer);b.renderbufferStorage(b.RENDERBUFFER,b.DEPTH_COMPONENT16,h.width,h.height);b.bindTexture(b.TEXTURE_2D,h.__webGLTexture);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,i(h.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,
-i(h.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,i(h.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,i(h.min_filter));b.texImage2D(b.TEXTURE_2D,0,i(h.format),h.width,h.height,0,i(h.format),i(h.type),null);b.bindFramebuffer(b.FRAMEBUFFER,h.__webGLFramebuffer);b.framebufferTexture2D(b.FRAMEBUFFER,b.COLOR_ATTACHMENT0,b.TEXTURE_2D,h.__webGLTexture,0);b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,h.__webGLRenderbuffer);b.bindTexture(b.TEXTURE_2D,
-null);b.bindRenderbuffer(b.RENDERBUFFER,null);b.bindFramebuffer(b.FRAMEBUFFER,null)}if(h){k=h.__webGLFramebuffer;p=h.width;t=h.height}else{k=null;p=j.width;t=j.height}if(k!=n){b.bindFramebuffer(b.FRAMEBUFFER,k);b.viewport(0,0,p,t);f&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);n=k}this.autoClear&&this.clear();k=d.__webGLObjects.length;for(f=0;f<k;f++){t=d.__webGLObjects[f];p=t.object;if(m=p.visible){if(!(m=!(p instanceof THREE.Mesh)))a:{m=void 0;for(var x=p.matrix,u=-p.geometry.boundingSphere.radius*
-Math.max(p.scale.x,Math.max(p.scale.y,p.scale.z)),A=0;A<6;A++){m=l[A].x*x.n14+l[A].y*x.n24+l[A].z*x.n34+l[A].w;if(m<=u){m=false;break a}}m=true}m=m}if(m){if(p.autoUpdateMatrix){p.updateMatrix();p.matrix.flattenToArray(p._objectMatrixArray)}this.setupMatrices(p,o);t.render=true}else t.render=false}m=d.__webGLObjectsImmediate.length;for(f=0;f<m;f++){p=d.__webGLObjectsImmediate[f].object;if(p.visible){if(p.autoUpdateMatrix){p.updateMatrix();p.matrix.flattenToArray(p._objectMatrixArray)}this.setupMatrices(p,
-o)}}for(f=0;f<k;f++){t=d.__webGLObjects[f];if(t.render){p=t.object;t=t.buffer;e(p);this.renderPass(o,r,v,p,t,THREE.NormalBlending,false)}}for(f=0;f<m;f++){p=d.__webGLObjectsImmediate[f].object;if(p.visible){e(p);this.renderPassImmediate(o,r,v,p,THREE.NormalBlending,false)}}for(f=0;f<k;f++){t=d.__webGLObjects[f];if(t.render){p=t.object;t=t.buffer;e(p);this.renderPass(o,r,v,p,t,THREE.AdditiveBlending,false);this.renderPass(o,r,v,p,t,THREE.SubtractiveBlending,false);this.renderPass(o,r,v,p,t,THREE.AdditiveBlending,
-true);this.renderPass(o,r,v,p,t,THREE.SubtractiveBlending,true);this.renderPass(o,r,v,p,t,THREE.NormalBlending,true);this.renderPass(o,r,v,p,t,THREE.BillboardBlending,false)}}for(f=0;f<m;f++){p=d.__webGLObjectsImmediate[f].object;if(p.visible){e(p);this.renderPassImmediate(o,r,v,p,THREE.NormalBlending,true)}}if(h&&h.min_filter!==THREE.NearestFilter&&h.min_filter!==THREE.LinearFilter){b.bindTexture(b.TEXTURE_2D,h.__webGLTexture);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}};this.initWebGLObjects=
-function(d,o){function h(u,A,B,N){if(u[A]==undefined){d.__webGLObjects.push({buffer:B,object:N});u[A]=1}}function f(u,A,B){if(u[A]==undefined){d.__webGLObjectsImmediate.push({object:B});u[A]=1}}var k,m,t,p,r,v,x;if(!d.__webGLObjects){d.__webGLObjects=[];d.__webGLObjectsMap={};d.__webGLObjectsImmediate=[]}k=0;for(m=d.objects.length;k<m;k++){t=d.objects[k];r=t.geometry;if(d.__webGLObjectsMap[t.id]==undefined){d.__webGLObjectsMap[t.id]={};t._modelViewMatrix=new THREE.Matrix4;t._normalMatrixArray=new Float32Array(9);
-t._modelViewMatrixArray=new Float32Array(16);t._objectMatrixArray=new Float32Array(16);t.matrix.flattenToArray(t._objectMatrixArray)}x=d.__webGLObjectsMap[t.id];if(t instanceof THREE.Mesh){for(p in r.geometryChunks){v=r.geometryChunks[p];if(!v.__webGLVertexBuffer){this.createMeshBuffers(v);this.initMeshBuffers(v,t);r.__dirtyVertices=true;r.__dirtyElements=true;r.__dirtyUvs=true;r.__dirtyNormals=true;r.__dirtyTangents=true;r.__dirtyColors=true}if(r.__dirtyVertices||r.__dirtyElements||r.__dirtyUvs||
-r.__dirtyNormals||r.__dirtyColors||r.__dirtyTangents)this.setMeshBuffers(v,t,b.DYNAMIC_DRAW);h(x,p,v,t)}r.__dirtyVertices=false;r.__dirtyElements=false;r.__dirtyUvs=false;r.__dirtyNormals=false;r.__dirtyTangents=false;r.__dirtyColors=false}else if(t instanceof THREE.Line){if(!r.__webGLVertexBuffer){this.createLineBuffers(r);this.initLineBuffers(r);r.__dirtyVertices=true;r.__dirtyColors=true}if(r.__dirtyVertices||r.__dirtyColors)this.setLineBuffers(r,b.DYNAMIC_DRAW);h(x,0,r,t);r.__dirtyVertices=false;
-r.__dirtyColors=false}else if(t instanceof THREE.ParticleSystem){if(!r.__webGLVertexBuffer){this.createParticleBuffers(r);this.initParticleBuffers(r);r.__dirtyVertices=true;r.__dirtyColors=true}if(r.__dirtyVertices||r.__dirtyColors||t.sortParticles)this.setParticleBuffers(r,b.DYNAMIC_DRAW,t,o);h(x,0,r,t);r.__dirtyVertices=false;r.__dirtyColors=false}else t instanceof THREE.MarchingCubes&&f(x,0,t)}};this.removeObject=function(d,o){var h,f;for(h=d.__webGLObjects.length-1;h>=0;h--){f=d.__webGLObjects[h].object;
-o==f&&d.__webGLObjects.splice(h,1)}};this.setupMatrices=function(d,o){d._modelViewMatrix.multiplyToArray(o.matrix,d.matrix,d._modelViewMatrixArray);d._normalMatrix=THREE.Matrix4.makeInvert3x3(d._modelViewMatrix).transposeIntoArray(d._normalMatrixArray)};this.loadMatrices=function(d,o){b.uniformMatrix4fv(d.uniforms.viewMatrix,false,w);b.uniformMatrix4fv(d.uniforms.projectionMatrix,false,z);b.uniformMatrix4fv(d.uniforms.modelViewMatrix,false,o._modelViewMatrixArray);b.uniformMatrix3fv(d.uniforms.normalMatrix,
-false,o._normalMatrixArray);b.uniformMatrix4fv(d.uniforms.objectMatrix,false,o._objectMatrixArray)};this.loadCamera=function(d,o){b.uniform3f(d.uniforms.cameraPosition,o.position.x,o.position.y,o.position.z)};this.setDepthTest=function(d){d?b.enable(b.DEPTH_TEST):b.disable(b.DEPTH_TEST)};this.setBlending=function(d){switch(d){case THREE.AdditiveBlending:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE);break;case THREE.SubtractiveBlending:b.blendFunc(b.DST_COLOR,b.ZERO);break;case THREE.BillboardBlending:b.blendEquation(b.FUNC_ADD);
-b.blendFunc(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA);break;default:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(d,o){if(d){!o||o=="ccw"?b.frontFace(b.CCW):b.frontFace(b.CW);if(d=="back")b.cullFace(b.BACK);else d=="front"?b.cullFace(b.FRONT):b.cullFace(b.FRONT_AND_BACK);b.enable(b.CULL_FACE)}else b.disable(b.CULL_FACE)};this.supportsVertexTextures=function(){return b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}};
-THREE.Snippets={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );\n#endif",
-envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube env_map;\nuniform int combine;\n#endif",envmap_fragment:"#ifdef USE_ENVMAP\nvec4 cubeColor = textureCube( env_map, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = vec4( mix( gl_FragColor.xyz, cubeColor.xyz, reflectivity ), opacity );\n} else {\ngl_FragColor = gl_FragColor * cubeColor;\n}\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refraction_ratio;\nuniform bool useRefract;\n#endif",
-envmap_vertex:"#ifdef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nif ( useRefract ) {\nvReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refraction_ratio );\n} else {\nvReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );\n}\n#endif",map_particle_pars_fragment:"#ifdef USE_MAP\nuniform sampler2D map;\n#endif",
-map_particle_fragment:"#ifdef USE_MAP\ngl_FragColor = gl_FragColor * texture2D( map, gl_PointCoord );\n#endif",map_pars_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\n#endif",map_fragment:"#ifdef USE_MAP\ngl_FragColor = gl_FragColor * texture2D( map, vUv );\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv;\n#endif",lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\nvarying vec2 vUv2;\nuniform sampler2D light_map;\n#endif",lightmap_pars_vertex:"#ifdef USE_LIGHTMAP\nvarying vec2 vUv2;\n#endif",
-lightmap_fragment:"#ifdef USE_LIGHTMAP\ngl_FragColor = gl_FragColor * texture2D( light_map, vUv2 );\n#endif",lightmap_vertex:"#ifdef USE_LIGHTMAP\nvUv2 = uv2;\n#endif",lights_pars_vertex:"uniform bool enableLighting;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n#ifdef PHONG\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\n#endif",
+"uv","uv2","tangent","color"];h=0;for(r=f.length;h<r;h++){o=f[h];d.attributes[o]=b.getAttribLocation(d,o)}}};this.setProgram=function(d,o,h,f,k){this.initMaterial(f,o,h);var m=f.program;if(m!=s){b.useProgram(m);s=m}if(f instanceof THREE.MeshShaderMaterial||f instanceof THREE.MeshPhongMaterial||f.env_map)this.loadCamera(m,d);this.loadMatrices(m,k);if(f instanceof THREE.MeshPhongMaterial||f instanceof THREE.MeshLambertMaterial){this.setupLights(m,o);o=this.lights;f.uniforms.enableLighting.value=o.directional.length+
+o.point.length;f.uniforms.ambientLightColor.value=o.ambient;f.uniforms.directionalLightColor.value=o.directional.colors;f.uniforms.directionalLightDirection.value=o.directional.positions;f.uniforms.pointLightColor.value=o.point.colors;f.uniforms.pointLightPosition.value=o.point.positions}if(f instanceof THREE.MeshBasicMaterial||f instanceof THREE.MeshLambertMaterial||f instanceof THREE.MeshPhongMaterial){f.uniforms.diffuse.value.setRGB(f.color.r*f.opacity,f.color.g*f.opacity,f.color.b*f.opacity);
+f.uniforms.opacity.value=f.opacity;f.uniforms.map.texture=f.map;f.uniforms.light_map.texture=f.light_map;f.uniforms.env_map.texture=f.env_map;f.uniforms.reflectivity.value=f.reflectivity;f.uniforms.refraction_ratio.value=f.refraction_ratio;f.uniforms.combine.value=f.combine;f.uniforms.useRefract.value=f.env_map&&f.env_map.mapping instanceof THREE.CubeRefractionMapping;if(h){f.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){f.uniforms.fogNear.value=h.near;f.uniforms.fogFar.value=
+h.far}else if(h instanceof THREE.FogExp2)f.uniforms.fogDensity.value=h.density}}if(f instanceof THREE.LineBasicMaterial){f.uniforms.diffuse.value.setRGB(f.color.r*f.opacity,f.color.g*f.opacity,f.color.b*f.opacity);f.uniforms.opacity.value=f.opacity;if(h){f.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){f.uniforms.fogNear.value=h.near;f.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)f.uniforms.fogDensity.value=h.density}}if(f instanceof THREE.ParticleBasicMaterial){f.uniforms.psColor.value.setRGB(f.color.r*
+f.opacity,f.color.g*f.opacity,f.color.b*f.opacity);f.uniforms.opacity.value=f.opacity;f.uniforms.size.value=f.size;f.uniforms.map.texture=f.map;if(h){f.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){f.uniforms.fogNear.value=h.near;f.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)f.uniforms.fogDensity.value=h.density}}if(f instanceof THREE.MeshPhongMaterial){f.uniforms.ambient.value.setRGB(f.ambient.r,f.ambient.g,f.ambient.b);f.uniforms.specular.value.setRGB(f.specular.r,
+f.specular.g,f.specular.b);f.uniforms.shininess.value=f.shininess}if(f instanceof THREE.MeshDepthMaterial){f.uniforms.mNear.value=d.near;f.uniforms.mFar.value=d.far;f.uniforms.opacity.value=f.opacity}if(f instanceof THREE.MeshNormalMaterial)f.uniforms.opacity.value=f.opacity;d=f.uniforms;for(var t in d)if(k=m.uniforms[t]){f=d[t];o=f.type;h=f.value;if(o=="i")b.uniform1i(k,h);else if(o=="f")b.uniform1f(k,h);else if(o=="fv1")b.uniform1fv(k,h);else if(o=="fv")b.uniform3fv(k,h);else if(o=="v2")b.uniform2f(k,
+h.x,h.y);else if(o=="v3")b.uniform3f(k,h.x,h.y,h.z);else if(o=="c")b.uniform3f(k,h.r,h.g,h.b);else if(o=="t"){b.uniform1i(k,h);if(f=f.texture)if(f.image instanceof Array&&f.image.length==6){f=f;h=h;if(f.image.length==6){if(!f.image.__webGLTextureCube&&!f.image.__cubeMapInitialized&&f.image.loadCount==6){f.image.__webGLTextureCube=b.createTexture();b.bindTexture(b.TEXTURE_CUBE_MAP,f.image.__webGLTextureCube);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,
+b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_MAG_FILTER,b.LINEAR);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_MIN_FILTER,b.LINEAR_MIPMAP_LINEAR);for(o=0;o<6;++o)b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X+o,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,f.image[o]);b.generateMipmap(b.TEXTURE_CUBE_MAP);b.bindTexture(b.TEXTURE_CUBE_MAP,null);f.image.__cubeMapInitialized=true}b.activeTexture(b.TEXTURE0+h);b.bindTexture(b.TEXTURE_CUBE_MAP,f.image.__webGLTextureCube)}}else{f=f;h=h;if(!f.__webGLTexture&&
+f.image.loaded){f.__webGLTexture=b.createTexture();b.bindTexture(b.TEXTURE_2D,f.__webGLTexture);b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,f.image);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,i(f.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,i(f.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,i(f.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,i(f.min_filter));b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}b.activeTexture(b.TEXTURE0+
+h);b.bindTexture(b.TEXTURE_2D,f.__webGLTexture)}}}return m};this.renderBuffer=function(d,o,h,f,k,m){d=this.setProgram(d,o,h,f,m).attributes;b.bindBuffer(b.ARRAY_BUFFER,k.__webGLVertexBuffer);b.vertexAttribPointer(d.position,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.position);if(d.color>=0){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLColorBuffer);b.vertexAttribPointer(d.color,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.color)}if(d.normal>=0){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLNormalBuffer);
+b.vertexAttribPointer(d.normal,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.normal)}if(d.tangent>=0){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLTangentBuffer);b.vertexAttribPointer(d.tangent,4,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.tangent)}if(d.uv>=0)if(k.__webGLUVBuffer){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLUVBuffer);b.vertexAttribPointer(d.uv,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.uv)}else b.disableVertexAttribArray(d.uv);if(d.uv2>=0)if(k.__webGLUV2Buffer){b.bindBuffer(b.ARRAY_BUFFER,
+k.__webGLUV2Buffer);b.vertexAttribPointer(d.uv2,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.uv2)}else b.disableVertexAttribArray(d.uv2);if(m instanceof THREE.Mesh)if(f.wireframe){b.lineWidth(f.wireframe_linewidth);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,k.__webGLLineBuffer);b.drawElements(b.LINES,k.__webGLLineCount,b.UNSIGNED_SHORT,0)}else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,k.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,k.__webGLFaceCount,b.UNSIGNED_SHORT,0)}else if(m instanceof THREE.Line){m=
+m.type==THREE.LineStrip?b.LINE_STRIP:b.LINES;b.lineWidth(f.linewidth);b.drawArrays(m,0,k.__webGLLineCount)}else m instanceof THREE.ParticleSystem&&b.drawArrays(b.POINTS,0,k.__webGLParticleCount)};this.renderPass=function(d,o,h,f,k,m,t){var p,r,v,x,u;v=0;for(x=f.materials.length;v<x;v++){p=f.materials[v];if(p instanceof THREE.MeshFaceMaterial){p=0;for(r=k.materials.length;p<r;p++)if((u=k.materials[p])&&u.blending==m&&u.opacity<1==t){this.setBlending(u.blending);this.setDepthTest(u.depth_test);this.renderBuffer(d,
+o,h,u,k,f)}}else if((u=p)&&u.blending==m&&u.opacity<1==t){this.setBlending(u.blending);this.setDepthTest(u.depth_test);this.renderBuffer(d,o,h,u,k,f)}}};this.renderPassImmediate=function(d,o,h,f,k,m){var t,p,r,v;t=0;for(p=f.materials.length;t<p;t++)if((r=f.materials[t])&&r.blending==k&&r.opacity<1==m){this.setBlending(r.blending);this.setDepthTest(r.depth_test);v=this.setProgram(d,o,h,r,f);f.render(function(x){var u=v;if(!x.__webGLVertexBuffer)x.__webGLVertexBuffer=b.createBuffer();if(!x.__webGLNormalBuffer)x.__webGLNormalBuffer=
+b.createBuffer();if(x.hasPos){b.bindBuffer(b.ARRAY_BUFFER,x.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,x.positionArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(u.attributes.position);b.vertexAttribPointer(u.attributes.position,3,b.FLOAT,false,0,0)}if(x.hasNormal){b.bindBuffer(b.ARRAY_BUFFER,x.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,x.normalArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(u.attributes.normal);b.vertexAttribPointer(u.attributes.normal,3,b.FLOAT,false,0,0)}b.drawArrays(b.TRIANGLES,
+0,x.count);x.count=0})}};this.render=function(d,o,h,f){var k,m,t,p,r=d.lights,v=d.fog;o.autoUpdateMatrix&&o.updateMatrix();o.matrix.flattenToArray(w);o.projectionMatrix.flattenToArray(z);q.multiply(o.projectionMatrix,o.matrix);l[0].set(q.n41-q.n11,q.n42-q.n12,q.n43-q.n13,q.n44-q.n14);l[1].set(q.n41+q.n11,q.n42+q.n12,q.n43+q.n13,q.n44+q.n14);l[2].set(q.n41+q.n21,q.n42+q.n22,q.n43+q.n23,q.n44+q.n24);l[3].set(q.n41-q.n21,q.n42-q.n22,q.n43-q.n23,q.n44-q.n24);l[4].set(q.n41-q.n31,q.n42-q.n32,q.n43-q.n33,
+q.n44-q.n34);l[5].set(q.n41+q.n31,q.n42+q.n32,q.n43+q.n33,q.n44+q.n34);for(k=0;k<5;k++){p=l[k];p.divideScalar(Math.sqrt(p.x*p.x+p.y*p.y+p.z*p.z))}this.initWebGLObjects(d,o);f=f!==undefined?f:true;if(h&&!h.__webGLFramebuffer){h.__webGLFramebuffer=b.createFramebuffer();h.__webGLRenderbuffer=b.createRenderbuffer();h.__webGLTexture=b.createTexture();b.bindRenderbuffer(b.RENDERBUFFER,h.__webGLRenderbuffer);b.renderbufferStorage(b.RENDERBUFFER,b.DEPTH_COMPONENT16,h.width,h.height);b.bindTexture(b.TEXTURE_2D,
+h.__webGLTexture);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,i(h.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,i(h.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,i(h.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,i(h.min_filter));b.texImage2D(b.TEXTURE_2D,0,i(h.format),h.width,h.height,0,i(h.format),i(h.type),null);b.bindFramebuffer(b.FRAMEBUFFER,h.__webGLFramebuffer);b.framebufferTexture2D(b.FRAMEBUFFER,b.COLOR_ATTACHMENT0,b.TEXTURE_2D,h.__webGLTexture,0);
+b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,h.__webGLRenderbuffer);b.bindTexture(b.TEXTURE_2D,null);b.bindRenderbuffer(b.RENDERBUFFER,null);b.bindFramebuffer(b.FRAMEBUFFER,null)}if(h){k=h.__webGLFramebuffer;p=h.width;t=h.height}else{k=null;p=j.width;t=j.height}if(k!=n){b.bindFramebuffer(b.FRAMEBUFFER,k);b.viewport(0,0,p,t);f&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);n=k}this.autoClear&&this.clear();k=d.__webGLObjects.length;for(f=0;f<k;f++){t=d.__webGLObjects[f];
+p=t.object;if(m=p.visible){if(!(m=!(p instanceof THREE.Mesh)))a:{m=void 0;for(var x=p.matrix,u=-p.geometry.boundingSphere.radius*Math.max(p.scale.x,Math.max(p.scale.y,p.scale.z)),A=0;A<6;A++){m=l[A].x*x.n14+l[A].y*x.n24+l[A].z*x.n34+l[A].w;if(m<=u){m=false;break a}}m=true}m=m}if(m){if(p.autoUpdateMatrix){p.updateMatrix();p.matrix.flattenToArray(p._objectMatrixArray)}this.setupMatrices(p,o);t.render=true}else t.render=false}m=d.__webGLObjectsImmediate.length;for(f=0;f<m;f++){p=d.__webGLObjectsImmediate[f].object;
+if(p.visible){if(p.autoUpdateMatrix){p.updateMatrix();p.matrix.flattenToArray(p._objectMatrixArray)}this.setupMatrices(p,o)}}for(f=0;f<k;f++){t=d.__webGLObjects[f];if(t.render){p=t.object;t=t.buffer;e(p);this.renderPass(o,r,v,p,t,THREE.NormalBlending,false)}}for(f=0;f<m;f++){p=d.__webGLObjectsImmediate[f].object;if(p.visible){e(p);this.renderPassImmediate(o,r,v,p,THREE.NormalBlending,false)}}for(f=0;f<k;f++){t=d.__webGLObjects[f];if(t.render){p=t.object;t=t.buffer;e(p);this.renderPass(o,r,v,p,t,THREE.AdditiveBlending,
+false);this.renderPass(o,r,v,p,t,THREE.SubtractiveBlending,false);this.renderPass(o,r,v,p,t,THREE.AdditiveBlending,true);this.renderPass(o,r,v,p,t,THREE.SubtractiveBlending,true);this.renderPass(o,r,v,p,t,THREE.NormalBlending,true);this.renderPass(o,r,v,p,t,THREE.BillboardBlending,false)}}for(f=0;f<m;f++){p=d.__webGLObjectsImmediate[f].object;if(p.visible){e(p);this.renderPassImmediate(o,r,v,p,THREE.NormalBlending,true)}}if(h&&h.min_filter!==THREE.NearestFilter&&h.min_filter!==THREE.LinearFilter){b.bindTexture(b.TEXTURE_2D,
+h.__webGLTexture);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}};this.initWebGLObjects=function(d,o){function h(u,A,B,N){if(u[A]==undefined){d.__webGLObjects.push({buffer:B,object:N});u[A]=1}}function f(u,A,B){if(u[A]==undefined){d.__webGLObjectsImmediate.push({object:B});u[A]=1}}var k,m,t,p,r,v,x;if(!d.__webGLObjects){d.__webGLObjects=[];d.__webGLObjectsMap={};d.__webGLObjectsImmediate=[]}k=0;for(m=d.objects.length;k<m;k++){t=d.objects[k];r=t.geometry;if(d.__webGLObjectsMap[t.id]==
+undefined){d.__webGLObjectsMap[t.id]={};t._modelViewMatrix=new THREE.Matrix4;t._normalMatrixArray=new Float32Array(9);t._modelViewMatrixArray=new Float32Array(16);t._objectMatrixArray=new Float32Array(16);t.matrix.flattenToArray(t._objectMatrixArray)}x=d.__webGLObjectsMap[t.id];if(t instanceof THREE.Mesh){for(p in r.geometryChunks){v=r.geometryChunks[p];if(!v.__webGLVertexBuffer){this.createMeshBuffers(v);this.initMeshBuffers(v,t);r.__dirtyVertices=true;r.__dirtyElements=true;r.__dirtyUvs=true;r.__dirtyNormals=
+true;r.__dirtyTangents=true;r.__dirtyColors=true}if(r.__dirtyVertices||r.__dirtyElements||r.__dirtyUvs||r.__dirtyNormals||r.__dirtyColors||r.__dirtyTangents)this.setMeshBuffers(v,t,b.DYNAMIC_DRAW);h(x,p,v,t)}r.__dirtyVertices=false;r.__dirtyElements=false;r.__dirtyUvs=false;r.__dirtyNormals=false;r.__dirtyTangents=false;r.__dirtyColors=false}else if(t instanceof THREE.Line){if(!r.__webGLVertexBuffer){this.createLineBuffers(r);this.initLineBuffers(r);r.__dirtyVertices=true;r.__dirtyColors=true}if(r.__dirtyVertices||
+r.__dirtyColors)this.setLineBuffers(r,b.DYNAMIC_DRAW);h(x,0,r,t);r.__dirtyVertices=false;r.__dirtyColors=false}else if(t instanceof THREE.ParticleSystem){if(!r.__webGLVertexBuffer){this.createParticleBuffers(r);this.initParticleBuffers(r);r.__dirtyVertices=true;r.__dirtyColors=true}if(r.__dirtyVertices||r.__dirtyColors||t.sortParticles)this.setParticleBuffers(r,b.DYNAMIC_DRAW,t,o);h(x,0,r,t);r.__dirtyVertices=false;r.__dirtyColors=false}else t instanceof THREE.MarchingCubes&&f(x,0,t)}};this.removeObject=
+function(d,o){var h,f;for(h=d.__webGLObjects.length-1;h>=0;h--){f=d.__webGLObjects[h].object;o==f&&d.__webGLObjects.splice(h,1)}};this.setupMatrices=function(d,o){d._modelViewMatrix.multiplyToArray(o.matrix,d.matrix,d._modelViewMatrixArray);d._normalMatrix=THREE.Matrix4.makeInvert3x3(d._modelViewMatrix).transposeIntoArray(d._normalMatrixArray)};this.loadMatrices=function(d,o){b.uniformMatrix4fv(d.uniforms.viewMatrix,false,w);b.uniformMatrix4fv(d.uniforms.projectionMatrix,false,z);b.uniformMatrix4fv(d.uniforms.modelViewMatrix,
+false,o._modelViewMatrixArray);b.uniformMatrix3fv(d.uniforms.normalMatrix,false,o._normalMatrixArray);b.uniformMatrix4fv(d.uniforms.objectMatrix,false,o._objectMatrixArray)};this.loadCamera=function(d,o){b.uniform3f(d.uniforms.cameraPosition,o.position.x,o.position.y,o.position.z)};this.setDepthTest=function(d){d?b.enable(b.DEPTH_TEST):b.disable(b.DEPTH_TEST)};this.setBlending=function(d){switch(d){case THREE.AdditiveBlending:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE);break;case THREE.SubtractiveBlending:b.blendFunc(b.DST_COLOR,
+b.ZERO);break;case THREE.BillboardBlending:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA);break;default:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(d,o){if(d){!o||o=="ccw"?b.frontFace(b.CCW):b.frontFace(b.CW);if(d=="back")b.cullFace(b.BACK);else d=="front"?b.cullFace(b.FRONT):b.cullFace(b.FRONT_AND_BACK);b.enable(b.CULL_FACE)}else b.disable(b.CULL_FACE)};this.supportsVertexTextures=function(){return b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>
+0}};
+THREE.Snippets={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );\n#endif",envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube env_map;\nuniform int combine;\n#endif",
+envmap_fragment:"#ifdef USE_ENVMAP\nvec4 cubeColor = textureCube( env_map, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = vec4( mix( gl_FragColor.xyz, cubeColor.xyz, reflectivity ), opacity );\n} else {\ngl_FragColor = gl_FragColor * cubeColor;\n}\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refraction_ratio;\nuniform bool useRefract;\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nif ( useRefract ) {\nvReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refraction_ratio );\n} else {\nvReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );\n}\n#endif",
+map_particle_pars_fragment:"#ifdef USE_MAP\nuniform sampler2D map;\n#endif",map_particle_fragment:"#ifdef USE_MAP\ngl_FragColor = gl_FragColor * texture2D( map, gl_PointCoord );\n#endif",map_pars_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\n#endif",map_fragment:"#ifdef USE_MAP\ngl_FragColor = gl_FragColor * texture2D( map, vUv );\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv;\n#endif",lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\nvarying vec2 vUv2;\nuniform sampler2D light_map;\n#endif",
+lightmap_pars_vertex:"#ifdef USE_LIGHTMAP\nvarying vec2 vUv2;\n#endif",lightmap_fragment:"#ifdef USE_LIGHTMAP\ngl_FragColor = gl_FragColor * texture2D( light_map, vUv2 );\n#endif",lightmap_vertex:"#ifdef USE_LIGHTMAP\nvUv2 = uv2;\n#endif",lights_pars_vertex:"uniform bool enableLighting;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n#ifdef PHONG\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\n#endif",
 lights_vertex:"if ( !enableLighting ) {\nvLightWeighting = vec3( 1.0 );\n} else {\nvLightWeighting = ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nfloat directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );\nvLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;\n}\n#endif\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 pointLightVector = normalize( lPosition.xyz - mvPosition.xyz );\nfloat pointLightWeighting = max( dot( transformedNormal, pointLightVector ), 0.0 );\nvLightWeighting += pointLightColor[ i ] * pointLightWeighting;\n#ifdef PHONG\nvPointLightVector[ i ] = pointLightVector;\n#endif\n}\n#endif\n}",
 lights_pars_fragment:"#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\nvarying vec3 vViewPosition;\nvarying vec3 vNormal;",lights_fragment:"vec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );\nvec4 mColor = vec4( diffuse, opacity );\nvec4 mSpecular = vec4( specular, opacity );\n#if MAX_POINT_LIGHTS > 0\nvec4 pointDiffuse  = vec4( 0.0 );\nvec4 pointSpecular = vec4( 0.0 );\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec3 pointVector = normalize( vPointLightVector[ i ] );\nvec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );\nfloat pointDotNormalHalf = dot( normal, pointHalfVector );\nfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );\nfloat pointSpecularWeight = 0.0;\nif ( pointDotNormalHalf >= 0.0 )\npointSpecularWeight = pow( pointDotNormalHalf, shininess );\npointDiffuse  += mColor * pointDiffuseWeight;\npointSpecular += mSpecular * pointSpecularWeight;\n}\n#endif\n#if MAX_DIR_LIGHTS > 0\nvec4 dirDiffuse  = vec4( 0.0 );\nvec4 dirSpecular = vec4( 0.0 );\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nvec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );\nfloat dirDotNormalHalf = dot( normal, dirHalfVector );\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\nfloat dirSpecularWeight = 0.0;\nif ( dirDotNormalHalf >= 0.0 )\ndirSpecularWeight = pow( dirDotNormalHalf, shininess );\ndirDiffuse  += mColor * dirDiffuseWeight;\ndirSpecular += mSpecular * dirSpecularWeight;\n}\n#endif\nvec4 totalLight = vec4( ambient, opacity );\n#if MAX_DIR_LIGHTS > 0\ntotalLight += dirDiffuse + dirSpecular;\n#endif\n#if MAX_POINT_LIGHTS > 0\ntotalLight += pointDiffuse + pointSpecular;\n#endif\ngl_FragColor = gl_FragColor * totalLight;",
 color_pars_fragment:"#ifdef USE_COLOR\nvarying vec3 vColor;\n#endif",color_fragment:"#ifdef USE_COLOR\ngl_FragColor = gl_FragColor * vec4( vColor, opacity );\n#endif",color_pars_vertex:"#ifdef USE_COLOR\nvarying vec3 vColor;\n#endif",color_vertex:"#ifdef USE_COLOR\nvColor = color;\n#endif"};

+ 35 - 35
build/ThreeExtras.js

@@ -38,7 +38,7 @@ k=h*g,n=h*b;this.set(k*g+d,k*b-e*m,k*m+e*b,0,k*b+e*m,n*b+d,n*m-e*g,0,k*m-e*b,n*m
 THREE.Matrix4.scaleMatrix=function(a,c,d){var e=new THREE.Matrix4;e.setScale(a,c,d);return e};THREE.Matrix4.rotationXMatrix=function(a){var c=new THREE.Matrix4;c.setRotX(a);return c};THREE.Matrix4.rotationYMatrix=function(a){var c=new THREE.Matrix4;c.setRotY(a);return c};THREE.Matrix4.rotationZMatrix=function(a){var c=new THREE.Matrix4;c.setRotZ(a);return c};THREE.Matrix4.rotationAxisAngleMatrix=function(a,c){var d=new THREE.Matrix4;d.setRotAxis(a,c);return d};
 THREE.Matrix4.makeInvert=function(a){var c=a.n11,d=a.n12,e=a.n13,h=a.n14,g=a.n21,b=a.n22,m=a.n23,k=a.n24,n=a.n31,o=a.n32,y=a.n33,v=a.n34,q=a.n41,z=a.n42,B=a.n43,H=a.n44,f=new THREE.Matrix4;f.n11=m*v*z-k*y*z+k*o*B-b*v*B-m*o*H+b*y*H;f.n12=h*y*z-e*v*z-h*o*B+d*v*B+e*o*H-d*y*H;f.n13=e*k*z-h*m*z+h*b*B-d*k*B-e*b*H+d*m*H;f.n14=h*m*o-e*k*o-h*b*y+d*k*y+e*b*v-d*m*v;f.n21=k*y*q-m*v*q-k*n*B+g*v*B+m*n*H-g*y*H;f.n22=e*v*q-h*y*q+h*n*B-c*v*B-e*n*H+c*y*H;f.n23=h*m*q-e*k*q-h*g*B+c*k*B+e*g*H-c*m*H;f.n24=e*k*n-h*m*n+
 h*g*y-c*k*y-e*g*v+c*m*v;f.n31=b*v*q-k*o*q+k*n*z-g*v*z-b*n*H+g*o*H;f.n32=h*o*q-d*v*q-h*n*z+c*v*z+d*n*H-c*o*H;f.n33=e*k*q-h*b*q+h*g*z-c*k*z-d*g*H+c*b*H;f.n34=h*b*n-d*k*n-h*g*o+c*k*o+d*g*v-c*b*v;f.n41=m*o*q-b*y*q-m*n*z+g*y*z+b*n*B-g*o*B;f.n42=d*y*q-e*o*q+e*n*z-c*y*z-d*n*B+c*o*B;f.n43=e*b*q-d*m*q-e*g*z+c*m*z+d*g*B-c*b*B;f.n44=d*m*n-e*b*n+e*g*o-c*m*o-d*g*y+c*b*y;f.multiplyScalar(1/a.determinant());return f};
-THREE.Matrix4.makeInvert3x3=function(a){var c=a.flatten();a=a.m33;var d=a.m,e=c[10]*c[5]-c[6]*c[9],h=-c[10]*c[1]+c[2]*c[9],g=c[6]*c[1]-c[2]*c[5],b=-c[10]*c[4]+c[6]*c[8],m=c[10]*c[0]-c[2]*c[8],k=-c[6]*c[0]+c[2]*c[4],n=c[9]*c[4]-c[5]*c[8],o=-c[9]*c[0]+c[1]*c[8],y=c[5]*c[0]-c[1]*c[4];c=c[0]*e+c[1]*b+c[2]*n;if(c==0)throw"matrix not invertible";c=1/c;d[0]=c*e;d[1]=c*h;d[2]=c*g;d[3]=c*b;d[4]=c*m;d[5]=c*k;d[6]=c*n;d[7]=c*o;d[8]=c*y;return a};
+THREE.Matrix4.makeInvert3x3=function(a){var c=a.m33,d=c.m,e=a.n33*a.n22-a.n32*a.n23,h=-a.n33*a.n21+a.n31*a.n23,g=a.n32*a.n21-a.n31*a.n22,b=-a.n33*a.n12+a.n32*a.n13,m=a.n33*a.n11-a.n31*a.n13,k=-a.n32*a.n11+a.n31*a.n12,n=a.n23*a.n12-a.n22*a.n13,o=-a.n23*a.n11+a.n21*a.n13,y=a.n22*a.n11-a.n21*a.n12;a=a.n11*e+a.n21*b+a.n31*n;if(a==0)throw"matrix not invertible";a=1/a;d[0]=a*e;d[1]=a*h;d[2]=a*g;d[3]=a*b;d[4]=a*m;d[5]=a*k;d[6]=a*n;d[7]=a*o;d[8]=a*y;return c};
 THREE.Matrix4.makeFrustum=function(a,c,d,e,h,g){var b,m,k;b=new THREE.Matrix4;m=2*h/(c-a);k=2*h/(e-d);a=(c+a)/(c-a);d=(e+d)/(e-d);e=-(g+h)/(g-h);h=-2*g*h/(g-h);b.n11=m;b.n12=0;b.n13=a;b.n14=0;b.n21=0;b.n22=k;b.n23=d;b.n24=0;b.n31=0;b.n32=0;b.n33=e;b.n34=h;b.n41=0;b.n42=0;b.n43=-1;b.n44=0;return b};THREE.Matrix4.makePerspective=function(a,c,d,e){var h;a=d*Math.tan(a*Math.PI/360);h=-a;return THREE.Matrix4.makeFrustum(h*c,a*c,h,a,d,e)};
 THREE.Matrix4.makeOrtho=function(a,c,d,e,h,g){var b,m,k,n;b=new THREE.Matrix4;m=c-a;k=d-e;n=g-h;a=(c+a)/m;d=(d+e)/k;h=(g+h)/n;b.n11=2/m;b.n12=0;b.n13=0;b.n14=-a;b.n21=0;b.n22=2/k;b.n23=0;b.n24=-d;b.n31=0;b.n32=0;b.n33=-2/n;b.n34=-h;b.n41=0;b.n42=0;b.n43=0;b.n44=1;return b};THREE.Matrix4.__tmpVec1=new THREE.Vector3;THREE.Matrix4.__tmpVec2=new THREE.Vector3;THREE.Matrix4.__tmpVec3=new THREE.Vector3;
 THREE.Vertex=function(a,c){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=c||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.tangent=new THREE.Vector4;this.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}};
@@ -176,40 +176,40 @@ THREE.ParticleBasicMaterial&&c(f,THREE.ShaderLib.particle_basic);var w,x,u,A;t=u
 "#define MAX_DIR_LIGHTS "+w.maxDirLights,"#define MAX_POINT_LIGHTS "+w.maxPointLights,w.fog?"#define USE_FOG":"",w.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",w.map?"#define USE_MAP":"",w.env_map?"#define USE_ENVMAP":"",w.light_map?"#define USE_LIGHTMAP":"",w.vertex_colors?"#define USE_COLOR":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");w=[b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+w.maxDirLights,"#define MAX_POINT_LIGHTS "+
 w.maxPointLights,w.map?"#define USE_MAP":"",w.env_map?"#define USE_ENVMAP":"",w.light_map?"#define USE_LIGHTMAP":"",w.vertex_colors?"#define USE_COLOR":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec3 color;\nattribute vec2 uv;\nattribute vec2 uv2;\n"].join("\n");b.attachShader(j,e("fragment",t+A));b.attachShader(j,
 e("vertex",w+p));b.linkProgram(j);b.getProgramParameter(j,b.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+b.getProgramParameter(j,b.VALIDATE_STATUS)+", gl error ["+b.getError()+"]");j.uniforms={};j.attributes={};f.program=j;j=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(l in f.uniforms)j.push(l);l=f.program;A=0;for(p=j.length;A<p;A++){t=j[A];l.uniforms[t]=b.getUniformLocation(l,t)}f=f.program;l=["position","normal",
-"uv","uv2","tangent","color"];j=0;for(A=l.length;j<A;j++){p=l[j];f.attributes[p]=b.getAttribLocation(f,p)}}};this.setProgram=function(f,p,j,l,t){this.initMaterial(l,p,j);var w=l.program;if(w!=m){b.useProgram(w);m=w}this.loadCamera(w,f);this.loadMatrices(w,t);if(l instanceof THREE.MeshPhongMaterial||l instanceof THREE.MeshLambertMaterial){this.setupLights(w,p);p=this.lights;l.uniforms.enableLighting.value=p.directional.length+p.point.length;l.uniforms.ambientLightColor.value=p.ambient;l.uniforms.directionalLightColor.value=
-p.directional.colors;l.uniforms.directionalLightDirection.value=p.directional.positions;l.uniforms.pointLightColor.value=p.point.colors;l.uniforms.pointLightPosition.value=p.point.positions}if(l instanceof THREE.MeshBasicMaterial||l instanceof THREE.MeshLambertMaterial||l instanceof THREE.MeshPhongMaterial){l.uniforms.diffuse.value.setRGB(l.color.r*l.opacity,l.color.g*l.opacity,l.color.b*l.opacity);l.uniforms.opacity.value=l.opacity;l.uniforms.map.texture=l.map;l.uniforms.light_map.texture=l.light_map;
-l.uniforms.env_map.texture=l.env_map;l.uniforms.reflectivity.value=l.reflectivity;l.uniforms.refraction_ratio.value=l.refraction_ratio;l.uniforms.combine.value=l.combine;l.uniforms.useRefract.value=l.env_map&&l.env_map.mapping instanceof THREE.CubeRefractionMapping;if(j){l.uniforms.fogColor.value.setHex(j.color.hex);if(j instanceof THREE.Fog){l.uniforms.fogNear.value=j.near;l.uniforms.fogFar.value=j.far}else if(j instanceof THREE.FogExp2)l.uniforms.fogDensity.value=j.density}}if(l instanceof THREE.LineBasicMaterial){l.uniforms.diffuse.value.setRGB(l.color.r*
-l.opacity,l.color.g*l.opacity,l.color.b*l.opacity);l.uniforms.opacity.value=l.opacity;if(j){l.uniforms.fogColor.value.setHex(j.color.hex);if(j instanceof THREE.Fog){l.uniforms.fogNear.value=j.near;l.uniforms.fogFar.value=j.far}else if(j instanceof THREE.FogExp2)l.uniforms.fogDensity.value=j.density}}if(l instanceof THREE.ParticleBasicMaterial){l.uniforms.psColor.value.setRGB(l.color.r*l.opacity,l.color.g*l.opacity,l.color.b*l.opacity);l.uniforms.opacity.value=l.opacity;l.uniforms.size.value=l.size;
-l.uniforms.map.texture=l.map;if(j){l.uniforms.fogColor.value.setHex(j.color.hex);if(j instanceof THREE.Fog){l.uniforms.fogNear.value=j.near;l.uniforms.fogFar.value=j.far}else if(j instanceof THREE.FogExp2)l.uniforms.fogDensity.value=j.density}}if(l instanceof THREE.MeshPhongMaterial){l.uniforms.ambient.value.setRGB(l.ambient.r,l.ambient.g,l.ambient.b);l.uniforms.specular.value.setRGB(l.specular.r,l.specular.g,l.specular.b);l.uniforms.shininess.value=l.shininess}if(l instanceof THREE.MeshDepthMaterial){l.uniforms.mNear.value=
-f.near;l.uniforms.mFar.value=f.far;l.uniforms.opacity.value=l.opacity}if(l instanceof THREE.MeshNormalMaterial)l.uniforms.opacity.value=l.opacity;f=l.uniforms;for(var x in f)if(t=w.uniforms[x]){l=f[x];p=l.type;j=l.value;if(p=="i")b.uniform1i(t,j);else if(p=="f")b.uniform1f(t,j);else if(p=="fv1")b.uniform1fv(t,j);else if(p=="fv")b.uniform3fv(t,j);else if(p=="v2")b.uniform2f(t,j.x,j.y);else if(p=="v3")b.uniform3f(t,j.x,j.y,j.z);else if(p=="c")b.uniform3f(t,j.r,j.g,j.b);else if(p=="t"){b.uniform1i(t,
-j);if(l=l.texture)if(l.image instanceof Array&&l.image.length==6){l=l;j=j;if(l.image.length==6){if(!l.image.__webGLTextureCube&&!l.image.__cubeMapInitialized&&l.image.loadCount==6){l.image.__webGLTextureCube=b.createTexture();b.bindTexture(b.TEXTURE_CUBE_MAP,l.image.__webGLTextureCube);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_MAG_FILTER,b.LINEAR);b.texParameteri(b.TEXTURE_CUBE_MAP,
-b.TEXTURE_MIN_FILTER,b.LINEAR_MIPMAP_LINEAR);for(p=0;p<6;++p)b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X+p,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,l.image[p]);b.generateMipmap(b.TEXTURE_CUBE_MAP);b.bindTexture(b.TEXTURE_CUBE_MAP,null);l.image.__cubeMapInitialized=true}b.activeTexture(b.TEXTURE0+j);b.bindTexture(b.TEXTURE_CUBE_MAP,l.image.__webGLTextureCube)}}else{l=l;j=j;if(!l.__webGLTexture&&l.image.loaded){l.__webGLTexture=b.createTexture();b.bindTexture(b.TEXTURE_2D,l.__webGLTexture);b.texImage2D(b.TEXTURE_2D,
-0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,l.image);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,h(l.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,h(l.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,h(l.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,h(l.min_filter));b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}b.activeTexture(b.TEXTURE0+j);b.bindTexture(b.TEXTURE_2D,l.__webGLTexture)}}}return w};this.renderBuffer=function(f,p,j,l,t,w){f=this.setProgram(f,
-p,j,l,w).attributes;b.bindBuffer(b.ARRAY_BUFFER,t.__webGLVertexBuffer);b.vertexAttribPointer(f.position,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.position);if(f.color>=0){b.bindBuffer(b.ARRAY_BUFFER,t.__webGLColorBuffer);b.vertexAttribPointer(f.color,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.color)}if(f.normal>=0){b.bindBuffer(b.ARRAY_BUFFER,t.__webGLNormalBuffer);b.vertexAttribPointer(f.normal,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.normal)}if(f.tangent>=0){b.bindBuffer(b.ARRAY_BUFFER,
-t.__webGLTangentBuffer);b.vertexAttribPointer(f.tangent,4,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.tangent)}if(f.uv>=0)if(t.__webGLUVBuffer){b.bindBuffer(b.ARRAY_BUFFER,t.__webGLUVBuffer);b.vertexAttribPointer(f.uv,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.uv)}else b.disableVertexAttribArray(f.uv);if(f.uv2>=0)if(t.__webGLUV2Buffer){b.bindBuffer(b.ARRAY_BUFFER,t.__webGLUV2Buffer);b.vertexAttribPointer(f.uv2,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.uv2)}else b.disableVertexAttribArray(f.uv2);
-if(w instanceof THREE.Mesh)if(l.wireframe){b.lineWidth(l.wireframe_linewidth);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,t.__webGLLineBuffer);b.drawElements(b.LINES,t.__webGLLineCount,b.UNSIGNED_SHORT,0)}else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,t.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,t.__webGLFaceCount,b.UNSIGNED_SHORT,0)}else if(w instanceof THREE.Line){w=w.type==THREE.LineStrip?b.LINE_STRIP:b.LINES;b.lineWidth(l.linewidth);b.drawArrays(w,0,t.__webGLLineCount)}else w instanceof THREE.ParticleSystem&&
-b.drawArrays(b.POINTS,0,t.__webGLParticleCount)};this.renderPass=function(f,p,j,l,t,w,x){var u,A,C,F,E;C=0;for(F=l.materials.length;C<F;C++){u=l.materials[C];if(u instanceof THREE.MeshFaceMaterial){u=0;for(A=t.materials.length;u<A;u++)if((E=t.materials[u])&&E.blending==w&&E.opacity<1==x){this.setBlending(E.blending);this.setDepthTest(E.depth_test);this.renderBuffer(f,p,j,E,t,l)}}else if((E=u)&&E.blending==w&&E.opacity<1==x){this.setBlending(E.blending);this.setDepthTest(E.depth_test);this.renderBuffer(f,
-p,j,E,t,l)}}};this.renderPassImmediate=function(f,p,j,l,t,w){var x,u,A,C;x=0;for(u=l.materials.length;x<u;x++)if((A=l.materials[x])&&A.blending==t&&A.opacity<1==w){this.setBlending(A.blending);this.setDepthTest(A.depth_test);C=this.setProgram(f,p,j,A,l);l.render(function(F){var E=C;if(!F.__webGLVertexBuffer)F.__webGLVertexBuffer=b.createBuffer();if(!F.__webGLNormalBuffer)F.__webGLNormalBuffer=b.createBuffer();if(F.hasPos){b.bindBuffer(b.ARRAY_BUFFER,F.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,
-F.positionArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(E.attributes.position);b.vertexAttribPointer(E.attributes.position,3,b.FLOAT,false,0,0)}if(F.hasNormal){b.bindBuffer(b.ARRAY_BUFFER,F.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,F.normalArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(E.attributes.normal);b.vertexAttribPointer(E.attributes.normal,3,b.FLOAT,false,0,0)}b.drawArrays(b.TRIANGLES,0,F.count);F.count=0})}};this.render=function(f,p,j,l){var t,w,x,u,A=f.lights,C=f.fog;p.autoUpdateMatrix&&
-p.updateMatrix();p.matrix.flattenToArray(v);p.projectionMatrix.flattenToArray(y);o.multiply(p.projectionMatrix,p.matrix);n[0].set(o.n41-o.n11,o.n42-o.n12,o.n43-o.n13,o.n44-o.n14);n[1].set(o.n41+o.n11,o.n42+o.n12,o.n43+o.n13,o.n44+o.n14);n[2].set(o.n41+o.n21,o.n42+o.n22,o.n43+o.n23,o.n44+o.n24);n[3].set(o.n41-o.n21,o.n42-o.n22,o.n43-o.n23,o.n44-o.n24);n[4].set(o.n41-o.n31,o.n42-o.n32,o.n43-o.n33,o.n44-o.n34);n[5].set(o.n41+o.n31,o.n42+o.n32,o.n43+o.n33,o.n44+o.n34);for(t=0;t<5;t++){u=n[t];u.divideScalar(Math.sqrt(u.x*
-u.x+u.y*u.y+u.z*u.z))}this.initWebGLObjects(f,p);l=l!==undefined?l:true;if(j&&!j.__webGLFramebuffer){j.__webGLFramebuffer=b.createFramebuffer();j.__webGLRenderbuffer=b.createRenderbuffer();j.__webGLTexture=b.createTexture();b.bindRenderbuffer(b.RENDERBUFFER,j.__webGLRenderbuffer);b.renderbufferStorage(b.RENDERBUFFER,b.DEPTH_COMPONENT16,j.width,j.height);b.bindTexture(b.TEXTURE_2D,j.__webGLTexture);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,h(j.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,
-h(j.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,h(j.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,h(j.min_filter));b.texImage2D(b.TEXTURE_2D,0,h(j.format),j.width,j.height,0,h(j.format),h(j.type),null);b.bindFramebuffer(b.FRAMEBUFFER,j.__webGLFramebuffer);b.framebufferTexture2D(b.FRAMEBUFFER,b.COLOR_ATTACHMENT0,b.TEXTURE_2D,j.__webGLTexture,0);b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,j.__webGLRenderbuffer);b.bindTexture(b.TEXTURE_2D,
-null);b.bindRenderbuffer(b.RENDERBUFFER,null);b.bindFramebuffer(b.FRAMEBUFFER,null)}if(j){t=j.__webGLFramebuffer;u=j.width;x=j.height}else{t=null;u=g.width;x=g.height}if(t!=k){b.bindFramebuffer(b.FRAMEBUFFER,t);b.viewport(0,0,u,x);l&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);k=t}this.autoClear&&this.clear();t=f.__webGLObjects.length;for(l=0;l<t;l++){x=f.__webGLObjects[l];u=x.object;if(w=u.visible){if(!(w=!(u instanceof THREE.Mesh)))a:{w=void 0;for(var F=u.matrix,E=-u.geometry.boundingSphere.radius*
-Math.max(u.scale.x,Math.max(u.scale.y,u.scale.z)),D=0;D<6;D++){w=n[D].x*F.n14+n[D].y*F.n24+n[D].z*F.n34+n[D].w;if(w<=E){w=false;break a}}w=true}w=w}if(w){if(u.autoUpdateMatrix){u.updateMatrix();u.matrix.flattenToArray(u._objectMatrixArray)}this.setupMatrices(u,p);x.render=true}else x.render=false}w=f.__webGLObjectsImmediate.length;for(l=0;l<w;l++){u=f.__webGLObjectsImmediate[l].object;if(u.visible){if(u.autoUpdateMatrix){u.updateMatrix();u.matrix.flattenToArray(u._objectMatrixArray)}this.setupMatrices(u,
-p)}}for(l=0;l<t;l++){x=f.__webGLObjects[l];if(x.render){u=x.object;x=x.buffer;d(u);this.renderPass(p,A,C,u,x,THREE.NormalBlending,false)}}for(l=0;l<w;l++){u=f.__webGLObjectsImmediate[l].object;if(u.visible){d(u);this.renderPassImmediate(p,A,C,u,THREE.NormalBlending,false)}}for(l=0;l<t;l++){x=f.__webGLObjects[l];if(x.render){u=x.object;x=x.buffer;d(u);this.renderPass(p,A,C,u,x,THREE.AdditiveBlending,false);this.renderPass(p,A,C,u,x,THREE.SubtractiveBlending,false);this.renderPass(p,A,C,u,x,THREE.AdditiveBlending,
-true);this.renderPass(p,A,C,u,x,THREE.SubtractiveBlending,true);this.renderPass(p,A,C,u,x,THREE.NormalBlending,true);this.renderPass(p,A,C,u,x,THREE.BillboardBlending,false)}}for(l=0;l<w;l++){u=f.__webGLObjectsImmediate[l].object;if(u.visible){d(u);this.renderPassImmediate(p,A,C,u,THREE.NormalBlending,true)}}if(j&&j.min_filter!==THREE.NearestFilter&&j.min_filter!==THREE.LinearFilter){b.bindTexture(b.TEXTURE_2D,j.__webGLTexture);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}};this.initWebGLObjects=
-function(f,p){function j(E,D,I,S){if(E[D]==undefined){f.__webGLObjects.push({buffer:I,object:S});E[D]=1}}function l(E,D,I){if(E[D]==undefined){f.__webGLObjectsImmediate.push({object:I});E[D]=1}}var t,w,x,u,A,C,F;if(!f.__webGLObjects){f.__webGLObjects=[];f.__webGLObjectsMap={};f.__webGLObjectsImmediate=[]}t=0;for(w=f.objects.length;t<w;t++){x=f.objects[t];A=x.geometry;if(f.__webGLObjectsMap[x.id]==undefined){f.__webGLObjectsMap[x.id]={};x._modelViewMatrix=new THREE.Matrix4;x._normalMatrixArray=new Float32Array(9);
-x._modelViewMatrixArray=new Float32Array(16);x._objectMatrixArray=new Float32Array(16);x.matrix.flattenToArray(x._objectMatrixArray)}F=f.__webGLObjectsMap[x.id];if(x instanceof THREE.Mesh){for(u in A.geometryChunks){C=A.geometryChunks[u];if(!C.__webGLVertexBuffer){this.createMeshBuffers(C);this.initMeshBuffers(C,x);A.__dirtyVertices=true;A.__dirtyElements=true;A.__dirtyUvs=true;A.__dirtyNormals=true;A.__dirtyTangents=true;A.__dirtyColors=true}if(A.__dirtyVertices||A.__dirtyElements||A.__dirtyUvs||
-A.__dirtyNormals||A.__dirtyColors||A.__dirtyTangents)this.setMeshBuffers(C,x,b.DYNAMIC_DRAW);j(F,u,C,x)}A.__dirtyVertices=false;A.__dirtyElements=false;A.__dirtyUvs=false;A.__dirtyNormals=false;A.__dirtyTangents=false;A.__dirtyColors=false}else if(x instanceof THREE.Line){if(!A.__webGLVertexBuffer){this.createLineBuffers(A);this.initLineBuffers(A);A.__dirtyVertices=true;A.__dirtyColors=true}if(A.__dirtyVertices||A.__dirtyColors)this.setLineBuffers(A,b.DYNAMIC_DRAW);j(F,0,A,x);A.__dirtyVertices=false;
-A.__dirtyColors=false}else if(x instanceof THREE.ParticleSystem){if(!A.__webGLVertexBuffer){this.createParticleBuffers(A);this.initParticleBuffers(A);A.__dirtyVertices=true;A.__dirtyColors=true}if(A.__dirtyVertices||A.__dirtyColors||x.sortParticles)this.setParticleBuffers(A,b.DYNAMIC_DRAW,x,p);j(F,0,A,x);A.__dirtyVertices=false;A.__dirtyColors=false}else x instanceof THREE.MarchingCubes&&l(F,0,x)}};this.removeObject=function(f,p){var j,l;for(j=f.__webGLObjects.length-1;j>=0;j--){l=f.__webGLObjects[j].object;
-p==l&&f.__webGLObjects.splice(j,1)}};this.setupMatrices=function(f,p){f._modelViewMatrix.multiplyToArray(p.matrix,f.matrix,f._modelViewMatrixArray);f._normalMatrix=THREE.Matrix4.makeInvert3x3(f._modelViewMatrix).transposeIntoArray(f._normalMatrixArray)};this.loadMatrices=function(f,p){b.uniformMatrix4fv(f.uniforms.viewMatrix,false,v);b.uniformMatrix4fv(f.uniforms.projectionMatrix,false,y);b.uniformMatrix4fv(f.uniforms.modelViewMatrix,false,p._modelViewMatrixArray);b.uniformMatrix3fv(f.uniforms.normalMatrix,
-false,p._normalMatrixArray);b.uniformMatrix4fv(f.uniforms.objectMatrix,false,p._objectMatrixArray)};this.loadCamera=function(f,p){b.uniform3f(f.uniforms.cameraPosition,p.position.x,p.position.y,p.position.z)};this.setDepthTest=function(f){f?b.enable(b.DEPTH_TEST):b.disable(b.DEPTH_TEST)};this.setBlending=function(f){switch(f){case THREE.AdditiveBlending:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE);break;case THREE.SubtractiveBlending:b.blendFunc(b.DST_COLOR,b.ZERO);break;case THREE.BillboardBlending:b.blendEquation(b.FUNC_ADD);
-b.blendFunc(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA);break;default:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(f,p){if(f){!p||p=="ccw"?b.frontFace(b.CCW):b.frontFace(b.CW);if(f=="back")b.cullFace(b.BACK);else f=="front"?b.cullFace(b.FRONT):b.cullFace(b.FRONT_AND_BACK);b.enable(b.CULL_FACE)}else b.disable(b.CULL_FACE)};this.supportsVertexTextures=function(){return b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}};
-THREE.Snippets={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );\n#endif",
-envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube env_map;\nuniform int combine;\n#endif",envmap_fragment:"#ifdef USE_ENVMAP\nvec4 cubeColor = textureCube( env_map, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = vec4( mix( gl_FragColor.xyz, cubeColor.xyz, reflectivity ), opacity );\n} else {\ngl_FragColor = gl_FragColor * cubeColor;\n}\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refraction_ratio;\nuniform bool useRefract;\n#endif",
-envmap_vertex:"#ifdef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nif ( useRefract ) {\nvReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refraction_ratio );\n} else {\nvReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );\n}\n#endif",map_particle_pars_fragment:"#ifdef USE_MAP\nuniform sampler2D map;\n#endif",
-map_particle_fragment:"#ifdef USE_MAP\ngl_FragColor = gl_FragColor * texture2D( map, gl_PointCoord );\n#endif",map_pars_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\n#endif",map_fragment:"#ifdef USE_MAP\ngl_FragColor = gl_FragColor * texture2D( map, vUv );\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv;\n#endif",lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\nvarying vec2 vUv2;\nuniform sampler2D light_map;\n#endif",lightmap_pars_vertex:"#ifdef USE_LIGHTMAP\nvarying vec2 vUv2;\n#endif",
-lightmap_fragment:"#ifdef USE_LIGHTMAP\ngl_FragColor = gl_FragColor * texture2D( light_map, vUv2 );\n#endif",lightmap_vertex:"#ifdef USE_LIGHTMAP\nvUv2 = uv2;\n#endif",lights_pars_vertex:"uniform bool enableLighting;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n#ifdef PHONG\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\n#endif",
+"uv","uv2","tangent","color"];j=0;for(A=l.length;j<A;j++){p=l[j];f.attributes[p]=b.getAttribLocation(f,p)}}};this.setProgram=function(f,p,j,l,t){this.initMaterial(l,p,j);var w=l.program;if(w!=m){b.useProgram(w);m=w}if(l instanceof THREE.MeshShaderMaterial||l instanceof THREE.MeshPhongMaterial||l.env_map)this.loadCamera(w,f);this.loadMatrices(w,t);if(l instanceof THREE.MeshPhongMaterial||l instanceof THREE.MeshLambertMaterial){this.setupLights(w,p);p=this.lights;l.uniforms.enableLighting.value=p.directional.length+
+p.point.length;l.uniforms.ambientLightColor.value=p.ambient;l.uniforms.directionalLightColor.value=p.directional.colors;l.uniforms.directionalLightDirection.value=p.directional.positions;l.uniforms.pointLightColor.value=p.point.colors;l.uniforms.pointLightPosition.value=p.point.positions}if(l instanceof THREE.MeshBasicMaterial||l instanceof THREE.MeshLambertMaterial||l instanceof THREE.MeshPhongMaterial){l.uniforms.diffuse.value.setRGB(l.color.r*l.opacity,l.color.g*l.opacity,l.color.b*l.opacity);
+l.uniforms.opacity.value=l.opacity;l.uniforms.map.texture=l.map;l.uniforms.light_map.texture=l.light_map;l.uniforms.env_map.texture=l.env_map;l.uniforms.reflectivity.value=l.reflectivity;l.uniforms.refraction_ratio.value=l.refraction_ratio;l.uniforms.combine.value=l.combine;l.uniforms.useRefract.value=l.env_map&&l.env_map.mapping instanceof THREE.CubeRefractionMapping;if(j){l.uniforms.fogColor.value.setHex(j.color.hex);if(j instanceof THREE.Fog){l.uniforms.fogNear.value=j.near;l.uniforms.fogFar.value=
+j.far}else if(j instanceof THREE.FogExp2)l.uniforms.fogDensity.value=j.density}}if(l instanceof THREE.LineBasicMaterial){l.uniforms.diffuse.value.setRGB(l.color.r*l.opacity,l.color.g*l.opacity,l.color.b*l.opacity);l.uniforms.opacity.value=l.opacity;if(j){l.uniforms.fogColor.value.setHex(j.color.hex);if(j instanceof THREE.Fog){l.uniforms.fogNear.value=j.near;l.uniforms.fogFar.value=j.far}else if(j instanceof THREE.FogExp2)l.uniforms.fogDensity.value=j.density}}if(l instanceof THREE.ParticleBasicMaterial){l.uniforms.psColor.value.setRGB(l.color.r*
+l.opacity,l.color.g*l.opacity,l.color.b*l.opacity);l.uniforms.opacity.value=l.opacity;l.uniforms.size.value=l.size;l.uniforms.map.texture=l.map;if(j){l.uniforms.fogColor.value.setHex(j.color.hex);if(j instanceof THREE.Fog){l.uniforms.fogNear.value=j.near;l.uniforms.fogFar.value=j.far}else if(j instanceof THREE.FogExp2)l.uniforms.fogDensity.value=j.density}}if(l instanceof THREE.MeshPhongMaterial){l.uniforms.ambient.value.setRGB(l.ambient.r,l.ambient.g,l.ambient.b);l.uniforms.specular.value.setRGB(l.specular.r,
+l.specular.g,l.specular.b);l.uniforms.shininess.value=l.shininess}if(l instanceof THREE.MeshDepthMaterial){l.uniforms.mNear.value=f.near;l.uniforms.mFar.value=f.far;l.uniforms.opacity.value=l.opacity}if(l instanceof THREE.MeshNormalMaterial)l.uniforms.opacity.value=l.opacity;f=l.uniforms;for(var x in f)if(t=w.uniforms[x]){l=f[x];p=l.type;j=l.value;if(p=="i")b.uniform1i(t,j);else if(p=="f")b.uniform1f(t,j);else if(p=="fv1")b.uniform1fv(t,j);else if(p=="fv")b.uniform3fv(t,j);else if(p=="v2")b.uniform2f(t,
+j.x,j.y);else if(p=="v3")b.uniform3f(t,j.x,j.y,j.z);else if(p=="c")b.uniform3f(t,j.r,j.g,j.b);else if(p=="t"){b.uniform1i(t,j);if(l=l.texture)if(l.image instanceof Array&&l.image.length==6){l=l;j=j;if(l.image.length==6){if(!l.image.__webGLTextureCube&&!l.image.__cubeMapInitialized&&l.image.loadCount==6){l.image.__webGLTextureCube=b.createTexture();b.bindTexture(b.TEXTURE_CUBE_MAP,l.image.__webGLTextureCube);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,
+b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_MAG_FILTER,b.LINEAR);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_MIN_FILTER,b.LINEAR_MIPMAP_LINEAR);for(p=0;p<6;++p)b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X+p,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,l.image[p]);b.generateMipmap(b.TEXTURE_CUBE_MAP);b.bindTexture(b.TEXTURE_CUBE_MAP,null);l.image.__cubeMapInitialized=true}b.activeTexture(b.TEXTURE0+j);b.bindTexture(b.TEXTURE_CUBE_MAP,l.image.__webGLTextureCube)}}else{l=l;j=j;if(!l.__webGLTexture&&
+l.image.loaded){l.__webGLTexture=b.createTexture();b.bindTexture(b.TEXTURE_2D,l.__webGLTexture);b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,l.image);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,h(l.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,h(l.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,h(l.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,h(l.min_filter));b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}b.activeTexture(b.TEXTURE0+
+j);b.bindTexture(b.TEXTURE_2D,l.__webGLTexture)}}}return w};this.renderBuffer=function(f,p,j,l,t,w){f=this.setProgram(f,p,j,l,w).attributes;b.bindBuffer(b.ARRAY_BUFFER,t.__webGLVertexBuffer);b.vertexAttribPointer(f.position,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.position);if(f.color>=0){b.bindBuffer(b.ARRAY_BUFFER,t.__webGLColorBuffer);b.vertexAttribPointer(f.color,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.color)}if(f.normal>=0){b.bindBuffer(b.ARRAY_BUFFER,t.__webGLNormalBuffer);
+b.vertexAttribPointer(f.normal,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.normal)}if(f.tangent>=0){b.bindBuffer(b.ARRAY_BUFFER,t.__webGLTangentBuffer);b.vertexAttribPointer(f.tangent,4,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.tangent)}if(f.uv>=0)if(t.__webGLUVBuffer){b.bindBuffer(b.ARRAY_BUFFER,t.__webGLUVBuffer);b.vertexAttribPointer(f.uv,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.uv)}else b.disableVertexAttribArray(f.uv);if(f.uv2>=0)if(t.__webGLUV2Buffer){b.bindBuffer(b.ARRAY_BUFFER,
+t.__webGLUV2Buffer);b.vertexAttribPointer(f.uv2,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.uv2)}else b.disableVertexAttribArray(f.uv2);if(w instanceof THREE.Mesh)if(l.wireframe){b.lineWidth(l.wireframe_linewidth);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,t.__webGLLineBuffer);b.drawElements(b.LINES,t.__webGLLineCount,b.UNSIGNED_SHORT,0)}else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,t.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,t.__webGLFaceCount,b.UNSIGNED_SHORT,0)}else if(w instanceof THREE.Line){w=
+w.type==THREE.LineStrip?b.LINE_STRIP:b.LINES;b.lineWidth(l.linewidth);b.drawArrays(w,0,t.__webGLLineCount)}else w instanceof THREE.ParticleSystem&&b.drawArrays(b.POINTS,0,t.__webGLParticleCount)};this.renderPass=function(f,p,j,l,t,w,x){var u,A,C,F,E;C=0;for(F=l.materials.length;C<F;C++){u=l.materials[C];if(u instanceof THREE.MeshFaceMaterial){u=0;for(A=t.materials.length;u<A;u++)if((E=t.materials[u])&&E.blending==w&&E.opacity<1==x){this.setBlending(E.blending);this.setDepthTest(E.depth_test);this.renderBuffer(f,
+p,j,E,t,l)}}else if((E=u)&&E.blending==w&&E.opacity<1==x){this.setBlending(E.blending);this.setDepthTest(E.depth_test);this.renderBuffer(f,p,j,E,t,l)}}};this.renderPassImmediate=function(f,p,j,l,t,w){var x,u,A,C;x=0;for(u=l.materials.length;x<u;x++)if((A=l.materials[x])&&A.blending==t&&A.opacity<1==w){this.setBlending(A.blending);this.setDepthTest(A.depth_test);C=this.setProgram(f,p,j,A,l);l.render(function(F){var E=C;if(!F.__webGLVertexBuffer)F.__webGLVertexBuffer=b.createBuffer();if(!F.__webGLNormalBuffer)F.__webGLNormalBuffer=
+b.createBuffer();if(F.hasPos){b.bindBuffer(b.ARRAY_BUFFER,F.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,F.positionArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(E.attributes.position);b.vertexAttribPointer(E.attributes.position,3,b.FLOAT,false,0,0)}if(F.hasNormal){b.bindBuffer(b.ARRAY_BUFFER,F.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,F.normalArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(E.attributes.normal);b.vertexAttribPointer(E.attributes.normal,3,b.FLOAT,false,0,0)}b.drawArrays(b.TRIANGLES,
+0,F.count);F.count=0})}};this.render=function(f,p,j,l){var t,w,x,u,A=f.lights,C=f.fog;p.autoUpdateMatrix&&p.updateMatrix();p.matrix.flattenToArray(v);p.projectionMatrix.flattenToArray(y);o.multiply(p.projectionMatrix,p.matrix);n[0].set(o.n41-o.n11,o.n42-o.n12,o.n43-o.n13,o.n44-o.n14);n[1].set(o.n41+o.n11,o.n42+o.n12,o.n43+o.n13,o.n44+o.n14);n[2].set(o.n41+o.n21,o.n42+o.n22,o.n43+o.n23,o.n44+o.n24);n[3].set(o.n41-o.n21,o.n42-o.n22,o.n43-o.n23,o.n44-o.n24);n[4].set(o.n41-o.n31,o.n42-o.n32,o.n43-o.n33,
+o.n44-o.n34);n[5].set(o.n41+o.n31,o.n42+o.n32,o.n43+o.n33,o.n44+o.n34);for(t=0;t<5;t++){u=n[t];u.divideScalar(Math.sqrt(u.x*u.x+u.y*u.y+u.z*u.z))}this.initWebGLObjects(f,p);l=l!==undefined?l:true;if(j&&!j.__webGLFramebuffer){j.__webGLFramebuffer=b.createFramebuffer();j.__webGLRenderbuffer=b.createRenderbuffer();j.__webGLTexture=b.createTexture();b.bindRenderbuffer(b.RENDERBUFFER,j.__webGLRenderbuffer);b.renderbufferStorage(b.RENDERBUFFER,b.DEPTH_COMPONENT16,j.width,j.height);b.bindTexture(b.TEXTURE_2D,
+j.__webGLTexture);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,h(j.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,h(j.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,h(j.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,h(j.min_filter));b.texImage2D(b.TEXTURE_2D,0,h(j.format),j.width,j.height,0,h(j.format),h(j.type),null);b.bindFramebuffer(b.FRAMEBUFFER,j.__webGLFramebuffer);b.framebufferTexture2D(b.FRAMEBUFFER,b.COLOR_ATTACHMENT0,b.TEXTURE_2D,j.__webGLTexture,0);
+b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,j.__webGLRenderbuffer);b.bindTexture(b.TEXTURE_2D,null);b.bindRenderbuffer(b.RENDERBUFFER,null);b.bindFramebuffer(b.FRAMEBUFFER,null)}if(j){t=j.__webGLFramebuffer;u=j.width;x=j.height}else{t=null;u=g.width;x=g.height}if(t!=k){b.bindFramebuffer(b.FRAMEBUFFER,t);b.viewport(0,0,u,x);l&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);k=t}this.autoClear&&this.clear();t=f.__webGLObjects.length;for(l=0;l<t;l++){x=f.__webGLObjects[l];
+u=x.object;if(w=u.visible){if(!(w=!(u instanceof THREE.Mesh)))a:{w=void 0;for(var F=u.matrix,E=-u.geometry.boundingSphere.radius*Math.max(u.scale.x,Math.max(u.scale.y,u.scale.z)),D=0;D<6;D++){w=n[D].x*F.n14+n[D].y*F.n24+n[D].z*F.n34+n[D].w;if(w<=E){w=false;break a}}w=true}w=w}if(w){if(u.autoUpdateMatrix){u.updateMatrix();u.matrix.flattenToArray(u._objectMatrixArray)}this.setupMatrices(u,p);x.render=true}else x.render=false}w=f.__webGLObjectsImmediate.length;for(l=0;l<w;l++){u=f.__webGLObjectsImmediate[l].object;
+if(u.visible){if(u.autoUpdateMatrix){u.updateMatrix();u.matrix.flattenToArray(u._objectMatrixArray)}this.setupMatrices(u,p)}}for(l=0;l<t;l++){x=f.__webGLObjects[l];if(x.render){u=x.object;x=x.buffer;d(u);this.renderPass(p,A,C,u,x,THREE.NormalBlending,false)}}for(l=0;l<w;l++){u=f.__webGLObjectsImmediate[l].object;if(u.visible){d(u);this.renderPassImmediate(p,A,C,u,THREE.NormalBlending,false)}}for(l=0;l<t;l++){x=f.__webGLObjects[l];if(x.render){u=x.object;x=x.buffer;d(u);this.renderPass(p,A,C,u,x,THREE.AdditiveBlending,
+false);this.renderPass(p,A,C,u,x,THREE.SubtractiveBlending,false);this.renderPass(p,A,C,u,x,THREE.AdditiveBlending,true);this.renderPass(p,A,C,u,x,THREE.SubtractiveBlending,true);this.renderPass(p,A,C,u,x,THREE.NormalBlending,true);this.renderPass(p,A,C,u,x,THREE.BillboardBlending,false)}}for(l=0;l<w;l++){u=f.__webGLObjectsImmediate[l].object;if(u.visible){d(u);this.renderPassImmediate(p,A,C,u,THREE.NormalBlending,true)}}if(j&&j.min_filter!==THREE.NearestFilter&&j.min_filter!==THREE.LinearFilter){b.bindTexture(b.TEXTURE_2D,
+j.__webGLTexture);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}};this.initWebGLObjects=function(f,p){function j(E,D,I,S){if(E[D]==undefined){f.__webGLObjects.push({buffer:I,object:S});E[D]=1}}function l(E,D,I){if(E[D]==undefined){f.__webGLObjectsImmediate.push({object:I});E[D]=1}}var t,w,x,u,A,C,F;if(!f.__webGLObjects){f.__webGLObjects=[];f.__webGLObjectsMap={};f.__webGLObjectsImmediate=[]}t=0;for(w=f.objects.length;t<w;t++){x=f.objects[t];A=x.geometry;if(f.__webGLObjectsMap[x.id]==
+undefined){f.__webGLObjectsMap[x.id]={};x._modelViewMatrix=new THREE.Matrix4;x._normalMatrixArray=new Float32Array(9);x._modelViewMatrixArray=new Float32Array(16);x._objectMatrixArray=new Float32Array(16);x.matrix.flattenToArray(x._objectMatrixArray)}F=f.__webGLObjectsMap[x.id];if(x instanceof THREE.Mesh){for(u in A.geometryChunks){C=A.geometryChunks[u];if(!C.__webGLVertexBuffer){this.createMeshBuffers(C);this.initMeshBuffers(C,x);A.__dirtyVertices=true;A.__dirtyElements=true;A.__dirtyUvs=true;A.__dirtyNormals=
+true;A.__dirtyTangents=true;A.__dirtyColors=true}if(A.__dirtyVertices||A.__dirtyElements||A.__dirtyUvs||A.__dirtyNormals||A.__dirtyColors||A.__dirtyTangents)this.setMeshBuffers(C,x,b.DYNAMIC_DRAW);j(F,u,C,x)}A.__dirtyVertices=false;A.__dirtyElements=false;A.__dirtyUvs=false;A.__dirtyNormals=false;A.__dirtyTangents=false;A.__dirtyColors=false}else if(x instanceof THREE.Line){if(!A.__webGLVertexBuffer){this.createLineBuffers(A);this.initLineBuffers(A);A.__dirtyVertices=true;A.__dirtyColors=true}if(A.__dirtyVertices||
+A.__dirtyColors)this.setLineBuffers(A,b.DYNAMIC_DRAW);j(F,0,A,x);A.__dirtyVertices=false;A.__dirtyColors=false}else if(x instanceof THREE.ParticleSystem){if(!A.__webGLVertexBuffer){this.createParticleBuffers(A);this.initParticleBuffers(A);A.__dirtyVertices=true;A.__dirtyColors=true}if(A.__dirtyVertices||A.__dirtyColors||x.sortParticles)this.setParticleBuffers(A,b.DYNAMIC_DRAW,x,p);j(F,0,A,x);A.__dirtyVertices=false;A.__dirtyColors=false}else x instanceof THREE.MarchingCubes&&l(F,0,x)}};this.removeObject=
+function(f,p){var j,l;for(j=f.__webGLObjects.length-1;j>=0;j--){l=f.__webGLObjects[j].object;p==l&&f.__webGLObjects.splice(j,1)}};this.setupMatrices=function(f,p){f._modelViewMatrix.multiplyToArray(p.matrix,f.matrix,f._modelViewMatrixArray);f._normalMatrix=THREE.Matrix4.makeInvert3x3(f._modelViewMatrix).transposeIntoArray(f._normalMatrixArray)};this.loadMatrices=function(f,p){b.uniformMatrix4fv(f.uniforms.viewMatrix,false,v);b.uniformMatrix4fv(f.uniforms.projectionMatrix,false,y);b.uniformMatrix4fv(f.uniforms.modelViewMatrix,
+false,p._modelViewMatrixArray);b.uniformMatrix3fv(f.uniforms.normalMatrix,false,p._normalMatrixArray);b.uniformMatrix4fv(f.uniforms.objectMatrix,false,p._objectMatrixArray)};this.loadCamera=function(f,p){b.uniform3f(f.uniforms.cameraPosition,p.position.x,p.position.y,p.position.z)};this.setDepthTest=function(f){f?b.enable(b.DEPTH_TEST):b.disable(b.DEPTH_TEST)};this.setBlending=function(f){switch(f){case THREE.AdditiveBlending:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE);break;case THREE.SubtractiveBlending:b.blendFunc(b.DST_COLOR,
+b.ZERO);break;case THREE.BillboardBlending:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA);break;default:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(f,p){if(f){!p||p=="ccw"?b.frontFace(b.CCW):b.frontFace(b.CW);if(f=="back")b.cullFace(b.BACK);else f=="front"?b.cullFace(b.FRONT):b.cullFace(b.FRONT_AND_BACK);b.enable(b.CULL_FACE)}else b.disable(b.CULL_FACE)};this.supportsVertexTextures=function(){return b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>
+0}};
+THREE.Snippets={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );\n#endif",envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube env_map;\nuniform int combine;\n#endif",
+envmap_fragment:"#ifdef USE_ENVMAP\nvec4 cubeColor = textureCube( env_map, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = vec4( mix( gl_FragColor.xyz, cubeColor.xyz, reflectivity ), opacity );\n} else {\ngl_FragColor = gl_FragColor * cubeColor;\n}\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refraction_ratio;\nuniform bool useRefract;\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nif ( useRefract ) {\nvReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refraction_ratio );\n} else {\nvReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );\n}\n#endif",
+map_particle_pars_fragment:"#ifdef USE_MAP\nuniform sampler2D map;\n#endif",map_particle_fragment:"#ifdef USE_MAP\ngl_FragColor = gl_FragColor * texture2D( map, gl_PointCoord );\n#endif",map_pars_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\n#endif",map_fragment:"#ifdef USE_MAP\ngl_FragColor = gl_FragColor * texture2D( map, vUv );\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv;\n#endif",lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\nvarying vec2 vUv2;\nuniform sampler2D light_map;\n#endif",
+lightmap_pars_vertex:"#ifdef USE_LIGHTMAP\nvarying vec2 vUv2;\n#endif",lightmap_fragment:"#ifdef USE_LIGHTMAP\ngl_FragColor = gl_FragColor * texture2D( light_map, vUv2 );\n#endif",lightmap_vertex:"#ifdef USE_LIGHTMAP\nvUv2 = uv2;\n#endif",lights_pars_vertex:"uniform bool enableLighting;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n#ifdef PHONG\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\n#endif",
 lights_vertex:"if ( !enableLighting ) {\nvLightWeighting = vec3( 1.0 );\n} else {\nvLightWeighting = ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nfloat directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );\nvLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;\n}\n#endif\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 pointLightVector = normalize( lPosition.xyz - mvPosition.xyz );\nfloat pointLightWeighting = max( dot( transformedNormal, pointLightVector ), 0.0 );\nvLightWeighting += pointLightColor[ i ] * pointLightWeighting;\n#ifdef PHONG\nvPointLightVector[ i ] = pointLightVector;\n#endif\n}\n#endif\n}",
 lights_pars_fragment:"#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\nvarying vec3 vViewPosition;\nvarying vec3 vNormal;",lights_fragment:"vec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );\nvec4 mColor = vec4( diffuse, opacity );\nvec4 mSpecular = vec4( specular, opacity );\n#if MAX_POINT_LIGHTS > 0\nvec4 pointDiffuse  = vec4( 0.0 );\nvec4 pointSpecular = vec4( 0.0 );\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec3 pointVector = normalize( vPointLightVector[ i ] );\nvec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );\nfloat pointDotNormalHalf = dot( normal, pointHalfVector );\nfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );\nfloat pointSpecularWeight = 0.0;\nif ( pointDotNormalHalf >= 0.0 )\npointSpecularWeight = pow( pointDotNormalHalf, shininess );\npointDiffuse  += mColor * pointDiffuseWeight;\npointSpecular += mSpecular * pointSpecularWeight;\n}\n#endif\n#if MAX_DIR_LIGHTS > 0\nvec4 dirDiffuse  = vec4( 0.0 );\nvec4 dirSpecular = vec4( 0.0 );\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nvec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );\nfloat dirDotNormalHalf = dot( normal, dirHalfVector );\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\nfloat dirSpecularWeight = 0.0;\nif ( dirDotNormalHalf >= 0.0 )\ndirSpecularWeight = pow( dirDotNormalHalf, shininess );\ndirDiffuse  += mColor * dirDiffuseWeight;\ndirSpecular += mSpecular * dirSpecularWeight;\n}\n#endif\nvec4 totalLight = vec4( ambient, opacity );\n#if MAX_DIR_LIGHTS > 0\ntotalLight += dirDiffuse + dirSpecular;\n#endif\n#if MAX_POINT_LIGHTS > 0\ntotalLight += pointDiffuse + pointSpecular;\n#endif\ngl_FragColor = gl_FragColor * totalLight;",
 color_pars_fragment:"#ifdef USE_COLOR\nvarying vec3 vColor;\n#endif",color_fragment:"#ifdef USE_COLOR\ngl_FragColor = gl_FragColor * vec4( vColor, opacity );\n#endif",color_pars_vertex:"#ifdef USE_COLOR\nvarying vec3 vColor;\n#endif",color_vertex:"#ifdef USE_COLOR\nvColor = color;\n#endif"};

+ 11 - 12
src/core/Matrix4.js

@@ -567,21 +567,20 @@ THREE.Matrix4.makeInvert3x3 = function ( m1 ) {
 	// input:  THREE.Matrix4, output: THREE.Matrix3
 	// ( based on http://code.google.com/p/webgl-mjs/ )
 
-	var m = m1.flatten(),
-		m33 = m1.m33,
+	var m33 = m1.m33,
 		m33m = m33.m,
 
-	a11 =   m[ 10 ] * m[ 5 ] - m[ 6 ] * m[ 9 ],
-	a21 = - m[ 10 ] * m[ 1 ] + m[ 2 ] * m[ 9 ],
-	a31 =   m[ 6 ]  * m[ 1 ] - m[ 2 ] * m[ 5 ],
-	a12 = - m[ 10 ] * m[ 4 ] + m[ 6 ] * m[ 8 ],
-	a22 =   m[ 10 ] * m[ 0 ] - m[ 2 ] * m[ 8 ],
-	a32 = - m[ 6 ]  * m[ 0 ] + m[ 2 ] * m[ 4 ],
-	a13 =   m[ 9 ]  * m[ 4 ] - m[ 5 ] * m[ 8 ],
-	a23 = - m[ 9 ]  * m[ 0 ] + m[ 1 ] * m[ 8 ],
-	a33 =   m[ 5 ]  * m[ 0 ] - m[ 1 ] * m[ 4 ],
+	a11 =   m1.n33 * m1.n22 - m1.n32 * m1.n23,
+	a21 = - m1.n33 * m1.n21 + m1.n31 * m1.n23,
+	a31 =   m1.n32 * m1.n21 - m1.n31 * m1.n22,
+	a12 = - m1.n33 * m1.n12 + m1.n32 * m1.n13,
+	a22 =   m1.n33 * m1.n11 - m1.n31 * m1.n13,
+	a32 = - m1.n32 * m1.n11 + m1.n31 * m1.n12,
+	a13 =   m1.n23 * m1.n12 - m1.n22 * m1.n13,
+	a23 = - m1.n23 * m1.n11 + m1.n21 * m1.n13,
+	a33 =   m1.n22 * m1.n11 - m1.n21 * m1.n12,
 	
-	det = m[ 0 ]  * a11 + m[ 1 ] * a12 + m[ 2 ] * a13,
+	det = m1.n11 * a11 + m1.n21 * a12 + m1.n31 * a13,
 	
 	idet;
 

+ 11 - 1
src/renderers/WebGLRenderer.js

@@ -1085,7 +1085,17 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		}
 
-		this.loadCamera( program, camera );
+		// only Phong and environment mapping use cameraPosition uniform
+		// shader material also gets it for the sake of genericity
+		
+		if ( material instanceof THREE.MeshShaderMaterial ||
+			 material instanceof THREE.MeshPhongMaterial ||
+			 material.env_map ) {
+			
+			this.loadCamera( program, camera );
+			
+		}
+		
 		this.loadMatrices( program, object );
 
 		if ( material instanceof THREE.MeshPhongMaterial ||