Three.js 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // Three.js r29 - 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,f){this.r=a;this.g=c;this.b=f;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,f){this.x=a||0;this.y=c||0;this.z=f||0};
  7. THREE.Vector3.prototype={set:function(a,c,f){this.x=a;this.y=c;this.z=f;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,f=this.y,h=this.z;this.x=f*a.z-h*a.y;this.y=h*a.x-c*a.z;this.z=c*a.y-f*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){return Math.sqrt(this.distanceToSquared(a))},
  9. distanceToSquared:function(a){var c=this.x-a.x,f=this.y-a.y;a=this.z-a.z;return c*c+f*f+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(){this.length()>0?this.multiplyScalar(1/this.length()):this.multiplyScalar(0);return this},setLength:function(a){return this.normalize().multiplyScalar(a)},isZero:function(){return Math.abs(this.x)<
  10. 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,f,h){this.x=a||0;this.y=c||0;this.z=f||0;this.w=h||1};
  11. THREE.Vector4.prototype={set:function(a,c,f,h){this.x=a;this.y=c;this.z=f;this.w=h;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,f,h=a.objects,b=[];a=0;for(c=h.length;a<c;a++){f=h[a];if(f instanceof THREE.Mesh)b=b.concat(this.intersectObject(f))}b.sort(function(d,o){return d.distance-o.distance});return b},intersectObject:function(a){function c(y,A,M,s){s=s.clone().subSelf(A);M=M.clone().subSelf(A);var q=y.clone().subSelf(A);y=s.dot(s);A=s.dot(M);s=s.dot(q);var l=M.dot(M);M=M.dot(q);q=1/(y*l-A*A);l=(l*s-A*M)*q;y=(y*M-A*s)*q;return l>0&&y>0&&l+y<1}var f,h,b,d,o,r,n,e,g,k,
  15. j,p=a.geometry,i=p.vertices,C=[];f=0;for(h=p.faces.length;f<h;f++){b=p.faces[f];k=this.origin.clone();j=this.direction.clone();d=a.matrix.transform(i[b.a].position.clone());o=a.matrix.transform(i[b.b].position.clone());r=a.matrix.transform(i[b.c].position.clone());n=b instanceof THREE.Face4?a.matrix.transform(i[b.d].position.clone()):null;e=a.matrixRotation.transform(b.normal.clone());g=j.dot(e);if(g<0){e=e.dot((new THREE.Vector3).sub(d,k))/g;k=k.addSelf(j.multiplyScalar(e));if(b instanceof THREE.Face3){if(c(k,
  16. d,o,r)){b={distance:this.origin.distanceTo(k),point:k,face:b,object:a};C.push(b)}}else if(b instanceof THREE.Face4)if(c(k,d,o,n)||c(k,o,r,n)){b={distance:this.origin.distanceTo(k),point:k,face:b,object:a};C.push(b)}}}return C}};
  17. THREE.Rectangle=function(){function a(){d=h-c;o=b-f}var c,f,h,b,d,o,r=true;this.getX=function(){return c};this.getY=function(){return f};this.getWidth=function(){return d};this.getHeight=function(){return o};this.getLeft=function(){return c};this.getTop=function(){return f};this.getRight=function(){return h};this.getBottom=function(){return b};this.set=function(n,e,g,k){r=false;c=n;f=e;h=g;b=k;a()};this.addPoint=function(n,e){if(r){r=false;c=n;f=e;h=n;b=e}else{c=Math.min(c,n);f=Math.min(f,e);h=Math.max(h,
  18. n);b=Math.max(b,e)}a()};this.addRectangle=function(n){if(r){r=false;c=n.getLeft();f=n.getTop();h=n.getRight();b=n.getBottom()}else{c=Math.min(c,n.getLeft());f=Math.min(f,n.getTop());h=Math.max(h,n.getRight());b=Math.max(b,n.getBottom())}a()};this.inflate=function(n){c-=n;f-=n;h+=n;b+=n;a()};this.minSelf=function(n){c=Math.max(c,n.getLeft());f=Math.max(f,n.getTop());h=Math.min(h,n.getRight());b=Math.min(b,n.getBottom());a()};this.instersects=function(n){return Math.min(h,n.getRight())-Math.max(c,n.getLeft())>=
  19. 0&&Math.min(b,n.getBottom())-Math.max(f,n.getTop())>=0};this.empty=function(){r=true;b=h=f=c=0;a()};this.isEmpty=function(){return r};this.toString=function(){return"THREE.Rectangle ( left: "+c+", right: "+h+", top: "+f+", bottom: "+b+", width: "+d+", height: "+o+" )"}};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(){this._x=new THREE.Vector3;this._y=new THREE.Vector3;this._z=new THREE.Vector3};
  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,f){var h=this._x,b=this._y,d=this._z;d.sub(a,c);d.normalize();h.cross(f,d);h.normalize();b.cross(d,h);b.normalize();this.n11=h.x;this.n12=h.y;this.n13=h.z;this.n14=-h.dot(a);this.n21=b.x;this.n22=b.y;this.n23=b.z;this.n24=-b.dot(a);this.n31=d.x;this.n32=d.y;this.n33=d.z;this.n34=-d.dot(a);this.n43=this.n42=this.n41=0;this.n44=1},transform:function(a){var c=a.x,f=a.y,h=a.z,b=a.w?a.w:1;a.x=this.n11*c+this.n12*f+this.n13*h+this.n14*
  23. b;a.y=this.n21*c+this.n22*f+this.n23*h+this.n24*b;a.z=this.n31*c+this.n32*f+this.n33*h+this.n34*b;b=this.n41*c+this.n42*f+this.n43*h+this.n44*b;if(a.w)a.w=b;else{a.x/=b;a.y/=b;a.z/=b}return a},crossVector:function(a){var c=new THREE.Vector4;c.x=this.n11*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,
  24. c){this.n11=a.n11*c.n11+a.n12*c.n21+a.n13*c.n31+a.n14*c.n41;this.n12=a.n11*c.n12+a.n12*c.n22+a.n13*c.n32+a.n14*c.n42;this.n13=a.n11*c.n13+a.n12*c.n23+a.n13*c.n33+a.n14*c.n43;this.n14=a.n11*c.n14+a.n12*c.n24+a.n13*c.n34+a.n14*c.n44;this.n21=a.n21*c.n11+a.n22*c.n21+a.n23*c.n31+a.n24*c.n41;this.n22=a.n21*c.n12+a.n22*c.n22+a.n23*c.n32+a.n24*c.n42;this.n23=a.n21*c.n13+a.n22*c.n23+a.n23*c.n33+a.n24*c.n43;this.n24=a.n21*c.n14+a.n22*c.n24+a.n23*c.n34+a.n24*c.n44;this.n31=a.n31*c.n11+a.n32*c.n21+a.n33*c.n31+
  25. a.n34*c.n41;this.n32=a.n31*c.n12+a.n32*c.n22+a.n33*c.n32+a.n34*c.n42;this.n33=a.n31*c.n13+a.n32*c.n23+a.n33*c.n33+a.n34*c.n43;this.n34=a.n31*c.n14+a.n32*c.n24+a.n33*c.n34+a.n34*c.n44;this.n41=a.n41*c.n11+a.n42*c.n21+a.n43*c.n31+a.n44*c.n41;this.n42=a.n41*c.n12+a.n42*c.n22+a.n43*c.n32+a.n44*c.n42;this.n43=a.n41*c.n13+a.n42*c.n23+a.n43*c.n33+a.n44*c.n43;this.n44=a.n41*c.n14+a.n42*c.n24+a.n43*c.n34+a.n44*c.n44},multiplySelf:function(a){var c=this.n11,f=this.n12,h=this.n13,b=this.n14,d=this.n21,o=this.n22,
  26. r=this.n23,n=this.n24,e=this.n31,g=this.n32,k=this.n33,j=this.n34,p=this.n41,i=this.n42,C=this.n43,y=this.n44;this.n11=c*a.n11+f*a.n21+h*a.n31+b*a.n41;this.n12=c*a.n12+f*a.n22+h*a.n32+b*a.n42;this.n13=c*a.n13+f*a.n23+h*a.n33+b*a.n43;this.n14=c*a.n14+f*a.n24+h*a.n34+b*a.n44;this.n21=d*a.n11+o*a.n21+r*a.n31+n*a.n41;this.n22=d*a.n12+o*a.n22+r*a.n32+n*a.n42;this.n23=d*a.n13+o*a.n23+r*a.n33+n*a.n43;this.n24=d*a.n14+o*a.n24+r*a.n34+n*a.n44;this.n31=e*a.n11+g*a.n21+k*a.n31+j*a.n41;this.n32=e*a.n12+g*a.n22+
  27. k*a.n32+j*a.n42;this.n33=e*a.n13+g*a.n23+k*a.n33+j*a.n43;this.n34=e*a.n14+g*a.n24+k*a.n34+j*a.n44;this.n41=p*a.n11+i*a.n21+C*a.n31+y*a.n41;this.n42=p*a.n12+i*a.n22+C*a.n32+y*a.n42;this.n43=p*a.n13+i*a.n23+C*a.n33+y*a.n43;this.n44=p*a.n14+i*a.n24+C*a.n34+y*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,f,h){var b=c[f];c[f]=c[h];c[h]=b}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,f){var h=new THREE.Matrix4;h.n14=a;h.n24=c;h.n34=f;return h};THREE.Matrix4.scaleMatrix=function(a,c,f){var h=new THREE.Matrix4;h.n11=a;h.n22=c;h.n33=f;return h};
  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 f=new THREE.Matrix4,h=Math.cos(c),b=Math.sin(c),d=1-h,o=a.x,r=a.y,n=a.z;f.n11=d*o*o+h;f.n12=d*o*r-b*n;f.n13=d*o*n+b*r;f.n21=d*o*r+b*n;f.n22=d*r*r+h;f.n23=d*r*n-b*o;f.n31=d*o*n-b*r;f.n32=d*r*n+b*o;f.n33=d*n*n+h;return f};
  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 f=c[10]*c[5]-c[6]*c[9],h=-c[10]*c[1]+c[2]*c[9],b=c[6]*c[1]-c[2]*c[5],d=-c[10]*c[4]+c[6]*c[8],o=c[10]*c[0]-c[2]*c[8],r=-c[6]*c[0]+c[2]*c[4],n=c[9]*c[4]-c[5]*c[8],e=-c[9]*c[0]+c[1]*c[8],g=c[5]*c[0]-c[1]*c[4];c=c[0]*f+c[1]*d+c[2]*n;if(c==0)throw"matrix not invertible";c=1/c;a.m[0]=c*f;a.m[1]=c*h;a.m[2]=c*b;a.m[3]=c*d;a.m[4]=c*o;a.m[5]=c*r;a.m[6]=c*n;a.m[7]=c*e;a.m[8]=c*g;return a};
  39. THREE.Matrix4.makeFrustum=function(a,c,f,h,b,d){var o,r,n;o=new THREE.Matrix4;r=2*b/(c-a);n=2*b/(h-f);a=(c+a)/(c-a);f=(h+f)/(h-f);h=-(d+b)/(d-b);b=-2*d*b/(d-b);o.n11=r;o.n12=0;o.n13=a;o.n14=0;o.n21=0;o.n22=n;o.n23=f;o.n24=0;o.n31=0;o.n32=0;o.n33=h;o.n34=b;o.n41=0;o.n42=0;o.n43=-1;o.n44=0;return o};THREE.Matrix4.makePerspective=function(a,c,f,h){var b;a=f*Math.tan(a*Math.PI/360);b=-a;return THREE.Matrix4.makeFrustum(b*c,a*c,b,a,f,h)};
  40. THREE.Matrix4.makeOrtho=function(a,c,f,h,b,d){var o,r,n,e;o=new THREE.Matrix4;r=c-a;n=f-h;e=d-b;a=(c+a)/r;f=(f+h)/n;b=(d+b)/e;o.n11=2/r;o.n12=0;o.n13=0;o.n14=-a;o.n21=0;o.n22=2/n;o.n23=0;o.n24=-f;o.n31=0;o.n32=0;o.n33=-2/e;o.n34=-b;o.n41=0;o.n42=0;o.n43=0;o.n44=1;return o};
  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,f,h,b){this.a=a;this.b=c;this.c=f;this.centroid=new THREE.Vector3;this.normal=h instanceof THREE.Vector3?h:new THREE.Vector3;this.vertexNormals=h instanceof Array?h:[];this.material=b instanceof Array?b:[b]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
  43. THREE.Face4=function(a,c,f,h,b,d){this.a=a;this.b=c;this.c=f;this.d=h;this.centroid=new THREE.Vector3;this.normal=b instanceof THREE.Vector3?b:new THREE.Vector3;this.vertexNormals=b instanceof Array?b:[];this.material=d instanceof Array?d:[d]};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,f;a=0;for(c=this.faces.length;a<c;a++){f=this.faces[a];f.centroid.set(0,0,0);if(f instanceof THREE.Face3){f.centroid.addSelf(this.vertices[f.a].position);f.centroid.addSelf(this.vertices[f.b].position);f.centroid.addSelf(this.vertices[f.c].position);f.centroid.divideScalar(3)}else if(f instanceof THREE.Face4){f.centroid.addSelf(this.vertices[f.a].position);f.centroid.addSelf(this.vertices[f.b].position);f.centroid.addSelf(this.vertices[f.c].position);
  46. f.centroid.addSelf(this.vertices[f.d].position);f.centroid.divideScalar(4)}}},computeNormals:function(a){var c,f,h,b,d,o,r=new THREE.Vector3,n=new THREE.Vector3;h=0;for(b=this.vertices.length;h<b;h++){d=this.vertices[h];d.normal.set(0,0,0)}h=0;for(b=this.faces.length;h<b;h++){d=this.faces[h];if(a&&d.vertexNormals.length){r.set(0,0,0);c=0;for(f=d.normal.length;c<f;c++)r.addSelf(d.vertexNormals[c]);r.divideScalar(3)}else{c=this.vertices[d.a];f=this.vertices[d.b];o=this.vertices[d.c];r.sub(o.position,
  47. f.position);n.sub(c.position,f.position);r.crossSelf(n)}r.isZero()||r.normalize();d.normal.copy(r)}},computeBoundingBox:function(){if(this.vertices.length>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>
  48. 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>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,f,h){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,f,h);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+" )"}};
  50. THREE.Light=function(a){this.color=new THREE.Color(-16777216|a)};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(0,0,0);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.matrixTranslation=new THREE.Matrix4;this.matrixRotation=new THREE.Matrix4;this.matrixScale=new THREE.Matrix4;this.screen=new THREE.Vector3;this.autoUpdateMatrix=true;this.updateMatrix=function(){this.matrixPosition=THREE.Matrix4.translationMatrix(this.position.x,this.position.y,this.position.z);this.matrixRotation=THREE.Matrix4.rotationXMatrix(this.rotation.x);
  53. this.matrixRotation.multiplySelf(THREE.Matrix4.rotationYMatrix(this.rotation.y));this.matrixRotation.multiplySelf(THREE.Matrix4.rotationZMatrix(this.rotation.z));this.matrixScale=THREE.Matrix4.scaleMatrix(this.scale.x,this.scale.y,this.scale.z);this.matrix.copy(this.matrixPosition);this.matrix.multiplySelf(this.matrixRotation);this.matrix.multiplySelf(this.matrixScale)}};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,f){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();f&&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(g){var k=[];c=0;for(f=g.length;c<f;c++)g[c]==undefined?k.push("undefined"):k.push(g[c].toString());return k.join("_")}var c,f,h,b,d,o,r,n,e={};h=0;for(b=this.geometry.faces.length;h<b;h++){d=this.geometry.faces[h];o=d.material;r=a(o);if(e[r]==undefined)e[r]={hash:r,counter:0};n=e[r].hash+"_"+e[r].counter;if(this.materialFaceGroup[n]==undefined)this.materialFaceGroup[n]={faces:[],material:o,vertices:0};d=d instanceof THREE.Face3?3:4;if(this.materialFaceGroup[n].vertices+
  57. d>65535){e[r].counter+=1;n=e[r].hash+"_"+e[r].counter;if(this.materialFaceGroup[n]==undefined)this.materialFaceGroup[n]={faces:[],material:o,vertices:0}}this.materialFaceGroup[n].faces.push(h);this.materialFaceGroup[n].vertices+=d}};THREE.Mesh.prototype.normalizeUVs=function(){var a,c,f,h,b;a=0;for(c=this.geometry.uvs.length;a<c;a++){b=this.geometry.uvs[a];f=0;for(h=b.length;f<h;f++){if(b[f].u!=1)b[f].u-=Math.floor(b[f].u);if(b[f].v!=1)b[f].v-=Math.floor(b[f].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;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}this.toString=function(){return"THREE.LineBasicMaterial (<br/>color: "+this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>linewidth: "+
  60. this.linewidth+"<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;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.map!==undefined)this.map=a.map;if(a.env_map!==undefined)this.env_map=a.env_map;if(a.combine!==
  62. 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}this.toString=function(){return"THREE.MeshBasicMaterial (<br/>id: "+
  63. this.id+"<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>env_map: "+this.env_map+"<br/>combine: "+this.combine+"<br/>reflectivity: "+this.reflectivity+"<br/>refraction_ratio: "+this.refraction_ratio+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>wireframe: "+this.wireframe+"<br/>wireframe_linewidth: "+this.wireframe_linewidth+"<br/>)"}};THREE.MeshBasicMaterialCounter={value:0};
  64. 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;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.map!==undefined)this.map=a.map;if(a.env_map!==undefined)this.env_map=a.env_map;if(a.combine!==
  65. 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}this.toString=function(){return"THREE.MeshLambertMaterial (<br/>id: "+
  66. this.id+"<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>env_map: "+this.env_map+"<br/>combine: "+this.combine+"<br/>reflectivity: "+this.reflectivity+"<br/>refraction_ratio: "+this.refraction_ratio+"<br/>opacity: "+this.opacity+"<br/>shading: "+this.shading+"<br/>blending: "+this.blending+"<br/>wireframe: "+this.wireframe+"<br/>wireframe_size: "+this.wireframe_linewidth+"<br/> )"}};THREE.MeshLambertMaterialCounter={value:0};
  67. 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;if(a){if(a.color!==undefined)this.color=
  68. 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=a.reflectivity;if(a.refraction_ratio!==undefined)this.refraction_ratio=
  69. 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}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+
  70. "<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: "+this.wireframe+"<br/>wireframe_linewidth: "+this.wireframe_linewidth+"<br/>"+ +")"}};THREE.MeshPhongMaterialCounter={value:0};
  71. 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"}};
  72. 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"}};
  73. 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};
  74. 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: "+
  75. 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/>)"}};
  76. THREE.ParticleDOMMaterial=function(a){this.domElement=a;this.toString=function(){return"THREE.ParticleDOMMaterial ( domElement: "+this.domElement+" )"}};THREE.Texture=function(a,c,f,h){this.image=a;this.mapping=c!==undefined?c:THREE.UVMapping;this.wrap_s=f!==undefined?f:THREE.ClampToEdge;this.wrap_t=h!==undefined?h: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/>)"}};THREE.UVMapping=0;
  77. THREE.ReflectionMap=1;THREE.RefractionMap=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/>)"}};
  78. 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+" )"}};
  79. THREE.Projector=function(){function a(s,q){var l=0,S=1,H=s.z+s.w,T=q.z+q.w,Y=-s.z+s.w,t=-q.z+q.w;if(H>=0&&T>=0&&Y>=0&&t>=0)return true;else if(H<0&&T<0||Y<0&&t<0)return false;else{if(H<0)l=Math.max(l,H/(H-T));else if(T<0)S=Math.min(S,H/(H-T));if(Y<0)l=Math.max(l,Y/(Y-t));else if(t<0)S=Math.min(S,Y/(Y-t));if(S<l)return false;else{s.lerpSelf(q,l);q.lerpSelf(s,1-S);return true}}}var c=null,f,h,b=[],d,o,r=[],n,e,g=[],k,j,p=[],i=new THREE.Vector4,C=new THREE.Matrix4,y=new THREE.Matrix4,A=new THREE.Vector4,
  80. M=new THREE.Vector4;this.projectScene=function(s,q){var l,S,H,T,Y,t,F,w,D,P,fa,B,L,K;c=[];j=e=o=h=0;q.autoUpdateMatrix&&q.updateMatrix();C.multiply(q.projectionMatrix,q.matrix);Y=s.objects;l=0;for(S=Y.length;l<S;l++){t=Y[l];F=t.matrix;t.autoUpdateMatrix&&t.updateMatrix();if(t instanceof THREE.Mesh){y.multiply(C,F);w=t.geometry.vertices;H=0;for(T=w.length;H<T;H++){D=w[H];P=D.positionScreen;P.copy(D.position);y.transform(P);P.multiplyScalar(1/P.w);D.__visible=P.z>0&&P.z<1}fa=t.geometry.faces;H=0;for(T=
  81. fa.length;H<T;H++){B=fa[H];if(B instanceof THREE.Face3){D=w[B.a];P=w[B.b];L=w[B.c];if(D.__visible&&P.__visible&&L.__visible)if(t.doubleSided||t.flipSided!=(L.positionScreen.x-D.positionScreen.x)*(P.positionScreen.y-D.positionScreen.y)-(L.positionScreen.y-D.positionScreen.y)*(P.positionScreen.x-D.positionScreen.x)<0){f=b[h]=b[h]||new THREE.RenderableFace3;f.v1.positionScreen.copy(D.positionScreen);f.v2.positionScreen.copy(P.positionScreen);f.v3.positionScreen.copy(L.positionScreen);f.normalWorld.copy(B.normal);
  82. t.matrixRotation.transform(f.normalWorld);f.centroidWorld.copy(B.centroid);F.transform(f.centroidWorld);f.centroidScreen.copy(f.centroidWorld);C.transform(f.centroidScreen);f.z=f.centroidScreen.z;f.meshMaterial=t.material;f.faceMaterial=B.material;f.overdraw=t.overdraw;f.uvs=t.geometry.uvs[H];f.color=B.color;c.push(f);h++}}else if(B instanceof THREE.Face4){D=w[B.a];P=w[B.b];L=w[B.c];K=w[B.d];if(D.__visible&&P.__visible&&L.__visible&&K.__visible)if(t.doubleSided||t.flipSided!=((K.positionScreen.x-
  83. D.positionScreen.x)*(P.positionScreen.y-D.positionScreen.y)-(K.positionScreen.y-D.positionScreen.y)*(P.positionScreen.x-D.positionScreen.x)<0||(P.positionScreen.x-L.positionScreen.x)*(K.positionScreen.y-L.positionScreen.y)-(P.positionScreen.y-L.positionScreen.y)*(K.positionScreen.x-L.positionScreen.x)<0)){d=r[o]=r[o]||new THREE.RenderableFace4;d.v1.positionScreen.copy(D.positionScreen);d.v2.positionScreen.copy(P.positionScreen);d.v3.positionScreen.copy(L.positionScreen);d.v4.positionScreen.copy(K.positionScreen);
  84. d.normalWorld.copy(B.normal);t.matrixRotation.transform(d.normalWorld);d.centroidWorld.copy(B.centroid);F.transform(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);C.transform(d.centroidScreen);d.z=d.centroidScreen.z;d.meshMaterial=t.material;d.faceMaterial=B.material;d.overdraw=t.overdraw;d.uvs=t.geometry.uvs[H];d.color=B.color;c.push(d);o++}}}}else if(t instanceof THREE.Line){y.multiply(C,F);w=t.geometry.vertices;D=w[0];D.positionScreen.copy(D.position);y.transform(D.positionScreen);H=1;
  85. for(T=w.length;H<T;H++){D=w[H];D.positionScreen.copy(D.position);y.transform(D.positionScreen);P=w[H-1];A.copy(D.positionScreen);M.copy(P.positionScreen);if(a(A,M)){A.multiplyScalar(1/A.w);M.multiplyScalar(1/M.w);n=g[e]=g[e]||new THREE.RenderableLine;n.v1.positionScreen.copy(A);n.v2.positionScreen.copy(M);n.z=Math.max(A.z,M.z);n.material=t.material;c.push(n);e++}}}else if(t instanceof THREE.Particle){i.set(t.position.x,t.position.y,t.position.z,1);C.transform(i);i.z/=i.w;if(i.z>0&&i.z<1){k=p[j]=p[j]||
  86. new THREE.RenderableParticle;k.x=i.x/i.w;k.y=i.y/i.w;k.z=i.z;k.rotation=t.rotation.z;k.scale.x=t.scale.x*Math.abs(k.x-(i.x+q.projectionMatrix.n11)/(i.w+q.projectionMatrix.n14));k.scale.y=t.scale.y*Math.abs(k.y-(i.y+q.projectionMatrix.n22)/(i.w+q.projectionMatrix.n24));k.material=t.material;c.push(k);j++}}}c.sort(function(R,x){return x.z-R.z});return c};this.unprojectVector=function(s,q){var l=new THREE.Matrix4;l.multiply(THREE.Matrix4.makeInvert(q.matrix),THREE.Matrix4.makeInvert(q.projectionMatrix));
  87. l.transform(s);return s}};
  88. THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,c=new THREE.Projector,f,h,b,d;this.domElement=document.createElement("div");this.setSize=function(o,r){f=o;h=r;b=f/2;d=h/2};this.render=function(o,r){var n,e,g,k,j,p,i,C;a=c.projectScene(o,r);n=0;for(e=a.length;n<e;n++){j=a[n];if(j instanceof THREE.RenderableParticle){i=j.x*b+b;C=j.y*d+d;g=0;for(k=j.material.length;g<k;g++){p=j.material[g];if(p instanceof THREE.ParticleDOMMaterial){p=p.domElement;p.style.left=i+"px";p.style.top=C+"px"}}}}}};
  89. THREE.CanvasRenderer=function(){function a(v,N,I){var J,m,G;lights=v.lights;v=0;for(J=lights.length;v<J;v++){m=lights[v];G=m.color;if(m instanceof THREE.DirectionalLight){m=N.normalWorld.dot(m.position)*m.intensity;if(m>0){I.r+=G.r*m;I.g+=G.g*m;I.b+=G.b*m}}else if(m instanceof THREE.PointLight){Ja.sub(m.position,N.centroidWorld);Ja.normalize();m=N.normalWorld.dot(Ja)*m.intensity;if(m>0){I.r+=G.r*m;I.g+=G.g*m;I.b+=G.b*m}}}}function c(v,N,I,J,m,G){if(m.opacity!=0){o(m.opacity);r(m.blending);L=v.positionScreen.x;
  90. K=v.positionScreen.y;R=N.positionScreen.x;x=N.positionScreen.y;u=I.positionScreen.x;Q=I.positionScreen.y;if(m.map){ea=m.map.image;na=ea.width-1;oa=ea.height-1;ca.u=J.uvs[0].u*na;ca.v=J.uvs[0].v*oa;Z.u=J.uvs[1].u*na;Z.v=J.uvs[1].v*oa;da.u=J.uvs[2].u*na;da.v=J.uvs[2].v*oa;d(ea,L,K,R,x,u,Q,ca.u,ca.v,Z.u,Z.v,da.u,da.v)}else if(m instanceof THREE.MeshBasicMaterial)h(L,K,R,x,u,Q,m.color,m.wireframe,m.wireframe_linewidth);else if(m instanceof THREE.MeshLambertMaterial){if(Fa){aa.r=ga.r;aa.g=ga.g;aa.b=ga.b;
  91. a(G,J,aa);U.r=m.color.r*aa.r;U.g=m.color.g*aa.g;U.b=m.color.b*aa.b;U.updateStyleString()}else U.__styleString=m.color.__styleString;h(L,K,R,x,u,Q,U,m.wireframe,m.wireframe_linewidth)}else if(m instanceof THREE.MeshDepthMaterial){pa=m.__2near;qa=m.__farPlusNear;ra=m.__farMinusNear;va=~~((1-pa/(qa-v.positionScreen.z*ra))*255);wa=~~((1-pa/(qa-N.positionScreen.z*ra))*255);ma=~~((1-pa/(qa-I.positionScreen.z*ra))*255);ea=k([va,va,va],[wa,wa,wa],[ma,ma,ma],[ma,ma,ma]);ca.u=0;ca.v=0;Z.u=ka;Z.v=0;da.u=0;da.v=
  92. ka;d(ea,L,K,R,x,u,Q,ca.u,ca.v,Z.u,Z.v,da.u,da.v)}else if(m instanceof THREE.MeshNormalMaterial){U.r=j(J.normalWorld.x);U.g=j(J.normalWorld.y);U.b=j(J.normalWorld.z);U.updateStyleString();h(L,K,R,x,u,Q,U,m.wireframe,m.wireframe_linewidth)}}}function f(v,N,I,J,m,G,V,z,W){if(z.opacity!=0){o(z.opacity);r(z.blending);L=v.positionScreen.x;K=v.positionScreen.y;R=N.positionScreen.x;x=N.positionScreen.y;u=I.positionScreen.x;Q=I.positionScreen.y;ha=J.positionScreen.x;O=J.positionScreen.y;X=m.positionScreen.x;
  93. xa=m.positionScreen.y;Ka=G.positionScreen.x;La=G.positionScreen.y;if(z.map){ea=z.map.image;na=ea.width-1;oa=ea.height-1;ca.copy(V.uvs[0]);Z.copy(V.uvs[1]);da.copy(V.uvs[2]);ia.copy(V.uvs[3]);ca.u*=na;ca.v*=oa;Z.u*=na;Z.v*=oa;da.u*=na;da.v*=oa;ia.u*=na;ia.v*=oa;d(ea,L,K,R,x,ha,O,ca.u,ca.v,Z.u,Z.v,ia.u,ia.v);d(ea,X,xa,u,Q,Ka,La,Z.u,Z.v,da.u,da.v,ia.u,ia.v)}else if(z instanceof THREE.MeshBasicMaterial)b(L,K,R,x,u,Q,ha,O,z.color,z.wireframe,z.wireframe_linewidth);else if(z instanceof THREE.MeshLambertMaterial){if(Fa){aa.r=
  94. ga.r;aa.g=ga.g;aa.b=ga.b;a(W,V,aa);U.r=z.color.r*aa.r;U.g=z.color.g*aa.g;U.b=z.color.b*aa.b;U.updateStyleString()}else U.__styleString=z.color.__styleString;b(L,K,R,x,u,Q,ha,O,U,z.wireframe,z.wireframe_linewidth)}else if(z instanceof THREE.MeshDepthMaterial){pa=z.__2near;qa=z.__farPlusNear;ra=z.__farMinusNear;va=~~((1-pa/(qa-v.positionScreen.z*ra))*255);wa=~~((1-pa/(qa-N.positionScreen.z*ra))*255);ma=~~((1-pa/(qa-I.positionScreen.z*ra))*255);Ga=~~((1-pa/(qa-J.positionScreen.z*ra))*255);ea=k([va,va,
  95. va],[wa,wa,wa],[Ga,Ga,Ga],[ma,ma,ma]);ca.u=0;ca.v=0;Z.u=ka;Z.v=0;da.u=ka;da.v=ka;ia.u=0;ia.v=ka;d(ea,L,K,R,x,ha,O,ca.u,ca.v,Z.u,Z.v,ia.u,ia.v);d(ea,X,xa,u,Q,Ka,La,Z.u,Z.v,da.u,da.v,ia.u,ia.v)}else if(z instanceof THREE.MeshNormalMaterial){U.r=j(V.normalWorld.x);U.g=j(V.normalWorld.y);U.b=j(V.normalWorld.z);U.updateStyleString();b(L,K,R,x,u,Q,ha,O,U,z.wireframe,z.wireframe_linewidth)}}}function h(v,N,I,J,m,G,V,z,W){l.beginPath();l.moveTo(v,N);l.lineTo(I,J);l.lineTo(m,G);l.lineTo(v,N);l.closePath();
  96. if(z){n(W);e(V.__styleString);l.stroke();$.inflate(W*2)}else{g(V.__styleString);l.fill()}}function b(v,N,I,J,m,G,V,z,W,E,ba){l.beginPath();l.moveTo(v,N);l.lineTo(I,J);l.lineTo(m,G);l.lineTo(V,z);l.lineTo(v,N);l.closePath();if(E){n(ba);e(W.__styleString);l.stroke();$.inflate(ba*2)}else{g(W.__styleString);l.fill()}}function d(v,N,I,J,m,G,V,z,W,E,ba,la,sa){l.beginPath();l.moveTo(N,I);l.lineTo(J,m);l.lineTo(G,V);l.closePath();J-=N;m-=I;G-=N;V-=I;E-=z;ba-=W;la-=z;sa-=W;var ta=1/(E*sa-la*ba),Ba=(sa*J-ba*
  97. G)*ta;ba=(sa*m-ba*V)*ta;J=(E*G-la*J)*ta;m=(E*V-la*m)*ta;N=N-Ba*z-J*W;I=I-ba*z-m*W;l.save();l.transform(Ba,ba,J,m,N,I);l.clip();l.drawImage(v,0,0);l.restore()}function o(v){if(S!=v)l.globalAlpha=S=v}function r(v){if(H!=v){switch(v){case THREE.NormalBlending:l.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:l.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:l.globalCompositeOperation="darker"}H=v}}function n(v){if(t!=v)l.lineWidth=t=v}function e(v){if(T!=
  98. v)l.strokeStyle=T=v}function g(v){if(Y!=v)l.fillStyle=Y=v}function k(v,N,I,J){ja[0]=v[0];ja[1]=v[1];ja[2]=v[2];ja[4]=N[0];ja[5]=N[1];ja[6]=N[2];ja[8]=I[0];ja[9]=I[1];ja[10]=I[2];ja[12]=J[0];ja[13]=J[1];ja[14]=J[2];Ca.putImageData(Ma,0,0);Ha.drawImage(Da,0,0);return Ea}function j(v){return v<0?Math.min((1+v)*0.5,0.5):0.5+Math.min(v*0.5,0.5)}function p(v,N){var I=N.x-v.x,J=N.y-v.y,m=1/Math.sqrt(I*I+J*J);I*=m;J*=m;N.x+=I;N.y+=J;v.x-=I;v.y-=J}var i=null,C=new THREE.Projector,y=document.createElement("canvas"),
  99. A,M,s,q,l=y.getContext("2d"),S=1,H=0,T=null,Y=null,t=1,F,w,D,P,fa=new THREE.Vertex,B=new THREE.Vertex,L,K,R,x,u,Q,ha,O,X,xa,Ka,La,va,wa,ma,Ga,pa,qa,ra,ea,na,oa,ya=new THREE.Rectangle,ua=new THREE.Rectangle,$=new THREE.Rectangle,Fa=false,U=new THREE.Color(16777215),aa=new THREE.Color(16777215),ga=new THREE.Color(0),za=new THREE.Color(0),Aa=new THREE.Color(0),Qa=Math.PI*2,Ja=new THREE.Vector3,ca=new THREE.UV,Z=new THREE.UV,da=new THREE.UV,ia=new THREE.UV,Da,Ca,Ma,ja,Ea,Ha,ka=16;Da=document.createElement("canvas");
  100. Da.width=Da.height=2;Ca=Da.getContext("2d");Ca.fillStyle="rgba(0,0,0,1)";Ca.fillRect(0,0,2,2);Ma=Ca.getImageData(0,0,2,2);ja=Ma.data;Ea=document.createElement("canvas");Ea.width=Ea.height=ka;Ha=Ea.getContext("2d");Ha.translate(-ka/2,-ka/2);Ha.scale(ka,ka);ka--;this.domElement=y;this.autoClear=true;this.setSize=function(v,N){A=v;M=N;s=A/2;q=M/2;y.width=A;y.height=M;l.lineJoin="round";l.lineCap="round";ya.set(-s,-q,s,q)};this.clear=function(){if(!ua.isEmpty()){ua.inflate(1);ua.minSelf(ya);l.setTransform(1,
  101. 0,0,-1,s,q);l.clearRect(ua.getX(),ua.getY(),ua.getWidth(),ua.getHeight());ua.empty()}};this.render=function(v,N){var I,J,m,G,V,z,W,E;this.autoClear&&this.clear();i=C.projectScene(v,N);l.setTransform(1,0,0,-1,s,q);if(Fa=v.lights.length>0){V=v.lights;ga.setRGB(0,0,0);za.setRGB(0,0,0);Aa.setRGB(0,0,0);I=0;for(J=V.length;I<J;I++){m=V[I];G=m.color;if(m instanceof THREE.AmbientLight){ga.r+=G.r;ga.g+=G.g;ga.b+=G.b}else if(m instanceof THREE.DirectionalLight){za.r+=G.r;za.g+=G.g;za.b+=G.b}else if(m instanceof
  102. THREE.PointLight){Aa.r+=G.r;Aa.g+=G.g;Aa.b+=G.b}}}I=0;for(J=i.length;I<J;I++){m=i[I];$.empty();if(m instanceof THREE.RenderableParticle){F=m;F.x*=s;F.y*=q;G=0;for(V=m.material.length;G<V;G++)if(E=m.material[G]){z=F;W=m;E=E;if(E.opacity!=0){o(E.opacity);r(E.blending);var ba=void 0,la=void 0,sa=void 0,ta=void 0,Ba=void 0,Na=void 0,Ia=void 0,Oa=void 0,Pa=void 0;if(E instanceof THREE.ParticleBasicMaterial){Ia=E.bitmap;Oa=Ia.width/2;Pa=Ia.height/2;sa=W.scale.x*s;ta=W.scale.y*q;ba=sa*Oa;la=ta*Pa;Ba=E.offset.x*
  103. sa;Na=E.offset.y*ta;$.set(z.x+Ba-ba,z.y+Na-la,z.x+Ba+ba,z.y+Na+la);if(ya.instersects($)){l.save();l.translate(z.x,z.y);l.rotate(-W.rotation);l.scale(sa,-ta);l.translate(-Oa+E.offset.x,-Pa-E.offset.y);l.drawImage(Ia,0,0);l.restore()}}else if(E instanceof THREE.ParticleCircleMaterial){if(Fa){aa.r=ga.r+za.r+Aa.r;aa.g=ga.g+za.g+Aa.g;aa.b=ga.b+za.b+Aa.b;U.r=E.color.r*aa.r;U.g=E.color.g*aa.g;U.b=E.color.b*aa.b;U.updateStyleString()}else U.__styleString=E.color.__styleString;ba=W.scale.x*s;la=W.scale.y*
  104. q;$.set(z.x-ba,z.y-la,z.x+ba,z.y+la);if(ya.instersects($)){g(U.__styleString);l.save();l.translate(z.x,z.y);l.rotate(-W.rotation);l.scale(ba,la);l.beginPath();l.arc(0,0,1,0,Qa,true);l.closePath();l.fill();l.restore()}}}}}else if(m instanceof THREE.RenderableLine){F=m.v1;w=m.v2;F.positionScreen.x*=s;F.positionScreen.y*=q;w.positionScreen.x*=s;w.positionScreen.y*=q;$.addPoint(F.positionScreen.x,F.positionScreen.y);$.addPoint(w.positionScreen.x,w.positionScreen.y);if(!ya.instersects($))continue;G=0;
  105. for(V=m.material.length;G<V;)if(E=m.material[G++]){z=F;W=w;E=E;if(E.opacity!=0){o(E.opacity);r(E.blending);l.beginPath();l.moveTo(z.positionScreen.x,z.positionScreen.y);l.lineTo(W.positionScreen.x,W.positionScreen.y);l.closePath();if(E instanceof THREE.LineBasicMaterial){U.__styleString=E.color.__styleString;n(E.linewidth);e(U.__styleString);l.stroke();$.inflate(E.linewidth*2)}}}}else if(m instanceof THREE.RenderableFace3){F=m.v1;w=m.v2;D=m.v3;F.positionScreen.x*=s;F.positionScreen.y*=q;w.positionScreen.x*=
  106. s;w.positionScreen.y*=q;D.positionScreen.x*=s;D.positionScreen.y*=q;if(m.overdraw){p(F.positionScreen,w.positionScreen);p(w.positionScreen,D.positionScreen);p(D.positionScreen,F.positionScreen)}$.addPoint(F.positionScreen.x,F.positionScreen.y);$.addPoint(w.positionScreen.x,w.positionScreen.y);$.addPoint(D.positionScreen.x,D.positionScreen.y);if(!ya.instersects($))continue;G=0;for(V=m.meshMaterial.length;G<V;){E=m.meshMaterial[G++];if(E instanceof THREE.MeshFaceMaterial){z=0;for(W=m.faceMaterial.length;z<
  107. W;)(E=m.faceMaterial[z++])&&c(F,w,D,m,E,v)}else E&&c(F,w,D,m,E,v)}}else if(m instanceof THREE.RenderableFace4){F=m.v1;w=m.v2;D=m.v3;P=m.v4;F.positionScreen.x*=s;F.positionScreen.y*=q;w.positionScreen.x*=s;w.positionScreen.y*=q;D.positionScreen.x*=s;D.positionScreen.y*=q;P.positionScreen.x*=s;P.positionScreen.y*=q;fa.positionScreen.copy(w.positionScreen);B.positionScreen.copy(P.positionScreen);if(m.overdraw){p(F.positionScreen,w.positionScreen);p(w.positionScreen,P.positionScreen);p(P.positionScreen,
  108. F.positionScreen)}if(m.overdraw){p(D.positionScreen,fa.positionScreen);p(D.positionScreen,B.positionScreen)}$.addPoint(F.positionScreen.x,F.positionScreen.y);$.addPoint(w.positionScreen.x,w.positionScreen.y);$.addPoint(D.positionScreen.x,D.positionScreen.y);$.addPoint(P.positionScreen.x,P.positionScreen.y);if(!ya.instersects($))continue;G=0;for(V=m.meshMaterial.length;G<V;){E=m.meshMaterial[G++];if(E instanceof THREE.MeshFaceMaterial){z=0;for(W=m.faceMaterial.length;z<W;)(E=m.faceMaterial[z++])&&
  109. f(F,w,D,P,fa,B,m,E,v)}else E&&f(F,w,D,P,fa,B,m,E,v)}}ua.addRectangle($)}l.setTransform(1,0,0,1,0,0)}};
  110. THREE.SVGRenderer=function(){function a(B,L,K){var R,x,u,Q;R=0;for(x=B.lights.length;R<x;R++){u=B.lights[R];if(u instanceof THREE.DirectionalLight){Q=L.normalWorld.dot(u.position)*u.intensity;if(Q>0){K.r+=u.color.r*Q;K.g+=u.color.g*Q;K.b+=u.color.b*Q}}else if(u instanceof THREE.PointLight){Y.sub(u.position,L.centroidWorld);Y.normalize();Q=L.normalWorld.dot(Y)*u.intensity;if(Q>0){K.r+=u.color.r*Q;K.g+=u.color.g*Q;K.b+=u.color.b*Q}}}}function c(B,L,K,R,x,u){w=h(D++);w.setAttribute("d","M "+B.positionScreen.x+
  111. " "+B.positionScreen.y+" L "+L.positionScreen.x+" "+L.positionScreen.y+" L "+K.positionScreen.x+","+K.positionScreen.y+"z");if(x instanceof THREE.MeshBasicMaterial)s.__styleString=x.color.__styleString;else if(x instanceof THREE.MeshLambertMaterial)if(M){q.r=l.r;q.g=l.g;q.b=l.b;a(u,R,q);s.r=x.color.r*q.r;s.g=x.color.g*q.g;s.b=x.color.b*q.b;s.updateStyleString()}else s.__styleString=x.color.__styleString;else if(x instanceof THREE.MeshDepthMaterial){T=1-x.__2near/(x.__farPlusNear-R.z*x.__farMinusNear);
  112. s.setRGB(T,T,T)}else x instanceof THREE.MeshNormalMaterial&&s.setRGB(b(R.normalWorld.x),b(R.normalWorld.y),b(R.normalWorld.z));x.wireframe?w.setAttribute("style","fill: none; stroke: "+s.__styleString+"; stroke-width: "+x.wireframe_linewidth+"; stroke-opacity: "+x.opacity+"; stroke-linecap: round; stroke-linejoin: round"):w.setAttribute("style","fill: "+s.__styleString+"; fill-opacity: "+x.opacity);r.appendChild(w)}function f(B,L,K,R,x,u,Q){w=h(D++);w.setAttribute("d","M "+B.positionScreen.x+" "+
  113. B.positionScreen.y+" L "+L.positionScreen.x+" "+L.positionScreen.y+" L "+K.positionScreen.x+","+K.positionScreen.y+" L "+R.positionScreen.x+","+R.positionScreen.y+"z");if(u instanceof THREE.MeshBasicMaterial)s.__styleString=u.color.__styleString;else if(u instanceof THREE.MeshLambertMaterial)if(M){q.r=l.r;q.g=l.g;q.b=l.b;a(Q,x,q);s.r=u.color.r*q.r;s.g=u.color.g*q.g;s.b=u.color.b*q.b;s.updateStyleString()}else s.__styleString=u.color.__styleString;else if(u instanceof THREE.MeshDepthMaterial){T=1-
  114. u.__2near/(u.__farPlusNear-x.z*u.__farMinusNear);s.setRGB(T,T,T)}else u instanceof THREE.MeshNormalMaterial&&s.setRGB(b(x.normalWorld.x),b(x.normalWorld.y),b(x.normalWorld.z));u.wireframe?w.setAttribute("style","fill: none; stroke: "+s.__styleString+"; stroke-width: "+u.wireframe_linewidth+"; stroke-opacity: "+u.opacity+"; stroke-linecap: round; stroke-linejoin: round"):w.setAttribute("style","fill: "+s.__styleString+"; fill-opacity: "+u.opacity);r.appendChild(w)}function h(B){if(t[B]==null){t[B]=
  115. document.createElementNS("http://www.w3.org/2000/svg","path");fa==0&&t[B].setAttribute("shape-rendering","crispEdges");return t[B]}return t[B]}function b(B){return B<0?Math.min((1+B)*0.5,0.5):0.5+Math.min(B*0.5,0.5)}var d=null,o=new THREE.Projector,r=document.createElementNS("http://www.w3.org/2000/svg","svg"),n,e,g,k,j,p,i,C,y=new THREE.Rectangle,A=new THREE.Rectangle,M=false,s=new THREE.Color(16777215),q=new THREE.Color(16777215),l=new THREE.Color(0),S=new THREE.Color(0),H=new THREE.Color(0),T,
  116. Y=new THREE.Vector3,t=[],F=[],w,D,P,fa=1;this.domElement=r;this.autoClear=true;this.setQuality=function(B){switch(B){case "high":fa=1;break;case "low":fa=0}};this.setSize=function(B,L){n=B;e=L;g=n/2;k=e/2;r.setAttribute("viewBox",-g+" "+-k+" "+n+" "+e);r.setAttribute("width",n);r.setAttribute("height",e);y.set(-g,-k,g,k)};this.clear=function(){for(;r.childNodes.length>0;)r.removeChild(r.childNodes[0])};this.render=function(B,L){var K,R,x,u,Q,ha,O,X;this.autoClear&&this.clear();d=o.projectScene(B,
  117. L);P=D=0;if(M=B.lights.length>0){O=B.lights;l.setRGB(0,0,0);S.setRGB(0,0,0);H.setRGB(0,0,0);K=0;for(R=O.length;K<R;K++){x=O[K];u=x.color;if(x instanceof THREE.AmbientLight){l.r+=u.r;l.g+=u.g;l.b+=u.b}else if(x instanceof THREE.DirectionalLight){S.r+=u.r;S.g+=u.g;S.b+=u.b}else if(x instanceof THREE.PointLight){H.r+=u.r;H.g+=u.g;H.b+=u.b}}}K=0;for(R=d.length;K<R;K++){O=d[K];A.empty();if(O instanceof THREE.RenderableParticle){j=O;j.x*=g;j.y*=-k;x=0;for(u=O.material.length;x<u;x++)if(X=O.material[x]){Q=
  118. j;ha=O;X=X;var xa=P++;if(F[xa]==null){F[xa]=document.createElementNS("http://www.w3.org/2000/svg","circle");fa==0&&F[xa].setAttribute("shape-rendering","crispEdges")}w=F[xa];w.setAttribute("cx",Q.x);w.setAttribute("cy",Q.y);w.setAttribute("r",ha.scale.x*g);if(X instanceof THREE.ParticleCircleMaterial){if(M){q.r=l.r+S.r+H.r;q.g=l.g+S.g+H.g;q.b=l.b+S.b+H.b;s.r=X.color.r*q.r;s.g=X.color.g*q.g;s.b=X.color.b*q.b;s.updateStyleString()}else s=X.color;w.setAttribute("style","fill: "+s.__styleString)}r.appendChild(w)}}else if(O instanceof
  119. THREE.RenderableFace3){j=O.v1;p=O.v2;i=O.v3;j.positionScreen.x*=g;j.positionScreen.y*=-k;p.positionScreen.x*=g;p.positionScreen.y*=-k;i.positionScreen.x*=g;i.positionScreen.y*=-k;A.addPoint(j.positionScreen.x,j.positionScreen.y);A.addPoint(p.positionScreen.x,p.positionScreen.y);A.addPoint(i.positionScreen.x,i.positionScreen.y);if(y.instersects(A)){x=0;for(u=O.meshMaterial.length;x<u;){X=O.meshMaterial[x++];if(X instanceof THREE.MeshFaceMaterial){Q=0;for(ha=O.faceMaterial.length;Q<ha;)(X=O.faceMaterial[Q++])&&
  120. c(j,p,i,O,X,B)}else X&&c(j,p,i,O,X,B)}}}else if(O instanceof THREE.RenderableFace4){j=O.v1;p=O.v2;i=O.v3;C=O.v4;j.positionScreen.x*=g;j.positionScreen.y*=-k;p.positionScreen.x*=g;p.positionScreen.y*=-k;i.positionScreen.x*=g;i.positionScreen.y*=-k;C.positionScreen.x*=g;C.positionScreen.y*=-k;A.addPoint(j.positionScreen.x,j.positionScreen.y);A.addPoint(p.positionScreen.x,p.positionScreen.y);A.addPoint(i.positionScreen.x,i.positionScreen.y);A.addPoint(C.positionScreen.x,C.positionScreen.y);if(y.instersects(A)){x=
  121. 0;for(u=O.meshMaterial.length;x<u;){X=O.meshMaterial[x++];if(X instanceof THREE.MeshFaceMaterial){Q=0;for(ha=O.faceMaterial.length;Q<ha;)(X=O.faceMaterial[Q++])&&f(j,p,i,C,O,X,B)}else X&&f(j,p,i,C,O,X,B)}}}}}};
  122. THREE.WebGLRenderer=function(a){function c(e,g){var k;if(e=="fragment")k=b.createShader(b.FRAGMENT_SHADER);else if(e=="vertex")k=b.createShader(b.VERTEX_SHADER);b.shaderSource(k,g);b.compileShader(k);if(!b.getShaderParameter(k,b.COMPILE_STATUS)){alert(b.getShaderInfoLog(k));return null}return k}function f(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 h=document.createElement("canvas"),b,
  123. d,o=new THREE.Matrix4,r;a=function(e,g){if(e){var k,j,p,i=pointLights=maxDirLights=maxPointLights=0;k=0;for(j=e.lights.length;k<j;k++){p=e.lights[k];p instanceof THREE.DirectionalLight&&i++;p instanceof THREE.PointLight&&pointLights++}if(pointLights+i<=g){maxDirLights=i;maxPointLights=pointLights}else{maxDirLights=Math.ceil(g*i/(pointLights+i));maxPointLights=g-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:g-1}}(a,4);this.domElement=h;this.autoClear=
  124. true;try{b=h.getContext("experimental-webgl",{antialias:true})}catch(n){}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);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,g){d=b.createProgram();b.attachShader(d,c("fragment",["#ifdef GL_ES\nprecision highp float;\n#endif",e?"#define MAX_DIR_LIGHTS "+
  125. e:"",g?"#define MAX_POINT_LIGHTS "+g:"","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;",e?
  126. "uniform mat4 viewMatrix;":"",e?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",g?"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 );",
  127. g?"vec4 pointDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );":"",g?"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",g?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",g?"vec3 pointVector = normalize( vPointLightVector[ i ] );":"",g?"vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );":"",g?"float pointDotNormalHalf = dot( normal, pointHalfVector );":"",g?"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );":"",g?"float pointSpecularWeight = 0.0;":"",g?"if ( pointDotNormalHalf >= 0.0 )":
  128. "",g?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",g?"pointDiffuse += mColor * pointDiffuseWeight;":"",g?"pointSpecular += mSpecular * pointSpecularWeight;":"",g?"}":"",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 );":
  129. "",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;":"",g?"totalLight += pointDiffuse + pointSpecular;":
  130. "","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")));
  131. b.attachShader(d,c("vertex",[e?"#define MAX_DIR_LIGHTS "+e:"",g?"#define MAX_POINT_LIGHTS "+g:"","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;",e?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",e?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",g?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":
  132. "",g?"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;",g?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","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;",
  133. 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?"}":"",g?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",g?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",g?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
  134. "",g?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",g?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",g?"}":"","}\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")));
  135. b.linkProgram(d);if(!b.getProgramParameter(d,b.LINK_STATUS)){alert("Could not initialise shaders");alert("VALIDATE_STATUS: "+b.getProgramParameter(d,b.VALIDATE_STATUS));alert(b.getError())}b.useProgram(d);d.viewMatrix=b.getUniformLocation(d,"viewMatrix");d.modelViewMatrix=b.getUniformLocation(d,"modelViewMatrix");d.projectionMatrix=b.getUniformLocation(d,"projectionMatrix");d.normalMatrix=b.getUniformLocation(d,"normalMatrix");d.objMatrix=b.getUniformLocation(d,"objMatrix");d.cameraPosition=b.getUniformLocation(d,
  136. "cameraPosition");d.enableLighting=b.getUniformLocation(d,"enableLighting");d.ambientLightColor=b.getUniformLocation(d,"ambientLightColor");if(e){d.directionalLightNumber=b.getUniformLocation(d,"directionalLightNumber");d.directionalLightColor=b.getUniformLocation(d,"directionalLightColor");d.directionalLightDirection=b.getUniformLocation(d,"directionalLightDirection")}if(g){d.pointLightNumber=b.getUniformLocation(d,"pointLightNumber");d.pointLightColor=b.getUniformLocation(d,"pointLightColor");d.pointLightPosition=
  137. b.getUniformLocation(d,"pointLightPosition")}d.material=b.getUniformLocation(d,"material");d.mColor=b.getUniformLocation(d,"mColor");d.mOpacity=b.getUniformLocation(d,"mOpacity");d.mReflectivity=b.getUniformLocation(d,"mReflectivity");d.mAmbient=b.getUniformLocation(d,"mAmbient");d.mSpecular=b.getUniformLocation(d,"mSpecular");d.mShininess=b.getUniformLocation(d,"mShininess");d.enableMap=b.getUniformLocation(d,"enableMap");b.uniform1i(d.enableMap,0);d.tMap=b.getUniformLocation(d,"tMap");b.uniform1i(d.tMap,
  138. 0);d.enableCubeMap=b.getUniformLocation(d,"enableCubeMap");b.uniform1i(d.enableCubeMap,0);d.tCube=b.getUniformLocation(d,"tCube");b.uniform1i(d.tCube,1);d.mixEnvMap=b.getUniformLocation(d,"mixEnvMap");b.uniform1i(d.mixEnvMap,0);d.mRefractionRatio=b.getUniformLocation(d,"mRefractionRatio");d.useRefract=b.getUniformLocation(d,"useRefract");b.uniform1i(d.useRefract,0);d.m2Near=b.getUniformLocation(d,"m2Near");d.mFarPlusNear=b.getUniformLocation(d,"mFarPlusNear");d.mFarMinusNear=b.getUniformLocation(d,
  139. "mFarMinusNear");d.position=b.getAttribLocation(d,"position");b.enableVertexAttribArray(d.position);d.normal=b.getAttribLocation(d,"normal");b.enableVertexAttribArray(d.normal);d.uv=b.getAttribLocation(d,"uv");b.enableVertexAttribArray(d.uv);d.viewMatrixArray=new Float32Array(16);d.modelViewMatrixArray=new Float32Array(16);d.projectionMatrixArray=new Float32Array(16)})(a.directional,a.point);this.setSize=function(e,g){h.width=e;h.height=g;b.viewport(0,0,h.width,h.height)};this.clear=function(){b.clear(b.COLOR_BUFFER_BIT|
  140. b.DEPTH_BUFFER_BIT)};this.setupLights=function(e){var g,k,j,p,i=[],C=[],y=[];p=[];var A=[];b.uniform1i(d.enableLighting,e.lights.length);g=0;for(k=e.lights.length;g<k;g++){j=e.lights[g];if(j instanceof THREE.AmbientLight)i.push(j);else if(j instanceof THREE.DirectionalLight)y.push(j);else j instanceof THREE.PointLight&&C.push(j)}g=e=j=p=0;for(k=i.length;g<k;g++){e+=i[g].color.r;j+=i[g].color.g;p+=i[g].color.b}b.uniform3f(d.ambientLightColor,e,j,p);p=[];A=[];g=0;for(k=y.length;g<k;g++){j=y[g];p.push(j.color.r*
  141. j.intensity);p.push(j.color.g*j.intensity);p.push(j.color.b*j.intensity);A.push(j.position.x);A.push(j.position.y);A.push(j.position.z)}if(y.length){b.uniform1i(d.directionalLightNumber,y.length);b.uniform3fv(d.directionalLightDirection,A);b.uniform3fv(d.directionalLightColor,p)}p=[];A=[];g=0;for(k=C.length;g<k;g++){j=C[g];p.push(j.color.r*j.intensity);p.push(j.color.g*j.intensity);p.push(j.color.b*j.intensity);A.push(j.position.x);A.push(j.position.y);A.push(j.position.z)}if(C.length){b.uniform1i(d.pointLightNumber,
  142. C.length);b.uniform3fv(d.pointLightPosition,A);b.uniform3fv(d.pointLightColor,p)}};this.createBuffers=function(e,g){var k,j,p,i,C,y,A,M,s,q=e.materialFaceGroup[g],l=[],S=[],H=[],T=[],Y=[],t=0,F=false;k=0;for(j=e.material.length;k<j;k++){meshMaterial=e.material[k];if(meshMaterial instanceof THREE.MeshFaceMaterial){i=0;for(C=q.material.length;i<C;i++)if(q.material[i]&&q.material[i].shading!=undefined&&q.material[i].shading==THREE.SmoothShading){F=true;break}}else if(meshMaterial&&meshMaterial.shading!=
  143. undefined&&meshMaterial.shading==THREE.SmoothShading){F=true;break}if(F)break}k=0;for(j=q.faces.length;k<j;k++){p=q.faces[k];i=e.geometry.faces[p];C=i.vertexNormals;y=i.normal;p=e.geometry.uvs[p];if(i instanceof THREE.Face3){A=e.geometry.vertices[i.a].position;M=e.geometry.vertices[i.b].position;s=e.geometry.vertices[i.c].position;H.push(A.x,A.y,A.z);H.push(M.x,M.y,M.z);H.push(s.x,s.y,s.z);if(C.length==3&&F)for(i=0;i<3;i++)T.push(C[i].x,C[i].y,C[i].z);else for(i=0;i<3;i++)T.push(y.x,y.y,y.z);if(p)for(i=
  144. 0;i<3;i++)Y.push(p[i].u,p[i].v);l.push(t,t+1,t+2);S.push(t,t+1);S.push(t,t+2);S.push(t+1,t+2);t+=3}else if(i instanceof THREE.Face4){A=e.geometry.vertices[i.a].position;M=e.geometry.vertices[i.b].position;s=e.geometry.vertices[i.c].position;i=e.geometry.vertices[i.d].position;H.push(A.x,A.y,A.z);H.push(M.x,M.y,M.z);H.push(s.x,s.y,s.z);H.push(i.x,i.y,i.z);if(C.length==4&&F)for(i=0;i<4;i++)T.push(C[i].x,C[i].y,C[i].z);else for(i=0;i<4;i++)T.push(y.x,y.y,y.z);if(p)for(i=0;i<4;i++)Y.push(p[i].u,p[i].v);
  145. l.push(t,t+1,t+2);l.push(t,t+2,t+3);S.push(t,t+1);S.push(t,t+2);S.push(t,t+3);S.push(t+1,t+2);S.push(t+2,t+3);t+=4}}if(H.length){q.__webGLVertexBuffer=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,q.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,new Float32Array(H),b.STATIC_DRAW);q.__webGLNormalBuffer=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,q.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,new Float32Array(T),b.STATIC_DRAW);q.__webGLUVBuffer=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,q.__webGLUVBuffer);
  146. b.bufferData(b.ARRAY_BUFFER,new Float32Array(Y),b.STATIC_DRAW);q.__webGLFaceBuffer=b.createBuffer();b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,q.__webGLFaceBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,new Uint16Array(l),b.STATIC_DRAW);q.__webGLLineBuffer=b.createBuffer();b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,q.__webGLLineBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,new Uint16Array(S),b.STATIC_DRAW);q.__webGLFaceCount=l.length;q.__webGLLineCount=S.length}};this.renderBuffer=function(e,g){var k,j,p,i,C,y,A,M,
  147. s,q;if(e instanceof THREE.MeshPhongMaterial||e instanceof THREE.MeshLambertMaterial||e instanceof THREE.MeshBasicMaterial){k=e.color;j=e.opacity;i=e.wireframe;C=e.wireframe_linewidth;A=e.map;M=e.env_map;y=e.combine==THREE.Mix;p=e.reflectivity;q=e.env_map&&e.env_map.mapping==THREE.RefractionMap;s=e.refraction_ratio;b.uniform4f(d.mColor,k.r*j,k.g*j,k.b*j,j);b.uniform1i(d.mixEnvMap,y);b.uniform1f(d.mReflectivity,p);b.uniform1i(d.useRefract,q);b.uniform1f(d.mRefractionRatio,s)}if(e instanceof THREE.MeshNormalMaterial){j=
  148. e.opacity;b.uniform1f(d.mOpacity,j);b.uniform1i(d.material,4)}else if(e instanceof THREE.MeshDepthMaterial){j=e.opacity;i=e.wireframe;C=e.wireframe_linewidth;b.uniform1f(d.mOpacity,j);b.uniform1f(d.m2Near,e.__2near);b.uniform1f(d.mFarPlusNear,e.__farPlusNear);b.uniform1f(d.mFarMinusNear,e.__farMinusNear);b.uniform1i(d.material,3)}else if(e instanceof THREE.MeshPhongMaterial){k=e.ambient;p=e.specular;y=e.shininess;b.uniform4f(d.mAmbient,k.r,k.g,k.b,j);b.uniform4f(d.mSpecular,p.r,p.g,p.b,j);b.uniform1f(d.mShininess,
  149. y);b.uniform1i(d.material,2)}else if(e instanceof THREE.MeshLambertMaterial)b.uniform1i(d.material,1);else if(e instanceof THREE.MeshBasicMaterial)b.uniform1i(d.material,0);else if(e instanceof THREE.MeshCubeMaterial){b.uniform1i(d.material,5);M=e.env_map}if(A){if(!e.__webGLTexture&&e.map.image.loaded){e.__webGLTexture=b.createTexture();b.bindTexture(b.TEXTURE_2D,e.__webGLTexture);b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.map.image);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,
  150. f(e.map.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,f(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.__webGLTexture);b.uniform1i(d.tMap,0);b.uniform1i(d.enableMap,1)}else b.uniform1i(d.enableMap,0);if(M){if(e.env_map&&e.env_map instanceof THREE.TextureCube&&e.env_map.image.length==
  151. 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,b.LINEAR);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_MIN_FILTER,b.LINEAR_MIPMAP_LINEAR);
  152. for(j=0;j<6;++j)b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X+j,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[j]);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(d.tCube,1)}b.uniform1i(d.enableCubeMap,1)}else b.uniform1i(d.enableCubeMap,0);b.bindBuffer(b.ARRAY_BUFFER,g.__webGLVertexBuffer);b.vertexAttribPointer(d.position,
  153. 3,b.FLOAT,false,0,0);b.bindBuffer(b.ARRAY_BUFFER,g.__webGLNormalBuffer);b.vertexAttribPointer(d.normal,3,b.FLOAT,false,0,0);if(A){b.bindBuffer(b.ARRAY_BUFFER,g.__webGLUVBuffer);b.enableVertexAttribArray(d.uv);b.vertexAttribPointer(d.uv,2,b.FLOAT,false,0,0)}else b.disableVertexAttribArray(d.uv);if(i){b.lineWidth(C);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,g.__webGLLineBuffer);b.drawElements(b.LINES,g.__webGLLineCount,b.UNSIGNED_SHORT,0)}else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,g.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,
  154. g.__webGLFaceCount,b.UNSIGNED_SHORT,0)}};this.renderPass=function(e,g,k){var j,p,i,C,y;i=0;for(C=e.material.length;i<C;i++){j=e.material[i];if(j instanceof THREE.MeshFaceMaterial){j=0;for(p=g.material.length;j<p;j++)if((y=g.material[j])&&y.blending==k){this.setBlending(y.blending);this.renderBuffer(y,g)}}else if((y=j)&&y.blending==k){this.setBlending(y.blending);this.renderBuffer(y,g)}}};this.render=function(e,g){var k,j;this.initWebGLObjects(e);this.autoClear&&this.clear();g.autoUpdateMatrix&&g.updateMatrix();
  155. b.uniform3f(d.cameraPosition,g.position.x,g.position.y,g.position.z);this.setupLights(e);k=0;for(j=e.__webGLObjects.length;k<j;k++){webGLObject=e.__webGLObjects[k];this.setupMatrices(webGLObject.__object,g);this.renderPass(webGLObject.__object,webGLObject,THREE.NormalBlending)}k=0;for(j=e.__webGLObjects.length;k<j;k++){webGLObject=e.__webGLObjects[k];this.setupMatrices(webGLObject.__object,g);this.renderPass(webGLObject.__object,webGLObject,THREE.AdditiveBlending);this.renderPass(webGLObject.__object,
  156. webGLObject,THREE.SubtractiveBlending)}};this.initWebGLObjects=function(e){var g,k,j,p,i;if(!e.__webGLObjects)e.__webGLObjects=[];g=0;for(k=e.objects.length;g<k;g++){j=e.objects[g];if(j instanceof THREE.Mesh)for(p in j.materialFaceGroup){i=j.materialFaceGroup[p];if(!i.__webGLVertexBuffer){this.createBuffers(j,p);i.__object=j;e.__webGLObjects.push(i)}}}};this.setupMatrices=function(e,g){e.autoUpdateMatrix&&e.updateMatrix();o.multiply(g.matrix,e.matrix);d.viewMatrixArray=new Float32Array(g.matrix.flatten());
  157. d.modelViewMatrixArray=new Float32Array(o.flatten());d.projectionMatrixArray=new Float32Array(g.projectionMatrix.flatten());r=THREE.Matrix4.makeInvert3x3(o).transpose();d.normalMatrixArray=new Float32Array(r.m);b.uniformMatrix4fv(d.viewMatrix,false,d.viewMatrixArray);b.uniformMatrix4fv(d.modelViewMatrix,false,d.modelViewMatrixArray);b.uniformMatrix4fv(d.projectionMatrix,false,d.projectionMatrixArray);b.uniformMatrix3fv(d.normalMatrix,false,d.normalMatrixArray);b.uniformMatrix4fv(d.objMatrix,false,
  158. new Float32Array(e.matrix.flatten()))};this.setBlending=function(e){switch(e){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(e,g){if(e){!g||g=="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)}};
  159. THREE.RenderableFace3=function(){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.material=this.color=this.z=null};
  160. THREE.RenderableFace4=function(){this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.v4=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.material=this.color=this.z=null};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=this.color=null};
  161. THREE.RenderableLine=function(){this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=this.color=this.z=null};