ThreeExtras.js 109 KB

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