ThreeDebug.js 76 KB

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