Browse Source

Fixed lights removal not being reflected in WebGLRenderer.

alteredq 14 years ago
parent
commit
9a9ed7cc85
5 changed files with 321 additions and 298 deletions
  1. 102 102
      build/Three.js
  2. 104 104
      build/ThreeDebug.js
  3. 78 78
      build/ThreeExtras.js
  4. 11 1
      examples/lights_test.html
  5. 26 13
      src/renderers/WebGLRenderer.js

+ 102 - 102
build/Three.js

@@ -13,32 +13,32 @@ THREE.Vector4=function(a,c,d,g){this.x=a||0;this.y=c||0;this.z=d||0;this.w=g||1}
 THREE.Vector4.prototype={set:function(a,c,d,g){this.x=a;this.y=c;this.z=d;this.w=g;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,c){this.x=a.x+c.x;this.y=a.y+c.y;this.z=a.z+c.z;this.w=a.w+c.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,c){this.x=a.x-c.x;this.y=a.y-c.y;this.z=a.z-c.z;this.w=a.w-c.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,c){this.x+=(a.x-this.x)*c;this.y+=(a.y-this.y)*c;this.z+=(a.z-this.z)*c;this.w+=(a.w-this.w)*c},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,c){this.origin=a||new THREE.Vector3;this.direction=c||new THREE.Vector3};
-THREE.Ray.prototype={intersectScene:function(a){var c,d,g=a.objects,i=[];a=0;for(c=g.length;a<c;a++){d=g[a];if(d instanceof THREE.Mesh)i=i.concat(this.intersectObject(d))}i.sort(function(l,b){return l.distance-b.distance});return i},intersectObject:function(a){function c(L,s,T,F){F=F.clone().subSelf(s);T=T.clone().subSelf(s);var P=L.clone().subSelf(s);L=F.dot(F);s=F.dot(T);F=F.dot(P);var f=T.dot(T);T=T.dot(P);P=1/(L*f-s*s);f=(f*F-s*T)*P;L=(L*T-s*F)*P;return f>0&&L>0&&f+L<1}var d,g,i,l,b,r,m,n,z,y,
-w,x=a.geometry,I=x.vertices,M=[];d=0;for(g=x.faces.length;d<g;d++){i=x.faces[d];y=this.origin.clone();w=this.direction.clone();l=a.matrix.multiplyVector3(I[i.a].position.clone());b=a.matrix.multiplyVector3(I[i.b].position.clone());r=a.matrix.multiplyVector3(I[i.c].position.clone());m=i instanceof THREE.Face4?a.matrix.multiplyVector3(I[i.d].position.clone()):null;n=a.rotationMatrix.multiplyVector3(i.normal.clone());z=w.dot(n);if(z<0){n=n.dot((new THREE.Vector3).sub(l,y))/z;y=y.addSelf(w.multiplyScalar(n));
+THREE.Ray.prototype={intersectScene:function(a){var c,d,g=a.objects,i=[];a=0;for(c=g.length;a<c;a++){d=g[a];if(d instanceof THREE.Mesh)i=i.concat(this.intersectObject(d))}i.sort(function(l,b){return l.distance-b.distance});return i},intersectObject:function(a){function c(L,s,T,F){F=F.clone().subSelf(s);T=T.clone().subSelf(s);var P=L.clone().subSelf(s);L=F.dot(F);s=F.dot(T);F=F.dot(P);var f=T.dot(T);T=T.dot(P);P=1/(L*f-s*s);f=(f*F-s*T)*P;L=(L*T-s*F)*P;return f>0&&L>0&&f+L<1}var d,g,i,l,b,r,m,o,z,y,
+w,x=a.geometry,I=x.vertices,M=[];d=0;for(g=x.faces.length;d<g;d++){i=x.faces[d];y=this.origin.clone();w=this.direction.clone();l=a.matrix.multiplyVector3(I[i.a].position.clone());b=a.matrix.multiplyVector3(I[i.b].position.clone());r=a.matrix.multiplyVector3(I[i.c].position.clone());m=i instanceof THREE.Face4?a.matrix.multiplyVector3(I[i.d].position.clone()):null;o=a.rotationMatrix.multiplyVector3(i.normal.clone());z=w.dot(o);if(z<0){o=o.dot((new THREE.Vector3).sub(l,y))/z;y=y.addSelf(w.multiplyScalar(o));
 if(i instanceof THREE.Face3){if(c(y,l,b,r)){i={distance:this.origin.distanceTo(y),point:y,face:i,object:a};M.push(i)}}else if(i instanceof THREE.Face4)if(c(y,l,b,m)||c(y,b,r,m)){i={distance:this.origin.distanceTo(y),point:y,face:i,object:a};M.push(i)}}}return M}};
-THREE.Rectangle=function(){function a(){l=g-c;b=i-d}var c,d,g,i,l,b,r=true;this.getX=function(){return c};this.getY=function(){return d};this.getWidth=function(){return l};this.getHeight=function(){return b};this.getLeft=function(){return c};this.getTop=function(){return d};this.getRight=function(){return g};this.getBottom=function(){return i};this.set=function(m,n,z,y){r=false;c=m;d=n;g=z;i=y;a()};this.addPoint=function(m,n){if(r){r=false;c=m;d=n;g=m;i=n}else{c=c<m?c:m;d=d<n?d:n;g=g>m?g:m;i=i>n?
-i:n}a()};this.add3Points=function(m,n,z,y,w,x){if(r){r=false;c=m<z?m<w?m:w:z<w?z:w;d=n<y?n<x?n:x:y<x?y:x;g=m>z?m>w?m:w:z>w?z:w;i=n>y?n>x?n:x:y>x?y:x}else{c=m<z?m<w?m<c?m:c:w<c?w:c:z<w?z<c?z:c:w<c?w:c;d=n<y?n<x?n<d?n:d:x<d?x:d:y<x?y<d?y:d:x<d?x:d;g=m>z?m>w?m>g?m:g:w>g?w:g:z>w?z>g?z:g:w>g?w:g;i=n>y?n>x?n>i?n:i:x>i?x:i:y>x?y>i?y:i:x>i?x:i}a()};this.addRectangle=function(m){if(r){r=false;c=m.getLeft();d=m.getTop();g=m.getRight();i=m.getBottom()}else{c=c<m.getLeft()?c:m.getLeft();d=d<m.getTop()?d:m.getTop();
+THREE.Rectangle=function(){function a(){l=g-c;b=i-d}var c,d,g,i,l,b,r=true;this.getX=function(){return c};this.getY=function(){return d};this.getWidth=function(){return l};this.getHeight=function(){return b};this.getLeft=function(){return c};this.getTop=function(){return d};this.getRight=function(){return g};this.getBottom=function(){return i};this.set=function(m,o,z,y){r=false;c=m;d=o;g=z;i=y;a()};this.addPoint=function(m,o){if(r){r=false;c=m;d=o;g=m;i=o}else{c=c<m?c:m;d=d<o?d:o;g=g>m?g:m;i=i>o?
+i:o}a()};this.add3Points=function(m,o,z,y,w,x){if(r){r=false;c=m<z?m<w?m:w:z<w?z:w;d=o<y?o<x?o:x:y<x?y:x;g=m>z?m>w?m:w:z>w?z:w;i=o>y?o>x?o:x:y>x?y:x}else{c=m<z?m<w?m<c?m:c:w<c?w:c:z<w?z<c?z:c:w<c?w:c;d=o<y?o<x?o<d?o:d:x<d?x:d:y<x?y<d?y:d:x<d?x:d;g=m>z?m>w?m>g?m:g:w>g?w:g:z>w?z>g?z:g:w>g?w:g;i=o>y?o>x?o>i?o:i:x>i?x:i:y>x?y>i?y:i:x>i?x:i}a()};this.addRectangle=function(m){if(r){r=false;c=m.getLeft();d=m.getTop();g=m.getRight();i=m.getBottom()}else{c=c<m.getLeft()?c:m.getLeft();d=d<m.getTop()?d:m.getTop();
 g=g>m.getRight()?g:m.getRight();i=i>m.getBottom()?i:m.getBottom()}a()};this.inflate=function(m){c-=m;d-=m;g+=m;i+=m;a()};this.minSelf=function(m){c=c>m.getLeft()?c:m.getLeft();d=d>m.getTop()?d:m.getTop();g=g<m.getRight()?g:m.getRight();i=i<m.getBottom()?i:m.getBottom();a()};this.instersects=function(m){return Math.min(g,m.getRight())-Math.max(c,m.getLeft())>=0&&Math.min(i,m.getBottom())-Math.max(d,m.getTop())>=0};this.empty=function(){r=true;i=g=d=c=0;a()};this.isEmpty=function(){return r};this.toString=
 function(){return"THREE.Rectangle ( left: "+c+", right: "+g+", top: "+d+", bottom: "+i+", width: "+l+", height: "+b+" )"}};THREE.Matrix3=function(){this.m=[]};THREE.Matrix3.prototype={transpose:function(){var a,c=this.m;a=c[1];c[1]=c[3];c[3]=a;a=c[2];c[2]=c[6];c[6]=a;a=c[5];c[5]=c[7];c[7]=a;return this}};
-THREE.Matrix4=function(a,c,d,g,i,l,b,r,m,n,z,y,w,x,I,M){this.n11=a||1;this.n12=c||0;this.n13=d||0;this.n14=g||0;this.n21=i||0;this.n22=l||1;this.n23=b||0;this.n24=r||0;this.n31=m||0;this.n32=n||0;this.n33=z||1;this.n34=y||0;this.n41=w||0;this.n42=x||0;this.n43=I||0;this.n44=M||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,c,d,g,i,l,b,r,m,n,z,y,w,x,I,M){this.n11=a;this.n12=c;this.n13=d;this.n14=g;this.n21=i;this.n22=l;this.n23=b;this.n24=r;this.n31=m;this.n32=n;this.n33=z;this.n34=y;this.n41=w;this.n42=x;this.n43=I;this.n44=M;return this},copy:function(a){this.n11=a.n11;this.n12=a.n12;this.n13=
+THREE.Matrix4=function(a,c,d,g,i,l,b,r,m,o,z,y,w,x,I,M){this.n11=a||1;this.n12=c||0;this.n13=d||0;this.n14=g||0;this.n21=i||0;this.n22=l||1;this.n23=b||0;this.n24=r||0;this.n31=m||0;this.n32=o||0;this.n33=z||1;this.n34=y||0;this.n41=w||0;this.n42=x||0;this.n43=I||0;this.n44=M||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,c,d,g,i,l,b,r,m,o,z,y,w,x,I,M){this.n11=a;this.n12=c;this.n13=d;this.n14=g;this.n21=i;this.n22=l;this.n23=b;this.n24=r;this.n31=m;this.n32=o;this.n33=z;this.n34=y;this.n41=w;this.n42=x;this.n43=I;this.n44=M;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,c,d){var g=THREE.Matrix4.__tmpVec1,i=THREE.Matrix4.__tmpVec2,l=THREE.Matrix4.__tmpVec3;l.sub(a,c).normalize();g.cross(d,l).normalize();i.cross(l,g).normalize();this.n11=g.x;this.n12=g.y;this.n13=g.z;this.n14=-g.dot(a);this.n21=i.x;this.n22=i.y;this.n23=i.z;this.n24=-i.dot(a);
 this.n31=l.x;this.n32=l.y;this.n33=l.z;this.n34=-l.dot(a);this.n43=this.n42=this.n41=0;this.n44=1;return this},multiplyVector3:function(a){var c=a.x,d=a.y,g=a.z,i=1/(this.n41*c+this.n42*d+this.n43*g+this.n44);a.x=(this.n11*c+this.n12*d+this.n13*g+this.n14)*i;a.y=(this.n21*c+this.n22*d+this.n23*g+this.n24)*i;a.z=(this.n31*c+this.n32*d+this.n33*g+this.n34)*i;return a},multiplyVector4:function(a){var c=a.x,d=a.y,g=a.z,i=a.w;a.x=this.n11*c+this.n12*d+this.n13*g+this.n14*i;a.y=this.n21*c+this.n22*d+this.n23*
-g+this.n24*i;a.z=this.n31*c+this.n32*d+this.n33*g+this.n34*i;a.w=this.n41*c+this.n42*d+this.n43*g+this.n44*i;return a},crossVector:function(a){var c=new THREE.Vector4;c.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;c.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;c.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;c.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return c},multiply:function(a,c){var d=a.n11,g=a.n12,i=a.n13,l=a.n14,b=a.n21,r=a.n22,m=a.n23,n=a.n24,z=a.n31,
-y=a.n32,w=a.n33,x=a.n34,I=a.n41,M=a.n42,L=a.n43,s=a.n44,T=c.n11,F=c.n12,P=c.n13,f=c.n14,p=c.n21,h=c.n22,e=c.n23,o=c.n24,j=c.n31,t=c.n32,q=c.n33,k=c.n34,u=c.n41,B=c.n42,v=c.n43,O=c.n44;this.n11=d*T+g*p+i*j+l*u;this.n12=d*F+g*h+i*t+l*B;this.n13=d*P+g*e+i*q+l*v;this.n14=d*f+g*o+i*k+l*O;this.n21=b*T+r*p+m*j+n*u;this.n22=b*F+r*h+m*t+n*B;this.n23=b*P+r*e+m*q+n*v;this.n24=b*f+r*o+m*k+n*O;this.n31=z*T+y*p+w*j+x*u;this.n32=z*F+y*h+w*t+x*B;this.n33=z*P+y*e+w*q+x*v;this.n34=z*f+y*o+w*k+x*O;this.n41=I*T+M*p+
-L*j+s*u;this.n42=I*F+M*h+L*t+s*B;this.n43=I*P+M*e+L*q+s*v;this.n44=I*f+M*o+L*k+s*O;return this},multiplySelf:function(a){var c=this.n11,d=this.n12,g=this.n13,i=this.n14,l=this.n21,b=this.n22,r=this.n23,m=this.n24,n=this.n31,z=this.n32,y=this.n33,w=this.n34,x=this.n41,I=this.n42,M=this.n43,L=this.n44,s=a.n11,T=a.n21,F=a.n31,P=a.n41,f=a.n12,p=a.n22,h=a.n32,e=a.n42,o=a.n13,j=a.n23,t=a.n33,q=a.n43,k=a.n14,u=a.n24,B=a.n34;a=a.n44;this.n11=c*s+d*T+g*F+i*P;this.n12=c*f+d*p+g*h+i*e;this.n13=c*o+d*j+g*t+i*
-q;this.n14=c*k+d*u+g*B+i*a;this.n21=l*s+b*T+r*F+m*P;this.n22=l*f+b*p+r*h+m*e;this.n23=l*o+b*j+r*t+m*q;this.n24=l*k+b*u+r*B+m*a;this.n31=n*s+z*T+y*F+w*P;this.n32=n*f+z*p+y*h+w*e;this.n33=n*o+z*j+y*t+w*q;this.n34=n*k+z*u+y*B+w*a;this.n41=x*s+I*T+M*F+L*P;this.n42=x*f+I*p+M*h+L*e;this.n43=x*o+I*j+M*t+L*q;this.n44=x*k+I*u+M*B+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,d=this.n13,g=this.n14,i=this.n21,l=this.n22,b=this.n23,r=this.n24,m=this.n31,n=this.n32,z=this.n33,y=this.n34,w=this.n41,x=this.n42,I=this.n43,M=this.n44;return g*b*n*w-d*r*n*w-g*l*z*w+c*r*z*w+d*l*y*w-c*b*y*w-g*b*m*x+d*r*m*x+g*i*z*x-a*r*z*x-d*i*y*x+a*b*y*x+g*l*m*I-c*r*m*I-g*i*n*I+a*r*n*I+c*i*y*I-a*l*y*I-d*l*m*M+c*b*m*M+d*i*n*M-a*b*n*M-c*i*z*M+a*l*z*M},transpose:function(){function a(c,d,
+g+this.n24*i;a.z=this.n31*c+this.n32*d+this.n33*g+this.n34*i;a.w=this.n41*c+this.n42*d+this.n43*g+this.n44*i;return a},crossVector:function(a){var c=new THREE.Vector4;c.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;c.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;c.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;c.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return c},multiply:function(a,c){var d=a.n11,g=a.n12,i=a.n13,l=a.n14,b=a.n21,r=a.n22,m=a.n23,o=a.n24,z=a.n31,
+y=a.n32,w=a.n33,x=a.n34,I=a.n41,M=a.n42,L=a.n43,s=a.n44,T=c.n11,F=c.n12,P=c.n13,f=c.n14,p=c.n21,h=c.n22,e=c.n23,n=c.n24,j=c.n31,t=c.n32,q=c.n33,k=c.n34,u=c.n41,B=c.n42,v=c.n43,O=c.n44;this.n11=d*T+g*p+i*j+l*u;this.n12=d*F+g*h+i*t+l*B;this.n13=d*P+g*e+i*q+l*v;this.n14=d*f+g*n+i*k+l*O;this.n21=b*T+r*p+m*j+o*u;this.n22=b*F+r*h+m*t+o*B;this.n23=b*P+r*e+m*q+o*v;this.n24=b*f+r*n+m*k+o*O;this.n31=z*T+y*p+w*j+x*u;this.n32=z*F+y*h+w*t+x*B;this.n33=z*P+y*e+w*q+x*v;this.n34=z*f+y*n+w*k+x*O;this.n41=I*T+M*p+
+L*j+s*u;this.n42=I*F+M*h+L*t+s*B;this.n43=I*P+M*e+L*q+s*v;this.n44=I*f+M*n+L*k+s*O;return this},multiplySelf:function(a){var c=this.n11,d=this.n12,g=this.n13,i=this.n14,l=this.n21,b=this.n22,r=this.n23,m=this.n24,o=this.n31,z=this.n32,y=this.n33,w=this.n34,x=this.n41,I=this.n42,M=this.n43,L=this.n44,s=a.n11,T=a.n21,F=a.n31,P=a.n41,f=a.n12,p=a.n22,h=a.n32,e=a.n42,n=a.n13,j=a.n23,t=a.n33,q=a.n43,k=a.n14,u=a.n24,B=a.n34;a=a.n44;this.n11=c*s+d*T+g*F+i*P;this.n12=c*f+d*p+g*h+i*e;this.n13=c*n+d*j+g*t+i*
+q;this.n14=c*k+d*u+g*B+i*a;this.n21=l*s+b*T+r*F+m*P;this.n22=l*f+b*p+r*h+m*e;this.n23=l*n+b*j+r*t+m*q;this.n24=l*k+b*u+r*B+m*a;this.n31=o*s+z*T+y*F+w*P;this.n32=o*f+z*p+y*h+w*e;this.n33=o*n+z*j+y*t+w*q;this.n34=o*k+z*u+y*B+w*a;this.n41=x*s+I*T+M*F+L*P;this.n42=x*f+I*p+M*h+L*e;this.n43=x*n+I*j+M*t+L*q;this.n44=x*k+I*u+M*B+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,d=this.n13,g=this.n14,i=this.n21,l=this.n22,b=this.n23,r=this.n24,m=this.n31,o=this.n32,z=this.n33,y=this.n34,w=this.n41,x=this.n42,I=this.n43,M=this.n44;return g*b*o*w-d*r*o*w-g*l*z*w+c*r*z*w+d*l*y*w-c*b*y*w-g*b*m*x+d*r*m*x+g*i*z*x-a*r*z*x-d*i*y*x+a*b*y*x+g*l*m*I-c*r*m*I-g*i*o*I+a*r*o*I+c*i*y*I-a*l*y*I-d*l*m*M+c*b*m*M+d*i*o*M-a*b*o*M-c*i*z*M+a*l*z*M},transpose:function(){function a(c,d,
 g){var i=c[d];c[d]=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,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),g=Math.sin(c),i=1-d,l=a.x,b=a.y,r=a.z,m=i*l,n=i*b;this.set(m*l+d,m*b-g*r,m*r+g*b,0,m*b+g*r,n*b+d,n*r-g*l,0,m*r-g*b,n*r+g*l,i*r*r+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(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),g=Math.sin(c),i=1-d,l=a.x,b=a.y,r=a.z,m=i*l,o=i*b;this.set(m*l+d,m*b-g*r,m*r+g*b,0,m*b+g*r,o*b+d,o*r-g*l,0,m*r-g*b,o*r+g*l,i*r*r+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 g=new THREE.Matrix4;g.setTranslation(a,c,d);return g};THREE.Matrix4.scaleMatrix=function(a,c,d){var g=new THREE.Matrix4;g.setScale(a,c,d);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 d=new THREE.Matrix4;d.setRotAxis(a,c);return d};
-THREE.Matrix4.makeInvert=function(a){var c=a.n11,d=a.n12,g=a.n13,i=a.n14,l=a.n21,b=a.n22,r=a.n23,m=a.n24,n=a.n31,z=a.n32,y=a.n33,w=a.n34,x=a.n41,I=a.n42,M=a.n43,L=a.n44,s=new THREE.Matrix4;s.n11=r*w*I-m*y*I+m*z*M-b*w*M-r*z*L+b*y*L;s.n12=i*y*I-g*w*I-i*z*M+d*w*M+g*z*L-d*y*L;s.n13=g*m*I-i*r*I+i*b*M-d*m*M-g*b*L+d*r*L;s.n14=i*r*z-g*m*z-i*b*y+d*m*y+g*b*w-d*r*w;s.n21=m*y*x-r*w*x-m*n*M+l*w*M+r*n*L-l*y*L;s.n22=g*w*x-i*y*x+i*n*M-c*w*M-g*n*L+c*y*L;s.n23=i*r*x-g*m*x-i*l*M+c*m*M+g*l*L-c*r*L;s.n24=g*m*n-i*r*n+
-i*l*y-c*m*y-g*l*w+c*r*w;s.n31=b*w*x-m*z*x+m*n*I-l*w*I-b*n*L+l*z*L;s.n32=i*z*x-d*w*x-i*n*I+c*w*I+d*n*L-c*z*L;s.n33=g*m*x-i*b*x+i*l*I-c*m*I-d*l*L+c*b*L;s.n34=i*b*n-d*m*n-i*l*z+c*m*z+d*l*w-c*b*w;s.n41=r*z*x-b*y*x-r*n*I+l*y*I+b*n*M-l*z*M;s.n42=d*y*x-g*z*x+g*n*I-c*y*I-d*n*M+c*z*M;s.n43=g*b*x-d*r*x-g*l*I+c*r*I+d*l*M-c*b*M;s.n44=d*r*n-g*b*n+g*l*z-c*r*z-d*l*y+c*b*y;s.multiplyScalar(1/a.determinant());return s};
-THREE.Matrix4.makeInvert3x3=function(a){var c=a.flatten();a=a.m33;var d=a.m,g=c[10]*c[5]-c[6]*c[9],i=-c[10]*c[1]+c[2]*c[9],l=c[6]*c[1]-c[2]*c[5],b=-c[10]*c[4]+c[6]*c[8],r=c[10]*c[0]-c[2]*c[8],m=-c[6]*c[0]+c[2]*c[4],n=c[9]*c[4]-c[5]*c[8],z=-c[9]*c[0]+c[1]*c[8],y=c[5]*c[0]-c[1]*c[4];c=c[0]*g+c[1]*b+c[2]*n;if(c==0)throw"matrix not invertible";c=1/c;d[0]=c*g;d[1]=c*i;d[2]=c*l;d[3]=c*b;d[4]=c*r;d[5]=c*m;d[6]=c*n;d[7]=c*z;d[8]=c*y;return a};
+THREE.Matrix4.makeInvert=function(a){var c=a.n11,d=a.n12,g=a.n13,i=a.n14,l=a.n21,b=a.n22,r=a.n23,m=a.n24,o=a.n31,z=a.n32,y=a.n33,w=a.n34,x=a.n41,I=a.n42,M=a.n43,L=a.n44,s=new THREE.Matrix4;s.n11=r*w*I-m*y*I+m*z*M-b*w*M-r*z*L+b*y*L;s.n12=i*y*I-g*w*I-i*z*M+d*w*M+g*z*L-d*y*L;s.n13=g*m*I-i*r*I+i*b*M-d*m*M-g*b*L+d*r*L;s.n14=i*r*z-g*m*z-i*b*y+d*m*y+g*b*w-d*r*w;s.n21=m*y*x-r*w*x-m*o*M+l*w*M+r*o*L-l*y*L;s.n22=g*w*x-i*y*x+i*o*M-c*w*M-g*o*L+c*y*L;s.n23=i*r*x-g*m*x-i*l*M+c*m*M+g*l*L-c*r*L;s.n24=g*m*o-i*r*o+
+i*l*y-c*m*y-g*l*w+c*r*w;s.n31=b*w*x-m*z*x+m*o*I-l*w*I-b*o*L+l*z*L;s.n32=i*z*x-d*w*x-i*o*I+c*w*I+d*o*L-c*z*L;s.n33=g*m*x-i*b*x+i*l*I-c*m*I-d*l*L+c*b*L;s.n34=i*b*o-d*m*o-i*l*z+c*m*z+d*l*w-c*b*w;s.n41=r*z*x-b*y*x-r*o*I+l*y*I+b*o*M-l*z*M;s.n42=d*y*x-g*z*x+g*o*I-c*y*I-d*o*M+c*z*M;s.n43=g*b*x-d*r*x-g*l*I+c*r*I+d*l*M-c*b*M;s.n44=d*r*o-g*b*o+g*l*z-c*r*z-d*l*y+c*b*y;s.multiplyScalar(1/a.determinant());return s};
+THREE.Matrix4.makeInvert3x3=function(a){var c=a.flatten();a=a.m33;var d=a.m,g=c[10]*c[5]-c[6]*c[9],i=-c[10]*c[1]+c[2]*c[9],l=c[6]*c[1]-c[2]*c[5],b=-c[10]*c[4]+c[6]*c[8],r=c[10]*c[0]-c[2]*c[8],m=-c[6]*c[0]+c[2]*c[4],o=c[9]*c[4]-c[5]*c[8],z=-c[9]*c[0]+c[1]*c[8],y=c[5]*c[0]-c[1]*c[4];c=c[0]*g+c[1]*b+c[2]*o;if(c==0)throw"matrix not invertible";c=1/c;d[0]=c*g;d[1]=c*i;d[2]=c*l;d[3]=c*b;d[4]=c*r;d[5]=c*m;d[6]=c*o;d[7]=c*z;d[8]=c*y;return a};
 THREE.Matrix4.makeFrustum=function(a,c,d,g,i,l){var b,r,m;b=new THREE.Matrix4;r=2*i/(c-a);m=2*i/(g-d);a=(c+a)/(c-a);d=(g+d)/(g-d);g=-(l+i)/(l-i);i=-2*l*i/(l-i);b.n11=r;b.n12=0;b.n13=a;b.n14=0;b.n21=0;b.n22=m;b.n23=d;b.n24=0;b.n31=0;b.n32=0;b.n33=g;b.n34=i;b.n41=0;b.n42=0;b.n43=-1;b.n44=0;return b};THREE.Matrix4.makePerspective=function(a,c,d,g){var i;a=d*Math.tan(a*Math.PI/360);i=-a;return THREE.Matrix4.makeFrustum(i*c,a*c,i,a,d,g)};
-THREE.Matrix4.makeOrtho=function(a,c,d,g,i,l){var b,r,m,n;b=new THREE.Matrix4;r=c-a;m=d-g;n=l-i;a=(c+a)/r;d=(d+g)/m;i=(l+i)/n;b.n11=2/r;b.n12=0;b.n13=0;b.n14=-a;b.n21=0;b.n22=2/m;b.n23=0;b.n24=-d;b.n31=0;b.n32=0;b.n33=-2/n;b.n34=-i;b.n41=0;b.n42=0;b.n43=0;b.n44=1;return b};THREE.Matrix4.__tmpVec1=new THREE.Vector3;THREE.Matrix4.__tmpVec2=new THREE.Vector3;THREE.Matrix4.__tmpVec3=new THREE.Vector3;
+THREE.Matrix4.makeOrtho=function(a,c,d,g,i,l){var b,r,m,o;b=new THREE.Matrix4;r=c-a;m=d-g;o=l-i;a=(c+a)/r;d=(d+g)/m;i=(l+i)/o;b.n11=2/r;b.n12=0;b.n13=0;b.n14=-a;b.n21=0;b.n22=2/m;b.n23=0;b.n24=-d;b.n31=0;b.n32=0;b.n33=-2/o;b.n34=-i;b.n41=0;b.n42=0;b.n43=0;b.n44=1;return b};THREE.Matrix4.__tmpVec1=new THREE.Vector3;THREE.Matrix4.__tmpVec2=new THREE.Vector3;THREE.Matrix4.__tmpVec3=new THREE.Vector3;
 THREE.Vertex=function(a,c){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=c||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,c,d,g,i){this.a=a;this.b=c;this.c=d;this.centroid=new THREE.Vector3;this.normal=g instanceof THREE.Vector3?g:new THREE.Vector3;this.vertexNormals=g instanceof Array?g:[];this.materials=i instanceof Array?i:[i]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
 THREE.Face4=function(a,c,d,g,i,l){this.a=a;this.b=c;this.c=d;this.d=g;this.centroid=new THREE.Vector3;this.normal=i instanceof THREE.Vector3?i:new THREE.Vector3;this.vertexNormals=i instanceof Array?i:[];this.materials=l instanceof Array?l:[l]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,c){this.u=a||0;this.v=c||0};
@@ -47,13 +47,13 @@ THREE.Geometry.prototype={computeCentroids:function(){var a,c,d;a=0;for(c=this.f
 d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeFaceNormals:function(a){var c,d,g,i,l,b,r=new THREE.Vector3,m=new THREE.Vector3;g=0;for(i=this.vertices.length;g<i;g++){l=this.vertices[g];l.normal.set(0,0,0)}g=0;for(i=this.faces.length;g<i;g++){l=this.faces[g];if(a&&l.vertexNormals.length){r.set(0,0,0);c=0;for(d=l.normal.length;c<d;c++)r.addSelf(l.vertexNormals[c]);r.divideScalar(3)}else{c=this.vertices[l.a];d=this.vertices[l.b];b=this.vertices[l.c];r.sub(b.position,
 d.position);m.sub(c.position,d.position);r.crossSelf(m)}r.isZero()||r.normalize();l.normal.copy(r)}},computeVertexNormals:function(){var a,c,d,g;if(this.__tmpVertices==undefined){g=this.__tmpVertices=Array(this.vertices.length);a=0;for(c=this.vertices.length;a<c;a++)g[a]=new THREE.Vector3;a=0;for(c=this.faces.length;a<c;a++){d=this.faces[a];if(d instanceof THREE.Face3)d.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];else if(d instanceof THREE.Face4)d.vertexNormals=[new THREE.Vector3,
 new THREE.Vector3,new THREE.Vector3,new THREE.Vector3]}}else{g=this.__tmpVertices;a=0;for(c=this.vertices.length;a<c;a++)g[a].set(0,0,0)}a=0;for(c=this.faces.length;a<c;a++){d=this.faces[a];if(d instanceof THREE.Face3){g[d.a].addSelf(d.normal);g[d.b].addSelf(d.normal);g[d.c].addSelf(d.normal)}else if(d instanceof THREE.Face4){g[d.a].addSelf(d.normal);g[d.b].addSelf(d.normal);g[d.c].addSelf(d.normal);g[d.d].addSelf(d.normal)}}a=0;for(c=this.vertices.length;a<c;a++)g[a].normalize();a=0;for(c=this.faces.length;a<
-c;a++){d=this.faces[a];if(d instanceof THREE.Face3){d.vertexNormals[0].copy(g[d.a]);d.vertexNormals[1].copy(g[d.b]);d.vertexNormals[2].copy(g[d.c])}else if(d instanceof THREE.Face4){d.vertexNormals[0].copy(g[d.a]);d.vertexNormals[1].copy(g[d.b]);d.vertexNormals[2].copy(g[d.c]);d.vertexNormals[3].copy(g[d.d])}}},computeTangents:function(){function a(k,u,B,v,O,G,D){l=k.vertices[u].position;b=k.vertices[B].position;r=k.vertices[v].position;m=i[O];n=i[G];z=i[D];y=b.x-l.x;w=r.x-l.x;x=b.y-l.y;I=r.y-l.y;
-M=b.z-l.z;L=r.z-l.z;s=n.u-m.u;T=z.u-m.u;F=n.v-m.v;P=z.v-m.v;f=1/(s*P-T*F);e.set((P*y-F*w)*f,(P*x-F*I)*f,(P*M-F*L)*f);o.set((s*w-T*y)*f,(s*I-T*x)*f,(s*L-T*M)*f);p[u].addSelf(e);p[B].addSelf(e);p[v].addSelf(e);h[u].addSelf(o);h[B].addSelf(o);h[v].addSelf(o)}var c,d,g,i,l,b,r,m,n,z,y,w,x,I,M,L,s,T,F,P,f,p=[],h=[],e=new THREE.Vector3,o=new THREE.Vector3,j=new THREE.Vector3,t=new THREE.Vector3,q=new THREE.Vector3;c=0;for(d=this.vertices.length;c<d;c++){p[c]=new THREE.Vector3;h[c]=new THREE.Vector3}c=0;
+c;a++){d=this.faces[a];if(d instanceof THREE.Face3){d.vertexNormals[0].copy(g[d.a]);d.vertexNormals[1].copy(g[d.b]);d.vertexNormals[2].copy(g[d.c])}else if(d instanceof THREE.Face4){d.vertexNormals[0].copy(g[d.a]);d.vertexNormals[1].copy(g[d.b]);d.vertexNormals[2].copy(g[d.c]);d.vertexNormals[3].copy(g[d.d])}}},computeTangents:function(){function a(k,u,B,v,O,G,D){l=k.vertices[u].position;b=k.vertices[B].position;r=k.vertices[v].position;m=i[O];o=i[G];z=i[D];y=b.x-l.x;w=r.x-l.x;x=b.y-l.y;I=r.y-l.y;
+M=b.z-l.z;L=r.z-l.z;s=o.u-m.u;T=z.u-m.u;F=o.v-m.v;P=z.v-m.v;f=1/(s*P-T*F);e.set((P*y-F*w)*f,(P*x-F*I)*f,(P*M-F*L)*f);n.set((s*w-T*y)*f,(s*I-T*x)*f,(s*L-T*M)*f);p[u].addSelf(e);p[B].addSelf(e);p[v].addSelf(e);h[u].addSelf(n);h[B].addSelf(n);h[v].addSelf(n)}var c,d,g,i,l,b,r,m,o,z,y,w,x,I,M,L,s,T,F,P,f,p=[],h=[],e=new THREE.Vector3,n=new THREE.Vector3,j=new THREE.Vector3,t=new THREE.Vector3,q=new THREE.Vector3;c=0;for(d=this.vertices.length;c<d;c++){p[c]=new THREE.Vector3;h[c]=new THREE.Vector3}c=0;
 for(d=this.faces.length;c<d;c++){g=this.faces[c];i=this.uvs[c];if(g instanceof THREE.Face3){a(this,g.a,g.b,g.c,0,1,2);this.vertices[g.a].normal.copy(g.vertexNormals[0]);this.vertices[g.b].normal.copy(g.vertexNormals[1]);this.vertices[g.c].normal.copy(g.vertexNormals[2])}else if(g instanceof THREE.Face4){a(this,g.a,g.b,g.c,0,1,2);a(this,g.a,g.b,g.d,0,1,3);this.vertices[g.a].normal.copy(g.vertexNormals[0]);this.vertices[g.b].normal.copy(g.vertexNormals[1]);this.vertices[g.c].normal.copy(g.vertexNormals[2]);
 this.vertices[g.d].normal.copy(g.vertexNormals[3])}}c=0;for(d=this.vertices.length;c<d;c++){q.copy(this.vertices[c].normal);g=p[c];j.copy(g);j.subSelf(q.multiplyScalar(q.dot(g))).normalize();t.cross(this.vertices[c].normal,g);g=t.dot(h[c]);g=g<0?-1:1;this.vertices[c].tangent.set(j.x,j.y,j.z,g)}this.hasTangents=true},computeBoundingBox:function(){var a;if(this.vertices.length>0){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 c=1,d=this.vertices.length;c<d;c++){a=this.vertices[c];if(a.position.x<this.boundingBox.x[0])this.boundingBox.x[0]=a.position.x;else if(a.position.x>this.boundingBox.x[1])this.boundingBox.x[1]=a.position.x;if(a.position.y<this.boundingBox.y[0])this.boundingBox.y[0]=a.position.y;else if(a.position.y>this.boundingBox.y[1])this.boundingBox.y[1]=a.position.y;if(a.position.z<this.boundingBox.z[0])this.boundingBox.z[0]=a.position.z;else 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,c=0,d=this.vertices.length;c<d;c++)a=Math.max(a,this.vertices[c].position.length());this.boundingSphere={radius:a}},sortFacesByMaterial:function(){function a(z){var y=[];c=0;for(d=z.length;c<d;c++)z[c]==undefined?y.push("undefined"):y.push(z[c].toString());return y.join("_")}var c,d,g,i,l,b,r,m,n={};g=0;for(i=this.faces.length;g<i;g++){l=this.faces[g];
-b=l.materials;r=a(b);if(n[r]==undefined)n[r]={hash:r,counter:0};m=n[r].hash+"_"+n[r].counter;if(this.geometryChunks[m]==undefined)this.geometryChunks[m]={faces:[],materials:b,vertices:0};l=l instanceof THREE.Face3?3:4;if(this.geometryChunks[m].vertices+l>65535){n[r].counter+=1;m=n[r].hash+"_"+n[r].counter;if(this.geometryChunks[m]==undefined)this.geometryChunks[m]={faces:[],materials:b,vertices:0}}this.geometryChunks[m].faces.push(g);this.geometryChunks[m].vertices+=l}},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,c=0,d=this.vertices.length;c<d;c++)a=Math.max(a,this.vertices[c].position.length());this.boundingSphere={radius:a}},sortFacesByMaterial:function(){function a(z){var y=[];c=0;for(d=z.length;c<d;c++)z[c]==undefined?y.push("undefined"):y.push(z[c].toString());return y.join("_")}var c,d,g,i,l,b,r,m,o={};g=0;for(i=this.faces.length;g<i;g++){l=this.faces[g];
+b=l.materials;r=a(b);if(o[r]==undefined)o[r]={hash:r,counter:0};m=o[r].hash+"_"+o[r].counter;if(this.geometryChunks[m]==undefined)this.geometryChunks[m]={faces:[],materials:b,vertices:0};l=l instanceof THREE.Face3?3:4;if(this.geometryChunks[m].vertices+l>65535){o[r].counter+=1;m=o[r].hash+"_"+o[r].counter;if(this.geometryChunks[m]==undefined)this.geometryChunks[m]={faces:[],materials:b,vertices:0}}this.geometryChunks[m].faces.push(g);this.geometryChunks[m].vertices+=l}},toString:function(){return"THREE.Geometry ( vertices: "+
 this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
 THREE.Camera=function(a,c,d,g){this.fov=a;this.aspect=c;this.near=d;this.far=g;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(i){this.tmpVec.sub(this.target.position,this.position).normalize().multiplyScalar(i);this.tmpVec.crossSelf(this.up);this.position.addSelf(this.tmpVec);this.target.position.addSelf(this.tmpVec)};
 this.translateZ=function(i){this.tmpVec.sub(this.target.position,this.position).normalize().multiplyScalar(i);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()};
@@ -102,103 +102,103 @@ var Uniforms={clone:function(a){var c,d,g,i={};for(c in a){i[c]={};for(d in a[c]
 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,c,d){this.color=new THREE.Color(a);this.near=c||1;this.far=d||1E3};THREE.FogExp2=function(a,c){this.color=new THREE.Color(a);this.density=c||2.5E-4};
-THREE.Projector=function(){function a(h,e){return e.z-h.z}function c(h,e){var o=0,j=1,t=h.z+h.w,q=e.z+e.w,k=-h.z+h.w,u=-e.z+e.w;if(t>=0&&q>=0&&k>=0&&u>=0)return true;else if(t<0&&q<0||k<0&&u<0)return false;else{if(t<0)o=Math.max(o,t/(t-q));else if(q<0)j=Math.min(j,t/(t-q));if(k<0)o=Math.max(o,k/(k-u));else if(u<0)j=Math.min(j,k/(k-u));if(j<o)return false;else{h.lerpSelf(e,o);e.lerpSelf(h,1-j);return true}}}var d,g,i=[],l,b,r,m=[],n,z,y=[],w,x,I=[],M=new THREE.Vector4,L=new THREE.Vector4,s=new THREE.Matrix4,
-T=new THREE.Matrix4,F=[],P=new THREE.Vector4,f=new THREE.Vector4,p;this.projectObjects=function(h,e,o){var j=[],t,q;g=0;s.multiply(e.projectionMatrix,e.matrix);F[0]=new THREE.Vector4(s.n41-s.n11,s.n42-s.n12,s.n43-s.n13,s.n44-s.n14);F[1]=new THREE.Vector4(s.n41+s.n11,s.n42+s.n12,s.n43+s.n13,s.n44+s.n14);F[2]=new THREE.Vector4(s.n41+s.n21,s.n42+s.n22,s.n43+s.n23,s.n44+s.n24);F[3]=new THREE.Vector4(s.n41-s.n21,s.n42-s.n22,s.n43-s.n23,s.n44-s.n24);F[4]=new THREE.Vector4(s.n41-s.n31,s.n42-s.n32,s.n43-
+THREE.Projector=function(){function a(h,e){return e.z-h.z}function c(h,e){var n=0,j=1,t=h.z+h.w,q=e.z+e.w,k=-h.z+h.w,u=-e.z+e.w;if(t>=0&&q>=0&&k>=0&&u>=0)return true;else if(t<0&&q<0||k<0&&u<0)return false;else{if(t<0)n=Math.max(n,t/(t-q));else if(q<0)j=Math.min(j,t/(t-q));if(k<0)n=Math.max(n,k/(k-u));else if(u<0)j=Math.min(j,k/(k-u));if(j<n)return false;else{h.lerpSelf(e,n);e.lerpSelf(h,1-j);return true}}}var d,g,i=[],l,b,r,m=[],o,z,y=[],w,x,I=[],M=new THREE.Vector4,L=new THREE.Vector4,s=new THREE.Matrix4,
+T=new THREE.Matrix4,F=[],P=new THREE.Vector4,f=new THREE.Vector4,p;this.projectObjects=function(h,e,n){var j=[],t,q;g=0;s.multiply(e.projectionMatrix,e.matrix);F[0]=new THREE.Vector4(s.n41-s.n11,s.n42-s.n12,s.n43-s.n13,s.n44-s.n14);F[1]=new THREE.Vector4(s.n41+s.n11,s.n42+s.n12,s.n43+s.n13,s.n44+s.n14);F[2]=new THREE.Vector4(s.n41+s.n21,s.n42+s.n22,s.n43+s.n23,s.n44+s.n24);F[3]=new THREE.Vector4(s.n41-s.n21,s.n42-s.n22,s.n43-s.n23,s.n44-s.n24);F[4]=new THREE.Vector4(s.n41-s.n31,s.n42-s.n32,s.n43-
 s.n33,s.n44-s.n34);F[5]=new THREE.Vector4(s.n41+s.n31,s.n42+s.n32,s.n43+s.n33,s.n44+s.n34);e=0;for(t=F.length;e<t;e++){q=F[e];q.divideScalar(Math.sqrt(q.x*q.x+q.y*q.y+q.z*q.z))}t=h.objects;h=0;for(e=t.length;h<e;h++){q=t[h];var k;if(!(k=!q.visible)){if(k=q instanceof THREE.Mesh){a:{k=void 0;for(var u=q.position,B=-q.geometry.boundingSphere.radius*Math.max(q.scale.x,Math.max(q.scale.y,q.scale.z)),v=0;v<6;v++){k=F[v].x*u.x+F[v].y*u.y+F[v].z*u.z+F[v].w;if(k<=B){k=false;break a}}k=true}k=!k}k=k}if(!k){d=
-i[g]=i[g]||new THREE.RenderableObject;M.copy(q.position);s.multiplyVector3(M);d.object=q;d.z=M.z;j.push(d);g++}}o&&j.sort(a);return j};this.projectScene=function(h,e,o){var j=[],t=e.near,q=e.far,k,u,B,v,O,G,D,V,U,J,H,N,R,A,K,X;r=z=x=0;e.autoUpdateMatrix&&e.updateMatrix();s.multiply(e.projectionMatrix,e.matrix);G=this.projectObjects(h,e,true);h=0;for(k=G.length;h<k;h++){D=G[h].object;if(D.visible){D.autoUpdateMatrix&&D.updateMatrix();V=D.matrix;U=D.rotationMatrix;J=D.materials;H=D.overdraw;if(D instanceof
-THREE.Mesh){N=D.geometry;R=N.vertices;u=0;for(B=R.length;u<B;u++){A=R[u];A.positionWorld.copy(A.position);V.multiplyVector3(A.positionWorld);v=A.positionScreen;v.copy(A.positionWorld);s.multiplyVector4(v);v.x/=v.w;v.y/=v.w;A.__visible=v.z>t&&v.z<q}N=N.faces;u=0;for(B=N.length;u<B;u++){A=N[u];if(A instanceof THREE.Face3){v=R[A.a];O=R[A.b];K=R[A.c];if(v.__visible&&O.__visible&&K.__visible)if(D.doubleSided||D.flipSided!=(K.positionScreen.x-v.positionScreen.x)*(O.positionScreen.y-v.positionScreen.y)-
-(K.positionScreen.y-v.positionScreen.y)*(O.positionScreen.x-v.positionScreen.x)<0){l=m[r]=m[r]||new THREE.RenderableFace3;l.v1.positionWorld.copy(v.positionWorld);l.v2.positionWorld.copy(O.positionWorld);l.v3.positionWorld.copy(K.positionWorld);l.v1.positionScreen.copy(v.positionScreen);l.v2.positionScreen.copy(O.positionScreen);l.v3.positionScreen.copy(K.positionScreen);l.normalWorld.copy(A.normal);U.multiplyVector3(l.normalWorld);l.centroidWorld.copy(A.centroid);V.multiplyVector3(l.centroidWorld);
-l.centroidScreen.copy(l.centroidWorld);s.multiplyVector3(l.centroidScreen);K=A.vertexNormals;p=l.vertexNormalsWorld;v=0;for(O=K.length;v<O;v++){X=p[v]=p[v]||new THREE.Vector3;X.copy(K[v]);U.multiplyVector3(X)}l.z=l.centroidScreen.z;l.meshMaterials=J;l.faceMaterials=A.materials;l.overdraw=H;if(D.geometry.uvs[u]){l.uvs[0]=D.geometry.uvs[u][0];l.uvs[1]=D.geometry.uvs[u][1];l.uvs[2]=D.geometry.uvs[u][2]}j.push(l);r++}}else if(A instanceof THREE.Face4){v=R[A.a];O=R[A.b];K=R[A.c];X=R[A.d];if(v.__visible&&
-O.__visible&&K.__visible&&X.__visible)if(D.doubleSided||D.flipSided!=((X.positionScreen.x-v.positionScreen.x)*(O.positionScreen.y-v.positionScreen.y)-(X.positionScreen.y-v.positionScreen.y)*(O.positionScreen.x-v.positionScreen.x)<0||(O.positionScreen.x-K.positionScreen.x)*(X.positionScreen.y-K.positionScreen.y)-(O.positionScreen.y-K.positionScreen.y)*(X.positionScreen.x-K.positionScreen.x)<0)){l=m[r]=m[r]||new THREE.RenderableFace3;l.v1.positionWorld.copy(v.positionWorld);l.v2.positionWorld.copy(O.positionWorld);
-l.v3.positionWorld.copy(X.positionWorld);l.v1.positionScreen.copy(v.positionScreen);l.v2.positionScreen.copy(O.positionScreen);l.v3.positionScreen.copy(X.positionScreen);l.normalWorld.copy(A.normal);U.multiplyVector3(l.normalWorld);l.centroidWorld.copy(A.centroid);V.multiplyVector3(l.centroidWorld);l.centroidScreen.copy(l.centroidWorld);s.multiplyVector3(l.centroidScreen);l.z=l.centroidScreen.z;l.meshMaterials=J;l.faceMaterials=A.materials;l.overdraw=H;if(D.geometry.uvs[u]){l.uvs[0]=D.geometry.uvs[u][0];
-l.uvs[1]=D.geometry.uvs[u][1];l.uvs[2]=D.geometry.uvs[u][3]}j.push(l);r++;b=m[r]=m[r]||new THREE.RenderableFace3;b.v1.positionWorld.copy(O.positionWorld);b.v2.positionWorld.copy(K.positionWorld);b.v3.positionWorld.copy(X.positionWorld);b.v1.positionScreen.copy(O.positionScreen);b.v2.positionScreen.copy(K.positionScreen);b.v3.positionScreen.copy(X.positionScreen);b.normalWorld.copy(l.normalWorld);b.centroidWorld.copy(l.centroidWorld);b.centroidScreen.copy(l.centroidScreen);b.z=b.centroidScreen.z;b.meshMaterials=
-J;b.faceMaterials=A.materials;b.overdraw=H;if(D.geometry.uvs[u]){b.uvs[0]=D.geometry.uvs[u][1];b.uvs[1]=D.geometry.uvs[u][2];b.uvs[2]=D.geometry.uvs[u][3]}j.push(b);r++}}}}else if(D instanceof THREE.Line){T.multiply(s,V);R=D.geometry.vertices;A=R[0];A.positionScreen.copy(A.position);T.multiplyVector4(A.positionScreen);u=1;for(B=R.length;u<B;u++){v=R[u];v.positionScreen.copy(v.position);T.multiplyVector4(v.positionScreen);O=R[u-1];P.copy(v.positionScreen);f.copy(O.positionScreen);if(c(P,f)){P.multiplyScalar(1/
-P.w);f.multiplyScalar(1/f.w);n=y[z]=y[z]||new THREE.RenderableLine;n.v1.positionScreen.copy(P);n.v2.positionScreen.copy(f);n.z=Math.max(P.z,f.z);n.materials=D.materials;j.push(n);z++}}}else if(D instanceof THREE.Particle){L.set(D.position.x,D.position.y,D.position.z,1);s.multiplyVector4(L);L.z/=L.w;if(L.z>0&&L.z<1){w=I[x]=I[x]||new THREE.RenderableParticle;w.x=L.x/L.w;w.y=L.y/L.w;w.z=L.z;w.rotation=D.rotation.z;w.scale.x=D.scale.x*Math.abs(w.x-(L.x+e.projectionMatrix.n11)/(L.w+e.projectionMatrix.n14));
-w.scale.y=D.scale.y*Math.abs(w.y-(L.y+e.projectionMatrix.n22)/(L.w+e.projectionMatrix.n24));w.materials=D.materials;j.push(w);x++}}}}o&&j.sort(a);return j};this.unprojectVector=function(h,e){var o=THREE.Matrix4.makeInvert(e.matrix);o.multiplySelf(THREE.Matrix4.makeInvert(e.projectionMatrix));o.multiplyVector3(h);return h}};
-THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,c=new THREE.Projector,d,g,i,l;this.domElement=document.createElement("div");this.setSize=function(b,r){d=b;g=r;i=d/2;l=g/2};this.render=function(b,r){var m,n,z,y,w,x,I,M;a=c.projectScene(b,r);m=0;for(n=a.length;m<n;m++){w=a[m];if(w instanceof THREE.RenderableParticle){I=w.x*i+i;M=w.y*l+l;z=0;for(y=w.material.length;z<y;z++){x=w.material[z];if(x instanceof THREE.ParticleDOMMaterial){x=x.domElement;x.style.left=I+"px";x.style.top=M+"px"}}}}}};
-THREE.CanvasRenderer=function(){function a(aa){if(w!=aa)n.globalAlpha=w=aa}function c(aa){if(x!=aa){switch(aa){case THREE.NormalBlending:n.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:n.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:n.globalCompositeOperation="darker"}x=aa}}var d=null,g=new THREE.Projector,i=document.createElement("canvas"),l,b,r,m,n=i.getContext("2d"),z=new THREE.Color(0),y=0,w=1,x=0,I=null,M=null,L=1,s,T,F,P,f,p,h,e,o,j=new THREE.Color,
-t=new THREE.Color,q=new THREE.Color,k=new THREE.Color,u=new THREE.Color,B,v,O,G,D,V,U,J,H,N=new THREE.Rectangle,R=new THREE.Rectangle,A=new THREE.Rectangle,K=false,X=new THREE.Color,ga=new THREE.Color,da=new THREE.Color,Y=new THREE.Color,ba=Math.PI*2,Z=new THREE.Vector3,ea,wa,ha,ia,sa,pa,qa=16;ea=document.createElement("canvas");ea.width=ea.height=2;wa=ea.getContext("2d");wa.fillStyle="rgba(0,0,0,1)";wa.fillRect(0,0,2,2);ha=wa.getImageData(0,0,2,2);ia=ha.data;sa=document.createElement("canvas");sa.width=
-sa.height=qa;pa=sa.getContext("2d");pa.translate(-qa/2,-qa/2);pa.scale(qa,qa);qa--;this.domElement=i;this.sortElements=this.sortObjects=this.autoClear=true;this.setSize=function(aa,ma){l=aa;b=ma;r=l/2;m=b/2;i.width=l;i.height=b;N.set(-r,-m,r,m);w=1;x=0;M=I=null;L=1};this.setClearColor=function(aa,ma){z=aa;y=ma;R.set(-r,-m,r,m);n.setTransform(1,0,0,-1,r,m);this.clear()};this.setClearColorHex=function(aa,ma){z.setHex(aa);y=ma;R.set(-r,-m,r,m);n.setTransform(1,0,0,-1,r,m);this.clear()};this.clear=function(){n.setTransform(1,
-0,0,-1,r,m);if(!R.isEmpty()){R.inflate(1);R.minSelf(N);if(z.hex==0&&y==0)n.clearRect(R.getX(),R.getY(),R.getWidth(),R.getHeight());else{c(THREE.NormalBlending);a(1);n.fillStyle="rgba("+Math.floor(z.r*255)+","+Math.floor(z.g*255)+","+Math.floor(z.b*255)+","+y+")";n.fillRect(R.getX(),R.getY(),R.getWidth(),R.getHeight())}R.empty()}};this.render=function(aa,ma){function ka(C){var W,S,E,Q=C.lights;ga.setRGB(0,0,0);da.setRGB(0,0,0);Y.setRGB(0,0,0);C=0;for(W=Q.length;C<W;C++){S=Q[C];E=S.color;if(S instanceof
-THREE.AmbientLight){ga.r+=E.r;ga.g+=E.g;ga.b+=E.b}else if(S instanceof THREE.DirectionalLight){da.r+=E.r;da.g+=E.g;da.b+=E.b}else if(S instanceof THREE.PointLight){Y.r+=E.r;Y.g+=E.g;Y.b+=E.b}}}function xa(C,W,S,E){var Q,$,fa,ja,la=C.lights;C=0;for(Q=la.length;C<Q;C++){$=la[C];fa=$.color;ja=$.intensity;if($ instanceof THREE.DirectionalLight){$=S.dot($.position)*ja;if($>0){E.r+=fa.r*$;E.g+=fa.g*$;E.b+=fa.b*$}}else if($ instanceof THREE.PointLight){Z.sub($.position,W);Z.normalize();$=S.dot(Z)*ja;if($>
-0){E.r+=fa.r*$;E.g+=fa.g*$;E.b+=fa.b*$}}}}function Ga(C,W,S){if(S.opacity!=0){a(S.opacity);c(S.blending);var E,Q,$,fa,ja,la;if(S instanceof THREE.ParticleBasicMaterial){if(S.map&&S.map.image.loaded){fa=S.map.image;ja=fa.width>>1;la=fa.height>>1;Q=W.scale.x*r;$=W.scale.y*m;S=Q*ja;E=$*la;A.set(C.x-S,C.y-E,C.x+S,C.y+E);if(N.instersects(A)){n.save();n.translate(C.x,C.y);n.rotate(-W.rotation);n.scale(Q,-$);n.translate(-ja,-la);n.drawImage(fa,0,0);n.restore()}}}else if(S instanceof THREE.ParticleCircleMaterial){if(K){X.r=
-ga.r+da.r+Y.r;X.g=ga.g+da.g+Y.g;X.b=ga.b+da.b+Y.b;j.r=S.color.r*X.r;j.g=S.color.g*X.g;j.b=S.color.b*X.b;j.updateStyleString()}else j.__styleString=S.color.__styleString;S=W.scale.x*r;E=W.scale.y*m;A.set(C.x-S,C.y-E,C.x+S,C.y+E);if(N.instersects(A)){Q=j.__styleString;if(M!=Q)n.fillStyle=M=Q;n.save();n.translate(C.x,C.y);n.rotate(-W.rotation);n.scale(S,E);n.beginPath();n.arc(0,0,1,0,ba,true);n.closePath();n.fill();n.restore()}}}}function Ha(C,W,S,E){if(E.opacity!=0){a(E.opacity);c(E.blending);n.beginPath();
-n.moveTo(C.positionScreen.x,C.positionScreen.y);n.lineTo(W.positionScreen.x,W.positionScreen.y);n.closePath();if(E instanceof THREE.LineBasicMaterial){j.__styleString=E.color.__styleString;C=E.linewidth;if(L!=C)n.lineWidth=L=C;C=j.__styleString;if(I!=C)n.strokeStyle=I=C;n.stroke();A.inflate(E.linewidth*2)}}}function Da(C,W,S,E,Q,$){if(Q.opacity!=0){a(Q.opacity);c(Q.blending);P=C.positionScreen.x;f=C.positionScreen.y;p=W.positionScreen.x;h=W.positionScreen.y;e=S.positionScreen.x;o=S.positionScreen.y;
-n.beginPath();n.moveTo(P,f);n.lineTo(p,h);n.lineTo(e,o);n.lineTo(P,f);n.closePath();if(Q instanceof THREE.MeshBasicMaterial)if(Q.map)Q.map.image.loaded&&Q.map.mapping instanceof THREE.UVMapping&&Aa(P,f,p,h,e,o,Q.map.image,E.uvs[0].u,E.uvs[0].v,E.uvs[1].u,E.uvs[1].v,E.uvs[2].u,E.uvs[2].v);else if(Q.env_map){if(Q.env_map.image.loaded)if(Q.env_map.mapping instanceof THREE.SphericalReflectionMapping){C=ma.matrix;Z.copy(E.vertexNormalsWorld[0]);G=(Z.x*C.n11+Z.y*C.n12+Z.z*C.n13)*0.5+0.5;D=-(Z.x*C.n21+Z.y*
-C.n22+Z.z*C.n23)*0.5+0.5;Z.copy(E.vertexNormalsWorld[1]);V=(Z.x*C.n11+Z.y*C.n12+Z.z*C.n13)*0.5+0.5;U=-(Z.x*C.n21+Z.y*C.n22+Z.z*C.n23)*0.5+0.5;Z.copy(E.vertexNormalsWorld[2]);J=(Z.x*C.n11+Z.y*C.n12+Z.z*C.n13)*0.5+0.5;H=-(Z.x*C.n21+Z.y*C.n22+Z.z*C.n23)*0.5+0.5;Aa(P,f,p,h,e,o,Q.env_map.image,G,D,V,U,J,H)}}else Q.wireframe?na(Q.color.__styleString,Q.wireframe_linewidth):Ea(Q.color.__styleString);else if(Q instanceof THREE.MeshLambertMaterial){if(Q.map&&!Q.wireframe){Q.map.mapping instanceof THREE.UVMapping&&
-Aa(P,f,p,h,e,o,Q.map.image,E.uvs[0].u,E.uvs[0].v,E.uvs[1].u,E.uvs[1].v,E.uvs[2].u,E.uvs[2].v);c(THREE.SubtractiveBlending)}if(K)if(!Q.wireframe&&Q.shading==THREE.SmoothShading&&E.vertexNormalsWorld.length==3){t.r=q.r=k.r=ga.r;t.g=q.g=k.g=ga.g;t.b=q.b=k.b=ga.b;xa($,E.v1.positionWorld,E.vertexNormalsWorld[0],t);xa($,E.v2.positionWorld,E.vertexNormalsWorld[1],q);xa($,E.v3.positionWorld,E.vertexNormalsWorld[2],k);u.r=(q.r+k.r)*0.5;u.g=(q.g+k.g)*0.5;u.b=(q.b+k.b)*0.5;O=Ma(t,q,k,u);Aa(P,f,p,h,e,o,O,0,0,
-1,0,0,1)}else{X.r=ga.r;X.g=ga.g;X.b=ga.b;xa($,E.centroidWorld,E.normalWorld,X);j.r=Q.color.r*X.r;j.g=Q.color.g*X.g;j.b=Q.color.b*X.b;j.updateStyleString();Q.wireframe?na(j.__styleString,Q.wireframe_linewidth):Ea(j.__styleString)}else Q.wireframe?na(Q.color.__styleString,Q.wireframe_linewidth):Ea(Q.color.__styleString)}else if(Q instanceof THREE.MeshDepthMaterial){B=ma.near;v=ma.far;t.r=t.g=t.b=1-Ia(C.positionScreen.z,B,v);q.r=q.g=q.b=1-Ia(W.positionScreen.z,B,v);k.r=k.g=k.b=1-Ia(S.positionScreen.z,
-B,v);u.r=(q.r+k.r)*0.5;u.g=(q.g+k.g)*0.5;u.b=(q.b+k.b)*0.5;O=Ma(t,q,k,u);Aa(P,f,p,h,e,o,O,0,0,1,0,0,1)}else if(Q instanceof THREE.MeshNormalMaterial){j.r=Ja(E.normalWorld.x);j.g=Ja(E.normalWorld.y);j.b=Ja(E.normalWorld.z);j.updateStyleString();Q.wireframe?na(j.__styleString,Q.wireframe_linewidth):Ea(j.__styleString)}}}function na(C,W){if(I!=C)n.strokeStyle=I=C;if(L!=W)n.lineWidth=L=W;n.stroke();A.inflate(W*2)}function Ea(C){if(M!=C)n.fillStyle=M=C;n.fill()}function Aa(C,W,S,E,Q,$,fa,ja,la,ta,oa,ua,
-Ba){var ya,va;ya=fa.width-1;va=fa.height-1;ja*=ya;la*=va;ta*=ya;oa*=va;ua*=ya;Ba*=va;S-=C;E-=W;Q-=C;$-=W;ta-=ja;oa-=la;ua-=ja;Ba-=la;va=1/(ta*Ba-ua*oa);ya=(Ba*S-oa*Q)*va;oa=(Ba*E-oa*$)*va;S=(ta*Q-ua*S)*va;E=(ta*$-ua*E)*va;C=C-ya*ja-S*la;W=W-oa*ja-E*la;n.save();n.transform(ya,oa,S,E,C,W);n.clip();n.drawImage(fa,0,0);n.restore()}function Ma(C,W,S,E){var Q=~~(C.r*255),$=~~(C.g*255);C=~~(C.b*255);var fa=~~(W.r*255),ja=~~(W.g*255);W=~~(W.b*255);var la=~~(S.r*255),ta=~~(S.g*255);S=~~(S.b*255);var oa=~~(E.r*
-255),ua=~~(E.g*255);E=~~(E.b*255);ia[0]=Q<0?0:Q>255?255:Q;ia[1]=$<0?0:$>255?255:$;ia[2]=C<0?0:C>255?255:C;ia[4]=fa<0?0:fa>255?255:fa;ia[5]=ja<0?0:ja>255?255:ja;ia[6]=W<0?0:W>255?255:W;ia[8]=la<0?0:la>255?255:la;ia[9]=ta<0?0:ta>255?255:ta;ia[10]=S<0?0:S>255?255:S;ia[12]=oa<0?0:oa>255?255:oa;ia[13]=ua<0?0:ua>255?255:ua;ia[14]=E<0?0:E>255?255:E;wa.putImageData(ha,0,0);pa.drawImage(ea,0,0);return sa}function Ia(C,W,S){C=(C-W)/(S-W);return C*C*(3-2*C)}function Ja(C){C=(C+1)*0.5;return C<0?0:C>1?1:C}function Ka(C,
-W){var S=W.x-C.x,E=W.y-C.y,Q=1/Math.sqrt(S*S+E*E);S*=Q;E*=Q;W.x+=S;W.y+=E;C.x-=S;C.y-=E}var Fa,Na,ca,ra,za,La,Oa,Ca;this.autoClear?this.clear():n.setTransform(1,0,0,-1,r,m);d=g.projectScene(aa,ma,this.sortElements);(K=aa.lights.length>0)&&ka(aa);Fa=0;for(Na=d.length;Fa<Na;Fa++){ca=d[Fa];A.empty();if(ca instanceof THREE.RenderableParticle){s=ca;s.x*=r;s.y*=m;ra=0;for(za=ca.materials.length;ra<za;ra++)Ga(s,ca,ca.materials[ra],aa)}else if(ca instanceof THREE.RenderableLine){s=ca.v1;T=ca.v2;s.positionScreen.x*=
+i[g]=i[g]||new THREE.RenderableObject;M.copy(q.position);s.multiplyVector3(M);d.object=q;d.z=M.z;j.push(d);g++}}n&&j.sort(a);return j};this.projectScene=function(h,e,n){var j=[],t=e.near,q=e.far,k,u,B,v,O,G,D,U,X,K,H,N,R,A,J,W;r=z=x=0;e.autoUpdateMatrix&&e.updateMatrix();s.multiply(e.projectionMatrix,e.matrix);G=this.projectObjects(h,e,true);h=0;for(k=G.length;h<k;h++){D=G[h].object;if(D.visible){D.autoUpdateMatrix&&D.updateMatrix();U=D.matrix;X=D.rotationMatrix;K=D.materials;H=D.overdraw;if(D instanceof
+THREE.Mesh){N=D.geometry;R=N.vertices;u=0;for(B=R.length;u<B;u++){A=R[u];A.positionWorld.copy(A.position);U.multiplyVector3(A.positionWorld);v=A.positionScreen;v.copy(A.positionWorld);s.multiplyVector4(v);v.x/=v.w;v.y/=v.w;A.__visible=v.z>t&&v.z<q}N=N.faces;u=0;for(B=N.length;u<B;u++){A=N[u];if(A instanceof THREE.Face3){v=R[A.a];O=R[A.b];J=R[A.c];if(v.__visible&&O.__visible&&J.__visible)if(D.doubleSided||D.flipSided!=(J.positionScreen.x-v.positionScreen.x)*(O.positionScreen.y-v.positionScreen.y)-
+(J.positionScreen.y-v.positionScreen.y)*(O.positionScreen.x-v.positionScreen.x)<0){l=m[r]=m[r]||new THREE.RenderableFace3;l.v1.positionWorld.copy(v.positionWorld);l.v2.positionWorld.copy(O.positionWorld);l.v3.positionWorld.copy(J.positionWorld);l.v1.positionScreen.copy(v.positionScreen);l.v2.positionScreen.copy(O.positionScreen);l.v3.positionScreen.copy(J.positionScreen);l.normalWorld.copy(A.normal);X.multiplyVector3(l.normalWorld);l.centroidWorld.copy(A.centroid);U.multiplyVector3(l.centroidWorld);
+l.centroidScreen.copy(l.centroidWorld);s.multiplyVector3(l.centroidScreen);J=A.vertexNormals;p=l.vertexNormalsWorld;v=0;for(O=J.length;v<O;v++){W=p[v]=p[v]||new THREE.Vector3;W.copy(J[v]);X.multiplyVector3(W)}l.z=l.centroidScreen.z;l.meshMaterials=K;l.faceMaterials=A.materials;l.overdraw=H;if(D.geometry.uvs[u]){l.uvs[0]=D.geometry.uvs[u][0];l.uvs[1]=D.geometry.uvs[u][1];l.uvs[2]=D.geometry.uvs[u][2]}j.push(l);r++}}else if(A instanceof THREE.Face4){v=R[A.a];O=R[A.b];J=R[A.c];W=R[A.d];if(v.__visible&&
+O.__visible&&J.__visible&&W.__visible)if(D.doubleSided||D.flipSided!=((W.positionScreen.x-v.positionScreen.x)*(O.positionScreen.y-v.positionScreen.y)-(W.positionScreen.y-v.positionScreen.y)*(O.positionScreen.x-v.positionScreen.x)<0||(O.positionScreen.x-J.positionScreen.x)*(W.positionScreen.y-J.positionScreen.y)-(O.positionScreen.y-J.positionScreen.y)*(W.positionScreen.x-J.positionScreen.x)<0)){l=m[r]=m[r]||new THREE.RenderableFace3;l.v1.positionWorld.copy(v.positionWorld);l.v2.positionWorld.copy(O.positionWorld);
+l.v3.positionWorld.copy(W.positionWorld);l.v1.positionScreen.copy(v.positionScreen);l.v2.positionScreen.copy(O.positionScreen);l.v3.positionScreen.copy(W.positionScreen);l.normalWorld.copy(A.normal);X.multiplyVector3(l.normalWorld);l.centroidWorld.copy(A.centroid);U.multiplyVector3(l.centroidWorld);l.centroidScreen.copy(l.centroidWorld);s.multiplyVector3(l.centroidScreen);l.z=l.centroidScreen.z;l.meshMaterials=K;l.faceMaterials=A.materials;l.overdraw=H;if(D.geometry.uvs[u]){l.uvs[0]=D.geometry.uvs[u][0];
+l.uvs[1]=D.geometry.uvs[u][1];l.uvs[2]=D.geometry.uvs[u][3]}j.push(l);r++;b=m[r]=m[r]||new THREE.RenderableFace3;b.v1.positionWorld.copy(O.positionWorld);b.v2.positionWorld.copy(J.positionWorld);b.v3.positionWorld.copy(W.positionWorld);b.v1.positionScreen.copy(O.positionScreen);b.v2.positionScreen.copy(J.positionScreen);b.v3.positionScreen.copy(W.positionScreen);b.normalWorld.copy(l.normalWorld);b.centroidWorld.copy(l.centroidWorld);b.centroidScreen.copy(l.centroidScreen);b.z=b.centroidScreen.z;b.meshMaterials=
+K;b.faceMaterials=A.materials;b.overdraw=H;if(D.geometry.uvs[u]){b.uvs[0]=D.geometry.uvs[u][1];b.uvs[1]=D.geometry.uvs[u][2];b.uvs[2]=D.geometry.uvs[u][3]}j.push(b);r++}}}}else if(D instanceof THREE.Line){T.multiply(s,U);R=D.geometry.vertices;A=R[0];A.positionScreen.copy(A.position);T.multiplyVector4(A.positionScreen);u=1;for(B=R.length;u<B;u++){v=R[u];v.positionScreen.copy(v.position);T.multiplyVector4(v.positionScreen);O=R[u-1];P.copy(v.positionScreen);f.copy(O.positionScreen);if(c(P,f)){P.multiplyScalar(1/
+P.w);f.multiplyScalar(1/f.w);o=y[z]=y[z]||new THREE.RenderableLine;o.v1.positionScreen.copy(P);o.v2.positionScreen.copy(f);o.z=Math.max(P.z,f.z);o.materials=D.materials;j.push(o);z++}}}else if(D instanceof THREE.Particle){L.set(D.position.x,D.position.y,D.position.z,1);s.multiplyVector4(L);L.z/=L.w;if(L.z>0&&L.z<1){w=I[x]=I[x]||new THREE.RenderableParticle;w.x=L.x/L.w;w.y=L.y/L.w;w.z=L.z;w.rotation=D.rotation.z;w.scale.x=D.scale.x*Math.abs(w.x-(L.x+e.projectionMatrix.n11)/(L.w+e.projectionMatrix.n14));
+w.scale.y=D.scale.y*Math.abs(w.y-(L.y+e.projectionMatrix.n22)/(L.w+e.projectionMatrix.n24));w.materials=D.materials;j.push(w);x++}}}}n&&j.sort(a);return j};this.unprojectVector=function(h,e){var n=THREE.Matrix4.makeInvert(e.matrix);n.multiplySelf(THREE.Matrix4.makeInvert(e.projectionMatrix));n.multiplyVector3(h);return h}};
+THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,c=new THREE.Projector,d,g,i,l;this.domElement=document.createElement("div");this.setSize=function(b,r){d=b;g=r;i=d/2;l=g/2};this.render=function(b,r){var m,o,z,y,w,x,I,M;a=c.projectScene(b,r);m=0;for(o=a.length;m<o;m++){w=a[m];if(w instanceof THREE.RenderableParticle){I=w.x*i+i;M=w.y*l+l;z=0;for(y=w.material.length;z<y;z++){x=w.material[z];if(x instanceof THREE.ParticleDOMMaterial){x=x.domElement;x.style.left=I+"px";x.style.top=M+"px"}}}}}};
+THREE.CanvasRenderer=function(){function a(aa){if(w!=aa)o.globalAlpha=w=aa}function c(aa){if(x!=aa){switch(aa){case THREE.NormalBlending:o.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:o.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:o.globalCompositeOperation="darker"}x=aa}}var d=null,g=new THREE.Projector,i=document.createElement("canvas"),l,b,r,m,o=i.getContext("2d"),z=new THREE.Color(0),y=0,w=1,x=0,I=null,M=null,L=1,s,T,F,P,f,p,h,e,n,j=new THREE.Color,
+t=new THREE.Color,q=new THREE.Color,k=new THREE.Color,u=new THREE.Color,B,v,O,G,D,U,X,K,H,N=new THREE.Rectangle,R=new THREE.Rectangle,A=new THREE.Rectangle,J=false,W=new THREE.Color,ga=new THREE.Color,da=new THREE.Color,Y=new THREE.Color,ba=Math.PI*2,Z=new THREE.Vector3,ea,wa,ha,ia,sa,pa,qa=16;ea=document.createElement("canvas");ea.width=ea.height=2;wa=ea.getContext("2d");wa.fillStyle="rgba(0,0,0,1)";wa.fillRect(0,0,2,2);ha=wa.getImageData(0,0,2,2);ia=ha.data;sa=document.createElement("canvas");sa.width=
+sa.height=qa;pa=sa.getContext("2d");pa.translate(-qa/2,-qa/2);pa.scale(qa,qa);qa--;this.domElement=i;this.sortElements=this.sortObjects=this.autoClear=true;this.setSize=function(aa,ma){l=aa;b=ma;r=l/2;m=b/2;i.width=l;i.height=b;N.set(-r,-m,r,m);w=1;x=0;M=I=null;L=1};this.setClearColor=function(aa,ma){z=aa;y=ma;R.set(-r,-m,r,m);o.setTransform(1,0,0,-1,r,m);this.clear()};this.setClearColorHex=function(aa,ma){z.setHex(aa);y=ma;R.set(-r,-m,r,m);o.setTransform(1,0,0,-1,r,m);this.clear()};this.clear=function(){o.setTransform(1,
+0,0,-1,r,m);if(!R.isEmpty()){R.inflate(1);R.minSelf(N);if(z.hex==0&&y==0)o.clearRect(R.getX(),R.getY(),R.getWidth(),R.getHeight());else{c(THREE.NormalBlending);a(1);o.fillStyle="rgba("+Math.floor(z.r*255)+","+Math.floor(z.g*255)+","+Math.floor(z.b*255)+","+y+")";o.fillRect(R.getX(),R.getY(),R.getWidth(),R.getHeight())}R.empty()}};this.render=function(aa,ma){function ka(C){var V,S,E,Q=C.lights;ga.setRGB(0,0,0);da.setRGB(0,0,0);Y.setRGB(0,0,0);C=0;for(V=Q.length;C<V;C++){S=Q[C];E=S.color;if(S instanceof
+THREE.AmbientLight){ga.r+=E.r;ga.g+=E.g;ga.b+=E.b}else if(S instanceof THREE.DirectionalLight){da.r+=E.r;da.g+=E.g;da.b+=E.b}else if(S instanceof THREE.PointLight){Y.r+=E.r;Y.g+=E.g;Y.b+=E.b}}}function xa(C,V,S,E){var Q,$,fa,ja,la=C.lights;C=0;for(Q=la.length;C<Q;C++){$=la[C];fa=$.color;ja=$.intensity;if($ instanceof THREE.DirectionalLight){$=S.dot($.position)*ja;if($>0){E.r+=fa.r*$;E.g+=fa.g*$;E.b+=fa.b*$}}else if($ instanceof THREE.PointLight){Z.sub($.position,V);Z.normalize();$=S.dot(Z)*ja;if($>
+0){E.r+=fa.r*$;E.g+=fa.g*$;E.b+=fa.b*$}}}}function Ga(C,V,S){if(S.opacity!=0){a(S.opacity);c(S.blending);var E,Q,$,fa,ja,la;if(S instanceof THREE.ParticleBasicMaterial){if(S.map&&S.map.image.loaded){fa=S.map.image;ja=fa.width>>1;la=fa.height>>1;Q=V.scale.x*r;$=V.scale.y*m;S=Q*ja;E=$*la;A.set(C.x-S,C.y-E,C.x+S,C.y+E);if(N.instersects(A)){o.save();o.translate(C.x,C.y);o.rotate(-V.rotation);o.scale(Q,-$);o.translate(-ja,-la);o.drawImage(fa,0,0);o.restore()}}}else if(S instanceof THREE.ParticleCircleMaterial){if(J){W.r=
+ga.r+da.r+Y.r;W.g=ga.g+da.g+Y.g;W.b=ga.b+da.b+Y.b;j.r=S.color.r*W.r;j.g=S.color.g*W.g;j.b=S.color.b*W.b;j.updateStyleString()}else j.__styleString=S.color.__styleString;S=V.scale.x*r;E=V.scale.y*m;A.set(C.x-S,C.y-E,C.x+S,C.y+E);if(N.instersects(A)){Q=j.__styleString;if(M!=Q)o.fillStyle=M=Q;o.save();o.translate(C.x,C.y);o.rotate(-V.rotation);o.scale(S,E);o.beginPath();o.arc(0,0,1,0,ba,true);o.closePath();o.fill();o.restore()}}}}function Ha(C,V,S,E){if(E.opacity!=0){a(E.opacity);c(E.blending);o.beginPath();
+o.moveTo(C.positionScreen.x,C.positionScreen.y);o.lineTo(V.positionScreen.x,V.positionScreen.y);o.closePath();if(E instanceof THREE.LineBasicMaterial){j.__styleString=E.color.__styleString;C=E.linewidth;if(L!=C)o.lineWidth=L=C;C=j.__styleString;if(I!=C)o.strokeStyle=I=C;o.stroke();A.inflate(E.linewidth*2)}}}function Da(C,V,S,E,Q,$){if(Q.opacity!=0){a(Q.opacity);c(Q.blending);P=C.positionScreen.x;f=C.positionScreen.y;p=V.positionScreen.x;h=V.positionScreen.y;e=S.positionScreen.x;n=S.positionScreen.y;
+o.beginPath();o.moveTo(P,f);o.lineTo(p,h);o.lineTo(e,n);o.lineTo(P,f);o.closePath();if(Q instanceof THREE.MeshBasicMaterial)if(Q.map)Q.map.image.loaded&&Q.map.mapping instanceof THREE.UVMapping&&Aa(P,f,p,h,e,n,Q.map.image,E.uvs[0].u,E.uvs[0].v,E.uvs[1].u,E.uvs[1].v,E.uvs[2].u,E.uvs[2].v);else if(Q.env_map){if(Q.env_map.image.loaded)if(Q.env_map.mapping instanceof THREE.SphericalReflectionMapping){C=ma.matrix;Z.copy(E.vertexNormalsWorld[0]);G=(Z.x*C.n11+Z.y*C.n12+Z.z*C.n13)*0.5+0.5;D=-(Z.x*C.n21+Z.y*
+C.n22+Z.z*C.n23)*0.5+0.5;Z.copy(E.vertexNormalsWorld[1]);U=(Z.x*C.n11+Z.y*C.n12+Z.z*C.n13)*0.5+0.5;X=-(Z.x*C.n21+Z.y*C.n22+Z.z*C.n23)*0.5+0.5;Z.copy(E.vertexNormalsWorld[2]);K=(Z.x*C.n11+Z.y*C.n12+Z.z*C.n13)*0.5+0.5;H=-(Z.x*C.n21+Z.y*C.n22+Z.z*C.n23)*0.5+0.5;Aa(P,f,p,h,e,n,Q.env_map.image,G,D,U,X,K,H)}}else Q.wireframe?na(Q.color.__styleString,Q.wireframe_linewidth):Ea(Q.color.__styleString);else if(Q instanceof THREE.MeshLambertMaterial){if(Q.map&&!Q.wireframe){Q.map.mapping instanceof THREE.UVMapping&&
+Aa(P,f,p,h,e,n,Q.map.image,E.uvs[0].u,E.uvs[0].v,E.uvs[1].u,E.uvs[1].v,E.uvs[2].u,E.uvs[2].v);c(THREE.SubtractiveBlending)}if(J)if(!Q.wireframe&&Q.shading==THREE.SmoothShading&&E.vertexNormalsWorld.length==3){t.r=q.r=k.r=ga.r;t.g=q.g=k.g=ga.g;t.b=q.b=k.b=ga.b;xa($,E.v1.positionWorld,E.vertexNormalsWorld[0],t);xa($,E.v2.positionWorld,E.vertexNormalsWorld[1],q);xa($,E.v3.positionWorld,E.vertexNormalsWorld[2],k);u.r=(q.r+k.r)*0.5;u.g=(q.g+k.g)*0.5;u.b=(q.b+k.b)*0.5;O=Ma(t,q,k,u);Aa(P,f,p,h,e,n,O,0,0,
+1,0,0,1)}else{W.r=ga.r;W.g=ga.g;W.b=ga.b;xa($,E.centroidWorld,E.normalWorld,W);j.r=Q.color.r*W.r;j.g=Q.color.g*W.g;j.b=Q.color.b*W.b;j.updateStyleString();Q.wireframe?na(j.__styleString,Q.wireframe_linewidth):Ea(j.__styleString)}else Q.wireframe?na(Q.color.__styleString,Q.wireframe_linewidth):Ea(Q.color.__styleString)}else if(Q instanceof THREE.MeshDepthMaterial){B=ma.near;v=ma.far;t.r=t.g=t.b=1-Ia(C.positionScreen.z,B,v);q.r=q.g=q.b=1-Ia(V.positionScreen.z,B,v);k.r=k.g=k.b=1-Ia(S.positionScreen.z,
+B,v);u.r=(q.r+k.r)*0.5;u.g=(q.g+k.g)*0.5;u.b=(q.b+k.b)*0.5;O=Ma(t,q,k,u);Aa(P,f,p,h,e,n,O,0,0,1,0,0,1)}else if(Q instanceof THREE.MeshNormalMaterial){j.r=Ja(E.normalWorld.x);j.g=Ja(E.normalWorld.y);j.b=Ja(E.normalWorld.z);j.updateStyleString();Q.wireframe?na(j.__styleString,Q.wireframe_linewidth):Ea(j.__styleString)}}}function na(C,V){if(I!=C)o.strokeStyle=I=C;if(L!=V)o.lineWidth=L=V;o.stroke();A.inflate(V*2)}function Ea(C){if(M!=C)o.fillStyle=M=C;o.fill()}function Aa(C,V,S,E,Q,$,fa,ja,la,ta,oa,ua,
+Ba){var ya,va;ya=fa.width-1;va=fa.height-1;ja*=ya;la*=va;ta*=ya;oa*=va;ua*=ya;Ba*=va;S-=C;E-=V;Q-=C;$-=V;ta-=ja;oa-=la;ua-=ja;Ba-=la;va=1/(ta*Ba-ua*oa);ya=(Ba*S-oa*Q)*va;oa=(Ba*E-oa*$)*va;S=(ta*Q-ua*S)*va;E=(ta*$-ua*E)*va;C=C-ya*ja-S*la;V=V-oa*ja-E*la;o.save();o.transform(ya,oa,S,E,C,V);o.clip();o.drawImage(fa,0,0);o.restore()}function Ma(C,V,S,E){var Q=~~(C.r*255),$=~~(C.g*255);C=~~(C.b*255);var fa=~~(V.r*255),ja=~~(V.g*255);V=~~(V.b*255);var la=~~(S.r*255),ta=~~(S.g*255);S=~~(S.b*255);var oa=~~(E.r*
+255),ua=~~(E.g*255);E=~~(E.b*255);ia[0]=Q<0?0:Q>255?255:Q;ia[1]=$<0?0:$>255?255:$;ia[2]=C<0?0:C>255?255:C;ia[4]=fa<0?0:fa>255?255:fa;ia[5]=ja<0?0:ja>255?255:ja;ia[6]=V<0?0:V>255?255:V;ia[8]=la<0?0:la>255?255:la;ia[9]=ta<0?0:ta>255?255:ta;ia[10]=S<0?0:S>255?255:S;ia[12]=oa<0?0:oa>255?255:oa;ia[13]=ua<0?0:ua>255?255:ua;ia[14]=E<0?0:E>255?255:E;wa.putImageData(ha,0,0);pa.drawImage(ea,0,0);return sa}function Ia(C,V,S){C=(C-V)/(S-V);return C*C*(3-2*C)}function Ja(C){C=(C+1)*0.5;return C<0?0:C>1?1:C}function Ka(C,
+V){var S=V.x-C.x,E=V.y-C.y,Q=1/Math.sqrt(S*S+E*E);S*=Q;E*=Q;V.x+=S;V.y+=E;C.x-=S;C.y-=E}var Fa,Na,ca,ra,za,La,Oa,Ca;this.autoClear?this.clear():o.setTransform(1,0,0,-1,r,m);d=g.projectScene(aa,ma,this.sortElements);(J=aa.lights.length>0)&&ka(aa);Fa=0;for(Na=d.length;Fa<Na;Fa++){ca=d[Fa];A.empty();if(ca instanceof THREE.RenderableParticle){s=ca;s.x*=r;s.y*=m;ra=0;for(za=ca.materials.length;ra<za;ra++)Ga(s,ca,ca.materials[ra],aa)}else if(ca instanceof THREE.RenderableLine){s=ca.v1;T=ca.v2;s.positionScreen.x*=
 r;s.positionScreen.y*=m;T.positionScreen.x*=r;T.positionScreen.y*=m;A.addPoint(s.positionScreen.x,s.positionScreen.y);A.addPoint(T.positionScreen.x,T.positionScreen.y);if(N.instersects(A)){ra=0;for(za=ca.materials.length;ra<za;)Ha(s,T,ca,ca.materials[ra++],aa)}}else if(ca instanceof THREE.RenderableFace3){s=ca.v1;T=ca.v2;F=ca.v3;s.positionScreen.x*=r;s.positionScreen.y*=m;T.positionScreen.x*=r;T.positionScreen.y*=m;F.positionScreen.x*=r;F.positionScreen.y*=m;if(ca.overdraw){Ka(s.positionScreen,T.positionScreen);
-Ka(T.positionScreen,F.positionScreen);Ka(F.positionScreen,s.positionScreen)}A.add3Points(s.positionScreen.x,s.positionScreen.y,T.positionScreen.x,T.positionScreen.y,F.positionScreen.x,F.positionScreen.y);if(N.instersects(A)){ra=0;for(za=ca.meshMaterials.length;ra<za;){Ca=ca.meshMaterials[ra++];if(Ca instanceof THREE.MeshFaceMaterial){La=0;for(Oa=ca.faceMaterials.length;La<Oa;)(Ca=ca.faceMaterials[La++])&&Da(s,T,F,ca,Ca,aa)}else Da(s,T,F,ca,Ca,aa)}}}R.addRectangle(A)}n.setTransform(1,0,0,1,0,0)}};
-THREE.SVGRenderer=function(){function a(G,D,V){var U,J,H,N;U=0;for(J=G.lights.length;U<J;U++){H=G.lights[U];if(H instanceof THREE.DirectionalLight){N=D.normalWorld.dot(H.position)*H.intensity;if(N>0){V.r+=H.color.r*N;V.g+=H.color.g*N;V.b+=H.color.b*N}}else if(H instanceof THREE.PointLight){o.sub(H.position,D.centroidWorld);o.normalize();N=D.normalWorld.dot(o)*H.intensity;if(N>0){V.r+=H.color.r*N;V.g+=H.color.g*N;V.b+=H.color.b*N}}}}function c(G,D,V,U,J,H){k=g(u++);k.setAttribute("d","M "+G.positionScreen.x+
-" "+G.positionScreen.y+" L "+D.positionScreen.x+" "+D.positionScreen.y+" L "+V.positionScreen.x+","+V.positionScreen.y+"z");if(J instanceof THREE.MeshBasicMaterial)F.__styleString=J.color.__styleString;else if(J instanceof THREE.MeshLambertMaterial)if(T){P.r=f.r;P.g=f.g;P.b=f.b;a(H,U,P);F.r=J.color.r*P.r;F.g=J.color.g*P.g;F.b=J.color.b*P.b;F.updateStyleString()}else F.__styleString=J.color.__styleString;else if(J instanceof THREE.MeshDepthMaterial){e=1-J.__2near/(J.__farPlusNear-U.z*J.__farMinusNear);
-F.setRGB(e,e,e)}else J instanceof THREE.MeshNormalMaterial&&F.setRGB(i(U.normalWorld.x),i(U.normalWorld.y),i(U.normalWorld.z));J.wireframe?k.setAttribute("style","fill: none; stroke: "+F.__styleString+"; stroke-width: "+J.wireframe_linewidth+"; stroke-opacity: "+J.opacity+"; stroke-linecap: "+J.wireframe_linecap+"; stroke-linejoin: "+J.wireframe_linejoin):k.setAttribute("style","fill: "+F.__styleString+"; fill-opacity: "+J.opacity);r.appendChild(k)}function d(G,D,V,U,J,H,N){k=g(u++);k.setAttribute("d",
-"M "+G.positionScreen.x+" "+G.positionScreen.y+" L "+D.positionScreen.x+" "+D.positionScreen.y+" L "+V.positionScreen.x+","+V.positionScreen.y+" L "+U.positionScreen.x+","+U.positionScreen.y+"z");if(H instanceof THREE.MeshBasicMaterial)F.__styleString=H.color.__styleString;else if(H instanceof THREE.MeshLambertMaterial)if(T){P.r=f.r;P.g=f.g;P.b=f.b;a(N,J,P);F.r=H.color.r*P.r;F.g=H.color.g*P.g;F.b=H.color.b*P.b;F.updateStyleString()}else F.__styleString=H.color.__styleString;else if(H instanceof THREE.MeshDepthMaterial){e=
-1-H.__2near/(H.__farPlusNear-J.z*H.__farMinusNear);F.setRGB(e,e,e)}else H instanceof THREE.MeshNormalMaterial&&F.setRGB(i(J.normalWorld.x),i(J.normalWorld.y),i(J.normalWorld.z));H.wireframe?k.setAttribute("style","fill: none; stroke: "+F.__styleString+"; stroke-width: "+H.wireframe_linewidth+"; stroke-opacity: "+H.opacity+"; stroke-linecap: "+H.wireframe_linecap+"; stroke-linejoin: "+H.wireframe_linejoin):k.setAttribute("style","fill: "+F.__styleString+"; fill-opacity: "+H.opacity);r.appendChild(k)}
-function g(G){if(j[G]==null){j[G]=document.createElementNS("http://www.w3.org/2000/svg","path");O==0&&j[G].setAttribute("shape-rendering","crispEdges");return j[G]}return j[G]}function i(G){return G<0?Math.min((1+G)*0.5,0.5):0.5+Math.min(G*0.5,0.5)}var l=null,b=new THREE.Projector,r=document.createElementNS("http://www.w3.org/2000/svg","svg"),m,n,z,y,w,x,I,M,L=new THREE.Rectangle,s=new THREE.Rectangle,T=false,F=new THREE.Color(16777215),P=new THREE.Color(16777215),f=new THREE.Color(0),p=new THREE.Color(0),
-h=new THREE.Color(0),e,o=new THREE.Vector3,j=[],t=[],q=[],k,u,B,v,O=1;this.domElement=r;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(G){switch(G){case "high":O=1;break;case "low":O=0}};this.setSize=function(G,D){m=G;n=D;z=m/2;y=n/2;r.setAttribute("viewBox",-z+" "+-y+" "+m+" "+n);r.setAttribute("width",m);r.setAttribute("height",n);L.set(-z,-y,z,y)};this.clear=function(){for(;r.childNodes.length>0;)r.removeChild(r.childNodes[0])};this.render=function(G,D){var V,U,
-J,H,N,R,A,K;this.autoClear&&this.clear();l=b.projectScene(G,D,this.sortElements);v=B=u=0;if(T=G.lights.length>0){A=G.lights;f.setRGB(0,0,0);p.setRGB(0,0,0);h.setRGB(0,0,0);V=0;for(U=A.length;V<U;V++){J=A[V];H=J.color;if(J instanceof THREE.AmbientLight){f.r+=H.r;f.g+=H.g;f.b+=H.b}else if(J instanceof THREE.DirectionalLight){p.r+=H.r;p.g+=H.g;p.b+=H.b}else if(J instanceof THREE.PointLight){h.r+=H.r;h.g+=H.g;h.b+=H.b}}}V=0;for(U=l.length;V<U;V++){A=l[V];s.empty();if(A instanceof THREE.RenderableParticle){w=
-A;w.x*=z;w.y*=-y;J=0;for(H=A.materials.length;J<H;J++)if(K=A.materials[J]){N=w;R=A;K=K;var X=B++;if(t[X]==null){t[X]=document.createElementNS("http://www.w3.org/2000/svg","circle");O==0&&t[X].setAttribute("shape-rendering","crispEdges")}k=t[X];k.setAttribute("cx",N.x);k.setAttribute("cy",N.y);k.setAttribute("r",R.scale.x*z);if(K instanceof THREE.ParticleCircleMaterial){if(T){P.r=f.r+p.r+h.r;P.g=f.g+p.g+h.g;P.b=f.b+p.b+h.b;F.r=K.color.r*P.r;F.g=K.color.g*P.g;F.b=K.color.b*P.b;F.updateStyleString()}else F=
-K.color;k.setAttribute("style","fill: "+F.__styleString)}r.appendChild(k)}}else if(A instanceof THREE.RenderableLine){w=A.v1;x=A.v2;w.positionScreen.x*=z;w.positionScreen.y*=-y;x.positionScreen.x*=z;x.positionScreen.y*=-y;s.addPoint(w.positionScreen.x,w.positionScreen.y);s.addPoint(x.positionScreen.x,x.positionScreen.y);if(L.instersects(s)){J=0;for(H=A.materials.length;J<H;)if(K=A.materials[J++]){N=w;R=x;K=K;X=v++;if(q[X]==null){q[X]=document.createElementNS("http://www.w3.org/2000/svg","line");O==
-0&&q[X].setAttribute("shape-rendering","crispEdges")}k=q[X];k.setAttribute("x1",N.positionScreen.x);k.setAttribute("y1",N.positionScreen.y);k.setAttribute("x2",R.positionScreen.x);k.setAttribute("y2",R.positionScreen.y);if(K instanceof THREE.LineBasicMaterial){F.__styleString=K.color.__styleString;k.setAttribute("style","fill: none; stroke: "+F.__styleString+"; stroke-width: "+K.linewidth+"; stroke-opacity: "+K.opacity+"; stroke-linecap: "+K.linecap+"; stroke-linejoin: "+K.linejoin);r.appendChild(k)}}}}else if(A instanceof
-THREE.RenderableFace3){w=A.v1;x=A.v2;I=A.v3;w.positionScreen.x*=z;w.positionScreen.y*=-y;x.positionScreen.x*=z;x.positionScreen.y*=-y;I.positionScreen.x*=z;I.positionScreen.y*=-y;s.addPoint(w.positionScreen.x,w.positionScreen.y);s.addPoint(x.positionScreen.x,x.positionScreen.y);s.addPoint(I.positionScreen.x,I.positionScreen.y);if(L.instersects(s)){J=0;for(H=A.meshMaterials.length;J<H;){K=A.meshMaterials[J++];if(K instanceof THREE.MeshFaceMaterial){N=0;for(R=A.faceMaterials.length;N<R;)(K=A.faceMaterials[N++])&&
-c(w,x,I,A,K,G)}else K&&c(w,x,I,A,K,G)}}}else if(A instanceof THREE.RenderableFace4){w=A.v1;x=A.v2;I=A.v3;M=A.v4;w.positionScreen.x*=z;w.positionScreen.y*=-y;x.positionScreen.x*=z;x.positionScreen.y*=-y;I.positionScreen.x*=z;I.positionScreen.y*=-y;M.positionScreen.x*=z;M.positionScreen.y*=-y;s.addPoint(w.positionScreen.x,w.positionScreen.y);s.addPoint(x.positionScreen.x,x.positionScreen.y);s.addPoint(I.positionScreen.x,I.positionScreen.y);s.addPoint(M.positionScreen.x,M.positionScreen.y);if(L.instersects(s)){J=
-0;for(H=A.meshMaterials.length;J<H;){K=A.meshMaterials[J++];if(K instanceof THREE.MeshFaceMaterial){N=0;for(R=A.faceMaterials.length;N<R;)(K=A.faceMaterials[N++])&&d(w,x,I,M,A,K,G)}else K&&d(w,x,I,M,A,K,G)}}}}}};
+Ka(T.positionScreen,F.positionScreen);Ka(F.positionScreen,s.positionScreen)}A.add3Points(s.positionScreen.x,s.positionScreen.y,T.positionScreen.x,T.positionScreen.y,F.positionScreen.x,F.positionScreen.y);if(N.instersects(A)){ra=0;for(za=ca.meshMaterials.length;ra<za;){Ca=ca.meshMaterials[ra++];if(Ca instanceof THREE.MeshFaceMaterial){La=0;for(Oa=ca.faceMaterials.length;La<Oa;)(Ca=ca.faceMaterials[La++])&&Da(s,T,F,ca,Ca,aa)}else Da(s,T,F,ca,Ca,aa)}}}R.addRectangle(A)}o.setTransform(1,0,0,1,0,0)}};
+THREE.SVGRenderer=function(){function a(G,D,U){var X,K,H,N;X=0;for(K=G.lights.length;X<K;X++){H=G.lights[X];if(H instanceof THREE.DirectionalLight){N=D.normalWorld.dot(H.position)*H.intensity;if(N>0){U.r+=H.color.r*N;U.g+=H.color.g*N;U.b+=H.color.b*N}}else if(H instanceof THREE.PointLight){n.sub(H.position,D.centroidWorld);n.normalize();N=D.normalWorld.dot(n)*H.intensity;if(N>0){U.r+=H.color.r*N;U.g+=H.color.g*N;U.b+=H.color.b*N}}}}function c(G,D,U,X,K,H){k=g(u++);k.setAttribute("d","M "+G.positionScreen.x+
+" "+G.positionScreen.y+" L "+D.positionScreen.x+" "+D.positionScreen.y+" L "+U.positionScreen.x+","+U.positionScreen.y+"z");if(K instanceof THREE.MeshBasicMaterial)F.__styleString=K.color.__styleString;else if(K instanceof THREE.MeshLambertMaterial)if(T){P.r=f.r;P.g=f.g;P.b=f.b;a(H,X,P);F.r=K.color.r*P.r;F.g=K.color.g*P.g;F.b=K.color.b*P.b;F.updateStyleString()}else F.__styleString=K.color.__styleString;else if(K instanceof THREE.MeshDepthMaterial){e=1-K.__2near/(K.__farPlusNear-X.z*K.__farMinusNear);
+F.setRGB(e,e,e)}else K instanceof THREE.MeshNormalMaterial&&F.setRGB(i(X.normalWorld.x),i(X.normalWorld.y),i(X.normalWorld.z));K.wireframe?k.setAttribute("style","fill: none; stroke: "+F.__styleString+"; stroke-width: "+K.wireframe_linewidth+"; stroke-opacity: "+K.opacity+"; stroke-linecap: "+K.wireframe_linecap+"; stroke-linejoin: "+K.wireframe_linejoin):k.setAttribute("style","fill: "+F.__styleString+"; fill-opacity: "+K.opacity);r.appendChild(k)}function d(G,D,U,X,K,H,N){k=g(u++);k.setAttribute("d",
+"M "+G.positionScreen.x+" "+G.positionScreen.y+" L "+D.positionScreen.x+" "+D.positionScreen.y+" L "+U.positionScreen.x+","+U.positionScreen.y+" L "+X.positionScreen.x+","+X.positionScreen.y+"z");if(H instanceof THREE.MeshBasicMaterial)F.__styleString=H.color.__styleString;else if(H instanceof THREE.MeshLambertMaterial)if(T){P.r=f.r;P.g=f.g;P.b=f.b;a(N,K,P);F.r=H.color.r*P.r;F.g=H.color.g*P.g;F.b=H.color.b*P.b;F.updateStyleString()}else F.__styleString=H.color.__styleString;else if(H instanceof THREE.MeshDepthMaterial){e=
+1-H.__2near/(H.__farPlusNear-K.z*H.__farMinusNear);F.setRGB(e,e,e)}else H instanceof THREE.MeshNormalMaterial&&F.setRGB(i(K.normalWorld.x),i(K.normalWorld.y),i(K.normalWorld.z));H.wireframe?k.setAttribute("style","fill: none; stroke: "+F.__styleString+"; stroke-width: "+H.wireframe_linewidth+"; stroke-opacity: "+H.opacity+"; stroke-linecap: "+H.wireframe_linecap+"; stroke-linejoin: "+H.wireframe_linejoin):k.setAttribute("style","fill: "+F.__styleString+"; fill-opacity: "+H.opacity);r.appendChild(k)}
+function g(G){if(j[G]==null){j[G]=document.createElementNS("http://www.w3.org/2000/svg","path");O==0&&j[G].setAttribute("shape-rendering","crispEdges");return j[G]}return j[G]}function i(G){return G<0?Math.min((1+G)*0.5,0.5):0.5+Math.min(G*0.5,0.5)}var l=null,b=new THREE.Projector,r=document.createElementNS("http://www.w3.org/2000/svg","svg"),m,o,z,y,w,x,I,M,L=new THREE.Rectangle,s=new THREE.Rectangle,T=false,F=new THREE.Color(16777215),P=new THREE.Color(16777215),f=new THREE.Color(0),p=new THREE.Color(0),
+h=new THREE.Color(0),e,n=new THREE.Vector3,j=[],t=[],q=[],k,u,B,v,O=1;this.domElement=r;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(G){switch(G){case "high":O=1;break;case "low":O=0}};this.setSize=function(G,D){m=G;o=D;z=m/2;y=o/2;r.setAttribute("viewBox",-z+" "+-y+" "+m+" "+o);r.setAttribute("width",m);r.setAttribute("height",o);L.set(-z,-y,z,y)};this.clear=function(){for(;r.childNodes.length>0;)r.removeChild(r.childNodes[0])};this.render=function(G,D){var U,X,
+K,H,N,R,A,J;this.autoClear&&this.clear();l=b.projectScene(G,D,this.sortElements);v=B=u=0;if(T=G.lights.length>0){A=G.lights;f.setRGB(0,0,0);p.setRGB(0,0,0);h.setRGB(0,0,0);U=0;for(X=A.length;U<X;U++){K=A[U];H=K.color;if(K instanceof THREE.AmbientLight){f.r+=H.r;f.g+=H.g;f.b+=H.b}else if(K instanceof THREE.DirectionalLight){p.r+=H.r;p.g+=H.g;p.b+=H.b}else if(K instanceof THREE.PointLight){h.r+=H.r;h.g+=H.g;h.b+=H.b}}}U=0;for(X=l.length;U<X;U++){A=l[U];s.empty();if(A instanceof THREE.RenderableParticle){w=
+A;w.x*=z;w.y*=-y;K=0;for(H=A.materials.length;K<H;K++)if(J=A.materials[K]){N=w;R=A;J=J;var W=B++;if(t[W]==null){t[W]=document.createElementNS("http://www.w3.org/2000/svg","circle");O==0&&t[W].setAttribute("shape-rendering","crispEdges")}k=t[W];k.setAttribute("cx",N.x);k.setAttribute("cy",N.y);k.setAttribute("r",R.scale.x*z);if(J instanceof THREE.ParticleCircleMaterial){if(T){P.r=f.r+p.r+h.r;P.g=f.g+p.g+h.g;P.b=f.b+p.b+h.b;F.r=J.color.r*P.r;F.g=J.color.g*P.g;F.b=J.color.b*P.b;F.updateStyleString()}else F=
+J.color;k.setAttribute("style","fill: "+F.__styleString)}r.appendChild(k)}}else if(A instanceof THREE.RenderableLine){w=A.v1;x=A.v2;w.positionScreen.x*=z;w.positionScreen.y*=-y;x.positionScreen.x*=z;x.positionScreen.y*=-y;s.addPoint(w.positionScreen.x,w.positionScreen.y);s.addPoint(x.positionScreen.x,x.positionScreen.y);if(L.instersects(s)){K=0;for(H=A.materials.length;K<H;)if(J=A.materials[K++]){N=w;R=x;J=J;W=v++;if(q[W]==null){q[W]=document.createElementNS("http://www.w3.org/2000/svg","line");O==
+0&&q[W].setAttribute("shape-rendering","crispEdges")}k=q[W];k.setAttribute("x1",N.positionScreen.x);k.setAttribute("y1",N.positionScreen.y);k.setAttribute("x2",R.positionScreen.x);k.setAttribute("y2",R.positionScreen.y);if(J instanceof THREE.LineBasicMaterial){F.__styleString=J.color.__styleString;k.setAttribute("style","fill: none; stroke: "+F.__styleString+"; stroke-width: "+J.linewidth+"; stroke-opacity: "+J.opacity+"; stroke-linecap: "+J.linecap+"; stroke-linejoin: "+J.linejoin);r.appendChild(k)}}}}else if(A instanceof
+THREE.RenderableFace3){w=A.v1;x=A.v2;I=A.v3;w.positionScreen.x*=z;w.positionScreen.y*=-y;x.positionScreen.x*=z;x.positionScreen.y*=-y;I.positionScreen.x*=z;I.positionScreen.y*=-y;s.addPoint(w.positionScreen.x,w.positionScreen.y);s.addPoint(x.positionScreen.x,x.positionScreen.y);s.addPoint(I.positionScreen.x,I.positionScreen.y);if(L.instersects(s)){K=0;for(H=A.meshMaterials.length;K<H;){J=A.meshMaterials[K++];if(J instanceof THREE.MeshFaceMaterial){N=0;for(R=A.faceMaterials.length;N<R;)(J=A.faceMaterials[N++])&&
+c(w,x,I,A,J,G)}else J&&c(w,x,I,A,J,G)}}}else if(A instanceof THREE.RenderableFace4){w=A.v1;x=A.v2;I=A.v3;M=A.v4;w.positionScreen.x*=z;w.positionScreen.y*=-y;x.positionScreen.x*=z;x.positionScreen.y*=-y;I.positionScreen.x*=z;I.positionScreen.y*=-y;M.positionScreen.x*=z;M.positionScreen.y*=-y;s.addPoint(w.positionScreen.x,w.positionScreen.y);s.addPoint(x.positionScreen.x,x.positionScreen.y);s.addPoint(I.positionScreen.x,I.positionScreen.y);s.addPoint(M.positionScreen.x,M.positionScreen.y);if(L.instersects(s)){K=
+0;for(H=A.meshMaterials.length;K<H;){J=A.meshMaterials[K++];if(J instanceof THREE.MeshFaceMaterial){N=0;for(R=A.faceMaterials.length;N<R;)(J=A.faceMaterials[N++])&&d(w,x,I,M,A,J,G)}else J&&d(w,x,I,M,A,J,G)}}}}}};
 THREE.WebGLRenderer=function(a){function c(f,p){f.fragment_shader=p.fragment_shader;f.vertex_shader=p.vertex_shader;f.uniforms=Uniforms.clone(p.uniforms)}function d(f){if(f.doubleSided)b.disable(b.CULL_FACE);else{b.enable(b.CULL_FACE);f.flipSided?b.frontFace(b.CW):b.frontFace(b.CCW)}}function g(f,p){var h;if(f=="fragment")h=b.createShader(b.FRAGMENT_SHADER);else if(f=="vertex")h=b.createShader(b.VERTEX_SHADER);b.shaderSource(h,p);b.compileShader(h);if(!b.getShaderParameter(h,b.COMPILE_STATUS)){alert(b.getShaderInfoLog(h));
 return null}return h}function i(f){switch(f){case THREE.RepeatWrapping:return b.REPEAT;case THREE.ClampToEdgeWrapping:return b.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return b.MIRRORED_REPEAT;case THREE.NearestFilter:return b.NEAREST;case THREE.NearestMipMapNearestFilter:return b.NEAREST_MIPMAP_NEAREST;case THREE.NearestMipMapLinearFilter:return b.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return b.LINEAR;case THREE.LinearMipMapNearestFilter:return b.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return b.LINEAR_MIPMAP_LINEAR;
 case THREE.ByteType:return b.BYTE;case THREE.UnsignedByteType:return b.UNSIGNED_BYTE;case THREE.ShortType:return b.SHORT;case THREE.UnsignedShortType:return b.UNSIGNED_SHORT;case THREE.IntType:return b.INT;case THREE.UnsignedShortType:return b.UNSIGNED_INT;case THREE.FloatType:return b.FLOAT;case THREE.AlphaFormat:return b.ALPHA;case THREE.RGBFormat:return b.RGB;case THREE.RGBAFormat:return b.RGBA;case THREE.LuminanceFormat:return b.LUMINANCE;case THREE.LuminanceAlphaFormat:return b.LUMINANCE_ALPHA}return 0}
-var l=document.createElement("canvas"),b,r=null,m=null,n=new THREE.Matrix4,z,y=new Float32Array(16),w=new Float32Array(16),x=new Float32Array(16),I=new Float32Array(9),M=new Float32Array(16),L=new THREE.Matrix4,s=new THREE.Vector4,T=true,F=new THREE.Color(0),P=0;if(a){if(a.antialias!==undefined)T=a.antialias;a.clearColor!==undefined&&F.setHex(a.clearColor);if(a.clearAlpha!==undefined)P=a.clearAlpha}this.domElement=l;this.autoClear=true;(function(f,p,h){try{b=l.getContext("experimental-webgl",{antialias:f})}catch(e){console.log(e)}if(!b){alert("WebGL not supported");
+var l=document.createElement("canvas"),b,r=null,m=null,o=new THREE.Matrix4,z,y=new Float32Array(16),w=new Float32Array(16),x=new Float32Array(16),I=new Float32Array(9),M=new Float32Array(16),L=new THREE.Matrix4,s=new THREE.Vector4,T=true,F=new THREE.Color(0),P=0;if(a){if(a.antialias!==undefined)T=a.antialias;a.clearColor!==undefined&&F.setHex(a.clearColor);if(a.clearAlpha!==undefined)P=a.clearAlpha}this.domElement=l;this.autoClear=true;(function(f,p,h){try{b=l.getContext("experimental-webgl",{antialias:f})}catch(e){console.log(e)}if(!b){alert("WebGL not supported");
 throw"cannot create webgl context";}b.clearColor(0,0,0,1);b.clearDepth(1);b.enable(b.DEPTH_TEST);b.depthFunc(b.LEQUAL);b.frontFace(b.CCW);b.cullFace(b.BACK);b.enable(b.CULL_FACE);b.enable(b.BLEND);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA);b.clearColor(p.r,p.g,p.b,h)})(T,F,P);this.context=b;this.lights={ambient:[0,0,0],directional:{length:0,colors:[],positions:[]},point:{length:0,colors:[],positions:[]}};this.setSize=function(f,p){l.width=f;l.height=p;b.viewport(0,0,l.width,l.height)};this.setClearColorHex=
-function(f,p){var h=new THREE.Color(f);b.clearColor(h.r,h.g,h.b,p)};this.setClearColor=function(f,p){b.clearColor(f.r,f.g,f.b,p)};this.clear=function(){b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT)};this.setupLights=function(f,p){var h,e,o,j=0,t=0,q=0,k,u,B,v=this.lights,O=v.directional.colors,G=v.directional.positions,D=v.point.colors,V=v.point.positions,U=0,J=0;h=0;for(e=p.length;h<e;h++){o=p[h];k=o.color;u=o.position;B=o.intensity;if(o instanceof THREE.AmbientLight){j+=k.r;t+=k.g;q+=k.b}else if(o instanceof
-THREE.DirectionalLight){O[U*3]=k.r*B;O[U*3+1]=k.g*B;O[U*3+2]=k.b*B;G[U*3]=u.x;G[U*3+1]=u.y;G[U*3+2]=u.z;U+=1}else if(o instanceof THREE.PointLight){D[J*3]=k.r*B;D[J*3+1]=k.g*B;D[J*3+2]=k.b*B;V[J*3]=u.x;V[J*3+1]=u.y;V[J*3+2]=u.z;J+=1}}v.point.length=J;v.directional.length=U;v.ambient[0]=j;v.ambient[1]=t;v.ambient[2]=q};this.createParticleBuffers=function(f){f.__webGLVertexBuffer=b.createBuffer();f.__webGLColorBuffer=b.createBuffer();f.__webGLParticleBuffer=b.createBuffer()};this.createLineBuffers=
-function(f){f.__webGLVertexBuffer=b.createBuffer();f.__webGLColorBuffer=b.createBuffer();f.__webGLLineBuffer=b.createBuffer()};this.createMeshBuffers=function(f){f.__webGLVertexBuffer=b.createBuffer();f.__webGLNormalBuffer=b.createBuffer();f.__webGLTangentBuffer=b.createBuffer();f.__webGLColorBuffer=b.createBuffer();f.__webGLUVBuffer=b.createBuffer();f.__webGLUV2Buffer=b.createBuffer();f.__webGLFaceBuffer=b.createBuffer();f.__webGLLineBuffer=b.createBuffer()};this.initLineBuffers=function(f){var p=
-f.vertices.length;f.__vertexArray=new Float32Array(p*3);f.__colorArray=new Float32Array(p*3);f.__lineArray=new Uint16Array(p);f.__webGLLineCount=p};this.initParticleBuffers=function(f){var p=f.vertices.length;f.__vertexArray=new Float32Array(p*3);f.__colorArray=new Float32Array(p*3);f.__particleArray=new Uint16Array(p);f.__sortArray=[];f.__webGLParticleCount=p};this.initMeshBuffers=function(f,p){var h,e,o=0,j=0,t=0,q=p.geometry.faces,k=f.faces;h=0;for(e=k.length;h<e;h++){fi=k[h];face=q[fi];if(face instanceof
-THREE.Face3){o+=3;j+=1;t+=3}else if(face instanceof THREE.Face4){o+=4;j+=2;t+=4}}f.__vertexArray=new Float32Array(o*3);f.__normalArray=new Float32Array(o*3);f.__tangentArray=new Float32Array(o*4);f.__colorArray=new Float32Array(o*3);f.__uvArray=new Float32Array(o*2);f.__uv2Array=new Float32Array(o*2);f.__faceArray=new Uint16Array(j*3);f.__lineArray=new Uint16Array(t*2);o=false;h=0;for(e=p.materials.length;h<e;h++){q=p.materials[h];if(q instanceof THREE.MeshFaceMaterial){q=0;for(k=f.materials.length;q<
-k;q++)if(f.materials[q]&&f.materials[q].shading!=undefined&&f.materials[q].shading==THREE.SmoothShading){o=true;break}}else if(q&&q.shading!=undefined&&q.shading==THREE.SmoothShading){o=true;break}if(o)break}f.__needsSmoothNormals=o;f.__webGLFaceCount=j*3;f.__webGLLineCount=t*2};this.setMeshBuffers=function(f,p,h){var e,o,j,t,q,k,u,B,v,O,G=0,D=0,V=0,U=0,J=0,H=0,N=0,R=0,A=0,K=f.__vertexArray,X=f.__uvArray,ga=f.__uv2Array,da=f.__normalArray,Y=f.__tangentArray,ba=f.__colorArray,Z=f.__faceArray,ea=f.__lineArray,
-wa=f.__needsSmoothNormals,ha=p.geometry,ia=ha.__dirtyVertices,sa=ha.__dirtyElements,pa=ha.__dirtyUvs,qa=ha.__dirtyNormals,aa=ha.__dirtyTangents,ma=ha.__dirtyColors,ka=ha.vertices,xa=f.faces,Ga=ha.faces,Ha=ha.uvs,Da=ha.uvs2,na=ha.colors;p=0;for(e=xa.length;p<e;p++){o=xa[p];j=Ga[o];k=Ha[o];o=Da[o];t=j.vertexNormals;q=j.normal;if(j instanceof THREE.Face3){if(ia){u=ka[j.a].position;B=ka[j.b].position;v=ka[j.c].position;K[D]=u.x;K[D+1]=u.y;K[D+2]=u.z;K[D+3]=B.x;K[D+4]=B.y;K[D+5]=B.z;K[D+6]=v.x;K[D+7]=
-v.y;K[D+8]=v.z;D+=9}if(ma&&na.length){u=na[j.a];B=na[j.b];v=na[j.c];ba[A]=u.r;ba[A+1]=u.g;ba[A+2]=u.b;ba[A+3]=B.r;ba[A+4]=B.g;ba[A+5]=B.b;ba[A+6]=v.r;ba[A+7]=v.g;ba[A+8]=v.b;A+=9}if(aa&&ha.hasTangents){u=ka[j.a].tangent;B=ka[j.b].tangent;v=ka[j.c].tangent;Y[N]=u.x;Y[N+1]=u.y;Y[N+2]=u.z;Y[N+3]=u.w;Y[N+4]=B.x;Y[N+5]=B.y;Y[N+6]=B.z;Y[N+7]=B.w;Y[N+8]=v.x;Y[N+9]=v.y;Y[N+10]=v.z;Y[N+11]=v.w;N+=12}if(qa)if(t.length==3&&wa)for(j=0;j<3;j++){q=t[j];da[H]=q.x;da[H+1]=q.y;da[H+2]=q.z;H+=3}else for(j=0;j<3;j++){da[H]=
-q.x;da[H+1]=q.y;da[H+2]=q.z;H+=3}if(pa&&k)for(j=0;j<3;j++){t=k[j];X[V]=t.u;X[V+1]=t.v;V+=2}if(pa&&o)for(j=0;j<3;j++){k=o[j];ga[U]=k.u;ga[U+1]=k.v;U+=2}if(sa){Z[J]=G;Z[J+1]=G+1;Z[J+2]=G+2;J+=3;ea[R]=G;ea[R+1]=G+1;ea[R+2]=G;ea[R+3]=G+2;ea[R+4]=G+1;ea[R+5]=G+2;R+=6;G+=3}}else if(j instanceof THREE.Face4){if(ia){u=ka[j.a].position;B=ka[j.b].position;v=ka[j.c].position;O=ka[j.d].position;K[D]=u.x;K[D+1]=u.y;K[D+2]=u.z;K[D+3]=B.x;K[D+4]=B.y;K[D+5]=B.z;K[D+6]=v.x;K[D+7]=v.y;K[D+8]=v.z;K[D+9]=O.x;K[D+10]=
-O.y;K[D+11]=O.z;D+=12}if(ma&&na.length){u=na[j.a];B=na[j.b];v=na[j.d];ba[A]=u.r;ba[A+1]=u.g;ba[A+2]=u.b;ba[A+3]=B.r;ba[A+4]=B.g;ba[A+5]=B.b;ba[A+6]=v.r;ba[A+7]=v.g;ba[A+8]=v.b;ba[A+9]=(void 0).r;ba[A+10]=(void 0).g;ba[A+11]=(void 0).b;A+=12}if(aa&&ha.hasTangents){u=ka[j.a].tangent;B=ka[j.b].tangent;v=ka[j.c].tangent;j=ka[j.d].tangent;Y[N]=u.x;Y[N+1]=u.y;Y[N+2]=u.z;Y[N+3]=u.w;Y[N+4]=B.x;Y[N+5]=B.y;Y[N+6]=B.z;Y[N+7]=B.w;Y[N+8]=v.x;Y[N+9]=v.y;Y[N+10]=v.z;Y[N+11]=v.w;Y[N+12]=j.x;Y[N+13]=j.y;Y[N+14]=j.z;
-Y[N+15]=j.w;N+=16}if(qa)if(t.length==4&&wa)for(j=0;j<4;j++){q=t[j];da[H]=q.x;da[H+1]=q.y;da[H+2]=q.z;H+=3}else for(j=0;j<4;j++){da[H]=q.x;da[H+1]=q.y;da[H+2]=q.z;H+=3}if(pa&&k)for(j=0;j<4;j++){t=k[j];X[V]=t.u;X[V+1]=t.v;V+=2}if(pa&&o)for(j=0;j<4;j++){k=o[j];ga[U]=k.u;ga[U+1]=k.v;U+=2}if(sa){Z[J]=G;Z[J+1]=G+1;Z[J+2]=G+2;Z[J+3]=G;Z[J+4]=G+2;Z[J+5]=G+3;J+=6;ea[R]=G;ea[R+1]=G+1;ea[R+2]=G;ea[R+3]=G+3;ea[R+4]=G+1;ea[R+5]=G+2;ea[R+6]=G+2;ea[R+7]=G+3;R+=8;G+=4}}}if(ia){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLVertexBuffer);
-b.bufferData(b.ARRAY_BUFFER,K,h)}if(ma&&na.length){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLColorBuffer);b.bufferData(b.ARRAY_BUFFER,ba,h)}if(qa){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,da,h)}if(aa&&ha.hasTangents){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLTangentBuffer);b.bufferData(b.ARRAY_BUFFER,Y,h)}if(pa&&V>0){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLUVBuffer);b.bufferData(b.ARRAY_BUFFER,X,h)}if(pa&&U>0){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLUV2Buffer);b.bufferData(b.ARRAY_BUFFER,
-ga,h)}if(sa){b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,f.__webGLFaceBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,Z,h);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,f.__webGLLineBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,ea,h)}};this.setLineBuffers=function(f,p){var h,e,o,j=f.vertices,t=f.colors,q=j.length,k=t.length,u=f.__vertexArray,B=f.__colorArray,v=f.__lineArray,O=f.__dirtyColors,G=f.__dirtyElements;if(f.__dirtyVertices){for(h=0;h<q;h++){e=j[h].position;o=h*3;u[o]=e.x;u[o+1]=e.y;u[o+2]=e.z}b.bindBuffer(b.ARRAY_BUFFER,
-f.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,u,p)}if(O){for(h=0;h<k;h++){color=t[h];o=h*3;B[o]=color.r;B[o+1]=color.g;B[o+2]=color.b}b.bindBuffer(b.ARRAY_BUFFER,f.__webGLColorBuffer);b.bufferData(b.ARRAY_BUFFER,B,p)}if(G){for(h=0;h<q;h++)v[h]=h;b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,f.__webGLLineBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,v,p)}};this.setParticleBuffers=function(f,p,h,e){var o,j,t;j=f.vertices;var q=j.length,k=f.colors,u=k.length,B=f.__vertexArray,v=f.__particleArray,O=f.__colorArray,
-G=f.__sortArray,D=f.__dirtyVertices,V=f.__dirtyElements,U=f.__dirtyColors;if(h.sortParticles){L.multiply(e.projectionMatrix,e.matrix);L.multiplySelf(h.matrix);for(o=0;o<q;o++){t=j[o].position;s.copy(t);L.multiplyVector3(s);G[o]=[s.z,o]}G.sort(function(J,H){return H[0]-J[0]});for(o=0;o<q;o++){t=j[G[o][1]].position;e=o*3;B[e]=t.x;B[e+1]=t.y;B[e+2]=t.z}for(j=0;j<u;j++){e=j*3;color=k[G[j][1]];O[e]=color.r;O[e+1]=color.g;O[e+2]=color.b}}else{if(D)for(o=0;o<q;o++){t=j[o].position;e=o*3;B[e]=t.x;B[e+1]=
-t.y;B[e+2]=t.z}if(U)for(j=0;j<u;j++){color=k[j];e=j*3;O[e]=color.r;O[e+1]=color.g;O[e+2]=color.b}}if(V){for(o=0;o<q;o++)v[o]=o;b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,f.__webGLParticleBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,v,p)}if(D||h.sortParticles){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,B,p)}if(U||h.sortParticles){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLColorBuffer);b.bufferData(b.ARRAY_BUFFER,O,p)}};this.initMaterial=function(f,p,h){if(!f.program){var e,o;
-if(f instanceof THREE.MeshDepthMaterial)c(f,THREE.ShaderLib.depth);else if(f instanceof THREE.MeshNormalMaterial)c(f,THREE.ShaderLib.normal);else if(f instanceof THREE.MeshBasicMaterial)c(f,THREE.ShaderLib.basic);else if(f instanceof THREE.MeshLambertMaterial)c(f,THREE.ShaderLib.lambert);else if(f instanceof THREE.MeshPhongMaterial)c(f,THREE.ShaderLib.phong);else if(f instanceof THREE.LineBasicMaterial)c(f,THREE.ShaderLib.basic);else f instanceof THREE.ParticleBasicMaterial&&c(f,THREE.ShaderLib.particle_basic);
-var j,t,q,k;o=q=k=0;for(j=p.length;o<j;o++){t=p[o];t instanceof THREE.DirectionalLight&&q++;t instanceof THREE.PointLight&&k++}if(k+q<=4){p=q;k=k}else{p=Math.ceil(4*q/(k+q));k=4-p}o={directional:p,point:k};k=f.fragment_shader;p=f.vertex_shader;j={fog:h,map:f.map,env_map:f.env_map,light_map:f.light_map,vertex_colors:f.vertex_colors,maxDirLights:o.directional,maxPointLights:o.point};h=b.createProgram();o=["#ifdef GL_ES\nprecision highp float;\n#endif","#define MAX_DIR_LIGHTS "+j.maxDirLights,"#define MAX_POINT_LIGHTS "+
-j.maxPointLights,j.fog?"#define USE_FOG":"",j.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",j.map?"#define USE_MAP":"",j.env_map?"#define USE_ENVMAP":"",j.light_map?"#define USE_LIGHTMAP":"",j.vertex_colors?"#define USE_COLOR":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");j=[b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+j.maxDirLights,"#define MAX_POINT_LIGHTS "+j.maxPointLights,j.map?"#define USE_MAP":"",
-j.env_map?"#define USE_ENVMAP":"",j.light_map?"#define USE_LIGHTMAP":"",j.vertex_colors?"#define USE_COLOR":"","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 vec3 color;\nattribute vec2 uv;\nattribute vec2 uv2;\n"].join("\n");b.attachShader(h,g("fragment",o+k));b.attachShader(h,g("vertex",j+p));b.linkProgram(h);
-b.getProgramParameter(h,b.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+b.getProgramParameter(h,b.VALIDATE_STATUS)+", gl error ["+b.getError()+"]");h.uniforms={};h.attributes={};f.program=h;h=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(e in f.uniforms)h.push(e);e=f.program;k=0;for(p=h.length;k<p;k++){o=h[k];e.uniforms[o]=b.getUniformLocation(e,o)}f=f.program;e=["position","normal","uv","uv2","tangent","color"];h=0;
-for(k=e.length;h<k;h++){p=e[h];f.attributes[p]=b.getAttribLocation(f,p)}}};this.setProgram=function(f,p,h,e){this.initMaterial(e,p,h);var o=e.program;if(o!=r){b.useProgram(o);r=o}this.loadCamera(o,f);this.loadMatrices(o);if(e instanceof THREE.MeshPhongMaterial||e instanceof THREE.MeshLambertMaterial){this.setupLights(o,p);p=this.lights;e.uniforms.enableLighting.value=p.directional.length+p.point.length;e.uniforms.ambientLightColor.value=p.ambient;e.uniforms.directionalLightColor.value=p.directional.colors;
-e.uniforms.directionalLightDirection.value=p.directional.positions;e.uniforms.pointLightColor.value=p.point.colors;e.uniforms.pointLightPosition.value=p.point.positions}if(e instanceof THREE.MeshBasicMaterial||e instanceof THREE.MeshLambertMaterial||e instanceof THREE.MeshPhongMaterial){e.uniforms.diffuse.value.setRGB(e.color.r*e.opacity,e.color.g*e.opacity,e.color.b*e.opacity);e.uniforms.opacity.value=e.opacity;e.uniforms.map.texture=e.map;e.uniforms.light_map.texture=e.light_map;e.uniforms.env_map.texture=
-e.env_map;e.uniforms.reflectivity.value=e.reflectivity;e.uniforms.refraction_ratio.value=e.refraction_ratio;e.uniforms.combine.value=e.combine;e.uniforms.useRefract.value=e.env_map&&e.env_map.mapping instanceof THREE.CubeRefractionMapping;if(h){e.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){e.uniforms.fogNear.value=h.near;e.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)e.uniforms.fogDensity.value=h.density}}if(e instanceof THREE.LineBasicMaterial){e.uniforms.diffuse.value.setRGB(e.color.r*
+function(f,p){var h=new THREE.Color(f);b.clearColor(h.r,h.g,h.b,p)};this.setClearColor=function(f,p){b.clearColor(f.r,f.g,f.b,p)};this.clear=function(){b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT)};this.setupLights=function(f,p){var h,e,n,j=0,t=0,q=0,k,u,B,v=this.lights,O=v.directional.colors,G=v.directional.positions,D=v.point.colors,U=v.point.positions,X=0,K=0;h=n=n=0;for(e=p.length;h<e;h++){n=p[h];k=n.color;u=n.position;B=n.intensity;if(n instanceof THREE.AmbientLight){j+=k.r;t+=k.g;q+=k.b}else if(n instanceof
+THREE.DirectionalLight){n=X*3;O[n]=k.r*B;O[n+1]=k.g*B;O[n+2]=k.b*B;G[n]=u.x;G[n+1]=u.y;G[n+2]=u.z;X+=1}else if(n instanceof THREE.PointLight){n=K*3;D[n]=k.r*B;D[n+1]=k.g*B;D[n+2]=k.b*B;U[n]=u.x;U[n+1]=u.y;U[n+2]=u.z;K+=1}}for(h=X*3;h<O.length;h++)O[h]=0;for(h=K*3;h<D.length;h++)D[h]=0;v.point.length=K;v.directional.length=X;v.ambient[0]=j;v.ambient[1]=t;v.ambient[2]=q};this.createParticleBuffers=function(f){f.__webGLVertexBuffer=b.createBuffer();f.__webGLColorBuffer=b.createBuffer();f.__webGLParticleBuffer=
+b.createBuffer()};this.createLineBuffers=function(f){f.__webGLVertexBuffer=b.createBuffer();f.__webGLColorBuffer=b.createBuffer();f.__webGLLineBuffer=b.createBuffer()};this.createMeshBuffers=function(f){f.__webGLVertexBuffer=b.createBuffer();f.__webGLNormalBuffer=b.createBuffer();f.__webGLTangentBuffer=b.createBuffer();f.__webGLColorBuffer=b.createBuffer();f.__webGLUVBuffer=b.createBuffer();f.__webGLUV2Buffer=b.createBuffer();f.__webGLFaceBuffer=b.createBuffer();f.__webGLLineBuffer=b.createBuffer()};
+this.initLineBuffers=function(f){var p=f.vertices.length;f.__vertexArray=new Float32Array(p*3);f.__colorArray=new Float32Array(p*3);f.__lineArray=new Uint16Array(p);f.__webGLLineCount=p};this.initParticleBuffers=function(f){var p=f.vertices.length;f.__vertexArray=new Float32Array(p*3);f.__colorArray=new Float32Array(p*3);f.__particleArray=new Uint16Array(p);f.__sortArray=[];f.__webGLParticleCount=p};this.initMeshBuffers=function(f,p){var h,e,n=0,j=0,t=0,q=p.geometry.faces,k=f.faces;h=0;for(e=k.length;h<
+e;h++){fi=k[h];face=q[fi];if(face instanceof THREE.Face3){n+=3;j+=1;t+=3}else if(face instanceof THREE.Face4){n+=4;j+=2;t+=4}}f.__vertexArray=new Float32Array(n*3);f.__normalArray=new Float32Array(n*3);f.__tangentArray=new Float32Array(n*4);f.__colorArray=new Float32Array(n*3);f.__uvArray=new Float32Array(n*2);f.__uv2Array=new Float32Array(n*2);f.__faceArray=new Uint16Array(j*3);f.__lineArray=new Uint16Array(t*2);n=false;h=0;for(e=p.materials.length;h<e;h++){q=p.materials[h];if(q instanceof THREE.MeshFaceMaterial){q=
+0;for(k=f.materials.length;q<k;q++)if(f.materials[q]&&f.materials[q].shading!=undefined&&f.materials[q].shading==THREE.SmoothShading){n=true;break}}else if(q&&q.shading!=undefined&&q.shading==THREE.SmoothShading){n=true;break}if(n)break}f.__needsSmoothNormals=n;f.__webGLFaceCount=j*3;f.__webGLLineCount=t*2};this.setMeshBuffers=function(f,p,h){var e,n,j,t,q,k,u,B,v,O,G=0,D=0,U=0,X=0,K=0,H=0,N=0,R=0,A=0,J=f.__vertexArray,W=f.__uvArray,ga=f.__uv2Array,da=f.__normalArray,Y=f.__tangentArray,ba=f.__colorArray,
+Z=f.__faceArray,ea=f.__lineArray,wa=f.__needsSmoothNormals,ha=p.geometry,ia=ha.__dirtyVertices,sa=ha.__dirtyElements,pa=ha.__dirtyUvs,qa=ha.__dirtyNormals,aa=ha.__dirtyTangents,ma=ha.__dirtyColors,ka=ha.vertices,xa=f.faces,Ga=ha.faces,Ha=ha.uvs,Da=ha.uvs2,na=ha.colors;p=0;for(e=xa.length;p<e;p++){n=xa[p];j=Ga[n];k=Ha[n];n=Da[n];t=j.vertexNormals;q=j.normal;if(j instanceof THREE.Face3){if(ia){u=ka[j.a].position;B=ka[j.b].position;v=ka[j.c].position;J[D]=u.x;J[D+1]=u.y;J[D+2]=u.z;J[D+3]=B.x;J[D+4]=
+B.y;J[D+5]=B.z;J[D+6]=v.x;J[D+7]=v.y;J[D+8]=v.z;D+=9}if(ma&&na.length){u=na[j.a];B=na[j.b];v=na[j.c];ba[A]=u.r;ba[A+1]=u.g;ba[A+2]=u.b;ba[A+3]=B.r;ba[A+4]=B.g;ba[A+5]=B.b;ba[A+6]=v.r;ba[A+7]=v.g;ba[A+8]=v.b;A+=9}if(aa&&ha.hasTangents){u=ka[j.a].tangent;B=ka[j.b].tangent;v=ka[j.c].tangent;Y[N]=u.x;Y[N+1]=u.y;Y[N+2]=u.z;Y[N+3]=u.w;Y[N+4]=B.x;Y[N+5]=B.y;Y[N+6]=B.z;Y[N+7]=B.w;Y[N+8]=v.x;Y[N+9]=v.y;Y[N+10]=v.z;Y[N+11]=v.w;N+=12}if(qa)if(t.length==3&&wa)for(j=0;j<3;j++){q=t[j];da[H]=q.x;da[H+1]=q.y;da[H+
+2]=q.z;H+=3}else for(j=0;j<3;j++){da[H]=q.x;da[H+1]=q.y;da[H+2]=q.z;H+=3}if(pa&&k)for(j=0;j<3;j++){t=k[j];W[U]=t.u;W[U+1]=t.v;U+=2}if(pa&&n)for(j=0;j<3;j++){k=n[j];ga[X]=k.u;ga[X+1]=k.v;X+=2}if(sa){Z[K]=G;Z[K+1]=G+1;Z[K+2]=G+2;K+=3;ea[R]=G;ea[R+1]=G+1;ea[R+2]=G;ea[R+3]=G+2;ea[R+4]=G+1;ea[R+5]=G+2;R+=6;G+=3}}else if(j instanceof THREE.Face4){if(ia){u=ka[j.a].position;B=ka[j.b].position;v=ka[j.c].position;O=ka[j.d].position;J[D]=u.x;J[D+1]=u.y;J[D+2]=u.z;J[D+3]=B.x;J[D+4]=B.y;J[D+5]=B.z;J[D+6]=v.x;
+J[D+7]=v.y;J[D+8]=v.z;J[D+9]=O.x;J[D+10]=O.y;J[D+11]=O.z;D+=12}if(ma&&na.length){u=na[j.a];B=na[j.b];v=na[j.d];ba[A]=u.r;ba[A+1]=u.g;ba[A+2]=u.b;ba[A+3]=B.r;ba[A+4]=B.g;ba[A+5]=B.b;ba[A+6]=v.r;ba[A+7]=v.g;ba[A+8]=v.b;ba[A+9]=(void 0).r;ba[A+10]=(void 0).g;ba[A+11]=(void 0).b;A+=12}if(aa&&ha.hasTangents){u=ka[j.a].tangent;B=ka[j.b].tangent;v=ka[j.c].tangent;j=ka[j.d].tangent;Y[N]=u.x;Y[N+1]=u.y;Y[N+2]=u.z;Y[N+3]=u.w;Y[N+4]=B.x;Y[N+5]=B.y;Y[N+6]=B.z;Y[N+7]=B.w;Y[N+8]=v.x;Y[N+9]=v.y;Y[N+10]=v.z;Y[N+
+11]=v.w;Y[N+12]=j.x;Y[N+13]=j.y;Y[N+14]=j.z;Y[N+15]=j.w;N+=16}if(qa)if(t.length==4&&wa)for(j=0;j<4;j++){q=t[j];da[H]=q.x;da[H+1]=q.y;da[H+2]=q.z;H+=3}else for(j=0;j<4;j++){da[H]=q.x;da[H+1]=q.y;da[H+2]=q.z;H+=3}if(pa&&k)for(j=0;j<4;j++){t=k[j];W[U]=t.u;W[U+1]=t.v;U+=2}if(pa&&n)for(j=0;j<4;j++){k=n[j];ga[X]=k.u;ga[X+1]=k.v;X+=2}if(sa){Z[K]=G;Z[K+1]=G+1;Z[K+2]=G+2;Z[K+3]=G;Z[K+4]=G+2;Z[K+5]=G+3;K+=6;ea[R]=G;ea[R+1]=G+1;ea[R+2]=G;ea[R+3]=G+3;ea[R+4]=G+1;ea[R+5]=G+2;ea[R+6]=G+2;ea[R+7]=G+3;R+=8;G+=4}}}if(ia){b.bindBuffer(b.ARRAY_BUFFER,
+f.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,J,h)}if(ma&&na.length){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLColorBuffer);b.bufferData(b.ARRAY_BUFFER,ba,h)}if(qa){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,da,h)}if(aa&&ha.hasTangents){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLTangentBuffer);b.bufferData(b.ARRAY_BUFFER,Y,h)}if(pa&&U>0){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLUVBuffer);b.bufferData(b.ARRAY_BUFFER,W,h)}if(pa&&X>0){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLUV2Buffer);
+b.bufferData(b.ARRAY_BUFFER,ga,h)}if(sa){b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,f.__webGLFaceBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,Z,h);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,f.__webGLLineBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,ea,h)}};this.setLineBuffers=function(f,p){var h,e,n,j=f.vertices,t=f.colors,q=j.length,k=t.length,u=f.__vertexArray,B=f.__colorArray,v=f.__lineArray,O=f.__dirtyColors,G=f.__dirtyElements;if(f.__dirtyVertices){for(h=0;h<q;h++){e=j[h].position;n=h*3;u[n]=e.x;u[n+1]=e.y;u[n+
+2]=e.z}b.bindBuffer(b.ARRAY_BUFFER,f.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,u,p)}if(O){for(h=0;h<k;h++){color=t[h];n=h*3;B[n]=color.r;B[n+1]=color.g;B[n+2]=color.b}b.bindBuffer(b.ARRAY_BUFFER,f.__webGLColorBuffer);b.bufferData(b.ARRAY_BUFFER,B,p)}if(G){for(h=0;h<q;h++)v[h]=h;b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,f.__webGLLineBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,v,p)}};this.setParticleBuffers=function(f,p,h,e){var n,j,t;j=f.vertices;var q=j.length,k=f.colors,u=k.length,B=f.__vertexArray,
+v=f.__particleArray,O=f.__colorArray,G=f.__sortArray,D=f.__dirtyVertices,U=f.__dirtyElements,X=f.__dirtyColors;if(h.sortParticles){L.multiply(e.projectionMatrix,e.matrix);L.multiplySelf(h.matrix);for(n=0;n<q;n++){t=j[n].position;s.copy(t);L.multiplyVector3(s);G[n]=[s.z,n]}G.sort(function(K,H){return H[0]-K[0]});for(n=0;n<q;n++){t=j[G[n][1]].position;e=n*3;B[e]=t.x;B[e+1]=t.y;B[e+2]=t.z}for(j=0;j<u;j++){e=j*3;color=k[G[j][1]];O[e]=color.r;O[e+1]=color.g;O[e+2]=color.b}}else{if(D)for(n=0;n<q;n++){t=
+j[n].position;e=n*3;B[e]=t.x;B[e+1]=t.y;B[e+2]=t.z}if(X)for(j=0;j<u;j++){color=k[j];e=j*3;O[e]=color.r;O[e+1]=color.g;O[e+2]=color.b}}if(U){for(n=0;n<q;n++)v[n]=n;b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,f.__webGLParticleBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,v,p)}if(D||h.sortParticles){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,B,p)}if(X||h.sortParticles){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLColorBuffer);b.bufferData(b.ARRAY_BUFFER,O,p)}};this.initMaterial=function(f,
+p,h){if(!f.program){var e,n;if(f instanceof THREE.MeshDepthMaterial)c(f,THREE.ShaderLib.depth);else if(f instanceof THREE.MeshNormalMaterial)c(f,THREE.ShaderLib.normal);else if(f instanceof THREE.MeshBasicMaterial)c(f,THREE.ShaderLib.basic);else if(f instanceof THREE.MeshLambertMaterial)c(f,THREE.ShaderLib.lambert);else if(f instanceof THREE.MeshPhongMaterial)c(f,THREE.ShaderLib.phong);else if(f instanceof THREE.LineBasicMaterial)c(f,THREE.ShaderLib.basic);else f instanceof THREE.ParticleBasicMaterial&&
+c(f,THREE.ShaderLib.particle_basic);var j,t,q,k;n=q=k=0;for(j=p.length;n<j;n++){t=p[n];t instanceof THREE.DirectionalLight&&q++;t instanceof THREE.PointLight&&k++}if(k+q<=4){p=q;k=k}else{p=Math.ceil(4*q/(k+q));k=4-p}n={directional:p,point:k};k=f.fragment_shader;p=f.vertex_shader;j={fog:h,map:f.map,env_map:f.env_map,light_map:f.light_map,vertex_colors:f.vertex_colors,maxDirLights:n.directional,maxPointLights:n.point};h=b.createProgram();n=["#ifdef GL_ES\nprecision highp float;\n#endif","#define MAX_DIR_LIGHTS "+
+j.maxDirLights,"#define MAX_POINT_LIGHTS "+j.maxPointLights,j.fog?"#define USE_FOG":"",j.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",j.map?"#define USE_MAP":"",j.env_map?"#define USE_ENVMAP":"",j.light_map?"#define USE_LIGHTMAP":"",j.vertex_colors?"#define USE_COLOR":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");j=[b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+j.maxDirLights,"#define MAX_POINT_LIGHTS "+
+j.maxPointLights,j.map?"#define USE_MAP":"",j.env_map?"#define USE_ENVMAP":"",j.light_map?"#define USE_LIGHTMAP":"",j.vertex_colors?"#define USE_COLOR":"","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 vec3 color;\nattribute vec2 uv;\nattribute vec2 uv2;\n"].join("\n");b.attachShader(h,g("fragment",n+k));b.attachShader(h,
+g("vertex",j+p));b.linkProgram(h);b.getProgramParameter(h,b.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+b.getProgramParameter(h,b.VALIDATE_STATUS)+", gl error ["+b.getError()+"]");h.uniforms={};h.attributes={};f.program=h;h=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(e in f.uniforms)h.push(e);e=f.program;k=0;for(p=h.length;k<p;k++){n=h[k];e.uniforms[n]=b.getUniformLocation(e,n)}f=f.program;e=["position","normal",
+"uv","uv2","tangent","color"];h=0;for(k=e.length;h<k;h++){p=e[h];f.attributes[p]=b.getAttribLocation(f,p)}}};this.setProgram=function(f,p,h,e){this.initMaterial(e,p,h);var n=e.program;if(n!=r){b.useProgram(n);r=n}this.loadCamera(n,f);this.loadMatrices(n);if(e instanceof THREE.MeshPhongMaterial||e instanceof THREE.MeshLambertMaterial){this.setupLights(n,p);p=this.lights;e.uniforms.enableLighting.value=p.directional.length+p.point.length;e.uniforms.ambientLightColor.value=p.ambient;e.uniforms.directionalLightColor.value=
+p.directional.colors;e.uniforms.directionalLightDirection.value=p.directional.positions;e.uniforms.pointLightColor.value=p.point.colors;e.uniforms.pointLightPosition.value=p.point.positions}if(e instanceof THREE.MeshBasicMaterial||e instanceof THREE.MeshLambertMaterial||e instanceof THREE.MeshPhongMaterial){e.uniforms.diffuse.value.setRGB(e.color.r*e.opacity,e.color.g*e.opacity,e.color.b*e.opacity);e.uniforms.opacity.value=e.opacity;e.uniforms.map.texture=e.map;e.uniforms.light_map.texture=e.light_map;
+e.uniforms.env_map.texture=e.env_map;e.uniforms.reflectivity.value=e.reflectivity;e.uniforms.refraction_ratio.value=e.refraction_ratio;e.uniforms.combine.value=e.combine;e.uniforms.useRefract.value=e.env_map&&e.env_map.mapping instanceof THREE.CubeRefractionMapping;if(h){e.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){e.uniforms.fogNear.value=h.near;e.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)e.uniforms.fogDensity.value=h.density}}if(e instanceof THREE.LineBasicMaterial){e.uniforms.diffuse.value.setRGB(e.color.r*
 e.opacity,e.color.g*e.opacity,e.color.b*e.opacity);e.uniforms.opacity.value=e.opacity;if(h){e.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){e.uniforms.fogNear.value=h.near;e.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)e.uniforms.fogDensity.value=h.density}}if(e instanceof THREE.ParticleBasicMaterial){e.uniforms.psColor.value.setRGB(e.color.r*e.opacity,e.color.g*e.opacity,e.color.b*e.opacity);e.uniforms.opacity.value=e.opacity;e.uniforms.size.value=e.size;
 e.uniforms.map.texture=e.map;if(h){e.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){e.uniforms.fogNear.value=h.near;e.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)e.uniforms.fogDensity.value=h.density}}if(e instanceof THREE.MeshPhongMaterial){e.uniforms.ambient.value.setRGB(e.ambient.r,e.ambient.g,e.ambient.b);e.uniforms.specular.value.setRGB(e.specular.r,e.specular.g,e.specular.b);e.uniforms.shininess.value=e.shininess}if(e instanceof THREE.MeshDepthMaterial){e.uniforms.mNear.value=
-f.near;e.uniforms.mFar.value=f.far;e.uniforms.opacity.value=e.opacity}if(e instanceof THREE.MeshNormalMaterial)e.uniforms.opacity.value=e.opacity;f=e.uniforms;var j,t;for(j in f)if(t=o.uniforms[j]){e=f[j];p=e.type;h=e.value;if(p=="i")b.uniform1i(t,h);else if(p=="f")b.uniform1f(t,h);else if(p=="fv1")b.uniform1fv(t,h);else if(p=="fv")b.uniform3fv(t,h);else if(p=="v2")b.uniform2f(t,h.x,h.y);else if(p=="v3")b.uniform3f(t,h.x,h.y,h.z);else if(p=="c")b.uniform3f(t,h.r,h.g,h.b);else if(p=="t"){b.uniform1i(t,
+f.near;e.uniforms.mFar.value=f.far;e.uniforms.opacity.value=e.opacity}if(e instanceof THREE.MeshNormalMaterial)e.uniforms.opacity.value=e.opacity;f=e.uniforms;var j,t;for(j in f)if(t=n.uniforms[j]){e=f[j];p=e.type;h=e.value;if(p=="i")b.uniform1i(t,h);else if(p=="f")b.uniform1f(t,h);else if(p=="fv1")b.uniform1fv(t,h);else if(p=="fv")b.uniform3fv(t,h);else if(p=="v2")b.uniform2f(t,h.x,h.y);else if(p=="v3")b.uniform3f(t,h.x,h.y,h.z);else if(p=="c")b.uniform3f(t,h.r,h.g,h.b);else if(p=="t"){b.uniform1i(t,
 h);if(e=e.texture)if(e.image instanceof Array&&e.image.length==6){e=e;h=h;if(e.image.length==6){if(!e.image.__webGLTextureCube&&!e.image.__cubeMapInitialized&&e.image.loadCount==6){e.image.__webGLTextureCube=b.createTexture();b.bindTexture(b.TEXTURE_CUBE_MAP,e.image.__webGLTextureCube);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_MAG_FILTER,b.LINEAR);b.texParameteri(b.TEXTURE_CUBE_MAP,
 b.TEXTURE_MIN_FILTER,b.LINEAR_MIPMAP_LINEAR);for(p=0;p<6;++p)b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X+p,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.image[p]);b.generateMipmap(b.TEXTURE_CUBE_MAP);b.bindTexture(b.TEXTURE_CUBE_MAP,null);e.image.__cubeMapInitialized=true}b.activeTexture(b.TEXTURE0+h);b.bindTexture(b.TEXTURE_CUBE_MAP,e.image.__webGLTextureCube)}}else{e=e;h=h;if(!e.__webGLTexture&&e.image.loaded){e.__webGLTexture=b.createTexture();b.bindTexture(b.TEXTURE_2D,e.__webGLTexture);b.texImage2D(b.TEXTURE_2D,
-0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.image);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,i(e.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,i(e.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,i(e.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,i(e.min_filter));b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}b.activeTexture(b.TEXTURE0+h);b.bindTexture(b.TEXTURE_2D,e.__webGLTexture)}}}return o};this.renderBuffer=function(f,p,h,e,o,j){f=this.setProgram(f,
-p,h,e,j).attributes;b.bindBuffer(b.ARRAY_BUFFER,o.__webGLVertexBuffer);b.vertexAttribPointer(f.position,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.position);if(f.color>=0){b.bindBuffer(b.ARRAY_BUFFER,o.__webGLColorBuffer);b.vertexAttribPointer(f.color,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.color)}if(f.normal>=0){b.bindBuffer(b.ARRAY_BUFFER,o.__webGLNormalBuffer);b.vertexAttribPointer(f.normal,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.normal)}if(f.tangent>=0){b.bindBuffer(b.ARRAY_BUFFER,
-o.__webGLTangentBuffer);b.vertexAttribPointer(f.tangent,4,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.tangent)}if(f.uv>=0)if(o.__webGLUVBuffer){b.bindBuffer(b.ARRAY_BUFFER,o.__webGLUVBuffer);b.vertexAttribPointer(f.uv,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.uv)}else b.disableVertexAttribArray(f.uv);if(f.uv2>=0)if(o.__webGLUV2Buffer){b.bindBuffer(b.ARRAY_BUFFER,o.__webGLUV2Buffer);b.vertexAttribPointer(f.uv2,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.uv2)}else b.disableVertexAttribArray(f.uv2);
-if(e.wireframe||e instanceof THREE.LineBasicMaterial){f=e.wireframe_linewidth!==undefined?e.wireframe_linewidth:e.linewidth!==undefined?e.linewidth:1;e=e instanceof THREE.LineBasicMaterial&&j.type==THREE.LineStrip?b.LINE_STRIP:b.LINES;b.lineWidth(f);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,o.__webGLLineBuffer);b.drawElements(e,o.__webGLLineCount,b.UNSIGNED_SHORT,0)}else if(e instanceof THREE.ParticleBasicMaterial){b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,o.__webGLParticleBuffer);b.drawElements(b.POINTS,o.__webGLParticleCount,
-b.UNSIGNED_SHORT,0)}else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,o.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,o.__webGLFaceCount,b.UNSIGNED_SHORT,0)}};this.renderPass=function(f,p,h,e,o,j,t){var q,k,u,B,v;u=0;for(B=e.materials.length;u<B;u++){q=e.materials[u];if(q instanceof THREE.MeshFaceMaterial){q=0;for(k=o.materials.length;q<k;q++)if((v=o.materials[q])&&v.blending==j&&v.opacity<1==t){this.setBlending(v.blending);this.setDepthTest(v.depth_test);this.renderBuffer(f,p,h,v,o,e)}}else if((v=q)&&v.blending==
-j&&v.opacity<1==t){this.setBlending(v.blending);this.setDepthTest(v.depth_test);this.renderBuffer(f,p,h,v,o,e)}}};this.renderPassImmediate=function(f,p,h,e,o,j){var t,q,k,u;t=0;for(q=e.materials.length;t<q;t++)if((k=e.materials[t])&&k.blending==o&&k.opacity<1==j){this.setBlending(k.blending);this.setDepthTest(k.depth_test);u=this.setProgram(f,p,h,k,e);e.render(function(B){var v=u;if(!B.__webGLVertexBuffer)B.__webGLVertexBuffer=b.createBuffer();if(!B.__webGLNormalBuffer)B.__webGLNormalBuffer=b.createBuffer();
+0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.image);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,i(e.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,i(e.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,i(e.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,i(e.min_filter));b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}b.activeTexture(b.TEXTURE0+h);b.bindTexture(b.TEXTURE_2D,e.__webGLTexture)}}}return n};this.renderBuffer=function(f,p,h,e,n,j){f=this.setProgram(f,
+p,h,e,j).attributes;b.bindBuffer(b.ARRAY_BUFFER,n.__webGLVertexBuffer);b.vertexAttribPointer(f.position,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.position);if(f.color>=0){b.bindBuffer(b.ARRAY_BUFFER,n.__webGLColorBuffer);b.vertexAttribPointer(f.color,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.color)}if(f.normal>=0){b.bindBuffer(b.ARRAY_BUFFER,n.__webGLNormalBuffer);b.vertexAttribPointer(f.normal,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.normal)}if(f.tangent>=0){b.bindBuffer(b.ARRAY_BUFFER,
+n.__webGLTangentBuffer);b.vertexAttribPointer(f.tangent,4,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.tangent)}if(f.uv>=0)if(n.__webGLUVBuffer){b.bindBuffer(b.ARRAY_BUFFER,n.__webGLUVBuffer);b.vertexAttribPointer(f.uv,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.uv)}else b.disableVertexAttribArray(f.uv);if(f.uv2>=0)if(n.__webGLUV2Buffer){b.bindBuffer(b.ARRAY_BUFFER,n.__webGLUV2Buffer);b.vertexAttribPointer(f.uv2,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.uv2)}else b.disableVertexAttribArray(f.uv2);
+if(e.wireframe||e instanceof THREE.LineBasicMaterial){f=e.wireframe_linewidth!==undefined?e.wireframe_linewidth:e.linewidth!==undefined?e.linewidth:1;e=e instanceof THREE.LineBasicMaterial&&j.type==THREE.LineStrip?b.LINE_STRIP:b.LINES;b.lineWidth(f);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,n.__webGLLineBuffer);b.drawElements(e,n.__webGLLineCount,b.UNSIGNED_SHORT,0)}else if(e instanceof THREE.ParticleBasicMaterial){b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,n.__webGLParticleBuffer);b.drawElements(b.POINTS,n.__webGLParticleCount,
+b.UNSIGNED_SHORT,0)}else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,n.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,n.__webGLFaceCount,b.UNSIGNED_SHORT,0)}};this.renderPass=function(f,p,h,e,n,j,t){var q,k,u,B,v;u=0;for(B=e.materials.length;u<B;u++){q=e.materials[u];if(q instanceof THREE.MeshFaceMaterial){q=0;for(k=n.materials.length;q<k;q++)if((v=n.materials[q])&&v.blending==j&&v.opacity<1==t){this.setBlending(v.blending);this.setDepthTest(v.depth_test);this.renderBuffer(f,p,h,v,n,e)}}else if((v=q)&&v.blending==
+j&&v.opacity<1==t){this.setBlending(v.blending);this.setDepthTest(v.depth_test);this.renderBuffer(f,p,h,v,n,e)}}};this.renderPassImmediate=function(f,p,h,e,n,j){var t,q,k,u;t=0;for(q=e.materials.length;t<q;t++)if((k=e.materials[t])&&k.blending==n&&k.opacity<1==j){this.setBlending(k.blending);this.setDepthTest(k.depth_test);u=this.setProgram(f,p,h,k,e);e.render(function(B){var v=u;if(!B.__webGLVertexBuffer)B.__webGLVertexBuffer=b.createBuffer();if(!B.__webGLNormalBuffer)B.__webGLNormalBuffer=b.createBuffer();
 if(B.hasPos){b.bindBuffer(b.ARRAY_BUFFER,B.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,B.positionArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(v.attributes.position);b.vertexAttribPointer(v.attributes.position,3,b.FLOAT,false,0,0)}if(B.hasNormal){b.bindBuffer(b.ARRAY_BUFFER,B.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,B.normalArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(v.attributes.normal);b.vertexAttribPointer(v.attributes.normal,3,b.FLOAT,false,0,0)}b.drawArrays(b.TRIANGLES,0,B.count);
-B.count=0})}};this.render=function(f,p,h,e){var o,j,t,q,k=f.lights,u=f.fog;p.autoUpdateMatrix&&p.updateMatrix();y.set(p.matrix.flatten());x.set(p.projectionMatrix.flatten());this.initWebGLObjects(f,p);e=e!==undefined?e:true;if(h&&!h.__webGLFramebuffer){h.__webGLFramebuffer=b.createFramebuffer();h.__webGLRenderbuffer=b.createRenderbuffer();h.__webGLTexture=b.createTexture();b.bindRenderbuffer(b.RENDERBUFFER,h.__webGLRenderbuffer);b.renderbufferStorage(b.RENDERBUFFER,b.DEPTH_COMPONENT16,h.width,h.height);
+B.count=0})}};this.render=function(f,p,h,e){var n,j,t,q,k=f.lights,u=f.fog;p.autoUpdateMatrix&&p.updateMatrix();y.set(p.matrix.flatten());x.set(p.projectionMatrix.flatten());this.initWebGLObjects(f,p);e=e!==undefined?e:true;if(h&&!h.__webGLFramebuffer){h.__webGLFramebuffer=b.createFramebuffer();h.__webGLRenderbuffer=b.createRenderbuffer();h.__webGLTexture=b.createTexture();b.bindRenderbuffer(b.RENDERBUFFER,h.__webGLRenderbuffer);b.renderbufferStorage(b.RENDERBUFFER,b.DEPTH_COMPONENT16,h.width,h.height);
 b.bindTexture(b.TEXTURE_2D,h.__webGLTexture);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,i(h.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,i(h.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,i(h.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,i(h.min_filter));b.texImage2D(b.TEXTURE_2D,0,i(h.format),h.width,h.height,0,i(h.format),i(h.type),null);b.bindFramebuffer(b.FRAMEBUFFER,h.__webGLFramebuffer);b.framebufferTexture2D(b.FRAMEBUFFER,b.COLOR_ATTACHMENT0,b.TEXTURE_2D,
-h.__webGLTexture,0);b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,h.__webGLRenderbuffer);b.bindTexture(b.TEXTURE_2D,null);b.bindRenderbuffer(b.RENDERBUFFER,null);b.bindFramebuffer(b.FRAMEBUFFER,null)}if(h){o=h.__webGLFramebuffer;q=h.width;j=h.height}else{o=null;q=l.width;j=l.height}if(o!=m){b.bindFramebuffer(b.FRAMEBUFFER,o);b.viewport(0,0,q,j);e&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);m=o}this.autoClear&&this.clear();o=f.__webGLObjects.length;for(e=0;e<o;e++){t=
-f.__webGLObjects[e];q=t.object;q.visible&&q.autoUpdateMatrix&&q.updateMatrix()}j=f.__webGLObjectsImmediate.length;for(e=0;e<j;e++){t=f.__webGLObjectsImmediate[e];q=t.object;q.visible&&q.autoUpdateMatrix&&q.updateMatrix()}for(e=0;e<o;e++){t=f.__webGLObjects[e];q=t.object;j=t.buffer;if(q.visible){d(q);this.setupMatrices(q,p);this.renderPass(p,k,u,q,j,THREE.NormalBlending,false)}}for(e=0;e<f.__webGLObjectsImmediate.length;e++){t=f.__webGLObjectsImmediate[e];q=t.object;if(q.visible){d(q);this.setupMatrices(q,
-p);this.renderPassImmediate(p,k,u,q,THREE.NormalBlending,false)}}for(e=0;e<o;e++){t=f.__webGLObjects[e];q=t.object;j=t.buffer;if(q.visible){d(q);this.setupMatrices(q,p);this.renderPass(p,k,u,q,j,THREE.AdditiveBlending,false);this.renderPass(p,k,u,q,j,THREE.SubtractiveBlending,false);this.renderPass(p,k,u,q,j,THREE.AdditiveBlending,true);this.renderPass(p,k,u,q,j,THREE.SubtractiveBlending,true);this.renderPass(p,k,u,q,j,THREE.NormalBlending,true);this.renderPass(p,k,u,q,j,THREE.BillboardBlending,false)}}for(e=
+h.__webGLTexture,0);b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,h.__webGLRenderbuffer);b.bindTexture(b.TEXTURE_2D,null);b.bindRenderbuffer(b.RENDERBUFFER,null);b.bindFramebuffer(b.FRAMEBUFFER,null)}if(h){n=h.__webGLFramebuffer;q=h.width;j=h.height}else{n=null;q=l.width;j=l.height}if(n!=m){b.bindFramebuffer(b.FRAMEBUFFER,n);b.viewport(0,0,q,j);e&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);m=n}this.autoClear&&this.clear();n=f.__webGLObjects.length;for(e=0;e<n;e++){t=
+f.__webGLObjects[e];q=t.object;q.visible&&q.autoUpdateMatrix&&q.updateMatrix()}j=f.__webGLObjectsImmediate.length;for(e=0;e<j;e++){t=f.__webGLObjectsImmediate[e];q=t.object;q.visible&&q.autoUpdateMatrix&&q.updateMatrix()}for(e=0;e<n;e++){t=f.__webGLObjects[e];q=t.object;j=t.buffer;if(q.visible){d(q);this.setupMatrices(q,p);this.renderPass(p,k,u,q,j,THREE.NormalBlending,false)}}for(e=0;e<f.__webGLObjectsImmediate.length;e++){t=f.__webGLObjectsImmediate[e];q=t.object;if(q.visible){d(q);this.setupMatrices(q,
+p);this.renderPassImmediate(p,k,u,q,THREE.NormalBlending,false)}}for(e=0;e<n;e++){t=f.__webGLObjects[e];q=t.object;j=t.buffer;if(q.visible){d(q);this.setupMatrices(q,p);this.renderPass(p,k,u,q,j,THREE.AdditiveBlending,false);this.renderPass(p,k,u,q,j,THREE.SubtractiveBlending,false);this.renderPass(p,k,u,q,j,THREE.AdditiveBlending,true);this.renderPass(p,k,u,q,j,THREE.SubtractiveBlending,true);this.renderPass(p,k,u,q,j,THREE.NormalBlending,true);this.renderPass(p,k,u,q,j,THREE.BillboardBlending,false)}}for(e=
 0;e<f.__webGLObjectsImmediate.length;e++){t=f.__webGLObjectsImmediate[e];q=t.object;if(q.visible){d(q);this.setupMatrices(q,p);this.renderPassImmediate(p,k,u,q,THREE.NormalBlending,true)}}if(h&&h.min_filter!==THREE.NearestFilter&&h.min_filter!==THREE.LinearFilter){b.bindTexture(b.TEXTURE_2D,h.__webGLTexture);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}};this.initWebGLObjects=function(f,p){function h(v,O,G,D){if(v[O]==undefined){f.__webGLObjects.push({buffer:G,object:D});v[O]=1}}
-function e(v,O,G){if(v[O]==undefined){f.__webGLObjectsImmediate.push({object:G});v[O]=1}}var o,j,t,q,k,u,B;if(!f.__webGLObjects){f.__webGLObjects=[];f.__webGLObjectsMap={};f.__webGLObjectsImmediate=[]}o=0;for(j=f.objects.length;o<j;o++){t=f.objects[o];k=t.geometry;if(f.__webGLObjectsMap[t.id]==undefined)f.__webGLObjectsMap[t.id]={};B=f.__webGLObjectsMap[t.id];if(t instanceof THREE.Mesh){for(q in k.geometryChunks){u=k.geometryChunks[q];if(!u.__webGLVertexBuffer){this.createMeshBuffers(u);this.initMeshBuffers(u,
+function e(v,O,G){if(v[O]==undefined){f.__webGLObjectsImmediate.push({object:G});v[O]=1}}var n,j,t,q,k,u,B;if(!f.__webGLObjects){f.__webGLObjects=[];f.__webGLObjectsMap={};f.__webGLObjectsImmediate=[]}n=0;for(j=f.objects.length;n<j;n++){t=f.objects[n];k=t.geometry;if(f.__webGLObjectsMap[t.id]==undefined)f.__webGLObjectsMap[t.id]={};B=f.__webGLObjectsMap[t.id];if(t instanceof THREE.Mesh){for(q in k.geometryChunks){u=k.geometryChunks[q];if(!u.__webGLVertexBuffer){this.createMeshBuffers(u);this.initMeshBuffers(u,
 t);k.__dirtyVertices=true;k.__dirtyElements=true;k.__dirtyUvs=true;k.__dirtyNormals=true;k.__dirtyTangents=true;k.__dirtyColors=true}if(k.__dirtyVertices||k.__dirtyElements||k.__dirtyUvs||k.__dirtyNormals||k.__dirtyColors||k.__dirtyTangents)this.setMeshBuffers(u,t,b.DYNAMIC_DRAW);h(B,q,u,t)}k.__dirtyVertices=false;k.__dirtyElements=false;k.__dirtyUvs=false;k.__dirtyNormals=false;k.__dirtyTangents=false;k.__dirtyColors=false}else if(t instanceof THREE.Line){if(!k.__webGLVertexBuffer){this.createLineBuffers(k);
 this.initLineBuffers(k);k.__dirtyVertices=true;k.__dirtyElements=true;k.__dirtyColors=true}if(k.__dirtyVertices||k.__dirtyColors)this.setLineBuffers(k,b.DYNAMIC_DRAW);h(B,0,k,t);k.__dirtyVertices=false;k.__dirtyElements=false}else if(t instanceof THREE.ParticleSystem){if(!k.__webGLVertexBuffer){this.createParticleBuffers(k);this.initParticleBuffers(k);k.__dirtyVertices=true;k.__dirtyColors=true;k.__dirtyElements=true}if(k.__dirtyVertices||k.__dirtyColors||t.sortParticles)this.setParticleBuffers(k,
-b.DYNAMIC_DRAW,t,p);h(B,0,k,t);k.__dirtyVertices=false;k.__dirtyColors=false;k.__dirtyElements=false}else t instanceof THREE.MarchingCubes&&e(B,0,t)}};this.removeObject=function(f,p){var h,e;for(h=f.__webGLObjects.length-1;h>=0;h--){e=f.__webGLObjects[h].object;p==e&&f.__webGLObjects.splice(h,1)}};this.setupMatrices=function(f,p){n.multiply(p.matrix,f.matrix);w.set(n.flatten());z=THREE.Matrix4.makeInvert3x3(n).transpose();I.set(z.m);M.set(f.matrix.flatten())};this.loadMatrices=function(f){b.uniformMatrix4fv(f.uniforms.viewMatrix,
+b.DYNAMIC_DRAW,t,p);h(B,0,k,t);k.__dirtyVertices=false;k.__dirtyColors=false;k.__dirtyElements=false}else t instanceof THREE.MarchingCubes&&e(B,0,t)}};this.removeObject=function(f,p){var h,e;for(h=f.__webGLObjects.length-1;h>=0;h--){e=f.__webGLObjects[h].object;p==e&&f.__webGLObjects.splice(h,1)}};this.setupMatrices=function(f,p){o.multiply(p.matrix,f.matrix);w.set(o.flatten());z=THREE.Matrix4.makeInvert3x3(o).transpose();I.set(z.m);M.set(f.matrix.flatten())};this.loadMatrices=function(f){b.uniformMatrix4fv(f.uniforms.viewMatrix,
 false,y);b.uniformMatrix4fv(f.uniforms.modelViewMatrix,false,w);b.uniformMatrix4fv(f.uniforms.projectionMatrix,false,x);b.uniformMatrix3fv(f.uniforms.normalMatrix,false,I);b.uniformMatrix4fv(f.uniforms.objectMatrix,false,M)};this.loadCamera=function(f,p){b.uniform3f(f.uniforms.cameraPosition,p.position.x,p.position.y,p.position.z)};this.setDepthTest=function(f){f?b.enable(b.DEPTH_TEST):b.disable(b.DEPTH_TEST)};this.setBlending=function(f){switch(f){case THREE.AdditiveBlending:b.blendEquation(b.FUNC_ADD);
 b.blendFunc(b.ONE,b.ONE);break;case THREE.SubtractiveBlending:b.blendFunc(b.DST_COLOR,b.ZERO);break;case THREE.BillboardBlending:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA);break;default:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(f,p){if(f){!p||p=="ccw"?b.frontFace(b.CCW):b.frontFace(b.CW);if(f=="back")b.cullFace(b.BACK);else f=="front"?b.cullFace(b.FRONT):b.cullFace(b.FRONT_AND_BACK);b.enable(b.CULL_FACE)}else b.disable(b.CULL_FACE)};
 this.supportsVertexTextures=function(){return b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}};

+ 104 - 104
build/ThreeDebug.js

@@ -13,32 +13,32 @@ THREE.Vector4=function(a,c,d,g){this.x=a||0;this.y=c||0;this.z=d||0;this.w=g||1}
 THREE.Vector4.prototype={set:function(a,c,d,g){this.x=a;this.y=c;this.z=d;this.w=g;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,c){this.x=a.x+c.x;this.y=a.y+c.y;this.z=a.z+c.z;this.w=a.w+c.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,c){this.x=a.x-c.x;this.y=a.y-c.y;this.z=a.z-c.z;this.w=a.w-c.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,c){this.x+=(a.x-this.x)*c;this.y+=(a.y-this.y)*c;this.z+=(a.z-this.z)*c;this.w+=(a.w-this.w)*c},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,c){this.origin=a||new THREE.Vector3;this.direction=c||new THREE.Vector3};
-THREE.Ray.prototype={intersectScene:function(a){var c,d,g=a.objects,i=[];a=0;for(c=g.length;a<c;a++){d=g[a];if(d instanceof THREE.Mesh)i=i.concat(this.intersectObject(d))}i.sort(function(l,b){return l.distance-b.distance});return i},intersectObject:function(a){function c(M,s,T,F){F=F.clone().subSelf(s);T=T.clone().subSelf(s);var Q=M.clone().subSelf(s);M=F.dot(F);s=F.dot(T);F=F.dot(Q);var f=T.dot(T);T=T.dot(Q);Q=1/(M*f-s*s);f=(f*F-s*T)*Q;M=(M*T-s*F)*Q;return f>0&&M>0&&f+M<1}var d,g,i,l,b,r,m,n,z,y,
-w,x=a.geometry,I=x.vertices,N=[];d=0;for(g=x.faces.length;d<g;d++){i=x.faces[d];y=this.origin.clone();w=this.direction.clone();l=a.matrix.multiplyVector3(I[i.a].position.clone());b=a.matrix.multiplyVector3(I[i.b].position.clone());r=a.matrix.multiplyVector3(I[i.c].position.clone());m=i instanceof THREE.Face4?a.matrix.multiplyVector3(I[i.d].position.clone()):null;n=a.rotationMatrix.multiplyVector3(i.normal.clone());z=w.dot(n);if(z<0){n=n.dot((new THREE.Vector3).sub(l,y))/z;y=y.addSelf(w.multiplyScalar(n));
+THREE.Ray.prototype={intersectScene:function(a){var c,d,g=a.objects,i=[];a=0;for(c=g.length;a<c;a++){d=g[a];if(d instanceof THREE.Mesh)i=i.concat(this.intersectObject(d))}i.sort(function(l,b){return l.distance-b.distance});return i},intersectObject:function(a){function c(M,s,T,F){F=F.clone().subSelf(s);T=T.clone().subSelf(s);var Q=M.clone().subSelf(s);M=F.dot(F);s=F.dot(T);F=F.dot(Q);var f=T.dot(T);T=T.dot(Q);Q=1/(M*f-s*s);f=(f*F-s*T)*Q;M=(M*T-s*F)*Q;return f>0&&M>0&&f+M<1}var d,g,i,l,b,r,m,o,z,y,
+w,x=a.geometry,I=x.vertices,N=[];d=0;for(g=x.faces.length;d<g;d++){i=x.faces[d];y=this.origin.clone();w=this.direction.clone();l=a.matrix.multiplyVector3(I[i.a].position.clone());b=a.matrix.multiplyVector3(I[i.b].position.clone());r=a.matrix.multiplyVector3(I[i.c].position.clone());m=i instanceof THREE.Face4?a.matrix.multiplyVector3(I[i.d].position.clone()):null;o=a.rotationMatrix.multiplyVector3(i.normal.clone());z=w.dot(o);if(z<0){o=o.dot((new THREE.Vector3).sub(l,y))/z;y=y.addSelf(w.multiplyScalar(o));
 if(i instanceof THREE.Face3){if(c(y,l,b,r)){i={distance:this.origin.distanceTo(y),point:y,face:i,object:a};N.push(i)}}else if(i instanceof THREE.Face4)if(c(y,l,b,m)||c(y,b,r,m)){i={distance:this.origin.distanceTo(y),point:y,face:i,object:a};N.push(i)}}}return N}};
-THREE.Rectangle=function(){function a(){l=g-c;b=i-d}var c,d,g,i,l,b,r=true;this.getX=function(){return c};this.getY=function(){return d};this.getWidth=function(){return l};this.getHeight=function(){return b};this.getLeft=function(){return c};this.getTop=function(){return d};this.getRight=function(){return g};this.getBottom=function(){return i};this.set=function(m,n,z,y){r=false;c=m;d=n;g=z;i=y;a()};this.addPoint=function(m,n){if(r){r=false;c=m;d=n;g=m;i=n}else{c=c<m?c:m;d=d<n?d:n;g=g>m?g:m;i=i>n?
-i:n}a()};this.add3Points=function(m,n,z,y,w,x){if(r){r=false;c=m<z?m<w?m:w:z<w?z:w;d=n<y?n<x?n:x:y<x?y:x;g=m>z?m>w?m:w:z>w?z:w;i=n>y?n>x?n:x:y>x?y:x}else{c=m<z?m<w?m<c?m:c:w<c?w:c:z<w?z<c?z:c:w<c?w:c;d=n<y?n<x?n<d?n:d:x<d?x:d:y<x?y<d?y:d:x<d?x:d;g=m>z?m>w?m>g?m:g:w>g?w:g:z>w?z>g?z:g:w>g?w:g;i=n>y?n>x?n>i?n:i:x>i?x:i:y>x?y>i?y:i:x>i?x:i}a()};this.addRectangle=function(m){if(r){r=false;c=m.getLeft();d=m.getTop();g=m.getRight();i=m.getBottom()}else{c=c<m.getLeft()?c:m.getLeft();d=d<m.getTop()?d:m.getTop();
+THREE.Rectangle=function(){function a(){l=g-c;b=i-d}var c,d,g,i,l,b,r=true;this.getX=function(){return c};this.getY=function(){return d};this.getWidth=function(){return l};this.getHeight=function(){return b};this.getLeft=function(){return c};this.getTop=function(){return d};this.getRight=function(){return g};this.getBottom=function(){return i};this.set=function(m,o,z,y){r=false;c=m;d=o;g=z;i=y;a()};this.addPoint=function(m,o){if(r){r=false;c=m;d=o;g=m;i=o}else{c=c<m?c:m;d=d<o?d:o;g=g>m?g:m;i=i>o?
+i:o}a()};this.add3Points=function(m,o,z,y,w,x){if(r){r=false;c=m<z?m<w?m:w:z<w?z:w;d=o<y?o<x?o:x:y<x?y:x;g=m>z?m>w?m:w:z>w?z:w;i=o>y?o>x?o:x:y>x?y:x}else{c=m<z?m<w?m<c?m:c:w<c?w:c:z<w?z<c?z:c:w<c?w:c;d=o<y?o<x?o<d?o:d:x<d?x:d:y<x?y<d?y:d:x<d?x:d;g=m>z?m>w?m>g?m:g:w>g?w:g:z>w?z>g?z:g:w>g?w:g;i=o>y?o>x?o>i?o:i:x>i?x:i:y>x?y>i?y:i:x>i?x:i}a()};this.addRectangle=function(m){if(r){r=false;c=m.getLeft();d=m.getTop();g=m.getRight();i=m.getBottom()}else{c=c<m.getLeft()?c:m.getLeft();d=d<m.getTop()?d:m.getTop();
 g=g>m.getRight()?g:m.getRight();i=i>m.getBottom()?i:m.getBottom()}a()};this.inflate=function(m){c-=m;d-=m;g+=m;i+=m;a()};this.minSelf=function(m){c=c>m.getLeft()?c:m.getLeft();d=d>m.getTop()?d:m.getTop();g=g<m.getRight()?g:m.getRight();i=i<m.getBottom()?i:m.getBottom();a()};this.instersects=function(m){return Math.min(g,m.getRight())-Math.max(c,m.getLeft())>=0&&Math.min(i,m.getBottom())-Math.max(d,m.getTop())>=0};this.empty=function(){r=true;i=g=d=c=0;a()};this.isEmpty=function(){return r};this.toString=
 function(){return"THREE.Rectangle ( left: "+c+", right: "+g+", top: "+d+", bottom: "+i+", width: "+l+", height: "+b+" )"}};THREE.Matrix3=function(){this.m=[]};THREE.Matrix3.prototype={transpose:function(){var a,c=this.m;a=c[1];c[1]=c[3];c[3]=a;a=c[2];c[2]=c[6];c[6]=a;a=c[5];c[5]=c[7];c[7]=a;return this}};
-THREE.Matrix4=function(a,c,d,g,i,l,b,r,m,n,z,y,w,x,I,N){this.n11=a||1;this.n12=c||0;this.n13=d||0;this.n14=g||0;this.n21=i||0;this.n22=l||1;this.n23=b||0;this.n24=r||0;this.n31=m||0;this.n32=n||0;this.n33=z||1;this.n34=y||0;this.n41=w||0;this.n42=x||0;this.n43=I||0;this.n44=N||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,c,d,g,i,l,b,r,m,n,z,y,w,x,I,N){this.n11=a;this.n12=c;this.n13=d;this.n14=g;this.n21=i;this.n22=l;this.n23=b;this.n24=r;this.n31=m;this.n32=n;this.n33=z;this.n34=y;this.n41=w;this.n42=x;this.n43=I;this.n44=N;return this},copy:function(a){this.n11=a.n11;this.n12=a.n12;this.n13=
+THREE.Matrix4=function(a,c,d,g,i,l,b,r,m,o,z,y,w,x,I,N){this.n11=a||1;this.n12=c||0;this.n13=d||0;this.n14=g||0;this.n21=i||0;this.n22=l||1;this.n23=b||0;this.n24=r||0;this.n31=m||0;this.n32=o||0;this.n33=z||1;this.n34=y||0;this.n41=w||0;this.n42=x||0;this.n43=I||0;this.n44=N||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,c,d,g,i,l,b,r,m,o,z,y,w,x,I,N){this.n11=a;this.n12=c;this.n13=d;this.n14=g;this.n21=i;this.n22=l;this.n23=b;this.n24=r;this.n31=m;this.n32=o;this.n33=z;this.n34=y;this.n41=w;this.n42=x;this.n43=I;this.n44=N;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,c,d){var g=THREE.Matrix4.__tmpVec1,i=THREE.Matrix4.__tmpVec2,l=THREE.Matrix4.__tmpVec3;l.sub(a,c).normalize();g.cross(d,l).normalize();i.cross(l,g).normalize();this.n11=g.x;this.n12=g.y;this.n13=g.z;this.n14=-g.dot(a);this.n21=i.x;this.n22=i.y;this.n23=i.z;this.n24=-i.dot(a);
 this.n31=l.x;this.n32=l.y;this.n33=l.z;this.n34=-l.dot(a);this.n43=this.n42=this.n41=0;this.n44=1;return this},multiplyVector3:function(a){var c=a.x,d=a.y,g=a.z,i=1/(this.n41*c+this.n42*d+this.n43*g+this.n44);a.x=(this.n11*c+this.n12*d+this.n13*g+this.n14)*i;a.y=(this.n21*c+this.n22*d+this.n23*g+this.n24)*i;a.z=(this.n31*c+this.n32*d+this.n33*g+this.n34)*i;return a},multiplyVector4:function(a){var c=a.x,d=a.y,g=a.z,i=a.w;a.x=this.n11*c+this.n12*d+this.n13*g+this.n14*i;a.y=this.n21*c+this.n22*d+this.n23*
-g+this.n24*i;a.z=this.n31*c+this.n32*d+this.n33*g+this.n34*i;a.w=this.n41*c+this.n42*d+this.n43*g+this.n44*i;return a},crossVector:function(a){var c=new THREE.Vector4;c.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;c.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;c.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;c.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return c},multiply:function(a,c){var d=a.n11,g=a.n12,i=a.n13,l=a.n14,b=a.n21,r=a.n22,m=a.n23,n=a.n24,z=a.n31,
-y=a.n32,w=a.n33,x=a.n34,I=a.n41,N=a.n42,M=a.n43,s=a.n44,T=c.n11,F=c.n12,Q=c.n13,f=c.n14,p=c.n21,h=c.n22,e=c.n23,o=c.n24,j=c.n31,t=c.n32,q=c.n33,k=c.n34,u=c.n41,C=c.n42,v=c.n43,O=c.n44;this.n11=d*T+g*p+i*j+l*u;this.n12=d*F+g*h+i*t+l*C;this.n13=d*Q+g*e+i*q+l*v;this.n14=d*f+g*o+i*k+l*O;this.n21=b*T+r*p+m*j+n*u;this.n22=b*F+r*h+m*t+n*C;this.n23=b*Q+r*e+m*q+n*v;this.n24=b*f+r*o+m*k+n*O;this.n31=z*T+y*p+w*j+x*u;this.n32=z*F+y*h+w*t+x*C;this.n33=z*Q+y*e+w*q+x*v;this.n34=z*f+y*o+w*k+x*O;this.n41=I*T+N*p+
-M*j+s*u;this.n42=I*F+N*h+M*t+s*C;this.n43=I*Q+N*e+M*q+s*v;this.n44=I*f+N*o+M*k+s*O;return this},multiplySelf:function(a){var c=this.n11,d=this.n12,g=this.n13,i=this.n14,l=this.n21,b=this.n22,r=this.n23,m=this.n24,n=this.n31,z=this.n32,y=this.n33,w=this.n34,x=this.n41,I=this.n42,N=this.n43,M=this.n44,s=a.n11,T=a.n21,F=a.n31,Q=a.n41,f=a.n12,p=a.n22,h=a.n32,e=a.n42,o=a.n13,j=a.n23,t=a.n33,q=a.n43,k=a.n14,u=a.n24,C=a.n34;a=a.n44;this.n11=c*s+d*T+g*F+i*Q;this.n12=c*f+d*p+g*h+i*e;this.n13=c*o+d*j+g*t+i*
-q;this.n14=c*k+d*u+g*C+i*a;this.n21=l*s+b*T+r*F+m*Q;this.n22=l*f+b*p+r*h+m*e;this.n23=l*o+b*j+r*t+m*q;this.n24=l*k+b*u+r*C+m*a;this.n31=n*s+z*T+y*F+w*Q;this.n32=n*f+z*p+y*h+w*e;this.n33=n*o+z*j+y*t+w*q;this.n34=n*k+z*u+y*C+w*a;this.n41=x*s+I*T+N*F+M*Q;this.n42=x*f+I*p+N*h+M*e;this.n43=x*o+I*j+N*t+M*q;this.n44=x*k+I*u+N*C+M*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,g=this.n14,i=this.n21,l=this.n22,b=this.n23,r=this.n24,m=this.n31,n=this.n32,z=this.n33,y=this.n34,w=this.n41,x=this.n42,I=this.n43,N=this.n44;return g*b*n*w-d*r*n*w-g*l*z*w+c*r*z*w+d*l*y*w-c*b*y*w-g*b*m*x+d*r*m*x+g*i*z*x-a*r*z*x-d*i*y*x+a*b*y*x+g*l*m*I-c*r*m*I-g*i*n*I+a*r*n*I+c*i*y*I-a*l*y*I-d*l*m*N+c*b*m*N+d*i*n*N-a*b*n*N-c*i*z*N+a*l*z*N},transpose:function(){function a(c,d,
+g+this.n24*i;a.z=this.n31*c+this.n32*d+this.n33*g+this.n34*i;a.w=this.n41*c+this.n42*d+this.n43*g+this.n44*i;return a},crossVector:function(a){var c=new THREE.Vector4;c.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;c.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;c.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;c.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return c},multiply:function(a,c){var d=a.n11,g=a.n12,i=a.n13,l=a.n14,b=a.n21,r=a.n22,m=a.n23,o=a.n24,z=a.n31,
+y=a.n32,w=a.n33,x=a.n34,I=a.n41,N=a.n42,M=a.n43,s=a.n44,T=c.n11,F=c.n12,Q=c.n13,f=c.n14,p=c.n21,h=c.n22,e=c.n23,n=c.n24,j=c.n31,t=c.n32,q=c.n33,k=c.n34,u=c.n41,C=c.n42,v=c.n43,O=c.n44;this.n11=d*T+g*p+i*j+l*u;this.n12=d*F+g*h+i*t+l*C;this.n13=d*Q+g*e+i*q+l*v;this.n14=d*f+g*n+i*k+l*O;this.n21=b*T+r*p+m*j+o*u;this.n22=b*F+r*h+m*t+o*C;this.n23=b*Q+r*e+m*q+o*v;this.n24=b*f+r*n+m*k+o*O;this.n31=z*T+y*p+w*j+x*u;this.n32=z*F+y*h+w*t+x*C;this.n33=z*Q+y*e+w*q+x*v;this.n34=z*f+y*n+w*k+x*O;this.n41=I*T+N*p+
+M*j+s*u;this.n42=I*F+N*h+M*t+s*C;this.n43=I*Q+N*e+M*q+s*v;this.n44=I*f+N*n+M*k+s*O;return this},multiplySelf:function(a){var c=this.n11,d=this.n12,g=this.n13,i=this.n14,l=this.n21,b=this.n22,r=this.n23,m=this.n24,o=this.n31,z=this.n32,y=this.n33,w=this.n34,x=this.n41,I=this.n42,N=this.n43,M=this.n44,s=a.n11,T=a.n21,F=a.n31,Q=a.n41,f=a.n12,p=a.n22,h=a.n32,e=a.n42,n=a.n13,j=a.n23,t=a.n33,q=a.n43,k=a.n14,u=a.n24,C=a.n34;a=a.n44;this.n11=c*s+d*T+g*F+i*Q;this.n12=c*f+d*p+g*h+i*e;this.n13=c*n+d*j+g*t+i*
+q;this.n14=c*k+d*u+g*C+i*a;this.n21=l*s+b*T+r*F+m*Q;this.n22=l*f+b*p+r*h+m*e;this.n23=l*n+b*j+r*t+m*q;this.n24=l*k+b*u+r*C+m*a;this.n31=o*s+z*T+y*F+w*Q;this.n32=o*f+z*p+y*h+w*e;this.n33=o*n+z*j+y*t+w*q;this.n34=o*k+z*u+y*C+w*a;this.n41=x*s+I*T+N*F+M*Q;this.n42=x*f+I*p+N*h+M*e;this.n43=x*n+I*j+N*t+M*q;this.n44=x*k+I*u+N*C+M*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,g=this.n14,i=this.n21,l=this.n22,b=this.n23,r=this.n24,m=this.n31,o=this.n32,z=this.n33,y=this.n34,w=this.n41,x=this.n42,I=this.n43,N=this.n44;return g*b*o*w-d*r*o*w-g*l*z*w+c*r*z*w+d*l*y*w-c*b*y*w-g*b*m*x+d*r*m*x+g*i*z*x-a*r*z*x-d*i*y*x+a*b*y*x+g*l*m*I-c*r*m*I-g*i*o*I+a*r*o*I+c*i*y*I-a*l*y*I-d*l*m*N+c*b*m*N+d*i*o*N-a*b*o*N-c*i*z*N+a*l*z*N},transpose:function(){function a(c,d,
 g){var i=c[d];c[d]=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,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),g=Math.sin(c),i=1-d,l=a.x,b=a.y,r=a.z,m=i*l,n=i*b;this.set(m*l+d,m*b-g*r,m*r+g*b,0,m*b+g*r,n*b+d,n*r-g*l,0,m*r-g*b,n*r+g*l,i*r*r+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(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),g=Math.sin(c),i=1-d,l=a.x,b=a.y,r=a.z,m=i*l,o=i*b;this.set(m*l+d,m*b-g*r,m*r+g*b,0,m*b+g*r,o*b+d,o*r-g*l,0,m*r-g*b,o*r+g*l,i*r*r+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 g=new THREE.Matrix4;g.setTranslation(a,c,d);return g};THREE.Matrix4.scaleMatrix=function(a,c,d){var g=new THREE.Matrix4;g.setScale(a,c,d);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 d=new THREE.Matrix4;d.setRotAxis(a,c);return d};
-THREE.Matrix4.makeInvert=function(a){var c=a.n11,d=a.n12,g=a.n13,i=a.n14,l=a.n21,b=a.n22,r=a.n23,m=a.n24,n=a.n31,z=a.n32,y=a.n33,w=a.n34,x=a.n41,I=a.n42,N=a.n43,M=a.n44,s=new THREE.Matrix4;s.n11=r*w*I-m*y*I+m*z*N-b*w*N-r*z*M+b*y*M;s.n12=i*y*I-g*w*I-i*z*N+d*w*N+g*z*M-d*y*M;s.n13=g*m*I-i*r*I+i*b*N-d*m*N-g*b*M+d*r*M;s.n14=i*r*z-g*m*z-i*b*y+d*m*y+g*b*w-d*r*w;s.n21=m*y*x-r*w*x-m*n*N+l*w*N+r*n*M-l*y*M;s.n22=g*w*x-i*y*x+i*n*N-c*w*N-g*n*M+c*y*M;s.n23=i*r*x-g*m*x-i*l*N+c*m*N+g*l*M-c*r*M;s.n24=g*m*n-i*r*n+
-i*l*y-c*m*y-g*l*w+c*r*w;s.n31=b*w*x-m*z*x+m*n*I-l*w*I-b*n*M+l*z*M;s.n32=i*z*x-d*w*x-i*n*I+c*w*I+d*n*M-c*z*M;s.n33=g*m*x-i*b*x+i*l*I-c*m*I-d*l*M+c*b*M;s.n34=i*b*n-d*m*n-i*l*z+c*m*z+d*l*w-c*b*w;s.n41=r*z*x-b*y*x-r*n*I+l*y*I+b*n*N-l*z*N;s.n42=d*y*x-g*z*x+g*n*I-c*y*I-d*n*N+c*z*N;s.n43=g*b*x-d*r*x-g*l*I+c*r*I+d*l*N-c*b*N;s.n44=d*r*n-g*b*n+g*l*z-c*r*z-d*l*y+c*b*y;s.multiplyScalar(1/a.determinant());return s};
-THREE.Matrix4.makeInvert3x3=function(a){var c=a.flatten();a=a.m33;var d=a.m,g=c[10]*c[5]-c[6]*c[9],i=-c[10]*c[1]+c[2]*c[9],l=c[6]*c[1]-c[2]*c[5],b=-c[10]*c[4]+c[6]*c[8],r=c[10]*c[0]-c[2]*c[8],m=-c[6]*c[0]+c[2]*c[4],n=c[9]*c[4]-c[5]*c[8],z=-c[9]*c[0]+c[1]*c[8],y=c[5]*c[0]-c[1]*c[4];c=c[0]*g+c[1]*b+c[2]*n;if(c==0)throw"matrix not invertible";c=1/c;d[0]=c*g;d[1]=c*i;d[2]=c*l;d[3]=c*b;d[4]=c*r;d[5]=c*m;d[6]=c*n;d[7]=c*z;d[8]=c*y;return a};
+THREE.Matrix4.makeInvert=function(a){var c=a.n11,d=a.n12,g=a.n13,i=a.n14,l=a.n21,b=a.n22,r=a.n23,m=a.n24,o=a.n31,z=a.n32,y=a.n33,w=a.n34,x=a.n41,I=a.n42,N=a.n43,M=a.n44,s=new THREE.Matrix4;s.n11=r*w*I-m*y*I+m*z*N-b*w*N-r*z*M+b*y*M;s.n12=i*y*I-g*w*I-i*z*N+d*w*N+g*z*M-d*y*M;s.n13=g*m*I-i*r*I+i*b*N-d*m*N-g*b*M+d*r*M;s.n14=i*r*z-g*m*z-i*b*y+d*m*y+g*b*w-d*r*w;s.n21=m*y*x-r*w*x-m*o*N+l*w*N+r*o*M-l*y*M;s.n22=g*w*x-i*y*x+i*o*N-c*w*N-g*o*M+c*y*M;s.n23=i*r*x-g*m*x-i*l*N+c*m*N+g*l*M-c*r*M;s.n24=g*m*o-i*r*o+
+i*l*y-c*m*y-g*l*w+c*r*w;s.n31=b*w*x-m*z*x+m*o*I-l*w*I-b*o*M+l*z*M;s.n32=i*z*x-d*w*x-i*o*I+c*w*I+d*o*M-c*z*M;s.n33=g*m*x-i*b*x+i*l*I-c*m*I-d*l*M+c*b*M;s.n34=i*b*o-d*m*o-i*l*z+c*m*z+d*l*w-c*b*w;s.n41=r*z*x-b*y*x-r*o*I+l*y*I+b*o*N-l*z*N;s.n42=d*y*x-g*z*x+g*o*I-c*y*I-d*o*N+c*z*N;s.n43=g*b*x-d*r*x-g*l*I+c*r*I+d*l*N-c*b*N;s.n44=d*r*o-g*b*o+g*l*z-c*r*z-d*l*y+c*b*y;s.multiplyScalar(1/a.determinant());return s};
+THREE.Matrix4.makeInvert3x3=function(a){var c=a.flatten();a=a.m33;var d=a.m,g=c[10]*c[5]-c[6]*c[9],i=-c[10]*c[1]+c[2]*c[9],l=c[6]*c[1]-c[2]*c[5],b=-c[10]*c[4]+c[6]*c[8],r=c[10]*c[0]-c[2]*c[8],m=-c[6]*c[0]+c[2]*c[4],o=c[9]*c[4]-c[5]*c[8],z=-c[9]*c[0]+c[1]*c[8],y=c[5]*c[0]-c[1]*c[4];c=c[0]*g+c[1]*b+c[2]*o;if(c==0)throw"matrix not invertible";c=1/c;d[0]=c*g;d[1]=c*i;d[2]=c*l;d[3]=c*b;d[4]=c*r;d[5]=c*m;d[6]=c*o;d[7]=c*z;d[8]=c*y;return a};
 THREE.Matrix4.makeFrustum=function(a,c,d,g,i,l){var b,r,m;b=new THREE.Matrix4;r=2*i/(c-a);m=2*i/(g-d);a=(c+a)/(c-a);d=(g+d)/(g-d);g=-(l+i)/(l-i);i=-2*l*i/(l-i);b.n11=r;b.n12=0;b.n13=a;b.n14=0;b.n21=0;b.n22=m;b.n23=d;b.n24=0;b.n31=0;b.n32=0;b.n33=g;b.n34=i;b.n41=0;b.n42=0;b.n43=-1;b.n44=0;return b};THREE.Matrix4.makePerspective=function(a,c,d,g){var i;a=d*Math.tan(a*Math.PI/360);i=-a;return THREE.Matrix4.makeFrustum(i*c,a*c,i,a,d,g)};
-THREE.Matrix4.makeOrtho=function(a,c,d,g,i,l){var b,r,m,n;b=new THREE.Matrix4;r=c-a;m=d-g;n=l-i;a=(c+a)/r;d=(d+g)/m;i=(l+i)/n;b.n11=2/r;b.n12=0;b.n13=0;b.n14=-a;b.n21=0;b.n22=2/m;b.n23=0;b.n24=-d;b.n31=0;b.n32=0;b.n33=-2/n;b.n34=-i;b.n41=0;b.n42=0;b.n43=0;b.n44=1;return b};THREE.Matrix4.__tmpVec1=new THREE.Vector3;THREE.Matrix4.__tmpVec2=new THREE.Vector3;THREE.Matrix4.__tmpVec3=new THREE.Vector3;
+THREE.Matrix4.makeOrtho=function(a,c,d,g,i,l){var b,r,m,o;b=new THREE.Matrix4;r=c-a;m=d-g;o=l-i;a=(c+a)/r;d=(d+g)/m;i=(l+i)/o;b.n11=2/r;b.n12=0;b.n13=0;b.n14=-a;b.n21=0;b.n22=2/m;b.n23=0;b.n24=-d;b.n31=0;b.n32=0;b.n33=-2/o;b.n34=-i;b.n41=0;b.n42=0;b.n43=0;b.n44=1;return b};THREE.Matrix4.__tmpVec1=new THREE.Vector3;THREE.Matrix4.__tmpVec2=new THREE.Vector3;THREE.Matrix4.__tmpVec3=new THREE.Vector3;
 THREE.Vertex=function(a,c){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=c||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,c,d,g,i){this.a=a;this.b=c;this.c=d;this.centroid=new THREE.Vector3;this.normal=g instanceof THREE.Vector3?g:new THREE.Vector3;this.vertexNormals=g instanceof Array?g:[];this.materials=i instanceof Array?i:[i]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
 THREE.Face4=function(a,c,d,g,i,l){this.a=a;this.b=c;this.c=d;this.d=g;this.centroid=new THREE.Vector3;this.normal=i instanceof THREE.Vector3?i:new THREE.Vector3;this.vertexNormals=i instanceof Array?i:[];this.materials=l instanceof Array?l:[l]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,c){this.u=a||0;this.v=c||0};
@@ -47,13 +47,13 @@ THREE.Geometry.prototype={computeCentroids:function(){var a,c,d;a=0;for(c=this.f
 d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeFaceNormals:function(a){var c,d,g,i,l,b,r=new THREE.Vector3,m=new THREE.Vector3;g=0;for(i=this.vertices.length;g<i;g++){l=this.vertices[g];l.normal.set(0,0,0)}g=0;for(i=this.faces.length;g<i;g++){l=this.faces[g];if(a&&l.vertexNormals.length){r.set(0,0,0);c=0;for(d=l.normal.length;c<d;c++)r.addSelf(l.vertexNormals[c]);r.divideScalar(3)}else{c=this.vertices[l.a];d=this.vertices[l.b];b=this.vertices[l.c];r.sub(b.position,
 d.position);m.sub(c.position,d.position);r.crossSelf(m)}r.isZero()||r.normalize();l.normal.copy(r)}},computeVertexNormals:function(){var a,c,d,g;if(this.__tmpVertices==undefined){g=this.__tmpVertices=Array(this.vertices.length);a=0;for(c=this.vertices.length;a<c;a++)g[a]=new THREE.Vector3;a=0;for(c=this.faces.length;a<c;a++){d=this.faces[a];if(d instanceof THREE.Face3)d.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];else if(d instanceof THREE.Face4)d.vertexNormals=[new THREE.Vector3,
 new THREE.Vector3,new THREE.Vector3,new THREE.Vector3]}}else{g=this.__tmpVertices;a=0;for(c=this.vertices.length;a<c;a++)g[a].set(0,0,0)}a=0;for(c=this.faces.length;a<c;a++){d=this.faces[a];if(d instanceof THREE.Face3){g[d.a].addSelf(d.normal);g[d.b].addSelf(d.normal);g[d.c].addSelf(d.normal)}else if(d instanceof THREE.Face4){g[d.a].addSelf(d.normal);g[d.b].addSelf(d.normal);g[d.c].addSelf(d.normal);g[d.d].addSelf(d.normal)}}a=0;for(c=this.vertices.length;a<c;a++)g[a].normalize();a=0;for(c=this.faces.length;a<
-c;a++){d=this.faces[a];if(d instanceof THREE.Face3){d.vertexNormals[0].copy(g[d.a]);d.vertexNormals[1].copy(g[d.b]);d.vertexNormals[2].copy(g[d.c])}else if(d instanceof THREE.Face4){d.vertexNormals[0].copy(g[d.a]);d.vertexNormals[1].copy(g[d.b]);d.vertexNormals[2].copy(g[d.c]);d.vertexNormals[3].copy(g[d.d])}}},computeTangents:function(){function a(k,u,C,v,O,G,D){l=k.vertices[u].position;b=k.vertices[C].position;r=k.vertices[v].position;m=i[O];n=i[G];z=i[D];y=b.x-l.x;w=r.x-l.x;x=b.y-l.y;I=r.y-l.y;
-N=b.z-l.z;M=r.z-l.z;s=n.u-m.u;T=z.u-m.u;F=n.v-m.v;Q=z.v-m.v;f=1/(s*Q-T*F);e.set((Q*y-F*w)*f,(Q*x-F*I)*f,(Q*N-F*M)*f);o.set((s*w-T*y)*f,(s*I-T*x)*f,(s*M-T*N)*f);p[u].addSelf(e);p[C].addSelf(e);p[v].addSelf(e);h[u].addSelf(o);h[C].addSelf(o);h[v].addSelf(o)}var c,d,g,i,l,b,r,m,n,z,y,w,x,I,N,M,s,T,F,Q,f,p=[],h=[],e=new THREE.Vector3,o=new THREE.Vector3,j=new THREE.Vector3,t=new THREE.Vector3,q=new THREE.Vector3;c=0;for(d=this.vertices.length;c<d;c++){p[c]=new THREE.Vector3;h[c]=new THREE.Vector3}c=0;
+c;a++){d=this.faces[a];if(d instanceof THREE.Face3){d.vertexNormals[0].copy(g[d.a]);d.vertexNormals[1].copy(g[d.b]);d.vertexNormals[2].copy(g[d.c])}else if(d instanceof THREE.Face4){d.vertexNormals[0].copy(g[d.a]);d.vertexNormals[1].copy(g[d.b]);d.vertexNormals[2].copy(g[d.c]);d.vertexNormals[3].copy(g[d.d])}}},computeTangents:function(){function a(k,u,C,v,O,G,D){l=k.vertices[u].position;b=k.vertices[C].position;r=k.vertices[v].position;m=i[O];o=i[G];z=i[D];y=b.x-l.x;w=r.x-l.x;x=b.y-l.y;I=r.y-l.y;
+N=b.z-l.z;M=r.z-l.z;s=o.u-m.u;T=z.u-m.u;F=o.v-m.v;Q=z.v-m.v;f=1/(s*Q-T*F);e.set((Q*y-F*w)*f,(Q*x-F*I)*f,(Q*N-F*M)*f);n.set((s*w-T*y)*f,(s*I-T*x)*f,(s*M-T*N)*f);p[u].addSelf(e);p[C].addSelf(e);p[v].addSelf(e);h[u].addSelf(n);h[C].addSelf(n);h[v].addSelf(n)}var c,d,g,i,l,b,r,m,o,z,y,w,x,I,N,M,s,T,F,Q,f,p=[],h=[],e=new THREE.Vector3,n=new THREE.Vector3,j=new THREE.Vector3,t=new THREE.Vector3,q=new THREE.Vector3;c=0;for(d=this.vertices.length;c<d;c++){p[c]=new THREE.Vector3;h[c]=new THREE.Vector3}c=0;
 for(d=this.faces.length;c<d;c++){g=this.faces[c];i=this.uvs[c];if(g instanceof THREE.Face3){a(this,g.a,g.b,g.c,0,1,2);this.vertices[g.a].normal.copy(g.vertexNormals[0]);this.vertices[g.b].normal.copy(g.vertexNormals[1]);this.vertices[g.c].normal.copy(g.vertexNormals[2])}else if(g instanceof THREE.Face4){a(this,g.a,g.b,g.c,0,1,2);a(this,g.a,g.b,g.d,0,1,3);this.vertices[g.a].normal.copy(g.vertexNormals[0]);this.vertices[g.b].normal.copy(g.vertexNormals[1]);this.vertices[g.c].normal.copy(g.vertexNormals[2]);
 this.vertices[g.d].normal.copy(g.vertexNormals[3])}}c=0;for(d=this.vertices.length;c<d;c++){q.copy(this.vertices[c].normal);g=p[c];j.copy(g);j.subSelf(q.multiplyScalar(q.dot(g))).normalize();t.cross(this.vertices[c].normal,g);g=t.dot(h[c]);g=g<0?-1:1;this.vertices[c].tangent.set(j.x,j.y,j.z,g)}this.hasTangents=true},computeBoundingBox:function(){var a;if(this.vertices.length>0){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 c=1,d=this.vertices.length;c<d;c++){a=this.vertices[c];if(a.position.x<this.boundingBox.x[0])this.boundingBox.x[0]=a.position.x;else if(a.position.x>this.boundingBox.x[1])this.boundingBox.x[1]=a.position.x;if(a.position.y<this.boundingBox.y[0])this.boundingBox.y[0]=a.position.y;else if(a.position.y>this.boundingBox.y[1])this.boundingBox.y[1]=a.position.y;if(a.position.z<this.boundingBox.z[0])this.boundingBox.z[0]=a.position.z;else 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,c=0,d=this.vertices.length;c<d;c++)a=Math.max(a,this.vertices[c].position.length());this.boundingSphere={radius:a}},sortFacesByMaterial:function(){function a(z){var y=[];c=0;for(d=z.length;c<d;c++)z[c]==undefined?y.push("undefined"):y.push(z[c].toString());return y.join("_")}var c,d,g,i,l,b,r,m,n={};g=0;for(i=this.faces.length;g<i;g++){l=this.faces[g];
-b=l.materials;r=a(b);if(n[r]==undefined)n[r]={hash:r,counter:0};m=n[r].hash+"_"+n[r].counter;if(this.geometryChunks[m]==undefined)this.geometryChunks[m]={faces:[],materials:b,vertices:0};l=l instanceof THREE.Face3?3:4;if(this.geometryChunks[m].vertices+l>65535){n[r].counter+=1;m=n[r].hash+"_"+n[r].counter;if(this.geometryChunks[m]==undefined)this.geometryChunks[m]={faces:[],materials:b,vertices:0}}this.geometryChunks[m].faces.push(g);this.geometryChunks[m].vertices+=l}},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,c=0,d=this.vertices.length;c<d;c++)a=Math.max(a,this.vertices[c].position.length());this.boundingSphere={radius:a}},sortFacesByMaterial:function(){function a(z){var y=[];c=0;for(d=z.length;c<d;c++)z[c]==undefined?y.push("undefined"):y.push(z[c].toString());return y.join("_")}var c,d,g,i,l,b,r,m,o={};g=0;for(i=this.faces.length;g<i;g++){l=this.faces[g];
+b=l.materials;r=a(b);if(o[r]==undefined)o[r]={hash:r,counter:0};m=o[r].hash+"_"+o[r].counter;if(this.geometryChunks[m]==undefined)this.geometryChunks[m]={faces:[],materials:b,vertices:0};l=l instanceof THREE.Face3?3:4;if(this.geometryChunks[m].vertices+l>65535){o[r].counter+=1;m=o[r].hash+"_"+o[r].counter;if(this.geometryChunks[m]==undefined)this.geometryChunks[m]={faces:[],materials:b,vertices:0}}this.geometryChunks[m].faces.push(g);this.geometryChunks[m].vertices+=l}},toString:function(){return"THREE.Geometry ( vertices: "+
 this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
 THREE.Camera=function(a,c,d,g){this.fov=a;this.aspect=c;this.near=d;this.far=g;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(i){this.tmpVec.sub(this.target.position,this.position).normalize().multiplyScalar(i);this.tmpVec.crossSelf(this.up);this.position.addSelf(this.tmpVec);this.target.position.addSelf(this.tmpVec)};
 this.translateZ=function(i){this.tmpVec.sub(this.target.position,this.position).normalize().multiplyScalar(i);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()};
@@ -102,104 +102,104 @@ var Uniforms={clone:function(a){var c,d,g,i={};for(c in a){i[c]={};for(d in a[c]
 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,c,d){this.color=new THREE.Color(a);this.near=c||1;this.far=d||1E3};THREE.FogExp2=function(a,c){this.color=new THREE.Color(a);this.density=c||2.5E-4};
-THREE.Projector=function(){function a(h,e){return e.z-h.z}function c(h,e){var o=0,j=1,t=h.z+h.w,q=e.z+e.w,k=-h.z+h.w,u=-e.z+e.w;if(t>=0&&q>=0&&k>=0&&u>=0)return true;else if(t<0&&q<0||k<0&&u<0)return false;else{if(t<0)o=Math.max(o,t/(t-q));else if(q<0)j=Math.min(j,t/(t-q));if(k<0)o=Math.max(o,k/(k-u));else if(u<0)j=Math.min(j,k/(k-u));if(j<o)return false;else{h.lerpSelf(e,o);e.lerpSelf(h,1-j);return true}}}var d,g,i=[],l,b,r,m=[],n,z,y=[],w,x,I=[],N=new THREE.Vector4,M=new THREE.Vector4,s=new THREE.Matrix4,
-T=new THREE.Matrix4,F=[],Q=new THREE.Vector4,f=new THREE.Vector4,p;this.projectObjects=function(h,e,o){var j=[],t,q;g=0;s.multiply(e.projectionMatrix,e.matrix);F[0]=new THREE.Vector4(s.n41-s.n11,s.n42-s.n12,s.n43-s.n13,s.n44-s.n14);F[1]=new THREE.Vector4(s.n41+s.n11,s.n42+s.n12,s.n43+s.n13,s.n44+s.n14);F[2]=new THREE.Vector4(s.n41+s.n21,s.n42+s.n22,s.n43+s.n23,s.n44+s.n24);F[3]=new THREE.Vector4(s.n41-s.n21,s.n42-s.n22,s.n43-s.n23,s.n44-s.n24);F[4]=new THREE.Vector4(s.n41-s.n31,s.n42-s.n32,s.n43-
+THREE.Projector=function(){function a(h,e){return e.z-h.z}function c(h,e){var n=0,j=1,t=h.z+h.w,q=e.z+e.w,k=-h.z+h.w,u=-e.z+e.w;if(t>=0&&q>=0&&k>=0&&u>=0)return true;else if(t<0&&q<0||k<0&&u<0)return false;else{if(t<0)n=Math.max(n,t/(t-q));else if(q<0)j=Math.min(j,t/(t-q));if(k<0)n=Math.max(n,k/(k-u));else if(u<0)j=Math.min(j,k/(k-u));if(j<n)return false;else{h.lerpSelf(e,n);e.lerpSelf(h,1-j);return true}}}var d,g,i=[],l,b,r,m=[],o,z,y=[],w,x,I=[],N=new THREE.Vector4,M=new THREE.Vector4,s=new THREE.Matrix4,
+T=new THREE.Matrix4,F=[],Q=new THREE.Vector4,f=new THREE.Vector4,p;this.projectObjects=function(h,e,n){var j=[],t,q;g=0;s.multiply(e.projectionMatrix,e.matrix);F[0]=new THREE.Vector4(s.n41-s.n11,s.n42-s.n12,s.n43-s.n13,s.n44-s.n14);F[1]=new THREE.Vector4(s.n41+s.n11,s.n42+s.n12,s.n43+s.n13,s.n44+s.n14);F[2]=new THREE.Vector4(s.n41+s.n21,s.n42+s.n22,s.n43+s.n23,s.n44+s.n24);F[3]=new THREE.Vector4(s.n41-s.n21,s.n42-s.n22,s.n43-s.n23,s.n44-s.n24);F[4]=new THREE.Vector4(s.n41-s.n31,s.n42-s.n32,s.n43-
 s.n33,s.n44-s.n34);F[5]=new THREE.Vector4(s.n41+s.n31,s.n42+s.n32,s.n43+s.n33,s.n44+s.n34);e=0;for(t=F.length;e<t;e++){q=F[e];q.divideScalar(Math.sqrt(q.x*q.x+q.y*q.y+q.z*q.z))}t=h.objects;h=0;for(e=t.length;h<e;h++){q=t[h];var k;if(!(k=!q.visible)){if(k=q instanceof THREE.Mesh){a:{k=void 0;for(var u=q.position,C=-q.geometry.boundingSphere.radius*Math.max(q.scale.x,Math.max(q.scale.y,q.scale.z)),v=0;v<6;v++){k=F[v].x*u.x+F[v].y*u.y+F[v].z*u.z+F[v].w;if(k<=C){k=false;break a}}k=true}k=!k}k=k}if(!k){d=
-i[g]=i[g]||new THREE.RenderableObject;N.copy(q.position);s.multiplyVector3(N);d.object=q;d.z=N.z;j.push(d);g++}}o&&j.sort(a);return j};this.projectScene=function(h,e,o){var j=[],t=e.near,q=e.far,k,u,C,v,O,G,D,V,U,J,H,K,P,A,L,X;r=z=x=0;e.autoUpdateMatrix&&e.updateMatrix();s.multiply(e.projectionMatrix,e.matrix);G=this.projectObjects(h,e,true);h=0;for(k=G.length;h<k;h++){D=G[h].object;if(D.visible){D.autoUpdateMatrix&&D.updateMatrix();V=D.matrix;U=D.rotationMatrix;J=D.materials;H=D.overdraw;if(D instanceof
-THREE.Mesh){K=D.geometry;P=K.vertices;u=0;for(C=P.length;u<C;u++){A=P[u];A.positionWorld.copy(A.position);V.multiplyVector3(A.positionWorld);v=A.positionScreen;v.copy(A.positionWorld);s.multiplyVector4(v);v.x/=v.w;v.y/=v.w;A.__visible=v.z>t&&v.z<q}K=K.faces;u=0;for(C=K.length;u<C;u++){A=K[u];if(A instanceof THREE.Face3){v=P[A.a];O=P[A.b];L=P[A.c];if(v.__visible&&O.__visible&&L.__visible)if(D.doubleSided||D.flipSided!=(L.positionScreen.x-v.positionScreen.x)*(O.positionScreen.y-v.positionScreen.y)-
-(L.positionScreen.y-v.positionScreen.y)*(O.positionScreen.x-v.positionScreen.x)<0){l=m[r]=m[r]||new THREE.RenderableFace3;l.v1.positionWorld.copy(v.positionWorld);l.v2.positionWorld.copy(O.positionWorld);l.v3.positionWorld.copy(L.positionWorld);l.v1.positionScreen.copy(v.positionScreen);l.v2.positionScreen.copy(O.positionScreen);l.v3.positionScreen.copy(L.positionScreen);l.normalWorld.copy(A.normal);U.multiplyVector3(l.normalWorld);l.centroidWorld.copy(A.centroid);V.multiplyVector3(l.centroidWorld);
-l.centroidScreen.copy(l.centroidWorld);s.multiplyVector3(l.centroidScreen);L=A.vertexNormals;p=l.vertexNormalsWorld;v=0;for(O=L.length;v<O;v++){X=p[v]=p[v]||new THREE.Vector3;X.copy(L[v]);U.multiplyVector3(X)}l.z=l.centroidScreen.z;l.meshMaterials=J;l.faceMaterials=A.materials;l.overdraw=H;if(D.geometry.uvs[u]){l.uvs[0]=D.geometry.uvs[u][0];l.uvs[1]=D.geometry.uvs[u][1];l.uvs[2]=D.geometry.uvs[u][2]}j.push(l);r++}}else if(A instanceof THREE.Face4){v=P[A.a];O=P[A.b];L=P[A.c];X=P[A.d];if(v.__visible&&
-O.__visible&&L.__visible&&X.__visible)if(D.doubleSided||D.flipSided!=((X.positionScreen.x-v.positionScreen.x)*(O.positionScreen.y-v.positionScreen.y)-(X.positionScreen.y-v.positionScreen.y)*(O.positionScreen.x-v.positionScreen.x)<0||(O.positionScreen.x-L.positionScreen.x)*(X.positionScreen.y-L.positionScreen.y)-(O.positionScreen.y-L.positionScreen.y)*(X.positionScreen.x-L.positionScreen.x)<0)){l=m[r]=m[r]||new THREE.RenderableFace3;l.v1.positionWorld.copy(v.positionWorld);l.v2.positionWorld.copy(O.positionWorld);
-l.v3.positionWorld.copy(X.positionWorld);l.v1.positionScreen.copy(v.positionScreen);l.v2.positionScreen.copy(O.positionScreen);l.v3.positionScreen.copy(X.positionScreen);l.normalWorld.copy(A.normal);U.multiplyVector3(l.normalWorld);l.centroidWorld.copy(A.centroid);V.multiplyVector3(l.centroidWorld);l.centroidScreen.copy(l.centroidWorld);s.multiplyVector3(l.centroidScreen);l.z=l.centroidScreen.z;l.meshMaterials=J;l.faceMaterials=A.materials;l.overdraw=H;if(D.geometry.uvs[u]){l.uvs[0]=D.geometry.uvs[u][0];
-l.uvs[1]=D.geometry.uvs[u][1];l.uvs[2]=D.geometry.uvs[u][3]}j.push(l);r++;b=m[r]=m[r]||new THREE.RenderableFace3;b.v1.positionWorld.copy(O.positionWorld);b.v2.positionWorld.copy(L.positionWorld);b.v3.positionWorld.copy(X.positionWorld);b.v1.positionScreen.copy(O.positionScreen);b.v2.positionScreen.copy(L.positionScreen);b.v3.positionScreen.copy(X.positionScreen);b.normalWorld.copy(l.normalWorld);b.centroidWorld.copy(l.centroidWorld);b.centroidScreen.copy(l.centroidScreen);b.z=b.centroidScreen.z;b.meshMaterials=
-J;b.faceMaterials=A.materials;b.overdraw=H;if(D.geometry.uvs[u]){b.uvs[0]=D.geometry.uvs[u][1];b.uvs[1]=D.geometry.uvs[u][2];b.uvs[2]=D.geometry.uvs[u][3]}j.push(b);r++}}}}else if(D instanceof THREE.Line){T.multiply(s,V);P=D.geometry.vertices;A=P[0];A.positionScreen.copy(A.position);T.multiplyVector4(A.positionScreen);u=1;for(C=P.length;u<C;u++){v=P[u];v.positionScreen.copy(v.position);T.multiplyVector4(v.positionScreen);O=P[u-1];Q.copy(v.positionScreen);f.copy(O.positionScreen);if(c(Q,f)){Q.multiplyScalar(1/
-Q.w);f.multiplyScalar(1/f.w);n=y[z]=y[z]||new THREE.RenderableLine;n.v1.positionScreen.copy(Q);n.v2.positionScreen.copy(f);n.z=Math.max(Q.z,f.z);n.materials=D.materials;j.push(n);z++}}}else if(D instanceof THREE.Particle){M.set(D.position.x,D.position.y,D.position.z,1);s.multiplyVector4(M);M.z/=M.w;if(M.z>0&&M.z<1){w=I[x]=I[x]||new THREE.RenderableParticle;w.x=M.x/M.w;w.y=M.y/M.w;w.z=M.z;w.rotation=D.rotation.z;w.scale.x=D.scale.x*Math.abs(w.x-(M.x+e.projectionMatrix.n11)/(M.w+e.projectionMatrix.n14));
-w.scale.y=D.scale.y*Math.abs(w.y-(M.y+e.projectionMatrix.n22)/(M.w+e.projectionMatrix.n24));w.materials=D.materials;j.push(w);x++}}}}o&&j.sort(a);return j};this.unprojectVector=function(h,e){var o=THREE.Matrix4.makeInvert(e.matrix);o.multiplySelf(THREE.Matrix4.makeInvert(e.projectionMatrix));o.multiplyVector3(h);return h}};
-THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,c=new THREE.Projector,d,g,i,l;this.domElement=document.createElement("div");this.setSize=function(b,r){d=b;g=r;i=d/2;l=g/2};this.render=function(b,r){var m,n,z,y,w,x,I,N;a=c.projectScene(b,r);m=0;for(n=a.length;m<n;m++){w=a[m];if(w instanceof THREE.RenderableParticle){I=w.x*i+i;N=w.y*l+l;z=0;for(y=w.material.length;z<y;z++){x=w.material[z];if(x instanceof THREE.ParticleDOMMaterial){x=x.domElement;x.style.left=I+"px";x.style.top=N+"px"}}}}}};
-THREE.CanvasRenderer=function(){function a(aa){if(w!=aa)n.globalAlpha=w=aa}function c(aa){if(x!=aa){switch(aa){case THREE.NormalBlending:n.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:n.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:n.globalCompositeOperation="darker"}x=aa}}var d=null,g=new THREE.Projector,i=document.createElement("canvas"),l,b,r,m,n=i.getContext("2d"),z=new THREE.Color(0),y=0,w=1,x=0,I=null,N=null,M=1,s,T,F,Q,f,p,h,e,o,j=new THREE.Color,
-t=new THREE.Color,q=new THREE.Color,k=new THREE.Color,u=new THREE.Color,C,v,O,G,D,V,U,J,H,K=new THREE.Rectangle,P=new THREE.Rectangle,A=new THREE.Rectangle,L=false,X=new THREE.Color,ga=new THREE.Color,da=new THREE.Color,Y=new THREE.Color,ba=Math.PI*2,Z=new THREE.Vector3,ea,wa,ha,ia,sa,pa,qa=16;ea=document.createElement("canvas");ea.width=ea.height=2;wa=ea.getContext("2d");wa.fillStyle="rgba(0,0,0,1)";wa.fillRect(0,0,2,2);ha=wa.getImageData(0,0,2,2);ia=ha.data;sa=document.createElement("canvas");sa.width=
-sa.height=qa;pa=sa.getContext("2d");pa.translate(-qa/2,-qa/2);pa.scale(qa,qa);qa--;this.domElement=i;this.sortElements=this.sortObjects=this.autoClear=true;this.setSize=function(aa,ma){l=aa;b=ma;r=l/2;m=b/2;i.width=l;i.height=b;K.set(-r,-m,r,m);w=1;x=0;N=I=null;M=1};this.setClearColor=function(aa,ma){z=aa;y=ma;P.set(-r,-m,r,m);n.setTransform(1,0,0,-1,r,m);this.clear()};this.setClearColorHex=function(aa,ma){z.setHex(aa);y=ma;P.set(-r,-m,r,m);n.setTransform(1,0,0,-1,r,m);this.clear()};this.clear=function(){n.setTransform(1,
-0,0,-1,r,m);if(!P.isEmpty()){P.inflate(1);P.minSelf(K);if(z.hex==0&&y==0)n.clearRect(P.getX(),P.getY(),P.getWidth(),P.getHeight());else{c(THREE.NormalBlending);a(1);n.fillStyle="rgba("+Math.floor(z.r*255)+","+Math.floor(z.g*255)+","+Math.floor(z.b*255)+","+y+")";n.fillRect(P.getX(),P.getY(),P.getWidth(),P.getHeight())}P.empty()}};this.render=function(aa,ma){function ka(B){var W,S,E,R=B.lights;ga.setRGB(0,0,0);da.setRGB(0,0,0);Y.setRGB(0,0,0);B=0;for(W=R.length;B<W;B++){S=R[B];E=S.color;if(S instanceof
-THREE.AmbientLight){ga.r+=E.r;ga.g+=E.g;ga.b+=E.b}else if(S instanceof THREE.DirectionalLight){da.r+=E.r;da.g+=E.g;da.b+=E.b}else if(S instanceof THREE.PointLight){Y.r+=E.r;Y.g+=E.g;Y.b+=E.b}}}function xa(B,W,S,E){var R,$,fa,ja,la=B.lights;B=0;for(R=la.length;B<R;B++){$=la[B];fa=$.color;ja=$.intensity;if($ instanceof THREE.DirectionalLight){$=S.dot($.position)*ja;if($>0){E.r+=fa.r*$;E.g+=fa.g*$;E.b+=fa.b*$}}else if($ instanceof THREE.PointLight){Z.sub($.position,W);Z.normalize();$=S.dot(Z)*ja;if($>
-0){E.r+=fa.r*$;E.g+=fa.g*$;E.b+=fa.b*$}}}}function Ga(B,W,S){if(S.opacity!=0){a(S.opacity);c(S.blending);var E,R,$,fa,ja,la;if(S instanceof THREE.ParticleBasicMaterial){if(S.map&&S.map.image.loaded){fa=S.map.image;ja=fa.width>>1;la=fa.height>>1;R=W.scale.x*r;$=W.scale.y*m;S=R*ja;E=$*la;A.set(B.x-S,B.y-E,B.x+S,B.y+E);if(!K.instersects(A))return;n.save();n.translate(B.x,B.y);n.rotate(-W.rotation);n.scale(R,-$);n.translate(-ja,-la);n.drawImage(fa,0,0);n.restore()}n.beginPath();n.moveTo(B.x-10,B.y);n.lineTo(B.x+
-10,B.y);n.moveTo(B.x,B.y-10);n.lineTo(B.x,B.y+10);n.closePath();n.strokeStyle="rgb(255,255,0)";n.stroke()}else if(S instanceof THREE.ParticleCircleMaterial){if(L){X.r=ga.r+da.r+Y.r;X.g=ga.g+da.g+Y.g;X.b=ga.b+da.b+Y.b;j.r=S.color.r*X.r;j.g=S.color.g*X.g;j.b=S.color.b*X.b;j.updateStyleString()}else j.__styleString=S.color.__styleString;S=W.scale.x*r;E=W.scale.y*m;A.set(B.x-S,B.y-E,B.x+S,B.y+E);if(K.instersects(A)){R=j.__styleString;if(N!=R)n.fillStyle=N=R;n.save();n.translate(B.x,B.y);n.rotate(-W.rotation);
-n.scale(S,E);n.beginPath();n.arc(0,0,1,0,ba,true);n.closePath();n.fill();n.restore()}}}}function Ha(B,W,S,E){if(E.opacity!=0){a(E.opacity);c(E.blending);n.beginPath();n.moveTo(B.positionScreen.x,B.positionScreen.y);n.lineTo(W.positionScreen.x,W.positionScreen.y);n.closePath();if(E instanceof THREE.LineBasicMaterial){j.__styleString=E.color.__styleString;B=E.linewidth;if(M!=B)n.lineWidth=M=B;B=j.__styleString;if(I!=B)n.strokeStyle=I=B;n.stroke();A.inflate(E.linewidth*2)}}}function Da(B,W,S,E,R,$){if(R.opacity!=
-0){a(R.opacity);c(R.blending);Q=B.positionScreen.x;f=B.positionScreen.y;p=W.positionScreen.x;h=W.positionScreen.y;e=S.positionScreen.x;o=S.positionScreen.y;n.beginPath();n.moveTo(Q,f);n.lineTo(p,h);n.lineTo(e,o);n.lineTo(Q,f);n.closePath();if(R instanceof THREE.MeshBasicMaterial)if(R.map)R.map.image.loaded&&R.map.mapping instanceof THREE.UVMapping&&Aa(Q,f,p,h,e,o,R.map.image,E.uvs[0].u,E.uvs[0].v,E.uvs[1].u,E.uvs[1].v,E.uvs[2].u,E.uvs[2].v);else if(R.env_map){if(R.env_map.image.loaded)if(R.env_map.mapping instanceof
-THREE.SphericalReflectionMapping){B=ma.matrix;Z.copy(E.vertexNormalsWorld[0]);G=(Z.x*B.n11+Z.y*B.n12+Z.z*B.n13)*0.5+0.5;D=-(Z.x*B.n21+Z.y*B.n22+Z.z*B.n23)*0.5+0.5;Z.copy(E.vertexNormalsWorld[1]);V=(Z.x*B.n11+Z.y*B.n12+Z.z*B.n13)*0.5+0.5;U=-(Z.x*B.n21+Z.y*B.n22+Z.z*B.n23)*0.5+0.5;Z.copy(E.vertexNormalsWorld[2]);J=(Z.x*B.n11+Z.y*B.n12+Z.z*B.n13)*0.5+0.5;H=-(Z.x*B.n21+Z.y*B.n22+Z.z*B.n23)*0.5+0.5;Aa(Q,f,p,h,e,o,R.env_map.image,G,D,V,U,J,H)}}else R.wireframe?na(R.color.__styleString,R.wireframe_linewidth):
-Ea(R.color.__styleString);else if(R instanceof THREE.MeshLambertMaterial){if(R.map&&!R.wireframe){R.map.mapping instanceof THREE.UVMapping&&Aa(Q,f,p,h,e,o,R.map.image,E.uvs[0].u,E.uvs[0].v,E.uvs[1].u,E.uvs[1].v,E.uvs[2].u,E.uvs[2].v);c(THREE.SubtractiveBlending)}if(L)if(!R.wireframe&&R.shading==THREE.SmoothShading&&E.vertexNormalsWorld.length==3){t.r=q.r=k.r=ga.r;t.g=q.g=k.g=ga.g;t.b=q.b=k.b=ga.b;xa($,E.v1.positionWorld,E.vertexNormalsWorld[0],t);xa($,E.v2.positionWorld,E.vertexNormalsWorld[1],q);
-xa($,E.v3.positionWorld,E.vertexNormalsWorld[2],k);u.r=(q.r+k.r)*0.5;u.g=(q.g+k.g)*0.5;u.b=(q.b+k.b)*0.5;O=Ma(t,q,k,u);Aa(Q,f,p,h,e,o,O,0,0,1,0,0,1)}else{X.r=ga.r;X.g=ga.g;X.b=ga.b;xa($,E.centroidWorld,E.normalWorld,X);j.r=R.color.r*X.r;j.g=R.color.g*X.g;j.b=R.color.b*X.b;j.updateStyleString();R.wireframe?na(j.__styleString,R.wireframe_linewidth):Ea(j.__styleString)}else R.wireframe?na(R.color.__styleString,R.wireframe_linewidth):Ea(R.color.__styleString)}else if(R instanceof THREE.MeshDepthMaterial){C=
-ma.near;v=ma.far;t.r=t.g=t.b=1-Ia(B.positionScreen.z,C,v);q.r=q.g=q.b=1-Ia(W.positionScreen.z,C,v);k.r=k.g=k.b=1-Ia(S.positionScreen.z,C,v);u.r=(q.r+k.r)*0.5;u.g=(q.g+k.g)*0.5;u.b=(q.b+k.b)*0.5;O=Ma(t,q,k,u);Aa(Q,f,p,h,e,o,O,0,0,1,0,0,1)}else if(R instanceof THREE.MeshNormalMaterial){j.r=Ja(E.normalWorld.x);j.g=Ja(E.normalWorld.y);j.b=Ja(E.normalWorld.z);j.updateStyleString();R.wireframe?na(j.__styleString,R.wireframe_linewidth):Ea(j.__styleString)}}}function na(B,W){if(I!=B)n.strokeStyle=I=B;if(M!=
-W)n.lineWidth=M=W;n.stroke();A.inflate(W*2)}function Ea(B){if(N!=B)n.fillStyle=N=B;n.fill()}function Aa(B,W,S,E,R,$,fa,ja,la,ta,oa,ua,Ba){var ya,va;ya=fa.width-1;va=fa.height-1;ja*=ya;la*=va;ta*=ya;oa*=va;ua*=ya;Ba*=va;S-=B;E-=W;R-=B;$-=W;ta-=ja;oa-=la;ua-=ja;Ba-=la;va=1/(ta*Ba-ua*oa);ya=(Ba*S-oa*R)*va;oa=(Ba*E-oa*$)*va;S=(ta*R-ua*S)*va;E=(ta*$-ua*E)*va;B=B-ya*ja-S*la;W=W-oa*ja-E*la;n.save();n.transform(ya,oa,S,E,B,W);n.clip();n.drawImage(fa,0,0);n.restore()}function Ma(B,W,S,E){var R=~~(B.r*255),
-$=~~(B.g*255);B=~~(B.b*255);var fa=~~(W.r*255),ja=~~(W.g*255);W=~~(W.b*255);var la=~~(S.r*255),ta=~~(S.g*255);S=~~(S.b*255);var oa=~~(E.r*255),ua=~~(E.g*255);E=~~(E.b*255);ia[0]=R<0?0:R>255?255:R;ia[1]=$<0?0:$>255?255:$;ia[2]=B<0?0:B>255?255:B;ia[4]=fa<0?0:fa>255?255:fa;ia[5]=ja<0?0:ja>255?255:ja;ia[6]=W<0?0:W>255?255:W;ia[8]=la<0?0:la>255?255:la;ia[9]=ta<0?0:ta>255?255:ta;ia[10]=S<0?0:S>255?255:S;ia[12]=oa<0?0:oa>255?255:oa;ia[13]=ua<0?0:ua>255?255:ua;ia[14]=E<0?0:E>255?255:E;wa.putImageData(ha,
-0,0);pa.drawImage(ea,0,0);return sa}function Ia(B,W,S){B=(B-W)/(S-W);return B*B*(3-2*B)}function Ja(B){B=(B+1)*0.5;return B<0?0:B>1?1:B}function Ka(B,W){var S=W.x-B.x,E=W.y-B.y,R=1/Math.sqrt(S*S+E*E);S*=R;E*=R;W.x+=S;W.y+=E;B.x-=S;B.y-=E}var Fa,Na,ca,ra,za,La,Oa,Ca;this.autoClear?this.clear():n.setTransform(1,0,0,-1,r,m);d=g.projectScene(aa,ma,this.sortElements);n.fillStyle="rgba( 0, 255, 255, 0.5 )";n.fillRect(K.getX(),K.getY(),K.getWidth(),K.getHeight());(L=aa.lights.length>0)&&ka(aa);Fa=0;for(Na=
-d.length;Fa<Na;Fa++){ca=d[Fa];A.empty();if(ca instanceof THREE.RenderableParticle){s=ca;s.x*=r;s.y*=m;ra=0;for(za=ca.materials.length;ra<za;ra++)Ga(s,ca,ca.materials[ra],aa)}else if(ca instanceof THREE.RenderableLine){s=ca.v1;T=ca.v2;s.positionScreen.x*=r;s.positionScreen.y*=m;T.positionScreen.x*=r;T.positionScreen.y*=m;A.addPoint(s.positionScreen.x,s.positionScreen.y);A.addPoint(T.positionScreen.x,T.positionScreen.y);if(K.instersects(A)){ra=0;for(za=ca.materials.length;ra<za;)Ha(s,T,ca,ca.materials[ra++],
-aa)}}else if(ca instanceof THREE.RenderableFace3){s=ca.v1;T=ca.v2;F=ca.v3;s.positionScreen.x*=r;s.positionScreen.y*=m;T.positionScreen.x*=r;T.positionScreen.y*=m;F.positionScreen.x*=r;F.positionScreen.y*=m;if(ca.overdraw){Ka(s.positionScreen,T.positionScreen);Ka(T.positionScreen,F.positionScreen);Ka(F.positionScreen,s.positionScreen)}A.add3Points(s.positionScreen.x,s.positionScreen.y,T.positionScreen.x,T.positionScreen.y,F.positionScreen.x,F.positionScreen.y);if(K.instersects(A)){ra=0;for(za=ca.meshMaterials.length;ra<
-za;){Ca=ca.meshMaterials[ra++];if(Ca instanceof THREE.MeshFaceMaterial){La=0;for(Oa=ca.faceMaterials.length;La<Oa;)(Ca=ca.faceMaterials[La++])&&Da(s,T,F,ca,Ca,aa)}else Da(s,T,F,ca,Ca,aa)}}}P.addRectangle(A)}n.lineWidth=1;n.strokeStyle="rgba( 255, 0, 0, 0.5 )";n.strokeRect(P.getX(),P.getY(),P.getWidth(),P.getHeight());n.setTransform(1,0,0,1,0,0)}};
-THREE.SVGRenderer=function(){function a(G,D,V){var U,J,H,K;U=0;for(J=G.lights.length;U<J;U++){H=G.lights[U];if(H instanceof THREE.DirectionalLight){K=D.normalWorld.dot(H.position)*H.intensity;if(K>0){V.r+=H.color.r*K;V.g+=H.color.g*K;V.b+=H.color.b*K}}else if(H instanceof THREE.PointLight){o.sub(H.position,D.centroidWorld);o.normalize();K=D.normalWorld.dot(o)*H.intensity;if(K>0){V.r+=H.color.r*K;V.g+=H.color.g*K;V.b+=H.color.b*K}}}}function c(G,D,V,U,J,H){k=g(u++);k.setAttribute("d","M "+G.positionScreen.x+
-" "+G.positionScreen.y+" L "+D.positionScreen.x+" "+D.positionScreen.y+" L "+V.positionScreen.x+","+V.positionScreen.y+"z");if(J instanceof THREE.MeshBasicMaterial)F.__styleString=J.color.__styleString;else if(J instanceof THREE.MeshLambertMaterial)if(T){Q.r=f.r;Q.g=f.g;Q.b=f.b;a(H,U,Q);F.r=J.color.r*Q.r;F.g=J.color.g*Q.g;F.b=J.color.b*Q.b;F.updateStyleString()}else F.__styleString=J.color.__styleString;else if(J instanceof THREE.MeshDepthMaterial){e=1-J.__2near/(J.__farPlusNear-U.z*J.__farMinusNear);
-F.setRGB(e,e,e)}else J instanceof THREE.MeshNormalMaterial&&F.setRGB(i(U.normalWorld.x),i(U.normalWorld.y),i(U.normalWorld.z));J.wireframe?k.setAttribute("style","fill: none; stroke: "+F.__styleString+"; stroke-width: "+J.wireframe_linewidth+"; stroke-opacity: "+J.opacity+"; stroke-linecap: "+J.wireframe_linecap+"; stroke-linejoin: "+J.wireframe_linejoin):k.setAttribute("style","fill: "+F.__styleString+"; fill-opacity: "+J.opacity);r.appendChild(k)}function d(G,D,V,U,J,H,K){k=g(u++);k.setAttribute("d",
-"M "+G.positionScreen.x+" "+G.positionScreen.y+" L "+D.positionScreen.x+" "+D.positionScreen.y+" L "+V.positionScreen.x+","+V.positionScreen.y+" L "+U.positionScreen.x+","+U.positionScreen.y+"z");if(H instanceof THREE.MeshBasicMaterial)F.__styleString=H.color.__styleString;else if(H instanceof THREE.MeshLambertMaterial)if(T){Q.r=f.r;Q.g=f.g;Q.b=f.b;a(K,J,Q);F.r=H.color.r*Q.r;F.g=H.color.g*Q.g;F.b=H.color.b*Q.b;F.updateStyleString()}else F.__styleString=H.color.__styleString;else if(H instanceof THREE.MeshDepthMaterial){e=
-1-H.__2near/(H.__farPlusNear-J.z*H.__farMinusNear);F.setRGB(e,e,e)}else H instanceof THREE.MeshNormalMaterial&&F.setRGB(i(J.normalWorld.x),i(J.normalWorld.y),i(J.normalWorld.z));H.wireframe?k.setAttribute("style","fill: none; stroke: "+F.__styleString+"; stroke-width: "+H.wireframe_linewidth+"; stroke-opacity: "+H.opacity+"; stroke-linecap: "+H.wireframe_linecap+"; stroke-linejoin: "+H.wireframe_linejoin):k.setAttribute("style","fill: "+F.__styleString+"; fill-opacity: "+H.opacity);r.appendChild(k)}
-function g(G){if(j[G]==null){j[G]=document.createElementNS("http://www.w3.org/2000/svg","path");O==0&&j[G].setAttribute("shape-rendering","crispEdges");return j[G]}return j[G]}function i(G){return G<0?Math.min((1+G)*0.5,0.5):0.5+Math.min(G*0.5,0.5)}var l=null,b=new THREE.Projector,r=document.createElementNS("http://www.w3.org/2000/svg","svg"),m,n,z,y,w,x,I,N,M=new THREE.Rectangle,s=new THREE.Rectangle,T=false,F=new THREE.Color(16777215),Q=new THREE.Color(16777215),f=new THREE.Color(0),p=new THREE.Color(0),
-h=new THREE.Color(0),e,o=new THREE.Vector3,j=[],t=[],q=[],k,u,C,v,O=1;this.domElement=r;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(G){switch(G){case "high":O=1;break;case "low":O=0}};this.setSize=function(G,D){m=G;n=D;z=m/2;y=n/2;r.setAttribute("viewBox",-z+" "+-y+" "+m+" "+n);r.setAttribute("width",m);r.setAttribute("height",n);M.set(-z,-y,z,y)};this.clear=function(){for(;r.childNodes.length>0;)r.removeChild(r.childNodes[0])};this.render=function(G,D){var V,U,
-J,H,K,P,A,L;this.autoClear&&this.clear();l=b.projectScene(G,D,this.sortElements);v=C=u=0;if(T=G.lights.length>0){A=G.lights;f.setRGB(0,0,0);p.setRGB(0,0,0);h.setRGB(0,0,0);V=0;for(U=A.length;V<U;V++){J=A[V];H=J.color;if(J instanceof THREE.AmbientLight){f.r+=H.r;f.g+=H.g;f.b+=H.b}else if(J instanceof THREE.DirectionalLight){p.r+=H.r;p.g+=H.g;p.b+=H.b}else if(J instanceof THREE.PointLight){h.r+=H.r;h.g+=H.g;h.b+=H.b}}}V=0;for(U=l.length;V<U;V++){A=l[V];s.empty();if(A instanceof THREE.RenderableParticle){w=
-A;w.x*=z;w.y*=-y;J=0;for(H=A.materials.length;J<H;J++)if(L=A.materials[J]){K=w;P=A;L=L;var X=C++;if(t[X]==null){t[X]=document.createElementNS("http://www.w3.org/2000/svg","circle");O==0&&t[X].setAttribute("shape-rendering","crispEdges")}k=t[X];k.setAttribute("cx",K.x);k.setAttribute("cy",K.y);k.setAttribute("r",P.scale.x*z);if(L instanceof THREE.ParticleCircleMaterial){if(T){Q.r=f.r+p.r+h.r;Q.g=f.g+p.g+h.g;Q.b=f.b+p.b+h.b;F.r=L.color.r*Q.r;F.g=L.color.g*Q.g;F.b=L.color.b*Q.b;F.updateStyleString()}else F=
-L.color;k.setAttribute("style","fill: "+F.__styleString)}r.appendChild(k)}}else if(A instanceof THREE.RenderableLine){w=A.v1;x=A.v2;w.positionScreen.x*=z;w.positionScreen.y*=-y;x.positionScreen.x*=z;x.positionScreen.y*=-y;s.addPoint(w.positionScreen.x,w.positionScreen.y);s.addPoint(x.positionScreen.x,x.positionScreen.y);if(M.instersects(s)){J=0;for(H=A.materials.length;J<H;)if(L=A.materials[J++]){K=w;P=x;L=L;X=v++;if(q[X]==null){q[X]=document.createElementNS("http://www.w3.org/2000/svg","line");O==
-0&&q[X].setAttribute("shape-rendering","crispEdges")}k=q[X];k.setAttribute("x1",K.positionScreen.x);k.setAttribute("y1",K.positionScreen.y);k.setAttribute("x2",P.positionScreen.x);k.setAttribute("y2",P.positionScreen.y);if(L instanceof THREE.LineBasicMaterial){F.__styleString=L.color.__styleString;k.setAttribute("style","fill: none; stroke: "+F.__styleString+"; stroke-width: "+L.linewidth+"; stroke-opacity: "+L.opacity+"; stroke-linecap: "+L.linecap+"; stroke-linejoin: "+L.linejoin);r.appendChild(k)}}}}else if(A instanceof
-THREE.RenderableFace3){w=A.v1;x=A.v2;I=A.v3;w.positionScreen.x*=z;w.positionScreen.y*=-y;x.positionScreen.x*=z;x.positionScreen.y*=-y;I.positionScreen.x*=z;I.positionScreen.y*=-y;s.addPoint(w.positionScreen.x,w.positionScreen.y);s.addPoint(x.positionScreen.x,x.positionScreen.y);s.addPoint(I.positionScreen.x,I.positionScreen.y);if(M.instersects(s)){J=0;for(H=A.meshMaterials.length;J<H;){L=A.meshMaterials[J++];if(L instanceof THREE.MeshFaceMaterial){K=0;for(P=A.faceMaterials.length;K<P;)(L=A.faceMaterials[K++])&&
-c(w,x,I,A,L,G)}else L&&c(w,x,I,A,L,G)}}}else if(A instanceof THREE.RenderableFace4){w=A.v1;x=A.v2;I=A.v3;N=A.v4;w.positionScreen.x*=z;w.positionScreen.y*=-y;x.positionScreen.x*=z;x.positionScreen.y*=-y;I.positionScreen.x*=z;I.positionScreen.y*=-y;N.positionScreen.x*=z;N.positionScreen.y*=-y;s.addPoint(w.positionScreen.x,w.positionScreen.y);s.addPoint(x.positionScreen.x,x.positionScreen.y);s.addPoint(I.positionScreen.x,I.positionScreen.y);s.addPoint(N.positionScreen.x,N.positionScreen.y);if(M.instersects(s)){J=
-0;for(H=A.meshMaterials.length;J<H;){L=A.meshMaterials[J++];if(L instanceof THREE.MeshFaceMaterial){K=0;for(P=A.faceMaterials.length;K<P;)(L=A.faceMaterials[K++])&&d(w,x,I,N,A,L,G)}else L&&d(w,x,I,N,A,L,G)}}}}}};
+i[g]=i[g]||new THREE.RenderableObject;N.copy(q.position);s.multiplyVector3(N);d.object=q;d.z=N.z;j.push(d);g++}}n&&j.sort(a);return j};this.projectScene=function(h,e,n){var j=[],t=e.near,q=e.far,k,u,C,v,O,G,D,U,X,L,H,J,P,A,K,W;r=z=x=0;e.autoUpdateMatrix&&e.updateMatrix();s.multiply(e.projectionMatrix,e.matrix);G=this.projectObjects(h,e,true);h=0;for(k=G.length;h<k;h++){D=G[h].object;if(D.visible){D.autoUpdateMatrix&&D.updateMatrix();U=D.matrix;X=D.rotationMatrix;L=D.materials;H=D.overdraw;if(D instanceof
+THREE.Mesh){J=D.geometry;P=J.vertices;u=0;for(C=P.length;u<C;u++){A=P[u];A.positionWorld.copy(A.position);U.multiplyVector3(A.positionWorld);v=A.positionScreen;v.copy(A.positionWorld);s.multiplyVector4(v);v.x/=v.w;v.y/=v.w;A.__visible=v.z>t&&v.z<q}J=J.faces;u=0;for(C=J.length;u<C;u++){A=J[u];if(A instanceof THREE.Face3){v=P[A.a];O=P[A.b];K=P[A.c];if(v.__visible&&O.__visible&&K.__visible)if(D.doubleSided||D.flipSided!=(K.positionScreen.x-v.positionScreen.x)*(O.positionScreen.y-v.positionScreen.y)-
+(K.positionScreen.y-v.positionScreen.y)*(O.positionScreen.x-v.positionScreen.x)<0){l=m[r]=m[r]||new THREE.RenderableFace3;l.v1.positionWorld.copy(v.positionWorld);l.v2.positionWorld.copy(O.positionWorld);l.v3.positionWorld.copy(K.positionWorld);l.v1.positionScreen.copy(v.positionScreen);l.v2.positionScreen.copy(O.positionScreen);l.v3.positionScreen.copy(K.positionScreen);l.normalWorld.copy(A.normal);X.multiplyVector3(l.normalWorld);l.centroidWorld.copy(A.centroid);U.multiplyVector3(l.centroidWorld);
+l.centroidScreen.copy(l.centroidWorld);s.multiplyVector3(l.centroidScreen);K=A.vertexNormals;p=l.vertexNormalsWorld;v=0;for(O=K.length;v<O;v++){W=p[v]=p[v]||new THREE.Vector3;W.copy(K[v]);X.multiplyVector3(W)}l.z=l.centroidScreen.z;l.meshMaterials=L;l.faceMaterials=A.materials;l.overdraw=H;if(D.geometry.uvs[u]){l.uvs[0]=D.geometry.uvs[u][0];l.uvs[1]=D.geometry.uvs[u][1];l.uvs[2]=D.geometry.uvs[u][2]}j.push(l);r++}}else if(A instanceof THREE.Face4){v=P[A.a];O=P[A.b];K=P[A.c];W=P[A.d];if(v.__visible&&
+O.__visible&&K.__visible&&W.__visible)if(D.doubleSided||D.flipSided!=((W.positionScreen.x-v.positionScreen.x)*(O.positionScreen.y-v.positionScreen.y)-(W.positionScreen.y-v.positionScreen.y)*(O.positionScreen.x-v.positionScreen.x)<0||(O.positionScreen.x-K.positionScreen.x)*(W.positionScreen.y-K.positionScreen.y)-(O.positionScreen.y-K.positionScreen.y)*(W.positionScreen.x-K.positionScreen.x)<0)){l=m[r]=m[r]||new THREE.RenderableFace3;l.v1.positionWorld.copy(v.positionWorld);l.v2.positionWorld.copy(O.positionWorld);
+l.v3.positionWorld.copy(W.positionWorld);l.v1.positionScreen.copy(v.positionScreen);l.v2.positionScreen.copy(O.positionScreen);l.v3.positionScreen.copy(W.positionScreen);l.normalWorld.copy(A.normal);X.multiplyVector3(l.normalWorld);l.centroidWorld.copy(A.centroid);U.multiplyVector3(l.centroidWorld);l.centroidScreen.copy(l.centroidWorld);s.multiplyVector3(l.centroidScreen);l.z=l.centroidScreen.z;l.meshMaterials=L;l.faceMaterials=A.materials;l.overdraw=H;if(D.geometry.uvs[u]){l.uvs[0]=D.geometry.uvs[u][0];
+l.uvs[1]=D.geometry.uvs[u][1];l.uvs[2]=D.geometry.uvs[u][3]}j.push(l);r++;b=m[r]=m[r]||new THREE.RenderableFace3;b.v1.positionWorld.copy(O.positionWorld);b.v2.positionWorld.copy(K.positionWorld);b.v3.positionWorld.copy(W.positionWorld);b.v1.positionScreen.copy(O.positionScreen);b.v2.positionScreen.copy(K.positionScreen);b.v3.positionScreen.copy(W.positionScreen);b.normalWorld.copy(l.normalWorld);b.centroidWorld.copy(l.centroidWorld);b.centroidScreen.copy(l.centroidScreen);b.z=b.centroidScreen.z;b.meshMaterials=
+L;b.faceMaterials=A.materials;b.overdraw=H;if(D.geometry.uvs[u]){b.uvs[0]=D.geometry.uvs[u][1];b.uvs[1]=D.geometry.uvs[u][2];b.uvs[2]=D.geometry.uvs[u][3]}j.push(b);r++}}}}else if(D instanceof THREE.Line){T.multiply(s,U);P=D.geometry.vertices;A=P[0];A.positionScreen.copy(A.position);T.multiplyVector4(A.positionScreen);u=1;for(C=P.length;u<C;u++){v=P[u];v.positionScreen.copy(v.position);T.multiplyVector4(v.positionScreen);O=P[u-1];Q.copy(v.positionScreen);f.copy(O.positionScreen);if(c(Q,f)){Q.multiplyScalar(1/
+Q.w);f.multiplyScalar(1/f.w);o=y[z]=y[z]||new THREE.RenderableLine;o.v1.positionScreen.copy(Q);o.v2.positionScreen.copy(f);o.z=Math.max(Q.z,f.z);o.materials=D.materials;j.push(o);z++}}}else if(D instanceof THREE.Particle){M.set(D.position.x,D.position.y,D.position.z,1);s.multiplyVector4(M);M.z/=M.w;if(M.z>0&&M.z<1){w=I[x]=I[x]||new THREE.RenderableParticle;w.x=M.x/M.w;w.y=M.y/M.w;w.z=M.z;w.rotation=D.rotation.z;w.scale.x=D.scale.x*Math.abs(w.x-(M.x+e.projectionMatrix.n11)/(M.w+e.projectionMatrix.n14));
+w.scale.y=D.scale.y*Math.abs(w.y-(M.y+e.projectionMatrix.n22)/(M.w+e.projectionMatrix.n24));w.materials=D.materials;j.push(w);x++}}}}n&&j.sort(a);return j};this.unprojectVector=function(h,e){var n=THREE.Matrix4.makeInvert(e.matrix);n.multiplySelf(THREE.Matrix4.makeInvert(e.projectionMatrix));n.multiplyVector3(h);return h}};
+THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,c=new THREE.Projector,d,g,i,l;this.domElement=document.createElement("div");this.setSize=function(b,r){d=b;g=r;i=d/2;l=g/2};this.render=function(b,r){var m,o,z,y,w,x,I,N;a=c.projectScene(b,r);m=0;for(o=a.length;m<o;m++){w=a[m];if(w instanceof THREE.RenderableParticle){I=w.x*i+i;N=w.y*l+l;z=0;for(y=w.material.length;z<y;z++){x=w.material[z];if(x instanceof THREE.ParticleDOMMaterial){x=x.domElement;x.style.left=I+"px";x.style.top=N+"px"}}}}}};
+THREE.CanvasRenderer=function(){function a(aa){if(w!=aa)o.globalAlpha=w=aa}function c(aa){if(x!=aa){switch(aa){case THREE.NormalBlending:o.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:o.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:o.globalCompositeOperation="darker"}x=aa}}var d=null,g=new THREE.Projector,i=document.createElement("canvas"),l,b,r,m,o=i.getContext("2d"),z=new THREE.Color(0),y=0,w=1,x=0,I=null,N=null,M=1,s,T,F,Q,f,p,h,e,n,j=new THREE.Color,
+t=new THREE.Color,q=new THREE.Color,k=new THREE.Color,u=new THREE.Color,C,v,O,G,D,U,X,L,H,J=new THREE.Rectangle,P=new THREE.Rectangle,A=new THREE.Rectangle,K=false,W=new THREE.Color,ga=new THREE.Color,da=new THREE.Color,Y=new THREE.Color,ba=Math.PI*2,Z=new THREE.Vector3,ea,wa,ha,ia,sa,pa,qa=16;ea=document.createElement("canvas");ea.width=ea.height=2;wa=ea.getContext("2d");wa.fillStyle="rgba(0,0,0,1)";wa.fillRect(0,0,2,2);ha=wa.getImageData(0,0,2,2);ia=ha.data;sa=document.createElement("canvas");sa.width=
+sa.height=qa;pa=sa.getContext("2d");pa.translate(-qa/2,-qa/2);pa.scale(qa,qa);qa--;this.domElement=i;this.sortElements=this.sortObjects=this.autoClear=true;this.setSize=function(aa,ma){l=aa;b=ma;r=l/2;m=b/2;i.width=l;i.height=b;J.set(-r,-m,r,m);w=1;x=0;N=I=null;M=1};this.setClearColor=function(aa,ma){z=aa;y=ma;P.set(-r,-m,r,m);o.setTransform(1,0,0,-1,r,m);this.clear()};this.setClearColorHex=function(aa,ma){z.setHex(aa);y=ma;P.set(-r,-m,r,m);o.setTransform(1,0,0,-1,r,m);this.clear()};this.clear=function(){o.setTransform(1,
+0,0,-1,r,m);if(!P.isEmpty()){P.inflate(1);P.minSelf(J);if(z.hex==0&&y==0)o.clearRect(P.getX(),P.getY(),P.getWidth(),P.getHeight());else{c(THREE.NormalBlending);a(1);o.fillStyle="rgba("+Math.floor(z.r*255)+","+Math.floor(z.g*255)+","+Math.floor(z.b*255)+","+y+")";o.fillRect(P.getX(),P.getY(),P.getWidth(),P.getHeight())}P.empty()}};this.render=function(aa,ma){function ka(B){var V,S,E,R=B.lights;ga.setRGB(0,0,0);da.setRGB(0,0,0);Y.setRGB(0,0,0);B=0;for(V=R.length;B<V;B++){S=R[B];E=S.color;if(S instanceof
+THREE.AmbientLight){ga.r+=E.r;ga.g+=E.g;ga.b+=E.b}else if(S instanceof THREE.DirectionalLight){da.r+=E.r;da.g+=E.g;da.b+=E.b}else if(S instanceof THREE.PointLight){Y.r+=E.r;Y.g+=E.g;Y.b+=E.b}}}function xa(B,V,S,E){var R,$,fa,ja,la=B.lights;B=0;for(R=la.length;B<R;B++){$=la[B];fa=$.color;ja=$.intensity;if($ instanceof THREE.DirectionalLight){$=S.dot($.position)*ja;if($>0){E.r+=fa.r*$;E.g+=fa.g*$;E.b+=fa.b*$}}else if($ instanceof THREE.PointLight){Z.sub($.position,V);Z.normalize();$=S.dot(Z)*ja;if($>
+0){E.r+=fa.r*$;E.g+=fa.g*$;E.b+=fa.b*$}}}}function Ga(B,V,S){if(S.opacity!=0){a(S.opacity);c(S.blending);var E,R,$,fa,ja,la;if(S instanceof THREE.ParticleBasicMaterial){if(S.map&&S.map.image.loaded){fa=S.map.image;ja=fa.width>>1;la=fa.height>>1;R=V.scale.x*r;$=V.scale.y*m;S=R*ja;E=$*la;A.set(B.x-S,B.y-E,B.x+S,B.y+E);if(!J.instersects(A))return;o.save();o.translate(B.x,B.y);o.rotate(-V.rotation);o.scale(R,-$);o.translate(-ja,-la);o.drawImage(fa,0,0);o.restore()}o.beginPath();o.moveTo(B.x-10,B.y);o.lineTo(B.x+
+10,B.y);o.moveTo(B.x,B.y-10);o.lineTo(B.x,B.y+10);o.closePath();o.strokeStyle="rgb(255,255,0)";o.stroke()}else if(S instanceof THREE.ParticleCircleMaterial){if(K){W.r=ga.r+da.r+Y.r;W.g=ga.g+da.g+Y.g;W.b=ga.b+da.b+Y.b;j.r=S.color.r*W.r;j.g=S.color.g*W.g;j.b=S.color.b*W.b;j.updateStyleString()}else j.__styleString=S.color.__styleString;S=V.scale.x*r;E=V.scale.y*m;A.set(B.x-S,B.y-E,B.x+S,B.y+E);if(J.instersects(A)){R=j.__styleString;if(N!=R)o.fillStyle=N=R;o.save();o.translate(B.x,B.y);o.rotate(-V.rotation);
+o.scale(S,E);o.beginPath();o.arc(0,0,1,0,ba,true);o.closePath();o.fill();o.restore()}}}}function Ha(B,V,S,E){if(E.opacity!=0){a(E.opacity);c(E.blending);o.beginPath();o.moveTo(B.positionScreen.x,B.positionScreen.y);o.lineTo(V.positionScreen.x,V.positionScreen.y);o.closePath();if(E instanceof THREE.LineBasicMaterial){j.__styleString=E.color.__styleString;B=E.linewidth;if(M!=B)o.lineWidth=M=B;B=j.__styleString;if(I!=B)o.strokeStyle=I=B;o.stroke();A.inflate(E.linewidth*2)}}}function Da(B,V,S,E,R,$){if(R.opacity!=
+0){a(R.opacity);c(R.blending);Q=B.positionScreen.x;f=B.positionScreen.y;p=V.positionScreen.x;h=V.positionScreen.y;e=S.positionScreen.x;n=S.positionScreen.y;o.beginPath();o.moveTo(Q,f);o.lineTo(p,h);o.lineTo(e,n);o.lineTo(Q,f);o.closePath();if(R instanceof THREE.MeshBasicMaterial)if(R.map)R.map.image.loaded&&R.map.mapping instanceof THREE.UVMapping&&Aa(Q,f,p,h,e,n,R.map.image,E.uvs[0].u,E.uvs[0].v,E.uvs[1].u,E.uvs[1].v,E.uvs[2].u,E.uvs[2].v);else if(R.env_map){if(R.env_map.image.loaded)if(R.env_map.mapping instanceof
+THREE.SphericalReflectionMapping){B=ma.matrix;Z.copy(E.vertexNormalsWorld[0]);G=(Z.x*B.n11+Z.y*B.n12+Z.z*B.n13)*0.5+0.5;D=-(Z.x*B.n21+Z.y*B.n22+Z.z*B.n23)*0.5+0.5;Z.copy(E.vertexNormalsWorld[1]);U=(Z.x*B.n11+Z.y*B.n12+Z.z*B.n13)*0.5+0.5;X=-(Z.x*B.n21+Z.y*B.n22+Z.z*B.n23)*0.5+0.5;Z.copy(E.vertexNormalsWorld[2]);L=(Z.x*B.n11+Z.y*B.n12+Z.z*B.n13)*0.5+0.5;H=-(Z.x*B.n21+Z.y*B.n22+Z.z*B.n23)*0.5+0.5;Aa(Q,f,p,h,e,n,R.env_map.image,G,D,U,X,L,H)}}else R.wireframe?na(R.color.__styleString,R.wireframe_linewidth):
+Ea(R.color.__styleString);else if(R instanceof THREE.MeshLambertMaterial){if(R.map&&!R.wireframe){R.map.mapping instanceof THREE.UVMapping&&Aa(Q,f,p,h,e,n,R.map.image,E.uvs[0].u,E.uvs[0].v,E.uvs[1].u,E.uvs[1].v,E.uvs[2].u,E.uvs[2].v);c(THREE.SubtractiveBlending)}if(K)if(!R.wireframe&&R.shading==THREE.SmoothShading&&E.vertexNormalsWorld.length==3){t.r=q.r=k.r=ga.r;t.g=q.g=k.g=ga.g;t.b=q.b=k.b=ga.b;xa($,E.v1.positionWorld,E.vertexNormalsWorld[0],t);xa($,E.v2.positionWorld,E.vertexNormalsWorld[1],q);
+xa($,E.v3.positionWorld,E.vertexNormalsWorld[2],k);u.r=(q.r+k.r)*0.5;u.g=(q.g+k.g)*0.5;u.b=(q.b+k.b)*0.5;O=Ma(t,q,k,u);Aa(Q,f,p,h,e,n,O,0,0,1,0,0,1)}else{W.r=ga.r;W.g=ga.g;W.b=ga.b;xa($,E.centroidWorld,E.normalWorld,W);j.r=R.color.r*W.r;j.g=R.color.g*W.g;j.b=R.color.b*W.b;j.updateStyleString();R.wireframe?na(j.__styleString,R.wireframe_linewidth):Ea(j.__styleString)}else R.wireframe?na(R.color.__styleString,R.wireframe_linewidth):Ea(R.color.__styleString)}else if(R instanceof THREE.MeshDepthMaterial){C=
+ma.near;v=ma.far;t.r=t.g=t.b=1-Ia(B.positionScreen.z,C,v);q.r=q.g=q.b=1-Ia(V.positionScreen.z,C,v);k.r=k.g=k.b=1-Ia(S.positionScreen.z,C,v);u.r=(q.r+k.r)*0.5;u.g=(q.g+k.g)*0.5;u.b=(q.b+k.b)*0.5;O=Ma(t,q,k,u);Aa(Q,f,p,h,e,n,O,0,0,1,0,0,1)}else if(R instanceof THREE.MeshNormalMaterial){j.r=Ja(E.normalWorld.x);j.g=Ja(E.normalWorld.y);j.b=Ja(E.normalWorld.z);j.updateStyleString();R.wireframe?na(j.__styleString,R.wireframe_linewidth):Ea(j.__styleString)}}}function na(B,V){if(I!=B)o.strokeStyle=I=B;if(M!=
+V)o.lineWidth=M=V;o.stroke();A.inflate(V*2)}function Ea(B){if(N!=B)o.fillStyle=N=B;o.fill()}function Aa(B,V,S,E,R,$,fa,ja,la,ta,oa,ua,Ba){var ya,va;ya=fa.width-1;va=fa.height-1;ja*=ya;la*=va;ta*=ya;oa*=va;ua*=ya;Ba*=va;S-=B;E-=V;R-=B;$-=V;ta-=ja;oa-=la;ua-=ja;Ba-=la;va=1/(ta*Ba-ua*oa);ya=(Ba*S-oa*R)*va;oa=(Ba*E-oa*$)*va;S=(ta*R-ua*S)*va;E=(ta*$-ua*E)*va;B=B-ya*ja-S*la;V=V-oa*ja-E*la;o.save();o.transform(ya,oa,S,E,B,V);o.clip();o.drawImage(fa,0,0);o.restore()}function Ma(B,V,S,E){var R=~~(B.r*255),
+$=~~(B.g*255);B=~~(B.b*255);var fa=~~(V.r*255),ja=~~(V.g*255);V=~~(V.b*255);var la=~~(S.r*255),ta=~~(S.g*255);S=~~(S.b*255);var oa=~~(E.r*255),ua=~~(E.g*255);E=~~(E.b*255);ia[0]=R<0?0:R>255?255:R;ia[1]=$<0?0:$>255?255:$;ia[2]=B<0?0:B>255?255:B;ia[4]=fa<0?0:fa>255?255:fa;ia[5]=ja<0?0:ja>255?255:ja;ia[6]=V<0?0:V>255?255:V;ia[8]=la<0?0:la>255?255:la;ia[9]=ta<0?0:ta>255?255:ta;ia[10]=S<0?0:S>255?255:S;ia[12]=oa<0?0:oa>255?255:oa;ia[13]=ua<0?0:ua>255?255:ua;ia[14]=E<0?0:E>255?255:E;wa.putImageData(ha,
+0,0);pa.drawImage(ea,0,0);return sa}function Ia(B,V,S){B=(B-V)/(S-V);return B*B*(3-2*B)}function Ja(B){B=(B+1)*0.5;return B<0?0:B>1?1:B}function Ka(B,V){var S=V.x-B.x,E=V.y-B.y,R=1/Math.sqrt(S*S+E*E);S*=R;E*=R;V.x+=S;V.y+=E;B.x-=S;B.y-=E}var Fa,Na,ca,ra,za,La,Oa,Ca;this.autoClear?this.clear():o.setTransform(1,0,0,-1,r,m);d=g.projectScene(aa,ma,this.sortElements);o.fillStyle="rgba( 0, 255, 255, 0.5 )";o.fillRect(J.getX(),J.getY(),J.getWidth(),J.getHeight());(K=aa.lights.length>0)&&ka(aa);Fa=0;for(Na=
+d.length;Fa<Na;Fa++){ca=d[Fa];A.empty();if(ca instanceof THREE.RenderableParticle){s=ca;s.x*=r;s.y*=m;ra=0;for(za=ca.materials.length;ra<za;ra++)Ga(s,ca,ca.materials[ra],aa)}else if(ca instanceof THREE.RenderableLine){s=ca.v1;T=ca.v2;s.positionScreen.x*=r;s.positionScreen.y*=m;T.positionScreen.x*=r;T.positionScreen.y*=m;A.addPoint(s.positionScreen.x,s.positionScreen.y);A.addPoint(T.positionScreen.x,T.positionScreen.y);if(J.instersects(A)){ra=0;for(za=ca.materials.length;ra<za;)Ha(s,T,ca,ca.materials[ra++],
+aa)}}else if(ca instanceof THREE.RenderableFace3){s=ca.v1;T=ca.v2;F=ca.v3;s.positionScreen.x*=r;s.positionScreen.y*=m;T.positionScreen.x*=r;T.positionScreen.y*=m;F.positionScreen.x*=r;F.positionScreen.y*=m;if(ca.overdraw){Ka(s.positionScreen,T.positionScreen);Ka(T.positionScreen,F.positionScreen);Ka(F.positionScreen,s.positionScreen)}A.add3Points(s.positionScreen.x,s.positionScreen.y,T.positionScreen.x,T.positionScreen.y,F.positionScreen.x,F.positionScreen.y);if(J.instersects(A)){ra=0;for(za=ca.meshMaterials.length;ra<
+za;){Ca=ca.meshMaterials[ra++];if(Ca instanceof THREE.MeshFaceMaterial){La=0;for(Oa=ca.faceMaterials.length;La<Oa;)(Ca=ca.faceMaterials[La++])&&Da(s,T,F,ca,Ca,aa)}else Da(s,T,F,ca,Ca,aa)}}}P.addRectangle(A)}o.lineWidth=1;o.strokeStyle="rgba( 255, 0, 0, 0.5 )";o.strokeRect(P.getX(),P.getY(),P.getWidth(),P.getHeight());o.setTransform(1,0,0,1,0,0)}};
+THREE.SVGRenderer=function(){function a(G,D,U){var X,L,H,J;X=0;for(L=G.lights.length;X<L;X++){H=G.lights[X];if(H instanceof THREE.DirectionalLight){J=D.normalWorld.dot(H.position)*H.intensity;if(J>0){U.r+=H.color.r*J;U.g+=H.color.g*J;U.b+=H.color.b*J}}else if(H instanceof THREE.PointLight){n.sub(H.position,D.centroidWorld);n.normalize();J=D.normalWorld.dot(n)*H.intensity;if(J>0){U.r+=H.color.r*J;U.g+=H.color.g*J;U.b+=H.color.b*J}}}}function c(G,D,U,X,L,H){k=g(u++);k.setAttribute("d","M "+G.positionScreen.x+
+" "+G.positionScreen.y+" L "+D.positionScreen.x+" "+D.positionScreen.y+" L "+U.positionScreen.x+","+U.positionScreen.y+"z");if(L instanceof THREE.MeshBasicMaterial)F.__styleString=L.color.__styleString;else if(L instanceof THREE.MeshLambertMaterial)if(T){Q.r=f.r;Q.g=f.g;Q.b=f.b;a(H,X,Q);F.r=L.color.r*Q.r;F.g=L.color.g*Q.g;F.b=L.color.b*Q.b;F.updateStyleString()}else F.__styleString=L.color.__styleString;else if(L instanceof THREE.MeshDepthMaterial){e=1-L.__2near/(L.__farPlusNear-X.z*L.__farMinusNear);
+F.setRGB(e,e,e)}else L instanceof THREE.MeshNormalMaterial&&F.setRGB(i(X.normalWorld.x),i(X.normalWorld.y),i(X.normalWorld.z));L.wireframe?k.setAttribute("style","fill: none; stroke: "+F.__styleString+"; stroke-width: "+L.wireframe_linewidth+"; stroke-opacity: "+L.opacity+"; stroke-linecap: "+L.wireframe_linecap+"; stroke-linejoin: "+L.wireframe_linejoin):k.setAttribute("style","fill: "+F.__styleString+"; fill-opacity: "+L.opacity);r.appendChild(k)}function d(G,D,U,X,L,H,J){k=g(u++);k.setAttribute("d",
+"M "+G.positionScreen.x+" "+G.positionScreen.y+" L "+D.positionScreen.x+" "+D.positionScreen.y+" L "+U.positionScreen.x+","+U.positionScreen.y+" L "+X.positionScreen.x+","+X.positionScreen.y+"z");if(H instanceof THREE.MeshBasicMaterial)F.__styleString=H.color.__styleString;else if(H instanceof THREE.MeshLambertMaterial)if(T){Q.r=f.r;Q.g=f.g;Q.b=f.b;a(J,L,Q);F.r=H.color.r*Q.r;F.g=H.color.g*Q.g;F.b=H.color.b*Q.b;F.updateStyleString()}else F.__styleString=H.color.__styleString;else if(H instanceof THREE.MeshDepthMaterial){e=
+1-H.__2near/(H.__farPlusNear-L.z*H.__farMinusNear);F.setRGB(e,e,e)}else H instanceof THREE.MeshNormalMaterial&&F.setRGB(i(L.normalWorld.x),i(L.normalWorld.y),i(L.normalWorld.z));H.wireframe?k.setAttribute("style","fill: none; stroke: "+F.__styleString+"; stroke-width: "+H.wireframe_linewidth+"; stroke-opacity: "+H.opacity+"; stroke-linecap: "+H.wireframe_linecap+"; stroke-linejoin: "+H.wireframe_linejoin):k.setAttribute("style","fill: "+F.__styleString+"; fill-opacity: "+H.opacity);r.appendChild(k)}
+function g(G){if(j[G]==null){j[G]=document.createElementNS("http://www.w3.org/2000/svg","path");O==0&&j[G].setAttribute("shape-rendering","crispEdges");return j[G]}return j[G]}function i(G){return G<0?Math.min((1+G)*0.5,0.5):0.5+Math.min(G*0.5,0.5)}var l=null,b=new THREE.Projector,r=document.createElementNS("http://www.w3.org/2000/svg","svg"),m,o,z,y,w,x,I,N,M=new THREE.Rectangle,s=new THREE.Rectangle,T=false,F=new THREE.Color(16777215),Q=new THREE.Color(16777215),f=new THREE.Color(0),p=new THREE.Color(0),
+h=new THREE.Color(0),e,n=new THREE.Vector3,j=[],t=[],q=[],k,u,C,v,O=1;this.domElement=r;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(G){switch(G){case "high":O=1;break;case "low":O=0}};this.setSize=function(G,D){m=G;o=D;z=m/2;y=o/2;r.setAttribute("viewBox",-z+" "+-y+" "+m+" "+o);r.setAttribute("width",m);r.setAttribute("height",o);M.set(-z,-y,z,y)};this.clear=function(){for(;r.childNodes.length>0;)r.removeChild(r.childNodes[0])};this.render=function(G,D){var U,X,
+L,H,J,P,A,K;this.autoClear&&this.clear();l=b.projectScene(G,D,this.sortElements);v=C=u=0;if(T=G.lights.length>0){A=G.lights;f.setRGB(0,0,0);p.setRGB(0,0,0);h.setRGB(0,0,0);U=0;for(X=A.length;U<X;U++){L=A[U];H=L.color;if(L instanceof THREE.AmbientLight){f.r+=H.r;f.g+=H.g;f.b+=H.b}else if(L instanceof THREE.DirectionalLight){p.r+=H.r;p.g+=H.g;p.b+=H.b}else if(L instanceof THREE.PointLight){h.r+=H.r;h.g+=H.g;h.b+=H.b}}}U=0;for(X=l.length;U<X;U++){A=l[U];s.empty();if(A instanceof THREE.RenderableParticle){w=
+A;w.x*=z;w.y*=-y;L=0;for(H=A.materials.length;L<H;L++)if(K=A.materials[L]){J=w;P=A;K=K;var W=C++;if(t[W]==null){t[W]=document.createElementNS("http://www.w3.org/2000/svg","circle");O==0&&t[W].setAttribute("shape-rendering","crispEdges")}k=t[W];k.setAttribute("cx",J.x);k.setAttribute("cy",J.y);k.setAttribute("r",P.scale.x*z);if(K instanceof THREE.ParticleCircleMaterial){if(T){Q.r=f.r+p.r+h.r;Q.g=f.g+p.g+h.g;Q.b=f.b+p.b+h.b;F.r=K.color.r*Q.r;F.g=K.color.g*Q.g;F.b=K.color.b*Q.b;F.updateStyleString()}else F=
+K.color;k.setAttribute("style","fill: "+F.__styleString)}r.appendChild(k)}}else if(A instanceof THREE.RenderableLine){w=A.v1;x=A.v2;w.positionScreen.x*=z;w.positionScreen.y*=-y;x.positionScreen.x*=z;x.positionScreen.y*=-y;s.addPoint(w.positionScreen.x,w.positionScreen.y);s.addPoint(x.positionScreen.x,x.positionScreen.y);if(M.instersects(s)){L=0;for(H=A.materials.length;L<H;)if(K=A.materials[L++]){J=w;P=x;K=K;W=v++;if(q[W]==null){q[W]=document.createElementNS("http://www.w3.org/2000/svg","line");O==
+0&&q[W].setAttribute("shape-rendering","crispEdges")}k=q[W];k.setAttribute("x1",J.positionScreen.x);k.setAttribute("y1",J.positionScreen.y);k.setAttribute("x2",P.positionScreen.x);k.setAttribute("y2",P.positionScreen.y);if(K instanceof THREE.LineBasicMaterial){F.__styleString=K.color.__styleString;k.setAttribute("style","fill: none; stroke: "+F.__styleString+"; stroke-width: "+K.linewidth+"; stroke-opacity: "+K.opacity+"; stroke-linecap: "+K.linecap+"; stroke-linejoin: "+K.linejoin);r.appendChild(k)}}}}else if(A instanceof
+THREE.RenderableFace3){w=A.v1;x=A.v2;I=A.v3;w.positionScreen.x*=z;w.positionScreen.y*=-y;x.positionScreen.x*=z;x.positionScreen.y*=-y;I.positionScreen.x*=z;I.positionScreen.y*=-y;s.addPoint(w.positionScreen.x,w.positionScreen.y);s.addPoint(x.positionScreen.x,x.positionScreen.y);s.addPoint(I.positionScreen.x,I.positionScreen.y);if(M.instersects(s)){L=0;for(H=A.meshMaterials.length;L<H;){K=A.meshMaterials[L++];if(K instanceof THREE.MeshFaceMaterial){J=0;for(P=A.faceMaterials.length;J<P;)(K=A.faceMaterials[J++])&&
+c(w,x,I,A,K,G)}else K&&c(w,x,I,A,K,G)}}}else if(A instanceof THREE.RenderableFace4){w=A.v1;x=A.v2;I=A.v3;N=A.v4;w.positionScreen.x*=z;w.positionScreen.y*=-y;x.positionScreen.x*=z;x.positionScreen.y*=-y;I.positionScreen.x*=z;I.positionScreen.y*=-y;N.positionScreen.x*=z;N.positionScreen.y*=-y;s.addPoint(w.positionScreen.x,w.positionScreen.y);s.addPoint(x.positionScreen.x,x.positionScreen.y);s.addPoint(I.positionScreen.x,I.positionScreen.y);s.addPoint(N.positionScreen.x,N.positionScreen.y);if(M.instersects(s)){L=
+0;for(H=A.meshMaterials.length;L<H;){K=A.meshMaterials[L++];if(K instanceof THREE.MeshFaceMaterial){J=0;for(P=A.faceMaterials.length;J<P;)(K=A.faceMaterials[J++])&&d(w,x,I,N,A,K,G)}else K&&d(w,x,I,N,A,K,G)}}}}}};
 THREE.WebGLRenderer=function(a){function c(f,p){f.fragment_shader=p.fragment_shader;f.vertex_shader=p.vertex_shader;f.uniforms=Uniforms.clone(p.uniforms)}function d(f){if(f.doubleSided)b.disable(b.CULL_FACE);else{b.enable(b.CULL_FACE);f.flipSided?b.frontFace(b.CW):b.frontFace(b.CCW)}}function g(f,p){var h;if(f=="fragment")h=b.createShader(b.FRAGMENT_SHADER);else if(f=="vertex")h=b.createShader(b.VERTEX_SHADER);b.shaderSource(h,p);b.compileShader(h);if(!b.getShaderParameter(h,b.COMPILE_STATUS)){alert(b.getShaderInfoLog(h));
 return null}return h}function i(f){switch(f){case THREE.RepeatWrapping:return b.REPEAT;case THREE.ClampToEdgeWrapping:return b.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return b.MIRRORED_REPEAT;case THREE.NearestFilter:return b.NEAREST;case THREE.NearestMipMapNearestFilter:return b.NEAREST_MIPMAP_NEAREST;case THREE.NearestMipMapLinearFilter:return b.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return b.LINEAR;case THREE.LinearMipMapNearestFilter:return b.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return b.LINEAR_MIPMAP_LINEAR;
 case THREE.ByteType:return b.BYTE;case THREE.UnsignedByteType:return b.UNSIGNED_BYTE;case THREE.ShortType:return b.SHORT;case THREE.UnsignedShortType:return b.UNSIGNED_SHORT;case THREE.IntType:return b.INT;case THREE.UnsignedShortType:return b.UNSIGNED_INT;case THREE.FloatType:return b.FLOAT;case THREE.AlphaFormat:return b.ALPHA;case THREE.RGBFormat:return b.RGB;case THREE.RGBAFormat:return b.RGBA;case THREE.LuminanceFormat:return b.LUMINANCE;case THREE.LuminanceAlphaFormat:return b.LUMINANCE_ALPHA}return 0}
-var l=document.createElement("canvas"),b,r=null,m=null,n=new THREE.Matrix4,z,y=new Float32Array(16),w=new Float32Array(16),x=new Float32Array(16),I=new Float32Array(9),N=new Float32Array(16),M=new THREE.Matrix4,s=new THREE.Vector4,T=true,F=new THREE.Color(0),Q=0;if(a){if(a.antialias!==undefined)T=a.antialias;a.clearColor!==undefined&&F.setHex(a.clearColor);if(a.clearAlpha!==undefined)Q=a.clearAlpha}this.domElement=l;this.autoClear=true;(function(f,p,h){try{b=l.getContext("experimental-webgl",{antialias:f})}catch(e){console.log(e)}if(!b){alert("WebGL not supported");
+var l=document.createElement("canvas"),b,r=null,m=null,o=new THREE.Matrix4,z,y=new Float32Array(16),w=new Float32Array(16),x=new Float32Array(16),I=new Float32Array(9),N=new Float32Array(16),M=new THREE.Matrix4,s=new THREE.Vector4,T=true,F=new THREE.Color(0),Q=0;if(a){if(a.antialias!==undefined)T=a.antialias;a.clearColor!==undefined&&F.setHex(a.clearColor);if(a.clearAlpha!==undefined)Q=a.clearAlpha}this.domElement=l;this.autoClear=true;(function(f,p,h){try{b=l.getContext("experimental-webgl",{antialias:f})}catch(e){console.log(e)}if(!b){alert("WebGL not supported");
 throw"cannot create webgl context";}b.clearColor(0,0,0,1);b.clearDepth(1);b.enable(b.DEPTH_TEST);b.depthFunc(b.LEQUAL);b.frontFace(b.CCW);b.cullFace(b.BACK);b.enable(b.CULL_FACE);b.enable(b.BLEND);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA);b.clearColor(p.r,p.g,p.b,h)})(T,F,Q);this.context=b;this.lights={ambient:[0,0,0],directional:{length:0,colors:[],positions:[]},point:{length:0,colors:[],positions:[]}};this.setSize=function(f,p){l.width=f;l.height=p;b.viewport(0,0,l.width,l.height)};this.setClearColorHex=
-function(f,p){var h=new THREE.Color(f);b.clearColor(h.r,h.g,h.b,p)};this.setClearColor=function(f,p){b.clearColor(f.r,f.g,f.b,p)};this.clear=function(){b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT)};this.setupLights=function(f,p){var h,e,o,j=0,t=0,q=0,k,u,C,v=this.lights,O=v.directional.colors,G=v.directional.positions,D=v.point.colors,V=v.point.positions,U=0,J=0;h=0;for(e=p.length;h<e;h++){o=p[h];k=o.color;u=o.position;C=o.intensity;if(o instanceof THREE.AmbientLight){j+=k.r;t+=k.g;q+=k.b}else if(o instanceof
-THREE.DirectionalLight){O[U*3]=k.r*C;O[U*3+1]=k.g*C;O[U*3+2]=k.b*C;G[U*3]=u.x;G[U*3+1]=u.y;G[U*3+2]=u.z;U+=1}else if(o instanceof THREE.PointLight){D[J*3]=k.r*C;D[J*3+1]=k.g*C;D[J*3+2]=k.b*C;V[J*3]=u.x;V[J*3+1]=u.y;V[J*3+2]=u.z;J+=1}}v.point.length=J;v.directional.length=U;v.ambient[0]=j;v.ambient[1]=t;v.ambient[2]=q};this.createParticleBuffers=function(f){f.__webGLVertexBuffer=b.createBuffer();f.__webGLColorBuffer=b.createBuffer();f.__webGLParticleBuffer=b.createBuffer()};this.createLineBuffers=
-function(f){f.__webGLVertexBuffer=b.createBuffer();f.__webGLColorBuffer=b.createBuffer();f.__webGLLineBuffer=b.createBuffer()};this.createMeshBuffers=function(f){f.__webGLVertexBuffer=b.createBuffer();f.__webGLNormalBuffer=b.createBuffer();f.__webGLTangentBuffer=b.createBuffer();f.__webGLColorBuffer=b.createBuffer();f.__webGLUVBuffer=b.createBuffer();f.__webGLUV2Buffer=b.createBuffer();f.__webGLFaceBuffer=b.createBuffer();f.__webGLLineBuffer=b.createBuffer()};this.initLineBuffers=function(f){var p=
-f.vertices.length;f.__vertexArray=new Float32Array(p*3);f.__colorArray=new Float32Array(p*3);f.__lineArray=new Uint16Array(p);f.__webGLLineCount=p};this.initParticleBuffers=function(f){var p=f.vertices.length;f.__vertexArray=new Float32Array(p*3);f.__colorArray=new Float32Array(p*3);f.__particleArray=new Uint16Array(p);f.__sortArray=[];f.__webGLParticleCount=p};this.initMeshBuffers=function(f,p){var h,e,o=0,j=0,t=0,q=p.geometry.faces,k=f.faces;h=0;for(e=k.length;h<e;h++){fi=k[h];face=q[fi];if(face instanceof
-THREE.Face3){o+=3;j+=1;t+=3}else if(face instanceof THREE.Face4){o+=4;j+=2;t+=4}}f.__vertexArray=new Float32Array(o*3);f.__normalArray=new Float32Array(o*3);f.__tangentArray=new Float32Array(o*4);f.__colorArray=new Float32Array(o*3);f.__uvArray=new Float32Array(o*2);f.__uv2Array=new Float32Array(o*2);f.__faceArray=new Uint16Array(j*3);f.__lineArray=new Uint16Array(t*2);o=false;h=0;for(e=p.materials.length;h<e;h++){q=p.materials[h];if(q instanceof THREE.MeshFaceMaterial){q=0;for(k=f.materials.length;q<
-k;q++)if(f.materials[q]&&f.materials[q].shading!=undefined&&f.materials[q].shading==THREE.SmoothShading){o=true;break}}else if(q&&q.shading!=undefined&&q.shading==THREE.SmoothShading){o=true;break}if(o)break}f.__needsSmoothNormals=o;f.__webGLFaceCount=j*3;f.__webGLLineCount=t*2};this.setMeshBuffers=function(f,p,h){var e,o,j,t,q,k,u,C,v,O,G=0,D=0,V=0,U=0,J=0,H=0,K=0,P=0,A=0,L=f.__vertexArray,X=f.__uvArray,ga=f.__uv2Array,da=f.__normalArray,Y=f.__tangentArray,ba=f.__colorArray,Z=f.__faceArray,ea=f.__lineArray,
-wa=f.__needsSmoothNormals,ha=p.geometry,ia=ha.__dirtyVertices,sa=ha.__dirtyElements,pa=ha.__dirtyUvs,qa=ha.__dirtyNormals,aa=ha.__dirtyTangents,ma=ha.__dirtyColors,ka=ha.vertices,xa=f.faces,Ga=ha.faces,Ha=ha.uvs,Da=ha.uvs2,na=ha.colors;p=0;for(e=xa.length;p<e;p++){o=xa[p];j=Ga[o];k=Ha[o];o=Da[o];t=j.vertexNormals;q=j.normal;if(j instanceof THREE.Face3){if(ia){u=ka[j.a].position;C=ka[j.b].position;v=ka[j.c].position;L[D]=u.x;L[D+1]=u.y;L[D+2]=u.z;L[D+3]=C.x;L[D+4]=C.y;L[D+5]=C.z;L[D+6]=v.x;L[D+7]=
-v.y;L[D+8]=v.z;D+=9}if(ma&&na.length){u=na[j.a];C=na[j.b];v=na[j.c];ba[A]=u.r;ba[A+1]=u.g;ba[A+2]=u.b;ba[A+3]=C.r;ba[A+4]=C.g;ba[A+5]=C.b;ba[A+6]=v.r;ba[A+7]=v.g;ba[A+8]=v.b;A+=9}if(aa&&ha.hasTangents){u=ka[j.a].tangent;C=ka[j.b].tangent;v=ka[j.c].tangent;Y[K]=u.x;Y[K+1]=u.y;Y[K+2]=u.z;Y[K+3]=u.w;Y[K+4]=C.x;Y[K+5]=C.y;Y[K+6]=C.z;Y[K+7]=C.w;Y[K+8]=v.x;Y[K+9]=v.y;Y[K+10]=v.z;Y[K+11]=v.w;K+=12}if(qa)if(t.length==3&&wa)for(j=0;j<3;j++){q=t[j];da[H]=q.x;da[H+1]=q.y;da[H+2]=q.z;H+=3}else for(j=0;j<3;j++){da[H]=
-q.x;da[H+1]=q.y;da[H+2]=q.z;H+=3}if(pa&&k)for(j=0;j<3;j++){t=k[j];X[V]=t.u;X[V+1]=t.v;V+=2}if(pa&&o)for(j=0;j<3;j++){k=o[j];ga[U]=k.u;ga[U+1]=k.v;U+=2}if(sa){Z[J]=G;Z[J+1]=G+1;Z[J+2]=G+2;J+=3;ea[P]=G;ea[P+1]=G+1;ea[P+2]=G;ea[P+3]=G+2;ea[P+4]=G+1;ea[P+5]=G+2;P+=6;G+=3}}else if(j instanceof THREE.Face4){if(ia){u=ka[j.a].position;C=ka[j.b].position;v=ka[j.c].position;O=ka[j.d].position;L[D]=u.x;L[D+1]=u.y;L[D+2]=u.z;L[D+3]=C.x;L[D+4]=C.y;L[D+5]=C.z;L[D+6]=v.x;L[D+7]=v.y;L[D+8]=v.z;L[D+9]=O.x;L[D+10]=
-O.y;L[D+11]=O.z;D+=12}if(ma&&na.length){u=na[j.a];C=na[j.b];v=na[j.d];ba[A]=u.r;ba[A+1]=u.g;ba[A+2]=u.b;ba[A+3]=C.r;ba[A+4]=C.g;ba[A+5]=C.b;ba[A+6]=v.r;ba[A+7]=v.g;ba[A+8]=v.b;ba[A+9]=(void 0).r;ba[A+10]=(void 0).g;ba[A+11]=(void 0).b;A+=12}if(aa&&ha.hasTangents){u=ka[j.a].tangent;C=ka[j.b].tangent;v=ka[j.c].tangent;j=ka[j.d].tangent;Y[K]=u.x;Y[K+1]=u.y;Y[K+2]=u.z;Y[K+3]=u.w;Y[K+4]=C.x;Y[K+5]=C.y;Y[K+6]=C.z;Y[K+7]=C.w;Y[K+8]=v.x;Y[K+9]=v.y;Y[K+10]=v.z;Y[K+11]=v.w;Y[K+12]=j.x;Y[K+13]=j.y;Y[K+14]=j.z;
-Y[K+15]=j.w;K+=16}if(qa)if(t.length==4&&wa)for(j=0;j<4;j++){q=t[j];da[H]=q.x;da[H+1]=q.y;da[H+2]=q.z;H+=3}else for(j=0;j<4;j++){da[H]=q.x;da[H+1]=q.y;da[H+2]=q.z;H+=3}if(pa&&k)for(j=0;j<4;j++){t=k[j];X[V]=t.u;X[V+1]=t.v;V+=2}if(pa&&o)for(j=0;j<4;j++){k=o[j];ga[U]=k.u;ga[U+1]=k.v;U+=2}if(sa){Z[J]=G;Z[J+1]=G+1;Z[J+2]=G+2;Z[J+3]=G;Z[J+4]=G+2;Z[J+5]=G+3;J+=6;ea[P]=G;ea[P+1]=G+1;ea[P+2]=G;ea[P+3]=G+3;ea[P+4]=G+1;ea[P+5]=G+2;ea[P+6]=G+2;ea[P+7]=G+3;P+=8;G+=4}}}if(ia){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLVertexBuffer);
-b.bufferData(b.ARRAY_BUFFER,L,h)}if(ma&&na.length){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLColorBuffer);b.bufferData(b.ARRAY_BUFFER,ba,h)}if(qa){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,da,h)}if(aa&&ha.hasTangents){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLTangentBuffer);b.bufferData(b.ARRAY_BUFFER,Y,h)}if(pa&&V>0){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLUVBuffer);b.bufferData(b.ARRAY_BUFFER,X,h)}if(pa&&U>0){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLUV2Buffer);b.bufferData(b.ARRAY_BUFFER,
-ga,h)}if(sa){b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,f.__webGLFaceBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,Z,h);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,f.__webGLLineBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,ea,h)}};this.setLineBuffers=function(f,p){var h,e,o,j=f.vertices,t=f.colors,q=j.length,k=t.length,u=f.__vertexArray,C=f.__colorArray,v=f.__lineArray,O=f.__dirtyColors,G=f.__dirtyElements;if(f.__dirtyVertices){for(h=0;h<q;h++){e=j[h].position;o=h*3;u[o]=e.x;u[o+1]=e.y;u[o+2]=e.z}b.bindBuffer(b.ARRAY_BUFFER,
-f.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,u,p)}if(O){for(h=0;h<k;h++){color=t[h];o=h*3;C[o]=color.r;C[o+1]=color.g;C[o+2]=color.b}b.bindBuffer(b.ARRAY_BUFFER,f.__webGLColorBuffer);b.bufferData(b.ARRAY_BUFFER,C,p)}if(G){for(h=0;h<q;h++)v[h]=h;b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,f.__webGLLineBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,v,p)}};this.setParticleBuffers=function(f,p,h,e){var o,j,t;j=f.vertices;var q=j.length,k=f.colors,u=k.length,C=f.__vertexArray,v=f.__particleArray,O=f.__colorArray,
-G=f.__sortArray,D=f.__dirtyVertices,V=f.__dirtyElements,U=f.__dirtyColors;if(h.sortParticles){M.multiply(e.projectionMatrix,e.matrix);M.multiplySelf(h.matrix);for(o=0;o<q;o++){t=j[o].position;s.copy(t);M.multiplyVector3(s);G[o]=[s.z,o]}G.sort(function(J,H){return H[0]-J[0]});for(o=0;o<q;o++){t=j[G[o][1]].position;e=o*3;C[e]=t.x;C[e+1]=t.y;C[e+2]=t.z}for(j=0;j<u;j++){e=j*3;color=k[G[j][1]];O[e]=color.r;O[e+1]=color.g;O[e+2]=color.b}}else{if(D)for(o=0;o<q;o++){t=j[o].position;e=o*3;C[e]=t.x;C[e+1]=
-t.y;C[e+2]=t.z}if(U)for(j=0;j<u;j++){color=k[j];e=j*3;O[e]=color.r;O[e+1]=color.g;O[e+2]=color.b}}if(V){for(o=0;o<q;o++)v[o]=o;b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,f.__webGLParticleBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,v,p)}if(D||h.sortParticles){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,C,p)}if(U||h.sortParticles){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLColorBuffer);b.bufferData(b.ARRAY_BUFFER,O,p)}};this.initMaterial=function(f,p,h){if(!f.program){var e,o;
-if(f instanceof THREE.MeshDepthMaterial)c(f,THREE.ShaderLib.depth);else if(f instanceof THREE.MeshNormalMaterial)c(f,THREE.ShaderLib.normal);else if(f instanceof THREE.MeshBasicMaterial)c(f,THREE.ShaderLib.basic);else if(f instanceof THREE.MeshLambertMaterial)c(f,THREE.ShaderLib.lambert);else if(f instanceof THREE.MeshPhongMaterial)c(f,THREE.ShaderLib.phong);else if(f instanceof THREE.LineBasicMaterial)c(f,THREE.ShaderLib.basic);else f instanceof THREE.ParticleBasicMaterial&&c(f,THREE.ShaderLib.particle_basic);
-var j,t,q,k;o=q=k=0;for(j=p.length;o<j;o++){t=p[o];t instanceof THREE.DirectionalLight&&q++;t instanceof THREE.PointLight&&k++}if(k+q<=4){p=q;k=k}else{p=Math.ceil(4*q/(k+q));k=4-p}o={directional:p,point:k};k=f.fragment_shader;p=f.vertex_shader;j={fog:h,map:f.map,env_map:f.env_map,light_map:f.light_map,vertex_colors:f.vertex_colors,maxDirLights:o.directional,maxPointLights:o.point};h=b.createProgram();o=["#ifdef GL_ES\nprecision highp float;\n#endif","#define MAX_DIR_LIGHTS "+j.maxDirLights,"#define MAX_POINT_LIGHTS "+
-j.maxPointLights,j.fog?"#define USE_FOG":"",j.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",j.map?"#define USE_MAP":"",j.env_map?"#define USE_ENVMAP":"",j.light_map?"#define USE_LIGHTMAP":"",j.vertex_colors?"#define USE_COLOR":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");j=[b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+j.maxDirLights,"#define MAX_POINT_LIGHTS "+j.maxPointLights,j.map?"#define USE_MAP":"",
-j.env_map?"#define USE_ENVMAP":"",j.light_map?"#define USE_LIGHTMAP":"",j.vertex_colors?"#define USE_COLOR":"","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 vec3 color;\nattribute vec2 uv;\nattribute vec2 uv2;\n"].join("\n");b.attachShader(h,g("fragment",o+k));b.attachShader(h,g("vertex",j+p));b.linkProgram(h);
-b.getProgramParameter(h,b.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+b.getProgramParameter(h,b.VALIDATE_STATUS)+", gl error ["+b.getError()+"]");h.uniforms={};h.attributes={};f.program=h;h=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(e in f.uniforms)h.push(e);e=f.program;k=0;for(p=h.length;k<p;k++){o=h[k];e.uniforms[o]=b.getUniformLocation(e,o)}f=f.program;e=["position","normal","uv","uv2","tangent","color"];h=0;
-for(k=e.length;h<k;h++){p=e[h];f.attributes[p]=b.getAttribLocation(f,p)}}};this.setProgram=function(f,p,h,e){this.initMaterial(e,p,h);var o=e.program;if(o!=r){b.useProgram(o);r=o}this.loadCamera(o,f);this.loadMatrices(o);if(e instanceof THREE.MeshPhongMaterial||e instanceof THREE.MeshLambertMaterial){this.setupLights(o,p);p=this.lights;e.uniforms.enableLighting.value=p.directional.length+p.point.length;e.uniforms.ambientLightColor.value=p.ambient;e.uniforms.directionalLightColor.value=p.directional.colors;
-e.uniforms.directionalLightDirection.value=p.directional.positions;e.uniforms.pointLightColor.value=p.point.colors;e.uniforms.pointLightPosition.value=p.point.positions}if(e instanceof THREE.MeshBasicMaterial||e instanceof THREE.MeshLambertMaterial||e instanceof THREE.MeshPhongMaterial){e.uniforms.diffuse.value.setRGB(e.color.r*e.opacity,e.color.g*e.opacity,e.color.b*e.opacity);e.uniforms.opacity.value=e.opacity;e.uniforms.map.texture=e.map;e.uniforms.light_map.texture=e.light_map;e.uniforms.env_map.texture=
-e.env_map;e.uniforms.reflectivity.value=e.reflectivity;e.uniforms.refraction_ratio.value=e.refraction_ratio;e.uniforms.combine.value=e.combine;e.uniforms.useRefract.value=e.env_map&&e.env_map.mapping instanceof THREE.CubeRefractionMapping;if(h){e.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){e.uniforms.fogNear.value=h.near;e.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)e.uniforms.fogDensity.value=h.density}}if(e instanceof THREE.LineBasicMaterial){e.uniforms.diffuse.value.setRGB(e.color.r*
+function(f,p){var h=new THREE.Color(f);b.clearColor(h.r,h.g,h.b,p)};this.setClearColor=function(f,p){b.clearColor(f.r,f.g,f.b,p)};this.clear=function(){b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT)};this.setupLights=function(f,p){var h,e,n,j=0,t=0,q=0,k,u,C,v=this.lights,O=v.directional.colors,G=v.directional.positions,D=v.point.colors,U=v.point.positions,X=0,L=0;h=n=n=0;for(e=p.length;h<e;h++){n=p[h];k=n.color;u=n.position;C=n.intensity;if(n instanceof THREE.AmbientLight){j+=k.r;t+=k.g;q+=k.b}else if(n instanceof
+THREE.DirectionalLight){n=X*3;O[n]=k.r*C;O[n+1]=k.g*C;O[n+2]=k.b*C;G[n]=u.x;G[n+1]=u.y;G[n+2]=u.z;X+=1}else if(n instanceof THREE.PointLight){n=L*3;D[n]=k.r*C;D[n+1]=k.g*C;D[n+2]=k.b*C;U[n]=u.x;U[n+1]=u.y;U[n+2]=u.z;L+=1}}for(h=X*3;h<O.length;h++)O[h]=0;for(h=L*3;h<D.length;h++)D[h]=0;v.point.length=L;v.directional.length=X;v.ambient[0]=j;v.ambient[1]=t;v.ambient[2]=q};this.createParticleBuffers=function(f){f.__webGLVertexBuffer=b.createBuffer();f.__webGLColorBuffer=b.createBuffer();f.__webGLParticleBuffer=
+b.createBuffer()};this.createLineBuffers=function(f){f.__webGLVertexBuffer=b.createBuffer();f.__webGLColorBuffer=b.createBuffer();f.__webGLLineBuffer=b.createBuffer()};this.createMeshBuffers=function(f){f.__webGLVertexBuffer=b.createBuffer();f.__webGLNormalBuffer=b.createBuffer();f.__webGLTangentBuffer=b.createBuffer();f.__webGLColorBuffer=b.createBuffer();f.__webGLUVBuffer=b.createBuffer();f.__webGLUV2Buffer=b.createBuffer();f.__webGLFaceBuffer=b.createBuffer();f.__webGLLineBuffer=b.createBuffer()};
+this.initLineBuffers=function(f){var p=f.vertices.length;f.__vertexArray=new Float32Array(p*3);f.__colorArray=new Float32Array(p*3);f.__lineArray=new Uint16Array(p);f.__webGLLineCount=p};this.initParticleBuffers=function(f){var p=f.vertices.length;f.__vertexArray=new Float32Array(p*3);f.__colorArray=new Float32Array(p*3);f.__particleArray=new Uint16Array(p);f.__sortArray=[];f.__webGLParticleCount=p};this.initMeshBuffers=function(f,p){var h,e,n=0,j=0,t=0,q=p.geometry.faces,k=f.faces;h=0;for(e=k.length;h<
+e;h++){fi=k[h];face=q[fi];if(face instanceof THREE.Face3){n+=3;j+=1;t+=3}else if(face instanceof THREE.Face4){n+=4;j+=2;t+=4}}f.__vertexArray=new Float32Array(n*3);f.__normalArray=new Float32Array(n*3);f.__tangentArray=new Float32Array(n*4);f.__colorArray=new Float32Array(n*3);f.__uvArray=new Float32Array(n*2);f.__uv2Array=new Float32Array(n*2);f.__faceArray=new Uint16Array(j*3);f.__lineArray=new Uint16Array(t*2);n=false;h=0;for(e=p.materials.length;h<e;h++){q=p.materials[h];if(q instanceof THREE.MeshFaceMaterial){q=
+0;for(k=f.materials.length;q<k;q++)if(f.materials[q]&&f.materials[q].shading!=undefined&&f.materials[q].shading==THREE.SmoothShading){n=true;break}}else if(q&&q.shading!=undefined&&q.shading==THREE.SmoothShading){n=true;break}if(n)break}f.__needsSmoothNormals=n;f.__webGLFaceCount=j*3;f.__webGLLineCount=t*2};this.setMeshBuffers=function(f,p,h){var e,n,j,t,q,k,u,C,v,O,G=0,D=0,U=0,X=0,L=0,H=0,J=0,P=0,A=0,K=f.__vertexArray,W=f.__uvArray,ga=f.__uv2Array,da=f.__normalArray,Y=f.__tangentArray,ba=f.__colorArray,
+Z=f.__faceArray,ea=f.__lineArray,wa=f.__needsSmoothNormals,ha=p.geometry,ia=ha.__dirtyVertices,sa=ha.__dirtyElements,pa=ha.__dirtyUvs,qa=ha.__dirtyNormals,aa=ha.__dirtyTangents,ma=ha.__dirtyColors,ka=ha.vertices,xa=f.faces,Ga=ha.faces,Ha=ha.uvs,Da=ha.uvs2,na=ha.colors;p=0;for(e=xa.length;p<e;p++){n=xa[p];j=Ga[n];k=Ha[n];n=Da[n];t=j.vertexNormals;q=j.normal;if(j instanceof THREE.Face3){if(ia){u=ka[j.a].position;C=ka[j.b].position;v=ka[j.c].position;K[D]=u.x;K[D+1]=u.y;K[D+2]=u.z;K[D+3]=C.x;K[D+4]=
+C.y;K[D+5]=C.z;K[D+6]=v.x;K[D+7]=v.y;K[D+8]=v.z;D+=9}if(ma&&na.length){u=na[j.a];C=na[j.b];v=na[j.c];ba[A]=u.r;ba[A+1]=u.g;ba[A+2]=u.b;ba[A+3]=C.r;ba[A+4]=C.g;ba[A+5]=C.b;ba[A+6]=v.r;ba[A+7]=v.g;ba[A+8]=v.b;A+=9}if(aa&&ha.hasTangents){u=ka[j.a].tangent;C=ka[j.b].tangent;v=ka[j.c].tangent;Y[J]=u.x;Y[J+1]=u.y;Y[J+2]=u.z;Y[J+3]=u.w;Y[J+4]=C.x;Y[J+5]=C.y;Y[J+6]=C.z;Y[J+7]=C.w;Y[J+8]=v.x;Y[J+9]=v.y;Y[J+10]=v.z;Y[J+11]=v.w;J+=12}if(qa)if(t.length==3&&wa)for(j=0;j<3;j++){q=t[j];da[H]=q.x;da[H+1]=q.y;da[H+
+2]=q.z;H+=3}else for(j=0;j<3;j++){da[H]=q.x;da[H+1]=q.y;da[H+2]=q.z;H+=3}if(pa&&k)for(j=0;j<3;j++){t=k[j];W[U]=t.u;W[U+1]=t.v;U+=2}if(pa&&n)for(j=0;j<3;j++){k=n[j];ga[X]=k.u;ga[X+1]=k.v;X+=2}if(sa){Z[L]=G;Z[L+1]=G+1;Z[L+2]=G+2;L+=3;ea[P]=G;ea[P+1]=G+1;ea[P+2]=G;ea[P+3]=G+2;ea[P+4]=G+1;ea[P+5]=G+2;P+=6;G+=3}}else if(j instanceof THREE.Face4){if(ia){u=ka[j.a].position;C=ka[j.b].position;v=ka[j.c].position;O=ka[j.d].position;K[D]=u.x;K[D+1]=u.y;K[D+2]=u.z;K[D+3]=C.x;K[D+4]=C.y;K[D+5]=C.z;K[D+6]=v.x;
+K[D+7]=v.y;K[D+8]=v.z;K[D+9]=O.x;K[D+10]=O.y;K[D+11]=O.z;D+=12}if(ma&&na.length){u=na[j.a];C=na[j.b];v=na[j.d];ba[A]=u.r;ba[A+1]=u.g;ba[A+2]=u.b;ba[A+3]=C.r;ba[A+4]=C.g;ba[A+5]=C.b;ba[A+6]=v.r;ba[A+7]=v.g;ba[A+8]=v.b;ba[A+9]=(void 0).r;ba[A+10]=(void 0).g;ba[A+11]=(void 0).b;A+=12}if(aa&&ha.hasTangents){u=ka[j.a].tangent;C=ka[j.b].tangent;v=ka[j.c].tangent;j=ka[j.d].tangent;Y[J]=u.x;Y[J+1]=u.y;Y[J+2]=u.z;Y[J+3]=u.w;Y[J+4]=C.x;Y[J+5]=C.y;Y[J+6]=C.z;Y[J+7]=C.w;Y[J+8]=v.x;Y[J+9]=v.y;Y[J+10]=v.z;Y[J+
+11]=v.w;Y[J+12]=j.x;Y[J+13]=j.y;Y[J+14]=j.z;Y[J+15]=j.w;J+=16}if(qa)if(t.length==4&&wa)for(j=0;j<4;j++){q=t[j];da[H]=q.x;da[H+1]=q.y;da[H+2]=q.z;H+=3}else for(j=0;j<4;j++){da[H]=q.x;da[H+1]=q.y;da[H+2]=q.z;H+=3}if(pa&&k)for(j=0;j<4;j++){t=k[j];W[U]=t.u;W[U+1]=t.v;U+=2}if(pa&&n)for(j=0;j<4;j++){k=n[j];ga[X]=k.u;ga[X+1]=k.v;X+=2}if(sa){Z[L]=G;Z[L+1]=G+1;Z[L+2]=G+2;Z[L+3]=G;Z[L+4]=G+2;Z[L+5]=G+3;L+=6;ea[P]=G;ea[P+1]=G+1;ea[P+2]=G;ea[P+3]=G+3;ea[P+4]=G+1;ea[P+5]=G+2;ea[P+6]=G+2;ea[P+7]=G+3;P+=8;G+=4}}}if(ia){b.bindBuffer(b.ARRAY_BUFFER,
+f.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,K,h)}if(ma&&na.length){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLColorBuffer);b.bufferData(b.ARRAY_BUFFER,ba,h)}if(qa){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,da,h)}if(aa&&ha.hasTangents){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLTangentBuffer);b.bufferData(b.ARRAY_BUFFER,Y,h)}if(pa&&U>0){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLUVBuffer);b.bufferData(b.ARRAY_BUFFER,W,h)}if(pa&&X>0){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLUV2Buffer);
+b.bufferData(b.ARRAY_BUFFER,ga,h)}if(sa){b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,f.__webGLFaceBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,Z,h);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,f.__webGLLineBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,ea,h)}};this.setLineBuffers=function(f,p){var h,e,n,j=f.vertices,t=f.colors,q=j.length,k=t.length,u=f.__vertexArray,C=f.__colorArray,v=f.__lineArray,O=f.__dirtyColors,G=f.__dirtyElements;if(f.__dirtyVertices){for(h=0;h<q;h++){e=j[h].position;n=h*3;u[n]=e.x;u[n+1]=e.y;u[n+
+2]=e.z}b.bindBuffer(b.ARRAY_BUFFER,f.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,u,p)}if(O){for(h=0;h<k;h++){color=t[h];n=h*3;C[n]=color.r;C[n+1]=color.g;C[n+2]=color.b}b.bindBuffer(b.ARRAY_BUFFER,f.__webGLColorBuffer);b.bufferData(b.ARRAY_BUFFER,C,p)}if(G){for(h=0;h<q;h++)v[h]=h;b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,f.__webGLLineBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,v,p)}};this.setParticleBuffers=function(f,p,h,e){var n,j,t;j=f.vertices;var q=j.length,k=f.colors,u=k.length,C=f.__vertexArray,
+v=f.__particleArray,O=f.__colorArray,G=f.__sortArray,D=f.__dirtyVertices,U=f.__dirtyElements,X=f.__dirtyColors;if(h.sortParticles){M.multiply(e.projectionMatrix,e.matrix);M.multiplySelf(h.matrix);for(n=0;n<q;n++){t=j[n].position;s.copy(t);M.multiplyVector3(s);G[n]=[s.z,n]}G.sort(function(L,H){return H[0]-L[0]});for(n=0;n<q;n++){t=j[G[n][1]].position;e=n*3;C[e]=t.x;C[e+1]=t.y;C[e+2]=t.z}for(j=0;j<u;j++){e=j*3;color=k[G[j][1]];O[e]=color.r;O[e+1]=color.g;O[e+2]=color.b}}else{if(D)for(n=0;n<q;n++){t=
+j[n].position;e=n*3;C[e]=t.x;C[e+1]=t.y;C[e+2]=t.z}if(X)for(j=0;j<u;j++){color=k[j];e=j*3;O[e]=color.r;O[e+1]=color.g;O[e+2]=color.b}}if(U){for(n=0;n<q;n++)v[n]=n;b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,f.__webGLParticleBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,v,p)}if(D||h.sortParticles){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,C,p)}if(X||h.sortParticles){b.bindBuffer(b.ARRAY_BUFFER,f.__webGLColorBuffer);b.bufferData(b.ARRAY_BUFFER,O,p)}};this.initMaterial=function(f,
+p,h){if(!f.program){var e,n;if(f instanceof THREE.MeshDepthMaterial)c(f,THREE.ShaderLib.depth);else if(f instanceof THREE.MeshNormalMaterial)c(f,THREE.ShaderLib.normal);else if(f instanceof THREE.MeshBasicMaterial)c(f,THREE.ShaderLib.basic);else if(f instanceof THREE.MeshLambertMaterial)c(f,THREE.ShaderLib.lambert);else if(f instanceof THREE.MeshPhongMaterial)c(f,THREE.ShaderLib.phong);else if(f instanceof THREE.LineBasicMaterial)c(f,THREE.ShaderLib.basic);else f instanceof THREE.ParticleBasicMaterial&&
+c(f,THREE.ShaderLib.particle_basic);var j,t,q,k;n=q=k=0;for(j=p.length;n<j;n++){t=p[n];t instanceof THREE.DirectionalLight&&q++;t instanceof THREE.PointLight&&k++}if(k+q<=4){p=q;k=k}else{p=Math.ceil(4*q/(k+q));k=4-p}n={directional:p,point:k};k=f.fragment_shader;p=f.vertex_shader;j={fog:h,map:f.map,env_map:f.env_map,light_map:f.light_map,vertex_colors:f.vertex_colors,maxDirLights:n.directional,maxPointLights:n.point};h=b.createProgram();n=["#ifdef GL_ES\nprecision highp float;\n#endif","#define MAX_DIR_LIGHTS "+
+j.maxDirLights,"#define MAX_POINT_LIGHTS "+j.maxPointLights,j.fog?"#define USE_FOG":"",j.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",j.map?"#define USE_MAP":"",j.env_map?"#define USE_ENVMAP":"",j.light_map?"#define USE_LIGHTMAP":"",j.vertex_colors?"#define USE_COLOR":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");j=[b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+j.maxDirLights,"#define MAX_POINT_LIGHTS "+
+j.maxPointLights,j.map?"#define USE_MAP":"",j.env_map?"#define USE_ENVMAP":"",j.light_map?"#define USE_LIGHTMAP":"",j.vertex_colors?"#define USE_COLOR":"","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 vec3 color;\nattribute vec2 uv;\nattribute vec2 uv2;\n"].join("\n");b.attachShader(h,g("fragment",n+k));b.attachShader(h,
+g("vertex",j+p));b.linkProgram(h);b.getProgramParameter(h,b.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+b.getProgramParameter(h,b.VALIDATE_STATUS)+", gl error ["+b.getError()+"]");h.uniforms={};h.attributes={};f.program=h;h=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(e in f.uniforms)h.push(e);e=f.program;k=0;for(p=h.length;k<p;k++){n=h[k];e.uniforms[n]=b.getUniformLocation(e,n)}f=f.program;e=["position","normal",
+"uv","uv2","tangent","color"];h=0;for(k=e.length;h<k;h++){p=e[h];f.attributes[p]=b.getAttribLocation(f,p)}}};this.setProgram=function(f,p,h,e){this.initMaterial(e,p,h);var n=e.program;if(n!=r){b.useProgram(n);r=n}this.loadCamera(n,f);this.loadMatrices(n);if(e instanceof THREE.MeshPhongMaterial||e instanceof THREE.MeshLambertMaterial){this.setupLights(n,p);p=this.lights;e.uniforms.enableLighting.value=p.directional.length+p.point.length;e.uniforms.ambientLightColor.value=p.ambient;e.uniforms.directionalLightColor.value=
+p.directional.colors;e.uniforms.directionalLightDirection.value=p.directional.positions;e.uniforms.pointLightColor.value=p.point.colors;e.uniforms.pointLightPosition.value=p.point.positions}if(e instanceof THREE.MeshBasicMaterial||e instanceof THREE.MeshLambertMaterial||e instanceof THREE.MeshPhongMaterial){e.uniforms.diffuse.value.setRGB(e.color.r*e.opacity,e.color.g*e.opacity,e.color.b*e.opacity);e.uniforms.opacity.value=e.opacity;e.uniforms.map.texture=e.map;e.uniforms.light_map.texture=e.light_map;
+e.uniforms.env_map.texture=e.env_map;e.uniforms.reflectivity.value=e.reflectivity;e.uniforms.refraction_ratio.value=e.refraction_ratio;e.uniforms.combine.value=e.combine;e.uniforms.useRefract.value=e.env_map&&e.env_map.mapping instanceof THREE.CubeRefractionMapping;if(h){e.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){e.uniforms.fogNear.value=h.near;e.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)e.uniforms.fogDensity.value=h.density}}if(e instanceof THREE.LineBasicMaterial){e.uniforms.diffuse.value.setRGB(e.color.r*
 e.opacity,e.color.g*e.opacity,e.color.b*e.opacity);e.uniforms.opacity.value=e.opacity;if(h){e.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){e.uniforms.fogNear.value=h.near;e.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)e.uniforms.fogDensity.value=h.density}}if(e instanceof THREE.ParticleBasicMaterial){e.uniforms.psColor.value.setRGB(e.color.r*e.opacity,e.color.g*e.opacity,e.color.b*e.opacity);e.uniforms.opacity.value=e.opacity;e.uniforms.size.value=e.size;
 e.uniforms.map.texture=e.map;if(h){e.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){e.uniforms.fogNear.value=h.near;e.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)e.uniforms.fogDensity.value=h.density}}if(e instanceof THREE.MeshPhongMaterial){e.uniforms.ambient.value.setRGB(e.ambient.r,e.ambient.g,e.ambient.b);e.uniforms.specular.value.setRGB(e.specular.r,e.specular.g,e.specular.b);e.uniforms.shininess.value=e.shininess}if(e instanceof THREE.MeshDepthMaterial){e.uniforms.mNear.value=
-f.near;e.uniforms.mFar.value=f.far;e.uniforms.opacity.value=e.opacity}if(e instanceof THREE.MeshNormalMaterial)e.uniforms.opacity.value=e.opacity;f=e.uniforms;var j,t;for(j in f)if(t=o.uniforms[j]){e=f[j];p=e.type;h=e.value;if(p=="i")b.uniform1i(t,h);else if(p=="f")b.uniform1f(t,h);else if(p=="fv1")b.uniform1fv(t,h);else if(p=="fv")b.uniform3fv(t,h);else if(p=="v2")b.uniform2f(t,h.x,h.y);else if(p=="v3")b.uniform3f(t,h.x,h.y,h.z);else if(p=="c")b.uniform3f(t,h.r,h.g,h.b);else if(p=="t"){b.uniform1i(t,
+f.near;e.uniforms.mFar.value=f.far;e.uniforms.opacity.value=e.opacity}if(e instanceof THREE.MeshNormalMaterial)e.uniforms.opacity.value=e.opacity;f=e.uniforms;var j,t;for(j in f)if(t=n.uniforms[j]){e=f[j];p=e.type;h=e.value;if(p=="i")b.uniform1i(t,h);else if(p=="f")b.uniform1f(t,h);else if(p=="fv1")b.uniform1fv(t,h);else if(p=="fv")b.uniform3fv(t,h);else if(p=="v2")b.uniform2f(t,h.x,h.y);else if(p=="v3")b.uniform3f(t,h.x,h.y,h.z);else if(p=="c")b.uniform3f(t,h.r,h.g,h.b);else if(p=="t"){b.uniform1i(t,
 h);if(e=e.texture)if(e.image instanceof Array&&e.image.length==6){e=e;h=h;if(e.image.length==6){if(!e.image.__webGLTextureCube&&!e.image.__cubeMapInitialized&&e.image.loadCount==6){e.image.__webGLTextureCube=b.createTexture();b.bindTexture(b.TEXTURE_CUBE_MAP,e.image.__webGLTextureCube);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_MAG_FILTER,b.LINEAR);b.texParameteri(b.TEXTURE_CUBE_MAP,
 b.TEXTURE_MIN_FILTER,b.LINEAR_MIPMAP_LINEAR);for(p=0;p<6;++p)b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X+p,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.image[p]);b.generateMipmap(b.TEXTURE_CUBE_MAP);b.bindTexture(b.TEXTURE_CUBE_MAP,null);e.image.__cubeMapInitialized=true}b.activeTexture(b.TEXTURE0+h);b.bindTexture(b.TEXTURE_CUBE_MAP,e.image.__webGLTextureCube)}}else{e=e;h=h;if(!e.__webGLTexture&&e.image.loaded){e.__webGLTexture=b.createTexture();b.bindTexture(b.TEXTURE_2D,e.__webGLTexture);b.texImage2D(b.TEXTURE_2D,
-0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.image);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,i(e.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,i(e.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,i(e.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,i(e.min_filter));b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}b.activeTexture(b.TEXTURE0+h);b.bindTexture(b.TEXTURE_2D,e.__webGLTexture)}}}return o};this.renderBuffer=function(f,p,h,e,o,j){f=this.setProgram(f,
-p,h,e,j).attributes;b.bindBuffer(b.ARRAY_BUFFER,o.__webGLVertexBuffer);b.vertexAttribPointer(f.position,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.position);if(f.color>=0){b.bindBuffer(b.ARRAY_BUFFER,o.__webGLColorBuffer);b.vertexAttribPointer(f.color,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.color)}if(f.normal>=0){b.bindBuffer(b.ARRAY_BUFFER,o.__webGLNormalBuffer);b.vertexAttribPointer(f.normal,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.normal)}if(f.tangent>=0){b.bindBuffer(b.ARRAY_BUFFER,
-o.__webGLTangentBuffer);b.vertexAttribPointer(f.tangent,4,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.tangent)}if(f.uv>=0)if(o.__webGLUVBuffer){b.bindBuffer(b.ARRAY_BUFFER,o.__webGLUVBuffer);b.vertexAttribPointer(f.uv,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.uv)}else b.disableVertexAttribArray(f.uv);if(f.uv2>=0)if(o.__webGLUV2Buffer){b.bindBuffer(b.ARRAY_BUFFER,o.__webGLUV2Buffer);b.vertexAttribPointer(f.uv2,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.uv2)}else b.disableVertexAttribArray(f.uv2);
-if(e.wireframe||e instanceof THREE.LineBasicMaterial){f=e.wireframe_linewidth!==undefined?e.wireframe_linewidth:e.linewidth!==undefined?e.linewidth:1;e=e instanceof THREE.LineBasicMaterial&&j.type==THREE.LineStrip?b.LINE_STRIP:b.LINES;b.lineWidth(f);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,o.__webGLLineBuffer);b.drawElements(e,o.__webGLLineCount,b.UNSIGNED_SHORT,0)}else if(e instanceof THREE.ParticleBasicMaterial){b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,o.__webGLParticleBuffer);b.drawElements(b.POINTS,o.__webGLParticleCount,
-b.UNSIGNED_SHORT,0)}else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,o.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,o.__webGLFaceCount,b.UNSIGNED_SHORT,0)}};this.renderPass=function(f,p,h,e,o,j,t){var q,k,u,C,v;u=0;for(C=e.materials.length;u<C;u++){q=e.materials[u];if(q instanceof THREE.MeshFaceMaterial){q=0;for(k=o.materials.length;q<k;q++)if((v=o.materials[q])&&v.blending==j&&v.opacity<1==t){this.setBlending(v.blending);this.setDepthTest(v.depth_test);this.renderBuffer(f,p,h,v,o,e)}}else if((v=q)&&v.blending==
-j&&v.opacity<1==t){this.setBlending(v.blending);this.setDepthTest(v.depth_test);this.renderBuffer(f,p,h,v,o,e)}}};this.renderPassImmediate=function(f,p,h,e,o,j){var t,q,k,u;t=0;for(q=e.materials.length;t<q;t++)if((k=e.materials[t])&&k.blending==o&&k.opacity<1==j){this.setBlending(k.blending);this.setDepthTest(k.depth_test);u=this.setProgram(f,p,h,k,e);e.render(function(C){var v=u;if(!C.__webGLVertexBuffer)C.__webGLVertexBuffer=b.createBuffer();if(!C.__webGLNormalBuffer)C.__webGLNormalBuffer=b.createBuffer();
+0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.image);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,i(e.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,i(e.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,i(e.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,i(e.min_filter));b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}b.activeTexture(b.TEXTURE0+h);b.bindTexture(b.TEXTURE_2D,e.__webGLTexture)}}}return n};this.renderBuffer=function(f,p,h,e,n,j){f=this.setProgram(f,
+p,h,e,j).attributes;b.bindBuffer(b.ARRAY_BUFFER,n.__webGLVertexBuffer);b.vertexAttribPointer(f.position,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.position);if(f.color>=0){b.bindBuffer(b.ARRAY_BUFFER,n.__webGLColorBuffer);b.vertexAttribPointer(f.color,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.color)}if(f.normal>=0){b.bindBuffer(b.ARRAY_BUFFER,n.__webGLNormalBuffer);b.vertexAttribPointer(f.normal,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.normal)}if(f.tangent>=0){b.bindBuffer(b.ARRAY_BUFFER,
+n.__webGLTangentBuffer);b.vertexAttribPointer(f.tangent,4,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.tangent)}if(f.uv>=0)if(n.__webGLUVBuffer){b.bindBuffer(b.ARRAY_BUFFER,n.__webGLUVBuffer);b.vertexAttribPointer(f.uv,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.uv)}else b.disableVertexAttribArray(f.uv);if(f.uv2>=0)if(n.__webGLUV2Buffer){b.bindBuffer(b.ARRAY_BUFFER,n.__webGLUV2Buffer);b.vertexAttribPointer(f.uv2,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(f.uv2)}else b.disableVertexAttribArray(f.uv2);
+if(e.wireframe||e instanceof THREE.LineBasicMaterial){f=e.wireframe_linewidth!==undefined?e.wireframe_linewidth:e.linewidth!==undefined?e.linewidth:1;e=e instanceof THREE.LineBasicMaterial&&j.type==THREE.LineStrip?b.LINE_STRIP:b.LINES;b.lineWidth(f);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,n.__webGLLineBuffer);b.drawElements(e,n.__webGLLineCount,b.UNSIGNED_SHORT,0)}else if(e instanceof THREE.ParticleBasicMaterial){b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,n.__webGLParticleBuffer);b.drawElements(b.POINTS,n.__webGLParticleCount,
+b.UNSIGNED_SHORT,0)}else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,n.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,n.__webGLFaceCount,b.UNSIGNED_SHORT,0)}};this.renderPass=function(f,p,h,e,n,j,t){var q,k,u,C,v;u=0;for(C=e.materials.length;u<C;u++){q=e.materials[u];if(q instanceof THREE.MeshFaceMaterial){q=0;for(k=n.materials.length;q<k;q++)if((v=n.materials[q])&&v.blending==j&&v.opacity<1==t){this.setBlending(v.blending);this.setDepthTest(v.depth_test);this.renderBuffer(f,p,h,v,n,e)}}else if((v=q)&&v.blending==
+j&&v.opacity<1==t){this.setBlending(v.blending);this.setDepthTest(v.depth_test);this.renderBuffer(f,p,h,v,n,e)}}};this.renderPassImmediate=function(f,p,h,e,n,j){var t,q,k,u;t=0;for(q=e.materials.length;t<q;t++)if((k=e.materials[t])&&k.blending==n&&k.opacity<1==j){this.setBlending(k.blending);this.setDepthTest(k.depth_test);u=this.setProgram(f,p,h,k,e);e.render(function(C){var v=u;if(!C.__webGLVertexBuffer)C.__webGLVertexBuffer=b.createBuffer();if(!C.__webGLNormalBuffer)C.__webGLNormalBuffer=b.createBuffer();
 if(C.hasPos){b.bindBuffer(b.ARRAY_BUFFER,C.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,C.positionArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(v.attributes.position);b.vertexAttribPointer(v.attributes.position,3,b.FLOAT,false,0,0)}if(C.hasNormal){b.bindBuffer(b.ARRAY_BUFFER,C.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,C.normalArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(v.attributes.normal);b.vertexAttribPointer(v.attributes.normal,3,b.FLOAT,false,0,0)}b.drawArrays(b.TRIANGLES,0,C.count);
-C.count=0})}};this.render=function(f,p,h,e){var o,j,t,q,k=f.lights,u=f.fog;p.autoUpdateMatrix&&p.updateMatrix();y.set(p.matrix.flatten());x.set(p.projectionMatrix.flatten());this.initWebGLObjects(f,p);e=e!==undefined?e:true;if(h&&!h.__webGLFramebuffer){h.__webGLFramebuffer=b.createFramebuffer();h.__webGLRenderbuffer=b.createRenderbuffer();h.__webGLTexture=b.createTexture();b.bindRenderbuffer(b.RENDERBUFFER,h.__webGLRenderbuffer);b.renderbufferStorage(b.RENDERBUFFER,b.DEPTH_COMPONENT16,h.width,h.height);
+C.count=0})}};this.render=function(f,p,h,e){var n,j,t,q,k=f.lights,u=f.fog;p.autoUpdateMatrix&&p.updateMatrix();y.set(p.matrix.flatten());x.set(p.projectionMatrix.flatten());this.initWebGLObjects(f,p);e=e!==undefined?e:true;if(h&&!h.__webGLFramebuffer){h.__webGLFramebuffer=b.createFramebuffer();h.__webGLRenderbuffer=b.createRenderbuffer();h.__webGLTexture=b.createTexture();b.bindRenderbuffer(b.RENDERBUFFER,h.__webGLRenderbuffer);b.renderbufferStorage(b.RENDERBUFFER,b.DEPTH_COMPONENT16,h.width,h.height);
 b.bindTexture(b.TEXTURE_2D,h.__webGLTexture);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,i(h.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,i(h.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,i(h.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,i(h.min_filter));b.texImage2D(b.TEXTURE_2D,0,i(h.format),h.width,h.height,0,i(h.format),i(h.type),null);b.bindFramebuffer(b.FRAMEBUFFER,h.__webGLFramebuffer);b.framebufferTexture2D(b.FRAMEBUFFER,b.COLOR_ATTACHMENT0,b.TEXTURE_2D,
-h.__webGLTexture,0);b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,h.__webGLRenderbuffer);b.bindTexture(b.TEXTURE_2D,null);b.bindRenderbuffer(b.RENDERBUFFER,null);b.bindFramebuffer(b.FRAMEBUFFER,null)}if(h){o=h.__webGLFramebuffer;q=h.width;j=h.height}else{o=null;q=l.width;j=l.height}if(o!=m){b.bindFramebuffer(b.FRAMEBUFFER,o);b.viewport(0,0,q,j);e&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);m=o}this.autoClear&&this.clear();o=f.__webGLObjects.length;for(e=0;e<o;e++){t=
-f.__webGLObjects[e];q=t.object;q.visible&&q.autoUpdateMatrix&&q.updateMatrix()}j=f.__webGLObjectsImmediate.length;for(e=0;e<j;e++){t=f.__webGLObjectsImmediate[e];q=t.object;q.visible&&q.autoUpdateMatrix&&q.updateMatrix()}for(e=0;e<o;e++){t=f.__webGLObjects[e];q=t.object;j=t.buffer;if(q.visible){d(q);this.setupMatrices(q,p);this.renderPass(p,k,u,q,j,THREE.NormalBlending,false)}}for(e=0;e<f.__webGLObjectsImmediate.length;e++){t=f.__webGLObjectsImmediate[e];q=t.object;if(q.visible){d(q);this.setupMatrices(q,
-p);this.renderPassImmediate(p,k,u,q,THREE.NormalBlending,false)}}for(e=0;e<o;e++){t=f.__webGLObjects[e];q=t.object;j=t.buffer;if(q.visible){d(q);this.setupMatrices(q,p);this.renderPass(p,k,u,q,j,THREE.AdditiveBlending,false);this.renderPass(p,k,u,q,j,THREE.SubtractiveBlending,false);this.renderPass(p,k,u,q,j,THREE.AdditiveBlending,true);this.renderPass(p,k,u,q,j,THREE.SubtractiveBlending,true);this.renderPass(p,k,u,q,j,THREE.NormalBlending,true);this.renderPass(p,k,u,q,j,THREE.BillboardBlending,false)}}for(e=
+h.__webGLTexture,0);b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,h.__webGLRenderbuffer);b.bindTexture(b.TEXTURE_2D,null);b.bindRenderbuffer(b.RENDERBUFFER,null);b.bindFramebuffer(b.FRAMEBUFFER,null)}if(h){n=h.__webGLFramebuffer;q=h.width;j=h.height}else{n=null;q=l.width;j=l.height}if(n!=m){b.bindFramebuffer(b.FRAMEBUFFER,n);b.viewport(0,0,q,j);e&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);m=n}this.autoClear&&this.clear();n=f.__webGLObjects.length;for(e=0;e<n;e++){t=
+f.__webGLObjects[e];q=t.object;q.visible&&q.autoUpdateMatrix&&q.updateMatrix()}j=f.__webGLObjectsImmediate.length;for(e=0;e<j;e++){t=f.__webGLObjectsImmediate[e];q=t.object;q.visible&&q.autoUpdateMatrix&&q.updateMatrix()}for(e=0;e<n;e++){t=f.__webGLObjects[e];q=t.object;j=t.buffer;if(q.visible){d(q);this.setupMatrices(q,p);this.renderPass(p,k,u,q,j,THREE.NormalBlending,false)}}for(e=0;e<f.__webGLObjectsImmediate.length;e++){t=f.__webGLObjectsImmediate[e];q=t.object;if(q.visible){d(q);this.setupMatrices(q,
+p);this.renderPassImmediate(p,k,u,q,THREE.NormalBlending,false)}}for(e=0;e<n;e++){t=f.__webGLObjects[e];q=t.object;j=t.buffer;if(q.visible){d(q);this.setupMatrices(q,p);this.renderPass(p,k,u,q,j,THREE.AdditiveBlending,false);this.renderPass(p,k,u,q,j,THREE.SubtractiveBlending,false);this.renderPass(p,k,u,q,j,THREE.AdditiveBlending,true);this.renderPass(p,k,u,q,j,THREE.SubtractiveBlending,true);this.renderPass(p,k,u,q,j,THREE.NormalBlending,true);this.renderPass(p,k,u,q,j,THREE.BillboardBlending,false)}}for(e=
 0;e<f.__webGLObjectsImmediate.length;e++){t=f.__webGLObjectsImmediate[e];q=t.object;if(q.visible){d(q);this.setupMatrices(q,p);this.renderPassImmediate(p,k,u,q,THREE.NormalBlending,true)}}if(h&&h.min_filter!==THREE.NearestFilter&&h.min_filter!==THREE.LinearFilter){b.bindTexture(b.TEXTURE_2D,h.__webGLTexture);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}};this.initWebGLObjects=function(f,p){function h(v,O,G,D){if(v[O]==undefined){f.__webGLObjects.push({buffer:G,object:D});v[O]=1}}
-function e(v,O,G){if(v[O]==undefined){f.__webGLObjectsImmediate.push({object:G});v[O]=1}}var o,j,t,q,k,u,C;if(!f.__webGLObjects){f.__webGLObjects=[];f.__webGLObjectsMap={};f.__webGLObjectsImmediate=[]}o=0;for(j=f.objects.length;o<j;o++){t=f.objects[o];k=t.geometry;if(f.__webGLObjectsMap[t.id]==undefined)f.__webGLObjectsMap[t.id]={};C=f.__webGLObjectsMap[t.id];if(t instanceof THREE.Mesh){for(q in k.geometryChunks){u=k.geometryChunks[q];if(!u.__webGLVertexBuffer){this.createMeshBuffers(u);this.initMeshBuffers(u,
+function e(v,O,G){if(v[O]==undefined){f.__webGLObjectsImmediate.push({object:G});v[O]=1}}var n,j,t,q,k,u,C;if(!f.__webGLObjects){f.__webGLObjects=[];f.__webGLObjectsMap={};f.__webGLObjectsImmediate=[]}n=0;for(j=f.objects.length;n<j;n++){t=f.objects[n];k=t.geometry;if(f.__webGLObjectsMap[t.id]==undefined)f.__webGLObjectsMap[t.id]={};C=f.__webGLObjectsMap[t.id];if(t instanceof THREE.Mesh){for(q in k.geometryChunks){u=k.geometryChunks[q];if(!u.__webGLVertexBuffer){this.createMeshBuffers(u);this.initMeshBuffers(u,
 t);k.__dirtyVertices=true;k.__dirtyElements=true;k.__dirtyUvs=true;k.__dirtyNormals=true;k.__dirtyTangents=true;k.__dirtyColors=true}if(k.__dirtyVertices||k.__dirtyElements||k.__dirtyUvs||k.__dirtyNormals||k.__dirtyColors||k.__dirtyTangents)this.setMeshBuffers(u,t,b.DYNAMIC_DRAW);h(C,q,u,t)}k.__dirtyVertices=false;k.__dirtyElements=false;k.__dirtyUvs=false;k.__dirtyNormals=false;k.__dirtyTangents=false;k.__dirtyColors=false}else if(t instanceof THREE.Line){if(!k.__webGLVertexBuffer){this.createLineBuffers(k);
 this.initLineBuffers(k);k.__dirtyVertices=true;k.__dirtyElements=true;k.__dirtyColors=true}if(k.__dirtyVertices||k.__dirtyColors)this.setLineBuffers(k,b.DYNAMIC_DRAW);h(C,0,k,t);k.__dirtyVertices=false;k.__dirtyElements=false}else if(t instanceof THREE.ParticleSystem){if(!k.__webGLVertexBuffer){this.createParticleBuffers(k);this.initParticleBuffers(k);k.__dirtyVertices=true;k.__dirtyColors=true;k.__dirtyElements=true}if(k.__dirtyVertices||k.__dirtyColors||t.sortParticles)this.setParticleBuffers(k,
-b.DYNAMIC_DRAW,t,p);h(C,0,k,t);k.__dirtyVertices=false;k.__dirtyColors=false;k.__dirtyElements=false}else t instanceof THREE.MarchingCubes&&e(C,0,t)}};this.removeObject=function(f,p){var h,e;for(h=f.__webGLObjects.length-1;h>=0;h--){e=f.__webGLObjects[h].object;p==e&&f.__webGLObjects.splice(h,1)}};this.setupMatrices=function(f,p){n.multiply(p.matrix,f.matrix);w.set(n.flatten());z=THREE.Matrix4.makeInvert3x3(n).transpose();I.set(z.m);N.set(f.matrix.flatten())};this.loadMatrices=function(f){b.uniformMatrix4fv(f.uniforms.viewMatrix,
+b.DYNAMIC_DRAW,t,p);h(C,0,k,t);k.__dirtyVertices=false;k.__dirtyColors=false;k.__dirtyElements=false}else t instanceof THREE.MarchingCubes&&e(C,0,t)}};this.removeObject=function(f,p){var h,e;for(h=f.__webGLObjects.length-1;h>=0;h--){e=f.__webGLObjects[h].object;p==e&&f.__webGLObjects.splice(h,1)}};this.setupMatrices=function(f,p){o.multiply(p.matrix,f.matrix);w.set(o.flatten());z=THREE.Matrix4.makeInvert3x3(o).transpose();I.set(z.m);N.set(f.matrix.flatten())};this.loadMatrices=function(f){b.uniformMatrix4fv(f.uniforms.viewMatrix,
 false,y);b.uniformMatrix4fv(f.uniforms.modelViewMatrix,false,w);b.uniformMatrix4fv(f.uniforms.projectionMatrix,false,x);b.uniformMatrix3fv(f.uniforms.normalMatrix,false,I);b.uniformMatrix4fv(f.uniforms.objectMatrix,false,N)};this.loadCamera=function(f,p){b.uniform3f(f.uniforms.cameraPosition,p.position.x,p.position.y,p.position.z)};this.setDepthTest=function(f){f?b.enable(b.DEPTH_TEST):b.disable(b.DEPTH_TEST)};this.setBlending=function(f){switch(f){case THREE.AdditiveBlending:b.blendEquation(b.FUNC_ADD);
 b.blendFunc(b.ONE,b.ONE);break;case THREE.SubtractiveBlending:b.blendFunc(b.DST_COLOR,b.ZERO);break;case THREE.BillboardBlending:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA);break;default:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(f,p){if(f){!p||p=="ccw"?b.frontFace(b.CCW):b.frontFace(b.CW);if(f=="back")b.cullFace(b.BACK);else f=="front"?b.cullFace(b.FRONT):b.cullFace(b.FRONT_AND_BACK);b.enable(b.CULL_FACE)}else b.disable(b.CULL_FACE)};
 this.supportsVertexTextures=function(){return b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}};

+ 78 - 78
build/ThreeExtras.js

@@ -25,8 +25,8 @@ THREE.Matrix4.prototype={identity:function(){this.n11=1;this.n21=this.n14=this.n
 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,c,d){var e=THREE.Matrix4.__tmpVec1,g=THREE.Matrix4.__tmpVec2,f=THREE.Matrix4.__tmpVec3;f.sub(a,c).normalize();e.cross(d,f).normalize();g.cross(f,e).normalize();this.n11=e.x;this.n12=e.y;this.n13=e.z;this.n14=-e.dot(a);this.n21=g.x;this.n22=g.y;this.n23=g.z;this.n24=-g.dot(a);
 this.n31=f.x;this.n32=f.y;this.n33=f.z;this.n34=-f.dot(a);this.n43=this.n42=this.n41=0;this.n44=1;return this},multiplyVector3:function(a){var c=a.x,d=a.y,e=a.z,g=1/(this.n41*c+this.n42*d+this.n43*e+this.n44);a.x=(this.n11*c+this.n12*d+this.n13*e+this.n14)*g;a.y=(this.n21*c+this.n22*d+this.n23*e+this.n24)*g;a.z=(this.n31*c+this.n32*d+this.n33*e+this.n34)*g;return a},multiplyVector4:function(a){var c=a.x,d=a.y,e=a.z,g=a.w;a.x=this.n11*c+this.n12*d+this.n13*e+this.n14*g;a.y=this.n21*c+this.n22*d+this.n23*
 e+this.n24*g;a.z=this.n31*c+this.n32*d+this.n33*e+this.n34*g;a.w=this.n41*c+this.n42*d+this.n43*e+this.n44*g;return a},crossVector:function(a){var c=new THREE.Vector4;c.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;c.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;c.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;c.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return c},multiply:function(a,c){var d=a.n11,e=a.n12,g=a.n13,f=a.n14,b=a.n21,k=a.n22,h=a.n23,m=a.n24,o=a.n31,
-y=a.n32,v=a.n33,q=a.n34,z=a.n41,B=a.n42,H=a.n43,w=a.n44,I=c.n11,t=c.n12,L=c.n13,l=c.n14,A=c.n21,n=c.n22,j=c.n23,x=c.n24,u=c.n31,E=c.n32,C=c.n33,p=c.n34,F=c.n41,M=c.n42,G=c.n43,X=c.n44;this.n11=d*I+e*A+g*u+f*F;this.n12=d*t+e*n+g*E+f*M;this.n13=d*L+e*j+g*C+f*G;this.n14=d*l+e*x+g*p+f*X;this.n21=b*I+k*A+h*u+m*F;this.n22=b*t+k*n+h*E+m*M;this.n23=b*L+k*j+h*C+m*G;this.n24=b*l+k*x+h*p+m*X;this.n31=o*I+y*A+v*u+q*F;this.n32=o*t+y*n+v*E+q*M;this.n33=o*L+y*j+v*C+q*G;this.n34=o*l+y*x+v*p+q*X;this.n41=z*I+B*A+
-H*u+w*F;this.n42=z*t+B*n+H*E+w*M;this.n43=z*L+B*j+H*C+w*G;this.n44=z*l+B*x+H*p+w*X;return this},multiplySelf:function(a){var c=this.n11,d=this.n12,e=this.n13,g=this.n14,f=this.n21,b=this.n22,k=this.n23,h=this.n24,m=this.n31,o=this.n32,y=this.n33,v=this.n34,q=this.n41,z=this.n42,B=this.n43,H=this.n44,w=a.n11,I=a.n21,t=a.n31,L=a.n41,l=a.n12,A=a.n22,n=a.n32,j=a.n42,x=a.n13,u=a.n23,E=a.n33,C=a.n43,p=a.n14,F=a.n24,M=a.n34;a=a.n44;this.n11=c*w+d*I+e*t+g*L;this.n12=c*l+d*A+e*n+g*j;this.n13=c*x+d*u+e*E+g*
+y=a.n32,v=a.n33,q=a.n34,z=a.n41,B=a.n42,H=a.n43,w=a.n44,I=c.n11,t=c.n12,L=c.n13,l=c.n14,A=c.n21,n=c.n22,j=c.n23,x=c.n24,u=c.n31,E=c.n32,C=c.n33,p=c.n34,F=c.n41,M=c.n42,G=c.n43,W=c.n44;this.n11=d*I+e*A+g*u+f*F;this.n12=d*t+e*n+g*E+f*M;this.n13=d*L+e*j+g*C+f*G;this.n14=d*l+e*x+g*p+f*W;this.n21=b*I+k*A+h*u+m*F;this.n22=b*t+k*n+h*E+m*M;this.n23=b*L+k*j+h*C+m*G;this.n24=b*l+k*x+h*p+m*W;this.n31=o*I+y*A+v*u+q*F;this.n32=o*t+y*n+v*E+q*M;this.n33=o*L+y*j+v*C+q*G;this.n34=o*l+y*x+v*p+q*W;this.n41=z*I+B*A+
+H*u+w*F;this.n42=z*t+B*n+H*E+w*M;this.n43=z*L+B*j+H*C+w*G;this.n44=z*l+B*x+H*p+w*W;return this},multiplySelf:function(a){var c=this.n11,d=this.n12,e=this.n13,g=this.n14,f=this.n21,b=this.n22,k=this.n23,h=this.n24,m=this.n31,o=this.n32,y=this.n33,v=this.n34,q=this.n41,z=this.n42,B=this.n43,H=this.n44,w=a.n11,I=a.n21,t=a.n31,L=a.n41,l=a.n12,A=a.n22,n=a.n32,j=a.n42,x=a.n13,u=a.n23,E=a.n33,C=a.n43,p=a.n14,F=a.n24,M=a.n34;a=a.n44;this.n11=c*w+d*I+e*t+g*L;this.n12=c*l+d*A+e*n+g*j;this.n13=c*x+d*u+e*E+g*
 C;this.n14=c*p+d*F+e*M+g*a;this.n21=f*w+b*I+k*t+h*L;this.n22=f*l+b*A+k*n+h*j;this.n23=f*x+b*u+k*E+h*C;this.n24=f*p+b*F+k*M+h*a;this.n31=m*w+o*I+y*t+v*L;this.n32=m*l+o*A+y*n+v*j;this.n33=m*x+o*u+y*E+v*C;this.n34=m*p+o*F+y*M+v*a;this.n41=q*w+z*I+B*t+H*L;this.n42=q*l+z*A+B*n+H*j;this.n43=q*x+z*u+B*E+H*C;this.n44=q*p+z*F+B*M+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,g=this.n21,f=this.n22,b=this.n23,k=this.n24,h=this.n31,m=this.n32,o=this.n33,y=this.n34,v=this.n41,q=this.n42,z=this.n43,B=this.n44;return e*b*m*v-d*k*m*v-e*f*o*v+c*k*o*v+d*f*y*v-c*b*y*v-e*b*h*q+d*k*h*q+e*g*o*q-a*k*o*q-d*g*y*q+a*b*y*q+e*f*h*z-c*k*h*z-e*g*m*z+a*k*m*z+c*g*y*z-a*f*y*z-d*f*h*B+c*b*h*B+d*g*m*B-a*b*m*B-c*g*o*B+a*f*o*B},transpose:function(){function a(c,d,
 e){var g=c[d];c[d]=c[e];c[e]=g}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;
@@ -47,7 +47,7 @@ THREE.Geometry.prototype={computeCentroids:function(){var a,c,d;a=0;for(c=this.f
 d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeFaceNormals:function(a){var c,d,e,g,f,b,k=new THREE.Vector3,h=new THREE.Vector3;e=0;for(g=this.vertices.length;e<g;e++){f=this.vertices[e];f.normal.set(0,0,0)}e=0;for(g=this.faces.length;e<g;e++){f=this.faces[e];if(a&&f.vertexNormals.length){k.set(0,0,0);c=0;for(d=f.normal.length;c<d;c++)k.addSelf(f.vertexNormals[c]);k.divideScalar(3)}else{c=this.vertices[f.a];d=this.vertices[f.b];b=this.vertices[f.c];k.sub(b.position,
 d.position);h.sub(c.position,d.position);k.crossSelf(h)}k.isZero()||k.normalize();f.normal.copy(k)}},computeVertexNormals:function(){var a,c,d,e;if(this.__tmpVertices==undefined){e=this.__tmpVertices=Array(this.vertices.length);a=0;for(c=this.vertices.length;a<c;a++)e[a]=new THREE.Vector3;a=0;for(c=this.faces.length;a<c;a++){d=this.faces[a];if(d instanceof THREE.Face3)d.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];else if(d instanceof THREE.Face4)d.vertexNormals=[new THREE.Vector3,
 new THREE.Vector3,new THREE.Vector3,new THREE.Vector3]}}else{e=this.__tmpVertices;a=0;for(c=this.vertices.length;a<c;a++)e[a].set(0,0,0)}a=0;for(c=this.faces.length;a<c;a++){d=this.faces[a];if(d instanceof THREE.Face3){e[d.a].addSelf(d.normal);e[d.b].addSelf(d.normal);e[d.c].addSelf(d.normal)}else if(d instanceof THREE.Face4){e[d.a].addSelf(d.normal);e[d.b].addSelf(d.normal);e[d.c].addSelf(d.normal);e[d.d].addSelf(d.normal)}}a=0;for(c=this.vertices.length;a<c;a++)e[a].normalize();a=0;for(c=this.faces.length;a<
-c;a++){d=this.faces[a];if(d instanceof THREE.Face3){d.vertexNormals[0].copy(e[d.a]);d.vertexNormals[1].copy(e[d.b]);d.vertexNormals[2].copy(e[d.c])}else if(d instanceof THREE.Face4){d.vertexNormals[0].copy(e[d.a]);d.vertexNormals[1].copy(e[d.b]);d.vertexNormals[2].copy(e[d.c]);d.vertexNormals[3].copy(e[d.d])}}},computeTangents:function(){function a(p,F,M,G,X,Q,P){f=p.vertices[F].position;b=p.vertices[M].position;k=p.vertices[G].position;h=g[X];m=g[Q];o=g[P];y=b.x-f.x;v=k.x-f.x;q=b.y-f.y;z=k.y-f.y;
+c;a++){d=this.faces[a];if(d instanceof THREE.Face3){d.vertexNormals[0].copy(e[d.a]);d.vertexNormals[1].copy(e[d.b]);d.vertexNormals[2].copy(e[d.c])}else if(d instanceof THREE.Face4){d.vertexNormals[0].copy(e[d.a]);d.vertexNormals[1].copy(e[d.b]);d.vertexNormals[2].copy(e[d.c]);d.vertexNormals[3].copy(e[d.d])}}},computeTangents:function(){function a(p,F,M,G,W,Q,O){f=p.vertices[F].position;b=p.vertices[M].position;k=p.vertices[G].position;h=g[W];m=g[Q];o=g[O];y=b.x-f.x;v=k.x-f.x;q=b.y-f.y;z=k.y-f.y;
 B=b.z-f.z;H=k.z-f.z;w=m.u-h.u;I=o.u-h.u;t=m.v-h.v;L=o.v-h.v;l=1/(w*L-I*t);j.set((L*y-t*v)*l,(L*q-t*z)*l,(L*B-t*H)*l);x.set((w*v-I*y)*l,(w*z-I*q)*l,(w*H-I*B)*l);A[F].addSelf(j);A[M].addSelf(j);A[G].addSelf(j);n[F].addSelf(x);n[M].addSelf(x);n[G].addSelf(x)}var c,d,e,g,f,b,k,h,m,o,y,v,q,z,B,H,w,I,t,L,l,A=[],n=[],j=new THREE.Vector3,x=new THREE.Vector3,u=new THREE.Vector3,E=new THREE.Vector3,C=new THREE.Vector3;c=0;for(d=this.vertices.length;c<d;c++){A[c]=new THREE.Vector3;n[c]=new THREE.Vector3}c=0;
 for(d=this.faces.length;c<d;c++){e=this.faces[c];g=this.uvs[c];if(e instanceof THREE.Face3){a(this,e.a,e.b,e.c,0,1,2);this.vertices[e.a].normal.copy(e.vertexNormals[0]);this.vertices[e.b].normal.copy(e.vertexNormals[1]);this.vertices[e.c].normal.copy(e.vertexNormals[2])}else if(e instanceof THREE.Face4){a(this,e.a,e.b,e.c,0,1,2);a(this,e.a,e.b,e.d,0,1,3);this.vertices[e.a].normal.copy(e.vertexNormals[0]);this.vertices[e.b].normal.copy(e.vertexNormals[1]);this.vertices[e.c].normal.copy(e.vertexNormals[2]);
 this.vertices[e.d].normal.copy(e.vertexNormals[3])}}c=0;for(d=this.vertices.length;c<d;c++){C.copy(this.vertices[c].normal);e=A[c];u.copy(e);u.subSelf(C.multiplyScalar(C.dot(e))).normalize();E.cross(this.vertices[c].normal,e);e=E.dot(n[c]);e=e<0?-1:1;this.vertices[c].tangent.set(u.x,u.y,u.z,e)}this.hasTangents=true},computeBoundingBox:function(){var a;if(this.vertices.length>0){this.boundingBox={x:[this.vertices[0].position.x,this.vertices[0].position.x],y:[this.vertices[0].position.y,this.vertices[0].position.y],
@@ -105,79 +105,79 @@ THREE.Fog=function(a,c,d){this.color=new THREE.Color(a);this.near=c||1;this.far=
 THREE.Projector=function(){function a(n,j){return j.z-n.z}function c(n,j){var x=0,u=1,E=n.z+n.w,C=j.z+j.w,p=-n.z+n.w,F=-j.z+j.w;if(E>=0&&C>=0&&p>=0&&F>=0)return true;else if(E<0&&C<0||p<0&&F<0)return false;else{if(E<0)x=Math.max(x,E/(E-C));else if(C<0)u=Math.min(u,E/(E-C));if(p<0)x=Math.max(x,p/(p-F));else if(F<0)u=Math.min(u,p/(p-F));if(u<x)return false;else{n.lerpSelf(j,x);j.lerpSelf(n,1-u);return true}}}var d,e,g=[],f,b,k,h=[],m,o,y=[],v,q,z=[],B=new THREE.Vector4,H=new THREE.Vector4,w=new THREE.Matrix4,
 I=new THREE.Matrix4,t=[],L=new THREE.Vector4,l=new THREE.Vector4,A;this.projectObjects=function(n,j,x){var u=[],E,C;e=0;w.multiply(j.projectionMatrix,j.matrix);t[0]=new THREE.Vector4(w.n41-w.n11,w.n42-w.n12,w.n43-w.n13,w.n44-w.n14);t[1]=new THREE.Vector4(w.n41+w.n11,w.n42+w.n12,w.n43+w.n13,w.n44+w.n14);t[2]=new THREE.Vector4(w.n41+w.n21,w.n42+w.n22,w.n43+w.n23,w.n44+w.n24);t[3]=new THREE.Vector4(w.n41-w.n21,w.n42-w.n22,w.n43-w.n23,w.n44-w.n24);t[4]=new THREE.Vector4(w.n41-w.n31,w.n42-w.n32,w.n43-
 w.n33,w.n44-w.n34);t[5]=new THREE.Vector4(w.n41+w.n31,w.n42+w.n32,w.n43+w.n33,w.n44+w.n34);j=0;for(E=t.length;j<E;j++){C=t[j];C.divideScalar(Math.sqrt(C.x*C.x+C.y*C.y+C.z*C.z))}E=n.objects;n=0;for(j=E.length;n<j;n++){C=E[n];var p;if(!(p=!C.visible)){if(p=C instanceof THREE.Mesh){a:{p=void 0;for(var F=C.position,M=-C.geometry.boundingSphere.radius*Math.max(C.scale.x,Math.max(C.scale.y,C.scale.z)),G=0;G<6;G++){p=t[G].x*F.x+t[G].y*F.y+t[G].z*F.z+t[G].w;if(p<=M){p=false;break a}}p=true}p=!p}p=p}if(!p){d=
-g[e]=g[e]||new THREE.RenderableObject;B.copy(C.position);w.multiplyVector3(B);d.object=C;d.z=B.z;u.push(d);e++}}x&&u.sort(a);return u};this.projectScene=function(n,j,x){var u=[],E=j.near,C=j.far,p,F,M,G,X,Q,P,ca,aa,T,R,W,Y,K,U,ba;k=o=q=0;j.autoUpdateMatrix&&j.updateMatrix();w.multiply(j.projectionMatrix,j.matrix);Q=this.projectObjects(n,j,true);n=0;for(p=Q.length;n<p;n++){P=Q[n].object;if(P.visible){P.autoUpdateMatrix&&P.updateMatrix();ca=P.matrix;aa=P.rotationMatrix;T=P.materials;R=P.overdraw;if(P instanceof
-THREE.Mesh){W=P.geometry;Y=W.vertices;F=0;for(M=Y.length;F<M;F++){K=Y[F];K.positionWorld.copy(K.position);ca.multiplyVector3(K.positionWorld);G=K.positionScreen;G.copy(K.positionWorld);w.multiplyVector4(G);G.x/=G.w;G.y/=G.w;K.__visible=G.z>E&&G.z<C}W=W.faces;F=0;for(M=W.length;F<M;F++){K=W[F];if(K instanceof THREE.Face3){G=Y[K.a];X=Y[K.b];U=Y[K.c];if(G.__visible&&X.__visible&&U.__visible)if(P.doubleSided||P.flipSided!=(U.positionScreen.x-G.positionScreen.x)*(X.positionScreen.y-G.positionScreen.y)-
-(U.positionScreen.y-G.positionScreen.y)*(X.positionScreen.x-G.positionScreen.x)<0){f=h[k]=h[k]||new THREE.RenderableFace3;f.v1.positionWorld.copy(G.positionWorld);f.v2.positionWorld.copy(X.positionWorld);f.v3.positionWorld.copy(U.positionWorld);f.v1.positionScreen.copy(G.positionScreen);f.v2.positionScreen.copy(X.positionScreen);f.v3.positionScreen.copy(U.positionScreen);f.normalWorld.copy(K.normal);aa.multiplyVector3(f.normalWorld);f.centroidWorld.copy(K.centroid);ca.multiplyVector3(f.centroidWorld);
-f.centroidScreen.copy(f.centroidWorld);w.multiplyVector3(f.centroidScreen);U=K.vertexNormals;A=f.vertexNormalsWorld;G=0;for(X=U.length;G<X;G++){ba=A[G]=A[G]||new THREE.Vector3;ba.copy(U[G]);aa.multiplyVector3(ba)}f.z=f.centroidScreen.z;f.meshMaterials=T;f.faceMaterials=K.materials;f.overdraw=R;if(P.geometry.uvs[F]){f.uvs[0]=P.geometry.uvs[F][0];f.uvs[1]=P.geometry.uvs[F][1];f.uvs[2]=P.geometry.uvs[F][2]}u.push(f);k++}}else if(K instanceof THREE.Face4){G=Y[K.a];X=Y[K.b];U=Y[K.c];ba=Y[K.d];if(G.__visible&&
-X.__visible&&U.__visible&&ba.__visible)if(P.doubleSided||P.flipSided!=((ba.positionScreen.x-G.positionScreen.x)*(X.positionScreen.y-G.positionScreen.y)-(ba.positionScreen.y-G.positionScreen.y)*(X.positionScreen.x-G.positionScreen.x)<0||(X.positionScreen.x-U.positionScreen.x)*(ba.positionScreen.y-U.positionScreen.y)-(X.positionScreen.y-U.positionScreen.y)*(ba.positionScreen.x-U.positionScreen.x)<0)){f=h[k]=h[k]||new THREE.RenderableFace3;f.v1.positionWorld.copy(G.positionWorld);f.v2.positionWorld.copy(X.positionWorld);
-f.v3.positionWorld.copy(ba.positionWorld);f.v1.positionScreen.copy(G.positionScreen);f.v2.positionScreen.copy(X.positionScreen);f.v3.positionScreen.copy(ba.positionScreen);f.normalWorld.copy(K.normal);aa.multiplyVector3(f.normalWorld);f.centroidWorld.copy(K.centroid);ca.multiplyVector3(f.centroidWorld);f.centroidScreen.copy(f.centroidWorld);w.multiplyVector3(f.centroidScreen);f.z=f.centroidScreen.z;f.meshMaterials=T;f.faceMaterials=K.materials;f.overdraw=R;if(P.geometry.uvs[F]){f.uvs[0]=P.geometry.uvs[F][0];
-f.uvs[1]=P.geometry.uvs[F][1];f.uvs[2]=P.geometry.uvs[F][3]}u.push(f);k++;b=h[k]=h[k]||new THREE.RenderableFace3;b.v1.positionWorld.copy(X.positionWorld);b.v2.positionWorld.copy(U.positionWorld);b.v3.positionWorld.copy(ba.positionWorld);b.v1.positionScreen.copy(X.positionScreen);b.v2.positionScreen.copy(U.positionScreen);b.v3.positionScreen.copy(ba.positionScreen);b.normalWorld.copy(f.normalWorld);b.centroidWorld.copy(f.centroidWorld);b.centroidScreen.copy(f.centroidScreen);b.z=b.centroidScreen.z;
-b.meshMaterials=T;b.faceMaterials=K.materials;b.overdraw=R;if(P.geometry.uvs[F]){b.uvs[0]=P.geometry.uvs[F][1];b.uvs[1]=P.geometry.uvs[F][2];b.uvs[2]=P.geometry.uvs[F][3]}u.push(b);k++}}}}else if(P instanceof THREE.Line){I.multiply(w,ca);Y=P.geometry.vertices;K=Y[0];K.positionScreen.copy(K.position);I.multiplyVector4(K.positionScreen);F=1;for(M=Y.length;F<M;F++){G=Y[F];G.positionScreen.copy(G.position);I.multiplyVector4(G.positionScreen);X=Y[F-1];L.copy(G.positionScreen);l.copy(X.positionScreen);
-if(c(L,l)){L.multiplyScalar(1/L.w);l.multiplyScalar(1/l.w);m=y[o]=y[o]||new THREE.RenderableLine;m.v1.positionScreen.copy(L);m.v2.positionScreen.copy(l);m.z=Math.max(L.z,l.z);m.materials=P.materials;u.push(m);o++}}}else if(P instanceof THREE.Particle){H.set(P.position.x,P.position.y,P.position.z,1);w.multiplyVector4(H);H.z/=H.w;if(H.z>0&&H.z<1){v=z[q]=z[q]||new THREE.RenderableParticle;v.x=H.x/H.w;v.y=H.y/H.w;v.z=H.z;v.rotation=P.rotation.z;v.scale.x=P.scale.x*Math.abs(v.x-(H.x+j.projectionMatrix.n11)/
-(H.w+j.projectionMatrix.n14));v.scale.y=P.scale.y*Math.abs(v.y-(H.y+j.projectionMatrix.n22)/(H.w+j.projectionMatrix.n24));v.materials=P.materials;u.push(v);q++}}}}x&&u.sort(a);return u};this.unprojectVector=function(n,j){var x=THREE.Matrix4.makeInvert(j.matrix);x.multiplySelf(THREE.Matrix4.makeInvert(j.projectionMatrix));x.multiplyVector3(n);return n}};
+g[e]=g[e]||new THREE.RenderableObject;B.copy(C.position);w.multiplyVector3(B);d.object=C;d.z=B.z;u.push(d);e++}}x&&u.sort(a);return u};this.projectScene=function(n,j,x){var u=[],E=j.near,C=j.far,p,F,M,G,W,Q,O,ba,ca,U,R,X,Y,K,T,aa;k=o=q=0;j.autoUpdateMatrix&&j.updateMatrix();w.multiply(j.projectionMatrix,j.matrix);Q=this.projectObjects(n,j,true);n=0;for(p=Q.length;n<p;n++){O=Q[n].object;if(O.visible){O.autoUpdateMatrix&&O.updateMatrix();ba=O.matrix;ca=O.rotationMatrix;U=O.materials;R=O.overdraw;if(O instanceof
+THREE.Mesh){X=O.geometry;Y=X.vertices;F=0;for(M=Y.length;F<M;F++){K=Y[F];K.positionWorld.copy(K.position);ba.multiplyVector3(K.positionWorld);G=K.positionScreen;G.copy(K.positionWorld);w.multiplyVector4(G);G.x/=G.w;G.y/=G.w;K.__visible=G.z>E&&G.z<C}X=X.faces;F=0;for(M=X.length;F<M;F++){K=X[F];if(K instanceof THREE.Face3){G=Y[K.a];W=Y[K.b];T=Y[K.c];if(G.__visible&&W.__visible&&T.__visible)if(O.doubleSided||O.flipSided!=(T.positionScreen.x-G.positionScreen.x)*(W.positionScreen.y-G.positionScreen.y)-
+(T.positionScreen.y-G.positionScreen.y)*(W.positionScreen.x-G.positionScreen.x)<0){f=h[k]=h[k]||new THREE.RenderableFace3;f.v1.positionWorld.copy(G.positionWorld);f.v2.positionWorld.copy(W.positionWorld);f.v3.positionWorld.copy(T.positionWorld);f.v1.positionScreen.copy(G.positionScreen);f.v2.positionScreen.copy(W.positionScreen);f.v3.positionScreen.copy(T.positionScreen);f.normalWorld.copy(K.normal);ca.multiplyVector3(f.normalWorld);f.centroidWorld.copy(K.centroid);ba.multiplyVector3(f.centroidWorld);
+f.centroidScreen.copy(f.centroidWorld);w.multiplyVector3(f.centroidScreen);T=K.vertexNormals;A=f.vertexNormalsWorld;G=0;for(W=T.length;G<W;G++){aa=A[G]=A[G]||new THREE.Vector3;aa.copy(T[G]);ca.multiplyVector3(aa)}f.z=f.centroidScreen.z;f.meshMaterials=U;f.faceMaterials=K.materials;f.overdraw=R;if(O.geometry.uvs[F]){f.uvs[0]=O.geometry.uvs[F][0];f.uvs[1]=O.geometry.uvs[F][1];f.uvs[2]=O.geometry.uvs[F][2]}u.push(f);k++}}else if(K instanceof THREE.Face4){G=Y[K.a];W=Y[K.b];T=Y[K.c];aa=Y[K.d];if(G.__visible&&
+W.__visible&&T.__visible&&aa.__visible)if(O.doubleSided||O.flipSided!=((aa.positionScreen.x-G.positionScreen.x)*(W.positionScreen.y-G.positionScreen.y)-(aa.positionScreen.y-G.positionScreen.y)*(W.positionScreen.x-G.positionScreen.x)<0||(W.positionScreen.x-T.positionScreen.x)*(aa.positionScreen.y-T.positionScreen.y)-(W.positionScreen.y-T.positionScreen.y)*(aa.positionScreen.x-T.positionScreen.x)<0)){f=h[k]=h[k]||new THREE.RenderableFace3;f.v1.positionWorld.copy(G.positionWorld);f.v2.positionWorld.copy(W.positionWorld);
+f.v3.positionWorld.copy(aa.positionWorld);f.v1.positionScreen.copy(G.positionScreen);f.v2.positionScreen.copy(W.positionScreen);f.v3.positionScreen.copy(aa.positionScreen);f.normalWorld.copy(K.normal);ca.multiplyVector3(f.normalWorld);f.centroidWorld.copy(K.centroid);ba.multiplyVector3(f.centroidWorld);f.centroidScreen.copy(f.centroidWorld);w.multiplyVector3(f.centroidScreen);f.z=f.centroidScreen.z;f.meshMaterials=U;f.faceMaterials=K.materials;f.overdraw=R;if(O.geometry.uvs[F]){f.uvs[0]=O.geometry.uvs[F][0];
+f.uvs[1]=O.geometry.uvs[F][1];f.uvs[2]=O.geometry.uvs[F][3]}u.push(f);k++;b=h[k]=h[k]||new THREE.RenderableFace3;b.v1.positionWorld.copy(W.positionWorld);b.v2.positionWorld.copy(T.positionWorld);b.v3.positionWorld.copy(aa.positionWorld);b.v1.positionScreen.copy(W.positionScreen);b.v2.positionScreen.copy(T.positionScreen);b.v3.positionScreen.copy(aa.positionScreen);b.normalWorld.copy(f.normalWorld);b.centroidWorld.copy(f.centroidWorld);b.centroidScreen.copy(f.centroidScreen);b.z=b.centroidScreen.z;
+b.meshMaterials=U;b.faceMaterials=K.materials;b.overdraw=R;if(O.geometry.uvs[F]){b.uvs[0]=O.geometry.uvs[F][1];b.uvs[1]=O.geometry.uvs[F][2];b.uvs[2]=O.geometry.uvs[F][3]}u.push(b);k++}}}}else if(O instanceof THREE.Line){I.multiply(w,ba);Y=O.geometry.vertices;K=Y[0];K.positionScreen.copy(K.position);I.multiplyVector4(K.positionScreen);F=1;for(M=Y.length;F<M;F++){G=Y[F];G.positionScreen.copy(G.position);I.multiplyVector4(G.positionScreen);W=Y[F-1];L.copy(G.positionScreen);l.copy(W.positionScreen);
+if(c(L,l)){L.multiplyScalar(1/L.w);l.multiplyScalar(1/l.w);m=y[o]=y[o]||new THREE.RenderableLine;m.v1.positionScreen.copy(L);m.v2.positionScreen.copy(l);m.z=Math.max(L.z,l.z);m.materials=O.materials;u.push(m);o++}}}else if(O instanceof THREE.Particle){H.set(O.position.x,O.position.y,O.position.z,1);w.multiplyVector4(H);H.z/=H.w;if(H.z>0&&H.z<1){v=z[q]=z[q]||new THREE.RenderableParticle;v.x=H.x/H.w;v.y=H.y/H.w;v.z=H.z;v.rotation=O.rotation.z;v.scale.x=O.scale.x*Math.abs(v.x-(H.x+j.projectionMatrix.n11)/
+(H.w+j.projectionMatrix.n14));v.scale.y=O.scale.y*Math.abs(v.y-(H.y+j.projectionMatrix.n22)/(H.w+j.projectionMatrix.n24));v.materials=O.materials;u.push(v);q++}}}}x&&u.sort(a);return u};this.unprojectVector=function(n,j){var x=THREE.Matrix4.makeInvert(j.matrix);x.multiplySelf(THREE.Matrix4.makeInvert(j.projectionMatrix));x.multiplyVector3(n);return n}};
 THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,c=new THREE.Projector,d,e,g,f;this.domElement=document.createElement("div");this.setSize=function(b,k){d=b;e=k;g=d/2;f=e/2};this.render=function(b,k){var h,m,o,y,v,q,z,B;a=c.projectScene(b,k);h=0;for(m=a.length;h<m;h++){v=a[h];if(v instanceof THREE.RenderableParticle){z=v.x*g+g;B=v.y*f+f;o=0;for(y=v.material.length;o<y;o++){q=v.material[o];if(q instanceof THREE.ParticleDOMMaterial){q=q.domElement;q.style.left=z+"px";q.style.top=B+"px"}}}}}};
 THREE.CanvasRenderer=function(){function a(ka){if(v!=ka)m.globalAlpha=v=ka}function c(ka){if(q!=ka){switch(ka){case THREE.NormalBlending:m.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:m.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:m.globalCompositeOperation="darker"}q=ka}}var d=null,e=new THREE.Projector,g=document.createElement("canvas"),f,b,k,h,m=g.getContext("2d"),o=new THREE.Color(0),y=0,v=1,q=0,z=null,B=null,H=1,w,I,t,L,l,A,n,j,x,u=new THREE.Color,
-E=new THREE.Color,C=new THREE.Color,p=new THREE.Color,F=new THREE.Color,M,G,X,Q,P,ca,aa,T,R,W=new THREE.Rectangle,Y=new THREE.Rectangle,K=new THREE.Rectangle,U=false,ba=new THREE.Color,ja=new THREE.Color,ha=new THREE.Color,D=new THREE.Color,J=Math.PI*2,N=new THREE.Vector3,V,da,ga,ia,ta,qa,va=16;V=document.createElement("canvas");V.width=V.height=2;da=V.getContext("2d");da.fillStyle="rgba(0,0,0,1)";da.fillRect(0,0,2,2);ga=da.getImageData(0,0,2,2);ia=ga.data;ta=document.createElement("canvas");ta.width=
-ta.height=va;qa=ta.getContext("2d");qa.translate(-va/2,-va/2);qa.scale(va,va);va--;this.domElement=g;this.sortElements=this.sortObjects=this.autoClear=true;this.setSize=function(ka,ra){f=ka;b=ra;k=f/2;h=b/2;g.width=f;g.height=b;W.set(-k,-h,k,h);v=1;q=0;B=z=null;H=1};this.setClearColor=function(ka,ra){o=ka;y=ra;Y.set(-k,-h,k,h);m.setTransform(1,0,0,-1,k,h);this.clear()};this.setClearColorHex=function(ka,ra){o.setHex(ka);y=ra;Y.set(-k,-h,k,h);m.setTransform(1,0,0,-1,k,h);this.clear()};this.clear=function(){m.setTransform(1,
-0,0,-1,k,h);if(!Y.isEmpty()){Y.inflate(1);Y.minSelf(W);if(o.hex==0&&y==0)m.clearRect(Y.getX(),Y.getY(),Y.getWidth(),Y.getHeight());else{c(THREE.NormalBlending);a(1);m.fillStyle="rgba("+Math.floor(o.r*255)+","+Math.floor(o.g*255)+","+Math.floor(o.b*255)+","+y+")";m.fillRect(Y.getX(),Y.getY(),Y.getWidth(),Y.getHeight())}Y.empty()}};this.render=function(ka,ra){function oa(O){var ea,$,S,Z=O.lights;ja.setRGB(0,0,0);ha.setRGB(0,0,0);D.setRGB(0,0,0);O=0;for(ea=Z.length;O<ea;O++){$=Z[O];S=$.color;if($ instanceof
-THREE.AmbientLight){ja.r+=S.r;ja.g+=S.g;ja.b+=S.b}else if($ instanceof THREE.DirectionalLight){ha.r+=S.r;ha.g+=S.g;ha.b+=S.b}else if($ instanceof THREE.PointLight){D.r+=S.r;D.g+=S.g;D.b+=S.b}}}function Aa(O,ea,$,S){var Z,fa,ma,na,pa=O.lights;O=0;for(Z=pa.length;O<Z;O++){fa=pa[O];ma=fa.color;na=fa.intensity;if(fa instanceof THREE.DirectionalLight){fa=$.dot(fa.position)*na;if(fa>0){S.r+=ma.r*fa;S.g+=ma.g*fa;S.b+=ma.b*fa}}else if(fa instanceof THREE.PointLight){N.sub(fa.position,ea);N.normalize();fa=
-$.dot(N)*na;if(fa>0){S.r+=ma.r*fa;S.g+=ma.g*fa;S.b+=ma.b*fa}}}}function Ja(O,ea,$){if($.opacity!=0){a($.opacity);c($.blending);var S,Z,fa,ma,na,pa;if($ instanceof THREE.ParticleBasicMaterial){if($.map&&$.map.image.loaded){ma=$.map.image;na=ma.width>>1;pa=ma.height>>1;Z=ea.scale.x*k;fa=ea.scale.y*h;$=Z*na;S=fa*pa;K.set(O.x-$,O.y-S,O.x+$,O.y+S);if(W.instersects(K)){m.save();m.translate(O.x,O.y);m.rotate(-ea.rotation);m.scale(Z,-fa);m.translate(-na,-pa);m.drawImage(ma,0,0);m.restore()}}}else if($ instanceof
-THREE.ParticleCircleMaterial){if(U){ba.r=ja.r+ha.r+D.r;ba.g=ja.g+ha.g+D.g;ba.b=ja.b+ha.b+D.b;u.r=$.color.r*ba.r;u.g=$.color.g*ba.g;u.b=$.color.b*ba.b;u.updateStyleString()}else u.__styleString=$.color.__styleString;$=ea.scale.x*k;S=ea.scale.y*h;K.set(O.x-$,O.y-S,O.x+$,O.y+S);if(W.instersects(K)){Z=u.__styleString;if(B!=Z)m.fillStyle=B=Z;m.save();m.translate(O.x,O.y);m.rotate(-ea.rotation);m.scale($,S);m.beginPath();m.arc(0,0,1,0,J,true);m.closePath();m.fill();m.restore()}}}}function Ka(O,ea,$,S){if(S.opacity!=
-0){a(S.opacity);c(S.blending);m.beginPath();m.moveTo(O.positionScreen.x,O.positionScreen.y);m.lineTo(ea.positionScreen.x,ea.positionScreen.y);m.closePath();if(S instanceof THREE.LineBasicMaterial){u.__styleString=S.color.__styleString;O=S.linewidth;if(H!=O)m.lineWidth=H=O;O=u.__styleString;if(z!=O)m.strokeStyle=z=O;m.stroke();K.inflate(S.linewidth*2)}}}function Ga(O,ea,$,S,Z,fa){if(Z.opacity!=0){a(Z.opacity);c(Z.blending);L=O.positionScreen.x;l=O.positionScreen.y;A=ea.positionScreen.x;n=ea.positionScreen.y;
-j=$.positionScreen.x;x=$.positionScreen.y;m.beginPath();m.moveTo(L,l);m.lineTo(A,n);m.lineTo(j,x);m.lineTo(L,l);m.closePath();if(Z instanceof THREE.MeshBasicMaterial)if(Z.map)Z.map.image.loaded&&Z.map.mapping instanceof THREE.UVMapping&&Da(L,l,A,n,j,x,Z.map.image,S.uvs[0].u,S.uvs[0].v,S.uvs[1].u,S.uvs[1].v,S.uvs[2].u,S.uvs[2].v);else if(Z.env_map){if(Z.env_map.image.loaded)if(Z.env_map.mapping instanceof THREE.SphericalReflectionMapping){O=ra.matrix;N.copy(S.vertexNormalsWorld[0]);Q=(N.x*O.n11+N.y*
-O.n12+N.z*O.n13)*0.5+0.5;P=-(N.x*O.n21+N.y*O.n22+N.z*O.n23)*0.5+0.5;N.copy(S.vertexNormalsWorld[1]);ca=(N.x*O.n11+N.y*O.n12+N.z*O.n13)*0.5+0.5;aa=-(N.x*O.n21+N.y*O.n22+N.z*O.n23)*0.5+0.5;N.copy(S.vertexNormalsWorld[2]);T=(N.x*O.n11+N.y*O.n12+N.z*O.n13)*0.5+0.5;R=-(N.x*O.n21+N.y*O.n22+N.z*O.n23)*0.5+0.5;Da(L,l,A,n,j,x,Z.env_map.image,Q,P,ca,aa,T,R)}}else Z.wireframe?sa(Z.color.__styleString,Z.wireframe_linewidth):Ha(Z.color.__styleString);else if(Z instanceof THREE.MeshLambertMaterial){if(Z.map&&!Z.wireframe){Z.map.mapping instanceof
-THREE.UVMapping&&Da(L,l,A,n,j,x,Z.map.image,S.uvs[0].u,S.uvs[0].v,S.uvs[1].u,S.uvs[1].v,S.uvs[2].u,S.uvs[2].v);c(THREE.SubtractiveBlending)}if(U)if(!Z.wireframe&&Z.shading==THREE.SmoothShading&&S.vertexNormalsWorld.length==3){E.r=C.r=p.r=ja.r;E.g=C.g=p.g=ja.g;E.b=C.b=p.b=ja.b;Aa(fa,S.v1.positionWorld,S.vertexNormalsWorld[0],E);Aa(fa,S.v2.positionWorld,S.vertexNormalsWorld[1],C);Aa(fa,S.v3.positionWorld,S.vertexNormalsWorld[2],p);F.r=(C.r+p.r)*0.5;F.g=(C.g+p.g)*0.5;F.b=(C.b+p.b)*0.5;X=Pa(E,C,p,F);
-Da(L,l,A,n,j,x,X,0,0,1,0,0,1)}else{ba.r=ja.r;ba.g=ja.g;ba.b=ja.b;Aa(fa,S.centroidWorld,S.normalWorld,ba);u.r=Z.color.r*ba.r;u.g=Z.color.g*ba.g;u.b=Z.color.b*ba.b;u.updateStyleString();Z.wireframe?sa(u.__styleString,Z.wireframe_linewidth):Ha(u.__styleString)}else Z.wireframe?sa(Z.color.__styleString,Z.wireframe_linewidth):Ha(Z.color.__styleString)}else if(Z instanceof THREE.MeshDepthMaterial){M=ra.near;G=ra.far;E.r=E.g=E.b=1-La(O.positionScreen.z,M,G);C.r=C.g=C.b=1-La(ea.positionScreen.z,M,G);p.r=
-p.g=p.b=1-La($.positionScreen.z,M,G);F.r=(C.r+p.r)*0.5;F.g=(C.g+p.g)*0.5;F.b=(C.b+p.b)*0.5;X=Pa(E,C,p,F);Da(L,l,A,n,j,x,X,0,0,1,0,0,1)}else if(Z instanceof THREE.MeshNormalMaterial){u.r=Ma(S.normalWorld.x);u.g=Ma(S.normalWorld.y);u.b=Ma(S.normalWorld.z);u.updateStyleString();Z.wireframe?sa(u.__styleString,Z.wireframe_linewidth):Ha(u.__styleString)}}}function sa(O,ea){if(z!=O)m.strokeStyle=z=O;if(H!=ea)m.lineWidth=H=ea;m.stroke();K.inflate(ea*2)}function Ha(O){if(B!=O)m.fillStyle=B=O;m.fill()}function Da(O,
-ea,$,S,Z,fa,ma,na,pa,xa,ua,ya,Ea){var Ba,za;Ba=ma.width-1;za=ma.height-1;na*=Ba;pa*=za;xa*=Ba;ua*=za;ya*=Ba;Ea*=za;$-=O;S-=ea;Z-=O;fa-=ea;xa-=na;ua-=pa;ya-=na;Ea-=pa;za=1/(xa*Ea-ya*ua);Ba=(Ea*$-ua*Z)*za;ua=(Ea*S-ua*fa)*za;$=(xa*Z-ya*$)*za;S=(xa*fa-ya*S)*za;O=O-Ba*na-$*pa;ea=ea-ua*na-S*pa;m.save();m.transform(Ba,ua,$,S,O,ea);m.clip();m.drawImage(ma,0,0);m.restore()}function Pa(O,ea,$,S){var Z=~~(O.r*255),fa=~~(O.g*255);O=~~(O.b*255);var ma=~~(ea.r*255),na=~~(ea.g*255);ea=~~(ea.b*255);var pa=~~($.r*
-255),xa=~~($.g*255);$=~~($.b*255);var ua=~~(S.r*255),ya=~~(S.g*255);S=~~(S.b*255);ia[0]=Z<0?0:Z>255?255:Z;ia[1]=fa<0?0:fa>255?255:fa;ia[2]=O<0?0:O>255?255:O;ia[4]=ma<0?0:ma>255?255:ma;ia[5]=na<0?0:na>255?255:na;ia[6]=ea<0?0:ea>255?255:ea;ia[8]=pa<0?0:pa>255?255:pa;ia[9]=xa<0?0:xa>255?255:xa;ia[10]=$<0?0:$>255?255:$;ia[12]=ua<0?0:ua>255?255:ua;ia[13]=ya<0?0:ya>255?255:ya;ia[14]=S<0?0:S>255?255:S;da.putImageData(ga,0,0);qa.drawImage(V,0,0);return ta}function La(O,ea,$){O=(O-ea)/($-ea);return O*O*(3-
-2*O)}function Ma(O){O=(O+1)*0.5;return O<0?0:O>1?1:O}function Na(O,ea){var $=ea.x-O.x,S=ea.y-O.y,Z=1/Math.sqrt($*$+S*S);$*=Z;S*=Z;ea.x+=$;ea.y+=S;O.x-=$;O.y-=S}var Ia,Qa,la,wa,Ca,Oa,Ra,Fa;this.autoClear?this.clear():m.setTransform(1,0,0,-1,k,h);d=e.projectScene(ka,ra,this.sortElements);(U=ka.lights.length>0)&&oa(ka);Ia=0;for(Qa=d.length;Ia<Qa;Ia++){la=d[Ia];K.empty();if(la instanceof THREE.RenderableParticle){w=la;w.x*=k;w.y*=h;wa=0;for(Ca=la.materials.length;wa<Ca;wa++)Ja(w,la,la.materials[wa],ka)}else if(la instanceof
-THREE.RenderableLine){w=la.v1;I=la.v2;w.positionScreen.x*=k;w.positionScreen.y*=h;I.positionScreen.x*=k;I.positionScreen.y*=h;K.addPoint(w.positionScreen.x,w.positionScreen.y);K.addPoint(I.positionScreen.x,I.positionScreen.y);if(W.instersects(K)){wa=0;for(Ca=la.materials.length;wa<Ca;)Ka(w,I,la,la.materials[wa++],ka)}}else if(la instanceof THREE.RenderableFace3){w=la.v1;I=la.v2;t=la.v3;w.positionScreen.x*=k;w.positionScreen.y*=h;I.positionScreen.x*=k;I.positionScreen.y*=h;t.positionScreen.x*=k;t.positionScreen.y*=
-h;if(la.overdraw){Na(w.positionScreen,I.positionScreen);Na(I.positionScreen,t.positionScreen);Na(t.positionScreen,w.positionScreen)}K.add3Points(w.positionScreen.x,w.positionScreen.y,I.positionScreen.x,I.positionScreen.y,t.positionScreen.x,t.positionScreen.y);if(W.instersects(K)){wa=0;for(Ca=la.meshMaterials.length;wa<Ca;){Fa=la.meshMaterials[wa++];if(Fa instanceof THREE.MeshFaceMaterial){Oa=0;for(Ra=la.faceMaterials.length;Oa<Ra;)(Fa=la.faceMaterials[Oa++])&&Ga(w,I,t,la,Fa,ka)}else Ga(w,I,t,la,Fa,
+E=new THREE.Color,C=new THREE.Color,p=new THREE.Color,F=new THREE.Color,M,G,W,Q,O,ba,ca,U,R,X=new THREE.Rectangle,Y=new THREE.Rectangle,K=new THREE.Rectangle,T=false,aa=new THREE.Color,ja=new THREE.Color,ha=new THREE.Color,D=new THREE.Color,J=Math.PI*2,N=new THREE.Vector3,V,da,ga,ia,ta,qa,va=16;V=document.createElement("canvas");V.width=V.height=2;da=V.getContext("2d");da.fillStyle="rgba(0,0,0,1)";da.fillRect(0,0,2,2);ga=da.getImageData(0,0,2,2);ia=ga.data;ta=document.createElement("canvas");ta.width=
+ta.height=va;qa=ta.getContext("2d");qa.translate(-va/2,-va/2);qa.scale(va,va);va--;this.domElement=g;this.sortElements=this.sortObjects=this.autoClear=true;this.setSize=function(ka,ra){f=ka;b=ra;k=f/2;h=b/2;g.width=f;g.height=b;X.set(-k,-h,k,h);v=1;q=0;B=z=null;H=1};this.setClearColor=function(ka,ra){o=ka;y=ra;Y.set(-k,-h,k,h);m.setTransform(1,0,0,-1,k,h);this.clear()};this.setClearColorHex=function(ka,ra){o.setHex(ka);y=ra;Y.set(-k,-h,k,h);m.setTransform(1,0,0,-1,k,h);this.clear()};this.clear=function(){m.setTransform(1,
+0,0,-1,k,h);if(!Y.isEmpty()){Y.inflate(1);Y.minSelf(X);if(o.hex==0&&y==0)m.clearRect(Y.getX(),Y.getY(),Y.getWidth(),Y.getHeight());else{c(THREE.NormalBlending);a(1);m.fillStyle="rgba("+Math.floor(o.r*255)+","+Math.floor(o.g*255)+","+Math.floor(o.b*255)+","+y+")";m.fillRect(Y.getX(),Y.getY(),Y.getWidth(),Y.getHeight())}Y.empty()}};this.render=function(ka,ra){function oa(P){var ea,$,S,Z=P.lights;ja.setRGB(0,0,0);ha.setRGB(0,0,0);D.setRGB(0,0,0);P=0;for(ea=Z.length;P<ea;P++){$=Z[P];S=$.color;if($ instanceof
+THREE.AmbientLight){ja.r+=S.r;ja.g+=S.g;ja.b+=S.b}else if($ instanceof THREE.DirectionalLight){ha.r+=S.r;ha.g+=S.g;ha.b+=S.b}else if($ instanceof THREE.PointLight){D.r+=S.r;D.g+=S.g;D.b+=S.b}}}function Aa(P,ea,$,S){var Z,fa,ma,na,pa=P.lights;P=0;for(Z=pa.length;P<Z;P++){fa=pa[P];ma=fa.color;na=fa.intensity;if(fa instanceof THREE.DirectionalLight){fa=$.dot(fa.position)*na;if(fa>0){S.r+=ma.r*fa;S.g+=ma.g*fa;S.b+=ma.b*fa}}else if(fa instanceof THREE.PointLight){N.sub(fa.position,ea);N.normalize();fa=
+$.dot(N)*na;if(fa>0){S.r+=ma.r*fa;S.g+=ma.g*fa;S.b+=ma.b*fa}}}}function Ja(P,ea,$){if($.opacity!=0){a($.opacity);c($.blending);var S,Z,fa,ma,na,pa;if($ instanceof THREE.ParticleBasicMaterial){if($.map&&$.map.image.loaded){ma=$.map.image;na=ma.width>>1;pa=ma.height>>1;Z=ea.scale.x*k;fa=ea.scale.y*h;$=Z*na;S=fa*pa;K.set(P.x-$,P.y-S,P.x+$,P.y+S);if(X.instersects(K)){m.save();m.translate(P.x,P.y);m.rotate(-ea.rotation);m.scale(Z,-fa);m.translate(-na,-pa);m.drawImage(ma,0,0);m.restore()}}}else if($ instanceof
+THREE.ParticleCircleMaterial){if(T){aa.r=ja.r+ha.r+D.r;aa.g=ja.g+ha.g+D.g;aa.b=ja.b+ha.b+D.b;u.r=$.color.r*aa.r;u.g=$.color.g*aa.g;u.b=$.color.b*aa.b;u.updateStyleString()}else u.__styleString=$.color.__styleString;$=ea.scale.x*k;S=ea.scale.y*h;K.set(P.x-$,P.y-S,P.x+$,P.y+S);if(X.instersects(K)){Z=u.__styleString;if(B!=Z)m.fillStyle=B=Z;m.save();m.translate(P.x,P.y);m.rotate(-ea.rotation);m.scale($,S);m.beginPath();m.arc(0,0,1,0,J,true);m.closePath();m.fill();m.restore()}}}}function Ka(P,ea,$,S){if(S.opacity!=
+0){a(S.opacity);c(S.blending);m.beginPath();m.moveTo(P.positionScreen.x,P.positionScreen.y);m.lineTo(ea.positionScreen.x,ea.positionScreen.y);m.closePath();if(S instanceof THREE.LineBasicMaterial){u.__styleString=S.color.__styleString;P=S.linewidth;if(H!=P)m.lineWidth=H=P;P=u.__styleString;if(z!=P)m.strokeStyle=z=P;m.stroke();K.inflate(S.linewidth*2)}}}function Ga(P,ea,$,S,Z,fa){if(Z.opacity!=0){a(Z.opacity);c(Z.blending);L=P.positionScreen.x;l=P.positionScreen.y;A=ea.positionScreen.x;n=ea.positionScreen.y;
+j=$.positionScreen.x;x=$.positionScreen.y;m.beginPath();m.moveTo(L,l);m.lineTo(A,n);m.lineTo(j,x);m.lineTo(L,l);m.closePath();if(Z instanceof THREE.MeshBasicMaterial)if(Z.map)Z.map.image.loaded&&Z.map.mapping instanceof THREE.UVMapping&&Da(L,l,A,n,j,x,Z.map.image,S.uvs[0].u,S.uvs[0].v,S.uvs[1].u,S.uvs[1].v,S.uvs[2].u,S.uvs[2].v);else if(Z.env_map){if(Z.env_map.image.loaded)if(Z.env_map.mapping instanceof THREE.SphericalReflectionMapping){P=ra.matrix;N.copy(S.vertexNormalsWorld[0]);Q=(N.x*P.n11+N.y*
+P.n12+N.z*P.n13)*0.5+0.5;O=-(N.x*P.n21+N.y*P.n22+N.z*P.n23)*0.5+0.5;N.copy(S.vertexNormalsWorld[1]);ba=(N.x*P.n11+N.y*P.n12+N.z*P.n13)*0.5+0.5;ca=-(N.x*P.n21+N.y*P.n22+N.z*P.n23)*0.5+0.5;N.copy(S.vertexNormalsWorld[2]);U=(N.x*P.n11+N.y*P.n12+N.z*P.n13)*0.5+0.5;R=-(N.x*P.n21+N.y*P.n22+N.z*P.n23)*0.5+0.5;Da(L,l,A,n,j,x,Z.env_map.image,Q,O,ba,ca,U,R)}}else Z.wireframe?sa(Z.color.__styleString,Z.wireframe_linewidth):Ha(Z.color.__styleString);else if(Z instanceof THREE.MeshLambertMaterial){if(Z.map&&!Z.wireframe){Z.map.mapping instanceof
+THREE.UVMapping&&Da(L,l,A,n,j,x,Z.map.image,S.uvs[0].u,S.uvs[0].v,S.uvs[1].u,S.uvs[1].v,S.uvs[2].u,S.uvs[2].v);c(THREE.SubtractiveBlending)}if(T)if(!Z.wireframe&&Z.shading==THREE.SmoothShading&&S.vertexNormalsWorld.length==3){E.r=C.r=p.r=ja.r;E.g=C.g=p.g=ja.g;E.b=C.b=p.b=ja.b;Aa(fa,S.v1.positionWorld,S.vertexNormalsWorld[0],E);Aa(fa,S.v2.positionWorld,S.vertexNormalsWorld[1],C);Aa(fa,S.v3.positionWorld,S.vertexNormalsWorld[2],p);F.r=(C.r+p.r)*0.5;F.g=(C.g+p.g)*0.5;F.b=(C.b+p.b)*0.5;W=Pa(E,C,p,F);
+Da(L,l,A,n,j,x,W,0,0,1,0,0,1)}else{aa.r=ja.r;aa.g=ja.g;aa.b=ja.b;Aa(fa,S.centroidWorld,S.normalWorld,aa);u.r=Z.color.r*aa.r;u.g=Z.color.g*aa.g;u.b=Z.color.b*aa.b;u.updateStyleString();Z.wireframe?sa(u.__styleString,Z.wireframe_linewidth):Ha(u.__styleString)}else Z.wireframe?sa(Z.color.__styleString,Z.wireframe_linewidth):Ha(Z.color.__styleString)}else if(Z instanceof THREE.MeshDepthMaterial){M=ra.near;G=ra.far;E.r=E.g=E.b=1-La(P.positionScreen.z,M,G);C.r=C.g=C.b=1-La(ea.positionScreen.z,M,G);p.r=
+p.g=p.b=1-La($.positionScreen.z,M,G);F.r=(C.r+p.r)*0.5;F.g=(C.g+p.g)*0.5;F.b=(C.b+p.b)*0.5;W=Pa(E,C,p,F);Da(L,l,A,n,j,x,W,0,0,1,0,0,1)}else if(Z instanceof THREE.MeshNormalMaterial){u.r=Ma(S.normalWorld.x);u.g=Ma(S.normalWorld.y);u.b=Ma(S.normalWorld.z);u.updateStyleString();Z.wireframe?sa(u.__styleString,Z.wireframe_linewidth):Ha(u.__styleString)}}}function sa(P,ea){if(z!=P)m.strokeStyle=z=P;if(H!=ea)m.lineWidth=H=ea;m.stroke();K.inflate(ea*2)}function Ha(P){if(B!=P)m.fillStyle=B=P;m.fill()}function Da(P,
+ea,$,S,Z,fa,ma,na,pa,xa,ua,ya,Ea){var Ba,za;Ba=ma.width-1;za=ma.height-1;na*=Ba;pa*=za;xa*=Ba;ua*=za;ya*=Ba;Ea*=za;$-=P;S-=ea;Z-=P;fa-=ea;xa-=na;ua-=pa;ya-=na;Ea-=pa;za=1/(xa*Ea-ya*ua);Ba=(Ea*$-ua*Z)*za;ua=(Ea*S-ua*fa)*za;$=(xa*Z-ya*$)*za;S=(xa*fa-ya*S)*za;P=P-Ba*na-$*pa;ea=ea-ua*na-S*pa;m.save();m.transform(Ba,ua,$,S,P,ea);m.clip();m.drawImage(ma,0,0);m.restore()}function Pa(P,ea,$,S){var Z=~~(P.r*255),fa=~~(P.g*255);P=~~(P.b*255);var ma=~~(ea.r*255),na=~~(ea.g*255);ea=~~(ea.b*255);var pa=~~($.r*
+255),xa=~~($.g*255);$=~~($.b*255);var ua=~~(S.r*255),ya=~~(S.g*255);S=~~(S.b*255);ia[0]=Z<0?0:Z>255?255:Z;ia[1]=fa<0?0:fa>255?255:fa;ia[2]=P<0?0:P>255?255:P;ia[4]=ma<0?0:ma>255?255:ma;ia[5]=na<0?0:na>255?255:na;ia[6]=ea<0?0:ea>255?255:ea;ia[8]=pa<0?0:pa>255?255:pa;ia[9]=xa<0?0:xa>255?255:xa;ia[10]=$<0?0:$>255?255:$;ia[12]=ua<0?0:ua>255?255:ua;ia[13]=ya<0?0:ya>255?255:ya;ia[14]=S<0?0:S>255?255:S;da.putImageData(ga,0,0);qa.drawImage(V,0,0);return ta}function La(P,ea,$){P=(P-ea)/($-ea);return P*P*(3-
+2*P)}function Ma(P){P=(P+1)*0.5;return P<0?0:P>1?1:P}function Na(P,ea){var $=ea.x-P.x,S=ea.y-P.y,Z=1/Math.sqrt($*$+S*S);$*=Z;S*=Z;ea.x+=$;ea.y+=S;P.x-=$;P.y-=S}var Ia,Qa,la,wa,Ca,Oa,Ra,Fa;this.autoClear?this.clear():m.setTransform(1,0,0,-1,k,h);d=e.projectScene(ka,ra,this.sortElements);(T=ka.lights.length>0)&&oa(ka);Ia=0;for(Qa=d.length;Ia<Qa;Ia++){la=d[Ia];K.empty();if(la instanceof THREE.RenderableParticle){w=la;w.x*=k;w.y*=h;wa=0;for(Ca=la.materials.length;wa<Ca;wa++)Ja(w,la,la.materials[wa],ka)}else if(la instanceof
+THREE.RenderableLine){w=la.v1;I=la.v2;w.positionScreen.x*=k;w.positionScreen.y*=h;I.positionScreen.x*=k;I.positionScreen.y*=h;K.addPoint(w.positionScreen.x,w.positionScreen.y);K.addPoint(I.positionScreen.x,I.positionScreen.y);if(X.instersects(K)){wa=0;for(Ca=la.materials.length;wa<Ca;)Ka(w,I,la,la.materials[wa++],ka)}}else if(la instanceof THREE.RenderableFace3){w=la.v1;I=la.v2;t=la.v3;w.positionScreen.x*=k;w.positionScreen.y*=h;I.positionScreen.x*=k;I.positionScreen.y*=h;t.positionScreen.x*=k;t.positionScreen.y*=
+h;if(la.overdraw){Na(w.positionScreen,I.positionScreen);Na(I.positionScreen,t.positionScreen);Na(t.positionScreen,w.positionScreen)}K.add3Points(w.positionScreen.x,w.positionScreen.y,I.positionScreen.x,I.positionScreen.y,t.positionScreen.x,t.positionScreen.y);if(X.instersects(K)){wa=0;for(Ca=la.meshMaterials.length;wa<Ca;){Fa=la.meshMaterials[wa++];if(Fa instanceof THREE.MeshFaceMaterial){Oa=0;for(Ra=la.faceMaterials.length;Oa<Ra;)(Fa=la.faceMaterials[Oa++])&&Ga(w,I,t,la,Fa,ka)}else Ga(w,I,t,la,Fa,
 ka)}}}Y.addRectangle(K)}m.setTransform(1,0,0,1,0,0)}};
-THREE.SVGRenderer=function(){function a(Q,P,ca){var aa,T,R,W;aa=0;for(T=Q.lights.length;aa<T;aa++){R=Q.lights[aa];if(R instanceof THREE.DirectionalLight){W=P.normalWorld.dot(R.position)*R.intensity;if(W>0){ca.r+=R.color.r*W;ca.g+=R.color.g*W;ca.b+=R.color.b*W}}else if(R instanceof THREE.PointLight){x.sub(R.position,P.centroidWorld);x.normalize();W=P.normalWorld.dot(x)*R.intensity;if(W>0){ca.r+=R.color.r*W;ca.g+=R.color.g*W;ca.b+=R.color.b*W}}}}function c(Q,P,ca,aa,T,R){p=e(F++);p.setAttribute("d",
-"M "+Q.positionScreen.x+" "+Q.positionScreen.y+" L "+P.positionScreen.x+" "+P.positionScreen.y+" L "+ca.positionScreen.x+","+ca.positionScreen.y+"z");if(T instanceof THREE.MeshBasicMaterial)t.__styleString=T.color.__styleString;else if(T instanceof THREE.MeshLambertMaterial)if(I){L.r=l.r;L.g=l.g;L.b=l.b;a(R,aa,L);t.r=T.color.r*L.r;t.g=T.color.g*L.g;t.b=T.color.b*L.b;t.updateStyleString()}else t.__styleString=T.color.__styleString;else if(T instanceof THREE.MeshDepthMaterial){j=1-T.__2near/(T.__farPlusNear-
-aa.z*T.__farMinusNear);t.setRGB(j,j,j)}else T instanceof THREE.MeshNormalMaterial&&t.setRGB(g(aa.normalWorld.x),g(aa.normalWorld.y),g(aa.normalWorld.z));T.wireframe?p.setAttribute("style","fill: none; stroke: "+t.__styleString+"; stroke-width: "+T.wireframe_linewidth+"; stroke-opacity: "+T.opacity+"; stroke-linecap: "+T.wireframe_linecap+"; stroke-linejoin: "+T.wireframe_linejoin):p.setAttribute("style","fill: "+t.__styleString+"; fill-opacity: "+T.opacity);k.appendChild(p)}function d(Q,P,ca,aa,T,
-R,W){p=e(F++);p.setAttribute("d","M "+Q.positionScreen.x+" "+Q.positionScreen.y+" L "+P.positionScreen.x+" "+P.positionScreen.y+" L "+ca.positionScreen.x+","+ca.positionScreen.y+" L "+aa.positionScreen.x+","+aa.positionScreen.y+"z");if(R instanceof THREE.MeshBasicMaterial)t.__styleString=R.color.__styleString;else if(R instanceof THREE.MeshLambertMaterial)if(I){L.r=l.r;L.g=l.g;L.b=l.b;a(W,T,L);t.r=R.color.r*L.r;t.g=R.color.g*L.g;t.b=R.color.b*L.b;t.updateStyleString()}else t.__styleString=R.color.__styleString;
-else if(R instanceof THREE.MeshDepthMaterial){j=1-R.__2near/(R.__farPlusNear-T.z*R.__farMinusNear);t.setRGB(j,j,j)}else R instanceof THREE.MeshNormalMaterial&&t.setRGB(g(T.normalWorld.x),g(T.normalWorld.y),g(T.normalWorld.z));R.wireframe?p.setAttribute("style","fill: none; stroke: "+t.__styleString+"; stroke-width: "+R.wireframe_linewidth+"; stroke-opacity: "+R.opacity+"; stroke-linecap: "+R.wireframe_linecap+"; stroke-linejoin: "+R.wireframe_linejoin):p.setAttribute("style","fill: "+t.__styleString+
-"; fill-opacity: "+R.opacity);k.appendChild(p)}function e(Q){if(u[Q]==null){u[Q]=document.createElementNS("http://www.w3.org/2000/svg","path");X==0&&u[Q].setAttribute("shape-rendering","crispEdges");return u[Q]}return u[Q]}function g(Q){return Q<0?Math.min((1+Q)*0.5,0.5):0.5+Math.min(Q*0.5,0.5)}var f=null,b=new THREE.Projector,k=document.createElementNS("http://www.w3.org/2000/svg","svg"),h,m,o,y,v,q,z,B,H=new THREE.Rectangle,w=new THREE.Rectangle,I=false,t=new THREE.Color(16777215),L=new THREE.Color(16777215),
-l=new THREE.Color(0),A=new THREE.Color(0),n=new THREE.Color(0),j,x=new THREE.Vector3,u=[],E=[],C=[],p,F,M,G,X=1;this.domElement=k;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(Q){switch(Q){case "high":X=1;break;case "low":X=0}};this.setSize=function(Q,P){h=Q;m=P;o=h/2;y=m/2;k.setAttribute("viewBox",-o+" "+-y+" "+h+" "+m);k.setAttribute("width",h);k.setAttribute("height",m);H.set(-o,-y,o,y)};this.clear=function(){for(;k.childNodes.length>0;)k.removeChild(k.childNodes[0])};
-this.render=function(Q,P){var ca,aa,T,R,W,Y,K,U;this.autoClear&&this.clear();f=b.projectScene(Q,P,this.sortElements);G=M=F=0;if(I=Q.lights.length>0){K=Q.lights;l.setRGB(0,0,0);A.setRGB(0,0,0);n.setRGB(0,0,0);ca=0;for(aa=K.length;ca<aa;ca++){T=K[ca];R=T.color;if(T instanceof THREE.AmbientLight){l.r+=R.r;l.g+=R.g;l.b+=R.b}else if(T instanceof THREE.DirectionalLight){A.r+=R.r;A.g+=R.g;A.b+=R.b}else if(T instanceof THREE.PointLight){n.r+=R.r;n.g+=R.g;n.b+=R.b}}}ca=0;for(aa=f.length;ca<aa;ca++){K=f[ca];
-w.empty();if(K instanceof THREE.RenderableParticle){v=K;v.x*=o;v.y*=-y;T=0;for(R=K.materials.length;T<R;T++)if(U=K.materials[T]){W=v;Y=K;U=U;var ba=M++;if(E[ba]==null){E[ba]=document.createElementNS("http://www.w3.org/2000/svg","circle");X==0&&E[ba].setAttribute("shape-rendering","crispEdges")}p=E[ba];p.setAttribute("cx",W.x);p.setAttribute("cy",W.y);p.setAttribute("r",Y.scale.x*o);if(U instanceof THREE.ParticleCircleMaterial){if(I){L.r=l.r+A.r+n.r;L.g=l.g+A.g+n.g;L.b=l.b+A.b+n.b;t.r=U.color.r*L.r;
-t.g=U.color.g*L.g;t.b=U.color.b*L.b;t.updateStyleString()}else t=U.color;p.setAttribute("style","fill: "+t.__styleString)}k.appendChild(p)}}else if(K instanceof THREE.RenderableLine){v=K.v1;q=K.v2;v.positionScreen.x*=o;v.positionScreen.y*=-y;q.positionScreen.x*=o;q.positionScreen.y*=-y;w.addPoint(v.positionScreen.x,v.positionScreen.y);w.addPoint(q.positionScreen.x,q.positionScreen.y);if(H.instersects(w)){T=0;for(R=K.materials.length;T<R;)if(U=K.materials[T++]){W=v;Y=q;U=U;ba=G++;if(C[ba]==null){C[ba]=
-document.createElementNS("http://www.w3.org/2000/svg","line");X==0&&C[ba].setAttribute("shape-rendering","crispEdges")}p=C[ba];p.setAttribute("x1",W.positionScreen.x);p.setAttribute("y1",W.positionScreen.y);p.setAttribute("x2",Y.positionScreen.x);p.setAttribute("y2",Y.positionScreen.y);if(U instanceof THREE.LineBasicMaterial){t.__styleString=U.color.__styleString;p.setAttribute("style","fill: none; stroke: "+t.__styleString+"; stroke-width: "+U.linewidth+"; stroke-opacity: "+U.opacity+"; stroke-linecap: "+
-U.linecap+"; stroke-linejoin: "+U.linejoin);k.appendChild(p)}}}}else if(K instanceof THREE.RenderableFace3){v=K.v1;q=K.v2;z=K.v3;v.positionScreen.x*=o;v.positionScreen.y*=-y;q.positionScreen.x*=o;q.positionScreen.y*=-y;z.positionScreen.x*=o;z.positionScreen.y*=-y;w.addPoint(v.positionScreen.x,v.positionScreen.y);w.addPoint(q.positionScreen.x,q.positionScreen.y);w.addPoint(z.positionScreen.x,z.positionScreen.y);if(H.instersects(w)){T=0;for(R=K.meshMaterials.length;T<R;){U=K.meshMaterials[T++];if(U instanceof
-THREE.MeshFaceMaterial){W=0;for(Y=K.faceMaterials.length;W<Y;)(U=K.faceMaterials[W++])&&c(v,q,z,K,U,Q)}else U&&c(v,q,z,K,U,Q)}}}else if(K instanceof THREE.RenderableFace4){v=K.v1;q=K.v2;z=K.v3;B=K.v4;v.positionScreen.x*=o;v.positionScreen.y*=-y;q.positionScreen.x*=o;q.positionScreen.y*=-y;z.positionScreen.x*=o;z.positionScreen.y*=-y;B.positionScreen.x*=o;B.positionScreen.y*=-y;w.addPoint(v.positionScreen.x,v.positionScreen.y);w.addPoint(q.positionScreen.x,q.positionScreen.y);w.addPoint(z.positionScreen.x,
-z.positionScreen.y);w.addPoint(B.positionScreen.x,B.positionScreen.y);if(H.instersects(w)){T=0;for(R=K.meshMaterials.length;T<R;){U=K.meshMaterials[T++];if(U instanceof THREE.MeshFaceMaterial){W=0;for(Y=K.faceMaterials.length;W<Y;)(U=K.faceMaterials[W++])&&d(v,q,z,B,K,U,Q)}else U&&d(v,q,z,B,K,U,Q)}}}}}};
+THREE.SVGRenderer=function(){function a(Q,O,ba){var ca,U,R,X;ca=0;for(U=Q.lights.length;ca<U;ca++){R=Q.lights[ca];if(R instanceof THREE.DirectionalLight){X=O.normalWorld.dot(R.position)*R.intensity;if(X>0){ba.r+=R.color.r*X;ba.g+=R.color.g*X;ba.b+=R.color.b*X}}else if(R instanceof THREE.PointLight){x.sub(R.position,O.centroidWorld);x.normalize();X=O.normalWorld.dot(x)*R.intensity;if(X>0){ba.r+=R.color.r*X;ba.g+=R.color.g*X;ba.b+=R.color.b*X}}}}function c(Q,O,ba,ca,U,R){p=e(F++);p.setAttribute("d",
+"M "+Q.positionScreen.x+" "+Q.positionScreen.y+" L "+O.positionScreen.x+" "+O.positionScreen.y+" L "+ba.positionScreen.x+","+ba.positionScreen.y+"z");if(U instanceof THREE.MeshBasicMaterial)t.__styleString=U.color.__styleString;else if(U instanceof THREE.MeshLambertMaterial)if(I){L.r=l.r;L.g=l.g;L.b=l.b;a(R,ca,L);t.r=U.color.r*L.r;t.g=U.color.g*L.g;t.b=U.color.b*L.b;t.updateStyleString()}else t.__styleString=U.color.__styleString;else if(U instanceof THREE.MeshDepthMaterial){j=1-U.__2near/(U.__farPlusNear-
+ca.z*U.__farMinusNear);t.setRGB(j,j,j)}else U instanceof THREE.MeshNormalMaterial&&t.setRGB(g(ca.normalWorld.x),g(ca.normalWorld.y),g(ca.normalWorld.z));U.wireframe?p.setAttribute("style","fill: none; stroke: "+t.__styleString+"; stroke-width: "+U.wireframe_linewidth+"; stroke-opacity: "+U.opacity+"; stroke-linecap: "+U.wireframe_linecap+"; stroke-linejoin: "+U.wireframe_linejoin):p.setAttribute("style","fill: "+t.__styleString+"; fill-opacity: "+U.opacity);k.appendChild(p)}function d(Q,O,ba,ca,U,
+R,X){p=e(F++);p.setAttribute("d","M "+Q.positionScreen.x+" "+Q.positionScreen.y+" L "+O.positionScreen.x+" "+O.positionScreen.y+" L "+ba.positionScreen.x+","+ba.positionScreen.y+" L "+ca.positionScreen.x+","+ca.positionScreen.y+"z");if(R instanceof THREE.MeshBasicMaterial)t.__styleString=R.color.__styleString;else if(R instanceof THREE.MeshLambertMaterial)if(I){L.r=l.r;L.g=l.g;L.b=l.b;a(X,U,L);t.r=R.color.r*L.r;t.g=R.color.g*L.g;t.b=R.color.b*L.b;t.updateStyleString()}else t.__styleString=R.color.__styleString;
+else if(R instanceof THREE.MeshDepthMaterial){j=1-R.__2near/(R.__farPlusNear-U.z*R.__farMinusNear);t.setRGB(j,j,j)}else R instanceof THREE.MeshNormalMaterial&&t.setRGB(g(U.normalWorld.x),g(U.normalWorld.y),g(U.normalWorld.z));R.wireframe?p.setAttribute("style","fill: none; stroke: "+t.__styleString+"; stroke-width: "+R.wireframe_linewidth+"; stroke-opacity: "+R.opacity+"; stroke-linecap: "+R.wireframe_linecap+"; stroke-linejoin: "+R.wireframe_linejoin):p.setAttribute("style","fill: "+t.__styleString+
+"; fill-opacity: "+R.opacity);k.appendChild(p)}function e(Q){if(u[Q]==null){u[Q]=document.createElementNS("http://www.w3.org/2000/svg","path");W==0&&u[Q].setAttribute("shape-rendering","crispEdges");return u[Q]}return u[Q]}function g(Q){return Q<0?Math.min((1+Q)*0.5,0.5):0.5+Math.min(Q*0.5,0.5)}var f=null,b=new THREE.Projector,k=document.createElementNS("http://www.w3.org/2000/svg","svg"),h,m,o,y,v,q,z,B,H=new THREE.Rectangle,w=new THREE.Rectangle,I=false,t=new THREE.Color(16777215),L=new THREE.Color(16777215),
+l=new THREE.Color(0),A=new THREE.Color(0),n=new THREE.Color(0),j,x=new THREE.Vector3,u=[],E=[],C=[],p,F,M,G,W=1;this.domElement=k;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(Q){switch(Q){case "high":W=1;break;case "low":W=0}};this.setSize=function(Q,O){h=Q;m=O;o=h/2;y=m/2;k.setAttribute("viewBox",-o+" "+-y+" "+h+" "+m);k.setAttribute("width",h);k.setAttribute("height",m);H.set(-o,-y,o,y)};this.clear=function(){for(;k.childNodes.length>0;)k.removeChild(k.childNodes[0])};
+this.render=function(Q,O){var ba,ca,U,R,X,Y,K,T;this.autoClear&&this.clear();f=b.projectScene(Q,O,this.sortElements);G=M=F=0;if(I=Q.lights.length>0){K=Q.lights;l.setRGB(0,0,0);A.setRGB(0,0,0);n.setRGB(0,0,0);ba=0;for(ca=K.length;ba<ca;ba++){U=K[ba];R=U.color;if(U instanceof THREE.AmbientLight){l.r+=R.r;l.g+=R.g;l.b+=R.b}else if(U instanceof THREE.DirectionalLight){A.r+=R.r;A.g+=R.g;A.b+=R.b}else if(U instanceof THREE.PointLight){n.r+=R.r;n.g+=R.g;n.b+=R.b}}}ba=0;for(ca=f.length;ba<ca;ba++){K=f[ba];
+w.empty();if(K instanceof THREE.RenderableParticle){v=K;v.x*=o;v.y*=-y;U=0;for(R=K.materials.length;U<R;U++)if(T=K.materials[U]){X=v;Y=K;T=T;var aa=M++;if(E[aa]==null){E[aa]=document.createElementNS("http://www.w3.org/2000/svg","circle");W==0&&E[aa].setAttribute("shape-rendering","crispEdges")}p=E[aa];p.setAttribute("cx",X.x);p.setAttribute("cy",X.y);p.setAttribute("r",Y.scale.x*o);if(T instanceof THREE.ParticleCircleMaterial){if(I){L.r=l.r+A.r+n.r;L.g=l.g+A.g+n.g;L.b=l.b+A.b+n.b;t.r=T.color.r*L.r;
+t.g=T.color.g*L.g;t.b=T.color.b*L.b;t.updateStyleString()}else t=T.color;p.setAttribute("style","fill: "+t.__styleString)}k.appendChild(p)}}else if(K instanceof THREE.RenderableLine){v=K.v1;q=K.v2;v.positionScreen.x*=o;v.positionScreen.y*=-y;q.positionScreen.x*=o;q.positionScreen.y*=-y;w.addPoint(v.positionScreen.x,v.positionScreen.y);w.addPoint(q.positionScreen.x,q.positionScreen.y);if(H.instersects(w)){U=0;for(R=K.materials.length;U<R;)if(T=K.materials[U++]){X=v;Y=q;T=T;aa=G++;if(C[aa]==null){C[aa]=
+document.createElementNS("http://www.w3.org/2000/svg","line");W==0&&C[aa].setAttribute("shape-rendering","crispEdges")}p=C[aa];p.setAttribute("x1",X.positionScreen.x);p.setAttribute("y1",X.positionScreen.y);p.setAttribute("x2",Y.positionScreen.x);p.setAttribute("y2",Y.positionScreen.y);if(T instanceof THREE.LineBasicMaterial){t.__styleString=T.color.__styleString;p.setAttribute("style","fill: none; stroke: "+t.__styleString+"; stroke-width: "+T.linewidth+"; stroke-opacity: "+T.opacity+"; stroke-linecap: "+
+T.linecap+"; stroke-linejoin: "+T.linejoin);k.appendChild(p)}}}}else if(K instanceof THREE.RenderableFace3){v=K.v1;q=K.v2;z=K.v3;v.positionScreen.x*=o;v.positionScreen.y*=-y;q.positionScreen.x*=o;q.positionScreen.y*=-y;z.positionScreen.x*=o;z.positionScreen.y*=-y;w.addPoint(v.positionScreen.x,v.positionScreen.y);w.addPoint(q.positionScreen.x,q.positionScreen.y);w.addPoint(z.positionScreen.x,z.positionScreen.y);if(H.instersects(w)){U=0;for(R=K.meshMaterials.length;U<R;){T=K.meshMaterials[U++];if(T instanceof
+THREE.MeshFaceMaterial){X=0;for(Y=K.faceMaterials.length;X<Y;)(T=K.faceMaterials[X++])&&c(v,q,z,K,T,Q)}else T&&c(v,q,z,K,T,Q)}}}else if(K instanceof THREE.RenderableFace4){v=K.v1;q=K.v2;z=K.v3;B=K.v4;v.positionScreen.x*=o;v.positionScreen.y*=-y;q.positionScreen.x*=o;q.positionScreen.y*=-y;z.positionScreen.x*=o;z.positionScreen.y*=-y;B.positionScreen.x*=o;B.positionScreen.y*=-y;w.addPoint(v.positionScreen.x,v.positionScreen.y);w.addPoint(q.positionScreen.x,q.positionScreen.y);w.addPoint(z.positionScreen.x,
+z.positionScreen.y);w.addPoint(B.positionScreen.x,B.positionScreen.y);if(H.instersects(w)){U=0;for(R=K.meshMaterials.length;U<R;){T=K.meshMaterials[U++];if(T instanceof THREE.MeshFaceMaterial){X=0;for(Y=K.faceMaterials.length;X<Y;)(T=K.faceMaterials[X++])&&d(v,q,z,B,K,T,Q)}else T&&d(v,q,z,B,K,T,Q)}}}}}};
 THREE.WebGLRenderer=function(a){function c(l,A){l.fragment_shader=A.fragment_shader;l.vertex_shader=A.vertex_shader;l.uniforms=Uniforms.clone(A.uniforms)}function d(l){if(l.doubleSided)b.disable(b.CULL_FACE);else{b.enable(b.CULL_FACE);l.flipSided?b.frontFace(b.CW):b.frontFace(b.CCW)}}function e(l,A){var n;if(l=="fragment")n=b.createShader(b.FRAGMENT_SHADER);else if(l=="vertex")n=b.createShader(b.VERTEX_SHADER);b.shaderSource(n,A);b.compileShader(n);if(!b.getShaderParameter(n,b.COMPILE_STATUS)){alert(b.getShaderInfoLog(n));
 return null}return n}function g(l){switch(l){case THREE.RepeatWrapping:return b.REPEAT;case THREE.ClampToEdgeWrapping:return b.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return b.MIRRORED_REPEAT;case THREE.NearestFilter:return b.NEAREST;case THREE.NearestMipMapNearestFilter:return b.NEAREST_MIPMAP_NEAREST;case THREE.NearestMipMapLinearFilter:return b.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return b.LINEAR;case THREE.LinearMipMapNearestFilter:return b.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return b.LINEAR_MIPMAP_LINEAR;
 case THREE.ByteType:return b.BYTE;case THREE.UnsignedByteType:return b.UNSIGNED_BYTE;case THREE.ShortType:return b.SHORT;case THREE.UnsignedShortType:return b.UNSIGNED_SHORT;case THREE.IntType:return b.INT;case THREE.UnsignedShortType:return b.UNSIGNED_INT;case THREE.FloatType:return b.FLOAT;case THREE.AlphaFormat:return b.ALPHA;case THREE.RGBFormat:return b.RGB;case THREE.RGBAFormat:return b.RGBA;case THREE.LuminanceFormat:return b.LUMINANCE;case THREE.LuminanceAlphaFormat:return b.LUMINANCE_ALPHA}return 0}
 var f=document.createElement("canvas"),b,k=null,h=null,m=new THREE.Matrix4,o,y=new Float32Array(16),v=new Float32Array(16),q=new Float32Array(16),z=new Float32Array(9),B=new Float32Array(16),H=new THREE.Matrix4,w=new THREE.Vector4,I=true,t=new THREE.Color(0),L=0;if(a){if(a.antialias!==undefined)I=a.antialias;a.clearColor!==undefined&&t.setHex(a.clearColor);if(a.clearAlpha!==undefined)L=a.clearAlpha}this.domElement=f;this.autoClear=true;(function(l,A,n){try{b=f.getContext("experimental-webgl",{antialias:l})}catch(j){console.log(j)}if(!b){alert("WebGL not supported");
 throw"cannot create webgl context";}b.clearColor(0,0,0,1);b.clearDepth(1);b.enable(b.DEPTH_TEST);b.depthFunc(b.LEQUAL);b.frontFace(b.CCW);b.cullFace(b.BACK);b.enable(b.CULL_FACE);b.enable(b.BLEND);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA);b.clearColor(A.r,A.g,A.b,n)})(I,t,L);this.context=b;this.lights={ambient:[0,0,0],directional:{length:0,colors:[],positions:[]},point:{length:0,colors:[],positions:[]}};this.setSize=function(l,A){f.width=l;f.height=A;b.viewport(0,0,f.width,f.height)};this.setClearColorHex=
-function(l,A){var n=new THREE.Color(l);b.clearColor(n.r,n.g,n.b,A)};this.setClearColor=function(l,A){b.clearColor(l.r,l.g,l.b,A)};this.clear=function(){b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT)};this.setupLights=function(l,A){var n,j,x,u=0,E=0,C=0,p,F,M,G=this.lights,X=G.directional.colors,Q=G.directional.positions,P=G.point.colors,ca=G.point.positions,aa=0,T=0;n=0;for(j=A.length;n<j;n++){x=A[n];p=x.color;F=x.position;M=x.intensity;if(x instanceof THREE.AmbientLight){u+=p.r;E+=p.g;C+=p.b}else if(x instanceof
-THREE.DirectionalLight){X[aa*3]=p.r*M;X[aa*3+1]=p.g*M;X[aa*3+2]=p.b*M;Q[aa*3]=F.x;Q[aa*3+1]=F.y;Q[aa*3+2]=F.z;aa+=1}else if(x instanceof THREE.PointLight){P[T*3]=p.r*M;P[T*3+1]=p.g*M;P[T*3+2]=p.b*M;ca[T*3]=F.x;ca[T*3+1]=F.y;ca[T*3+2]=F.z;T+=1}}G.point.length=T;G.directional.length=aa;G.ambient[0]=u;G.ambient[1]=E;G.ambient[2]=C};this.createParticleBuffers=function(l){l.__webGLVertexBuffer=b.createBuffer();l.__webGLColorBuffer=b.createBuffer();l.__webGLParticleBuffer=b.createBuffer()};this.createLineBuffers=
-function(l){l.__webGLVertexBuffer=b.createBuffer();l.__webGLColorBuffer=b.createBuffer();l.__webGLLineBuffer=b.createBuffer()};this.createMeshBuffers=function(l){l.__webGLVertexBuffer=b.createBuffer();l.__webGLNormalBuffer=b.createBuffer();l.__webGLTangentBuffer=b.createBuffer();l.__webGLColorBuffer=b.createBuffer();l.__webGLUVBuffer=b.createBuffer();l.__webGLUV2Buffer=b.createBuffer();l.__webGLFaceBuffer=b.createBuffer();l.__webGLLineBuffer=b.createBuffer()};this.initLineBuffers=function(l){var A=
-l.vertices.length;l.__vertexArray=new Float32Array(A*3);l.__colorArray=new Float32Array(A*3);l.__lineArray=new Uint16Array(A);l.__webGLLineCount=A};this.initParticleBuffers=function(l){var A=l.vertices.length;l.__vertexArray=new Float32Array(A*3);l.__colorArray=new Float32Array(A*3);l.__particleArray=new Uint16Array(A);l.__sortArray=[];l.__webGLParticleCount=A};this.initMeshBuffers=function(l,A){var n,j,x=0,u=0,E=0,C=A.geometry.faces,p=l.faces;n=0;for(j=p.length;n<j;n++){fi=p[n];face=C[fi];if(face instanceof
-THREE.Face3){x+=3;u+=1;E+=3}else if(face instanceof THREE.Face4){x+=4;u+=2;E+=4}}l.__vertexArray=new Float32Array(x*3);l.__normalArray=new Float32Array(x*3);l.__tangentArray=new Float32Array(x*4);l.__colorArray=new Float32Array(x*3);l.__uvArray=new Float32Array(x*2);l.__uv2Array=new Float32Array(x*2);l.__faceArray=new Uint16Array(u*3);l.__lineArray=new Uint16Array(E*2);x=false;n=0;for(j=A.materials.length;n<j;n++){C=A.materials[n];if(C instanceof THREE.MeshFaceMaterial){C=0;for(p=l.materials.length;C<
-p;C++)if(l.materials[C]&&l.materials[C].shading!=undefined&&l.materials[C].shading==THREE.SmoothShading){x=true;break}}else if(C&&C.shading!=undefined&&C.shading==THREE.SmoothShading){x=true;break}if(x)break}l.__needsSmoothNormals=x;l.__webGLFaceCount=u*3;l.__webGLLineCount=E*2};this.setMeshBuffers=function(l,A,n){var j,x,u,E,C,p,F,M,G,X,Q=0,P=0,ca=0,aa=0,T=0,R=0,W=0,Y=0,K=0,U=l.__vertexArray,ba=l.__uvArray,ja=l.__uv2Array,ha=l.__normalArray,D=l.__tangentArray,J=l.__colorArray,N=l.__faceArray,V=l.__lineArray,
-da=l.__needsSmoothNormals,ga=A.geometry,ia=ga.__dirtyVertices,ta=ga.__dirtyElements,qa=ga.__dirtyUvs,va=ga.__dirtyNormals,ka=ga.__dirtyTangents,ra=ga.__dirtyColors,oa=ga.vertices,Aa=l.faces,Ja=ga.faces,Ka=ga.uvs,Ga=ga.uvs2,sa=ga.colors;A=0;for(j=Aa.length;A<j;A++){x=Aa[A];u=Ja[x];p=Ka[x];x=Ga[x];E=u.vertexNormals;C=u.normal;if(u instanceof THREE.Face3){if(ia){F=oa[u.a].position;M=oa[u.b].position;G=oa[u.c].position;U[P]=F.x;U[P+1]=F.y;U[P+2]=F.z;U[P+3]=M.x;U[P+4]=M.y;U[P+5]=M.z;U[P+6]=G.x;U[P+7]=
-G.y;U[P+8]=G.z;P+=9}if(ra&&sa.length){F=sa[u.a];M=sa[u.b];G=sa[u.c];J[K]=F.r;J[K+1]=F.g;J[K+2]=F.b;J[K+3]=M.r;J[K+4]=M.g;J[K+5]=M.b;J[K+6]=G.r;J[K+7]=G.g;J[K+8]=G.b;K+=9}if(ka&&ga.hasTangents){F=oa[u.a].tangent;M=oa[u.b].tangent;G=oa[u.c].tangent;D[W]=F.x;D[W+1]=F.y;D[W+2]=F.z;D[W+3]=F.w;D[W+4]=M.x;D[W+5]=M.y;D[W+6]=M.z;D[W+7]=M.w;D[W+8]=G.x;D[W+9]=G.y;D[W+10]=G.z;D[W+11]=G.w;W+=12}if(va)if(E.length==3&&da)for(u=0;u<3;u++){C=E[u];ha[R]=C.x;ha[R+1]=C.y;ha[R+2]=C.z;R+=3}else for(u=0;u<3;u++){ha[R]=
-C.x;ha[R+1]=C.y;ha[R+2]=C.z;R+=3}if(qa&&p)for(u=0;u<3;u++){E=p[u];ba[ca]=E.u;ba[ca+1]=E.v;ca+=2}if(qa&&x)for(u=0;u<3;u++){p=x[u];ja[aa]=p.u;ja[aa+1]=p.v;aa+=2}if(ta){N[T]=Q;N[T+1]=Q+1;N[T+2]=Q+2;T+=3;V[Y]=Q;V[Y+1]=Q+1;V[Y+2]=Q;V[Y+3]=Q+2;V[Y+4]=Q+1;V[Y+5]=Q+2;Y+=6;Q+=3}}else if(u instanceof THREE.Face4){if(ia){F=oa[u.a].position;M=oa[u.b].position;G=oa[u.c].position;X=oa[u.d].position;U[P]=F.x;U[P+1]=F.y;U[P+2]=F.z;U[P+3]=M.x;U[P+4]=M.y;U[P+5]=M.z;U[P+6]=G.x;U[P+7]=G.y;U[P+8]=G.z;U[P+9]=X.x;U[P+10]=
-X.y;U[P+11]=X.z;P+=12}if(ra&&sa.length){F=sa[u.a];M=sa[u.b];G=sa[u.d];J[K]=F.r;J[K+1]=F.g;J[K+2]=F.b;J[K+3]=M.r;J[K+4]=M.g;J[K+5]=M.b;J[K+6]=G.r;J[K+7]=G.g;J[K+8]=G.b;J[K+9]=(void 0).r;J[K+10]=(void 0).g;J[K+11]=(void 0).b;K+=12}if(ka&&ga.hasTangents){F=oa[u.a].tangent;M=oa[u.b].tangent;G=oa[u.c].tangent;u=oa[u.d].tangent;D[W]=F.x;D[W+1]=F.y;D[W+2]=F.z;D[W+3]=F.w;D[W+4]=M.x;D[W+5]=M.y;D[W+6]=M.z;D[W+7]=M.w;D[W+8]=G.x;D[W+9]=G.y;D[W+10]=G.z;D[W+11]=G.w;D[W+12]=u.x;D[W+13]=u.y;D[W+14]=u.z;D[W+15]=u.w;
-W+=16}if(va)if(E.length==4&&da)for(u=0;u<4;u++){C=E[u];ha[R]=C.x;ha[R+1]=C.y;ha[R+2]=C.z;R+=3}else for(u=0;u<4;u++){ha[R]=C.x;ha[R+1]=C.y;ha[R+2]=C.z;R+=3}if(qa&&p)for(u=0;u<4;u++){E=p[u];ba[ca]=E.u;ba[ca+1]=E.v;ca+=2}if(qa&&x)for(u=0;u<4;u++){p=x[u];ja[aa]=p.u;ja[aa+1]=p.v;aa+=2}if(ta){N[T]=Q;N[T+1]=Q+1;N[T+2]=Q+2;N[T+3]=Q;N[T+4]=Q+2;N[T+5]=Q+3;T+=6;V[Y]=Q;V[Y+1]=Q+1;V[Y+2]=Q;V[Y+3]=Q+3;V[Y+4]=Q+1;V[Y+5]=Q+2;V[Y+6]=Q+2;V[Y+7]=Q+3;Y+=8;Q+=4}}}if(ia){b.bindBuffer(b.ARRAY_BUFFER,l.__webGLVertexBuffer);
-b.bufferData(b.ARRAY_BUFFER,U,n)}if(ra&&sa.length){b.bindBuffer(b.ARRAY_BUFFER,l.__webGLColorBuffer);b.bufferData(b.ARRAY_BUFFER,J,n)}if(va){b.bindBuffer(b.ARRAY_BUFFER,l.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,ha,n)}if(ka&&ga.hasTangents){b.bindBuffer(b.ARRAY_BUFFER,l.__webGLTangentBuffer);b.bufferData(b.ARRAY_BUFFER,D,n)}if(qa&&ca>0){b.bindBuffer(b.ARRAY_BUFFER,l.__webGLUVBuffer);b.bufferData(b.ARRAY_BUFFER,ba,n)}if(qa&&aa>0){b.bindBuffer(b.ARRAY_BUFFER,l.__webGLUV2Buffer);b.bufferData(b.ARRAY_BUFFER,
-ja,n)}if(ta){b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,l.__webGLFaceBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,N,n);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,l.__webGLLineBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,V,n)}};this.setLineBuffers=function(l,A){var n,j,x,u=l.vertices,E=l.colors,C=u.length,p=E.length,F=l.__vertexArray,M=l.__colorArray,G=l.__lineArray,X=l.__dirtyColors,Q=l.__dirtyElements;if(l.__dirtyVertices){for(n=0;n<C;n++){j=u[n].position;x=n*3;F[x]=j.x;F[x+1]=j.y;F[x+2]=j.z}b.bindBuffer(b.ARRAY_BUFFER,
-l.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,F,A)}if(X){for(n=0;n<p;n++){color=E[n];x=n*3;M[x]=color.r;M[x+1]=color.g;M[x+2]=color.b}b.bindBuffer(b.ARRAY_BUFFER,l.__webGLColorBuffer);b.bufferData(b.ARRAY_BUFFER,M,A)}if(Q){for(n=0;n<C;n++)G[n]=n;b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,l.__webGLLineBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,G,A)}};this.setParticleBuffers=function(l,A,n,j){var x,u,E;u=l.vertices;var C=u.length,p=l.colors,F=p.length,M=l.__vertexArray,G=l.__particleArray,X=l.__colorArray,
-Q=l.__sortArray,P=l.__dirtyVertices,ca=l.__dirtyElements,aa=l.__dirtyColors;if(n.sortParticles){H.multiply(j.projectionMatrix,j.matrix);H.multiplySelf(n.matrix);for(x=0;x<C;x++){E=u[x].position;w.copy(E);H.multiplyVector3(w);Q[x]=[w.z,x]}Q.sort(function(T,R){return R[0]-T[0]});for(x=0;x<C;x++){E=u[Q[x][1]].position;j=x*3;M[j]=E.x;M[j+1]=E.y;M[j+2]=E.z}for(u=0;u<F;u++){j=u*3;color=p[Q[u][1]];X[j]=color.r;X[j+1]=color.g;X[j+2]=color.b}}else{if(P)for(x=0;x<C;x++){E=u[x].position;j=x*3;M[j]=E.x;M[j+1]=
-E.y;M[j+2]=E.z}if(aa)for(u=0;u<F;u++){color=p[u];j=u*3;X[j]=color.r;X[j+1]=color.g;X[j+2]=color.b}}if(ca){for(x=0;x<C;x++)G[x]=x;b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,l.__webGLParticleBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,G,A)}if(P||n.sortParticles){b.bindBuffer(b.ARRAY_BUFFER,l.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,M,A)}if(aa||n.sortParticles){b.bindBuffer(b.ARRAY_BUFFER,l.__webGLColorBuffer);b.bufferData(b.ARRAY_BUFFER,X,A)}};this.initMaterial=function(l,A,n){if(!l.program){var j,
-x;if(l instanceof THREE.MeshDepthMaterial)c(l,THREE.ShaderLib.depth);else if(l instanceof THREE.MeshNormalMaterial)c(l,THREE.ShaderLib.normal);else if(l instanceof THREE.MeshBasicMaterial)c(l,THREE.ShaderLib.basic);else if(l instanceof THREE.MeshLambertMaterial)c(l,THREE.ShaderLib.lambert);else if(l instanceof THREE.MeshPhongMaterial)c(l,THREE.ShaderLib.phong);else if(l instanceof THREE.LineBasicMaterial)c(l,THREE.ShaderLib.basic);else l instanceof THREE.ParticleBasicMaterial&&c(l,THREE.ShaderLib.particle_basic);
-var u,E,C,p;x=C=p=0;for(u=A.length;x<u;x++){E=A[x];E instanceof THREE.DirectionalLight&&C++;E instanceof THREE.PointLight&&p++}if(p+C<=4){A=C;p=p}else{A=Math.ceil(4*C/(p+C));p=4-A}x={directional:A,point:p};p=l.fragment_shader;A=l.vertex_shader;u={fog:n,map:l.map,env_map:l.env_map,light_map:l.light_map,vertex_colors:l.vertex_colors,maxDirLights:x.directional,maxPointLights:x.point};n=b.createProgram();x=["#ifdef GL_ES\nprecision highp float;\n#endif","#define MAX_DIR_LIGHTS "+u.maxDirLights,"#define MAX_POINT_LIGHTS "+
-u.maxPointLights,u.fog?"#define USE_FOG":"",u.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",u.map?"#define USE_MAP":"",u.env_map?"#define USE_ENVMAP":"",u.light_map?"#define USE_LIGHTMAP":"",u.vertex_colors?"#define USE_COLOR":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");u=[b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+u.maxDirLights,"#define MAX_POINT_LIGHTS "+u.maxPointLights,u.map?"#define USE_MAP":"",
-u.env_map?"#define USE_ENVMAP":"",u.light_map?"#define USE_LIGHTMAP":"",u.vertex_colors?"#define USE_COLOR":"","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 vec3 color;\nattribute vec2 uv;\nattribute vec2 uv2;\n"].join("\n");b.attachShader(n,e("fragment",x+p));b.attachShader(n,e("vertex",u+A));b.linkProgram(n);
-b.getProgramParameter(n,b.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+b.getProgramParameter(n,b.VALIDATE_STATUS)+", gl error ["+b.getError()+"]");n.uniforms={};n.attributes={};l.program=n;n=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(j in l.uniforms)n.push(j);j=l.program;p=0;for(A=n.length;p<A;p++){x=n[p];j.uniforms[x]=b.getUniformLocation(j,x)}l=l.program;j=["position","normal","uv","uv2","tangent","color"];n=0;
-for(p=j.length;n<p;n++){A=j[n];l.attributes[A]=b.getAttribLocation(l,A)}}};this.setProgram=function(l,A,n,j){this.initMaterial(j,A,n);var x=j.program;if(x!=k){b.useProgram(x);k=x}this.loadCamera(x,l);this.loadMatrices(x);if(j instanceof THREE.MeshPhongMaterial||j instanceof THREE.MeshLambertMaterial){this.setupLights(x,A);A=this.lights;j.uniforms.enableLighting.value=A.directional.length+A.point.length;j.uniforms.ambientLightColor.value=A.ambient;j.uniforms.directionalLightColor.value=A.directional.colors;
-j.uniforms.directionalLightDirection.value=A.directional.positions;j.uniforms.pointLightColor.value=A.point.colors;j.uniforms.pointLightPosition.value=A.point.positions}if(j instanceof THREE.MeshBasicMaterial||j instanceof THREE.MeshLambertMaterial||j instanceof THREE.MeshPhongMaterial){j.uniforms.diffuse.value.setRGB(j.color.r*j.opacity,j.color.g*j.opacity,j.color.b*j.opacity);j.uniforms.opacity.value=j.opacity;j.uniforms.map.texture=j.map;j.uniforms.light_map.texture=j.light_map;j.uniforms.env_map.texture=
-j.env_map;j.uniforms.reflectivity.value=j.reflectivity;j.uniforms.refraction_ratio.value=j.refraction_ratio;j.uniforms.combine.value=j.combine;j.uniforms.useRefract.value=j.env_map&&j.env_map.mapping instanceof THREE.CubeRefractionMapping;if(n){j.uniforms.fogColor.value.setHex(n.color.hex);if(n instanceof THREE.Fog){j.uniforms.fogNear.value=n.near;j.uniforms.fogFar.value=n.far}else if(n instanceof THREE.FogExp2)j.uniforms.fogDensity.value=n.density}}if(j instanceof THREE.LineBasicMaterial){j.uniforms.diffuse.value.setRGB(j.color.r*
+function(l,A){var n=new THREE.Color(l);b.clearColor(n.r,n.g,n.b,A)};this.setClearColor=function(l,A){b.clearColor(l.r,l.g,l.b,A)};this.clear=function(){b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT)};this.setupLights=function(l,A){var n,j,x,u=0,E=0,C=0,p,F,M,G=this.lights,W=G.directional.colors,Q=G.directional.positions,O=G.point.colors,ba=G.point.positions,ca=0,U=0;n=x=x=0;for(j=A.length;n<j;n++){x=A[n];p=x.color;F=x.position;M=x.intensity;if(x instanceof THREE.AmbientLight){u+=p.r;E+=p.g;C+=p.b}else if(x instanceof
+THREE.DirectionalLight){x=ca*3;W[x]=p.r*M;W[x+1]=p.g*M;W[x+2]=p.b*M;Q[x]=F.x;Q[x+1]=F.y;Q[x+2]=F.z;ca+=1}else if(x instanceof THREE.PointLight){x=U*3;O[x]=p.r*M;O[x+1]=p.g*M;O[x+2]=p.b*M;ba[x]=F.x;ba[x+1]=F.y;ba[x+2]=F.z;U+=1}}for(n=ca*3;n<W.length;n++)W[n]=0;for(n=U*3;n<O.length;n++)O[n]=0;G.point.length=U;G.directional.length=ca;G.ambient[0]=u;G.ambient[1]=E;G.ambient[2]=C};this.createParticleBuffers=function(l){l.__webGLVertexBuffer=b.createBuffer();l.__webGLColorBuffer=b.createBuffer();l.__webGLParticleBuffer=
+b.createBuffer()};this.createLineBuffers=function(l){l.__webGLVertexBuffer=b.createBuffer();l.__webGLColorBuffer=b.createBuffer();l.__webGLLineBuffer=b.createBuffer()};this.createMeshBuffers=function(l){l.__webGLVertexBuffer=b.createBuffer();l.__webGLNormalBuffer=b.createBuffer();l.__webGLTangentBuffer=b.createBuffer();l.__webGLColorBuffer=b.createBuffer();l.__webGLUVBuffer=b.createBuffer();l.__webGLUV2Buffer=b.createBuffer();l.__webGLFaceBuffer=b.createBuffer();l.__webGLLineBuffer=b.createBuffer()};
+this.initLineBuffers=function(l){var A=l.vertices.length;l.__vertexArray=new Float32Array(A*3);l.__colorArray=new Float32Array(A*3);l.__lineArray=new Uint16Array(A);l.__webGLLineCount=A};this.initParticleBuffers=function(l){var A=l.vertices.length;l.__vertexArray=new Float32Array(A*3);l.__colorArray=new Float32Array(A*3);l.__particleArray=new Uint16Array(A);l.__sortArray=[];l.__webGLParticleCount=A};this.initMeshBuffers=function(l,A){var n,j,x=0,u=0,E=0,C=A.geometry.faces,p=l.faces;n=0;for(j=p.length;n<
+j;n++){fi=p[n];face=C[fi];if(face instanceof THREE.Face3){x+=3;u+=1;E+=3}else if(face instanceof THREE.Face4){x+=4;u+=2;E+=4}}l.__vertexArray=new Float32Array(x*3);l.__normalArray=new Float32Array(x*3);l.__tangentArray=new Float32Array(x*4);l.__colorArray=new Float32Array(x*3);l.__uvArray=new Float32Array(x*2);l.__uv2Array=new Float32Array(x*2);l.__faceArray=new Uint16Array(u*3);l.__lineArray=new Uint16Array(E*2);x=false;n=0;for(j=A.materials.length;n<j;n++){C=A.materials[n];if(C instanceof THREE.MeshFaceMaterial){C=
+0;for(p=l.materials.length;C<p;C++)if(l.materials[C]&&l.materials[C].shading!=undefined&&l.materials[C].shading==THREE.SmoothShading){x=true;break}}else if(C&&C.shading!=undefined&&C.shading==THREE.SmoothShading){x=true;break}if(x)break}l.__needsSmoothNormals=x;l.__webGLFaceCount=u*3;l.__webGLLineCount=E*2};this.setMeshBuffers=function(l,A,n){var j,x,u,E,C,p,F,M,G,W,Q=0,O=0,ba=0,ca=0,U=0,R=0,X=0,Y=0,K=0,T=l.__vertexArray,aa=l.__uvArray,ja=l.__uv2Array,ha=l.__normalArray,D=l.__tangentArray,J=l.__colorArray,
+N=l.__faceArray,V=l.__lineArray,da=l.__needsSmoothNormals,ga=A.geometry,ia=ga.__dirtyVertices,ta=ga.__dirtyElements,qa=ga.__dirtyUvs,va=ga.__dirtyNormals,ka=ga.__dirtyTangents,ra=ga.__dirtyColors,oa=ga.vertices,Aa=l.faces,Ja=ga.faces,Ka=ga.uvs,Ga=ga.uvs2,sa=ga.colors;A=0;for(j=Aa.length;A<j;A++){x=Aa[A];u=Ja[x];p=Ka[x];x=Ga[x];E=u.vertexNormals;C=u.normal;if(u instanceof THREE.Face3){if(ia){F=oa[u.a].position;M=oa[u.b].position;G=oa[u.c].position;T[O]=F.x;T[O+1]=F.y;T[O+2]=F.z;T[O+3]=M.x;T[O+4]=M.y;
+T[O+5]=M.z;T[O+6]=G.x;T[O+7]=G.y;T[O+8]=G.z;O+=9}if(ra&&sa.length){F=sa[u.a];M=sa[u.b];G=sa[u.c];J[K]=F.r;J[K+1]=F.g;J[K+2]=F.b;J[K+3]=M.r;J[K+4]=M.g;J[K+5]=M.b;J[K+6]=G.r;J[K+7]=G.g;J[K+8]=G.b;K+=9}if(ka&&ga.hasTangents){F=oa[u.a].tangent;M=oa[u.b].tangent;G=oa[u.c].tangent;D[X]=F.x;D[X+1]=F.y;D[X+2]=F.z;D[X+3]=F.w;D[X+4]=M.x;D[X+5]=M.y;D[X+6]=M.z;D[X+7]=M.w;D[X+8]=G.x;D[X+9]=G.y;D[X+10]=G.z;D[X+11]=G.w;X+=12}if(va)if(E.length==3&&da)for(u=0;u<3;u++){C=E[u];ha[R]=C.x;ha[R+1]=C.y;ha[R+2]=C.z;R+=3}else for(u=
+0;u<3;u++){ha[R]=C.x;ha[R+1]=C.y;ha[R+2]=C.z;R+=3}if(qa&&p)for(u=0;u<3;u++){E=p[u];aa[ba]=E.u;aa[ba+1]=E.v;ba+=2}if(qa&&x)for(u=0;u<3;u++){p=x[u];ja[ca]=p.u;ja[ca+1]=p.v;ca+=2}if(ta){N[U]=Q;N[U+1]=Q+1;N[U+2]=Q+2;U+=3;V[Y]=Q;V[Y+1]=Q+1;V[Y+2]=Q;V[Y+3]=Q+2;V[Y+4]=Q+1;V[Y+5]=Q+2;Y+=6;Q+=3}}else if(u instanceof THREE.Face4){if(ia){F=oa[u.a].position;M=oa[u.b].position;G=oa[u.c].position;W=oa[u.d].position;T[O]=F.x;T[O+1]=F.y;T[O+2]=F.z;T[O+3]=M.x;T[O+4]=M.y;T[O+5]=M.z;T[O+6]=G.x;T[O+7]=G.y;T[O+8]=G.z;
+T[O+9]=W.x;T[O+10]=W.y;T[O+11]=W.z;O+=12}if(ra&&sa.length){F=sa[u.a];M=sa[u.b];G=sa[u.d];J[K]=F.r;J[K+1]=F.g;J[K+2]=F.b;J[K+3]=M.r;J[K+4]=M.g;J[K+5]=M.b;J[K+6]=G.r;J[K+7]=G.g;J[K+8]=G.b;J[K+9]=(void 0).r;J[K+10]=(void 0).g;J[K+11]=(void 0).b;K+=12}if(ka&&ga.hasTangents){F=oa[u.a].tangent;M=oa[u.b].tangent;G=oa[u.c].tangent;u=oa[u.d].tangent;D[X]=F.x;D[X+1]=F.y;D[X+2]=F.z;D[X+3]=F.w;D[X+4]=M.x;D[X+5]=M.y;D[X+6]=M.z;D[X+7]=M.w;D[X+8]=G.x;D[X+9]=G.y;D[X+10]=G.z;D[X+11]=G.w;D[X+12]=u.x;D[X+13]=u.y;D[X+
+14]=u.z;D[X+15]=u.w;X+=16}if(va)if(E.length==4&&da)for(u=0;u<4;u++){C=E[u];ha[R]=C.x;ha[R+1]=C.y;ha[R+2]=C.z;R+=3}else for(u=0;u<4;u++){ha[R]=C.x;ha[R+1]=C.y;ha[R+2]=C.z;R+=3}if(qa&&p)for(u=0;u<4;u++){E=p[u];aa[ba]=E.u;aa[ba+1]=E.v;ba+=2}if(qa&&x)for(u=0;u<4;u++){p=x[u];ja[ca]=p.u;ja[ca+1]=p.v;ca+=2}if(ta){N[U]=Q;N[U+1]=Q+1;N[U+2]=Q+2;N[U+3]=Q;N[U+4]=Q+2;N[U+5]=Q+3;U+=6;V[Y]=Q;V[Y+1]=Q+1;V[Y+2]=Q;V[Y+3]=Q+3;V[Y+4]=Q+1;V[Y+5]=Q+2;V[Y+6]=Q+2;V[Y+7]=Q+3;Y+=8;Q+=4}}}if(ia){b.bindBuffer(b.ARRAY_BUFFER,
+l.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,T,n)}if(ra&&sa.length){b.bindBuffer(b.ARRAY_BUFFER,l.__webGLColorBuffer);b.bufferData(b.ARRAY_BUFFER,J,n)}if(va){b.bindBuffer(b.ARRAY_BUFFER,l.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,ha,n)}if(ka&&ga.hasTangents){b.bindBuffer(b.ARRAY_BUFFER,l.__webGLTangentBuffer);b.bufferData(b.ARRAY_BUFFER,D,n)}if(qa&&ba>0){b.bindBuffer(b.ARRAY_BUFFER,l.__webGLUVBuffer);b.bufferData(b.ARRAY_BUFFER,aa,n)}if(qa&&ca>0){b.bindBuffer(b.ARRAY_BUFFER,l.__webGLUV2Buffer);
+b.bufferData(b.ARRAY_BUFFER,ja,n)}if(ta){b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,l.__webGLFaceBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,N,n);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,l.__webGLLineBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,V,n)}};this.setLineBuffers=function(l,A){var n,j,x,u=l.vertices,E=l.colors,C=u.length,p=E.length,F=l.__vertexArray,M=l.__colorArray,G=l.__lineArray,W=l.__dirtyColors,Q=l.__dirtyElements;if(l.__dirtyVertices){for(n=0;n<C;n++){j=u[n].position;x=n*3;F[x]=j.x;F[x+1]=j.y;F[x+
+2]=j.z}b.bindBuffer(b.ARRAY_BUFFER,l.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,F,A)}if(W){for(n=0;n<p;n++){color=E[n];x=n*3;M[x]=color.r;M[x+1]=color.g;M[x+2]=color.b}b.bindBuffer(b.ARRAY_BUFFER,l.__webGLColorBuffer);b.bufferData(b.ARRAY_BUFFER,M,A)}if(Q){for(n=0;n<C;n++)G[n]=n;b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,l.__webGLLineBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,G,A)}};this.setParticleBuffers=function(l,A,n,j){var x,u,E;u=l.vertices;var C=u.length,p=l.colors,F=p.length,M=l.__vertexArray,
+G=l.__particleArray,W=l.__colorArray,Q=l.__sortArray,O=l.__dirtyVertices,ba=l.__dirtyElements,ca=l.__dirtyColors;if(n.sortParticles){H.multiply(j.projectionMatrix,j.matrix);H.multiplySelf(n.matrix);for(x=0;x<C;x++){E=u[x].position;w.copy(E);H.multiplyVector3(w);Q[x]=[w.z,x]}Q.sort(function(U,R){return R[0]-U[0]});for(x=0;x<C;x++){E=u[Q[x][1]].position;j=x*3;M[j]=E.x;M[j+1]=E.y;M[j+2]=E.z}for(u=0;u<F;u++){j=u*3;color=p[Q[u][1]];W[j]=color.r;W[j+1]=color.g;W[j+2]=color.b}}else{if(O)for(x=0;x<C;x++){E=
+u[x].position;j=x*3;M[j]=E.x;M[j+1]=E.y;M[j+2]=E.z}if(ca)for(u=0;u<F;u++){color=p[u];j=u*3;W[j]=color.r;W[j+1]=color.g;W[j+2]=color.b}}if(ba){for(x=0;x<C;x++)G[x]=x;b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,l.__webGLParticleBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,G,A)}if(O||n.sortParticles){b.bindBuffer(b.ARRAY_BUFFER,l.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,M,A)}if(ca||n.sortParticles){b.bindBuffer(b.ARRAY_BUFFER,l.__webGLColorBuffer);b.bufferData(b.ARRAY_BUFFER,W,A)}};this.initMaterial=
+function(l,A,n){if(!l.program){var j,x;if(l instanceof THREE.MeshDepthMaterial)c(l,THREE.ShaderLib.depth);else if(l instanceof THREE.MeshNormalMaterial)c(l,THREE.ShaderLib.normal);else if(l instanceof THREE.MeshBasicMaterial)c(l,THREE.ShaderLib.basic);else if(l instanceof THREE.MeshLambertMaterial)c(l,THREE.ShaderLib.lambert);else if(l instanceof THREE.MeshPhongMaterial)c(l,THREE.ShaderLib.phong);else if(l instanceof THREE.LineBasicMaterial)c(l,THREE.ShaderLib.basic);else l instanceof THREE.ParticleBasicMaterial&&
+c(l,THREE.ShaderLib.particle_basic);var u,E,C,p;x=C=p=0;for(u=A.length;x<u;x++){E=A[x];E instanceof THREE.DirectionalLight&&C++;E instanceof THREE.PointLight&&p++}if(p+C<=4){A=C;p=p}else{A=Math.ceil(4*C/(p+C));p=4-A}x={directional:A,point:p};p=l.fragment_shader;A=l.vertex_shader;u={fog:n,map:l.map,env_map:l.env_map,light_map:l.light_map,vertex_colors:l.vertex_colors,maxDirLights:x.directional,maxPointLights:x.point};n=b.createProgram();x=["#ifdef GL_ES\nprecision highp float;\n#endif","#define MAX_DIR_LIGHTS "+
+u.maxDirLights,"#define MAX_POINT_LIGHTS "+u.maxPointLights,u.fog?"#define USE_FOG":"",u.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",u.map?"#define USE_MAP":"",u.env_map?"#define USE_ENVMAP":"",u.light_map?"#define USE_LIGHTMAP":"",u.vertex_colors?"#define USE_COLOR":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");u=[b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+u.maxDirLights,"#define MAX_POINT_LIGHTS "+
+u.maxPointLights,u.map?"#define USE_MAP":"",u.env_map?"#define USE_ENVMAP":"",u.light_map?"#define USE_LIGHTMAP":"",u.vertex_colors?"#define USE_COLOR":"","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 vec3 color;\nattribute vec2 uv;\nattribute vec2 uv2;\n"].join("\n");b.attachShader(n,e("fragment",x+p));b.attachShader(n,
+e("vertex",u+A));b.linkProgram(n);b.getProgramParameter(n,b.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+b.getProgramParameter(n,b.VALIDATE_STATUS)+", gl error ["+b.getError()+"]");n.uniforms={};n.attributes={};l.program=n;n=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(j in l.uniforms)n.push(j);j=l.program;p=0;for(A=n.length;p<A;p++){x=n[p];j.uniforms[x]=b.getUniformLocation(j,x)}l=l.program;j=["position","normal",
+"uv","uv2","tangent","color"];n=0;for(p=j.length;n<p;n++){A=j[n];l.attributes[A]=b.getAttribLocation(l,A)}}};this.setProgram=function(l,A,n,j){this.initMaterial(j,A,n);var x=j.program;if(x!=k){b.useProgram(x);k=x}this.loadCamera(x,l);this.loadMatrices(x);if(j instanceof THREE.MeshPhongMaterial||j instanceof THREE.MeshLambertMaterial){this.setupLights(x,A);A=this.lights;j.uniforms.enableLighting.value=A.directional.length+A.point.length;j.uniforms.ambientLightColor.value=A.ambient;j.uniforms.directionalLightColor.value=
+A.directional.colors;j.uniforms.directionalLightDirection.value=A.directional.positions;j.uniforms.pointLightColor.value=A.point.colors;j.uniforms.pointLightPosition.value=A.point.positions}if(j instanceof THREE.MeshBasicMaterial||j instanceof THREE.MeshLambertMaterial||j instanceof THREE.MeshPhongMaterial){j.uniforms.diffuse.value.setRGB(j.color.r*j.opacity,j.color.g*j.opacity,j.color.b*j.opacity);j.uniforms.opacity.value=j.opacity;j.uniforms.map.texture=j.map;j.uniforms.light_map.texture=j.light_map;
+j.uniforms.env_map.texture=j.env_map;j.uniforms.reflectivity.value=j.reflectivity;j.uniforms.refraction_ratio.value=j.refraction_ratio;j.uniforms.combine.value=j.combine;j.uniforms.useRefract.value=j.env_map&&j.env_map.mapping instanceof THREE.CubeRefractionMapping;if(n){j.uniforms.fogColor.value.setHex(n.color.hex);if(n instanceof THREE.Fog){j.uniforms.fogNear.value=n.near;j.uniforms.fogFar.value=n.far}else if(n instanceof THREE.FogExp2)j.uniforms.fogDensity.value=n.density}}if(j instanceof THREE.LineBasicMaterial){j.uniforms.diffuse.value.setRGB(j.color.r*
 j.opacity,j.color.g*j.opacity,j.color.b*j.opacity);j.uniforms.opacity.value=j.opacity;if(n){j.uniforms.fogColor.value.setHex(n.color.hex);if(n instanceof THREE.Fog){j.uniforms.fogNear.value=n.near;j.uniforms.fogFar.value=n.far}else if(n instanceof THREE.FogExp2)j.uniforms.fogDensity.value=n.density}}if(j instanceof THREE.ParticleBasicMaterial){j.uniforms.psColor.value.setRGB(j.color.r*j.opacity,j.color.g*j.opacity,j.color.b*j.opacity);j.uniforms.opacity.value=j.opacity;j.uniforms.size.value=j.size;
 j.uniforms.map.texture=j.map;if(n){j.uniforms.fogColor.value.setHex(n.color.hex);if(n instanceof THREE.Fog){j.uniforms.fogNear.value=n.near;j.uniforms.fogFar.value=n.far}else if(n instanceof THREE.FogExp2)j.uniforms.fogDensity.value=n.density}}if(j instanceof THREE.MeshPhongMaterial){j.uniforms.ambient.value.setRGB(j.ambient.r,j.ambient.g,j.ambient.b);j.uniforms.specular.value.setRGB(j.specular.r,j.specular.g,j.specular.b);j.uniforms.shininess.value=j.shininess}if(j instanceof THREE.MeshDepthMaterial){j.uniforms.mNear.value=
 l.near;j.uniforms.mFar.value=l.far;j.uniforms.opacity.value=j.opacity}if(j instanceof THREE.MeshNormalMaterial)j.uniforms.opacity.value=j.opacity;l=j.uniforms;var u,E;for(u in l)if(E=x.uniforms[u]){j=l[u];A=j.type;n=j.value;if(A=="i")b.uniform1i(E,n);else if(A=="f")b.uniform1f(E,n);else if(A=="fv1")b.uniform1fv(E,n);else if(A=="fv")b.uniform3fv(E,n);else if(A=="v2")b.uniform2f(E,n.x,n.y);else if(A=="v3")b.uniform3f(E,n.x,n.y,n.z);else if(A=="c")b.uniform3f(E,n.r,n.g,n.b);else if(A=="t"){b.uniform1i(E,
@@ -195,8 +195,8 @@ b.bindTexture(b.TEXTURE_2D,n.__webGLTexture);b.texParameteri(b.TEXTURE_2D,b.TEXT
 n.__webGLTexture,0);b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,n.__webGLRenderbuffer);b.bindTexture(b.TEXTURE_2D,null);b.bindRenderbuffer(b.RENDERBUFFER,null);b.bindFramebuffer(b.FRAMEBUFFER,null)}if(n){x=n.__webGLFramebuffer;C=n.width;u=n.height}else{x=null;C=f.width;u=f.height}if(x!=h){b.bindFramebuffer(b.FRAMEBUFFER,x);b.viewport(0,0,C,u);j&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);h=x}this.autoClear&&this.clear();x=l.__webGLObjects.length;for(j=0;j<x;j++){E=
 l.__webGLObjects[j];C=E.object;C.visible&&C.autoUpdateMatrix&&C.updateMatrix()}u=l.__webGLObjectsImmediate.length;for(j=0;j<u;j++){E=l.__webGLObjectsImmediate[j];C=E.object;C.visible&&C.autoUpdateMatrix&&C.updateMatrix()}for(j=0;j<x;j++){E=l.__webGLObjects[j];C=E.object;u=E.buffer;if(C.visible){d(C);this.setupMatrices(C,A);this.renderPass(A,p,F,C,u,THREE.NormalBlending,false)}}for(j=0;j<l.__webGLObjectsImmediate.length;j++){E=l.__webGLObjectsImmediate[j];C=E.object;if(C.visible){d(C);this.setupMatrices(C,
 A);this.renderPassImmediate(A,p,F,C,THREE.NormalBlending,false)}}for(j=0;j<x;j++){E=l.__webGLObjects[j];C=E.object;u=E.buffer;if(C.visible){d(C);this.setupMatrices(C,A);this.renderPass(A,p,F,C,u,THREE.AdditiveBlending,false);this.renderPass(A,p,F,C,u,THREE.SubtractiveBlending,false);this.renderPass(A,p,F,C,u,THREE.AdditiveBlending,true);this.renderPass(A,p,F,C,u,THREE.SubtractiveBlending,true);this.renderPass(A,p,F,C,u,THREE.NormalBlending,true);this.renderPass(A,p,F,C,u,THREE.BillboardBlending,false)}}for(j=
-0;j<l.__webGLObjectsImmediate.length;j++){E=l.__webGLObjectsImmediate[j];C=E.object;if(C.visible){d(C);this.setupMatrices(C,A);this.renderPassImmediate(A,p,F,C,THREE.NormalBlending,true)}}if(n&&n.min_filter!==THREE.NearestFilter&&n.min_filter!==THREE.LinearFilter){b.bindTexture(b.TEXTURE_2D,n.__webGLTexture);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}};this.initWebGLObjects=function(l,A){function n(G,X,Q,P){if(G[X]==undefined){l.__webGLObjects.push({buffer:Q,object:P});G[X]=1}}
-function j(G,X,Q){if(G[X]==undefined){l.__webGLObjectsImmediate.push({object:Q});G[X]=1}}var x,u,E,C,p,F,M;if(!l.__webGLObjects){l.__webGLObjects=[];l.__webGLObjectsMap={};l.__webGLObjectsImmediate=[]}x=0;for(u=l.objects.length;x<u;x++){E=l.objects[x];p=E.geometry;if(l.__webGLObjectsMap[E.id]==undefined)l.__webGLObjectsMap[E.id]={};M=l.__webGLObjectsMap[E.id];if(E instanceof THREE.Mesh){for(C in p.geometryChunks){F=p.geometryChunks[C];if(!F.__webGLVertexBuffer){this.createMeshBuffers(F);this.initMeshBuffers(F,
+0;j<l.__webGLObjectsImmediate.length;j++){E=l.__webGLObjectsImmediate[j];C=E.object;if(C.visible){d(C);this.setupMatrices(C,A);this.renderPassImmediate(A,p,F,C,THREE.NormalBlending,true)}}if(n&&n.min_filter!==THREE.NearestFilter&&n.min_filter!==THREE.LinearFilter){b.bindTexture(b.TEXTURE_2D,n.__webGLTexture);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}};this.initWebGLObjects=function(l,A){function n(G,W,Q,O){if(G[W]==undefined){l.__webGLObjects.push({buffer:Q,object:O});G[W]=1}}
+function j(G,W,Q){if(G[W]==undefined){l.__webGLObjectsImmediate.push({object:Q});G[W]=1}}var x,u,E,C,p,F,M;if(!l.__webGLObjects){l.__webGLObjects=[];l.__webGLObjectsMap={};l.__webGLObjectsImmediate=[]}x=0;for(u=l.objects.length;x<u;x++){E=l.objects[x];p=E.geometry;if(l.__webGLObjectsMap[E.id]==undefined)l.__webGLObjectsMap[E.id]={};M=l.__webGLObjectsMap[E.id];if(E instanceof THREE.Mesh){for(C in p.geometryChunks){F=p.geometryChunks[C];if(!F.__webGLVertexBuffer){this.createMeshBuffers(F);this.initMeshBuffers(F,
 E);p.__dirtyVertices=true;p.__dirtyElements=true;p.__dirtyUvs=true;p.__dirtyNormals=true;p.__dirtyTangents=true;p.__dirtyColors=true}if(p.__dirtyVertices||p.__dirtyElements||p.__dirtyUvs||p.__dirtyNormals||p.__dirtyColors||p.__dirtyTangents)this.setMeshBuffers(F,E,b.DYNAMIC_DRAW);n(M,C,F,E)}p.__dirtyVertices=false;p.__dirtyElements=false;p.__dirtyUvs=false;p.__dirtyNormals=false;p.__dirtyTangents=false;p.__dirtyColors=false}else if(E instanceof THREE.Line){if(!p.__webGLVertexBuffer){this.createLineBuffers(p);
 this.initLineBuffers(p);p.__dirtyVertices=true;p.__dirtyElements=true;p.__dirtyColors=true}if(p.__dirtyVertices||p.__dirtyColors)this.setLineBuffers(p,b.DYNAMIC_DRAW);n(M,0,p,E);p.__dirtyVertices=false;p.__dirtyElements=false}else if(E instanceof THREE.ParticleSystem){if(!p.__webGLVertexBuffer){this.createParticleBuffers(p);this.initParticleBuffers(p);p.__dirtyVertices=true;p.__dirtyColors=true;p.__dirtyElements=true}if(p.__dirtyVertices||p.__dirtyColors||E.sortParticles)this.setParticleBuffers(p,
 b.DYNAMIC_DRAW,E,A);n(M,0,p,E);p.__dirtyVertices=false;p.__dirtyColors=false;p.__dirtyElements=false}else E instanceof THREE.MarchingCubes&&j(M,0,E)}};this.removeObject=function(l,A){var n,j;for(n=l.__webGLObjects.length-1;n>=0;n--){j=l.__webGLObjects[n].object;A==j&&l.__webGLObjects.splice(n,1)}};this.setupMatrices=function(l,A){m.multiply(A.matrix,l.matrix);v.set(m.flatten());o=THREE.Matrix4.makeInvert3x3(m).transpose();z.set(o.m);B.set(l.matrix.flatten())};this.loadMatrices=function(l){b.uniformMatrix4fv(l.uniforms.viewMatrix,
@@ -248,7 +248,7 @@ value:0,texture:null},uImageIncrement:{type:"v2",value:new THREE.Vector2(0.00195
 film:{uniforms:{tDiffuse:{type:"t",value:0,texture:null},time:{type:"f",value:0},grayscale:{type:"i",value:1}},vertex_shader:"varying vec2 vUv;\nvoid main() {\nvUv = vec2( uv.x, 1.0 - uv.y );\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragment_shader:"varying vec2 vUv;\nuniform sampler2D tDiffuse;\nuniform float time;\nuniform bool grayscale;\nconst float fNintensity = 0.35;\nconst float fSintensity = 0.35;\nconst float fScount = 4096.0;\nvoid main() {\nvec4 cTextureScreen = texture2D( tDiffuse, vUv );\nfloat x = vUv.x * vUv.y * time *  1000.0;\nx = mod( x, 13.0 ) * mod( x, 123.0 );\nfloat dx = mod( x, 0.01 );\nvec3 cResult = cTextureScreen.rgb + cTextureScreen.rgb * clamp( 0.1 + dx * 100.0, 0.0, 1.0 );\nvec2 sc = vec2( sin(vUv.y * fScount), cos(vUv.y * fScount) );\ncResult += cTextureScreen.rgb * vec3( sc.x, sc.y, sc.x ) * fSintensity;\ncResult = cTextureScreen.rgb + clamp( fNintensity, 0.0,1.0 ) * ( cResult - cTextureScreen.rgb );\nif( grayscale ) {\ncResult = vec3( cResult.r * 0.3 + cResult.g * 0.59 + cResult.b * 0.11 );\n}\ngl_FragColor =  vec4( cResult, cTextureScreen.a );\n}"},
 screen:{uniforms:{tDiffuse:{type:"t",value:0,texture:null},opacity:{type:"f",value:1}},vertex_shader:"varying vec2 vUv;\nvoid main() {\nvUv = vec2( uv.x, 1.0 - uv.y );\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragment_shader:"varying vec2 vUv;\nuniform sampler2D tDiffuse;\nuniform float opacity;\nvoid main() {\nvec4 texel = texture2D( tDiffuse, vUv );\ngl_FragColor = opacity * texel;\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}"}},buildKernel:function(a){var c,d,e,g,f=2*Math.ceil(a*3)+1;if(f>25)f=25;g=(f-1)*0.5;d=Array(f);for(c=e=0;c<f;++c){d[c]=Math.exp(-((c-g)*(c-g))/(2*a*a));e+=d[c]}for(c=0;c<f;++c)d[c]/=e;return d}},Cube=function(a,c,d,e,g,f,b,k){function h(B,H,w,I,t,L,l,A){var n,j,x=e||1,u=g||1,E=x+1,C=u+1,p=t/2,F=L/2;t=t/x;var M=L/u,G=m.vertices.length;if(B=="x"&&H=="y"||B=="y"&&H=="x")n="z";else if(B=="x"&&H=="z"||B=="z"&&H=="x")n="y";else if(B==
-"z"&&H=="y"||B=="y"&&H=="z")n="x";for(j=0;j<C;j++)for(L=0;L<E;L++){var X=new THREE.Vector3;X[B]=(L*t-p)*w;X[H]=(j*M-F)*I;X[n]=l;m.vertices.push(new THREE.Vertex(X))}for(j=0;j<u;j++)for(L=0;L<x;L++){m.faces.push(new THREE.Face4(L+E*j+G,L+E*(j+1)+G,L+1+E*(j+1)+G,L+1+E*j+G,null,A));m.uvs.push([new THREE.UV(L/x,j/u),new THREE.UV(L/x,(j+1)/u),new THREE.UV((L+1)/x,(j+1)/u),new THREE.UV((L+1)/x,j/u)])}}THREE.Geometry.call(this);var m=this,o=a/2,y=c/2,v=d/2;b=b?-1:1;if(f!==undefined)if(f instanceof Array)this.materials=
+"z"&&H=="y"||B=="y"&&H=="z")n="x";for(j=0;j<C;j++)for(L=0;L<E;L++){var W=new THREE.Vector3;W[B]=(L*t-p)*w;W[H]=(j*M-F)*I;W[n]=l;m.vertices.push(new THREE.Vertex(W))}for(j=0;j<u;j++)for(L=0;L<x;L++){m.faces.push(new THREE.Face4(L+E*j+G,L+E*(j+1)+G,L+1+E*(j+1)+G,L+1+E*j+G,null,A));m.uvs.push([new THREE.UV(L/x,j/u),new THREE.UV(L/x,(j+1)/u),new THREE.UV((L+1)/x,(j+1)/u),new THREE.UV((L+1)/x,j/u)])}}THREE.Geometry.call(this);var m=this,o=a/2,y=c/2,v=d/2;b=b?-1:1;if(f!==undefined)if(f instanceof Array)this.materials=
 f;else{this.materials=[];for(var q=0;q<6;q++)this.materials.push([f])}else this.materials=[];this.sides={px:true,nx:true,py:true,ny:true,pz:true,nz:true};if(k!=undefined)for(var z in k)if(this.sides[z]!=undefined)this.sides[z]=k[z];this.sides.px&&h("z","y",1*b,-1,d,c,-o,this.materials[0]);this.sides.nx&&h("z","y",-1*b,-1,d,c,o,this.materials[1]);this.sides.py&&h("x","z",1*b,1,a,d,y,this.materials[2]);this.sides.ny&&h("x","z",1*b,-1,a,d,-y,this.materials[3]);this.sides.pz&&h("x","y",1*b,-1,a,c,v,this.materials[4]);
 this.sides.nz&&h("x","y",-1*b,-1,a,c,-v,this.materials[5]);(function(){for(var B=[],H=[],w=0,I=m.vertices.length;w<I;w++){for(var t=m.vertices[w],L=false,l=0,A=B.length;l<A;l++){var n=B[l];if(t.position.x==n.position.x&&t.position.y==n.position.y&&t.position.z==n.position.z){H[w]=l;L=true;break}}if(!L){H[w]=B.length;B.push(new THREE.Vertex(t.position.clone()))}}w=0;for(I=m.faces.length;w<I;w++){t=m.faces[w];t.a=H[t.a];t.b=H[t.b];t.c=H[t.c];t.d=H[t.d]}m.vertices=B})();this.computeCentroids();this.computeFaceNormals();
 this.sortFacesByMaterial()};Cube.prototype=new THREE.Geometry;Cube.prototype.constructor=Cube;
@@ -309,15 +309,15 @@ c},loadAsciiOld:function(a,c){var d=document.createElement("script");d.type="tex
 THREE.Loader.prototype.extractUrlbase(c),g=a.bin_path?a.bin_path:THREE.Loader.prototype.extractUrlbase(c);a=(new Date).getTime();c=new Worker(c);var f=this.showProgress?THREE.Loader.prototype.updateProgress:null;c.onmessage=function(b){THREE.Loader.prototype.loadAjaxBuffers(b.data.buffers,b.data.materials,d,g,e,f)};c.onerror=function(b){alert("worker.onerror: "+b.message+"\n"+b.data);b.preventDefault()};c.postMessage(a)},loadAjaxBuffers:function(a,c,d,e,g,f){var b=new XMLHttpRequest,k=e+"/"+a,h=0;
 b.onreadystatechange=function(){if(b.readyState==4)b.status==200||b.status==0?THREE.Loader.prototype.createBinModel(b.responseText,d,g,c):alert("Couldn't load ["+k+"] ["+b.status+"]");else if(b.readyState==3){if(f){if(h==0)h=b.getResponseHeader("Content-Length");f({total:h,loaded:b.responseText.length})}}else if(b.readyState==2)h=b.getResponseHeader("Content-Length")};b.open("GET",k,true);b.overrideMimeType("text/plain; charset=x-user-defined");b.setRequestHeader("Content-Type","text/plain");b.send(null)},
 createBinModel:function(a,c,d,e){var g=function(f){function b(D,J){var N=o(D,J),V=o(D,J+1),da=o(D,J+2),ga=o(D,J+3),ia=(ga<<1&255|da>>7)-127;N=(da&127)<<16|V<<8|N;if(N==0&&ia==-127)return 0;return(1-2*(ga>>7))*(1+N*Math.pow(2,-23))*Math.pow(2,ia)}function k(D,J){var N=o(D,J),V=o(D,J+1),da=o(D,J+2);return(o(D,J+3)<<24)+(da<<16)+(V<<8)+N}function h(D,J){var N=o(D,J);return(o(D,J+1)<<8)+N}function m(D,J){var N=o(D,J);return N>127?N-256:N}function o(D,J){return D.charCodeAt(J)&255}function y(D){var J,
-N,V;J=k(a,D);N=k(a,D+A);V=k(a,D+n);D=h(a,D+j);THREE.Loader.prototype.f3(w,J,N,V,D)}function v(D){var J,N,V,da,ga,ia;J=k(a,D);N=k(a,D+A);V=k(a,D+n);da=h(a,D+j);ga=k(a,D+x);ia=k(a,D+u);D=k(a,D+E);THREE.Loader.prototype.f3n(w,L,J,N,V,da,ga,ia,D)}function q(D){var J,N,V,da;J=k(a,D);N=k(a,D+C);V=k(a,D+p);da=k(a,D+F);D=h(a,D+M);THREE.Loader.prototype.f4(w,J,N,V,da,D)}function z(D){var J,N,V,da,ga,ia,ta,qa;J=k(a,D);N=k(a,D+C);V=k(a,D+p);da=k(a,D+F);ga=h(a,D+M);ia=k(a,D+G);ta=k(a,D+X);qa=k(a,D+Q);D=k(a,D+
-P);THREE.Loader.prototype.f4n(w,L,J,N,V,da,ga,ia,ta,qa,D)}function B(D){var J,N;J=k(a,D);N=k(a,D+ca);D=k(a,D+aa);THREE.Loader.prototype.uv3(w.uvs,l[J*2],l[J*2+1],l[N*2],l[N*2+1],l[D*2],l[D*2+1])}function H(D){var J,N,V;J=k(a,D);N=k(a,D+T);V=k(a,D+R);D=k(a,D+W);THREE.Loader.prototype.uv4(w.uvs,l[J*2],l[J*2+1],l[N*2],l[N*2+1],l[V*2],l[V*2+1],l[D*2],l[D*2+1])}var w=this,I=0,t,L=[],l=[],A,n,j,x,u,E,C,p,F,M,G,X,Q,P,ca,aa,T,R,W,Y,K,U,ba,ja,ha;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(w,
+N,V;J=k(a,D);N=k(a,D+A);V=k(a,D+n);D=h(a,D+j);THREE.Loader.prototype.f3(w,J,N,V,D)}function v(D){var J,N,V,da,ga,ia;J=k(a,D);N=k(a,D+A);V=k(a,D+n);da=h(a,D+j);ga=k(a,D+x);ia=k(a,D+u);D=k(a,D+E);THREE.Loader.prototype.f3n(w,L,J,N,V,da,ga,ia,D)}function q(D){var J,N,V,da;J=k(a,D);N=k(a,D+C);V=k(a,D+p);da=k(a,D+F);D=h(a,D+M);THREE.Loader.prototype.f4(w,J,N,V,da,D)}function z(D){var J,N,V,da,ga,ia,ta,qa;J=k(a,D);N=k(a,D+C);V=k(a,D+p);da=k(a,D+F);ga=h(a,D+M);ia=k(a,D+G);ta=k(a,D+W);qa=k(a,D+Q);D=k(a,D+
+O);THREE.Loader.prototype.f4n(w,L,J,N,V,da,ga,ia,ta,qa,D)}function B(D){var J,N;J=k(a,D);N=k(a,D+ba);D=k(a,D+ca);THREE.Loader.prototype.uv3(w.uvs,l[J*2],l[J*2+1],l[N*2],l[N*2+1],l[D*2],l[D*2+1])}function H(D){var J,N,V;J=k(a,D);N=k(a,D+U);V=k(a,D+R);D=k(a,D+X);THREE.Loader.prototype.uv4(w.uvs,l[J*2],l[J*2+1],l[N*2],l[N*2+1],l[V*2],l[V*2+1],l[D*2],l[D*2+1])}var w=this,I=0,t,L=[],l=[],A,n,j,x,u,E,C,p,F,M,G,W,Q,O,ba,ca,U,R,X,Y,K,T,aa,ja,ha;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(w,
 e,f);t={signature:a.substr(I,8),header_bytes:o(a,I+8),vertex_coordinate_bytes:o(a,I+9),normal_coordinate_bytes:o(a,I+10),uv_coordinate_bytes:o(a,I+11),vertex_index_bytes:o(a,I+12),normal_index_bytes:o(a,I+13),uv_index_bytes:o(a,I+14),material_index_bytes:o(a,I+15),nvertices:k(a,I+16),nnormals:k(a,I+16+4),nuvs:k(a,I+16+8),ntri_flat:k(a,I+16+12),ntri_smooth:k(a,I+16+16),ntri_flat_uv:k(a,I+16+20),ntri_smooth_uv:k(a,I+16+24),nquad_flat:k(a,I+16+28),nquad_smooth:k(a,I+16+32),nquad_flat_uv:k(a,I+16+36),
-nquad_smooth_uv:k(a,I+16+40)};I+=t.header_bytes;A=t.vertex_index_bytes;n=t.vertex_index_bytes*2;j=t.vertex_index_bytes*3;x=t.vertex_index_bytes*3+t.material_index_bytes;u=t.vertex_index_bytes*3+t.material_index_bytes+t.normal_index_bytes;E=t.vertex_index_bytes*3+t.material_index_bytes+t.normal_index_bytes*2;C=t.vertex_index_bytes;p=t.vertex_index_bytes*2;F=t.vertex_index_bytes*3;M=t.vertex_index_bytes*4;G=t.vertex_index_bytes*4+t.material_index_bytes;X=t.vertex_index_bytes*4+t.material_index_bytes+
-t.normal_index_bytes;Q=t.vertex_index_bytes*4+t.material_index_bytes+t.normal_index_bytes*2;P=t.vertex_index_bytes*4+t.material_index_bytes+t.normal_index_bytes*3;ca=t.uv_index_bytes;aa=t.uv_index_bytes*2;T=t.uv_index_bytes;R=t.uv_index_bytes*2;W=t.uv_index_bytes*3;f=t.vertex_index_bytes*3+t.material_index_bytes;ha=t.vertex_index_bytes*4+t.material_index_bytes;Y=t.ntri_flat*f;K=t.ntri_smooth*(f+t.normal_index_bytes*3);U=t.ntri_flat_uv*(f+t.uv_index_bytes*3);ba=t.ntri_smooth_uv*(f+t.normal_index_bytes*
+nquad_smooth_uv:k(a,I+16+40)};I+=t.header_bytes;A=t.vertex_index_bytes;n=t.vertex_index_bytes*2;j=t.vertex_index_bytes*3;x=t.vertex_index_bytes*3+t.material_index_bytes;u=t.vertex_index_bytes*3+t.material_index_bytes+t.normal_index_bytes;E=t.vertex_index_bytes*3+t.material_index_bytes+t.normal_index_bytes*2;C=t.vertex_index_bytes;p=t.vertex_index_bytes*2;F=t.vertex_index_bytes*3;M=t.vertex_index_bytes*4;G=t.vertex_index_bytes*4+t.material_index_bytes;W=t.vertex_index_bytes*4+t.material_index_bytes+
+t.normal_index_bytes;Q=t.vertex_index_bytes*4+t.material_index_bytes+t.normal_index_bytes*2;O=t.vertex_index_bytes*4+t.material_index_bytes+t.normal_index_bytes*3;ba=t.uv_index_bytes;ca=t.uv_index_bytes*2;U=t.uv_index_bytes;R=t.uv_index_bytes*2;X=t.uv_index_bytes*3;f=t.vertex_index_bytes*3+t.material_index_bytes;ha=t.vertex_index_bytes*4+t.material_index_bytes;Y=t.ntri_flat*f;K=t.ntri_smooth*(f+t.normal_index_bytes*3);T=t.ntri_flat_uv*(f+t.uv_index_bytes*3);aa=t.ntri_smooth_uv*(f+t.normal_index_bytes*
 3+t.uv_index_bytes*3);ja=t.nquad_flat*ha;f=t.nquad_smooth*(ha+t.normal_index_bytes*4);ha=t.nquad_flat_uv*(ha+t.uv_index_bytes*4);I+=function(D){var J,N,V,da=t.vertex_coordinate_bytes*3,ga=D+t.nvertices*da;for(D=D;D<ga;D+=da){J=b(a,D);N=b(a,D+t.vertex_coordinate_bytes);V=b(a,D+t.vertex_coordinate_bytes*2);THREE.Loader.prototype.v(w,J,N,V)}return t.nvertices*da}(I);I+=function(D){var J,N,V,da=t.normal_coordinate_bytes*3,ga=D+t.nnormals*da;for(D=D;D<ga;D+=da){J=m(a,D);N=m(a,D+t.normal_coordinate_bytes);
-V=m(a,D+t.normal_coordinate_bytes*2);L.push(J/127,N/127,V/127)}return t.nnormals*da}(I);I+=function(D){var J,N,V=t.uv_coordinate_bytes*2,da=D+t.nuvs*V;for(D=D;D<da;D+=V){J=b(a,D);N=b(a,D+t.uv_coordinate_bytes);l.push(J,N)}return t.nuvs*V}(I);I=I;Y=I+Y;K=Y+K;U=K+U;ba=U+ba;ja=ba+ja;f=ja+f;ha=f+ha;(function(D){var J,N=t.vertex_index_bytes*3+t.material_index_bytes,V=N+t.uv_index_bytes*3,da=D+t.ntri_flat_uv*V;for(J=D;J<da;J+=V){y(J);B(J+N)}return da-D})(K);(function(D){var J,N=t.vertex_index_bytes*3+t.material_index_bytes+
-t.normal_index_bytes*3,V=N+t.uv_index_bytes*3,da=D+t.ntri_smooth_uv*V;for(J=D;J<da;J+=V){v(J);B(J+N)}return da-D})(U);(function(D){var J,N=t.vertex_index_bytes*4+t.material_index_bytes,V=N+t.uv_index_bytes*4,da=D+t.nquad_flat_uv*V;for(J=D;J<da;J+=V){q(J);H(J+N)}return da-D})(f);(function(D){var J,N=t.vertex_index_bytes*4+t.material_index_bytes+t.normal_index_bytes*4,V=N+t.uv_index_bytes*4,da=D+t.nquad_smooth_uv*V;for(J=D;J<da;J+=V){z(J);H(J+N)}return da-D})(ha);(function(D){var J,N=t.vertex_index_bytes*
-3+t.material_index_bytes,V=D+t.ntri_flat*N;for(J=D;J<V;J+=N)y(J);return V-D})(I);(function(D){var J,N=t.vertex_index_bytes*3+t.material_index_bytes+t.normal_index_bytes*3,V=D+t.ntri_smooth*N;for(J=D;J<V;J+=N)v(J);return V-D})(Y);(function(D){var J,N=t.vertex_index_bytes*4+t.material_index_bytes,V=D+t.nquad_flat*N;for(J=D;J<V;J+=N)q(J);return V-D})(ba);(function(D){var J,N=t.vertex_index_bytes*4+t.material_index_bytes+t.normal_index_bytes*4,V=D+t.nquad_smooth*N;for(J=D;J<V;J+=N)z(J);return V-D})(ja);
+V=m(a,D+t.normal_coordinate_bytes*2);L.push(J/127,N/127,V/127)}return t.nnormals*da}(I);I+=function(D){var J,N,V=t.uv_coordinate_bytes*2,da=D+t.nuvs*V;for(D=D;D<da;D+=V){J=b(a,D);N=b(a,D+t.uv_coordinate_bytes);l.push(J,N)}return t.nuvs*V}(I);I=I;Y=I+Y;K=Y+K;T=K+T;aa=T+aa;ja=aa+ja;f=ja+f;ha=f+ha;(function(D){var J,N=t.vertex_index_bytes*3+t.material_index_bytes,V=N+t.uv_index_bytes*3,da=D+t.ntri_flat_uv*V;for(J=D;J<da;J+=V){y(J);B(J+N)}return da-D})(K);(function(D){var J,N=t.vertex_index_bytes*3+t.material_index_bytes+
+t.normal_index_bytes*3,V=N+t.uv_index_bytes*3,da=D+t.ntri_smooth_uv*V;for(J=D;J<da;J+=V){v(J);B(J+N)}return da-D})(T);(function(D){var J,N=t.vertex_index_bytes*4+t.material_index_bytes,V=N+t.uv_index_bytes*4,da=D+t.nquad_flat_uv*V;for(J=D;J<da;J+=V){q(J);H(J+N)}return da-D})(f);(function(D){var J,N=t.vertex_index_bytes*4+t.material_index_bytes+t.normal_index_bytes*4,V=N+t.uv_index_bytes*4,da=D+t.nquad_smooth_uv*V;for(J=D;J<da;J+=V){z(J);H(J+N)}return da-D})(ha);(function(D){var J,N=t.vertex_index_bytes*
+3+t.material_index_bytes,V=D+t.ntri_flat*N;for(J=D;J<V;J+=N)y(J);return V-D})(I);(function(D){var J,N=t.vertex_index_bytes*3+t.material_index_bytes+t.normal_index_bytes*3,V=D+t.ntri_smooth*N;for(J=D;J<V;J+=N)v(J);return V-D})(Y);(function(D){var J,N=t.vertex_index_bytes*4+t.material_index_bytes,V=D+t.nquad_flat*N;for(J=D;J<V;J+=N)q(J);return V-D})(aa);(function(D){var J,N=t.vertex_index_bytes*4+t.material_index_bytes+t.normal_index_bytes*4,V=D+t.nquad_smooth*N;for(J=D;J<V;J+=N)z(J);return V-D})(ja);
 this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};g.prototype=new THREE.Geometry;g.prototype.constructor=g;c(new g(d))},createModel:function(a,c,d){var e=function(g){var f=this;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(f,a.materials,g);(function(){var b,k,h,m,o;b=0;for(k=a.vertices.length;b<k;b+=3){h=a.vertices[b];m=a.vertices[b+1];o=a.vertices[b+2];THREE.Loader.prototype.v(f,h,m,o)}})();(function(){function b(z,B){THREE.Loader.prototype.f3(f,z[B],
 z[B+1],z[B+2],z[B+3])}function k(z,B){THREE.Loader.prototype.f3n(f,a.normals,z[B],z[B+1],z[B+2],z[B+3],z[B+4],z[B+5],z[B+6])}function h(z,B){THREE.Loader.prototype.f4(f,z[B],z[B+1],z[B+2],z[B+3],z[B+4])}function m(z,B){THREE.Loader.prototype.f4n(f,a.normals,z[B],z[B+1],z[B+2],z[B+3],z[B+4],z[B+5],z[B+6],z[B+7],z[B+8])}function o(z,B){var H,w,I,t,L,l,A,n,j;H=z[B];w=z[B+1];I=z[B+2];t=a.uvs[H*2];A=a.uvs[H*2+1];L=a.uvs[w*2];n=a.uvs[w*2+1];l=a.uvs[I*2];j=a.uvs[I*2+1];THREE.Loader.prototype.uv3(f.uvs,t,
 A,L,n,l,j);if(a.uvs2){t=a.uvs2[H*2];A=a.uvs2[H*2+1];L=a.uvs2[w*2];n=a.uvs2[w*2+1];l=a.uvs2[I*2];j=a.uvs2[I*2+1];THREE.Loader.prototype.uv3(f.uvs2,t,1-A,L,1-n,l,1-j)}}function y(z,B){var H,w,I,t,L,l,A,n,j,x,u,E;H=z[B];w=z[B+1];I=z[B+2];t=z[B+3];L=a.uvs[H*2];j=a.uvs[H*2+1];l=a.uvs[w*2];x=a.uvs[w*2+1];A=a.uvs[I*2];u=a.uvs[I*2+1];n=a.uvs[t*2];E=a.uvs[t*2+1];THREE.Loader.prototype.uv4(f.uvs,L,j,l,x,A,u,n,E);if(a.uvs2){L=a.uvs2[H*2];j=a.uvs2[H*2+1];l=a.uvs2[w*2];x=a.uvs2[w*2+1];A=a.uvs2[I*2];u=a.uvs2[I*

+ 11 - 1
examples/lights_test.html

@@ -196,10 +196,20 @@
 
 			}
 
-			var r = 0;
+			var r = 0, counter = 0;
 
 			function loop() {
 
+				if( counter == 30 ) {
+					
+					scene.removeLight( directionalLight );
+					
+				} else {
+				
+					counter++;
+					
+				}
+				
 				camera.position.x += ( mouseX - camera.position.x ) * .05;
 				camera.position.y += ( - mouseY - camera.position.y ) * .05;
 				camera.updateMatrix();

+ 26 - 13
src/renderers/WebGLRenderer.js

@@ -107,7 +107,10 @@ THREE.WebGLRenderer = function ( parameters ) {
 			ppositions = zlights.point.positions,
 
 			dlength = 0,
-			plength = 0;
+			plength = 0,
+		
+			doffset = 0,
+			poffset = 0;
 
 		for ( l = 0, ll = lights.length; l < ll; l++ ) {
 
@@ -124,31 +127,41 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 			} else if ( light instanceof THREE.DirectionalLight ) {
 
-				dcolors[ dlength*3 ]     = color.r * intensity;
-				dcolors[ dlength*3 + 1 ] = color.g * intensity;
-				dcolors[ dlength*3 + 2 ] = color.b * intensity;
+				doffset = dlength * 3;
+				
+				dcolors[ doffset ]     = color.r * intensity;
+				dcolors[ doffset + 1 ] = color.g * intensity;
+				dcolors[ doffset + 2 ] = color.b * intensity;
 
-				dpositions[ dlength*3 ]     = position.x;
-				dpositions[ dlength*3 + 1 ] = position.y;
-				dpositions[ dlength*3 + 2 ] = position.z;
+				dpositions[ doffset ]     = position.x;
+				dpositions[ doffset + 1 ] = position.y;
+				dpositions[ doffset + 2 ] = position.z;
 
 				dlength += 1;
 
 			} else if( light instanceof THREE.PointLight ) {
 
-				pcolors[ plength*3 ]     = color.r * intensity;
-				pcolors[ plength*3 + 1 ] = color.g * intensity;
-				pcolors[ plength*3 + 2 ] = color.b * intensity;
+				poffset = plength * 3;
+				
+				pcolors[ poffset ]     = color.r * intensity;
+				pcolors[ poffset + 1 ] = color.g * intensity;
+				pcolors[ poffset + 2 ] = color.b * intensity;
 
-				ppositions[ plength*3 ]     = position.x;
-				ppositions[ plength*3 + 1 ] = position.y;
-				ppositions[ plength*3 + 2 ] = position.z;
+				ppositions[ poffset ]     = position.x;
+				ppositions[ poffset + 1 ] = position.y;
+				ppositions[ poffset + 2 ] = position.z;
 
 				plength += 1;
 
 			}
 
 		}
+		
+		// null eventual remains from removed lights
+		// (this is to avoid if in shader)
+		
+		for( l = dlength * 3; l < dcolors.length; l++ ) dcolors[ l ] = 0.0;
+		for( l = plength * 3; l < pcolors.length; l++ ) pcolors[ l ] = 0.0;
 
 		zlights.point.length = plength;
 		zlights.directional.length = dlength;