Browse Source

Added normal + ambient occlusion + displacement mapping demo.

A lot of things going on in this commit:

- added tangents computation for geometries
    - mesh must have UV coordinates
    - to be called explicitly once geometry is loaded like this: geometry.computeTangents()
    - tangents are stored in Vertex objects
    - quads are not solved properly (though workaround hack seems to work at least somehow, as far as each vertex appears at least somewhere)

- extended VBOs in WebGLRenderer to include tangent streams (when available)

- added "normal" shader to ShaderUtils (to be used with MeshShaderMaterial)
   - Blinn-Phong with one directional and one point light (7 varyings gone, just one spare)
   - normal maps are in tangent space
   - displacement maps use simple luminance value (could be changed if better precision is needed)

- displacement mapping uses vertex texture fetch
    - this requires GPU with Shader Model 3.0
    - not currently supported in ANGLE
    - for this, added "supportsVertexTextures" method to WebGLRenderer API, so that application can handle this
alteredq 14 years ago
parent
commit
ac5276b41f

+ 120 - 115
build/Three.js

@@ -5,59 +5,62 @@ THREE.Color.prototype={setRGB:function(a,b,d){this.r=a;this.g=b;this.b=d;if(this
 THREE.Vector2.prototype={set:function(a,b){this.x=a;this.y=b;return this},copy:function(a){this.x=a.x;this.y=a.y;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;return this},unit:function(){this.multiplyScalar(1/this.length());return this},length:function(){return Math.sqrt(this.x*
 this.x+this.y*this.y)},lengthSq:function(){return this.x*this.x+this.y*this.y},negate:function(){this.x=-this.x;this.y=-this.y;return this},clone:function(){return new THREE.Vector2(this.x,this.y)},toString:function(){return"THREE.Vector2 ("+this.x+", "+this.y+")"}};THREE.Vector3=function(a,b,d){this.x=a||0;this.y=b||0;this.z=d||0};
 THREE.Vector3.prototype={set:function(a,b,d){this.x=a;this.y=b;this.z=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;return this},addScalar:function(a){this.x+=a;this.y+=a;this.z+=a;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;return this},
-cross:function(a,b){this.x=a.y*b.z-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){var b=this.x,d=this.y,g=this.z;this.x=d*a.z-g*a.y;this.y=g*a.x-b*a.z;this.z=b*a.y-d*a.x;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=
+cross:function(a,b){this.x=a.y*b.z-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){var b=this.x,d=this.y,f=this.z;this.x=d*a.z-f*a.y;this.y=f*a.x-b*a.z;this.z=b*a.y-d*a.x;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=
 a;return this},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},distanceTo:function(a){var b=this.x-a.x,d=this.y-a.y;a=this.z-a.z;return Math.sqrt(b*b+d*d+a*a)},distanceToSquared:function(a){var b=this.x-a.x,d=this.y-a.y;a=this.z-a.z;return b*b+d*d+a*a},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},negate:function(){this.x=-this.x;this.y=-this.y;this.z=-this.z;return this},normalize:function(){var a=
 Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z);a>0?this.multiplyScalar(1/a):this.set(0,0,0);return this},setLength:function(a){return this.normalize().multiplyScalar(a)},isZero:function(){return Math.abs(this.x)<1.0E-4&&Math.abs(this.y)<1.0E-4&&Math.abs(this.z)<1.0E-4},clone:function(){return new THREE.Vector3(this.x,this.y,this.z)},toString:function(){return"THREE.Vector3 ( "+this.x+", "+this.y+", "+this.z+" )"}};
-THREE.Vector4=function(a,b,d,g){this.x=a||0;this.y=b||0;this.z=d||0;this.w=g||1};
-THREE.Vector4.prototype={set:function(a,b,d,g){this.x=a;this.y=b;this.z=d;this.w=g;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w||1;return this},add:function(a,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=function(a,b,d,f){this.x=a||0;this.y=b||0;this.z=d||0;this.w=f||1};
+THREE.Vector4.prototype={set:function(a,b,d,f){this.x=a;this.y=b;this.z=d;this.w=f;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w||1;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;
 return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=a;this.w/=a;return this},lerpSelf:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},toString:function(){return"THREE.Vector4 ("+this.x+", "+this.y+", "+this.z+", "+this.w+")"}};
 THREE.Ray=function(a,b){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3};
-THREE.Ray.prototype={intersectScene:function(a){var b,d,g=a.objects,j=[];a=0;for(b=g.length;a<b;a++){d=g[a];if(d instanceof THREE.Mesh)j=j.concat(this.intersectObject(d))}j.sort(function(n,m){return n.distance-m.distance});return j},intersectObject:function(a){function b(L,N,O,v){v=v.clone().subSelf(N);O=O.clone().subSelf(N);var f=L.clone().subSelf(N);L=v.dot(v);N=v.dot(O);v=v.dot(f);var k=O.dot(O);O=O.dot(f);f=1/(L*k-N*N);k=(k*v-N*O)*f;L=(L*O-N*v)*f;return k>0&&L>0&&k+L<1}var d,g,j,n,m,l,o,c,F,D,
-w,x=a.geometry,I=x.vertices,G=[];d=0;for(g=x.faces.length;d<g;d++){j=x.faces[d];D=this.origin.clone();w=this.direction.clone();n=a.matrix.multiplyVector3(I[j.a].position.clone());m=a.matrix.multiplyVector3(I[j.b].position.clone());l=a.matrix.multiplyVector3(I[j.c].position.clone());o=j instanceof THREE.Face4?a.matrix.multiplyVector3(I[j.d].position.clone()):null;c=a.rotationMatrix.multiplyVector3(j.normal.clone());F=w.dot(c);if(F<0){c=c.dot((new THREE.Vector3).sub(n,D))/F;D=D.addSelf(w.multiplyScalar(c));
-if(j instanceof THREE.Face3){if(b(D,n,m,l)){j={distance:this.origin.distanceTo(D),point:D,face:j,object:a};G.push(j)}}else if(j instanceof THREE.Face4)if(b(D,n,m,o)||b(D,m,l,o)){j={distance:this.origin.distanceTo(D),point:D,face:j,object:a};G.push(j)}}}return G}};
-THREE.Rectangle=function(){function a(){n=g-b;m=j-d}var b,d,g,j,n,m,l=true;this.getX=function(){return b};this.getY=function(){return d};this.getWidth=function(){return n};this.getHeight=function(){return m};this.getLeft=function(){return b};this.getTop=function(){return d};this.getRight=function(){return g};this.getBottom=function(){return j};this.set=function(o,c,F,D){l=false;b=o;d=c;g=F;j=D;a()};this.addPoint=function(o,c){if(l){l=false;b=o;d=c;g=o;j=c}else{b=Math.min(b,o);d=Math.min(d,c);g=Math.max(g,
-o);j=Math.max(j,c)}a()};this.addRectangle=function(o){if(l){l=false;b=o.getLeft();d=o.getTop();g=o.getRight();j=o.getBottom()}else{b=Math.min(b,o.getLeft());d=Math.min(d,o.getTop());g=Math.max(g,o.getRight());j=Math.max(j,o.getBottom())}a()};this.inflate=function(o){b-=o;d-=o;g+=o;j+=o;a()};this.minSelf=function(o){b=Math.max(b,o.getLeft());d=Math.max(d,o.getTop());g=Math.min(g,o.getRight());j=Math.min(j,o.getBottom());a()};this.instersects=function(o){return Math.min(g,o.getRight())-Math.max(b,o.getLeft())>=
-0&&Math.min(j,o.getBottom())-Math.max(d,o.getTop())>=0};this.empty=function(){l=true;j=g=d=b=0;a()};this.isEmpty=function(){return l};this.toString=function(){return"THREE.Rectangle ( left: "+b+", right: "+g+", top: "+d+", bottom: "+j+", width: "+n+", 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,f=a.objects,j=[];a=0;for(b=f.length;a<b;a++){d=f[a];if(d instanceof THREE.Mesh)j=j.concat(this.intersectObject(d))}j.sort(function(m,n){return m.distance-n.distance});return j},intersectObject:function(a){function b(J,L,M,u){u=u.clone().subSelf(L);M=M.clone().subSelf(L);var e=J.clone().subSelf(L);J=u.dot(u);L=u.dot(M);u=u.dot(e);var k=M.dot(M);M=M.dot(e);e=1/(J*k-L*L);k=(k*u-L*M)*e;J=(J*M-L*u)*e;return k>0&&J>0&&k+J<1}var d,f,j,m,n,l,o,c,E,C,
+x,z=a.geometry,H=z.vertices,G=[];d=0;for(f=z.faces.length;d<f;d++){j=z.faces[d];C=this.origin.clone();x=this.direction.clone();m=a.matrix.multiplyVector3(H[j.a].position.clone());n=a.matrix.multiplyVector3(H[j.b].position.clone());l=a.matrix.multiplyVector3(H[j.c].position.clone());o=j instanceof THREE.Face4?a.matrix.multiplyVector3(H[j.d].position.clone()):null;c=a.rotationMatrix.multiplyVector3(j.normal.clone());E=x.dot(c);if(E<0){c=c.dot((new THREE.Vector3).sub(m,C))/E;C=C.addSelf(x.multiplyScalar(c));
+if(j instanceof THREE.Face3){if(b(C,m,n,l)){j={distance:this.origin.distanceTo(C),point:C,face:j,object:a};G.push(j)}}else if(j instanceof THREE.Face4)if(b(C,m,n,o)||b(C,n,l,o)){j={distance:this.origin.distanceTo(C),point:C,face:j,object:a};G.push(j)}}}return G}};
+THREE.Rectangle=function(){function a(){m=f-b;n=j-d}var b,d,f,j,m,n,l=true;this.getX=function(){return b};this.getY=function(){return d};this.getWidth=function(){return m};this.getHeight=function(){return n};this.getLeft=function(){return b};this.getTop=function(){return d};this.getRight=function(){return f};this.getBottom=function(){return j};this.set=function(o,c,E,C){l=false;b=o;d=c;f=E;j=C;a()};this.addPoint=function(o,c){if(l){l=false;b=o;d=c;f=o;j=c}else{b=Math.min(b,o);d=Math.min(d,c);f=Math.max(f,
+o);j=Math.max(j,c)}a()};this.addRectangle=function(o){if(l){l=false;b=o.getLeft();d=o.getTop();f=o.getRight();j=o.getBottom()}else{b=Math.min(b,o.getLeft());d=Math.min(d,o.getTop());f=Math.max(f,o.getRight());j=Math.max(j,o.getBottom())}a()};this.inflate=function(o){b-=o;d-=o;f+=o;j+=o;a()};this.minSelf=function(o){b=Math.max(b,o.getLeft());d=Math.max(d,o.getTop());f=Math.min(f,o.getRight());j=Math.min(j,o.getBottom());a()};this.instersects=function(o){return Math.min(f,o.getRight())-Math.max(b,o.getLeft())>=
+0&&Math.min(j,o.getBottom())-Math.max(d,o.getTop())>=0};this.empty=function(){l=true;j=f=d=b=0;a()};this.isEmpty=function(){return l};this.toString=function(){return"THREE.Rectangle ( left: "+b+", right: "+f+", top: "+d+", bottom: "+j+", width: "+m+", height: "+n+" )"}};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.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 g=new THREE.Vector3,j=new THREE.Vector3,n=new THREE.Vector3;n.sub(a,b).normalize();g.cross(d,n).normalize();j.cross(n,g).normalize();this.n11=g.x;this.n12=g.y;this.n13=g.z;this.n14=-g.dot(a);this.n21=j.x;this.n22=j.y;this.n23=j.z;this.n24=-j.dot(a);this.n31=n.x;this.n32=n.y;this.n33=n.z;this.n34=-n.dot(a);this.n43=this.n42=this.n41=0;this.n44=1},multiplyVector3:function(a){var b=a.x,d=a.y,g=a.z,j=1/(this.n41*b+this.n42*
-d+this.n43*g+this.n44);a.x=(this.n11*b+this.n12*d+this.n13*g+this.n14)*j;a.y=(this.n21*b+this.n22*d+this.n23*g+this.n24)*j;a.z=(this.n31*b+this.n32*d+this.n33*g+this.n34)*j;return a},multiplyVector4:function(a){var b=a.x,d=a.y,g=a.z,j=a.w;a.x=this.n11*b+this.n12*d+this.n13*g+this.n14*j;a.y=this.n21*b+this.n22*d+this.n23*g+this.n24*j;a.z=this.n31*b+this.n32*d+this.n33*g+this.n34*j;a.w=this.n41*b+this.n42*d+this.n43*g+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,g=a.n12,j=a.n13,n=a.n14,m=a.n21,l=a.n22,o=a.n23,c=a.n24,F=a.n31,D=a.n32,w=a.n33,x=a.n34,I=a.n41,G=a.n42,L=a.n43,N=a.n44,O=b.n11,v=b.n12,f=b.n13,k=b.n14,e=b.n21,p=b.n22,h=b.n23,i=b.n24,s=b.n31,r=b.n32,M=b.n33,A=b.n34,H=b.n41,Q=b.n42,u=b.n43,
-R=b.n44;this.n11=d*O+g*e+j*s+n*H;this.n12=d*v+g*p+j*r+n*Q;this.n13=d*f+g*h+j*M+n*u;this.n14=d*k+g*i+j*A+n*R;this.n21=m*O+l*e+o*s+c*H;this.n22=m*v+l*p+o*r+c*Q;this.n23=m*f+l*h+o*M+c*u;this.n24=m*k+l*i+o*A+c*R;this.n31=F*O+D*e+w*s+x*H;this.n32=F*v+D*p+w*r+x*Q;this.n33=F*f+D*h+w*M+x*u;this.n34=F*k+D*i+w*A+x*R;this.n41=I*O+G*e+L*s+N*H;this.n42=I*v+G*p+L*r+N*Q;this.n43=I*f+G*h+L*M+N*u;this.n44=I*k+G*i+L*A+N*R},multiplySelf:function(a){var b=this.n11,d=this.n12,g=this.n13,j=this.n14,n=this.n21,m=this.n22,
-l=this.n23,o=this.n24,c=this.n31,F=this.n32,D=this.n33,w=this.n34,x=this.n41,I=this.n42,G=this.n43,L=this.n44;this.n11=b*a.n11+d*a.n21+g*a.n31+j*a.n41;this.n12=b*a.n12+d*a.n22+g*a.n32+j*a.n42;this.n13=b*a.n13+d*a.n23+g*a.n33+j*a.n43;this.n14=b*a.n14+d*a.n24+g*a.n34+j*a.n44;this.n21=n*a.n11+m*a.n21+l*a.n31+o*a.n41;this.n22=n*a.n12+m*a.n22+l*a.n32+o*a.n42;this.n23=n*a.n13+m*a.n23+l*a.n33+o*a.n43;this.n24=n*a.n14+m*a.n24+l*a.n34+o*a.n44;this.n31=c*a.n11+F*a.n21+D*a.n31+w*a.n41;this.n32=c*a.n12+F*a.n22+
-D*a.n32+w*a.n42;this.n33=c*a.n13+F*a.n23+D*a.n33+w*a.n43;this.n34=c*a.n14+F*a.n24+D*a.n34+w*a.n44;this.n41=x*a.n11+I*a.n21+G*a.n31+L*a.n41;this.n42=x*a.n12+I*a.n22+G*a.n32+L*a.n42;this.n43=x*a.n13+I*a.n23+G*a.n33+L*a.n43;this.n44=x*a.n14+I*a.n24+G*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 f=new THREE.Vector3,j=new THREE.Vector3,m=new THREE.Vector3;m.sub(a,b).normalize();f.cross(d,m).normalize();j.cross(m,f).normalize();this.n11=f.x;this.n12=f.y;this.n13=f.z;this.n14=-f.dot(a);this.n21=j.x;this.n22=j.y;this.n23=j.z;this.n24=-j.dot(a);this.n31=m.x;this.n32=m.y;this.n33=m.z;this.n34=-m.dot(a);this.n43=this.n42=this.n41=0;this.n44=1},multiplyVector3:function(a){var b=a.x,d=a.y,f=a.z,j=1/(this.n41*b+this.n42*
+d+this.n43*f+this.n44);a.x=(this.n11*b+this.n12*d+this.n13*f+this.n14)*j;a.y=(this.n21*b+this.n22*d+this.n23*f+this.n24)*j;a.z=(this.n31*b+this.n32*d+this.n33*f+this.n34)*j;return a},multiplyVector4:function(a){var b=a.x,d=a.y,f=a.z,j=a.w;a.x=this.n11*b+this.n12*d+this.n13*f+this.n14*j;a.y=this.n21*b+this.n22*d+this.n23*f+this.n24*j;a.z=this.n31*b+this.n32*d+this.n33*f+this.n34*j;a.w=this.n41*b+this.n42*d+this.n43*f+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,f=a.n12,j=a.n13,m=a.n14,n=a.n21,l=a.n22,o=a.n23,c=a.n24,E=a.n31,C=a.n32,x=a.n33,z=a.n34,H=a.n41,G=a.n42,J=a.n43,L=a.n44,M=b.n11,u=b.n12,e=b.n13,k=b.n14,g=b.n21,q=b.n22,h=b.n23,i=b.n24,r=b.n31,p=b.n32,D=b.n33,w=b.n34,I=b.n41,S=b.n42,t=b.n43,
+O=b.n44;this.n11=d*M+f*g+j*r+m*I;this.n12=d*u+f*q+j*p+m*S;this.n13=d*e+f*h+j*D+m*t;this.n14=d*k+f*i+j*w+m*O;this.n21=n*M+l*g+o*r+c*I;this.n22=n*u+l*q+o*p+c*S;this.n23=n*e+l*h+o*D+c*t;this.n24=n*k+l*i+o*w+c*O;this.n31=E*M+C*g+x*r+z*I;this.n32=E*u+C*q+x*p+z*S;this.n33=E*e+C*h+x*D+z*t;this.n34=E*k+C*i+x*w+z*O;this.n41=H*M+G*g+J*r+L*I;this.n42=H*u+G*q+J*p+L*S;this.n43=H*e+G*h+J*D+L*t;this.n44=H*k+G*i+J*w+L*O},multiplySelf:function(a){var b=this.n11,d=this.n12,f=this.n13,j=this.n14,m=this.n21,n=this.n22,
+l=this.n23,o=this.n24,c=this.n31,E=this.n32,C=this.n33,x=this.n34,z=this.n41,H=this.n42,G=this.n43,J=this.n44;this.n11=b*a.n11+d*a.n21+f*a.n31+j*a.n41;this.n12=b*a.n12+d*a.n22+f*a.n32+j*a.n42;this.n13=b*a.n13+d*a.n23+f*a.n33+j*a.n43;this.n14=b*a.n14+d*a.n24+f*a.n34+j*a.n44;this.n21=m*a.n11+n*a.n21+l*a.n31+o*a.n41;this.n22=m*a.n12+n*a.n22+l*a.n32+o*a.n42;this.n23=m*a.n13+n*a.n23+l*a.n33+o*a.n43;this.n24=m*a.n14+n*a.n24+l*a.n34+o*a.n44;this.n31=c*a.n11+E*a.n21+C*a.n31+x*a.n41;this.n32=c*a.n12+E*a.n22+
+C*a.n32+x*a.n42;this.n33=c*a.n13+E*a.n23+C*a.n33+x*a.n43;this.n34=c*a.n14+E*a.n24+C*a.n34+x*a.n44;this.n41=z*a.n11+H*a.n21+G*a.n31+J*a.n41;this.n42=z*a.n12+H*a.n22+G*a.n32+J*a.n42;this.n43=z*a.n13+H*a.n23+G*a.n33+J*a.n43;this.n44=z*a.n14+H*a.n24+G*a.n34+J*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.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,g){var j=b[d];b[d]=b[g];b[g]=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,f){var j=b[d];b[d]=b[f];b[f]=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]},
-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 g=new THREE.Matrix4;g.n14=a;g.n24=b;g.n34=d;return g};THREE.Matrix4.scaleMatrix=function(a,b,d){var g=new THREE.Matrix4;g.n11=a;g.n22=b;g.n33=d;return g};
+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 f=new THREE.Matrix4;f.n14=a;f.n24=b;f.n34=d;return f};THREE.Matrix4.scaleMatrix=function(a,b,d){var f=new THREE.Matrix4;f.n11=a;f.n22=b;f.n33=d;return f};
 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,g=Math.cos(b),j=Math.sin(b),n=1-g,m=a.x,l=a.y,o=a.z;d.n11=n*m*m+g;d.n12=n*m*l-j*o;d.n13=n*m*o+j*l;d.n21=n*m*l+j*o;d.n22=n*l*l+g;d.n23=n*l*o-j*m;d.n31=n*m*o-j*l;d.n32=n*l*o+j*m;d.n33=n*o*o+g;return d};
+THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var d=new THREE.Matrix4,f=Math.cos(b),j=Math.sin(b),m=1-f,n=a.x,l=a.y,o=a.z;d.n11=m*n*n+f;d.n12=m*n*l-j*o;d.n13=m*n*o+j*l;d.n21=m*n*l+j*o;d.n22=m*l*l+f;d.n23=m*l*o-j*n;d.n31=m*n*o-j*l;d.n32=m*l*o+j*n;d.n33=m*o*o+f;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*
 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.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],g=-b[10]*b[1]+b[2]*b[9],j=b[6]*b[1]-b[2]*b[5],n=-b[10]*b[4]+b[6]*b[8],m=b[10]*b[0]-b[2]*b[8],l=-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],F=b[5]*b[0]-b[1]*b[4];b=b[0]*d+b[1]*n+b[2]*o;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*d;a.m[1]=b*g;a.m[2]=b*j;a.m[3]=b*n;a.m[4]=b*m;a.m[5]=b*l;a.m[6]=b*o;a.m[7]=b*c;a.m[8]=b*F;return a};
-THREE.Matrix4.makeFrustum=function(a,b,d,g,j,n){var m,l,o;m=new THREE.Matrix4;l=2*j/(b-a);o=2*j/(g-d);a=(b+a)/(b-a);d=(g+d)/(g-d);g=-(n+j)/(n-j);j=-2*n*j/(n-j);m.n11=l;m.n12=0;m.n13=a;m.n14=0;m.n21=0;m.n22=o;m.n23=d;m.n24=0;m.n31=0;m.n32=0;m.n33=g;m.n34=j;m.n41=0;m.n42=0;m.n43=-1;m.n44=0;return m};THREE.Matrix4.makePerspective=function(a,b,d,g){var j;a=d*Math.tan(a*Math.PI/360);j=-a;return THREE.Matrix4.makeFrustum(j*b,a*b,j,a,d,g)};
-THREE.Matrix4.makeOrtho=function(a,b,d,g,j,n){var m,l,o,c;m=new THREE.Matrix4;l=b-a;o=d-g;c=n-j;a=(b+a)/l;d=(d+g)/o;j=(n+j)/c;m.n11=2/l;m.n12=0;m.n13=0;m.n14=-a;m.n21=0;m.n22=2/o;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.Face3=function(a,b,d,g,j){this.a=a;this.b=b;this.c=d;this.centroid=new THREE.Vector3;this.normal=g instanceof THREE.Vector3?g:new THREE.Vector3;this.vertexNormals=g instanceof Array?g:[];this.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,g,j,n){this.a=a;this.b=b;this.c=d;this.d=g;this.centroid=new THREE.Vector3;this.normal=j instanceof THREE.Vector3?j:new THREE.Vector3;this.vertexNormals=j instanceof Array?j:[];this.material=n instanceof Array?n:[n]};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.Matrix4.makeInvert3x3=function(a){var b=a.flatten();a=new THREE.Matrix3;var d=b[10]*b[5]-b[6]*b[9],f=-b[10]*b[1]+b[2]*b[9],j=b[6]*b[1]-b[2]*b[5],m=-b[10]*b[4]+b[6]*b[8],n=b[10]*b[0]-b[2]*b[8],l=-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],E=b[5]*b[0]-b[1]*b[4];b=b[0]*d+b[1]*m+b[2]*o;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*d;a.m[1]=b*f;a.m[2]=b*j;a.m[3]=b*m;a.m[4]=b*n;a.m[5]=b*l;a.m[6]=b*o;a.m[7]=b*c;a.m[8]=b*E;return a};
+THREE.Matrix4.makeFrustum=function(a,b,d,f,j,m){var n,l,o;n=new THREE.Matrix4;l=2*j/(b-a);o=2*j/(f-d);a=(b+a)/(b-a);d=(f+d)/(f-d);f=-(m+j)/(m-j);j=-2*m*j/(m-j);n.n11=l;n.n12=0;n.n13=a;n.n14=0;n.n21=0;n.n22=o;n.n23=d;n.n24=0;n.n31=0;n.n32=0;n.n33=f;n.n34=j;n.n41=0;n.n42=0;n.n43=-1;n.n44=0;return n};THREE.Matrix4.makePerspective=function(a,b,d,f){var j;a=d*Math.tan(a*Math.PI/360);j=-a;return THREE.Matrix4.makeFrustum(j*b,a*b,j,a,d,f)};
+THREE.Matrix4.makeOrtho=function(a,b,d,f,j,m){var n,l,o,c;n=new THREE.Matrix4;l=b-a;o=d-f;c=m-j;a=(b+a)/l;d=(d+f)/o;j=(m+j)/c;n.n11=2/l;n.n12=0;n.n13=0;n.n14=-a;n.n21=0;n.n22=2/o;n.n23=0;n.n24=-d;n.n31=0;n.n32=0;n.n33=-2/c;n.n34=-j;n.n41=0;n.n42=0;n.n43=0;n.n44=1;return n};
+THREE.Vertex=function(a,b){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=b||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.tangent=new THREE.Vector4;this.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}};
+THREE.Face3=function(a,b,d,f,j){this.a=a;this.b=b;this.c=d;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.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
+THREE.Face4=function(a,b,d,f,j,m){this.a=a;this.b=b;this.c=d;this.d=f;this.centroid=new THREE.Vector3;this.normal=j instanceof THREE.Vector3?j:new THREE.Vector3;this.vertexNormals=j instanceof Array?j:[];this.material=m instanceof Array?m:[m]};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={};this.hasTangents=false};
 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);if(d instanceof THREE.Face3){d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);d.centroid.divideScalar(3)}else if(d instanceof THREE.Face4){d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);
-d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeNormals:function(a){var b,d,g,j,n,m,l=new THREE.Vector3,o=new THREE.Vector3;g=0;for(j=this.vertices.length;g<j;g++){n=this.vertices[g];n.normal.set(0,0,0)}g=0;for(j=this.faces.length;g<j;g++){n=this.faces[g];if(a&&n.vertexNormals.length){l.set(0,0,0);b=0;for(d=n.normal.length;b<d;b++)l.addSelf(n.vertexNormals[b]);l.divideScalar(3)}else{b=this.vertices[n.a];d=this.vertices[n.b];m=this.vertices[n.c];l.sub(m.position,
-d.position);o.sub(b.position,d.position);l.crossSelf(o)}l.isZero()||l.normalize();n.normal.copy(l)}},computeVertexNormals:function(){var a,b=[],d,g;a=0;for(vl=this.vertices.length;a<vl;a++)b[a]=new THREE.Vector3;a=0;for(d=this.faces.length;a<d;a++){g=this.faces[a];if(g instanceof THREE.Face3){b[g.a].addSelf(g.normal);b[g.b].addSelf(g.normal);b[g.c].addSelf(g.normal)}else if(g instanceof THREE.Face4){b[g.a].addSelf(g.normal);b[g.b].addSelf(g.normal);b[g.c].addSelf(g.normal);b[g.d].addSelf(g.normal)}}a=
-0;for(vl=this.vertices.length;a<vl;a++)b[a].normalize();a=0;for(d=this.faces.length;a<d;a++){g=this.faces[a];if(g instanceof THREE.Face3){g.vertexNormals[0]=b[g.a].clone();g.vertexNormals[1]=b[g.b].clone();g.vertexNormals[2]=b[g.c].clone()}else if(g instanceof THREE.Face4){g.vertexNormals[0]=b[g.a].clone();g.vertexNormals[1]=b[g.b].clone();g.vertexNormals[2]=b[g.c].clone();g.vertexNormals[3]=b[g.d].clone()}}},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(F){var D=[];b=0;for(d=F.length;b<d;b++)F[b]==undefined?D.push("undefined"):D.push(F[b].toString());return D.join("_")}var b,d,g,j,n,m,l,o,c={};g=0;for(j=this.faces.length;g<j;g++){n=this.faces[g];m=n.material;l=a(m);if(c[l]==undefined)c[l]={hash:l,counter:0};o=c[l].hash+"_"+c[l].counter;if(this.geometryChunks[o]==
-undefined)this.geometryChunks[o]={faces:[],material:m,vertices:0};n=n instanceof THREE.Face3?3:4;if(this.geometryChunks[o].vertices+n>65535){c[l].counter+=1;o=c[l].hash+"_"+c[l].counter;if(this.geometryChunks[o]==undefined)this.geometryChunks[o]={faces:[],material:m,vertices:0}}this.geometryChunks[o].faces.push(g);this.geometryChunks[o].vertices+=n}},toString:function(){return"THREE.Geometry ( vertices: "+this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
-THREE.Camera=function(a,b,d,g){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,g);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)};
+d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeNormals:function(a){var b,d,f,j,m,n,l=new THREE.Vector3,o=new THREE.Vector3;f=0;for(j=this.vertices.length;f<j;f++){m=this.vertices[f];m.normal.set(0,0,0)}f=0;for(j=this.faces.length;f<j;f++){m=this.faces[f];if(a&&m.vertexNormals.length){l.set(0,0,0);b=0;for(d=m.normal.length;b<d;b++)l.addSelf(m.vertexNormals[b]);l.divideScalar(3)}else{b=this.vertices[m.a];d=this.vertices[m.b];n=this.vertices[m.c];l.sub(n.position,
+d.position);o.sub(b.position,d.position);l.crossSelf(o)}l.isZero()||l.normalize();m.normal.copy(l)}},computeVertexNormals:function(){var a,b=[],d,f;a=0;for(vl=this.vertices.length;a<vl;a++)b[a]=new THREE.Vector3;a=0;for(d=this.faces.length;a<d;a++){f=this.faces[a];if(f instanceof THREE.Face3){b[f.a].addSelf(f.normal);b[f.b].addSelf(f.normal);b[f.c].addSelf(f.normal)}else if(f instanceof THREE.Face4){b[f.a].addSelf(f.normal);b[f.b].addSelf(f.normal);b[f.c].addSelf(f.normal);b[f.d].addSelf(f.normal)}}a=
+0;for(vl=this.vertices.length;a<vl;a++)b[a].normalize();a=0;for(d=this.faces.length;a<d;a++){f=this.faces[a];if(f instanceof THREE.Face3){f.vertexNormals[0]=b[f.a].clone();f.vertexNormals[1]=b[f.b].clone();f.vertexNormals[2]=b[f.c].clone()}else if(f instanceof THREE.Face4){f.vertexNormals[0]=b[f.a].clone();f.vertexNormals[1]=b[f.b].clone();f.vertexNormals[2]=b[f.c].clone();f.vertexNormals[3]=b[f.d].clone()}}},computeTangents:function(){function a(w,I,S,t){m=w.vertices[I].position;n=w.vertices[S].position;
+l=w.vertices[t].position;o=j[0];c=j[1];E=j[2];C=n.x-m.x;x=l.x-m.x;z=n.y-m.y;H=l.y-m.y;G=n.z-m.z;J=l.z-m.z;L=c.u-o.u;M=E.u-o.u;u=c.v-o.v;e=E.v-o.v;k=1/(L*e-M*u);i.set((e*C-u*x)*k,(e*z-u*H)*k,(e*G-u*J)*k);r.set((L*x-M*C)*k,(L*H-M*z)*k,(L*J-M*G)*k);q[I].addSelf(i);q[S].addSelf(i);q[t].addSelf(i);h[I].addSelf(r);h[S].addSelf(r);h[t].addSelf(r)}var b,d,f,j,m,n,l,o,c,E,C,x,z,H,G,J,L,M,u,e,k,g,q=[],h=[],i=new THREE.Vector3,r=new THREE.Vector3,p=new THREE.Vector3,D=new THREE.Vector3;g=new THREE.Vector3;b=
+0;for(d=this.vertices.length;b<d;b++){q[b]=new THREE.Vector3;h[b]=new THREE.Vector3}b=0;for(d=this.faces.length;b<d;b++){f=this.faces[b];j=this.uvs[b];if(f instanceof THREE.Face3){a(this,f.a,f.b,f.c);this.vertices[f.a].normal.copy(f.vertexNormals[0]);this.vertices[f.b].normal.copy(f.vertexNormals[1]);this.vertices[f.c].normal.copy(f.vertexNormals[2])}else if(f instanceof THREE.Face4){a(this,f.a,f.b,f.c);this.vertices[f.a].normal.copy(f.vertexNormals[0]);this.vertices[f.b].normal.copy(f.vertexNormals[1]);
+this.vertices[f.c].normal.copy(f.vertexNormals[2]);this.vertices[f.d].normal.copy(f.vertexNormals[3])}}b=0;for(d=this.vertices.length;b<d;b++){g.copy(this.vertices[b].normal);f=q[b];p.copy(f);p.subSelf(g.multiplyScalar(g.dot(f))).normalize();D.cross(this.vertices[b].normal,f);test=D.dot(h[b]);f=test<0?-1:1;this.vertices[b].tangent.set(p.x,p.y,p.z,f)}this.hasTangents=true},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 C=[];b=0;for(d=E.length;b<d;b++)E[b]==undefined?C.push("undefined"):C.push(E[b].toString());return C.join("_")}var b,d,f,j,m,n,l,o,c={};f=0;for(j=this.faces.length;f<j;f++){m=this.faces[f];n=m.material;l=a(n);if(c[l]==undefined)c[l]={hash:l,counter:0};o=c[l].hash+"_"+c[l].counter;if(this.geometryChunks[o]==undefined)this.geometryChunks[o]={faces:[],material:n,
+vertices:0};m=m instanceof THREE.Face3?3:4;if(this.geometryChunks[o].vertices+m>65535){c[l].counter+=1;o=c[l].hash+"_"+c[l].counter;if(this.geometryChunks[o]==undefined)this.geometryChunks[o]={faces:[],material:n,vertices:0}}this.geometryChunks[o].faces.push(f);this.geometryChunks[o].vertices+=m}},toString:function(){return"THREE.Geometry ( vertices: "+this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
+THREE.Camera=function(a,b,d,f){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,f);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.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.Object3D=function(){this.id=THREE.Object3DCounter.value++;this.position=new THREE.Vector3;this.rotation=new THREE.Vector3;this.scale=new THREE.Vector3(1,1,1);this.matrix=new THREE.Matrix4;this.translationMatrix=new THREE.Matrix4;this.rotationMatrix=new THREE.Matrix4;this.scaleMatrix=new THREE.Matrix4;this.screen=new THREE.Vector3;this.autoUpdateMatrix=this.visible=true;this.updateMatrix=function(){this.matrixPosition=THREE.Matrix4.translationMatrix(this.position.x,this.position.y,this.position.z);
 this.rotationMatrix=THREE.Matrix4.rotationXMatrix(this.rotation.x);this.rotationMatrix.multiplySelf(THREE.Matrix4.rotationYMatrix(this.rotation.y));this.rotationMatrix.multiplySelf(THREE.Matrix4.rotationZMatrix(this.rotation.z));this.scaleMatrix=THREE.Matrix4.scaleMatrix(this.scale.x,this.scale.y,this.scale.z);this.matrix.copy(this.matrixPosition);this.matrix.multiplySelf(this.rotationMatrix);this.matrix.multiplySelf(this.scaleMatrix)}};THREE.Object3DCounter={value:0};
 THREE.Particle=function(a){THREE.Object3D.call(this);this.material=a instanceof Array?a:[a];this.autoUpdateMatrix=false};THREE.Particle.prototype=new THREE.Object3D;THREE.Particle.prototype.constructor=THREE.Particle;THREE.Line=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.material=b instanceof Array?b:[b]};THREE.Line.prototype=new THREE.Object3D;THREE.Line.prototype.constructor=THREE.Line;
 THREE.Mesh=function(a,b,d){THREE.Object3D.call(this);this.geometry=a;this.material=b instanceof Array?b:[b];this.overdraw=this.doubleSided=this.flipSided=false;d&&this.normalizeUVs();this.geometry.computeBoundingBox()};THREE.Mesh.prototype=new THREE.Object3D;THREE.Mesh.prototype.constructor=THREE.Mesh;
-THREE.Mesh.prototype.normalizeUVs=function(){var a,b,d,g,j;a=0;for(b=this.geometry.uvs.length;a<b;a++){j=this.geometry.uvs[a];d=0;for(g=j.length;d<g;d++){if(j[d].u!=1)j[d].u-=Math.floor(j[d].u);if(j[d].v!=1)j[d].v-=Math.floor(j[d].v)}}};THREE.FlatShading=0;THREE.SmoothShading=1;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;
+THREE.Mesh.prototype.normalizeUVs=function(){var a,b,d,f,j;a=0;for(b=this.geometry.uvs.length;a<b;a++){j=this.geometry.uvs[a];d=0;for(f=j.length;d<f;d++){if(j[d].u!=1)j[d].u-=Math.floor(j[d].u);if(j[d].v!=1)j[d].v-=Math.floor(j[d].v)}}};THREE.FlatShading=0;THREE.SmoothShading=1;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;
 THREE.LineBasicMaterial=function(a){this.color=new THREE.Color(16711680);this.opacity=1;this.blending=THREE.NormalBlending;this.linewidth=1;this.linejoin=this.linecap="round";if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending;if(a.linewidth!==undefined)this.linewidth=a.linewidth;if(a.linecap!==undefined)this.linecap=a.linecap;if(a.linejoin!==undefined)this.linejoin=a.linejoin}this.toString=function(){return"THREE.LineBasicMaterial (<br/>color: "+
 this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>linewidth: "+this.linewidth+"<br/>linecap: "+this.linecap+"<br/>linejoin: "+this.linejoin+"<br/>)"}};
 THREE.MeshBasicMaterial=function(a){this.id=THREE.MeshBasicMaterialCounter.value++;this.color=new THREE.Color(15658734);this.env_map=this.map=null;this.combine=THREE.MultiplyOperation;this.reflectivity=1;this.refraction_ratio=0.98;this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=this.wireframe_linecap="round";if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.map!==undefined)this.map=
@@ -82,91 +85,93 @@ undefined)this.uniforms=a.uniforms;if(a.shading!==undefined)this.shading=a.shadi
 THREE.ParticleBasicMaterial=function(a){this.color=new THREE.Color(16711680);this.map=null;this.opacity=1;this.blending=THREE.NormalBlending;this.offset=new THREE.Vector2;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.map!==undefined)this.map=a.map;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}this.toString=function(){return"THREE.ParticleBasicMaterial (<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>opacity: "+this.opacity+"<br/>blending: "+
 this.blending+"<br/>)"}};THREE.ParticleCircleMaterial=function(a){this.color=new THREE.Color(16711680);this.opacity=1;this.blending=THREE.NormalBlending;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}this.toString=function(){return"THREE.ParticleCircleMaterial (<br/>color: "+this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>)"}};
 THREE.ParticleDOMMaterial=function(a){this.domElement=a;this.toString=function(){return"THREE.ParticleDOMMaterial ( domElement: "+this.domElement+" )"}};
-THREE.Texture=function(a,b,d,g,j,n){this.image=a;this.mapping=b!==undefined?b:new THREE.UVMapping;this.wrap_s=d!==undefined?d:THREE.ClampToEdgeWrapping;this.wrap_t=g!==undefined?g:THREE.ClampToEdgeWrapping;this.mag_filter=j!==undefined?j:THREE.LinearFilter;this.min_filter=n!==undefined?n:THREE.LinearMipMapLinearFilter;this.toString=function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>wrap_s: "+this.wrap_s+"<br/>wrap_t: "+this.wrap_t+"<br/>mag_filter: "+this.mag_filter+"<br/>min_filter: "+
+THREE.Texture=function(a,b,d,f,j,m){this.image=a;this.mapping=b!==undefined?b:new THREE.UVMapping;this.wrap_s=d!==undefined?d:THREE.ClampToEdgeWrapping;this.wrap_t=f!==undefined?f:THREE.ClampToEdgeWrapping;this.mag_filter=j!==undefined?j:THREE.LinearFilter;this.min_filter=m!==undefined?m:THREE.LinearMipMapLinearFilter;this.toString=function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>wrap_s: "+this.wrap_s+"<br/>wrap_t: "+this.wrap_t+"<br/>mag_filter: "+this.mag_filter+"<br/>min_filter: "+
 this.min_filter+"<br/>)"}};THREE.MultiplyOperation=0;THREE.MixOperation=1;THREE.RepeatWrapping=0;THREE.ClampToEdgeWrapping=1;THREE.MirroredRepeatWrapping=2;THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLinearFilter=5;THREE.LinearFilter=6;THREE.LinearMipMapNearestFilter=7;THREE.LinearMipMapLinearFilter=8;THREE.CubeReflectionMapping=function(){};THREE.CubeRefractionMapping=function(){};THREE.LatitudeReflectionMapping=function(){};THREE.LatitudeRefractionMapping=function(){};
 THREE.SphericalReflectionMapping=function(){};THREE.SphericalRefractionMapping=function(){};THREE.UVMapping=function(){};
 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(O,v){var f=0,k=1,e=O.z+O.w,p=v.z+v.w,h=-O.z+O.w,i=-v.z+v.w;if(e>=0&&p>=0&&h>=0&&i>=0)return true;else if(e<0&&p<0||h<0&&i<0)return false;else{if(e<0)f=Math.max(f,e/(e-p));else if(p<0)k=Math.min(k,e/(e-p));if(h<0)f=Math.max(f,h/(h-i));else if(i<0)k=Math.min(k,h/(h-i));if(k<f)return false;else{O.lerpSelf(v,f);v.lerpSelf(O,1-k);return true}}}var b=null,d,g,j,n=[],m,l,o=[],c,F,D=[],w=new THREE.Vector4,x=new THREE.Matrix4,I=new THREE.Matrix4,G=new THREE.Vector4,L=
-new THREE.Vector4,N;this.projectScene=function(O,v){var f,k,e,p,h,i,s,r,M,A,H,Q,u,R,y,z,E;b=[];j=l=F=0;v.autoUpdateMatrix&&v.updateMatrix();x.multiply(v.projectionMatrix,v.matrix);s=O.objects;f=0;for(k=s.length;f<k;f++){r=s[f];r.autoUpdateMatrix&&r.updateMatrix();M=r.matrix;A=r.rotationMatrix;H=r.material;Q=r.overdraw;if(r instanceof THREE.Mesh){u=r.geometry.vertices;e=0;for(p=u.length;e<p;e++){R=u[e];R.positionWorld.copy(R.position);M.multiplyVector3(R.positionWorld);y=R.positionScreen;y.copy(R.positionWorld);
-x.multiplyVector4(y);y.multiplyScalar(1/y.w);R.__visible=y.z>0&&y.z<1}R=r.geometry.faces;e=0;for(p=R.length;e<p;e++){y=R[e];if(y instanceof THREE.Face3){h=u[y.a];i=u[y.b];z=u[y.c];if(h.__visible&&i.__visible&&z.__visible)if(r.doubleSided||r.flipSided!=(z.positionScreen.x-h.positionScreen.x)*(i.positionScreen.y-h.positionScreen.y)-(z.positionScreen.y-h.positionScreen.y)*(i.positionScreen.x-h.positionScreen.x)<0){d=n[j]=n[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(h.positionWorld);d.v2.positionWorld.copy(i.positionWorld);
-d.v3.positionWorld.copy(z.positionWorld);d.v1.positionScreen.copy(h.positionScreen);d.v2.positionScreen.copy(i.positionScreen);d.v3.positionScreen.copy(z.positionScreen);d.normalWorld.copy(y.normal);A.multiplyVector3(d.normalWorld);d.centroidWorld.copy(y.centroid);M.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);x.multiplyVector3(d.centroidScreen);z=y.vertexNormals;N=d.vertexNormalsWorld;h=0;for(i=z.length;h<i;h++){E=N[h]=N[h]||new THREE.Vector3;E.copy(z[h]);A.multiplyVector3(E)}d.z=
-d.centroidScreen.z;d.meshMaterial=H;d.faceMaterial=y.material;d.overdraw=Q;if(r.geometry.uvs[e]){d.uvs[0]=r.geometry.uvs[e][0];d.uvs[1]=r.geometry.uvs[e][1];d.uvs[2]=r.geometry.uvs[e][2]}b.push(d);j++}}else if(y instanceof THREE.Face4){h=u[y.a];i=u[y.b];z=u[y.c];E=u[y.d];if(h.__visible&&i.__visible&&z.__visible&&E.__visible)if(r.doubleSided||r.flipSided!=((E.positionScreen.x-h.positionScreen.x)*(i.positionScreen.y-h.positionScreen.y)-(E.positionScreen.y-h.positionScreen.y)*(i.positionScreen.x-h.positionScreen.x)<
-0||(i.positionScreen.x-z.positionScreen.x)*(E.positionScreen.y-z.positionScreen.y)-(i.positionScreen.y-z.positionScreen.y)*(E.positionScreen.x-z.positionScreen.x)<0)){d=n[j]=n[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(h.positionWorld);d.v2.positionWorld.copy(i.positionWorld);d.v3.positionWorld.copy(E.positionWorld);d.v1.positionScreen.copy(h.positionScreen);d.v2.positionScreen.copy(i.positionScreen);d.v3.positionScreen.copy(E.positionScreen);d.normalWorld.copy(y.normal);A.multiplyVector3(d.normalWorld);
-d.centroidWorld.copy(y.centroid);M.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);x.multiplyVector3(d.centroidScreen);d.z=d.centroidScreen.z;d.meshMaterial=H;d.faceMaterial=y.material;d.overdraw=Q;if(r.geometry.uvs[e]){d.uvs[0]=r.geometry.uvs[e][0];d.uvs[1]=r.geometry.uvs[e][1];d.uvs[2]=r.geometry.uvs[e][3]}b.push(d);j++;g=n[j]=n[j]||new THREE.RenderableFace3;g.v1.positionWorld.copy(i.positionWorld);g.v2.positionWorld.copy(z.positionWorld);g.v3.positionWorld.copy(E.positionWorld);
-g.v1.positionScreen.copy(i.positionScreen);g.v2.positionScreen.copy(z.positionScreen);g.v3.positionScreen.copy(E.positionScreen);g.normalWorld.copy(d.normalWorld);g.centroidWorld.copy(d.centroidWorld);g.centroidScreen.copy(d.centroidScreen);g.z=g.centroidScreen.z;g.meshMaterial=H;g.faceMaterial=y.material;g.overdraw=Q;if(r.geometry.uvs[e]){g.uvs[0]=r.geometry.uvs[e][1];g.uvs[1]=r.geometry.uvs[e][2];g.uvs[2]=r.geometry.uvs[e][3]}b.push(g);j++}}}}else if(r instanceof THREE.Line){I.multiply(x,M);u=r.geometry.vertices;
-R=u[0];R.positionScreen.copy(R.position);I.multiplyVector4(R.positionScreen);e=1;for(p=u.length;e<p;e++){h=u[e];h.positionScreen.copy(h.position);I.multiplyVector4(h.positionScreen);i=u[e-1];G.copy(h.positionScreen);L.copy(i.positionScreen);if(a(G,L)){G.multiplyScalar(1/G.w);L.multiplyScalar(1/L.w);m=o[l]=o[l]||new THREE.RenderableLine;m.v1.positionScreen.copy(G);m.v2.positionScreen.copy(L);m.z=Math.max(G.z,L.z);m.material=r.material;b.push(m);l++}}}else if(r instanceof THREE.Particle){w.set(r.position.x,
-r.position.y,r.position.z,1);x.multiplyVector4(w);w.z/=w.w;if(w.z>0&&w.z<1){c=D[F]=D[F]||new THREE.RenderableParticle;c.x=w.x/w.w;c.y=w.y/w.w;c.z=w.z;c.rotation=r.rotation.z;c.scale.x=r.scale.x*Math.abs(c.x-(w.x+v.projectionMatrix.n11)/(w.w+v.projectionMatrix.n14));c.scale.y=r.scale.y*Math.abs(c.y-(w.y+v.projectionMatrix.n22)/(w.w+v.projectionMatrix.n24));c.material=r.material;b.push(c);F++}}}b.sort(function(W,J){return J.z-W.z});return b};this.unprojectVector=function(O,v){var f=new THREE.Matrix4;
-f.multiply(THREE.Matrix4.makeInvert(v.matrix),THREE.Matrix4.makeInvert(v.projectionMatrix));f.multiplyVector3(O);return O}};
-THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,d,g,j,n;this.domElement=document.createElement("div");this.setSize=function(m,l){d=m;g=l;j=d/2;n=g/2};this.render=function(m,l){var o,c,F,D,w,x,I,G;a=b.projectScene(m,l);o=0;for(c=a.length;o<c;o++){w=a[o];if(w instanceof THREE.RenderableParticle){I=w.x*j+j;G=w.y*n+n;F=0;for(D=w.material.length;F<D;F++){x=w.material[F];if(x instanceof THREE.ParticleDOMMaterial){x=x.domElement;x.style.left=I+"px";x.style.top=G+"px"}}}}}};
-THREE.CanvasRenderer=function(){var a=null,b=new THREE.Projector,d=document.createElement("canvas"),g,j,n,m,l=d.getContext("2d"),o=1,c=0,F=null,D=null,w=1,x=Math.min,I=Math.max,G,L,N,O,v,f,k,e,p,h=new THREE.Color,i=new THREE.Color,s=new THREE.Color,r=new THREE.Color,M=new THREE.Color,A,H,Q,u,R,y,z,E,W,J,B=new THREE.Rectangle,U=new THREE.Rectangle,X=new THREE.Rectangle,S=false,P=new THREE.Color,Z=new THREE.Color,ia=new THREE.Color,ja=new THREE.Color,La=Math.PI*2,Y=new THREE.Vector3,na,oa,Ca,ba,pa,
-va,la=16;na=document.createElement("canvas");na.width=na.height=2;oa=na.getContext("2d");oa.fillStyle="rgba(0,0,0,1)";oa.fillRect(0,0,2,2);Ca=oa.getImageData(0,0,2,2);ba=Ca.data;pa=document.createElement("canvas");pa.width=pa.height=la;va=pa.getContext("2d");va.translate(-la/2,-la/2);va.scale(la,la);la--;this.domElement=d;this.autoClear=true;this.setSize=function(fa,wa){g=fa;j=wa;n=g/2;m=j/2;d.width=g;d.height=j;B.set(-n,-m,n,m)};this.clear=function(){if(!U.isEmpty()){U.inflate(1);U.minSelf(B);l.clearRect(U.getX(),
-U.getY(),U.getWidth(),U.getHeight());U.empty()}};this.render=function(fa,wa){function Ma(q){var T,K,t,C=q.lights;Z.setRGB(0,0,0);ia.setRGB(0,0,0);ja.setRGB(0,0,0);q=0;for(T=C.length;q<T;q++){K=C[q];t=K.color;if(K instanceof THREE.AmbientLight){Z.r+=t.r;Z.g+=t.g;Z.b+=t.b}else if(K instanceof THREE.DirectionalLight){ia.r+=t.r;ia.g+=t.g;ia.b+=t.b}else if(K instanceof THREE.PointLight){ja.r+=t.r;ja.g+=t.g;ja.b+=t.b}}}function xa(q,T,K,t){var C,V,aa,ca,da=q.lights;q=0;for(C=da.length;q<C;q++){V=da[q];
-aa=V.color;ca=V.intensity;if(V instanceof THREE.DirectionalLight){V=K.dot(V.position)*ca;if(V>0){t.r+=aa.r*V;t.g+=aa.g*V;t.b+=aa.b*V}}else if(V instanceof THREE.PointLight){Y.sub(V.position,T);Y.normalize();V=K.dot(Y)*ca;if(V>0){t.r+=aa.r*V;t.g+=aa.g*V;t.b+=aa.b*V}}}}function Na(q,T,K){if(K.opacity!=0){Da(K.opacity);ya(K.blending);var t,C,V,aa,ca,da;if(K instanceof THREE.ParticleBasicMaterial){if(K.map){aa=K.map;ca=aa.width>>1;da=aa.height>>1;C=T.scale.x*n;V=T.scale.y*m;K=C*ca;t=V*da;X.set(q.x-K,
-q.y-t,q.x+K,q.y+t);if(B.instersects(X)){l.save();l.translate(q.x,q.y);l.rotate(-T.rotation);l.scale(C,-V);l.translate(-ca,-da);l.drawImage(aa,0,0);l.restore()}}}else if(K instanceof THREE.ParticleCircleMaterial){if(S){P.r=Z.r+ia.r+ja.r;P.g=Z.g+ia.g+ja.g;P.b=Z.b+ia.b+ja.b;h.r=K.color.r*P.r;h.g=K.color.g*P.g;h.b=K.color.b*P.b;h.updateStyleString()}else h.__styleString=K.color.__styleString;K=T.scale.x*n;t=T.scale.y*m;X.set(q.x-K,q.y-t,q.x+K,q.y+t);if(B.instersects(X)){C=h.__styleString;if(D!=C)l.fillStyle=
-D=C;l.save();l.translate(q.x,q.y);l.rotate(-T.rotation);l.scale(K,t);l.beginPath();l.arc(0,0,1,0,La,true);l.closePath();l.fill();l.restore()}}}}function Oa(q,T,K,t){if(t.opacity!=0){Da(t.opacity);ya(t.blending);l.beginPath();l.moveTo(q.positionScreen.x,q.positionScreen.y);l.lineTo(T.positionScreen.x,T.positionScreen.y);l.closePath();if(t instanceof THREE.LineBasicMaterial){h.__styleString=t.color.__styleString;q=t.linewidth;if(w!=q)l.lineWidth=w=q;q=h.__styleString;if(F!=q)l.strokeStyle=F=q;l.stroke();
-X.inflate(t.linewidth*2)}}}function Ha(q,T,K,t,C,V){if(C.opacity!=0){Da(C.opacity);ya(C.blending);O=q.positionScreen.x;v=q.positionScreen.y;f=T.positionScreen.x;k=T.positionScreen.y;e=K.positionScreen.x;p=K.positionScreen.y;l.beginPath();l.moveTo(O,v);l.lineTo(f,k);l.lineTo(e,p);l.lineTo(O,v);l.closePath();if(C instanceof THREE.MeshBasicMaterial)if(C.map)C.map.image.loaded&&C.map.mapping instanceof THREE.UVMapping&&qa(O,v,f,k,e,p,C.map.image,t.uvs[0].u,t.uvs[0].v,t.uvs[1].u,t.uvs[1].v,t.uvs[2].u,
-t.uvs[2].v);else if(C.env_map){if(C.env_map.image.loaded)if(C.env_map.mapping instanceof THREE.SphericalReflectionMapping){q=wa.matrix;Y.copy(t.vertexNormalsWorld[0]);R=(Y.x*q.n11+Y.y*q.n12+Y.z*q.n13)*0.5+0.5;y=-(Y.x*q.n21+Y.y*q.n22+Y.z*q.n23)*0.5+0.5;Y.copy(t.vertexNormalsWorld[1]);z=(Y.x*q.n11+Y.y*q.n12+Y.z*q.n13)*0.5+0.5;E=-(Y.x*q.n21+Y.y*q.n22+Y.z*q.n23)*0.5+0.5;Y.copy(t.vertexNormalsWorld[2]);W=(Y.x*q.n11+Y.y*q.n12+Y.z*q.n13)*0.5+0.5;J=-(Y.x*q.n21+Y.y*q.n22+Y.z*q.n23)*0.5+0.5;qa(O,v,f,k,e,p,
-C.env_map.image,R,y,z,E,W,J)}}else C.wireframe?za(C.color.__styleString,C.wireframe_linewidth):Aa(C.color.__styleString);else if(C instanceof THREE.MeshLambertMaterial){if(C.map&&!C.wireframe){C.map.mapping instanceof THREE.UVMapping&&qa(O,v,f,k,e,p,C.map.image,t.uvs[0].u,t.uvs[0].v,t.uvs[1].u,t.uvs[1].v,t.uvs[2].u,t.uvs[2].v);ya(THREE.SubtractiveBlending)}if(S)if(!C.wireframe&&C.shading==THREE.SmoothShading&&t.vertexNormalsWorld.length==3){i.r=s.r=r.r=Z.r;i.g=s.g=r.g=Z.g;i.b=s.b=r.b=Z.b;xa(V,t.v1.positionWorld,
-t.vertexNormalsWorld[0],i);xa(V,t.v2.positionWorld,t.vertexNormalsWorld[1],s);xa(V,t.v3.positionWorld,t.vertexNormalsWorld[2],r);M.r=(s.r+r.r)*0.5;M.g=(s.g+r.g)*0.5;M.b=(s.b+r.b)*0.5;u=Ia(i,s,r,M);qa(O,v,f,k,e,p,u,0,0,1,0,0,1)}else{P.r=Z.r;P.g=Z.g;P.b=Z.b;xa(V,t.centroidWorld,t.normalWorld,P);h.r=C.color.r*P.r;h.g=C.color.g*P.g;h.b=C.color.b*P.b;h.updateStyleString();C.wireframe?za(h.__styleString,C.wireframe_linewidth):Aa(h.__styleString)}else C.wireframe?za(C.color.__styleString,C.wireframe_linewidth):
-Aa(C.color.__styleString)}else if(C instanceof THREE.MeshDepthMaterial){A=C.__2near;H=C.__farPlusNear;Q=C.__farMinusNear;i.r=i.g=i.b=1-A/(H-q.positionScreen.z*Q);s.r=s.g=s.b=1-A/(H-T.positionScreen.z*Q);r.r=r.g=r.b=1-A/(H-K.positionScreen.z*Q);M.r=(s.r+r.r)*0.5;M.g=(s.g+r.g)*0.5;M.b=(s.b+r.b)*0.5;u=Ia(i,s,r,M);qa(O,v,f,k,e,p,u,0,0,1,0,0,1)}else if(C instanceof THREE.MeshNormalMaterial){h.r=Ea(t.normalWorld.x);h.g=Ea(t.normalWorld.y);h.b=Ea(t.normalWorld.z);h.updateStyleString();C.wireframe?za(h.__styleString,
-C.wireframe_linewidth):Aa(h.__styleString)}}}function za(q,T){if(F!=q)l.strokeStyle=F=q;if(w!=T)l.lineWidth=w=T;l.stroke();X.inflate(T*2)}function Aa(q){if(D!=q)l.fillStyle=D=q;l.fill()}function qa(q,T,K,t,C,V,aa,ca,da,ra,ha,sa,ta){var ka,ga;ka=aa.width-1;ga=aa.height-1;ca*=ka;da*=ga;ra*=ka;ha*=ga;sa*=ka;ta*=ga;K-=q;t-=T;C-=q;V-=T;ra-=ca;ha-=da;sa-=ca;ta-=da;ga=1/(ra*ta-sa*ha);ka=(ta*K-ha*C)*ga;ha=(ta*t-ha*V)*ga;K=(ra*C-sa*K)*ga;t=(ra*V-sa*t)*ga;q=q-ka*ca-K*da;T=T-ha*ca-t*da;l.save();l.transform(ka,
-ha,K,t,q,T);l.clip();l.drawImage(aa,0,0);l.restore()}function Da(q){if(o!=q)l.globalAlpha=o=q}function ya(q){if(c!=q){switch(q){case THREE.NormalBlending:l.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:l.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:l.globalCompositeOperation="darker"}c=q}}function Ia(q,T,K,t){ba[0]=I(0,x(255,~~(q.r*255)));ba[1]=I(0,x(255,~~(q.g*255)));ba[2]=I(0,x(255,~~(q.b*255)));ba[4]=I(0,x(255,~~(T.r*255)));ba[5]=I(0,x(255,
-~~(T.g*255)));ba[6]=I(0,x(255,~~(T.b*255)));ba[8]=I(0,x(255,~~(K.r*255)));ba[9]=I(0,x(255,~~(K.g*255)));ba[10]=I(0,x(255,~~(K.b*255)));ba[12]=I(0,x(255,~~(t.r*255)));ba[13]=I(0,x(255,~~(t.g*255)));ba[14]=I(0,x(255,~~(t.b*255)));oa.putImageData(Ca,0,0);va.drawImage(na,0,0);return pa}function Ea(q){return q<0?x((1+q)*0.5,0.5):0.5+x(q*0.5,0.5)}function Fa(q,T){var K=T.x-q.x,t=T.y-q.y,C=1/Math.sqrt(K*K+t*t);K*=C;t*=C;T.x+=K;T.y+=t;q.x-=K;q.y-=t}var Ba,Ja,$,ea,ma,Ga,Ka,ua;l.setTransform(1,0,0,-1,n,m);
-this.autoClear&&this.clear();a=b.projectScene(fa,wa);(S=fa.lights.length>0)&&Ma(fa);Ba=0;for(Ja=a.length;Ba<Ja;Ba++){$=a[Ba];X.empty();if($ instanceof THREE.RenderableParticle){G=$;G.x*=n;G.y*=m;ea=0;for(ma=$.material.length;ea<ma;ea++)Na(G,$,$.material[ea],fa)}else if($ instanceof THREE.RenderableLine){G=$.v1;L=$.v2;G.positionScreen.x*=n;G.positionScreen.y*=m;L.positionScreen.x*=n;L.positionScreen.y*=m;X.addPoint(G.positionScreen.x,G.positionScreen.y);X.addPoint(L.positionScreen.x,L.positionScreen.y);
-if(B.instersects(X)){ea=0;for(ma=$.material.length;ea<ma;)Oa(G,L,$,$.material[ea++],fa)}}else if($ instanceof THREE.RenderableFace3){G=$.v1;L=$.v2;N=$.v3;G.positionScreen.x*=n;G.positionScreen.y*=m;L.positionScreen.x*=n;L.positionScreen.y*=m;N.positionScreen.x*=n;N.positionScreen.y*=m;if($.overdraw){Fa(G.positionScreen,L.positionScreen);Fa(L.positionScreen,N.positionScreen);Fa(N.positionScreen,G.positionScreen)}X.addPoint(G.positionScreen.x,G.positionScreen.y);X.addPoint(L.positionScreen.x,L.positionScreen.y);
-X.addPoint(N.positionScreen.x,N.positionScreen.y);if(B.instersects(X)){ea=0;for(ma=$.meshMaterial.length;ea<ma;){ua=$.meshMaterial[ea++];if(ua instanceof THREE.MeshFaceMaterial){Ga=0;for(Ka=$.faceMaterial.length;Ga<Ka;)(ua=$.faceMaterial[Ga++])&&Ha(G,L,N,$,ua,fa)}else Ha(G,L,N,$,ua,fa)}}}U.addRectangle(X)}l.setTransform(1,0,0,1,0,0)}};
-THREE.SVGRenderer=function(){function a(y,z,E){var W,J,B,U;W=0;for(J=y.lights.length;W<J;W++){B=y.lights[W];if(B instanceof THREE.DirectionalLight){U=z.normalWorld.dot(B.position)*B.intensity;if(U>0){E.r+=B.color.r*U;E.g+=B.color.g*U;E.b+=B.color.b*U}}else if(B instanceof THREE.PointLight){i.sub(B.position,z.centroidWorld);i.normalize();U=z.normalWorld.dot(i)*B.intensity;if(U>0){E.r+=B.color.r*U;E.g+=B.color.g*U;E.b+=B.color.b*U}}}}function b(y,z,E,W,J,B){A=g(H++);A.setAttribute("d","M "+y.positionScreen.x+
-" "+y.positionScreen.y+" L "+z.positionScreen.x+" "+z.positionScreen.y+" L "+E.positionScreen.x+","+E.positionScreen.y+"z");if(J instanceof THREE.MeshBasicMaterial)v.__styleString=J.color.__styleString;else if(J instanceof THREE.MeshLambertMaterial)if(O){f.r=k.r;f.g=k.g;f.b=k.b;a(B,W,f);v.r=J.color.r*f.r;v.g=J.color.g*f.g;v.b=J.color.b*f.b;v.updateStyleString()}else v.__styleString=J.color.__styleString;else if(J instanceof THREE.MeshDepthMaterial){h=1-J.__2near/(J.__farPlusNear-W.z*J.__farMinusNear);
-v.setRGB(h,h,h)}else J instanceof THREE.MeshNormalMaterial&&v.setRGB(j(W.normalWorld.x),j(W.normalWorld.y),j(W.normalWorld.z));J.wireframe?A.setAttribute("style","fill: none; stroke: "+v.__styleString+"; stroke-width: "+J.wireframe_linewidth+"; stroke-opacity: "+J.opacity+"; stroke-linecap: "+J.wireframe_linecap+"; stroke-linejoin: "+J.wireframe_linejoin):A.setAttribute("style","fill: "+v.__styleString+"; fill-opacity: "+J.opacity);l.appendChild(A)}function d(y,z,E,W,J,B,U){A=g(H++);A.setAttribute("d",
-"M "+y.positionScreen.x+" "+y.positionScreen.y+" L "+z.positionScreen.x+" "+z.positionScreen.y+" L "+E.positionScreen.x+","+E.positionScreen.y+" L "+W.positionScreen.x+","+W.positionScreen.y+"z");if(B instanceof THREE.MeshBasicMaterial)v.__styleString=B.color.__styleString;else if(B instanceof THREE.MeshLambertMaterial)if(O){f.r=k.r;f.g=k.g;f.b=k.b;a(U,J,f);v.r=B.color.r*f.r;v.g=B.color.g*f.g;v.b=B.color.b*f.b;v.updateStyleString()}else v.__styleString=B.color.__styleString;else if(B instanceof THREE.MeshDepthMaterial){h=
-1-B.__2near/(B.__farPlusNear-J.z*B.__farMinusNear);v.setRGB(h,h,h)}else B instanceof THREE.MeshNormalMaterial&&v.setRGB(j(J.normalWorld.x),j(J.normalWorld.y),j(J.normalWorld.z));B.wireframe?A.setAttribute("style","fill: none; stroke: "+v.__styleString+"; stroke-width: "+B.wireframe_linewidth+"; stroke-opacity: "+B.opacity+"; stroke-linecap: "+B.wireframe_linecap+"; stroke-linejoin: "+B.wireframe_linejoin):A.setAttribute("style","fill: "+v.__styleString+"; fill-opacity: "+B.opacity);l.appendChild(A)}
-function g(y){if(s[y]==null){s[y]=document.createElementNS("http://www.w3.org/2000/svg","path");R==0&&s[y].setAttribute("shape-rendering","crispEdges");return s[y]}return s[y]}function j(y){return y<0?Math.min((1+y)*0.5,0.5):0.5+Math.min(y*0.5,0.5)}var n=null,m=new THREE.Projector,l=document.createElementNS("http://www.w3.org/2000/svg","svg"),o,c,F,D,w,x,I,G,L=new THREE.Rectangle,N=new THREE.Rectangle,O=false,v=new THREE.Color(16777215),f=new THREE.Color(16777215),k=new THREE.Color(0),e=new THREE.Color(0),
-p=new THREE.Color(0),h,i=new THREE.Vector3,s=[],r=[],M=[],A,H,Q,u,R=1;this.domElement=l;this.autoClear=true;this.setQuality=function(y){switch(y){case "high":R=1;break;case "low":R=0}};this.setSize=function(y,z){o=y;c=z;F=o/2;D=c/2;l.setAttribute("viewBox",-F+" "+-D+" "+o+" "+c);l.setAttribute("width",o);l.setAttribute("height",c);L.set(-F,-D,F,D)};this.clear=function(){for(;l.childNodes.length>0;)l.removeChild(l.childNodes[0])};this.render=function(y,z){var E,W,J,B,U,X,S,P;this.autoClear&&this.clear();
-n=m.projectScene(y,z);u=Q=H=0;if(O=y.lights.length>0){S=y.lights;k.setRGB(0,0,0);e.setRGB(0,0,0);p.setRGB(0,0,0);E=0;for(W=S.length;E<W;E++){J=S[E];B=J.color;if(J instanceof THREE.AmbientLight){k.r+=B.r;k.g+=B.g;k.b+=B.b}else if(J instanceof THREE.DirectionalLight){e.r+=B.r;e.g+=B.g;e.b+=B.b}else if(J instanceof THREE.PointLight){p.r+=B.r;p.g+=B.g;p.b+=B.b}}}E=0;for(W=n.length;E<W;E++){S=n[E];N.empty();if(S instanceof THREE.RenderableParticle){w=S;w.x*=F;w.y*=-D;J=0;for(B=S.material.length;J<B;J++)if(P=
-S.material[J]){U=w;X=S;P=P;var Z=Q++;if(r[Z]==null){r[Z]=document.createElementNS("http://www.w3.org/2000/svg","circle");R==0&&r[Z].setAttribute("shape-rendering","crispEdges")}A=r[Z];A.setAttribute("cx",U.x);A.setAttribute("cy",U.y);A.setAttribute("r",X.scale.x*F);if(P instanceof THREE.ParticleCircleMaterial){if(O){f.r=k.r+e.r+p.r;f.g=k.g+e.g+p.g;f.b=k.b+e.b+p.b;v.r=P.color.r*f.r;v.g=P.color.g*f.g;v.b=P.color.b*f.b;v.updateStyleString()}else v=P.color;A.setAttribute("style","fill: "+v.__styleString)}l.appendChild(A)}}else if(S instanceof
-THREE.RenderableLine){w=S.v1;x=S.v2;w.positionScreen.x*=F;w.positionScreen.y*=-D;x.positionScreen.x*=F;x.positionScreen.y*=-D;N.addPoint(w.positionScreen.x,w.positionScreen.y);N.addPoint(x.positionScreen.x,x.positionScreen.y);if(L.instersects(N)){J=0;for(B=S.material.length;J<B;)if(P=S.material[J++]){U=w;X=x;P=P;Z=u++;if(M[Z]==null){M[Z]=document.createElementNS("http://www.w3.org/2000/svg","line");R==0&&M[Z].setAttribute("shape-rendering","crispEdges")}A=M[Z];A.setAttribute("x1",U.positionScreen.x);
-A.setAttribute("y1",U.positionScreen.y);A.setAttribute("x2",X.positionScreen.x);A.setAttribute("y2",X.positionScreen.y);if(P instanceof THREE.LineBasicMaterial){v.__styleString=P.color.__styleString;A.setAttribute("style","fill: none; stroke: "+v.__styleString+"; stroke-width: "+P.linewidth+"; stroke-opacity: "+P.opacity+"; stroke-linecap: "+P.linecap+"; stroke-linejoin: "+P.linejoin);l.appendChild(A)}}}}else if(S instanceof THREE.RenderableFace3){w=S.v1;x=S.v2;I=S.v3;w.positionScreen.x*=F;w.positionScreen.y*=
--D;x.positionScreen.x*=F;x.positionScreen.y*=-D;I.positionScreen.x*=F;I.positionScreen.y*=-D;N.addPoint(w.positionScreen.x,w.positionScreen.y);N.addPoint(x.positionScreen.x,x.positionScreen.y);N.addPoint(I.positionScreen.x,I.positionScreen.y);if(L.instersects(N)){J=0;for(B=S.meshMaterial.length;J<B;){P=S.meshMaterial[J++];if(P instanceof THREE.MeshFaceMaterial){U=0;for(X=S.faceMaterial.length;U<X;)(P=S.faceMaterial[U++])&&b(w,x,I,S,P,y)}else P&&b(w,x,I,S,P,y)}}}else if(S instanceof THREE.RenderableFace4){w=
-S.v1;x=S.v2;I=S.v3;G=S.v4;w.positionScreen.x*=F;w.positionScreen.y*=-D;x.positionScreen.x*=F;x.positionScreen.y*=-D;I.positionScreen.x*=F;I.positionScreen.y*=-D;G.positionScreen.x*=F;G.positionScreen.y*=-D;N.addPoint(w.positionScreen.x,w.positionScreen.y);N.addPoint(x.positionScreen.x,x.positionScreen.y);N.addPoint(I.positionScreen.x,I.positionScreen.y);N.addPoint(G.positionScreen.x,G.positionScreen.y);if(L.instersects(N)){J=0;for(B=S.meshMaterial.length;J<B;){P=S.meshMaterial[J++];if(P instanceof
-THREE.MeshFaceMaterial){U=0;for(X=S.faceMaterial.length;U<X;)(P=S.faceMaterial[U++])&&d(w,x,I,G,S,P,y)}else P&&d(w,x,I,G,S,P,y)}}}}}};
-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\nuniform mat4 viewMatrix;\n"+f));c.attachShader(e,m("vertex","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"+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.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 g(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,l(f.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,l(f.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,l(f.mag_filter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,l(f.min_filter));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,p,h;e=0;for(p=k.length;e<p;e++){h=k[e];f.uniforms[h]=c.getUniformLocation(f,h)}}function n(f,k){var e,p,h;e=0;for(p=k.length;e<p;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 l(f){switch(f){case THREE.RepeatWrapping:return c.REPEAT;case THREE.ClampToEdgeWrapping:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return c.MIRRORED_REPEAT;case THREE.NearestFilter:return c.NEAREST;case THREE.NearestMipMapNearestFilter:return c.NEAREST_MIPMAP_NEAREST;case THREE.NearestMipMapLinearFilter:return c.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return c.LINEAR;case THREE.LinearMipMapNearestFilter:return c.LINEAR_MIPMAP_NEAREST;
-case THREE.LinearMipMapLinearFilter:return c.LINEAR_MIPMAP_LINEAR}return 0}var o=document.createElement("canvas"),c,F,D,w=new THREE.Matrix4,x,I=new Float32Array(16),G=new Float32Array(16),L=new Float32Array(16),N=new Float32Array(9),O=new Float32Array(16);a=function(f,k){if(f){var e,p,h,i=pointLights=maxDirLights=maxPointLights=0;e=0;for(p=f.lights.length;e<p;e++){h=f.lights[e];h instanceof THREE.DirectionalLight&&i++;h instanceof THREE.PointLight&&pointLights++}if(pointLights+i<=k){maxDirLights=
-i;maxPointLights=pointLights}else{maxDirLights=Math.ceil(k*i/(pointLights+i));maxPointLights=k-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:k-1}}(a,4);this.domElement=o;this.autoClear=true;try{c=o.getContext("experimental-webgl",{antialias:true})}catch(v){}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);F=D=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 ];":"","varying 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 );":
+THREE.Projector=function(){function a(M,u){var e=0,k=1,g=M.z+M.w,q=u.z+u.w,h=-M.z+M.w,i=-u.z+u.w;if(g>=0&&q>=0&&h>=0&&i>=0)return true;else if(g<0&&q<0||h<0&&i<0)return false;else{if(g<0)e=Math.max(e,g/(g-q));else if(q<0)k=Math.min(k,g/(g-q));if(h<0)e=Math.max(e,h/(h-i));else if(i<0)k=Math.min(k,h/(h-i));if(k<e)return false;else{M.lerpSelf(u,e);u.lerpSelf(M,1-k);return true}}}var b=null,d,f,j,m=[],n,l,o=[],c,E,C=[],x=new THREE.Vector4,z=new THREE.Matrix4,H=new THREE.Matrix4,G=new THREE.Vector4,J=
+new THREE.Vector4,L;this.projectScene=function(M,u){var e,k,g,q,h,i,r,p,D,w,I,S,t,O,B,P,Q;b=[];j=l=E=0;u.autoUpdateMatrix&&u.updateMatrix();z.multiply(u.projectionMatrix,u.matrix);r=M.objects;e=0;for(k=r.length;e<k;e++){p=r[e];p.autoUpdateMatrix&&p.updateMatrix();D=p.matrix;w=p.rotationMatrix;I=p.material;S=p.overdraw;if(p instanceof THREE.Mesh){t=p.geometry.vertices;g=0;for(q=t.length;g<q;g++){O=t[g];O.positionWorld.copy(O.position);D.multiplyVector3(O.positionWorld);B=O.positionScreen;B.copy(O.positionWorld);
+z.multiplyVector4(B);B.multiplyScalar(1/B.w);O.__visible=B.z>0&&B.z<1}O=p.geometry.faces;g=0;for(q=O.length;g<q;g++){B=O[g];if(B instanceof THREE.Face3){h=t[B.a];i=t[B.b];P=t[B.c];if(h.__visible&&i.__visible&&P.__visible)if(p.doubleSided||p.flipSided!=(P.positionScreen.x-h.positionScreen.x)*(i.positionScreen.y-h.positionScreen.y)-(P.positionScreen.y-h.positionScreen.y)*(i.positionScreen.x-h.positionScreen.x)<0){d=m[j]=m[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(h.positionWorld);d.v2.positionWorld.copy(i.positionWorld);
+d.v3.positionWorld.copy(P.positionWorld);d.v1.positionScreen.copy(h.positionScreen);d.v2.positionScreen.copy(i.positionScreen);d.v3.positionScreen.copy(P.positionScreen);d.normalWorld.copy(B.normal);w.multiplyVector3(d.normalWorld);d.centroidWorld.copy(B.centroid);D.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);z.multiplyVector3(d.centroidScreen);P=B.vertexNormals;L=d.vertexNormalsWorld;h=0;for(i=P.length;h<i;h++){Q=L[h]=L[h]||new THREE.Vector3;Q.copy(P[h]);w.multiplyVector3(Q)}d.z=
+d.centroidScreen.z;d.meshMaterial=I;d.faceMaterial=B.material;d.overdraw=S;if(p.geometry.uvs[g]){d.uvs[0]=p.geometry.uvs[g][0];d.uvs[1]=p.geometry.uvs[g][1];d.uvs[2]=p.geometry.uvs[g][2]}b.push(d);j++}}else if(B instanceof THREE.Face4){h=t[B.a];i=t[B.b];P=t[B.c];Q=t[B.d];if(h.__visible&&i.__visible&&P.__visible&&Q.__visible)if(p.doubleSided||p.flipSided!=((Q.positionScreen.x-h.positionScreen.x)*(i.positionScreen.y-h.positionScreen.y)-(Q.positionScreen.y-h.positionScreen.y)*(i.positionScreen.x-h.positionScreen.x)<
+0||(i.positionScreen.x-P.positionScreen.x)*(Q.positionScreen.y-P.positionScreen.y)-(i.positionScreen.y-P.positionScreen.y)*(Q.positionScreen.x-P.positionScreen.x)<0)){d=m[j]=m[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(h.positionWorld);d.v2.positionWorld.copy(i.positionWorld);d.v3.positionWorld.copy(Q.positionWorld);d.v1.positionScreen.copy(h.positionScreen);d.v2.positionScreen.copy(i.positionScreen);d.v3.positionScreen.copy(Q.positionScreen);d.normalWorld.copy(B.normal);w.multiplyVector3(d.normalWorld);
+d.centroidWorld.copy(B.centroid);D.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);z.multiplyVector3(d.centroidScreen);d.z=d.centroidScreen.z;d.meshMaterial=I;d.faceMaterial=B.material;d.overdraw=S;if(p.geometry.uvs[g]){d.uvs[0]=p.geometry.uvs[g][0];d.uvs[1]=p.geometry.uvs[g][1];d.uvs[2]=p.geometry.uvs[g][3]}b.push(d);j++;f=m[j]=m[j]||new THREE.RenderableFace3;f.v1.positionWorld.copy(i.positionWorld);f.v2.positionWorld.copy(P.positionWorld);f.v3.positionWorld.copy(Q.positionWorld);
+f.v1.positionScreen.copy(i.positionScreen);f.v2.positionScreen.copy(P.positionScreen);f.v3.positionScreen.copy(Q.positionScreen);f.normalWorld.copy(d.normalWorld);f.centroidWorld.copy(d.centroidWorld);f.centroidScreen.copy(d.centroidScreen);f.z=f.centroidScreen.z;f.meshMaterial=I;f.faceMaterial=B.material;f.overdraw=S;if(p.geometry.uvs[g]){f.uvs[0]=p.geometry.uvs[g][1];f.uvs[1]=p.geometry.uvs[g][2];f.uvs[2]=p.geometry.uvs[g][3]}b.push(f);j++}}}}else if(p instanceof THREE.Line){H.multiply(z,D);t=p.geometry.vertices;
+O=t[0];O.positionScreen.copy(O.position);H.multiplyVector4(O.positionScreen);g=1;for(q=t.length;g<q;g++){h=t[g];h.positionScreen.copy(h.position);H.multiplyVector4(h.positionScreen);i=t[g-1];G.copy(h.positionScreen);J.copy(i.positionScreen);if(a(G,J)){G.multiplyScalar(1/G.w);J.multiplyScalar(1/J.w);n=o[l]=o[l]||new THREE.RenderableLine;n.v1.positionScreen.copy(G);n.v2.positionScreen.copy(J);n.z=Math.max(G.z,J.z);n.material=p.material;b.push(n);l++}}}else if(p instanceof THREE.Particle){x.set(p.position.x,
+p.position.y,p.position.z,1);z.multiplyVector4(x);x.z/=x.w;if(x.z>0&&x.z<1){c=C[E]=C[E]||new THREE.RenderableParticle;c.x=x.x/x.w;c.y=x.y/x.w;c.z=x.z;c.rotation=p.rotation.z;c.scale.x=p.scale.x*Math.abs(c.x-(x.x+u.projectionMatrix.n11)/(x.w+u.projectionMatrix.n14));c.scale.y=p.scale.y*Math.abs(c.y-(x.y+u.projectionMatrix.n22)/(x.w+u.projectionMatrix.n24));c.material=p.material;b.push(c);E++}}}b.sort(function(K,y){return y.z-K.z});return b};this.unprojectVector=function(M,u){var e=new THREE.Matrix4;
+e.multiply(THREE.Matrix4.makeInvert(u.matrix),THREE.Matrix4.makeInvert(u.projectionMatrix));e.multiplyVector3(M);return M}};
+THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,d,f,j,m;this.domElement=document.createElement("div");this.setSize=function(n,l){d=n;f=l;j=d/2;m=f/2};this.render=function(n,l){var o,c,E,C,x,z,H,G;a=b.projectScene(n,l);o=0;for(c=a.length;o<c;o++){x=a[o];if(x instanceof THREE.RenderableParticle){H=x.x*j+j;G=x.y*m+m;E=0;for(C=x.material.length;E<C;E++){z=x.material[E];if(z instanceof THREE.ParticleDOMMaterial){z=z.domElement;z.style.left=H+"px";z.style.top=G+"px"}}}}}};
+THREE.CanvasRenderer=function(){var a=null,b=new THREE.Projector,d=document.createElement("canvas"),f,j,m,n,l=d.getContext("2d"),o=1,c=0,E=null,C=null,x=1,z=Math.min,H=Math.max,G,J,L,M,u,e,k,g,q,h=new THREE.Color,i=new THREE.Color,r=new THREE.Color,p=new THREE.Color,D=new THREE.Color,w,I,S,t,O,B,P,Q,K,y,A=new THREE.Rectangle,V=new THREE.Rectangle,X=new THREE.Rectangle,T=false,R=new THREE.Color,Z=new THREE.Color,ia=new THREE.Color,ja=new THREE.Color,La=Math.PI*2,Y=new THREE.Vector3,na,oa,Ca,ba,pa,
+va,la=16;na=document.createElement("canvas");na.width=na.height=2;oa=na.getContext("2d");oa.fillStyle="rgba(0,0,0,1)";oa.fillRect(0,0,2,2);Ca=oa.getImageData(0,0,2,2);ba=Ca.data;pa=document.createElement("canvas");pa.width=pa.height=la;va=pa.getContext("2d");va.translate(-la/2,-la/2);va.scale(la,la);la--;this.domElement=d;this.autoClear=true;this.setSize=function(fa,wa){f=fa;j=wa;m=f/2;n=j/2;d.width=f;d.height=j;A.set(-m,-n,m,n)};this.clear=function(){if(!V.isEmpty()){V.inflate(1);V.minSelf(A);l.clearRect(V.getX(),
+V.getY(),V.getWidth(),V.getHeight());V.empty()}};this.render=function(fa,wa){function Ma(s){var U,N,v,F=s.lights;Z.setRGB(0,0,0);ia.setRGB(0,0,0);ja.setRGB(0,0,0);s=0;for(U=F.length;s<U;s++){N=F[s];v=N.color;if(N instanceof THREE.AmbientLight){Z.r+=v.r;Z.g+=v.g;Z.b+=v.b}else if(N instanceof THREE.DirectionalLight){ia.r+=v.r;ia.g+=v.g;ia.b+=v.b}else if(N instanceof THREE.PointLight){ja.r+=v.r;ja.g+=v.g;ja.b+=v.b}}}function xa(s,U,N,v){var F,W,aa,ca,da=s.lights;s=0;for(F=da.length;s<F;s++){W=da[s];
+aa=W.color;ca=W.intensity;if(W instanceof THREE.DirectionalLight){W=N.dot(W.position)*ca;if(W>0){v.r+=aa.r*W;v.g+=aa.g*W;v.b+=aa.b*W}}else if(W instanceof THREE.PointLight){Y.sub(W.position,U);Y.normalize();W=N.dot(Y)*ca;if(W>0){v.r+=aa.r*W;v.g+=aa.g*W;v.b+=aa.b*W}}}}function Na(s,U,N){if(N.opacity!=0){Da(N.opacity);ya(N.blending);var v,F,W,aa,ca,da;if(N instanceof THREE.ParticleBasicMaterial){if(N.map){aa=N.map;ca=aa.width>>1;da=aa.height>>1;F=U.scale.x*m;W=U.scale.y*n;N=F*ca;v=W*da;X.set(s.x-N,
+s.y-v,s.x+N,s.y+v);if(A.instersects(X)){l.save();l.translate(s.x,s.y);l.rotate(-U.rotation);l.scale(F,-W);l.translate(-ca,-da);l.drawImage(aa,0,0);l.restore()}}}else if(N instanceof THREE.ParticleCircleMaterial){if(T){R.r=Z.r+ia.r+ja.r;R.g=Z.g+ia.g+ja.g;R.b=Z.b+ia.b+ja.b;h.r=N.color.r*R.r;h.g=N.color.g*R.g;h.b=N.color.b*R.b;h.updateStyleString()}else h.__styleString=N.color.__styleString;N=U.scale.x*m;v=U.scale.y*n;X.set(s.x-N,s.y-v,s.x+N,s.y+v);if(A.instersects(X)){F=h.__styleString;if(C!=F)l.fillStyle=
+C=F;l.save();l.translate(s.x,s.y);l.rotate(-U.rotation);l.scale(N,v);l.beginPath();l.arc(0,0,1,0,La,true);l.closePath();l.fill();l.restore()}}}}function Oa(s,U,N,v){if(v.opacity!=0){Da(v.opacity);ya(v.blending);l.beginPath();l.moveTo(s.positionScreen.x,s.positionScreen.y);l.lineTo(U.positionScreen.x,U.positionScreen.y);l.closePath();if(v instanceof THREE.LineBasicMaterial){h.__styleString=v.color.__styleString;s=v.linewidth;if(x!=s)l.lineWidth=x=s;s=h.__styleString;if(E!=s)l.strokeStyle=E=s;l.stroke();
+X.inflate(v.linewidth*2)}}}function Ha(s,U,N,v,F,W){if(F.opacity!=0){Da(F.opacity);ya(F.blending);M=s.positionScreen.x;u=s.positionScreen.y;e=U.positionScreen.x;k=U.positionScreen.y;g=N.positionScreen.x;q=N.positionScreen.y;l.beginPath();l.moveTo(M,u);l.lineTo(e,k);l.lineTo(g,q);l.lineTo(M,u);l.closePath();if(F instanceof THREE.MeshBasicMaterial)if(F.map)F.map.image.loaded&&F.map.mapping instanceof THREE.UVMapping&&qa(M,u,e,k,g,q,F.map.image,v.uvs[0].u,v.uvs[0].v,v.uvs[1].u,v.uvs[1].v,v.uvs[2].u,
+v.uvs[2].v);else if(F.env_map){if(F.env_map.image.loaded)if(F.env_map.mapping instanceof THREE.SphericalReflectionMapping){s=wa.matrix;Y.copy(v.vertexNormalsWorld[0]);O=(Y.x*s.n11+Y.y*s.n12+Y.z*s.n13)*0.5+0.5;B=-(Y.x*s.n21+Y.y*s.n22+Y.z*s.n23)*0.5+0.5;Y.copy(v.vertexNormalsWorld[1]);P=(Y.x*s.n11+Y.y*s.n12+Y.z*s.n13)*0.5+0.5;Q=-(Y.x*s.n21+Y.y*s.n22+Y.z*s.n23)*0.5+0.5;Y.copy(v.vertexNormalsWorld[2]);K=(Y.x*s.n11+Y.y*s.n12+Y.z*s.n13)*0.5+0.5;y=-(Y.x*s.n21+Y.y*s.n22+Y.z*s.n23)*0.5+0.5;qa(M,u,e,k,g,q,
+F.env_map.image,O,B,P,Q,K,y)}}else F.wireframe?za(F.color.__styleString,F.wireframe_linewidth):Aa(F.color.__styleString);else if(F instanceof THREE.MeshLambertMaterial){if(F.map&&!F.wireframe){F.map.mapping instanceof THREE.UVMapping&&qa(M,u,e,k,g,q,F.map.image,v.uvs[0].u,v.uvs[0].v,v.uvs[1].u,v.uvs[1].v,v.uvs[2].u,v.uvs[2].v);ya(THREE.SubtractiveBlending)}if(T)if(!F.wireframe&&F.shading==THREE.SmoothShading&&v.vertexNormalsWorld.length==3){i.r=r.r=p.r=Z.r;i.g=r.g=p.g=Z.g;i.b=r.b=p.b=Z.b;xa(W,v.v1.positionWorld,
+v.vertexNormalsWorld[0],i);xa(W,v.v2.positionWorld,v.vertexNormalsWorld[1],r);xa(W,v.v3.positionWorld,v.vertexNormalsWorld[2],p);D.r=(r.r+p.r)*0.5;D.g=(r.g+p.g)*0.5;D.b=(r.b+p.b)*0.5;t=Ia(i,r,p,D);qa(M,u,e,k,g,q,t,0,0,1,0,0,1)}else{R.r=Z.r;R.g=Z.g;R.b=Z.b;xa(W,v.centroidWorld,v.normalWorld,R);h.r=F.color.r*R.r;h.g=F.color.g*R.g;h.b=F.color.b*R.b;h.updateStyleString();F.wireframe?za(h.__styleString,F.wireframe_linewidth):Aa(h.__styleString)}else F.wireframe?za(F.color.__styleString,F.wireframe_linewidth):
+Aa(F.color.__styleString)}else if(F instanceof THREE.MeshDepthMaterial){w=F.__2near;I=F.__farPlusNear;S=F.__farMinusNear;i.r=i.g=i.b=1-w/(I-s.positionScreen.z*S);r.r=r.g=r.b=1-w/(I-U.positionScreen.z*S);p.r=p.g=p.b=1-w/(I-N.positionScreen.z*S);D.r=(r.r+p.r)*0.5;D.g=(r.g+p.g)*0.5;D.b=(r.b+p.b)*0.5;t=Ia(i,r,p,D);qa(M,u,e,k,g,q,t,0,0,1,0,0,1)}else if(F instanceof THREE.MeshNormalMaterial){h.r=Ea(v.normalWorld.x);h.g=Ea(v.normalWorld.y);h.b=Ea(v.normalWorld.z);h.updateStyleString();F.wireframe?za(h.__styleString,
+F.wireframe_linewidth):Aa(h.__styleString)}}}function za(s,U){if(E!=s)l.strokeStyle=E=s;if(x!=U)l.lineWidth=x=U;l.stroke();X.inflate(U*2)}function Aa(s){if(C!=s)l.fillStyle=C=s;l.fill()}function qa(s,U,N,v,F,W,aa,ca,da,ra,ha,sa,ta){var ka,ga;ka=aa.width-1;ga=aa.height-1;ca*=ka;da*=ga;ra*=ka;ha*=ga;sa*=ka;ta*=ga;N-=s;v-=U;F-=s;W-=U;ra-=ca;ha-=da;sa-=ca;ta-=da;ga=1/(ra*ta-sa*ha);ka=(ta*N-ha*F)*ga;ha=(ta*v-ha*W)*ga;N=(ra*F-sa*N)*ga;v=(ra*W-sa*v)*ga;s=s-ka*ca-N*da;U=U-ha*ca-v*da;l.save();l.transform(ka,
+ha,N,v,s,U);l.clip();l.drawImage(aa,0,0);l.restore()}function Da(s){if(o!=s)l.globalAlpha=o=s}function ya(s){if(c!=s){switch(s){case THREE.NormalBlending:l.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:l.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:l.globalCompositeOperation="darker"}c=s}}function Ia(s,U,N,v){ba[0]=H(0,z(255,~~(s.r*255)));ba[1]=H(0,z(255,~~(s.g*255)));ba[2]=H(0,z(255,~~(s.b*255)));ba[4]=H(0,z(255,~~(U.r*255)));ba[5]=H(0,z(255,
+~~(U.g*255)));ba[6]=H(0,z(255,~~(U.b*255)));ba[8]=H(0,z(255,~~(N.r*255)));ba[9]=H(0,z(255,~~(N.g*255)));ba[10]=H(0,z(255,~~(N.b*255)));ba[12]=H(0,z(255,~~(v.r*255)));ba[13]=H(0,z(255,~~(v.g*255)));ba[14]=H(0,z(255,~~(v.b*255)));oa.putImageData(Ca,0,0);va.drawImage(na,0,0);return pa}function Ea(s){return s<0?z((1+s)*0.5,0.5):0.5+z(s*0.5,0.5)}function Fa(s,U){var N=U.x-s.x,v=U.y-s.y,F=1/Math.sqrt(N*N+v*v);N*=F;v*=F;U.x+=N;U.y+=v;s.x-=N;s.y-=v}var Ba,Ja,$,ea,ma,Ga,Ka,ua;l.setTransform(1,0,0,-1,m,n);
+this.autoClear&&this.clear();a=b.projectScene(fa,wa);(T=fa.lights.length>0)&&Ma(fa);Ba=0;for(Ja=a.length;Ba<Ja;Ba++){$=a[Ba];X.empty();if($ instanceof THREE.RenderableParticle){G=$;G.x*=m;G.y*=n;ea=0;for(ma=$.material.length;ea<ma;ea++)Na(G,$,$.material[ea],fa)}else if($ instanceof THREE.RenderableLine){G=$.v1;J=$.v2;G.positionScreen.x*=m;G.positionScreen.y*=n;J.positionScreen.x*=m;J.positionScreen.y*=n;X.addPoint(G.positionScreen.x,G.positionScreen.y);X.addPoint(J.positionScreen.x,J.positionScreen.y);
+if(A.instersects(X)){ea=0;for(ma=$.material.length;ea<ma;)Oa(G,J,$,$.material[ea++],fa)}}else if($ instanceof THREE.RenderableFace3){G=$.v1;J=$.v2;L=$.v3;G.positionScreen.x*=m;G.positionScreen.y*=n;J.positionScreen.x*=m;J.positionScreen.y*=n;L.positionScreen.x*=m;L.positionScreen.y*=n;if($.overdraw){Fa(G.positionScreen,J.positionScreen);Fa(J.positionScreen,L.positionScreen);Fa(L.positionScreen,G.positionScreen)}X.addPoint(G.positionScreen.x,G.positionScreen.y);X.addPoint(J.positionScreen.x,J.positionScreen.y);
+X.addPoint(L.positionScreen.x,L.positionScreen.y);if(A.instersects(X)){ea=0;for(ma=$.meshMaterial.length;ea<ma;){ua=$.meshMaterial[ea++];if(ua instanceof THREE.MeshFaceMaterial){Ga=0;for(Ka=$.faceMaterial.length;Ga<Ka;)(ua=$.faceMaterial[Ga++])&&Ha(G,J,L,$,ua,fa)}else Ha(G,J,L,$,ua,fa)}}}V.addRectangle(X)}l.setTransform(1,0,0,1,0,0)}};
+THREE.SVGRenderer=function(){function a(B,P,Q){var K,y,A,V;K=0;for(y=B.lights.length;K<y;K++){A=B.lights[K];if(A instanceof THREE.DirectionalLight){V=P.normalWorld.dot(A.position)*A.intensity;if(V>0){Q.r+=A.color.r*V;Q.g+=A.color.g*V;Q.b+=A.color.b*V}}else if(A instanceof THREE.PointLight){i.sub(A.position,P.centroidWorld);i.normalize();V=P.normalWorld.dot(i)*A.intensity;if(V>0){Q.r+=A.color.r*V;Q.g+=A.color.g*V;Q.b+=A.color.b*V}}}}function b(B,P,Q,K,y,A){w=f(I++);w.setAttribute("d","M "+B.positionScreen.x+
+" "+B.positionScreen.y+" L "+P.positionScreen.x+" "+P.positionScreen.y+" L "+Q.positionScreen.x+","+Q.positionScreen.y+"z");if(y instanceof THREE.MeshBasicMaterial)u.__styleString=y.color.__styleString;else if(y instanceof THREE.MeshLambertMaterial)if(M){e.r=k.r;e.g=k.g;e.b=k.b;a(A,K,e);u.r=y.color.r*e.r;u.g=y.color.g*e.g;u.b=y.color.b*e.b;u.updateStyleString()}else u.__styleString=y.color.__styleString;else if(y instanceof THREE.MeshDepthMaterial){h=1-y.__2near/(y.__farPlusNear-K.z*y.__farMinusNear);
+u.setRGB(h,h,h)}else y instanceof THREE.MeshNormalMaterial&&u.setRGB(j(K.normalWorld.x),j(K.normalWorld.y),j(K.normalWorld.z));y.wireframe?w.setAttribute("style","fill: none; stroke: "+u.__styleString+"; stroke-width: "+y.wireframe_linewidth+"; stroke-opacity: "+y.opacity+"; stroke-linecap: "+y.wireframe_linecap+"; stroke-linejoin: "+y.wireframe_linejoin):w.setAttribute("style","fill: "+u.__styleString+"; fill-opacity: "+y.opacity);l.appendChild(w)}function d(B,P,Q,K,y,A,V){w=f(I++);w.setAttribute("d",
+"M "+B.positionScreen.x+" "+B.positionScreen.y+" L "+P.positionScreen.x+" "+P.positionScreen.y+" L "+Q.positionScreen.x+","+Q.positionScreen.y+" L "+K.positionScreen.x+","+K.positionScreen.y+"z");if(A instanceof THREE.MeshBasicMaterial)u.__styleString=A.color.__styleString;else if(A instanceof THREE.MeshLambertMaterial)if(M){e.r=k.r;e.g=k.g;e.b=k.b;a(V,y,e);u.r=A.color.r*e.r;u.g=A.color.g*e.g;u.b=A.color.b*e.b;u.updateStyleString()}else u.__styleString=A.color.__styleString;else if(A instanceof THREE.MeshDepthMaterial){h=
+1-A.__2near/(A.__farPlusNear-y.z*A.__farMinusNear);u.setRGB(h,h,h)}else A instanceof THREE.MeshNormalMaterial&&u.setRGB(j(y.normalWorld.x),j(y.normalWorld.y),j(y.normalWorld.z));A.wireframe?w.setAttribute("style","fill: none; stroke: "+u.__styleString+"; stroke-width: "+A.wireframe_linewidth+"; stroke-opacity: "+A.opacity+"; stroke-linecap: "+A.wireframe_linecap+"; stroke-linejoin: "+A.wireframe_linejoin):w.setAttribute("style","fill: "+u.__styleString+"; fill-opacity: "+A.opacity);l.appendChild(w)}
+function f(B){if(r[B]==null){r[B]=document.createElementNS("http://www.w3.org/2000/svg","path");O==0&&r[B].setAttribute("shape-rendering","crispEdges");return r[B]}return r[B]}function j(B){return B<0?Math.min((1+B)*0.5,0.5):0.5+Math.min(B*0.5,0.5)}var m=null,n=new THREE.Projector,l=document.createElementNS("http://www.w3.org/2000/svg","svg"),o,c,E,C,x,z,H,G,J=new THREE.Rectangle,L=new THREE.Rectangle,M=false,u=new THREE.Color(16777215),e=new THREE.Color(16777215),k=new THREE.Color(0),g=new THREE.Color(0),
+q=new THREE.Color(0),h,i=new THREE.Vector3,r=[],p=[],D=[],w,I,S,t,O=1;this.domElement=l;this.autoClear=true;this.setQuality=function(B){switch(B){case "high":O=1;break;case "low":O=0}};this.setSize=function(B,P){o=B;c=P;E=o/2;C=c/2;l.setAttribute("viewBox",-E+" "+-C+" "+o+" "+c);l.setAttribute("width",o);l.setAttribute("height",c);J.set(-E,-C,E,C)};this.clear=function(){for(;l.childNodes.length>0;)l.removeChild(l.childNodes[0])};this.render=function(B,P){var Q,K,y,A,V,X,T,R;this.autoClear&&this.clear();
+m=n.projectScene(B,P);t=S=I=0;if(M=B.lights.length>0){T=B.lights;k.setRGB(0,0,0);g.setRGB(0,0,0);q.setRGB(0,0,0);Q=0;for(K=T.length;Q<K;Q++){y=T[Q];A=y.color;if(y instanceof THREE.AmbientLight){k.r+=A.r;k.g+=A.g;k.b+=A.b}else if(y instanceof THREE.DirectionalLight){g.r+=A.r;g.g+=A.g;g.b+=A.b}else if(y instanceof THREE.PointLight){q.r+=A.r;q.g+=A.g;q.b+=A.b}}}Q=0;for(K=m.length;Q<K;Q++){T=m[Q];L.empty();if(T instanceof THREE.RenderableParticle){x=T;x.x*=E;x.y*=-C;y=0;for(A=T.material.length;y<A;y++)if(R=
+T.material[y]){V=x;X=T;R=R;var Z=S++;if(p[Z]==null){p[Z]=document.createElementNS("http://www.w3.org/2000/svg","circle");O==0&&p[Z].setAttribute("shape-rendering","crispEdges")}w=p[Z];w.setAttribute("cx",V.x);w.setAttribute("cy",V.y);w.setAttribute("r",X.scale.x*E);if(R instanceof THREE.ParticleCircleMaterial){if(M){e.r=k.r+g.r+q.r;e.g=k.g+g.g+q.g;e.b=k.b+g.b+q.b;u.r=R.color.r*e.r;u.g=R.color.g*e.g;u.b=R.color.b*e.b;u.updateStyleString()}else u=R.color;w.setAttribute("style","fill: "+u.__styleString)}l.appendChild(w)}}else if(T instanceof
+THREE.RenderableLine){x=T.v1;z=T.v2;x.positionScreen.x*=E;x.positionScreen.y*=-C;z.positionScreen.x*=E;z.positionScreen.y*=-C;L.addPoint(x.positionScreen.x,x.positionScreen.y);L.addPoint(z.positionScreen.x,z.positionScreen.y);if(J.instersects(L)){y=0;for(A=T.material.length;y<A;)if(R=T.material[y++]){V=x;X=z;R=R;Z=t++;if(D[Z]==null){D[Z]=document.createElementNS("http://www.w3.org/2000/svg","line");O==0&&D[Z].setAttribute("shape-rendering","crispEdges")}w=D[Z];w.setAttribute("x1",V.positionScreen.x);
+w.setAttribute("y1",V.positionScreen.y);w.setAttribute("x2",X.positionScreen.x);w.setAttribute("y2",X.positionScreen.y);if(R instanceof THREE.LineBasicMaterial){u.__styleString=R.color.__styleString;w.setAttribute("style","fill: none; stroke: "+u.__styleString+"; stroke-width: "+R.linewidth+"; stroke-opacity: "+R.opacity+"; stroke-linecap: "+R.linecap+"; stroke-linejoin: "+R.linejoin);l.appendChild(w)}}}}else if(T instanceof THREE.RenderableFace3){x=T.v1;z=T.v2;H=T.v3;x.positionScreen.x*=E;x.positionScreen.y*=
+-C;z.positionScreen.x*=E;z.positionScreen.y*=-C;H.positionScreen.x*=E;H.positionScreen.y*=-C;L.addPoint(x.positionScreen.x,x.positionScreen.y);L.addPoint(z.positionScreen.x,z.positionScreen.y);L.addPoint(H.positionScreen.x,H.positionScreen.y);if(J.instersects(L)){y=0;for(A=T.meshMaterial.length;y<A;){R=T.meshMaterial[y++];if(R instanceof THREE.MeshFaceMaterial){V=0;for(X=T.faceMaterial.length;V<X;)(R=T.faceMaterial[V++])&&b(x,z,H,T,R,B)}else R&&b(x,z,H,T,R,B)}}}else if(T instanceof THREE.RenderableFace4){x=
+T.v1;z=T.v2;H=T.v3;G=T.v4;x.positionScreen.x*=E;x.positionScreen.y*=-C;z.positionScreen.x*=E;z.positionScreen.y*=-C;H.positionScreen.x*=E;H.positionScreen.y*=-C;G.positionScreen.x*=E;G.positionScreen.y*=-C;L.addPoint(x.positionScreen.x,x.positionScreen.y);L.addPoint(z.positionScreen.x,z.positionScreen.y);L.addPoint(H.positionScreen.x,H.positionScreen.y);L.addPoint(G.positionScreen.x,G.positionScreen.y);if(J.instersects(L)){y=0;for(A=T.meshMaterial.length;y<A;){R=T.meshMaterial[y++];if(R instanceof
+THREE.MeshFaceMaterial){V=0;for(X=T.faceMaterial.length;V<X;)(R=T.faceMaterial[V++])&&d(x,z,H,G,T,R,B)}else R&&d(x,z,H,G,T,R,B)}}}}}};
+THREE.WebGLRenderer=function(a){function b(e,k){var g=c.createProgram(),q=[c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"].join("\n");c.attachShader(g,n("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\nuniform mat4 viewMatrix;\n"+
+e));c.attachShader(g,n("vertex",q+k));c.linkProgram(g);c.getProgramParameter(g,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(g,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");g.uniforms={};g.attributes={};return g}function d(e,k){if(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 g=0;g<6;++g)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+g,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,e.image[g]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);e.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+k);c.bindTexture(c.TEXTURE_CUBE_MAP,
+e.image.__webGLTextureCube)}}function f(e,k){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,l(e.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,l(e.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,l(e.mag_filter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,l(e.min_filter));c.generateMipmap(c.TEXTURE_2D);
+c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+k);c.bindTexture(c.TEXTURE_2D,e.__webGLTexture)}function j(e,k){var g,q,h;g=0;for(q=k.length;g<q;g++){h=k[g];e.uniforms[h]=c.getUniformLocation(e,h)}}function m(e,k){var g,q,h;g=0;for(q=k.length;g<q;g++){h=k[g];e.attributes[h]=c.getAttribLocation(e,h);e.attributes[h]>=0&&c.enableVertexAttribArray(e.attributes[h])}}function n(e,k){var g;if(e=="fragment")g=c.createShader(c.FRAGMENT_SHADER);else if(e=="vertex")g=c.createShader(c.VERTEX_SHADER);
+c.shaderSource(g,k);c.compileShader(g);if(!c.getShaderParameter(g,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(g));return null}return g}function l(e){switch(e){case THREE.RepeatWrapping:return c.REPEAT;case THREE.ClampToEdgeWrapping:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return c.MIRRORED_REPEAT;case THREE.NearestFilter:return c.NEAREST;case THREE.NearestMipMapNearestFilter:return c.NEAREST_MIPMAP_NEAREST;case THREE.NearestMipMapLinearFilter:return c.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return c.LINEAR;
+case THREE.LinearMipMapNearestFilter:return c.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return c.LINEAR_MIPMAP_LINEAR}return 0}var o=document.createElement("canvas"),c,E,C,x=new THREE.Matrix4,z,H=new Float32Array(16),G=new Float32Array(16),J=new Float32Array(16),L=new Float32Array(9),M=new Float32Array(16);a=function(e,k){if(e){var g,q,h,i=pointLights=maxDirLights=maxPointLights=0;g=0;for(q=e.lights.length;g<q;g++){h=e.lights[g];h instanceof THREE.DirectionalLight&&i++;h instanceof
+THREE.PointLight&&pointLights++}if(pointLights+i<=k){maxDirLights=i;maxPointLights=pointLights}else{maxDirLights=Math.ceil(k*i/(pointLights+i));maxPointLights=k-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:k-1}}(a,4);this.domElement=o;this.autoClear=true;try{c=o.getContext("experimental-webgl",{antialias:true})}catch(u){}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=C=function(e,k){var g=[e?"#define MAX_DIR_LIGHTS "+e:"",k?"#define MAX_POINT_LIGHTS "+k:"","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 ];":
+"",k?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",k?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","varying 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;",
+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?"}":"",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"),
-p=[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 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 );",
+q=[e?"#define MAX_DIR_LIGHTS "+e:"",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;",
+e?"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 ) + 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;":
+"",k?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",k?"pointDiffuse  += mColor * pointDiffuseWeight;":"",k?"pointSpecular += mSpecular * pointSpecularWeight;":"",k?"}":"",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;":"",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");
-e=b(p,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);n(e,["position","normal","uv"]);return e}(a.directional,a.point);this.setSize=function(f,k){o.width=f;o.height=k;c.viewport(0,0,o.width,o.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(f,k){var e,p,h,i,s,r=[],
-M=[],A=[];i=[];s=[];c.uniform1i(f.uniforms.enableLighting,k.length);e=0;for(p=k.length;e<p;e++){h=k[e];if(h instanceof THREE.AmbientLight)r.push(h);else if(h instanceof THREE.DirectionalLight)A.push(h);else h instanceof THREE.PointLight&&M.push(h)}e=h=i=s=0;for(p=r.length;e<p;e++){h+=r[e].color.r;i+=r[e].color.g;s+=r[e].color.b}c.uniform3f(f.uniforms.ambientLightColor,h,i,s);i=[];s=[];e=0;for(p=A.length;e<p;e++){h=A[e];i.push(h.color.r*h.intensity);i.push(h.color.g*h.intensity);i.push(h.color.b*h.intensity);
-s.push(h.position.x);s.push(h.position.y);s.push(h.position.z)}if(A.length){c.uniform1i(f.uniforms.directionalLightNumber,A.length);c.uniform3fv(f.uniforms.directionalLightDirection,s);c.uniform3fv(f.uniforms.directionalLightColor,i)}i=[];s=[];e=0;for(p=M.length;e<p;e++){h=M[e];i.push(h.color.r*h.intensity);i.push(h.color.g*h.intensity);i.push(h.color.b*h.intensity);s.push(h.position.x);s.push(h.position.y);s.push(h.position.z)}if(M.length){c.uniform1i(f.uniforms.pointLightNumber,M.length);c.uniform3fv(f.uniforms.pointLightPosition,
-s);c.uniform3fv(f.uniforms.pointLightColor,i)}};this.createBuffers=function(f,k){var e,p,h,i,s,r,M,A,H=[],Q=[],u=[],R=[],y=[],z=0,E=f.geometry.geometryChunks[k],W;h=false;e=0;for(p=f.material.length;e<p;e++){meshMaterial=f.material[e];if(meshMaterial instanceof THREE.MeshFaceMaterial){s=0;for(W=E.material.length;s<W;s++)if(E.material[s]&&E.material[s].shading!=undefined&&E.material[s].shading==THREE.SmoothShading){h=true;break}}else if(meshMaterial&&meshMaterial.shading!=undefined&&meshMaterial.shading==
-THREE.SmoothShading){h=true;break}if(h)break}W=h;e=0;for(p=E.faces.length;e<p;e++){h=E.faces[e];i=f.geometry.faces[h];s=i.vertexNormals;faceNormal=i.normal;h=f.geometry.uvs[h];if(i instanceof THREE.Face3){r=f.geometry.vertices[i.a].position;M=f.geometry.vertices[i.b].position;A=f.geometry.vertices[i.c].position;u.push(r.x,r.y,r.z);u.push(M.x,M.y,M.z);u.push(A.x,A.y,A.z);if(s.length==3&&W)for(i=0;i<3;i++)R.push(s[i].x,s[i].y,s[i].z);else for(i=0;i<3;i++)R.push(faceNormal.x,faceNormal.y,faceNormal.z);
-if(h)for(i=0;i<3;i++)y.push(h[i].u,h[i].v);H.push(z,z+1,z+2);Q.push(z,z+1);Q.push(z,z+2);Q.push(z+1,z+2);z+=3}else if(i instanceof THREE.Face4){r=f.geometry.vertices[i.a].position;M=f.geometry.vertices[i.b].position;A=f.geometry.vertices[i.c].position;i=f.geometry.vertices[i.d].position;u.push(r.x,r.y,r.z);u.push(M.x,M.y,M.z);u.push(A.x,A.y,A.z);u.push(i.x,i.y,i.z);if(s.length==4&&W)for(i=0;i<4;i++)R.push(s[i].x,s[i].y,s[i].z);else for(i=0;i<4;i++)R.push(faceNormal.x,faceNormal.y,faceNormal.z);if(h)for(i=
-0;i<4;i++)y.push(h[i].u,h[i].v);H.push(z,z+1,z+2);H.push(z,z+2,z+3);Q.push(z,z+1);Q.push(z,z+2);Q.push(z,z+3);Q.push(z+1,z+2);Q.push(z+2,z+3);z+=4}}if(u.length){E.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,E.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(u),c.STATIC_DRAW);E.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,E.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(R),c.STATIC_DRAW);if(y.length>0){E.__webGLUVBuffer=c.createBuffer();
-c.bindBuffer(c.ARRAY_BUFFER,E.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(y),c.STATIC_DRAW)}E.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,E.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(H),c.STATIC_DRAW);E.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,E.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(Q),c.STATIC_DRAW);E.__webGLFaceCount=H.length;E.__webGLLineCount=Q.length}};this.renderBuffer=
-function(f,k,e,p){var h,i,s,r,M,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);n(e.program,["position","normal","uv"])}u=e.program}else u=D;if(u!=F){c.useProgram(u);F=u}u==D&&this.setupLights(u,k);this.loadCamera(u,f);this.loadMatrices(u);if(e instanceof THREE.MeshShaderMaterial){s=e.wireframe;
-r=e.wireframe_linewidth;f=u;k=e.uniforms;var R;for(h in k){Q=k[h].type;H=k[h].value;R=f.uniforms[h];if(Q=="i")c.uniform1i(R,H);else if(Q=="f")c.uniform1f(R,H);else if(Q=="v3")c.uniform3f(R,H.x,H.y,H.z);else if(Q=="c")c.uniform3f(R,H.r,H.g,H.b);else if(Q=="t"){c.uniform1i(R,H);if(Q=k[h].texture)Q.image instanceof Array&&Q.image.length==6?d(Q,H):g(Q,H)}}}if(e instanceof THREE.MeshPhongMaterial||e instanceof THREE.MeshLambertMaterial||e instanceof THREE.MeshBasicMaterial){h=e.color;i=e.opacity;s=e.wireframe;
-r=e.wireframe_linewidth;M=e.map;A=e.env_map;k=e.combine==THREE.MixOperation;f=e.reflectivity;Q=e.env_map&&e.env_map.mapping instanceof THREE.CubeRefractionMapping;H=e.refraction_ratio;c.uniform4f(u.uniforms.mColor,h.r*i,h.g*i,h.b*i,i);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){i=e.opacity;c.uniform1f(u.uniforms.mOpacity,i);c.uniform1i(u.uniforms.material,
-4)}else if(e instanceof THREE.MeshDepthMaterial){i=e.opacity;s=e.wireframe;r=e.wireframe_linewidth;c.uniform1f(u.uniforms.mOpacity,i);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,i);c.uniform4f(u.uniforms.mSpecular,f.r,f.g,f.b,i);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(M){g(M,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);i=u.attributes;c.bindBuffer(c.ARRAY_BUFFER,p.__webGLVertexBuffer);c.vertexAttribPointer(i.position,3,c.FLOAT,false,0,0);c.bindBuffer(c.ARRAY_BUFFER,p.__webGLNormalBuffer);c.vertexAttribPointer(i.normal,3,c.FLOAT,false,0,0);if(i.uv>=0)if(p.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,p.__webGLUVBuffer);c.enableVertexAttribArray(i.uv);c.vertexAttribPointer(i.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(i.uv);if(s){c.lineWidth(r);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(f,k,e,p,h,i){var s,r,M,A,H;M=0;for(A=e.material.length;M<A;M++){s=e.material[M];if(s instanceof THREE.MeshFaceMaterial){s=0;for(r=p.material.length;s<r;s++)if((H=p.material[s])&&H.blending==h&&H.opacity<1==i){this.setBlending(H.blending);this.renderBuffer(f,k,H,p)}}else if((H=s)&&H.blending==
-h&&H.opacity<1==i){this.setBlending(H.blending);this.renderBuffer(f,k,H,p)}}};this.render=function(f,k){var e,p,h,i,s=f.lights;this.initWebGLObjects(f);this.autoClear&&this.clear();k.autoUpdateMatrix&&k.updateMatrix();e=0;for(p=f.__webGLObjects.length;e<p;e++){h=f.__webGLObjects[e];i=h.object;h=h.buffer;if(i.visible){this.setupMatrices(i,k);this.renderPass(k,s,i,h,THREE.NormalBlending,false)}}e=0;for(p=f.__webGLObjects.length;e<p;e++){h=f.__webGLObjects[e];i=h.object;h=h.buffer;if(i.visible){this.setupMatrices(i,
-k);this.renderPass(k,s,i,h,THREE.AdditiveBlending,false);this.renderPass(k,s,i,h,THREE.SubtractiveBlending,false);this.renderPass(k,s,i,h,THREE.AdditiveBlending,true);this.renderPass(k,s,i,h,THREE.SubtractiveBlending,true);this.renderPass(k,s,i,h,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(f){var k,e,p,h,i,s;if(!f.__webGLObjects){f.__webGLObjects=[];f.__webGLObjectsMap={}}k=0;for(e=f.objects.length;k<e;k++){p=f.objects[k];if(f.__webGLObjectsMap[p.id]==undefined)f.__webGLObjectsMap[p.id]=
-{};s=f.__webGLObjectsMap[p.id];if(p instanceof THREE.Mesh)for(i in p.geometry.geometryChunks){h=p.geometry.geometryChunks[i];h.__webGLVertexBuffer||this.createBuffers(p,i);if(s[i]==undefined){h={buffer:h,object:p};f.__webGLObjects.push(h);s[i]=1}}}};this.removeObject=function(f,k){var e,p;for(e=f.__webGLObjects.length-1;e>=0;e--){p=f.__webGLObjects[e].object;k==p&&f.__webGLObjects.splice(e,1)}};this.setupMatrices=function(f,k){f.autoUpdateMatrix&&f.updateMatrix();w.multiply(k.matrix,f.matrix);I.set(k.matrix.flatten());
-G.set(w.flatten());L.set(k.projectionMatrix.flatten());x=THREE.Matrix4.makeInvert3x3(w).transpose();N.set(x.m);O.set(f.matrix.flatten())};this.loadMatrices=function(f){c.uniformMatrix4fv(f.uniforms.viewMatrix,false,I);c.uniformMatrix4fv(f.uniforms.modelViewMatrix,false,G);c.uniformMatrix4fv(f.uniforms.projectionMatrix,false,L);c.uniformMatrix3fv(f.uniforms.normalMatrix,false,N);c.uniformMatrix4fv(f.uniforms.objectMatrix,false,O)};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.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=null};
+g=b(q,g);c.useProgram(g);j(g,["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(g,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);k&&j(g,["pointLightNumber","pointLightColor",
+"pointLightPosition"]);c.uniform1i(g.uniforms.enableMap,0);c.uniform1i(g.uniforms.tMap,0);c.uniform1i(g.uniforms.enableCubeMap,0);c.uniform1i(g.uniforms.tCube,1);c.uniform1i(g.uniforms.mixEnvMap,0);c.uniform1i(g.uniforms.useRefract,0);m(g,["position","normal","uv"]);return g}(a.directional,a.point);this.setSize=function(e,k){o.width=e;o.height=k;c.viewport(0,0,o.width,o.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(e,k){var g,q,h,i,r,p=[],
+D=[],w=[];i=[];r=[];c.uniform1i(e.uniforms.enableLighting,k.length);g=0;for(q=k.length;g<q;g++){h=k[g];if(h instanceof THREE.AmbientLight)p.push(h);else if(h instanceof THREE.DirectionalLight)w.push(h);else h instanceof THREE.PointLight&&D.push(h)}g=h=i=r=0;for(q=p.length;g<q;g++){h+=p[g].color.r;i+=p[g].color.g;r+=p[g].color.b}c.uniform3f(e.uniforms.ambientLightColor,h,i,r);i=[];r=[];g=0;for(q=w.length;g<q;g++){h=w[g];i.push(h.color.r*h.intensity);i.push(h.color.g*h.intensity);i.push(h.color.b*h.intensity);
+r.push(h.position.x);r.push(h.position.y);r.push(h.position.z)}if(w.length){c.uniform1i(e.uniforms.directionalLightNumber,w.length);c.uniform3fv(e.uniforms.directionalLightDirection,r);c.uniform3fv(e.uniforms.directionalLightColor,i)}i=[];r=[];g=0;for(q=D.length;g<q;g++){h=D[g];i.push(h.color.r*h.intensity);i.push(h.color.g*h.intensity);i.push(h.color.b*h.intensity);r.push(h.position.x);r.push(h.position.y);r.push(h.position.z)}if(D.length){c.uniform1i(e.uniforms.pointLightNumber,D.length);c.uniform3fv(e.uniforms.pointLightPosition,
+r);c.uniform3fv(e.uniforms.pointLightColor,i)}};this.createBuffers=function(e,k){var g,q,h,i,r,p,D,w,I,S=[],t=[],O=[],B=[],P=[],Q=[],K=0,y=e.geometry.geometryChunks[k],A;h=false;g=0;for(q=e.material.length;g<q;g++){meshMaterial=e.material[g];if(meshMaterial instanceof THREE.MeshFaceMaterial){r=0;for(A=y.material.length;r<A;r++)if(y.material[r]&&y.material[r].shading!=undefined&&y.material[r].shading==THREE.SmoothShading){h=true;break}}else if(meshMaterial&&meshMaterial.shading!=undefined&&meshMaterial.shading==
+THREE.SmoothShading){h=true;break}if(h)break}A=h;g=0;for(q=y.faces.length;g<q;g++){h=y.faces[g];i=e.geometry.faces[h];r=i.vertexNormals;faceNormal=i.normal;h=e.geometry.uvs[h];if(i instanceof THREE.Face3){p=e.geometry.vertices[i.a].position;D=e.geometry.vertices[i.b].position;w=e.geometry.vertices[i.c].position;O.push(p.x,p.y,p.z);O.push(D.x,D.y,D.z);O.push(w.x,w.y,w.z);if(e.geometry.hasTangents){p=e.geometry.vertices[i.a].tangent;D=e.geometry.vertices[i.b].tangent;w=e.geometry.vertices[i.c].tangent;
+P.push(p.x,p.y,p.z,p.w);P.push(D.x,D.y,D.z,D.w);P.push(w.x,w.y,w.z,w.w)}if(r.length==3&&A)for(i=0;i<3;i++)B.push(r[i].x,r[i].y,r[i].z);else for(i=0;i<3;i++)B.push(faceNormal.x,faceNormal.y,faceNormal.z);if(h)for(i=0;i<3;i++)Q.push(h[i].u,h[i].v);S.push(K,K+1,K+2);t.push(K,K+1);t.push(K,K+2);t.push(K+1,K+2);K+=3}else if(i instanceof THREE.Face4){p=e.geometry.vertices[i.a].position;D=e.geometry.vertices[i.b].position;w=e.geometry.vertices[i.c].position;I=e.geometry.vertices[i.d].position;O.push(p.x,
+p.y,p.z);O.push(D.x,D.y,D.z);O.push(w.x,w.y,w.z);O.push(I.x,I.y,I.z);if(e.geometry.hasTangents){p=e.geometry.vertices[i.a].tangent;D=e.geometry.vertices[i.b].tangent;w=e.geometry.vertices[i.c].tangent;i=e.geometry.vertices[i.d].tangent;P.push(p.x,p.y,p.z,p.w);P.push(D.x,D.y,D.z,D.w);P.push(w.x,w.y,w.z,w.w);P.push(i.x,i.y,i.z,i.w)}if(r.length==4&&A)for(i=0;i<4;i++)B.push(r[i].x,r[i].y,r[i].z);else for(i=0;i<4;i++)B.push(faceNormal.x,faceNormal.y,faceNormal.z);if(h)for(i=0;i<4;i++)Q.push(h[i].u,h[i].v);
+S.push(K,K+1,K+2);S.push(K,K+2,K+3);t.push(K,K+1);t.push(K,K+2);t.push(K,K+3);t.push(K+1,K+2);t.push(K+2,K+3);K+=4}}if(O.length){y.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,y.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(O),c.STATIC_DRAW);y.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,y.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(B),c.STATIC_DRAW);if(e.geometry.hasTangents){y.__webGLTangentBuffer=c.createBuffer();
+c.bindBuffer(c.ARRAY_BUFFER,y.__webGLTangentBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(P),c.STATIC_DRAW)}if(Q.length>0){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(S),c.STATIC_DRAW);y.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,
+y.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(t),c.STATIC_DRAW);y.__webGLFaceCount=S.length;y.__webGLLineCount=t.length}};this.renderBuffer=function(e,k,g,q){var h,i,r,p,D,w,I,S,t;if(g instanceof THREE.MeshShaderMaterial){if(!g.program){g.program=b(g.fragment_shader,g.vertex_shader);I=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(t in g.uniforms)I.push(t);j(g.program,I);m(g.program,["position","normal","uv","tangent"])}t=
+g.program}else t=C;if(t!=E){c.useProgram(t);E=t}t==C&&this.setupLights(t,k);this.loadCamera(t,e);this.loadMatrices(t);if(g instanceof THREE.MeshShaderMaterial){r=g.wireframe;p=g.wireframe_linewidth;e=t;k=g.uniforms;var O;for(h in k){S=k[h].type;I=k[h].value;O=e.uniforms[h];if(S=="i")c.uniform1i(O,I);else if(S=="f")c.uniform1f(O,I);else if(S=="v3")c.uniform3f(O,I.x,I.y,I.z);else if(S=="c")c.uniform3f(O,I.r,I.g,I.b);else if(S=="t"){c.uniform1i(O,I);if(S=k[h].texture)S.image instanceof Array&&S.image.length==
+6?d(S,I):f(S,I)}}}if(g instanceof THREE.MeshPhongMaterial||g instanceof THREE.MeshLambertMaterial||g instanceof THREE.MeshBasicMaterial){h=g.color;i=g.opacity;r=g.wireframe;p=g.wireframe_linewidth;D=g.map;w=g.env_map;k=g.combine==THREE.MixOperation;e=g.reflectivity;S=g.env_map&&g.env_map.mapping instanceof THREE.CubeRefractionMapping;I=g.refraction_ratio;c.uniform4f(t.uniforms.mColor,h.r*i,h.g*i,h.b*i,i);c.uniform1i(t.uniforms.mixEnvMap,k);c.uniform1f(t.uniforms.mReflectivity,e);c.uniform1i(t.uniforms.useRefract,
+S);c.uniform1f(t.uniforms.mRefractionRatio,I)}if(g instanceof THREE.MeshNormalMaterial){i=g.opacity;c.uniform1f(t.uniforms.mOpacity,i);c.uniform1i(t.uniforms.material,4)}else if(g instanceof THREE.MeshDepthMaterial){i=g.opacity;r=g.wireframe;p=g.wireframe_linewidth;c.uniform1f(t.uniforms.mOpacity,i);c.uniform1f(t.uniforms.m2Near,g.__2near);c.uniform1f(t.uniforms.mFarPlusNear,g.__farPlusNear);c.uniform1f(t.uniforms.mFarMinusNear,g.__farMinusNear);c.uniform1i(t.uniforms.material,3)}else if(g instanceof
+THREE.MeshPhongMaterial){h=g.ambient;e=g.specular;g=g.shininess;c.uniform4f(t.uniforms.mAmbient,h.r,h.g,h.b,i);c.uniform4f(t.uniforms.mSpecular,e.r,e.g,e.b,i);c.uniform1f(t.uniforms.mShininess,g);c.uniform1i(t.uniforms.material,2)}else if(g instanceof THREE.MeshLambertMaterial)c.uniform1i(t.uniforms.material,1);else if(g instanceof THREE.MeshBasicMaterial)c.uniform1i(t.uniforms.material,0);else if(g instanceof THREE.MeshCubeMaterial){c.uniform1i(t.uniforms.material,5);w=g.env_map}if(D){f(D,0);c.uniform1i(t.uniforms.tMap,
+0);c.uniform1i(t.uniforms.enableMap,1)}else c.uniform1i(t.uniforms.enableMap,0);if(w){d(w,1);c.uniform1i(t.uniforms.tCube,1);c.uniform1i(t.uniforms.enableCubeMap,1)}else c.uniform1i(t.uniforms.enableCubeMap,0);i=t.attributes;c.bindBuffer(c.ARRAY_BUFFER,q.__webGLVertexBuffer);c.vertexAttribPointer(i.position,3,c.FLOAT,false,0,0);c.bindBuffer(c.ARRAY_BUFFER,q.__webGLNormalBuffer);c.vertexAttribPointer(i.normal,3,c.FLOAT,false,0,0);if(i.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,q.__webGLTangentBuffer);
+c.vertexAttribPointer(i.tangent,4,c.FLOAT,false,0,0)}if(i.uv>=0)if(q.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,q.__webGLUVBuffer);c.enableVertexAttribArray(i.uv);c.vertexAttribPointer(i.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(i.uv);if(r){c.lineWidth(p);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,q.__webGLLineBuffer);c.drawElements(c.LINES,q.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,q.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,q.__webGLFaceCount,c.UNSIGNED_SHORT,
+0)}};this.renderPass=function(e,k,g,q,h,i){var r,p,D,w,I;D=0;for(w=g.material.length;D<w;D++){r=g.material[D];if(r instanceof THREE.MeshFaceMaterial){r=0;for(p=q.material.length;r<p;r++)if((I=q.material[r])&&I.blending==h&&I.opacity<1==i){this.setBlending(I.blending);this.renderBuffer(e,k,I,q)}}else if((I=r)&&I.blending==h&&I.opacity<1==i){this.setBlending(I.blending);this.renderBuffer(e,k,I,q)}}};this.render=function(e,k){var g,q,h,i,r=e.lights;this.initWebGLObjects(e);this.autoClear&&this.clear();
+k.autoUpdateMatrix&&k.updateMatrix();g=0;for(q=e.__webGLObjects.length;g<q;g++){h=e.__webGLObjects[g];i=h.object;h=h.buffer;if(i.visible){this.setupMatrices(i,k);this.renderPass(k,r,i,h,THREE.NormalBlending,false)}}g=0;for(q=e.__webGLObjects.length;g<q;g++){h=e.__webGLObjects[g];i=h.object;h=h.buffer;if(i.visible){this.setupMatrices(i,k);this.renderPass(k,r,i,h,THREE.AdditiveBlending,false);this.renderPass(k,r,i,h,THREE.SubtractiveBlending,false);this.renderPass(k,r,i,h,THREE.AdditiveBlending,true);
+this.renderPass(k,r,i,h,THREE.SubtractiveBlending,true);this.renderPass(k,r,i,h,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(e){var k,g,q,h,i,r;if(!e.__webGLObjects){e.__webGLObjects=[];e.__webGLObjectsMap={}}k=0;for(g=e.objects.length;k<g;k++){q=e.objects[k];if(e.__webGLObjectsMap[q.id]==undefined)e.__webGLObjectsMap[q.id]={};r=e.__webGLObjectsMap[q.id];if(q instanceof THREE.Mesh)for(i in q.geometry.geometryChunks){h=q.geometry.geometryChunks[i];h.__webGLVertexBuffer||this.createBuffers(q,
+i);if(r[i]==undefined){h={buffer:h,object:q};e.__webGLObjects.push(h);r[i]=1}}}};this.removeObject=function(e,k){var g,q;for(g=e.__webGLObjects.length-1;g>=0;g--){q=e.__webGLObjects[g].object;k==q&&e.__webGLObjects.splice(g,1)}};this.setupMatrices=function(e,k){e.autoUpdateMatrix&&e.updateMatrix();x.multiply(k.matrix,e.matrix);H.set(k.matrix.flatten());G.set(x.flatten());J.set(k.projectionMatrix.flatten());z=THREE.Matrix4.makeInvert3x3(x).transpose();L.set(z.m);M.set(e.matrix.flatten())};this.loadMatrices=
+function(e){c.uniformMatrix4fv(e.uniforms.viewMatrix,false,H);c.uniformMatrix4fv(e.uniforms.modelViewMatrix,false,G);c.uniformMatrix4fv(e.uniforms.projectionMatrix,false,J);c.uniformMatrix3fv(e.uniforms.normalMatrix,false,L);c.uniformMatrix4fv(e.uniforms.objectMatrix,false,M)};this.loadCamera=function(e,k){c.uniform3f(e.uniforms.cameraPosition,k.position.x,k.position.y,k.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,k){if(e){!k||k=="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)};this.supportsVertexTextures=function(){return c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}};
+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};

+ 121 - 116
build/ThreeDebug.js

@@ -5,59 +5,62 @@ THREE.Color.prototype={setRGB:function(a,b,d){this.r=a;this.g=b;this.b=d;if(this
 THREE.Vector2.prototype={set:function(a,b){this.x=a;this.y=b;return this},copy:function(a){this.x=a.x;this.y=a.y;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;return this},unit:function(){this.multiplyScalar(1/this.length());return this},length:function(){return Math.sqrt(this.x*
 this.x+this.y*this.y)},lengthSq:function(){return this.x*this.x+this.y*this.y},negate:function(){this.x=-this.x;this.y=-this.y;return this},clone:function(){return new THREE.Vector2(this.x,this.y)},toString:function(){return"THREE.Vector2 ("+this.x+", "+this.y+")"}};THREE.Vector3=function(a,b,d){this.x=a||0;this.y=b||0;this.z=d||0};
 THREE.Vector3.prototype={set:function(a,b,d){this.x=a;this.y=b;this.z=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;return this},addScalar:function(a){this.x+=a;this.y+=a;this.z+=a;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;return this},
-cross:function(a,b){this.x=a.y*b.z-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){var b=this.x,d=this.y,g=this.z;this.x=d*a.z-g*a.y;this.y=g*a.x-b*a.z;this.z=b*a.y-d*a.x;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=
+cross:function(a,b){this.x=a.y*b.z-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){var b=this.x,d=this.y,f=this.z;this.x=d*a.z-f*a.y;this.y=f*a.x-b*a.z;this.z=b*a.y-d*a.x;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=
 a;return this},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},distanceTo:function(a){var b=this.x-a.x,d=this.y-a.y;a=this.z-a.z;return Math.sqrt(b*b+d*d+a*a)},distanceToSquared:function(a){var b=this.x-a.x,d=this.y-a.y;a=this.z-a.z;return b*b+d*d+a*a},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},negate:function(){this.x=-this.x;this.y=-this.y;this.z=-this.z;return this},normalize:function(){var a=
 Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z);a>0?this.multiplyScalar(1/a):this.set(0,0,0);return this},setLength:function(a){return this.normalize().multiplyScalar(a)},isZero:function(){return Math.abs(this.x)<1.0E-4&&Math.abs(this.y)<1.0E-4&&Math.abs(this.z)<1.0E-4},clone:function(){return new THREE.Vector3(this.x,this.y,this.z)},toString:function(){return"THREE.Vector3 ( "+this.x+", "+this.y+", "+this.z+" )"}};
-THREE.Vector4=function(a,b,d,g){this.x=a||0;this.y=b||0;this.z=d||0;this.w=g||1};
-THREE.Vector4.prototype={set:function(a,b,d,g){this.x=a;this.y=b;this.z=d;this.w=g;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w||1;return this},add:function(a,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=function(a,b,d,f){this.x=a||0;this.y=b||0;this.z=d||0;this.w=f||1};
+THREE.Vector4.prototype={set:function(a,b,d,f){this.x=a;this.y=b;this.z=d;this.w=f;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w||1;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;
 return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=a;this.w/=a;return this},lerpSelf:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},toString:function(){return"THREE.Vector4 ("+this.x+", "+this.y+", "+this.z+", "+this.w+")"}};
 THREE.Ray=function(a,b){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3};
-THREE.Ray.prototype={intersectScene:function(a){var b,d,g=a.objects,j=[];a=0;for(b=g.length;a<b;a++){d=g[a];if(d instanceof THREE.Mesh)j=j.concat(this.intersectObject(d))}j.sort(function(n,m){return n.distance-m.distance});return j},intersectObject:function(a){function b(L,N,O,v){v=v.clone().subSelf(N);O=O.clone().subSelf(N);var f=L.clone().subSelf(N);L=v.dot(v);N=v.dot(O);v=v.dot(f);var l=O.dot(O);O=O.dot(f);f=1/(L*l-N*N);l=(l*v-N*O)*f;L=(L*O-N*v)*f;return l>0&&L>0&&l+L<1}var d,g,j,n,m,k,o,c,F,D,
-w,x=a.geometry,I=x.vertices,G=[];d=0;for(g=x.faces.length;d<g;d++){j=x.faces[d];D=this.origin.clone();w=this.direction.clone();n=a.matrix.multiplyVector3(I[j.a].position.clone());m=a.matrix.multiplyVector3(I[j.b].position.clone());k=a.matrix.multiplyVector3(I[j.c].position.clone());o=j instanceof THREE.Face4?a.matrix.multiplyVector3(I[j.d].position.clone()):null;c=a.rotationMatrix.multiplyVector3(j.normal.clone());F=w.dot(c);if(F<0){c=c.dot((new THREE.Vector3).sub(n,D))/F;D=D.addSelf(w.multiplyScalar(c));
-if(j instanceof THREE.Face3){if(b(D,n,m,k)){j={distance:this.origin.distanceTo(D),point:D,face:j,object:a};G.push(j)}}else if(j instanceof THREE.Face4)if(b(D,n,m,o)||b(D,m,k,o)){j={distance:this.origin.distanceTo(D),point:D,face:j,object:a};G.push(j)}}}return G}};
-THREE.Rectangle=function(){function a(){n=g-b;m=j-d}var b,d,g,j,n,m,k=true;this.getX=function(){return b};this.getY=function(){return d};this.getWidth=function(){return n};this.getHeight=function(){return m};this.getLeft=function(){return b};this.getTop=function(){return d};this.getRight=function(){return g};this.getBottom=function(){return j};this.set=function(o,c,F,D){k=false;b=o;d=c;g=F;j=D;a()};this.addPoint=function(o,c){if(k){k=false;b=o;d=c;g=o;j=c}else{b=Math.min(b,o);d=Math.min(d,c);g=Math.max(g,
-o);j=Math.max(j,c)}a()};this.addRectangle=function(o){if(k){k=false;b=o.getLeft();d=o.getTop();g=o.getRight();j=o.getBottom()}else{b=Math.min(b,o.getLeft());d=Math.min(d,o.getTop());g=Math.max(g,o.getRight());j=Math.max(j,o.getBottom())}a()};this.inflate=function(o){b-=o;d-=o;g+=o;j+=o;a()};this.minSelf=function(o){b=Math.max(b,o.getLeft());d=Math.max(d,o.getTop());g=Math.min(g,o.getRight());j=Math.min(j,o.getBottom());a()};this.instersects=function(o){return Math.min(g,o.getRight())-Math.max(b,o.getLeft())>=
-0&&Math.min(j,o.getBottom())-Math.max(d,o.getTop())>=0};this.empty=function(){k=true;j=g=d=b=0;a()};this.isEmpty=function(){return k};this.toString=function(){return"THREE.Rectangle ( left: "+b+", right: "+g+", top: "+d+", bottom: "+j+", width: "+n+", 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,f=a.objects,j=[];a=0;for(b=f.length;a<b;a++){d=f[a];if(d instanceof THREE.Mesh)j=j.concat(this.intersectObject(d))}j.sort(function(m,n){return m.distance-n.distance});return j},intersectObject:function(a){function b(J,L,M,u){u=u.clone().subSelf(L);M=M.clone().subSelf(L);var e=J.clone().subSelf(L);J=u.dot(u);L=u.dot(M);u=u.dot(e);var l=M.dot(M);M=M.dot(e);e=1/(J*l-L*L);l=(l*u-L*M)*e;J=(J*M-L*u)*e;return l>0&&J>0&&l+J<1}var d,f,j,m,n,k,o,c,E,C,
+x,z=a.geometry,H=z.vertices,G=[];d=0;for(f=z.faces.length;d<f;d++){j=z.faces[d];C=this.origin.clone();x=this.direction.clone();m=a.matrix.multiplyVector3(H[j.a].position.clone());n=a.matrix.multiplyVector3(H[j.b].position.clone());k=a.matrix.multiplyVector3(H[j.c].position.clone());o=j instanceof THREE.Face4?a.matrix.multiplyVector3(H[j.d].position.clone()):null;c=a.rotationMatrix.multiplyVector3(j.normal.clone());E=x.dot(c);if(E<0){c=c.dot((new THREE.Vector3).sub(m,C))/E;C=C.addSelf(x.multiplyScalar(c));
+if(j instanceof THREE.Face3){if(b(C,m,n,k)){j={distance:this.origin.distanceTo(C),point:C,face:j,object:a};G.push(j)}}else if(j instanceof THREE.Face4)if(b(C,m,n,o)||b(C,n,k,o)){j={distance:this.origin.distanceTo(C),point:C,face:j,object:a};G.push(j)}}}return G}};
+THREE.Rectangle=function(){function a(){m=f-b;n=j-d}var b,d,f,j,m,n,k=true;this.getX=function(){return b};this.getY=function(){return d};this.getWidth=function(){return m};this.getHeight=function(){return n};this.getLeft=function(){return b};this.getTop=function(){return d};this.getRight=function(){return f};this.getBottom=function(){return j};this.set=function(o,c,E,C){k=false;b=o;d=c;f=E;j=C;a()};this.addPoint=function(o,c){if(k){k=false;b=o;d=c;f=o;j=c}else{b=Math.min(b,o);d=Math.min(d,c);f=Math.max(f,
+o);j=Math.max(j,c)}a()};this.addRectangle=function(o){if(k){k=false;b=o.getLeft();d=o.getTop();f=o.getRight();j=o.getBottom()}else{b=Math.min(b,o.getLeft());d=Math.min(d,o.getTop());f=Math.max(f,o.getRight());j=Math.max(j,o.getBottom())}a()};this.inflate=function(o){b-=o;d-=o;f+=o;j+=o;a()};this.minSelf=function(o){b=Math.max(b,o.getLeft());d=Math.max(d,o.getTop());f=Math.min(f,o.getRight());j=Math.min(j,o.getBottom());a()};this.instersects=function(o){return Math.min(f,o.getRight())-Math.max(b,o.getLeft())>=
+0&&Math.min(j,o.getBottom())-Math.max(d,o.getTop())>=0};this.empty=function(){k=true;j=f=d=b=0;a()};this.isEmpty=function(){return k};this.toString=function(){return"THREE.Rectangle ( left: "+b+", right: "+f+", top: "+d+", bottom: "+j+", width: "+m+", height: "+n+" )"}};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.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 g=new THREE.Vector3,j=new THREE.Vector3,n=new THREE.Vector3;n.sub(a,b).normalize();g.cross(d,n).normalize();j.cross(n,g).normalize();this.n11=g.x;this.n12=g.y;this.n13=g.z;this.n14=-g.dot(a);this.n21=j.x;this.n22=j.y;this.n23=j.z;this.n24=-j.dot(a);this.n31=n.x;this.n32=n.y;this.n33=n.z;this.n34=-n.dot(a);this.n43=this.n42=this.n41=0;this.n44=1},multiplyVector3:function(a){var b=a.x,d=a.y,g=a.z,j=1/(this.n41*b+this.n42*
-d+this.n43*g+this.n44);a.x=(this.n11*b+this.n12*d+this.n13*g+this.n14)*j;a.y=(this.n21*b+this.n22*d+this.n23*g+this.n24)*j;a.z=(this.n31*b+this.n32*d+this.n33*g+this.n34)*j;return a},multiplyVector4:function(a){var b=a.x,d=a.y,g=a.z,j=a.w;a.x=this.n11*b+this.n12*d+this.n13*g+this.n14*j;a.y=this.n21*b+this.n22*d+this.n23*g+this.n24*j;a.z=this.n31*b+this.n32*d+this.n33*g+this.n34*j;a.w=this.n41*b+this.n42*d+this.n43*g+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,g=a.n12,j=a.n13,n=a.n14,m=a.n21,k=a.n22,o=a.n23,c=a.n24,F=a.n31,D=a.n32,w=a.n33,x=a.n34,I=a.n41,G=a.n42,L=a.n43,N=a.n44,O=b.n11,v=b.n12,f=b.n13,l=b.n14,e=b.n21,q=b.n22,h=b.n23,i=b.n24,s=b.n31,r=b.n32,M=b.n33,B=b.n34,H=b.n41,Q=b.n42,u=b.n43,
-R=b.n44;this.n11=d*O+g*e+j*s+n*H;this.n12=d*v+g*q+j*r+n*Q;this.n13=d*f+g*h+j*M+n*u;this.n14=d*l+g*i+j*B+n*R;this.n21=m*O+k*e+o*s+c*H;this.n22=m*v+k*q+o*r+c*Q;this.n23=m*f+k*h+o*M+c*u;this.n24=m*l+k*i+o*B+c*R;this.n31=F*O+D*e+w*s+x*H;this.n32=F*v+D*q+w*r+x*Q;this.n33=F*f+D*h+w*M+x*u;this.n34=F*l+D*i+w*B+x*R;this.n41=I*O+G*e+L*s+N*H;this.n42=I*v+G*q+L*r+N*Q;this.n43=I*f+G*h+L*M+N*u;this.n44=I*l+G*i+L*B+N*R},multiplySelf:function(a){var b=this.n11,d=this.n12,g=this.n13,j=this.n14,n=this.n21,m=this.n22,
-k=this.n23,o=this.n24,c=this.n31,F=this.n32,D=this.n33,w=this.n34,x=this.n41,I=this.n42,G=this.n43,L=this.n44;this.n11=b*a.n11+d*a.n21+g*a.n31+j*a.n41;this.n12=b*a.n12+d*a.n22+g*a.n32+j*a.n42;this.n13=b*a.n13+d*a.n23+g*a.n33+j*a.n43;this.n14=b*a.n14+d*a.n24+g*a.n34+j*a.n44;this.n21=n*a.n11+m*a.n21+k*a.n31+o*a.n41;this.n22=n*a.n12+m*a.n22+k*a.n32+o*a.n42;this.n23=n*a.n13+m*a.n23+k*a.n33+o*a.n43;this.n24=n*a.n14+m*a.n24+k*a.n34+o*a.n44;this.n31=c*a.n11+F*a.n21+D*a.n31+w*a.n41;this.n32=c*a.n12+F*a.n22+
-D*a.n32+w*a.n42;this.n33=c*a.n13+F*a.n23+D*a.n33+w*a.n43;this.n34=c*a.n14+F*a.n24+D*a.n34+w*a.n44;this.n41=x*a.n11+I*a.n21+G*a.n31+L*a.n41;this.n42=x*a.n12+I*a.n22+G*a.n32+L*a.n42;this.n43=x*a.n13+I*a.n23+G*a.n33+L*a.n43;this.n44=x*a.n14+I*a.n24+G*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 f=new THREE.Vector3,j=new THREE.Vector3,m=new THREE.Vector3;m.sub(a,b).normalize();f.cross(d,m).normalize();j.cross(m,f).normalize();this.n11=f.x;this.n12=f.y;this.n13=f.z;this.n14=-f.dot(a);this.n21=j.x;this.n22=j.y;this.n23=j.z;this.n24=-j.dot(a);this.n31=m.x;this.n32=m.y;this.n33=m.z;this.n34=-m.dot(a);this.n43=this.n42=this.n41=0;this.n44=1},multiplyVector3:function(a){var b=a.x,d=a.y,f=a.z,j=1/(this.n41*b+this.n42*
+d+this.n43*f+this.n44);a.x=(this.n11*b+this.n12*d+this.n13*f+this.n14)*j;a.y=(this.n21*b+this.n22*d+this.n23*f+this.n24)*j;a.z=(this.n31*b+this.n32*d+this.n33*f+this.n34)*j;return a},multiplyVector4:function(a){var b=a.x,d=a.y,f=a.z,j=a.w;a.x=this.n11*b+this.n12*d+this.n13*f+this.n14*j;a.y=this.n21*b+this.n22*d+this.n23*f+this.n24*j;a.z=this.n31*b+this.n32*d+this.n33*f+this.n34*j;a.w=this.n41*b+this.n42*d+this.n43*f+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,f=a.n12,j=a.n13,m=a.n14,n=a.n21,k=a.n22,o=a.n23,c=a.n24,E=a.n31,C=a.n32,x=a.n33,z=a.n34,H=a.n41,G=a.n42,J=a.n43,L=a.n44,M=b.n11,u=b.n12,e=b.n13,l=b.n14,g=b.n21,q=b.n22,h=b.n23,i=b.n24,s=b.n31,p=b.n32,D=b.n33,w=b.n34,I=b.n41,S=b.n42,t=b.n43,
+O=b.n44;this.n11=d*M+f*g+j*s+m*I;this.n12=d*u+f*q+j*p+m*S;this.n13=d*e+f*h+j*D+m*t;this.n14=d*l+f*i+j*w+m*O;this.n21=n*M+k*g+o*s+c*I;this.n22=n*u+k*q+o*p+c*S;this.n23=n*e+k*h+o*D+c*t;this.n24=n*l+k*i+o*w+c*O;this.n31=E*M+C*g+x*s+z*I;this.n32=E*u+C*q+x*p+z*S;this.n33=E*e+C*h+x*D+z*t;this.n34=E*l+C*i+x*w+z*O;this.n41=H*M+G*g+J*s+L*I;this.n42=H*u+G*q+J*p+L*S;this.n43=H*e+G*h+J*D+L*t;this.n44=H*l+G*i+J*w+L*O},multiplySelf:function(a){var b=this.n11,d=this.n12,f=this.n13,j=this.n14,m=this.n21,n=this.n22,
+k=this.n23,o=this.n24,c=this.n31,E=this.n32,C=this.n33,x=this.n34,z=this.n41,H=this.n42,G=this.n43,J=this.n44;this.n11=b*a.n11+d*a.n21+f*a.n31+j*a.n41;this.n12=b*a.n12+d*a.n22+f*a.n32+j*a.n42;this.n13=b*a.n13+d*a.n23+f*a.n33+j*a.n43;this.n14=b*a.n14+d*a.n24+f*a.n34+j*a.n44;this.n21=m*a.n11+n*a.n21+k*a.n31+o*a.n41;this.n22=m*a.n12+n*a.n22+k*a.n32+o*a.n42;this.n23=m*a.n13+n*a.n23+k*a.n33+o*a.n43;this.n24=m*a.n14+n*a.n24+k*a.n34+o*a.n44;this.n31=c*a.n11+E*a.n21+C*a.n31+x*a.n41;this.n32=c*a.n12+E*a.n22+
+C*a.n32+x*a.n42;this.n33=c*a.n13+E*a.n23+C*a.n33+x*a.n43;this.n34=c*a.n14+E*a.n24+C*a.n34+x*a.n44;this.n41=z*a.n11+H*a.n21+G*a.n31+J*a.n41;this.n42=z*a.n12+H*a.n22+G*a.n32+J*a.n42;this.n43=z*a.n13+H*a.n23+G*a.n33+J*a.n43;this.n44=z*a.n14+H*a.n24+G*a.n34+J*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.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,g){var j=b[d];b[d]=b[g];b[g]=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,f){var j=b[d];b[d]=b[f];b[f]=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]},
-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 g=new THREE.Matrix4;g.n14=a;g.n24=b;g.n34=d;return g};THREE.Matrix4.scaleMatrix=function(a,b,d){var g=new THREE.Matrix4;g.n11=a;g.n22=b;g.n33=d;return g};
+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 f=new THREE.Matrix4;f.n14=a;f.n24=b;f.n34=d;return f};THREE.Matrix4.scaleMatrix=function(a,b,d){var f=new THREE.Matrix4;f.n11=a;f.n22=b;f.n33=d;return f};
 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,g=Math.cos(b),j=Math.sin(b),n=1-g,m=a.x,k=a.y,o=a.z;d.n11=n*m*m+g;d.n12=n*m*k-j*o;d.n13=n*m*o+j*k;d.n21=n*m*k+j*o;d.n22=n*k*k+g;d.n23=n*k*o-j*m;d.n31=n*m*o-j*k;d.n32=n*k*o+j*m;d.n33=n*o*o+g;return d};
+THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var d=new THREE.Matrix4,f=Math.cos(b),j=Math.sin(b),m=1-f,n=a.x,k=a.y,o=a.z;d.n11=m*n*n+f;d.n12=m*n*k-j*o;d.n13=m*n*o+j*k;d.n21=m*n*k+j*o;d.n22=m*k*k+f;d.n23=m*k*o-j*n;d.n31=m*n*o-j*k;d.n32=m*k*o+j*n;d.n33=m*o*o+f;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*
 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.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],g=-b[10]*b[1]+b[2]*b[9],j=b[6]*b[1]-b[2]*b[5],n=-b[10]*b[4]+b[6]*b[8],m=b[10]*b[0]-b[2]*b[8],k=-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],F=b[5]*b[0]-b[1]*b[4];b=b[0]*d+b[1]*n+b[2]*o;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*d;a.m[1]=b*g;a.m[2]=b*j;a.m[3]=b*n;a.m[4]=b*m;a.m[5]=b*k;a.m[6]=b*o;a.m[7]=b*c;a.m[8]=b*F;return a};
-THREE.Matrix4.makeFrustum=function(a,b,d,g,j,n){var m,k,o;m=new THREE.Matrix4;k=2*j/(b-a);o=2*j/(g-d);a=(b+a)/(b-a);d=(g+d)/(g-d);g=-(n+j)/(n-j);j=-2*n*j/(n-j);m.n11=k;m.n12=0;m.n13=a;m.n14=0;m.n21=0;m.n22=o;m.n23=d;m.n24=0;m.n31=0;m.n32=0;m.n33=g;m.n34=j;m.n41=0;m.n42=0;m.n43=-1;m.n44=0;return m};THREE.Matrix4.makePerspective=function(a,b,d,g){var j;a=d*Math.tan(a*Math.PI/360);j=-a;return THREE.Matrix4.makeFrustum(j*b,a*b,j,a,d,g)};
-THREE.Matrix4.makeOrtho=function(a,b,d,g,j,n){var m,k,o,c;m=new THREE.Matrix4;k=b-a;o=d-g;c=n-j;a=(b+a)/k;d=(d+g)/o;j=(n+j)/c;m.n11=2/k;m.n12=0;m.n13=0;m.n14=-a;m.n21=0;m.n22=2/o;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.Face3=function(a,b,d,g,j){this.a=a;this.b=b;this.c=d;this.centroid=new THREE.Vector3;this.normal=g instanceof THREE.Vector3?g:new THREE.Vector3;this.vertexNormals=g instanceof Array?g:[];this.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,g,j,n){this.a=a;this.b=b;this.c=d;this.d=g;this.centroid=new THREE.Vector3;this.normal=j instanceof THREE.Vector3?j:new THREE.Vector3;this.vertexNormals=j instanceof Array?j:[];this.material=n instanceof Array?n:[n]};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.Matrix4.makeInvert3x3=function(a){var b=a.flatten();a=new THREE.Matrix3;var d=b[10]*b[5]-b[6]*b[9],f=-b[10]*b[1]+b[2]*b[9],j=b[6]*b[1]-b[2]*b[5],m=-b[10]*b[4]+b[6]*b[8],n=b[10]*b[0]-b[2]*b[8],k=-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],E=b[5]*b[0]-b[1]*b[4];b=b[0]*d+b[1]*m+b[2]*o;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*d;a.m[1]=b*f;a.m[2]=b*j;a.m[3]=b*m;a.m[4]=b*n;a.m[5]=b*k;a.m[6]=b*o;a.m[7]=b*c;a.m[8]=b*E;return a};
+THREE.Matrix4.makeFrustum=function(a,b,d,f,j,m){var n,k,o;n=new THREE.Matrix4;k=2*j/(b-a);o=2*j/(f-d);a=(b+a)/(b-a);d=(f+d)/(f-d);f=-(m+j)/(m-j);j=-2*m*j/(m-j);n.n11=k;n.n12=0;n.n13=a;n.n14=0;n.n21=0;n.n22=o;n.n23=d;n.n24=0;n.n31=0;n.n32=0;n.n33=f;n.n34=j;n.n41=0;n.n42=0;n.n43=-1;n.n44=0;return n};THREE.Matrix4.makePerspective=function(a,b,d,f){var j;a=d*Math.tan(a*Math.PI/360);j=-a;return THREE.Matrix4.makeFrustum(j*b,a*b,j,a,d,f)};
+THREE.Matrix4.makeOrtho=function(a,b,d,f,j,m){var n,k,o,c;n=new THREE.Matrix4;k=b-a;o=d-f;c=m-j;a=(b+a)/k;d=(d+f)/o;j=(m+j)/c;n.n11=2/k;n.n12=0;n.n13=0;n.n14=-a;n.n21=0;n.n22=2/o;n.n23=0;n.n24=-d;n.n31=0;n.n32=0;n.n33=-2/c;n.n34=-j;n.n41=0;n.n42=0;n.n43=0;n.n44=1;return n};
+THREE.Vertex=function(a,b){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=b||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.tangent=new THREE.Vector4;this.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}};
+THREE.Face3=function(a,b,d,f,j){this.a=a;this.b=b;this.c=d;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.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
+THREE.Face4=function(a,b,d,f,j,m){this.a=a;this.b=b;this.c=d;this.d=f;this.centroid=new THREE.Vector3;this.normal=j instanceof THREE.Vector3?j:new THREE.Vector3;this.vertexNormals=j instanceof Array?j:[];this.material=m instanceof Array?m:[m]};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={};this.hasTangents=false};
 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);if(d instanceof THREE.Face3){d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);d.centroid.divideScalar(3)}else if(d instanceof THREE.Face4){d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);
-d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeNormals:function(a){var b,d,g,j,n,m,k=new THREE.Vector3,o=new THREE.Vector3;g=0;for(j=this.vertices.length;g<j;g++){n=this.vertices[g];n.normal.set(0,0,0)}g=0;for(j=this.faces.length;g<j;g++){n=this.faces[g];if(a&&n.vertexNormals.length){k.set(0,0,0);b=0;for(d=n.normal.length;b<d;b++)k.addSelf(n.vertexNormals[b]);k.divideScalar(3)}else{b=this.vertices[n.a];d=this.vertices[n.b];m=this.vertices[n.c];k.sub(m.position,
-d.position);o.sub(b.position,d.position);k.crossSelf(o)}k.isZero()||k.normalize();n.normal.copy(k)}},computeVertexNormals:function(){var a,b=[],d,g;a=0;for(vl=this.vertices.length;a<vl;a++)b[a]=new THREE.Vector3;a=0;for(d=this.faces.length;a<d;a++){g=this.faces[a];if(g instanceof THREE.Face3){b[g.a].addSelf(g.normal);b[g.b].addSelf(g.normal);b[g.c].addSelf(g.normal)}else if(g instanceof THREE.Face4){b[g.a].addSelf(g.normal);b[g.b].addSelf(g.normal);b[g.c].addSelf(g.normal);b[g.d].addSelf(g.normal)}}a=
-0;for(vl=this.vertices.length;a<vl;a++)b[a].normalize();a=0;for(d=this.faces.length;a<d;a++){g=this.faces[a];if(g instanceof THREE.Face3){g.vertexNormals[0]=b[g.a].clone();g.vertexNormals[1]=b[g.b].clone();g.vertexNormals[2]=b[g.c].clone()}else if(g instanceof THREE.Face4){g.vertexNormals[0]=b[g.a].clone();g.vertexNormals[1]=b[g.b].clone();g.vertexNormals[2]=b[g.c].clone();g.vertexNormals[3]=b[g.d].clone()}}},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(F){var D=[];b=0;for(d=F.length;b<d;b++)F[b]==undefined?D.push("undefined"):D.push(F[b].toString());return D.join("_")}var b,d,g,j,n,m,k,o,c={};g=0;for(j=this.faces.length;g<j;g++){n=this.faces[g];m=n.material;k=a(m);if(c[k]==undefined)c[k]={hash:k,counter:0};o=c[k].hash+"_"+c[k].counter;if(this.geometryChunks[o]==
-undefined)this.geometryChunks[o]={faces:[],material:m,vertices:0};n=n instanceof THREE.Face3?3:4;if(this.geometryChunks[o].vertices+n>65535){c[k].counter+=1;o=c[k].hash+"_"+c[k].counter;if(this.geometryChunks[o]==undefined)this.geometryChunks[o]={faces:[],material:m,vertices:0}}this.geometryChunks[o].faces.push(g);this.geometryChunks[o].vertices+=n}},toString:function(){return"THREE.Geometry ( vertices: "+this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
-THREE.Camera=function(a,b,d,g){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,g);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)};
+d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeNormals:function(a){var b,d,f,j,m,n,k=new THREE.Vector3,o=new THREE.Vector3;f=0;for(j=this.vertices.length;f<j;f++){m=this.vertices[f];m.normal.set(0,0,0)}f=0;for(j=this.faces.length;f<j;f++){m=this.faces[f];if(a&&m.vertexNormals.length){k.set(0,0,0);b=0;for(d=m.normal.length;b<d;b++)k.addSelf(m.vertexNormals[b]);k.divideScalar(3)}else{b=this.vertices[m.a];d=this.vertices[m.b];n=this.vertices[m.c];k.sub(n.position,
+d.position);o.sub(b.position,d.position);k.crossSelf(o)}k.isZero()||k.normalize();m.normal.copy(k)}},computeVertexNormals:function(){var a,b=[],d,f;a=0;for(vl=this.vertices.length;a<vl;a++)b[a]=new THREE.Vector3;a=0;for(d=this.faces.length;a<d;a++){f=this.faces[a];if(f instanceof THREE.Face3){b[f.a].addSelf(f.normal);b[f.b].addSelf(f.normal);b[f.c].addSelf(f.normal)}else if(f instanceof THREE.Face4){b[f.a].addSelf(f.normal);b[f.b].addSelf(f.normal);b[f.c].addSelf(f.normal);b[f.d].addSelf(f.normal)}}a=
+0;for(vl=this.vertices.length;a<vl;a++)b[a].normalize();a=0;for(d=this.faces.length;a<d;a++){f=this.faces[a];if(f instanceof THREE.Face3){f.vertexNormals[0]=b[f.a].clone();f.vertexNormals[1]=b[f.b].clone();f.vertexNormals[2]=b[f.c].clone()}else if(f instanceof THREE.Face4){f.vertexNormals[0]=b[f.a].clone();f.vertexNormals[1]=b[f.b].clone();f.vertexNormals[2]=b[f.c].clone();f.vertexNormals[3]=b[f.d].clone()}}},computeTangents:function(){function a(w,I,S,t){m=w.vertices[I].position;n=w.vertices[S].position;
+k=w.vertices[t].position;o=j[0];c=j[1];E=j[2];C=n.x-m.x;x=k.x-m.x;z=n.y-m.y;H=k.y-m.y;G=n.z-m.z;J=k.z-m.z;L=c.u-o.u;M=E.u-o.u;u=c.v-o.v;e=E.v-o.v;l=1/(L*e-M*u);i.set((e*C-u*x)*l,(e*z-u*H)*l,(e*G-u*J)*l);s.set((L*x-M*C)*l,(L*H-M*z)*l,(L*J-M*G)*l);q[I].addSelf(i);q[S].addSelf(i);q[t].addSelf(i);h[I].addSelf(s);h[S].addSelf(s);h[t].addSelf(s)}var b,d,f,j,m,n,k,o,c,E,C,x,z,H,G,J,L,M,u,e,l,g,q=[],h=[],i=new THREE.Vector3,s=new THREE.Vector3,p=new THREE.Vector3,D=new THREE.Vector3;g=new THREE.Vector3;b=
+0;for(d=this.vertices.length;b<d;b++){q[b]=new THREE.Vector3;h[b]=new THREE.Vector3}b=0;for(d=this.faces.length;b<d;b++){f=this.faces[b];j=this.uvs[b];if(f instanceof THREE.Face3){a(this,f.a,f.b,f.c);this.vertices[f.a].normal.copy(f.vertexNormals[0]);this.vertices[f.b].normal.copy(f.vertexNormals[1]);this.vertices[f.c].normal.copy(f.vertexNormals[2])}else if(f instanceof THREE.Face4){a(this,f.a,f.b,f.c);this.vertices[f.a].normal.copy(f.vertexNormals[0]);this.vertices[f.b].normal.copy(f.vertexNormals[1]);
+this.vertices[f.c].normal.copy(f.vertexNormals[2]);this.vertices[f.d].normal.copy(f.vertexNormals[3])}}b=0;for(d=this.vertices.length;b<d;b++){g.copy(this.vertices[b].normal);f=q[b];p.copy(f);p.subSelf(g.multiplyScalar(g.dot(f))).normalize();D.cross(this.vertices[b].normal,f);test=D.dot(h[b]);f=test<0?-1:1;this.vertices[b].tangent.set(p.x,p.y,p.z,f)}this.hasTangents=true},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 C=[];b=0;for(d=E.length;b<d;b++)E[b]==undefined?C.push("undefined"):C.push(E[b].toString());return C.join("_")}var b,d,f,j,m,n,k,o,c={};f=0;for(j=this.faces.length;f<j;f++){m=this.faces[f];n=m.material;k=a(n);if(c[k]==undefined)c[k]={hash:k,counter:0};o=c[k].hash+"_"+c[k].counter;if(this.geometryChunks[o]==undefined)this.geometryChunks[o]={faces:[],material:n,
+vertices:0};m=m instanceof THREE.Face3?3:4;if(this.geometryChunks[o].vertices+m>65535){c[k].counter+=1;o=c[k].hash+"_"+c[k].counter;if(this.geometryChunks[o]==undefined)this.geometryChunks[o]={faces:[],material:n,vertices:0}}this.geometryChunks[o].faces.push(f);this.geometryChunks[o].vertices+=m}},toString:function(){return"THREE.Geometry ( vertices: "+this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
+THREE.Camera=function(a,b,d,f){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,f);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.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.Object3D=function(){this.id=THREE.Object3DCounter.value++;this.position=new THREE.Vector3;this.rotation=new THREE.Vector3;this.scale=new THREE.Vector3(1,1,1);this.matrix=new THREE.Matrix4;this.translationMatrix=new THREE.Matrix4;this.rotationMatrix=new THREE.Matrix4;this.scaleMatrix=new THREE.Matrix4;this.screen=new THREE.Vector3;this.autoUpdateMatrix=this.visible=true;this.updateMatrix=function(){this.matrixPosition=THREE.Matrix4.translationMatrix(this.position.x,this.position.y,this.position.z);
 this.rotationMatrix=THREE.Matrix4.rotationXMatrix(this.rotation.x);this.rotationMatrix.multiplySelf(THREE.Matrix4.rotationYMatrix(this.rotation.y));this.rotationMatrix.multiplySelf(THREE.Matrix4.rotationZMatrix(this.rotation.z));this.scaleMatrix=THREE.Matrix4.scaleMatrix(this.scale.x,this.scale.y,this.scale.z);this.matrix.copy(this.matrixPosition);this.matrix.multiplySelf(this.rotationMatrix);this.matrix.multiplySelf(this.scaleMatrix)}};THREE.Object3DCounter={value:0};
 THREE.Particle=function(a){THREE.Object3D.call(this);this.material=a instanceof Array?a:[a];this.autoUpdateMatrix=false};THREE.Particle.prototype=new THREE.Object3D;THREE.Particle.prototype.constructor=THREE.Particle;THREE.Line=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.material=b instanceof Array?b:[b]};THREE.Line.prototype=new THREE.Object3D;THREE.Line.prototype.constructor=THREE.Line;
 THREE.Mesh=function(a,b,d){THREE.Object3D.call(this);this.geometry=a;this.material=b instanceof Array?b:[b];this.overdraw=this.doubleSided=this.flipSided=false;d&&this.normalizeUVs();this.geometry.computeBoundingBox()};THREE.Mesh.prototype=new THREE.Object3D;THREE.Mesh.prototype.constructor=THREE.Mesh;
-THREE.Mesh.prototype.normalizeUVs=function(){var a,b,d,g,j;a=0;for(b=this.geometry.uvs.length;a<b;a++){j=this.geometry.uvs[a];d=0;for(g=j.length;d<g;d++){if(j[d].u!=1)j[d].u-=Math.floor(j[d].u);if(j[d].v!=1)j[d].v-=Math.floor(j[d].v)}}};THREE.FlatShading=0;THREE.SmoothShading=1;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;
+THREE.Mesh.prototype.normalizeUVs=function(){var a,b,d,f,j;a=0;for(b=this.geometry.uvs.length;a<b;a++){j=this.geometry.uvs[a];d=0;for(f=j.length;d<f;d++){if(j[d].u!=1)j[d].u-=Math.floor(j[d].u);if(j[d].v!=1)j[d].v-=Math.floor(j[d].v)}}};THREE.FlatShading=0;THREE.SmoothShading=1;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;
 THREE.LineBasicMaterial=function(a){this.color=new THREE.Color(16711680);this.opacity=1;this.blending=THREE.NormalBlending;this.linewidth=1;this.linejoin=this.linecap="round";if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending;if(a.linewidth!==undefined)this.linewidth=a.linewidth;if(a.linecap!==undefined)this.linecap=a.linecap;if(a.linejoin!==undefined)this.linejoin=a.linejoin}this.toString=function(){return"THREE.LineBasicMaterial (<br/>color: "+
 this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>linewidth: "+this.linewidth+"<br/>linecap: "+this.linecap+"<br/>linejoin: "+this.linejoin+"<br/>)"}};
 THREE.MeshBasicMaterial=function(a){this.id=THREE.MeshBasicMaterialCounter.value++;this.color=new THREE.Color(15658734);this.env_map=this.map=null;this.combine=THREE.MultiplyOperation;this.reflectivity=1;this.refraction_ratio=0.98;this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=this.wireframe_linecap="round";if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.map!==undefined)this.map=
@@ -82,92 +85,94 @@ undefined)this.uniforms=a.uniforms;if(a.shading!==undefined)this.shading=a.shadi
 THREE.ParticleBasicMaterial=function(a){this.color=new THREE.Color(16711680);this.map=null;this.opacity=1;this.blending=THREE.NormalBlending;this.offset=new THREE.Vector2;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.map!==undefined)this.map=a.map;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}this.toString=function(){return"THREE.ParticleBasicMaterial (<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>opacity: "+this.opacity+"<br/>blending: "+
 this.blending+"<br/>)"}};THREE.ParticleCircleMaterial=function(a){this.color=new THREE.Color(16711680);this.opacity=1;this.blending=THREE.NormalBlending;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}this.toString=function(){return"THREE.ParticleCircleMaterial (<br/>color: "+this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>)"}};
 THREE.ParticleDOMMaterial=function(a){this.domElement=a;this.toString=function(){return"THREE.ParticleDOMMaterial ( domElement: "+this.domElement+" )"}};
-THREE.Texture=function(a,b,d,g,j,n){this.image=a;this.mapping=b!==undefined?b:new THREE.UVMapping;this.wrap_s=d!==undefined?d:THREE.ClampToEdgeWrapping;this.wrap_t=g!==undefined?g:THREE.ClampToEdgeWrapping;this.mag_filter=j!==undefined?j:THREE.LinearFilter;this.min_filter=n!==undefined?n:THREE.LinearMipMapLinearFilter;this.toString=function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>wrap_s: "+this.wrap_s+"<br/>wrap_t: "+this.wrap_t+"<br/>mag_filter: "+this.mag_filter+"<br/>min_filter: "+
+THREE.Texture=function(a,b,d,f,j,m){this.image=a;this.mapping=b!==undefined?b:new THREE.UVMapping;this.wrap_s=d!==undefined?d:THREE.ClampToEdgeWrapping;this.wrap_t=f!==undefined?f:THREE.ClampToEdgeWrapping;this.mag_filter=j!==undefined?j:THREE.LinearFilter;this.min_filter=m!==undefined?m:THREE.LinearMipMapLinearFilter;this.toString=function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>wrap_s: "+this.wrap_s+"<br/>wrap_t: "+this.wrap_t+"<br/>mag_filter: "+this.mag_filter+"<br/>min_filter: "+
 this.min_filter+"<br/>)"}};THREE.MultiplyOperation=0;THREE.MixOperation=1;THREE.RepeatWrapping=0;THREE.ClampToEdgeWrapping=1;THREE.MirroredRepeatWrapping=2;THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLinearFilter=5;THREE.LinearFilter=6;THREE.LinearMipMapNearestFilter=7;THREE.LinearMipMapLinearFilter=8;THREE.CubeReflectionMapping=function(){};THREE.CubeRefractionMapping=function(){};THREE.LatitudeReflectionMapping=function(){};THREE.LatitudeRefractionMapping=function(){};
 THREE.SphericalReflectionMapping=function(){};THREE.SphericalRefractionMapping=function(){};THREE.UVMapping=function(){};
 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(O,v){var f=0,l=1,e=O.z+O.w,q=v.z+v.w,h=-O.z+O.w,i=-v.z+v.w;if(e>=0&&q>=0&&h>=0&&i>=0)return true;else if(e<0&&q<0||h<0&&i<0)return false;else{if(e<0)f=Math.max(f,e/(e-q));else if(q<0)l=Math.min(l,e/(e-q));if(h<0)f=Math.max(f,h/(h-i));else if(i<0)l=Math.min(l,h/(h-i));if(l<f)return false;else{O.lerpSelf(v,f);v.lerpSelf(O,1-l);return true}}}var b=null,d,g,j,n=[],m,k,o=[],c,F,D=[],w=new THREE.Vector4,x=new THREE.Matrix4,I=new THREE.Matrix4,G=new THREE.Vector4,L=
-new THREE.Vector4,N;this.projectScene=function(O,v){var f,l,e,q,h,i,s,r,M,B,H,Q,u,R,y,A,E;b=[];j=k=F=0;v.autoUpdateMatrix&&v.updateMatrix();x.multiply(v.projectionMatrix,v.matrix);s=O.objects;f=0;for(l=s.length;f<l;f++){r=s[f];r.autoUpdateMatrix&&r.updateMatrix();M=r.matrix;B=r.rotationMatrix;H=r.material;Q=r.overdraw;if(r instanceof THREE.Mesh){u=r.geometry.vertices;e=0;for(q=u.length;e<q;e++){R=u[e];R.positionWorld.copy(R.position);M.multiplyVector3(R.positionWorld);y=R.positionScreen;y.copy(R.positionWorld);
-x.multiplyVector4(y);y.multiplyScalar(1/y.w);R.__visible=y.z>0&&y.z<1}R=r.geometry.faces;e=0;for(q=R.length;e<q;e++){y=R[e];if(y instanceof THREE.Face3){h=u[y.a];i=u[y.b];A=u[y.c];if(h.__visible&&i.__visible&&A.__visible)if(r.doubleSided||r.flipSided!=(A.positionScreen.x-h.positionScreen.x)*(i.positionScreen.y-h.positionScreen.y)-(A.positionScreen.y-h.positionScreen.y)*(i.positionScreen.x-h.positionScreen.x)<0){d=n[j]=n[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(h.positionWorld);d.v2.positionWorld.copy(i.positionWorld);
-d.v3.positionWorld.copy(A.positionWorld);d.v1.positionScreen.copy(h.positionScreen);d.v2.positionScreen.copy(i.positionScreen);d.v3.positionScreen.copy(A.positionScreen);d.normalWorld.copy(y.normal);B.multiplyVector3(d.normalWorld);d.centroidWorld.copy(y.centroid);M.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);x.multiplyVector3(d.centroidScreen);A=y.vertexNormals;N=d.vertexNormalsWorld;h=0;for(i=A.length;h<i;h++){E=N[h]=N[h]||new THREE.Vector3;E.copy(A[h]);B.multiplyVector3(E)}d.z=
-d.centroidScreen.z;d.meshMaterial=H;d.faceMaterial=y.material;d.overdraw=Q;if(r.geometry.uvs[e]){d.uvs[0]=r.geometry.uvs[e][0];d.uvs[1]=r.geometry.uvs[e][1];d.uvs[2]=r.geometry.uvs[e][2]}b.push(d);j++}}else if(y instanceof THREE.Face4){h=u[y.a];i=u[y.b];A=u[y.c];E=u[y.d];if(h.__visible&&i.__visible&&A.__visible&&E.__visible)if(r.doubleSided||r.flipSided!=((E.positionScreen.x-h.positionScreen.x)*(i.positionScreen.y-h.positionScreen.y)-(E.positionScreen.y-h.positionScreen.y)*(i.positionScreen.x-h.positionScreen.x)<
-0||(i.positionScreen.x-A.positionScreen.x)*(E.positionScreen.y-A.positionScreen.y)-(i.positionScreen.y-A.positionScreen.y)*(E.positionScreen.x-A.positionScreen.x)<0)){d=n[j]=n[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(h.positionWorld);d.v2.positionWorld.copy(i.positionWorld);d.v3.positionWorld.copy(E.positionWorld);d.v1.positionScreen.copy(h.positionScreen);d.v2.positionScreen.copy(i.positionScreen);d.v3.positionScreen.copy(E.positionScreen);d.normalWorld.copy(y.normal);B.multiplyVector3(d.normalWorld);
-d.centroidWorld.copy(y.centroid);M.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);x.multiplyVector3(d.centroidScreen);d.z=d.centroidScreen.z;d.meshMaterial=H;d.faceMaterial=y.material;d.overdraw=Q;if(r.geometry.uvs[e]){d.uvs[0]=r.geometry.uvs[e][0];d.uvs[1]=r.geometry.uvs[e][1];d.uvs[2]=r.geometry.uvs[e][3]}b.push(d);j++;g=n[j]=n[j]||new THREE.RenderableFace3;g.v1.positionWorld.copy(i.positionWorld);g.v2.positionWorld.copy(A.positionWorld);g.v3.positionWorld.copy(E.positionWorld);
-g.v1.positionScreen.copy(i.positionScreen);g.v2.positionScreen.copy(A.positionScreen);g.v3.positionScreen.copy(E.positionScreen);g.normalWorld.copy(d.normalWorld);g.centroidWorld.copy(d.centroidWorld);g.centroidScreen.copy(d.centroidScreen);g.z=g.centroidScreen.z;g.meshMaterial=H;g.faceMaterial=y.material;g.overdraw=Q;if(r.geometry.uvs[e]){g.uvs[0]=r.geometry.uvs[e][1];g.uvs[1]=r.geometry.uvs[e][2];g.uvs[2]=r.geometry.uvs[e][3]}b.push(g);j++}}}}else if(r instanceof THREE.Line){I.multiply(x,M);u=r.geometry.vertices;
-R=u[0];R.positionScreen.copy(R.position);I.multiplyVector4(R.positionScreen);e=1;for(q=u.length;e<q;e++){h=u[e];h.positionScreen.copy(h.position);I.multiplyVector4(h.positionScreen);i=u[e-1];G.copy(h.positionScreen);L.copy(i.positionScreen);if(a(G,L)){G.multiplyScalar(1/G.w);L.multiplyScalar(1/L.w);m=o[k]=o[k]||new THREE.RenderableLine;m.v1.positionScreen.copy(G);m.v2.positionScreen.copy(L);m.z=Math.max(G.z,L.z);m.material=r.material;b.push(m);k++}}}else if(r instanceof THREE.Particle){w.set(r.position.x,
-r.position.y,r.position.z,1);x.multiplyVector4(w);w.z/=w.w;if(w.z>0&&w.z<1){c=D[F]=D[F]||new THREE.RenderableParticle;c.x=w.x/w.w;c.y=w.y/w.w;c.z=w.z;c.rotation=r.rotation.z;c.scale.x=r.scale.x*Math.abs(c.x-(w.x+v.projectionMatrix.n11)/(w.w+v.projectionMatrix.n14));c.scale.y=r.scale.y*Math.abs(c.y-(w.y+v.projectionMatrix.n22)/(w.w+v.projectionMatrix.n24));c.material=r.material;b.push(c);F++}}}b.sort(function(W,J){return J.z-W.z});return b};this.unprojectVector=function(O,v){var f=new THREE.Matrix4;
-f.multiply(THREE.Matrix4.makeInvert(v.matrix),THREE.Matrix4.makeInvert(v.projectionMatrix));f.multiplyVector3(O);return O}};
-THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,d,g,j,n;this.domElement=document.createElement("div");this.setSize=function(m,k){d=m;g=k;j=d/2;n=g/2};this.render=function(m,k){var o,c,F,D,w,x,I,G;a=b.projectScene(m,k);o=0;for(c=a.length;o<c;o++){w=a[o];if(w instanceof THREE.RenderableParticle){I=w.x*j+j;G=w.y*n+n;F=0;for(D=w.material.length;F<D;F++){x=w.material[F];if(x instanceof THREE.ParticleDOMMaterial){x=x.domElement;x.style.left=I+"px";x.style.top=G+"px"}}}}}};
-THREE.CanvasRenderer=function(){var a=null,b=new THREE.Projector,d=document.createElement("canvas"),g,j,n,m,k=d.getContext("2d"),o=1,c=0,F=null,D=null,w=1,x=Math.min,I=Math.max,G,L,N,O,v,f,l,e,q,h=new THREE.Color,i=new THREE.Color,s=new THREE.Color,r=new THREE.Color,M=new THREE.Color,B,H,Q,u,R,y,A,E,W,J,z=new THREE.Rectangle,S=new THREE.Rectangle,X=new THREE.Rectangle,T=false,P=new THREE.Color,Z=new THREE.Color,ia=new THREE.Color,ja=new THREE.Color,La=Math.PI*2,Y=new THREE.Vector3,na,oa,Ca,ba,pa,
-va,la=16;na=document.createElement("canvas");na.width=na.height=2;oa=na.getContext("2d");oa.fillStyle="rgba(0,0,0,1)";oa.fillRect(0,0,2,2);Ca=oa.getImageData(0,0,2,2);ba=Ca.data;pa=document.createElement("canvas");pa.width=pa.height=la;va=pa.getContext("2d");va.translate(-la/2,-la/2);va.scale(la,la);la--;this.domElement=d;this.autoClear=true;this.setSize=function(fa,wa){g=fa;j=wa;n=g/2;m=j/2;d.width=g;d.height=j;z.set(-n,-m,n,m)};this.clear=function(){if(!S.isEmpty()){S.inflate(1);S.minSelf(z);k.clearRect(S.getX(),
-S.getY(),S.getWidth(),S.getHeight());S.empty()}};this.render=function(fa,wa){function Ma(p){var U,K,t,C=p.lights;Z.setRGB(0,0,0);ia.setRGB(0,0,0);ja.setRGB(0,0,0);p=0;for(U=C.length;p<U;p++){K=C[p];t=K.color;if(K instanceof THREE.AmbientLight){Z.r+=t.r;Z.g+=t.g;Z.b+=t.b}else if(K instanceof THREE.DirectionalLight){ia.r+=t.r;ia.g+=t.g;ia.b+=t.b}else if(K instanceof THREE.PointLight){ja.r+=t.r;ja.g+=t.g;ja.b+=t.b}}}function xa(p,U,K,t){var C,V,aa,ca,da=p.lights;p=0;for(C=da.length;p<C;p++){V=da[p];
-aa=V.color;ca=V.intensity;if(V instanceof THREE.DirectionalLight){V=K.dot(V.position)*ca;if(V>0){t.r+=aa.r*V;t.g+=aa.g*V;t.b+=aa.b*V}}else if(V instanceof THREE.PointLight){Y.sub(V.position,U);Y.normalize();V=K.dot(Y)*ca;if(V>0){t.r+=aa.r*V;t.g+=aa.g*V;t.b+=aa.b*V}}}}function Na(p,U,K){if(K.opacity!=0){Da(K.opacity);ya(K.blending);var t,C,V,aa,ca,da;if(K instanceof THREE.ParticleBasicMaterial){if(K.map){aa=K.map;ca=aa.width>>1;da=aa.height>>1;C=U.scale.x*n;V=U.scale.y*m;K=C*ca;t=V*da;X.set(p.x-K,
-p.y-t,p.x+K,p.y+t);if(!z.instersects(X))return;k.save();k.translate(p.x,p.y);k.rotate(-U.rotation);k.scale(C,-V);k.translate(-ca,-da);k.drawImage(aa,0,0);k.restore()}k.beginPath();k.moveTo(p.x-10,p.y);k.lineTo(p.x+10,p.y);k.moveTo(p.x,p.y-10);k.lineTo(p.x,p.y+10);k.closePath();k.strokeStyle="rgb(255,255,0)";k.stroke()}else if(K instanceof THREE.ParticleCircleMaterial){if(T){P.r=Z.r+ia.r+ja.r;P.g=Z.g+ia.g+ja.g;P.b=Z.b+ia.b+ja.b;h.r=K.color.r*P.r;h.g=K.color.g*P.g;h.b=K.color.b*P.b;h.updateStyleString()}else h.__styleString=
-K.color.__styleString;K=U.scale.x*n;t=U.scale.y*m;X.set(p.x-K,p.y-t,p.x+K,p.y+t);if(z.instersects(X)){C=h.__styleString;if(D!=C)k.fillStyle=D=C;k.save();k.translate(p.x,p.y);k.rotate(-U.rotation);k.scale(K,t);k.beginPath();k.arc(0,0,1,0,La,true);k.closePath();k.fill();k.restore()}}}}function Oa(p,U,K,t){if(t.opacity!=0){Da(t.opacity);ya(t.blending);k.beginPath();k.moveTo(p.positionScreen.x,p.positionScreen.y);k.lineTo(U.positionScreen.x,U.positionScreen.y);k.closePath();if(t instanceof THREE.LineBasicMaterial){h.__styleString=
-t.color.__styleString;p=t.linewidth;if(w!=p)k.lineWidth=w=p;p=h.__styleString;if(F!=p)k.strokeStyle=F=p;k.stroke();X.inflate(t.linewidth*2)}}}function Ha(p,U,K,t,C,V){if(C.opacity!=0){Da(C.opacity);ya(C.blending);O=p.positionScreen.x;v=p.positionScreen.y;f=U.positionScreen.x;l=U.positionScreen.y;e=K.positionScreen.x;q=K.positionScreen.y;k.beginPath();k.moveTo(O,v);k.lineTo(f,l);k.lineTo(e,q);k.lineTo(O,v);k.closePath();if(C instanceof THREE.MeshBasicMaterial)if(C.map)C.map.image.loaded&&C.map.mapping instanceof
-THREE.UVMapping&&qa(O,v,f,l,e,q,C.map.image,t.uvs[0].u,t.uvs[0].v,t.uvs[1].u,t.uvs[1].v,t.uvs[2].u,t.uvs[2].v);else if(C.env_map){if(C.env_map.image.loaded)if(C.env_map.mapping instanceof THREE.SphericalReflectionMapping){p=wa.matrix;Y.copy(t.vertexNormalsWorld[0]);R=(Y.x*p.n11+Y.y*p.n12+Y.z*p.n13)*0.5+0.5;y=-(Y.x*p.n21+Y.y*p.n22+Y.z*p.n23)*0.5+0.5;Y.copy(t.vertexNormalsWorld[1]);A=(Y.x*p.n11+Y.y*p.n12+Y.z*p.n13)*0.5+0.5;E=-(Y.x*p.n21+Y.y*p.n22+Y.z*p.n23)*0.5+0.5;Y.copy(t.vertexNormalsWorld[2]);W=
-(Y.x*p.n11+Y.y*p.n12+Y.z*p.n13)*0.5+0.5;J=-(Y.x*p.n21+Y.y*p.n22+Y.z*p.n23)*0.5+0.5;qa(O,v,f,l,e,q,C.env_map.image,R,y,A,E,W,J)}}else C.wireframe?za(C.color.__styleString,C.wireframe_linewidth):Aa(C.color.__styleString);else if(C instanceof THREE.MeshLambertMaterial){if(C.map&&!C.wireframe){C.map.mapping instanceof THREE.UVMapping&&qa(O,v,f,l,e,q,C.map.image,t.uvs[0].u,t.uvs[0].v,t.uvs[1].u,t.uvs[1].v,t.uvs[2].u,t.uvs[2].v);ya(THREE.SubtractiveBlending)}if(T)if(!C.wireframe&&C.shading==THREE.SmoothShading&&
-t.vertexNormalsWorld.length==3){i.r=s.r=r.r=Z.r;i.g=s.g=r.g=Z.g;i.b=s.b=r.b=Z.b;xa(V,t.v1.positionWorld,t.vertexNormalsWorld[0],i);xa(V,t.v2.positionWorld,t.vertexNormalsWorld[1],s);xa(V,t.v3.positionWorld,t.vertexNormalsWorld[2],r);M.r=(s.r+r.r)*0.5;M.g=(s.g+r.g)*0.5;M.b=(s.b+r.b)*0.5;u=Ia(i,s,r,M);qa(O,v,f,l,e,q,u,0,0,1,0,0,1)}else{P.r=Z.r;P.g=Z.g;P.b=Z.b;xa(V,t.centroidWorld,t.normalWorld,P);h.r=C.color.r*P.r;h.g=C.color.g*P.g;h.b=C.color.b*P.b;h.updateStyleString();C.wireframe?za(h.__styleString,
-C.wireframe_linewidth):Aa(h.__styleString)}else C.wireframe?za(C.color.__styleString,C.wireframe_linewidth):Aa(C.color.__styleString)}else if(C instanceof THREE.MeshDepthMaterial){B=C.__2near;H=C.__farPlusNear;Q=C.__farMinusNear;i.r=i.g=i.b=1-B/(H-p.positionScreen.z*Q);s.r=s.g=s.b=1-B/(H-U.positionScreen.z*Q);r.r=r.g=r.b=1-B/(H-K.positionScreen.z*Q);M.r=(s.r+r.r)*0.5;M.g=(s.g+r.g)*0.5;M.b=(s.b+r.b)*0.5;u=Ia(i,s,r,M);qa(O,v,f,l,e,q,u,0,0,1,0,0,1)}else if(C instanceof THREE.MeshNormalMaterial){h.r=
-Ea(t.normalWorld.x);h.g=Ea(t.normalWorld.y);h.b=Ea(t.normalWorld.z);h.updateStyleString();C.wireframe?za(h.__styleString,C.wireframe_linewidth):Aa(h.__styleString)}}}function za(p,U){if(F!=p)k.strokeStyle=F=p;if(w!=U)k.lineWidth=w=U;k.stroke();X.inflate(U*2)}function Aa(p){if(D!=p)k.fillStyle=D=p;k.fill()}function qa(p,U,K,t,C,V,aa,ca,da,ra,ha,sa,ta){var ka,ga;ka=aa.width-1;ga=aa.height-1;ca*=ka;da*=ga;ra*=ka;ha*=ga;sa*=ka;ta*=ga;K-=p;t-=U;C-=p;V-=U;ra-=ca;ha-=da;sa-=ca;ta-=da;ga=1/(ra*ta-sa*ha);
-ka=(ta*K-ha*C)*ga;ha=(ta*t-ha*V)*ga;K=(ra*C-sa*K)*ga;t=(ra*V-sa*t)*ga;p=p-ka*ca-K*da;U=U-ha*ca-t*da;k.save();k.transform(ka,ha,K,t,p,U);k.clip();k.drawImage(aa,0,0);k.restore()}function Da(p){if(o!=p)k.globalAlpha=o=p}function ya(p){if(c!=p){switch(p){case THREE.NormalBlending:k.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:k.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:k.globalCompositeOperation="darker"}c=p}}function Ia(p,U,K,t){ba[0]=I(0,x(255,
-~~(p.r*255)));ba[1]=I(0,x(255,~~(p.g*255)));ba[2]=I(0,x(255,~~(p.b*255)));ba[4]=I(0,x(255,~~(U.r*255)));ba[5]=I(0,x(255,~~(U.g*255)));ba[6]=I(0,x(255,~~(U.b*255)));ba[8]=I(0,x(255,~~(K.r*255)));ba[9]=I(0,x(255,~~(K.g*255)));ba[10]=I(0,x(255,~~(K.b*255)));ba[12]=I(0,x(255,~~(t.r*255)));ba[13]=I(0,x(255,~~(t.g*255)));ba[14]=I(0,x(255,~~(t.b*255)));oa.putImageData(Ca,0,0);va.drawImage(na,0,0);return pa}function Ea(p){return p<0?x((1+p)*0.5,0.5):0.5+x(p*0.5,0.5)}function Fa(p,U){var K=U.x-p.x,t=U.y-p.y,
-C=1/Math.sqrt(K*K+t*t);K*=C;t*=C;U.x+=K;U.y+=t;p.x-=K;p.y-=t}var Ba,Ja,$,ea,ma,Ga,Ka,ua;k.setTransform(1,0,0,-1,n,m);this.autoClear&&this.clear();a=b.projectScene(fa,wa);k.fillStyle="rgba(0, 255, 255, 0.5)";k.fillRect(z.getX(),z.getY(),z.getWidth(),z.getHeight());(T=fa.lights.length>0)&&Ma(fa);Ba=0;for(Ja=a.length;Ba<Ja;Ba++){$=a[Ba];X.empty();if($ instanceof THREE.RenderableParticle){G=$;G.x*=n;G.y*=m;ea=0;for(ma=$.material.length;ea<ma;ea++)Na(G,$,$.material[ea],fa)}else if($ instanceof THREE.RenderableLine){G=
-$.v1;L=$.v2;G.positionScreen.x*=n;G.positionScreen.y*=m;L.positionScreen.x*=n;L.positionScreen.y*=m;X.addPoint(G.positionScreen.x,G.positionScreen.y);X.addPoint(L.positionScreen.x,L.positionScreen.y);if(z.instersects(X)){ea=0;for(ma=$.material.length;ea<ma;)Oa(G,L,$,$.material[ea++],fa)}}else if($ instanceof THREE.RenderableFace3){G=$.v1;L=$.v2;N=$.v3;G.positionScreen.x*=n;G.positionScreen.y*=m;L.positionScreen.x*=n;L.positionScreen.y*=m;N.positionScreen.x*=n;N.positionScreen.y*=m;if($.overdraw){Fa(G.positionScreen,
-L.positionScreen);Fa(L.positionScreen,N.positionScreen);Fa(N.positionScreen,G.positionScreen)}X.addPoint(G.positionScreen.x,G.positionScreen.y);X.addPoint(L.positionScreen.x,L.positionScreen.y);X.addPoint(N.positionScreen.x,N.positionScreen.y);if(z.instersects(X)){ea=0;for(ma=$.meshMaterial.length;ea<ma;){ua=$.meshMaterial[ea++];if(ua instanceof THREE.MeshFaceMaterial){Ga=0;for(Ka=$.faceMaterial.length;Ga<Ka;)(ua=$.faceMaterial[Ga++])&&Ha(G,L,N,$,ua,fa)}else Ha(G,L,N,$,ua,fa)}}}S.addRectangle(X)}k.lineWidth=
-1;k.strokeStyle="rgba( 255, 0, 0, 0.5 )";k.strokeRect(S.getX(),S.getY(),S.getWidth(),S.getHeight());k.setTransform(1,0,0,1,0,0)}};
-THREE.SVGRenderer=function(){function a(y,A,E){var W,J,z,S;W=0;for(J=y.lights.length;W<J;W++){z=y.lights[W];if(z instanceof THREE.DirectionalLight){S=A.normalWorld.dot(z.position)*z.intensity;if(S>0){E.r+=z.color.r*S;E.g+=z.color.g*S;E.b+=z.color.b*S}}else if(z instanceof THREE.PointLight){i.sub(z.position,A.centroidWorld);i.normalize();S=A.normalWorld.dot(i)*z.intensity;if(S>0){E.r+=z.color.r*S;E.g+=z.color.g*S;E.b+=z.color.b*S}}}}function b(y,A,E,W,J,z){B=g(H++);B.setAttribute("d","M "+y.positionScreen.x+
-" "+y.positionScreen.y+" L "+A.positionScreen.x+" "+A.positionScreen.y+" L "+E.positionScreen.x+","+E.positionScreen.y+"z");if(J instanceof THREE.MeshBasicMaterial)v.__styleString=J.color.__styleString;else if(J instanceof THREE.MeshLambertMaterial)if(O){f.r=l.r;f.g=l.g;f.b=l.b;a(z,W,f);v.r=J.color.r*f.r;v.g=J.color.g*f.g;v.b=J.color.b*f.b;v.updateStyleString()}else v.__styleString=J.color.__styleString;else if(J instanceof THREE.MeshDepthMaterial){h=1-J.__2near/(J.__farPlusNear-W.z*J.__farMinusNear);
-v.setRGB(h,h,h)}else J instanceof THREE.MeshNormalMaterial&&v.setRGB(j(W.normalWorld.x),j(W.normalWorld.y),j(W.normalWorld.z));J.wireframe?B.setAttribute("style","fill: none; stroke: "+v.__styleString+"; stroke-width: "+J.wireframe_linewidth+"; stroke-opacity: "+J.opacity+"; stroke-linecap: "+J.wireframe_linecap+"; stroke-linejoin: "+J.wireframe_linejoin):B.setAttribute("style","fill: "+v.__styleString+"; fill-opacity: "+J.opacity);k.appendChild(B)}function d(y,A,E,W,J,z,S){B=g(H++);B.setAttribute("d",
-"M "+y.positionScreen.x+" "+y.positionScreen.y+" L "+A.positionScreen.x+" "+A.positionScreen.y+" L "+E.positionScreen.x+","+E.positionScreen.y+" L "+W.positionScreen.x+","+W.positionScreen.y+"z");if(z instanceof THREE.MeshBasicMaterial)v.__styleString=z.color.__styleString;else if(z instanceof THREE.MeshLambertMaterial)if(O){f.r=l.r;f.g=l.g;f.b=l.b;a(S,J,f);v.r=z.color.r*f.r;v.g=z.color.g*f.g;v.b=z.color.b*f.b;v.updateStyleString()}else v.__styleString=z.color.__styleString;else if(z instanceof THREE.MeshDepthMaterial){h=
-1-z.__2near/(z.__farPlusNear-J.z*z.__farMinusNear);v.setRGB(h,h,h)}else z instanceof THREE.MeshNormalMaterial&&v.setRGB(j(J.normalWorld.x),j(J.normalWorld.y),j(J.normalWorld.z));z.wireframe?B.setAttribute("style","fill: none; stroke: "+v.__styleString+"; stroke-width: "+z.wireframe_linewidth+"; stroke-opacity: "+z.opacity+"; stroke-linecap: "+z.wireframe_linecap+"; stroke-linejoin: "+z.wireframe_linejoin):B.setAttribute("style","fill: "+v.__styleString+"; fill-opacity: "+z.opacity);k.appendChild(B)}
-function g(y){if(s[y]==null){s[y]=document.createElementNS("http://www.w3.org/2000/svg","path");R==0&&s[y].setAttribute("shape-rendering","crispEdges");return s[y]}return s[y]}function j(y){return y<0?Math.min((1+y)*0.5,0.5):0.5+Math.min(y*0.5,0.5)}var n=null,m=new THREE.Projector,k=document.createElementNS("http://www.w3.org/2000/svg","svg"),o,c,F,D,w,x,I,G,L=new THREE.Rectangle,N=new THREE.Rectangle,O=false,v=new THREE.Color(16777215),f=new THREE.Color(16777215),l=new THREE.Color(0),e=new THREE.Color(0),
-q=new THREE.Color(0),h,i=new THREE.Vector3,s=[],r=[],M=[],B,H,Q,u,R=1;this.domElement=k;this.autoClear=true;this.setQuality=function(y){switch(y){case "high":R=1;break;case "low":R=0}};this.setSize=function(y,A){o=y;c=A;F=o/2;D=c/2;k.setAttribute("viewBox",-F+" "+-D+" "+o+" "+c);k.setAttribute("width",o);k.setAttribute("height",c);L.set(-F,-D,F,D)};this.clear=function(){for(;k.childNodes.length>0;)k.removeChild(k.childNodes[0])};this.render=function(y,A){var E,W,J,z,S,X,T,P;this.autoClear&&this.clear();
-n=m.projectScene(y,A);u=Q=H=0;if(O=y.lights.length>0){T=y.lights;l.setRGB(0,0,0);e.setRGB(0,0,0);q.setRGB(0,0,0);E=0;for(W=T.length;E<W;E++){J=T[E];z=J.color;if(J instanceof THREE.AmbientLight){l.r+=z.r;l.g+=z.g;l.b+=z.b}else if(J instanceof THREE.DirectionalLight){e.r+=z.r;e.g+=z.g;e.b+=z.b}else if(J instanceof THREE.PointLight){q.r+=z.r;q.g+=z.g;q.b+=z.b}}}E=0;for(W=n.length;E<W;E++){T=n[E];N.empty();if(T instanceof THREE.RenderableParticle){w=T;w.x*=F;w.y*=-D;J=0;for(z=T.material.length;J<z;J++)if(P=
-T.material[J]){S=w;X=T;P=P;var Z=Q++;if(r[Z]==null){r[Z]=document.createElementNS("http://www.w3.org/2000/svg","circle");R==0&&r[Z].setAttribute("shape-rendering","crispEdges")}B=r[Z];B.setAttribute("cx",S.x);B.setAttribute("cy",S.y);B.setAttribute("r",X.scale.x*F);if(P instanceof THREE.ParticleCircleMaterial){if(O){f.r=l.r+e.r+q.r;f.g=l.g+e.g+q.g;f.b=l.b+e.b+q.b;v.r=P.color.r*f.r;v.g=P.color.g*f.g;v.b=P.color.b*f.b;v.updateStyleString()}else v=P.color;B.setAttribute("style","fill: "+v.__styleString)}k.appendChild(B)}}else if(T instanceof
-THREE.RenderableLine){w=T.v1;x=T.v2;w.positionScreen.x*=F;w.positionScreen.y*=-D;x.positionScreen.x*=F;x.positionScreen.y*=-D;N.addPoint(w.positionScreen.x,w.positionScreen.y);N.addPoint(x.positionScreen.x,x.positionScreen.y);if(L.instersects(N)){J=0;for(z=T.material.length;J<z;)if(P=T.material[J++]){S=w;X=x;P=P;Z=u++;if(M[Z]==null){M[Z]=document.createElementNS("http://www.w3.org/2000/svg","line");R==0&&M[Z].setAttribute("shape-rendering","crispEdges")}B=M[Z];B.setAttribute("x1",S.positionScreen.x);
-B.setAttribute("y1",S.positionScreen.y);B.setAttribute("x2",X.positionScreen.x);B.setAttribute("y2",X.positionScreen.y);if(P instanceof THREE.LineBasicMaterial){v.__styleString=P.color.__styleString;B.setAttribute("style","fill: none; stroke: "+v.__styleString+"; stroke-width: "+P.linewidth+"; stroke-opacity: "+P.opacity+"; stroke-linecap: "+P.linecap+"; stroke-linejoin: "+P.linejoin);k.appendChild(B)}}}}else if(T instanceof THREE.RenderableFace3){w=T.v1;x=T.v2;I=T.v3;w.positionScreen.x*=F;w.positionScreen.y*=
--D;x.positionScreen.x*=F;x.positionScreen.y*=-D;I.positionScreen.x*=F;I.positionScreen.y*=-D;N.addPoint(w.positionScreen.x,w.positionScreen.y);N.addPoint(x.positionScreen.x,x.positionScreen.y);N.addPoint(I.positionScreen.x,I.positionScreen.y);if(L.instersects(N)){J=0;for(z=T.meshMaterial.length;J<z;){P=T.meshMaterial[J++];if(P instanceof THREE.MeshFaceMaterial){S=0;for(X=T.faceMaterial.length;S<X;)(P=T.faceMaterial[S++])&&b(w,x,I,T,P,y)}else P&&b(w,x,I,T,P,y)}}}else if(T instanceof THREE.RenderableFace4){w=
-T.v1;x=T.v2;I=T.v3;G=T.v4;w.positionScreen.x*=F;w.positionScreen.y*=-D;x.positionScreen.x*=F;x.positionScreen.y*=-D;I.positionScreen.x*=F;I.positionScreen.y*=-D;G.positionScreen.x*=F;G.positionScreen.y*=-D;N.addPoint(w.positionScreen.x,w.positionScreen.y);N.addPoint(x.positionScreen.x,x.positionScreen.y);N.addPoint(I.positionScreen.x,I.positionScreen.y);N.addPoint(G.positionScreen.x,G.positionScreen.y);if(L.instersects(N)){J=0;for(z=T.meshMaterial.length;J<z;){P=T.meshMaterial[J++];if(P instanceof
-THREE.MeshFaceMaterial){S=0;for(X=T.faceMaterial.length;S<X;)(P=T.faceMaterial[S++])&&d(w,x,I,G,T,P,y)}else P&&d(w,x,I,G,T,P,y)}}}}}};
-THREE.WebGLRenderer=function(a){function b(f,l){var e=c.createProgram();c.attachShader(e,m("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\nuniform mat4 viewMatrix;\n"+f));c.attachShader(e,m("vertex","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"+l));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,l){if(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+l);c.bindTexture(c.TEXTURE_CUBE_MAP,f.image.__webGLTextureCube)}}function g(f,
-l){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,k(f.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,k(f.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,k(f.mag_filter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,k(f.min_filter));c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+
-l);c.bindTexture(c.TEXTURE_2D,f.__webGLTexture)}function j(f,l){var e,q,h;e=0;for(q=l.length;e<q;e++){h=l[e];f.uniforms[h]=c.getUniformLocation(f,h)}}function n(f,l){var e,q,h;e=0;for(q=l.length;e<q;e++){h=l[e];f.attributes[h]=c.getAttribLocation(f,h);f.attributes[h]>=0&&c.enableVertexAttribArray(f.attributes[h])}}function m(f,l){var e;if(f=="fragment")e=c.createShader(c.FRAGMENT_SHADER);else if(f=="vertex")e=c.createShader(c.VERTEX_SHADER);c.shaderSource(e,l);c.compileShader(e);if(!c.getShaderParameter(e,
-c.COMPILE_STATUS)){alert(c.getShaderInfoLog(e));return null}return e}function k(f){switch(f){case THREE.RepeatWrapping:return c.REPEAT;case THREE.ClampToEdgeWrapping:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return c.MIRRORED_REPEAT;case THREE.NearestFilter:return c.NEAREST;case THREE.NearestMipMapNearestFilter:return c.NEAREST_MIPMAP_NEAREST;case THREE.NearestMipMapLinearFilter:return c.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return c.LINEAR;case THREE.LinearMipMapNearestFilter:return c.LINEAR_MIPMAP_NEAREST;
-case THREE.LinearMipMapLinearFilter:return c.LINEAR_MIPMAP_LINEAR}return 0}var o=document.createElement("canvas"),c,F,D,w=new THREE.Matrix4,x,I=new Float32Array(16),G=new Float32Array(16),L=new Float32Array(16),N=new Float32Array(9),O=new Float32Array(16);a=function(f,l){if(f){var e,q,h,i=pointLights=maxDirLights=maxPointLights=0;e=0;for(q=f.lights.length;e<q;e++){h=f.lights[e];h instanceof THREE.DirectionalLight&&i++;h instanceof THREE.PointLight&&pointLights++}if(pointLights+i<=l){maxDirLights=
-i;maxPointLights=pointLights}else{maxDirLights=Math.ceil(l*i/(pointLights+i));maxPointLights=l-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:l-1}}(a,4);this.domElement=o;this.autoClear=true;try{c=o.getContext("experimental-webgl",{antialias:true})}catch(v){}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);F=D=function(f,l){var e=[f?"#define MAX_DIR_LIGHTS "+f:"",l?"#define MAX_POINT_LIGHTS "+l:"","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 ];":"",l?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":
-"",l?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",l?"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?"}":"",l?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",l?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",l?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
+THREE.Projector=function(){function a(M,u){var e=0,l=1,g=M.z+M.w,q=u.z+u.w,h=-M.z+M.w,i=-u.z+u.w;if(g>=0&&q>=0&&h>=0&&i>=0)return true;else if(g<0&&q<0||h<0&&i<0)return false;else{if(g<0)e=Math.max(e,g/(g-q));else if(q<0)l=Math.min(l,g/(g-q));if(h<0)e=Math.max(e,h/(h-i));else if(i<0)l=Math.min(l,h/(h-i));if(l<e)return false;else{M.lerpSelf(u,e);u.lerpSelf(M,1-l);return true}}}var b=null,d,f,j,m=[],n,k,o=[],c,E,C=[],x=new THREE.Vector4,z=new THREE.Matrix4,H=new THREE.Matrix4,G=new THREE.Vector4,J=
+new THREE.Vector4,L;this.projectScene=function(M,u){var e,l,g,q,h,i,s,p,D,w,I,S,t,O,B,P,Q;b=[];j=k=E=0;u.autoUpdateMatrix&&u.updateMatrix();z.multiply(u.projectionMatrix,u.matrix);s=M.objects;e=0;for(l=s.length;e<l;e++){p=s[e];p.autoUpdateMatrix&&p.updateMatrix();D=p.matrix;w=p.rotationMatrix;I=p.material;S=p.overdraw;if(p instanceof THREE.Mesh){t=p.geometry.vertices;g=0;for(q=t.length;g<q;g++){O=t[g];O.positionWorld.copy(O.position);D.multiplyVector3(O.positionWorld);B=O.positionScreen;B.copy(O.positionWorld);
+z.multiplyVector4(B);B.multiplyScalar(1/B.w);O.__visible=B.z>0&&B.z<1}O=p.geometry.faces;g=0;for(q=O.length;g<q;g++){B=O[g];if(B instanceof THREE.Face3){h=t[B.a];i=t[B.b];P=t[B.c];if(h.__visible&&i.__visible&&P.__visible)if(p.doubleSided||p.flipSided!=(P.positionScreen.x-h.positionScreen.x)*(i.positionScreen.y-h.positionScreen.y)-(P.positionScreen.y-h.positionScreen.y)*(i.positionScreen.x-h.positionScreen.x)<0){d=m[j]=m[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(h.positionWorld);d.v2.positionWorld.copy(i.positionWorld);
+d.v3.positionWorld.copy(P.positionWorld);d.v1.positionScreen.copy(h.positionScreen);d.v2.positionScreen.copy(i.positionScreen);d.v3.positionScreen.copy(P.positionScreen);d.normalWorld.copy(B.normal);w.multiplyVector3(d.normalWorld);d.centroidWorld.copy(B.centroid);D.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);z.multiplyVector3(d.centroidScreen);P=B.vertexNormals;L=d.vertexNormalsWorld;h=0;for(i=P.length;h<i;h++){Q=L[h]=L[h]||new THREE.Vector3;Q.copy(P[h]);w.multiplyVector3(Q)}d.z=
+d.centroidScreen.z;d.meshMaterial=I;d.faceMaterial=B.material;d.overdraw=S;if(p.geometry.uvs[g]){d.uvs[0]=p.geometry.uvs[g][0];d.uvs[1]=p.geometry.uvs[g][1];d.uvs[2]=p.geometry.uvs[g][2]}b.push(d);j++}}else if(B instanceof THREE.Face4){h=t[B.a];i=t[B.b];P=t[B.c];Q=t[B.d];if(h.__visible&&i.__visible&&P.__visible&&Q.__visible)if(p.doubleSided||p.flipSided!=((Q.positionScreen.x-h.positionScreen.x)*(i.positionScreen.y-h.positionScreen.y)-(Q.positionScreen.y-h.positionScreen.y)*(i.positionScreen.x-h.positionScreen.x)<
+0||(i.positionScreen.x-P.positionScreen.x)*(Q.positionScreen.y-P.positionScreen.y)-(i.positionScreen.y-P.positionScreen.y)*(Q.positionScreen.x-P.positionScreen.x)<0)){d=m[j]=m[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(h.positionWorld);d.v2.positionWorld.copy(i.positionWorld);d.v3.positionWorld.copy(Q.positionWorld);d.v1.positionScreen.copy(h.positionScreen);d.v2.positionScreen.copy(i.positionScreen);d.v3.positionScreen.copy(Q.positionScreen);d.normalWorld.copy(B.normal);w.multiplyVector3(d.normalWorld);
+d.centroidWorld.copy(B.centroid);D.multiplyVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);z.multiplyVector3(d.centroidScreen);d.z=d.centroidScreen.z;d.meshMaterial=I;d.faceMaterial=B.material;d.overdraw=S;if(p.geometry.uvs[g]){d.uvs[0]=p.geometry.uvs[g][0];d.uvs[1]=p.geometry.uvs[g][1];d.uvs[2]=p.geometry.uvs[g][3]}b.push(d);j++;f=m[j]=m[j]||new THREE.RenderableFace3;f.v1.positionWorld.copy(i.positionWorld);f.v2.positionWorld.copy(P.positionWorld);f.v3.positionWorld.copy(Q.positionWorld);
+f.v1.positionScreen.copy(i.positionScreen);f.v2.positionScreen.copy(P.positionScreen);f.v3.positionScreen.copy(Q.positionScreen);f.normalWorld.copy(d.normalWorld);f.centroidWorld.copy(d.centroidWorld);f.centroidScreen.copy(d.centroidScreen);f.z=f.centroidScreen.z;f.meshMaterial=I;f.faceMaterial=B.material;f.overdraw=S;if(p.geometry.uvs[g]){f.uvs[0]=p.geometry.uvs[g][1];f.uvs[1]=p.geometry.uvs[g][2];f.uvs[2]=p.geometry.uvs[g][3]}b.push(f);j++}}}}else if(p instanceof THREE.Line){H.multiply(z,D);t=p.geometry.vertices;
+O=t[0];O.positionScreen.copy(O.position);H.multiplyVector4(O.positionScreen);g=1;for(q=t.length;g<q;g++){h=t[g];h.positionScreen.copy(h.position);H.multiplyVector4(h.positionScreen);i=t[g-1];G.copy(h.positionScreen);J.copy(i.positionScreen);if(a(G,J)){G.multiplyScalar(1/G.w);J.multiplyScalar(1/J.w);n=o[k]=o[k]||new THREE.RenderableLine;n.v1.positionScreen.copy(G);n.v2.positionScreen.copy(J);n.z=Math.max(G.z,J.z);n.material=p.material;b.push(n);k++}}}else if(p instanceof THREE.Particle){x.set(p.position.x,
+p.position.y,p.position.z,1);z.multiplyVector4(x);x.z/=x.w;if(x.z>0&&x.z<1){c=C[E]=C[E]||new THREE.RenderableParticle;c.x=x.x/x.w;c.y=x.y/x.w;c.z=x.z;c.rotation=p.rotation.z;c.scale.x=p.scale.x*Math.abs(c.x-(x.x+u.projectionMatrix.n11)/(x.w+u.projectionMatrix.n14));c.scale.y=p.scale.y*Math.abs(c.y-(x.y+u.projectionMatrix.n22)/(x.w+u.projectionMatrix.n24));c.material=p.material;b.push(c);E++}}}b.sort(function(K,y){return y.z-K.z});return b};this.unprojectVector=function(M,u){var e=new THREE.Matrix4;
+e.multiply(THREE.Matrix4.makeInvert(u.matrix),THREE.Matrix4.makeInvert(u.projectionMatrix));e.multiplyVector3(M);return M}};
+THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,d,f,j,m;this.domElement=document.createElement("div");this.setSize=function(n,k){d=n;f=k;j=d/2;m=f/2};this.render=function(n,k){var o,c,E,C,x,z,H,G;a=b.projectScene(n,k);o=0;for(c=a.length;o<c;o++){x=a[o];if(x instanceof THREE.RenderableParticle){H=x.x*j+j;G=x.y*m+m;E=0;for(C=x.material.length;E<C;E++){z=x.material[E];if(z instanceof THREE.ParticleDOMMaterial){z=z.domElement;z.style.left=H+"px";z.style.top=G+"px"}}}}}};
+THREE.CanvasRenderer=function(){var a=null,b=new THREE.Projector,d=document.createElement("canvas"),f,j,m,n,k=d.getContext("2d"),o=1,c=0,E=null,C=null,x=1,z=Math.min,H=Math.max,G,J,L,M,u,e,l,g,q,h=new THREE.Color,i=new THREE.Color,s=new THREE.Color,p=new THREE.Color,D=new THREE.Color,w,I,S,t,O,B,P,Q,K,y,A=new THREE.Rectangle,T=new THREE.Rectangle,X=new THREE.Rectangle,U=false,R=new THREE.Color,Z=new THREE.Color,ia=new THREE.Color,ja=new THREE.Color,La=Math.PI*2,Y=new THREE.Vector3,na,oa,Ca,ba,pa,
+va,la=16;na=document.createElement("canvas");na.width=na.height=2;oa=na.getContext("2d");oa.fillStyle="rgba(0,0,0,1)";oa.fillRect(0,0,2,2);Ca=oa.getImageData(0,0,2,2);ba=Ca.data;pa=document.createElement("canvas");pa.width=pa.height=la;va=pa.getContext("2d");va.translate(-la/2,-la/2);va.scale(la,la);la--;this.domElement=d;this.autoClear=true;this.setSize=function(fa,wa){f=fa;j=wa;m=f/2;n=j/2;d.width=f;d.height=j;A.set(-m,-n,m,n)};this.clear=function(){if(!T.isEmpty()){T.inflate(1);T.minSelf(A);k.clearRect(T.getX(),
+T.getY(),T.getWidth(),T.getHeight());T.empty()}};this.render=function(fa,wa){function Ma(r){var V,N,v,F=r.lights;Z.setRGB(0,0,0);ia.setRGB(0,0,0);ja.setRGB(0,0,0);r=0;for(V=F.length;r<V;r++){N=F[r];v=N.color;if(N instanceof THREE.AmbientLight){Z.r+=v.r;Z.g+=v.g;Z.b+=v.b}else if(N instanceof THREE.DirectionalLight){ia.r+=v.r;ia.g+=v.g;ia.b+=v.b}else if(N instanceof THREE.PointLight){ja.r+=v.r;ja.g+=v.g;ja.b+=v.b}}}function xa(r,V,N,v){var F,W,aa,ca,da=r.lights;r=0;for(F=da.length;r<F;r++){W=da[r];
+aa=W.color;ca=W.intensity;if(W instanceof THREE.DirectionalLight){W=N.dot(W.position)*ca;if(W>0){v.r+=aa.r*W;v.g+=aa.g*W;v.b+=aa.b*W}}else if(W instanceof THREE.PointLight){Y.sub(W.position,V);Y.normalize();W=N.dot(Y)*ca;if(W>0){v.r+=aa.r*W;v.g+=aa.g*W;v.b+=aa.b*W}}}}function Na(r,V,N){if(N.opacity!=0){Da(N.opacity);ya(N.blending);var v,F,W,aa,ca,da;if(N instanceof THREE.ParticleBasicMaterial){if(N.map){aa=N.map;ca=aa.width>>1;da=aa.height>>1;F=V.scale.x*m;W=V.scale.y*n;N=F*ca;v=W*da;X.set(r.x-N,
+r.y-v,r.x+N,r.y+v);if(!A.instersects(X))return;k.save();k.translate(r.x,r.y);k.rotate(-V.rotation);k.scale(F,-W);k.translate(-ca,-da);k.drawImage(aa,0,0);k.restore()}k.beginPath();k.moveTo(r.x-10,r.y);k.lineTo(r.x+10,r.y);k.moveTo(r.x,r.y-10);k.lineTo(r.x,r.y+10);k.closePath();k.strokeStyle="rgb(255,255,0)";k.stroke()}else if(N instanceof THREE.ParticleCircleMaterial){if(U){R.r=Z.r+ia.r+ja.r;R.g=Z.g+ia.g+ja.g;R.b=Z.b+ia.b+ja.b;h.r=N.color.r*R.r;h.g=N.color.g*R.g;h.b=N.color.b*R.b;h.updateStyleString()}else h.__styleString=
+N.color.__styleString;N=V.scale.x*m;v=V.scale.y*n;X.set(r.x-N,r.y-v,r.x+N,r.y+v);if(A.instersects(X)){F=h.__styleString;if(C!=F)k.fillStyle=C=F;k.save();k.translate(r.x,r.y);k.rotate(-V.rotation);k.scale(N,v);k.beginPath();k.arc(0,0,1,0,La,true);k.closePath();k.fill();k.restore()}}}}function Oa(r,V,N,v){if(v.opacity!=0){Da(v.opacity);ya(v.blending);k.beginPath();k.moveTo(r.positionScreen.x,r.positionScreen.y);k.lineTo(V.positionScreen.x,V.positionScreen.y);k.closePath();if(v instanceof THREE.LineBasicMaterial){h.__styleString=
+v.color.__styleString;r=v.linewidth;if(x!=r)k.lineWidth=x=r;r=h.__styleString;if(E!=r)k.strokeStyle=E=r;k.stroke();X.inflate(v.linewidth*2)}}}function Ha(r,V,N,v,F,W){if(F.opacity!=0){Da(F.opacity);ya(F.blending);M=r.positionScreen.x;u=r.positionScreen.y;e=V.positionScreen.x;l=V.positionScreen.y;g=N.positionScreen.x;q=N.positionScreen.y;k.beginPath();k.moveTo(M,u);k.lineTo(e,l);k.lineTo(g,q);k.lineTo(M,u);k.closePath();if(F instanceof THREE.MeshBasicMaterial)if(F.map)F.map.image.loaded&&F.map.mapping instanceof
+THREE.UVMapping&&qa(M,u,e,l,g,q,F.map.image,v.uvs[0].u,v.uvs[0].v,v.uvs[1].u,v.uvs[1].v,v.uvs[2].u,v.uvs[2].v);else if(F.env_map){if(F.env_map.image.loaded)if(F.env_map.mapping instanceof THREE.SphericalReflectionMapping){r=wa.matrix;Y.copy(v.vertexNormalsWorld[0]);O=(Y.x*r.n11+Y.y*r.n12+Y.z*r.n13)*0.5+0.5;B=-(Y.x*r.n21+Y.y*r.n22+Y.z*r.n23)*0.5+0.5;Y.copy(v.vertexNormalsWorld[1]);P=(Y.x*r.n11+Y.y*r.n12+Y.z*r.n13)*0.5+0.5;Q=-(Y.x*r.n21+Y.y*r.n22+Y.z*r.n23)*0.5+0.5;Y.copy(v.vertexNormalsWorld[2]);K=
+(Y.x*r.n11+Y.y*r.n12+Y.z*r.n13)*0.5+0.5;y=-(Y.x*r.n21+Y.y*r.n22+Y.z*r.n23)*0.5+0.5;qa(M,u,e,l,g,q,F.env_map.image,O,B,P,Q,K,y)}}else F.wireframe?za(F.color.__styleString,F.wireframe_linewidth):Aa(F.color.__styleString);else if(F instanceof THREE.MeshLambertMaterial){if(F.map&&!F.wireframe){F.map.mapping instanceof THREE.UVMapping&&qa(M,u,e,l,g,q,F.map.image,v.uvs[0].u,v.uvs[0].v,v.uvs[1].u,v.uvs[1].v,v.uvs[2].u,v.uvs[2].v);ya(THREE.SubtractiveBlending)}if(U)if(!F.wireframe&&F.shading==THREE.SmoothShading&&
+v.vertexNormalsWorld.length==3){i.r=s.r=p.r=Z.r;i.g=s.g=p.g=Z.g;i.b=s.b=p.b=Z.b;xa(W,v.v1.positionWorld,v.vertexNormalsWorld[0],i);xa(W,v.v2.positionWorld,v.vertexNormalsWorld[1],s);xa(W,v.v3.positionWorld,v.vertexNormalsWorld[2],p);D.r=(s.r+p.r)*0.5;D.g=(s.g+p.g)*0.5;D.b=(s.b+p.b)*0.5;t=Ia(i,s,p,D);qa(M,u,e,l,g,q,t,0,0,1,0,0,1)}else{R.r=Z.r;R.g=Z.g;R.b=Z.b;xa(W,v.centroidWorld,v.normalWorld,R);h.r=F.color.r*R.r;h.g=F.color.g*R.g;h.b=F.color.b*R.b;h.updateStyleString();F.wireframe?za(h.__styleString,
+F.wireframe_linewidth):Aa(h.__styleString)}else F.wireframe?za(F.color.__styleString,F.wireframe_linewidth):Aa(F.color.__styleString)}else if(F instanceof THREE.MeshDepthMaterial){w=F.__2near;I=F.__farPlusNear;S=F.__farMinusNear;i.r=i.g=i.b=1-w/(I-r.positionScreen.z*S);s.r=s.g=s.b=1-w/(I-V.positionScreen.z*S);p.r=p.g=p.b=1-w/(I-N.positionScreen.z*S);D.r=(s.r+p.r)*0.5;D.g=(s.g+p.g)*0.5;D.b=(s.b+p.b)*0.5;t=Ia(i,s,p,D);qa(M,u,e,l,g,q,t,0,0,1,0,0,1)}else if(F instanceof THREE.MeshNormalMaterial){h.r=
+Ea(v.normalWorld.x);h.g=Ea(v.normalWorld.y);h.b=Ea(v.normalWorld.z);h.updateStyleString();F.wireframe?za(h.__styleString,F.wireframe_linewidth):Aa(h.__styleString)}}}function za(r,V){if(E!=r)k.strokeStyle=E=r;if(x!=V)k.lineWidth=x=V;k.stroke();X.inflate(V*2)}function Aa(r){if(C!=r)k.fillStyle=C=r;k.fill()}function qa(r,V,N,v,F,W,aa,ca,da,ra,ha,sa,ta){var ka,ga;ka=aa.width-1;ga=aa.height-1;ca*=ka;da*=ga;ra*=ka;ha*=ga;sa*=ka;ta*=ga;N-=r;v-=V;F-=r;W-=V;ra-=ca;ha-=da;sa-=ca;ta-=da;ga=1/(ra*ta-sa*ha);
+ka=(ta*N-ha*F)*ga;ha=(ta*v-ha*W)*ga;N=(ra*F-sa*N)*ga;v=(ra*W-sa*v)*ga;r=r-ka*ca-N*da;V=V-ha*ca-v*da;k.save();k.transform(ka,ha,N,v,r,V);k.clip();k.drawImage(aa,0,0);k.restore()}function Da(r){if(o!=r)k.globalAlpha=o=r}function ya(r){if(c!=r){switch(r){case THREE.NormalBlending:k.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:k.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:k.globalCompositeOperation="darker"}c=r}}function Ia(r,V,N,v){ba[0]=H(0,z(255,
+~~(r.r*255)));ba[1]=H(0,z(255,~~(r.g*255)));ba[2]=H(0,z(255,~~(r.b*255)));ba[4]=H(0,z(255,~~(V.r*255)));ba[5]=H(0,z(255,~~(V.g*255)));ba[6]=H(0,z(255,~~(V.b*255)));ba[8]=H(0,z(255,~~(N.r*255)));ba[9]=H(0,z(255,~~(N.g*255)));ba[10]=H(0,z(255,~~(N.b*255)));ba[12]=H(0,z(255,~~(v.r*255)));ba[13]=H(0,z(255,~~(v.g*255)));ba[14]=H(0,z(255,~~(v.b*255)));oa.putImageData(Ca,0,0);va.drawImage(na,0,0);return pa}function Ea(r){return r<0?z((1+r)*0.5,0.5):0.5+z(r*0.5,0.5)}function Fa(r,V){var N=V.x-r.x,v=V.y-r.y,
+F=1/Math.sqrt(N*N+v*v);N*=F;v*=F;V.x+=N;V.y+=v;r.x-=N;r.y-=v}var Ba,Ja,$,ea,ma,Ga,Ka,ua;k.setTransform(1,0,0,-1,m,n);this.autoClear&&this.clear();a=b.projectScene(fa,wa);k.fillStyle="rgba(0, 255, 255, 0.5)";k.fillRect(A.getX(),A.getY(),A.getWidth(),A.getHeight());(U=fa.lights.length>0)&&Ma(fa);Ba=0;for(Ja=a.length;Ba<Ja;Ba++){$=a[Ba];X.empty();if($ instanceof THREE.RenderableParticle){G=$;G.x*=m;G.y*=n;ea=0;for(ma=$.material.length;ea<ma;ea++)Na(G,$,$.material[ea],fa)}else if($ instanceof THREE.RenderableLine){G=
+$.v1;J=$.v2;G.positionScreen.x*=m;G.positionScreen.y*=n;J.positionScreen.x*=m;J.positionScreen.y*=n;X.addPoint(G.positionScreen.x,G.positionScreen.y);X.addPoint(J.positionScreen.x,J.positionScreen.y);if(A.instersects(X)){ea=0;for(ma=$.material.length;ea<ma;)Oa(G,J,$,$.material[ea++],fa)}}else if($ instanceof THREE.RenderableFace3){G=$.v1;J=$.v2;L=$.v3;G.positionScreen.x*=m;G.positionScreen.y*=n;J.positionScreen.x*=m;J.positionScreen.y*=n;L.positionScreen.x*=m;L.positionScreen.y*=n;if($.overdraw){Fa(G.positionScreen,
+J.positionScreen);Fa(J.positionScreen,L.positionScreen);Fa(L.positionScreen,G.positionScreen)}X.addPoint(G.positionScreen.x,G.positionScreen.y);X.addPoint(J.positionScreen.x,J.positionScreen.y);X.addPoint(L.positionScreen.x,L.positionScreen.y);if(A.instersects(X)){ea=0;for(ma=$.meshMaterial.length;ea<ma;){ua=$.meshMaterial[ea++];if(ua instanceof THREE.MeshFaceMaterial){Ga=0;for(Ka=$.faceMaterial.length;Ga<Ka;)(ua=$.faceMaterial[Ga++])&&Ha(G,J,L,$,ua,fa)}else Ha(G,J,L,$,ua,fa)}}}T.addRectangle(X)}k.lineWidth=
+1;k.strokeStyle="rgba( 255, 0, 0, 0.5 )";k.strokeRect(T.getX(),T.getY(),T.getWidth(),T.getHeight());k.setTransform(1,0,0,1,0,0)}};
+THREE.SVGRenderer=function(){function a(B,P,Q){var K,y,A,T;K=0;for(y=B.lights.length;K<y;K++){A=B.lights[K];if(A instanceof THREE.DirectionalLight){T=P.normalWorld.dot(A.position)*A.intensity;if(T>0){Q.r+=A.color.r*T;Q.g+=A.color.g*T;Q.b+=A.color.b*T}}else if(A instanceof THREE.PointLight){i.sub(A.position,P.centroidWorld);i.normalize();T=P.normalWorld.dot(i)*A.intensity;if(T>0){Q.r+=A.color.r*T;Q.g+=A.color.g*T;Q.b+=A.color.b*T}}}}function b(B,P,Q,K,y,A){w=f(I++);w.setAttribute("d","M "+B.positionScreen.x+
+" "+B.positionScreen.y+" L "+P.positionScreen.x+" "+P.positionScreen.y+" L "+Q.positionScreen.x+","+Q.positionScreen.y+"z");if(y instanceof THREE.MeshBasicMaterial)u.__styleString=y.color.__styleString;else if(y instanceof THREE.MeshLambertMaterial)if(M){e.r=l.r;e.g=l.g;e.b=l.b;a(A,K,e);u.r=y.color.r*e.r;u.g=y.color.g*e.g;u.b=y.color.b*e.b;u.updateStyleString()}else u.__styleString=y.color.__styleString;else if(y instanceof THREE.MeshDepthMaterial){h=1-y.__2near/(y.__farPlusNear-K.z*y.__farMinusNear);
+u.setRGB(h,h,h)}else y instanceof THREE.MeshNormalMaterial&&u.setRGB(j(K.normalWorld.x),j(K.normalWorld.y),j(K.normalWorld.z));y.wireframe?w.setAttribute("style","fill: none; stroke: "+u.__styleString+"; stroke-width: "+y.wireframe_linewidth+"; stroke-opacity: "+y.opacity+"; stroke-linecap: "+y.wireframe_linecap+"; stroke-linejoin: "+y.wireframe_linejoin):w.setAttribute("style","fill: "+u.__styleString+"; fill-opacity: "+y.opacity);k.appendChild(w)}function d(B,P,Q,K,y,A,T){w=f(I++);w.setAttribute("d",
+"M "+B.positionScreen.x+" "+B.positionScreen.y+" L "+P.positionScreen.x+" "+P.positionScreen.y+" L "+Q.positionScreen.x+","+Q.positionScreen.y+" L "+K.positionScreen.x+","+K.positionScreen.y+"z");if(A instanceof THREE.MeshBasicMaterial)u.__styleString=A.color.__styleString;else if(A instanceof THREE.MeshLambertMaterial)if(M){e.r=l.r;e.g=l.g;e.b=l.b;a(T,y,e);u.r=A.color.r*e.r;u.g=A.color.g*e.g;u.b=A.color.b*e.b;u.updateStyleString()}else u.__styleString=A.color.__styleString;else if(A instanceof THREE.MeshDepthMaterial){h=
+1-A.__2near/(A.__farPlusNear-y.z*A.__farMinusNear);u.setRGB(h,h,h)}else A instanceof THREE.MeshNormalMaterial&&u.setRGB(j(y.normalWorld.x),j(y.normalWorld.y),j(y.normalWorld.z));A.wireframe?w.setAttribute("style","fill: none; stroke: "+u.__styleString+"; stroke-width: "+A.wireframe_linewidth+"; stroke-opacity: "+A.opacity+"; stroke-linecap: "+A.wireframe_linecap+"; stroke-linejoin: "+A.wireframe_linejoin):w.setAttribute("style","fill: "+u.__styleString+"; fill-opacity: "+A.opacity);k.appendChild(w)}
+function f(B){if(s[B]==null){s[B]=document.createElementNS("http://www.w3.org/2000/svg","path");O==0&&s[B].setAttribute("shape-rendering","crispEdges");return s[B]}return s[B]}function j(B){return B<0?Math.min((1+B)*0.5,0.5):0.5+Math.min(B*0.5,0.5)}var m=null,n=new THREE.Projector,k=document.createElementNS("http://www.w3.org/2000/svg","svg"),o,c,E,C,x,z,H,G,J=new THREE.Rectangle,L=new THREE.Rectangle,M=false,u=new THREE.Color(16777215),e=new THREE.Color(16777215),l=new THREE.Color(0),g=new THREE.Color(0),
+q=new THREE.Color(0),h,i=new THREE.Vector3,s=[],p=[],D=[],w,I,S,t,O=1;this.domElement=k;this.autoClear=true;this.setQuality=function(B){switch(B){case "high":O=1;break;case "low":O=0}};this.setSize=function(B,P){o=B;c=P;E=o/2;C=c/2;k.setAttribute("viewBox",-E+" "+-C+" "+o+" "+c);k.setAttribute("width",o);k.setAttribute("height",c);J.set(-E,-C,E,C)};this.clear=function(){for(;k.childNodes.length>0;)k.removeChild(k.childNodes[0])};this.render=function(B,P){var Q,K,y,A,T,X,U,R;this.autoClear&&this.clear();
+m=n.projectScene(B,P);t=S=I=0;if(M=B.lights.length>0){U=B.lights;l.setRGB(0,0,0);g.setRGB(0,0,0);q.setRGB(0,0,0);Q=0;for(K=U.length;Q<K;Q++){y=U[Q];A=y.color;if(y instanceof THREE.AmbientLight){l.r+=A.r;l.g+=A.g;l.b+=A.b}else if(y instanceof THREE.DirectionalLight){g.r+=A.r;g.g+=A.g;g.b+=A.b}else if(y instanceof THREE.PointLight){q.r+=A.r;q.g+=A.g;q.b+=A.b}}}Q=0;for(K=m.length;Q<K;Q++){U=m[Q];L.empty();if(U instanceof THREE.RenderableParticle){x=U;x.x*=E;x.y*=-C;y=0;for(A=U.material.length;y<A;y++)if(R=
+U.material[y]){T=x;X=U;R=R;var Z=S++;if(p[Z]==null){p[Z]=document.createElementNS("http://www.w3.org/2000/svg","circle");O==0&&p[Z].setAttribute("shape-rendering","crispEdges")}w=p[Z];w.setAttribute("cx",T.x);w.setAttribute("cy",T.y);w.setAttribute("r",X.scale.x*E);if(R instanceof THREE.ParticleCircleMaterial){if(M){e.r=l.r+g.r+q.r;e.g=l.g+g.g+q.g;e.b=l.b+g.b+q.b;u.r=R.color.r*e.r;u.g=R.color.g*e.g;u.b=R.color.b*e.b;u.updateStyleString()}else u=R.color;w.setAttribute("style","fill: "+u.__styleString)}k.appendChild(w)}}else if(U instanceof
+THREE.RenderableLine){x=U.v1;z=U.v2;x.positionScreen.x*=E;x.positionScreen.y*=-C;z.positionScreen.x*=E;z.positionScreen.y*=-C;L.addPoint(x.positionScreen.x,x.positionScreen.y);L.addPoint(z.positionScreen.x,z.positionScreen.y);if(J.instersects(L)){y=0;for(A=U.material.length;y<A;)if(R=U.material[y++]){T=x;X=z;R=R;Z=t++;if(D[Z]==null){D[Z]=document.createElementNS("http://www.w3.org/2000/svg","line");O==0&&D[Z].setAttribute("shape-rendering","crispEdges")}w=D[Z];w.setAttribute("x1",T.positionScreen.x);
+w.setAttribute("y1",T.positionScreen.y);w.setAttribute("x2",X.positionScreen.x);w.setAttribute("y2",X.positionScreen.y);if(R instanceof THREE.LineBasicMaterial){u.__styleString=R.color.__styleString;w.setAttribute("style","fill: none; stroke: "+u.__styleString+"; stroke-width: "+R.linewidth+"; stroke-opacity: "+R.opacity+"; stroke-linecap: "+R.linecap+"; stroke-linejoin: "+R.linejoin);k.appendChild(w)}}}}else if(U instanceof THREE.RenderableFace3){x=U.v1;z=U.v2;H=U.v3;x.positionScreen.x*=E;x.positionScreen.y*=
+-C;z.positionScreen.x*=E;z.positionScreen.y*=-C;H.positionScreen.x*=E;H.positionScreen.y*=-C;L.addPoint(x.positionScreen.x,x.positionScreen.y);L.addPoint(z.positionScreen.x,z.positionScreen.y);L.addPoint(H.positionScreen.x,H.positionScreen.y);if(J.instersects(L)){y=0;for(A=U.meshMaterial.length;y<A;){R=U.meshMaterial[y++];if(R instanceof THREE.MeshFaceMaterial){T=0;for(X=U.faceMaterial.length;T<X;)(R=U.faceMaterial[T++])&&b(x,z,H,U,R,B)}else R&&b(x,z,H,U,R,B)}}}else if(U instanceof THREE.RenderableFace4){x=
+U.v1;z=U.v2;H=U.v3;G=U.v4;x.positionScreen.x*=E;x.positionScreen.y*=-C;z.positionScreen.x*=E;z.positionScreen.y*=-C;H.positionScreen.x*=E;H.positionScreen.y*=-C;G.positionScreen.x*=E;G.positionScreen.y*=-C;L.addPoint(x.positionScreen.x,x.positionScreen.y);L.addPoint(z.positionScreen.x,z.positionScreen.y);L.addPoint(H.positionScreen.x,H.positionScreen.y);L.addPoint(G.positionScreen.x,G.positionScreen.y);if(J.instersects(L)){y=0;for(A=U.meshMaterial.length;y<A;){R=U.meshMaterial[y++];if(R instanceof
+THREE.MeshFaceMaterial){T=0;for(X=U.faceMaterial.length;T<X;)(R=U.faceMaterial[T++])&&d(x,z,H,G,U,R,B)}else R&&d(x,z,H,G,U,R,B)}}}}}};
+THREE.WebGLRenderer=function(a){function b(e,l){var g=c.createProgram(),q=[c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"].join("\n");c.attachShader(g,n("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\nuniform mat4 viewMatrix;\n"+
+e));c.attachShader(g,n("vertex",q+l));c.linkProgram(g);c.getProgramParameter(g,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(g,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");g.uniforms={};g.attributes={};return g}function d(e,l){if(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 g=0;g<6;++g)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+g,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,e.image[g]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);e.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+l);c.bindTexture(c.TEXTURE_CUBE_MAP,
+e.image.__webGLTextureCube)}}function f(e,l){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,k(e.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,k(e.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,k(e.mag_filter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,k(e.min_filter));c.generateMipmap(c.TEXTURE_2D);
+c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+l);c.bindTexture(c.TEXTURE_2D,e.__webGLTexture)}function j(e,l){var g,q,h;g=0;for(q=l.length;g<q;g++){h=l[g];e.uniforms[h]=c.getUniformLocation(e,h)}}function m(e,l){var g,q,h;g=0;for(q=l.length;g<q;g++){h=l[g];e.attributes[h]=c.getAttribLocation(e,h);e.attributes[h]>=0&&c.enableVertexAttribArray(e.attributes[h])}}function n(e,l){var g;if(e=="fragment")g=c.createShader(c.FRAGMENT_SHADER);else if(e=="vertex")g=c.createShader(c.VERTEX_SHADER);
+c.shaderSource(g,l);c.compileShader(g);if(!c.getShaderParameter(g,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(g));return null}return g}function k(e){switch(e){case THREE.RepeatWrapping:return c.REPEAT;case THREE.ClampToEdgeWrapping:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return c.MIRRORED_REPEAT;case THREE.NearestFilter:return c.NEAREST;case THREE.NearestMipMapNearestFilter:return c.NEAREST_MIPMAP_NEAREST;case THREE.NearestMipMapLinearFilter:return c.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return c.LINEAR;
+case THREE.LinearMipMapNearestFilter:return c.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return c.LINEAR_MIPMAP_LINEAR}return 0}var o=document.createElement("canvas"),c,E,C,x=new THREE.Matrix4,z,H=new Float32Array(16),G=new Float32Array(16),J=new Float32Array(16),L=new Float32Array(9),M=new Float32Array(16);a=function(e,l){if(e){var g,q,h,i=pointLights=maxDirLights=maxPointLights=0;g=0;for(q=e.lights.length;g<q;g++){h=e.lights[g];h instanceof THREE.DirectionalLight&&i++;h instanceof
+THREE.PointLight&&pointLights++}if(pointLights+i<=l){maxDirLights=i;maxPointLights=pointLights}else{maxDirLights=Math.ceil(l*i/(pointLights+i));maxPointLights=l-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:l-1}}(a,4);this.domElement=o;this.autoClear=true;try{c=o.getContext("experimental-webgl",{antialias:true})}catch(u){}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=C=function(e,l){var g=[e?"#define MAX_DIR_LIGHTS "+e:"",l?"#define MAX_POINT_LIGHTS "+l:"","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 ];":
+"",l?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",l?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",l?"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?"}":"",l?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",l?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",l?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
 "",l?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",l?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",l?"}":"","}\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"),
-q=[f?"#define MAX_DIR_LIGHTS "+f:"",l?"#define MAX_POINT_LIGHTS "+l:"","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 vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",l?"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 );",
+q=[e?"#define MAX_DIR_LIGHTS "+e:"",l?"#define MAX_POINT_LIGHTS "+l:"","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 vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",l?"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 ) + 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 );",
 l?"vec4 pointDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",l?"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",l?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",l?"vec3 pointVector = normalize( vPointLightVector[ i ] );":"",l?"vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );":"",l?"float pointDotNormalHalf = dot( normal, pointHalfVector );":"",l?"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );":"",l?"float pointSpecularWeight = 0.0;":"",l?"if ( pointDotNormalHalf >= 0.0 )":
-"",l?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",l?"pointDiffuse  += mColor * pointDiffuseWeight;":"",l?"pointSpecular += mSpecular * pointSpecularWeight;":"",l?"}":"",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;":"",l?"totalLight += pointDiffuse + pointSpecular;":
+"",l?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",l?"pointDiffuse  += mColor * pointDiffuseWeight;":"",l?"pointSpecular += mSpecular * pointSpecularWeight;":"",l?"}":"",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;":"",l?"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");
-e=b(q,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"]);l&&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);n(e,["position","normal","uv"]);return e}(a.directional,a.point);this.setSize=function(f,l){o.width=f;o.height=l;c.viewport(0,0,o.width,o.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(f,l){var e,q,h,i,s,r=[],
-M=[],B=[];i=[];s=[];c.uniform1i(f.uniforms.enableLighting,l.length);e=0;for(q=l.length;e<q;e++){h=l[e];if(h instanceof THREE.AmbientLight)r.push(h);else if(h instanceof THREE.DirectionalLight)B.push(h);else h instanceof THREE.PointLight&&M.push(h)}e=h=i=s=0;for(q=r.length;e<q;e++){h+=r[e].color.r;i+=r[e].color.g;s+=r[e].color.b}c.uniform3f(f.uniforms.ambientLightColor,h,i,s);i=[];s=[];e=0;for(q=B.length;e<q;e++){h=B[e];i.push(h.color.r*h.intensity);i.push(h.color.g*h.intensity);i.push(h.color.b*h.intensity);
-s.push(h.position.x);s.push(h.position.y);s.push(h.position.z)}if(B.length){c.uniform1i(f.uniforms.directionalLightNumber,B.length);c.uniform3fv(f.uniforms.directionalLightDirection,s);c.uniform3fv(f.uniforms.directionalLightColor,i)}i=[];s=[];e=0;for(q=M.length;e<q;e++){h=M[e];i.push(h.color.r*h.intensity);i.push(h.color.g*h.intensity);i.push(h.color.b*h.intensity);s.push(h.position.x);s.push(h.position.y);s.push(h.position.z)}if(M.length){c.uniform1i(f.uniforms.pointLightNumber,M.length);c.uniform3fv(f.uniforms.pointLightPosition,
-s);c.uniform3fv(f.uniforms.pointLightColor,i)}};this.createBuffers=function(f,l){var e,q,h,i,s,r,M,B,H=[],Q=[],u=[],R=[],y=[],A=0,E=f.geometry.geometryChunks[l],W;h=false;e=0;for(q=f.material.length;e<q;e++){meshMaterial=f.material[e];if(meshMaterial instanceof THREE.MeshFaceMaterial){s=0;for(W=E.material.length;s<W;s++)if(E.material[s]&&E.material[s].shading!=undefined&&E.material[s].shading==THREE.SmoothShading){h=true;break}}else if(meshMaterial&&meshMaterial.shading!=undefined&&meshMaterial.shading==
-THREE.SmoothShading){h=true;break}if(h)break}W=h;e=0;for(q=E.faces.length;e<q;e++){h=E.faces[e];i=f.geometry.faces[h];s=i.vertexNormals;faceNormal=i.normal;h=f.geometry.uvs[h];if(i instanceof THREE.Face3){r=f.geometry.vertices[i.a].position;M=f.geometry.vertices[i.b].position;B=f.geometry.vertices[i.c].position;u.push(r.x,r.y,r.z);u.push(M.x,M.y,M.z);u.push(B.x,B.y,B.z);if(s.length==3&&W)for(i=0;i<3;i++)R.push(s[i].x,s[i].y,s[i].z);else for(i=0;i<3;i++)R.push(faceNormal.x,faceNormal.y,faceNormal.z);
-if(h)for(i=0;i<3;i++)y.push(h[i].u,h[i].v);H.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(i instanceof THREE.Face4){r=f.geometry.vertices[i.a].position;M=f.geometry.vertices[i.b].position;B=f.geometry.vertices[i.c].position;i=f.geometry.vertices[i.d].position;u.push(r.x,r.y,r.z);u.push(M.x,M.y,M.z);u.push(B.x,B.y,B.z);u.push(i.x,i.y,i.z);if(s.length==4&&W)for(i=0;i<4;i++)R.push(s[i].x,s[i].y,s[i].z);else for(i=0;i<4;i++)R.push(faceNormal.x,faceNormal.y,faceNormal.z);if(h)for(i=
-0;i<4;i++)y.push(h[i].u,h[i].v);H.push(A,A+1,A+2);H.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(u.length){E.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,E.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(u),c.STATIC_DRAW);E.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,E.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(R),c.STATIC_DRAW);if(y.length>0){E.__webGLUVBuffer=c.createBuffer();
-c.bindBuffer(c.ARRAY_BUFFER,E.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(y),c.STATIC_DRAW)}E.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,E.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(H),c.STATIC_DRAW);E.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,E.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(Q),c.STATIC_DRAW);E.__webGLFaceCount=H.length;E.__webGLLineCount=Q.length}};this.renderBuffer=
-function(f,l,e,q){var h,i,s,r,M,B,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);n(e.program,["position","normal","uv"])}u=e.program}else u=D;if(u!=F){c.useProgram(u);F=u}u==D&&this.setupLights(u,l);this.loadCamera(u,f);this.loadMatrices(u);if(e instanceof THREE.MeshShaderMaterial){s=e.wireframe;
-r=e.wireframe_linewidth;f=u;l=e.uniforms;var R;for(h in l){Q=l[h].type;H=l[h].value;R=f.uniforms[h];if(Q=="i")c.uniform1i(R,H);else if(Q=="f")c.uniform1f(R,H);else if(Q=="v3")c.uniform3f(R,H.x,H.y,H.z);else if(Q=="c")c.uniform3f(R,H.r,H.g,H.b);else if(Q=="t"){c.uniform1i(R,H);if(Q=l[h].texture)Q.image instanceof Array&&Q.image.length==6?d(Q,H):g(Q,H)}}}if(e instanceof THREE.MeshPhongMaterial||e instanceof THREE.MeshLambertMaterial||e instanceof THREE.MeshBasicMaterial){h=e.color;i=e.opacity;s=e.wireframe;
-r=e.wireframe_linewidth;M=e.map;B=e.env_map;l=e.combine==THREE.MixOperation;f=e.reflectivity;Q=e.env_map&&e.env_map.mapping instanceof THREE.CubeRefractionMapping;H=e.refraction_ratio;c.uniform4f(u.uniforms.mColor,h.r*i,h.g*i,h.b*i,i);c.uniform1i(u.uniforms.mixEnvMap,l);c.uniform1f(u.uniforms.mReflectivity,f);c.uniform1i(u.uniforms.useRefract,Q);c.uniform1f(u.uniforms.mRefractionRatio,H)}if(e instanceof THREE.MeshNormalMaterial){i=e.opacity;c.uniform1f(u.uniforms.mOpacity,i);c.uniform1i(u.uniforms.material,
-4)}else if(e instanceof THREE.MeshDepthMaterial){i=e.opacity;s=e.wireframe;r=e.wireframe_linewidth;c.uniform1f(u.uniforms.mOpacity,i);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,i);c.uniform4f(u.uniforms.mSpecular,f.r,f.g,f.b,i);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);B=e.env_map}if(M){g(M,0);c.uniform1i(u.uniforms.tMap,0);c.uniform1i(u.uniforms.enableMap,1)}else c.uniform1i(u.uniforms.enableMap,0);if(B){d(B,1);c.uniform1i(u.uniforms.tCube,1);c.uniform1i(u.uniforms.enableCubeMap,1)}else c.uniform1i(u.uniforms.enableCubeMap,
-0);i=u.attributes;c.bindBuffer(c.ARRAY_BUFFER,q.__webGLVertexBuffer);c.vertexAttribPointer(i.position,3,c.FLOAT,false,0,0);c.bindBuffer(c.ARRAY_BUFFER,q.__webGLNormalBuffer);c.vertexAttribPointer(i.normal,3,c.FLOAT,false,0,0);if(i.uv>=0)if(q.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,q.__webGLUVBuffer);c.enableVertexAttribArray(i.uv);c.vertexAttribPointer(i.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(i.uv);if(s){c.lineWidth(r);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,q.__webGLLineBuffer);
-c.drawElements(c.LINES,q.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,q.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,q.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(f,l,e,q,h,i){var s,r,M,B,H;M=0;for(B=e.material.length;M<B;M++){s=e.material[M];if(s instanceof THREE.MeshFaceMaterial){s=0;for(r=q.material.length;s<r;s++)if((H=q.material[s])&&H.blending==h&&H.opacity<1==i){this.setBlending(H.blending);this.renderBuffer(f,l,H,q)}}else if((H=s)&&H.blending==
-h&&H.opacity<1==i){this.setBlending(H.blending);this.renderBuffer(f,l,H,q)}}};this.render=function(f,l){var e,q,h,i,s=f.lights;this.initWebGLObjects(f);this.autoClear&&this.clear();l.autoUpdateMatrix&&l.updateMatrix();e=0;for(q=f.__webGLObjects.length;e<q;e++){h=f.__webGLObjects[e];i=h.object;h=h.buffer;if(i.visible){this.setupMatrices(i,l);this.renderPass(l,s,i,h,THREE.NormalBlending,false)}}e=0;for(q=f.__webGLObjects.length;e<q;e++){h=f.__webGLObjects[e];i=h.object;h=h.buffer;if(i.visible){this.setupMatrices(i,
-l);this.renderPass(l,s,i,h,THREE.AdditiveBlending,false);this.renderPass(l,s,i,h,THREE.SubtractiveBlending,false);this.renderPass(l,s,i,h,THREE.AdditiveBlending,true);this.renderPass(l,s,i,h,THREE.SubtractiveBlending,true);this.renderPass(l,s,i,h,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(f){var l,e,q,h,i,s;if(!f.__webGLObjects){f.__webGLObjects=[];f.__webGLObjectsMap={}}l=0;for(e=f.objects.length;l<e;l++){q=f.objects[l];if(f.__webGLObjectsMap[q.id]==undefined)f.__webGLObjectsMap[q.id]=
-{};s=f.__webGLObjectsMap[q.id];if(q instanceof THREE.Mesh)for(i in q.geometry.geometryChunks){h=q.geometry.geometryChunks[i];h.__webGLVertexBuffer||this.createBuffers(q,i);if(s[i]==undefined){h={buffer:h,object:q};f.__webGLObjects.push(h);s[i]=1}}}};this.removeObject=function(f,l){var e,q;for(e=f.__webGLObjects.length-1;e>=0;e--){q=f.__webGLObjects[e].object;l==q&&f.__webGLObjects.splice(e,1)}};this.setupMatrices=function(f,l){f.autoUpdateMatrix&&f.updateMatrix();w.multiply(l.matrix,f.matrix);I.set(l.matrix.flatten());
-G.set(w.flatten());L.set(l.projectionMatrix.flatten());x=THREE.Matrix4.makeInvert3x3(w).transpose();N.set(x.m);O.set(f.matrix.flatten())};this.loadMatrices=function(f){c.uniformMatrix4fv(f.uniforms.viewMatrix,false,I);c.uniformMatrix4fv(f.uniforms.modelViewMatrix,false,G);c.uniformMatrix4fv(f.uniforms.projectionMatrix,false,L);c.uniformMatrix3fv(f.uniforms.normalMatrix,false,N);c.uniformMatrix4fv(f.uniforms.objectMatrix,false,O)};this.loadCamera=function(f,l){c.uniform3f(f.uniforms.cameraPosition,
-l.position.x,l.position.y,l.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,l){if(f){!l||l=="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.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=null};
+g=b(q,g);c.useProgram(g);j(g,["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(g,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);l&&j(g,["pointLightNumber","pointLightColor",
+"pointLightPosition"]);c.uniform1i(g.uniforms.enableMap,0);c.uniform1i(g.uniforms.tMap,0);c.uniform1i(g.uniforms.enableCubeMap,0);c.uniform1i(g.uniforms.tCube,1);c.uniform1i(g.uniforms.mixEnvMap,0);c.uniform1i(g.uniforms.useRefract,0);m(g,["position","normal","uv"]);return g}(a.directional,a.point);this.setSize=function(e,l){o.width=e;o.height=l;c.viewport(0,0,o.width,o.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(e,l){var g,q,h,i,s,p=[],
+D=[],w=[];i=[];s=[];c.uniform1i(e.uniforms.enableLighting,l.length);g=0;for(q=l.length;g<q;g++){h=l[g];if(h instanceof THREE.AmbientLight)p.push(h);else if(h instanceof THREE.DirectionalLight)w.push(h);else h instanceof THREE.PointLight&&D.push(h)}g=h=i=s=0;for(q=p.length;g<q;g++){h+=p[g].color.r;i+=p[g].color.g;s+=p[g].color.b}c.uniform3f(e.uniforms.ambientLightColor,h,i,s);i=[];s=[];g=0;for(q=w.length;g<q;g++){h=w[g];i.push(h.color.r*h.intensity);i.push(h.color.g*h.intensity);i.push(h.color.b*h.intensity);
+s.push(h.position.x);s.push(h.position.y);s.push(h.position.z)}if(w.length){c.uniform1i(e.uniforms.directionalLightNumber,w.length);c.uniform3fv(e.uniforms.directionalLightDirection,s);c.uniform3fv(e.uniforms.directionalLightColor,i)}i=[];s=[];g=0;for(q=D.length;g<q;g++){h=D[g];i.push(h.color.r*h.intensity);i.push(h.color.g*h.intensity);i.push(h.color.b*h.intensity);s.push(h.position.x);s.push(h.position.y);s.push(h.position.z)}if(D.length){c.uniform1i(e.uniforms.pointLightNumber,D.length);c.uniform3fv(e.uniforms.pointLightPosition,
+s);c.uniform3fv(e.uniforms.pointLightColor,i)}};this.createBuffers=function(e,l){var g,q,h,i,s,p,D,w,I,S=[],t=[],O=[],B=[],P=[],Q=[],K=0,y=e.geometry.geometryChunks[l],A;h=false;g=0;for(q=e.material.length;g<q;g++){meshMaterial=e.material[g];if(meshMaterial instanceof THREE.MeshFaceMaterial){s=0;for(A=y.material.length;s<A;s++)if(y.material[s]&&y.material[s].shading!=undefined&&y.material[s].shading==THREE.SmoothShading){h=true;break}}else if(meshMaterial&&meshMaterial.shading!=undefined&&meshMaterial.shading==
+THREE.SmoothShading){h=true;break}if(h)break}A=h;g=0;for(q=y.faces.length;g<q;g++){h=y.faces[g];i=e.geometry.faces[h];s=i.vertexNormals;faceNormal=i.normal;h=e.geometry.uvs[h];if(i instanceof THREE.Face3){p=e.geometry.vertices[i.a].position;D=e.geometry.vertices[i.b].position;w=e.geometry.vertices[i.c].position;O.push(p.x,p.y,p.z);O.push(D.x,D.y,D.z);O.push(w.x,w.y,w.z);if(e.geometry.hasTangents){p=e.geometry.vertices[i.a].tangent;D=e.geometry.vertices[i.b].tangent;w=e.geometry.vertices[i.c].tangent;
+P.push(p.x,p.y,p.z,p.w);P.push(D.x,D.y,D.z,D.w);P.push(w.x,w.y,w.z,w.w)}if(s.length==3&&A)for(i=0;i<3;i++)B.push(s[i].x,s[i].y,s[i].z);else for(i=0;i<3;i++)B.push(faceNormal.x,faceNormal.y,faceNormal.z);if(h)for(i=0;i<3;i++)Q.push(h[i].u,h[i].v);S.push(K,K+1,K+2);t.push(K,K+1);t.push(K,K+2);t.push(K+1,K+2);K+=3}else if(i instanceof THREE.Face4){p=e.geometry.vertices[i.a].position;D=e.geometry.vertices[i.b].position;w=e.geometry.vertices[i.c].position;I=e.geometry.vertices[i.d].position;O.push(p.x,
+p.y,p.z);O.push(D.x,D.y,D.z);O.push(w.x,w.y,w.z);O.push(I.x,I.y,I.z);if(e.geometry.hasTangents){p=e.geometry.vertices[i.a].tangent;D=e.geometry.vertices[i.b].tangent;w=e.geometry.vertices[i.c].tangent;i=e.geometry.vertices[i.d].tangent;P.push(p.x,p.y,p.z,p.w);P.push(D.x,D.y,D.z,D.w);P.push(w.x,w.y,w.z,w.w);P.push(i.x,i.y,i.z,i.w)}if(s.length==4&&A)for(i=0;i<4;i++)B.push(s[i].x,s[i].y,s[i].z);else for(i=0;i<4;i++)B.push(faceNormal.x,faceNormal.y,faceNormal.z);if(h)for(i=0;i<4;i++)Q.push(h[i].u,h[i].v);
+S.push(K,K+1,K+2);S.push(K,K+2,K+3);t.push(K,K+1);t.push(K,K+2);t.push(K,K+3);t.push(K+1,K+2);t.push(K+2,K+3);K+=4}}if(O.length){y.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,y.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(O),c.STATIC_DRAW);y.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,y.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(B),c.STATIC_DRAW);if(e.geometry.hasTangents){y.__webGLTangentBuffer=c.createBuffer();
+c.bindBuffer(c.ARRAY_BUFFER,y.__webGLTangentBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(P),c.STATIC_DRAW)}if(Q.length>0){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(S),c.STATIC_DRAW);y.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,
+y.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(t),c.STATIC_DRAW);y.__webGLFaceCount=S.length;y.__webGLLineCount=t.length}};this.renderBuffer=function(e,l,g,q){var h,i,s,p,D,w,I,S,t;if(g instanceof THREE.MeshShaderMaterial){if(!g.program){g.program=b(g.fragment_shader,g.vertex_shader);I=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(t in g.uniforms)I.push(t);j(g.program,I);m(g.program,["position","normal","uv","tangent"])}t=
+g.program}else t=C;if(t!=E){c.useProgram(t);E=t}t==C&&this.setupLights(t,l);this.loadCamera(t,e);this.loadMatrices(t);if(g instanceof THREE.MeshShaderMaterial){s=g.wireframe;p=g.wireframe_linewidth;e=t;l=g.uniforms;var O;for(h in l){S=l[h].type;I=l[h].value;O=e.uniforms[h];if(S=="i")c.uniform1i(O,I);else if(S=="f")c.uniform1f(O,I);else if(S=="v3")c.uniform3f(O,I.x,I.y,I.z);else if(S=="c")c.uniform3f(O,I.r,I.g,I.b);else if(S=="t"){c.uniform1i(O,I);if(S=l[h].texture)S.image instanceof Array&&S.image.length==
+6?d(S,I):f(S,I)}}}if(g instanceof THREE.MeshPhongMaterial||g instanceof THREE.MeshLambertMaterial||g instanceof THREE.MeshBasicMaterial){h=g.color;i=g.opacity;s=g.wireframe;p=g.wireframe_linewidth;D=g.map;w=g.env_map;l=g.combine==THREE.MixOperation;e=g.reflectivity;S=g.env_map&&g.env_map.mapping instanceof THREE.CubeRefractionMapping;I=g.refraction_ratio;c.uniform4f(t.uniforms.mColor,h.r*i,h.g*i,h.b*i,i);c.uniform1i(t.uniforms.mixEnvMap,l);c.uniform1f(t.uniforms.mReflectivity,e);c.uniform1i(t.uniforms.useRefract,
+S);c.uniform1f(t.uniforms.mRefractionRatio,I)}if(g instanceof THREE.MeshNormalMaterial){i=g.opacity;c.uniform1f(t.uniforms.mOpacity,i);c.uniform1i(t.uniforms.material,4)}else if(g instanceof THREE.MeshDepthMaterial){i=g.opacity;s=g.wireframe;p=g.wireframe_linewidth;c.uniform1f(t.uniforms.mOpacity,i);c.uniform1f(t.uniforms.m2Near,g.__2near);c.uniform1f(t.uniforms.mFarPlusNear,g.__farPlusNear);c.uniform1f(t.uniforms.mFarMinusNear,g.__farMinusNear);c.uniform1i(t.uniforms.material,3)}else if(g instanceof
+THREE.MeshPhongMaterial){h=g.ambient;e=g.specular;g=g.shininess;c.uniform4f(t.uniforms.mAmbient,h.r,h.g,h.b,i);c.uniform4f(t.uniforms.mSpecular,e.r,e.g,e.b,i);c.uniform1f(t.uniforms.mShininess,g);c.uniform1i(t.uniforms.material,2)}else if(g instanceof THREE.MeshLambertMaterial)c.uniform1i(t.uniforms.material,1);else if(g instanceof THREE.MeshBasicMaterial)c.uniform1i(t.uniforms.material,0);else if(g instanceof THREE.MeshCubeMaterial){c.uniform1i(t.uniforms.material,5);w=g.env_map}if(D){f(D,0);c.uniform1i(t.uniforms.tMap,
+0);c.uniform1i(t.uniforms.enableMap,1)}else c.uniform1i(t.uniforms.enableMap,0);if(w){d(w,1);c.uniform1i(t.uniforms.tCube,1);c.uniform1i(t.uniforms.enableCubeMap,1)}else c.uniform1i(t.uniforms.enableCubeMap,0);i=t.attributes;c.bindBuffer(c.ARRAY_BUFFER,q.__webGLVertexBuffer);c.vertexAttribPointer(i.position,3,c.FLOAT,false,0,0);c.bindBuffer(c.ARRAY_BUFFER,q.__webGLNormalBuffer);c.vertexAttribPointer(i.normal,3,c.FLOAT,false,0,0);if(i.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,q.__webGLTangentBuffer);
+c.vertexAttribPointer(i.tangent,4,c.FLOAT,false,0,0)}if(i.uv>=0)if(q.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,q.__webGLUVBuffer);c.enableVertexAttribArray(i.uv);c.vertexAttribPointer(i.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(i.uv);if(s){c.lineWidth(p);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,q.__webGLLineBuffer);c.drawElements(c.LINES,q.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,q.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,q.__webGLFaceCount,c.UNSIGNED_SHORT,
+0)}};this.renderPass=function(e,l,g,q,h,i){var s,p,D,w,I;D=0;for(w=g.material.length;D<w;D++){s=g.material[D];if(s instanceof THREE.MeshFaceMaterial){s=0;for(p=q.material.length;s<p;s++)if((I=q.material[s])&&I.blending==h&&I.opacity<1==i){this.setBlending(I.blending);this.renderBuffer(e,l,I,q)}}else if((I=s)&&I.blending==h&&I.opacity<1==i){this.setBlending(I.blending);this.renderBuffer(e,l,I,q)}}};this.render=function(e,l){var g,q,h,i,s=e.lights;this.initWebGLObjects(e);this.autoClear&&this.clear();
+l.autoUpdateMatrix&&l.updateMatrix();g=0;for(q=e.__webGLObjects.length;g<q;g++){h=e.__webGLObjects[g];i=h.object;h=h.buffer;if(i.visible){this.setupMatrices(i,l);this.renderPass(l,s,i,h,THREE.NormalBlending,false)}}g=0;for(q=e.__webGLObjects.length;g<q;g++){h=e.__webGLObjects[g];i=h.object;h=h.buffer;if(i.visible){this.setupMatrices(i,l);this.renderPass(l,s,i,h,THREE.AdditiveBlending,false);this.renderPass(l,s,i,h,THREE.SubtractiveBlending,false);this.renderPass(l,s,i,h,THREE.AdditiveBlending,true);
+this.renderPass(l,s,i,h,THREE.SubtractiveBlending,true);this.renderPass(l,s,i,h,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(e){var l,g,q,h,i,s;if(!e.__webGLObjects){e.__webGLObjects=[];e.__webGLObjectsMap={}}l=0;for(g=e.objects.length;l<g;l++){q=e.objects[l];if(e.__webGLObjectsMap[q.id]==undefined)e.__webGLObjectsMap[q.id]={};s=e.__webGLObjectsMap[q.id];if(q instanceof THREE.Mesh)for(i in q.geometry.geometryChunks){h=q.geometry.geometryChunks[i];h.__webGLVertexBuffer||this.createBuffers(q,
+i);if(s[i]==undefined){h={buffer:h,object:q};e.__webGLObjects.push(h);s[i]=1}}}};this.removeObject=function(e,l){var g,q;for(g=e.__webGLObjects.length-1;g>=0;g--){q=e.__webGLObjects[g].object;l==q&&e.__webGLObjects.splice(g,1)}};this.setupMatrices=function(e,l){e.autoUpdateMatrix&&e.updateMatrix();x.multiply(l.matrix,e.matrix);H.set(l.matrix.flatten());G.set(x.flatten());J.set(l.projectionMatrix.flatten());z=THREE.Matrix4.makeInvert3x3(x).transpose();L.set(z.m);M.set(e.matrix.flatten())};this.loadMatrices=
+function(e){c.uniformMatrix4fv(e.uniforms.viewMatrix,false,H);c.uniformMatrix4fv(e.uniforms.modelViewMatrix,false,G);c.uniformMatrix4fv(e.uniforms.projectionMatrix,false,J);c.uniformMatrix3fv(e.uniforms.normalMatrix,false,L);c.uniformMatrix4fv(e.uniforms.objectMatrix,false,M)};this.loadCamera=function(e,l){c.uniform3f(e.uniforms.cameraPosition,l.position.x,l.position.y,l.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,l){if(e){!l||l=="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)};this.supportsVertexTextures=function(){return c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}};
+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};

File diff suppressed because it is too large
+ 115 - 114
build/ThreeExtras.js


+ 282 - 0
examples/materials_normalmap.html

@@ -0,0 +1,282 @@
+<!DOCTYPE HTML>
+<html lang="en">
+	<head>
+		<title>three.js - webgl normal map</title>
+		<meta charset="utf-8">
+		<style type="text/css">
+			body {
+				background:#000;
+				color:#fff;
+				padding:0;
+				margin:0;
+				font-weight: bold;
+				overflow:hidden;
+			}
+
+			a {	color: #ffffff;	}
+
+			#info {
+				position: absolute;
+				top: 0px; width: 100%;
+				color: #ffffff;
+				padding: 5px;
+				font-family:Monospace;
+				font-size:13px;
+				text-align:center;
+				z-index:1000; 
+			}
+			
+			#oldie {
+				font-family:monospace;
+				font-size:13px;
+				
+				text-align:center;
+				background:rgb(200,100,0);
+				color:#fff;
+				padding:1em;
+				
+				width:475px;
+				margin:5em auto 0;
+				
+				border:solid 2px #fff;
+				border-radius:10px;
+				
+				display:none;
+			}
+			
+			#vt { display:none } 
+			#vt, #vt a { color:orange; }
+			.code { }
+			
+			#log { position:absolute; top:50px; text-align:left; display:block; z-index:100 }
+		</style>
+	</head>
+
+	<body>
+		<pre id="log"></pre>
+		
+		<div id="info">
+			<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - webgl (<span id="description">normal + ao + displacement</span>) map demo. 
+			ninja head from <a href="http://developer.amd.com/archive/gpu/MeshMapper/pages/default.aspx" target="_blank">AMD GPU MeshMapper</a>
+			
+			<div id="vt">displacement mapping needs vertex textures (GPU with Shader Model 3.0)<br/>
+			on Windows use <span class="code">Chrome --use-gl=desktop</span> or Firefox 4<br/>
+			please star this <a href="http://code.google.com/p/chromium/issues/detail?id=52497">Chrome issue</a> to get ANGLE support
+			</div>
+		</div>
+		
+		<center>
+		<div id="oldie">
+			Sorry, your browser doesn't support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation">WebGL</a> 
+			and <a href="http://www.whatwg.org/specs/web-workers/current-work/">Web Workers</a>.<br/>
+			<br/>
+			Please try in 
+			<a href="http://www.chromium.org/getting-involved/dev-channel">Chrome 9+</a> / 
+			<a href="http://www.mozilla.com/en-US/firefox/all-beta.html">Firefox 4+</a> / 
+			<a href="http://nightly.webkit.org/">Safari OSX 10.6+</a>
+		</div>
+		</center>
+
+		<script type="text/javascript" src="../build/ThreeExtras.js"></script> 
+		<script type="text/javascript" src="js/Stats.js"></script>
+		
+		<script type="text/javascript">
+
+			if ( !is_browser_compatible() ) {
+			
+				document.getElementById( "oldie" ).style.display = "block";
+				
+			}
+			
+			var statsEnabled = true;
+
+			var container, stats, loader;
+
+			var camera, scene, webglRenderer;
+
+			var mesh, zmesh, lightMesh, geometry;
+			var mesh1, mesh2;
+	
+			var directionalLight, pointLight, ambientLight;
+
+			var mouseX = 0;
+			var mouseY = 0;
+
+			var windowHalfX = window.innerWidth / 2;
+			var windowHalfY = window.innerHeight / 2;
+
+			var r = 0.0;
+
+			document.addEventListener( 'mousemove', onDocumentMouseMove, false );
+
+			init();
+			setInterval( loop, 1000 / 60 );
+
+			function init() {
+
+				container = document.createElement('div');
+				document.body.appendChild(container);
+
+				camera = new THREE.Camera( 60, window.innerWidth / window.innerHeight, 1, 100000 );
+				camera.projectionMatrix = THREE.Matrix4.makeOrtho( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, -10000, 10000 );
+				camera.position.z = 6200;
+
+				scene = new THREE.Scene();
+
+				// LIGHTS
+
+				ambientLight = new THREE.AmbientLight( 0x111111 );
+				scene.addLight( ambientLight );
+
+				pointLight = new THREE.PointLight( 0xffff55 );
+				pointLight.position.z = 10000;
+				scene.addLight( pointLight );
+
+				directionalLight = new THREE.DirectionalLight( 0xaaaa88 );
+				directionalLight.position.x = 1;
+				directionalLight.position.y = 1;
+				directionalLight.position.z = 0.5;
+				directionalLight.position.normalize();
+				scene.addLight( directionalLight );
+
+				// light representation
+				
+				var sphere = new Sphere( 100, 16, 8, 1 );
+				lightMesh = new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color:0xffaa00 } ) );
+				lightMesh.position = pointLight.position;
+				lightMesh.scale.x = lightMesh.scale.y = lightMesh.scale.z = 0.05;
+				scene.addObject(lightMesh);
+
+				// common material parameters
+				
+				var ambient = 0x050505, diffuse = 0x555555, specular = 0xaa6600, shininess = 10, scale = 23;
+
+				// normal map shader
+				
+				var fragment_shader = ShaderUtils.lib[ "normal" ].fragment_shader;
+				var vertex_shader = ShaderUtils.lib[ "normal" ].vertex_shader;
+				var uniforms = ShaderUtils.lib[ "normal" ].uniforms;
+
+				uniforms[ "tNormal" ].texture = ImageUtils.loadTexture( "textures/normal/ninja/normal.jpg" );
+				uniforms[ "tAO" ].texture = ImageUtils.loadTexture( "textures/normal/ninja/ao.jpg" );
+				
+				uniforms[ "tDisplacement" ].texture = ImageUtils.loadTexture( "textures/normal/ninja/displacement.jpg" );
+				uniforms[ "uDisplacementBias" ].value = -0.428408 * scale;
+				uniforms[ "uDisplacementScale" ].value = 2.436143 * scale;
+				
+				uniforms[ "uPointLightPos" ].value = pointLight.position;
+				uniforms[ "uPointLightColor" ].value = pointLight.color;
+
+				uniforms[ "uDirLightPos" ].value = directionalLight.position;
+				uniforms[ "uDirLightColor" ].value = directionalLight.color;
+				
+				uniforms[ "uAmbientLightColor" ].value = ambientLight.color;
+				
+				uniforms[ "uDiffuseColor" ].value.setHex( diffuse );
+				uniforms[ "uSpecularColor" ].value.setHex( specular );
+				uniforms[ "uAmbientColor" ].value.setHex( ambient );
+				
+				uniforms[ "uShininess" ].value = shininess;
+
+				var material1 = new THREE.MeshShaderMaterial( { fragment_shader: fragment_shader, 
+															    vertex_shader: vertex_shader, 
+															    uniforms: uniforms
+															  } );
+
+				var material2 = new THREE.MeshPhongMaterial( { color: diffuse, specular: specular, ambient: ambient, shininess: shininess } );
+
+				loader = new THREE.Loader( true );
+				document.body.appendChild( loader.statusDomElement );
+				
+				loader.loadBinary( "obj/ninja/NinjaLo_bin.js", function( geometry ) { createScene( geometry, scale, material1, material2 ) }, "obj/ninja" );
+
+				webglRenderer = new THREE.WebGLRenderer( scene );
+				webglRenderer.setSize( window.innerWidth, window.innerHeight );
+				container.appendChild( webglRenderer.domElement );
+
+				var description = "normal + ao" + ( webglRenderer.supportsVertexTextures() ? " + displacement" : " + <strike>displacement</strike>" );
+				document.getElementById( "description" ).innerHTML = description;
+				document.getElementById( "vt" ).style.display = webglRenderer.supportsVertexTextures() ? "none" : "block";
+				
+				if ( statsEnabled ) {
+
+					stats = new Stats();
+					stats.domElement.style.position = 'absolute';
+					stats.domElement.style.top = '0px';
+					stats.domElement.style.zIndex = 100;
+					container.appendChild( stats.domElement );
+
+				}
+
+			}
+
+			function createScene( geometry, scale, material1, material2 ) {
+				
+				geometry.computeTangents();
+				
+				mesh1 = SceneUtils.addMesh( scene, geometry, scale, -scale * 12, 0, 0, 0,0,0, material1 );
+				mesh2 = SceneUtils.addMesh( scene, geometry, scale,  scale * 12, 0, 0, 0,0,0, material2 );
+				
+				loader.statusDomElement.style.display = "none";
+				
+			}
+			
+			function onDocumentMouseMove(event) {
+
+				mouseX = ( event.clientX - windowHalfX ) * 10;
+				mouseY = ( event.clientY - windowHalfY ) * 10;
+
+			}
+			
+			function loop() {
+
+				var ry = mouseX * 0.0003, rx = mouseY * 0.0003;
+				
+				if( mesh1 ) {
+				
+					mesh1.rotation.y = ry;
+					mesh1.rotation.x = rx;
+					
+				}
+				
+				if( mesh2 ) {
+					
+					mesh2.rotation.y = ry;
+					mesh2.rotation.x = rx;
+					
+				}
+				
+				lightMesh.position.x = 2500 * Math.cos( r );
+				lightMesh.position.z = 2500 * Math.sin( r );
+
+				r += 0.01;
+
+				webglRenderer.render( scene, camera );
+
+				if ( statsEnabled ) stats.update();
+
+			}
+
+			function log( text ) {
+
+				var e = document.getElementById("log");
+				e.innerHTML = text + "<br/>" + e.innerHTML;
+
+			}
+			
+			function is_browser_compatible() {
+				
+				// WebGL support
+				
+				try { var test = new Float32Array(1); } catch(e) { return false; }
+				
+				// Web workers
+				
+				return !!window.Worker;
+			
+			}
+
+		</script>
+
+	</body>
+</html>

+ 7 - 0
examples/obj/ninja/.htaccess

@@ -0,0 +1,7 @@
+<Files *.js>
+SetOutputFilter DEFLATE
+</Files>
+
+<Files *.bin>
+SetOutputFilter DEFLATE
+</Files>

BIN
examples/obj/ninja/NinjaLo_bin.bin


+ 22 - 0
examples/obj/ninja/NinjaLo_bin.js

@@ -0,0 +1,22 @@
+// Converted from: ../../examples/obj/ninja/ninjaHead_Low.obj
+//  vertices: 4485
+//  faces: 4810 
+//  materials: 0
+//
+//  Generated with OBJ -> Three.js converter
+//  http://github.com/alteredq/three.js/blob/master/utils/exporters/convert_obj_threejs_slim.py
+
+
+var model = {
+    'materials': [	{
+	"a_dbg_color" : 0xeeeeee,
+	"a_dbg_index" : 0,
+	"a_dbg_name" : "default"
+	}],
+
+    'buffers': 'NinjaLo_bin.bin',
+
+    'end': (new Date).getTime()
+    }
+    
+postMessage( model );

BIN
examples/textures/normal/ninja/ao.jpg


BIN
examples/textures/normal/ninja/displacement.jpg


+ 2 - 0
examples/textures/normal/ninja/displacement.txt

@@ -0,0 +1,2 @@
+DisplacementMap Scale: 2.436143
+DisplacementMap Bias : -0.428408

BIN
examples/textures/normal/ninja/normal.jpg


+ 117 - 0
src/core/Geometry.js

@@ -12,6 +12,8 @@ THREE.Geometry = function () {
 
 	this.geometryChunks = {};
 
+	this.hasTangents = false;
+	
 };
 
 THREE.Geometry.prototype = {
@@ -167,6 +169,121 @@ THREE.Geometry.prototype = {
 
 	},
 
+	computeTangents: function() {
+		
+		// based on http://www.terathon.com/code/tangent.html
+		// tangents go to vertices
+		
+		var f, fl, v, vl, face, uv, vA, vB, vC, uvA, uvB, uvC,
+			x1, x2, y1, y2, z1, z2,
+			s1, s2, t1, t2, r, t, n,
+			tan1 = [], tan2 = [],
+			sdir = new THREE.Vector3(), tdir = new THREE.Vector3(),
+			tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3(), 
+			n = new THREE.Vector3(), w;
+		
+		for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
+
+			tan1[ v ] = new THREE.Vector3();
+			tan2[ v ] = new THREE.Vector3();
+
+		}
+		
+		function handleTriangle( context, a, b, c ) {
+			
+			vA = context.vertices[ a ].position;
+			vB = context.vertices[ b ].position;
+			vC = context.vertices[ c ].position;
+			
+			uvA = uv[ 0 ];
+			uvB = uv[ 1 ];
+			uvC = uv[ 2 ];
+			
+			x1 = vB.x - vA.x;
+			x2 = vC.x - vA.x;
+			y1 = vB.y - vA.y;
+			y2 = vC.y - vA.y;
+			z1 = vB.z - vA.z;
+			z2 = vC.z - vA.z;
+
+			s1 = uvB.u - uvA.u;
+			s2 = uvC.u - uvA.u;
+			t1 = uvB.v - uvA.v;
+			t2 = uvC.v - uvA.v;
+
+			r = 1.0 / ( s1 * t2 - s2 * t1 );
+			sdir.set( ( t2 * x1 - t1 * x2 ) * r, 
+					  ( t2 * y1 - t1 * y2 ) * r,
+					  ( t2 * z1 - t1 * z2 ) * r );
+			tdir.set( ( s1 * x2 - s2 * x1 ) * r, 
+					  ( s1 * y2 - s2 * y1 ) * r,
+					  ( s1 * z2 - s2 * z1 ) * r );
+			
+			tan1[ a ].addSelf( sdir );
+			tan1[ b ].addSelf( sdir );
+			tan1[ c ].addSelf( sdir );
+			
+			tan2[ a ].addSelf( tdir );
+			tan2[ b ].addSelf( tdir );
+			tan2[ c ].addSelf( tdir );
+			
+		}
+		
+		for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
+			
+			face = this.faces[ f ];
+			uv = this.uvs[ f ];
+			
+			if ( face instanceof THREE.Face3 ) {
+				
+				handleTriangle( this, face.a, face.b, face.c );
+				
+				this.vertices[ face.a ].normal.copy( face.vertexNormals[ 0 ] );
+				this.vertices[ face.b ].normal.copy( face.vertexNormals[ 1 ] );
+				this.vertices[ face.c ].normal.copy( face.vertexNormals[ 2 ] );
+				
+				
+			} else if ( face instanceof THREE.Face4 ) {
+				
+				handleTriangle( this, face.a, face.b, face.c );
+				
+				// this messes up everything
+				// quads need to be handled differently
+				//handleTriangle( this, face.a, face.c, face.d );
+
+				this.vertices[ face.a ].normal.copy( face.vertexNormals[ 0 ] );
+				this.vertices[ face.b ].normal.copy( face.vertexNormals[ 1 ] );
+				this.vertices[ face.c ].normal.copy( face.vertexNormals[ 2 ] );
+				this.vertices[ face.d ].normal.copy( face.vertexNormals[ 3 ] );
+				
+			}
+			
+		}
+		
+		for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
+			
+			n.copy( this.vertices[ v ].normal );
+			t = tan1[ v ];
+			
+			// Gram-Schmidt orthogonalize
+			
+			tmp.copy( t );
+			tmp.subSelf( n.multiplyScalar( n.dot( t ) ) ).normalize();
+			
+			// Calculate handedness
+			
+			tmp2.cross( this.vertices[ v ].normal, t );
+			test = tmp2.dot( tan2[ v ] );
+			w = (test < 0.0) ? -1.0 : 1.0;
+			
+			this.vertices[ v ].tangent.set( tmp.x, tmp.y, tmp.z, w );
+			
+		}
+		
+		this.hasTangents = true;
+		
+	},
+	
 	computeBoundingBox: function () {
 
 		if ( this.vertices.length > 0 ) {

+ 2 - 0
src/core/Vertex.js

@@ -12,6 +12,8 @@ THREE.Vertex = function ( position, normal ) {
 	this.normalWorld = new THREE.Vector3();
 	this.normalScreen = new THREE.Vector3();
 
+	this.tangent = new THREE.Vector4();
+	
 	this.__visible = true;
 
 }

+ 195 - 0
src/extras/ShaderUtils.js

@@ -62,6 +62,201 @@ var ShaderUtils = {
 			"}"	
 			].join("\n")
 			
+		},
+		
+		'normal' : {
+			
+		uniforms: {
+		
+		"tNormal":			{ type: "t", value: 2, texture: null },
+		"tAO":				{ type: "t", value: 3, texture: null },
+		
+		"tDisplacement":	 { type: "t", value: 4, texture: null },
+		"uDisplacementBias": { type: "f", value: -0.5 },
+		"uDisplacementScale":{ type: "f", value: 2.5 },
+		
+		"uPointLightPos":	{ type: "v3", value: new THREE.Vector3() },
+		"uPointLightColor":	{ type: "c", value: new THREE.Color( 0xeeeeee ) },
+		
+		"uDirLightPos":		{ type: "v3", value: new THREE.Vector3() },
+		"uDirLightColor":	{ type: "c", value: new THREE.Color( 0xeeeeee ) },
+		
+		"uAmbientLightColor":{ type: "c", value: new THREE.Color( 0x050505 ) },
+		
+		"uDiffuseColor":	{ type: "c", value: new THREE.Color( 0xeeeeee ) },
+		"uSpecularColor":	{ type: "c", value: new THREE.Color( 0x111111 ) },
+		"uAmbientColor":	{ type: "c", value: new THREE.Color( 0x050505 ) },
+		"uShininess":		{ type: "f", value: 30 }
+		
+		},
+		
+		fragment_shader: [
+		
+		"uniform vec3 uDirLightPos;",
+		"uniform vec3 uDirLightColor;",
+
+		"uniform vec3 uPointLightPos;",
+		"uniform vec3 uPointLightColor;",
+
+		"uniform vec3 uAmbientColor;",
+		"uniform vec3 uDiffuseColor;",
+		"uniform vec3 uSpecularColor;",
+		"uniform float uShininess;",
+		
+		"uniform sampler2D tNormal;",
+		"uniform sampler2D tAO;",
+		
+		"varying vec3 vTangent;",
+		"varying vec3 vBinormal;",
+		"varying vec3 vNormal;",
+		"varying vec2 vUv;",
+		
+		"varying vec3 vLightWeighting;",
+		"varying vec3 vPointLightVector;",
+		"varying vec3 vViewPosition;",
+		
+		"void main() {",
+			
+			"vec3 normalTex = normalize( texture2D( tNormal, vUv ).xyz * 2.0 - 1.0 );",
+			"vec3 aoTex = texture2D( tAO, vUv ).xyz;",
+			
+			"mat3 tsb = mat3( vTangent, vBinormal, vNormal );",
+			"vec3 finalNormal = tsb * normalTex;",
+			
+			"vec3 normal = normalize( finalNormal );",
+			"vec3 viewPosition = normalize( vViewPosition );",
+
+			// point light
+
+			"vec4 pointDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );",
+			"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );",
+
+			"vec3 pointVector = normalize( vPointLightVector );",
+			"vec3 pointHalfVector = normalize( vPointLightVector + vViewPosition );",
+
+			"float pointDotNormalHalf = dot( normal, pointHalfVector );",
+			"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );",
+
+			"float pointSpecularWeight = 0.0;",
+			"if ( pointDotNormalHalf >= 0.0 )",
+				"pointSpecularWeight = pow( pointDotNormalHalf, uShininess );",
+
+			"pointDiffuse  += vec4( uDiffuseColor, 1.0 ) * pointDiffuseWeight;",
+			"pointSpecular += vec4( uSpecularColor, 1.0 ) * pointSpecularWeight;",
+
+			// directional light
+
+			"vec4 dirDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );",
+			"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );",
+
+			"vec4 lDirection = viewMatrix * vec4( uDirLightPos, 0.0 );",
+
+			"vec3 dirVector = normalize( lDirection.xyz );",
+			"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );",
+
+			"float dirDotNormalHalf = dot( normal, dirHalfVector );",
+			"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );",
+
+			"float dirSpecularWeight = 0.0;",
+			"if ( dirDotNormalHalf >= 0.0 )",
+				"dirSpecularWeight = pow( dirDotNormalHalf, uShininess );",
+
+			"dirDiffuse  += vec4( uDiffuseColor, 1.0 ) * dirDiffuseWeight;",
+			"dirSpecular += vec4( uSpecularColor, 1.0 ) * dirSpecularWeight;",
+
+			// all lights contribution summation
+
+			"vec4 totalLight = vec4( uAmbientColor, 1.0 );",
+			"totalLight += dirDiffuse + dirSpecular;",
+			"totalLight += pointDiffuse + pointSpecular;",
+
+			"gl_FragColor = vec4( totalLight.xyz * vLightWeighting * aoTex, 1.0 );",
+			
+		"}"	
+		].join("\n"),
+				
+		vertex_shader: [
+
+		"attribute vec4 tangent;",
+
+		"uniform vec3 uDirLightPos;",
+		"uniform vec3 uDirLightColor;",
+
+		"uniform vec3 uPointLightPos;",
+		"uniform vec3 uPointLightColor;",
+		
+		"uniform vec3 uAmbientLightColor;",
+		
+		"#ifdef VERTEX_TEXTURES",
+		
+		"uniform sampler2D tDisplacement;",
+		"uniform float uDisplacementScale;",
+		"uniform float uDisplacementBias;",
+		
+		"#endif",
+		
+		"varying vec3 vTangent;",
+		"varying vec3 vBinormal;",
+		"varying vec3 vNormal;",
+		"varying vec2 vUv;",
+		
+		"varying vec3 vLightWeighting;",
+		"varying vec3 vPointLightVector;",
+		"varying vec3 vViewPosition;",
+		
+		"void main() {",
+		
+			"vec4 mPosition = objectMatrix * vec4( position, 1.0 );",
+			"vViewPosition = cameraPosition - mPosition.xyz;",
+		
+			"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
+			"vNormal = normalize( normalMatrix * normal );",
+			
+			// tangent and binormal vectors
+			
+			"vTangent = normalize( normalMatrix * tangent.xyz );",
+
+			"vBinormal = cross( vNormal, vTangent ) * tangent.w;",
+			"vBinormal = normalize( vBinormal );",
+			
+			"vUv = uv;",
+			
+			// ambient light
+			
+			"vLightWeighting = uAmbientLightColor;",
+			
+			// point light
+			
+			"vec4 lPosition = viewMatrix * vec4( uPointLightPos, 1.0 );",
+			"vPointLightVector = normalize( lPosition.xyz - mvPosition.xyz );",
+			"float pointLightWeighting = max( dot( vNormal, vPointLightVector ), 0.0 );",
+			"vLightWeighting += uPointLightColor * pointLightWeighting;",
+			
+			// directional light
+			
+			"vec4 lDirection = viewMatrix * vec4( uDirLightPos, 0.0 );",
+			"float directionalLightWeighting = max( dot( vNormal, normalize( lDirection.xyz ) ), 0.0 );",
+			"vLightWeighting += uDirLightColor * directionalLightWeighting;",
+			
+			// displacement mapping
+			
+			"#ifdef VERTEX_TEXTURES",
+			
+			"vec3 dv = texture2D( tDisplacement, uv ).xyz;",
+			"float df = uDisplacementScale * dv.x + uDisplacementBias;",
+			"vec4 displacedPosition = vec4( vNormal.xyz * df, 0.0 ) + mvPosition;",
+			"gl_Position = projectionMatrix * displacedPosition;",
+			
+			"#else",
+			
+			"gl_Position = projectionMatrix * mvPosition;",
+			
+			"#endif",
+			
+		"}"	
+		
+		].join("\n")
+
 		}
 	}
 

+ 65 - 6
src/renderers/WebGLRenderer.js

@@ -159,13 +159,14 @@ THREE.WebGLRenderer = function ( scene ) {
 
 	this.createBuffers = function ( object, g ) {
 
-		var f, fl, fi, face, vertexNormals, normal, uv, v1, v2, v3, v4, m, ml, i,
+		var f, fl, fi, face, vertexNormals, normal, uv, v1, v2, v3, v4, t1, t2, t3, t4, m, ml, i,
 
 		faceArray = [],
 		lineArray = [],
 
 		vertexArray = [],
 		normalArray = [],
+		tangentArray = [],
 		uvArray = [],
 
 		vertexIndex = 0,
@@ -193,8 +194,21 @@ THREE.WebGLRenderer = function ( scene ) {
 				vertexArray.push( v2.x, v2.y, v2.z );
 				vertexArray.push( v3.x, v3.y, v3.z );
 
+				if ( object.geometry.hasTangents ) {
+					
+					t1 = object.geometry.vertices[ face.a ].tangent;
+					t2 = object.geometry.vertices[ face.b ].tangent;
+					t3 = object.geometry.vertices[ face.c ].tangent;
+
+					tangentArray.push( t1.x, t1.y, t1.z, t1.w );
+					tangentArray.push( t2.x, t2.y, t2.z, t2.w );
+					tangentArray.push( t3.x, t3.y, t3.z, t3.w );
+					
+				}
+
 				if ( vertexNormals.length == 3 && needsSmoothNormals ) {
 
+					
 					for ( i = 0; i < 3; i ++ ) {
 
 						normalArray.push( vertexNormals[ i ].x, vertexNormals[ i ].y, vertexNormals[ i ].z );
@@ -242,15 +256,29 @@ THREE.WebGLRenderer = function ( scene ) {
 				vertexArray.push( v2.x, v2.y, v2.z );
 				vertexArray.push( v3.x, v3.y, v3.z );
 				vertexArray.push( v4.x, v4.y, v4.z );
+				
+				if ( object.geometry.hasTangents ) {
+					
+					t1 = object.geometry.vertices[ face.a ].tangent;
+					t2 = object.geometry.vertices[ face.b ].tangent;
+					t3 = object.geometry.vertices[ face.c ].tangent;
+					t4 = object.geometry.vertices[ face.d ].tangent;
+
+					tangentArray.push( t1.x, t1.y, t1.z, t1.w );
+					tangentArray.push( t2.x, t2.y, t2.z, t2.w );
+					tangentArray.push( t3.x, t3.y, t3.z, t3.w );
+					tangentArray.push( t4.x, t4.y, t4.z, t4.w );
+					
+				}
 
 				if ( vertexNormals.length == 4 && needsSmoothNormals ) {
-
+					
 					for ( i = 0; i < 4; i ++ ) {
 
 						normalArray.push( vertexNormals[ i ].x, vertexNormals[ i ].y, vertexNormals[ i ].z );
 
 					}
-
+					
 				} else {
 
 					for ( i = 0; i < 4; i ++ ) {
@@ -302,6 +330,14 @@ THREE.WebGLRenderer = function ( scene ) {
 		_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryChunk.__webGLNormalBuffer );
 		_gl.bufferData( _gl.ARRAY_BUFFER, new Float32Array( normalArray ), _gl.STATIC_DRAW );
 
+		if ( object.geometry.hasTangents ) {
+			
+			geometryChunk.__webGLTangentBuffer = _gl.createBuffer();
+			_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryChunk.__webGLTangentBuffer );
+			_gl.bufferData( _gl.ARRAY_BUFFER, new Float32Array( tangentArray ), _gl.STATIC_DRAW );
+			
+		}
+		
 		if ( uvArray.length > 0 ) {
 
 			geometryChunk.__webGLUVBuffer = _gl.createBuffer();
@@ -346,7 +382,7 @@ THREE.WebGLRenderer = function ( scene ) {
 
 				}
 				cacheUniformLocations( material.program, identifiers );
-				cacheAttributeLocations( material.program, [ "position", "normal", "uv" ] );
+				cacheAttributeLocations( material.program, [ "position", "normal", "uv", "tangent" ] );
 
 			}
 
@@ -374,7 +410,6 @@ THREE.WebGLRenderer = function ( scene ) {
 		this.loadCamera( program, camera );
 		this.loadMatrices( program );
 
-
 		if ( material instanceof THREE.MeshShaderMaterial ) {
 
 			mWireframe = material.wireframe;
@@ -507,6 +542,15 @@ THREE.WebGLRenderer = function ( scene ) {
 		_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryChunk.__webGLNormalBuffer );
 		_gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
 
+		// tangents
+
+		if ( attributes.tangent >= 0 ) {
+			
+			_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryChunk.__webGLTangentBuffer );
+			_gl.vertexAttribPointer( attributes.tangent, 4, _gl.FLOAT, false, 0, 0 );
+			
+		}
+		
 		// uvs
 
 		if ( attributes.uv >= 0 ) {
@@ -828,6 +872,19 @@ THREE.WebGLRenderer = function ( scene ) {
 
 	};
 
+	this.supportsVertexTextures = function() {
+		
+		return maxVertexTextures() > 0;
+		
+	};
+	
+	function maxVertexTextures() {
+		
+		return _gl.getParameter( _gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
+
+	};
+	
+	
 	function initGL() {
 
 		try {
@@ -940,7 +997,7 @@ THREE.WebGLRenderer = function ( scene ) {
 
 				"} else if ( material == 4 ) { ",
 
-					"gl_FragColor = vec4( 0.5*normalize( vNormal ) + vec3(0.5, 0.5, 0.5), mOpacity );",
+					"gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, mOpacity );",
 
 				// Depth
 
@@ -1184,6 +1241,8 @@ THREE.WebGLRenderer = function ( scene ) {
 		].join("\n"),
 
 		prefix_vertex = [
+			maxVertexTextures() > 0 ? "#define VERTEX_TEXTURES" : "",
+		
 			"uniform mat4 objectMatrix;",
 			"uniform mat4 modelViewMatrix;",
 			"uniform mat4 projectionMatrix;",

Some files were not shown because too many files changed in this diff