ThreeExtras.js 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // ThreeExtras.js r31 - 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,b,e){this.r=a;this.g=b;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,b){this.x=a||0;this.y=b||0};
  5. THREE.Vector2.prototype={set:function(a,b){this.x=a;this.y=b;return this},copy:function(a){this.x=a.x;this.y=a.y;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;return this},unit:function(){this.multiplyScalar(1/this.length());return this},length:function(){return Math.sqrt(this.x*
  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,b,e){this.x=a||0;this.y=b||0;this.z=e||0};
  7. THREE.Vector3.prototype={set:function(a,b,e){this.x=a;this.y=b;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,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;return this},addScalar:function(a){this.x+=a;this.y+=a;this.z+=a;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;return this},
  8. cross:function(a,b){this.x=a.y*b.z-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){var b=this.x,e=this.y,d=this.z;this.x=e*a.z-d*a.y;this.y=d*a.x-b*a.z;this.z=b*a.y-e*a.x;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=
  9. a;return this},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},distanceTo:function(a){var b=this.x-a.x,e=this.y-a.y;a=this.z-a.z;return Math.sqrt(b*b+e*e+a*a)},distanceToSquared:function(a){var b=this.x-a.x,e=this.y-a.y;a=this.z-a.z;return b*b+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=-this.x;this.y=-this.y;this.z=-this.z;return this},normalize:function(){var a=
  10. 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,b,e,d){this.x=a||0;this.y=b||0;this.z=e||0;this.w=d||1};
  12. THREE.Vector4.prototype={set:function(a,b,e,d){this.x=a;this.y=b;this.z=e;this.w=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w||1;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;
  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,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},toString:function(){return"THREE.Vector4 ("+this.x+", "+this.y+", "+this.z+", "+this.w+")"}};
  14. THREE.Ray=function(a,b){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3};
  15. THREE.Ray.prototype={intersectScene:function(a){var b,e,d=a.objects,f=[];a=0;for(b=d.length;a<b;a++){e=d[a];if(e instanceof THREE.Mesh)f=f.concat(this.intersectObject(e))}f.sort(function(g,k){return g.distance-k.distance});return f},intersectObject:function(a){function b(K,v,D,n){n=n.clone().subSelf(v);D=D.clone().subSelf(v);var O=K.clone().subSelf(v);K=n.dot(n);v=n.dot(D);n=n.dot(O);var L=D.dot(D);D=D.dot(O);O=1/(K*L-v*v);L=(L*n-v*D)*O;K=(K*D-v*n)*O;return L>0&&K>0&&L+K<1}var e,d,f,g,k,j,i,o,w,c,
  16. u,y=a.geometry,B=y.vertices,C=[];e=0;for(d=y.faces.length;e<d;e++){f=y.faces[e];c=this.origin.clone();u=this.direction.clone();g=a.matrix.multiplyVector3(B[f.a].position.clone());k=a.matrix.multiplyVector3(B[f.b].position.clone());j=a.matrix.multiplyVector3(B[f.c].position.clone());i=f instanceof THREE.Face4?a.matrix.multiplyVector3(B[f.d].position.clone()):null;o=a.rotationMatrix.multiplyVector3(f.normal.clone());w=u.dot(o);if(w<0){o=o.dot((new THREE.Vector3).sub(g,c))/w;c=c.addSelf(u.multiplyScalar(o));
  17. if(f instanceof THREE.Face3){if(b(c,g,k,j)){f={distance:this.origin.distanceTo(c),point:c,face:f,object:a};C.push(f)}}else if(f instanceof THREE.Face4)if(b(c,g,k,i)||b(c,k,j,i)){f={distance:this.origin.distanceTo(c),point:c,face:f,object:a};C.push(f)}}}return C}};
  18. THREE.Rectangle=function(){function a(){g=d-b;k=f-e}var b,e,d,f,g,k,j=true;this.getX=function(){return b};this.getY=function(){return e};this.getWidth=function(){return g};this.getHeight=function(){return k};this.getLeft=function(){return b};this.getTop=function(){return e};this.getRight=function(){return d};this.getBottom=function(){return f};this.set=function(i,o,w,c){j=false;b=i;e=o;d=w;f=c;a()};this.addPoint=function(i,o){if(j){j=false;b=i;e=o;d=i;f=o}else{b=b<i?b:i;e=e<o?e:o;d=d>i?d:i;f=f>o?
  19. f:o}a()};this.add3Points=function(i,o,w,c,u,y){if(j){j=false;b=i<w?i<u?i:u:w<u?w:u;e=o<c?o<y?o:y:c<y?c:y;d=i>w?i>u?i:u:w>u?w:u;f=o>c?o>y?o:y:c>y?c:y}else{b=i<w?i<u?i<b?i:b:u<b?u:b:w<u?w<b?w:b:u<b?u:b;e=o<c?o<y?o<e?o:e:y<e?y:e:c<y?c<e?c:e:y<e?y:e;d=i>w?i>u?i>d?i:d:u>d?u:d:w>u?w>d?w:d:u>d?u:d;f=o>c?o>y?o>f?o:f:y>f?y:f:c>y?c>f?c:f:y>f?y:f}a()};this.addRectangle=function(i){if(j){j=false;b=i.getLeft();e=i.getTop();d=i.getRight();f=i.getBottom()}else{b=b<i.getLeft()?b:i.getLeft();e=e<i.getTop()?e:i.getTop();
  20. d=d>i.getRight()?d:i.getRight();f=f>i.getBottom()?f:i.getBottom()}a()};this.inflate=function(i){b-=i;e-=i;d+=i;f+=i;a()};this.minSelf=function(i){b=b>i.getLeft()?b:i.getLeft();e=e>i.getTop()?e:i.getTop();d=d<i.getRight()?d:i.getRight();f=f<i.getBottom()?f:i.getBottom();a()};this.instersects=function(i){return Math.min(d,i.getRight())-Math.max(b,i.getLeft())>=0&&Math.min(f,i.getBottom())-Math.max(e,i.getTop())>=0};this.empty=function(){j=true;f=d=e=b=0;a()};this.isEmpty=function(){return j};this.toString=
  21. function(){return"THREE.Rectangle ( left: "+b+", right: "+d+", top: "+e+", bottom: "+f+", width: "+g+", height: "+k+" )"}};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,b,e,d,f,g,k,j,i,o,w,c,u,y,B,C){this.n11=a||1;this.n12=b||0;this.n13=e||0;this.n14=d||0;this.n21=f||0;this.n22=g||1;this.n23=k||0;this.n24=j||0;this.n31=i||0;this.n32=o||0;this.n33=w||1;this.n34=c||0;this.n41=u||0;this.n42=y||0;this.n43=B||0;this.n44=C||1};
  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,b,e,d,f,g,k,j,i,o,w,c,u,y,B,C){this.n11=a;this.n12=b;this.n13=e;this.n14=d;this.n21=f;this.n22=g;this.n23=k;this.n24=j;this.n31=i;this.n32=o;this.n33=w;this.n34=c;this.n41=u;this.n42=y;this.n43=B;this.n44=C;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,b,e){var d=new THREE.Vector3,f=new THREE.Vector3,g=new THREE.Vector3;g.sub(a,b).normalize();d.cross(e,g).normalize();f.cross(g,d).normalize();this.n11=d.x;this.n12=d.y;this.n13=d.z;this.n14=-d.dot(a);this.n21=f.x;this.n22=f.y;this.n23=f.z;this.n24=-f.dot(a);this.n31=g.x;
  25. this.n32=g.y;this.n33=g.z;this.n34=-g.dot(a);this.n43=this.n42=this.n41=0;this.n44=1;return this},multiplyVector3:function(a){var b=a.x,e=a.y,d=a.z,f=1/(this.n41*b+this.n42*e+this.n43*d+this.n44);a.x=(this.n11*b+this.n12*e+this.n13*d+this.n14)*f;a.y=(this.n21*b+this.n22*e+this.n23*d+this.n24)*f;a.z=(this.n31*b+this.n32*e+this.n33*d+this.n34)*f;return a},multiplyVector4:function(a){var b=a.x,e=a.y,d=a.z,f=a.w;a.x=this.n11*b+this.n12*e+this.n13*d+this.n14*f;a.y=this.n21*b+this.n22*e+this.n23*d+this.n24*
  26. f;a.z=this.n31*b+this.n32*e+this.n33*d+this.n34*f;a.w=this.n41*b+this.n42*e+this.n43*d+this.n44*f;return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var e=a.n11,d=a.n12,f=a.n13,g=a.n14,k=a.n21,j=a.n22,i=a.n23,o=a.n24,w=a.n31,c=a.n32,
  27. u=a.n33,y=a.n34,B=a.n41,C=a.n42,K=a.n43,v=a.n44,D=b.n11,n=b.n12,O=b.n13,L=b.n14,h=b.n21,m=b.n22,l=b.n23,p=b.n24,s=b.n31,t=b.n32,x=b.n33,z=b.n34,E=b.n41,P=b.n42,N=b.n43,M=b.n44;this.n11=e*D+d*h+f*s+g*E;this.n12=e*n+d*m+f*t+g*P;this.n13=e*O+d*l+f*x+g*N;this.n14=e*L+d*p+f*z+g*M;this.n21=k*D+j*h+i*s+o*E;this.n22=k*n+j*m+i*t+o*P;this.n23=k*O+j*l+i*x+o*N;this.n24=k*L+j*p+i*z+o*M;this.n31=w*D+c*h+u*s+y*E;this.n32=w*n+c*m+u*t+y*P;this.n33=w*O+c*l+u*x+y*N;this.n34=w*L+c*p+u*z+y*M;this.n41=B*D+C*h+K*s+v*E;
  28. this.n42=B*n+C*m+K*t+v*P;this.n43=B*O+C*l+K*x+v*N;this.n44=B*L+C*p+K*z+v*M;return this},multiplySelf:function(a){var b=this.n11,e=this.n12,d=this.n13,f=this.n14,g=this.n21,k=this.n22,j=this.n23,i=this.n24,o=this.n31,w=this.n32,c=this.n33,u=this.n34,y=this.n41,B=this.n42,C=this.n43,K=this.n44,v=a.n11,D=a.n21,n=a.n31,O=a.n41,L=a.n12,h=a.n22,m=a.n32,l=a.n42,p=a.n13,s=a.n23,t=a.n33,x=a.n43,z=a.n14,E=a.n24,P=a.n34;a=a.n44;this.n11=b*v+e*D+d*n+f*O;this.n12=b*L+e*h+d*m+f*l;this.n13=b*p+e*s+d*t+f*x;this.n14=
  29. b*z+e*E+d*P+f*a;this.n21=g*v+k*D+j*n+i*O;this.n22=g*L+k*h+j*m+i*l;this.n23=g*p+k*s+j*t+i*x;this.n24=g*z+k*E+j*P+i*a;this.n31=o*v+w*D+c*n+u*O;this.n32=o*L+w*h+c*m+u*l;this.n33=o*p+w*s+c*t+u*x;this.n34=o*z+w*E+c*P+u*a;this.n41=y*v+B*D+C*n+K*O;this.n42=y*L+B*h+C*m+K*l;this.n43=y*p+B*s+C*t+K*x;this.n44=y*z+B*E+C*P+K*a;return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=
  30. a;this.n42*=a;this.n43*=a;this.n44*=a;return this},determinant:function(){return this.n14*this.n23*this.n32*this.n41-this.n13*this.n24*this.n32*this.n41-this.n14*this.n22*this.n33*this.n41+this.n12*this.n24*this.n33*this.n41+this.n13*this.n22*this.n34*this.n41-this.n12*this.n23*this.n34*this.n41-this.n14*this.n23*this.n31*this.n42+this.n13*this.n24*this.n31*this.n42+this.n14*this.n21*this.n33*this.n42-this.n11*this.n24*this.n33*this.n42-this.n13*this.n21*this.n34*this.n42+this.n11*this.n23*this.n34*
  31. this.n42+this.n14*this.n22*this.n31*this.n43-this.n12*this.n24*this.n31*this.n43-this.n14*this.n21*this.n32*this.n43+this.n11*this.n24*this.n32*this.n43+this.n12*this.n21*this.n34*this.n43-this.n11*this.n22*this.n34*this.n43-this.n13*this.n22*this.n31*this.n44+this.n12*this.n23*this.n31*this.n44+this.n13*this.n21*this.n32*this.n44-this.n11*this.n23*this.n32*this.n44-this.n12*this.n21*this.n33*this.n44+this.n11*this.n22*this.n33*this.n44},transpose:function(){function a(b,e,d){var f=b[e];b[e]=b[d];
  32. b[d]=f}a(this,"n21","n12");a(this,"n31","n13");a(this,"n32","n23");a(this,"n41","n14");a(this,"n42","n24");a(this,"n43","n34");return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=this.n44;return a},flatten:function(){return[this.n11,this.n21,this.n31,this.n41,this.n12,
  33. this.n22,this.n32,this.n42,this.n13,this.n23,this.n33,this.n43,this.n14,this.n24,this.n34,this.n44]},toString:function(){return"| "+this.n11+" "+this.n12+" "+this.n13+" "+this.n14+" |\n| "+this.n21+" "+this.n22+" "+this.n23+" "+this.n24+" |\n| "+this.n31+" "+this.n32+" "+this.n33+" "+this.n34+" |\n| "+this.n41+" "+this.n42+" "+this.n43+" "+this.n44+" |"}};THREE.Matrix4.translationMatrix=function(a,b,e){var d=new THREE.Matrix4;d.n14=a;d.n24=b;d.n34=e;return d};
  34. THREE.Matrix4.scaleMatrix=function(a,b,e){var d=new THREE.Matrix4;d.n11=a;d.n22=b;d.n33=e;return d};THREE.Matrix4.rotationXMatrix=function(a){var b=new THREE.Matrix4;b.n22=b.n33=Math.cos(a);b.n32=Math.sin(a);b.n23=-b.n32;return b};THREE.Matrix4.rotationYMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n33=Math.cos(a);b.n13=Math.sin(a);b.n31=-b.n13;return b};THREE.Matrix4.rotationZMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n22=Math.cos(a);b.n21=Math.sin(a);b.n12=-b.n21;return b};
  35. THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var e=new THREE.Matrix4,d=Math.cos(b),f=Math.sin(b),g=1-d,k=a.x,j=a.y,i=a.z;e.n11=g*k*k+d;e.n12=g*k*j-f*i;e.n13=g*k*i+f*j;e.n21=g*k*j+f*i;e.n22=g*j*j+d;e.n23=g*j*i-f*k;e.n31=g*k*i-f*j;e.n32=g*j*i+f*k;e.n33=g*i*i+d;return e};
  36. THREE.Matrix4.makeInvert=function(a){var b=new THREE.Matrix4;b.n11=a.n23*a.n34*a.n42-a.n24*a.n33*a.n42+a.n24*a.n32*a.n43-a.n22*a.n34*a.n43-a.n23*a.n32*a.n44+a.n22*a.n33*a.n44;b.n12=a.n14*a.n33*a.n42-a.n13*a.n34*a.n42-a.n14*a.n32*a.n43+a.n12*a.n34*a.n43+a.n13*a.n32*a.n44-a.n12*a.n33*a.n44;b.n13=a.n13*a.n24*a.n42-a.n14*a.n23*a.n42+a.n14*a.n22*a.n43-a.n12*a.n24*a.n43-a.n13*a.n22*a.n44+a.n12*a.n23*a.n44;b.n14=a.n14*a.n23*a.n32-a.n13*a.n24*a.n32-a.n14*a.n22*a.n33+a.n12*a.n24*a.n33+a.n13*a.n22*a.n34-a.n12*
  37. a.n23*a.n34;b.n21=a.n24*a.n33*a.n41-a.n23*a.n34*a.n41-a.n24*a.n31*a.n43+a.n21*a.n34*a.n43+a.n23*a.n31*a.n44-a.n21*a.n33*a.n44;b.n22=a.n13*a.n34*a.n41-a.n14*a.n33*a.n41+a.n14*a.n31*a.n43-a.n11*a.n34*a.n43-a.n13*a.n31*a.n44+a.n11*a.n33*a.n44;b.n23=a.n14*a.n23*a.n41-a.n13*a.n24*a.n41-a.n14*a.n21*a.n43+a.n11*a.n24*a.n43+a.n13*a.n21*a.n44-a.n11*a.n23*a.n44;b.n24=a.n13*a.n24*a.n31-a.n14*a.n23*a.n31+a.n14*a.n21*a.n33-a.n11*a.n24*a.n33-a.n13*a.n21*a.n34+a.n11*a.n23*a.n34;b.n31=a.n22*a.n34*a.n41-a.n24*a.n32*
  38. a.n41+a.n24*a.n31*a.n42-a.n21*a.n34*a.n42-a.n22*a.n31*a.n44+a.n21*a.n32*a.n44;b.n32=a.n14*a.n32*a.n41-a.n12*a.n34*a.n41-a.n14*a.n31*a.n42+a.n11*a.n34*a.n42+a.n12*a.n31*a.n44-a.n11*a.n32*a.n44;b.n33=a.n13*a.n24*a.n41-a.n14*a.n22*a.n41+a.n14*a.n21*a.n42-a.n11*a.n24*a.n42-a.n12*a.n21*a.n44+a.n11*a.n22*a.n44;b.n34=a.n14*a.n22*a.n31-a.n12*a.n24*a.n31-a.n14*a.n21*a.n32+a.n11*a.n24*a.n32+a.n12*a.n21*a.n34-a.n11*a.n22*a.n34;b.n41=a.n23*a.n32*a.n41-a.n22*a.n33*a.n41-a.n23*a.n31*a.n42+a.n21*a.n33*a.n42+a.n22*
  39. a.n31*a.n43-a.n21*a.n32*a.n43;b.n42=a.n12*a.n33*a.n41-a.n13*a.n32*a.n41+a.n13*a.n31*a.n42-a.n11*a.n33*a.n42-a.n12*a.n31*a.n43+a.n11*a.n32*a.n43;b.n43=a.n13*a.n22*a.n41-a.n12*a.n23*a.n41-a.n13*a.n21*a.n42+a.n11*a.n23*a.n42+a.n12*a.n21*a.n43-a.n11*a.n22*a.n43;b.n44=a.n12*a.n23*a.n31-a.n13*a.n22*a.n31+a.n13*a.n21*a.n32-a.n11*a.n23*a.n32-a.n12*a.n21*a.n33+a.n11*a.n22*a.n33;b.multiplyScalar(1/a.determinant());return b};
  40. THREE.Matrix4.makeInvert3x3=function(a){var b=a.flatten();a=new THREE.Matrix3;var e=b[10]*b[5]-b[6]*b[9],d=-b[10]*b[1]+b[2]*b[9],f=b[6]*b[1]-b[2]*b[5],g=-b[10]*b[4]+b[6]*b[8],k=b[10]*b[0]-b[2]*b[8],j=-b[6]*b[0]+b[2]*b[4],i=b[9]*b[4]-b[5]*b[8],o=-b[9]*b[0]+b[1]*b[8],w=b[5]*b[0]-b[1]*b[4];b=b[0]*e+b[1]*g+b[2]*i;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*e;a.m[1]=b*d;a.m[2]=b*f;a.m[3]=b*g;a.m[4]=b*k;a.m[5]=b*j;a.m[6]=b*i;a.m[7]=b*o;a.m[8]=b*w;return a};
  41. THREE.Matrix4.makeFrustum=function(a,b,e,d,f,g){var k,j,i;k=new THREE.Matrix4;j=2*f/(b-a);i=2*f/(d-e);a=(b+a)/(b-a);e=(d+e)/(d-e);d=-(g+f)/(g-f);f=-2*g*f/(g-f);k.n11=j;k.n12=0;k.n13=a;k.n14=0;k.n21=0;k.n22=i;k.n23=e;k.n24=0;k.n31=0;k.n32=0;k.n33=d;k.n34=f;k.n41=0;k.n42=0;k.n43=-1;k.n44=0;return k};THREE.Matrix4.makePerspective=function(a,b,e,d){var f;a=e*Math.tan(a*Math.PI/360);f=-a;return THREE.Matrix4.makeFrustum(f*b,a*b,f,a,e,d)};
  42. THREE.Matrix4.makeOrtho=function(a,b,e,d,f,g){var k,j,i,o;k=new THREE.Matrix4;j=b-a;i=e-d;o=g-f;a=(b+a)/j;e=(e+d)/i;f=(g+f)/o;k.n11=2/j;k.n12=0;k.n13=0;k.n14=-a;k.n21=0;k.n22=2/i;k.n23=0;k.n24=-e;k.n31=0;k.n32=0;k.n33=-2/o;k.n34=-f;k.n41=0;k.n42=0;k.n43=0;k.n44=1;return k};
  43. THREE.Vertex=function(a,b){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=b||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.tangent=new THREE.Vector4;this.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}};
  44. THREE.Face3=function(a,b,e,d,f){this.a=a;this.b=b;this.c=e;this.centroid=new THREE.Vector3;this.normal=d instanceof THREE.Vector3?d:new THREE.Vector3;this.vertexNormals=d instanceof Array?d:[];this.materials=f instanceof Array?f:[f]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
  45. THREE.Face4=function(a,b,e,d,f,g){this.a=a;this.b=b;this.c=e;this.d=d;this.centroid=new THREE.Vector3;this.normal=f instanceof THREE.Vector3?f:new THREE.Vector3;this.vertexNormals=f instanceof Array?f:[];this.materials=g instanceof Array?g:[g]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
  46. 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};
  47. THREE.Geometry.prototype={computeCentroids:function(){var a,b,e;a=0;for(b=this.faces.length;a<b;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);
  48. e.centroid.addSelf(this.vertices[e.d].position);e.centroid.divideScalar(4)}}},computeFaceNormals:function(a){var b,e,d,f,g,k,j=new THREE.Vector3,i=new THREE.Vector3;d=0;for(f=this.vertices.length;d<f;d++){g=this.vertices[d];g.normal.set(0,0,0)}d=0;for(f=this.faces.length;d<f;d++){g=this.faces[d];if(a&&g.vertexNormals.length){j.set(0,0,0);b=0;for(e=g.normal.length;b<e;b++)j.addSelf(g.vertexNormals[b]);j.divideScalar(3)}else{b=this.vertices[g.a];e=this.vertices[g.b];k=this.vertices[g.c];j.sub(k.position,
  49. e.position);i.sub(b.position,e.position);j.crossSelf(i)}j.isZero()||j.normalize();g.normal.copy(j)}},computeVertexNormals:function(){var a,b=[],e,d;a=0;for(vl=this.vertices.length;a<vl;a++)b[a]=new THREE.Vector3;a=0;for(e=this.faces.length;a<e;a++){d=this.faces[a];if(d instanceof THREE.Face3){b[d.a].addSelf(d.normal);b[d.b].addSelf(d.normal);b[d.c].addSelf(d.normal)}else if(d instanceof THREE.Face4){b[d.a].addSelf(d.normal);b[d.b].addSelf(d.normal);b[d.c].addSelf(d.normal);b[d.d].addSelf(d.normal)}}a=
  50. 0;for(vl=this.vertices.length;a<vl;a++)b[a].normalize();a=0;for(e=this.faces.length;a<e;a++){d=this.faces[a];if(d instanceof THREE.Face3){d.vertexNormals[0]=b[d.a].clone();d.vertexNormals[1]=b[d.b].clone();d.vertexNormals[2]=b[d.c].clone()}else if(d instanceof THREE.Face4){d.vertexNormals[0]=b[d.a].clone();d.vertexNormals[1]=b[d.b].clone();d.vertexNormals[2]=b[d.c].clone();d.vertexNormals[3]=b[d.d].clone()}}},computeTangents:function(){function a(z,E,P,N,M,Q,F){g=z.vertices[E].position;k=z.vertices[P].position;
  51. j=z.vertices[N].position;i=f[M];o=f[Q];w=f[F];c=k.x-g.x;u=j.x-g.x;y=k.y-g.y;B=j.y-g.y;C=k.z-g.z;K=j.z-g.z;v=o.u-i.u;D=w.u-i.u;n=o.v-i.v;O=w.v-i.v;L=1/(v*O-D*n);p.set((O*c-n*u)*L,(O*y-n*B)*L,(O*C-n*K)*L);s.set((v*u-D*c)*L,(v*B-D*y)*L,(v*K-D*C)*L);m[E].addSelf(p);m[P].addSelf(p);m[N].addSelf(p);l[E].addSelf(s);l[P].addSelf(s);l[N].addSelf(s)}var b,e,d,f,g,k,j,i,o,w,c,u,y,B,C,K,v,D,n,O,L,h,m=[],l=[],p=new THREE.Vector3,s=new THREE.Vector3,t=new THREE.Vector3,x=new THREE.Vector3;h=new THREE.Vector3;b=
  52. 0;for(e=this.vertices.length;b<e;b++){m[b]=new THREE.Vector3;l[b]=new THREE.Vector3}b=0;for(e=this.faces.length;b<e;b++){d=this.faces[b];f=this.uvs[b];if(d instanceof THREE.Face3){a(this,d.a,d.b,d.c,0,1,2);this.vertices[d.a].normal.copy(d.vertexNormals[0]);this.vertices[d.b].normal.copy(d.vertexNormals[1]);this.vertices[d.c].normal.copy(d.vertexNormals[2])}else if(d instanceof THREE.Face4){a(this,d.a,d.b,d.c,0,1,2);a(this,d.a,d.b,d.d,0,1,3);this.vertices[d.a].normal.copy(d.vertexNormals[0]);this.vertices[d.b].normal.copy(d.vertexNormals[1]);
  53. this.vertices[d.c].normal.copy(d.vertexNormals[2]);this.vertices[d.d].normal.copy(d.vertexNormals[3])}}b=0;for(e=this.vertices.length;b<e;b++){h.copy(this.vertices[b].normal);d=m[b];t.copy(d);t.subSelf(h.multiplyScalar(h.dot(d))).normalize();x.cross(this.vertices[b].normal,d);test=x.dot(l[b]);d=test<0?-1:1;this.vertices[b].tangent.set(t.x,t.y,t.z,d)}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],
  54. y:[this.vertices[0].position.y,this.vertices[0].position.y],z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var b=1,e=this.vertices.length;b<e;b++){a=this.vertices[b];if(a.position.x<this.boundingBox.x[0])this.boundingBox.x[0]=a.position.x;else if(a.position.x>this.boundingBox.x[1])this.boundingBox.x[1]=a.position.x;if(a.position.y<this.boundingBox.y[0])this.boundingBox.y[0]=a.position.y;else if(a.position.y>this.boundingBox.y[1])this.boundingBox.y[1]=a.position.y;if(a.position.z<
  55. this.boundingBox.z[0])this.boundingBox.z[0]=a.position.z;else if(a.position.z>this.boundingBox.z[1])this.boundingBox.z[1]=a.position.z}}},computeBoundingSphere:function(){for(var a=this.boundingSphere===null?0:this.boundingSphere.radius,b=0,e=this.vertices.length;b<e;b++)a=Math.max(a,this.vertices[b].position.length());this.boundingSphere={radius:a}},sortFacesByMaterial:function(){function a(o){var w=[];b=0;for(e=o.length;b<e;b++)o[b]==undefined?w.push("undefined"):w.push(o[b].toString());return w.join("_")}
  56. var b,e,d,f,g,k,j,i={};d=0;for(f=this.faces.length;d<f;d++){g=this.faces[d];materials=g.materials;k=a(materials);if(i[k]==undefined)i[k]={hash:k,counter:0};j=i[k].hash+"_"+i[k].counter;if(this.geometryChunks[j]==undefined)this.geometryChunks[j]={faces:[],materials:materials,vertices:0};g=g instanceof THREE.Face3?3:4;if(this.geometryChunks[j].vertices+g>65535){i[k].counter+=1;j=i[k].hash+"_"+i[k].counter;if(this.geometryChunks[j]==undefined)this.geometryChunks[j]={faces:[],materials:materials,vertices:0}}this.geometryChunks[j].faces.push(d);
  57. this.geometryChunks[j].vertices+=g}},toString:function(){return"THREE.Geometry ( vertices: "+this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
  58. THREE.Camera=function(a,b,e,d){this.fov=a;this.aspect=b;this.near=e;this.far=d;this.position=new THREE.Vector3;this.target={position:new THREE.Vector3};this.autoUpdateMatrix=true;this.projectionMatrix=null;this.matrix=new THREE.Matrix4;this.up=new THREE.Vector3(0,1,0);this.translateX=function(f){f=this.target.position.clone().subSelf(this.position).normalize().multiplyScalar(f);f.cross(f.clone(),this.up);this.position.addSelf(f);this.target.position.addSelf(f)};this.translateZ=function(f){f=this.target.position.clone().subSelf(this.position).normalize().multiplyScalar(f);
  59. this.position.subSelf(f);this.target.position.subSelf(f)};this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.updateProjectionMatrix=function(){this.projectionMatrix=THREE.Matrix4.makePerspective(this.fov,this.aspect,this.near,this.far)};this.updateProjectionMatrix()};THREE.Camera.prototype={toString:function(){return"THREE.Camera ( "+this.position+", "+this.target.position+" )"}};THREE.Light=function(a){this.color=new THREE.Color(a)};
  60. THREE.AmbientLight=function(a){THREE.Light.call(this,a)};THREE.AmbientLight.prototype=new THREE.Light;THREE.AmbientLight.prototype.constructor=THREE.AmbientLight;THREE.DirectionalLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,1,0);this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.DirectionalLight;
  61. THREE.PointLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3;this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.PointLight;
  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.translationMatrix=new THREE.Matrix4;this.rotationMatrix=new THREE.Matrix4;this.scaleMatrix=new THREE.Matrix4;this.screen=new THREE.Vector3;this.visible=this.autoUpdateMatrix=true};
  63. THREE.Object3D.prototype={updateMatrix:function(){this.matrixPosition=THREE.Matrix4.translationMatrix(this.position.x,this.position.y,this.position.z);this.rotationMatrix=THREE.Matrix4.rotationXMatrix(this.rotation.x);this.rotationMatrix.multiplySelf(THREE.Matrix4.rotationYMatrix(this.rotation.y));this.rotationMatrix.multiplySelf(THREE.Matrix4.rotationZMatrix(this.rotation.z));this.scaleMatrix=THREE.Matrix4.scaleMatrix(this.scale.x,this.scale.y,this.scale.z);this.matrix.copy(this.matrixPosition);
  64. this.matrix.multiplySelf(this.rotationMatrix);this.matrix.multiplySelf(this.scaleMatrix)}};THREE.Object3DCounter={value:0};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.Line=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.materials=b instanceof Array?b:[b]};THREE.Line.prototype=new THREE.Object3D;
  65. THREE.Line.prototype.constructor=THREE.Line;THREE.Mesh=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.materials=b instanceof Array?b:[b];this.overdraw=this.doubleSided=this.flipSided=false;this.geometry.boundingSphere||this.geometry.computeBoundingSphere()};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;
  66. 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}};
  67. 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/>)"}};
  68. 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=
  69. 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!==
  70. 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}};
  71. 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+
  72. "<br/>wireframe_linejoin: "+this.wireframe_linejoin+"<br/>)"}};THREE.MeshBasicMaterialCounter={value:0};
  73. 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=
  74. 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!==
  75. 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}};
  76. 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: "+
  77. this.wireframe_linecap+"<br/>wireframe_linejoin: "+this.wireframe_linejoin+"<br/> )"}};THREE.MeshLambertMaterialCounter={value:0};
  78. 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=
  79. 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=
  80. 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!==
  81. undefined)this.wireframe_linejoin=a.wireframe_linejoin}};
  82. 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: "+
  83. 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};
  84. 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"}};
  85. 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"}};
  86. 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!==
  87. 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}};
  88. 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};
  89. 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}};
  90. 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}};
  91. 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+" )"}};
  92. THREE.Texture=function(a,b,e,d,f,g){this.image=a;this.mapping=b!==undefined?b:new THREE.UVMapping;this.wrap_s=e!==undefined?e:THREE.ClampToEdgeWrapping;this.wrap_t=d!==undefined?d:THREE.ClampToEdgeWrapping;this.mag_filter=f!==undefined?f:THREE.LinearFilter;this.min_filter=g!==undefined?g:THREE.LinearMipMapLinearFilter};
  93. 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;
  94. THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLinearFilter=5;THREE.LinearFilter=6;THREE.LinearMipMapNearestFilter=7;THREE.LinearMipMapLinearFilter=8;var Uniforms={clone:function(a){var b,e,d={};for(b in a){d[b]={};for(e in a[b]){parameter_src=a[b][e];d[b][e]=parameter_src instanceof THREE.Color||parameter_src instanceof THREE.Vector3||parameter_src instanceof THREE.Texture?parameter_src.clone():parameter_src}}return d}};THREE.CubeReflectionMapping=function(){};
  95. THREE.CubeRefractionMapping=function(){};THREE.LatitudeReflectionMapping=function(){};THREE.LatitudeRefractionMapping=function(){};THREE.SphericalReflectionMapping=function(){};THREE.SphericalRefractionMapping=function(){};THREE.UVMapping=function(){};
  96. 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+" )"}};
  97. THREE.Fog=function(a,b,e){this.color=new THREE.Color(a);this.near=b||1;this.far=e||1E3};THREE.FogExp2=function(a,b){this.color=new THREE.Color(a);this.density=b||2.5E-4};
  98. THREE.Projector=function(){function a(m,l){return l.z-m.z}function b(m,l){var p=0,s=1,t=m.z+m.w,x=l.z+l.w,z=-m.z+m.w,E=-l.z+l.w;if(t>=0&&x>=0&&z>=0&&E>=0)return true;else if(t<0&&x<0||z<0&&E<0)return false;else{if(t<0)p=Math.max(p,t/(t-x));else if(x<0)s=Math.min(s,t/(t-x));if(z<0)p=Math.max(p,z/(z-E));else if(E<0)s=Math.min(s,z/(z-E));if(s<p)return false;else{m.lerpSelf(l,p);l.lerpSelf(m,1-s);return true}}}var e,d,f=[],g,k,j,i=[],o,w,c=[],u,y,B=[],C=new THREE.Vector4,K=new THREE.Vector4,v=new THREE.Matrix4,
  99. D=new THREE.Matrix4,n=[],O=new THREE.Vector4,L=new THREE.Vector4,h;this.projectObjects=function(m,l,p){var s=[],t,x;d=0;v.multiply(l.projectionMatrix,l.matrix);n[0]=new THREE.Vector4(v.n41-v.n11,v.n42-v.n12,v.n43-v.n13,v.n44-v.n14);n[1]=new THREE.Vector4(v.n41+v.n11,v.n42+v.n12,v.n43+v.n13,v.n44+v.n14);n[2]=new THREE.Vector4(v.n41+v.n21,v.n42+v.n22,v.n43+v.n23,v.n44+v.n24);n[3]=new THREE.Vector4(v.n41-v.n21,v.n42-v.n22,v.n43-v.n23,v.n44-v.n24);n[4]=new THREE.Vector4(v.n41-v.n31,v.n42-v.n32,v.n43-
  100. v.n33,v.n44-v.n34);n[5]=new THREE.Vector4(v.n41+v.n31,v.n42+v.n32,v.n43+v.n33,v.n44+v.n34);l=0;for(t=n.length;l<t;l++){x=n[l];x.divideScalar(Math.sqrt(x.x*x.x+x.y*x.y+x.z*x.z))}t=m.objects;m=0;for(l=t.length;m<l;m++){x=t[m];var z;if(!(z=!x.visible)){if(z=x instanceof THREE.Mesh){a:{z=void 0;for(var E=x.position,P=-x.geometry.boundingSphere.radius*Math.max(x.scale.x,Math.max(x.scale.y,x.scale.z)),N=0;N<6;N++){z=n[N].x*E.x+n[N].y*E.y+n[N].z*E.z+n[N].w;if(z<=P){z=false;break a}}z=true}z=!z}z=z}if(!z){e=
  101. f[d]=f[d]||new THREE.RenderableObject;C.copy(x.position);v.multiplyVector3(C);e.object=x;e.z=C.z;s.push(e);d++}}p&&s.sort(a);return s};this.projectScene=function(m,l,p){var s=[],t=l.near,x=l.far,z,E,P,N,M,Q,F,W,Y,S,H,R,q,r,A,I;j=w=y=0;l.autoUpdateMatrix&&l.updateMatrix();v.multiply(l.projectionMatrix,l.matrix);Q=this.projectObjects(m,l,true);m=0;for(z=Q.length;m<z;m++){F=Q[m].object;if(F.visible){F.autoUpdateMatrix&&F.updateMatrix();W=F.matrix;Y=F.rotationMatrix;S=F.materials;H=F.overdraw;if(F instanceof
  102. THREE.Mesh){R=F.geometry;q=R.vertices;E=0;for(P=q.length;E<P;E++){r=q[E];r.positionWorld.copy(r.position);W.multiplyVector3(r.positionWorld);N=r.positionScreen;N.copy(r.positionWorld);v.multiplyVector4(N);N.x/=N.w;N.y/=N.w;r.__visible=N.z>t&&N.z<x}R=R.faces;E=0;for(P=R.length;E<P;E++){r=R[E];if(r instanceof THREE.Face3){N=q[r.a];M=q[r.b];A=q[r.c];if(N.__visible&&M.__visible&&A.__visible)if(F.doubleSided||F.flipSided!=(A.positionScreen.x-N.positionScreen.x)*(M.positionScreen.y-N.positionScreen.y)-
  103. (A.positionScreen.y-N.positionScreen.y)*(M.positionScreen.x-N.positionScreen.x)<0){g=i[j]=i[j]||new THREE.RenderableFace3;g.v1.positionWorld.copy(N.positionWorld);g.v2.positionWorld.copy(M.positionWorld);g.v3.positionWorld.copy(A.positionWorld);g.v1.positionScreen.copy(N.positionScreen);g.v2.positionScreen.copy(M.positionScreen);g.v3.positionScreen.copy(A.positionScreen);g.normalWorld.copy(r.normal);Y.multiplyVector3(g.normalWorld);g.centroidWorld.copy(r.centroid);W.multiplyVector3(g.centroidWorld);
  104. g.centroidScreen.copy(g.centroidWorld);v.multiplyVector3(g.centroidScreen);A=r.vertexNormals;h=g.vertexNormalsWorld;N=0;for(M=A.length;N<M;N++){I=h[N]=h[N]||new THREE.Vector3;I.copy(A[N]);Y.multiplyVector3(I)}g.z=g.centroidScreen.z;g.meshMaterials=S;g.faceMaterials=r.materials;g.overdraw=H;if(F.geometry.uvs[E]){g.uvs[0]=F.geometry.uvs[E][0];g.uvs[1]=F.geometry.uvs[E][1];g.uvs[2]=F.geometry.uvs[E][2]}s.push(g);j++}}else if(r instanceof THREE.Face4){N=q[r.a];M=q[r.b];A=q[r.c];I=q[r.d];if(N.__visible&&
  105. M.__visible&&A.__visible&&I.__visible)if(F.doubleSided||F.flipSided!=((I.positionScreen.x-N.positionScreen.x)*(M.positionScreen.y-N.positionScreen.y)-(I.positionScreen.y-N.positionScreen.y)*(M.positionScreen.x-N.positionScreen.x)<0||(M.positionScreen.x-A.positionScreen.x)*(I.positionScreen.y-A.positionScreen.y)-(M.positionScreen.y-A.positionScreen.y)*(I.positionScreen.x-A.positionScreen.x)<0)){g=i[j]=i[j]||new THREE.RenderableFace3;g.v1.positionWorld.copy(N.positionWorld);g.v2.positionWorld.copy(M.positionWorld);
  106. g.v3.positionWorld.copy(I.positionWorld);g.v1.positionScreen.copy(N.positionScreen);g.v2.positionScreen.copy(M.positionScreen);g.v3.positionScreen.copy(I.positionScreen);g.normalWorld.copy(r.normal);Y.multiplyVector3(g.normalWorld);g.centroidWorld.copy(r.centroid);W.multiplyVector3(g.centroidWorld);g.centroidScreen.copy(g.centroidWorld);v.multiplyVector3(g.centroidScreen);g.z=g.centroidScreen.z;g.meshMaterials=S;g.faceMaterials=r.materials;g.overdraw=H;if(F.geometry.uvs[E]){g.uvs[0]=F.geometry.uvs[E][0];
  107. g.uvs[1]=F.geometry.uvs[E][1];g.uvs[2]=F.geometry.uvs[E][3]}s.push(g);j++;k=i[j]=i[j]||new THREE.RenderableFace3;k.v1.positionWorld.copy(M.positionWorld);k.v2.positionWorld.copy(A.positionWorld);k.v3.positionWorld.copy(I.positionWorld);k.v1.positionScreen.copy(M.positionScreen);k.v2.positionScreen.copy(A.positionScreen);k.v3.positionScreen.copy(I.positionScreen);k.normalWorld.copy(g.normalWorld);k.centroidWorld.copy(g.centroidWorld);k.centroidScreen.copy(g.centroidScreen);k.z=k.centroidScreen.z;k.meshMaterials=
  108. S;k.faceMaterials=r.materials;k.overdraw=H;if(F.geometry.uvs[E]){k.uvs[0]=F.geometry.uvs[E][1];k.uvs[1]=F.geometry.uvs[E][2];k.uvs[2]=F.geometry.uvs[E][3]}s.push(k);j++}}}}else if(F instanceof THREE.Line){D.multiply(v,W);q=F.geometry.vertices;r=q[0];r.positionScreen.copy(r.position);D.multiplyVector4(r.positionScreen);E=1;for(P=q.length;E<P;E++){N=q[E];N.positionScreen.copy(N.position);D.multiplyVector4(N.positionScreen);M=q[E-1];O.copy(N.positionScreen);L.copy(M.positionScreen);if(b(O,L)){O.multiplyScalar(1/
  109. O.w);L.multiplyScalar(1/L.w);o=c[w]=c[w]||new THREE.RenderableLine;o.v1.positionScreen.copy(O);o.v2.positionScreen.copy(L);o.z=Math.max(O.z,L.z);o.materials=F.materials;s.push(o);w++}}}else if(F instanceof THREE.Particle){K.set(F.position.x,F.position.y,F.position.z,1);v.multiplyVector4(K);K.z/=K.w;if(K.z>0&&K.z<1){u=B[y]=B[y]||new THREE.RenderableParticle;u.x=K.x/K.w;u.y=K.y/K.w;u.z=K.z;u.rotation=F.rotation.z;u.scale.x=F.scale.x*Math.abs(u.x-(K.x+l.projectionMatrix.n11)/(K.w+l.projectionMatrix.n14));
  110. u.scale.y=F.scale.y*Math.abs(u.y-(K.y+l.projectionMatrix.n22)/(K.w+l.projectionMatrix.n24));u.materials=F.materials;s.push(u);y++}}}}p&&s.sort(a);return s};this.unprojectVector=function(m,l){var p=new THREE.Matrix4;p.multiply(THREE.Matrix4.makeInvert(l.matrix),THREE.Matrix4.makeInvert(l.projectionMatrix));p.multiplyVector3(m);return m}};
  111. THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,e,d,f,g;this.domElement=document.createElement("div");this.setSize=function(k,j){e=k;d=j;f=e/2;g=d/2};this.render=function(k,j){var i,o,w,c,u,y,B,C;a=b.projectScene(k,j);i=0;for(o=a.length;i<o;i++){u=a[i];if(u instanceof THREE.RenderableParticle){B=u.x*f+f;C=u.y*g+g;w=0;for(c=u.material.length;w<c;w++){y=u.material[w];if(y instanceof THREE.ParticleDOMMaterial){y=y.domElement;y.style.left=B+"px";y.style.top=C+"px"}}}}}};
  112. THREE.CanvasRenderer=function(){function a(da){if(u!=da)o.globalAlpha=u=da}function b(da){if(y!=da){switch(da){case THREE.NormalBlending:o.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:o.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:o.globalCompositeOperation="darker"}y=da}}var e=null,d=new THREE.Projector,f=document.createElement("canvas"),g,k,j,i,o=f.getContext("2d"),w=null,c=null,u=1,y=0,B=null,C=null,K=1,v,D,n,O,L,h,m,l,p,s=new THREE.Color,
  113. t=new THREE.Color,x=new THREE.Color,z=new THREE.Color,E=new THREE.Color,P,N,M,Q,F,W,Y,S,H,R=new THREE.Rectangle,q=new THREE.Rectangle,r=new THREE.Rectangle,A=false,I=new THREE.Color,V=new THREE.Color,ba=new THREE.Color,fa=new THREE.Color,xa=Math.PI*2,$=new THREE.Vector3,ra,sa,Da,ha,ta,ya,pa=16;ra=document.createElement("canvas");ra.width=ra.height=2;sa=ra.getContext("2d");sa.fillStyle="rgba(0,0,0,1)";sa.fillRect(0,0,2,2);Da=sa.getImageData(0,0,2,2);ha=Da.data;ta=document.createElement("canvas");ta.width=
  114. ta.height=pa;ya=ta.getContext("2d");ya.translate(-pa/2,-pa/2);ya.scale(pa,pa);pa--;this.domElement=f;this.sortElements=this.sortObjects=this.autoClear=true;this.setSize=function(da,na){g=da;k=na;j=g/2;i=k/2;f.width=g;f.height=k;R.set(-j,-i,j,i)};this.setClearColor=function(da,na){w=da!==null?new THREE.Color(da):null;c=na;q.set(-j,-i,j,i);o.setTransform(1,0,0,-1,j,i);this.clear()};this.clear=function(){if(!q.isEmpty()){q.inflate(1);q.minSelf(R);if(w!==null){b(THREE.NormalBlending);a(1);o.fillStyle=
  115. "rgba("+Math.floor(w.r*255)+","+Math.floor(w.g*255)+","+Math.floor(w.b*255)+","+c+")";o.fillRect(q.getX(),q.getY(),q.getWidth(),q.getHeight())}else o.clearRect(q.getX(),q.getY(),q.getWidth(),q.getHeight());q.empty()}};this.render=function(da,na){function Ma(G){var X,U,J,T=G.lights;V.setRGB(0,0,0);ba.setRGB(0,0,0);fa.setRGB(0,0,0);G=0;for(X=T.length;G<X;G++){U=T[G];J=U.color;if(U instanceof THREE.AmbientLight){V.r+=J.r;V.g+=J.g;V.b+=J.b}else if(U instanceof THREE.DirectionalLight){ba.r+=J.r;ba.g+=
  116. J.g;ba.b+=J.b}else if(U instanceof THREE.PointLight){fa.r+=J.r;fa.g+=J.g;fa.b+=J.b}}}function za(G,X,U,J){var T,Z,ca,ea,ga=G.lights;G=0;for(T=ga.length;G<T;G++){Z=ga[G];ca=Z.color;ea=Z.intensity;if(Z instanceof THREE.DirectionalLight){Z=U.dot(Z.position)*ea;if(Z>0){J.r+=ca.r*Z;J.g+=ca.g*Z;J.b+=ca.b*Z}}else if(Z instanceof THREE.PointLight){$.sub(Z.position,X);$.normalize();Z=U.dot($)*ea;if(Z>0){J.r+=ca.r*Z;J.g+=ca.g*Z;J.b+=ca.b*Z}}}}function Na(G,X,U){if(U.opacity!=0){a(U.opacity);b(U.blending);var J,
  117. T,Z,ca,ea,ga;if(U instanceof THREE.ParticleBasicMaterial){if(U.map){ca=U.map;ea=ca.width>>1;ga=ca.height>>1;T=X.scale.x*j;Z=X.scale.y*i;U=T*ea;J=Z*ga;r.set(G.x-U,G.y-J,G.x+U,G.y+J);if(R.instersects(r)){o.save();o.translate(G.x,G.y);o.rotate(-X.rotation);o.scale(T,-Z);o.translate(-ea,-ga);o.drawImage(ca,0,0);o.restore()}}}else if(U instanceof THREE.ParticleCircleMaterial){if(A){I.r=V.r+ba.r+fa.r;I.g=V.g+ba.g+fa.g;I.b=V.b+ba.b+fa.b;s.r=U.color.r*I.r;s.g=U.color.g*I.g;s.b=U.color.b*I.b;s.updateStyleString()}else s.__styleString=
  118. U.color.__styleString;U=X.scale.x*j;J=X.scale.y*i;r.set(G.x-U,G.y-J,G.x+U,G.y+J);if(R.instersects(r)){T=s.__styleString;if(C!=T)o.fillStyle=C=T;o.save();o.translate(G.x,G.y);o.rotate(-X.rotation);o.scale(U,J);o.beginPath();o.arc(0,0,1,0,xa,true);o.closePath();o.fill();o.restore()}}}}function Oa(G,X,U,J){if(J.opacity!=0){a(J.opacity);b(J.blending);o.beginPath();o.moveTo(G.positionScreen.x,G.positionScreen.y);o.lineTo(X.positionScreen.x,X.positionScreen.y);o.closePath();if(J instanceof THREE.LineBasicMaterial){s.__styleString=
  119. J.color.__styleString;G=J.linewidth;if(K!=G)o.lineWidth=K=G;G=s.__styleString;if(B!=G)o.strokeStyle=B=G;o.stroke();r.inflate(J.linewidth*2)}}}function Ia(G,X,U,J,T,Z){if(T.opacity!=0){a(T.opacity);b(T.blending);O=G.positionScreen.x;L=G.positionScreen.y;h=X.positionScreen.x;m=X.positionScreen.y;l=U.positionScreen.x;p=U.positionScreen.y;o.beginPath();o.moveTo(O,L);o.lineTo(h,m);o.lineTo(l,p);o.lineTo(O,L);o.closePath();if(T instanceof THREE.MeshBasicMaterial)if(T.map)T.map.image.loaded&&T.map.mapping instanceof
  120. THREE.UVMapping&&ua(O,L,h,m,l,p,T.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(T.env_map){if(T.env_map.image.loaded)if(T.env_map.mapping instanceof THREE.SphericalReflectionMapping){G=na.matrix;$.copy(J.vertexNormalsWorld[0]);Q=($.x*G.n11+$.y*G.n12+$.z*G.n13)*0.5+0.5;F=-($.x*G.n21+$.y*G.n22+$.z*G.n23)*0.5+0.5;$.copy(J.vertexNormalsWorld[1]);W=($.x*G.n11+$.y*G.n12+$.z*G.n13)*0.5+0.5;Y=-($.x*G.n21+$.y*G.n22+$.z*G.n23)*0.5+0.5;$.copy(J.vertexNormalsWorld[2]);S=
  121. ($.x*G.n11+$.y*G.n12+$.z*G.n13)*0.5+0.5;H=-($.x*G.n21+$.y*G.n22+$.z*G.n23)*0.5+0.5;ua(O,L,h,m,l,p,T.env_map.image,Q,F,W,Y,S,H)}}else T.wireframe?Aa(T.color.__styleString,T.wireframe_linewidth):Ba(T.color.__styleString);else if(T instanceof THREE.MeshLambertMaterial){if(T.map&&!T.wireframe){T.map.mapping instanceof THREE.UVMapping&&ua(O,L,h,m,l,p,T.map.image,J.uvs[0].u,J.uvs[0].v,J.uvs[1].u,J.uvs[1].v,J.uvs[2].u,J.uvs[2].v);b(THREE.SubtractiveBlending)}if(A)if(!T.wireframe&&T.shading==THREE.SmoothShading&&
  122. J.vertexNormalsWorld.length==3){t.r=x.r=z.r=V.r;t.g=x.g=z.g=V.g;t.b=x.b=z.b=V.b;za(Z,J.v1.positionWorld,J.vertexNormalsWorld[0],t);za(Z,J.v2.positionWorld,J.vertexNormalsWorld[1],x);za(Z,J.v3.positionWorld,J.vertexNormalsWorld[2],z);E.r=(x.r+z.r)*0.5;E.g=(x.g+z.g)*0.5;E.b=(x.b+z.b)*0.5;M=Ja(t,x,z,E);ua(O,L,h,m,l,p,M,0,0,1,0,0,1)}else{I.r=V.r;I.g=V.g;I.b=V.b;za(Z,J.centroidWorld,J.normalWorld,I);s.r=T.color.r*I.r;s.g=T.color.g*I.g;s.b=T.color.b*I.b;s.updateStyleString();T.wireframe?Aa(s.__styleString,
  123. T.wireframe_linewidth):Ba(s.__styleString)}else T.wireframe?Aa(T.color.__styleString,T.wireframe_linewidth):Ba(T.color.__styleString)}else if(T instanceof THREE.MeshDepthMaterial){P=na.near;N=na.far;t.r=t.g=t.b=1-Ea(G.positionScreen.z,P,N);x.r=x.g=x.b=1-Ea(X.positionScreen.z,P,N);z.r=z.g=z.b=1-Ea(U.positionScreen.z,P,N);E.r=(x.r+z.r)*0.5;E.g=(x.g+z.g)*0.5;E.b=(x.b+z.b)*0.5;M=Ja(t,x,z,E);ua(O,L,h,m,l,p,M,0,0,1,0,0,1)}else if(T instanceof THREE.MeshNormalMaterial){s.r=Fa(J.normalWorld.x);s.g=Fa(J.normalWorld.y);
  124. s.b=Fa(J.normalWorld.z);s.updateStyleString();T.wireframe?Aa(s.__styleString,T.wireframe_linewidth):Ba(s.__styleString)}}}function Aa(G,X){if(B!=G)o.strokeStyle=B=G;if(K!=X)o.lineWidth=K=X;o.stroke();r.inflate(X*2)}function Ba(G){if(C!=G)o.fillStyle=C=G;o.fill()}function ua(G,X,U,J,T,Z,ca,ea,ga,ka,ia,la,va){var oa,ma;oa=ca.width-1;ma=ca.height-1;ea*=oa;ga*=ma;ka*=oa;ia*=ma;la*=oa;va*=ma;U-=G;J-=X;T-=G;Z-=X;ka-=ea;ia-=ga;la-=ea;va-=ga;ma=1/(ka*va-la*ia);oa=(va*U-ia*T)*ma;ia=(va*J-ia*Z)*ma;U=(ka*T-
  125. la*U)*ma;J=(ka*Z-la*J)*ma;G=G-oa*ea-U*ga;X=X-ia*ea-J*ga;o.save();o.transform(oa,ia,U,J,G,X);o.clip();o.drawImage(ca,0,0);o.restore()}function Ja(G,X,U,J){var T=~~(G.r*255),Z=~~(G.g*255);G=~~(G.b*255);var ca=~~(X.r*255),ea=~~(X.g*255);X=~~(X.b*255);var ga=~~(U.r*255),ka=~~(U.g*255);U=~~(U.b*255);var ia=~~(J.r*255),la=~~(J.g*255);J=~~(J.b*255);ha[0]=T<0?0:T>255?255:T;ha[1]=Z<0?0:Z>255?255:Z;ha[2]=G<0?0:G>255?255:G;ha[4]=ca<0?0:ca>255?255:ca;ha[5]=ea<0?0:ea>255?255:ea;ha[6]=X<0?0:X>255?255:X;ha[8]=ga<
  126. 0?0:ga>255?255:ga;ha[9]=ka<0?0:ka>255?255:ka;ha[10]=U<0?0:U>255?255:U;ha[12]=ia<0?0:ia>255?255:ia;ha[13]=la<0?0:la>255?255:la;ha[14]=J<0?0:J>255?255:J;sa.putImageData(Da,0,0);ya.drawImage(ra,0,0);return ta}function Ea(G,X,U){G=(G-X)/(U-X);return G*G*(3-2*G)}function Fa(G){G=(G+1)*0.5;return G<0?0:G>1?1:G}function Ga(G,X){var U=X.x-G.x,J=X.y-G.y,T=1/Math.sqrt(U*U+J*J);U*=T;J*=T;X.x+=U;X.y+=J;G.x-=U;G.y-=J}var Ca,Ka,aa,ja,qa,Ha,La,wa;o.setTransform(1,0,0,-1,j,i);this.autoClear&&this.clear();e=d.projectScene(da,
  127. na,this.sortElements);(A=da.lights.length>0)&&Ma(da);Ca=0;for(Ka=e.length;Ca<Ka;Ca++){aa=e[Ca];r.empty();if(aa instanceof THREE.RenderableParticle){v=aa;v.x*=j;v.y*=i;ja=0;for(qa=aa.materials.length;ja<qa;ja++)Na(v,aa,aa.materials[ja],da)}else if(aa instanceof THREE.RenderableLine){v=aa.v1;D=aa.v2;v.positionScreen.x*=j;v.positionScreen.y*=i;D.positionScreen.x*=j;D.positionScreen.y*=i;r.addPoint(v.positionScreen.x,v.positionScreen.y);r.addPoint(D.positionScreen.x,D.positionScreen.y);if(R.instersects(r)){ja=
  128. 0;for(qa=aa.materials.length;ja<qa;)Oa(v,D,aa,aa.materials[ja++],da)}}else if(aa instanceof THREE.RenderableFace3){v=aa.v1;D=aa.v2;n=aa.v3;v.positionScreen.x*=j;v.positionScreen.y*=i;D.positionScreen.x*=j;D.positionScreen.y*=i;n.positionScreen.x*=j;n.positionScreen.y*=i;if(aa.overdraw){Ga(v.positionScreen,D.positionScreen);Ga(D.positionScreen,n.positionScreen);Ga(n.positionScreen,v.positionScreen)}r.add3Points(v.positionScreen.x,v.positionScreen.y,D.positionScreen.x,D.positionScreen.y,n.positionScreen.x,
  129. n.positionScreen.y);if(R.instersects(r)){ja=0;for(qa=aa.meshMaterials.length;ja<qa;){wa=aa.meshMaterials[ja++];if(wa instanceof THREE.MeshFaceMaterial){Ha=0;for(La=aa.faceMaterials.length;Ha<La;)(wa=aa.faceMaterials[Ha++])&&Ia(v,D,n,aa,wa,da)}else Ia(v,D,n,aa,wa,da)}}}q.addRectangle(r)}o.setTransform(1,0,0,1,0,0)}};
  130. THREE.SVGRenderer=function(){function a(Q,F,W){var Y,S,H,R;Y=0;for(S=Q.lights.length;Y<S;Y++){H=Q.lights[Y];if(H instanceof THREE.DirectionalLight){R=F.normalWorld.dot(H.position)*H.intensity;if(R>0){W.r+=H.color.r*R;W.g+=H.color.g*R;W.b+=H.color.b*R}}else if(H instanceof THREE.PointLight){p.sub(H.position,F.centroidWorld);p.normalize();R=F.normalWorld.dot(p)*H.intensity;if(R>0){W.r+=H.color.r*R;W.g+=H.color.g*R;W.b+=H.color.b*R}}}}function b(Q,F,W,Y,S,H){z=d(E++);z.setAttribute("d","M "+Q.positionScreen.x+
  131. " "+Q.positionScreen.y+" L "+F.positionScreen.x+" "+F.positionScreen.y+" L "+W.positionScreen.x+","+W.positionScreen.y+"z");if(S instanceof THREE.MeshBasicMaterial)n.__styleString=S.color.__styleString;else if(S instanceof THREE.MeshLambertMaterial)if(D){O.r=L.r;O.g=L.g;O.b=L.b;a(H,Y,O);n.r=S.color.r*O.r;n.g=S.color.g*O.g;n.b=S.color.b*O.b;n.updateStyleString()}else n.__styleString=S.color.__styleString;else if(S instanceof THREE.MeshDepthMaterial){l=1-S.__2near/(S.__farPlusNear-Y.z*S.__farMinusNear);
  132. n.setRGB(l,l,l)}else S instanceof THREE.MeshNormalMaterial&&n.setRGB(f(Y.normalWorld.x),f(Y.normalWorld.y),f(Y.normalWorld.z));S.wireframe?z.setAttribute("style","fill: none; stroke: "+n.__styleString+"; stroke-width: "+S.wireframe_linewidth+"; stroke-opacity: "+S.opacity+"; stroke-linecap: "+S.wireframe_linecap+"; stroke-linejoin: "+S.wireframe_linejoin):z.setAttribute("style","fill: "+n.__styleString+"; fill-opacity: "+S.opacity);j.appendChild(z)}function e(Q,F,W,Y,S,H,R){z=d(E++);z.setAttribute("d",
  133. "M "+Q.positionScreen.x+" "+Q.positionScreen.y+" L "+F.positionScreen.x+" "+F.positionScreen.y+" L "+W.positionScreen.x+","+W.positionScreen.y+" L "+Y.positionScreen.x+","+Y.positionScreen.y+"z");if(H instanceof THREE.MeshBasicMaterial)n.__styleString=H.color.__styleString;else if(H instanceof THREE.MeshLambertMaterial)if(D){O.r=L.r;O.g=L.g;O.b=L.b;a(R,S,O);n.r=H.color.r*O.r;n.g=H.color.g*O.g;n.b=H.color.b*O.b;n.updateStyleString()}else n.__styleString=H.color.__styleString;else if(H instanceof THREE.MeshDepthMaterial){l=
  134. 1-H.__2near/(H.__farPlusNear-S.z*H.__farMinusNear);n.setRGB(l,l,l)}else H instanceof THREE.MeshNormalMaterial&&n.setRGB(f(S.normalWorld.x),f(S.normalWorld.y),f(S.normalWorld.z));H.wireframe?z.setAttribute("style","fill: none; stroke: "+n.__styleString+"; stroke-width: "+H.wireframe_linewidth+"; stroke-opacity: "+H.opacity+"; stroke-linecap: "+H.wireframe_linecap+"; stroke-linejoin: "+H.wireframe_linejoin):z.setAttribute("style","fill: "+n.__styleString+"; fill-opacity: "+H.opacity);j.appendChild(z)}
  135. function d(Q){if(s[Q]==null){s[Q]=document.createElementNS("http://www.w3.org/2000/svg","path");M==0&&s[Q].setAttribute("shape-rendering","crispEdges");return s[Q]}return s[Q]}function f(Q){return Q<0?Math.min((1+Q)*0.5,0.5):0.5+Math.min(Q*0.5,0.5)}var g=null,k=new THREE.Projector,j=document.createElementNS("http://www.w3.org/2000/svg","svg"),i,o,w,c,u,y,B,C,K=new THREE.Rectangle,v=new THREE.Rectangle,D=false,n=new THREE.Color(16777215),O=new THREE.Color(16777215),L=new THREE.Color(0),h=new THREE.Color(0),
  136. m=new THREE.Color(0),l,p=new THREE.Vector3,s=[],t=[],x=[],z,E,P,N,M=1;this.domElement=j;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(Q){switch(Q){case "high":M=1;break;case "low":M=0}};this.setSize=function(Q,F){i=Q;o=F;w=i/2;c=o/2;j.setAttribute("viewBox",-w+" "+-c+" "+i+" "+o);j.setAttribute("width",i);j.setAttribute("height",o);K.set(-w,-c,w,c)};this.clear=function(){for(;j.childNodes.length>0;)j.removeChild(j.childNodes[0])};this.render=function(Q,F){var W,Y,
  137. S,H,R,q,r,A;this.autoClear&&this.clear();g=k.projectScene(Q,F,this.sortElements);N=P=E=0;if(D=Q.lights.length>0){r=Q.lights;L.setRGB(0,0,0);h.setRGB(0,0,0);m.setRGB(0,0,0);W=0;for(Y=r.length;W<Y;W++){S=r[W];H=S.color;if(S instanceof THREE.AmbientLight){L.r+=H.r;L.g+=H.g;L.b+=H.b}else if(S instanceof THREE.DirectionalLight){h.r+=H.r;h.g+=H.g;h.b+=H.b}else if(S instanceof THREE.PointLight){m.r+=H.r;m.g+=H.g;m.b+=H.b}}}W=0;for(Y=g.length;W<Y;W++){r=g[W];v.empty();if(r instanceof THREE.RenderableParticle){u=
  138. r;u.x*=w;u.y*=-c;S=0;for(H=r.materials.length;S<H;S++)if(A=r.materials[S]){R=u;q=r;A=A;var I=P++;if(t[I]==null){t[I]=document.createElementNS("http://www.w3.org/2000/svg","circle");M==0&&t[I].setAttribute("shape-rendering","crispEdges")}z=t[I];z.setAttribute("cx",R.x);z.setAttribute("cy",R.y);z.setAttribute("r",q.scale.x*w);if(A instanceof THREE.ParticleCircleMaterial){if(D){O.r=L.r+h.r+m.r;O.g=L.g+h.g+m.g;O.b=L.b+h.b+m.b;n.r=A.color.r*O.r;n.g=A.color.g*O.g;n.b=A.color.b*O.b;n.updateStyleString()}else n=
  139. A.color;z.setAttribute("style","fill: "+n.__styleString)}j.appendChild(z)}}else if(r instanceof THREE.RenderableLine){u=r.v1;y=r.v2;u.positionScreen.x*=w;u.positionScreen.y*=-c;y.positionScreen.x*=w;y.positionScreen.y*=-c;v.addPoint(u.positionScreen.x,u.positionScreen.y);v.addPoint(y.positionScreen.x,y.positionScreen.y);if(K.instersects(v)){S=0;for(H=r.materials.length;S<H;)if(A=r.materials[S++]){R=u;q=y;A=A;I=N++;if(x[I]==null){x[I]=document.createElementNS("http://www.w3.org/2000/svg","line");M==
  140. 0&&x[I].setAttribute("shape-rendering","crispEdges")}z=x[I];z.setAttribute("x1",R.positionScreen.x);z.setAttribute("y1",R.positionScreen.y);z.setAttribute("x2",q.positionScreen.x);z.setAttribute("y2",q.positionScreen.y);if(A instanceof THREE.LineBasicMaterial){n.__styleString=A.color.__styleString;z.setAttribute("style","fill: none; stroke: "+n.__styleString+"; stroke-width: "+A.linewidth+"; stroke-opacity: "+A.opacity+"; stroke-linecap: "+A.linecap+"; stroke-linejoin: "+A.linejoin);j.appendChild(z)}}}}else if(r instanceof
  141. THREE.RenderableFace3){u=r.v1;y=r.v2;B=r.v3;u.positionScreen.x*=w;u.positionScreen.y*=-c;y.positionScreen.x*=w;y.positionScreen.y*=-c;B.positionScreen.x*=w;B.positionScreen.y*=-c;v.addPoint(u.positionScreen.x,u.positionScreen.y);v.addPoint(y.positionScreen.x,y.positionScreen.y);v.addPoint(B.positionScreen.x,B.positionScreen.y);if(K.instersects(v)){S=0;for(H=r.meshMaterials.length;S<H;){A=r.meshMaterials[S++];if(A instanceof THREE.MeshFaceMaterial){R=0;for(q=r.faceMaterials.length;R<q;)(A=r.faceMaterials[R++])&&
  142. b(u,y,B,r,A,Q)}else A&&b(u,y,B,r,A,Q)}}}else if(r instanceof THREE.RenderableFace4){u=r.v1;y=r.v2;B=r.v3;C=r.v4;u.positionScreen.x*=w;u.positionScreen.y*=-c;y.positionScreen.x*=w;y.positionScreen.y*=-c;B.positionScreen.x*=w;B.positionScreen.y*=-c;C.positionScreen.x*=w;C.positionScreen.y*=-c;v.addPoint(u.positionScreen.x,u.positionScreen.y);v.addPoint(y.positionScreen.x,y.positionScreen.y);v.addPoint(B.positionScreen.x,B.positionScreen.y);v.addPoint(C.positionScreen.x,C.positionScreen.y);if(K.instersects(v)){S=
  143. 0;for(H=r.meshMaterials.length;S<H;){A=r.meshMaterials[S++];if(A instanceof THREE.MeshFaceMaterial){R=0;for(q=r.faceMaterials.length;R<q;)(A=r.faceMaterials[R++])&&e(u,y,B,C,r,A,Q)}else A&&e(u,y,B,C,r,A,Q)}}}}}};
  144. THREE.WebGLRenderer=function(a){function b(h,m){h.fragment_shader=m.fragment_shader;h.vertex_shader=m.vertex_shader;h.uniforms=Uniforms.clone(m.uniforms)}function e(h,m){h.uniforms.color.value.setHex(h.color.hex);h.uniforms.opacity.value=h.opacity;h.uniforms.map.texture=h.map;h.uniforms.env_map.texture=h.env_map;h.uniforms.reflectivity.value=h.reflectivity;h.uniforms.refraction_ratio.value=h.refraction_ratio;h.uniforms.combine.value=h.combine;h.uniforms.useRefract.value=h.env_map&&h.env_map.mapping instanceof
  145. THREE.CubeRefractionMapping;if(m){h.uniforms.fogColor.value.setHex(m.color.hex);if(m instanceof THREE.Fog){h.uniforms.fogNear.value=m.near;h.uniforms.fogFar.value=m.far}else if(m instanceof THREE.FogExp2)h.uniforms.fogDensity.value=m.density}}function d(h,m,l){var p=c.createProgram(),s=["#ifdef GL_ES\nprecision highp float;\n#endif",l.fog?"#define USE_FOG":"",l.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",l.map?"#define USE_MAP":"",l.env_map?"#define USE_ENVMAP":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");
  146. l=[c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"",l.map?"#define USE_MAP":"",l.env_map?"#define USE_ENVMAP":"","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"].join("\n");c.attachShader(p,i("fragment",s+h));c.attachShader(p,i("vertex",l+m));c.linkProgram(p);c.getProgramParameter(p,
  147. c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(p,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");p.uniforms={};p.attributes={};return p}function f(h,m){if(h.image.length==6){if(!h.image.__webGLTextureCube&&!h.image.__cubeMapInitialized&&h.image.loadCount==6){h.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,h.image.__webGLTextureCube);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,
  148. c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(var l=0;l<6;++l)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+l,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,h.image[l]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);h.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+m);c.bindTexture(c.TEXTURE_CUBE_MAP,h.image.__webGLTextureCube)}}function g(h,
  149. m){if(!h.__webGLTexture&&h.image.loaded){h.__webGLTexture=c.createTexture();c.bindTexture(c.TEXTURE_2D,h.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,h.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,o(h.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,o(h.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,o(h.mag_filter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,o(h.min_filter));c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+
  150. m);c.bindTexture(c.TEXTURE_2D,h.__webGLTexture)}function k(h,m){var l,p,s;l=0;for(p=m.length;l<p;l++){s=m[l];h.uniforms[s]=c.getUniformLocation(h,s)}}function j(h,m){var l,p,s;l=0;for(p=m.length;l<p;l++){s=m[l];h.attributes[s]=c.getAttribLocation(h,s)}}function i(h,m){var l;if(h=="fragment")l=c.createShader(c.FRAGMENT_SHADER);else if(h=="vertex")l=c.createShader(c.VERTEX_SHADER);c.shaderSource(l,m);c.compileShader(l);if(!c.getShaderParameter(l,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(l));return null}return l}
  151. function o(h){switch(h){case THREE.RepeatWrapping:return c.REPEAT;case THREE.ClampToEdgeWrapping:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return c.MIRRORED_REPEAT;case THREE.NearestFilter:return c.NEAREST;case THREE.NearestMipMapNearestFilter:return c.NEAREST_MIPMAP_NEAREST;case THREE.NearestMipMapLinearFilter:return c.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return c.LINEAR;case THREE.LinearMipMapNearestFilter:return c.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return c.LINEAR_MIPMAP_LINEAR}return 0}
  152. var w=document.createElement("canvas"),c,u,y,B=new THREE.Matrix4,C,K=new Float32Array(16),v=new Float32Array(16),D=new Float32Array(16),n=new Float32Array(9),O=new Float32Array(16),L=function(h,m){if(h){var l,p,s,t=pointLights=maxDirLights=maxPointLights=0;l=0;for(p=h.lights.length;l<p;l++){s=h.lights[l];s instanceof THREE.DirectionalLight&&t++;s instanceof THREE.PointLight&&pointLights++}if(pointLights+t<=m){maxDirLights=t;maxPointLights=pointLights}else{maxDirLights=Math.ceil(m*t/(pointLights+t));
  153. maxPointLights=m-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:m-1}}(a.scene,4);fog=a.scene?a.scene.fog:null;antialias=a.antialias!=undefined?a.antialias:true;clearColor=a.clearColor?new THREE.Color(a.clearColor):new THREE.Color(0);clearAlpha=a.clearAlpha?a.clearAlpha:0;this.domElement=w;this.autoClear=true;(function(h,m,l){try{c=w.getContext("experimental-webgl",{antialias:h})}catch(p){}if(!c){alert("WebGL not supported");throw"cannot create webgl context";
  154. }c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK);c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(m.r,m.g,m.b,l)})(antialias,clearColor,clearAlpha);u=y=function(h,m,l){var p=[h?"#define MAX_DIR_LIGHTS "+h:"",m?"#define MAX_POINT_LIGHTS "+m:"","uniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",
  155. h?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",h?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",m?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",m?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",m?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform float mRefractionRatio;\nvoid main(void) {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec3 transformedNormal = normalize( normalMatrix * normal );\nif ( !enableLighting ) {\nvLightWeighting = vec3( 1.0, 1.0, 1.0 );\n} else {\nvLightWeighting = ambientLightColor;",
  156. h?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",h?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",h?"float directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );":"",h?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",h?"}":"",m?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",m?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",m?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
  157. "",m?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",m?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",m?"}":"","}\nvNormal = transformedNormal;\nvUv = uv;\nif ( useRefract ) {\nvReflect = refract( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz), mRefractionRatio );\n} else {\nvReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );\n}\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n"),
  158. s=[h?"#define MAX_DIR_LIGHTS "+h:"",m?"#define MAX_POINT_LIGHTS "+m:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;",THREE.Snippets.fog_uniforms,"uniform int pointLightNumber;\nuniform int directionalLightNumber;",h?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":
  159. "","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",m?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nvoid main() {\nvec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nvec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nif ( enableMap ) {\nmapColor = texture2D( tMap, vUv );\n}\nif ( enableCubeMap ) {\ncubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\n}\nif ( material == 2 ) { \nvec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );",
  160. m?"vec4 pointDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );":"",m?"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",m?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",m?"vec3 pointVector = normalize( vPointLightVector[ i ] );":"",m?"vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );":"",m?"float pointDotNormalHalf = dot( normal, pointHalfVector );":"",m?"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );":"",m?"float pointSpecularWeight = 0.0;":"",m?"if ( pointDotNormalHalf >= 0.0 )":
  161. "",m?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",m?"pointDiffuse += mColor * pointDiffuseWeight;":"",m?"pointSpecular += mSpecular * pointSpecularWeight;":"",m?"}":"",h?"vec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );":"",h?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",h?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",h?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",h?"vec3 dirVector = normalize( lDirection.xyz );":"",h?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
  162. "",h?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",h?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",h?"float dirSpecularWeight = 0.0;":"",h?"if ( dirDotNormalHalf >= 0.0 )":"",h?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",h?"dirDiffuse += mColor * dirDiffuseWeight;":"",h?"dirSpecular += mSpecular * dirSpecularWeight;":"",h?"}":"","vec4 totalLight = mAmbient;",h?"totalLight += dirDiffuse + dirSpecular;":"",m?"totalLight += pointDiffuse + pointSpecular;":
  163. "","if ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mapColor.rgb * totalLight.xyz * vLightWeighting, cubeColor.rgb, mReflectivity ), mapColor.a );\n} else {\ngl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );\n}\n} else if ( material == 1 ) {\nif ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mColor.rgb * mapColor.rgb * vLightWeighting, cubeColor.rgb, mReflectivity ), mColor.a * mapColor.a );\n} else {\ngl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );\n}\n}",
  164. THREE.Snippets.fog_fragment,"}"].join("\n");p=d(s,p,{fog:l});c.useProgram(p);k(p,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract"]);l&&k(p,["fogColor","fogNear","fogFar","fogDensity"]);h&&k(p,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);
  165. m&&k(p,["pointLightNumber","pointLightColor","pointLightPosition"]);c.uniform1i(p.uniforms.enableMap,0);c.uniform1i(p.uniforms.tMap,0);c.uniform1i(p.uniforms.enableCubeMap,0);c.uniform1i(p.uniforms.tCube,1);c.uniform1i(p.uniforms.mixEnvMap,0);c.uniform1i(p.uniforms.useRefract,0);j(p,["position","normal","uv"]);return p}(L.directional,L.point,fog);this.setSize=function(h,m){w.width=h;w.height=m;c.viewport(0,0,w.width,w.height)};this.setClearColor=function(h,m){var l=new THREE.Color(h);c.clearColor(l.r,
  166. l.g,l.b,m)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(h,m){var l,p,s,t,x,z=[],E=[],P=[];t=[];x=[];c.uniform1i(h.uniforms.enableLighting,m.length);l=0;for(p=m.length;l<p;l++){s=m[l];if(s instanceof THREE.AmbientLight)z.push(s);else if(s instanceof THREE.DirectionalLight)P.push(s);else s instanceof THREE.PointLight&&E.push(s)}l=s=t=x=0;for(p=z.length;l<p;l++){s+=z[l].color.r;t+=z[l].color.g;x+=z[l].color.b}c.uniform3f(h.uniforms.ambientLightColor,
  167. s,t,x);t=[];x=[];l=0;for(p=P.length;l<p;l++){s=P[l];t.push(s.color.r*s.intensity);t.push(s.color.g*s.intensity);t.push(s.color.b*s.intensity);x.push(s.position.x);x.push(s.position.y);x.push(s.position.z)}if(P.length){c.uniform1i(h.uniforms.directionalLightNumber,P.length);c.uniform3fv(h.uniforms.directionalLightDirection,x);c.uniform3fv(h.uniforms.directionalLightColor,t)}t=[];x=[];l=0;for(p=E.length;l<p;l++){s=E[l];t.push(s.color.r*s.intensity);t.push(s.color.g*s.intensity);t.push(s.color.b*s.intensity);
  168. x.push(s.position.x);x.push(s.position.y);x.push(s.position.z)}if(E.length){c.uniform1i(h.uniforms.pointLightNumber,E.length);c.uniform3fv(h.uniforms.pointLightPosition,x);c.uniform3fv(h.uniforms.pointLightColor,t)}};this.createBuffers=function(h,m){var l,p,s,t,x,z,E,P,N,M=[],Q=[],F=[],W=[],Y=[],S=[],H=0,R=h.geometry.geometryChunks[m],q;s=false;l=0;for(p=h.materials.length;l<p;l++){meshMaterial=h.materials[l];if(meshMaterial instanceof THREE.MeshFaceMaterial){x=0;for(q=R.materials.length;x<q;x++)if(R.materials[x]&&
  169. R.materials[x].shading!=undefined&&R.materials[x].shading==THREE.SmoothShading){s=true;break}}else if(meshMaterial&&meshMaterial.shading!=undefined&&meshMaterial.shading==THREE.SmoothShading){s=true;break}if(s)break}q=s;l=0;for(p=R.faces.length;l<p;l++){s=R.faces[l];t=h.geometry.faces[s];x=t.vertexNormals;faceNormal=t.normal;s=h.geometry.uvs[s];if(t instanceof THREE.Face3){z=h.geometry.vertices[t.a].position;E=h.geometry.vertices[t.b].position;P=h.geometry.vertices[t.c].position;F.push(z.x,z.y,z.z);
  170. F.push(E.x,E.y,E.z);F.push(P.x,P.y,P.z);if(h.geometry.hasTangents){z=h.geometry.vertices[t.a].tangent;E=h.geometry.vertices[t.b].tangent;P=h.geometry.vertices[t.c].tangent;Y.push(z.x,z.y,z.z,z.w);Y.push(E.x,E.y,E.z,E.w);Y.push(P.x,P.y,P.z,P.w)}if(x.length==3&&q)for(t=0;t<3;t++)W.push(x[t].x,x[t].y,x[t].z);else for(t=0;t<3;t++)W.push(faceNormal.x,faceNormal.y,faceNormal.z);if(s)for(t=0;t<3;t++)S.push(s[t].u,s[t].v);M.push(H,H+1,H+2);Q.push(H,H+1);Q.push(H,H+2);Q.push(H+1,H+2);H+=3}else if(t instanceof
  171. THREE.Face4){z=h.geometry.vertices[t.a].position;E=h.geometry.vertices[t.b].position;P=h.geometry.vertices[t.c].position;N=h.geometry.vertices[t.d].position;F.push(z.x,z.y,z.z);F.push(E.x,E.y,E.z);F.push(P.x,P.y,P.z);F.push(N.x,N.y,N.z);if(h.geometry.hasTangents){z=h.geometry.vertices[t.a].tangent;E=h.geometry.vertices[t.b].tangent;P=h.geometry.vertices[t.c].tangent;t=h.geometry.vertices[t.d].tangent;Y.push(z.x,z.y,z.z,z.w);Y.push(E.x,E.y,E.z,E.w);Y.push(P.x,P.y,P.z,P.w);Y.push(t.x,t.y,t.z,t.w)}if(x.length==
  172. 4&&q)for(t=0;t<4;t++)W.push(x[t].x,x[t].y,x[t].z);else for(t=0;t<4;t++)W.push(faceNormal.x,faceNormal.y,faceNormal.z);if(s)for(t=0;t<4;t++)S.push(s[t].u,s[t].v);M.push(H,H+1,H+2);M.push(H,H+2,H+3);Q.push(H,H+1);Q.push(H,H+2);Q.push(H,H+3);Q.push(H+1,H+2);Q.push(H+2,H+3);H+=4}}if(F.length){R.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,R.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(F),c.STATIC_DRAW);R.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,
  173. R.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(W),c.STATIC_DRAW);if(h.geometry.hasTangents){R.__webGLTangentBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,R.__webGLTangentBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(Y),c.STATIC_DRAW)}if(S.length>0){R.__webGLUVBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,R.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(S),c.STATIC_DRAW)}R.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,
  174. R.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(M),c.STATIC_DRAW);R.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,R.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(Q),c.STATIC_DRAW);R.__webGLFaceCount=M.length;R.__webGLLineCount=Q.length}};this.renderBuffer=function(h,m,l,p,s){var t,x,z,E,P,N,M,Q,F;if(p instanceof THREE.MeshShaderMaterial||p instanceof THREE.MeshDepthMaterial||p instanceof THREE.MeshNormalMaterial||p instanceof
  175. THREE.MeshBasicMaterial){if(!p.program){if(p instanceof THREE.MeshDepthMaterial){b(p,THREE.ShaderLib.depth);p.uniforms.mNear.value=h.near;p.uniforms.mFar.value=h.far}else if(p instanceof THREE.MeshNormalMaterial)b(p,THREE.ShaderLib.normal);else if(p instanceof THREE.MeshBasicMaterial){b(p,THREE.ShaderLib.basic);e(p,l)}p.program=d(p.fragment_shader,p.vertex_shader,{fog:l,map:p.map,env_map:p.env_map});M=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];
  176. for(F in p.uniforms)M.push(F);k(p.program,M);j(p.program,["position","normal","uv","tangent"])}F=p.program}else F=y;if(F!=u){c.useProgram(F);u=F}F==y&&this.setupLights(F,m);this.loadCamera(F,h);this.loadMatrices(F);p instanceof THREE.MeshBasicMaterial&&e(p,l);if(p instanceof THREE.MeshShaderMaterial||p instanceof THREE.MeshDepthMaterial||p instanceof THREE.MeshNormalMaterial||p instanceof THREE.MeshBasicMaterial){z=p.wireframe;E=p.wireframe_linewidth;h=F;m=p.uniforms;var W;for(t in m){Q=m[t].type;
  177. M=m[t].value;W=h.uniforms[t];if(Q=="i")c.uniform1i(W,M);else if(Q=="f")c.uniform1f(W,M);else if(Q=="v3")c.uniform3f(W,M.x,M.y,M.z);else if(Q=="c")c.uniform3f(W,M.r,M.g,M.b);else if(Q=="t"){c.uniform1i(W,M);if(Q=m[t].texture)Q.image instanceof Array&&Q.image.length==6?f(Q,M):g(Q,M)}}}if(p instanceof THREE.MeshPhongMaterial||p instanceof THREE.MeshLambertMaterial){t=p.color;x=p.opacity;z=p.wireframe;E=p.wireframe_linewidth;P=p.map;N=p.env_map;m=p.combine==THREE.MixOperation;h=p.reflectivity;Q=p.env_map&&
  178. p.env_map.mapping instanceof THREE.CubeRefractionMapping;M=p.refraction_ratio;c.uniform4f(F.uniforms.mColor,t.r*x,t.g*x,t.b*x,x);c.uniform1i(F.uniforms.mixEnvMap,m);c.uniform1f(F.uniforms.mReflectivity,h);c.uniform1i(F.uniforms.useRefract,Q);c.uniform1f(F.uniforms.mRefractionRatio,M);if(l){c.uniform3f(F.uniforms.fogColor,l.color.r,l.color.g,l.color.b);if(l instanceof THREE.Fog){c.uniform1f(F.uniforms.fogNear,l.near);c.uniform1f(F.uniforms.fogFar,l.far)}else l instanceof THREE.FogExp2&&c.uniform1f(F.uniforms.fogDensity,
  179. l.density)}}if(p instanceof THREE.MeshPhongMaterial){l=p.ambient;t=p.specular;p=p.shininess;c.uniform4f(F.uniforms.mAmbient,l.r,l.g,l.b,x);c.uniform4f(F.uniforms.mSpecular,t.r,t.g,t.b,x);c.uniform1f(F.uniforms.mShininess,p);c.uniform1i(F.uniforms.material,2)}else p instanceof THREE.MeshLambertMaterial&&c.uniform1i(F.uniforms.material,1);if(P){g(P,0);c.uniform1i(F.uniforms.tMap,0);c.uniform1i(F.uniforms.enableMap,1)}else c.uniform1i(F.uniforms.enableMap,0);if(N){f(N,1);c.uniform1i(F.uniforms.tCube,
  180. 1);c.uniform1i(F.uniforms.enableCubeMap,1)}else c.uniform1i(F.uniforms.enableCubeMap,0);x=F.attributes;c.bindBuffer(c.ARRAY_BUFFER,s.__webGLVertexBuffer);c.vertexAttribPointer(x.position,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(x.position);if(x.normal>=0){c.bindBuffer(c.ARRAY_BUFFER,s.__webGLNormalBuffer);c.vertexAttribPointer(x.normal,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(x.normal)}if(x.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,s.__webGLTangentBuffer);c.vertexAttribPointer(x.tangent,
  181. 4,c.FLOAT,false,0,0);c.enableVertexAttribArray(x.tangent)}if(x.uv>=0)if(s.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,s.__webGLUVBuffer);c.vertexAttribPointer(x.uv,2,c.FLOAT,false,0,0);c.enableVertexAttribArray(x.uv)}else c.disableVertexAttribArray(x.uv);if(z){c.lineWidth(E);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,s.__webGLLineBuffer);c.drawElements(c.LINES,s.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,s.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,s.__webGLFaceCount,
  182. c.UNSIGNED_SHORT,0)}};this.renderPass=function(h,m,l,p,s,t,x){var z,E,P,N,M;P=0;for(N=p.materials.length;P<N;P++){z=p.materials[P];if(z instanceof THREE.MeshFaceMaterial){z=0;for(E=s.materials.length;z<E;z++)if((M=s.materials[z])&&M.blending==t&&M.opacity<1==x){this.setBlending(M.blending);this.renderBuffer(h,m,l,M,s)}}else if((M=z)&&M.blending==t&&M.opacity<1==x){this.setBlending(M.blending);this.renderBuffer(h,m,l,M,s)}}};this.render=function(h,m){var l,p,s,t,x=h.lights,z=h.fog;this.initWebGLObjects(h);
  183. this.autoClear&&this.clear();m.autoUpdateMatrix&&m.updateMatrix();K.set(m.matrix.flatten());D.set(m.projectionMatrix.flatten());l=0;for(p=h.__webGLObjects.length;l<p;l++){s=h.__webGLObjects[l];t=s.object;s=s.buffer;if(t.visible){this.setupMatrices(t,m);this.renderPass(m,x,z,t,s,THREE.NormalBlending,false)}}l=0;for(p=h.__webGLObjects.length;l<p;l++){s=h.__webGLObjects[l];t=s.object;s=s.buffer;if(t.visible){this.setupMatrices(t,m);this.renderPass(m,x,z,t,s,THREE.AdditiveBlending,false);this.renderPass(m,
  184. x,z,t,s,THREE.SubtractiveBlending,false);this.renderPass(m,x,z,t,s,THREE.AdditiveBlending,true);this.renderPass(m,x,z,t,s,THREE.SubtractiveBlending,true);this.renderPass(m,x,z,t,s,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(h){var m,l,p,s,t,x;if(!h.__webGLObjects){h.__webGLObjects=[];h.__webGLObjectsMap={}}m=0;for(l=h.objects.length;m<l;m++){p=h.objects[m];if(h.__webGLObjectsMap[p.id]==undefined)h.__webGLObjectsMap[p.id]={};x=h.__webGLObjectsMap[p.id];if(p instanceof THREE.Mesh)for(t in p.geometry.geometryChunks){s=
  185. p.geometry.geometryChunks[t];s.__webGLVertexBuffer||this.createBuffers(p,t);if(x[t]==undefined){s={buffer:s,object:p};h.__webGLObjects.push(s);x[t]=1}}}};this.removeObject=function(h,m){var l,p;for(l=h.__webGLObjects.length-1;l>=0;l--){p=h.__webGLObjects[l].object;m==p&&h.__webGLObjects.splice(l,1)}};this.setupMatrices=function(h,m){h.autoUpdateMatrix&&h.updateMatrix();B.multiply(m.matrix,h.matrix);v.set(B.flatten());C=THREE.Matrix4.makeInvert3x3(B).transpose();n.set(C.m);O.set(h.matrix.flatten())};
  186. this.loadMatrices=function(h){c.uniformMatrix4fv(h.uniforms.viewMatrix,false,K);c.uniformMatrix4fv(h.uniforms.modelViewMatrix,false,v);c.uniformMatrix4fv(h.uniforms.projectionMatrix,false,D);c.uniformMatrix3fv(h.uniforms.normalMatrix,false,n);c.uniformMatrix4fv(h.uniforms.objectMatrix,false,O)};this.loadCamera=function(h,m){c.uniform3f(h.uniforms.cameraPosition,m.position.x,m.position.y,m.position.z)};this.setBlending=function(h){switch(h){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,
  187. c.ONE);break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(h,m){if(h){!m||m=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(h=="back")c.cullFace(c.BACK);else h=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)};this.supportsVertexTextures=function(){return c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}};
  188. THREE.Snippets={fog_uniforms:"#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"};
  189. 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}",
  190. 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:{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},
  191. 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)}},fragment_shader:["uniform vec3 color;\nuniform float opacity;\n#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif\n#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube env_map;\nuniform int combine;\n#endif",THREE.Snippets.fog_uniforms,"void main() {\nvec4 mColor = vec4( color, opacity );\nvec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nvec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );\n#ifdef USE_MAP\nmapColor = texture2D( map, vUv );\n#endif\n#ifdef USE_ENVMAP\ncubeColor = textureCube( env_map, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = mix( mColor * mapColor, cubeColor, reflectivity );\n} else {\ngl_FragColor = mColor * mapColor * cubeColor;\n}\n#else\ngl_FragColor = mColor * mapColor;\n#endif",
  192. THREE.Snippets.fog_fragment,"}"].join("\n"),vertex_shader:"#ifdef USE_MAP\nvarying vec2 vUv;\n#endif\n#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refraction_ratio;\nuniform bool useRefract;\n#endif\nvoid main() {\n#ifdef USE_MAP\nvUv = uv;\n#endif\n#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\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}"}};
  193. 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]};
  194. 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};
  195. var GeometryUtils={merge:function(a,b){var e=b instanceof THREE.Mesh,d=a.vertices.length,f=e?b.geometry:b,g=a.vertices,k=f.vertices,j=a.faces,i=f.faces,o=a.uvs;f=f.uvs;e&&b.updateMatrix();for(var w=0,c=k.length;w<c;w++){var u=new THREE.Vertex(k[w].position.clone());e&&b.matrix.multiplyVector3(u.position);g.push(u)}w=0;for(c=i.length;w<c;w++){k=i[w];var y,B=k.vertexNormals;if(k instanceof THREE.Face3)y=new THREE.Face3(k.a+d,k.b+d,k.c+d);else if(k instanceof THREE.Face4)y=new THREE.Face4(k.a+d,k.b+
  196. d,k.c+d,k.d+d);y.centroid.copy(k.centroid);y.normal.copy(k.normal);e=0;for(g=B.length;e<g;e++){u=B[e];y.vertexNormals.push(u.clone())}y.materials=k.materials.slice();j.push(y)}w=0;for(c=f.length;w<c;w++){d=f[w];j=[];e=0;for(g=d.length;e<g;e++)j.push(new THREE.UV(d[e].u,d[e].v));o.push(j)}}},ImageUtils={loadTexture:function(a,b){var e=new Image;e.onload=function(){this.loaded=true};e.src=a;return new THREE.Texture(e,b)},loadArray:function(a){var b,e,d=[];b=d.loadCount=0;for(e=a.length;b<e;++b){d[b]=
  197. new Image;d[b].loaded=0;d[b].onload=function(){d.loadCount+=1;this.loaded=true};d[b].src=a[b]}return d}},SceneUtils={addMesh:function(a,b,e,d,f,g,k,j,i,o){b=new THREE.Mesh(b,o);b.scale.x=b.scale.y=b.scale.z=e;b.position.x=d;b.position.y=f;b.position.z=g;b.rotation.x=k;b.rotation.y=j;b.rotation.z=i;a.addObject(b);return b},addPanoramaCubeWebGL:function(a,b,e){var d=ShaderUtils.lib.cube;d.uniforms.tCube.texture=e;e=new THREE.MeshShaderMaterial({fragment_shader:d.fragment_shader,vertex_shader:d.vertex_shader,
  198. uniforms:d.uniforms});b=new THREE.Mesh(new Cube(b,b,b,1,1,null,true),e);a.addObject(b);return b},addPanoramaCube:function(a,b,e){var d=[];d.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[0])}));d.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[1])}));d.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[2])}));d.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[3])}));d.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[4])}));d.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[5])}));
  199. mesh=new THREE.Mesh(new Cube(b,b,b,1,1,d,true),new THREE.MeshFaceMaterial);a.addObject(mesh);return mesh},addPanoramaCubePlanes:function(a,b,e){var d=b/2;b=new Plane(b,b);var f=Math.PI/2,g=Math.PI;SceneUtils.addMesh(a,b,1,0,0,-d,0,0,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(e[5])}));SceneUtils.addMesh(a,b,1,-d,0,0,0,f,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(e[0])}));SceneUtils.addMesh(a,b,1,d,0,0,0,-f,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(e[1])}));SceneUtils.addMesh(a,
  200. b,1,0,d,0,f,0,g,new THREE.MeshBasicMaterial({map:new THREE.Texture(e[2])}));SceneUtils.addMesh(a,b,1,0,-d,0,-f,0,g,new THREE.MeshBasicMaterial({map:new THREE.Texture(e[3])}))}},ShaderUtils={lib:{fresnel:{uniforms:{mRefractionRatio:{type:"f",value:1.02},mFresnelBias:{type:"f",value:0.1},mFresnelPower:{type:"f",value:2},mFresnelScale:{type:"f",value:1},tCube:{type:"t",value:1,texture:null}},fragment_shader:"uniform samplerCube tCube;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main() {\nvec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\nvec4 refractedColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nrefractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;\nrefractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;\nrefractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;\nrefractedColor.a = 1.0;\ngl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );\n}",
  201. vertex_shader:"uniform float mRefractionRatio;\nuniform float mFresnelBias;\nuniform float mFresnelScale;\nuniform float mFresnelPower;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main(void) {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = normalize ( mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal );\nvec3 I = mPosition.xyz - cameraPosition;\nvReflect = reflect( I, nWorld );\nvRefract[0] = refract( normalize( I ), nWorld, mRefractionRatio );\nvRefract[1] = refract( normalize( I ), nWorld, mRefractionRatio * 0.99 );\nvRefract[2] = refract( normalize( I ), nWorld, mRefractionRatio * 0.98 );\nvReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), nWorld ), mFresnelPower );\ngl_Position = projectionMatrix * mvPosition;\n}"},
  202. normal:{uniforms:{enableAO:{type:"i",value:0},enableDiffuse:{type:"i",value:0},tDiffuse:{type:"t",value:0,texture:null},tNormal:{type:"t",value:2,texture:null},tAO:{type:"t",value:3,texture:null},uNormalScale:{type:"f",value:1},tDisplacement:{type:"t",value:4,texture:null},uDisplacementBias:{type:"f",value:-0.5},uDisplacementScale:{type:"f",value:2.5},uPointLightPos:{type:"v3",value:new THREE.Vector3},uPointLightColor:{type:"c",value:new THREE.Color(15658734)},uDirLightPos:{type:"v3",value:new THREE.Vector3},
  203. uDirLightColor:{type:"c",value:new THREE.Color(15658734)},uAmbientLightColor:{type:"c",value:new THREE.Color(328965)},uDiffuseColor:{type:"c",value:new THREE.Color(15658734)},uSpecularColor:{type:"c",value:new THREE.Color(1118481)},uAmbientColor:{type:"c",value:new THREE.Color(328965)},uShininess:{type:"f",value:30}},fragment_shader:"uniform vec3 uDirLightPos;\nuniform vec3 uAmbientLightColor;\nuniform vec3 uDirLightColor;\nuniform vec3 uPointLightColor;\nuniform vec3 uAmbientColor;\nuniform vec3 uDiffuseColor;\nuniform vec3 uSpecularColor;\nuniform float uShininess;\nuniform bool enableDiffuse;\nuniform bool enableAO;\nuniform sampler2D tDiffuse;\nuniform sampler2D tNormal;\nuniform sampler2D tAO;\nuniform float uNormalScale;\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vPointLightVector;\nvarying vec3 vViewPosition;\nvoid main() {\nvec3 diffuseTex = vec3( 1.0, 1.0, 1.0 );\nvec3 aoTex = vec3( 1.0, 1.0, 1.0 );\nvec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;\nnormalTex.xy *= uNormalScale;\nnormalTex = normalize( normalTex );\nif( enableDiffuse )\ndiffuseTex = texture2D( tDiffuse, vUv ).xyz;\nif( enableAO )\naoTex = texture2D( tAO, vUv ).xyz;\nmat3 tsb = mat3( vTangent, vBinormal, vNormal );\nvec3 finalNormal = tsb * normalTex;\nvec3 normal = normalize( finalNormal );\nvec3 viewPosition = normalize( vViewPosition );\nvec4 pointDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec3 pointVector = normalize( vPointLightVector );\nvec3 pointHalfVector = normalize( vPointLightVector + vViewPosition );\nfloat pointDotNormalHalf = dot( normal, pointHalfVector );\nfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );\nfloat pointSpecularWeight = 0.0;\nif ( pointDotNormalHalf >= 0.0 )\npointSpecularWeight = pow( pointDotNormalHalf, uShininess );\npointDiffuse += vec4( uDiffuseColor, 1.0 ) * pointDiffuseWeight;\npointSpecular += vec4( uSpecularColor, 1.0 ) * pointSpecularWeight;\nvec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec4 lDirection = viewMatrix * vec4( uDirLightPos, 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nvec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );\nfloat dirDotNormalHalf = dot( normal, dirHalfVector );\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\nfloat dirSpecularWeight = 0.0;\nif ( dirDotNormalHalf >= 0.0 )\ndirSpecularWeight = pow( dirDotNormalHalf, uShininess );\ndirDiffuse += vec4( uDiffuseColor, 1.0 ) * dirDiffuseWeight;\ndirSpecular += vec4( uSpecularColor, 1.0 ) * dirSpecularWeight;\nvec4 totalLight = vec4( uAmbientLightColor * uAmbientColor, 1.0 );\ntotalLight += vec4( uDirLightColor, 1.0 ) * ( dirDiffuse + dirSpecular );\ntotalLight += vec4( uPointLightColor, 1.0 ) * ( pointDiffuse + pointSpecular );\ngl_FragColor = vec4( totalLight.xyz * aoTex * diffuseTex, 1.0 );\n}",
  204. vertex_shader:"attribute vec4 tangent;\nuniform vec3 uPointLightPos;\n#ifdef VERTEX_TEXTURES\nuniform sampler2D tDisplacement;\nuniform float uDisplacementScale;\nuniform float uDisplacementBias;\n#endif\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vPointLightVector;\nvarying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalize( normalMatrix * normal );\nvTangent = normalize( normalMatrix * tangent.xyz );\nvBinormal = cross( vNormal, vTangent ) * tangent.w;\nvBinormal = normalize( vBinormal );\nvUv = uv;\nvec4 lPosition = viewMatrix * vec4( uPointLightPos, 1.0 );\nvPointLightVector = normalize( lPosition.xyz - mvPosition.xyz );\n#ifdef VERTEX_TEXTURES\nvec3 dv = texture2D( tDisplacement, uv ).xyz;\nfloat df = uDisplacementScale * dv.x + uDisplacementBias;\nvec4 displacedPosition = vec4( vNormal.xyz * df, 0.0 ) + mvPosition;\ngl_Position = projectionMatrix * displacedPosition;\n#else\ngl_Position = projectionMatrix * mvPosition;\n#endif\n}"},
  205. basic:{uniforms:{},vertex_shader:"void main() {\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragment_shader:"void main() {\ngl_FragColor = vec4(1.0, 0.0, 0.0, 0.5);\n}"},cube:{uniforms:{tCube:{type:"t",value:1,texture:null}},vertex_shader:"varying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",
  206. fragment_shader:"uniform samplerCube tCube;\nvarying vec3 vViewPosition;\nvoid main() {\nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( - wPos.x, wPos.yz ) );\n}"}}},Cube=function(a,b,e,d,f,g,k,j){function i(C,K,v,D,n,O,L,h){var m,l=d||1,p=f||1,s=l+1,t=p+1,x=n/2,z=O/2;n=n/l;O=O/p;var E=o.vertices.length;if(C=="x"&&K=="y"||C=="y"&&K=="x")m="z";else if(C=="x"&&K=="z"||C=="z"&&K=="x")m="y";else if(C=="z"&&K=="y"||C=="y"&&K=="z")m="x";for(iy=0;iy<t;iy++)for(ix=0;ix<
  207. s;ix++){var P=new THREE.Vector3;P[C]=(ix*n-x)*v;P[K]=(iy*O-z)*D;P[m]=L;o.vertices.push(new THREE.Vertex(P))}for(iy=0;iy<p;iy++)for(ix=0;ix<l;ix++){o.faces.push(new THREE.Face4(ix+s*iy+E,ix+s*(iy+1)+E,ix+1+s*(iy+1)+E,ix+1+s*iy+E,null,h));o.uvs.push([new THREE.UV(ix/l,iy/p),new THREE.UV(ix/l,(iy+1)/p),new THREE.UV((ix+1)/l,(iy+1)/p),new THREE.UV((ix+1)/l,iy/p)])}}THREE.Geometry.call(this);var o=this,w=a/2,c=b/2,u=e/2;k=k?-1:1;if(g!==undefined)if(g instanceof Array)this.materials=g;else{this.materials=
  208. [];for(var y=0;y<6;y++)this.materials.push([g])}else this.materials=[];this.sides={px:true,nx:true,py:true,ny:true,pz:true,nz:true};if(j!=undefined)for(var B in j)if(this.sides[B]!=undefined)this.sides[B]=j[B];this.sides.px&&i("z","y",1*k,-1,e,b,-w,this.materials[0]);this.sides.nx&&i("z","y",-1*k,-1,e,b,w,this.materials[1]);this.sides.py&&i("x","z",1*k,1,a,e,c,this.materials[2]);this.sides.ny&&i("x","z",1*k,-1,a,e,-c,this.materials[3]);this.sides.pz&&i("x","y",1*k,-1,a,b,u,this.materials[4]);this.sides.nz&&
  209. i("x","y",-1*k,-1,a,b,-u,this.materials[5]);(function(){for(var C=[],K=[],v=0,D=o.vertices.length;v<D;v++){for(var n=o.vertices[v],O=false,L=0,h=C.length;L<h;L++){var m=C[L];if(n.position.x==m.position.x&&n.position.y==m.position.y&&n.position.z==m.position.z){K[v]=L;O=true;break}}if(!O){K[v]=C.length;C.push(new THREE.Vertex(n.position.clone()))}}v=0;for(D=o.faces.length;v<D;v++){n=o.faces[v];n.a=K[n.a];n.b=K[n.b];n.c=K[n.c];n.d=K[n.d]}o.vertices=C})();this.computeCentroids();this.computeFaceNormals();
  210. this.sortFacesByMaterial()};Cube.prototype=new THREE.Geometry;Cube.prototype.constructor=Cube;
  211. var Cylinder=function(a,b,e,d,f){function g(o,w,c){k.vertices.push(new THREE.Vertex(new THREE.Vector3(o,w,c)))}THREE.Geometry.call(this);var k=this,j=Math.PI,i;for(i=0;i<a;i++)g(Math.sin(2*j*i/a)*b,Math.cos(2*j*i/a)*b,0);for(i=0;i<a;i++)g(Math.sin(2*j*i/a)*e,Math.cos(2*j*i/a)*e,d);for(i=0;i<a;i++)k.faces.push(new THREE.Face4(i,i+a,a+(i+1)%a,(i+1)%a));if(e!=0){g(0,0,-f);for(i=a;i<a+a/2;i++)k.faces.push(new THREE.Face4(2*a,(2*i-2*a)%a,(2*i-2*a+1)%a,(2*i-2*a+2)%a))}if(b!=0){g(0,0,d+f);for(i=a+a/2;i<
  212. 2*a;i++)k.faces.push(new THREE.Face4((2*i-2*a+2)%a+a,(2*i-2*a+1)%a+a,(2*i-2*a)%a+a,2*a+1))}this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};Cylinder.prototype=new THREE.Geometry;Cylinder.prototype.constructor=Cylinder;
  213. var Plane=function(a,b,e,d){THREE.Geometry.call(this);var f,g=a/2,k=b/2;e=e||1;d=d||1;var j=e+1,i=d+1;a=a/e;var o=b/d;for(f=0;f<i;f++)for(b=0;b<j;b++)this.vertices.push(new THREE.Vertex(new THREE.Vector3(b*a-g,-(f*o-k),0)));for(f=0;f<d;f++)for(b=0;b<e;b++){this.faces.push(new THREE.Face4(b+j*f,b+j*(f+1),b+1+j*(f+1),b+1+j*f));this.uvs.push([new THREE.UV(b/e,f/d),new THREE.UV(b/e,(f+1)/d),new THREE.UV((b+1)/e,(f+1)/d),new THREE.UV((b+1)/e,f/d)])}this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};
  214. Plane.prototype=new THREE.Geometry;Plane.prototype.constructor=Plane;
  215. var Sphere=function(a,b,e){THREE.Geometry.call(this);var d,f=Math.PI,g=Math.max(3,b||8),k=Math.max(2,e||6);b=[];for(e=0;e<k+1;e++){d=e/k;var j=a*Math.cos(d*f),i=a*Math.sin(d*f),o=[],w=0;for(d=0;d<g;d++){var c=2*d/g,u=i*Math.sin(c*f);c=i*Math.cos(c*f);(e==0||e==k)&&d>0||(w=this.vertices.push(new THREE.Vertex(new THREE.Vector3(c,j,u)))-1);o.push(w)}b.push(o)}var y,B,C;f=b.length;for(e=0;e<f;e++){g=b[e].length;if(e>0)for(d=0;d<g;d++){o=d==g-1;k=b[e][o?0:d+1];j=b[e][o?g-1:d];i=b[e-1][o?g-1:d];o=b[e-1][o?
  216. 0:d+1];u=e/(f-1);y=(e-1)/(f-1);B=(d+1)/g;c=d/g;w=new THREE.UV(1-B,u);u=new THREE.UV(1-c,u);c=new THREE.UV(1-c,y);var K=new THREE.UV(1-B,y);if(e<b.length-1){y=this.vertices[k].position.clone();B=this.vertices[j].position.clone();C=this.vertices[i].position.clone();y.normalize();B.normalize();C.normalize();this.faces.push(new THREE.Face3(k,j,i,[new THREE.Vector3(y.x,y.y,y.z),new THREE.Vector3(B.x,B.y,B.z),new THREE.Vector3(C.x,C.y,C.z)]));this.uvs.push([w,u,c])}if(e>1){y=this.vertices[k].position.clone();
  217. B=this.vertices[i].position.clone();C=this.vertices[o].position.clone();y.normalize();B.normalize();C.normalize();this.faces.push(new THREE.Face3(k,i,o,[new THREE.Vector3(y.x,y.y,y.z),new THREE.Vector3(B.x,B.y,B.z),new THREE.Vector3(C.x,C.y,C.z)]));this.uvs.push([w,c,K])}}}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.sortFacesByMaterial();this.boundingSphere={radius:a}};Sphere.prototype=new THREE.Geometry;Sphere.prototype.constructor=Sphere;
  218. THREE.Loader=function(a){this.statusDomElement=(this.showStatus=a)?this.addStatusElement():null};
  219. THREE.Loader.prototype={addStatusElement:function(){var a=document.createElement("div");a.style.fontSize="0.8em";a.style.textAlign="left";a.style.background="#b00";a.style.color="#fff";a.style.width="140px";a.style.padding="0.25em 0.25em 0.25em 0.5em";a.style.position="absolute";a.style.right="0px";a.style.top="0px";a.style.zIndex=1E3;a.innerHTML="Loading ...";return a},updateProgress:function(a){var b="Loaded ";b+=a.total?(100*a.loaded/a.total).toFixed(0)+"%":(a.loaded/1E3).toFixed(2)+" KB";this.statusDomElement.innerHTML=
  220. b},loadAsciiOld:function(a,b){var e=document.createElement("script");e.type="text/javascript";e.onload=b;e.src=a;document.getElementsByTagName("head")[0].appendChild(e)},loadAscii:function(a,b,e){var d=(new Date).getTime();a=new Worker(a);a.onmessage=function(f){THREE.Loader.prototype.createModel(f.data,b,e)};a.postMessage(d)},loadBinary:function(a,b,e){var d=(new Date).getTime();a=new Worker(a);var f=this.showProgress?THREE.Loader.prototype.updateProgress:null;a.onmessage=function(g){THREE.Loader.prototype.loadAjaxBuffers(g.data.buffers,
  221. g.data.materials,b,e,f)};a.onerror=function(g){alert("worker.onerror: "+g.message+"\n"+g.data);g.preventDefault()};a.postMessage(d)},loadAjaxBuffers:function(a,b,e,d,f){var g=new XMLHttpRequest,k=d+"/"+a,j=0;g.onreadystatechange=function(){if(g.readyState==4)g.status==200||g.status==0?THREE.Loader.prototype.createBinModel(g.responseText,e,d,b):alert("Couldn't load ["+k+"] ["+g.status+"]");else if(g.readyState==3){if(f){if(j==0)j=g.getResponseHeader("Content-Length");f({total:j,loaded:g.responseText.length})}}else if(g.readyState==
  222. 2)j=g.getResponseHeader("Content-Length")};g.open("GET",k,true);g.overrideMimeType("text/plain; charset=x-user-defined");g.setRequestHeader("Content-Type","text/plain");g.send(null)},createBinModel:function(a,b,e,d){var f=function(g){function k(q,r){var A=w(q,r),I=w(q,r+1),V=w(q,r+2),ba=w(q,r+3),fa=(ba<<1&255|V>>7)-127;A=(V&127)<<16|I<<8|A;if(A==0&&fa==-127)return 0;return(1-2*(ba>>7))*(1+A*Math.pow(2,-23))*Math.pow(2,fa)}function j(q,r){var A=w(q,r),I=w(q,r+1),V=w(q,r+2);return(w(q,r+3)<<24)+(V<<
  223. 16)+(I<<8)+A}function i(q,r){var A=w(q,r);return(w(q,r+1)<<8)+A}function o(q,r){var A=w(q,r);return A>127?A-256:A}function w(q,r){return q.charCodeAt(r)&255}function c(q){var r,A,I;r=j(a,q);A=j(a,q+h);I=j(a,q+m);q=i(a,q+l);THREE.Loader.prototype.f3(v,r,A,I,q)}function u(q){var r,A,I,V,ba,fa;r=j(a,q);A=j(a,q+h);I=j(a,q+m);V=i(a,q+l);ba=j(a,q+p);fa=j(a,q+s);q=j(a,q+t);THREE.Loader.prototype.f3n(v,O,r,A,I,V,ba,fa,q)}function y(q){var r,A,I,V;r=j(a,q);A=j(a,q+x);I=j(a,q+z);V=j(a,q+E);q=i(a,q+P);THREE.Loader.prototype.f4(v,
  224. r,A,I,V,q)}function B(q){var r,A,I,V,ba,fa,xa,$;r=j(a,q);A=j(a,q+x);I=j(a,q+z);V=j(a,q+E);ba=i(a,q+P);fa=j(a,q+N);xa=j(a,q+M);$=j(a,q+Q);q=j(a,q+F);THREE.Loader.prototype.f4n(v,O,r,A,I,V,ba,fa,xa,$,q)}function C(q){var r,A;r=j(a,q);A=j(a,q+W);q=j(a,q+Y);THREE.Loader.prototype.uv3(v,L[r*2],L[r*2+1],L[A*2],L[A*2+1],L[q*2],L[q*2+1])}function K(q){var r,A,I;r=j(a,q);A=j(a,q+S);I=j(a,q+H);q=j(a,q+R);THREE.Loader.prototype.uv4(v,L[r*2],L[r*2+1],L[A*2],L[A*2+1],L[I*2],L[I*2+1],L[q*2],L[q*2+1])}var v=this,
  225. D=0,n,O=[],L=[],h,m,l,p,s,t,x,z,E,P,N,M,Q,F,W,Y,S,H,R;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(v,d,g);n={signature:a.substr(D,8),header_bytes:w(a,D+8),vertex_coordinate_bytes:w(a,D+9),normal_coordinate_bytes:w(a,D+10),uv_coordinate_bytes:w(a,D+11),vertex_index_bytes:w(a,D+12),normal_index_bytes:w(a,D+13),uv_index_bytes:w(a,D+14),material_index_bytes:w(a,D+15),nvertices:j(a,D+16),nnormals:j(a,D+16+4),nuvs:j(a,D+16+8),ntri_flat:j(a,D+16+12),ntri_smooth:j(a,D+16+16),ntri_flat_uv:j(a,
  226. D+16+20),ntri_smooth_uv:j(a,D+16+24),nquad_flat:j(a,D+16+28),nquad_smooth:j(a,D+16+32),nquad_flat_uv:j(a,D+16+36),nquad_smooth_uv:j(a,D+16+40)};D+=n.header_bytes;h=n.vertex_index_bytes;m=n.vertex_index_bytes*2;l=n.vertex_index_bytes*3;p=n.vertex_index_bytes*3+n.material_index_bytes;s=n.vertex_index_bytes*3+n.material_index_bytes+n.normal_index_bytes;t=n.vertex_index_bytes*3+n.material_index_bytes+n.normal_index_bytes*2;x=n.vertex_index_bytes;z=n.vertex_index_bytes*2;E=n.vertex_index_bytes*3;P=n.vertex_index_bytes*
  227. 4;N=n.vertex_index_bytes*4+n.material_index_bytes;M=n.vertex_index_bytes*4+n.material_index_bytes+n.normal_index_bytes;Q=n.vertex_index_bytes*4+n.material_index_bytes+n.normal_index_bytes*2;F=n.vertex_index_bytes*4+n.material_index_bytes+n.normal_index_bytes*3;W=n.uv_index_bytes;Y=n.uv_index_bytes*2;S=n.uv_index_bytes;H=n.uv_index_bytes*2;R=n.uv_index_bytes*3;D+=function(q){var r,A,I,V=n.vertex_coordinate_bytes*3,ba=q+n.nvertices*V;for(q=q;q<ba;q+=V){r=k(a,q);A=k(a,q+n.vertex_coordinate_bytes);I=
  228. k(a,q+n.vertex_coordinate_bytes*2);THREE.Loader.prototype.v(v,r,A,I)}return n.nvertices*V}(D);D+=function(q){var r,A,I,V=n.normal_coordinate_bytes*3,ba=q+n.nnormals*V;for(q=q;q<ba;q+=V){r=o(a,q);A=o(a,q+n.normal_coordinate_bytes);I=o(a,q+n.normal_coordinate_bytes*2);O.push(r/127,A/127,I/127)}return n.nnormals*V}(D);D+=function(q){var r,A,I=n.uv_coordinate_bytes*2,V=q+n.nuvs*I;for(q=q;q<V;q+=I){r=k(a,q);A=k(a,q+n.uv_coordinate_bytes);L.push(r,A)}return n.nuvs*I}(D);D+=function(q){var r,A=n.vertex_index_bytes*
  229. 3+n.material_index_bytes,I=q+n.ntri_flat*A;for(r=q;r<I;r+=A)c(r);return I-q}(D);D+=function(q){var r,A=n.vertex_index_bytes*3+n.material_index_bytes+n.normal_index_bytes*3,I=q+n.ntri_smooth*A;for(r=q;r<I;r+=A)u(r);return I-q}(D);D+=function(q){var r,A=n.vertex_index_bytes*3+n.material_index_bytes,I=A+n.uv_index_bytes*3,V=q+n.ntri_flat_uv*I;for(r=q;r<V;r+=I){c(r);C(r+A)}return V-q}(D);D+=function(q){var r,A=n.vertex_index_bytes*3+n.material_index_bytes+n.normal_index_bytes*3,I=A+n.uv_index_bytes*3,
  230. V=q+n.ntri_smooth_uv*I;for(r=q;r<V;r+=I){u(r);C(r+A)}return V-q}(D);D+=function(q){var r,A=n.vertex_index_bytes*4+n.material_index_bytes,I=q+n.nquad_flat*A;for(r=q;r<I;r+=A)y(r);return I-q}(D);D+=function(q){var r,A=n.vertex_index_bytes*4+n.material_index_bytes+n.normal_index_bytes*4,I=q+n.nquad_smooth*A;for(r=q;r<I;r+=A)B(r);return I-q}(D);D+=function(q){var r,A=n.vertex_index_bytes*4+n.material_index_bytes,I=A+n.uv_index_bytes*4,V=q+n.nquad_flat_uv*I;for(r=q;r<V;r+=I){y(r);K(r+A)}return V-q}(D);
  231. D+=function(q){var r,A=n.vertex_index_bytes*4+n.material_index_bytes+n.normal_index_bytes*4,I=A+n.uv_index_bytes*4,V=q+n.nquad_smooth_uv*I;for(r=q;r<V;r+=I){B(r);K(r+A)}return V-q}(D);this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};f.prototype=new THREE.Geometry;f.prototype.constructor=f;b(new f(e))},createModel:function(a,b,e){var d=function(f){var g=this;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(g,a.materials,f);(function(){var k,j,i,o,w;k=0;for(j=
  232. a.vertices.length;k<j;k+=3){i=a.vertices[k];o=a.vertices[k+1];w=a.vertices[k+2];THREE.Loader.prototype.v(g,i,o,w)}})();(function(){function k(B,C){THREE.Loader.prototype.f3(g,B[C],B[C+1],B[C+2],B[C+3])}function j(B,C){THREE.Loader.prototype.f3n(g,a.normals,B[C],B[C+1],B[C+2],B[C+3],B[C+4],B[C+5],B[C+6])}function i(B,C){THREE.Loader.prototype.f4(g,B[C],B[C+1],B[C+2],B[C+3],B[C+4])}function o(B,C){THREE.Loader.prototype.f4n(g,a.normals,B[C],B[C+1],B[C+2],B[C+3],B[C+4],B[C+5],B[C+6],B[C+7],B[C+8])}function w(B,
  233. C){var K,v,D;K=B[C];v=B[C+1];D=B[C+2];THREE.Loader.prototype.uv3(g,a.uvs[K*2],a.uvs[K*2+1],a.uvs[v*2],a.uvs[v*2+1],a.uvs[D*2],a.uvs[D*2+1])}function c(B,C){var K,v,D,n;K=B[C];v=B[C+1];D=B[C+2];n=B[C+3];THREE.Loader.prototype.uv4(g,a.uvs[K*2],a.uvs[K*2+1],a.uvs[v*2],a.uvs[v*2+1],a.uvs[D*2],a.uvs[D*2+1],a.uvs[n*2],a.uvs[n*2+1])}var u,y;u=0;for(y=a.triangles.length;u<y;u+=4)k(a.triangles,u);u=0;for(y=a.triangles_uv.length;u<y;u+=7){k(a.triangles_uv,u);w(a.triangles_uv,u+4)}u=0;for(y=a.triangles_n.length;u<
  234. y;u+=7)j(a.triangles_n,u);u=0;for(y=a.triangles_n_uv.length;u<y;u+=10){j(a.triangles_n_uv,u);w(a.triangles_n_uv,u+7)}u=0;for(y=a.quads.length;u<y;u+=5)i(a.quads,u);u=0;for(y=a.quads_uv.length;u<y;u+=9){i(a.quads_uv,u);c(a.quads_uv,u+5)}u=0;for(y=a.quads_n.length;u<y;u+=9)o(a.quads_n,u);u=0;for(y=a.quads_n_uv.length;u<y;u+=13){o(a.quads_n_uv,u);c(a.quads_n_uv,u+9)}})();this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};d.prototype=new THREE.Geometry;d.prototype.constructor=
  235. d;b(new d(e))},v:function(a,b,e,d){a.vertices.push(new THREE.Vertex(new THREE.Vector3(b,e,d)))},f3:function(a,b,e,d,f){a.faces.push(new THREE.Face3(b,e,d,null,a.materials[f]))},f4:function(a,b,e,d,f,g){a.faces.push(new THREE.Face4(b,e,d,f,null,a.materials[g]))},f3n:function(a,b,e,d,f,g,k,j,i){g=a.materials[g];var o=b[j*3],w=b[j*3+1];j=b[j*3+2];var c=b[i*3],u=b[i*3+1];i=b[i*3+2];a.faces.push(new THREE.Face3(e,d,f,[new THREE.Vector3(b[k*3],b[k*3+1],b[k*3+2]),new THREE.Vector3(o,w,j),new THREE.Vector3(c,
  236. u,i)],g))},f4n:function(a,b,e,d,f,g,k,j,i,o,w){k=a.materials[k];var c=b[i*3],u=b[i*3+1];i=b[i*3+2];var y=b[o*3],B=b[o*3+1];o=b[o*3+2];var C=b[w*3],K=b[w*3+1];w=b[w*3+2];a.faces.push(new THREE.Face4(e,d,f,g,[new THREE.Vector3(b[j*3],b[j*3+1],b[j*3+2]),new THREE.Vector3(c,u,i),new THREE.Vector3(y,B,o),new THREE.Vector3(C,K,w)],k))},uv3:function(a,b,e,d,f,g,k){var j=[];j.push(new THREE.UV(b,e));j.push(new THREE.UV(d,f));j.push(new THREE.UV(g,k));a.uvs.push(j)},uv4:function(a,b,e,d,f,g,k,j,i){var o=[];
  237. o.push(new THREE.UV(b,e));o.push(new THREE.UV(d,f));o.push(new THREE.UV(g,k));o.push(new THREE.UV(j,i));a.uvs.push(o)},init_materials:function(a,b,e){a.materials=[];for(var d=0;d<b.length;++d)a.materials[d]=[THREE.Loader.prototype.createMaterial(b[d],e)]},createMaterial:function(a,b){function e(g){g=Math.log(g)/Math.LN2;return Math.floor(g)==g}var d,f;if(a.map_diffuse&&b){f=document.createElement("canvas");d=new THREE.MeshLambertMaterial({map:new THREE.Texture(f)});f=new Image;f.onload=function(){if(!e(this.width)||
  238. !e(this.height)){var g=Math.pow(2,Math.round(Math.log(this.width)/Math.LN2)),k=Math.pow(2,Math.round(Math.log(this.height)/Math.LN2));d.map.image.width=g;d.map.image.height=k;d.map.image.getContext("2d").drawImage(this,0,0,g,k)}else d.map.image=this;d.map.image.loaded=1};f.src=b+"/"+a.map_diffuse}else if(a.col_diffuse){f=(a.col_diffuse[0]*255<<16)+(a.col_diffuse[1]*255<<8)+a.col_diffuse[2]*255;d=new THREE.MeshLambertMaterial({color:f,opacity:a.transparency})}else d=a.a_dbg_color?new THREE.MeshLambertMaterial({color:a.a_dbg_color}):
  239. new THREE.MeshLambertMaterial({color:15658734});return d}};