ThreeDebug.js 94 KB

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