فهرست منبع

Refactored default uniforms out of Fresnel shader and ubershader into buildProgram.

Also yet another fix for car demo load progress.
alteredq 15 سال پیش
والد
کامیت
8f06a4f37d
7فایلهای تغییر یافته به همراه58 افزوده شده و 63 حذف شده
  1. 9 10
      build/Three.js
  2. 9 10
      build/ThreeDebug.js
  3. 10 11
      build/ThreeExtras.js
  4. 1 1
      examples/materials_cars.html
  5. 3 9
      src/extras/ShaderUtils.js
  6. 1 1
      src/materials/MeshShaderMaterial.js
  7. 25 21
      src/renderers/WebGLRenderer.js

+ 9 - 10
build/Three.js

@@ -123,13 +123,12 @@ x.setAttribute("y1",V.positionScreen.y);x.setAttribute("x2",ba.positionScreen.x)
 -H;F.positionScreen.x*=E;F.positionScreen.y*=-H;P.positionScreen.x*=E;P.positionScreen.y*=-H;s.addPoint(w.positionScreen.x,w.positionScreen.y);s.addPoint(F.positionScreen.x,F.positionScreen.y);s.addPoint(P.positionScreen.x,P.positionScreen.y);if(O.instersects(s)){C=0;for(A=K.meshMaterial.length;C<A;){L=K.meshMaterial[C++];if(L instanceof THREE.MeshFaceMaterial){V=0;for(ba=K.faceMaterial.length;V<ba;)(L=K.faceMaterial[V++])&&c(w,F,P,K,L,p)}else L&&c(w,F,P,K,L,p)}}}else if(K instanceof THREE.RenderableFace4){w=
 K.v1;F=K.v2;P=K.v3;N=K.v4;w.positionScreen.x*=E;w.positionScreen.y*=-H;F.positionScreen.x*=E;F.positionScreen.y*=-H;P.positionScreen.x*=E;P.positionScreen.y*=-H;N.positionScreen.x*=E;N.positionScreen.y*=-H;s.addPoint(w.positionScreen.x,w.positionScreen.y);s.addPoint(F.positionScreen.x,F.positionScreen.y);s.addPoint(P.positionScreen.x,P.positionScreen.y);s.addPoint(N.positionScreen.x,N.positionScreen.y);if(O.instersects(s)){C=0;for(A=K.meshMaterial.length;C<A;){L=K.meshMaterial[C++];if(L instanceof
 THREE.MeshFaceMaterial){V=0;for(ba=K.faceMaterial.length;V<ba;)(L=K.faceMaterial[V++])&&e(w,F,P,N,K,L,p)}else L&&e(w,F,P,N,K,L,p)}}}}}};
-THREE.WebGLRenderer=function(a){function c(f,d){var i=b.createProgram();b.attachShader(i,h("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\n"+f));b.attachShader(i,h("vertex",d));b.linkProgram(i);if(!b.getProgramParameter(i,b.LINK_STATUS)){alert("Could not initialise shaders");alert("VALIDATE_STATUS: "+b.getProgramParameter(i,b.VALIDATE_STATUS));alert(b.getError())}i.uniforms={};return i}function e(f,d){var i,o,k;i=0;for(o=d.length;i<o;i++){k=d[i];f.uniforms[k]=b.getUniformLocation(f,k)}}
-function g(f){f.position=b.getAttribLocation(f,"position");b.enableVertexAttribArray(f.position);f.normal=b.getAttribLocation(f,"normal");b.enableVertexAttribArray(f.normal);f.uv=b.getAttribLocation(f,"uv");b.enableVertexAttribArray(f.uv)}function h(f,d){var i;if(f=="fragment")i=b.createShader(b.FRAGMENT_SHADER);else if(f=="vertex")i=b.createShader(b.VERTEX_SHADER);b.shaderSource(i,d);b.compileShader(i);if(!b.getShaderParameter(i,b.COMPILE_STATUS)){alert(b.getShaderInfoLog(i));return null}return i}
-function q(f){switch(f){case THREE.Repeat:return b.REPEAT;case THREE.ClampToEdge:return b.CLAMP_TO_EDGE;case THREE.MirroredRepeat:return b.MIRRORED_REPEAT}return 0}var m=document.createElement("canvas"),b,l,y,E=new THREE.Matrix4,H,w=new Float32Array(16),F=new Float32Array(16),P=new Float32Array(16),N=new Float32Array(9),O=new Float32Array(16);a=function(f,d){if(f){var i,o,k,j=pointLights=maxDirLights=maxPointLights=0;i=0;for(o=f.lights.length;i<o;i++){k=f.lights[i];k instanceof THREE.DirectionalLight&&
-j++;k instanceof THREE.PointLight&&pointLights++}if(pointLights+j<=d){maxDirLights=j;maxPointLights=pointLights}else{maxDirLights=Math.ceil(d*j/(pointLights+j));maxPointLights=d-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:d-1}}(a,4);this.domElement=m;this.autoClear=true;try{b=m.getContext("experimental-webgl",{antialias:true})}catch(s){}if(!b){alert("WebGL not supported");throw"cannot create webgl context";}b.clearColor(0,0,0,1);b.clearDepth(1);b.enable(b.DEPTH_TEST);
-b.depthFunc(b.LEQUAL);b.frontFace(b.CCW);b.cullFace(b.BACK);b.enable(b.CULL_FACE);b.enable(b.BLEND);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA);b.clearColor(0,0,0,0);(function(f,d){var i=[f?"#define MAX_DIR_LIGHTS "+f:"",d?"#define MAX_POINT_LIGHTS "+d:"","attribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\nuniform vec3 cameraPosition;\nuniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",
-f?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",f?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",d?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",d?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","uniform mat4 objMatrix;\nuniform mat4 viewMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat3 normalMatrix;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",d?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":
-"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform float mRefractionRatio;\nvoid main(void) {\nvec4 mPosition = objMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 nWorld = mat3( objMatrix[0].xyz, objMatrix[1].xyz, objMatrix[2].xyz ) * normal;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec3 transformedNormal = normalize( normalMatrix * normal );\nif ( !enableLighting ) {\nvLightWeighting = vec3( 1.0, 1.0, 1.0 );\n} else {\nvLightWeighting = ambientLightColor;",
+THREE.WebGLRenderer=function(a){function c(f,d){var i=b.createProgram();b.attachShader(i,h("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\n"+f));b.attachShader(i,h("vertex","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform vec3 cameraPosition;\n"+d));b.linkProgram(i);if(!b.getProgramParameter(i,b.LINK_STATUS)){alert("Could not initialise shaders");alert("VALIDATE_STATUS: "+b.getProgramParameter(i,b.VALIDATE_STATUS));alert(b.getError())}i.uniforms=
+{};return i}function e(f,d){var i,o,k;i=0;for(o=d.length;i<o;i++){k=d[i];f.uniforms[k]=b.getUniformLocation(f,k)}}function g(f){f.position=b.getAttribLocation(f,"position");b.enableVertexAttribArray(f.position);f.normal=b.getAttribLocation(f,"normal");b.enableVertexAttribArray(f.normal);f.uv=b.getAttribLocation(f,"uv");b.enableVertexAttribArray(f.uv)}function h(f,d){var i;if(f=="fragment")i=b.createShader(b.FRAGMENT_SHADER);else if(f=="vertex")i=b.createShader(b.VERTEX_SHADER);b.shaderSource(i,d);
+b.compileShader(i);if(!b.getShaderParameter(i,b.COMPILE_STATUS)){alert(b.getShaderInfoLog(i));return null}return i}function q(f){switch(f){case THREE.Repeat:return b.REPEAT;case THREE.ClampToEdge:return b.CLAMP_TO_EDGE;case THREE.MirroredRepeat:return b.MIRRORED_REPEAT}return 0}var m=document.createElement("canvas"),b,l,y,E=new THREE.Matrix4,H,w=new Float32Array(16),F=new Float32Array(16),P=new Float32Array(16),N=new Float32Array(9),O=new Float32Array(16);a=function(f,d){if(f){var i,o,k,j=pointLights=
+maxDirLights=maxPointLights=0;i=0;for(o=f.lights.length;i<o;i++){k=f.lights[i];k instanceof THREE.DirectionalLight&&j++;k instanceof THREE.PointLight&&pointLights++}if(pointLights+j<=d){maxDirLights=j;maxPointLights=pointLights}else{maxDirLights=Math.ceil(d*j/(pointLights+j));maxPointLights=d-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:d-1}}(a,4);this.domElement=m;this.autoClear=true;try{b=m.getContext("experimental-webgl",{antialias:true})}catch(s){}if(!b){alert("WebGL not supported");
+throw"cannot create webgl context";}b.clearColor(0,0,0,1);b.clearDepth(1);b.enable(b.DEPTH_TEST);b.depthFunc(b.LEQUAL);b.frontFace(b.CCW);b.cullFace(b.BACK);b.enable(b.CULL_FACE);b.enable(b.BLEND);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA);b.clearColor(0,0,0,0);(function(f,d){var i=[f?"#define MAX_DIR_LIGHTS "+f:"",d?"#define MAX_POINT_LIGHTS "+d:"","attribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\nuniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",
+f?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",f?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",d?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",d?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","uniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",d?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform float mRefractionRatio;\nvoid main(void) {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec3 transformedNormal = normalize( normalMatrix * normal );\nif ( !enableLighting ) {\nvLightWeighting = vec3( 1.0, 1.0, 1.0 );\n} else {\nvLightWeighting = ambientLightColor;",
 f?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",f?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",f?"float directionalLightWeighting = max( dot( transformedNormal, normalize(lDirection.xyz ) ), 0.0 );":"",f?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",f?"}":"",d?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",d?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",d?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
 "",d?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",d?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",d?"}":"","}\nvNormal = transformedNormal;\nvUv = uv;\nif ( useRefract ) {\nvReflect = refract( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz), mRefractionRatio );\n} else {\nvReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );\n}\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n"),
 o=[f?"#define MAX_DIR_LIGHTS "+f:"",d?"#define MAX_POINT_LIGHTS "+d:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\nuniform float m2Near;\nuniform float mFarPlusNear;\nuniform float mFarMinusNear;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
@@ -138,7 +137,7 @@ d?"vec4 pointDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",d?"vec4 pointSpecular =
 "",d?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",d?"pointDiffuse  += mColor * pointDiffuseWeight;":"",d?"pointSpecular += mSpecular * pointSpecularWeight;":"",d?"}":"",f?"vec4 dirDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",f?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",f?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",f?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",f?"vec3 dirVector = normalize( lDirection.xyz );":"",f?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
 "",f?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",f?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",f?"float dirSpecularWeight = 0.0;":"",f?"if ( dirDotNormalHalf >= 0.0 )":"",f?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",f?"dirDiffuse  += mColor * dirDiffuseWeight;":"",f?"dirSpecular += mSpecular * dirSpecularWeight;":"",f?"}":"","vec4 totalLight = mAmbient;",f?"totalLight += dirDiffuse + dirSpecular;":"",d?"totalLight += pointDiffuse + pointSpecular;":
 "","if ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mapColor.rgb * totalLight.xyz * vLightWeighting, cubeColor.rgb, mReflectivity ), mapColor.a );\n} else {\ngl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );\n}\n} else if ( material == 1 ) {\nif ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mColor.rgb * mapColor.rgb * vLightWeighting, cubeColor.rgb, mReflectivity ), mColor.a * mapColor.a );\n} else {\ngl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );\n}\n} else {\nif ( mixEnvMap ) {\ngl_FragColor = mix( mColor * mapColor, cubeColor, mReflectivity );\n} else {\ngl_FragColor = mColor * mapColor * cubeColor;\n}\n}\n}"].join("\n");
-l=c(o,i);b.useProgram(l);e(l,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract","m2Near","mFarPlusNear","mFarMinusNear"]);f&&e(l,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);d&&e(l,["pointLightNumber","pointLightColor",
+l=c(o,i);b.useProgram(l);e(l,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract","m2Near","mFarPlusNear","mFarMinusNear"]);f&&e(l,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);d&&e(l,["pointLightNumber","pointLightColor",
 "pointLightPosition"]);b.uniform1i(l.uniforms.enableMap,0);b.uniform1i(l.uniforms.tMap,0);b.uniform1i(l.uniforms.enableCubeMap,0);b.uniform1i(l.uniforms.tCube,1);b.uniform1i(l.uniforms.mixEnvMap,0);b.uniform1i(l.uniforms.useRefract,0);g(l)})(a.directional,a.point);this.setSize=function(f,d){m.width=f;m.height=d;b.viewport(0,0,m.width,m.height)};this.clear=function(){b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT)};this.setupLights=function(f,d){var i,o,k,j,n,t=[],Q=[],r=[];j=[];n=[];b.uniform1i(f.uniforms.enableLighting,
 d.lights.length);i=0;for(o=d.lights.length;i<o;i++){k=d.lights[i];if(k instanceof THREE.AmbientLight)t.push(k);else if(k instanceof THREE.DirectionalLight)r.push(k);else k instanceof THREE.PointLight&&Q.push(k)}i=k=j=n=0;for(o=t.length;i<o;i++){k+=t[i].color.r;j+=t[i].color.g;n+=t[i].color.b}b.uniform3f(f.uniforms.ambientLightColor,k,j,n);j=[];n=[];i=0;for(o=r.length;i<o;i++){k=r[i];j.push(k.color.r*k.intensity);j.push(k.color.g*k.intensity);j.push(k.color.b*k.intensity);n.push(k.position.x);n.push(k.position.y);
 n.push(k.position.z)}if(r.length){b.uniform1i(f.uniforms.directionalLightNumber,r.length);b.uniform3fv(f.uniforms.directionalLightDirection,n);b.uniform3fv(f.uniforms.directionalLightColor,j)}j=[];n=[];i=0;for(o=Q.length;i<o;i++){k=Q[i];j.push(k.color.r*k.intensity);j.push(k.color.g*k.intensity);j.push(k.color.b*k.intensity);n.push(k.position.x);n.push(k.position.y);n.push(k.position.z)}if(Q.length){b.uniform1i(f.uniforms.pointLightNumber,Q.length);b.uniform3fv(f.uniforms.pointLightPosition,n);b.uniform3fv(f.uniforms.pointLightColor,
@@ -147,7 +146,7 @@ k;i=0;for(o=p.faces.length;i<o;i++){k=p.faces[i];j=f.geometry.faces[k];n=j.verte
 z+1,z+2);x.push(z,z+1);x.push(z,z+2);x.push(z+1,z+2);z+=3}else if(j instanceof THREE.Face4){t=f.geometry.vertices[j.a].position;Q=f.geometry.vertices[j.b].position;r=f.geometry.vertices[j.c].position;j=f.geometry.vertices[j.d].position;v.push(t.x,t.y,t.z);v.push(Q.x,Q.y,Q.z);v.push(r.x,r.y,r.z);v.push(j.x,j.y,j.z);if(n.length==4&&B)for(j=0;j<4;j++)U.push(n[j].x,n[j].y,n[j].z);else for(j=0;j<4;j++)U.push(faceNormal.x,faceNormal.y,faceNormal.z);if(k)for(j=0;j<4;j++)I.push(k[j].u,k[j].v);T.push(z,z+
 1,z+2);T.push(z,z+2,z+3);x.push(z,z+1);x.push(z,z+2);x.push(z,z+3);x.push(z+1,z+2);x.push(z+2,z+3);z+=4}}if(v.length){p.__webGLVertexBuffer=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,p.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,new Float32Array(v),b.STATIC_DRAW);p.__webGLNormalBuffer=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,p.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,new Float32Array(U),b.STATIC_DRAW);p.__webGLUVBuffer=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,p.__webGLUVBuffer);
 b.bufferData(b.ARRAY_BUFFER,new Float32Array(I),b.STATIC_DRAW);p.__webGLFaceBuffer=b.createBuffer();b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,p.__webGLFaceBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,new Uint16Array(T),b.STATIC_DRAW);p.__webGLLineBuffer=b.createBuffer();b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,p.__webGLLineBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,new Uint16Array(x),b.STATIC_DRAW);p.__webGLFaceCount=T.length;p.__webGLLineCount=x.length}};this.renderBuffer=function(f,d,i){var o,k,j,n,t,Q,r,
-T,x,v;if(d instanceof THREE.MeshShaderMaterial){if(!d.program){d.program=c(d.fragment_shader,d.vertex_shader);t=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objMatrix","cameraPosition"];for(v in d.uniforms)t.push(v);e(d.program,t);g(d.program)}v=d.program}else v=l;if(v!=y){b.useProgram(v);y=v}if(d instanceof THREE.MeshShaderMaterial){t=v;T=d.uniforms;var U,I;for(k in T){U=T[k].type;x=T[k].value;I=t.uniforms[k];if(U=="i")b.uniform1i(I,x);else if(U=="f")b.uniform1f(I,x);else if(U==
+T,x,v;if(d instanceof THREE.MeshShaderMaterial){if(!d.program){d.program=c(d.fragment_shader,d.vertex_shader);t=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(v in d.uniforms)t.push(v);e(d.program,t);g(d.program)}v=d.program}else v=l;if(v!=y){b.useProgram(v);y=v}if(d instanceof THREE.MeshShaderMaterial){t=v;T=d.uniforms;var U,I;for(k in T){U=T[k].type;x=T[k].value;I=t.uniforms[k];if(U=="i")b.uniform1i(I,x);else if(U=="f")b.uniform1f(I,x);else if(U==
 "t"){b.uniform1i(I,x);x=T[k].texture;if(x instanceof THREE.TextureCube&&x.image.length==6){if(!x.image.__webGLTextureCube&&!x.image.__cubeMapInitialized&&x.image.loadCount==6){x.image.__webGLTextureCube=b.createTexture();b.bindTexture(b.TEXTURE_CUBE_MAP,x.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(U=0;U<6;++U)b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X+U,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,x.image[U]);b.generateMipmap(b.TEXTURE_CUBE_MAP);b.bindTexture(b.TEXTURE_CUBE_MAP,null);x.image.__cubeMapInitialized=true}b.activeTexture(b.TEXTURE1);b.bindTexture(b.TEXTURE_CUBE_MAP,x.image.__webGLTextureCube)}}}this.loadCamera(v,f);this.loadMatrices(v)}else if(d instanceof THREE.MeshPhongMaterial||d instanceof THREE.MeshLambertMaterial||d instanceof THREE.MeshBasicMaterial){f=
 d.color;o=d.opacity;j=d.wireframe;n=d.wireframe_linewidth;Q=d.map;r=d.env_map;t=d.combine==THREE.Mix;k=d.reflectivity;x=d.env_map&&d.env_map.mapping==THREE.RefractionMap;T=d.refraction_ratio;b.uniform4f(v.uniforms.mColor,f.r*o,f.g*o,f.b*o,o);b.uniform1i(v.uniforms.mixEnvMap,t);b.uniform1f(v.uniforms.mReflectivity,k);b.uniform1i(v.uniforms.useRefract,x);b.uniform1f(v.uniforms.mRefractionRatio,T)}if(d instanceof THREE.MeshNormalMaterial){o=d.opacity;b.uniform1f(v.uniforms.mOpacity,o);b.uniform1i(v.uniforms.material,
@@ -161,7 +160,7 @@ b.UNSIGNED_SHORT,0)}else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,i.__webGLFaceBuffer
 this.renderBuffer(f,r,i)}}};this.render=function(f,d){var i,o;this.initWebGLObjects(f);this.autoClear&&this.clear();d.autoUpdateMatrix&&d.updateMatrix();this.loadCamera(l,d);this.setupLights(l,f);i=0;for(o=f.__webGLObjects.length;i<o;i++){webGLObject=f.__webGLObjects[i];if(webGLObject.__object.visible){this.setupMatrices(webGLObject.__object,d);this.loadMatrices(l);this.renderPass(d,webGLObject.__object,webGLObject,THREE.NormalBlending,false)}}i=0;for(o=f.__webGLObjects.length;i<o;i++){webGLObject=
 f.__webGLObjects[i];if(webGLObject.__object.visible){this.setupMatrices(webGLObject.__object,d);this.loadMatrices(l);this.renderPass(d,webGLObject.__object,webGLObject,THREE.AdditiveBlending,false);this.renderPass(d,webGLObject.__object,webGLObject,THREE.SubtractiveBlending,false);this.renderPass(d,webGLObject.__object,webGLObject,THREE.AdditiveBlending,true);this.renderPass(d,webGLObject.__object,webGLObject,THREE.SubtractiveBlending,true);this.renderPass(d,webGLObject.__object,webGLObject,THREE.NormalBlending,
 true)}}};this.initWebGLObjects=function(f){var d,i,o,k,j;if(!f.__webGLObjects)f.__webGLObjects=[];d=0;for(i=f.objects.length;d<i;d++){o=f.objects[d];if(o instanceof THREE.Mesh)for(k in o.materialFaceGroup){j=o.materialFaceGroup[k];if(!j.__webGLVertexBuffer){this.createBuffers(o,k);j.__object=o;f.__webGLObjects.push(j)}}}};this.removeObject=function(f,d){var i,o;for(i=f.__webGLObjects.length-1;i>=0;i--){o=f.__webGLObjects[i].__object;d==o&&f.__webGLObjects.splice(i,1)}};this.setupMatrices=function(f,
-d){f.autoUpdateMatrix&&f.updateMatrix();E.multiply(d.matrix,f.matrix);w.set(d.matrix.flatten());F.set(E.flatten());P.set(d.projectionMatrix.flatten());H=THREE.Matrix4.makeInvert3x3(E).transpose();N.set(H.m);O.set(f.matrix.flatten())};this.loadMatrices=function(f){b.uniformMatrix4fv(f.uniforms.viewMatrix,false,w);b.uniformMatrix4fv(f.uniforms.modelViewMatrix,false,F);b.uniformMatrix4fv(f.uniforms.projectionMatrix,false,P);b.uniformMatrix3fv(f.uniforms.normalMatrix,false,N);b.uniformMatrix4fv(f.uniforms.objMatrix,
+d){f.autoUpdateMatrix&&f.updateMatrix();E.multiply(d.matrix,f.matrix);w.set(d.matrix.flatten());F.set(E.flatten());P.set(d.projectionMatrix.flatten());H=THREE.Matrix4.makeInvert3x3(E).transpose();N.set(H.m);O.set(f.matrix.flatten())};this.loadMatrices=function(f){b.uniformMatrix4fv(f.uniforms.viewMatrix,false,w);b.uniformMatrix4fv(f.uniforms.modelViewMatrix,false,F);b.uniformMatrix4fv(f.uniforms.projectionMatrix,false,P);b.uniformMatrix3fv(f.uniforms.normalMatrix,false,N);b.uniformMatrix4fv(f.uniforms.objectMatrix,
 false,O)};this.loadCamera=function(f,d){b.uniform3f(f.uniforms.cameraPosition,d.position.x,d.position.y,d.position.z)};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;default:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(f,d){if(f){!d||d=="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)}};
 THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];this.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};

+ 9 - 10
build/ThreeDebug.js

@@ -124,13 +124,12 @@ x.setAttribute("y1",V.positionScreen.y);x.setAttribute("x2",ba.positionScreen.x)
 -I;F.positionScreen.x*=E;F.positionScreen.y*=-I;Q.positionScreen.x*=E;Q.positionScreen.y*=-I;r.addPoint(w.positionScreen.x,w.positionScreen.y);r.addPoint(F.positionScreen.x,F.positionScreen.y);r.addPoint(Q.positionScreen.x,Q.positionScreen.y);if(P.instersects(r)){C=0;for(A=H.meshMaterial.length;C<A;){M=H.meshMaterial[C++];if(M instanceof THREE.MeshFaceMaterial){V=0;for(ba=H.faceMaterial.length;V<ba;)(M=H.faceMaterial[V++])&&c(w,F,Q,H,M,p)}else M&&c(w,F,Q,H,M,p)}}}else if(H instanceof THREE.RenderableFace4){w=
 H.v1;F=H.v2;Q=H.v3;O=H.v4;w.positionScreen.x*=E;w.positionScreen.y*=-I;F.positionScreen.x*=E;F.positionScreen.y*=-I;Q.positionScreen.x*=E;Q.positionScreen.y*=-I;O.positionScreen.x*=E;O.positionScreen.y*=-I;r.addPoint(w.positionScreen.x,w.positionScreen.y);r.addPoint(F.positionScreen.x,F.positionScreen.y);r.addPoint(Q.positionScreen.x,Q.positionScreen.y);r.addPoint(O.positionScreen.x,O.positionScreen.y);if(P.instersects(r)){C=0;for(A=H.meshMaterial.length;C<A;){M=H.meshMaterial[C++];if(M instanceof
 THREE.MeshFaceMaterial){V=0;for(ba=H.faceMaterial.length;V<ba;)(M=H.faceMaterial[V++])&&e(w,F,Q,O,H,M,p)}else M&&e(w,F,Q,O,H,M,p)}}}}}};
-THREE.WebGLRenderer=function(a){function c(f,d){var i=b.createProgram();b.attachShader(i,h("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\n"+f));b.attachShader(i,h("vertex",d));b.linkProgram(i);if(!b.getProgramParameter(i,b.LINK_STATUS)){alert("Could not initialise shaders");alert("VALIDATE_STATUS: "+b.getProgramParameter(i,b.VALIDATE_STATUS));alert(b.getError())}i.uniforms={};return i}function e(f,d){var i,o,k;i=0;for(o=d.length;i<o;i++){k=d[i];f.uniforms[k]=b.getUniformLocation(f,k)}}
-function g(f){f.position=b.getAttribLocation(f,"position");b.enableVertexAttribArray(f.position);f.normal=b.getAttribLocation(f,"normal");b.enableVertexAttribArray(f.normal);f.uv=b.getAttribLocation(f,"uv");b.enableVertexAttribArray(f.uv)}function h(f,d){var i;if(f=="fragment")i=b.createShader(b.FRAGMENT_SHADER);else if(f=="vertex")i=b.createShader(b.VERTEX_SHADER);b.shaderSource(i,d);b.compileShader(i);if(!b.getShaderParameter(i,b.COMPILE_STATUS)){alert(b.getShaderInfoLog(i));return null}return i}
-function q(f){switch(f){case THREE.Repeat:return b.REPEAT;case THREE.ClampToEdge:return b.CLAMP_TO_EDGE;case THREE.MirroredRepeat:return b.MIRRORED_REPEAT}return 0}var m=document.createElement("canvas"),b,l,y,E=new THREE.Matrix4,I,w=new Float32Array(16),F=new Float32Array(16),Q=new Float32Array(16),O=new Float32Array(9),P=new Float32Array(16);a=function(f,d){if(f){var i,o,k,j=pointLights=maxDirLights=maxPointLights=0;i=0;for(o=f.lights.length;i<o;i++){k=f.lights[i];k instanceof THREE.DirectionalLight&&
-j++;k instanceof THREE.PointLight&&pointLights++}if(pointLights+j<=d){maxDirLights=j;maxPointLights=pointLights}else{maxDirLights=Math.ceil(d*j/(pointLights+j));maxPointLights=d-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:d-1}}(a,4);this.domElement=m;this.autoClear=true;try{b=m.getContext("experimental-webgl",{antialias:true})}catch(r){}if(!b){alert("WebGL not supported");throw"cannot create webgl context";}b.clearColor(0,0,0,1);b.clearDepth(1);b.enable(b.DEPTH_TEST);
-b.depthFunc(b.LEQUAL);b.frontFace(b.CCW);b.cullFace(b.BACK);b.enable(b.CULL_FACE);b.enable(b.BLEND);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA);b.clearColor(0,0,0,0);(function(f,d){var i=[f?"#define MAX_DIR_LIGHTS "+f:"",d?"#define MAX_POINT_LIGHTS "+d:"","attribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\nuniform vec3 cameraPosition;\nuniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",
-f?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",f?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",d?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",d?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","uniform mat4 objMatrix;\nuniform mat4 viewMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat3 normalMatrix;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",d?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":
-"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform float mRefractionRatio;\nvoid main(void) {\nvec4 mPosition = objMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 nWorld = mat3( objMatrix[0].xyz, objMatrix[1].xyz, objMatrix[2].xyz ) * normal;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec3 transformedNormal = normalize( normalMatrix * normal );\nif ( !enableLighting ) {\nvLightWeighting = vec3( 1.0, 1.0, 1.0 );\n} else {\nvLightWeighting = ambientLightColor;",
+THREE.WebGLRenderer=function(a){function c(f,d){var i=b.createProgram();b.attachShader(i,h("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\n"+f));b.attachShader(i,h("vertex","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform vec3 cameraPosition;\n"+d));b.linkProgram(i);if(!b.getProgramParameter(i,b.LINK_STATUS)){alert("Could not initialise shaders");alert("VALIDATE_STATUS: "+b.getProgramParameter(i,b.VALIDATE_STATUS));alert(b.getError())}i.uniforms=
+{};return i}function e(f,d){var i,o,k;i=0;for(o=d.length;i<o;i++){k=d[i];f.uniforms[k]=b.getUniformLocation(f,k)}}function g(f){f.position=b.getAttribLocation(f,"position");b.enableVertexAttribArray(f.position);f.normal=b.getAttribLocation(f,"normal");b.enableVertexAttribArray(f.normal);f.uv=b.getAttribLocation(f,"uv");b.enableVertexAttribArray(f.uv)}function h(f,d){var i;if(f=="fragment")i=b.createShader(b.FRAGMENT_SHADER);else if(f=="vertex")i=b.createShader(b.VERTEX_SHADER);b.shaderSource(i,d);
+b.compileShader(i);if(!b.getShaderParameter(i,b.COMPILE_STATUS)){alert(b.getShaderInfoLog(i));return null}return i}function q(f){switch(f){case THREE.Repeat:return b.REPEAT;case THREE.ClampToEdge:return b.CLAMP_TO_EDGE;case THREE.MirroredRepeat:return b.MIRRORED_REPEAT}return 0}var m=document.createElement("canvas"),b,l,y,E=new THREE.Matrix4,I,w=new Float32Array(16),F=new Float32Array(16),Q=new Float32Array(16),O=new Float32Array(9),P=new Float32Array(16);a=function(f,d){if(f){var i,o,k,j=pointLights=
+maxDirLights=maxPointLights=0;i=0;for(o=f.lights.length;i<o;i++){k=f.lights[i];k instanceof THREE.DirectionalLight&&j++;k instanceof THREE.PointLight&&pointLights++}if(pointLights+j<=d){maxDirLights=j;maxPointLights=pointLights}else{maxDirLights=Math.ceil(d*j/(pointLights+j));maxPointLights=d-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:d-1}}(a,4);this.domElement=m;this.autoClear=true;try{b=m.getContext("experimental-webgl",{antialias:true})}catch(r){}if(!b){alert("WebGL not supported");
+throw"cannot create webgl context";}b.clearColor(0,0,0,1);b.clearDepth(1);b.enable(b.DEPTH_TEST);b.depthFunc(b.LEQUAL);b.frontFace(b.CCW);b.cullFace(b.BACK);b.enable(b.CULL_FACE);b.enable(b.BLEND);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA);b.clearColor(0,0,0,0);(function(f,d){var i=[f?"#define MAX_DIR_LIGHTS "+f:"",d?"#define MAX_POINT_LIGHTS "+d:"","attribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\nuniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",
+f?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",f?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",d?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",d?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","uniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",d?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform float mRefractionRatio;\nvoid main(void) {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec3 transformedNormal = normalize( normalMatrix * normal );\nif ( !enableLighting ) {\nvLightWeighting = vec3( 1.0, 1.0, 1.0 );\n} else {\nvLightWeighting = ambientLightColor;",
 f?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",f?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",f?"float directionalLightWeighting = max( dot( transformedNormal, normalize(lDirection.xyz ) ), 0.0 );":"",f?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",f?"}":"",d?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",d?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",d?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
 "",d?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",d?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",d?"}":"","}\nvNormal = transformedNormal;\nvUv = uv;\nif ( useRefract ) {\nvReflect = refract( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz), mRefractionRatio );\n} else {\nvReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );\n}\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n"),
 o=[f?"#define MAX_DIR_LIGHTS "+f:"",d?"#define MAX_POINT_LIGHTS "+d:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\nuniform float m2Near;\nuniform float mFarPlusNear;\nuniform float mFarMinusNear;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
@@ -139,7 +138,7 @@ d?"vec4 pointDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",d?"vec4 pointSpecular =
 "",d?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",d?"pointDiffuse  += mColor * pointDiffuseWeight;":"",d?"pointSpecular += mSpecular * pointSpecularWeight;":"",d?"}":"",f?"vec4 dirDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",f?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",f?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",f?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",f?"vec3 dirVector = normalize( lDirection.xyz );":"",f?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
 "",f?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",f?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",f?"float dirSpecularWeight = 0.0;":"",f?"if ( dirDotNormalHalf >= 0.0 )":"",f?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",f?"dirDiffuse  += mColor * dirDiffuseWeight;":"",f?"dirSpecular += mSpecular * dirSpecularWeight;":"",f?"}":"","vec4 totalLight = mAmbient;",f?"totalLight += dirDiffuse + dirSpecular;":"",d?"totalLight += pointDiffuse + pointSpecular;":
 "","if ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mapColor.rgb * totalLight.xyz * vLightWeighting, cubeColor.rgb, mReflectivity ), mapColor.a );\n} else {\ngl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );\n}\n} else if ( material == 1 ) {\nif ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mColor.rgb * mapColor.rgb * vLightWeighting, cubeColor.rgb, mReflectivity ), mColor.a * mapColor.a );\n} else {\ngl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );\n}\n} else {\nif ( mixEnvMap ) {\ngl_FragColor = mix( mColor * mapColor, cubeColor, mReflectivity );\n} else {\ngl_FragColor = mColor * mapColor * cubeColor;\n}\n}\n}"].join("\n");
-l=c(o,i);b.useProgram(l);e(l,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract","m2Near","mFarPlusNear","mFarMinusNear"]);f&&e(l,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);d&&e(l,["pointLightNumber","pointLightColor",
+l=c(o,i);b.useProgram(l);e(l,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract","m2Near","mFarPlusNear","mFarMinusNear"]);f&&e(l,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);d&&e(l,["pointLightNumber","pointLightColor",
 "pointLightPosition"]);b.uniform1i(l.uniforms.enableMap,0);b.uniform1i(l.uniforms.tMap,0);b.uniform1i(l.uniforms.enableCubeMap,0);b.uniform1i(l.uniforms.tCube,1);b.uniform1i(l.uniforms.mixEnvMap,0);b.uniform1i(l.uniforms.useRefract,0);g(l)})(a.directional,a.point);this.setSize=function(f,d){m.width=f;m.height=d;b.viewport(0,0,m.width,m.height)};this.clear=function(){b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT)};this.setupLights=function(f,d){var i,o,k,j,n,t=[],R=[],s=[];j=[];n=[];b.uniform1i(f.uniforms.enableLighting,
 d.lights.length);i=0;for(o=d.lights.length;i<o;i++){k=d.lights[i];if(k instanceof THREE.AmbientLight)t.push(k);else if(k instanceof THREE.DirectionalLight)s.push(k);else k instanceof THREE.PointLight&&R.push(k)}i=k=j=n=0;for(o=t.length;i<o;i++){k+=t[i].color.r;j+=t[i].color.g;n+=t[i].color.b}b.uniform3f(f.uniforms.ambientLightColor,k,j,n);j=[];n=[];i=0;for(o=s.length;i<o;i++){k=s[i];j.push(k.color.r*k.intensity);j.push(k.color.g*k.intensity);j.push(k.color.b*k.intensity);n.push(k.position.x);n.push(k.position.y);
 n.push(k.position.z)}if(s.length){b.uniform1i(f.uniforms.directionalLightNumber,s.length);b.uniform3fv(f.uniforms.directionalLightDirection,n);b.uniform3fv(f.uniforms.directionalLightColor,j)}j=[];n=[];i=0;for(o=R.length;i<o;i++){k=R[i];j.push(k.color.r*k.intensity);j.push(k.color.g*k.intensity);j.push(k.color.b*k.intensity);n.push(k.position.x);n.push(k.position.y);n.push(k.position.z)}if(R.length){b.uniform1i(f.uniforms.pointLightNumber,R.length);b.uniform3fv(f.uniforms.pointLightPosition,n);b.uniform3fv(f.uniforms.pointLightColor,
@@ -148,7 +147,7 @@ k;i=0;for(o=p.faces.length;i<o;i++){k=p.faces[i];j=f.geometry.faces[k];n=j.verte
 z+1,z+2);x.push(z,z+1);x.push(z,z+2);x.push(z+1,z+2);z+=3}else if(j instanceof THREE.Face4){t=f.geometry.vertices[j.a].position;R=f.geometry.vertices[j.b].position;s=f.geometry.vertices[j.c].position;j=f.geometry.vertices[j.d].position;v.push(t.x,t.y,t.z);v.push(R.x,R.y,R.z);v.push(s.x,s.y,s.z);v.push(j.x,j.y,j.z);if(n.length==4&&B)for(j=0;j<4;j++)U.push(n[j].x,n[j].y,n[j].z);else for(j=0;j<4;j++)U.push(faceNormal.x,faceNormal.y,faceNormal.z);if(k)for(j=0;j<4;j++)J.push(k[j].u,k[j].v);T.push(z,z+
 1,z+2);T.push(z,z+2,z+3);x.push(z,z+1);x.push(z,z+2);x.push(z,z+3);x.push(z+1,z+2);x.push(z+2,z+3);z+=4}}if(v.length){p.__webGLVertexBuffer=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,p.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,new Float32Array(v),b.STATIC_DRAW);p.__webGLNormalBuffer=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,p.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,new Float32Array(U),b.STATIC_DRAW);p.__webGLUVBuffer=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,p.__webGLUVBuffer);
 b.bufferData(b.ARRAY_BUFFER,new Float32Array(J),b.STATIC_DRAW);p.__webGLFaceBuffer=b.createBuffer();b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,p.__webGLFaceBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,new Uint16Array(T),b.STATIC_DRAW);p.__webGLLineBuffer=b.createBuffer();b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,p.__webGLLineBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,new Uint16Array(x),b.STATIC_DRAW);p.__webGLFaceCount=T.length;p.__webGLLineCount=x.length}};this.renderBuffer=function(f,d,i){var o,k,j,n,t,R,s,
-T,x,v;if(d instanceof THREE.MeshShaderMaterial){if(!d.program){d.program=c(d.fragment_shader,d.vertex_shader);t=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objMatrix","cameraPosition"];for(v in d.uniforms)t.push(v);e(d.program,t);g(d.program)}v=d.program}else v=l;if(v!=y){b.useProgram(v);y=v}if(d instanceof THREE.MeshShaderMaterial){t=v;T=d.uniforms;var U,J;for(k in T){U=T[k].type;x=T[k].value;J=t.uniforms[k];if(U=="i")b.uniform1i(J,x);else if(U=="f")b.uniform1f(J,x);else if(U==
+T,x,v;if(d instanceof THREE.MeshShaderMaterial){if(!d.program){d.program=c(d.fragment_shader,d.vertex_shader);t=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(v in d.uniforms)t.push(v);e(d.program,t);g(d.program)}v=d.program}else v=l;if(v!=y){b.useProgram(v);y=v}if(d instanceof THREE.MeshShaderMaterial){t=v;T=d.uniforms;var U,J;for(k in T){U=T[k].type;x=T[k].value;J=t.uniforms[k];if(U=="i")b.uniform1i(J,x);else if(U=="f")b.uniform1f(J,x);else if(U==
 "t"){b.uniform1i(J,x);x=T[k].texture;if(x instanceof THREE.TextureCube&&x.image.length==6){if(!x.image.__webGLTextureCube&&!x.image.__cubeMapInitialized&&x.image.loadCount==6){x.image.__webGLTextureCube=b.createTexture();b.bindTexture(b.TEXTURE_CUBE_MAP,x.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(U=0;U<6;++U)b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X+U,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,x.image[U]);b.generateMipmap(b.TEXTURE_CUBE_MAP);b.bindTexture(b.TEXTURE_CUBE_MAP,null);x.image.__cubeMapInitialized=true}b.activeTexture(b.TEXTURE1);b.bindTexture(b.TEXTURE_CUBE_MAP,x.image.__webGLTextureCube)}}}this.loadCamera(v,f);this.loadMatrices(v)}else if(d instanceof THREE.MeshPhongMaterial||d instanceof THREE.MeshLambertMaterial||d instanceof THREE.MeshBasicMaterial){f=
 d.color;o=d.opacity;j=d.wireframe;n=d.wireframe_linewidth;R=d.map;s=d.env_map;t=d.combine==THREE.Mix;k=d.reflectivity;x=d.env_map&&d.env_map.mapping==THREE.RefractionMap;T=d.refraction_ratio;b.uniform4f(v.uniforms.mColor,f.r*o,f.g*o,f.b*o,o);b.uniform1i(v.uniforms.mixEnvMap,t);b.uniform1f(v.uniforms.mReflectivity,k);b.uniform1i(v.uniforms.useRefract,x);b.uniform1f(v.uniforms.mRefractionRatio,T)}if(d instanceof THREE.MeshNormalMaterial){o=d.opacity;b.uniform1f(v.uniforms.mOpacity,o);b.uniform1i(v.uniforms.material,
@@ -162,7 +161,7 @@ b.UNSIGNED_SHORT,0)}else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,i.__webGLFaceBuffer
 this.renderBuffer(f,s,i)}}};this.render=function(f,d){var i,o;this.initWebGLObjects(f);this.autoClear&&this.clear();d.autoUpdateMatrix&&d.updateMatrix();this.loadCamera(l,d);this.setupLights(l,f);i=0;for(o=f.__webGLObjects.length;i<o;i++){webGLObject=f.__webGLObjects[i];if(webGLObject.__object.visible){this.setupMatrices(webGLObject.__object,d);this.loadMatrices(l);this.renderPass(d,webGLObject.__object,webGLObject,THREE.NormalBlending,false)}}i=0;for(o=f.__webGLObjects.length;i<o;i++){webGLObject=
 f.__webGLObjects[i];if(webGLObject.__object.visible){this.setupMatrices(webGLObject.__object,d);this.loadMatrices(l);this.renderPass(d,webGLObject.__object,webGLObject,THREE.AdditiveBlending,false);this.renderPass(d,webGLObject.__object,webGLObject,THREE.SubtractiveBlending,false);this.renderPass(d,webGLObject.__object,webGLObject,THREE.AdditiveBlending,true);this.renderPass(d,webGLObject.__object,webGLObject,THREE.SubtractiveBlending,true);this.renderPass(d,webGLObject.__object,webGLObject,THREE.NormalBlending,
 true)}}};this.initWebGLObjects=function(f){var d,i,o,k,j;if(!f.__webGLObjects)f.__webGLObjects=[];d=0;for(i=f.objects.length;d<i;d++){o=f.objects[d];if(o instanceof THREE.Mesh)for(k in o.materialFaceGroup){j=o.materialFaceGroup[k];if(!j.__webGLVertexBuffer){this.createBuffers(o,k);j.__object=o;f.__webGLObjects.push(j)}}}};this.removeObject=function(f,d){var i,o;for(i=f.__webGLObjects.length-1;i>=0;i--){o=f.__webGLObjects[i].__object;d==o&&f.__webGLObjects.splice(i,1)}};this.setupMatrices=function(f,
-d){f.autoUpdateMatrix&&f.updateMatrix();E.multiply(d.matrix,f.matrix);w.set(d.matrix.flatten());F.set(E.flatten());Q.set(d.projectionMatrix.flatten());I=THREE.Matrix4.makeInvert3x3(E).transpose();O.set(I.m);P.set(f.matrix.flatten())};this.loadMatrices=function(f){b.uniformMatrix4fv(f.uniforms.viewMatrix,false,w);b.uniformMatrix4fv(f.uniforms.modelViewMatrix,false,F);b.uniformMatrix4fv(f.uniforms.projectionMatrix,false,Q);b.uniformMatrix3fv(f.uniforms.normalMatrix,false,O);b.uniformMatrix4fv(f.uniforms.objMatrix,
+d){f.autoUpdateMatrix&&f.updateMatrix();E.multiply(d.matrix,f.matrix);w.set(d.matrix.flatten());F.set(E.flatten());Q.set(d.projectionMatrix.flatten());I=THREE.Matrix4.makeInvert3x3(E).transpose();O.set(I.m);P.set(f.matrix.flatten())};this.loadMatrices=function(f){b.uniformMatrix4fv(f.uniforms.viewMatrix,false,w);b.uniformMatrix4fv(f.uniforms.modelViewMatrix,false,F);b.uniformMatrix4fv(f.uniforms.projectionMatrix,false,Q);b.uniformMatrix3fv(f.uniforms.normalMatrix,false,O);b.uniformMatrix4fv(f.uniforms.objectMatrix,
 false,P)};this.loadCamera=function(f,d){b.uniform3f(f.uniforms.cameraPosition,d.position.x,d.position.y,d.position.z)};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;default:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(f,d){if(f){!d||d=="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)}};
 THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];this.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};

+ 10 - 11
build/ThreeExtras.js

@@ -124,13 +124,12 @@ G.setAttribute("y1",X.positionScreen.y);G.setAttribute("x2",l.positionScreen.x);
 -D;w.positionScreen.x*=s;w.positionScreen.y*=-D;v.positionScreen.x*=s;v.positionScreen.y*=-D;u.addPoint(q.positionScreen.x,q.positionScreen.y);u.addPoint(w.positionScreen.x,w.positionScreen.y);u.addPoint(v.positionScreen.x,v.positionScreen.y);if(K.instersects(u)){M=0;for(J=n.meshMaterial.length;M<J;){t=n.meshMaterial[M++];if(t instanceof THREE.MeshFaceMaterial){X=0;for(l=n.faceMaterial.length;X<l;)(t=n.faceMaterial[X++])&&b(q,w,v,n,t,A)}else t&&b(q,w,v,n,t,A)}}}else if(n instanceof THREE.RenderableFace4){q=
 n.v1;w=n.v2;v=n.v3;z=n.v4;q.positionScreen.x*=s;q.positionScreen.y*=-D;w.positionScreen.x*=s;w.positionScreen.y*=-D;v.positionScreen.x*=s;v.positionScreen.y*=-D;z.positionScreen.x*=s;z.positionScreen.y*=-D;u.addPoint(q.positionScreen.x,q.positionScreen.y);u.addPoint(w.positionScreen.x,w.positionScreen.y);u.addPoint(v.positionScreen.x,v.positionScreen.y);u.addPoint(z.positionScreen.x,z.positionScreen.y);if(K.instersects(u)){M=0;for(J=n.meshMaterial.length;M<J;){t=n.meshMaterial[M++];if(t instanceof
 THREE.MeshFaceMaterial){X=0;for(l=n.faceMaterial.length;X<l;)(t=n.faceMaterial[X++])&&d(q,w,v,z,n,t,A)}else t&&d(q,w,v,z,n,t,A)}}}}}};
-THREE.WebGLRenderer=function(a){function b(h,e){var m=c.createProgram();c.attachShader(m,g("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\n"+h));c.attachShader(m,g("vertex",e));c.linkProgram(m);if(!c.getProgramParameter(m,c.LINK_STATUS)){alert("Could not initialise shaders");alert("VALIDATE_STATUS: "+c.getProgramParameter(m,c.VALIDATE_STATUS));alert(c.getError())}m.uniforms={};return m}function d(h,e){var m,r,p;m=0;for(r=e.length;m<r;m++){p=e[m];h.uniforms[p]=c.getUniformLocation(h,p)}}
-function f(h){h.position=c.getAttribLocation(h,"position");c.enableVertexAttribArray(h.position);h.normal=c.getAttribLocation(h,"normal");c.enableVertexAttribArray(h.normal);h.uv=c.getAttribLocation(h,"uv");c.enableVertexAttribArray(h.uv)}function g(h,e){var m;if(h=="fragment")m=c.createShader(c.FRAGMENT_SHADER);else if(h=="vertex")m=c.createShader(c.VERTEX_SHADER);c.shaderSource(m,e);c.compileShader(m);if(!c.getShaderParameter(m,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(m));return null}return m}
-function i(h){switch(h){case THREE.Repeat:return c.REPEAT;case THREE.ClampToEdge:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeat:return c.MIRRORED_REPEAT}return 0}var k=document.createElement("canvas"),c,j,y,s=new THREE.Matrix4,D,q=new Float32Array(16),w=new Float32Array(16),v=new Float32Array(16),z=new Float32Array(9),K=new Float32Array(16);a=function(h,e){if(h){var m,r,p,o=pointLights=maxDirLights=maxPointLights=0;m=0;for(r=h.lights.length;m<r;m++){p=h.lights[m];p instanceof THREE.DirectionalLight&&
-o++;p instanceof THREE.PointLight&&pointLights++}if(pointLights+o<=e){maxDirLights=o;maxPointLights=pointLights}else{maxDirLights=Math.ceil(e*o/(pointLights+o));maxPointLights=e-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:e-1}}(a,4);this.domElement=k;this.autoClear=true;try{c=k.getContext("experimental-webgl",{antialias:true})}catch(u){}if(!c){alert("WebGL not supported");throw"cannot create webgl context";}c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);
-c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK);c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(0,0,0,0);(function(h,e){var m=[h?"#define MAX_DIR_LIGHTS "+h:"",e?"#define MAX_POINT_LIGHTS "+e:"","attribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\nuniform vec3 cameraPosition;\nuniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",
-h?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",h?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",e?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",e?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","uniform mat4 objMatrix;\nuniform mat4 viewMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat3 normalMatrix;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",e?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":
-"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform float mRefractionRatio;\nvoid main(void) {\nvec4 mPosition = objMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 nWorld = mat3( objMatrix[0].xyz, objMatrix[1].xyz, objMatrix[2].xyz ) * normal;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec3 transformedNormal = normalize( normalMatrix * normal );\nif ( !enableLighting ) {\nvLightWeighting = vec3( 1.0, 1.0, 1.0 );\n} else {\nvLightWeighting = ambientLightColor;",
+THREE.WebGLRenderer=function(a){function b(h,e){var m=c.createProgram();c.attachShader(m,g("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\n"+h));c.attachShader(m,g("vertex","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform vec3 cameraPosition;\n"+e));c.linkProgram(m);if(!c.getProgramParameter(m,c.LINK_STATUS)){alert("Could not initialise shaders");alert("VALIDATE_STATUS: "+c.getProgramParameter(m,c.VALIDATE_STATUS));alert(c.getError())}m.uniforms=
+{};return m}function d(h,e){var m,r,p;m=0;for(r=e.length;m<r;m++){p=e[m];h.uniforms[p]=c.getUniformLocation(h,p)}}function f(h){h.position=c.getAttribLocation(h,"position");c.enableVertexAttribArray(h.position);h.normal=c.getAttribLocation(h,"normal");c.enableVertexAttribArray(h.normal);h.uv=c.getAttribLocation(h,"uv");c.enableVertexAttribArray(h.uv)}function g(h,e){var m;if(h=="fragment")m=c.createShader(c.FRAGMENT_SHADER);else if(h=="vertex")m=c.createShader(c.VERTEX_SHADER);c.shaderSource(m,e);
+c.compileShader(m);if(!c.getShaderParameter(m,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(m));return null}return m}function i(h){switch(h){case THREE.Repeat:return c.REPEAT;case THREE.ClampToEdge:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeat:return c.MIRRORED_REPEAT}return 0}var k=document.createElement("canvas"),c,j,y,s=new THREE.Matrix4,D,q=new Float32Array(16),w=new Float32Array(16),v=new Float32Array(16),z=new Float32Array(9),K=new Float32Array(16);a=function(h,e){if(h){var m,r,p,o=pointLights=
+maxDirLights=maxPointLights=0;m=0;for(r=h.lights.length;m<r;m++){p=h.lights[m];p instanceof THREE.DirectionalLight&&o++;p instanceof THREE.PointLight&&pointLights++}if(pointLights+o<=e){maxDirLights=o;maxPointLights=pointLights}else{maxDirLights=Math.ceil(e*o/(pointLights+o));maxPointLights=e-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:e-1}}(a,4);this.domElement=k;this.autoClear=true;try{c=k.getContext("experimental-webgl",{antialias:true})}catch(u){}if(!c){alert("WebGL not supported");
+throw"cannot create webgl context";}c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK);c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(0,0,0,0);(function(h,e){var m=[h?"#define MAX_DIR_LIGHTS "+h:"",e?"#define MAX_POINT_LIGHTS "+e:"","attribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\nuniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",
+h?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",h?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",e?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",e?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","uniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",e?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform float mRefractionRatio;\nvoid main(void) {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec3 transformedNormal = normalize( normalMatrix * normal );\nif ( !enableLighting ) {\nvLightWeighting = vec3( 1.0, 1.0, 1.0 );\n} else {\nvLightWeighting = ambientLightColor;",
 h?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",h?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",h?"float directionalLightWeighting = max( dot( transformedNormal, normalize(lDirection.xyz ) ), 0.0 );":"",h?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",h?"}":"",e?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",e?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",e?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
 "",e?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",e?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",e?"}":"","}\nvNormal = transformedNormal;\nvUv = uv;\nif ( useRefract ) {\nvReflect = refract( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz), mRefractionRatio );\n} else {\nvReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );\n}\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n"),
 r=[h?"#define MAX_DIR_LIGHTS "+h:"",e?"#define MAX_POINT_LIGHTS "+e:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\nuniform float m2Near;\nuniform float mFarPlusNear;\nuniform float mFarMinusNear;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
@@ -139,7 +138,7 @@ e?"vec4 pointDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",e?"vec4 pointSpecular =
 "",e?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",e?"pointDiffuse  += mColor * pointDiffuseWeight;":"",e?"pointSpecular += mSpecular * pointSpecularWeight;":"",e?"}":"",h?"vec4 dirDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",h?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",h?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",h?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",h?"vec3 dirVector = normalize( lDirection.xyz );":"",h?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
 "",h?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",h?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",h?"float dirSpecularWeight = 0.0;":"",h?"if ( dirDotNormalHalf >= 0.0 )":"",h?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",h?"dirDiffuse  += mColor * dirDiffuseWeight;":"",h?"dirSpecular += mSpecular * dirSpecularWeight;":"",h?"}":"","vec4 totalLight = mAmbient;",h?"totalLight += dirDiffuse + dirSpecular;":"",e?"totalLight += pointDiffuse + pointSpecular;":
 "","if ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mapColor.rgb * totalLight.xyz * vLightWeighting, cubeColor.rgb, mReflectivity ), mapColor.a );\n} else {\ngl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );\n}\n} else if ( material == 1 ) {\nif ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mColor.rgb * mapColor.rgb * vLightWeighting, cubeColor.rgb, mReflectivity ), mColor.a * mapColor.a );\n} else {\ngl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );\n}\n} else {\nif ( mixEnvMap ) {\ngl_FragColor = mix( mColor * mapColor, cubeColor, mReflectivity );\n} else {\ngl_FragColor = mColor * mapColor * cubeColor;\n}\n}\n}"].join("\n");
-j=b(r,m);c.useProgram(j);d(j,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract","m2Near","mFarPlusNear","mFarMinusNear"]);h&&d(j,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);e&&d(j,["pointLightNumber","pointLightColor",
+j=b(r,m);c.useProgram(j);d(j,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract","m2Near","mFarPlusNear","mFarMinusNear"]);h&&d(j,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);e&&d(j,["pointLightNumber","pointLightColor",
 "pointLightPosition"]);c.uniform1i(j.uniforms.enableMap,0);c.uniform1i(j.uniforms.tMap,0);c.uniform1i(j.uniforms.enableCubeMap,0);c.uniform1i(j.uniforms.tCube,1);c.uniform1i(j.uniforms.mixEnvMap,0);c.uniform1i(j.uniforms.useRefract,0);f(j)})(a.directional,a.point);this.setSize=function(h,e){k.width=h;k.height=e;c.viewport(0,0,k.width,k.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(h,e){var m,r,p,o,x,C=[],S=[],B=[];o=[];x=[];c.uniform1i(h.uniforms.enableLighting,
 e.lights.length);m=0;for(r=e.lights.length;m<r;m++){p=e.lights[m];if(p instanceof THREE.AmbientLight)C.push(p);else if(p instanceof THREE.DirectionalLight)B.push(p);else p instanceof THREE.PointLight&&S.push(p)}m=p=o=x=0;for(r=C.length;m<r;m++){p+=C[m].color.r;o+=C[m].color.g;x+=C[m].color.b}c.uniform3f(h.uniforms.ambientLightColor,p,o,x);o=[];x=[];m=0;for(r=B.length;m<r;m++){p=B[m];o.push(p.color.r*p.intensity);o.push(p.color.g*p.intensity);o.push(p.color.b*p.intensity);x.push(p.position.x);x.push(p.position.y);
 x.push(p.position.z)}if(B.length){c.uniform1i(h.uniforms.directionalLightNumber,B.length);c.uniform3fv(h.uniforms.directionalLightDirection,x);c.uniform3fv(h.uniforms.directionalLightColor,o)}o=[];x=[];m=0;for(r=S.length;m<r;m++){p=S[m];o.push(p.color.r*p.intensity);o.push(p.color.g*p.intensity);o.push(p.color.b*p.intensity);x.push(p.position.x);x.push(p.position.y);x.push(p.position.z)}if(S.length){c.uniform1i(h.uniforms.pointLightNumber,S.length);c.uniform3fv(h.uniforms.pointLightPosition,x);c.uniform3fv(h.uniforms.pointLightColor,
@@ -148,7 +147,7 @@ p;m=0;for(r=A.faces.length;m<r;m++){p=A.faces[m];o=h.geometry.faces[p];x=o.verte
 I+1,I+2);G.push(I,I+1);G.push(I,I+2);G.push(I+1,I+2);I+=3}else if(o instanceof THREE.Face4){C=h.geometry.vertices[o.a].position;S=h.geometry.vertices[o.b].position;B=h.geometry.vertices[o.c].position;o=h.geometry.vertices[o.d].position;E.push(C.x,C.y,C.z);E.push(S.x,S.y,S.z);E.push(B.x,B.y,B.z);E.push(o.x,o.y,o.z);if(x.length==4&&L)for(o=0;o<4;o++)W.push(x[o].x,x[o].y,x[o].z);else for(o=0;o<4;o++)W.push(faceNormal.x,faceNormal.y,faceNormal.z);if(p)for(o=0;o<4;o++)O.push(p[o].u,p[o].v);V.push(I,I+
 1,I+2);V.push(I,I+2,I+3);G.push(I,I+1);G.push(I,I+2);G.push(I,I+3);G.push(I+1,I+2);G.push(I+2,I+3);I+=4}}if(E.length){A.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,A.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(E),c.STATIC_DRAW);A.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,A.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(W),c.STATIC_DRAW);A.__webGLUVBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,A.__webGLUVBuffer);
 c.bufferData(c.ARRAY_BUFFER,new Float32Array(O),c.STATIC_DRAW);A.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,A.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(V),c.STATIC_DRAW);A.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,A.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(G),c.STATIC_DRAW);A.__webGLFaceCount=V.length;A.__webGLLineCount=G.length}};this.renderBuffer=function(h,e,m){var r,p,o,x,C,S,B,
-V,G,E;if(e instanceof THREE.MeshShaderMaterial){if(!e.program){e.program=b(e.fragment_shader,e.vertex_shader);C=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objMatrix","cameraPosition"];for(E in e.uniforms)C.push(E);d(e.program,C);f(e.program)}E=e.program}else E=j;if(E!=y){c.useProgram(E);y=E}if(e instanceof THREE.MeshShaderMaterial){C=E;V=e.uniforms;var W,O;for(p in V){W=V[p].type;G=V[p].value;O=C.uniforms[p];if(W=="i")c.uniform1i(O,G);else if(W=="f")c.uniform1f(O,G);else if(W==
+V,G,E;if(e instanceof THREE.MeshShaderMaterial){if(!e.program){e.program=b(e.fragment_shader,e.vertex_shader);C=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(E in e.uniforms)C.push(E);d(e.program,C);f(e.program)}E=e.program}else E=j;if(E!=y){c.useProgram(E);y=E}if(e instanceof THREE.MeshShaderMaterial){C=E;V=e.uniforms;var W,O;for(p in V){W=V[p].type;G=V[p].value;O=C.uniforms[p];if(W=="i")c.uniform1i(O,G);else if(W=="f")c.uniform1f(O,G);else if(W==
 "t"){c.uniform1i(O,G);G=V[p].texture;if(G instanceof THREE.TextureCube&&G.image.length==6){if(!G.image.__webGLTextureCube&&!G.image.__cubeMapInitialized&&G.image.loadCount==6){G.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,G.image.__webGLTextureCube);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,
 c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(W=0;W<6;++W)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+W,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,G.image[W]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);G.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE1);c.bindTexture(c.TEXTURE_CUBE_MAP,G.image.__webGLTextureCube)}}}this.loadCamera(E,h);this.loadMatrices(E)}else if(e instanceof THREE.MeshPhongMaterial||e instanceof THREE.MeshLambertMaterial||e instanceof THREE.MeshBasicMaterial){h=
 e.color;r=e.opacity;o=e.wireframe;x=e.wireframe_linewidth;S=e.map;B=e.env_map;C=e.combine==THREE.Mix;p=e.reflectivity;G=e.env_map&&e.env_map.mapping==THREE.RefractionMap;V=e.refraction_ratio;c.uniform4f(E.uniforms.mColor,h.r*r,h.g*r,h.b*r,r);c.uniform1i(E.uniforms.mixEnvMap,C);c.uniform1f(E.uniforms.mReflectivity,p);c.uniform1i(E.uniforms.useRefract,G);c.uniform1f(E.uniforms.mRefractionRatio,V)}if(e instanceof THREE.MeshNormalMaterial){r=e.opacity;c.uniform1f(E.uniforms.mOpacity,r);c.uniform1i(E.uniforms.material,
@@ -162,7 +161,7 @@ c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,m.__webGLFaceBuffer
 this.renderBuffer(h,B,m)}}};this.render=function(h,e){var m,r;this.initWebGLObjects(h);this.autoClear&&this.clear();e.autoUpdateMatrix&&e.updateMatrix();this.loadCamera(j,e);this.setupLights(j,h);m=0;for(r=h.__webGLObjects.length;m<r;m++){webGLObject=h.__webGLObjects[m];if(webGLObject.__object.visible){this.setupMatrices(webGLObject.__object,e);this.loadMatrices(j);this.renderPass(e,webGLObject.__object,webGLObject,THREE.NormalBlending,false)}}m=0;for(r=h.__webGLObjects.length;m<r;m++){webGLObject=
 h.__webGLObjects[m];if(webGLObject.__object.visible){this.setupMatrices(webGLObject.__object,e);this.loadMatrices(j);this.renderPass(e,webGLObject.__object,webGLObject,THREE.AdditiveBlending,false);this.renderPass(e,webGLObject.__object,webGLObject,THREE.SubtractiveBlending,false);this.renderPass(e,webGLObject.__object,webGLObject,THREE.AdditiveBlending,true);this.renderPass(e,webGLObject.__object,webGLObject,THREE.SubtractiveBlending,true);this.renderPass(e,webGLObject.__object,webGLObject,THREE.NormalBlending,
 true)}}};this.initWebGLObjects=function(h){var e,m,r,p,o;if(!h.__webGLObjects)h.__webGLObjects=[];e=0;for(m=h.objects.length;e<m;e++){r=h.objects[e];if(r instanceof THREE.Mesh)for(p in r.materialFaceGroup){o=r.materialFaceGroup[p];if(!o.__webGLVertexBuffer){this.createBuffers(r,p);o.__object=r;h.__webGLObjects.push(o)}}}};this.removeObject=function(h,e){var m,r;for(m=h.__webGLObjects.length-1;m>=0;m--){r=h.__webGLObjects[m].__object;e==r&&h.__webGLObjects.splice(m,1)}};this.setupMatrices=function(h,
-e){h.autoUpdateMatrix&&h.updateMatrix();s.multiply(e.matrix,h.matrix);q.set(e.matrix.flatten());w.set(s.flatten());v.set(e.projectionMatrix.flatten());D=THREE.Matrix4.makeInvert3x3(s).transpose();z.set(D.m);K.set(h.matrix.flatten())};this.loadMatrices=function(h){c.uniformMatrix4fv(h.uniforms.viewMatrix,false,q);c.uniformMatrix4fv(h.uniforms.modelViewMatrix,false,w);c.uniformMatrix4fv(h.uniforms.projectionMatrix,false,v);c.uniformMatrix3fv(h.uniforms.normalMatrix,false,z);c.uniformMatrix4fv(h.uniforms.objMatrix,
+e){h.autoUpdateMatrix&&h.updateMatrix();s.multiply(e.matrix,h.matrix);q.set(e.matrix.flatten());w.set(s.flatten());v.set(e.projectionMatrix.flatten());D=THREE.Matrix4.makeInvert3x3(s).transpose();z.set(D.m);K.set(h.matrix.flatten())};this.loadMatrices=function(h){c.uniformMatrix4fv(h.uniforms.viewMatrix,false,q);c.uniformMatrix4fv(h.uniforms.modelViewMatrix,false,w);c.uniformMatrix4fv(h.uniforms.projectionMatrix,false,v);c.uniformMatrix3fv(h.uniforms.normalMatrix,false,z);c.uniformMatrix4fv(h.uniforms.objectMatrix,
 false,K)};this.loadCamera=function(h,e){c.uniform3f(h.uniforms.cameraPosition,e.position.x,e.position.y,e.position.z)};this.setBlending=function(h){switch(h){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE);break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(h,e){if(h){!e||e=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(h=="back")c.cullFace(c.BACK);
 else h=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)}};
 THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];this.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};
@@ -173,7 +172,7 @@ f;b.position.y=g;b.position.z=i;b.rotation.x=k;b.rotation.y=c;b.rotation.z=j;a.a
 f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[4])}));f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[5])}));mesh=new THREE.Mesh(new Cube(b,b,b,1,1,f,true),new THREE.MeshFaceMaterial);a.addObject(mesh);return mesh},addPanoramaCubePlanes:function(a,b,d){var f=b/2;b=new Plane(b,b);var g=Math.PI/2,i=Math.PI;SceneUtils.addMesh(a,b,1,0,0,-f,0,0,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[5])}));SceneUtils.addMesh(a,b,1,-f,0,0,0,g,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[0])}));
 SceneUtils.addMesh(a,b,1,f,0,0,0,-g,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[1])}));SceneUtils.addMesh(a,b,1,0,f,0,g,0,i,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[2])}));SceneUtils.addMesh(a,b,1,0,-f,0,-g,0,i,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[3])}))}},ShaderUtils={lib:{fresnel:{uniforms:{mRefractionRatio:{type:"f",value:1.02},mFresnelBias:{type:"f",value:0.1},mFresnelPower:{type:"f",value:2},mFresnelScale:{type:"f",value:1},tCube:{type:"t",value:1,texture:null}},
 fragment_shader:"uniform samplerCube tCube;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main() {\nvec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\nvec4 refractedColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nrefractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;\nrefractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;\nrefractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;\nrefractedColor.a = 1.0;\ngl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );\n}",
-vertex_shader:"attribute vec3 position;\nattribute vec3 normal;\nattribute vec3 uv;\nuniform mat4 objMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform vec3 cameraPosition;\nuniform float mRefractionRatio;\nuniform float mFresnelBias;\nuniform float mFresnelScale;\nuniform float mFresnelPower;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main(void) {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec4 mPosition = objMatrix * vec4( position, 1.0 );\nvec3 nWorld = normalize ( mat3( objMatrix[0].xyz, objMatrix[1].xyz, objMatrix[2].xyz ) * normal );\nvec3 I = mPosition.xyz - cameraPosition;\nvReflect = reflect( I, nWorld );\nvRefract[0] = refract( normalize( I ), nWorld, mRefractionRatio );\nvRefract[1] = refract( normalize( I ), nWorld, mRefractionRatio * 0.99 );\nvRefract[2] = refract( normalize( I ), nWorld, mRefractionRatio * 0.98 );\nvReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), nWorld ), mFresnelPower );\ngl_Position = projectionMatrix * mvPosition;\n}"}}},
+vertex_shader:"attribute vec3 position;\nattribute vec3 normal;\nattribute vec3 uv;\nuniform float mRefractionRatio;\nuniform float mFresnelBias;\nuniform float mFresnelScale;\nuniform float mFresnelPower;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main(void) {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = normalize ( mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal );\nvec3 I = mPosition.xyz - cameraPosition;\nvReflect = reflect( I, nWorld );\nvRefract[0] = refract( normalize( I ), nWorld, mRefractionRatio );\nvRefract[1] = refract( normalize( I ), nWorld, mRefractionRatio * 0.99 );\nvRefract[2] = refract( normalize( I ), nWorld, mRefractionRatio * 0.98 );\nvReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), nWorld ), mFresnelPower );\ngl_Position = projectionMatrix * mvPosition;\n}"}}},
 Cube=function(a,b,d,f,g,i,k){function c(w,v,z,K,u,h,e,m){var r=f||1,p=g||1,o=r+1,x=p+1;u=u/r;h=h/p;var C=j.vertices.length,S;if(w=="x"&&v=="y"||w=="y"&&v=="x")S="z";else if(w=="x"&&v=="z"||w=="z"&&v=="x")S="y";else if(w=="z"&&v=="y"||w=="y"&&v=="z")S="x";for(iy=0;iy<x;iy++)for(ix=0;ix<o;ix++){var B=new THREE.Vector3;B[w]=(ix*u-y)*z;B[v]=(iy*h-s)*K;B[S]=e;j.vertices.push(new THREE.Vertex(B))}for(iy=0;iy<p;iy++)for(ix=0;ix<r;ix++){j.faces.push(new THREE.Face4(ix+o*iy+C,ix+o*(iy+1)+C,ix+1+o*(iy+1)+C,
 ix+1+o*iy+C,null,m));j.uvs.push([new THREE.UV(ix/r,iy/p),new THREE.UV(ix/r,(iy+1)/p),new THREE.UV((ix+1)/r,(iy+1)/p),new THREE.UV((ix+1)/r,iy/p)])}}THREE.Geometry.call(this);var j=this,y=a/2,s=b/2,D=d/2;k=k?-1:1;if(i!==undefined)if(i instanceof Array)this.materials=i;else{this.materials=[];for(var q=0;q<6;q++)this.materials.push([i])}else this.materials=[];c("z","y",1*k,-1,d,b,-y,this.materials[0]);c("z","y",-1*k,-1,d,b,y,this.materials[1]);c("x","z",1*k,1,a,d,s,this.materials[2]);c("x","z",1*k,-1,
 a,d,-s,this.materials[3]);c("x","y",1*k,-1,a,b,D,this.materials[4]);c("x","y",-1*k,-1,a,b,-D,this.materials[5]);(function(){for(var w=[],v=[],z=0,K=j.vertices.length;z<K;z++){for(var u=j.vertices[z],h=false,e=0,m=w.length;e<m;e++){var r=w[e];if(u.position.x==r.position.x&&u.position.y==r.position.y&&u.position.z==r.position.z){v[z]=e;h=true;break}}if(!h){v[z]=w.length;w.push(new THREE.Vertex(u.position.clone()))}}z=0;for(K=j.faces.length;z<K;z++){u=j.faces[z];u.a=v[u.a];u.b=v[u.b];u.c=v[u.c];u.d=

+ 1 - 1
examples/materials_cars.html

@@ -466,7 +466,7 @@
 
 					if ( ! CARS[ car ].object ) {
 
-						$( "status" ).style.display = "block";
+						loader.statusDomElement.style.display = "block";
 						loader.loadBinary( CARS[ car ].url, function( geometry ) { createScene( geometry, car ) }, CARS[ car ].path );
 
 					} else {

+ 3 - 9
src/extras/ShaderUtils.js

@@ -37,13 +37,7 @@ var ShaderUtils = {
 			
 			"attribute vec3 position;",
 			"attribute vec3 normal;",
-			"attribute vec3 uv;",
-			
-			"uniform mat4 objMatrix;",
-			"uniform mat4 modelViewMatrix;",
-			"uniform mat4 projectionMatrix;",
-			
-			"uniform vec3 cameraPosition;",
+			"attribute vec3 uv;",			
 			
 			"uniform float mRefractionRatio;",
 			"uniform float mFresnelBias;",
@@ -56,9 +50,9 @@ var ShaderUtils = {
 
 			"void main(void) {",
 				"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
-				"vec4 mPosition = objMatrix * vec4( position, 1.0 );",
+				"vec4 mPosition = objectMatrix * vec4( position, 1.0 );",
 				
-				"vec3 nWorld = normalize ( mat3( objMatrix[0].xyz, objMatrix[1].xyz, objMatrix[2].xyz ) * normal );",
+				"vec3 nWorld = normalize ( mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal );",
 				
 				"vec3 I = mPosition.xyz - cameraPosition;",
 				

+ 1 - 1
src/materials/MeshShaderMaterial.js

@@ -4,7 +4,7 @@
  * parameters = {
  *  fragment_shader: <string>,
  *  vertex_shader: <string>,
- *  uniforms: [ "parameter1": value1, "parameter2": value2 ],
+ *  uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  
  *  shading: THREE.SmoothShading,
  *  blending: THREE.NormalBlending,

+ 25 - 21
src/renderers/WebGLRenderer.js

@@ -27,7 +27,7 @@ THREE.WebGLRenderer = function ( scene ) {
 	_modelViewMatrixArray = new Float32Array(16), 
 	_projectionMatrixArray = new Float32Array(16), 
 	_normalMatrixArray = new Float32Array(9),
-	_objMatrixArray = new Float32Array(16),
+	_objectMatrixArray = new Float32Array(16),
 
 	// ubershader material constants
 	
@@ -332,7 +332,7 @@ THREE.WebGLRenderer = function ( scene ) {
 				
 				material.program = buildProgram( material.fragment_shader, material.vertex_shader );
 				
-				identifiers = [ 'viewMatrix', 'modelViewMatrix', 'projectionMatrix', 'normalMatrix', 'objMatrix', 'cameraPosition' ];
+				identifiers = [ 'viewMatrix', 'modelViewMatrix', 'projectionMatrix', 'normalMatrix', 'objectMatrix', 'cameraPosition' ];
 				for( u in material.uniforms ) identifiers.push(u);
 				cacheUniformLocations( material.program, identifiers );
 				cacheAttributeLocations( material.program );
@@ -740,7 +740,7 @@ THREE.WebGLRenderer = function ( scene ) {
 		_normalMatrix = THREE.Matrix4.makeInvert3x3( _modelViewMatrix ).transpose();
 		_normalMatrixArray.set( _normalMatrix.m );
 
-		_objMatrixArray.set( object.matrix.flatten() );
+		_objectMatrixArray.set( object.matrix.flatten() );
 	
 	};
 	
@@ -750,7 +750,7 @@ THREE.WebGLRenderer = function ( scene ) {
 		_gl.uniformMatrix4fv( program.uniforms.modelViewMatrix, false, _modelViewMatrixArray );
 		_gl.uniformMatrix4fv( program.uniforms.projectionMatrix, false, _projectionMatrixArray );
 		_gl.uniformMatrix3fv( program.uniforms.normalMatrix, false, _normalMatrixArray );
-		_gl.uniformMatrix4fv( program.uniforms.objMatrix, false, _objMatrixArray );
+		_gl.uniformMatrix4fv( program.uniforms.objectMatrix, false, _objectMatrixArray );
 		
 	};
 
@@ -1086,8 +1086,6 @@ THREE.WebGLRenderer = function ( scene ) {
 			"attribute vec3 normal;",
 			"attribute vec2 uv;",
 
-			"uniform vec3 cameraPosition;",
-
 			"uniform bool enableLighting;",
 			"uniform bool useRefract;",
 
@@ -1102,10 +1100,7 @@ THREE.WebGLRenderer = function ( scene ) {
 			maxPointLights ? "uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];"    : "",
 			maxPointLights ? "uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];" : "",
 
-			"uniform mat4 objMatrix;",
 			"uniform mat4 viewMatrix;",
-			"uniform mat4 modelViewMatrix;",
-			"uniform mat4 projectionMatrix;",
 			"uniform mat3 normalMatrix;",
 
 			"varying vec3 vNormal;",
@@ -1124,12 +1119,12 @@ THREE.WebGLRenderer = function ( scene ) {
 
 				// world space
 
-				"vec4 mPosition = objMatrix * vec4( position, 1.0 );",
+				"vec4 mPosition = objectMatrix * vec4( position, 1.0 );",
 				"vViewPosition = cameraPosition - mPosition.xyz;",
 
 				// this doesn't work on Mac
-				//"vec3 nWorld = mat3(objMatrix) * normal;",
-				"vec3 nWorld = mat3( objMatrix[0].xyz, objMatrix[1].xyz, objMatrix[2].xyz ) * normal;",
+				//"vec3 nWorld = mat3(objectMatrix) * normal;",
+				"vec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;",
 
 				// eye space
 
@@ -1188,14 +1183,23 @@ THREE.WebGLRenderer = function ( scene ) {
 		
 		var program = _gl.createProgram(),
 		
-		prefix = [ "#ifdef GL_ES",
-				   "precision highp float;",
-				   "#endif",
-				   ""
-			     ].join("\n");
-
-		_gl.attachShader( program, getShader( "fragment", prefix + fragment_shader ) );
-		_gl.attachShader( program, getShader( "vertex", vertex_shader ) );
+		prefix_fragment = [
+			"#ifdef GL_ES",
+			"precision highp float;",
+			"#endif",
+			""
+		].join("\n"),
+
+		prefix_vertex = [
+			"uniform mat4 objectMatrix;",
+			"uniform mat4 modelViewMatrix;",
+			"uniform mat4 projectionMatrix;",
+			"uniform vec3 cameraPosition;",
+			""
+		].join("\n");
+		
+		_gl.attachShader( program, getShader( "fragment", prefix_fragment + fragment_shader ) );
+		_gl.attachShader( program, getShader( "vertex", prefix_vertex + vertex_shader ) );
 		
 		_gl.linkProgram( program );
 
@@ -1322,7 +1326,7 @@ THREE.WebGLRenderer = function ( scene ) {
 		// material properties (Basic / Lambert / Blinn-Phong shader)
 		// material properties (Depth)
 
-		cacheUniformLocations( _program, [ 'viewMatrix', 'modelViewMatrix', 'projectionMatrix', 'normalMatrix', 'objMatrix', 'cameraPosition',
+		cacheUniformLocations( _program, [ 'viewMatrix', 'modelViewMatrix', 'projectionMatrix', 'normalMatrix', 'objectMatrix', 'cameraPosition',
 										   'enableLighting', 'ambientLightColor',
 										   'material', 'mColor', 'mAmbient', 'mSpecular', 'mShininess', 'mOpacity',
 										   'enableMap', 'tMap',