ThreeDebug.js 106 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. // ThreeDebug.js r32 - http://github.com/mrdoob/three.js
  2. var THREE=THREE||{};THREE.Color=function(a){this.autoUpdate=true;this.setHex(a)};
  3. THREE.Color.prototype={setRGB:function(a,c,d){this.r=a;this.g=c;this.b=d;if(this.autoUpdate){this.updateHex();this.updateStyleString()}},setHSV:function(a,c,d){var h,j,m,b,r,o;if(d==0)h=j=m=0;else{b=Math.floor(a*6);r=a*6-b;a=d*(1-c);o=d*(1-c*r);c=d*(1-c*(1-r));switch(b){case 1:h=o;j=d;m=a;break;case 2:h=a;j=d;m=c;break;case 3:h=a;j=o;m=d;break;case 4:h=c;j=a;m=d;break;case 5:h=d;j=a;m=o;break;case 6:case 0:h=d;j=c;m=a}}this.r=h;this.g=j;this.b=m;if(this.autoUpdate){this.updateHex();this.updateStyleString()}},
  4. setHex:function(a){this.hex=~~a&16777215;if(this.autoUpdate){this.updateRGBA();this.updateStyleString()}},updateHex:function(){this.hex=~~(this.r*255)<<16^~~(this.g*255)<<8^~~(this.b*255)},updateRGBA:function(){this.r=(this.hex>>16&255)/255;this.g=(this.hex>>8&255)/255;this.b=(this.hex&255)/255},updateStyleString:function(){this.__styleString="rgb("+~~(this.r*255)+","+~~(this.g*255)+","+~~(this.b*255)+")"},clone:function(){return new THREE.Color(this.hex)},toString:function(){return"THREE.Color ( r: "+
  5. this.r+", g: "+this.g+", b: "+this.b+", hex: "+this.hex+" )"}};THREE.Vector2=function(a,c){this.x=a||0;this.y=c||0};
  6. THREE.Vector2.prototype={set:function(a,c){this.x=a;this.y=c;return this},copy:function(a){this.x=a.x;this.y=a.y;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;return this},add:function(a,c){this.x=a.x+c.x;this.y=a.y+c.y;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;return this},sub:function(a,c){this.x=a.x-c.x;this.y=a.y-c.y;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;return this},unit:function(){this.multiplyScalar(1/this.length());return this},length:function(){return Math.sqrt(this.x*
  7. this.x+this.y*this.y)},lengthSq:function(){return this.x*this.x+this.y*this.y},negate:function(){this.x=-this.x;this.y=-this.y;return this},clone:function(){return new THREE.Vector2(this.x,this.y)},toString:function(){return"THREE.Vector2 ("+this.x+", "+this.y+")"}};THREE.Vector3=function(a,c,d){this.x=a||0;this.y=c||0;this.z=d||0};
  8. THREE.Vector3.prototype={set:function(a,c,d){this.x=a;this.y=c;this.z=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this},add:function(a,c){this.x=a.x+c.x;this.y=a.y+c.y;this.z=a.z+c.z;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;return this},addScalar:function(a){this.x+=a;this.y+=a;this.z+=a;return this},sub:function(a,c){this.x=a.x-c.x;this.y=a.y-c.y;this.z=a.z-c.z;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;return this},
  9. cross:function(a,c){this.x=a.y*c.z-a.z*c.y;this.y=a.z*c.x-a.x*c.z;this.z=a.x*c.y-a.y*c.x;return this},crossSelf:function(a){var c=this.x,d=this.y,h=this.z;this.x=d*a.z-h*a.y;this.y=h*a.x-c*a.z;this.z=c*a.y-d*a.x;return this},multiply:function(a,c){this.x=a.x*c.x;this.y=a.y*c.y;this.z=a.z*c.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;return this},divideSelf:function(a){this.x/=a.x;this.y/=a.y;this.z/=
  10. a.z;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=a;return this},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},distanceTo:function(a){var c=this.x-a.x,d=this.y-a.y;a=this.z-a.z;return Math.sqrt(c*c+d*d+a*a)},distanceToSquared:function(a){var c=this.x-a.x,d=this.y-a.y;a=this.z-a.z;return c*c+d*d+a*a},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},negate:function(){this.x=
  11. -this.x;this.y=-this.y;this.z=-this.z;return this},normalize:function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z);a>0?this.multiplyScalar(1/a):this.set(0,0,0);return this},setLength:function(a){return this.normalize().multiplyScalar(a)},isZero:function(){return Math.abs(this.x)<1.0E-4&&Math.abs(this.y)<1.0E-4&&Math.abs(this.z)<1.0E-4},clone:function(){return new THREE.Vector3(this.x,this.y,this.z)},toString:function(){return"THREE.Vector3 ( "+this.x+", "+this.y+", "+this.z+" )"}};
  12. THREE.Vector4=function(a,c,d,h){this.x=a||0;this.y=c||0;this.z=d||0;this.w=h||1};
  13. THREE.Vector4.prototype={set:function(a,c,d,h){this.x=a;this.y=c;this.z=d;this.w=h;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w||1;return this},add:function(a,c){this.x=a.x+c.x;this.y=a.y+c.y;this.z=a.z+c.z;this.w=a.w+c.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,c){this.x=a.x-c.x;this.y=a.y-c.y;this.z=a.z-c.z;this.w=a.w-c.w;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;
  14. return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=a;this.w/=a;return this},lerpSelf:function(a,c){this.x+=(a.x-this.x)*c;this.y+=(a.y-this.y)*c;this.z+=(a.z-this.z)*c;this.w+=(a.w-this.w)*c},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},toString:function(){return"THREE.Vector4 ("+this.x+", "+this.y+", "+this.z+", "+this.w+")"}};
  15. THREE.Ray=function(a,c){this.origin=a||new THREE.Vector3;this.direction=c||new THREE.Vector3};
  16. THREE.Ray.prototype={intersectScene:function(a){var c,d,h=a.objects,j=[];a=0;for(c=h.length;a<c;a++){d=h[a];if(d instanceof THREE.Mesh)j=j.concat(this.intersectObject(d))}j.sort(function(m,b){return m.distance-b.distance});return j},intersectObject:function(a){function c(e,g,i,f){f=f.clone().subSelf(g);i=i.clone().subSelf(g);var k=e.clone().subSelf(g);e=f.dot(f);g=f.dot(i);f=f.dot(k);var l=i.dot(i);i=i.dot(k);k=1/(e*l-g*g);l=(l*f-g*i)*k;e=(e*i-g*f)*k;return l>0&&e>0&&l+e<1}var d,h,j,m,b,r,o,p,B,A,
  17. u,y=a.geometry,H=y.vertices,L=[];d=0;for(h=y.faces.length;d<h;d++){j=y.faces[d];A=this.origin.clone();u=this.direction.clone();m=a.matrix.multiplyVector3(H[j.a].position.clone());b=a.matrix.multiplyVector3(H[j.b].position.clone());r=a.matrix.multiplyVector3(H[j.c].position.clone());o=j instanceof THREE.Face4?a.matrix.multiplyVector3(H[j.d].position.clone()):null;p=a.rotationMatrix.multiplyVector3(j.normal.clone());B=u.dot(p);if(B<0){p=p.dot((new THREE.Vector3).sub(m,A))/B;A=A.addSelf(u.multiplyScalar(p));
  18. if(j instanceof THREE.Face3){if(c(A,m,b,r)){j={distance:this.origin.distanceTo(A),point:A,face:j,object:a};L.push(j)}}else if(j instanceof THREE.Face4)if(c(A,m,b,o)||c(A,b,r,o)){j={distance:this.origin.distanceTo(A),point:A,face:j,object:a};L.push(j)}}}return L}};
  19. THREE.Rectangle=function(){function a(){m=h-c;b=j-d}var c,d,h,j,m,b,r=true;this.getX=function(){return c};this.getY=function(){return d};this.getWidth=function(){return m};this.getHeight=function(){return b};this.getLeft=function(){return c};this.getTop=function(){return d};this.getRight=function(){return h};this.getBottom=function(){return j};this.set=function(o,p,B,A){r=false;c=o;d=p;h=B;j=A;a()};this.addPoint=function(o,p){if(r){r=false;c=o;d=p;h=o;j=p}else{c=c<o?c:o;d=d<p?d:p;h=h>o?h:o;j=j>p?
  20. j:p}a()};this.add3Points=function(o,p,B,A,u,y){if(r){r=false;c=o<B?o<u?o:u:B<u?B:u;d=p<A?p<y?p:y:A<y?A:y;h=o>B?o>u?o:u:B>u?B:u;j=p>A?p>y?p:y:A>y?A:y}else{c=o<B?o<u?o<c?o:c:u<c?u:c:B<u?B<c?B:c:u<c?u:c;d=p<A?p<y?p<d?p:d:y<d?y:d:A<y?A<d?A:d:y<d?y:d;h=o>B?o>u?o>h?o:h:u>h?u:h:B>u?B>h?B:h:u>h?u:h;j=p>A?p>y?p>j?p:j:y>j?y:j:A>y?A>j?A:j:y>j?y:j}a()};this.addRectangle=function(o){if(r){r=false;c=o.getLeft();d=o.getTop();h=o.getRight();j=o.getBottom()}else{c=c<o.getLeft()?c:o.getLeft();d=d<o.getTop()?d:o.getTop();
  21. h=h>o.getRight()?h:o.getRight();j=j>o.getBottom()?j:o.getBottom()}a()};this.inflate=function(o){c-=o;d-=o;h+=o;j+=o;a()};this.minSelf=function(o){c=c>o.getLeft()?c:o.getLeft();d=d>o.getTop()?d:o.getTop();h=h<o.getRight()?h:o.getRight();j=j<o.getBottom()?j:o.getBottom();a()};this.instersects=function(o){return Math.min(h,o.getRight())-Math.max(c,o.getLeft())>=0&&Math.min(j,o.getBottom())-Math.max(d,o.getTop())>=0};this.empty=function(){r=true;j=h=d=c=0;a()};this.isEmpty=function(){return r};this.toString=
  22. function(){return"THREE.Rectangle ( left: "+c+", right: "+h+", top: "+d+", bottom: "+j+", width: "+m+", height: "+b+" )"}};THREE.Matrix3=function(){this.m=[]};THREE.Matrix3.prototype={transpose:function(){var a,c=this.m;a=c[1];c[1]=c[3];c[3]=a;a=c[2];c[2]=c[6];c[6]=a;a=c[5];c[5]=c[7];c[7]=a;return this}};
  23. THREE.Matrix4=function(a,c,d,h,j,m,b,r,o,p,B,A,u,y,H,L){this.n11=a||1;this.n12=c||0;this.n13=d||0;this.n14=h||0;this.n21=j||0;this.n22=m||1;this.n23=b||0;this.n24=r||0;this.n31=o||0;this.n32=p||0;this.n33=B||1;this.n34=A||0;this.n41=u||0;this.n42=y||0;this.n43=H||0;this.n44=L||1;this.flat=Array(16);this.m33=new THREE.Matrix3};
  24. THREE.Matrix4.prototype={identity:function(){this.n11=1;this.n21=this.n14=this.n13=this.n12=0;this.n22=1;this.n32=this.n31=this.n24=this.n23=0;this.n33=1;this.n43=this.n42=this.n41=this.n34=0;this.n44=1;return this},set:function(a,c,d,h,j,m,b,r,o,p,B,A,u,y,H,L){this.n11=a;this.n12=c;this.n13=d;this.n14=h;this.n21=j;this.n22=m;this.n23=b;this.n24=r;this.n31=o;this.n32=p;this.n33=B;this.n34=A;this.n41=u;this.n42=y;this.n43=H;this.n44=L;return this},copy:function(a){this.n11=a.n11;this.n12=a.n12;this.n13=
  25. a.n13;this.n14=a.n14;this.n21=a.n21;this.n22=a.n22;this.n23=a.n23;this.n24=a.n24;this.n31=a.n31;this.n32=a.n32;this.n33=a.n33;this.n34=a.n34;this.n41=a.n41;this.n42=a.n42;this.n43=a.n43;this.n44=a.n44;return this},lookAt:function(a,c,d){var h=THREE.Matrix4.__tmpVec1,j=THREE.Matrix4.__tmpVec2,m=THREE.Matrix4.__tmpVec3;m.sub(a,c).normalize();h.cross(d,m).normalize();j.cross(m,h).normalize();this.n11=h.x;this.n12=h.y;this.n13=h.z;this.n14=-h.dot(a);this.n21=j.x;this.n22=j.y;this.n23=j.z;this.n24=-j.dot(a);
  26. this.n31=m.x;this.n32=m.y;this.n33=m.z;this.n34=-m.dot(a);this.n43=this.n42=this.n41=0;this.n44=1;return this},multiplyVector3:function(a){var c=a.x,d=a.y,h=a.z,j=1/(this.n41*c+this.n42*d+this.n43*h+this.n44);a.x=(this.n11*c+this.n12*d+this.n13*h+this.n14)*j;a.y=(this.n21*c+this.n22*d+this.n23*h+this.n24)*j;a.z=(this.n31*c+this.n32*d+this.n33*h+this.n34)*j;return a},multiplyVector4:function(a){var c=a.x,d=a.y,h=a.z,j=a.w;a.x=this.n11*c+this.n12*d+this.n13*h+this.n14*j;a.y=this.n21*c+this.n22*d+this.n23*
  27. h+this.n24*j;a.z=this.n31*c+this.n32*d+this.n33*h+this.n34*j;a.w=this.n41*c+this.n42*d+this.n43*h+this.n44*j;return a},crossVector:function(a){var c=new THREE.Vector4;c.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;c.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;c.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;c.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return c},multiply:function(a,c){var d=a.n11,h=a.n12,j=a.n13,m=a.n14,b=a.n21,r=a.n22,o=a.n23,p=a.n24,B=a.n31,
  28. A=a.n32,u=a.n33,y=a.n34,H=a.n41,L=a.n42,e=a.n43,g=a.n44,i=c.n11,f=c.n12,k=c.n13,l=c.n14,t=c.n21,q=c.n22,n=c.n23,z=c.n24,s=c.n31,w=c.n32,E=c.n33,v=c.n34,D=c.n41,W=c.n42,J=c.n43,Q=c.n44;this.n11=d*i+h*t+j*s+m*D;this.n12=d*f+h*q+j*w+m*W;this.n13=d*k+h*n+j*E+m*J;this.n14=d*l+h*z+j*v+m*Q;this.n21=b*i+r*t+o*s+p*D;this.n22=b*f+r*q+o*w+p*W;this.n23=b*k+r*n+o*E+p*J;this.n24=b*l+r*z+o*v+p*Q;this.n31=B*i+A*t+u*s+y*D;this.n32=B*f+A*q+u*w+y*W;this.n33=B*k+A*n+u*E+y*J;this.n34=B*l+A*z+u*v+y*Q;this.n41=H*i+L*t+
  29. e*s+g*D;this.n42=H*f+L*q+e*w+g*W;this.n43=H*k+L*n+e*E+g*J;this.n44=H*l+L*z+e*v+g*Q;return this},multiplySelf:function(a){var c=this.n11,d=this.n12,h=this.n13,j=this.n14,m=this.n21,b=this.n22,r=this.n23,o=this.n24,p=this.n31,B=this.n32,A=this.n33,u=this.n34,y=this.n41,H=this.n42,L=this.n43,e=this.n44,g=a.n11,i=a.n21,f=a.n31,k=a.n41,l=a.n12,t=a.n22,q=a.n32,n=a.n42,z=a.n13,s=a.n23,w=a.n33,E=a.n43,v=a.n14,D=a.n24,W=a.n34;a=a.n44;this.n11=c*g+d*i+h*f+j*k;this.n12=c*l+d*t+h*q+j*n;this.n13=c*z+d*s+h*w+j*
  30. E;this.n14=c*v+d*D+h*W+j*a;this.n21=m*g+b*i+r*f+o*k;this.n22=m*l+b*t+r*q+o*n;this.n23=m*z+b*s+r*w+o*E;this.n24=m*v+b*D+r*W+o*a;this.n31=p*g+B*i+A*f+u*k;this.n32=p*l+B*t+A*q+u*n;this.n33=p*z+B*s+A*w+u*E;this.n34=p*v+B*D+A*W+u*a;this.n41=y*g+H*i+L*f+e*k;this.n42=y*l+H*t+L*q+e*n;this.n43=y*z+H*s+L*w+e*E;this.n44=y*v+H*D+L*W+e*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*=
  31. a;this.n41*=a;this.n42*=a;this.n43*=a;this.n44*=a;return this},determinant:function(){var a=this.n11,c=this.n12,d=this.n13,h=this.n14,j=this.n21,m=this.n22,b=this.n23,r=this.n24,o=this.n31,p=this.n32,B=this.n33,A=this.n34,u=this.n41,y=this.n42,H=this.n43,L=this.n44;return h*b*p*u-d*r*p*u-h*m*B*u+c*r*B*u+d*m*A*u-c*b*A*u-h*b*o*y+d*r*o*y+h*j*B*y-a*r*B*y-d*j*A*y+a*b*A*y+h*m*o*H-c*r*o*H-h*j*p*H+a*r*p*H+c*j*A*H-a*m*A*H-d*m*o*L+c*b*o*L+d*j*p*L-a*b*p*L-c*j*B*L+a*m*B*L},transpose:function(){function a(c,d,
  32. h){var j=c[d];c[d]=c[h];c[h]=j}a(this,"n21","n12");a(this,"n31","n13");a(this,"n32","n23");a(this,"n41","n14");a(this,"n42","n24");a(this,"n43","n34");return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=this.n44;return a},flatten:function(){var a=this.flat;a[0]=this.n11;
  33. a[1]=this.n21;a[2]=this.n31;a[3]=this.n41;a[4]=this.n12;a[5]=this.n22;a[6]=this.n32;a[7]=this.n42;a[8]=this.n13;a[9]=this.n23;a[10]=this.n33;a[11]=this.n43;a[12]=this.n14;a[13]=this.n24;a[14]=this.n34;a[15]=this.n44;return a},setTranslation:function(a,c,d){this.set(1,0,0,a,0,1,0,c,0,0,1,d,0,0,0,1);return this},setScale:function(a,c,d){this.set(a,0,0,0,0,c,0,0,0,0,d,0,0,0,0,1);return this},setRotX:function(a){var c=Math.cos(a);a=Math.sin(a);this.set(1,0,0,0,0,c,-a,0,0,a,c,0,0,0,0,1);return this},setRotY:function(a){var c=
  34. Math.cos(a);a=Math.sin(a);this.set(c,0,a,0,0,1,0,0,-a,0,c,0,0,0,0,1);return this},setRotZ:function(a){var c=Math.cos(a);a=Math.sin(a);this.set(c,-a,0,0,a,c,0,0,0,0,1,0,0,0,0,1);return this},setRotAxis:function(a,c){var d=Math.cos(c),h=Math.sin(c),j=1-d,m=a.x,b=a.y,r=a.z,o=j*m,p=j*b;this.set(o*m+d,o*b-h*r,o*r+h*b,0,o*b+h*r,p*b+d,p*r-h*m,0,o*r-h*b,p*r+h*m,j*r*r+d,0,0,0,0,1);return this},toString:function(){return"| "+this.n11+" "+this.n12+" "+this.n13+" "+this.n14+" |\n| "+this.n21+" "+this.n22+" "+
  35. this.n23+" "+this.n24+" |\n| "+this.n31+" "+this.n32+" "+this.n33+" "+this.n34+" |\n| "+this.n41+" "+this.n42+" "+this.n43+" "+this.n44+" |"}};THREE.Matrix4.translationMatrix=function(a,c,d){var h=new THREE.Matrix4;h.setTranslation(a,c,d);return h};THREE.Matrix4.scaleMatrix=function(a,c,d){var h=new THREE.Matrix4;h.setScale(a,c,d);return h};THREE.Matrix4.rotationXMatrix=function(a){var c=new THREE.Matrix4;c.setRotX(a);return c};
  36. THREE.Matrix4.rotationYMatrix=function(a){var c=new THREE.Matrix4;c.setRotY(a);return c};THREE.Matrix4.rotationZMatrix=function(a){var c=new THREE.Matrix4;c.setRotZ(a);return c};THREE.Matrix4.rotationAxisAngleMatrix=function(a,c){var d=new THREE.Matrix4;d.setRotAxis(a,c);return d};
  37. THREE.Matrix4.makeInvert=function(a){var c=a.n11,d=a.n12,h=a.n13,j=a.n14,m=a.n21,b=a.n22,r=a.n23,o=a.n24,p=a.n31,B=a.n32,A=a.n33,u=a.n34,y=a.n41,H=a.n42,L=a.n43,e=a.n44,g=new THREE.Matrix4;g.n11=r*u*H-o*A*H+o*B*L-b*u*L-r*B*e+b*A*e;g.n12=j*A*H-h*u*H-j*B*L+d*u*L+h*B*e-d*A*e;g.n13=h*o*H-j*r*H+j*b*L-d*o*L-h*b*e+d*r*e;g.n14=j*r*B-h*o*B-j*b*A+d*o*A+h*b*u-d*r*u;g.n21=o*A*y-r*u*y-o*p*L+m*u*L+r*p*e-m*A*e;g.n22=h*u*y-j*A*y+j*p*L-c*u*L-h*p*e+c*A*e;g.n23=j*r*y-h*o*y-j*m*L+c*o*L+h*m*e-c*r*e;g.n24=h*o*p-j*r*p+
  38. j*m*A-c*o*A-h*m*u+c*r*u;g.n31=b*u*y-o*B*y+o*p*H-m*u*H-b*p*e+m*B*e;g.n32=j*B*y-d*u*y-j*p*H+c*u*H+d*p*e-c*B*e;g.n33=h*o*y-j*b*y+j*m*H-c*o*H-d*m*e+c*b*e;g.n34=j*b*p-d*o*p-j*m*B+c*o*B+d*m*u-c*b*u;g.n41=r*B*y-b*A*y-r*p*H+m*A*H+b*p*L-m*B*L;g.n42=d*A*y-h*B*y+h*p*H-c*A*H-d*p*L+c*B*L;g.n43=h*b*y-d*r*y-h*m*H+c*r*H+d*m*L-c*b*L;g.n44=d*r*p-h*b*p+h*m*B-c*r*B-d*m*A+c*b*A;g.multiplyScalar(1/a.determinant());return g};
  39. THREE.Matrix4.makeInvert3x3=function(a){var c=a.flatten();a=a.m33;var d=a.m,h=c[10]*c[5]-c[6]*c[9],j=-c[10]*c[1]+c[2]*c[9],m=c[6]*c[1]-c[2]*c[5],b=-c[10]*c[4]+c[6]*c[8],r=c[10]*c[0]-c[2]*c[8],o=-c[6]*c[0]+c[2]*c[4],p=c[9]*c[4]-c[5]*c[8],B=-c[9]*c[0]+c[1]*c[8],A=c[5]*c[0]-c[1]*c[4];c=c[0]*h+c[1]*b+c[2]*p;if(c==0)throw"matrix not invertible";c=1/c;d[0]=c*h;d[1]=c*j;d[2]=c*m;d[3]=c*b;d[4]=c*r;d[5]=c*o;d[6]=c*p;d[7]=c*B;d[8]=c*A;return a};
  40. THREE.Matrix4.makeFrustum=function(a,c,d,h,j,m){var b,r,o;b=new THREE.Matrix4;r=2*j/(c-a);o=2*j/(h-d);a=(c+a)/(c-a);d=(h+d)/(h-d);h=-(m+j)/(m-j);j=-2*m*j/(m-j);b.n11=r;b.n12=0;b.n13=a;b.n14=0;b.n21=0;b.n22=o;b.n23=d;b.n24=0;b.n31=0;b.n32=0;b.n33=h;b.n34=j;b.n41=0;b.n42=0;b.n43=-1;b.n44=0;return b};THREE.Matrix4.makePerspective=function(a,c,d,h){var j;a=d*Math.tan(a*Math.PI/360);j=-a;return THREE.Matrix4.makeFrustum(j*c,a*c,j,a,d,h)};
  41. THREE.Matrix4.makeOrtho=function(a,c,d,h,j,m){var b,r,o,p;b=new THREE.Matrix4;r=c-a;o=d-h;p=m-j;a=(c+a)/r;d=(d+h)/o;j=(m+j)/p;b.n11=2/r;b.n12=0;b.n13=0;b.n14=-a;b.n21=0;b.n22=2/o;b.n23=0;b.n24=-d;b.n31=0;b.n32=0;b.n33=-2/p;b.n34=-j;b.n41=0;b.n42=0;b.n43=0;b.n44=1;return b};THREE.Matrix4.__tmpVec1=new THREE.Vector3;THREE.Matrix4.__tmpVec2=new THREE.Vector3;THREE.Matrix4.__tmpVec3=new THREE.Vector3;
  42. THREE.Vertex=function(a,c){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=c||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.tangent=new THREE.Vector4;this.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}};
  43. THREE.Face3=function(a,c,d,h,j){this.a=a;this.b=c;this.c=d;this.centroid=new THREE.Vector3;this.normal=h instanceof THREE.Vector3?h:new THREE.Vector3;this.vertexNormals=h instanceof Array?h:[];this.materials=j instanceof Array?j:[j]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
  44. THREE.Face4=function(a,c,d,h,j,m){this.a=a;this.b=c;this.c=d;this.d=h;this.centroid=new THREE.Vector3;this.normal=j instanceof THREE.Vector3?j:new THREE.Vector3;this.vertexNormals=j instanceof Array?j:[];this.materials=m instanceof Array?m:[m]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,c){this.u=a||0;this.v=c||0};
  45. 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.uvs2=[];this.colors=[];this.boundingSphere=this.boundingBox=null;this.geometryChunks={};this.hasTangents=false};
  46. THREE.Geometry.prototype={computeCentroids:function(){var a,c,d;a=0;for(c=this.faces.length;a<c;a++){d=this.faces[a];d.centroid.set(0,0,0);if(d instanceof THREE.Face3){d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);d.centroid.divideScalar(3)}else if(d instanceof THREE.Face4){d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);
  47. d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeFaceNormals:function(a){var c,d,h,j,m,b,r=new THREE.Vector3,o=new THREE.Vector3;h=0;for(j=this.vertices.length;h<j;h++){m=this.vertices[h];m.normal.set(0,0,0)}h=0;for(j=this.faces.length;h<j;h++){m=this.faces[h];if(a&&m.vertexNormals.length){r.set(0,0,0);c=0;for(d=m.normal.length;c<d;c++)r.addSelf(m.vertexNormals[c]);r.divideScalar(3)}else{c=this.vertices[m.a];d=this.vertices[m.b];b=this.vertices[m.c];r.sub(b.position,
  48. d.position);o.sub(c.position,d.position);r.crossSelf(o)}r.isZero()||r.normalize();m.normal.copy(r)}},computeVertexNormals:function(){var a,c,d,h;if(this.__tmpVertices==undefined){h=this.__tmpVertices=Array(this.vertices.length);a=0;for(c=this.vertices.length;a<c;a++)h[a]=new THREE.Vector3;a=0;for(c=this.faces.length;a<c;a++){d=this.faces[a];if(d instanceof THREE.Face3)d.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];else if(d instanceof THREE.Face4)d.vertexNormals=[new THREE.Vector3,
  49. new THREE.Vector3,new THREE.Vector3,new THREE.Vector3]}}else{h=this.__tmpVertices;a=0;for(c=this.vertices.length;a<c;a++)h[a].set(0,0,0)}a=0;for(c=this.faces.length;a<c;a++){d=this.faces[a];if(d instanceof THREE.Face3){h[d.a].addSelf(d.normal);h[d.b].addSelf(d.normal);h[d.c].addSelf(d.normal)}else if(d instanceof THREE.Face4){h[d.a].addSelf(d.normal);h[d.b].addSelf(d.normal);h[d.c].addSelf(d.normal);h[d.d].addSelf(d.normal)}}a=0;for(c=this.vertices.length;a<c;a++)h[a].normalize();a=0;for(c=this.faces.length;a<
  50. c;a++){d=this.faces[a];if(d instanceof THREE.Face3){d.vertexNormals[0].copy(h[d.a]);d.vertexNormals[1].copy(h[d.b]);d.vertexNormals[2].copy(h[d.c])}else if(d instanceof THREE.Face4){d.vertexNormals[0].copy(h[d.a]);d.vertexNormals[1].copy(h[d.b]);d.vertexNormals[2].copy(h[d.c]);d.vertexNormals[3].copy(h[d.d])}}},computeTangents:function(){function a(v,D,W,J,Q,P,F){m=v.vertices[D].position;b=v.vertices[W].position;r=v.vertices[J].position;o=j[Q];p=j[P];B=j[F];A=b.x-m.x;u=r.x-m.x;y=b.y-m.y;H=r.y-m.y;
  51. L=b.z-m.z;e=r.z-m.z;g=p.u-o.u;i=B.u-o.u;f=p.v-o.v;k=B.v-o.v;l=1/(g*k-i*f);n.set((k*A-f*u)*l,(k*y-f*H)*l,(k*L-f*e)*l);z.set((g*u-i*A)*l,(g*H-i*y)*l,(g*e-i*L)*l);t[D].addSelf(n);t[W].addSelf(n);t[J].addSelf(n);q[D].addSelf(z);q[W].addSelf(z);q[J].addSelf(z)}var c,d,h,j,m,b,r,o,p,B,A,u,y,H,L,e,g,i,f,k,l,t=[],q=[],n=new THREE.Vector3,z=new THREE.Vector3,s=new THREE.Vector3,w=new THREE.Vector3,E=new THREE.Vector3;c=0;for(d=this.vertices.length;c<d;c++){t[c]=new THREE.Vector3;q[c]=new THREE.Vector3}c=0;
  52. for(d=this.faces.length;c<d;c++){h=this.faces[c];j=this.uvs[c];if(h instanceof THREE.Face3){a(this,h.a,h.b,h.c,0,1,2);this.vertices[h.a].normal.copy(h.vertexNormals[0]);this.vertices[h.b].normal.copy(h.vertexNormals[1]);this.vertices[h.c].normal.copy(h.vertexNormals[2])}else if(h instanceof THREE.Face4){a(this,h.a,h.b,h.c,0,1,2);a(this,h.a,h.b,h.d,0,1,3);this.vertices[h.a].normal.copy(h.vertexNormals[0]);this.vertices[h.b].normal.copy(h.vertexNormals[1]);this.vertices[h.c].normal.copy(h.vertexNormals[2]);
  53. this.vertices[h.d].normal.copy(h.vertexNormals[3])}}c=0;for(d=this.vertices.length;c<d;c++){E.copy(this.vertices[c].normal);h=t[c];s.copy(h);s.subSelf(E.multiplyScalar(E.dot(h))).normalize();w.cross(this.vertices[c].normal,h);h=w.dot(q[c]);h=h<0?-1:1;this.vertices[c].tangent.set(s.x,s.y,s.z,h)}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],
  54. z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var c=1,d=this.vertices.length;c<d;c++){a=this.vertices[c];if(a.position.x<this.boundingBox.x[0])this.boundingBox.x[0]=a.position.x;else if(a.position.x>this.boundingBox.x[1])this.boundingBox.x[1]=a.position.x;if(a.position.y<this.boundingBox.y[0])this.boundingBox.y[0]=a.position.y;else if(a.position.y>this.boundingBox.y[1])this.boundingBox.y[1]=a.position.y;if(a.position.z<this.boundingBox.z[0])this.boundingBox.z[0]=a.position.z;else if(a.position.z>
  55. this.boundingBox.z[1])this.boundingBox.z[1]=a.position.z}}},computeBoundingSphere:function(){for(var a=this.boundingSphere===null?0:this.boundingSphere.radius,c=0,d=this.vertices.length;c<d;c++)a=Math.max(a,this.vertices[c].position.length());this.boundingSphere={radius:a}},sortFacesByMaterial:function(){function a(B){var A=[];c=0;for(d=B.length;c<d;c++)B[c]==undefined?A.push("undefined"):A.push(B[c].toString());return A.join("_")}var c,d,h,j,m,b,r,o,p={};h=0;for(j=this.faces.length;h<j;h++){m=this.faces[h];
  56. b=m.materials;r=a(b);if(p[r]==undefined)p[r]={hash:r,counter:0};o=p[r].hash+"_"+p[r].counter;if(this.geometryChunks[o]==undefined)this.geometryChunks[o]={faces:[],materials:b,vertices:0};m=m instanceof THREE.Face3?3:4;if(this.geometryChunks[o].vertices+m>65535){p[r].counter+=1;o=p[r].hash+"_"+p[r].counter;if(this.geometryChunks[o]==undefined)this.geometryChunks[o]={faces:[],materials:b,vertices:0}}this.geometryChunks[o].faces.push(h);this.geometryChunks[o].vertices+=m}},toString:function(){return"THREE.Geometry ( vertices: "+
  57. this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
  58. THREE.Camera=function(a,c,d,h){this.fov=a;this.aspect=c;this.near=d;this.far=h;this.position=new THREE.Vector3;this.target={position:new THREE.Vector3};this.autoUpdateMatrix=true;this.projectionMatrix=null;this.matrix=new THREE.Matrix4;this.up=new THREE.Vector3(0,1,0);this.tmpVec=new THREE.Vector3;this.translateX=function(j){this.tmpVec.sub(this.target.position,this.position).normalize().multiplyScalar(j);this.tmpVec.crossSelf(this.up);this.position.addSelf(this.tmpVec);this.target.position.addSelf(this.tmpVec)};
  59. this.translateZ=function(j){this.tmpVec.sub(this.target.position,this.position).normalize().multiplyScalar(j);this.position.subSelf(this.tmpVec);this.target.position.subSelf(this.tmpVec)};this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.updateProjectionMatrix=function(){this.projectionMatrix=THREE.Matrix4.makePerspective(this.fov,this.aspect,this.near,this.far)};this.updateProjectionMatrix()};
  60. THREE.Camera.prototype={toString:function(){return"THREE.Camera ( "+this.position+", "+this.target.position+" )"}};THREE.Light=function(a){this.color=new THREE.Color(a)};THREE.AmbientLight=function(a){THREE.Light.call(this,a)};THREE.AmbientLight.prototype=new THREE.Light;THREE.AmbientLight.prototype.constructor=THREE.AmbientLight;THREE.DirectionalLight=function(a,c){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,1,0);this.intensity=c||1};THREE.DirectionalLight.prototype=new THREE.Light;
  61. THREE.DirectionalLight.prototype.constructor=THREE.DirectionalLight;THREE.PointLight=function(a,c){THREE.Light.call(this,a);this.position=new THREE.Vector3;this.intensity=c||1};THREE.PointLight.prototype=new THREE.Light;THREE.PointLight.prototype.constructor=THREE.PointLight;
  62. THREE.Object3D=function(){this.id=THREE.Object3DCounter.value++;this.position=new THREE.Vector3;this.rotation=new THREE.Vector3;this.scale=new THREE.Vector3(1,1,1);this.matrix=new THREE.Matrix4;this.rotationMatrix=new THREE.Matrix4;this.tmpMatrix=new THREE.Matrix4;this.screen=new THREE.Vector3;this.visible=this.autoUpdateMatrix=true};
  63. THREE.Object3D.prototype={updateMatrix:function(){var a=this.position,c=this.rotation,d=this.scale,h=this.tmpMatrix;this.matrix.setTranslation(a.x,a.y,a.z);this.rotationMatrix.setRotX(c.x);if(c.y!=0){h.setRotY(c.y);this.rotationMatrix.multiplySelf(h)}if(c.z!=0){h.setRotZ(c.z);this.rotationMatrix.multiplySelf(h)}this.matrix.multiplySelf(this.rotationMatrix);if(d.x!=0||d.y!=0||d.z!=0){h.setScale(d.x,d.y,d.z);this.matrix.multiplySelf(h)}}};THREE.Object3DCounter={value:0};
  64. THREE.Particle=function(a){THREE.Object3D.call(this);this.materials=a instanceof Array?a:[a];this.autoUpdateMatrix=false};THREE.Particle.prototype=new THREE.Object3D;THREE.Particle.prototype.constructor=THREE.Particle;THREE.ParticleSystem=function(a,c){THREE.Object3D.call(this);this.geometry=a;this.materials=c instanceof Array?c:[c];this.sortParticles=false};THREE.ParticleSystem.prototype=new THREE.Object3D;THREE.ParticleSystem.prototype.constructor=THREE.ParticleSystem;
  65. THREE.Line=function(a,c,d){THREE.Object3D.call(this);this.geometry=a;this.materials=c instanceof Array?c:[c];this.type=d!=undefined?d:THREE.LineStrip};THREE.LineStrip=0;THREE.LinePieces=1;THREE.Line.prototype=new THREE.Object3D;THREE.Line.prototype.constructor=THREE.Line;THREE.Mesh=function(a,c){THREE.Object3D.call(this);this.geometry=a;this.materials=c instanceof Array?c:[c];this.overdraw=this.doubleSided=this.flipSided=false;this.geometry.boundingSphere||this.geometry.computeBoundingSphere()};
  66. THREE.Mesh.prototype=new THREE.Object3D;THREE.Mesh.prototype.constructor=THREE.Mesh;THREE.FlatShading=0;THREE.SmoothShading=1;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;THREE.BillboardBlending=3;
  67. THREE.LineBasicMaterial=function(a){this.id=THREE.LineBasicMaterialCounter.value++;this.color=new THREE.Color(16777215);this.opacity=1;this.blending=THREE.NormalBlending;this.depth_test=true;this.linewidth=1;this.linejoin=this.linecap="round";this.vertex_colors=false;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending;if(a.depth_test!==undefined)this.depth_test=a.depth_test;if(a.linewidth!==undefined)this.linewidth=
  68. a.linewidth;if(a.linecap!==undefined)this.linecap=a.linecap;if(a.linejoin!==undefined)this.linejoin=a.linejoin;if(a.vertex_colors!==undefined)this.vertex_colors=a.vertex_colors}};
  69. THREE.LineBasicMaterial.prototype={toString:function(){return"THREE.LineBasicMaterial (<br/>id: "+this.id+"<br/>color: "+this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>depth_test: "+this.depth_test+"<br/>linewidth: "+this.linewidth+"<br/>linecap: "+this.linecap+"<br/>linejoin: "+this.linejoin+"<br/>vertex_colors: "+this.vertex_colors+"<br/>)"}};THREE.LineBasicMaterialCounter={value:0};
  70. THREE.MeshBasicMaterial=function(a){this.id=THREE.MeshBasicMaterialCounter.value++;this.color=new THREE.Color(16777215);this.opacity=1;this.env_map=this.light_map=this.map=null;this.combine=THREE.MultiplyOperation;this.reflectivity=1;this.refraction_ratio=0.98;this.fog=true;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.depth_test=true;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=this.wireframe_linecap="round";this.vertex_colors=false;if(a){a.color!==
  71. undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.map!==undefined)this.map=a.map;if(a.light_map!==undefined)this.light_map=a.light_map;if(a.env_map!==undefined)this.env_map=a.env_map;if(a.combine!==undefined)this.combine=a.combine;if(a.reflectivity!==undefined)this.reflectivity=a.reflectivity;if(a.refraction_ratio!==undefined)this.refraction_ratio=a.refraction_ratio;if(a.fog!==undefined)this.fog=a.fog;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==
  72. undefined)this.blending=a.blending;if(a.depth_test!==undefined)this.depth_test=a.depth_test;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframe_linewidth!==undefined)this.wireframe_linewidth=a.wireframe_linewidth;if(a.wireframe_linecap!==undefined)this.wireframe_linecap=a.wireframe_linecap;if(a.wireframe_linejoin!==undefined)this.wireframe_linejoin=a.wireframe_linejoin;if(a.vertex_colors!==undefined)this.vertex_colors=a.vertex_colors}};
  73. THREE.MeshBasicMaterial.prototype={toString:function(){return"THREE.MeshBasicMaterial (<br/>id: "+this.id+"<br/>color: "+this.color+"<br/>opacity: "+this.opacity+"<br/>map: "+this.map+"<br/>light_map: "+this.light_map+"<br/>env_map: "+this.env_map+"<br/>combine: "+this.combine+"<br/>reflectivity: "+this.reflectivity+"<br/>refraction_ratio: "+this.refraction_ratio+"<br/>blending: "+this.blending+"<br/>depth_test: "+this.depth_test+"<br/>wireframe: "+this.wireframe+"<br/>wireframe_linewidth: "+this.wireframe_linewidth+
  74. "<br/>wireframe_linecap: "+this.wireframe_linecap+"<br/>wireframe_linejoin: "+this.wireframe_linejoin+"<br/>vertex_colors: "+this.vertex_colors+"<br/>)"}};THREE.MeshBasicMaterialCounter={value:0};
  75. THREE.MeshLambertMaterial=function(a){this.id=THREE.MeshLambertMaterialCounter.value++;this.color=new THREE.Color(16777215);this.opacity=1;this.env_map=this.light_map=this.map=null;this.combine=THREE.MultiplyOperation;this.reflectivity=1;this.refraction_ratio=0.98;this.fog=true;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.depth_test=true;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=this.wireframe_linecap="round";this.vertex_colors=false;if(a){a.color!==
  76. undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.map!==undefined)this.map=a.map;if(a.light_map!==undefined)this.light_map=a.light_map;if(a.env_map!==undefined)this.env_map=a.env_map;if(a.combine!==undefined)this.combine=a.combine;if(a.reflectivity!==undefined)this.reflectivity=a.reflectivity;if(a.refraction_ratio!==undefined)this.refraction_ratio=a.refraction_ratio;if(a.fog!==undefined)this.fog=a.fog;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==
  77. undefined)this.blending=a.blending;if(a.depth_test!==undefined)this.depth_test=a.depth_test;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframe_linewidth!==undefined)this.wireframe_linewidth=a.wireframe_linewidth;if(a.wireframe_linecap!==undefined)this.wireframe_linecap=a.wireframe_linecap;if(a.wireframe_linejoin!==undefined)this.wireframe_linejoin=a.wireframe_linejoin;if(a.vertex_colors!==undefined)this.vertex_colors=a.vertex_colors}};
  78. THREE.MeshLambertMaterial.prototype={toString:function(){return"THREE.MeshLambertMaterial (<br/>id: "+this.id+"<br/>color: "+this.color+"<br/>opacity: "+this.opacity+"<br/>map: "+this.map+"<br/>light_map: "+this.light_map+"<br/>env_map: "+this.env_map+"<br/>combine: "+this.combine+"<br/>reflectivity: "+this.reflectivity+"<br/>refraction_ratio: "+this.refraction_ratio+"<br/>shading: "+this.shading+"<br/>blending: "+this.blending+"<br/>depth_test: "+this.depth_test+"<br/>wireframe: "+this.wireframe+
  79. "<br/>wireframe_linewidth: "+this.wireframe_linewidth+"<br/>wireframe_linecap: "+this.wireframe_linecap+"<br/>wireframe_linejoin: "+this.wireframe_linejoin+"<br/>vertex_colors: "+this.vertex_colors+"<br/> )"}};THREE.MeshLambertMaterialCounter={value:0};
  80. THREE.MeshPhongMaterial=function(a){this.id=THREE.MeshPhongMaterialCounter.value++;this.color=new THREE.Color(16777215);this.ambient=new THREE.Color(328965);this.specular=new THREE.Color(1118481);this.shininess=30;this.opacity=1;this.env_map=this.light_map=this.map=null;this.combine=THREE.MultiplyOperation;this.reflectivity=1;this.refraction_ratio=0.98;this.fog=true;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.depth_test=true;this.wireframe=false;this.wireframe_linewidth=
  81. 1;this.wireframe_linejoin=this.wireframe_linecap="round";this.vertex_colors=false;if(a){if(a.color!==undefined)this.color=new THREE.Color(a.color);if(a.ambient!==undefined)this.ambient=new THREE.Color(a.ambient);if(a.specular!==undefined)this.specular=new THREE.Color(a.specular);if(a.shininess!==undefined)this.shininess=a.shininess;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.light_map!==undefined)this.light_map=a.light_map;if(a.map!==undefined)this.map=a.map;if(a.env_map!==undefined)this.env_map=
  82. a.env_map;if(a.combine!==undefined)this.combine=a.combine;if(a.reflectivity!==undefined)this.reflectivity=a.reflectivity;if(a.refraction_ratio!==undefined)this.refraction_ratio=a.refraction_ratio;if(a.fog!==undefined)this.fog=a.fog;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending;if(a.depth_test!==undefined)this.depth_test=a.depth_test;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframe_linewidth!==undefined)this.wireframe_linewidth=
  83. a.wireframe_linewidth;if(a.wireframe_linecap!==undefined)this.wireframe_linecap=a.wireframe_linecap;if(a.wireframe_linejoin!==undefined)this.wireframe_linejoin=a.wireframe_linejoin;if(a.vertex_colors!==undefined)this.vertex_colors=a.vertex_colors}};
  84. THREE.MeshPhongMaterial.prototype={toString:function(){return"THREE.MeshPhongMaterial (<br/>id: "+this.id+"<br/>color: "+this.color+"<br/>ambient: "+this.ambient+"<br/>specular: "+this.specular+"<br/>shininess: "+this.shininess+"<br/>opacity: "+this.opacity+"<br/>map: "+this.map+"<br/>env_map: "+this.env_map+"<br/>combine: "+this.combine+"<br/>reflectivity: "+this.reflectivity+"<br/>refraction_ratio: "+this.refraction_ratio+"<br/>shading: "+this.shading+"<br/>blending: "+this.blending+"<br/>depth_test: "+
  85. this.depth_test+"<br/>wireframe: "+this.wireframe+"<br/>wireframe_linewidth: "+this.wireframe_linewidth+"<br/>wireframe_linecap: "+this.wireframe_linecap+"<br/>wireframe_linejoin: "+this.wireframe_linejoin+"<br/>vertex_colors: "+this.vertex_colors+"<br/>)"}};THREE.MeshPhongMaterialCounter={value:0};
  86. THREE.MeshDepthMaterial=function(a){this.id=THREE.MeshDepthMaterialCounter.value++;this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.depth_test=true;this.wireframe=false;this.wireframe_linewidth=1;if(a){if(a.opacity!==undefined)this.opacity=a.opacity;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending;if(a.depth_test!==undefined)this.depth_test=a.depth_test;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframe_linewidth!==
  87. undefined)this.wireframe_linewidth=a.wireframe_linewidth}};THREE.MeshDepthMaterial.prototype={toString:function(){return"THREE.MeshDepthMaterial (<br/>id: "+this.id+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>depth_test: "+this.depth_test+"<br/>wireframe: "+this.wireframe+"<br/>wireframe_linewidth: "+this.wireframe_linewidth+"<br/>)"}};THREE.MeshDepthMaterialCounter={value:0};
  88. THREE.MeshNormalMaterial=function(a){this.id=THREE.MeshNormalMaterialCounter.value++;this.opacity=1;this.shading=THREE.FlatShading;this.blending=THREE.NormalBlending;this.depth_test=true;this.wireframe=false;this.wireframe_linewidth=1;if(a){if(a.opacity!==undefined)this.opacity=a.opacity;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending;if(a.depth_test!==undefined)this.depth_test=a.depth_test;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframe_linewidth!==
  89. undefined)this.wireframe_linewidth=a.wireframe_linewidth}};THREE.MeshNormalMaterial.prototype={toString:function(){return"THREE.MeshNormalMaterial (<br/>id: "+this.id+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>depth_test: "+this.depth_test+"<br/>wireframe: "+this.wireframe+"<br/>wireframe_linewidth: "+this.wireframe_linewidth+"<br/>)"}};THREE.MeshNormalMaterialCounter={value:0};THREE.MeshFaceMaterial=function(){};THREE.MeshFaceMaterial.prototype={toString:function(){return"THREE.MeshFaceMaterial"}};
  90. THREE.MeshShaderMaterial=function(a){this.id=THREE.MeshShaderMaterialCounter.value++;this.vertex_shader=this.fragment_shader="void main() {}";this.uniforms={};this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.depth_test=true;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=this.wireframe_linecap="round";this.vertex_colors=false;if(a){if(a.fragment_shader!==undefined)this.fragment_shader=a.fragment_shader;if(a.vertex_shader!==undefined)this.vertex_shader=
  91. a.vertex_shader;if(a.uniforms!==undefined)this.uniforms=a.uniforms;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending;if(a.depth_test!==undefined)this.depth_test=a.depth_test;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframe_linewidth!==undefined)this.wireframe_linewidth=a.wireframe_linewidth;if(a.wireframe_linecap!==undefined)this.wireframe_linecap=a.wireframe_linecap;if(a.wireframe_linejoin!==
  92. undefined)this.wireframe_linejoin=a.wireframe_linejoin;if(a.vertex_colors!==undefined)this.vertex_colors=a.vertex_colors}};
  93. THREE.MeshShaderMaterial.prototype={toString:function(){return"THREE.MeshShaderMaterial (<br/>id: "+this.id+"<br/>blending: "+this.blending+"<br/>depth_test: "+this.depth_test+"<br/>wireframe: "+this.wireframe+"<br/>wireframe_linewidth: "+this.wireframe_linewidth+"<br/>wireframe_linecap: "+this.wireframe_linecap+"<br/>wireframe_linejoin: "+this.wireframe_linejoin+"<br/>vertex_colors: "+this.vertex_colors+"<br/>)"}};THREE.MeshShaderMaterialCounter={value:0};
  94. THREE.ParticleBasicMaterial=function(a){this.id=THREE.ParticleBasicMaterialCounter.value++;this.color=new THREE.Color(16777215);this.opacity=1;this.map=null;this.size=1;this.blending=THREE.NormalBlending;this.depth_test=true;this.offset=new THREE.Vector2;this.vertex_colors=false;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.map!==undefined)this.map=a.map;if(a.size!==undefined)this.size=a.size;if(a.blending!==undefined)this.blending=a.blending;
  95. if(a.depth_test!==undefined)this.depth_test=a.depth_test;if(a.vertex_colors!==undefined)this.vertex_colors=a.vertex_colors}};THREE.ParticleBasicMaterial.prototype={toString:function(){return"THREE.ParticleBasicMaterial (<br/>id: "+this.id+"<br/>color: "+this.color+"<br/>opacity: "+this.opacity+"<br/>map: "+this.map+"<br/>size: "+this.size+"<br/>blending: "+this.blending+"<br/>depth_test: "+this.depth_test+"<br/>vertex_colors: "+this.vertex_colors+"<br/>)"}};THREE.ParticleBasicMaterialCounter={value:0};
  96. THREE.ParticleCircleMaterial=function(a){this.color=new THREE.Color(16777215);this.opacity=1;this.blending=THREE.NormalBlending;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}};THREE.ParticleCircleMaterial.prototype={toString:function(){return"THREE.ParticleCircleMaterial (<br/>color: "+this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>)"}};
  97. THREE.ParticleDOMMaterial=function(a){this.domElement=a};THREE.ParticleDOMMaterial.prototype={toString:function(){return"THREE.ParticleDOMMaterial ( domElement: "+this.domElement+" )"}};THREE.Texture=function(a,c,d,h,j,m){this.image=a;this.mapping=c!==undefined?c:new THREE.UVMapping;this.wrap_s=d!==undefined?d:THREE.ClampToEdgeWrapping;this.wrap_t=h!==undefined?h:THREE.ClampToEdgeWrapping;this.mag_filter=j!==undefined?j:THREE.LinearFilter;this.min_filter=m!==undefined?m:THREE.LinearMipMapLinearFilter};
  98. THREE.Texture.prototype={clone:function(){return new THREE.Texture(this.image,this.mapping,this.wrap_s,this.wrap_t,this.mag_filter,this.min_filter)},toString:function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>wrap_s: "+this.wrap_s+"<br/>wrap_t: "+this.wrap_t+"<br/>mag_filter: "+this.mag_filter+"<br/>min_filter: "+this.min_filter+"<br/>)"}};THREE.MultiplyOperation=0;THREE.MixOperation=1;THREE.RepeatWrapping=0;THREE.ClampToEdgeWrapping=1;THREE.MirroredRepeatWrapping=2;
  99. THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLinearFilter=5;THREE.LinearFilter=6;THREE.LinearMipMapNearestFilter=7;THREE.LinearMipMapLinearFilter=8;THREE.ByteType=9;THREE.UnsignedByteType=10;THREE.ShortType=11;THREE.UnsignedShortType=12;THREE.IntType=13;THREE.UnsignedIntType=14;THREE.FloatType=15;THREE.AlphaFormat=16;THREE.RGBFormat=17;THREE.RGBAFormat=18;THREE.LuminanceFormat=19;THREE.LuminanceAlphaFormat=20;
  100. THREE.RenderTarget=function(a,c,d){this.width=a;this.height=c;d=d||{};this.wrap_s=d.wrap_s!==undefined?d.wrap_s:THREE.ClampToEdgeWrapping;this.wrap_t=d.wrap_t!==undefined?d.wrap_t:THREE.ClampToEdgeWrapping;this.mag_filter=d.mag_filter!==undefined?d.mag_filter:THREE.LinearFilter;this.min_filter=d.min_filter!==undefined?d.min_filter:THREE.LinearMipMapLinearFilter;this.format=d.format!==undefined?d.format:THREE.RGBFormat;this.type=d.type!==undefined?d.type:THREE.UnsignedByteType};
  101. var Uniforms={clone:function(a){var c,d,h,j={};for(c in a){j[c]={};for(d in a[c]){h=a[c][d];j[c][d]=h instanceof THREE.Color||h instanceof THREE.Vector3||h instanceof THREE.Texture?h.clone():h}}return j},merge:function(a){var c,d,h,j={};for(c=0;c<a.length;c++){h=this.clone(a[c]);for(d in h)j[d]=h[d]}return j}};THREE.CubeReflectionMapping=function(){};THREE.CubeRefractionMapping=function(){};THREE.LatitudeReflectionMapping=function(){};THREE.LatitudeRefractionMapping=function(){};
  102. THREE.SphericalReflectionMapping=function(){};THREE.SphericalRefractionMapping=function(){};THREE.UVMapping=function(){};
  103. 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+" )"}};
  104. THREE.Fog=function(a,c,d){this.color=new THREE.Color(a);this.near=c||1;this.far=d||1E3};THREE.FogExp2=function(a,c){this.color=new THREE.Color(a);this.density=c||2.5E-4};
  105. THREE.Projector=function(){function a(q,n){return n.z-q.z}function c(q,n){var z=0,s=1,w=q.z+q.w,E=n.z+n.w,v=-q.z+q.w,D=-n.z+n.w;if(w>=0&&E>=0&&v>=0&&D>=0)return true;else if(w<0&&E<0||v<0&&D<0)return false;else{if(w<0)z=Math.max(z,w/(w-E));else if(E<0)s=Math.min(s,w/(w-E));if(v<0)z=Math.max(z,v/(v-D));else if(D<0)s=Math.min(s,v/(v-D));if(s<z)return false;else{q.lerpSelf(n,z);n.lerpSelf(q,1-s);return true}}}var d,h,j=[],m,b,r,o=[],p,B,A=[],u,y,H=[],L=new THREE.Vector4,e=new THREE.Vector4,g=new THREE.Matrix4,
  106. i=new THREE.Matrix4,f=[],k=new THREE.Vector4,l=new THREE.Vector4,t;this.projectObjects=function(q,n,z){var s=[],w,E;h=0;g.multiply(n.projectionMatrix,n.matrix);f[0]=new THREE.Vector4(g.n41-g.n11,g.n42-g.n12,g.n43-g.n13,g.n44-g.n14);f[1]=new THREE.Vector4(g.n41+g.n11,g.n42+g.n12,g.n43+g.n13,g.n44+g.n14);f[2]=new THREE.Vector4(g.n41+g.n21,g.n42+g.n22,g.n43+g.n23,g.n44+g.n24);f[3]=new THREE.Vector4(g.n41-g.n21,g.n42-g.n22,g.n43-g.n23,g.n44-g.n24);f[4]=new THREE.Vector4(g.n41-g.n31,g.n42-g.n32,g.n43-
  107. g.n33,g.n44-g.n34);f[5]=new THREE.Vector4(g.n41+g.n31,g.n42+g.n32,g.n43+g.n33,g.n44+g.n34);n=0;for(w=f.length;n<w;n++){E=f[n];E.divideScalar(Math.sqrt(E.x*E.x+E.y*E.y+E.z*E.z))}w=q.objects;q=0;for(n=w.length;q<n;q++){E=w[q];var v;if(!(v=!E.visible)){if(v=E instanceof THREE.Mesh){a:{v=void 0;for(var D=E.position,W=-E.geometry.boundingSphere.radius*Math.max(E.scale.x,Math.max(E.scale.y,E.scale.z)),J=0;J<6;J++){v=f[J].x*D.x+f[J].y*D.y+f[J].z*D.z+f[J].w;if(v<=W){v=false;break a}}v=true}v=!v}v=v}if(!v){d=
  108. j[h]=j[h]||new THREE.RenderableObject;L.copy(E.position);g.multiplyVector3(L);d.object=E;d.z=L.z;s.push(d);h++}}z&&s.sort(a);return s};this.projectScene=function(q,n,z){var s=[],w=n.near,E=n.far,v,D,W,J,Q,P,F,V,S,I,M,T,O,x,K,U;r=B=y=0;n.autoUpdateMatrix&&n.updateMatrix();g.multiply(n.projectionMatrix,n.matrix);P=this.projectObjects(q,n,true);q=0;for(v=P.length;q<v;q++){F=P[q].object;if(F.visible){F.autoUpdateMatrix&&F.updateMatrix();V=F.matrix;S=F.rotationMatrix;I=F.materials;M=F.overdraw;if(F instanceof
  109. THREE.Mesh){T=F.geometry;O=T.vertices;D=0;for(W=O.length;D<W;D++){x=O[D];x.positionWorld.copy(x.position);V.multiplyVector3(x.positionWorld);J=x.positionScreen;J.copy(x.positionWorld);g.multiplyVector4(J);J.x/=J.w;J.y/=J.w;x.__visible=J.z>w&&J.z<E}T=T.faces;D=0;for(W=T.length;D<W;D++){x=T[D];if(x instanceof THREE.Face3){J=O[x.a];Q=O[x.b];K=O[x.c];if(J.__visible&&Q.__visible&&K.__visible)if(F.doubleSided||F.flipSided!=(K.positionScreen.x-J.positionScreen.x)*(Q.positionScreen.y-J.positionScreen.y)-
  110. (K.positionScreen.y-J.positionScreen.y)*(Q.positionScreen.x-J.positionScreen.x)<0){m=o[r]=o[r]||new THREE.RenderableFace3;m.v1.positionWorld.copy(J.positionWorld);m.v2.positionWorld.copy(Q.positionWorld);m.v3.positionWorld.copy(K.positionWorld);m.v1.positionScreen.copy(J.positionScreen);m.v2.positionScreen.copy(Q.positionScreen);m.v3.positionScreen.copy(K.positionScreen);m.normalWorld.copy(x.normal);S.multiplyVector3(m.normalWorld);m.centroidWorld.copy(x.centroid);V.multiplyVector3(m.centroidWorld);
  111. m.centroidScreen.copy(m.centroidWorld);g.multiplyVector3(m.centroidScreen);K=x.vertexNormals;t=m.vertexNormalsWorld;J=0;for(Q=K.length;J<Q;J++){U=t[J]=t[J]||new THREE.Vector3;U.copy(K[J]);S.multiplyVector3(U)}m.z=m.centroidScreen.z;m.meshMaterials=I;m.faceMaterials=x.materials;m.overdraw=M;if(F.geometry.uvs[D]){m.uvs[0]=F.geometry.uvs[D][0];m.uvs[1]=F.geometry.uvs[D][1];m.uvs[2]=F.geometry.uvs[D][2]}s.push(m);r++}}else if(x instanceof THREE.Face4){J=O[x.a];Q=O[x.b];K=O[x.c];U=O[x.d];if(J.__visible&&
  112. Q.__visible&&K.__visible&&U.__visible)if(F.doubleSided||F.flipSided!=((U.positionScreen.x-J.positionScreen.x)*(Q.positionScreen.y-J.positionScreen.y)-(U.positionScreen.y-J.positionScreen.y)*(Q.positionScreen.x-J.positionScreen.x)<0||(Q.positionScreen.x-K.positionScreen.x)*(U.positionScreen.y-K.positionScreen.y)-(Q.positionScreen.y-K.positionScreen.y)*(U.positionScreen.x-K.positionScreen.x)<0)){m=o[r]=o[r]||new THREE.RenderableFace3;m.v1.positionWorld.copy(J.positionWorld);m.v2.positionWorld.copy(Q.positionWorld);
  113. m.v3.positionWorld.copy(U.positionWorld);m.v1.positionScreen.copy(J.positionScreen);m.v2.positionScreen.copy(Q.positionScreen);m.v3.positionScreen.copy(U.positionScreen);m.normalWorld.copy(x.normal);S.multiplyVector3(m.normalWorld);m.centroidWorld.copy(x.centroid);V.multiplyVector3(m.centroidWorld);m.centroidScreen.copy(m.centroidWorld);g.multiplyVector3(m.centroidScreen);m.z=m.centroidScreen.z;m.meshMaterials=I;m.faceMaterials=x.materials;m.overdraw=M;if(F.geometry.uvs[D]){m.uvs[0]=F.geometry.uvs[D][0];
  114. m.uvs[1]=F.geometry.uvs[D][1];m.uvs[2]=F.geometry.uvs[D][3]}s.push(m);r++;b=o[r]=o[r]||new THREE.RenderableFace3;b.v1.positionWorld.copy(Q.positionWorld);b.v2.positionWorld.copy(K.positionWorld);b.v3.positionWorld.copy(U.positionWorld);b.v1.positionScreen.copy(Q.positionScreen);b.v2.positionScreen.copy(K.positionScreen);b.v3.positionScreen.copy(U.positionScreen);b.normalWorld.copy(m.normalWorld);b.centroidWorld.copy(m.centroidWorld);b.centroidScreen.copy(m.centroidScreen);b.z=b.centroidScreen.z;b.meshMaterials=
  115. I;b.faceMaterials=x.materials;b.overdraw=M;if(F.geometry.uvs[D]){b.uvs[0]=F.geometry.uvs[D][1];b.uvs[1]=F.geometry.uvs[D][2];b.uvs[2]=F.geometry.uvs[D][3]}s.push(b);r++}}}}else if(F instanceof THREE.Line){i.multiply(g,V);O=F.geometry.vertices;x=O[0];x.positionScreen.copy(x.position);i.multiplyVector4(x.positionScreen);D=1;for(W=O.length;D<W;D++){J=O[D];J.positionScreen.copy(J.position);i.multiplyVector4(J.positionScreen);Q=O[D-1];k.copy(J.positionScreen);l.copy(Q.positionScreen);if(c(k,l)){k.multiplyScalar(1/
  116. k.w);l.multiplyScalar(1/l.w);p=A[B]=A[B]||new THREE.RenderableLine;p.v1.positionScreen.copy(k);p.v2.positionScreen.copy(l);p.z=Math.max(k.z,l.z);p.materials=F.materials;s.push(p);B++}}}else if(F instanceof THREE.Particle){e.set(F.position.x,F.position.y,F.position.z,1);g.multiplyVector4(e);e.z/=e.w;if(e.z>0&&e.z<1){u=H[y]=H[y]||new THREE.RenderableParticle;u.x=e.x/e.w;u.y=e.y/e.w;u.z=e.z;u.rotation=F.rotation.z;u.scale.x=F.scale.x*Math.abs(u.x-(e.x+n.projectionMatrix.n11)/(e.w+n.projectionMatrix.n14));
  117. u.scale.y=F.scale.y*Math.abs(u.y-(e.y+n.projectionMatrix.n22)/(e.w+n.projectionMatrix.n24));u.materials=F.materials;s.push(u);y++}}}}z&&s.sort(a);return s};this.unprojectVector=function(q,n){var z=THREE.Matrix4.makeInvert(n.matrix);z.multiplySelf(THREE.Matrix4.makeInvert(n.projectionMatrix));z.multiplyVector3(q);return q}};
  118. THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,c=new THREE.Projector,d,h,j,m;this.domElement=document.createElement("div");this.setSize=function(b,r){d=b;h=r;j=d/2;m=h/2};this.render=function(b,r){var o,p,B,A,u,y,H,L;a=c.projectScene(b,r);o=0;for(p=a.length;o<p;o++){u=a[o];if(u instanceof THREE.RenderableParticle){H=u.x*j+j;L=u.y*m+m;B=0;for(A=u.material.length;B<A;B++){y=u.material[B];if(y instanceof THREE.ParticleDOMMaterial){y=y.domElement;y.style.left=H+"px";y.style.top=L+"px"}}}}}};
  119. THREE.CanvasRenderer=function(){function a(ba){if(u!=ba)p.globalAlpha=u=ba}function c(ba){if(y!=ba){switch(ba){case THREE.NormalBlending:p.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:p.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:p.globalCompositeOperation="darker"}y=ba}}var d=null,h=new THREE.Projector,j=document.createElement("canvas"),m,b,r,o,p=j.getContext("2d"),B=new THREE.Color(0),A=0,u=1,y=0,H=null,L=null,e=1,g,i,f,k,l,t,q,n,z,s=new THREE.Color,
  120. w=new THREE.Color,E=new THREE.Color,v=new THREE.Color,D=new THREE.Color,W,J,Q,P,F,V,S,I,M,T=new THREE.Rectangle,O=new THREE.Rectangle,x=new THREE.Rectangle,K=false,U=new THREE.Color,Z=new THREE.Color,ma=new THREE.Color,ca=new THREE.Color,xa=Math.PI*2,$=new THREE.Vector3,ia,pa,ua,fa,da,va,ta=16;ia=document.createElement("canvas");ia.width=ia.height=2;pa=ia.getContext("2d");pa.fillStyle="rgba(0,0,0,1)";pa.fillRect(0,0,2,2);ua=pa.getImageData(0,0,2,2);fa=ua.data;da=document.createElement("canvas");da.width=
  121. da.height=ta;va=da.getContext("2d");va.translate(-ta/2,-ta/2);va.scale(ta,ta);ta--;this.domElement=j;this.sortElements=this.sortObjects=this.autoClear=true;this.setSize=function(ba,ja){m=ba;b=ja;r=m/2;o=b/2;j.width=m;j.height=b;T.set(-r,-o,r,o);u=1;y=0;L=H=null;e=1};this.setClearColor=function(ba,ja){B=ba;A=ja;O.set(-r,-o,r,o);p.setTransform(1,0,0,-1,r,o);this.clear()};this.setClearColorHex=function(ba,ja){B.setHex(ba);A=ja;O.set(-r,-o,r,o);p.setTransform(1,0,0,-1,r,o);this.clear()};this.clear=function(){p.setTransform(1,
  122. 0,0,-1,r,o);if(!O.isEmpty()){O.inflate(1);O.minSelf(T);if(B.hex==0&&A==0)p.clearRect(O.getX(),O.getY(),O.getWidth(),O.getHeight());else{c(THREE.NormalBlending);a(1);p.fillStyle="rgba("+Math.floor(B.r*255)+","+Math.floor(B.g*255)+","+Math.floor(B.b*255)+","+A+")";p.fillRect(O.getX(),O.getY(),O.getWidth(),O.getHeight())}O.empty()}};this.render=function(ba,ja){function la(C){var X,R,G,N=C.lights;Z.setRGB(0,0,0);ma.setRGB(0,0,0);ca.setRGB(0,0,0);C=0;for(X=N.length;C<X;C++){R=N[C];G=R.color;if(R instanceof
  123. THREE.AmbientLight){Z.r+=G.r;Z.g+=G.g;Z.b+=G.b}else if(R instanceof THREE.DirectionalLight){ma.r+=G.r;ma.g+=G.g;ma.b+=G.b}else if(R instanceof THREE.PointLight){ca.r+=G.r;ca.g+=G.g;ca.b+=G.b}}}function Ba(C,X,R,G){var N,Y,ea,ga,ha=C.lights;C=0;for(N=ha.length;C<N;C++){Y=ha[C];ea=Y.color;ga=Y.intensity;if(Y instanceof THREE.DirectionalLight){Y=R.dot(Y.position)*ga;if(Y>0){G.r+=ea.r*Y;G.g+=ea.g*Y;G.b+=ea.b*Y}}else if(Y instanceof THREE.PointLight){$.sub(Y.position,X);$.normalize();Y=R.dot($)*ga;if(Y>
  124. 0){G.r+=ea.r*Y;G.g+=ea.g*Y;G.b+=ea.b*Y}}}}function Na(C,X,R){if(R.opacity!=0){a(R.opacity);c(R.blending);var G,N,Y,ea,ga,ha;if(R instanceof THREE.ParticleBasicMaterial){if(R.map&&R.map.image.loaded){ea=R.map.image;ga=ea.width>>1;ha=ea.height>>1;N=X.scale.x*r;Y=X.scale.y*o;R=N*ga;G=Y*ha;x.set(C.x-R,C.y-G,C.x+R,C.y+G);if(!T.instersects(x))return;p.save();p.translate(C.x,C.y);p.rotate(-X.rotation);p.scale(N,-Y);p.translate(-ga,-ha);p.drawImage(ea,0,0);p.restore()}p.beginPath();p.moveTo(C.x-10,C.y);p.lineTo(C.x+
  125. 10,C.y);p.moveTo(C.x,C.y-10);p.lineTo(C.x,C.y+10);p.closePath();p.strokeStyle="rgb(255,255,0)";p.stroke()}else if(R instanceof THREE.ParticleCircleMaterial){if(K){U.r=Z.r+ma.r+ca.r;U.g=Z.g+ma.g+ca.g;U.b=Z.b+ma.b+ca.b;s.r=R.color.r*U.r;s.g=R.color.g*U.g;s.b=R.color.b*U.b;s.updateStyleString()}else s.__styleString=R.color.__styleString;R=X.scale.x*r;G=X.scale.y*o;x.set(C.x-R,C.y-G,C.x+R,C.y+G);if(T.instersects(x)){N=s.__styleString;if(L!=N)p.fillStyle=L=N;p.save();p.translate(C.x,C.y);p.rotate(-X.rotation);
  126. p.scale(R,G);p.beginPath();p.arc(0,0,1,0,xa,true);p.closePath();p.fill();p.restore()}}}}function Oa(C,X,R,G){if(G.opacity!=0){a(G.opacity);c(G.blending);p.beginPath();p.moveTo(C.positionScreen.x,C.positionScreen.y);p.lineTo(X.positionScreen.x,X.positionScreen.y);p.closePath();if(G instanceof THREE.LineBasicMaterial){s.__styleString=G.color.__styleString;C=G.linewidth;if(e!=C)p.lineWidth=e=C;C=s.__styleString;if(H!=C)p.strokeStyle=H=C;p.stroke();x.inflate(G.linewidth*2)}}}function Ja(C,X,R,G,N,Y){if(N.opacity!=
  127. 0){a(N.opacity);c(N.blending);k=C.positionScreen.x;l=C.positionScreen.y;t=X.positionScreen.x;q=X.positionScreen.y;n=R.positionScreen.x;z=R.positionScreen.y;p.beginPath();p.moveTo(k,l);p.lineTo(t,q);p.lineTo(n,z);p.lineTo(k,l);p.closePath();if(N instanceof THREE.MeshBasicMaterial)if(N.map)N.map.image.loaded&&N.map.mapping instanceof THREE.UVMapping&&ya(k,l,t,q,n,z,N.map.image,G.uvs[0].u,G.uvs[0].v,G.uvs[1].u,G.uvs[1].v,G.uvs[2].u,G.uvs[2].v);else if(N.env_map){if(N.env_map.image.loaded)if(N.env_map.mapping instanceof
  128. THREE.SphericalReflectionMapping){C=ja.matrix;$.copy(G.vertexNormalsWorld[0]);P=($.x*C.n11+$.y*C.n12+$.z*C.n13)*0.5+0.5;F=-($.x*C.n21+$.y*C.n22+$.z*C.n23)*0.5+0.5;$.copy(G.vertexNormalsWorld[1]);V=($.x*C.n11+$.y*C.n12+$.z*C.n13)*0.5+0.5;S=-($.x*C.n21+$.y*C.n22+$.z*C.n23)*0.5+0.5;$.copy(G.vertexNormalsWorld[2]);I=($.x*C.n11+$.y*C.n12+$.z*C.n13)*0.5+0.5;M=-($.x*C.n21+$.y*C.n22+$.z*C.n23)*0.5+0.5;ya(k,l,t,q,n,z,N.env_map.image,P,F,V,S,I,M)}}else N.wireframe?Ca(N.color.__styleString,N.wireframe_linewidth):
  129. Da(N.color.__styleString);else if(N instanceof THREE.MeshLambertMaterial){if(N.map&&!N.wireframe){N.map.mapping instanceof THREE.UVMapping&&ya(k,l,t,q,n,z,N.map.image,G.uvs[0].u,G.uvs[0].v,G.uvs[1].u,G.uvs[1].v,G.uvs[2].u,G.uvs[2].v);c(THREE.SubtractiveBlending)}if(K)if(!N.wireframe&&N.shading==THREE.SmoothShading&&G.vertexNormalsWorld.length==3){w.r=E.r=v.r=Z.r;w.g=E.g=v.g=Z.g;w.b=E.b=v.b=Z.b;Ba(Y,G.v1.positionWorld,G.vertexNormalsWorld[0],w);Ba(Y,G.v2.positionWorld,G.vertexNormalsWorld[1],E);Ba(Y,
  130. G.v3.positionWorld,G.vertexNormalsWorld[2],v);D.r=(E.r+v.r)*0.5;D.g=(E.g+v.g)*0.5;D.b=(E.b+v.b)*0.5;Q=Ka(w,E,v,D);ya(k,l,t,q,n,z,Q,0,0,1,0,0,1)}else{U.r=Z.r;U.g=Z.g;U.b=Z.b;Ba(Y,G.centroidWorld,G.normalWorld,U);s.r=N.color.r*U.r;s.g=N.color.g*U.g;s.b=N.color.b*U.b;s.updateStyleString();N.wireframe?Ca(s.__styleString,N.wireframe_linewidth):Da(s.__styleString)}else N.wireframe?Ca(N.color.__styleString,N.wireframe_linewidth):Da(N.color.__styleString)}else if(N instanceof THREE.MeshDepthMaterial){W=ja.near;
  131. J=ja.far;w.r=w.g=w.b=1-Fa(C.positionScreen.z,W,J);E.r=E.g=E.b=1-Fa(X.positionScreen.z,W,J);v.r=v.g=v.b=1-Fa(R.positionScreen.z,W,J);D.r=(E.r+v.r)*0.5;D.g=(E.g+v.g)*0.5;D.b=(E.b+v.b)*0.5;Q=Ka(w,E,v,D);ya(k,l,t,q,n,z,Q,0,0,1,0,0,1)}else if(N instanceof THREE.MeshNormalMaterial){s.r=Ga(G.normalWorld.x);s.g=Ga(G.normalWorld.y);s.b=Ga(G.normalWorld.z);s.updateStyleString();N.wireframe?Ca(s.__styleString,N.wireframe_linewidth):Da(s.__styleString)}}}function Ca(C,X){if(H!=C)p.strokeStyle=H=C;if(e!=X)p.lineWidth=
  132. e=X;p.stroke();x.inflate(X*2)}function Da(C){if(L!=C)p.fillStyle=L=C;p.fill()}function ya(C,X,R,G,N,Y,ea,ga,ha,qa,ka,ra,za){var na,sa;na=ea.width-1;sa=ea.height-1;ga*=na;ha*=sa;qa*=na;ka*=sa;ra*=na;za*=sa;R-=C;G-=X;N-=C;Y-=X;qa-=ga;ka-=ha;ra-=ga;za-=ha;na=qa*za-ra*ka;if(na!=0){sa=1/na;na=(za*R-ka*N)*sa;ka=(za*G-ka*Y)*sa;R=(qa*N-ra*R)*sa;G=(qa*Y-ra*G)*sa;C=C-na*ga-R*ha;X=X-ka*ga-G*ha;p.save();p.transform(na,ka,R,G,C,X);p.clip();p.drawImage(ea,0,0);p.restore()}}function Ka(C,X,R,G){var N=~~(C.r*255),
  133. Y=~~(C.g*255);C=~~(C.b*255);var ea=~~(X.r*255),ga=~~(X.g*255);X=~~(X.b*255);var ha=~~(R.r*255),qa=~~(R.g*255);R=~~(R.b*255);var ka=~~(G.r*255),ra=~~(G.g*255);G=~~(G.b*255);fa[0]=N<0?0:N>255?255:N;fa[1]=Y<0?0:Y>255?255:Y;fa[2]=C<0?0:C>255?255:C;fa[4]=ea<0?0:ea>255?255:ea;fa[5]=ga<0?0:ga>255?255:ga;fa[6]=X<0?0:X>255?255:X;fa[8]=ha<0?0:ha>255?255:ha;fa[9]=qa<0?0:qa>255?255:qa;fa[10]=R<0?0:R>255?255:R;fa[12]=ka<0?0:ka>255?255:ka;fa[13]=ra<0?0:ra>255?255:ra;fa[14]=G<0?0:G>255?255:G;pa.putImageData(ua,
  134. 0,0);va.drawImage(ia,0,0);return da}function Fa(C,X,R){C=(C-X)/(R-X);return C*C*(3-2*C)}function Ga(C){C=(C+1)*0.5;return C<0?0:C>1?1:C}function Ha(C,X){var R=X.x-C.x,G=X.y-C.y,N=1/Math.sqrt(R*R+G*G);R*=N;G*=N;X.x+=R;X.y+=G;C.x-=R;C.y-=G}var Ea,La,aa,oa,wa,Ia,Ma,Aa;this.autoClear?this.clear():p.setTransform(1,0,0,-1,r,o);d=h.projectScene(ba,ja,this.sortElements);p.fillStyle="rgba( 0, 255, 255, 0.5 )";p.fillRect(T.getX(),T.getY(),T.getWidth(),T.getHeight());(K=ba.lights.length>0)&&la(ba);Ea=0;for(La=
  135. d.length;Ea<La;Ea++){aa=d[Ea];x.empty();if(aa instanceof THREE.RenderableParticle){g=aa;g.x*=r;g.y*=o;oa=0;for(wa=aa.materials.length;oa<wa;oa++)Na(g,aa,aa.materials[oa],ba)}else if(aa instanceof THREE.RenderableLine){g=aa.v1;i=aa.v2;g.positionScreen.x*=r;g.positionScreen.y*=o;i.positionScreen.x*=r;i.positionScreen.y*=o;x.addPoint(g.positionScreen.x,g.positionScreen.y);x.addPoint(i.positionScreen.x,i.positionScreen.y);if(T.instersects(x)){oa=0;for(wa=aa.materials.length;oa<wa;)Oa(g,i,aa,aa.materials[oa++],
  136. ba)}}else if(aa instanceof THREE.RenderableFace3){g=aa.v1;i=aa.v2;f=aa.v3;g.positionScreen.x*=r;g.positionScreen.y*=o;i.positionScreen.x*=r;i.positionScreen.y*=o;f.positionScreen.x*=r;f.positionScreen.y*=o;if(aa.overdraw){Ha(g.positionScreen,i.positionScreen);Ha(i.positionScreen,f.positionScreen);Ha(f.positionScreen,g.positionScreen)}x.add3Points(g.positionScreen.x,g.positionScreen.y,i.positionScreen.x,i.positionScreen.y,f.positionScreen.x,f.positionScreen.y);if(T.instersects(x)){oa=0;for(wa=aa.meshMaterials.length;oa<
  137. wa;){Aa=aa.meshMaterials[oa++];if(Aa instanceof THREE.MeshFaceMaterial){Ia=0;for(Ma=aa.faceMaterials.length;Ia<Ma;)(Aa=aa.faceMaterials[Ia++])&&Ja(g,i,f,aa,Aa,ba)}else Ja(g,i,f,aa,Aa,ba)}}}O.addRectangle(x)}p.lineWidth=1;p.strokeStyle="rgba( 255, 0, 0, 0.5 )";p.strokeRect(O.getX(),O.getY(),O.getWidth(),O.getHeight());p.setTransform(1,0,0,1,0,0)}};
  138. THREE.SVGRenderer=function(){function a(P,F,V){var S,I,M,T;S=0;for(I=P.lights.length;S<I;S++){M=P.lights[S];if(M instanceof THREE.DirectionalLight){T=F.normalWorld.dot(M.position)*M.intensity;if(T>0){V.r+=M.color.r*T;V.g+=M.color.g*T;V.b+=M.color.b*T}}else if(M instanceof THREE.PointLight){z.sub(M.position,F.centroidWorld);z.normalize();T=F.normalWorld.dot(z)*M.intensity;if(T>0){V.r+=M.color.r*T;V.g+=M.color.g*T;V.b+=M.color.b*T}}}}function c(P,F,V,S,I,M){v=h(D++);v.setAttribute("d","M "+P.positionScreen.x+
  139. " "+P.positionScreen.y+" L "+F.positionScreen.x+" "+F.positionScreen.y+" L "+V.positionScreen.x+","+V.positionScreen.y+"z");if(I instanceof THREE.MeshBasicMaterial)f.__styleString=I.color.__styleString;else if(I instanceof THREE.MeshLambertMaterial)if(i){k.r=l.r;k.g=l.g;k.b=l.b;a(M,S,k);f.r=I.color.r*k.r;f.g=I.color.g*k.g;f.b=I.color.b*k.b;f.updateStyleString()}else f.__styleString=I.color.__styleString;else if(I instanceof THREE.MeshDepthMaterial){n=1-I.__2near/(I.__farPlusNear-S.z*I.__farMinusNear);
  140. f.setRGB(n,n,n)}else I instanceof THREE.MeshNormalMaterial&&f.setRGB(j(S.normalWorld.x),j(S.normalWorld.y),j(S.normalWorld.z));I.wireframe?v.setAttribute("style","fill: none; stroke: "+f.__styleString+"; stroke-width: "+I.wireframe_linewidth+"; stroke-opacity: "+I.opacity+"; stroke-linecap: "+I.wireframe_linecap+"; stroke-linejoin: "+I.wireframe_linejoin):v.setAttribute("style","fill: "+f.__styleString+"; fill-opacity: "+I.opacity);r.appendChild(v)}function d(P,F,V,S,I,M,T){v=h(D++);v.setAttribute("d",
  141. "M "+P.positionScreen.x+" "+P.positionScreen.y+" L "+F.positionScreen.x+" "+F.positionScreen.y+" L "+V.positionScreen.x+","+V.positionScreen.y+" L "+S.positionScreen.x+","+S.positionScreen.y+"z");if(M instanceof THREE.MeshBasicMaterial)f.__styleString=M.color.__styleString;else if(M instanceof THREE.MeshLambertMaterial)if(i){k.r=l.r;k.g=l.g;k.b=l.b;a(T,I,k);f.r=M.color.r*k.r;f.g=M.color.g*k.g;f.b=M.color.b*k.b;f.updateStyleString()}else f.__styleString=M.color.__styleString;else if(M instanceof THREE.MeshDepthMaterial){n=
  142. 1-M.__2near/(M.__farPlusNear-I.z*M.__farMinusNear);f.setRGB(n,n,n)}else M instanceof THREE.MeshNormalMaterial&&f.setRGB(j(I.normalWorld.x),j(I.normalWorld.y),j(I.normalWorld.z));M.wireframe?v.setAttribute("style","fill: none; stroke: "+f.__styleString+"; stroke-width: "+M.wireframe_linewidth+"; stroke-opacity: "+M.opacity+"; stroke-linecap: "+M.wireframe_linecap+"; stroke-linejoin: "+M.wireframe_linejoin):v.setAttribute("style","fill: "+f.__styleString+"; fill-opacity: "+M.opacity);r.appendChild(v)}
  143. function h(P){if(s[P]==null){s[P]=document.createElementNS("http://www.w3.org/2000/svg","path");Q==0&&s[P].setAttribute("shape-rendering","crispEdges");return s[P]}return s[P]}function j(P){return P<0?Math.min((1+P)*0.5,0.5):0.5+Math.min(P*0.5,0.5)}var m=null,b=new THREE.Projector,r=document.createElementNS("http://www.w3.org/2000/svg","svg"),o,p,B,A,u,y,H,L,e=new THREE.Rectangle,g=new THREE.Rectangle,i=false,f=new THREE.Color(16777215),k=new THREE.Color(16777215),l=new THREE.Color(0),t=new THREE.Color(0),
  144. q=new THREE.Color(0),n,z=new THREE.Vector3,s=[],w=[],E=[],v,D,W,J,Q=1;this.domElement=r;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(P){switch(P){case "high":Q=1;break;case "low":Q=0}};this.setSize=function(P,F){o=P;p=F;B=o/2;A=p/2;r.setAttribute("viewBox",-B+" "+-A+" "+o+" "+p);r.setAttribute("width",o);r.setAttribute("height",p);e.set(-B,-A,B,A)};this.clear=function(){for(;r.childNodes.length>0;)r.removeChild(r.childNodes[0])};this.render=function(P,F){var V,S,
  145. I,M,T,O,x,K;this.autoClear&&this.clear();m=b.projectScene(P,F,this.sortElements);J=W=D=0;if(i=P.lights.length>0){x=P.lights;l.setRGB(0,0,0);t.setRGB(0,0,0);q.setRGB(0,0,0);V=0;for(S=x.length;V<S;V++){I=x[V];M=I.color;if(I instanceof THREE.AmbientLight){l.r+=M.r;l.g+=M.g;l.b+=M.b}else if(I instanceof THREE.DirectionalLight){t.r+=M.r;t.g+=M.g;t.b+=M.b}else if(I instanceof THREE.PointLight){q.r+=M.r;q.g+=M.g;q.b+=M.b}}}V=0;for(S=m.length;V<S;V++){x=m[V];g.empty();if(x instanceof THREE.RenderableParticle){u=
  146. x;u.x*=B;u.y*=-A;I=0;for(M=x.materials.length;I<M;I++)if(K=x.materials[I]){T=u;O=x;K=K;var U=W++;if(w[U]==null){w[U]=document.createElementNS("http://www.w3.org/2000/svg","circle");Q==0&&w[U].setAttribute("shape-rendering","crispEdges")}v=w[U];v.setAttribute("cx",T.x);v.setAttribute("cy",T.y);v.setAttribute("r",O.scale.x*B);if(K instanceof THREE.ParticleCircleMaterial){if(i){k.r=l.r+t.r+q.r;k.g=l.g+t.g+q.g;k.b=l.b+t.b+q.b;f.r=K.color.r*k.r;f.g=K.color.g*k.g;f.b=K.color.b*k.b;f.updateStyleString()}else f=
  147. K.color;v.setAttribute("style","fill: "+f.__styleString)}r.appendChild(v)}}else if(x instanceof THREE.RenderableLine){u=x.v1;y=x.v2;u.positionScreen.x*=B;u.positionScreen.y*=-A;y.positionScreen.x*=B;y.positionScreen.y*=-A;g.addPoint(u.positionScreen.x,u.positionScreen.y);g.addPoint(y.positionScreen.x,y.positionScreen.y);if(e.instersects(g)){I=0;for(M=x.materials.length;I<M;)if(K=x.materials[I++]){T=u;O=y;K=K;U=J++;if(E[U]==null){E[U]=document.createElementNS("http://www.w3.org/2000/svg","line");Q==
  148. 0&&E[U].setAttribute("shape-rendering","crispEdges")}v=E[U];v.setAttribute("x1",T.positionScreen.x);v.setAttribute("y1",T.positionScreen.y);v.setAttribute("x2",O.positionScreen.x);v.setAttribute("y2",O.positionScreen.y);if(K instanceof THREE.LineBasicMaterial){f.__styleString=K.color.__styleString;v.setAttribute("style","fill: none; stroke: "+f.__styleString+"; stroke-width: "+K.linewidth+"; stroke-opacity: "+K.opacity+"; stroke-linecap: "+K.linecap+"; stroke-linejoin: "+K.linejoin);r.appendChild(v)}}}}else if(x instanceof
  149. THREE.RenderableFace3){u=x.v1;y=x.v2;H=x.v3;u.positionScreen.x*=B;u.positionScreen.y*=-A;y.positionScreen.x*=B;y.positionScreen.y*=-A;H.positionScreen.x*=B;H.positionScreen.y*=-A;g.addPoint(u.positionScreen.x,u.positionScreen.y);g.addPoint(y.positionScreen.x,y.positionScreen.y);g.addPoint(H.positionScreen.x,H.positionScreen.y);if(e.instersects(g)){I=0;for(M=x.meshMaterials.length;I<M;){K=x.meshMaterials[I++];if(K instanceof THREE.MeshFaceMaterial){T=0;for(O=x.faceMaterials.length;T<O;)(K=x.faceMaterials[T++])&&
  150. c(u,y,H,x,K,P)}else K&&c(u,y,H,x,K,P)}}}else if(x instanceof THREE.RenderableFace4){u=x.v1;y=x.v2;H=x.v3;L=x.v4;u.positionScreen.x*=B;u.positionScreen.y*=-A;y.positionScreen.x*=B;y.positionScreen.y*=-A;H.positionScreen.x*=B;H.positionScreen.y*=-A;L.positionScreen.x*=B;L.positionScreen.y*=-A;g.addPoint(u.positionScreen.x,u.positionScreen.y);g.addPoint(y.positionScreen.x,y.positionScreen.y);g.addPoint(H.positionScreen.x,H.positionScreen.y);g.addPoint(L.positionScreen.x,L.positionScreen.y);if(e.instersects(g)){I=
  151. 0;for(M=x.meshMaterials.length;I<M;){K=x.meshMaterials[I++];if(K instanceof THREE.MeshFaceMaterial){T=0;for(O=x.faceMaterials.length;T<O;)(K=x.faceMaterials[T++])&&d(u,y,H,L,x,K,P)}else K&&d(u,y,H,L,x,K,P)}}}}}};
  152. THREE.WebGLRenderer=function(a){function c(e,g){e.fragment_shader=g.fragment_shader;e.vertex_shader=g.vertex_shader;e.uniforms=Uniforms.clone(g.uniforms)}function d(e){if(e.doubleSided)b.disable(b.CULL_FACE);else{b.enable(b.CULL_FACE);e.flipSided?b.frontFace(b.CW):b.frontFace(b.CCW)}}function h(e,g){var i;if(e=="fragment")i=b.createShader(b.FRAGMENT_SHADER);else if(e=="vertex")i=b.createShader(b.VERTEX_SHADER);b.shaderSource(i,g);b.compileShader(i);if(!b.getShaderParameter(i,b.COMPILE_STATUS)){alert(b.getShaderInfoLog(i));
  153. return null}return i}function j(e){switch(e){case THREE.RepeatWrapping:return b.REPEAT;case THREE.ClampToEdgeWrapping:return b.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return b.MIRRORED_REPEAT;case THREE.NearestFilter:return b.NEAREST;case THREE.NearestMipMapNearestFilter:return b.NEAREST_MIPMAP_NEAREST;case THREE.NearestMipMapLinearFilter:return b.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return b.LINEAR;case THREE.LinearMipMapNearestFilter:return b.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return b.LINEAR_MIPMAP_LINEAR;
  154. case THREE.ByteType:return b.BYTE;case THREE.UnsignedByteType:return b.UNSIGNED_BYTE;case THREE.ShortType:return b.SHORT;case THREE.UnsignedShortType:return b.UNSIGNED_SHORT;case THREE.IntType:return b.INT;case THREE.UnsignedShortType:return b.UNSIGNED_INT;case THREE.FloatType:return b.FLOAT;case THREE.AlphaFormat:return b.ALPHA;case THREE.RGBFormat:return b.RGB;case THREE.RGBAFormat:return b.RGBA;case THREE.LuminanceFormat:return b.LUMINANCE;case THREE.LuminanceAlphaFormat:return b.LUMINANCE_ALPHA}return 0}
  155. var m=document.createElement("canvas"),b,r=null,o=null,p=new THREE.Matrix4,B=new Float32Array(16),A=new Float32Array(16),u=new THREE.Vector4,y=true,H=new THREE.Color(0),L=0;if(a){if(a.antialias!==undefined)y=a.antialias;a.clearColor!==undefined&&H.setHex(a.clearColor);if(a.clearAlpha!==undefined)L=a.clearAlpha}this.domElement=m;this.autoClear=true;(function(e,g,i){try{b=m.getContext("experimental-webgl",{antialias:e})}catch(f){console.log(f)}if(!b){alert("WebGL not supported");throw"cannot create webgl context";
  156. }b.clearColor(0,0,0,1);b.clearDepth(1);b.enable(b.DEPTH_TEST);b.depthFunc(b.LEQUAL);b.frontFace(b.CCW);b.cullFace(b.BACK);b.enable(b.CULL_FACE);b.enable(b.BLEND);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA);b.clearColor(g.r,g.g,g.b,i)})(y,H,L);this.context=b;this.lights={ambient:[0,0,0],directional:{length:0,colors:[],positions:[]},point:{length:0,colors:[],positions:[]}};this.setSize=function(e,g){m.width=e;m.height=g;b.viewport(0,0,m.width,m.height)};this.setClearColorHex=function(e,g){var i=new THREE.Color(e);
  157. b.clearColor(i.r,i.g,i.b,g)};this.setClearColor=function(e,g){b.clearColor(e.r,e.g,e.b,g)};this.clear=function(){b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT)};this.setupLights=function(e,g){var i,f,k,l=0,t=0,q=0,n,z,s,w=this.lights,E=w.directional.colors,v=w.directional.positions,D=w.point.colors,W=w.point.positions,J=0,Q=0;i=k=k=0;for(f=g.length;i<f;i++){k=g[i];n=k.color;z=k.position;s=k.intensity;if(k instanceof THREE.AmbientLight){l+=n.r;t+=n.g;q+=n.b}else if(k instanceof THREE.DirectionalLight){k=
  158. J*3;E[k]=n.r*s;E[k+1]=n.g*s;E[k+2]=n.b*s;v[k]=z.x;v[k+1]=z.y;v[k+2]=z.z;J+=1}else if(k instanceof THREE.PointLight){k=Q*3;D[k]=n.r*s;D[k+1]=n.g*s;D[k+2]=n.b*s;W[k]=z.x;W[k+1]=z.y;W[k+2]=z.z;Q+=1}}for(i=J*3;i<E.length;i++)E[i]=0;for(i=Q*3;i<D.length;i++)D[i]=0;w.point.length=Q;w.directional.length=J;w.ambient[0]=l;w.ambient[1]=t;w.ambient[2]=q};this.createParticleBuffers=function(e){e.__webGLVertexBuffer=b.createBuffer();e.__webGLColorBuffer=b.createBuffer();e.__webGLParticleBuffer=b.createBuffer()};
  159. this.createLineBuffers=function(e){e.__webGLVertexBuffer=b.createBuffer();e.__webGLColorBuffer=b.createBuffer();e.__webGLLineBuffer=b.createBuffer()};this.createMeshBuffers=function(e){e.__webGLVertexBuffer=b.createBuffer();e.__webGLNormalBuffer=b.createBuffer();e.__webGLTangentBuffer=b.createBuffer();e.__webGLColorBuffer=b.createBuffer();e.__webGLUVBuffer=b.createBuffer();e.__webGLUV2Buffer=b.createBuffer();e.__webGLFaceBuffer=b.createBuffer();e.__webGLLineBuffer=b.createBuffer()};this.initLineBuffers=
  160. function(e){var g=e.vertices.length;e.__vertexArray=new Float32Array(g*3);e.__colorArray=new Float32Array(g*3);e.__lineArray=new Uint16Array(g);e.__webGLLineCount=g};this.initParticleBuffers=function(e){var g=e.vertices.length;e.__vertexArray=new Float32Array(g*3);e.__colorArray=new Float32Array(g*3);e.__particleArray=new Uint16Array(g);e.__sortArray=[];e.__webGLParticleCount=g};this.initMeshBuffers=function(e,g){var i,f,k=0,l=0,t=0,q=g.geometry.faces,n=e.faces;i=0;for(f=n.length;i<f;i++){fi=n[i];
  161. face=q[fi];if(face instanceof THREE.Face3){k+=3;l+=1;t+=3}else if(face instanceof THREE.Face4){k+=4;l+=2;t+=4}}e.__vertexArray=new Float32Array(k*3);e.__normalArray=new Float32Array(k*3);e.__tangentArray=new Float32Array(k*4);e.__colorArray=new Float32Array(k*3);e.__uvArray=new Float32Array(k*2);e.__uv2Array=new Float32Array(k*2);e.__faceArray=new Uint16Array(l*3);e.__lineArray=new Uint16Array(t*2);k=false;i=0;for(f=g.materials.length;i<f;i++){q=g.materials[i];if(q instanceof THREE.MeshFaceMaterial){q=
  162. 0;for(n=e.materials.length;q<n;q++)if(e.materials[q]&&e.materials[q].shading!=undefined&&e.materials[q].shading==THREE.SmoothShading){k=true;break}}else if(q&&q.shading!=undefined&&q.shading==THREE.SmoothShading){k=true;break}if(k)break}e.__needsSmoothNormals=k;e.__webGLFaceCount=l*3;e.__webGLLineCount=t*2};this.setMeshBuffers=function(e,g,i){var f,k,l,t,q,n,z,s,w,E,v=0,D=0,W=0,J=0,Q=0,P=0,F=0,V=0,S=0,I=e.__vertexArray,M=e.__uvArray,T=e.__uv2Array,O=e.__normalArray,x=e.__tangentArray,K=e.__colorArray,
  163. U=e.__faceArray,Z=e.__lineArray,ma=e.__needsSmoothNormals,ca=g.geometry,xa=ca.__dirtyVertices,$=ca.__dirtyElements,ia=ca.__dirtyUvs,pa=ca.__dirtyNormals,ua=ca.__dirtyTangents,fa=ca.__dirtyColors,da=ca.vertices,va=e.faces,ta=ca.faces,ba=ca.uvs,ja=ca.uvs2,la=ca.colors;g=0;for(f=va.length;g<f;g++){k=va[g];l=ta[k];n=ba[k];k=ja[k];t=l.vertexNormals;q=l.normal;if(l instanceof THREE.Face3){if(xa){z=da[l.a].position;s=da[l.b].position;w=da[l.c].position;I[D]=z.x;I[D+1]=z.y;I[D+2]=z.z;I[D+3]=s.x;I[D+4]=s.y;
  164. I[D+5]=s.z;I[D+6]=w.x;I[D+7]=w.y;I[D+8]=w.z;D+=9}if(fa&&la.length){z=la[l.a];s=la[l.b];w=la[l.c];K[S]=z.r;K[S+1]=z.g;K[S+2]=z.b;K[S+3]=s.r;K[S+4]=s.g;K[S+5]=s.b;K[S+6]=w.r;K[S+7]=w.g;K[S+8]=w.b;S+=9}if(ua&&ca.hasTangents){z=da[l.a].tangent;s=da[l.b].tangent;w=da[l.c].tangent;x[F]=z.x;x[F+1]=z.y;x[F+2]=z.z;x[F+3]=z.w;x[F+4]=s.x;x[F+5]=s.y;x[F+6]=s.z;x[F+7]=s.w;x[F+8]=w.x;x[F+9]=w.y;x[F+10]=w.z;x[F+11]=w.w;F+=12}if(pa)if(t.length==3&&ma)for(l=0;l<3;l++){q=t[l];O[P]=q.x;O[P+1]=q.y;O[P+2]=q.z;P+=3}else for(l=
  165. 0;l<3;l++){O[P]=q.x;O[P+1]=q.y;O[P+2]=q.z;P+=3}if(ia&&n)for(l=0;l<3;l++){t=n[l];M[W]=t.u;M[W+1]=t.v;W+=2}if(ia&&k)for(l=0;l<3;l++){n=k[l];T[J]=n.u;T[J+1]=n.v;J+=2}if($){U[Q]=v;U[Q+1]=v+1;U[Q+2]=v+2;Q+=3;Z[V]=v;Z[V+1]=v+1;Z[V+2]=v;Z[V+3]=v+2;Z[V+4]=v+1;Z[V+5]=v+2;V+=6;v+=3}}else if(l instanceof THREE.Face4){if(xa){z=da[l.a].position;s=da[l.b].position;w=da[l.c].position;E=da[l.d].position;I[D]=z.x;I[D+1]=z.y;I[D+2]=z.z;I[D+3]=s.x;I[D+4]=s.y;I[D+5]=s.z;I[D+6]=w.x;I[D+7]=w.y;I[D+8]=w.z;I[D+9]=E.x;I[D+
  166. 10]=E.y;I[D+11]=E.z;D+=12}if(fa&&la.length){z=la[l.a];s=la[l.b];w=la[l.d];K[S]=z.r;K[S+1]=z.g;K[S+2]=z.b;K[S+3]=s.r;K[S+4]=s.g;K[S+5]=s.b;K[S+6]=w.r;K[S+7]=w.g;K[S+8]=w.b;K[S+9]=(void 0).r;K[S+10]=(void 0).g;K[S+11]=(void 0).b;S+=12}if(ua&&ca.hasTangents){z=da[l.a].tangent;s=da[l.b].tangent;w=da[l.c].tangent;l=da[l.d].tangent;x[F]=z.x;x[F+1]=z.y;x[F+2]=z.z;x[F+3]=z.w;x[F+4]=s.x;x[F+5]=s.y;x[F+6]=s.z;x[F+7]=s.w;x[F+8]=w.x;x[F+9]=w.y;x[F+10]=w.z;x[F+11]=w.w;x[F+12]=l.x;x[F+13]=l.y;x[F+14]=l.z;x[F+15]=
  167. l.w;F+=16}if(pa)if(t.length==4&&ma)for(l=0;l<4;l++){q=t[l];O[P]=q.x;O[P+1]=q.y;O[P+2]=q.z;P+=3}else for(l=0;l<4;l++){O[P]=q.x;O[P+1]=q.y;O[P+2]=q.z;P+=3}if(ia&&n)for(l=0;l<4;l++){t=n[l];M[W]=t.u;M[W+1]=t.v;W+=2}if(ia&&k)for(l=0;l<4;l++){n=k[l];T[J]=n.u;T[J+1]=n.v;J+=2}if($){U[Q]=v;U[Q+1]=v+1;U[Q+2]=v+2;U[Q+3]=v;U[Q+4]=v+2;U[Q+5]=v+3;Q+=6;Z[V]=v;Z[V+1]=v+1;Z[V+2]=v;Z[V+3]=v+3;Z[V+4]=v+1;Z[V+5]=v+2;Z[V+6]=v+2;Z[V+7]=v+3;V+=8;v+=4}}}if(xa){b.bindBuffer(b.ARRAY_BUFFER,e.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,
  168. I,i)}if(fa&&la.length){b.bindBuffer(b.ARRAY_BUFFER,e.__webGLColorBuffer);b.bufferData(b.ARRAY_BUFFER,K,i)}if(pa){b.bindBuffer(b.ARRAY_BUFFER,e.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,O,i)}if(ua&&ca.hasTangents){b.bindBuffer(b.ARRAY_BUFFER,e.__webGLTangentBuffer);b.bufferData(b.ARRAY_BUFFER,x,i)}if(ia&&W>0){b.bindBuffer(b.ARRAY_BUFFER,e.__webGLUVBuffer);b.bufferData(b.ARRAY_BUFFER,M,i)}if(ia&&J>0){b.bindBuffer(b.ARRAY_BUFFER,e.__webGLUV2Buffer);b.bufferData(b.ARRAY_BUFFER,T,i)}if($){b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,
  169. e.__webGLFaceBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,U,i);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,e.__webGLLineBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,Z,i)}};this.setLineBuffers=function(e,g){var i,f,k,l=e.vertices,t=e.colors,q=l.length,n=t.length,z=e.__vertexArray,s=e.__colorArray,w=e.__lineArray,E=e.__dirtyColors,v=e.__dirtyElements;if(e.__dirtyVertices){for(i=0;i<q;i++){f=l[i].position;k=i*3;z[k]=f.x;z[k+1]=f.y;z[k+2]=f.z}b.bindBuffer(b.ARRAY_BUFFER,e.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,
  170. z,g)}if(E){for(i=0;i<n;i++){color=t[i];k=i*3;s[k]=color.r;s[k+1]=color.g;s[k+2]=color.b}b.bindBuffer(b.ARRAY_BUFFER,e.__webGLColorBuffer);b.bufferData(b.ARRAY_BUFFER,s,g)}if(v){for(i=0;i<q;i++)w[i]=i;b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,e.__webGLLineBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,w,g)}};this.setParticleBuffers=function(e,g,i,f){var k,l,t;l=e.vertices;var q=l.length,n=e.colors,z=n.length,s=e.__vertexArray,w=e.__particleArray,E=e.__colorArray,v=e.__sortArray,D=e.__dirtyVertices,W=e.__dirtyElements,
  171. J=e.__dirtyColors;if(i.sortParticles){p.multiply(f.projectionMatrix,f.matrix);p.multiplySelf(i.matrix);for(k=0;k<q;k++){t=l[k].position;u.copy(t);p.multiplyVector3(u);v[k]=[u.z,k]}v.sort(function(Q,P){return P[0]-Q[0]});for(k=0;k<q;k++){t=l[v[k][1]].position;f=k*3;s[f]=t.x;s[f+1]=t.y;s[f+2]=t.z}for(l=0;l<z;l++){f=l*3;color=n[v[l][1]];E[f]=color.r;E[f+1]=color.g;E[f+2]=color.b}}else{if(D)for(k=0;k<q;k++){t=l[k].position;f=k*3;s[f]=t.x;s[f+1]=t.y;s[f+2]=t.z}if(J)for(l=0;l<z;l++){color=n[l];f=l*3;E[f]=
  172. color.r;E[f+1]=color.g;E[f+2]=color.b}}if(W){for(k=0;k<q;k++)w[k]=k;b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,e.__webGLParticleBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,w,g)}if(D||i.sortParticles){b.bindBuffer(b.ARRAY_BUFFER,e.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,s,g)}if(J||i.sortParticles){b.bindBuffer(b.ARRAY_BUFFER,e.__webGLColorBuffer);b.bufferData(b.ARRAY_BUFFER,E,g)}};this.initMaterial=function(e,g,i){if(!e.program){var f,k;if(e instanceof THREE.MeshDepthMaterial)c(e,THREE.ShaderLib.depth);
  173. else if(e instanceof THREE.MeshNormalMaterial)c(e,THREE.ShaderLib.normal);else if(e instanceof THREE.MeshBasicMaterial)c(e,THREE.ShaderLib.basic);else if(e instanceof THREE.MeshLambertMaterial)c(e,THREE.ShaderLib.lambert);else if(e instanceof THREE.MeshPhongMaterial)c(e,THREE.ShaderLib.phong);else if(e instanceof THREE.LineBasicMaterial)c(e,THREE.ShaderLib.basic);else e instanceof THREE.ParticleBasicMaterial&&c(e,THREE.ShaderLib.particle_basic);var l,t,q,n;k=q=n=0;for(l=g.length;k<l;k++){t=g[k];t instanceof
  174. THREE.DirectionalLight&&q++;t instanceof THREE.PointLight&&n++}if(n+q<=4){g=q;n=n}else{g=Math.ceil(4*q/(n+q));n=4-g}k={directional:g,point:n};n=e.fragment_shader;g=e.vertex_shader;l={fog:i,map:e.map,env_map:e.env_map,light_map:e.light_map,vertex_colors:e.vertex_colors,maxDirLights:k.directional,maxPointLights:k.point};i=b.createProgram();k=["#ifdef GL_ES\nprecision highp float;\n#endif","#define MAX_DIR_LIGHTS "+l.maxDirLights,"#define MAX_POINT_LIGHTS "+l.maxPointLights,l.fog?"#define USE_FOG":"",
  175. l.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",l.map?"#define USE_MAP":"",l.env_map?"#define USE_ENVMAP":"",l.light_map?"#define USE_LIGHTMAP":"",l.vertex_colors?"#define USE_COLOR":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");l=[b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+l.maxDirLights,"#define MAX_POINT_LIGHTS "+l.maxPointLights,l.map?"#define USE_MAP":"",l.env_map?"#define USE_ENVMAP":"",l.light_map?
  176. "#define USE_LIGHTMAP":"",l.vertex_colors?"#define USE_COLOR":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec3 color;\nattribute vec2 uv;\nattribute vec2 uv2;\n"].join("\n");b.attachShader(i,h("fragment",k+n));b.attachShader(i,h("vertex",l+g));b.linkProgram(i);b.getProgramParameter(i,b.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+
  177. b.getProgramParameter(i,b.VALIDATE_STATUS)+", gl error ["+b.getError()+"]");i.uniforms={};i.attributes={};e.program=i;i=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(f in e.uniforms)i.push(f);f=e.program;n=0;for(g=i.length;n<g;n++){k=i[n];f.uniforms[k]=b.getUniformLocation(f,k)}e=e.program;f=["position","normal","uv","uv2","tangent","color"];i=0;for(n=f.length;i<n;i++){g=f[i];e.attributes[g]=b.getAttribLocation(e,g)}}};this.setProgram=function(e,
  178. g,i,f,k){this.initMaterial(f,g,i);var l=f.program;if(l!=r){b.useProgram(l);r=l}this.loadCamera(l,e);this.loadMatrices(l,k);if(f instanceof THREE.MeshPhongMaterial||f instanceof THREE.MeshLambertMaterial){this.setupLights(l,g);g=this.lights;f.uniforms.enableLighting.value=g.directional.length+g.point.length;f.uniforms.ambientLightColor.value=g.ambient;f.uniforms.directionalLightColor.value=g.directional.colors;f.uniforms.directionalLightDirection.value=g.directional.positions;f.uniforms.pointLightColor.value=
  179. g.point.colors;f.uniforms.pointLightPosition.value=g.point.positions}if(f instanceof THREE.MeshBasicMaterial||f instanceof THREE.MeshLambertMaterial||f instanceof THREE.MeshPhongMaterial){f.uniforms.diffuse.value.setRGB(f.color.r*f.opacity,f.color.g*f.opacity,f.color.b*f.opacity);f.uniforms.opacity.value=f.opacity;f.uniforms.map.texture=f.map;f.uniforms.light_map.texture=f.light_map;f.uniforms.env_map.texture=f.env_map;f.uniforms.reflectivity.value=f.reflectivity;f.uniforms.refraction_ratio.value=
  180. f.refraction_ratio;f.uniforms.combine.value=f.combine;f.uniforms.useRefract.value=f.env_map&&f.env_map.mapping instanceof THREE.CubeRefractionMapping;if(i){f.uniforms.fogColor.value.setHex(i.color.hex);if(i instanceof THREE.Fog){f.uniforms.fogNear.value=i.near;f.uniforms.fogFar.value=i.far}else if(i instanceof THREE.FogExp2)f.uniforms.fogDensity.value=i.density}}if(f instanceof THREE.LineBasicMaterial){f.uniforms.diffuse.value.setRGB(f.color.r*f.opacity,f.color.g*f.opacity,f.color.b*f.opacity);f.uniforms.opacity.value=
  181. f.opacity;if(i){f.uniforms.fogColor.value.setHex(i.color.hex);if(i instanceof THREE.Fog){f.uniforms.fogNear.value=i.near;f.uniforms.fogFar.value=i.far}else if(i instanceof THREE.FogExp2)f.uniforms.fogDensity.value=i.density}}if(f instanceof THREE.ParticleBasicMaterial){f.uniforms.psColor.value.setRGB(f.color.r*f.opacity,f.color.g*f.opacity,f.color.b*f.opacity);f.uniforms.opacity.value=f.opacity;f.uniforms.size.value=f.size;f.uniforms.map.texture=f.map;if(i){f.uniforms.fogColor.value.setHex(i.color.hex);
  182. if(i instanceof THREE.Fog){f.uniforms.fogNear.value=i.near;f.uniforms.fogFar.value=i.far}else if(i instanceof THREE.FogExp2)f.uniforms.fogDensity.value=i.density}}if(f instanceof THREE.MeshPhongMaterial){f.uniforms.ambient.value.setRGB(f.ambient.r,f.ambient.g,f.ambient.b);f.uniforms.specular.value.setRGB(f.specular.r,f.specular.g,f.specular.b);f.uniforms.shininess.value=f.shininess}if(f instanceof THREE.MeshDepthMaterial){f.uniforms.mNear.value=e.near;f.uniforms.mFar.value=e.far;f.uniforms.opacity.value=
  183. f.opacity}if(f instanceof THREE.MeshNormalMaterial)f.uniforms.opacity.value=f.opacity;e=f.uniforms;for(var t in e)if(k=l.uniforms[t]){f=e[t];g=f.type;i=f.value;if(g=="i")b.uniform1i(k,i);else if(g=="f")b.uniform1f(k,i);else if(g=="fv1")b.uniform1fv(k,i);else if(g=="fv")b.uniform3fv(k,i);else if(g=="v2")b.uniform2f(k,i.x,i.y);else if(g=="v3")b.uniform3f(k,i.x,i.y,i.z);else if(g=="c")b.uniform3f(k,i.r,i.g,i.b);else if(g=="t"){b.uniform1i(k,i);if(f=f.texture)if(f.image instanceof Array&&f.image.length==
  184. 6){f=f;i=i;if(f.image.length==6){if(!f.image.__webGLTextureCube&&!f.image.__cubeMapInitialized&&f.image.loadCount==6){f.image.__webGLTextureCube=b.createTexture();b.bindTexture(b.TEXTURE_CUBE_MAP,f.image.__webGLTextureCube);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_MAG_FILTER,b.LINEAR);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_MIN_FILTER,b.LINEAR_MIPMAP_LINEAR);
  185. for(g=0;g<6;++g)b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X+g,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,f.image[g]);b.generateMipmap(b.TEXTURE_CUBE_MAP);b.bindTexture(b.TEXTURE_CUBE_MAP,null);f.image.__cubeMapInitialized=true}b.activeTexture(b.TEXTURE0+i);b.bindTexture(b.TEXTURE_CUBE_MAP,f.image.__webGLTextureCube)}}else{f=f;i=i;if(!f.__webGLTexture&&f.image.loaded){f.__webGLTexture=b.createTexture();b.bindTexture(b.TEXTURE_2D,f.__webGLTexture);b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,f.image);
  186. b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,j(f.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,j(f.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,j(f.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,j(f.min_filter));b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}b.activeTexture(b.TEXTURE0+i);b.bindTexture(b.TEXTURE_2D,f.__webGLTexture)}}}return l};this.renderBuffer=function(e,g,i,f,k,l){e=this.setProgram(e,g,i,f,l).attributes;b.bindBuffer(b.ARRAY_BUFFER,
  187. k.__webGLVertexBuffer);b.vertexAttribPointer(e.position,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(e.position);if(e.color>=0){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLColorBuffer);b.vertexAttribPointer(e.color,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(e.color)}if(e.normal>=0){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLNormalBuffer);b.vertexAttribPointer(e.normal,3,b.FLOAT,false,0,0);b.enableVertexAttribArray(e.normal)}if(e.tangent>=0){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLTangentBuffer);b.vertexAttribPointer(e.tangent,
  188. 4,b.FLOAT,false,0,0);b.enableVertexAttribArray(e.tangent)}if(e.uv>=0)if(k.__webGLUVBuffer){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLUVBuffer);b.vertexAttribPointer(e.uv,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(e.uv)}else b.disableVertexAttribArray(e.uv);if(e.uv2>=0)if(k.__webGLUV2Buffer){b.bindBuffer(b.ARRAY_BUFFER,k.__webGLUV2Buffer);b.vertexAttribPointer(e.uv2,2,b.FLOAT,false,0,0);b.enableVertexAttribArray(e.uv2)}else b.disableVertexAttribArray(e.uv2);if(f.wireframe||f instanceof THREE.LineBasicMaterial){e=
  189. f.wireframe_linewidth!==undefined?f.wireframe_linewidth:f.linewidth!==undefined?f.linewidth:1;f=f instanceof THREE.LineBasicMaterial&&l.type==THREE.LineStrip?b.LINE_STRIP:b.LINES;b.lineWidth(e);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,k.__webGLLineBuffer);b.drawElements(f,k.__webGLLineCount,b.UNSIGNED_SHORT,0)}else if(f instanceof THREE.ParticleBasicMaterial){b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,k.__webGLParticleBuffer);b.drawElements(b.POINTS,k.__webGLParticleCount,b.UNSIGNED_SHORT,0)}else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,
  190. k.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,k.__webGLFaceCount,b.UNSIGNED_SHORT,0)}};this.renderPass=function(e,g,i,f,k,l,t){var q,n,z,s,w;z=0;for(s=f.materials.length;z<s;z++){q=f.materials[z];if(q instanceof THREE.MeshFaceMaterial){q=0;for(n=k.materials.length;q<n;q++)if((w=k.materials[q])&&w.blending==l&&w.opacity<1==t){this.setBlending(w.blending);this.setDepthTest(w.depth_test);this.renderBuffer(e,g,i,w,k,f)}}else if((w=q)&&w.blending==l&&w.opacity<1==t){this.setBlending(w.blending);this.setDepthTest(w.depth_test);
  191. this.renderBuffer(e,g,i,w,k,f)}}};this.renderPassImmediate=function(e,g,i,f,k,l){var t,q,n,z;t=0;for(q=f.materials.length;t<q;t++)if((n=f.materials[t])&&n.blending==k&&n.opacity<1==l){this.setBlending(n.blending);this.setDepthTest(n.depth_test);z=this.setProgram(e,g,i,n,f);f.render(function(s){var w=z;if(!s.__webGLVertexBuffer)s.__webGLVertexBuffer=b.createBuffer();if(!s.__webGLNormalBuffer)s.__webGLNormalBuffer=b.createBuffer();if(s.hasPos){b.bindBuffer(b.ARRAY_BUFFER,s.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,
  192. s.positionArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(w.attributes.position);b.vertexAttribPointer(w.attributes.position,3,b.FLOAT,false,0,0)}if(s.hasNormal){b.bindBuffer(b.ARRAY_BUFFER,s.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,s.normalArray,b.DYNAMIC_DRAW);b.enableVertexAttribArray(w.attributes.normal);b.vertexAttribPointer(w.attributes.normal,3,b.FLOAT,false,0,0)}b.drawArrays(b.TRIANGLES,0,s.count);s.count=0})}};this.render=function(e,g,i,f){var k,l,t,q,n=e.lights,z=e.fog;g.autoUpdateMatrix&&
  193. g.updateMatrix();A.set(g.matrix.flatten());B.set(g.projectionMatrix.flatten());this.initWebGLObjects(e,g);f=f!==undefined?f:true;if(i&&!i.__webGLFramebuffer){i.__webGLFramebuffer=b.createFramebuffer();i.__webGLRenderbuffer=b.createRenderbuffer();i.__webGLTexture=b.createTexture();b.bindRenderbuffer(b.RENDERBUFFER,i.__webGLRenderbuffer);b.renderbufferStorage(b.RENDERBUFFER,b.DEPTH_COMPONENT16,i.width,i.height);b.bindTexture(b.TEXTURE_2D,i.__webGLTexture);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,
  194. j(i.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,j(i.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,j(i.mag_filter));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,j(i.min_filter));b.texImage2D(b.TEXTURE_2D,0,j(i.format),i.width,i.height,0,j(i.format),j(i.type),null);b.bindFramebuffer(b.FRAMEBUFFER,i.__webGLFramebuffer);b.framebufferTexture2D(b.FRAMEBUFFER,b.COLOR_ATTACHMENT0,b.TEXTURE_2D,i.__webGLTexture,0);b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,
  195. i.__webGLRenderbuffer);b.bindTexture(b.TEXTURE_2D,null);b.bindRenderbuffer(b.RENDERBUFFER,null);b.bindFramebuffer(b.FRAMEBUFFER,null)}if(i){k=i.__webGLFramebuffer;q=i.width;l=i.height}else{k=null;q=m.width;l=m.height}if(k!=o){b.bindFramebuffer(b.FRAMEBUFFER,k);b.viewport(0,0,q,l);f&&b.clear(b.COLOR_BUFFER_BIT|b.DEPTH_BUFFER_BIT);o=k}this.autoClear&&this.clear();k=e.__webGLObjects.length;for(f=0;f<k;f++){t=e.__webGLObjects[f];q=t.object;if(q.visible){q.autoUpdateMatrix&&q.updateMatrix();this.setupMatrices(q,
  196. g)}}l=e.__webGLObjectsImmediate.length;for(f=0;f<l;f++){t=e.__webGLObjectsImmediate[f];q=t.object;if(q.visible){q.autoUpdateMatrix&&q.updateMatrix();this.setupMatrices(q,g)}}for(f=0;f<k;f++){t=e.__webGLObjects[f];q=t.object;l=t.buffer;if(q.visible){d(q);this.renderPass(g,n,z,q,l,THREE.NormalBlending,false)}}for(f=0;f<e.__webGLObjectsImmediate.length;f++){t=e.__webGLObjectsImmediate[f];q=t.object;if(q.visible){d(q);this.renderPassImmediate(g,n,z,q,THREE.NormalBlending,false)}}for(f=0;f<k;f++){t=e.__webGLObjects[f];
  197. q=t.object;l=t.buffer;if(q.visible){d(q);this.renderPass(g,n,z,q,l,THREE.AdditiveBlending,false);this.renderPass(g,n,z,q,l,THREE.SubtractiveBlending,false);this.renderPass(g,n,z,q,l,THREE.AdditiveBlending,true);this.renderPass(g,n,z,q,l,THREE.SubtractiveBlending,true);this.renderPass(g,n,z,q,l,THREE.NormalBlending,true);this.renderPass(g,n,z,q,l,THREE.BillboardBlending,false)}}for(f=0;f<e.__webGLObjectsImmediate.length;f++){t=e.__webGLObjectsImmediate[f];q=t.object;if(q.visible){d(q);this.renderPassImmediate(g,
  198. n,z,q,THREE.NormalBlending,true)}}if(i&&i.min_filter!==THREE.NearestFilter&&i.min_filter!==THREE.LinearFilter){b.bindTexture(b.TEXTURE_2D,i.__webGLTexture);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}};this.initWebGLObjects=function(e,g){function i(w,E,v,D){if(w[E]==undefined){e.__webGLObjects.push({buffer:v,object:D});w[E]=1}}function f(w,E,v){if(w[E]==undefined){e.__webGLObjectsImmediate.push({object:v});w[E]=1}}var k,l,t,q,n,z,s;if(!e.__webGLObjects){e.__webGLObjects=[];e.__webGLObjectsMap=
  199. {};e.__webGLObjectsImmediate=[]}k=0;for(l=e.objects.length;k<l;k++){t=e.objects[k];n=t.geometry;if(e.__webGLObjectsMap[t.id]==undefined){e.__webGLObjectsMap[t.id]={};t._modelViewMatrix=new THREE.Matrix4;t._normalMatrixArray=new Float32Array(9);t._modelViewMatrixArray=new Float32Array(16);t._objectMatrixArray=new Float32Array(16)}s=e.__webGLObjectsMap[t.id];if(t instanceof THREE.Mesh){for(q in n.geometryChunks){z=n.geometryChunks[q];if(!z.__webGLVertexBuffer){this.createMeshBuffers(z);this.initMeshBuffers(z,
  200. t);n.__dirtyVertices=true;n.__dirtyElements=true;n.__dirtyUvs=true;n.__dirtyNormals=true;n.__dirtyTangents=true;n.__dirtyColors=true}if(n.__dirtyVertices||n.__dirtyElements||n.__dirtyUvs||n.__dirtyNormals||n.__dirtyColors||n.__dirtyTangents)this.setMeshBuffers(z,t,b.DYNAMIC_DRAW);i(s,q,z,t)}n.__dirtyVertices=false;n.__dirtyElements=false;n.__dirtyUvs=false;n.__dirtyNormals=false;n.__dirtyTangents=false;n.__dirtyColors=false}else if(t instanceof THREE.Line){if(!n.__webGLVertexBuffer){this.createLineBuffers(n);
  201. this.initLineBuffers(n);n.__dirtyVertices=true;n.__dirtyElements=true;n.__dirtyColors=true}if(n.__dirtyVertices||n.__dirtyColors)this.setLineBuffers(n,b.DYNAMIC_DRAW);i(s,0,n,t);n.__dirtyVertices=false;n.__dirtyElements=false;n.__dirtyColors=false}else if(t instanceof THREE.ParticleSystem){if(!n.__webGLVertexBuffer){this.createParticleBuffers(n);this.initParticleBuffers(n);n.__dirtyVertices=true;n.__dirtyColors=true;n.__dirtyElements=true}if(n.__dirtyVertices||n.__dirtyColors||t.sortParticles)this.setParticleBuffers(n,
  202. b.DYNAMIC_DRAW,t,g);i(s,0,n,t);n.__dirtyVertices=false;n.__dirtyColors=false;n.__dirtyElements=false}else t instanceof THREE.MarchingCubes&&f(s,0,t)}};this.removeObject=function(e,g){var i,f;for(i=e.__webGLObjects.length-1;i>=0;i--){f=e.__webGLObjects[i].object;g==f&&e.__webGLObjects.splice(i,1)}};this.setupMatrices=function(e,g){e._modelViewMatrix.multiply(g.matrix,e.matrix);e._modelViewMatrixArray.set(e._modelViewMatrix.flatten());e._normalMatrix=THREE.Matrix4.makeInvert3x3(e._modelViewMatrix).transpose();
  203. e._normalMatrixArray.set(e._normalMatrix.m);e._objectMatrixArray.set(e.matrix.flatten())};this.loadMatrices=function(e,g){b.uniformMatrix4fv(e.uniforms.viewMatrix,false,A);b.uniformMatrix4fv(e.uniforms.projectionMatrix,false,B);b.uniformMatrix4fv(e.uniforms.modelViewMatrix,false,g._modelViewMatrixArray);b.uniformMatrix3fv(e.uniforms.normalMatrix,false,g._normalMatrixArray);b.uniformMatrix4fv(e.uniforms.objectMatrix,false,g._objectMatrixArray)};this.loadCamera=function(e,g){b.uniform3f(e.uniforms.cameraPosition,
  204. g.position.x,g.position.y,g.position.z)};this.setDepthTest=function(e){e?b.enable(b.DEPTH_TEST):b.disable(b.DEPTH_TEST)};this.setBlending=function(e){switch(e){case THREE.AdditiveBlending:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE);break;case THREE.SubtractiveBlending:b.blendFunc(b.DST_COLOR,b.ZERO);break;case THREE.BillboardBlending:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA);break;default:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA)}};
  205. this.setFaceCulling=function(e,g){if(e){!g||g=="ccw"?b.frontFace(b.CCW):b.frontFace(b.CW);if(e=="back")b.cullFace(b.BACK);else e=="front"?b.cullFace(b.FRONT):b.cullFace(b.FRONT_AND_BACK);b.enable(b.CULL_FACE)}else b.disable(b.CULL_FACE)};this.supportsVertexTextures=function(){return b.getParameter(b.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}};
  206. 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, gl_FragColor.w ), fogFactor );\n#endif",
  207. 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\nvec4 cubeColor = textureCube( env_map, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = vec4( mix( gl_FragColor.xyz, cubeColor.xyz, reflectivity ), opacity );\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",
  208. 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_particle_pars_fragment:"#ifdef USE_MAP\nuniform sampler2D map;\n#endif",
  209. map_particle_fragment:"#ifdef USE_MAP\ngl_FragColor = gl_FragColor * texture2D( map, gl_PointCoord );\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\ngl_FragColor = gl_FragColor * texture2D( map, vUv );\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv;\n#endif",lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\nvarying vec2 vUv2;\nuniform sampler2D light_map;\n#endif",lightmap_pars_vertex:"#ifdef USE_LIGHTMAP\nvarying vec2 vUv2;\n#endif",
  210. lightmap_fragment:"#ifdef USE_LIGHTMAP\ngl_FragColor = gl_FragColor * texture2D( light_map, vUv2 );\n#endif",lightmap_vertex:"#ifdef USE_LIGHTMAP\nvUv2 = uv2;\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",
  211. lights_vertex:"if ( !enableLighting ) {\nvLightWeighting = vec3( 1.0 );\n} else {\nvLightWeighting = ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nfloat directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );\nvLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;\n}\n#endif\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 pointLightVector = normalize( lPosition.xyz - mvPosition.xyz );\nfloat pointLightWeighting = max( dot( transformedNormal, pointLightVector ), 0.0 );\nvLightWeighting += pointLightColor[ i ] * pointLightWeighting;\n#ifdef PHONG\nvPointLightVector[ i ] = pointLightVector;\n#endif\n}\n#endif\n}",
  212. lights_pars_fragment:"#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\nvarying vec3 vViewPosition;\nvarying vec3 vNormal;",lights_fragment:"vec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );\nvec4 mColor = vec4( diffuse, opacity );\nvec4 mSpecular = vec4( specular, opacity );\n#if MAX_POINT_LIGHTS > 0\nvec4 pointDiffuse = vec4( 0.0 );\nvec4 pointSpecular = vec4( 0.0 );\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec3 pointVector = normalize( vPointLightVector[ i ] );\nvec3 pointHalfVector = normalize( vPointLightVector[ i ] + 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, shininess );\npointDiffuse += mColor * pointDiffuseWeight;\npointSpecular += mSpecular * pointSpecularWeight;\n}\n#endif\n#if MAX_DIR_LIGHTS > 0\nvec4 dirDiffuse = vec4( 0.0 );\nvec4 dirSpecular = vec4( 0.0 );\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 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, shininess );\ndirDiffuse += mColor * dirDiffuseWeight;\ndirSpecular += mSpecular * dirSpecularWeight;\n}\n#endif\nvec4 totalLight = vec4( ambient, opacity );\n#if MAX_DIR_LIGHTS > 0\ntotalLight += dirDiffuse + dirSpecular;\n#endif\n#if MAX_POINT_LIGHTS > 0\ntotalLight += pointDiffuse + pointSpecular;\n#endif\ngl_FragColor = gl_FragColor * totalLight;",
  213. color_pars_fragment:"#ifdef USE_COLOR\nvarying vec3 vColor;\n#endif",color_fragment:"#ifdef USE_COLOR\ngl_FragColor = gl_FragColor * vec4( vColor, opacity );\n#endif",color_pars_vertex:"#ifdef USE_COLOR\nvarying vec3 vColor;\n#endif",color_vertex:"#ifdef USE_COLOR\nvColor = color;\n#endif"};
  214. THREE.UniformsLib={common:{diffuse:{type:"c",value:new THREE.Color(15658734)},opacity:{type:"f",value:1},map:{type:"t",value:0,texture:null},light_map:{type:"t",value:2,texture:null},env_map:{type:"t",value:1,texture:null},useRefract:{type:"i",value:0},reflectivity:{type:"f",value:1},refraction_ratio:{type:"f",value:0.98},combine:{type:"i",value:0},fogDensity:{type:"f",value:2.5E-4},fogNear:{type:"f",value:1},fogFar:{type:"f",value:2E3},fogColor:{type:"c",value:new THREE.Color(16777215)}},lights:{enableLighting:{type:"i",
  215. value:1},ambientLightColor:{type:"fv",value:[]},directionalLightDirection:{type:"fv",value:[]},directionalLightColor:{type:"fv",value:[]},pointLightPosition:{type:"fv",value:[]},pointLightColor:{type:"fv",value:[]}},particle:{psColor:{type:"c",value:new THREE.Color(15658734)},opacity:{type:"f",value:1},size:{type:"f",value:1},map:{type:"t",value:0,texture:null},fogDensity:{type:"f",value:2.5E-4},fogNear:{type:"f",value:1},fogFar:{type:"f",value:2E3},fogColor:{type:"c",value:new THREE.Color(16777215)}}};
  216. THREE.ShaderLib={depth:{uniforms:{mNear:{type:"f",value:1},mFar:{type:"f",value:2E3},opacity:{type:"f",value:1}},fragment_shader:"uniform float mNear;\nuniform float mFar;\nuniform float opacity;\nvoid main() {\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\nfloat color = 1.0 - smoothstep( mNear, mFar, depth );\ngl_FragColor = vec4( vec3( color ), opacity );\n}",vertex_shader:"void main() {\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}"},normal:{uniforms:{opacity:{type:"f",
  217. value:1}},fragment_shader:"uniform float opacity;\nvarying vec3 vNormal;\nvoid main() {\ngl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );\n}",vertex_shader:"varying vec3 vNormal;\nvoid main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalize( normalMatrix * normal );\ngl_Position = projectionMatrix * mvPosition;\n}"},basic:{uniforms:THREE.UniformsLib.common,fragment_shader:["uniform vec3 diffuse;\nuniform float opacity;",THREE.Snippets.color_pars_fragment,
  218. THREE.Snippets.map_pars_fragment,THREE.Snippets.lightmap_pars_fragment,THREE.Snippets.envmap_pars_fragment,THREE.Snippets.fog_pars_fragment,"void main() {\ngl_FragColor = vec4( diffuse, opacity );",THREE.Snippets.map_fragment,THREE.Snippets.lightmap_fragment,THREE.Snippets.color_fragment,THREE.Snippets.envmap_fragment,THREE.Snippets.fog_fragment,"}"].join("\n"),vertex_shader:[THREE.Snippets.map_pars_vertex,THREE.Snippets.lightmap_pars_vertex,THREE.Snippets.envmap_pars_vertex,THREE.Snippets.color_pars_vertex,
  219. "void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.Snippets.map_vertex,THREE.Snippets.lightmap_vertex,THREE.Snippets.envmap_vertex,THREE.Snippets.color_vertex,"gl_Position = projectionMatrix * mvPosition;\n}"].join("\n")},lambert:{uniforms:Uniforms.merge([THREE.UniformsLib.common,THREE.UniformsLib.lights]),fragment_shader:["uniform vec3 diffuse;\nuniform float opacity;\nvarying vec3 vLightWeighting;",THREE.Snippets.color_pars_fragment,THREE.Snippets.map_pars_fragment,
  220. THREE.Snippets.lightmap_pars_fragment,THREE.Snippets.envmap_pars_fragment,THREE.Snippets.fog_pars_fragment,"void main() {\ngl_FragColor = vec4( diffuse, opacity );\ngl_FragColor = gl_FragColor * vec4( vLightWeighting, 1.0 );",THREE.Snippets.map_fragment,THREE.Snippets.lightmap_fragment,THREE.Snippets.color_fragment,THREE.Snippets.envmap_fragment,THREE.Snippets.fog_fragment,"}"].join("\n"),vertex_shader:["varying vec3 vLightWeighting;",THREE.Snippets.map_pars_vertex,THREE.Snippets.lightmap_pars_vertex,
  221. THREE.Snippets.envmap_pars_vertex,THREE.Snippets.lights_pars_vertex,THREE.Snippets.color_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.Snippets.map_vertex,THREE.Snippets.lightmap_vertex,THREE.Snippets.envmap_vertex,THREE.Snippets.color_vertex,"vec3 transformedNormal = normalize( normalMatrix * normal );",THREE.Snippets.lights_vertex,"gl_Position = projectionMatrix * mvPosition;\n}"].join("\n")},phong:{uniforms:Uniforms.merge([THREE.UniformsLib.common,
  222. THREE.UniformsLib.lights,{ambient:{type:"c",value:new THREE.Color(328965)},specular:{type:"c",value:new THREE.Color(1118481)},shininess:{type:"f",value:30}}]),fragment_shader:["uniform vec3 diffuse;\nuniform float opacity;\nuniform vec3 ambient;\nuniform vec3 specular;\nuniform float shininess;\nvarying vec3 vLightWeighting;",THREE.Snippets.color_pars_fragment,THREE.Snippets.map_pars_fragment,THREE.Snippets.lightmap_pars_fragment,THREE.Snippets.envmap_pars_fragment,THREE.Snippets.fog_pars_fragment,
  223. THREE.Snippets.lights_pars_fragment,"void main() {\ngl_FragColor = vec4( vLightWeighting, 1.0 );",THREE.Snippets.lights_fragment,THREE.Snippets.map_fragment,THREE.Snippets.lightmap_fragment,THREE.Snippets.color_fragment,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.lightmap_pars_vertex,THREE.Snippets.envmap_pars_vertex,
  224. THREE.Snippets.lights_pars_vertex,THREE.Snippets.color_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.Snippets.map_vertex,THREE.Snippets.lightmap_vertex,THREE.Snippets.envmap_vertex,THREE.Snippets.color_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,
  225. "gl_Position = projectionMatrix * mvPosition;\n}"].join("\n")},particle_basic:{uniforms:THREE.UniformsLib.particle,fragment_shader:["uniform vec3 psColor;\nuniform float opacity;",THREE.Snippets.color_pars_fragment,THREE.Snippets.map_particle_pars_fragment,THREE.Snippets.fog_pars_fragment,"void main() {\ngl_FragColor = vec4( psColor, opacity );",THREE.Snippets.map_particle_fragment,THREE.Snippets.color_fragment,THREE.Snippets.fog_fragment,"}"].join("\n"),vertex_shader:["uniform float size;",THREE.Snippets.color_pars_vertex,
  226. "void main() {",THREE.Snippets.color_vertex,"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\ngl_Position = projectionMatrix * mvPosition;\ngl_PointSize = size;\n}"].join("\n")}};THREE.RenderableObject=function(){this.z=this.object=null};
  227. 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};
  228. THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.materials=null};