ThreeExtras.js 110 KB

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