diff --git a/build/ThreeExtras.js b/build/ThreeExtras.js index 39a58d88..b55a915e 100644 --- a/build/ThreeExtras.js +++ b/build/ThreeExtras.js @@ -12,47 +12,47 @@ THREE.Vector4=function(a,b,d,e){this.x=a||0;this.y=b||0;this.z=d||0;this.w=e||1} THREE.Vector4.prototype={set:function(a,b,d,e){this.x=a;this.y=b;this.z=d;this.w=e;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w||1;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w; return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=a;this.w/=a;return this},lerpSelf:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},toString:function(){return"THREE.Vector4 ("+this.x+", "+this.y+", "+this.z+", "+this.w+")"}}; THREE.Ray=function(a,b){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3}; -THREE.Ray.prototype={intersectScene:function(a){var b,d,e=a.objects,f=[];a=0;for(b=e.length;a0&&H>0&&m+H<1}var d,e,f,h,j,c,i,k,r,z, -n,u=a.geometry,x=u.vertices,y=[];d=0;for(e=u.faces.length;di?e:i;f=f>k? -f:k}a()};this.add3Points=function(i,k,r,z,n,u){if(c){c=false;b=ir?i>n?i:n:r>n?r:n;f=k>z?k>u?k:u:z>u?z:u}else{b=ir?i>n?i>e?i:e:n>e?n:e:r>n?r>e?r:e:n>e?n:e;f=k>z?k>u?k>f?k:f:u>f?u:f:z>u?z>f?z:f:u>f?u:f}a()};this.addRectangle=function(i){if(c){c=false;b=i.getLeft();d=i.getTop();e=i.getRight();f=i.getBottom()}else{b=bi.getRight()?e:i.getRight();f=f>i.getBottom()?f:i.getBottom()}a()};this.inflate=function(i){b-=i;d-=i;e+=i;f+=i;a()};this.minSelf=function(i){b=b>i.getLeft()?b:i.getLeft();d=d>i.getTop()?d:i.getTop();e=e=0&&Math.min(f,i.getBottom())-Math.max(d,i.getTop())>=0};this.empty=function(){c=true;f=e=d=b=0;a()};this.isEmpty=function(){return c};this.toString= -function(){return"THREE.Rectangle ( left: "+b+", right: "+e+", top: "+d+", bottom: "+f+", width: "+h+", height: "+j+" )"}};THREE.Matrix3=function(){this.m=[]};THREE.Matrix3.prototype={transpose:function(){var a,b=this.m;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this}}; -THREE.Matrix4=function(a,b,d,e,f,h,j,c,i,k,r,z,n,u,x,y){this.n11=a||1;this.n12=b||0;this.n13=d||0;this.n14=e||0;this.n21=f||0;this.n22=h||1;this.n23=j||0;this.n24=c||0;this.n31=i||0;this.n32=k||0;this.n33=r||1;this.n34=z||0;this.n41=n||0;this.n42=u||0;this.n43=x||0;this.n44=y||1;this.flat=Array(16);this.m33=new THREE.Matrix3}; -THREE.Matrix4.prototype={identity:function(){this.n11=1;this.n21=this.n14=this.n13=this.n12=0;this.n22=1;this.n32=this.n31=this.n24=this.n23=0;this.n33=1;this.n43=this.n42=this.n41=this.n34=0;this.n44=1;return this},set:function(a,b,d,e,f,h,j,c,i,k,r,z,n,u,x,y){this.n11=a;this.n12=b;this.n13=d;this.n14=e;this.n21=f;this.n22=h;this.n23=j;this.n24=c;this.n31=i;this.n32=k;this.n33=r;this.n34=z;this.n41=n;this.n42=u;this.n43=x;this.n44=y;return this},copy:function(a){this.n11=a.n11;this.n12=a.n12;this.n13= -a.n13;this.n14=a.n14;this.n21=a.n21;this.n22=a.n22;this.n23=a.n23;this.n24=a.n24;this.n31=a.n31;this.n32=a.n32;this.n33=a.n33;this.n34=a.n34;this.n41=a.n41;this.n42=a.n42;this.n43=a.n43;this.n44=a.n44;return this},lookAt:function(a,b,d){var e=THREE.Matrix4.__tmpVec1,f=THREE.Matrix4.__tmpVec2,h=THREE.Matrix4.__tmpVec3;h.sub(a,b).normalize();e.cross(d,h).normalize();f.cross(h,e).normalize();this.n11=e.x;this.n12=e.y;this.n13=e.z;this.n14=-e.dot(a);this.n21=f.x;this.n22=f.y;this.n23=f.z;this.n24=-f.dot(a); -this.n31=h.x;this.n32=h.y;this.n33=h.z;this.n34=-h.dot(a);this.n43=this.n42=this.n41=0;this.n44=1;return this},multiplyVector3:function(a){var b=a.x,d=a.y,e=a.z,f=1/(this.n41*b+this.n42*d+this.n43*e+this.n44);a.x=(this.n11*b+this.n12*d+this.n13*e+this.n14)*f;a.y=(this.n21*b+this.n22*d+this.n23*e+this.n24)*f;a.z=(this.n31*b+this.n32*d+this.n33*e+this.n34)*f;return a},multiplyVector4:function(a){var b=a.x,d=a.y,e=a.z,f=a.w;a.x=this.n11*b+this.n12*d+this.n13*e+this.n14*f;a.y=this.n21*b+this.n22*d+this.n23* -e+this.n24*f;a.z=this.n31*b+this.n32*d+this.n33*e+this.n34*f;a.w=this.n41*b+this.n42*d+this.n43*e+this.n44*f;return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var d=a.n11,e=a.n12,f=a.n13,h=a.n14,j=a.n21,c=a.n22,i=a.n23,k=a.n24,r=a.n31, -z=a.n32,n=a.n33,u=a.n34,x=a.n41,y=a.n42,H=a.n43,p=a.n44,I=b.n11,l=b.n12,g=b.n13,m=b.n14,w=b.n21,o=b.n22,v=b.n23,J=b.n24,s=b.n31,A=b.n32,C=b.n33,B=b.n34,t=b.n41,L=b.n42,F=b.n43,R=b.n44;this.n11=d*I+e*w+f*s+h*t;this.n12=d*l+e*o+f*A+h*L;this.n13=d*g+e*v+f*C+h*F;this.n14=d*m+e*J+f*B+h*R;this.n21=j*I+c*w+i*s+k*t;this.n22=j*l+c*o+i*A+k*L;this.n23=j*g+c*v+i*C+k*F;this.n24=j*m+c*J+i*B+k*R;this.n31=r*I+z*w+n*s+u*t;this.n32=r*l+z*o+n*A+u*L;this.n33=r*g+z*v+n*C+u*F;this.n34=r*m+z*J+n*B+u*R;this.n41=x*I+y*w+ -H*s+p*t;this.n42=x*l+y*o+H*A+p*L;this.n43=x*g+y*v+H*C+p*F;this.n44=x*m+y*J+H*B+p*R;return this},multiplySelf:function(a){var b=this.n11,d=this.n12,e=this.n13,f=this.n14,h=this.n21,j=this.n22,c=this.n23,i=this.n24,k=this.n31,r=this.n32,z=this.n33,n=this.n34,u=this.n41,x=this.n42,y=this.n43,H=this.n44,p=a.n11,I=a.n21,l=a.n31,g=a.n41,m=a.n12,w=a.n22,o=a.n32,v=a.n42,J=a.n13,s=a.n23,A=a.n33,C=a.n43,B=a.n14,t=a.n24,L=a.n34;a=a.n44;this.n11=b*p+d*I+e*l+f*g;this.n12=b*m+d*w+e*o+f*v;this.n13=b*J+d*s+e*A+f* -C;this.n14=b*B+d*t+e*L+f*a;this.n21=h*p+j*I+c*l+i*g;this.n22=h*m+j*w+c*o+i*v;this.n23=h*J+j*s+c*A+i*C;this.n24=h*B+j*t+c*L+i*a;this.n31=k*p+r*I+z*l+n*g;this.n32=k*m+r*w+z*o+n*v;this.n33=k*J+r*s+z*A+n*C;this.n34=k*B+r*t+z*L+n*a;this.n41=u*p+x*I+y*l+H*g;this.n42=u*m+x*w+y*o+H*v;this.n43=u*J+x*s+y*A+H*C;this.n44=u*B+x*t+y*L+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,b=this.n12,d=this.n13,e=this.n14,f=this.n21,h=this.n22,j=this.n23,c=this.n24,i=this.n31,k=this.n32,r=this.n33,z=this.n34,n=this.n41,u=this.n42,x=this.n43,y=this.n44;return e*j*k*n-d*c*k*n-e*h*r*n+b*c*r*n+d*h*z*n-b*j*z*n-e*j*i*u+d*c*i*u+e*f*r*u-a*c*r*u-d*f*z*u+a*j*z*u+e*h*i*x-b*c*i*x-e*f*k*x+a*c*k*x+b*f*z*x-a*h*z*x-d*h*i*y+b*j*i*y+d*f*k*y-a*j*k*y-b*f*r*y+a*h*r*y},transpose:function(){function a(b,d, +THREE.Ray.prototype={intersectScene:function(a){var b,d,e=a.objects,f=[];a=0;for(b=e.length;a0&&H>0&&n+H<1}var d,e,f,g,k,c,j,l,t,D, +o,u=a.geometry,w=u.vertices,C=[];d=0;for(e=u.faces.length;dj?e:j;f=f>l? +f:l}a()};this.add3Points=function(j,l,t,D,o,u){if(c){c=false;b=jt?j>o?j:o:t>o?t:o;f=l>D?l>u?l:u:D>u?D:u}else{b=jt?j>o?j>e?j:e:o>e?o:e:t>o?t>e?t:e:o>e?o:e;f=l>D?l>u?l>f?l:f:u>f?u:f:D>u?D>f?D:f:u>f?u:f}a()};this.addRectangle=function(j){if(c){c=false;b=j.getLeft();d=j.getTop();e=j.getRight();f=j.getBottom()}else{b=bj.getRight()?e:j.getRight();f=f>j.getBottom()?f:j.getBottom()}a()};this.inflate=function(j){b-=j;d-=j;e+=j;f+=j;a()};this.minSelf=function(j){b=b>j.getLeft()?b:j.getLeft();d=d>j.getTop()?d:j.getTop();e=e=0&&Math.min(f,j.getBottom())-Math.max(d,j.getTop())>=0};this.empty=function(){c=true;f=e=d=b=0;a()};this.isEmpty=function(){return c};this.toString= +function(){return"THREE.Rectangle ( left: "+b+", right: "+e+", top: "+d+", bottom: "+f+", width: "+g+", height: "+k+" )"}};THREE.Matrix3=function(){this.m=[]};THREE.Matrix3.prototype={transpose:function(){var a,b=this.m;a=b[1];b[1]=b[3];b[3]=a;a=b[2];b[2]=b[6];b[6]=a;a=b[5];b[5]=b[7];b[7]=a;return this}}; +THREE.Matrix4=function(a,b,d,e,f,g,k,c,j,l,t,D,o,u,w,C){this.n11=a||1;this.n12=b||0;this.n13=d||0;this.n14=e||0;this.n21=f||0;this.n22=g||1;this.n23=k||0;this.n24=c||0;this.n31=j||0;this.n32=l||0;this.n33=t||1;this.n34=D||0;this.n41=o||0;this.n42=u||0;this.n43=w||0;this.n44=C||1;this.flat=Array(16);this.m33=new THREE.Matrix3}; +THREE.Matrix4.prototype={identity:function(){this.n11=1;this.n21=this.n14=this.n13=this.n12=0;this.n22=1;this.n32=this.n31=this.n24=this.n23=0;this.n33=1;this.n43=this.n42=this.n41=this.n34=0;this.n44=1;return this},set:function(a,b,d,e,f,g,k,c,j,l,t,D,o,u,w,C){this.n11=a;this.n12=b;this.n13=d;this.n14=e;this.n21=f;this.n22=g;this.n23=k;this.n24=c;this.n31=j;this.n32=l;this.n33=t;this.n34=D;this.n41=o;this.n42=u;this.n43=w;this.n44=C;return this},copy:function(a){this.n11=a.n11;this.n12=a.n12;this.n13= +a.n13;this.n14=a.n14;this.n21=a.n21;this.n22=a.n22;this.n23=a.n23;this.n24=a.n24;this.n31=a.n31;this.n32=a.n32;this.n33=a.n33;this.n34=a.n34;this.n41=a.n41;this.n42=a.n42;this.n43=a.n43;this.n44=a.n44;return this},lookAt:function(a,b,d){var e=THREE.Matrix4.__tmpVec1,f=THREE.Matrix4.__tmpVec2,g=THREE.Matrix4.__tmpVec3;g.sub(a,b).normalize();e.cross(d,g).normalize();f.cross(g,e).normalize();this.n11=e.x;this.n12=e.y;this.n13=e.z;this.n14=-e.dot(a);this.n21=f.x;this.n22=f.y;this.n23=f.z;this.n24=-f.dot(a); +this.n31=g.x;this.n32=g.y;this.n33=g.z;this.n34=-g.dot(a);this.n43=this.n42=this.n41=0;this.n44=1;return this},multiplyVector3:function(a){var b=a.x,d=a.y,e=a.z,f=1/(this.n41*b+this.n42*d+this.n43*e+this.n44);a.x=(this.n11*b+this.n12*d+this.n13*e+this.n14)*f;a.y=(this.n21*b+this.n22*d+this.n23*e+this.n24)*f;a.z=(this.n31*b+this.n32*d+this.n33*e+this.n34)*f;return a},multiplyVector4:function(a){var b=a.x,d=a.y,e=a.z,f=a.w;a.x=this.n11*b+this.n12*d+this.n13*e+this.n14*f;a.y=this.n21*b+this.n22*d+this.n23* +e+this.n24*f;a.z=this.n31*b+this.n32*d+this.n33*e+this.n34*f;a.w=this.n41*b+this.n42*d+this.n43*e+this.n44*f;return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var d=a.n11,e=a.n12,f=a.n13,g=a.n14,k=a.n21,c=a.n22,j=a.n23,l=a.n24,t=a.n31, +D=a.n32,o=a.n33,u=a.n34,w=a.n41,C=a.n42,H=a.n43,v=a.n44,I=b.n11,m=b.n12,h=b.n13,n=b.n14,B=b.n21,q=b.n22,z=b.n23,M=b.n24,p=b.n31,A=b.n32,F=b.n33,E=b.n34,y=b.n41,O=b.n42,K=b.n43,U=b.n44;this.n11=d*I+e*B+f*p+g*y;this.n12=d*m+e*q+f*A+g*O;this.n13=d*h+e*z+f*F+g*K;this.n14=d*n+e*M+f*E+g*U;this.n21=k*I+c*B+j*p+l*y;this.n22=k*m+c*q+j*A+l*O;this.n23=k*h+c*z+j*F+l*K;this.n24=k*n+c*M+j*E+l*U;this.n31=t*I+D*B+o*p+u*y;this.n32=t*m+D*q+o*A+u*O;this.n33=t*h+D*z+o*F+u*K;this.n34=t*n+D*M+o*E+u*U;this.n41=w*I+C*B+ +H*p+v*y;this.n42=w*m+C*q+H*A+v*O;this.n43=w*h+C*z+H*F+v*K;this.n44=w*n+C*M+H*E+v*U;return this},multiplySelf:function(a){var b=this.n11,d=this.n12,e=this.n13,f=this.n14,g=this.n21,k=this.n22,c=this.n23,j=this.n24,l=this.n31,t=this.n32,D=this.n33,o=this.n34,u=this.n41,w=this.n42,C=this.n43,H=this.n44,v=a.n11,I=a.n21,m=a.n31,h=a.n41,n=a.n12,B=a.n22,q=a.n32,z=a.n42,M=a.n13,p=a.n23,A=a.n33,F=a.n43,E=a.n14,y=a.n24,O=a.n34;a=a.n44;this.n11=b*v+d*I+e*m+f*h;this.n12=b*n+d*B+e*q+f*z;this.n13=b*M+d*p+e*A+f* +F;this.n14=b*E+d*y+e*O+f*a;this.n21=g*v+k*I+c*m+j*h;this.n22=g*n+k*B+c*q+j*z;this.n23=g*M+k*p+c*A+j*F;this.n24=g*E+k*y+c*O+j*a;this.n31=l*v+t*I+D*m+o*h;this.n32=l*n+t*B+D*q+o*z;this.n33=l*M+t*p+D*A+o*F;this.n34=l*E+t*y+D*O+o*a;this.n41=u*v+w*I+C*m+H*h;this.n42=u*n+w*B+C*q+H*z;this.n43=u*M+w*p+C*A+H*F;this.n44=u*E+w*y+C*O+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,b=this.n12,d=this.n13,e=this.n14,f=this.n21,g=this.n22,k=this.n23,c=this.n24,j=this.n31,l=this.n32,t=this.n33,D=this.n34,o=this.n41,u=this.n42,w=this.n43,C=this.n44;return e*k*l*o-d*c*l*o-e*g*t*o+b*c*t*o+d*g*D*o-b*k*D*o-e*k*j*u+d*c*j*u+e*f*t*u-a*c*t*u-d*f*D*u+a*k*D*u+e*g*j*w-b*c*j*w-e*f*l*w+a*c*l*w+b*f*D*w-a*g*D*w-d*g*j*C+b*k*j*C+d*f*l*C-a*k*l*C-b*f*t*C+a*g*t*C},transpose:function(){function a(b,d, e){var f=b[d];b[d]=b[e];b[e]=f}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,b,d){this.set(1,0,0,a,0,1,0,b,0,0,1,d,0,0,0,1);return this},setScale:function(a,b,d){this.set(a,0,0,0,0,b,0,0,0,0,d,0,0,0,0,1);return this},setRotX:function(a){var b=Math.cos(a);a=Math.sin(a);this.set(1,0,0,0,0,b,-a,0,0,a,b,0,0,0,0,1);return this},setRotY:function(a){var b= -Math.cos(a);a=Math.sin(a);this.set(b,0,a,0,0,1,0,0,-a,0,b,0,0,0,0,1);return this},setRotZ:function(a){var b=Math.cos(a);a=Math.sin(a);this.set(b,-a,0,0,a,b,0,0,0,0,1,0,0,0,0,1);return this},setRotAxis:function(a,b){var d=Math.cos(b),e=Math.sin(b),f=1-d,h=a.x,j=a.y,c=a.z,i=f*h,k=f*j;this.set(i*h+d,i*j-e*c,i*c+e*j,0,i*j+e*c,k*j+d,k*c-e*h,0,i*c-e*j,k*c+e*h,f*c*c+d,0,0,0,0,1);return this},toString:function(){return"| "+this.n11+" "+this.n12+" "+this.n13+" "+this.n14+" |\n| "+this.n21+" "+this.n22+" "+ +Math.cos(a);a=Math.sin(a);this.set(b,0,a,0,0,1,0,0,-a,0,b,0,0,0,0,1);return this},setRotZ:function(a){var b=Math.cos(a);a=Math.sin(a);this.set(b,-a,0,0,a,b,0,0,0,0,1,0,0,0,0,1);return this},setRotAxis:function(a,b){var d=Math.cos(b),e=Math.sin(b),f=1-d,g=a.x,k=a.y,c=a.z,j=f*g,l=f*k;this.set(j*g+d,j*k-e*c,j*c+e*k,0,j*k+e*c,l*k+d,l*c-e*g,0,j*c-e*k,l*c+e*g,f*c*c+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,b,d){var e=new THREE.Matrix4;e.setTranslation(a,b,d);return e};THREE.Matrix4.scaleMatrix=function(a,b,d){var e=new THREE.Matrix4;e.setScale(a,b,d);return e};THREE.Matrix4.rotationXMatrix=function(a){var b=new THREE.Matrix4;b.setRotX(a);return b}; THREE.Matrix4.rotationYMatrix=function(a){var b=new THREE.Matrix4;b.setRotY(a);return b};THREE.Matrix4.rotationZMatrix=function(a){var b=new THREE.Matrix4;b.setRotZ(a);return b};THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var d=new THREE.Matrix4;d.setRotAxis(a,b);return d}; -THREE.Matrix4.makeInvert=function(a){var b=a.n11,d=a.n12,e=a.n13,f=a.n14,h=a.n21,j=a.n22,c=a.n23,i=a.n24,k=a.n31,r=a.n32,z=a.n33,n=a.n34,u=a.n41,x=a.n42,y=a.n43,H=a.n44,p=new THREE.Matrix4;p.n11=c*n*x-i*z*x+i*r*y-j*n*y-c*r*H+j*z*H;p.n12=f*z*x-e*n*x-f*r*y+d*n*y+e*r*H-d*z*H;p.n13=e*i*x-f*c*x+f*j*y-d*i*y-e*j*H+d*c*H;p.n14=f*c*r-e*i*r-f*j*z+d*i*z+e*j*n-d*c*n;p.n21=i*z*u-c*n*u-i*k*y+h*n*y+c*k*H-h*z*H;p.n22=e*n*u-f*z*u+f*k*y-b*n*y-e*k*H+b*z*H;p.n23=f*c*u-e*i*u-f*h*y+b*i*y+e*h*H-b*c*H;p.n24=e*i*k-f*c*k+ -f*h*z-b*i*z-e*h*n+b*c*n;p.n31=j*n*u-i*r*u+i*k*x-h*n*x-j*k*H+h*r*H;p.n32=f*r*u-d*n*u-f*k*x+b*n*x+d*k*H-b*r*H;p.n33=e*i*u-f*j*u+f*h*x-b*i*x-d*h*H+b*j*H;p.n34=f*j*k-d*i*k-f*h*r+b*i*r+d*h*n-b*j*n;p.n41=c*r*u-j*z*u-c*k*x+h*z*x+j*k*y-h*r*y;p.n42=d*z*u-e*r*u+e*k*x-b*z*x-d*k*y+b*r*y;p.n43=e*j*u-d*c*u-e*h*x+b*c*x+d*h*y-b*j*y;p.n44=d*c*k-e*j*k+e*h*r-b*c*r-d*h*z+b*j*z;p.multiplyScalar(1/a.determinant());return p}; -THREE.Matrix4.makeInvert3x3=function(a){var b=a.flatten();a=a.m33;var d=a.m,e=b[10]*b[5]-b[6]*b[9],f=-b[10]*b[1]+b[2]*b[9],h=b[6]*b[1]-b[2]*b[5],j=-b[10]*b[4]+b[6]*b[8],c=b[10]*b[0]-b[2]*b[8],i=-b[6]*b[0]+b[2]*b[4],k=b[9]*b[4]-b[5]*b[8],r=-b[9]*b[0]+b[1]*b[8],z=b[5]*b[0]-b[1]*b[4];b=b[0]*e+b[1]*j+b[2]*k;if(b==0)throw"matrix not invertible";b=1/b;d[0]=b*e;d[1]=b*f;d[2]=b*h;d[3]=b*j;d[4]=b*c;d[5]=b*i;d[6]=b*k;d[7]=b*r;d[8]=b*z;return a}; -THREE.Matrix4.makeFrustum=function(a,b,d,e,f,h){var j,c,i;j=new THREE.Matrix4;c=2*f/(b-a);i=2*f/(e-d);a=(b+a)/(b-a);d=(e+d)/(e-d);e=-(h+f)/(h-f);f=-2*h*f/(h-f);j.n11=c;j.n12=0;j.n13=a;j.n14=0;j.n21=0;j.n22=i;j.n23=d;j.n24=0;j.n31=0;j.n32=0;j.n33=e;j.n34=f;j.n41=0;j.n42=0;j.n43=-1;j.n44=0;return j};THREE.Matrix4.makePerspective=function(a,b,d,e){var f;a=d*Math.tan(a*Math.PI/360);f=-a;return THREE.Matrix4.makeFrustum(f*b,a*b,f,a,d,e)}; -THREE.Matrix4.makeOrtho=function(a,b,d,e,f,h){var j,c,i,k;j=new THREE.Matrix4;c=b-a;i=d-e;k=h-f;a=(b+a)/c;d=(d+e)/i;f=(h+f)/k;j.n11=2/c;j.n12=0;j.n13=0;j.n14=-a;j.n21=0;j.n22=2/i;j.n23=0;j.n24=-d;j.n31=0;j.n32=0;j.n33=-2/k;j.n34=-f;j.n41=0;j.n42=0;j.n43=0;j.n44=1;return j};THREE.Matrix4.__tmpVec1=new THREE.Vector3;THREE.Matrix4.__tmpVec2=new THREE.Vector3;THREE.Matrix4.__tmpVec3=new THREE.Vector3; +THREE.Matrix4.makeInvert=function(a){var b=a.n11,d=a.n12,e=a.n13,f=a.n14,g=a.n21,k=a.n22,c=a.n23,j=a.n24,l=a.n31,t=a.n32,D=a.n33,o=a.n34,u=a.n41,w=a.n42,C=a.n43,H=a.n44,v=new THREE.Matrix4;v.n11=c*o*w-j*D*w+j*t*C-k*o*C-c*t*H+k*D*H;v.n12=f*D*w-e*o*w-f*t*C+d*o*C+e*t*H-d*D*H;v.n13=e*j*w-f*c*w+f*k*C-d*j*C-e*k*H+d*c*H;v.n14=f*c*t-e*j*t-f*k*D+d*j*D+e*k*o-d*c*o;v.n21=j*D*u-c*o*u-j*l*C+g*o*C+c*l*H-g*D*H;v.n22=e*o*u-f*D*u+f*l*C-b*o*C-e*l*H+b*D*H;v.n23=f*c*u-e*j*u-f*g*C+b*j*C+e*g*H-b*c*H;v.n24=e*j*l-f*c*l+ +f*g*D-b*j*D-e*g*o+b*c*o;v.n31=k*o*u-j*t*u+j*l*w-g*o*w-k*l*H+g*t*H;v.n32=f*t*u-d*o*u-f*l*w+b*o*w+d*l*H-b*t*H;v.n33=e*j*u-f*k*u+f*g*w-b*j*w-d*g*H+b*k*H;v.n34=f*k*l-d*j*l-f*g*t+b*j*t+d*g*o-b*k*o;v.n41=c*t*u-k*D*u-c*l*w+g*D*w+k*l*C-g*t*C;v.n42=d*D*u-e*t*u+e*l*w-b*D*w-d*l*C+b*t*C;v.n43=e*k*u-d*c*u-e*g*w+b*c*w+d*g*C-b*k*C;v.n44=d*c*l-e*k*l+e*g*t-b*c*t-d*g*D+b*k*D;v.multiplyScalar(1/a.determinant());return v}; +THREE.Matrix4.makeInvert3x3=function(a){var b=a.flatten();a=a.m33;var d=a.m,e=b[10]*b[5]-b[6]*b[9],f=-b[10]*b[1]+b[2]*b[9],g=b[6]*b[1]-b[2]*b[5],k=-b[10]*b[4]+b[6]*b[8],c=b[10]*b[0]-b[2]*b[8],j=-b[6]*b[0]+b[2]*b[4],l=b[9]*b[4]-b[5]*b[8],t=-b[9]*b[0]+b[1]*b[8],D=b[5]*b[0]-b[1]*b[4];b=b[0]*e+b[1]*k+b[2]*l;if(b==0)throw"matrix not invertible";b=1/b;d[0]=b*e;d[1]=b*f;d[2]=b*g;d[3]=b*k;d[4]=b*c;d[5]=b*j;d[6]=b*l;d[7]=b*t;d[8]=b*D;return a}; +THREE.Matrix4.makeFrustum=function(a,b,d,e,f,g){var k,c,j;k=new THREE.Matrix4;c=2*f/(b-a);j=2*f/(e-d);a=(b+a)/(b-a);d=(e+d)/(e-d);e=-(g+f)/(g-f);f=-2*g*f/(g-f);k.n11=c;k.n12=0;k.n13=a;k.n14=0;k.n21=0;k.n22=j;k.n23=d;k.n24=0;k.n31=0;k.n32=0;k.n33=e;k.n34=f;k.n41=0;k.n42=0;k.n43=-1;k.n44=0;return k};THREE.Matrix4.makePerspective=function(a,b,d,e){var f;a=d*Math.tan(a*Math.PI/360);f=-a;return THREE.Matrix4.makeFrustum(f*b,a*b,f,a,d,e)}; +THREE.Matrix4.makeOrtho=function(a,b,d,e,f,g){var k,c,j,l;k=new THREE.Matrix4;c=b-a;j=d-e;l=g-f;a=(b+a)/c;d=(d+e)/j;f=(g+f)/l;k.n11=2/c;k.n12=0;k.n13=0;k.n14=-a;k.n21=0;k.n22=2/j;k.n23=0;k.n24=-d;k.n31=0;k.n32=0;k.n33=-2/l;k.n34=-f;k.n41=0;k.n42=0;k.n43=0;k.n44=1;return k};THREE.Matrix4.__tmpVec1=new THREE.Vector3;THREE.Matrix4.__tmpVec2=new THREE.Vector3;THREE.Matrix4.__tmpVec3=new THREE.Vector3; THREE.Vertex=function(a,b){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=b||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.tangent=new THREE.Vector4;this.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}}; THREE.Face3=function(a,b,d,e,f){this.a=a;this.b=b;this.c=d;this.centroid=new THREE.Vector3;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.materials=f instanceof Array?f:[f]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}}; -THREE.Face4=function(a,b,d,e,f,h){this.a=a;this.b=b;this.c=d;this.d=e;this.centroid=new THREE.Vector3;this.normal=f instanceof THREE.Vector3?f:new THREE.Vector3;this.vertexNormals=f instanceof Array?f:[];this.materials=h instanceof Array?h:[h]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,b){this.u=a||0;this.v=b||0}; +THREE.Face4=function(a,b,d,e,f,g){this.a=a;this.b=b;this.c=d;this.d=e;this.centroid=new THREE.Vector3;this.normal=f instanceof THREE.Vector3?f:new THREE.Vector3;this.vertexNormals=f instanceof Array?f:[];this.materials=g instanceof Array?g:[g]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,b){this.u=a||0;this.v=b||0}; THREE.UV.prototype={copy:function(a){this.u=a.u;this.v=a.v},toString:function(){return"THREE.UV ("+this.u+", "+this.v+")"}};THREE.Geometry=function(){this.vertices=[];this.faces=[];this.uvs=[];this.boundingSphere=this.boundingBox=null;this.geometryChunks={};this.hasTangents=false}; THREE.Geometry.prototype={computeCentroids:function(){var a,b,d;a=0;for(b=this.faces.length;a0){this.boundingBox={x:[this.vertices[0].position.x,this.vertices[0].position.x],y:[this.vertices[0].position.y,this.vertices[0].position.y], +this.vertices[e.d].normal.copy(e.vertexNormals[3])}}b=0;for(d=this.vertices.length;b0){this.boundingBox={x:[this.vertices[0].position.x,this.vertices[0].position.x],y:[this.vertices[0].position.y,this.vertices[0].position.y], z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var b=1,d=this.vertices.length;bthis.boundingBox.x[1])this.boundingBox.x[1]=a.position.x;if(a.position.ythis.boundingBox.y[1])this.boundingBox.y[1]=a.position.y;if(a.position.z -this.boundingBox.z[1])this.boundingBox.z[1]=a.position.z}}},computeBoundingSphere:function(){for(var a=this.boundingSphere===null?0:this.boundingSphere.radius,b=0,d=this.vertices.length;b65535){k[c].counter+=1;i=k[c].hash+"_"+k[c].counter;if(this.geometryChunks[i]==undefined)this.geometryChunks[i]={faces:[],materials:j,vertices:0}}this.geometryChunks[i].faces.push(e);this.geometryChunks[i].vertices+=h}},toString:function(){return"THREE.Geometry ( vertices: "+ +this.boundingBox.z[1])this.boundingBox.z[1]=a.position.z}}},computeBoundingSphere:function(){for(var a=this.boundingSphere===null?0:this.boundingSphere.radius,b=0,d=this.vertices.length;b65535){l[c].counter+=1;j=l[c].hash+"_"+l[c].counter;if(this.geometryChunks[j]==undefined)this.geometryChunks[j]={faces:[],materials:k,vertices:0}}this.geometryChunks[j].faces.push(e);this.geometryChunks[j].vertices+=g}},toString:function(){return"THREE.Geometry ( vertices: "+ this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}}; THREE.Camera=function(a,b,d,e){this.fov=a;this.aspect=b;this.near=d;this.far=e;this.position=new THREE.Vector3;this.target={position:new THREE.Vector3};this.autoUpdateMatrix=true;this.projectionMatrix=null;this.matrix=new THREE.Matrix4;this.up=new THREE.Vector3(0,1,0);this.tmpVec=new THREE.Vector3;this.translateX=function(f){this.tmpVec.sub(this.target.position,this.position).normalize().multiplyScalar(f);this.tmpVec.crossSelf(this.up);this.position.addSelf(this.tmpVec);this.target.position.addSelf(this.tmpVec)}; this.translateZ=function(f){this.tmpVec.sub(this.target.position,this.position).normalize().multiplyScalar(f);this.position.subSelf(this.tmpVec);this.target.position.subSelf(this.tmpVec)};this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.updateProjectionMatrix=function(){this.projectionMatrix=THREE.Matrix4.makePerspective(this.fov,this.aspect,this.near,this.far)};this.updateProjectionMatrix()}; @@ -89,7 +89,7 @@ THREE.MeshShaderMaterial.prototype={toString:function(){return"THREE.MeshShaderM THREE.ParticleBasicMaterial=function(a){this.color=new THREE.Color(16777215);this.map=null;this.opacity=1;this.blending=THREE.NormalBlending;this.offset=new THREE.Vector2;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.map!==undefined)this.map=a.map;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}}; THREE.ParticleBasicMaterial.prototype={toString:function(){return"THREE.ParticleBasicMaterial (
color: "+this.color+"
map: "+this.map+"
opacity: "+this.opacity+"
blending: "+this.blending+"
)"}};THREE.ParticleCircleMaterial=function(a){this.color=new THREE.Color(16777215);this.opacity=1;this.blending=THREE.NormalBlending;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}}; THREE.ParticleCircleMaterial.prototype={toString:function(){return"THREE.ParticleCircleMaterial (
color: "+this.color+"
opacity: "+this.opacity+"
blending: "+this.blending+"
)"}};THREE.ParticleDOMMaterial=function(a){this.domElement=a};THREE.ParticleDOMMaterial.prototype={toString:function(){return"THREE.ParticleDOMMaterial ( domElement: "+this.domElement+" )"}}; -THREE.Texture=function(a,b,d,e,f,h){this.image=a;this.mapping=b!==undefined?b:new THREE.UVMapping;this.wrap_s=d!==undefined?d:THREE.ClampToEdgeWrapping;this.wrap_t=e!==undefined?e:THREE.ClampToEdgeWrapping;this.mag_filter=f!==undefined?f:THREE.LinearFilter;this.min_filter=h!==undefined?h:THREE.LinearMipMapLinearFilter}; +THREE.Texture=function(a,b,d,e,f,g){this.image=a;this.mapping=b!==undefined?b:new THREE.UVMapping;this.wrap_s=d!==undefined?d:THREE.ClampToEdgeWrapping;this.wrap_t=e!==undefined?e:THREE.ClampToEdgeWrapping;this.mag_filter=f!==undefined?f:THREE.LinearFilter;this.min_filter=g!==undefined?g:THREE.LinearMipMapLinearFilter}; THREE.Texture.prototype={clone:function(){return new THREE.Texture(this.image,this.mapping,this.wrap_s,this.wrap_t,this.mag_filter,this.min_filter)},toString:function(){return"THREE.Texture (
image: "+this.image+"
wrap_s: "+this.wrap_s+"
wrap_t: "+this.wrap_t+"
mag_filter: "+this.mag_filter+"
min_filter: "+this.min_filter+"
)"}};THREE.MultiplyOperation=0;THREE.MixOperation=1;THREE.RepeatWrapping=0;THREE.ClampToEdgeWrapping=1;THREE.MirroredRepeatWrapping=2; THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLinearFilter=5;THREE.LinearFilter=6;THREE.LinearMipMapNearestFilter=7;THREE.LinearMipMapLinearFilter=8;THREE.ByteType=9;THREE.UnsignedByteType=10;THREE.ShortType=11;THREE.UnsignedShortType=12;THREE.IntType=13;THREE.UnsignedIntType=14;THREE.FloatType=15;THREE.AlphaFormat=16;THREE.RGBFormat=17;THREE.RGBAFormat=18;THREE.LuminanceFormat=19;THREE.LuminanceAlphaFormat=20; THREE.RenderTarget=function(a,b,d){this.width=a;this.height=b;d=d||{};this.wrap_s=d.wrap_s!==undefined?d.wrap_s:THREE.ClampToEdgeWrapping;this.wrap_t=d.wrap_t!==undefined?d.wrap_t:THREE.ClampToEdgeWrapping;this.mag_filter=d.mag_filter!==undefined?d.mag_filter:THREE.LinearFilter;this.min_filter=d.min_filter!==undefined?d.min_filter:THREE.LinearMipMapLinearFilter;this.format=d.format!==undefined?d.format:THREE.RGBFormat;this.type=d.type!==undefined?d.type:THREE.UnsignedByteType}; @@ -97,93 +97,94 @@ var Uniforms={clone:function(a){var b,d,e,f={};for(b in a){f[b]={};for(d in a[b] THREE.SphericalReflectionMapping=function(){};THREE.SphericalRefractionMapping=function(){};THREE.UVMapping=function(){}; THREE.Scene=function(){this.objects=[];this.lights=[];this.fog=null;this.addObject=function(a){this.objects.indexOf(a)===-1&&this.objects.push(a)};this.removeObject=function(a){a=this.objects.indexOf(a);a!==-1&&this.objects.splice(a,1)};this.addLight=function(a){this.lights.indexOf(a)===-1&&this.lights.push(a)};this.removeLight=function(a){a=this.lights.indexOf(a);a!==-1&&this.lights.splice(a,1)};this.toString=function(){return"THREE.Scene ( "+this.objects+" )"}}; THREE.Fog=function(a,b,d){this.color=new THREE.Color(a);this.near=b||1;this.far=d||1E3};THREE.FogExp2=function(a,b){this.color=new THREE.Color(a);this.density=b||2.5E-4}; -THREE.Projector=function(){function a(o,v){return v.z-o.z}function b(o,v){var J=0,s=1,A=o.z+o.w,C=v.z+v.w,B=-o.z+o.w,t=-v.z+v.w;if(A>=0&&C>=0&&B>=0&&t>=0)return true;else if(A<0&&C<0||B<0&&t<0)return false;else{if(A<0)J=Math.max(J,A/(A-C));else if(C<0)s=Math.min(s,A/(A-C));if(B<0)J=Math.max(J,B/(B-t));else if(t<0)s=Math.min(s,B/(B-t));if(sA&&F.z0&&H.z<1){n=x[u]=x[u]||new THREE.RenderableParticle;n.x=H.x/H.w;n.y=H.y/H.w;n.z=H.z;n.rotation=M.rotation.z;n.scale.x=M.scale.x*Math.abs(n.x-(H.x+v.projectionMatrix.n11)/(H.w+v.projectionMatrix.n14)); -n.scale.y=M.scale.y*Math.abs(n.y-(H.y+v.projectionMatrix.n22)/(H.w+v.projectionMatrix.n24));n.materials=M.materials;s.push(n);u++}}}}J&&s.sort(a);return s};this.unprojectVector=function(o,v){var J=THREE.Matrix4.makeInvert(v.matrix);J.multiplySelf(THREE.Matrix4.makeInvert(v.projectionMatrix));J.multiplyVector3(o);return o}}; -THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,d,e,f,h;this.domElement=document.createElement("div");this.setSize=function(j,c){d=j;e=c;f=d/2;h=e/2};this.render=function(j,c){var i,k,r,z,n,u,x,y;a=b.projectScene(j,c);i=0;for(k=a.length;i0){N.r+=ia.r*ca;N.g+=ia.g*ca;N.b+=ia.b*ca}}else if(ca instanceof THREE.PointLight){E.sub(ca.position,ba);E.normalize();ca=Y.dot(E)*ka;if(ca>0){N.r+=ia.r*ca;N.g+=ia.g*ca;N.b+=ia.b*ca}}}}function Na(K,ba,Y){if(Y.opacity!=0){a(Y.opacity); -b(Y.blending);var N,X,ca,ia,ka,la;if(Y instanceof THREE.ParticleBasicMaterial){if(Y.map){ia=Y.map;ka=ia.width>>1;la=ia.height>>1;X=ba.scale.x*c;ca=ba.scale.y*i;Y=X*ka;N=ca*la;D.set(K.x-Y,K.y-N,K.x+Y,K.y+N);if(Z.instersects(D)){k.save();k.translate(K.x,K.y);k.rotate(-ba.rotation);k.scale(X,-ca);k.translate(-ka,-la);k.drawImage(ia,0,0);k.restore()}}}else if(Y instanceof THREE.ParticleCircleMaterial){if(P){S.r=fa.r+ea.r+q.r;S.g=fa.g+ea.g+q.g;S.b=fa.b+ea.b+q.b;s.r=Y.color.r*S.r;s.g=Y.color.g*S.g;s.b= -Y.color.b*S.b;s.updateStyleString()}else s.__styleString=Y.color.__styleString;Y=ba.scale.x*c;N=ba.scale.y*i;D.set(K.x-Y,K.y-N,K.x+Y,K.y+N);if(Z.instersects(D)){X=s.__styleString;if(y!=X)k.fillStyle=y=X;k.save();k.translate(K.x,K.y);k.rotate(-ba.rotation);k.scale(Y,N);k.beginPath();k.arc(0,0,1,0,G,true);k.closePath();k.fill();k.restore()}}}}function Oa(K,ba,Y,N){if(N.opacity!=0){a(N.opacity);b(N.blending);k.beginPath();k.moveTo(K.positionScreen.x,K.positionScreen.y);k.lineTo(ba.positionScreen.x,ba.positionScreen.y); -k.closePath();if(N instanceof THREE.LineBasicMaterial){s.__styleString=N.color.__styleString;K=N.linewidth;if(H!=K)k.lineWidth=H=K;K=s.__styleString;if(x!=K)k.strokeStyle=x=K;k.stroke();D.inflate(N.linewidth*2)}}}function Ia(K,ba,Y,N,X,ca){if(X.opacity!=0){a(X.opacity);b(X.blending);g=K.positionScreen.x;m=K.positionScreen.y;w=ba.positionScreen.x;o=ba.positionScreen.y;v=Y.positionScreen.x;J=Y.positionScreen.y;k.beginPath();k.moveTo(g,m);k.lineTo(w,o);k.lineTo(v,J);k.lineTo(g,m);k.closePath();if(X instanceof -THREE.MeshBasicMaterial)if(X.map)X.map.image.loaded&&X.map.mapping instanceof THREE.UVMapping&&xa(g,m,w,o,v,J,X.map.image,N.uvs[0].u,N.uvs[0].v,N.uvs[1].u,N.uvs[1].v,N.uvs[2].u,N.uvs[2].v);else if(X.env_map){if(X.env_map.image.loaded)if(X.env_map.mapping instanceof THREE.SphericalReflectionMapping){K=ta.matrix;E.copy(N.vertexNormalsWorld[0]);T=(E.x*K.n11+E.y*K.n12+E.z*K.n13)*0.5+0.5;M=-(E.x*K.n21+E.y*K.n22+E.z*K.n23)*0.5+0.5;E.copy(N.vertexNormalsWorld[1]);aa=(E.x*K.n11+E.y*K.n12+E.z*K.n13)*0.5+0.5; -U=-(E.x*K.n21+E.y*K.n22+E.z*K.n23)*0.5+0.5;E.copy(N.vertexNormalsWorld[2]);O=(E.x*K.n11+E.y*K.n12+E.z*K.n13)*0.5+0.5;Q=-(E.x*K.n21+E.y*K.n22+E.z*K.n23)*0.5+0.5;xa(g,m,w,o,v,J,X.env_map.image,T,M,aa,U,O,Q)}}else X.wireframe?Ba(X.color.__styleString,X.wireframe_linewidth):Ca(X.color.__styleString);else if(X instanceof THREE.MeshLambertMaterial){if(X.map&&!X.wireframe){X.map.mapping instanceof THREE.UVMapping&&xa(g,m,w,o,v,J,X.map.image,N.uvs[0].u,N.uvs[0].v,N.uvs[1].u,N.uvs[1].v,N.uvs[2].u,N.uvs[2].v); -b(THREE.SubtractiveBlending)}if(P)if(!X.wireframe&&X.shading==THREE.SmoothShading&&N.vertexNormalsWorld.length==3){A.r=C.r=B.r=fa.r;A.g=C.g=B.g=fa.g;A.b=C.b=B.b=fa.b;Aa(ca,N.v1.positionWorld,N.vertexNormalsWorld[0],A);Aa(ca,N.v2.positionWorld,N.vertexNormalsWorld[1],C);Aa(ca,N.v3.positionWorld,N.vertexNormalsWorld[2],B);t.r=(C.r+B.r)*0.5;t.g=(C.g+B.g)*0.5;t.b=(C.b+B.b)*0.5;R=Ja(A,C,B,t);xa(g,m,w,o,v,J,R,0,0,1,0,0,1)}else{S.r=fa.r;S.g=fa.g;S.b=fa.b;Aa(ca,N.centroidWorld,N.normalWorld,S);s.r=X.color.r* -S.r;s.g=X.color.g*S.g;s.b=X.color.b*S.b;s.updateStyleString();X.wireframe?Ba(s.__styleString,X.wireframe_linewidth):Ca(s.__styleString)}else X.wireframe?Ba(X.color.__styleString,X.wireframe_linewidth):Ca(X.color.__styleString)}else if(X instanceof THREE.MeshDepthMaterial){L=ta.near;F=ta.far;A.r=A.g=A.b=1-Ea(K.positionScreen.z,L,F);C.r=C.g=C.b=1-Ea(ba.positionScreen.z,L,F);B.r=B.g=B.b=1-Ea(Y.positionScreen.z,L,F);t.r=(C.r+B.r)*0.5;t.g=(C.g+B.g)*0.5;t.b=(C.b+B.b)*0.5;R=Ja(A,C,B,t);xa(g,m,w,o,v,J,R, -0,0,1,0,0,1)}else if(X instanceof THREE.MeshNormalMaterial){s.r=Fa(N.normalWorld.x);s.g=Fa(N.normalWorld.y);s.b=Fa(N.normalWorld.z);s.updateStyleString();X.wireframe?Ba(s.__styleString,X.wireframe_linewidth):Ca(s.__styleString)}}}function Ba(K,ba){if(x!=K)k.strokeStyle=x=K;if(H!=ba)k.lineWidth=H=ba;k.stroke();D.inflate(ba*2)}function Ca(K){if(y!=K)k.fillStyle=y=K;k.fill()}function xa(K,ba,Y,N,X,ca,ia,ka,la,qa,ma,ra,ya){var ua,sa;ua=ia.width-1;sa=ia.height-1;ka*=ua;la*=sa;qa*=ua;ma*=sa;ra*=ua;ya*= -sa;Y-=K;N-=ba;X-=K;ca-=ba;qa-=ka;ma-=la;ra-=ka;ya-=la;sa=1/(qa*ya-ra*ma);ua=(ya*Y-ma*X)*sa;ma=(ya*N-ma*ca)*sa;Y=(qa*X-ra*Y)*sa;N=(qa*ca-ra*N)*sa;K=K-ua*ka-Y*la;ba=ba-ma*ka-N*la;k.save();k.transform(ua,ma,Y,N,K,ba);k.clip();k.drawImage(ia,0,0);k.restore()}function Ja(K,ba,Y,N){var X=~~(K.r*255),ca=~~(K.g*255);K=~~(K.b*255);var ia=~~(ba.r*255),ka=~~(ba.g*255);ba=~~(ba.b*255);var la=~~(Y.r*255),qa=~~(Y.g*255);Y=~~(Y.b*255);var ma=~~(N.r*255),ra=~~(N.g*255);N=~~(N.b*255);ga[0]=X<0?0:X>255?255:X;ga[1]= -ca<0?0:ca>255?255:ca;ga[2]=K<0?0:K>255?255:K;ga[4]=ia<0?0:ia>255?255:ia;ga[5]=ka<0?0:ka>255?255:ka;ga[6]=ba<0?0:ba>255?255:ba;ga[8]=la<0?0:la>255?255:la;ga[9]=qa<0?0:qa>255?255:qa;ga[10]=Y<0?0:Y>255?255:Y;ga[12]=ma<0?0:ma>255?255:ma;ga[13]=ra<0?0:ra>255?255:ra;ga[14]=N<0?0:N>255?255:N;$.putImageData(da,0,0);pa.drawImage(W,0,0);return na}function Ea(K,ba,Y){K=(K-ba)/(Y-ba);return K*K*(3-2*K)}function Fa(K){K=(K+1)*0.5;return K<0?0:K>1?1:K}function Ga(K,ba){var Y=ba.x-K.x,N=ba.y-K.y,X=1/Math.sqrt(Y* -Y+N*N);Y*=X;N*=X;ba.x+=Y;ba.y+=N;K.x-=Y;K.y-=N}var Da,Ka,ha,oa,wa,Ha,La,za;k.setTransform(1,0,0,-1,c,i);this.autoClear&&this.clear();d=e.projectScene(ja,ta,this.sortElements);(P=ja.lights.length>0)&&Ma(ja);Da=0;for(Ka=d.length;Da0){aa.r+=Q.color.r*Z;aa.g+=Q.color.g*Z;aa.b+=Q.color.b*Z}}else if(Q instanceof THREE.PointLight){J.sub(Q.position,M.centroidWorld);J.normalize();Z=M.normalWorld.dot(J)*Q.intensity;if(Z>0){aa.r+=Q.color.r*Z;aa.g+=Q.color.g*Z;aa.b+=Q.color.b*Z}}}}function b(T,M,aa,U,O,Q){B=e(t++);B.setAttribute("d","M "+ -T.positionScreen.x+" "+T.positionScreen.y+" L "+M.positionScreen.x+" "+M.positionScreen.y+" L "+aa.positionScreen.x+","+aa.positionScreen.y+"z");if(O instanceof THREE.MeshBasicMaterial)l.__styleString=O.color.__styleString;else if(O instanceof THREE.MeshLambertMaterial)if(I){g.r=m.r;g.g=m.g;g.b=m.b;a(Q,U,g);l.r=O.color.r*g.r;l.g=O.color.g*g.g;l.b=O.color.b*g.b;l.updateStyleString()}else l.__styleString=O.color.__styleString;else if(O instanceof THREE.MeshDepthMaterial){v=1-O.__2near/(O.__farPlusNear- -U.z*O.__farMinusNear);l.setRGB(v,v,v)}else O instanceof THREE.MeshNormalMaterial&&l.setRGB(f(U.normalWorld.x),f(U.normalWorld.y),f(U.normalWorld.z));O.wireframe?B.setAttribute("style","fill: none; stroke: "+l.__styleString+"; stroke-width: "+O.wireframe_linewidth+"; stroke-opacity: "+O.opacity+"; stroke-linecap: "+O.wireframe_linecap+"; stroke-linejoin: "+O.wireframe_linejoin):B.setAttribute("style","fill: "+l.__styleString+"; fill-opacity: "+O.opacity);c.appendChild(B)}function d(T,M,aa,U,O,Q,Z){B= -e(t++);B.setAttribute("d","M "+T.positionScreen.x+" "+T.positionScreen.y+" L "+M.positionScreen.x+" "+M.positionScreen.y+" L "+aa.positionScreen.x+","+aa.positionScreen.y+" L "+U.positionScreen.x+","+U.positionScreen.y+"z");if(Q instanceof THREE.MeshBasicMaterial)l.__styleString=Q.color.__styleString;else if(Q instanceof THREE.MeshLambertMaterial)if(I){g.r=m.r;g.g=m.g;g.b=m.b;a(Z,O,g);l.r=Q.color.r*g.r;l.g=Q.color.g*g.g;l.b=Q.color.b*g.b;l.updateStyleString()}else l.__styleString=Q.color.__styleString; -else if(Q instanceof THREE.MeshDepthMaterial){v=1-Q.__2near/(Q.__farPlusNear-O.z*Q.__farMinusNear);l.setRGB(v,v,v)}else Q instanceof THREE.MeshNormalMaterial&&l.setRGB(f(O.normalWorld.x),f(O.normalWorld.y),f(O.normalWorld.z));Q.wireframe?B.setAttribute("style","fill: none; stroke: "+l.__styleString+"; stroke-width: "+Q.wireframe_linewidth+"; stroke-opacity: "+Q.opacity+"; stroke-linecap: "+Q.wireframe_linecap+"; stroke-linejoin: "+Q.wireframe_linejoin):B.setAttribute("style","fill: "+l.__styleString+ -"; fill-opacity: "+Q.opacity);c.appendChild(B)}function e(T){if(s[T]==null){s[T]=document.createElementNS("http://www.w3.org/2000/svg","path");R==0&&s[T].setAttribute("shape-rendering","crispEdges");return s[T]}return s[T]}function f(T){return T<0?Math.min((1+T)*0.5,0.5):0.5+Math.min(T*0.5,0.5)}var h=null,j=new THREE.Projector,c=document.createElementNS("http://www.w3.org/2000/svg","svg"),i,k,r,z,n,u,x,y,H=new THREE.Rectangle,p=new THREE.Rectangle,I=false,l=new THREE.Color(16777215),g=new THREE.Color(16777215), -m=new THREE.Color(0),w=new THREE.Color(0),o=new THREE.Color(0),v,J=new THREE.Vector3,s=[],A=[],C=[],B,t,L,F,R=1;this.domElement=c;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(T){switch(T){case "high":R=1;break;case "low":R=0}};this.setSize=function(T,M){i=T;k=M;r=i/2;z=k/2;c.setAttribute("viewBox",-r+" "+-z+" "+i+" "+k);c.setAttribute("width",i);c.setAttribute("height",k);H.set(-r,-z,r,z)};this.clear=function(){for(;c.childNodes.length>0;)c.removeChild(c.childNodes[0])}; -this.render=function(T,M){var aa,U,O,Q,Z,V,D,P;this.autoClear&&this.clear();h=j.projectScene(T,M,this.sortElements);F=L=t=0;if(I=T.lights.length>0){D=T.lights;m.setRGB(0,0,0);w.setRGB(0,0,0);o.setRGB(0,0,0);aa=0;for(U=D.length;aa=0&&F>=0&&E>=0&&y>=0)return true;else if(A<0&&F<0||E<0&&y<0)return false;else{if(A<0)M=Math.max(M,A/(A-F));else if(F<0)p=Math.min(p,A/(A-F));if(E<0)M=Math.max(M,E/(E-y));else if(y<0)p=Math.min(p,E/(E-y));if(pA&&K.z0&&H.z<1){o=w[u]=w[u]||new THREE.RenderableParticle;o.x=H.x/H.w;o.y=H.y/H.w;o.z=H.z;o.rotation=P.rotation.z;o.scale.x=P.scale.x*Math.abs(o.x-(H.x+z.projectionMatrix.n11)/(H.w+z.projectionMatrix.n14)); +o.scale.y=P.scale.y*Math.abs(o.y-(H.y+z.projectionMatrix.n22)/(H.w+z.projectionMatrix.n24));o.materials=P.materials;p.push(o);u++}}}}M&&p.sort(a);return p};this.unprojectVector=function(q,z){var M=THREE.Matrix4.makeInvert(z.matrix);M.multiplySelf(THREE.Matrix4.makeInvert(z.projectionMatrix));M.multiplyVector3(q);return q}}; +THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,d,e,f,g;this.domElement=document.createElement("div");this.setSize=function(k,c){d=k;e=c;f=d/2;g=e/2};this.render=function(k,c){var j,l,t,D,o,u,w,C;a=b.projectScene(k,c);j=0;for(l=a.length;j0){Q.r+=la.r*fa;Q.g+=la.g*fa;Q.b+=la.b*fa}}else if(fa instanceof THREE.PointLight){J.sub(fa.position,ea);J.normalize();fa=aa.dot(J)*na;if(fa>0){Q.r+=la.r*fa;Q.g+=la.g*fa;Q.b+=la.b*fa}}}}function Qa(N,ea,aa){if(aa.opacity!= +0){a(aa.opacity);b(aa.blending);var Q,$,fa,la,na,oa;if(aa instanceof THREE.ParticleBasicMaterial){if(aa.map){la=aa.map;na=la.width>>1;oa=la.height>>1;$=ea.scale.x*c;fa=ea.scale.y*j;aa=$*na;Q=fa*oa;G.set(N.x-aa,N.y-Q,N.x+aa,N.y+Q);if(ba.instersects(G)){l.save();l.translate(N.x,N.y);l.rotate(-ea.rotation);l.scale($,-fa);l.translate(-na,-oa);l.drawImage(la,0,0);l.restore()}}}else if(aa instanceof THREE.ParticleCircleMaterial){if(S){V.r=ia.r+ha.r+x.r;V.g=ia.g+ha.g+x.g;V.b=ia.b+ha.b+x.b;p.r=aa.color.r* +V.r;p.g=aa.color.g*V.g;p.b=aa.color.b*V.b;p.updateStyleString()}else p.__styleString=aa.color.__styleString;aa=ea.scale.x*c;Q=ea.scale.y*j;G.set(N.x-aa,N.y-Q,N.x+aa,N.y+Q);if(ba.instersects(G)){$=p.__styleString;if(C!=$)l.fillStyle=C=$;l.save();l.translate(N.x,N.y);l.rotate(-ea.rotation);l.scale(aa,Q);l.beginPath();l.arc(0,0,1,0,L,true);l.closePath();l.fill();l.restore()}}}}function Ra(N,ea,aa,Q){if(Q.opacity!=0){a(Q.opacity);b(Q.blending);l.beginPath();l.moveTo(N.positionScreen.x,N.positionScreen.y); +l.lineTo(ea.positionScreen.x,ea.positionScreen.y);l.closePath();if(Q instanceof THREE.LineBasicMaterial){p.__styleString=Q.color.__styleString;N=Q.linewidth;if(H!=N)l.lineWidth=H=N;N=p.__styleString;if(w!=N)l.strokeStyle=w=N;l.stroke();G.inflate(Q.linewidth*2)}}}function La(N,ea,aa,Q,$,fa){if($.opacity!=0){a($.opacity);b($.blending);h=N.positionScreen.x;n=N.positionScreen.y;B=ea.positionScreen.x;q=ea.positionScreen.y;z=aa.positionScreen.x;M=aa.positionScreen.y;l.beginPath();l.moveTo(h,n);l.lineTo(B, +q);l.lineTo(z,M);l.lineTo(h,n);l.closePath();if($ instanceof THREE.MeshBasicMaterial)if($.map)$.map.image.loaded&&$.map.mapping instanceof THREE.UVMapping&&Aa(h,n,B,q,z,M,$.map.image,Q.uvs[0].u,Q.uvs[0].v,Q.uvs[1].u,Q.uvs[1].v,Q.uvs[2].u,Q.uvs[2].v);else if($.env_map){if($.env_map.image.loaded)if($.env_map.mapping instanceof THREE.SphericalReflectionMapping){N=wa.matrix;J.copy(Q.vertexNormalsWorld[0]);W=(J.x*N.n11+J.y*N.n12+J.z*N.n13)*0.5+0.5;P=-(J.x*N.n21+J.y*N.n22+J.z*N.n23)*0.5+0.5;J.copy(Q.vertexNormalsWorld[1]); +da=(J.x*N.n11+J.y*N.n12+J.z*N.n13)*0.5+0.5;X=-(J.x*N.n21+J.y*N.n22+J.z*N.n23)*0.5+0.5;J.copy(Q.vertexNormalsWorld[2]);R=(J.x*N.n11+J.y*N.n12+J.z*N.n13)*0.5+0.5;T=-(J.x*N.n21+J.y*N.n22+J.z*N.n23)*0.5+0.5;Aa(h,n,B,q,z,M,$.env_map.image,W,P,da,X,R,T)}}else $.wireframe?Ea($.color.__styleString,$.wireframe_linewidth):Fa($.color.__styleString);else if($ instanceof THREE.MeshLambertMaterial){if($.map&&!$.wireframe){$.map.mapping instanceof THREE.UVMapping&&Aa(h,n,B,q,z,M,$.map.image,Q.uvs[0].u,Q.uvs[0].v, +Q.uvs[1].u,Q.uvs[1].v,Q.uvs[2].u,Q.uvs[2].v);b(THREE.SubtractiveBlending)}if(S)if(!$.wireframe&&$.shading==THREE.SmoothShading&&Q.vertexNormalsWorld.length==3){A.r=F.r=E.r=ia.r;A.g=F.g=E.g=ia.g;A.b=F.b=E.b=ia.b;Da(fa,Q.v1.positionWorld,Q.vertexNormalsWorld[0],A);Da(fa,Q.v2.positionWorld,Q.vertexNormalsWorld[1],F);Da(fa,Q.v3.positionWorld,Q.vertexNormalsWorld[2],E);y.r=(F.r+E.r)*0.5;y.g=(F.g+E.g)*0.5;y.b=(F.b+E.b)*0.5;U=Ma(A,F,E,y);Aa(h,n,B,q,z,M,U,0,0,1,0,0,1)}else{V.r=ia.r;V.g=ia.g;V.b=ia.b;Da(fa, +Q.centroidWorld,Q.normalWorld,V);p.r=$.color.r*V.r;p.g=$.color.g*V.g;p.b=$.color.b*V.b;p.updateStyleString();$.wireframe?Ea(p.__styleString,$.wireframe_linewidth):Fa(p.__styleString)}else $.wireframe?Ea($.color.__styleString,$.wireframe_linewidth):Fa($.color.__styleString)}else if($ instanceof THREE.MeshDepthMaterial){O=wa.near;K=wa.far;A.r=A.g=A.b=1-Ha(N.positionScreen.z,O,K);F.r=F.g=F.b=1-Ha(ea.positionScreen.z,O,K);E.r=E.g=E.b=1-Ha(aa.positionScreen.z,O,K);y.r=(F.r+E.r)*0.5;y.g=(F.g+E.g)*0.5;y.b= +(F.b+E.b)*0.5;U=Ma(A,F,E,y);Aa(h,n,B,q,z,M,U,0,0,1,0,0,1)}else if($ instanceof THREE.MeshNormalMaterial){p.r=Ia(Q.normalWorld.x);p.g=Ia(Q.normalWorld.y);p.b=Ia(Q.normalWorld.z);p.updateStyleString();$.wireframe?Ea(p.__styleString,$.wireframe_linewidth):Fa(p.__styleString)}}}function Ea(N,ea){if(w!=N)l.strokeStyle=w=N;if(H!=ea)l.lineWidth=H=ea;l.stroke();G.inflate(ea*2)}function Fa(N){if(C!=N)l.fillStyle=C=N;l.fill()}function Aa(N,ea,aa,Q,$,fa,la,na,oa,ta,pa,ua,Ba){var xa,va;xa=la.width-1;va=la.height- +1;na*=xa;oa*=va;ta*=xa;pa*=va;ua*=xa;Ba*=va;aa-=N;Q-=ea;$-=N;fa-=ea;ta-=na;pa-=oa;ua-=na;Ba-=oa;va=1/(ta*Ba-ua*pa);xa=(Ba*aa-pa*$)*va;pa=(Ba*Q-pa*fa)*va;aa=(ta*$-ua*aa)*va;Q=(ta*fa-ua*Q)*va;N=N-xa*na-aa*oa;ea=ea-pa*na-Q*oa;l.save();l.transform(xa,pa,aa,Q,N,ea);l.clip();l.drawImage(la,0,0);l.restore()}function Ma(N,ea,aa,Q){var $=~~(N.r*255),fa=~~(N.g*255);N=~~(N.b*255);var la=~~(ea.r*255),na=~~(ea.g*255);ea=~~(ea.b*255);var oa=~~(aa.r*255),ta=~~(aa.g*255);aa=~~(aa.b*255);var pa=~~(Q.r*255),ua=~~(Q.g* +255);Q=~~(Q.b*255);ja[0]=$<0?0:$>255?255:$;ja[1]=fa<0?0:fa>255?255:fa;ja[2]=N<0?0:N>255?255:N;ja[4]=la<0?0:la>255?255:la;ja[5]=na<0?0:na>255?255:na;ja[6]=ea<0?0:ea>255?255:ea;ja[8]=oa<0?0:oa>255?255:oa;ja[9]=ta<0?0:ta>255?255:ta;ja[10]=aa<0?0:aa>255?255:aa;ja[12]=pa<0?0:pa>255?255:pa;ja[13]=ua<0?0:ua>255?255:ua;ja[14]=Q<0?0:Q>255?255:Q;ca.putImageData(ga,0,0);sa.drawImage(Z,0,0);return qa}function Ha(N,ea,aa){N=(N-ea)/(aa-ea);return N*N*(3-2*N)}function Ia(N){N=(N+1)*0.5;return N<0?0:N>1?1:N}function Ja(N, +ea){var aa=ea.x-N.x,Q=ea.y-N.y,$=1/Math.sqrt(aa*aa+Q*Q);aa*=$;Q*=$;ea.x+=aa;ea.y+=Q;N.x-=aa;N.y-=Q}var Ga,Na,ka,ra,za,Ka,Oa,Ca;l.setTransform(1,0,0,-1,c,j);this.autoClear&&this.clear();d=e.projectScene(ma,wa,this.sortElements);(S=ma.lights.length>0)&&Pa(ma);Ga=0;for(Na=d.length;Ga0){da.r+=T.color.r*ba;da.g+=T.color.g*ba;da.b+=T.color.b*ba}}else if(T instanceof THREE.PointLight){M.sub(T.position,P.centroidWorld);M.normalize();ba=P.normalWorld.dot(M)*T.intensity;if(ba>0){da.r+=T.color.r*ba;da.g+=T.color.g*ba;da.b+=T.color.b*ba}}}}function b(W,P,da,X,R,T){E=e(y++);E.setAttribute("d", +"M "+W.positionScreen.x+" "+W.positionScreen.y+" L "+P.positionScreen.x+" "+P.positionScreen.y+" L "+da.positionScreen.x+","+da.positionScreen.y+"z");if(R instanceof THREE.MeshBasicMaterial)m.__styleString=R.color.__styleString;else if(R instanceof THREE.MeshLambertMaterial)if(I){h.r=n.r;h.g=n.g;h.b=n.b;a(T,X,h);m.r=R.color.r*h.r;m.g=R.color.g*h.g;m.b=R.color.b*h.b;m.updateStyleString()}else m.__styleString=R.color.__styleString;else if(R instanceof THREE.MeshDepthMaterial){z=1-R.__2near/(R.__farPlusNear- +X.z*R.__farMinusNear);m.setRGB(z,z,z)}else R instanceof THREE.MeshNormalMaterial&&m.setRGB(f(X.normalWorld.x),f(X.normalWorld.y),f(X.normalWorld.z));R.wireframe?E.setAttribute("style","fill: none; stroke: "+m.__styleString+"; stroke-width: "+R.wireframe_linewidth+"; stroke-opacity: "+R.opacity+"; stroke-linecap: "+R.wireframe_linecap+"; stroke-linejoin: "+R.wireframe_linejoin):E.setAttribute("style","fill: "+m.__styleString+"; fill-opacity: "+R.opacity);c.appendChild(E)}function d(W,P,da,X,R,T,ba){E= +e(y++);E.setAttribute("d","M "+W.positionScreen.x+" "+W.positionScreen.y+" L "+P.positionScreen.x+" "+P.positionScreen.y+" L "+da.positionScreen.x+","+da.positionScreen.y+" L "+X.positionScreen.x+","+X.positionScreen.y+"z");if(T instanceof THREE.MeshBasicMaterial)m.__styleString=T.color.__styleString;else if(T instanceof THREE.MeshLambertMaterial)if(I){h.r=n.r;h.g=n.g;h.b=n.b;a(ba,R,h);m.r=T.color.r*h.r;m.g=T.color.g*h.g;m.b=T.color.b*h.b;m.updateStyleString()}else m.__styleString=T.color.__styleString; +else if(T instanceof THREE.MeshDepthMaterial){z=1-T.__2near/(T.__farPlusNear-R.z*T.__farMinusNear);m.setRGB(z,z,z)}else T instanceof THREE.MeshNormalMaterial&&m.setRGB(f(R.normalWorld.x),f(R.normalWorld.y),f(R.normalWorld.z));T.wireframe?E.setAttribute("style","fill: none; stroke: "+m.__styleString+"; stroke-width: "+T.wireframe_linewidth+"; stroke-opacity: "+T.opacity+"; stroke-linecap: "+T.wireframe_linecap+"; stroke-linejoin: "+T.wireframe_linejoin):E.setAttribute("style","fill: "+m.__styleString+ +"; fill-opacity: "+T.opacity);c.appendChild(E)}function e(W){if(p[W]==null){p[W]=document.createElementNS("http://www.w3.org/2000/svg","path");U==0&&p[W].setAttribute("shape-rendering","crispEdges");return p[W]}return p[W]}function f(W){return W<0?Math.min((1+W)*0.5,0.5):0.5+Math.min(W*0.5,0.5)}var g=null,k=new THREE.Projector,c=document.createElementNS("http://www.w3.org/2000/svg","svg"),j,l,t,D,o,u,w,C,H=new THREE.Rectangle,v=new THREE.Rectangle,I=false,m=new THREE.Color(16777215),h=new THREE.Color(16777215), +n=new THREE.Color(0),B=new THREE.Color(0),q=new THREE.Color(0),z,M=new THREE.Vector3,p=[],A=[],F=[],E,y,O,K,U=1;this.domElement=c;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(W){switch(W){case "high":U=1;break;case "low":U=0}};this.setSize=function(W,P){j=W;l=P;t=j/2;D=l/2;c.setAttribute("viewBox",-t+" "+-D+" "+j+" "+l);c.setAttribute("width",j);c.setAttribute("height",l);H.set(-t,-D,t,D)};this.clear=function(){for(;c.childNodes.length>0;)c.removeChild(c.childNodes[0])}; +this.render=function(W,P){var da,X,R,T,ba,Y,G,S;this.autoClear&&this.clear();g=k.projectScene(W,P,this.sortElements);K=O=y=0;if(I=W.lights.length>0){G=W.lights;n.setRGB(0,0,0);B.setRGB(0,0,0);q.setRGB(0,0,0);da=0;for(X=G.length;da0){c.bindBuffer(c.ARRAY_BUFFER,g.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,fa,w)}if(v){c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,g.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER, -G,w);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,g.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,E,w)}};this.setLineBuffers=function(g,m,w,o){var v,J,s=g.vertices,A=s.length,C=g.__vertexArray,B=g.__lineArray;if(w)for(w=0;w0?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+B.maxDirLights,"#define MAX_POINT_LIGHTS "+B.maxPointLights,B.map?"#define USE_MAP":"",B.env_map?"#define USE_ENVMAP":"", -"uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"].join("\n");c.attachShader(L,f("fragment",F+A));c.attachShader(L,f("vertex",B+t));c.linkProgram(L);c.getProgramParameter(L,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(L,c.VALIDATE_STATUS)+", gl error ["+ -c.getError()+"]");L.uniforms={};L.attributes={};o.program=L;A=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(s in o.uniforms)A.push(s);s=o.program;t=0;for(L=A.length;t=0){c.bindBuffer(c.ARRAY_BUFFER,v.__webGLNormalBuffer);c.vertexAttribPointer(C.normal,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(C.normal)}if(C.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,v.__webGLTangentBuffer);c.vertexAttribPointer(C.tangent,4,c.FLOAT, -false,0,0);c.enableVertexAttribArray(C.tangent)}if(C.uv>=0)if(v.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,v.__webGLUVBuffer);c.vertexAttribPointer(C.uv,2,c.FLOAT,false,0,0);c.enableVertexAttribArray(C.uv)}else c.disableVertexAttribArray(C.uv);if(o.wireframe||o instanceof THREE.LineBasicMaterial){C=o.wireframe_linewidth!==undefined?o.wireframe_linewidth:o.linewidth!==undefined?o.linewidth:1;o=o instanceof THREE.LineBasicMaterial&&J.type==THREE.LineStrip?c.LINE_STRIP:c.LINES;c.lineWidth(C);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER, -v.__webGLLineBuffer);c.drawElements(o,v.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,v.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,v.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(g,m,w,o,v,J,s){var A,C,B,t,L;B=0;for(t=o.materials.length;B=0;w--){o=g.__webGLObjects[w].object;m==o&&g.__webGLObjects.splice(w,1)}};this.setupMatrices=function(g,m){g.autoUpdateMatrix&&g.updateMatrix();r.multiply(m.matrix,g.matrix);u.set(r.flatten()); -z=THREE.Matrix4.makeInvert3x3(r).transpose();y.set(z.m);H.set(g.matrix.flatten())};this.loadMatrices=function(g){c.uniformMatrix4fv(g.uniforms.viewMatrix,false,n);c.uniformMatrix4fv(g.uniforms.modelViewMatrix,false,u);c.uniformMatrix4fv(g.uniforms.projectionMatrix,false,x);c.uniformMatrix3fv(g.uniforms.normalMatrix,false,y);c.uniformMatrix4fv(g.uniforms.objectMatrix,false,H)};this.loadCamera=function(g,m){c.uniform3f(g.uniforms.cameraPosition,m.position.x,m.position.y,m.position.z)};this.setBlending= -function(g){switch(g){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE);break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(g,m){if(g){!m||m=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(g=="back")c.cullFace(c.BACK);else g=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)};this.supportsVertexTextures= -function(){return c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}}; +case THREE.IntType:return c.INT;case THREE.UnsignedShortType:return c.UNSIGNED_INT;case THREE.FloatType:return c.FLOAT;case THREE.AlphaFormat:return c.ALPHA;case THREE.RGBFormat:return c.RGB;case THREE.RGBAFormat:return c.RGBA;case THREE.LuminanceFormat:return c.LUMINANCE;case THREE.LuminanceAlphaFormat:return c.LUMINANCE_ALPHA}return 0}var k=document.createElement("canvas"),c,j=null,l=null,t=new THREE.Matrix4,D,o=new Float32Array(16),u=new Float32Array(16),w=new Float32Array(16),C=new Float32Array(9), +H=new Float32Array(16),v=true,I=new THREE.Color(0),m=0;if(a){if(a.antialias!==undefined)v=a.antialias;a.clearColor!==undefined&&I.setHex(a.clearColor);if(a.clearAlpha!==undefined)m=a.clearAlpha}this.domElement=k;this.autoClear=true;(function(h,n,B){try{c=k.getContext("experimental-webgl",{antialias:h})}catch(q){}if(!c){alert("WebGL not supported");throw"cannot create webgl context";}c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK); +c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(n.r,n.g,n.b,B)})(v,I,m);this.context=c;this.lights={ambient:[0,0,0],directional:{length:0,colors:[],positions:[]},point:{length:0,colors:[],positions:[]}};this.setSize=function(h,n){k.width=h;k.height=n;c.viewport(0,0,k.width,k.height)};this.setClearColor=function(h,n){var B=new THREE.Color(h);c.clearColor(B.r,B.g,B.b,n)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights= +function(h,n){var B,q,z,M=0,p=0,A=0,F,E,y,O=this.lights,K=O.directional.colors,U=O.directional.positions,W=O.point.colors,P=O.point.positions,da=0,X=0;B=0;for(q=n.length;B0){c.bindBuffer(c.ARRAY_BUFFER,h.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,ia,B)}if(z){c.bindBuffer(c.ELEMENT_ARRAY_BUFFER, +h.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,L,B);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,h.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,J,B)}};this.setLineBuffers=function(h,n,B,q){var z,M,p=h.vertices,A=p.length,F=h.__vertexArray,E=h.__lineArray;if(B)for(B=0;B0?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+E.maxDirLights,"#define MAX_POINT_LIGHTS "+E.maxPointLights, +E.map?"#define USE_MAP":"",E.env_map?"#define USE_ENVMAP":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"].join("\n");c.attachShader(O,f("fragment",K+A));c.attachShader(O,f("vertex",E+y));c.linkProgram(O);c.getProgramParameter(O,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+ +c.getProgramParameter(O,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");O.uniforms={};O.attributes={};q.program=O;A=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(p in q.uniforms)A.push(p);p=q.program;y=0;for(O=A.length;y=0){c.bindBuffer(c.ARRAY_BUFFER,z.__webGLNormalBuffer);c.vertexAttribPointer(F.normal,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(F.normal)}if(F.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,z.__webGLTangentBuffer); +c.vertexAttribPointer(F.tangent,4,c.FLOAT,false,0,0);c.enableVertexAttribArray(F.tangent)}if(F.uv>=0)if(z.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,z.__webGLUVBuffer);c.vertexAttribPointer(F.uv,2,c.FLOAT,false,0,0);c.enableVertexAttribArray(F.uv)}else c.disableVertexAttribArray(F.uv);if(q.wireframe||q instanceof THREE.LineBasicMaterial){F=q.wireframe_linewidth!==undefined?q.wireframe_linewidth:q.linewidth!==undefined?q.linewidth:1;q=q instanceof THREE.LineBasicMaterial&&M.type==THREE.LineStrip? +c.LINE_STRIP:c.LINES;c.lineWidth(F);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,z.__webGLLineBuffer);c.drawElements(q,z.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,z.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,z.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(h,n,B,q,z,M,p){var A,F,E,y,O;E=0;for(y=q.materials.length;E=0;B--){q=h.__webGLObjects[B].object;n==q&&h.__webGLObjects.splice(B,1)}};this.setupMatrices=function(h,n){h.autoUpdateMatrix&& +h.updateMatrix();t.multiply(n.matrix,h.matrix);u.set(t.flatten());D=THREE.Matrix4.makeInvert3x3(t).transpose();C.set(D.m);H.set(h.matrix.flatten())};this.loadMatrices=function(h){c.uniformMatrix4fv(h.uniforms.viewMatrix,false,o);c.uniformMatrix4fv(h.uniforms.modelViewMatrix,false,u);c.uniformMatrix4fv(h.uniforms.projectionMatrix,false,w);c.uniformMatrix3fv(h.uniforms.normalMatrix,false,C);c.uniformMatrix4fv(h.uniforms.objectMatrix,false,H)};this.loadCamera=function(h,n){c.uniform3f(h.uniforms.cameraPosition, +n.position.x,n.position.y,n.position.z)};this.setBlending=function(h){switch(h){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE);break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(h,n){if(h){!n||n=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(h=="back")c.cullFace(c.BACK);else h=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK); +c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)};this.supportsVertexTextures=function(){return c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}}; THREE.Snippets={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, 1.0 ), fogFactor );\n#endif",envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube env_map;\nuniform int combine;\n#endif", envmap_fragment:"#ifdef USE_ENVMAP\ncubeColor = textureCube( env_map, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = mix( gl_FragColor, cubeColor, reflectivity );\n} else {\ngl_FragColor = gl_FragColor * cubeColor;\n}\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refraction_ratio;\nuniform bool useRefract;\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nif ( useRefract ) {\nvReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refraction_ratio );\n} else {\nvReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );\n}\n#endif", map_pars_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\n#endif",map_fragment:"#ifdef USE_MAP\nmapColor = texture2D( map, vUv );\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv;\n#endif",lights_pars_vertex:"uniform bool enableLighting;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n#ifdef PHONG\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\n#endif", @@ -200,50 +201,57 @@ shininess:{type:"f",value:30}}]),fragment_shader:["uniform vec3 color;\nuniform "gl_FragColor = mapColor * totalLight * vec4( vLightWeighting, 1.0 );",THREE.Snippets.envmap_fragment,THREE.Snippets.fog_fragment,"}"].join("\n"),vertex_shader:["#define PHONG\nvarying vec3 vLightWeighting;\nvarying vec3 vViewPosition;\nvarying vec3 vNormal;",THREE.Snippets.map_pars_vertex,THREE.Snippets.envmap_pars_vertex,THREE.Snippets.lights_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.Snippets.map_vertex,THREE.Snippets.envmap_vertex,"#ifndef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\n#endif\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 transformedNormal = normalize( normalMatrix * normal );\nvNormal = transformedNormal;", THREE.Snippets.lights_vertex,"gl_Position = projectionMatrix * mvPosition;\n}"].join("\n")}};THREE.RenderableObject=function(){this.z=this.object=null};THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[];this.faceMaterials=this.meshMaterials=null;this.overdraw=false;this.uvs=[null,null,null]}; THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.materials=null};THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.materials=null}; -var GeometryUtils={merge:function(a,b){var d=b instanceof THREE.Mesh,e=a.vertices.length,f=d?b.geometry:b,h=a.vertices,j=f.vertices,c=a.faces,i=f.faces,k=a.uvs;f=f.uvs;d&&b.autoUpdateMatrix&&b.updateMatrix();for(var r=0,z=j.length;r= 0.0 )\npointSpecularWeight = pow( pointDotNormalHalf, uShininess );\npointDiffuse += vec4( uDiffuseColor, 1.0 ) * pointDiffuseWeight;\npointSpecular += vec4( uSpecularColor, 1.0 ) * pointSpecularWeight;\nvec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec4 lDirection = viewMatrix * vec4( uDirLightPos, 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nvec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );\nfloat dirDotNormalHalf = dot( normal, dirHalfVector );\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\nfloat dirSpecularWeight = 0.0;\nif ( dirDotNormalHalf >= 0.0 )\ndirSpecularWeight = pow( dirDotNormalHalf, uShininess );\ndirDiffuse += vec4( uDiffuseColor, 1.0 ) * dirDiffuseWeight;\ndirSpecular += vec4( uSpecularColor, 1.0 ) * dirSpecularWeight;\nvec4 totalLight = vec4( uAmbientLightColor * uAmbientColor, 1.0 );\ntotalLight += vec4( uDirLightColor, 1.0 ) * ( dirDiffuse + dirSpecular );\ntotalLight += vec4( uPointLightColor, 1.0 ) * ( pointDiffuse + pointSpecular );\ngl_FragColor = vec4( totalLight.xyz * aoTex * diffuseTex, 1.0 );\n}", vertex_shader:"attribute vec4 tangent;\nuniform vec3 uPointLightPos;\n#ifdef VERTEX_TEXTURES\nuniform sampler2D tDisplacement;\nuniform float uDisplacementScale;\nuniform float uDisplacementBias;\n#endif\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vPointLightVector;\nvarying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalize( normalMatrix * normal );\nvTangent = normalize( normalMatrix * tangent.xyz );\nvBinormal = cross( vNormal, vTangent ) * tangent.w;\nvBinormal = normalize( vBinormal );\nvUv = uv;\nvec4 lPosition = viewMatrix * vec4( uPointLightPos, 1.0 );\nvPointLightVector = normalize( lPosition.xyz - mvPosition.xyz );\n#ifdef VERTEX_TEXTURES\nvec3 dv = texture2D( tDisplacement, uv ).xyz;\nfloat df = uDisplacementScale * dv.x + uDisplacementBias;\nvec4 displacedPosition = vec4( vNormal.xyz * df, 0.0 ) + mvPosition;\ngl_Position = projectionMatrix * displacedPosition;\n#else\ngl_Position = projectionMatrix * mvPosition;\n#endif\n}"}, cube:{uniforms:{tCube:{type:"t",value:1,texture:null}},vertex_shader:"varying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragment_shader:"uniform samplerCube tCube;\nvarying vec3 vViewPosition;\nvoid main() {\nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( - wPos.x, wPos.yz ) );\n}"},basic:{uniforms:{}, -vertex_shader:"void main() {\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragment_shader:"void main() {\ngl_FragColor = vec4(1.0, 0.0, 0.0, 0.5);\n}"}}},Cube=function(a,b,d,e,f,h,j,c){function i(y,H,p,I,l,g,m,w){var o,v,J=e||1,s=f||1,A=J+1,C=s+1,B=l/2,t=g/2;l=l/J;var L=g/s,F=k.vertices.length;if(y=="x"&&H=="y"||y=="y"&&H=="x")o="z";else if(y=="x"&&H=="z"||y=="z"&&H=="x")o="y";else if(y=="z"&&H=="y"||y=="y"&&H=="z")o="x";for(v=0;v0||(r=this.vertices.push(new THREE.Vertex(new THREE.Vector3(z,c,n)))-1);k.push(r)}b.push(k)}var u,x,y;f=b.length;for(d=0;d0)for(e=0;e1){u=this.vertices[j].position.clone(); -x=this.vertices[i].position.clone();y=this.vertices[k].position.clone();u.normalize();x.normalize();y.normalize();this.faces.push(new THREE.Face3(j,i,k,[new THREE.Vector3(u.x,u.y,u.z),new THREE.Vector3(x.x,x.y,x.z),new THREE.Vector3(y.x,y.y,y.z)]));this.uvs.push([r,z,H])}}}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.sortFacesByMaterial();this.boundingSphere={radius:a}};Sphere.prototype=new THREE.Geometry;Sphere.prototype.constructor=Sphere; -function LathedObject(a,b,d){THREE.Geometry.call(this);b=b||12;d=d||2*Math.PI;b=d/b;for(var e=[],f=[],h=[],j=[],c=0;c0||(t=this.vertices.push(new THREE.Vertex(new THREE.Vector3(D,c,o)))-1);l.push(t)}b.push(l)}var u,w,C;f=b.length;for(d=0;d0)for(e=0;e1){u=this.vertices[k].position.clone(); +w=this.vertices[j].position.clone();C=this.vertices[l].position.clone();u.normalize();w.normalize();C.normalize();this.faces.push(new THREE.Face3(k,j,l,[new THREE.Vector3(u.x,u.y,u.z),new THREE.Vector3(w.x,w.y,w.z),new THREE.Vector3(C.x,C.y,C.z)]));this.uvs.push([t,D,H])}}}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.sortFacesByMaterial();this.boundingSphere={radius:a}};Sphere.prototype=new THREE.Geometry;Sphere.prototype.constructor=Sphere; +var Torus=function(a,b,d,e){this.radius=a||100;this.tube=b||40;this.segmentsR=d||8;this.segmentsT=e||6;a=[];THREE.Geometry.call(this);for(b=0;b<=this.segmentsR;++b)for(d=0;d<=this.segmentsT;++d){e=d/this.segmentsT*2*Math.PI;var f=b/this.segmentsR*2*Math.PI;this.vertices.push(new THREE.Vertex(new THREE.Vector3((this.radius+this.tube*Math.cos(f))*Math.cos(e),(this.radius+this.tube*Math.cos(f))*Math.sin(e),this.tube*Math.sin(f))));a.push([d/this.segmentsT,1-b/this.segmentsR])}for(b=1;b<=this.segmentsR;++b)for(d= +1;d<=this.segmentsT;++d){e=(this.segmentsT+1)*b+d;f=(this.segmentsT+1)*b+d-1;var g=(this.segmentsT+1)*(b-1)+d-1,k=(this.segmentsT+1)*(b-1)+d;this.faces.push(new THREE.Face4(e,f,g,k));this.uvs.push([new THREE.UV(a[e][0],a[e][1]),new THREE.UV(a[f][0],a[f][1]),new THREE.UV(a[g][0],a[g][1]),new THREE.UV(a[k][0],a[k][1])])}delete a;this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.sortFacesByMaterial()};Torus.prototype=new THREE.Geometry;Torus.prototype.constructor=Torus; +function LathedObject(a,b,d){THREE.Geometry.call(this);b=b||12;d=d||2*Math.PI;b=d/b;for(var e=[],f=[],g=[],k=[],c=0;c>7)-127;E=($&127)<<16|W<<8|E;if(E==0&&ga==-127)return 0;return(1-2*(da>>7))*(1+E*Math.pow(2,-23))*Math.pow(2,ga)}function c(q,G){var E=r(q,G),W=r(q,G+1),$=r(q,G+2);return(r(q,G+3)<<24)+($<<16)+(W<<8)+E}function i(q,G){var E=r(q,G);return(r(q,G+1)<<8)+E}function k(q,G){var E=r(q,G);return E>127?E-256:E}function r(q,G){return q.charCodeAt(G)&255}function z(q){var G,E,W;G= -c(a,q);E=c(a,q+w);W=c(a,q+o);q=i(a,q+v);THREE.Loader.prototype.f3(p,G,E,W,q)}function n(q){var G,E,W,$,da,ga;G=c(a,q);E=c(a,q+w);W=c(a,q+o);$=i(a,q+v);da=c(a,q+J);ga=c(a,q+s);q=c(a,q+A);THREE.Loader.prototype.f3n(p,g,G,E,W,$,da,ga,q)}function u(q){var G,E,W,$;G=c(a,q);E=c(a,q+C);W=c(a,q+B);$=c(a,q+t);q=i(a,q+L);THREE.Loader.prototype.f4(p,G,E,W,$,q)}function x(q){var G,E,W,$,da,ga,na,pa;G=c(a,q);E=c(a,q+C);W=c(a,q+B);$=c(a,q+t);da=i(a,q+L);ga=c(a,q+F);na=c(a,q+R);pa=c(a,q+T);q=c(a,q+M);THREE.Loader.prototype.f4n(p, -g,G,E,W,$,da,ga,na,pa,q)}function y(q){var G,E;G=c(a,q);E=c(a,q+aa);q=c(a,q+U);THREE.Loader.prototype.uv3(p,m[G*2],m[G*2+1],m[E*2],m[E*2+1],m[q*2],m[q*2+1])}function H(q){var G,E,W;G=c(a,q);E=c(a,q+O);W=c(a,q+Q);q=c(a,q+Z);THREE.Loader.prototype.uv4(p,m[G*2],m[G*2+1],m[E*2],m[E*2+1],m[W*2],m[W*2+1],m[q*2],m[q*2+1])}var p=this,I=0,l,g=[],m=[],w,o,v,J,s,A,C,B,t,L,F,R,T,M,aa,U,O,Q,Z,V,D,P,S,fa,ea;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(p,e,h);l={signature:a.substr(I,8),header_bytes:r(a, -I+8),vertex_coordinate_bytes:r(a,I+9),normal_coordinate_bytes:r(a,I+10),uv_coordinate_bytes:r(a,I+11),vertex_index_bytes:r(a,I+12),normal_index_bytes:r(a,I+13),uv_index_bytes:r(a,I+14),material_index_bytes:r(a,I+15),nvertices:c(a,I+16),nnormals:c(a,I+16+4),nuvs:c(a,I+16+8),ntri_flat:c(a,I+16+12),ntri_smooth:c(a,I+16+16),ntri_flat_uv:c(a,I+16+20),ntri_smooth_uv:c(a,I+16+24),nquad_flat:c(a,I+16+28),nquad_smooth:c(a,I+16+32),nquad_flat_uv:c(a,I+16+36),nquad_smooth_uv:c(a,I+16+40)};I+=l.header_bytes; -w=l.vertex_index_bytes;o=l.vertex_index_bytes*2;v=l.vertex_index_bytes*3;J=l.vertex_index_bytes*3+l.material_index_bytes;s=l.vertex_index_bytes*3+l.material_index_bytes+l.normal_index_bytes;A=l.vertex_index_bytes*3+l.material_index_bytes+l.normal_index_bytes*2;C=l.vertex_index_bytes;B=l.vertex_index_bytes*2;t=l.vertex_index_bytes*3;L=l.vertex_index_bytes*4;F=l.vertex_index_bytes*4+l.material_index_bytes;R=l.vertex_index_bytes*4+l.material_index_bytes+l.normal_index_bytes;T=l.vertex_index_bytes*4+ -l.material_index_bytes+l.normal_index_bytes*2;M=l.vertex_index_bytes*4+l.material_index_bytes+l.normal_index_bytes*3;aa=l.uv_index_bytes;U=l.uv_index_bytes*2;O=l.uv_index_bytes;Q=l.uv_index_bytes*2;Z=l.uv_index_bytes*3;h=l.vertex_index_bytes*3+l.material_index_bytes;ea=l.vertex_index_bytes*4+l.material_index_bytes;V=l.ntri_flat*h;D=l.ntri_smooth*(h+l.normal_index_bytes*3);P=l.ntri_flat_uv*(h+l.uv_index_bytes*3);S=l.ntri_smooth_uv*(h+l.normal_index_bytes*3+l.uv_index_bytes*3);fa=l.nquad_flat*ea;h= -l.nquad_smooth*(ea+l.normal_index_bytes*4);ea=l.nquad_flat_uv*(ea+l.uv_index_bytes*4);I+=function(q){var G,E,W,$=l.vertex_coordinate_bytes*3,da=q+l.nvertices*$;for(q=q;q>7)-127;J=(ca&127)<<16|Z<<8|J;if(J==0&&ja==-127)return 0;return(1-2*(ga>>7))*(1+J*Math.pow(2,-23))*Math.pow(2,ja)}function c(x,L){var J=t(x,L),Z=t(x,L+1),ca=t(x,L+2);return(t(x,L+3)<<24)+(ca<<16)+(Z<<8)+J}function j(x,L){var J=t(x,L);return(t(x,L+1)<<8)+J}function l(x,L){var J=t(x,L);return J>127?J-256:J}function t(x,L){return x.charCodeAt(L)&255}function D(x){var L, +J,Z;L=c(a,x);J=c(a,x+B);Z=c(a,x+q);x=j(a,x+z);THREE.Loader.prototype.f3(v,L,J,Z,x)}function o(x){var L,J,Z,ca,ga,ja;L=c(a,x);J=c(a,x+B);Z=c(a,x+q);ca=j(a,x+z);ga=c(a,x+M);ja=c(a,x+p);x=c(a,x+A);THREE.Loader.prototype.f3n(v,h,L,J,Z,ca,ga,ja,x)}function u(x){var L,J,Z,ca;L=c(a,x);J=c(a,x+F);Z=c(a,x+E);ca=c(a,x+y);x=j(a,x+O);THREE.Loader.prototype.f4(v,L,J,Z,ca,x)}function w(x){var L,J,Z,ca,ga,ja,qa,sa;L=c(a,x);J=c(a,x+F);Z=c(a,x+E);ca=c(a,x+y);ga=j(a,x+O);ja=c(a,x+K);qa=c(a,x+U);sa=c(a,x+W);x=c(a,x+ +P);THREE.Loader.prototype.f4n(v,h,L,J,Z,ca,ga,ja,qa,sa,x)}function C(x){var L,J;L=c(a,x);J=c(a,x+da);x=c(a,x+X);THREE.Loader.prototype.uv3(v,n[L*2],n[L*2+1],n[J*2],n[J*2+1],n[x*2],n[x*2+1])}function H(x){var L,J,Z;L=c(a,x);J=c(a,x+R);Z=c(a,x+T);x=c(a,x+ba);THREE.Loader.prototype.uv4(v,n[L*2],n[L*2+1],n[J*2],n[J*2+1],n[Z*2],n[Z*2+1],n[x*2],n[x*2+1])}var v=this,I=0,m,h=[],n=[],B,q,z,M,p,A,F,E,y,O,K,U,W,P,da,X,R,T,ba,Y,G,S,V,ia,ha;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(v,e,g); +m={signature:a.substr(I,8),header_bytes:t(a,I+8),vertex_coordinate_bytes:t(a,I+9),normal_coordinate_bytes:t(a,I+10),uv_coordinate_bytes:t(a,I+11),vertex_index_bytes:t(a,I+12),normal_index_bytes:t(a,I+13),uv_index_bytes:t(a,I+14),material_index_bytes:t(a,I+15),nvertices:c(a,I+16),nnormals:c(a,I+16+4),nuvs:c(a,I+16+8),ntri_flat:c(a,I+16+12),ntri_smooth:c(a,I+16+16),ntri_flat_uv:c(a,I+16+20),ntri_smooth_uv:c(a,I+16+24),nquad_flat:c(a,I+16+28),nquad_smooth:c(a,I+16+32),nquad_flat_uv:c(a,I+16+36),nquad_smooth_uv:c(a, +I+16+40)};I+=m.header_bytes;B=m.vertex_index_bytes;q=m.vertex_index_bytes*2;z=m.vertex_index_bytes*3;M=m.vertex_index_bytes*3+m.material_index_bytes;p=m.vertex_index_bytes*3+m.material_index_bytes+m.normal_index_bytes;A=m.vertex_index_bytes*3+m.material_index_bytes+m.normal_index_bytes*2;F=m.vertex_index_bytes;E=m.vertex_index_bytes*2;y=m.vertex_index_bytes*3;O=m.vertex_index_bytes*4;K=m.vertex_index_bytes*4+m.material_index_bytes;U=m.vertex_index_bytes*4+m.material_index_bytes+m.normal_index_bytes; +W=m.vertex_index_bytes*4+m.material_index_bytes+m.normal_index_bytes*2;P=m.vertex_index_bytes*4+m.material_index_bytes+m.normal_index_bytes*3;da=m.uv_index_bytes;X=m.uv_index_bytes*2;R=m.uv_index_bytes;T=m.uv_index_bytes*2;ba=m.uv_index_bytes*3;g=m.vertex_index_bytes*3+m.material_index_bytes;ha=m.vertex_index_bytes*4+m.material_index_bytes;Y=m.ntri_flat*g;G=m.ntri_smooth*(g+m.normal_index_bytes*3);S=m.ntri_flat_uv*(g+m.uv_index_bytes*3);V=m.ntri_smooth_uv*(g+m.normal_index_bytes*3+m.uv_index_bytes* +3);ia=m.nquad_flat*ha;g=m.nquad_smooth*(ha+m.normal_index_bytes*4);ha=m.nquad_flat_uv*(ha+m.uv_index_bytes*4);I+=function(x){var L,J,Z,ca=m.vertex_coordinate_bytes*3,ga=x+m.nvertices*ca;for(x=x;x + + + three.js - scene loader test + + + + + +
+ three.js - scene loader test +
+ +

+
+		
+		
+
+		
+
+	
+
diff --git a/examples/scenes/test_scene.js b/examples/scenes/test_scene.js
new file mode 100644
index 00000000..9079c0af
--- /dev/null
+++ b/examples/scenes/test_scene.js
@@ -0,0 +1,287 @@
+var scene = {
+	
+"objects": 
+{	
+	"cube1" : {
+		"geometry" : "cube",
+		"materials": [ "lambert_red" ],
+		"position" : [ 0, 0, 0 ],
+		"rotation" : [ 0, -0.3, 0 ],
+		"scale"	   : [ 1, 1, 1 ],
+		"visible"  : true
+	},
+
+	"cube2" : {
+		"geometry" : "cube",
+		"materials": [ "basic_black" ],
+		"position" : [ 0, 0, 0 ],
+		"rotation" : [ 0, -0.3, 0 ],
+		"scale"	   : [ 2, 2, 2 ],
+		"visible"  : true
+	},
+
+	"sphere" : {
+		"geometry" : "sphere",
+		"materials": [ "lambert_green" ],
+		"position" : [ -20, -5, 15 ],
+		"rotation" : [ 0, 0, 0 ],
+		"scale"	   : [ 1, 1, 1 ],
+		"visible"  : true
+	},
+
+	"torus" : {
+		"geometry" : "torus",
+		"materials": [ "phong_orange" ],
+		"position" : [ 0, 5, -50 ],
+		"rotation" : [ 0, 0, 0 ],
+		"scale"	   : [ 2, 2, 2 ],
+		"visible"  : true
+	},
+
+	"cone" : {
+		"geometry" : "cone",
+		"materials": [ "lambert_blue" ],
+		"position" : [ -50, 40, -50 ],
+		"rotation" : [ 1.57, 0, 0 ],
+		"scale"	   : [ 1, 1, 1 ],
+		"visible"  : true
+	},
+
+	"cylinder" : {
+		"geometry" : "cylinder",
+		"materials": [ "lambert_blue" ],
+		"position" : [ 50, 40, -50 ],
+		"rotation" : [ 1.57, 0, 0 ],
+		"scale"	   : [ 1, 1, 1 ],
+		"visible"  : true
+	},
+	
+	"veyron" : {
+		"geometry" : "veyron",
+		"materials": [ "face" ],
+		"position" : [ 40, -1, 0 ],
+		"rotation" : [ 0, 0.3, 0 ],
+		"scale"	   : [ 0.25, 0.25, 0.25 ],
+		"visible"  : true
+	},
+
+	"walt" : {
+		"geometry" : "WaltHead",
+		"materials": [ "phong_white" ],
+		"position" : [ -45, 10, 0 ],
+		"rotation" : [ 0, 0, 0 ],
+		"scale"	   : [ 0.5, 0.5, 0.5 ],
+		"visible"  : true
+	},
+	
+	"ground" : {
+		"geometry" : "plane",
+		"materials": [ "basic_gray" ],
+		"position" : [ 0, -10, 0 ],
+		"rotation" : [ 1.57, 0, 0 ],
+		"scale"	   : [ 100, 100, 100 ],
+		"visible"  : true
+	}	
+	
+},
+	
+"geometries":
+{
+	"cube": {
+		"type"  : "cube",
+		"width" : 10, 
+		"height": 10,
+		"depth" : 10, 
+		"segments_width"  : 1, 
+		"segments_height" : 1,
+		"flipped" : false, 
+		"sides"   : { "px": true, "nx": true, "py": true, "ny": true, "pz": true, "nz": true }
+	},
+
+	"plane": {
+		"type"   : "plane",
+		"width"  : 10, 
+		"height" : 10,
+		"segments_width"  : 50, 
+		"segments_height" : 50
+	},	
+
+	"sphere": {
+		"type"    : "sphere",
+		"radius"  : 5, 
+		"segments_width"  : 32, 
+		"segments_height" : 16
+	},
+ 
+	"torus": {
+		"type"    : "torus",
+		"radius"  : 5,
+		"tube"	  : 2,
+		"segmentsR" : 16, 
+		"segmentsT" : 32
+	},
+	
+	"cylinder": {
+		"type"    : "cylinder",
+		"numSegs"  : 32, 
+		"topRad"   : 5, 
+		"botRad"   : 5,
+		"height"   : 50,
+		"topOffset": 0,
+		"botOffset": 0
+	},
+
+	"cone": {
+		"type"    : "cylinder",
+		"numSegs"  : 32, 
+		"topRad"   : 0, 
+		"botRad"   : 5,
+		"height"   : 50,
+		"topOffset": 0,
+		"botOffset": 0
+	},
+	
+	"WaltHead": {
+		"type": "bin_mesh",
+		"url" : "obj/walt/WaltHead_bin.js"
+	},
+
+	"veyron": {
+		"type": "bin_mesh",
+		"url" : "obj/veyron/VeyronNoUv_bin.js"
+	},
+
+	"TextureCube": {
+		"type": "ascii_mesh",
+		"url" : "obj/textureTest/textureTest_baked.js"
+	},
+	
+	
+},
+	
+"materials":
+{
+	"basic_red": {
+		"type": "MeshBasicMaterial",
+		"parameters": { color: 0xff0000, wireframe: true } 
+	},
+
+	"basic_green": {
+		"type": "MeshBasicMaterial",
+		"parameters": { color: 0x007711, wireframe: true } 
+	},
+
+	"basic_gray": {
+		"type": "MeshBasicMaterial",
+		"parameters": { color: 0x666666, wireframe: true } 
+	},
+
+	"basic_black": {
+		"type": "MeshBasicMaterial",
+		"parameters": { color: 0x000000, wireframe: true } 
+	},
+	
+	"basic_blue": {
+		"type": "MeshBasicMaterial",
+		"parameters": { color: 0x0000ff, wireframe: true } 
+	},
+	
+	"lambert_red": {
+		"type": "MeshLambertMaterial",
+		"parameters": { color: 0xff0000 } 
+	},
+	
+	"lambert_green": {
+		"type": "MeshLambertMaterial",
+		"parameters": { color: 0x007711 } 
+	},
+
+	"lambert_blue": {
+		"type": "MeshLambertMaterial",
+		"parameters": { color: 0x0055aa } 
+	},
+	
+	"phong_white": {
+		"type": "MeshPhongMaterial",
+		"parameters": { color: 0xaaaaaa } 
+	},
+
+	"phong_orange": {
+		"type": "MeshPhongMaterial",
+		"parameters": { color:0x000000, specular: 0xaa5500 } 
+	},
+	
+	"face": {
+		"type": "MeshFaceMaterial",
+		"parameters": {}
+	}
+	
+},
+
+"cameras":
+{
+	"cam1": {
+		"type"  : "perspective",
+		"fov"   : 50,
+		"aspect": 1.33333,
+		"near"  : 1,
+		"far"   : 1000,
+		"position": [0,0,100],
+		"target"  : [0,0,0]
+	},
+
+	"cam2": {
+		"type"  : "ortho",
+		"left"  : 0,
+		"right" : 1024,
+		"top"   : 0,
+		"bottom": 1024,
+		"near"  : 1,
+		"far"   : 1000,
+		"position": [0,0,0],
+		"target"  : [0,0,0]
+	}
+
+},
+
+"lights":
+{
+	"light1": {
+		"type"		 : "directional",
+		"direction"	 : [0,1,1],
+		"color" 	 : [1,1,1]
+	},
+
+	"light2": {
+		"type"	  : "point",
+		"position": [0,0,0],
+		"color"   : [1,1,1]
+	}
+	
+},
+
+"fogs":
+{
+	"basic": {
+		"type" : "linear",
+		"color": [1,0,0],
+		"near" : 1,
+		"far"  : 1000
+	},
+	
+	"exponential": {
+		"type"    : "exp2",
+		"color"   : [1,1,1],
+		"density" : 0.005,
+	}
+},
+	
+"defaults" : 
+{
+	"camera": "cam1",
+	"fog"	: "exponential"
+}
+
+};
+
+postMessage( scene );
\ No newline at end of file
diff --git a/src/extras/SceneUtils.js b/src/extras/SceneUtils.js
index 1879e6e9..525ef5cb 100644
--- a/src/extras/SceneUtils.js
+++ b/src/extras/SceneUtils.js
@@ -1,4 +1,243 @@
 var SceneUtils = {
+	
+	loadScene : function( url, callback ) {
+
+		var dg, dm, dd, dl, dc, df, f,
+			g, o, m, l, p, c, t,
+			geometry, material, camera, fog, materials,
+			loader, callback_model,
+			worker = new Worker( url );
+
+		worker.onmessage = function( event ) {
+
+			function handle_objects() {
+				
+				for( dd in data.objects ) {
+					
+					if ( !result.objects[ dd ] ) {
+						
+						o = data.objects[ dd ];
+						
+						geometry = result.geometries[ o.geometry ];
+						
+						if ( geometry ) {
+							
+							materials = [];
+							for( i = 0; i < o.materials.length; i++ ) {
+								
+								materials[ i ] = result.materials[ o.materials[i] ];
+								
+							}
+							
+							p = o.position;
+							r = o.rotation;
+							s = o.scale;
+							
+							object = new THREE.Mesh( geometry, materials );
+							object.position.set( p[0], p[1], p[2] );
+							object.rotation.set( r[0], r[1], r[2] );
+							object.scale.set( s[0], s[1], s[2] );
+							object.visible = o.visible;
+							
+							result.scene.addObject( object );
+							
+							result.objects[ dd ] = object;
+							
+						}
+						
+					}
+					
+				}
+			};
+			
+			function handle_mesh( geo, id ) {
+				
+				result.geometries[ id ] = geo; 
+				handle_objects();
+				
+			};
+			
+			function create_callback( id ) {
+				
+				return function( geo ) { handle_mesh( geo, id ); }
+				
+			}
+			
+			var data = event.data;
+			
+			var result = {
+				
+				scene: new THREE.Scene(),
+				geometries: {},
+				materials: {},
+				objects: {},
+				cameras: {},
+				lights: {},
+				fogs: {}
+			
+			};
+			
+			loader = new THREE.Loader();
+			
+			// geometries	
+			
+			for( dg in data.geometries ) {
+				
+				g = data.geometries[ dg ];
+				
+				if ( g.type == "cube" ) {
+					
+					geometry = new Cube( g.width, g.height, g.depth, g.segments_width, g.segments_height, null, g.flipped, g.sides );
+					result.geometries[ dg ] = geometry;
+					
+				} else if ( g.type == "plane" ) {
+					
+					geometry = new Plane( g.width, g.height, g.segments_width, g.segments_height );
+					result.geometries[ dg ] = geometry;
+					
+				} else if ( g.type == "sphere" ) {
+					
+					geometry = new Sphere( g.radius, g.segments_width, g.segments_height );
+					result.geometries[ dg ] = geometry;
+					
+				} else if ( g.type == "cylinder" ) {
+					
+					geometry = new Cylinder( g.numSegs, g.topRad, g.botRad, g.height, g.topOffset, g.botOffset );
+					result.geometries[ dg ] = geometry;
+
+				} else if ( g.type == "torus" ) {
+					
+					geometry = new Torus( g.radius, g.tube, g.segmentsR, g.segmentsT );
+					result.geometries[ dg ] = geometry;
+					
+				} else if ( g.type == "bin_mesh" ) {
+					
+					loader.loadBinary( { model: g.url, 
+										 callback: create_callback( dg )
+										} );
+					
+				} else if ( g.type == "ascii_mesh" ) {
+					
+					loader.loadAscii( { model: g.url, 
+										callback: create_callback( dg )
+										} );
+					
+				}
+				
+			}
+
+			// materials
+			
+			for( dm in data.materials ) {
+				
+				m = data.materials[ dm ];
+				
+				material = new THREE[ m.type ]( m.parameters );
+				result.materials[ dm ] = material;
+				
+			}
+			
+			// objects
+			
+			handle_objects();
+			
+			
+			// lights
+			
+			for( dl in data.lights ) {
+				
+				l = data.lights[ dl ];
+				
+				if ( l.type == "directional" ) {
+				
+					p = l.direction;
+					
+					light = new THREE.DirectionalLight();
+					light.position.set( p[0], p[1], p[2] );
+					light.position.normalize();
+					
+				} else if ( l.type == "point" ) {
+				
+					p = l.position;
+					
+					light = new THREE.PointLight();
+					light.position.set( p[0], p[1], p[2] );
+					
+				}
+				
+				c = l.color;
+				light.color.setRGB( c[0], c[1], c[2] );
+				
+				result.scene.addLight( light );
+				
+				result.lights[ dl ] = light;
+				
+			}
+			
+			// cameras
+			
+			for( dc in data.cameras ) {
+				
+				c = data.cameras[ dc ];
+				
+				if ( c.type == "perspective" ) {
+					
+					camera = new THREE.Camera( c.fov, c.aspect, c.near, c.far );
+					
+				} else if ( c.type == "ortho" ) {
+					
+					camera = new THREE.Camera();
+					camera.projectionMatrix = THREE.Matrix4.makeOrtho( c.left, c.right, c.top, c.bottom, c.near, c.far );
+					
+				}
+				
+				p = c.position;
+				t = c.target;
+				camera.position.set( p[0], p[1], p[2] );
+				camera.target.position.set( t[0], t[1], t[2] );
+				
+				result.cameras[ dc ] = camera;
+				
+			}
+
+			// fogs
+			
+			for( df in data.fogs ) {
+				
+				f = data.fogs[ df ];
+				
+				if ( f.type == "linear" ) {
+					
+					fog = new THREE.Fog( 0x000000, f.near, f.far );
+				
+				} else if ( f.type == "exp2" ) {
+					
+					fog = new THREE.FogExp2( 0x000000, f.density );
+					
+				}
+				
+				c = f.color;
+				fog.color.setRGB( c[0], c[1], c[2] );
+				
+				result.fogs[ df ] = fog;
+				
+			}
+			
+			result.currentCamera = result.cameras[ data.defaults.camera ];
+			
+			if ( result.fogs && data.defaults.fog ) {
+			
+				result.scene.fog = result.fogs[ data.defaults.fog ];
+				
+			}
+			
+			callback( result );
+
+		};
+
+		worker.postMessage( 0 );
+		
+	},
 
 	addMesh: function ( scene, geometry, scale, x, y, z, rx, ry, rz, material ) {
 
diff --git a/utils/build.py b/utils/build.py
index 6ad2a4b7..0e9d38e9 100644
--- a/utils/build.py
+++ b/utils/build.py
@@ -80,7 +80,9 @@ EXTRAS_FILES = [
 'extras/primitives/Cube.js',
 'extras/primitives/Cylinder.js',
 'extras/primitives/Plane.js',
-'extras/primitives/Sphere.js','extras/primitives/LathedObject.js',
+'extras/primitives/Sphere.js',
+'extras/primitives/Torus.js',
+'extras/primitives/LathedObject.js',
 'extras/io/Loader.js'
 ]