ThreeExtras.js 105 KB

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