ThreeExtras.js 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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)+")"},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,x,E,l){l=l.clone().subSelf(x);E=E.clone().subSelf(x);var P=K.clone().subSelf(x);K=l.dot(l);x=l.dot(E);l=l.dot(P);var M=E.dot(E);E=E.dot(P);P=1/(K*M-x*x);M=(M*l-x*E)*P;K=(K*E-x*l)*P;return M>0&&K>0&&M+K<1}var e,d,f,g,k,h,i,c,w,z,
  16. s,u=a.geometry,y=u.vertices,C=[];e=0;for(d=u.faces.length;e<d;e++){f=u.faces[e];z=this.origin.clone();s=this.direction.clone();g=a.matrix.multiplyVector3(y[f.a].position.clone());k=a.matrix.multiplyVector3(y[f.b].position.clone());h=a.matrix.multiplyVector3(y[f.c].position.clone());i=f instanceof THREE.Face4?a.matrix.multiplyVector3(y[f.d].position.clone()):null;c=a.rotationMatrix.multiplyVector3(f.normal.clone());w=s.dot(c);if(w<0){c=c.dot((new THREE.Vector3).sub(g,z))/w;z=z.addSelf(s.multiplyScalar(c));
  17. if(f instanceof THREE.Face3){if(b(z,g,k,h)){f={distance:this.origin.distanceTo(z),point:z,face:f,object:a};C.push(f)}}else if(f instanceof THREE.Face4)if(b(z,g,k,i)||b(z,k,h,i)){f={distance:this.origin.distanceTo(z),point:z,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,h=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,c,w,z){h=false;b=i;e=c;d=w;f=z;a()};this.addPoint=function(i,c){if(h){h=false;b=i;e=c;d=i;f=c}else{b=b<i?b:i;e=e<c?e:c;d=d>i?d:i;f=f>c?
  19. f:c}a()};this.add3Points=function(i,c,w,z,s,u){if(h){h=false;b=i<w?i<s?i:s:w<s?w:s;e=c<z?c<u?c:u:z<u?z:u;d=i>w?i>s?i:s:w>s?w:s;f=c>z?c>u?c:u:z>u?z:u}else{b=i<w?i<s?i<b?i:b:s<b?s:b:w<s?w<b?w:b:s<b?s:b;e=c<z?c<u?c<e?c:e:u<e?u:e:z<u?z<e?z:e:u<e?u:e;d=i>w?i>s?i>d?i:d:s>d?s:d:w>s?w>d?w:d:s>d?s:d;f=c>z?c>u?c>f?c:f:u>f?u:f:z>u?z>f?z:f:u>f?u:f}a()};this.addRectangle=function(i){if(h){h=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(){h=true;f=d=e=b=0;a()};this.isEmpty=function(){return h};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,h,i,c,w,z,s,u,y,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=h||0;this.n31=i||0;this.n32=c||0;this.n33=w||1;this.n34=z||0;this.n41=s||0;this.n42=u||0;this.n43=y||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,h,i,c,w,z,s,u,y,C){this.n11=a;this.n12=b;this.n13=e;this.n14=d;this.n21=f;this.n22=g;this.n23=k;this.n24=h;this.n31=i;this.n32=c;this.n33=w;this.n34=z;this.n41=s;this.n42=u;this.n43=y;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,h=a.n22,i=a.n23,c=a.n24,w=a.n31,z=a.n32,
  27. s=a.n33,u=a.n34,y=a.n41,C=a.n42,K=a.n43,x=a.n44,E=b.n11,l=b.n12,P=b.n13,M=b.n14,j=b.n21,p=b.n22,n=b.n23,m=b.n24,r=b.n31,q=b.n32,v=b.n33,A=b.n34,D=b.n41,I=b.n42,X=b.n43,G=b.n44;this.n11=e*E+d*j+f*r+g*D;this.n12=e*l+d*p+f*q+g*I;this.n13=e*P+d*n+f*v+g*X;this.n14=e*M+d*m+f*A+g*G;this.n21=k*E+h*j+i*r+c*D;this.n22=k*l+h*p+i*q+c*I;this.n23=k*P+h*n+i*v+c*X;this.n24=k*M+h*m+i*A+c*G;this.n31=w*E+z*j+s*r+u*D;this.n32=w*l+z*p+s*q+u*I;this.n33=w*P+z*n+s*v+u*X;this.n34=w*M+z*m+s*A+u*G;this.n41=y*E+C*j+K*r+x*D;
  28. this.n42=y*l+C*p+K*q+x*I;this.n43=y*P+C*n+K*v+x*X;this.n44=y*M+C*m+K*A+x*G;return this},multiplySelf:function(a){var b=this.n11,e=this.n12,d=this.n13,f=this.n14,g=this.n21,k=this.n22,h=this.n23,i=this.n24,c=this.n31,w=this.n32,z=this.n33,s=this.n34,u=this.n41,y=this.n42,C=this.n43,K=this.n44,x=a.n11,E=a.n21,l=a.n31,P=a.n41,M=a.n12,j=a.n22,p=a.n32,n=a.n42,m=a.n13,r=a.n23,q=a.n33,v=a.n43,A=a.n14,D=a.n24,I=a.n34;a=a.n44;this.n11=b*x+e*E+d*l+f*P;this.n12=b*M+e*j+d*p+f*n;this.n13=b*m+e*r+d*q+f*v;this.n14=
  29. b*A+e*D+d*I+f*a;this.n21=g*x+k*E+h*l+i*P;this.n22=g*M+k*j+h*p+i*n;this.n23=g*m+k*r+h*q+i*v;this.n24=g*A+k*D+h*I+i*a;this.n31=c*x+w*E+z*l+s*P;this.n32=c*M+w*j+z*p+s*n;this.n33=c*m+w*r+z*q+s*v;this.n34=c*A+w*D+z*I+s*a;this.n41=u*x+y*E+C*l+K*P;this.n42=u*M+y*j+C*p+K*n;this.n43=u*m+y*r+C*q+K*v;this.n44=u*A+y*D+C*I+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,h=a.y,i=a.z;e.n11=g*k*k+d;e.n12=g*k*h-f*i;e.n13=g*k*i+f*h;e.n21=g*k*h+f*i;e.n22=g*h*h+d;e.n23=g*h*i-f*k;e.n31=g*k*i-f*h;e.n32=g*h*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],h=-b[6]*b[0]+b[2]*b[4],i=b[9]*b[4]-b[5]*b[8],c=-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*h;a.m[6]=b*i;a.m[7]=b*c;a.m[8]=b*w;return a};
  41. THREE.Matrix4.makeFrustum=function(a,b,e,d,f,g){var k,h,i;k=new THREE.Matrix4;h=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=h;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,h,i,c;k=new THREE.Matrix4;h=b-a;i=e-d;c=g-f;a=(b+a)/h;e=(e+d)/i;f=(g+f)/c;k.n11=2/h;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/c;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.material=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.material=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,h=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){h.set(0,0,0);b=0;for(e=g.normal.length;b<e;b++)h.addSelf(g.vertexNormals[b]);h.divideScalar(3)}else{b=this.vertices[g.a];e=this.vertices[g.b];k=this.vertices[g.c];h.sub(k.position,
  49. e.position);i.sub(b.position,e.position);h.crossSelf(i)}h.isZero()||h.normalize();g.normal.copy(h)}},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(A,D,I,X){g=A.vertices[D].position;k=A.vertices[I].position;
  51. h=A.vertices[X].position;i=f[0];c=f[1];w=f[2];z=k.x-g.x;s=h.x-g.x;u=k.y-g.y;y=h.y-g.y;C=k.z-g.z;K=h.z-g.z;x=c.u-i.u;E=w.u-i.u;l=c.v-i.v;P=w.v-i.v;M=1/(x*P-E*l);m.set((P*z-l*s)*M,(P*u-l*y)*M,(P*C-l*K)*M);r.set((x*s-E*z)*M,(x*y-E*u)*M,(x*K-E*C)*M);p[D].addSelf(m);p[I].addSelf(m);p[X].addSelf(m);n[D].addSelf(r);n[I].addSelf(r);n[X].addSelf(r)}var b,e,d,f,g,k,h,i,c,w,z,s,u,y,C,K,x,E,l,P,M,j,p=[],n=[],m=new THREE.Vector3,r=new THREE.Vector3,q=new THREE.Vector3,v=new THREE.Vector3;j=new THREE.Vector3;b=
  52. 0;for(e=this.vertices.length;b<e;b++){p[b]=new THREE.Vector3;n[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);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);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++){j.copy(this.vertices[b].normal);d=p[b];q.copy(d);q.subSelf(j.multiplyScalar(j.dot(d))).normalize();v.cross(this.vertices[b].normal,d);test=v.dot(n[b]);d=test<0?-1:1;this.vertices[b].tangent.set(q.x,q.y,q.z,d)}this.hasTangents=true},computeBoundingBox:function(){var a;if(this.vertices.length>0){this.bbox={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.bbox.x[0])this.bbox.x[0]=a.position.x;else if(a.position.x>this.bbox.x[1])this.bbox.x[1]=a.position.x;if(a.position.y<this.bbox.y[0])this.bbox.y[0]=a.position.y;else if(a.position.y>this.bbox.y[1])this.bbox.y[1]=a.position.y;if(a.position.z<this.bbox.z[0])this.bbox.z[0]=a.position.z;else if(a.position.z>
  55. this.bbox.z[1])this.bbox.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(w){var z=[];b=0;for(e=w.length;b<e;b++)w[b]==undefined?z.push("undefined"):z.push(w[b].toString());return z.join("_")}var b,e,d,f,g,k,h,i,c={};d=0;for(f=this.faces.length;d<f;d++){g=this.faces[d];k=
  56. g.material;h=a(k);if(c[h]==undefined)c[h]={hash:h,counter:0};i=c[h].hash+"_"+c[h].counter;if(this.geometryChunks[i]==undefined)this.geometryChunks[i]={faces:[],material:k,vertices:0};g=g instanceof THREE.Face3?3:4;if(this.geometryChunks[i].vertices+g>65535){c[h].counter+=1;i=c[h].hash+"_"+c[h].counter;if(this.geometryChunks[i]==undefined)this.geometryChunks[i]={faces:[],material:k,vertices:0}}this.geometryChunks[i].faces.push(d);this.geometryChunks[i].vertices+=g}},toString:function(){return"THREE.Geometry ( vertices: "+
  57. this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
  58. THREE.Camera=function(a,b,e,d){this.position=new THREE.Vector3;this.target={position:new THREE.Vector3};this.up=new THREE.Vector3(0,1,0);this.matrix=new THREE.Matrix4;this.projectionMatrix=THREE.Matrix4.makePerspective(a,b,e,d);this.autoUpdateMatrix=true;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.toString=function(){return"THREE.Camera ( "+this.position+", "+this.target.position+" )"}};THREE.Light=function(a){this.color=new THREE.Color(a)};THREE.AmbientLight=function(a){THREE.Light.call(this,a)};THREE.AmbientLight.prototype=new THREE.Light;THREE.AmbientLight.prototype.constructor=THREE.AmbientLight;
  60. 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;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;
  61. 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.autoUpdateMatrix=this.visible=true;this.updateMatrix=function(){this.matrixPosition=THREE.Matrix4.translationMatrix(this.position.x,this.position.y,this.position.z);
  62. 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);this.matrix.multiplySelf(this.rotationMatrix);this.matrix.multiplySelf(this.scaleMatrix)}};THREE.Object3DCounter={value:0};
  63. THREE.Particle=function(a){THREE.Object3D.call(this);this.material=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.material=b instanceof Array?b:[b]};THREE.Line.prototype=new THREE.Object3D;THREE.Line.prototype.constructor=THREE.Line;
  64. THREE.Mesh=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.material=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;
  65. 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}this.toString=function(){return"THREE.LineBasicMaterial (<br/>color: "+
  66. this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>linewidth: "+this.linewidth+"<br/>linecap: "+this.linecap+"<br/>linejoin: "+this.linejoin+"<br/>)"}};
  67. 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.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=
  68. 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.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=
  69. 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}this.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: "+
  70. 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.MeshBasicMaterialCounter={value:0};
  71. 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.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=
  72. 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.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=
  73. 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}this.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: "+
  74. this.shading+"<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.MeshLambertMaterialCounter={value:0};
  75. 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.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=this.wireframe_linecap=
  76. "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=
  77. a.reflectivity;if(a.refraction_ratio!==undefined)this.refraction_ratio=a.refraction_ratio;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!==undefined)this.wireframe_linejoin=
  78. a.wireframe_linejoin}this.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: "+
  79. 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};
  80. THREE.MeshDepthMaterial=function(a){this.near=1;this.far=1E3;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.near!==undefined)this.near=a.near;if(a.far!==undefined)this.far=a.far;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}this.__2near=2*this.near;this.__farPlusNear=this.far+this.near;this.__farMinusNear=
  81. this.far-this.near;this.toString=function(){return"THREE.MeshDepthMaterial"}};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}this.toString=function(){return"THREE.MeshNormalMaterial"}};THREE.MeshFaceMaterial=function(){this.toString=function(){return"THREE.MeshFaceMaterial"}};
  82. 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!==
  83. 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}this.toString=function(){return"THREE.MeshShaderMaterial (<br/>id: "+this.id+
  84. "<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};
  85. 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}this.toString=function(){return"THREE.ParticleBasicMaterial (<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>opacity: "+this.opacity+"<br/>blending: "+
  86. 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}this.toString=function(){return"THREE.ParticleCircleMaterial (<br/>color: "+this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>)"}};
  87. THREE.ParticleDOMMaterial=function(a){this.domElement=a;this.toString=function(){return"THREE.ParticleDOMMaterial ( domElement: "+this.domElement+" )"}};
  88. 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;this.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: "+
  89. this.min_filter+"<br/>)"}};THREE.MultiplyOperation=0;THREE.MixOperation=1;THREE.RepeatWrapping=0;THREE.ClampToEdgeWrapping=1;THREE.MirroredRepeatWrapping=2;THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLinearFilter=5;THREE.LinearFilter=6;THREE.LinearMipMapNearestFilter=7;THREE.LinearMipMapLinearFilter=8;THREE.CubeReflectionMapping=function(){};THREE.CubeRefractionMapping=function(){};THREE.LatitudeReflectionMapping=function(){};THREE.LatitudeRefractionMapping=function(){};
  90. THREE.SphericalReflectionMapping=function(){};THREE.SphericalRefractionMapping=function(){};THREE.UVMapping=function(){};
  91. 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+" )"}};
  92. THREE.Fog=function(a,b){this.color=new THREE.Color(a);this.density=b||2.5E-4};
  93. THREE.Projector=function(){function a(p,n){return n.z-p.z}function b(p,n){var m=0,r=1,q=p.z+p.w,v=n.z+n.w,A=-p.z+p.w,D=-n.z+n.w;if(q>=0&&v>=0&&A>=0&&D>=0)return true;else if(q<0&&v<0||A<0&&D<0)return false;else{if(q<0)m=Math.max(m,q/(q-v));else if(v<0)r=Math.min(r,q/(q-v));if(A<0)m=Math.max(m,A/(A-D));else if(D<0)r=Math.min(r,A/(A-D));if(r<m)return false;else{p.lerpSelf(n,m);n.lerpSelf(p,1-r);return true}}}var e,d,f=[],g,k,h,i=[],c,w,z=[],s,u,y=[],C=new THREE.Vector4,K=new THREE.Vector4,x=new THREE.Matrix4,
  94. E=new THREE.Matrix4,l=[],P=new THREE.Vector4,M=new THREE.Vector4,j;this.projectObjects=function(p,n,m){var r=[],q,v;d=0;x.multiply(n.projectionMatrix,n.matrix);l[0]=new THREE.Vector4(x.n41-x.n11,x.n42-x.n12,x.n43-x.n13,x.n44-x.n14);l[1]=new THREE.Vector4(x.n41+x.n11,x.n42+x.n12,x.n43+x.n13,x.n44+x.n14);l[2]=new THREE.Vector4(x.n41+x.n21,x.n42+x.n22,x.n43+x.n23,x.n44+x.n24);l[3]=new THREE.Vector4(x.n41-x.n21,x.n42-x.n22,x.n43-x.n23,x.n44-x.n24);l[4]=new THREE.Vector4(x.n41-x.n31,x.n42-x.n32,x.n43-
  95. x.n33,x.n44-x.n34);l[5]=new THREE.Vector4(x.n41+x.n31,x.n42+x.n32,x.n43+x.n33,x.n44+x.n34);n=0;for(q=l.length;n<q;n++){v=l[n];v.divideScalar(Math.sqrt(v.x*v.x+v.y*v.y+v.z*v.z))}q=p.objects;p=0;for(n=q.length;p<n;p++){v=q[p];var A;if(!(A=!v.visible)){a:{A=void 0;for(var D=v.position,I=-v.geometry.boundingSphere.radius*Math.max(v.scale.x,Math.max(v.scale.y,v.scale.z)),X=0;X<6;X++){A=l[X].x*D.x+l[X].y*D.y+l[X].z*D.z+l[X].w;if(A<=I){A=false;break a}}A=true}A=!A}if(!A){e=f[d]=f[d]||new THREE.RenderableObject;
  96. C.copy(v.position);x.multiplyVector3(C);e.object=v;e.z=C.z;r.push(e);d++}}m&&r.sort(a);return r};this.projectScene=function(p,n,m){var r=[],q,v,A,D,I,X,G,Q,R,U,V,N,B,J,o,t;h=w=u=0;n.autoUpdateMatrix&&n.updateMatrix();x.multiply(n.projectionMatrix,n.matrix);X=p.objects;p=0;for(q=X.length;p<q;p++){G=X[p];if(G.visible){G.autoUpdateMatrix&&G.updateMatrix();Q=G.matrix;R=G.rotationMatrix;U=G.material;V=G.overdraw;if(G instanceof THREE.Mesh){N=G.geometry;B=N.vertices;v=0;for(A=B.length;v<A;v++){J=B[v];J.positionWorld.copy(J.position);
  97. Q.multiplyVector3(J.positionWorld);D=J.positionScreen;D.copy(J.positionWorld);x.multiplyVector4(D);D.multiplyScalar(1/D.w);J.__visible=D.z>0&&D.z<1}N=N.faces;v=0;for(A=N.length;v<A;v++){J=N[v];if(J instanceof THREE.Face3){D=B[J.a];I=B[J.b];o=B[J.c];if(D.__visible&&I.__visible&&o.__visible)if(G.doubleSided||G.flipSided!=(o.positionScreen.x-D.positionScreen.x)*(I.positionScreen.y-D.positionScreen.y)-(o.positionScreen.y-D.positionScreen.y)*(I.positionScreen.x-D.positionScreen.x)<0){g=i[h]=i[h]||new THREE.RenderableFace3;
  98. g.v1.positionWorld.copy(D.positionWorld);g.v2.positionWorld.copy(I.positionWorld);g.v3.positionWorld.copy(o.positionWorld);g.v1.positionScreen.copy(D.positionScreen);g.v2.positionScreen.copy(I.positionScreen);g.v3.positionScreen.copy(o.positionScreen);g.normalWorld.copy(J.normal);R.multiplyVector3(g.normalWorld);g.centroidWorld.copy(J.centroid);Q.multiplyVector3(g.centroidWorld);g.centroidScreen.copy(g.centroidWorld);x.multiplyVector3(g.centroidScreen);o=J.vertexNormals;j=g.vertexNormalsWorld;D=0;
  99. for(I=o.length;D<I;D++){t=j[D]=j[D]||new THREE.Vector3;t.copy(o[D]);R.multiplyVector3(t)}g.z=g.centroidScreen.z;g.meshMaterial=U;g.faceMaterial=J.material;g.overdraw=V;if(G.geometry.uvs[v]){g.uvs[0]=G.geometry.uvs[v][0];g.uvs[1]=G.geometry.uvs[v][1];g.uvs[2]=G.geometry.uvs[v][2]}r.push(g);h++}}else if(J instanceof THREE.Face4){D=B[J.a];I=B[J.b];o=B[J.c];t=B[J.d];if(D.__visible&&I.__visible&&o.__visible&&t.__visible)if(G.doubleSided||G.flipSided!=((t.positionScreen.x-D.positionScreen.x)*(I.positionScreen.y-
  100. D.positionScreen.y)-(t.positionScreen.y-D.positionScreen.y)*(I.positionScreen.x-D.positionScreen.x)<0||(I.positionScreen.x-o.positionScreen.x)*(t.positionScreen.y-o.positionScreen.y)-(I.positionScreen.y-o.positionScreen.y)*(t.positionScreen.x-o.positionScreen.x)<0)){g=i[h]=i[h]||new THREE.RenderableFace3;g.v1.positionWorld.copy(D.positionWorld);g.v2.positionWorld.copy(I.positionWorld);g.v3.positionWorld.copy(t.positionWorld);g.v1.positionScreen.copy(D.positionScreen);g.v2.positionScreen.copy(I.positionScreen);
  101. g.v3.positionScreen.copy(t.positionScreen);g.normalWorld.copy(J.normal);R.multiplyVector3(g.normalWorld);g.centroidWorld.copy(J.centroid);Q.multiplyVector3(g.centroidWorld);g.centroidScreen.copy(g.centroidWorld);x.multiplyVector3(g.centroidScreen);g.z=g.centroidScreen.z;g.meshMaterial=U;g.faceMaterial=J.material;g.overdraw=V;if(G.geometry.uvs[v]){g.uvs[0]=G.geometry.uvs[v][0];g.uvs[1]=G.geometry.uvs[v][1];g.uvs[2]=G.geometry.uvs[v][3]}r.push(g);h++;k=i[h]=i[h]||new THREE.RenderableFace3;k.v1.positionWorld.copy(I.positionWorld);
  102. k.v2.positionWorld.copy(o.positionWorld);k.v3.positionWorld.copy(t.positionWorld);k.v1.positionScreen.copy(I.positionScreen);k.v2.positionScreen.copy(o.positionScreen);k.v3.positionScreen.copy(t.positionScreen);k.normalWorld.copy(g.normalWorld);k.centroidWorld.copy(g.centroidWorld);k.centroidScreen.copy(g.centroidScreen);k.z=k.centroidScreen.z;k.meshMaterial=U;k.faceMaterial=J.material;k.overdraw=V;if(G.geometry.uvs[v]){k.uvs[0]=G.geometry.uvs[v][1];k.uvs[1]=G.geometry.uvs[v][2];k.uvs[2]=G.geometry.uvs[v][3]}r.push(k);
  103. h++}}}}else if(G instanceof THREE.Line){E.multiply(x,Q);B=G.geometry.vertices;J=B[0];J.positionScreen.copy(J.position);E.multiplyVector4(J.positionScreen);v=1;for(A=B.length;v<A;v++){D=B[v];D.positionScreen.copy(D.position);E.multiplyVector4(D.positionScreen);I=B[v-1];P.copy(D.positionScreen);M.copy(I.positionScreen);if(b(P,M)){P.multiplyScalar(1/P.w);M.multiplyScalar(1/M.w);c=z[w]=z[w]||new THREE.RenderableLine;c.v1.positionScreen.copy(P);c.v2.positionScreen.copy(M);c.z=Math.max(P.z,M.z);c.material=
  104. G.material;r.push(c);w++}}}else if(G instanceof THREE.Particle){K.set(G.position.x,G.position.y,G.position.z,1);x.multiplyVector4(K);K.z/=K.w;if(K.z>0&&K.z<1){s=y[u]=y[u]||new THREE.RenderableParticle;s.x=K.x/K.w;s.y=K.y/K.w;s.z=K.z;s.rotation=G.rotation.z;s.scale.x=G.scale.x*Math.abs(s.x-(K.x+n.projectionMatrix.n11)/(K.w+n.projectionMatrix.n14));s.scale.y=G.scale.y*Math.abs(s.y-(K.y+n.projectionMatrix.n22)/(K.w+n.projectionMatrix.n24));s.material=G.material;r.push(s);u++}}}}m&&r.sort(a);return r};
  105. this.unprojectVector=function(p,n){var m=new THREE.Matrix4;m.multiply(THREE.Matrix4.makeInvert(n.matrix),THREE.Matrix4.makeInvert(n.projectionMatrix));m.multiplyVector3(p);return p}};
  106. 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,h){e=k;d=h;f=e/2;g=d/2};this.render=function(k,h){var i,c,w,z,s,u,y,C;a=b.projectScene(k,h);i=0;for(c=a.length;i<c;i++){s=a[i];if(s instanceof THREE.RenderableParticle){y=s.x*f+f;C=s.y*g+g;w=0;for(z=s.material.length;w<z;w++){u=s.material[w];if(u instanceof THREE.ParticleDOMMaterial){u=u.domElement;u.style.left=y+"px";u.style.top=C+"px"}}}}}};
  107. THREE.CanvasRenderer=function(){var a=null,b=new THREE.Projector,e=document.createElement("canvas"),d,f,g,k,h=e.getContext("2d"),i=1,c=0,w=null,z=null,s=1,u,y,C,K,x,E,l,P,M,j=new THREE.Color,p=new THREE.Color,n=new THREE.Color,m=new THREE.Color,r=new THREE.Color,q,v,A,D,I,X,G,Q,R,U,V=new THREE.Rectangle,N=new THREE.Rectangle,B=new THREE.Rectangle,J=false,o=new THREE.Color,t=new THREE.Color,F=new THREE.Color,O=new THREE.Color,Y=Math.PI*2,Z=new THREE.Vector3,ea,ma,oa,fa,ra,va,pa=16;ea=document.createElement("canvas");
  108. ea.width=ea.height=2;ma=ea.getContext("2d");ma.fillStyle="rgba(0,0,0,1)";ma.fillRect(0,0,2,2);oa=ma.getImageData(0,0,2,2);fa=oa.data;ra=document.createElement("canvas");ra.width=ra.height=pa;va=ra.getContext("2d");va.translate(-pa/2,-pa/2);va.scale(pa,pa);pa--;this.domElement=e;this.sortElements=this.sortObjects=this.autoClear=true;this.setSize=function(ia,wa){d=ia;f=wa;g=d/2;k=f/2;e.width=d;e.height=f;V.set(-g,-k,g,k)};this.clear=function(){if(!N.isEmpty()){N.inflate(1);N.minSelf(V);h.clearRect(N.getX(),
  109. N.getY(),N.getWidth(),N.getHeight());N.empty()}};this.render=function(ia,wa){function Ka(H){var W,T,L,S=H.lights;t.setRGB(0,0,0);F.setRGB(0,0,0);O.setRGB(0,0,0);H=0;for(W=S.length;H<W;H++){T=S[H];L=T.color;if(T instanceof THREE.AmbientLight){t.r+=L.r;t.g+=L.g;t.b+=L.b}else if(T instanceof THREE.DirectionalLight){F.r+=L.r;F.g+=L.g;F.b+=L.b}else if(T instanceof THREE.PointLight){O.r+=L.r;O.g+=L.g;O.b+=L.b}}}function xa(H,W,T,L){var S,$,ba,ca,da=H.lights;H=0;for(S=da.length;H<S;H++){$=da[H];ba=$.color;
  110. ca=$.intensity;if($ instanceof THREE.DirectionalLight){$=T.dot($.position)*ca;if($>0){L.r+=ba.r*$;L.g+=ba.g*$;L.b+=ba.b*$}}else if($ instanceof THREE.PointLight){Z.sub($.position,W);Z.normalize();$=T.dot(Z)*ca;if($>0){L.r+=ba.r*$;L.g+=ba.g*$;L.b+=ba.b*$}}}}function La(H,W,T){if(T.opacity!=0){Ca(T.opacity);ya(T.blending);var L,S,$,ba,ca,da;if(T instanceof THREE.ParticleBasicMaterial){if(T.map){ba=T.map;ca=ba.width>>1;da=ba.height>>1;S=W.scale.x*g;$=W.scale.y*k;T=S*ca;L=$*da;B.set(H.x-T,H.y-L,H.x+T,
  111. H.y+L);if(V.instersects(B)){h.save();h.translate(H.x,H.y);h.rotate(-W.rotation);h.scale(S,-$);h.translate(-ca,-da);h.drawImage(ba,0,0);h.restore()}}}else if(T instanceof THREE.ParticleCircleMaterial){if(J){o.r=t.r+F.r+O.r;o.g=t.g+F.g+O.g;o.b=t.b+F.b+O.b;j.r=T.color.r*o.r;j.g=T.color.g*o.g;j.b=T.color.b*o.b;j.updateStyleString()}else j.__styleString=T.color.__styleString;T=W.scale.x*g;L=W.scale.y*k;B.set(H.x-T,H.y-L,H.x+T,H.y+L);if(V.instersects(B)){S=j.__styleString;if(z!=S)h.fillStyle=z=S;h.save();
  112. h.translate(H.x,H.y);h.rotate(-W.rotation);h.scale(T,L);h.beginPath();h.arc(0,0,1,0,Y,true);h.closePath();h.fill();h.restore()}}}}function Ma(H,W,T,L){if(L.opacity!=0){Ca(L.opacity);ya(L.blending);h.beginPath();h.moveTo(H.positionScreen.x,H.positionScreen.y);h.lineTo(W.positionScreen.x,W.positionScreen.y);h.closePath();if(L instanceof THREE.LineBasicMaterial){j.__styleString=L.color.__styleString;H=L.linewidth;if(s!=H)h.lineWidth=s=H;H=j.__styleString;if(w!=H)h.strokeStyle=w=H;h.stroke();B.inflate(L.linewidth*
  113. 2)}}}function Ga(H,W,T,L,S,$){if(S.opacity!=0){Ca(S.opacity);ya(S.blending);K=H.positionScreen.x;x=H.positionScreen.y;E=W.positionScreen.x;l=W.positionScreen.y;P=T.positionScreen.x;M=T.positionScreen.y;h.beginPath();h.moveTo(K,x);h.lineTo(E,l);h.lineTo(P,M);h.lineTo(K,x);h.closePath();if(S instanceof THREE.MeshBasicMaterial)if(S.map)S.map.image.loaded&&S.map.mapping instanceof THREE.UVMapping&&sa(K,x,E,l,P,M,S.map.image,L.uvs[0].u,L.uvs[0].v,L.uvs[1].u,L.uvs[1].v,L.uvs[2].u,L.uvs[2].v);else if(S.env_map){if(S.env_map.image.loaded)if(S.env_map.mapping instanceof
  114. THREE.SphericalReflectionMapping){H=wa.matrix;Z.copy(L.vertexNormalsWorld[0]);I=(Z.x*H.n11+Z.y*H.n12+Z.z*H.n13)*0.5+0.5;X=-(Z.x*H.n21+Z.y*H.n22+Z.z*H.n23)*0.5+0.5;Z.copy(L.vertexNormalsWorld[1]);G=(Z.x*H.n11+Z.y*H.n12+Z.z*H.n13)*0.5+0.5;Q=-(Z.x*H.n21+Z.y*H.n22+Z.z*H.n23)*0.5+0.5;Z.copy(L.vertexNormalsWorld[2]);R=(Z.x*H.n11+Z.y*H.n12+Z.z*H.n13)*0.5+0.5;U=-(Z.x*H.n21+Z.y*H.n22+Z.z*H.n23)*0.5+0.5;sa(K,x,E,l,P,M,S.env_map.image,I,X,G,Q,R,U)}}else S.wireframe?za(S.color.__styleString,S.wireframe_linewidth):
  115. Aa(S.color.__styleString);else if(S instanceof THREE.MeshLambertMaterial){if(S.map&&!S.wireframe){S.map.mapping instanceof THREE.UVMapping&&sa(K,x,E,l,P,M,S.map.image,L.uvs[0].u,L.uvs[0].v,L.uvs[1].u,L.uvs[1].v,L.uvs[2].u,L.uvs[2].v);ya(THREE.SubtractiveBlending)}if(J)if(!S.wireframe&&S.shading==THREE.SmoothShading&&L.vertexNormalsWorld.length==3){p.r=n.r=m.r=t.r;p.g=n.g=m.g=t.g;p.b=n.b=m.b=t.b;xa($,L.v1.positionWorld,L.vertexNormalsWorld[0],p);xa($,L.v2.positionWorld,L.vertexNormalsWorld[1],n);xa($,
  116. L.v3.positionWorld,L.vertexNormalsWorld[2],m);r.r=(n.r+m.r)*0.5;r.g=(n.g+m.g)*0.5;r.b=(n.b+m.b)*0.5;D=Ha(p,n,m,r);sa(K,x,E,l,P,M,D,0,0,1,0,0,1)}else{o.r=t.r;o.g=t.g;o.b=t.b;xa($,L.centroidWorld,L.normalWorld,o);j.r=S.color.r*o.r;j.g=S.color.g*o.g;j.b=S.color.b*o.b;j.updateStyleString();S.wireframe?za(j.__styleString,S.wireframe_linewidth):Aa(j.__styleString)}else S.wireframe?za(S.color.__styleString,S.wireframe_linewidth):Aa(S.color.__styleString)}else if(S instanceof THREE.MeshDepthMaterial){q=S.__2near;
  117. v=S.__farPlusNear;A=S.__farMinusNear;p.r=p.g=p.b=1-q/(v-H.positionScreen.z*A);n.r=n.g=n.b=1-q/(v-W.positionScreen.z*A);m.r=m.g=m.b=1-q/(v-T.positionScreen.z*A);r.r=(n.r+m.r)*0.5;r.g=(n.g+m.g)*0.5;r.b=(n.b+m.b)*0.5;D=Ha(p,n,m,r);sa(K,x,E,l,P,M,D,0,0,1,0,0,1)}else if(S instanceof THREE.MeshNormalMaterial){j.r=Da(L.normalWorld.x);j.g=Da(L.normalWorld.y);j.b=Da(L.normalWorld.z);j.updateStyleString();S.wireframe?za(j.__styleString,S.wireframe_linewidth):Aa(j.__styleString)}}}function za(H,W){if(w!=H)h.strokeStyle=
  118. w=H;if(s!=W)h.lineWidth=s=W;h.stroke();B.inflate(W*2)}function Aa(H){if(z!=H)h.fillStyle=z=H;h.fill()}function sa(H,W,T,L,S,$,ba,ca,da,ja,ga,ka,ta){var na,la;na=ba.width-1;la=ba.height-1;ca*=na;da*=la;ja*=na;ga*=la;ka*=na;ta*=la;T-=H;L-=W;S-=H;$-=W;ja-=ca;ga-=da;ka-=ca;ta-=da;la=1/(ja*ta-ka*ga);na=(ta*T-ga*S)*la;ga=(ta*L-ga*$)*la;T=(ja*S-ka*T)*la;L=(ja*$-ka*L)*la;H=H-na*ca-T*da;W=W-ga*ca-L*da;h.save();h.transform(na,ga,T,L,H,W);h.clip();h.drawImage(ba,0,0);h.restore()}function Ca(H){if(i!=H)h.globalAlpha=
  119. i=H}function ya(H){if(c!=H){switch(H){case THREE.NormalBlending:h.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:h.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:h.globalCompositeOperation="darker"}c=H}}function Ha(H,W,T,L){var S=~~(H.r*255),$=~~(H.g*255);H=~~(H.b*255);var ba=~~(W.r*255),ca=~~(W.g*255);W=~~(W.b*255);var da=~~(T.r*255),ja=~~(T.g*255);T=~~(T.b*255);var ga=~~(L.r*255),ka=~~(L.g*255);L=~~(L.b*255);fa[0]=S<0?0:S>255?255:S;fa[1]=$<0?0:
  120. $>255?255:$;fa[2]=H<0?0:H>255?255:H;fa[4]=ba<0?0:ba>255?255:ba;fa[5]=ca<0?0:ca>255?255:ca;fa[6]=W<0?0:W>255?255:W;fa[8]=da<0?0:da>255?255:da;fa[9]=ja<0?0:ja>255?255:ja;fa[10]=T<0?0:T>255?255:T;fa[12]=ga<0?0:ga>255?255:ga;fa[13]=ka<0?0:ka>255?255:ka;fa[14]=L<0?0:L>255?255:L;ma.putImageData(oa,0,0);va.drawImage(ea,0,0);return ra}function Da(H){H=(H+1)*0.5;return H<0?0:H>1?1:H}function Ea(H,W){var T=W.x-H.x,L=W.y-H.y,S=1/Math.sqrt(T*T+L*L);T*=S;L*=S;W.x+=T;W.y+=L;H.x-=T;H.y-=L}var Ba,Ia,aa,ha,qa,Fa,
  121. Ja,ua;h.setTransform(1,0,0,-1,g,k);this.autoClear&&this.clear();a=b.projectScene(ia,wa,this.sortElements);(J=ia.lights.length>0)&&Ka(ia);Ba=0;for(Ia=a.length;Ba<Ia;Ba++){aa=a[Ba];B.empty();if(aa instanceof THREE.RenderableParticle){u=aa;u.x*=g;u.y*=k;ha=0;for(qa=aa.material.length;ha<qa;ha++)La(u,aa,aa.material[ha],ia)}else if(aa instanceof THREE.RenderableLine){u=aa.v1;y=aa.v2;u.positionScreen.x*=g;u.positionScreen.y*=k;y.positionScreen.x*=g;y.positionScreen.y*=k;B.addPoint(u.positionScreen.x,u.positionScreen.y);
  122. B.addPoint(y.positionScreen.x,y.positionScreen.y);if(V.instersects(B)){ha=0;for(qa=aa.material.length;ha<qa;)Ma(u,y,aa,aa.material[ha++],ia)}}else if(aa instanceof THREE.RenderableFace3){u=aa.v1;y=aa.v2;C=aa.v3;u.positionScreen.x*=g;u.positionScreen.y*=k;y.positionScreen.x*=g;y.positionScreen.y*=k;C.positionScreen.x*=g;C.positionScreen.y*=k;if(aa.overdraw){Ea(u.positionScreen,y.positionScreen);Ea(y.positionScreen,C.positionScreen);Ea(C.positionScreen,u.positionScreen)}B.add3Points(u.positionScreen.x,
  123. u.positionScreen.y,y.positionScreen.x,y.positionScreen.y,C.positionScreen.x,C.positionScreen.y);if(V.instersects(B)){ha=0;for(qa=aa.meshMaterial.length;ha<qa;){ua=aa.meshMaterial[ha++];if(ua instanceof THREE.MeshFaceMaterial){Fa=0;for(Ja=aa.faceMaterial.length;Fa<Ja;)(ua=aa.faceMaterial[Fa++])&&Ga(u,y,C,aa,ua,ia)}else Ga(u,y,C,aa,ua,ia)}}}N.addRectangle(B)}h.setTransform(1,0,0,1,0,0)}};
  124. THREE.SVGRenderer=function(){function a(Q,R,U){var V,N,B,J;V=0;for(N=Q.lights.length;V<N;V++){B=Q.lights[V];if(B instanceof THREE.DirectionalLight){J=R.normalWorld.dot(B.position)*B.intensity;if(J>0){U.r+=B.color.r*J;U.g+=B.color.g*J;U.b+=B.color.b*J}}else if(B instanceof THREE.PointLight){m.sub(B.position,R.centroidWorld);m.normalize();J=R.normalWorld.dot(m)*B.intensity;if(J>0){U.r+=B.color.r*J;U.g+=B.color.g*J;U.b+=B.color.b*J}}}}function b(Q,R,U,V,N,B){A=d(D++);A.setAttribute("d","M "+Q.positionScreen.x+
  125. " "+Q.positionScreen.y+" L "+R.positionScreen.x+" "+R.positionScreen.y+" L "+U.positionScreen.x+","+U.positionScreen.y+"z");if(N instanceof THREE.MeshBasicMaterial)l.__styleString=N.color.__styleString;else if(N instanceof THREE.MeshLambertMaterial)if(E){P.r=M.r;P.g=M.g;P.b=M.b;a(B,V,P);l.r=N.color.r*P.r;l.g=N.color.g*P.g;l.b=N.color.b*P.b;l.updateStyleString()}else l.__styleString=N.color.__styleString;else if(N instanceof THREE.MeshDepthMaterial){n=1-N.__2near/(N.__farPlusNear-V.z*N.__farMinusNear);
  126. l.setRGB(n,n,n)}else N instanceof THREE.MeshNormalMaterial&&l.setRGB(f(V.normalWorld.x),f(V.normalWorld.y),f(V.normalWorld.z));N.wireframe?A.setAttribute("style","fill: none; stroke: "+l.__styleString+"; stroke-width: "+N.wireframe_linewidth+"; stroke-opacity: "+N.opacity+"; stroke-linecap: "+N.wireframe_linecap+"; stroke-linejoin: "+N.wireframe_linejoin):A.setAttribute("style","fill: "+l.__styleString+"; fill-opacity: "+N.opacity);h.appendChild(A)}function e(Q,R,U,V,N,B,J){A=d(D++);A.setAttribute("d",
  127. "M "+Q.positionScreen.x+" "+Q.positionScreen.y+" L "+R.positionScreen.x+" "+R.positionScreen.y+" L "+U.positionScreen.x+","+U.positionScreen.y+" L "+V.positionScreen.x+","+V.positionScreen.y+"z");if(B instanceof THREE.MeshBasicMaterial)l.__styleString=B.color.__styleString;else if(B instanceof THREE.MeshLambertMaterial)if(E){P.r=M.r;P.g=M.g;P.b=M.b;a(J,N,P);l.r=B.color.r*P.r;l.g=B.color.g*P.g;l.b=B.color.b*P.b;l.updateStyleString()}else l.__styleString=B.color.__styleString;else if(B instanceof THREE.MeshDepthMaterial){n=
  128. 1-B.__2near/(B.__farPlusNear-N.z*B.__farMinusNear);l.setRGB(n,n,n)}else B instanceof THREE.MeshNormalMaterial&&l.setRGB(f(N.normalWorld.x),f(N.normalWorld.y),f(N.normalWorld.z));B.wireframe?A.setAttribute("style","fill: none; stroke: "+l.__styleString+"; stroke-width: "+B.wireframe_linewidth+"; stroke-opacity: "+B.opacity+"; stroke-linecap: "+B.wireframe_linecap+"; stroke-linejoin: "+B.wireframe_linejoin):A.setAttribute("style","fill: "+l.__styleString+"; fill-opacity: "+B.opacity);h.appendChild(A)}
  129. function d(Q){if(r[Q]==null){r[Q]=document.createElementNS("http://www.w3.org/2000/svg","path");G==0&&r[Q].setAttribute("shape-rendering","crispEdges");return r[Q]}return r[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,h=document.createElementNS("http://www.w3.org/2000/svg","svg"),i,c,w,z,s,u,y,C,K=new THREE.Rectangle,x=new THREE.Rectangle,E=false,l=new THREE.Color(16777215),P=new THREE.Color(16777215),M=new THREE.Color(0),j=new THREE.Color(0),
  130. p=new THREE.Color(0),n,m=new THREE.Vector3,r=[],q=[],v=[],A,D,I,X,G=1;this.domElement=h;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(Q){switch(Q){case "high":G=1;break;case "low":G=0}};this.setSize=function(Q,R){i=Q;c=R;w=i/2;z=c/2;h.setAttribute("viewBox",-w+" "+-z+" "+i+" "+c);h.setAttribute("width",i);h.setAttribute("height",c);K.set(-w,-z,w,z)};this.clear=function(){for(;h.childNodes.length>0;)h.removeChild(h.childNodes[0])};this.render=function(Q,R){var U,V,
  131. N,B,J,o,t,F;this.autoClear&&this.clear();g=k.projectScene(Q,R,this.sortElements);X=I=D=0;if(E=Q.lights.length>0){t=Q.lights;M.setRGB(0,0,0);j.setRGB(0,0,0);p.setRGB(0,0,0);U=0;for(V=t.length;U<V;U++){N=t[U];B=N.color;if(N instanceof THREE.AmbientLight){M.r+=B.r;M.g+=B.g;M.b+=B.b}else if(N instanceof THREE.DirectionalLight){j.r+=B.r;j.g+=B.g;j.b+=B.b}else if(N instanceof THREE.PointLight){p.r+=B.r;p.g+=B.g;p.b+=B.b}}}U=0;for(V=g.length;U<V;U++){t=g[U];x.empty();if(t instanceof THREE.RenderableParticle){s=
  132. t;s.x*=w;s.y*=-z;N=0;for(B=t.material.length;N<B;N++)if(F=t.material[N]){J=s;o=t;F=F;var O=I++;if(q[O]==null){q[O]=document.createElementNS("http://www.w3.org/2000/svg","circle");G==0&&q[O].setAttribute("shape-rendering","crispEdges")}A=q[O];A.setAttribute("cx",J.x);A.setAttribute("cy",J.y);A.setAttribute("r",o.scale.x*w);if(F instanceof THREE.ParticleCircleMaterial){if(E){P.r=M.r+j.r+p.r;P.g=M.g+j.g+p.g;P.b=M.b+j.b+p.b;l.r=F.color.r*P.r;l.g=F.color.g*P.g;l.b=F.color.b*P.b;l.updateStyleString()}else l=
  133. F.color;A.setAttribute("style","fill: "+l.__styleString)}h.appendChild(A)}}else if(t instanceof THREE.RenderableLine){s=t.v1;u=t.v2;s.positionScreen.x*=w;s.positionScreen.y*=-z;u.positionScreen.x*=w;u.positionScreen.y*=-z;x.addPoint(s.positionScreen.x,s.positionScreen.y);x.addPoint(u.positionScreen.x,u.positionScreen.y);if(K.instersects(x)){N=0;for(B=t.material.length;N<B;)if(F=t.material[N++]){J=s;o=u;F=F;O=X++;if(v[O]==null){v[O]=document.createElementNS("http://www.w3.org/2000/svg","line");G==
  134. 0&&v[O].setAttribute("shape-rendering","crispEdges")}A=v[O];A.setAttribute("x1",J.positionScreen.x);A.setAttribute("y1",J.positionScreen.y);A.setAttribute("x2",o.positionScreen.x);A.setAttribute("y2",o.positionScreen.y);if(F instanceof THREE.LineBasicMaterial){l.__styleString=F.color.__styleString;A.setAttribute("style","fill: none; stroke: "+l.__styleString+"; stroke-width: "+F.linewidth+"; stroke-opacity: "+F.opacity+"; stroke-linecap: "+F.linecap+"; stroke-linejoin: "+F.linejoin);h.appendChild(A)}}}}else if(t instanceof
  135. THREE.RenderableFace3){s=t.v1;u=t.v2;y=t.v3;s.positionScreen.x*=w;s.positionScreen.y*=-z;u.positionScreen.x*=w;u.positionScreen.y*=-z;y.positionScreen.x*=w;y.positionScreen.y*=-z;x.addPoint(s.positionScreen.x,s.positionScreen.y);x.addPoint(u.positionScreen.x,u.positionScreen.y);x.addPoint(y.positionScreen.x,y.positionScreen.y);if(K.instersects(x)){N=0;for(B=t.meshMaterial.length;N<B;){F=t.meshMaterial[N++];if(F instanceof THREE.MeshFaceMaterial){J=0;for(o=t.faceMaterial.length;J<o;)(F=t.faceMaterial[J++])&&
  136. b(s,u,y,t,F,Q)}else F&&b(s,u,y,t,F,Q)}}}else if(t instanceof THREE.RenderableFace4){s=t.v1;u=t.v2;y=t.v3;C=t.v4;s.positionScreen.x*=w;s.positionScreen.y*=-z;u.positionScreen.x*=w;u.positionScreen.y*=-z;y.positionScreen.x*=w;y.positionScreen.y*=-z;C.positionScreen.x*=w;C.positionScreen.y*=-z;x.addPoint(s.positionScreen.x,s.positionScreen.y);x.addPoint(u.positionScreen.x,u.positionScreen.y);x.addPoint(y.positionScreen.x,y.positionScreen.y);x.addPoint(C.positionScreen.x,C.positionScreen.y);if(K.instersects(x)){N=
  137. 0;for(B=t.meshMaterial.length;N<B;){F=t.meshMaterial[N++];if(F instanceof THREE.MeshFaceMaterial){J=0;for(o=t.faceMaterial.length;J<o;)(F=t.faceMaterial[J++])&&e(s,u,y,C,t,F,Q)}else F&&e(s,u,y,C,t,F,Q)}}}}}};
  138. THREE.WebGLRenderer=function(a){function b(j,p,n){var m=c.createProgram();n=["#ifdef GL_ES\nprecision highp float;\n#endif",n?"#define USE_FOG":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");var r=[c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","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");
  139. c.attachShader(m,k("fragment",n+j));c.attachShader(m,k("vertex",r+p));c.linkProgram(m);c.getProgramParameter(m,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(m,c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");m.uniforms={};m.attributes={};return m}function e(j,p){if(j.image.length==6){if(!j.image.__webGLTextureCube&&!j.image.__cubeMapInitialized&&j.image.loadCount==6){j.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,j.image.__webGLTextureCube);
  140. c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(var n=0;n<6;++n)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+n,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,j.image[n]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);j.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+
  141. p);c.bindTexture(c.TEXTURE_CUBE_MAP,j.image.__webGLTextureCube)}}function d(j,p){if(!j.__webGLTexture&&j.image.loaded){j.__webGLTexture=c.createTexture();c.bindTexture(c.TEXTURE_2D,j.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,j.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,h(j.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,h(j.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,h(j.mag_filter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,
  142. h(j.min_filter));c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+p);c.bindTexture(c.TEXTURE_2D,j.__webGLTexture)}function f(j,p){var n,m,r;n=0;for(m=p.length;n<m;n++){r=p[n];j.uniforms[r]=c.getUniformLocation(j,r)}}function g(j,p){var n,m,r;n=0;for(m=p.length;n<m;n++){r=p[n];j.attributes[r]=c.getAttribLocation(j,r)}}function k(j,p){var n;if(j=="fragment")n=c.createShader(c.FRAGMENT_SHADER);else if(j=="vertex")n=c.createShader(c.VERTEX_SHADER);c.shaderSource(n,
  143. p);c.compileShader(n);if(!c.getShaderParameter(n,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(n));return null}return n}function h(j){switch(j){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;
  144. case THREE.LinearMipMapNearestFilter:return c.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return c.LINEAR_MIPMAP_LINEAR}return 0}var i=document.createElement("canvas"),c,w,z,s=new THREE.Matrix4,u,y=new Float32Array(16),C=new Float32Array(16),K=new Float32Array(16),x=new Float32Array(9),E=new Float32Array(16),l=function(j,p){if(j){var n,m,r,q=pointLights=maxDirLights=maxPointLights=0;n=0;for(m=j.lights.length;n<m;n++){r=j.lights[n];r instanceof THREE.DirectionalLight&&q++;r instanceof
  145. THREE.PointLight&&pointLights++}if(pointLights+q<=p){maxDirLights=q;maxPointLights=pointLights}else{maxDirLights=Math.ceil(p*q/(pointLights+q));maxPointLights=p-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:p-1}}(a,4);fog=a?a.fog:null;this.domElement=i;this.autoClear=true;try{c=i.getContext("experimental-webgl",{antialias:true})}catch(P){}if(!c){alert("WebGL not supported");throw"cannot create webgl context";}c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);
  146. 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(0,0,0,0);w=z=function(j,p,n){var m=[j?"#define MAX_DIR_LIGHTS "+j:"",p?"#define MAX_POINT_LIGHTS "+p:"","uniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",j?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",j?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":
  147. "",p?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",p?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",p?"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;",
  148. j?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",j?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",j?"float directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );":"",j?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",j?"}":"",p?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",p?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",p?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
  149. "",p?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",p?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",p?"}":"","}\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"),
  150. r=[j?"#define MAX_DIR_LIGHTS "+j:"",p?"#define MAX_POINT_LIGHTS "+p:"","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;\n#ifdef USE_FOG\nuniform vec3 fogColor;\nuniform float fogDensity;\n#endif\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
  151. j?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",p?"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 );",
  152. p?"vec4 pointDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );":"",p?"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",p?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",p?"vec3 pointVector = normalize( vPointLightVector[ i ] );":"",p?"vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );":"",p?"float pointDotNormalHalf = dot( normal, pointHalfVector );":"",p?"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );":"",p?"float pointSpecularWeight = 0.0;":"",p?"if ( pointDotNormalHalf >= 0.0 )":
  153. "",p?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",p?"pointDiffuse += mColor * pointDiffuseWeight;":"",p?"pointSpecular += mSpecular * pointSpecularWeight;":"",p?"}":"",j?"vec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );":"",j?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",j?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",j?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",j?"vec3 dirVector = normalize( lDirection.xyz );":"",j?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
  154. "",j?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",j?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",j?"float dirSpecularWeight = 0.0;":"",j?"if ( dirDotNormalHalf >= 0.0 )":"",j?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",j?"dirDiffuse += mColor * dirDiffuseWeight;":"",j?"dirSpecular += mSpecular * dirSpecularWeight;":"",j?"}":"","vec4 totalLight = mAmbient;",j?"totalLight += dirDiffuse + dirSpecular;":"",p?"totalLight += pointDiffuse + pointSpecular;":
  155. "","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} else {\nif ( mixEnvMap ) {\ngl_FragColor = mix( mColor * mapColor, cubeColor, mReflectivity );\n} else {\ngl_FragColor = mColor * mapColor * cubeColor;\n}\n}\n#ifdef USE_FOG\nconst float LOG2 = 1.442695;\nfloat z = gl_FragCoord.z / gl_FragCoord.w;\nfloat fogFactor = exp2( - fogDensity * fogDensity * z * z * LOG2 );\nfogFactor = clamp( fogFactor, 0.0, 1.0 );\ngl_FragColor = mix( vec4( fogColor, 1.0 ), gl_FragColor, fogFactor );\n#endif\n}"].join("\n");
  156. m=b(r,m,n);c.useProgram(m);f(m,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract"]);n&&f(m,["fogColor","fogDensity"]);j&&f(m,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);p&&f(m,["pointLightNumber","pointLightColor",
  157. "pointLightPosition"]);c.uniform1i(m.uniforms.enableMap,0);c.uniform1i(m.uniforms.tMap,0);c.uniform1i(m.uniforms.enableCubeMap,0);c.uniform1i(m.uniforms.tCube,1);c.uniform1i(m.uniforms.mixEnvMap,0);c.uniform1i(m.uniforms.useRefract,0);g(m,["position","normal","uv"]);return m}(l.directional,l.point,fog);this.setSize=function(j,p){i.width=j;i.height=p;c.viewport(0,0,i.width,i.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(j,p){var n,m,r,q,v,
  158. A=[],D=[],I=[];q=[];v=[];c.uniform1i(j.uniforms.enableLighting,p.length);n=0;for(m=p.length;n<m;n++){r=p[n];if(r instanceof THREE.AmbientLight)A.push(r);else if(r instanceof THREE.DirectionalLight)I.push(r);else r instanceof THREE.PointLight&&D.push(r)}n=r=q=v=0;for(m=A.length;n<m;n++){r+=A[n].color.r;q+=A[n].color.g;v+=A[n].color.b}c.uniform3f(j.uniforms.ambientLightColor,r,q,v);q=[];v=[];n=0;for(m=I.length;n<m;n++){r=I[n];q.push(r.color.r*r.intensity);q.push(r.color.g*r.intensity);q.push(r.color.b*
  159. r.intensity);v.push(r.position.x);v.push(r.position.y);v.push(r.position.z)}if(I.length){c.uniform1i(j.uniforms.directionalLightNumber,I.length);c.uniform3fv(j.uniforms.directionalLightDirection,v);c.uniform3fv(j.uniforms.directionalLightColor,q)}q=[];v=[];n=0;for(m=D.length;n<m;n++){r=D[n];q.push(r.color.r*r.intensity);q.push(r.color.g*r.intensity);q.push(r.color.b*r.intensity);v.push(r.position.x);v.push(r.position.y);v.push(r.position.z)}if(D.length){c.uniform1i(j.uniforms.pointLightNumber,D.length);
  160. c.uniform3fv(j.uniforms.pointLightPosition,v);c.uniform3fv(j.uniforms.pointLightColor,q)}};this.createBuffers=function(j,p){var n,m,r,q,v,A,D,I,X,G=[],Q=[],R=[],U=[],V=[],N=[],B=0,J=j.geometry.geometryChunks[p],o;r=false;n=0;for(m=j.material.length;n<m;n++){meshMaterial=j.material[n];if(meshMaterial instanceof THREE.MeshFaceMaterial){v=0;for(o=J.material.length;v<o;v++)if(J.material[v]&&J.material[v].shading!=undefined&&J.material[v].shading==THREE.SmoothShading){r=true;break}}else if(meshMaterial&&
  161. meshMaterial.shading!=undefined&&meshMaterial.shading==THREE.SmoothShading){r=true;break}if(r)break}o=r;n=0;for(m=J.faces.length;n<m;n++){r=J.faces[n];q=j.geometry.faces[r];v=q.vertexNormals;faceNormal=q.normal;r=j.geometry.uvs[r];if(q instanceof THREE.Face3){A=j.geometry.vertices[q.a].position;D=j.geometry.vertices[q.b].position;I=j.geometry.vertices[q.c].position;R.push(A.x,A.y,A.z);R.push(D.x,D.y,D.z);R.push(I.x,I.y,I.z);if(j.geometry.hasTangents){A=j.geometry.vertices[q.a].tangent;D=j.geometry.vertices[q.b].tangent;
  162. I=j.geometry.vertices[q.c].tangent;V.push(A.x,A.y,A.z,A.w);V.push(D.x,D.y,D.z,D.w);V.push(I.x,I.y,I.z,I.w)}if(v.length==3&&o)for(q=0;q<3;q++)U.push(v[q].x,v[q].y,v[q].z);else for(q=0;q<3;q++)U.push(faceNormal.x,faceNormal.y,faceNormal.z);if(r)for(q=0;q<3;q++)N.push(r[q].u,r[q].v);G.push(B,B+1,B+2);Q.push(B,B+1);Q.push(B,B+2);Q.push(B+1,B+2);B+=3}else if(q instanceof THREE.Face4){A=j.geometry.vertices[q.a].position;D=j.geometry.vertices[q.b].position;I=j.geometry.vertices[q.c].position;X=j.geometry.vertices[q.d].position;
  163. R.push(A.x,A.y,A.z);R.push(D.x,D.y,D.z);R.push(I.x,I.y,I.z);R.push(X.x,X.y,X.z);if(j.geometry.hasTangents){A=j.geometry.vertices[q.a].tangent;D=j.geometry.vertices[q.b].tangent;I=j.geometry.vertices[q.c].tangent;q=j.geometry.vertices[q.d].tangent;V.push(A.x,A.y,A.z,A.w);V.push(D.x,D.y,D.z,D.w);V.push(I.x,I.y,I.z,I.w);V.push(q.x,q.y,q.z,q.w)}if(v.length==4&&o)for(q=0;q<4;q++)U.push(v[q].x,v[q].y,v[q].z);else for(q=0;q<4;q++)U.push(faceNormal.x,faceNormal.y,faceNormal.z);if(r)for(q=0;q<4;q++)N.push(r[q].u,
  164. r[q].v);G.push(B,B+1,B+2);G.push(B,B+2,B+3);Q.push(B,B+1);Q.push(B,B+2);Q.push(B,B+3);Q.push(B+1,B+2);Q.push(B+2,B+3);B+=4}}if(R.length){J.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,J.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(R),c.STATIC_DRAW);J.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,J.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(U),c.STATIC_DRAW);if(j.geometry.hasTangents){J.__webGLTangentBuffer=c.createBuffer();
  165. c.bindBuffer(c.ARRAY_BUFFER,J.__webGLTangentBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(V),c.STATIC_DRAW)}if(N.length>0){J.__webGLUVBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,J.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(N),c.STATIC_DRAW)}J.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,J.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(G),c.STATIC_DRAW);J.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,
  166. J.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(Q),c.STATIC_DRAW);J.__webGLFaceCount=G.length;J.__webGLLineCount=Q.length}};this.renderBuffer=function(j,p,n,m,r){var q,v,A,D,I,X,G,Q,R;if(m instanceof THREE.MeshShaderMaterial||m instanceof THREE.MeshDepthMaterial||m instanceof THREE.MeshNormalMaterial){if(!m.program){if(m instanceof THREE.MeshDepthMaterial){G=M.depth;m.fragment_shader=G.fragment_shader;m.vertex_shader=G.vertex_shader;m.uniforms=G.uniforms;m.uniforms.mNear.value=
  167. m.near;m.uniforms.mFar.value=m.far}else if(m instanceof THREE.MeshNormalMaterial){G=M.normal;m.fragment_shader=G.fragment_shader;m.vertex_shader=G.vertex_shader;m.uniforms=G.uniforms}m.program=b(m.fragment_shader,m.vertex_shader,null);G=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(R in m.uniforms)G.push(R);f(m.program,G);g(m.program,["position","normal","uv","tangent"])}R=m.program}else R=z;if(R!=w){c.useProgram(R);w=R}R==z&&this.setupLights(R,
  168. p);this.loadCamera(R,j);this.loadMatrices(R);if(m instanceof THREE.MeshShaderMaterial||m instanceof THREE.MeshDepthMaterial||m instanceof THREE.MeshNormalMaterial){A=m.wireframe;D=m.wireframe_linewidth;j=R;p=m.uniforms;var U;for(q in p){Q=p[q].type;G=p[q].value;U=j.uniforms[q];if(Q=="i")c.uniform1i(U,G);else if(Q=="f")c.uniform1f(U,G);else if(Q=="v3")c.uniform3f(U,G.x,G.y,G.z);else if(Q=="c")c.uniform3f(U,G.r,G.g,G.b);else if(Q=="t"){c.uniform1i(U,G);if(Q=p[q].texture)Q.image instanceof Array&&Q.image.length==
  169. 6?e(Q,G):d(Q,G)}}}if(m instanceof THREE.MeshPhongMaterial||m instanceof THREE.MeshLambertMaterial||m instanceof THREE.MeshBasicMaterial){q=m.color;v=m.opacity;A=m.wireframe;D=m.wireframe_linewidth;I=m.map;X=m.env_map;p=m.combine==THREE.MixOperation;j=m.reflectivity;Q=m.env_map&&m.env_map.mapping instanceof THREE.CubeRefractionMapping;G=m.refraction_ratio;c.uniform4f(R.uniforms.mColor,q.r*v,q.g*v,q.b*v,v);c.uniform1i(R.uniforms.mixEnvMap,p);c.uniform1f(R.uniforms.mReflectivity,j);c.uniform1i(R.uniforms.useRefract,
  170. Q);c.uniform1f(R.uniforms.mRefractionRatio,G);if(n){c.uniform1f(R.uniforms.fogDensity,n.density);c.uniform3f(R.uniforms.fogColor,n.color.r,n.color.g,n.color.b)}}if(m instanceof THREE.MeshPhongMaterial){n=m.ambient;q=m.specular;m=m.shininess;c.uniform4f(R.uniforms.mAmbient,n.r,n.g,n.b,v);c.uniform4f(R.uniforms.mSpecular,q.r,q.g,q.b,v);c.uniform1f(R.uniforms.mShininess,m);c.uniform1i(R.uniforms.material,2)}else if(m instanceof THREE.MeshLambertMaterial)c.uniform1i(R.uniforms.material,1);else m instanceof
  171. THREE.MeshBasicMaterial&&c.uniform1i(R.uniforms.material,0);if(I){d(I,0);c.uniform1i(R.uniforms.tMap,0);c.uniform1i(R.uniforms.enableMap,1)}else c.uniform1i(R.uniforms.enableMap,0);if(X){e(X,1);c.uniform1i(R.uniforms.tCube,1);c.uniform1i(R.uniforms.enableCubeMap,1)}else c.uniform1i(R.uniforms.enableCubeMap,0);v=R.attributes;c.bindBuffer(c.ARRAY_BUFFER,r.__webGLVertexBuffer);c.vertexAttribPointer(v.position,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(v.position);if(v.normal>=0){c.bindBuffer(c.ARRAY_BUFFER,
  172. r.__webGLNormalBuffer);c.vertexAttribPointer(v.normal,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(v.normal)}if(v.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,r.__webGLTangentBuffer);c.vertexAttribPointer(v.tangent,4,c.FLOAT,false,0,0);c.enableVertexAttribArray(v.tangent)}if(v.uv>=0)if(r.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,r.__webGLUVBuffer);c.vertexAttribPointer(v.uv,2,c.FLOAT,false,0,0);c.enableVertexAttribArray(v.uv)}else c.disableVertexAttribArray(v.uv);if(A){c.lineWidth(D);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,
  173. r.__webGLLineBuffer);c.drawElements(c.LINES,r.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,r.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,r.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(j,p,n,m,r,q,v){var A,D,I,X,G;I=0;for(X=m.material.length;I<X;I++){A=m.material[I];if(A instanceof THREE.MeshFaceMaterial){A=0;for(D=r.material.length;A<D;A++)if((G=r.material[A])&&G.blending==q&&G.opacity<1==v){this.setBlending(G.blending);this.renderBuffer(j,p,n,
  174. G,r)}}else if((G=A)&&G.blending==q&&G.opacity<1==v){this.setBlending(G.blending);this.renderBuffer(j,p,n,G,r)}}};this.render=function(j,p){var n,m,r,q,v=j.lights,A=j.fog;this.initWebGLObjects(j);this.autoClear&&this.clear();p.autoUpdateMatrix&&p.updateMatrix();y.set(p.matrix.flatten());K.set(p.projectionMatrix.flatten());n=0;for(m=j.__webGLObjects.length;n<m;n++){r=j.__webGLObjects[n];q=r.object;r=r.buffer;if(q.visible){this.setupMatrices(q,p);this.renderPass(p,v,A,q,r,THREE.NormalBlending,false)}}n=
  175. 0;for(m=j.__webGLObjects.length;n<m;n++){r=j.__webGLObjects[n];q=r.object;r=r.buffer;if(q.visible){this.setupMatrices(q,p);this.renderPass(p,v,A,q,r,THREE.AdditiveBlending,false);this.renderPass(p,v,A,q,r,THREE.SubtractiveBlending,false);this.renderPass(p,v,A,q,r,THREE.AdditiveBlending,true);this.renderPass(p,v,A,q,r,THREE.SubtractiveBlending,true);this.renderPass(p,v,A,q,r,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(j){var p,n,m,r,q,v;if(!j.__webGLObjects){j.__webGLObjects=[];j.__webGLObjectsMap=
  176. {}}p=0;for(n=j.objects.length;p<n;p++){m=j.objects[p];if(j.__webGLObjectsMap[m.id]==undefined)j.__webGLObjectsMap[m.id]={};v=j.__webGLObjectsMap[m.id];if(m instanceof THREE.Mesh)for(q in m.geometry.geometryChunks){r=m.geometry.geometryChunks[q];r.__webGLVertexBuffer||this.createBuffers(m,q);if(v[q]==undefined){r={buffer:r,object:m};j.__webGLObjects.push(r);v[q]=1}}}};this.removeObject=function(j,p){var n,m;for(n=j.__webGLObjects.length-1;n>=0;n--){m=j.__webGLObjects[n].object;p==m&&j.__webGLObjects.splice(n,
  177. 1)}};this.setupMatrices=function(j,p){j.autoUpdateMatrix&&j.updateMatrix();s.multiply(p.matrix,j.matrix);C.set(s.flatten());u=THREE.Matrix4.makeInvert3x3(s).transpose();x.set(u.m);E.set(j.matrix.flatten())};this.loadMatrices=function(j){c.uniformMatrix4fv(j.uniforms.viewMatrix,false,y);c.uniformMatrix4fv(j.uniforms.modelViewMatrix,false,C);c.uniformMatrix4fv(j.uniforms.projectionMatrix,false,K);c.uniformMatrix3fv(j.uniforms.normalMatrix,false,x);c.uniformMatrix4fv(j.uniforms.objectMatrix,false,E)};
  178. this.loadCamera=function(j,p){c.uniform3f(j.uniforms.cameraPosition,p.position.x,p.position.y,p.position.z)};this.setBlending=function(j){switch(j){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE);break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(j,p){if(j){!p||p=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(j=="back")c.cullFace(c.BACK);
  179. else j=="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};var M={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}",
  180. 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}",vertex_shader:"varying vec3 vNormal;\nvoid main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalize( normalMatrix * normal );\ngl_Position = projectionMatrix * mvPosition;\n}"}}};
  181. 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.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};
  182. THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null};THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=null};
  183. 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,h=a.faces,i=f.faces,c=a.uvs;f=f.uvs;e&&b.updateMatrix();for(var w=0,z=k.length;w<z;w++){var s=new THREE.Vertex(k[w].position.clone());e&&b.matrix.multiplyVector3(s.position);g.push(s)}w=0;for(z=i.length;w<z;w++){k=i[w];var u,y=k.vertexNormals;if(k instanceof THREE.Face3)u=new THREE.Face3(k.a+d,k.b+d,k.c+d);else if(k instanceof THREE.Face4)u=new THREE.Face4(k.a+d,k.b+
  184. d,k.c+d,k.d+d);u.centroid.copy(k.centroid);u.normal.copy(k.normal);e=0;for(g=y.length;e<g;e++){s=y[e];u.vertexNormals.push(s.clone())}u.material=k.material.slice();h.push(u)}w=0;for(z=f.length;w<z;w++){d=f[w];h=[];e=0;for(g=d.length;e<g;e++)h.push(new THREE.UV(d[e].u,d[e].v));c.push(h)}}},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]=
  185. 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,h,i,c){b=new THREE.Mesh(b,c);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=h;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,
  186. 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])}));
  187. 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,
  188. 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}",
  189. 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}"},
  190. normal:{uniforms:{tNormal:{type:"t",value:2,texture:null},tAO:{type:"t",value:3,texture:null},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},uDirLightColor:{type:"c",value:new THREE.Color(15658734)},uAmbientLightColor:{type:"c",value:new THREE.Color(328965)},uDiffuseColor:{type:"c",
  191. 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 uDirLightColor;\nuniform vec3 uPointLightPos;\nuniform vec3 uPointLightColor;\nuniform vec3 uAmbientColor;\nuniform vec3 uDiffuseColor;\nuniform vec3 uSpecularColor;\nuniform float uShininess;\nuniform sampler2D tNormal;\nuniform sampler2D tAO;\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;\nvarying vec3 vPointLightVector;\nvarying vec3 vViewPosition;\nvoid main() {\nvec3 normalTex = normalize( texture2D( tNormal, vUv ).xyz * 2.0 - 1.0 );\nvec3 aoTex = 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( uAmbientColor, 1.0 );\ntotalLight += dirDiffuse + dirSpecular;\ntotalLight += pointDiffuse + pointSpecular;\ngl_FragColor = vec4( totalLight.xyz * vLightWeighting * aoTex, 1.0 );\n}",
  192. vertex_shader:"attribute vec4 tangent;\nuniform vec3 uDirLightPos;\nuniform vec3 uDirLightColor;\nuniform vec3 uPointLightPos;\nuniform vec3 uPointLightColor;\nuniform vec3 uAmbientLightColor;\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 vLightWeighting;\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;\nvLightWeighting = uAmbientLightColor;\nvec4 lPosition = viewMatrix * vec4( uPointLightPos, 1.0 );\nvPointLightVector = normalize( lPosition.xyz - mvPosition.xyz );\nfloat pointLightWeighting = max( dot( vNormal, vPointLightVector ), 0.0 );\nvLightWeighting += uPointLightColor * pointLightWeighting;\nvec4 lDirection = viewMatrix * vec4( uDirLightPos, 0.0 );\nfloat directionalLightWeighting = max( dot( vNormal, normalize( lDirection.xyz ) ), 0.0 );\nvLightWeighting += uDirLightColor * directionalLightWeighting;\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}"},
  193. 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}",
  194. 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,h){function i(C,K,x,E,l,P,M,j){var p,n=d||1,m=f||1,r=n+1,q=m+1,v=l/2,A=P/2;l=l/n;P=P/m;var D=c.vertices.length;if(C=="x"&&K=="y"||C=="y"&&K=="x")p="z";else if(C=="x"&&K=="z"||C=="z"&&K=="x")p="y";else if(C=="z"&&K=="y"||C=="y"&&K=="z")p="x";for(iy=0;iy<q;iy++)for(ix=0;ix<
  195. r;ix++){var I=new THREE.Vector3;I[C]=(ix*l-v)*x;I[K]=(iy*P-A)*E;I[p]=M;c.vertices.push(new THREE.Vertex(I))}for(iy=0;iy<m;iy++)for(ix=0;ix<n;ix++){c.faces.push(new THREE.Face4(ix+r*iy+D,ix+r*(iy+1)+D,ix+1+r*(iy+1)+D,ix+1+r*iy+D,null,j));c.uvs.push([new THREE.UV(ix/n,iy/m),new THREE.UV(ix/n,(iy+1)/m),new THREE.UV((ix+1)/n,(iy+1)/m),new THREE.UV((ix+1)/n,iy/m)])}}THREE.Geometry.call(this);var c=this,w=a/2,z=b/2,s=e/2;k=k?-1:1;if(g!==undefined)if(g instanceof Array)this.materials=g;else{this.materials=
  196. [];for(var u=0;u<6;u++)this.materials.push([g])}else this.materials=[];this.sides={px:true,nx:true,py:true,ny:true,pz:true,nz:true};if(h!=undefined)for(var y in h)if(this.sides[y]!=undefined)this.sides[y]=h[y];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,z,this.materials[2]);this.sides.ny&&i("x","z",1*k,-1,a,e,-z,this.materials[3]);this.sides.pz&&i("x","y",1*k,-1,a,b,s,this.materials[4]);this.sides.nz&&
  197. i("x","y",-1*k,-1,a,b,-s,this.materials[5]);(function(){for(var C=[],K=[],x=0,E=c.vertices.length;x<E;x++){for(var l=c.vertices[x],P=false,M=0,j=C.length;M<j;M++){var p=C[M];if(l.position.x==p.position.x&&l.position.y==p.position.y&&l.position.z==p.position.z){K[x]=M;P=true;break}}if(!P){K[x]=C.length;C.push(new THREE.Vertex(l.position.clone()))}}x=0;for(E=c.faces.length;x<E;x++){l=c.faces[x];l.a=K[l.a];l.b=K[l.b];l.c=K[l.c];l.d=K[l.d]}c.vertices=C})();this.computeCentroids();this.computeFaceNormals();
  198. this.sortFacesByMaterial()};Cube.prototype=new THREE.Geometry;Cube.prototype.constructor=Cube;
  199. var Cylinder=function(a,b,e,d,f){function g(c,w,z){k.vertices.push(new THREE.Vertex(new THREE.Vector3(c,w,z)))}THREE.Geometry.call(this);var k=this,h=Math.PI,i;for(i=0;i<a;i++)g(Math.sin(2*h*i/a)*b,Math.cos(2*h*i/a)*b,0);for(i=0;i<a;i++)g(Math.sin(2*h*i/a)*e,Math.cos(2*h*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<
  200. 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;
  201. 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 h=e+1,i=d+1;a=a/e;var c=b/d;for(f=0;f<i;f++)for(b=0;b<h;b++)this.vertices.push(new THREE.Vertex(new THREE.Vector3(b*a-g,-(f*c-k),0)));for(f=0;f<d;f++)for(b=0;b<e;b++){this.faces.push(new THREE.Face4(b+h*f,b+h*(f+1),b+1+h*(f+1),b+1+h*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()};
  202. Plane.prototype=new THREE.Geometry;Plane.prototype.constructor=Plane;
  203. 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 h=a*Math.cos(d*f),i=a*Math.sin(d*f),c=[],w=0;for(d=0;d<g;d++){var z=2*d/g,s=i*Math.sin(z*f);z=i*Math.cos(z*f);(e==0||e==k)&&d>0||(w=this.vertices.push(new THREE.Vertex(new THREE.Vector3(z,h,s)))-1);c.push(w)}b.push(c)}var u,y;a=b.length;for(e=0;e<a;e++){f=b[e].length;if(e>0)for(d=0;d<f;d++){i=d==f-1;g=b[e][i?0:d+1];k=b[e][i?f-1:d];h=b[e-1][i?f-1:d];i=b[e-1][i?
  204. 0:d+1];w=e/(a-1);z=(e-1)/(a-1);u=(d+1)/f;s=d/f;c=new THREE.UV(1-u,w);w=new THREE.UV(1-s,w);s=new THREE.UV(1-s,z);var C=new THREE.UV(1-u,z);if(e<b.length-1){z=this.vertices[g].position.clone();u=this.vertices[k].position.clone();y=this.vertices[h].position.clone();z.normalize();u.normalize();y.normalize();this.faces.push(new THREE.Face3(g,k,h,[new THREE.Vector3(z.x,z.y,z.z),new THREE.Vector3(u.x,u.y,u.z),new THREE.Vector3(y.x,y.y,y.z)]));this.uvs.push([c,w,s])}if(e>1){z=this.vertices[g].position.clone();
  205. u=this.vertices[h].position.clone();y=this.vertices[i].position.clone();z.normalize();u.normalize();y.normalize();this.faces.push(new THREE.Face3(g,h,i,[new THREE.Vector3(z.x,z.y,z.z),new THREE.Vector3(u.x,u.y,u.z),new THREE.Vector3(y.x,y.y,y.z)]));this.uvs.push([c,s,C])}}}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.sortFacesByMaterial()};Sphere.prototype=new THREE.Geometry;Sphere.prototype.constructor=Sphere;
  206. THREE.Loader=function(a){this.statusDomElement=(this.showStatus=a)?this.addStatusElement():null};
  207. 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=
  208. 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,
  209. 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,h=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(h==0)h=g.getResponseHeader("Content-Length");f({total:h,loaded:g.responseText.length})}}else if(g.readyState==
  210. 2)h=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(o,t){var F=w(o,t),O=w(o,t+1),Y=w(o,t+2),Z=w(o,t+3),ea=(Z<<1&255|Y>>7)-127;F=(Y&127)<<16|O<<8|F;if(F==0&&ea==-127)return 0;return(1-2*(Z>>7))*(1+F*Math.pow(2,-23))*Math.pow(2,ea)}function h(o,t){var F=w(o,t),O=w(o,t+1),Y=w(o,t+2);return(w(o,t+3)<<24)+(Y<<16)+
  211. (O<<8)+F}function i(o,t){var F=w(o,t);return(w(o,t+1)<<8)+F}function c(o,t){var F=w(o,t);return F>127?F-256:F}function w(o,t){return o.charCodeAt(t)&255}function z(o){var t,F,O;t=h(a,o);F=h(a,o+j);O=h(a,o+p);o=i(a,o+n);THREE.Loader.prototype.f3(x,t,F,O,o)}function s(o){var t,F,O,Y,Z,ea;t=h(a,o);F=h(a,o+j);O=h(a,o+p);Y=i(a,o+n);Z=h(a,o+m);ea=h(a,o+r);o=h(a,o+q);THREE.Loader.prototype.f3n(x,P,t,F,O,Y,Z,ea,o)}function u(o){var t,F,O,Y;t=h(a,o);F=h(a,o+v);O=h(a,o+A);Y=h(a,o+D);o=i(a,o+I);THREE.Loader.prototype.f4(x,
  212. t,F,O,Y,o)}function y(o){var t,F,O,Y,Z,ea,ma,oa;t=h(a,o);F=h(a,o+v);O=h(a,o+A);Y=h(a,o+D);Z=i(a,o+I);ea=h(a,o+X);ma=h(a,o+G);oa=h(a,o+Q);o=h(a,o+R);THREE.Loader.prototype.f4n(x,P,t,F,O,Y,Z,ea,ma,oa,o)}function C(o){var t,F;t=h(a,o);F=h(a,o+U);o=h(a,o+V);THREE.Loader.prototype.uv3(x,M[t*2],M[t*2+1],M[F*2],M[F*2+1],M[o*2],M[o*2+1])}function K(o){var t,F,O;t=h(a,o);F=h(a,o+N);O=h(a,o+B);o=h(a,o+J);THREE.Loader.prototype.uv4(x,M[t*2],M[t*2+1],M[F*2],M[F*2+1],M[O*2],M[O*2+1],M[o*2],M[o*2+1])}var x=this,
  213. E=0,l,P=[],M=[],j,p,n,m,r,q,v,A,D,I,X,G,Q,R,U,V,N,B,J;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(x,d,g);l={signature:a.substr(E,8),header_bytes:w(a,E+8),vertex_coordinate_bytes:w(a,E+9),normal_coordinate_bytes:w(a,E+10),uv_coordinate_bytes:w(a,E+11),vertex_index_bytes:w(a,E+12),normal_index_bytes:w(a,E+13),uv_index_bytes:w(a,E+14),material_index_bytes:w(a,E+15),nvertices:h(a,E+16),nnormals:h(a,E+16+4),nuvs:h(a,E+16+8),ntri_flat:h(a,E+16+12),ntri_smooth:h(a,E+16+16),ntri_flat_uv:h(a,
  214. E+16+20),ntri_smooth_uv:h(a,E+16+24),nquad_flat:h(a,E+16+28),nquad_smooth:h(a,E+16+32),nquad_flat_uv:h(a,E+16+36),nquad_smooth_uv:h(a,E+16+40)};E+=l.header_bytes;j=l.vertex_index_bytes;p=l.vertex_index_bytes*2;n=l.vertex_index_bytes*3;m=l.vertex_index_bytes*3+l.material_index_bytes;r=l.vertex_index_bytes*3+l.material_index_bytes+l.normal_index_bytes;q=l.vertex_index_bytes*3+l.material_index_bytes+l.normal_index_bytes*2;v=l.vertex_index_bytes;A=l.vertex_index_bytes*2;D=l.vertex_index_bytes*3;I=l.vertex_index_bytes*
  215. 4;X=l.vertex_index_bytes*4+l.material_index_bytes;G=l.vertex_index_bytes*4+l.material_index_bytes+l.normal_index_bytes;Q=l.vertex_index_bytes*4+l.material_index_bytes+l.normal_index_bytes*2;R=l.vertex_index_bytes*4+l.material_index_bytes+l.normal_index_bytes*3;U=l.uv_index_bytes;V=l.uv_index_bytes*2;N=l.uv_index_bytes;B=l.uv_index_bytes*2;J=l.uv_index_bytes*3;E+=function(o){var t,F,O,Y=l.vertex_coordinate_bytes*3,Z=o+l.nvertices*Y;for(o=o;o<Z;o+=Y){t=k(a,o);F=k(a,o+l.vertex_coordinate_bytes);O=k(a,
  216. o+l.vertex_coordinate_bytes*2);THREE.Loader.prototype.v(x,t,F,O)}return l.nvertices*Y}(E);E+=function(o){var t,F,O,Y=l.normal_coordinate_bytes*3,Z=o+l.nnormals*Y;for(o=o;o<Z;o+=Y){t=c(a,o);F=c(a,o+l.normal_coordinate_bytes);O=c(a,o+l.normal_coordinate_bytes*2);P.push(t/127,F/127,O/127)}return l.nnormals*Y}(E);E+=function(o){var t,F,O=l.uv_coordinate_bytes*2,Y=o+l.nuvs*O;for(o=o;o<Y;o+=O){t=k(a,o);F=k(a,o+l.uv_coordinate_bytes);M.push(t,F)}return l.nuvs*O}(E);E+=function(o){var t,F=l.vertex_index_bytes*
  217. 3+l.material_index_bytes,O=o+l.ntri_flat*F;for(t=o;t<O;t+=F)z(t);return O-o}(E);E+=function(o){var t,F=l.vertex_index_bytes*3+l.material_index_bytes+l.normal_index_bytes*3,O=o+l.ntri_smooth*F;for(t=o;t<O;t+=F)s(t);return O-o}(E);E+=function(o){var t,F=l.vertex_index_bytes*3+l.material_index_bytes,O=F+l.uv_index_bytes*3,Y=o+l.ntri_flat_uv*O;for(t=o;t<Y;t+=O){z(t);C(t+F)}return Y-o}(E);E+=function(o){var t,F=l.vertex_index_bytes*3+l.material_index_bytes+l.normal_index_bytes*3,O=F+l.uv_index_bytes*3,
  218. Y=o+l.ntri_smooth_uv*O;for(t=o;t<Y;t+=O){s(t);C(t+F)}return Y-o}(E);E+=function(o){var t,F=l.vertex_index_bytes*4+l.material_index_bytes,O=o+l.nquad_flat*F;for(t=o;t<O;t+=F)u(t);return O-o}(E);E+=function(o){var t,F=l.vertex_index_bytes*4+l.material_index_bytes+l.normal_index_bytes*4,O=o+l.nquad_smooth*F;for(t=o;t<O;t+=F)y(t);return O-o}(E);E+=function(o){var t,F=l.vertex_index_bytes*4+l.material_index_bytes,O=F+l.uv_index_bytes*4,Y=o+l.nquad_flat_uv*O;for(t=o;t<Y;t+=O){u(t);K(t+F)}return Y-o}(E);
  219. E+=function(o){var t,F=l.vertex_index_bytes*4+l.material_index_bytes+l.normal_index_bytes*4,O=F+l.uv_index_bytes*4,Y=o+l.nquad_smooth_uv*O;for(t=o;t<Y;t+=O){y(t);K(t+F)}return Y-o}(E);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,h,i,c,w;k=0;for(h=
  220. a.vertices.length;k<h;k+=3){i=a.vertices[k];c=a.vertices[k+1];w=a.vertices[k+2];THREE.Loader.prototype.v(g,i,c,w)}})();(function(){function k(y,C){THREE.Loader.prototype.f3(g,y[C],y[C+1],y[C+2],y[C+3])}function h(y,C){THREE.Loader.prototype.f3n(g,a.normals,y[C],y[C+1],y[C+2],y[C+3],y[C+4],y[C+5],y[C+6])}function i(y,C){THREE.Loader.prototype.f4(g,y[C],y[C+1],y[C+2],y[C+3],y[C+4])}function c(y,C){THREE.Loader.prototype.f4n(g,a.normals,y[C],y[C+1],y[C+2],y[C+3],y[C+4],y[C+5],y[C+6],y[C+7],y[C+8])}function w(y,
  221. C){var K,x,E;K=y[C];x=y[C+1];E=y[C+2];THREE.Loader.prototype.uv3(g,a.uvs[K*2],a.uvs[K*2+1],a.uvs[x*2],a.uvs[x*2+1],a.uvs[E*2],a.uvs[E*2+1])}function z(y,C){var K,x,E,l;K=y[C];x=y[C+1];E=y[C+2];l=y[C+3];THREE.Loader.prototype.uv4(g,a.uvs[K*2],a.uvs[K*2+1],a.uvs[x*2],a.uvs[x*2+1],a.uvs[E*2],a.uvs[E*2+1],a.uvs[l*2],a.uvs[l*2+1])}var s,u;s=0;for(u=a.triangles.length;s<u;s+=4)k(a.triangles,s);s=0;for(u=a.triangles_uv.length;s<u;s+=7){k(a.triangles_uv,s);w(a.triangles_uv,s+4)}s=0;for(u=a.triangles_n.length;s<
  222. u;s+=7)h(a.triangles_n,s);s=0;for(u=a.triangles_n_uv.length;s<u;s+=10){h(a.triangles_n_uv,s);w(a.triangles_n_uv,s+7)}s=0;for(u=a.quads.length;s<u;s+=5)i(a.quads,s);s=0;for(u=a.quads_uv.length;s<u;s+=9){i(a.quads_uv,s);z(a.quads_uv,s+5)}s=0;for(u=a.quads_n.length;s<u;s+=9)c(a.quads_n,s);s=0;for(u=a.quads_n_uv.length;s<u;s+=13){c(a.quads_n_uv,s);z(a.quads_n_uv,s+9)}})();this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};d.prototype=new THREE.Geometry;d.prototype.constructor=
  223. 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,h,i){g=a.materials[g];var c=b[h*3],w=b[h*3+1];h=b[h*3+2];var z=b[i*3],s=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(c,w,h),new THREE.Vector3(z,
  224. s,i)],g))},f4n:function(a,b,e,d,f,g,k,h,i,c,w){k=a.materials[k];var z=b[i*3],s=b[i*3+1];i=b[i*3+2];var u=b[c*3],y=b[c*3+1];c=b[c*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[h*3],b[h*3+1],b[h*3+2]),new THREE.Vector3(z,s,i),new THREE.Vector3(u,y,c),new THREE.Vector3(C,K,w)],k))},uv3:function(a,b,e,d,f,g,k){var h=[];h.push(new THREE.UV(b,e));h.push(new THREE.UV(d,f));h.push(new THREE.UV(g,k));a.uvs.push(h)},uv4:function(a,b,e,d,f,g,k,h,i){var c=[];
  225. c.push(new THREE.UV(b,e));c.push(new THREE.UV(d,f));c.push(new THREE.UV(g,k));c.push(new THREE.UV(h,i));a.uvs.push(c)},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)||
  226. !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}):
  227. new THREE.MeshLambertMaterial({color:15658734});return d}};