Fixed scene check bug in allocateLights in WebGLRenderer.

Also some refactoring of initWebGLObjects slipped in this commit.
This commit is contained in:
alteredq
2011-01-09 07:37:20 +01:00
parent e43de3dcf7
commit bc9cf2be75
5 changed files with 352 additions and 349 deletions
+94 -94
View File
@@ -12,48 +12,48 @@ THREE.Vector4=function(a,b,f,e){this.x=a||0;this.y=b||0;this.z=f||0;this.w=e||1}
THREE.Vector4.prototype={set:function(a,b,f,e){this.x=a;this.y=b;this.z=f;this.w=e;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w||1;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;
return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=a;this.w/=a;return this},lerpSelf:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},toString:function(){return"THREE.Vector4 ("+this.x+", "+this.y+", "+this.z+", "+this.w+")"}};
THREE.Ray=function(a,b){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3};
THREE.Ray.prototype={intersectScene:function(a){var b,f,e=a.objects,g=[];a=0;for(b=e.length;a<b;a++){f=e[a];if(f instanceof THREE.Mesh)g=g.concat(this.intersectObject(f))}g.sort(function(j,o){return j.distance-o.distance});return g},intersectObject:function(a){function b(O,q,L,d){d=d.clone().subSelf(q);L=L.clone().subSelf(q);var h=O.clone().subSelf(q);O=d.dot(d);q=d.dot(L);d=d.dot(h);var r=L.dot(L);L=L.dot(h);h=1/(O*r-q*q);r=(r*d-q*L)*h;O=(O*L-q*d)*h;return r>0&&O>0&&r+O<1}var f,e,g,j,o,c,k,n,B,D,
x,A=a.geometry,M=A.vertices,Q=[];f=0;for(e=A.faces.length;f<e;f++){g=A.faces[f];D=this.origin.clone();x=this.direction.clone();j=a.matrix.multiplyVector3(M[g.a].position.clone());o=a.matrix.multiplyVector3(M[g.b].position.clone());c=a.matrix.multiplyVector3(M[g.c].position.clone());k=g instanceof THREE.Face4?a.matrix.multiplyVector3(M[g.d].position.clone()):null;n=a.rotationMatrix.multiplyVector3(g.normal.clone());B=x.dot(n);if(B<0){n=n.dot((new THREE.Vector3).sub(j,D))/B;D=D.addSelf(x.multiplyScalar(n));
if(g instanceof THREE.Face3){if(b(D,j,o,c)){g={distance:this.origin.distanceTo(D),point:D,face:g,object:a};Q.push(g)}}else if(g instanceof THREE.Face4)if(b(D,j,o,k)||b(D,o,c,k)){g={distance:this.origin.distanceTo(D),point:D,face:g,object:a};Q.push(g)}}}return Q}};
THREE.Rectangle=function(){function a(){j=e-b;o=g-f}var b,f,e,g,j,o,c=true;this.getX=function(){return b};this.getY=function(){return f};this.getWidth=function(){return j};this.getHeight=function(){return o};this.getLeft=function(){return b};this.getTop=function(){return f};this.getRight=function(){return e};this.getBottom=function(){return g};this.set=function(k,n,B,D){c=false;b=k;f=n;e=B;g=D;a()};this.addPoint=function(k,n){if(c){c=false;b=k;f=n;e=k;g=n}else{b=b<k?b:k;f=f<n?f:n;e=e>k?e:k;g=g>n?
g:n}a()};this.add3Points=function(k,n,B,D,x,A){if(c){c=false;b=k<B?k<x?k:x:B<x?B:x;f=n<D?n<A?n:A:D<A?D:A;e=k>B?k>x?k:x:B>x?B:x;g=n>D?n>A?n:A:D>A?D:A}else{b=k<B?k<x?k<b?k:b:x<b?x:b:B<x?B<b?B:b:x<b?x:b;f=n<D?n<A?n<f?n:f:A<f?A:f:D<A?D<f?D:f:A<f?A:f;e=k>B?k>x?k>e?k:e:x>e?x:e:B>x?B>e?B:e:x>e?x:e;g=n>D?n>A?n>g?n:g:A>g?A:g:D>A?D>g?D:g:A>g?A:g}a()};this.addRectangle=function(k){if(c){c=false;b=k.getLeft();f=k.getTop();e=k.getRight();g=k.getBottom()}else{b=b<k.getLeft()?b:k.getLeft();f=f<k.getTop()?f:k.getTop();
THREE.Ray.prototype={intersectScene:function(a){var b,f,e=a.objects,g=[];a=0;for(b=e.length;a<b;a++){f=e[a];if(f instanceof THREE.Mesh)g=g.concat(this.intersectObject(f))}g.sort(function(j,p){return j.distance-p.distance});return g},intersectObject:function(a){function b(O,s,L,d){d=d.clone().subSelf(s);L=L.clone().subSelf(s);var h=O.clone().subSelf(s);O=d.dot(d);s=d.dot(L);d=d.dot(h);var q=L.dot(L);L=L.dot(h);h=1/(O*q-s*s);q=(q*d-s*L)*h;O=(O*L-s*d)*h;return q>0&&O>0&&q+O<1}var f,e,g,j,p,c,k,m,B,D,
x,A=a.geometry,M=A.vertices,Q=[];f=0;for(e=A.faces.length;f<e;f++){g=A.faces[f];D=this.origin.clone();x=this.direction.clone();j=a.matrix.multiplyVector3(M[g.a].position.clone());p=a.matrix.multiplyVector3(M[g.b].position.clone());c=a.matrix.multiplyVector3(M[g.c].position.clone());k=g instanceof THREE.Face4?a.matrix.multiplyVector3(M[g.d].position.clone()):null;m=a.rotationMatrix.multiplyVector3(g.normal.clone());B=x.dot(m);if(B<0){m=m.dot((new THREE.Vector3).sub(j,D))/B;D=D.addSelf(x.multiplyScalar(m));
if(g instanceof THREE.Face3){if(b(D,j,p,c)){g={distance:this.origin.distanceTo(D),point:D,face:g,object:a};Q.push(g)}}else if(g instanceof THREE.Face4)if(b(D,j,p,k)||b(D,p,c,k)){g={distance:this.origin.distanceTo(D),point:D,face:g,object:a};Q.push(g)}}}return Q}};
THREE.Rectangle=function(){function a(){j=e-b;p=g-f}var b,f,e,g,j,p,c=true;this.getX=function(){return b};this.getY=function(){return f};this.getWidth=function(){return j};this.getHeight=function(){return p};this.getLeft=function(){return b};this.getTop=function(){return f};this.getRight=function(){return e};this.getBottom=function(){return g};this.set=function(k,m,B,D){c=false;b=k;f=m;e=B;g=D;a()};this.addPoint=function(k,m){if(c){c=false;b=k;f=m;e=k;g=m}else{b=b<k?b:k;f=f<m?f:m;e=e>k?e:k;g=g>m?
g:m}a()};this.add3Points=function(k,m,B,D,x,A){if(c){c=false;b=k<B?k<x?k:x:B<x?B:x;f=m<D?m<A?m:A:D<A?D:A;e=k>B?k>x?k:x:B>x?B:x;g=m>D?m>A?m:A:D>A?D:A}else{b=k<B?k<x?k<b?k:b:x<b?x:b:B<x?B<b?B:b:x<b?x:b;f=m<D?m<A?m<f?m:f:A<f?A:f:D<A?D<f?D:f:A<f?A:f;e=k>B?k>x?k>e?k:e:x>e?x:e:B>x?B>e?B:e:x>e?x:e;g=m>D?m>A?m>g?m:g:A>g?A:g:D>A?D>g?D:g:A>g?A:g}a()};this.addRectangle=function(k){if(c){c=false;b=k.getLeft();f=k.getTop();e=k.getRight();g=k.getBottom()}else{b=b<k.getLeft()?b:k.getLeft();f=f<k.getTop()?f:k.getTop();
e=e>k.getRight()?e:k.getRight();g=g>k.getBottom()?g:k.getBottom()}a()};this.inflate=function(k){b-=k;f-=k;e+=k;g+=k;a()};this.minSelf=function(k){b=b>k.getLeft()?b:k.getLeft();f=f>k.getTop()?f:k.getTop();e=e<k.getRight()?e:k.getRight();g=g<k.getBottom()?g:k.getBottom();a()};this.instersects=function(k){return Math.min(e,k.getRight())-Math.max(b,k.getLeft())>=0&&Math.min(g,k.getBottom())-Math.max(f,k.getTop())>=0};this.empty=function(){c=true;g=e=f=b=0;a()};this.isEmpty=function(){return c};this.toString=
function(){return"THREE.Rectangle ( left: "+b+", right: "+e+", top: "+f+", bottom: "+g+", width: "+j+", height: "+o+" )"}};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(a,b,f,e,g,j,o,c,k,n,B,D,x,A,M,Q){this.n11=a||1;this.n12=b||0;this.n13=f||0;this.n14=e||0;this.n21=g||0;this.n22=j||1;this.n23=o||0;this.n24=c||0;this.n31=k||0;this.n32=n||0;this.n33=B||1;this.n34=D||0;this.n41=x||0;this.n42=A||0;this.n43=M||0;this.n44=Q||1};
THREE.Matrix4.prototype={identity:function(){this.n11=1;this.n21=this.n14=this.n13=this.n12=0;this.n22=1;this.n32=this.n31=this.n24=this.n23=0;this.n33=1;this.n43=this.n42=this.n41=this.n34=0;this.n44=1;return this},set:function(a,b,f,e,g,j,o,c,k,n,B,D,x,A,M,Q){this.n11=a;this.n12=b;this.n13=f;this.n14=e;this.n21=g;this.n22=j;this.n23=o;this.n24=c;this.n31=k;this.n32=n;this.n33=B;this.n34=D;this.n41=x;this.n42=A;this.n43=M;this.n44=Q;return this},copy:function(a){this.n11=a.n11;this.n12=a.n12;this.n13=
function(){return"THREE.Rectangle ( left: "+b+", right: "+e+", top: "+f+", bottom: "+g+", width: "+j+", height: "+p+" )"}};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(a,b,f,e,g,j,p,c,k,m,B,D,x,A,M,Q){this.n11=a||1;this.n12=b||0;this.n13=f||0;this.n14=e||0;this.n21=g||0;this.n22=j||1;this.n23=p||0;this.n24=c||0;this.n31=k||0;this.n32=m||0;this.n33=B||1;this.n34=D||0;this.n41=x||0;this.n42=A||0;this.n43=M||0;this.n44=Q||1};
THREE.Matrix4.prototype={identity:function(){this.n11=1;this.n21=this.n14=this.n13=this.n12=0;this.n22=1;this.n32=this.n31=this.n24=this.n23=0;this.n33=1;this.n43=this.n42=this.n41=this.n34=0;this.n44=1;return this},set:function(a,b,f,e,g,j,p,c,k,m,B,D,x,A,M,Q){this.n11=a;this.n12=b;this.n13=f;this.n14=e;this.n21=g;this.n22=j;this.n23=p;this.n24=c;this.n31=k;this.n32=m;this.n33=B;this.n34=D;this.n41=x;this.n42=A;this.n43=M;this.n44=Q;return this},copy:function(a){this.n11=a.n11;this.n12=a.n12;this.n13=
a.n13;this.n14=a.n14;this.n21=a.n21;this.n22=a.n22;this.n23=a.n23;this.n24=a.n24;this.n31=a.n31;this.n32=a.n32;this.n33=a.n33;this.n34=a.n34;this.n41=a.n41;this.n42=a.n42;this.n43=a.n43;this.n44=a.n44;return this},lookAt:function(a,b,f){var e=new THREE.Vector3,g=new THREE.Vector3,j=new THREE.Vector3;j.sub(a,b).normalize();e.cross(f,j).normalize();g.cross(j,e).normalize();this.n11=e.x;this.n12=e.y;this.n13=e.z;this.n14=-e.dot(a);this.n21=g.x;this.n22=g.y;this.n23=g.z;this.n24=-g.dot(a);this.n31=j.x;
this.n32=j.y;this.n33=j.z;this.n34=-j.dot(a);this.n43=this.n42=this.n41=0;this.n44=1;return this},multiplyVector3:function(a){var b=a.x,f=a.y,e=a.z,g=1/(this.n41*b+this.n42*f+this.n43*e+this.n44);a.x=(this.n11*b+this.n12*f+this.n13*e+this.n14)*g;a.y=(this.n21*b+this.n22*f+this.n23*e+this.n24)*g;a.z=(this.n31*b+this.n32*f+this.n33*e+this.n34)*g;return a},multiplyVector4:function(a){var b=a.x,f=a.y,e=a.z,g=a.w;a.x=this.n11*b+this.n12*f+this.n13*e+this.n14*g;a.y=this.n21*b+this.n22*f+this.n23*e+this.n24*
g;a.z=this.n31*b+this.n32*f+this.n33*e+this.n34*g;a.w=this.n41*b+this.n42*f+this.n43*e+this.n44*g;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 f=a.n11,e=a.n12,g=a.n13,j=a.n14,o=a.n21,c=a.n22,k=a.n23,n=a.n24,B=a.n31,D=a.n32,
x=a.n33,A=a.n34,M=a.n41,Q=a.n42,O=a.n43,q=a.n44,L=b.n11,d=b.n12,h=b.n13,r=b.n14,l=b.n21,m=b.n22,i=b.n23,t=b.n24,p=b.n31,y=b.n32,u=b.n33,s=b.n34,v=b.n41,W=b.n42,G=b.n43,S=b.n44;this.n11=f*L+e*l+g*p+j*v;this.n12=f*d+e*m+g*y+j*W;this.n13=f*h+e*i+g*u+j*G;this.n14=f*r+e*t+g*s+j*S;this.n21=o*L+c*l+k*p+n*v;this.n22=o*d+c*m+k*y+n*W;this.n23=o*h+c*i+k*u+n*G;this.n24=o*r+c*t+k*s+n*S;this.n31=B*L+D*l+x*p+A*v;this.n32=B*d+D*m+x*y+A*W;this.n33=B*h+D*i+x*u+A*G;this.n34=B*r+D*t+x*s+A*S;this.n41=M*L+Q*l+O*p+q*v;
this.n42=M*d+Q*m+O*y+q*W;this.n43=M*h+Q*i+O*u+q*G;this.n44=M*r+Q*t+O*s+q*S;return this},multiplySelf:function(a){var b=this.n11,f=this.n12,e=this.n13,g=this.n14,j=this.n21,o=this.n22,c=this.n23,k=this.n24,n=this.n31,B=this.n32,D=this.n33,x=this.n34,A=this.n41,M=this.n42,Q=this.n43,O=this.n44,q=a.n11,L=a.n21,d=a.n31,h=a.n41,r=a.n12,l=a.n22,m=a.n32,i=a.n42,t=a.n13,p=a.n23,y=a.n33,u=a.n43,s=a.n14,v=a.n24,W=a.n34;a=a.n44;this.n11=b*q+f*L+e*d+g*h;this.n12=b*r+f*l+e*m+g*i;this.n13=b*t+f*p+e*y+g*u;this.n14=
b*s+f*v+e*W+g*a;this.n21=j*q+o*L+c*d+k*h;this.n22=j*r+o*l+c*m+k*i;this.n23=j*t+o*p+c*y+k*u;this.n24=j*s+o*v+c*W+k*a;this.n31=n*q+B*L+D*d+x*h;this.n32=n*r+B*l+D*m+x*i;this.n33=n*t+B*p+D*y+x*u;this.n34=n*s+B*v+D*W+x*a;this.n41=A*q+M*L+Q*d+O*h;this.n42=A*r+M*l+Q*m+O*i;this.n43=A*t+M*p+Q*y+O*u;this.n44=A*s+M*v+Q*W+O*a;return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=
g;a.z=this.n31*b+this.n32*f+this.n33*e+this.n34*g;a.w=this.n41*b+this.n42*f+this.n43*e+this.n44*g;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 f=a.n11,e=a.n12,g=a.n13,j=a.n14,p=a.n21,c=a.n22,k=a.n23,m=a.n24,B=a.n31,D=a.n32,
x=a.n33,A=a.n34,M=a.n41,Q=a.n42,O=a.n43,s=a.n44,L=b.n11,d=b.n12,h=b.n13,q=b.n14,n=b.n21,l=b.n22,i=b.n23,u=b.n24,o=b.n31,y=b.n32,t=b.n33,r=b.n34,v=b.n41,W=b.n42,G=b.n43,S=b.n44;this.n11=f*L+e*n+g*o+j*v;this.n12=f*d+e*l+g*y+j*W;this.n13=f*h+e*i+g*t+j*G;this.n14=f*q+e*u+g*r+j*S;this.n21=p*L+c*n+k*o+m*v;this.n22=p*d+c*l+k*y+m*W;this.n23=p*h+c*i+k*t+m*G;this.n24=p*q+c*u+k*r+m*S;this.n31=B*L+D*n+x*o+A*v;this.n32=B*d+D*l+x*y+A*W;this.n33=B*h+D*i+x*t+A*G;this.n34=B*q+D*u+x*r+A*S;this.n41=M*L+Q*n+O*o+s*v;
this.n42=M*d+Q*l+O*y+s*W;this.n43=M*h+Q*i+O*t+s*G;this.n44=M*q+Q*u+O*r+s*S;return this},multiplySelf:function(a){var b=this.n11,f=this.n12,e=this.n13,g=this.n14,j=this.n21,p=this.n22,c=this.n23,k=this.n24,m=this.n31,B=this.n32,D=this.n33,x=this.n34,A=this.n41,M=this.n42,Q=this.n43,O=this.n44,s=a.n11,L=a.n21,d=a.n31,h=a.n41,q=a.n12,n=a.n22,l=a.n32,i=a.n42,u=a.n13,o=a.n23,y=a.n33,t=a.n43,r=a.n14,v=a.n24,W=a.n34;a=a.n44;this.n11=b*s+f*L+e*d+g*h;this.n12=b*q+f*n+e*l+g*i;this.n13=b*u+f*o+e*y+g*t;this.n14=
b*r+f*v+e*W+g*a;this.n21=j*s+p*L+c*d+k*h;this.n22=j*q+p*n+c*l+k*i;this.n23=j*u+p*o+c*y+k*t;this.n24=j*r+p*v+c*W+k*a;this.n31=m*s+B*L+D*d+x*h;this.n32=m*q+B*n+D*l+x*i;this.n33=m*u+B*o+D*y+x*t;this.n34=m*r+B*v+D*W+x*a;this.n41=A*s+M*L+Q*d+O*h;this.n42=A*q+M*n+Q*l+O*i;this.n43=A*u+M*o+Q*y+O*t;this.n44=A*r+M*v+Q*W+O*a;return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=
a;this.n42*=a;this.n43*=a;this.n44*=a;return this},determinant:function(){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,f,e){var g=b[f];b[f]=b[e];
b[e]=g}a(this,"n21","n12");a(this,"n31","n13");a(this,"n32","n23");a(this,"n41","n14");a(this,"n42","n24");a(this,"n43","n34");return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=this.n44;return a},flatten:function(){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,f){var e=new THREE.Matrix4;e.n14=a;e.n24=b;e.n34=f;return e};
THREE.Matrix4.scaleMatrix=function(a,b,f){var e=new THREE.Matrix4;e.n11=a;e.n22=b;e.n33=f;return e};THREE.Matrix4.rotationXMatrix=function(a){var b=new THREE.Matrix4;b.n22=b.n33=Math.cos(a);b.n32=Math.sin(a);b.n23=-b.n32;return b};THREE.Matrix4.rotationYMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n33=Math.cos(a);b.n13=Math.sin(a);b.n31=-b.n13;return b};THREE.Matrix4.rotationZMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n22=Math.cos(a);b.n21=Math.sin(a);b.n12=-b.n21;return b};
THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var f=new THREE.Matrix4,e=Math.cos(b),g=Math.sin(b),j=1-e,o=a.x,c=a.y,k=a.z;f.n11=j*o*o+e;f.n12=j*o*c-g*k;f.n13=j*o*k+g*c;f.n21=j*o*c+g*k;f.n22=j*c*c+e;f.n23=j*c*k-g*o;f.n31=j*o*k-g*c;f.n32=j*c*k+g*o;f.n33=j*k*k+e;return f};
THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var f=new THREE.Matrix4,e=Math.cos(b),g=Math.sin(b),j=1-e,p=a.x,c=a.y,k=a.z;f.n11=j*p*p+e;f.n12=j*p*c-g*k;f.n13=j*p*k+g*c;f.n21=j*p*c+g*k;f.n22=j*c*c+e;f.n23=j*c*k-g*p;f.n31=j*p*k-g*c;f.n32=j*c*k+g*p;f.n33=j*k*k+e;return f};
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 f=b[10]*b[5]-b[6]*b[9],e=-b[10]*b[1]+b[2]*b[9],g=b[6]*b[1]-b[2]*b[5],j=-b[10]*b[4]+b[6]*b[8],o=b[10]*b[0]-b[2]*b[8],c=-b[6]*b[0]+b[2]*b[4],k=b[9]*b[4]-b[5]*b[8],n=-b[9]*b[0]+b[1]*b[8],B=b[5]*b[0]-b[1]*b[4];b=b[0]*f+b[1]*j+b[2]*k;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*f;a.m[1]=b*e;a.m[2]=b*g;a.m[3]=b*j;a.m[4]=b*o;a.m[5]=b*c;a.m[6]=b*k;a.m[7]=b*n;a.m[8]=b*B;return a};
THREE.Matrix4.makeFrustum=function(a,b,f,e,g,j){var o,c,k;o=new THREE.Matrix4;c=2*g/(b-a);k=2*g/(e-f);a=(b+a)/(b-a);f=(e+f)/(e-f);e=-(j+g)/(j-g);g=-2*j*g/(j-g);o.n11=c;o.n12=0;o.n13=a;o.n14=0;o.n21=0;o.n22=k;o.n23=f;o.n24=0;o.n31=0;o.n32=0;o.n33=e;o.n34=g;o.n41=0;o.n42=0;o.n43=-1;o.n44=0;return o};THREE.Matrix4.makePerspective=function(a,b,f,e){var g;a=f*Math.tan(a*Math.PI/360);g=-a;return THREE.Matrix4.makeFrustum(g*b,a*b,g,a,f,e)};
THREE.Matrix4.makeOrtho=function(a,b,f,e,g,j){var o,c,k,n;o=new THREE.Matrix4;c=b-a;k=f-e;n=j-g;a=(b+a)/c;f=(f+e)/k;g=(j+g)/n;o.n11=2/c;o.n12=0;o.n13=0;o.n14=-a;o.n21=0;o.n22=2/k;o.n23=0;o.n24=-f;o.n31=0;o.n32=0;o.n33=-2/n;o.n34=-g;o.n41=0;o.n42=0;o.n43=0;o.n44=1;return o};
THREE.Matrix4.makeInvert3x3=function(a){var b=a.flatten();a=new THREE.Matrix3;var f=b[10]*b[5]-b[6]*b[9],e=-b[10]*b[1]+b[2]*b[9],g=b[6]*b[1]-b[2]*b[5],j=-b[10]*b[4]+b[6]*b[8],p=b[10]*b[0]-b[2]*b[8],c=-b[6]*b[0]+b[2]*b[4],k=b[9]*b[4]-b[5]*b[8],m=-b[9]*b[0]+b[1]*b[8],B=b[5]*b[0]-b[1]*b[4];b=b[0]*f+b[1]*j+b[2]*k;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*f;a.m[1]=b*e;a.m[2]=b*g;a.m[3]=b*j;a.m[4]=b*p;a.m[5]=b*c;a.m[6]=b*k;a.m[7]=b*m;a.m[8]=b*B;return a};
THREE.Matrix4.makeFrustum=function(a,b,f,e,g,j){var p,c,k;p=new THREE.Matrix4;c=2*g/(b-a);k=2*g/(e-f);a=(b+a)/(b-a);f=(e+f)/(e-f);e=-(j+g)/(j-g);g=-2*j*g/(j-g);p.n11=c;p.n12=0;p.n13=a;p.n14=0;p.n21=0;p.n22=k;p.n23=f;p.n24=0;p.n31=0;p.n32=0;p.n33=e;p.n34=g;p.n41=0;p.n42=0;p.n43=-1;p.n44=0;return p};THREE.Matrix4.makePerspective=function(a,b,f,e){var g;a=f*Math.tan(a*Math.PI/360);g=-a;return THREE.Matrix4.makeFrustum(g*b,a*b,g,a,f,e)};
THREE.Matrix4.makeOrtho=function(a,b,f,e,g,j){var p,c,k,m;p=new THREE.Matrix4;c=b-a;k=f-e;m=j-g;a=(b+a)/c;f=(f+e)/k;g=(j+g)/m;p.n11=2/c;p.n12=0;p.n13=0;p.n14=-a;p.n21=0;p.n22=2/k;p.n23=0;p.n24=-f;p.n31=0;p.n32=0;p.n33=-2/m;p.n34=-g;p.n41=0;p.n42=0;p.n43=0;p.n44=1;return p};
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,f,e,g){this.a=a;this.b=b;this.c=f;this.centroid=new THREE.Vector3;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.materials=g instanceof Array?g:[g]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
THREE.Face4=function(a,b,f,e,g,j){this.a=a;this.b=b;this.c=f;this.d=e;this.centroid=new THREE.Vector3;this.normal=g instanceof THREE.Vector3?g:new THREE.Vector3;this.vertexNormals=g instanceof Array?g:[];this.materials=j instanceof Array?j:[j]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
THREE.UV.prototype={copy:function(a){this.u=a.u;this.v=a.v},toString:function(){return"THREE.UV ("+this.u+", "+this.v+")"}};THREE.Geometry=function(){this.vertices=[];this.faces=[];this.uvs=[];this.boundingSphere=this.boundingBox=null;this.geometryChunks={};this.hasTangents=false};
THREE.Geometry.prototype={computeCentroids:function(){var a,b,f;a=0;for(b=this.faces.length;a<b;a++){f=this.faces[a];f.centroid.set(0,0,0);if(f instanceof THREE.Face3){f.centroid.addSelf(this.vertices[f.a].position);f.centroid.addSelf(this.vertices[f.b].position);f.centroid.addSelf(this.vertices[f.c].position);f.centroid.divideScalar(3)}else if(f instanceof THREE.Face4){f.centroid.addSelf(this.vertices[f.a].position);f.centroid.addSelf(this.vertices[f.b].position);f.centroid.addSelf(this.vertices[f.c].position);
f.centroid.addSelf(this.vertices[f.d].position);f.centroid.divideScalar(4)}}},computeFaceNormals:function(a){var b,f,e,g,j,o,c=new THREE.Vector3,k=new THREE.Vector3;e=0;for(g=this.vertices.length;e<g;e++){j=this.vertices[e];j.normal.set(0,0,0)}e=0;for(g=this.faces.length;e<g;e++){j=this.faces[e];if(a&&j.vertexNormals.length){c.set(0,0,0);b=0;for(f=j.normal.length;b<f;b++)c.addSelf(j.vertexNormals[b]);c.divideScalar(3)}else{b=this.vertices[j.a];f=this.vertices[j.b];o=this.vertices[j.c];c.sub(o.position,
f.centroid.addSelf(this.vertices[f.d].position);f.centroid.divideScalar(4)}}},computeFaceNormals:function(a){var b,f,e,g,j,p,c=new THREE.Vector3,k=new THREE.Vector3;e=0;for(g=this.vertices.length;e<g;e++){j=this.vertices[e];j.normal.set(0,0,0)}e=0;for(g=this.faces.length;e<g;e++){j=this.faces[e];if(a&&j.vertexNormals.length){c.set(0,0,0);b=0;for(f=j.normal.length;b<f;b++)c.addSelf(j.vertexNormals[b]);c.divideScalar(3)}else{b=this.vertices[j.a];f=this.vertices[j.b];p=this.vertices[j.c];c.sub(p.position,
f.position);k.sub(b.position,f.position);c.crossSelf(k)}c.isZero()||c.normalize();j.normal.copy(c)}},computeVertexNormals:function(){var a,b,f=[],e;a=0;for(b=this.vertices.length;a<b;a++)f[a]=new THREE.Vector3;a=0;for(b=this.faces.length;a<b;a++){e=this.faces[a];if(e instanceof THREE.Face3){f[e.a].addSelf(e.normal);f[e.b].addSelf(e.normal);f[e.c].addSelf(e.normal)}else if(e instanceof THREE.Face4){f[e.a].addSelf(e.normal);f[e.b].addSelf(e.normal);f[e.c].addSelf(e.normal);f[e.d].addSelf(e.normal)}}a=
0;for(b=this.vertices.length;a<b;a++)f[a].normalize();a=0;for(b=this.faces.length;a<b;a++){e=this.faces[a];if(e instanceof THREE.Face3){e.vertexNormals[0]=f[e.a].clone();e.vertexNormals[1]=f[e.b].clone();e.vertexNormals[2]=f[e.c].clone()}else if(e instanceof THREE.Face4){e.vertexNormals[0]=f[e.a].clone();e.vertexNormals[1]=f[e.b].clone();e.vertexNormals[2]=f[e.c].clone();e.vertexNormals[3]=f[e.d].clone()}}},computeTangents:function(){function a(s,v,W,G,S,P,H){j=s.vertices[v].position;o=s.vertices[W].position;
c=s.vertices[G].position;k=g[S];n=g[P];B=g[H];D=o.x-j.x;x=c.x-j.x;A=o.y-j.y;M=c.y-j.y;Q=o.z-j.z;O=c.z-j.z;q=n.u-k.u;L=B.u-k.u;d=n.v-k.v;h=B.v-k.v;r=1/(q*h-L*d);i.set((h*D-d*x)*r,(h*A-d*M)*r,(h*Q-d*O)*r);t.set((q*x-L*D)*r,(q*M-L*A)*r,(q*O-L*Q)*r);l[v].addSelf(i);l[W].addSelf(i);l[G].addSelf(i);m[v].addSelf(t);m[W].addSelf(t);m[G].addSelf(t)}var b,f,e,g,j,o,c,k,n,B,D,x,A,M,Q,O,q,L,d,h,r,l=[],m=[],i=new THREE.Vector3,t=new THREE.Vector3,p=new THREE.Vector3,y=new THREE.Vector3,u=new THREE.Vector3;b=0;
for(f=this.vertices.length;b<f;b++){l[b]=new THREE.Vector3;m[b]=new THREE.Vector3}b=0;for(f=this.faces.length;b<f;b++){e=this.faces[b];g=this.uvs[b];if(e instanceof THREE.Face3){a(this,e.a,e.b,e.c,0,1,2);this.vertices[e.a].normal.copy(e.vertexNormals[0]);this.vertices[e.b].normal.copy(e.vertexNormals[1]);this.vertices[e.c].normal.copy(e.vertexNormals[2])}else if(e instanceof THREE.Face4){a(this,e.a,e.b,e.c,0,1,2);a(this,e.a,e.b,e.d,0,1,3);this.vertices[e.a].normal.copy(e.vertexNormals[0]);this.vertices[e.b].normal.copy(e.vertexNormals[1]);
this.vertices[e.c].normal.copy(e.vertexNormals[2]);this.vertices[e.d].normal.copy(e.vertexNormals[3])}}b=0;for(f=this.vertices.length;b<f;b++){u.copy(this.vertices[b].normal);e=l[b];p.copy(e);p.subSelf(u.multiplyScalar(u.dot(e))).normalize();y.cross(this.vertices[b].normal,e);e=y.dot(m[b]);e=e<0?-1:1;this.vertices[b].tangent.set(p.x,p.y,p.z,e)}this.hasTangents=true},computeBoundingBox:function(){var a;if(this.vertices.length>0){this.boundingBox={x:[this.vertices[0].position.x,this.vertices[0].position.x],
0;for(b=this.vertices.length;a<b;a++)f[a].normalize();a=0;for(b=this.faces.length;a<b;a++){e=this.faces[a];if(e instanceof THREE.Face3){e.vertexNormals[0]=f[e.a].clone();e.vertexNormals[1]=f[e.b].clone();e.vertexNormals[2]=f[e.c].clone()}else if(e instanceof THREE.Face4){e.vertexNormals[0]=f[e.a].clone();e.vertexNormals[1]=f[e.b].clone();e.vertexNormals[2]=f[e.c].clone();e.vertexNormals[3]=f[e.d].clone()}}},computeTangents:function(){function a(r,v,W,G,S,P,H){j=r.vertices[v].position;p=r.vertices[W].position;
c=r.vertices[G].position;k=g[S];m=g[P];B=g[H];D=p.x-j.x;x=c.x-j.x;A=p.y-j.y;M=c.y-j.y;Q=p.z-j.z;O=c.z-j.z;s=m.u-k.u;L=B.u-k.u;d=m.v-k.v;h=B.v-k.v;q=1/(s*h-L*d);i.set((h*D-d*x)*q,(h*A-d*M)*q,(h*Q-d*O)*q);u.set((s*x-L*D)*q,(s*M-L*A)*q,(s*O-L*Q)*q);n[v].addSelf(i);n[W].addSelf(i);n[G].addSelf(i);l[v].addSelf(u);l[W].addSelf(u);l[G].addSelf(u)}var b,f,e,g,j,p,c,k,m,B,D,x,A,M,Q,O,s,L,d,h,q,n=[],l=[],i=new THREE.Vector3,u=new THREE.Vector3,o=new THREE.Vector3,y=new THREE.Vector3,t=new THREE.Vector3;b=0;
for(f=this.vertices.length;b<f;b++){n[b]=new THREE.Vector3;l[b]=new THREE.Vector3}b=0;for(f=this.faces.length;b<f;b++){e=this.faces[b];g=this.uvs[b];if(e instanceof THREE.Face3){a(this,e.a,e.b,e.c,0,1,2);this.vertices[e.a].normal.copy(e.vertexNormals[0]);this.vertices[e.b].normal.copy(e.vertexNormals[1]);this.vertices[e.c].normal.copy(e.vertexNormals[2])}else if(e instanceof THREE.Face4){a(this,e.a,e.b,e.c,0,1,2);a(this,e.a,e.b,e.d,0,1,3);this.vertices[e.a].normal.copy(e.vertexNormals[0]);this.vertices[e.b].normal.copy(e.vertexNormals[1]);
this.vertices[e.c].normal.copy(e.vertexNormals[2]);this.vertices[e.d].normal.copy(e.vertexNormals[3])}}b=0;for(f=this.vertices.length;b<f;b++){t.copy(this.vertices[b].normal);e=n[b];o.copy(e);o.subSelf(t.multiplyScalar(t.dot(e))).normalize();y.cross(this.vertices[b].normal,e);e=y.dot(l[b]);e=e<0?-1:1;this.vertices[b].tangent.set(o.x,o.y,o.z,e)}this.hasTangents=true},computeBoundingBox:function(){var a;if(this.vertices.length>0){this.boundingBox={x:[this.vertices[0].position.x,this.vertices[0].position.x],
y:[this.vertices[0].position.y,this.vertices[0].position.y],z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var b=1,f=this.vertices.length;b<f;b++){a=this.vertices[b];if(a.position.x<this.boundingBox.x[0])this.boundingBox.x[0]=a.position.x;else if(a.position.x>this.boundingBox.x[1])this.boundingBox.x[1]=a.position.x;if(a.position.y<this.boundingBox.y[0])this.boundingBox.y[0]=a.position.y;else if(a.position.y>this.boundingBox.y[1])this.boundingBox.y[1]=a.position.y;if(a.position.z<
this.boundingBox.z[0])this.boundingBox.z[0]=a.position.z;else if(a.position.z>this.boundingBox.z[1])this.boundingBox.z[1]=a.position.z}}},computeBoundingSphere:function(){for(var a=this.boundingSphere===null?0:this.boundingSphere.radius,b=0,f=this.vertices.length;b<f;b++)a=Math.max(a,this.vertices[b].position.length());this.boundingSphere={radius:a}},sortFacesByMaterial:function(){function a(B){var D=[];b=0;for(f=B.length;b<f;b++)B[b]==undefined?D.push("undefined"):D.push(B[b].toString());return D.join("_")}
var b,f,e,g,j,o,c,k,n={};e=0;for(g=this.faces.length;e<g;e++){j=this.faces[e];o=j.materials;c=a(o);if(n[c]==undefined)n[c]={hash:c,counter:0};k=n[c].hash+"_"+n[c].counter;if(this.geometryChunks[k]==undefined)this.geometryChunks[k]={faces:[],materials:o,vertices:0};j=j instanceof THREE.Face3?3:4;if(this.geometryChunks[k].vertices+j>65535){n[c].counter+=1;k=n[c].hash+"_"+n[c].counter;if(this.geometryChunks[k]==undefined)this.geometryChunks[k]={faces:[],materials:o,vertices:0}}this.geometryChunks[k].faces.push(e);
var b,f,e,g,j,p,c,k,m={};e=0;for(g=this.faces.length;e<g;e++){j=this.faces[e];p=j.materials;c=a(p);if(m[c]==undefined)m[c]={hash:c,counter:0};k=m[c].hash+"_"+m[c].counter;if(this.geometryChunks[k]==undefined)this.geometryChunks[k]={faces:[],materials:p,vertices:0};j=j instanceof THREE.Face3?3:4;if(this.geometryChunks[k].vertices+j>65535){m[c].counter+=1;k=m[c].hash+"_"+m[c].counter;if(this.geometryChunks[k]==undefined)this.geometryChunks[k]={faces:[],materials:p,vertices:0}}this.geometryChunks[k].faces.push(e);
this.geometryChunks[k].vertices+=j}},toString:function(){return"THREE.Geometry ( vertices: "+this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
THREE.Camera=function(a,b,f,e){this.fov=a;this.aspect=b;this.near=f;this.far=e;this.position=new THREE.Vector3;this.target={position:new THREE.Vector3};this.autoUpdateMatrix=true;this.projectionMatrix=null;this.matrix=new THREE.Matrix4;this.up=new THREE.Vector3(0,1,0);this.translateX=function(g){g=this.target.position.clone().subSelf(this.position).normalize().multiplyScalar(g);g.cross(g.clone(),this.up);this.position.addSelf(g);this.target.position.addSelf(g)};this.translateZ=function(g){g=this.target.position.clone().subSelf(this.position).normalize().multiplyScalar(g);
this.position.subSelf(g);this.target.position.subSelf(g)};this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.updateProjectionMatrix=function(){this.projectionMatrix=THREE.Matrix4.makePerspective(this.fov,this.aspect,this.near,this.far)};this.updateProjectionMatrix()};THREE.Camera.prototype={toString:function(){return"THREE.Camera ( "+this.position+", "+this.target.position+" )"}};THREE.Light=function(a){this.color=new THREE.Color(a)};
@@ -96,85 +96,85 @@ THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLine
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.fog=null;this.addObject=function(a){this.objects.indexOf(a)===-1&&this.objects.push(a)};this.removeObject=function(a){a=this.objects.indexOf(a);a!==-1&&this.objects.splice(a,1)};this.addLight=function(a){this.lights.indexOf(a)===-1&&this.lights.push(a)};this.removeLight=function(a){a=this.lights.indexOf(a);a!==-1&&this.lights.splice(a,1)};this.toString=function(){return"THREE.Scene ( "+this.objects+" )"}};
THREE.Fog=function(a,b,f){this.color=new THREE.Color(a);this.near=b||1;this.far=f||1E3};THREE.FogExp2=function(a,b){this.color=new THREE.Color(a);this.density=b||2.5E-4};
THREE.Projector=function(){function a(m,i){return i.z-m.z}function b(m,i){var t=0,p=1,y=m.z+m.w,u=i.z+i.w,s=-m.z+m.w,v=-i.z+i.w;if(y>=0&&u>=0&&s>=0&&v>=0)return true;else if(y<0&&u<0||s<0&&v<0)return false;else{if(y<0)t=Math.max(t,y/(y-u));else if(u<0)p=Math.min(p,y/(y-u));if(s<0)t=Math.max(t,s/(s-v));else if(v<0)p=Math.min(p,s/(s-v));if(p<t)return false;else{m.lerpSelf(i,t);i.lerpSelf(m,1-p);return true}}}var f,e,g=[],j,o,c,k=[],n,B,D=[],x,A,M=[],Q=new THREE.Vector4,O=new THREE.Vector4,q=new THREE.Matrix4,
L=new THREE.Matrix4,d=[],h=new THREE.Vector4,r=new THREE.Vector4,l;this.projectObjects=function(m,i,t){var p=[],y,u;e=0;q.multiply(i.projectionMatrix,i.matrix);d[0]=new THREE.Vector4(q.n41-q.n11,q.n42-q.n12,q.n43-q.n13,q.n44-q.n14);d[1]=new THREE.Vector4(q.n41+q.n11,q.n42+q.n12,q.n43+q.n13,q.n44+q.n14);d[2]=new THREE.Vector4(q.n41+q.n21,q.n42+q.n22,q.n43+q.n23,q.n44+q.n24);d[3]=new THREE.Vector4(q.n41-q.n21,q.n42-q.n22,q.n43-q.n23,q.n44-q.n24);d[4]=new THREE.Vector4(q.n41-q.n31,q.n42-q.n32,q.n43-
q.n33,q.n44-q.n34);d[5]=new THREE.Vector4(q.n41+q.n31,q.n42+q.n32,q.n43+q.n33,q.n44+q.n34);i=0;for(y=d.length;i<y;i++){u=d[i];u.divideScalar(Math.sqrt(u.x*u.x+u.y*u.y+u.z*u.z))}y=m.objects;m=0;for(i=y.length;m<i;m++){u=y[m];var s;if(!(s=!u.visible)){if(s=u instanceof THREE.Mesh){a:{s=void 0;for(var v=u.position,W=-u.geometry.boundingSphere.radius*Math.max(u.scale.x,Math.max(u.scale.y,u.scale.z)),G=0;G<6;G++){s=d[G].x*v.x+d[G].y*v.y+d[G].z*v.z+d[G].w;if(s<=W){s=false;break a}}s=true}s=!s}s=s}if(!s){f=
g[e]=g[e]||new THREE.RenderableObject;Q.copy(u.position);q.multiplyVector3(Q);f.object=u;f.z=Q.z;p.push(f);e++}}t&&p.sort(a);return p};this.projectScene=function(m,i,t){var p=[],y=i.near,u=i.far,s,v,W,G,S,P,H,X,K,E,F,U,T,C,N,V;c=B=A=0;i.autoUpdateMatrix&&i.updateMatrix();q.multiply(i.projectionMatrix,i.matrix);P=this.projectObjects(m,i,true);m=0;for(s=P.length;m<s;m++){H=P[m].object;if(H.visible){H.autoUpdateMatrix&&H.updateMatrix();X=H.matrix;K=H.rotationMatrix;E=H.materials;F=H.overdraw;if(H instanceof
THREE.Mesh){U=H.geometry;T=U.vertices;v=0;for(W=T.length;v<W;v++){C=T[v];C.positionWorld.copy(C.position);X.multiplyVector3(C.positionWorld);G=C.positionScreen;G.copy(C.positionWorld);q.multiplyVector4(G);G.x/=G.w;G.y/=G.w;C.__visible=G.z>y&&G.z<u}U=U.faces;v=0;for(W=U.length;v<W;v++){C=U[v];if(C instanceof THREE.Face3){G=T[C.a];S=T[C.b];N=T[C.c];if(G.__visible&&S.__visible&&N.__visible)if(H.doubleSided||H.flipSided!=(N.positionScreen.x-G.positionScreen.x)*(S.positionScreen.y-G.positionScreen.y)-
THREE.Projector=function(){function a(l,i){return i.z-l.z}function b(l,i){var u=0,o=1,y=l.z+l.w,t=i.z+i.w,r=-l.z+l.w,v=-i.z+i.w;if(y>=0&&t>=0&&r>=0&&v>=0)return true;else if(y<0&&t<0||r<0&&v<0)return false;else{if(y<0)u=Math.max(u,y/(y-t));else if(t<0)o=Math.min(o,y/(y-t));if(r<0)u=Math.max(u,r/(r-v));else if(v<0)o=Math.min(o,r/(r-v));if(o<u)return false;else{l.lerpSelf(i,u);i.lerpSelf(l,1-o);return true}}}var f,e,g=[],j,p,c,k=[],m,B,D=[],x,A,M=[],Q=new THREE.Vector4,O=new THREE.Vector4,s=new THREE.Matrix4,
L=new THREE.Matrix4,d=[],h=new THREE.Vector4,q=new THREE.Vector4,n;this.projectObjects=function(l,i,u){var o=[],y,t;e=0;s.multiply(i.projectionMatrix,i.matrix);d[0]=new THREE.Vector4(s.n41-s.n11,s.n42-s.n12,s.n43-s.n13,s.n44-s.n14);d[1]=new THREE.Vector4(s.n41+s.n11,s.n42+s.n12,s.n43+s.n13,s.n44+s.n14);d[2]=new THREE.Vector4(s.n41+s.n21,s.n42+s.n22,s.n43+s.n23,s.n44+s.n24);d[3]=new THREE.Vector4(s.n41-s.n21,s.n42-s.n22,s.n43-s.n23,s.n44-s.n24);d[4]=new THREE.Vector4(s.n41-s.n31,s.n42-s.n32,s.n43-
s.n33,s.n44-s.n34);d[5]=new THREE.Vector4(s.n41+s.n31,s.n42+s.n32,s.n43+s.n33,s.n44+s.n34);i=0;for(y=d.length;i<y;i++){t=d[i];t.divideScalar(Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z))}y=l.objects;l=0;for(i=y.length;l<i;l++){t=y[l];var r;if(!(r=!t.visible)){if(r=t instanceof THREE.Mesh){a:{r=void 0;for(var v=t.position,W=-t.geometry.boundingSphere.radius*Math.max(t.scale.x,Math.max(t.scale.y,t.scale.z)),G=0;G<6;G++){r=d[G].x*v.x+d[G].y*v.y+d[G].z*v.z+d[G].w;if(r<=W){r=false;break a}}r=true}r=!r}r=r}if(!r){f=
g[e]=g[e]||new THREE.RenderableObject;Q.copy(t.position);s.multiplyVector3(Q);f.object=t;f.z=Q.z;o.push(f);e++}}u&&o.sort(a);return o};this.projectScene=function(l,i,u){var o=[],y=i.near,t=i.far,r,v,W,G,S,P,H,X,K,E,F,U,T,C,N,V;c=B=A=0;i.autoUpdateMatrix&&i.updateMatrix();s.multiply(i.projectionMatrix,i.matrix);P=this.projectObjects(l,i,true);l=0;for(r=P.length;l<r;l++){H=P[l].object;if(H.visible){H.autoUpdateMatrix&&H.updateMatrix();X=H.matrix;K=H.rotationMatrix;E=H.materials;F=H.overdraw;if(H instanceof
THREE.Mesh){U=H.geometry;T=U.vertices;v=0;for(W=T.length;v<W;v++){C=T[v];C.positionWorld.copy(C.position);X.multiplyVector3(C.positionWorld);G=C.positionScreen;G.copy(C.positionWorld);s.multiplyVector4(G);G.x/=G.w;G.y/=G.w;C.__visible=G.z>y&&G.z<t}U=U.faces;v=0;for(W=U.length;v<W;v++){C=U[v];if(C instanceof THREE.Face3){G=T[C.a];S=T[C.b];N=T[C.c];if(G.__visible&&S.__visible&&N.__visible)if(H.doubleSided||H.flipSided!=(N.positionScreen.x-G.positionScreen.x)*(S.positionScreen.y-G.positionScreen.y)-
(N.positionScreen.y-G.positionScreen.y)*(S.positionScreen.x-G.positionScreen.x)<0){j=k[c]=k[c]||new THREE.RenderableFace3;j.v1.positionWorld.copy(G.positionWorld);j.v2.positionWorld.copy(S.positionWorld);j.v3.positionWorld.copy(N.positionWorld);j.v1.positionScreen.copy(G.positionScreen);j.v2.positionScreen.copy(S.positionScreen);j.v3.positionScreen.copy(N.positionScreen);j.normalWorld.copy(C.normal);K.multiplyVector3(j.normalWorld);j.centroidWorld.copy(C.centroid);X.multiplyVector3(j.centroidWorld);
j.centroidScreen.copy(j.centroidWorld);q.multiplyVector3(j.centroidScreen);N=C.vertexNormals;l=j.vertexNormalsWorld;G=0;for(S=N.length;G<S;G++){V=l[G]=l[G]||new THREE.Vector3;V.copy(N[G]);K.multiplyVector3(V)}j.z=j.centroidScreen.z;j.meshMaterials=E;j.faceMaterials=C.materials;j.overdraw=F;if(H.geometry.uvs[v]){j.uvs[0]=H.geometry.uvs[v][0];j.uvs[1]=H.geometry.uvs[v][1];j.uvs[2]=H.geometry.uvs[v][2]}p.push(j);c++}}else if(C instanceof THREE.Face4){G=T[C.a];S=T[C.b];N=T[C.c];V=T[C.d];if(G.__visible&&
j.centroidScreen.copy(j.centroidWorld);s.multiplyVector3(j.centroidScreen);N=C.vertexNormals;n=j.vertexNormalsWorld;G=0;for(S=N.length;G<S;G++){V=n[G]=n[G]||new THREE.Vector3;V.copy(N[G]);K.multiplyVector3(V)}j.z=j.centroidScreen.z;j.meshMaterials=E;j.faceMaterials=C.materials;j.overdraw=F;if(H.geometry.uvs[v]){j.uvs[0]=H.geometry.uvs[v][0];j.uvs[1]=H.geometry.uvs[v][1];j.uvs[2]=H.geometry.uvs[v][2]}o.push(j);c++}}else if(C instanceof THREE.Face4){G=T[C.a];S=T[C.b];N=T[C.c];V=T[C.d];if(G.__visible&&
S.__visible&&N.__visible&&V.__visible)if(H.doubleSided||H.flipSided!=((V.positionScreen.x-G.positionScreen.x)*(S.positionScreen.y-G.positionScreen.y)-(V.positionScreen.y-G.positionScreen.y)*(S.positionScreen.x-G.positionScreen.x)<0||(S.positionScreen.x-N.positionScreen.x)*(V.positionScreen.y-N.positionScreen.y)-(S.positionScreen.y-N.positionScreen.y)*(V.positionScreen.x-N.positionScreen.x)<0)){j=k[c]=k[c]||new THREE.RenderableFace3;j.v1.positionWorld.copy(G.positionWorld);j.v2.positionWorld.copy(S.positionWorld);
j.v3.positionWorld.copy(V.positionWorld);j.v1.positionScreen.copy(G.positionScreen);j.v2.positionScreen.copy(S.positionScreen);j.v3.positionScreen.copy(V.positionScreen);j.normalWorld.copy(C.normal);K.multiplyVector3(j.normalWorld);j.centroidWorld.copy(C.centroid);X.multiplyVector3(j.centroidWorld);j.centroidScreen.copy(j.centroidWorld);q.multiplyVector3(j.centroidScreen);j.z=j.centroidScreen.z;j.meshMaterials=E;j.faceMaterials=C.materials;j.overdraw=F;if(H.geometry.uvs[v]){j.uvs[0]=H.geometry.uvs[v][0];
j.uvs[1]=H.geometry.uvs[v][1];j.uvs[2]=H.geometry.uvs[v][3]}p.push(j);c++;o=k[c]=k[c]||new THREE.RenderableFace3;o.v1.positionWorld.copy(S.positionWorld);o.v2.positionWorld.copy(N.positionWorld);o.v3.positionWorld.copy(V.positionWorld);o.v1.positionScreen.copy(S.positionScreen);o.v2.positionScreen.copy(N.positionScreen);o.v3.positionScreen.copy(V.positionScreen);o.normalWorld.copy(j.normalWorld);o.centroidWorld.copy(j.centroidWorld);o.centroidScreen.copy(j.centroidScreen);o.z=o.centroidScreen.z;o.meshMaterials=
E;o.faceMaterials=C.materials;o.overdraw=F;if(H.geometry.uvs[v]){o.uvs[0]=H.geometry.uvs[v][1];o.uvs[1]=H.geometry.uvs[v][2];o.uvs[2]=H.geometry.uvs[v][3]}p.push(o);c++}}}}else if(H instanceof THREE.Line){L.multiply(q,X);T=H.geometry.vertices;C=T[0];C.positionScreen.copy(C.position);L.multiplyVector4(C.positionScreen);v=1;for(W=T.length;v<W;v++){G=T[v];G.positionScreen.copy(G.position);L.multiplyVector4(G.positionScreen);S=T[v-1];h.copy(G.positionScreen);r.copy(S.positionScreen);if(b(h,r)){h.multiplyScalar(1/
h.w);r.multiplyScalar(1/r.w);n=D[B]=D[B]||new THREE.RenderableLine;n.v1.positionScreen.copy(h);n.v2.positionScreen.copy(r);n.z=Math.max(h.z,r.z);n.materials=H.materials;p.push(n);B++}}}else if(H instanceof THREE.Particle){O.set(H.position.x,H.position.y,H.position.z,1);q.multiplyVector4(O);O.z/=O.w;if(O.z>0&&O.z<1){x=M[A]=M[A]||new THREE.RenderableParticle;x.x=O.x/O.w;x.y=O.y/O.w;x.z=O.z;x.rotation=H.rotation.z;x.scale.x=H.scale.x*Math.abs(x.x-(O.x+i.projectionMatrix.n11)/(O.w+i.projectionMatrix.n14));
x.scale.y=H.scale.y*Math.abs(x.y-(O.y+i.projectionMatrix.n22)/(O.w+i.projectionMatrix.n24));x.materials=H.materials;p.push(x);A++}}}}t&&p.sort(a);return p};this.unprojectVector=function(m,i){var t=new THREE.Matrix4;t.multiply(THREE.Matrix4.makeInvert(i.matrix),THREE.Matrix4.makeInvert(i.projectionMatrix));t.multiplyVector3(m);return m}};
THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,f,e,g,j;this.domElement=document.createElement("div");this.setSize=function(o,c){f=o;e=c;g=f/2;j=e/2};this.render=function(o,c){var k,n,B,D,x,A,M,Q;a=b.projectScene(o,c);k=0;for(n=a.length;k<n;k++){x=a[k];if(x instanceof THREE.RenderableParticle){M=x.x*g+g;Q=x.y*j+j;B=0;for(D=x.material.length;B<D;B++){A=x.material[B];if(A instanceof THREE.ParticleDOMMaterial){A=A.domElement;A.style.left=M+"px";A.style.top=Q+"px"}}}}}};
THREE.CanvasRenderer=function(){function a(ba){if(x!=ba)n.globalAlpha=x=ba}function b(ba){if(A!=ba){switch(ba){case THREE.NormalBlending:n.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:n.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:n.globalCompositeOperation="darker"}A=ba}}var f=null,e=new THREE.Projector,g=document.createElement("canvas"),j,o,c,k,n=g.getContext("2d"),B=null,D=null,x=1,A=0,M=null,Q=null,O=1,q,L,d,h,r,l,m,i,t,p=new THREE.Color,
y=new THREE.Color,u=new THREE.Color,s=new THREE.Color,v=new THREE.Color,W,G,S,P,H,X,K,E,F,U=new THREE.Rectangle,T=new THREE.Rectangle,C=new THREE.Rectangle,N=false,V=new THREE.Color,ea=new THREE.Color,ma=new THREE.Color,na=new THREE.Color,La=Math.PI*2,Z=new THREE.Vector3,ra,sa,Ca,fa,ta,xa,pa=16;ra=document.createElement("canvas");ra.width=ra.height=2;sa=ra.getContext("2d");sa.fillStyle="rgba(0,0,0,1)";sa.fillRect(0,0,2,2);Ca=sa.getImageData(0,0,2,2);fa=Ca.data;ta=document.createElement("canvas");
ta.width=ta.height=pa;xa=ta.getContext("2d");xa.translate(-pa/2,-pa/2);xa.scale(pa,pa);pa--;this.domElement=g;this.sortElements=this.sortObjects=this.autoClear=true;this.setSize=function(ba,la){j=ba;o=la;c=j/2;k=o/2;g.width=j;g.height=o;U.set(-c,-k,c,k)};this.setClearColor=function(ba,la){B=ba!==null?new THREE.Color(ba):null;D=la;T.set(-c,-k,c,k);n.setTransform(1,0,0,-1,c,k);this.clear()};this.clear=function(){if(!T.isEmpty()){T.inflate(1);T.minSelf(U);if(B!==null){b(THREE.NormalBlending);a(1);n.fillStyle=
"rgba("+Math.floor(B.r*255)+","+Math.floor(B.g*255)+","+Math.floor(B.b*255)+","+D+")";n.fillRect(T.getX(),T.getY(),T.getWidth(),T.getHeight())}else n.clearRect(T.getX(),T.getY(),T.getWidth(),T.getHeight());T.empty()}};this.render=function(ba,la){function Ma(w){var R,J,z,I=w.lights;ea.setRGB(0,0,0);ma.setRGB(0,0,0);na.setRGB(0,0,0);w=0;for(R=I.length;w<R;w++){J=I[w];z=J.color;if(J instanceof THREE.AmbientLight){ea.r+=z.r;ea.g+=z.g;ea.b+=z.b}else if(J instanceof THREE.DirectionalLight){ma.r+=z.r;ma.g+=
j.v3.positionWorld.copy(V.positionWorld);j.v1.positionScreen.copy(G.positionScreen);j.v2.positionScreen.copy(S.positionScreen);j.v3.positionScreen.copy(V.positionScreen);j.normalWorld.copy(C.normal);K.multiplyVector3(j.normalWorld);j.centroidWorld.copy(C.centroid);X.multiplyVector3(j.centroidWorld);j.centroidScreen.copy(j.centroidWorld);s.multiplyVector3(j.centroidScreen);j.z=j.centroidScreen.z;j.meshMaterials=E;j.faceMaterials=C.materials;j.overdraw=F;if(H.geometry.uvs[v]){j.uvs[0]=H.geometry.uvs[v][0];
j.uvs[1]=H.geometry.uvs[v][1];j.uvs[2]=H.geometry.uvs[v][3]}o.push(j);c++;p=k[c]=k[c]||new THREE.RenderableFace3;p.v1.positionWorld.copy(S.positionWorld);p.v2.positionWorld.copy(N.positionWorld);p.v3.positionWorld.copy(V.positionWorld);p.v1.positionScreen.copy(S.positionScreen);p.v2.positionScreen.copy(N.positionScreen);p.v3.positionScreen.copy(V.positionScreen);p.normalWorld.copy(j.normalWorld);p.centroidWorld.copy(j.centroidWorld);p.centroidScreen.copy(j.centroidScreen);p.z=p.centroidScreen.z;p.meshMaterials=
E;p.faceMaterials=C.materials;p.overdraw=F;if(H.geometry.uvs[v]){p.uvs[0]=H.geometry.uvs[v][1];p.uvs[1]=H.geometry.uvs[v][2];p.uvs[2]=H.geometry.uvs[v][3]}o.push(p);c++}}}}else if(H instanceof THREE.Line){L.multiply(s,X);T=H.geometry.vertices;C=T[0];C.positionScreen.copy(C.position);L.multiplyVector4(C.positionScreen);v=1;for(W=T.length;v<W;v++){G=T[v];G.positionScreen.copy(G.position);L.multiplyVector4(G.positionScreen);S=T[v-1];h.copy(G.positionScreen);q.copy(S.positionScreen);if(b(h,q)){h.multiplyScalar(1/
h.w);q.multiplyScalar(1/q.w);m=D[B]=D[B]||new THREE.RenderableLine;m.v1.positionScreen.copy(h);m.v2.positionScreen.copy(q);m.z=Math.max(h.z,q.z);m.materials=H.materials;o.push(m);B++}}}else if(H instanceof THREE.Particle){O.set(H.position.x,H.position.y,H.position.z,1);s.multiplyVector4(O);O.z/=O.w;if(O.z>0&&O.z<1){x=M[A]=M[A]||new THREE.RenderableParticle;x.x=O.x/O.w;x.y=O.y/O.w;x.z=O.z;x.rotation=H.rotation.z;x.scale.x=H.scale.x*Math.abs(x.x-(O.x+i.projectionMatrix.n11)/(O.w+i.projectionMatrix.n14));
x.scale.y=H.scale.y*Math.abs(x.y-(O.y+i.projectionMatrix.n22)/(O.w+i.projectionMatrix.n24));x.materials=H.materials;o.push(x);A++}}}}u&&o.sort(a);return o};this.unprojectVector=function(l,i){var u=new THREE.Matrix4;u.multiply(THREE.Matrix4.makeInvert(i.matrix),THREE.Matrix4.makeInvert(i.projectionMatrix));u.multiplyVector3(l);return l}};
THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,f,e,g,j;this.domElement=document.createElement("div");this.setSize=function(p,c){f=p;e=c;g=f/2;j=e/2};this.render=function(p,c){var k,m,B,D,x,A,M,Q;a=b.projectScene(p,c);k=0;for(m=a.length;k<m;k++){x=a[k];if(x instanceof THREE.RenderableParticle){M=x.x*g+g;Q=x.y*j+j;B=0;for(D=x.material.length;B<D;B++){A=x.material[B];if(A instanceof THREE.ParticleDOMMaterial){A=A.domElement;A.style.left=M+"px";A.style.top=Q+"px"}}}}}};
THREE.CanvasRenderer=function(){function a(ba){if(x!=ba)m.globalAlpha=x=ba}function b(ba){if(A!=ba){switch(ba){case THREE.NormalBlending:m.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:m.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:m.globalCompositeOperation="darker"}A=ba}}var f=null,e=new THREE.Projector,g=document.createElement("canvas"),j,p,c,k,m=g.getContext("2d"),B=null,D=null,x=1,A=0,M=null,Q=null,O=1,s,L,d,h,q,n,l,i,u,o=new THREE.Color,
y=new THREE.Color,t=new THREE.Color,r=new THREE.Color,v=new THREE.Color,W,G,S,P,H,X,K,E,F,U=new THREE.Rectangle,T=new THREE.Rectangle,C=new THREE.Rectangle,N=false,V=new THREE.Color,ea=new THREE.Color,ma=new THREE.Color,na=new THREE.Color,La=Math.PI*2,Z=new THREE.Vector3,ra,sa,Ca,fa,ta,xa,pa=16;ra=document.createElement("canvas");ra.width=ra.height=2;sa=ra.getContext("2d");sa.fillStyle="rgba(0,0,0,1)";sa.fillRect(0,0,2,2);Ca=sa.getImageData(0,0,2,2);fa=Ca.data;ta=document.createElement("canvas");
ta.width=ta.height=pa;xa=ta.getContext("2d");xa.translate(-pa/2,-pa/2);xa.scale(pa,pa);pa--;this.domElement=g;this.sortElements=this.sortObjects=this.autoClear=true;this.setSize=function(ba,la){j=ba;p=la;c=j/2;k=p/2;g.width=j;g.height=p;U.set(-c,-k,c,k)};this.setClearColor=function(ba,la){B=ba!==null?new THREE.Color(ba):null;D=la;T.set(-c,-k,c,k);m.setTransform(1,0,0,-1,c,k);this.clear()};this.clear=function(){if(!T.isEmpty()){T.inflate(1);T.minSelf(U);if(B!==null){b(THREE.NormalBlending);a(1);m.fillStyle=
"rgba("+Math.floor(B.r*255)+","+Math.floor(B.g*255)+","+Math.floor(B.b*255)+","+D+")";m.fillRect(T.getX(),T.getY(),T.getWidth(),T.getHeight())}else m.clearRect(T.getX(),T.getY(),T.getWidth(),T.getHeight());T.empty()}};this.render=function(ba,la){function Ma(w){var R,J,z,I=w.lights;ea.setRGB(0,0,0);ma.setRGB(0,0,0);na.setRGB(0,0,0);w=0;for(R=I.length;w<R;w++){J=I[w];z=J.color;if(J instanceof THREE.AmbientLight){ea.r+=z.r;ea.g+=z.g;ea.b+=z.b}else if(J instanceof THREE.DirectionalLight){ma.r+=z.r;ma.g+=
z.g;ma.b+=z.b}else if(J instanceof THREE.PointLight){na.r+=z.r;na.g+=z.g;na.b+=z.b}}}function ya(w,R,J,z){var I,Y,aa,ca,da=w.lights;w=0;for(I=da.length;w<I;w++){Y=da[w];aa=Y.color;ca=Y.intensity;if(Y instanceof THREE.DirectionalLight){Y=J.dot(Y.position)*ca;if(Y>0){z.r+=aa.r*Y;z.g+=aa.g*Y;z.b+=aa.b*Y}}else if(Y instanceof THREE.PointLight){Z.sub(Y.position,R);Z.normalize();Y=J.dot(Z)*ca;if(Y>0){z.r+=aa.r*Y;z.g+=aa.g*Y;z.b+=aa.b*Y}}}}function Na(w,R,J){if(J.opacity!=0){a(J.opacity);b(J.blending);var z,
I,Y,aa,ca,da;if(J instanceof THREE.ParticleBasicMaterial){if(J.map){aa=J.map;ca=aa.width>>1;da=aa.height>>1;I=R.scale.x*c;Y=R.scale.y*k;J=I*ca;z=Y*da;C.set(w.x-J,w.y-z,w.x+J,w.y+z);if(U.instersects(C)){n.save();n.translate(w.x,w.y);n.rotate(-R.rotation);n.scale(I,-Y);n.translate(-ca,-da);n.drawImage(aa,0,0);n.restore()}}}else if(J instanceof THREE.ParticleCircleMaterial){if(N){V.r=ea.r+ma.r+na.r;V.g=ea.g+ma.g+na.g;V.b=ea.b+ma.b+na.b;p.r=J.color.r*V.r;p.g=J.color.g*V.g;p.b=J.color.b*V.b;p.updateStyleString()}else p.__styleString=
J.color.__styleString;J=R.scale.x*c;z=R.scale.y*k;C.set(w.x-J,w.y-z,w.x+J,w.y+z);if(U.instersects(C)){I=p.__styleString;if(Q!=I)n.fillStyle=Q=I;n.save();n.translate(w.x,w.y);n.rotate(-R.rotation);n.scale(J,z);n.beginPath();n.arc(0,0,1,0,La,true);n.closePath();n.fill();n.restore()}}}}function Oa(w,R,J,z){if(z.opacity!=0){a(z.opacity);b(z.blending);n.beginPath();n.moveTo(w.positionScreen.x,w.positionScreen.y);n.lineTo(R.positionScreen.x,R.positionScreen.y);n.closePath();if(z instanceof THREE.LineBasicMaterial){p.__styleString=
z.color.__styleString;w=z.linewidth;if(O!=w)n.lineWidth=O=w;w=p.__styleString;if(M!=w)n.strokeStyle=M=w;n.stroke();C.inflate(z.linewidth*2)}}}function Ha(w,R,J,z,I,Y){if(I.opacity!=0){a(I.opacity);b(I.blending);h=w.positionScreen.x;r=w.positionScreen.y;l=R.positionScreen.x;m=R.positionScreen.y;i=J.positionScreen.x;t=J.positionScreen.y;n.beginPath();n.moveTo(h,r);n.lineTo(l,m);n.lineTo(i,t);n.lineTo(h,r);n.closePath();if(I instanceof THREE.MeshBasicMaterial)if(I.map)I.map.image.loaded&&I.map.mapping instanceof
THREE.UVMapping&&ua(h,r,l,m,i,t,I.map.image,z.uvs[0].u,z.uvs[0].v,z.uvs[1].u,z.uvs[1].v,z.uvs[2].u,z.uvs[2].v);else if(I.env_map){if(I.env_map.image.loaded)if(I.env_map.mapping instanceof THREE.SphericalReflectionMapping){w=la.matrix;Z.copy(z.vertexNormalsWorld[0]);P=(Z.x*w.n11+Z.y*w.n12+Z.z*w.n13)*0.5+0.5;H=-(Z.x*w.n21+Z.y*w.n22+Z.z*w.n23)*0.5+0.5;Z.copy(z.vertexNormalsWorld[1]);X=(Z.x*w.n11+Z.y*w.n12+Z.z*w.n13)*0.5+0.5;K=-(Z.x*w.n21+Z.y*w.n22+Z.z*w.n23)*0.5+0.5;Z.copy(z.vertexNormalsWorld[2]);E=
(Z.x*w.n11+Z.y*w.n12+Z.z*w.n13)*0.5+0.5;F=-(Z.x*w.n21+Z.y*w.n22+Z.z*w.n23)*0.5+0.5;ua(h,r,l,m,i,t,I.env_map.image,P,H,X,K,E,F)}}else I.wireframe?za(I.color.__styleString,I.wireframe_linewidth):Aa(I.color.__styleString);else if(I instanceof THREE.MeshLambertMaterial){if(I.map&&!I.wireframe){I.map.mapping instanceof THREE.UVMapping&&ua(h,r,l,m,i,t,I.map.image,z.uvs[0].u,z.uvs[0].v,z.uvs[1].u,z.uvs[1].v,z.uvs[2].u,z.uvs[2].v);b(THREE.SubtractiveBlending)}if(N)if(!I.wireframe&&I.shading==THREE.SmoothShading&&
z.vertexNormalsWorld.length==3){y.r=u.r=s.r=ea.r;y.g=u.g=s.g=ea.g;y.b=u.b=s.b=ea.b;ya(Y,z.v1.positionWorld,z.vertexNormalsWorld[0],y);ya(Y,z.v2.positionWorld,z.vertexNormalsWorld[1],u);ya(Y,z.v3.positionWorld,z.vertexNormalsWorld[2],s);v.r=(u.r+s.r)*0.5;v.g=(u.g+s.g)*0.5;v.b=(u.b+s.b)*0.5;S=Ia(y,u,s,v);ua(h,r,l,m,i,t,S,0,0,1,0,0,1)}else{V.r=ea.r;V.g=ea.g;V.b=ea.b;ya(Y,z.centroidWorld,z.normalWorld,V);p.r=I.color.r*V.r;p.g=I.color.g*V.g;p.b=I.color.b*V.b;p.updateStyleString();I.wireframe?za(p.__styleString,
I.wireframe_linewidth):Aa(p.__styleString)}else I.wireframe?za(I.color.__styleString,I.wireframe_linewidth):Aa(I.color.__styleString)}else if(I instanceof THREE.MeshDepthMaterial){W=la.near;G=la.far;y.r=y.g=y.b=1-Da(w.positionScreen.z,W,G);u.r=u.g=u.b=1-Da(R.positionScreen.z,W,G);s.r=s.g=s.b=1-Da(J.positionScreen.z,W,G);v.r=(u.r+s.r)*0.5;v.g=(u.g+s.g)*0.5;v.b=(u.b+s.b)*0.5;S=Ia(y,u,s,v);ua(h,r,l,m,i,t,S,0,0,1,0,0,1)}else if(I instanceof THREE.MeshNormalMaterial){p.r=Ea(z.normalWorld.x);p.g=Ea(z.normalWorld.y);
p.b=Ea(z.normalWorld.z);p.updateStyleString();I.wireframe?za(p.__styleString,I.wireframe_linewidth):Aa(p.__styleString)}}}function za(w,R){if(M!=w)n.strokeStyle=M=w;if(O!=R)n.lineWidth=O=R;n.stroke();C.inflate(R*2)}function Aa(w){if(Q!=w)n.fillStyle=Q=w;n.fill()}function ua(w,R,J,z,I,Y,aa,ca,da,ia,ga,ja,va){var oa,ka;oa=aa.width-1;ka=aa.height-1;ca*=oa;da*=ka;ia*=oa;ga*=ka;ja*=oa;va*=ka;J-=w;z-=R;I-=w;Y-=R;ia-=ca;ga-=da;ja-=ca;va-=da;ka=1/(ia*va-ja*ga);oa=(va*J-ga*I)*ka;ga=(va*z-ga*Y)*ka;J=(ia*I-
ja*J)*ka;z=(ia*Y-ja*z)*ka;w=w-oa*ca-J*da;R=R-ga*ca-z*da;n.save();n.transform(oa,ga,J,z,w,R);n.clip();n.drawImage(aa,0,0);n.restore()}function Ia(w,R,J,z){var I=~~(w.r*255),Y=~~(w.g*255);w=~~(w.b*255);var aa=~~(R.r*255),ca=~~(R.g*255);R=~~(R.b*255);var da=~~(J.r*255),ia=~~(J.g*255);J=~~(J.b*255);var ga=~~(z.r*255),ja=~~(z.g*255);z=~~(z.b*255);fa[0]=I<0?0:I>255?255:I;fa[1]=Y<0?0:Y>255?255:Y;fa[2]=w<0?0:w>255?255:w;fa[4]=aa<0?0:aa>255?255:aa;fa[5]=ca<0?0:ca>255?255:ca;fa[6]=R<0?0:R>255?255:R;fa[8]=da<
0?0:da>255?255:da;fa[9]=ia<0?0:ia>255?255:ia;fa[10]=J<0?0:J>255?255:J;fa[12]=ga<0?0:ga>255?255:ga;fa[13]=ja<0?0:ja>255?255:ja;fa[14]=z<0?0:z>255?255:z;sa.putImageData(Ca,0,0);xa.drawImage(ra,0,0);return ta}function Da(w,R,J){w=(w-R)/(J-R);return w*w*(3-2*w)}function Ea(w){w=(w+1)*0.5;return w<0?0:w>1?1:w}function Fa(w,R){var J=R.x-w.x,z=R.y-w.y,I=1/Math.sqrt(J*J+z*z);J*=I;z*=I;R.x+=J;R.y+=z;w.x-=J;w.y-=z}var Ba,Ja,$,ha,qa,Ga,Ka,wa;n.setTransform(1,0,0,-1,c,k);this.autoClear&&this.clear();f=e.projectScene(ba,
la,this.sortElements);(N=ba.lights.length>0)&&Ma(ba);Ba=0;for(Ja=f.length;Ba<Ja;Ba++){$=f[Ba];C.empty();if($ instanceof THREE.RenderableParticle){q=$;q.x*=c;q.y*=k;ha=0;for(qa=$.materials.length;ha<qa;ha++)Na(q,$,$.materials[ha],ba)}else if($ instanceof THREE.RenderableLine){q=$.v1;L=$.v2;q.positionScreen.x*=c;q.positionScreen.y*=k;L.positionScreen.x*=c;L.positionScreen.y*=k;C.addPoint(q.positionScreen.x,q.positionScreen.y);C.addPoint(L.positionScreen.x,L.positionScreen.y);if(U.instersects(C)){ha=
0;for(qa=$.materials.length;ha<qa;)Oa(q,L,$,$.materials[ha++],ba)}}else if($ instanceof THREE.RenderableFace3){q=$.v1;L=$.v2;d=$.v3;q.positionScreen.x*=c;q.positionScreen.y*=k;L.positionScreen.x*=c;L.positionScreen.y*=k;d.positionScreen.x*=c;d.positionScreen.y*=k;if($.overdraw){Fa(q.positionScreen,L.positionScreen);Fa(L.positionScreen,d.positionScreen);Fa(d.positionScreen,q.positionScreen)}C.add3Points(q.positionScreen.x,q.positionScreen.y,L.positionScreen.x,L.positionScreen.y,d.positionScreen.x,
d.positionScreen.y);if(U.instersects(C)){ha=0;for(qa=$.meshMaterials.length;ha<qa;){wa=$.meshMaterials[ha++];if(wa instanceof THREE.MeshFaceMaterial){Ga=0;for(Ka=$.faceMaterials.length;Ga<Ka;)(wa=$.faceMaterials[Ga++])&&Ha(q,L,d,$,wa,ba)}else Ha(q,L,d,$,wa,ba)}}}T.addRectangle(C)}n.setTransform(1,0,0,1,0,0)}};
THREE.SVGRenderer=function(){function a(P,H,X){var K,E,F,U;K=0;for(E=P.lights.length;K<E;K++){F=P.lights[K];if(F instanceof THREE.DirectionalLight){U=H.normalWorld.dot(F.position)*F.intensity;if(U>0){X.r+=F.color.r*U;X.g+=F.color.g*U;X.b+=F.color.b*U}}else if(F instanceof THREE.PointLight){t.sub(F.position,H.centroidWorld);t.normalize();U=H.normalWorld.dot(t)*F.intensity;if(U>0){X.r+=F.color.r*U;X.g+=F.color.g*U;X.b+=F.color.b*U}}}}function b(P,H,X,K,E,F){s=e(v++);s.setAttribute("d","M "+P.positionScreen.x+
" "+P.positionScreen.y+" L "+H.positionScreen.x+" "+H.positionScreen.y+" L "+X.positionScreen.x+","+X.positionScreen.y+"z");if(E instanceof THREE.MeshBasicMaterial)d.__styleString=E.color.__styleString;else if(E instanceof THREE.MeshLambertMaterial)if(L){h.r=r.r;h.g=r.g;h.b=r.b;a(F,K,h);d.r=E.color.r*h.r;d.g=E.color.g*h.g;d.b=E.color.b*h.b;d.updateStyleString()}else d.__styleString=E.color.__styleString;else if(E instanceof THREE.MeshDepthMaterial){i=1-E.__2near/(E.__farPlusNear-K.z*E.__farMinusNear);
d.setRGB(i,i,i)}else E instanceof THREE.MeshNormalMaterial&&d.setRGB(g(K.normalWorld.x),g(K.normalWorld.y),g(K.normalWorld.z));E.wireframe?s.setAttribute("style","fill: none; stroke: "+d.__styleString+"; stroke-width: "+E.wireframe_linewidth+"; stroke-opacity: "+E.opacity+"; stroke-linecap: "+E.wireframe_linecap+"; stroke-linejoin: "+E.wireframe_linejoin):s.setAttribute("style","fill: "+d.__styleString+"; fill-opacity: "+E.opacity);c.appendChild(s)}function f(P,H,X,K,E,F,U){s=e(v++);s.setAttribute("d",
"M "+P.positionScreen.x+" "+P.positionScreen.y+" L "+H.positionScreen.x+" "+H.positionScreen.y+" L "+X.positionScreen.x+","+X.positionScreen.y+" L "+K.positionScreen.x+","+K.positionScreen.y+"z");if(F instanceof THREE.MeshBasicMaterial)d.__styleString=F.color.__styleString;else if(F instanceof THREE.MeshLambertMaterial)if(L){h.r=r.r;h.g=r.g;h.b=r.b;a(U,E,h);d.r=F.color.r*h.r;d.g=F.color.g*h.g;d.b=F.color.b*h.b;d.updateStyleString()}else d.__styleString=F.color.__styleString;else if(F instanceof THREE.MeshDepthMaterial){i=
1-F.__2near/(F.__farPlusNear-E.z*F.__farMinusNear);d.setRGB(i,i,i)}else F instanceof THREE.MeshNormalMaterial&&d.setRGB(g(E.normalWorld.x),g(E.normalWorld.y),g(E.normalWorld.z));F.wireframe?s.setAttribute("style","fill: none; stroke: "+d.__styleString+"; stroke-width: "+F.wireframe_linewidth+"; stroke-opacity: "+F.opacity+"; stroke-linecap: "+F.wireframe_linecap+"; stroke-linejoin: "+F.wireframe_linejoin):s.setAttribute("style","fill: "+d.__styleString+"; fill-opacity: "+F.opacity);c.appendChild(s)}
function e(P){if(p[P]==null){p[P]=document.createElementNS("http://www.w3.org/2000/svg","path");S==0&&p[P].setAttribute("shape-rendering","crispEdges");return p[P]}return p[P]}function g(P){return P<0?Math.min((1+P)*0.5,0.5):0.5+Math.min(P*0.5,0.5)}var j=null,o=new THREE.Projector,c=document.createElementNS("http://www.w3.org/2000/svg","svg"),k,n,B,D,x,A,M,Q,O=new THREE.Rectangle,q=new THREE.Rectangle,L=false,d=new THREE.Color(16777215),h=new THREE.Color(16777215),r=new THREE.Color(0),l=new THREE.Color(0),
m=new THREE.Color(0),i,t=new THREE.Vector3,p=[],y=[],u=[],s,v,W,G,S=1;this.domElement=c;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(P){switch(P){case "high":S=1;break;case "low":S=0}};this.setSize=function(P,H){k=P;n=H;B=k/2;D=n/2;c.setAttribute("viewBox",-B+" "+-D+" "+k+" "+n);c.setAttribute("width",k);c.setAttribute("height",n);O.set(-B,-D,B,D)};this.clear=function(){for(;c.childNodes.length>0;)c.removeChild(c.childNodes[0])};this.render=function(P,H){var X,K,
E,F,U,T,C,N;this.autoClear&&this.clear();j=o.projectScene(P,H,this.sortElements);G=W=v=0;if(L=P.lights.length>0){C=P.lights;r.setRGB(0,0,0);l.setRGB(0,0,0);m.setRGB(0,0,0);X=0;for(K=C.length;X<K;X++){E=C[X];F=E.color;if(E instanceof THREE.AmbientLight){r.r+=F.r;r.g+=F.g;r.b+=F.b}else if(E instanceof THREE.DirectionalLight){l.r+=F.r;l.g+=F.g;l.b+=F.b}else if(E instanceof THREE.PointLight){m.r+=F.r;m.g+=F.g;m.b+=F.b}}}X=0;for(K=j.length;X<K;X++){C=j[X];q.empty();if(C instanceof THREE.RenderableParticle){x=
C;x.x*=B;x.y*=-D;E=0;for(F=C.materials.length;E<F;E++)if(N=C.materials[E]){U=x;T=C;N=N;var V=W++;if(y[V]==null){y[V]=document.createElementNS("http://www.w3.org/2000/svg","circle");S==0&&y[V].setAttribute("shape-rendering","crispEdges")}s=y[V];s.setAttribute("cx",U.x);s.setAttribute("cy",U.y);s.setAttribute("r",T.scale.x*B);if(N instanceof THREE.ParticleCircleMaterial){if(L){h.r=r.r+l.r+m.r;h.g=r.g+l.g+m.g;h.b=r.b+l.b+m.b;d.r=N.color.r*h.r;d.g=N.color.g*h.g;d.b=N.color.b*h.b;d.updateStyleString()}else d=
N.color;s.setAttribute("style","fill: "+d.__styleString)}c.appendChild(s)}}else if(C instanceof THREE.RenderableLine){x=C.v1;A=C.v2;x.positionScreen.x*=B;x.positionScreen.y*=-D;A.positionScreen.x*=B;A.positionScreen.y*=-D;q.addPoint(x.positionScreen.x,x.positionScreen.y);q.addPoint(A.positionScreen.x,A.positionScreen.y);if(O.instersects(q)){E=0;for(F=C.materials.length;E<F;)if(N=C.materials[E++]){U=x;T=A;N=N;V=G++;if(u[V]==null){u[V]=document.createElementNS("http://www.w3.org/2000/svg","line");S==
0&&u[V].setAttribute("shape-rendering","crispEdges")}s=u[V];s.setAttribute("x1",U.positionScreen.x);s.setAttribute("y1",U.positionScreen.y);s.setAttribute("x2",T.positionScreen.x);s.setAttribute("y2",T.positionScreen.y);if(N instanceof THREE.LineBasicMaterial){d.__styleString=N.color.__styleString;s.setAttribute("style","fill: none; stroke: "+d.__styleString+"; stroke-width: "+N.linewidth+"; stroke-opacity: "+N.opacity+"; stroke-linecap: "+N.linecap+"; stroke-linejoin: "+N.linejoin);c.appendChild(s)}}}}else if(C instanceof
THREE.RenderableFace3){x=C.v1;A=C.v2;M=C.v3;x.positionScreen.x*=B;x.positionScreen.y*=-D;A.positionScreen.x*=B;A.positionScreen.y*=-D;M.positionScreen.x*=B;M.positionScreen.y*=-D;q.addPoint(x.positionScreen.x,x.positionScreen.y);q.addPoint(A.positionScreen.x,A.positionScreen.y);q.addPoint(M.positionScreen.x,M.positionScreen.y);if(O.instersects(q)){E=0;for(F=C.meshMaterials.length;E<F;){N=C.meshMaterials[E++];if(N instanceof THREE.MeshFaceMaterial){U=0;for(T=C.faceMaterials.length;U<T;)(N=C.faceMaterials[U++])&&
b(x,A,M,C,N,P)}else N&&b(x,A,M,C,N,P)}}}else if(C instanceof THREE.RenderableFace4){x=C.v1;A=C.v2;M=C.v3;Q=C.v4;x.positionScreen.x*=B;x.positionScreen.y*=-D;A.positionScreen.x*=B;A.positionScreen.y*=-D;M.positionScreen.x*=B;M.positionScreen.y*=-D;Q.positionScreen.x*=B;Q.positionScreen.y*=-D;q.addPoint(x.positionScreen.x,x.positionScreen.y);q.addPoint(A.positionScreen.x,A.positionScreen.y);q.addPoint(M.positionScreen.x,M.positionScreen.y);q.addPoint(Q.positionScreen.x,Q.positionScreen.y);if(O.instersects(q)){E=
I,Y,aa,ca,da;if(J instanceof THREE.ParticleBasicMaterial){if(J.map){aa=J.map;ca=aa.width>>1;da=aa.height>>1;I=R.scale.x*c;Y=R.scale.y*k;J=I*ca;z=Y*da;C.set(w.x-J,w.y-z,w.x+J,w.y+z);if(U.instersects(C)){m.save();m.translate(w.x,w.y);m.rotate(-R.rotation);m.scale(I,-Y);m.translate(-ca,-da);m.drawImage(aa,0,0);m.restore()}}}else if(J instanceof THREE.ParticleCircleMaterial){if(N){V.r=ea.r+ma.r+na.r;V.g=ea.g+ma.g+na.g;V.b=ea.b+ma.b+na.b;o.r=J.color.r*V.r;o.g=J.color.g*V.g;o.b=J.color.b*V.b;o.updateStyleString()}else o.__styleString=
J.color.__styleString;J=R.scale.x*c;z=R.scale.y*k;C.set(w.x-J,w.y-z,w.x+J,w.y+z);if(U.instersects(C)){I=o.__styleString;if(Q!=I)m.fillStyle=Q=I;m.save();m.translate(w.x,w.y);m.rotate(-R.rotation);m.scale(J,z);m.beginPath();m.arc(0,0,1,0,La,true);m.closePath();m.fill();m.restore()}}}}function Oa(w,R,J,z){if(z.opacity!=0){a(z.opacity);b(z.blending);m.beginPath();m.moveTo(w.positionScreen.x,w.positionScreen.y);m.lineTo(R.positionScreen.x,R.positionScreen.y);m.closePath();if(z instanceof THREE.LineBasicMaterial){o.__styleString=
z.color.__styleString;w=z.linewidth;if(O!=w)m.lineWidth=O=w;w=o.__styleString;if(M!=w)m.strokeStyle=M=w;m.stroke();C.inflate(z.linewidth*2)}}}function Ha(w,R,J,z,I,Y){if(I.opacity!=0){a(I.opacity);b(I.blending);h=w.positionScreen.x;q=w.positionScreen.y;n=R.positionScreen.x;l=R.positionScreen.y;i=J.positionScreen.x;u=J.positionScreen.y;m.beginPath();m.moveTo(h,q);m.lineTo(n,l);m.lineTo(i,u);m.lineTo(h,q);m.closePath();if(I instanceof THREE.MeshBasicMaterial)if(I.map)I.map.image.loaded&&I.map.mapping instanceof
THREE.UVMapping&&ua(h,q,n,l,i,u,I.map.image,z.uvs[0].u,z.uvs[0].v,z.uvs[1].u,z.uvs[1].v,z.uvs[2].u,z.uvs[2].v);else if(I.env_map){if(I.env_map.image.loaded)if(I.env_map.mapping instanceof THREE.SphericalReflectionMapping){w=la.matrix;Z.copy(z.vertexNormalsWorld[0]);P=(Z.x*w.n11+Z.y*w.n12+Z.z*w.n13)*0.5+0.5;H=-(Z.x*w.n21+Z.y*w.n22+Z.z*w.n23)*0.5+0.5;Z.copy(z.vertexNormalsWorld[1]);X=(Z.x*w.n11+Z.y*w.n12+Z.z*w.n13)*0.5+0.5;K=-(Z.x*w.n21+Z.y*w.n22+Z.z*w.n23)*0.5+0.5;Z.copy(z.vertexNormalsWorld[2]);E=
(Z.x*w.n11+Z.y*w.n12+Z.z*w.n13)*0.5+0.5;F=-(Z.x*w.n21+Z.y*w.n22+Z.z*w.n23)*0.5+0.5;ua(h,q,n,l,i,u,I.env_map.image,P,H,X,K,E,F)}}else I.wireframe?za(I.color.__styleString,I.wireframe_linewidth):Aa(I.color.__styleString);else if(I instanceof THREE.MeshLambertMaterial){if(I.map&&!I.wireframe){I.map.mapping instanceof THREE.UVMapping&&ua(h,q,n,l,i,u,I.map.image,z.uvs[0].u,z.uvs[0].v,z.uvs[1].u,z.uvs[1].v,z.uvs[2].u,z.uvs[2].v);b(THREE.SubtractiveBlending)}if(N)if(!I.wireframe&&I.shading==THREE.SmoothShading&&
z.vertexNormalsWorld.length==3){y.r=t.r=r.r=ea.r;y.g=t.g=r.g=ea.g;y.b=t.b=r.b=ea.b;ya(Y,z.v1.positionWorld,z.vertexNormalsWorld[0],y);ya(Y,z.v2.positionWorld,z.vertexNormalsWorld[1],t);ya(Y,z.v3.positionWorld,z.vertexNormalsWorld[2],r);v.r=(t.r+r.r)*0.5;v.g=(t.g+r.g)*0.5;v.b=(t.b+r.b)*0.5;S=Ia(y,t,r,v);ua(h,q,n,l,i,u,S,0,0,1,0,0,1)}else{V.r=ea.r;V.g=ea.g;V.b=ea.b;ya(Y,z.centroidWorld,z.normalWorld,V);o.r=I.color.r*V.r;o.g=I.color.g*V.g;o.b=I.color.b*V.b;o.updateStyleString();I.wireframe?za(o.__styleString,
I.wireframe_linewidth):Aa(o.__styleString)}else I.wireframe?za(I.color.__styleString,I.wireframe_linewidth):Aa(I.color.__styleString)}else if(I instanceof THREE.MeshDepthMaterial){W=la.near;G=la.far;y.r=y.g=y.b=1-Da(w.positionScreen.z,W,G);t.r=t.g=t.b=1-Da(R.positionScreen.z,W,G);r.r=r.g=r.b=1-Da(J.positionScreen.z,W,G);v.r=(t.r+r.r)*0.5;v.g=(t.g+r.g)*0.5;v.b=(t.b+r.b)*0.5;S=Ia(y,t,r,v);ua(h,q,n,l,i,u,S,0,0,1,0,0,1)}else if(I instanceof THREE.MeshNormalMaterial){o.r=Ea(z.normalWorld.x);o.g=Ea(z.normalWorld.y);
o.b=Ea(z.normalWorld.z);o.updateStyleString();I.wireframe?za(o.__styleString,I.wireframe_linewidth):Aa(o.__styleString)}}}function za(w,R){if(M!=w)m.strokeStyle=M=w;if(O!=R)m.lineWidth=O=R;m.stroke();C.inflate(R*2)}function Aa(w){if(Q!=w)m.fillStyle=Q=w;m.fill()}function ua(w,R,J,z,I,Y,aa,ca,da,ia,ga,ja,va){var oa,ka;oa=aa.width-1;ka=aa.height-1;ca*=oa;da*=ka;ia*=oa;ga*=ka;ja*=oa;va*=ka;J-=w;z-=R;I-=w;Y-=R;ia-=ca;ga-=da;ja-=ca;va-=da;ka=1/(ia*va-ja*ga);oa=(va*J-ga*I)*ka;ga=(va*z-ga*Y)*ka;J=(ia*I-
ja*J)*ka;z=(ia*Y-ja*z)*ka;w=w-oa*ca-J*da;R=R-ga*ca-z*da;m.save();m.transform(oa,ga,J,z,w,R);m.clip();m.drawImage(aa,0,0);m.restore()}function Ia(w,R,J,z){var I=~~(w.r*255),Y=~~(w.g*255);w=~~(w.b*255);var aa=~~(R.r*255),ca=~~(R.g*255);R=~~(R.b*255);var da=~~(J.r*255),ia=~~(J.g*255);J=~~(J.b*255);var ga=~~(z.r*255),ja=~~(z.g*255);z=~~(z.b*255);fa[0]=I<0?0:I>255?255:I;fa[1]=Y<0?0:Y>255?255:Y;fa[2]=w<0?0:w>255?255:w;fa[4]=aa<0?0:aa>255?255:aa;fa[5]=ca<0?0:ca>255?255:ca;fa[6]=R<0?0:R>255?255:R;fa[8]=da<
0?0:da>255?255:da;fa[9]=ia<0?0:ia>255?255:ia;fa[10]=J<0?0:J>255?255:J;fa[12]=ga<0?0:ga>255?255:ga;fa[13]=ja<0?0:ja>255?255:ja;fa[14]=z<0?0:z>255?255:z;sa.putImageData(Ca,0,0);xa.drawImage(ra,0,0);return ta}function Da(w,R,J){w=(w-R)/(J-R);return w*w*(3-2*w)}function Ea(w){w=(w+1)*0.5;return w<0?0:w>1?1:w}function Fa(w,R){var J=R.x-w.x,z=R.y-w.y,I=1/Math.sqrt(J*J+z*z);J*=I;z*=I;R.x+=J;R.y+=z;w.x-=J;w.y-=z}var Ba,Ja,$,ha,qa,Ga,Ka,wa;m.setTransform(1,0,0,-1,c,k);this.autoClear&&this.clear();f=e.projectScene(ba,
la,this.sortElements);(N=ba.lights.length>0)&&Ma(ba);Ba=0;for(Ja=f.length;Ba<Ja;Ba++){$=f[Ba];C.empty();if($ instanceof THREE.RenderableParticle){s=$;s.x*=c;s.y*=k;ha=0;for(qa=$.materials.length;ha<qa;ha++)Na(s,$,$.materials[ha],ba)}else if($ instanceof THREE.RenderableLine){s=$.v1;L=$.v2;s.positionScreen.x*=c;s.positionScreen.y*=k;L.positionScreen.x*=c;L.positionScreen.y*=k;C.addPoint(s.positionScreen.x,s.positionScreen.y);C.addPoint(L.positionScreen.x,L.positionScreen.y);if(U.instersects(C)){ha=
0;for(qa=$.materials.length;ha<qa;)Oa(s,L,$,$.materials[ha++],ba)}}else if($ instanceof THREE.RenderableFace3){s=$.v1;L=$.v2;d=$.v3;s.positionScreen.x*=c;s.positionScreen.y*=k;L.positionScreen.x*=c;L.positionScreen.y*=k;d.positionScreen.x*=c;d.positionScreen.y*=k;if($.overdraw){Fa(s.positionScreen,L.positionScreen);Fa(L.positionScreen,d.positionScreen);Fa(d.positionScreen,s.positionScreen)}C.add3Points(s.positionScreen.x,s.positionScreen.y,L.positionScreen.x,L.positionScreen.y,d.positionScreen.x,
d.positionScreen.y);if(U.instersects(C)){ha=0;for(qa=$.meshMaterials.length;ha<qa;){wa=$.meshMaterials[ha++];if(wa instanceof THREE.MeshFaceMaterial){Ga=0;for(Ka=$.faceMaterials.length;Ga<Ka;)(wa=$.faceMaterials[Ga++])&&Ha(s,L,d,$,wa,ba)}else Ha(s,L,d,$,wa,ba)}}}T.addRectangle(C)}m.setTransform(1,0,0,1,0,0)}};
THREE.SVGRenderer=function(){function a(P,H,X){var K,E,F,U;K=0;for(E=P.lights.length;K<E;K++){F=P.lights[K];if(F instanceof THREE.DirectionalLight){U=H.normalWorld.dot(F.position)*F.intensity;if(U>0){X.r+=F.color.r*U;X.g+=F.color.g*U;X.b+=F.color.b*U}}else if(F instanceof THREE.PointLight){u.sub(F.position,H.centroidWorld);u.normalize();U=H.normalWorld.dot(u)*F.intensity;if(U>0){X.r+=F.color.r*U;X.g+=F.color.g*U;X.b+=F.color.b*U}}}}function b(P,H,X,K,E,F){r=e(v++);r.setAttribute("d","M "+P.positionScreen.x+
" "+P.positionScreen.y+" L "+H.positionScreen.x+" "+H.positionScreen.y+" L "+X.positionScreen.x+","+X.positionScreen.y+"z");if(E instanceof THREE.MeshBasicMaterial)d.__styleString=E.color.__styleString;else if(E instanceof THREE.MeshLambertMaterial)if(L){h.r=q.r;h.g=q.g;h.b=q.b;a(F,K,h);d.r=E.color.r*h.r;d.g=E.color.g*h.g;d.b=E.color.b*h.b;d.updateStyleString()}else d.__styleString=E.color.__styleString;else if(E instanceof THREE.MeshDepthMaterial){i=1-E.__2near/(E.__farPlusNear-K.z*E.__farMinusNear);
d.setRGB(i,i,i)}else E instanceof THREE.MeshNormalMaterial&&d.setRGB(g(K.normalWorld.x),g(K.normalWorld.y),g(K.normalWorld.z));E.wireframe?r.setAttribute("style","fill: none; stroke: "+d.__styleString+"; stroke-width: "+E.wireframe_linewidth+"; stroke-opacity: "+E.opacity+"; stroke-linecap: "+E.wireframe_linecap+"; stroke-linejoin: "+E.wireframe_linejoin):r.setAttribute("style","fill: "+d.__styleString+"; fill-opacity: "+E.opacity);c.appendChild(r)}function f(P,H,X,K,E,F,U){r=e(v++);r.setAttribute("d",
"M "+P.positionScreen.x+" "+P.positionScreen.y+" L "+H.positionScreen.x+" "+H.positionScreen.y+" L "+X.positionScreen.x+","+X.positionScreen.y+" L "+K.positionScreen.x+","+K.positionScreen.y+"z");if(F instanceof THREE.MeshBasicMaterial)d.__styleString=F.color.__styleString;else if(F instanceof THREE.MeshLambertMaterial)if(L){h.r=q.r;h.g=q.g;h.b=q.b;a(U,E,h);d.r=F.color.r*h.r;d.g=F.color.g*h.g;d.b=F.color.b*h.b;d.updateStyleString()}else d.__styleString=F.color.__styleString;else if(F instanceof THREE.MeshDepthMaterial){i=
1-F.__2near/(F.__farPlusNear-E.z*F.__farMinusNear);d.setRGB(i,i,i)}else F instanceof THREE.MeshNormalMaterial&&d.setRGB(g(E.normalWorld.x),g(E.normalWorld.y),g(E.normalWorld.z));F.wireframe?r.setAttribute("style","fill: none; stroke: "+d.__styleString+"; stroke-width: "+F.wireframe_linewidth+"; stroke-opacity: "+F.opacity+"; stroke-linecap: "+F.wireframe_linecap+"; stroke-linejoin: "+F.wireframe_linejoin):r.setAttribute("style","fill: "+d.__styleString+"; fill-opacity: "+F.opacity);c.appendChild(r)}
function e(P){if(o[P]==null){o[P]=document.createElementNS("http://www.w3.org/2000/svg","path");S==0&&o[P].setAttribute("shape-rendering","crispEdges");return o[P]}return o[P]}function g(P){return P<0?Math.min((1+P)*0.5,0.5):0.5+Math.min(P*0.5,0.5)}var j=null,p=new THREE.Projector,c=document.createElementNS("http://www.w3.org/2000/svg","svg"),k,m,B,D,x,A,M,Q,O=new THREE.Rectangle,s=new THREE.Rectangle,L=false,d=new THREE.Color(16777215),h=new THREE.Color(16777215),q=new THREE.Color(0),n=new THREE.Color(0),
l=new THREE.Color(0),i,u=new THREE.Vector3,o=[],y=[],t=[],r,v,W,G,S=1;this.domElement=c;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(P){switch(P){case "high":S=1;break;case "low":S=0}};this.setSize=function(P,H){k=P;m=H;B=k/2;D=m/2;c.setAttribute("viewBox",-B+" "+-D+" "+k+" "+m);c.setAttribute("width",k);c.setAttribute("height",m);O.set(-B,-D,B,D)};this.clear=function(){for(;c.childNodes.length>0;)c.removeChild(c.childNodes[0])};this.render=function(P,H){var X,K,
E,F,U,T,C,N;this.autoClear&&this.clear();j=p.projectScene(P,H,this.sortElements);G=W=v=0;if(L=P.lights.length>0){C=P.lights;q.setRGB(0,0,0);n.setRGB(0,0,0);l.setRGB(0,0,0);X=0;for(K=C.length;X<K;X++){E=C[X];F=E.color;if(E instanceof THREE.AmbientLight){q.r+=F.r;q.g+=F.g;q.b+=F.b}else if(E instanceof THREE.DirectionalLight){n.r+=F.r;n.g+=F.g;n.b+=F.b}else if(E instanceof THREE.PointLight){l.r+=F.r;l.g+=F.g;l.b+=F.b}}}X=0;for(K=j.length;X<K;X++){C=j[X];s.empty();if(C instanceof THREE.RenderableParticle){x=
C;x.x*=B;x.y*=-D;E=0;for(F=C.materials.length;E<F;E++)if(N=C.materials[E]){U=x;T=C;N=N;var V=W++;if(y[V]==null){y[V]=document.createElementNS("http://www.w3.org/2000/svg","circle");S==0&&y[V].setAttribute("shape-rendering","crispEdges")}r=y[V];r.setAttribute("cx",U.x);r.setAttribute("cy",U.y);r.setAttribute("r",T.scale.x*B);if(N instanceof THREE.ParticleCircleMaterial){if(L){h.r=q.r+n.r+l.r;h.g=q.g+n.g+l.g;h.b=q.b+n.b+l.b;d.r=N.color.r*h.r;d.g=N.color.g*h.g;d.b=N.color.b*h.b;d.updateStyleString()}else d=
N.color;r.setAttribute("style","fill: "+d.__styleString)}c.appendChild(r)}}else if(C instanceof THREE.RenderableLine){x=C.v1;A=C.v2;x.positionScreen.x*=B;x.positionScreen.y*=-D;A.positionScreen.x*=B;A.positionScreen.y*=-D;s.addPoint(x.positionScreen.x,x.positionScreen.y);s.addPoint(A.positionScreen.x,A.positionScreen.y);if(O.instersects(s)){E=0;for(F=C.materials.length;E<F;)if(N=C.materials[E++]){U=x;T=A;N=N;V=G++;if(t[V]==null){t[V]=document.createElementNS("http://www.w3.org/2000/svg","line");S==
0&&t[V].setAttribute("shape-rendering","crispEdges")}r=t[V];r.setAttribute("x1",U.positionScreen.x);r.setAttribute("y1",U.positionScreen.y);r.setAttribute("x2",T.positionScreen.x);r.setAttribute("y2",T.positionScreen.y);if(N instanceof THREE.LineBasicMaterial){d.__styleString=N.color.__styleString;r.setAttribute("style","fill: none; stroke: "+d.__styleString+"; stroke-width: "+N.linewidth+"; stroke-opacity: "+N.opacity+"; stroke-linecap: "+N.linecap+"; stroke-linejoin: "+N.linejoin);c.appendChild(r)}}}}else if(C instanceof
THREE.RenderableFace3){x=C.v1;A=C.v2;M=C.v3;x.positionScreen.x*=B;x.positionScreen.y*=-D;A.positionScreen.x*=B;A.positionScreen.y*=-D;M.positionScreen.x*=B;M.positionScreen.y*=-D;s.addPoint(x.positionScreen.x,x.positionScreen.y);s.addPoint(A.positionScreen.x,A.positionScreen.y);s.addPoint(M.positionScreen.x,M.positionScreen.y);if(O.instersects(s)){E=0;for(F=C.meshMaterials.length;E<F;){N=C.meshMaterials[E++];if(N instanceof THREE.MeshFaceMaterial){U=0;for(T=C.faceMaterials.length;U<T;)(N=C.faceMaterials[U++])&&
b(x,A,M,C,N,P)}else N&&b(x,A,M,C,N,P)}}}else if(C instanceof THREE.RenderableFace4){x=C.v1;A=C.v2;M=C.v3;Q=C.v4;x.positionScreen.x*=B;x.positionScreen.y*=-D;A.positionScreen.x*=B;A.positionScreen.y*=-D;M.positionScreen.x*=B;M.positionScreen.y*=-D;Q.positionScreen.x*=B;Q.positionScreen.y*=-D;s.addPoint(x.positionScreen.x,x.positionScreen.y);s.addPoint(A.positionScreen.x,A.positionScreen.y);s.addPoint(M.positionScreen.x,M.positionScreen.y);s.addPoint(Q.positionScreen.x,Q.positionScreen.y);if(O.instersects(s)){E=
0;for(F=C.meshMaterials.length;E<F;){N=C.meshMaterials[E++];if(N instanceof THREE.MeshFaceMaterial){U=0;for(T=C.faceMaterials.length;U<T;)(N=C.faceMaterials[U++])&&f(x,A,M,Q,C,N,P)}else N&&f(x,A,M,Q,C,N,P)}}}}}};
THREE.WebGLRenderer=function(a){function b(d,h){d.fragment_shader=h.fragment_shader;d.vertex_shader=h.vertex_shader;d.uniforms=Uniforms.clone(h.uniforms)}function f(d,h){d.uniforms.color.value.setRGB(d.color.r*d.opacity,d.color.g*d.opacity,d.color.b*d.opacity);d.uniforms.opacity.value=d.opacity;d.uniforms.map.texture=d.map;d.uniforms.env_map.texture=d.env_map;d.uniforms.reflectivity.value=d.reflectivity;d.uniforms.refraction_ratio.value=d.refraction_ratio;d.uniforms.combine.value=d.combine;d.uniforms.useRefract.value=
d.env_map&&d.env_map.mapping instanceof THREE.CubeRefractionMapping;if(h){d.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){d.uniforms.fogNear.value=h.near;d.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)d.uniforms.fogDensity.value=h.density}}function e(d,h){d.uniforms.color.value.setRGB(d.color.r*d.opacity,d.color.g*d.opacity,d.color.b*d.opacity);d.uniforms.opacity.value=d.opacity;if(h){d.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){d.uniforms.fogNear.value=
h.near;d.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)d.uniforms.fogDensity.value=h.density}}function g(d,h){var r;if(d=="fragment")r=c.createShader(c.FRAGMENT_SHADER);else if(d=="vertex")r=c.createShader(c.VERTEX_SHADER);c.shaderSource(r,h);c.compileShader(r);if(!c.getShaderParameter(r,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(r));return null}return r}function j(d){switch(d){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,k=null,n=new THREE.Matrix4,B,D=new Float32Array(16),x=new Float32Array(16),A=new Float32Array(16),
M=new Float32Array(9),Q=new Float32Array(16),O=true,q=new THREE.Color(0),L=0;if(a){if(a.antialias!==undefined)O=a.antialias;a.clearColor!==undefined&&q.setHex(a.clearColor);if(a.clearAlpha!==undefined)L=a.clearAlpha}this.domElement=o;this.autoClear=true;(function(d,h,r){try{c=o.getContext("experimental-webgl",{antialias:d})}catch(l){}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(h.r,h.g,h.b,r)})(O,q,L);this.setSize=function(d,h){o.width=d;o.height=h;c.viewport(0,0,o.width,o.height)};this.setClearColor=function(d,h){var r=new THREE.Color(d);c.clearColor(r.r,r.g,r.b,h)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(d,h){var r,l,m,i=0,t=0,p=0,y=[],u=[],s=[],v=[];r=0;for(l=h.length;r<l;r++){m=h[r];if(m instanceof THREE.AmbientLight){i+=
m.color.r;t+=m.color.g;p+=m.color.b}else if(m instanceof THREE.DirectionalLight){y.push(m.color.r*m.intensity,m.color.g*m.intensity,m.color.b*m.intensity);u.push(m.position.x,m.position.y,m.position.z)}else if(m instanceof THREE.PointLight){s.push(m.color.r*m.intensity,m.color.g*m.intensity,m.color.b*m.intensity);v.push(m.position.x,m.position.y,m.position.z)}}return{ambient:[i,t,p],directional:{colors:y,positions:u},point:{colors:s,positions:v}}};this.createLineBuffers=function(d){var h,r,l,m=[],
i=[],t=d.geometry.vertices;h=0;for(r=t.length;h<r;h++){l=t[h].position;m.push(l.x,l.y,l.z);i.push(h)}if(m.length){d.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,d.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(m),c.STATIC_DRAW);d.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,d.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(i),c.STATIC_DRAW);d.__webGLLineCount=i.length}};this.createBuffers=function(d,h){var r,l,
m,i,t,p,y,u,s,v,W=[],G=[],S=[],P=[],H=[],X=[],K=0,E=d.geometry.geometryChunks[h],F;t=false;r=0;for(l=d.materials.length;r<l;r++){p=d.materials[r];if(p instanceof THREE.MeshFaceMaterial){p=0;for(F=E.materials.length;p<F;p++)if(E.materials[p]&&E.materials[p].shading!=undefined&&E.materials[p].shading==THREE.SmoothShading){t=true;break}}else if(p&&p.shading!=undefined&&p.shading==THREE.SmoothShading){t=true;break}if(t)break}F=t;r=0;for(l=E.faces.length;r<l;r++){m=E.faces[r];i=d.geometry.faces[m];t=i.vertexNormals;
p=i.normal;m=d.geometry.uvs[m];if(i instanceof THREE.Face3){y=d.geometry.vertices[i.a].position;u=d.geometry.vertices[i.b].position;s=d.geometry.vertices[i.c].position;S.push(y.x,y.y,y.z,u.x,u.y,u.z,s.x,s.y,s.z);if(d.geometry.hasTangents){y=d.geometry.vertices[i.a].tangent;u=d.geometry.vertices[i.b].tangent;s=d.geometry.vertices[i.c].tangent;H.push(y.x,y.y,y.z,y.w,u.x,u.y,u.z,u.w,s.x,s.y,s.z,s.w)}if(t.length==3&&F)for(i=0;i<3;i++)P.push(t[i].x,t[i].y,t[i].z);else for(i=0;i<3;i++)P.push(p.x,p.y,p.z);
if(m)for(i=0;i<3;i++)X.push(m[i].u,m[i].v);W.push(K,K+1,K+2);G.push(K,K+1,K,K+2,K+1,K+2);K+=3}else if(i instanceof THREE.Face4){y=d.geometry.vertices[i.a].position;u=d.geometry.vertices[i.b].position;s=d.geometry.vertices[i.c].position;v=d.geometry.vertices[i.d].position;S.push(y.x,y.y,y.z,u.x,u.y,u.z,s.x,s.y,s.z,v.x,v.y,v.z);if(d.geometry.hasTangents){y=d.geometry.vertices[i.a].tangent;u=d.geometry.vertices[i.b].tangent;s=d.geometry.vertices[i.c].tangent;i=d.geometry.vertices[i.d].tangent;H.push(y.x,
y.y,y.z,y.w,u.x,u.y,u.z,u.w,s.x,s.y,s.z,s.w,i.x,i.y,i.z,i.w)}if(t.length==4&&F)for(i=0;i<4;i++)P.push(t[i].x,t[i].y,t[i].z);else for(i=0;i<4;i++)P.push(p.x,p.y,p.z);if(m)for(i=0;i<4;i++)X.push(m[i].u,m[i].v);W.push(K,K+1,K+2,K,K+2,K+3);G.push(K,K+1,K,K+2,K,K+3,K+1,K+2,K+2,K+3);K+=4}}if(S.length){E.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,E.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(S),c.STATIC_DRAW);E.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,
h.near;d.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)d.uniforms.fogDensity.value=h.density}}function g(d,h){var q;if(d=="fragment")q=c.createShader(c.FRAGMENT_SHADER);else if(d=="vertex")q=c.createShader(c.VERTEX_SHADER);c.shaderSource(q,h);c.compileShader(q);if(!c.getShaderParameter(q,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(q));return null}return q}function j(d){switch(d){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 p=document.createElement("canvas"),c,k=null,m=new THREE.Matrix4,B,D=new Float32Array(16),x=new Float32Array(16),A=new Float32Array(16),
M=new Float32Array(9),Q=new Float32Array(16),O=true,s=new THREE.Color(0),L=0;if(a){if(a.antialias!==undefined)O=a.antialias;a.clearColor!==undefined&&s.setHex(a.clearColor);if(a.clearAlpha!==undefined)L=a.clearAlpha}this.domElement=p;this.autoClear=true;(function(d,h,q){try{c=p.getContext("experimental-webgl",{antialias:d})}catch(n){}if(!c){alert("WebGL not supported");throw"cannot create webgl context";}c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);
c.cullFace(c.BACK);c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(h.r,h.g,h.b,q)})(O,s,L);this.setSize=function(d,h){p.width=d;p.height=h;c.viewport(0,0,p.width,p.height)};this.setClearColor=function(d,h){var q=new THREE.Color(d);c.clearColor(q.r,q.g,q.b,h)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(d,h){var q,n,l,i=0,u=0,o=0,y=[],t=[],r=[],v=[];q=0;for(n=h.length;q<n;q++){l=h[q];if(l instanceof THREE.AmbientLight){i+=
l.color.r;u+=l.color.g;o+=l.color.b}else if(l instanceof THREE.DirectionalLight){y.push(l.color.r*l.intensity,l.color.g*l.intensity,l.color.b*l.intensity);t.push(l.position.x,l.position.y,l.position.z)}else if(l instanceof THREE.PointLight){r.push(l.color.r*l.intensity,l.color.g*l.intensity,l.color.b*l.intensity);v.push(l.position.x,l.position.y,l.position.z)}}return{ambient:[i,u,o],directional:{colors:y,positions:t},point:{colors:r,positions:v}}};this.createParticleBuffers=function(){};this.createLineBuffers=
function(d){var h,q,n,l=[],i=[],u=d.geometry.vertices;h=0;for(q=u.length;h<q;h++){n=u[h].position;l.push(n.x,n.y,n.z);i.push(h)}if(l.length){d.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,d.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(l),c.STATIC_DRAW);d.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,d.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(i),c.STATIC_DRAW);d.__webGLLineCount=i.length}};this.createBuffers=
function(d,h){var q,n,l,i,u,o,y,t,r,v,W=[],G=[],S=[],P=[],H=[],X=[],K=0,E=d.geometry.geometryChunks[h],F;u=false;q=0;for(n=d.materials.length;q<n;q++){o=d.materials[q];if(o instanceof THREE.MeshFaceMaterial){o=0;for(F=E.materials.length;o<F;o++)if(E.materials[o]&&E.materials[o].shading!=undefined&&E.materials[o].shading==THREE.SmoothShading){u=true;break}}else if(o&&o.shading!=undefined&&o.shading==THREE.SmoothShading){u=true;break}if(u)break}F=u;q=0;for(n=E.faces.length;q<n;q++){l=E.faces[q];i=d.geometry.faces[l];
u=i.vertexNormals;o=i.normal;l=d.geometry.uvs[l];if(i instanceof THREE.Face3){y=d.geometry.vertices[i.a].position;t=d.geometry.vertices[i.b].position;r=d.geometry.vertices[i.c].position;S.push(y.x,y.y,y.z,t.x,t.y,t.z,r.x,r.y,r.z);if(d.geometry.hasTangents){y=d.geometry.vertices[i.a].tangent;t=d.geometry.vertices[i.b].tangent;r=d.geometry.vertices[i.c].tangent;H.push(y.x,y.y,y.z,y.w,t.x,t.y,t.z,t.w,r.x,r.y,r.z,r.w)}if(u.length==3&&F)for(i=0;i<3;i++)P.push(u[i].x,u[i].y,u[i].z);else for(i=0;i<3;i++)P.push(o.x,
o.y,o.z);if(l)for(i=0;i<3;i++)X.push(l[i].u,l[i].v);W.push(K,K+1,K+2);G.push(K,K+1,K,K+2,K+1,K+2);K+=3}else if(i instanceof THREE.Face4){y=d.geometry.vertices[i.a].position;t=d.geometry.vertices[i.b].position;r=d.geometry.vertices[i.c].position;v=d.geometry.vertices[i.d].position;S.push(y.x,y.y,y.z,t.x,t.y,t.z,r.x,r.y,r.z,v.x,v.y,v.z);if(d.geometry.hasTangents){y=d.geometry.vertices[i.a].tangent;t=d.geometry.vertices[i.b].tangent;r=d.geometry.vertices[i.c].tangent;i=d.geometry.vertices[i.d].tangent;
H.push(y.x,y.y,y.z,y.w,t.x,t.y,t.z,t.w,r.x,r.y,r.z,r.w,i.x,i.y,i.z,i.w)}if(u.length==4&&F)for(i=0;i<4;i++)P.push(u[i].x,u[i].y,u[i].z);else for(i=0;i<4;i++)P.push(o.x,o.y,o.z);if(l)for(i=0;i<4;i++)X.push(l[i].u,l[i].v);W.push(K,K+1,K+2,K,K+2,K+3);G.push(K,K+1,K,K+2,K,K+3,K+1,K+2,K+2,K+3);K+=4}}if(S.length){E.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,E.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(S),c.STATIC_DRAW);E.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,
E.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(P),c.STATIC_DRAW);if(d.geometry.hasTangents){E.__webGLTangentBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,E.__webGLTangentBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(H),c.STATIC_DRAW)}if(X.length>0){E.__webGLUVBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,E.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(X),c.STATIC_DRAW)}E.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,
E.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(W),c.STATIC_DRAW);E.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,E.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(G),c.STATIC_DRAW);E.__webGLFaceCount=W.length;E.__webGLLineCount=G.length}};this.renderBuffer=function(d,h,r,l,m){var i,t,p,y;if(!l.program){if(l instanceof THREE.MeshDepthMaterial){b(l,THREE.ShaderLib.depth);l.uniforms.mNear.value=d.near;l.uniforms.mFar.value=d.far}else if(l instanceof
THREE.MeshNormalMaterial)b(l,THREE.ShaderLib.normal);else if(l instanceof THREE.MeshBasicMaterial){b(l,THREE.ShaderLib.basic);f(l,r)}else if(l instanceof THREE.MeshLambertMaterial){b(l,THREE.ShaderLib.lambert);f(l,r)}else if(l instanceof THREE.MeshPhongMaterial){b(l,THREE.ShaderLib.phong);f(l,r)}else if(l instanceof THREE.LineBasicMaterial){b(l,THREE.ShaderLib.basic);e(l,r)}if(scene){var u,s,v;u=y=t=0;for(s=h.length;u<s;u++){v=h[u];v instanceof THREE.DirectionalLight&&y++;v instanceof THREE.PointLight&&
t++}if(t+y<=4){u=y;t=t}else{u=Math.ceil(4*y/(t+y));t=4-u}t={directional:u,point:t}}else t={directional:1,point:3};y={fog:r,map:l.map,env_map:l.env_map,maxDirLights:t.directional,maxPointLights:t.point};t=l.fragment_shader;u=l.vertex_shader;s=c.createProgram();v=["#ifdef GL_ES\nprecision highp float;\n#endif","#define MAX_DIR_LIGHTS "+y.maxDirLights,"#define MAX_POINT_LIGHTS "+y.maxPointLights,y.fog?"#define USE_FOG":"",y.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",y.map?"#define USE_MAP":"",
y.env_map?"#define USE_ENVMAP":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");y=[c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+y.maxDirLights,"#define MAX_POINT_LIGHTS "+y.maxPointLights,y.map?"#define USE_MAP":"",y.env_map?"#define USE_ENVMAP":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"].join("\n");
c.attachShader(s,g("fragment",v+t));c.attachShader(s,g("vertex",y+u));c.linkProgram(s);c.getProgramParameter(s,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(s,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");s.uniforms={};s.attributes={};l.program=s;t=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(i in l.uniforms)t.push(i);i=l.program;u=0;for(s=t.length;u<s;u++){v=t[u];i.uniforms[v]=c.getUniformLocation(i,
v)}i=l.program;t=["position","normal","uv","tangent"];u=0;for(s=t.length;u<s;u++){v=t[u];i.attributes[v]=c.getAttribLocation(i,v)}}i=l.program;if(i!=k){c.useProgram(i);k=i}this.loadCamera(i,d);this.loadMatrices(i);if(l instanceof THREE.MeshPhongMaterial||l instanceof THREE.MeshLambertMaterial){d=this.setupLights(i,h);l.uniforms.enableLighting.value=d.directional.positions.length+d.point.positions.length;l.uniforms.ambientLightColor.value=d.ambient;l.uniforms.directionalLightColor.value=d.directional.colors;
l.uniforms.directionalLightDirection.value=d.directional.positions;l.uniforms.pointLightColor.value=d.point.colors;l.uniforms.pointLightPosition.value=d.point.positions}if(l instanceof THREE.MeshBasicMaterial||l instanceof THREE.MeshLambertMaterial||l instanceof THREE.MeshPhongMaterial)f(l,r);l instanceof THREE.LineBasicMaterial&&e(l,r);if(l instanceof THREE.MeshPhongMaterial){l.uniforms.ambient.value.setRGB(l.ambient.r,l.ambient.g,l.ambient.b);l.uniforms.specular.value.setRGB(l.specular.r,l.specular.g,
l.specular.b);l.uniforms.shininess.value=l.shininess}r=l.uniforms;for(p in r)if(t=i.uniforms[p]){h=r[p].type;d=r[p].value;if(h=="i")c.uniform1i(t,d);else if(h=="f")c.uniform1f(t,d);else if(h=="fv")c.uniform3fv(t,d);else if(h=="v2")c.uniform2f(t,d.x,d.y);else if(h=="v3")c.uniform3f(t,d.x,d.y,d.z);else if(h=="c")c.uniform3f(t,d.r,d.g,d.b);else if(h=="t"){c.uniform1i(t,d);if(h=r[p].texture)if(h.image instanceof Array&&h.image.length==6){h=h;d=d;if(h.image.length==6){if(!h.image.__webGLTextureCube&&!h.image.__cubeMapInitialized&&
h.image.loadCount==6){h.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,h.image.__webGLTextureCube);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(t=0;t<6;++t)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,
h.image[t]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);h.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+d);c.bindTexture(c.TEXTURE_CUBE_MAP,h.image.__webGLTextureCube)}}else{h=h;d=d;if(!h.__webGLTexture&&h.image.loaded){h.__webGLTexture=c.createTexture();c.bindTexture(c.TEXTURE_2D,h.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,h.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,j(h.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,
j(h.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,j(h.mag_filter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,j(h.min_filter));c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+d);c.bindTexture(c.TEXTURE_2D,h.__webGLTexture)}}}p=i.attributes;c.bindBuffer(c.ARRAY_BUFFER,m.__webGLVertexBuffer);c.vertexAttribPointer(p.position,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(p.position);if(p.normal>=0){c.bindBuffer(c.ARRAY_BUFFER,m.__webGLNormalBuffer);
c.vertexAttribPointer(p.normal,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(p.normal)}if(p.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,m.__webGLTangentBuffer);c.vertexAttribPointer(p.tangent,4,c.FLOAT,false,0,0);c.enableVertexAttribArray(p.tangent)}if(p.uv>=0)if(m.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,m.__webGLUVBuffer);c.vertexAttribPointer(p.uv,2,c.FLOAT,false,0,0);c.enableVertexAttribArray(p.uv)}else c.disableVertexAttribArray(p.uv);if(l.wireframe||l instanceof THREE.LineBasicMaterial){p=
l.wireframe_linewidth!==undefined?l.wireframe_linewidth:l.linewidth!==undefined?l.linewidth:1;l=l instanceof THREE.LineBasicMaterial&&m.type==THREE.LineStrip?c.LINE_STRIP:c.LINES;c.lineWidth(p);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,m.__webGLLineBuffer);c.drawElements(l,m.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,m.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,m.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(d,h,r,l,m,i,t){var p,y,u,s,v;u=0;for(s=
l.materials.length;u<s;u++){p=l.materials[u];if(p instanceof THREE.MeshFaceMaterial){p=0;for(y=m.materials.length;p<y;p++)if((v=m.materials[p])&&v.blending==i&&v.opacity<1==t){this.setBlending(v.blending);this.renderBuffer(d,h,r,v,m)}}else if((v=p)&&v.blending==i&&v.opacity<1==t){this.setBlending(v.blending);this.renderBuffer(d,h,r,v,m)}}};this.render=function(d,h){var r,l,m,i,t=d.lights,p=d.fog;this.initWebGLObjects(d);this.autoClear&&this.clear();h.autoUpdateMatrix&&h.updateMatrix();D.set(h.matrix.flatten());
A.set(h.projectionMatrix.flatten());r=0;for(l=d.__webGLObjects.length;r<l;r++){m=d.__webGLObjects[r];i=m.object;m=m.buffer;if(i.visible){this.setupMatrices(i,h);this.renderPass(h,t,p,i,m,THREE.NormalBlending,false)}}r=0;for(l=d.__webGLObjects.length;r<l;r++){m=d.__webGLObjects[r];i=m.object;m=m.buffer;if(i.visible){this.setupMatrices(i,h);this.renderPass(h,t,p,i,m,THREE.AdditiveBlending,false);this.renderPass(h,t,p,i,m,THREE.SubtractiveBlending,false);this.renderPass(h,t,p,i,m,THREE.AdditiveBlending,
true);this.renderPass(h,t,p,i,m,THREE.SubtractiveBlending,true);this.renderPass(h,t,p,i,m,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(d){var h,r,l,m,i,t;if(!d.__webGLObjects){d.__webGLObjects=[];d.__webGLObjectsMap={}}h=0;for(r=d.objects.length;h<r;h++){l=d.objects[h];if(d.__webGLObjectsMap[l.id]==undefined)d.__webGLObjectsMap[l.id]={};t=d.__webGLObjectsMap[l.id];if(l instanceof THREE.Mesh)for(i in l.geometry.geometryChunks){m=l.geometry.geometryChunks[i];m.__webGLVertexBuffer||this.createBuffers(l,
i);if(t[i]==undefined){m={buffer:m,object:l};d.__webGLObjects.push(m);t[i]=1}}else if(l instanceof THREE.Line){l.__webGLVertexBuffer||this.createLineBuffers(l);i=0;if(t[i]==undefined){m={buffer:l,object:l};d.__webGLObjects.push(m);t[i]=1}}}};this.removeObject=function(d,h){var r,l;for(r=d.__webGLObjects.length-1;r>=0;r--){l=d.__webGLObjects[r].object;h==l&&d.__webGLObjects.splice(r,1)}};this.setupMatrices=function(d,h){d.autoUpdateMatrix&&d.updateMatrix();n.multiply(h.matrix,d.matrix);x.set(n.flatten());
B=THREE.Matrix4.makeInvert3x3(n).transpose();M.set(B.m);Q.set(d.matrix.flatten())};this.loadMatrices=function(d){c.uniformMatrix4fv(d.uniforms.viewMatrix,false,D);c.uniformMatrix4fv(d.uniforms.modelViewMatrix,false,x);c.uniformMatrix4fv(d.uniforms.projectionMatrix,false,A);c.uniformMatrix3fv(d.uniforms.normalMatrix,false,M);c.uniformMatrix4fv(d.uniforms.objectMatrix,false,Q)};this.loadCamera=function(d,h){c.uniform3f(d.uniforms.cameraPosition,h.position.x,h.position.y,h.position.z)};this.setBlending=
function(d){switch(d){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(d,h){if(d){!h||h=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(d=="back")c.cullFace(c.BACK);else d=="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}};
E.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(W),c.STATIC_DRAW);E.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,E.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(G),c.STATIC_DRAW);E.__webGLFaceCount=W.length;E.__webGLLineCount=G.length}};this.renderBuffer=function(d,h,q,n,l){var i,u,o,y;if(!n.program){if(n instanceof THREE.MeshDepthMaterial){b(n,THREE.ShaderLib.depth);n.uniforms.mNear.value=d.near;n.uniforms.mFar.value=d.far}else if(n instanceof
THREE.MeshNormalMaterial)b(n,THREE.ShaderLib.normal);else if(n instanceof THREE.MeshBasicMaterial){b(n,THREE.ShaderLib.basic);f(n,q)}else if(n instanceof THREE.MeshLambertMaterial){b(n,THREE.ShaderLib.lambert);f(n,q)}else if(n instanceof THREE.MeshPhongMaterial){b(n,THREE.ShaderLib.phong);f(n,q)}else if(n instanceof THREE.LineBasicMaterial){b(n,THREE.ShaderLib.basic);e(n,q)}var t,r,v;t=y=u=0;for(r=h.length;t<r;t++){v=h[t];v instanceof THREE.DirectionalLight&&y++;v instanceof THREE.PointLight&&u++}if(u+
y<=4){t=y;u=u}else{t=Math.ceil(4*y/(u+y));u=4-t}u={directional:t,point:u};y={fog:q,map:n.map,env_map:n.env_map,maxDirLights:u.directional,maxPointLights:u.point};u=n.fragment_shader;t=n.vertex_shader;r=c.createProgram();v=["#ifdef GL_ES\nprecision highp float;\n#endif","#define MAX_DIR_LIGHTS "+y.maxDirLights,"#define MAX_POINT_LIGHTS "+y.maxPointLights,y.fog?"#define USE_FOG":"",y.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",y.map?"#define USE_MAP":"",y.env_map?"#define USE_ENVMAP":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");
y=[c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+y.maxDirLights,"#define MAX_POINT_LIGHTS "+y.maxPointLights,y.map?"#define USE_MAP":"",y.env_map?"#define USE_ENVMAP":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"].join("\n");c.attachShader(r,
g("fragment",v+u));c.attachShader(r,g("vertex",y+t));c.linkProgram(r);c.getProgramParameter(r,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(r,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");r.uniforms={};r.attributes={};n.program=r;u=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(i in n.uniforms)u.push(i);i=n.program;t=0;for(r=u.length;t<r;t++){v=u[t];i.uniforms[v]=c.getUniformLocation(i,v)}i=
n.program;u=["position","normal","uv","tangent"];t=0;for(r=u.length;t<r;t++){v=u[t];i.attributes[v]=c.getAttribLocation(i,v)}}i=n.program;if(i!=k){c.useProgram(i);k=i}this.loadCamera(i,d);this.loadMatrices(i);if(n instanceof THREE.MeshPhongMaterial||n instanceof THREE.MeshLambertMaterial){d=this.setupLights(i,h);n.uniforms.enableLighting.value=d.directional.positions.length+d.point.positions.length;n.uniforms.ambientLightColor.value=d.ambient;n.uniforms.directionalLightColor.value=d.directional.colors;
n.uniforms.directionalLightDirection.value=d.directional.positions;n.uniforms.pointLightColor.value=d.point.colors;n.uniforms.pointLightPosition.value=d.point.positions}if(n instanceof THREE.MeshBasicMaterial||n instanceof THREE.MeshLambertMaterial||n instanceof THREE.MeshPhongMaterial)f(n,q);n instanceof THREE.LineBasicMaterial&&e(n,q);if(n instanceof THREE.MeshPhongMaterial){n.uniforms.ambient.value.setRGB(n.ambient.r,n.ambient.g,n.ambient.b);n.uniforms.specular.value.setRGB(n.specular.r,n.specular.g,
n.specular.b);n.uniforms.shininess.value=n.shininess}q=n.uniforms;for(o in q)if(u=i.uniforms[o]){h=q[o].type;d=q[o].value;if(h=="i")c.uniform1i(u,d);else if(h=="f")c.uniform1f(u,d);else if(h=="fv")c.uniform3fv(u,d);else if(h=="v2")c.uniform2f(u,d.x,d.y);else if(h=="v3")c.uniform3f(u,d.x,d.y,d.z);else if(h=="c")c.uniform3f(u,d.r,d.g,d.b);else if(h=="t"){c.uniform1i(u,d);if(h=q[o].texture)if(h.image instanceof Array&&h.image.length==6){h=h;d=d;if(h.image.length==6){if(!h.image.__webGLTextureCube&&!h.image.__cubeMapInitialized&&
h.image.loadCount==6){h.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,h.image.__webGLTextureCube);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(u=0;u<6;++u)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+u,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,
h.image[u]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);h.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+d);c.bindTexture(c.TEXTURE_CUBE_MAP,h.image.__webGLTextureCube)}}else{h=h;d=d;if(!h.__webGLTexture&&h.image.loaded){h.__webGLTexture=c.createTexture();c.bindTexture(c.TEXTURE_2D,h.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,h.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,j(h.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,
j(h.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,j(h.mag_filter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,j(h.min_filter));c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+d);c.bindTexture(c.TEXTURE_2D,h.__webGLTexture)}}}o=i.attributes;c.bindBuffer(c.ARRAY_BUFFER,l.__webGLVertexBuffer);c.vertexAttribPointer(o.position,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.position);if(o.normal>=0){c.bindBuffer(c.ARRAY_BUFFER,l.__webGLNormalBuffer);
c.vertexAttribPointer(o.normal,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.normal)}if(o.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,l.__webGLTangentBuffer);c.vertexAttribPointer(o.tangent,4,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.tangent)}if(o.uv>=0)if(l.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,l.__webGLUVBuffer);c.vertexAttribPointer(o.uv,2,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.uv)}else c.disableVertexAttribArray(o.uv);if(n.wireframe||n instanceof THREE.LineBasicMaterial){o=
n.wireframe_linewidth!==undefined?n.wireframe_linewidth:n.linewidth!==undefined?n.linewidth:1;n=n instanceof THREE.LineBasicMaterial&&l.type==THREE.LineStrip?c.LINE_STRIP:c.LINES;c.lineWidth(o);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,l.__webGLLineBuffer);c.drawElements(n,l.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,l.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,l.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(d,h,q,n,l,i,u){var o,y,t,r,v;t=0;for(r=
n.materials.length;t<r;t++){o=n.materials[t];if(o instanceof THREE.MeshFaceMaterial){o=0;for(y=l.materials.length;o<y;o++)if((v=l.materials[o])&&v.blending==i&&v.opacity<1==u){this.setBlending(v.blending);this.renderBuffer(d,h,q,v,l)}}else if((v=o)&&v.blending==i&&v.opacity<1==u){this.setBlending(v.blending);this.renderBuffer(d,h,q,v,l)}}};this.render=function(d,h){var q,n,l,i,u=d.lights,o=d.fog;this.initWebGLObjects(d);this.autoClear&&this.clear();h.autoUpdateMatrix&&h.updateMatrix();D.set(h.matrix.flatten());
A.set(h.projectionMatrix.flatten());q=0;for(n=d.__webGLObjects.length;q<n;q++){l=d.__webGLObjects[q];i=l.object;l=l.buffer;if(i.visible){this.setupMatrices(i,h);this.renderPass(h,u,o,i,l,THREE.NormalBlending,false)}}q=0;for(n=d.__webGLObjects.length;q<n;q++){l=d.__webGLObjects[q];i=l.object;l=l.buffer;if(i.visible){this.setupMatrices(i,h);this.renderPass(h,u,o,i,l,THREE.AdditiveBlending,false);this.renderPass(h,u,o,i,l,THREE.SubtractiveBlending,false);this.renderPass(h,u,o,i,l,THREE.AdditiveBlending,
true);this.renderPass(h,u,o,i,l,THREE.SubtractiveBlending,true);this.renderPass(h,u,o,i,l,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(d){function h(y,t,r,v){if(y[t]==undefined){d.__webGLObjects.push({buffer:r,object:v});y[t]=1}}var q,n,l,i,u,o;if(!d.__webGLObjects){d.__webGLObjects=[];d.__webGLObjectsMap={}}q=0;for(n=d.objects.length;q<n;q++){l=d.objects[q];if(d.__webGLObjectsMap[l.id]==undefined)d.__webGLObjectsMap[l.id]={};o=d.__webGLObjectsMap[l.id];if(l instanceof THREE.Mesh)for(i in l.geometry.geometryChunks){u=
l.geometry.geometryChunks[i];u.__webGLVertexBuffer||this.createBuffers(l,i);h(o,i,u,l)}else if(l instanceof THREE.Line){l.__webGLVertexBuffer||this.createLineBuffers(l);h(o,0,l,l)}else if(l instanceof THREE.ParticleSystem){l.__webGLVertexBuffer||this.createParticleBuffers(l);h(o,0,l,l)}}};this.removeObject=function(d,h){var q,n;for(q=d.__webGLObjects.length-1;q>=0;q--){n=d.__webGLObjects[q].object;h==n&&d.__webGLObjects.splice(q,1)}};this.setupMatrices=function(d,h){d.autoUpdateMatrix&&d.updateMatrix();
m.multiply(h.matrix,d.matrix);x.set(m.flatten());B=THREE.Matrix4.makeInvert3x3(m).transpose();M.set(B.m);Q.set(d.matrix.flatten())};this.loadMatrices=function(d){c.uniformMatrix4fv(d.uniforms.viewMatrix,false,D);c.uniformMatrix4fv(d.uniforms.modelViewMatrix,false,x);c.uniformMatrix4fv(d.uniforms.projectionMatrix,false,A);c.uniformMatrix3fv(d.uniforms.normalMatrix,false,M);c.uniformMatrix4fv(d.uniforms.objectMatrix,false,Q)};this.loadCamera=function(d,h){c.uniform3f(d.uniforms.cameraPosition,h.position.x,
h.position.y,h.position.z)};this.setBlending=function(d){switch(d){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(d,h){if(d){!h||h=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(d=="back")c.cullFace(c.BACK);else d=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)};
this.supportsVertexTextures=function(){return c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}};
THREE.Snippets={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, 1.0 ), fogFactor );\n#endif",envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube env_map;\nuniform int combine;\n#endif",
envmap_fragment:"#ifdef USE_ENVMAP\ncubeColor = textureCube( env_map, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = mix( gl_FragColor, cubeColor, reflectivity );\n} else {\ngl_FragColor = gl_FragColor * cubeColor;\n}\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refraction_ratio;\nuniform bool useRefract;\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nif ( useRefract ) {\nvReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refraction_ratio );\n} else {\nvReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );\n}\n#endif",
map_pars_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\n#endif",map_fragment:"#ifdef USE_MAP\nmapColor = texture2D( map, vUv );\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv;\n#endif",lights_pars_vertex:"uniform bool enableLighting;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n#ifdef PHONG\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\n#endif",
+94 -94
View File
@@ -12,48 +12,48 @@ THREE.Vector4=function(a,b,f,e){this.x=a||0;this.y=b||0;this.z=f||0;this.w=e||1}
THREE.Vector4.prototype={set:function(a,b,f,e){this.x=a;this.y=b;this.z=f;this.w=e;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w||1;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;
return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=a;this.w/=a;return this},lerpSelf:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},toString:function(){return"THREE.Vector4 ("+this.x+", "+this.y+", "+this.z+", "+this.w+")"}};
THREE.Ray=function(a,b){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3};
THREE.Ray.prototype={intersectScene:function(a){var b,f,e=a.objects,g=[];a=0;for(b=e.length;a<b;a++){f=e[a];if(f instanceof THREE.Mesh)g=g.concat(this.intersectObject(f))}g.sort(function(j,o){return j.distance-o.distance});return g},intersectObject:function(a){function b(O,q,L,d){d=d.clone().subSelf(q);L=L.clone().subSelf(q);var h=O.clone().subSelf(q);O=d.dot(d);q=d.dot(L);d=d.dot(h);var r=L.dot(L);L=L.dot(h);h=1/(O*r-q*q);r=(r*d-q*L)*h;O=(O*L-q*d)*h;return r>0&&O>0&&r+O<1}var f,e,g,j,o,c,k,l,B,D,
x,A=a.geometry,M=A.vertices,Q=[];f=0;for(e=A.faces.length;f<e;f++){g=A.faces[f];D=this.origin.clone();x=this.direction.clone();j=a.matrix.multiplyVector3(M[g.a].position.clone());o=a.matrix.multiplyVector3(M[g.b].position.clone());c=a.matrix.multiplyVector3(M[g.c].position.clone());k=g instanceof THREE.Face4?a.matrix.multiplyVector3(M[g.d].position.clone()):null;l=a.rotationMatrix.multiplyVector3(g.normal.clone());B=x.dot(l);if(B<0){l=l.dot((new THREE.Vector3).sub(j,D))/B;D=D.addSelf(x.multiplyScalar(l));
if(g instanceof THREE.Face3){if(b(D,j,o,c)){g={distance:this.origin.distanceTo(D),point:D,face:g,object:a};Q.push(g)}}else if(g instanceof THREE.Face4)if(b(D,j,o,k)||b(D,o,c,k)){g={distance:this.origin.distanceTo(D),point:D,face:g,object:a};Q.push(g)}}}return Q}};
THREE.Rectangle=function(){function a(){j=e-b;o=g-f}var b,f,e,g,j,o,c=true;this.getX=function(){return b};this.getY=function(){return f};this.getWidth=function(){return j};this.getHeight=function(){return o};this.getLeft=function(){return b};this.getTop=function(){return f};this.getRight=function(){return e};this.getBottom=function(){return g};this.set=function(k,l,B,D){c=false;b=k;f=l;e=B;g=D;a()};this.addPoint=function(k,l){if(c){c=false;b=k;f=l;e=k;g=l}else{b=b<k?b:k;f=f<l?f:l;e=e>k?e:k;g=g>l?
g:l}a()};this.add3Points=function(k,l,B,D,x,A){if(c){c=false;b=k<B?k<x?k:x:B<x?B:x;f=l<D?l<A?l:A:D<A?D:A;e=k>B?k>x?k:x:B>x?B:x;g=l>D?l>A?l:A:D>A?D:A}else{b=k<B?k<x?k<b?k:b:x<b?x:b:B<x?B<b?B:b:x<b?x:b;f=l<D?l<A?l<f?l:f:A<f?A:f:D<A?D<f?D:f:A<f?A:f;e=k>B?k>x?k>e?k:e:x>e?x:e:B>x?B>e?B:e:x>e?x:e;g=l>D?l>A?l>g?l:g:A>g?A:g:D>A?D>g?D:g:A>g?A:g}a()};this.addRectangle=function(k){if(c){c=false;b=k.getLeft();f=k.getTop();e=k.getRight();g=k.getBottom()}else{b=b<k.getLeft()?b:k.getLeft();f=f<k.getTop()?f:k.getTop();
THREE.Ray.prototype={intersectScene:function(a){var b,f,e=a.objects,g=[];a=0;for(b=e.length;a<b;a++){f=e[a];if(f instanceof THREE.Mesh)g=g.concat(this.intersectObject(f))}g.sort(function(j,p){return j.distance-p.distance});return g},intersectObject:function(a){function b(O,s,L,d){d=d.clone().subSelf(s);L=L.clone().subSelf(s);var h=O.clone().subSelf(s);O=d.dot(d);s=d.dot(L);d=d.dot(h);var q=L.dot(L);L=L.dot(h);h=1/(O*q-s*s);q=(q*d-s*L)*h;O=(O*L-s*d)*h;return q>0&&O>0&&q+O<1}var f,e,g,j,p,c,k,m,B,D,
x,A=a.geometry,M=A.vertices,Q=[];f=0;for(e=A.faces.length;f<e;f++){g=A.faces[f];D=this.origin.clone();x=this.direction.clone();j=a.matrix.multiplyVector3(M[g.a].position.clone());p=a.matrix.multiplyVector3(M[g.b].position.clone());c=a.matrix.multiplyVector3(M[g.c].position.clone());k=g instanceof THREE.Face4?a.matrix.multiplyVector3(M[g.d].position.clone()):null;m=a.rotationMatrix.multiplyVector3(g.normal.clone());B=x.dot(m);if(B<0){m=m.dot((new THREE.Vector3).sub(j,D))/B;D=D.addSelf(x.multiplyScalar(m));
if(g instanceof THREE.Face3){if(b(D,j,p,c)){g={distance:this.origin.distanceTo(D),point:D,face:g,object:a};Q.push(g)}}else if(g instanceof THREE.Face4)if(b(D,j,p,k)||b(D,p,c,k)){g={distance:this.origin.distanceTo(D),point:D,face:g,object:a};Q.push(g)}}}return Q}};
THREE.Rectangle=function(){function a(){j=e-b;p=g-f}var b,f,e,g,j,p,c=true;this.getX=function(){return b};this.getY=function(){return f};this.getWidth=function(){return j};this.getHeight=function(){return p};this.getLeft=function(){return b};this.getTop=function(){return f};this.getRight=function(){return e};this.getBottom=function(){return g};this.set=function(k,m,B,D){c=false;b=k;f=m;e=B;g=D;a()};this.addPoint=function(k,m){if(c){c=false;b=k;f=m;e=k;g=m}else{b=b<k?b:k;f=f<m?f:m;e=e>k?e:k;g=g>m?
g:m}a()};this.add3Points=function(k,m,B,D,x,A){if(c){c=false;b=k<B?k<x?k:x:B<x?B:x;f=m<D?m<A?m:A:D<A?D:A;e=k>B?k>x?k:x:B>x?B:x;g=m>D?m>A?m:A:D>A?D:A}else{b=k<B?k<x?k<b?k:b:x<b?x:b:B<x?B<b?B:b:x<b?x:b;f=m<D?m<A?m<f?m:f:A<f?A:f:D<A?D<f?D:f:A<f?A:f;e=k>B?k>x?k>e?k:e:x>e?x:e:B>x?B>e?B:e:x>e?x:e;g=m>D?m>A?m>g?m:g:A>g?A:g:D>A?D>g?D:g:A>g?A:g}a()};this.addRectangle=function(k){if(c){c=false;b=k.getLeft();f=k.getTop();e=k.getRight();g=k.getBottom()}else{b=b<k.getLeft()?b:k.getLeft();f=f<k.getTop()?f:k.getTop();
e=e>k.getRight()?e:k.getRight();g=g>k.getBottom()?g:k.getBottom()}a()};this.inflate=function(k){b-=k;f-=k;e+=k;g+=k;a()};this.minSelf=function(k){b=b>k.getLeft()?b:k.getLeft();f=f>k.getTop()?f:k.getTop();e=e<k.getRight()?e:k.getRight();g=g<k.getBottom()?g:k.getBottom();a()};this.instersects=function(k){return Math.min(e,k.getRight())-Math.max(b,k.getLeft())>=0&&Math.min(g,k.getBottom())-Math.max(f,k.getTop())>=0};this.empty=function(){c=true;g=e=f=b=0;a()};this.isEmpty=function(){return c};this.toString=
function(){return"THREE.Rectangle ( left: "+b+", right: "+e+", top: "+f+", bottom: "+g+", width: "+j+", height: "+o+" )"}};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(a,b,f,e,g,j,o,c,k,l,B,D,x,A,M,Q){this.n11=a||1;this.n12=b||0;this.n13=f||0;this.n14=e||0;this.n21=g||0;this.n22=j||1;this.n23=o||0;this.n24=c||0;this.n31=k||0;this.n32=l||0;this.n33=B||1;this.n34=D||0;this.n41=x||0;this.n42=A||0;this.n43=M||0;this.n44=Q||1};
THREE.Matrix4.prototype={identity:function(){this.n11=1;this.n21=this.n14=this.n13=this.n12=0;this.n22=1;this.n32=this.n31=this.n24=this.n23=0;this.n33=1;this.n43=this.n42=this.n41=this.n34=0;this.n44=1;return this},set:function(a,b,f,e,g,j,o,c,k,l,B,D,x,A,M,Q){this.n11=a;this.n12=b;this.n13=f;this.n14=e;this.n21=g;this.n22=j;this.n23=o;this.n24=c;this.n31=k;this.n32=l;this.n33=B;this.n34=D;this.n41=x;this.n42=A;this.n43=M;this.n44=Q;return this},copy:function(a){this.n11=a.n11;this.n12=a.n12;this.n13=
function(){return"THREE.Rectangle ( left: "+b+", right: "+e+", top: "+f+", bottom: "+g+", width: "+j+", height: "+p+" )"}};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(a,b,f,e,g,j,p,c,k,m,B,D,x,A,M,Q){this.n11=a||1;this.n12=b||0;this.n13=f||0;this.n14=e||0;this.n21=g||0;this.n22=j||1;this.n23=p||0;this.n24=c||0;this.n31=k||0;this.n32=m||0;this.n33=B||1;this.n34=D||0;this.n41=x||0;this.n42=A||0;this.n43=M||0;this.n44=Q||1};
THREE.Matrix4.prototype={identity:function(){this.n11=1;this.n21=this.n14=this.n13=this.n12=0;this.n22=1;this.n32=this.n31=this.n24=this.n23=0;this.n33=1;this.n43=this.n42=this.n41=this.n34=0;this.n44=1;return this},set:function(a,b,f,e,g,j,p,c,k,m,B,D,x,A,M,Q){this.n11=a;this.n12=b;this.n13=f;this.n14=e;this.n21=g;this.n22=j;this.n23=p;this.n24=c;this.n31=k;this.n32=m;this.n33=B;this.n34=D;this.n41=x;this.n42=A;this.n43=M;this.n44=Q;return this},copy:function(a){this.n11=a.n11;this.n12=a.n12;this.n13=
a.n13;this.n14=a.n14;this.n21=a.n21;this.n22=a.n22;this.n23=a.n23;this.n24=a.n24;this.n31=a.n31;this.n32=a.n32;this.n33=a.n33;this.n34=a.n34;this.n41=a.n41;this.n42=a.n42;this.n43=a.n43;this.n44=a.n44;return this},lookAt:function(a,b,f){var e=new THREE.Vector3,g=new THREE.Vector3,j=new THREE.Vector3;j.sub(a,b).normalize();e.cross(f,j).normalize();g.cross(j,e).normalize();this.n11=e.x;this.n12=e.y;this.n13=e.z;this.n14=-e.dot(a);this.n21=g.x;this.n22=g.y;this.n23=g.z;this.n24=-g.dot(a);this.n31=j.x;
this.n32=j.y;this.n33=j.z;this.n34=-j.dot(a);this.n43=this.n42=this.n41=0;this.n44=1;return this},multiplyVector3:function(a){var b=a.x,f=a.y,e=a.z,g=1/(this.n41*b+this.n42*f+this.n43*e+this.n44);a.x=(this.n11*b+this.n12*f+this.n13*e+this.n14)*g;a.y=(this.n21*b+this.n22*f+this.n23*e+this.n24)*g;a.z=(this.n31*b+this.n32*f+this.n33*e+this.n34)*g;return a},multiplyVector4:function(a){var b=a.x,f=a.y,e=a.z,g=a.w;a.x=this.n11*b+this.n12*f+this.n13*e+this.n14*g;a.y=this.n21*b+this.n22*f+this.n23*e+this.n24*
g;a.z=this.n31*b+this.n32*f+this.n33*e+this.n34*g;a.w=this.n41*b+this.n42*f+this.n43*e+this.n44*g;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 f=a.n11,e=a.n12,g=a.n13,j=a.n14,o=a.n21,c=a.n22,k=a.n23,l=a.n24,B=a.n31,D=a.n32,
x=a.n33,A=a.n34,M=a.n41,Q=a.n42,O=a.n43,q=a.n44,L=b.n11,d=b.n12,h=b.n13,r=b.n14,m=b.n21,n=b.n22,i=b.n23,t=b.n24,p=b.n31,y=b.n32,u=b.n33,s=b.n34,w=b.n41,W=b.n42,G=b.n43,T=b.n44;this.n11=f*L+e*m+g*p+j*w;this.n12=f*d+e*n+g*y+j*W;this.n13=f*h+e*i+g*u+j*G;this.n14=f*r+e*t+g*s+j*T;this.n21=o*L+c*m+k*p+l*w;this.n22=o*d+c*n+k*y+l*W;this.n23=o*h+c*i+k*u+l*G;this.n24=o*r+c*t+k*s+l*T;this.n31=B*L+D*m+x*p+A*w;this.n32=B*d+D*n+x*y+A*W;this.n33=B*h+D*i+x*u+A*G;this.n34=B*r+D*t+x*s+A*T;this.n41=M*L+Q*m+O*p+q*w;
this.n42=M*d+Q*n+O*y+q*W;this.n43=M*h+Q*i+O*u+q*G;this.n44=M*r+Q*t+O*s+q*T;return this},multiplySelf:function(a){var b=this.n11,f=this.n12,e=this.n13,g=this.n14,j=this.n21,o=this.n22,c=this.n23,k=this.n24,l=this.n31,B=this.n32,D=this.n33,x=this.n34,A=this.n41,M=this.n42,Q=this.n43,O=this.n44,q=a.n11,L=a.n21,d=a.n31,h=a.n41,r=a.n12,m=a.n22,n=a.n32,i=a.n42,t=a.n13,p=a.n23,y=a.n33,u=a.n43,s=a.n14,w=a.n24,W=a.n34;a=a.n44;this.n11=b*q+f*L+e*d+g*h;this.n12=b*r+f*m+e*n+g*i;this.n13=b*t+f*p+e*y+g*u;this.n14=
b*s+f*w+e*W+g*a;this.n21=j*q+o*L+c*d+k*h;this.n22=j*r+o*m+c*n+k*i;this.n23=j*t+o*p+c*y+k*u;this.n24=j*s+o*w+c*W+k*a;this.n31=l*q+B*L+D*d+x*h;this.n32=l*r+B*m+D*n+x*i;this.n33=l*t+B*p+D*y+x*u;this.n34=l*s+B*w+D*W+x*a;this.n41=A*q+M*L+Q*d+O*h;this.n42=A*r+M*m+Q*n+O*i;this.n43=A*t+M*p+Q*y+O*u;this.n44=A*s+M*w+Q*W+O*a;return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=
g;a.z=this.n31*b+this.n32*f+this.n33*e+this.n34*g;a.w=this.n41*b+this.n42*f+this.n43*e+this.n44*g;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 f=a.n11,e=a.n12,g=a.n13,j=a.n14,p=a.n21,c=a.n22,k=a.n23,m=a.n24,B=a.n31,D=a.n32,
x=a.n33,A=a.n34,M=a.n41,Q=a.n42,O=a.n43,s=a.n44,L=b.n11,d=b.n12,h=b.n13,q=b.n14,n=b.n21,l=b.n22,i=b.n23,u=b.n24,o=b.n31,y=b.n32,t=b.n33,r=b.n34,w=b.n41,W=b.n42,G=b.n43,T=b.n44;this.n11=f*L+e*n+g*o+j*w;this.n12=f*d+e*l+g*y+j*W;this.n13=f*h+e*i+g*t+j*G;this.n14=f*q+e*u+g*r+j*T;this.n21=p*L+c*n+k*o+m*w;this.n22=p*d+c*l+k*y+m*W;this.n23=p*h+c*i+k*t+m*G;this.n24=p*q+c*u+k*r+m*T;this.n31=B*L+D*n+x*o+A*w;this.n32=B*d+D*l+x*y+A*W;this.n33=B*h+D*i+x*t+A*G;this.n34=B*q+D*u+x*r+A*T;this.n41=M*L+Q*n+O*o+s*w;
this.n42=M*d+Q*l+O*y+s*W;this.n43=M*h+Q*i+O*t+s*G;this.n44=M*q+Q*u+O*r+s*T;return this},multiplySelf:function(a){var b=this.n11,f=this.n12,e=this.n13,g=this.n14,j=this.n21,p=this.n22,c=this.n23,k=this.n24,m=this.n31,B=this.n32,D=this.n33,x=this.n34,A=this.n41,M=this.n42,Q=this.n43,O=this.n44,s=a.n11,L=a.n21,d=a.n31,h=a.n41,q=a.n12,n=a.n22,l=a.n32,i=a.n42,u=a.n13,o=a.n23,y=a.n33,t=a.n43,r=a.n14,w=a.n24,W=a.n34;a=a.n44;this.n11=b*s+f*L+e*d+g*h;this.n12=b*q+f*n+e*l+g*i;this.n13=b*u+f*o+e*y+g*t;this.n14=
b*r+f*w+e*W+g*a;this.n21=j*s+p*L+c*d+k*h;this.n22=j*q+p*n+c*l+k*i;this.n23=j*u+p*o+c*y+k*t;this.n24=j*r+p*w+c*W+k*a;this.n31=m*s+B*L+D*d+x*h;this.n32=m*q+B*n+D*l+x*i;this.n33=m*u+B*o+D*y+x*t;this.n34=m*r+B*w+D*W+x*a;this.n41=A*s+M*L+Q*d+O*h;this.n42=A*q+M*n+Q*l+O*i;this.n43=A*u+M*o+Q*y+O*t;this.n44=A*r+M*w+Q*W+O*a;return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=
a;this.n42*=a;this.n43*=a;this.n44*=a;return this},determinant:function(){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,f,e){var g=b[f];b[f]=b[e];
b[e]=g}a(this,"n21","n12");a(this,"n31","n13");a(this,"n32","n23");a(this,"n41","n14");a(this,"n42","n24");a(this,"n43","n34");return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=this.n44;return a},flatten:function(){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,f){var e=new THREE.Matrix4;e.n14=a;e.n24=b;e.n34=f;return e};
THREE.Matrix4.scaleMatrix=function(a,b,f){var e=new THREE.Matrix4;e.n11=a;e.n22=b;e.n33=f;return e};THREE.Matrix4.rotationXMatrix=function(a){var b=new THREE.Matrix4;b.n22=b.n33=Math.cos(a);b.n32=Math.sin(a);b.n23=-b.n32;return b};THREE.Matrix4.rotationYMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n33=Math.cos(a);b.n13=Math.sin(a);b.n31=-b.n13;return b};THREE.Matrix4.rotationZMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n22=Math.cos(a);b.n21=Math.sin(a);b.n12=-b.n21;return b};
THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var f=new THREE.Matrix4,e=Math.cos(b),g=Math.sin(b),j=1-e,o=a.x,c=a.y,k=a.z;f.n11=j*o*o+e;f.n12=j*o*c-g*k;f.n13=j*o*k+g*c;f.n21=j*o*c+g*k;f.n22=j*c*c+e;f.n23=j*c*k-g*o;f.n31=j*o*k-g*c;f.n32=j*c*k+g*o;f.n33=j*k*k+e;return f};
THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var f=new THREE.Matrix4,e=Math.cos(b),g=Math.sin(b),j=1-e,p=a.x,c=a.y,k=a.z;f.n11=j*p*p+e;f.n12=j*p*c-g*k;f.n13=j*p*k+g*c;f.n21=j*p*c+g*k;f.n22=j*c*c+e;f.n23=j*c*k-g*p;f.n31=j*p*k-g*c;f.n32=j*c*k+g*p;f.n33=j*k*k+e;return f};
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 f=b[10]*b[5]-b[6]*b[9],e=-b[10]*b[1]+b[2]*b[9],g=b[6]*b[1]-b[2]*b[5],j=-b[10]*b[4]+b[6]*b[8],o=b[10]*b[0]-b[2]*b[8],c=-b[6]*b[0]+b[2]*b[4],k=b[9]*b[4]-b[5]*b[8],l=-b[9]*b[0]+b[1]*b[8],B=b[5]*b[0]-b[1]*b[4];b=b[0]*f+b[1]*j+b[2]*k;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*f;a.m[1]=b*e;a.m[2]=b*g;a.m[3]=b*j;a.m[4]=b*o;a.m[5]=b*c;a.m[6]=b*k;a.m[7]=b*l;a.m[8]=b*B;return a};
THREE.Matrix4.makeFrustum=function(a,b,f,e,g,j){var o,c,k;o=new THREE.Matrix4;c=2*g/(b-a);k=2*g/(e-f);a=(b+a)/(b-a);f=(e+f)/(e-f);e=-(j+g)/(j-g);g=-2*j*g/(j-g);o.n11=c;o.n12=0;o.n13=a;o.n14=0;o.n21=0;o.n22=k;o.n23=f;o.n24=0;o.n31=0;o.n32=0;o.n33=e;o.n34=g;o.n41=0;o.n42=0;o.n43=-1;o.n44=0;return o};THREE.Matrix4.makePerspective=function(a,b,f,e){var g;a=f*Math.tan(a*Math.PI/360);g=-a;return THREE.Matrix4.makeFrustum(g*b,a*b,g,a,f,e)};
THREE.Matrix4.makeOrtho=function(a,b,f,e,g,j){var o,c,k,l;o=new THREE.Matrix4;c=b-a;k=f-e;l=j-g;a=(b+a)/c;f=(f+e)/k;g=(j+g)/l;o.n11=2/c;o.n12=0;o.n13=0;o.n14=-a;o.n21=0;o.n22=2/k;o.n23=0;o.n24=-f;o.n31=0;o.n32=0;o.n33=-2/l;o.n34=-g;o.n41=0;o.n42=0;o.n43=0;o.n44=1;return o};
THREE.Matrix4.makeInvert3x3=function(a){var b=a.flatten();a=new THREE.Matrix3;var f=b[10]*b[5]-b[6]*b[9],e=-b[10]*b[1]+b[2]*b[9],g=b[6]*b[1]-b[2]*b[5],j=-b[10]*b[4]+b[6]*b[8],p=b[10]*b[0]-b[2]*b[8],c=-b[6]*b[0]+b[2]*b[4],k=b[9]*b[4]-b[5]*b[8],m=-b[9]*b[0]+b[1]*b[8],B=b[5]*b[0]-b[1]*b[4];b=b[0]*f+b[1]*j+b[2]*k;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*f;a.m[1]=b*e;a.m[2]=b*g;a.m[3]=b*j;a.m[4]=b*p;a.m[5]=b*c;a.m[6]=b*k;a.m[7]=b*m;a.m[8]=b*B;return a};
THREE.Matrix4.makeFrustum=function(a,b,f,e,g,j){var p,c,k;p=new THREE.Matrix4;c=2*g/(b-a);k=2*g/(e-f);a=(b+a)/(b-a);f=(e+f)/(e-f);e=-(j+g)/(j-g);g=-2*j*g/(j-g);p.n11=c;p.n12=0;p.n13=a;p.n14=0;p.n21=0;p.n22=k;p.n23=f;p.n24=0;p.n31=0;p.n32=0;p.n33=e;p.n34=g;p.n41=0;p.n42=0;p.n43=-1;p.n44=0;return p};THREE.Matrix4.makePerspective=function(a,b,f,e){var g;a=f*Math.tan(a*Math.PI/360);g=-a;return THREE.Matrix4.makeFrustum(g*b,a*b,g,a,f,e)};
THREE.Matrix4.makeOrtho=function(a,b,f,e,g,j){var p,c,k,m;p=new THREE.Matrix4;c=b-a;k=f-e;m=j-g;a=(b+a)/c;f=(f+e)/k;g=(j+g)/m;p.n11=2/c;p.n12=0;p.n13=0;p.n14=-a;p.n21=0;p.n22=2/k;p.n23=0;p.n24=-f;p.n31=0;p.n32=0;p.n33=-2/m;p.n34=-g;p.n41=0;p.n42=0;p.n43=0;p.n44=1;return p};
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,f,e,g){this.a=a;this.b=b;this.c=f;this.centroid=new THREE.Vector3;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.materials=g instanceof Array?g:[g]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
THREE.Face4=function(a,b,f,e,g,j){this.a=a;this.b=b;this.c=f;this.d=e;this.centroid=new THREE.Vector3;this.normal=g instanceof THREE.Vector3?g:new THREE.Vector3;this.vertexNormals=g instanceof Array?g:[];this.materials=j instanceof Array?j:[j]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
THREE.UV.prototype={copy:function(a){this.u=a.u;this.v=a.v},toString:function(){return"THREE.UV ("+this.u+", "+this.v+")"}};THREE.Geometry=function(){this.vertices=[];this.faces=[];this.uvs=[];this.boundingSphere=this.boundingBox=null;this.geometryChunks={};this.hasTangents=false};
THREE.Geometry.prototype={computeCentroids:function(){var a,b,f;a=0;for(b=this.faces.length;a<b;a++){f=this.faces[a];f.centroid.set(0,0,0);if(f instanceof THREE.Face3){f.centroid.addSelf(this.vertices[f.a].position);f.centroid.addSelf(this.vertices[f.b].position);f.centroid.addSelf(this.vertices[f.c].position);f.centroid.divideScalar(3)}else if(f instanceof THREE.Face4){f.centroid.addSelf(this.vertices[f.a].position);f.centroid.addSelf(this.vertices[f.b].position);f.centroid.addSelf(this.vertices[f.c].position);
f.centroid.addSelf(this.vertices[f.d].position);f.centroid.divideScalar(4)}}},computeFaceNormals:function(a){var b,f,e,g,j,o,c=new THREE.Vector3,k=new THREE.Vector3;e=0;for(g=this.vertices.length;e<g;e++){j=this.vertices[e];j.normal.set(0,0,0)}e=0;for(g=this.faces.length;e<g;e++){j=this.faces[e];if(a&&j.vertexNormals.length){c.set(0,0,0);b=0;for(f=j.normal.length;b<f;b++)c.addSelf(j.vertexNormals[b]);c.divideScalar(3)}else{b=this.vertices[j.a];f=this.vertices[j.b];o=this.vertices[j.c];c.sub(o.position,
f.centroid.addSelf(this.vertices[f.d].position);f.centroid.divideScalar(4)}}},computeFaceNormals:function(a){var b,f,e,g,j,p,c=new THREE.Vector3,k=new THREE.Vector3;e=0;for(g=this.vertices.length;e<g;e++){j=this.vertices[e];j.normal.set(0,0,0)}e=0;for(g=this.faces.length;e<g;e++){j=this.faces[e];if(a&&j.vertexNormals.length){c.set(0,0,0);b=0;for(f=j.normal.length;b<f;b++)c.addSelf(j.vertexNormals[b]);c.divideScalar(3)}else{b=this.vertices[j.a];f=this.vertices[j.b];p=this.vertices[j.c];c.sub(p.position,
f.position);k.sub(b.position,f.position);c.crossSelf(k)}c.isZero()||c.normalize();j.normal.copy(c)}},computeVertexNormals:function(){var a,b,f=[],e;a=0;for(b=this.vertices.length;a<b;a++)f[a]=new THREE.Vector3;a=0;for(b=this.faces.length;a<b;a++){e=this.faces[a];if(e instanceof THREE.Face3){f[e.a].addSelf(e.normal);f[e.b].addSelf(e.normal);f[e.c].addSelf(e.normal)}else if(e instanceof THREE.Face4){f[e.a].addSelf(e.normal);f[e.b].addSelf(e.normal);f[e.c].addSelf(e.normal);f[e.d].addSelf(e.normal)}}a=
0;for(b=this.vertices.length;a<b;a++)f[a].normalize();a=0;for(b=this.faces.length;a<b;a++){e=this.faces[a];if(e instanceof THREE.Face3){e.vertexNormals[0]=f[e.a].clone();e.vertexNormals[1]=f[e.b].clone();e.vertexNormals[2]=f[e.c].clone()}else if(e instanceof THREE.Face4){e.vertexNormals[0]=f[e.a].clone();e.vertexNormals[1]=f[e.b].clone();e.vertexNormals[2]=f[e.c].clone();e.vertexNormals[3]=f[e.d].clone()}}},computeTangents:function(){function a(s,w,W,G,T,P,H){j=s.vertices[w].position;o=s.vertices[W].position;
c=s.vertices[G].position;k=g[T];l=g[P];B=g[H];D=o.x-j.x;x=c.x-j.x;A=o.y-j.y;M=c.y-j.y;Q=o.z-j.z;O=c.z-j.z;q=l.u-k.u;L=B.u-k.u;d=l.v-k.v;h=B.v-k.v;r=1/(q*h-L*d);i.set((h*D-d*x)*r,(h*A-d*M)*r,(h*Q-d*O)*r);t.set((q*x-L*D)*r,(q*M-L*A)*r,(q*O-L*Q)*r);m[w].addSelf(i);m[W].addSelf(i);m[G].addSelf(i);n[w].addSelf(t);n[W].addSelf(t);n[G].addSelf(t)}var b,f,e,g,j,o,c,k,l,B,D,x,A,M,Q,O,q,L,d,h,r,m=[],n=[],i=new THREE.Vector3,t=new THREE.Vector3,p=new THREE.Vector3,y=new THREE.Vector3,u=new THREE.Vector3;b=0;
for(f=this.vertices.length;b<f;b++){m[b]=new THREE.Vector3;n[b]=new THREE.Vector3}b=0;for(f=this.faces.length;b<f;b++){e=this.faces[b];g=this.uvs[b];if(e instanceof THREE.Face3){a(this,e.a,e.b,e.c,0,1,2);this.vertices[e.a].normal.copy(e.vertexNormals[0]);this.vertices[e.b].normal.copy(e.vertexNormals[1]);this.vertices[e.c].normal.copy(e.vertexNormals[2])}else if(e instanceof THREE.Face4){a(this,e.a,e.b,e.c,0,1,2);a(this,e.a,e.b,e.d,0,1,3);this.vertices[e.a].normal.copy(e.vertexNormals[0]);this.vertices[e.b].normal.copy(e.vertexNormals[1]);
this.vertices[e.c].normal.copy(e.vertexNormals[2]);this.vertices[e.d].normal.copy(e.vertexNormals[3])}}b=0;for(f=this.vertices.length;b<f;b++){u.copy(this.vertices[b].normal);e=m[b];p.copy(e);p.subSelf(u.multiplyScalar(u.dot(e))).normalize();y.cross(this.vertices[b].normal,e);e=y.dot(n[b]);e=e<0?-1:1;this.vertices[b].tangent.set(p.x,p.y,p.z,e)}this.hasTangents=true},computeBoundingBox:function(){var a;if(this.vertices.length>0){this.boundingBox={x:[this.vertices[0].position.x,this.vertices[0].position.x],
0;for(b=this.vertices.length;a<b;a++)f[a].normalize();a=0;for(b=this.faces.length;a<b;a++){e=this.faces[a];if(e instanceof THREE.Face3){e.vertexNormals[0]=f[e.a].clone();e.vertexNormals[1]=f[e.b].clone();e.vertexNormals[2]=f[e.c].clone()}else if(e instanceof THREE.Face4){e.vertexNormals[0]=f[e.a].clone();e.vertexNormals[1]=f[e.b].clone();e.vertexNormals[2]=f[e.c].clone();e.vertexNormals[3]=f[e.d].clone()}}},computeTangents:function(){function a(r,w,W,G,T,P,H){j=r.vertices[w].position;p=r.vertices[W].position;
c=r.vertices[G].position;k=g[T];m=g[P];B=g[H];D=p.x-j.x;x=c.x-j.x;A=p.y-j.y;M=c.y-j.y;Q=p.z-j.z;O=c.z-j.z;s=m.u-k.u;L=B.u-k.u;d=m.v-k.v;h=B.v-k.v;q=1/(s*h-L*d);i.set((h*D-d*x)*q,(h*A-d*M)*q,(h*Q-d*O)*q);u.set((s*x-L*D)*q,(s*M-L*A)*q,(s*O-L*Q)*q);n[w].addSelf(i);n[W].addSelf(i);n[G].addSelf(i);l[w].addSelf(u);l[W].addSelf(u);l[G].addSelf(u)}var b,f,e,g,j,p,c,k,m,B,D,x,A,M,Q,O,s,L,d,h,q,n=[],l=[],i=new THREE.Vector3,u=new THREE.Vector3,o=new THREE.Vector3,y=new THREE.Vector3,t=new THREE.Vector3;b=0;
for(f=this.vertices.length;b<f;b++){n[b]=new THREE.Vector3;l[b]=new THREE.Vector3}b=0;for(f=this.faces.length;b<f;b++){e=this.faces[b];g=this.uvs[b];if(e instanceof THREE.Face3){a(this,e.a,e.b,e.c,0,1,2);this.vertices[e.a].normal.copy(e.vertexNormals[0]);this.vertices[e.b].normal.copy(e.vertexNormals[1]);this.vertices[e.c].normal.copy(e.vertexNormals[2])}else if(e instanceof THREE.Face4){a(this,e.a,e.b,e.c,0,1,2);a(this,e.a,e.b,e.d,0,1,3);this.vertices[e.a].normal.copy(e.vertexNormals[0]);this.vertices[e.b].normal.copy(e.vertexNormals[1]);
this.vertices[e.c].normal.copy(e.vertexNormals[2]);this.vertices[e.d].normal.copy(e.vertexNormals[3])}}b=0;for(f=this.vertices.length;b<f;b++){t.copy(this.vertices[b].normal);e=n[b];o.copy(e);o.subSelf(t.multiplyScalar(t.dot(e))).normalize();y.cross(this.vertices[b].normal,e);e=y.dot(l[b]);e=e<0?-1:1;this.vertices[b].tangent.set(o.x,o.y,o.z,e)}this.hasTangents=true},computeBoundingBox:function(){var a;if(this.vertices.length>0){this.boundingBox={x:[this.vertices[0].position.x,this.vertices[0].position.x],
y:[this.vertices[0].position.y,this.vertices[0].position.y],z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var b=1,f=this.vertices.length;b<f;b++){a=this.vertices[b];if(a.position.x<this.boundingBox.x[0])this.boundingBox.x[0]=a.position.x;else if(a.position.x>this.boundingBox.x[1])this.boundingBox.x[1]=a.position.x;if(a.position.y<this.boundingBox.y[0])this.boundingBox.y[0]=a.position.y;else if(a.position.y>this.boundingBox.y[1])this.boundingBox.y[1]=a.position.y;if(a.position.z<
this.boundingBox.z[0])this.boundingBox.z[0]=a.position.z;else if(a.position.z>this.boundingBox.z[1])this.boundingBox.z[1]=a.position.z}}},computeBoundingSphere:function(){for(var a=this.boundingSphere===null?0:this.boundingSphere.radius,b=0,f=this.vertices.length;b<f;b++)a=Math.max(a,this.vertices[b].position.length());this.boundingSphere={radius:a}},sortFacesByMaterial:function(){function a(B){var D=[];b=0;for(f=B.length;b<f;b++)B[b]==undefined?D.push("undefined"):D.push(B[b].toString());return D.join("_")}
var b,f,e,g,j,o,c,k,l={};e=0;for(g=this.faces.length;e<g;e++){j=this.faces[e];o=j.materials;c=a(o);if(l[c]==undefined)l[c]={hash:c,counter:0};k=l[c].hash+"_"+l[c].counter;if(this.geometryChunks[k]==undefined)this.geometryChunks[k]={faces:[],materials:o,vertices:0};j=j instanceof THREE.Face3?3:4;if(this.geometryChunks[k].vertices+j>65535){l[c].counter+=1;k=l[c].hash+"_"+l[c].counter;if(this.geometryChunks[k]==undefined)this.geometryChunks[k]={faces:[],materials:o,vertices:0}}this.geometryChunks[k].faces.push(e);
var b,f,e,g,j,p,c,k,m={};e=0;for(g=this.faces.length;e<g;e++){j=this.faces[e];p=j.materials;c=a(p);if(m[c]==undefined)m[c]={hash:c,counter:0};k=m[c].hash+"_"+m[c].counter;if(this.geometryChunks[k]==undefined)this.geometryChunks[k]={faces:[],materials:p,vertices:0};j=j instanceof THREE.Face3?3:4;if(this.geometryChunks[k].vertices+j>65535){m[c].counter+=1;k=m[c].hash+"_"+m[c].counter;if(this.geometryChunks[k]==undefined)this.geometryChunks[k]={faces:[],materials:p,vertices:0}}this.geometryChunks[k].faces.push(e);
this.geometryChunks[k].vertices+=j}},toString:function(){return"THREE.Geometry ( vertices: "+this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
THREE.Camera=function(a,b,f,e){this.fov=a;this.aspect=b;this.near=f;this.far=e;this.position=new THREE.Vector3;this.target={position:new THREE.Vector3};this.autoUpdateMatrix=true;this.projectionMatrix=null;this.matrix=new THREE.Matrix4;this.up=new THREE.Vector3(0,1,0);this.translateX=function(g){g=this.target.position.clone().subSelf(this.position).normalize().multiplyScalar(g);g.cross(g.clone(),this.up);this.position.addSelf(g);this.target.position.addSelf(g)};this.translateZ=function(g){g=this.target.position.clone().subSelf(this.position).normalize().multiplyScalar(g);
this.position.subSelf(g);this.target.position.subSelf(g)};this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.updateProjectionMatrix=function(){this.projectionMatrix=THREE.Matrix4.makePerspective(this.fov,this.aspect,this.near,this.far)};this.updateProjectionMatrix()};THREE.Camera.prototype={toString:function(){return"THREE.Camera ( "+this.position+", "+this.target.position+" )"}};THREE.Light=function(a){this.color=new THREE.Color(a)};
@@ -96,86 +96,86 @@ THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLine
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.fog=null;this.addObject=function(a){this.objects.indexOf(a)===-1&&this.objects.push(a)};this.removeObject=function(a){a=this.objects.indexOf(a);a!==-1&&this.objects.splice(a,1)};this.addLight=function(a){this.lights.indexOf(a)===-1&&this.lights.push(a)};this.removeLight=function(a){a=this.lights.indexOf(a);a!==-1&&this.lights.splice(a,1)};this.toString=function(){return"THREE.Scene ( "+this.objects+" )"}};
THREE.Fog=function(a,b,f){this.color=new THREE.Color(a);this.near=b||1;this.far=f||1E3};THREE.FogExp2=function(a,b){this.color=new THREE.Color(a);this.density=b||2.5E-4};
THREE.Projector=function(){function a(n,i){return i.z-n.z}function b(n,i){var t=0,p=1,y=n.z+n.w,u=i.z+i.w,s=-n.z+n.w,w=-i.z+i.w;if(y>=0&&u>=0&&s>=0&&w>=0)return true;else if(y<0&&u<0||s<0&&w<0)return false;else{if(y<0)t=Math.max(t,y/(y-u));else if(u<0)p=Math.min(p,y/(y-u));if(s<0)t=Math.max(t,s/(s-w));else if(w<0)p=Math.min(p,s/(s-w));if(p<t)return false;else{n.lerpSelf(i,t);i.lerpSelf(n,1-p);return true}}}var f,e,g=[],j,o,c,k=[],l,B,D=[],x,A,M=[],Q=new THREE.Vector4,O=new THREE.Vector4,q=new THREE.Matrix4,
L=new THREE.Matrix4,d=[],h=new THREE.Vector4,r=new THREE.Vector4,m;this.projectObjects=function(n,i,t){var p=[],y,u;e=0;q.multiply(i.projectionMatrix,i.matrix);d[0]=new THREE.Vector4(q.n41-q.n11,q.n42-q.n12,q.n43-q.n13,q.n44-q.n14);d[1]=new THREE.Vector4(q.n41+q.n11,q.n42+q.n12,q.n43+q.n13,q.n44+q.n14);d[2]=new THREE.Vector4(q.n41+q.n21,q.n42+q.n22,q.n43+q.n23,q.n44+q.n24);d[3]=new THREE.Vector4(q.n41-q.n21,q.n42-q.n22,q.n43-q.n23,q.n44-q.n24);d[4]=new THREE.Vector4(q.n41-q.n31,q.n42-q.n32,q.n43-
q.n33,q.n44-q.n34);d[5]=new THREE.Vector4(q.n41+q.n31,q.n42+q.n32,q.n43+q.n33,q.n44+q.n34);i=0;for(y=d.length;i<y;i++){u=d[i];u.divideScalar(Math.sqrt(u.x*u.x+u.y*u.y+u.z*u.z))}y=n.objects;n=0;for(i=y.length;n<i;n++){u=y[n];var s;if(!(s=!u.visible)){if(s=u instanceof THREE.Mesh){a:{s=void 0;for(var w=u.position,W=-u.geometry.boundingSphere.radius*Math.max(u.scale.x,Math.max(u.scale.y,u.scale.z)),G=0;G<6;G++){s=d[G].x*w.x+d[G].y*w.y+d[G].z*w.z+d[G].w;if(s<=W){s=false;break a}}s=true}s=!s}s=s}if(!s){f=
g[e]=g[e]||new THREE.RenderableObject;Q.copy(u.position);q.multiplyVector3(Q);f.object=u;f.z=Q.z;p.push(f);e++}}t&&p.sort(a);return p};this.projectScene=function(n,i,t){var p=[],y=i.near,u=i.far,s,w,W,G,T,P,H,X,K,E,F,U,R,C,N,V;c=B=A=0;i.autoUpdateMatrix&&i.updateMatrix();q.multiply(i.projectionMatrix,i.matrix);P=this.projectObjects(n,i,true);n=0;for(s=P.length;n<s;n++){H=P[n].object;if(H.visible){H.autoUpdateMatrix&&H.updateMatrix();X=H.matrix;K=H.rotationMatrix;E=H.materials;F=H.overdraw;if(H instanceof
THREE.Mesh){U=H.geometry;R=U.vertices;w=0;for(W=R.length;w<W;w++){C=R[w];C.positionWorld.copy(C.position);X.multiplyVector3(C.positionWorld);G=C.positionScreen;G.copy(C.positionWorld);q.multiplyVector4(G);G.x/=G.w;G.y/=G.w;C.__visible=G.z>y&&G.z<u}U=U.faces;w=0;for(W=U.length;w<W;w++){C=U[w];if(C instanceof THREE.Face3){G=R[C.a];T=R[C.b];N=R[C.c];if(G.__visible&&T.__visible&&N.__visible)if(H.doubleSided||H.flipSided!=(N.positionScreen.x-G.positionScreen.x)*(T.positionScreen.y-G.positionScreen.y)-
THREE.Projector=function(){function a(l,i){return i.z-l.z}function b(l,i){var u=0,o=1,y=l.z+l.w,t=i.z+i.w,r=-l.z+l.w,w=-i.z+i.w;if(y>=0&&t>=0&&r>=0&&w>=0)return true;else if(y<0&&t<0||r<0&&w<0)return false;else{if(y<0)u=Math.max(u,y/(y-t));else if(t<0)o=Math.min(o,y/(y-t));if(r<0)u=Math.max(u,r/(r-w));else if(w<0)o=Math.min(o,r/(r-w));if(o<u)return false;else{l.lerpSelf(i,u);i.lerpSelf(l,1-o);return true}}}var f,e,g=[],j,p,c,k=[],m,B,D=[],x,A,M=[],Q=new THREE.Vector4,O=new THREE.Vector4,s=new THREE.Matrix4,
L=new THREE.Matrix4,d=[],h=new THREE.Vector4,q=new THREE.Vector4,n;this.projectObjects=function(l,i,u){var o=[],y,t;e=0;s.multiply(i.projectionMatrix,i.matrix);d[0]=new THREE.Vector4(s.n41-s.n11,s.n42-s.n12,s.n43-s.n13,s.n44-s.n14);d[1]=new THREE.Vector4(s.n41+s.n11,s.n42+s.n12,s.n43+s.n13,s.n44+s.n14);d[2]=new THREE.Vector4(s.n41+s.n21,s.n42+s.n22,s.n43+s.n23,s.n44+s.n24);d[3]=new THREE.Vector4(s.n41-s.n21,s.n42-s.n22,s.n43-s.n23,s.n44-s.n24);d[4]=new THREE.Vector4(s.n41-s.n31,s.n42-s.n32,s.n43-
s.n33,s.n44-s.n34);d[5]=new THREE.Vector4(s.n41+s.n31,s.n42+s.n32,s.n43+s.n33,s.n44+s.n34);i=0;for(y=d.length;i<y;i++){t=d[i];t.divideScalar(Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z))}y=l.objects;l=0;for(i=y.length;l<i;l++){t=y[l];var r;if(!(r=!t.visible)){if(r=t instanceof THREE.Mesh){a:{r=void 0;for(var w=t.position,W=-t.geometry.boundingSphere.radius*Math.max(t.scale.x,Math.max(t.scale.y,t.scale.z)),G=0;G<6;G++){r=d[G].x*w.x+d[G].y*w.y+d[G].z*w.z+d[G].w;if(r<=W){r=false;break a}}r=true}r=!r}r=r}if(!r){f=
g[e]=g[e]||new THREE.RenderableObject;Q.copy(t.position);s.multiplyVector3(Q);f.object=t;f.z=Q.z;o.push(f);e++}}u&&o.sort(a);return o};this.projectScene=function(l,i,u){var o=[],y=i.near,t=i.far,r,w,W,G,T,P,H,X,K,E,F,U,R,C,N,V;c=B=A=0;i.autoUpdateMatrix&&i.updateMatrix();s.multiply(i.projectionMatrix,i.matrix);P=this.projectObjects(l,i,true);l=0;for(r=P.length;l<r;l++){H=P[l].object;if(H.visible){H.autoUpdateMatrix&&H.updateMatrix();X=H.matrix;K=H.rotationMatrix;E=H.materials;F=H.overdraw;if(H instanceof
THREE.Mesh){U=H.geometry;R=U.vertices;w=0;for(W=R.length;w<W;w++){C=R[w];C.positionWorld.copy(C.position);X.multiplyVector3(C.positionWorld);G=C.positionScreen;G.copy(C.positionWorld);s.multiplyVector4(G);G.x/=G.w;G.y/=G.w;C.__visible=G.z>y&&G.z<t}U=U.faces;w=0;for(W=U.length;w<W;w++){C=U[w];if(C instanceof THREE.Face3){G=R[C.a];T=R[C.b];N=R[C.c];if(G.__visible&&T.__visible&&N.__visible)if(H.doubleSided||H.flipSided!=(N.positionScreen.x-G.positionScreen.x)*(T.positionScreen.y-G.positionScreen.y)-
(N.positionScreen.y-G.positionScreen.y)*(T.positionScreen.x-G.positionScreen.x)<0){j=k[c]=k[c]||new THREE.RenderableFace3;j.v1.positionWorld.copy(G.positionWorld);j.v2.positionWorld.copy(T.positionWorld);j.v3.positionWorld.copy(N.positionWorld);j.v1.positionScreen.copy(G.positionScreen);j.v2.positionScreen.copy(T.positionScreen);j.v3.positionScreen.copy(N.positionScreen);j.normalWorld.copy(C.normal);K.multiplyVector3(j.normalWorld);j.centroidWorld.copy(C.centroid);X.multiplyVector3(j.centroidWorld);
j.centroidScreen.copy(j.centroidWorld);q.multiplyVector3(j.centroidScreen);N=C.vertexNormals;m=j.vertexNormalsWorld;G=0;for(T=N.length;G<T;G++){V=m[G]=m[G]||new THREE.Vector3;V.copy(N[G]);K.multiplyVector3(V)}j.z=j.centroidScreen.z;j.meshMaterials=E;j.faceMaterials=C.materials;j.overdraw=F;if(H.geometry.uvs[w]){j.uvs[0]=H.geometry.uvs[w][0];j.uvs[1]=H.geometry.uvs[w][1];j.uvs[2]=H.geometry.uvs[w][2]}p.push(j);c++}}else if(C instanceof THREE.Face4){G=R[C.a];T=R[C.b];N=R[C.c];V=R[C.d];if(G.__visible&&
j.centroidScreen.copy(j.centroidWorld);s.multiplyVector3(j.centroidScreen);N=C.vertexNormals;n=j.vertexNormalsWorld;G=0;for(T=N.length;G<T;G++){V=n[G]=n[G]||new THREE.Vector3;V.copy(N[G]);K.multiplyVector3(V)}j.z=j.centroidScreen.z;j.meshMaterials=E;j.faceMaterials=C.materials;j.overdraw=F;if(H.geometry.uvs[w]){j.uvs[0]=H.geometry.uvs[w][0];j.uvs[1]=H.geometry.uvs[w][1];j.uvs[2]=H.geometry.uvs[w][2]}o.push(j);c++}}else if(C instanceof THREE.Face4){G=R[C.a];T=R[C.b];N=R[C.c];V=R[C.d];if(G.__visible&&
T.__visible&&N.__visible&&V.__visible)if(H.doubleSided||H.flipSided!=((V.positionScreen.x-G.positionScreen.x)*(T.positionScreen.y-G.positionScreen.y)-(V.positionScreen.y-G.positionScreen.y)*(T.positionScreen.x-G.positionScreen.x)<0||(T.positionScreen.x-N.positionScreen.x)*(V.positionScreen.y-N.positionScreen.y)-(T.positionScreen.y-N.positionScreen.y)*(V.positionScreen.x-N.positionScreen.x)<0)){j=k[c]=k[c]||new THREE.RenderableFace3;j.v1.positionWorld.copy(G.positionWorld);j.v2.positionWorld.copy(T.positionWorld);
j.v3.positionWorld.copy(V.positionWorld);j.v1.positionScreen.copy(G.positionScreen);j.v2.positionScreen.copy(T.positionScreen);j.v3.positionScreen.copy(V.positionScreen);j.normalWorld.copy(C.normal);K.multiplyVector3(j.normalWorld);j.centroidWorld.copy(C.centroid);X.multiplyVector3(j.centroidWorld);j.centroidScreen.copy(j.centroidWorld);q.multiplyVector3(j.centroidScreen);j.z=j.centroidScreen.z;j.meshMaterials=E;j.faceMaterials=C.materials;j.overdraw=F;if(H.geometry.uvs[w]){j.uvs[0]=H.geometry.uvs[w][0];
j.uvs[1]=H.geometry.uvs[w][1];j.uvs[2]=H.geometry.uvs[w][3]}p.push(j);c++;o=k[c]=k[c]||new THREE.RenderableFace3;o.v1.positionWorld.copy(T.positionWorld);o.v2.positionWorld.copy(N.positionWorld);o.v3.positionWorld.copy(V.positionWorld);o.v1.positionScreen.copy(T.positionScreen);o.v2.positionScreen.copy(N.positionScreen);o.v3.positionScreen.copy(V.positionScreen);o.normalWorld.copy(j.normalWorld);o.centroidWorld.copy(j.centroidWorld);o.centroidScreen.copy(j.centroidScreen);o.z=o.centroidScreen.z;o.meshMaterials=
E;o.faceMaterials=C.materials;o.overdraw=F;if(H.geometry.uvs[w]){o.uvs[0]=H.geometry.uvs[w][1];o.uvs[1]=H.geometry.uvs[w][2];o.uvs[2]=H.geometry.uvs[w][3]}p.push(o);c++}}}}else if(H instanceof THREE.Line){L.multiply(q,X);R=H.geometry.vertices;C=R[0];C.positionScreen.copy(C.position);L.multiplyVector4(C.positionScreen);w=1;for(W=R.length;w<W;w++){G=R[w];G.positionScreen.copy(G.position);L.multiplyVector4(G.positionScreen);T=R[w-1];h.copy(G.positionScreen);r.copy(T.positionScreen);if(b(h,r)){h.multiplyScalar(1/
h.w);r.multiplyScalar(1/r.w);l=D[B]=D[B]||new THREE.RenderableLine;l.v1.positionScreen.copy(h);l.v2.positionScreen.copy(r);l.z=Math.max(h.z,r.z);l.materials=H.materials;p.push(l);B++}}}else if(H instanceof THREE.Particle){O.set(H.position.x,H.position.y,H.position.z,1);q.multiplyVector4(O);O.z/=O.w;if(O.z>0&&O.z<1){x=M[A]=M[A]||new THREE.RenderableParticle;x.x=O.x/O.w;x.y=O.y/O.w;x.z=O.z;x.rotation=H.rotation.z;x.scale.x=H.scale.x*Math.abs(x.x-(O.x+i.projectionMatrix.n11)/(O.w+i.projectionMatrix.n14));
x.scale.y=H.scale.y*Math.abs(x.y-(O.y+i.projectionMatrix.n22)/(O.w+i.projectionMatrix.n24));x.materials=H.materials;p.push(x);A++}}}}t&&p.sort(a);return p};this.unprojectVector=function(n,i){var t=new THREE.Matrix4;t.multiply(THREE.Matrix4.makeInvert(i.matrix),THREE.Matrix4.makeInvert(i.projectionMatrix));t.multiplyVector3(n);return n}};
THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,f,e,g,j;this.domElement=document.createElement("div");this.setSize=function(o,c){f=o;e=c;g=f/2;j=e/2};this.render=function(o,c){var k,l,B,D,x,A,M,Q;a=b.projectScene(o,c);k=0;for(l=a.length;k<l;k++){x=a[k];if(x instanceof THREE.RenderableParticle){M=x.x*g+g;Q=x.y*j+j;B=0;for(D=x.material.length;B<D;B++){A=x.material[B];if(A instanceof THREE.ParticleDOMMaterial){A=A.domElement;A.style.left=M+"px";A.style.top=Q+"px"}}}}}};
THREE.CanvasRenderer=function(){function a(ba){if(x!=ba)l.globalAlpha=x=ba}function b(ba){if(A!=ba){switch(ba){case THREE.NormalBlending:l.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:l.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:l.globalCompositeOperation="darker"}A=ba}}var f=null,e=new THREE.Projector,g=document.createElement("canvas"),j,o,c,k,l=g.getContext("2d"),B=null,D=null,x=1,A=0,M=null,Q=null,O=1,q,L,d,h,r,m,n,i,t,p=new THREE.Color,
y=new THREE.Color,u=new THREE.Color,s=new THREE.Color,w=new THREE.Color,W,G,T,P,H,X,K,E,F,U=new THREE.Rectangle,R=new THREE.Rectangle,C=new THREE.Rectangle,N=false,V=new THREE.Color,ea=new THREE.Color,ma=new THREE.Color,na=new THREE.Color,La=Math.PI*2,Z=new THREE.Vector3,ra,sa,Ca,fa,ta,xa,pa=16;ra=document.createElement("canvas");ra.width=ra.height=2;sa=ra.getContext("2d");sa.fillStyle="rgba(0,0,0,1)";sa.fillRect(0,0,2,2);Ca=sa.getImageData(0,0,2,2);fa=Ca.data;ta=document.createElement("canvas");
ta.width=ta.height=pa;xa=ta.getContext("2d");xa.translate(-pa/2,-pa/2);xa.scale(pa,pa);pa--;this.domElement=g;this.sortElements=this.sortObjects=this.autoClear=true;this.setSize=function(ba,la){j=ba;o=la;c=j/2;k=o/2;g.width=j;g.height=o;U.set(-c,-k,c,k)};this.setClearColor=function(ba,la){B=ba!==null?new THREE.Color(ba):null;D=la;R.set(-c,-k,c,k);l.setTransform(1,0,0,-1,c,k);this.clear()};this.clear=function(){if(!R.isEmpty()){R.inflate(1);R.minSelf(U);if(B!==null){b(THREE.NormalBlending);a(1);l.fillStyle=
"rgba("+Math.floor(B.r*255)+","+Math.floor(B.g*255)+","+Math.floor(B.b*255)+","+D+")";l.fillRect(R.getX(),R.getY(),R.getWidth(),R.getHeight())}else l.clearRect(R.getX(),R.getY(),R.getWidth(),R.getHeight());R.empty()}};this.render=function(ba,la){function Ma(v){var S,J,z,I=v.lights;ea.setRGB(0,0,0);ma.setRGB(0,0,0);na.setRGB(0,0,0);v=0;for(S=I.length;v<S;v++){J=I[v];z=J.color;if(J instanceof THREE.AmbientLight){ea.r+=z.r;ea.g+=z.g;ea.b+=z.b}else if(J instanceof THREE.DirectionalLight){ma.r+=z.r;ma.g+=
j.v3.positionWorld.copy(V.positionWorld);j.v1.positionScreen.copy(G.positionScreen);j.v2.positionScreen.copy(T.positionScreen);j.v3.positionScreen.copy(V.positionScreen);j.normalWorld.copy(C.normal);K.multiplyVector3(j.normalWorld);j.centroidWorld.copy(C.centroid);X.multiplyVector3(j.centroidWorld);j.centroidScreen.copy(j.centroidWorld);s.multiplyVector3(j.centroidScreen);j.z=j.centroidScreen.z;j.meshMaterials=E;j.faceMaterials=C.materials;j.overdraw=F;if(H.geometry.uvs[w]){j.uvs[0]=H.geometry.uvs[w][0];
j.uvs[1]=H.geometry.uvs[w][1];j.uvs[2]=H.geometry.uvs[w][3]}o.push(j);c++;p=k[c]=k[c]||new THREE.RenderableFace3;p.v1.positionWorld.copy(T.positionWorld);p.v2.positionWorld.copy(N.positionWorld);p.v3.positionWorld.copy(V.positionWorld);p.v1.positionScreen.copy(T.positionScreen);p.v2.positionScreen.copy(N.positionScreen);p.v3.positionScreen.copy(V.positionScreen);p.normalWorld.copy(j.normalWorld);p.centroidWorld.copy(j.centroidWorld);p.centroidScreen.copy(j.centroidScreen);p.z=p.centroidScreen.z;p.meshMaterials=
E;p.faceMaterials=C.materials;p.overdraw=F;if(H.geometry.uvs[w]){p.uvs[0]=H.geometry.uvs[w][1];p.uvs[1]=H.geometry.uvs[w][2];p.uvs[2]=H.geometry.uvs[w][3]}o.push(p);c++}}}}else if(H instanceof THREE.Line){L.multiply(s,X);R=H.geometry.vertices;C=R[0];C.positionScreen.copy(C.position);L.multiplyVector4(C.positionScreen);w=1;for(W=R.length;w<W;w++){G=R[w];G.positionScreen.copy(G.position);L.multiplyVector4(G.positionScreen);T=R[w-1];h.copy(G.positionScreen);q.copy(T.positionScreen);if(b(h,q)){h.multiplyScalar(1/
h.w);q.multiplyScalar(1/q.w);m=D[B]=D[B]||new THREE.RenderableLine;m.v1.positionScreen.copy(h);m.v2.positionScreen.copy(q);m.z=Math.max(h.z,q.z);m.materials=H.materials;o.push(m);B++}}}else if(H instanceof THREE.Particle){O.set(H.position.x,H.position.y,H.position.z,1);s.multiplyVector4(O);O.z/=O.w;if(O.z>0&&O.z<1){x=M[A]=M[A]||new THREE.RenderableParticle;x.x=O.x/O.w;x.y=O.y/O.w;x.z=O.z;x.rotation=H.rotation.z;x.scale.x=H.scale.x*Math.abs(x.x-(O.x+i.projectionMatrix.n11)/(O.w+i.projectionMatrix.n14));
x.scale.y=H.scale.y*Math.abs(x.y-(O.y+i.projectionMatrix.n22)/(O.w+i.projectionMatrix.n24));x.materials=H.materials;o.push(x);A++}}}}u&&o.sort(a);return o};this.unprojectVector=function(l,i){var u=new THREE.Matrix4;u.multiply(THREE.Matrix4.makeInvert(i.matrix),THREE.Matrix4.makeInvert(i.projectionMatrix));u.multiplyVector3(l);return l}};
THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,f,e,g,j;this.domElement=document.createElement("div");this.setSize=function(p,c){f=p;e=c;g=f/2;j=e/2};this.render=function(p,c){var k,m,B,D,x,A,M,Q;a=b.projectScene(p,c);k=0;for(m=a.length;k<m;k++){x=a[k];if(x instanceof THREE.RenderableParticle){M=x.x*g+g;Q=x.y*j+j;B=0;for(D=x.material.length;B<D;B++){A=x.material[B];if(A instanceof THREE.ParticleDOMMaterial){A=A.domElement;A.style.left=M+"px";A.style.top=Q+"px"}}}}}};
THREE.CanvasRenderer=function(){function a(ba){if(x!=ba)m.globalAlpha=x=ba}function b(ba){if(A!=ba){switch(ba){case THREE.NormalBlending:m.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:m.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:m.globalCompositeOperation="darker"}A=ba}}var f=null,e=new THREE.Projector,g=document.createElement("canvas"),j,p,c,k,m=g.getContext("2d"),B=null,D=null,x=1,A=0,M=null,Q=null,O=1,s,L,d,h,q,n,l,i,u,o=new THREE.Color,
y=new THREE.Color,t=new THREE.Color,r=new THREE.Color,w=new THREE.Color,W,G,T,P,H,X,K,E,F,U=new THREE.Rectangle,R=new THREE.Rectangle,C=new THREE.Rectangle,N=false,V=new THREE.Color,ea=new THREE.Color,ma=new THREE.Color,na=new THREE.Color,La=Math.PI*2,Z=new THREE.Vector3,ra,sa,Ca,fa,ta,xa,pa=16;ra=document.createElement("canvas");ra.width=ra.height=2;sa=ra.getContext("2d");sa.fillStyle="rgba(0,0,0,1)";sa.fillRect(0,0,2,2);Ca=sa.getImageData(0,0,2,2);fa=Ca.data;ta=document.createElement("canvas");
ta.width=ta.height=pa;xa=ta.getContext("2d");xa.translate(-pa/2,-pa/2);xa.scale(pa,pa);pa--;this.domElement=g;this.sortElements=this.sortObjects=this.autoClear=true;this.setSize=function(ba,la){j=ba;p=la;c=j/2;k=p/2;g.width=j;g.height=p;U.set(-c,-k,c,k)};this.setClearColor=function(ba,la){B=ba!==null?new THREE.Color(ba):null;D=la;R.set(-c,-k,c,k);m.setTransform(1,0,0,-1,c,k);this.clear()};this.clear=function(){if(!R.isEmpty()){R.inflate(1);R.minSelf(U);if(B!==null){b(THREE.NormalBlending);a(1);m.fillStyle=
"rgba("+Math.floor(B.r*255)+","+Math.floor(B.g*255)+","+Math.floor(B.b*255)+","+D+")";m.fillRect(R.getX(),R.getY(),R.getWidth(),R.getHeight())}else m.clearRect(R.getX(),R.getY(),R.getWidth(),R.getHeight());R.empty()}};this.render=function(ba,la){function Ma(v){var S,J,z,I=v.lights;ea.setRGB(0,0,0);ma.setRGB(0,0,0);na.setRGB(0,0,0);v=0;for(S=I.length;v<S;v++){J=I[v];z=J.color;if(J instanceof THREE.AmbientLight){ea.r+=z.r;ea.g+=z.g;ea.b+=z.b}else if(J instanceof THREE.DirectionalLight){ma.r+=z.r;ma.g+=
z.g;ma.b+=z.b}else if(J instanceof THREE.PointLight){na.r+=z.r;na.g+=z.g;na.b+=z.b}}}function ya(v,S,J,z){var I,Y,aa,ca,da=v.lights;v=0;for(I=da.length;v<I;v++){Y=da[v];aa=Y.color;ca=Y.intensity;if(Y instanceof THREE.DirectionalLight){Y=J.dot(Y.position)*ca;if(Y>0){z.r+=aa.r*Y;z.g+=aa.g*Y;z.b+=aa.b*Y}}else if(Y instanceof THREE.PointLight){Z.sub(Y.position,S);Z.normalize();Y=J.dot(Z)*ca;if(Y>0){z.r+=aa.r*Y;z.g+=aa.g*Y;z.b+=aa.b*Y}}}}function Na(v,S,J){if(J.opacity!=0){a(J.opacity);b(J.blending);var z,
I,Y,aa,ca,da;if(J instanceof THREE.ParticleBasicMaterial){if(J.map){aa=J.map;ca=aa.width>>1;da=aa.height>>1;I=S.scale.x*c;Y=S.scale.y*k;J=I*ca;z=Y*da;C.set(v.x-J,v.y-z,v.x+J,v.y+z);if(!U.instersects(C))return;l.save();l.translate(v.x,v.y);l.rotate(-S.rotation);l.scale(I,-Y);l.translate(-ca,-da);l.drawImage(aa,0,0);l.restore()}l.beginPath();l.moveTo(v.x-10,v.y);l.lineTo(v.x+10,v.y);l.moveTo(v.x,v.y-10);l.lineTo(v.x,v.y+10);l.closePath();l.strokeStyle="rgb(255,255,0)";l.stroke()}else if(J instanceof
THREE.ParticleCircleMaterial){if(N){V.r=ea.r+ma.r+na.r;V.g=ea.g+ma.g+na.g;V.b=ea.b+ma.b+na.b;p.r=J.color.r*V.r;p.g=J.color.g*V.g;p.b=J.color.b*V.b;p.updateStyleString()}else p.__styleString=J.color.__styleString;J=S.scale.x*c;z=S.scale.y*k;C.set(v.x-J,v.y-z,v.x+J,v.y+z);if(U.instersects(C)){I=p.__styleString;if(Q!=I)l.fillStyle=Q=I;l.save();l.translate(v.x,v.y);l.rotate(-S.rotation);l.scale(J,z);l.beginPath();l.arc(0,0,1,0,La,true);l.closePath();l.fill();l.restore()}}}}function Oa(v,S,J,z){if(z.opacity!=
0){a(z.opacity);b(z.blending);l.beginPath();l.moveTo(v.positionScreen.x,v.positionScreen.y);l.lineTo(S.positionScreen.x,S.positionScreen.y);l.closePath();if(z instanceof THREE.LineBasicMaterial){p.__styleString=z.color.__styleString;v=z.linewidth;if(O!=v)l.lineWidth=O=v;v=p.__styleString;if(M!=v)l.strokeStyle=M=v;l.stroke();C.inflate(z.linewidth*2)}}}function Ha(v,S,J,z,I,Y){if(I.opacity!=0){a(I.opacity);b(I.blending);h=v.positionScreen.x;r=v.positionScreen.y;m=S.positionScreen.x;n=S.positionScreen.y;
i=J.positionScreen.x;t=J.positionScreen.y;l.beginPath();l.moveTo(h,r);l.lineTo(m,n);l.lineTo(i,t);l.lineTo(h,r);l.closePath();if(I instanceof THREE.MeshBasicMaterial)if(I.map)I.map.image.loaded&&I.map.mapping instanceof THREE.UVMapping&&ua(h,r,m,n,i,t,I.map.image,z.uvs[0].u,z.uvs[0].v,z.uvs[1].u,z.uvs[1].v,z.uvs[2].u,z.uvs[2].v);else if(I.env_map){if(I.env_map.image.loaded)if(I.env_map.mapping instanceof THREE.SphericalReflectionMapping){v=la.matrix;Z.copy(z.vertexNormalsWorld[0]);P=(Z.x*v.n11+Z.y*
v.n12+Z.z*v.n13)*0.5+0.5;H=-(Z.x*v.n21+Z.y*v.n22+Z.z*v.n23)*0.5+0.5;Z.copy(z.vertexNormalsWorld[1]);X=(Z.x*v.n11+Z.y*v.n12+Z.z*v.n13)*0.5+0.5;K=-(Z.x*v.n21+Z.y*v.n22+Z.z*v.n23)*0.5+0.5;Z.copy(z.vertexNormalsWorld[2]);E=(Z.x*v.n11+Z.y*v.n12+Z.z*v.n13)*0.5+0.5;F=-(Z.x*v.n21+Z.y*v.n22+Z.z*v.n23)*0.5+0.5;ua(h,r,m,n,i,t,I.env_map.image,P,H,X,K,E,F)}}else I.wireframe?za(I.color.__styleString,I.wireframe_linewidth):Aa(I.color.__styleString);else if(I instanceof THREE.MeshLambertMaterial){if(I.map&&!I.wireframe){I.map.mapping instanceof
THREE.UVMapping&&ua(h,r,m,n,i,t,I.map.image,z.uvs[0].u,z.uvs[0].v,z.uvs[1].u,z.uvs[1].v,z.uvs[2].u,z.uvs[2].v);b(THREE.SubtractiveBlending)}if(N)if(!I.wireframe&&I.shading==THREE.SmoothShading&&z.vertexNormalsWorld.length==3){y.r=u.r=s.r=ea.r;y.g=u.g=s.g=ea.g;y.b=u.b=s.b=ea.b;ya(Y,z.v1.positionWorld,z.vertexNormalsWorld[0],y);ya(Y,z.v2.positionWorld,z.vertexNormalsWorld[1],u);ya(Y,z.v3.positionWorld,z.vertexNormalsWorld[2],s);w.r=(u.r+s.r)*0.5;w.g=(u.g+s.g)*0.5;w.b=(u.b+s.b)*0.5;T=Ia(y,u,s,w);ua(h,
r,m,n,i,t,T,0,0,1,0,0,1)}else{V.r=ea.r;V.g=ea.g;V.b=ea.b;ya(Y,z.centroidWorld,z.normalWorld,V);p.r=I.color.r*V.r;p.g=I.color.g*V.g;p.b=I.color.b*V.b;p.updateStyleString();I.wireframe?za(p.__styleString,I.wireframe_linewidth):Aa(p.__styleString)}else I.wireframe?za(I.color.__styleString,I.wireframe_linewidth):Aa(I.color.__styleString)}else if(I instanceof THREE.MeshDepthMaterial){W=la.near;G=la.far;y.r=y.g=y.b=1-Da(v.positionScreen.z,W,G);u.r=u.g=u.b=1-Da(S.positionScreen.z,W,G);s.r=s.g=s.b=1-Da(J.positionScreen.z,
W,G);w.r=(u.r+s.r)*0.5;w.g=(u.g+s.g)*0.5;w.b=(u.b+s.b)*0.5;T=Ia(y,u,s,w);ua(h,r,m,n,i,t,T,0,0,1,0,0,1)}else if(I instanceof THREE.MeshNormalMaterial){p.r=Ea(z.normalWorld.x);p.g=Ea(z.normalWorld.y);p.b=Ea(z.normalWorld.z);p.updateStyleString();I.wireframe?za(p.__styleString,I.wireframe_linewidth):Aa(p.__styleString)}}}function za(v,S){if(M!=v)l.strokeStyle=M=v;if(O!=S)l.lineWidth=O=S;l.stroke();C.inflate(S*2)}function Aa(v){if(Q!=v)l.fillStyle=Q=v;l.fill()}function ua(v,S,J,z,I,Y,aa,ca,da,ia,ga,ja,
va){var oa,ka;oa=aa.width-1;ka=aa.height-1;ca*=oa;da*=ka;ia*=oa;ga*=ka;ja*=oa;va*=ka;J-=v;z-=S;I-=v;Y-=S;ia-=ca;ga-=da;ja-=ca;va-=da;ka=1/(ia*va-ja*ga);oa=(va*J-ga*I)*ka;ga=(va*z-ga*Y)*ka;J=(ia*I-ja*J)*ka;z=(ia*Y-ja*z)*ka;v=v-oa*ca-J*da;S=S-ga*ca-z*da;l.save();l.transform(oa,ga,J,z,v,S);l.clip();l.drawImage(aa,0,0);l.restore()}function Ia(v,S,J,z){var I=~~(v.r*255),Y=~~(v.g*255);v=~~(v.b*255);var aa=~~(S.r*255),ca=~~(S.g*255);S=~~(S.b*255);var da=~~(J.r*255),ia=~~(J.g*255);J=~~(J.b*255);var ga=~~(z.r*
I,Y,aa,ca,da;if(J instanceof THREE.ParticleBasicMaterial){if(J.map){aa=J.map;ca=aa.width>>1;da=aa.height>>1;I=S.scale.x*c;Y=S.scale.y*k;J=I*ca;z=Y*da;C.set(v.x-J,v.y-z,v.x+J,v.y+z);if(!U.instersects(C))return;m.save();m.translate(v.x,v.y);m.rotate(-S.rotation);m.scale(I,-Y);m.translate(-ca,-da);m.drawImage(aa,0,0);m.restore()}m.beginPath();m.moveTo(v.x-10,v.y);m.lineTo(v.x+10,v.y);m.moveTo(v.x,v.y-10);m.lineTo(v.x,v.y+10);m.closePath();m.strokeStyle="rgb(255,255,0)";m.stroke()}else if(J instanceof
THREE.ParticleCircleMaterial){if(N){V.r=ea.r+ma.r+na.r;V.g=ea.g+ma.g+na.g;V.b=ea.b+ma.b+na.b;o.r=J.color.r*V.r;o.g=J.color.g*V.g;o.b=J.color.b*V.b;o.updateStyleString()}else o.__styleString=J.color.__styleString;J=S.scale.x*c;z=S.scale.y*k;C.set(v.x-J,v.y-z,v.x+J,v.y+z);if(U.instersects(C)){I=o.__styleString;if(Q!=I)m.fillStyle=Q=I;m.save();m.translate(v.x,v.y);m.rotate(-S.rotation);m.scale(J,z);m.beginPath();m.arc(0,0,1,0,La,true);m.closePath();m.fill();m.restore()}}}}function Oa(v,S,J,z){if(z.opacity!=
0){a(z.opacity);b(z.blending);m.beginPath();m.moveTo(v.positionScreen.x,v.positionScreen.y);m.lineTo(S.positionScreen.x,S.positionScreen.y);m.closePath();if(z instanceof THREE.LineBasicMaterial){o.__styleString=z.color.__styleString;v=z.linewidth;if(O!=v)m.lineWidth=O=v;v=o.__styleString;if(M!=v)m.strokeStyle=M=v;m.stroke();C.inflate(z.linewidth*2)}}}function Ha(v,S,J,z,I,Y){if(I.opacity!=0){a(I.opacity);b(I.blending);h=v.positionScreen.x;q=v.positionScreen.y;n=S.positionScreen.x;l=S.positionScreen.y;
i=J.positionScreen.x;u=J.positionScreen.y;m.beginPath();m.moveTo(h,q);m.lineTo(n,l);m.lineTo(i,u);m.lineTo(h,q);m.closePath();if(I instanceof THREE.MeshBasicMaterial)if(I.map)I.map.image.loaded&&I.map.mapping instanceof THREE.UVMapping&&ua(h,q,n,l,i,u,I.map.image,z.uvs[0].u,z.uvs[0].v,z.uvs[1].u,z.uvs[1].v,z.uvs[2].u,z.uvs[2].v);else if(I.env_map){if(I.env_map.image.loaded)if(I.env_map.mapping instanceof THREE.SphericalReflectionMapping){v=la.matrix;Z.copy(z.vertexNormalsWorld[0]);P=(Z.x*v.n11+Z.y*
v.n12+Z.z*v.n13)*0.5+0.5;H=-(Z.x*v.n21+Z.y*v.n22+Z.z*v.n23)*0.5+0.5;Z.copy(z.vertexNormalsWorld[1]);X=(Z.x*v.n11+Z.y*v.n12+Z.z*v.n13)*0.5+0.5;K=-(Z.x*v.n21+Z.y*v.n22+Z.z*v.n23)*0.5+0.5;Z.copy(z.vertexNormalsWorld[2]);E=(Z.x*v.n11+Z.y*v.n12+Z.z*v.n13)*0.5+0.5;F=-(Z.x*v.n21+Z.y*v.n22+Z.z*v.n23)*0.5+0.5;ua(h,q,n,l,i,u,I.env_map.image,P,H,X,K,E,F)}}else I.wireframe?za(I.color.__styleString,I.wireframe_linewidth):Aa(I.color.__styleString);else if(I instanceof THREE.MeshLambertMaterial){if(I.map&&!I.wireframe){I.map.mapping instanceof
THREE.UVMapping&&ua(h,q,n,l,i,u,I.map.image,z.uvs[0].u,z.uvs[0].v,z.uvs[1].u,z.uvs[1].v,z.uvs[2].u,z.uvs[2].v);b(THREE.SubtractiveBlending)}if(N)if(!I.wireframe&&I.shading==THREE.SmoothShading&&z.vertexNormalsWorld.length==3){y.r=t.r=r.r=ea.r;y.g=t.g=r.g=ea.g;y.b=t.b=r.b=ea.b;ya(Y,z.v1.positionWorld,z.vertexNormalsWorld[0],y);ya(Y,z.v2.positionWorld,z.vertexNormalsWorld[1],t);ya(Y,z.v3.positionWorld,z.vertexNormalsWorld[2],r);w.r=(t.r+r.r)*0.5;w.g=(t.g+r.g)*0.5;w.b=(t.b+r.b)*0.5;T=Ia(y,t,r,w);ua(h,
q,n,l,i,u,T,0,0,1,0,0,1)}else{V.r=ea.r;V.g=ea.g;V.b=ea.b;ya(Y,z.centroidWorld,z.normalWorld,V);o.r=I.color.r*V.r;o.g=I.color.g*V.g;o.b=I.color.b*V.b;o.updateStyleString();I.wireframe?za(o.__styleString,I.wireframe_linewidth):Aa(o.__styleString)}else I.wireframe?za(I.color.__styleString,I.wireframe_linewidth):Aa(I.color.__styleString)}else if(I instanceof THREE.MeshDepthMaterial){W=la.near;G=la.far;y.r=y.g=y.b=1-Da(v.positionScreen.z,W,G);t.r=t.g=t.b=1-Da(S.positionScreen.z,W,G);r.r=r.g=r.b=1-Da(J.positionScreen.z,
W,G);w.r=(t.r+r.r)*0.5;w.g=(t.g+r.g)*0.5;w.b=(t.b+r.b)*0.5;T=Ia(y,t,r,w);ua(h,q,n,l,i,u,T,0,0,1,0,0,1)}else if(I instanceof THREE.MeshNormalMaterial){o.r=Ea(z.normalWorld.x);o.g=Ea(z.normalWorld.y);o.b=Ea(z.normalWorld.z);o.updateStyleString();I.wireframe?za(o.__styleString,I.wireframe_linewidth):Aa(o.__styleString)}}}function za(v,S){if(M!=v)m.strokeStyle=M=v;if(O!=S)m.lineWidth=O=S;m.stroke();C.inflate(S*2)}function Aa(v){if(Q!=v)m.fillStyle=Q=v;m.fill()}function ua(v,S,J,z,I,Y,aa,ca,da,ia,ga,ja,
va){var oa,ka;oa=aa.width-1;ka=aa.height-1;ca*=oa;da*=ka;ia*=oa;ga*=ka;ja*=oa;va*=ka;J-=v;z-=S;I-=v;Y-=S;ia-=ca;ga-=da;ja-=ca;va-=da;ka=1/(ia*va-ja*ga);oa=(va*J-ga*I)*ka;ga=(va*z-ga*Y)*ka;J=(ia*I-ja*J)*ka;z=(ia*Y-ja*z)*ka;v=v-oa*ca-J*da;S=S-ga*ca-z*da;m.save();m.transform(oa,ga,J,z,v,S);m.clip();m.drawImage(aa,0,0);m.restore()}function Ia(v,S,J,z){var I=~~(v.r*255),Y=~~(v.g*255);v=~~(v.b*255);var aa=~~(S.r*255),ca=~~(S.g*255);S=~~(S.b*255);var da=~~(J.r*255),ia=~~(J.g*255);J=~~(J.b*255);var ga=~~(z.r*
255),ja=~~(z.g*255);z=~~(z.b*255);fa[0]=I<0?0:I>255?255:I;fa[1]=Y<0?0:Y>255?255:Y;fa[2]=v<0?0:v>255?255:v;fa[4]=aa<0?0:aa>255?255:aa;fa[5]=ca<0?0:ca>255?255:ca;fa[6]=S<0?0:S>255?255:S;fa[8]=da<0?0:da>255?255:da;fa[9]=ia<0?0:ia>255?255:ia;fa[10]=J<0?0:J>255?255:J;fa[12]=ga<0?0:ga>255?255:ga;fa[13]=ja<0?0:ja>255?255:ja;fa[14]=z<0?0:z>255?255:z;sa.putImageData(Ca,0,0);xa.drawImage(ra,0,0);return ta}function Da(v,S,J){v=(v-S)/(J-S);return v*v*(3-2*v)}function Ea(v){v=(v+1)*0.5;return v<0?0:v>1?1:v}function Fa(v,
S){var J=S.x-v.x,z=S.y-v.y,I=1/Math.sqrt(J*J+z*z);J*=I;z*=I;S.x+=J;S.y+=z;v.x-=J;v.y-=z}var Ba,Ja,$,ha,qa,Ga,Ka,wa;l.setTransform(1,0,0,-1,c,k);this.autoClear&&this.clear();f=e.projectScene(ba,la,this.sortElements);l.fillStyle="rgba( 0, 255, 255, 0.5 )";l.fillRect(U.getX(),U.getY(),U.getWidth(),U.getHeight());(N=ba.lights.length>0)&&Ma(ba);Ba=0;for(Ja=f.length;Ba<Ja;Ba++){$=f[Ba];C.empty();if($ instanceof THREE.RenderableParticle){q=$;q.x*=c;q.y*=k;ha=0;for(qa=$.materials.length;ha<qa;ha++)Na(q,$,
$.materials[ha],ba)}else if($ instanceof THREE.RenderableLine){q=$.v1;L=$.v2;q.positionScreen.x*=c;q.positionScreen.y*=k;L.positionScreen.x*=c;L.positionScreen.y*=k;C.addPoint(q.positionScreen.x,q.positionScreen.y);C.addPoint(L.positionScreen.x,L.positionScreen.y);if(U.instersects(C)){ha=0;for(qa=$.materials.length;ha<qa;)Oa(q,L,$,$.materials[ha++],ba)}}else if($ instanceof THREE.RenderableFace3){q=$.v1;L=$.v2;d=$.v3;q.positionScreen.x*=c;q.positionScreen.y*=k;L.positionScreen.x*=c;L.positionScreen.y*=
k;d.positionScreen.x*=c;d.positionScreen.y*=k;if($.overdraw){Fa(q.positionScreen,L.positionScreen);Fa(L.positionScreen,d.positionScreen);Fa(d.positionScreen,q.positionScreen)}C.add3Points(q.positionScreen.x,q.positionScreen.y,L.positionScreen.x,L.positionScreen.y,d.positionScreen.x,d.positionScreen.y);if(U.instersects(C)){ha=0;for(qa=$.meshMaterials.length;ha<qa;){wa=$.meshMaterials[ha++];if(wa instanceof THREE.MeshFaceMaterial){Ga=0;for(Ka=$.faceMaterials.length;Ga<Ka;)(wa=$.faceMaterials[Ga++])&&
Ha(q,L,d,$,wa,ba)}else Ha(q,L,d,$,wa,ba)}}}R.addRectangle(C)}l.lineWidth=1;l.strokeStyle="rgba( 255, 0, 0, 0.5 )";l.strokeRect(R.getX(),R.getY(),R.getWidth(),R.getHeight());l.setTransform(1,0,0,1,0,0)}};
THREE.SVGRenderer=function(){function a(P,H,X){var K,E,F,U;K=0;for(E=P.lights.length;K<E;K++){F=P.lights[K];if(F instanceof THREE.DirectionalLight){U=H.normalWorld.dot(F.position)*F.intensity;if(U>0){X.r+=F.color.r*U;X.g+=F.color.g*U;X.b+=F.color.b*U}}else if(F instanceof THREE.PointLight){t.sub(F.position,H.centroidWorld);t.normalize();U=H.normalWorld.dot(t)*F.intensity;if(U>0){X.r+=F.color.r*U;X.g+=F.color.g*U;X.b+=F.color.b*U}}}}function b(P,H,X,K,E,F){s=e(w++);s.setAttribute("d","M "+P.positionScreen.x+
" "+P.positionScreen.y+" L "+H.positionScreen.x+" "+H.positionScreen.y+" L "+X.positionScreen.x+","+X.positionScreen.y+"z");if(E instanceof THREE.MeshBasicMaterial)d.__styleString=E.color.__styleString;else if(E instanceof THREE.MeshLambertMaterial)if(L){h.r=r.r;h.g=r.g;h.b=r.b;a(F,K,h);d.r=E.color.r*h.r;d.g=E.color.g*h.g;d.b=E.color.b*h.b;d.updateStyleString()}else d.__styleString=E.color.__styleString;else if(E instanceof THREE.MeshDepthMaterial){i=1-E.__2near/(E.__farPlusNear-K.z*E.__farMinusNear);
d.setRGB(i,i,i)}else E instanceof THREE.MeshNormalMaterial&&d.setRGB(g(K.normalWorld.x),g(K.normalWorld.y),g(K.normalWorld.z));E.wireframe?s.setAttribute("style","fill: none; stroke: "+d.__styleString+"; stroke-width: "+E.wireframe_linewidth+"; stroke-opacity: "+E.opacity+"; stroke-linecap: "+E.wireframe_linecap+"; stroke-linejoin: "+E.wireframe_linejoin):s.setAttribute("style","fill: "+d.__styleString+"; fill-opacity: "+E.opacity);c.appendChild(s)}function f(P,H,X,K,E,F,U){s=e(w++);s.setAttribute("d",
"M "+P.positionScreen.x+" "+P.positionScreen.y+" L "+H.positionScreen.x+" "+H.positionScreen.y+" L "+X.positionScreen.x+","+X.positionScreen.y+" L "+K.positionScreen.x+","+K.positionScreen.y+"z");if(F instanceof THREE.MeshBasicMaterial)d.__styleString=F.color.__styleString;else if(F instanceof THREE.MeshLambertMaterial)if(L){h.r=r.r;h.g=r.g;h.b=r.b;a(U,E,h);d.r=F.color.r*h.r;d.g=F.color.g*h.g;d.b=F.color.b*h.b;d.updateStyleString()}else d.__styleString=F.color.__styleString;else if(F instanceof THREE.MeshDepthMaterial){i=
1-F.__2near/(F.__farPlusNear-E.z*F.__farMinusNear);d.setRGB(i,i,i)}else F instanceof THREE.MeshNormalMaterial&&d.setRGB(g(E.normalWorld.x),g(E.normalWorld.y),g(E.normalWorld.z));F.wireframe?s.setAttribute("style","fill: none; stroke: "+d.__styleString+"; stroke-width: "+F.wireframe_linewidth+"; stroke-opacity: "+F.opacity+"; stroke-linecap: "+F.wireframe_linecap+"; stroke-linejoin: "+F.wireframe_linejoin):s.setAttribute("style","fill: "+d.__styleString+"; fill-opacity: "+F.opacity);c.appendChild(s)}
function e(P){if(p[P]==null){p[P]=document.createElementNS("http://www.w3.org/2000/svg","path");T==0&&p[P].setAttribute("shape-rendering","crispEdges");return p[P]}return p[P]}function g(P){return P<0?Math.min((1+P)*0.5,0.5):0.5+Math.min(P*0.5,0.5)}var j=null,o=new THREE.Projector,c=document.createElementNS("http://www.w3.org/2000/svg","svg"),k,l,B,D,x,A,M,Q,O=new THREE.Rectangle,q=new THREE.Rectangle,L=false,d=new THREE.Color(16777215),h=new THREE.Color(16777215),r=new THREE.Color(0),m=new THREE.Color(0),
n=new THREE.Color(0),i,t=new THREE.Vector3,p=[],y=[],u=[],s,w,W,G,T=1;this.domElement=c;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(P){switch(P){case "high":T=1;break;case "low":T=0}};this.setSize=function(P,H){k=P;l=H;B=k/2;D=l/2;c.setAttribute("viewBox",-B+" "+-D+" "+k+" "+l);c.setAttribute("width",k);c.setAttribute("height",l);O.set(-B,-D,B,D)};this.clear=function(){for(;c.childNodes.length>0;)c.removeChild(c.childNodes[0])};this.render=function(P,H){var X,K,
E,F,U,R,C,N;this.autoClear&&this.clear();j=o.projectScene(P,H,this.sortElements);G=W=w=0;if(L=P.lights.length>0){C=P.lights;r.setRGB(0,0,0);m.setRGB(0,0,0);n.setRGB(0,0,0);X=0;for(K=C.length;X<K;X++){E=C[X];F=E.color;if(E instanceof THREE.AmbientLight){r.r+=F.r;r.g+=F.g;r.b+=F.b}else if(E instanceof THREE.DirectionalLight){m.r+=F.r;m.g+=F.g;m.b+=F.b}else if(E instanceof THREE.PointLight){n.r+=F.r;n.g+=F.g;n.b+=F.b}}}X=0;for(K=j.length;X<K;X++){C=j[X];q.empty();if(C instanceof THREE.RenderableParticle){x=
C;x.x*=B;x.y*=-D;E=0;for(F=C.materials.length;E<F;E++)if(N=C.materials[E]){U=x;R=C;N=N;var V=W++;if(y[V]==null){y[V]=document.createElementNS("http://www.w3.org/2000/svg","circle");T==0&&y[V].setAttribute("shape-rendering","crispEdges")}s=y[V];s.setAttribute("cx",U.x);s.setAttribute("cy",U.y);s.setAttribute("r",R.scale.x*B);if(N instanceof THREE.ParticleCircleMaterial){if(L){h.r=r.r+m.r+n.r;h.g=r.g+m.g+n.g;h.b=r.b+m.b+n.b;d.r=N.color.r*h.r;d.g=N.color.g*h.g;d.b=N.color.b*h.b;d.updateStyleString()}else d=
N.color;s.setAttribute("style","fill: "+d.__styleString)}c.appendChild(s)}}else if(C instanceof THREE.RenderableLine){x=C.v1;A=C.v2;x.positionScreen.x*=B;x.positionScreen.y*=-D;A.positionScreen.x*=B;A.positionScreen.y*=-D;q.addPoint(x.positionScreen.x,x.positionScreen.y);q.addPoint(A.positionScreen.x,A.positionScreen.y);if(O.instersects(q)){E=0;for(F=C.materials.length;E<F;)if(N=C.materials[E++]){U=x;R=A;N=N;V=G++;if(u[V]==null){u[V]=document.createElementNS("http://www.w3.org/2000/svg","line");T==
0&&u[V].setAttribute("shape-rendering","crispEdges")}s=u[V];s.setAttribute("x1",U.positionScreen.x);s.setAttribute("y1",U.positionScreen.y);s.setAttribute("x2",R.positionScreen.x);s.setAttribute("y2",R.positionScreen.y);if(N instanceof THREE.LineBasicMaterial){d.__styleString=N.color.__styleString;s.setAttribute("style","fill: none; stroke: "+d.__styleString+"; stroke-width: "+N.linewidth+"; stroke-opacity: "+N.opacity+"; stroke-linecap: "+N.linecap+"; stroke-linejoin: "+N.linejoin);c.appendChild(s)}}}}else if(C instanceof
THREE.RenderableFace3){x=C.v1;A=C.v2;M=C.v3;x.positionScreen.x*=B;x.positionScreen.y*=-D;A.positionScreen.x*=B;A.positionScreen.y*=-D;M.positionScreen.x*=B;M.positionScreen.y*=-D;q.addPoint(x.positionScreen.x,x.positionScreen.y);q.addPoint(A.positionScreen.x,A.positionScreen.y);q.addPoint(M.positionScreen.x,M.positionScreen.y);if(O.instersects(q)){E=0;for(F=C.meshMaterials.length;E<F;){N=C.meshMaterials[E++];if(N instanceof THREE.MeshFaceMaterial){U=0;for(R=C.faceMaterials.length;U<R;)(N=C.faceMaterials[U++])&&
b(x,A,M,C,N,P)}else N&&b(x,A,M,C,N,P)}}}else if(C instanceof THREE.RenderableFace4){x=C.v1;A=C.v2;M=C.v3;Q=C.v4;x.positionScreen.x*=B;x.positionScreen.y*=-D;A.positionScreen.x*=B;A.positionScreen.y*=-D;M.positionScreen.x*=B;M.positionScreen.y*=-D;Q.positionScreen.x*=B;Q.positionScreen.y*=-D;q.addPoint(x.positionScreen.x,x.positionScreen.y);q.addPoint(A.positionScreen.x,A.positionScreen.y);q.addPoint(M.positionScreen.x,M.positionScreen.y);q.addPoint(Q.positionScreen.x,Q.positionScreen.y);if(O.instersects(q)){E=
S){var J=S.x-v.x,z=S.y-v.y,I=1/Math.sqrt(J*J+z*z);J*=I;z*=I;S.x+=J;S.y+=z;v.x-=J;v.y-=z}var Ba,Ja,$,ha,qa,Ga,Ka,wa;m.setTransform(1,0,0,-1,c,k);this.autoClear&&this.clear();f=e.projectScene(ba,la,this.sortElements);m.fillStyle="rgba( 0, 255, 255, 0.5 )";m.fillRect(U.getX(),U.getY(),U.getWidth(),U.getHeight());(N=ba.lights.length>0)&&Ma(ba);Ba=0;for(Ja=f.length;Ba<Ja;Ba++){$=f[Ba];C.empty();if($ instanceof THREE.RenderableParticle){s=$;s.x*=c;s.y*=k;ha=0;for(qa=$.materials.length;ha<qa;ha++)Na(s,$,
$.materials[ha],ba)}else if($ instanceof THREE.RenderableLine){s=$.v1;L=$.v2;s.positionScreen.x*=c;s.positionScreen.y*=k;L.positionScreen.x*=c;L.positionScreen.y*=k;C.addPoint(s.positionScreen.x,s.positionScreen.y);C.addPoint(L.positionScreen.x,L.positionScreen.y);if(U.instersects(C)){ha=0;for(qa=$.materials.length;ha<qa;)Oa(s,L,$,$.materials[ha++],ba)}}else if($ instanceof THREE.RenderableFace3){s=$.v1;L=$.v2;d=$.v3;s.positionScreen.x*=c;s.positionScreen.y*=k;L.positionScreen.x*=c;L.positionScreen.y*=
k;d.positionScreen.x*=c;d.positionScreen.y*=k;if($.overdraw){Fa(s.positionScreen,L.positionScreen);Fa(L.positionScreen,d.positionScreen);Fa(d.positionScreen,s.positionScreen)}C.add3Points(s.positionScreen.x,s.positionScreen.y,L.positionScreen.x,L.positionScreen.y,d.positionScreen.x,d.positionScreen.y);if(U.instersects(C)){ha=0;for(qa=$.meshMaterials.length;ha<qa;){wa=$.meshMaterials[ha++];if(wa instanceof THREE.MeshFaceMaterial){Ga=0;for(Ka=$.faceMaterials.length;Ga<Ka;)(wa=$.faceMaterials[Ga++])&&
Ha(s,L,d,$,wa,ba)}else Ha(s,L,d,$,wa,ba)}}}R.addRectangle(C)}m.lineWidth=1;m.strokeStyle="rgba( 255, 0, 0, 0.5 )";m.strokeRect(R.getX(),R.getY(),R.getWidth(),R.getHeight());m.setTransform(1,0,0,1,0,0)}};
THREE.SVGRenderer=function(){function a(P,H,X){var K,E,F,U;K=0;for(E=P.lights.length;K<E;K++){F=P.lights[K];if(F instanceof THREE.DirectionalLight){U=H.normalWorld.dot(F.position)*F.intensity;if(U>0){X.r+=F.color.r*U;X.g+=F.color.g*U;X.b+=F.color.b*U}}else if(F instanceof THREE.PointLight){u.sub(F.position,H.centroidWorld);u.normalize();U=H.normalWorld.dot(u)*F.intensity;if(U>0){X.r+=F.color.r*U;X.g+=F.color.g*U;X.b+=F.color.b*U}}}}function b(P,H,X,K,E,F){r=e(w++);r.setAttribute("d","M "+P.positionScreen.x+
" "+P.positionScreen.y+" L "+H.positionScreen.x+" "+H.positionScreen.y+" L "+X.positionScreen.x+","+X.positionScreen.y+"z");if(E instanceof THREE.MeshBasicMaterial)d.__styleString=E.color.__styleString;else if(E instanceof THREE.MeshLambertMaterial)if(L){h.r=q.r;h.g=q.g;h.b=q.b;a(F,K,h);d.r=E.color.r*h.r;d.g=E.color.g*h.g;d.b=E.color.b*h.b;d.updateStyleString()}else d.__styleString=E.color.__styleString;else if(E instanceof THREE.MeshDepthMaterial){i=1-E.__2near/(E.__farPlusNear-K.z*E.__farMinusNear);
d.setRGB(i,i,i)}else E instanceof THREE.MeshNormalMaterial&&d.setRGB(g(K.normalWorld.x),g(K.normalWorld.y),g(K.normalWorld.z));E.wireframe?r.setAttribute("style","fill: none; stroke: "+d.__styleString+"; stroke-width: "+E.wireframe_linewidth+"; stroke-opacity: "+E.opacity+"; stroke-linecap: "+E.wireframe_linecap+"; stroke-linejoin: "+E.wireframe_linejoin):r.setAttribute("style","fill: "+d.__styleString+"; fill-opacity: "+E.opacity);c.appendChild(r)}function f(P,H,X,K,E,F,U){r=e(w++);r.setAttribute("d",
"M "+P.positionScreen.x+" "+P.positionScreen.y+" L "+H.positionScreen.x+" "+H.positionScreen.y+" L "+X.positionScreen.x+","+X.positionScreen.y+" L "+K.positionScreen.x+","+K.positionScreen.y+"z");if(F instanceof THREE.MeshBasicMaterial)d.__styleString=F.color.__styleString;else if(F instanceof THREE.MeshLambertMaterial)if(L){h.r=q.r;h.g=q.g;h.b=q.b;a(U,E,h);d.r=F.color.r*h.r;d.g=F.color.g*h.g;d.b=F.color.b*h.b;d.updateStyleString()}else d.__styleString=F.color.__styleString;else if(F instanceof THREE.MeshDepthMaterial){i=
1-F.__2near/(F.__farPlusNear-E.z*F.__farMinusNear);d.setRGB(i,i,i)}else F instanceof THREE.MeshNormalMaterial&&d.setRGB(g(E.normalWorld.x),g(E.normalWorld.y),g(E.normalWorld.z));F.wireframe?r.setAttribute("style","fill: none; stroke: "+d.__styleString+"; stroke-width: "+F.wireframe_linewidth+"; stroke-opacity: "+F.opacity+"; stroke-linecap: "+F.wireframe_linecap+"; stroke-linejoin: "+F.wireframe_linejoin):r.setAttribute("style","fill: "+d.__styleString+"; fill-opacity: "+F.opacity);c.appendChild(r)}
function e(P){if(o[P]==null){o[P]=document.createElementNS("http://www.w3.org/2000/svg","path");T==0&&o[P].setAttribute("shape-rendering","crispEdges");return o[P]}return o[P]}function g(P){return P<0?Math.min((1+P)*0.5,0.5):0.5+Math.min(P*0.5,0.5)}var j=null,p=new THREE.Projector,c=document.createElementNS("http://www.w3.org/2000/svg","svg"),k,m,B,D,x,A,M,Q,O=new THREE.Rectangle,s=new THREE.Rectangle,L=false,d=new THREE.Color(16777215),h=new THREE.Color(16777215),q=new THREE.Color(0),n=new THREE.Color(0),
l=new THREE.Color(0),i,u=new THREE.Vector3,o=[],y=[],t=[],r,w,W,G,T=1;this.domElement=c;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(P){switch(P){case "high":T=1;break;case "low":T=0}};this.setSize=function(P,H){k=P;m=H;B=k/2;D=m/2;c.setAttribute("viewBox",-B+" "+-D+" "+k+" "+m);c.setAttribute("width",k);c.setAttribute("height",m);O.set(-B,-D,B,D)};this.clear=function(){for(;c.childNodes.length>0;)c.removeChild(c.childNodes[0])};this.render=function(P,H){var X,K,
E,F,U,R,C,N;this.autoClear&&this.clear();j=p.projectScene(P,H,this.sortElements);G=W=w=0;if(L=P.lights.length>0){C=P.lights;q.setRGB(0,0,0);n.setRGB(0,0,0);l.setRGB(0,0,0);X=0;for(K=C.length;X<K;X++){E=C[X];F=E.color;if(E instanceof THREE.AmbientLight){q.r+=F.r;q.g+=F.g;q.b+=F.b}else if(E instanceof THREE.DirectionalLight){n.r+=F.r;n.g+=F.g;n.b+=F.b}else if(E instanceof THREE.PointLight){l.r+=F.r;l.g+=F.g;l.b+=F.b}}}X=0;for(K=j.length;X<K;X++){C=j[X];s.empty();if(C instanceof THREE.RenderableParticle){x=
C;x.x*=B;x.y*=-D;E=0;for(F=C.materials.length;E<F;E++)if(N=C.materials[E]){U=x;R=C;N=N;var V=W++;if(y[V]==null){y[V]=document.createElementNS("http://www.w3.org/2000/svg","circle");T==0&&y[V].setAttribute("shape-rendering","crispEdges")}r=y[V];r.setAttribute("cx",U.x);r.setAttribute("cy",U.y);r.setAttribute("r",R.scale.x*B);if(N instanceof THREE.ParticleCircleMaterial){if(L){h.r=q.r+n.r+l.r;h.g=q.g+n.g+l.g;h.b=q.b+n.b+l.b;d.r=N.color.r*h.r;d.g=N.color.g*h.g;d.b=N.color.b*h.b;d.updateStyleString()}else d=
N.color;r.setAttribute("style","fill: "+d.__styleString)}c.appendChild(r)}}else if(C instanceof THREE.RenderableLine){x=C.v1;A=C.v2;x.positionScreen.x*=B;x.positionScreen.y*=-D;A.positionScreen.x*=B;A.positionScreen.y*=-D;s.addPoint(x.positionScreen.x,x.positionScreen.y);s.addPoint(A.positionScreen.x,A.positionScreen.y);if(O.instersects(s)){E=0;for(F=C.materials.length;E<F;)if(N=C.materials[E++]){U=x;R=A;N=N;V=G++;if(t[V]==null){t[V]=document.createElementNS("http://www.w3.org/2000/svg","line");T==
0&&t[V].setAttribute("shape-rendering","crispEdges")}r=t[V];r.setAttribute("x1",U.positionScreen.x);r.setAttribute("y1",U.positionScreen.y);r.setAttribute("x2",R.positionScreen.x);r.setAttribute("y2",R.positionScreen.y);if(N instanceof THREE.LineBasicMaterial){d.__styleString=N.color.__styleString;r.setAttribute("style","fill: none; stroke: "+d.__styleString+"; stroke-width: "+N.linewidth+"; stroke-opacity: "+N.opacity+"; stroke-linecap: "+N.linecap+"; stroke-linejoin: "+N.linejoin);c.appendChild(r)}}}}else if(C instanceof
THREE.RenderableFace3){x=C.v1;A=C.v2;M=C.v3;x.positionScreen.x*=B;x.positionScreen.y*=-D;A.positionScreen.x*=B;A.positionScreen.y*=-D;M.positionScreen.x*=B;M.positionScreen.y*=-D;s.addPoint(x.positionScreen.x,x.positionScreen.y);s.addPoint(A.positionScreen.x,A.positionScreen.y);s.addPoint(M.positionScreen.x,M.positionScreen.y);if(O.instersects(s)){E=0;for(F=C.meshMaterials.length;E<F;){N=C.meshMaterials[E++];if(N instanceof THREE.MeshFaceMaterial){U=0;for(R=C.faceMaterials.length;U<R;)(N=C.faceMaterials[U++])&&
b(x,A,M,C,N,P)}else N&&b(x,A,M,C,N,P)}}}else if(C instanceof THREE.RenderableFace4){x=C.v1;A=C.v2;M=C.v3;Q=C.v4;x.positionScreen.x*=B;x.positionScreen.y*=-D;A.positionScreen.x*=B;A.positionScreen.y*=-D;M.positionScreen.x*=B;M.positionScreen.y*=-D;Q.positionScreen.x*=B;Q.positionScreen.y*=-D;s.addPoint(x.positionScreen.x,x.positionScreen.y);s.addPoint(A.positionScreen.x,A.positionScreen.y);s.addPoint(M.positionScreen.x,M.positionScreen.y);s.addPoint(Q.positionScreen.x,Q.positionScreen.y);if(O.instersects(s)){E=
0;for(F=C.meshMaterials.length;E<F;){N=C.meshMaterials[E++];if(N instanceof THREE.MeshFaceMaterial){U=0;for(R=C.faceMaterials.length;U<R;)(N=C.faceMaterials[U++])&&f(x,A,M,Q,C,N,P)}else N&&f(x,A,M,Q,C,N,P)}}}}}};
THREE.WebGLRenderer=function(a){function b(d,h){d.fragment_shader=h.fragment_shader;d.vertex_shader=h.vertex_shader;d.uniforms=Uniforms.clone(h.uniforms)}function f(d,h){d.uniforms.color.value.setRGB(d.color.r*d.opacity,d.color.g*d.opacity,d.color.b*d.opacity);d.uniforms.opacity.value=d.opacity;d.uniforms.map.texture=d.map;d.uniforms.env_map.texture=d.env_map;d.uniforms.reflectivity.value=d.reflectivity;d.uniforms.refraction_ratio.value=d.refraction_ratio;d.uniforms.combine.value=d.combine;d.uniforms.useRefract.value=
d.env_map&&d.env_map.mapping instanceof THREE.CubeRefractionMapping;if(h){d.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){d.uniforms.fogNear.value=h.near;d.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)d.uniforms.fogDensity.value=h.density}}function e(d,h){d.uniforms.color.value.setRGB(d.color.r*d.opacity,d.color.g*d.opacity,d.color.b*d.opacity);d.uniforms.opacity.value=d.opacity;if(h){d.uniforms.fogColor.value.setHex(h.color.hex);if(h instanceof THREE.Fog){d.uniforms.fogNear.value=
h.near;d.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)d.uniforms.fogDensity.value=h.density}}function g(d,h){var r;if(d=="fragment")r=c.createShader(c.FRAGMENT_SHADER);else if(d=="vertex")r=c.createShader(c.VERTEX_SHADER);c.shaderSource(r,h);c.compileShader(r);if(!c.getShaderParameter(r,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(r));return null}return r}function j(d){switch(d){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,k=null,l=new THREE.Matrix4,B,D=new Float32Array(16),x=new Float32Array(16),A=new Float32Array(16),
M=new Float32Array(9),Q=new Float32Array(16),O=true,q=new THREE.Color(0),L=0;if(a){if(a.antialias!==undefined)O=a.antialias;a.clearColor!==undefined&&q.setHex(a.clearColor);if(a.clearAlpha!==undefined)L=a.clearAlpha}this.domElement=o;this.autoClear=true;(function(d,h,r){try{c=o.getContext("experimental-webgl",{antialias:d})}catch(m){}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(h.r,h.g,h.b,r)})(O,q,L);this.setSize=function(d,h){o.width=d;o.height=h;c.viewport(0,0,o.width,o.height)};this.setClearColor=function(d,h){var r=new THREE.Color(d);c.clearColor(r.r,r.g,r.b,h)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(d,h){var r,m,n,i=0,t=0,p=0,y=[],u=[],s=[],w=[];r=0;for(m=h.length;r<m;r++){n=h[r];if(n instanceof THREE.AmbientLight){i+=
n.color.r;t+=n.color.g;p+=n.color.b}else if(n instanceof THREE.DirectionalLight){y.push(n.color.r*n.intensity,n.color.g*n.intensity,n.color.b*n.intensity);u.push(n.position.x,n.position.y,n.position.z)}else if(n instanceof THREE.PointLight){s.push(n.color.r*n.intensity,n.color.g*n.intensity,n.color.b*n.intensity);w.push(n.position.x,n.position.y,n.position.z)}}return{ambient:[i,t,p],directional:{colors:y,positions:u},point:{colors:s,positions:w}}};this.createLineBuffers=function(d){var h,r,m,n=[],
i=[],t=d.geometry.vertices;h=0;for(r=t.length;h<r;h++){m=t[h].position;n.push(m.x,m.y,m.z);i.push(h)}if(n.length){d.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,d.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(n),c.STATIC_DRAW);d.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,d.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(i),c.STATIC_DRAW);d.__webGLLineCount=i.length}};this.createBuffers=function(d,h){var r,m,
n,i,t,p,y,u,s,w,W=[],G=[],T=[],P=[],H=[],X=[],K=0,E=d.geometry.geometryChunks[h],F;t=false;r=0;for(m=d.materials.length;r<m;r++){p=d.materials[r];if(p instanceof THREE.MeshFaceMaterial){p=0;for(F=E.materials.length;p<F;p++)if(E.materials[p]&&E.materials[p].shading!=undefined&&E.materials[p].shading==THREE.SmoothShading){t=true;break}}else if(p&&p.shading!=undefined&&p.shading==THREE.SmoothShading){t=true;break}if(t)break}F=t;r=0;for(m=E.faces.length;r<m;r++){n=E.faces[r];i=d.geometry.faces[n];t=i.vertexNormals;
p=i.normal;n=d.geometry.uvs[n];if(i instanceof THREE.Face3){y=d.geometry.vertices[i.a].position;u=d.geometry.vertices[i.b].position;s=d.geometry.vertices[i.c].position;T.push(y.x,y.y,y.z,u.x,u.y,u.z,s.x,s.y,s.z);if(d.geometry.hasTangents){y=d.geometry.vertices[i.a].tangent;u=d.geometry.vertices[i.b].tangent;s=d.geometry.vertices[i.c].tangent;H.push(y.x,y.y,y.z,y.w,u.x,u.y,u.z,u.w,s.x,s.y,s.z,s.w)}if(t.length==3&&F)for(i=0;i<3;i++)P.push(t[i].x,t[i].y,t[i].z);else for(i=0;i<3;i++)P.push(p.x,p.y,p.z);
if(n)for(i=0;i<3;i++)X.push(n[i].u,n[i].v);W.push(K,K+1,K+2);G.push(K,K+1,K,K+2,K+1,K+2);K+=3}else if(i instanceof THREE.Face4){y=d.geometry.vertices[i.a].position;u=d.geometry.vertices[i.b].position;s=d.geometry.vertices[i.c].position;w=d.geometry.vertices[i.d].position;T.push(y.x,y.y,y.z,u.x,u.y,u.z,s.x,s.y,s.z,w.x,w.y,w.z);if(d.geometry.hasTangents){y=d.geometry.vertices[i.a].tangent;u=d.geometry.vertices[i.b].tangent;s=d.geometry.vertices[i.c].tangent;i=d.geometry.vertices[i.d].tangent;H.push(y.x,
y.y,y.z,y.w,u.x,u.y,u.z,u.w,s.x,s.y,s.z,s.w,i.x,i.y,i.z,i.w)}if(t.length==4&&F)for(i=0;i<4;i++)P.push(t[i].x,t[i].y,t[i].z);else for(i=0;i<4;i++)P.push(p.x,p.y,p.z);if(n)for(i=0;i<4;i++)X.push(n[i].u,n[i].v);W.push(K,K+1,K+2,K,K+2,K+3);G.push(K,K+1,K,K+2,K,K+3,K+1,K+2,K+2,K+3);K+=4}}if(T.length){E.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,E.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(T),c.STATIC_DRAW);E.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,
h.near;d.uniforms.fogFar.value=h.far}else if(h instanceof THREE.FogExp2)d.uniforms.fogDensity.value=h.density}}function g(d,h){var q;if(d=="fragment")q=c.createShader(c.FRAGMENT_SHADER);else if(d=="vertex")q=c.createShader(c.VERTEX_SHADER);c.shaderSource(q,h);c.compileShader(q);if(!c.getShaderParameter(q,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(q));return null}return q}function j(d){switch(d){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 p=document.createElement("canvas"),c,k=null,m=new THREE.Matrix4,B,D=new Float32Array(16),x=new Float32Array(16),A=new Float32Array(16),
M=new Float32Array(9),Q=new Float32Array(16),O=true,s=new THREE.Color(0),L=0;if(a){if(a.antialias!==undefined)O=a.antialias;a.clearColor!==undefined&&s.setHex(a.clearColor);if(a.clearAlpha!==undefined)L=a.clearAlpha}this.domElement=p;this.autoClear=true;(function(d,h,q){try{c=p.getContext("experimental-webgl",{antialias:d})}catch(n){}if(!c){alert("WebGL not supported");throw"cannot create webgl context";}c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);
c.cullFace(c.BACK);c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(h.r,h.g,h.b,q)})(O,s,L);this.setSize=function(d,h){p.width=d;p.height=h;c.viewport(0,0,p.width,p.height)};this.setClearColor=function(d,h){var q=new THREE.Color(d);c.clearColor(q.r,q.g,q.b,h)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(d,h){var q,n,l,i=0,u=0,o=0,y=[],t=[],r=[],w=[];q=0;for(n=h.length;q<n;q++){l=h[q];if(l instanceof THREE.AmbientLight){i+=
l.color.r;u+=l.color.g;o+=l.color.b}else if(l instanceof THREE.DirectionalLight){y.push(l.color.r*l.intensity,l.color.g*l.intensity,l.color.b*l.intensity);t.push(l.position.x,l.position.y,l.position.z)}else if(l instanceof THREE.PointLight){r.push(l.color.r*l.intensity,l.color.g*l.intensity,l.color.b*l.intensity);w.push(l.position.x,l.position.y,l.position.z)}}return{ambient:[i,u,o],directional:{colors:y,positions:t},point:{colors:r,positions:w}}};this.createParticleBuffers=function(){};this.createLineBuffers=
function(d){var h,q,n,l=[],i=[],u=d.geometry.vertices;h=0;for(q=u.length;h<q;h++){n=u[h].position;l.push(n.x,n.y,n.z);i.push(h)}if(l.length){d.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,d.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(l),c.STATIC_DRAW);d.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,d.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(i),c.STATIC_DRAW);d.__webGLLineCount=i.length}};this.createBuffers=
function(d,h){var q,n,l,i,u,o,y,t,r,w,W=[],G=[],T=[],P=[],H=[],X=[],K=0,E=d.geometry.geometryChunks[h],F;u=false;q=0;for(n=d.materials.length;q<n;q++){o=d.materials[q];if(o instanceof THREE.MeshFaceMaterial){o=0;for(F=E.materials.length;o<F;o++)if(E.materials[o]&&E.materials[o].shading!=undefined&&E.materials[o].shading==THREE.SmoothShading){u=true;break}}else if(o&&o.shading!=undefined&&o.shading==THREE.SmoothShading){u=true;break}if(u)break}F=u;q=0;for(n=E.faces.length;q<n;q++){l=E.faces[q];i=d.geometry.faces[l];
u=i.vertexNormals;o=i.normal;l=d.geometry.uvs[l];if(i instanceof THREE.Face3){y=d.geometry.vertices[i.a].position;t=d.geometry.vertices[i.b].position;r=d.geometry.vertices[i.c].position;T.push(y.x,y.y,y.z,t.x,t.y,t.z,r.x,r.y,r.z);if(d.geometry.hasTangents){y=d.geometry.vertices[i.a].tangent;t=d.geometry.vertices[i.b].tangent;r=d.geometry.vertices[i.c].tangent;H.push(y.x,y.y,y.z,y.w,t.x,t.y,t.z,t.w,r.x,r.y,r.z,r.w)}if(u.length==3&&F)for(i=0;i<3;i++)P.push(u[i].x,u[i].y,u[i].z);else for(i=0;i<3;i++)P.push(o.x,
o.y,o.z);if(l)for(i=0;i<3;i++)X.push(l[i].u,l[i].v);W.push(K,K+1,K+2);G.push(K,K+1,K,K+2,K+1,K+2);K+=3}else if(i instanceof THREE.Face4){y=d.geometry.vertices[i.a].position;t=d.geometry.vertices[i.b].position;r=d.geometry.vertices[i.c].position;w=d.geometry.vertices[i.d].position;T.push(y.x,y.y,y.z,t.x,t.y,t.z,r.x,r.y,r.z,w.x,w.y,w.z);if(d.geometry.hasTangents){y=d.geometry.vertices[i.a].tangent;t=d.geometry.vertices[i.b].tangent;r=d.geometry.vertices[i.c].tangent;i=d.geometry.vertices[i.d].tangent;
H.push(y.x,y.y,y.z,y.w,t.x,t.y,t.z,t.w,r.x,r.y,r.z,r.w,i.x,i.y,i.z,i.w)}if(u.length==4&&F)for(i=0;i<4;i++)P.push(u[i].x,u[i].y,u[i].z);else for(i=0;i<4;i++)P.push(o.x,o.y,o.z);if(l)for(i=0;i<4;i++)X.push(l[i].u,l[i].v);W.push(K,K+1,K+2,K,K+2,K+3);G.push(K,K+1,K,K+2,K,K+3,K+1,K+2,K+2,K+3);K+=4}}if(T.length){E.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,E.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(T),c.STATIC_DRAW);E.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,
E.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(P),c.STATIC_DRAW);if(d.geometry.hasTangents){E.__webGLTangentBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,E.__webGLTangentBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(H),c.STATIC_DRAW)}if(X.length>0){E.__webGLUVBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,E.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(X),c.STATIC_DRAW)}E.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,
E.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(W),c.STATIC_DRAW);E.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,E.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(G),c.STATIC_DRAW);E.__webGLFaceCount=W.length;E.__webGLLineCount=G.length}};this.renderBuffer=function(d,h,r,m,n){var i,t,p,y;if(!m.program){if(m instanceof THREE.MeshDepthMaterial){b(m,THREE.ShaderLib.depth);m.uniforms.mNear.value=d.near;m.uniforms.mFar.value=d.far}else if(m instanceof
THREE.MeshNormalMaterial)b(m,THREE.ShaderLib.normal);else if(m instanceof THREE.MeshBasicMaterial){b(m,THREE.ShaderLib.basic);f(m,r)}else if(m instanceof THREE.MeshLambertMaterial){b(m,THREE.ShaderLib.lambert);f(m,r)}else if(m instanceof THREE.MeshPhongMaterial){b(m,THREE.ShaderLib.phong);f(m,r)}else if(m instanceof THREE.LineBasicMaterial){b(m,THREE.ShaderLib.basic);e(m,r)}if(scene){var u,s,w;u=y=t=0;for(s=h.length;u<s;u++){w=h[u];w instanceof THREE.DirectionalLight&&y++;w instanceof THREE.PointLight&&
t++}if(t+y<=4){u=y;t=t}else{u=Math.ceil(4*y/(t+y));t=4-u}t={directional:u,point:t}}else t={directional:1,point:3};y={fog:r,map:m.map,env_map:m.env_map,maxDirLights:t.directional,maxPointLights:t.point};t=m.fragment_shader;u=m.vertex_shader;s=c.createProgram();w=["#ifdef GL_ES\nprecision highp float;\n#endif","#define MAX_DIR_LIGHTS "+y.maxDirLights,"#define MAX_POINT_LIGHTS "+y.maxPointLights,y.fog?"#define USE_FOG":"",y.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",y.map?"#define USE_MAP":"",
y.env_map?"#define USE_ENVMAP":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");y=[c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+y.maxDirLights,"#define MAX_POINT_LIGHTS "+y.maxPointLights,y.map?"#define USE_MAP":"",y.env_map?"#define USE_ENVMAP":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"].join("\n");
c.attachShader(s,g("fragment",w+t));c.attachShader(s,g("vertex",y+u));c.linkProgram(s);c.getProgramParameter(s,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(s,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");s.uniforms={};s.attributes={};m.program=s;t=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(i in m.uniforms)t.push(i);i=m.program;u=0;for(s=t.length;u<s;u++){w=t[u];i.uniforms[w]=c.getUniformLocation(i,
w)}i=m.program;t=["position","normal","uv","tangent"];u=0;for(s=t.length;u<s;u++){w=t[u];i.attributes[w]=c.getAttribLocation(i,w)}}i=m.program;if(i!=k){c.useProgram(i);k=i}this.loadCamera(i,d);this.loadMatrices(i);if(m instanceof THREE.MeshPhongMaterial||m instanceof THREE.MeshLambertMaterial){d=this.setupLights(i,h);m.uniforms.enableLighting.value=d.directional.positions.length+d.point.positions.length;m.uniforms.ambientLightColor.value=d.ambient;m.uniforms.directionalLightColor.value=d.directional.colors;
m.uniforms.directionalLightDirection.value=d.directional.positions;m.uniforms.pointLightColor.value=d.point.colors;m.uniforms.pointLightPosition.value=d.point.positions}if(m instanceof THREE.MeshBasicMaterial||m instanceof THREE.MeshLambertMaterial||m instanceof THREE.MeshPhongMaterial)f(m,r);m instanceof THREE.LineBasicMaterial&&e(m,r);if(m instanceof THREE.MeshPhongMaterial){m.uniforms.ambient.value.setRGB(m.ambient.r,m.ambient.g,m.ambient.b);m.uniforms.specular.value.setRGB(m.specular.r,m.specular.g,
m.specular.b);m.uniforms.shininess.value=m.shininess}r=m.uniforms;for(p in r)if(t=i.uniforms[p]){h=r[p].type;d=r[p].value;if(h=="i")c.uniform1i(t,d);else if(h=="f")c.uniform1f(t,d);else if(h=="fv")c.uniform3fv(t,d);else if(h=="v2")c.uniform2f(t,d.x,d.y);else if(h=="v3")c.uniform3f(t,d.x,d.y,d.z);else if(h=="c")c.uniform3f(t,d.r,d.g,d.b);else if(h=="t"){c.uniform1i(t,d);if(h=r[p].texture)if(h.image instanceof Array&&h.image.length==6){h=h;d=d;if(h.image.length==6){if(!h.image.__webGLTextureCube&&!h.image.__cubeMapInitialized&&
h.image.loadCount==6){h.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,h.image.__webGLTextureCube);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(t=0;t<6;++t)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,
h.image[t]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);h.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+d);c.bindTexture(c.TEXTURE_CUBE_MAP,h.image.__webGLTextureCube)}}else{h=h;d=d;if(!h.__webGLTexture&&h.image.loaded){h.__webGLTexture=c.createTexture();c.bindTexture(c.TEXTURE_2D,h.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,h.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,j(h.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,
j(h.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,j(h.mag_filter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,j(h.min_filter));c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+d);c.bindTexture(c.TEXTURE_2D,h.__webGLTexture)}}}p=i.attributes;c.bindBuffer(c.ARRAY_BUFFER,n.__webGLVertexBuffer);c.vertexAttribPointer(p.position,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(p.position);if(p.normal>=0){c.bindBuffer(c.ARRAY_BUFFER,n.__webGLNormalBuffer);
c.vertexAttribPointer(p.normal,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(p.normal)}if(p.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,n.__webGLTangentBuffer);c.vertexAttribPointer(p.tangent,4,c.FLOAT,false,0,0);c.enableVertexAttribArray(p.tangent)}if(p.uv>=0)if(n.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,n.__webGLUVBuffer);c.vertexAttribPointer(p.uv,2,c.FLOAT,false,0,0);c.enableVertexAttribArray(p.uv)}else c.disableVertexAttribArray(p.uv);if(m.wireframe||m instanceof THREE.LineBasicMaterial){p=
m.wireframe_linewidth!==undefined?m.wireframe_linewidth:m.linewidth!==undefined?m.linewidth:1;m=m instanceof THREE.LineBasicMaterial&&n.type==THREE.LineStrip?c.LINE_STRIP:c.LINES;c.lineWidth(p);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,n.__webGLLineBuffer);c.drawElements(m,n.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,n.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,n.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(d,h,r,m,n,i,t){var p,y,u,s,w;u=0;for(s=
m.materials.length;u<s;u++){p=m.materials[u];if(p instanceof THREE.MeshFaceMaterial){p=0;for(y=n.materials.length;p<y;p++)if((w=n.materials[p])&&w.blending==i&&w.opacity<1==t){this.setBlending(w.blending);this.renderBuffer(d,h,r,w,n)}}else if((w=p)&&w.blending==i&&w.opacity<1==t){this.setBlending(w.blending);this.renderBuffer(d,h,r,w,n)}}};this.render=function(d,h){var r,m,n,i,t=d.lights,p=d.fog;this.initWebGLObjects(d);this.autoClear&&this.clear();h.autoUpdateMatrix&&h.updateMatrix();D.set(h.matrix.flatten());
A.set(h.projectionMatrix.flatten());r=0;for(m=d.__webGLObjects.length;r<m;r++){n=d.__webGLObjects[r];i=n.object;n=n.buffer;if(i.visible){this.setupMatrices(i,h);this.renderPass(h,t,p,i,n,THREE.NormalBlending,false)}}r=0;for(m=d.__webGLObjects.length;r<m;r++){n=d.__webGLObjects[r];i=n.object;n=n.buffer;if(i.visible){this.setupMatrices(i,h);this.renderPass(h,t,p,i,n,THREE.AdditiveBlending,false);this.renderPass(h,t,p,i,n,THREE.SubtractiveBlending,false);this.renderPass(h,t,p,i,n,THREE.AdditiveBlending,
true);this.renderPass(h,t,p,i,n,THREE.SubtractiveBlending,true);this.renderPass(h,t,p,i,n,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(d){var h,r,m,n,i,t;if(!d.__webGLObjects){d.__webGLObjects=[];d.__webGLObjectsMap={}}h=0;for(r=d.objects.length;h<r;h++){m=d.objects[h];if(d.__webGLObjectsMap[m.id]==undefined)d.__webGLObjectsMap[m.id]={};t=d.__webGLObjectsMap[m.id];if(m instanceof THREE.Mesh)for(i in m.geometry.geometryChunks){n=m.geometry.geometryChunks[i];n.__webGLVertexBuffer||this.createBuffers(m,
i);if(t[i]==undefined){n={buffer:n,object:m};d.__webGLObjects.push(n);t[i]=1}}else if(m instanceof THREE.Line){m.__webGLVertexBuffer||this.createLineBuffers(m);i=0;if(t[i]==undefined){n={buffer:m,object:m};d.__webGLObjects.push(n);t[i]=1}}}};this.removeObject=function(d,h){var r,m;for(r=d.__webGLObjects.length-1;r>=0;r--){m=d.__webGLObjects[r].object;h==m&&d.__webGLObjects.splice(r,1)}};this.setupMatrices=function(d,h){d.autoUpdateMatrix&&d.updateMatrix();l.multiply(h.matrix,d.matrix);x.set(l.flatten());
B=THREE.Matrix4.makeInvert3x3(l).transpose();M.set(B.m);Q.set(d.matrix.flatten())};this.loadMatrices=function(d){c.uniformMatrix4fv(d.uniforms.viewMatrix,false,D);c.uniformMatrix4fv(d.uniforms.modelViewMatrix,false,x);c.uniformMatrix4fv(d.uniforms.projectionMatrix,false,A);c.uniformMatrix3fv(d.uniforms.normalMatrix,false,M);c.uniformMatrix4fv(d.uniforms.objectMatrix,false,Q)};this.loadCamera=function(d,h){c.uniform3f(d.uniforms.cameraPosition,h.position.x,h.position.y,h.position.z)};this.setBlending=
function(d){switch(d){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(d,h){if(d){!h||h=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(d=="back")c.cullFace(c.BACK);else d=="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}};
E.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(W),c.STATIC_DRAW);E.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,E.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(G),c.STATIC_DRAW);E.__webGLFaceCount=W.length;E.__webGLLineCount=G.length}};this.renderBuffer=function(d,h,q,n,l){var i,u,o,y;if(!n.program){if(n instanceof THREE.MeshDepthMaterial){b(n,THREE.ShaderLib.depth);n.uniforms.mNear.value=d.near;n.uniforms.mFar.value=d.far}else if(n instanceof
THREE.MeshNormalMaterial)b(n,THREE.ShaderLib.normal);else if(n instanceof THREE.MeshBasicMaterial){b(n,THREE.ShaderLib.basic);f(n,q)}else if(n instanceof THREE.MeshLambertMaterial){b(n,THREE.ShaderLib.lambert);f(n,q)}else if(n instanceof THREE.MeshPhongMaterial){b(n,THREE.ShaderLib.phong);f(n,q)}else if(n instanceof THREE.LineBasicMaterial){b(n,THREE.ShaderLib.basic);e(n,q)}var t,r,w;t=y=u=0;for(r=h.length;t<r;t++){w=h[t];w instanceof THREE.DirectionalLight&&y++;w instanceof THREE.PointLight&&u++}if(u+
y<=4){t=y;u=u}else{t=Math.ceil(4*y/(u+y));u=4-t}u={directional:t,point:u};y={fog:q,map:n.map,env_map:n.env_map,maxDirLights:u.directional,maxPointLights:u.point};u=n.fragment_shader;t=n.vertex_shader;r=c.createProgram();w=["#ifdef GL_ES\nprecision highp float;\n#endif","#define MAX_DIR_LIGHTS "+y.maxDirLights,"#define MAX_POINT_LIGHTS "+y.maxPointLights,y.fog?"#define USE_FOG":"",y.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",y.map?"#define USE_MAP":"",y.env_map?"#define USE_ENVMAP":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");
y=[c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+y.maxDirLights,"#define MAX_POINT_LIGHTS "+y.maxPointLights,y.map?"#define USE_MAP":"",y.env_map?"#define USE_ENVMAP":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"].join("\n");c.attachShader(r,
g("fragment",w+u));c.attachShader(r,g("vertex",y+t));c.linkProgram(r);c.getProgramParameter(r,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(r,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");r.uniforms={};r.attributes={};n.program=r;u=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(i in n.uniforms)u.push(i);i=n.program;t=0;for(r=u.length;t<r;t++){w=u[t];i.uniforms[w]=c.getUniformLocation(i,w)}i=
n.program;u=["position","normal","uv","tangent"];t=0;for(r=u.length;t<r;t++){w=u[t];i.attributes[w]=c.getAttribLocation(i,w)}}i=n.program;if(i!=k){c.useProgram(i);k=i}this.loadCamera(i,d);this.loadMatrices(i);if(n instanceof THREE.MeshPhongMaterial||n instanceof THREE.MeshLambertMaterial){d=this.setupLights(i,h);n.uniforms.enableLighting.value=d.directional.positions.length+d.point.positions.length;n.uniforms.ambientLightColor.value=d.ambient;n.uniforms.directionalLightColor.value=d.directional.colors;
n.uniforms.directionalLightDirection.value=d.directional.positions;n.uniforms.pointLightColor.value=d.point.colors;n.uniforms.pointLightPosition.value=d.point.positions}if(n instanceof THREE.MeshBasicMaterial||n instanceof THREE.MeshLambertMaterial||n instanceof THREE.MeshPhongMaterial)f(n,q);n instanceof THREE.LineBasicMaterial&&e(n,q);if(n instanceof THREE.MeshPhongMaterial){n.uniforms.ambient.value.setRGB(n.ambient.r,n.ambient.g,n.ambient.b);n.uniforms.specular.value.setRGB(n.specular.r,n.specular.g,
n.specular.b);n.uniforms.shininess.value=n.shininess}q=n.uniforms;for(o in q)if(u=i.uniforms[o]){h=q[o].type;d=q[o].value;if(h=="i")c.uniform1i(u,d);else if(h=="f")c.uniform1f(u,d);else if(h=="fv")c.uniform3fv(u,d);else if(h=="v2")c.uniform2f(u,d.x,d.y);else if(h=="v3")c.uniform3f(u,d.x,d.y,d.z);else if(h=="c")c.uniform3f(u,d.r,d.g,d.b);else if(h=="t"){c.uniform1i(u,d);if(h=q[o].texture)if(h.image instanceof Array&&h.image.length==6){h=h;d=d;if(h.image.length==6){if(!h.image.__webGLTextureCube&&!h.image.__cubeMapInitialized&&
h.image.loadCount==6){h.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,h.image.__webGLTextureCube);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(u=0;u<6;++u)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+u,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,
h.image[u]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);h.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+d);c.bindTexture(c.TEXTURE_CUBE_MAP,h.image.__webGLTextureCube)}}else{h=h;d=d;if(!h.__webGLTexture&&h.image.loaded){h.__webGLTexture=c.createTexture();c.bindTexture(c.TEXTURE_2D,h.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,h.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,j(h.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,
j(h.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,j(h.mag_filter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,j(h.min_filter));c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+d);c.bindTexture(c.TEXTURE_2D,h.__webGLTexture)}}}o=i.attributes;c.bindBuffer(c.ARRAY_BUFFER,l.__webGLVertexBuffer);c.vertexAttribPointer(o.position,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.position);if(o.normal>=0){c.bindBuffer(c.ARRAY_BUFFER,l.__webGLNormalBuffer);
c.vertexAttribPointer(o.normal,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.normal)}if(o.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,l.__webGLTangentBuffer);c.vertexAttribPointer(o.tangent,4,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.tangent)}if(o.uv>=0)if(l.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,l.__webGLUVBuffer);c.vertexAttribPointer(o.uv,2,c.FLOAT,false,0,0);c.enableVertexAttribArray(o.uv)}else c.disableVertexAttribArray(o.uv);if(n.wireframe||n instanceof THREE.LineBasicMaterial){o=
n.wireframe_linewidth!==undefined?n.wireframe_linewidth:n.linewidth!==undefined?n.linewidth:1;n=n instanceof THREE.LineBasicMaterial&&l.type==THREE.LineStrip?c.LINE_STRIP:c.LINES;c.lineWidth(o);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,l.__webGLLineBuffer);c.drawElements(n,l.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,l.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,l.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(d,h,q,n,l,i,u){var o,y,t,r,w;t=0;for(r=
n.materials.length;t<r;t++){o=n.materials[t];if(o instanceof THREE.MeshFaceMaterial){o=0;for(y=l.materials.length;o<y;o++)if((w=l.materials[o])&&w.blending==i&&w.opacity<1==u){this.setBlending(w.blending);this.renderBuffer(d,h,q,w,l)}}else if((w=o)&&w.blending==i&&w.opacity<1==u){this.setBlending(w.blending);this.renderBuffer(d,h,q,w,l)}}};this.render=function(d,h){var q,n,l,i,u=d.lights,o=d.fog;this.initWebGLObjects(d);this.autoClear&&this.clear();h.autoUpdateMatrix&&h.updateMatrix();D.set(h.matrix.flatten());
A.set(h.projectionMatrix.flatten());q=0;for(n=d.__webGLObjects.length;q<n;q++){l=d.__webGLObjects[q];i=l.object;l=l.buffer;if(i.visible){this.setupMatrices(i,h);this.renderPass(h,u,o,i,l,THREE.NormalBlending,false)}}q=0;for(n=d.__webGLObjects.length;q<n;q++){l=d.__webGLObjects[q];i=l.object;l=l.buffer;if(i.visible){this.setupMatrices(i,h);this.renderPass(h,u,o,i,l,THREE.AdditiveBlending,false);this.renderPass(h,u,o,i,l,THREE.SubtractiveBlending,false);this.renderPass(h,u,o,i,l,THREE.AdditiveBlending,
true);this.renderPass(h,u,o,i,l,THREE.SubtractiveBlending,true);this.renderPass(h,u,o,i,l,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(d){function h(y,t,r,w){if(y[t]==undefined){d.__webGLObjects.push({buffer:r,object:w});y[t]=1}}var q,n,l,i,u,o;if(!d.__webGLObjects){d.__webGLObjects=[];d.__webGLObjectsMap={}}q=0;for(n=d.objects.length;q<n;q++){l=d.objects[q];if(d.__webGLObjectsMap[l.id]==undefined)d.__webGLObjectsMap[l.id]={};o=d.__webGLObjectsMap[l.id];if(l instanceof THREE.Mesh)for(i in l.geometry.geometryChunks){u=
l.geometry.geometryChunks[i];u.__webGLVertexBuffer||this.createBuffers(l,i);h(o,i,u,l)}else if(l instanceof THREE.Line){l.__webGLVertexBuffer||this.createLineBuffers(l);h(o,0,l,l)}else if(l instanceof THREE.ParticleSystem){l.__webGLVertexBuffer||this.createParticleBuffers(l);h(o,0,l,l)}}};this.removeObject=function(d,h){var q,n;for(q=d.__webGLObjects.length-1;q>=0;q--){n=d.__webGLObjects[q].object;h==n&&d.__webGLObjects.splice(q,1)}};this.setupMatrices=function(d,h){d.autoUpdateMatrix&&d.updateMatrix();
m.multiply(h.matrix,d.matrix);x.set(m.flatten());B=THREE.Matrix4.makeInvert3x3(m).transpose();M.set(B.m);Q.set(d.matrix.flatten())};this.loadMatrices=function(d){c.uniformMatrix4fv(d.uniforms.viewMatrix,false,D);c.uniformMatrix4fv(d.uniforms.modelViewMatrix,false,x);c.uniformMatrix4fv(d.uniforms.projectionMatrix,false,A);c.uniformMatrix3fv(d.uniforms.normalMatrix,false,M);c.uniformMatrix4fv(d.uniforms.objectMatrix,false,Q)};this.loadCamera=function(d,h){c.uniform3f(d.uniforms.cameraPosition,h.position.x,
h.position.y,h.position.z)};this.setBlending=function(d){switch(d){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(d,h){if(d){!h||h=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(d=="back")c.cullFace(c.BACK);else d=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)};
this.supportsVertexTextures=function(){return c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}};
THREE.Snippets={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, 1.0 ), fogFactor );\n#endif",envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube env_map;\nuniform int combine;\n#endif",
envmap_fragment:"#ifdef USE_ENVMAP\ncubeColor = textureCube( env_map, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = mix( gl_FragColor, cubeColor, reflectivity );\n} else {\ngl_FragColor = gl_FragColor * cubeColor;\n}\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refraction_ratio;\nuniform bool useRefract;\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nif ( useRefract ) {\nvReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refraction_ratio );\n} else {\nvReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );\n}\n#endif",
map_pars_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\n#endif",map_fragment:"#ifdef USE_MAP\nmapColor = texture2D( map, vUv );\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv;\n#endif",lights_pars_vertex:"uniform bool enableLighting;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n#ifdef PHONG\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\n#endif",
+117 -117
View File
@@ -12,21 +12,21 @@ THREE.Vector4=function(a,b,f,e){this.x=a||0;this.y=b||0;this.z=f||0;this.w=e||1}
THREE.Vector4.prototype={set:function(a,b,f,e){this.x=a;this.y=b;this.z=f;this.w=e;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w||1;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;
return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=a;this.w/=a;return this},lerpSelf:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},toString:function(){return"THREE.Vector4 ("+this.x+", "+this.y+", "+this.z+", "+this.w+")"}};
THREE.Ray=function(a,b){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3};
THREE.Ray.prototype={intersectScene:function(a){var b,f,e=a.objects,g=[];a=0;for(b=e.length;a<b;a++){f=e[a];if(f instanceof THREE.Mesh)g=g.concat(this.intersectObject(f))}g.sort(function(h,j){return h.distance-j.distance});return g},intersectObject:function(a){function b(K,p,C,d){d=d.clone().subSelf(p);C=C.clone().subSelf(p);var k=K.clone().subSelf(p);K=d.dot(d);p=d.dot(C);d=d.dot(k);var r=C.dot(C);C=C.dot(k);k=1/(K*r-p*p);r=(r*d-p*C)*k;K=(K*C-p*d)*k;return r>0&&K>0&&r+K<1}var f,e,g,h,j,c,i,m,s,B,
n,v=a.geometry,y=v.vertices,A=[];f=0;for(e=v.faces.length;f<e;f++){g=v.faces[f];B=this.origin.clone();n=this.direction.clone();h=a.matrix.multiplyVector3(y[g.a].position.clone());j=a.matrix.multiplyVector3(y[g.b].position.clone());c=a.matrix.multiplyVector3(y[g.c].position.clone());i=g instanceof THREE.Face4?a.matrix.multiplyVector3(y[g.d].position.clone()):null;m=a.rotationMatrix.multiplyVector3(g.normal.clone());s=n.dot(m);if(s<0){m=m.dot((new THREE.Vector3).sub(h,B))/s;B=B.addSelf(n.multiplyScalar(m));
THREE.Ray.prototype={intersectScene:function(a){var b,f,e=a.objects,g=[];a=0;for(b=e.length;a<b;a++){f=e[a];if(f instanceof THREE.Mesh)g=g.concat(this.intersectObject(f))}g.sort(function(h,j){return h.distance-j.distance});return g},intersectObject:function(a){function b(K,p,E,d){d=d.clone().subSelf(p);E=E.clone().subSelf(p);var k=K.clone().subSelf(p);K=d.dot(d);p=d.dot(E);d=d.dot(k);var q=E.dot(E);E=E.dot(k);k=1/(K*q-p*p);q=(q*d-p*E)*k;K=(K*E-p*d)*k;return q>0&&K>0&&q+K<1}var f,e,g,h,j,c,i,l,r,B,
o,v=a.geometry,z=v.vertices,A=[];f=0;for(e=v.faces.length;f<e;f++){g=v.faces[f];B=this.origin.clone();o=this.direction.clone();h=a.matrix.multiplyVector3(z[g.a].position.clone());j=a.matrix.multiplyVector3(z[g.b].position.clone());c=a.matrix.multiplyVector3(z[g.c].position.clone());i=g instanceof THREE.Face4?a.matrix.multiplyVector3(z[g.d].position.clone()):null;l=a.rotationMatrix.multiplyVector3(g.normal.clone());r=o.dot(l);if(r<0){l=l.dot((new THREE.Vector3).sub(h,B))/r;B=B.addSelf(o.multiplyScalar(l));
if(g instanceof THREE.Face3){if(b(B,h,j,c)){g={distance:this.origin.distanceTo(B),point:B,face:g,object:a};A.push(g)}}else if(g instanceof THREE.Face4)if(b(B,h,j,i)||b(B,j,c,i)){g={distance:this.origin.distanceTo(B),point:B,face:g,object:a};A.push(g)}}}return A}};
THREE.Rectangle=function(){function a(){h=e-b;j=g-f}var b,f,e,g,h,j,c=true;this.getX=function(){return b};this.getY=function(){return f};this.getWidth=function(){return h};this.getHeight=function(){return j};this.getLeft=function(){return b};this.getTop=function(){return f};this.getRight=function(){return e};this.getBottom=function(){return g};this.set=function(i,m,s,B){c=false;b=i;f=m;e=s;g=B;a()};this.addPoint=function(i,m){if(c){c=false;b=i;f=m;e=i;g=m}else{b=b<i?b:i;f=f<m?f:m;e=e>i?e:i;g=g>m?
g:m}a()};this.add3Points=function(i,m,s,B,n,v){if(c){c=false;b=i<s?i<n?i:n:s<n?s:n;f=m<B?m<v?m:v:B<v?B:v;e=i>s?i>n?i:n:s>n?s:n;g=m>B?m>v?m:v:B>v?B:v}else{b=i<s?i<n?i<b?i:b:n<b?n:b:s<n?s<b?s:b:n<b?n:b;f=m<B?m<v?m<f?m:f:v<f?v:f:B<v?B<f?B:f:v<f?v:f;e=i>s?i>n?i>e?i:e:n>e?n:e:s>n?s>e?s:e:n>e?n:e;g=m>B?m>v?m>g?m:g:v>g?v:g:B>v?B>g?B:g:v>g?v:g}a()};this.addRectangle=function(i){if(c){c=false;b=i.getLeft();f=i.getTop();e=i.getRight();g=i.getBottom()}else{b=b<i.getLeft()?b:i.getLeft();f=f<i.getTop()?f:i.getTop();
THREE.Rectangle=function(){function a(){h=e-b;j=g-f}var b,f,e,g,h,j,c=true;this.getX=function(){return b};this.getY=function(){return f};this.getWidth=function(){return h};this.getHeight=function(){return j};this.getLeft=function(){return b};this.getTop=function(){return f};this.getRight=function(){return e};this.getBottom=function(){return g};this.set=function(i,l,r,B){c=false;b=i;f=l;e=r;g=B;a()};this.addPoint=function(i,l){if(c){c=false;b=i;f=l;e=i;g=l}else{b=b<i?b:i;f=f<l?f:l;e=e>i?e:i;g=g>l?
g:l}a()};this.add3Points=function(i,l,r,B,o,v){if(c){c=false;b=i<r?i<o?i:o:r<o?r:o;f=l<B?l<v?l:v:B<v?B:v;e=i>r?i>o?i:o:r>o?r:o;g=l>B?l>v?l:v:B>v?B:v}else{b=i<r?i<o?i<b?i:b:o<b?o:b:r<o?r<b?r:b:o<b?o:b;f=l<B?l<v?l<f?l:f:v<f?v:f:B<v?B<f?B:f:v<f?v:f;e=i>r?i>o?i>e?i:e:o>e?o:e:r>o?r>e?r:e:o>e?o:e;g=l>B?l>v?l>g?l:g:v>g?v:g:B>v?B>g?B:g:v>g?v:g}a()};this.addRectangle=function(i){if(c){c=false;b=i.getLeft();f=i.getTop();e=i.getRight();g=i.getBottom()}else{b=b<i.getLeft()?b:i.getLeft();f=f<i.getTop()?f:i.getTop();
e=e>i.getRight()?e:i.getRight();g=g>i.getBottom()?g:i.getBottom()}a()};this.inflate=function(i){b-=i;f-=i;e+=i;g+=i;a()};this.minSelf=function(i){b=b>i.getLeft()?b:i.getLeft();f=f>i.getTop()?f:i.getTop();e=e<i.getRight()?e:i.getRight();g=g<i.getBottom()?g:i.getBottom();a()};this.instersects=function(i){return Math.min(e,i.getRight())-Math.max(b,i.getLeft())>=0&&Math.min(g,i.getBottom())-Math.max(f,i.getTop())>=0};this.empty=function(){c=true;g=e=f=b=0;a()};this.isEmpty=function(){return c};this.toString=
function(){return"THREE.Rectangle ( left: "+b+", right: "+e+", top: "+f+", bottom: "+g+", width: "+h+", height: "+j+" )"}};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(a,b,f,e,g,h,j,c,i,m,s,B,n,v,y,A){this.n11=a||1;this.n12=b||0;this.n13=f||0;this.n14=e||0;this.n21=g||0;this.n22=h||1;this.n23=j||0;this.n24=c||0;this.n31=i||0;this.n32=m||0;this.n33=s||1;this.n34=B||0;this.n41=n||0;this.n42=v||0;this.n43=y||0;this.n44=A||1};
THREE.Matrix4.prototype={identity:function(){this.n11=1;this.n21=this.n14=this.n13=this.n12=0;this.n22=1;this.n32=this.n31=this.n24=this.n23=0;this.n33=1;this.n43=this.n42=this.n41=this.n34=0;this.n44=1;return this},set:function(a,b,f,e,g,h,j,c,i,m,s,B,n,v,y,A){this.n11=a;this.n12=b;this.n13=f;this.n14=e;this.n21=g;this.n22=h;this.n23=j;this.n24=c;this.n31=i;this.n32=m;this.n33=s;this.n34=B;this.n41=n;this.n42=v;this.n43=y;this.n44=A;return this},copy:function(a){this.n11=a.n11;this.n12=a.n12;this.n13=
THREE.Matrix4=function(a,b,f,e,g,h,j,c,i,l,r,B,o,v,z,A){this.n11=a||1;this.n12=b||0;this.n13=f||0;this.n14=e||0;this.n21=g||0;this.n22=h||1;this.n23=j||0;this.n24=c||0;this.n31=i||0;this.n32=l||0;this.n33=r||1;this.n34=B||0;this.n41=o||0;this.n42=v||0;this.n43=z||0;this.n44=A||1};
THREE.Matrix4.prototype={identity:function(){this.n11=1;this.n21=this.n14=this.n13=this.n12=0;this.n22=1;this.n32=this.n31=this.n24=this.n23=0;this.n33=1;this.n43=this.n42=this.n41=this.n34=0;this.n44=1;return this},set:function(a,b,f,e,g,h,j,c,i,l,r,B,o,v,z,A){this.n11=a;this.n12=b;this.n13=f;this.n14=e;this.n21=g;this.n22=h;this.n23=j;this.n24=c;this.n31=i;this.n32=l;this.n33=r;this.n34=B;this.n41=o;this.n42=v;this.n43=z;this.n44=A;return this},copy:function(a){this.n11=a.n11;this.n12=a.n12;this.n13=
a.n13;this.n14=a.n14;this.n21=a.n21;this.n22=a.n22;this.n23=a.n23;this.n24=a.n24;this.n31=a.n31;this.n32=a.n32;this.n33=a.n33;this.n34=a.n34;this.n41=a.n41;this.n42=a.n42;this.n43=a.n43;this.n44=a.n44;return this},lookAt:function(a,b,f){var e=new THREE.Vector3,g=new THREE.Vector3,h=new THREE.Vector3;h.sub(a,b).normalize();e.cross(f,h).normalize();g.cross(h,e).normalize();this.n11=e.x;this.n12=e.y;this.n13=e.z;this.n14=-e.dot(a);this.n21=g.x;this.n22=g.y;this.n23=g.z;this.n24=-g.dot(a);this.n31=h.x;
this.n32=h.y;this.n33=h.z;this.n34=-h.dot(a);this.n43=this.n42=this.n41=0;this.n44=1;return this},multiplyVector3:function(a){var b=a.x,f=a.y,e=a.z,g=1/(this.n41*b+this.n42*f+this.n43*e+this.n44);a.x=(this.n11*b+this.n12*f+this.n13*e+this.n14)*g;a.y=(this.n21*b+this.n22*f+this.n23*e+this.n24)*g;a.z=(this.n31*b+this.n32*f+this.n33*e+this.n34)*g;return a},multiplyVector4:function(a){var b=a.x,f=a.y,e=a.z,g=a.w;a.x=this.n11*b+this.n12*f+this.n13*e+this.n14*g;a.y=this.n21*b+this.n22*f+this.n23*e+this.n24*
g;a.z=this.n31*b+this.n32*f+this.n33*e+this.n34*g;a.w=this.n41*b+this.n42*f+this.n43*e+this.n44*g;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 f=a.n11,e=a.n12,g=a.n13,h=a.n14,j=a.n21,c=a.n22,i=a.n23,m=a.n24,s=a.n31,B=a.n32,
n=a.n33,v=a.n34,y=a.n41,A=a.n42,K=a.n43,p=a.n44,C=b.n11,d=b.n12,k=b.n13,r=b.n14,q=b.n21,o=b.n22,l=b.n23,x=b.n24,u=b.n31,E=b.n32,z=b.n33,w=b.n34,D=b.n41,$=b.n42,M=b.n43,U=b.n44;this.n11=f*C+e*q+g*u+h*D;this.n12=f*d+e*o+g*E+h*$;this.n13=f*k+e*l+g*z+h*M;this.n14=f*r+e*x+g*w+h*U;this.n21=j*C+c*q+i*u+m*D;this.n22=j*d+c*o+i*E+m*$;this.n23=j*k+c*l+i*z+m*M;this.n24=j*r+c*x+i*w+m*U;this.n31=s*C+B*q+n*u+v*D;this.n32=s*d+B*o+n*E+v*$;this.n33=s*k+B*l+n*z+v*M;this.n34=s*r+B*x+n*w+v*U;this.n41=y*C+A*q+K*u+p*D;
this.n42=y*d+A*o+K*E+p*$;this.n43=y*k+A*l+K*z+p*M;this.n44=y*r+A*x+K*w+p*U;return this},multiplySelf:function(a){var b=this.n11,f=this.n12,e=this.n13,g=this.n14,h=this.n21,j=this.n22,c=this.n23,i=this.n24,m=this.n31,s=this.n32,B=this.n33,n=this.n34,v=this.n41,y=this.n42,A=this.n43,K=this.n44,p=a.n11,C=a.n21,d=a.n31,k=a.n41,r=a.n12,q=a.n22,o=a.n32,l=a.n42,x=a.n13,u=a.n23,E=a.n33,z=a.n43,w=a.n14,D=a.n24,$=a.n34;a=a.n44;this.n11=b*p+f*C+e*d+g*k;this.n12=b*r+f*q+e*o+g*l;this.n13=b*x+f*u+e*E+g*z;this.n14=
b*w+f*D+e*$+g*a;this.n21=h*p+j*C+c*d+i*k;this.n22=h*r+j*q+c*o+i*l;this.n23=h*x+j*u+c*E+i*z;this.n24=h*w+j*D+c*$+i*a;this.n31=m*p+s*C+B*d+n*k;this.n32=m*r+s*q+B*o+n*l;this.n33=m*x+s*u+B*E+n*z;this.n34=m*w+s*D+B*$+n*a;this.n41=v*p+y*C+A*d+K*k;this.n42=v*r+y*q+A*o+K*l;this.n43=v*x+y*u+A*E+K*z;this.n44=v*w+y*D+A*$+K*a;return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=
g;a.z=this.n31*b+this.n32*f+this.n33*e+this.n34*g;a.w=this.n41*b+this.n42*f+this.n43*e+this.n44*g;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 f=a.n11,e=a.n12,g=a.n13,h=a.n14,j=a.n21,c=a.n22,i=a.n23,l=a.n24,r=a.n31,B=a.n32,
o=a.n33,v=a.n34,z=a.n41,A=a.n42,K=a.n43,p=a.n44,E=b.n11,d=b.n12,k=b.n13,q=b.n14,s=b.n21,n=b.n22,m=b.n23,x=b.n24,t=b.n31,D=b.n32,y=b.n33,w=b.n34,C=b.n41,$=b.n42,M=b.n43,U=b.n44;this.n11=f*E+e*s+g*t+h*C;this.n12=f*d+e*n+g*D+h*$;this.n13=f*k+e*m+g*y+h*M;this.n14=f*q+e*x+g*w+h*U;this.n21=j*E+c*s+i*t+l*C;this.n22=j*d+c*n+i*D+l*$;this.n23=j*k+c*m+i*y+l*M;this.n24=j*q+c*x+i*w+l*U;this.n31=r*E+B*s+o*t+v*C;this.n32=r*d+B*n+o*D+v*$;this.n33=r*k+B*m+o*y+v*M;this.n34=r*q+B*x+o*w+v*U;this.n41=z*E+A*s+K*t+p*C;
this.n42=z*d+A*n+K*D+p*$;this.n43=z*k+A*m+K*y+p*M;this.n44=z*q+A*x+K*w+p*U;return this},multiplySelf:function(a){var b=this.n11,f=this.n12,e=this.n13,g=this.n14,h=this.n21,j=this.n22,c=this.n23,i=this.n24,l=this.n31,r=this.n32,B=this.n33,o=this.n34,v=this.n41,z=this.n42,A=this.n43,K=this.n44,p=a.n11,E=a.n21,d=a.n31,k=a.n41,q=a.n12,s=a.n22,n=a.n32,m=a.n42,x=a.n13,t=a.n23,D=a.n33,y=a.n43,w=a.n14,C=a.n24,$=a.n34;a=a.n44;this.n11=b*p+f*E+e*d+g*k;this.n12=b*q+f*s+e*n+g*m;this.n13=b*x+f*t+e*D+g*y;this.n14=
b*w+f*C+e*$+g*a;this.n21=h*p+j*E+c*d+i*k;this.n22=h*q+j*s+c*n+i*m;this.n23=h*x+j*t+c*D+i*y;this.n24=h*w+j*C+c*$+i*a;this.n31=l*p+r*E+B*d+o*k;this.n32=l*q+r*s+B*n+o*m;this.n33=l*x+r*t+B*D+o*y;this.n34=l*w+r*C+B*$+o*a;this.n41=v*p+z*E+A*d+K*k;this.n42=v*q+z*s+A*n+K*m;this.n43=v*x+z*t+A*D+K*y;this.n44=v*w+z*C+A*$+K*a;return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=
a;this.n42*=a;this.n43*=a;this.n44*=a;return this},determinant:function(){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,f,e){var g=b[f];b[f]=b[e];
b[e]=g}a(this,"n21","n12");a(this,"n31","n13");a(this,"n32","n23");a(this,"n41","n14");a(this,"n42","n24");a(this,"n43","n34");return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=this.n44;return a},flatten:function(){return[this.n11,this.n21,this.n31,this.n41,this.n12,
@@ -37,9 +37,9 @@ THREE.Matrix4.makeInvert=function(a){var b=new THREE.Matrix4;b.n11=a.n23*a.n34*a
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 f=b[10]*b[5]-b[6]*b[9],e=-b[10]*b[1]+b[2]*b[9],g=b[6]*b[1]-b[2]*b[5],h=-b[10]*b[4]+b[6]*b[8],j=b[10]*b[0]-b[2]*b[8],c=-b[6]*b[0]+b[2]*b[4],i=b[9]*b[4]-b[5]*b[8],m=-b[9]*b[0]+b[1]*b[8],s=b[5]*b[0]-b[1]*b[4];b=b[0]*f+b[1]*h+b[2]*i;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*f;a.m[1]=b*e;a.m[2]=b*g;a.m[3]=b*h;a.m[4]=b*j;a.m[5]=b*c;a.m[6]=b*i;a.m[7]=b*m;a.m[8]=b*s;return a};
THREE.Matrix4.makeInvert3x3=function(a){var b=a.flatten();a=new THREE.Matrix3;var f=b[10]*b[5]-b[6]*b[9],e=-b[10]*b[1]+b[2]*b[9],g=b[6]*b[1]-b[2]*b[5],h=-b[10]*b[4]+b[6]*b[8],j=b[10]*b[0]-b[2]*b[8],c=-b[6]*b[0]+b[2]*b[4],i=b[9]*b[4]-b[5]*b[8],l=-b[9]*b[0]+b[1]*b[8],r=b[5]*b[0]-b[1]*b[4];b=b[0]*f+b[1]*h+b[2]*i;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*f;a.m[1]=b*e;a.m[2]=b*g;a.m[3]=b*h;a.m[4]=b*j;a.m[5]=b*c;a.m[6]=b*i;a.m[7]=b*l;a.m[8]=b*r;return a};
THREE.Matrix4.makeFrustum=function(a,b,f,e,g,h){var j,c,i;j=new THREE.Matrix4;c=2*g/(b-a);i=2*g/(e-f);a=(b+a)/(b-a);f=(e+f)/(e-f);e=-(h+g)/(h-g);g=-2*h*g/(h-g);j.n11=c;j.n12=0;j.n13=a;j.n14=0;j.n21=0;j.n22=i;j.n23=f;j.n24=0;j.n31=0;j.n32=0;j.n33=e;j.n34=g;j.n41=0;j.n42=0;j.n43=-1;j.n44=0;return j};THREE.Matrix4.makePerspective=function(a,b,f,e){var g;a=f*Math.tan(a*Math.PI/360);g=-a;return THREE.Matrix4.makeFrustum(g*b,a*b,g,a,f,e)};
THREE.Matrix4.makeOrtho=function(a,b,f,e,g,h){var j,c,i,m;j=new THREE.Matrix4;c=b-a;i=f-e;m=h-g;a=(b+a)/c;f=(f+e)/i;g=(h+g)/m;j.n11=2/c;j.n12=0;j.n13=0;j.n14=-a;j.n21=0;j.n22=2/i;j.n23=0;j.n24=-f;j.n31=0;j.n32=0;j.n33=-2/m;j.n34=-g;j.n41=0;j.n42=0;j.n43=0;j.n44=1;return j};
THREE.Matrix4.makeOrtho=function(a,b,f,e,g,h){var j,c,i,l;j=new THREE.Matrix4;c=b-a;i=f-e;l=h-g;a=(b+a)/c;f=(f+e)/i;g=(h+g)/l;j.n11=2/c;j.n12=0;j.n13=0;j.n14=-a;j.n21=0;j.n22=2/i;j.n23=0;j.n24=-f;j.n31=0;j.n32=0;j.n33=-2/l;j.n34=-g;j.n41=0;j.n42=0;j.n43=0;j.n44=1;return j};
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,f,e,g){this.a=a;this.b=b;this.c=f;this.centroid=new THREE.Vector3;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.materials=g instanceof Array?g:[g]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
THREE.Face4=function(a,b,f,e,g,h){this.a=a;this.b=b;this.c=f;this.d=e;this.centroid=new THREE.Vector3;this.normal=g instanceof THREE.Vector3?g:new THREE.Vector3;this.vertexNormals=g instanceof Array?g:[];this.materials=h instanceof Array?h:[h]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
@@ -47,13 +47,13 @@ THREE.UV.prototype={copy:function(a){this.u=a.u;this.v=a.v},toString:function(){
THREE.Geometry.prototype={computeCentroids:function(){var a,b,f;a=0;for(b=this.faces.length;a<b;a++){f=this.faces[a];f.centroid.set(0,0,0);if(f instanceof THREE.Face3){f.centroid.addSelf(this.vertices[f.a].position);f.centroid.addSelf(this.vertices[f.b].position);f.centroid.addSelf(this.vertices[f.c].position);f.centroid.divideScalar(3)}else if(f instanceof THREE.Face4){f.centroid.addSelf(this.vertices[f.a].position);f.centroid.addSelf(this.vertices[f.b].position);f.centroid.addSelf(this.vertices[f.c].position);
f.centroid.addSelf(this.vertices[f.d].position);f.centroid.divideScalar(4)}}},computeFaceNormals:function(a){var b,f,e,g,h,j,c=new THREE.Vector3,i=new THREE.Vector3;e=0;for(g=this.vertices.length;e<g;e++){h=this.vertices[e];h.normal.set(0,0,0)}e=0;for(g=this.faces.length;e<g;e++){h=this.faces[e];if(a&&h.vertexNormals.length){c.set(0,0,0);b=0;for(f=h.normal.length;b<f;b++)c.addSelf(h.vertexNormals[b]);c.divideScalar(3)}else{b=this.vertices[h.a];f=this.vertices[h.b];j=this.vertices[h.c];c.sub(j.position,
f.position);i.sub(b.position,f.position);c.crossSelf(i)}c.isZero()||c.normalize();h.normal.copy(c)}},computeVertexNormals:function(){var a,b,f=[],e;a=0;for(b=this.vertices.length;a<b;a++)f[a]=new THREE.Vector3;a=0;for(b=this.faces.length;a<b;a++){e=this.faces[a];if(e instanceof THREE.Face3){f[e.a].addSelf(e.normal);f[e.b].addSelf(e.normal);f[e.c].addSelf(e.normal)}else if(e instanceof THREE.Face4){f[e.a].addSelf(e.normal);f[e.b].addSelf(e.normal);f[e.c].addSelf(e.normal);f[e.d].addSelf(e.normal)}}a=
0;for(b=this.vertices.length;a<b;a++)f[a].normalize();a=0;for(b=this.faces.length;a<b;a++){e=this.faces[a];if(e instanceof THREE.Face3){e.vertexNormals[0]=f[e.a].clone();e.vertexNormals[1]=f[e.b].clone();e.vertexNormals[2]=f[e.c].clone()}else if(e instanceof THREE.Face4){e.vertexNormals[0]=f[e.a].clone();e.vertexNormals[1]=f[e.b].clone();e.vertexNormals[2]=f[e.c].clone();e.vertexNormals[3]=f[e.d].clone()}}},computeTangents:function(){function a(w,D,$,M,U,V,O){h=w.vertices[D].position;j=w.vertices[$].position;
c=w.vertices[M].position;i=g[U];m=g[V];s=g[O];B=j.x-h.x;n=c.x-h.x;v=j.y-h.y;y=c.y-h.y;A=j.z-h.z;K=c.z-h.z;p=m.u-i.u;C=s.u-i.u;d=m.v-i.v;k=s.v-i.v;r=1/(p*k-C*d);l.set((k*B-d*n)*r,(k*v-d*y)*r,(k*A-d*K)*r);x.set((p*n-C*B)*r,(p*y-C*v)*r,(p*K-C*A)*r);q[D].addSelf(l);q[$].addSelf(l);q[M].addSelf(l);o[D].addSelf(x);o[$].addSelf(x);o[M].addSelf(x)}var b,f,e,g,h,j,c,i,m,s,B,n,v,y,A,K,p,C,d,k,r,q=[],o=[],l=new THREE.Vector3,x=new THREE.Vector3,u=new THREE.Vector3,E=new THREE.Vector3,z=new THREE.Vector3;b=0;
for(f=this.vertices.length;b<f;b++){q[b]=new THREE.Vector3;o[b]=new THREE.Vector3}b=0;for(f=this.faces.length;b<f;b++){e=this.faces[b];g=this.uvs[b];if(e instanceof THREE.Face3){a(this,e.a,e.b,e.c,0,1,2);this.vertices[e.a].normal.copy(e.vertexNormals[0]);this.vertices[e.b].normal.copy(e.vertexNormals[1]);this.vertices[e.c].normal.copy(e.vertexNormals[2])}else if(e instanceof THREE.Face4){a(this,e.a,e.b,e.c,0,1,2);a(this,e.a,e.b,e.d,0,1,3);this.vertices[e.a].normal.copy(e.vertexNormals[0]);this.vertices[e.b].normal.copy(e.vertexNormals[1]);
this.vertices[e.c].normal.copy(e.vertexNormals[2]);this.vertices[e.d].normal.copy(e.vertexNormals[3])}}b=0;for(f=this.vertices.length;b<f;b++){z.copy(this.vertices[b].normal);e=q[b];u.copy(e);u.subSelf(z.multiplyScalar(z.dot(e))).normalize();E.cross(this.vertices[b].normal,e);e=E.dot(o[b]);e=e<0?-1:1;this.vertices[b].tangent.set(u.x,u.y,u.z,e)}this.hasTangents=true},computeBoundingBox:function(){var a;if(this.vertices.length>0){this.boundingBox={x:[this.vertices[0].position.x,this.vertices[0].position.x],
0;for(b=this.vertices.length;a<b;a++)f[a].normalize();a=0;for(b=this.faces.length;a<b;a++){e=this.faces[a];if(e instanceof THREE.Face3){e.vertexNormals[0]=f[e.a].clone();e.vertexNormals[1]=f[e.b].clone();e.vertexNormals[2]=f[e.c].clone()}else if(e instanceof THREE.Face4){e.vertexNormals[0]=f[e.a].clone();e.vertexNormals[1]=f[e.b].clone();e.vertexNormals[2]=f[e.c].clone();e.vertexNormals[3]=f[e.d].clone()}}},computeTangents:function(){function a(w,C,$,M,U,V,O){h=w.vertices[C].position;j=w.vertices[$].position;
c=w.vertices[M].position;i=g[U];l=g[V];r=g[O];B=j.x-h.x;o=c.x-h.x;v=j.y-h.y;z=c.y-h.y;A=j.z-h.z;K=c.z-h.z;p=l.u-i.u;E=r.u-i.u;d=l.v-i.v;k=r.v-i.v;q=1/(p*k-E*d);m.set((k*B-d*o)*q,(k*v-d*z)*q,(k*A-d*K)*q);x.set((p*o-E*B)*q,(p*z-E*v)*q,(p*K-E*A)*q);s[C].addSelf(m);s[$].addSelf(m);s[M].addSelf(m);n[C].addSelf(x);n[$].addSelf(x);n[M].addSelf(x)}var b,f,e,g,h,j,c,i,l,r,B,o,v,z,A,K,p,E,d,k,q,s=[],n=[],m=new THREE.Vector3,x=new THREE.Vector3,t=new THREE.Vector3,D=new THREE.Vector3,y=new THREE.Vector3;b=0;
for(f=this.vertices.length;b<f;b++){s[b]=new THREE.Vector3;n[b]=new THREE.Vector3}b=0;for(f=this.faces.length;b<f;b++){e=this.faces[b];g=this.uvs[b];if(e instanceof THREE.Face3){a(this,e.a,e.b,e.c,0,1,2);this.vertices[e.a].normal.copy(e.vertexNormals[0]);this.vertices[e.b].normal.copy(e.vertexNormals[1]);this.vertices[e.c].normal.copy(e.vertexNormals[2])}else if(e instanceof THREE.Face4){a(this,e.a,e.b,e.c,0,1,2);a(this,e.a,e.b,e.d,0,1,3);this.vertices[e.a].normal.copy(e.vertexNormals[0]);this.vertices[e.b].normal.copy(e.vertexNormals[1]);
this.vertices[e.c].normal.copy(e.vertexNormals[2]);this.vertices[e.d].normal.copy(e.vertexNormals[3])}}b=0;for(f=this.vertices.length;b<f;b++){y.copy(this.vertices[b].normal);e=s[b];t.copy(e);t.subSelf(y.multiplyScalar(y.dot(e))).normalize();D.cross(this.vertices[b].normal,e);e=D.dot(n[b]);e=e<0?-1:1;this.vertices[b].tangent.set(t.x,t.y,t.z,e)}this.hasTangents=true},computeBoundingBox:function(){var a;if(this.vertices.length>0){this.boundingBox={x:[this.vertices[0].position.x,this.vertices[0].position.x],
y:[this.vertices[0].position.y,this.vertices[0].position.y],z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var b=1,f=this.vertices.length;b<f;b++){a=this.vertices[b];if(a.position.x<this.boundingBox.x[0])this.boundingBox.x[0]=a.position.x;else if(a.position.x>this.boundingBox.x[1])this.boundingBox.x[1]=a.position.x;if(a.position.y<this.boundingBox.y[0])this.boundingBox.y[0]=a.position.y;else if(a.position.y>this.boundingBox.y[1])this.boundingBox.y[1]=a.position.y;if(a.position.z<
this.boundingBox.z[0])this.boundingBox.z[0]=a.position.z;else if(a.position.z>this.boundingBox.z[1])this.boundingBox.z[1]=a.position.z}}},computeBoundingSphere:function(){for(var a=this.boundingSphere===null?0:this.boundingSphere.radius,b=0,f=this.vertices.length;b<f;b++)a=Math.max(a,this.vertices[b].position.length());this.boundingSphere={radius:a}},sortFacesByMaterial:function(){function a(s){var B=[];b=0;for(f=s.length;b<f;b++)s[b]==undefined?B.push("undefined"):B.push(s[b].toString());return B.join("_")}
var b,f,e,g,h,j,c,i,m={};e=0;for(g=this.faces.length;e<g;e++){h=this.faces[e];j=h.materials;c=a(j);if(m[c]==undefined)m[c]={hash:c,counter:0};i=m[c].hash+"_"+m[c].counter;if(this.geometryChunks[i]==undefined)this.geometryChunks[i]={faces:[],materials:j,vertices:0};h=h instanceof THREE.Face3?3:4;if(this.geometryChunks[i].vertices+h>65535){m[c].counter+=1;i=m[c].hash+"_"+m[c].counter;if(this.geometryChunks[i]==undefined)this.geometryChunks[i]={faces:[],materials:j,vertices:0}}this.geometryChunks[i].faces.push(e);
this.boundingBox.z[0])this.boundingBox.z[0]=a.position.z;else if(a.position.z>this.boundingBox.z[1])this.boundingBox.z[1]=a.position.z}}},computeBoundingSphere:function(){for(var a=this.boundingSphere===null?0:this.boundingSphere.radius,b=0,f=this.vertices.length;b<f;b++)a=Math.max(a,this.vertices[b].position.length());this.boundingSphere={radius:a}},sortFacesByMaterial:function(){function a(r){var B=[];b=0;for(f=r.length;b<f;b++)r[b]==undefined?B.push("undefined"):B.push(r[b].toString());return B.join("_")}
var b,f,e,g,h,j,c,i,l={};e=0;for(g=this.faces.length;e<g;e++){h=this.faces[e];j=h.materials;c=a(j);if(l[c]==undefined)l[c]={hash:c,counter:0};i=l[c].hash+"_"+l[c].counter;if(this.geometryChunks[i]==undefined)this.geometryChunks[i]={faces:[],materials:j,vertices:0};h=h instanceof THREE.Face3?3:4;if(this.geometryChunks[i].vertices+h>65535){l[c].counter+=1;i=l[c].hash+"_"+l[c].counter;if(this.geometryChunks[i]==undefined)this.geometryChunks[i]={faces:[],materials:j,vertices:0}}this.geometryChunks[i].faces.push(e);
this.geometryChunks[i].vertices+=h}},toString:function(){return"THREE.Geometry ( vertices: "+this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
THREE.Camera=function(a,b,f,e){this.fov=a;this.aspect=b;this.near=f;this.far=e;this.position=new THREE.Vector3;this.target={position:new THREE.Vector3};this.autoUpdateMatrix=true;this.projectionMatrix=null;this.matrix=new THREE.Matrix4;this.up=new THREE.Vector3(0,1,0);this.translateX=function(g){g=this.target.position.clone().subSelf(this.position).normalize().multiplyScalar(g);g.cross(g.clone(),this.up);this.position.addSelf(g);this.target.position.addSelf(g)};this.translateZ=function(g){g=this.target.position.clone().subSelf(this.position).normalize().multiplyScalar(g);
this.position.subSelf(g);this.target.position.subSelf(g)};this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.updateProjectionMatrix=function(){this.projectionMatrix=THREE.Matrix4.makePerspective(this.fov,this.aspect,this.near,this.far)};this.updateProjectionMatrix()};THREE.Camera.prototype={toString:function(){return"THREE.Camera ( "+this.position+", "+this.target.position+" )"}};THREE.Light=function(a){this.color=new THREE.Color(a)};
@@ -96,85 +96,85 @@ THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLine
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.fog=null;this.addObject=function(a){this.objects.indexOf(a)===-1&&this.objects.push(a)};this.removeObject=function(a){a=this.objects.indexOf(a);a!==-1&&this.objects.splice(a,1)};this.addLight=function(a){this.lights.indexOf(a)===-1&&this.lights.push(a)};this.removeLight=function(a){a=this.lights.indexOf(a);a!==-1&&this.lights.splice(a,1)};this.toString=function(){return"THREE.Scene ( "+this.objects+" )"}};
THREE.Fog=function(a,b,f){this.color=new THREE.Color(a);this.near=b||1;this.far=f||1E3};THREE.FogExp2=function(a,b){this.color=new THREE.Color(a);this.density=b||2.5E-4};
THREE.Projector=function(){function a(o,l){return l.z-o.z}function b(o,l){var x=0,u=1,E=o.z+o.w,z=l.z+l.w,w=-o.z+o.w,D=-l.z+l.w;if(E>=0&&z>=0&&w>=0&&D>=0)return true;else if(E<0&&z<0||w<0&&D<0)return false;else{if(E<0)x=Math.max(x,E/(E-z));else if(z<0)u=Math.min(u,E/(E-z));if(w<0)x=Math.max(x,w/(w-D));else if(D<0)u=Math.min(u,w/(w-D));if(u<x)return false;else{o.lerpSelf(l,x);l.lerpSelf(o,1-u);return true}}}var f,e,g=[],h,j,c,i=[],m,s,B=[],n,v,y=[],A=new THREE.Vector4,K=new THREE.Vector4,p=new THREE.Matrix4,
C=new THREE.Matrix4,d=[],k=new THREE.Vector4,r=new THREE.Vector4,q;this.projectObjects=function(o,l,x){var u=[],E,z;e=0;p.multiply(l.projectionMatrix,l.matrix);d[0]=new THREE.Vector4(p.n41-p.n11,p.n42-p.n12,p.n43-p.n13,p.n44-p.n14);d[1]=new THREE.Vector4(p.n41+p.n11,p.n42+p.n12,p.n43+p.n13,p.n44+p.n14);d[2]=new THREE.Vector4(p.n41+p.n21,p.n42+p.n22,p.n43+p.n23,p.n44+p.n24);d[3]=new THREE.Vector4(p.n41-p.n21,p.n42-p.n22,p.n43-p.n23,p.n44-p.n24);d[4]=new THREE.Vector4(p.n41-p.n31,p.n42-p.n32,p.n43-
p.n33,p.n44-p.n34);d[5]=new THREE.Vector4(p.n41+p.n31,p.n42+p.n32,p.n43+p.n33,p.n44+p.n34);l=0;for(E=d.length;l<E;l++){z=d[l];z.divideScalar(Math.sqrt(z.x*z.x+z.y*z.y+z.z*z.z))}E=o.objects;o=0;for(l=E.length;o<l;o++){z=E[o];var w;if(!(w=!z.visible)){if(w=z instanceof THREE.Mesh){a:{w=void 0;for(var D=z.position,$=-z.geometry.boundingSphere.radius*Math.max(z.scale.x,Math.max(z.scale.y,z.scale.z)),M=0;M<6;M++){w=d[M].x*D.x+d[M].y*D.y+d[M].z*D.z+d[M].w;if(w<=$){w=false;break a}}w=true}w=!w}w=w}if(!w){f=
g[e]=g[e]||new THREE.RenderableObject;A.copy(z.position);p.multiplyVector3(A);f.object=z;f.z=A.z;u.push(f);e++}}x&&u.sort(a);return u};this.projectScene=function(o,l,x){var u=[],E=l.near,z=l.far,w,D,$,M,U,V,O,ba,R,L,N,Z,W,I,S,Y;c=s=v=0;l.autoUpdateMatrix&&l.updateMatrix();p.multiply(l.projectionMatrix,l.matrix);V=this.projectObjects(o,l,true);o=0;for(w=V.length;o<w;o++){O=V[o].object;if(O.visible){O.autoUpdateMatrix&&O.updateMatrix();ba=O.matrix;R=O.rotationMatrix;L=O.materials;N=O.overdraw;if(O instanceof
THREE.Mesh){Z=O.geometry;W=Z.vertices;D=0;for($=W.length;D<$;D++){I=W[D];I.positionWorld.copy(I.position);ba.multiplyVector3(I.positionWorld);M=I.positionScreen;M.copy(I.positionWorld);p.multiplyVector4(M);M.x/=M.w;M.y/=M.w;I.__visible=M.z>E&&M.z<z}Z=Z.faces;D=0;for($=Z.length;D<$;D++){I=Z[D];if(I instanceof THREE.Face3){M=W[I.a];U=W[I.b];S=W[I.c];if(M.__visible&&U.__visible&&S.__visible)if(O.doubleSided||O.flipSided!=(S.positionScreen.x-M.positionScreen.x)*(U.positionScreen.y-M.positionScreen.y)-
THREE.Projector=function(){function a(n,m){return m.z-n.z}function b(n,m){var x=0,t=1,D=n.z+n.w,y=m.z+m.w,w=-n.z+n.w,C=-m.z+m.w;if(D>=0&&y>=0&&w>=0&&C>=0)return true;else if(D<0&&y<0||w<0&&C<0)return false;else{if(D<0)x=Math.max(x,D/(D-y));else if(y<0)t=Math.min(t,D/(D-y));if(w<0)x=Math.max(x,w/(w-C));else if(C<0)t=Math.min(t,w/(w-C));if(t<x)return false;else{n.lerpSelf(m,x);m.lerpSelf(n,1-t);return true}}}var f,e,g=[],h,j,c,i=[],l,r,B=[],o,v,z=[],A=new THREE.Vector4,K=new THREE.Vector4,p=new THREE.Matrix4,
E=new THREE.Matrix4,d=[],k=new THREE.Vector4,q=new THREE.Vector4,s;this.projectObjects=function(n,m,x){var t=[],D,y;e=0;p.multiply(m.projectionMatrix,m.matrix);d[0]=new THREE.Vector4(p.n41-p.n11,p.n42-p.n12,p.n43-p.n13,p.n44-p.n14);d[1]=new THREE.Vector4(p.n41+p.n11,p.n42+p.n12,p.n43+p.n13,p.n44+p.n14);d[2]=new THREE.Vector4(p.n41+p.n21,p.n42+p.n22,p.n43+p.n23,p.n44+p.n24);d[3]=new THREE.Vector4(p.n41-p.n21,p.n42-p.n22,p.n43-p.n23,p.n44-p.n24);d[4]=new THREE.Vector4(p.n41-p.n31,p.n42-p.n32,p.n43-
p.n33,p.n44-p.n34);d[5]=new THREE.Vector4(p.n41+p.n31,p.n42+p.n32,p.n43+p.n33,p.n44+p.n34);m=0;for(D=d.length;m<D;m++){y=d[m];y.divideScalar(Math.sqrt(y.x*y.x+y.y*y.y+y.z*y.z))}D=n.objects;n=0;for(m=D.length;n<m;n++){y=D[n];var w;if(!(w=!y.visible)){if(w=y instanceof THREE.Mesh){a:{w=void 0;for(var C=y.position,$=-y.geometry.boundingSphere.radius*Math.max(y.scale.x,Math.max(y.scale.y,y.scale.z)),M=0;M<6;M++){w=d[M].x*C.x+d[M].y*C.y+d[M].z*C.z+d[M].w;if(w<=$){w=false;break a}}w=true}w=!w}w=w}if(!w){f=
g[e]=g[e]||new THREE.RenderableObject;A.copy(y.position);p.multiplyVector3(A);f.object=y;f.z=A.z;t.push(f);e++}}x&&t.sort(a);return t};this.projectScene=function(n,m,x){var t=[],D=m.near,y=m.far,w,C,$,M,U,V,O,ba,R,L,N,Z,W,I,S,Y;c=r=v=0;m.autoUpdateMatrix&&m.updateMatrix();p.multiply(m.projectionMatrix,m.matrix);V=this.projectObjects(n,m,true);n=0;for(w=V.length;n<w;n++){O=V[n].object;if(O.visible){O.autoUpdateMatrix&&O.updateMatrix();ba=O.matrix;R=O.rotationMatrix;L=O.materials;N=O.overdraw;if(O instanceof
THREE.Mesh){Z=O.geometry;W=Z.vertices;C=0;for($=W.length;C<$;C++){I=W[C];I.positionWorld.copy(I.position);ba.multiplyVector3(I.positionWorld);M=I.positionScreen;M.copy(I.positionWorld);p.multiplyVector4(M);M.x/=M.w;M.y/=M.w;I.__visible=M.z>D&&M.z<y}Z=Z.faces;C=0;for($=Z.length;C<$;C++){I=Z[C];if(I instanceof THREE.Face3){M=W[I.a];U=W[I.b];S=W[I.c];if(M.__visible&&U.__visible&&S.__visible)if(O.doubleSided||O.flipSided!=(S.positionScreen.x-M.positionScreen.x)*(U.positionScreen.y-M.positionScreen.y)-
(S.positionScreen.y-M.positionScreen.y)*(U.positionScreen.x-M.positionScreen.x)<0){h=i[c]=i[c]||new THREE.RenderableFace3;h.v1.positionWorld.copy(M.positionWorld);h.v2.positionWorld.copy(U.positionWorld);h.v3.positionWorld.copy(S.positionWorld);h.v1.positionScreen.copy(M.positionScreen);h.v2.positionScreen.copy(U.positionScreen);h.v3.positionScreen.copy(S.positionScreen);h.normalWorld.copy(I.normal);R.multiplyVector3(h.normalWorld);h.centroidWorld.copy(I.centroid);ba.multiplyVector3(h.centroidWorld);
h.centroidScreen.copy(h.centroidWorld);p.multiplyVector3(h.centroidScreen);S=I.vertexNormals;q=h.vertexNormalsWorld;M=0;for(U=S.length;M<U;M++){Y=q[M]=q[M]||new THREE.Vector3;Y.copy(S[M]);R.multiplyVector3(Y)}h.z=h.centroidScreen.z;h.meshMaterials=L;h.faceMaterials=I.materials;h.overdraw=N;if(O.geometry.uvs[D]){h.uvs[0]=O.geometry.uvs[D][0];h.uvs[1]=O.geometry.uvs[D][1];h.uvs[2]=O.geometry.uvs[D][2]}u.push(h);c++}}else if(I instanceof THREE.Face4){M=W[I.a];U=W[I.b];S=W[I.c];Y=W[I.d];if(M.__visible&&
h.centroidScreen.copy(h.centroidWorld);p.multiplyVector3(h.centroidScreen);S=I.vertexNormals;s=h.vertexNormalsWorld;M=0;for(U=S.length;M<U;M++){Y=s[M]=s[M]||new THREE.Vector3;Y.copy(S[M]);R.multiplyVector3(Y)}h.z=h.centroidScreen.z;h.meshMaterials=L;h.faceMaterials=I.materials;h.overdraw=N;if(O.geometry.uvs[C]){h.uvs[0]=O.geometry.uvs[C][0];h.uvs[1]=O.geometry.uvs[C][1];h.uvs[2]=O.geometry.uvs[C][2]}t.push(h);c++}}else if(I instanceof THREE.Face4){M=W[I.a];U=W[I.b];S=W[I.c];Y=W[I.d];if(M.__visible&&
U.__visible&&S.__visible&&Y.__visible)if(O.doubleSided||O.flipSided!=((Y.positionScreen.x-M.positionScreen.x)*(U.positionScreen.y-M.positionScreen.y)-(Y.positionScreen.y-M.positionScreen.y)*(U.positionScreen.x-M.positionScreen.x)<0||(U.positionScreen.x-S.positionScreen.x)*(Y.positionScreen.y-S.positionScreen.y)-(U.positionScreen.y-S.positionScreen.y)*(Y.positionScreen.x-S.positionScreen.x)<0)){h=i[c]=i[c]||new THREE.RenderableFace3;h.v1.positionWorld.copy(M.positionWorld);h.v2.positionWorld.copy(U.positionWorld);
h.v3.positionWorld.copy(Y.positionWorld);h.v1.positionScreen.copy(M.positionScreen);h.v2.positionScreen.copy(U.positionScreen);h.v3.positionScreen.copy(Y.positionScreen);h.normalWorld.copy(I.normal);R.multiplyVector3(h.normalWorld);h.centroidWorld.copy(I.centroid);ba.multiplyVector3(h.centroidWorld);h.centroidScreen.copy(h.centroidWorld);p.multiplyVector3(h.centroidScreen);h.z=h.centroidScreen.z;h.meshMaterials=L;h.faceMaterials=I.materials;h.overdraw=N;if(O.geometry.uvs[D]){h.uvs[0]=O.geometry.uvs[D][0];
h.uvs[1]=O.geometry.uvs[D][1];h.uvs[2]=O.geometry.uvs[D][3]}u.push(h);c++;j=i[c]=i[c]||new THREE.RenderableFace3;j.v1.positionWorld.copy(U.positionWorld);j.v2.positionWorld.copy(S.positionWorld);j.v3.positionWorld.copy(Y.positionWorld);j.v1.positionScreen.copy(U.positionScreen);j.v2.positionScreen.copy(S.positionScreen);j.v3.positionScreen.copy(Y.positionScreen);j.normalWorld.copy(h.normalWorld);j.centroidWorld.copy(h.centroidWorld);j.centroidScreen.copy(h.centroidScreen);j.z=j.centroidScreen.z;j.meshMaterials=
L;j.faceMaterials=I.materials;j.overdraw=N;if(O.geometry.uvs[D]){j.uvs[0]=O.geometry.uvs[D][1];j.uvs[1]=O.geometry.uvs[D][2];j.uvs[2]=O.geometry.uvs[D][3]}u.push(j);c++}}}}else if(O instanceof THREE.Line){C.multiply(p,ba);W=O.geometry.vertices;I=W[0];I.positionScreen.copy(I.position);C.multiplyVector4(I.positionScreen);D=1;for($=W.length;D<$;D++){M=W[D];M.positionScreen.copy(M.position);C.multiplyVector4(M.positionScreen);U=W[D-1];k.copy(M.positionScreen);r.copy(U.positionScreen);if(b(k,r)){k.multiplyScalar(1/
k.w);r.multiplyScalar(1/r.w);m=B[s]=B[s]||new THREE.RenderableLine;m.v1.positionScreen.copy(k);m.v2.positionScreen.copy(r);m.z=Math.max(k.z,r.z);m.materials=O.materials;u.push(m);s++}}}else if(O instanceof THREE.Particle){K.set(O.position.x,O.position.y,O.position.z,1);p.multiplyVector4(K);K.z/=K.w;if(K.z>0&&K.z<1){n=y[v]=y[v]||new THREE.RenderableParticle;n.x=K.x/K.w;n.y=K.y/K.w;n.z=K.z;n.rotation=O.rotation.z;n.scale.x=O.scale.x*Math.abs(n.x-(K.x+l.projectionMatrix.n11)/(K.w+l.projectionMatrix.n14));
n.scale.y=O.scale.y*Math.abs(n.y-(K.y+l.projectionMatrix.n22)/(K.w+l.projectionMatrix.n24));n.materials=O.materials;u.push(n);v++}}}}x&&u.sort(a);return u};this.unprojectVector=function(o,l){var x=new THREE.Matrix4;x.multiply(THREE.Matrix4.makeInvert(l.matrix),THREE.Matrix4.makeInvert(l.projectionMatrix));x.multiplyVector3(o);return o}};
THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,f,e,g,h;this.domElement=document.createElement("div");this.setSize=function(j,c){f=j;e=c;g=f/2;h=e/2};this.render=function(j,c){var i,m,s,B,n,v,y,A;a=b.projectScene(j,c);i=0;for(m=a.length;i<m;i++){n=a[i];if(n instanceof THREE.RenderableParticle){y=n.x*g+g;A=n.y*h+h;s=0;for(B=n.material.length;s<B;s++){v=n.material[s];if(v instanceof THREE.ParticleDOMMaterial){v=v.domElement;v.style.left=y+"px";v.style.top=A+"px"}}}}}};
THREE.CanvasRenderer=function(){function a(ga){if(n!=ga)m.globalAlpha=n=ga}function b(ga){if(v!=ga){switch(ga){case THREE.NormalBlending:m.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:m.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:m.globalCompositeOperation="darker"}v=ga}}var f=null,e=new THREE.Projector,g=document.createElement("canvas"),h,j,c,i,m=g.getContext("2d"),s=null,B=null,n=1,v=0,y=null,A=null,K=1,p,C,d,k,r,q,o,l,x,u=new THREE.Color,
E=new THREE.Color,z=new THREE.Color,w=new THREE.Color,D=new THREE.Color,$,M,U,V,O,ba,R,L,N,Z=new THREE.Rectangle,W=new THREE.Rectangle,I=new THREE.Rectangle,S=false,Y=new THREE.Color,ha=new THREE.Color,ja=new THREE.Color,t=new THREE.Color,G=Math.PI*2,H=new THREE.Vector3,Q,aa,ka,ea,ra,ta,va=16;Q=document.createElement("canvas");Q.width=Q.height=2;aa=Q.getContext("2d");aa.fillStyle="rgba(0,0,0,1)";aa.fillRect(0,0,2,2);ka=aa.getImageData(0,0,2,2);ea=ka.data;ra=document.createElement("canvas");ra.width=
ra.height=va;ta=ra.getContext("2d");ta.translate(-va/2,-va/2);ta.scale(va,va);va--;this.domElement=g;this.sortElements=this.sortObjects=this.autoClear=true;this.setSize=function(ga,sa){h=ga;j=sa;c=h/2;i=j/2;g.width=h;g.height=j;Z.set(-c,-i,c,i)};this.setClearColor=function(ga,sa){s=ga!==null?new THREE.Color(ga):null;B=sa;W.set(-c,-i,c,i);m.setTransform(1,0,0,-1,c,i);this.clear()};this.clear=function(){if(!W.isEmpty()){W.inflate(1);W.minSelf(Z);if(s!==null){b(THREE.NormalBlending);a(1);m.fillStyle=
"rgba("+Math.floor(s.r*255)+","+Math.floor(s.g*255)+","+Math.floor(s.b*255)+","+B+")";m.fillRect(W.getX(),W.getY(),W.getWidth(),W.getHeight())}else m.clearRect(W.getX(),W.getY(),W.getWidth(),W.getHeight());W.empty()}};this.render=function(ga,sa){function Ma(F){var X,T,J,P=F.lights;ha.setRGB(0,0,0);ja.setRGB(0,0,0);t.setRGB(0,0,0);F=0;for(X=P.length;F<X;F++){T=P[F];J=T.color;if(T instanceof THREE.AmbientLight){ha.r+=J.r;ha.g+=J.g;ha.b+=J.b}else if(T instanceof THREE.DirectionalLight){ja.r+=J.r;ja.g+=
J.g;ja.b+=J.b}else if(T instanceof THREE.PointLight){t.r+=J.r;t.g+=J.g;t.b+=J.b}}}function Aa(F,X,T,J){var P,ca,fa,ia,la=F.lights;F=0;for(P=la.length;F<P;F++){ca=la[F];fa=ca.color;ia=ca.intensity;if(ca instanceof THREE.DirectionalLight){ca=T.dot(ca.position)*ia;if(ca>0){J.r+=fa.r*ca;J.g+=fa.g*ca;J.b+=fa.b*ca}}else if(ca instanceof THREE.PointLight){H.sub(ca.position,X);H.normalize();ca=T.dot(H)*ia;if(ca>0){J.r+=fa.r*ca;J.g+=fa.g*ca;J.b+=fa.b*ca}}}}function Na(F,X,T){if(T.opacity!=0){a(T.opacity);
b(T.blending);var J,P,ca,fa,ia,la;if(T instanceof THREE.ParticleBasicMaterial){if(T.map){fa=T.map;ia=fa.width>>1;la=fa.height>>1;P=X.scale.x*c;ca=X.scale.y*i;T=P*ia;J=ca*la;I.set(F.x-T,F.y-J,F.x+T,F.y+J);if(Z.instersects(I)){m.save();m.translate(F.x,F.y);m.rotate(-X.rotation);m.scale(P,-ca);m.translate(-ia,-la);m.drawImage(fa,0,0);m.restore()}}}else if(T instanceof THREE.ParticleCircleMaterial){if(S){Y.r=ha.r+ja.r+t.r;Y.g=ha.g+ja.g+t.g;Y.b=ha.b+ja.b+t.b;u.r=T.color.r*Y.r;u.g=T.color.g*Y.g;u.b=T.color.b*
Y.b;u.updateStyleString()}else u.__styleString=T.color.__styleString;T=X.scale.x*c;J=X.scale.y*i;I.set(F.x-T,F.y-J,F.x+T,F.y+J);if(Z.instersects(I)){P=u.__styleString;if(A!=P)m.fillStyle=A=P;m.save();m.translate(F.x,F.y);m.rotate(-X.rotation);m.scale(T,J);m.beginPath();m.arc(0,0,1,0,G,true);m.closePath();m.fill();m.restore()}}}}function Oa(F,X,T,J){if(J.opacity!=0){a(J.opacity);b(J.blending);m.beginPath();m.moveTo(F.positionScreen.x,F.positionScreen.y);m.lineTo(X.positionScreen.x,X.positionScreen.y);
m.closePath();if(J instanceof THREE.LineBasicMaterial){u.__styleString=J.color.__styleString;F=J.linewidth;if(K!=F)m.lineWidth=K=F;F=u.__styleString;if(y!=F)m.strokeStyle=y=F;m.stroke();I.inflate(J.linewidth*2)}}}function Ia(F,X,T,J,P,ca){if(P.opacity!=0){a(P.opacity);b(P.blending);k=F.positionScreen.x;r=F.positionScreen.y;q=X.positionScreen.x;o=X.positionScreen.y;l=T.positionScreen.x;x=T.positionScreen.y;m.beginPath();m.moveTo(k,r);m.lineTo(q,o);m.lineTo(l,x);m.lineTo(k,r);m.closePath();if(P instanceof
THREE.MeshBasicMaterial)if(P.map)P.map.image.loaded&&P.map.mapping instanceof THREE.UVMapping&&xa(k,r,q,o,l,x,P.map.image,J.uvs[0].u,J.uvs[0].v,J.uvs[1].u,J.uvs[1].v,J.uvs[2].u,J.uvs[2].v);else if(P.env_map){if(P.env_map.image.loaded)if(P.env_map.mapping instanceof THREE.SphericalReflectionMapping){F=sa.matrix;H.copy(J.vertexNormalsWorld[0]);V=(H.x*F.n11+H.y*F.n12+H.z*F.n13)*0.5+0.5;O=-(H.x*F.n21+H.y*F.n22+H.z*F.n23)*0.5+0.5;H.copy(J.vertexNormalsWorld[1]);ba=(H.x*F.n11+H.y*F.n12+H.z*F.n13)*0.5+0.5;
R=-(H.x*F.n21+H.y*F.n22+H.z*F.n23)*0.5+0.5;H.copy(J.vertexNormalsWorld[2]);L=(H.x*F.n11+H.y*F.n12+H.z*F.n13)*0.5+0.5;N=-(H.x*F.n21+H.y*F.n22+H.z*F.n23)*0.5+0.5;xa(k,r,q,o,l,x,P.env_map.image,V,O,ba,R,L,N)}}else P.wireframe?Ba(P.color.__styleString,P.wireframe_linewidth):Ca(P.color.__styleString);else if(P instanceof THREE.MeshLambertMaterial){if(P.map&&!P.wireframe){P.map.mapping instanceof THREE.UVMapping&&xa(k,r,q,o,l,x,P.map.image,J.uvs[0].u,J.uvs[0].v,J.uvs[1].u,J.uvs[1].v,J.uvs[2].u,J.uvs[2].v);
b(THREE.SubtractiveBlending)}if(S)if(!P.wireframe&&P.shading==THREE.SmoothShading&&J.vertexNormalsWorld.length==3){E.r=z.r=w.r=ha.r;E.g=z.g=w.g=ha.g;E.b=z.b=w.b=ha.b;Aa(ca,J.v1.positionWorld,J.vertexNormalsWorld[0],E);Aa(ca,J.v2.positionWorld,J.vertexNormalsWorld[1],z);Aa(ca,J.v3.positionWorld,J.vertexNormalsWorld[2],w);D.r=(z.r+w.r)*0.5;D.g=(z.g+w.g)*0.5;D.b=(z.b+w.b)*0.5;U=Ja(E,z,w,D);xa(k,r,q,o,l,x,U,0,0,1,0,0,1)}else{Y.r=ha.r;Y.g=ha.g;Y.b=ha.b;Aa(ca,J.centroidWorld,J.normalWorld,Y);u.r=P.color.r*
Y.r;u.g=P.color.g*Y.g;u.b=P.color.b*Y.b;u.updateStyleString();P.wireframe?Ba(u.__styleString,P.wireframe_linewidth):Ca(u.__styleString)}else P.wireframe?Ba(P.color.__styleString,P.wireframe_linewidth):Ca(P.color.__styleString)}else if(P instanceof THREE.MeshDepthMaterial){$=sa.near;M=sa.far;E.r=E.g=E.b=1-Ea(F.positionScreen.z,$,M);z.r=z.g=z.b=1-Ea(X.positionScreen.z,$,M);w.r=w.g=w.b=1-Ea(T.positionScreen.z,$,M);D.r=(z.r+w.r)*0.5;D.g=(z.g+w.g)*0.5;D.b=(z.b+w.b)*0.5;U=Ja(E,z,w,D);xa(k,r,q,o,l,x,U,0,
0,1,0,0,1)}else if(P instanceof THREE.MeshNormalMaterial){u.r=Fa(J.normalWorld.x);u.g=Fa(J.normalWorld.y);u.b=Fa(J.normalWorld.z);u.updateStyleString();P.wireframe?Ba(u.__styleString,P.wireframe_linewidth):Ca(u.__styleString)}}}function Ba(F,X){if(y!=F)m.strokeStyle=y=F;if(K!=X)m.lineWidth=K=X;m.stroke();I.inflate(X*2)}function Ca(F){if(A!=F)m.fillStyle=A=F;m.fill()}function xa(F,X,T,J,P,ca,fa,ia,la,oa,ma,pa,ya){var ua,qa;ua=fa.width-1;qa=fa.height-1;ia*=ua;la*=qa;oa*=ua;ma*=qa;pa*=ua;ya*=qa;T-=F;
J-=X;P-=F;ca-=X;oa-=ia;ma-=la;pa-=ia;ya-=la;qa=1/(oa*ya-pa*ma);ua=(ya*T-ma*P)*qa;ma=(ya*J-ma*ca)*qa;T=(oa*P-pa*T)*qa;J=(oa*ca-pa*J)*qa;F=F-ua*ia-T*la;X=X-ma*ia-J*la;m.save();m.transform(ua,ma,T,J,F,X);m.clip();m.drawImage(fa,0,0);m.restore()}function Ja(F,X,T,J){var P=~~(F.r*255),ca=~~(F.g*255);F=~~(F.b*255);var fa=~~(X.r*255),ia=~~(X.g*255);X=~~(X.b*255);var la=~~(T.r*255),oa=~~(T.g*255);T=~~(T.b*255);var ma=~~(J.r*255),pa=~~(J.g*255);J=~~(J.b*255);ea[0]=P<0?0:P>255?255:P;ea[1]=ca<0?0:ca>255?255:
h.v3.positionWorld.copy(Y.positionWorld);h.v1.positionScreen.copy(M.positionScreen);h.v2.positionScreen.copy(U.positionScreen);h.v3.positionScreen.copy(Y.positionScreen);h.normalWorld.copy(I.normal);R.multiplyVector3(h.normalWorld);h.centroidWorld.copy(I.centroid);ba.multiplyVector3(h.centroidWorld);h.centroidScreen.copy(h.centroidWorld);p.multiplyVector3(h.centroidScreen);h.z=h.centroidScreen.z;h.meshMaterials=L;h.faceMaterials=I.materials;h.overdraw=N;if(O.geometry.uvs[C]){h.uvs[0]=O.geometry.uvs[C][0];
h.uvs[1]=O.geometry.uvs[C][1];h.uvs[2]=O.geometry.uvs[C][3]}t.push(h);c++;j=i[c]=i[c]||new THREE.RenderableFace3;j.v1.positionWorld.copy(U.positionWorld);j.v2.positionWorld.copy(S.positionWorld);j.v3.positionWorld.copy(Y.positionWorld);j.v1.positionScreen.copy(U.positionScreen);j.v2.positionScreen.copy(S.positionScreen);j.v3.positionScreen.copy(Y.positionScreen);j.normalWorld.copy(h.normalWorld);j.centroidWorld.copy(h.centroidWorld);j.centroidScreen.copy(h.centroidScreen);j.z=j.centroidScreen.z;j.meshMaterials=
L;j.faceMaterials=I.materials;j.overdraw=N;if(O.geometry.uvs[C]){j.uvs[0]=O.geometry.uvs[C][1];j.uvs[1]=O.geometry.uvs[C][2];j.uvs[2]=O.geometry.uvs[C][3]}t.push(j);c++}}}}else if(O instanceof THREE.Line){E.multiply(p,ba);W=O.geometry.vertices;I=W[0];I.positionScreen.copy(I.position);E.multiplyVector4(I.positionScreen);C=1;for($=W.length;C<$;C++){M=W[C];M.positionScreen.copy(M.position);E.multiplyVector4(M.positionScreen);U=W[C-1];k.copy(M.positionScreen);q.copy(U.positionScreen);if(b(k,q)){k.multiplyScalar(1/
k.w);q.multiplyScalar(1/q.w);l=B[r]=B[r]||new THREE.RenderableLine;l.v1.positionScreen.copy(k);l.v2.positionScreen.copy(q);l.z=Math.max(k.z,q.z);l.materials=O.materials;t.push(l);r++}}}else if(O instanceof THREE.Particle){K.set(O.position.x,O.position.y,O.position.z,1);p.multiplyVector4(K);K.z/=K.w;if(K.z>0&&K.z<1){o=z[v]=z[v]||new THREE.RenderableParticle;o.x=K.x/K.w;o.y=K.y/K.w;o.z=K.z;o.rotation=O.rotation.z;o.scale.x=O.scale.x*Math.abs(o.x-(K.x+m.projectionMatrix.n11)/(K.w+m.projectionMatrix.n14));
o.scale.y=O.scale.y*Math.abs(o.y-(K.y+m.projectionMatrix.n22)/(K.w+m.projectionMatrix.n24));o.materials=O.materials;t.push(o);v++}}}}x&&t.sort(a);return t};this.unprojectVector=function(n,m){var x=new THREE.Matrix4;x.multiply(THREE.Matrix4.makeInvert(m.matrix),THREE.Matrix4.makeInvert(m.projectionMatrix));x.multiplyVector3(n);return n}};
THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,f,e,g,h;this.domElement=document.createElement("div");this.setSize=function(j,c){f=j;e=c;g=f/2;h=e/2};this.render=function(j,c){var i,l,r,B,o,v,z,A;a=b.projectScene(j,c);i=0;for(l=a.length;i<l;i++){o=a[i];if(o instanceof THREE.RenderableParticle){z=o.x*g+g;A=o.y*h+h;r=0;for(B=o.material.length;r<B;r++){v=o.material[r];if(v instanceof THREE.ParticleDOMMaterial){v=v.domElement;v.style.left=z+"px";v.style.top=A+"px"}}}}}};
THREE.CanvasRenderer=function(){function a(ga){if(o!=ga)l.globalAlpha=o=ga}function b(ga){if(v!=ga){switch(ga){case THREE.NormalBlending:l.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:l.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:l.globalCompositeOperation="darker"}v=ga}}var f=null,e=new THREE.Projector,g=document.createElement("canvas"),h,j,c,i,l=g.getContext("2d"),r=null,B=null,o=1,v=0,z=null,A=null,K=1,p,E,d,k,q,s,n,m,x,t=new THREE.Color,
D=new THREE.Color,y=new THREE.Color,w=new THREE.Color,C=new THREE.Color,$,M,U,V,O,ba,R,L,N,Z=new THREE.Rectangle,W=new THREE.Rectangle,I=new THREE.Rectangle,S=false,Y=new THREE.Color,ha=new THREE.Color,ja=new THREE.Color,u=new THREE.Color,G=Math.PI*2,H=new THREE.Vector3,Q,aa,ka,ea,ra,ta,va=16;Q=document.createElement("canvas");Q.width=Q.height=2;aa=Q.getContext("2d");aa.fillStyle="rgba(0,0,0,1)";aa.fillRect(0,0,2,2);ka=aa.getImageData(0,0,2,2);ea=ka.data;ra=document.createElement("canvas");ra.width=
ra.height=va;ta=ra.getContext("2d");ta.translate(-va/2,-va/2);ta.scale(va,va);va--;this.domElement=g;this.sortElements=this.sortObjects=this.autoClear=true;this.setSize=function(ga,sa){h=ga;j=sa;c=h/2;i=j/2;g.width=h;g.height=j;Z.set(-c,-i,c,i)};this.setClearColor=function(ga,sa){r=ga!==null?new THREE.Color(ga):null;B=sa;W.set(-c,-i,c,i);l.setTransform(1,0,0,-1,c,i);this.clear()};this.clear=function(){if(!W.isEmpty()){W.inflate(1);W.minSelf(Z);if(r!==null){b(THREE.NormalBlending);a(1);l.fillStyle=
"rgba("+Math.floor(r.r*255)+","+Math.floor(r.g*255)+","+Math.floor(r.b*255)+","+B+")";l.fillRect(W.getX(),W.getY(),W.getWidth(),W.getHeight())}else l.clearRect(W.getX(),W.getY(),W.getWidth(),W.getHeight());W.empty()}};this.render=function(ga,sa){function Ma(F){var X,T,J,P=F.lights;ha.setRGB(0,0,0);ja.setRGB(0,0,0);u.setRGB(0,0,0);F=0;for(X=P.length;F<X;F++){T=P[F];J=T.color;if(T instanceof THREE.AmbientLight){ha.r+=J.r;ha.g+=J.g;ha.b+=J.b}else if(T instanceof THREE.DirectionalLight){ja.r+=J.r;ja.g+=
J.g;ja.b+=J.b}else if(T instanceof THREE.PointLight){u.r+=J.r;u.g+=J.g;u.b+=J.b}}}function Aa(F,X,T,J){var P,ca,fa,ia,la=F.lights;F=0;for(P=la.length;F<P;F++){ca=la[F];fa=ca.color;ia=ca.intensity;if(ca instanceof THREE.DirectionalLight){ca=T.dot(ca.position)*ia;if(ca>0){J.r+=fa.r*ca;J.g+=fa.g*ca;J.b+=fa.b*ca}}else if(ca instanceof THREE.PointLight){H.sub(ca.position,X);H.normalize();ca=T.dot(H)*ia;if(ca>0){J.r+=fa.r*ca;J.g+=fa.g*ca;J.b+=fa.b*ca}}}}function Na(F,X,T){if(T.opacity!=0){a(T.opacity);
b(T.blending);var J,P,ca,fa,ia,la;if(T instanceof THREE.ParticleBasicMaterial){if(T.map){fa=T.map;ia=fa.width>>1;la=fa.height>>1;P=X.scale.x*c;ca=X.scale.y*i;T=P*ia;J=ca*la;I.set(F.x-T,F.y-J,F.x+T,F.y+J);if(Z.instersects(I)){l.save();l.translate(F.x,F.y);l.rotate(-X.rotation);l.scale(P,-ca);l.translate(-ia,-la);l.drawImage(fa,0,0);l.restore()}}}else if(T instanceof THREE.ParticleCircleMaterial){if(S){Y.r=ha.r+ja.r+u.r;Y.g=ha.g+ja.g+u.g;Y.b=ha.b+ja.b+u.b;t.r=T.color.r*Y.r;t.g=T.color.g*Y.g;t.b=T.color.b*
Y.b;t.updateStyleString()}else t.__styleString=T.color.__styleString;T=X.scale.x*c;J=X.scale.y*i;I.set(F.x-T,F.y-J,F.x+T,F.y+J);if(Z.instersects(I)){P=t.__styleString;if(A!=P)l.fillStyle=A=P;l.save();l.translate(F.x,F.y);l.rotate(-X.rotation);l.scale(T,J);l.beginPath();l.arc(0,0,1,0,G,true);l.closePath();l.fill();l.restore()}}}}function Oa(F,X,T,J){if(J.opacity!=0){a(J.opacity);b(J.blending);l.beginPath();l.moveTo(F.positionScreen.x,F.positionScreen.y);l.lineTo(X.positionScreen.x,X.positionScreen.y);
l.closePath();if(J instanceof THREE.LineBasicMaterial){t.__styleString=J.color.__styleString;F=J.linewidth;if(K!=F)l.lineWidth=K=F;F=t.__styleString;if(z!=F)l.strokeStyle=z=F;l.stroke();I.inflate(J.linewidth*2)}}}function Ia(F,X,T,J,P,ca){if(P.opacity!=0){a(P.opacity);b(P.blending);k=F.positionScreen.x;q=F.positionScreen.y;s=X.positionScreen.x;n=X.positionScreen.y;m=T.positionScreen.x;x=T.positionScreen.y;l.beginPath();l.moveTo(k,q);l.lineTo(s,n);l.lineTo(m,x);l.lineTo(k,q);l.closePath();if(P instanceof
THREE.MeshBasicMaterial)if(P.map)P.map.image.loaded&&P.map.mapping instanceof THREE.UVMapping&&xa(k,q,s,n,m,x,P.map.image,J.uvs[0].u,J.uvs[0].v,J.uvs[1].u,J.uvs[1].v,J.uvs[2].u,J.uvs[2].v);else if(P.env_map){if(P.env_map.image.loaded)if(P.env_map.mapping instanceof THREE.SphericalReflectionMapping){F=sa.matrix;H.copy(J.vertexNormalsWorld[0]);V=(H.x*F.n11+H.y*F.n12+H.z*F.n13)*0.5+0.5;O=-(H.x*F.n21+H.y*F.n22+H.z*F.n23)*0.5+0.5;H.copy(J.vertexNormalsWorld[1]);ba=(H.x*F.n11+H.y*F.n12+H.z*F.n13)*0.5+0.5;
R=-(H.x*F.n21+H.y*F.n22+H.z*F.n23)*0.5+0.5;H.copy(J.vertexNormalsWorld[2]);L=(H.x*F.n11+H.y*F.n12+H.z*F.n13)*0.5+0.5;N=-(H.x*F.n21+H.y*F.n22+H.z*F.n23)*0.5+0.5;xa(k,q,s,n,m,x,P.env_map.image,V,O,ba,R,L,N)}}else P.wireframe?Ba(P.color.__styleString,P.wireframe_linewidth):Ca(P.color.__styleString);else if(P instanceof THREE.MeshLambertMaterial){if(P.map&&!P.wireframe){P.map.mapping instanceof THREE.UVMapping&&xa(k,q,s,n,m,x,P.map.image,J.uvs[0].u,J.uvs[0].v,J.uvs[1].u,J.uvs[1].v,J.uvs[2].u,J.uvs[2].v);
b(THREE.SubtractiveBlending)}if(S)if(!P.wireframe&&P.shading==THREE.SmoothShading&&J.vertexNormalsWorld.length==3){D.r=y.r=w.r=ha.r;D.g=y.g=w.g=ha.g;D.b=y.b=w.b=ha.b;Aa(ca,J.v1.positionWorld,J.vertexNormalsWorld[0],D);Aa(ca,J.v2.positionWorld,J.vertexNormalsWorld[1],y);Aa(ca,J.v3.positionWorld,J.vertexNormalsWorld[2],w);C.r=(y.r+w.r)*0.5;C.g=(y.g+w.g)*0.5;C.b=(y.b+w.b)*0.5;U=Ja(D,y,w,C);xa(k,q,s,n,m,x,U,0,0,1,0,0,1)}else{Y.r=ha.r;Y.g=ha.g;Y.b=ha.b;Aa(ca,J.centroidWorld,J.normalWorld,Y);t.r=P.color.r*
Y.r;t.g=P.color.g*Y.g;t.b=P.color.b*Y.b;t.updateStyleString();P.wireframe?Ba(t.__styleString,P.wireframe_linewidth):Ca(t.__styleString)}else P.wireframe?Ba(P.color.__styleString,P.wireframe_linewidth):Ca(P.color.__styleString)}else if(P instanceof THREE.MeshDepthMaterial){$=sa.near;M=sa.far;D.r=D.g=D.b=1-Ea(F.positionScreen.z,$,M);y.r=y.g=y.b=1-Ea(X.positionScreen.z,$,M);w.r=w.g=w.b=1-Ea(T.positionScreen.z,$,M);C.r=(y.r+w.r)*0.5;C.g=(y.g+w.g)*0.5;C.b=(y.b+w.b)*0.5;U=Ja(D,y,w,C);xa(k,q,s,n,m,x,U,0,
0,1,0,0,1)}else if(P instanceof THREE.MeshNormalMaterial){t.r=Fa(J.normalWorld.x);t.g=Fa(J.normalWorld.y);t.b=Fa(J.normalWorld.z);t.updateStyleString();P.wireframe?Ba(t.__styleString,P.wireframe_linewidth):Ca(t.__styleString)}}}function Ba(F,X){if(z!=F)l.strokeStyle=z=F;if(K!=X)l.lineWidth=K=X;l.stroke();I.inflate(X*2)}function Ca(F){if(A!=F)l.fillStyle=A=F;l.fill()}function xa(F,X,T,J,P,ca,fa,ia,la,oa,ma,pa,ya){var ua,qa;ua=fa.width-1;qa=fa.height-1;ia*=ua;la*=qa;oa*=ua;ma*=qa;pa*=ua;ya*=qa;T-=F;
J-=X;P-=F;ca-=X;oa-=ia;ma-=la;pa-=ia;ya-=la;qa=1/(oa*ya-pa*ma);ua=(ya*T-ma*P)*qa;ma=(ya*J-ma*ca)*qa;T=(oa*P-pa*T)*qa;J=(oa*ca-pa*J)*qa;F=F-ua*ia-T*la;X=X-ma*ia-J*la;l.save();l.transform(ua,ma,T,J,F,X);l.clip();l.drawImage(fa,0,0);l.restore()}function Ja(F,X,T,J){var P=~~(F.r*255),ca=~~(F.g*255);F=~~(F.b*255);var fa=~~(X.r*255),ia=~~(X.g*255);X=~~(X.b*255);var la=~~(T.r*255),oa=~~(T.g*255);T=~~(T.b*255);var ma=~~(J.r*255),pa=~~(J.g*255);J=~~(J.b*255);ea[0]=P<0?0:P>255?255:P;ea[1]=ca<0?0:ca>255?255:
ca;ea[2]=F<0?0:F>255?255:F;ea[4]=fa<0?0:fa>255?255:fa;ea[5]=ia<0?0:ia>255?255:ia;ea[6]=X<0?0:X>255?255:X;ea[8]=la<0?0:la>255?255:la;ea[9]=oa<0?0:oa>255?255:oa;ea[10]=T<0?0:T>255?255:T;ea[12]=ma<0?0:ma>255?255:ma;ea[13]=pa<0?0:pa>255?255:pa;ea[14]=J<0?0:J>255?255:J;aa.putImageData(ka,0,0);ta.drawImage(Q,0,0);return ra}function Ea(F,X,T){F=(F-X)/(T-X);return F*F*(3-2*F)}function Fa(F){F=(F+1)*0.5;return F<0?0:F>1?1:F}function Ga(F,X){var T=X.x-F.x,J=X.y-F.y,P=1/Math.sqrt(T*T+J*J);T*=P;J*=P;X.x+=T;X.y+=
J;F.x-=T;F.y-=J}var Da,Ka,da,na,wa,Ha,La,za;m.setTransform(1,0,0,-1,c,i);this.autoClear&&this.clear();f=e.projectScene(ga,sa,this.sortElements);(S=ga.lights.length>0)&&Ma(ga);Da=0;for(Ka=f.length;Da<Ka;Da++){da=f[Da];I.empty();if(da instanceof THREE.RenderableParticle){p=da;p.x*=c;p.y*=i;na=0;for(wa=da.materials.length;na<wa;na++)Na(p,da,da.materials[na],ga)}else if(da instanceof THREE.RenderableLine){p=da.v1;C=da.v2;p.positionScreen.x*=c;p.positionScreen.y*=i;C.positionScreen.x*=c;C.positionScreen.y*=
i;I.addPoint(p.positionScreen.x,p.positionScreen.y);I.addPoint(C.positionScreen.x,C.positionScreen.y);if(Z.instersects(I)){na=0;for(wa=da.materials.length;na<wa;)Oa(p,C,da,da.materials[na++],ga)}}else if(da instanceof THREE.RenderableFace3){p=da.v1;C=da.v2;d=da.v3;p.positionScreen.x*=c;p.positionScreen.y*=i;C.positionScreen.x*=c;C.positionScreen.y*=i;d.positionScreen.x*=c;d.positionScreen.y*=i;if(da.overdraw){Ga(p.positionScreen,C.positionScreen);Ga(C.positionScreen,d.positionScreen);Ga(d.positionScreen,
p.positionScreen)}I.add3Points(p.positionScreen.x,p.positionScreen.y,C.positionScreen.x,C.positionScreen.y,d.positionScreen.x,d.positionScreen.y);if(Z.instersects(I)){na=0;for(wa=da.meshMaterials.length;na<wa;){za=da.meshMaterials[na++];if(za instanceof THREE.MeshFaceMaterial){Ha=0;for(La=da.faceMaterials.length;Ha<La;)(za=da.faceMaterials[Ha++])&&Ia(p,C,d,da,za,ga)}else Ia(p,C,d,da,za,ga)}}}W.addRectangle(I)}m.setTransform(1,0,0,1,0,0)}};
THREE.SVGRenderer=function(){function a(V,O,ba){var R,L,N,Z;R=0;for(L=V.lights.length;R<L;R++){N=V.lights[R];if(N instanceof THREE.DirectionalLight){Z=O.normalWorld.dot(N.position)*N.intensity;if(Z>0){ba.r+=N.color.r*Z;ba.g+=N.color.g*Z;ba.b+=N.color.b*Z}}else if(N instanceof THREE.PointLight){x.sub(N.position,O.centroidWorld);x.normalize();Z=O.normalWorld.dot(x)*N.intensity;if(Z>0){ba.r+=N.color.r*Z;ba.g+=N.color.g*Z;ba.b+=N.color.b*Z}}}}function b(V,O,ba,R,L,N){w=e(D++);w.setAttribute("d","M "+
V.positionScreen.x+" "+V.positionScreen.y+" L "+O.positionScreen.x+" "+O.positionScreen.y+" L "+ba.positionScreen.x+","+ba.positionScreen.y+"z");if(L instanceof THREE.MeshBasicMaterial)d.__styleString=L.color.__styleString;else if(L instanceof THREE.MeshLambertMaterial)if(C){k.r=r.r;k.g=r.g;k.b=r.b;a(N,R,k);d.r=L.color.r*k.r;d.g=L.color.g*k.g;d.b=L.color.b*k.b;d.updateStyleString()}else d.__styleString=L.color.__styleString;else if(L instanceof THREE.MeshDepthMaterial){l=1-L.__2near/(L.__farPlusNear-
R.z*L.__farMinusNear);d.setRGB(l,l,l)}else L instanceof THREE.MeshNormalMaterial&&d.setRGB(g(R.normalWorld.x),g(R.normalWorld.y),g(R.normalWorld.z));L.wireframe?w.setAttribute("style","fill: none; stroke: "+d.__styleString+"; stroke-width: "+L.wireframe_linewidth+"; stroke-opacity: "+L.opacity+"; stroke-linecap: "+L.wireframe_linecap+"; stroke-linejoin: "+L.wireframe_linejoin):w.setAttribute("style","fill: "+d.__styleString+"; fill-opacity: "+L.opacity);c.appendChild(w)}function f(V,O,ba,R,L,N,Z){w=
e(D++);w.setAttribute("d","M "+V.positionScreen.x+" "+V.positionScreen.y+" L "+O.positionScreen.x+" "+O.positionScreen.y+" L "+ba.positionScreen.x+","+ba.positionScreen.y+" L "+R.positionScreen.x+","+R.positionScreen.y+"z");if(N instanceof THREE.MeshBasicMaterial)d.__styleString=N.color.__styleString;else if(N instanceof THREE.MeshLambertMaterial)if(C){k.r=r.r;k.g=r.g;k.b=r.b;a(Z,L,k);d.r=N.color.r*k.r;d.g=N.color.g*k.g;d.b=N.color.b*k.b;d.updateStyleString()}else d.__styleString=N.color.__styleString;
else if(N instanceof THREE.MeshDepthMaterial){l=1-N.__2near/(N.__farPlusNear-L.z*N.__farMinusNear);d.setRGB(l,l,l)}else N instanceof THREE.MeshNormalMaterial&&d.setRGB(g(L.normalWorld.x),g(L.normalWorld.y),g(L.normalWorld.z));N.wireframe?w.setAttribute("style","fill: none; stroke: "+d.__styleString+"; stroke-width: "+N.wireframe_linewidth+"; stroke-opacity: "+N.opacity+"; stroke-linecap: "+N.wireframe_linecap+"; stroke-linejoin: "+N.wireframe_linejoin):w.setAttribute("style","fill: "+d.__styleString+
"; fill-opacity: "+N.opacity);c.appendChild(w)}function e(V){if(u[V]==null){u[V]=document.createElementNS("http://www.w3.org/2000/svg","path");U==0&&u[V].setAttribute("shape-rendering","crispEdges");return u[V]}return u[V]}function g(V){return V<0?Math.min((1+V)*0.5,0.5):0.5+Math.min(V*0.5,0.5)}var h=null,j=new THREE.Projector,c=document.createElementNS("http://www.w3.org/2000/svg","svg"),i,m,s,B,n,v,y,A,K=new THREE.Rectangle,p=new THREE.Rectangle,C=false,d=new THREE.Color(16777215),k=new THREE.Color(16777215),
r=new THREE.Color(0),q=new THREE.Color(0),o=new THREE.Color(0),l,x=new THREE.Vector3,u=[],E=[],z=[],w,D,$,M,U=1;this.domElement=c;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(V){switch(V){case "high":U=1;break;case "low":U=0}};this.setSize=function(V,O){i=V;m=O;s=i/2;B=m/2;c.setAttribute("viewBox",-s+" "+-B+" "+i+" "+m);c.setAttribute("width",i);c.setAttribute("height",m);K.set(-s,-B,s,B)};this.clear=function(){for(;c.childNodes.length>0;)c.removeChild(c.childNodes[0])};
this.render=function(V,O){var ba,R,L,N,Z,W,I,S;this.autoClear&&this.clear();h=j.projectScene(V,O,this.sortElements);M=$=D=0;if(C=V.lights.length>0){I=V.lights;r.setRGB(0,0,0);q.setRGB(0,0,0);o.setRGB(0,0,0);ba=0;for(R=I.length;ba<R;ba++){L=I[ba];N=L.color;if(L instanceof THREE.AmbientLight){r.r+=N.r;r.g+=N.g;r.b+=N.b}else if(L instanceof THREE.DirectionalLight){q.r+=N.r;q.g+=N.g;q.b+=N.b}else if(L instanceof THREE.PointLight){o.r+=N.r;o.g+=N.g;o.b+=N.b}}}ba=0;for(R=h.length;ba<R;ba++){I=h[ba];p.empty();
if(I instanceof THREE.RenderableParticle){n=I;n.x*=s;n.y*=-B;L=0;for(N=I.materials.length;L<N;L++)if(S=I.materials[L]){Z=n;W=I;S=S;var Y=$++;if(E[Y]==null){E[Y]=document.createElementNS("http://www.w3.org/2000/svg","circle");U==0&&E[Y].setAttribute("shape-rendering","crispEdges")}w=E[Y];w.setAttribute("cx",Z.x);w.setAttribute("cy",Z.y);w.setAttribute("r",W.scale.x*s);if(S instanceof THREE.ParticleCircleMaterial){if(C){k.r=r.r+q.r+o.r;k.g=r.g+q.g+o.g;k.b=r.b+q.b+o.b;d.r=S.color.r*k.r;d.g=S.color.g*
k.g;d.b=S.color.b*k.b;d.updateStyleString()}else d=S.color;w.setAttribute("style","fill: "+d.__styleString)}c.appendChild(w)}}else if(I instanceof THREE.RenderableLine){n=I.v1;v=I.v2;n.positionScreen.x*=s;n.positionScreen.y*=-B;v.positionScreen.x*=s;v.positionScreen.y*=-B;p.addPoint(n.positionScreen.x,n.positionScreen.y);p.addPoint(v.positionScreen.x,v.positionScreen.y);if(K.instersects(p)){L=0;for(N=I.materials.length;L<N;)if(S=I.materials[L++]){Z=n;W=v;S=S;Y=M++;if(z[Y]==null){z[Y]=document.createElementNS("http://www.w3.org/2000/svg",
"line");U==0&&z[Y].setAttribute("shape-rendering","crispEdges")}w=z[Y];w.setAttribute("x1",Z.positionScreen.x);w.setAttribute("y1",Z.positionScreen.y);w.setAttribute("x2",W.positionScreen.x);w.setAttribute("y2",W.positionScreen.y);if(S instanceof THREE.LineBasicMaterial){d.__styleString=S.color.__styleString;w.setAttribute("style","fill: none; stroke: "+d.__styleString+"; stroke-width: "+S.linewidth+"; stroke-opacity: "+S.opacity+"; stroke-linecap: "+S.linecap+"; stroke-linejoin: "+S.linejoin);c.appendChild(w)}}}}else if(I instanceof
THREE.RenderableFace3){n=I.v1;v=I.v2;y=I.v3;n.positionScreen.x*=s;n.positionScreen.y*=-B;v.positionScreen.x*=s;v.positionScreen.y*=-B;y.positionScreen.x*=s;y.positionScreen.y*=-B;p.addPoint(n.positionScreen.x,n.positionScreen.y);p.addPoint(v.positionScreen.x,v.positionScreen.y);p.addPoint(y.positionScreen.x,y.positionScreen.y);if(K.instersects(p)){L=0;for(N=I.meshMaterials.length;L<N;){S=I.meshMaterials[L++];if(S instanceof THREE.MeshFaceMaterial){Z=0;for(W=I.faceMaterials.length;Z<W;)(S=I.faceMaterials[Z++])&&
b(n,v,y,I,S,V)}else S&&b(n,v,y,I,S,V)}}}else if(I instanceof THREE.RenderableFace4){n=I.v1;v=I.v2;y=I.v3;A=I.v4;n.positionScreen.x*=s;n.positionScreen.y*=-B;v.positionScreen.x*=s;v.positionScreen.y*=-B;y.positionScreen.x*=s;y.positionScreen.y*=-B;A.positionScreen.x*=s;A.positionScreen.y*=-B;p.addPoint(n.positionScreen.x,n.positionScreen.y);p.addPoint(v.positionScreen.x,v.positionScreen.y);p.addPoint(y.positionScreen.x,y.positionScreen.y);p.addPoint(A.positionScreen.x,A.positionScreen.y);if(K.instersects(p)){L=
0;for(N=I.meshMaterials.length;L<N;){S=I.meshMaterials[L++];if(S instanceof THREE.MeshFaceMaterial){Z=0;for(W=I.faceMaterials.length;Z<W;)(S=I.faceMaterials[Z++])&&f(n,v,y,A,I,S,V)}else S&&f(n,v,y,A,I,S,V)}}}}}};
J;F.x-=T;F.y-=J}var Da,Ka,da,na,wa,Ha,La,za;l.setTransform(1,0,0,-1,c,i);this.autoClear&&this.clear();f=e.projectScene(ga,sa,this.sortElements);(S=ga.lights.length>0)&&Ma(ga);Da=0;for(Ka=f.length;Da<Ka;Da++){da=f[Da];I.empty();if(da instanceof THREE.RenderableParticle){p=da;p.x*=c;p.y*=i;na=0;for(wa=da.materials.length;na<wa;na++)Na(p,da,da.materials[na],ga)}else if(da instanceof THREE.RenderableLine){p=da.v1;E=da.v2;p.positionScreen.x*=c;p.positionScreen.y*=i;E.positionScreen.x*=c;E.positionScreen.y*=
i;I.addPoint(p.positionScreen.x,p.positionScreen.y);I.addPoint(E.positionScreen.x,E.positionScreen.y);if(Z.instersects(I)){na=0;for(wa=da.materials.length;na<wa;)Oa(p,E,da,da.materials[na++],ga)}}else if(da instanceof THREE.RenderableFace3){p=da.v1;E=da.v2;d=da.v3;p.positionScreen.x*=c;p.positionScreen.y*=i;E.positionScreen.x*=c;E.positionScreen.y*=i;d.positionScreen.x*=c;d.positionScreen.y*=i;if(da.overdraw){Ga(p.positionScreen,E.positionScreen);Ga(E.positionScreen,d.positionScreen);Ga(d.positionScreen,
p.positionScreen)}I.add3Points(p.positionScreen.x,p.positionScreen.y,E.positionScreen.x,E.positionScreen.y,d.positionScreen.x,d.positionScreen.y);if(Z.instersects(I)){na=0;for(wa=da.meshMaterials.length;na<wa;){za=da.meshMaterials[na++];if(za instanceof THREE.MeshFaceMaterial){Ha=0;for(La=da.faceMaterials.length;Ha<La;)(za=da.faceMaterials[Ha++])&&Ia(p,E,d,da,za,ga)}else Ia(p,E,d,da,za,ga)}}}W.addRectangle(I)}l.setTransform(1,0,0,1,0,0)}};
THREE.SVGRenderer=function(){function a(V,O,ba){var R,L,N,Z;R=0;for(L=V.lights.length;R<L;R++){N=V.lights[R];if(N instanceof THREE.DirectionalLight){Z=O.normalWorld.dot(N.position)*N.intensity;if(Z>0){ba.r+=N.color.r*Z;ba.g+=N.color.g*Z;ba.b+=N.color.b*Z}}else if(N instanceof THREE.PointLight){x.sub(N.position,O.centroidWorld);x.normalize();Z=O.normalWorld.dot(x)*N.intensity;if(Z>0){ba.r+=N.color.r*Z;ba.g+=N.color.g*Z;ba.b+=N.color.b*Z}}}}function b(V,O,ba,R,L,N){w=e(C++);w.setAttribute("d","M "+
V.positionScreen.x+" "+V.positionScreen.y+" L "+O.positionScreen.x+" "+O.positionScreen.y+" L "+ba.positionScreen.x+","+ba.positionScreen.y+"z");if(L instanceof THREE.MeshBasicMaterial)d.__styleString=L.color.__styleString;else if(L instanceof THREE.MeshLambertMaterial)if(E){k.r=q.r;k.g=q.g;k.b=q.b;a(N,R,k);d.r=L.color.r*k.r;d.g=L.color.g*k.g;d.b=L.color.b*k.b;d.updateStyleString()}else d.__styleString=L.color.__styleString;else if(L instanceof THREE.MeshDepthMaterial){m=1-L.__2near/(L.__farPlusNear-
R.z*L.__farMinusNear);d.setRGB(m,m,m)}else L instanceof THREE.MeshNormalMaterial&&d.setRGB(g(R.normalWorld.x),g(R.normalWorld.y),g(R.normalWorld.z));L.wireframe?w.setAttribute("style","fill: none; stroke: "+d.__styleString+"; stroke-width: "+L.wireframe_linewidth+"; stroke-opacity: "+L.opacity+"; stroke-linecap: "+L.wireframe_linecap+"; stroke-linejoin: "+L.wireframe_linejoin):w.setAttribute("style","fill: "+d.__styleString+"; fill-opacity: "+L.opacity);c.appendChild(w)}function f(V,O,ba,R,L,N,Z){w=
e(C++);w.setAttribute("d","M "+V.positionScreen.x+" "+V.positionScreen.y+" L "+O.positionScreen.x+" "+O.positionScreen.y+" L "+ba.positionScreen.x+","+ba.positionScreen.y+" L "+R.positionScreen.x+","+R.positionScreen.y+"z");if(N instanceof THREE.MeshBasicMaterial)d.__styleString=N.color.__styleString;else if(N instanceof THREE.MeshLambertMaterial)if(E){k.r=q.r;k.g=q.g;k.b=q.b;a(Z,L,k);d.r=N.color.r*k.r;d.g=N.color.g*k.g;d.b=N.color.b*k.b;d.updateStyleString()}else d.__styleString=N.color.__styleString;
else if(N instanceof THREE.MeshDepthMaterial){m=1-N.__2near/(N.__farPlusNear-L.z*N.__farMinusNear);d.setRGB(m,m,m)}else N instanceof THREE.MeshNormalMaterial&&d.setRGB(g(L.normalWorld.x),g(L.normalWorld.y),g(L.normalWorld.z));N.wireframe?w.setAttribute("style","fill: none; stroke: "+d.__styleString+"; stroke-width: "+N.wireframe_linewidth+"; stroke-opacity: "+N.opacity+"; stroke-linecap: "+N.wireframe_linecap+"; stroke-linejoin: "+N.wireframe_linejoin):w.setAttribute("style","fill: "+d.__styleString+
"; fill-opacity: "+N.opacity);c.appendChild(w)}function e(V){if(t[V]==null){t[V]=document.createElementNS("http://www.w3.org/2000/svg","path");U==0&&t[V].setAttribute("shape-rendering","crispEdges");return t[V]}return t[V]}function g(V){return V<0?Math.min((1+V)*0.5,0.5):0.5+Math.min(V*0.5,0.5)}var h=null,j=new THREE.Projector,c=document.createElementNS("http://www.w3.org/2000/svg","svg"),i,l,r,B,o,v,z,A,K=new THREE.Rectangle,p=new THREE.Rectangle,E=false,d=new THREE.Color(16777215),k=new THREE.Color(16777215),
q=new THREE.Color(0),s=new THREE.Color(0),n=new THREE.Color(0),m,x=new THREE.Vector3,t=[],D=[],y=[],w,C,$,M,U=1;this.domElement=c;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(V){switch(V){case "high":U=1;break;case "low":U=0}};this.setSize=function(V,O){i=V;l=O;r=i/2;B=l/2;c.setAttribute("viewBox",-r+" "+-B+" "+i+" "+l);c.setAttribute("width",i);c.setAttribute("height",l);K.set(-r,-B,r,B)};this.clear=function(){for(;c.childNodes.length>0;)c.removeChild(c.childNodes[0])};
this.render=function(V,O){var ba,R,L,N,Z,W,I,S;this.autoClear&&this.clear();h=j.projectScene(V,O,this.sortElements);M=$=C=0;if(E=V.lights.length>0){I=V.lights;q.setRGB(0,0,0);s.setRGB(0,0,0);n.setRGB(0,0,0);ba=0;for(R=I.length;ba<R;ba++){L=I[ba];N=L.color;if(L instanceof THREE.AmbientLight){q.r+=N.r;q.g+=N.g;q.b+=N.b}else if(L instanceof THREE.DirectionalLight){s.r+=N.r;s.g+=N.g;s.b+=N.b}else if(L instanceof THREE.PointLight){n.r+=N.r;n.g+=N.g;n.b+=N.b}}}ba=0;for(R=h.length;ba<R;ba++){I=h[ba];p.empty();
if(I instanceof THREE.RenderableParticle){o=I;o.x*=r;o.y*=-B;L=0;for(N=I.materials.length;L<N;L++)if(S=I.materials[L]){Z=o;W=I;S=S;var Y=$++;if(D[Y]==null){D[Y]=document.createElementNS("http://www.w3.org/2000/svg","circle");U==0&&D[Y].setAttribute("shape-rendering","crispEdges")}w=D[Y];w.setAttribute("cx",Z.x);w.setAttribute("cy",Z.y);w.setAttribute("r",W.scale.x*r);if(S instanceof THREE.ParticleCircleMaterial){if(E){k.r=q.r+s.r+n.r;k.g=q.g+s.g+n.g;k.b=q.b+s.b+n.b;d.r=S.color.r*k.r;d.g=S.color.g*
k.g;d.b=S.color.b*k.b;d.updateStyleString()}else d=S.color;w.setAttribute("style","fill: "+d.__styleString)}c.appendChild(w)}}else if(I instanceof THREE.RenderableLine){o=I.v1;v=I.v2;o.positionScreen.x*=r;o.positionScreen.y*=-B;v.positionScreen.x*=r;v.positionScreen.y*=-B;p.addPoint(o.positionScreen.x,o.positionScreen.y);p.addPoint(v.positionScreen.x,v.positionScreen.y);if(K.instersects(p)){L=0;for(N=I.materials.length;L<N;)if(S=I.materials[L++]){Z=o;W=v;S=S;Y=M++;if(y[Y]==null){y[Y]=document.createElementNS("http://www.w3.org/2000/svg",
"line");U==0&&y[Y].setAttribute("shape-rendering","crispEdges")}w=y[Y];w.setAttribute("x1",Z.positionScreen.x);w.setAttribute("y1",Z.positionScreen.y);w.setAttribute("x2",W.positionScreen.x);w.setAttribute("y2",W.positionScreen.y);if(S instanceof THREE.LineBasicMaterial){d.__styleString=S.color.__styleString;w.setAttribute("style","fill: none; stroke: "+d.__styleString+"; stroke-width: "+S.linewidth+"; stroke-opacity: "+S.opacity+"; stroke-linecap: "+S.linecap+"; stroke-linejoin: "+S.linejoin);c.appendChild(w)}}}}else if(I instanceof
THREE.RenderableFace3){o=I.v1;v=I.v2;z=I.v3;o.positionScreen.x*=r;o.positionScreen.y*=-B;v.positionScreen.x*=r;v.positionScreen.y*=-B;z.positionScreen.x*=r;z.positionScreen.y*=-B;p.addPoint(o.positionScreen.x,o.positionScreen.y);p.addPoint(v.positionScreen.x,v.positionScreen.y);p.addPoint(z.positionScreen.x,z.positionScreen.y);if(K.instersects(p)){L=0;for(N=I.meshMaterials.length;L<N;){S=I.meshMaterials[L++];if(S instanceof THREE.MeshFaceMaterial){Z=0;for(W=I.faceMaterials.length;Z<W;)(S=I.faceMaterials[Z++])&&
b(o,v,z,I,S,V)}else S&&b(o,v,z,I,S,V)}}}else if(I instanceof THREE.RenderableFace4){o=I.v1;v=I.v2;z=I.v3;A=I.v4;o.positionScreen.x*=r;o.positionScreen.y*=-B;v.positionScreen.x*=r;v.positionScreen.y*=-B;z.positionScreen.x*=r;z.positionScreen.y*=-B;A.positionScreen.x*=r;A.positionScreen.y*=-B;p.addPoint(o.positionScreen.x,o.positionScreen.y);p.addPoint(v.positionScreen.x,v.positionScreen.y);p.addPoint(z.positionScreen.x,z.positionScreen.y);p.addPoint(A.positionScreen.x,A.positionScreen.y);if(K.instersects(p)){L=
0;for(N=I.meshMaterials.length;L<N;){S=I.meshMaterials[L++];if(S instanceof THREE.MeshFaceMaterial){Z=0;for(W=I.faceMaterials.length;Z<W;)(S=I.faceMaterials[Z++])&&f(o,v,z,A,I,S,V)}else S&&f(o,v,z,A,I,S,V)}}}}}};
THREE.WebGLRenderer=function(a){function b(d,k){d.fragment_shader=k.fragment_shader;d.vertex_shader=k.vertex_shader;d.uniforms=Uniforms.clone(k.uniforms)}function f(d,k){d.uniforms.color.value.setRGB(d.color.r*d.opacity,d.color.g*d.opacity,d.color.b*d.opacity);d.uniforms.opacity.value=d.opacity;d.uniforms.map.texture=d.map;d.uniforms.env_map.texture=d.env_map;d.uniforms.reflectivity.value=d.reflectivity;d.uniforms.refraction_ratio.value=d.refraction_ratio;d.uniforms.combine.value=d.combine;d.uniforms.useRefract.value=
d.env_map&&d.env_map.mapping instanceof THREE.CubeRefractionMapping;if(k){d.uniforms.fogColor.value.setHex(k.color.hex);if(k instanceof THREE.Fog){d.uniforms.fogNear.value=k.near;d.uniforms.fogFar.value=k.far}else if(k instanceof THREE.FogExp2)d.uniforms.fogDensity.value=k.density}}function e(d,k){d.uniforms.color.value.setRGB(d.color.r*d.opacity,d.color.g*d.opacity,d.color.b*d.opacity);d.uniforms.opacity.value=d.opacity;if(k){d.uniforms.fogColor.value.setHex(k.color.hex);if(k instanceof THREE.Fog){d.uniforms.fogNear.value=
k.near;d.uniforms.fogFar.value=k.far}else if(k instanceof THREE.FogExp2)d.uniforms.fogDensity.value=k.density}}function g(d,k){var r;if(d=="fragment")r=c.createShader(c.FRAGMENT_SHADER);else if(d=="vertex")r=c.createShader(c.VERTEX_SHADER);c.shaderSource(r,k);c.compileShader(r);if(!c.getShaderParameter(r,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(r));return null}return r}function h(d){switch(d){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 j=document.createElement("canvas"),c,i=null,m=new THREE.Matrix4,s,B=new Float32Array(16),n=new Float32Array(16),v=new Float32Array(16),
y=new Float32Array(9),A=new Float32Array(16),K=true,p=new THREE.Color(0),C=0;if(a){if(a.antialias!==undefined)K=a.antialias;a.clearColor!==undefined&&p.setHex(a.clearColor);if(a.clearAlpha!==undefined)C=a.clearAlpha}this.domElement=j;this.autoClear=true;(function(d,k,r){try{c=j.getContext("experimental-webgl",{antialias:d})}catch(q){}if(!c){alert("WebGL not supported");throw"cannot create webgl context";}c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);
c.cullFace(c.BACK);c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(k.r,k.g,k.b,r)})(K,p,C);this.setSize=function(d,k){j.width=d;j.height=k;c.viewport(0,0,j.width,j.height)};this.setClearColor=function(d,k){var r=new THREE.Color(d);c.clearColor(r.r,r.g,r.b,k)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(d,k){var r,q,o,l=0,x=0,u=0,E=[],z=[],w=[],D=[];r=0;for(q=k.length;r<q;r++){o=k[r];if(o instanceof THREE.AmbientLight){l+=
o.color.r;x+=o.color.g;u+=o.color.b}else if(o instanceof THREE.DirectionalLight){E.push(o.color.r*o.intensity,o.color.g*o.intensity,o.color.b*o.intensity);z.push(o.position.x,o.position.y,o.position.z)}else if(o instanceof THREE.PointLight){w.push(o.color.r*o.intensity,o.color.g*o.intensity,o.color.b*o.intensity);D.push(o.position.x,o.position.y,o.position.z)}}return{ambient:[l,x,u],directional:{colors:E,positions:z},point:{colors:w,positions:D}}};this.createLineBuffers=function(d){var k,r,q,o=[],
l=[],x=d.geometry.vertices;k=0;for(r=x.length;k<r;k++){q=x[k].position;o.push(q.x,q.y,q.z);l.push(k)}if(o.length){d.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,d.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(o),c.STATIC_DRAW);d.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,d.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(l),c.STATIC_DRAW);d.__webGLLineCount=l.length}};this.createBuffers=function(d,k){var r,q,
o,l,x,u,E,z,w,D,$=[],M=[],U=[],V=[],O=[],ba=[],R=0,L=d.geometry.geometryChunks[k],N;x=false;r=0;for(q=d.materials.length;r<q;r++){u=d.materials[r];if(u instanceof THREE.MeshFaceMaterial){u=0;for(N=L.materials.length;u<N;u++)if(L.materials[u]&&L.materials[u].shading!=undefined&&L.materials[u].shading==THREE.SmoothShading){x=true;break}}else if(u&&u.shading!=undefined&&u.shading==THREE.SmoothShading){x=true;break}if(x)break}N=x;r=0;for(q=L.faces.length;r<q;r++){o=L.faces[r];l=d.geometry.faces[o];x=
l.vertexNormals;u=l.normal;o=d.geometry.uvs[o];if(l instanceof THREE.Face3){E=d.geometry.vertices[l.a].position;z=d.geometry.vertices[l.b].position;w=d.geometry.vertices[l.c].position;U.push(E.x,E.y,E.z,z.x,z.y,z.z,w.x,w.y,w.z);if(d.geometry.hasTangents){E=d.geometry.vertices[l.a].tangent;z=d.geometry.vertices[l.b].tangent;w=d.geometry.vertices[l.c].tangent;O.push(E.x,E.y,E.z,E.w,z.x,z.y,z.z,z.w,w.x,w.y,w.z,w.w)}if(x.length==3&&N)for(l=0;l<3;l++)V.push(x[l].x,x[l].y,x[l].z);else for(l=0;l<3;l++)V.push(u.x,
u.y,u.z);if(o)for(l=0;l<3;l++)ba.push(o[l].u,o[l].v);$.push(R,R+1,R+2);M.push(R,R+1,R,R+2,R+1,R+2);R+=3}else if(l instanceof THREE.Face4){E=d.geometry.vertices[l.a].position;z=d.geometry.vertices[l.b].position;w=d.geometry.vertices[l.c].position;D=d.geometry.vertices[l.d].position;U.push(E.x,E.y,E.z,z.x,z.y,z.z,w.x,w.y,w.z,D.x,D.y,D.z);if(d.geometry.hasTangents){E=d.geometry.vertices[l.a].tangent;z=d.geometry.vertices[l.b].tangent;w=d.geometry.vertices[l.c].tangent;l=d.geometry.vertices[l.d].tangent;
O.push(E.x,E.y,E.z,E.w,z.x,z.y,z.z,z.w,w.x,w.y,w.z,w.w,l.x,l.y,l.z,l.w)}if(x.length==4&&N)for(l=0;l<4;l++)V.push(x[l].x,x[l].y,x[l].z);else for(l=0;l<4;l++)V.push(u.x,u.y,u.z);if(o)for(l=0;l<4;l++)ba.push(o[l].u,o[l].v);$.push(R,R+1,R+2,R,R+2,R+3);M.push(R,R+1,R,R+2,R,R+3,R+1,R+2,R+2,R+3);R+=4}}if(U.length){L.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,L.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(U),c.STATIC_DRAW);L.__webGLNormalBuffer=c.createBuffer();
c.bindBuffer(c.ARRAY_BUFFER,L.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(V),c.STATIC_DRAW);if(d.geometry.hasTangents){L.__webGLTangentBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,L.__webGLTangentBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(O),c.STATIC_DRAW)}if(ba.length>0){L.__webGLUVBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,L.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(ba),c.STATIC_DRAW)}L.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,
L.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array($),c.STATIC_DRAW);L.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,L.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(M),c.STATIC_DRAW);L.__webGLFaceCount=$.length;L.__webGLLineCount=M.length}};this.renderBuffer=function(d,k,r,q,o){var l,x,u,E;if(!q.program){if(q instanceof THREE.MeshDepthMaterial){b(q,THREE.ShaderLib.depth);q.uniforms.mNear.value=d.near;q.uniforms.mFar.value=d.far}else if(q instanceof
THREE.MeshNormalMaterial)b(q,THREE.ShaderLib.normal);else if(q instanceof THREE.MeshBasicMaterial){b(q,THREE.ShaderLib.basic);f(q,r)}else if(q instanceof THREE.MeshLambertMaterial){b(q,THREE.ShaderLib.lambert);f(q,r)}else if(q instanceof THREE.MeshPhongMaterial){b(q,THREE.ShaderLib.phong);f(q,r)}else if(q instanceof THREE.LineBasicMaterial){b(q,THREE.ShaderLib.basic);e(q,r)}if(scene){var z,w,D;z=E=x=0;for(w=k.length;z<w;z++){D=k[z];D instanceof THREE.DirectionalLight&&E++;D instanceof THREE.PointLight&&
x++}if(x+E<=4){z=E;x=x}else{z=Math.ceil(4*E/(x+E));x=4-z}x={directional:z,point:x}}else x={directional:1,point:3};E={fog:r,map:q.map,env_map:q.env_map,maxDirLights:x.directional,maxPointLights:x.point};x=q.fragment_shader;z=q.vertex_shader;w=c.createProgram();D=["#ifdef GL_ES\nprecision highp float;\n#endif","#define MAX_DIR_LIGHTS "+E.maxDirLights,"#define MAX_POINT_LIGHTS "+E.maxPointLights,E.fog?"#define USE_FOG":"",E.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",E.map?"#define USE_MAP":"",
E.env_map?"#define USE_ENVMAP":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");E=[c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+E.maxDirLights,"#define MAX_POINT_LIGHTS "+E.maxPointLights,E.map?"#define USE_MAP":"",E.env_map?"#define USE_ENVMAP":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"].join("\n");
c.attachShader(w,g("fragment",D+x));c.attachShader(w,g("vertex",E+z));c.linkProgram(w);c.getProgramParameter(w,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(w,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");w.uniforms={};w.attributes={};q.program=w;x=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(l in q.uniforms)x.push(l);l=q.program;z=0;for(w=x.length;z<w;z++){D=x[z];l.uniforms[D]=c.getUniformLocation(l,
D)}l=q.program;x=["position","normal","uv","tangent"];z=0;for(w=x.length;z<w;z++){D=x[z];l.attributes[D]=c.getAttribLocation(l,D)}}l=q.program;if(l!=i){c.useProgram(l);i=l}this.loadCamera(l,d);this.loadMatrices(l);if(q instanceof THREE.MeshPhongMaterial||q instanceof THREE.MeshLambertMaterial){d=this.setupLights(l,k);q.uniforms.enableLighting.value=d.directional.positions.length+d.point.positions.length;q.uniforms.ambientLightColor.value=d.ambient;q.uniforms.directionalLightColor.value=d.directional.colors;
q.uniforms.directionalLightDirection.value=d.directional.positions;q.uniforms.pointLightColor.value=d.point.colors;q.uniforms.pointLightPosition.value=d.point.positions}if(q instanceof THREE.MeshBasicMaterial||q instanceof THREE.MeshLambertMaterial||q instanceof THREE.MeshPhongMaterial)f(q,r);q instanceof THREE.LineBasicMaterial&&e(q,r);if(q instanceof THREE.MeshPhongMaterial){q.uniforms.ambient.value.setRGB(q.ambient.r,q.ambient.g,q.ambient.b);q.uniforms.specular.value.setRGB(q.specular.r,q.specular.g,
q.specular.b);q.uniforms.shininess.value=q.shininess}r=q.uniforms;for(u in r)if(x=l.uniforms[u]){k=r[u].type;d=r[u].value;if(k=="i")c.uniform1i(x,d);else if(k=="f")c.uniform1f(x,d);else if(k=="fv")c.uniform3fv(x,d);else if(k=="v2")c.uniform2f(x,d.x,d.y);else if(k=="v3")c.uniform3f(x,d.x,d.y,d.z);else if(k=="c")c.uniform3f(x,d.r,d.g,d.b);else if(k=="t"){c.uniform1i(x,d);if(k=r[u].texture)if(k.image instanceof Array&&k.image.length==6){k=k;d=d;if(k.image.length==6){if(!k.image.__webGLTextureCube&&!k.image.__cubeMapInitialized&&
k.near;d.uniforms.fogFar.value=k.far}else if(k instanceof THREE.FogExp2)d.uniforms.fogDensity.value=k.density}}function g(d,k){var q;if(d=="fragment")q=c.createShader(c.FRAGMENT_SHADER);else if(d=="vertex")q=c.createShader(c.VERTEX_SHADER);c.shaderSource(q,k);c.compileShader(q);if(!c.getShaderParameter(q,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(q));return null}return q}function h(d){switch(d){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 j=document.createElement("canvas"),c,i=null,l=new THREE.Matrix4,r,B=new Float32Array(16),o=new Float32Array(16),v=new Float32Array(16),
z=new Float32Array(9),A=new Float32Array(16),K=true,p=new THREE.Color(0),E=0;if(a){if(a.antialias!==undefined)K=a.antialias;a.clearColor!==undefined&&p.setHex(a.clearColor);if(a.clearAlpha!==undefined)E=a.clearAlpha}this.domElement=j;this.autoClear=true;(function(d,k,q){try{c=j.getContext("experimental-webgl",{antialias:d})}catch(s){}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(k.r,k.g,k.b,q)})(K,p,E);this.setSize=function(d,k){j.width=d;j.height=k;c.viewport(0,0,j.width,j.height)};this.setClearColor=function(d,k){var q=new THREE.Color(d);c.clearColor(q.r,q.g,q.b,k)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(d,k){var q,s,n,m=0,x=0,t=0,D=[],y=[],w=[],C=[];q=0;for(s=k.length;q<s;q++){n=k[q];if(n instanceof THREE.AmbientLight){m+=
n.color.r;x+=n.color.g;t+=n.color.b}else if(n instanceof THREE.DirectionalLight){D.push(n.color.r*n.intensity,n.color.g*n.intensity,n.color.b*n.intensity);y.push(n.position.x,n.position.y,n.position.z)}else if(n instanceof THREE.PointLight){w.push(n.color.r*n.intensity,n.color.g*n.intensity,n.color.b*n.intensity);C.push(n.position.x,n.position.y,n.position.z)}}return{ambient:[m,x,t],directional:{colors:D,positions:y},point:{colors:w,positions:C}}};this.createParticleBuffers=function(){};this.createLineBuffers=
function(d){var k,q,s,n=[],m=[],x=d.geometry.vertices;k=0;for(q=x.length;k<q;k++){s=x[k].position;n.push(s.x,s.y,s.z);m.push(k)}if(n.length){d.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,d.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(n),c.STATIC_DRAW);d.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,d.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(m),c.STATIC_DRAW);d.__webGLLineCount=m.length}};this.createBuffers=
function(d,k){var q,s,n,m,x,t,D,y,w,C,$=[],M=[],U=[],V=[],O=[],ba=[],R=0,L=d.geometry.geometryChunks[k],N;x=false;q=0;for(s=d.materials.length;q<s;q++){t=d.materials[q];if(t instanceof THREE.MeshFaceMaterial){t=0;for(N=L.materials.length;t<N;t++)if(L.materials[t]&&L.materials[t].shading!=undefined&&L.materials[t].shading==THREE.SmoothShading){x=true;break}}else if(t&&t.shading!=undefined&&t.shading==THREE.SmoothShading){x=true;break}if(x)break}N=x;q=0;for(s=L.faces.length;q<s;q++){n=L.faces[q];m=
d.geometry.faces[n];x=m.vertexNormals;t=m.normal;n=d.geometry.uvs[n];if(m instanceof THREE.Face3){D=d.geometry.vertices[m.a].position;y=d.geometry.vertices[m.b].position;w=d.geometry.vertices[m.c].position;U.push(D.x,D.y,D.z,y.x,y.y,y.z,w.x,w.y,w.z);if(d.geometry.hasTangents){D=d.geometry.vertices[m.a].tangent;y=d.geometry.vertices[m.b].tangent;w=d.geometry.vertices[m.c].tangent;O.push(D.x,D.y,D.z,D.w,y.x,y.y,y.z,y.w,w.x,w.y,w.z,w.w)}if(x.length==3&&N)for(m=0;m<3;m++)V.push(x[m].x,x[m].y,x[m].z);
else for(m=0;m<3;m++)V.push(t.x,t.y,t.z);if(n)for(m=0;m<3;m++)ba.push(n[m].u,n[m].v);$.push(R,R+1,R+2);M.push(R,R+1,R,R+2,R+1,R+2);R+=3}else if(m instanceof THREE.Face4){D=d.geometry.vertices[m.a].position;y=d.geometry.vertices[m.b].position;w=d.geometry.vertices[m.c].position;C=d.geometry.vertices[m.d].position;U.push(D.x,D.y,D.z,y.x,y.y,y.z,w.x,w.y,w.z,C.x,C.y,C.z);if(d.geometry.hasTangents){D=d.geometry.vertices[m.a].tangent;y=d.geometry.vertices[m.b].tangent;w=d.geometry.vertices[m.c].tangent;
m=d.geometry.vertices[m.d].tangent;O.push(D.x,D.y,D.z,D.w,y.x,y.y,y.z,y.w,w.x,w.y,w.z,w.w,m.x,m.y,m.z,m.w)}if(x.length==4&&N)for(m=0;m<4;m++)V.push(x[m].x,x[m].y,x[m].z);else for(m=0;m<4;m++)V.push(t.x,t.y,t.z);if(n)for(m=0;m<4;m++)ba.push(n[m].u,n[m].v);$.push(R,R+1,R+2,R,R+2,R+3);M.push(R,R+1,R,R+2,R,R+3,R+1,R+2,R+2,R+3);R+=4}}if(U.length){L.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,L.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(U),c.STATIC_DRAW);L.__webGLNormalBuffer=
c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,L.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(V),c.STATIC_DRAW);if(d.geometry.hasTangents){L.__webGLTangentBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,L.__webGLTangentBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(O),c.STATIC_DRAW)}if(ba.length>0){L.__webGLUVBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,L.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(ba),c.STATIC_DRAW)}L.__webGLFaceBuffer=c.createBuffer();
c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,L.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array($),c.STATIC_DRAW);L.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,L.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(M),c.STATIC_DRAW);L.__webGLFaceCount=$.length;L.__webGLLineCount=M.length}};this.renderBuffer=function(d,k,q,s,n){var m,x,t,D;if(!s.program){if(s instanceof THREE.MeshDepthMaterial){b(s,THREE.ShaderLib.depth);s.uniforms.mNear.value=
d.near;s.uniforms.mFar.value=d.far}else if(s instanceof THREE.MeshNormalMaterial)b(s,THREE.ShaderLib.normal);else if(s instanceof THREE.MeshBasicMaterial){b(s,THREE.ShaderLib.basic);f(s,q)}else if(s instanceof THREE.MeshLambertMaterial){b(s,THREE.ShaderLib.lambert);f(s,q)}else if(s instanceof THREE.MeshPhongMaterial){b(s,THREE.ShaderLib.phong);f(s,q)}else if(s instanceof THREE.LineBasicMaterial){b(s,THREE.ShaderLib.basic);e(s,q)}var y,w,C;y=D=x=0;for(w=k.length;y<w;y++){C=k[y];C instanceof THREE.DirectionalLight&&
D++;C instanceof THREE.PointLight&&x++}if(x+D<=4){y=D;x=x}else{y=Math.ceil(4*D/(x+D));x=4-y}x={directional:y,point:x};D={fog:q,map:s.map,env_map:s.env_map,maxDirLights:x.directional,maxPointLights:x.point};x=s.fragment_shader;y=s.vertex_shader;w=c.createProgram();C=["#ifdef GL_ES\nprecision highp float;\n#endif","#define MAX_DIR_LIGHTS "+D.maxDirLights,"#define MAX_POINT_LIGHTS "+D.maxPointLights,D.fog?"#define USE_FOG":"",D.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",D.map?"#define USE_MAP":
"",D.env_map?"#define USE_ENVMAP":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");D=[c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+D.maxDirLights,"#define MAX_POINT_LIGHTS "+D.maxPointLights,D.map?"#define USE_MAP":"",D.env_map?"#define USE_ENVMAP":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"].join("\n");
c.attachShader(w,g("fragment",C+x));c.attachShader(w,g("vertex",D+y));c.linkProgram(w);c.getProgramParameter(w,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(w,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");w.uniforms={};w.attributes={};s.program=w;x=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(m in s.uniforms)x.push(m);m=s.program;y=0;for(w=x.length;y<w;y++){C=x[y];m.uniforms[C]=c.getUniformLocation(m,
C)}m=s.program;x=["position","normal","uv","tangent"];y=0;for(w=x.length;y<w;y++){C=x[y];m.attributes[C]=c.getAttribLocation(m,C)}}m=s.program;if(m!=i){c.useProgram(m);i=m}this.loadCamera(m,d);this.loadMatrices(m);if(s instanceof THREE.MeshPhongMaterial||s instanceof THREE.MeshLambertMaterial){d=this.setupLights(m,k);s.uniforms.enableLighting.value=d.directional.positions.length+d.point.positions.length;s.uniforms.ambientLightColor.value=d.ambient;s.uniforms.directionalLightColor.value=d.directional.colors;
s.uniforms.directionalLightDirection.value=d.directional.positions;s.uniforms.pointLightColor.value=d.point.colors;s.uniforms.pointLightPosition.value=d.point.positions}if(s instanceof THREE.MeshBasicMaterial||s instanceof THREE.MeshLambertMaterial||s instanceof THREE.MeshPhongMaterial)f(s,q);s instanceof THREE.LineBasicMaterial&&e(s,q);if(s instanceof THREE.MeshPhongMaterial){s.uniforms.ambient.value.setRGB(s.ambient.r,s.ambient.g,s.ambient.b);s.uniforms.specular.value.setRGB(s.specular.r,s.specular.g,
s.specular.b);s.uniforms.shininess.value=s.shininess}q=s.uniforms;for(t in q)if(x=m.uniforms[t]){k=q[t].type;d=q[t].value;if(k=="i")c.uniform1i(x,d);else if(k=="f")c.uniform1f(x,d);else if(k=="fv")c.uniform3fv(x,d);else if(k=="v2")c.uniform2f(x,d.x,d.y);else if(k=="v3")c.uniform3f(x,d.x,d.y,d.z);else if(k=="c")c.uniform3f(x,d.r,d.g,d.b);else if(k=="t"){c.uniform1i(x,d);if(k=q[t].texture)if(k.image instanceof Array&&k.image.length==6){k=k;d=d;if(k.image.length==6){if(!k.image.__webGLTextureCube&&!k.image.__cubeMapInitialized&&
k.image.loadCount==6){k.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,k.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(x=0;x<6;++x)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+x,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,
k.image[x]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);k.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+d);c.bindTexture(c.TEXTURE_CUBE_MAP,k.image.__webGLTextureCube)}}else{k=k;d=d;if(!k.__webGLTexture&&k.image.loaded){k.__webGLTexture=c.createTexture();c.bindTexture(c.TEXTURE_2D,k.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,k.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,h(k.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,
h(k.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,h(k.mag_filter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,h(k.min_filter));c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+d);c.bindTexture(c.TEXTURE_2D,k.__webGLTexture)}}}u=l.attributes;c.bindBuffer(c.ARRAY_BUFFER,o.__webGLVertexBuffer);c.vertexAttribPointer(u.position,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(u.position);if(u.normal>=0){c.bindBuffer(c.ARRAY_BUFFER,o.__webGLNormalBuffer);
c.vertexAttribPointer(u.normal,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(u.normal)}if(u.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,o.__webGLTangentBuffer);c.vertexAttribPointer(u.tangent,4,c.FLOAT,false,0,0);c.enableVertexAttribArray(u.tangent)}if(u.uv>=0)if(o.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,o.__webGLUVBuffer);c.vertexAttribPointer(u.uv,2,c.FLOAT,false,0,0);c.enableVertexAttribArray(u.uv)}else c.disableVertexAttribArray(u.uv);if(q.wireframe||q instanceof THREE.LineBasicMaterial){u=
q.wireframe_linewidth!==undefined?q.wireframe_linewidth:q.linewidth!==undefined?q.linewidth:1;q=q instanceof THREE.LineBasicMaterial&&o.type==THREE.LineStrip?c.LINE_STRIP:c.LINES;c.lineWidth(u);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,o.__webGLLineBuffer);c.drawElements(q,o.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,o.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,o.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(d,k,r,q,o,l,x){var u,E,z,w,D;z=0;for(w=
q.materials.length;z<w;z++){u=q.materials[z];if(u instanceof THREE.MeshFaceMaterial){u=0;for(E=o.materials.length;u<E;u++)if((D=o.materials[u])&&D.blending==l&&D.opacity<1==x){this.setBlending(D.blending);this.renderBuffer(d,k,r,D,o)}}else if((D=u)&&D.blending==l&&D.opacity<1==x){this.setBlending(D.blending);this.renderBuffer(d,k,r,D,o)}}};this.render=function(d,k){var r,q,o,l,x=d.lights,u=d.fog;this.initWebGLObjects(d);this.autoClear&&this.clear();k.autoUpdateMatrix&&k.updateMatrix();B.set(k.matrix.flatten());
v.set(k.projectionMatrix.flatten());r=0;for(q=d.__webGLObjects.length;r<q;r++){o=d.__webGLObjects[r];l=o.object;o=o.buffer;if(l.visible){this.setupMatrices(l,k);this.renderPass(k,x,u,l,o,THREE.NormalBlending,false)}}r=0;for(q=d.__webGLObjects.length;r<q;r++){o=d.__webGLObjects[r];l=o.object;o=o.buffer;if(l.visible){this.setupMatrices(l,k);this.renderPass(k,x,u,l,o,THREE.AdditiveBlending,false);this.renderPass(k,x,u,l,o,THREE.SubtractiveBlending,false);this.renderPass(k,x,u,l,o,THREE.AdditiveBlending,
true);this.renderPass(k,x,u,l,o,THREE.SubtractiveBlending,true);this.renderPass(k,x,u,l,o,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(d){var k,r,q,o,l,x;if(!d.__webGLObjects){d.__webGLObjects=[];d.__webGLObjectsMap={}}k=0;for(r=d.objects.length;k<r;k++){q=d.objects[k];if(d.__webGLObjectsMap[q.id]==undefined)d.__webGLObjectsMap[q.id]={};x=d.__webGLObjectsMap[q.id];if(q instanceof THREE.Mesh)for(l in q.geometry.geometryChunks){o=q.geometry.geometryChunks[l];o.__webGLVertexBuffer||this.createBuffers(q,
l);if(x[l]==undefined){o={buffer:o,object:q};d.__webGLObjects.push(o);x[l]=1}}else if(q instanceof THREE.Line){q.__webGLVertexBuffer||this.createLineBuffers(q);l=0;if(x[l]==undefined){o={buffer:q,object:q};d.__webGLObjects.push(o);x[l]=1}}}};this.removeObject=function(d,k){var r,q;for(r=d.__webGLObjects.length-1;r>=0;r--){q=d.__webGLObjects[r].object;k==q&&d.__webGLObjects.splice(r,1)}};this.setupMatrices=function(d,k){d.autoUpdateMatrix&&d.updateMatrix();m.multiply(k.matrix,d.matrix);n.set(m.flatten());
s=THREE.Matrix4.makeInvert3x3(m).transpose();y.set(s.m);A.set(d.matrix.flatten())};this.loadMatrices=function(d){c.uniformMatrix4fv(d.uniforms.viewMatrix,false,B);c.uniformMatrix4fv(d.uniforms.modelViewMatrix,false,n);c.uniformMatrix4fv(d.uniforms.projectionMatrix,false,v);c.uniformMatrix3fv(d.uniforms.normalMatrix,false,y);c.uniformMatrix4fv(d.uniforms.objectMatrix,false,A)};this.loadCamera=function(d,k){c.uniform3f(d.uniforms.cameraPosition,k.position.x,k.position.y,k.position.z)};this.setBlending=
function(d){switch(d){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(d,k){if(d){!k||k=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(d=="back")c.cullFace(c.BACK);else d=="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}};
h(k.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,h(k.mag_filter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,h(k.min_filter));c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+d);c.bindTexture(c.TEXTURE_2D,k.__webGLTexture)}}}t=m.attributes;c.bindBuffer(c.ARRAY_BUFFER,n.__webGLVertexBuffer);c.vertexAttribPointer(t.position,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(t.position);if(t.normal>=0){c.bindBuffer(c.ARRAY_BUFFER,n.__webGLNormalBuffer);
c.vertexAttribPointer(t.normal,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(t.normal)}if(t.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,n.__webGLTangentBuffer);c.vertexAttribPointer(t.tangent,4,c.FLOAT,false,0,0);c.enableVertexAttribArray(t.tangent)}if(t.uv>=0)if(n.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,n.__webGLUVBuffer);c.vertexAttribPointer(t.uv,2,c.FLOAT,false,0,0);c.enableVertexAttribArray(t.uv)}else c.disableVertexAttribArray(t.uv);if(s.wireframe||s instanceof THREE.LineBasicMaterial){t=
s.wireframe_linewidth!==undefined?s.wireframe_linewidth:s.linewidth!==undefined?s.linewidth:1;s=s instanceof THREE.LineBasicMaterial&&n.type==THREE.LineStrip?c.LINE_STRIP:c.LINES;c.lineWidth(t);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,n.__webGLLineBuffer);c.drawElements(s,n.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,n.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,n.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(d,k,q,s,n,m,x){var t,D,y,w,C;y=0;for(w=
s.materials.length;y<w;y++){t=s.materials[y];if(t instanceof THREE.MeshFaceMaterial){t=0;for(D=n.materials.length;t<D;t++)if((C=n.materials[t])&&C.blending==m&&C.opacity<1==x){this.setBlending(C.blending);this.renderBuffer(d,k,q,C,n)}}else if((C=t)&&C.blending==m&&C.opacity<1==x){this.setBlending(C.blending);this.renderBuffer(d,k,q,C,n)}}};this.render=function(d,k){var q,s,n,m,x=d.lights,t=d.fog;this.initWebGLObjects(d);this.autoClear&&this.clear();k.autoUpdateMatrix&&k.updateMatrix();B.set(k.matrix.flatten());
v.set(k.projectionMatrix.flatten());q=0;for(s=d.__webGLObjects.length;q<s;q++){n=d.__webGLObjects[q];m=n.object;n=n.buffer;if(m.visible){this.setupMatrices(m,k);this.renderPass(k,x,t,m,n,THREE.NormalBlending,false)}}q=0;for(s=d.__webGLObjects.length;q<s;q++){n=d.__webGLObjects[q];m=n.object;n=n.buffer;if(m.visible){this.setupMatrices(m,k);this.renderPass(k,x,t,m,n,THREE.AdditiveBlending,false);this.renderPass(k,x,t,m,n,THREE.SubtractiveBlending,false);this.renderPass(k,x,t,m,n,THREE.AdditiveBlending,
true);this.renderPass(k,x,t,m,n,THREE.SubtractiveBlending,true);this.renderPass(k,x,t,m,n,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(d){function k(D,y,w,C){if(D[y]==undefined){d.__webGLObjects.push({buffer:w,object:C});D[y]=1}}var q,s,n,m,x,t;if(!d.__webGLObjects){d.__webGLObjects=[];d.__webGLObjectsMap={}}q=0;for(s=d.objects.length;q<s;q++){n=d.objects[q];if(d.__webGLObjectsMap[n.id]==undefined)d.__webGLObjectsMap[n.id]={};t=d.__webGLObjectsMap[n.id];if(n instanceof THREE.Mesh)for(m in n.geometry.geometryChunks){x=
n.geometry.geometryChunks[m];x.__webGLVertexBuffer||this.createBuffers(n,m);k(t,m,x,n)}else if(n instanceof THREE.Line){n.__webGLVertexBuffer||this.createLineBuffers(n);k(t,0,n,n)}else if(n instanceof THREE.ParticleSystem){n.__webGLVertexBuffer||this.createParticleBuffers(n);k(t,0,n,n)}}};this.removeObject=function(d,k){var q,s;for(q=d.__webGLObjects.length-1;q>=0;q--){s=d.__webGLObjects[q].object;k==s&&d.__webGLObjects.splice(q,1)}};this.setupMatrices=function(d,k){d.autoUpdateMatrix&&d.updateMatrix();
l.multiply(k.matrix,d.matrix);o.set(l.flatten());r=THREE.Matrix4.makeInvert3x3(l).transpose();z.set(r.m);A.set(d.matrix.flatten())};this.loadMatrices=function(d){c.uniformMatrix4fv(d.uniforms.viewMatrix,false,B);c.uniformMatrix4fv(d.uniforms.modelViewMatrix,false,o);c.uniformMatrix4fv(d.uniforms.projectionMatrix,false,v);c.uniformMatrix3fv(d.uniforms.normalMatrix,false,z);c.uniformMatrix4fv(d.uniforms.objectMatrix,false,A)};this.loadCamera=function(d,k){c.uniform3f(d.uniforms.cameraPosition,k.position.x,
k.position.y,k.position.z)};this.setBlending=function(d){switch(d){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(d,k){if(d){!k||k=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(d=="back")c.cullFace(c.BACK);else d=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)};
this.supportsVertexTextures=function(){return c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}};
THREE.Snippets={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, 1.0 ), fogFactor );\n#endif",envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube env_map;\nuniform int combine;\n#endif",
envmap_fragment:"#ifdef USE_ENVMAP\ncubeColor = textureCube( env_map, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = mix( gl_FragColor, cubeColor, reflectivity );\n} else {\ngl_FragColor = gl_FragColor * cubeColor;\n}\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refraction_ratio;\nuniform bool useRefract;\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nif ( useRefract ) {\nvReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refraction_ratio );\n} else {\nvReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );\n}\n#endif",
map_pars_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\n#endif",map_fragment:"#ifdef USE_MAP\nmapColor = texture2D( map, vUv );\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv;\n#endif",lights_pars_vertex:"uniform bool enableLighting;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n#ifdef PHONG\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\n#endif",
@@ -191,9 +191,9 @@ shininess:{type:"f",value:30}}]),fragment_shader:["uniform vec3 color;\nuniform
"gl_FragColor = mapColor * totalLight * vec4( vLightWeighting, 1.0 );",THREE.Snippets.envmap_fragment,THREE.Snippets.fog_fragment,"}"].join("\n"),vertex_shader:["#define PHONG\nvarying vec3 vLightWeighting;\nvarying vec3 vViewPosition;\nvarying vec3 vNormal;",THREE.Snippets.map_pars_vertex,THREE.Snippets.envmap_pars_vertex,THREE.Snippets.lights_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.Snippets.map_vertex,THREE.Snippets.envmap_vertex,"#ifndef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\n#endif\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 transformedNormal = normalize( normalMatrix * normal );\nvNormal = transformedNormal;",
THREE.Snippets.lights_vertex,"gl_Position = projectionMatrix * mvPosition;\n}"].join("\n")}};THREE.RenderableObject=function(){this.z=this.object=null};THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[];this.faceMaterials=this.meshMaterials=null;this.overdraw=false;this.uvs=[null,null,null]};
THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.materials=null};THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.materials=null};
var GeometryUtils={merge:function(a,b){var f=b instanceof THREE.Mesh,e=a.vertices.length,g=f?b.geometry:b,h=a.vertices,j=g.vertices,c=a.faces,i=g.faces,m=a.uvs;g=g.uvs;f&&b.updateMatrix();for(var s=0,B=j.length;s<B;s++){var n=new THREE.Vertex(j[s].position.clone());f&&b.matrix.multiplyVector3(n.position);h.push(n)}s=0;for(B=i.length;s<B;s++){j=i[s];var v,y=j.vertexNormals;if(j instanceof THREE.Face3)v=new THREE.Face3(j.a+e,j.b+e,j.c+e);else if(j instanceof THREE.Face4)v=new THREE.Face4(j.a+e,j.b+
e,j.c+e,j.d+e);v.centroid.copy(j.centroid);v.normal.copy(j.normal);f=0;for(h=y.length;f<h;f++){n=y[f];v.vertexNormals.push(n.clone())}v.materials=j.materials.slice();c.push(v)}s=0;for(B=g.length;s<B;s++){e=g[s];c=[];f=0;for(h=e.length;f<h;f++)c.push(new THREE.UV(e[f].u,e[f].v));m.push(c)}}},ImageUtils={loadTexture:function(a,b){var f=new Image;f.onload=function(){this.loaded=true};f.src=a;return new THREE.Texture(f,b)},loadArray:function(a){var b,f,e=[];b=e.loadCount=0;for(f=a.length;b<f;++b){e[b]=
new Image;e[b].loaded=0;e[b].onload=function(){e.loadCount+=1;this.loaded=true};e[b].src=a[b]}return e}},SceneUtils={addMesh:function(a,b,f,e,g,h,j,c,i,m){b=new THREE.Mesh(b,m);b.scale.x=b.scale.y=b.scale.z=f;b.position.x=e;b.position.y=g;b.position.z=h;b.rotation.x=j;b.rotation.y=c;b.rotation.z=i;a.addObject(b);return b},addPanoramaCubeWebGL:function(a,b,f){var e=ShaderUtils.lib.cube;e.uniforms.tCube.texture=f;f=new THREE.MeshShaderMaterial({fragment_shader:e.fragment_shader,vertex_shader:e.vertex_shader,
var GeometryUtils={merge:function(a,b){var f=b instanceof THREE.Mesh,e=a.vertices.length,g=f?b.geometry:b,h=a.vertices,j=g.vertices,c=a.faces,i=g.faces,l=a.uvs;g=g.uvs;f&&b.updateMatrix();for(var r=0,B=j.length;r<B;r++){var o=new THREE.Vertex(j[r].position.clone());f&&b.matrix.multiplyVector3(o.position);h.push(o)}r=0;for(B=i.length;r<B;r++){j=i[r];var v,z=j.vertexNormals;if(j instanceof THREE.Face3)v=new THREE.Face3(j.a+e,j.b+e,j.c+e);else if(j instanceof THREE.Face4)v=new THREE.Face4(j.a+e,j.b+
e,j.c+e,j.d+e);v.centroid.copy(j.centroid);v.normal.copy(j.normal);f=0;for(h=z.length;f<h;f++){o=z[f];v.vertexNormals.push(o.clone())}v.materials=j.materials.slice();c.push(v)}r=0;for(B=g.length;r<B;r++){e=g[r];c=[];f=0;for(h=e.length;f<h;f++)c.push(new THREE.UV(e[f].u,e[f].v));l.push(c)}}},ImageUtils={loadTexture:function(a,b){var f=new Image;f.onload=function(){this.loaded=true};f.src=a;return new THREE.Texture(f,b)},loadArray:function(a){var b,f,e=[];b=e.loadCount=0;for(f=a.length;b<f;++b){e[b]=
new Image;e[b].loaded=0;e[b].onload=function(){e.loadCount+=1;this.loaded=true};e[b].src=a[b]}return e}},SceneUtils={addMesh:function(a,b,f,e,g,h,j,c,i,l){b=new THREE.Mesh(b,l);b.scale.x=b.scale.y=b.scale.z=f;b.position.x=e;b.position.y=g;b.position.z=h;b.rotation.x=j;b.rotation.y=c;b.rotation.z=i;a.addObject(b);return b},addPanoramaCubeWebGL:function(a,b,f){var e=ShaderUtils.lib.cube;e.uniforms.tCube.texture=f;f=new THREE.MeshShaderMaterial({fragment_shader:e.fragment_shader,vertex_shader:e.vertex_shader,
uniforms:e.uniforms});b=new THREE.Mesh(new Cube(b,b,b,1,1,null,true),f);a.addObject(b);return b},addPanoramaCube:function(a,b,f){var e=[];e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(f[0])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(f[1])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(f[2])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(f[3])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(f[4])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(f[5])}));
b=new THREE.Mesh(new Cube(b,b,b,1,1,e,true),new THREE.MeshFaceMaterial);a.addObject(b);return b},addPanoramaCubePlanes:function(a,b,f){var e=b/2;b=new Plane(b,b);var g=Math.PI/2,h=Math.PI;SceneUtils.addMesh(a,b,1,0,0,-e,0,0,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(f[5])}));SceneUtils.addMesh(a,b,1,-e,0,0,0,g,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(f[0])}));SceneUtils.addMesh(a,b,1,e,0,0,0,-g,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(f[1])}));SceneUtils.addMesh(a,
b,1,0,e,0,g,0,h,new THREE.MeshBasicMaterial({map:new THREE.Texture(f[2])}));SceneUtils.addMesh(a,b,1,0,-e,0,-g,0,h,new THREE.MeshBasicMaterial({map:new THREE.Texture(f[3])}))}},ShaderUtils={lib:{fresnel:{uniforms:{mRefractionRatio:{type:"f",value:1.02},mFresnelBias:{type:"f",value:0.1},mFresnelPower:{type:"f",value:2},mFresnelScale:{type:"f",value:1},tCube:{type:"t",value:1,texture:null}},fragment_shader:"uniform samplerCube tCube;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main() {\nvec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\nvec4 refractedColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nrefractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;\nrefractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;\nrefractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;\nrefractedColor.a = 1.0;\ngl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );\n}",
@@ -202,38 +202,38 @@ normal:{uniforms:{enableAO:{type:"i",value:0},enableDiffuse:{type:"i",value:0},t
uDirLightColor:{type:"c",value:new THREE.Color(15658734)},uAmbientLightColor:{type:"c",value:new THREE.Color(328965)},uDiffuseColor:{type:"c",value:new THREE.Color(15658734)},uSpecularColor:{type:"c",value:new THREE.Color(1118481)},uAmbientColor:{type:"c",value:new THREE.Color(328965)},uShininess:{type:"f",value:30}},fragment_shader:"uniform vec3 uDirLightPos;\nuniform vec3 uAmbientLightColor;\nuniform vec3 uDirLightColor;\nuniform vec3 uPointLightColor;\nuniform vec3 uAmbientColor;\nuniform vec3 uDiffuseColor;\nuniform vec3 uSpecularColor;\nuniform float uShininess;\nuniform bool enableDiffuse;\nuniform bool enableAO;\nuniform sampler2D tDiffuse;\nuniform sampler2D tNormal;\nuniform sampler2D tAO;\nuniform float uNormalScale;\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vPointLightVector;\nvarying vec3 vViewPosition;\nvoid main() {\nvec3 diffuseTex = vec3( 1.0, 1.0, 1.0 );\nvec3 aoTex = vec3( 1.0, 1.0, 1.0 );\nvec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;\nnormalTex.xy *= uNormalScale;\nnormalTex = normalize( normalTex );\nif( enableDiffuse )\ndiffuseTex = texture2D( tDiffuse, vUv ).xyz;\nif( enableAO )\naoTex = texture2D( tAO, vUv ).xyz;\nmat3 tsb = mat3( vTangent, vBinormal, vNormal );\nvec3 finalNormal = tsb * normalTex;\nvec3 normal = normalize( finalNormal );\nvec3 viewPosition = normalize( vViewPosition );\nvec4 pointDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec3 pointVector = normalize( vPointLightVector );\nvec3 pointHalfVector = normalize( vPointLightVector + vViewPosition );\nfloat pointDotNormalHalf = dot( normal, pointHalfVector );\nfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );\nfloat pointSpecularWeight = 0.0;\nif ( pointDotNormalHalf >= 0.0 )\npointSpecularWeight = pow( pointDotNormalHalf, uShininess );\npointDiffuse += vec4( uDiffuseColor, 1.0 ) * pointDiffuseWeight;\npointSpecular += vec4( uSpecularColor, 1.0 ) * pointSpecularWeight;\nvec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec4 lDirection = viewMatrix * vec4( uDirLightPos, 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nvec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );\nfloat dirDotNormalHalf = dot( normal, dirHalfVector );\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\nfloat dirSpecularWeight = 0.0;\nif ( dirDotNormalHalf >= 0.0 )\ndirSpecularWeight = pow( dirDotNormalHalf, uShininess );\ndirDiffuse += vec4( uDiffuseColor, 1.0 ) * dirDiffuseWeight;\ndirSpecular += vec4( uSpecularColor, 1.0 ) * dirSpecularWeight;\nvec4 totalLight = vec4( uAmbientLightColor * uAmbientColor, 1.0 );\ntotalLight += vec4( uDirLightColor, 1.0 ) * ( dirDiffuse + dirSpecular );\ntotalLight += vec4( uPointLightColor, 1.0 ) * ( pointDiffuse + pointSpecular );\ngl_FragColor = vec4( totalLight.xyz * aoTex * diffuseTex, 1.0 );\n}",
vertex_shader:"attribute vec4 tangent;\nuniform vec3 uPointLightPos;\n#ifdef VERTEX_TEXTURES\nuniform sampler2D tDisplacement;\nuniform float uDisplacementScale;\nuniform float uDisplacementBias;\n#endif\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vPointLightVector;\nvarying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalize( normalMatrix * normal );\nvTangent = normalize( normalMatrix * tangent.xyz );\nvBinormal = cross( vNormal, vTangent ) * tangent.w;\nvBinormal = normalize( vBinormal );\nvUv = uv;\nvec4 lPosition = viewMatrix * vec4( uPointLightPos, 1.0 );\nvPointLightVector = normalize( lPosition.xyz - mvPosition.xyz );\n#ifdef VERTEX_TEXTURES\nvec3 dv = texture2D( tDisplacement, uv ).xyz;\nfloat df = uDisplacementScale * dv.x + uDisplacementBias;\nvec4 displacedPosition = vec4( vNormal.xyz * df, 0.0 ) + mvPosition;\ngl_Position = projectionMatrix * displacedPosition;\n#else\ngl_Position = projectionMatrix * mvPosition;\n#endif\n}"},
basic:{uniforms:{},vertex_shader:"void main() {\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragment_shader:"void main() {\ngl_FragColor = vec4(1.0, 0.0, 0.0, 0.5);\n}"},cube:{uniforms:{tCube:{type:"t",value:1,texture:null}},vertex_shader:"varying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",
fragment_shader:"uniform samplerCube tCube;\nvarying vec3 vViewPosition;\nvoid main() {\nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( - wPos.x, wPos.yz ) );\n}"}}},Cube=function(a,b,f,e,g,h,j,c){function i(A,K,p,C,d,k,r,q){var o,l,x=e||1,u=g||1,E=x+1,z=u+1,w=d/2,D=k/2;d=d/x;var $=k/u,M=m.vertices.length;if(A=="x"&&K=="y"||A=="y"&&K=="x")o="z";else if(A=="x"&&K=="z"||A=="z"&&K=="x")o="y";else if(A=="z"&&K=="y"||A=="y"&&K=="z")o="x";for(l=0;l<z;l++)for(k=0;k<
E;k++){var U=new THREE.Vector3;U[A]=(k*d-w)*p;U[K]=(l*$-D)*C;U[o]=r;m.vertices.push(new THREE.Vertex(U))}for(l=0;l<u;l++)for(k=0;k<x;k++){m.faces.push(new THREE.Face4(k+E*l+M,k+E*(l+1)+M,k+1+E*(l+1)+M,k+1+E*l+M,null,q));m.uvs.push([new THREE.UV(k/x,l/u),new THREE.UV(k/x,(l+1)/u),new THREE.UV((k+1)/x,(l+1)/u),new THREE.UV((k+1)/x,l/u)])}}THREE.Geometry.call(this);var m=this,s=a/2,B=b/2,n=f/2;j=j?-1:1;if(h!==undefined)if(h instanceof Array)this.materials=h;else{this.materials=[];for(var v=0;v<6;v++)this.materials.push([h])}else this.materials=
[];this.sides={px:true,nx:true,py:true,ny:true,pz:true,nz:true};if(c!=undefined)for(var y in c)if(this.sides[y]!=undefined)this.sides[y]=c[y];this.sides.px&&i("z","y",1*j,-1,f,b,-s,this.materials[0]);this.sides.nx&&i("z","y",-1*j,-1,f,b,s,this.materials[1]);this.sides.py&&i("x","z",1*j,1,a,f,B,this.materials[2]);this.sides.ny&&i("x","z",1*j,-1,a,f,-B,this.materials[3]);this.sides.pz&&i("x","y",1*j,-1,a,b,n,this.materials[4]);this.sides.nz&&i("x","y",-1*j,-1,a,b,-n,this.materials[5]);(function(){for(var A=
[],K=[],p=0,C=m.vertices.length;p<C;p++){for(var d=m.vertices[p],k=false,r=0,q=A.length;r<q;r++){var o=A[r];if(d.position.x==o.position.x&&d.position.y==o.position.y&&d.position.z==o.position.z){K[p]=r;k=true;break}}if(!k){K[p]=A.length;A.push(new THREE.Vertex(d.position.clone()))}}p=0;for(C=m.faces.length;p<C;p++){d=m.faces[p];d.a=K[d.a];d.b=K[d.b];d.c=K[d.c];d.d=K[d.d]}m.vertices=A})();this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};Cube.prototype=new THREE.Geometry;
fragment_shader:"uniform samplerCube tCube;\nvarying vec3 vViewPosition;\nvoid main() {\nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( - wPos.x, wPos.yz ) );\n}"}}},Cube=function(a,b,f,e,g,h,j,c){function i(A,K,p,E,d,k,q,s){var n,m,x=e||1,t=g||1,D=x+1,y=t+1,w=d/2,C=k/2;d=d/x;var $=k/t,M=l.vertices.length;if(A=="x"&&K=="y"||A=="y"&&K=="x")n="z";else if(A=="x"&&K=="z"||A=="z"&&K=="x")n="y";else if(A=="z"&&K=="y"||A=="y"&&K=="z")n="x";for(m=0;m<y;m++)for(k=0;k<
D;k++){var U=new THREE.Vector3;U[A]=(k*d-w)*p;U[K]=(m*$-C)*E;U[n]=q;l.vertices.push(new THREE.Vertex(U))}for(m=0;m<t;m++)for(k=0;k<x;k++){l.faces.push(new THREE.Face4(k+D*m+M,k+D*(m+1)+M,k+1+D*(m+1)+M,k+1+D*m+M,null,s));l.uvs.push([new THREE.UV(k/x,m/t),new THREE.UV(k/x,(m+1)/t),new THREE.UV((k+1)/x,(m+1)/t),new THREE.UV((k+1)/x,m/t)])}}THREE.Geometry.call(this);var l=this,r=a/2,B=b/2,o=f/2;j=j?-1:1;if(h!==undefined)if(h instanceof Array)this.materials=h;else{this.materials=[];for(var v=0;v<6;v++)this.materials.push([h])}else this.materials=
[];this.sides={px:true,nx:true,py:true,ny:true,pz:true,nz:true};if(c!=undefined)for(var z in c)if(this.sides[z]!=undefined)this.sides[z]=c[z];this.sides.px&&i("z","y",1*j,-1,f,b,-r,this.materials[0]);this.sides.nx&&i("z","y",-1*j,-1,f,b,r,this.materials[1]);this.sides.py&&i("x","z",1*j,1,a,f,B,this.materials[2]);this.sides.ny&&i("x","z",1*j,-1,a,f,-B,this.materials[3]);this.sides.pz&&i("x","y",1*j,-1,a,b,o,this.materials[4]);this.sides.nz&&i("x","y",-1*j,-1,a,b,-o,this.materials[5]);(function(){for(var A=
[],K=[],p=0,E=l.vertices.length;p<E;p++){for(var d=l.vertices[p],k=false,q=0,s=A.length;q<s;q++){var n=A[q];if(d.position.x==n.position.x&&d.position.y==n.position.y&&d.position.z==n.position.z){K[p]=q;k=true;break}}if(!k){K[p]=A.length;A.push(new THREE.Vertex(d.position.clone()))}}p=0;for(E=l.faces.length;p<E;p++){d=l.faces[p];d.a=K[d.a];d.b=K[d.b];d.c=K[d.c];d.d=K[d.d]}l.vertices=A})();this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};Cube.prototype=new THREE.Geometry;
Cube.prototype.constructor=Cube;
var Cylinder=function(a,b,f,e,g){function h(m,s,B){j.vertices.push(new THREE.Vertex(new THREE.Vector3(m,s,B)))}THREE.Geometry.call(this);var j=this,c=Math.PI,i;for(i=0;i<a;i++)h(Math.sin(2*c*i/a)*b,Math.cos(2*c*i/a)*b,0);for(i=0;i<a;i++)h(Math.sin(2*c*i/a)*f,Math.cos(2*c*i/a)*f,e);for(i=0;i<a;i++)j.faces.push(new THREE.Face4(i,i+a,a+(i+1)%a,(i+1)%a));if(f!=0){h(0,0,-g);for(i=a;i<a+a/2;i++)j.faces.push(new THREE.Face4(2*a,(2*i-2*a)%a,(2*i-2*a+1)%a,(2*i-2*a+2)%a))}if(b!=0){h(0,0,e+g);for(i=a+a/2;i<
var Cylinder=function(a,b,f,e,g){function h(l,r,B){j.vertices.push(new THREE.Vertex(new THREE.Vector3(l,r,B)))}THREE.Geometry.call(this);var j=this,c=Math.PI,i;for(i=0;i<a;i++)h(Math.sin(2*c*i/a)*b,Math.cos(2*c*i/a)*b,0);for(i=0;i<a;i++)h(Math.sin(2*c*i/a)*f,Math.cos(2*c*i/a)*f,e);for(i=0;i<a;i++)j.faces.push(new THREE.Face4(i,i+a,a+(i+1)%a,(i+1)%a));if(f!=0){h(0,0,-g);for(i=a;i<a+a/2;i++)j.faces.push(new THREE.Face4(2*a,(2*i-2*a)%a,(2*i-2*a+1)%a,(2*i-2*a+2)%a))}if(b!=0){h(0,0,e+g);for(i=a+a/2;i<
2*a;i++)j.faces.push(new THREE.Face4((2*i-2*a+2)%a+a,(2*i-2*a+1)%a+a,(2*i-2*a)%a+a,2*a+1))}this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};Cylinder.prototype=new THREE.Geometry;Cylinder.prototype.constructor=Cylinder;
var Plane=function(a,b,f,e){THREE.Geometry.call(this);var g,h=a/2,j=b/2;f=f||1;e=e||1;var c=f+1,i=e+1;a=a/f;var m=b/e;for(g=0;g<i;g++)for(b=0;b<c;b++)this.vertices.push(new THREE.Vertex(new THREE.Vector3(b*a-h,-(g*m-j),0)));for(g=0;g<e;g++)for(b=0;b<f;b++){this.faces.push(new THREE.Face4(b+c*g,b+c*(g+1),b+1+c*(g+1),b+1+c*g));this.uvs.push([new THREE.UV(b/f,g/e),new THREE.UV(b/f,(g+1)/e),new THREE.UV((b+1)/f,(g+1)/e),new THREE.UV((b+1)/f,g/e)])}this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};
var Plane=function(a,b,f,e){THREE.Geometry.call(this);var g,h=a/2,j=b/2;f=f||1;e=e||1;var c=f+1,i=e+1;a=a/f;var l=b/e;for(g=0;g<i;g++)for(b=0;b<c;b++)this.vertices.push(new THREE.Vertex(new THREE.Vector3(b*a-h,-(g*l-j),0)));for(g=0;g<e;g++)for(b=0;b<f;b++){this.faces.push(new THREE.Face4(b+c*g,b+c*(g+1),b+1+c*(g+1),b+1+c*g));this.uvs.push([new THREE.UV(b/f,g/e),new THREE.UV(b/f,(g+1)/e),new THREE.UV((b+1)/f,(g+1)/e),new THREE.UV((b+1)/f,g/e)])}this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};
Plane.prototype=new THREE.Geometry;Plane.prototype.constructor=Plane;
var Sphere=function(a,b,f){THREE.Geometry.call(this);var e,g=Math.PI,h=Math.max(3,b||8),j=Math.max(2,f||6);b=[];for(f=0;f<j+1;f++){e=f/j;var c=a*Math.cos(e*g),i=a*Math.sin(e*g),m=[],s=0;for(e=0;e<h;e++){var B=2*e/h,n=i*Math.sin(B*g);B=i*Math.cos(B*g);(f==0||f==j)&&e>0||(s=this.vertices.push(new THREE.Vertex(new THREE.Vector3(B,c,n)))-1);m.push(s)}b.push(m)}var v,y,A;g=b.length;for(f=0;f<g;f++){h=b[f].length;if(f>0)for(e=0;e<h;e++){m=e==h-1;j=b[f][m?0:e+1];c=b[f][m?h-1:e];i=b[f-1][m?h-1:e];m=b[f-1][m?
0:e+1];n=f/(g-1);v=(f-1)/(g-1);y=(e+1)/h;B=e/h;s=new THREE.UV(1-y,n);n=new THREE.UV(1-B,n);B=new THREE.UV(1-B,v);var K=new THREE.UV(1-y,v);if(f<b.length-1){v=this.vertices[j].position.clone();y=this.vertices[c].position.clone();A=this.vertices[i].position.clone();v.normalize();y.normalize();A.normalize();this.faces.push(new THREE.Face3(j,c,i,[new THREE.Vector3(v.x,v.y,v.z),new THREE.Vector3(y.x,y.y,y.z),new THREE.Vector3(A.x,A.y,A.z)]));this.uvs.push([s,n,B])}if(f>1){v=this.vertices[j].position.clone();
y=this.vertices[i].position.clone();A=this.vertices[m].position.clone();v.normalize();y.normalize();A.normalize();this.faces.push(new THREE.Face3(j,i,m,[new THREE.Vector3(v.x,v.y,v.z),new THREE.Vector3(y.x,y.y,y.z),new THREE.Vector3(A.x,A.y,A.z)]));this.uvs.push([s,B,K])}}}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.sortFacesByMaterial();this.boundingSphere={radius:a}};Sphere.prototype=new THREE.Geometry;Sphere.prototype.constructor=Sphere;
var Sphere=function(a,b,f){THREE.Geometry.call(this);var e,g=Math.PI,h=Math.max(3,b||8),j=Math.max(2,f||6);b=[];for(f=0;f<j+1;f++){e=f/j;var c=a*Math.cos(e*g),i=a*Math.sin(e*g),l=[],r=0;for(e=0;e<h;e++){var B=2*e/h,o=i*Math.sin(B*g);B=i*Math.cos(B*g);(f==0||f==j)&&e>0||(r=this.vertices.push(new THREE.Vertex(new THREE.Vector3(B,c,o)))-1);l.push(r)}b.push(l)}var v,z,A;g=b.length;for(f=0;f<g;f++){h=b[f].length;if(f>0)for(e=0;e<h;e++){l=e==h-1;j=b[f][l?0:e+1];c=b[f][l?h-1:e];i=b[f-1][l?h-1:e];l=b[f-1][l?
0:e+1];o=f/(g-1);v=(f-1)/(g-1);z=(e+1)/h;B=e/h;r=new THREE.UV(1-z,o);o=new THREE.UV(1-B,o);B=new THREE.UV(1-B,v);var K=new THREE.UV(1-z,v);if(f<b.length-1){v=this.vertices[j].position.clone();z=this.vertices[c].position.clone();A=this.vertices[i].position.clone();v.normalize();z.normalize();A.normalize();this.faces.push(new THREE.Face3(j,c,i,[new THREE.Vector3(v.x,v.y,v.z),new THREE.Vector3(z.x,z.y,z.z),new THREE.Vector3(A.x,A.y,A.z)]));this.uvs.push([r,o,B])}if(f>1){v=this.vertices[j].position.clone();
z=this.vertices[i].position.clone();A=this.vertices[l].position.clone();v.normalize();z.normalize();A.normalize();this.faces.push(new THREE.Face3(j,i,l,[new THREE.Vector3(v.x,v.y,v.z),new THREE.Vector3(z.x,z.y,z.z),new THREE.Vector3(A.x,A.y,A.z)]));this.uvs.push([r,B,K])}}}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.sortFacesByMaterial();this.boundingSphere={radius:a}};Sphere.prototype=new THREE.Geometry;Sphere.prototype.constructor=Sphere;
THREE.Loader=function(a){this.statusDomElement=(this.showStatus=a)?this.addStatusElement():null};
THREE.Loader.prototype={addStatusElement:function(){var a=document.createElement("div");a.style.fontSize="0.8em";a.style.textAlign="left";a.style.background="#b00";a.style.color="#fff";a.style.width="140px";a.style.padding="0.25em 0.25em 0.25em 0.5em";a.style.position="absolute";a.style.right="0px";a.style.top="0px";a.style.zIndex=1E3;a.innerHTML="Loading ...";return a},updateProgress:function(a){var b="Loaded ";b+=a.total?(100*a.loaded/a.total).toFixed(0)+"%":(a.loaded/1E3).toFixed(2)+" KB";this.statusDomElement.innerHTML=
b},loadAsciiOld:function(a,b){var f=document.createElement("script");f.type="text/javascript";f.onload=b;f.src=a;document.getElementsByTagName("head")[0].appendChild(f)},loadAscii:function(a){var b=a.model,f=a.callback,e=a.texture_path?a.texture_path:THREE.Loader.prototype.extractUrlbase(b);a=(new Date).getTime();b=new Worker(b);b.onmessage=function(g){THREE.Loader.prototype.createModel(g.data,f,e)};b.postMessage(a)},loadBinary:function(a){var b=a.model,f=a.callback,e=a.texture_path?a.texture_path:
THREE.Loader.prototype.extractUrlbase(b),g=a.bin_path?a.bin_path:THREE.Loader.prototype.extractUrlbase(b);a=(new Date).getTime();b=new Worker(b);var h=this.showProgress?THREE.Loader.prototype.updateProgress:null;b.onmessage=function(j){THREE.Loader.prototype.loadAjaxBuffers(j.data.buffers,j.data.materials,f,g,e,h)};b.onerror=function(j){alert("worker.onerror: "+j.message+"\n"+j.data);j.preventDefault()};b.postMessage(a)},loadAjaxBuffers:function(a,b,f,e,g,h){var j=new XMLHttpRequest,c=e+"/"+a,i=0;
j.onreadystatechange=function(){if(j.readyState==4)j.status==200||j.status==0?THREE.Loader.prototype.createBinModel(j.responseText,f,g,b):alert("Couldn't load ["+c+"] ["+j.status+"]");else if(j.readyState==3){if(h){if(i==0)i=j.getResponseHeader("Content-Length");h({total:i,loaded:j.responseText.length})}}else if(j.readyState==2)i=j.getResponseHeader("Content-Length")};j.open("GET",c,true);j.overrideMimeType("text/plain; charset=x-user-defined");j.setRequestHeader("Content-Type","text/plain");j.send(null)},
createBinModel:function(a,b,f,e){var g=function(h){function j(t,G){var H=s(t,G),Q=s(t,G+1),aa=s(t,G+2),ka=s(t,G+3),ea=(ka<<1&255|aa>>7)-127;H=(aa&127)<<16|Q<<8|H;if(H==0&&ea==-127)return 0;return(1-2*(ka>>7))*(1+H*Math.pow(2,-23))*Math.pow(2,ea)}function c(t,G){var H=s(t,G),Q=s(t,G+1),aa=s(t,G+2);return(s(t,G+3)<<24)+(aa<<16)+(Q<<8)+H}function i(t,G){var H=s(t,G);return(s(t,G+1)<<8)+H}function m(t,G){var H=s(t,G);return H>127?H-256:H}function s(t,G){return t.charCodeAt(G)&255}function B(t){var G,
H,Q;G=c(a,t);H=c(a,t+q);Q=c(a,t+o);t=i(a,t+l);THREE.Loader.prototype.f3(p,G,H,Q,t)}function n(t){var G,H,Q,aa,ka,ea;G=c(a,t);H=c(a,t+q);Q=c(a,t+o);aa=i(a,t+l);ka=c(a,t+x);ea=c(a,t+u);t=c(a,t+E);THREE.Loader.prototype.f3n(p,k,G,H,Q,aa,ka,ea,t)}function v(t){var G,H,Q,aa;G=c(a,t);H=c(a,t+z);Q=c(a,t+w);aa=c(a,t+D);t=i(a,t+$);THREE.Loader.prototype.f4(p,G,H,Q,aa,t)}function y(t){var G,H,Q,aa,ka,ea,ra,ta;G=c(a,t);H=c(a,t+z);Q=c(a,t+w);aa=c(a,t+D);ka=i(a,t+$);ea=c(a,t+M);ra=c(a,t+U);ta=c(a,t+V);t=c(a,t+
O);THREE.Loader.prototype.f4n(p,k,G,H,Q,aa,ka,ea,ra,ta,t)}function A(t){var G,H;G=c(a,t);H=c(a,t+ba);t=c(a,t+R);THREE.Loader.prototype.uv3(p,r[G*2],r[G*2+1],r[H*2],r[H*2+1],r[t*2],r[t*2+1])}function K(t){var G,H,Q;G=c(a,t);H=c(a,t+L);Q=c(a,t+N);t=c(a,t+Z);THREE.Loader.prototype.uv4(p,r[G*2],r[G*2+1],r[H*2],r[H*2+1],r[Q*2],r[Q*2+1],r[t*2],r[t*2+1])}var p=this,C=0,d,k=[],r=[],q,o,l,x,u,E,z,w,D,$,M,U,V,O,ba,R,L,N,Z,W,I,S,Y,ha,ja;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(p,e,h);
d={signature:a.substr(C,8),header_bytes:s(a,C+8),vertex_coordinate_bytes:s(a,C+9),normal_coordinate_bytes:s(a,C+10),uv_coordinate_bytes:s(a,C+11),vertex_index_bytes:s(a,C+12),normal_index_bytes:s(a,C+13),uv_index_bytes:s(a,C+14),material_index_bytes:s(a,C+15),nvertices:c(a,C+16),nnormals:c(a,C+16+4),nuvs:c(a,C+16+8),ntri_flat:c(a,C+16+12),ntri_smooth:c(a,C+16+16),ntri_flat_uv:c(a,C+16+20),ntri_smooth_uv:c(a,C+16+24),nquad_flat:c(a,C+16+28),nquad_smooth:c(a,C+16+32),nquad_flat_uv:c(a,C+16+36),nquad_smooth_uv:c(a,
C+16+40)};C+=d.header_bytes;q=d.vertex_index_bytes;o=d.vertex_index_bytes*2;l=d.vertex_index_bytes*3;x=d.vertex_index_bytes*3+d.material_index_bytes;u=d.vertex_index_bytes*3+d.material_index_bytes+d.normal_index_bytes;E=d.vertex_index_bytes*3+d.material_index_bytes+d.normal_index_bytes*2;z=d.vertex_index_bytes;w=d.vertex_index_bytes*2;D=d.vertex_index_bytes*3;$=d.vertex_index_bytes*4;M=d.vertex_index_bytes*4+d.material_index_bytes;U=d.vertex_index_bytes*4+d.material_index_bytes+d.normal_index_bytes;
createBinModel:function(a,b,f,e){var g=function(h){function j(u,G){var H=r(u,G),Q=r(u,G+1),aa=r(u,G+2),ka=r(u,G+3),ea=(ka<<1&255|aa>>7)-127;H=(aa&127)<<16|Q<<8|H;if(H==0&&ea==-127)return 0;return(1-2*(ka>>7))*(1+H*Math.pow(2,-23))*Math.pow(2,ea)}function c(u,G){var H=r(u,G),Q=r(u,G+1),aa=r(u,G+2);return(r(u,G+3)<<24)+(aa<<16)+(Q<<8)+H}function i(u,G){var H=r(u,G);return(r(u,G+1)<<8)+H}function l(u,G){var H=r(u,G);return H>127?H-256:H}function r(u,G){return u.charCodeAt(G)&255}function B(u){var G,
H,Q;G=c(a,u);H=c(a,u+s);Q=c(a,u+n);u=i(a,u+m);THREE.Loader.prototype.f3(p,G,H,Q,u)}function o(u){var G,H,Q,aa,ka,ea;G=c(a,u);H=c(a,u+s);Q=c(a,u+n);aa=i(a,u+m);ka=c(a,u+x);ea=c(a,u+t);u=c(a,u+D);THREE.Loader.prototype.f3n(p,k,G,H,Q,aa,ka,ea,u)}function v(u){var G,H,Q,aa;G=c(a,u);H=c(a,u+y);Q=c(a,u+w);aa=c(a,u+C);u=i(a,u+$);THREE.Loader.prototype.f4(p,G,H,Q,aa,u)}function z(u){var G,H,Q,aa,ka,ea,ra,ta;G=c(a,u);H=c(a,u+y);Q=c(a,u+w);aa=c(a,u+C);ka=i(a,u+$);ea=c(a,u+M);ra=c(a,u+U);ta=c(a,u+V);u=c(a,u+
O);THREE.Loader.prototype.f4n(p,k,G,H,Q,aa,ka,ea,ra,ta,u)}function A(u){var G,H;G=c(a,u);H=c(a,u+ba);u=c(a,u+R);THREE.Loader.prototype.uv3(p,q[G*2],q[G*2+1],q[H*2],q[H*2+1],q[u*2],q[u*2+1])}function K(u){var G,H,Q;G=c(a,u);H=c(a,u+L);Q=c(a,u+N);u=c(a,u+Z);THREE.Loader.prototype.uv4(p,q[G*2],q[G*2+1],q[H*2],q[H*2+1],q[Q*2],q[Q*2+1],q[u*2],q[u*2+1])}var p=this,E=0,d,k=[],q=[],s,n,m,x,t,D,y,w,C,$,M,U,V,O,ba,R,L,N,Z,W,I,S,Y,ha,ja;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(p,e,h);
d={signature:a.substr(E,8),header_bytes:r(a,E+8),vertex_coordinate_bytes:r(a,E+9),normal_coordinate_bytes:r(a,E+10),uv_coordinate_bytes:r(a,E+11),vertex_index_bytes:r(a,E+12),normal_index_bytes:r(a,E+13),uv_index_bytes:r(a,E+14),material_index_bytes:r(a,E+15),nvertices:c(a,E+16),nnormals:c(a,E+16+4),nuvs:c(a,E+16+8),ntri_flat:c(a,E+16+12),ntri_smooth:c(a,E+16+16),ntri_flat_uv:c(a,E+16+20),ntri_smooth_uv:c(a,E+16+24),nquad_flat:c(a,E+16+28),nquad_smooth:c(a,E+16+32),nquad_flat_uv:c(a,E+16+36),nquad_smooth_uv:c(a,
E+16+40)};E+=d.header_bytes;s=d.vertex_index_bytes;n=d.vertex_index_bytes*2;m=d.vertex_index_bytes*3;x=d.vertex_index_bytes*3+d.material_index_bytes;t=d.vertex_index_bytes*3+d.material_index_bytes+d.normal_index_bytes;D=d.vertex_index_bytes*3+d.material_index_bytes+d.normal_index_bytes*2;y=d.vertex_index_bytes;w=d.vertex_index_bytes*2;C=d.vertex_index_bytes*3;$=d.vertex_index_bytes*4;M=d.vertex_index_bytes*4+d.material_index_bytes;U=d.vertex_index_bytes*4+d.material_index_bytes+d.normal_index_bytes;
V=d.vertex_index_bytes*4+d.material_index_bytes+d.normal_index_bytes*2;O=d.vertex_index_bytes*4+d.material_index_bytes+d.normal_index_bytes*3;ba=d.uv_index_bytes;R=d.uv_index_bytes*2;L=d.uv_index_bytes;N=d.uv_index_bytes*2;Z=d.uv_index_bytes*3;h=d.vertex_index_bytes*3+d.material_index_bytes;ja=d.vertex_index_bytes*4+d.material_index_bytes;W=d.ntri_flat*h;I=d.ntri_smooth*(h+d.normal_index_bytes*3);S=d.ntri_flat_uv*(h+d.uv_index_bytes*3);Y=d.ntri_smooth_uv*(h+d.normal_index_bytes*3+d.uv_index_bytes*
3);ha=d.nquad_flat*ja;h=d.nquad_smooth*(ja+d.normal_index_bytes*4);ja=d.nquad_flat_uv*(ja+d.uv_index_bytes*4);C+=function(t){var G,H,Q,aa=d.vertex_coordinate_bytes*3,ka=t+d.nvertices*aa;for(t=t;t<ka;t+=aa){G=j(a,t);H=j(a,t+d.vertex_coordinate_bytes);Q=j(a,t+d.vertex_coordinate_bytes*2);THREE.Loader.prototype.v(p,G,H,Q)}return d.nvertices*aa}(C);C+=function(t){var G,H,Q,aa=d.normal_coordinate_bytes*3,ka=t+d.nnormals*aa;for(t=t;t<ka;t+=aa){G=m(a,t);H=m(a,t+d.normal_coordinate_bytes);Q=m(a,t+d.normal_coordinate_bytes*
2);k.push(G/127,H/127,Q/127)}return d.nnormals*aa}(C);C+=function(t){var G,H,Q=d.uv_coordinate_bytes*2,aa=t+d.nuvs*Q;for(t=t;t<aa;t+=Q){G=j(a,t);H=j(a,t+d.uv_coordinate_bytes);r.push(G,H)}return d.nuvs*Q}(C);C=C;W=C+W;I=W+I;S=I+S;Y=S+Y;ha=Y+ha;h=ha+h;ja=h+ja;(function(t){var G,H=d.vertex_index_bytes*3+d.material_index_bytes,Q=H+d.uv_index_bytes*3,aa=t+d.ntri_flat_uv*Q;for(G=t;G<aa;G+=Q){B(G);A(G+H)}return aa-t})(I);(function(t){var G,H=d.vertex_index_bytes*3+d.material_index_bytes+d.normal_index_bytes*
3,Q=H+d.uv_index_bytes*3,aa=t+d.ntri_smooth_uv*Q;for(G=t;G<aa;G+=Q){n(G);A(G+H)}return aa-t})(S);(function(t){var G,H=d.vertex_index_bytes*4+d.material_index_bytes,Q=H+d.uv_index_bytes*4,aa=t+d.nquad_flat_uv*Q;for(G=t;G<aa;G+=Q){v(G);K(G+H)}return aa-t})(h);(function(t){var G,H=d.vertex_index_bytes*4+d.material_index_bytes+d.normal_index_bytes*4,Q=H+d.uv_index_bytes*4,aa=t+d.nquad_smooth_uv*Q;for(G=t;G<aa;G+=Q){y(G);K(G+H)}return aa-t})(ja);(function(t){var G,H=d.vertex_index_bytes*3+d.material_index_bytes,
Q=t+d.ntri_flat*H;for(G=t;G<Q;G+=H)B(G);return Q-t})(C);(function(t){var G,H=d.vertex_index_bytes*3+d.material_index_bytes+d.normal_index_bytes*3,Q=t+d.ntri_smooth*H;for(G=t;G<Q;G+=H)n(G);return Q-t})(W);(function(t){var G,H=d.vertex_index_bytes*4+d.material_index_bytes,Q=t+d.nquad_flat*H;for(G=t;G<Q;G+=H)v(G);return Q-t})(Y);(function(t){var G,H=d.vertex_index_bytes*4+d.material_index_bytes+d.normal_index_bytes*4,Q=t+d.nquad_smooth*H;for(G=t;G<Q;G+=H)y(G);return Q-t})(ha);this.computeCentroids();
this.computeFaceNormals();this.sortFacesByMaterial()};g.prototype=new THREE.Geometry;g.prototype.constructor=g;b(new g(f))},createModel:function(a,b,f){var e=function(g){var h=this;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(h,a.materials,g);(function(){var j,c,i,m,s;j=0;for(c=a.vertices.length;j<c;j+=3){i=a.vertices[j];m=a.vertices[j+1];s=a.vertices[j+2];THREE.Loader.prototype.v(h,i,m,s)}})();(function(){function j(y,A){THREE.Loader.prototype.f3(h,y[A],y[A+1],y[A+2],y[A+3])}function c(y,
A){THREE.Loader.prototype.f3n(h,a.normals,y[A],y[A+1],y[A+2],y[A+3],y[A+4],y[A+5],y[A+6])}function i(y,A){THREE.Loader.prototype.f4(h,y[A],y[A+1],y[A+2],y[A+3],y[A+4])}function m(y,A){THREE.Loader.prototype.f4n(h,a.normals,y[A],y[A+1],y[A+2],y[A+3],y[A+4],y[A+5],y[A+6],y[A+7],y[A+8])}function s(y,A){var K,p,C;K=y[A];p=y[A+1];C=y[A+2];THREE.Loader.prototype.uv3(h,a.uvs[K*2],a.uvs[K*2+1],a.uvs[p*2],a.uvs[p*2+1],a.uvs[C*2],a.uvs[C*2+1])}function B(y,A){var K,p,C,d;K=y[A];p=y[A+1];C=y[A+2];d=y[A+3];THREE.Loader.prototype.uv4(h,
a.uvs[K*2],a.uvs[K*2+1],a.uvs[p*2],a.uvs[p*2+1],a.uvs[C*2],a.uvs[C*2+1],a.uvs[d*2],a.uvs[d*2+1])}var n,v;n=0;for(v=a.triangles_uv.length;n<v;n+=7){j(a.triangles_uv,n);s(a.triangles_uv,n+4)}n=0;for(v=a.triangles_n_uv.length;n<v;n+=10){c(a.triangles_n_uv,n);s(a.triangles_n_uv,n+7)}n=0;for(v=a.quads_uv.length;n<v;n+=9){i(a.quads_uv,n);B(a.quads_uv,n+5)}n=0;for(v=a.quads_n_uv.length;n<v;n+=13){m(a.quads_n_uv,n);B(a.quads_n_uv,n+9)}n=0;for(v=a.triangles.length;n<v;n+=4)j(a.triangles,n);n=0;for(v=a.triangles_n.length;n<
v;n+=7)c(a.triangles_n,n);n=0;for(v=a.quads.length;n<v;n+=5)i(a.quads,n);n=0;for(v=a.quads_n.length;n<v;n+=9)m(a.quads_n,n)})();this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};e.prototype=new THREE.Geometry;e.prototype.constructor=e;b(new e(f))},v:function(a,b,f,e){a.vertices.push(new THREE.Vertex(new THREE.Vector3(b,f,e)))},f3:function(a,b,f,e,g){a.faces.push(new THREE.Face3(b,f,e,null,a.materials[g]))},f4:function(a,b,f,e,g,h){a.faces.push(new THREE.Face4(b,f,e,g,null,
a.materials[h]))},f3n:function(a,b,f,e,g,h,j,c,i){h=a.materials[h];var m=b[c*3],s=b[c*3+1];c=b[c*3+2];var B=b[i*3],n=b[i*3+1];i=b[i*3+2];a.faces.push(new THREE.Face3(f,e,g,[new THREE.Vector3(b[j*3],b[j*3+1],b[j*3+2]),new THREE.Vector3(m,s,c),new THREE.Vector3(B,n,i)],h))},f4n:function(a,b,f,e,g,h,j,c,i,m,s){j=a.materials[j];var B=b[i*3],n=b[i*3+1];i=b[i*3+2];var v=b[m*3],y=b[m*3+1];m=b[m*3+2];var A=b[s*3],K=b[s*3+1];s=b[s*3+2];a.faces.push(new THREE.Face4(f,e,g,h,[new THREE.Vector3(b[c*3],b[c*3+1],
b[c*3+2]),new THREE.Vector3(B,n,i),new THREE.Vector3(v,y,m),new THREE.Vector3(A,K,s)],j))},uv3:function(a,b,f,e,g,h,j){var c=[];c.push(new THREE.UV(b,f));c.push(new THREE.UV(e,g));c.push(new THREE.UV(h,j));a.uvs.push(c)},uv4:function(a,b,f,e,g,h,j,c,i){var m=[];m.push(new THREE.UV(b,f));m.push(new THREE.UV(e,g));m.push(new THREE.UV(h,j));m.push(new THREE.UV(c,i));a.uvs.push(m)},init_materials:function(a,b,f){a.materials=[];for(var e=0;e<b.length;++e)a.materials[e]=[THREE.Loader.prototype.createMaterial(b[e],
3);ha=d.nquad_flat*ja;h=d.nquad_smooth*(ja+d.normal_index_bytes*4);ja=d.nquad_flat_uv*(ja+d.uv_index_bytes*4);E+=function(u){var G,H,Q,aa=d.vertex_coordinate_bytes*3,ka=u+d.nvertices*aa;for(u=u;u<ka;u+=aa){G=j(a,u);H=j(a,u+d.vertex_coordinate_bytes);Q=j(a,u+d.vertex_coordinate_bytes*2);THREE.Loader.prototype.v(p,G,H,Q)}return d.nvertices*aa}(E);E+=function(u){var G,H,Q,aa=d.normal_coordinate_bytes*3,ka=u+d.nnormals*aa;for(u=u;u<ka;u+=aa){G=l(a,u);H=l(a,u+d.normal_coordinate_bytes);Q=l(a,u+d.normal_coordinate_bytes*
2);k.push(G/127,H/127,Q/127)}return d.nnormals*aa}(E);E+=function(u){var G,H,Q=d.uv_coordinate_bytes*2,aa=u+d.nuvs*Q;for(u=u;u<aa;u+=Q){G=j(a,u);H=j(a,u+d.uv_coordinate_bytes);q.push(G,H)}return d.nuvs*Q}(E);E=E;W=E+W;I=W+I;S=I+S;Y=S+Y;ha=Y+ha;h=ha+h;ja=h+ja;(function(u){var G,H=d.vertex_index_bytes*3+d.material_index_bytes,Q=H+d.uv_index_bytes*3,aa=u+d.ntri_flat_uv*Q;for(G=u;G<aa;G+=Q){B(G);A(G+H)}return aa-u})(I);(function(u){var G,H=d.vertex_index_bytes*3+d.material_index_bytes+d.normal_index_bytes*
3,Q=H+d.uv_index_bytes*3,aa=u+d.ntri_smooth_uv*Q;for(G=u;G<aa;G+=Q){o(G);A(G+H)}return aa-u})(S);(function(u){var G,H=d.vertex_index_bytes*4+d.material_index_bytes,Q=H+d.uv_index_bytes*4,aa=u+d.nquad_flat_uv*Q;for(G=u;G<aa;G+=Q){v(G);K(G+H)}return aa-u})(h);(function(u){var G,H=d.vertex_index_bytes*4+d.material_index_bytes+d.normal_index_bytes*4,Q=H+d.uv_index_bytes*4,aa=u+d.nquad_smooth_uv*Q;for(G=u;G<aa;G+=Q){z(G);K(G+H)}return aa-u})(ja);(function(u){var G,H=d.vertex_index_bytes*3+d.material_index_bytes,
Q=u+d.ntri_flat*H;for(G=u;G<Q;G+=H)B(G);return Q-u})(E);(function(u){var G,H=d.vertex_index_bytes*3+d.material_index_bytes+d.normal_index_bytes*3,Q=u+d.ntri_smooth*H;for(G=u;G<Q;G+=H)o(G);return Q-u})(W);(function(u){var G,H=d.vertex_index_bytes*4+d.material_index_bytes,Q=u+d.nquad_flat*H;for(G=u;G<Q;G+=H)v(G);return Q-u})(Y);(function(u){var G,H=d.vertex_index_bytes*4+d.material_index_bytes+d.normal_index_bytes*4,Q=u+d.nquad_smooth*H;for(G=u;G<Q;G+=H)z(G);return Q-u})(ha);this.computeCentroids();
this.computeFaceNormals();this.sortFacesByMaterial()};g.prototype=new THREE.Geometry;g.prototype.constructor=g;b(new g(f))},createModel:function(a,b,f){var e=function(g){var h=this;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(h,a.materials,g);(function(){var j,c,i,l,r;j=0;for(c=a.vertices.length;j<c;j+=3){i=a.vertices[j];l=a.vertices[j+1];r=a.vertices[j+2];THREE.Loader.prototype.v(h,i,l,r)}})();(function(){function j(z,A){THREE.Loader.prototype.f3(h,z[A],z[A+1],z[A+2],z[A+3])}function c(z,
A){THREE.Loader.prototype.f3n(h,a.normals,z[A],z[A+1],z[A+2],z[A+3],z[A+4],z[A+5],z[A+6])}function i(z,A){THREE.Loader.prototype.f4(h,z[A],z[A+1],z[A+2],z[A+3],z[A+4])}function l(z,A){THREE.Loader.prototype.f4n(h,a.normals,z[A],z[A+1],z[A+2],z[A+3],z[A+4],z[A+5],z[A+6],z[A+7],z[A+8])}function r(z,A){var K,p,E;K=z[A];p=z[A+1];E=z[A+2];THREE.Loader.prototype.uv3(h,a.uvs[K*2],a.uvs[K*2+1],a.uvs[p*2],a.uvs[p*2+1],a.uvs[E*2],a.uvs[E*2+1])}function B(z,A){var K,p,E,d;K=z[A];p=z[A+1];E=z[A+2];d=z[A+3];THREE.Loader.prototype.uv4(h,
a.uvs[K*2],a.uvs[K*2+1],a.uvs[p*2],a.uvs[p*2+1],a.uvs[E*2],a.uvs[E*2+1],a.uvs[d*2],a.uvs[d*2+1])}var o,v;o=0;for(v=a.triangles_uv.length;o<v;o+=7){j(a.triangles_uv,o);r(a.triangles_uv,o+4)}o=0;for(v=a.triangles_n_uv.length;o<v;o+=10){c(a.triangles_n_uv,o);r(a.triangles_n_uv,o+7)}o=0;for(v=a.quads_uv.length;o<v;o+=9){i(a.quads_uv,o);B(a.quads_uv,o+5)}o=0;for(v=a.quads_n_uv.length;o<v;o+=13){l(a.quads_n_uv,o);B(a.quads_n_uv,o+9)}o=0;for(v=a.triangles.length;o<v;o+=4)j(a.triangles,o);o=0;for(v=a.triangles_n.length;o<
v;o+=7)c(a.triangles_n,o);o=0;for(v=a.quads.length;o<v;o+=5)i(a.quads,o);o=0;for(v=a.quads_n.length;o<v;o+=9)l(a.quads_n,o)})();this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};e.prototype=new THREE.Geometry;e.prototype.constructor=e;b(new e(f))},v:function(a,b,f,e){a.vertices.push(new THREE.Vertex(new THREE.Vector3(b,f,e)))},f3:function(a,b,f,e,g){a.faces.push(new THREE.Face3(b,f,e,null,a.materials[g]))},f4:function(a,b,f,e,g,h){a.faces.push(new THREE.Face4(b,f,e,g,null,
a.materials[h]))},f3n:function(a,b,f,e,g,h,j,c,i){h=a.materials[h];var l=b[c*3],r=b[c*3+1];c=b[c*3+2];var B=b[i*3],o=b[i*3+1];i=b[i*3+2];a.faces.push(new THREE.Face3(f,e,g,[new THREE.Vector3(b[j*3],b[j*3+1],b[j*3+2]),new THREE.Vector3(l,r,c),new THREE.Vector3(B,o,i)],h))},f4n:function(a,b,f,e,g,h,j,c,i,l,r){j=a.materials[j];var B=b[i*3],o=b[i*3+1];i=b[i*3+2];var v=b[l*3],z=b[l*3+1];l=b[l*3+2];var A=b[r*3],K=b[r*3+1];r=b[r*3+2];a.faces.push(new THREE.Face4(f,e,g,h,[new THREE.Vector3(b[c*3],b[c*3+1],
b[c*3+2]),new THREE.Vector3(B,o,i),new THREE.Vector3(v,z,l),new THREE.Vector3(A,K,r)],j))},uv3:function(a,b,f,e,g,h,j){var c=[];c.push(new THREE.UV(b,f));c.push(new THREE.UV(e,g));c.push(new THREE.UV(h,j));a.uvs.push(c)},uv4:function(a,b,f,e,g,h,j,c,i){var l=[];l.push(new THREE.UV(b,f));l.push(new THREE.UV(e,g));l.push(new THREE.UV(h,j));l.push(new THREE.UV(c,i));a.uvs.push(l)},init_materials:function(a,b,f){a.materials=[];for(var e=0;e<b.length;++e)a.materials[e]=[THREE.Loader.prototype.createMaterial(b[e],
f)]},createMaterial:function(a,b){function f(h){h=Math.log(h)/Math.LN2;return Math.floor(h)==h}var e,g;if(a.map_diffuse&&b){g=document.createElement("canvas");e=new THREE.MeshLambertMaterial({map:new THREE.Texture(g)});g=new Image;g.onload=function(){if(!f(this.width)||!f(this.height)){var h=Math.pow(2,Math.round(Math.log(this.width)/Math.LN2)),j=Math.pow(2,Math.round(Math.log(this.height)/Math.LN2));e.map.image.width=h;e.map.image.height=j;e.map.image.getContext("2d").drawImage(this,0,0,h,j)}else e.map.image=
this;e.map.image.loaded=1};g.src=b+"/"+a.map_diffuse}else if(a.col_diffuse){g=(a.col_diffuse[0]*255<<16)+(a.col_diffuse[1]*255<<8)+a.col_diffuse[2]*255;e=new THREE.MeshLambertMaterial({color:g,opacity:a.transparency})}else e=a.a_dbg_color?new THREE.MeshLambertMaterial({color:a.a_dbg_color}):new THREE.MeshLambertMaterial({color:15658734});return e},extractUrlbase:function(a){a=a.split("/");a.pop();return a.join("/")}};
+1
View File
@@ -38,6 +38,7 @@
<script type="text/javascript" src="../src/lights/PointLight.js"></script>
<script type="text/javascript" src="../src/objects/Object3D.js"></script>
<script type="text/javascript" src="../src/objects/Particle.js"></script>
<script type="text/javascript" src="../src/objects/ParticleSystem.js"></script>
<script type="text/javascript" src="../src/objects/Line.js"></script>
<script type="text/javascript" src="../src/objects/Mesh.js"></script>
<script type="text/javascript" src="../src/materials/Material.js"></script>
+46 -44
View File
@@ -116,6 +116,9 @@ THREE.WebGLRenderer = function ( parameters ) {
};
this.createParticleBuffers = function( object ) {
};
this.createLineBuffers = function( object ) {
var v, vl, vertex,
@@ -727,7 +730,18 @@ THREE.WebGLRenderer = function ( parameters ) {
this.initWebGLObjects = function( scene ) {
var o, ol, object, globject, g, geometryChunk, objmap;
function add_buffer( objmap, id, buffer, object ) {
if ( objmap[ id ] == undefined ) {
scene.__webGLObjects.push( { buffer: buffer, object: object } );
objmap[ id ] = 1;
}
};
var o, ol, object, g, geometryChunk, objmap;
if ( !scene.__webGLObjects ) {
@@ -766,14 +780,7 @@ THREE.WebGLRenderer = function ( parameters ) {
// create separate wrapper per each use of VBO
if ( objmap[ g ] == undefined ) {
globject = { buffer: geometryChunk, object: object };
scene.__webGLObjects.push( globject );
objmap[ g ] = 1;
}
add_buffer( objmap, g, geometryChunk, object );
}
@@ -786,20 +793,21 @@ THREE.WebGLRenderer = function ( parameters ) {
}
g = 0;
add_buffer( objmap, 0, object, object );
if ( objmap[ g ] == undefined ) {
globject = { buffer: object, object: object };
scene.__webGLObjects.push( globject );
objmap[ g ] = 1;
} else if ( object instanceof THREE.ParticleSystem ) {
if( ! object.__webGLVertexBuffer ) {
this.createParticleBuffers( object );
}
}/* else if ( object instanceof THREE.ParticleSystem ) {
}else if ( object instanceof THREE.Particle ) {
add_buffer( objmap, 0, object, object );
}/*else if ( object instanceof THREE.Particle ) {
}*/
@@ -1275,37 +1283,31 @@ THREE.WebGLRenderer = function ( parameters ) {
function allocateLights( lights, maxLights ) {
if ( scene ) {
var l, ll, light, dirLights, pointLights, maxDirLights, maxPointLights;
dirLights = pointLights = maxDirLights = maxPointLights = 0;
var l, ll, light, dirLights, pointLights, maxDirLights, maxPointLights;
dirLights = pointLights = maxDirLights = maxPointLights = 0;
for ( l = 0, ll = lights.length; l < ll; l++ ) {
for ( l = 0, ll = lights.length; l < ll; l++ ) {
light = lights[ l ];
light = lights[ l ];
if ( light instanceof THREE.DirectionalLight ) dirLights++;
if ( light instanceof THREE.PointLight ) pointLights++;
}
if ( ( pointLights + dirLights ) <= maxLights ) {
maxDirLights = dirLights;
maxPointLights = pointLights;
} else {
maxDirLights = Math.ceil( maxLights * dirLights / ( pointLights + dirLights ) );
maxPointLights = maxLights - maxDirLights;
}
return { 'directional' : maxDirLights, 'point' : maxPointLights };
if ( light instanceof THREE.DirectionalLight ) dirLights++;
if ( light instanceof THREE.PointLight ) pointLights++;
}
return { 'directional' : 1, 'point' : maxLights - 1 };
if ( ( pointLights + dirLights ) <= maxLights ) {
maxDirLights = dirLights;
maxPointLights = pointLights;
} else {
maxDirLights = Math.ceil( maxLights * dirLights / ( pointLights + dirLights ) );
maxPointLights = maxLights - maxDirLights;
}
return { 'directional' : maxDirLights, 'point' : maxPointLights };
};