浏览代码

Fixed vertex shader to work in Mac.

alteredq 14 年之前
父节点
当前提交
0610f5734f
共有 3 个文件被更改,包括 59 次插入55 次删除
  1. 28 27
      build/Three.js
  2. 28 27
      build/ThreeDebug.js
  3. 3 1
      src/renderers/WebGLRenderer.js

+ 28 - 27
build/Three.js

@@ -126,32 +126,33 @@ g?"vec4 pointDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",g?"vec4 pointSpecular =
 "",e?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",e?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",e?"float dirSpecularWeight = 0.0;":"",e?"if ( dirDotNormalHalf >= 0.0 )":"",e?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",e?"dirDiffuse  += mColor * dirDiffuseWeight;":"",e?"dirSpecular += mSpecular * dirSpecularWeight;":"",e?"}":"","vec4 totalLight = mAmbient;",e?"totalLight += dirDiffuse + dirSpecular;":"",g?"totalLight += pointDiffuse + pointSpecular;":
 "","gl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );\n} else if ( material == 1 ) {\ngl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );\n} else {\ngl_FragColor = mColor * mapColor * cubeColor;\n}\n}"].join("\n")));b.attachShader(d,c("vertex",[e?"#define MAX_DIR_LIGHTS "+e:"",g?"#define MAX_POINT_LIGHTS "+g:"","attribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\nuniform vec3 cameraPosition;\nuniform bool enableLighting;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",
 e?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",e?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",g?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",g?"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;",g?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":
-"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nvoid main(void) {\nvec4 mPosition = objMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 nWorld = mat3(objMatrix) * 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;",e?"for( int i = 0; i < directionalLightNumber; i++ ) {":
-"",e?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",e?"float directionalLightWeighting = max( dot( transformedNormal, normalize(lDirection.xyz ) ), 0.0 );":"",e?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",e?"}":"",g?"for( int i = 0; i < pointLightNumber; i++ ) {":"",g?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",g?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":"",g?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":
-"",g?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",g?"}":"","}\nvNormal = transformedNormal;\nvUv = uv;\nvReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n")));b.linkProgram(d);b.getProgramParameter(d,b.LINK_STATUS)||alert("Could not initialise shaders");b.useProgram(d);d.viewMatrix=b.getUniformLocation(d,"viewMatrix");d.modelViewMatrix=b.getUniformLocation(d,"modelViewMatrix");d.projectionMatrix=
-b.getUniformLocation(d,"projectionMatrix");d.normalMatrix=b.getUniformLocation(d,"normalMatrix");d.objMatrix=b.getUniformLocation(d,"objMatrix");d.cameraPosition=b.getUniformLocation(d,"cameraPosition");d.enableLighting=b.getUniformLocation(d,"enableLighting");d.ambientLightColor=b.getUniformLocation(d,"ambientLightColor");if(e){d.directionalLightNumber=b.getUniformLocation(d,"directionalLightNumber");d.directionalLightColor=b.getUniformLocation(d,"directionalLightColor");d.directionalLightDirection=
-b.getUniformLocation(d,"directionalLightDirection")}if(g){d.pointLightNumber=b.getUniformLocation(d,"pointLightNumber");d.pointLightColor=b.getUniformLocation(d,"pointLightColor");d.pointLightPosition=b.getUniformLocation(d,"pointLightPosition")}d.material=b.getUniformLocation(d,"material");d.mColor=b.getUniformLocation(d,"mColor");d.mOpacity=b.getUniformLocation(d,"mOpacity");d.mReflectivity=b.getUniformLocation(d,"mReflectivity");d.mAmbient=b.getUniformLocation(d,"mAmbient");d.mSpecular=b.getUniformLocation(d,
-"mSpecular");d.mShininess=b.getUniformLocation(d,"mShininess");d.enableMap=b.getUniformLocation(d,"enableMap");b.uniform1i(d.enableMap,0);d.tMap=b.getUniformLocation(d,"tMap");b.uniform1i(d.tMap,0);d.enableCubeMap=b.getUniformLocation(d,"enableCubeMap");b.uniform1i(d.enableCubeMap,0);d.tCube=b.getUniformLocation(d,"tCube");b.uniform1i(d.tCube,1);d.m2Near=b.getUniformLocation(d,"m2Near");d.mFarPlusNear=b.getUniformLocation(d,"mFarPlusNear");d.mFarMinusNear=b.getUniformLocation(d,"mFarMinusNear");d.position=
-b.getAttribLocation(d,"position");b.enableVertexAttribArray(d.position);d.normal=b.getAttribLocation(d,"normal");b.enableVertexAttribArray(d.normal);d.uv=b.getAttribLocation(d,"uv");b.enableVertexAttribArray(d.uv);d.viewMatrixArray=new Float32Array(16);d.modelViewMatrixArray=new Float32Array(16);d.projectionMatrixArray=new Float32Array(16)})(a.directional,a.point);this.setSize=function(e,g){f.width=e;f.height=g;b.viewport(0,0,f.width,f.height)};this.clear=function(){b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT)};
-this.setupLights=function(e){var g,m,h,l,r=[],o=[],p=[];l=[];var w=[];b.uniform1i(d.enableLighting,e.lights.length);g=0;for(m=e.lights.length;g<m;g++){h=e.lights[g];if(h instanceof THREE.AmbientLight)r.push(h);else if(h instanceof THREE.DirectionalLight)p.push(h);else h instanceof THREE.PointLight&&o.push(h)}g=e=h=l=0;for(m=r.length;g<m;g++){e+=r[g].color.r;h+=r[g].color.g;l+=r[g].color.b}b.uniform3f(d.ambientLightColor,e,h,l);l=[];w=[];g=0;for(m=p.length;g<m;g++){h=p[g];l.push(h.color.r*h.intensity);
-l.push(h.color.g*h.intensity);l.push(h.color.b*h.intensity);w.push(h.position.x);w.push(h.position.y);w.push(h.position.z)}if(p.length){b.uniform1i(d.directionalLightNumber,p.length);b.uniform3fv(d.directionalLightDirection,w);b.uniform3fv(d.directionalLightColor,l)}l=[];w=[];g=0;for(m=o.length;g<m;g++){h=o[g];l.push(h.color.r*h.intensity);l.push(h.color.g*h.intensity);l.push(h.color.b*h.intensity);w.push(h.position.x);w.push(h.position.y);w.push(h.position.z)}if(o.length){b.uniform1i(d.pointLightNumber,
-o.length);b.uniform3fv(d.pointLightPosition,w);b.uniform3fv(d.pointLightColor,l)}};this.createBuffers=function(e,g){var m,h,l,r,o,p,w,i,B,q=e.materialFaceGroup[g],D=[],u=[],L=[],v=[],s=[],x=0,M=false;m=0;for(h=e.material.length;m<h;m++){meshMaterial=e.material[m];if(meshMaterial instanceof THREE.MeshFaceMaterial){o=0;for(p=q.material.length;o<p;o++)if(q.material[o]&&q.material[o].shading!=undefined&&q.material[o].shading==THREE.SmoothShading){M=true;break}}else if(meshMaterial&&meshMaterial.shading!=
-undefined&&meshMaterial.shading==THREE.SmoothShading){M=true;break}if(M)break}m=0;for(h=q.faces.length;m<h;m++){l=q.faces[m];r=e.geometry.faces[l];o=r.vertexNormals;p=r.normal;l=e.geometry.uvs[l];if(r instanceof THREE.Face3){w=e.geometry.vertices[r.a].position;i=e.geometry.vertices[r.b].position;B=e.geometry.vertices[r.c].position;L.push(w.x,w.y,w.z);L.push(i.x,i.y,i.z);L.push(B.x,B.y,B.z);if(o.length==3&&M){v.push(o[0].x,o[0].y,o[0].z);v.push(o[1].x,o[1].y,o[1].z);v.push(o[2].x,o[2].y,o[2].z)}else{v.push(p.x,
-p.y,p.z);v.push(p.x,p.y,p.z);v.push(p.x,p.y,p.z)}if(l){s.push(l[0].u,l[0].v);s.push(l[1].u,l[1].v);s.push(l[2].u,l[2].v)}D.push(x,x+1,x+2);u.push(x,x+1);u.push(x,x+2);u.push(x+1,x+2);x+=3}else if(r instanceof THREE.Face4){w=e.geometry.vertices[r.a].position;i=e.geometry.vertices[r.b].position;B=e.geometry.vertices[r.c].position;r=e.geometry.vertices[r.d].position;L.push(w.x,w.y,w.z);L.push(i.x,i.y,i.z);L.push(B.x,B.y,B.z);L.push(r.x,r.y,r.z);if(o.length==4&&M){v.push(o[0].x,o[0].y,o[0].z);v.push(o[1].x,
-o[1].y,o[1].z);v.push(o[2].x,o[2].y,o[2].z);v.push(o[3].x,o[3].y,o[3].z)}else{v.push(p.x,p.y,p.z);v.push(p.x,p.y,p.z);v.push(p.x,p.y,p.z);v.push(p.x,p.y,p.z)}if(l){s.push(l[0].u,l[0].v);s.push(l[1].u,l[1].v);s.push(l[2].u,l[2].v);s.push(l[3].u,l[3].v)}D.push(x,x+1,x+2);D.push(x,x+2,x+3);u.push(x,x+1);u.push(x,x+2);u.push(x,x+3);u.push(x+1,x+2);u.push(x+2,x+3);x+=4}}if(L.length){q.__webGLVertexBuffer=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,q.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,new Float32Array(L),
-b.STATIC_DRAW);q.__webGLNormalBuffer=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,q.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,new Float32Array(v),b.STATIC_DRAW);q.__webGLUVBuffer=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,q.__webGLUVBuffer);b.bufferData(b.ARRAY_BUFFER,new Float32Array(s),b.STATIC_DRAW);q.__webGLFaceBuffer=b.createBuffer();b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,q.__webGLFaceBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,new Uint16Array(D),b.STATIC_DRAW);q.__webGLLineBuffer=b.createBuffer();
-b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,q.__webGLLineBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,new Uint16Array(u),b.STATIC_DRAW);q.__webGLFaceCount=D.length;q.__webGLLineCount=u.length}};this.renderBuffer=function(e,g){var m,h,l,r,o,p,w,i;if(e instanceof THREE.MeshPhongMaterial||e instanceof THREE.MeshLambertMaterial||e instanceof THREE.MeshBasicMaterial){m=e.color;h=e.opacity;l=e.reflectivity;r=e.wireframe;o=e.wireframe_linewidth;w=e.map;i=e.env_map;b.uniform4f(d.mColor,m.r*h,m.g*h,m.b*h,h);b.uniform1f(d.mReflectivity,
-l)}if(e instanceof THREE.MeshNormalMaterial){h=e.opacity;b.uniform1f(d.mOpacity,h);b.uniform1i(d.material,4)}else if(e instanceof THREE.MeshDepthMaterial){h=e.opacity;r=e.wireframe;o=e.wireframe_linewidth;b.uniform1f(d.mOpacity,h);b.uniform1f(d.m2Near,e.__2near);b.uniform1f(d.mFarPlusNear,e.__farPlusNear);b.uniform1f(d.mFarMinusNear,e.__farMinusNear);b.uniform1i(d.material,3)}else if(e instanceof THREE.MeshPhongMaterial){m=e.ambient;l=e.specular;p=e.shininess;b.uniform4f(d.mAmbient,m.r,m.g,m.b,h);
-b.uniform4f(d.mSpecular,l.r,l.g,l.b,h);b.uniform1f(d.mShininess,p);b.uniform1i(d.material,2)}else if(e instanceof THREE.MeshLambertMaterial)b.uniform1i(d.material,1);else e instanceof THREE.MeshBasicMaterial&&b.uniform1i(d.material,0);if(w){if(!e.__webGLTexture&&e.map.image.loaded){e.__webGLTexture=b.createTexture();b.bindTexture(b.TEXTURE_2D,e.__webGLTexture);b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.map.image);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,b.LINEAR);b.texParameteri(b.TEXTURE_2D,
-b.TEXTURE_MIN_FILTER,b.LINEAR_MIPMAP_LINEAR);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}b.activeTexture(b.TEXTURE0);b.bindTexture(b.TEXTURE_2D,e.__webGLTexture);b.uniform1i(d.tMap,0);b.uniform1i(d.enableMap,1)}else b.uniform1i(d.enableMap,0);if(i){if(e.env_map&&e.env_map instanceof THREE.TextureCube&&e.env_map.image.length==6){if(!e.__webGLTextureCube&&!e.__cubeMapInitialized&&e.env_map.image.loadCount==6){e.__webGLTextureCube=b.createTexture();b.bindTexture(b.TEXTURE_CUBE_MAP,
-e.__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);b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[0]);b.texImage2D(b.TEXTURE_CUBE_MAP_NEGATIVE_X,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[1]);b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_Y,
-0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[2]);b.texImage2D(b.TEXTURE_CUBE_MAP_NEGATIVE_Y,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[3]);b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_Z,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[4]);b.texImage2D(b.TEXTURE_CUBE_MAP_NEGATIVE_Z,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[5]);b.generateMipmap(b.TEXTURE_CUBE_MAP);b.bindTexture(b.TEXTURE_CUBE_MAP,null);e.__cubeMapInitialized=true}b.activeTexture(b.TEXTURE1);b.bindTexture(b.TEXTURE_CUBE_MAP,
-e.__webGLTextureCube);b.uniform1i(d.tCube,1)}b.uniform1i(d.enableCubeMap,1)}else b.uniform1i(d.enableCubeMap,0);b.bindBuffer(b.ARRAY_BUFFER,g.__webGLVertexBuffer);b.vertexAttribPointer(d.position,3,b.FLOAT,false,0,0);b.bindBuffer(b.ARRAY_BUFFER,g.__webGLNormalBuffer);b.vertexAttribPointer(d.normal,3,b.FLOAT,false,0,0);if(w){b.bindBuffer(b.ARRAY_BUFFER,g.__webGLUVBuffer);b.enableVertexAttribArray(d.uv);b.vertexAttribPointer(d.uv,2,b.FLOAT,false,0,0)}else b.disableVertexAttribArray(d.uv);if(r){b.lineWidth(o);
-b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,g.__webGLLineBuffer);b.drawElements(b.LINES,g.__webGLLineCount,b.UNSIGNED_SHORT,0)}else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,g.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,g.__webGLFaceCount,b.UNSIGNED_SHORT,0)}};this.renderPass=function(e,g,m){var h,l,r,o,p;r=0;for(o=e.material.length;r<o;r++){h=e.material[r];if(h instanceof THREE.MeshFaceMaterial){h=0;for(l=g.material.length;h<l;h++)if((p=g.material[h])&&p.blending==m){this.setBlending(p.blending);this.renderBuffer(p,
-g)}}else if((p=h)&&p.blending==m){this.setBlending(p.blending);this.renderBuffer(p,g)}}};this.render=function(e,g){var m,h;this.initWebGLObjects(e);this.autoClear&&this.clear();g.autoUpdateMatrix&&g.updateMatrix();b.uniform3f(d.cameraPosition,g.position.x,g.position.y,g.position.z);this.setupLights(e);m=0;for(h=e.__webGLObjects.length;m<h;m++){webGLObject=e.__webGLObjects[m];this.setupMatrices(webGLObject.__object,g);this.renderPass(webGLObject.__object,webGLObject,THREE.NormalBlending)}m=0;for(h=
-e.__webGLObjects.length;m<h;m++){webGLObject=e.__webGLObjects[m];this.setupMatrices(webGLObject.__object,g);this.renderPass(webGLObject.__object,webGLObject,THREE.AdditiveBlending);this.renderPass(webGLObject.__object,webGLObject,THREE.SubtractiveBlending)}};this.initWebGLObjects=function(e){var g,m,h,l,r;if(!e.__webGLObjects)e.__webGLObjects=[];g=0;for(m=e.objects.length;g<m;g++){h=e.objects[g];if(h instanceof THREE.Mesh)for(l in h.materialFaceGroup){r=h.materialFaceGroup[l];if(!r.__webGLVertexBuffer){this.createBuffers(h,
-l);r.__object=h;e.__webGLObjects.push(r)}}}};this.setupMatrices=function(e,g){e.autoUpdateMatrix&&e.updateMatrix();j.multiply(g.matrix,e.matrix);d.viewMatrixArray=new Float32Array(g.matrix.flatten());d.modelViewMatrixArray=new Float32Array(j.flatten());d.projectionMatrixArray=new Float32Array(g.projectionMatrix.flatten());n=THREE.Matrix4.makeInvert3x3(j).transpose();d.normalMatrixArray=new Float32Array(n.m);b.uniformMatrix4fv(d.viewMatrix,false,d.viewMatrixArray);b.uniformMatrix4fv(d.modelViewMatrix,
-false,d.modelViewMatrixArray);b.uniformMatrix4fv(d.projectionMatrix,false,d.projectionMatrixArray);b.uniformMatrix3fv(d.normalMatrix,false,d.normalMatrixArray);b.uniformMatrix4fv(d.objMatrix,false,new Float32Array(e.matrix.flatten()))};this.setBlending=function(e){switch(e){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(e,g){if(e){!g||g=="ccw"?b.frontFace(b.CCW):b.frontFace(b.CW);if(e=="back")b.cullFace(b.BACK);else e=="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.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.material=this.color=this.z=null};
+"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\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;",
+e?"for( int i = 0; i < directionalLightNumber; i++ ) {":"",e?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",e?"float directionalLightWeighting = max( dot( transformedNormal, normalize(lDirection.xyz ) ), 0.0 );":"",e?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",e?"}":"",g?"for( int i = 0; i < pointLightNumber; i++ ) {":"",g?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",g?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
+"",g?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",g?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",g?"}":"","}\nvNormal = transformedNormal;\nvUv = uv;\nvReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n")));b.linkProgram(d);b.getProgramParameter(d,b.LINK_STATUS)||alert("Could not initialise shaders");b.useProgram(d);d.viewMatrix=b.getUniformLocation(d,
+"viewMatrix");d.modelViewMatrix=b.getUniformLocation(d,"modelViewMatrix");d.projectionMatrix=b.getUniformLocation(d,"projectionMatrix");d.normalMatrix=b.getUniformLocation(d,"normalMatrix");d.objMatrix=b.getUniformLocation(d,"objMatrix");d.cameraPosition=b.getUniformLocation(d,"cameraPosition");d.enableLighting=b.getUniformLocation(d,"enableLighting");d.ambientLightColor=b.getUniformLocation(d,"ambientLightColor");if(e){d.directionalLightNumber=b.getUniformLocation(d,"directionalLightNumber");d.directionalLightColor=
+b.getUniformLocation(d,"directionalLightColor");d.directionalLightDirection=b.getUniformLocation(d,"directionalLightDirection")}if(g){d.pointLightNumber=b.getUniformLocation(d,"pointLightNumber");d.pointLightColor=b.getUniformLocation(d,"pointLightColor");d.pointLightPosition=b.getUniformLocation(d,"pointLightPosition")}d.material=b.getUniformLocation(d,"material");d.mColor=b.getUniformLocation(d,"mColor");d.mOpacity=b.getUniformLocation(d,"mOpacity");d.mReflectivity=b.getUniformLocation(d,"mReflectivity");
+d.mAmbient=b.getUniformLocation(d,"mAmbient");d.mSpecular=b.getUniformLocation(d,"mSpecular");d.mShininess=b.getUniformLocation(d,"mShininess");d.enableMap=b.getUniformLocation(d,"enableMap");b.uniform1i(d.enableMap,0);d.tMap=b.getUniformLocation(d,"tMap");b.uniform1i(d.tMap,0);d.enableCubeMap=b.getUniformLocation(d,"enableCubeMap");b.uniform1i(d.enableCubeMap,0);d.tCube=b.getUniformLocation(d,"tCube");b.uniform1i(d.tCube,1);d.m2Near=b.getUniformLocation(d,"m2Near");d.mFarPlusNear=b.getUniformLocation(d,
+"mFarPlusNear");d.mFarMinusNear=b.getUniformLocation(d,"mFarMinusNear");d.position=b.getAttribLocation(d,"position");b.enableVertexAttribArray(d.position);d.normal=b.getAttribLocation(d,"normal");b.enableVertexAttribArray(d.normal);d.uv=b.getAttribLocation(d,"uv");b.enableVertexAttribArray(d.uv);d.viewMatrixArray=new Float32Array(16);d.modelViewMatrixArray=new Float32Array(16);d.projectionMatrixArray=new Float32Array(16)})(a.directional,a.point);this.setSize=function(e,g){f.width=e;f.height=g;b.viewport(0,
+0,f.width,f.height)};this.clear=function(){b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT)};this.setupLights=function(e){var g,m,h,l,r=[],o=[],p=[];l=[];var w=[];b.uniform1i(d.enableLighting,e.lights.length);g=0;for(m=e.lights.length;g<m;g++){h=e.lights[g];if(h instanceof THREE.AmbientLight)r.push(h);else if(h instanceof THREE.DirectionalLight)p.push(h);else h instanceof THREE.PointLight&&o.push(h)}g=e=h=l=0;for(m=r.length;g<m;g++){e+=r[g].color.r;h+=r[g].color.g;l+=r[g].color.b}b.uniform3f(d.ambientLightColor,
+e,h,l);l=[];w=[];g=0;for(m=p.length;g<m;g++){h=p[g];l.push(h.color.r*h.intensity);l.push(h.color.g*h.intensity);l.push(h.color.b*h.intensity);w.push(h.position.x);w.push(h.position.y);w.push(h.position.z)}if(p.length){b.uniform1i(d.directionalLightNumber,p.length);b.uniform3fv(d.directionalLightDirection,w);b.uniform3fv(d.directionalLightColor,l)}l=[];w=[];g=0;for(m=o.length;g<m;g++){h=o[g];l.push(h.color.r*h.intensity);l.push(h.color.g*h.intensity);l.push(h.color.b*h.intensity);w.push(h.position.x);
+w.push(h.position.y);w.push(h.position.z)}if(o.length){b.uniform1i(d.pointLightNumber,o.length);b.uniform3fv(d.pointLightPosition,w);b.uniform3fv(d.pointLightColor,l)}};this.createBuffers=function(e,g){var m,h,l,r,o,p,w,i,B,q=e.materialFaceGroup[g],D=[],u=[],L=[],v=[],s=[],x=0,M=false;m=0;for(h=e.material.length;m<h;m++){meshMaterial=e.material[m];if(meshMaterial instanceof THREE.MeshFaceMaterial){o=0;for(p=q.material.length;o<p;o++)if(q.material[o]&&q.material[o].shading!=undefined&&q.material[o].shading==
+THREE.SmoothShading){M=true;break}}else if(meshMaterial&&meshMaterial.shading!=undefined&&meshMaterial.shading==THREE.SmoothShading){M=true;break}if(M)break}m=0;for(h=q.faces.length;m<h;m++){l=q.faces[m];r=e.geometry.faces[l];o=r.vertexNormals;p=r.normal;l=e.geometry.uvs[l];if(r instanceof THREE.Face3){w=e.geometry.vertices[r.a].position;i=e.geometry.vertices[r.b].position;B=e.geometry.vertices[r.c].position;L.push(w.x,w.y,w.z);L.push(i.x,i.y,i.z);L.push(B.x,B.y,B.z);if(o.length==3&&M){v.push(o[0].x,
+o[0].y,o[0].z);v.push(o[1].x,o[1].y,o[1].z);v.push(o[2].x,o[2].y,o[2].z)}else{v.push(p.x,p.y,p.z);v.push(p.x,p.y,p.z);v.push(p.x,p.y,p.z)}if(l){s.push(l[0].u,l[0].v);s.push(l[1].u,l[1].v);s.push(l[2].u,l[2].v)}D.push(x,x+1,x+2);u.push(x,x+1);u.push(x,x+2);u.push(x+1,x+2);x+=3}else if(r instanceof THREE.Face4){w=e.geometry.vertices[r.a].position;i=e.geometry.vertices[r.b].position;B=e.geometry.vertices[r.c].position;r=e.geometry.vertices[r.d].position;L.push(w.x,w.y,w.z);L.push(i.x,i.y,i.z);L.push(B.x,
+B.y,B.z);L.push(r.x,r.y,r.z);if(o.length==4&&M){v.push(o[0].x,o[0].y,o[0].z);v.push(o[1].x,o[1].y,o[1].z);v.push(o[2].x,o[2].y,o[2].z);v.push(o[3].x,o[3].y,o[3].z)}else{v.push(p.x,p.y,p.z);v.push(p.x,p.y,p.z);v.push(p.x,p.y,p.z);v.push(p.x,p.y,p.z)}if(l){s.push(l[0].u,l[0].v);s.push(l[1].u,l[1].v);s.push(l[2].u,l[2].v);s.push(l[3].u,l[3].v)}D.push(x,x+1,x+2);D.push(x,x+2,x+3);u.push(x,x+1);u.push(x,x+2);u.push(x,x+3);u.push(x+1,x+2);u.push(x+2,x+3);x+=4}}if(L.length){q.__webGLVertexBuffer=b.createBuffer();
+b.bindBuffer(b.ARRAY_BUFFER,q.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,new Float32Array(L),b.STATIC_DRAW);q.__webGLNormalBuffer=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,q.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,new Float32Array(v),b.STATIC_DRAW);q.__webGLUVBuffer=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,q.__webGLUVBuffer);b.bufferData(b.ARRAY_BUFFER,new Float32Array(s),b.STATIC_DRAW);q.__webGLFaceBuffer=b.createBuffer();b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,q.__webGLFaceBuffer);
+b.bufferData(b.ELEMENT_ARRAY_BUFFER,new Uint16Array(D),b.STATIC_DRAW);q.__webGLLineBuffer=b.createBuffer();b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,q.__webGLLineBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,new Uint16Array(u),b.STATIC_DRAW);q.__webGLFaceCount=D.length;q.__webGLLineCount=u.length}};this.renderBuffer=function(e,g){var m,h,l,r,o,p,w,i;if(e instanceof THREE.MeshPhongMaterial||e instanceof THREE.MeshLambertMaterial||e instanceof THREE.MeshBasicMaterial){m=e.color;h=e.opacity;l=e.reflectivity;
+r=e.wireframe;o=e.wireframe_linewidth;w=e.map;i=e.env_map;b.uniform4f(d.mColor,m.r*h,m.g*h,m.b*h,h);b.uniform1f(d.mReflectivity,l)}if(e instanceof THREE.MeshNormalMaterial){h=e.opacity;b.uniform1f(d.mOpacity,h);b.uniform1i(d.material,4)}else if(e instanceof THREE.MeshDepthMaterial){h=e.opacity;r=e.wireframe;o=e.wireframe_linewidth;b.uniform1f(d.mOpacity,h);b.uniform1f(d.m2Near,e.__2near);b.uniform1f(d.mFarPlusNear,e.__farPlusNear);b.uniform1f(d.mFarMinusNear,e.__farMinusNear);b.uniform1i(d.material,
+3)}else if(e instanceof THREE.MeshPhongMaterial){m=e.ambient;l=e.specular;p=e.shininess;b.uniform4f(d.mAmbient,m.r,m.g,m.b,h);b.uniform4f(d.mSpecular,l.r,l.g,l.b,h);b.uniform1f(d.mShininess,p);b.uniform1i(d.material,2)}else if(e instanceof THREE.MeshLambertMaterial)b.uniform1i(d.material,1);else e instanceof THREE.MeshBasicMaterial&&b.uniform1i(d.material,0);if(w){if(!e.__webGLTexture&&e.map.image.loaded){e.__webGLTexture=b.createTexture();b.bindTexture(b.TEXTURE_2D,e.__webGLTexture);b.texImage2D(b.TEXTURE_2D,
+0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.map.image);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,b.LINEAR);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,b.LINEAR_MIPMAP_LINEAR);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}b.activeTexture(b.TEXTURE0);b.bindTexture(b.TEXTURE_2D,e.__webGLTexture);b.uniform1i(d.tMap,0);b.uniform1i(d.enableMap,1)}else b.uniform1i(d.enableMap,0);if(i){if(e.env_map&&e.env_map instanceof THREE.TextureCube&&e.env_map.image.length==6){if(!e.__webGLTextureCube&&
+!e.__cubeMapInitialized&&e.env_map.image.loadCount==6){e.__webGLTextureCube=b.createTexture();b.bindTexture(b.TEXTURE_CUBE_MAP,e.__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);b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,
+e.env_map.image[0]);b.texImage2D(b.TEXTURE_CUBE_MAP_NEGATIVE_X,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[1]);b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_Y,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[2]);b.texImage2D(b.TEXTURE_CUBE_MAP_NEGATIVE_Y,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[3]);b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_Z,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[4]);b.texImage2D(b.TEXTURE_CUBE_MAP_NEGATIVE_Z,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[5]);b.generateMipmap(b.TEXTURE_CUBE_MAP);
+b.bindTexture(b.TEXTURE_CUBE_MAP,null);e.__cubeMapInitialized=true}b.activeTexture(b.TEXTURE1);b.bindTexture(b.TEXTURE_CUBE_MAP,e.__webGLTextureCube);b.uniform1i(d.tCube,1)}b.uniform1i(d.enableCubeMap,1)}else b.uniform1i(d.enableCubeMap,0);b.bindBuffer(b.ARRAY_BUFFER,g.__webGLVertexBuffer);b.vertexAttribPointer(d.position,3,b.FLOAT,false,0,0);b.bindBuffer(b.ARRAY_BUFFER,g.__webGLNormalBuffer);b.vertexAttribPointer(d.normal,3,b.FLOAT,false,0,0);if(w){b.bindBuffer(b.ARRAY_BUFFER,g.__webGLUVBuffer);
+b.enableVertexAttribArray(d.uv);b.vertexAttribPointer(d.uv,2,b.FLOAT,false,0,0)}else b.disableVertexAttribArray(d.uv);if(r){b.lineWidth(o);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,g.__webGLLineBuffer);b.drawElements(b.LINES,g.__webGLLineCount,b.UNSIGNED_SHORT,0)}else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,g.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,g.__webGLFaceCount,b.UNSIGNED_SHORT,0)}};this.renderPass=function(e,g,m){var h,l,r,o,p;r=0;for(o=e.material.length;r<o;r++){h=e.material[r];if(h instanceof
+THREE.MeshFaceMaterial){h=0;for(l=g.material.length;h<l;h++)if((p=g.material[h])&&p.blending==m){this.setBlending(p.blending);this.renderBuffer(p,g)}}else if((p=h)&&p.blending==m){this.setBlending(p.blending);this.renderBuffer(p,g)}}};this.render=function(e,g){var m,h;this.initWebGLObjects(e);this.autoClear&&this.clear();g.autoUpdateMatrix&&g.updateMatrix();b.uniform3f(d.cameraPosition,g.position.x,g.position.y,g.position.z);this.setupLights(e);m=0;for(h=e.__webGLObjects.length;m<h;m++){webGLObject=
+e.__webGLObjects[m];this.setupMatrices(webGLObject.__object,g);this.renderPass(webGLObject.__object,webGLObject,THREE.NormalBlending)}m=0;for(h=e.__webGLObjects.length;m<h;m++){webGLObject=e.__webGLObjects[m];this.setupMatrices(webGLObject.__object,g);this.renderPass(webGLObject.__object,webGLObject,THREE.AdditiveBlending);this.renderPass(webGLObject.__object,webGLObject,THREE.SubtractiveBlending)}};this.initWebGLObjects=function(e){var g,m,h,l,r;if(!e.__webGLObjects)e.__webGLObjects=[];g=0;for(m=
+e.objects.length;g<m;g++){h=e.objects[g];if(h instanceof THREE.Mesh)for(l in h.materialFaceGroup){r=h.materialFaceGroup[l];if(!r.__webGLVertexBuffer){this.createBuffers(h,l);r.__object=h;e.__webGLObjects.push(r)}}}};this.setupMatrices=function(e,g){e.autoUpdateMatrix&&e.updateMatrix();j.multiply(g.matrix,e.matrix);d.viewMatrixArray=new Float32Array(g.matrix.flatten());d.modelViewMatrixArray=new Float32Array(j.flatten());d.projectionMatrixArray=new Float32Array(g.projectionMatrix.flatten());n=THREE.Matrix4.makeInvert3x3(j).transpose();
+d.normalMatrixArray=new Float32Array(n.m);b.uniformMatrix4fv(d.viewMatrix,false,d.viewMatrixArray);b.uniformMatrix4fv(d.modelViewMatrix,false,d.modelViewMatrixArray);b.uniformMatrix4fv(d.projectionMatrix,false,d.projectionMatrixArray);b.uniformMatrix3fv(d.normalMatrix,false,d.normalMatrixArray);b.uniformMatrix4fv(d.objMatrix,false,new Float32Array(e.matrix.flatten()))};this.setBlending=function(e){switch(e){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(e,g){if(e){!g||g=="ccw"?b.frontFace(b.CCW):b.frontFace(b.CW);if(e=="back")b.cullFace(b.BACK);else e=="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.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.material=this.color=this.z=null};
 THREE.RenderableFace4=function(){this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.v4=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.material=this.color=this.z=null};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=this.color=null};
 THREE.RenderableLine=function(){this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=this.color=this.z=null};

+ 28 - 27
build/ThreeDebug.js

@@ -127,32 +127,33 @@ g?"vec4 pointDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",g?"vec4 pointSpecular =
 "",e?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",e?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",e?"float dirSpecularWeight = 0.0;":"",e?"if ( dirDotNormalHalf >= 0.0 )":"",e?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",e?"dirDiffuse  += mColor * dirDiffuseWeight;":"",e?"dirSpecular += mSpecular * dirSpecularWeight;":"",e?"}":"","vec4 totalLight = mAmbient;",e?"totalLight += dirDiffuse + dirSpecular;":"",g?"totalLight += pointDiffuse + pointSpecular;":
 "","gl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );\n} else if ( material == 1 ) {\ngl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );\n} else {\ngl_FragColor = mColor * mapColor * cubeColor;\n}\n}"].join("\n")));b.attachShader(d,c("vertex",[e?"#define MAX_DIR_LIGHTS "+e:"",g?"#define MAX_POINT_LIGHTS "+g:"","attribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\nuniform vec3 cameraPosition;\nuniform bool enableLighting;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",
 e?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",e?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",g?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",g?"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;",g?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":
-"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nvoid main(void) {\nvec4 mPosition = objMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 nWorld = mat3(objMatrix) * 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;",e?"for( int i = 0; i < directionalLightNumber; i++ ) {":
-"",e?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",e?"float directionalLightWeighting = max( dot( transformedNormal, normalize(lDirection.xyz ) ), 0.0 );":"",e?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",e?"}":"",g?"for( int i = 0; i < pointLightNumber; i++ ) {":"",g?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",g?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":"",g?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":
-"",g?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",g?"}":"","}\nvNormal = transformedNormal;\nvUv = uv;\nvReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n")));b.linkProgram(d);b.getProgramParameter(d,b.LINK_STATUS)||alert("Could not initialise shaders");b.useProgram(d);d.viewMatrix=b.getUniformLocation(d,"viewMatrix");d.modelViewMatrix=b.getUniformLocation(d,"modelViewMatrix");d.projectionMatrix=
-b.getUniformLocation(d,"projectionMatrix");d.normalMatrix=b.getUniformLocation(d,"normalMatrix");d.objMatrix=b.getUniformLocation(d,"objMatrix");d.cameraPosition=b.getUniformLocation(d,"cameraPosition");d.enableLighting=b.getUniformLocation(d,"enableLighting");d.ambientLightColor=b.getUniformLocation(d,"ambientLightColor");if(e){d.directionalLightNumber=b.getUniformLocation(d,"directionalLightNumber");d.directionalLightColor=b.getUniformLocation(d,"directionalLightColor");d.directionalLightDirection=
-b.getUniformLocation(d,"directionalLightDirection")}if(g){d.pointLightNumber=b.getUniformLocation(d,"pointLightNumber");d.pointLightColor=b.getUniformLocation(d,"pointLightColor");d.pointLightPosition=b.getUniformLocation(d,"pointLightPosition")}d.material=b.getUniformLocation(d,"material");d.mColor=b.getUniformLocation(d,"mColor");d.mOpacity=b.getUniformLocation(d,"mOpacity");d.mReflectivity=b.getUniformLocation(d,"mReflectivity");d.mAmbient=b.getUniformLocation(d,"mAmbient");d.mSpecular=b.getUniformLocation(d,
-"mSpecular");d.mShininess=b.getUniformLocation(d,"mShininess");d.enableMap=b.getUniformLocation(d,"enableMap");b.uniform1i(d.enableMap,0);d.tMap=b.getUniformLocation(d,"tMap");b.uniform1i(d.tMap,0);d.enableCubeMap=b.getUniformLocation(d,"enableCubeMap");b.uniform1i(d.enableCubeMap,0);d.tCube=b.getUniformLocation(d,"tCube");b.uniform1i(d.tCube,1);d.m2Near=b.getUniformLocation(d,"m2Near");d.mFarPlusNear=b.getUniformLocation(d,"mFarPlusNear");d.mFarMinusNear=b.getUniformLocation(d,"mFarMinusNear");d.position=
-b.getAttribLocation(d,"position");b.enableVertexAttribArray(d.position);d.normal=b.getAttribLocation(d,"normal");b.enableVertexAttribArray(d.normal);d.uv=b.getAttribLocation(d,"uv");b.enableVertexAttribArray(d.uv);d.viewMatrixArray=new Float32Array(16);d.modelViewMatrixArray=new Float32Array(16);d.projectionMatrixArray=new Float32Array(16)})(a.directional,a.point);this.setSize=function(e,g){f.width=e;f.height=g;b.viewport(0,0,f.width,f.height)};this.clear=function(){b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT)};
-this.setupLights=function(e){var g,m,i,l,r=[],o=[],p=[];l=[];var x=[];b.uniform1i(d.enableLighting,e.lights.length);g=0;for(m=e.lights.length;g<m;g++){i=e.lights[g];if(i instanceof THREE.AmbientLight)r.push(i);else if(i instanceof THREE.DirectionalLight)p.push(i);else i instanceof THREE.PointLight&&o.push(i)}g=e=i=l=0;for(m=r.length;g<m;g++){e+=r[g].color.r;i+=r[g].color.g;l+=r[g].color.b}b.uniform3f(d.ambientLightColor,e,i,l);l=[];x=[];g=0;for(m=p.length;g<m;g++){i=p[g];l.push(i.color.r*i.intensity);
-l.push(i.color.g*i.intensity);l.push(i.color.b*i.intensity);x.push(i.position.x);x.push(i.position.y);x.push(i.position.z)}if(p.length){b.uniform1i(d.directionalLightNumber,p.length);b.uniform3fv(d.directionalLightDirection,x);b.uniform3fv(d.directionalLightColor,l)}l=[];x=[];g=0;for(m=o.length;g<m;g++){i=o[g];l.push(i.color.r*i.intensity);l.push(i.color.g*i.intensity);l.push(i.color.b*i.intensity);x.push(i.position.x);x.push(i.position.y);x.push(i.position.z)}if(o.length){b.uniform1i(d.pointLightNumber,
-o.length);b.uniform3fv(d.pointLightPosition,x);b.uniform3fv(d.pointLightColor,l)}};this.createBuffers=function(e,g){var m,i,l,r,o,p,x,h,B,q=e.materialFaceGroup[g],D=[],u=[],L=[],v=[],s=[],y=0,M=false;m=0;for(i=e.material.length;m<i;m++){meshMaterial=e.material[m];if(meshMaterial instanceof THREE.MeshFaceMaterial){o=0;for(p=q.material.length;o<p;o++)if(q.material[o]&&q.material[o].shading!=undefined&&q.material[o].shading==THREE.SmoothShading){M=true;break}}else if(meshMaterial&&meshMaterial.shading!=
-undefined&&meshMaterial.shading==THREE.SmoothShading){M=true;break}if(M)break}m=0;for(i=q.faces.length;m<i;m++){l=q.faces[m];r=e.geometry.faces[l];o=r.vertexNormals;p=r.normal;l=e.geometry.uvs[l];if(r instanceof THREE.Face3){x=e.geometry.vertices[r.a].position;h=e.geometry.vertices[r.b].position;B=e.geometry.vertices[r.c].position;L.push(x.x,x.y,x.z);L.push(h.x,h.y,h.z);L.push(B.x,B.y,B.z);if(o.length==3&&M){v.push(o[0].x,o[0].y,o[0].z);v.push(o[1].x,o[1].y,o[1].z);v.push(o[2].x,o[2].y,o[2].z)}else{v.push(p.x,
-p.y,p.z);v.push(p.x,p.y,p.z);v.push(p.x,p.y,p.z)}if(l){s.push(l[0].u,l[0].v);s.push(l[1].u,l[1].v);s.push(l[2].u,l[2].v)}D.push(y,y+1,y+2);u.push(y,y+1);u.push(y,y+2);u.push(y+1,y+2);y+=3}else if(r instanceof THREE.Face4){x=e.geometry.vertices[r.a].position;h=e.geometry.vertices[r.b].position;B=e.geometry.vertices[r.c].position;r=e.geometry.vertices[r.d].position;L.push(x.x,x.y,x.z);L.push(h.x,h.y,h.z);L.push(B.x,B.y,B.z);L.push(r.x,r.y,r.z);if(o.length==4&&M){v.push(o[0].x,o[0].y,o[0].z);v.push(o[1].x,
-o[1].y,o[1].z);v.push(o[2].x,o[2].y,o[2].z);v.push(o[3].x,o[3].y,o[3].z)}else{v.push(p.x,p.y,p.z);v.push(p.x,p.y,p.z);v.push(p.x,p.y,p.z);v.push(p.x,p.y,p.z)}if(l){s.push(l[0].u,l[0].v);s.push(l[1].u,l[1].v);s.push(l[2].u,l[2].v);s.push(l[3].u,l[3].v)}D.push(y,y+1,y+2);D.push(y,y+2,y+3);u.push(y,y+1);u.push(y,y+2);u.push(y,y+3);u.push(y+1,y+2);u.push(y+2,y+3);y+=4}}if(L.length){q.__webGLVertexBuffer=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,q.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,new Float32Array(L),
-b.STATIC_DRAW);q.__webGLNormalBuffer=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,q.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,new Float32Array(v),b.STATIC_DRAW);q.__webGLUVBuffer=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,q.__webGLUVBuffer);b.bufferData(b.ARRAY_BUFFER,new Float32Array(s),b.STATIC_DRAW);q.__webGLFaceBuffer=b.createBuffer();b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,q.__webGLFaceBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,new Uint16Array(D),b.STATIC_DRAW);q.__webGLLineBuffer=b.createBuffer();
-b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,q.__webGLLineBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,new Uint16Array(u),b.STATIC_DRAW);q.__webGLFaceCount=D.length;q.__webGLLineCount=u.length}};this.renderBuffer=function(e,g){var m,i,l,r,o,p,x,h;if(e instanceof THREE.MeshPhongMaterial||e instanceof THREE.MeshLambertMaterial||e instanceof THREE.MeshBasicMaterial){m=e.color;i=e.opacity;l=e.reflectivity;r=e.wireframe;o=e.wireframe_linewidth;x=e.map;h=e.env_map;b.uniform4f(d.mColor,m.r*i,m.g*i,m.b*i,i);b.uniform1f(d.mReflectivity,
-l)}if(e instanceof THREE.MeshNormalMaterial){i=e.opacity;b.uniform1f(d.mOpacity,i);b.uniform1i(d.material,4)}else if(e instanceof THREE.MeshDepthMaterial){i=e.opacity;r=e.wireframe;o=e.wireframe_linewidth;b.uniform1f(d.mOpacity,i);b.uniform1f(d.m2Near,e.__2near);b.uniform1f(d.mFarPlusNear,e.__farPlusNear);b.uniform1f(d.mFarMinusNear,e.__farMinusNear);b.uniform1i(d.material,3)}else if(e instanceof THREE.MeshPhongMaterial){m=e.ambient;l=e.specular;p=e.shininess;b.uniform4f(d.mAmbient,m.r,m.g,m.b,i);
-b.uniform4f(d.mSpecular,l.r,l.g,l.b,i);b.uniform1f(d.mShininess,p);b.uniform1i(d.material,2)}else if(e instanceof THREE.MeshLambertMaterial)b.uniform1i(d.material,1);else e instanceof THREE.MeshBasicMaterial&&b.uniform1i(d.material,0);if(x){if(!e.__webGLTexture&&e.map.image.loaded){e.__webGLTexture=b.createTexture();b.bindTexture(b.TEXTURE_2D,e.__webGLTexture);b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.map.image);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,b.LINEAR);b.texParameteri(b.TEXTURE_2D,
-b.TEXTURE_MIN_FILTER,b.LINEAR_MIPMAP_LINEAR);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}b.activeTexture(b.TEXTURE0);b.bindTexture(b.TEXTURE_2D,e.__webGLTexture);b.uniform1i(d.tMap,0);b.uniform1i(d.enableMap,1)}else b.uniform1i(d.enableMap,0);if(h){if(e.env_map&&e.env_map instanceof THREE.TextureCube&&e.env_map.image.length==6){if(!e.__webGLTextureCube&&!e.__cubeMapInitialized&&e.env_map.image.loadCount==6){e.__webGLTextureCube=b.createTexture();b.bindTexture(b.TEXTURE_CUBE_MAP,
-e.__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);b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[0]);b.texImage2D(b.TEXTURE_CUBE_MAP_NEGATIVE_X,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[1]);b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_Y,
-0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[2]);b.texImage2D(b.TEXTURE_CUBE_MAP_NEGATIVE_Y,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[3]);b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_Z,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[4]);b.texImage2D(b.TEXTURE_CUBE_MAP_NEGATIVE_Z,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[5]);b.generateMipmap(b.TEXTURE_CUBE_MAP);b.bindTexture(b.TEXTURE_CUBE_MAP,null);e.__cubeMapInitialized=true}b.activeTexture(b.TEXTURE1);b.bindTexture(b.TEXTURE_CUBE_MAP,
-e.__webGLTextureCube);b.uniform1i(d.tCube,1)}b.uniform1i(d.enableCubeMap,1)}else b.uniform1i(d.enableCubeMap,0);b.bindBuffer(b.ARRAY_BUFFER,g.__webGLVertexBuffer);b.vertexAttribPointer(d.position,3,b.FLOAT,false,0,0);b.bindBuffer(b.ARRAY_BUFFER,g.__webGLNormalBuffer);b.vertexAttribPointer(d.normal,3,b.FLOAT,false,0,0);if(x){b.bindBuffer(b.ARRAY_BUFFER,g.__webGLUVBuffer);b.enableVertexAttribArray(d.uv);b.vertexAttribPointer(d.uv,2,b.FLOAT,false,0,0)}else b.disableVertexAttribArray(d.uv);if(r){b.lineWidth(o);
-b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,g.__webGLLineBuffer);b.drawElements(b.LINES,g.__webGLLineCount,b.UNSIGNED_SHORT,0)}else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,g.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,g.__webGLFaceCount,b.UNSIGNED_SHORT,0)}};this.renderPass=function(e,g,m){var i,l,r,o,p;r=0;for(o=e.material.length;r<o;r++){i=e.material[r];if(i instanceof THREE.MeshFaceMaterial){i=0;for(l=g.material.length;i<l;i++)if((p=g.material[i])&&p.blending==m){this.setBlending(p.blending);this.renderBuffer(p,
-g)}}else if((p=i)&&p.blending==m){this.setBlending(p.blending);this.renderBuffer(p,g)}}};this.render=function(e,g){var m,i;this.initWebGLObjects(e);this.autoClear&&this.clear();g.autoUpdateMatrix&&g.updateMatrix();b.uniform3f(d.cameraPosition,g.position.x,g.position.y,g.position.z);this.setupLights(e);m=0;for(i=e.__webGLObjects.length;m<i;m++){webGLObject=e.__webGLObjects[m];this.setupMatrices(webGLObject.__object,g);this.renderPass(webGLObject.__object,webGLObject,THREE.NormalBlending)}m=0;for(i=
-e.__webGLObjects.length;m<i;m++){webGLObject=e.__webGLObjects[m];this.setupMatrices(webGLObject.__object,g);this.renderPass(webGLObject.__object,webGLObject,THREE.AdditiveBlending);this.renderPass(webGLObject.__object,webGLObject,THREE.SubtractiveBlending)}};this.initWebGLObjects=function(e){var g,m,i,l,r;if(!e.__webGLObjects)e.__webGLObjects=[];g=0;for(m=e.objects.length;g<m;g++){i=e.objects[g];if(i instanceof THREE.Mesh)for(l in i.materialFaceGroup){r=i.materialFaceGroup[l];if(!r.__webGLVertexBuffer){this.createBuffers(i,
-l);r.__object=i;e.__webGLObjects.push(r)}}}};this.setupMatrices=function(e,g){e.autoUpdateMatrix&&e.updateMatrix();j.multiply(g.matrix,e.matrix);d.viewMatrixArray=new Float32Array(g.matrix.flatten());d.modelViewMatrixArray=new Float32Array(j.flatten());d.projectionMatrixArray=new Float32Array(g.projectionMatrix.flatten());n=THREE.Matrix4.makeInvert3x3(j).transpose();d.normalMatrixArray=new Float32Array(n.m);b.uniformMatrix4fv(d.viewMatrix,false,d.viewMatrixArray);b.uniformMatrix4fv(d.modelViewMatrix,
-false,d.modelViewMatrixArray);b.uniformMatrix4fv(d.projectionMatrix,false,d.projectionMatrixArray);b.uniformMatrix3fv(d.normalMatrix,false,d.normalMatrixArray);b.uniformMatrix4fv(d.objMatrix,false,new Float32Array(e.matrix.flatten()))};this.setBlending=function(e){switch(e){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(e,g){if(e){!g||g=="ccw"?b.frontFace(b.CCW):b.frontFace(b.CW);if(e=="back")b.cullFace(b.BACK);else e=="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.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.material=this.color=this.z=null};
+"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\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;",
+e?"for( int i = 0; i < directionalLightNumber; i++ ) {":"",e?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",e?"float directionalLightWeighting = max( dot( transformedNormal, normalize(lDirection.xyz ) ), 0.0 );":"",e?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",e?"}":"",g?"for( int i = 0; i < pointLightNumber; i++ ) {":"",g?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",g?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
+"",g?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",g?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",g?"}":"","}\nvNormal = transformedNormal;\nvUv = uv;\nvReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n")));b.linkProgram(d);b.getProgramParameter(d,b.LINK_STATUS)||alert("Could not initialise shaders");b.useProgram(d);d.viewMatrix=b.getUniformLocation(d,
+"viewMatrix");d.modelViewMatrix=b.getUniformLocation(d,"modelViewMatrix");d.projectionMatrix=b.getUniformLocation(d,"projectionMatrix");d.normalMatrix=b.getUniformLocation(d,"normalMatrix");d.objMatrix=b.getUniformLocation(d,"objMatrix");d.cameraPosition=b.getUniformLocation(d,"cameraPosition");d.enableLighting=b.getUniformLocation(d,"enableLighting");d.ambientLightColor=b.getUniformLocation(d,"ambientLightColor");if(e){d.directionalLightNumber=b.getUniformLocation(d,"directionalLightNumber");d.directionalLightColor=
+b.getUniformLocation(d,"directionalLightColor");d.directionalLightDirection=b.getUniformLocation(d,"directionalLightDirection")}if(g){d.pointLightNumber=b.getUniformLocation(d,"pointLightNumber");d.pointLightColor=b.getUniformLocation(d,"pointLightColor");d.pointLightPosition=b.getUniformLocation(d,"pointLightPosition")}d.material=b.getUniformLocation(d,"material");d.mColor=b.getUniformLocation(d,"mColor");d.mOpacity=b.getUniformLocation(d,"mOpacity");d.mReflectivity=b.getUniformLocation(d,"mReflectivity");
+d.mAmbient=b.getUniformLocation(d,"mAmbient");d.mSpecular=b.getUniformLocation(d,"mSpecular");d.mShininess=b.getUniformLocation(d,"mShininess");d.enableMap=b.getUniformLocation(d,"enableMap");b.uniform1i(d.enableMap,0);d.tMap=b.getUniformLocation(d,"tMap");b.uniform1i(d.tMap,0);d.enableCubeMap=b.getUniformLocation(d,"enableCubeMap");b.uniform1i(d.enableCubeMap,0);d.tCube=b.getUniformLocation(d,"tCube");b.uniform1i(d.tCube,1);d.m2Near=b.getUniformLocation(d,"m2Near");d.mFarPlusNear=b.getUniformLocation(d,
+"mFarPlusNear");d.mFarMinusNear=b.getUniformLocation(d,"mFarMinusNear");d.position=b.getAttribLocation(d,"position");b.enableVertexAttribArray(d.position);d.normal=b.getAttribLocation(d,"normal");b.enableVertexAttribArray(d.normal);d.uv=b.getAttribLocation(d,"uv");b.enableVertexAttribArray(d.uv);d.viewMatrixArray=new Float32Array(16);d.modelViewMatrixArray=new Float32Array(16);d.projectionMatrixArray=new Float32Array(16)})(a.directional,a.point);this.setSize=function(e,g){f.width=e;f.height=g;b.viewport(0,
+0,f.width,f.height)};this.clear=function(){b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT)};this.setupLights=function(e){var g,m,i,l,r=[],o=[],p=[];l=[];var x=[];b.uniform1i(d.enableLighting,e.lights.length);g=0;for(m=e.lights.length;g<m;g++){i=e.lights[g];if(i instanceof THREE.AmbientLight)r.push(i);else if(i instanceof THREE.DirectionalLight)p.push(i);else i instanceof THREE.PointLight&&o.push(i)}g=e=i=l=0;for(m=r.length;g<m;g++){e+=r[g].color.r;i+=r[g].color.g;l+=r[g].color.b}b.uniform3f(d.ambientLightColor,
+e,i,l);l=[];x=[];g=0;for(m=p.length;g<m;g++){i=p[g];l.push(i.color.r*i.intensity);l.push(i.color.g*i.intensity);l.push(i.color.b*i.intensity);x.push(i.position.x);x.push(i.position.y);x.push(i.position.z)}if(p.length){b.uniform1i(d.directionalLightNumber,p.length);b.uniform3fv(d.directionalLightDirection,x);b.uniform3fv(d.directionalLightColor,l)}l=[];x=[];g=0;for(m=o.length;g<m;g++){i=o[g];l.push(i.color.r*i.intensity);l.push(i.color.g*i.intensity);l.push(i.color.b*i.intensity);x.push(i.position.x);
+x.push(i.position.y);x.push(i.position.z)}if(o.length){b.uniform1i(d.pointLightNumber,o.length);b.uniform3fv(d.pointLightPosition,x);b.uniform3fv(d.pointLightColor,l)}};this.createBuffers=function(e,g){var m,i,l,r,o,p,x,h,B,q=e.materialFaceGroup[g],D=[],u=[],L=[],v=[],s=[],y=0,M=false;m=0;for(i=e.material.length;m<i;m++){meshMaterial=e.material[m];if(meshMaterial instanceof THREE.MeshFaceMaterial){o=0;for(p=q.material.length;o<p;o++)if(q.material[o]&&q.material[o].shading!=undefined&&q.material[o].shading==
+THREE.SmoothShading){M=true;break}}else if(meshMaterial&&meshMaterial.shading!=undefined&&meshMaterial.shading==THREE.SmoothShading){M=true;break}if(M)break}m=0;for(i=q.faces.length;m<i;m++){l=q.faces[m];r=e.geometry.faces[l];o=r.vertexNormals;p=r.normal;l=e.geometry.uvs[l];if(r instanceof THREE.Face3){x=e.geometry.vertices[r.a].position;h=e.geometry.vertices[r.b].position;B=e.geometry.vertices[r.c].position;L.push(x.x,x.y,x.z);L.push(h.x,h.y,h.z);L.push(B.x,B.y,B.z);if(o.length==3&&M){v.push(o[0].x,
+o[0].y,o[0].z);v.push(o[1].x,o[1].y,o[1].z);v.push(o[2].x,o[2].y,o[2].z)}else{v.push(p.x,p.y,p.z);v.push(p.x,p.y,p.z);v.push(p.x,p.y,p.z)}if(l){s.push(l[0].u,l[0].v);s.push(l[1].u,l[1].v);s.push(l[2].u,l[2].v)}D.push(y,y+1,y+2);u.push(y,y+1);u.push(y,y+2);u.push(y+1,y+2);y+=3}else if(r instanceof THREE.Face4){x=e.geometry.vertices[r.a].position;h=e.geometry.vertices[r.b].position;B=e.geometry.vertices[r.c].position;r=e.geometry.vertices[r.d].position;L.push(x.x,x.y,x.z);L.push(h.x,h.y,h.z);L.push(B.x,
+B.y,B.z);L.push(r.x,r.y,r.z);if(o.length==4&&M){v.push(o[0].x,o[0].y,o[0].z);v.push(o[1].x,o[1].y,o[1].z);v.push(o[2].x,o[2].y,o[2].z);v.push(o[3].x,o[3].y,o[3].z)}else{v.push(p.x,p.y,p.z);v.push(p.x,p.y,p.z);v.push(p.x,p.y,p.z);v.push(p.x,p.y,p.z)}if(l){s.push(l[0].u,l[0].v);s.push(l[1].u,l[1].v);s.push(l[2].u,l[2].v);s.push(l[3].u,l[3].v)}D.push(y,y+1,y+2);D.push(y,y+2,y+3);u.push(y,y+1);u.push(y,y+2);u.push(y,y+3);u.push(y+1,y+2);u.push(y+2,y+3);y+=4}}if(L.length){q.__webGLVertexBuffer=b.createBuffer();
+b.bindBuffer(b.ARRAY_BUFFER,q.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,new Float32Array(L),b.STATIC_DRAW);q.__webGLNormalBuffer=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,q.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,new Float32Array(v),b.STATIC_DRAW);q.__webGLUVBuffer=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,q.__webGLUVBuffer);b.bufferData(b.ARRAY_BUFFER,new Float32Array(s),b.STATIC_DRAW);q.__webGLFaceBuffer=b.createBuffer();b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,q.__webGLFaceBuffer);
+b.bufferData(b.ELEMENT_ARRAY_BUFFER,new Uint16Array(D),b.STATIC_DRAW);q.__webGLLineBuffer=b.createBuffer();b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,q.__webGLLineBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,new Uint16Array(u),b.STATIC_DRAW);q.__webGLFaceCount=D.length;q.__webGLLineCount=u.length}};this.renderBuffer=function(e,g){var m,i,l,r,o,p,x,h;if(e instanceof THREE.MeshPhongMaterial||e instanceof THREE.MeshLambertMaterial||e instanceof THREE.MeshBasicMaterial){m=e.color;i=e.opacity;l=e.reflectivity;
+r=e.wireframe;o=e.wireframe_linewidth;x=e.map;h=e.env_map;b.uniform4f(d.mColor,m.r*i,m.g*i,m.b*i,i);b.uniform1f(d.mReflectivity,l)}if(e instanceof THREE.MeshNormalMaterial){i=e.opacity;b.uniform1f(d.mOpacity,i);b.uniform1i(d.material,4)}else if(e instanceof THREE.MeshDepthMaterial){i=e.opacity;r=e.wireframe;o=e.wireframe_linewidth;b.uniform1f(d.mOpacity,i);b.uniform1f(d.m2Near,e.__2near);b.uniform1f(d.mFarPlusNear,e.__farPlusNear);b.uniform1f(d.mFarMinusNear,e.__farMinusNear);b.uniform1i(d.material,
+3)}else if(e instanceof THREE.MeshPhongMaterial){m=e.ambient;l=e.specular;p=e.shininess;b.uniform4f(d.mAmbient,m.r,m.g,m.b,i);b.uniform4f(d.mSpecular,l.r,l.g,l.b,i);b.uniform1f(d.mShininess,p);b.uniform1i(d.material,2)}else if(e instanceof THREE.MeshLambertMaterial)b.uniform1i(d.material,1);else e instanceof THREE.MeshBasicMaterial&&b.uniform1i(d.material,0);if(x){if(!e.__webGLTexture&&e.map.image.loaded){e.__webGLTexture=b.createTexture();b.bindTexture(b.TEXTURE_2D,e.__webGLTexture);b.texImage2D(b.TEXTURE_2D,
+0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.map.image);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,b.LINEAR);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,b.LINEAR_MIPMAP_LINEAR);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}b.activeTexture(b.TEXTURE0);b.bindTexture(b.TEXTURE_2D,e.__webGLTexture);b.uniform1i(d.tMap,0);b.uniform1i(d.enableMap,1)}else b.uniform1i(d.enableMap,0);if(h){if(e.env_map&&e.env_map instanceof THREE.TextureCube&&e.env_map.image.length==6){if(!e.__webGLTextureCube&&
+!e.__cubeMapInitialized&&e.env_map.image.loadCount==6){e.__webGLTextureCube=b.createTexture();b.bindTexture(b.TEXTURE_CUBE_MAP,e.__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);b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,
+e.env_map.image[0]);b.texImage2D(b.TEXTURE_CUBE_MAP_NEGATIVE_X,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[1]);b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_Y,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[2]);b.texImage2D(b.TEXTURE_CUBE_MAP_NEGATIVE_Y,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[3]);b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_Z,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[4]);b.texImage2D(b.TEXTURE_CUBE_MAP_NEGATIVE_Z,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[5]);b.generateMipmap(b.TEXTURE_CUBE_MAP);
+b.bindTexture(b.TEXTURE_CUBE_MAP,null);e.__cubeMapInitialized=true}b.activeTexture(b.TEXTURE1);b.bindTexture(b.TEXTURE_CUBE_MAP,e.__webGLTextureCube);b.uniform1i(d.tCube,1)}b.uniform1i(d.enableCubeMap,1)}else b.uniform1i(d.enableCubeMap,0);b.bindBuffer(b.ARRAY_BUFFER,g.__webGLVertexBuffer);b.vertexAttribPointer(d.position,3,b.FLOAT,false,0,0);b.bindBuffer(b.ARRAY_BUFFER,g.__webGLNormalBuffer);b.vertexAttribPointer(d.normal,3,b.FLOAT,false,0,0);if(x){b.bindBuffer(b.ARRAY_BUFFER,g.__webGLUVBuffer);
+b.enableVertexAttribArray(d.uv);b.vertexAttribPointer(d.uv,2,b.FLOAT,false,0,0)}else b.disableVertexAttribArray(d.uv);if(r){b.lineWidth(o);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,g.__webGLLineBuffer);b.drawElements(b.LINES,g.__webGLLineCount,b.UNSIGNED_SHORT,0)}else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,g.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,g.__webGLFaceCount,b.UNSIGNED_SHORT,0)}};this.renderPass=function(e,g,m){var i,l,r,o,p;r=0;for(o=e.material.length;r<o;r++){i=e.material[r];if(i instanceof
+THREE.MeshFaceMaterial){i=0;for(l=g.material.length;i<l;i++)if((p=g.material[i])&&p.blending==m){this.setBlending(p.blending);this.renderBuffer(p,g)}}else if((p=i)&&p.blending==m){this.setBlending(p.blending);this.renderBuffer(p,g)}}};this.render=function(e,g){var m,i;this.initWebGLObjects(e);this.autoClear&&this.clear();g.autoUpdateMatrix&&g.updateMatrix();b.uniform3f(d.cameraPosition,g.position.x,g.position.y,g.position.z);this.setupLights(e);m=0;for(i=e.__webGLObjects.length;m<i;m++){webGLObject=
+e.__webGLObjects[m];this.setupMatrices(webGLObject.__object,g);this.renderPass(webGLObject.__object,webGLObject,THREE.NormalBlending)}m=0;for(i=e.__webGLObjects.length;m<i;m++){webGLObject=e.__webGLObjects[m];this.setupMatrices(webGLObject.__object,g);this.renderPass(webGLObject.__object,webGLObject,THREE.AdditiveBlending);this.renderPass(webGLObject.__object,webGLObject,THREE.SubtractiveBlending)}};this.initWebGLObjects=function(e){var g,m,i,l,r;if(!e.__webGLObjects)e.__webGLObjects=[];g=0;for(m=
+e.objects.length;g<m;g++){i=e.objects[g];if(i instanceof THREE.Mesh)for(l in i.materialFaceGroup){r=i.materialFaceGroup[l];if(!r.__webGLVertexBuffer){this.createBuffers(i,l);r.__object=i;e.__webGLObjects.push(r)}}}};this.setupMatrices=function(e,g){e.autoUpdateMatrix&&e.updateMatrix();j.multiply(g.matrix,e.matrix);d.viewMatrixArray=new Float32Array(g.matrix.flatten());d.modelViewMatrixArray=new Float32Array(j.flatten());d.projectionMatrixArray=new Float32Array(g.projectionMatrix.flatten());n=THREE.Matrix4.makeInvert3x3(j).transpose();
+d.normalMatrixArray=new Float32Array(n.m);b.uniformMatrix4fv(d.viewMatrix,false,d.viewMatrixArray);b.uniformMatrix4fv(d.modelViewMatrix,false,d.modelViewMatrixArray);b.uniformMatrix4fv(d.projectionMatrix,false,d.projectionMatrixArray);b.uniformMatrix3fv(d.normalMatrix,false,d.normalMatrixArray);b.uniformMatrix4fv(d.objMatrix,false,new Float32Array(e.matrix.flatten()))};this.setBlending=function(e){switch(e){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(e,g){if(e){!g||g=="ccw"?b.frontFace(b.CCW):b.frontFace(b.CW);if(e=="back")b.cullFace(b.BACK);else e=="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.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.material=this.color=this.z=null};
 THREE.RenderableFace4=function(){this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.v4=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.material=this.color=this.z=null};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=this.color=null};
 THREE.RenderableLine=function(){this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=this.color=this.z=null};

+ 3 - 1
src/renderers/WebGLRenderer.js

@@ -1042,7 +1042,9 @@ THREE.WebGLRenderer = function ( scene ) {
 				"vec4 mPosition = objMatrix * vec4( position, 1.0 );",
 				"vViewPosition = cameraPosition - mPosition.xyz;",
 				
-				"vec3 nWorld = mat3(objMatrix) * normal;",
+				// this doesn't work on Mac
+				//"vec3 nWorld = mat3(objMatrix) * normal;",
+				"vec3 nWorld = mat3( objMatrix[0].xyz, objMatrix[1].xyz, objMatrix[2].xyz ) * normal;",
 				
 				// eye space