From eced0ca840eb0f5cc23dc69ad785a48825396d3e Mon Sep 17 00:00:00 2001 From: alteredq Date: Sun, 13 Feb 2011 22:51:17 +0100 Subject: [PATCH] Small performance optimizations in WebGLRenderer: skipping few more typed arrays setters. This should affect only use cases with lots of animated objects (unlike current performance tests where object matrices are not updated). --- build/Three.js | 14 ++++++------- build/ThreeDebug.js | 14 ++++++------- build/ThreeExtras.js | 14 ++++++------- examples/materials_shaders_fresnel.html | 2 ++ src/core/Matrix4.js | 26 +++++++++++++++++++++++++ src/renderers/WebGLRenderer.js | 14 ++++++------- 6 files changed, 56 insertions(+), 28 deletions(-) diff --git a/build/Three.js b/build/Three.js index f9c4a15a..755d893b 100755 --- a/build/Three.js +++ b/build/Three.js @@ -32,10 +32,10 @@ e[15]=this.n44;return this},multiplySelf:function(a){var c=this.n11,e=this.n12,g l+s*t+m*o;this.n23=j*r+b*v+s*x+m*u;this.n24=j*A+b*B+s*N+m*a;this.n31=p*d+q*n+z*h+w*f;this.n32=p*k+q*l+z*t+w*o;this.n33=p*r+q*v+z*x+w*u;this.n34=p*A+q*B+z*N+w*a;this.n41=y*d+F*n+K*h+L*f;this.n42=y*k+F*l+K*t+L*o;this.n43=y*r+F*v+K*x+L*u;this.n44=y*A+F*B+K*N+L*a;return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=a;this.n42*=a;this.n43*=a;this.n44*=a;return this}, determinant:function(){var a=this.n11,c=this.n12,e=this.n13,g=this.n14,i=this.n21,j=this.n22,b=this.n23,s=this.n24,m=this.n31,p=this.n32,q=this.n33,z=this.n34,w=this.n41,y=this.n42,F=this.n43,K=this.n44;return g*b*p*w-e*s*p*w-g*j*q*w+c*s*q*w+e*j*z*w-c*b*z*w-g*b*m*y+e*s*m*y+g*i*q*y-a*s*q*y-e*i*z*y+a*b*z*y+g*j*m*F-c*s*m*F-g*i*p*F+a*s*p*F+c*i*z*F-a*j*z*F-e*j*m*K+c*b*m*K+e*i*p*K-a*b*p*K-c*i*q*K+a*j*q*K},transpose:function(){function a(c,e,g){var i=c[e];c[e]=c[g];c[g]=i}a(this,"n21","n12");a(this,"n31", "n13");a(this,"n32","n23");a(this,"n41","n14");a(this,"n42","n24");a(this,"n43","n34");return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=this.n44;return a},flatten:function(){var a=this.flat;a[0]=this.n11;a[1]=this.n21;a[2]=this.n31;a[3]=this.n41;a[4]=this.n12;a[5]= -this.n22;a[6]=this.n32;a[7]=this.n42;a[8]=this.n13;a[9]=this.n23;a[10]=this.n33;a[11]=this.n43;a[12]=this.n14;a[13]=this.n24;a[14]=this.n34;a[15]=this.n44;return a},setTranslation:function(a,c,e){this.set(1,0,0,a,0,1,0,c,0,0,1,e,0,0,0,1);return this},setScale:function(a,c,e){this.set(a,0,0,0,0,c,0,0,0,0,e,0,0,0,0,1);return this},setRotX:function(a){var c=Math.cos(a);a=Math.sin(a);this.set(1,0,0,0,0,c,-a,0,0,a,c,0,0,0,0,1);return this},setRotY:function(a){var c=Math.cos(a);a=Math.sin(a);this.set(c, -0,a,0,0,1,0,0,-a,0,c,0,0,0,0,1);return this},setRotZ:function(a){var c=Math.cos(a);a=Math.sin(a);this.set(c,-a,0,0,a,c,0,0,0,0,1,0,0,0,0,1);return this},setRotAxis:function(a,c){var e=Math.cos(c),g=Math.sin(c),i=1-e,j=a.x,b=a.y,s=a.z,m=i*j,p=i*b;this.set(m*j+e,m*b-g*s,m*s+g*b,0,m*b+g*s,p*b+e,p*s-g*j,0,m*s-g*b,p*s+g*j,i*s*s+e,0,0,0,0,1);return this},toString:function(){return"| "+this.n11+" "+this.n12+" "+this.n13+" "+this.n14+" |\n| "+this.n21+" "+this.n22+" "+this.n23+" "+this.n24+" |\n| "+this.n31+ -" "+this.n32+" "+this.n33+" "+this.n34+" |\n| "+this.n41+" "+this.n42+" "+this.n43+" "+this.n44+" |"}};THREE.Matrix4.translationMatrix=function(a,c,e){var g=new THREE.Matrix4;g.setTranslation(a,c,e);return g};THREE.Matrix4.scaleMatrix=function(a,c,e){var g=new THREE.Matrix4;g.setScale(a,c,e);return g};THREE.Matrix4.rotationXMatrix=function(a){var c=new THREE.Matrix4;c.setRotX(a);return c};THREE.Matrix4.rotationYMatrix=function(a){var c=new THREE.Matrix4;c.setRotY(a);return c}; -THREE.Matrix4.rotationZMatrix=function(a){var c=new THREE.Matrix4;c.setRotZ(a);return c};THREE.Matrix4.rotationAxisAngleMatrix=function(a,c){var e=new THREE.Matrix4;e.setRotAxis(a,c);return e}; +this.n22;a[6]=this.n32;a[7]=this.n42;a[8]=this.n13;a[9]=this.n23;a[10]=this.n33;a[11]=this.n43;a[12]=this.n14;a[13]=this.n24;a[14]=this.n34;a[15]=this.n44;return a},flattenToArray:function(a){a[0]=this.n11;a[1]=this.n21;a[2]=this.n31;a[3]=this.n41;a[4]=this.n12;a[5]=this.n22;a[6]=this.n32;a[7]=this.n42;a[8]=this.n13;a[9]=this.n23;a[10]=this.n33;a[11]=this.n43;a[12]=this.n14;a[13]=this.n24;a[14]=this.n34;a[15]=this.n44;return a},setTranslation:function(a,c,e){this.set(1,0,0,a,0,1,0,c,0,0,1,e,0,0,0, +1);return this},setScale:function(a,c,e){this.set(a,0,0,0,0,c,0,0,0,0,e,0,0,0,0,1);return this},setRotX:function(a){var c=Math.cos(a);a=Math.sin(a);this.set(1,0,0,0,0,c,-a,0,0,a,c,0,0,0,0,1);return this},setRotY:function(a){var c=Math.cos(a);a=Math.sin(a);this.set(c,0,a,0,0,1,0,0,-a,0,c,0,0,0,0,1);return this},setRotZ:function(a){var c=Math.cos(a);a=Math.sin(a);this.set(c,-a,0,0,a,c,0,0,0,0,1,0,0,0,0,1);return this},setRotAxis:function(a,c){var e=Math.cos(c),g=Math.sin(c),i=1-e,j=a.x,b=a.y,s=a.z, +m=i*j,p=i*b;this.set(m*j+e,m*b-g*s,m*s+g*b,0,m*b+g*s,p*b+e,p*s-g*j,0,m*s-g*b,p*s+g*j,i*s*s+e,0,0,0,0,1);return this},toString:function(){return"| "+this.n11+" "+this.n12+" "+this.n13+" "+this.n14+" |\n| "+this.n21+" "+this.n22+" "+this.n23+" "+this.n24+" |\n| "+this.n31+" "+this.n32+" "+this.n33+" "+this.n34+" |\n| "+this.n41+" "+this.n42+" "+this.n43+" "+this.n44+" |"}};THREE.Matrix4.translationMatrix=function(a,c,e){var g=new THREE.Matrix4;g.setTranslation(a,c,e);return g}; +THREE.Matrix4.scaleMatrix=function(a,c,e){var g=new THREE.Matrix4;g.setScale(a,c,e);return g};THREE.Matrix4.rotationXMatrix=function(a){var c=new THREE.Matrix4;c.setRotX(a);return c};THREE.Matrix4.rotationYMatrix=function(a){var c=new THREE.Matrix4;c.setRotY(a);return c};THREE.Matrix4.rotationZMatrix=function(a){var c=new THREE.Matrix4;c.setRotZ(a);return c};THREE.Matrix4.rotationAxisAngleMatrix=function(a,c){var e=new THREE.Matrix4;e.setRotAxis(a,c);return e}; THREE.Matrix4.makeInvert=function(a){var c=a.n11,e=a.n12,g=a.n13,i=a.n14,j=a.n21,b=a.n22,s=a.n23,m=a.n24,p=a.n31,q=a.n32,z=a.n33,w=a.n34,y=a.n41,F=a.n42,K=a.n43,L=a.n44,d=new THREE.Matrix4;d.n11=s*w*F-m*z*F+m*q*K-b*w*K-s*q*L+b*z*L;d.n12=i*z*F-g*w*F-i*q*K+e*w*K+g*q*L-e*z*L;d.n13=g*m*F-i*s*F+i*b*K-e*m*K-g*b*L+e*s*L;d.n14=i*s*q-g*m*q-i*b*z+e*m*z+g*b*w-e*s*w;d.n21=m*z*y-s*w*y-m*p*K+j*w*K+s*p*L-j*z*L;d.n22=g*w*y-i*z*y+i*p*K-c*w*K-g*p*L+c*z*L;d.n23=i*s*y-g*m*y-i*j*K+c*m*K+g*j*L-c*s*L;d.n24=g*m*p-i*s*p+ i*j*z-c*m*z-g*j*w+c*s*w;d.n31=b*w*y-m*q*y+m*p*F-j*w*F-b*p*L+j*q*L;d.n32=i*q*y-e*w*y-i*p*F+c*w*F+e*p*L-c*q*L;d.n33=g*m*y-i*b*y+i*j*F-c*m*F-e*j*L+c*b*L;d.n34=i*b*p-e*m*p-i*j*q+c*m*q+e*j*w-c*b*w;d.n41=s*q*y-b*z*y-s*p*F+j*z*F+b*p*K-j*q*K;d.n42=e*z*y-g*q*y+g*p*F-c*z*F-e*p*K+c*q*K;d.n43=g*b*y-e*s*y-g*j*F+c*s*F+e*j*K-c*b*K;d.n44=e*s*p-g*b*p+g*j*q-c*s*q-e*j*z+c*b*z;d.multiplyScalar(1/a.determinant());return d}; THREE.Matrix4.makeInvert3x3=function(a){var c=a.flatten();a=a.m33;var e=a.m,g=c[10]*c[5]-c[6]*c[9],i=-c[10]*c[1]+c[2]*c[9],j=c[6]*c[1]-c[2]*c[5],b=-c[10]*c[4]+c[6]*c[8],s=c[10]*c[0]-c[2]*c[8],m=-c[6]*c[0]+c[2]*c[4],p=c[9]*c[4]-c[5]*c[8],q=-c[9]*c[0]+c[1]*c[8],z=c[5]*c[0]-c[1]*c[4];c=c[0]*g+c[1]*b+c[2]*p;if(c==0)throw"matrix not invertible";c=1/c;e[0]=c*g;e[1]=c*i;e[2]=c*j;e[3]=c*b;e[4]=c*s;e[5]=c*m;e[6]=c*p;e[7]=c*q;e[8]=c*z;return a}; @@ -191,15 +191,15 @@ if(l instanceof THREE.Mesh)if(f.wireframe){b.lineWidth(f.wireframe_linewidth);b. b.drawArrays(b.POINTS,0,k.__webGLParticleCount)};this.renderPass=function(d,n,h,f,k,l,t){var o,r,v,x,u;v=0;for(x=f.materials.length;v=0;h--){f=d.__webGLObjects[h].object; n==f&&d.__webGLObjects.splice(h,1)}};this.setupMatrices=function(d,n){d._modelViewMatrix.multiplyToArray(n.matrix,d.matrix,d._modelViewMatrixArray);d._normalMatrix=THREE.Matrix4.makeInvert3x3(d._modelViewMatrix).transposeIntoArray(d._normalMatrixArray)};this.loadMatrices=function(d,n){b.uniformMatrix4fv(d.uniforms.viewMatrix,false,w);b.uniformMatrix4fv(d.uniforms.projectionMatrix,false,z);b.uniformMatrix4fv(d.uniforms.modelViewMatrix,false,n._modelViewMatrixArray);b.uniformMatrix3fv(d.uniforms.normalMatrix, diff --git a/build/ThreeDebug.js b/build/ThreeDebug.js index 742eb107..27a319c1 100644 --- a/build/ThreeDebug.js +++ b/build/ThreeDebug.js @@ -32,10 +32,10 @@ e[15]=this.n44;return this},multiplySelf:function(a){var c=this.n11,e=this.n12,g m+s*t+n*p;this.n23=j*r+b*v+s*x+n*u;this.n24=j*A+b*B+s*N+n*a;this.n31=l*d+q*o+z*h+w*f;this.n32=l*k+q*m+z*t+w*p;this.n33=l*r+q*v+z*x+w*u;this.n34=l*A+q*B+z*N+w*a;this.n41=y*d+F*o+K*h+L*f;this.n42=y*k+F*m+K*t+L*p;this.n43=y*r+F*v+K*x+L*u;this.n44=y*A+F*B+K*N+L*a;return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=a;this.n42*=a;this.n43*=a;this.n44*=a;return this}, determinant:function(){var a=this.n11,c=this.n12,e=this.n13,g=this.n14,i=this.n21,j=this.n22,b=this.n23,s=this.n24,n=this.n31,l=this.n32,q=this.n33,z=this.n34,w=this.n41,y=this.n42,F=this.n43,K=this.n44;return g*b*l*w-e*s*l*w-g*j*q*w+c*s*q*w+e*j*z*w-c*b*z*w-g*b*n*y+e*s*n*y+g*i*q*y-a*s*q*y-e*i*z*y+a*b*z*y+g*j*n*F-c*s*n*F-g*i*l*F+a*s*l*F+c*i*z*F-a*j*z*F-e*j*n*K+c*b*n*K+e*i*l*K-a*b*l*K-c*i*q*K+a*j*q*K},transpose:function(){function a(c,e,g){var i=c[e];c[e]=c[g];c[g]=i}a(this,"n21","n12");a(this,"n31", "n13");a(this,"n32","n23");a(this,"n41","n14");a(this,"n42","n24");a(this,"n43","n34");return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=this.n44;return a},flatten:function(){var a=this.flat;a[0]=this.n11;a[1]=this.n21;a[2]=this.n31;a[3]=this.n41;a[4]=this.n12;a[5]= -this.n22;a[6]=this.n32;a[7]=this.n42;a[8]=this.n13;a[9]=this.n23;a[10]=this.n33;a[11]=this.n43;a[12]=this.n14;a[13]=this.n24;a[14]=this.n34;a[15]=this.n44;return a},setTranslation:function(a,c,e){this.set(1,0,0,a,0,1,0,c,0,0,1,e,0,0,0,1);return this},setScale:function(a,c,e){this.set(a,0,0,0,0,c,0,0,0,0,e,0,0,0,0,1);return this},setRotX:function(a){var c=Math.cos(a);a=Math.sin(a);this.set(1,0,0,0,0,c,-a,0,0,a,c,0,0,0,0,1);return this},setRotY:function(a){var c=Math.cos(a);a=Math.sin(a);this.set(c, -0,a,0,0,1,0,0,-a,0,c,0,0,0,0,1);return this},setRotZ:function(a){var c=Math.cos(a);a=Math.sin(a);this.set(c,-a,0,0,a,c,0,0,0,0,1,0,0,0,0,1);return this},setRotAxis:function(a,c){var e=Math.cos(c),g=Math.sin(c),i=1-e,j=a.x,b=a.y,s=a.z,n=i*j,l=i*b;this.set(n*j+e,n*b-g*s,n*s+g*b,0,n*b+g*s,l*b+e,l*s-g*j,0,n*s-g*b,l*s+g*j,i*s*s+e,0,0,0,0,1);return this},toString:function(){return"| "+this.n11+" "+this.n12+" "+this.n13+" "+this.n14+" |\n| "+this.n21+" "+this.n22+" "+this.n23+" "+this.n24+" |\n| "+this.n31+ -" "+this.n32+" "+this.n33+" "+this.n34+" |\n| "+this.n41+" "+this.n42+" "+this.n43+" "+this.n44+" |"}};THREE.Matrix4.translationMatrix=function(a,c,e){var g=new THREE.Matrix4;g.setTranslation(a,c,e);return g};THREE.Matrix4.scaleMatrix=function(a,c,e){var g=new THREE.Matrix4;g.setScale(a,c,e);return g};THREE.Matrix4.rotationXMatrix=function(a){var c=new THREE.Matrix4;c.setRotX(a);return c};THREE.Matrix4.rotationYMatrix=function(a){var c=new THREE.Matrix4;c.setRotY(a);return c}; -THREE.Matrix4.rotationZMatrix=function(a){var c=new THREE.Matrix4;c.setRotZ(a);return c};THREE.Matrix4.rotationAxisAngleMatrix=function(a,c){var e=new THREE.Matrix4;e.setRotAxis(a,c);return e}; +this.n22;a[6]=this.n32;a[7]=this.n42;a[8]=this.n13;a[9]=this.n23;a[10]=this.n33;a[11]=this.n43;a[12]=this.n14;a[13]=this.n24;a[14]=this.n34;a[15]=this.n44;return a},flattenToArray:function(a){a[0]=this.n11;a[1]=this.n21;a[2]=this.n31;a[3]=this.n41;a[4]=this.n12;a[5]=this.n22;a[6]=this.n32;a[7]=this.n42;a[8]=this.n13;a[9]=this.n23;a[10]=this.n33;a[11]=this.n43;a[12]=this.n14;a[13]=this.n24;a[14]=this.n34;a[15]=this.n44;return a},setTranslation:function(a,c,e){this.set(1,0,0,a,0,1,0,c,0,0,1,e,0,0,0, +1);return this},setScale:function(a,c,e){this.set(a,0,0,0,0,c,0,0,0,0,e,0,0,0,0,1);return this},setRotX:function(a){var c=Math.cos(a);a=Math.sin(a);this.set(1,0,0,0,0,c,-a,0,0,a,c,0,0,0,0,1);return this},setRotY:function(a){var c=Math.cos(a);a=Math.sin(a);this.set(c,0,a,0,0,1,0,0,-a,0,c,0,0,0,0,1);return this},setRotZ:function(a){var c=Math.cos(a);a=Math.sin(a);this.set(c,-a,0,0,a,c,0,0,0,0,1,0,0,0,0,1);return this},setRotAxis:function(a,c){var e=Math.cos(c),g=Math.sin(c),i=1-e,j=a.x,b=a.y,s=a.z, +n=i*j,l=i*b;this.set(n*j+e,n*b-g*s,n*s+g*b,0,n*b+g*s,l*b+e,l*s-g*j,0,n*s-g*b,l*s+g*j,i*s*s+e,0,0,0,0,1);return this},toString:function(){return"| "+this.n11+" "+this.n12+" "+this.n13+" "+this.n14+" |\n| "+this.n21+" "+this.n22+" "+this.n23+" "+this.n24+" |\n| "+this.n31+" "+this.n32+" "+this.n33+" "+this.n34+" |\n| "+this.n41+" "+this.n42+" "+this.n43+" "+this.n44+" |"}};THREE.Matrix4.translationMatrix=function(a,c,e){var g=new THREE.Matrix4;g.setTranslation(a,c,e);return g}; +THREE.Matrix4.scaleMatrix=function(a,c,e){var g=new THREE.Matrix4;g.setScale(a,c,e);return g};THREE.Matrix4.rotationXMatrix=function(a){var c=new THREE.Matrix4;c.setRotX(a);return c};THREE.Matrix4.rotationYMatrix=function(a){var c=new THREE.Matrix4;c.setRotY(a);return c};THREE.Matrix4.rotationZMatrix=function(a){var c=new THREE.Matrix4;c.setRotZ(a);return c};THREE.Matrix4.rotationAxisAngleMatrix=function(a,c){var e=new THREE.Matrix4;e.setRotAxis(a,c);return e}; THREE.Matrix4.makeInvert=function(a){var c=a.n11,e=a.n12,g=a.n13,i=a.n14,j=a.n21,b=a.n22,s=a.n23,n=a.n24,l=a.n31,q=a.n32,z=a.n33,w=a.n34,y=a.n41,F=a.n42,K=a.n43,L=a.n44,d=new THREE.Matrix4;d.n11=s*w*F-n*z*F+n*q*K-b*w*K-s*q*L+b*z*L;d.n12=i*z*F-g*w*F-i*q*K+e*w*K+g*q*L-e*z*L;d.n13=g*n*F-i*s*F+i*b*K-e*n*K-g*b*L+e*s*L;d.n14=i*s*q-g*n*q-i*b*z+e*n*z+g*b*w-e*s*w;d.n21=n*z*y-s*w*y-n*l*K+j*w*K+s*l*L-j*z*L;d.n22=g*w*y-i*z*y+i*l*K-c*w*K-g*l*L+c*z*L;d.n23=i*s*y-g*n*y-i*j*K+c*n*K+g*j*L-c*s*L;d.n24=g*n*l-i*s*l+ i*j*z-c*n*z-g*j*w+c*s*w;d.n31=b*w*y-n*q*y+n*l*F-j*w*F-b*l*L+j*q*L;d.n32=i*q*y-e*w*y-i*l*F+c*w*F+e*l*L-c*q*L;d.n33=g*n*y-i*b*y+i*j*F-c*n*F-e*j*L+c*b*L;d.n34=i*b*l-e*n*l-i*j*q+c*n*q+e*j*w-c*b*w;d.n41=s*q*y-b*z*y-s*l*F+j*z*F+b*l*K-j*q*K;d.n42=e*z*y-g*q*y+g*l*F-c*z*F-e*l*K+c*q*K;d.n43=g*b*y-e*s*y-g*j*F+c*s*F+e*j*K-c*b*K;d.n44=e*s*l-g*b*l+g*j*q-c*s*q-e*j*z+c*b*z;d.multiplyScalar(1/a.determinant());return d}; THREE.Matrix4.makeInvert3x3=function(a){var c=a.flatten();a=a.m33;var e=a.m,g=c[10]*c[5]-c[6]*c[9],i=-c[10]*c[1]+c[2]*c[9],j=c[6]*c[1]-c[2]*c[5],b=-c[10]*c[4]+c[6]*c[8],s=c[10]*c[0]-c[2]*c[8],n=-c[6]*c[0]+c[2]*c[4],l=c[9]*c[4]-c[5]*c[8],q=-c[9]*c[0]+c[1]*c[8],z=c[5]*c[0]-c[1]*c[4];c=c[0]*g+c[1]*b+c[2]*l;if(c==0)throw"matrix not invertible";c=1/c;e[0]=c*g;e[1]=c*i;e[2]=c*j;e[3]=c*b;e[4]=c*s;e[5]=c*n;e[6]=c*l;e[7]=c*q;e[8]=c*z;return a}; @@ -191,15 +191,15 @@ if(m instanceof THREE.Mesh)if(f.wireframe){b.lineWidth(f.wireframe_linewidth);b. b.drawArrays(b.POINTS,0,k.__webGLParticleCount)};this.renderPass=function(d,o,h,f,k,m,t){var p,r,v,x,u;v=0;for(x=f.materials.length;v=0;h--){f=d.__webGLObjects[h].object; o==f&&d.__webGLObjects.splice(h,1)}};this.setupMatrices=function(d,o){d._modelViewMatrix.multiplyToArray(o.matrix,d.matrix,d._modelViewMatrixArray);d._normalMatrix=THREE.Matrix4.makeInvert3x3(d._modelViewMatrix).transposeIntoArray(d._normalMatrixArray)};this.loadMatrices=function(d,o){b.uniformMatrix4fv(d.uniforms.viewMatrix,false,w);b.uniformMatrix4fv(d.uniforms.projectionMatrix,false,z);b.uniformMatrix4fv(d.uniforms.modelViewMatrix,false,o._modelViewMatrixArray);b.uniformMatrix3fv(d.uniforms.normalMatrix, diff --git a/build/ThreeExtras.js b/build/ThreeExtras.js index b834ff95..578d1bc0 100644 --- a/build/ThreeExtras.js +++ b/build/ThreeExtras.js @@ -32,10 +32,10 @@ d[15]=this.n44;return this},multiplySelf:function(a){var c=this.n11,d=this.n12,e w+m*x+k*u;this.n23=g*A+b*C+m*F+k*E;this.n24=g*D+b*I+m*S+k*a;this.n31=n*f+o*p+y*j+v*l;this.n32=n*t+o*w+y*x+v*u;this.n33=n*A+o*C+y*F+v*E;this.n34=n*D+o*I+y*S+v*a;this.n41=q*f+z*p+B*j+H*l;this.n42=q*t+z*w+B*x+H*u;this.n43=q*A+z*C+B*F+H*E;this.n44=q*D+z*I+B*S+H*a;return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=a;this.n42*=a;this.n43*=a;this.n44*=a;return this}, determinant:function(){var a=this.n11,c=this.n12,d=this.n13,e=this.n14,h=this.n21,g=this.n22,b=this.n23,m=this.n24,k=this.n31,n=this.n32,o=this.n33,y=this.n34,v=this.n41,q=this.n42,z=this.n43,B=this.n44;return e*b*n*v-d*m*n*v-e*g*o*v+c*m*o*v+d*g*y*v-c*b*y*v-e*b*k*q+d*m*k*q+e*h*o*q-a*m*o*q-d*h*y*q+a*b*y*q+e*g*k*z-c*m*k*z-e*h*n*z+a*m*n*z+c*h*y*z-a*g*y*z-d*g*k*B+c*b*k*B+d*h*n*B-a*b*n*B-c*h*o*B+a*g*o*B},transpose:function(){function a(c,d,e){var h=c[d];c[d]=c[e];c[e]=h}a(this,"n21","n12");a(this,"n31", "n13");a(this,"n32","n23");a(this,"n41","n14");a(this,"n42","n24");a(this,"n43","n34");return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=this.n44;return a},flatten:function(){var a=this.flat;a[0]=this.n11;a[1]=this.n21;a[2]=this.n31;a[3]=this.n41;a[4]=this.n12;a[5]= -this.n22;a[6]=this.n32;a[7]=this.n42;a[8]=this.n13;a[9]=this.n23;a[10]=this.n33;a[11]=this.n43;a[12]=this.n14;a[13]=this.n24;a[14]=this.n34;a[15]=this.n44;return a},setTranslation:function(a,c,d){this.set(1,0,0,a,0,1,0,c,0,0,1,d,0,0,0,1);return this},setScale:function(a,c,d){this.set(a,0,0,0,0,c,0,0,0,0,d,0,0,0,0,1);return this},setRotX:function(a){var c=Math.cos(a);a=Math.sin(a);this.set(1,0,0,0,0,c,-a,0,0,a,c,0,0,0,0,1);return this},setRotY:function(a){var c=Math.cos(a);a=Math.sin(a);this.set(c, -0,a,0,0,1,0,0,-a,0,c,0,0,0,0,1);return this},setRotZ:function(a){var c=Math.cos(a);a=Math.sin(a);this.set(c,-a,0,0,a,c,0,0,0,0,1,0,0,0,0,1);return this},setRotAxis:function(a,c){var d=Math.cos(c),e=Math.sin(c),h=1-d,g=a.x,b=a.y,m=a.z,k=h*g,n=h*b;this.set(k*g+d,k*b-e*m,k*m+e*b,0,k*b+e*m,n*b+d,n*m-e*g,0,k*m-e*b,n*m+e*g,h*m*m+d,0,0,0,0,1);return this},toString:function(){return"| "+this.n11+" "+this.n12+" "+this.n13+" "+this.n14+" |\n| "+this.n21+" "+this.n22+" "+this.n23+" "+this.n24+" |\n| "+this.n31+ -" "+this.n32+" "+this.n33+" "+this.n34+" |\n| "+this.n41+" "+this.n42+" "+this.n43+" "+this.n44+" |"}};THREE.Matrix4.translationMatrix=function(a,c,d){var e=new THREE.Matrix4;e.setTranslation(a,c,d);return e};THREE.Matrix4.scaleMatrix=function(a,c,d){var e=new THREE.Matrix4;e.setScale(a,c,d);return e};THREE.Matrix4.rotationXMatrix=function(a){var c=new THREE.Matrix4;c.setRotX(a);return c};THREE.Matrix4.rotationYMatrix=function(a){var c=new THREE.Matrix4;c.setRotY(a);return c}; -THREE.Matrix4.rotationZMatrix=function(a){var c=new THREE.Matrix4;c.setRotZ(a);return c};THREE.Matrix4.rotationAxisAngleMatrix=function(a,c){var d=new THREE.Matrix4;d.setRotAxis(a,c);return d}; +this.n22;a[6]=this.n32;a[7]=this.n42;a[8]=this.n13;a[9]=this.n23;a[10]=this.n33;a[11]=this.n43;a[12]=this.n14;a[13]=this.n24;a[14]=this.n34;a[15]=this.n44;return a},flattenToArray:function(a){a[0]=this.n11;a[1]=this.n21;a[2]=this.n31;a[3]=this.n41;a[4]=this.n12;a[5]=this.n22;a[6]=this.n32;a[7]=this.n42;a[8]=this.n13;a[9]=this.n23;a[10]=this.n33;a[11]=this.n43;a[12]=this.n14;a[13]=this.n24;a[14]=this.n34;a[15]=this.n44;return a},setTranslation:function(a,c,d){this.set(1,0,0,a,0,1,0,c,0,0,1,d,0,0,0, +1);return this},setScale:function(a,c,d){this.set(a,0,0,0,0,c,0,0,0,0,d,0,0,0,0,1);return this},setRotX:function(a){var c=Math.cos(a);a=Math.sin(a);this.set(1,0,0,0,0,c,-a,0,0,a,c,0,0,0,0,1);return this},setRotY:function(a){var c=Math.cos(a);a=Math.sin(a);this.set(c,0,a,0,0,1,0,0,-a,0,c,0,0,0,0,1);return this},setRotZ:function(a){var c=Math.cos(a);a=Math.sin(a);this.set(c,-a,0,0,a,c,0,0,0,0,1,0,0,0,0,1);return this},setRotAxis:function(a,c){var d=Math.cos(c),e=Math.sin(c),h=1-d,g=a.x,b=a.y,m=a.z, +k=h*g,n=h*b;this.set(k*g+d,k*b-e*m,k*m+e*b,0,k*b+e*m,n*b+d,n*m-e*g,0,k*m-e*b,n*m+e*g,h*m*m+d,0,0,0,0,1);return this},toString:function(){return"| "+this.n11+" "+this.n12+" "+this.n13+" "+this.n14+" |\n| "+this.n21+" "+this.n22+" "+this.n23+" "+this.n24+" |\n| "+this.n31+" "+this.n32+" "+this.n33+" "+this.n34+" |\n| "+this.n41+" "+this.n42+" "+this.n43+" "+this.n44+" |"}};THREE.Matrix4.translationMatrix=function(a,c,d){var e=new THREE.Matrix4;e.setTranslation(a,c,d);return e}; +THREE.Matrix4.scaleMatrix=function(a,c,d){var e=new THREE.Matrix4;e.setScale(a,c,d);return e};THREE.Matrix4.rotationXMatrix=function(a){var c=new THREE.Matrix4;c.setRotX(a);return c};THREE.Matrix4.rotationYMatrix=function(a){var c=new THREE.Matrix4;c.setRotY(a);return c};THREE.Matrix4.rotationZMatrix=function(a){var c=new THREE.Matrix4;c.setRotZ(a);return c};THREE.Matrix4.rotationAxisAngleMatrix=function(a,c){var d=new THREE.Matrix4;d.setRotAxis(a,c);return d}; THREE.Matrix4.makeInvert=function(a){var c=a.n11,d=a.n12,e=a.n13,h=a.n14,g=a.n21,b=a.n22,m=a.n23,k=a.n24,n=a.n31,o=a.n32,y=a.n33,v=a.n34,q=a.n41,z=a.n42,B=a.n43,H=a.n44,f=new THREE.Matrix4;f.n11=m*v*z-k*y*z+k*o*B-b*v*B-m*o*H+b*y*H;f.n12=h*y*z-e*v*z-h*o*B+d*v*B+e*o*H-d*y*H;f.n13=e*k*z-h*m*z+h*b*B-d*k*B-e*b*H+d*m*H;f.n14=h*m*o-e*k*o-h*b*y+d*k*y+e*b*v-d*m*v;f.n21=k*y*q-m*v*q-k*n*B+g*v*B+m*n*H-g*y*H;f.n22=e*v*q-h*y*q+h*n*B-c*v*B-e*n*H+c*y*H;f.n23=h*m*q-e*k*q-h*g*B+c*k*B+e*g*H-c*m*H;f.n24=e*k*n-h*m*n+ h*g*y-c*k*y-e*g*v+c*m*v;f.n31=b*v*q-k*o*q+k*n*z-g*v*z-b*n*H+g*o*H;f.n32=h*o*q-d*v*q-h*n*z+c*v*z+d*n*H-c*o*H;f.n33=e*k*q-h*b*q+h*g*z-c*k*z-d*g*H+c*b*H;f.n34=h*b*n-d*k*n-h*g*o+c*k*o+d*g*v-c*b*v;f.n41=m*o*q-b*y*q-m*n*z+g*y*z+b*n*B-g*o*B;f.n42=d*y*q-e*o*q+e*n*z-c*y*z-d*n*B+c*o*B;f.n43=e*b*q-d*m*q-e*g*z+c*m*z+d*g*B-c*b*B;f.n44=d*m*n-e*b*n+e*g*o-c*m*o-d*g*y+c*b*y;f.multiplyScalar(1/a.determinant());return f}; THREE.Matrix4.makeInvert3x3=function(a){var c=a.flatten();a=a.m33;var d=a.m,e=c[10]*c[5]-c[6]*c[9],h=-c[10]*c[1]+c[2]*c[9],g=c[6]*c[1]-c[2]*c[5],b=-c[10]*c[4]+c[6]*c[8],m=c[10]*c[0]-c[2]*c[8],k=-c[6]*c[0]+c[2]*c[4],n=c[9]*c[4]-c[5]*c[8],o=-c[9]*c[0]+c[1]*c[8],y=c[5]*c[0]-c[1]*c[4];c=c[0]*e+c[1]*b+c[2]*n;if(c==0)throw"matrix not invertible";c=1/c;d[0]=c*e;d[1]=c*h;d[2]=c*g;d[3]=c*b;d[4]=c*m;d[5]=c*k;d[6]=c*n;d[7]=c*o;d[8]=c*y;return a}; @@ -191,15 +191,15 @@ if(w instanceof THREE.Mesh)if(l.wireframe){b.lineWidth(l.wireframe_linewidth);b. b.drawArrays(b.POINTS,0,t.__webGLParticleCount)};this.renderPass=function(f,p,j,l,t,w,x){var u,A,C,F,E;C=0;for(F=l.materials.length;C=0;j--){l=f.__webGLObjects[j].object; p==l&&f.__webGLObjects.splice(j,1)}};this.setupMatrices=function(f,p){f._modelViewMatrix.multiplyToArray(p.matrix,f.matrix,f._modelViewMatrixArray);f._normalMatrix=THREE.Matrix4.makeInvert3x3(f._modelViewMatrix).transposeIntoArray(f._normalMatrixArray)};this.loadMatrices=function(f,p){b.uniformMatrix4fv(f.uniforms.viewMatrix,false,v);b.uniformMatrix4fv(f.uniforms.projectionMatrix,false,y);b.uniformMatrix4fv(f.uniforms.modelViewMatrix,false,p._modelViewMatrixArray);b.uniformMatrix3fv(f.uniforms.normalMatrix, diff --git a/examples/materials_shaders_fresnel.html b/examples/materials_shaders_fresnel.html index 1f721ad2..213cd33e 100644 --- a/examples/materials_shaders_fresnel.html +++ b/examples/materials_shaders_fresnel.html @@ -108,6 +108,8 @@ mesh.position.y = Math.random() * 10000 - 5000; mesh.position.z = Math.random() * 10000 - 5000; mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 4 + 1; + mesh.autoUpdateMatrix = false; + mesh.updateMatrix(); scene.addObject( mesh ); } diff --git a/src/core/Matrix4.js b/src/core/Matrix4.js index 26d7d5ec..e36f499a 100644 --- a/src/core/Matrix4.js +++ b/src/core/Matrix4.js @@ -352,6 +352,32 @@ THREE.Matrix4.prototype = { }, + flattenToArray: function( flat ) { + + flat[ 0 ] = this.n11; + flat[ 1 ] = this.n21; + flat[ 2 ] = this.n31; + flat[ 3 ] = this.n41; + + flat[ 4 ] = this.n12; + flat[ 5 ] = this.n22; + flat[ 6 ] = this.n32; + flat[ 7 ] = this.n42; + + flat[ 8 ] = this.n13; + flat[ 9 ] = this.n23; + flat[ 10 ] = this.n33; + flat[ 11 ] = this.n43; + + flat[ 12 ] = this.n14; + flat[ 13 ] = this.n24; + flat[ 14 ] = this.n34; + flat[ 15 ] = this.n44; + + return flat; + + }, + setTranslation: function( x, y, z ) { this.set( 1, 0, 0, x, diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index cb10059c..70441da6 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -1427,8 +1427,8 @@ THREE.WebGLRenderer = function ( parameters ) { camera.autoUpdateMatrix && camera.updateMatrix(); - _viewMatrixArray.set( camera.matrix.flatten() ); - _projectionMatrixArray.set( camera.projectionMatrix.flatten() ); + camera.matrix.flattenToArray( _viewMatrixArray ); + camera.projectionMatrix.flattenToArray( _projectionMatrixArray ); _projScreenMatrix.multiply( camera.projectionMatrix, camera.matrix ); computeFrustum( _projScreenMatrix ); @@ -1457,7 +1457,7 @@ THREE.WebGLRenderer = function ( parameters ) { if( object.autoUpdateMatrix ) { object.updateMatrix(); - object._objectMatrixArray.set( object.matrix.flatten() ); + object.matrix.flattenToArray( object._objectMatrixArray ); } @@ -1484,7 +1484,7 @@ THREE.WebGLRenderer = function ( parameters ) { if( object.autoUpdateMatrix ) { object.updateMatrix(); - object._objectMatrixArray.set( object.matrix.flatten() ); + object.matrix.flattenToArray( object._objectMatrixArray ); } @@ -1634,10 +1634,10 @@ THREE.WebGLRenderer = function ( parameters ) { object._modelViewMatrix = new THREE.Matrix4(); object._normalMatrixArray = new Float32Array( 9 ); - object._modelViewMatrixArray = new Float32Array( 16 ); + object._modelViewMatrixArray = new Float32Array( 16 ); object._objectMatrixArray = new Float32Array( 16 ); - - object._objectMatrixArray.set( object.matrix.flatten() ); + + object.matrix.flattenToArray( object._objectMatrixArray ); }