ThreeDebug.js 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // ThreeDebug.js r30 - 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,d){this.r=a;this.g=b;this.b=d;if(this.autoUpdate){this.updateHex();this.updateStyleString()}},setHex:function(a){this.hex=~~a&16777215;if(this.autoUpdate){this.updateRGBA();this.updateStyleString()}},updateHex:function(){this.hex=~~(this.r*255)<<16^~~(this.g*255)<<8^~~(this.b*255)},updateRGBA:function(){this.r=(this.hex>>16&255)/255;this.g=(this.hex>>8&255)/255;this.b=(this.hex&255)/255},updateStyleString:function(){this.__styleString="rgb("+~~(this.r*255)+
  4. ","+~~(this.g*255)+","+~~(this.b*255)+")"},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,d){this.x=a||0;this.y=b||0;this.z=d||0};
  7. THREE.Vector3.prototype={set:function(a,b,d){this.x=a;this.y=b;this.z=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this},add:function(a,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,d=this.y,i=this.z;this.x=d*a.z-i*a.y;this.y=i*a.x-b*a.z;this.z=b*a.y-d*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,d=this.y-a.y;a=this.z-a.z;return Math.sqrt(b*b+d*d+a*a)},distanceToSquared:function(a){var b=this.x-a.x,d=this.y-a.y;a=this.z-a.z;return b*b+d*d+a*a},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},negate:function(){this.x=-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,d,i){this.x=a||0;this.y=b||0;this.z=d||0;this.w=i||1};
  12. THREE.Vector4.prototype={set:function(a,b,d,i){this.x=a;this.y=b;this.z=d;this.w=i;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,d,i=a.objects,j=[];a=0;for(b=i.length;a<b;a++){d=i[a];if(d instanceof THREE.Mesh)j=j.concat(this.intersectObject(d))}j.sort(function(p,m){return p.distance-m.distance});return j},intersectObject:function(a){function b(M,n,S,B){B=B.clone().subSelf(n);S=S.clone().subSelf(n);var e=M.clone().subSelf(n);M=B.dot(B);n=B.dot(S);B=B.dot(e);var f=S.dot(S);S=S.dot(e);e=1/(M*f-n*n);f=(f*B-n*S)*e;M=(M*S-n*B)*e;return f>0&&M>0&&f+M<1}var d,i,j,p,m,r,l,c,z,G,
  16. x,F=a.geometry,O=F.vertices,J=[];d=0;for(i=F.faces.length;d<i;d++){j=F.faces[d];G=this.origin.clone();x=this.direction.clone();p=a.matrix.transformVector3(O[j.a].position.clone());m=a.matrix.transformVector3(O[j.b].position.clone());r=a.matrix.transformVector3(O[j.c].position.clone());l=j instanceof THREE.Face4?a.matrix.transformVector3(O[j.d].position.clone()):null;c=a.rotationMatrix.transformVector3(j.normal.clone());z=x.dot(c);if(z<0){c=c.dot((new THREE.Vector3).sub(p,G))/z;G=G.addSelf(x.multiplyScalar(c));
  17. if(j instanceof THREE.Face3){if(b(G,p,m,r)){j={distance:this.origin.distanceTo(G),point:G,face:j,object:a};J.push(j)}}else if(j instanceof THREE.Face4)if(b(G,p,m,l)||b(G,m,r,l)){j={distance:this.origin.distanceTo(G),point:G,face:j,object:a};J.push(j)}}}return J}};
  18. THREE.Rectangle=function(){function a(){p=i-b;m=j-d}var b,d,i,j,p,m,r=true;this.getX=function(){return b};this.getY=function(){return d};this.getWidth=function(){return p};this.getHeight=function(){return m};this.getLeft=function(){return b};this.getTop=function(){return d};this.getRight=function(){return i};this.getBottom=function(){return j};this.set=function(l,c,z,G){r=false;b=l;d=c;i=z;j=G;a()};this.addPoint=function(l,c){if(r){r=false;b=l;d=c;i=l;j=c}else{b=Math.min(b,l);d=Math.min(d,c);i=Math.max(i,
  19. l);j=Math.max(j,c)}a()};this.addRectangle=function(l){if(r){r=false;b=l.getLeft();d=l.getTop();i=l.getRight();j=l.getBottom()}else{b=Math.min(b,l.getLeft());d=Math.min(d,l.getTop());i=Math.max(i,l.getRight());j=Math.max(j,l.getBottom())}a()};this.inflate=function(l){b-=l;d-=l;i+=l;j+=l;a()};this.minSelf=function(l){b=Math.max(b,l.getLeft());d=Math.max(d,l.getTop());i=Math.min(i,l.getRight());j=Math.min(j,l.getBottom());a()};this.instersects=function(l){return Math.min(i,l.getRight())-Math.max(b,l.getLeft())>=
  20. 0&&Math.min(j,l.getBottom())-Math.max(d,l.getTop())>=0};this.empty=function(){r=true;j=i=d=b=0;a()};this.isEmpty=function(){return r};this.toString=function(){return"THREE.Rectangle ( left: "+b+", right: "+i+", top: "+d+", bottom: "+j+", width: "+p+", height: "+m+" )"}};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}};
  21. THREE.Matrix4=function(){};
  22. THREE.Matrix4.prototype={n11:1,n12:0,n13:0,n14:0,n21:0,n22:1,n23:0,n24:0,n31:0,n32:0,n33:1,n34:0,n41:0,n42:0,n43:0,n44:1,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},copy:function(a){this.n11=a.n11;this.n12=a.n12;this.n13=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=
  23. a.n41;this.n42=a.n42;this.n43=a.n43;this.n44=a.n44},lookAt:function(a,b,d){var i=new THREE.Vector3,j=new THREE.Vector3,p=new THREE.Vector3;p.sub(a,b).normalize();i.cross(d,p).normalize();j.cross(p,i).normalize();this.n11=i.x;this.n12=i.y;this.n13=i.z;this.n14=-i.dot(a);this.n21=j.x;this.n22=j.y;this.n23=j.z;this.n24=-j.dot(a);this.n31=p.x;this.n32=p.y;this.n33=p.z;this.n34=-p.dot(a);this.n43=this.n42=this.n41=0;this.n44=1},transformVector3:function(a){var b=a.x,d=a.y,i=a.z,j=1/(this.n41*b+this.n42*
  24. d+this.n43*i+this.n44);a.x=(this.n11*b+this.n12*d+this.n13*i+this.n14)*j;a.y=(this.n21*b+this.n22*d+this.n23*i+this.n24)*j;a.z=(this.n31*b+this.n32*d+this.n33*i+this.n34)*j;return a},transformVector4:function(a){var b=a.x,d=a.y,i=a.z,j=a.w;a.x=this.n11*b+this.n12*d+this.n13*i+this.n14*j;a.y=this.n21*b+this.n22*d+this.n23*i+this.n24*j;a.z=this.n31*b+this.n32*d+this.n33*i+this.n34*j;a.w=this.n41*b+this.n42*d+this.n43*i+this.n44*j;return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*
  25. 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 d=a.n11,i=a.n12,j=a.n13,p=a.n14,m=a.n21,r=a.n22,l=a.n23,c=a.n24,z=a.n31,G=a.n32,x=a.n33,F=a.n34,O=a.n41,J=a.n42,M=a.n43,n=a.n44,S=b.n11,B=b.n12,e=b.n13,f=b.n14,k=b.n21,o=b.n22,g=b.n23,h=b.n24,w=b.n31,s=b.n32,L=b.n33,u=b.n34,T=b.n41,Q=b.n42,t=b.n43,
  26. H=b.n44;this.n11=d*S+i*k+j*w+p*T;this.n12=d*B+i*o+j*s+p*Q;this.n13=d*e+i*g+j*L+p*t;this.n14=d*f+i*h+j*u+p*H;this.n21=m*S+r*k+l*w+c*T;this.n22=m*B+r*o+l*s+c*Q;this.n23=m*e+r*g+l*L+c*t;this.n24=m*f+r*h+l*u+c*H;this.n31=z*S+G*k+x*w+F*T;this.n32=z*B+G*o+x*s+F*Q;this.n33=z*e+G*g+x*L+F*t;this.n34=z*f+G*h+x*u+F*H;this.n41=O*S+J*k+M*w+n*T;this.n42=O*B+J*o+M*s+n*Q;this.n43=O*e+J*g+M*L+n*t;this.n44=O*f+J*h+M*u+n*H},multiplySelf:function(a){var b=this.n11,d=this.n12,i=this.n13,j=this.n14,p=this.n21,m=this.n22,
  27. r=this.n23,l=this.n24,c=this.n31,z=this.n32,G=this.n33,x=this.n34,F=this.n41,O=this.n42,J=this.n43,M=this.n44;this.n11=b*a.n11+d*a.n21+i*a.n31+j*a.n41;this.n12=b*a.n12+d*a.n22+i*a.n32+j*a.n42;this.n13=b*a.n13+d*a.n23+i*a.n33+j*a.n43;this.n14=b*a.n14+d*a.n24+i*a.n34+j*a.n44;this.n21=p*a.n11+m*a.n21+r*a.n31+l*a.n41;this.n22=p*a.n12+m*a.n22+r*a.n32+l*a.n42;this.n23=p*a.n13+m*a.n23+r*a.n33+l*a.n43;this.n24=p*a.n14+m*a.n24+r*a.n34+l*a.n44;this.n31=c*a.n11+z*a.n21+G*a.n31+x*a.n41;this.n32=c*a.n12+z*a.n22+
  28. G*a.n32+x*a.n42;this.n33=c*a.n13+z*a.n23+G*a.n33+x*a.n43;this.n34=c*a.n14+z*a.n24+G*a.n34+x*a.n44;this.n41=F*a.n11+O*a.n21+J*a.n31+M*a.n41;this.n42=F*a.n12+O*a.n22+J*a.n32+M*a.n42;this.n43=F*a.n13+O*a.n23+J*a.n33+M*a.n43;this.n44=F*a.n14+O*a.n24+J*a.n34+M*a.n44},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*=a;this.n42*=a;this.n43*=a;this.n44*=a},determinant:function(){return this.n14*
  29. 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*this.n42+this.n14*this.n22*this.n31*this.n43-this.n12*this.n24*this.n31*this.n43-this.n14*
  30. 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,d,i){var j=b[d];b[d]=b[i];b[i]=j}a(this,"n21","n12");a(this,"n31","n13");a(this,"n32","n23");a(this,"n41","n14");a(this,
  31. "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,this.n22,this.n32,this.n42,this.n13,this.n23,this.n33,this.n43,this.n14,this.n24,this.n34,this.n44]},
  32. 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,d){var i=new THREE.Matrix4;i.n14=a;i.n24=b;i.n34=d;return i};THREE.Matrix4.scaleMatrix=function(a,b,d){var i=new THREE.Matrix4;i.n11=a;i.n22=b;i.n33=d;return i};
  33. 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};
  34. THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var d=new THREE.Matrix4,i=Math.cos(b),j=Math.sin(b),p=1-i,m=a.x,r=a.y,l=a.z;d.n11=p*m*m+i;d.n12=p*m*r-j*l;d.n13=p*m*l+j*r;d.n21=p*m*r+j*l;d.n22=p*r*r+i;d.n23=p*r*l-j*m;d.n31=p*m*l-j*r;d.n32=p*r*l+j*m;d.n33=p*l*l+i;return d};
  35. 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*
  36. 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*
  37. 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*
  38. 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};
  39. THREE.Matrix4.makeInvert3x3=function(a){var b=a.flatten();a=new THREE.Matrix3;var d=b[10]*b[5]-b[6]*b[9],i=-b[10]*b[1]+b[2]*b[9],j=b[6]*b[1]-b[2]*b[5],p=-b[10]*b[4]+b[6]*b[8],m=b[10]*b[0]-b[2]*b[8],r=-b[6]*b[0]+b[2]*b[4],l=b[9]*b[4]-b[5]*b[8],c=-b[9]*b[0]+b[1]*b[8],z=b[5]*b[0]-b[1]*b[4];b=b[0]*d+b[1]*p+b[2]*l;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*d;a.m[1]=b*i;a.m[2]=b*j;a.m[3]=b*p;a.m[4]=b*m;a.m[5]=b*r;a.m[6]=b*l;a.m[7]=b*c;a.m[8]=b*z;return a};
  40. THREE.Matrix4.makeFrustum=function(a,b,d,i,j,p){var m,r,l;m=new THREE.Matrix4;r=2*j/(b-a);l=2*j/(i-d);a=(b+a)/(b-a);d=(i+d)/(i-d);i=-(p+j)/(p-j);j=-2*p*j/(p-j);m.n11=r;m.n12=0;m.n13=a;m.n14=0;m.n21=0;m.n22=l;m.n23=d;m.n24=0;m.n31=0;m.n32=0;m.n33=i;m.n34=j;m.n41=0;m.n42=0;m.n43=-1;m.n44=0;return m};THREE.Matrix4.makePerspective=function(a,b,d,i){var j;a=d*Math.tan(a*Math.PI/360);j=-a;return THREE.Matrix4.makeFrustum(j*b,a*b,j,a,d,i)};
  41. THREE.Matrix4.makeOrtho=function(a,b,d,i,j,p){var m,r,l,c;m=new THREE.Matrix4;r=b-a;l=d-i;c=p-j;a=(b+a)/r;d=(d+i)/l;j=(p+j)/c;m.n11=2/r;m.n12=0;m.n13=0;m.n14=-a;m.n21=0;m.n22=2/l;m.n23=0;m.n24=-d;m.n31=0;m.n32=0;m.n33=-2/c;m.n34=-j;m.n41=0;m.n42=0;m.n43=0;m.n44=1;return m};
  42. 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.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}};
  43. THREE.Face3=function(a,b,d,i,j){this.a=a;this.b=b;this.c=d;this.centroid=new THREE.Vector3;this.normal=i instanceof THREE.Vector3?i:new THREE.Vector3;this.vertexNormals=i instanceof Array?i:[];this.material=j instanceof Array?j:[j]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
  44. THREE.Face4=function(a,b,d,i,j,p){this.a=a;this.b=b;this.c=d;this.d=i;this.centroid=new THREE.Vector3;this.normal=j instanceof THREE.Vector3?j:new THREE.Vector3;this.vertexNormals=j instanceof Array?j:[];this.material=p instanceof Array?p:[p]};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};
  45. 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.geometryChunks={}};
  46. THREE.Geometry.prototype={computeCentroids:function(){var a,b,d;a=0;for(b=this.faces.length;a<b;a++){d=this.faces[a];d.centroid.set(0,0,0);d.centroid.addSelf(this.vertices[d.a].position);d.centroid.addSelf(this.vertices[d.b].position);d.centroid.addSelf(this.vertices[d.c].position);if(d instanceof THREE.Face3)d.centroid.divideScalar(3);else if(d instanceof THREE.Face4){d.centroid.addSelf(this.vertices[d.d].position);d.centroid.divideScalar(4)}}},computeNormals:function(a){var b,d,i,j,p,m,r=new THREE.Vector3,
  47. l=new THREE.Vector3;i=0;for(j=this.vertices.length;i<j;i++){p=this.vertices[i];p.normal.set(0,0,0)}i=0;for(j=this.faces.length;i<j;i++){p=this.faces[i];if(a&&p.vertexNormals.length){r.set(0,0,0);b=0;for(d=p.normal.length;b<d;b++)r.addSelf(p.vertexNormals[b]);r.divideScalar(3)}else{b=this.vertices[p.a];d=this.vertices[p.b];m=this.vertices[p.c];r.sub(m.position,d.position);l.sub(b.position,d.position);r.crossSelf(l)}r.isZero()||r.normalize();p.normal.copy(r)}},computeBoundingBox:function(){if(this.vertices.length>
  48. 0){this.bbox={x:[this.vertices[0].position.x,this.vertices[0].position.x],y:[this.vertices[0].position.y,this.vertices[0].position.y],z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var a=1,b=this.vertices.length;a<b;a++){vertex=this.vertices[a];if(vertex.position.x<this.bbox.x[0])this.bbox.x[0]=vertex.position.x;else if(vertex.position.x>this.bbox.x[1])this.bbox.x[1]=vertex.position.x;if(vertex.position.y<this.bbox.y[0])this.bbox.y[0]=vertex.position.y;else if(vertex.position.y>
  49. this.bbox.y[1])this.bbox.y[1]=vertex.position.y;if(vertex.position.z<this.bbox.z[0])this.bbox.z[0]=vertex.position.z;else if(vertex.position.z>this.bbox.z[1])this.bbox.z[1]=vertex.position.z}}},sortFacesByMaterial:function(){function a(z){var G=[];b=0;for(d=z.length;b<d;b++)z[b]==undefined?G.push("undefined"):G.push(z[b].toString());return G.join("_")}var b,d,i,j,p,m,r,l,c={};i=0;for(j=this.faces.length;i<j;i++){p=this.faces[i];m=p.material;r=a(m);if(c[r]==undefined)c[r]={hash:r,counter:0};l=c[r].hash+
  50. "_"+c[r].counter;if(this.geometryChunks[l]==undefined)this.geometryChunks[l]={faces:[],material:m,vertices:0};p=p instanceof THREE.Face3?3:4;if(this.geometryChunks[l].vertices+p>65535){c[r].counter+=1;l=c[r].hash+"_"+c[r].counter;if(this.geometryChunks[l]==undefined)this.geometryChunks[l]={faces:[],material:m,vertices:0}}this.geometryChunks[l].faces.push(i);this.geometryChunks[l].vertices+=p}},toString:function(){return"THREE.Geometry ( vertices: "+this.vertices+", faces: "+this.faces+" )"}};
  51. THREE.Camera=function(a,b,d,i){this.position=new THREE.Vector3(0,0,0);this.target={position:new THREE.Vector3(0,0,0)};this.up=new THREE.Vector3(0,1,0);this.matrix=new THREE.Matrix4;this.projectionMatrix=THREE.Matrix4.makePerspective(a,b,d,i);this.autoUpdateMatrix=true;this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.toString=function(){return"THREE.Camera ( "+this.position+", "+this.target.position+" )"}};THREE.Light=function(a){this.color=new THREE.Color(a)};
  52. 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;
  53. 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;
  54. THREE.Object3D=function(){this.id=THREE.Object3DCounter.value++;this.position=new THREE.Vector3;this.rotation=new THREE.Vector3;this.scale=new THREE.Vector3(1,1,1);this.matrix=new THREE.Matrix4;this.translationMatrix=new THREE.Matrix4;this.rotationMatrix=new THREE.Matrix4;this.scaleMatrix=new THREE.Matrix4;this.screen=new THREE.Vector3;this.autoUpdateMatrix=this.visible=true;this.updateMatrix=function(){this.matrixPosition=THREE.Matrix4.translationMatrix(this.position.x,this.position.y,this.position.z);
  55. this.rotationMatrix=THREE.Matrix4.rotationXMatrix(this.rotation.x);this.rotationMatrix.multiplySelf(THREE.Matrix4.rotationYMatrix(this.rotation.y));this.rotationMatrix.multiplySelf(THREE.Matrix4.rotationZMatrix(this.rotation.z));this.scaleMatrix=THREE.Matrix4.scaleMatrix(this.scale.x,this.scale.y,this.scale.z);this.matrix.copy(this.matrixPosition);this.matrix.multiplySelf(this.rotationMatrix);this.matrix.multiplySelf(this.scaleMatrix)}};THREE.Object3DCounter={value:0};
  56. THREE.Particle=function(a){THREE.Object3D.call(this);this.material=a instanceof Array?a:[a];this.autoUpdateMatrix=false};THREE.Particle.prototype=new THREE.Object3D;THREE.Particle.prototype.constructor=THREE.Particle;THREE.Line=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.material=b instanceof Array?b:[b]};THREE.Line.prototype=new THREE.Object3D;THREE.Line.prototype.constructor=THREE.Line;
  57. THREE.Mesh=function(a,b,d){THREE.Object3D.call(this);this.geometry=a;this.material=b instanceof Array?b:[b];this.overdraw=this.doubleSided=this.flipSided=false;d&&this.normalizeUVs();this.geometry.computeBoundingBox()};THREE.Mesh.prototype=new THREE.Object3D;THREE.Mesh.prototype.constructor=THREE.Mesh;
  58. THREE.Mesh.prototype.normalizeUVs=function(){var a,b,d,i,j;a=0;for(b=this.geometry.uvs.length;a<b;a++){j=this.geometry.uvs[a];d=0;for(i=j.length;d<i;d++){if(j[d].u!=1)j[d].u-=Math.floor(j[d].u);if(j[d].v!=1)j[d].v-=Math.floor(j[d].v)}}};THREE.FlatShading=0;THREE.SmoothShading=1;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;
  59. THREE.LineBasicMaterial=function(a){this.color=new THREE.Color(16711680);this.opacity=1;this.blending=THREE.NormalBlending;this.linewidth=1;this.linejoin=this.linecap="round";if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending;if(a.linewidth!==undefined)this.linewidth=a.linewidth;if(a.linecap!==undefined)this.linecap=a.linecap;if(a.linejoin!==undefined)this.linejoin=a.linejoin}this.toString=function(){return"THREE.LineBasicMaterial (<br/>color: "+
  60. this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>linewidth: "+this.linewidth+"<br/>linecap: "+this.linecap+"<br/>linejoin: "+this.linejoin+"<br/>)"}};
  61. THREE.MeshBasicMaterial=function(a){this.id=THREE.MeshBasicMaterialCounter.value++;this.color=new THREE.Color(15658734);this.env_map=this.map=null;this.combine=THREE.Multiply;this.reflectivity=1;this.refraction_ratio=0.98;this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=this.wireframe_linecap="round";if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.map!==undefined)this.map=a.map;if(a.env_map!==
  62. undefined)this.env_map=a.env_map;if(a.combine!==undefined)this.combine=a.combine;if(a.reflectivity!==undefined)this.reflectivity=a.reflectivity;if(a.refraction_ratio!==undefined)this.refraction_ratio=a.refraction_ratio;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframe_linewidth!==undefined)this.wireframe_linewidth=a.wireframe_linewidth;
  63. if(a.wireframe_linecap!==undefined)this.wireframe_linecap=a.wireframe_linecap;if(a.wireframe_linejoin!==undefined)this.wireframe_linejoin=a.wireframe_linejoin}this.toString=function(){return"THREE.MeshBasicMaterial (<br/>id: "+this.id+"<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>env_map: "+this.env_map+"<br/>combine: "+this.combine+"<br/>reflectivity: "+this.reflectivity+"<br/>refraction_ratio: "+this.refraction_ratio+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>wireframe: "+
  64. this.wireframe+"<br/>wireframe_linewidth: "+this.wireframe_linewidth+"<br/>wireframe_linecap: "+this.wireframe_linecap+"<br/>wireframe_linejoin: "+this.wireframe_linejoin+"<br/>)"}};THREE.MeshBasicMaterialCounter={value:0};
  65. THREE.MeshLambertMaterial=function(a){this.id=THREE.MeshLambertMaterialCounter.value++;this.color=new THREE.Color(15658734);this.env_map=this.map=null;this.combine=THREE.Multiply;this.reflectivity=1;this.refraction_ratio=0.98;this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=this.wireframe_linecap="round";if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.map!==undefined)this.map=a.map;
  66. if(a.env_map!==undefined)this.env_map=a.env_map;if(a.combine!==undefined)this.combine=a.combine;if(a.reflectivity!==undefined)this.reflectivity=a.reflectivity;if(a.refraction_ratio!==undefined)this.refraction_ratio=a.refraction_ratio;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframe_linewidth!==undefined)this.wireframe_linewidth=a.wireframe_linewidth;
  67. if(a.wireframe_linecap!==undefined)this.wireframe_linecap=a.wireframe_linecap;if(a.wireframe_linejoin!==undefined)this.wireframe_linejoin=a.wireframe_linejoin}this.toString=function(){return"THREE.MeshLambertMaterial (<br/>id: "+this.id+"<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>env_map: "+this.env_map+"<br/>combine: "+this.combine+"<br/>reflectivity: "+this.reflectivity+"<br/>refraction_ratio: "+this.refraction_ratio+"<br/>opacity: "+this.opacity+"<br/>shading: "+this.shading+"<br/>blending: "+
  68. this.blending+"<br/>wireframe: "+this.wireframe+"<br/>wireframe_linewidth: "+this.wireframe_linewidth+"<br/>wireframe_linecap: "+this.wireframe_linecap+"<br/>wireframe_linejoin: "+this.wireframe_linejoin+"<br/> )"}};THREE.MeshLambertMaterialCounter={value:0};
  69. THREE.MeshPhongMaterial=function(a){this.id=THREE.MeshPhongMaterialCounter.value++;this.color=new THREE.Color(15658734);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.Multiply;this.reflectivity=1;this.refraction_ratio=0.98;this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=this.wireframe_linecap=
  70. "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=
  71. a.reflectivity;if(a.refraction_ratio!==undefined)this.refraction_ratio=a.refraction_ratio;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframe_linewidth!==undefined)this.wireframe_linewidth=a.wireframe_linewidth;if(a.wireframe_linecap!==undefined)this.wireframe_linecap=a.wireframe_linecap;if(a.wireframe_linejoin!==undefined)this.wireframe_linejoin=
  72. a.wireframe_linejoin}this.toString=function(){return"THREE.MeshPhongMaterial (<br/>id: "+this.id+"<br/>color: "+this.color+"<br/>ambient: "+this.ambient+"<br/>specular: "+this.specular+"<br/>shininess: "+this.shininess+"<br/>map: "+this.map+"<br/>specular_map: "+this.specular_map+"<br/>env_map: "+this.env_map+"<br/>combine: "+this.combine+"<br/>reflectivity: "+this.reflectivity+"<br/>refraction_ratio: "+this.refraction_ratio+"<br/>opacity: "+this.opacity+"<br/>shading: "+this.shading+"<br/>wireframe: "+
  73. 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};
  74. THREE.MeshDepthMaterial=function(a){this.near=1;this.far=1E3;this.opacity=1;this.blending=THREE.NormalBlending;if(a){if(a.near!==undefined)this.near=a.near;if(a.far!==undefined)this.far=a.far;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}this.__2near=2*this.near;this.__farPlusNear=this.far+this.near;this.__farMinusNear=this.far-this.near;this.toString=function(){return"THREE.MeshDepthMaterial"}};
  75. THREE.MeshNormalMaterial=function(a){this.opacity=1;this.shading=THREE.FlatShading;this.blending=THREE.NormalBlending;if(a){if(a.opacity!==undefined)this.opacity=a.opacity;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending}this.toString=function(){return"THREE.MeshNormalMaterial"}};THREE.MeshFaceMaterial=function(){this.toString=function(){return"THREE.MeshFaceMaterial"}};
  76. THREE.MeshCubeMaterial=function(a){this.id=THREE.MeshCubeMaterial.value++;this.env_map=null;this.blending=THREE.NormalBlending;if(a)if(a.env_map!==undefined)this.env_map=a.env_map;this.toString=function(){return"THREE.MeshCubeMaterial( id: "+this.id+"<br/>env_map: "+this.env_map+" )"}};THREE.MeshCubeMaterialCounter={value:0};
  77. THREE.MeshShaderMaterial=function(a){this.id=THREE.MeshShaderMaterialCounter.value++;this.vertex_shader=this.fragment_shader="void main() {}";this.uniforms={};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!==undefined)this.uniforms=
  78. a.uniforms;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframe_linewidth!==undefined)this.wireframe_linewidth=a.wireframe_linewidth;if(a.wireframe_linecap!==undefined)this.wireframe_linecap=a.wireframe_linecap;if(a.wireframe_linejoin!==undefined)this.wireframe_linejoin=a.wireframe_linejoin}this.toString=function(){return"THREE.MeshShaderMaterial (<br/>id: "+this.id+"<br/>blending: "+
  79. 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};
  80. THREE.ParticleBasicMaterial=function(a){this.color=new THREE.Color(16711680);this.map=null;this.opacity=1;this.blending=THREE.NormalBlending;this.offset=new THREE.Vector2;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.map!==undefined)this.map=a.map;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}this.toString=function(){return"THREE.ParticleBasicMaterial (<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>opacity: "+this.opacity+"<br/>blending: "+
  81. this.blending+"<br/>)"}};THREE.ParticleCircleMaterial=function(a){this.color=new THREE.Color(16711680);this.opacity=1;this.blending=THREE.NormalBlending;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}this.toString=function(){return"THREE.ParticleCircleMaterial (<br/>color: "+this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>)"}};
  82. THREE.ParticleDOMMaterial=function(a){this.domElement=a;this.toString=function(){return"THREE.ParticleDOMMaterial ( domElement: "+this.domElement+" )"}};THREE.Texture=function(a,b,d,i){this.image=a;this.loaded=false;this.mapping=b!==undefined?b:THREE.UVMapping;this.wrap_s=d!==undefined?d:THREE.ClampToEdge;this.wrap_t=i!==undefined?i:THREE.ClampToEdge;this.toString=function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>wrap_s: "+this.wrap_s+"<br/>wrap_t: "+this.wrap_t+"<br/>)"}};
  83. THREE.UVMapping=0;THREE.ReflectionMapping=1;THREE.RefractionMapping=2;THREE.Multiply=0;THREE.Mix=1;THREE.Repeat=0;THREE.ClampToEdge=1;THREE.MirroredRepeat=2;THREE.TextureCube=function(a,b){this.image=a;this.mapping=b?b:THREE.ReflectionMap;this.toString=function(){return"THREE.TextureCube (<br/>image: "+this.image+"<br/>mapping: "+this.mapping+"<br/>)"}};
  84. THREE.Scene=function(){this.objects=[];this.lights=[];this.addObject=function(a){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.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+" )"}};
  85. THREE.Projector=function(){function a(S,B){var e=0,f=1,k=S.z+S.w,o=B.z+B.w,g=-S.z+S.w,h=-B.z+B.w;if(k>=0&&o>=0&&g>=0&&h>=0)return true;else if(k<0&&o<0||g<0&&h<0)return false;else{if(k<0)e=Math.max(e,k/(k-o));else if(o<0)f=Math.min(f,k/(k-o));if(g<0)e=Math.max(e,g/(g-h));else if(h<0)f=Math.min(f,g/(g-h));if(f<e)return false;else{S.lerpSelf(B,e);B.lerpSelf(S,1-f);return true}}}var b=null,d,i,j,p=[],m,r,l=[],c,z,G=[],x=new THREE.Vector4,F=new THREE.Matrix4,O=new THREE.Matrix4,J=new THREE.Vector4,M=
  86. new THREE.Vector4,n;this.projectScene=function(S,B){var e,f,k,o,g,h,w,s,L,u,T,Q,t,H,q,A,y;b=[];j=r=z=0;B.autoUpdateMatrix&&B.updateMatrix();F.multiply(B.projectionMatrix,B.matrix);w=S.objects;e=0;for(f=w.length;e<f;e++){s=w[e];s.autoUpdateMatrix&&s.updateMatrix();L=s.matrix;u=s.rotationMatrix;T=s.material;Q=s.overdraw;if(s instanceof THREE.Mesh){t=s.geometry.vertices;k=0;for(o=t.length;k<o;k++){H=t[k];H.positionWorld.copy(H.position);L.transformVector3(H.positionWorld);q=H.positionScreen;q.copy(H.positionWorld);
  87. F.transformVector4(q);q.multiplyScalar(1/q.w);H.__visible=q.z>0&&q.z<1}H=s.geometry.faces;k=0;for(o=H.length;k<o;k++){q=H[k];if(q instanceof THREE.Face3){g=t[q.a];h=t[q.b];A=t[q.c];if(g.__visible&&h.__visible&&A.__visible)if(s.doubleSided||s.flipSided!=(A.positionScreen.x-g.positionScreen.x)*(h.positionScreen.y-g.positionScreen.y)-(A.positionScreen.y-g.positionScreen.y)*(h.positionScreen.x-g.positionScreen.x)<0){d=p[j]=p[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(g.positionWorld);d.v2.positionWorld.copy(h.positionWorld);
  88. d.v3.positionWorld.copy(A.positionWorld);d.v1.positionScreen.copy(g.positionScreen);d.v2.positionScreen.copy(h.positionScreen);d.v3.positionScreen.copy(A.positionScreen);d.normalWorld.copy(q.normal);u.transformVector3(d.normalWorld);d.centroidWorld.copy(q.centroid);L.transformVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);F.transformVector3(d.centroidScreen);A=q.vertexNormals;n=d.vertexNormalsWorld;g=0;for(h=A.length;g<h;g++){y=n[g]=n[g]||new THREE.Vector3;y.copy(A[g]);u.transformVector3(y)}d.z=
  89. d.centroidScreen.z;d.meshMaterial=T;d.faceMaterial=q.material;d.overdraw=Q;if(s.geometry.uvs[k]){d.uvs[0]=s.geometry.uvs[k][0];d.uvs[1]=s.geometry.uvs[k][1];d.uvs[2]=s.geometry.uvs[k][2]}b.push(d);j++}}else if(q instanceof THREE.Face4){g=t[q.a];h=t[q.b];A=t[q.c];y=t[q.d];if(g.__visible&&h.__visible&&A.__visible&&y.__visible)if(s.doubleSided||s.flipSided!=((y.positionScreen.x-g.positionScreen.x)*(h.positionScreen.y-g.positionScreen.y)-(y.positionScreen.y-g.positionScreen.y)*(h.positionScreen.x-g.positionScreen.x)<
  90. 0||(h.positionScreen.x-A.positionScreen.x)*(y.positionScreen.y-A.positionScreen.y)-(h.positionScreen.y-A.positionScreen.y)*(y.positionScreen.x-A.positionScreen.x)<0)){d=p[j]=p[j]||new THREE.RenderableFace3;d.v1.positionWorld.copy(g.positionWorld);d.v2.positionWorld.copy(h.positionWorld);d.v3.positionWorld.copy(y.positionWorld);d.v1.positionScreen.copy(g.positionScreen);d.v2.positionScreen.copy(h.positionScreen);d.v3.positionScreen.copy(y.positionScreen);d.normalWorld.copy(q.normal);u.transformVector3(d.normalWorld);
  91. d.centroidWorld.copy(q.centroid);L.transformVector3(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);F.transformVector3(d.centroidScreen);d.z=d.centroidScreen.z;d.meshMaterial=T;d.faceMaterial=q.material;d.overdraw=Q;if(s.geometry.uvs[k]){d.uvs[0]=s.geometry.uvs[k][0];d.uvs[1]=s.geometry.uvs[k][1];d.uvs[2]=s.geometry.uvs[k][3]}b.push(d);j++;i=p[j]=p[j]||new THREE.RenderableFace3;i.v1.positionWorld.copy(h.positionWorld);i.v2.positionWorld.copy(A.positionWorld);i.v3.positionWorld.copy(y.positionWorld);
  92. i.v1.positionScreen.copy(h.positionScreen);i.v2.positionScreen.copy(A.positionScreen);i.v3.positionScreen.copy(y.positionScreen);i.normalWorld.copy(d.normalWorld);i.centroidWorld.copy(d.centroidWorld);i.centroidScreen.copy(d.centroidScreen);i.z=i.centroidScreen.z;i.meshMaterial=T;i.faceMaterial=q.material;i.overdraw=Q;if(s.geometry.uvs[k]){i.uvs[0]=s.geometry.uvs[k][1];i.uvs[1]=s.geometry.uvs[k][2];i.uvs[2]=s.geometry.uvs[k][3]}b.push(i);j++}}}}else if(s instanceof THREE.Line){O.multiply(F,L);t=s.geometry.vertices;
  93. H=t[0];H.positionScreen.copy(H.position);O.transformVector4(H.positionScreen);k=1;for(o=t.length;k<o;k++){g=t[k];g.positionScreen.copy(g.position);O.transformVector4(g.positionScreen);h=t[k-1];J.copy(g.positionScreen);M.copy(h.positionScreen);if(a(J,M)){J.multiplyScalar(1/J.w);M.multiplyScalar(1/M.w);m=l[r]=l[r]||new THREE.RenderableLine;m.v1.positionScreen.copy(J);m.v2.positionScreen.copy(M);m.z=Math.max(J.z,M.z);m.material=s.material;b.push(m);r++}}}else if(s instanceof THREE.Particle){x.set(s.position.x,
  94. s.position.y,s.position.z,1);F.transformVector4(x);x.z/=x.w;if(x.z>0&&x.z<1){c=G[z]=G[z]||new THREE.RenderableParticle;c.x=x.x/x.w;c.y=x.y/x.w;c.z=x.z;c.rotation=s.rotation.z;c.scale.x=s.scale.x*Math.abs(c.x-(x.x+B.projectionMatrix.n11)/(x.w+B.projectionMatrix.n14));c.scale.y=s.scale.y*Math.abs(c.y-(x.y+B.projectionMatrix.n22)/(x.w+B.projectionMatrix.n24));c.material=s.material;b.push(c);z++}}}b.sort(function(P,D){return D.z-P.z});return b};this.unprojectVector=function(S,B){var e=new THREE.Matrix4;
  95. e.multiply(THREE.Matrix4.makeInvert(B.matrix),THREE.Matrix4.makeInvert(B.projectionMatrix));e.transformVector3(S);return S}};
  96. THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,d,i,j,p;this.domElement=document.createElement("div");this.setSize=function(m,r){d=m;i=r;j=d/2;p=i/2};this.render=function(m,r){var l,c,z,G,x,F,O,J;a=b.projectScene(m,r);l=0;for(c=a.length;l<c;l++){x=a[l];if(x instanceof THREE.RenderableParticle){O=x.x*j+j;J=x.y*p+p;z=0;for(G=x.material.length;z<G;z++){F=x.material[z];if(F instanceof THREE.ParticleDOMMaterial){F=F.domElement;F.style.left=O+"px";F.style.top=J+"px"}}}}}};
  97. THREE.CanvasRenderer=function(){function a(I,Y,U,E){var v,K,$,N,X=I.lights;I=0;for(v=X.length;I<v;I++){K=X[I];$=K.color;N=K.intensity;if(K instanceof THREE.DirectionalLight){K=U.dot(K.position)*N;if(K>0){E.r+=$.r*K;E.g+=$.g*K;E.b+=$.b*K}}else if(K instanceof THREE.PointLight){aa.sub(K.position,Y);aa.normalize();K=U.dot(aa)*N;if(K>0){E.r+=$.r*K;E.g+=$.g*K;E.b+=$.b*K}}}}function b(I,Y,U,E,v,K){if(v.opacity!=0){p(v.opacity);m(v.blending);L=I.positionScreen.x;u=I.positionScreen.y;T=Y.positionScreen.x;
  98. Q=Y.positionScreen.y;t=U.positionScreen.x;H=U.positionScreen.y;var $=L,N=u,X=T,ba=Q,Z=t,ca=H;n.beginPath();n.moveTo($,N);n.lineTo(X,ba);n.lineTo(Z,ca);n.lineTo($,N);n.closePath();if(v instanceof THREE.MeshBasicMaterial)if(v.map&&v.map.loaded)j(L,u,T,Q,t,H,v.map.image,E.uvs[0].u,E.uvs[0].v,E.uvs[1].u,E.uvs[1].v,E.uvs[2].u,E.uvs[2].v);else if(v.env_map&&v.env_map.loaded){if(v.env_map.mapping==THREE.ReflectionMapping){aa.copy(E.vertexNormalsWorld[0]);V=(aa.x*camera.matrix.n11+aa.y*camera.matrix.n12+
  99. aa.z*camera.matrix.n13)*0.5+0.5;ka=-(aa.x*camera.matrix.n21+aa.y*camera.matrix.n22+aa.z*camera.matrix.n23)*0.5+0.5;aa.copy(E.vertexNormalsWorld[1]);za=(aa.x*camera.matrix.n11+aa.y*camera.matrix.n12+aa.z*camera.matrix.n13)*0.5+0.5;Aa=-(aa.x*camera.matrix.n21+aa.y*camera.matrix.n22+aa.z*camera.matrix.n23)*0.5+0.5;aa.copy(E.vertexNormalsWorld[2]);Ba=(aa.x*camera.matrix.n11+aa.y*camera.matrix.n12+aa.z*camera.matrix.n13)*0.5+0.5;Ca=-(aa.x*camera.matrix.n21+aa.y*camera.matrix.n22+aa.z*camera.matrix.n23)*
  100. 0.5+0.5;j(L,u,T,Q,t,H,v.env_map.image,V,ka,za,Aa,Ba,Ca)}}else v.wireframe?d(v.color.__styleString,v.wireframe_linewidth):i(v.color.__styleString);else if(v instanceof THREE.MeshLambertMaterial){if(v.map&&!v.wireframe){j(L,u,T,Q,t,H,v.map.image,E.uvs[0].u,E.uvs[0].v,E.uvs[1].u,E.uvs[1].v,E.uvs[2].u,E.uvs[2].v);m(THREE.SubtractiveBlending)}if(va)if(!v.wireframe&&v.shading==THREE.SmoothShading&&E.vertexNormalsWorld.length==3){A.r=y.r=P.r=ga.r;A.g=y.g=P.g=ga.g;A.b=y.b=P.b=ga.b;a(K,E.v1.positionWorld,
  101. E.vertexNormalsWorld[0],A);a(K,E.v2.positionWorld,E.vertexNormalsWorld[1],y);a(K,E.v3.positionWorld,E.vertexNormalsWorld[2],P);D.r=(y.r+P.r)*0.5;D.g=(y.g+P.g)*0.5;D.b=(y.b+P.b)*0.5;R=r(A,y,P,D);j(L,u,T,Q,t,H,R,0,0,1,0,0,1)}else{ha.r=ga.r;ha.g=ga.g;ha.b=ga.b;a(K,E.centroidWorld,E.normalWorld,ha);q.r=v.color.r*ha.r;q.g=v.color.g*ha.g;q.b=v.color.b*ha.b;q.updateStyleString();v.wireframe?d(q.__styleString,v.wireframe_linewidth):i(q.__styleString)}else v.wireframe?d(v.color.__styleString,v.wireframe_linewidth):
  102. i(v.color.__styleString)}else if(v instanceof THREE.MeshDepthMaterial){C=v.__2near;W=v.__farPlusNear;ea=v.__farMinusNear;A.r=A.g=A.b=1-C/(W-I.positionScreen.z*ea);y.r=y.g=y.b=1-C/(W-Y.positionScreen.z*ea);P.r=P.g=P.b=1-C/(W-U.positionScreen.z*ea);D.r=(y.r+P.r)*0.5;D.g=(y.g+P.g)*0.5;D.b=(y.b+P.b)*0.5;R=r(A,y,P,D);j(L,u,T,Q,t,H,R,0,0,1,0,0,1)}else if(v instanceof THREE.MeshNormalMaterial){q.r=l(E.normalWorld.x);q.g=l(E.normalWorld.y);q.b=l(E.normalWorld.z);q.updateStyleString();v.wireframe?d(q.__styleString,
  103. v.wireframe_linewidth):i(q.__styleString)}}}function d(I,Y){if(e!=I)n.strokeStyle=e=I;if(k!=Y)n.lineWidth=k=Y;n.stroke();da.inflate(Y*2)}function i(I){if(f!=I)n.fillStyle=f=I;n.fill()}function j(I,Y,U,E,v,K,$,N,X,ba,Z,ca,na){var la,fa;la=$.width-1;fa=$.height-1;N*=la;X*=fa;ba*=la;Z*=fa;ca*=la;na*=fa;U-=I;E-=Y;v-=I;K-=Y;ba-=N;Z-=X;ca-=N;na-=X;fa=1/(ba*na-ca*Z);la=(na*U-Z*v)*fa;Z=(na*E-Z*K)*fa;U=(ba*v-ca*U)*fa;E=(ba*K-ca*E)*fa;I=I-la*N-U*X;Y=Y-Z*N-E*X;n.save();n.transform(la,Z,U,E,I,Y);n.clip();n.drawImage($,
  104. 0,0);n.restore()}function p(I){if(S!=I)n.globalAlpha=S=I}function m(I){if(B!=I){switch(I){case THREE.NormalBlending:n.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:n.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:n.globalCompositeOperation="darker"}B=I}}function r(I,Y,U,E){ia[0]=g(0,o(255,~~(I.r*255)));ia[1]=g(0,o(255,~~(I.g*255)));ia[2]=g(0,o(255,~~(I.b*255)));ia[4]=g(0,o(255,~~(Y.r*255)));ia[5]=g(0,o(255,~~(Y.g*255)));ia[6]=g(0,o(255,~~(Y.b*255)));
  105. ia[8]=g(0,o(255,~~(U.r*255)));ia[9]=g(0,o(255,~~(U.g*255)));ia[10]=g(0,o(255,~~(U.b*255)));ia[12]=g(0,o(255,~~(E.r*255)));ia[13]=g(0,o(255,~~(E.g*255)));ia[14]=g(0,o(255,~~(E.b*255)));ra.putImageData(wa,0,0);ua.drawImage(sa,0,0);return ta}function l(I){return I<0?o((1+I)*0.5,0.5):0.5+o(I*0.5,0.5)}function c(I,Y){var U=Y.x-I.x,E=Y.y-I.y,v=1/Math.sqrt(U*U+E*E);U*=v;E*=v;Y.x+=U;Y.y+=E;I.x-=U;I.y-=E}var z=null,G=new THREE.Projector,x=document.createElement("canvas"),F,O,J,M,n=x.getContext("2d"),S=1,B=
  106. 0,e=null,f=null,k=1,o=Math.min,g=Math.max,h,w,s,L,u,T,Q,t,H,q=new THREE.Color,A=new THREE.Color,y=new THREE.Color,P=new THREE.Color,D=new THREE.Color,C,W,ea,R,V,ka,za,Aa,Ba,Ca,ma=new THREE.Rectangle,ja=new THREE.Rectangle,da=new THREE.Rectangle,va=false,ha=new THREE.Color,ga=new THREE.Color,oa=new THREE.Color,pa=new THREE.Color,Da=Math.PI*2,aa=new THREE.Vector3,sa,ra,wa,ia,ta,ua,qa=16;sa=document.createElement("canvas");sa.width=sa.height=2;ra=sa.getContext("2d");ra.fillStyle="rgba(0,0,0,1)";ra.fillRect(0,
  107. 0,2,2);wa=ra.getImageData(0,0,2,2);ia=wa.data;ta=document.createElement("canvas");ta.width=ta.height=qa;ua=ta.getContext("2d");ua.translate(-qa/2,-qa/2);ua.scale(qa,qa);qa--;this.domElement=x;this.autoClear=true;this.setSize=function(I,Y){F=I;O=Y;J=F/2;M=O/2;x.width=F;x.height=O;ma.set(-J,-M,J,M)};this.clear=function(){if(!ja.isEmpty()){ja.inflate(1);ja.minSelf(ma);n.clearRect(ja.getX(),ja.getY(),ja.getWidth(),ja.getHeight());ja.empty()}};this.render=function(I,Y){var U,E,v,K,$,N,X,ba;n.setTransform(1,
  108. 0,0,-1,J,M);this.autoClear&&this.clear();z=G.projectScene(I,Y);n.fillStyle="rgba(0, 255, 255, 0.5)";n.fillRect(ma.getX(),ma.getY(),ma.getWidth(),ma.getHeight());if(va=I.lights.length>0){$=I.lights;ga.setRGB(0,0,0);oa.setRGB(0,0,0);pa.setRGB(0,0,0);U=0;for(E=$.length;U<E;U++){v=$[U];K=v.color;if(v instanceof THREE.AmbientLight){ga.r+=K.r;ga.g+=K.g;ga.b+=K.b}else if(v instanceof THREE.DirectionalLight){oa.r+=K.r;oa.g+=K.g;oa.b+=K.b}else if(v instanceof THREE.PointLight){pa.r+=K.r;pa.g+=K.g;pa.b+=K.b}}}U=
  109. 0;for(E=z.length;U<E;U++){v=z[U];da.empty();if(v instanceof THREE.RenderableParticle){h=v;h.x*=J;h.y*=M;K=0;for($=v.material.length;K<$;K++)a:{N=h;X=v;var Z=v.material[K];if(Z.opacity!=0){p(Z.opacity);m(Z.blending);ba=void 0;var ca=void 0,na=void 0,la=void 0,fa=void 0,xa=void 0,ya=void 0;if(Z instanceof THREE.ParticleBasicMaterial){if(Z.map){fa=Z.map;xa=fa.width>>1;ya=fa.height>>1;na=X.scale.x*J;la=X.scale.y*M;ba=na*xa;ca=la*ya;da.set(N.x-ba,N.y-ca,N.x+ba,N.y+ca);if(!ma.instersects(da))break a;n.save();
  110. n.translate(N.x,N.y);n.rotate(-X.rotation);n.scale(na,-la);n.translate(-xa,-ya);n.drawImage(fa,0,0);n.restore()}n.beginPath();n.moveTo(N.x-10,N.y);n.lineTo(N.x+10,N.y);n.moveTo(N.x,N.y-10);n.lineTo(N.x,N.y+10);n.closePath();n.strokeStyle="rgb(255,255,0)";n.stroke()}else if(Z instanceof THREE.ParticleCircleMaterial){if(va){ha.r=ga.r+oa.r+pa.r;ha.g=ga.g+oa.g+pa.g;ha.b=ga.b+oa.b+pa.b;q.r=Z.color.r*ha.r;q.g=Z.color.g*ha.g;q.b=Z.color.b*ha.b;q.updateStyleString()}else q.__styleString=Z.color.__styleString;
  111. ba=X.scale.x*J;ca=X.scale.y*M;da.set(N.x-ba,N.y-ca,N.x+ba,N.y+ca);if(ma.instersects(da)){Z=q.__styleString;if(f!=Z)n.fillStyle=f=Z;n.save();n.translate(N.x,N.y);n.rotate(-X.rotation);n.scale(ba,ca);n.beginPath();n.arc(0,0,1,0,Da,true);n.closePath();n.fill();n.restore()}}}}}else if(v instanceof THREE.RenderableLine){h=v.v1;w=v.v2;h.positionScreen.x*=J;h.positionScreen.y*=M;w.positionScreen.x*=J;w.positionScreen.y*=M;da.addPoint(h.positionScreen.x,h.positionScreen.y);da.addPoint(w.positionScreen.x,
  112. w.positionScreen.y);if(ma.instersects(da)){K=0;for($=v.material.length;K<$;){X=h;ba=w;N=v.material[K++];if(N.opacity!=0){p(N.opacity);m(N.blending);n.beginPath();n.moveTo(X.positionScreen.x,X.positionScreen.y);n.lineTo(ba.positionScreen.x,ba.positionScreen.y);n.closePath();if(N instanceof THREE.LineBasicMaterial){q.__styleString=N.color.__styleString;X=N.linewidth;if(k!=X)n.lineWidth=k=X;X=q.__styleString;if(e!=X)n.strokeStyle=e=X;n.stroke();da.inflate(N.linewidth*2)}}}}}else if(v instanceof THREE.RenderableFace3){h=
  113. v.v1;w=v.v2;s=v.v3;h.positionScreen.x*=J;h.positionScreen.y*=M;w.positionScreen.x*=J;w.positionScreen.y*=M;s.positionScreen.x*=J;s.positionScreen.y*=M;if(v.overdraw){c(h.positionScreen,w.positionScreen);c(w.positionScreen,s.positionScreen);c(s.positionScreen,h.positionScreen)}da.addPoint(h.positionScreen.x,h.positionScreen.y);da.addPoint(w.positionScreen.x,w.positionScreen.y);da.addPoint(s.positionScreen.x,s.positionScreen.y);if(ma.instersects(da)){K=0;for($=v.meshMaterial.length;K<$;){ba=v.meshMaterial[K++];
  114. if(ba instanceof THREE.MeshFaceMaterial){N=0;for(X=v.faceMaterial.length;N<X;)(ba=v.faceMaterial[N++])&&b(h,w,s,v,ba,I)}else b(h,w,s,v,ba,I)}}}ja.addRectangle(da)}n.lineWidth=1;n.strokeStyle="rgba( 255, 0, 0, 0.5 )";n.strokeRect(ja.getX(),ja.getY(),ja.getWidth(),ja.getHeight());n.setTransform(1,0,0,1,0,0)}};
  115. THREE.SVGRenderer=function(){function a(q,A,y){var P,D,C,W;P=0;for(D=q.lights.length;P<D;P++){C=q.lights[P];if(C instanceof THREE.DirectionalLight){W=A.normalWorld.dot(C.position)*C.intensity;if(W>0){y.r+=C.color.r*W;y.g+=C.color.g*W;y.b+=C.color.b*W}}else if(C instanceof THREE.PointLight){h.sub(C.position,A.centroidWorld);h.normalize();W=A.normalWorld.dot(h)*C.intensity;if(W>0){y.r+=C.color.r*W;y.g+=C.color.g*W;y.b+=C.color.b*W}}}}function b(q,A,y,P,D,C){u=i(T++);u.setAttribute("d","M "+q.positionScreen.x+
  116. " "+q.positionScreen.y+" L "+A.positionScreen.x+" "+A.positionScreen.y+" L "+y.positionScreen.x+","+y.positionScreen.y+"z");if(D instanceof THREE.MeshBasicMaterial)B.__styleString=D.color.__styleString;else if(D instanceof THREE.MeshLambertMaterial)if(S){e.r=f.r;e.g=f.g;e.b=f.b;a(C,P,e);B.r=D.color.r*e.r;B.g=D.color.g*e.g;B.b=D.color.b*e.b;B.updateStyleString()}else B.__styleString=D.color.__styleString;else if(D instanceof THREE.MeshDepthMaterial){g=1-D.__2near/(D.__farPlusNear-P.z*D.__farMinusNear);
  117. B.setRGB(g,g,g)}else D instanceof THREE.MeshNormalMaterial&&B.setRGB(j(P.normalWorld.x),j(P.normalWorld.y),j(P.normalWorld.z));D.wireframe?u.setAttribute("style","fill: none; stroke: "+B.__styleString+"; stroke-width: "+D.wireframe_linewidth+"; stroke-opacity: "+D.opacity+"; stroke-linecap: "+D.wireframe_linecap+"; stroke-linejoin: "+D.wireframe_linejoin):u.setAttribute("style","fill: "+B.__styleString+"; fill-opacity: "+D.opacity);r.appendChild(u)}function d(q,A,y,P,D,C,W){u=i(T++);u.setAttribute("d",
  118. "M "+q.positionScreen.x+" "+q.positionScreen.y+" L "+A.positionScreen.x+" "+A.positionScreen.y+" L "+y.positionScreen.x+","+y.positionScreen.y+" L "+P.positionScreen.x+","+P.positionScreen.y+"z");if(C instanceof THREE.MeshBasicMaterial)B.__styleString=C.color.__styleString;else if(C instanceof THREE.MeshLambertMaterial)if(S){e.r=f.r;e.g=f.g;e.b=f.b;a(W,D,e);B.r=C.color.r*e.r;B.g=C.color.g*e.g;B.b=C.color.b*e.b;B.updateStyleString()}else B.__styleString=C.color.__styleString;else if(C instanceof THREE.MeshDepthMaterial){g=
  119. 1-C.__2near/(C.__farPlusNear-D.z*C.__farMinusNear);B.setRGB(g,g,g)}else C instanceof THREE.MeshNormalMaterial&&B.setRGB(j(D.normalWorld.x),j(D.normalWorld.y),j(D.normalWorld.z));C.wireframe?u.setAttribute("style","fill: none; stroke: "+B.__styleString+"; stroke-width: "+C.wireframe_linewidth+"; stroke-opacity: "+C.opacity+"; stroke-linecap: "+C.wireframe_linecap+"; stroke-linejoin: "+C.wireframe_linejoin):u.setAttribute("style","fill: "+B.__styleString+"; fill-opacity: "+C.opacity);r.appendChild(u)}
  120. function i(q){if(w[q]==null){w[q]=document.createElementNS("http://www.w3.org/2000/svg","path");H==0&&w[q].setAttribute("shape-rendering","crispEdges");return w[q]}return w[q]}function j(q){return q<0?Math.min((1+q)*0.5,0.5):0.5+Math.min(q*0.5,0.5)}var p=null,m=new THREE.Projector,r=document.createElementNS("http://www.w3.org/2000/svg","svg"),l,c,z,G,x,F,O,J,M=new THREE.Rectangle,n=new THREE.Rectangle,S=false,B=new THREE.Color(16777215),e=new THREE.Color(16777215),f=new THREE.Color(0),k=new THREE.Color(0),
  121. o=new THREE.Color(0),g,h=new THREE.Vector3,w=[],s=[],L=[],u,T,Q,t,H=1;this.domElement=r;this.autoClear=true;this.setQuality=function(q){switch(q){case "high":H=1;break;case "low":H=0}};this.setSize=function(q,A){l=q;c=A;z=l/2;G=c/2;r.setAttribute("viewBox",-z+" "+-G+" "+l+" "+c);r.setAttribute("width",l);r.setAttribute("height",c);M.set(-z,-G,z,G)};this.clear=function(){for(;r.childNodes.length>0;)r.removeChild(r.childNodes[0])};this.render=function(q,A){var y,P,D,C,W,ea,R,V;this.autoClear&&this.clear();
  122. p=m.projectScene(q,A);t=Q=T=0;if(S=q.lights.length>0){R=q.lights;f.setRGB(0,0,0);k.setRGB(0,0,0);o.setRGB(0,0,0);y=0;for(P=R.length;y<P;y++){D=R[y];C=D.color;if(D instanceof THREE.AmbientLight){f.r+=C.r;f.g+=C.g;f.b+=C.b}else if(D instanceof THREE.DirectionalLight){k.r+=C.r;k.g+=C.g;k.b+=C.b}else if(D instanceof THREE.PointLight){o.r+=C.r;o.g+=C.g;o.b+=C.b}}}y=0;for(P=p.length;y<P;y++){R=p[y];n.empty();if(R instanceof THREE.RenderableParticle){x=R;x.x*=z;x.y*=-G;D=0;for(C=R.material.length;D<C;D++)if(V=
  123. R.material[D]){W=x;ea=R;V=V;var ka=Q++;if(s[ka]==null){s[ka]=document.createElementNS("http://www.w3.org/2000/svg","circle");H==0&&s[ka].setAttribute("shape-rendering","crispEdges")}u=s[ka];u.setAttribute("cx",W.x);u.setAttribute("cy",W.y);u.setAttribute("r",ea.scale.x*z);if(V instanceof THREE.ParticleCircleMaterial){if(S){e.r=f.r+k.r+o.r;e.g=f.g+k.g+o.g;e.b=f.b+k.b+o.b;B.r=V.color.r*e.r;B.g=V.color.g*e.g;B.b=V.color.b*e.b;B.updateStyleString()}else B=V.color;u.setAttribute("style","fill: "+B.__styleString)}r.appendChild(u)}}else if(R instanceof
  124. THREE.RenderableLine){x=R.v1;F=R.v2;x.positionScreen.x*=z;x.positionScreen.y*=-G;F.positionScreen.x*=z;F.positionScreen.y*=-G;n.addPoint(x.positionScreen.x,x.positionScreen.y);n.addPoint(F.positionScreen.x,F.positionScreen.y);if(M.instersects(n)){D=0;for(C=R.material.length;D<C;)if(V=R.material[D++]){W=x;ea=F;V=V;ka=t++;if(L[ka]==null){L[ka]=document.createElementNS("http://www.w3.org/2000/svg","line");H==0&&L[ka].setAttribute("shape-rendering","crispEdges")}u=L[ka];u.setAttribute("x1",W.positionScreen.x);
  125. u.setAttribute("y1",W.positionScreen.y);u.setAttribute("x2",ea.positionScreen.x);u.setAttribute("y2",ea.positionScreen.y);if(V instanceof THREE.LineBasicMaterial){B.__styleString=V.color.__styleString;u.setAttribute("style","fill: none; stroke: "+B.__styleString+"; stroke-width: "+V.linewidth+"; stroke-opacity: "+V.opacity+"; stroke-linecap: "+V.linecap+"; stroke-linejoin: "+V.linejoin);r.appendChild(u)}}}}else if(R instanceof THREE.RenderableFace3){x=R.v1;F=R.v2;O=R.v3;x.positionScreen.x*=z;x.positionScreen.y*=
  126. -G;F.positionScreen.x*=z;F.positionScreen.y*=-G;O.positionScreen.x*=z;O.positionScreen.y*=-G;n.addPoint(x.positionScreen.x,x.positionScreen.y);n.addPoint(F.positionScreen.x,F.positionScreen.y);n.addPoint(O.positionScreen.x,O.positionScreen.y);if(M.instersects(n)){D=0;for(C=R.meshMaterial.length;D<C;){V=R.meshMaterial[D++];if(V instanceof THREE.MeshFaceMaterial){W=0;for(ea=R.faceMaterial.length;W<ea;)(V=R.faceMaterial[W++])&&b(x,F,O,R,V,q)}else V&&b(x,F,O,R,V,q)}}}else if(R instanceof THREE.RenderableFace4){x=
  127. R.v1;F=R.v2;O=R.v3;J=R.v4;x.positionScreen.x*=z;x.positionScreen.y*=-G;F.positionScreen.x*=z;F.positionScreen.y*=-G;O.positionScreen.x*=z;O.positionScreen.y*=-G;J.positionScreen.x*=z;J.positionScreen.y*=-G;n.addPoint(x.positionScreen.x,x.positionScreen.y);n.addPoint(F.positionScreen.x,F.positionScreen.y);n.addPoint(O.positionScreen.x,O.positionScreen.y);n.addPoint(J.positionScreen.x,J.positionScreen.y);if(M.instersects(n)){D=0;for(C=R.meshMaterial.length;D<C;){V=R.meshMaterial[D++];if(V instanceof
  128. THREE.MeshFaceMaterial){W=0;for(ea=R.faceMaterial.length;W<ea;)(V=R.faceMaterial[W++])&&d(x,F,O,J,R,V,q)}else V&&d(x,F,O,J,R,V,q)}}}}}};
  129. THREE.WebGLRenderer=function(a){function b(e,f){var k=c.createProgram();c.attachShader(k,m("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\n"+e));c.attachShader(k,m("vertex","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"+f));c.linkProgram(k);c.getProgramParameter(k,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(k,
  130. c.VALIDATE_STATUS)+", gl error ["+c.getError()+"]");k.uniforms={};return k}function d(e,f){if(e instanceof THREE.TextureCube&&e.image.length==6){if(!e.image.__webGLTextureCube&&!e.image.__cubeMapInitialized&&e.image.loadCount==6){e.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,e.image.__webGLTextureCube);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,
  131. c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(var k=0;k<6;++k)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+k,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,e.image[k]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);e.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+f);c.bindTexture(c.TEXTURE_CUBE_MAP,e.image.__webGLTextureCube)}}function i(e,f){if(!e.__webGLTexture&&e.image.loaded){e.__webGLTexture=c.createTexture();
  132. c.bindTexture(c.TEXTURE_2D,e.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,e.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,r(e.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,r(e.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+f);c.bindTexture(c.TEXTURE_2D,e.__webGLTexture)}
  133. function j(e,f){var k,o,g;k=0;for(o=f.length;k<o;k++){g=f[k];e.uniforms[g]=c.getUniformLocation(e,g)}}function p(e){e.position=c.getAttribLocation(e,"position");c.enableVertexAttribArray(e.position);e.normal=c.getAttribLocation(e,"normal");c.enableVertexAttribArray(e.normal);e.uv=c.getAttribLocation(e,"uv");c.enableVertexAttribArray(e.uv)}function m(e,f){var k;if(e=="fragment")k=c.createShader(c.FRAGMENT_SHADER);else if(e=="vertex")k=c.createShader(c.VERTEX_SHADER);c.shaderSource(k,f);c.compileShader(k);
  134. if(!c.getShaderParameter(k,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(k));return null}return k}function r(e){switch(e){case THREE.Repeat:return c.REPEAT;case THREE.ClampToEdge:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeat:return c.MIRRORED_REPEAT}return 0}var l=document.createElement("canvas"),c,z,G,x=new THREE.Matrix4,F,O=new Float32Array(16),J=new Float32Array(16),M=new Float32Array(16),n=new Float32Array(9),S=new Float32Array(16);a=function(e,f){if(e){var k,o,g,h=pointLights=maxDirLights=maxPointLights=
  135. 0;k=0;for(o=e.lights.length;k<o;k++){g=e.lights[k];g instanceof THREE.DirectionalLight&&h++;g instanceof THREE.PointLight&&pointLights++}if(pointLights+h<=f){maxDirLights=h;maxPointLights=pointLights}else{maxDirLights=Math.ceil(f*h/(pointLights+h));maxPointLights=f-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:f-1}}(a,4);this.domElement=l;this.autoClear=true;try{c=l.getContext("experimental-webgl",{antialias:true})}catch(B){}if(!c){alert("WebGL not supported");
  136. throw"cannot create webgl context";}c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK);c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(0,0,0,0);(function(e,f){var k=[e?"#define MAX_DIR_LIGHTS "+e:"",f?"#define MAX_POINT_LIGHTS "+f:"","uniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",
  137. e?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",e?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",f?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",f?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","uniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",f?"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;",
  138. e?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",e?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",e?"float directionalLightWeighting = max( dot( transformedNormal, normalize(lDirection.xyz ) ), 0.0 );":"",e?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",e?"}":"",f?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",f?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",f?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
  139. "",f?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",f?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",f?"}":"","}\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"),
  140. o=[e?"#define MAX_DIR_LIGHTS "+e:"",f?"#define MAX_POINT_LIGHTS "+f:"","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;\nuniform float m2Near;\nuniform float mFarPlusNear;\nuniform float mFarMinusNear;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
  141. e?"uniform mat4 viewMatrix;":"",e?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",f?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform vec3 cameraPosition;\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 == 5 ) { \nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( -wPos.x, wPos.yz ) );\n} else if ( material == 4 ) { \ngl_FragColor = vec4( 0.5*normalize( vNormal ) + vec3(0.5, 0.5, 0.5), mOpacity );\n} else if ( material == 3 ) { \nfloat w = 0.5;\ngl_FragColor = vec4( w, w, w, mOpacity );\n} else if ( material == 2 ) { \nvec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );",
  142. f?"vec4 pointDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );":"",f?"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",f?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",f?"vec3 pointVector = normalize( vPointLightVector[ i ] );":"",f?"vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );":"",f?"float pointDotNormalHalf = dot( normal, pointHalfVector );":"",f?"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );":"",f?"float pointSpecularWeight = 0.0;":"",f?"if ( pointDotNormalHalf >= 0.0 )":
  143. "",f?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",f?"pointDiffuse += mColor * pointDiffuseWeight;":"",f?"pointSpecular += mSpecular * pointSpecularWeight;":"",f?"}":"",e?"vec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );":"",e?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",e?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",e?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",e?"vec3 dirVector = normalize( lDirection.xyz );":"",e?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
  144. "",e?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",e?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",e?"float dirSpecularWeight = 0.0;":"",e?"if ( dirDotNormalHalf >= 0.0 )":"",e?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",e?"dirDiffuse += mColor * dirDiffuseWeight;":"",e?"dirSpecular += mSpecular * dirSpecularWeight;":"",e?"}":"","vec4 totalLight = mAmbient;",e?"totalLight += dirDiffuse + dirSpecular;":"",f?"totalLight += pointDiffuse + pointSpecular;":
  145. "","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}"].join("\n");
  146. z=b(o,k);c.useProgram(z);j(z,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract","m2Near","mFarPlusNear","mFarMinusNear"]);e&&j(z,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);f&&j(z,["pointLightNumber","pointLightColor",
  147. "pointLightPosition"]);c.uniform1i(z.uniforms.enableMap,0);c.uniform1i(z.uniforms.tMap,0);c.uniform1i(z.uniforms.enableCubeMap,0);c.uniform1i(z.uniforms.tCube,1);c.uniform1i(z.uniforms.mixEnvMap,0);c.uniform1i(z.uniforms.useRefract,0);p(z)})(a.directional,a.point);this.setSize=function(e,f){l.width=e;l.height=f;c.viewport(0,0,l.width,l.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(e,f){var k,o,g,h,w,s=[],L=[],u=[];h=[];w=[];c.uniform1i(e.uniforms.enableLighting,
  148. f.lights.length);k=0;for(o=f.lights.length;k<o;k++){g=f.lights[k];if(g instanceof THREE.AmbientLight)s.push(g);else if(g instanceof THREE.DirectionalLight)u.push(g);else g instanceof THREE.PointLight&&L.push(g)}k=g=h=w=0;for(o=s.length;k<o;k++){g+=s[k].color.r;h+=s[k].color.g;w+=s[k].color.b}c.uniform3f(e.uniforms.ambientLightColor,g,h,w);h=[];w=[];k=0;for(o=u.length;k<o;k++){g=u[k];h.push(g.color.r*g.intensity);h.push(g.color.g*g.intensity);h.push(g.color.b*g.intensity);w.push(g.position.x);w.push(g.position.y);
  149. w.push(g.position.z)}if(u.length){c.uniform1i(e.uniforms.directionalLightNumber,u.length);c.uniform3fv(e.uniforms.directionalLightDirection,w);c.uniform3fv(e.uniforms.directionalLightColor,h)}h=[];w=[];k=0;for(o=L.length;k<o;k++){g=L[k];h.push(g.color.r*g.intensity);h.push(g.color.g*g.intensity);h.push(g.color.b*g.intensity);w.push(g.position.x);w.push(g.position.y);w.push(g.position.z)}if(L.length){c.uniform1i(e.uniforms.pointLightNumber,L.length);c.uniform3fv(e.uniforms.pointLightPosition,w);c.uniform3fv(e.uniforms.pointLightColor,
  150. h)}};this.createBuffers=function(e,f){var k,o,g,h,w,s,L,u,T=[],Q=[],t=[],H=[],q=[],A=0,y=e.geometry.geometryChunks[f],P;g=false;k=0;for(o=e.material.length;k<o;k++){meshMaterial=e.material[k];if(meshMaterial instanceof THREE.MeshFaceMaterial){w=0;for(P=y.material.length;w<P;w++)if(y.material[w]&&y.material[w].shading!=undefined&&y.material[w].shading==THREE.SmoothShading){g=true;break}}else if(meshMaterial&&meshMaterial.shading!=undefined&&meshMaterial.shading==THREE.SmoothShading){g=true;break}if(g)break}P=
  151. g;k=0;for(o=y.faces.length;k<o;k++){g=y.faces[k];h=e.geometry.faces[g];w=h.vertexNormals;faceNormal=h.normal;g=e.geometry.uvs[g];if(h instanceof THREE.Face3){s=e.geometry.vertices[h.a].position;L=e.geometry.vertices[h.b].position;u=e.geometry.vertices[h.c].position;t.push(s.x,s.y,s.z);t.push(L.x,L.y,L.z);t.push(u.x,u.y,u.z);if(w.length==3&&P)for(h=0;h<3;h++)H.push(w[h].x,w[h].y,w[h].z);else for(h=0;h<3;h++)H.push(faceNormal.x,faceNormal.y,faceNormal.z);if(g)for(h=0;h<3;h++)q.push(g[h].u,g[h].v);T.push(A,
  152. A+1,A+2);Q.push(A,A+1);Q.push(A,A+2);Q.push(A+1,A+2);A+=3}else if(h instanceof THREE.Face4){s=e.geometry.vertices[h.a].position;L=e.geometry.vertices[h.b].position;u=e.geometry.vertices[h.c].position;h=e.geometry.vertices[h.d].position;t.push(s.x,s.y,s.z);t.push(L.x,L.y,L.z);t.push(u.x,u.y,u.z);t.push(h.x,h.y,h.z);if(w.length==4&&P)for(h=0;h<4;h++)H.push(w[h].x,w[h].y,w[h].z);else for(h=0;h<4;h++)H.push(faceNormal.x,faceNormal.y,faceNormal.z);if(g)for(h=0;h<4;h++)q.push(g[h].u,g[h].v);T.push(A,A+
  153. 1,A+2);T.push(A,A+2,A+3);Q.push(A,A+1);Q.push(A,A+2);Q.push(A,A+3);Q.push(A+1,A+2);Q.push(A+2,A+3);A+=4}}if(t.length){y.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,y.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(t),c.STATIC_DRAW);y.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,y.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(H),c.STATIC_DRAW);y.__webGLUVBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,y.__webGLUVBuffer);
  154. c.bufferData(c.ARRAY_BUFFER,new Float32Array(q),c.STATIC_DRAW);y.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,y.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(T),c.STATIC_DRAW);y.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,y.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(Q),c.STATIC_DRAW);y.__webGLFaceCount=T.length;y.__webGLLineCount=Q.length}};this.renderBuffer=function(e,f,k){var o,g,h,w,s,L,u,
  155. T,Q,t;if(f instanceof THREE.MeshShaderMaterial){if(!f.program){f.program=b(f.fragment_shader,f.vertex_shader);u=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(t in f.uniforms)u.push(t);j(f.program,u);p(f.program)}t=f.program}else t=z;if(t!=G){c.useProgram(t);G=t}if(f instanceof THREE.MeshShaderMaterial){h=f.wireframe;w=f.wireframe_linewidth;u=t;T=f.uniforms;var H,q;for(g in T){H=T[g].type;Q=T[g].value;q=u.uniforms[g];if(H=="i")c.uniform1i(q,
  156. Q);else if(H=="f")c.uniform1f(q,Q);else if(H=="t"){c.uniform1i(q,Q);H=T[g].texture;if(H instanceof THREE.TextureCube)d(H,Q);else H instanceof THREE.Texture&&i(H,Q)}}this.loadCamera(t,e);this.loadMatrices(t)}else if(f instanceof THREE.MeshPhongMaterial||f instanceof THREE.MeshLambertMaterial||f instanceof THREE.MeshBasicMaterial){e=f.color;o=f.opacity;h=f.wireframe;w=f.wireframe_linewidth;s=f.map;L=f.env_map;u=f.combine==THREE.Mix;g=f.reflectivity;Q=f.env_map&&f.env_map.mapping==THREE.RefractionMapping;
  157. T=f.refraction_ratio;c.uniform4f(t.uniforms.mColor,e.r*o,e.g*o,e.b*o,o);c.uniform1i(t.uniforms.mixEnvMap,u);c.uniform1f(t.uniforms.mReflectivity,g);c.uniform1i(t.uniforms.useRefract,Q);c.uniform1f(t.uniforms.mRefractionRatio,T)}if(f instanceof THREE.MeshNormalMaterial){o=f.opacity;c.uniform1f(t.uniforms.mOpacity,o);c.uniform1i(t.uniforms.material,4)}else if(f instanceof THREE.MeshDepthMaterial){o=f.opacity;h=f.wireframe;w=f.wireframe_linewidth;c.uniform1f(t.uniforms.mOpacity,o);c.uniform1f(t.uniforms.m2Near,
  158. f.__2near);c.uniform1f(t.uniforms.mFarPlusNear,f.__farPlusNear);c.uniform1f(t.uniforms.mFarMinusNear,f.__farMinusNear);c.uniform1i(t.uniforms.material,3)}else if(f instanceof THREE.MeshPhongMaterial){e=f.ambient;g=f.specular;f=f.shininess;c.uniform4f(t.uniforms.mAmbient,e.r,e.g,e.b,o);c.uniform4f(t.uniforms.mSpecular,g.r,g.g,g.b,o);c.uniform1f(t.uniforms.mShininess,f);c.uniform1i(t.uniforms.material,2)}else if(f instanceof THREE.MeshLambertMaterial)c.uniform1i(t.uniforms.material,1);else if(f instanceof
  159. THREE.MeshBasicMaterial)c.uniform1i(t.uniforms.material,0);else if(f instanceof THREE.MeshCubeMaterial){c.uniform1i(t.uniforms.material,5);L=f.env_map}if(s){i(s,0);c.uniform1i(t.uniforms.tMap,0);c.uniform1i(t.uniforms.enableMap,1)}else c.uniform1i(t.uniforms.enableMap,0);if(L){d(L,1);c.uniform1i(t.uniforms.tCube,1);c.uniform1i(t.uniforms.enableCubeMap,1)}else c.uniform1i(t.uniforms.enableCubeMap,0);c.bindBuffer(c.ARRAY_BUFFER,k.__webGLVertexBuffer);c.vertexAttribPointer(t.position,3,c.FLOAT,false,
  160. 0,0);c.bindBuffer(c.ARRAY_BUFFER,k.__webGLNormalBuffer);c.vertexAttribPointer(t.normal,3,c.FLOAT,false,0,0);if(s){c.bindBuffer(c.ARRAY_BUFFER,k.__webGLUVBuffer);c.enableVertexAttribArray(t.uv);c.vertexAttribPointer(t.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(t.uv);if(h){c.lineWidth(w);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,k.__webGLLineBuffer);c.drawElements(c.LINES,k.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,k.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,
  161. k.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(e,f,k,o,g){var h,w,s,L,u;s=0;for(L=f.material.length;s<L;s++){h=f.material[s];if(h instanceof THREE.MeshFaceMaterial){h=0;for(w=k.material.length;h<w;h++)if((u=k.material[h])&&u.blending==o&&u.opacity<1==g){this.setBlending(u.blending);this.renderBuffer(e,u,k)}}else if((u=h)&&u.blending==o&&u.opacity<1==g){this.setBlending(u.blending);this.renderBuffer(e,u,k)}}};this.render=function(e,f){var k,o,g,h;this.initWebGLObjects(e);this.autoClear&&
  162. this.clear();f.autoUpdateMatrix&&f.updateMatrix();this.loadCamera(z,f);this.setupLights(z,e);k=0;for(o=e.__webGLObjects.length;k<o;k++){g=e.__webGLObjects[k];h=g.object;g=g.buffer;if(h.visible){this.setupMatrices(h,f);this.loadMatrices(z);this.renderPass(f,h,g,THREE.NormalBlending,false)}}k=0;for(o=e.__webGLObjects.length;k<o;k++){g=e.__webGLObjects[k];h=g.object;g=g.buffer;if(h.visible){this.setupMatrices(h,f);this.loadMatrices(z);this.renderPass(f,h,g,THREE.AdditiveBlending,false);this.renderPass(f,
  163. h,g,THREE.SubtractiveBlending,false);this.renderPass(f,h,g,THREE.AdditiveBlending,true);this.renderPass(f,h,g,THREE.SubtractiveBlending,true);this.renderPass(f,h,g,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(e){var f,k,o,g,h,w;if(!e.__webGLObjects){e.__webGLObjects=[];e.__webGLObjectsMap={}}f=0;for(k=e.objects.length;f<k;f++){o=e.objects[f];if(e.__webGLObjectsMap[o.id]==undefined)e.__webGLObjectsMap[o.id]={};w=e.__webGLObjectsMap[o.id];if(o instanceof THREE.Mesh)for(h in o.geometry.geometryChunks){g=
  164. o.geometry.geometryChunks[h];g.__webGLVertexBuffer||this.createBuffers(o,h);if(w[h]==undefined){g={buffer:g,object:o};e.__webGLObjects.push(g);w[h]=1}}}};this.removeObject=function(e,f){var k,o;for(k=e.__webGLObjects.length-1;k>=0;k--){o=e.__webGLObjects[k].object;f==o&&e.__webGLObjects.splice(k,1)}};this.setupMatrices=function(e,f){e.autoUpdateMatrix&&e.updateMatrix();x.multiply(f.matrix,e.matrix);O.set(f.matrix.flatten());J.set(x.flatten());M.set(f.projectionMatrix.flatten());F=THREE.Matrix4.makeInvert3x3(x).transpose();
  165. n.set(F.m);S.set(e.matrix.flatten())};this.loadMatrices=function(e){c.uniformMatrix4fv(e.uniforms.viewMatrix,false,O);c.uniformMatrix4fv(e.uniforms.modelViewMatrix,false,J);c.uniformMatrix4fv(e.uniforms.projectionMatrix,false,M);c.uniformMatrix3fv(e.uniforms.normalMatrix,false,n);c.uniformMatrix4fv(e.uniforms.objectMatrix,false,S)};this.loadCamera=function(e,f){c.uniform3f(e.uniforms.cameraPosition,f.position.x,f.position.y,f.position.z)};this.setBlending=function(e){switch(e){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);
  166. 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(e,f){if(e){!f||f=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(e=="back")c.cullFace(c.BACK);else e=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)}};
  167. THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[];this.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null};
  168. THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=null};