ThreeDebug.js 76 KB

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