ThreeDebug.js 99 KB

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