Răsfoiți Sursa

Refactored WebGLRenderer to be able to handle MeshShaderMaterial also for Lines and ParticleSystems.

It is now object type that determines which type of primitives is going to be used (triangles / lines / line strips / points).
alteredq 14 ani în urmă
părinte
comite
fe2e9759b6
4 a modificat fișierele cu 58 adăugiri și 47 ștergeri
  1. 10 10
      build/Three.js
  2. 10 10
      build/ThreeDebug.js
  3. 10 10
      build/ThreeExtras.js
  4. 28 17
      src/renderers/WebGLRenderer.js

+ 10 - 10
build/Three.js

@@ -187,16 +187,16 @@ b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_M
 f.image.loaded){f.__webGLTexture=b.createTexture();b.bindTexture(b.TEXTURE_2D,f.__webGLTexture);b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,f.image);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,i(f.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,i(f.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,i(f.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,i(f.min_filter));b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}b.activeTexture(b.TEXTURE0+
 h);b.bindTexture(b.TEXTURE_2D,f.__webGLTexture)}}}return l};this.renderBuffer=function(d,n,h,f,k,l){d=this.setProgram(d,n,h,f,l).attributes;b.bindBuffer(b.ARRAY_BUFFER,k.__webGLVertexBuffer);b.vertexAttribPointer(d.position,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.position);if(d.color>=0){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLColorBuffer);b.vertexAttribPointer(d.color,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.color)}if(d.normal>=0){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLNormalBuffer);
 b.vertexAttribPointer(d.normal,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.normal)}if(d.tangent>=0){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLTangentBuffer);b.vertexAttribPointer(d.tangent,4,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.tangent)}if(d.uv>=0)if(k.__webGLUVBuffer){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLUVBuffer);b.vertexAttribPointer(d.uv,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.uv)}else b.disableVertexAttribArray(d.uv);if(d.uv2>=0)if(k.__webGLUV2Buffer){b.bindBuffer(b.ARRAY_BUFFER,
-k.__webGLUV2Buffer);b.vertexAttribPointer(d.uv2,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.uv2)}else b.disableVertexAttribArray(d.uv2);if(f.wireframe||f instanceof THREE.LineBasicMaterial){d=f.wireframe_linewidth!==undefined?f.wireframe_linewidth:f.linewidth!==undefined?f.linewidth:1;f=f instanceof THREE.LineBasicMaterial&&l.type==THREE.LineStrip?b.LINE_STRIP:b.LINES;b.lineWidth(d);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,k.__webGLLineBuffer);b.drawElements(f,k.__webGLLineCount,b.UNSIGNED_SHORT,
-0)}else if(f instanceof THREE.ParticleBasicMaterial)b.drawArrays(b.POINTS,0,k.__webGLParticleCount);else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,k.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,k.__webGLFaceCount,b.UNSIGNED_SHORT,0)}};this.renderPass=function(d,n,h,f,k,l,t){var o,q,v,x,u;v=0;for(x=f.materials.length;v<x;v++){o=f.materials[v];if(o instanceof THREE.MeshFaceMaterial){o=0;for(q=k.materials.length;o<q;o++)if((u=k.materials[o])&&u.blending==l&&u.opacity<1==t){this.setBlending(u.blending);this.setDepthTest(u.depth_test);
-this.renderBuffer(d,n,h,u,k,f)}}else if((u=o)&&u.blending==l&&u.opacity<1==t){this.setBlending(u.blending);this.setDepthTest(u.depth_test);this.renderBuffer(d,n,h,u,k,f)}}};this.renderPassImmediate=function(d,n,h,f,k,l){var t,o,q,v;t=0;for(o=f.materials.length;t<o;t++)if((q=f.materials[t])&&q.blending==k&&q.opacity<1==l){this.setBlending(q.blending);this.setDepthTest(q.depth_test);v=this.setProgram(d,n,h,q,f);f.render(function(x){var u=v;if(!x.__webGLVertexBuffer)x.__webGLVertexBuffer=b.createBuffer();
-if(!x.__webGLNormalBuffer)x.__webGLNormalBuffer=b.createBuffer();if(x.hasPos){b.bindBuffer(b.ARRAY_BUFFER,x.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,x.positionArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(u.attributes.position);b.vertexAttribPointer(u.attributes.position,3,b.FLOAT,false,0,0)}if(x.hasNormal){b.bindBuffer(b.ARRAY_BUFFER,x.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,x.normalArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(u.attributes.normal);b.vertexAttribPointer(u.attributes.normal,
-3,b.FLOAT,false,0,0)}b.drawArrays(b.TRIANGLES,0,x.count);x.count=0})}};this.render=function(d,n,h,f){var k,l,t,o,q=d.lights,v=d.fog;n.autoUpdateMatrix&&n.updateMatrix();w.set(n.matrix.flatten());A.set(n.projectionMatrix.flatten());r.multiply(n.projectionMatrix,n.matrix);p[0].set(r.n41-r.n11,r.n42-r.n12,r.n43-r.n13,r.n44-r.n14);p[1].set(r.n41+r.n11,r.n42+r.n12,r.n43+r.n13,r.n44+r.n14);p[2].set(r.n41+r.n21,r.n42+r.n22,r.n43+r.n23,r.n44+r.n24);p[3].set(r.n41-r.n21,r.n42-r.n22,r.n43-r.n23,r.n44-r.n24);
-p[4].set(r.n41-r.n31,r.n42-r.n32,r.n43-r.n33,r.n44-r.n34);p[5].set(r.n41+r.n31,r.n42+r.n32,r.n43+r.n33,r.n44+r.n34);for(k=0;k<5;k++){o=p[k];o.divideScalar(Math.sqrt(o.x*o.x+o.y*o.y+o.z*o.z))}this.initWebGLObjects(d,n);f=f!==undefined?f:true;if(h&&!h.__webGLFramebuffer){h.__webGLFramebuffer=b.createFramebuffer();h.__webGLRenderbuffer=b.createRenderbuffer();h.__webGLTexture=b.createTexture();b.bindRenderbuffer(b.RENDERBUFFER,h.__webGLRenderbuffer);b.renderbufferStorage(b.RENDERBUFFER,b.DEPTH_COMPONENT16,
-h.width,h.height);b.bindTexture(b.TEXTURE_2D,h.__webGLTexture);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,i(h.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,i(h.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,i(h.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,i(h.min_filter));b.texImage2D(b.TEXTURE_2D,0,i(h.format),h.width,h.height,0,i(h.format),i(h.type),null);b.bindFramebuffer(b.FRAMEBUFFER,h.__webGLFramebuffer);b.framebufferTexture2D(b.FRAMEBUFFER,b.COLOR_ATTACHMENT0,
-b.TEXTURE_2D,h.__webGLTexture,0);b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,h.__webGLRenderbuffer);b.bindTexture(b.TEXTURE_2D,null);b.bindRenderbuffer(b.RENDERBUFFER,null);b.bindFramebuffer(b.FRAMEBUFFER,null)}if(h){k=h.__webGLFramebuffer;o=h.width;t=h.height}else{k=null;o=j.width;t=j.height}if(k!=m){b.bindFramebuffer(b.FRAMEBUFFER,k);b.viewport(0,0,o,t);f&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);m=k}this.autoClear&&this.clear();k=d.__webGLObjects.length;for(f=
-0;f<k;f++){t=d.__webGLObjects[f];o=t.object;if(l=o.visible){if(!(l=!(o instanceof THREE.Mesh)))a:{l=void 0;for(var x=o.matrix,u=-o.geometry.boundingSphere.radius*Math.max(o.scale.x,Math.max(o.scale.y,o.scale.z)),z=0;z<6;z++){l=p[z].x*x.n14+p[z].y*x.n24+p[z].z*x.n34+p[z].w;if(l<=u){l=false;break a}}l=true}l=l}if(l){if(o.autoUpdateMatrix){o.updateMatrix();o._objectMatrixArray.set(o.matrix.flatten())}this.setupMatrices(o,n);t.render=true}else t.render=false}l=d.__webGLObjectsImmediate.length;for(f=0;f<
-l;f++){o=d.__webGLObjectsImmediate[f].object;if(o.visible){if(o.autoUpdateMatrix){o.updateMatrix();o._objectMatrixArray.set(o.matrix.flatten())}this.setupMatrices(o,n)}}for(f=0;f<k;f++){t=d.__webGLObjects[f];if(t.render){o=t.object;t=t.buffer;e(o);this.renderPass(n,q,v,o,t,THREE.NormalBlending,false)}}for(f=0;f<l;f++){o=d.__webGLObjectsImmediate[f].object;if(o.visible){e(o);this.renderPassImmediate(n,q,v,o,THREE.NormalBlending,false)}}for(f=0;f<k;f++){t=d.__webGLObjects[f];if(t.render){o=t.object;
+k.__webGLUV2Buffer);b.vertexAttribPointer(d.uv2,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.uv2)}else b.disableVertexAttribArray(d.uv2);if(l instanceof THREE.Mesh)if(f.wireframe){b.lineWidth(f.wireframe_linewidth);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,k.__webGLLineBuffer);b.drawElements(b.LINES,k.__webGLLineCount,b.UNSIGNED_SHORT,0)}else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,k.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,k.__webGLFaceCount,b.UNSIGNED_SHORT,0)}else if(l instanceof THREE.Line){l=
+l.type==THREE.LineStrip?b.LINE_STRIP:b.LINES;b.lineWidth(f.linewidth);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,k.__webGLLineBuffer);b.drawElements(l,k.__webGLLineCount,b.UNSIGNED_SHORT,0)}else l instanceof THREE.ParticleSystem&&b.drawArrays(b.POINTS,0,k.__webGLParticleCount)};this.renderPass=function(d,n,h,f,k,l,t){var o,q,v,x,u;v=0;for(x=f.materials.length;v<x;v++){o=f.materials[v];if(o instanceof THREE.MeshFaceMaterial){o=0;for(q=k.materials.length;o<q;o++)if((u=k.materials[o])&&u.blending==l&&u.opacity<
+1==t){this.setBlending(u.blending);this.setDepthTest(u.depth_test);this.renderBuffer(d,n,h,u,k,f)}}else if((u=o)&&u.blending==l&&u.opacity<1==t){this.setBlending(u.blending);this.setDepthTest(u.depth_test);this.renderBuffer(d,n,h,u,k,f)}}};this.renderPassImmediate=function(d,n,h,f,k,l){var t,o,q,v;t=0;for(o=f.materials.length;t<o;t++)if((q=f.materials[t])&&q.blending==k&&q.opacity<1==l){this.setBlending(q.blending);this.setDepthTest(q.depth_test);v=this.setProgram(d,n,h,q,f);f.render(function(x){var u=
+v;if(!x.__webGLVertexBuffer)x.__webGLVertexBuffer=b.createBuffer();if(!x.__webGLNormalBuffer)x.__webGLNormalBuffer=b.createBuffer();if(x.hasPos){b.bindBuffer(b.ARRAY_BUFFER,x.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,x.positionArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(u.attributes.position);b.vertexAttribPointer(u.attributes.position,3,b.FLOAT,false,0,0)}if(x.hasNormal){b.bindBuffer(b.ARRAY_BUFFER,x.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,x.normalArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(u.attributes.normal);
+b.vertexAttribPointer(u.attributes.normal,3,b.FLOAT,false,0,0)}b.drawArrays(b.TRIANGLES,0,x.count);x.count=0})}};this.render=function(d,n,h,f){var k,l,t,o,q=d.lights,v=d.fog;n.autoUpdateMatrix&&n.updateMatrix();w.set(n.matrix.flatten());A.set(n.projectionMatrix.flatten());r.multiply(n.projectionMatrix,n.matrix);p[0].set(r.n41-r.n11,r.n42-r.n12,r.n43-r.n13,r.n44-r.n14);p[1].set(r.n41+r.n11,r.n42+r.n12,r.n43+r.n13,r.n44+r.n14);p[2].set(r.n41+r.n21,r.n42+r.n22,r.n43+r.n23,r.n44+r.n24);p[3].set(r.n41-
+r.n21,r.n42-r.n22,r.n43-r.n23,r.n44-r.n24);p[4].set(r.n41-r.n31,r.n42-r.n32,r.n43-r.n33,r.n44-r.n34);p[5].set(r.n41+r.n31,r.n42+r.n32,r.n43+r.n33,r.n44+r.n34);for(k=0;k<5;k++){o=p[k];o.divideScalar(Math.sqrt(o.x*o.x+o.y*o.y+o.z*o.z))}this.initWebGLObjects(d,n);f=f!==undefined?f:true;if(h&&!h.__webGLFramebuffer){h.__webGLFramebuffer=b.createFramebuffer();h.__webGLRenderbuffer=b.createRenderbuffer();h.__webGLTexture=b.createTexture();b.bindRenderbuffer(b.RENDERBUFFER,h.__webGLRenderbuffer);b.renderbufferStorage(b.RENDERBUFFER,
+b.DEPTH_COMPONENT16,h.width,h.height);b.bindTexture(b.TEXTURE_2D,h.__webGLTexture);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,i(h.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,i(h.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,i(h.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,i(h.min_filter));b.texImage2D(b.TEXTURE_2D,0,i(h.format),h.width,h.height,0,i(h.format),i(h.type),null);b.bindFramebuffer(b.FRAMEBUFFER,h.__webGLFramebuffer);b.framebufferTexture2D(b.FRAMEBUFFER,
+b.COLOR_ATTACHMENT0,b.TEXTURE_2D,h.__webGLTexture,0);b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,h.__webGLRenderbuffer);b.bindTexture(b.TEXTURE_2D,null);b.bindRenderbuffer(b.RENDERBUFFER,null);b.bindFramebuffer(b.FRAMEBUFFER,null)}if(h){k=h.__webGLFramebuffer;o=h.width;t=h.height}else{k=null;o=j.width;t=j.height}if(k!=m){b.bindFramebuffer(b.FRAMEBUFFER,k);b.viewport(0,0,o,t);f&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);m=k}this.autoClear&&this.clear();k=d.__webGLObjects.length;
+for(f=0;f<k;f++){t=d.__webGLObjects[f];o=t.object;if(l=o.visible){if(!(l=!(o instanceof THREE.Mesh)))a:{l=void 0;for(var x=o.matrix,u=-o.geometry.boundingSphere.radius*Math.max(o.scale.x,Math.max(o.scale.y,o.scale.z)),z=0;z<6;z++){l=p[z].x*x.n14+p[z].y*x.n24+p[z].z*x.n34+p[z].w;if(l<=u){l=false;break a}}l=true}l=l}if(l){if(o.autoUpdateMatrix){o.updateMatrix();o._objectMatrixArray.set(o.matrix.flatten())}this.setupMatrices(o,n);t.render=true}else t.render=false}l=d.__webGLObjectsImmediate.length;for(f=
+0;f<l;f++){o=d.__webGLObjectsImmediate[f].object;if(o.visible){if(o.autoUpdateMatrix){o.updateMatrix();o._objectMatrixArray.set(o.matrix.flatten())}this.setupMatrices(o,n)}}for(f=0;f<k;f++){t=d.__webGLObjects[f];if(t.render){o=t.object;t=t.buffer;e(o);this.renderPass(n,q,v,o,t,THREE.NormalBlending,false)}}for(f=0;f<l;f++){o=d.__webGLObjectsImmediate[f].object;if(o.visible){e(o);this.renderPassImmediate(n,q,v,o,THREE.NormalBlending,false)}}for(f=0;f<k;f++){t=d.__webGLObjects[f];if(t.render){o=t.object;
 t=t.buffer;e(o);this.renderPass(n,q,v,o,t,THREE.AdditiveBlending,false);this.renderPass(n,q,v,o,t,THREE.SubtractiveBlending,false);this.renderPass(n,q,v,o,t,THREE.AdditiveBlending,true);this.renderPass(n,q,v,o,t,THREE.SubtractiveBlending,true);this.renderPass(n,q,v,o,t,THREE.NormalBlending,true);this.renderPass(n,q,v,o,t,THREE.BillboardBlending,false)}}for(f=0;f<l;f++){o=d.__webGLObjectsImmediate[f].object;if(o.visible){e(o);this.renderPassImmediate(n,q,v,o,THREE.NormalBlending,true)}}if(h&&h.min_filter!==
 THREE.NearestFilter&&h.min_filter!==THREE.LinearFilter){b.bindTexture(b.TEXTURE_2D,h.__webGLTexture);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}};this.initWebGLObjects=function(d,n){function h(u,z,B,N){if(u[z]==undefined){d.__webGLObjects.push({buffer:B,object:N});u[z]=1}}function f(u,z,B){if(u[z]==undefined){d.__webGLObjectsImmediate.push({object:B});u[z]=1}}var k,l,t,o,q,v,x;if(!d.__webGLObjects){d.__webGLObjects=[];d.__webGLObjectsMap={};d.__webGLObjectsImmediate=[]}k=0;for(l=
 d.objects.length;k<l;k++){t=d.objects[k];q=t.geometry;if(d.__webGLObjectsMap[t.id]==undefined){d.__webGLObjectsMap[t.id]={};t._modelViewMatrix=new THREE.Matrix4;t._normalMatrixArray=new Float32Array(9);t._modelViewMatrixArray=new Float32Array(16);t._objectMatrixArray=new Float32Array(16);t._objectMatrixArray.set(t.matrix.flatten())}x=d.__webGLObjectsMap[t.id];if(t instanceof THREE.Mesh){for(o in q.geometryChunks){v=q.geometryChunks[o];if(!v.__webGLVertexBuffer){this.createMeshBuffers(v);this.initMeshBuffers(v,

+ 10 - 10
build/ThreeDebug.js

@@ -187,16 +187,16 @@ b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_M
 f.image.loaded){f.__webGLTexture=b.createTexture();b.bindTexture(b.TEXTURE_2D,f.__webGLTexture);b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,f.image);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,i(f.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,i(f.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,i(f.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,i(f.min_filter));b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}b.activeTexture(b.TEXTURE0+
 h);b.bindTexture(b.TEXTURE_2D,f.__webGLTexture)}}}return m};this.renderBuffer=function(d,o,h,f,k,m){d=this.setProgram(d,o,h,f,m).attributes;b.bindBuffer(b.ARRAY_BUFFER,k.__webGLVertexBuffer);b.vertexAttribPointer(d.position,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.position);if(d.color>=0){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLColorBuffer);b.vertexAttribPointer(d.color,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.color)}if(d.normal>=0){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLNormalBuffer);
 b.vertexAttribPointer(d.normal,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.normal)}if(d.tangent>=0){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLTangentBuffer);b.vertexAttribPointer(d.tangent,4,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.tangent)}if(d.uv>=0)if(k.__webGLUVBuffer){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLUVBuffer);b.vertexAttribPointer(d.uv,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.uv)}else b.disableVertexAttribArray(d.uv);if(d.uv2>=0)if(k.__webGLUV2Buffer){b.bindBuffer(b.ARRAY_BUFFER,
-k.__webGLUV2Buffer);b.vertexAttribPointer(d.uv2,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.uv2)}else b.disableVertexAttribArray(d.uv2);if(f.wireframe||f instanceof THREE.LineBasicMaterial){d=f.wireframe_linewidth!==undefined?f.wireframe_linewidth:f.linewidth!==undefined?f.linewidth:1;f=f instanceof THREE.LineBasicMaterial&&m.type==THREE.LineStrip?b.LINE_STRIP:b.LINES;b.lineWidth(d);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,k.__webGLLineBuffer);b.drawElements(f,k.__webGLLineCount,b.UNSIGNED_SHORT,
-0)}else if(f instanceof THREE.ParticleBasicMaterial)b.drawArrays(b.POINTS,0,k.__webGLParticleCount);else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,k.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,k.__webGLFaceCount,b.UNSIGNED_SHORT,0)}};this.renderPass=function(d,o,h,f,k,m,t){var p,q,v,x,u;v=0;for(x=f.materials.length;v<x;v++){p=f.materials[v];if(p instanceof THREE.MeshFaceMaterial){p=0;for(q=k.materials.length;p<q;p++)if((u=k.materials[p])&&u.blending==m&&u.opacity<1==t){this.setBlending(u.blending);this.setDepthTest(u.depth_test);
-this.renderBuffer(d,o,h,u,k,f)}}else if((u=p)&&u.blending==m&&u.opacity<1==t){this.setBlending(u.blending);this.setDepthTest(u.depth_test);this.renderBuffer(d,o,h,u,k,f)}}};this.renderPassImmediate=function(d,o,h,f,k,m){var t,p,q,v;t=0;for(p=f.materials.length;t<p;t++)if((q=f.materials[t])&&q.blending==k&&q.opacity<1==m){this.setBlending(q.blending);this.setDepthTest(q.depth_test);v=this.setProgram(d,o,h,q,f);f.render(function(x){var u=v;if(!x.__webGLVertexBuffer)x.__webGLVertexBuffer=b.createBuffer();
-if(!x.__webGLNormalBuffer)x.__webGLNormalBuffer=b.createBuffer();if(x.hasPos){b.bindBuffer(b.ARRAY_BUFFER,x.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,x.positionArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(u.attributes.position);b.vertexAttribPointer(u.attributes.position,3,b.FLOAT,false,0,0)}if(x.hasNormal){b.bindBuffer(b.ARRAY_BUFFER,x.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,x.normalArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(u.attributes.normal);b.vertexAttribPointer(u.attributes.normal,
-3,b.FLOAT,false,0,0)}b.drawArrays(b.TRIANGLES,0,x.count);x.count=0})}};this.render=function(d,o,h,f){var k,m,t,p,q=d.lights,v=d.fog;o.autoUpdateMatrix&&o.updateMatrix();w.set(o.matrix.flatten());A.set(o.projectionMatrix.flatten());r.multiply(o.projectionMatrix,o.matrix);l[0].set(r.n41-r.n11,r.n42-r.n12,r.n43-r.n13,r.n44-r.n14);l[1].set(r.n41+r.n11,r.n42+r.n12,r.n43+r.n13,r.n44+r.n14);l[2].set(r.n41+r.n21,r.n42+r.n22,r.n43+r.n23,r.n44+r.n24);l[3].set(r.n41-r.n21,r.n42-r.n22,r.n43-r.n23,r.n44-r.n24);
-l[4].set(r.n41-r.n31,r.n42-r.n32,r.n43-r.n33,r.n44-r.n34);l[5].set(r.n41+r.n31,r.n42+r.n32,r.n43+r.n33,r.n44+r.n34);for(k=0;k<5;k++){p=l[k];p.divideScalar(Math.sqrt(p.x*p.x+p.y*p.y+p.z*p.z))}this.initWebGLObjects(d,o);f=f!==undefined?f:true;if(h&&!h.__webGLFramebuffer){h.__webGLFramebuffer=b.createFramebuffer();h.__webGLRenderbuffer=b.createRenderbuffer();h.__webGLTexture=b.createTexture();b.bindRenderbuffer(b.RENDERBUFFER,h.__webGLRenderbuffer);b.renderbufferStorage(b.RENDERBUFFER,b.DEPTH_COMPONENT16,
-h.width,h.height);b.bindTexture(b.TEXTURE_2D,h.__webGLTexture);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,i(h.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,i(h.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,i(h.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,i(h.min_filter));b.texImage2D(b.TEXTURE_2D,0,i(h.format),h.width,h.height,0,i(h.format),i(h.type),null);b.bindFramebuffer(b.FRAMEBUFFER,h.__webGLFramebuffer);b.framebufferTexture2D(b.FRAMEBUFFER,b.COLOR_ATTACHMENT0,
-b.TEXTURE_2D,h.__webGLTexture,0);b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,h.__webGLRenderbuffer);b.bindTexture(b.TEXTURE_2D,null);b.bindRenderbuffer(b.RENDERBUFFER,null);b.bindFramebuffer(b.FRAMEBUFFER,null)}if(h){k=h.__webGLFramebuffer;p=h.width;t=h.height}else{k=null;p=j.width;t=j.height}if(k!=n){b.bindFramebuffer(b.FRAMEBUFFER,k);b.viewport(0,0,p,t);f&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);n=k}this.autoClear&&this.clear();k=d.__webGLObjects.length;for(f=
-0;f<k;f++){t=d.__webGLObjects[f];p=t.object;if(m=p.visible){if(!(m=!(p instanceof THREE.Mesh)))a:{m=void 0;for(var x=p.matrix,u=-p.geometry.boundingSphere.radius*Math.max(p.scale.x,Math.max(p.scale.y,p.scale.z)),z=0;z<6;z++){m=l[z].x*x.n14+l[z].y*x.n24+l[z].z*x.n34+l[z].w;if(m<=u){m=false;break a}}m=true}m=m}if(m){if(p.autoUpdateMatrix){p.updateMatrix();p._objectMatrixArray.set(p.matrix.flatten())}this.setupMatrices(p,o);t.render=true}else t.render=false}m=d.__webGLObjectsImmediate.length;for(f=0;f<
-m;f++){p=d.__webGLObjectsImmediate[f].object;if(p.visible){if(p.autoUpdateMatrix){p.updateMatrix();p._objectMatrixArray.set(p.matrix.flatten())}this.setupMatrices(p,o)}}for(f=0;f<k;f++){t=d.__webGLObjects[f];if(t.render){p=t.object;t=t.buffer;e(p);this.renderPass(o,q,v,p,t,THREE.NormalBlending,false)}}for(f=0;f<m;f++){p=d.__webGLObjectsImmediate[f].object;if(p.visible){e(p);this.renderPassImmediate(o,q,v,p,THREE.NormalBlending,false)}}for(f=0;f<k;f++){t=d.__webGLObjects[f];if(t.render){p=t.object;
+k.__webGLUV2Buffer);b.vertexAttribPointer(d.uv2,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(d.uv2)}else b.disableVertexAttribArray(d.uv2);if(m instanceof THREE.Mesh)if(f.wireframe){b.lineWidth(f.wireframe_linewidth);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,k.__webGLLineBuffer);b.drawElements(b.LINES,k.__webGLLineCount,b.UNSIGNED_SHORT,0)}else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,k.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,k.__webGLFaceCount,b.UNSIGNED_SHORT,0)}else if(m instanceof THREE.Line){m=
+m.type==THREE.LineStrip?b.LINE_STRIP:b.LINES;b.lineWidth(f.linewidth);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,k.__webGLLineBuffer);b.drawElements(m,k.__webGLLineCount,b.UNSIGNED_SHORT,0)}else m instanceof THREE.ParticleSystem&&b.drawArrays(b.POINTS,0,k.__webGLParticleCount)};this.renderPass=function(d,o,h,f,k,m,t){var p,q,v,x,u;v=0;for(x=f.materials.length;v<x;v++){p=f.materials[v];if(p instanceof THREE.MeshFaceMaterial){p=0;for(q=k.materials.length;p<q;p++)if((u=k.materials[p])&&u.blending==m&&u.opacity<
+1==t){this.setBlending(u.blending);this.setDepthTest(u.depth_test);this.renderBuffer(d,o,h,u,k,f)}}else if((u=p)&&u.blending==m&&u.opacity<1==t){this.setBlending(u.blending);this.setDepthTest(u.depth_test);this.renderBuffer(d,o,h,u,k,f)}}};this.renderPassImmediate=function(d,o,h,f,k,m){var t,p,q,v;t=0;for(p=f.materials.length;t<p;t++)if((q=f.materials[t])&&q.blending==k&&q.opacity<1==m){this.setBlending(q.blending);this.setDepthTest(q.depth_test);v=this.setProgram(d,o,h,q,f);f.render(function(x){var u=
+v;if(!x.__webGLVertexBuffer)x.__webGLVertexBuffer=b.createBuffer();if(!x.__webGLNormalBuffer)x.__webGLNormalBuffer=b.createBuffer();if(x.hasPos){b.bindBuffer(b.ARRAY_BUFFER,x.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,x.positionArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(u.attributes.position);b.vertexAttribPointer(u.attributes.position,3,b.FLOAT,false,0,0)}if(x.hasNormal){b.bindBuffer(b.ARRAY_BUFFER,x.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,x.normalArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(u.attributes.normal);
+b.vertexAttribPointer(u.attributes.normal,3,b.FLOAT,false,0,0)}b.drawArrays(b.TRIANGLES,0,x.count);x.count=0})}};this.render=function(d,o,h,f){var k,m,t,p,q=d.lights,v=d.fog;o.autoUpdateMatrix&&o.updateMatrix();w.set(o.matrix.flatten());A.set(o.projectionMatrix.flatten());r.multiply(o.projectionMatrix,o.matrix);l[0].set(r.n41-r.n11,r.n42-r.n12,r.n43-r.n13,r.n44-r.n14);l[1].set(r.n41+r.n11,r.n42+r.n12,r.n43+r.n13,r.n44+r.n14);l[2].set(r.n41+r.n21,r.n42+r.n22,r.n43+r.n23,r.n44+r.n24);l[3].set(r.n41-
+r.n21,r.n42-r.n22,r.n43-r.n23,r.n44-r.n24);l[4].set(r.n41-r.n31,r.n42-r.n32,r.n43-r.n33,r.n44-r.n34);l[5].set(r.n41+r.n31,r.n42+r.n32,r.n43+r.n33,r.n44+r.n34);for(k=0;k<5;k++){p=l[k];p.divideScalar(Math.sqrt(p.x*p.x+p.y*p.y+p.z*p.z))}this.initWebGLObjects(d,o);f=f!==undefined?f:true;if(h&&!h.__webGLFramebuffer){h.__webGLFramebuffer=b.createFramebuffer();h.__webGLRenderbuffer=b.createRenderbuffer();h.__webGLTexture=b.createTexture();b.bindRenderbuffer(b.RENDERBUFFER,h.__webGLRenderbuffer);b.renderbufferStorage(b.RENDERBUFFER,
+b.DEPTH_COMPONENT16,h.width,h.height);b.bindTexture(b.TEXTURE_2D,h.__webGLTexture);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,i(h.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,i(h.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,i(h.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,i(h.min_filter));b.texImage2D(b.TEXTURE_2D,0,i(h.format),h.width,h.height,0,i(h.format),i(h.type),null);b.bindFramebuffer(b.FRAMEBUFFER,h.__webGLFramebuffer);b.framebufferTexture2D(b.FRAMEBUFFER,
+b.COLOR_ATTACHMENT0,b.TEXTURE_2D,h.__webGLTexture,0);b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,h.__webGLRenderbuffer);b.bindTexture(b.TEXTURE_2D,null);b.bindRenderbuffer(b.RENDERBUFFER,null);b.bindFramebuffer(b.FRAMEBUFFER,null)}if(h){k=h.__webGLFramebuffer;p=h.width;t=h.height}else{k=null;p=j.width;t=j.height}if(k!=n){b.bindFramebuffer(b.FRAMEBUFFER,k);b.viewport(0,0,p,t);f&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);n=k}this.autoClear&&this.clear();k=d.__webGLObjects.length;
+for(f=0;f<k;f++){t=d.__webGLObjects[f];p=t.object;if(m=p.visible){if(!(m=!(p instanceof THREE.Mesh)))a:{m=void 0;for(var x=p.matrix,u=-p.geometry.boundingSphere.radius*Math.max(p.scale.x,Math.max(p.scale.y,p.scale.z)),z=0;z<6;z++){m=l[z].x*x.n14+l[z].y*x.n24+l[z].z*x.n34+l[z].w;if(m<=u){m=false;break a}}m=true}m=m}if(m){if(p.autoUpdateMatrix){p.updateMatrix();p._objectMatrixArray.set(p.matrix.flatten())}this.setupMatrices(p,o);t.render=true}else t.render=false}m=d.__webGLObjectsImmediate.length;for(f=
+0;f<m;f++){p=d.__webGLObjectsImmediate[f].object;if(p.visible){if(p.autoUpdateMatrix){p.updateMatrix();p._objectMatrixArray.set(p.matrix.flatten())}this.setupMatrices(p,o)}}for(f=0;f<k;f++){t=d.__webGLObjects[f];if(t.render){p=t.object;t=t.buffer;e(p);this.renderPass(o,q,v,p,t,THREE.NormalBlending,false)}}for(f=0;f<m;f++){p=d.__webGLObjectsImmediate[f].object;if(p.visible){e(p);this.renderPassImmediate(o,q,v,p,THREE.NormalBlending,false)}}for(f=0;f<k;f++){t=d.__webGLObjects[f];if(t.render){p=t.object;
 t=t.buffer;e(p);this.renderPass(o,q,v,p,t,THREE.AdditiveBlending,false);this.renderPass(o,q,v,p,t,THREE.SubtractiveBlending,false);this.renderPass(o,q,v,p,t,THREE.AdditiveBlending,true);this.renderPass(o,q,v,p,t,THREE.SubtractiveBlending,true);this.renderPass(o,q,v,p,t,THREE.NormalBlending,true);this.renderPass(o,q,v,p,t,THREE.BillboardBlending,false)}}for(f=0;f<m;f++){p=d.__webGLObjectsImmediate[f].object;if(p.visible){e(p);this.renderPassImmediate(o,q,v,p,THREE.NormalBlending,true)}}if(h&&h.min_filter!==
 THREE.NearestFilter&&h.min_filter!==THREE.LinearFilter){b.bindTexture(b.TEXTURE_2D,h.__webGLTexture);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}};this.initWebGLObjects=function(d,o){function h(u,z,B,N){if(u[z]==undefined){d.__webGLObjects.push({buffer:B,object:N});u[z]=1}}function f(u,z,B){if(u[z]==undefined){d.__webGLObjectsImmediate.push({object:B});u[z]=1}}var k,m,t,p,q,v,x;if(!d.__webGLObjects){d.__webGLObjects=[];d.__webGLObjectsMap={};d.__webGLObjectsImmediate=[]}k=0;for(m=
 d.objects.length;k<m;k++){t=d.objects[k];q=t.geometry;if(d.__webGLObjectsMap[t.id]==undefined){d.__webGLObjectsMap[t.id]={};t._modelViewMatrix=new THREE.Matrix4;t._normalMatrixArray=new Float32Array(9);t._modelViewMatrixArray=new Float32Array(16);t._objectMatrixArray=new Float32Array(16);t._objectMatrixArray.set(t.matrix.flatten())}x=d.__webGLObjectsMap[t.id];if(t instanceof THREE.Mesh){for(p in q.geometryChunks){v=q.geometryChunks[p];if(!v.__webGLVertexBuffer){this.createMeshBuffers(v);this.initMeshBuffers(v,

+ 10 - 10
build/ThreeExtras.js

@@ -187,16 +187,16 @@ b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_M
 l.image.loaded){l.__webGLTexture=b.createTexture();b.bindTexture(b.TEXTURE_2D,l.__webGLTexture);b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,l.image);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,j(l.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,j(l.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,j(l.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,j(l.min_filter));b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}b.activeTexture(b.TEXTURE0+
 h);b.bindTexture(b.TEXTURE_2D,l.__webGLTexture)}}}return w};this.renderBuffer=function(f,p,h,l,t,w){f=this.setProgram(f,p,h,l,w).attributes;b.bindBuffer(b.ARRAY_BUFFER,t.__webGLVertexBuffer);b.vertexAttribPointer(f.position,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.position);if(f.color>=0){b.bindBuffer(b.ARRAY_BUFFER,t.__webGLColorBuffer);b.vertexAttribPointer(f.color,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.color)}if(f.normal>=0){b.bindBuffer(b.ARRAY_BUFFER,t.__webGLNormalBuffer);
 b.vertexAttribPointer(f.normal,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.normal)}if(f.tangent>=0){b.bindBuffer(b.ARRAY_BUFFER,t.__webGLTangentBuffer);b.vertexAttribPointer(f.tangent,4,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.tangent)}if(f.uv>=0)if(t.__webGLUVBuffer){b.bindBuffer(b.ARRAY_BUFFER,t.__webGLUVBuffer);b.vertexAttribPointer(f.uv,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.uv)}else b.disableVertexAttribArray(f.uv);if(f.uv2>=0)if(t.__webGLUV2Buffer){b.bindBuffer(b.ARRAY_BUFFER,
-t.__webGLUV2Buffer);b.vertexAttribPointer(f.uv2,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.uv2)}else b.disableVertexAttribArray(f.uv2);if(l.wireframe||l instanceof THREE.LineBasicMaterial){f=l.wireframe_linewidth!==undefined?l.wireframe_linewidth:l.linewidth!==undefined?l.linewidth:1;l=l instanceof THREE.LineBasicMaterial&&w.type==THREE.LineStrip?b.LINE_STRIP:b.LINES;b.lineWidth(f);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,t.__webGLLineBuffer);b.drawElements(l,t.__webGLLineCount,b.UNSIGNED_SHORT,
-0)}else if(l instanceof THREE.ParticleBasicMaterial)b.drawArrays(b.POINTS,0,t.__webGLParticleCount);else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,t.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,t.__webGLFaceCount,b.UNSIGNED_SHORT,0)}};this.renderPass=function(f,p,h,l,t,w,x){var u,A,C,F,E;C=0;for(F=l.materials.length;C<F;C++){u=l.materials[C];if(u instanceof THREE.MeshFaceMaterial){u=0;for(A=t.materials.length;u<A;u++)if((E=t.materials[u])&&E.blending==w&&E.opacity<1==x){this.setBlending(E.blending);this.setDepthTest(E.depth_test);
-this.renderBuffer(f,p,h,E,t,l)}}else if((E=u)&&E.blending==w&&E.opacity<1==x){this.setBlending(E.blending);this.setDepthTest(E.depth_test);this.renderBuffer(f,p,h,E,t,l)}}};this.renderPassImmediate=function(f,p,h,l,t,w){var x,u,A,C;x=0;for(u=l.materials.length;x<u;x++)if((A=l.materials[x])&&A.blending==t&&A.opacity<1==w){this.setBlending(A.blending);this.setDepthTest(A.depth_test);C=this.setProgram(f,p,h,A,l);l.render(function(F){var E=C;if(!F.__webGLVertexBuffer)F.__webGLVertexBuffer=b.createBuffer();
-if(!F.__webGLNormalBuffer)F.__webGLNormalBuffer=b.createBuffer();if(F.hasPos){b.bindBuffer(b.ARRAY_BUFFER,F.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,F.positionArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(E.attributes.position);b.vertexAttribPointer(E.attributes.position,3,b.FLOAT,false,0,0)}if(F.hasNormal){b.bindBuffer(b.ARRAY_BUFFER,F.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,F.normalArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(E.attributes.normal);b.vertexAttribPointer(E.attributes.normal,
-3,b.FLOAT,false,0,0)}b.drawArrays(b.TRIANGLES,0,F.count);F.count=0})}};this.render=function(f,p,h,l){var t,w,x,u,A=f.lights,C=f.fog;p.autoUpdateMatrix&&p.updateMatrix();v.set(p.matrix.flatten());y.set(p.projectionMatrix.flatten());o.multiply(p.projectionMatrix,p.matrix);n[0].set(o.n41-o.n11,o.n42-o.n12,o.n43-o.n13,o.n44-o.n14);n[1].set(o.n41+o.n11,o.n42+o.n12,o.n43+o.n13,o.n44+o.n14);n[2].set(o.n41+o.n21,o.n42+o.n22,o.n43+o.n23,o.n44+o.n24);n[3].set(o.n41-o.n21,o.n42-o.n22,o.n43-o.n23,o.n44-o.n24);
-n[4].set(o.n41-o.n31,o.n42-o.n32,o.n43-o.n33,o.n44-o.n34);n[5].set(o.n41+o.n31,o.n42+o.n32,o.n43+o.n33,o.n44+o.n34);for(t=0;t<5;t++){u=n[t];u.divideScalar(Math.sqrt(u.x*u.x+u.y*u.y+u.z*u.z))}this.initWebGLObjects(f,p);l=l!==undefined?l:true;if(h&&!h.__webGLFramebuffer){h.__webGLFramebuffer=b.createFramebuffer();h.__webGLRenderbuffer=b.createRenderbuffer();h.__webGLTexture=b.createTexture();b.bindRenderbuffer(b.RENDERBUFFER,h.__webGLRenderbuffer);b.renderbufferStorage(b.RENDERBUFFER,b.DEPTH_COMPONENT16,
-h.width,h.height);b.bindTexture(b.TEXTURE_2D,h.__webGLTexture);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,j(h.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,j(h.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,j(h.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,j(h.min_filter));b.texImage2D(b.TEXTURE_2D,0,j(h.format),h.width,h.height,0,j(h.format),j(h.type),null);b.bindFramebuffer(b.FRAMEBUFFER,h.__webGLFramebuffer);b.framebufferTexture2D(b.FRAMEBUFFER,b.COLOR_ATTACHMENT0,
-b.TEXTURE_2D,h.__webGLTexture,0);b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,h.__webGLRenderbuffer);b.bindTexture(b.TEXTURE_2D,null);b.bindRenderbuffer(b.RENDERBUFFER,null);b.bindFramebuffer(b.FRAMEBUFFER,null)}if(h){t=h.__webGLFramebuffer;u=h.width;x=h.height}else{t=null;u=g.width;x=g.height}if(t!=k){b.bindFramebuffer(b.FRAMEBUFFER,t);b.viewport(0,0,u,x);l&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);k=t}this.autoClear&&this.clear();t=f.__webGLObjects.length;for(l=
-0;l<t;l++){x=f.__webGLObjects[l];u=x.object;if(w=u.visible){if(!(w=!(u instanceof THREE.Mesh)))a:{w=void 0;for(var F=u.matrix,E=-u.geometry.boundingSphere.radius*Math.max(u.scale.x,Math.max(u.scale.y,u.scale.z)),D=0;D<6;D++){w=n[D].x*F.n14+n[D].y*F.n24+n[D].z*F.n34+n[D].w;if(w<=E){w=false;break a}}w=true}w=w}if(w){if(u.autoUpdateMatrix){u.updateMatrix();u._objectMatrixArray.set(u.matrix.flatten())}this.setupMatrices(u,p);x.render=true}else x.render=false}w=f.__webGLObjectsImmediate.length;for(l=0;l<
-w;l++){u=f.__webGLObjectsImmediate[l].object;if(u.visible){if(u.autoUpdateMatrix){u.updateMatrix();u._objectMatrixArray.set(u.matrix.flatten())}this.setupMatrices(u,p)}}for(l=0;l<t;l++){x=f.__webGLObjects[l];if(x.render){u=x.object;x=x.buffer;d(u);this.renderPass(p,A,C,u,x,THREE.NormalBlending,false)}}for(l=0;l<w;l++){u=f.__webGLObjectsImmediate[l].object;if(u.visible){d(u);this.renderPassImmediate(p,A,C,u,THREE.NormalBlending,false)}}for(l=0;l<t;l++){x=f.__webGLObjects[l];if(x.render){u=x.object;
+t.__webGLUV2Buffer);b.vertexAttribPointer(f.uv2,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.uv2)}else b.disableVertexAttribArray(f.uv2);if(w instanceof THREE.Mesh)if(l.wireframe){b.lineWidth(l.wireframe_linewidth);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,t.__webGLLineBuffer);b.drawElements(b.LINES,t.__webGLLineCount,b.UNSIGNED_SHORT,0)}else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,t.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,t.__webGLFaceCount,b.UNSIGNED_SHORT,0)}else if(w instanceof THREE.Line){w=
+w.type==THREE.LineStrip?b.LINE_STRIP:b.LINES;b.lineWidth(l.linewidth);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,t.__webGLLineBuffer);b.drawElements(w,t.__webGLLineCount,b.UNSIGNED_SHORT,0)}else w instanceof THREE.ParticleSystem&&b.drawArrays(b.POINTS,0,t.__webGLParticleCount)};this.renderPass=function(f,p,h,l,t,w,x){var u,A,C,F,E;C=0;for(F=l.materials.length;C<F;C++){u=l.materials[C];if(u instanceof THREE.MeshFaceMaterial){u=0;for(A=t.materials.length;u<A;u++)if((E=t.materials[u])&&E.blending==w&&E.opacity<
+1==x){this.setBlending(E.blending);this.setDepthTest(E.depth_test);this.renderBuffer(f,p,h,E,t,l)}}else if((E=u)&&E.blending==w&&E.opacity<1==x){this.setBlending(E.blending);this.setDepthTest(E.depth_test);this.renderBuffer(f,p,h,E,t,l)}}};this.renderPassImmediate=function(f,p,h,l,t,w){var x,u,A,C;x=0;for(u=l.materials.length;x<u;x++)if((A=l.materials[x])&&A.blending==t&&A.opacity<1==w){this.setBlending(A.blending);this.setDepthTest(A.depth_test);C=this.setProgram(f,p,h,A,l);l.render(function(F){var E=
+C;if(!F.__webGLVertexBuffer)F.__webGLVertexBuffer=b.createBuffer();if(!F.__webGLNormalBuffer)F.__webGLNormalBuffer=b.createBuffer();if(F.hasPos){b.bindBuffer(b.ARRAY_BUFFER,F.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,F.positionArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(E.attributes.position);b.vertexAttribPointer(E.attributes.position,3,b.FLOAT,false,0,0)}if(F.hasNormal){b.bindBuffer(b.ARRAY_BUFFER,F.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,F.normalArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(E.attributes.normal);
+b.vertexAttribPointer(E.attributes.normal,3,b.FLOAT,false,0,0)}b.drawArrays(b.TRIANGLES,0,F.count);F.count=0})}};this.render=function(f,p,h,l){var t,w,x,u,A=f.lights,C=f.fog;p.autoUpdateMatrix&&p.updateMatrix();v.set(p.matrix.flatten());y.set(p.projectionMatrix.flatten());o.multiply(p.projectionMatrix,p.matrix);n[0].set(o.n41-o.n11,o.n42-o.n12,o.n43-o.n13,o.n44-o.n14);n[1].set(o.n41+o.n11,o.n42+o.n12,o.n43+o.n13,o.n44+o.n14);n[2].set(o.n41+o.n21,o.n42+o.n22,o.n43+o.n23,o.n44+o.n24);n[3].set(o.n41-
+o.n21,o.n42-o.n22,o.n43-o.n23,o.n44-o.n24);n[4].set(o.n41-o.n31,o.n42-o.n32,o.n43-o.n33,o.n44-o.n34);n[5].set(o.n41+o.n31,o.n42+o.n32,o.n43+o.n33,o.n44+o.n34);for(t=0;t<5;t++){u=n[t];u.divideScalar(Math.sqrt(u.x*u.x+u.y*u.y+u.z*u.z))}this.initWebGLObjects(f,p);l=l!==undefined?l:true;if(h&&!h.__webGLFramebuffer){h.__webGLFramebuffer=b.createFramebuffer();h.__webGLRenderbuffer=b.createRenderbuffer();h.__webGLTexture=b.createTexture();b.bindRenderbuffer(b.RENDERBUFFER,h.__webGLRenderbuffer);b.renderbufferStorage(b.RENDERBUFFER,
+b.DEPTH_COMPONENT16,h.width,h.height);b.bindTexture(b.TEXTURE_2D,h.__webGLTexture);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,j(h.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,j(h.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,j(h.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,j(h.min_filter));b.texImage2D(b.TEXTURE_2D,0,j(h.format),h.width,h.height,0,j(h.format),j(h.type),null);b.bindFramebuffer(b.FRAMEBUFFER,h.__webGLFramebuffer);b.framebufferTexture2D(b.FRAMEBUFFER,
+b.COLOR_ATTACHMENT0,b.TEXTURE_2D,h.__webGLTexture,0);b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,h.__webGLRenderbuffer);b.bindTexture(b.TEXTURE_2D,null);b.bindRenderbuffer(b.RENDERBUFFER,null);b.bindFramebuffer(b.FRAMEBUFFER,null)}if(h){t=h.__webGLFramebuffer;u=h.width;x=h.height}else{t=null;u=g.width;x=g.height}if(t!=k){b.bindFramebuffer(b.FRAMEBUFFER,t);b.viewport(0,0,u,x);l&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);k=t}this.autoClear&&this.clear();t=f.__webGLObjects.length;
+for(l=0;l<t;l++){x=f.__webGLObjects[l];u=x.object;if(w=u.visible){if(!(w=!(u instanceof THREE.Mesh)))a:{w=void 0;for(var F=u.matrix,E=-u.geometry.boundingSphere.radius*Math.max(u.scale.x,Math.max(u.scale.y,u.scale.z)),D=0;D<6;D++){w=n[D].x*F.n14+n[D].y*F.n24+n[D].z*F.n34+n[D].w;if(w<=E){w=false;break a}}w=true}w=w}if(w){if(u.autoUpdateMatrix){u.updateMatrix();u._objectMatrixArray.set(u.matrix.flatten())}this.setupMatrices(u,p);x.render=true}else x.render=false}w=f.__webGLObjectsImmediate.length;for(l=
+0;l<w;l++){u=f.__webGLObjectsImmediate[l].object;if(u.visible){if(u.autoUpdateMatrix){u.updateMatrix();u._objectMatrixArray.set(u.matrix.flatten())}this.setupMatrices(u,p)}}for(l=0;l<t;l++){x=f.__webGLObjects[l];if(x.render){u=x.object;x=x.buffer;d(u);this.renderPass(p,A,C,u,x,THREE.NormalBlending,false)}}for(l=0;l<w;l++){u=f.__webGLObjectsImmediate[l].object;if(u.visible){d(u);this.renderPassImmediate(p,A,C,u,THREE.NormalBlending,false)}}for(l=0;l<t;l++){x=f.__webGLObjects[l];if(x.render){u=x.object;
 x=x.buffer;d(u);this.renderPass(p,A,C,u,x,THREE.AdditiveBlending,false);this.renderPass(p,A,C,u,x,THREE.SubtractiveBlending,false);this.renderPass(p,A,C,u,x,THREE.AdditiveBlending,true);this.renderPass(p,A,C,u,x,THREE.SubtractiveBlending,true);this.renderPass(p,A,C,u,x,THREE.NormalBlending,true);this.renderPass(p,A,C,u,x,THREE.BillboardBlending,false)}}for(l=0;l<w;l++){u=f.__webGLObjectsImmediate[l].object;if(u.visible){d(u);this.renderPassImmediate(p,A,C,u,THREE.NormalBlending,true)}}if(h&&h.min_filter!==
 THREE.NearestFilter&&h.min_filter!==THREE.LinearFilter){b.bindTexture(b.TEXTURE_2D,h.__webGLTexture);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}};this.initWebGLObjects=function(f,p){function h(E,D,I,S){if(E[D]==undefined){f.__webGLObjects.push({buffer:I,object:S});E[D]=1}}function l(E,D,I){if(E[D]==undefined){f.__webGLObjectsImmediate.push({object:I});E[D]=1}}var t,w,x,u,A,C,F;if(!f.__webGLObjects){f.__webGLObjects=[];f.__webGLObjectsMap={};f.__webGLObjectsImmediate=[]}t=0;for(w=
 f.objects.length;t<w;t++){x=f.objects[t];A=x.geometry;if(f.__webGLObjectsMap[x.id]==undefined){f.__webGLObjectsMap[x.id]={};x._modelViewMatrix=new THREE.Matrix4;x._normalMatrixArray=new Float32Array(9);x._modelViewMatrixArray=new Float32Array(16);x._objectMatrixArray=new Float32Array(16);x._objectMatrixArray.set(x.matrix.flatten())}F=f.__webGLObjectsMap[x.id];if(x instanceof THREE.Mesh){for(u in A.geometryChunks){C=A.geometryChunks[u];if(!C.__webGLVertexBuffer){this.createMeshBuffers(C);this.initMeshBuffers(C,

+ 28 - 17
src/renderers/WebGLRenderer.js

@@ -1242,31 +1242,42 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		}
 
-		// render lines
+		// render mesh
 
-		if ( material.wireframe || material instanceof THREE.LineBasicMaterial ) {
+		if ( object instanceof THREE.Mesh ) {
 
-			linewidth = material.wireframe_linewidth !== undefined ? material.wireframe_linewidth :
-						material.linewidth !== undefined ? material.linewidth : 1;
+			// wireframe
+			
+			if ( material.wireframe ) {
 
-			primitives = material instanceof THREE.LineBasicMaterial && object.type == THREE.LineStrip ? _gl.LINE_STRIP : _gl.LINES;
+				_gl.lineWidth( material.wireframe_linewidth );
+				_gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, geometryChunk.__webGLLineBuffer );
+				_gl.drawElements( _gl.LINES, geometryChunk.__webGLLineCount, _gl.UNSIGNED_SHORT, 0 );
+			
+			// triangles
+			
+			} else {
+				
+				_gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, geometryChunk.__webGLFaceBuffer );
+				_gl.drawElements( _gl.TRIANGLES, geometryChunk.__webGLFaceCount, _gl.UNSIGNED_SHORT, 0 );
+				
+			}
+		
+		// render lines
+		
+		} else if ( object instanceof THREE.Line ) {
+			
+			primitives = object.type == THREE.LineStrip ? _gl.LINE_STRIP : _gl.LINES;
 
-			_gl.lineWidth( linewidth );
+			_gl.lineWidth( material.linewidth );
 			_gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, geometryChunk.__webGLLineBuffer );
 			_gl.drawElements( primitives, geometryChunk.__webGLLineCount, _gl.UNSIGNED_SHORT, 0 );
-
+		
 		// render particles
-
-		} else if ( material instanceof THREE.ParticleBasicMaterial ) {
-			
-			_gl.drawArrays( _gl.POINTS, 0, geometryChunk.__webGLParticleCount );			
-
-		// render triangles
-			
-		} else {
+		
+		} else if ( object instanceof THREE.ParticleSystem ) {
 			
-			_gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, geometryChunk.__webGLFaceBuffer );
-			_gl.drawElements( _gl.TRIANGLES, geometryChunk.__webGLFaceCount, _gl.UNSIGNED_SHORT, 0 );
+			_gl.drawArrays( _gl.POINTS, 0, geometryChunk.__webGLParticleCount );
 			
 		}