Browse Source

Fixed bug(s) causing broken Fresnel demo.

As suspected, this was caused by incorrect shader state management when switching between multiple shaders (thanks Firefox for verbose warnings).

Also, testing WebGL performance is very tricky. You can get different performance depending on the state of browsers / system (messed up state can be 10-66% slower):

1. freshly started Chrome can be much faster than Chrome that already ran few WebGL demos (which are now closed)
2. demo opened in new Chrome tab can be faster than demo reloaded in the same tab
3. even demos opened and closed in Firefox can slow down Chrome demos

This suggests that browsers do not clean GPU state properly :(
alteredq 14 years ago
parent
commit
a1d68ddba3
5 changed files with 435 additions and 401 deletions
  1. 102 101
      build/Three.js
  2. 103 102
      build/ThreeDebug.js
  3. 128 127
      build/ThreeExtras.js
  4. 2 3
      examples/materials_shaders_fresnel.html
  5. 100 68
      src/renderers/WebGLRenderer.js

+ 102 - 101
build/Three.js

@@ -12,42 +12,43 @@ THREE.Vector4=function(a,b,d,i){this.x=a||0;this.y=b||0;this.z=d||0;this.w=i||1}
 THREE.Vector4.prototype={set:function(a,b,d,i){this.x=a;this.y=b;this.z=d;this.w=i;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w||1;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;
 THREE.Vector4.prototype={set:function(a,b,d,i){this.x=a;this.y=b;this.z=d;this.w=i;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w||1;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;
 return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=a;this.w/=a;return this},lerpSelf:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},toString:function(){return"THREE.Vector4 ("+this.x+", "+this.y+", "+this.z+", "+this.w+")"}};
 return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=a;this.w/=a;return this},lerpSelf:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},toString:function(){return"THREE.Vector4 ("+this.x+", "+this.y+", "+this.z+", "+this.w+")"}};
 THREE.Ray=function(a,b){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3};
 THREE.Ray=function(a,b){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3};
-THREE.Ray.prototype={intersectScene:function(a){var b,d,i=a.objects,j=[];a=0;for(b=i.length;a<b;a++){d=i[a];if(d instanceof THREE.Mesh)j=j.concat(this.intersectObject(d))}j.sort(function(o,m){return o.distance-m.distance});return j},intersectObject:function(a){function b(M,r,R,B){B=B.clone().subSelf(r);R=R.clone().subSelf(r);var e=M.clone().subSelf(r);M=B.dot(B);r=B.dot(R);B=B.dot(e);var f=R.dot(R);R=R.dot(e);e=1/(M*f-r*r);f=(f*B-r*R)*e;M=(M*R-r*B)*e;return f>0&&M>0&&f+M<1}var d,i,j,o,m,q,l,c,z,G,
-x,F=a.geometry,N=F.vertices,J=[];d=0;for(i=F.faces.length;d<i;d++){j=F.faces[d];G=this.origin.clone();x=this.direction.clone();o=a.matrix.transformVector3(N[j.a].position.clone());m=a.matrix.transformVector3(N[j.b].position.clone());q=a.matrix.transformVector3(N[j.c].position.clone());l=j instanceof THREE.Face4?a.matrix.transformVector3(N[j.d].position.clone()):null;c=a.rotationMatrix.transformVector3(j.normal.clone());z=x.dot(c);if(z<0){c=c.dot((new THREE.Vector3).sub(o,G))/z;G=G.addSelf(x.multiplyScalar(c));
-if(j instanceof THREE.Face3){if(b(G,o,m,q)){j={distance:this.origin.distanceTo(G),point:G,face:j,object:a};J.push(j)}}else if(j instanceof THREE.Face4)if(b(G,o,m,l)||b(G,m,q,l)){j={distance:this.origin.distanceTo(G),point:G,face:j,object:a};J.push(j)}}}return J}};
-THREE.Rectangle=function(){function a(){o=i-b;m=j-d}var b,d,i,j,o,m,q=true;this.getX=function(){return b};this.getY=function(){return d};this.getWidth=function(){return o};this.getHeight=function(){return m};this.getLeft=function(){return b};this.getTop=function(){return d};this.getRight=function(){return i};this.getBottom=function(){return j};this.set=function(l,c,z,G){q=false;b=l;d=c;i=z;j=G;a()};this.addPoint=function(l,c){if(q){q=false;b=l;d=c;i=l;j=c}else{b=Math.min(b,l);d=Math.min(d,c);i=Math.max(i,
-l);j=Math.max(j,c)}a()};this.addRectangle=function(l){if(q){q=false;b=l.getLeft();d=l.getTop();i=l.getRight();j=l.getBottom()}else{b=Math.min(b,l.getLeft());d=Math.min(d,l.getTop());i=Math.max(i,l.getRight());j=Math.max(j,l.getBottom())}a()};this.inflate=function(l){b-=l;d-=l;i+=l;j+=l;a()};this.minSelf=function(l){b=Math.max(b,l.getLeft());d=Math.max(d,l.getTop());i=Math.min(i,l.getRight());j=Math.min(j,l.getBottom());a()};this.instersects=function(l){return Math.min(i,l.getRight())-Math.max(b,l.getLeft())>=
-0&&Math.min(j,l.getBottom())-Math.max(d,l.getTop())>=0};this.empty=function(){q=true;j=i=d=b=0;a()};this.isEmpty=function(){return q};this.toString=function(){return"THREE.Rectangle ( left: "+b+", right: "+i+", top: "+d+", bottom: "+j+", width: "+o+", height: "+m+" )"}};THREE.Matrix3=function(){this.m=[]};THREE.Matrix3.prototype={transpose:function(){var a;a=this.m[1];this.m[1]=this.m[3];this.m[3]=a;a=this.m[2];this.m[2]=this.m[6];this.m[6]=a;a=this.m[5];this.m[5]=this.m[7];this.m[7]=a;return this}};
+THREE.Ray.prototype={intersectScene:function(a){var b,d,i=a.objects,j=[];a=0;for(b=i.length;a<b;a++){d=i[a];if(d instanceof THREE.Mesh)j=j.concat(this.intersectObject(d))}j.sort(function(o,m){return o.distance-m.distance});return j},intersectObject:function(a){function b(M,r,S,z){z=z.clone().subSelf(r);S=S.clone().subSelf(r);var f=M.clone().subSelf(r);M=z.dot(z);r=z.dot(S);z=z.dot(f);var k=S.dot(S);S=S.dot(f);f=1/(M*k-r*r);k=(k*z-r*S)*f;M=(M*S-r*z)*f;return k>0&&M>0&&k+M<1}var d,i,j,o,m,p,l,c,E,G,
+w,F=a.geometry,O=F.vertices,J=[];d=0;for(i=F.faces.length;d<i;d++){j=F.faces[d];G=this.origin.clone();w=this.direction.clone();o=a.matrix.multiplyVector3(O[j.a].position.clone());m=a.matrix.multiplyVector3(O[j.b].position.clone());p=a.matrix.multiplyVector3(O[j.c].position.clone());l=j instanceof THREE.Face4?a.matrix.multiplyVector3(O[j.d].position.clone()):null;c=a.rotationMatrix.multiplyVector3(j.normal.clone());E=w.dot(c);if(E<0){c=c.dot((new THREE.Vector3).sub(o,G))/E;G=G.addSelf(w.multiplyScalar(c));
+if(j instanceof THREE.Face3){if(b(G,o,m,p)){j={distance:this.origin.distanceTo(G),point:G,face:j,object:a};J.push(j)}}else if(j instanceof THREE.Face4)if(b(G,o,m,l)||b(G,m,p,l)){j={distance:this.origin.distanceTo(G),point:G,face:j,object:a};J.push(j)}}}return J}};
+THREE.Rectangle=function(){function a(){o=i-b;m=j-d}var b,d,i,j,o,m,p=true;this.getX=function(){return b};this.getY=function(){return d};this.getWidth=function(){return o};this.getHeight=function(){return m};this.getLeft=function(){return b};this.getTop=function(){return d};this.getRight=function(){return i};this.getBottom=function(){return j};this.set=function(l,c,E,G){p=false;b=l;d=c;i=E;j=G;a()};this.addPoint=function(l,c){if(p){p=false;b=l;d=c;i=l;j=c}else{b=Math.min(b,l);d=Math.min(d,c);i=Math.max(i,
+l);j=Math.max(j,c)}a()};this.addRectangle=function(l){if(p){p=false;b=l.getLeft();d=l.getTop();i=l.getRight();j=l.getBottom()}else{b=Math.min(b,l.getLeft());d=Math.min(d,l.getTop());i=Math.max(i,l.getRight());j=Math.max(j,l.getBottom())}a()};this.inflate=function(l){b-=l;d-=l;i+=l;j+=l;a()};this.minSelf=function(l){b=Math.max(b,l.getLeft());d=Math.max(d,l.getTop());i=Math.min(i,l.getRight());j=Math.min(j,l.getBottom());a()};this.instersects=function(l){return Math.min(i,l.getRight())-Math.max(b,l.getLeft())>=
+0&&Math.min(j,l.getBottom())-Math.max(d,l.getTop())>=0};this.empty=function(){p=true;j=i=d=b=0;a()};this.isEmpty=function(){return p};this.toString=function(){return"THREE.Rectangle ( left: "+b+", right: "+i+", top: "+d+", bottom: "+j+", width: "+o+", height: "+m+" )"}};THREE.Matrix3=function(){this.m=[]};THREE.Matrix3.prototype={transpose:function(){var a;a=this.m[1];this.m[1]=this.m[3];this.m[3]=a;a=this.m[2];this.m[2]=this.m[6];this.m[6]=a;a=this.m[5];this.m[5]=this.m[7];this.m[7]=a;return this}};
 THREE.Matrix4=function(){};
 THREE.Matrix4=function(){};
 THREE.Matrix4.prototype={n11:1,n12:0,n13:0,n14:0,n21:0,n22:1,n23:0,n24:0,n31:0,n32:0,n33:1,n34:0,n41:0,n42:0,n43:0,n44:1,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},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=
 THREE.Matrix4.prototype={n11:1,n12:0,n13:0,n14:0,n21:0,n22:1,n23:0,n24:0,n31:0,n32:0,n33:1,n34:0,n41:0,n42:0,n43:0,n44:1,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},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},lookAt:function(a,b,d){var i=new THREE.Vector3,j=new THREE.Vector3,o=new THREE.Vector3;o.sub(a,b).normalize();i.cross(d,o).normalize();j.cross(o,i).normalize();this.n11=i.x;this.n12=i.y;this.n13=i.z;this.n14=-i.dot(a);this.n21=j.x;this.n22=j.y;this.n23=j.z;this.n24=-j.dot(a);this.n31=o.x;this.n32=o.y;this.n33=o.z;this.n34=-o.dot(a);this.n43=this.n42=this.n41=0;this.n44=1},transformVector3:function(a){var b=a.x,d=a.y,i=a.z,j=1/(this.n41*b+this.n42*
-d+this.n43*i+this.n44);a.x=(this.n11*b+this.n12*d+this.n13*i+this.n14)*j;a.y=(this.n21*b+this.n22*d+this.n23*i+this.n24)*j;a.z=(this.n31*b+this.n32*d+this.n33*i+this.n34)*j;return a},transformVector4:function(a){var b=a.x,d=a.y,i=a.z,j=a.w;a.x=this.n11*b+this.n12*d+this.n13*i+this.n14*j;a.y=this.n21*b+this.n22*d+this.n23*i+this.n24*j;a.z=this.n31*b+this.n32*d+this.n33*i+this.n34*j;a.w=this.n41*b+this.n42*d+this.n43*i+this.n44*j;return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*
-a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var d=a.n11,i=a.n12,j=a.n13,o=a.n14,m=a.n21,q=a.n22,l=a.n23,c=a.n24,z=a.n31,G=a.n32,x=a.n33,F=a.n34,N=a.n41,J=a.n42,M=a.n43,r=a.n44,R=b.n11,B=b.n12,e=b.n13,f=b.n14,k=b.n21,n=b.n22,g=b.n23,h=b.n24,w=b.n31,s=b.n32,L=b.n33,u=b.n34,T=b.n41,P=b.n42,t=b.n43,
-H=b.n44;this.n11=d*R+i*k+j*w+o*T;this.n12=d*B+i*n+j*s+o*P;this.n13=d*e+i*g+j*L+o*t;this.n14=d*f+i*h+j*u+o*H;this.n21=m*R+q*k+l*w+c*T;this.n22=m*B+q*n+l*s+c*P;this.n23=m*e+q*g+l*L+c*t;this.n24=m*f+q*h+l*u+c*H;this.n31=z*R+G*k+x*w+F*T;this.n32=z*B+G*n+x*s+F*P;this.n33=z*e+G*g+x*L+F*t;this.n34=z*f+G*h+x*u+F*H;this.n41=N*R+J*k+M*w+r*T;this.n42=N*B+J*n+M*s+r*P;this.n43=N*e+J*g+M*L+r*t;this.n44=N*f+J*h+M*u+r*H},multiplySelf:function(a){var b=this.n11,d=this.n12,i=this.n13,j=this.n14,o=this.n21,m=this.n22,
-q=this.n23,l=this.n24,c=this.n31,z=this.n32,G=this.n33,x=this.n34,F=this.n41,N=this.n42,J=this.n43,M=this.n44;this.n11=b*a.n11+d*a.n21+i*a.n31+j*a.n41;this.n12=b*a.n12+d*a.n22+i*a.n32+j*a.n42;this.n13=b*a.n13+d*a.n23+i*a.n33+j*a.n43;this.n14=b*a.n14+d*a.n24+i*a.n34+j*a.n44;this.n21=o*a.n11+m*a.n21+q*a.n31+l*a.n41;this.n22=o*a.n12+m*a.n22+q*a.n32+l*a.n42;this.n23=o*a.n13+m*a.n23+q*a.n33+l*a.n43;this.n24=o*a.n14+m*a.n24+q*a.n34+l*a.n44;this.n31=c*a.n11+z*a.n21+G*a.n31+x*a.n41;this.n32=c*a.n12+z*a.n22+
-G*a.n32+x*a.n42;this.n33=c*a.n13+z*a.n23+G*a.n33+x*a.n43;this.n34=c*a.n14+z*a.n24+G*a.n34+x*a.n44;this.n41=F*a.n11+N*a.n21+J*a.n31+M*a.n41;this.n42=F*a.n12+N*a.n22+J*a.n32+M*a.n42;this.n43=F*a.n13+N*a.n23+J*a.n33+M*a.n43;this.n44=F*a.n14+N*a.n24+J*a.n34+M*a.n44},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},determinant:function(){return this.n14*
+a.n41;this.n42=a.n42;this.n43=a.n43;this.n44=a.n44},lookAt:function(a,b,d){var i=new THREE.Vector3,j=new THREE.Vector3,o=new THREE.Vector3;o.sub(a,b).normalize();i.cross(d,o).normalize();j.cross(o,i).normalize();this.n11=i.x;this.n12=i.y;this.n13=i.z;this.n14=-i.dot(a);this.n21=j.x;this.n22=j.y;this.n23=j.z;this.n24=-j.dot(a);this.n31=o.x;this.n32=o.y;this.n33=o.z;this.n34=-o.dot(a);this.n43=this.n42=this.n41=0;this.n44=1},multiplyVector3:function(a){var b=a.x,d=a.y,i=a.z,j=1/(this.n41*b+this.n42*
+d+this.n43*i+this.n44);a.x=(this.n11*b+this.n12*d+this.n13*i+this.n14)*j;a.y=(this.n21*b+this.n22*d+this.n23*i+this.n24)*j;a.z=(this.n31*b+this.n32*d+this.n33*i+this.n34)*j;return a},multiplyVector4:function(a){var b=a.x,d=a.y,i=a.z,j=a.w;a.x=this.n11*b+this.n12*d+this.n13*i+this.n14*j;a.y=this.n21*b+this.n22*d+this.n23*i+this.n24*j;a.z=this.n31*b+this.n32*d+this.n33*i+this.n34*j;a.w=this.n41*b+this.n42*d+this.n43*i+this.n44*j;return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*
+a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var d=a.n11,i=a.n12,j=a.n13,o=a.n14,m=a.n21,p=a.n22,l=a.n23,c=a.n24,E=a.n31,G=a.n32,w=a.n33,F=a.n34,O=a.n41,J=a.n42,M=a.n43,r=a.n44,S=b.n11,z=b.n12,f=b.n13,k=b.n14,e=b.n21,n=b.n22,h=b.n23,g=b.n24,q=b.n31,t=b.n32,K=b.n33,A=b.n34,H=b.n41,P=b.n42,u=b.n43,
+N=b.n44;this.n11=d*S+i*e+j*q+o*H;this.n12=d*z+i*n+j*t+o*P;this.n13=d*f+i*h+j*K+o*u;this.n14=d*k+i*g+j*A+o*N;this.n21=m*S+p*e+l*q+c*H;this.n22=m*z+p*n+l*t+c*P;this.n23=m*f+p*h+l*K+c*u;this.n24=m*k+p*g+l*A+c*N;this.n31=E*S+G*e+w*q+F*H;this.n32=E*z+G*n+w*t+F*P;this.n33=E*f+G*h+w*K+F*u;this.n34=E*k+G*g+w*A+F*N;this.n41=O*S+J*e+M*q+r*H;this.n42=O*z+J*n+M*t+r*P;this.n43=O*f+J*h+M*K+r*u;this.n44=O*k+J*g+M*A+r*N},multiplySelf:function(a){var b=this.n11,d=this.n12,i=this.n13,j=this.n14,o=this.n21,m=this.n22,
+p=this.n23,l=this.n24,c=this.n31,E=this.n32,G=this.n33,w=this.n34,F=this.n41,O=this.n42,J=this.n43,M=this.n44;this.n11=b*a.n11+d*a.n21+i*a.n31+j*a.n41;this.n12=b*a.n12+d*a.n22+i*a.n32+j*a.n42;this.n13=b*a.n13+d*a.n23+i*a.n33+j*a.n43;this.n14=b*a.n14+d*a.n24+i*a.n34+j*a.n44;this.n21=o*a.n11+m*a.n21+p*a.n31+l*a.n41;this.n22=o*a.n12+m*a.n22+p*a.n32+l*a.n42;this.n23=o*a.n13+m*a.n23+p*a.n33+l*a.n43;this.n24=o*a.n14+m*a.n24+p*a.n34+l*a.n44;this.n31=c*a.n11+E*a.n21+G*a.n31+w*a.n41;this.n32=c*a.n12+E*a.n22+
+G*a.n32+w*a.n42;this.n33=c*a.n13+E*a.n23+G*a.n33+w*a.n43;this.n34=c*a.n14+E*a.n24+G*a.n34+w*a.n44;this.n41=F*a.n11+O*a.n21+J*a.n31+M*a.n41;this.n42=F*a.n12+O*a.n22+J*a.n32+M*a.n42;this.n43=F*a.n13+O*a.n23+J*a.n33+M*a.n43;this.n44=F*a.n14+O*a.n24+J*a.n34+M*a.n44},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},determinant:function(){return this.n14*
 this.n23*this.n32*this.n41-this.n13*this.n24*this.n32*this.n41-this.n14*this.n22*this.n33*this.n41+this.n12*this.n24*this.n33*this.n41+this.n13*this.n22*this.n34*this.n41-this.n12*this.n23*this.n34*this.n41-this.n14*this.n23*this.n31*this.n42+this.n13*this.n24*this.n31*this.n42+this.n14*this.n21*this.n33*this.n42-this.n11*this.n24*this.n33*this.n42-this.n13*this.n21*this.n34*this.n42+this.n11*this.n23*this.n34*this.n42+this.n14*this.n22*this.n31*this.n43-this.n12*this.n24*this.n31*this.n43-this.n14*
 this.n23*this.n32*this.n41-this.n13*this.n24*this.n32*this.n41-this.n14*this.n22*this.n33*this.n41+this.n12*this.n24*this.n33*this.n41+this.n13*this.n22*this.n34*this.n41-this.n12*this.n23*this.n34*this.n41-this.n14*this.n23*this.n31*this.n42+this.n13*this.n24*this.n31*this.n42+this.n14*this.n21*this.n33*this.n42-this.n11*this.n24*this.n33*this.n42-this.n13*this.n21*this.n34*this.n42+this.n11*this.n23*this.n34*this.n42+this.n14*this.n22*this.n31*this.n43-this.n12*this.n24*this.n31*this.n43-this.n14*
 this.n21*this.n32*this.n43+this.n11*this.n24*this.n32*this.n43+this.n12*this.n21*this.n34*this.n43-this.n11*this.n22*this.n34*this.n43-this.n13*this.n22*this.n31*this.n44+this.n12*this.n23*this.n31*this.n44+this.n13*this.n21*this.n32*this.n44-this.n11*this.n23*this.n32*this.n44-this.n12*this.n21*this.n33*this.n44+this.n11*this.n22*this.n33*this.n44},transpose:function(){function a(b,d,i){var j=b[d];b[d]=b[i];b[i]=j}a(this,"n21","n12");a(this,"n31","n13");a(this,"n32","n23");a(this,"n41","n14");a(this,
 this.n21*this.n32*this.n43+this.n11*this.n24*this.n32*this.n43+this.n12*this.n21*this.n34*this.n43-this.n11*this.n22*this.n34*this.n43-this.n13*this.n22*this.n31*this.n44+this.n12*this.n23*this.n31*this.n44+this.n13*this.n21*this.n32*this.n44-this.n11*this.n23*this.n32*this.n44-this.n12*this.n21*this.n33*this.n44+this.n11*this.n22*this.n33*this.n44},transpose:function(){function a(b,d,i){var j=b[d];b[d]=b[i];b[i]=j}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(){return[this.n11,this.n21,this.n31,this.n41,this.n12,this.n22,this.n32,this.n42,this.n13,this.n23,this.n33,this.n43,this.n14,this.n24,this.n34,this.n44]},
 "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(){return[this.n11,this.n21,this.n31,this.n41,this.n12,this.n22,this.n32,this.n42,this.n13,this.n23,this.n33,this.n43,this.n14,this.n24,this.n34,this.n44]},
 toString:function(){return"| "+this.n11+" "+this.n12+" "+this.n13+" "+this.n14+" |\n| "+this.n21+" "+this.n22+" "+this.n23+" "+this.n24+" |\n| "+this.n31+" "+this.n32+" "+this.n33+" "+this.n34+" |\n| "+this.n41+" "+this.n42+" "+this.n43+" "+this.n44+" |"}};THREE.Matrix4.translationMatrix=function(a,b,d){var i=new THREE.Matrix4;i.n14=a;i.n24=b;i.n34=d;return i};THREE.Matrix4.scaleMatrix=function(a,b,d){var i=new THREE.Matrix4;i.n11=a;i.n22=b;i.n33=d;return i};
 toString:function(){return"| "+this.n11+" "+this.n12+" "+this.n13+" "+this.n14+" |\n| "+this.n21+" "+this.n22+" "+this.n23+" "+this.n24+" |\n| "+this.n31+" "+this.n32+" "+this.n33+" "+this.n34+" |\n| "+this.n41+" "+this.n42+" "+this.n43+" "+this.n44+" |"}};THREE.Matrix4.translationMatrix=function(a,b,d){var i=new THREE.Matrix4;i.n14=a;i.n24=b;i.n34=d;return i};THREE.Matrix4.scaleMatrix=function(a,b,d){var i=new THREE.Matrix4;i.n11=a;i.n22=b;i.n33=d;return i};
 THREE.Matrix4.rotationXMatrix=function(a){var b=new THREE.Matrix4;b.n22=b.n33=Math.cos(a);b.n32=Math.sin(a);b.n23=-b.n32;return b};THREE.Matrix4.rotationYMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n33=Math.cos(a);b.n13=Math.sin(a);b.n31=-b.n13;return b};THREE.Matrix4.rotationZMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n22=Math.cos(a);b.n21=Math.sin(a);b.n12=-b.n21;return b};
 THREE.Matrix4.rotationXMatrix=function(a){var b=new THREE.Matrix4;b.n22=b.n33=Math.cos(a);b.n32=Math.sin(a);b.n23=-b.n32;return b};THREE.Matrix4.rotationYMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n33=Math.cos(a);b.n13=Math.sin(a);b.n31=-b.n13;return b};THREE.Matrix4.rotationZMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n22=Math.cos(a);b.n21=Math.sin(a);b.n12=-b.n21;return b};
-THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var d=new THREE.Matrix4,i=Math.cos(b),j=Math.sin(b),o=1-i,m=a.x,q=a.y,l=a.z;d.n11=o*m*m+i;d.n12=o*m*q-j*l;d.n13=o*m*l+j*q;d.n21=o*m*q+j*l;d.n22=o*q*q+i;d.n23=o*q*l-j*m;d.n31=o*m*l-j*q;d.n32=o*q*l+j*m;d.n33=o*l*l+i;return d};
+THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var d=new THREE.Matrix4,i=Math.cos(b),j=Math.sin(b),o=1-i,m=a.x,p=a.y,l=a.z;d.n11=o*m*m+i;d.n12=o*m*p-j*l;d.n13=o*m*l+j*p;d.n21=o*m*p+j*l;d.n22=o*p*p+i;d.n23=o*p*l-j*m;d.n31=o*m*l-j*p;d.n32=o*p*l+j*m;d.n33=o*l*l+i;return d};
 THREE.Matrix4.makeInvert=function(a){var b=new THREE.Matrix4;b.n11=a.n23*a.n34*a.n42-a.n24*a.n33*a.n42+a.n24*a.n32*a.n43-a.n22*a.n34*a.n43-a.n23*a.n32*a.n44+a.n22*a.n33*a.n44;b.n12=a.n14*a.n33*a.n42-a.n13*a.n34*a.n42-a.n14*a.n32*a.n43+a.n12*a.n34*a.n43+a.n13*a.n32*a.n44-a.n12*a.n33*a.n44;b.n13=a.n13*a.n24*a.n42-a.n14*a.n23*a.n42+a.n14*a.n22*a.n43-a.n12*a.n24*a.n43-a.n13*a.n22*a.n44+a.n12*a.n23*a.n44;b.n14=a.n14*a.n23*a.n32-a.n13*a.n24*a.n32-a.n14*a.n22*a.n33+a.n12*a.n24*a.n33+a.n13*a.n22*a.n34-a.n12*
 THREE.Matrix4.makeInvert=function(a){var b=new THREE.Matrix4;b.n11=a.n23*a.n34*a.n42-a.n24*a.n33*a.n42+a.n24*a.n32*a.n43-a.n22*a.n34*a.n43-a.n23*a.n32*a.n44+a.n22*a.n33*a.n44;b.n12=a.n14*a.n33*a.n42-a.n13*a.n34*a.n42-a.n14*a.n32*a.n43+a.n12*a.n34*a.n43+a.n13*a.n32*a.n44-a.n12*a.n33*a.n44;b.n13=a.n13*a.n24*a.n42-a.n14*a.n23*a.n42+a.n14*a.n22*a.n43-a.n12*a.n24*a.n43-a.n13*a.n22*a.n44+a.n12*a.n23*a.n44;b.n14=a.n14*a.n23*a.n32-a.n13*a.n24*a.n32-a.n14*a.n22*a.n33+a.n12*a.n24*a.n33+a.n13*a.n22*a.n34-a.n12*
 a.n23*a.n34;b.n21=a.n24*a.n33*a.n41-a.n23*a.n34*a.n41-a.n24*a.n31*a.n43+a.n21*a.n34*a.n43+a.n23*a.n31*a.n44-a.n21*a.n33*a.n44;b.n22=a.n13*a.n34*a.n41-a.n14*a.n33*a.n41+a.n14*a.n31*a.n43-a.n11*a.n34*a.n43-a.n13*a.n31*a.n44+a.n11*a.n33*a.n44;b.n23=a.n14*a.n23*a.n41-a.n13*a.n24*a.n41-a.n14*a.n21*a.n43+a.n11*a.n24*a.n43+a.n13*a.n21*a.n44-a.n11*a.n23*a.n44;b.n24=a.n13*a.n24*a.n31-a.n14*a.n23*a.n31+a.n14*a.n21*a.n33-a.n11*a.n24*a.n33-a.n13*a.n21*a.n34+a.n11*a.n23*a.n34;b.n31=a.n22*a.n34*a.n41-a.n24*a.n32*
 a.n23*a.n34;b.n21=a.n24*a.n33*a.n41-a.n23*a.n34*a.n41-a.n24*a.n31*a.n43+a.n21*a.n34*a.n43+a.n23*a.n31*a.n44-a.n21*a.n33*a.n44;b.n22=a.n13*a.n34*a.n41-a.n14*a.n33*a.n41+a.n14*a.n31*a.n43-a.n11*a.n34*a.n43-a.n13*a.n31*a.n44+a.n11*a.n33*a.n44;b.n23=a.n14*a.n23*a.n41-a.n13*a.n24*a.n41-a.n14*a.n21*a.n43+a.n11*a.n24*a.n43+a.n13*a.n21*a.n44-a.n11*a.n23*a.n44;b.n24=a.n13*a.n24*a.n31-a.n14*a.n23*a.n31+a.n14*a.n21*a.n33-a.n11*a.n24*a.n33-a.n13*a.n21*a.n34+a.n11*a.n23*a.n34;b.n31=a.n22*a.n34*a.n41-a.n24*a.n32*
 a.n41+a.n24*a.n31*a.n42-a.n21*a.n34*a.n42-a.n22*a.n31*a.n44+a.n21*a.n32*a.n44;b.n32=a.n14*a.n32*a.n41-a.n12*a.n34*a.n41-a.n14*a.n31*a.n42+a.n11*a.n34*a.n42+a.n12*a.n31*a.n44-a.n11*a.n32*a.n44;b.n33=a.n13*a.n24*a.n41-a.n14*a.n22*a.n41+a.n14*a.n21*a.n42-a.n11*a.n24*a.n42-a.n12*a.n21*a.n44+a.n11*a.n22*a.n44;b.n34=a.n14*a.n22*a.n31-a.n12*a.n24*a.n31-a.n14*a.n21*a.n32+a.n11*a.n24*a.n32+a.n12*a.n21*a.n34-a.n11*a.n22*a.n34;b.n41=a.n23*a.n32*a.n41-a.n22*a.n33*a.n41-a.n23*a.n31*a.n42+a.n21*a.n33*a.n42+a.n22*
 a.n41+a.n24*a.n31*a.n42-a.n21*a.n34*a.n42-a.n22*a.n31*a.n44+a.n21*a.n32*a.n44;b.n32=a.n14*a.n32*a.n41-a.n12*a.n34*a.n41-a.n14*a.n31*a.n42+a.n11*a.n34*a.n42+a.n12*a.n31*a.n44-a.n11*a.n32*a.n44;b.n33=a.n13*a.n24*a.n41-a.n14*a.n22*a.n41+a.n14*a.n21*a.n42-a.n11*a.n24*a.n42-a.n12*a.n21*a.n44+a.n11*a.n22*a.n44;b.n34=a.n14*a.n22*a.n31-a.n12*a.n24*a.n31-a.n14*a.n21*a.n32+a.n11*a.n24*a.n32+a.n12*a.n21*a.n34-a.n11*a.n22*a.n34;b.n41=a.n23*a.n32*a.n41-a.n22*a.n33*a.n41-a.n23*a.n31*a.n42+a.n21*a.n33*a.n42+a.n22*
 a.n31*a.n43-a.n21*a.n32*a.n43;b.n42=a.n12*a.n33*a.n41-a.n13*a.n32*a.n41+a.n13*a.n31*a.n42-a.n11*a.n33*a.n42-a.n12*a.n31*a.n43+a.n11*a.n32*a.n43;b.n43=a.n13*a.n22*a.n41-a.n12*a.n23*a.n41-a.n13*a.n21*a.n42+a.n11*a.n23*a.n42+a.n12*a.n21*a.n43-a.n11*a.n22*a.n43;b.n44=a.n12*a.n23*a.n31-a.n13*a.n22*a.n31+a.n13*a.n21*a.n32-a.n11*a.n23*a.n32-a.n12*a.n21*a.n33+a.n11*a.n22*a.n33;b.multiplyScalar(1/a.determinant());return b};
 a.n31*a.n43-a.n21*a.n32*a.n43;b.n42=a.n12*a.n33*a.n41-a.n13*a.n32*a.n41+a.n13*a.n31*a.n42-a.n11*a.n33*a.n42-a.n12*a.n31*a.n43+a.n11*a.n32*a.n43;b.n43=a.n13*a.n22*a.n41-a.n12*a.n23*a.n41-a.n13*a.n21*a.n42+a.n11*a.n23*a.n42+a.n12*a.n21*a.n43-a.n11*a.n22*a.n43;b.n44=a.n12*a.n23*a.n31-a.n13*a.n22*a.n31+a.n13*a.n21*a.n32-a.n11*a.n23*a.n32-a.n12*a.n21*a.n33+a.n11*a.n22*a.n33;b.multiplyScalar(1/a.determinant());return b};
-THREE.Matrix4.makeInvert3x3=function(a){var b=a.flatten();a=new THREE.Matrix3;var d=b[10]*b[5]-b[6]*b[9],i=-b[10]*b[1]+b[2]*b[9],j=b[6]*b[1]-b[2]*b[5],o=-b[10]*b[4]+b[6]*b[8],m=b[10]*b[0]-b[2]*b[8],q=-b[6]*b[0]+b[2]*b[4],l=b[9]*b[4]-b[5]*b[8],c=-b[9]*b[0]+b[1]*b[8],z=b[5]*b[0]-b[1]*b[4];b=b[0]*d+b[1]*o+b[2]*l;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*d;a.m[1]=b*i;a.m[2]=b*j;a.m[3]=b*o;a.m[4]=b*m;a.m[5]=b*q;a.m[6]=b*l;a.m[7]=b*c;a.m[8]=b*z;return a};
-THREE.Matrix4.makeFrustum=function(a,b,d,i,j,o){var m,q,l;m=new THREE.Matrix4;q=2*j/(b-a);l=2*j/(i-d);a=(b+a)/(b-a);d=(i+d)/(i-d);i=-(o+j)/(o-j);j=-2*o*j/(o-j);m.n11=q;m.n12=0;m.n13=a;m.n14=0;m.n21=0;m.n22=l;m.n23=d;m.n24=0;m.n31=0;m.n32=0;m.n33=i;m.n34=j;m.n41=0;m.n42=0;m.n43=-1;m.n44=0;return m};THREE.Matrix4.makePerspective=function(a,b,d,i){var j;a=d*Math.tan(a*Math.PI/360);j=-a;return THREE.Matrix4.makeFrustum(j*b,a*b,j,a,d,i)};
-THREE.Matrix4.makeOrtho=function(a,b,d,i,j,o){var m,q,l,c;m=new THREE.Matrix4;q=b-a;l=d-i;c=o-j;a=(b+a)/q;d=(d+i)/l;j=(o+j)/c;m.n11=2/q;m.n12=0;m.n13=0;m.n14=-a;m.n21=0;m.n22=2/l;m.n23=0;m.n24=-d;m.n31=0;m.n32=0;m.n33=-2/c;m.n34=-j;m.n41=0;m.n42=0;m.n43=0;m.n44=1;return m};
+THREE.Matrix4.makeInvert3x3=function(a){var b=a.flatten();a=new THREE.Matrix3;var d=b[10]*b[5]-b[6]*b[9],i=-b[10]*b[1]+b[2]*b[9],j=b[6]*b[1]-b[2]*b[5],o=-b[10]*b[4]+b[6]*b[8],m=b[10]*b[0]-b[2]*b[8],p=-b[6]*b[0]+b[2]*b[4],l=b[9]*b[4]-b[5]*b[8],c=-b[9]*b[0]+b[1]*b[8],E=b[5]*b[0]-b[1]*b[4];b=b[0]*d+b[1]*o+b[2]*l;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*d;a.m[1]=b*i;a.m[2]=b*j;a.m[3]=b*o;a.m[4]=b*m;a.m[5]=b*p;a.m[6]=b*l;a.m[7]=b*c;a.m[8]=b*E;return a};
+THREE.Matrix4.makeFrustum=function(a,b,d,i,j,o){var m,p,l;m=new THREE.Matrix4;p=2*j/(b-a);l=2*j/(i-d);a=(b+a)/(b-a);d=(i+d)/(i-d);i=-(o+j)/(o-j);j=-2*o*j/(o-j);m.n11=p;m.n12=0;m.n13=a;m.n14=0;m.n21=0;m.n22=l;m.n23=d;m.n24=0;m.n31=0;m.n32=0;m.n33=i;m.n34=j;m.n41=0;m.n42=0;m.n43=-1;m.n44=0;return m};THREE.Matrix4.makePerspective=function(a,b,d,i){var j;a=d*Math.tan(a*Math.PI/360);j=-a;return THREE.Matrix4.makeFrustum(j*b,a*b,j,a,d,i)};
+THREE.Matrix4.makeOrtho=function(a,b,d,i,j,o){var m,p,l,c;m=new THREE.Matrix4;p=b-a;l=d-i;c=o-j;a=(b+a)/p;d=(d+i)/l;j=(o+j)/c;m.n11=2/p;m.n12=0;m.n13=0;m.n14=-a;m.n21=0;m.n22=2/l;m.n23=0;m.n24=-d;m.n31=0;m.n32=0;m.n33=-2/c;m.n34=-j;m.n41=0;m.n42=0;m.n43=0;m.n44=1;return m};
 THREE.Vertex=function(a,b){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=b||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}};
 THREE.Vertex=function(a,b){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=b||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}};
 THREE.Face3=function(a,b,d,i,j){this.a=a;this.b=b;this.c=d;this.centroid=new THREE.Vector3;this.normal=i instanceof THREE.Vector3?i:new THREE.Vector3;this.vertexNormals=i instanceof Array?i:[];this.material=j instanceof Array?j:[j]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
 THREE.Face3=function(a,b,d,i,j){this.a=a;this.b=b;this.c=d;this.centroid=new THREE.Vector3;this.normal=i instanceof THREE.Vector3?i:new THREE.Vector3;this.vertexNormals=i instanceof Array?i:[];this.material=j instanceof Array?j:[j]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
 THREE.Face4=function(a,b,d,i,j,o){this.a=a;this.b=b;this.c=d;this.d=i;this.centroid=new THREE.Vector3;this.normal=j instanceof THREE.Vector3?j:new THREE.Vector3;this.vertexNormals=j instanceof Array?j:[];this.material=o instanceof Array?o:[o]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
 THREE.Face4=function(a,b,d,i,j,o){this.a=a;this.b=b;this.c=d;this.d=i;this.centroid=new THREE.Vector3;this.normal=j instanceof THREE.Vector3?j:new THREE.Vector3;this.vertexNormals=j instanceof Array?j:[];this.material=o instanceof Array?o:[o]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
 THREE.UV.prototype={copy:function(a){this.u=a.u;this.v=a.v},toString:function(){return"THREE.UV ("+this.u+", "+this.v+")"}};THREE.Geometry=function(){this.vertices=[];this.faces=[];this.uvs=[];this.geometryChunks={}};
 THREE.UV.prototype={copy:function(a){this.u=a.u;this.v=a.v},toString:function(){return"THREE.UV ("+this.u+", "+this.v+")"}};THREE.Geometry=function(){this.vertices=[];this.faces=[];this.uvs=[];this.geometryChunks={}};
-THREE.Geometry.prototype={computeCentroids:function(){var a,b,d;a=0;for(b=this.faces.length;a<b;a++){d=this.faces[a];d.centroid.set(0,0,0);d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);if(d instanceof THREE.Face3)d.centroid.divideScalar(3);else if(d instanceof THREE.Face4){d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeNormals:function(a){var b,d,i,j,o,m,q=new THREE.Vector3,
-l=new THREE.Vector3;i=0;for(j=this.vertices.length;i<j;i++){o=this.vertices[i];o.normal.set(0,0,0)}i=0;for(j=this.faces.length;i<j;i++){o=this.faces[i];if(a&&o.vertexNormals.length){q.set(0,0,0);b=0;for(d=o.normal.length;b<d;b++)q.addSelf(o.vertexNormals[b]);q.divideScalar(3)}else{b=this.vertices[o.a];d=this.vertices[o.b];m=this.vertices[o.c];q.sub(m.position,d.position);l.sub(b.position,d.position);q.crossSelf(l)}q.isZero()||q.normalize();o.normal.copy(q)}},computeBoundingBox:function(){if(this.vertices.length>
-0){this.bbox={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 a=1,b=this.vertices.length;a<b;a++){vertex=this.vertices[a];if(vertex.position.x<this.bbox.x[0])this.bbox.x[0]=vertex.position.x;else if(vertex.position.x>this.bbox.x[1])this.bbox.x[1]=vertex.position.x;if(vertex.position.y<this.bbox.y[0])this.bbox.y[0]=vertex.position.y;else if(vertex.position.y>
-this.bbox.y[1])this.bbox.y[1]=vertex.position.y;if(vertex.position.z<this.bbox.z[0])this.bbox.z[0]=vertex.position.z;else if(vertex.position.z>this.bbox.z[1])this.bbox.z[1]=vertex.position.z}}},sortFacesByMaterial:function(){function a(z){var G=[];b=0;for(d=z.length;b<d;b++)z[b]==undefined?G.push("undefined"):G.push(z[b].toString());return G.join("_")}var b,d,i,j,o,m,q,l,c={};i=0;for(j=this.faces.length;i<j;i++){o=this.faces[i];m=o.material;q=a(m);if(c[q]==undefined)c[q]={hash:q,counter:0};l=c[q].hash+
-"_"+c[q].counter;if(this.geometryChunks[l]==undefined)this.geometryChunks[l]={faces:[],material:m,vertices:0};o=o instanceof THREE.Face3?3:4;if(this.geometryChunks[l].vertices+o>65535){c[q].counter+=1;l=c[q].hash+"_"+c[q].counter;if(this.geometryChunks[l]==undefined)this.geometryChunks[l]={faces:[],material:m,vertices:0}}this.geometryChunks[l].faces.push(i);this.geometryChunks[l].vertices+=o}},toString:function(){return"THREE.Geometry ( vertices: "+this.vertices+", faces: "+this.faces+" )"}};
+THREE.Geometry.prototype={computeCentroids:function(){var a,b,d;a=0;for(b=this.faces.length;a<b;a++){d=this.faces[a];d.centroid.set(0,0,0);d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);if(d instanceof THREE.Face3)d.centroid.divideScalar(3);else if(d instanceof THREE.Face4){d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeNormals:function(a){var b,d,i,j,o,m,p=new THREE.Vector3,
+l=new THREE.Vector3;i=0;for(j=this.vertices.length;i<j;i++){o=this.vertices[i];o.normal.set(0,0,0)}i=0;for(j=this.faces.length;i<j;i++){o=this.faces[i];if(a&&o.vertexNormals.length){p.set(0,0,0);b=0;for(d=o.normal.length;b<d;b++)p.addSelf(o.vertexNormals[b]);p.divideScalar(3)}else{b=this.vertices[o.a];d=this.vertices[o.b];m=this.vertices[o.c];p.sub(m.position,d.position);l.sub(b.position,d.position);p.crossSelf(l)}p.isZero()||p.normalize();o.normal.copy(p)}},computeVertexNormals:function(){var a,
+b;a=0;for(b=this.faces.length;a<b;a++);},computeBoundingBox:function(){if(this.vertices.length>0){this.bbox={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 a=1,b=this.vertices.length;a<b;a++){vertex=this.vertices[a];if(vertex.position.x<this.bbox.x[0])this.bbox.x[0]=vertex.position.x;else if(vertex.position.x>this.bbox.x[1])this.bbox.x[1]=vertex.position.x;
+if(vertex.position.y<this.bbox.y[0])this.bbox.y[0]=vertex.position.y;else if(vertex.position.y>this.bbox.y[1])this.bbox.y[1]=vertex.position.y;if(vertex.position.z<this.bbox.z[0])this.bbox.z[0]=vertex.position.z;else if(vertex.position.z>this.bbox.z[1])this.bbox.z[1]=vertex.position.z}}},sortFacesByMaterial:function(){function a(E){var G=[];b=0;for(d=E.length;b<d;b++)E[b]==undefined?G.push("undefined"):G.push(E[b].toString());return G.join("_")}var b,d,i,j,o,m,p,l,c={};i=0;for(j=this.faces.length;i<
+j;i++){o=this.faces[i];m=o.material;p=a(m);if(c[p]==undefined)c[p]={hash:p,counter:0};l=c[p].hash+"_"+c[p].counter;if(this.geometryChunks[l]==undefined)this.geometryChunks[l]={faces:[],material:m,vertices:0};o=o instanceof THREE.Face3?3:4;if(this.geometryChunks[l].vertices+o>65535){c[p].counter+=1;l=c[p].hash+"_"+c[p].counter;if(this.geometryChunks[l]==undefined)this.geometryChunks[l]={faces:[],material:m,vertices:0}}this.geometryChunks[l].faces.push(i);this.geometryChunks[l].vertices+=o}},toString:function(){return"THREE.Geometry ( vertices: "+
+this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
 THREE.Camera=function(a,b,d,i){this.position=new THREE.Vector3(0,0,0);this.target={position:new THREE.Vector3(0,0,0)};this.up=new THREE.Vector3(0,1,0);this.matrix=new THREE.Matrix4;this.projectionMatrix=THREE.Matrix4.makePerspective(a,b,d,i);this.autoUpdateMatrix=true;this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.toString=function(){return"THREE.Camera ( "+this.position+", "+this.target.position+" )"}};THREE.Light=function(a){this.color=new THREE.Color(a)};
 THREE.Camera=function(a,b,d,i){this.position=new THREE.Vector3(0,0,0);this.target={position:new THREE.Vector3(0,0,0)};this.up=new THREE.Vector3(0,1,0);this.matrix=new THREE.Matrix4;this.projectionMatrix=THREE.Matrix4.makePerspective(a,b,d,i);this.autoUpdateMatrix=true;this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.toString=function(){return"THREE.Camera ( "+this.position+", "+this.target.position+" )"}};THREE.Light=function(a){this.color=new THREE.Color(a)};
 THREE.AmbientLight=function(a){THREE.Light.call(this,a)};THREE.AmbientLight.prototype=new THREE.Light;THREE.AmbientLight.prototype.constructor=THREE.AmbientLight;THREE.DirectionalLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,1,0);this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.DirectionalLight;
 THREE.AmbientLight=function(a){THREE.Light.call(this,a)};THREE.AmbientLight.prototype=new THREE.Light;THREE.AmbientLight.prototype.constructor=THREE.AmbientLight;THREE.DirectionalLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,1,0);this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.DirectionalLight;
 THREE.PointLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3;this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.PointLight;
 THREE.PointLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3;this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.PointLight;
@@ -82,86 +83,86 @@ this.blending+"<br/>)"}};THREE.ParticleCircleMaterial=function(a){this.color=new
 THREE.ParticleDOMMaterial=function(a){this.domElement=a;this.toString=function(){return"THREE.ParticleDOMMaterial ( domElement: "+this.domElement+" )"}};THREE.Texture=function(a,b,d,i){this.image=a;this.loaded=false;this.mapping=b!==undefined?b:THREE.UVMapping;this.wrap_s=d!==undefined?d:THREE.ClampToEdge;this.wrap_t=i!==undefined?i:THREE.ClampToEdge;this.toString=function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>wrap_s: "+this.wrap_s+"<br/>wrap_t: "+this.wrap_t+"<br/>)"}};
 THREE.ParticleDOMMaterial=function(a){this.domElement=a;this.toString=function(){return"THREE.ParticleDOMMaterial ( domElement: "+this.domElement+" )"}};THREE.Texture=function(a,b,d,i){this.image=a;this.loaded=false;this.mapping=b!==undefined?b:THREE.UVMapping;this.wrap_s=d!==undefined?d:THREE.ClampToEdge;this.wrap_t=i!==undefined?i:THREE.ClampToEdge;this.toString=function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>wrap_s: "+this.wrap_s+"<br/>wrap_t: "+this.wrap_t+"<br/>)"}};
 THREE.UVMapping=0;THREE.ReflectionMapping=1;THREE.RefractionMapping=2;THREE.Multiply=0;THREE.Mix=1;THREE.Repeat=0;THREE.ClampToEdge=1;THREE.MirroredRepeat=2;THREE.TextureCube=function(a,b){this.image=a;this.mapping=b?b:THREE.ReflectionMap;this.toString=function(){return"THREE.TextureCube (<br/>image: "+this.image+"<br/>mapping: "+this.mapping+"<br/>)"}};
 THREE.UVMapping=0;THREE.ReflectionMapping=1;THREE.RefractionMapping=2;THREE.Multiply=0;THREE.Mix=1;THREE.Repeat=0;THREE.ClampToEdge=1;THREE.MirroredRepeat=2;THREE.TextureCube=function(a,b){this.image=a;this.mapping=b?b:THREE.ReflectionMap;this.toString=function(){return"THREE.TextureCube (<br/>image: "+this.image+"<br/>mapping: "+this.mapping+"<br/>)"}};
 THREE.Scene=function(){this.objects=[];this.lights=[];this.addObject=function(a){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.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.Scene=function(){this.objects=[];this.lights=[];this.addObject=function(a){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.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.Projector=function(){function a(R,B){var e=0,f=1,k=R.z+R.w,n=B.z+B.w,g=-R.z+R.w,h=-B.z+B.w;if(k>=0&&n>=0&&g>=0&&h>=0)return true;else if(k<0&&n<0||g<0&&h<0)return false;else{if(k<0)e=Math.max(e,k/(k-n));else if(n<0)f=Math.min(f,k/(k-n));if(g<0)e=Math.max(e,g/(g-h));else if(h<0)f=Math.min(f,g/(g-h));if(f<e)return false;else{R.lerpSelf(B,e);B.lerpSelf(R,1-f);return true}}}var b=null,d,i,j,o=[],m,q,l=[],c,z,G=[],x=new THREE.Vector4,F=new THREE.Matrix4,N=new THREE.Matrix4,J=new THREE.Vector4,M=
-new THREE.Vector4,r;this.projectScene=function(R,B){var e,f,k,n,g,h,w,s,L,u,T,P,t,H,p,A,y;b=[];j=q=z=0;B.autoUpdateMatrix&&B.updateMatrix();F.multiply(B.projectionMatrix,B.matrix);w=R.objects;e=0;for(f=w.length;e<f;e++){s=w[e];s.autoUpdateMatrix&&s.updateMatrix();L=s.matrix;u=s.rotationMatrix;T=s.material;P=s.overdraw;if(s instanceof THREE.Mesh){t=s.geometry.vertices;k=0;for(n=t.length;k<n;k++){H=t[k];H.positionWorld.copy(H.position);L.transformVector3(H.positionWorld);p=H.positionScreen;p.copy(H.positionWorld);
-F.transformVector4(p);p.multiplyScalar(1/p.w);H.__visible=p.z>0&&p.z<1}H=s.geometry.faces;k=0;for(n=H.length;k<n;k++){p=H[k];if(p instanceof THREE.Face3){g=t[p.a];h=t[p.b];A=t[p.c];if(g.__visible&&h.__visible&&A.__visible)if(s.doubleSided||s.flipSided!=(A.positionScreen.x-g.positionScreen.x)*(h.positionScreen.y-g.positionScreen.y)-(A.positionScreen.y-g.positionScreen.y)*(h.positionScreen.x-g.positionScreen.x)<0){d=o[j]=o[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(g.positionWorld);d.v2.positionWorld.copy(h.positionWorld);
-d.v3.positionWorld.copy(A.positionWorld);d.v1.positionScreen.copy(g.positionScreen);d.v2.positionScreen.copy(h.positionScreen);d.v3.positionScreen.copy(A.positionScreen);d.normalWorld.copy(p.normal);u.transformVector3(d.normalWorld);d.centroidWorld.copy(p.centroid);L.transformVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);F.transformVector3(d.centroidScreen);A=p.vertexNormals;r=d.vertexNormalsWorld;g=0;for(h=A.length;g<h;g++){y=r[g]=r[g]||new THREE.Vector3;y.copy(A[g]);u.transformVector3(y)}d.z=
-d.centroidScreen.z;d.meshMaterial=T;d.faceMaterial=p.material;d.overdraw=P;if(s.geometry.uvs[k]){d.uvs[0]=s.geometry.uvs[k][0];d.uvs[1]=s.geometry.uvs[k][1];d.uvs[2]=s.geometry.uvs[k][2]}b.push(d);j++}}else if(p instanceof THREE.Face4){g=t[p.a];h=t[p.b];A=t[p.c];y=t[p.d];if(g.__visible&&h.__visible&&A.__visible&&y.__visible)if(s.doubleSided||s.flipSided!=((y.positionScreen.x-g.positionScreen.x)*(h.positionScreen.y-g.positionScreen.y)-(y.positionScreen.y-g.positionScreen.y)*(h.positionScreen.x-g.positionScreen.x)<
-0||(h.positionScreen.x-A.positionScreen.x)*(y.positionScreen.y-A.positionScreen.y)-(h.positionScreen.y-A.positionScreen.y)*(y.positionScreen.x-A.positionScreen.x)<0)){d=o[j]=o[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(g.positionWorld);d.v2.positionWorld.copy(h.positionWorld);d.v3.positionWorld.copy(y.positionWorld);d.v1.positionScreen.copy(g.positionScreen);d.v2.positionScreen.copy(h.positionScreen);d.v3.positionScreen.copy(y.positionScreen);d.normalWorld.copy(p.normal);u.transformVector3(d.normalWorld);
-d.centroidWorld.copy(p.centroid);L.transformVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);F.transformVector3(d.centroidScreen);d.z=d.centroidScreen.z;d.meshMaterial=T;d.faceMaterial=p.material;d.overdraw=P;if(s.geometry.uvs[k]){d.uvs[0]=s.geometry.uvs[k][0];d.uvs[1]=s.geometry.uvs[k][1];d.uvs[2]=s.geometry.uvs[k][3]}b.push(d);j++;i=o[j]=o[j]||new THREE.RenderableFace3;i.v1.positionWorld.copy(h.positionWorld);i.v2.positionWorld.copy(A.positionWorld);i.v3.positionWorld.copy(y.positionWorld);
-i.v1.positionScreen.copy(h.positionScreen);i.v2.positionScreen.copy(A.positionScreen);i.v3.positionScreen.copy(y.positionScreen);i.normalWorld.copy(d.normalWorld);i.centroidWorld.copy(d.centroidWorld);i.centroidScreen.copy(d.centroidScreen);i.z=i.centroidScreen.z;i.meshMaterial=T;i.faceMaterial=p.material;i.overdraw=P;if(s.geometry.uvs[k]){i.uvs[0]=s.geometry.uvs[k][1];i.uvs[1]=s.geometry.uvs[k][2];i.uvs[2]=s.geometry.uvs[k][3]}b.push(i);j++}}}}else if(s instanceof THREE.Line){N.multiply(F,L);t=s.geometry.vertices;
-H=t[0];H.positionScreen.copy(H.position);N.transformVector4(H.positionScreen);k=1;for(n=t.length;k<n;k++){g=t[k];g.positionScreen.copy(g.position);N.transformVector4(g.positionScreen);h=t[k-1];J.copy(g.positionScreen);M.copy(h.positionScreen);if(a(J,M)){J.multiplyScalar(1/J.w);M.multiplyScalar(1/M.w);m=l[q]=l[q]||new THREE.RenderableLine;m.v1.positionScreen.copy(J);m.v2.positionScreen.copy(M);m.z=Math.max(J.z,M.z);m.material=s.material;b.push(m);q++}}}else if(s instanceof THREE.Particle){x.set(s.position.x,
-s.position.y,s.position.z,1);F.transformVector4(x);x.z/=x.w;if(x.z>0&&x.z<1){c=G[z]=G[z]||new THREE.RenderableParticle;c.x=x.x/x.w;c.y=x.y/x.w;c.z=x.z;c.rotation=s.rotation.z;c.scale.x=s.scale.x*Math.abs(c.x-(x.x+B.projectionMatrix.n11)/(x.w+B.projectionMatrix.n14));c.scale.y=s.scale.y*Math.abs(c.y-(x.y+B.projectionMatrix.n22)/(x.w+B.projectionMatrix.n24));c.material=s.material;b.push(c);z++}}}b.sort(function(O,D){return D.z-O.z});return b};this.unprojectVector=function(R,B){var e=new THREE.Matrix4;
-e.multiply(THREE.Matrix4.makeInvert(B.matrix),THREE.Matrix4.makeInvert(B.projectionMatrix));e.transformVector3(R);return R}};
-THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,d,i,j,o;this.domElement=document.createElement("div");this.setSize=function(m,q){d=m;i=q;j=d/2;o=i/2};this.render=function(m,q){var l,c,z,G,x,F,N,J;a=b.projectScene(m,q);l=0;for(c=a.length;l<c;l++){x=a[l];if(x instanceof THREE.RenderableParticle){N=x.x*j+j;J=x.y*o+o;z=0;for(G=x.material.length;z<G;z++){F=x.material[z];if(F instanceof THREE.ParticleDOMMaterial){F=F.domElement;F.style.left=N+"px";F.style.top=J+"px"}}}}}};
-THREE.CanvasRenderer=function(){function a(I,Y,U,E){var v,K,$,S,X=I.lights;I=0;for(v=X.length;I<v;I++){K=X[I];$=K.color;S=K.intensity;if(K instanceof THREE.DirectionalLight){K=U.dot(K.position)*S;if(K>0){E.r+=$.r*K;E.g+=$.g*K;E.b+=$.b*K}}else if(K instanceof THREE.PointLight){aa.sub(K.position,Y);aa.normalize();K=U.dot(aa)*S;if(K>0){E.r+=$.r*K;E.g+=$.g*K;E.b+=$.b*K}}}}function b(I,Y,U,E,v,K){if(v.opacity!=0){o(v.opacity);m(v.blending);L=I.positionScreen.x;u=I.positionScreen.y;T=Y.positionScreen.x;
-P=Y.positionScreen.y;t=U.positionScreen.x;H=U.positionScreen.y;var $=L,S=u,X=T,ba=P,Z=t,ca=H;r.beginPath();r.moveTo($,S);r.lineTo(X,ba);r.lineTo(Z,ca);r.lineTo($,S);r.closePath();if(v instanceof THREE.MeshBasicMaterial)if(v.map&&v.map.loaded)j(L,u,T,P,t,H,v.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(v.env_map&&v.env_map.loaded){if(v.env_map.mapping==THREE.ReflectionMapping){aa.copy(E.vertexNormalsWorld[0]);V=(aa.x*camera.matrix.n11+aa.y*camera.matrix.n12+
-aa.z*camera.matrix.n13)*0.5+0.5;ja=-(aa.x*camera.matrix.n21+aa.y*camera.matrix.n22+aa.z*camera.matrix.n23)*0.5+0.5;aa.copy(E.vertexNormalsWorld[1]);za=(aa.x*camera.matrix.n11+aa.y*camera.matrix.n12+aa.z*camera.matrix.n13)*0.5+0.5;Aa=-(aa.x*camera.matrix.n21+aa.y*camera.matrix.n22+aa.z*camera.matrix.n23)*0.5+0.5;aa.copy(E.vertexNormalsWorld[2]);Ba=(aa.x*camera.matrix.n11+aa.y*camera.matrix.n12+aa.z*camera.matrix.n13)*0.5+0.5;Ca=-(aa.x*camera.matrix.n21+aa.y*camera.matrix.n22+aa.z*camera.matrix.n23)*
-0.5+0.5;j(L,u,T,P,t,H,v.env_map.image,V,ja,za,Aa,Ba,Ca)}}else v.wireframe?d(v.color.__styleString,v.wireframe_linewidth):i(v.color.__styleString);else if(v instanceof THREE.MeshLambertMaterial){if(v.map&&!v.wireframe){j(L,u,T,P,t,H,v.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);m(THREE.SubtractiveBlending)}if(va)if(!v.wireframe&&v.shading==THREE.SmoothShading&&E.vertexNormalsWorld.length==3){A.r=y.r=O.r=ga.r;A.g=y.g=O.g=ga.g;A.b=y.b=O.b=ga.b;a(K,E.v1.positionWorld,
-E.vertexNormalsWorld[0],A);a(K,E.v2.positionWorld,E.vertexNormalsWorld[1],y);a(K,E.v3.positionWorld,E.vertexNormalsWorld[2],O);D.r=(y.r+O.r)*0.5;D.g=(y.g+O.g)*0.5;D.b=(y.b+O.b)*0.5;Q=q(A,y,O,D);j(L,u,T,P,t,H,Q,0,0,1,0,0,1)}else{ha.r=ga.r;ha.g=ga.g;ha.b=ga.b;a(K,E.centroidWorld,E.normalWorld,ha);p.r=v.color.r*ha.r;p.g=v.color.g*ha.g;p.b=v.color.b*ha.b;p.updateStyleString();v.wireframe?d(p.__styleString,v.wireframe_linewidth):i(p.__styleString)}else v.wireframe?d(v.color.__styleString,v.wireframe_linewidth):
-i(v.color.__styleString)}else if(v instanceof THREE.MeshDepthMaterial){C=v.__2near;W=v.__farPlusNear;ea=v.__farMinusNear;A.r=A.g=A.b=1-C/(W-I.positionScreen.z*ea);y.r=y.g=y.b=1-C/(W-Y.positionScreen.z*ea);O.r=O.g=O.b=1-C/(W-U.positionScreen.z*ea);D.r=(y.r+O.r)*0.5;D.g=(y.g+O.g)*0.5;D.b=(y.b+O.b)*0.5;Q=q(A,y,O,D);j(L,u,T,P,t,H,Q,0,0,1,0,0,1)}else if(v instanceof THREE.MeshNormalMaterial){p.r=l(E.normalWorld.x);p.g=l(E.normalWorld.y);p.b=l(E.normalWorld.z);p.updateStyleString();v.wireframe?d(p.__styleString,
-v.wireframe_linewidth):i(p.__styleString)}}}function d(I,Y){if(e!=I)r.strokeStyle=e=I;if(k!=Y)r.lineWidth=k=Y;r.stroke();da.inflate(Y*2)}function i(I){if(f!=I)r.fillStyle=f=I;r.fill()}function j(I,Y,U,E,v,K,$,S,X,ba,Z,ca,la){var ka,fa;ka=$.width-1;fa=$.height-1;S*=ka;X*=fa;ba*=ka;Z*=fa;ca*=ka;la*=fa;U-=I;E-=Y;v-=I;K-=Y;ba-=S;Z-=X;ca-=S;la-=X;fa=1/(ba*la-ca*Z);ka=(la*U-Z*v)*fa;Z=(la*E-Z*K)*fa;U=(ba*v-ca*U)*fa;E=(ba*K-ca*E)*fa;I=I-ka*S-U*X;Y=Y-Z*S-E*X;r.save();r.transform(ka,Z,U,E,I,Y);r.clip();r.drawImage($,
-0,0);r.restore()}function o(I){if(R!=I)r.globalAlpha=R=I}function m(I){if(B!=I){switch(I){case THREE.NormalBlending:r.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:r.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:r.globalCompositeOperation="darker"}B=I}}function q(I,Y,U,E){ia[0]=g(0,n(255,~~(I.r*255)));ia[1]=g(0,n(255,~~(I.g*255)));ia[2]=g(0,n(255,~~(I.b*255)));ia[4]=g(0,n(255,~~(Y.r*255)));ia[5]=g(0,n(255,~~(Y.g*255)));ia[6]=g(0,n(255,~~(Y.b*255)));
-ia[8]=g(0,n(255,~~(U.r*255)));ia[9]=g(0,n(255,~~(U.g*255)));ia[10]=g(0,n(255,~~(U.b*255)));ia[12]=g(0,n(255,~~(E.r*255)));ia[13]=g(0,n(255,~~(E.g*255)));ia[14]=g(0,n(255,~~(E.b*255)));ra.putImageData(wa,0,0);ua.drawImage(sa,0,0);return ta}function l(I){return I<0?n((1+I)*0.5,0.5):0.5+n(I*0.5,0.5)}function c(I,Y){var U=Y.x-I.x,E=Y.y-I.y,v=1/Math.sqrt(U*U+E*E);U*=v;E*=v;Y.x+=U;Y.y+=E;I.x-=U;I.y-=E}var z=null,G=new THREE.Projector,x=document.createElement("canvas"),F,N,J,M,r=x.getContext("2d"),R=1,B=
-0,e=null,f=null,k=1,n=Math.min,g=Math.max,h,w,s,L,u,T,P,t,H,p=new THREE.Color,A=new THREE.Color,y=new THREE.Color,O=new THREE.Color,D=new THREE.Color,C,W,ea,Q,V,ja,za,Aa,Ba,Ca,pa=new THREE.Rectangle,ma=new THREE.Rectangle,da=new THREE.Rectangle,va=false,ha=new THREE.Color,ga=new THREE.Color,na=new THREE.Color,oa=new THREE.Color,Da=Math.PI*2,aa=new THREE.Vector3,sa,ra,wa,ia,ta,ua,qa=16;sa=document.createElement("canvas");sa.width=sa.height=2;ra=sa.getContext("2d");ra.fillStyle="rgba(0,0,0,1)";ra.fillRect(0,
-0,2,2);wa=ra.getImageData(0,0,2,2);ia=wa.data;ta=document.createElement("canvas");ta.width=ta.height=qa;ua=ta.getContext("2d");ua.translate(-qa/2,-qa/2);ua.scale(qa,qa);qa--;this.domElement=x;this.autoClear=true;this.setSize=function(I,Y){F=I;N=Y;J=F/2;M=N/2;x.width=F;x.height=N;pa.set(-J,-M,J,M)};this.clear=function(){if(!ma.isEmpty()){ma.inflate(1);ma.minSelf(pa);r.clearRect(ma.getX(),ma.getY(),ma.getWidth(),ma.getHeight());ma.empty()}};this.render=function(I,Y){var U,E,v,K,$,S,X,ba;r.setTransform(1,
-0,0,-1,J,M);this.autoClear&&this.clear();z=G.projectScene(I,Y);if(va=I.lights.length>0){$=I.lights;ga.setRGB(0,0,0);na.setRGB(0,0,0);oa.setRGB(0,0,0);U=0;for(E=$.length;U<E;U++){v=$[U];K=v.color;if(v instanceof THREE.AmbientLight){ga.r+=K.r;ga.g+=K.g;ga.b+=K.b}else if(v instanceof THREE.DirectionalLight){na.r+=K.r;na.g+=K.g;na.b+=K.b}else if(v instanceof THREE.PointLight){oa.r+=K.r;oa.g+=K.g;oa.b+=K.b}}}U=0;for(E=z.length;U<E;U++){v=z[U];da.empty();if(v instanceof THREE.RenderableParticle){h=v;h.x*=
-J;h.y*=M;K=0;for($=v.material.length;K<$;K++){S=h;X=v;var Z=v.material[K];if(Z.opacity!=0){o(Z.opacity);m(Z.blending);ba=void 0;var ca=void 0,la=void 0,ka=void 0,fa=void 0,xa=void 0,ya=void 0;if(Z instanceof THREE.ParticleBasicMaterial){if(Z.map){fa=Z.map;xa=fa.width>>1;ya=fa.height>>1;la=X.scale.x*J;ka=X.scale.y*M;ba=la*xa;ca=ka*ya;da.set(S.x-ba,S.y-ca,S.x+ba,S.y+ca);if(pa.instersects(da)){r.save();r.translate(S.x,S.y);r.rotate(-X.rotation);r.scale(la,-ka);r.translate(-xa,-ya);r.drawImage(fa,0,0);
-r.restore()}}}else if(Z instanceof THREE.ParticleCircleMaterial){if(va){ha.r=ga.r+na.r+oa.r;ha.g=ga.g+na.g+oa.g;ha.b=ga.b+na.b+oa.b;p.r=Z.color.r*ha.r;p.g=Z.color.g*ha.g;p.b=Z.color.b*ha.b;p.updateStyleString()}else p.__styleString=Z.color.__styleString;ba=X.scale.x*J;ca=X.scale.y*M;da.set(S.x-ba,S.y-ca,S.x+ba,S.y+ca);if(pa.instersects(da)){Z=p.__styleString;if(f!=Z)r.fillStyle=f=Z;r.save();r.translate(S.x,S.y);r.rotate(-X.rotation);r.scale(ba,ca);r.beginPath();r.arc(0,0,1,0,Da,true);r.closePath();
-r.fill();r.restore()}}}}}else if(v instanceof THREE.RenderableLine){h=v.v1;w=v.v2;h.positionScreen.x*=J;h.positionScreen.y*=M;w.positionScreen.x*=J;w.positionScreen.y*=M;da.addPoint(h.positionScreen.x,h.positionScreen.y);da.addPoint(w.positionScreen.x,w.positionScreen.y);if(pa.instersects(da)){K=0;for($=v.material.length;K<$;){X=h;ba=w;S=v.material[K++];if(S.opacity!=0){o(S.opacity);m(S.blending);r.beginPath();r.moveTo(X.positionScreen.x,X.positionScreen.y);r.lineTo(ba.positionScreen.x,ba.positionScreen.y);
-r.closePath();if(S instanceof THREE.LineBasicMaterial){p.__styleString=S.color.__styleString;X=S.linewidth;if(k!=X)r.lineWidth=k=X;X=p.__styleString;if(e!=X)r.strokeStyle=e=X;r.stroke();da.inflate(S.linewidth*2)}}}}}else if(v instanceof THREE.RenderableFace3){h=v.v1;w=v.v2;s=v.v3;h.positionScreen.x*=J;h.positionScreen.y*=M;w.positionScreen.x*=J;w.positionScreen.y*=M;s.positionScreen.x*=J;s.positionScreen.y*=M;if(v.overdraw){c(h.positionScreen,w.positionScreen);c(w.positionScreen,s.positionScreen);
-c(s.positionScreen,h.positionScreen)}da.addPoint(h.positionScreen.x,h.positionScreen.y);da.addPoint(w.positionScreen.x,w.positionScreen.y);da.addPoint(s.positionScreen.x,s.positionScreen.y);if(pa.instersects(da)){K=0;for($=v.meshMaterial.length;K<$;){ba=v.meshMaterial[K++];if(ba instanceof THREE.MeshFaceMaterial){S=0;for(X=v.faceMaterial.length;S<X;)(ba=v.faceMaterial[S++])&&b(h,w,s,v,ba,I)}else b(h,w,s,v,ba,I)}}}ma.addRectangle(da)}r.setTransform(1,0,0,1,0,0)}};
-THREE.SVGRenderer=function(){function a(p,A,y){var O,D,C,W;O=0;for(D=p.lights.length;O<D;O++){C=p.lights[O];if(C instanceof THREE.DirectionalLight){W=A.normalWorld.dot(C.position)*C.intensity;if(W>0){y.r+=C.color.r*W;y.g+=C.color.g*W;y.b+=C.color.b*W}}else if(C instanceof THREE.PointLight){h.sub(C.position,A.centroidWorld);h.normalize();W=A.normalWorld.dot(h)*C.intensity;if(W>0){y.r+=C.color.r*W;y.g+=C.color.g*W;y.b+=C.color.b*W}}}}function b(p,A,y,O,D,C){u=i(T++);u.setAttribute("d","M "+p.positionScreen.x+
-" "+p.positionScreen.y+" L "+A.positionScreen.x+" "+A.positionScreen.y+" L "+y.positionScreen.x+","+y.positionScreen.y+"z");if(D instanceof THREE.MeshBasicMaterial)B.__styleString=D.color.__styleString;else if(D instanceof THREE.MeshLambertMaterial)if(R){e.r=f.r;e.g=f.g;e.b=f.b;a(C,O,e);B.r=D.color.r*e.r;B.g=D.color.g*e.g;B.b=D.color.b*e.b;B.updateStyleString()}else B.__styleString=D.color.__styleString;else if(D instanceof THREE.MeshDepthMaterial){g=1-D.__2near/(D.__farPlusNear-O.z*D.__farMinusNear);
-B.setRGB(g,g,g)}else D instanceof THREE.MeshNormalMaterial&&B.setRGB(j(O.normalWorld.x),j(O.normalWorld.y),j(O.normalWorld.z));D.wireframe?u.setAttribute("style","fill: none; stroke: "+B.__styleString+"; stroke-width: "+D.wireframe_linewidth+"; stroke-opacity: "+D.opacity+"; stroke-linecap: "+D.wireframe_linecap+"; stroke-linejoin: "+D.wireframe_linejoin):u.setAttribute("style","fill: "+B.__styleString+"; fill-opacity: "+D.opacity);q.appendChild(u)}function d(p,A,y,O,D,C,W){u=i(T++);u.setAttribute("d",
-"M "+p.positionScreen.x+" "+p.positionScreen.y+" L "+A.positionScreen.x+" "+A.positionScreen.y+" L "+y.positionScreen.x+","+y.positionScreen.y+" L "+O.positionScreen.x+","+O.positionScreen.y+"z");if(C instanceof THREE.MeshBasicMaterial)B.__styleString=C.color.__styleString;else if(C instanceof THREE.MeshLambertMaterial)if(R){e.r=f.r;e.g=f.g;e.b=f.b;a(W,D,e);B.r=C.color.r*e.r;B.g=C.color.g*e.g;B.b=C.color.b*e.b;B.updateStyleString()}else B.__styleString=C.color.__styleString;else if(C instanceof THREE.MeshDepthMaterial){g=
-1-C.__2near/(C.__farPlusNear-D.z*C.__farMinusNear);B.setRGB(g,g,g)}else C instanceof THREE.MeshNormalMaterial&&B.setRGB(j(D.normalWorld.x),j(D.normalWorld.y),j(D.normalWorld.z));C.wireframe?u.setAttribute("style","fill: none; stroke: "+B.__styleString+"; stroke-width: "+C.wireframe_linewidth+"; stroke-opacity: "+C.opacity+"; stroke-linecap: "+C.wireframe_linecap+"; stroke-linejoin: "+C.wireframe_linejoin):u.setAttribute("style","fill: "+B.__styleString+"; fill-opacity: "+C.opacity);q.appendChild(u)}
-function i(p){if(w[p]==null){w[p]=document.createElementNS("http://www.w3.org/2000/svg","path");H==0&&w[p].setAttribute("shape-rendering","crispEdges");return w[p]}return w[p]}function j(p){return p<0?Math.min((1+p)*0.5,0.5):0.5+Math.min(p*0.5,0.5)}var o=null,m=new THREE.Projector,q=document.createElementNS("http://www.w3.org/2000/svg","svg"),l,c,z,G,x,F,N,J,M=new THREE.Rectangle,r=new THREE.Rectangle,R=false,B=new THREE.Color(16777215),e=new THREE.Color(16777215),f=new THREE.Color(0),k=new THREE.Color(0),
-n=new THREE.Color(0),g,h=new THREE.Vector3,w=[],s=[],L=[],u,T,P,t,H=1;this.domElement=q;this.autoClear=true;this.setQuality=function(p){switch(p){case "high":H=1;break;case "low":H=0}};this.setSize=function(p,A){l=p;c=A;z=l/2;G=c/2;q.setAttribute("viewBox",-z+" "+-G+" "+l+" "+c);q.setAttribute("width",l);q.setAttribute("height",c);M.set(-z,-G,z,G)};this.clear=function(){for(;q.childNodes.length>0;)q.removeChild(q.childNodes[0])};this.render=function(p,A){var y,O,D,C,W,ea,Q,V;this.autoClear&&this.clear();
-o=m.projectScene(p,A);t=P=T=0;if(R=p.lights.length>0){Q=p.lights;f.setRGB(0,0,0);k.setRGB(0,0,0);n.setRGB(0,0,0);y=0;for(O=Q.length;y<O;y++){D=Q[y];C=D.color;if(D instanceof THREE.AmbientLight){f.r+=C.r;f.g+=C.g;f.b+=C.b}else if(D instanceof THREE.DirectionalLight){k.r+=C.r;k.g+=C.g;k.b+=C.b}else if(D instanceof THREE.PointLight){n.r+=C.r;n.g+=C.g;n.b+=C.b}}}y=0;for(O=o.length;y<O;y++){Q=o[y];r.empty();if(Q instanceof THREE.RenderableParticle){x=Q;x.x*=z;x.y*=-G;D=0;for(C=Q.material.length;D<C;D++)if(V=
-Q.material[D]){W=x;ea=Q;V=V;var ja=P++;if(s[ja]==null){s[ja]=document.createElementNS("http://www.w3.org/2000/svg","circle");H==0&&s[ja].setAttribute("shape-rendering","crispEdges")}u=s[ja];u.setAttribute("cx",W.x);u.setAttribute("cy",W.y);u.setAttribute("r",ea.scale.x*z);if(V instanceof THREE.ParticleCircleMaterial){if(R){e.r=f.r+k.r+n.r;e.g=f.g+k.g+n.g;e.b=f.b+k.b+n.b;B.r=V.color.r*e.r;B.g=V.color.g*e.g;B.b=V.color.b*e.b;B.updateStyleString()}else B=V.color;u.setAttribute("style","fill: "+B.__styleString)}q.appendChild(u)}}else if(Q instanceof
-THREE.RenderableLine){x=Q.v1;F=Q.v2;x.positionScreen.x*=z;x.positionScreen.y*=-G;F.positionScreen.x*=z;F.positionScreen.y*=-G;r.addPoint(x.positionScreen.x,x.positionScreen.y);r.addPoint(F.positionScreen.x,F.positionScreen.y);if(M.instersects(r)){D=0;for(C=Q.material.length;D<C;)if(V=Q.material[D++]){W=x;ea=F;V=V;ja=t++;if(L[ja]==null){L[ja]=document.createElementNS("http://www.w3.org/2000/svg","line");H==0&&L[ja].setAttribute("shape-rendering","crispEdges")}u=L[ja];u.setAttribute("x1",W.positionScreen.x);
-u.setAttribute("y1",W.positionScreen.y);u.setAttribute("x2",ea.positionScreen.x);u.setAttribute("y2",ea.positionScreen.y);if(V instanceof THREE.LineBasicMaterial){B.__styleString=V.color.__styleString;u.setAttribute("style","fill: none; stroke: "+B.__styleString+"; stroke-width: "+V.linewidth+"; stroke-opacity: "+V.opacity+"; stroke-linecap: "+V.linecap+"; stroke-linejoin: "+V.linejoin);q.appendChild(u)}}}}else if(Q instanceof THREE.RenderableFace3){x=Q.v1;F=Q.v2;N=Q.v3;x.positionScreen.x*=z;x.positionScreen.y*=
--G;F.positionScreen.x*=z;F.positionScreen.y*=-G;N.positionScreen.x*=z;N.positionScreen.y*=-G;r.addPoint(x.positionScreen.x,x.positionScreen.y);r.addPoint(F.positionScreen.x,F.positionScreen.y);r.addPoint(N.positionScreen.x,N.positionScreen.y);if(M.instersects(r)){D=0;for(C=Q.meshMaterial.length;D<C;){V=Q.meshMaterial[D++];if(V instanceof THREE.MeshFaceMaterial){W=0;for(ea=Q.faceMaterial.length;W<ea;)(V=Q.faceMaterial[W++])&&b(x,F,N,Q,V,p)}else V&&b(x,F,N,Q,V,p)}}}else if(Q instanceof THREE.RenderableFace4){x=
-Q.v1;F=Q.v2;N=Q.v3;J=Q.v4;x.positionScreen.x*=z;x.positionScreen.y*=-G;F.positionScreen.x*=z;F.positionScreen.y*=-G;N.positionScreen.x*=z;N.positionScreen.y*=-G;J.positionScreen.x*=z;J.positionScreen.y*=-G;r.addPoint(x.positionScreen.x,x.positionScreen.y);r.addPoint(F.positionScreen.x,F.positionScreen.y);r.addPoint(N.positionScreen.x,N.positionScreen.y);r.addPoint(J.positionScreen.x,J.positionScreen.y);if(M.instersects(r)){D=0;for(C=Q.meshMaterial.length;D<C;){V=Q.meshMaterial[D++];if(V instanceof
-THREE.MeshFaceMaterial){W=0;for(ea=Q.faceMaterial.length;W<ea;)(V=Q.faceMaterial[W++])&&d(x,F,N,J,Q,V,p)}else V&&d(x,F,N,J,Q,V,p)}}}}}};
-THREE.WebGLRenderer=function(a){function b(e,f){var k=c.createProgram();c.attachShader(k,m("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\n"+e));c.attachShader(k,m("vertex","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"+f));c.linkProgram(k);c.getProgramParameter(k,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(k,
-c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");k.uniforms={};return k}function d(e,f){if(e instanceof THREE.TextureCube&&e.image.length==6){if(!e.image.__webGLTextureCube&&!e.image.__cubeMapInitialized&&e.image.loadCount==6){e.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,e.image.__webGLTextureCube);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,
-c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(var k=0;k<6;++k)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+k,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,e.image[k]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);e.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+f);c.bindTexture(c.TEXTURE_CUBE_MAP,e.image.__webGLTextureCube)}}function i(e,f){if(!e.__webGLTexture&&e.image.loaded){e.__webGLTexture=c.createTexture();
-c.bindTexture(c.TEXTURE_2D,e.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,e.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,q(e.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,q(e.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+f);c.bindTexture(c.TEXTURE_2D,e.__webGLTexture)}
-function j(e,f){var k,n,g;k=0;for(n=f.length;k<n;k++){g=f[k];e.uniforms[g]=c.getUniformLocation(e,g)}}function o(e){e.position=c.getAttribLocation(e,"position");c.enableVertexAttribArray(e.position);e.normal=c.getAttribLocation(e,"normal");c.enableVertexAttribArray(e.normal);e.uv=c.getAttribLocation(e,"uv");c.enableVertexAttribArray(e.uv)}function m(e,f){var k;if(e=="fragment")k=c.createShader(c.FRAGMENT_SHADER);else if(e=="vertex")k=c.createShader(c.VERTEX_SHADER);c.shaderSource(k,f);c.compileShader(k);
-if(!c.getShaderParameter(k,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(k));return null}return k}function q(e){switch(e){case THREE.Repeat:return c.REPEAT;case THREE.ClampToEdge:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeat:return c.MIRRORED_REPEAT}return 0}var l=document.createElement("canvas"),c,z,G,x=new THREE.Matrix4,F,N=new Float32Array(16),J=new Float32Array(16),M=new Float32Array(16),r=new Float32Array(9),R=new Float32Array(16);a=function(e,f){if(e){var k,n,g,h=pointLights=maxDirLights=maxPointLights=
-0;k=0;for(n=e.lights.length;k<n;k++){g=e.lights[k];g instanceof THREE.DirectionalLight&&h++;g instanceof THREE.PointLight&&pointLights++}if(pointLights+h<=f){maxDirLights=h;maxPointLights=pointLights}else{maxDirLights=Math.ceil(f*h/(pointLights+h));maxPointLights=f-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:f-1}}(a,4);this.domElement=l;this.autoClear=true;try{c=l.getContext("experimental-webgl",{antialias:true})}catch(B){}if(!c){alert("WebGL not supported");
-throw"cannot create webgl context";}c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK);c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(0,0,0,0);(function(e,f){var k=[e?"#define MAX_DIR_LIGHTS "+e:"",f?"#define MAX_POINT_LIGHTS "+f:"","uniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",
-e?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",e?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",f?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",f?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","uniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",f?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform float mRefractionRatio;\nvoid main(void) {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec3 transformedNormal = normalize( normalMatrix * normal );\nif ( !enableLighting ) {\nvLightWeighting = vec3( 1.0, 1.0, 1.0 );\n} else {\nvLightWeighting = ambientLightColor;",
-e?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",e?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",e?"float directionalLightWeighting = max( dot( transformedNormal, normalize(lDirection.xyz ) ), 0.0 );":"",e?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",e?"}":"",f?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",f?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",f?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
-"",f?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",f?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",f?"}":"","}\nvNormal = transformedNormal;\nvUv = uv;\nif ( useRefract ) {\nvReflect = refract( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz), mRefractionRatio );\n} else {\nvReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );\n}\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n"),
-n=[e?"#define MAX_DIR_LIGHTS "+e:"",f?"#define MAX_POINT_LIGHTS "+f:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\nuniform float m2Near;\nuniform float mFarPlusNear;\nuniform float mFarMinusNear;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
-e?"uniform mat4 viewMatrix;":"",e?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",f?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform vec3 cameraPosition;\nvoid main() {\nvec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nvec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nif ( enableMap ) {\nmapColor = texture2D( tMap, vUv );\n}\nif ( enableCubeMap ) {\ncubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\n}\nif ( material == 5 ) { \nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( -wPos.x, wPos.yz ) );\n} else if ( material == 4 ) { \ngl_FragColor = vec4( 0.5*normalize( vNormal ) + vec3(0.5, 0.5, 0.5), mOpacity );\n} else if ( material == 3 ) { \nfloat w = 0.5;\ngl_FragColor = vec4( w, w, w, mOpacity );\n} else if ( material == 2 ) { \nvec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );",
-f?"vec4 pointDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",f?"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",f?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",f?"vec3 pointVector = normalize( vPointLightVector[ i ] );":"",f?"vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );":"",f?"float pointDotNormalHalf = dot( normal, pointHalfVector );":"",f?"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );":"",f?"float pointSpecularWeight = 0.0;":"",f?"if ( pointDotNormalHalf >= 0.0 )":
-"",f?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",f?"pointDiffuse  += mColor * pointDiffuseWeight;":"",f?"pointSpecular += mSpecular * pointSpecularWeight;":"",f?"}":"",e?"vec4 dirDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",e?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",e?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",e?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",e?"vec3 dirVector = normalize( lDirection.xyz );":"",e?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
-"",e?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",e?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",e?"float dirSpecularWeight = 0.0;":"",e?"if ( dirDotNormalHalf >= 0.0 )":"",e?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",e?"dirDiffuse  += mColor * dirDiffuseWeight;":"",e?"dirSpecular += mSpecular * dirSpecularWeight;":"",e?"}":"","vec4 totalLight = mAmbient;",e?"totalLight += dirDiffuse + dirSpecular;":"",f?"totalLight += pointDiffuse + pointSpecular;":
+THREE.Projector=function(){function a(S,z){var f=0,k=1,e=S.z+S.w,n=z.z+z.w,h=-S.z+S.w,g=-z.z+z.w;if(e>=0&&n>=0&&h>=0&&g>=0)return true;else if(e<0&&n<0||h<0&&g<0)return false;else{if(e<0)f=Math.max(f,e/(e-n));else if(n<0)k=Math.min(k,e/(e-n));if(h<0)f=Math.max(f,h/(h-g));else if(g<0)k=Math.min(k,h/(h-g));if(k<f)return false;else{S.lerpSelf(z,f);z.lerpSelf(S,1-k);return true}}}var b=null,d,i,j,o=[],m,p,l=[],c,E,G=[],w=new THREE.Vector4,F=new THREE.Matrix4,O=new THREE.Matrix4,J=new THREE.Vector4,M=
+new THREE.Vector4,r;this.projectScene=function(S,z){var f,k,e,n,h,g,q,t,K,A,H,P,u,N,s,y,x;b=[];j=p=E=0;z.autoUpdateMatrix&&z.updateMatrix();F.multiply(z.projectionMatrix,z.matrix);q=S.objects;f=0;for(k=q.length;f<k;f++){t=q[f];t.autoUpdateMatrix&&t.updateMatrix();K=t.matrix;A=t.rotationMatrix;H=t.material;P=t.overdraw;if(t instanceof THREE.Mesh){u=t.geometry.vertices;e=0;for(n=u.length;e<n;e++){N=u[e];N.positionWorld.copy(N.position);K.multiplyVector3(N.positionWorld);s=N.positionScreen;s.copy(N.positionWorld);
+F.multiplyVector4(s);s.multiplyScalar(1/s.w);N.__visible=s.z>0&&s.z<1}N=t.geometry.faces;e=0;for(n=N.length;e<n;e++){s=N[e];if(s instanceof THREE.Face3){h=u[s.a];g=u[s.b];y=u[s.c];if(h.__visible&&g.__visible&&y.__visible)if(t.doubleSided||t.flipSided!=(y.positionScreen.x-h.positionScreen.x)*(g.positionScreen.y-h.positionScreen.y)-(y.positionScreen.y-h.positionScreen.y)*(g.positionScreen.x-h.positionScreen.x)<0){d=o[j]=o[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(h.positionWorld);d.v2.positionWorld.copy(g.positionWorld);
+d.v3.positionWorld.copy(y.positionWorld);d.v1.positionScreen.copy(h.positionScreen);d.v2.positionScreen.copy(g.positionScreen);d.v3.positionScreen.copy(y.positionScreen);d.normalWorld.copy(s.normal);A.multiplyVector3(d.normalWorld);d.centroidWorld.copy(s.centroid);K.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);F.multiplyVector3(d.centroidScreen);y=s.vertexNormals;r=d.vertexNormalsWorld;h=0;for(g=y.length;h<g;h++){x=r[h]=r[h]||new THREE.Vector3;x.copy(y[h]);A.multiplyVector3(x)}d.z=
+d.centroidScreen.z;d.meshMaterial=H;d.faceMaterial=s.material;d.overdraw=P;if(t.geometry.uvs[e]){d.uvs[0]=t.geometry.uvs[e][0];d.uvs[1]=t.geometry.uvs[e][1];d.uvs[2]=t.geometry.uvs[e][2]}b.push(d);j++}}else if(s instanceof THREE.Face4){h=u[s.a];g=u[s.b];y=u[s.c];x=u[s.d];if(h.__visible&&g.__visible&&y.__visible&&x.__visible)if(t.doubleSided||t.flipSided!=((x.positionScreen.x-h.positionScreen.x)*(g.positionScreen.y-h.positionScreen.y)-(x.positionScreen.y-h.positionScreen.y)*(g.positionScreen.x-h.positionScreen.x)<
+0||(g.positionScreen.x-y.positionScreen.x)*(x.positionScreen.y-y.positionScreen.y)-(g.positionScreen.y-y.positionScreen.y)*(x.positionScreen.x-y.positionScreen.x)<0)){d=o[j]=o[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(h.positionWorld);d.v2.positionWorld.copy(g.positionWorld);d.v3.positionWorld.copy(x.positionWorld);d.v1.positionScreen.copy(h.positionScreen);d.v2.positionScreen.copy(g.positionScreen);d.v3.positionScreen.copy(x.positionScreen);d.normalWorld.copy(s.normal);A.multiplyVector3(d.normalWorld);
+d.centroidWorld.copy(s.centroid);K.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);F.multiplyVector3(d.centroidScreen);d.z=d.centroidScreen.z;d.meshMaterial=H;d.faceMaterial=s.material;d.overdraw=P;if(t.geometry.uvs[e]){d.uvs[0]=t.geometry.uvs[e][0];d.uvs[1]=t.geometry.uvs[e][1];d.uvs[2]=t.geometry.uvs[e][3]}b.push(d);j++;i=o[j]=o[j]||new THREE.RenderableFace3;i.v1.positionWorld.copy(g.positionWorld);i.v2.positionWorld.copy(y.positionWorld);i.v3.positionWorld.copy(x.positionWorld);
+i.v1.positionScreen.copy(g.positionScreen);i.v2.positionScreen.copy(y.positionScreen);i.v3.positionScreen.copy(x.positionScreen);i.normalWorld.copy(d.normalWorld);i.centroidWorld.copy(d.centroidWorld);i.centroidScreen.copy(d.centroidScreen);i.z=i.centroidScreen.z;i.meshMaterial=H;i.faceMaterial=s.material;i.overdraw=P;if(t.geometry.uvs[e]){i.uvs[0]=t.geometry.uvs[e][1];i.uvs[1]=t.geometry.uvs[e][2];i.uvs[2]=t.geometry.uvs[e][3]}b.push(i);j++}}}}else if(t instanceof THREE.Line){O.multiply(F,K);u=t.geometry.vertices;
+N=u[0];N.positionScreen.copy(N.position);O.multiplyVector4(N.positionScreen);e=1;for(n=u.length;e<n;e++){h=u[e];h.positionScreen.copy(h.position);O.multiplyVector4(h.positionScreen);g=u[e-1];J.copy(h.positionScreen);M.copy(g.positionScreen);if(a(J,M)){J.multiplyScalar(1/J.w);M.multiplyScalar(1/M.w);m=l[p]=l[p]||new THREE.RenderableLine;m.v1.positionScreen.copy(J);m.v2.positionScreen.copy(M);m.z=Math.max(J.z,M.z);m.material=t.material;b.push(m);p++}}}else if(t instanceof THREE.Particle){w.set(t.position.x,
+t.position.y,t.position.z,1);F.multiplyVector4(w);w.z/=w.w;if(w.z>0&&w.z<1){c=G[E]=G[E]||new THREE.RenderableParticle;c.x=w.x/w.w;c.y=w.y/w.w;c.z=w.z;c.rotation=t.rotation.z;c.scale.x=t.scale.x*Math.abs(c.x-(w.x+z.projectionMatrix.n11)/(w.w+z.projectionMatrix.n14));c.scale.y=t.scale.y*Math.abs(c.y-(w.y+z.projectionMatrix.n22)/(w.w+z.projectionMatrix.n24));c.material=t.material;b.push(c);E++}}}b.sort(function(Q,C){return C.z-Q.z});return b};this.unprojectVector=function(S,z){var f=new THREE.Matrix4;
+f.multiply(THREE.Matrix4.makeInvert(z.matrix),THREE.Matrix4.makeInvert(z.projectionMatrix));f.multiplyVector3(S);return S}};
+THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,d,i,j,o;this.domElement=document.createElement("div");this.setSize=function(m,p){d=m;i=p;j=d/2;o=i/2};this.render=function(m,p){var l,c,E,G,w,F,O,J;a=b.projectScene(m,p);l=0;for(c=a.length;l<c;l++){w=a[l];if(w instanceof THREE.RenderableParticle){O=w.x*j+j;J=w.y*o+o;E=0;for(G=w.material.length;E<G;E++){F=w.material[E];if(F instanceof THREE.ParticleDOMMaterial){F=F.domElement;F.style.left=O+"px";F.style.top=J+"px"}}}}}};
+THREE.CanvasRenderer=function(){function a(I,Y,U,D){var v,L,$,T,X=I.lights;I=0;for(v=X.length;I<v;I++){L=X[I];$=L.color;T=L.intensity;if(L instanceof THREE.DirectionalLight){L=U.dot(L.position)*T;if(L>0){D.r+=$.r*L;D.g+=$.g*L;D.b+=$.b*L}}else if(L instanceof THREE.PointLight){aa.sub(L.position,Y);aa.normalize();L=U.dot(aa)*T;if(L>0){D.r+=$.r*L;D.g+=$.g*L;D.b+=$.b*L}}}}function b(I,Y,U,D,v,L){if(v.opacity!=0){o(v.opacity);m(v.blending);K=I.positionScreen.x;A=I.positionScreen.y;H=Y.positionScreen.x;
+P=Y.positionScreen.y;u=U.positionScreen.x;N=U.positionScreen.y;var $=K,T=A,X=H,ba=P,Z=u,ca=N;r.beginPath();r.moveTo($,T);r.lineTo(X,ba);r.lineTo(Z,ca);r.lineTo($,T);r.closePath();if(v instanceof THREE.MeshBasicMaterial)if(v.map&&v.map.loaded)j(K,A,H,P,u,N,v.map.image,D.uvs[0].u,D.uvs[0].v,D.uvs[1].u,D.uvs[1].v,D.uvs[2].u,D.uvs[2].v);else if(v.env_map&&v.env_map.loaded){if(v.env_map.mapping==THREE.ReflectionMapping){aa.copy(D.vertexNormalsWorld[0]);V=(aa.x*camera.matrix.n11+aa.y*camera.matrix.n12+
+aa.z*camera.matrix.n13)*0.5+0.5;ja=-(aa.x*camera.matrix.n21+aa.y*camera.matrix.n22+aa.z*camera.matrix.n23)*0.5+0.5;aa.copy(D.vertexNormalsWorld[1]);za=(aa.x*camera.matrix.n11+aa.y*camera.matrix.n12+aa.z*camera.matrix.n13)*0.5+0.5;Aa=-(aa.x*camera.matrix.n21+aa.y*camera.matrix.n22+aa.z*camera.matrix.n23)*0.5+0.5;aa.copy(D.vertexNormalsWorld[2]);Ba=(aa.x*camera.matrix.n11+aa.y*camera.matrix.n12+aa.z*camera.matrix.n13)*0.5+0.5;Ca=-(aa.x*camera.matrix.n21+aa.y*camera.matrix.n22+aa.z*camera.matrix.n23)*
+0.5+0.5;j(K,A,H,P,u,N,v.env_map.image,V,ja,za,Aa,Ba,Ca)}}else v.wireframe?d(v.color.__styleString,v.wireframe_linewidth):i(v.color.__styleString);else if(v instanceof THREE.MeshLambertMaterial){if(v.map&&!v.wireframe){j(K,A,H,P,u,N,v.map.image,D.uvs[0].u,D.uvs[0].v,D.uvs[1].u,D.uvs[1].v,D.uvs[2].u,D.uvs[2].v);m(THREE.SubtractiveBlending)}if(va)if(!v.wireframe&&v.shading==THREE.SmoothShading&&D.vertexNormalsWorld.length==3){y.r=x.r=Q.r=ga.r;y.g=x.g=Q.g=ga.g;y.b=x.b=Q.b=ga.b;a(L,D.v1.positionWorld,
+D.vertexNormalsWorld[0],y);a(L,D.v2.positionWorld,D.vertexNormalsWorld[1],x);a(L,D.v3.positionWorld,D.vertexNormalsWorld[2],Q);C.r=(x.r+Q.r)*0.5;C.g=(x.g+Q.g)*0.5;C.b=(x.b+Q.b)*0.5;R=p(y,x,Q,C);j(K,A,H,P,u,N,R,0,0,1,0,0,1)}else{ha.r=ga.r;ha.g=ga.g;ha.b=ga.b;a(L,D.centroidWorld,D.normalWorld,ha);s.r=v.color.r*ha.r;s.g=v.color.g*ha.g;s.b=v.color.b*ha.b;s.updateStyleString();v.wireframe?d(s.__styleString,v.wireframe_linewidth):i(s.__styleString)}else v.wireframe?d(v.color.__styleString,v.wireframe_linewidth):
+i(v.color.__styleString)}else if(v instanceof THREE.MeshDepthMaterial){B=v.__2near;W=v.__farPlusNear;ea=v.__farMinusNear;y.r=y.g=y.b=1-B/(W-I.positionScreen.z*ea);x.r=x.g=x.b=1-B/(W-Y.positionScreen.z*ea);Q.r=Q.g=Q.b=1-B/(W-U.positionScreen.z*ea);C.r=(x.r+Q.r)*0.5;C.g=(x.g+Q.g)*0.5;C.b=(x.b+Q.b)*0.5;R=p(y,x,Q,C);j(K,A,H,P,u,N,R,0,0,1,0,0,1)}else if(v instanceof THREE.MeshNormalMaterial){s.r=l(D.normalWorld.x);s.g=l(D.normalWorld.y);s.b=l(D.normalWorld.z);s.updateStyleString();v.wireframe?d(s.__styleString,
+v.wireframe_linewidth):i(s.__styleString)}}}function d(I,Y){if(f!=I)r.strokeStyle=f=I;if(e!=Y)r.lineWidth=e=Y;r.stroke();da.inflate(Y*2)}function i(I){if(k!=I)r.fillStyle=k=I;r.fill()}function j(I,Y,U,D,v,L,$,T,X,ba,Z,ca,la){var ka,fa;ka=$.width-1;fa=$.height-1;T*=ka;X*=fa;ba*=ka;Z*=fa;ca*=ka;la*=fa;U-=I;D-=Y;v-=I;L-=Y;ba-=T;Z-=X;ca-=T;la-=X;fa=1/(ba*la-ca*Z);ka=(la*U-Z*v)*fa;Z=(la*D-Z*L)*fa;U=(ba*v-ca*U)*fa;D=(ba*L-ca*D)*fa;I=I-ka*T-U*X;Y=Y-Z*T-D*X;r.save();r.transform(ka,Z,U,D,I,Y);r.clip();r.drawImage($,
+0,0);r.restore()}function o(I){if(S!=I)r.globalAlpha=S=I}function m(I){if(z!=I){switch(I){case THREE.NormalBlending:r.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:r.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:r.globalCompositeOperation="darker"}z=I}}function p(I,Y,U,D){ia[0]=h(0,n(255,~~(I.r*255)));ia[1]=h(0,n(255,~~(I.g*255)));ia[2]=h(0,n(255,~~(I.b*255)));ia[4]=h(0,n(255,~~(Y.r*255)));ia[5]=h(0,n(255,~~(Y.g*255)));ia[6]=h(0,n(255,~~(Y.b*255)));
+ia[8]=h(0,n(255,~~(U.r*255)));ia[9]=h(0,n(255,~~(U.g*255)));ia[10]=h(0,n(255,~~(U.b*255)));ia[12]=h(0,n(255,~~(D.r*255)));ia[13]=h(0,n(255,~~(D.g*255)));ia[14]=h(0,n(255,~~(D.b*255)));ra.putImageData(wa,0,0);ua.drawImage(sa,0,0);return ta}function l(I){return I<0?n((1+I)*0.5,0.5):0.5+n(I*0.5,0.5)}function c(I,Y){var U=Y.x-I.x,D=Y.y-I.y,v=1/Math.sqrt(U*U+D*D);U*=v;D*=v;Y.x+=U;Y.y+=D;I.x-=U;I.y-=D}var E=null,G=new THREE.Projector,w=document.createElement("canvas"),F,O,J,M,r=w.getContext("2d"),S=1,z=
+0,f=null,k=null,e=1,n=Math.min,h=Math.max,g,q,t,K,A,H,P,u,N,s=new THREE.Color,y=new THREE.Color,x=new THREE.Color,Q=new THREE.Color,C=new THREE.Color,B,W,ea,R,V,ja,za,Aa,Ba,Ca,pa=new THREE.Rectangle,ma=new THREE.Rectangle,da=new THREE.Rectangle,va=false,ha=new THREE.Color,ga=new THREE.Color,na=new THREE.Color,oa=new THREE.Color,Da=Math.PI*2,aa=new THREE.Vector3,sa,ra,wa,ia,ta,ua,qa=16;sa=document.createElement("canvas");sa.width=sa.height=2;ra=sa.getContext("2d");ra.fillStyle="rgba(0,0,0,1)";ra.fillRect(0,
+0,2,2);wa=ra.getImageData(0,0,2,2);ia=wa.data;ta=document.createElement("canvas");ta.width=ta.height=qa;ua=ta.getContext("2d");ua.translate(-qa/2,-qa/2);ua.scale(qa,qa);qa--;this.domElement=w;this.autoClear=true;this.setSize=function(I,Y){F=I;O=Y;J=F/2;M=O/2;w.width=F;w.height=O;pa.set(-J,-M,J,M)};this.clear=function(){if(!ma.isEmpty()){ma.inflate(1);ma.minSelf(pa);r.clearRect(ma.getX(),ma.getY(),ma.getWidth(),ma.getHeight());ma.empty()}};this.render=function(I,Y){var U,D,v,L,$,T,X,ba;r.setTransform(1,
+0,0,-1,J,M);this.autoClear&&this.clear();E=G.projectScene(I,Y);if(va=I.lights.length>0){$=I.lights;ga.setRGB(0,0,0);na.setRGB(0,0,0);oa.setRGB(0,0,0);U=0;for(D=$.length;U<D;U++){v=$[U];L=v.color;if(v instanceof THREE.AmbientLight){ga.r+=L.r;ga.g+=L.g;ga.b+=L.b}else if(v instanceof THREE.DirectionalLight){na.r+=L.r;na.g+=L.g;na.b+=L.b}else if(v instanceof THREE.PointLight){oa.r+=L.r;oa.g+=L.g;oa.b+=L.b}}}U=0;for(D=E.length;U<D;U++){v=E[U];da.empty();if(v instanceof THREE.RenderableParticle){g=v;g.x*=
+J;g.y*=M;L=0;for($=v.material.length;L<$;L++){T=g;X=v;var Z=v.material[L];if(Z.opacity!=0){o(Z.opacity);m(Z.blending);ba=void 0;var ca=void 0,la=void 0,ka=void 0,fa=void 0,xa=void 0,ya=void 0;if(Z instanceof THREE.ParticleBasicMaterial){if(Z.map){fa=Z.map;xa=fa.width>>1;ya=fa.height>>1;la=X.scale.x*J;ka=X.scale.y*M;ba=la*xa;ca=ka*ya;da.set(T.x-ba,T.y-ca,T.x+ba,T.y+ca);if(pa.instersects(da)){r.save();r.translate(T.x,T.y);r.rotate(-X.rotation);r.scale(la,-ka);r.translate(-xa,-ya);r.drawImage(fa,0,0);
+r.restore()}}}else if(Z instanceof THREE.ParticleCircleMaterial){if(va){ha.r=ga.r+na.r+oa.r;ha.g=ga.g+na.g+oa.g;ha.b=ga.b+na.b+oa.b;s.r=Z.color.r*ha.r;s.g=Z.color.g*ha.g;s.b=Z.color.b*ha.b;s.updateStyleString()}else s.__styleString=Z.color.__styleString;ba=X.scale.x*J;ca=X.scale.y*M;da.set(T.x-ba,T.y-ca,T.x+ba,T.y+ca);if(pa.instersects(da)){Z=s.__styleString;if(k!=Z)r.fillStyle=k=Z;r.save();r.translate(T.x,T.y);r.rotate(-X.rotation);r.scale(ba,ca);r.beginPath();r.arc(0,0,1,0,Da,true);r.closePath();
+r.fill();r.restore()}}}}}else if(v instanceof THREE.RenderableLine){g=v.v1;q=v.v2;g.positionScreen.x*=J;g.positionScreen.y*=M;q.positionScreen.x*=J;q.positionScreen.y*=M;da.addPoint(g.positionScreen.x,g.positionScreen.y);da.addPoint(q.positionScreen.x,q.positionScreen.y);if(pa.instersects(da)){L=0;for($=v.material.length;L<$;){X=g;ba=q;T=v.material[L++];if(T.opacity!=0){o(T.opacity);m(T.blending);r.beginPath();r.moveTo(X.positionScreen.x,X.positionScreen.y);r.lineTo(ba.positionScreen.x,ba.positionScreen.y);
+r.closePath();if(T instanceof THREE.LineBasicMaterial){s.__styleString=T.color.__styleString;X=T.linewidth;if(e!=X)r.lineWidth=e=X;X=s.__styleString;if(f!=X)r.strokeStyle=f=X;r.stroke();da.inflate(T.linewidth*2)}}}}}else if(v instanceof THREE.RenderableFace3){g=v.v1;q=v.v2;t=v.v3;g.positionScreen.x*=J;g.positionScreen.y*=M;q.positionScreen.x*=J;q.positionScreen.y*=M;t.positionScreen.x*=J;t.positionScreen.y*=M;if(v.overdraw){c(g.positionScreen,q.positionScreen);c(q.positionScreen,t.positionScreen);
+c(t.positionScreen,g.positionScreen)}da.addPoint(g.positionScreen.x,g.positionScreen.y);da.addPoint(q.positionScreen.x,q.positionScreen.y);da.addPoint(t.positionScreen.x,t.positionScreen.y);if(pa.instersects(da)){L=0;for($=v.meshMaterial.length;L<$;){ba=v.meshMaterial[L++];if(ba instanceof THREE.MeshFaceMaterial){T=0;for(X=v.faceMaterial.length;T<X;)(ba=v.faceMaterial[T++])&&b(g,q,t,v,ba,I)}else b(g,q,t,v,ba,I)}}}ma.addRectangle(da)}r.setTransform(1,0,0,1,0,0)}};
+THREE.SVGRenderer=function(){function a(s,y,x){var Q,C,B,W;Q=0;for(C=s.lights.length;Q<C;Q++){B=s.lights[Q];if(B instanceof THREE.DirectionalLight){W=y.normalWorld.dot(B.position)*B.intensity;if(W>0){x.r+=B.color.r*W;x.g+=B.color.g*W;x.b+=B.color.b*W}}else if(B instanceof THREE.PointLight){g.sub(B.position,y.centroidWorld);g.normalize();W=y.normalWorld.dot(g)*B.intensity;if(W>0){x.r+=B.color.r*W;x.g+=B.color.g*W;x.b+=B.color.b*W}}}}function b(s,y,x,Q,C,B){A=i(H++);A.setAttribute("d","M "+s.positionScreen.x+
+" "+s.positionScreen.y+" L "+y.positionScreen.x+" "+y.positionScreen.y+" L "+x.positionScreen.x+","+x.positionScreen.y+"z");if(C instanceof THREE.MeshBasicMaterial)z.__styleString=C.color.__styleString;else if(C instanceof THREE.MeshLambertMaterial)if(S){f.r=k.r;f.g=k.g;f.b=k.b;a(B,Q,f);z.r=C.color.r*f.r;z.g=C.color.g*f.g;z.b=C.color.b*f.b;z.updateStyleString()}else z.__styleString=C.color.__styleString;else if(C instanceof THREE.MeshDepthMaterial){h=1-C.__2near/(C.__farPlusNear-Q.z*C.__farMinusNear);
+z.setRGB(h,h,h)}else C instanceof THREE.MeshNormalMaterial&&z.setRGB(j(Q.normalWorld.x),j(Q.normalWorld.y),j(Q.normalWorld.z));C.wireframe?A.setAttribute("style","fill: none; stroke: "+z.__styleString+"; stroke-width: "+C.wireframe_linewidth+"; stroke-opacity: "+C.opacity+"; stroke-linecap: "+C.wireframe_linecap+"; stroke-linejoin: "+C.wireframe_linejoin):A.setAttribute("style","fill: "+z.__styleString+"; fill-opacity: "+C.opacity);p.appendChild(A)}function d(s,y,x,Q,C,B,W){A=i(H++);A.setAttribute("d",
+"M "+s.positionScreen.x+" "+s.positionScreen.y+" L "+y.positionScreen.x+" "+y.positionScreen.y+" L "+x.positionScreen.x+","+x.positionScreen.y+" L "+Q.positionScreen.x+","+Q.positionScreen.y+"z");if(B instanceof THREE.MeshBasicMaterial)z.__styleString=B.color.__styleString;else if(B instanceof THREE.MeshLambertMaterial)if(S){f.r=k.r;f.g=k.g;f.b=k.b;a(W,C,f);z.r=B.color.r*f.r;z.g=B.color.g*f.g;z.b=B.color.b*f.b;z.updateStyleString()}else z.__styleString=B.color.__styleString;else if(B instanceof THREE.MeshDepthMaterial){h=
+1-B.__2near/(B.__farPlusNear-C.z*B.__farMinusNear);z.setRGB(h,h,h)}else B instanceof THREE.MeshNormalMaterial&&z.setRGB(j(C.normalWorld.x),j(C.normalWorld.y),j(C.normalWorld.z));B.wireframe?A.setAttribute("style","fill: none; stroke: "+z.__styleString+"; stroke-width: "+B.wireframe_linewidth+"; stroke-opacity: "+B.opacity+"; stroke-linecap: "+B.wireframe_linecap+"; stroke-linejoin: "+B.wireframe_linejoin):A.setAttribute("style","fill: "+z.__styleString+"; fill-opacity: "+B.opacity);p.appendChild(A)}
+function i(s){if(q[s]==null){q[s]=document.createElementNS("http://www.w3.org/2000/svg","path");N==0&&q[s].setAttribute("shape-rendering","crispEdges");return q[s]}return q[s]}function j(s){return s<0?Math.min((1+s)*0.5,0.5):0.5+Math.min(s*0.5,0.5)}var o=null,m=new THREE.Projector,p=document.createElementNS("http://www.w3.org/2000/svg","svg"),l,c,E,G,w,F,O,J,M=new THREE.Rectangle,r=new THREE.Rectangle,S=false,z=new THREE.Color(16777215),f=new THREE.Color(16777215),k=new THREE.Color(0),e=new THREE.Color(0),
+n=new THREE.Color(0),h,g=new THREE.Vector3,q=[],t=[],K=[],A,H,P,u,N=1;this.domElement=p;this.autoClear=true;this.setQuality=function(s){switch(s){case "high":N=1;break;case "low":N=0}};this.setSize=function(s,y){l=s;c=y;E=l/2;G=c/2;p.setAttribute("viewBox",-E+" "+-G+" "+l+" "+c);p.setAttribute("width",l);p.setAttribute("height",c);M.set(-E,-G,E,G)};this.clear=function(){for(;p.childNodes.length>0;)p.removeChild(p.childNodes[0])};this.render=function(s,y){var x,Q,C,B,W,ea,R,V;this.autoClear&&this.clear();
+o=m.projectScene(s,y);u=P=H=0;if(S=s.lights.length>0){R=s.lights;k.setRGB(0,0,0);e.setRGB(0,0,0);n.setRGB(0,0,0);x=0;for(Q=R.length;x<Q;x++){C=R[x];B=C.color;if(C instanceof THREE.AmbientLight){k.r+=B.r;k.g+=B.g;k.b+=B.b}else if(C instanceof THREE.DirectionalLight){e.r+=B.r;e.g+=B.g;e.b+=B.b}else if(C instanceof THREE.PointLight){n.r+=B.r;n.g+=B.g;n.b+=B.b}}}x=0;for(Q=o.length;x<Q;x++){R=o[x];r.empty();if(R instanceof THREE.RenderableParticle){w=R;w.x*=E;w.y*=-G;C=0;for(B=R.material.length;C<B;C++)if(V=
+R.material[C]){W=w;ea=R;V=V;var ja=P++;if(t[ja]==null){t[ja]=document.createElementNS("http://www.w3.org/2000/svg","circle");N==0&&t[ja].setAttribute("shape-rendering","crispEdges")}A=t[ja];A.setAttribute("cx",W.x);A.setAttribute("cy",W.y);A.setAttribute("r",ea.scale.x*E);if(V instanceof THREE.ParticleCircleMaterial){if(S){f.r=k.r+e.r+n.r;f.g=k.g+e.g+n.g;f.b=k.b+e.b+n.b;z.r=V.color.r*f.r;z.g=V.color.g*f.g;z.b=V.color.b*f.b;z.updateStyleString()}else z=V.color;A.setAttribute("style","fill: "+z.__styleString)}p.appendChild(A)}}else if(R instanceof
+THREE.RenderableLine){w=R.v1;F=R.v2;w.positionScreen.x*=E;w.positionScreen.y*=-G;F.positionScreen.x*=E;F.positionScreen.y*=-G;r.addPoint(w.positionScreen.x,w.positionScreen.y);r.addPoint(F.positionScreen.x,F.positionScreen.y);if(M.instersects(r)){C=0;for(B=R.material.length;C<B;)if(V=R.material[C++]){W=w;ea=F;V=V;ja=u++;if(K[ja]==null){K[ja]=document.createElementNS("http://www.w3.org/2000/svg","line");N==0&&K[ja].setAttribute("shape-rendering","crispEdges")}A=K[ja];A.setAttribute("x1",W.positionScreen.x);
+A.setAttribute("y1",W.positionScreen.y);A.setAttribute("x2",ea.positionScreen.x);A.setAttribute("y2",ea.positionScreen.y);if(V instanceof THREE.LineBasicMaterial){z.__styleString=V.color.__styleString;A.setAttribute("style","fill: none; stroke: "+z.__styleString+"; stroke-width: "+V.linewidth+"; stroke-opacity: "+V.opacity+"; stroke-linecap: "+V.linecap+"; stroke-linejoin: "+V.linejoin);p.appendChild(A)}}}}else if(R instanceof THREE.RenderableFace3){w=R.v1;F=R.v2;O=R.v3;w.positionScreen.x*=E;w.positionScreen.y*=
+-G;F.positionScreen.x*=E;F.positionScreen.y*=-G;O.positionScreen.x*=E;O.positionScreen.y*=-G;r.addPoint(w.positionScreen.x,w.positionScreen.y);r.addPoint(F.positionScreen.x,F.positionScreen.y);r.addPoint(O.positionScreen.x,O.positionScreen.y);if(M.instersects(r)){C=0;for(B=R.meshMaterial.length;C<B;){V=R.meshMaterial[C++];if(V instanceof THREE.MeshFaceMaterial){W=0;for(ea=R.faceMaterial.length;W<ea;)(V=R.faceMaterial[W++])&&b(w,F,O,R,V,s)}else V&&b(w,F,O,R,V,s)}}}else if(R instanceof THREE.RenderableFace4){w=
+R.v1;F=R.v2;O=R.v3;J=R.v4;w.positionScreen.x*=E;w.positionScreen.y*=-G;F.positionScreen.x*=E;F.positionScreen.y*=-G;O.positionScreen.x*=E;O.positionScreen.y*=-G;J.positionScreen.x*=E;J.positionScreen.y*=-G;r.addPoint(w.positionScreen.x,w.positionScreen.y);r.addPoint(F.positionScreen.x,F.positionScreen.y);r.addPoint(O.positionScreen.x,O.positionScreen.y);r.addPoint(J.positionScreen.x,J.positionScreen.y);if(M.instersects(r)){C=0;for(B=R.meshMaterial.length;C<B;){V=R.meshMaterial[C++];if(V instanceof
+THREE.MeshFaceMaterial){W=0;for(ea=R.faceMaterial.length;W<ea;)(V=R.faceMaterial[W++])&&d(w,F,O,J,R,V,s)}else V&&d(w,F,O,J,R,V,s)}}}}}};
+THREE.WebGLRenderer=function(a){function b(f,k){var e=c.createProgram();c.attachShader(e,m("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\n"+f));c.attachShader(e,m("vertex","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"+k));c.linkProgram(e);c.getProgramParameter(e,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(e,
+c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");e.uniforms={};e.attributes={};return e}function d(f,k){if(f instanceof THREE.TextureCube&&f.image.length==6){if(!f.image.__webGLTextureCube&&!f.image.__cubeMapInitialized&&f.image.loadCount==6){f.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,f.image.__webGLTextureCube);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,
+c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(var e=0;e<6;++e)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,f.image[e]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);f.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+k);c.bindTexture(c.TEXTURE_CUBE_MAP,f.image.__webGLTextureCube)}}function i(f,k){if(!f.__webGLTexture&&f.image.loaded){f.__webGLTexture=c.createTexture();
+c.bindTexture(c.TEXTURE_2D,f.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,f.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,p(f.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,p(f.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+k);c.bindTexture(c.TEXTURE_2D,f.__webGLTexture)}
+function j(f,k){var e,n,h;e=0;for(n=k.length;e<n;e++){h=k[e];f.uniforms[h]=c.getUniformLocation(f,h)}}function o(f,k){var e,n,h;e=0;for(n=k.length;e<n;e++){h=k[e];f.attributes[h]=c.getAttribLocation(f,h);f.attributes[h]>=0&&c.enableVertexAttribArray(f.attributes[h])}}function m(f,k){var e;if(f=="fragment")e=c.createShader(c.FRAGMENT_SHADER);else if(f=="vertex")e=c.createShader(c.VERTEX_SHADER);c.shaderSource(e,k);c.compileShader(e);if(!c.getShaderParameter(e,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(e));
+return null}return e}function p(f){switch(f){case THREE.Repeat:return c.REPEAT;case THREE.ClampToEdge:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeat:return c.MIRRORED_REPEAT}return 0}var l=document.createElement("canvas"),c,E,G,w=new THREE.Matrix4,F,O=new Float32Array(16),J=new Float32Array(16),M=new Float32Array(16),r=new Float32Array(9),S=new Float32Array(16);a=function(f,k){if(f){var e,n,h,g=pointLights=maxDirLights=maxPointLights=0;e=0;for(n=f.lights.length;e<n;e++){h=f.lights[e];h instanceof
+THREE.DirectionalLight&&g++;h instanceof THREE.PointLight&&pointLights++}if(pointLights+g<=k){maxDirLights=g;maxPointLights=pointLights}else{maxDirLights=Math.ceil(k*g/(pointLights+g));maxPointLights=k-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:k-1}}(a,4);this.domElement=l;this.autoClear=true;try{c=l.getContext("experimental-webgl",{antialias:true})}catch(z){}if(!c){alert("WebGL not supported");throw"cannot create webgl context";}c.clearColor(0,0,
+0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK);c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(0,0,0,0);E=G=function(f,k){var e=[f?"#define MAX_DIR_LIGHTS "+f:"",k?"#define MAX_POINT_LIGHTS "+k:"","uniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",f?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":
+"",f?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",k?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",k?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","uniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",k?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform float mRefractionRatio;\nvoid main(void) {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec3 transformedNormal = normalize( normalMatrix * normal );\nif ( !enableLighting ) {\nvLightWeighting = vec3( 1.0, 1.0, 1.0 );\n} else {\nvLightWeighting = ambientLightColor;",
+f?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",f?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",f?"float directionalLightWeighting = max( dot( transformedNormal, normalize(lDirection.xyz ) ), 0.0 );":"",f?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",f?"}":"",k?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",k?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",k?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
+"",k?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",k?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",k?"}":"","}\nvNormal = transformedNormal;\nvUv = uv;\nif ( useRefract ) {\nvReflect = refract( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz), mRefractionRatio );\n} else {\nvReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );\n}\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n"),
+n=[f?"#define MAX_DIR_LIGHTS "+f:"",k?"#define MAX_POINT_LIGHTS "+k:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\nuniform float m2Near;\nuniform float mFarPlusNear;\nuniform float mFarMinusNear;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
+f?"uniform mat4 viewMatrix;":"",f?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",k?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform vec3 cameraPosition;\nvoid main() {\nvec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nvec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nif ( enableMap ) {\nmapColor = texture2D( tMap, vUv );\n}\nif ( enableCubeMap ) {\ncubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\n}\nif ( material == 5 ) { \nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( -wPos.x, wPos.yz ) );\n} else if ( material == 4 ) { \ngl_FragColor = vec4( 0.5*normalize( vNormal ) + vec3(0.5, 0.5, 0.5), mOpacity );\n} else if ( material == 3 ) { \nfloat w = 0.5;\ngl_FragColor = vec4( w, w, w, mOpacity );\n} else if ( material == 2 ) { \nvec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );",
+k?"vec4 pointDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",k?"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",k?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",k?"vec3 pointVector = normalize( vPointLightVector[ i ] );":"",k?"vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );":"",k?"float pointDotNormalHalf = dot( normal, pointHalfVector );":"",k?"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );":"",k?"float pointSpecularWeight = 0.0;":"",k?"if ( pointDotNormalHalf >= 0.0 )":
+"",k?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",k?"pointDiffuse  += mColor * pointDiffuseWeight;":"",k?"pointSpecular += mSpecular * pointSpecularWeight;":"",k?"}":"",f?"vec4 dirDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",f?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",f?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",f?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",f?"vec3 dirVector = normalize( lDirection.xyz );":"",f?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
+"",f?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",f?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",f?"float dirSpecularWeight = 0.0;":"",f?"if ( dirDotNormalHalf >= 0.0 )":"",f?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",f?"dirDiffuse  += mColor * dirDiffuseWeight;":"",f?"dirSpecular += mSpecular * dirSpecularWeight;":"",f?"}":"","vec4 totalLight = mAmbient;",f?"totalLight += dirDiffuse + dirSpecular;":"",k?"totalLight += pointDiffuse + pointSpecular;":
 "","if ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mapColor.rgb * totalLight.xyz * vLightWeighting, cubeColor.rgb, mReflectivity ), mapColor.a );\n} else {\ngl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );\n}\n} else if ( material == 1 ) {\nif ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mColor.rgb * mapColor.rgb * vLightWeighting, cubeColor.rgb, mReflectivity ), mColor.a * mapColor.a );\n} else {\ngl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );\n}\n} else {\nif ( mixEnvMap ) {\ngl_FragColor = mix( mColor * mapColor, cubeColor, mReflectivity );\n} else {\ngl_FragColor = mColor * mapColor * cubeColor;\n}\n}\n}"].join("\n");
 "","if ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mapColor.rgb * totalLight.xyz * vLightWeighting, cubeColor.rgb, mReflectivity ), mapColor.a );\n} else {\ngl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );\n}\n} else if ( material == 1 ) {\nif ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mColor.rgb * mapColor.rgb * vLightWeighting, cubeColor.rgb, mReflectivity ), mColor.a * mapColor.a );\n} else {\ngl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );\n}\n} else {\nif ( mixEnvMap ) {\ngl_FragColor = mix( mColor * mapColor, cubeColor, mReflectivity );\n} else {\ngl_FragColor = mColor * mapColor * cubeColor;\n}\n}\n}"].join("\n");
-z=b(n,k);c.useProgram(z);j(z,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract","m2Near","mFarPlusNear","mFarMinusNear"]);e&&j(z,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);f&&j(z,["pointLightNumber","pointLightColor",
-"pointLightPosition"]);c.uniform1i(z.uniforms.enableMap,0);c.uniform1i(z.uniforms.tMap,0);c.uniform1i(z.uniforms.enableCubeMap,0);c.uniform1i(z.uniforms.tCube,1);c.uniform1i(z.uniforms.mixEnvMap,0);c.uniform1i(z.uniforms.useRefract,0);o(z)})(a.directional,a.point);this.setSize=function(e,f){l.width=e;l.height=f;c.viewport(0,0,l.width,l.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(e,f){var k,n,g,h,w,s=[],L=[],u=[];h=[];w=[];c.uniform1i(e.uniforms.enableLighting,
-f.lights.length);k=0;for(n=f.lights.length;k<n;k++){g=f.lights[k];if(g instanceof THREE.AmbientLight)s.push(g);else if(g instanceof THREE.DirectionalLight)u.push(g);else g instanceof THREE.PointLight&&L.push(g)}k=g=h=w=0;for(n=s.length;k<n;k++){g+=s[k].color.r;h+=s[k].color.g;w+=s[k].color.b}c.uniform3f(e.uniforms.ambientLightColor,g,h,w);h=[];w=[];k=0;for(n=u.length;k<n;k++){g=u[k];h.push(g.color.r*g.intensity);h.push(g.color.g*g.intensity);h.push(g.color.b*g.intensity);w.push(g.position.x);w.push(g.position.y);
-w.push(g.position.z)}if(u.length){c.uniform1i(e.uniforms.directionalLightNumber,u.length);c.uniform3fv(e.uniforms.directionalLightDirection,w);c.uniform3fv(e.uniforms.directionalLightColor,h)}h=[];w=[];k=0;for(n=L.length;k<n;k++){g=L[k];h.push(g.color.r*g.intensity);h.push(g.color.g*g.intensity);h.push(g.color.b*g.intensity);w.push(g.position.x);w.push(g.position.y);w.push(g.position.z)}if(L.length){c.uniform1i(e.uniforms.pointLightNumber,L.length);c.uniform3fv(e.uniforms.pointLightPosition,w);c.uniform3fv(e.uniforms.pointLightColor,
-h)}};this.createBuffers=function(e,f){var k,n,g,h,w,s,L,u,T=[],P=[],t=[],H=[],p=[],A=0,y=e.geometry.geometryChunks[f],O;g=false;k=0;for(n=e.material.length;k<n;k++){meshMaterial=e.material[k];if(meshMaterial instanceof THREE.MeshFaceMaterial){w=0;for(O=y.material.length;w<O;w++)if(y.material[w]&&y.material[w].shading!=undefined&&y.material[w].shading==THREE.SmoothShading){g=true;break}}else if(meshMaterial&&meshMaterial.shading!=undefined&&meshMaterial.shading==THREE.SmoothShading){g=true;break}if(g)break}O=
-g;k=0;for(n=y.faces.length;k<n;k++){g=y.faces[k];h=e.geometry.faces[g];w=h.vertexNormals;faceNormal=h.normal;g=e.geometry.uvs[g];if(h instanceof THREE.Face3){s=e.geometry.vertices[h.a].position;L=e.geometry.vertices[h.b].position;u=e.geometry.vertices[h.c].position;t.push(s.x,s.y,s.z);t.push(L.x,L.y,L.z);t.push(u.x,u.y,u.z);if(w.length==3&&O)for(h=0;h<3;h++)H.push(w[h].x,w[h].y,w[h].z);else for(h=0;h<3;h++)H.push(faceNormal.x,faceNormal.y,faceNormal.z);if(g)for(h=0;h<3;h++)p.push(g[h].u,g[h].v);T.push(A,
-A+1,A+2);P.push(A,A+1);P.push(A,A+2);P.push(A+1,A+2);A+=3}else if(h instanceof THREE.Face4){s=e.geometry.vertices[h.a].position;L=e.geometry.vertices[h.b].position;u=e.geometry.vertices[h.c].position;h=e.geometry.vertices[h.d].position;t.push(s.x,s.y,s.z);t.push(L.x,L.y,L.z);t.push(u.x,u.y,u.z);t.push(h.x,h.y,h.z);if(w.length==4&&O)for(h=0;h<4;h++)H.push(w[h].x,w[h].y,w[h].z);else for(h=0;h<4;h++)H.push(faceNormal.x,faceNormal.y,faceNormal.z);if(g)for(h=0;h<4;h++)p.push(g[h].u,g[h].v);T.push(A,A+
-1,A+2);T.push(A,A+2,A+3);P.push(A,A+1);P.push(A,A+2);P.push(A,A+3);P.push(A+1,A+2);P.push(A+2,A+3);A+=4}}if(t.length){y.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,y.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(t),c.STATIC_DRAW);y.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,y.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(H),c.STATIC_DRAW);y.__webGLUVBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,y.__webGLUVBuffer);
-c.bufferData(c.ARRAY_BUFFER,new Float32Array(p),c.STATIC_DRAW);y.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,y.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(T),c.STATIC_DRAW);y.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,y.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(P),c.STATIC_DRAW);y.__webGLFaceCount=T.length;y.__webGLLineCount=P.length}};this.renderBuffer=function(e,f,k){var n,g,h,w,s,L,u,
-T,P,t;if(f instanceof THREE.MeshShaderMaterial){if(!f.program){f.program=b(f.fragment_shader,f.vertex_shader);u=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(t in f.uniforms)u.push(t);j(f.program,u);o(f.program)}t=f.program}else t=z;if(t!=G){c.useProgram(t);G=t}if(f instanceof THREE.MeshShaderMaterial){h=f.wireframe;w=f.wireframe_linewidth;u=t;T=f.uniforms;var H,p;for(g in T){H=T[g].type;P=T[g].value;p=u.uniforms[g];if(H=="i")c.uniform1i(p,
-P);else if(H=="f")c.uniform1f(p,P);else if(H=="t"){c.uniform1i(p,P);H=T[g].texture;if(H instanceof THREE.TextureCube)d(H,P);else H instanceof THREE.Texture&&i(H,P)}}this.loadCamera(t,e);this.loadMatrices(t)}else if(f instanceof THREE.MeshPhongMaterial||f instanceof THREE.MeshLambertMaterial||f instanceof THREE.MeshBasicMaterial){e=f.color;n=f.opacity;h=f.wireframe;w=f.wireframe_linewidth;s=f.map;L=f.env_map;u=f.combine==THREE.Mix;g=f.reflectivity;P=f.env_map&&f.env_map.mapping==THREE.RefractionMapping;
-T=f.refraction_ratio;c.uniform4f(t.uniforms.mColor,e.r*n,e.g*n,e.b*n,n);c.uniform1i(t.uniforms.mixEnvMap,u);c.uniform1f(t.uniforms.mReflectivity,g);c.uniform1i(t.uniforms.useRefract,P);c.uniform1f(t.uniforms.mRefractionRatio,T)}if(f instanceof THREE.MeshNormalMaterial){n=f.opacity;c.uniform1f(t.uniforms.mOpacity,n);c.uniform1i(t.uniforms.material,4)}else if(f instanceof THREE.MeshDepthMaterial){n=f.opacity;h=f.wireframe;w=f.wireframe_linewidth;c.uniform1f(t.uniforms.mOpacity,n);c.uniform1f(t.uniforms.m2Near,
-f.__2near);c.uniform1f(t.uniforms.mFarPlusNear,f.__farPlusNear);c.uniform1f(t.uniforms.mFarMinusNear,f.__farMinusNear);c.uniform1i(t.uniforms.material,3)}else if(f instanceof THREE.MeshPhongMaterial){e=f.ambient;g=f.specular;f=f.shininess;c.uniform4f(t.uniforms.mAmbient,e.r,e.g,e.b,n);c.uniform4f(t.uniforms.mSpecular,g.r,g.g,g.b,n);c.uniform1f(t.uniforms.mShininess,f);c.uniform1i(t.uniforms.material,2)}else if(f instanceof THREE.MeshLambertMaterial)c.uniform1i(t.uniforms.material,1);else if(f instanceof
-THREE.MeshBasicMaterial)c.uniform1i(t.uniforms.material,0);else if(f instanceof THREE.MeshCubeMaterial){c.uniform1i(t.uniforms.material,5);L=f.env_map}if(s){i(s,0);c.uniform1i(t.uniforms.tMap,0);c.uniform1i(t.uniforms.enableMap,1)}else c.uniform1i(t.uniforms.enableMap,0);if(L){d(L,1);c.uniform1i(t.uniforms.tCube,1);c.uniform1i(t.uniforms.enableCubeMap,1)}else c.uniform1i(t.uniforms.enableCubeMap,0);c.bindBuffer(c.ARRAY_BUFFER,k.__webGLVertexBuffer);c.vertexAttribPointer(t.position,3,c.FLOAT,false,
-0,0);c.bindBuffer(c.ARRAY_BUFFER,k.__webGLNormalBuffer);c.vertexAttribPointer(t.normal,3,c.FLOAT,false,0,0);if(s){c.bindBuffer(c.ARRAY_BUFFER,k.__webGLUVBuffer);c.enableVertexAttribArray(t.uv);c.vertexAttribPointer(t.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(t.uv);if(h){c.lineWidth(w);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,k.__webGLLineBuffer);c.drawElements(c.LINES,k.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,k.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,
-k.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(e,f,k,n,g){var h,w,s,L,u;s=0;for(L=f.material.length;s<L;s++){h=f.material[s];if(h instanceof THREE.MeshFaceMaterial){h=0;for(w=k.material.length;h<w;h++)if((u=k.material[h])&&u.blending==n&&u.opacity<1==g){this.setBlending(u.blending);this.renderBuffer(e,u,k)}}else if((u=h)&&u.blending==n&&u.opacity<1==g){this.setBlending(u.blending);this.renderBuffer(e,u,k)}}};this.render=function(e,f){var k,n,g,h;this.initWebGLObjects(e);this.autoClear&&
-this.clear();f.autoUpdateMatrix&&f.updateMatrix();this.loadCamera(z,f);this.setupLights(z,e);k=0;for(n=e.__webGLObjects.length;k<n;k++){g=e.__webGLObjects[k];h=g.object;g=g.buffer;if(h.visible){this.setupMatrices(h,f);this.loadMatrices(z);this.renderPass(f,h,g,THREE.NormalBlending,false)}}k=0;for(n=e.__webGLObjects.length;k<n;k++){g=e.__webGLObjects[k];h=g.object;g=g.buffer;if(h.visible){this.setupMatrices(h,f);this.loadMatrices(z);this.renderPass(f,h,g,THREE.AdditiveBlending,false);this.renderPass(f,
-h,g,THREE.SubtractiveBlending,false);this.renderPass(f,h,g,THREE.AdditiveBlending,true);this.renderPass(f,h,g,THREE.SubtractiveBlending,true);this.renderPass(f,h,g,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(e){var f,k,n,g,h,w;if(!e.__webGLObjects){e.__webGLObjects=[];e.__webGLObjectsMap={}}f=0;for(k=e.objects.length;f<k;f++){n=e.objects[f];if(e.__webGLObjectsMap[n.id]==undefined)e.__webGLObjectsMap[n.id]={};w=e.__webGLObjectsMap[n.id];if(n instanceof THREE.Mesh)for(h in n.geometry.geometryChunks){g=
-n.geometry.geometryChunks[h];g.__webGLVertexBuffer||this.createBuffers(n,h);if(w[h]==undefined){g={buffer:g,object:n};e.__webGLObjects.push(g);w[h]=1}}}};this.removeObject=function(e,f){var k,n;for(k=e.__webGLObjects.length-1;k>=0;k--){n=e.__webGLObjects[k].object;f==n&&e.__webGLObjects.splice(k,1)}};this.setupMatrices=function(e,f){e.autoUpdateMatrix&&e.updateMatrix();x.multiply(f.matrix,e.matrix);N.set(f.matrix.flatten());J.set(x.flatten());M.set(f.projectionMatrix.flatten());F=THREE.Matrix4.makeInvert3x3(x).transpose();
-r.set(F.m);R.set(e.matrix.flatten())};this.loadMatrices=function(e){c.uniformMatrix4fv(e.uniforms.viewMatrix,false,N);c.uniformMatrix4fv(e.uniforms.modelViewMatrix,false,J);c.uniformMatrix4fv(e.uniforms.projectionMatrix,false,M);c.uniformMatrix3fv(e.uniforms.normalMatrix,false,r);c.uniformMatrix4fv(e.uniforms.objectMatrix,false,R)};this.loadCamera=function(e,f){c.uniform3f(e.uniforms.cameraPosition,f.position.x,f.position.y,f.position.z)};this.setBlending=function(e){switch(e){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);
-c.blendFunc(c.ONE,c.ONE);break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(e,f){if(e){!f||f=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(e=="back")c.cullFace(c.BACK);else e=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)}};
+e=b(n,e);c.useProgram(e);j(e,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract","m2Near","mFarPlusNear","mFarMinusNear"]);f&&j(e,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);k&&j(e,["pointLightNumber","pointLightColor",
+"pointLightPosition"]);c.uniform1i(e.uniforms.enableMap,0);c.uniform1i(e.uniforms.tMap,0);c.uniform1i(e.uniforms.enableCubeMap,0);c.uniform1i(e.uniforms.tCube,1);c.uniform1i(e.uniforms.mixEnvMap,0);c.uniform1i(e.uniforms.useRefract,0);o(e,["position","normal","uv"]);return e}(a.directional,a.point);this.setSize=function(f,k){l.width=f;l.height=k;c.viewport(0,0,l.width,l.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(f,k){var e,n,h,g,q,t=[],
+K=[],A=[];g=[];q=[];c.uniform1i(f.uniforms.enableLighting,k.length);e=0;for(n=k.length;e<n;e++){h=k[e];if(h instanceof THREE.AmbientLight)t.push(h);else if(h instanceof THREE.DirectionalLight)A.push(h);else h instanceof THREE.PointLight&&K.push(h)}e=h=g=q=0;for(n=t.length;e<n;e++){h+=t[e].color.r;g+=t[e].color.g;q+=t[e].color.b}c.uniform3f(f.uniforms.ambientLightColor,h,g,q);g=[];q=[];e=0;for(n=A.length;e<n;e++){h=A[e];g.push(h.color.r*h.intensity);g.push(h.color.g*h.intensity);g.push(h.color.b*h.intensity);
+q.push(h.position.x);q.push(h.position.y);q.push(h.position.z)}if(A.length){c.uniform1i(f.uniforms.directionalLightNumber,A.length);c.uniform3fv(f.uniforms.directionalLightDirection,q);c.uniform3fv(f.uniforms.directionalLightColor,g)}g=[];q=[];e=0;for(n=K.length;e<n;e++){h=K[e];g.push(h.color.r*h.intensity);g.push(h.color.g*h.intensity);g.push(h.color.b*h.intensity);q.push(h.position.x);q.push(h.position.y);q.push(h.position.z)}if(K.length){c.uniform1i(f.uniforms.pointLightNumber,K.length);c.uniform3fv(f.uniforms.pointLightPosition,
+q);c.uniform3fv(f.uniforms.pointLightColor,g)}};this.createBuffers=function(f,k){var e,n,h,g,q,t,K,A,H=[],P=[],u=[],N=[],s=[],y=0,x=f.geometry.geometryChunks[k],Q;h=false;e=0;for(n=f.material.length;e<n;e++){meshMaterial=f.material[e];if(meshMaterial instanceof THREE.MeshFaceMaterial){q=0;for(Q=x.material.length;q<Q;q++)if(x.material[q]&&x.material[q].shading!=undefined&&x.material[q].shading==THREE.SmoothShading){h=true;break}}else if(meshMaterial&&meshMaterial.shading!=undefined&&meshMaterial.shading==
+THREE.SmoothShading){h=true;break}if(h)break}Q=h;e=0;for(n=x.faces.length;e<n;e++){h=x.faces[e];g=f.geometry.faces[h];q=g.vertexNormals;faceNormal=g.normal;h=f.geometry.uvs[h];if(g instanceof THREE.Face3){t=f.geometry.vertices[g.a].position;K=f.geometry.vertices[g.b].position;A=f.geometry.vertices[g.c].position;u.push(t.x,t.y,t.z);u.push(K.x,K.y,K.z);u.push(A.x,A.y,A.z);if(q.length==3&&Q)for(g=0;g<3;g++)N.push(q[g].x,q[g].y,q[g].z);else for(g=0;g<3;g++)N.push(faceNormal.x,faceNormal.y,faceNormal.z);
+if(h)for(g=0;g<3;g++)s.push(h[g].u,h[g].v);H.push(y,y+1,y+2);P.push(y,y+1);P.push(y,y+2);P.push(y+1,y+2);y+=3}else if(g instanceof THREE.Face4){t=f.geometry.vertices[g.a].position;K=f.geometry.vertices[g.b].position;A=f.geometry.vertices[g.c].position;g=f.geometry.vertices[g.d].position;u.push(t.x,t.y,t.z);u.push(K.x,K.y,K.z);u.push(A.x,A.y,A.z);u.push(g.x,g.y,g.z);if(q.length==4&&Q)for(g=0;g<4;g++)N.push(q[g].x,q[g].y,q[g].z);else for(g=0;g<4;g++)N.push(faceNormal.x,faceNormal.y,faceNormal.z);if(h)for(g=
+0;g<4;g++)s.push(h[g].u,h[g].v);H.push(y,y+1,y+2);H.push(y,y+2,y+3);P.push(y,y+1);P.push(y,y+2);P.push(y,y+3);P.push(y+1,y+2);P.push(y+2,y+3);y+=4}}if(u.length){x.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,x.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(u),c.STATIC_DRAW);x.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,x.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(N),c.STATIC_DRAW);if(s.length>0){x.__webGLUVBuffer=c.createBuffer();
+c.bindBuffer(c.ARRAY_BUFFER,x.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(s),c.STATIC_DRAW)}x.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,x.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(H),c.STATIC_DRAW);x.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,x.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(P),c.STATIC_DRAW);x.__webGLFaceCount=H.length;x.__webGLLineCount=P.length}};this.renderBuffer=
+function(f,k,e,n){var h,g,q,t,K,A,H,P,u;if(e instanceof THREE.MeshShaderMaterial){if(!e.program){e.program=b(e.fragment_shader,e.vertex_shader);H=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(u in e.uniforms)H.push(u);j(e.program,H);o(e.program,["position","normal","uv"])}u=e.program}else u=G;if(u!=E){c.useProgram(u);E=u}u==G&&this.setupLights(u,k);this.loadCamera(u,f);this.loadMatrices(u);if(e instanceof THREE.MeshShaderMaterial){q=e.wireframe;
+t=e.wireframe_linewidth;f=u;k=e.uniforms;var N;for(h in k){P=k[h].type;H=k[h].value;N=f.uniforms[h];if(P=="i")c.uniform1i(N,H);else if(P=="f")c.uniform1f(N,H);else if(P=="t"){c.uniform1i(N,H);P=k[h].texture;if(P instanceof THREE.TextureCube)d(P,H);else P instanceof THREE.Texture&&i(P,H)}}}if(e instanceof THREE.MeshPhongMaterial||e instanceof THREE.MeshLambertMaterial||e instanceof THREE.MeshBasicMaterial){h=e.color;g=e.opacity;q=e.wireframe;t=e.wireframe_linewidth;K=e.map;A=e.env_map;k=e.combine==
+THREE.Mix;f=e.reflectivity;P=e.env_map&&e.env_map.mapping==THREE.RefractionMapping;H=e.refraction_ratio;c.uniform4f(u.uniforms.mColor,h.r*g,h.g*g,h.b*g,g);c.uniform1i(u.uniforms.mixEnvMap,k);c.uniform1f(u.uniforms.mReflectivity,f);c.uniform1i(u.uniforms.useRefract,P);c.uniform1f(u.uniforms.mRefractionRatio,H)}if(e instanceof THREE.MeshNormalMaterial){g=e.opacity;c.uniform1f(u.uniforms.mOpacity,g);c.uniform1i(u.uniforms.material,4)}else if(e instanceof THREE.MeshDepthMaterial){g=e.opacity;q=e.wireframe;
+t=e.wireframe_linewidth;c.uniform1f(u.uniforms.mOpacity,g);c.uniform1f(u.uniforms.m2Near,e.__2near);c.uniform1f(u.uniforms.mFarPlusNear,e.__farPlusNear);c.uniform1f(u.uniforms.mFarMinusNear,e.__farMinusNear);c.uniform1i(u.uniforms.material,3)}else if(e instanceof THREE.MeshPhongMaterial){h=e.ambient;f=e.specular;e=e.shininess;c.uniform4f(u.uniforms.mAmbient,h.r,h.g,h.b,g);c.uniform4f(u.uniforms.mSpecular,f.r,f.g,f.b,g);c.uniform1f(u.uniforms.mShininess,e);c.uniform1i(u.uniforms.material,2)}else if(e instanceof
+THREE.MeshLambertMaterial)c.uniform1i(u.uniforms.material,1);else if(e instanceof THREE.MeshBasicMaterial)c.uniform1i(u.uniforms.material,0);else if(e instanceof THREE.MeshCubeMaterial){c.uniform1i(u.uniforms.material,5);A=e.env_map}if(K){i(K,0);c.uniform1i(u.uniforms.tMap,0);c.uniform1i(u.uniforms.enableMap,1)}else c.uniform1i(u.uniforms.enableMap,0);if(A){d(A,1);c.uniform1i(u.uniforms.tCube,1);c.uniform1i(u.uniforms.enableCubeMap,1)}else c.uniform1i(u.uniforms.enableCubeMap,0);g=u.attributes;c.bindBuffer(c.ARRAY_BUFFER,
+n.__webGLVertexBuffer);c.vertexAttribPointer(g.position,3,c.FLOAT,false,0,0);c.bindBuffer(c.ARRAY_BUFFER,n.__webGLNormalBuffer);c.vertexAttribPointer(g.normal,3,c.FLOAT,false,0,0);if(g.uv>=0)if(n.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,n.__webGLUVBuffer);c.enableVertexAttribArray(g.uv);c.vertexAttribPointer(g.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(g.uv);if(q){c.lineWidth(t);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,n.__webGLLineBuffer);c.drawElements(c.LINES,n.__webGLLineCount,c.UNSIGNED_SHORT,
+0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,n.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,n.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(f,k,e,n,h,g){var q,t,K,A,H;K=0;for(A=e.material.length;K<A;K++){q=e.material[K];if(q instanceof THREE.MeshFaceMaterial){q=0;for(t=n.material.length;q<t;q++)if((H=n.material[q])&&H.blending==h&&H.opacity<1==g){this.setBlending(H.blending);this.renderBuffer(f,k,H,n)}}else if((H=q)&&H.blending==h&&H.opacity<1==g){this.setBlending(H.blending);this.renderBuffer(f,
+k,H,n)}}};this.render=function(f,k){var e,n,h,g,q=f.lights;this.initWebGLObjects(f);this.autoClear&&this.clear();k.autoUpdateMatrix&&k.updateMatrix();e=0;for(n=f.__webGLObjects.length;e<n;e++){h=f.__webGLObjects[e];g=h.object;h=h.buffer;if(g.visible){this.setupMatrices(g,k);this.renderPass(k,q,g,h,THREE.NormalBlending,false)}}e=0;for(n=f.__webGLObjects.length;e<n;e++){h=f.__webGLObjects[e];g=h.object;h=h.buffer;if(g.visible){this.setupMatrices(g,k);this.renderPass(k,q,g,h,THREE.AdditiveBlending,false);
+this.renderPass(k,q,g,h,THREE.SubtractiveBlending,false);this.renderPass(k,q,g,h,THREE.AdditiveBlending,true);this.renderPass(k,q,g,h,THREE.SubtractiveBlending,true);this.renderPass(k,q,g,h,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(f){var k,e,n,h,g,q;if(!f.__webGLObjects){f.__webGLObjects=[];f.__webGLObjectsMap={}}k=0;for(e=f.objects.length;k<e;k++){n=f.objects[k];if(f.__webGLObjectsMap[n.id]==undefined)f.__webGLObjectsMap[n.id]={};q=f.__webGLObjectsMap[n.id];if(n instanceof THREE.Mesh)for(g in n.geometry.geometryChunks){h=
+n.geometry.geometryChunks[g];h.__webGLVertexBuffer||this.createBuffers(n,g);if(q[g]==undefined){h={buffer:h,object:n};f.__webGLObjects.push(h);q[g]=1}}}};this.removeObject=function(f,k){var e,n;for(e=f.__webGLObjects.length-1;e>=0;e--){n=f.__webGLObjects[e].object;k==n&&f.__webGLObjects.splice(e,1)}};this.setupMatrices=function(f,k){f.autoUpdateMatrix&&f.updateMatrix();w.multiply(k.matrix,f.matrix);O.set(k.matrix.flatten());J.set(w.flatten());M.set(k.projectionMatrix.flatten());F=THREE.Matrix4.makeInvert3x3(w).transpose();
+r.set(F.m);S.set(f.matrix.flatten())};this.loadMatrices=function(f){c.uniformMatrix4fv(f.uniforms.viewMatrix,false,O);c.uniformMatrix4fv(f.uniforms.modelViewMatrix,false,J);c.uniformMatrix4fv(f.uniforms.projectionMatrix,false,M);c.uniformMatrix3fv(f.uniforms.normalMatrix,false,r);c.uniformMatrix4fv(f.uniforms.objectMatrix,false,S)};this.loadCamera=function(f,k){c.uniform3f(f.uniforms.cameraPosition,k.position.x,k.position.y,k.position.z)};this.setBlending=function(f){switch(f){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);
+c.blendFunc(c.ONE,c.ONE);break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(f,k){if(f){!k||k=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(f=="back")c.cullFace(c.BACK);else f=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)}};
 THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[];this.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null};
 THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[];this.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null};
 THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=null};
 THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=null};

+ 103 - 102
build/ThreeDebug.js

@@ -12,42 +12,43 @@ THREE.Vector4=function(a,b,d,i){this.x=a||0;this.y=b||0;this.z=d||0;this.w=i||1}
 THREE.Vector4.prototype={set:function(a,b,d,i){this.x=a;this.y=b;this.z=d;this.w=i;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w||1;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;
 THREE.Vector4.prototype={set:function(a,b,d,i){this.x=a;this.y=b;this.z=d;this.w=i;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w||1;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;
 return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=a;this.w/=a;return this},lerpSelf:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},toString:function(){return"THREE.Vector4 ("+this.x+", "+this.y+", "+this.z+", "+this.w+")"}};
 return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=a;this.w/=a;return this},lerpSelf:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},toString:function(){return"THREE.Vector4 ("+this.x+", "+this.y+", "+this.z+", "+this.w+")"}};
 THREE.Ray=function(a,b){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3};
 THREE.Ray=function(a,b){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3};
-THREE.Ray.prototype={intersectScene:function(a){var b,d,i=a.objects,j=[];a=0;for(b=i.length;a<b;a++){d=i[a];if(d instanceof THREE.Mesh)j=j.concat(this.intersectObject(d))}j.sort(function(p,m){return p.distance-m.distance});return j},intersectObject:function(a){function b(M,n,S,B){B=B.clone().subSelf(n);S=S.clone().subSelf(n);var e=M.clone().subSelf(n);M=B.dot(B);n=B.dot(S);B=B.dot(e);var f=S.dot(S);S=S.dot(e);e=1/(M*f-n*n);f=(f*B-n*S)*e;M=(M*S-n*B)*e;return f>0&&M>0&&f+M<1}var d,i,j,p,m,r,l,c,z,G,
-x,F=a.geometry,O=F.vertices,J=[];d=0;for(i=F.faces.length;d<i;d++){j=F.faces[d];G=this.origin.clone();x=this.direction.clone();p=a.matrix.transformVector3(O[j.a].position.clone());m=a.matrix.transformVector3(O[j.b].position.clone());r=a.matrix.transformVector3(O[j.c].position.clone());l=j instanceof THREE.Face4?a.matrix.transformVector3(O[j.d].position.clone()):null;c=a.rotationMatrix.transformVector3(j.normal.clone());z=x.dot(c);if(z<0){c=c.dot((new THREE.Vector3).sub(p,G))/z;G=G.addSelf(x.multiplyScalar(c));
-if(j instanceof THREE.Face3){if(b(G,p,m,r)){j={distance:this.origin.distanceTo(G),point:G,face:j,object:a};J.push(j)}}else if(j instanceof THREE.Face4)if(b(G,p,m,l)||b(G,m,r,l)){j={distance:this.origin.distanceTo(G),point:G,face:j,object:a};J.push(j)}}}return J}};
-THREE.Rectangle=function(){function a(){p=i-b;m=j-d}var b,d,i,j,p,m,r=true;this.getX=function(){return b};this.getY=function(){return d};this.getWidth=function(){return p};this.getHeight=function(){return m};this.getLeft=function(){return b};this.getTop=function(){return d};this.getRight=function(){return i};this.getBottom=function(){return j};this.set=function(l,c,z,G){r=false;b=l;d=c;i=z;j=G;a()};this.addPoint=function(l,c){if(r){r=false;b=l;d=c;i=l;j=c}else{b=Math.min(b,l);d=Math.min(d,c);i=Math.max(i,
-l);j=Math.max(j,c)}a()};this.addRectangle=function(l){if(r){r=false;b=l.getLeft();d=l.getTop();i=l.getRight();j=l.getBottom()}else{b=Math.min(b,l.getLeft());d=Math.min(d,l.getTop());i=Math.max(i,l.getRight());j=Math.max(j,l.getBottom())}a()};this.inflate=function(l){b-=l;d-=l;i+=l;j+=l;a()};this.minSelf=function(l){b=Math.max(b,l.getLeft());d=Math.max(d,l.getTop());i=Math.min(i,l.getRight());j=Math.min(j,l.getBottom());a()};this.instersects=function(l){return Math.min(i,l.getRight())-Math.max(b,l.getLeft())>=
-0&&Math.min(j,l.getBottom())-Math.max(d,l.getTop())>=0};this.empty=function(){r=true;j=i=d=b=0;a()};this.isEmpty=function(){return r};this.toString=function(){return"THREE.Rectangle ( left: "+b+", right: "+i+", top: "+d+", bottom: "+j+", width: "+p+", height: "+m+" )"}};THREE.Matrix3=function(){this.m=[]};THREE.Matrix3.prototype={transpose:function(){var a;a=this.m[1];this.m[1]=this.m[3];this.m[3]=a;a=this.m[2];this.m[2]=this.m[6];this.m[6]=a;a=this.m[5];this.m[5]=this.m[7];this.m[7]=a;return this}};
+THREE.Ray.prototype={intersectScene:function(a){var b,d,i=a.objects,j=[];a=0;for(b=i.length;a<b;a++){d=i[a];if(d instanceof THREE.Mesh)j=j.concat(this.intersectObject(d))}j.sort(function(p,m){return p.distance-m.distance});return j},intersectObject:function(a){function b(M,o,T,z){z=z.clone().subSelf(o);T=T.clone().subSelf(o);var f=M.clone().subSelf(o);M=z.dot(z);o=z.dot(T);z=z.dot(f);var k=T.dot(T);T=T.dot(f);f=1/(M*k-o*o);k=(k*z-o*T)*f;M=(M*T-o*z)*f;return k>0&&M>0&&k+M<1}var d,i,j,p,m,q,l,c,E,G,
+w,F=a.geometry,P=F.vertices,J=[];d=0;for(i=F.faces.length;d<i;d++){j=F.faces[d];G=this.origin.clone();w=this.direction.clone();p=a.matrix.multiplyVector3(P[j.a].position.clone());m=a.matrix.multiplyVector3(P[j.b].position.clone());q=a.matrix.multiplyVector3(P[j.c].position.clone());l=j instanceof THREE.Face4?a.matrix.multiplyVector3(P[j.d].position.clone()):null;c=a.rotationMatrix.multiplyVector3(j.normal.clone());E=w.dot(c);if(E<0){c=c.dot((new THREE.Vector3).sub(p,G))/E;G=G.addSelf(w.multiplyScalar(c));
+if(j instanceof THREE.Face3){if(b(G,p,m,q)){j={distance:this.origin.distanceTo(G),point:G,face:j,object:a};J.push(j)}}else if(j instanceof THREE.Face4)if(b(G,p,m,l)||b(G,m,q,l)){j={distance:this.origin.distanceTo(G),point:G,face:j,object:a};J.push(j)}}}return J}};
+THREE.Rectangle=function(){function a(){p=i-b;m=j-d}var b,d,i,j,p,m,q=true;this.getX=function(){return b};this.getY=function(){return d};this.getWidth=function(){return p};this.getHeight=function(){return m};this.getLeft=function(){return b};this.getTop=function(){return d};this.getRight=function(){return i};this.getBottom=function(){return j};this.set=function(l,c,E,G){q=false;b=l;d=c;i=E;j=G;a()};this.addPoint=function(l,c){if(q){q=false;b=l;d=c;i=l;j=c}else{b=Math.min(b,l);d=Math.min(d,c);i=Math.max(i,
+l);j=Math.max(j,c)}a()};this.addRectangle=function(l){if(q){q=false;b=l.getLeft();d=l.getTop();i=l.getRight();j=l.getBottom()}else{b=Math.min(b,l.getLeft());d=Math.min(d,l.getTop());i=Math.max(i,l.getRight());j=Math.max(j,l.getBottom())}a()};this.inflate=function(l){b-=l;d-=l;i+=l;j+=l;a()};this.minSelf=function(l){b=Math.max(b,l.getLeft());d=Math.max(d,l.getTop());i=Math.min(i,l.getRight());j=Math.min(j,l.getBottom());a()};this.instersects=function(l){return Math.min(i,l.getRight())-Math.max(b,l.getLeft())>=
+0&&Math.min(j,l.getBottom())-Math.max(d,l.getTop())>=0};this.empty=function(){q=true;j=i=d=b=0;a()};this.isEmpty=function(){return q};this.toString=function(){return"THREE.Rectangle ( left: "+b+", right: "+i+", top: "+d+", bottom: "+j+", width: "+p+", height: "+m+" )"}};THREE.Matrix3=function(){this.m=[]};THREE.Matrix3.prototype={transpose:function(){var a;a=this.m[1];this.m[1]=this.m[3];this.m[3]=a;a=this.m[2];this.m[2]=this.m[6];this.m[6]=a;a=this.m[5];this.m[5]=this.m[7];this.m[7]=a;return this}};
 THREE.Matrix4=function(){};
 THREE.Matrix4=function(){};
 THREE.Matrix4.prototype={n11:1,n12:0,n13:0,n14:0,n21:0,n22:1,n23:0,n24:0,n31:0,n32:0,n33:1,n34:0,n41:0,n42:0,n43:0,n44:1,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},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=
 THREE.Matrix4.prototype={n11:1,n12:0,n13:0,n14:0,n21:0,n22:1,n23:0,n24:0,n31:0,n32:0,n33:1,n34:0,n41:0,n42:0,n43:0,n44:1,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},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},lookAt:function(a,b,d){var i=new THREE.Vector3,j=new THREE.Vector3,p=new THREE.Vector3;p.sub(a,b).normalize();i.cross(d,p).normalize();j.cross(p,i).normalize();this.n11=i.x;this.n12=i.y;this.n13=i.z;this.n14=-i.dot(a);this.n21=j.x;this.n22=j.y;this.n23=j.z;this.n24=-j.dot(a);this.n31=p.x;this.n32=p.y;this.n33=p.z;this.n34=-p.dot(a);this.n43=this.n42=this.n41=0;this.n44=1},transformVector3:function(a){var b=a.x,d=a.y,i=a.z,j=1/(this.n41*b+this.n42*
-d+this.n43*i+this.n44);a.x=(this.n11*b+this.n12*d+this.n13*i+this.n14)*j;a.y=(this.n21*b+this.n22*d+this.n23*i+this.n24)*j;a.z=(this.n31*b+this.n32*d+this.n33*i+this.n34)*j;return a},transformVector4:function(a){var b=a.x,d=a.y,i=a.z,j=a.w;a.x=this.n11*b+this.n12*d+this.n13*i+this.n14*j;a.y=this.n21*b+this.n22*d+this.n23*i+this.n24*j;a.z=this.n31*b+this.n32*d+this.n33*i+this.n34*j;a.w=this.n41*b+this.n42*d+this.n43*i+this.n44*j;return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*
-a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var d=a.n11,i=a.n12,j=a.n13,p=a.n14,m=a.n21,r=a.n22,l=a.n23,c=a.n24,z=a.n31,G=a.n32,x=a.n33,F=a.n34,O=a.n41,J=a.n42,M=a.n43,n=a.n44,S=b.n11,B=b.n12,e=b.n13,f=b.n14,k=b.n21,o=b.n22,g=b.n23,h=b.n24,w=b.n31,s=b.n32,L=b.n33,u=b.n34,T=b.n41,Q=b.n42,t=b.n43,
-H=b.n44;this.n11=d*S+i*k+j*w+p*T;this.n12=d*B+i*o+j*s+p*Q;this.n13=d*e+i*g+j*L+p*t;this.n14=d*f+i*h+j*u+p*H;this.n21=m*S+r*k+l*w+c*T;this.n22=m*B+r*o+l*s+c*Q;this.n23=m*e+r*g+l*L+c*t;this.n24=m*f+r*h+l*u+c*H;this.n31=z*S+G*k+x*w+F*T;this.n32=z*B+G*o+x*s+F*Q;this.n33=z*e+G*g+x*L+F*t;this.n34=z*f+G*h+x*u+F*H;this.n41=O*S+J*k+M*w+n*T;this.n42=O*B+J*o+M*s+n*Q;this.n43=O*e+J*g+M*L+n*t;this.n44=O*f+J*h+M*u+n*H},multiplySelf:function(a){var b=this.n11,d=this.n12,i=this.n13,j=this.n14,p=this.n21,m=this.n22,
-r=this.n23,l=this.n24,c=this.n31,z=this.n32,G=this.n33,x=this.n34,F=this.n41,O=this.n42,J=this.n43,M=this.n44;this.n11=b*a.n11+d*a.n21+i*a.n31+j*a.n41;this.n12=b*a.n12+d*a.n22+i*a.n32+j*a.n42;this.n13=b*a.n13+d*a.n23+i*a.n33+j*a.n43;this.n14=b*a.n14+d*a.n24+i*a.n34+j*a.n44;this.n21=p*a.n11+m*a.n21+r*a.n31+l*a.n41;this.n22=p*a.n12+m*a.n22+r*a.n32+l*a.n42;this.n23=p*a.n13+m*a.n23+r*a.n33+l*a.n43;this.n24=p*a.n14+m*a.n24+r*a.n34+l*a.n44;this.n31=c*a.n11+z*a.n21+G*a.n31+x*a.n41;this.n32=c*a.n12+z*a.n22+
-G*a.n32+x*a.n42;this.n33=c*a.n13+z*a.n23+G*a.n33+x*a.n43;this.n34=c*a.n14+z*a.n24+G*a.n34+x*a.n44;this.n41=F*a.n11+O*a.n21+J*a.n31+M*a.n41;this.n42=F*a.n12+O*a.n22+J*a.n32+M*a.n42;this.n43=F*a.n13+O*a.n23+J*a.n33+M*a.n43;this.n44=F*a.n14+O*a.n24+J*a.n34+M*a.n44},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},determinant:function(){return this.n14*
+a.n41;this.n42=a.n42;this.n43=a.n43;this.n44=a.n44},lookAt:function(a,b,d){var i=new THREE.Vector3,j=new THREE.Vector3,p=new THREE.Vector3;p.sub(a,b).normalize();i.cross(d,p).normalize();j.cross(p,i).normalize();this.n11=i.x;this.n12=i.y;this.n13=i.z;this.n14=-i.dot(a);this.n21=j.x;this.n22=j.y;this.n23=j.z;this.n24=-j.dot(a);this.n31=p.x;this.n32=p.y;this.n33=p.z;this.n34=-p.dot(a);this.n43=this.n42=this.n41=0;this.n44=1},multiplyVector3:function(a){var b=a.x,d=a.y,i=a.z,j=1/(this.n41*b+this.n42*
+d+this.n43*i+this.n44);a.x=(this.n11*b+this.n12*d+this.n13*i+this.n14)*j;a.y=(this.n21*b+this.n22*d+this.n23*i+this.n24)*j;a.z=(this.n31*b+this.n32*d+this.n33*i+this.n34)*j;return a},multiplyVector4:function(a){var b=a.x,d=a.y,i=a.z,j=a.w;a.x=this.n11*b+this.n12*d+this.n13*i+this.n14*j;a.y=this.n21*b+this.n22*d+this.n23*i+this.n24*j;a.z=this.n31*b+this.n32*d+this.n33*i+this.n34*j;a.w=this.n41*b+this.n42*d+this.n43*i+this.n44*j;return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*
+a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var d=a.n11,i=a.n12,j=a.n13,p=a.n14,m=a.n21,q=a.n22,l=a.n23,c=a.n24,E=a.n31,G=a.n32,w=a.n33,F=a.n34,P=a.n41,J=a.n42,M=a.n43,o=a.n44,T=b.n11,z=b.n12,f=b.n13,k=b.n14,e=b.n21,n=b.n22,h=b.n23,g=b.n24,r=b.n31,t=b.n32,K=b.n33,A=b.n34,H=b.n41,Q=b.n42,u=b.n43,
+O=b.n44;this.n11=d*T+i*e+j*r+p*H;this.n12=d*z+i*n+j*t+p*Q;this.n13=d*f+i*h+j*K+p*u;this.n14=d*k+i*g+j*A+p*O;this.n21=m*T+q*e+l*r+c*H;this.n22=m*z+q*n+l*t+c*Q;this.n23=m*f+q*h+l*K+c*u;this.n24=m*k+q*g+l*A+c*O;this.n31=E*T+G*e+w*r+F*H;this.n32=E*z+G*n+w*t+F*Q;this.n33=E*f+G*h+w*K+F*u;this.n34=E*k+G*g+w*A+F*O;this.n41=P*T+J*e+M*r+o*H;this.n42=P*z+J*n+M*t+o*Q;this.n43=P*f+J*h+M*K+o*u;this.n44=P*k+J*g+M*A+o*O},multiplySelf:function(a){var b=this.n11,d=this.n12,i=this.n13,j=this.n14,p=this.n21,m=this.n22,
+q=this.n23,l=this.n24,c=this.n31,E=this.n32,G=this.n33,w=this.n34,F=this.n41,P=this.n42,J=this.n43,M=this.n44;this.n11=b*a.n11+d*a.n21+i*a.n31+j*a.n41;this.n12=b*a.n12+d*a.n22+i*a.n32+j*a.n42;this.n13=b*a.n13+d*a.n23+i*a.n33+j*a.n43;this.n14=b*a.n14+d*a.n24+i*a.n34+j*a.n44;this.n21=p*a.n11+m*a.n21+q*a.n31+l*a.n41;this.n22=p*a.n12+m*a.n22+q*a.n32+l*a.n42;this.n23=p*a.n13+m*a.n23+q*a.n33+l*a.n43;this.n24=p*a.n14+m*a.n24+q*a.n34+l*a.n44;this.n31=c*a.n11+E*a.n21+G*a.n31+w*a.n41;this.n32=c*a.n12+E*a.n22+
+G*a.n32+w*a.n42;this.n33=c*a.n13+E*a.n23+G*a.n33+w*a.n43;this.n34=c*a.n14+E*a.n24+G*a.n34+w*a.n44;this.n41=F*a.n11+P*a.n21+J*a.n31+M*a.n41;this.n42=F*a.n12+P*a.n22+J*a.n32+M*a.n42;this.n43=F*a.n13+P*a.n23+J*a.n33+M*a.n43;this.n44=F*a.n14+P*a.n24+J*a.n34+M*a.n44},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},determinant:function(){return this.n14*
 this.n23*this.n32*this.n41-this.n13*this.n24*this.n32*this.n41-this.n14*this.n22*this.n33*this.n41+this.n12*this.n24*this.n33*this.n41+this.n13*this.n22*this.n34*this.n41-this.n12*this.n23*this.n34*this.n41-this.n14*this.n23*this.n31*this.n42+this.n13*this.n24*this.n31*this.n42+this.n14*this.n21*this.n33*this.n42-this.n11*this.n24*this.n33*this.n42-this.n13*this.n21*this.n34*this.n42+this.n11*this.n23*this.n34*this.n42+this.n14*this.n22*this.n31*this.n43-this.n12*this.n24*this.n31*this.n43-this.n14*
 this.n23*this.n32*this.n41-this.n13*this.n24*this.n32*this.n41-this.n14*this.n22*this.n33*this.n41+this.n12*this.n24*this.n33*this.n41+this.n13*this.n22*this.n34*this.n41-this.n12*this.n23*this.n34*this.n41-this.n14*this.n23*this.n31*this.n42+this.n13*this.n24*this.n31*this.n42+this.n14*this.n21*this.n33*this.n42-this.n11*this.n24*this.n33*this.n42-this.n13*this.n21*this.n34*this.n42+this.n11*this.n23*this.n34*this.n42+this.n14*this.n22*this.n31*this.n43-this.n12*this.n24*this.n31*this.n43-this.n14*
 this.n21*this.n32*this.n43+this.n11*this.n24*this.n32*this.n43+this.n12*this.n21*this.n34*this.n43-this.n11*this.n22*this.n34*this.n43-this.n13*this.n22*this.n31*this.n44+this.n12*this.n23*this.n31*this.n44+this.n13*this.n21*this.n32*this.n44-this.n11*this.n23*this.n32*this.n44-this.n12*this.n21*this.n33*this.n44+this.n11*this.n22*this.n33*this.n44},transpose:function(){function a(b,d,i){var j=b[d];b[d]=b[i];b[i]=j}a(this,"n21","n12");a(this,"n31","n13");a(this,"n32","n23");a(this,"n41","n14");a(this,
 this.n21*this.n32*this.n43+this.n11*this.n24*this.n32*this.n43+this.n12*this.n21*this.n34*this.n43-this.n11*this.n22*this.n34*this.n43-this.n13*this.n22*this.n31*this.n44+this.n12*this.n23*this.n31*this.n44+this.n13*this.n21*this.n32*this.n44-this.n11*this.n23*this.n32*this.n44-this.n12*this.n21*this.n33*this.n44+this.n11*this.n22*this.n33*this.n44},transpose:function(){function a(b,d,i){var j=b[d];b[d]=b[i];b[i]=j}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(){return[this.n11,this.n21,this.n31,this.n41,this.n12,this.n22,this.n32,this.n42,this.n13,this.n23,this.n33,this.n43,this.n14,this.n24,this.n34,this.n44]},
 "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(){return[this.n11,this.n21,this.n31,this.n41,this.n12,this.n22,this.n32,this.n42,this.n13,this.n23,this.n33,this.n43,this.n14,this.n24,this.n34,this.n44]},
 toString:function(){return"| "+this.n11+" "+this.n12+" "+this.n13+" "+this.n14+" |\n| "+this.n21+" "+this.n22+" "+this.n23+" "+this.n24+" |\n| "+this.n31+" "+this.n32+" "+this.n33+" "+this.n34+" |\n| "+this.n41+" "+this.n42+" "+this.n43+" "+this.n44+" |"}};THREE.Matrix4.translationMatrix=function(a,b,d){var i=new THREE.Matrix4;i.n14=a;i.n24=b;i.n34=d;return i};THREE.Matrix4.scaleMatrix=function(a,b,d){var i=new THREE.Matrix4;i.n11=a;i.n22=b;i.n33=d;return i};
 toString:function(){return"| "+this.n11+" "+this.n12+" "+this.n13+" "+this.n14+" |\n| "+this.n21+" "+this.n22+" "+this.n23+" "+this.n24+" |\n| "+this.n31+" "+this.n32+" "+this.n33+" "+this.n34+" |\n| "+this.n41+" "+this.n42+" "+this.n43+" "+this.n44+" |"}};THREE.Matrix4.translationMatrix=function(a,b,d){var i=new THREE.Matrix4;i.n14=a;i.n24=b;i.n34=d;return i};THREE.Matrix4.scaleMatrix=function(a,b,d){var i=new THREE.Matrix4;i.n11=a;i.n22=b;i.n33=d;return i};
 THREE.Matrix4.rotationXMatrix=function(a){var b=new THREE.Matrix4;b.n22=b.n33=Math.cos(a);b.n32=Math.sin(a);b.n23=-b.n32;return b};THREE.Matrix4.rotationYMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n33=Math.cos(a);b.n13=Math.sin(a);b.n31=-b.n13;return b};THREE.Matrix4.rotationZMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n22=Math.cos(a);b.n21=Math.sin(a);b.n12=-b.n21;return b};
 THREE.Matrix4.rotationXMatrix=function(a){var b=new THREE.Matrix4;b.n22=b.n33=Math.cos(a);b.n32=Math.sin(a);b.n23=-b.n32;return b};THREE.Matrix4.rotationYMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n33=Math.cos(a);b.n13=Math.sin(a);b.n31=-b.n13;return b};THREE.Matrix4.rotationZMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n22=Math.cos(a);b.n21=Math.sin(a);b.n12=-b.n21;return b};
-THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var d=new THREE.Matrix4,i=Math.cos(b),j=Math.sin(b),p=1-i,m=a.x,r=a.y,l=a.z;d.n11=p*m*m+i;d.n12=p*m*r-j*l;d.n13=p*m*l+j*r;d.n21=p*m*r+j*l;d.n22=p*r*r+i;d.n23=p*r*l-j*m;d.n31=p*m*l-j*r;d.n32=p*r*l+j*m;d.n33=p*l*l+i;return d};
+THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var d=new THREE.Matrix4,i=Math.cos(b),j=Math.sin(b),p=1-i,m=a.x,q=a.y,l=a.z;d.n11=p*m*m+i;d.n12=p*m*q-j*l;d.n13=p*m*l+j*q;d.n21=p*m*q+j*l;d.n22=p*q*q+i;d.n23=p*q*l-j*m;d.n31=p*m*l-j*q;d.n32=p*q*l+j*m;d.n33=p*l*l+i;return d};
 THREE.Matrix4.makeInvert=function(a){var b=new THREE.Matrix4;b.n11=a.n23*a.n34*a.n42-a.n24*a.n33*a.n42+a.n24*a.n32*a.n43-a.n22*a.n34*a.n43-a.n23*a.n32*a.n44+a.n22*a.n33*a.n44;b.n12=a.n14*a.n33*a.n42-a.n13*a.n34*a.n42-a.n14*a.n32*a.n43+a.n12*a.n34*a.n43+a.n13*a.n32*a.n44-a.n12*a.n33*a.n44;b.n13=a.n13*a.n24*a.n42-a.n14*a.n23*a.n42+a.n14*a.n22*a.n43-a.n12*a.n24*a.n43-a.n13*a.n22*a.n44+a.n12*a.n23*a.n44;b.n14=a.n14*a.n23*a.n32-a.n13*a.n24*a.n32-a.n14*a.n22*a.n33+a.n12*a.n24*a.n33+a.n13*a.n22*a.n34-a.n12*
 THREE.Matrix4.makeInvert=function(a){var b=new THREE.Matrix4;b.n11=a.n23*a.n34*a.n42-a.n24*a.n33*a.n42+a.n24*a.n32*a.n43-a.n22*a.n34*a.n43-a.n23*a.n32*a.n44+a.n22*a.n33*a.n44;b.n12=a.n14*a.n33*a.n42-a.n13*a.n34*a.n42-a.n14*a.n32*a.n43+a.n12*a.n34*a.n43+a.n13*a.n32*a.n44-a.n12*a.n33*a.n44;b.n13=a.n13*a.n24*a.n42-a.n14*a.n23*a.n42+a.n14*a.n22*a.n43-a.n12*a.n24*a.n43-a.n13*a.n22*a.n44+a.n12*a.n23*a.n44;b.n14=a.n14*a.n23*a.n32-a.n13*a.n24*a.n32-a.n14*a.n22*a.n33+a.n12*a.n24*a.n33+a.n13*a.n22*a.n34-a.n12*
 a.n23*a.n34;b.n21=a.n24*a.n33*a.n41-a.n23*a.n34*a.n41-a.n24*a.n31*a.n43+a.n21*a.n34*a.n43+a.n23*a.n31*a.n44-a.n21*a.n33*a.n44;b.n22=a.n13*a.n34*a.n41-a.n14*a.n33*a.n41+a.n14*a.n31*a.n43-a.n11*a.n34*a.n43-a.n13*a.n31*a.n44+a.n11*a.n33*a.n44;b.n23=a.n14*a.n23*a.n41-a.n13*a.n24*a.n41-a.n14*a.n21*a.n43+a.n11*a.n24*a.n43+a.n13*a.n21*a.n44-a.n11*a.n23*a.n44;b.n24=a.n13*a.n24*a.n31-a.n14*a.n23*a.n31+a.n14*a.n21*a.n33-a.n11*a.n24*a.n33-a.n13*a.n21*a.n34+a.n11*a.n23*a.n34;b.n31=a.n22*a.n34*a.n41-a.n24*a.n32*
 a.n23*a.n34;b.n21=a.n24*a.n33*a.n41-a.n23*a.n34*a.n41-a.n24*a.n31*a.n43+a.n21*a.n34*a.n43+a.n23*a.n31*a.n44-a.n21*a.n33*a.n44;b.n22=a.n13*a.n34*a.n41-a.n14*a.n33*a.n41+a.n14*a.n31*a.n43-a.n11*a.n34*a.n43-a.n13*a.n31*a.n44+a.n11*a.n33*a.n44;b.n23=a.n14*a.n23*a.n41-a.n13*a.n24*a.n41-a.n14*a.n21*a.n43+a.n11*a.n24*a.n43+a.n13*a.n21*a.n44-a.n11*a.n23*a.n44;b.n24=a.n13*a.n24*a.n31-a.n14*a.n23*a.n31+a.n14*a.n21*a.n33-a.n11*a.n24*a.n33-a.n13*a.n21*a.n34+a.n11*a.n23*a.n34;b.n31=a.n22*a.n34*a.n41-a.n24*a.n32*
 a.n41+a.n24*a.n31*a.n42-a.n21*a.n34*a.n42-a.n22*a.n31*a.n44+a.n21*a.n32*a.n44;b.n32=a.n14*a.n32*a.n41-a.n12*a.n34*a.n41-a.n14*a.n31*a.n42+a.n11*a.n34*a.n42+a.n12*a.n31*a.n44-a.n11*a.n32*a.n44;b.n33=a.n13*a.n24*a.n41-a.n14*a.n22*a.n41+a.n14*a.n21*a.n42-a.n11*a.n24*a.n42-a.n12*a.n21*a.n44+a.n11*a.n22*a.n44;b.n34=a.n14*a.n22*a.n31-a.n12*a.n24*a.n31-a.n14*a.n21*a.n32+a.n11*a.n24*a.n32+a.n12*a.n21*a.n34-a.n11*a.n22*a.n34;b.n41=a.n23*a.n32*a.n41-a.n22*a.n33*a.n41-a.n23*a.n31*a.n42+a.n21*a.n33*a.n42+a.n22*
 a.n41+a.n24*a.n31*a.n42-a.n21*a.n34*a.n42-a.n22*a.n31*a.n44+a.n21*a.n32*a.n44;b.n32=a.n14*a.n32*a.n41-a.n12*a.n34*a.n41-a.n14*a.n31*a.n42+a.n11*a.n34*a.n42+a.n12*a.n31*a.n44-a.n11*a.n32*a.n44;b.n33=a.n13*a.n24*a.n41-a.n14*a.n22*a.n41+a.n14*a.n21*a.n42-a.n11*a.n24*a.n42-a.n12*a.n21*a.n44+a.n11*a.n22*a.n44;b.n34=a.n14*a.n22*a.n31-a.n12*a.n24*a.n31-a.n14*a.n21*a.n32+a.n11*a.n24*a.n32+a.n12*a.n21*a.n34-a.n11*a.n22*a.n34;b.n41=a.n23*a.n32*a.n41-a.n22*a.n33*a.n41-a.n23*a.n31*a.n42+a.n21*a.n33*a.n42+a.n22*
 a.n31*a.n43-a.n21*a.n32*a.n43;b.n42=a.n12*a.n33*a.n41-a.n13*a.n32*a.n41+a.n13*a.n31*a.n42-a.n11*a.n33*a.n42-a.n12*a.n31*a.n43+a.n11*a.n32*a.n43;b.n43=a.n13*a.n22*a.n41-a.n12*a.n23*a.n41-a.n13*a.n21*a.n42+a.n11*a.n23*a.n42+a.n12*a.n21*a.n43-a.n11*a.n22*a.n43;b.n44=a.n12*a.n23*a.n31-a.n13*a.n22*a.n31+a.n13*a.n21*a.n32-a.n11*a.n23*a.n32-a.n12*a.n21*a.n33+a.n11*a.n22*a.n33;b.multiplyScalar(1/a.determinant());return b};
 a.n31*a.n43-a.n21*a.n32*a.n43;b.n42=a.n12*a.n33*a.n41-a.n13*a.n32*a.n41+a.n13*a.n31*a.n42-a.n11*a.n33*a.n42-a.n12*a.n31*a.n43+a.n11*a.n32*a.n43;b.n43=a.n13*a.n22*a.n41-a.n12*a.n23*a.n41-a.n13*a.n21*a.n42+a.n11*a.n23*a.n42+a.n12*a.n21*a.n43-a.n11*a.n22*a.n43;b.n44=a.n12*a.n23*a.n31-a.n13*a.n22*a.n31+a.n13*a.n21*a.n32-a.n11*a.n23*a.n32-a.n12*a.n21*a.n33+a.n11*a.n22*a.n33;b.multiplyScalar(1/a.determinant());return b};
-THREE.Matrix4.makeInvert3x3=function(a){var b=a.flatten();a=new THREE.Matrix3;var d=b[10]*b[5]-b[6]*b[9],i=-b[10]*b[1]+b[2]*b[9],j=b[6]*b[1]-b[2]*b[5],p=-b[10]*b[4]+b[6]*b[8],m=b[10]*b[0]-b[2]*b[8],r=-b[6]*b[0]+b[2]*b[4],l=b[9]*b[4]-b[5]*b[8],c=-b[9]*b[0]+b[1]*b[8],z=b[5]*b[0]-b[1]*b[4];b=b[0]*d+b[1]*p+b[2]*l;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*d;a.m[1]=b*i;a.m[2]=b*j;a.m[3]=b*p;a.m[4]=b*m;a.m[5]=b*r;a.m[6]=b*l;a.m[7]=b*c;a.m[8]=b*z;return a};
-THREE.Matrix4.makeFrustum=function(a,b,d,i,j,p){var m,r,l;m=new THREE.Matrix4;r=2*j/(b-a);l=2*j/(i-d);a=(b+a)/(b-a);d=(i+d)/(i-d);i=-(p+j)/(p-j);j=-2*p*j/(p-j);m.n11=r;m.n12=0;m.n13=a;m.n14=0;m.n21=0;m.n22=l;m.n23=d;m.n24=0;m.n31=0;m.n32=0;m.n33=i;m.n34=j;m.n41=0;m.n42=0;m.n43=-1;m.n44=0;return m};THREE.Matrix4.makePerspective=function(a,b,d,i){var j;a=d*Math.tan(a*Math.PI/360);j=-a;return THREE.Matrix4.makeFrustum(j*b,a*b,j,a,d,i)};
-THREE.Matrix4.makeOrtho=function(a,b,d,i,j,p){var m,r,l,c;m=new THREE.Matrix4;r=b-a;l=d-i;c=p-j;a=(b+a)/r;d=(d+i)/l;j=(p+j)/c;m.n11=2/r;m.n12=0;m.n13=0;m.n14=-a;m.n21=0;m.n22=2/l;m.n23=0;m.n24=-d;m.n31=0;m.n32=0;m.n33=-2/c;m.n34=-j;m.n41=0;m.n42=0;m.n43=0;m.n44=1;return m};
+THREE.Matrix4.makeInvert3x3=function(a){var b=a.flatten();a=new THREE.Matrix3;var d=b[10]*b[5]-b[6]*b[9],i=-b[10]*b[1]+b[2]*b[9],j=b[6]*b[1]-b[2]*b[5],p=-b[10]*b[4]+b[6]*b[8],m=b[10]*b[0]-b[2]*b[8],q=-b[6]*b[0]+b[2]*b[4],l=b[9]*b[4]-b[5]*b[8],c=-b[9]*b[0]+b[1]*b[8],E=b[5]*b[0]-b[1]*b[4];b=b[0]*d+b[1]*p+b[2]*l;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*d;a.m[1]=b*i;a.m[2]=b*j;a.m[3]=b*p;a.m[4]=b*m;a.m[5]=b*q;a.m[6]=b*l;a.m[7]=b*c;a.m[8]=b*E;return a};
+THREE.Matrix4.makeFrustum=function(a,b,d,i,j,p){var m,q,l;m=new THREE.Matrix4;q=2*j/(b-a);l=2*j/(i-d);a=(b+a)/(b-a);d=(i+d)/(i-d);i=-(p+j)/(p-j);j=-2*p*j/(p-j);m.n11=q;m.n12=0;m.n13=a;m.n14=0;m.n21=0;m.n22=l;m.n23=d;m.n24=0;m.n31=0;m.n32=0;m.n33=i;m.n34=j;m.n41=0;m.n42=0;m.n43=-1;m.n44=0;return m};THREE.Matrix4.makePerspective=function(a,b,d,i){var j;a=d*Math.tan(a*Math.PI/360);j=-a;return THREE.Matrix4.makeFrustum(j*b,a*b,j,a,d,i)};
+THREE.Matrix4.makeOrtho=function(a,b,d,i,j,p){var m,q,l,c;m=new THREE.Matrix4;q=b-a;l=d-i;c=p-j;a=(b+a)/q;d=(d+i)/l;j=(p+j)/c;m.n11=2/q;m.n12=0;m.n13=0;m.n14=-a;m.n21=0;m.n22=2/l;m.n23=0;m.n24=-d;m.n31=0;m.n32=0;m.n33=-2/c;m.n34=-j;m.n41=0;m.n42=0;m.n43=0;m.n44=1;return m};
 THREE.Vertex=function(a,b){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=b||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}};
 THREE.Vertex=function(a,b){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=b||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}};
 THREE.Face3=function(a,b,d,i,j){this.a=a;this.b=b;this.c=d;this.centroid=new THREE.Vector3;this.normal=i instanceof THREE.Vector3?i:new THREE.Vector3;this.vertexNormals=i instanceof Array?i:[];this.material=j instanceof Array?j:[j]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
 THREE.Face3=function(a,b,d,i,j){this.a=a;this.b=b;this.c=d;this.centroid=new THREE.Vector3;this.normal=i instanceof THREE.Vector3?i:new THREE.Vector3;this.vertexNormals=i instanceof Array?i:[];this.material=j instanceof Array?j:[j]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
 THREE.Face4=function(a,b,d,i,j,p){this.a=a;this.b=b;this.c=d;this.d=i;this.centroid=new THREE.Vector3;this.normal=j instanceof THREE.Vector3?j:new THREE.Vector3;this.vertexNormals=j instanceof Array?j:[];this.material=p instanceof Array?p:[p]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
 THREE.Face4=function(a,b,d,i,j,p){this.a=a;this.b=b;this.c=d;this.d=i;this.centroid=new THREE.Vector3;this.normal=j instanceof THREE.Vector3?j:new THREE.Vector3;this.vertexNormals=j instanceof Array?j:[];this.material=p instanceof Array?p:[p]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
 THREE.UV.prototype={copy:function(a){this.u=a.u;this.v=a.v},toString:function(){return"THREE.UV ("+this.u+", "+this.v+")"}};THREE.Geometry=function(){this.vertices=[];this.faces=[];this.uvs=[];this.geometryChunks={}};
 THREE.UV.prototype={copy:function(a){this.u=a.u;this.v=a.v},toString:function(){return"THREE.UV ("+this.u+", "+this.v+")"}};THREE.Geometry=function(){this.vertices=[];this.faces=[];this.uvs=[];this.geometryChunks={}};
-THREE.Geometry.prototype={computeCentroids:function(){var a,b,d;a=0;for(b=this.faces.length;a<b;a++){d=this.faces[a];d.centroid.set(0,0,0);d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);if(d instanceof THREE.Face3)d.centroid.divideScalar(3);else if(d instanceof THREE.Face4){d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeNormals:function(a){var b,d,i,j,p,m,r=new THREE.Vector3,
-l=new THREE.Vector3;i=0;for(j=this.vertices.length;i<j;i++){p=this.vertices[i];p.normal.set(0,0,0)}i=0;for(j=this.faces.length;i<j;i++){p=this.faces[i];if(a&&p.vertexNormals.length){r.set(0,0,0);b=0;for(d=p.normal.length;b<d;b++)r.addSelf(p.vertexNormals[b]);r.divideScalar(3)}else{b=this.vertices[p.a];d=this.vertices[p.b];m=this.vertices[p.c];r.sub(m.position,d.position);l.sub(b.position,d.position);r.crossSelf(l)}r.isZero()||r.normalize();p.normal.copy(r)}},computeBoundingBox:function(){if(this.vertices.length>
-0){this.bbox={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 a=1,b=this.vertices.length;a<b;a++){vertex=this.vertices[a];if(vertex.position.x<this.bbox.x[0])this.bbox.x[0]=vertex.position.x;else if(vertex.position.x>this.bbox.x[1])this.bbox.x[1]=vertex.position.x;if(vertex.position.y<this.bbox.y[0])this.bbox.y[0]=vertex.position.y;else if(vertex.position.y>
-this.bbox.y[1])this.bbox.y[1]=vertex.position.y;if(vertex.position.z<this.bbox.z[0])this.bbox.z[0]=vertex.position.z;else if(vertex.position.z>this.bbox.z[1])this.bbox.z[1]=vertex.position.z}}},sortFacesByMaterial:function(){function a(z){var G=[];b=0;for(d=z.length;b<d;b++)z[b]==undefined?G.push("undefined"):G.push(z[b].toString());return G.join("_")}var b,d,i,j,p,m,r,l,c={};i=0;for(j=this.faces.length;i<j;i++){p=this.faces[i];m=p.material;r=a(m);if(c[r]==undefined)c[r]={hash:r,counter:0};l=c[r].hash+
-"_"+c[r].counter;if(this.geometryChunks[l]==undefined)this.geometryChunks[l]={faces:[],material:m,vertices:0};p=p instanceof THREE.Face3?3:4;if(this.geometryChunks[l].vertices+p>65535){c[r].counter+=1;l=c[r].hash+"_"+c[r].counter;if(this.geometryChunks[l]==undefined)this.geometryChunks[l]={faces:[],material:m,vertices:0}}this.geometryChunks[l].faces.push(i);this.geometryChunks[l].vertices+=p}},toString:function(){return"THREE.Geometry ( vertices: "+this.vertices+", faces: "+this.faces+" )"}};
+THREE.Geometry.prototype={computeCentroids:function(){var a,b,d;a=0;for(b=this.faces.length;a<b;a++){d=this.faces[a];d.centroid.set(0,0,0);d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);if(d instanceof THREE.Face3)d.centroid.divideScalar(3);else if(d instanceof THREE.Face4){d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeNormals:function(a){var b,d,i,j,p,m,q=new THREE.Vector3,
+l=new THREE.Vector3;i=0;for(j=this.vertices.length;i<j;i++){p=this.vertices[i];p.normal.set(0,0,0)}i=0;for(j=this.faces.length;i<j;i++){p=this.faces[i];if(a&&p.vertexNormals.length){q.set(0,0,0);b=0;for(d=p.normal.length;b<d;b++)q.addSelf(p.vertexNormals[b]);q.divideScalar(3)}else{b=this.vertices[p.a];d=this.vertices[p.b];m=this.vertices[p.c];q.sub(m.position,d.position);l.sub(b.position,d.position);q.crossSelf(l)}q.isZero()||q.normalize();p.normal.copy(q)}},computeVertexNormals:function(){var a,
+b;a=0;for(b=this.faces.length;a<b;a++);},computeBoundingBox:function(){if(this.vertices.length>0){this.bbox={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 a=1,b=this.vertices.length;a<b;a++){vertex=this.vertices[a];if(vertex.position.x<this.bbox.x[0])this.bbox.x[0]=vertex.position.x;else if(vertex.position.x>this.bbox.x[1])this.bbox.x[1]=vertex.position.x;
+if(vertex.position.y<this.bbox.y[0])this.bbox.y[0]=vertex.position.y;else if(vertex.position.y>this.bbox.y[1])this.bbox.y[1]=vertex.position.y;if(vertex.position.z<this.bbox.z[0])this.bbox.z[0]=vertex.position.z;else if(vertex.position.z>this.bbox.z[1])this.bbox.z[1]=vertex.position.z}}},sortFacesByMaterial:function(){function a(E){var G=[];b=0;for(d=E.length;b<d;b++)E[b]==undefined?G.push("undefined"):G.push(E[b].toString());return G.join("_")}var b,d,i,j,p,m,q,l,c={};i=0;for(j=this.faces.length;i<
+j;i++){p=this.faces[i];m=p.material;q=a(m);if(c[q]==undefined)c[q]={hash:q,counter:0};l=c[q].hash+"_"+c[q].counter;if(this.geometryChunks[l]==undefined)this.geometryChunks[l]={faces:[],material:m,vertices:0};p=p instanceof THREE.Face3?3:4;if(this.geometryChunks[l].vertices+p>65535){c[q].counter+=1;l=c[q].hash+"_"+c[q].counter;if(this.geometryChunks[l]==undefined)this.geometryChunks[l]={faces:[],material:m,vertices:0}}this.geometryChunks[l].faces.push(i);this.geometryChunks[l].vertices+=p}},toString:function(){return"THREE.Geometry ( vertices: "+
+this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
 THREE.Camera=function(a,b,d,i){this.position=new THREE.Vector3(0,0,0);this.target={position:new THREE.Vector3(0,0,0)};this.up=new THREE.Vector3(0,1,0);this.matrix=new THREE.Matrix4;this.projectionMatrix=THREE.Matrix4.makePerspective(a,b,d,i);this.autoUpdateMatrix=true;this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.toString=function(){return"THREE.Camera ( "+this.position+", "+this.target.position+" )"}};THREE.Light=function(a){this.color=new THREE.Color(a)};
 THREE.Camera=function(a,b,d,i){this.position=new THREE.Vector3(0,0,0);this.target={position:new THREE.Vector3(0,0,0)};this.up=new THREE.Vector3(0,1,0);this.matrix=new THREE.Matrix4;this.projectionMatrix=THREE.Matrix4.makePerspective(a,b,d,i);this.autoUpdateMatrix=true;this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.toString=function(){return"THREE.Camera ( "+this.position+", "+this.target.position+" )"}};THREE.Light=function(a){this.color=new THREE.Color(a)};
 THREE.AmbientLight=function(a){THREE.Light.call(this,a)};THREE.AmbientLight.prototype=new THREE.Light;THREE.AmbientLight.prototype.constructor=THREE.AmbientLight;THREE.DirectionalLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,1,0);this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.DirectionalLight;
 THREE.AmbientLight=function(a){THREE.Light.call(this,a)};THREE.AmbientLight.prototype=new THREE.Light;THREE.AmbientLight.prototype.constructor=THREE.AmbientLight;THREE.DirectionalLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,1,0);this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.DirectionalLight;
 THREE.PointLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3;this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.PointLight;
 THREE.PointLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3;this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.PointLight;
@@ -82,87 +83,87 @@ this.blending+"<br/>)"}};THREE.ParticleCircleMaterial=function(a){this.color=new
 THREE.ParticleDOMMaterial=function(a){this.domElement=a;this.toString=function(){return"THREE.ParticleDOMMaterial ( domElement: "+this.domElement+" )"}};THREE.Texture=function(a,b,d,i){this.image=a;this.loaded=false;this.mapping=b!==undefined?b:THREE.UVMapping;this.wrap_s=d!==undefined?d:THREE.ClampToEdge;this.wrap_t=i!==undefined?i:THREE.ClampToEdge;this.toString=function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>wrap_s: "+this.wrap_s+"<br/>wrap_t: "+this.wrap_t+"<br/>)"}};
 THREE.ParticleDOMMaterial=function(a){this.domElement=a;this.toString=function(){return"THREE.ParticleDOMMaterial ( domElement: "+this.domElement+" )"}};THREE.Texture=function(a,b,d,i){this.image=a;this.loaded=false;this.mapping=b!==undefined?b:THREE.UVMapping;this.wrap_s=d!==undefined?d:THREE.ClampToEdge;this.wrap_t=i!==undefined?i:THREE.ClampToEdge;this.toString=function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>wrap_s: "+this.wrap_s+"<br/>wrap_t: "+this.wrap_t+"<br/>)"}};
 THREE.UVMapping=0;THREE.ReflectionMapping=1;THREE.RefractionMapping=2;THREE.Multiply=0;THREE.Mix=1;THREE.Repeat=0;THREE.ClampToEdge=1;THREE.MirroredRepeat=2;THREE.TextureCube=function(a,b){this.image=a;this.mapping=b?b:THREE.ReflectionMap;this.toString=function(){return"THREE.TextureCube (<br/>image: "+this.image+"<br/>mapping: "+this.mapping+"<br/>)"}};
 THREE.UVMapping=0;THREE.ReflectionMapping=1;THREE.RefractionMapping=2;THREE.Multiply=0;THREE.Mix=1;THREE.Repeat=0;THREE.ClampToEdge=1;THREE.MirroredRepeat=2;THREE.TextureCube=function(a,b){this.image=a;this.mapping=b?b:THREE.ReflectionMap;this.toString=function(){return"THREE.TextureCube (<br/>image: "+this.image+"<br/>mapping: "+this.mapping+"<br/>)"}};
 THREE.Scene=function(){this.objects=[];this.lights=[];this.addObject=function(a){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.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.Scene=function(){this.objects=[];this.lights=[];this.addObject=function(a){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.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.Projector=function(){function a(S,B){var e=0,f=1,k=S.z+S.w,o=B.z+B.w,g=-S.z+S.w,h=-B.z+B.w;if(k>=0&&o>=0&&g>=0&&h>=0)return true;else if(k<0&&o<0||g<0&&h<0)return false;else{if(k<0)e=Math.max(e,k/(k-o));else if(o<0)f=Math.min(f,k/(k-o));if(g<0)e=Math.max(e,g/(g-h));else if(h<0)f=Math.min(f,g/(g-h));if(f<e)return false;else{S.lerpSelf(B,e);B.lerpSelf(S,1-f);return true}}}var b=null,d,i,j,p=[],m,r,l=[],c,z,G=[],x=new THREE.Vector4,F=new THREE.Matrix4,O=new THREE.Matrix4,J=new THREE.Vector4,M=
-new THREE.Vector4,n;this.projectScene=function(S,B){var e,f,k,o,g,h,w,s,L,u,T,Q,t,H,q,A,y;b=[];j=r=z=0;B.autoUpdateMatrix&&B.updateMatrix();F.multiply(B.projectionMatrix,B.matrix);w=S.objects;e=0;for(f=w.length;e<f;e++){s=w[e];s.autoUpdateMatrix&&s.updateMatrix();L=s.matrix;u=s.rotationMatrix;T=s.material;Q=s.overdraw;if(s instanceof THREE.Mesh){t=s.geometry.vertices;k=0;for(o=t.length;k<o;k++){H=t[k];H.positionWorld.copy(H.position);L.transformVector3(H.positionWorld);q=H.positionScreen;q.copy(H.positionWorld);
-F.transformVector4(q);q.multiplyScalar(1/q.w);H.__visible=q.z>0&&q.z<1}H=s.geometry.faces;k=0;for(o=H.length;k<o;k++){q=H[k];if(q instanceof THREE.Face3){g=t[q.a];h=t[q.b];A=t[q.c];if(g.__visible&&h.__visible&&A.__visible)if(s.doubleSided||s.flipSided!=(A.positionScreen.x-g.positionScreen.x)*(h.positionScreen.y-g.positionScreen.y)-(A.positionScreen.y-g.positionScreen.y)*(h.positionScreen.x-g.positionScreen.x)<0){d=p[j]=p[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(g.positionWorld);d.v2.positionWorld.copy(h.positionWorld);
-d.v3.positionWorld.copy(A.positionWorld);d.v1.positionScreen.copy(g.positionScreen);d.v2.positionScreen.copy(h.positionScreen);d.v3.positionScreen.copy(A.positionScreen);d.normalWorld.copy(q.normal);u.transformVector3(d.normalWorld);d.centroidWorld.copy(q.centroid);L.transformVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);F.transformVector3(d.centroidScreen);A=q.vertexNormals;n=d.vertexNormalsWorld;g=0;for(h=A.length;g<h;g++){y=n[g]=n[g]||new THREE.Vector3;y.copy(A[g]);u.transformVector3(y)}d.z=
-d.centroidScreen.z;d.meshMaterial=T;d.faceMaterial=q.material;d.overdraw=Q;if(s.geometry.uvs[k]){d.uvs[0]=s.geometry.uvs[k][0];d.uvs[1]=s.geometry.uvs[k][1];d.uvs[2]=s.geometry.uvs[k][2]}b.push(d);j++}}else if(q instanceof THREE.Face4){g=t[q.a];h=t[q.b];A=t[q.c];y=t[q.d];if(g.__visible&&h.__visible&&A.__visible&&y.__visible)if(s.doubleSided||s.flipSided!=((y.positionScreen.x-g.positionScreen.x)*(h.positionScreen.y-g.positionScreen.y)-(y.positionScreen.y-g.positionScreen.y)*(h.positionScreen.x-g.positionScreen.x)<
-0||(h.positionScreen.x-A.positionScreen.x)*(y.positionScreen.y-A.positionScreen.y)-(h.positionScreen.y-A.positionScreen.y)*(y.positionScreen.x-A.positionScreen.x)<0)){d=p[j]=p[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(g.positionWorld);d.v2.positionWorld.copy(h.positionWorld);d.v3.positionWorld.copy(y.positionWorld);d.v1.positionScreen.copy(g.positionScreen);d.v2.positionScreen.copy(h.positionScreen);d.v3.positionScreen.copy(y.positionScreen);d.normalWorld.copy(q.normal);u.transformVector3(d.normalWorld);
-d.centroidWorld.copy(q.centroid);L.transformVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);F.transformVector3(d.centroidScreen);d.z=d.centroidScreen.z;d.meshMaterial=T;d.faceMaterial=q.material;d.overdraw=Q;if(s.geometry.uvs[k]){d.uvs[0]=s.geometry.uvs[k][0];d.uvs[1]=s.geometry.uvs[k][1];d.uvs[2]=s.geometry.uvs[k][3]}b.push(d);j++;i=p[j]=p[j]||new THREE.RenderableFace3;i.v1.positionWorld.copy(h.positionWorld);i.v2.positionWorld.copy(A.positionWorld);i.v3.positionWorld.copy(y.positionWorld);
-i.v1.positionScreen.copy(h.positionScreen);i.v2.positionScreen.copy(A.positionScreen);i.v3.positionScreen.copy(y.positionScreen);i.normalWorld.copy(d.normalWorld);i.centroidWorld.copy(d.centroidWorld);i.centroidScreen.copy(d.centroidScreen);i.z=i.centroidScreen.z;i.meshMaterial=T;i.faceMaterial=q.material;i.overdraw=Q;if(s.geometry.uvs[k]){i.uvs[0]=s.geometry.uvs[k][1];i.uvs[1]=s.geometry.uvs[k][2];i.uvs[2]=s.geometry.uvs[k][3]}b.push(i);j++}}}}else if(s instanceof THREE.Line){O.multiply(F,L);t=s.geometry.vertices;
-H=t[0];H.positionScreen.copy(H.position);O.transformVector4(H.positionScreen);k=1;for(o=t.length;k<o;k++){g=t[k];g.positionScreen.copy(g.position);O.transformVector4(g.positionScreen);h=t[k-1];J.copy(g.positionScreen);M.copy(h.positionScreen);if(a(J,M)){J.multiplyScalar(1/J.w);M.multiplyScalar(1/M.w);m=l[r]=l[r]||new THREE.RenderableLine;m.v1.positionScreen.copy(J);m.v2.positionScreen.copy(M);m.z=Math.max(J.z,M.z);m.material=s.material;b.push(m);r++}}}else if(s instanceof THREE.Particle){x.set(s.position.x,
-s.position.y,s.position.z,1);F.transformVector4(x);x.z/=x.w;if(x.z>0&&x.z<1){c=G[z]=G[z]||new THREE.RenderableParticle;c.x=x.x/x.w;c.y=x.y/x.w;c.z=x.z;c.rotation=s.rotation.z;c.scale.x=s.scale.x*Math.abs(c.x-(x.x+B.projectionMatrix.n11)/(x.w+B.projectionMatrix.n14));c.scale.y=s.scale.y*Math.abs(c.y-(x.y+B.projectionMatrix.n22)/(x.w+B.projectionMatrix.n24));c.material=s.material;b.push(c);z++}}}b.sort(function(P,D){return D.z-P.z});return b};this.unprojectVector=function(S,B){var e=new THREE.Matrix4;
-e.multiply(THREE.Matrix4.makeInvert(B.matrix),THREE.Matrix4.makeInvert(B.projectionMatrix));e.transformVector3(S);return S}};
-THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,d,i,j,p;this.domElement=document.createElement("div");this.setSize=function(m,r){d=m;i=r;j=d/2;p=i/2};this.render=function(m,r){var l,c,z,G,x,F,O,J;a=b.projectScene(m,r);l=0;for(c=a.length;l<c;l++){x=a[l];if(x instanceof THREE.RenderableParticle){O=x.x*j+j;J=x.y*p+p;z=0;for(G=x.material.length;z<G;z++){F=x.material[z];if(F instanceof THREE.ParticleDOMMaterial){F=F.domElement;F.style.left=O+"px";F.style.top=J+"px"}}}}}};
-THREE.CanvasRenderer=function(){function a(I,Y,U,E){var v,K,$,N,X=I.lights;I=0;for(v=X.length;I<v;I++){K=X[I];$=K.color;N=K.intensity;if(K instanceof THREE.DirectionalLight){K=U.dot(K.position)*N;if(K>0){E.r+=$.r*K;E.g+=$.g*K;E.b+=$.b*K}}else if(K instanceof THREE.PointLight){aa.sub(K.position,Y);aa.normalize();K=U.dot(aa)*N;if(K>0){E.r+=$.r*K;E.g+=$.g*K;E.b+=$.b*K}}}}function b(I,Y,U,E,v,K){if(v.opacity!=0){p(v.opacity);m(v.blending);L=I.positionScreen.x;u=I.positionScreen.y;T=Y.positionScreen.x;
-Q=Y.positionScreen.y;t=U.positionScreen.x;H=U.positionScreen.y;var $=L,N=u,X=T,ba=Q,Z=t,ca=H;n.beginPath();n.moveTo($,N);n.lineTo(X,ba);n.lineTo(Z,ca);n.lineTo($,N);n.closePath();if(v instanceof THREE.MeshBasicMaterial)if(v.map&&v.map.loaded)j(L,u,T,Q,t,H,v.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(v.env_map&&v.env_map.loaded){if(v.env_map.mapping==THREE.ReflectionMapping){aa.copy(E.vertexNormalsWorld[0]);V=(aa.x*camera.matrix.n11+aa.y*camera.matrix.n12+
-aa.z*camera.matrix.n13)*0.5+0.5;ka=-(aa.x*camera.matrix.n21+aa.y*camera.matrix.n22+aa.z*camera.matrix.n23)*0.5+0.5;aa.copy(E.vertexNormalsWorld[1]);za=(aa.x*camera.matrix.n11+aa.y*camera.matrix.n12+aa.z*camera.matrix.n13)*0.5+0.5;Aa=-(aa.x*camera.matrix.n21+aa.y*camera.matrix.n22+aa.z*camera.matrix.n23)*0.5+0.5;aa.copy(E.vertexNormalsWorld[2]);Ba=(aa.x*camera.matrix.n11+aa.y*camera.matrix.n12+aa.z*camera.matrix.n13)*0.5+0.5;Ca=-(aa.x*camera.matrix.n21+aa.y*camera.matrix.n22+aa.z*camera.matrix.n23)*
-0.5+0.5;j(L,u,T,Q,t,H,v.env_map.image,V,ka,za,Aa,Ba,Ca)}}else v.wireframe?d(v.color.__styleString,v.wireframe_linewidth):i(v.color.__styleString);else if(v instanceof THREE.MeshLambertMaterial){if(v.map&&!v.wireframe){j(L,u,T,Q,t,H,v.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);m(THREE.SubtractiveBlending)}if(va)if(!v.wireframe&&v.shading==THREE.SmoothShading&&E.vertexNormalsWorld.length==3){A.r=y.r=P.r=ga.r;A.g=y.g=P.g=ga.g;A.b=y.b=P.b=ga.b;a(K,E.v1.positionWorld,
-E.vertexNormalsWorld[0],A);a(K,E.v2.positionWorld,E.vertexNormalsWorld[1],y);a(K,E.v3.positionWorld,E.vertexNormalsWorld[2],P);D.r=(y.r+P.r)*0.5;D.g=(y.g+P.g)*0.5;D.b=(y.b+P.b)*0.5;R=r(A,y,P,D);j(L,u,T,Q,t,H,R,0,0,1,0,0,1)}else{ha.r=ga.r;ha.g=ga.g;ha.b=ga.b;a(K,E.centroidWorld,E.normalWorld,ha);q.r=v.color.r*ha.r;q.g=v.color.g*ha.g;q.b=v.color.b*ha.b;q.updateStyleString();v.wireframe?d(q.__styleString,v.wireframe_linewidth):i(q.__styleString)}else v.wireframe?d(v.color.__styleString,v.wireframe_linewidth):
-i(v.color.__styleString)}else if(v instanceof THREE.MeshDepthMaterial){C=v.__2near;W=v.__farPlusNear;ea=v.__farMinusNear;A.r=A.g=A.b=1-C/(W-I.positionScreen.z*ea);y.r=y.g=y.b=1-C/(W-Y.positionScreen.z*ea);P.r=P.g=P.b=1-C/(W-U.positionScreen.z*ea);D.r=(y.r+P.r)*0.5;D.g=(y.g+P.g)*0.5;D.b=(y.b+P.b)*0.5;R=r(A,y,P,D);j(L,u,T,Q,t,H,R,0,0,1,0,0,1)}else if(v instanceof THREE.MeshNormalMaterial){q.r=l(E.normalWorld.x);q.g=l(E.normalWorld.y);q.b=l(E.normalWorld.z);q.updateStyleString();v.wireframe?d(q.__styleString,
-v.wireframe_linewidth):i(q.__styleString)}}}function d(I,Y){if(e!=I)n.strokeStyle=e=I;if(k!=Y)n.lineWidth=k=Y;n.stroke();da.inflate(Y*2)}function i(I){if(f!=I)n.fillStyle=f=I;n.fill()}function j(I,Y,U,E,v,K,$,N,X,ba,Z,ca,na){var la,fa;la=$.width-1;fa=$.height-1;N*=la;X*=fa;ba*=la;Z*=fa;ca*=la;na*=fa;U-=I;E-=Y;v-=I;K-=Y;ba-=N;Z-=X;ca-=N;na-=X;fa=1/(ba*na-ca*Z);la=(na*U-Z*v)*fa;Z=(na*E-Z*K)*fa;U=(ba*v-ca*U)*fa;E=(ba*K-ca*E)*fa;I=I-la*N-U*X;Y=Y-Z*N-E*X;n.save();n.transform(la,Z,U,E,I,Y);n.clip();n.drawImage($,
-0,0);n.restore()}function p(I){if(S!=I)n.globalAlpha=S=I}function m(I){if(B!=I){switch(I){case THREE.NormalBlending:n.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:n.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:n.globalCompositeOperation="darker"}B=I}}function r(I,Y,U,E){ia[0]=g(0,o(255,~~(I.r*255)));ia[1]=g(0,o(255,~~(I.g*255)));ia[2]=g(0,o(255,~~(I.b*255)));ia[4]=g(0,o(255,~~(Y.r*255)));ia[5]=g(0,o(255,~~(Y.g*255)));ia[6]=g(0,o(255,~~(Y.b*255)));
-ia[8]=g(0,o(255,~~(U.r*255)));ia[9]=g(0,o(255,~~(U.g*255)));ia[10]=g(0,o(255,~~(U.b*255)));ia[12]=g(0,o(255,~~(E.r*255)));ia[13]=g(0,o(255,~~(E.g*255)));ia[14]=g(0,o(255,~~(E.b*255)));ra.putImageData(wa,0,0);ua.drawImage(sa,0,0);return ta}function l(I){return I<0?o((1+I)*0.5,0.5):0.5+o(I*0.5,0.5)}function c(I,Y){var U=Y.x-I.x,E=Y.y-I.y,v=1/Math.sqrt(U*U+E*E);U*=v;E*=v;Y.x+=U;Y.y+=E;I.x-=U;I.y-=E}var z=null,G=new THREE.Projector,x=document.createElement("canvas"),F,O,J,M,n=x.getContext("2d"),S=1,B=
-0,e=null,f=null,k=1,o=Math.min,g=Math.max,h,w,s,L,u,T,Q,t,H,q=new THREE.Color,A=new THREE.Color,y=new THREE.Color,P=new THREE.Color,D=new THREE.Color,C,W,ea,R,V,ka,za,Aa,Ba,Ca,ma=new THREE.Rectangle,ja=new THREE.Rectangle,da=new THREE.Rectangle,va=false,ha=new THREE.Color,ga=new THREE.Color,oa=new THREE.Color,pa=new THREE.Color,Da=Math.PI*2,aa=new THREE.Vector3,sa,ra,wa,ia,ta,ua,qa=16;sa=document.createElement("canvas");sa.width=sa.height=2;ra=sa.getContext("2d");ra.fillStyle="rgba(0,0,0,1)";ra.fillRect(0,
-0,2,2);wa=ra.getImageData(0,0,2,2);ia=wa.data;ta=document.createElement("canvas");ta.width=ta.height=qa;ua=ta.getContext("2d");ua.translate(-qa/2,-qa/2);ua.scale(qa,qa);qa--;this.domElement=x;this.autoClear=true;this.setSize=function(I,Y){F=I;O=Y;J=F/2;M=O/2;x.width=F;x.height=O;ma.set(-J,-M,J,M)};this.clear=function(){if(!ja.isEmpty()){ja.inflate(1);ja.minSelf(ma);n.clearRect(ja.getX(),ja.getY(),ja.getWidth(),ja.getHeight());ja.empty()}};this.render=function(I,Y){var U,E,v,K,$,N,X,ba;n.setTransform(1,
-0,0,-1,J,M);this.autoClear&&this.clear();z=G.projectScene(I,Y);n.fillStyle="rgba(0, 255, 255, 0.5)";n.fillRect(ma.getX(),ma.getY(),ma.getWidth(),ma.getHeight());if(va=I.lights.length>0){$=I.lights;ga.setRGB(0,0,0);oa.setRGB(0,0,0);pa.setRGB(0,0,0);U=0;for(E=$.length;U<E;U++){v=$[U];K=v.color;if(v instanceof THREE.AmbientLight){ga.r+=K.r;ga.g+=K.g;ga.b+=K.b}else if(v instanceof THREE.DirectionalLight){oa.r+=K.r;oa.g+=K.g;oa.b+=K.b}else if(v instanceof THREE.PointLight){pa.r+=K.r;pa.g+=K.g;pa.b+=K.b}}}U=
-0;for(E=z.length;U<E;U++){v=z[U];da.empty();if(v instanceof THREE.RenderableParticle){h=v;h.x*=J;h.y*=M;K=0;for($=v.material.length;K<$;K++)a:{N=h;X=v;var Z=v.material[K];if(Z.opacity!=0){p(Z.opacity);m(Z.blending);ba=void 0;var ca=void 0,na=void 0,la=void 0,fa=void 0,xa=void 0,ya=void 0;if(Z instanceof THREE.ParticleBasicMaterial){if(Z.map){fa=Z.map;xa=fa.width>>1;ya=fa.height>>1;na=X.scale.x*J;la=X.scale.y*M;ba=na*xa;ca=la*ya;da.set(N.x-ba,N.y-ca,N.x+ba,N.y+ca);if(!ma.instersects(da))break a;n.save();
-n.translate(N.x,N.y);n.rotate(-X.rotation);n.scale(na,-la);n.translate(-xa,-ya);n.drawImage(fa,0,0);n.restore()}n.beginPath();n.moveTo(N.x-10,N.y);n.lineTo(N.x+10,N.y);n.moveTo(N.x,N.y-10);n.lineTo(N.x,N.y+10);n.closePath();n.strokeStyle="rgb(255,255,0)";n.stroke()}else if(Z instanceof THREE.ParticleCircleMaterial){if(va){ha.r=ga.r+oa.r+pa.r;ha.g=ga.g+oa.g+pa.g;ha.b=ga.b+oa.b+pa.b;q.r=Z.color.r*ha.r;q.g=Z.color.g*ha.g;q.b=Z.color.b*ha.b;q.updateStyleString()}else q.__styleString=Z.color.__styleString;
-ba=X.scale.x*J;ca=X.scale.y*M;da.set(N.x-ba,N.y-ca,N.x+ba,N.y+ca);if(ma.instersects(da)){Z=q.__styleString;if(f!=Z)n.fillStyle=f=Z;n.save();n.translate(N.x,N.y);n.rotate(-X.rotation);n.scale(ba,ca);n.beginPath();n.arc(0,0,1,0,Da,true);n.closePath();n.fill();n.restore()}}}}}else if(v instanceof THREE.RenderableLine){h=v.v1;w=v.v2;h.positionScreen.x*=J;h.positionScreen.y*=M;w.positionScreen.x*=J;w.positionScreen.y*=M;da.addPoint(h.positionScreen.x,h.positionScreen.y);da.addPoint(w.positionScreen.x,
-w.positionScreen.y);if(ma.instersects(da)){K=0;for($=v.material.length;K<$;){X=h;ba=w;N=v.material[K++];if(N.opacity!=0){p(N.opacity);m(N.blending);n.beginPath();n.moveTo(X.positionScreen.x,X.positionScreen.y);n.lineTo(ba.positionScreen.x,ba.positionScreen.y);n.closePath();if(N instanceof THREE.LineBasicMaterial){q.__styleString=N.color.__styleString;X=N.linewidth;if(k!=X)n.lineWidth=k=X;X=q.__styleString;if(e!=X)n.strokeStyle=e=X;n.stroke();da.inflate(N.linewidth*2)}}}}}else if(v instanceof THREE.RenderableFace3){h=
-v.v1;w=v.v2;s=v.v3;h.positionScreen.x*=J;h.positionScreen.y*=M;w.positionScreen.x*=J;w.positionScreen.y*=M;s.positionScreen.x*=J;s.positionScreen.y*=M;if(v.overdraw){c(h.positionScreen,w.positionScreen);c(w.positionScreen,s.positionScreen);c(s.positionScreen,h.positionScreen)}da.addPoint(h.positionScreen.x,h.positionScreen.y);da.addPoint(w.positionScreen.x,w.positionScreen.y);da.addPoint(s.positionScreen.x,s.positionScreen.y);if(ma.instersects(da)){K=0;for($=v.meshMaterial.length;K<$;){ba=v.meshMaterial[K++];
-if(ba instanceof THREE.MeshFaceMaterial){N=0;for(X=v.faceMaterial.length;N<X;)(ba=v.faceMaterial[N++])&&b(h,w,s,v,ba,I)}else b(h,w,s,v,ba,I)}}}ja.addRectangle(da)}n.lineWidth=1;n.strokeStyle="rgba( 255, 0, 0, 0.5 )";n.strokeRect(ja.getX(),ja.getY(),ja.getWidth(),ja.getHeight());n.setTransform(1,0,0,1,0,0)}};
-THREE.SVGRenderer=function(){function a(q,A,y){var P,D,C,W;P=0;for(D=q.lights.length;P<D;P++){C=q.lights[P];if(C instanceof THREE.DirectionalLight){W=A.normalWorld.dot(C.position)*C.intensity;if(W>0){y.r+=C.color.r*W;y.g+=C.color.g*W;y.b+=C.color.b*W}}else if(C instanceof THREE.PointLight){h.sub(C.position,A.centroidWorld);h.normalize();W=A.normalWorld.dot(h)*C.intensity;if(W>0){y.r+=C.color.r*W;y.g+=C.color.g*W;y.b+=C.color.b*W}}}}function b(q,A,y,P,D,C){u=i(T++);u.setAttribute("d","M "+q.positionScreen.x+
-" "+q.positionScreen.y+" L "+A.positionScreen.x+" "+A.positionScreen.y+" L "+y.positionScreen.x+","+y.positionScreen.y+"z");if(D instanceof THREE.MeshBasicMaterial)B.__styleString=D.color.__styleString;else if(D instanceof THREE.MeshLambertMaterial)if(S){e.r=f.r;e.g=f.g;e.b=f.b;a(C,P,e);B.r=D.color.r*e.r;B.g=D.color.g*e.g;B.b=D.color.b*e.b;B.updateStyleString()}else B.__styleString=D.color.__styleString;else if(D instanceof THREE.MeshDepthMaterial){g=1-D.__2near/(D.__farPlusNear-P.z*D.__farMinusNear);
-B.setRGB(g,g,g)}else D instanceof THREE.MeshNormalMaterial&&B.setRGB(j(P.normalWorld.x),j(P.normalWorld.y),j(P.normalWorld.z));D.wireframe?u.setAttribute("style","fill: none; stroke: "+B.__styleString+"; stroke-width: "+D.wireframe_linewidth+"; stroke-opacity: "+D.opacity+"; stroke-linecap: "+D.wireframe_linecap+"; stroke-linejoin: "+D.wireframe_linejoin):u.setAttribute("style","fill: "+B.__styleString+"; fill-opacity: "+D.opacity);r.appendChild(u)}function d(q,A,y,P,D,C,W){u=i(T++);u.setAttribute("d",
-"M "+q.positionScreen.x+" "+q.positionScreen.y+" L "+A.positionScreen.x+" "+A.positionScreen.y+" L "+y.positionScreen.x+","+y.positionScreen.y+" L "+P.positionScreen.x+","+P.positionScreen.y+"z");if(C instanceof THREE.MeshBasicMaterial)B.__styleString=C.color.__styleString;else if(C instanceof THREE.MeshLambertMaterial)if(S){e.r=f.r;e.g=f.g;e.b=f.b;a(W,D,e);B.r=C.color.r*e.r;B.g=C.color.g*e.g;B.b=C.color.b*e.b;B.updateStyleString()}else B.__styleString=C.color.__styleString;else if(C instanceof THREE.MeshDepthMaterial){g=
-1-C.__2near/(C.__farPlusNear-D.z*C.__farMinusNear);B.setRGB(g,g,g)}else C instanceof THREE.MeshNormalMaterial&&B.setRGB(j(D.normalWorld.x),j(D.normalWorld.y),j(D.normalWorld.z));C.wireframe?u.setAttribute("style","fill: none; stroke: "+B.__styleString+"; stroke-width: "+C.wireframe_linewidth+"; stroke-opacity: "+C.opacity+"; stroke-linecap: "+C.wireframe_linecap+"; stroke-linejoin: "+C.wireframe_linejoin):u.setAttribute("style","fill: "+B.__styleString+"; fill-opacity: "+C.opacity);r.appendChild(u)}
-function i(q){if(w[q]==null){w[q]=document.createElementNS("http://www.w3.org/2000/svg","path");H==0&&w[q].setAttribute("shape-rendering","crispEdges");return w[q]}return w[q]}function j(q){return q<0?Math.min((1+q)*0.5,0.5):0.5+Math.min(q*0.5,0.5)}var p=null,m=new THREE.Projector,r=document.createElementNS("http://www.w3.org/2000/svg","svg"),l,c,z,G,x,F,O,J,M=new THREE.Rectangle,n=new THREE.Rectangle,S=false,B=new THREE.Color(16777215),e=new THREE.Color(16777215),f=new THREE.Color(0),k=new THREE.Color(0),
-o=new THREE.Color(0),g,h=new THREE.Vector3,w=[],s=[],L=[],u,T,Q,t,H=1;this.domElement=r;this.autoClear=true;this.setQuality=function(q){switch(q){case "high":H=1;break;case "low":H=0}};this.setSize=function(q,A){l=q;c=A;z=l/2;G=c/2;r.setAttribute("viewBox",-z+" "+-G+" "+l+" "+c);r.setAttribute("width",l);r.setAttribute("height",c);M.set(-z,-G,z,G)};this.clear=function(){for(;r.childNodes.length>0;)r.removeChild(r.childNodes[0])};this.render=function(q,A){var y,P,D,C,W,ea,R,V;this.autoClear&&this.clear();
-p=m.projectScene(q,A);t=Q=T=0;if(S=q.lights.length>0){R=q.lights;f.setRGB(0,0,0);k.setRGB(0,0,0);o.setRGB(0,0,0);y=0;for(P=R.length;y<P;y++){D=R[y];C=D.color;if(D instanceof THREE.AmbientLight){f.r+=C.r;f.g+=C.g;f.b+=C.b}else if(D instanceof THREE.DirectionalLight){k.r+=C.r;k.g+=C.g;k.b+=C.b}else if(D instanceof THREE.PointLight){o.r+=C.r;o.g+=C.g;o.b+=C.b}}}y=0;for(P=p.length;y<P;y++){R=p[y];n.empty();if(R instanceof THREE.RenderableParticle){x=R;x.x*=z;x.y*=-G;D=0;for(C=R.material.length;D<C;D++)if(V=
-R.material[D]){W=x;ea=R;V=V;var ka=Q++;if(s[ka]==null){s[ka]=document.createElementNS("http://www.w3.org/2000/svg","circle");H==0&&s[ka].setAttribute("shape-rendering","crispEdges")}u=s[ka];u.setAttribute("cx",W.x);u.setAttribute("cy",W.y);u.setAttribute("r",ea.scale.x*z);if(V instanceof THREE.ParticleCircleMaterial){if(S){e.r=f.r+k.r+o.r;e.g=f.g+k.g+o.g;e.b=f.b+k.b+o.b;B.r=V.color.r*e.r;B.g=V.color.g*e.g;B.b=V.color.b*e.b;B.updateStyleString()}else B=V.color;u.setAttribute("style","fill: "+B.__styleString)}r.appendChild(u)}}else if(R instanceof
-THREE.RenderableLine){x=R.v1;F=R.v2;x.positionScreen.x*=z;x.positionScreen.y*=-G;F.positionScreen.x*=z;F.positionScreen.y*=-G;n.addPoint(x.positionScreen.x,x.positionScreen.y);n.addPoint(F.positionScreen.x,F.positionScreen.y);if(M.instersects(n)){D=0;for(C=R.material.length;D<C;)if(V=R.material[D++]){W=x;ea=F;V=V;ka=t++;if(L[ka]==null){L[ka]=document.createElementNS("http://www.w3.org/2000/svg","line");H==0&&L[ka].setAttribute("shape-rendering","crispEdges")}u=L[ka];u.setAttribute("x1",W.positionScreen.x);
-u.setAttribute("y1",W.positionScreen.y);u.setAttribute("x2",ea.positionScreen.x);u.setAttribute("y2",ea.positionScreen.y);if(V instanceof THREE.LineBasicMaterial){B.__styleString=V.color.__styleString;u.setAttribute("style","fill: none; stroke: "+B.__styleString+"; stroke-width: "+V.linewidth+"; stroke-opacity: "+V.opacity+"; stroke-linecap: "+V.linecap+"; stroke-linejoin: "+V.linejoin);r.appendChild(u)}}}}else if(R instanceof THREE.RenderableFace3){x=R.v1;F=R.v2;O=R.v3;x.positionScreen.x*=z;x.positionScreen.y*=
--G;F.positionScreen.x*=z;F.positionScreen.y*=-G;O.positionScreen.x*=z;O.positionScreen.y*=-G;n.addPoint(x.positionScreen.x,x.positionScreen.y);n.addPoint(F.positionScreen.x,F.positionScreen.y);n.addPoint(O.positionScreen.x,O.positionScreen.y);if(M.instersects(n)){D=0;for(C=R.meshMaterial.length;D<C;){V=R.meshMaterial[D++];if(V instanceof THREE.MeshFaceMaterial){W=0;for(ea=R.faceMaterial.length;W<ea;)(V=R.faceMaterial[W++])&&b(x,F,O,R,V,q)}else V&&b(x,F,O,R,V,q)}}}else if(R instanceof THREE.RenderableFace4){x=
-R.v1;F=R.v2;O=R.v3;J=R.v4;x.positionScreen.x*=z;x.positionScreen.y*=-G;F.positionScreen.x*=z;F.positionScreen.y*=-G;O.positionScreen.x*=z;O.positionScreen.y*=-G;J.positionScreen.x*=z;J.positionScreen.y*=-G;n.addPoint(x.positionScreen.x,x.positionScreen.y);n.addPoint(F.positionScreen.x,F.positionScreen.y);n.addPoint(O.positionScreen.x,O.positionScreen.y);n.addPoint(J.positionScreen.x,J.positionScreen.y);if(M.instersects(n)){D=0;for(C=R.meshMaterial.length;D<C;){V=R.meshMaterial[D++];if(V instanceof
-THREE.MeshFaceMaterial){W=0;for(ea=R.faceMaterial.length;W<ea;)(V=R.faceMaterial[W++])&&d(x,F,O,J,R,V,q)}else V&&d(x,F,O,J,R,V,q)}}}}}};
-THREE.WebGLRenderer=function(a){function b(e,f){var k=c.createProgram();c.attachShader(k,m("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\n"+e));c.attachShader(k,m("vertex","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"+f));c.linkProgram(k);c.getProgramParameter(k,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(k,
-c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");k.uniforms={};return k}function d(e,f){if(e instanceof THREE.TextureCube&&e.image.length==6){if(!e.image.__webGLTextureCube&&!e.image.__cubeMapInitialized&&e.image.loadCount==6){e.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,e.image.__webGLTextureCube);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,
-c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(var k=0;k<6;++k)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+k,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,e.image[k]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);e.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+f);c.bindTexture(c.TEXTURE_CUBE_MAP,e.image.__webGLTextureCube)}}function i(e,f){if(!e.__webGLTexture&&e.image.loaded){e.__webGLTexture=c.createTexture();
-c.bindTexture(c.TEXTURE_2D,e.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,e.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,r(e.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,r(e.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+f);c.bindTexture(c.TEXTURE_2D,e.__webGLTexture)}
-function j(e,f){var k,o,g;k=0;for(o=f.length;k<o;k++){g=f[k];e.uniforms[g]=c.getUniformLocation(e,g)}}function p(e){e.position=c.getAttribLocation(e,"position");c.enableVertexAttribArray(e.position);e.normal=c.getAttribLocation(e,"normal");c.enableVertexAttribArray(e.normal);e.uv=c.getAttribLocation(e,"uv");c.enableVertexAttribArray(e.uv)}function m(e,f){var k;if(e=="fragment")k=c.createShader(c.FRAGMENT_SHADER);else if(e=="vertex")k=c.createShader(c.VERTEX_SHADER);c.shaderSource(k,f);c.compileShader(k);
-if(!c.getShaderParameter(k,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(k));return null}return k}function r(e){switch(e){case THREE.Repeat:return c.REPEAT;case THREE.ClampToEdge:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeat:return c.MIRRORED_REPEAT}return 0}var l=document.createElement("canvas"),c,z,G,x=new THREE.Matrix4,F,O=new Float32Array(16),J=new Float32Array(16),M=new Float32Array(16),n=new Float32Array(9),S=new Float32Array(16);a=function(e,f){if(e){var k,o,g,h=pointLights=maxDirLights=maxPointLights=
-0;k=0;for(o=e.lights.length;k<o;k++){g=e.lights[k];g instanceof THREE.DirectionalLight&&h++;g instanceof THREE.PointLight&&pointLights++}if(pointLights+h<=f){maxDirLights=h;maxPointLights=pointLights}else{maxDirLights=Math.ceil(f*h/(pointLights+h));maxPointLights=f-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:f-1}}(a,4);this.domElement=l;this.autoClear=true;try{c=l.getContext("experimental-webgl",{antialias:true})}catch(B){}if(!c){alert("WebGL not supported");
-throw"cannot create webgl context";}c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK);c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(0,0,0,0);(function(e,f){var k=[e?"#define MAX_DIR_LIGHTS "+e:"",f?"#define MAX_POINT_LIGHTS "+f:"","uniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",
-e?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",e?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",f?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",f?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","uniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",f?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform float mRefractionRatio;\nvoid main(void) {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec3 transformedNormal = normalize( normalMatrix * normal );\nif ( !enableLighting ) {\nvLightWeighting = vec3( 1.0, 1.0, 1.0 );\n} else {\nvLightWeighting = ambientLightColor;",
-e?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",e?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",e?"float directionalLightWeighting = max( dot( transformedNormal, normalize(lDirection.xyz ) ), 0.0 );":"",e?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",e?"}":"",f?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",f?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",f?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
-"",f?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",f?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",f?"}":"","}\nvNormal = transformedNormal;\nvUv = uv;\nif ( useRefract ) {\nvReflect = refract( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz), mRefractionRatio );\n} else {\nvReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );\n}\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n"),
-o=[e?"#define MAX_DIR_LIGHTS "+e:"",f?"#define MAX_POINT_LIGHTS "+f:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\nuniform float m2Near;\nuniform float mFarPlusNear;\nuniform float mFarMinusNear;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
-e?"uniform mat4 viewMatrix;":"",e?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",f?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform vec3 cameraPosition;\nvoid main() {\nvec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nvec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nif ( enableMap ) {\nmapColor = texture2D( tMap, vUv );\n}\nif ( enableCubeMap ) {\ncubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\n}\nif ( material == 5 ) { \nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( -wPos.x, wPos.yz ) );\n} else if ( material == 4 ) { \ngl_FragColor = vec4( 0.5*normalize( vNormal ) + vec3(0.5, 0.5, 0.5), mOpacity );\n} else if ( material == 3 ) { \nfloat w = 0.5;\ngl_FragColor = vec4( w, w, w, mOpacity );\n} else if ( material == 2 ) { \nvec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );",
-f?"vec4 pointDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",f?"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",f?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",f?"vec3 pointVector = normalize( vPointLightVector[ i ] );":"",f?"vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );":"",f?"float pointDotNormalHalf = dot( normal, pointHalfVector );":"",f?"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );":"",f?"float pointSpecularWeight = 0.0;":"",f?"if ( pointDotNormalHalf >= 0.0 )":
-"",f?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",f?"pointDiffuse  += mColor * pointDiffuseWeight;":"",f?"pointSpecular += mSpecular * pointSpecularWeight;":"",f?"}":"",e?"vec4 dirDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",e?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",e?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",e?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",e?"vec3 dirVector = normalize( lDirection.xyz );":"",e?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
-"",e?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",e?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",e?"float dirSpecularWeight = 0.0;":"",e?"if ( dirDotNormalHalf >= 0.0 )":"",e?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",e?"dirDiffuse  += mColor * dirDiffuseWeight;":"",e?"dirSpecular += mSpecular * dirSpecularWeight;":"",e?"}":"","vec4 totalLight = mAmbient;",e?"totalLight += dirDiffuse + dirSpecular;":"",f?"totalLight += pointDiffuse + pointSpecular;":
+THREE.Projector=function(){function a(T,z){var f=0,k=1,e=T.z+T.w,n=z.z+z.w,h=-T.z+T.w,g=-z.z+z.w;if(e>=0&&n>=0&&h>=0&&g>=0)return true;else if(e<0&&n<0||h<0&&g<0)return false;else{if(e<0)f=Math.max(f,e/(e-n));else if(n<0)k=Math.min(k,e/(e-n));if(h<0)f=Math.max(f,h/(h-g));else if(g<0)k=Math.min(k,h/(h-g));if(k<f)return false;else{T.lerpSelf(z,f);z.lerpSelf(T,1-k);return true}}}var b=null,d,i,j,p=[],m,q,l=[],c,E,G=[],w=new THREE.Vector4,F=new THREE.Matrix4,P=new THREE.Matrix4,J=new THREE.Vector4,M=
+new THREE.Vector4,o;this.projectScene=function(T,z){var f,k,e,n,h,g,r,t,K,A,H,Q,u,O,s,y,x;b=[];j=q=E=0;z.autoUpdateMatrix&&z.updateMatrix();F.multiply(z.projectionMatrix,z.matrix);r=T.objects;f=0;for(k=r.length;f<k;f++){t=r[f];t.autoUpdateMatrix&&t.updateMatrix();K=t.matrix;A=t.rotationMatrix;H=t.material;Q=t.overdraw;if(t instanceof THREE.Mesh){u=t.geometry.vertices;e=0;for(n=u.length;e<n;e++){O=u[e];O.positionWorld.copy(O.position);K.multiplyVector3(O.positionWorld);s=O.positionScreen;s.copy(O.positionWorld);
+F.multiplyVector4(s);s.multiplyScalar(1/s.w);O.__visible=s.z>0&&s.z<1}O=t.geometry.faces;e=0;for(n=O.length;e<n;e++){s=O[e];if(s instanceof THREE.Face3){h=u[s.a];g=u[s.b];y=u[s.c];if(h.__visible&&g.__visible&&y.__visible)if(t.doubleSided||t.flipSided!=(y.positionScreen.x-h.positionScreen.x)*(g.positionScreen.y-h.positionScreen.y)-(y.positionScreen.y-h.positionScreen.y)*(g.positionScreen.x-h.positionScreen.x)<0){d=p[j]=p[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(h.positionWorld);d.v2.positionWorld.copy(g.positionWorld);
+d.v3.positionWorld.copy(y.positionWorld);d.v1.positionScreen.copy(h.positionScreen);d.v2.positionScreen.copy(g.positionScreen);d.v3.positionScreen.copy(y.positionScreen);d.normalWorld.copy(s.normal);A.multiplyVector3(d.normalWorld);d.centroidWorld.copy(s.centroid);K.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);F.multiplyVector3(d.centroidScreen);y=s.vertexNormals;o=d.vertexNormalsWorld;h=0;for(g=y.length;h<g;h++){x=o[h]=o[h]||new THREE.Vector3;x.copy(y[h]);A.multiplyVector3(x)}d.z=
+d.centroidScreen.z;d.meshMaterial=H;d.faceMaterial=s.material;d.overdraw=Q;if(t.geometry.uvs[e]){d.uvs[0]=t.geometry.uvs[e][0];d.uvs[1]=t.geometry.uvs[e][1];d.uvs[2]=t.geometry.uvs[e][2]}b.push(d);j++}}else if(s instanceof THREE.Face4){h=u[s.a];g=u[s.b];y=u[s.c];x=u[s.d];if(h.__visible&&g.__visible&&y.__visible&&x.__visible)if(t.doubleSided||t.flipSided!=((x.positionScreen.x-h.positionScreen.x)*(g.positionScreen.y-h.positionScreen.y)-(x.positionScreen.y-h.positionScreen.y)*(g.positionScreen.x-h.positionScreen.x)<
+0||(g.positionScreen.x-y.positionScreen.x)*(x.positionScreen.y-y.positionScreen.y)-(g.positionScreen.y-y.positionScreen.y)*(x.positionScreen.x-y.positionScreen.x)<0)){d=p[j]=p[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(h.positionWorld);d.v2.positionWorld.copy(g.positionWorld);d.v3.positionWorld.copy(x.positionWorld);d.v1.positionScreen.copy(h.positionScreen);d.v2.positionScreen.copy(g.positionScreen);d.v3.positionScreen.copy(x.positionScreen);d.normalWorld.copy(s.normal);A.multiplyVector3(d.normalWorld);
+d.centroidWorld.copy(s.centroid);K.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);F.multiplyVector3(d.centroidScreen);d.z=d.centroidScreen.z;d.meshMaterial=H;d.faceMaterial=s.material;d.overdraw=Q;if(t.geometry.uvs[e]){d.uvs[0]=t.geometry.uvs[e][0];d.uvs[1]=t.geometry.uvs[e][1];d.uvs[2]=t.geometry.uvs[e][3]}b.push(d);j++;i=p[j]=p[j]||new THREE.RenderableFace3;i.v1.positionWorld.copy(g.positionWorld);i.v2.positionWorld.copy(y.positionWorld);i.v3.positionWorld.copy(x.positionWorld);
+i.v1.positionScreen.copy(g.positionScreen);i.v2.positionScreen.copy(y.positionScreen);i.v3.positionScreen.copy(x.positionScreen);i.normalWorld.copy(d.normalWorld);i.centroidWorld.copy(d.centroidWorld);i.centroidScreen.copy(d.centroidScreen);i.z=i.centroidScreen.z;i.meshMaterial=H;i.faceMaterial=s.material;i.overdraw=Q;if(t.geometry.uvs[e]){i.uvs[0]=t.geometry.uvs[e][1];i.uvs[1]=t.geometry.uvs[e][2];i.uvs[2]=t.geometry.uvs[e][3]}b.push(i);j++}}}}else if(t instanceof THREE.Line){P.multiply(F,K);u=t.geometry.vertices;
+O=u[0];O.positionScreen.copy(O.position);P.multiplyVector4(O.positionScreen);e=1;for(n=u.length;e<n;e++){h=u[e];h.positionScreen.copy(h.position);P.multiplyVector4(h.positionScreen);g=u[e-1];J.copy(h.positionScreen);M.copy(g.positionScreen);if(a(J,M)){J.multiplyScalar(1/J.w);M.multiplyScalar(1/M.w);m=l[q]=l[q]||new THREE.RenderableLine;m.v1.positionScreen.copy(J);m.v2.positionScreen.copy(M);m.z=Math.max(J.z,M.z);m.material=t.material;b.push(m);q++}}}else if(t instanceof THREE.Particle){w.set(t.position.x,
+t.position.y,t.position.z,1);F.multiplyVector4(w);w.z/=w.w;if(w.z>0&&w.z<1){c=G[E]=G[E]||new THREE.RenderableParticle;c.x=w.x/w.w;c.y=w.y/w.w;c.z=w.z;c.rotation=t.rotation.z;c.scale.x=t.scale.x*Math.abs(c.x-(w.x+z.projectionMatrix.n11)/(w.w+z.projectionMatrix.n14));c.scale.y=t.scale.y*Math.abs(c.y-(w.y+z.projectionMatrix.n22)/(w.w+z.projectionMatrix.n24));c.material=t.material;b.push(c);E++}}}b.sort(function(R,C){return C.z-R.z});return b};this.unprojectVector=function(T,z){var f=new THREE.Matrix4;
+f.multiply(THREE.Matrix4.makeInvert(z.matrix),THREE.Matrix4.makeInvert(z.projectionMatrix));f.multiplyVector3(T);return T}};
+THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,d,i,j,p;this.domElement=document.createElement("div");this.setSize=function(m,q){d=m;i=q;j=d/2;p=i/2};this.render=function(m,q){var l,c,E,G,w,F,P,J;a=b.projectScene(m,q);l=0;for(c=a.length;l<c;l++){w=a[l];if(w instanceof THREE.RenderableParticle){P=w.x*j+j;J=w.y*p+p;E=0;for(G=w.material.length;E<G;E++){F=w.material[E];if(F instanceof THREE.ParticleDOMMaterial){F=F.domElement;F.style.left=P+"px";F.style.top=J+"px"}}}}}};
+THREE.CanvasRenderer=function(){function a(I,Y,U,D){var v,L,$,N,X=I.lights;I=0;for(v=X.length;I<v;I++){L=X[I];$=L.color;N=L.intensity;if(L instanceof THREE.DirectionalLight){L=U.dot(L.position)*N;if(L>0){D.r+=$.r*L;D.g+=$.g*L;D.b+=$.b*L}}else if(L instanceof THREE.PointLight){aa.sub(L.position,Y);aa.normalize();L=U.dot(aa)*N;if(L>0){D.r+=$.r*L;D.g+=$.g*L;D.b+=$.b*L}}}}function b(I,Y,U,D,v,L){if(v.opacity!=0){p(v.opacity);m(v.blending);K=I.positionScreen.x;A=I.positionScreen.y;H=Y.positionScreen.x;
+Q=Y.positionScreen.y;u=U.positionScreen.x;O=U.positionScreen.y;var $=K,N=A,X=H,ba=Q,Z=u,ca=O;o.beginPath();o.moveTo($,N);o.lineTo(X,ba);o.lineTo(Z,ca);o.lineTo($,N);o.closePath();if(v instanceof THREE.MeshBasicMaterial)if(v.map&&v.map.loaded)j(K,A,H,Q,u,O,v.map.image,D.uvs[0].u,D.uvs[0].v,D.uvs[1].u,D.uvs[1].v,D.uvs[2].u,D.uvs[2].v);else if(v.env_map&&v.env_map.loaded){if(v.env_map.mapping==THREE.ReflectionMapping){aa.copy(D.vertexNormalsWorld[0]);V=(aa.x*camera.matrix.n11+aa.y*camera.matrix.n12+
+aa.z*camera.matrix.n13)*0.5+0.5;ka=-(aa.x*camera.matrix.n21+aa.y*camera.matrix.n22+aa.z*camera.matrix.n23)*0.5+0.5;aa.copy(D.vertexNormalsWorld[1]);za=(aa.x*camera.matrix.n11+aa.y*camera.matrix.n12+aa.z*camera.matrix.n13)*0.5+0.5;Aa=-(aa.x*camera.matrix.n21+aa.y*camera.matrix.n22+aa.z*camera.matrix.n23)*0.5+0.5;aa.copy(D.vertexNormalsWorld[2]);Ba=(aa.x*camera.matrix.n11+aa.y*camera.matrix.n12+aa.z*camera.matrix.n13)*0.5+0.5;Ca=-(aa.x*camera.matrix.n21+aa.y*camera.matrix.n22+aa.z*camera.matrix.n23)*
+0.5+0.5;j(K,A,H,Q,u,O,v.env_map.image,V,ka,za,Aa,Ba,Ca)}}else v.wireframe?d(v.color.__styleString,v.wireframe_linewidth):i(v.color.__styleString);else if(v instanceof THREE.MeshLambertMaterial){if(v.map&&!v.wireframe){j(K,A,H,Q,u,O,v.map.image,D.uvs[0].u,D.uvs[0].v,D.uvs[1].u,D.uvs[1].v,D.uvs[2].u,D.uvs[2].v);m(THREE.SubtractiveBlending)}if(va)if(!v.wireframe&&v.shading==THREE.SmoothShading&&D.vertexNormalsWorld.length==3){y.r=x.r=R.r=ga.r;y.g=x.g=R.g=ga.g;y.b=x.b=R.b=ga.b;a(L,D.v1.positionWorld,
+D.vertexNormalsWorld[0],y);a(L,D.v2.positionWorld,D.vertexNormalsWorld[1],x);a(L,D.v3.positionWorld,D.vertexNormalsWorld[2],R);C.r=(x.r+R.r)*0.5;C.g=(x.g+R.g)*0.5;C.b=(x.b+R.b)*0.5;S=q(y,x,R,C);j(K,A,H,Q,u,O,S,0,0,1,0,0,1)}else{ha.r=ga.r;ha.g=ga.g;ha.b=ga.b;a(L,D.centroidWorld,D.normalWorld,ha);s.r=v.color.r*ha.r;s.g=v.color.g*ha.g;s.b=v.color.b*ha.b;s.updateStyleString();v.wireframe?d(s.__styleString,v.wireframe_linewidth):i(s.__styleString)}else v.wireframe?d(v.color.__styleString,v.wireframe_linewidth):
+i(v.color.__styleString)}else if(v instanceof THREE.MeshDepthMaterial){B=v.__2near;W=v.__farPlusNear;ea=v.__farMinusNear;y.r=y.g=y.b=1-B/(W-I.positionScreen.z*ea);x.r=x.g=x.b=1-B/(W-Y.positionScreen.z*ea);R.r=R.g=R.b=1-B/(W-U.positionScreen.z*ea);C.r=(x.r+R.r)*0.5;C.g=(x.g+R.g)*0.5;C.b=(x.b+R.b)*0.5;S=q(y,x,R,C);j(K,A,H,Q,u,O,S,0,0,1,0,0,1)}else if(v instanceof THREE.MeshNormalMaterial){s.r=l(D.normalWorld.x);s.g=l(D.normalWorld.y);s.b=l(D.normalWorld.z);s.updateStyleString();v.wireframe?d(s.__styleString,
+v.wireframe_linewidth):i(s.__styleString)}}}function d(I,Y){if(f!=I)o.strokeStyle=f=I;if(e!=Y)o.lineWidth=e=Y;o.stroke();da.inflate(Y*2)}function i(I){if(k!=I)o.fillStyle=k=I;o.fill()}function j(I,Y,U,D,v,L,$,N,X,ba,Z,ca,na){var la,fa;la=$.width-1;fa=$.height-1;N*=la;X*=fa;ba*=la;Z*=fa;ca*=la;na*=fa;U-=I;D-=Y;v-=I;L-=Y;ba-=N;Z-=X;ca-=N;na-=X;fa=1/(ba*na-ca*Z);la=(na*U-Z*v)*fa;Z=(na*D-Z*L)*fa;U=(ba*v-ca*U)*fa;D=(ba*L-ca*D)*fa;I=I-la*N-U*X;Y=Y-Z*N-D*X;o.save();o.transform(la,Z,U,D,I,Y);o.clip();o.drawImage($,
+0,0);o.restore()}function p(I){if(T!=I)o.globalAlpha=T=I}function m(I){if(z!=I){switch(I){case THREE.NormalBlending:o.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:o.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:o.globalCompositeOperation="darker"}z=I}}function q(I,Y,U,D){ia[0]=h(0,n(255,~~(I.r*255)));ia[1]=h(0,n(255,~~(I.g*255)));ia[2]=h(0,n(255,~~(I.b*255)));ia[4]=h(0,n(255,~~(Y.r*255)));ia[5]=h(0,n(255,~~(Y.g*255)));ia[6]=h(0,n(255,~~(Y.b*255)));
+ia[8]=h(0,n(255,~~(U.r*255)));ia[9]=h(0,n(255,~~(U.g*255)));ia[10]=h(0,n(255,~~(U.b*255)));ia[12]=h(0,n(255,~~(D.r*255)));ia[13]=h(0,n(255,~~(D.g*255)));ia[14]=h(0,n(255,~~(D.b*255)));ra.putImageData(wa,0,0);ua.drawImage(sa,0,0);return ta}function l(I){return I<0?n((1+I)*0.5,0.5):0.5+n(I*0.5,0.5)}function c(I,Y){var U=Y.x-I.x,D=Y.y-I.y,v=1/Math.sqrt(U*U+D*D);U*=v;D*=v;Y.x+=U;Y.y+=D;I.x-=U;I.y-=D}var E=null,G=new THREE.Projector,w=document.createElement("canvas"),F,P,J,M,o=w.getContext("2d"),T=1,z=
+0,f=null,k=null,e=1,n=Math.min,h=Math.max,g,r,t,K,A,H,Q,u,O,s=new THREE.Color,y=new THREE.Color,x=new THREE.Color,R=new THREE.Color,C=new THREE.Color,B,W,ea,S,V,ka,za,Aa,Ba,Ca,ma=new THREE.Rectangle,ja=new THREE.Rectangle,da=new THREE.Rectangle,va=false,ha=new THREE.Color,ga=new THREE.Color,oa=new THREE.Color,pa=new THREE.Color,Da=Math.PI*2,aa=new THREE.Vector3,sa,ra,wa,ia,ta,ua,qa=16;sa=document.createElement("canvas");sa.width=sa.height=2;ra=sa.getContext("2d");ra.fillStyle="rgba(0,0,0,1)";ra.fillRect(0,
+0,2,2);wa=ra.getImageData(0,0,2,2);ia=wa.data;ta=document.createElement("canvas");ta.width=ta.height=qa;ua=ta.getContext("2d");ua.translate(-qa/2,-qa/2);ua.scale(qa,qa);qa--;this.domElement=w;this.autoClear=true;this.setSize=function(I,Y){F=I;P=Y;J=F/2;M=P/2;w.width=F;w.height=P;ma.set(-J,-M,J,M)};this.clear=function(){if(!ja.isEmpty()){ja.inflate(1);ja.minSelf(ma);o.clearRect(ja.getX(),ja.getY(),ja.getWidth(),ja.getHeight());ja.empty()}};this.render=function(I,Y){var U,D,v,L,$,N,X,ba;o.setTransform(1,
+0,0,-1,J,M);this.autoClear&&this.clear();E=G.projectScene(I,Y);o.fillStyle="rgba(0, 255, 255, 0.5)";o.fillRect(ma.getX(),ma.getY(),ma.getWidth(),ma.getHeight());if(va=I.lights.length>0){$=I.lights;ga.setRGB(0,0,0);oa.setRGB(0,0,0);pa.setRGB(0,0,0);U=0;for(D=$.length;U<D;U++){v=$[U];L=v.color;if(v instanceof THREE.AmbientLight){ga.r+=L.r;ga.g+=L.g;ga.b+=L.b}else if(v instanceof THREE.DirectionalLight){oa.r+=L.r;oa.g+=L.g;oa.b+=L.b}else if(v instanceof THREE.PointLight){pa.r+=L.r;pa.g+=L.g;pa.b+=L.b}}}U=
+0;for(D=E.length;U<D;U++){v=E[U];da.empty();if(v instanceof THREE.RenderableParticle){g=v;g.x*=J;g.y*=M;L=0;for($=v.material.length;L<$;L++)a:{N=g;X=v;var Z=v.material[L];if(Z.opacity!=0){p(Z.opacity);m(Z.blending);ba=void 0;var ca=void 0,na=void 0,la=void 0,fa=void 0,xa=void 0,ya=void 0;if(Z instanceof THREE.ParticleBasicMaterial){if(Z.map){fa=Z.map;xa=fa.width>>1;ya=fa.height>>1;na=X.scale.x*J;la=X.scale.y*M;ba=na*xa;ca=la*ya;da.set(N.x-ba,N.y-ca,N.x+ba,N.y+ca);if(!ma.instersects(da))break a;o.save();
+o.translate(N.x,N.y);o.rotate(-X.rotation);o.scale(na,-la);o.translate(-xa,-ya);o.drawImage(fa,0,0);o.restore()}o.beginPath();o.moveTo(N.x-10,N.y);o.lineTo(N.x+10,N.y);o.moveTo(N.x,N.y-10);o.lineTo(N.x,N.y+10);o.closePath();o.strokeStyle="rgb(255,255,0)";o.stroke()}else if(Z instanceof THREE.ParticleCircleMaterial){if(va){ha.r=ga.r+oa.r+pa.r;ha.g=ga.g+oa.g+pa.g;ha.b=ga.b+oa.b+pa.b;s.r=Z.color.r*ha.r;s.g=Z.color.g*ha.g;s.b=Z.color.b*ha.b;s.updateStyleString()}else s.__styleString=Z.color.__styleString;
+ba=X.scale.x*J;ca=X.scale.y*M;da.set(N.x-ba,N.y-ca,N.x+ba,N.y+ca);if(ma.instersects(da)){Z=s.__styleString;if(k!=Z)o.fillStyle=k=Z;o.save();o.translate(N.x,N.y);o.rotate(-X.rotation);o.scale(ba,ca);o.beginPath();o.arc(0,0,1,0,Da,true);o.closePath();o.fill();o.restore()}}}}}else if(v instanceof THREE.RenderableLine){g=v.v1;r=v.v2;g.positionScreen.x*=J;g.positionScreen.y*=M;r.positionScreen.x*=J;r.positionScreen.y*=M;da.addPoint(g.positionScreen.x,g.positionScreen.y);da.addPoint(r.positionScreen.x,
+r.positionScreen.y);if(ma.instersects(da)){L=0;for($=v.material.length;L<$;){X=g;ba=r;N=v.material[L++];if(N.opacity!=0){p(N.opacity);m(N.blending);o.beginPath();o.moveTo(X.positionScreen.x,X.positionScreen.y);o.lineTo(ba.positionScreen.x,ba.positionScreen.y);o.closePath();if(N instanceof THREE.LineBasicMaterial){s.__styleString=N.color.__styleString;X=N.linewidth;if(e!=X)o.lineWidth=e=X;X=s.__styleString;if(f!=X)o.strokeStyle=f=X;o.stroke();da.inflate(N.linewidth*2)}}}}}else if(v instanceof THREE.RenderableFace3){g=
+v.v1;r=v.v2;t=v.v3;g.positionScreen.x*=J;g.positionScreen.y*=M;r.positionScreen.x*=J;r.positionScreen.y*=M;t.positionScreen.x*=J;t.positionScreen.y*=M;if(v.overdraw){c(g.positionScreen,r.positionScreen);c(r.positionScreen,t.positionScreen);c(t.positionScreen,g.positionScreen)}da.addPoint(g.positionScreen.x,g.positionScreen.y);da.addPoint(r.positionScreen.x,r.positionScreen.y);da.addPoint(t.positionScreen.x,t.positionScreen.y);if(ma.instersects(da)){L=0;for($=v.meshMaterial.length;L<$;){ba=v.meshMaterial[L++];
+if(ba instanceof THREE.MeshFaceMaterial){N=0;for(X=v.faceMaterial.length;N<X;)(ba=v.faceMaterial[N++])&&b(g,r,t,v,ba,I)}else b(g,r,t,v,ba,I)}}}ja.addRectangle(da)}o.lineWidth=1;o.strokeStyle="rgba( 255, 0, 0, 0.5 )";o.strokeRect(ja.getX(),ja.getY(),ja.getWidth(),ja.getHeight());o.setTransform(1,0,0,1,0,0)}};
+THREE.SVGRenderer=function(){function a(s,y,x){var R,C,B,W;R=0;for(C=s.lights.length;R<C;R++){B=s.lights[R];if(B instanceof THREE.DirectionalLight){W=y.normalWorld.dot(B.position)*B.intensity;if(W>0){x.r+=B.color.r*W;x.g+=B.color.g*W;x.b+=B.color.b*W}}else if(B instanceof THREE.PointLight){g.sub(B.position,y.centroidWorld);g.normalize();W=y.normalWorld.dot(g)*B.intensity;if(W>0){x.r+=B.color.r*W;x.g+=B.color.g*W;x.b+=B.color.b*W}}}}function b(s,y,x,R,C,B){A=i(H++);A.setAttribute("d","M "+s.positionScreen.x+
+" "+s.positionScreen.y+" L "+y.positionScreen.x+" "+y.positionScreen.y+" L "+x.positionScreen.x+","+x.positionScreen.y+"z");if(C instanceof THREE.MeshBasicMaterial)z.__styleString=C.color.__styleString;else if(C instanceof THREE.MeshLambertMaterial)if(T){f.r=k.r;f.g=k.g;f.b=k.b;a(B,R,f);z.r=C.color.r*f.r;z.g=C.color.g*f.g;z.b=C.color.b*f.b;z.updateStyleString()}else z.__styleString=C.color.__styleString;else if(C instanceof THREE.MeshDepthMaterial){h=1-C.__2near/(C.__farPlusNear-R.z*C.__farMinusNear);
+z.setRGB(h,h,h)}else C instanceof THREE.MeshNormalMaterial&&z.setRGB(j(R.normalWorld.x),j(R.normalWorld.y),j(R.normalWorld.z));C.wireframe?A.setAttribute("style","fill: none; stroke: "+z.__styleString+"; stroke-width: "+C.wireframe_linewidth+"; stroke-opacity: "+C.opacity+"; stroke-linecap: "+C.wireframe_linecap+"; stroke-linejoin: "+C.wireframe_linejoin):A.setAttribute("style","fill: "+z.__styleString+"; fill-opacity: "+C.opacity);q.appendChild(A)}function d(s,y,x,R,C,B,W){A=i(H++);A.setAttribute("d",
+"M "+s.positionScreen.x+" "+s.positionScreen.y+" L "+y.positionScreen.x+" "+y.positionScreen.y+" L "+x.positionScreen.x+","+x.positionScreen.y+" L "+R.positionScreen.x+","+R.positionScreen.y+"z");if(B instanceof THREE.MeshBasicMaterial)z.__styleString=B.color.__styleString;else if(B instanceof THREE.MeshLambertMaterial)if(T){f.r=k.r;f.g=k.g;f.b=k.b;a(W,C,f);z.r=B.color.r*f.r;z.g=B.color.g*f.g;z.b=B.color.b*f.b;z.updateStyleString()}else z.__styleString=B.color.__styleString;else if(B instanceof THREE.MeshDepthMaterial){h=
+1-B.__2near/(B.__farPlusNear-C.z*B.__farMinusNear);z.setRGB(h,h,h)}else B instanceof THREE.MeshNormalMaterial&&z.setRGB(j(C.normalWorld.x),j(C.normalWorld.y),j(C.normalWorld.z));B.wireframe?A.setAttribute("style","fill: none; stroke: "+z.__styleString+"; stroke-width: "+B.wireframe_linewidth+"; stroke-opacity: "+B.opacity+"; stroke-linecap: "+B.wireframe_linecap+"; stroke-linejoin: "+B.wireframe_linejoin):A.setAttribute("style","fill: "+z.__styleString+"; fill-opacity: "+B.opacity);q.appendChild(A)}
+function i(s){if(r[s]==null){r[s]=document.createElementNS("http://www.w3.org/2000/svg","path");O==0&&r[s].setAttribute("shape-rendering","crispEdges");return r[s]}return r[s]}function j(s){return s<0?Math.min((1+s)*0.5,0.5):0.5+Math.min(s*0.5,0.5)}var p=null,m=new THREE.Projector,q=document.createElementNS("http://www.w3.org/2000/svg","svg"),l,c,E,G,w,F,P,J,M=new THREE.Rectangle,o=new THREE.Rectangle,T=false,z=new THREE.Color(16777215),f=new THREE.Color(16777215),k=new THREE.Color(0),e=new THREE.Color(0),
+n=new THREE.Color(0),h,g=new THREE.Vector3,r=[],t=[],K=[],A,H,Q,u,O=1;this.domElement=q;this.autoClear=true;this.setQuality=function(s){switch(s){case "high":O=1;break;case "low":O=0}};this.setSize=function(s,y){l=s;c=y;E=l/2;G=c/2;q.setAttribute("viewBox",-E+" "+-G+" "+l+" "+c);q.setAttribute("width",l);q.setAttribute("height",c);M.set(-E,-G,E,G)};this.clear=function(){for(;q.childNodes.length>0;)q.removeChild(q.childNodes[0])};this.render=function(s,y){var x,R,C,B,W,ea,S,V;this.autoClear&&this.clear();
+p=m.projectScene(s,y);u=Q=H=0;if(T=s.lights.length>0){S=s.lights;k.setRGB(0,0,0);e.setRGB(0,0,0);n.setRGB(0,0,0);x=0;for(R=S.length;x<R;x++){C=S[x];B=C.color;if(C instanceof THREE.AmbientLight){k.r+=B.r;k.g+=B.g;k.b+=B.b}else if(C instanceof THREE.DirectionalLight){e.r+=B.r;e.g+=B.g;e.b+=B.b}else if(C instanceof THREE.PointLight){n.r+=B.r;n.g+=B.g;n.b+=B.b}}}x=0;for(R=p.length;x<R;x++){S=p[x];o.empty();if(S instanceof THREE.RenderableParticle){w=S;w.x*=E;w.y*=-G;C=0;for(B=S.material.length;C<B;C++)if(V=
+S.material[C]){W=w;ea=S;V=V;var ka=Q++;if(t[ka]==null){t[ka]=document.createElementNS("http://www.w3.org/2000/svg","circle");O==0&&t[ka].setAttribute("shape-rendering","crispEdges")}A=t[ka];A.setAttribute("cx",W.x);A.setAttribute("cy",W.y);A.setAttribute("r",ea.scale.x*E);if(V instanceof THREE.ParticleCircleMaterial){if(T){f.r=k.r+e.r+n.r;f.g=k.g+e.g+n.g;f.b=k.b+e.b+n.b;z.r=V.color.r*f.r;z.g=V.color.g*f.g;z.b=V.color.b*f.b;z.updateStyleString()}else z=V.color;A.setAttribute("style","fill: "+z.__styleString)}q.appendChild(A)}}else if(S instanceof
+THREE.RenderableLine){w=S.v1;F=S.v2;w.positionScreen.x*=E;w.positionScreen.y*=-G;F.positionScreen.x*=E;F.positionScreen.y*=-G;o.addPoint(w.positionScreen.x,w.positionScreen.y);o.addPoint(F.positionScreen.x,F.positionScreen.y);if(M.instersects(o)){C=0;for(B=S.material.length;C<B;)if(V=S.material[C++]){W=w;ea=F;V=V;ka=u++;if(K[ka]==null){K[ka]=document.createElementNS("http://www.w3.org/2000/svg","line");O==0&&K[ka].setAttribute("shape-rendering","crispEdges")}A=K[ka];A.setAttribute("x1",W.positionScreen.x);
+A.setAttribute("y1",W.positionScreen.y);A.setAttribute("x2",ea.positionScreen.x);A.setAttribute("y2",ea.positionScreen.y);if(V instanceof THREE.LineBasicMaterial){z.__styleString=V.color.__styleString;A.setAttribute("style","fill: none; stroke: "+z.__styleString+"; stroke-width: "+V.linewidth+"; stroke-opacity: "+V.opacity+"; stroke-linecap: "+V.linecap+"; stroke-linejoin: "+V.linejoin);q.appendChild(A)}}}}else if(S instanceof THREE.RenderableFace3){w=S.v1;F=S.v2;P=S.v3;w.positionScreen.x*=E;w.positionScreen.y*=
+-G;F.positionScreen.x*=E;F.positionScreen.y*=-G;P.positionScreen.x*=E;P.positionScreen.y*=-G;o.addPoint(w.positionScreen.x,w.positionScreen.y);o.addPoint(F.positionScreen.x,F.positionScreen.y);o.addPoint(P.positionScreen.x,P.positionScreen.y);if(M.instersects(o)){C=0;for(B=S.meshMaterial.length;C<B;){V=S.meshMaterial[C++];if(V instanceof THREE.MeshFaceMaterial){W=0;for(ea=S.faceMaterial.length;W<ea;)(V=S.faceMaterial[W++])&&b(w,F,P,S,V,s)}else V&&b(w,F,P,S,V,s)}}}else if(S instanceof THREE.RenderableFace4){w=
+S.v1;F=S.v2;P=S.v3;J=S.v4;w.positionScreen.x*=E;w.positionScreen.y*=-G;F.positionScreen.x*=E;F.positionScreen.y*=-G;P.positionScreen.x*=E;P.positionScreen.y*=-G;J.positionScreen.x*=E;J.positionScreen.y*=-G;o.addPoint(w.positionScreen.x,w.positionScreen.y);o.addPoint(F.positionScreen.x,F.positionScreen.y);o.addPoint(P.positionScreen.x,P.positionScreen.y);o.addPoint(J.positionScreen.x,J.positionScreen.y);if(M.instersects(o)){C=0;for(B=S.meshMaterial.length;C<B;){V=S.meshMaterial[C++];if(V instanceof
+THREE.MeshFaceMaterial){W=0;for(ea=S.faceMaterial.length;W<ea;)(V=S.faceMaterial[W++])&&d(w,F,P,J,S,V,s)}else V&&d(w,F,P,J,S,V,s)}}}}}};
+THREE.WebGLRenderer=function(a){function b(f,k){var e=c.createProgram();c.attachShader(e,m("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\n"+f));c.attachShader(e,m("vertex","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"+k));c.linkProgram(e);c.getProgramParameter(e,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(e,
+c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");e.uniforms={};e.attributes={};return e}function d(f,k){if(f instanceof THREE.TextureCube&&f.image.length==6){if(!f.image.__webGLTextureCube&&!f.image.__cubeMapInitialized&&f.image.loadCount==6){f.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,f.image.__webGLTextureCube);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,
+c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(var e=0;e<6;++e)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,f.image[e]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);f.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+k);c.bindTexture(c.TEXTURE_CUBE_MAP,f.image.__webGLTextureCube)}}function i(f,k){if(!f.__webGLTexture&&f.image.loaded){f.__webGLTexture=c.createTexture();
+c.bindTexture(c.TEXTURE_2D,f.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,f.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,q(f.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,q(f.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+k);c.bindTexture(c.TEXTURE_2D,f.__webGLTexture)}
+function j(f,k){var e,n,h;e=0;for(n=k.length;e<n;e++){h=k[e];f.uniforms[h]=c.getUniformLocation(f,h)}}function p(f,k){var e,n,h;e=0;for(n=k.length;e<n;e++){h=k[e];f.attributes[h]=c.getAttribLocation(f,h);f.attributes[h]>=0&&c.enableVertexAttribArray(f.attributes[h])}}function m(f,k){var e;if(f=="fragment")e=c.createShader(c.FRAGMENT_SHADER);else if(f=="vertex")e=c.createShader(c.VERTEX_SHADER);c.shaderSource(e,k);c.compileShader(e);if(!c.getShaderParameter(e,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(e));
+return null}return e}function q(f){switch(f){case THREE.Repeat:return c.REPEAT;case THREE.ClampToEdge:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeat:return c.MIRRORED_REPEAT}return 0}var l=document.createElement("canvas"),c,E,G,w=new THREE.Matrix4,F,P=new Float32Array(16),J=new Float32Array(16),M=new Float32Array(16),o=new Float32Array(9),T=new Float32Array(16);a=function(f,k){if(f){var e,n,h,g=pointLights=maxDirLights=maxPointLights=0;e=0;for(n=f.lights.length;e<n;e++){h=f.lights[e];h instanceof
+THREE.DirectionalLight&&g++;h instanceof THREE.PointLight&&pointLights++}if(pointLights+g<=k){maxDirLights=g;maxPointLights=pointLights}else{maxDirLights=Math.ceil(k*g/(pointLights+g));maxPointLights=k-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:k-1}}(a,4);this.domElement=l;this.autoClear=true;try{c=l.getContext("experimental-webgl",{antialias:true})}catch(z){}if(!c){alert("WebGL not supported");throw"cannot create webgl context";}c.clearColor(0,0,
+0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK);c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(0,0,0,0);E=G=function(f,k){var e=[f?"#define MAX_DIR_LIGHTS "+f:"",k?"#define MAX_POINT_LIGHTS "+k:"","uniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",f?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":
+"",f?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",k?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",k?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","uniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",k?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform float mRefractionRatio;\nvoid main(void) {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec3 transformedNormal = normalize( normalMatrix * normal );\nif ( !enableLighting ) {\nvLightWeighting = vec3( 1.0, 1.0, 1.0 );\n} else {\nvLightWeighting = ambientLightColor;",
+f?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",f?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",f?"float directionalLightWeighting = max( dot( transformedNormal, normalize(lDirection.xyz ) ), 0.0 );":"",f?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",f?"}":"",k?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",k?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",k?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
+"",k?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",k?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",k?"}":"","}\nvNormal = transformedNormal;\nvUv = uv;\nif ( useRefract ) {\nvReflect = refract( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz), mRefractionRatio );\n} else {\nvReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );\n}\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n"),
+n=[f?"#define MAX_DIR_LIGHTS "+f:"",k?"#define MAX_POINT_LIGHTS "+k:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\nuniform float m2Near;\nuniform float mFarPlusNear;\nuniform float mFarMinusNear;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
+f?"uniform mat4 viewMatrix;":"",f?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",k?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform vec3 cameraPosition;\nvoid main() {\nvec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nvec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nif ( enableMap ) {\nmapColor = texture2D( tMap, vUv );\n}\nif ( enableCubeMap ) {\ncubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\n}\nif ( material == 5 ) { \nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( -wPos.x, wPos.yz ) );\n} else if ( material == 4 ) { \ngl_FragColor = vec4( 0.5*normalize( vNormal ) + vec3(0.5, 0.5, 0.5), mOpacity );\n} else if ( material == 3 ) { \nfloat w = 0.5;\ngl_FragColor = vec4( w, w, w, mOpacity );\n} else if ( material == 2 ) { \nvec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );",
+k?"vec4 pointDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",k?"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",k?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",k?"vec3 pointVector = normalize( vPointLightVector[ i ] );":"",k?"vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );":"",k?"float pointDotNormalHalf = dot( normal, pointHalfVector );":"",k?"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );":"",k?"float pointSpecularWeight = 0.0;":"",k?"if ( pointDotNormalHalf >= 0.0 )":
+"",k?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",k?"pointDiffuse  += mColor * pointDiffuseWeight;":"",k?"pointSpecular += mSpecular * pointSpecularWeight;":"",k?"}":"",f?"vec4 dirDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",f?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",f?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",f?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",f?"vec3 dirVector = normalize( lDirection.xyz );":"",f?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
+"",f?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",f?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",f?"float dirSpecularWeight = 0.0;":"",f?"if ( dirDotNormalHalf >= 0.0 )":"",f?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",f?"dirDiffuse  += mColor * dirDiffuseWeight;":"",f?"dirSpecular += mSpecular * dirSpecularWeight;":"",f?"}":"","vec4 totalLight = mAmbient;",f?"totalLight += dirDiffuse + dirSpecular;":"",k?"totalLight += pointDiffuse + pointSpecular;":
 "","if ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mapColor.rgb * totalLight.xyz * vLightWeighting, cubeColor.rgb, mReflectivity ), mapColor.a );\n} else {\ngl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );\n}\n} else if ( material == 1 ) {\nif ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mColor.rgb * mapColor.rgb * vLightWeighting, cubeColor.rgb, mReflectivity ), mColor.a * mapColor.a );\n} else {\ngl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );\n}\n} else {\nif ( mixEnvMap ) {\ngl_FragColor = mix( mColor * mapColor, cubeColor, mReflectivity );\n} else {\ngl_FragColor = mColor * mapColor * cubeColor;\n}\n}\n}"].join("\n");
 "","if ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mapColor.rgb * totalLight.xyz * vLightWeighting, cubeColor.rgb, mReflectivity ), mapColor.a );\n} else {\ngl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );\n}\n} else if ( material == 1 ) {\nif ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mColor.rgb * mapColor.rgb * vLightWeighting, cubeColor.rgb, mReflectivity ), mColor.a * mapColor.a );\n} else {\ngl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );\n}\n} else {\nif ( mixEnvMap ) {\ngl_FragColor = mix( mColor * mapColor, cubeColor, mReflectivity );\n} else {\ngl_FragColor = mColor * mapColor * cubeColor;\n}\n}\n}"].join("\n");
-z=b(o,k);c.useProgram(z);j(z,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract","m2Near","mFarPlusNear","mFarMinusNear"]);e&&j(z,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);f&&j(z,["pointLightNumber","pointLightColor",
-"pointLightPosition"]);c.uniform1i(z.uniforms.enableMap,0);c.uniform1i(z.uniforms.tMap,0);c.uniform1i(z.uniforms.enableCubeMap,0);c.uniform1i(z.uniforms.tCube,1);c.uniform1i(z.uniforms.mixEnvMap,0);c.uniform1i(z.uniforms.useRefract,0);p(z)})(a.directional,a.point);this.setSize=function(e,f){l.width=e;l.height=f;c.viewport(0,0,l.width,l.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(e,f){var k,o,g,h,w,s=[],L=[],u=[];h=[];w=[];c.uniform1i(e.uniforms.enableLighting,
-f.lights.length);k=0;for(o=f.lights.length;k<o;k++){g=f.lights[k];if(g instanceof THREE.AmbientLight)s.push(g);else if(g instanceof THREE.DirectionalLight)u.push(g);else g instanceof THREE.PointLight&&L.push(g)}k=g=h=w=0;for(o=s.length;k<o;k++){g+=s[k].color.r;h+=s[k].color.g;w+=s[k].color.b}c.uniform3f(e.uniforms.ambientLightColor,g,h,w);h=[];w=[];k=0;for(o=u.length;k<o;k++){g=u[k];h.push(g.color.r*g.intensity);h.push(g.color.g*g.intensity);h.push(g.color.b*g.intensity);w.push(g.position.x);w.push(g.position.y);
-w.push(g.position.z)}if(u.length){c.uniform1i(e.uniforms.directionalLightNumber,u.length);c.uniform3fv(e.uniforms.directionalLightDirection,w);c.uniform3fv(e.uniforms.directionalLightColor,h)}h=[];w=[];k=0;for(o=L.length;k<o;k++){g=L[k];h.push(g.color.r*g.intensity);h.push(g.color.g*g.intensity);h.push(g.color.b*g.intensity);w.push(g.position.x);w.push(g.position.y);w.push(g.position.z)}if(L.length){c.uniform1i(e.uniforms.pointLightNumber,L.length);c.uniform3fv(e.uniforms.pointLightPosition,w);c.uniform3fv(e.uniforms.pointLightColor,
-h)}};this.createBuffers=function(e,f){var k,o,g,h,w,s,L,u,T=[],Q=[],t=[],H=[],q=[],A=0,y=e.geometry.geometryChunks[f],P;g=false;k=0;for(o=e.material.length;k<o;k++){meshMaterial=e.material[k];if(meshMaterial instanceof THREE.MeshFaceMaterial){w=0;for(P=y.material.length;w<P;w++)if(y.material[w]&&y.material[w].shading!=undefined&&y.material[w].shading==THREE.SmoothShading){g=true;break}}else if(meshMaterial&&meshMaterial.shading!=undefined&&meshMaterial.shading==THREE.SmoothShading){g=true;break}if(g)break}P=
-g;k=0;for(o=y.faces.length;k<o;k++){g=y.faces[k];h=e.geometry.faces[g];w=h.vertexNormals;faceNormal=h.normal;g=e.geometry.uvs[g];if(h instanceof THREE.Face3){s=e.geometry.vertices[h.a].position;L=e.geometry.vertices[h.b].position;u=e.geometry.vertices[h.c].position;t.push(s.x,s.y,s.z);t.push(L.x,L.y,L.z);t.push(u.x,u.y,u.z);if(w.length==3&&P)for(h=0;h<3;h++)H.push(w[h].x,w[h].y,w[h].z);else for(h=0;h<3;h++)H.push(faceNormal.x,faceNormal.y,faceNormal.z);if(g)for(h=0;h<3;h++)q.push(g[h].u,g[h].v);T.push(A,
-A+1,A+2);Q.push(A,A+1);Q.push(A,A+2);Q.push(A+1,A+2);A+=3}else if(h instanceof THREE.Face4){s=e.geometry.vertices[h.a].position;L=e.geometry.vertices[h.b].position;u=e.geometry.vertices[h.c].position;h=e.geometry.vertices[h.d].position;t.push(s.x,s.y,s.z);t.push(L.x,L.y,L.z);t.push(u.x,u.y,u.z);t.push(h.x,h.y,h.z);if(w.length==4&&P)for(h=0;h<4;h++)H.push(w[h].x,w[h].y,w[h].z);else for(h=0;h<4;h++)H.push(faceNormal.x,faceNormal.y,faceNormal.z);if(g)for(h=0;h<4;h++)q.push(g[h].u,g[h].v);T.push(A,A+
-1,A+2);T.push(A,A+2,A+3);Q.push(A,A+1);Q.push(A,A+2);Q.push(A,A+3);Q.push(A+1,A+2);Q.push(A+2,A+3);A+=4}}if(t.length){y.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,y.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(t),c.STATIC_DRAW);y.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,y.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(H),c.STATIC_DRAW);y.__webGLUVBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,y.__webGLUVBuffer);
-c.bufferData(c.ARRAY_BUFFER,new Float32Array(q),c.STATIC_DRAW);y.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,y.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(T),c.STATIC_DRAW);y.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,y.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(Q),c.STATIC_DRAW);y.__webGLFaceCount=T.length;y.__webGLLineCount=Q.length}};this.renderBuffer=function(e,f,k){var o,g,h,w,s,L,u,
-T,Q,t;if(f instanceof THREE.MeshShaderMaterial){if(!f.program){f.program=b(f.fragment_shader,f.vertex_shader);u=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(t in f.uniforms)u.push(t);j(f.program,u);p(f.program)}t=f.program}else t=z;if(t!=G){c.useProgram(t);G=t}if(f instanceof THREE.MeshShaderMaterial){h=f.wireframe;w=f.wireframe_linewidth;u=t;T=f.uniforms;var H,q;for(g in T){H=T[g].type;Q=T[g].value;q=u.uniforms[g];if(H=="i")c.uniform1i(q,
-Q);else if(H=="f")c.uniform1f(q,Q);else if(H=="t"){c.uniform1i(q,Q);H=T[g].texture;if(H instanceof THREE.TextureCube)d(H,Q);else H instanceof THREE.Texture&&i(H,Q)}}this.loadCamera(t,e);this.loadMatrices(t)}else if(f instanceof THREE.MeshPhongMaterial||f instanceof THREE.MeshLambertMaterial||f instanceof THREE.MeshBasicMaterial){e=f.color;o=f.opacity;h=f.wireframe;w=f.wireframe_linewidth;s=f.map;L=f.env_map;u=f.combine==THREE.Mix;g=f.reflectivity;Q=f.env_map&&f.env_map.mapping==THREE.RefractionMapping;
-T=f.refraction_ratio;c.uniform4f(t.uniforms.mColor,e.r*o,e.g*o,e.b*o,o);c.uniform1i(t.uniforms.mixEnvMap,u);c.uniform1f(t.uniforms.mReflectivity,g);c.uniform1i(t.uniforms.useRefract,Q);c.uniform1f(t.uniforms.mRefractionRatio,T)}if(f instanceof THREE.MeshNormalMaterial){o=f.opacity;c.uniform1f(t.uniforms.mOpacity,o);c.uniform1i(t.uniforms.material,4)}else if(f instanceof THREE.MeshDepthMaterial){o=f.opacity;h=f.wireframe;w=f.wireframe_linewidth;c.uniform1f(t.uniforms.mOpacity,o);c.uniform1f(t.uniforms.m2Near,
-f.__2near);c.uniform1f(t.uniforms.mFarPlusNear,f.__farPlusNear);c.uniform1f(t.uniforms.mFarMinusNear,f.__farMinusNear);c.uniform1i(t.uniforms.material,3)}else if(f instanceof THREE.MeshPhongMaterial){e=f.ambient;g=f.specular;f=f.shininess;c.uniform4f(t.uniforms.mAmbient,e.r,e.g,e.b,o);c.uniform4f(t.uniforms.mSpecular,g.r,g.g,g.b,o);c.uniform1f(t.uniforms.mShininess,f);c.uniform1i(t.uniforms.material,2)}else if(f instanceof THREE.MeshLambertMaterial)c.uniform1i(t.uniforms.material,1);else if(f instanceof
-THREE.MeshBasicMaterial)c.uniform1i(t.uniforms.material,0);else if(f instanceof THREE.MeshCubeMaterial){c.uniform1i(t.uniforms.material,5);L=f.env_map}if(s){i(s,0);c.uniform1i(t.uniforms.tMap,0);c.uniform1i(t.uniforms.enableMap,1)}else c.uniform1i(t.uniforms.enableMap,0);if(L){d(L,1);c.uniform1i(t.uniforms.tCube,1);c.uniform1i(t.uniforms.enableCubeMap,1)}else c.uniform1i(t.uniforms.enableCubeMap,0);c.bindBuffer(c.ARRAY_BUFFER,k.__webGLVertexBuffer);c.vertexAttribPointer(t.position,3,c.FLOAT,false,
-0,0);c.bindBuffer(c.ARRAY_BUFFER,k.__webGLNormalBuffer);c.vertexAttribPointer(t.normal,3,c.FLOAT,false,0,0);if(s){c.bindBuffer(c.ARRAY_BUFFER,k.__webGLUVBuffer);c.enableVertexAttribArray(t.uv);c.vertexAttribPointer(t.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(t.uv);if(h){c.lineWidth(w);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,k.__webGLLineBuffer);c.drawElements(c.LINES,k.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,k.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,
-k.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(e,f,k,o,g){var h,w,s,L,u;s=0;for(L=f.material.length;s<L;s++){h=f.material[s];if(h instanceof THREE.MeshFaceMaterial){h=0;for(w=k.material.length;h<w;h++)if((u=k.material[h])&&u.blending==o&&u.opacity<1==g){this.setBlending(u.blending);this.renderBuffer(e,u,k)}}else if((u=h)&&u.blending==o&&u.opacity<1==g){this.setBlending(u.blending);this.renderBuffer(e,u,k)}}};this.render=function(e,f){var k,o,g,h;this.initWebGLObjects(e);this.autoClear&&
-this.clear();f.autoUpdateMatrix&&f.updateMatrix();this.loadCamera(z,f);this.setupLights(z,e);k=0;for(o=e.__webGLObjects.length;k<o;k++){g=e.__webGLObjects[k];h=g.object;g=g.buffer;if(h.visible){this.setupMatrices(h,f);this.loadMatrices(z);this.renderPass(f,h,g,THREE.NormalBlending,false)}}k=0;for(o=e.__webGLObjects.length;k<o;k++){g=e.__webGLObjects[k];h=g.object;g=g.buffer;if(h.visible){this.setupMatrices(h,f);this.loadMatrices(z);this.renderPass(f,h,g,THREE.AdditiveBlending,false);this.renderPass(f,
-h,g,THREE.SubtractiveBlending,false);this.renderPass(f,h,g,THREE.AdditiveBlending,true);this.renderPass(f,h,g,THREE.SubtractiveBlending,true);this.renderPass(f,h,g,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(e){var f,k,o,g,h,w;if(!e.__webGLObjects){e.__webGLObjects=[];e.__webGLObjectsMap={}}f=0;for(k=e.objects.length;f<k;f++){o=e.objects[f];if(e.__webGLObjectsMap[o.id]==undefined)e.__webGLObjectsMap[o.id]={};w=e.__webGLObjectsMap[o.id];if(o instanceof THREE.Mesh)for(h in o.geometry.geometryChunks){g=
-o.geometry.geometryChunks[h];g.__webGLVertexBuffer||this.createBuffers(o,h);if(w[h]==undefined){g={buffer:g,object:o};e.__webGLObjects.push(g);w[h]=1}}}};this.removeObject=function(e,f){var k,o;for(k=e.__webGLObjects.length-1;k>=0;k--){o=e.__webGLObjects[k].object;f==o&&e.__webGLObjects.splice(k,1)}};this.setupMatrices=function(e,f){e.autoUpdateMatrix&&e.updateMatrix();x.multiply(f.matrix,e.matrix);O.set(f.matrix.flatten());J.set(x.flatten());M.set(f.projectionMatrix.flatten());F=THREE.Matrix4.makeInvert3x3(x).transpose();
-n.set(F.m);S.set(e.matrix.flatten())};this.loadMatrices=function(e){c.uniformMatrix4fv(e.uniforms.viewMatrix,false,O);c.uniformMatrix4fv(e.uniforms.modelViewMatrix,false,J);c.uniformMatrix4fv(e.uniforms.projectionMatrix,false,M);c.uniformMatrix3fv(e.uniforms.normalMatrix,false,n);c.uniformMatrix4fv(e.uniforms.objectMatrix,false,S)};this.loadCamera=function(e,f){c.uniform3f(e.uniforms.cameraPosition,f.position.x,f.position.y,f.position.z)};this.setBlending=function(e){switch(e){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);
-c.blendFunc(c.ONE,c.ONE);break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(e,f){if(e){!f||f=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(e=="back")c.cullFace(c.BACK);else e=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)}};
+e=b(n,e);c.useProgram(e);j(e,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract","m2Near","mFarPlusNear","mFarMinusNear"]);f&&j(e,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);k&&j(e,["pointLightNumber","pointLightColor",
+"pointLightPosition"]);c.uniform1i(e.uniforms.enableMap,0);c.uniform1i(e.uniforms.tMap,0);c.uniform1i(e.uniforms.enableCubeMap,0);c.uniform1i(e.uniforms.tCube,1);c.uniform1i(e.uniforms.mixEnvMap,0);c.uniform1i(e.uniforms.useRefract,0);p(e,["position","normal","uv"]);return e}(a.directional,a.point);this.setSize=function(f,k){l.width=f;l.height=k;c.viewport(0,0,l.width,l.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(f,k){var e,n,h,g,r,t=[],
+K=[],A=[];g=[];r=[];c.uniform1i(f.uniforms.enableLighting,k.length);e=0;for(n=k.length;e<n;e++){h=k[e];if(h instanceof THREE.AmbientLight)t.push(h);else if(h instanceof THREE.DirectionalLight)A.push(h);else h instanceof THREE.PointLight&&K.push(h)}e=h=g=r=0;for(n=t.length;e<n;e++){h+=t[e].color.r;g+=t[e].color.g;r+=t[e].color.b}c.uniform3f(f.uniforms.ambientLightColor,h,g,r);g=[];r=[];e=0;for(n=A.length;e<n;e++){h=A[e];g.push(h.color.r*h.intensity);g.push(h.color.g*h.intensity);g.push(h.color.b*h.intensity);
+r.push(h.position.x);r.push(h.position.y);r.push(h.position.z)}if(A.length){c.uniform1i(f.uniforms.directionalLightNumber,A.length);c.uniform3fv(f.uniforms.directionalLightDirection,r);c.uniform3fv(f.uniforms.directionalLightColor,g)}g=[];r=[];e=0;for(n=K.length;e<n;e++){h=K[e];g.push(h.color.r*h.intensity);g.push(h.color.g*h.intensity);g.push(h.color.b*h.intensity);r.push(h.position.x);r.push(h.position.y);r.push(h.position.z)}if(K.length){c.uniform1i(f.uniforms.pointLightNumber,K.length);c.uniform3fv(f.uniforms.pointLightPosition,
+r);c.uniform3fv(f.uniforms.pointLightColor,g)}};this.createBuffers=function(f,k){var e,n,h,g,r,t,K,A,H=[],Q=[],u=[],O=[],s=[],y=0,x=f.geometry.geometryChunks[k],R;h=false;e=0;for(n=f.material.length;e<n;e++){meshMaterial=f.material[e];if(meshMaterial instanceof THREE.MeshFaceMaterial){r=0;for(R=x.material.length;r<R;r++)if(x.material[r]&&x.material[r].shading!=undefined&&x.material[r].shading==THREE.SmoothShading){h=true;break}}else if(meshMaterial&&meshMaterial.shading!=undefined&&meshMaterial.shading==
+THREE.SmoothShading){h=true;break}if(h)break}R=h;e=0;for(n=x.faces.length;e<n;e++){h=x.faces[e];g=f.geometry.faces[h];r=g.vertexNormals;faceNormal=g.normal;h=f.geometry.uvs[h];if(g instanceof THREE.Face3){t=f.geometry.vertices[g.a].position;K=f.geometry.vertices[g.b].position;A=f.geometry.vertices[g.c].position;u.push(t.x,t.y,t.z);u.push(K.x,K.y,K.z);u.push(A.x,A.y,A.z);if(r.length==3&&R)for(g=0;g<3;g++)O.push(r[g].x,r[g].y,r[g].z);else for(g=0;g<3;g++)O.push(faceNormal.x,faceNormal.y,faceNormal.z);
+if(h)for(g=0;g<3;g++)s.push(h[g].u,h[g].v);H.push(y,y+1,y+2);Q.push(y,y+1);Q.push(y,y+2);Q.push(y+1,y+2);y+=3}else if(g instanceof THREE.Face4){t=f.geometry.vertices[g.a].position;K=f.geometry.vertices[g.b].position;A=f.geometry.vertices[g.c].position;g=f.geometry.vertices[g.d].position;u.push(t.x,t.y,t.z);u.push(K.x,K.y,K.z);u.push(A.x,A.y,A.z);u.push(g.x,g.y,g.z);if(r.length==4&&R)for(g=0;g<4;g++)O.push(r[g].x,r[g].y,r[g].z);else for(g=0;g<4;g++)O.push(faceNormal.x,faceNormal.y,faceNormal.z);if(h)for(g=
+0;g<4;g++)s.push(h[g].u,h[g].v);H.push(y,y+1,y+2);H.push(y,y+2,y+3);Q.push(y,y+1);Q.push(y,y+2);Q.push(y,y+3);Q.push(y+1,y+2);Q.push(y+2,y+3);y+=4}}if(u.length){x.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,x.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(u),c.STATIC_DRAW);x.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,x.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(O),c.STATIC_DRAW);if(s.length>0){x.__webGLUVBuffer=c.createBuffer();
+c.bindBuffer(c.ARRAY_BUFFER,x.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(s),c.STATIC_DRAW)}x.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,x.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(H),c.STATIC_DRAW);x.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,x.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(Q),c.STATIC_DRAW);x.__webGLFaceCount=H.length;x.__webGLLineCount=Q.length}};this.renderBuffer=
+function(f,k,e,n){var h,g,r,t,K,A,H,Q,u;if(e instanceof THREE.MeshShaderMaterial){if(!e.program){e.program=b(e.fragment_shader,e.vertex_shader);H=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(u in e.uniforms)H.push(u);j(e.program,H);p(e.program,["position","normal","uv"])}u=e.program}else u=G;if(u!=E){c.useProgram(u);E=u}u==G&&this.setupLights(u,k);this.loadCamera(u,f);this.loadMatrices(u);if(e instanceof THREE.MeshShaderMaterial){r=e.wireframe;
+t=e.wireframe_linewidth;f=u;k=e.uniforms;var O;for(h in k){Q=k[h].type;H=k[h].value;O=f.uniforms[h];if(Q=="i")c.uniform1i(O,H);else if(Q=="f")c.uniform1f(O,H);else if(Q=="t"){c.uniform1i(O,H);Q=k[h].texture;if(Q instanceof THREE.TextureCube)d(Q,H);else Q instanceof THREE.Texture&&i(Q,H)}}}if(e instanceof THREE.MeshPhongMaterial||e instanceof THREE.MeshLambertMaterial||e instanceof THREE.MeshBasicMaterial){h=e.color;g=e.opacity;r=e.wireframe;t=e.wireframe_linewidth;K=e.map;A=e.env_map;k=e.combine==
+THREE.Mix;f=e.reflectivity;Q=e.env_map&&e.env_map.mapping==THREE.RefractionMapping;H=e.refraction_ratio;c.uniform4f(u.uniforms.mColor,h.r*g,h.g*g,h.b*g,g);c.uniform1i(u.uniforms.mixEnvMap,k);c.uniform1f(u.uniforms.mReflectivity,f);c.uniform1i(u.uniforms.useRefract,Q);c.uniform1f(u.uniforms.mRefractionRatio,H)}if(e instanceof THREE.MeshNormalMaterial){g=e.opacity;c.uniform1f(u.uniforms.mOpacity,g);c.uniform1i(u.uniforms.material,4)}else if(e instanceof THREE.MeshDepthMaterial){g=e.opacity;r=e.wireframe;
+t=e.wireframe_linewidth;c.uniform1f(u.uniforms.mOpacity,g);c.uniform1f(u.uniforms.m2Near,e.__2near);c.uniform1f(u.uniforms.mFarPlusNear,e.__farPlusNear);c.uniform1f(u.uniforms.mFarMinusNear,e.__farMinusNear);c.uniform1i(u.uniforms.material,3)}else if(e instanceof THREE.MeshPhongMaterial){h=e.ambient;f=e.specular;e=e.shininess;c.uniform4f(u.uniforms.mAmbient,h.r,h.g,h.b,g);c.uniform4f(u.uniforms.mSpecular,f.r,f.g,f.b,g);c.uniform1f(u.uniforms.mShininess,e);c.uniform1i(u.uniforms.material,2)}else if(e instanceof
+THREE.MeshLambertMaterial)c.uniform1i(u.uniforms.material,1);else if(e instanceof THREE.MeshBasicMaterial)c.uniform1i(u.uniforms.material,0);else if(e instanceof THREE.MeshCubeMaterial){c.uniform1i(u.uniforms.material,5);A=e.env_map}if(K){i(K,0);c.uniform1i(u.uniforms.tMap,0);c.uniform1i(u.uniforms.enableMap,1)}else c.uniform1i(u.uniforms.enableMap,0);if(A){d(A,1);c.uniform1i(u.uniforms.tCube,1);c.uniform1i(u.uniforms.enableCubeMap,1)}else c.uniform1i(u.uniforms.enableCubeMap,0);g=u.attributes;c.bindBuffer(c.ARRAY_BUFFER,
+n.__webGLVertexBuffer);c.vertexAttribPointer(g.position,3,c.FLOAT,false,0,0);c.bindBuffer(c.ARRAY_BUFFER,n.__webGLNormalBuffer);c.vertexAttribPointer(g.normal,3,c.FLOAT,false,0,0);if(g.uv>=0)if(n.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,n.__webGLUVBuffer);c.enableVertexAttribArray(g.uv);c.vertexAttribPointer(g.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(g.uv);if(r){c.lineWidth(t);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,n.__webGLLineBuffer);c.drawElements(c.LINES,n.__webGLLineCount,c.UNSIGNED_SHORT,
+0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,n.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,n.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(f,k,e,n,h,g){var r,t,K,A,H;K=0;for(A=e.material.length;K<A;K++){r=e.material[K];if(r instanceof THREE.MeshFaceMaterial){r=0;for(t=n.material.length;r<t;r++)if((H=n.material[r])&&H.blending==h&&H.opacity<1==g){this.setBlending(H.blending);this.renderBuffer(f,k,H,n)}}else if((H=r)&&H.blending==h&&H.opacity<1==g){this.setBlending(H.blending);this.renderBuffer(f,
+k,H,n)}}};this.render=function(f,k){var e,n,h,g,r=f.lights;this.initWebGLObjects(f);this.autoClear&&this.clear();k.autoUpdateMatrix&&k.updateMatrix();e=0;for(n=f.__webGLObjects.length;e<n;e++){h=f.__webGLObjects[e];g=h.object;h=h.buffer;if(g.visible){this.setupMatrices(g,k);this.renderPass(k,r,g,h,THREE.NormalBlending,false)}}e=0;for(n=f.__webGLObjects.length;e<n;e++){h=f.__webGLObjects[e];g=h.object;h=h.buffer;if(g.visible){this.setupMatrices(g,k);this.renderPass(k,r,g,h,THREE.AdditiveBlending,false);
+this.renderPass(k,r,g,h,THREE.SubtractiveBlending,false);this.renderPass(k,r,g,h,THREE.AdditiveBlending,true);this.renderPass(k,r,g,h,THREE.SubtractiveBlending,true);this.renderPass(k,r,g,h,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(f){var k,e,n,h,g,r;if(!f.__webGLObjects){f.__webGLObjects=[];f.__webGLObjectsMap={}}k=0;for(e=f.objects.length;k<e;k++){n=f.objects[k];if(f.__webGLObjectsMap[n.id]==undefined)f.__webGLObjectsMap[n.id]={};r=f.__webGLObjectsMap[n.id];if(n instanceof THREE.Mesh)for(g in n.geometry.geometryChunks){h=
+n.geometry.geometryChunks[g];h.__webGLVertexBuffer||this.createBuffers(n,g);if(r[g]==undefined){h={buffer:h,object:n};f.__webGLObjects.push(h);r[g]=1}}}};this.removeObject=function(f,k){var e,n;for(e=f.__webGLObjects.length-1;e>=0;e--){n=f.__webGLObjects[e].object;k==n&&f.__webGLObjects.splice(e,1)}};this.setupMatrices=function(f,k){f.autoUpdateMatrix&&f.updateMatrix();w.multiply(k.matrix,f.matrix);P.set(k.matrix.flatten());J.set(w.flatten());M.set(k.projectionMatrix.flatten());F=THREE.Matrix4.makeInvert3x3(w).transpose();
+o.set(F.m);T.set(f.matrix.flatten())};this.loadMatrices=function(f){c.uniformMatrix4fv(f.uniforms.viewMatrix,false,P);c.uniformMatrix4fv(f.uniforms.modelViewMatrix,false,J);c.uniformMatrix4fv(f.uniforms.projectionMatrix,false,M);c.uniformMatrix3fv(f.uniforms.normalMatrix,false,o);c.uniformMatrix4fv(f.uniforms.objectMatrix,false,T)};this.loadCamera=function(f,k){c.uniform3f(f.uniforms.cameraPosition,k.position.x,k.position.y,k.position.z)};this.setBlending=function(f){switch(f){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);
+c.blendFunc(c.ONE,c.ONE);break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(f,k){if(f){!k||k=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(f=="back")c.cullFace(c.BACK);else f=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)}};
 THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[];this.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null};
 THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[];this.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null};
 THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=null};
 THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=null};

+ 128 - 127
build/ThreeExtras.js

@@ -12,42 +12,43 @@ THREE.Vector4=function(a,b,d,e){this.x=a||0;this.y=b||0;this.z=d||0;this.w=e||1}
 THREE.Vector4.prototype={set:function(a,b,d,e){this.x=a;this.y=b;this.z=d;this.w=e;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w||1;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;
 THREE.Vector4.prototype={set:function(a,b,d,e){this.x=a;this.y=b;this.z=d;this.w=e;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w||1;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;
 return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=a;this.w/=a;return this},lerpSelf:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},toString:function(){return"THREE.Vector4 ("+this.x+", "+this.y+", "+this.z+", "+this.w+")"}};
 return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=a;this.w/=a;return this},lerpSelf:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},toString:function(){return"THREE.Vector4 ("+this.x+", "+this.y+", "+this.z+", "+this.w+")"}};
 THREE.Ray=function(a,b){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3};
 THREE.Ray=function(a,b){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3};
-THREE.Ray.prototype={intersectScene:function(a){var b,d,e=a.objects,f=[];a=0;for(b=e.length;a<b;a++){d=e[a];if(d instanceof THREE.Mesh)f=f.concat(this.intersectObject(d))}f.sort(function(j,k){return j.distance-k.distance});return f},intersectObject:function(a){function b(L,u,A,n){n=n.clone().subSelf(u);A=A.clone().subSelf(u);var h=L.clone().subSelf(u);L=n.dot(n);u=n.dot(A);n=n.dot(h);var i=A.dot(A);A=A.dot(h);h=1/(L*i-u*u);i=(i*n-u*A)*h;L=(L*A-u*n)*h;return i>0&&L>0&&i+L<1}var d,e,f,j,k,g,o,c,s,F,
-r,w=a.geometry,v=w.vertices,y=[];d=0;for(e=w.faces.length;d<e;d++){f=w.faces[d];F=this.origin.clone();r=this.direction.clone();j=a.matrix.transformVector3(v[f.a].position.clone());k=a.matrix.transformVector3(v[f.b].position.clone());g=a.matrix.transformVector3(v[f.c].position.clone());o=f instanceof THREE.Face4?a.matrix.transformVector3(v[f.d].position.clone()):null;c=a.rotationMatrix.transformVector3(f.normal.clone());s=r.dot(c);if(s<0){c=c.dot((new THREE.Vector3).sub(j,F))/s;F=F.addSelf(r.multiplyScalar(c));
-if(f instanceof THREE.Face3){if(b(F,j,k,g)){f={distance:this.origin.distanceTo(F),point:F,face:f,object:a};y.push(f)}}else if(f instanceof THREE.Face4)if(b(F,j,k,o)||b(F,k,g,o)){f={distance:this.origin.distanceTo(F),point:F,face:f,object:a};y.push(f)}}}return y}};
-THREE.Rectangle=function(){function a(){j=e-b;k=f-d}var b,d,e,f,j,k,g=true;this.getX=function(){return b};this.getY=function(){return d};this.getWidth=function(){return j};this.getHeight=function(){return k};this.getLeft=function(){return b};this.getTop=function(){return d};this.getRight=function(){return e};this.getBottom=function(){return f};this.set=function(o,c,s,F){g=false;b=o;d=c;e=s;f=F;a()};this.addPoint=function(o,c){if(g){g=false;b=o;d=c;e=o;f=c}else{b=Math.min(b,o);d=Math.min(d,c);e=Math.max(e,
-o);f=Math.max(f,c)}a()};this.addRectangle=function(o){if(g){g=false;b=o.getLeft();d=o.getTop();e=o.getRight();f=o.getBottom()}else{b=Math.min(b,o.getLeft());d=Math.min(d,o.getTop());e=Math.max(e,o.getRight());f=Math.max(f,o.getBottom())}a()};this.inflate=function(o){b-=o;d-=o;e+=o;f+=o;a()};this.minSelf=function(o){b=Math.max(b,o.getLeft());d=Math.max(d,o.getTop());e=Math.min(e,o.getRight());f=Math.min(f,o.getBottom());a()};this.instersects=function(o){return Math.min(e,o.getRight())-Math.max(b,o.getLeft())>=
-0&&Math.min(f,o.getBottom())-Math.max(d,o.getTop())>=0};this.empty=function(){g=true;f=e=d=b=0;a()};this.isEmpty=function(){return g};this.toString=function(){return"THREE.Rectangle ( left: "+b+", right: "+e+", top: "+d+", bottom: "+f+", width: "+j+", height: "+k+" )"}};THREE.Matrix3=function(){this.m=[]};THREE.Matrix3.prototype={transpose:function(){var a;a=this.m[1];this.m[1]=this.m[3];this.m[3]=a;a=this.m[2];this.m[2]=this.m[6];this.m[6]=a;a=this.m[5];this.m[5]=this.m[7];this.m[7]=a;return this}};
+THREE.Ray.prototype={intersectScene:function(a){var b,d,e=a.objects,f=[];a=0;for(b=e.length;a<b;a++){d=e[a];if(d instanceof THREE.Mesh)f=f.concat(this.intersectObject(d))}f.sort(function(j,k){return j.distance-k.distance});return f},intersectObject:function(a){function b(L,u,A,o){o=o.clone().subSelf(u);A=A.clone().subSelf(u);var i=L.clone().subSelf(u);L=o.dot(o);u=o.dot(A);o=o.dot(i);var n=A.dot(A);A=A.dot(i);i=1/(L*n-u*u);n=(n*o-u*A)*i;L=(L*A-u*o)*i;return n>0&&L>0&&n+L<1}var d,e,f,j,k,g,p,c,t,F,
+r,w=a.geometry,v=w.vertices,y=[];d=0;for(e=w.faces.length;d<e;d++){f=w.faces[d];F=this.origin.clone();r=this.direction.clone();j=a.matrix.multiplyVector3(v[f.a].position.clone());k=a.matrix.multiplyVector3(v[f.b].position.clone());g=a.matrix.multiplyVector3(v[f.c].position.clone());p=f instanceof THREE.Face4?a.matrix.multiplyVector3(v[f.d].position.clone()):null;c=a.rotationMatrix.multiplyVector3(f.normal.clone());t=r.dot(c);if(t<0){c=c.dot((new THREE.Vector3).sub(j,F))/t;F=F.addSelf(r.multiplyScalar(c));
+if(f instanceof THREE.Face3){if(b(F,j,k,g)){f={distance:this.origin.distanceTo(F),point:F,face:f,object:a};y.push(f)}}else if(f instanceof THREE.Face4)if(b(F,j,k,p)||b(F,k,g,p)){f={distance:this.origin.distanceTo(F),point:F,face:f,object:a};y.push(f)}}}return y}};
+THREE.Rectangle=function(){function a(){j=e-b;k=f-d}var b,d,e,f,j,k,g=true;this.getX=function(){return b};this.getY=function(){return d};this.getWidth=function(){return j};this.getHeight=function(){return k};this.getLeft=function(){return b};this.getTop=function(){return d};this.getRight=function(){return e};this.getBottom=function(){return f};this.set=function(p,c,t,F){g=false;b=p;d=c;e=t;f=F;a()};this.addPoint=function(p,c){if(g){g=false;b=p;d=c;e=p;f=c}else{b=Math.min(b,p);d=Math.min(d,c);e=Math.max(e,
+p);f=Math.max(f,c)}a()};this.addRectangle=function(p){if(g){g=false;b=p.getLeft();d=p.getTop();e=p.getRight();f=p.getBottom()}else{b=Math.min(b,p.getLeft());d=Math.min(d,p.getTop());e=Math.max(e,p.getRight());f=Math.max(f,p.getBottom())}a()};this.inflate=function(p){b-=p;d-=p;e+=p;f+=p;a()};this.minSelf=function(p){b=Math.max(b,p.getLeft());d=Math.max(d,p.getTop());e=Math.min(e,p.getRight());f=Math.min(f,p.getBottom());a()};this.instersects=function(p){return Math.min(e,p.getRight())-Math.max(b,p.getLeft())>=
+0&&Math.min(f,p.getBottom())-Math.max(d,p.getTop())>=0};this.empty=function(){g=true;f=e=d=b=0;a()};this.isEmpty=function(){return g};this.toString=function(){return"THREE.Rectangle ( left: "+b+", right: "+e+", top: "+d+", bottom: "+f+", width: "+j+", height: "+k+" )"}};THREE.Matrix3=function(){this.m=[]};THREE.Matrix3.prototype={transpose:function(){var a;a=this.m[1];this.m[1]=this.m[3];this.m[3]=a;a=this.m[2];this.m[2]=this.m[6];this.m[6]=a;a=this.m[5];this.m[5]=this.m[7];this.m[7]=a;return this}};
 THREE.Matrix4=function(){};
 THREE.Matrix4=function(){};
 THREE.Matrix4.prototype={n11:1,n12:0,n13:0,n14:0,n21:0,n22:1,n23:0,n24:0,n31:0,n32:0,n33:1,n34:0,n41:0,n42:0,n43:0,n44:1,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},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=
 THREE.Matrix4.prototype={n11:1,n12:0,n13:0,n14:0,n21:0,n22:1,n23:0,n24:0,n31:0,n32:0,n33:1,n34:0,n41:0,n42:0,n43:0,n44:1,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},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},lookAt:function(a,b,d){var e=new THREE.Vector3,f=new THREE.Vector3,j=new THREE.Vector3;j.sub(a,b).normalize();e.cross(d,j).normalize();f.cross(j,e).normalize();this.n11=e.x;this.n12=e.y;this.n13=e.z;this.n14=-e.dot(a);this.n21=f.x;this.n22=f.y;this.n23=f.z;this.n24=-f.dot(a);this.n31=j.x;this.n32=j.y;this.n33=j.z;this.n34=-j.dot(a);this.n43=this.n42=this.n41=0;this.n44=1},transformVector3:function(a){var b=a.x,d=a.y,e=a.z,f=1/(this.n41*b+this.n42*
-d+this.n43*e+this.n44);a.x=(this.n11*b+this.n12*d+this.n13*e+this.n14)*f;a.y=(this.n21*b+this.n22*d+this.n23*e+this.n24)*f;a.z=(this.n31*b+this.n32*d+this.n33*e+this.n34)*f;return a},transformVector4:function(a){var b=a.x,d=a.y,e=a.z,f=a.w;a.x=this.n11*b+this.n12*d+this.n13*e+this.n14*f;a.y=this.n21*b+this.n22*d+this.n23*e+this.n24*f;a.z=this.n31*b+this.n32*d+this.n33*e+this.n34*f;a.w=this.n41*b+this.n42*d+this.n43*e+this.n44*f;return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*
-a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var d=a.n11,e=a.n12,f=a.n13,j=a.n14,k=a.n21,g=a.n22,o=a.n23,c=a.n24,s=a.n31,F=a.n32,r=a.n33,w=a.n34,v=a.n41,y=a.n42,L=a.n43,u=a.n44,A=b.n11,n=b.n12,h=b.n13,i=b.n14,p=b.n21,x=b.n22,m=b.n23,l=b.n24,E=b.n31,B=b.n32,Q=b.n33,G=b.n34,V=b.n41,U=b.n42,D=b.n43,
-P=b.n44;this.n11=d*A+e*p+f*E+j*V;this.n12=d*n+e*x+f*B+j*U;this.n13=d*h+e*m+f*Q+j*D;this.n14=d*i+e*l+f*G+j*P;this.n21=k*A+g*p+o*E+c*V;this.n22=k*n+g*x+o*B+c*U;this.n23=k*h+g*m+o*Q+c*D;this.n24=k*i+g*l+o*G+c*P;this.n31=s*A+F*p+r*E+w*V;this.n32=s*n+F*x+r*B+w*U;this.n33=s*h+F*m+r*Q+w*D;this.n34=s*i+F*l+r*G+w*P;this.n41=v*A+y*p+L*E+u*V;this.n42=v*n+y*x+L*B+u*U;this.n43=v*h+y*m+L*Q+u*D;this.n44=v*i+y*l+L*G+u*P},multiplySelf:function(a){var b=this.n11,d=this.n12,e=this.n13,f=this.n14,j=this.n21,k=this.n22,
-g=this.n23,o=this.n24,c=this.n31,s=this.n32,F=this.n33,r=this.n34,w=this.n41,v=this.n42,y=this.n43,L=this.n44;this.n11=b*a.n11+d*a.n21+e*a.n31+f*a.n41;this.n12=b*a.n12+d*a.n22+e*a.n32+f*a.n42;this.n13=b*a.n13+d*a.n23+e*a.n33+f*a.n43;this.n14=b*a.n14+d*a.n24+e*a.n34+f*a.n44;this.n21=j*a.n11+k*a.n21+g*a.n31+o*a.n41;this.n22=j*a.n12+k*a.n22+g*a.n32+o*a.n42;this.n23=j*a.n13+k*a.n23+g*a.n33+o*a.n43;this.n24=j*a.n14+k*a.n24+g*a.n34+o*a.n44;this.n31=c*a.n11+s*a.n21+F*a.n31+r*a.n41;this.n32=c*a.n12+s*a.n22+
-F*a.n32+r*a.n42;this.n33=c*a.n13+s*a.n23+F*a.n33+r*a.n43;this.n34=c*a.n14+s*a.n24+F*a.n34+r*a.n44;this.n41=w*a.n11+v*a.n21+y*a.n31+L*a.n41;this.n42=w*a.n12+v*a.n22+y*a.n32+L*a.n42;this.n43=w*a.n13+v*a.n23+y*a.n33+L*a.n43;this.n44=w*a.n14+v*a.n24+y*a.n34+L*a.n44},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},determinant:function(){return this.n14*
+a.n41;this.n42=a.n42;this.n43=a.n43;this.n44=a.n44},lookAt:function(a,b,d){var e=new THREE.Vector3,f=new THREE.Vector3,j=new THREE.Vector3;j.sub(a,b).normalize();e.cross(d,j).normalize();f.cross(j,e).normalize();this.n11=e.x;this.n12=e.y;this.n13=e.z;this.n14=-e.dot(a);this.n21=f.x;this.n22=f.y;this.n23=f.z;this.n24=-f.dot(a);this.n31=j.x;this.n32=j.y;this.n33=j.z;this.n34=-j.dot(a);this.n43=this.n42=this.n41=0;this.n44=1},multiplyVector3:function(a){var b=a.x,d=a.y,e=a.z,f=1/(this.n41*b+this.n42*
+d+this.n43*e+this.n44);a.x=(this.n11*b+this.n12*d+this.n13*e+this.n14)*f;a.y=(this.n21*b+this.n22*d+this.n23*e+this.n24)*f;a.z=(this.n31*b+this.n32*d+this.n33*e+this.n34)*f;return a},multiplyVector4:function(a){var b=a.x,d=a.y,e=a.z,f=a.w;a.x=this.n11*b+this.n12*d+this.n13*e+this.n14*f;a.y=this.n21*b+this.n22*d+this.n23*e+this.n24*f;a.z=this.n31*b+this.n32*d+this.n33*e+this.n34*f;a.w=this.n41*b+this.n42*d+this.n43*e+this.n44*f;return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*
+a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var d=a.n11,e=a.n12,f=a.n13,j=a.n14,k=a.n21,g=a.n22,p=a.n23,c=a.n24,t=a.n31,F=a.n32,r=a.n33,w=a.n34,v=a.n41,y=a.n42,L=a.n43,u=a.n44,A=b.n11,o=b.n12,i=b.n13,n=b.n14,h=b.n21,x=b.n22,m=b.n23,l=b.n24,B=b.n31,C=b.n32,Q=b.n33,J=b.n34,P=b.n41,S=b.n42,E=b.n43,
+T=b.n44;this.n11=d*A+e*h+f*B+j*P;this.n12=d*o+e*x+f*C+j*S;this.n13=d*i+e*m+f*Q+j*E;this.n14=d*n+e*l+f*J+j*T;this.n21=k*A+g*h+p*B+c*P;this.n22=k*o+g*x+p*C+c*S;this.n23=k*i+g*m+p*Q+c*E;this.n24=k*n+g*l+p*J+c*T;this.n31=t*A+F*h+r*B+w*P;this.n32=t*o+F*x+r*C+w*S;this.n33=t*i+F*m+r*Q+w*E;this.n34=t*n+F*l+r*J+w*T;this.n41=v*A+y*h+L*B+u*P;this.n42=v*o+y*x+L*C+u*S;this.n43=v*i+y*m+L*Q+u*E;this.n44=v*n+y*l+L*J+u*T},multiplySelf:function(a){var b=this.n11,d=this.n12,e=this.n13,f=this.n14,j=this.n21,k=this.n22,
+g=this.n23,p=this.n24,c=this.n31,t=this.n32,F=this.n33,r=this.n34,w=this.n41,v=this.n42,y=this.n43,L=this.n44;this.n11=b*a.n11+d*a.n21+e*a.n31+f*a.n41;this.n12=b*a.n12+d*a.n22+e*a.n32+f*a.n42;this.n13=b*a.n13+d*a.n23+e*a.n33+f*a.n43;this.n14=b*a.n14+d*a.n24+e*a.n34+f*a.n44;this.n21=j*a.n11+k*a.n21+g*a.n31+p*a.n41;this.n22=j*a.n12+k*a.n22+g*a.n32+p*a.n42;this.n23=j*a.n13+k*a.n23+g*a.n33+p*a.n43;this.n24=j*a.n14+k*a.n24+g*a.n34+p*a.n44;this.n31=c*a.n11+t*a.n21+F*a.n31+r*a.n41;this.n32=c*a.n12+t*a.n22+
+F*a.n32+r*a.n42;this.n33=c*a.n13+t*a.n23+F*a.n33+r*a.n43;this.n34=c*a.n14+t*a.n24+F*a.n34+r*a.n44;this.n41=w*a.n11+v*a.n21+y*a.n31+L*a.n41;this.n42=w*a.n12+v*a.n22+y*a.n32+L*a.n42;this.n43=w*a.n13+v*a.n23+y*a.n33+L*a.n43;this.n44=w*a.n14+v*a.n24+y*a.n34+L*a.n44},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},determinant:function(){return this.n14*
 this.n23*this.n32*this.n41-this.n13*this.n24*this.n32*this.n41-this.n14*this.n22*this.n33*this.n41+this.n12*this.n24*this.n33*this.n41+this.n13*this.n22*this.n34*this.n41-this.n12*this.n23*this.n34*this.n41-this.n14*this.n23*this.n31*this.n42+this.n13*this.n24*this.n31*this.n42+this.n14*this.n21*this.n33*this.n42-this.n11*this.n24*this.n33*this.n42-this.n13*this.n21*this.n34*this.n42+this.n11*this.n23*this.n34*this.n42+this.n14*this.n22*this.n31*this.n43-this.n12*this.n24*this.n31*this.n43-this.n14*
 this.n23*this.n32*this.n41-this.n13*this.n24*this.n32*this.n41-this.n14*this.n22*this.n33*this.n41+this.n12*this.n24*this.n33*this.n41+this.n13*this.n22*this.n34*this.n41-this.n12*this.n23*this.n34*this.n41-this.n14*this.n23*this.n31*this.n42+this.n13*this.n24*this.n31*this.n42+this.n14*this.n21*this.n33*this.n42-this.n11*this.n24*this.n33*this.n42-this.n13*this.n21*this.n34*this.n42+this.n11*this.n23*this.n34*this.n42+this.n14*this.n22*this.n31*this.n43-this.n12*this.n24*this.n31*this.n43-this.n14*
 this.n21*this.n32*this.n43+this.n11*this.n24*this.n32*this.n43+this.n12*this.n21*this.n34*this.n43-this.n11*this.n22*this.n34*this.n43-this.n13*this.n22*this.n31*this.n44+this.n12*this.n23*this.n31*this.n44+this.n13*this.n21*this.n32*this.n44-this.n11*this.n23*this.n32*this.n44-this.n12*this.n21*this.n33*this.n44+this.n11*this.n22*this.n33*this.n44},transpose:function(){function a(b,d,e){var f=b[d];b[d]=b[e];b[e]=f}a(this,"n21","n12");a(this,"n31","n13");a(this,"n32","n23");a(this,"n41","n14");a(this,
 this.n21*this.n32*this.n43+this.n11*this.n24*this.n32*this.n43+this.n12*this.n21*this.n34*this.n43-this.n11*this.n22*this.n34*this.n43-this.n13*this.n22*this.n31*this.n44+this.n12*this.n23*this.n31*this.n44+this.n13*this.n21*this.n32*this.n44-this.n11*this.n23*this.n32*this.n44-this.n12*this.n21*this.n33*this.n44+this.n11*this.n22*this.n33*this.n44},transpose:function(){function a(b,d,e){var f=b[d];b[d]=b[e];b[e]=f}a(this,"n21","n12");a(this,"n31","n13");a(this,"n32","n23");a(this,"n41","n14");a(this,
 "n42","n24");a(this,"n43","n34");return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=this.n44;return a},flatten:function(){return[this.n11,this.n21,this.n31,this.n41,this.n12,this.n22,this.n32,this.n42,this.n13,this.n23,this.n33,this.n43,this.n14,this.n24,this.n34,this.n44]},
 "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(){return[this.n11,this.n21,this.n31,this.n41,this.n12,this.n22,this.n32,this.n42,this.n13,this.n23,this.n33,this.n43,this.n14,this.n24,this.n34,this.n44]},
 toString:function(){return"| "+this.n11+" "+this.n12+" "+this.n13+" "+this.n14+" |\n| "+this.n21+" "+this.n22+" "+this.n23+" "+this.n24+" |\n| "+this.n31+" "+this.n32+" "+this.n33+" "+this.n34+" |\n| "+this.n41+" "+this.n42+" "+this.n43+" "+this.n44+" |"}};THREE.Matrix4.translationMatrix=function(a,b,d){var e=new THREE.Matrix4;e.n14=a;e.n24=b;e.n34=d;return e};THREE.Matrix4.scaleMatrix=function(a,b,d){var e=new THREE.Matrix4;e.n11=a;e.n22=b;e.n33=d;return e};
 toString:function(){return"| "+this.n11+" "+this.n12+" "+this.n13+" "+this.n14+" |\n| "+this.n21+" "+this.n22+" "+this.n23+" "+this.n24+" |\n| "+this.n31+" "+this.n32+" "+this.n33+" "+this.n34+" |\n| "+this.n41+" "+this.n42+" "+this.n43+" "+this.n44+" |"}};THREE.Matrix4.translationMatrix=function(a,b,d){var e=new THREE.Matrix4;e.n14=a;e.n24=b;e.n34=d;return e};THREE.Matrix4.scaleMatrix=function(a,b,d){var e=new THREE.Matrix4;e.n11=a;e.n22=b;e.n33=d;return e};
 THREE.Matrix4.rotationXMatrix=function(a){var b=new THREE.Matrix4;b.n22=b.n33=Math.cos(a);b.n32=Math.sin(a);b.n23=-b.n32;return b};THREE.Matrix4.rotationYMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n33=Math.cos(a);b.n13=Math.sin(a);b.n31=-b.n13;return b};THREE.Matrix4.rotationZMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n22=Math.cos(a);b.n21=Math.sin(a);b.n12=-b.n21;return b};
 THREE.Matrix4.rotationXMatrix=function(a){var b=new THREE.Matrix4;b.n22=b.n33=Math.cos(a);b.n32=Math.sin(a);b.n23=-b.n32;return b};THREE.Matrix4.rotationYMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n33=Math.cos(a);b.n13=Math.sin(a);b.n31=-b.n13;return b};THREE.Matrix4.rotationZMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n22=Math.cos(a);b.n21=Math.sin(a);b.n12=-b.n21;return b};
-THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var d=new THREE.Matrix4,e=Math.cos(b),f=Math.sin(b),j=1-e,k=a.x,g=a.y,o=a.z;d.n11=j*k*k+e;d.n12=j*k*g-f*o;d.n13=j*k*o+f*g;d.n21=j*k*g+f*o;d.n22=j*g*g+e;d.n23=j*g*o-f*k;d.n31=j*k*o-f*g;d.n32=j*g*o+f*k;d.n33=j*o*o+e;return d};
+THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var d=new THREE.Matrix4,e=Math.cos(b),f=Math.sin(b),j=1-e,k=a.x,g=a.y,p=a.z;d.n11=j*k*k+e;d.n12=j*k*g-f*p;d.n13=j*k*p+f*g;d.n21=j*k*g+f*p;d.n22=j*g*g+e;d.n23=j*g*p-f*k;d.n31=j*k*p-f*g;d.n32=j*g*p+f*k;d.n33=j*p*p+e;return d};
 THREE.Matrix4.makeInvert=function(a){var b=new THREE.Matrix4;b.n11=a.n23*a.n34*a.n42-a.n24*a.n33*a.n42+a.n24*a.n32*a.n43-a.n22*a.n34*a.n43-a.n23*a.n32*a.n44+a.n22*a.n33*a.n44;b.n12=a.n14*a.n33*a.n42-a.n13*a.n34*a.n42-a.n14*a.n32*a.n43+a.n12*a.n34*a.n43+a.n13*a.n32*a.n44-a.n12*a.n33*a.n44;b.n13=a.n13*a.n24*a.n42-a.n14*a.n23*a.n42+a.n14*a.n22*a.n43-a.n12*a.n24*a.n43-a.n13*a.n22*a.n44+a.n12*a.n23*a.n44;b.n14=a.n14*a.n23*a.n32-a.n13*a.n24*a.n32-a.n14*a.n22*a.n33+a.n12*a.n24*a.n33+a.n13*a.n22*a.n34-a.n12*
 THREE.Matrix4.makeInvert=function(a){var b=new THREE.Matrix4;b.n11=a.n23*a.n34*a.n42-a.n24*a.n33*a.n42+a.n24*a.n32*a.n43-a.n22*a.n34*a.n43-a.n23*a.n32*a.n44+a.n22*a.n33*a.n44;b.n12=a.n14*a.n33*a.n42-a.n13*a.n34*a.n42-a.n14*a.n32*a.n43+a.n12*a.n34*a.n43+a.n13*a.n32*a.n44-a.n12*a.n33*a.n44;b.n13=a.n13*a.n24*a.n42-a.n14*a.n23*a.n42+a.n14*a.n22*a.n43-a.n12*a.n24*a.n43-a.n13*a.n22*a.n44+a.n12*a.n23*a.n44;b.n14=a.n14*a.n23*a.n32-a.n13*a.n24*a.n32-a.n14*a.n22*a.n33+a.n12*a.n24*a.n33+a.n13*a.n22*a.n34-a.n12*
 a.n23*a.n34;b.n21=a.n24*a.n33*a.n41-a.n23*a.n34*a.n41-a.n24*a.n31*a.n43+a.n21*a.n34*a.n43+a.n23*a.n31*a.n44-a.n21*a.n33*a.n44;b.n22=a.n13*a.n34*a.n41-a.n14*a.n33*a.n41+a.n14*a.n31*a.n43-a.n11*a.n34*a.n43-a.n13*a.n31*a.n44+a.n11*a.n33*a.n44;b.n23=a.n14*a.n23*a.n41-a.n13*a.n24*a.n41-a.n14*a.n21*a.n43+a.n11*a.n24*a.n43+a.n13*a.n21*a.n44-a.n11*a.n23*a.n44;b.n24=a.n13*a.n24*a.n31-a.n14*a.n23*a.n31+a.n14*a.n21*a.n33-a.n11*a.n24*a.n33-a.n13*a.n21*a.n34+a.n11*a.n23*a.n34;b.n31=a.n22*a.n34*a.n41-a.n24*a.n32*
 a.n23*a.n34;b.n21=a.n24*a.n33*a.n41-a.n23*a.n34*a.n41-a.n24*a.n31*a.n43+a.n21*a.n34*a.n43+a.n23*a.n31*a.n44-a.n21*a.n33*a.n44;b.n22=a.n13*a.n34*a.n41-a.n14*a.n33*a.n41+a.n14*a.n31*a.n43-a.n11*a.n34*a.n43-a.n13*a.n31*a.n44+a.n11*a.n33*a.n44;b.n23=a.n14*a.n23*a.n41-a.n13*a.n24*a.n41-a.n14*a.n21*a.n43+a.n11*a.n24*a.n43+a.n13*a.n21*a.n44-a.n11*a.n23*a.n44;b.n24=a.n13*a.n24*a.n31-a.n14*a.n23*a.n31+a.n14*a.n21*a.n33-a.n11*a.n24*a.n33-a.n13*a.n21*a.n34+a.n11*a.n23*a.n34;b.n31=a.n22*a.n34*a.n41-a.n24*a.n32*
 a.n41+a.n24*a.n31*a.n42-a.n21*a.n34*a.n42-a.n22*a.n31*a.n44+a.n21*a.n32*a.n44;b.n32=a.n14*a.n32*a.n41-a.n12*a.n34*a.n41-a.n14*a.n31*a.n42+a.n11*a.n34*a.n42+a.n12*a.n31*a.n44-a.n11*a.n32*a.n44;b.n33=a.n13*a.n24*a.n41-a.n14*a.n22*a.n41+a.n14*a.n21*a.n42-a.n11*a.n24*a.n42-a.n12*a.n21*a.n44+a.n11*a.n22*a.n44;b.n34=a.n14*a.n22*a.n31-a.n12*a.n24*a.n31-a.n14*a.n21*a.n32+a.n11*a.n24*a.n32+a.n12*a.n21*a.n34-a.n11*a.n22*a.n34;b.n41=a.n23*a.n32*a.n41-a.n22*a.n33*a.n41-a.n23*a.n31*a.n42+a.n21*a.n33*a.n42+a.n22*
 a.n41+a.n24*a.n31*a.n42-a.n21*a.n34*a.n42-a.n22*a.n31*a.n44+a.n21*a.n32*a.n44;b.n32=a.n14*a.n32*a.n41-a.n12*a.n34*a.n41-a.n14*a.n31*a.n42+a.n11*a.n34*a.n42+a.n12*a.n31*a.n44-a.n11*a.n32*a.n44;b.n33=a.n13*a.n24*a.n41-a.n14*a.n22*a.n41+a.n14*a.n21*a.n42-a.n11*a.n24*a.n42-a.n12*a.n21*a.n44+a.n11*a.n22*a.n44;b.n34=a.n14*a.n22*a.n31-a.n12*a.n24*a.n31-a.n14*a.n21*a.n32+a.n11*a.n24*a.n32+a.n12*a.n21*a.n34-a.n11*a.n22*a.n34;b.n41=a.n23*a.n32*a.n41-a.n22*a.n33*a.n41-a.n23*a.n31*a.n42+a.n21*a.n33*a.n42+a.n22*
 a.n31*a.n43-a.n21*a.n32*a.n43;b.n42=a.n12*a.n33*a.n41-a.n13*a.n32*a.n41+a.n13*a.n31*a.n42-a.n11*a.n33*a.n42-a.n12*a.n31*a.n43+a.n11*a.n32*a.n43;b.n43=a.n13*a.n22*a.n41-a.n12*a.n23*a.n41-a.n13*a.n21*a.n42+a.n11*a.n23*a.n42+a.n12*a.n21*a.n43-a.n11*a.n22*a.n43;b.n44=a.n12*a.n23*a.n31-a.n13*a.n22*a.n31+a.n13*a.n21*a.n32-a.n11*a.n23*a.n32-a.n12*a.n21*a.n33+a.n11*a.n22*a.n33;b.multiplyScalar(1/a.determinant());return b};
 a.n31*a.n43-a.n21*a.n32*a.n43;b.n42=a.n12*a.n33*a.n41-a.n13*a.n32*a.n41+a.n13*a.n31*a.n42-a.n11*a.n33*a.n42-a.n12*a.n31*a.n43+a.n11*a.n32*a.n43;b.n43=a.n13*a.n22*a.n41-a.n12*a.n23*a.n41-a.n13*a.n21*a.n42+a.n11*a.n23*a.n42+a.n12*a.n21*a.n43-a.n11*a.n22*a.n43;b.n44=a.n12*a.n23*a.n31-a.n13*a.n22*a.n31+a.n13*a.n21*a.n32-a.n11*a.n23*a.n32-a.n12*a.n21*a.n33+a.n11*a.n22*a.n33;b.multiplyScalar(1/a.determinant());return b};
-THREE.Matrix4.makeInvert3x3=function(a){var b=a.flatten();a=new THREE.Matrix3;var d=b[10]*b[5]-b[6]*b[9],e=-b[10]*b[1]+b[2]*b[9],f=b[6]*b[1]-b[2]*b[5],j=-b[10]*b[4]+b[6]*b[8],k=b[10]*b[0]-b[2]*b[8],g=-b[6]*b[0]+b[2]*b[4],o=b[9]*b[4]-b[5]*b[8],c=-b[9]*b[0]+b[1]*b[8],s=b[5]*b[0]-b[1]*b[4];b=b[0]*d+b[1]*j+b[2]*o;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*d;a.m[1]=b*e;a.m[2]=b*f;a.m[3]=b*j;a.m[4]=b*k;a.m[5]=b*g;a.m[6]=b*o;a.m[7]=b*c;a.m[8]=b*s;return a};
-THREE.Matrix4.makeFrustum=function(a,b,d,e,f,j){var k,g,o;k=new THREE.Matrix4;g=2*f/(b-a);o=2*f/(e-d);a=(b+a)/(b-a);d=(e+d)/(e-d);e=-(j+f)/(j-f);f=-2*j*f/(j-f);k.n11=g;k.n12=0;k.n13=a;k.n14=0;k.n21=0;k.n22=o;k.n23=d;k.n24=0;k.n31=0;k.n32=0;k.n33=e;k.n34=f;k.n41=0;k.n42=0;k.n43=-1;k.n44=0;return k};THREE.Matrix4.makePerspective=function(a,b,d,e){var f;a=d*Math.tan(a*Math.PI/360);f=-a;return THREE.Matrix4.makeFrustum(f*b,a*b,f,a,d,e)};
-THREE.Matrix4.makeOrtho=function(a,b,d,e,f,j){var k,g,o,c;k=new THREE.Matrix4;g=b-a;o=d-e;c=j-f;a=(b+a)/g;d=(d+e)/o;f=(j+f)/c;k.n11=2/g;k.n12=0;k.n13=0;k.n14=-a;k.n21=0;k.n22=2/o;k.n23=0;k.n24=-d;k.n31=0;k.n32=0;k.n33=-2/c;k.n34=-f;k.n41=0;k.n42=0;k.n43=0;k.n44=1;return k};
+THREE.Matrix4.makeInvert3x3=function(a){var b=a.flatten();a=new THREE.Matrix3;var d=b[10]*b[5]-b[6]*b[9],e=-b[10]*b[1]+b[2]*b[9],f=b[6]*b[1]-b[2]*b[5],j=-b[10]*b[4]+b[6]*b[8],k=b[10]*b[0]-b[2]*b[8],g=-b[6]*b[0]+b[2]*b[4],p=b[9]*b[4]-b[5]*b[8],c=-b[9]*b[0]+b[1]*b[8],t=b[5]*b[0]-b[1]*b[4];b=b[0]*d+b[1]*j+b[2]*p;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*d;a.m[1]=b*e;a.m[2]=b*f;a.m[3]=b*j;a.m[4]=b*k;a.m[5]=b*g;a.m[6]=b*p;a.m[7]=b*c;a.m[8]=b*t;return a};
+THREE.Matrix4.makeFrustum=function(a,b,d,e,f,j){var k,g,p;k=new THREE.Matrix4;g=2*f/(b-a);p=2*f/(e-d);a=(b+a)/(b-a);d=(e+d)/(e-d);e=-(j+f)/(j-f);f=-2*j*f/(j-f);k.n11=g;k.n12=0;k.n13=a;k.n14=0;k.n21=0;k.n22=p;k.n23=d;k.n24=0;k.n31=0;k.n32=0;k.n33=e;k.n34=f;k.n41=0;k.n42=0;k.n43=-1;k.n44=0;return k};THREE.Matrix4.makePerspective=function(a,b,d,e){var f;a=d*Math.tan(a*Math.PI/360);f=-a;return THREE.Matrix4.makeFrustum(f*b,a*b,f,a,d,e)};
+THREE.Matrix4.makeOrtho=function(a,b,d,e,f,j){var k,g,p,c;k=new THREE.Matrix4;g=b-a;p=d-e;c=j-f;a=(b+a)/g;d=(d+e)/p;f=(j+f)/c;k.n11=2/g;k.n12=0;k.n13=0;k.n14=-a;k.n21=0;k.n22=2/p;k.n23=0;k.n24=-d;k.n31=0;k.n32=0;k.n33=-2/c;k.n34=-f;k.n41=0;k.n42=0;k.n43=0;k.n44=1;return k};
 THREE.Vertex=function(a,b){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=b||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}};
 THREE.Vertex=function(a,b){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=b||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}};
 THREE.Face3=function(a,b,d,e,f){this.a=a;this.b=b;this.c=d;this.centroid=new THREE.Vector3;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.material=f instanceof Array?f:[f]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
 THREE.Face3=function(a,b,d,e,f){this.a=a;this.b=b;this.c=d;this.centroid=new THREE.Vector3;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.material=f instanceof Array?f:[f]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
 THREE.Face4=function(a,b,d,e,f,j){this.a=a;this.b=b;this.c=d;this.d=e;this.centroid=new THREE.Vector3;this.normal=f instanceof THREE.Vector3?f:new THREE.Vector3;this.vertexNormals=f instanceof Array?f:[];this.material=j instanceof Array?j:[j]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
 THREE.Face4=function(a,b,d,e,f,j){this.a=a;this.b=b;this.c=d;this.d=e;this.centroid=new THREE.Vector3;this.normal=f instanceof THREE.Vector3?f:new THREE.Vector3;this.vertexNormals=f instanceof Array?f:[];this.material=j instanceof Array?j:[j]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
 THREE.UV.prototype={copy:function(a){this.u=a.u;this.v=a.v},toString:function(){return"THREE.UV ("+this.u+", "+this.v+")"}};THREE.Geometry=function(){this.vertices=[];this.faces=[];this.uvs=[];this.geometryChunks={}};
 THREE.UV.prototype={copy:function(a){this.u=a.u;this.v=a.v},toString:function(){return"THREE.UV ("+this.u+", "+this.v+")"}};THREE.Geometry=function(){this.vertices=[];this.faces=[];this.uvs=[];this.geometryChunks={}};
 THREE.Geometry.prototype={computeCentroids:function(){var a,b,d;a=0;for(b=this.faces.length;a<b;a++){d=this.faces[a];d.centroid.set(0,0,0);d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);if(d instanceof THREE.Face3)d.centroid.divideScalar(3);else if(d instanceof THREE.Face4){d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeNormals:function(a){var b,d,e,f,j,k,g=new THREE.Vector3,
 THREE.Geometry.prototype={computeCentroids:function(){var a,b,d;a=0;for(b=this.faces.length;a<b;a++){d=this.faces[a];d.centroid.set(0,0,0);d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);if(d instanceof THREE.Face3)d.centroid.divideScalar(3);else if(d instanceof THREE.Face4){d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeNormals:function(a){var b,d,e,f,j,k,g=new THREE.Vector3,
-o=new THREE.Vector3;e=0;for(f=this.vertices.length;e<f;e++){j=this.vertices[e];j.normal.set(0,0,0)}e=0;for(f=this.faces.length;e<f;e++){j=this.faces[e];if(a&&j.vertexNormals.length){g.set(0,0,0);b=0;for(d=j.normal.length;b<d;b++)g.addSelf(j.vertexNormals[b]);g.divideScalar(3)}else{b=this.vertices[j.a];d=this.vertices[j.b];k=this.vertices[j.c];g.sub(k.position,d.position);o.sub(b.position,d.position);g.crossSelf(o)}g.isZero()||g.normalize();j.normal.copy(g)}},computeBoundingBox:function(){if(this.vertices.length>
-0){this.bbox={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 a=1,b=this.vertices.length;a<b;a++){vertex=this.vertices[a];if(vertex.position.x<this.bbox.x[0])this.bbox.x[0]=vertex.position.x;else if(vertex.position.x>this.bbox.x[1])this.bbox.x[1]=vertex.position.x;if(vertex.position.y<this.bbox.y[0])this.bbox.y[0]=vertex.position.y;else if(vertex.position.y>
-this.bbox.y[1])this.bbox.y[1]=vertex.position.y;if(vertex.position.z<this.bbox.z[0])this.bbox.z[0]=vertex.position.z;else if(vertex.position.z>this.bbox.z[1])this.bbox.z[1]=vertex.position.z}}},sortFacesByMaterial:function(){function a(s){var F=[];b=0;for(d=s.length;b<d;b++)s[b]==undefined?F.push("undefined"):F.push(s[b].toString());return F.join("_")}var b,d,e,f,j,k,g,o,c={};e=0;for(f=this.faces.length;e<f;e++){j=this.faces[e];k=j.material;g=a(k);if(c[g]==undefined)c[g]={hash:g,counter:0};o=c[g].hash+
-"_"+c[g].counter;if(this.geometryChunks[o]==undefined)this.geometryChunks[o]={faces:[],material:k,vertices:0};j=j instanceof THREE.Face3?3:4;if(this.geometryChunks[o].vertices+j>65535){c[g].counter+=1;o=c[g].hash+"_"+c[g].counter;if(this.geometryChunks[o]==undefined)this.geometryChunks[o]={faces:[],material:k,vertices:0}}this.geometryChunks[o].faces.push(e);this.geometryChunks[o].vertices+=j}},toString:function(){return"THREE.Geometry ( vertices: "+this.vertices+", faces: "+this.faces+" )"}};
+p=new THREE.Vector3;e=0;for(f=this.vertices.length;e<f;e++){j=this.vertices[e];j.normal.set(0,0,0)}e=0;for(f=this.faces.length;e<f;e++){j=this.faces[e];if(a&&j.vertexNormals.length){g.set(0,0,0);b=0;for(d=j.normal.length;b<d;b++)g.addSelf(j.vertexNormals[b]);g.divideScalar(3)}else{b=this.vertices[j.a];d=this.vertices[j.b];k=this.vertices[j.c];g.sub(k.position,d.position);p.sub(b.position,d.position);g.crossSelf(p)}g.isZero()||g.normalize();j.normal.copy(g)}},computeVertexNormals:function(){var a,
+b;a=0;for(b=this.faces.length;a<b;a++);},computeBoundingBox:function(){if(this.vertices.length>0){this.bbox={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 a=1,b=this.vertices.length;a<b;a++){vertex=this.vertices[a];if(vertex.position.x<this.bbox.x[0])this.bbox.x[0]=vertex.position.x;else if(vertex.position.x>this.bbox.x[1])this.bbox.x[1]=vertex.position.x;
+if(vertex.position.y<this.bbox.y[0])this.bbox.y[0]=vertex.position.y;else if(vertex.position.y>this.bbox.y[1])this.bbox.y[1]=vertex.position.y;if(vertex.position.z<this.bbox.z[0])this.bbox.z[0]=vertex.position.z;else if(vertex.position.z>this.bbox.z[1])this.bbox.z[1]=vertex.position.z}}},sortFacesByMaterial:function(){function a(t){var F=[];b=0;for(d=t.length;b<d;b++)t[b]==undefined?F.push("undefined"):F.push(t[b].toString());return F.join("_")}var b,d,e,f,j,k,g,p,c={};e=0;for(f=this.faces.length;e<
+f;e++){j=this.faces[e];k=j.material;g=a(k);if(c[g]==undefined)c[g]={hash:g,counter:0};p=c[g].hash+"_"+c[g].counter;if(this.geometryChunks[p]==undefined)this.geometryChunks[p]={faces:[],material:k,vertices:0};j=j instanceof THREE.Face3?3:4;if(this.geometryChunks[p].vertices+j>65535){c[g].counter+=1;p=c[g].hash+"_"+c[g].counter;if(this.geometryChunks[p]==undefined)this.geometryChunks[p]={faces:[],material:k,vertices:0}}this.geometryChunks[p].faces.push(e);this.geometryChunks[p].vertices+=j}},toString:function(){return"THREE.Geometry ( vertices: "+
+this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
 THREE.Camera=function(a,b,d,e){this.position=new THREE.Vector3(0,0,0);this.target={position:new THREE.Vector3(0,0,0)};this.up=new THREE.Vector3(0,1,0);this.matrix=new THREE.Matrix4;this.projectionMatrix=THREE.Matrix4.makePerspective(a,b,d,e);this.autoUpdateMatrix=true;this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.toString=function(){return"THREE.Camera ( "+this.position+", "+this.target.position+" )"}};THREE.Light=function(a){this.color=new THREE.Color(a)};
 THREE.Camera=function(a,b,d,e){this.position=new THREE.Vector3(0,0,0);this.target={position:new THREE.Vector3(0,0,0)};this.up=new THREE.Vector3(0,1,0);this.matrix=new THREE.Matrix4;this.projectionMatrix=THREE.Matrix4.makePerspective(a,b,d,e);this.autoUpdateMatrix=true;this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.toString=function(){return"THREE.Camera ( "+this.position+", "+this.target.position+" )"}};THREE.Light=function(a){this.color=new THREE.Color(a)};
 THREE.AmbientLight=function(a){THREE.Light.call(this,a)};THREE.AmbientLight.prototype=new THREE.Light;THREE.AmbientLight.prototype.constructor=THREE.AmbientLight;THREE.DirectionalLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,1,0);this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.DirectionalLight;
 THREE.AmbientLight=function(a){THREE.Light.call(this,a)};THREE.AmbientLight.prototype=new THREE.Light;THREE.AmbientLight.prototype.constructor=THREE.AmbientLight;THREE.DirectionalLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,1,0);this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.DirectionalLight;
 THREE.PointLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3;this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.PointLight;
 THREE.PointLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3;this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.PointLight;
@@ -82,126 +83,126 @@ this.blending+"<br/>)"}};THREE.ParticleCircleMaterial=function(a){this.color=new
 THREE.ParticleDOMMaterial=function(a){this.domElement=a;this.toString=function(){return"THREE.ParticleDOMMaterial ( domElement: "+this.domElement+" )"}};THREE.Texture=function(a,b,d,e){this.image=a;this.loaded=false;this.mapping=b!==undefined?b:THREE.UVMapping;this.wrap_s=d!==undefined?d:THREE.ClampToEdge;this.wrap_t=e!==undefined?e:THREE.ClampToEdge;this.toString=function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>wrap_s: "+this.wrap_s+"<br/>wrap_t: "+this.wrap_t+"<br/>)"}};
 THREE.ParticleDOMMaterial=function(a){this.domElement=a;this.toString=function(){return"THREE.ParticleDOMMaterial ( domElement: "+this.domElement+" )"}};THREE.Texture=function(a,b,d,e){this.image=a;this.loaded=false;this.mapping=b!==undefined?b:THREE.UVMapping;this.wrap_s=d!==undefined?d:THREE.ClampToEdge;this.wrap_t=e!==undefined?e:THREE.ClampToEdge;this.toString=function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>wrap_s: "+this.wrap_s+"<br/>wrap_t: "+this.wrap_t+"<br/>)"}};
 THREE.UVMapping=0;THREE.ReflectionMapping=1;THREE.RefractionMapping=2;THREE.Multiply=0;THREE.Mix=1;THREE.Repeat=0;THREE.ClampToEdge=1;THREE.MirroredRepeat=2;THREE.TextureCube=function(a,b){this.image=a;this.mapping=b?b:THREE.ReflectionMap;this.toString=function(){return"THREE.TextureCube (<br/>image: "+this.image+"<br/>mapping: "+this.mapping+"<br/>)"}};
 THREE.UVMapping=0;THREE.ReflectionMapping=1;THREE.RefractionMapping=2;THREE.Multiply=0;THREE.Mix=1;THREE.Repeat=0;THREE.ClampToEdge=1;THREE.MirroredRepeat=2;THREE.TextureCube=function(a,b){this.image=a;this.mapping=b?b:THREE.ReflectionMap;this.toString=function(){return"THREE.TextureCube (<br/>image: "+this.image+"<br/>mapping: "+this.mapping+"<br/>)"}};
 THREE.Scene=function(){this.objects=[];this.lights=[];this.addObject=function(a){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.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.Scene=function(){this.objects=[];this.lights=[];this.addObject=function(a){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.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.Projector=function(){function a(A,n){var h=0,i=1,p=A.z+A.w,x=n.z+n.w,m=-A.z+A.w,l=-n.z+n.w;if(p>=0&&x>=0&&m>=0&&l>=0)return true;else if(p<0&&x<0||m<0&&l<0)return false;else{if(p<0)h=Math.max(h,p/(p-x));else if(x<0)i=Math.min(i,p/(p-x));if(m<0)h=Math.max(h,m/(m-l));else if(l<0)i=Math.min(i,m/(m-l));if(i<h)return false;else{A.lerpSelf(n,h);n.lerpSelf(A,1-i);return true}}}var b=null,d,e,f,j=[],k,g,o=[],c,s,F=[],r=new THREE.Vector4,w=new THREE.Matrix4,v=new THREE.Matrix4,y=new THREE.Vector4,L=
-new THREE.Vector4,u;this.projectScene=function(A,n){var h,i,p,x,m,l,E,B,Q,G,V,U,D,P,C,J,I;b=[];f=g=s=0;n.autoUpdateMatrix&&n.updateMatrix();w.multiply(n.projectionMatrix,n.matrix);E=A.objects;h=0;for(i=E.length;h<i;h++){B=E[h];B.autoUpdateMatrix&&B.updateMatrix();Q=B.matrix;G=B.rotationMatrix;V=B.material;U=B.overdraw;if(B instanceof THREE.Mesh){D=B.geometry.vertices;p=0;for(x=D.length;p<x;p++){P=D[p];P.positionWorld.copy(P.position);Q.transformVector3(P.positionWorld);C=P.positionScreen;C.copy(P.positionWorld);
-w.transformVector4(C);C.multiplyScalar(1/C.w);P.__visible=C.z>0&&C.z<1}P=B.geometry.faces;p=0;for(x=P.length;p<x;p++){C=P[p];if(C instanceof THREE.Face3){m=D[C.a];l=D[C.b];J=D[C.c];if(m.__visible&&l.__visible&&J.__visible)if(B.doubleSided||B.flipSided!=(J.positionScreen.x-m.positionScreen.x)*(l.positionScreen.y-m.positionScreen.y)-(J.positionScreen.y-m.positionScreen.y)*(l.positionScreen.x-m.positionScreen.x)<0){d=j[f]=j[f]||new THREE.RenderableFace3;d.v1.positionWorld.copy(m.positionWorld);d.v2.positionWorld.copy(l.positionWorld);
-d.v3.positionWorld.copy(J.positionWorld);d.v1.positionScreen.copy(m.positionScreen);d.v2.positionScreen.copy(l.positionScreen);d.v3.positionScreen.copy(J.positionScreen);d.normalWorld.copy(C.normal);G.transformVector3(d.normalWorld);d.centroidWorld.copy(C.centroid);Q.transformVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);w.transformVector3(d.centroidScreen);J=C.vertexNormals;u=d.vertexNormalsWorld;m=0;for(l=J.length;m<l;m++){I=u[m]=u[m]||new THREE.Vector3;I.copy(J[m]);G.transformVector3(I)}d.z=
-d.centroidScreen.z;d.meshMaterial=V;d.faceMaterial=C.material;d.overdraw=U;if(B.geometry.uvs[p]){d.uvs[0]=B.geometry.uvs[p][0];d.uvs[1]=B.geometry.uvs[p][1];d.uvs[2]=B.geometry.uvs[p][2]}b.push(d);f++}}else if(C instanceof THREE.Face4){m=D[C.a];l=D[C.b];J=D[C.c];I=D[C.d];if(m.__visible&&l.__visible&&J.__visible&&I.__visible)if(B.doubleSided||B.flipSided!=((I.positionScreen.x-m.positionScreen.x)*(l.positionScreen.y-m.positionScreen.y)-(I.positionScreen.y-m.positionScreen.y)*(l.positionScreen.x-m.positionScreen.x)<
-0||(l.positionScreen.x-J.positionScreen.x)*(I.positionScreen.y-J.positionScreen.y)-(l.positionScreen.y-J.positionScreen.y)*(I.positionScreen.x-J.positionScreen.x)<0)){d=j[f]=j[f]||new THREE.RenderableFace3;d.v1.positionWorld.copy(m.positionWorld);d.v2.positionWorld.copy(l.positionWorld);d.v3.positionWorld.copy(I.positionWorld);d.v1.positionScreen.copy(m.positionScreen);d.v2.positionScreen.copy(l.positionScreen);d.v3.positionScreen.copy(I.positionScreen);d.normalWorld.copy(C.normal);G.transformVector3(d.normalWorld);
-d.centroidWorld.copy(C.centroid);Q.transformVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);w.transformVector3(d.centroidScreen);d.z=d.centroidScreen.z;d.meshMaterial=V;d.faceMaterial=C.material;d.overdraw=U;if(B.geometry.uvs[p]){d.uvs[0]=B.geometry.uvs[p][0];d.uvs[1]=B.geometry.uvs[p][1];d.uvs[2]=B.geometry.uvs[p][3]}b.push(d);f++;e=j[f]=j[f]||new THREE.RenderableFace3;e.v1.positionWorld.copy(l.positionWorld);e.v2.positionWorld.copy(J.positionWorld);e.v3.positionWorld.copy(I.positionWorld);
-e.v1.positionScreen.copy(l.positionScreen);e.v2.positionScreen.copy(J.positionScreen);e.v3.positionScreen.copy(I.positionScreen);e.normalWorld.copy(d.normalWorld);e.centroidWorld.copy(d.centroidWorld);e.centroidScreen.copy(d.centroidScreen);e.z=e.centroidScreen.z;e.meshMaterial=V;e.faceMaterial=C.material;e.overdraw=U;if(B.geometry.uvs[p]){e.uvs[0]=B.geometry.uvs[p][1];e.uvs[1]=B.geometry.uvs[p][2];e.uvs[2]=B.geometry.uvs[p][3]}b.push(e);f++}}}}else if(B instanceof THREE.Line){v.multiply(w,Q);D=B.geometry.vertices;
-P=D[0];P.positionScreen.copy(P.position);v.transformVector4(P.positionScreen);p=1;for(x=D.length;p<x;p++){m=D[p];m.positionScreen.copy(m.position);v.transformVector4(m.positionScreen);l=D[p-1];y.copy(m.positionScreen);L.copy(l.positionScreen);if(a(y,L)){y.multiplyScalar(1/y.w);L.multiplyScalar(1/L.w);k=o[g]=o[g]||new THREE.RenderableLine;k.v1.positionScreen.copy(y);k.v2.positionScreen.copy(L);k.z=Math.max(y.z,L.z);k.material=B.material;b.push(k);g++}}}else if(B instanceof THREE.Particle){r.set(B.position.x,
-B.position.y,B.position.z,1);w.transformVector4(r);r.z/=r.w;if(r.z>0&&r.z<1){c=F[s]=F[s]||new THREE.RenderableParticle;c.x=r.x/r.w;c.y=r.y/r.w;c.z=r.z;c.rotation=B.rotation.z;c.scale.x=B.scale.x*Math.abs(c.x-(r.x+n.projectionMatrix.n11)/(r.w+n.projectionMatrix.n14));c.scale.y=B.scale.y*Math.abs(c.y-(r.y+n.projectionMatrix.n22)/(r.w+n.projectionMatrix.n24));c.material=B.material;b.push(c);s++}}}b.sort(function(T,N){return N.z-T.z});return b};this.unprojectVector=function(A,n){var h=new THREE.Matrix4;
-h.multiply(THREE.Matrix4.makeInvert(n.matrix),THREE.Matrix4.makeInvert(n.projectionMatrix));h.transformVector3(A);return A}};
-THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,d,e,f,j;this.domElement=document.createElement("div");this.setSize=function(k,g){d=k;e=g;f=d/2;j=e/2};this.render=function(k,g){var o,c,s,F,r,w,v,y;a=b.projectScene(k,g);o=0;for(c=a.length;o<c;o++){r=a[o];if(r instanceof THREE.RenderableParticle){v=r.x*f+f;y=r.y*j+j;s=0;for(F=r.material.length;s<F;s++){w=r.material[s];if(w instanceof THREE.ParticleDOMMaterial){w=w.domElement;w.style.left=v+"px";w.style.top=y+"px"}}}}}};
-THREE.CanvasRenderer=function(){function a(R,aa,Z,O){var H,S,ca,X,$=R.lights;R=0;for(H=$.length;R<H;R++){S=$[R];ca=S.color;X=S.intensity;if(S instanceof THREE.DirectionalLight){S=Z.dot(S.position)*X;if(S>0){O.r+=ca.r*S;O.g+=ca.g*S;O.b+=ca.b*S}}else if(S instanceof THREE.PointLight){da.sub(S.position,aa);da.normalize();S=Z.dot(da)*X;if(S>0){O.r+=ca.r*S;O.g+=ca.g*S;O.b+=ca.b*S}}}}function b(R,aa,Z,O,H,S){if(H.opacity!=0){j(H.opacity);k(H.blending);Q=R.positionScreen.x;G=R.positionScreen.y;V=aa.positionScreen.x;
-U=aa.positionScreen.y;D=Z.positionScreen.x;P=Z.positionScreen.y;var ca=Q,X=G,$=V,ea=U,ba=D,fa=P;u.beginPath();u.moveTo(ca,X);u.lineTo($,ea);u.lineTo(ba,fa);u.lineTo(ca,X);u.closePath();if(H instanceof THREE.MeshBasicMaterial)if(H.map&&H.map.loaded)f(Q,G,V,U,D,P,H.map.image,O.uvs[0].u,O.uvs[0].v,O.uvs[1].u,O.uvs[1].v,O.uvs[2].u,O.uvs[2].v);else if(H.env_map&&H.env_map.loaded){if(H.env_map.mapping==THREE.ReflectionMapping){da.copy(O.vertexNormalsWorld[0]);z=(da.x*camera.matrix.n11+da.y*camera.matrix.n12+
+THREE.Projector=function(){function a(A,o){var i=0,n=1,h=A.z+A.w,x=o.z+o.w,m=-A.z+A.w,l=-o.z+o.w;if(h>=0&&x>=0&&m>=0&&l>=0)return true;else if(h<0&&x<0||m<0&&l<0)return false;else{if(h<0)i=Math.max(i,h/(h-x));else if(x<0)n=Math.min(n,h/(h-x));if(m<0)i=Math.max(i,m/(m-l));else if(l<0)n=Math.min(n,m/(m-l));if(n<i)return false;else{A.lerpSelf(o,i);o.lerpSelf(A,1-n);return true}}}var b=null,d,e,f,j=[],k,g,p=[],c,t,F=[],r=new THREE.Vector4,w=new THREE.Matrix4,v=new THREE.Matrix4,y=new THREE.Vector4,L=
+new THREE.Vector4,u;this.projectScene=function(A,o){var i,n,h,x,m,l,B,C,Q,J,P,S,E,T,D,I,H;b=[];f=g=t=0;o.autoUpdateMatrix&&o.updateMatrix();w.multiply(o.projectionMatrix,o.matrix);B=A.objects;i=0;for(n=B.length;i<n;i++){C=B[i];C.autoUpdateMatrix&&C.updateMatrix();Q=C.matrix;J=C.rotationMatrix;P=C.material;S=C.overdraw;if(C instanceof THREE.Mesh){E=C.geometry.vertices;h=0;for(x=E.length;h<x;h++){T=E[h];T.positionWorld.copy(T.position);Q.multiplyVector3(T.positionWorld);D=T.positionScreen;D.copy(T.positionWorld);
+w.multiplyVector4(D);D.multiplyScalar(1/D.w);T.__visible=D.z>0&&D.z<1}T=C.geometry.faces;h=0;for(x=T.length;h<x;h++){D=T[h];if(D instanceof THREE.Face3){m=E[D.a];l=E[D.b];I=E[D.c];if(m.__visible&&l.__visible&&I.__visible)if(C.doubleSided||C.flipSided!=(I.positionScreen.x-m.positionScreen.x)*(l.positionScreen.y-m.positionScreen.y)-(I.positionScreen.y-m.positionScreen.y)*(l.positionScreen.x-m.positionScreen.x)<0){d=j[f]=j[f]||new THREE.RenderableFace3;d.v1.positionWorld.copy(m.positionWorld);d.v2.positionWorld.copy(l.positionWorld);
+d.v3.positionWorld.copy(I.positionWorld);d.v1.positionScreen.copy(m.positionScreen);d.v2.positionScreen.copy(l.positionScreen);d.v3.positionScreen.copy(I.positionScreen);d.normalWorld.copy(D.normal);J.multiplyVector3(d.normalWorld);d.centroidWorld.copy(D.centroid);Q.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);w.multiplyVector3(d.centroidScreen);I=D.vertexNormals;u=d.vertexNormalsWorld;m=0;for(l=I.length;m<l;m++){H=u[m]=u[m]||new THREE.Vector3;H.copy(I[m]);J.multiplyVector3(H)}d.z=
+d.centroidScreen.z;d.meshMaterial=P;d.faceMaterial=D.material;d.overdraw=S;if(C.geometry.uvs[h]){d.uvs[0]=C.geometry.uvs[h][0];d.uvs[1]=C.geometry.uvs[h][1];d.uvs[2]=C.geometry.uvs[h][2]}b.push(d);f++}}else if(D instanceof THREE.Face4){m=E[D.a];l=E[D.b];I=E[D.c];H=E[D.d];if(m.__visible&&l.__visible&&I.__visible&&H.__visible)if(C.doubleSided||C.flipSided!=((H.positionScreen.x-m.positionScreen.x)*(l.positionScreen.y-m.positionScreen.y)-(H.positionScreen.y-m.positionScreen.y)*(l.positionScreen.x-m.positionScreen.x)<
+0||(l.positionScreen.x-I.positionScreen.x)*(H.positionScreen.y-I.positionScreen.y)-(l.positionScreen.y-I.positionScreen.y)*(H.positionScreen.x-I.positionScreen.x)<0)){d=j[f]=j[f]||new THREE.RenderableFace3;d.v1.positionWorld.copy(m.positionWorld);d.v2.positionWorld.copy(l.positionWorld);d.v3.positionWorld.copy(H.positionWorld);d.v1.positionScreen.copy(m.positionScreen);d.v2.positionScreen.copy(l.positionScreen);d.v3.positionScreen.copy(H.positionScreen);d.normalWorld.copy(D.normal);J.multiplyVector3(d.normalWorld);
+d.centroidWorld.copy(D.centroid);Q.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);w.multiplyVector3(d.centroidScreen);d.z=d.centroidScreen.z;d.meshMaterial=P;d.faceMaterial=D.material;d.overdraw=S;if(C.geometry.uvs[h]){d.uvs[0]=C.geometry.uvs[h][0];d.uvs[1]=C.geometry.uvs[h][1];d.uvs[2]=C.geometry.uvs[h][3]}b.push(d);f++;e=j[f]=j[f]||new THREE.RenderableFace3;e.v1.positionWorld.copy(l.positionWorld);e.v2.positionWorld.copy(I.positionWorld);e.v3.positionWorld.copy(H.positionWorld);
+e.v1.positionScreen.copy(l.positionScreen);e.v2.positionScreen.copy(I.positionScreen);e.v3.positionScreen.copy(H.positionScreen);e.normalWorld.copy(d.normalWorld);e.centroidWorld.copy(d.centroidWorld);e.centroidScreen.copy(d.centroidScreen);e.z=e.centroidScreen.z;e.meshMaterial=P;e.faceMaterial=D.material;e.overdraw=S;if(C.geometry.uvs[h]){e.uvs[0]=C.geometry.uvs[h][1];e.uvs[1]=C.geometry.uvs[h][2];e.uvs[2]=C.geometry.uvs[h][3]}b.push(e);f++}}}}else if(C instanceof THREE.Line){v.multiply(w,Q);E=C.geometry.vertices;
+T=E[0];T.positionScreen.copy(T.position);v.multiplyVector4(T.positionScreen);h=1;for(x=E.length;h<x;h++){m=E[h];m.positionScreen.copy(m.position);v.multiplyVector4(m.positionScreen);l=E[h-1];y.copy(m.positionScreen);L.copy(l.positionScreen);if(a(y,L)){y.multiplyScalar(1/y.w);L.multiplyScalar(1/L.w);k=p[g]=p[g]||new THREE.RenderableLine;k.v1.positionScreen.copy(y);k.v2.positionScreen.copy(L);k.z=Math.max(y.z,L.z);k.material=C.material;b.push(k);g++}}}else if(C instanceof THREE.Particle){r.set(C.position.x,
+C.position.y,C.position.z,1);w.multiplyVector4(r);r.z/=r.w;if(r.z>0&&r.z<1){c=F[t]=F[t]||new THREE.RenderableParticle;c.x=r.x/r.w;c.y=r.y/r.w;c.z=r.z;c.rotation=C.rotation.z;c.scale.x=C.scale.x*Math.abs(c.x-(r.x+o.projectionMatrix.n11)/(r.w+o.projectionMatrix.n14));c.scale.y=C.scale.y*Math.abs(c.y-(r.y+o.projectionMatrix.n22)/(r.w+o.projectionMatrix.n24));c.material=C.material;b.push(c);t++}}}b.sort(function(V,N){return N.z-V.z});return b};this.unprojectVector=function(A,o){var i=new THREE.Matrix4;
+i.multiply(THREE.Matrix4.makeInvert(o.matrix),THREE.Matrix4.makeInvert(o.projectionMatrix));i.multiplyVector3(A);return A}};
+THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,d,e,f,j;this.domElement=document.createElement("div");this.setSize=function(k,g){d=k;e=g;f=d/2;j=e/2};this.render=function(k,g){var p,c,t,F,r,w,v,y;a=b.projectScene(k,g);p=0;for(c=a.length;p<c;p++){r=a[p];if(r instanceof THREE.RenderableParticle){v=r.x*f+f;y=r.y*j+j;t=0;for(F=r.material.length;t<F;t++){w=r.material[t];if(w instanceof THREE.ParticleDOMMaterial){w=w.domElement;w.style.left=v+"px";w.style.top=y+"px"}}}}}};
+THREE.CanvasRenderer=function(){function a(R,aa,Z,O){var G,U,ca,X,$=R.lights;R=0;for(G=$.length;R<G;R++){U=$[R];ca=U.color;X=U.intensity;if(U instanceof THREE.DirectionalLight){U=Z.dot(U.position)*X;if(U>0){O.r+=ca.r*U;O.g+=ca.g*U;O.b+=ca.b*U}}else if(U instanceof THREE.PointLight){da.sub(U.position,aa);da.normalize();U=Z.dot(da)*X;if(U>0){O.r+=ca.r*U;O.g+=ca.g*U;O.b+=ca.b*U}}}}function b(R,aa,Z,O,G,U){if(G.opacity!=0){j(G.opacity);k(G.blending);Q=R.positionScreen.x;J=R.positionScreen.y;P=aa.positionScreen.x;
+S=aa.positionScreen.y;E=Z.positionScreen.x;T=Z.positionScreen.y;var ca=Q,X=J,$=P,ea=S,ba=E,fa=T;u.beginPath();u.moveTo(ca,X);u.lineTo($,ea);u.lineTo(ba,fa);u.lineTo(ca,X);u.closePath();if(G instanceof THREE.MeshBasicMaterial)if(G.map&&G.map.loaded)f(Q,J,P,S,E,T,G.map.image,O.uvs[0].u,O.uvs[0].v,O.uvs[1].u,O.uvs[1].v,O.uvs[2].u,O.uvs[2].v);else if(G.env_map&&G.env_map.loaded){if(G.env_map.mapping==THREE.ReflectionMapping){da.copy(O.vertexNormalsWorld[0]);z=(da.x*camera.matrix.n11+da.y*camera.matrix.n12+
 da.z*camera.matrix.n13)*0.5+0.5;K=-(da.x*camera.matrix.n21+da.y*camera.matrix.n22+da.z*camera.matrix.n23)*0.5+0.5;da.copy(O.vertexNormalsWorld[1]);W=(da.x*camera.matrix.n11+da.y*camera.matrix.n12+da.z*camera.matrix.n13)*0.5+0.5;ga=-(da.x*camera.matrix.n21+da.y*camera.matrix.n22+da.z*camera.matrix.n23)*0.5+0.5;da.copy(O.vertexNormalsWorld[2]);ma=(da.x*camera.matrix.n11+da.y*camera.matrix.n12+da.z*camera.matrix.n13)*0.5+0.5;ua=-(da.x*camera.matrix.n21+da.y*camera.matrix.n22+da.z*camera.matrix.n23)*
 da.z*camera.matrix.n13)*0.5+0.5;K=-(da.x*camera.matrix.n21+da.y*camera.matrix.n22+da.z*camera.matrix.n23)*0.5+0.5;da.copy(O.vertexNormalsWorld[1]);W=(da.x*camera.matrix.n11+da.y*camera.matrix.n12+da.z*camera.matrix.n13)*0.5+0.5;ga=-(da.x*camera.matrix.n21+da.y*camera.matrix.n22+da.z*camera.matrix.n23)*0.5+0.5;da.copy(O.vertexNormalsWorld[2]);ma=(da.x*camera.matrix.n11+da.y*camera.matrix.n12+da.z*camera.matrix.n13)*0.5+0.5;ua=-(da.x*camera.matrix.n21+da.y*camera.matrix.n22+da.z*camera.matrix.n23)*
-0.5+0.5;f(Q,G,V,U,D,P,H.env_map.image,z,K,W,ga,ma,ua)}}else H.wireframe?d(H.color.__styleString,H.wireframe_linewidth):e(H.color.__styleString);else if(H instanceof THREE.MeshLambertMaterial){if(H.map&&!H.wireframe){f(Q,G,V,U,D,P,H.map.image,O.uvs[0].u,O.uvs[0].v,O.uvs[1].u,O.uvs[1].v,O.uvs[2].u,O.uvs[2].v);k(THREE.SubtractiveBlending)}if(za)if(!H.wireframe&&H.shading==THREE.SmoothShading&&O.vertexNormalsWorld.length==3){J.r=I.r=T.r=ja.r;J.g=I.g=T.g=ja.g;J.b=I.b=T.b=ja.b;a(S,O.v1.positionWorld,O.vertexNormalsWorld[0],
-J);a(S,O.v2.positionWorld,O.vertexNormalsWorld[1],I);a(S,O.v3.positionWorld,O.vertexNormalsWorld[2],T);N.r=(I.r+T.r)*0.5;N.g=(I.g+T.g)*0.5;N.b=(I.b+T.b)*0.5;t=g(J,I,T,N);f(Q,G,V,U,D,P,t,0,0,1,0,0,1)}else{ka.r=ja.r;ka.g=ja.g;ka.b=ja.b;a(S,O.centroidWorld,O.normalWorld,ka);C.r=H.color.r*ka.r;C.g=H.color.g*ka.g;C.b=H.color.b*ka.b;C.updateStyleString();H.wireframe?d(C.__styleString,H.wireframe_linewidth):e(C.__styleString)}else H.wireframe?d(H.color.__styleString,H.wireframe_linewidth):e(H.color.__styleString)}else if(H instanceof
-THREE.MeshDepthMaterial){M=H.__2near;Y=H.__farPlusNear;q=H.__farMinusNear;J.r=J.g=J.b=1-M/(Y-R.positionScreen.z*q);I.r=I.g=I.b=1-M/(Y-aa.positionScreen.z*q);T.r=T.g=T.b=1-M/(Y-Z.positionScreen.z*q);N.r=(I.r+T.r)*0.5;N.g=(I.g+T.g)*0.5;N.b=(I.b+T.b)*0.5;t=g(J,I,T,N);f(Q,G,V,U,D,P,t,0,0,1,0,0,1)}else if(H instanceof THREE.MeshNormalMaterial){C.r=o(O.normalWorld.x);C.g=o(O.normalWorld.y);C.b=o(O.normalWorld.z);C.updateStyleString();H.wireframe?d(C.__styleString,H.wireframe_linewidth):e(C.__styleString)}}}
-function d(R,aa){if(h!=R)u.strokeStyle=h=R;if(p!=aa)u.lineWidth=p=aa;u.stroke();ha.inflate(aa*2)}function e(R){if(i!=R)u.fillStyle=i=R;u.fill()}function f(R,aa,Z,O,H,S,ca,X,$,ea,ba,fa,oa){var na,ia;na=ca.width-1;ia=ca.height-1;X*=na;$*=ia;ea*=na;ba*=ia;fa*=na;oa*=ia;Z-=R;O-=aa;H-=R;S-=aa;ea-=X;ba-=$;fa-=X;oa-=$;ia=1/(ea*oa-fa*ba);na=(oa*Z-ba*H)*ia;ba=(oa*O-ba*S)*ia;Z=(ea*H-fa*Z)*ia;O=(ea*S-fa*O)*ia;R=R-na*X-Z*$;aa=aa-ba*X-O*$;u.save();u.transform(na,ba,Z,O,R,aa);u.clip();u.drawImage(ca,0,0);u.restore()}
-function j(R){if(A!=R)u.globalAlpha=A=R}function k(R){if(n!=R){switch(R){case THREE.NormalBlending:u.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:u.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:u.globalCompositeOperation="darker"}n=R}}function g(R,aa,Z,O){la[0]=m(0,x(255,~~(R.r*255)));la[1]=m(0,x(255,~~(R.g*255)));la[2]=m(0,x(255,~~(R.b*255)));la[4]=m(0,x(255,~~(aa.r*255)));la[5]=m(0,x(255,~~(aa.g*255)));la[6]=m(0,x(255,~~(aa.b*255)));la[8]=m(0,
-x(255,~~(Z.r*255)));la[9]=m(0,x(255,~~(Z.g*255)));la[10]=m(0,x(255,~~(Z.b*255)));la[12]=m(0,x(255,~~(O.r*255)));la[13]=m(0,x(255,~~(O.g*255)));la[14]=m(0,x(255,~~(O.b*255)));va.putImageData(Aa,0,0);ya.drawImage(wa,0,0);return xa}function o(R){return R<0?x((1+R)*0.5,0.5):0.5+x(R*0.5,0.5)}function c(R,aa){var Z=aa.x-R.x,O=aa.y-R.y,H=1/Math.sqrt(Z*Z+O*O);Z*=H;O*=H;aa.x+=Z;aa.y+=O;R.x-=Z;R.y-=O}var s=null,F=new THREE.Projector,r=document.createElement("canvas"),w,v,y,L,u=r.getContext("2d"),A=1,n=0,h=
-null,i=null,p=1,x=Math.min,m=Math.max,l,E,B,Q,G,V,U,D,P,C=new THREE.Color,J=new THREE.Color,I=new THREE.Color,T=new THREE.Color,N=new THREE.Color,M,Y,q,t,z,K,W,ga,ma,ua,pa=new THREE.Rectangle,qa=new THREE.Rectangle,ha=new THREE.Rectangle,za=false,ka=new THREE.Color,ja=new THREE.Color,ra=new THREE.Color,sa=new THREE.Color,Da=Math.PI*2,da=new THREE.Vector3,wa,va,Aa,la,xa,ya,ta=16;wa=document.createElement("canvas");wa.width=wa.height=2;va=wa.getContext("2d");va.fillStyle="rgba(0,0,0,1)";va.fillRect(0,
-0,2,2);Aa=va.getImageData(0,0,2,2);la=Aa.data;xa=document.createElement("canvas");xa.width=xa.height=ta;ya=xa.getContext("2d");ya.translate(-ta/2,-ta/2);ya.scale(ta,ta);ta--;this.domElement=r;this.autoClear=true;this.setSize=function(R,aa){w=R;v=aa;y=w/2;L=v/2;r.width=w;r.height=v;pa.set(-y,-L,y,L)};this.clear=function(){if(!qa.isEmpty()){qa.inflate(1);qa.minSelf(pa);u.clearRect(qa.getX(),qa.getY(),qa.getWidth(),qa.getHeight());qa.empty()}};this.render=function(R,aa){var Z,O,H,S,ca,X,$,ea;u.setTransform(1,
-0,0,-1,y,L);this.autoClear&&this.clear();s=F.projectScene(R,aa);if(za=R.lights.length>0){ca=R.lights;ja.setRGB(0,0,0);ra.setRGB(0,0,0);sa.setRGB(0,0,0);Z=0;for(O=ca.length;Z<O;Z++){H=ca[Z];S=H.color;if(H instanceof THREE.AmbientLight){ja.r+=S.r;ja.g+=S.g;ja.b+=S.b}else if(H instanceof THREE.DirectionalLight){ra.r+=S.r;ra.g+=S.g;ra.b+=S.b}else if(H instanceof THREE.PointLight){sa.r+=S.r;sa.g+=S.g;sa.b+=S.b}}}Z=0;for(O=s.length;Z<O;Z++){H=s[Z];ha.empty();if(H instanceof THREE.RenderableParticle){l=
-H;l.x*=y;l.y*=L;S=0;for(ca=H.material.length;S<ca;S++){X=l;$=H;var ba=H.material[S];if(ba.opacity!=0){j(ba.opacity);k(ba.blending);ea=void 0;var fa=void 0,oa=void 0,na=void 0,ia=void 0,Ba=void 0,Ca=void 0;if(ba instanceof THREE.ParticleBasicMaterial){if(ba.map){ia=ba.map;Ba=ia.width>>1;Ca=ia.height>>1;oa=$.scale.x*y;na=$.scale.y*L;ea=oa*Ba;fa=na*Ca;ha.set(X.x-ea,X.y-fa,X.x+ea,X.y+fa);if(pa.instersects(ha)){u.save();u.translate(X.x,X.y);u.rotate(-$.rotation);u.scale(oa,-na);u.translate(-Ba,-Ca);u.drawImage(ia,
-0,0);u.restore()}}}else if(ba instanceof THREE.ParticleCircleMaterial){if(za){ka.r=ja.r+ra.r+sa.r;ka.g=ja.g+ra.g+sa.g;ka.b=ja.b+ra.b+sa.b;C.r=ba.color.r*ka.r;C.g=ba.color.g*ka.g;C.b=ba.color.b*ka.b;C.updateStyleString()}else C.__styleString=ba.color.__styleString;ea=$.scale.x*y;fa=$.scale.y*L;ha.set(X.x-ea,X.y-fa,X.x+ea,X.y+fa);if(pa.instersects(ha)){ba=C.__styleString;if(i!=ba)u.fillStyle=i=ba;u.save();u.translate(X.x,X.y);u.rotate(-$.rotation);u.scale(ea,fa);u.beginPath();u.arc(0,0,1,0,Da,true);
-u.closePath();u.fill();u.restore()}}}}}else if(H instanceof THREE.RenderableLine){l=H.v1;E=H.v2;l.positionScreen.x*=y;l.positionScreen.y*=L;E.positionScreen.x*=y;E.positionScreen.y*=L;ha.addPoint(l.positionScreen.x,l.positionScreen.y);ha.addPoint(E.positionScreen.x,E.positionScreen.y);if(pa.instersects(ha)){S=0;for(ca=H.material.length;S<ca;){$=l;ea=E;X=H.material[S++];if(X.opacity!=0){j(X.opacity);k(X.blending);u.beginPath();u.moveTo($.positionScreen.x,$.positionScreen.y);u.lineTo(ea.positionScreen.x,
-ea.positionScreen.y);u.closePath();if(X instanceof THREE.LineBasicMaterial){C.__styleString=X.color.__styleString;$=X.linewidth;if(p!=$)u.lineWidth=p=$;$=C.__styleString;if(h!=$)u.strokeStyle=h=$;u.stroke();ha.inflate(X.linewidth*2)}}}}}else if(H instanceof THREE.RenderableFace3){l=H.v1;E=H.v2;B=H.v3;l.positionScreen.x*=y;l.positionScreen.y*=L;E.positionScreen.x*=y;E.positionScreen.y*=L;B.positionScreen.x*=y;B.positionScreen.y*=L;if(H.overdraw){c(l.positionScreen,E.positionScreen);c(E.positionScreen,
-B.positionScreen);c(B.positionScreen,l.positionScreen)}ha.addPoint(l.positionScreen.x,l.positionScreen.y);ha.addPoint(E.positionScreen.x,E.positionScreen.y);ha.addPoint(B.positionScreen.x,B.positionScreen.y);if(pa.instersects(ha)){S=0;for(ca=H.meshMaterial.length;S<ca;){ea=H.meshMaterial[S++];if(ea instanceof THREE.MeshFaceMaterial){X=0;for($=H.faceMaterial.length;X<$;)(ea=H.faceMaterial[X++])&&b(l,E,B,H,ea,R)}else b(l,E,B,H,ea,R)}}}qa.addRectangle(ha)}u.setTransform(1,0,0,1,0,0)}};
-THREE.SVGRenderer=function(){function a(C,J,I){var T,N,M,Y;T=0;for(N=C.lights.length;T<N;T++){M=C.lights[T];if(M instanceof THREE.DirectionalLight){Y=J.normalWorld.dot(M.position)*M.intensity;if(Y>0){I.r+=M.color.r*Y;I.g+=M.color.g*Y;I.b+=M.color.b*Y}}else if(M instanceof THREE.PointLight){l.sub(M.position,J.centroidWorld);l.normalize();Y=J.normalWorld.dot(l)*M.intensity;if(Y>0){I.r+=M.color.r*Y;I.g+=M.color.g*Y;I.b+=M.color.b*Y}}}}function b(C,J,I,T,N,M){G=e(V++);G.setAttribute("d","M "+C.positionScreen.x+
-" "+C.positionScreen.y+" L "+J.positionScreen.x+" "+J.positionScreen.y+" L "+I.positionScreen.x+","+I.positionScreen.y+"z");if(N instanceof THREE.MeshBasicMaterial)n.__styleString=N.color.__styleString;else if(N instanceof THREE.MeshLambertMaterial)if(A){h.r=i.r;h.g=i.g;h.b=i.b;a(M,T,h);n.r=N.color.r*h.r;n.g=N.color.g*h.g;n.b=N.color.b*h.b;n.updateStyleString()}else n.__styleString=N.color.__styleString;else if(N instanceof THREE.MeshDepthMaterial){m=1-N.__2near/(N.__farPlusNear-T.z*N.__farMinusNear);
-n.setRGB(m,m,m)}else N instanceof THREE.MeshNormalMaterial&&n.setRGB(f(T.normalWorld.x),f(T.normalWorld.y),f(T.normalWorld.z));N.wireframe?G.setAttribute("style","fill: none; stroke: "+n.__styleString+"; stroke-width: "+N.wireframe_linewidth+"; stroke-opacity: "+N.opacity+"; stroke-linecap: "+N.wireframe_linecap+"; stroke-linejoin: "+N.wireframe_linejoin):G.setAttribute("style","fill: "+n.__styleString+"; fill-opacity: "+N.opacity);g.appendChild(G)}function d(C,J,I,T,N,M,Y){G=e(V++);G.setAttribute("d",
-"M "+C.positionScreen.x+" "+C.positionScreen.y+" L "+J.positionScreen.x+" "+J.positionScreen.y+" L "+I.positionScreen.x+","+I.positionScreen.y+" L "+T.positionScreen.x+","+T.positionScreen.y+"z");if(M instanceof THREE.MeshBasicMaterial)n.__styleString=M.color.__styleString;else if(M instanceof THREE.MeshLambertMaterial)if(A){h.r=i.r;h.g=i.g;h.b=i.b;a(Y,N,h);n.r=M.color.r*h.r;n.g=M.color.g*h.g;n.b=M.color.b*h.b;n.updateStyleString()}else n.__styleString=M.color.__styleString;else if(M instanceof THREE.MeshDepthMaterial){m=
-1-M.__2near/(M.__farPlusNear-N.z*M.__farMinusNear);n.setRGB(m,m,m)}else M instanceof THREE.MeshNormalMaterial&&n.setRGB(f(N.normalWorld.x),f(N.normalWorld.y),f(N.normalWorld.z));M.wireframe?G.setAttribute("style","fill: none; stroke: "+n.__styleString+"; stroke-width: "+M.wireframe_linewidth+"; stroke-opacity: "+M.opacity+"; stroke-linecap: "+M.wireframe_linecap+"; stroke-linejoin: "+M.wireframe_linejoin):G.setAttribute("style","fill: "+n.__styleString+"; fill-opacity: "+M.opacity);g.appendChild(G)}
-function e(C){if(E[C]==null){E[C]=document.createElementNS("http://www.w3.org/2000/svg","path");P==0&&E[C].setAttribute("shape-rendering","crispEdges");return E[C]}return E[C]}function f(C){return C<0?Math.min((1+C)*0.5,0.5):0.5+Math.min(C*0.5,0.5)}var j=null,k=new THREE.Projector,g=document.createElementNS("http://www.w3.org/2000/svg","svg"),o,c,s,F,r,w,v,y,L=new THREE.Rectangle,u=new THREE.Rectangle,A=false,n=new THREE.Color(16777215),h=new THREE.Color(16777215),i=new THREE.Color(0),p=new THREE.Color(0),
-x=new THREE.Color(0),m,l=new THREE.Vector3,E=[],B=[],Q=[],G,V,U,D,P=1;this.domElement=g;this.autoClear=true;this.setQuality=function(C){switch(C){case "high":P=1;break;case "low":P=0}};this.setSize=function(C,J){o=C;c=J;s=o/2;F=c/2;g.setAttribute("viewBox",-s+" "+-F+" "+o+" "+c);g.setAttribute("width",o);g.setAttribute("height",c);L.set(-s,-F,s,F)};this.clear=function(){for(;g.childNodes.length>0;)g.removeChild(g.childNodes[0])};this.render=function(C,J){var I,T,N,M,Y,q,t,z;this.autoClear&&this.clear();
-j=k.projectScene(C,J);D=U=V=0;if(A=C.lights.length>0){t=C.lights;i.setRGB(0,0,0);p.setRGB(0,0,0);x.setRGB(0,0,0);I=0;for(T=t.length;I<T;I++){N=t[I];M=N.color;if(N instanceof THREE.AmbientLight){i.r+=M.r;i.g+=M.g;i.b+=M.b}else if(N instanceof THREE.DirectionalLight){p.r+=M.r;p.g+=M.g;p.b+=M.b}else if(N instanceof THREE.PointLight){x.r+=M.r;x.g+=M.g;x.b+=M.b}}}I=0;for(T=j.length;I<T;I++){t=j[I];u.empty();if(t instanceof THREE.RenderableParticle){r=t;r.x*=s;r.y*=-F;N=0;for(M=t.material.length;N<M;N++)if(z=
-t.material[N]){Y=r;q=t;z=z;var K=U++;if(B[K]==null){B[K]=document.createElementNS("http://www.w3.org/2000/svg","circle");P==0&&B[K].setAttribute("shape-rendering","crispEdges")}G=B[K];G.setAttribute("cx",Y.x);G.setAttribute("cy",Y.y);G.setAttribute("r",q.scale.x*s);if(z instanceof THREE.ParticleCircleMaterial){if(A){h.r=i.r+p.r+x.r;h.g=i.g+p.g+x.g;h.b=i.b+p.b+x.b;n.r=z.color.r*h.r;n.g=z.color.g*h.g;n.b=z.color.b*h.b;n.updateStyleString()}else n=z.color;G.setAttribute("style","fill: "+n.__styleString)}g.appendChild(G)}}else if(t instanceof
-THREE.RenderableLine){r=t.v1;w=t.v2;r.positionScreen.x*=s;r.positionScreen.y*=-F;w.positionScreen.x*=s;w.positionScreen.y*=-F;u.addPoint(r.positionScreen.x,r.positionScreen.y);u.addPoint(w.positionScreen.x,w.positionScreen.y);if(L.instersects(u)){N=0;for(M=t.material.length;N<M;)if(z=t.material[N++]){Y=r;q=w;z=z;K=D++;if(Q[K]==null){Q[K]=document.createElementNS("http://www.w3.org/2000/svg","line");P==0&&Q[K].setAttribute("shape-rendering","crispEdges")}G=Q[K];G.setAttribute("x1",Y.positionScreen.x);
-G.setAttribute("y1",Y.positionScreen.y);G.setAttribute("x2",q.positionScreen.x);G.setAttribute("y2",q.positionScreen.y);if(z instanceof THREE.LineBasicMaterial){n.__styleString=z.color.__styleString;G.setAttribute("style","fill: none; stroke: "+n.__styleString+"; stroke-width: "+z.linewidth+"; stroke-opacity: "+z.opacity+"; stroke-linecap: "+z.linecap+"; stroke-linejoin: "+z.linejoin);g.appendChild(G)}}}}else if(t instanceof THREE.RenderableFace3){r=t.v1;w=t.v2;v=t.v3;r.positionScreen.x*=s;r.positionScreen.y*=
--F;w.positionScreen.x*=s;w.positionScreen.y*=-F;v.positionScreen.x*=s;v.positionScreen.y*=-F;u.addPoint(r.positionScreen.x,r.positionScreen.y);u.addPoint(w.positionScreen.x,w.positionScreen.y);u.addPoint(v.positionScreen.x,v.positionScreen.y);if(L.instersects(u)){N=0;for(M=t.meshMaterial.length;N<M;){z=t.meshMaterial[N++];if(z instanceof THREE.MeshFaceMaterial){Y=0;for(q=t.faceMaterial.length;Y<q;)(z=t.faceMaterial[Y++])&&b(r,w,v,t,z,C)}else z&&b(r,w,v,t,z,C)}}}else if(t instanceof THREE.RenderableFace4){r=
-t.v1;w=t.v2;v=t.v3;y=t.v4;r.positionScreen.x*=s;r.positionScreen.y*=-F;w.positionScreen.x*=s;w.positionScreen.y*=-F;v.positionScreen.x*=s;v.positionScreen.y*=-F;y.positionScreen.x*=s;y.positionScreen.y*=-F;u.addPoint(r.positionScreen.x,r.positionScreen.y);u.addPoint(w.positionScreen.x,w.positionScreen.y);u.addPoint(v.positionScreen.x,v.positionScreen.y);u.addPoint(y.positionScreen.x,y.positionScreen.y);if(L.instersects(u)){N=0;for(M=t.meshMaterial.length;N<M;){z=t.meshMaterial[N++];if(z instanceof
-THREE.MeshFaceMaterial){Y=0;for(q=t.faceMaterial.length;Y<q;)(z=t.faceMaterial[Y++])&&d(r,w,v,y,t,z,C)}else z&&d(r,w,v,y,t,z,C)}}}}}};
-THREE.WebGLRenderer=function(a){function b(h,i){var p=c.createProgram();c.attachShader(p,k("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\n"+h));c.attachShader(p,k("vertex","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"+i));c.linkProgram(p);c.getProgramParameter(p,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(p,
-c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");p.uniforms={};return p}function d(h,i){if(h instanceof THREE.TextureCube&&h.image.length==6){if(!h.image.__webGLTextureCube&&!h.image.__cubeMapInitialized&&h.image.loadCount==6){h.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,h.image.__webGLTextureCube);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,
-c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(var p=0;p<6;++p)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+p,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,h.image[p]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);h.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+i);c.bindTexture(c.TEXTURE_CUBE_MAP,h.image.__webGLTextureCube)}}function e(h,i){if(!h.__webGLTexture&&h.image.loaded){h.__webGLTexture=c.createTexture();
-c.bindTexture(c.TEXTURE_2D,h.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,h.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,g(h.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,g(h.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+i);c.bindTexture(c.TEXTURE_2D,h.__webGLTexture)}
-function f(h,i){var p,x,m;p=0;for(x=i.length;p<x;p++){m=i[p];h.uniforms[m]=c.getUniformLocation(h,m)}}function j(h){h.position=c.getAttribLocation(h,"position");c.enableVertexAttribArray(h.position);h.normal=c.getAttribLocation(h,"normal");c.enableVertexAttribArray(h.normal);h.uv=c.getAttribLocation(h,"uv");c.enableVertexAttribArray(h.uv)}function k(h,i){var p;if(h=="fragment")p=c.createShader(c.FRAGMENT_SHADER);else if(h=="vertex")p=c.createShader(c.VERTEX_SHADER);c.shaderSource(p,i);c.compileShader(p);
-if(!c.getShaderParameter(p,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(p));return null}return p}function g(h){switch(h){case THREE.Repeat:return c.REPEAT;case THREE.ClampToEdge:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeat:return c.MIRRORED_REPEAT}return 0}var o=document.createElement("canvas"),c,s,F,r=new THREE.Matrix4,w,v=new Float32Array(16),y=new Float32Array(16),L=new Float32Array(16),u=new Float32Array(9),A=new Float32Array(16);a=function(h,i){if(h){var p,x,m,l=pointLights=maxDirLights=maxPointLights=
-0;p=0;for(x=h.lights.length;p<x;p++){m=h.lights[p];m instanceof THREE.DirectionalLight&&l++;m instanceof THREE.PointLight&&pointLights++}if(pointLights+l<=i){maxDirLights=l;maxPointLights=pointLights}else{maxDirLights=Math.ceil(i*l/(pointLights+l));maxPointLights=i-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:i-1}}(a,4);this.domElement=o;this.autoClear=true;try{c=o.getContext("experimental-webgl",{antialias:true})}catch(n){}if(!c){alert("WebGL not supported");
-throw"cannot create webgl context";}c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK);c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(0,0,0,0);(function(h,i){var p=[h?"#define MAX_DIR_LIGHTS "+h:"",i?"#define MAX_POINT_LIGHTS "+i:"","uniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",
-h?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",h?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",i?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",i?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","uniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",i?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform float mRefractionRatio;\nvoid main(void) {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec3 transformedNormal = normalize( normalMatrix * normal );\nif ( !enableLighting ) {\nvLightWeighting = vec3( 1.0, 1.0, 1.0 );\n} else {\nvLightWeighting = ambientLightColor;",
-h?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",h?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",h?"float directionalLightWeighting = max( dot( transformedNormal, normalize(lDirection.xyz ) ), 0.0 );":"",h?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",h?"}":"",i?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",i?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",i?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
-"",i?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",i?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",i?"}":"","}\nvNormal = transformedNormal;\nvUv = uv;\nif ( useRefract ) {\nvReflect = refract( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz), mRefractionRatio );\n} else {\nvReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );\n}\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n"),
-x=[h?"#define MAX_DIR_LIGHTS "+h:"",i?"#define MAX_POINT_LIGHTS "+i:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\nuniform float m2Near;\nuniform float mFarPlusNear;\nuniform float mFarMinusNear;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
-h?"uniform mat4 viewMatrix;":"",h?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",i?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform vec3 cameraPosition;\nvoid main() {\nvec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nvec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nif ( enableMap ) {\nmapColor = texture2D( tMap, vUv );\n}\nif ( enableCubeMap ) {\ncubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\n}\nif ( material == 5 ) { \nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( -wPos.x, wPos.yz ) );\n} else if ( material == 4 ) { \ngl_FragColor = vec4( 0.5*normalize( vNormal ) + vec3(0.5, 0.5, 0.5), mOpacity );\n} else if ( material == 3 ) { \nfloat w = 0.5;\ngl_FragColor = vec4( w, w, w, mOpacity );\n} else if ( material == 2 ) { \nvec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );",
-i?"vec4 pointDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",i?"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",i?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",i?"vec3 pointVector = normalize( vPointLightVector[ i ] );":"",i?"vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );":"",i?"float pointDotNormalHalf = dot( normal, pointHalfVector );":"",i?"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );":"",i?"float pointSpecularWeight = 0.0;":"",i?"if ( pointDotNormalHalf >= 0.0 )":
-"",i?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",i?"pointDiffuse  += mColor * pointDiffuseWeight;":"",i?"pointSpecular += mSpecular * pointSpecularWeight;":"",i?"}":"",h?"vec4 dirDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",h?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",h?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",h?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",h?"vec3 dirVector = normalize( lDirection.xyz );":"",h?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
-"",h?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",h?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",h?"float dirSpecularWeight = 0.0;":"",h?"if ( dirDotNormalHalf >= 0.0 )":"",h?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",h?"dirDiffuse  += mColor * dirDiffuseWeight;":"",h?"dirSpecular += mSpecular * dirSpecularWeight;":"",h?"}":"","vec4 totalLight = mAmbient;",h?"totalLight += dirDiffuse + dirSpecular;":"",i?"totalLight += pointDiffuse + pointSpecular;":
+0.5+0.5;f(Q,J,P,S,E,T,G.env_map.image,z,K,W,ga,ma,ua)}}else G.wireframe?d(G.color.__styleString,G.wireframe_linewidth):e(G.color.__styleString);else if(G instanceof THREE.MeshLambertMaterial){if(G.map&&!G.wireframe){f(Q,J,P,S,E,T,G.map.image,O.uvs[0].u,O.uvs[0].v,O.uvs[1].u,O.uvs[1].v,O.uvs[2].u,O.uvs[2].v);k(THREE.SubtractiveBlending)}if(za)if(!G.wireframe&&G.shading==THREE.SmoothShading&&O.vertexNormalsWorld.length==3){I.r=H.r=V.r=ja.r;I.g=H.g=V.g=ja.g;I.b=H.b=V.b=ja.b;a(U,O.v1.positionWorld,O.vertexNormalsWorld[0],
+I);a(U,O.v2.positionWorld,O.vertexNormalsWorld[1],H);a(U,O.v3.positionWorld,O.vertexNormalsWorld[2],V);N.r=(H.r+V.r)*0.5;N.g=(H.g+V.g)*0.5;N.b=(H.b+V.b)*0.5;s=g(I,H,V,N);f(Q,J,P,S,E,T,s,0,0,1,0,0,1)}else{ka.r=ja.r;ka.g=ja.g;ka.b=ja.b;a(U,O.centroidWorld,O.normalWorld,ka);D.r=G.color.r*ka.r;D.g=G.color.g*ka.g;D.b=G.color.b*ka.b;D.updateStyleString();G.wireframe?d(D.__styleString,G.wireframe_linewidth):e(D.__styleString)}else G.wireframe?d(G.color.__styleString,G.wireframe_linewidth):e(G.color.__styleString)}else if(G instanceof
+THREE.MeshDepthMaterial){M=G.__2near;Y=G.__farPlusNear;q=G.__farMinusNear;I.r=I.g=I.b=1-M/(Y-R.positionScreen.z*q);H.r=H.g=H.b=1-M/(Y-aa.positionScreen.z*q);V.r=V.g=V.b=1-M/(Y-Z.positionScreen.z*q);N.r=(H.r+V.r)*0.5;N.g=(H.g+V.g)*0.5;N.b=(H.b+V.b)*0.5;s=g(I,H,V,N);f(Q,J,P,S,E,T,s,0,0,1,0,0,1)}else if(G instanceof THREE.MeshNormalMaterial){D.r=p(O.normalWorld.x);D.g=p(O.normalWorld.y);D.b=p(O.normalWorld.z);D.updateStyleString();G.wireframe?d(D.__styleString,G.wireframe_linewidth):e(D.__styleString)}}}
+function d(R,aa){if(i!=R)u.strokeStyle=i=R;if(h!=aa)u.lineWidth=h=aa;u.stroke();ha.inflate(aa*2)}function e(R){if(n!=R)u.fillStyle=n=R;u.fill()}function f(R,aa,Z,O,G,U,ca,X,$,ea,ba,fa,oa){var na,ia;na=ca.width-1;ia=ca.height-1;X*=na;$*=ia;ea*=na;ba*=ia;fa*=na;oa*=ia;Z-=R;O-=aa;G-=R;U-=aa;ea-=X;ba-=$;fa-=X;oa-=$;ia=1/(ea*oa-fa*ba);na=(oa*Z-ba*G)*ia;ba=(oa*O-ba*U)*ia;Z=(ea*G-fa*Z)*ia;O=(ea*U-fa*O)*ia;R=R-na*X-Z*$;aa=aa-ba*X-O*$;u.save();u.transform(na,ba,Z,O,R,aa);u.clip();u.drawImage(ca,0,0);u.restore()}
+function j(R){if(A!=R)u.globalAlpha=A=R}function k(R){if(o!=R){switch(R){case THREE.NormalBlending:u.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:u.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:u.globalCompositeOperation="darker"}o=R}}function g(R,aa,Z,O){la[0]=m(0,x(255,~~(R.r*255)));la[1]=m(0,x(255,~~(R.g*255)));la[2]=m(0,x(255,~~(R.b*255)));la[4]=m(0,x(255,~~(aa.r*255)));la[5]=m(0,x(255,~~(aa.g*255)));la[6]=m(0,x(255,~~(aa.b*255)));la[8]=m(0,
+x(255,~~(Z.r*255)));la[9]=m(0,x(255,~~(Z.g*255)));la[10]=m(0,x(255,~~(Z.b*255)));la[12]=m(0,x(255,~~(O.r*255)));la[13]=m(0,x(255,~~(O.g*255)));la[14]=m(0,x(255,~~(O.b*255)));va.putImageData(Aa,0,0);ya.drawImage(wa,0,0);return xa}function p(R){return R<0?x((1+R)*0.5,0.5):0.5+x(R*0.5,0.5)}function c(R,aa){var Z=aa.x-R.x,O=aa.y-R.y,G=1/Math.sqrt(Z*Z+O*O);Z*=G;O*=G;aa.x+=Z;aa.y+=O;R.x-=Z;R.y-=O}var t=null,F=new THREE.Projector,r=document.createElement("canvas"),w,v,y,L,u=r.getContext("2d"),A=1,o=0,i=
+null,n=null,h=1,x=Math.min,m=Math.max,l,B,C,Q,J,P,S,E,T,D=new THREE.Color,I=new THREE.Color,H=new THREE.Color,V=new THREE.Color,N=new THREE.Color,M,Y,q,s,z,K,W,ga,ma,ua,pa=new THREE.Rectangle,qa=new THREE.Rectangle,ha=new THREE.Rectangle,za=false,ka=new THREE.Color,ja=new THREE.Color,ra=new THREE.Color,sa=new THREE.Color,Da=Math.PI*2,da=new THREE.Vector3,wa,va,Aa,la,xa,ya,ta=16;wa=document.createElement("canvas");wa.width=wa.height=2;va=wa.getContext("2d");va.fillStyle="rgba(0,0,0,1)";va.fillRect(0,
+0,2,2);Aa=va.getImageData(0,0,2,2);la=Aa.data;xa=document.createElement("canvas");xa.width=xa.height=ta;ya=xa.getContext("2d");ya.translate(-ta/2,-ta/2);ya.scale(ta,ta);ta--;this.domElement=r;this.autoClear=true;this.setSize=function(R,aa){w=R;v=aa;y=w/2;L=v/2;r.width=w;r.height=v;pa.set(-y,-L,y,L)};this.clear=function(){if(!qa.isEmpty()){qa.inflate(1);qa.minSelf(pa);u.clearRect(qa.getX(),qa.getY(),qa.getWidth(),qa.getHeight());qa.empty()}};this.render=function(R,aa){var Z,O,G,U,ca,X,$,ea;u.setTransform(1,
+0,0,-1,y,L);this.autoClear&&this.clear();t=F.projectScene(R,aa);if(za=R.lights.length>0){ca=R.lights;ja.setRGB(0,0,0);ra.setRGB(0,0,0);sa.setRGB(0,0,0);Z=0;for(O=ca.length;Z<O;Z++){G=ca[Z];U=G.color;if(G instanceof THREE.AmbientLight){ja.r+=U.r;ja.g+=U.g;ja.b+=U.b}else if(G instanceof THREE.DirectionalLight){ra.r+=U.r;ra.g+=U.g;ra.b+=U.b}else if(G instanceof THREE.PointLight){sa.r+=U.r;sa.g+=U.g;sa.b+=U.b}}}Z=0;for(O=t.length;Z<O;Z++){G=t[Z];ha.empty();if(G instanceof THREE.RenderableParticle){l=
+G;l.x*=y;l.y*=L;U=0;for(ca=G.material.length;U<ca;U++){X=l;$=G;var ba=G.material[U];if(ba.opacity!=0){j(ba.opacity);k(ba.blending);ea=void 0;var fa=void 0,oa=void 0,na=void 0,ia=void 0,Ba=void 0,Ca=void 0;if(ba instanceof THREE.ParticleBasicMaterial){if(ba.map){ia=ba.map;Ba=ia.width>>1;Ca=ia.height>>1;oa=$.scale.x*y;na=$.scale.y*L;ea=oa*Ba;fa=na*Ca;ha.set(X.x-ea,X.y-fa,X.x+ea,X.y+fa);if(pa.instersects(ha)){u.save();u.translate(X.x,X.y);u.rotate(-$.rotation);u.scale(oa,-na);u.translate(-Ba,-Ca);u.drawImage(ia,
+0,0);u.restore()}}}else if(ba instanceof THREE.ParticleCircleMaterial){if(za){ka.r=ja.r+ra.r+sa.r;ka.g=ja.g+ra.g+sa.g;ka.b=ja.b+ra.b+sa.b;D.r=ba.color.r*ka.r;D.g=ba.color.g*ka.g;D.b=ba.color.b*ka.b;D.updateStyleString()}else D.__styleString=ba.color.__styleString;ea=$.scale.x*y;fa=$.scale.y*L;ha.set(X.x-ea,X.y-fa,X.x+ea,X.y+fa);if(pa.instersects(ha)){ba=D.__styleString;if(n!=ba)u.fillStyle=n=ba;u.save();u.translate(X.x,X.y);u.rotate(-$.rotation);u.scale(ea,fa);u.beginPath();u.arc(0,0,1,0,Da,true);
+u.closePath();u.fill();u.restore()}}}}}else if(G instanceof THREE.RenderableLine){l=G.v1;B=G.v2;l.positionScreen.x*=y;l.positionScreen.y*=L;B.positionScreen.x*=y;B.positionScreen.y*=L;ha.addPoint(l.positionScreen.x,l.positionScreen.y);ha.addPoint(B.positionScreen.x,B.positionScreen.y);if(pa.instersects(ha)){U=0;for(ca=G.material.length;U<ca;){$=l;ea=B;X=G.material[U++];if(X.opacity!=0){j(X.opacity);k(X.blending);u.beginPath();u.moveTo($.positionScreen.x,$.positionScreen.y);u.lineTo(ea.positionScreen.x,
+ea.positionScreen.y);u.closePath();if(X instanceof THREE.LineBasicMaterial){D.__styleString=X.color.__styleString;$=X.linewidth;if(h!=$)u.lineWidth=h=$;$=D.__styleString;if(i!=$)u.strokeStyle=i=$;u.stroke();ha.inflate(X.linewidth*2)}}}}}else if(G instanceof THREE.RenderableFace3){l=G.v1;B=G.v2;C=G.v3;l.positionScreen.x*=y;l.positionScreen.y*=L;B.positionScreen.x*=y;B.positionScreen.y*=L;C.positionScreen.x*=y;C.positionScreen.y*=L;if(G.overdraw){c(l.positionScreen,B.positionScreen);c(B.positionScreen,
+C.positionScreen);c(C.positionScreen,l.positionScreen)}ha.addPoint(l.positionScreen.x,l.positionScreen.y);ha.addPoint(B.positionScreen.x,B.positionScreen.y);ha.addPoint(C.positionScreen.x,C.positionScreen.y);if(pa.instersects(ha)){U=0;for(ca=G.meshMaterial.length;U<ca;){ea=G.meshMaterial[U++];if(ea instanceof THREE.MeshFaceMaterial){X=0;for($=G.faceMaterial.length;X<$;)(ea=G.faceMaterial[X++])&&b(l,B,C,G,ea,R)}else b(l,B,C,G,ea,R)}}}qa.addRectangle(ha)}u.setTransform(1,0,0,1,0,0)}};
+THREE.SVGRenderer=function(){function a(D,I,H){var V,N,M,Y;V=0;for(N=D.lights.length;V<N;V++){M=D.lights[V];if(M instanceof THREE.DirectionalLight){Y=I.normalWorld.dot(M.position)*M.intensity;if(Y>0){H.r+=M.color.r*Y;H.g+=M.color.g*Y;H.b+=M.color.b*Y}}else if(M instanceof THREE.PointLight){l.sub(M.position,I.centroidWorld);l.normalize();Y=I.normalWorld.dot(l)*M.intensity;if(Y>0){H.r+=M.color.r*Y;H.g+=M.color.g*Y;H.b+=M.color.b*Y}}}}function b(D,I,H,V,N,M){J=e(P++);J.setAttribute("d","M "+D.positionScreen.x+
+" "+D.positionScreen.y+" L "+I.positionScreen.x+" "+I.positionScreen.y+" L "+H.positionScreen.x+","+H.positionScreen.y+"z");if(N instanceof THREE.MeshBasicMaterial)o.__styleString=N.color.__styleString;else if(N instanceof THREE.MeshLambertMaterial)if(A){i.r=n.r;i.g=n.g;i.b=n.b;a(M,V,i);o.r=N.color.r*i.r;o.g=N.color.g*i.g;o.b=N.color.b*i.b;o.updateStyleString()}else o.__styleString=N.color.__styleString;else if(N instanceof THREE.MeshDepthMaterial){m=1-N.__2near/(N.__farPlusNear-V.z*N.__farMinusNear);
+o.setRGB(m,m,m)}else N instanceof THREE.MeshNormalMaterial&&o.setRGB(f(V.normalWorld.x),f(V.normalWorld.y),f(V.normalWorld.z));N.wireframe?J.setAttribute("style","fill: none; stroke: "+o.__styleString+"; stroke-width: "+N.wireframe_linewidth+"; stroke-opacity: "+N.opacity+"; stroke-linecap: "+N.wireframe_linecap+"; stroke-linejoin: "+N.wireframe_linejoin):J.setAttribute("style","fill: "+o.__styleString+"; fill-opacity: "+N.opacity);g.appendChild(J)}function d(D,I,H,V,N,M,Y){J=e(P++);J.setAttribute("d",
+"M "+D.positionScreen.x+" "+D.positionScreen.y+" L "+I.positionScreen.x+" "+I.positionScreen.y+" L "+H.positionScreen.x+","+H.positionScreen.y+" L "+V.positionScreen.x+","+V.positionScreen.y+"z");if(M instanceof THREE.MeshBasicMaterial)o.__styleString=M.color.__styleString;else if(M instanceof THREE.MeshLambertMaterial)if(A){i.r=n.r;i.g=n.g;i.b=n.b;a(Y,N,i);o.r=M.color.r*i.r;o.g=M.color.g*i.g;o.b=M.color.b*i.b;o.updateStyleString()}else o.__styleString=M.color.__styleString;else if(M instanceof THREE.MeshDepthMaterial){m=
+1-M.__2near/(M.__farPlusNear-N.z*M.__farMinusNear);o.setRGB(m,m,m)}else M instanceof THREE.MeshNormalMaterial&&o.setRGB(f(N.normalWorld.x),f(N.normalWorld.y),f(N.normalWorld.z));M.wireframe?J.setAttribute("style","fill: none; stroke: "+o.__styleString+"; stroke-width: "+M.wireframe_linewidth+"; stroke-opacity: "+M.opacity+"; stroke-linecap: "+M.wireframe_linecap+"; stroke-linejoin: "+M.wireframe_linejoin):J.setAttribute("style","fill: "+o.__styleString+"; fill-opacity: "+M.opacity);g.appendChild(J)}
+function e(D){if(B[D]==null){B[D]=document.createElementNS("http://www.w3.org/2000/svg","path");T==0&&B[D].setAttribute("shape-rendering","crispEdges");return B[D]}return B[D]}function f(D){return D<0?Math.min((1+D)*0.5,0.5):0.5+Math.min(D*0.5,0.5)}var j=null,k=new THREE.Projector,g=document.createElementNS("http://www.w3.org/2000/svg","svg"),p,c,t,F,r,w,v,y,L=new THREE.Rectangle,u=new THREE.Rectangle,A=false,o=new THREE.Color(16777215),i=new THREE.Color(16777215),n=new THREE.Color(0),h=new THREE.Color(0),
+x=new THREE.Color(0),m,l=new THREE.Vector3,B=[],C=[],Q=[],J,P,S,E,T=1;this.domElement=g;this.autoClear=true;this.setQuality=function(D){switch(D){case "high":T=1;break;case "low":T=0}};this.setSize=function(D,I){p=D;c=I;t=p/2;F=c/2;g.setAttribute("viewBox",-t+" "+-F+" "+p+" "+c);g.setAttribute("width",p);g.setAttribute("height",c);L.set(-t,-F,t,F)};this.clear=function(){for(;g.childNodes.length>0;)g.removeChild(g.childNodes[0])};this.render=function(D,I){var H,V,N,M,Y,q,s,z;this.autoClear&&this.clear();
+j=k.projectScene(D,I);E=S=P=0;if(A=D.lights.length>0){s=D.lights;n.setRGB(0,0,0);h.setRGB(0,0,0);x.setRGB(0,0,0);H=0;for(V=s.length;H<V;H++){N=s[H];M=N.color;if(N instanceof THREE.AmbientLight){n.r+=M.r;n.g+=M.g;n.b+=M.b}else if(N instanceof THREE.DirectionalLight){h.r+=M.r;h.g+=M.g;h.b+=M.b}else if(N instanceof THREE.PointLight){x.r+=M.r;x.g+=M.g;x.b+=M.b}}}H=0;for(V=j.length;H<V;H++){s=j[H];u.empty();if(s instanceof THREE.RenderableParticle){r=s;r.x*=t;r.y*=-F;N=0;for(M=s.material.length;N<M;N++)if(z=
+s.material[N]){Y=r;q=s;z=z;var K=S++;if(C[K]==null){C[K]=document.createElementNS("http://www.w3.org/2000/svg","circle");T==0&&C[K].setAttribute("shape-rendering","crispEdges")}J=C[K];J.setAttribute("cx",Y.x);J.setAttribute("cy",Y.y);J.setAttribute("r",q.scale.x*t);if(z instanceof THREE.ParticleCircleMaterial){if(A){i.r=n.r+h.r+x.r;i.g=n.g+h.g+x.g;i.b=n.b+h.b+x.b;o.r=z.color.r*i.r;o.g=z.color.g*i.g;o.b=z.color.b*i.b;o.updateStyleString()}else o=z.color;J.setAttribute("style","fill: "+o.__styleString)}g.appendChild(J)}}else if(s instanceof
+THREE.RenderableLine){r=s.v1;w=s.v2;r.positionScreen.x*=t;r.positionScreen.y*=-F;w.positionScreen.x*=t;w.positionScreen.y*=-F;u.addPoint(r.positionScreen.x,r.positionScreen.y);u.addPoint(w.positionScreen.x,w.positionScreen.y);if(L.instersects(u)){N=0;for(M=s.material.length;N<M;)if(z=s.material[N++]){Y=r;q=w;z=z;K=E++;if(Q[K]==null){Q[K]=document.createElementNS("http://www.w3.org/2000/svg","line");T==0&&Q[K].setAttribute("shape-rendering","crispEdges")}J=Q[K];J.setAttribute("x1",Y.positionScreen.x);
+J.setAttribute("y1",Y.positionScreen.y);J.setAttribute("x2",q.positionScreen.x);J.setAttribute("y2",q.positionScreen.y);if(z instanceof THREE.LineBasicMaterial){o.__styleString=z.color.__styleString;J.setAttribute("style","fill: none; stroke: "+o.__styleString+"; stroke-width: "+z.linewidth+"; stroke-opacity: "+z.opacity+"; stroke-linecap: "+z.linecap+"; stroke-linejoin: "+z.linejoin);g.appendChild(J)}}}}else if(s instanceof THREE.RenderableFace3){r=s.v1;w=s.v2;v=s.v3;r.positionScreen.x*=t;r.positionScreen.y*=
+-F;w.positionScreen.x*=t;w.positionScreen.y*=-F;v.positionScreen.x*=t;v.positionScreen.y*=-F;u.addPoint(r.positionScreen.x,r.positionScreen.y);u.addPoint(w.positionScreen.x,w.positionScreen.y);u.addPoint(v.positionScreen.x,v.positionScreen.y);if(L.instersects(u)){N=0;for(M=s.meshMaterial.length;N<M;){z=s.meshMaterial[N++];if(z instanceof THREE.MeshFaceMaterial){Y=0;for(q=s.faceMaterial.length;Y<q;)(z=s.faceMaterial[Y++])&&b(r,w,v,s,z,D)}else z&&b(r,w,v,s,z,D)}}}else if(s instanceof THREE.RenderableFace4){r=
+s.v1;w=s.v2;v=s.v3;y=s.v4;r.positionScreen.x*=t;r.positionScreen.y*=-F;w.positionScreen.x*=t;w.positionScreen.y*=-F;v.positionScreen.x*=t;v.positionScreen.y*=-F;y.positionScreen.x*=t;y.positionScreen.y*=-F;u.addPoint(r.positionScreen.x,r.positionScreen.y);u.addPoint(w.positionScreen.x,w.positionScreen.y);u.addPoint(v.positionScreen.x,v.positionScreen.y);u.addPoint(y.positionScreen.x,y.positionScreen.y);if(L.instersects(u)){N=0;for(M=s.meshMaterial.length;N<M;){z=s.meshMaterial[N++];if(z instanceof
+THREE.MeshFaceMaterial){Y=0;for(q=s.faceMaterial.length;Y<q;)(z=s.faceMaterial[Y++])&&d(r,w,v,y,s,z,D)}else z&&d(r,w,v,y,s,z,D)}}}}}};
+THREE.WebGLRenderer=function(a){function b(i,n){var h=c.createProgram();c.attachShader(h,k("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\n"+i));c.attachShader(h,k("vertex","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"+n));c.linkProgram(h);c.getProgramParameter(h,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(h,
+c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");h.uniforms={};h.attributes={};return h}function d(i,n){if(i instanceof THREE.TextureCube&&i.image.length==6){if(!i.image.__webGLTextureCube&&!i.image.__cubeMapInitialized&&i.image.loadCount==6){i.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,i.image.__webGLTextureCube);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,
+c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(var h=0;h<6;++h)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+h,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,i.image[h]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);i.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+n);c.bindTexture(c.TEXTURE_CUBE_MAP,i.image.__webGLTextureCube)}}function e(i,n){if(!i.__webGLTexture&&i.image.loaded){i.__webGLTexture=c.createTexture();
+c.bindTexture(c.TEXTURE_2D,i.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,i.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,g(i.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,g(i.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+n);c.bindTexture(c.TEXTURE_2D,i.__webGLTexture)}
+function f(i,n){var h,x,m;h=0;for(x=n.length;h<x;h++){m=n[h];i.uniforms[m]=c.getUniformLocation(i,m)}}function j(i,n){var h,x,m;h=0;for(x=n.length;h<x;h++){m=n[h];i.attributes[m]=c.getAttribLocation(i,m);i.attributes[m]>=0&&c.enableVertexAttribArray(i.attributes[m])}}function k(i,n){var h;if(i=="fragment")h=c.createShader(c.FRAGMENT_SHADER);else if(i=="vertex")h=c.createShader(c.VERTEX_SHADER);c.shaderSource(h,n);c.compileShader(h);if(!c.getShaderParameter(h,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(h));
+return null}return h}function g(i){switch(i){case THREE.Repeat:return c.REPEAT;case THREE.ClampToEdge:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeat:return c.MIRRORED_REPEAT}return 0}var p=document.createElement("canvas"),c,t,F,r=new THREE.Matrix4,w,v=new Float32Array(16),y=new Float32Array(16),L=new Float32Array(16),u=new Float32Array(9),A=new Float32Array(16);a=function(i,n){if(i){var h,x,m,l=pointLights=maxDirLights=maxPointLights=0;h=0;for(x=i.lights.length;h<x;h++){m=i.lights[h];m instanceof
+THREE.DirectionalLight&&l++;m instanceof THREE.PointLight&&pointLights++}if(pointLights+l<=n){maxDirLights=l;maxPointLights=pointLights}else{maxDirLights=Math.ceil(n*l/(pointLights+l));maxPointLights=n-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:n-1}}(a,4);this.domElement=p;this.autoClear=true;try{c=p.getContext("experimental-webgl",{antialias:true})}catch(o){}if(!c){alert("WebGL not supported");throw"cannot create webgl context";}c.clearColor(0,0,
+0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK);c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(0,0,0,0);t=F=function(i,n){var h=[i?"#define MAX_DIR_LIGHTS "+i:"",n?"#define MAX_POINT_LIGHTS "+n:"","uniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",i?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":
+"",i?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",n?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",n?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","uniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",n?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform float mRefractionRatio;\nvoid main(void) {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec3 transformedNormal = normalize( normalMatrix * normal );\nif ( !enableLighting ) {\nvLightWeighting = vec3( 1.0, 1.0, 1.0 );\n} else {\nvLightWeighting = ambientLightColor;",
+i?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",i?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",i?"float directionalLightWeighting = max( dot( transformedNormal, normalize(lDirection.xyz ) ), 0.0 );":"",i?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",i?"}":"",n?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",n?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",n?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
+"",n?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",n?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",n?"}":"","}\nvNormal = transformedNormal;\nvUv = uv;\nif ( useRefract ) {\nvReflect = refract( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz), mRefractionRatio );\n} else {\nvReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );\n}\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n"),
+x=[i?"#define MAX_DIR_LIGHTS "+i:"",n?"#define MAX_POINT_LIGHTS "+n:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\nuniform float m2Near;\nuniform float mFarPlusNear;\nuniform float mFarMinusNear;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
+i?"uniform mat4 viewMatrix;":"",i?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",n?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform vec3 cameraPosition;\nvoid main() {\nvec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nvec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nif ( enableMap ) {\nmapColor = texture2D( tMap, vUv );\n}\nif ( enableCubeMap ) {\ncubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\n}\nif ( material == 5 ) { \nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( -wPos.x, wPos.yz ) );\n} else if ( material == 4 ) { \ngl_FragColor = vec4( 0.5*normalize( vNormal ) + vec3(0.5, 0.5, 0.5), mOpacity );\n} else if ( material == 3 ) { \nfloat w = 0.5;\ngl_FragColor = vec4( w, w, w, mOpacity );\n} else if ( material == 2 ) { \nvec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );",
+n?"vec4 pointDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",n?"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",n?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",n?"vec3 pointVector = normalize( vPointLightVector[ i ] );":"",n?"vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );":"",n?"float pointDotNormalHalf = dot( normal, pointHalfVector );":"",n?"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );":"",n?"float pointSpecularWeight = 0.0;":"",n?"if ( pointDotNormalHalf >= 0.0 )":
+"",n?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",n?"pointDiffuse  += mColor * pointDiffuseWeight;":"",n?"pointSpecular += mSpecular * pointSpecularWeight;":"",n?"}":"",i?"vec4 dirDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",i?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",i?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",i?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",i?"vec3 dirVector = normalize( lDirection.xyz );":"",i?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
+"",i?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",i?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",i?"float dirSpecularWeight = 0.0;":"",i?"if ( dirDotNormalHalf >= 0.0 )":"",i?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",i?"dirDiffuse  += mColor * dirDiffuseWeight;":"",i?"dirSpecular += mSpecular * dirSpecularWeight;":"",i?"}":"","vec4 totalLight = mAmbient;",i?"totalLight += dirDiffuse + dirSpecular;":"",n?"totalLight += pointDiffuse + pointSpecular;":
 "","if ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mapColor.rgb * totalLight.xyz * vLightWeighting, cubeColor.rgb, mReflectivity ), mapColor.a );\n} else {\ngl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );\n}\n} else if ( material == 1 ) {\nif ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mColor.rgb * mapColor.rgb * vLightWeighting, cubeColor.rgb, mReflectivity ), mColor.a * mapColor.a );\n} else {\ngl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );\n}\n} else {\nif ( mixEnvMap ) {\ngl_FragColor = mix( mColor * mapColor, cubeColor, mReflectivity );\n} else {\ngl_FragColor = mColor * mapColor * cubeColor;\n}\n}\n}"].join("\n");
 "","if ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mapColor.rgb * totalLight.xyz * vLightWeighting, cubeColor.rgb, mReflectivity ), mapColor.a );\n} else {\ngl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );\n}\n} else if ( material == 1 ) {\nif ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mColor.rgb * mapColor.rgb * vLightWeighting, cubeColor.rgb, mReflectivity ), mColor.a * mapColor.a );\n} else {\ngl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );\n}\n} else {\nif ( mixEnvMap ) {\ngl_FragColor = mix( mColor * mapColor, cubeColor, mReflectivity );\n} else {\ngl_FragColor = mColor * mapColor * cubeColor;\n}\n}\n}"].join("\n");
-s=b(x,p);c.useProgram(s);f(s,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract","m2Near","mFarPlusNear","mFarMinusNear"]);h&&f(s,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);i&&f(s,["pointLightNumber","pointLightColor",
-"pointLightPosition"]);c.uniform1i(s.uniforms.enableMap,0);c.uniform1i(s.uniforms.tMap,0);c.uniform1i(s.uniforms.enableCubeMap,0);c.uniform1i(s.uniforms.tCube,1);c.uniform1i(s.uniforms.mixEnvMap,0);c.uniform1i(s.uniforms.useRefract,0);j(s)})(a.directional,a.point);this.setSize=function(h,i){o.width=h;o.height=i;c.viewport(0,0,o.width,o.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(h,i){var p,x,m,l,E,B=[],Q=[],G=[];l=[];E=[];c.uniform1i(h.uniforms.enableLighting,
-i.lights.length);p=0;for(x=i.lights.length;p<x;p++){m=i.lights[p];if(m instanceof THREE.AmbientLight)B.push(m);else if(m instanceof THREE.DirectionalLight)G.push(m);else m instanceof THREE.PointLight&&Q.push(m)}p=m=l=E=0;for(x=B.length;p<x;p++){m+=B[p].color.r;l+=B[p].color.g;E+=B[p].color.b}c.uniform3f(h.uniforms.ambientLightColor,m,l,E);l=[];E=[];p=0;for(x=G.length;p<x;p++){m=G[p];l.push(m.color.r*m.intensity);l.push(m.color.g*m.intensity);l.push(m.color.b*m.intensity);E.push(m.position.x);E.push(m.position.y);
-E.push(m.position.z)}if(G.length){c.uniform1i(h.uniforms.directionalLightNumber,G.length);c.uniform3fv(h.uniforms.directionalLightDirection,E);c.uniform3fv(h.uniforms.directionalLightColor,l)}l=[];E=[];p=0;for(x=Q.length;p<x;p++){m=Q[p];l.push(m.color.r*m.intensity);l.push(m.color.g*m.intensity);l.push(m.color.b*m.intensity);E.push(m.position.x);E.push(m.position.y);E.push(m.position.z)}if(Q.length){c.uniform1i(h.uniforms.pointLightNumber,Q.length);c.uniform3fv(h.uniforms.pointLightPosition,E);c.uniform3fv(h.uniforms.pointLightColor,
-l)}};this.createBuffers=function(h,i){var p,x,m,l,E,B,Q,G,V=[],U=[],D=[],P=[],C=[],J=0,I=h.geometry.geometryChunks[i],T;m=false;p=0;for(x=h.material.length;p<x;p++){meshMaterial=h.material[p];if(meshMaterial instanceof THREE.MeshFaceMaterial){E=0;for(T=I.material.length;E<T;E++)if(I.material[E]&&I.material[E].shading!=undefined&&I.material[E].shading==THREE.SmoothShading){m=true;break}}else if(meshMaterial&&meshMaterial.shading!=undefined&&meshMaterial.shading==THREE.SmoothShading){m=true;break}if(m)break}T=
-m;p=0;for(x=I.faces.length;p<x;p++){m=I.faces[p];l=h.geometry.faces[m];E=l.vertexNormals;faceNormal=l.normal;m=h.geometry.uvs[m];if(l instanceof THREE.Face3){B=h.geometry.vertices[l.a].position;Q=h.geometry.vertices[l.b].position;G=h.geometry.vertices[l.c].position;D.push(B.x,B.y,B.z);D.push(Q.x,Q.y,Q.z);D.push(G.x,G.y,G.z);if(E.length==3&&T)for(l=0;l<3;l++)P.push(E[l].x,E[l].y,E[l].z);else for(l=0;l<3;l++)P.push(faceNormal.x,faceNormal.y,faceNormal.z);if(m)for(l=0;l<3;l++)C.push(m[l].u,m[l].v);V.push(J,
-J+1,J+2);U.push(J,J+1);U.push(J,J+2);U.push(J+1,J+2);J+=3}else if(l instanceof THREE.Face4){B=h.geometry.vertices[l.a].position;Q=h.geometry.vertices[l.b].position;G=h.geometry.vertices[l.c].position;l=h.geometry.vertices[l.d].position;D.push(B.x,B.y,B.z);D.push(Q.x,Q.y,Q.z);D.push(G.x,G.y,G.z);D.push(l.x,l.y,l.z);if(E.length==4&&T)for(l=0;l<4;l++)P.push(E[l].x,E[l].y,E[l].z);else for(l=0;l<4;l++)P.push(faceNormal.x,faceNormal.y,faceNormal.z);if(m)for(l=0;l<4;l++)C.push(m[l].u,m[l].v);V.push(J,J+
-1,J+2);V.push(J,J+2,J+3);U.push(J,J+1);U.push(J,J+2);U.push(J,J+3);U.push(J+1,J+2);U.push(J+2,J+3);J+=4}}if(D.length){I.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,I.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(D),c.STATIC_DRAW);I.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,I.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(P),c.STATIC_DRAW);I.__webGLUVBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,I.__webGLUVBuffer);
-c.bufferData(c.ARRAY_BUFFER,new Float32Array(C),c.STATIC_DRAW);I.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,I.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(V),c.STATIC_DRAW);I.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,I.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(U),c.STATIC_DRAW);I.__webGLFaceCount=V.length;I.__webGLLineCount=U.length}};this.renderBuffer=function(h,i,p){var x,m,l,E,B,Q,G,
-V,U,D;if(i instanceof THREE.MeshShaderMaterial){if(!i.program){i.program=b(i.fragment_shader,i.vertex_shader);G=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(D in i.uniforms)G.push(D);f(i.program,G);j(i.program)}D=i.program}else D=s;if(D!=F){c.useProgram(D);F=D}if(i instanceof THREE.MeshShaderMaterial){l=i.wireframe;E=i.wireframe_linewidth;G=D;V=i.uniforms;var P,C;for(m in V){P=V[m].type;U=V[m].value;C=G.uniforms[m];if(P=="i")c.uniform1i(C,
-U);else if(P=="f")c.uniform1f(C,U);else if(P=="t"){c.uniform1i(C,U);P=V[m].texture;if(P instanceof THREE.TextureCube)d(P,U);else P instanceof THREE.Texture&&e(P,U)}}this.loadCamera(D,h);this.loadMatrices(D)}else if(i instanceof THREE.MeshPhongMaterial||i instanceof THREE.MeshLambertMaterial||i instanceof THREE.MeshBasicMaterial){h=i.color;x=i.opacity;l=i.wireframe;E=i.wireframe_linewidth;B=i.map;Q=i.env_map;G=i.combine==THREE.Mix;m=i.reflectivity;U=i.env_map&&i.env_map.mapping==THREE.RefractionMapping;
-V=i.refraction_ratio;c.uniform4f(D.uniforms.mColor,h.r*x,h.g*x,h.b*x,x);c.uniform1i(D.uniforms.mixEnvMap,G);c.uniform1f(D.uniforms.mReflectivity,m);c.uniform1i(D.uniforms.useRefract,U);c.uniform1f(D.uniforms.mRefractionRatio,V)}if(i instanceof THREE.MeshNormalMaterial){x=i.opacity;c.uniform1f(D.uniforms.mOpacity,x);c.uniform1i(D.uniforms.material,4)}else if(i instanceof THREE.MeshDepthMaterial){x=i.opacity;l=i.wireframe;E=i.wireframe_linewidth;c.uniform1f(D.uniforms.mOpacity,x);c.uniform1f(D.uniforms.m2Near,
-i.__2near);c.uniform1f(D.uniforms.mFarPlusNear,i.__farPlusNear);c.uniform1f(D.uniforms.mFarMinusNear,i.__farMinusNear);c.uniform1i(D.uniforms.material,3)}else if(i instanceof THREE.MeshPhongMaterial){h=i.ambient;m=i.specular;i=i.shininess;c.uniform4f(D.uniforms.mAmbient,h.r,h.g,h.b,x);c.uniform4f(D.uniforms.mSpecular,m.r,m.g,m.b,x);c.uniform1f(D.uniforms.mShininess,i);c.uniform1i(D.uniforms.material,2)}else if(i instanceof THREE.MeshLambertMaterial)c.uniform1i(D.uniforms.material,1);else if(i instanceof
-THREE.MeshBasicMaterial)c.uniform1i(D.uniforms.material,0);else if(i instanceof THREE.MeshCubeMaterial){c.uniform1i(D.uniforms.material,5);Q=i.env_map}if(B){e(B,0);c.uniform1i(D.uniforms.tMap,0);c.uniform1i(D.uniforms.enableMap,1)}else c.uniform1i(D.uniforms.enableMap,0);if(Q){d(Q,1);c.uniform1i(D.uniforms.tCube,1);c.uniform1i(D.uniforms.enableCubeMap,1)}else c.uniform1i(D.uniforms.enableCubeMap,0);c.bindBuffer(c.ARRAY_BUFFER,p.__webGLVertexBuffer);c.vertexAttribPointer(D.position,3,c.FLOAT,false,
-0,0);c.bindBuffer(c.ARRAY_BUFFER,p.__webGLNormalBuffer);c.vertexAttribPointer(D.normal,3,c.FLOAT,false,0,0);if(B){c.bindBuffer(c.ARRAY_BUFFER,p.__webGLUVBuffer);c.enableVertexAttribArray(D.uv);c.vertexAttribPointer(D.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(D.uv);if(l){c.lineWidth(E);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,p.__webGLLineBuffer);c.drawElements(c.LINES,p.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,p.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,
-p.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(h,i,p,x,m){var l,E,B,Q,G;B=0;for(Q=i.material.length;B<Q;B++){l=i.material[B];if(l instanceof THREE.MeshFaceMaterial){l=0;for(E=p.material.length;l<E;l++)if((G=p.material[l])&&G.blending==x&&G.opacity<1==m){this.setBlending(G.blending);this.renderBuffer(h,G,p)}}else if((G=l)&&G.blending==x&&G.opacity<1==m){this.setBlending(G.blending);this.renderBuffer(h,G,p)}}};this.render=function(h,i){var p,x,m,l;this.initWebGLObjects(h);this.autoClear&&
-this.clear();i.autoUpdateMatrix&&i.updateMatrix();this.loadCamera(s,i);this.setupLights(s,h);p=0;for(x=h.__webGLObjects.length;p<x;p++){m=h.__webGLObjects[p];l=m.object;m=m.buffer;if(l.visible){this.setupMatrices(l,i);this.loadMatrices(s);this.renderPass(i,l,m,THREE.NormalBlending,false)}}p=0;for(x=h.__webGLObjects.length;p<x;p++){m=h.__webGLObjects[p];l=m.object;m=m.buffer;if(l.visible){this.setupMatrices(l,i);this.loadMatrices(s);this.renderPass(i,l,m,THREE.AdditiveBlending,false);this.renderPass(i,
-l,m,THREE.SubtractiveBlending,false);this.renderPass(i,l,m,THREE.AdditiveBlending,true);this.renderPass(i,l,m,THREE.SubtractiveBlending,true);this.renderPass(i,l,m,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(h){var i,p,x,m,l,E;if(!h.__webGLObjects){h.__webGLObjects=[];h.__webGLObjectsMap={}}i=0;for(p=h.objects.length;i<p;i++){x=h.objects[i];if(h.__webGLObjectsMap[x.id]==undefined)h.__webGLObjectsMap[x.id]={};E=h.__webGLObjectsMap[x.id];if(x instanceof THREE.Mesh)for(l in x.geometry.geometryChunks){m=
-x.geometry.geometryChunks[l];m.__webGLVertexBuffer||this.createBuffers(x,l);if(E[l]==undefined){m={buffer:m,object:x};h.__webGLObjects.push(m);E[l]=1}}}};this.removeObject=function(h,i){var p,x;for(p=h.__webGLObjects.length-1;p>=0;p--){x=h.__webGLObjects[p].object;i==x&&h.__webGLObjects.splice(p,1)}};this.setupMatrices=function(h,i){h.autoUpdateMatrix&&h.updateMatrix();r.multiply(i.matrix,h.matrix);v.set(i.matrix.flatten());y.set(r.flatten());L.set(i.projectionMatrix.flatten());w=THREE.Matrix4.makeInvert3x3(r).transpose();
-u.set(w.m);A.set(h.matrix.flatten())};this.loadMatrices=function(h){c.uniformMatrix4fv(h.uniforms.viewMatrix,false,v);c.uniformMatrix4fv(h.uniforms.modelViewMatrix,false,y);c.uniformMatrix4fv(h.uniforms.projectionMatrix,false,L);c.uniformMatrix3fv(h.uniforms.normalMatrix,false,u);c.uniformMatrix4fv(h.uniforms.objectMatrix,false,A)};this.loadCamera=function(h,i){c.uniform3f(h.uniforms.cameraPosition,i.position.x,i.position.y,i.position.z)};this.setBlending=function(h){switch(h){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);
-c.blendFunc(c.ONE,c.ONE);break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(h,i){if(h){!i||i=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(h=="back")c.cullFace(c.BACK);else h=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)}};
+h=b(x,h);c.useProgram(h);f(h,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract","m2Near","mFarPlusNear","mFarMinusNear"]);i&&f(h,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);n&&f(h,["pointLightNumber","pointLightColor",
+"pointLightPosition"]);c.uniform1i(h.uniforms.enableMap,0);c.uniform1i(h.uniforms.tMap,0);c.uniform1i(h.uniforms.enableCubeMap,0);c.uniform1i(h.uniforms.tCube,1);c.uniform1i(h.uniforms.mixEnvMap,0);c.uniform1i(h.uniforms.useRefract,0);j(h,["position","normal","uv"]);return h}(a.directional,a.point);this.setSize=function(i,n){p.width=i;p.height=n;c.viewport(0,0,p.width,p.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(i,n){var h,x,m,l,B,C=[],
+Q=[],J=[];l=[];B=[];c.uniform1i(i.uniforms.enableLighting,n.length);h=0;for(x=n.length;h<x;h++){m=n[h];if(m instanceof THREE.AmbientLight)C.push(m);else if(m instanceof THREE.DirectionalLight)J.push(m);else m instanceof THREE.PointLight&&Q.push(m)}h=m=l=B=0;for(x=C.length;h<x;h++){m+=C[h].color.r;l+=C[h].color.g;B+=C[h].color.b}c.uniform3f(i.uniforms.ambientLightColor,m,l,B);l=[];B=[];h=0;for(x=J.length;h<x;h++){m=J[h];l.push(m.color.r*m.intensity);l.push(m.color.g*m.intensity);l.push(m.color.b*m.intensity);
+B.push(m.position.x);B.push(m.position.y);B.push(m.position.z)}if(J.length){c.uniform1i(i.uniforms.directionalLightNumber,J.length);c.uniform3fv(i.uniforms.directionalLightDirection,B);c.uniform3fv(i.uniforms.directionalLightColor,l)}l=[];B=[];h=0;for(x=Q.length;h<x;h++){m=Q[h];l.push(m.color.r*m.intensity);l.push(m.color.g*m.intensity);l.push(m.color.b*m.intensity);B.push(m.position.x);B.push(m.position.y);B.push(m.position.z)}if(Q.length){c.uniform1i(i.uniforms.pointLightNumber,Q.length);c.uniform3fv(i.uniforms.pointLightPosition,
+B);c.uniform3fv(i.uniforms.pointLightColor,l)}};this.createBuffers=function(i,n){var h,x,m,l,B,C,Q,J,P=[],S=[],E=[],T=[],D=[],I=0,H=i.geometry.geometryChunks[n],V;m=false;h=0;for(x=i.material.length;h<x;h++){meshMaterial=i.material[h];if(meshMaterial instanceof THREE.MeshFaceMaterial){B=0;for(V=H.material.length;B<V;B++)if(H.material[B]&&H.material[B].shading!=undefined&&H.material[B].shading==THREE.SmoothShading){m=true;break}}else if(meshMaterial&&meshMaterial.shading!=undefined&&meshMaterial.shading==
+THREE.SmoothShading){m=true;break}if(m)break}V=m;h=0;for(x=H.faces.length;h<x;h++){m=H.faces[h];l=i.geometry.faces[m];B=l.vertexNormals;faceNormal=l.normal;m=i.geometry.uvs[m];if(l instanceof THREE.Face3){C=i.geometry.vertices[l.a].position;Q=i.geometry.vertices[l.b].position;J=i.geometry.vertices[l.c].position;E.push(C.x,C.y,C.z);E.push(Q.x,Q.y,Q.z);E.push(J.x,J.y,J.z);if(B.length==3&&V)for(l=0;l<3;l++)T.push(B[l].x,B[l].y,B[l].z);else for(l=0;l<3;l++)T.push(faceNormal.x,faceNormal.y,faceNormal.z);
+if(m)for(l=0;l<3;l++)D.push(m[l].u,m[l].v);P.push(I,I+1,I+2);S.push(I,I+1);S.push(I,I+2);S.push(I+1,I+2);I+=3}else if(l instanceof THREE.Face4){C=i.geometry.vertices[l.a].position;Q=i.geometry.vertices[l.b].position;J=i.geometry.vertices[l.c].position;l=i.geometry.vertices[l.d].position;E.push(C.x,C.y,C.z);E.push(Q.x,Q.y,Q.z);E.push(J.x,J.y,J.z);E.push(l.x,l.y,l.z);if(B.length==4&&V)for(l=0;l<4;l++)T.push(B[l].x,B[l].y,B[l].z);else for(l=0;l<4;l++)T.push(faceNormal.x,faceNormal.y,faceNormal.z);if(m)for(l=
+0;l<4;l++)D.push(m[l].u,m[l].v);P.push(I,I+1,I+2);P.push(I,I+2,I+3);S.push(I,I+1);S.push(I,I+2);S.push(I,I+3);S.push(I+1,I+2);S.push(I+2,I+3);I+=4}}if(E.length){H.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,H.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(E),c.STATIC_DRAW);H.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,H.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(T),c.STATIC_DRAW);if(D.length>0){H.__webGLUVBuffer=c.createBuffer();
+c.bindBuffer(c.ARRAY_BUFFER,H.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(D),c.STATIC_DRAW)}H.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,H.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(P),c.STATIC_DRAW);H.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,H.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(S),c.STATIC_DRAW);H.__webGLFaceCount=P.length;H.__webGLLineCount=S.length}};this.renderBuffer=
+function(i,n,h,x){var m,l,B,C,Q,J,P,S,E;if(h instanceof THREE.MeshShaderMaterial){if(!h.program){h.program=b(h.fragment_shader,h.vertex_shader);P=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(E in h.uniforms)P.push(E);f(h.program,P);j(h.program,["position","normal","uv"])}E=h.program}else E=F;if(E!=t){c.useProgram(E);t=E}E==F&&this.setupLights(E,n);this.loadCamera(E,i);this.loadMatrices(E);if(h instanceof THREE.MeshShaderMaterial){B=h.wireframe;
+C=h.wireframe_linewidth;i=E;n=h.uniforms;var T;for(m in n){S=n[m].type;P=n[m].value;T=i.uniforms[m];if(S=="i")c.uniform1i(T,P);else if(S=="f")c.uniform1f(T,P);else if(S=="t"){c.uniform1i(T,P);S=n[m].texture;if(S instanceof THREE.TextureCube)d(S,P);else S instanceof THREE.Texture&&e(S,P)}}}if(h instanceof THREE.MeshPhongMaterial||h instanceof THREE.MeshLambertMaterial||h instanceof THREE.MeshBasicMaterial){m=h.color;l=h.opacity;B=h.wireframe;C=h.wireframe_linewidth;Q=h.map;J=h.env_map;n=h.combine==
+THREE.Mix;i=h.reflectivity;S=h.env_map&&h.env_map.mapping==THREE.RefractionMapping;P=h.refraction_ratio;c.uniform4f(E.uniforms.mColor,m.r*l,m.g*l,m.b*l,l);c.uniform1i(E.uniforms.mixEnvMap,n);c.uniform1f(E.uniforms.mReflectivity,i);c.uniform1i(E.uniforms.useRefract,S);c.uniform1f(E.uniforms.mRefractionRatio,P)}if(h instanceof THREE.MeshNormalMaterial){l=h.opacity;c.uniform1f(E.uniforms.mOpacity,l);c.uniform1i(E.uniforms.material,4)}else if(h instanceof THREE.MeshDepthMaterial){l=h.opacity;B=h.wireframe;
+C=h.wireframe_linewidth;c.uniform1f(E.uniforms.mOpacity,l);c.uniform1f(E.uniforms.m2Near,h.__2near);c.uniform1f(E.uniforms.mFarPlusNear,h.__farPlusNear);c.uniform1f(E.uniforms.mFarMinusNear,h.__farMinusNear);c.uniform1i(E.uniforms.material,3)}else if(h instanceof THREE.MeshPhongMaterial){m=h.ambient;i=h.specular;h=h.shininess;c.uniform4f(E.uniforms.mAmbient,m.r,m.g,m.b,l);c.uniform4f(E.uniforms.mSpecular,i.r,i.g,i.b,l);c.uniform1f(E.uniforms.mShininess,h);c.uniform1i(E.uniforms.material,2)}else if(h instanceof
+THREE.MeshLambertMaterial)c.uniform1i(E.uniforms.material,1);else if(h instanceof THREE.MeshBasicMaterial)c.uniform1i(E.uniforms.material,0);else if(h instanceof THREE.MeshCubeMaterial){c.uniform1i(E.uniforms.material,5);J=h.env_map}if(Q){e(Q,0);c.uniform1i(E.uniforms.tMap,0);c.uniform1i(E.uniforms.enableMap,1)}else c.uniform1i(E.uniforms.enableMap,0);if(J){d(J,1);c.uniform1i(E.uniforms.tCube,1);c.uniform1i(E.uniforms.enableCubeMap,1)}else c.uniform1i(E.uniforms.enableCubeMap,0);l=E.attributes;c.bindBuffer(c.ARRAY_BUFFER,
+x.__webGLVertexBuffer);c.vertexAttribPointer(l.position,3,c.FLOAT,false,0,0);c.bindBuffer(c.ARRAY_BUFFER,x.__webGLNormalBuffer);c.vertexAttribPointer(l.normal,3,c.FLOAT,false,0,0);if(l.uv>=0)if(x.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,x.__webGLUVBuffer);c.enableVertexAttribArray(l.uv);c.vertexAttribPointer(l.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(l.uv);if(B){c.lineWidth(C);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,x.__webGLLineBuffer);c.drawElements(c.LINES,x.__webGLLineCount,c.UNSIGNED_SHORT,
+0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,x.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,x.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(i,n,h,x,m,l){var B,C,Q,J,P;Q=0;for(J=h.material.length;Q<J;Q++){B=h.material[Q];if(B instanceof THREE.MeshFaceMaterial){B=0;for(C=x.material.length;B<C;B++)if((P=x.material[B])&&P.blending==m&&P.opacity<1==l){this.setBlending(P.blending);this.renderBuffer(i,n,P,x)}}else if((P=B)&&P.blending==m&&P.opacity<1==l){this.setBlending(P.blending);this.renderBuffer(i,
+n,P,x)}}};this.render=function(i,n){var h,x,m,l,B=i.lights;this.initWebGLObjects(i);this.autoClear&&this.clear();n.autoUpdateMatrix&&n.updateMatrix();h=0;for(x=i.__webGLObjects.length;h<x;h++){m=i.__webGLObjects[h];l=m.object;m=m.buffer;if(l.visible){this.setupMatrices(l,n);this.renderPass(n,B,l,m,THREE.NormalBlending,false)}}h=0;for(x=i.__webGLObjects.length;h<x;h++){m=i.__webGLObjects[h];l=m.object;m=m.buffer;if(l.visible){this.setupMatrices(l,n);this.renderPass(n,B,l,m,THREE.AdditiveBlending,false);
+this.renderPass(n,B,l,m,THREE.SubtractiveBlending,false);this.renderPass(n,B,l,m,THREE.AdditiveBlending,true);this.renderPass(n,B,l,m,THREE.SubtractiveBlending,true);this.renderPass(n,B,l,m,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(i){var n,h,x,m,l,B;if(!i.__webGLObjects){i.__webGLObjects=[];i.__webGLObjectsMap={}}n=0;for(h=i.objects.length;n<h;n++){x=i.objects[n];if(i.__webGLObjectsMap[x.id]==undefined)i.__webGLObjectsMap[x.id]={};B=i.__webGLObjectsMap[x.id];if(x instanceof THREE.Mesh)for(l in x.geometry.geometryChunks){m=
+x.geometry.geometryChunks[l];m.__webGLVertexBuffer||this.createBuffers(x,l);if(B[l]==undefined){m={buffer:m,object:x};i.__webGLObjects.push(m);B[l]=1}}}};this.removeObject=function(i,n){var h,x;for(h=i.__webGLObjects.length-1;h>=0;h--){x=i.__webGLObjects[h].object;n==x&&i.__webGLObjects.splice(h,1)}};this.setupMatrices=function(i,n){i.autoUpdateMatrix&&i.updateMatrix();r.multiply(n.matrix,i.matrix);v.set(n.matrix.flatten());y.set(r.flatten());L.set(n.projectionMatrix.flatten());w=THREE.Matrix4.makeInvert3x3(r).transpose();
+u.set(w.m);A.set(i.matrix.flatten())};this.loadMatrices=function(i){c.uniformMatrix4fv(i.uniforms.viewMatrix,false,v);c.uniformMatrix4fv(i.uniforms.modelViewMatrix,false,y);c.uniformMatrix4fv(i.uniforms.projectionMatrix,false,L);c.uniformMatrix3fv(i.uniforms.normalMatrix,false,u);c.uniformMatrix4fv(i.uniforms.objectMatrix,false,A)};this.loadCamera=function(i,n){c.uniform3f(i.uniforms.cameraPosition,n.position.x,n.position.y,n.position.z)};this.setBlending=function(i){switch(i){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);
+c.blendFunc(c.ONE,c.ONE);break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(i,n){if(i){!n||n=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(i=="back")c.cullFace(c.BACK);else i=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)}};
 THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[];this.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null};
 THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[];this.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null};
 THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=null};
 THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=null};
-var GeometryUtils={merge:function(a,b){var d=b instanceof THREE.Mesh,e=a.vertices.length,f=d?b.geometry:b,j=a.vertices,k=f.vertices,g=a.faces,o=f.faces,c=a.uvs;f=f.uvs;d&&b.updateMatrix();for(var s=0,F=k.length;s<F;s++){var r=new THREE.Vertex(k[s].position.clone());d&&b.matrix.transformVector3(r.position);j.push(r)}s=0;for(F=o.length;s<F;s++){k=o[s];var w,v=k.vertexNormals;if(k instanceof THREE.Face3)w=new THREE.Face3(k.a+e,k.b+e,k.c+e);else if(k instanceof THREE.Face4)w=new THREE.Face4(k.a+e,k.b+
-e,k.c+e,k.d+e);w.centroid.copy(k.centroid);w.normal.copy(k.normal);d=0;for(j=v.length;d<j;d++){r=v[d];w.vertexNormals.push(r.clone())}w.material=k.material.slice();g.push(w)}s=0;for(F=f.length;s<F;s++){e=f[s];g=[];d=0;for(j=e.length;d<j;d++)g.push(new THREE.UV(e[d].u,e[d].v));c.push(g)}}},ImageUtils={loadTexture:function(a,b){var d=new THREE.Texture(null,b),e=new Image;e.onload=function(){d.image=this;d.loaded=true};e.src=a;return d},loadArray:function(a){var b,d,e=[];b=e.loadCount=0;for(d=a.length;b<
-d;++b){e[b]=new Image;e[b].loaded=0;e[b].onload=function(){e.loadCount+=1;this.loaded=1};e[b].src=a[b]}return e}},SceneUtils={addMesh:function(a,b,d,e,f,j,k,g,o,c){b=new THREE.Mesh(b,c);b.scale.x=b.scale.y=b.scale.z=d;b.position.x=e;b.position.y=f;b.position.z=j;b.rotation.x=k;b.rotation.y=g;b.rotation.z=o;a.addObject(b);return b},addPanoramaCubeWebGL:function(a,b,d){d=new THREE.MeshCubeMaterial({env_map:d});b=new THREE.Mesh(new Cube(b,b,b,1,1,null,true),d);a.addObject(b);return b},addPanoramaCube:function(a,
+var GeometryUtils={merge:function(a,b){var d=b instanceof THREE.Mesh,e=a.vertices.length,f=d?b.geometry:b,j=a.vertices,k=f.vertices,g=a.faces,p=f.faces,c=a.uvs;f=f.uvs;d&&b.updateMatrix();for(var t=0,F=k.length;t<F;t++){var r=new THREE.Vertex(k[t].position.clone());d&&b.matrix.multiplyVector3(r.position);j.push(r)}t=0;for(F=p.length;t<F;t++){k=p[t];var w,v=k.vertexNormals;if(k instanceof THREE.Face3)w=new THREE.Face3(k.a+e,k.b+e,k.c+e);else if(k instanceof THREE.Face4)w=new THREE.Face4(k.a+e,k.b+
+e,k.c+e,k.d+e);w.centroid.copy(k.centroid);w.normal.copy(k.normal);d=0;for(j=v.length;d<j;d++){r=v[d];w.vertexNormals.push(r.clone())}w.material=k.material.slice();g.push(w)}t=0;for(F=f.length;t<F;t++){e=f[t];g=[];d=0;for(j=e.length;d<j;d++)g.push(new THREE.UV(e[d].u,e[d].v));c.push(g)}}},ImageUtils={loadTexture:function(a,b){var d=new THREE.Texture(null,b),e=new Image;e.onload=function(){d.image=this;d.loaded=true};e.src=a;return d},loadArray:function(a){var b,d,e=[];b=e.loadCount=0;for(d=a.length;b<
+d;++b){e[b]=new Image;e[b].loaded=0;e[b].onload=function(){e.loadCount+=1;this.loaded=1};e[b].src=a[b]}return e}},SceneUtils={addMesh:function(a,b,d,e,f,j,k,g,p,c){b=new THREE.Mesh(b,c);b.scale.x=b.scale.y=b.scale.z=d;b.position.x=e;b.position.y=f;b.position.z=j;b.rotation.x=k;b.rotation.y=g;b.rotation.z=p;a.addObject(b);return b},addPanoramaCubeWebGL:function(a,b,d){d=new THREE.MeshCubeMaterial({env_map:d});b=new THREE.Mesh(new Cube(b,b,b,1,1,null,true),d);a.addObject(b);return b},addPanoramaCube:function(a,
 b,d){var e=[];e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[0])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[1])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[2])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[3])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[4])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[5])}));mesh=new THREE.Mesh(new Cube(b,b,b,1,1,e,true),new THREE.MeshFaceMaterial);a.addObject(mesh);
 b,d){var e=[];e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[0])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[1])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[2])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[3])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[4])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[5])}));mesh=new THREE.Mesh(new Cube(b,b,b,1,1,e,true),new THREE.MeshFaceMaterial);a.addObject(mesh);
 return mesh},addPanoramaCubePlanes:function(a,b,d){var e=b/2;b=new Plane(b,b);var f=Math.PI/2,j=Math.PI;SceneUtils.addMesh(a,b,1,0,0,-e,0,0,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[5])}));SceneUtils.addMesh(a,b,1,-e,0,0,0,f,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[0])}));SceneUtils.addMesh(a,b,1,e,0,0,0,-f,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[1])}));SceneUtils.addMesh(a,b,1,0,e,0,f,0,j,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[2])}));SceneUtils.addMesh(a,
 return mesh},addPanoramaCubePlanes:function(a,b,d){var e=b/2;b=new Plane(b,b);var f=Math.PI/2,j=Math.PI;SceneUtils.addMesh(a,b,1,0,0,-e,0,0,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[5])}));SceneUtils.addMesh(a,b,1,-e,0,0,0,f,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[0])}));SceneUtils.addMesh(a,b,1,e,0,0,0,-f,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[1])}));SceneUtils.addMesh(a,b,1,0,e,0,f,0,j,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[2])}));SceneUtils.addMesh(a,
 b,1,0,-e,0,-f,0,j,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[3])}))}},ShaderUtils={lib:{fresnel:{uniforms:{mRefractionRatio:{type:"f",value:1.02},mFresnelBias:{type:"f",value:0.1},mFresnelPower:{type:"f",value:2},mFresnelScale:{type:"f",value:1},tCube:{type:"t",value:1,texture:null}},fragment_shader:"uniform samplerCube tCube;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main() {\nvec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\nvec4 refractedColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nrefractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;\nrefractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;\nrefractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;\nrefractedColor.a = 1.0;\ngl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );\n}",
 b,1,0,-e,0,-f,0,j,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[3])}))}},ShaderUtils={lib:{fresnel:{uniforms:{mRefractionRatio:{type:"f",value:1.02},mFresnelBias:{type:"f",value:0.1},mFresnelPower:{type:"f",value:2},mFresnelScale:{type:"f",value:1},tCube:{type:"t",value:1,texture:null}},fragment_shader:"uniform samplerCube tCube;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main() {\nvec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\nvec4 refractedColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nrefractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;\nrefractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;\nrefractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;\nrefractedColor.a = 1.0;\ngl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );\n}",
 vertex_shader:"uniform float mRefractionRatio;\nuniform float mFresnelBias;\nuniform float mFresnelScale;\nuniform float mFresnelPower;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main(void) {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = normalize ( mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal );\nvec3 I = mPosition.xyz - cameraPosition;\nvReflect = reflect( I, nWorld );\nvRefract[0] = refract( normalize( I ), nWorld, mRefractionRatio );\nvRefract[1] = refract( normalize( I ), nWorld, mRefractionRatio * 0.99 );\nvRefract[2] = refract( normalize( I ), nWorld, mRefractionRatio * 0.98 );\nvReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), nWorld ), mFresnelPower );\ngl_Position = projectionMatrix * mvPosition;\n}"}}},
 vertex_shader:"uniform float mRefractionRatio;\nuniform float mFresnelBias;\nuniform float mFresnelScale;\nuniform float mFresnelPower;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main(void) {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = normalize ( mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal );\nvec3 I = mPosition.xyz - cameraPosition;\nvReflect = reflect( I, nWorld );\nvRefract[0] = refract( normalize( I ), nWorld, mRefractionRatio );\nvRefract[1] = refract( normalize( I ), nWorld, mRefractionRatio * 0.99 );\nvRefract[2] = refract( normalize( I ), nWorld, mRefractionRatio * 0.98 );\nvReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), nWorld ), mFresnelPower );\ngl_Position = projectionMatrix * mvPosition;\n}"}}},
-Cube=function(a,b,d,e,f,j,k){function g(w,v,y,L,u,A,n,h){var i=e||1,p=f||1,x=i+1,m=p+1;u=u/i;A=A/p;var l=o.vertices.length,E;if(w=="x"&&v=="y"||w=="y"&&v=="x")E="z";else if(w=="x"&&v=="z"||w=="z"&&v=="x")E="y";else if(w=="z"&&v=="y"||w=="y"&&v=="z")E="x";for(iy=0;iy<m;iy++)for(ix=0;ix<x;ix++){var B=new THREE.Vector3;B[w]=(ix*u-c)*y;B[v]=(iy*A-s)*L;B[E]=n;o.vertices.push(new THREE.Vertex(B))}for(iy=0;iy<p;iy++)for(ix=0;ix<i;ix++){o.faces.push(new THREE.Face4(ix+x*iy+l,ix+x*(iy+1)+l,ix+1+x*(iy+1)+l,
-ix+1+x*iy+l,null,h));o.uvs.push([new THREE.UV(ix/i,iy/p),new THREE.UV(ix/i,(iy+1)/p),new THREE.UV((ix+1)/i,(iy+1)/p),new THREE.UV((ix+1)/i,iy/p)])}}THREE.Geometry.call(this);var o=this,c=a/2,s=b/2,F=d/2;k=k?-1:1;if(j!==undefined)if(j instanceof Array)this.materials=j;else{this.materials=[];for(var r=0;r<6;r++)this.materials.push([j])}else this.materials=[];g("z","y",1*k,-1,d,b,-c,this.materials[0]);g("z","y",-1*k,-1,d,b,c,this.materials[1]);g("x","z",1*k,1,a,d,s,this.materials[2]);g("x","z",1*k,-1,
-a,d,-s,this.materials[3]);g("x","y",1*k,-1,a,b,F,this.materials[4]);g("x","y",-1*k,-1,a,b,-F,this.materials[5]);(function(){for(var w=[],v=[],y=0,L=o.vertices.length;y<L;y++){for(var u=o.vertices[y],A=false,n=0,h=w.length;n<h;n++){var i=w[n];if(u.position.x==i.position.x&&u.position.y==i.position.y&&u.position.z==i.position.z){v[y]=n;A=true;break}}if(!A){v[y]=w.length;w.push(new THREE.Vertex(u.position.clone()))}}y=0;for(L=o.faces.length;y<L;y++){u=o.faces[y];u.a=v[u.a];u.b=v[u.b];u.c=v[u.c];u.d=
-v[u.d]}o.vertices=w})();this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};Cube.prototype=new THREE.Geometry;Cube.prototype.constructor=Cube;
-var Cylinder=function(a,b,d,e,f){function j(o,c,s){k.vertices.push(new THREE.Vertex(new THREE.Vector3(o,c,s)))}THREE.Geometry.call(this);var k=this,g;for(g=0;g<a;g++)j(Math.sin(6.283*g/a)*b,Math.cos(6.283*g/a)*b,0);for(g=0;g<a;g++)j(Math.sin(6.283*g/a)*d,Math.cos(6.283*g/a)*d,e);for(g=0;g<a;g++)k.faces.push(new THREE.Face4(g,g+a,a+(g+1)%a,(g+1)%a));if(d!=0){j(0,0,-f);for(g=a;g<a+a/2;g++)k.faces.push(new THREE.Face4(2*a,(2*g-2*a)%a,(2*g-2*a+1)%a,(2*g-2*a+2)%a))}if(b!=0){j(0,0,e+f);for(g=a+a/2;g<2*
+Cube=function(a,b,d,e,f,j,k){function g(w,v,y,L,u,A,o,i){var n=e||1,h=f||1,x=n+1,m=h+1;u=u/n;A=A/h;var l=p.vertices.length,B;if(w=="x"&&v=="y"||w=="y"&&v=="x")B="z";else if(w=="x"&&v=="z"||w=="z"&&v=="x")B="y";else if(w=="z"&&v=="y"||w=="y"&&v=="z")B="x";for(iy=0;iy<m;iy++)for(ix=0;ix<x;ix++){var C=new THREE.Vector3;C[w]=(ix*u-c)*y;C[v]=(iy*A-t)*L;C[B]=o;p.vertices.push(new THREE.Vertex(C))}for(iy=0;iy<h;iy++)for(ix=0;ix<n;ix++){p.faces.push(new THREE.Face4(ix+x*iy+l,ix+x*(iy+1)+l,ix+1+x*(iy+1)+l,
+ix+1+x*iy+l,null,i));p.uvs.push([new THREE.UV(ix/n,iy/h),new THREE.UV(ix/n,(iy+1)/h),new THREE.UV((ix+1)/n,(iy+1)/h),new THREE.UV((ix+1)/n,iy/h)])}}THREE.Geometry.call(this);var p=this,c=a/2,t=b/2,F=d/2;k=k?-1:1;if(j!==undefined)if(j instanceof Array)this.materials=j;else{this.materials=[];for(var r=0;r<6;r++)this.materials.push([j])}else this.materials=[];g("z","y",1*k,-1,d,b,-c,this.materials[0]);g("z","y",-1*k,-1,d,b,c,this.materials[1]);g("x","z",1*k,1,a,d,t,this.materials[2]);g("x","z",1*k,-1,
+a,d,-t,this.materials[3]);g("x","y",1*k,-1,a,b,F,this.materials[4]);g("x","y",-1*k,-1,a,b,-F,this.materials[5]);(function(){for(var w=[],v=[],y=0,L=p.vertices.length;y<L;y++){for(var u=p.vertices[y],A=false,o=0,i=w.length;o<i;o++){var n=w[o];if(u.position.x==n.position.x&&u.position.y==n.position.y&&u.position.z==n.position.z){v[y]=o;A=true;break}}if(!A){v[y]=w.length;w.push(new THREE.Vertex(u.position.clone()))}}y=0;for(L=p.faces.length;y<L;y++){u=p.faces[y];u.a=v[u.a];u.b=v[u.b];u.c=v[u.c];u.d=
+v[u.d]}p.vertices=w})();this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};Cube.prototype=new THREE.Geometry;Cube.prototype.constructor=Cube;
+var Cylinder=function(a,b,d,e,f){function j(p,c,t){k.vertices.push(new THREE.Vertex(new THREE.Vector3(p,c,t)))}THREE.Geometry.call(this);var k=this,g;for(g=0;g<a;g++)j(Math.sin(6.283*g/a)*b,Math.cos(6.283*g/a)*b,0);for(g=0;g<a;g++)j(Math.sin(6.283*g/a)*d,Math.cos(6.283*g/a)*d,e);for(g=0;g<a;g++)k.faces.push(new THREE.Face4(g,g+a,a+(g+1)%a,(g+1)%a));if(d!=0){j(0,0,-f);for(g=a;g<a+a/2;g++)k.faces.push(new THREE.Face4(2*a,(2*g-2*a)%a,(2*g-2*a+1)%a,(2*g-2*a+2)%a))}if(b!=0){j(0,0,e+f);for(g=a+a/2;g<2*
 a;g++)k.faces.push(new THREE.Face4((2*g-2*a+2)%a+a,(2*g-2*a+1)%a+a,(2*g-2*a)%a+a,2*a+1))}this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};Cylinder.prototype=new THREE.Geometry;Cylinder.prototype.constructor=Cylinder;
 a;g++)k.faces.push(new THREE.Face4((2*g-2*a+2)%a+a,(2*g-2*a+1)%a+a,(2*g-2*a)%a+a,2*a+1))}this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};Cylinder.prototype=new THREE.Geometry;Cylinder.prototype.constructor=Cylinder;
-var Plane=function(a,b,d,e){THREE.Geometry.call(this);var f,j=a/2,k=b/2;d=d||1;e=e||1;var g=d+1,o=e+1;a=a/d;var c=b/e;for(f=0;f<o;f++)for(b=0;b<g;b++)this.vertices.push(new THREE.Vertex(new THREE.Vector3(b*a-j,-(f*c-k),0)));for(f=0;f<e;f++)for(b=0;b<d;b++){this.faces.push(new THREE.Face4(b+g*f,b+g*(f+1),b+1+g*(f+1),b+1+g*f));this.uvs.push([new THREE.UV(b/d,f/e),new THREE.UV(b/d,(f+1)/e),new THREE.UV((b+1)/d,(f+1)/e),new THREE.UV((b+1)/d,f/e)])}this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};
+var Plane=function(a,b,d,e){THREE.Geometry.call(this);var f,j=a/2,k=b/2;d=d||1;e=e||1;var g=d+1,p=e+1;a=a/d;var c=b/e;for(f=0;f<p;f++)for(b=0;b<g;b++)this.vertices.push(new THREE.Vertex(new THREE.Vector3(b*a-j,-(f*c-k),0)));for(f=0;f<e;f++)for(b=0;b<d;b++){this.faces.push(new THREE.Face4(b+g*f,b+g*(f+1),b+1+g*(f+1),b+1+g*f));this.uvs.push([new THREE.UV(b/d,f/e),new THREE.UV(b/d,(f+1)/e),new THREE.UV((b+1)/d,(f+1)/e),new THREE.UV((b+1)/d,f/e)])}this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};
 Plane.prototype=new THREE.Geometry;Plane.prototype.constructor=Plane;
 Plane.prototype=new THREE.Geometry;Plane.prototype.constructor=Plane;
-var Sphere=function(a,b,d){THREE.Geometry.call(this);var e,f=Math.max(3,b||8),j=Math.max(2,d||6);b=[];for(d=0;d<j+1;d++){e=d/j;var k=a*Math.cos(e*Math.PI),g=a*Math.sin(e*Math.PI),o=[],c=0;for(e=0;e<f;e++){var s=2*e/f,F=g*Math.sin(s*Math.PI);s=g*Math.cos(s*Math.PI);(d==0||d==j)&&e>0||(c=this.vertices.push(new THREE.Vertex(new THREE.Vector3(s,k,F)))-1);o.push(c)}b.push(o)}var r,w,v;a=b.length;for(d=0;d<a;d++){f=b[d].length;if(d>0)for(e=0;e<f;e++){o=e==f-1;j=b[d][o?0:e+1];k=b[d][o?f-1:e];g=b[d-1][o?
-f-1:e];o=b[d-1][o?0:e+1];F=d/(a-1);r=(d-1)/(a-1);w=(e+1)/f;s=e/f;c=new THREE.UV(1-w,F);F=new THREE.UV(1-s,F);s=new THREE.UV(1-s,r);var y=new THREE.UV(1-w,r);if(d<b.length-1){r=this.vertices[j].position.clone();w=this.vertices[k].position.clone();v=this.vertices[g].position.clone();r.normalize();w.normalize();v.normalize();this.faces.push(new THREE.Face3(j,k,g,[new THREE.Vector3(r.x,r.y,r.z),new THREE.Vector3(w.x,w.y,w.z),new THREE.Vector3(v.x,v.y,v.z)]));this.uvs.push([c,F,s])}if(d>1){r=this.vertices[j].position.clone();
-w=this.vertices[g].position.clone();v=this.vertices[o].position.clone();r.normalize();w.normalize();v.normalize();this.faces.push(new THREE.Face3(j,g,o,[new THREE.Vector3(r.x,r.y,r.z),new THREE.Vector3(w.x,w.y,w.z),new THREE.Vector3(v.x,v.y,v.z)]));this.uvs.push([c,s,y])}}}this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};Sphere.prototype=new THREE.Geometry;Sphere.prototype.constructor=Sphere;
+var Sphere=function(a,b,d){THREE.Geometry.call(this);var e,f=Math.max(3,b||8),j=Math.max(2,d||6);b=[];for(d=0;d<j+1;d++){e=d/j;var k=a*Math.cos(e*Math.PI),g=a*Math.sin(e*Math.PI),p=[],c=0;for(e=0;e<f;e++){var t=2*e/f,F=g*Math.sin(t*Math.PI);t=g*Math.cos(t*Math.PI);(d==0||d==j)&&e>0||(c=this.vertices.push(new THREE.Vertex(new THREE.Vector3(t,k,F)))-1);p.push(c)}b.push(p)}var r,w,v;a=b.length;for(d=0;d<a;d++){f=b[d].length;if(d>0)for(e=0;e<f;e++){p=e==f-1;j=b[d][p?0:e+1];k=b[d][p?f-1:e];g=b[d-1][p?
+f-1:e];p=b[d-1][p?0:e+1];F=d/(a-1);r=(d-1)/(a-1);w=(e+1)/f;t=e/f;c=new THREE.UV(1-w,F);F=new THREE.UV(1-t,F);t=new THREE.UV(1-t,r);var y=new THREE.UV(1-w,r);if(d<b.length-1){r=this.vertices[j].position.clone();w=this.vertices[k].position.clone();v=this.vertices[g].position.clone();r.normalize();w.normalize();v.normalize();this.faces.push(new THREE.Face3(j,k,g,[new THREE.Vector3(r.x,r.y,r.z),new THREE.Vector3(w.x,w.y,w.z),new THREE.Vector3(v.x,v.y,v.z)]));this.uvs.push([c,F,t])}if(d>1){r=this.vertices[j].position.clone();
+w=this.vertices[g].position.clone();v=this.vertices[p].position.clone();r.normalize();w.normalize();v.normalize();this.faces.push(new THREE.Face3(j,g,p,[new THREE.Vector3(r.x,r.y,r.z),new THREE.Vector3(w.x,w.y,w.z),new THREE.Vector3(v.x,v.y,v.z)]));this.uvs.push([c,t,y])}}}this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};Sphere.prototype=new THREE.Geometry;Sphere.prototype.constructor=Sphere;
 THREE.Loader=function(a){this.statusDomElement=(this.showStatus=a)?this.addStatusElement():null};
 THREE.Loader=function(a){this.statusDomElement=(this.showStatus=a)?this.addStatusElement():null};
 THREE.Loader.prototype={addStatusElement:function(){var a=document.createElement("div");a.style.fontSize="0.8em";a.style.textAlign="left";a.style.background="#b00";a.style.color="#fff";a.style.width="140px";a.style.padding="0.25em 0.25em 0.25em 0.5em";a.style.position="absolute";a.style.right="0px";a.style.top="0px";a.style.zIndex=1E3;a.innerHTML="Loading ...";return a},updateProgress:function(a){var b="Loaded ";b+=a.total?(100*a.loaded/a.total).toFixed(0)+"%":(a.loaded/1E3).toFixed(2)+" KB";this.statusDomElement.innerHTML=
 THREE.Loader.prototype={addStatusElement:function(){var a=document.createElement("div");a.style.fontSize="0.8em";a.style.textAlign="left";a.style.background="#b00";a.style.color="#fff";a.style.width="140px";a.style.padding="0.25em 0.25em 0.25em 0.5em";a.style.position="absolute";a.style.right="0px";a.style.top="0px";a.style.zIndex=1E3;a.innerHTML="Loading ...";return a},updateProgress:function(a){var b="Loaded ";b+=a.total?(100*a.loaded/a.total).toFixed(0)+"%":(a.loaded/1E3).toFixed(2)+" KB";this.statusDomElement.innerHTML=
 b},loadAsciiOld:function(a,b){var d=document.createElement("script");d.type="text/javascript";d.onload=b;d.src=a;document.getElementsByTagName("head")[0].appendChild(d)},loadAscii:function(a,b,d){var e=(new Date).getTime();a=new Worker(a);a.onmessage=function(f){THREE.Loader.prototype.createModel(f.data,b,d)};a.postMessage(e)},loadBinary:function(a,b,d){var e=(new Date).getTime();a=new Worker(a);var f=this.showProgress?THREE.Loader.prototype.updateProgress:null;a.onmessage=function(j){THREE.Loader.prototype.loadAjaxBuffers(j.data.buffers,
 b},loadAsciiOld:function(a,b){var d=document.createElement("script");d.type="text/javascript";d.onload=b;d.src=a;document.getElementsByTagName("head")[0].appendChild(d)},loadAscii:function(a,b,d){var e=(new Date).getTime();a=new Worker(a);a.onmessage=function(f){THREE.Loader.prototype.createModel(f.data,b,d)};a.postMessage(e)},loadBinary:function(a,b,d){var e=(new Date).getTime();a=new Worker(a);var f=this.showProgress?THREE.Loader.prototype.updateProgress:null;a.onmessage=function(j){THREE.Loader.prototype.loadAjaxBuffers(j.data.buffers,
 j.data.materials,b,d,f)};a.onerror=function(j){alert("worker.onerror: "+j.message+"\n"+j.data);j.preventDefault()};a.postMessage(e)},loadAjaxBuffers:function(a,b,d,e,f){var j=new XMLHttpRequest,k=e+"/"+a,g=0;j.onreadystatechange=function(){if(j.readyState==4)j.status==200||j.status==0?THREE.Loader.prototype.createBinModel(j.responseText,d,e,b):alert("Couldn't load ["+k+"] ["+j.status+"]");else if(j.readyState==3){if(f){if(g==0)g=j.getResponseHeader("Content-Length");f({total:g,loaded:j.responseText.length})}}else if(j.readyState==
 j.data.materials,b,d,f)};a.onerror=function(j){alert("worker.onerror: "+j.message+"\n"+j.data);j.preventDefault()};a.postMessage(e)},loadAjaxBuffers:function(a,b,d,e,f){var j=new XMLHttpRequest,k=e+"/"+a,g=0;j.onreadystatechange=function(){if(j.readyState==4)j.status==200||j.status==0?THREE.Loader.prototype.createBinModel(j.responseText,d,e,b):alert("Couldn't load ["+k+"] ["+j.status+"]");else if(j.readyState==3){if(f){if(g==0)g=j.getResponseHeader("Content-Length");f({total:g,loaded:j.responseText.length})}}else if(j.readyState==
-2)g=j.getResponseHeader("Content-Length")};j.open("GET",k,true);j.overrideMimeType("text/plain; charset=x-user-defined");j.setRequestHeader("Content-Type","text/plain");j.send(null)},createBinModel:function(a,b,d,e){var f=function(j){function k(q,t){var z=s(q,t),K=s(q,t+1),W=s(q,t+2),ga=s(q,t+3),ma=(ga<<1&255|W>>7)-127;z=(W&127)<<16|K<<8|z;if(z==0&&ma==-127)return 0;return(1-2*(ga>>7))*(1+z*Math.pow(2,-23))*Math.pow(2,ma)}function g(q,t){var z=s(q,t),K=s(q,t+1),W=s(q,t+2);return(s(q,t+3)<<24)+(W<<
-16)+(K<<8)+z}function o(q,t){var z=s(q,t);return(s(q,t+1)<<8)+z}function c(q,t){var z=s(q,t);return z>127?z-256:z}function s(q,t){return q.charCodeAt(t)&255}function F(q){var t,z,K;t=g(a,q);z=g(a,q+p);K=g(a,q+x);q=o(a,q+m);THREE.Loader.prototype.f3(u,t,z,K,q)}function r(q){var t,z,K,W,ga,ma;t=g(a,q);z=g(a,q+p);K=g(a,q+x);W=o(a,q+m);ga=g(a,q+l);ma=g(a,q+E);q=g(a,q+B);THREE.Loader.prototype.f3n(u,h,t,z,K,W,ga,ma,q)}function w(q){var t,z,K,W;t=g(a,q);z=g(a,q+Q);K=g(a,q+G);W=g(a,q+V);q=o(a,q+U);THREE.Loader.prototype.f4(u,
-t,z,K,W,q)}function v(q){var t,z,K,W,ga,ma,ua,pa;t=g(a,q);z=g(a,q+Q);K=g(a,q+G);W=g(a,q+V);ga=o(a,q+U);ma=g(a,q+D);ua=g(a,q+P);pa=g(a,q+C);q=g(a,q+J);THREE.Loader.prototype.f4n(u,h,t,z,K,W,ga,ma,ua,pa,q)}function y(q){var t,z;t=g(a,q);z=g(a,q+I);q=g(a,q+T);THREE.Loader.prototype.uv3(u,i[t*2],i[t*2+1],i[z*2],i[z*2+1],i[q*2],i[q*2+1])}function L(q){var t,z,K;t=g(a,q);z=g(a,q+N);K=g(a,q+M);q=g(a,q+Y);THREE.Loader.prototype.uv4(u,i[t*2],i[t*2+1],i[z*2],i[z*2+1],i[K*2],i[K*2+1],i[q*2],i[q*2+1])}var u=
-this,A=0,n,h=[],i=[],p,x,m,l,E,B,Q,G,V,U,D,P,C,J,I,T,N,M,Y;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(u,e,j);n={signature:a.substr(A,8),header_bytes:s(a,A+8),vertex_coordinate_bytes:s(a,A+9),normal_coordinate_bytes:s(a,A+10),uv_coordinate_bytes:s(a,A+11),vertex_index_bytes:s(a,A+12),normal_index_bytes:s(a,A+13),uv_index_bytes:s(a,A+14),material_index_bytes:s(a,A+15),nvertices:g(a,A+16),nnormals:g(a,A+16+4),nuvs:g(a,A+16+8),ntri_flat:g(a,A+16+12),ntri_smooth:g(a,A+16+16),ntri_flat_uv:g(a,
-A+16+20),ntri_smooth_uv:g(a,A+16+24),nquad_flat:g(a,A+16+28),nquad_smooth:g(a,A+16+32),nquad_flat_uv:g(a,A+16+36),nquad_smooth_uv:g(a,A+16+40)};A+=n.header_bytes;p=n.vertex_index_bytes;x=n.vertex_index_bytes*2;m=n.vertex_index_bytes*3;l=n.vertex_index_bytes*3+n.material_index_bytes;E=n.vertex_index_bytes*3+n.material_index_bytes+n.normal_index_bytes;B=n.vertex_index_bytes*3+n.material_index_bytes+n.normal_index_bytes*2;Q=n.vertex_index_bytes;G=n.vertex_index_bytes*2;V=n.vertex_index_bytes*3;U=n.vertex_index_bytes*
-4;D=n.vertex_index_bytes*4+n.material_index_bytes;P=n.vertex_index_bytes*4+n.material_index_bytes+n.normal_index_bytes;C=n.vertex_index_bytes*4+n.material_index_bytes+n.normal_index_bytes*2;J=n.vertex_index_bytes*4+n.material_index_bytes+n.normal_index_bytes*3;I=n.uv_index_bytes;T=n.uv_index_bytes*2;N=n.uv_index_bytes;M=n.uv_index_bytes*2;Y=n.uv_index_bytes*3;A+=function(q){var t,z,K,W=n.vertex_coordinate_bytes*3,ga=q+n.nvertices*W;for(q=q;q<ga;q+=W){t=k(a,q);z=k(a,q+n.vertex_coordinate_bytes);K=
-k(a,q+n.vertex_coordinate_bytes*2);THREE.Loader.prototype.v(u,t,z,K)}return n.nvertices*W}(A);A+=function(q){var t,z,K,W=n.normal_coordinate_bytes*3,ga=q+n.nnormals*W;for(q=q;q<ga;q+=W){t=c(a,q);z=c(a,q+n.normal_coordinate_bytes);K=c(a,q+n.normal_coordinate_bytes*2);h.push(t/127,z/127,K/127)}return n.nnormals*W}(A);A+=function(q){var t,z,K=n.uv_coordinate_bytes*2,W=q+n.nuvs*K;for(q=q;q<W;q+=K){t=k(a,q);z=k(a,q+n.uv_coordinate_bytes);i.push(t,z)}return n.nuvs*K}(A);A+=function(q){var t,z=n.vertex_index_bytes*
-3+n.material_index_bytes,K=q+n.ntri_flat*z;for(t=q;t<K;t+=z)F(t);return K-q}(A);A+=function(q){var t,z=n.vertex_index_bytes*3+n.material_index_bytes+n.normal_index_bytes*3,K=q+n.ntri_smooth*z;for(t=q;t<K;t+=z)r(t);return K-q}(A);A+=function(q){var t,z=n.vertex_index_bytes*3+n.material_index_bytes,K=z+n.uv_index_bytes*3,W=q+n.ntri_flat_uv*K;for(t=q;t<W;t+=K){F(t);y(t+z)}return W-q}(A);A+=function(q){var t,z=n.vertex_index_bytes*3+n.material_index_bytes+n.normal_index_bytes*3,K=z+n.uv_index_bytes*3,
-W=q+n.ntri_smooth_uv*K;for(t=q;t<W;t+=K){r(t);y(t+z)}return W-q}(A);A+=function(q){var t,z=n.vertex_index_bytes*4+n.material_index_bytes,K=q+n.nquad_flat*z;for(t=q;t<K;t+=z)w(t);return K-q}(A);A+=function(q){var t,z=n.vertex_index_bytes*4+n.material_index_bytes+n.normal_index_bytes*4,K=q+n.nquad_smooth*z;for(t=q;t<K;t+=z)v(t);return K-q}(A);A+=function(q){var t,z=n.vertex_index_bytes*4+n.material_index_bytes,K=z+n.uv_index_bytes*4,W=q+n.nquad_flat_uv*K;for(t=q;t<W;t+=K){w(t);L(t+z)}return W-q}(A);
-A+=function(q){var t,z=n.vertex_index_bytes*4+n.material_index_bytes+n.normal_index_bytes*4,K=z+n.uv_index_bytes*4,W=q+n.nquad_smooth_uv*K;for(t=q;t<W;t+=K){v(t);L(t+z)}return W-q}(A);this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};f.prototype=new THREE.Geometry;f.prototype.constructor=f;b(new f(d))},createModel:function(a,b,d){var e=function(f){var j=this;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(j,a.materials,f);(function(){var k,g,o,c,s;k=0;for(g=
-a.vertices.length;k<g;k+=3){o=a.vertices[k];c=a.vertices[k+1];s=a.vertices[k+2];THREE.Loader.prototype.v(j,o,c,s)}})();(function(){function k(v,y){THREE.Loader.prototype.f3(j,v[y],v[y+1],v[y+2],v[y+3])}function g(v,y){THREE.Loader.prototype.f3n(j,a.normals,v[y],v[y+1],v[y+2],v[y+3],v[y+4],v[y+5],v[y+6])}function o(v,y){THREE.Loader.prototype.f4(j,v[y],v[y+1],v[y+2],v[y+3],v[y+4])}function c(v,y){THREE.Loader.prototype.f4n(j,a.normals,v[y],v[y+1],v[y+2],v[y+3],v[y+4],v[y+5],v[y+6],v[y+7],v[y+8])}function s(v,
-y){var L,u,A;L=v[y];u=v[y+1];A=v[y+2];THREE.Loader.prototype.uv3(j,a.uvs[L*2],a.uvs[L*2+1],a.uvs[u*2],a.uvs[u*2+1],a.uvs[A*2],a.uvs[A*2+1])}function F(v,y){var L,u,A,n;L=v[y];u=v[y+1];A=v[y+2];n=v[y+3];THREE.Loader.prototype.uv4(j,a.uvs[L*2],a.uvs[L*2+1],a.uvs[u*2],a.uvs[u*2+1],a.uvs[A*2],a.uvs[A*2+1],a.uvs[n*2],a.uvs[n*2+1])}var r,w;r=0;for(w=a.triangles.length;r<w;r+=4)k(a.triangles,r);r=0;for(w=a.triangles_uv.length;r<w;r+=7){k(a.triangles_uv,r);s(a.triangles_uv,r+4)}r=0;for(w=a.triangles_n.length;r<
-w;r+=7)g(a.triangles_n,r);r=0;for(w=a.triangles_n_uv.length;r<w;r+=10){g(a.triangles_n_uv,r);s(a.triangles_n_uv,r+7)}r=0;for(w=a.quads.length;r<w;r+=5)o(a.quads,r);r=0;for(w=a.quads_uv.length;r<w;r+=9){o(a.quads_uv,r);F(a.quads_uv,r+5)}r=0;for(w=a.quads_n.length;r<w;r+=9)c(a.quads_n,r);r=0;for(w=a.quads_n_uv.length;r<w;r+=13){c(a.quads_n_uv,r);F(a.quads_n_uv,r+9)}})();this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};e.prototype=new THREE.Geometry;e.prototype.constructor=e;
-b(new e(d))},v:function(a,b,d,e){a.vertices.push(new THREE.Vertex(new THREE.Vector3(b,d,e)))},f3:function(a,b,d,e,f){a.faces.push(new THREE.Face3(b,d,e,null,a.materials[f]))},f4:function(a,b,d,e,f,j){a.faces.push(new THREE.Face4(b,d,e,f,null,a.materials[j]))},f3n:function(a,b,d,e,f,j,k,g,o){j=a.materials[j];var c=b[g*3],s=b[g*3+1];g=b[g*3+2];var F=b[o*3],r=b[o*3+1];o=b[o*3+2];a.faces.push(new THREE.Face3(d,e,f,[new THREE.Vector3(b[k*3],b[k*3+1],b[k*3+2]),new THREE.Vector3(c,s,g),new THREE.Vector3(F,
-r,o)],j))},f4n:function(a,b,d,e,f,j,k,g,o,c,s){k=a.materials[k];var F=b[o*3],r=b[o*3+1];o=b[o*3+2];var w=b[c*3],v=b[c*3+1];c=b[c*3+2];var y=b[s*3],L=b[s*3+1];s=b[s*3+2];a.faces.push(new THREE.Face4(d,e,f,j,[new THREE.Vector3(b[g*3],b[g*3+1],b[g*3+2]),new THREE.Vector3(F,r,o),new THREE.Vector3(w,v,c),new THREE.Vector3(y,L,s)],k))},uv3:function(a,b,d,e,f,j,k){var g=[];g.push(new THREE.UV(b,d));g.push(new THREE.UV(e,f));g.push(new THREE.UV(j,k));a.uvs.push(g)},uv4:function(a,b,d,e,f,j,k,g,o){var c=[];
-c.push(new THREE.UV(b,d));c.push(new THREE.UV(e,f));c.push(new THREE.UV(j,k));c.push(new THREE.UV(g,o));a.uvs.push(c)},init_materials:function(a,b,d){a.materials=[];for(var e=0;e<b.length;++e)a.materials[e]=[THREE.Loader.prototype.createMaterial(b[e],d)]},createMaterial:function(a,b){function d(j){j=Math.log(j)/Math.LN2;return Math.floor(j)==j}var e,f;if(a.map_diffuse&&b){f=document.createElement("canvas");e=new THREE.MeshLambertMaterial({map:new THREE.Texture(f)});f=new Image;f.onload=function(){if(!d(this.width)||
+2)g=j.getResponseHeader("Content-Length")};j.open("GET",k,true);j.overrideMimeType("text/plain; charset=x-user-defined");j.setRequestHeader("Content-Type","text/plain");j.send(null)},createBinModel:function(a,b,d,e){var f=function(j){function k(q,s){var z=t(q,s),K=t(q,s+1),W=t(q,s+2),ga=t(q,s+3),ma=(ga<<1&255|W>>7)-127;z=(W&127)<<16|K<<8|z;if(z==0&&ma==-127)return 0;return(1-2*(ga>>7))*(1+z*Math.pow(2,-23))*Math.pow(2,ma)}function g(q,s){var z=t(q,s),K=t(q,s+1),W=t(q,s+2);return(t(q,s+3)<<24)+(W<<
+16)+(K<<8)+z}function p(q,s){var z=t(q,s);return(t(q,s+1)<<8)+z}function c(q,s){var z=t(q,s);return z>127?z-256:z}function t(q,s){return q.charCodeAt(s)&255}function F(q){var s,z,K;s=g(a,q);z=g(a,q+h);K=g(a,q+x);q=p(a,q+m);THREE.Loader.prototype.f3(u,s,z,K,q)}function r(q){var s,z,K,W,ga,ma;s=g(a,q);z=g(a,q+h);K=g(a,q+x);W=p(a,q+m);ga=g(a,q+l);ma=g(a,q+B);q=g(a,q+C);THREE.Loader.prototype.f3n(u,i,s,z,K,W,ga,ma,q)}function w(q){var s,z,K,W;s=g(a,q);z=g(a,q+Q);K=g(a,q+J);W=g(a,q+P);q=p(a,q+S);THREE.Loader.prototype.f4(u,
+s,z,K,W,q)}function v(q){var s,z,K,W,ga,ma,ua,pa;s=g(a,q);z=g(a,q+Q);K=g(a,q+J);W=g(a,q+P);ga=p(a,q+S);ma=g(a,q+E);ua=g(a,q+T);pa=g(a,q+D);q=g(a,q+I);THREE.Loader.prototype.f4n(u,i,s,z,K,W,ga,ma,ua,pa,q)}function y(q){var s,z;s=g(a,q);z=g(a,q+H);q=g(a,q+V);THREE.Loader.prototype.uv3(u,n[s*2],n[s*2+1],n[z*2],n[z*2+1],n[q*2],n[q*2+1])}function L(q){var s,z,K;s=g(a,q);z=g(a,q+N);K=g(a,q+M);q=g(a,q+Y);THREE.Loader.prototype.uv4(u,n[s*2],n[s*2+1],n[z*2],n[z*2+1],n[K*2],n[K*2+1],n[q*2],n[q*2+1])}var u=
+this,A=0,o,i=[],n=[],h,x,m,l,B,C,Q,J,P,S,E,T,D,I,H,V,N,M,Y;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(u,e,j);o={signature:a.substr(A,8),header_bytes:t(a,A+8),vertex_coordinate_bytes:t(a,A+9),normal_coordinate_bytes:t(a,A+10),uv_coordinate_bytes:t(a,A+11),vertex_index_bytes:t(a,A+12),normal_index_bytes:t(a,A+13),uv_index_bytes:t(a,A+14),material_index_bytes:t(a,A+15),nvertices:g(a,A+16),nnormals:g(a,A+16+4),nuvs:g(a,A+16+8),ntri_flat:g(a,A+16+12),ntri_smooth:g(a,A+16+16),ntri_flat_uv:g(a,
+A+16+20),ntri_smooth_uv:g(a,A+16+24),nquad_flat:g(a,A+16+28),nquad_smooth:g(a,A+16+32),nquad_flat_uv:g(a,A+16+36),nquad_smooth_uv:g(a,A+16+40)};A+=o.header_bytes;h=o.vertex_index_bytes;x=o.vertex_index_bytes*2;m=o.vertex_index_bytes*3;l=o.vertex_index_bytes*3+o.material_index_bytes;B=o.vertex_index_bytes*3+o.material_index_bytes+o.normal_index_bytes;C=o.vertex_index_bytes*3+o.material_index_bytes+o.normal_index_bytes*2;Q=o.vertex_index_bytes;J=o.vertex_index_bytes*2;P=o.vertex_index_bytes*3;S=o.vertex_index_bytes*
+4;E=o.vertex_index_bytes*4+o.material_index_bytes;T=o.vertex_index_bytes*4+o.material_index_bytes+o.normal_index_bytes;D=o.vertex_index_bytes*4+o.material_index_bytes+o.normal_index_bytes*2;I=o.vertex_index_bytes*4+o.material_index_bytes+o.normal_index_bytes*3;H=o.uv_index_bytes;V=o.uv_index_bytes*2;N=o.uv_index_bytes;M=o.uv_index_bytes*2;Y=o.uv_index_bytes*3;A+=function(q){var s,z,K,W=o.vertex_coordinate_bytes*3,ga=q+o.nvertices*W;for(q=q;q<ga;q+=W){s=k(a,q);z=k(a,q+o.vertex_coordinate_bytes);K=
+k(a,q+o.vertex_coordinate_bytes*2);THREE.Loader.prototype.v(u,s,z,K)}return o.nvertices*W}(A);A+=function(q){var s,z,K,W=o.normal_coordinate_bytes*3,ga=q+o.nnormals*W;for(q=q;q<ga;q+=W){s=c(a,q);z=c(a,q+o.normal_coordinate_bytes);K=c(a,q+o.normal_coordinate_bytes*2);i.push(s/127,z/127,K/127)}return o.nnormals*W}(A);A+=function(q){var s,z,K=o.uv_coordinate_bytes*2,W=q+o.nuvs*K;for(q=q;q<W;q+=K){s=k(a,q);z=k(a,q+o.uv_coordinate_bytes);n.push(s,z)}return o.nuvs*K}(A);A+=function(q){var s,z=o.vertex_index_bytes*
+3+o.material_index_bytes,K=q+o.ntri_flat*z;for(s=q;s<K;s+=z)F(s);return K-q}(A);A+=function(q){var s,z=o.vertex_index_bytes*3+o.material_index_bytes+o.normal_index_bytes*3,K=q+o.ntri_smooth*z;for(s=q;s<K;s+=z)r(s);return K-q}(A);A+=function(q){var s,z=o.vertex_index_bytes*3+o.material_index_bytes,K=z+o.uv_index_bytes*3,W=q+o.ntri_flat_uv*K;for(s=q;s<W;s+=K){F(s);y(s+z)}return W-q}(A);A+=function(q){var s,z=o.vertex_index_bytes*3+o.material_index_bytes+o.normal_index_bytes*3,K=z+o.uv_index_bytes*3,
+W=q+o.ntri_smooth_uv*K;for(s=q;s<W;s+=K){r(s);y(s+z)}return W-q}(A);A+=function(q){var s,z=o.vertex_index_bytes*4+o.material_index_bytes,K=q+o.nquad_flat*z;for(s=q;s<K;s+=z)w(s);return K-q}(A);A+=function(q){var s,z=o.vertex_index_bytes*4+o.material_index_bytes+o.normal_index_bytes*4,K=q+o.nquad_smooth*z;for(s=q;s<K;s+=z)v(s);return K-q}(A);A+=function(q){var s,z=o.vertex_index_bytes*4+o.material_index_bytes,K=z+o.uv_index_bytes*4,W=q+o.nquad_flat_uv*K;for(s=q;s<W;s+=K){w(s);L(s+z)}return W-q}(A);
+A+=function(q){var s,z=o.vertex_index_bytes*4+o.material_index_bytes+o.normal_index_bytes*4,K=z+o.uv_index_bytes*4,W=q+o.nquad_smooth_uv*K;for(s=q;s<W;s+=K){v(s);L(s+z)}return W-q}(A);this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};f.prototype=new THREE.Geometry;f.prototype.constructor=f;b(new f(d))},createModel:function(a,b,d){var e=function(f){var j=this;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(j,a.materials,f);(function(){var k,g,p,c,t;k=0;for(g=
+a.vertices.length;k<g;k+=3){p=a.vertices[k];c=a.vertices[k+1];t=a.vertices[k+2];THREE.Loader.prototype.v(j,p,c,t)}})();(function(){function k(v,y){THREE.Loader.prototype.f3(j,v[y],v[y+1],v[y+2],v[y+3])}function g(v,y){THREE.Loader.prototype.f3n(j,a.normals,v[y],v[y+1],v[y+2],v[y+3],v[y+4],v[y+5],v[y+6])}function p(v,y){THREE.Loader.prototype.f4(j,v[y],v[y+1],v[y+2],v[y+3],v[y+4])}function c(v,y){THREE.Loader.prototype.f4n(j,a.normals,v[y],v[y+1],v[y+2],v[y+3],v[y+4],v[y+5],v[y+6],v[y+7],v[y+8])}function t(v,
+y){var L,u,A;L=v[y];u=v[y+1];A=v[y+2];THREE.Loader.prototype.uv3(j,a.uvs[L*2],a.uvs[L*2+1],a.uvs[u*2],a.uvs[u*2+1],a.uvs[A*2],a.uvs[A*2+1])}function F(v,y){var L,u,A,o;L=v[y];u=v[y+1];A=v[y+2];o=v[y+3];THREE.Loader.prototype.uv4(j,a.uvs[L*2],a.uvs[L*2+1],a.uvs[u*2],a.uvs[u*2+1],a.uvs[A*2],a.uvs[A*2+1],a.uvs[o*2],a.uvs[o*2+1])}var r,w;r=0;for(w=a.triangles.length;r<w;r+=4)k(a.triangles,r);r=0;for(w=a.triangles_uv.length;r<w;r+=7){k(a.triangles_uv,r);t(a.triangles_uv,r+4)}r=0;for(w=a.triangles_n.length;r<
+w;r+=7)g(a.triangles_n,r);r=0;for(w=a.triangles_n_uv.length;r<w;r+=10){g(a.triangles_n_uv,r);t(a.triangles_n_uv,r+7)}r=0;for(w=a.quads.length;r<w;r+=5)p(a.quads,r);r=0;for(w=a.quads_uv.length;r<w;r+=9){p(a.quads_uv,r);F(a.quads_uv,r+5)}r=0;for(w=a.quads_n.length;r<w;r+=9)c(a.quads_n,r);r=0;for(w=a.quads_n_uv.length;r<w;r+=13){c(a.quads_n_uv,r);F(a.quads_n_uv,r+9)}})();this.computeCentroids();this.computeNormals();this.sortFacesByMaterial()};e.prototype=new THREE.Geometry;e.prototype.constructor=e;
+b(new e(d))},v:function(a,b,d,e){a.vertices.push(new THREE.Vertex(new THREE.Vector3(b,d,e)))},f3:function(a,b,d,e,f){a.faces.push(new THREE.Face3(b,d,e,null,a.materials[f]))},f4:function(a,b,d,e,f,j){a.faces.push(new THREE.Face4(b,d,e,f,null,a.materials[j]))},f3n:function(a,b,d,e,f,j,k,g,p){j=a.materials[j];var c=b[g*3],t=b[g*3+1];g=b[g*3+2];var F=b[p*3],r=b[p*3+1];p=b[p*3+2];a.faces.push(new THREE.Face3(d,e,f,[new THREE.Vector3(b[k*3],b[k*3+1],b[k*3+2]),new THREE.Vector3(c,t,g),new THREE.Vector3(F,
+r,p)],j))},f4n:function(a,b,d,e,f,j,k,g,p,c,t){k=a.materials[k];var F=b[p*3],r=b[p*3+1];p=b[p*3+2];var w=b[c*3],v=b[c*3+1];c=b[c*3+2];var y=b[t*3],L=b[t*3+1];t=b[t*3+2];a.faces.push(new THREE.Face4(d,e,f,j,[new THREE.Vector3(b[g*3],b[g*3+1],b[g*3+2]),new THREE.Vector3(F,r,p),new THREE.Vector3(w,v,c),new THREE.Vector3(y,L,t)],k))},uv3:function(a,b,d,e,f,j,k){var g=[];g.push(new THREE.UV(b,d));g.push(new THREE.UV(e,f));g.push(new THREE.UV(j,k));a.uvs.push(g)},uv4:function(a,b,d,e,f,j,k,g,p){var c=[];
+c.push(new THREE.UV(b,d));c.push(new THREE.UV(e,f));c.push(new THREE.UV(j,k));c.push(new THREE.UV(g,p));a.uvs.push(c)},init_materials:function(a,b,d){a.materials=[];for(var e=0;e<b.length;++e)a.materials[e]=[THREE.Loader.prototype.createMaterial(b[e],d)]},createMaterial:function(a,b){function d(j){j=Math.log(j)/Math.LN2;return Math.floor(j)==j}var e,f;if(a.map_diffuse&&b){f=document.createElement("canvas");e=new THREE.MeshLambertMaterial({map:new THREE.Texture(f)});f=new Image;f.onload=function(){if(!d(this.width)||
 !d(this.height)){var j=Math.pow(2,Math.round(Math.log(this.width)/Math.LN2)),k=Math.pow(2,Math.round(Math.log(this.height)/Math.LN2));e.map.image.width=j;e.map.image.height=k;e.map.image.getContext("2d").drawImage(this,0,0,j,k)}else e.map.image=this;e.map.image.loaded=1};f.src=b+"/"+a.map_diffuse}else if(a.col_diffuse){f=(a.col_diffuse[0]*255<<16)+(a.col_diffuse[1]*255<<8)+a.col_diffuse[2]*255;e=new THREE.MeshLambertMaterial({color:f,opacity:a.transparency})}else e=a.a_dbg_color?new THREE.MeshLambertMaterial({color:a.a_dbg_color}):
 !d(this.height)){var j=Math.pow(2,Math.round(Math.log(this.width)/Math.LN2)),k=Math.pow(2,Math.round(Math.log(this.height)/Math.LN2));e.map.image.width=j;e.map.image.height=k;e.map.image.getContext("2d").drawImage(this,0,0,j,k)}else e.map.image=this;e.map.image.loaded=1};f.src=b+"/"+a.map_diffuse}else if(a.col_diffuse){f=(a.col_diffuse[0]*255<<16)+(a.col_diffuse[1]*255<<8)+a.col_diffuse[2]*255;e=new THREE.MeshLambertMaterial({color:f,opacity:a.transparency})}else e=a.a_dbg_color?new THREE.MeshLambertMaterial({color:a.a_dbg_color}):
 new THREE.MeshLambertMaterial({color:15658734});return e}};
 new THREE.MeshLambertMaterial({color:15658734});return e}};

+ 2 - 3
examples/materials_shaders_fresnel.html

@@ -36,14 +36,14 @@
 		<div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - webgl cube Fresnel shader demo. texture by <a href="http://www.humus.name/index.php?page=Textures" target="_blank">Humus</a> </div>
 		<div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - webgl cube Fresnel shader demo. texture by <a href="http://www.humus.name/index.php?page=Textures" target="_blank">Humus</a> </div>
 
 
 		<script type="text/javascript" src="../build/ThreeExtras.js"></script> 
 		<script type="text/javascript" src="../build/ThreeExtras.js"></script> 
+		<script type="text/javascript" src="js/Stats.js"></script>
 
 
 		<!--
 		<!--
-		<script type="text/javascript" src="js/Stats.js"></script>
 		-->
 		-->
 		
 		
 		<script type="text/javascript">
 		<script type="text/javascript">
 
 
-			var statsEnabled = false;
+			var statsEnabled = true;
 
 
 			var container, stats;
 			var container, stats;
 
 
@@ -79,7 +79,6 @@
 				sceneCube = new THREE.Scene();
 				sceneCube = new THREE.Scene();
 
 
 				var geometry = new Sphere( 100, 32, 16 );
 				var geometry = new Sphere( 100, 32, 16 );
-				geometry.sortFacesByMaterial();
 
 
 				var path = "textures/cube/Park2/";
 				var path = "textures/cube/Park2/";
 				var format = '.jpg';
 				var format = '.jpg';

+ 100 - 68
src/renderers/WebGLRenderer.js

@@ -20,7 +20,7 @@ THREE.WebGLRenderer = function ( scene ) {
 	// See http://code.google.com/p/chromium/issues/detail?id=63491
 	// See http://code.google.com/p/chromium/issues/detail?id=63491
 
 
 	var _canvas = document.createElement( 'canvas' ), _gl, 
 	var _canvas = document.createElement( 'canvas' ), _gl, 
-	_program, _oldProgram,
+	_oldProgram, _uberProgram,
 	_modelViewMatrix = new THREE.Matrix4(), _normalMatrix,
 	_modelViewMatrix = new THREE.Matrix4(), _normalMatrix,
 	
 	
 	_viewMatrixArray = new Float32Array(16), 
 	_viewMatrixArray = new Float32Array(16), 
@@ -42,7 +42,9 @@ THREE.WebGLRenderer = function ( scene ) {
 	this.autoClear = true;
 	this.autoClear = true;
 
 
 	initGL();
 	initGL();
-	initUbershader( maxLightCount.directional, maxLightCount.point );
+	
+	_uberProgram = initUbershader( maxLightCount.directional, maxLightCount.point );
+	_oldProgram = _uberProgram;
 
 
 	//alert( dumpObject( getGLParams() ) );
 	//alert( dumpObject( getGLParams() ) );
 
 
@@ -60,17 +62,17 @@ THREE.WebGLRenderer = function ( scene ) {
 
 
 	};
 	};
 
 
-	this.setupLights = function ( program, scene ) {
+	this.setupLights = function ( program, lights ) {
 
 
 		var l, ll, light, r, g, b,
 		var l, ll, light, r, g, b,
 			ambientLights = [], pointLights = [], directionalLights = [],
 			ambientLights = [], pointLights = [], directionalLights = [],
 			colors = [], positions = [];
 			colors = [], positions = [];
 
 
-		_gl.uniform1i( program.uniforms.enableLighting, scene.lights.length );
+		_gl.uniform1i( program.uniforms.enableLighting, lights.length );
 
 
-		for ( l = 0, ll = scene.lights.length; l < ll; l++ ) {
+		for ( l = 0, ll = lights.length; l < ll; l++ ) {
 
 
-			light = scene.lights[ l ];
+			light = lights[ l ];
 
 
 			if ( light instanceof THREE.AmbientLight ) {
 			if ( light instanceof THREE.AmbientLight ) {
 
 
@@ -300,10 +302,14 @@ THREE.WebGLRenderer = function ( scene ) {
 		_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryChunk.__webGLNormalBuffer );
 		_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryChunk.__webGLNormalBuffer );
 		_gl.bufferData( _gl.ARRAY_BUFFER, new Float32Array( normalArray ), _gl.STATIC_DRAW );
 		_gl.bufferData( _gl.ARRAY_BUFFER, new Float32Array( normalArray ), _gl.STATIC_DRAW );
 
 
-		geometryChunk.__webGLUVBuffer = _gl.createBuffer();
-		_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryChunk.__webGLUVBuffer );
-		_gl.bufferData( _gl.ARRAY_BUFFER, new Float32Array( uvArray ), _gl.STATIC_DRAW );
-
+		if ( uvArray.length > 0 ) {
+			
+			geometryChunk.__webGLUVBuffer = _gl.createBuffer();
+			_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryChunk.__webGLUVBuffer );
+			_gl.bufferData( _gl.ARRAY_BUFFER, new Float32Array( uvArray ), _gl.STATIC_DRAW );
+			
+		}
+		
 		geometryChunk.__webGLFaceBuffer = _gl.createBuffer();
 		geometryChunk.__webGLFaceBuffer = _gl.createBuffer();
 		_gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, geometryChunk.__webGLFaceBuffer );
 		_gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, geometryChunk.__webGLFaceBuffer );
 		_gl.bufferData( _gl.ELEMENT_ARRAY_BUFFER, new Uint16Array( faceArray ), _gl.STATIC_DRAW );
 		_gl.bufferData( _gl.ELEMENT_ARRAY_BUFFER, new Uint16Array( faceArray ), _gl.STATIC_DRAW );
@@ -317,14 +323,14 @@ THREE.WebGLRenderer = function ( scene ) {
 
 
 	};
 	};
 
 
-	this.renderBuffer = function ( camera, material, geometryChunk ) {
+	this.renderBuffer = function ( camera, lights, material, geometryChunk ) {
 
 
 		var mColor, mOpacity, mReflectivity,
 		var mColor, mOpacity, mReflectivity,
 			mWireframe, mLineWidth, mBlending,
 			mWireframe, mLineWidth, mBlending,
 			mAmbient, mSpecular, mShininess,
 			mAmbient, mSpecular, mShininess,
 			mMap, envMap, mixEnvMap,
 			mMap, envMap, mixEnvMap,
 			mRefractionRatio, useRefract,
 			mRefractionRatio, useRefract,
-			program, u, identifiers;
+			program, u, identifiers, attributes;
 		
 		
 
 
 		if ( material instanceof THREE.MeshShaderMaterial ) {
 		if ( material instanceof THREE.MeshShaderMaterial ) {
@@ -334,9 +340,13 @@ THREE.WebGLRenderer = function ( scene ) {
 				material.program = buildProgram( material.fragment_shader, material.vertex_shader );
 				material.program = buildProgram( material.fragment_shader, material.vertex_shader );
 				
 				
 				identifiers = [ 'viewMatrix', 'modelViewMatrix', 'projectionMatrix', 'normalMatrix', 'objectMatrix', 'cameraPosition' ];
 				identifiers = [ 'viewMatrix', 'modelViewMatrix', 'projectionMatrix', 'normalMatrix', 'objectMatrix', 'cameraPosition' ];
-				for( u in material.uniforms ) identifiers.push(u);
+				for( u in material.uniforms ) {
+					
+					identifiers.push(u);
+					
+				}
 				cacheUniformLocations( material.program, identifiers );
 				cacheUniformLocations( material.program, identifiers );
-				cacheAttributeLocations( material.program );
+				cacheAttributeLocations( material.program, [ "position", "normal", "uv" ] );
 				
 				
 			}
 			}
 			
 			
@@ -344,7 +354,7 @@ THREE.WebGLRenderer = function ( scene ) {
 			
 			
 		} else {
 		} else {
 			
 			
-			program = _program;
+			program = _uberProgram;
 			
 			
 		}
 		}
 		
 		
@@ -354,17 +364,27 @@ THREE.WebGLRenderer = function ( scene ) {
 			_oldProgram = program;
 			_oldProgram = program;
 			
 			
 		}
 		}
+		
+		if ( program == _uberProgram ) {
+
+			this.setupLights( program, lights );
 			
 			
+		}
+		
+		this.loadCamera( program, camera );
+		this.loadMatrices( program );
+		
+		
 		if ( material instanceof THREE.MeshShaderMaterial ) {
 		if ( material instanceof THREE.MeshShaderMaterial ) {
 			
 			
 			mWireframe = material.wireframe;
 			mWireframe = material.wireframe;
 			mLineWidth = material.wireframe_linewidth;
 			mLineWidth = material.wireframe_linewidth;
 			
 			
 			setUniforms( program, material.uniforms );
 			setUniforms( program, material.uniforms );
-			this.loadCamera( program, camera );
-			this.loadMatrices( program );
 			
 			
-		} else if ( material instanceof THREE.MeshPhongMaterial ||
+		} 
+		
+		if ( material instanceof THREE.MeshPhongMaterial ||
 			 material instanceof THREE.MeshLambertMaterial ||
 			 material instanceof THREE.MeshLambertMaterial ||
 			 material instanceof THREE.MeshBasicMaterial ) {
 			 material instanceof THREE.MeshBasicMaterial ) {
 
 
@@ -473,28 +493,34 @@ THREE.WebGLRenderer = function ( scene ) {
 
 
 		}
 		}
 
 
+		attributes = program.attributes;
+		
 		// vertices
 		// vertices
 
 
 		_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryChunk.__webGLVertexBuffer );
 		_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryChunk.__webGLVertexBuffer );
-		_gl.vertexAttribPointer( program.position, 3, _gl.FLOAT, false, 0, 0 );
+		_gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
 
 
 		// normals
 		// normals
 
 
 		_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryChunk.__webGLNormalBuffer );
 		_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryChunk.__webGLNormalBuffer );
-		_gl.vertexAttribPointer( program.normal, 3, _gl.FLOAT, false, 0, 0 );
+		_gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
 
 
 		// uvs
 		// uvs
 
 
-		if ( mMap ) {
+		if ( attributes.uv >= 0 ) { 
+			
+			if ( geometryChunk.__webGLUVBuffer ) {
 
 
-			_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryChunk.__webGLUVBuffer );
+				_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryChunk.__webGLUVBuffer );
 
 
-			_gl.enableVertexAttribArray( program.uv );
-			_gl.vertexAttribPointer( program.uv, 2, _gl.FLOAT, false, 0, 0 );
+				_gl.enableVertexAttribArray( attributes.uv );
+				_gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
 
 
-		} else {
+			} else {
 
 
-			_gl.disableVertexAttribArray( program.uv );
+				_gl.disableVertexAttribArray( attributes.uv );
+				
+			}
 
 
 		}
 		}
 
 
@@ -517,7 +543,7 @@ THREE.WebGLRenderer = function ( scene ) {
 
 
 	};
 	};
 
 
-	this.renderPass = function ( camera, object, geometryChunk, blending, transparent ) {
+	this.renderPass = function ( camera, lights, object, geometryChunk, blending, transparent ) {
 
 
 		var i, l, m, ml, material, meshMaterial;
 		var i, l, m, ml, material, meshMaterial;
 
 
@@ -533,7 +559,7 @@ THREE.WebGLRenderer = function ( scene ) {
 					if ( material && material.blending == blending && ( material.opacity < 1.0 == transparent ) ) {
 					if ( material && material.blending == blending && ( material.opacity < 1.0 == transparent ) ) {
 
 
 						this.setBlending( material.blending );
 						this.setBlending( material.blending );
-						this.renderBuffer( camera, material, geometryChunk );
+						this.renderBuffer( camera, lights, material, geometryChunk );
 
 
 					}
 					}
 
 
@@ -545,7 +571,7 @@ THREE.WebGLRenderer = function ( scene ) {
 				if ( material && material.blending == blending && ( material.opacity < 1.0 == transparent ) ) {
 				if ( material && material.blending == blending && ( material.opacity < 1.0 == transparent ) ) {
 
 
 					this.setBlending( material.blending );
 					this.setBlending( material.blending );
-					this.renderBuffer( camera, material, geometryChunk );
+					this.renderBuffer( camera, lights, material, geometryChunk );
 					
 					
 				}
 				}
 
 
@@ -557,7 +583,8 @@ THREE.WebGLRenderer = function ( scene ) {
 	
 	
 	this.render = function( scene, camera ) {
 	this.render = function( scene, camera ) {
 
 
-		var o, ol, webGLObject, object, buffer;
+		var o, ol, webGLObject, object, buffer, 
+			lights = scene.lights;
 
 
 		this.initWebGLObjects( scene );
 		this.initWebGLObjects( scene );
 
 
@@ -568,10 +595,7 @@ THREE.WebGLRenderer = function ( scene ) {
 		}
 		}
 
 
 		camera.autoUpdateMatrix && camera.updateMatrix();
 		camera.autoUpdateMatrix && camera.updateMatrix();
-		this.loadCamera( _program, camera );
-
-		this.setupLights( _program, scene );
-
+		
 		// opaque pass
 		// opaque pass
 
 
 		for ( o = 0, ol = scene.__webGLObjects.length; o < ol; o++ ) {
 		for ( o = 0, ol = scene.__webGLObjects.length; o < ol; o++ ) {
@@ -584,8 +608,7 @@ THREE.WebGLRenderer = function ( scene ) {
 			if ( object.visible ) {
 			if ( object.visible ) {
 
 
 				this.setupMatrices( object, camera );
 				this.setupMatrices( object, camera );
-				this.loadMatrices( _program );
-				this.renderPass( camera, object, buffer, THREE.NormalBlending, false );
+				this.renderPass( camera, lights, object, buffer, THREE.NormalBlending, false );
 				
 				
 			}
 			}
 
 
@@ -603,21 +626,20 @@ THREE.WebGLRenderer = function ( scene ) {
 			if ( object.visible ) {
 			if ( object.visible ) {
 				
 				
 				this.setupMatrices( object, camera );
 				this.setupMatrices( object, camera );
-				this.loadMatrices( _program );
 
 
 				// opaque blended materials
 				// opaque blended materials
 				
 				
-				this.renderPass( camera, object, buffer, THREE.AdditiveBlending, false );
-				this.renderPass( camera, object, buffer, THREE.SubtractiveBlending, false );
+				this.renderPass( camera, lights, object, buffer, THREE.AdditiveBlending, false );
+				this.renderPass( camera, lights, object, buffer, THREE.SubtractiveBlending, false );
 				
 				
 				// transparent blended materials
 				// transparent blended materials
 				
 				
-				this.renderPass( camera, object, buffer, THREE.AdditiveBlending, true );
-				this.renderPass( camera, object, buffer, THREE.SubtractiveBlending, true );
+				this.renderPass( camera, lights, object, buffer, THREE.AdditiveBlending, true );
+				this.renderPass( camera, lights, object, buffer, THREE.SubtractiveBlending, true );
 
 
 				// transparent normal materials
 				// transparent normal materials
 				
 				
-				this.renderPass( camera, object, buffer, THREE.NormalBlending, true );
+				this.renderPass( camera, lights, object, buffer, THREE.NormalBlending, true );
 				
 				
 			}
 			}
 
 
@@ -1188,6 +1210,7 @@ THREE.WebGLRenderer = function ( scene ) {
 		}
 		}
 		
 		
 		program.uniforms = {};
 		program.uniforms = {};
+		program.attributes = {};
 		
 		
 		return program;
 		return program;
 		
 		
@@ -1301,44 +1324,51 @@ THREE.WebGLRenderer = function ( scene ) {
 		
 		
 		for( i = 0, l = identifiers.length; i < l; i++ ) {
 		for( i = 0, l = identifiers.length; i < l; i++ ) {
 			
 			
-			id = identifiers[i];
-			program.uniforms[id] = _gl.getUniformLocation( program, id );
+			id = identifiers[ i ];
+			program.uniforms[ id ] = _gl.getUniformLocation( program, id );
 			
 			
 		}
 		}
 		
 		
 	};
 	};
-	
-	function cacheAttributeLocations( program ) {
-		
-		program.position = _gl.getAttribLocation( program, "position" );
-		_gl.enableVertexAttribArray( program.position );
-
-		program.normal = _gl.getAttribLocation( program, "normal" );
-		_gl.enableVertexAttribArray( program.normal );
 
 
-		program.uv = _gl.getAttribLocation( program, "uv" );
-		_gl.enableVertexAttribArray( program.uv );
+	function cacheAttributeLocations( program, identifiers ) {
 
 
+		var i, l, id;
+		
+		for( i = 0, l = identifiers.length; i < l; i++ ) {
+			
+			id = identifiers[ i ];
+			program.attributes[ id ] = _gl.getAttribLocation( program, id );
+			
+			if ( program.attributes[ id ] >= 0 ) {
+			
+				_gl.enableVertexAttribArray( program.attributes[ id ] );
+				
+			}
+		
+		}
+		
 	};
 	};
 	
 	
 	function initUbershader( maxDirLights, maxPointLights ) {
 	function initUbershader( maxDirLights, maxPointLights ) {
 
 
 		var vertex_shader = generateVertexShader( maxDirLights, maxPointLights ),
 		var vertex_shader = generateVertexShader( maxDirLights, maxPointLights ),
-			fragment_shader = generateFragmentShader( maxDirLights, maxPointLights );
+			fragment_shader = generateFragmentShader( maxDirLights, maxPointLights ),
+			program;
 
 
 		//log ( vertex_shader );
 		//log ( vertex_shader );
 		//log ( fragment_shader );
 		//log ( fragment_shader );
 		
 		
-		_program = buildProgram( fragment_shader, vertex_shader );
+		program = buildProgram( fragment_shader, vertex_shader );
 		
 		
-		_gl.useProgram( _program );
+		_gl.useProgram( program );
 
 
 		// matrices
 		// matrices
 		// lights
 		// lights
 		// material properties (Basic / Lambert / Blinn-Phong shader)
 		// material properties (Basic / Lambert / Blinn-Phong shader)
 		// material properties (Depth)
 		// material properties (Depth)
 
 
-		cacheUniformLocations( _program, [ 'viewMatrix', 'modelViewMatrix', 'projectionMatrix', 'normalMatrix', 'objectMatrix', 'cameraPosition',
+		cacheUniformLocations( program, [ 'viewMatrix', 'modelViewMatrix', 'projectionMatrix', 'normalMatrix', 'objectMatrix', 'cameraPosition',
 										   'enableLighting', 'ambientLightColor',
 										   'enableLighting', 'ambientLightColor',
 										   'material', 'mColor', 'mAmbient', 'mSpecular', 'mShininess', 'mOpacity',
 										   'material', 'mColor', 'mAmbient', 'mSpecular', 'mShininess', 'mOpacity',
 										   'enableMap', 'tMap',
 										   'enableMap', 'tMap',
@@ -1350,34 +1380,36 @@ THREE.WebGLRenderer = function ( scene ) {
 
 
 		if ( maxDirLights ) {
 		if ( maxDirLights ) {
 			
 			
-			cacheUniformLocations( _program, [ 'directionalLightNumber', 'directionalLightColor', 'directionalLightDirection' ] );			
+			cacheUniformLocations( program, [ 'directionalLightNumber', 'directionalLightColor', 'directionalLightDirection' ] );			
 
 
 		}
 		}
 
 
 		if ( maxPointLights ) {
 		if ( maxPointLights ) {
 
 
-			cacheUniformLocations( _program, [ 'pointLightNumber', 'pointLightColor', 'pointLightPosition' ] );			
+			cacheUniformLocations( program, [ 'pointLightNumber', 'pointLightColor', 'pointLightPosition' ] );			
 
 
 		}
 		}
 
 
 		// texture (diffuse map)
 		// texture (diffuse map)
 		
 		
-		_gl.uniform1i( _program.uniforms.enableMap, 0 );
-		_gl.uniform1i( _program.uniforms.tMap, 0 );
+		_gl.uniform1i( program.uniforms.enableMap, 0 );
+		_gl.uniform1i( program.uniforms.tMap, 0 );
 
 
 		// cube texture
 		// cube texture
 
 
-		_gl.uniform1i( _program.uniforms.enableCubeMap, 0 );
-		_gl.uniform1i( _program.uniforms.tCube, 1 ); // it's important to use non-zero texture unit, otherwise it doesn't work
-		_gl.uniform1i( _program.uniforms.mixEnvMap, 0 );
+		_gl.uniform1i( program.uniforms.enableCubeMap, 0 );
+		_gl.uniform1i( program.uniforms.tCube, 1 ); // it's important to use non-zero texture unit, otherwise it doesn't work
+		_gl.uniform1i( program.uniforms.mixEnvMap, 0 );
 
 
 		// refraction
 		// refraction
 		
 		
-		_gl.uniform1i( _program.uniforms.useRefract, 0 );
+		_gl.uniform1i( program.uniforms.useRefract, 0 );
 		
 		
-		// vertex arrays
+		// attribute arrays
 
 
-		cacheAttributeLocations( _program );	
+		cacheAttributeLocations( program, [ "position", "normal", "uv" ] );
+		
+		return program;
 
 
 	};
 	};