ThreeExtras.js 120 KB

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