ThreeExtras.js 120 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. // ThreeExtras.js r32 - 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,e){this.r=a;this.g=b;this.b=e;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)+")"},clone:function(){return new THREE.Color(this.hex)},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,e){this.x=a||0;this.y=b||0;this.z=e||0};
  7. THREE.Vector3.prototype={set:function(a,b,e){this.x=a;this.y=b;this.z=e;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,e=this.y,f=this.z;this.x=e*a.z-f*a.y;this.y=f*a.x-b*a.z;this.z=b*a.y-e*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},divideSelf:function(a){this.x/=a.x;this.y/=a.y;this.z/=
  9. a.z;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=a;return this},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},distanceTo:function(a){var b=this.x-a.x,e=this.y-a.y;a=this.z-a.z;return Math.sqrt(b*b+e*e+a*a)},distanceToSquared:function(a){var b=this.x-a.x,e=this.y-a.y;a=this.z-a.z;return b*b+e*e+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=
  10. -this.x;this.y=-this.y;this.z=-this.z;return this},normalize:function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z);a>0?this.multiplyScalar(1/a):this.set(0,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,e,f){this.x=a||0;this.y=b||0;this.z=e||0;this.w=f||1};
  12. THREE.Vector4.prototype={set:function(a,b,e,f){this.x=a;this.y=b;this.z=e;this.w=f;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,e,f=a.objects,g=[];a=0;for(b=f.length;a<b;a++){e=f[a];if(e instanceof THREE.Mesh)g=g.concat(this.intersectObject(e))}g.sort(function(i,k){return i.distance-k.distance});return g},intersectObject:function(a){function b(N,r,O,m){m=m.clone().subSelf(r);O=O.clone().subSelf(r);var h=N.clone().subSelf(r);N=m.dot(m);r=m.dot(O);m=m.dot(h);var n=O.dot(O);O=O.dot(h);h=1/(N*n-r*r);n=(n*m-r*O)*h;N=(N*O-r*m)*h;return n>0&&N>0&&n+N<1}var e,f,g,i,k,d,j,l,q,F,
  16. o,A=a.geometry,D=A.vertices,E=[];e=0;for(f=A.faces.length;e<f;e++){g=A.faces[e];F=this.origin.clone();o=this.direction.clone();i=a.matrix.multiplyVector3(D[g.a].position.clone());k=a.matrix.multiplyVector3(D[g.b].position.clone());d=a.matrix.multiplyVector3(D[g.c].position.clone());j=g instanceof THREE.Face4?a.matrix.multiplyVector3(D[g.d].position.clone()):null;l=a.rotationMatrix.multiplyVector3(g.normal.clone());q=o.dot(l);if(q<0){l=l.dot((new THREE.Vector3).sub(i,F))/q;F=F.addSelf(o.multiplyScalar(l));
  17. if(g instanceof THREE.Face3){if(b(F,i,k,d)){g={distance:this.origin.distanceTo(F),point:F,face:g,object:a};E.push(g)}}else if(g instanceof THREE.Face4)if(b(F,i,k,j)||b(F,k,d,j)){g={distance:this.origin.distanceTo(F),point:F,face:g,object:a};E.push(g)}}}return E}};
  18. THREE.Rectangle=function(){function a(){i=f-b;k=g-e}var b,e,f,g,i,k,d=true;this.getX=function(){return b};this.getY=function(){return e};this.getWidth=function(){return i};this.getHeight=function(){return k};this.getLeft=function(){return b};this.getTop=function(){return e};this.getRight=function(){return f};this.getBottom=function(){return g};this.set=function(j,l,q,F){d=false;b=j;e=l;f=q;g=F;a()};this.addPoint=function(j,l){if(d){d=false;b=j;e=l;f=j;g=l}else{b=b<j?b:j;e=e<l?e:l;f=f>j?f:j;g=g>l?
  19. g:l}a()};this.add3Points=function(j,l,q,F,o,A){if(d){d=false;b=j<q?j<o?j:o:q<o?q:o;e=l<F?l<A?l:A:F<A?F:A;f=j>q?j>o?j:o:q>o?q:o;g=l>F?l>A?l:A:F>A?F:A}else{b=j<q?j<o?j<b?j:b:o<b?o:b:q<o?q<b?q:b:o<b?o:b;e=l<F?l<A?l<e?l:e:A<e?A:e:F<A?F<e?F:e:A<e?A:e;f=j>q?j>o?j>f?j:f:o>f?o:f:q>o?q>f?q:f:o>f?o:f;g=l>F?l>A?l>g?l:g:A>g?A:g:F>A?F>g?F:g:A>g?A:g}a()};this.addRectangle=function(j){if(d){d=false;b=j.getLeft();e=j.getTop();f=j.getRight();g=j.getBottom()}else{b=b<j.getLeft()?b:j.getLeft();e=e<j.getTop()?e:j.getTop();
  20. f=f>j.getRight()?f:j.getRight();g=g>j.getBottom()?g:j.getBottom()}a()};this.inflate=function(j){b-=j;e-=j;f+=j;g+=j;a()};this.minSelf=function(j){b=b>j.getLeft()?b:j.getLeft();e=e>j.getTop()?e:j.getTop();f=f<j.getRight()?f:j.getRight();g=g<j.getBottom()?g:j.getBottom();a()};this.instersects=function(j){return Math.min(f,j.getRight())-Math.max(b,j.getLeft())>=0&&Math.min(g,j.getBottom())-Math.max(e,j.getTop())>=0};this.empty=function(){d=true;g=f=e=b=0;a()};this.isEmpty=function(){return d};this.toString=
  21. function(){return"THREE.Rectangle ( left: "+b+", right: "+f+", top: "+e+", bottom: "+g+", width: "+i+", 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}};
  22. THREE.Matrix4=function(a,b,e,f,g,i,k,d,j,l,q,F,o,A,D,E){this.n11=a||1;this.n12=b||0;this.n13=e||0;this.n14=f||0;this.n21=g||0;this.n22=i||1;this.n23=k||0;this.n24=d||0;this.n31=j||0;this.n32=l||0;this.n33=q||1;this.n34=F||0;this.n41=o||0;this.n42=A||0;this.n43=D||0;this.n44=E||1;this.flat=Array(16);this.m33=new THREE.Matrix3};
  23. 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,e,f,g,i,k,d,j,l,q,F,o,A,D,E){this.n11=a;this.n12=b;this.n13=e;this.n14=f;this.n21=g;this.n22=i;this.n23=k;this.n24=d;this.n31=j;this.n32=l;this.n33=q;this.n34=F;this.n41=o;this.n42=A;this.n43=D;this.n44=E;return this},copy:function(a){this.n11=a.n11;this.n12=a.n12;this.n13=
  24. 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,e){var f=THREE.Matrix4.__tmpVec1,g=THREE.Matrix4.__tmpVec2,i=THREE.Matrix4.__tmpVec3;i.sub(a,b).normalize();f.cross(e,i).normalize();g.cross(i,f).normalize();this.n11=f.x;this.n12=f.y;this.n13=f.z;this.n14=-f.dot(a);this.n21=g.x;this.n22=g.y;this.n23=g.z;this.n24=-g.dot(a);
  25. this.n31=i.x;this.n32=i.y;this.n33=i.z;this.n34=-i.dot(a);this.n43=this.n42=this.n41=0;this.n44=1;return this},multiplyVector3:function(a){var b=a.x,e=a.y,f=a.z,g=1/(this.n41*b+this.n42*e+this.n43*f+this.n44);a.x=(this.n11*b+this.n12*e+this.n13*f+this.n14)*g;a.y=(this.n21*b+this.n22*e+this.n23*f+this.n24)*g;a.z=(this.n31*b+this.n32*e+this.n33*f+this.n34)*g;return a},multiplyVector4:function(a){var b=a.x,e=a.y,f=a.z,g=a.w;a.x=this.n11*b+this.n12*e+this.n13*f+this.n14*g;a.y=this.n21*b+this.n22*e+this.n23*
  26. f+this.n24*g;a.z=this.n31*b+this.n32*e+this.n33*f+this.n34*g;a.w=this.n41*b+this.n42*e+this.n43*f+this.n44*g;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 e=a.n11,f=a.n12,g=a.n13,i=a.n14,k=a.n21,d=a.n22,j=a.n23,l=a.n24,q=a.n31,
  27. F=a.n32,o=a.n33,A=a.n34,D=a.n41,E=a.n42,N=a.n43,r=a.n44,O=b.n11,m=b.n12,h=b.n13,n=b.n14,C=b.n21,p=b.n22,B=b.n23,P=b.n24,v=b.n31,G=b.n32,I=b.n33,H=b.n34,w=b.n41,R=b.n42,L=b.n43,X=b.n44;this.n11=e*O+f*C+g*v+i*w;this.n12=e*m+f*p+g*G+i*R;this.n13=e*h+f*B+g*I+i*L;this.n14=e*n+f*P+g*H+i*X;this.n21=k*O+d*C+j*v+l*w;this.n22=k*m+d*p+j*G+l*R;this.n23=k*h+d*B+j*I+l*L;this.n24=k*n+d*P+j*H+l*X;this.n31=q*O+F*C+o*v+A*w;this.n32=q*m+F*p+o*G+A*R;this.n33=q*h+F*B+o*I+A*L;this.n34=q*n+F*P+o*H+A*X;this.n41=D*O+E*C+
  28. N*v+r*w;this.n42=D*m+E*p+N*G+r*R;this.n43=D*h+E*B+N*I+r*L;this.n44=D*n+E*P+N*H+r*X;return this},multiplySelf:function(a){var b=this.n11,e=this.n12,f=this.n13,g=this.n14,i=this.n21,k=this.n22,d=this.n23,j=this.n24,l=this.n31,q=this.n32,F=this.n33,o=this.n34,A=this.n41,D=this.n42,E=this.n43,N=this.n44,r=a.n11,O=a.n21,m=a.n31,h=a.n41,n=a.n12,C=a.n22,p=a.n32,B=a.n42,P=a.n13,v=a.n23,G=a.n33,I=a.n43,H=a.n14,w=a.n24,R=a.n34;a=a.n44;this.n11=b*r+e*O+f*m+g*h;this.n12=b*n+e*C+f*p+g*B;this.n13=b*P+e*v+f*G+g*
  29. I;this.n14=b*H+e*w+f*R+g*a;this.n21=i*r+k*O+d*m+j*h;this.n22=i*n+k*C+d*p+j*B;this.n23=i*P+k*v+d*G+j*I;this.n24=i*H+k*w+d*R+j*a;this.n31=l*r+q*O+F*m+o*h;this.n32=l*n+q*C+F*p+o*B;this.n33=l*P+q*v+F*G+o*I;this.n34=l*H+q*w+F*R+o*a;this.n41=A*r+D*O+E*m+N*h;this.n42=A*n+D*C+E*p+N*B;this.n43=A*P+D*v+E*G+N*I;this.n44=A*H+D*w+E*R+N*a;return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*=a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=
  30. a;this.n41*=a;this.n42*=a;this.n43*=a;this.n44*=a;return this},determinant:function(){var a=this.n11,b=this.n12,e=this.n13,f=this.n14,g=this.n21,i=this.n22,k=this.n23,d=this.n24,j=this.n31,l=this.n32,q=this.n33,F=this.n34,o=this.n41,A=this.n42,D=this.n43,E=this.n44;return f*k*l*o-e*d*l*o-f*i*q*o+b*d*q*o+e*i*F*o-b*k*F*o-f*k*j*A+e*d*j*A+f*g*q*A-a*d*q*A-e*g*F*A+a*k*F*A+f*i*j*D-b*d*j*D-f*g*l*D+a*d*l*D+b*g*F*D-a*i*F*D-e*i*j*E+b*k*j*E+e*g*l*E-a*k*l*E-b*g*q*E+a*i*q*E},transpose:function(){function a(b,e,
  31. f){var g=b[e];b[e]=b[f];b[f]=g}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;a.n42=this.n42;a.n43=this.n43;a.n44=this.n44;return a},flatten:function(){this.flat[0]=this.n11;this.flat[1]=
  32. this.n21;this.flat[2]=this.n31;this.flat[3]=this.n41;this.flat[4]=this.n12;this.flat[5]=this.n22;this.flat[6]=this.n32;this.flat[7]=this.n42;this.flat[8]=this.n13;this.flat[9]=this.n23;this.flat[10]=this.n33;this.flat[11]=this.n43;this.flat[12]=this.n14;this.flat[13]=this.n24;this.flat[14]=this.n34;this.flat[15]=this.n44;return this.flat},setTranslation:function(a,b,e){this.set(1,0,0,a,0,1,0,b,0,0,1,e,0,0,0,1);return this},setScale:function(a,b,e){this.set(a,0,0,0,0,b,0,0,0,0,e,0,0,0,0,1);return this},
  33. setRotX:function(a){var b=Math.cos(a);a=Math.sin(a);this.set(1,0,0,0,0,b,-a,0,0,a,b,0,0,0,0,1);return this},setRotY:function(a){var b=Math.cos(a);a=Math.sin(a);this.set(b,0,a,0,0,1,0,0,-a,0,b,0,0,0,0,1);return this},setRotZ:function(a){var b=Math.cos(a);a=Math.sin(a);this.set(b,-a,0,0,a,b,0,0,0,0,1,0,0,0,0,1);return this},setRotAxis:function(a,b){c=Math.cos(b);s=Math.sin(b);t=1-c;x=a.x;y=a.y;z=a.z;tx=t*x;ty=t*y;this.set(tx*x+c,tx*y-s*z,tx*z+s*y,0,tx*y+s*z,ty*y+c,ty*z-s*x,0,tx*z-s*y,ty*z+s*x,t*z*z+
  34. c,0,0,0,0,1);return this},toString:function(){return"| "+this.n11+" "+this.n12+" "+this.n13+" "+this.n14+" |\n| "+this.n21+" "+this.n22+" "+this.n23+" "+this.n24+" |\n| "+this.n31+" "+this.n32+" "+this.n33+" "+this.n34+" |\n| "+this.n41+" "+this.n42+" "+this.n43+" "+this.n44+" |"}};THREE.Matrix4.translationMatrix=function(a,b,e){var f=new THREE.Matrix4;f.n14=a;f.n24=b;f.n34=e;return f};THREE.Matrix4.scaleMatrix=function(a,b,e){var f=new THREE.Matrix4;f.n11=a;f.n22=b;f.n33=e;return f};
  35. THREE.Matrix4.rotationXMatrix=function(a){var b=new THREE.Matrix4;b.n22=b.n33=Math.cos(a);b.n32=Math.sin(a);b.n23=-b.n32;return b};THREE.Matrix4.rotationYMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n33=Math.cos(a);b.n13=Math.sin(a);b.n31=-b.n13;return b};THREE.Matrix4.rotationZMatrix=function(a){var b=new THREE.Matrix4;b.n11=b.n22=Math.cos(a);b.n21=Math.sin(a);b.n12=-b.n21;return b};
  36. THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var e=new THREE.Matrix4,f=Math.cos(b),g=Math.sin(b),i=1-f,k=a.x,d=a.y,j=a.z,l=i*k,q=i*d;e.n11=l*k+f;e.n12=l*d-g*j;e.n13=l*j+g*d;e.n21=l*d+g*j;e.n22=q*d+f;e.n23=q*j-g*k;e.n31=l*j-g*d;e.n32=q*j+g*k;e.n33=i*j*j+f;return e};
  37. THREE.Matrix4.makeInvert=function(a){var b=a.n11,e=a.n12,f=a.n13,g=a.n14,i=a.n21,k=a.n22,d=a.n23,j=a.n24,l=a.n31,q=a.n32,F=a.n33,o=a.n34,A=a.n41,D=a.n42,E=a.n43,N=a.n44,r=new THREE.Matrix4;r.n11=d*o*D-j*F*D+j*q*E-k*o*E-d*q*N+k*F*N;r.n12=g*F*D-f*o*D-g*q*E+e*o*E+f*q*N-e*F*N;r.n13=f*j*D-g*d*D+g*k*E-e*j*E-f*k*N+e*d*N;r.n14=g*d*q-f*j*q-g*k*F+e*j*F+f*k*o-e*d*o;r.n21=j*F*A-d*o*A-j*l*E+i*o*E+d*l*N-i*F*N;r.n22=f*o*A-g*F*A+g*l*E-b*o*E-f*l*N+b*F*N;r.n23=g*d*A-f*j*A-g*i*E+b*j*E+f*i*N-b*d*N;r.n24=f*j*l-g*d*l+
  38. g*i*F-b*j*F-f*i*o+b*d*o;r.n31=k*o*A-j*q*A+j*l*D-i*o*D-k*l*N+i*q*N;r.n32=g*q*A-e*o*A-g*l*D+b*o*D+e*l*N-b*q*N;r.n33=f*j*A-g*k*A+g*i*D-b*j*D-e*i*N+b*k*N;r.n34=g*k*l-e*j*l-g*i*q+b*j*q+e*i*o-b*k*o;r.n41=d*q*A-k*F*A-d*l*D+i*F*D+k*l*E-i*q*E;r.n42=e*F*A-f*q*A+f*l*D-b*F*D-e*l*E+b*q*E;r.n43=f*k*A-e*d*A-f*i*D+b*d*D+e*i*E-b*k*E;r.n44=e*d*l-f*k*l+f*i*q-b*d*q-e*i*F+b*k*F;r.multiplyScalar(1/a.determinant());return r};
  39. THREE.Matrix4.makeInvert3x3=function(a){var b=a.flatten();a=a.m33;var e=b[10]*b[5]-b[6]*b[9],f=-b[10]*b[1]+b[2]*b[9],g=b[6]*b[1]-b[2]*b[5],i=-b[10]*b[4]+b[6]*b[8],k=b[10]*b[0]-b[2]*b[8],d=-b[6]*b[0]+b[2]*b[4],j=b[9]*b[4]-b[5]*b[8],l=-b[9]*b[0]+b[1]*b[8],q=b[5]*b[0]-b[1]*b[4];b=b[0]*e+b[1]*i+b[2]*j;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*e;a.m[1]=b*f;a.m[2]=b*g;a.m[3]=b*i;a.m[4]=b*k;a.m[5]=b*d;a.m[6]=b*j;a.m[7]=b*l;a.m[8]=b*q;return a};
  40. THREE.Matrix4.makeFrustum=function(a,b,e,f,g,i){var k,d,j;k=new THREE.Matrix4;d=2*g/(b-a);j=2*g/(f-e);a=(b+a)/(b-a);e=(f+e)/(f-e);f=-(i+g)/(i-g);g=-2*i*g/(i-g);k.n11=d;k.n12=0;k.n13=a;k.n14=0;k.n21=0;k.n22=j;k.n23=e;k.n24=0;k.n31=0;k.n32=0;k.n33=f;k.n34=g;k.n41=0;k.n42=0;k.n43=-1;k.n44=0;return k};THREE.Matrix4.makePerspective=function(a,b,e,f){var g;a=e*Math.tan(a*Math.PI/360);g=-a;return THREE.Matrix4.makeFrustum(g*b,a*b,g,a,e,f)};
  41. THREE.Matrix4.makeOrtho=function(a,b,e,f,g,i){var k,d,j,l;k=new THREE.Matrix4;d=b-a;j=e-f;l=i-g;a=(b+a)/d;e=(e+f)/j;g=(i+g)/l;k.n11=2/d;k.n12=0;k.n13=0;k.n14=-a;k.n21=0;k.n22=2/j;k.n23=0;k.n24=-e;k.n31=0;k.n32=0;k.n33=-2/l;k.n34=-g;k.n41=0;k.n42=0;k.n43=0;k.n44=1;return k};THREE.Matrix4.__tmpVec1=new THREE.Vector3;THREE.Matrix4.__tmpVec2=new THREE.Vector3;THREE.Matrix4.__tmpVec3=new THREE.Vector3;
  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,e,f,g){this.a=a;this.b=b;this.c=e;this.centroid=new THREE.Vector3;this.normal=f instanceof THREE.Vector3?f:new THREE.Vector3;this.vertexNormals=f instanceof Array?f:[];this.materials=g instanceof Array?g:[g]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
  44. THREE.Face4=function(a,b,e,f,g,i){this.a=a;this.b=b;this.c=e;this.d=f;this.centroid=new THREE.Vector3;this.normal=g instanceof THREE.Vector3?g:new THREE.Vector3;this.vertexNormals=g instanceof Array?g:[];this.materials=i instanceof Array?i:[i]};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.boundingSphere=this.boundingBox=null;this.geometryChunks={};this.hasTangents=false};
  46. THREE.Geometry.prototype={computeCentroids:function(){var a,b,e;a=0;for(b=this.faces.length;a<b;a++){e=this.faces[a];e.centroid.set(0,0,0);if(e instanceof THREE.Face3){e.centroid.addSelf(this.vertices[e.a].position);e.centroid.addSelf(this.vertices[e.b].position);e.centroid.addSelf(this.vertices[e.c].position);e.centroid.divideScalar(3)}else if(e instanceof THREE.Face4){e.centroid.addSelf(this.vertices[e.a].position);e.centroid.addSelf(this.vertices[e.b].position);e.centroid.addSelf(this.vertices[e.c].position);
  47. e.centroid.addSelf(this.vertices[e.d].position);e.centroid.divideScalar(4)}}},computeFaceNormals:function(a){var b,e,f,g,i,k,d=new THREE.Vector3,j=new THREE.Vector3;f=0;for(g=this.vertices.length;f<g;f++){i=this.vertices[f];i.normal.set(0,0,0)}f=0;for(g=this.faces.length;f<g;f++){i=this.faces[f];if(a&&i.vertexNormals.length){d.set(0,0,0);b=0;for(e=i.normal.length;b<e;b++)d.addSelf(i.vertexNormals[b]);d.divideScalar(3)}else{b=this.vertices[i.a];e=this.vertices[i.b];k=this.vertices[i.c];d.sub(k.position,
  48. e.position);j.sub(b.position,e.position);d.crossSelf(j)}d.isZero()||d.normalize();i.normal.copy(d)}},computeVertexNormals:function(){var a,b,e,f;if(this.__tmpVertices==undefined){f=this.__tmpVertices=Array(this.vertices.length);a=0;for(b=this.vertices.length;a<b;a++)f[a]=new THREE.Vector3;a=0;for(b=this.faces.length;a<b;a++){e=this.faces[a];if(e instanceof THREE.Face3)e.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];else if(e instanceof THREE.Face4)e.vertexNormals=[new THREE.Vector3,
  49. new THREE.Vector3,new THREE.Vector3,new THREE.Vector3]}}else{f=this.__tmpVertices;a=0;for(b=this.vertices.length;a<b;a++)f[a].set(0,0,0)}a=0;for(b=this.faces.length;a<b;a++){e=this.faces[a];if(e instanceof THREE.Face3){f[e.a].addSelf(e.normal);f[e.b].addSelf(e.normal);f[e.c].addSelf(e.normal)}else if(e instanceof THREE.Face4){f[e.a].addSelf(e.normal);f[e.b].addSelf(e.normal);f[e.c].addSelf(e.normal);f[e.d].addSelf(e.normal)}}a=0;for(b=this.vertices.length;a<b;a++)f[a].normalize();a=0;for(b=this.faces.length;a<
  50. b;a++){e=this.faces[a];if(e instanceof THREE.Face3){e.vertexNormals[0].copy(f[e.a]);e.vertexNormals[1].copy(f[e.b]);e.vertexNormals[2].copy(f[e.c])}else if(e instanceof THREE.Face4){e.vertexNormals[0].copy(f[e.a]);e.vertexNormals[1].copy(f[e.b]);e.vertexNormals[2].copy(f[e.c]);e.vertexNormals[3].copy(f[e.d])}}},computeTangents:function(){function a(H,w,R,L,X,Z,S){i=H.vertices[w].position;k=H.vertices[R].position;d=H.vertices[L].position;j=g[X];l=g[Z];q=g[S];F=k.x-i.x;o=d.x-i.x;A=k.y-i.y;D=d.y-i.y;
  51. E=k.z-i.z;N=d.z-i.z;r=l.u-j.u;O=q.u-j.u;m=l.v-j.v;h=q.v-j.v;n=1/(r*h-O*m);B.set((h*F-m*o)*n,(h*A-m*D)*n,(h*E-m*N)*n);P.set((r*o-O*F)*n,(r*D-O*A)*n,(r*N-O*E)*n);C[w].addSelf(B);C[R].addSelf(B);C[L].addSelf(B);p[w].addSelf(P);p[R].addSelf(P);p[L].addSelf(P)}var b,e,f,g,i,k,d,j,l,q,F,o,A,D,E,N,r,O,m,h,n,C=[],p=[],B=new THREE.Vector3,P=new THREE.Vector3,v=new THREE.Vector3,G=new THREE.Vector3,I=new THREE.Vector3;b=0;for(e=this.vertices.length;b<e;b++){C[b]=new THREE.Vector3;p[b]=new THREE.Vector3}b=0;
  52. for(e=this.faces.length;b<e;b++){f=this.faces[b];g=this.uvs[b];if(f instanceof THREE.Face3){a(this,f.a,f.b,f.c,0,1,2);this.vertices[f.a].normal.copy(f.vertexNormals[0]);this.vertices[f.b].normal.copy(f.vertexNormals[1]);this.vertices[f.c].normal.copy(f.vertexNormals[2])}else if(f instanceof THREE.Face4){a(this,f.a,f.b,f.c,0,1,2);a(this,f.a,f.b,f.d,0,1,3);this.vertices[f.a].normal.copy(f.vertexNormals[0]);this.vertices[f.b].normal.copy(f.vertexNormals[1]);this.vertices[f.c].normal.copy(f.vertexNormals[2]);
  53. this.vertices[f.d].normal.copy(f.vertexNormals[3])}}b=0;for(e=this.vertices.length;b<e;b++){I.copy(this.vertices[b].normal);f=C[b];v.copy(f);v.subSelf(I.multiplyScalar(I.dot(f))).normalize();G.cross(this.vertices[b].normal,f);f=G.dot(p[b]);f=f<0?-1:1;this.vertices[b].tangent.set(v.x,v.y,v.z,f)}this.hasTangents=true},computeBoundingBox:function(){var a;if(this.vertices.length>0){this.boundingBox={x:[this.vertices[0].position.x,this.vertices[0].position.x],y:[this.vertices[0].position.y,this.vertices[0].position.y],
  54. z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var b=1,e=this.vertices.length;b<e;b++){a=this.vertices[b];if(a.position.x<this.boundingBox.x[0])this.boundingBox.x[0]=a.position.x;else if(a.position.x>this.boundingBox.x[1])this.boundingBox.x[1]=a.position.x;if(a.position.y<this.boundingBox.y[0])this.boundingBox.y[0]=a.position.y;else if(a.position.y>this.boundingBox.y[1])this.boundingBox.y[1]=a.position.y;if(a.position.z<this.boundingBox.z[0])this.boundingBox.z[0]=a.position.z;else if(a.position.z>
  55. this.boundingBox.z[1])this.boundingBox.z[1]=a.position.z}}},computeBoundingSphere:function(){for(var a=this.boundingSphere===null?0:this.boundingSphere.radius,b=0,e=this.vertices.length;b<e;b++)a=Math.max(a,this.vertices[b].position.length());this.boundingSphere={radius:a}},sortFacesByMaterial:function(){function a(q){var F=[];b=0;for(e=q.length;b<e;b++)q[b]==undefined?F.push("undefined"):F.push(q[b].toString());return F.join("_")}var b,e,f,g,i,k,d,j,l={};f=0;for(g=this.faces.length;f<g;f++){i=this.faces[f];
  56. k=i.materials;d=a(k);if(l[d]==undefined)l[d]={hash:d,counter:0};j=l[d].hash+"_"+l[d].counter;if(this.geometryChunks[j]==undefined)this.geometryChunks[j]={faces:[],materials:k,vertices:0};i=i instanceof THREE.Face3?3:4;if(this.geometryChunks[j].vertices+i>65535){l[d].counter+=1;j=l[d].hash+"_"+l[d].counter;if(this.geometryChunks[j]==undefined)this.geometryChunks[j]={faces:[],materials:k,vertices:0}}this.geometryChunks[j].faces.push(f);this.geometryChunks[j].vertices+=i}},toString:function(){return"THREE.Geometry ( vertices: "+
  57. this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
  58. THREE.Camera=function(a,b,e,f){this.fov=a;this.aspect=b;this.near=e;this.far=f;this.position=new THREE.Vector3;this.target={position:new THREE.Vector3};this.autoUpdateMatrix=true;this.projectionMatrix=null;this.matrix=new THREE.Matrix4;this.up=new THREE.Vector3(0,1,0);this.tmpVec=new THREE.Vector3;this.translateX=function(g){this.tmpVec.sub(this.target.position,this.position).normalize().multiplyScalar(g);this.tmpVec.crossSelf(this.up);this.position.addSelf(this.tmpVec);this.target.position.addSelf(this.tmpVec)};
  59. this.translateZ=function(g){this.tmpVec.sub(this.target.position,this.position).normalize().multiplyScalar(g);this.position.subSelf(this.tmpVec);this.target.position.subSelf(this.tmpVec)};this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.updateProjectionMatrix=function(){this.projectionMatrix=THREE.Matrix4.makePerspective(this.fov,this.aspect,this.near,this.far)};this.updateProjectionMatrix()};
  60. THREE.Camera.prototype={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;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;
  61. 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;
  62. 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.rotationMatrix=new THREE.Matrix4;this.tmpMatrix=new THREE.Matrix4;this.screen=new THREE.Vector3;this.visible=this.autoUpdateMatrix=true};
  63. THREE.Object3D.prototype={updateMatrix:function(){var a=this.position,b=this.rotation,e=this.scale,f=this.tmpMatrix;this.matrix.setTranslation(a.x,a.y,a.z);this.rotationMatrix.identity();if(b.x!=0){f.setRotX(b.x);this.matrix.multiplySelf(f);this.rotationMatrix.multiplySelf(f)}if(b.y!=0){f.setRotY(b.y);this.matrix.multiplySelf(f);this.rotationMatrix.multiplySelf(f)}if(b.z!=0){f.setRotZ(b.z);this.matrix.multiplySelf(f);this.rotationMatrix.multiplySelf(f)}if(e.x!=0||e.y!=0||e.z!=0){f.setScale(e.x,e.y,
  64. e.z);this.matrix.multiplySelf(f)}}};THREE.Object3DCounter={value:0};THREE.Particle=function(a){THREE.Object3D.call(this);this.materials=a instanceof Array?a:[a];this.autoUpdateMatrix=false};THREE.Particle.prototype=new THREE.Object3D;THREE.Particle.prototype.constructor=THREE.Particle;THREE.ParticleSystem=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.materials=b instanceof Array?b:[b];this.autoUpdateMatrix=false};THREE.ParticleSystem.prototype=new THREE.Object3D;
  65. THREE.ParticleSystem.prototype.constructor=THREE.ParticleSystem;THREE.Line=function(a,b,e){THREE.Object3D.call(this);this.geometry=a;this.materials=b instanceof Array?b:[b];this.type=e!=undefined?e:THREE.LineStrip};THREE.LineStrip=0;THREE.LinePieces=1;THREE.Line.prototype=new THREE.Object3D;THREE.Line.prototype.constructor=THREE.Line;
  66. THREE.Mesh=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.materials=b instanceof Array?b:[b];this.overdraw=this.doubleSided=this.flipSided=false;this.geometry.boundingSphere||this.geometry.computeBoundingSphere()};THREE.Mesh.prototype=new THREE.Object3D;THREE.Mesh.prototype.constructor=THREE.Mesh;THREE.FlatShading=0;THREE.SmoothShading=1;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;
  67. THREE.LineBasicMaterial=function(a){this.color=new THREE.Color(16777215);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}};
  68. THREE.LineBasicMaterial.prototype={toString:function(){return"THREE.LineBasicMaterial (<br/>color: "+this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>linewidth: "+this.linewidth+"<br/>linecap: "+this.linecap+"<br/>linejoin: "+this.linejoin+"<br/>)"}};
  69. THREE.MeshBasicMaterial=function(a){this.id=THREE.MeshBasicMaterialCounter.value++;this.color=new THREE.Color(16777215);this.env_map=this.map=null;this.combine=THREE.MultiplyOperation;this.reflectivity=1;this.refraction_ratio=0.98;this.fog=true;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=
  70. 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.fog!==undefined)this.fog=a.fog;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!==
  71. 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}};
  72. THREE.MeshBasicMaterial.prototype={toString:function(){return"THREE.MeshBasicMaterial (<br/>id: "+this.id+"<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>env_map: "+this.env_map+"<br/>combine: "+this.combine+"<br/>reflectivity: "+this.reflectivity+"<br/>refraction_ratio: "+this.refraction_ratio+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>wireframe: "+this.wireframe+"<br/>wireframe_linewidth: "+this.wireframe_linewidth+"<br/>wireframe_linecap: "+this.wireframe_linecap+
  73. "<br/>wireframe_linejoin: "+this.wireframe_linejoin+"<br/>)"}};THREE.MeshBasicMaterialCounter={value:0};
  74. THREE.MeshLambertMaterial=function(a){this.id=THREE.MeshLambertMaterialCounter.value++;this.color=new THREE.Color(16777215);this.env_map=this.map=null;this.combine=THREE.MultiplyOperation;this.reflectivity=1;this.refraction_ratio=0.98;this.fog=true;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=
  75. 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.fog!==undefined)this.fog=a.fog;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!==
  76. 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}};
  77. THREE.MeshLambertMaterial.prototype={toString:function(){return"THREE.MeshLambertMaterial (<br/>id: "+this.id+"<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>env_map: "+this.env_map+"<br/>combine: "+this.combine+"<br/>reflectivity: "+this.reflectivity+"<br/>refraction_ratio: "+this.refraction_ratio+"<br/>opacity: "+this.opacity+"<br/>shading: "+this.shading+"<br/>blending: "+this.blending+"<br/>wireframe: "+this.wireframe+"<br/>wireframe_linewidth: "+this.wireframe_linewidth+"<br/>wireframe_linecap: "+
  78. this.wireframe_linecap+"<br/>wireframe_linejoin: "+this.wireframe_linejoin+"<br/> )"}};THREE.MeshLambertMaterialCounter={value:0};
  79. THREE.MeshPhongMaterial=function(a){this.id=THREE.MeshPhongMaterialCounter.value++;this.color=new THREE.Color(16777215);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.fog=true;this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=
  80. this.wireframe_linecap="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=
  81. a.reflectivity;if(a.refraction_ratio!==undefined)this.refraction_ratio=a.refraction_ratio;if(a.fog!==undefined)this.fog=a.fog;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!==
  82. undefined)this.wireframe_linejoin=a.wireframe_linejoin}};
  83. THREE.MeshPhongMaterial.prototype={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: "+
  84. 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};
  85. THREE.MeshDepthMaterial=function(a){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.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}};THREE.MeshDepthMaterial.prototype={toString:function(){return"THREE.MeshDepthMaterial"}};
  86. 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}};THREE.MeshNormalMaterial.prototype={toString:function(){return"THREE.MeshNormalMaterial"}};THREE.MeshFaceMaterial=function(){};THREE.MeshFaceMaterial.prototype={toString:function(){return"THREE.MeshFaceMaterial"}};
  87. 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!==
  88. 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}};
  89. THREE.MeshShaderMaterial.prototype={toString:function(){return"THREE.MeshShaderMaterial (<br/>id: "+this.id+"<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};
  90. THREE.ParticleBasicMaterial=function(a){this.color=new THREE.Color(16777215);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}};
  91. THREE.ParticleBasicMaterial.prototype={toString:function(){return"THREE.ParticleBasicMaterial (<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>)"}};THREE.ParticleCircleMaterial=function(a){this.color=new THREE.Color(16777215);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}};
  92. THREE.ParticleCircleMaterial.prototype={toString:function(){return"THREE.ParticleCircleMaterial (<br/>color: "+this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>)"}};THREE.ParticleDOMMaterial=function(a){this.domElement=a};THREE.ParticleDOMMaterial.prototype={toString:function(){return"THREE.ParticleDOMMaterial ( domElement: "+this.domElement+" )"}};
  93. THREE.Texture=function(a,b,e,f,g,i){this.image=a;this.mapping=b!==undefined?b:new THREE.UVMapping;this.wrap_s=e!==undefined?e:THREE.ClampToEdgeWrapping;this.wrap_t=f!==undefined?f:THREE.ClampToEdgeWrapping;this.mag_filter=g!==undefined?g:THREE.LinearFilter;this.min_filter=i!==undefined?i:THREE.LinearMipMapLinearFilter};
  94. THREE.Texture.prototype={clone:function(){return new THREE.Texture(this.image,this.mapping,this.wrap_s,this.wrap_t,this.mag_filter,this.min_filter)},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: "+this.min_filter+"<br/>)"}};THREE.MultiplyOperation=0;THREE.MixOperation=1;THREE.RepeatWrapping=0;THREE.ClampToEdgeWrapping=1;THREE.MirroredRepeatWrapping=2;
  95. THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLinearFilter=5;THREE.LinearFilter=6;THREE.LinearMipMapNearestFilter=7;THREE.LinearMipMapLinearFilter=8;THREE.ByteType=9;THREE.UnsignedByteType=10;THREE.ShortType=11;THREE.UnsignedShortType=12;THREE.IntType=13;THREE.UnsignedIntType=14;THREE.FloatType=15;THREE.AlphaFormat=16;THREE.RGBFormat=17;THREE.RGBAFormat=18;THREE.LuminanceFormat=19;THREE.LuminanceAlphaFormat=20;
  96. THREE.RenderTarget=function(a,b,e){this.width=a;this.height=b;e=e||{};this.wrap_s=e.wrap_s!==undefined?e.wrap_s:THREE.ClampToEdgeWrapping;this.wrap_t=e.wrap_t!==undefined?e.wrap_t:THREE.ClampToEdgeWrapping;this.mag_filter=e.mag_filter!==undefined?e.mag_filter:THREE.LinearFilter;this.min_filter=e.min_filter!==undefined?e.min_filter:THREE.LinearMipMapLinearFilter;this.format=e.format!==undefined?e.format:THREE.RGBFormat;this.type=e.type!==undefined?e.type:THREE.UnsignedByteType};
  97. var Uniforms={clone:function(a){var b,e,f,g={};for(b in a){g[b]={};for(e in a[b]){f=a[b][e];g[b][e]=f instanceof THREE.Color||f instanceof THREE.Vector3||f instanceof THREE.Texture?f.clone():f}}return g},merge:function(a){var b,e,f,g={};for(b=0;b<a.length;b++){f=this.clone(a[b]);for(e in f)g[e]=f[e]}return g}};THREE.CubeReflectionMapping=function(){};THREE.CubeRefractionMapping=function(){};THREE.LatitudeReflectionMapping=function(){};THREE.LatitudeRefractionMapping=function(){};
  98. THREE.SphericalReflectionMapping=function(){};THREE.SphericalRefractionMapping=function(){};THREE.UVMapping=function(){};
  99. THREE.Scene=function(){this.objects=[];this.lights=[];this.fog=null;this.addObject=function(a){this.objects.indexOf(a)===-1&&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.indexOf(a)===-1&&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+" )"}};
  100. THREE.Fog=function(a,b,e){this.color=new THREE.Color(a);this.near=b||1;this.far=e||1E3};THREE.FogExp2=function(a,b){this.color=new THREE.Color(a);this.density=b||2.5E-4};
  101. THREE.Projector=function(){function a(p,B){return B.z-p.z}function b(p,B){var P=0,v=1,G=p.z+p.w,I=B.z+B.w,H=-p.z+p.w,w=-B.z+B.w;if(G>=0&&I>=0&&H>=0&&w>=0)return true;else if(G<0&&I<0||H<0&&w<0)return false;else{if(G<0)P=Math.max(P,G/(G-I));else if(I<0)v=Math.min(v,G/(G-I));if(H<0)P=Math.max(P,H/(H-w));else if(w<0)v=Math.min(v,H/(H-w));if(v<P)return false;else{p.lerpSelf(B,P);B.lerpSelf(p,1-v);return true}}}var e,f,g=[],i,k,d,j=[],l,q,F=[],o,A,D=[],E=new THREE.Vector4,N=new THREE.Vector4,r=new THREE.Matrix4,
  102. O=new THREE.Matrix4,m=[],h=new THREE.Vector4,n=new THREE.Vector4,C;this.projectObjects=function(p,B,P){var v=[],G,I;f=0;r.multiply(B.projectionMatrix,B.matrix);m[0]=new THREE.Vector4(r.n41-r.n11,r.n42-r.n12,r.n43-r.n13,r.n44-r.n14);m[1]=new THREE.Vector4(r.n41+r.n11,r.n42+r.n12,r.n43+r.n13,r.n44+r.n14);m[2]=new THREE.Vector4(r.n41+r.n21,r.n42+r.n22,r.n43+r.n23,r.n44+r.n24);m[3]=new THREE.Vector4(r.n41-r.n21,r.n42-r.n22,r.n43-r.n23,r.n44-r.n24);m[4]=new THREE.Vector4(r.n41-r.n31,r.n42-r.n32,r.n43-
  103. r.n33,r.n44-r.n34);m[5]=new THREE.Vector4(r.n41+r.n31,r.n42+r.n32,r.n43+r.n33,r.n44+r.n34);B=0;for(G=m.length;B<G;B++){I=m[B];I.divideScalar(Math.sqrt(I.x*I.x+I.y*I.y+I.z*I.z))}G=p.objects;p=0;for(B=G.length;p<B;p++){I=G[p];var H;if(!(H=!I.visible)){if(H=I instanceof THREE.Mesh){a:{H=void 0;for(var w=I.position,R=-I.geometry.boundingSphere.radius*Math.max(I.scale.x,Math.max(I.scale.y,I.scale.z)),L=0;L<6;L++){H=m[L].x*w.x+m[L].y*w.y+m[L].z*w.z+m[L].w;if(H<=R){H=false;break a}}H=true}H=!H}H=H}if(!H){e=
  104. g[f]=g[f]||new THREE.RenderableObject;E.copy(I.position);r.multiplyVector3(E);e.object=I;e.z=E.z;v.push(e);f++}}P&&v.sort(a);return v};this.projectScene=function(p,B,P){var v=[],G=B.near,I=B.far,H,w,R,L,X,Z,S,ga,$,U,W,ea,aa,J,V,Y;d=q=A=0;B.autoUpdateMatrix&&B.updateMatrix();r.multiply(B.projectionMatrix,B.matrix);Z=this.projectObjects(p,B,true);p=0;for(H=Z.length;p<H;p++){S=Z[p].object;if(S.visible){S.autoUpdateMatrix&&S.updateMatrix();ga=S.matrix;$=S.rotationMatrix;U=S.materials;W=S.overdraw;if(S instanceof
  105. THREE.Mesh){ea=S.geometry;aa=ea.vertices;w=0;for(R=aa.length;w<R;w++){J=aa[w];J.positionWorld.copy(J.position);ga.multiplyVector3(J.positionWorld);L=J.positionScreen;L.copy(J.positionWorld);r.multiplyVector4(L);L.x/=L.w;L.y/=L.w;J.__visible=L.z>G&&L.z<I}ea=ea.faces;w=0;for(R=ea.length;w<R;w++){J=ea[w];if(J instanceof THREE.Face3){L=aa[J.a];X=aa[J.b];V=aa[J.c];if(L.__visible&&X.__visible&&V.__visible)if(S.doubleSided||S.flipSided!=(V.positionScreen.x-L.positionScreen.x)*(X.positionScreen.y-L.positionScreen.y)-
  106. (V.positionScreen.y-L.positionScreen.y)*(X.positionScreen.x-L.positionScreen.x)<0){i=j[d]=j[d]||new THREE.RenderableFace3;i.v1.positionWorld.copy(L.positionWorld);i.v2.positionWorld.copy(X.positionWorld);i.v3.positionWorld.copy(V.positionWorld);i.v1.positionScreen.copy(L.positionScreen);i.v2.positionScreen.copy(X.positionScreen);i.v3.positionScreen.copy(V.positionScreen);i.normalWorld.copy(J.normal);$.multiplyVector3(i.normalWorld);i.centroidWorld.copy(J.centroid);ga.multiplyVector3(i.centroidWorld);
  107. i.centroidScreen.copy(i.centroidWorld);r.multiplyVector3(i.centroidScreen);V=J.vertexNormals;C=i.vertexNormalsWorld;L=0;for(X=V.length;L<X;L++){Y=C[L]=C[L]||new THREE.Vector3;Y.copy(V[L]);$.multiplyVector3(Y)}i.z=i.centroidScreen.z;i.meshMaterials=U;i.faceMaterials=J.materials;i.overdraw=W;if(S.geometry.uvs[w]){i.uvs[0]=S.geometry.uvs[w][0];i.uvs[1]=S.geometry.uvs[w][1];i.uvs[2]=S.geometry.uvs[w][2]}v.push(i);d++}}else if(J instanceof THREE.Face4){L=aa[J.a];X=aa[J.b];V=aa[J.c];Y=aa[J.d];if(L.__visible&&
  108. X.__visible&&V.__visible&&Y.__visible)if(S.doubleSided||S.flipSided!=((Y.positionScreen.x-L.positionScreen.x)*(X.positionScreen.y-L.positionScreen.y)-(Y.positionScreen.y-L.positionScreen.y)*(X.positionScreen.x-L.positionScreen.x)<0||(X.positionScreen.x-V.positionScreen.x)*(Y.positionScreen.y-V.positionScreen.y)-(X.positionScreen.y-V.positionScreen.y)*(Y.positionScreen.x-V.positionScreen.x)<0)){i=j[d]=j[d]||new THREE.RenderableFace3;i.v1.positionWorld.copy(L.positionWorld);i.v2.positionWorld.copy(X.positionWorld);
  109. i.v3.positionWorld.copy(Y.positionWorld);i.v1.positionScreen.copy(L.positionScreen);i.v2.positionScreen.copy(X.positionScreen);i.v3.positionScreen.copy(Y.positionScreen);i.normalWorld.copy(J.normal);$.multiplyVector3(i.normalWorld);i.centroidWorld.copy(J.centroid);ga.multiplyVector3(i.centroidWorld);i.centroidScreen.copy(i.centroidWorld);r.multiplyVector3(i.centroidScreen);i.z=i.centroidScreen.z;i.meshMaterials=U;i.faceMaterials=J.materials;i.overdraw=W;if(S.geometry.uvs[w]){i.uvs[0]=S.geometry.uvs[w][0];
  110. i.uvs[1]=S.geometry.uvs[w][1];i.uvs[2]=S.geometry.uvs[w][3]}v.push(i);d++;k=j[d]=j[d]||new THREE.RenderableFace3;k.v1.positionWorld.copy(X.positionWorld);k.v2.positionWorld.copy(V.positionWorld);k.v3.positionWorld.copy(Y.positionWorld);k.v1.positionScreen.copy(X.positionScreen);k.v2.positionScreen.copy(V.positionScreen);k.v3.positionScreen.copy(Y.positionScreen);k.normalWorld.copy(i.normalWorld);k.centroidWorld.copy(i.centroidWorld);k.centroidScreen.copy(i.centroidScreen);k.z=k.centroidScreen.z;k.meshMaterials=
  111. U;k.faceMaterials=J.materials;k.overdraw=W;if(S.geometry.uvs[w]){k.uvs[0]=S.geometry.uvs[w][1];k.uvs[1]=S.geometry.uvs[w][2];k.uvs[2]=S.geometry.uvs[w][3]}v.push(k);d++}}}}else if(S instanceof THREE.Line){O.multiply(r,ga);aa=S.geometry.vertices;J=aa[0];J.positionScreen.copy(J.position);O.multiplyVector4(J.positionScreen);w=1;for(R=aa.length;w<R;w++){L=aa[w];L.positionScreen.copy(L.position);O.multiplyVector4(L.positionScreen);X=aa[w-1];h.copy(L.positionScreen);n.copy(X.positionScreen);if(b(h,n)){h.multiplyScalar(1/
  112. h.w);n.multiplyScalar(1/n.w);l=F[q]=F[q]||new THREE.RenderableLine;l.v1.positionScreen.copy(h);l.v2.positionScreen.copy(n);l.z=Math.max(h.z,n.z);l.materials=S.materials;v.push(l);q++}}}else if(S instanceof THREE.Particle){N.set(S.position.x,S.position.y,S.position.z,1);r.multiplyVector4(N);N.z/=N.w;if(N.z>0&&N.z<1){o=D[A]=D[A]||new THREE.RenderableParticle;o.x=N.x/N.w;o.y=N.y/N.w;o.z=N.z;o.rotation=S.rotation.z;o.scale.x=S.scale.x*Math.abs(o.x-(N.x+B.projectionMatrix.n11)/(N.w+B.projectionMatrix.n14));
  113. o.scale.y=S.scale.y*Math.abs(o.y-(N.y+B.projectionMatrix.n22)/(N.w+B.projectionMatrix.n24));o.materials=S.materials;v.push(o);A++}}}}P&&v.sort(a);return v};this.unprojectVector=function(p,B){var P=new THREE.Matrix4;P.multiply(THREE.Matrix4.makeInvert(B.matrix),THREE.Matrix4.makeInvert(B.projectionMatrix));P.multiplyVector3(p);return p}};
  114. THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,e,f,g,i;this.domElement=document.createElement("div");this.setSize=function(k,d){e=k;f=d;g=e/2;i=f/2};this.render=function(k,d){var j,l,q,F,o,A,D,E;a=b.projectScene(k,d);j=0;for(l=a.length;j<l;j++){o=a[j];if(o instanceof THREE.RenderableParticle){D=o.x*g+g;E=o.y*i+i;q=0;for(F=o.material.length;q<F;q++){A=o.material[q];if(A instanceof THREE.ParticleDOMMaterial){A=A.domElement;A.style.left=D+"px";A.style.top=E+"px"}}}}}};
  115. THREE.CanvasRenderer=function(){function a(pa){if(o!=pa)l.globalAlpha=o=pa}function b(pa){if(A!=pa){switch(pa){case THREE.NormalBlending:l.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:l.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:l.globalCompositeOperation="darker"}A=pa}}var e=null,f=new THREE.Projector,g=document.createElement("canvas"),i,k,d,j,l=g.getContext("2d"),q=null,F=null,o=1,A=0,D=null,E=null,N=1,r,O,m,h,n,C,p,B,P,v=new THREE.Color,
  116. G=new THREE.Color,I=new THREE.Color,H=new THREE.Color,w=new THREE.Color,R,L,X,Z,S,ga,$,U,W,ea=new THREE.Rectangle,aa=new THREE.Rectangle,J=new THREE.Rectangle,V=false,Y=new THREE.Color,la=new THREE.Color,ka=new THREE.Color,u=new THREE.Color,M=Math.PI*2,K=new THREE.Vector3,ba,fa,ja,ma,ta,va,Ba=16;ba=document.createElement("canvas");ba.width=ba.height=2;fa=ba.getContext("2d");fa.fillStyle="rgba(0,0,0,1)";fa.fillRect(0,0,2,2);ja=fa.getImageData(0,0,2,2);ma=ja.data;ta=document.createElement("canvas");
  117. ta.width=ta.height=Ba;va=ta.getContext("2d");va.translate(-Ba/2,-Ba/2);va.scale(Ba,Ba);Ba--;this.domElement=g;this.sortElements=this.sortObjects=this.autoClear=true;this.setSize=function(pa,za){i=pa;k=za;d=i/2;j=k/2;g.width=i;g.height=k;ea.set(-d,-j,d,j);o=1;A=0;E=D=null;N=1};this.setClearColor=function(pa,za){q=pa!==null?new THREE.Color(pa):null;F=za;aa.set(-d,-j,d,j);l.setTransform(1,0,0,-1,d,j);this.clear()};this.clear=function(){if(!aa.isEmpty()){aa.inflate(1);aa.minSelf(ea);if(q!==null){b(THREE.NormalBlending);
  118. a(1);l.fillStyle="rgba("+Math.floor(q.r*255)+","+Math.floor(q.g*255)+","+Math.floor(q.b*255)+","+F+")";l.fillRect(aa.getX(),aa.getY(),aa.getWidth(),aa.getHeight())}else l.clearRect(aa.getX(),aa.getY(),aa.getWidth(),aa.getHeight());aa.empty()}};this.render=function(pa,za){function Sa(Q){var ha,da,T,ca=Q.lights;la.setRGB(0,0,0);ka.setRGB(0,0,0);u.setRGB(0,0,0);Q=0;for(ha=ca.length;Q<ha;Q++){da=ca[Q];T=da.color;if(da instanceof THREE.AmbientLight){la.r+=T.r;la.g+=T.g;la.b+=T.b}else if(da instanceof THREE.DirectionalLight){ka.r+=
  119. T.r;ka.g+=T.g;ka.b+=T.b}else if(da instanceof THREE.PointLight){u.r+=T.r;u.g+=T.g;u.b+=T.b}}}function Ga(Q,ha,da,T){var ca,ia,oa,qa,ra=Q.lights;Q=0;for(ca=ra.length;Q<ca;Q++){ia=ra[Q];oa=ia.color;qa=ia.intensity;if(ia instanceof THREE.DirectionalLight){ia=da.dot(ia.position)*qa;if(ia>0){T.r+=oa.r*ia;T.g+=oa.g*ia;T.b+=oa.b*ia}}else if(ia instanceof THREE.PointLight){K.sub(ia.position,ha);K.normalize();ia=da.dot(K)*qa;if(ia>0){T.r+=oa.r*ia;T.g+=oa.g*ia;T.b+=oa.b*ia}}}}function Ta(Q,ha,da){if(da.opacity!=
  120. 0){a(da.opacity);b(da.blending);var T,ca,ia,oa,qa,ra;if(da instanceof THREE.ParticleBasicMaterial){if(da.map){oa=da.map;qa=oa.width>>1;ra=oa.height>>1;ca=ha.scale.x*d;ia=ha.scale.y*j;da=ca*qa;T=ia*ra;J.set(Q.x-da,Q.y-T,Q.x+da,Q.y+T);if(ea.instersects(J)){l.save();l.translate(Q.x,Q.y);l.rotate(-ha.rotation);l.scale(ca,-ia);l.translate(-qa,-ra);l.drawImage(oa,0,0);l.restore()}}}else if(da instanceof THREE.ParticleCircleMaterial){if(V){Y.r=la.r+ka.r+u.r;Y.g=la.g+ka.g+u.g;Y.b=la.b+ka.b+u.b;v.r=da.color.r*
  121. Y.r;v.g=da.color.g*Y.g;v.b=da.color.b*Y.b;v.updateStyleString()}else v.__styleString=da.color.__styleString;da=ha.scale.x*d;T=ha.scale.y*j;J.set(Q.x-da,Q.y-T,Q.x+da,Q.y+T);if(ea.instersects(J)){ca=v.__styleString;if(E!=ca)l.fillStyle=E=ca;l.save();l.translate(Q.x,Q.y);l.rotate(-ha.rotation);l.scale(da,T);l.beginPath();l.arc(0,0,1,0,M,true);l.closePath();l.fill();l.restore()}}}}function Ua(Q,ha,da,T){if(T.opacity!=0){a(T.opacity);b(T.blending);l.beginPath();l.moveTo(Q.positionScreen.x,Q.positionScreen.y);
  122. l.lineTo(ha.positionScreen.x,ha.positionScreen.y);l.closePath();if(T instanceof THREE.LineBasicMaterial){v.__styleString=T.color.__styleString;Q=T.linewidth;if(N!=Q)l.lineWidth=N=Q;Q=v.__styleString;if(D!=Q)l.strokeStyle=D=Q;l.stroke();J.inflate(T.linewidth*2)}}}function Oa(Q,ha,da,T,ca,ia){if(ca.opacity!=0){a(ca.opacity);b(ca.blending);h=Q.positionScreen.x;n=Q.positionScreen.y;C=ha.positionScreen.x;p=ha.positionScreen.y;B=da.positionScreen.x;P=da.positionScreen.y;l.beginPath();l.moveTo(h,n);l.lineTo(C,
  123. p);l.lineTo(B,P);l.lineTo(h,n);l.closePath();if(ca instanceof THREE.MeshBasicMaterial)if(ca.map)ca.map.image.loaded&&ca.map.mapping instanceof THREE.UVMapping&&Da(h,n,C,p,B,P,ca.map.image,T.uvs[0].u,T.uvs[0].v,T.uvs[1].u,T.uvs[1].v,T.uvs[2].u,T.uvs[2].v);else if(ca.env_map){if(ca.env_map.image.loaded)if(ca.env_map.mapping instanceof THREE.SphericalReflectionMapping){Q=za.matrix;K.copy(T.vertexNormalsWorld[0]);Z=(K.x*Q.n11+K.y*Q.n12+K.z*Q.n13)*0.5+0.5;S=-(K.x*Q.n21+K.y*Q.n22+K.z*Q.n23)*0.5+0.5;K.copy(T.vertexNormalsWorld[1]);
  124. ga=(K.x*Q.n11+K.y*Q.n12+K.z*Q.n13)*0.5+0.5;$=-(K.x*Q.n21+K.y*Q.n22+K.z*Q.n23)*0.5+0.5;K.copy(T.vertexNormalsWorld[2]);U=(K.x*Q.n11+K.y*Q.n12+K.z*Q.n13)*0.5+0.5;W=-(K.x*Q.n21+K.y*Q.n22+K.z*Q.n23)*0.5+0.5;Da(h,n,C,p,B,P,ca.env_map.image,Z,S,ga,$,U,W)}}else ca.wireframe?Ha(ca.color.__styleString,ca.wireframe_linewidth):Ia(ca.color.__styleString);else if(ca instanceof THREE.MeshLambertMaterial){if(ca.map&&!ca.wireframe){ca.map.mapping instanceof THREE.UVMapping&&Da(h,n,C,p,B,P,ca.map.image,T.uvs[0].u,
  125. T.uvs[0].v,T.uvs[1].u,T.uvs[1].v,T.uvs[2].u,T.uvs[2].v);b(THREE.SubtractiveBlending)}if(V)if(!ca.wireframe&&ca.shading==THREE.SmoothShading&&T.vertexNormalsWorld.length==3){G.r=I.r=H.r=la.r;G.g=I.g=H.g=la.g;G.b=I.b=H.b=la.b;Ga(ia,T.v1.positionWorld,T.vertexNormalsWorld[0],G);Ga(ia,T.v2.positionWorld,T.vertexNormalsWorld[1],I);Ga(ia,T.v3.positionWorld,T.vertexNormalsWorld[2],H);w.r=(I.r+H.r)*0.5;w.g=(I.g+H.g)*0.5;w.b=(I.b+H.b)*0.5;X=Pa(G,I,H,w);Da(h,n,C,p,B,P,X,0,0,1,0,0,1)}else{Y.r=la.r;Y.g=la.g;
  126. Y.b=la.b;Ga(ia,T.centroidWorld,T.normalWorld,Y);v.r=ca.color.r*Y.r;v.g=ca.color.g*Y.g;v.b=ca.color.b*Y.b;v.updateStyleString();ca.wireframe?Ha(v.__styleString,ca.wireframe_linewidth):Ia(v.__styleString)}else ca.wireframe?Ha(ca.color.__styleString,ca.wireframe_linewidth):Ia(ca.color.__styleString)}else if(ca instanceof THREE.MeshDepthMaterial){R=za.near;L=za.far;G.r=G.g=G.b=1-Ka(Q.positionScreen.z,R,L);I.r=I.g=I.b=1-Ka(ha.positionScreen.z,R,L);H.r=H.g=H.b=1-Ka(da.positionScreen.z,R,L);w.r=(I.r+H.r)*
  127. 0.5;w.g=(I.g+H.g)*0.5;w.b=(I.b+H.b)*0.5;X=Pa(G,I,H,w);Da(h,n,C,p,B,P,X,0,0,1,0,0,1)}else if(ca instanceof THREE.MeshNormalMaterial){v.r=La(T.normalWorld.x);v.g=La(T.normalWorld.y);v.b=La(T.normalWorld.z);v.updateStyleString();ca.wireframe?Ha(v.__styleString,ca.wireframe_linewidth):Ia(v.__styleString)}}}function Ha(Q,ha){if(D!=Q)l.strokeStyle=D=Q;if(N!=ha)l.lineWidth=N=ha;l.stroke();J.inflate(ha*2)}function Ia(Q){if(E!=Q)l.fillStyle=E=Q;l.fill()}function Da(Q,ha,da,T,ca,ia,oa,qa,ra,wa,sa,xa,Ea){var Aa,
  128. ya;Aa=oa.width-1;ya=oa.height-1;qa*=Aa;ra*=ya;wa*=Aa;sa*=ya;xa*=Aa;Ea*=ya;da-=Q;T-=ha;ca-=Q;ia-=ha;wa-=qa;sa-=ra;xa-=qa;Ea-=ra;ya=1/(wa*Ea-xa*sa);Aa=(Ea*da-sa*ca)*ya;sa=(Ea*T-sa*ia)*ya;da=(wa*ca-xa*da)*ya;T=(wa*ia-xa*T)*ya;Q=Q-Aa*qa-da*ra;ha=ha-sa*qa-T*ra;l.save();l.transform(Aa,sa,da,T,Q,ha);l.clip();l.drawImage(oa,0,0);l.restore()}function Pa(Q,ha,da,T){var ca=~~(Q.r*255),ia=~~(Q.g*255);Q=~~(Q.b*255);var oa=~~(ha.r*255),qa=~~(ha.g*255);ha=~~(ha.b*255);var ra=~~(da.r*255),wa=~~(da.g*255);da=~~(da.b*
  129. 255);var sa=~~(T.r*255),xa=~~(T.g*255);T=~~(T.b*255);ma[0]=ca<0?0:ca>255?255:ca;ma[1]=ia<0?0:ia>255?255:ia;ma[2]=Q<0?0:Q>255?255:Q;ma[4]=oa<0?0:oa>255?255:oa;ma[5]=qa<0?0:qa>255?255:qa;ma[6]=ha<0?0:ha>255?255:ha;ma[8]=ra<0?0:ra>255?255:ra;ma[9]=wa<0?0:wa>255?255:wa;ma[10]=da<0?0:da>255?255:da;ma[12]=sa<0?0:sa>255?255:sa;ma[13]=xa<0?0:xa>255?255:xa;ma[14]=T<0?0:T>255?255:T;fa.putImageData(ja,0,0);va.drawImage(ba,0,0);return ta}function Ka(Q,ha,da){Q=(Q-ha)/(da-ha);return Q*Q*(3-2*Q)}function La(Q){Q=
  130. (Q+1)*0.5;return Q<0?0:Q>1?1:Q}function Ma(Q,ha){var da=ha.x-Q.x,T=ha.y-Q.y,ca=1/Math.sqrt(da*da+T*T);da*=ca;T*=ca;ha.x+=da;ha.y+=T;Q.x-=da;Q.y-=T}var Ja,Qa,na,ua,Ca,Na,Ra,Fa;l.setTransform(1,0,0,-1,d,j);this.autoClear&&this.clear();e=f.projectScene(pa,za,this.sortElements);(V=pa.lights.length>0)&&Sa(pa);Ja=0;for(Qa=e.length;Ja<Qa;Ja++){na=e[Ja];J.empty();if(na instanceof THREE.RenderableParticle){r=na;r.x*=d;r.y*=j;ua=0;for(Ca=na.materials.length;ua<Ca;ua++)Ta(r,na,na.materials[ua],pa)}else if(na instanceof
  131. THREE.RenderableLine){r=na.v1;O=na.v2;r.positionScreen.x*=d;r.positionScreen.y*=j;O.positionScreen.x*=d;O.positionScreen.y*=j;J.addPoint(r.positionScreen.x,r.positionScreen.y);J.addPoint(O.positionScreen.x,O.positionScreen.y);if(ea.instersects(J)){ua=0;for(Ca=na.materials.length;ua<Ca;)Ua(r,O,na,na.materials[ua++],pa)}}else if(na instanceof THREE.RenderableFace3){r=na.v1;O=na.v2;m=na.v3;r.positionScreen.x*=d;r.positionScreen.y*=j;O.positionScreen.x*=d;O.positionScreen.y*=j;m.positionScreen.x*=d;m.positionScreen.y*=
  132. j;if(na.overdraw){Ma(r.positionScreen,O.positionScreen);Ma(O.positionScreen,m.positionScreen);Ma(m.positionScreen,r.positionScreen)}J.add3Points(r.positionScreen.x,r.positionScreen.y,O.positionScreen.x,O.positionScreen.y,m.positionScreen.x,m.positionScreen.y);if(ea.instersects(J)){ua=0;for(Ca=na.meshMaterials.length;ua<Ca;){Fa=na.meshMaterials[ua++];if(Fa instanceof THREE.MeshFaceMaterial){Na=0;for(Ra=na.faceMaterials.length;Na<Ra;)(Fa=na.faceMaterials[Na++])&&Oa(r,O,m,na,Fa,pa)}else Oa(r,O,m,na,
  133. Fa,pa)}}}aa.addRectangle(J)}l.setTransform(1,0,0,1,0,0)}};
  134. THREE.SVGRenderer=function(){function a(Z,S,ga){var $,U,W,ea;$=0;for(U=Z.lights.length;$<U;$++){W=Z.lights[$];if(W instanceof THREE.DirectionalLight){ea=S.normalWorld.dot(W.position)*W.intensity;if(ea>0){ga.r+=W.color.r*ea;ga.g+=W.color.g*ea;ga.b+=W.color.b*ea}}else if(W instanceof THREE.PointLight){P.sub(W.position,S.centroidWorld);P.normalize();ea=S.normalWorld.dot(P)*W.intensity;if(ea>0){ga.r+=W.color.r*ea;ga.g+=W.color.g*ea;ga.b+=W.color.b*ea}}}}function b(Z,S,ga,$,U,W){H=f(w++);H.setAttribute("d",
  135. "M "+Z.positionScreen.x+" "+Z.positionScreen.y+" L "+S.positionScreen.x+" "+S.positionScreen.y+" L "+ga.positionScreen.x+","+ga.positionScreen.y+"z");if(U instanceof THREE.MeshBasicMaterial)m.__styleString=U.color.__styleString;else if(U instanceof THREE.MeshLambertMaterial)if(O){h.r=n.r;h.g=n.g;h.b=n.b;a(W,$,h);m.r=U.color.r*h.r;m.g=U.color.g*h.g;m.b=U.color.b*h.b;m.updateStyleString()}else m.__styleString=U.color.__styleString;else if(U instanceof THREE.MeshDepthMaterial){B=1-U.__2near/(U.__farPlusNear-
  136. $.z*U.__farMinusNear);m.setRGB(B,B,B)}else U instanceof THREE.MeshNormalMaterial&&m.setRGB(g($.normalWorld.x),g($.normalWorld.y),g($.normalWorld.z));U.wireframe?H.setAttribute("style","fill: none; stroke: "+m.__styleString+"; stroke-width: "+U.wireframe_linewidth+"; stroke-opacity: "+U.opacity+"; stroke-linecap: "+U.wireframe_linecap+"; stroke-linejoin: "+U.wireframe_linejoin):H.setAttribute("style","fill: "+m.__styleString+"; fill-opacity: "+U.opacity);d.appendChild(H)}function e(Z,S,ga,$,U,W,ea){H=
  137. f(w++);H.setAttribute("d","M "+Z.positionScreen.x+" "+Z.positionScreen.y+" L "+S.positionScreen.x+" "+S.positionScreen.y+" L "+ga.positionScreen.x+","+ga.positionScreen.y+" L "+$.positionScreen.x+","+$.positionScreen.y+"z");if(W instanceof THREE.MeshBasicMaterial)m.__styleString=W.color.__styleString;else if(W instanceof THREE.MeshLambertMaterial)if(O){h.r=n.r;h.g=n.g;h.b=n.b;a(ea,U,h);m.r=W.color.r*h.r;m.g=W.color.g*h.g;m.b=W.color.b*h.b;m.updateStyleString()}else m.__styleString=W.color.__styleString;
  138. else if(W instanceof THREE.MeshDepthMaterial){B=1-W.__2near/(W.__farPlusNear-U.z*W.__farMinusNear);m.setRGB(B,B,B)}else W instanceof THREE.MeshNormalMaterial&&m.setRGB(g(U.normalWorld.x),g(U.normalWorld.y),g(U.normalWorld.z));W.wireframe?H.setAttribute("style","fill: none; stroke: "+m.__styleString+"; stroke-width: "+W.wireframe_linewidth+"; stroke-opacity: "+W.opacity+"; stroke-linecap: "+W.wireframe_linecap+"; stroke-linejoin: "+W.wireframe_linejoin):H.setAttribute("style","fill: "+m.__styleString+
  139. "; fill-opacity: "+W.opacity);d.appendChild(H)}function f(Z){if(v[Z]==null){v[Z]=document.createElementNS("http://www.w3.org/2000/svg","path");X==0&&v[Z].setAttribute("shape-rendering","crispEdges");return v[Z]}return v[Z]}function g(Z){return Z<0?Math.min((1+Z)*0.5,0.5):0.5+Math.min(Z*0.5,0.5)}var i=null,k=new THREE.Projector,d=document.createElementNS("http://www.w3.org/2000/svg","svg"),j,l,q,F,o,A,D,E,N=new THREE.Rectangle,r=new THREE.Rectangle,O=false,m=new THREE.Color(16777215),h=new THREE.Color(16777215),
  140. n=new THREE.Color(0),C=new THREE.Color(0),p=new THREE.Color(0),B,P=new THREE.Vector3,v=[],G=[],I=[],H,w,R,L,X=1;this.domElement=d;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(Z){switch(Z){case "high":X=1;break;case "low":X=0}};this.setSize=function(Z,S){j=Z;l=S;q=j/2;F=l/2;d.setAttribute("viewBox",-q+" "+-F+" "+j+" "+l);d.setAttribute("width",j);d.setAttribute("height",l);N.set(-q,-F,q,F)};this.clear=function(){for(;d.childNodes.length>0;)d.removeChild(d.childNodes[0])};
  141. this.render=function(Z,S){var ga,$,U,W,ea,aa,J,V;this.autoClear&&this.clear();i=k.projectScene(Z,S,this.sortElements);L=R=w=0;if(O=Z.lights.length>0){J=Z.lights;n.setRGB(0,0,0);C.setRGB(0,0,0);p.setRGB(0,0,0);ga=0;for($=J.length;ga<$;ga++){U=J[ga];W=U.color;if(U instanceof THREE.AmbientLight){n.r+=W.r;n.g+=W.g;n.b+=W.b}else if(U instanceof THREE.DirectionalLight){C.r+=W.r;C.g+=W.g;C.b+=W.b}else if(U instanceof THREE.PointLight){p.r+=W.r;p.g+=W.g;p.b+=W.b}}}ga=0;for($=i.length;ga<$;ga++){J=i[ga];r.empty();
  142. if(J instanceof THREE.RenderableParticle){o=J;o.x*=q;o.y*=-F;U=0;for(W=J.materials.length;U<W;U++)if(V=J.materials[U]){ea=o;aa=J;V=V;var Y=R++;if(G[Y]==null){G[Y]=document.createElementNS("http://www.w3.org/2000/svg","circle");X==0&&G[Y].setAttribute("shape-rendering","crispEdges")}H=G[Y];H.setAttribute("cx",ea.x);H.setAttribute("cy",ea.y);H.setAttribute("r",aa.scale.x*q);if(V instanceof THREE.ParticleCircleMaterial){if(O){h.r=n.r+C.r+p.r;h.g=n.g+C.g+p.g;h.b=n.b+C.b+p.b;m.r=V.color.r*h.r;m.g=V.color.g*
  143. h.g;m.b=V.color.b*h.b;m.updateStyleString()}else m=V.color;H.setAttribute("style","fill: "+m.__styleString)}d.appendChild(H)}}else if(J instanceof THREE.RenderableLine){o=J.v1;A=J.v2;o.positionScreen.x*=q;o.positionScreen.y*=-F;A.positionScreen.x*=q;A.positionScreen.y*=-F;r.addPoint(o.positionScreen.x,o.positionScreen.y);r.addPoint(A.positionScreen.x,A.positionScreen.y);if(N.instersects(r)){U=0;for(W=J.materials.length;U<W;)if(V=J.materials[U++]){ea=o;aa=A;V=V;Y=L++;if(I[Y]==null){I[Y]=document.createElementNS("http://www.w3.org/2000/svg",
  144. "line");X==0&&I[Y].setAttribute("shape-rendering","crispEdges")}H=I[Y];H.setAttribute("x1",ea.positionScreen.x);H.setAttribute("y1",ea.positionScreen.y);H.setAttribute("x2",aa.positionScreen.x);H.setAttribute("y2",aa.positionScreen.y);if(V instanceof THREE.LineBasicMaterial){m.__styleString=V.color.__styleString;H.setAttribute("style","fill: none; stroke: "+m.__styleString+"; stroke-width: "+V.linewidth+"; stroke-opacity: "+V.opacity+"; stroke-linecap: "+V.linecap+"; stroke-linejoin: "+V.linejoin);
  145. d.appendChild(H)}}}}else if(J instanceof THREE.RenderableFace3){o=J.v1;A=J.v2;D=J.v3;o.positionScreen.x*=q;o.positionScreen.y*=-F;A.positionScreen.x*=q;A.positionScreen.y*=-F;D.positionScreen.x*=q;D.positionScreen.y*=-F;r.addPoint(o.positionScreen.x,o.positionScreen.y);r.addPoint(A.positionScreen.x,A.positionScreen.y);r.addPoint(D.positionScreen.x,D.positionScreen.y);if(N.instersects(r)){U=0;for(W=J.meshMaterials.length;U<W;){V=J.meshMaterials[U++];if(V instanceof THREE.MeshFaceMaterial){ea=0;for(aa=
  146. J.faceMaterials.length;ea<aa;)(V=J.faceMaterials[ea++])&&b(o,A,D,J,V,Z)}else V&&b(o,A,D,J,V,Z)}}}else if(J instanceof THREE.RenderableFace4){o=J.v1;A=J.v2;D=J.v3;E=J.v4;o.positionScreen.x*=q;o.positionScreen.y*=-F;A.positionScreen.x*=q;A.positionScreen.y*=-F;D.positionScreen.x*=q;D.positionScreen.y*=-F;E.positionScreen.x*=q;E.positionScreen.y*=-F;r.addPoint(o.positionScreen.x,o.positionScreen.y);r.addPoint(A.positionScreen.x,A.positionScreen.y);r.addPoint(D.positionScreen.x,D.positionScreen.y);r.addPoint(E.positionScreen.x,
  147. E.positionScreen.y);if(N.instersects(r)){U=0;for(W=J.meshMaterials.length;U<W;){V=J.meshMaterials[U++];if(V instanceof THREE.MeshFaceMaterial){ea=0;for(aa=J.faceMaterials.length;ea<aa;)(V=J.faceMaterials[ea++])&&e(o,A,D,E,J,V,Z)}else V&&e(o,A,D,E,J,V,Z)}}}}}};
  148. THREE.WebGLRenderer=function(a){function b(h,n){h.fragment_shader=n.fragment_shader;h.vertex_shader=n.vertex_shader;h.uniforms=Uniforms.clone(n.uniforms)}function e(h,n){h.uniforms.color.value.setRGB(h.color.r*h.opacity,h.color.g*h.opacity,h.color.b*h.opacity);h.uniforms.opacity.value=h.opacity;h.uniforms.map.texture=h.map;h.uniforms.env_map.texture=h.env_map;h.uniforms.reflectivity.value=h.reflectivity;h.uniforms.refraction_ratio.value=h.refraction_ratio;h.uniforms.combine.value=h.combine;h.uniforms.useRefract.value=
  149. h.env_map&&h.env_map.mapping instanceof THREE.CubeRefractionMapping;if(n){h.uniforms.fogColor.value.setHex(n.color.hex);if(n instanceof THREE.Fog){h.uniforms.fogNear.value=n.near;h.uniforms.fogFar.value=n.far}else if(n instanceof THREE.FogExp2)h.uniforms.fogDensity.value=n.density}}function f(h,n){h.uniforms.color.value.setRGB(h.color.r*h.opacity,h.color.g*h.opacity,h.color.b*h.opacity);h.uniforms.opacity.value=h.opacity;if(n){h.uniforms.fogColor.value.setHex(n.color.hex);if(n instanceof THREE.Fog){h.uniforms.fogNear.value=
  150. n.near;h.uniforms.fogFar.value=n.far}else if(n instanceof THREE.FogExp2)h.uniforms.fogDensity.value=n.density}}function g(h,n){var C;if(h=="fragment")C=d.createShader(d.FRAGMENT_SHADER);else if(h=="vertex")C=d.createShader(d.VERTEX_SHADER);d.shaderSource(C,n);d.compileShader(C);if(!d.getShaderParameter(C,d.COMPILE_STATUS)){alert(d.getShaderInfoLog(C));return null}return C}function i(h){switch(h){case THREE.RepeatWrapping:return d.REPEAT;case THREE.ClampToEdgeWrapping:return d.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return d.MIRRORED_REPEAT;
  151. case THREE.NearestFilter:return d.NEAREST;case THREE.NearestMipMapNearestFilter:return d.NEAREST_MIPMAP_NEAREST;case THREE.NearestMipMapLinearFilter:return d.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return d.LINEAR;case THREE.LinearMipMapNearestFilter:return d.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return d.LINEAR_MIPMAP_LINEAR;case THREE.ByteType:return d.BYTE;case THREE.UnsignedByteType:return d.UNSIGNED_BYTE;case THREE.ShortType:return d.SHORT;case THREE.UnsignedShortType:return d.UNSIGNED_SHORT;
  152. case THREE.IntType:return d.INT;case THREE.UnsignedShortType:return d.UNSIGNED_INT;case THREE.FloatType:return d.FLOAT;case THREE.AlphaFormat:return d.ALPHA;case THREE.RGBFormat:return d.RGB;case THREE.RGBAFormat:return d.RGBA;case THREE.LuminanceFormat:return d.LUMINANCE;case THREE.LuminanceAlphaFormat:return d.LUMINANCE_ALPHA}return 0}var k=document.createElement("canvas"),d,j=null,l=null,q=new THREE.Matrix4,F,o=new Float32Array(16),A=new Float32Array(16),D=new Float32Array(16),E=new Float32Array(9),
  153. N=new Float32Array(16),r=true,O=new THREE.Color(0),m=0;if(a){if(a.antialias!==undefined)r=a.antialias;a.clearColor!==undefined&&O.setHex(a.clearColor);if(a.clearAlpha!==undefined)m=a.clearAlpha}this.domElement=k;this.autoClear=true;(function(h,n,C){try{d=k.getContext("experimental-webgl",{antialias:h})}catch(p){}if(!d){alert("WebGL not supported");throw"cannot create webgl context";}d.clearColor(0,0,0,1);d.clearDepth(1);d.enable(d.DEPTH_TEST);d.depthFunc(d.LEQUAL);d.frontFace(d.CCW);d.cullFace(d.BACK);
  154. d.enable(d.CULL_FACE);d.enable(d.BLEND);d.blendFunc(d.ONE,d.ONE_MINUS_SRC_ALPHA);d.clearColor(n.r,n.g,n.b,C)})(r,O,m);this.context=d;this.lights={ambient:[0,0,0],directional:{length:0,colors:[],positions:[]},point:{length:0,colors:[],positions:[]}};this.setSize=function(h,n){k.width=h;k.height=n;d.viewport(0,0,k.width,k.height)};this.setClearColor=function(h,n){var C=new THREE.Color(h);d.clearColor(C.r,C.g,C.b,n)};this.clear=function(){d.clear(d.COLOR_BUFFER_BIT|d.DEPTH_BUFFER_BIT)};this.setupLights=
  155. function(h,n){var C,p,B,P=0,v=0,G=0,I,H,w,R=this.lights,L=R.directional.colors,X=R.directional.positions,Z=R.point.colors,S=R.point.positions,ga=0,$=0;C=0;for(p=n.length;C<p;C++){B=n[C];I=B.color;H=B.position;w=B.intensity;if(B instanceof THREE.AmbientLight){P+=I.r;v+=I.g;G+=I.b}else if(B instanceof THREE.DirectionalLight){L[ga*3]=I.r*w;L[ga*3+1]=I.g*w;L[ga*3+2]=I.b*w;X[ga*3]=H.x;X[ga*3+1]=H.y;X[ga*3+2]=H.z;ga+=1}else if(B instanceof THREE.PointLight){Z[$*3]=I.r*w;Z[$*3+1]=I.g*w;Z[$*3+2]=I.b*w;S[$*
  156. 3]=H.x;S[$*3+1]=H.y;S[$*3+2]=H.z;$+=1}}R.point.length=$;R.directional.length=ga;R.ambient[0]=P;R.ambient[1]=v;R.ambient[2]=G};this.createParticleBuffers=function(h){h.__webGLVertexBuffer=d.createBuffer();h.__webGLFaceBuffer=d.createBuffer()};this.createLineBuffers=function(h){h.__webGLVertexBuffer=d.createBuffer();h.__webGLLineBuffer=d.createBuffer()};this.createMeshBuffers=function(h){h.__webGLVertexBuffer=d.createBuffer();h.__webGLNormalBuffer=d.createBuffer();h.__webGLTangentBuffer=d.createBuffer();
  157. h.__webGLUVBuffer=d.createBuffer();h.__webGLFaceBuffer=d.createBuffer();h.__webGLLineBuffer=d.createBuffer()};this.initLineBuffers=function(h){var n=h.vertices.length;h.__vertexArray=new Float32Array(n*3);h.__lineArray=new Uint16Array(n);h.__webGLLineCount=n};this.initMeshBuffers=function(h,n){var C,p,B=0,P=0,v=0,G=n.geometry.faces,I=h.faces;C=0;for(p=I.length;C<p;C++){fi=I[C];face=G[fi];if(face instanceof THREE.Face3){B+=3;P+=1;v+=3}else if(face instanceof THREE.Face4){B+=4;P+=2;v+=4}}h.__vertexArray=
  158. new Float32Array(B*3);h.__normalArray=new Float32Array(B*3);h.__tangentArray=new Float32Array(B*4);h.__uvArray=new Float32Array(B*2);h.__faceArray=new Uint16Array(P*3);h.__lineArray=new Uint16Array(v*2);B=false;C=0;for(p=n.materials.length;C<p;C++){G=n.materials[C];if(G instanceof THREE.MeshFaceMaterial){G=0;for(I=h.materials.length;G<I;G++)if(h.materials[G]&&h.materials[G].shading!=undefined&&h.materials[G].shading==THREE.SmoothShading){B=true;break}}else if(G&&G.shading!=undefined&&G.shading==THREE.SmoothShading){B=
  159. true;break}if(B)break}h.__needsSmoothNormals=B;h.__webGLFaceCount=P*3;h.__webGLLineCount=v*2};this.setMeshBuffers=function(h,n,C,p,B,P,v,G){var I,H,w,R,L,X,Z,S,ga,$=0,U=0,W=0,ea=0,aa=0,J=0,V=0,Y=h.__vertexArray,la=h.__uvArray,ka=h.__normalArray,u=h.__tangentArray,M=h.__faceArray,K=h.__lineArray,ba=h.__needsSmoothNormals,fa=n.geometry,ja=fa.vertices,ma=h.faces,ta=fa.faces,va=fa.uvs;n=0;for(I=ma.length;n<I;n++){H=ma[n];w=ta[H];H=va[H];R=w.vertexNormals;L=w.normal;if(w instanceof THREE.Face3){if(p){X=
  160. ja[w.a].position;Z=ja[w.b].position;S=ja[w.c].position;Y[U]=X.x;Y[U+1]=X.y;Y[U+2]=X.z;Y[U+3]=Z.x;Y[U+4]=Z.y;Y[U+5]=Z.z;Y[U+6]=S.x;Y[U+7]=S.y;Y[U+8]=S.z;U+=9}if(G&&fa.hasTangents){X=ja[w.a].tangent;Z=ja[w.b].tangent;S=ja[w.c].tangent;u[J]=X.x;u[J+1]=X.y;u[J+2]=X.z;u[J+3]=X.w;u[J+4]=Z.x;u[J+5]=Z.y;u[J+6]=Z.z;u[J+7]=Z.w;u[J+8]=S.x;u[J+9]=S.y;u[J+10]=S.z;u[J+11]=S.w;J+=12}if(v)if(R.length==3&&ba)for(w=0;w<3;w++){L=R[w];ka[aa]=L.x;ka[aa+1]=L.y;ka[aa+2]=L.z;aa+=3}else for(w=0;w<3;w++){ka[aa]=L.x;ka[aa+
  161. 1]=L.y;ka[aa+2]=L.z;aa+=3}if(P&&H)for(w=0;w<3;w++){R=H[w];la[W]=R.u;la[W+1]=R.v;W+=2}if(B){M[ea]=$;M[ea+1]=$+1;M[ea+2]=$+2;ea+=3;K[V]=$;K[V+1]=$+1;K[V+2]=$;K[V+3]=$+2;K[V+4]=$+1;K[V+5]=$+2;V+=6;$+=3}}else if(w instanceof THREE.Face4){if(p){X=ja[w.a].position;Z=ja[w.b].position;S=ja[w.c].position;ga=ja[w.d].position;Y[U]=X.x;Y[U+1]=X.y;Y[U+2]=X.z;Y[U+3]=Z.x;Y[U+4]=Z.y;Y[U+5]=Z.z;Y[U+6]=S.x;Y[U+7]=S.y;Y[U+8]=S.z;Y[U+9]=ga.x;Y[U+10]=ga.y;Y[U+11]=ga.z;U+=12}if(G&&fa.hasTangents){X=ja[w.a].tangent;Z=ja[w.b].tangent;
  162. S=ja[w.c].tangent;w=ja[w.d].tangent;u[J]=X.x;u[J+1]=X.y;u[J+2]=X.z;u[J+3]=X.w;u[J+4]=Z.x;u[J+5]=Z.y;u[J+6]=Z.z;u[J+7]=Z.w;u[J+8]=S.x;u[J+9]=S.y;u[J+10]=S.z;u[J+11]=S.w;u[J+12]=w.x;u[J+13]=w.y;u[J+14]=w.z;u[J+15]=w.w;J+=16}if(v)if(R.length==4&&ba)for(w=0;w<4;w++){L=R[w];ka[aa]=L.x;ka[aa+1]=L.y;ka[aa+2]=L.z;aa+=3}else for(w=0;w<4;w++){ka[aa]=L.x;ka[aa+1]=L.y;ka[aa+2]=L.z;aa+=3}if(P&&H)for(w=0;w<4;w++){R=H[w];la[W]=R.u;la[W+1]=R.v;W+=2}if(B){M[ea]=$;M[ea+1]=$+1;M[ea+2]=$+2;M[ea+3]=$;M[ea+4]=$+2;M[ea+
  163. 5]=$+3;ea+=6;K[V]=$;K[V+1]=$+1;K[V+2]=$;K[V+3]=$+3;K[V+4]=$+1;K[V+5]=$+2;K[V+6]=$+2;K[V+7]=$+3;V+=8;$+=4}}}if(p){d.bindBuffer(d.ARRAY_BUFFER,h.__webGLVertexBuffer);d.bufferData(d.ARRAY_BUFFER,Y,C)}if(v){d.bindBuffer(d.ARRAY_BUFFER,h.__webGLNormalBuffer);d.bufferData(d.ARRAY_BUFFER,ka,C)}if(G&&fa.hasTangents){d.bindBuffer(d.ARRAY_BUFFER,h.__webGLTangentBuffer);d.bufferData(d.ARRAY_BUFFER,u,C)}if(P&&W>0){d.bindBuffer(d.ARRAY_BUFFER,h.__webGLUVBuffer);d.bufferData(d.ARRAY_BUFFER,la,C)}if(B){d.bindBuffer(d.ELEMENT_ARRAY_BUFFER,
  164. h.__webGLFaceBuffer);d.bufferData(d.ELEMENT_ARRAY_BUFFER,M,C);d.bindBuffer(d.ELEMENT_ARRAY_BUFFER,h.__webGLLineBuffer);d.bufferData(d.ELEMENT_ARRAY_BUFFER,K,C)}};this.setLineBuffers=function(h,n,C,p){var B,P,v=h.vertices,G=v.length,I=h.__vertexArray,H=h.__lineArray;if(C)for(C=0;C<G;C++){B=v[C].position;P=C*3;I[P]=B.x;I[P+1]=B.y;I[P+2]=B.z}if(p)for(C=0;C<G;C++)H[C]=C;d.bindBuffer(d.ARRAY_BUFFER,h.__webGLVertexBuffer);d.bufferData(d.ARRAY_BUFFER,I,n);d.bindBuffer(d.ELEMENT_ARRAY_BUFFER,h.__webGLLineBuffer);
  165. d.bufferData(d.ELEMENT_ARRAY_BUFFER,H,n)};this.setParticleBuffers=function(){};this.renderBuffer=function(h,n,C,p,B,P){var v,G,I,H;if(!p.program){if(p instanceof THREE.MeshDepthMaterial){b(p,THREE.ShaderLib.depth);p.uniforms.mNear.value=h.near;p.uniforms.mFar.value=h.far}else if(p instanceof THREE.MeshNormalMaterial)b(p,THREE.ShaderLib.normal);else if(p instanceof THREE.MeshBasicMaterial){b(p,THREE.ShaderLib.basic);e(p,C)}else if(p instanceof THREE.MeshLambertMaterial){b(p,THREE.ShaderLib.lambert);
  166. e(p,C)}else if(p instanceof THREE.MeshPhongMaterial){b(p,THREE.ShaderLib.phong);e(p,C)}else if(p instanceof THREE.LineBasicMaterial){b(p,THREE.ShaderLib.basic);f(p,C)}var w,R,L;w=H=G=0;for(R=n.length;w<R;w++){L=n[w];L instanceof THREE.DirectionalLight&&H++;L instanceof THREE.PointLight&&G++}if(G+H<=4){w=H;G=G}else{w=Math.ceil(4*H/(G+H));G=4-w}G={directional:w,point:G};H={fog:C,map:p.map,env_map:p.env_map,maxDirLights:G.directional,maxPointLights:G.point};G=p.fragment_shader;w=p.vertex_shader;R=d.createProgram();
  167. L=["#ifdef GL_ES\nprecision highp float;\n#endif","#define MAX_DIR_LIGHTS "+H.maxDirLights,"#define MAX_POINT_LIGHTS "+H.maxPointLights,H.fog?"#define USE_FOG":"",H.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",H.map?"#define USE_MAP":"",H.env_map?"#define USE_ENVMAP":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");H=[d.getParameter(d.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+H.maxDirLights,"#define MAX_POINT_LIGHTS "+H.maxPointLights,
  168. H.map?"#define USE_MAP":"",H.env_map?"#define USE_ENVMAP":"","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");d.attachShader(R,g("fragment",L+G));d.attachShader(R,g("vertex",H+w));d.linkProgram(R);d.getProgramParameter(R,d.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+
  169. d.getProgramParameter(R,d.VALIDATE_STATUS)+", gl error ["+d.getError()+"]");R.uniforms={};R.attributes={};p.program=R;G=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(v in p.uniforms)G.push(v);v=p.program;w=0;for(R=G.length;w<R;w++){L=G[w];v.uniforms[L]=d.getUniformLocation(v,L)}v=p.program;G=["position","normal","uv","tangent"];w=0;for(R=G.length;w<R;w++){L=G[w];v.attributes[L]=d.getAttribLocation(v,L)}}v=p.program;if(v!=j){d.useProgram(v);
  170. j=v}this.loadCamera(v,h);this.loadMatrices(v);if(p instanceof THREE.MeshPhongMaterial||p instanceof THREE.MeshLambertMaterial){this.setupLights(v,n);h=this.lights;p.uniforms.enableLighting.value=h.directional.length+h.point.length;p.uniforms.ambientLightColor.value=h.ambient;p.uniforms.directionalLightColor.value=h.directional.colors;p.uniforms.directionalLightDirection.value=h.directional.positions;p.uniforms.pointLightColor.value=h.point.colors;p.uniforms.pointLightPosition.value=h.point.positions}if(p instanceof
  171. THREE.MeshBasicMaterial||p instanceof THREE.MeshLambertMaterial||p instanceof THREE.MeshPhongMaterial)e(p,C);p instanceof THREE.LineBasicMaterial&&f(p,C);if(p instanceof THREE.MeshPhongMaterial){p.uniforms.ambient.value.setRGB(p.ambient.r,p.ambient.g,p.ambient.b);p.uniforms.specular.value.setRGB(p.specular.r,p.specular.g,p.specular.b);p.uniforms.shininess.value=p.shininess}C=p.uniforms;for(I in C)if(w=v.uniforms[I]){n=C[I];G=n.type;h=n.value;if(G=="i")d.uniform1i(w,h);else if(G=="f")d.uniform1f(w,
  172. h);else if(G=="fv1")d.uniform1fv(w,h);else if(G=="fv")d.uniform3fv(w,h);else if(G=="v2")d.uniform2f(w,h.x,h.y);else if(G=="v3")d.uniform3f(w,h.x,h.y,h.z);else if(G=="c")d.uniform3f(w,h.r,h.g,h.b);else if(G=="t"){d.uniform1i(w,h);if(n=n.texture)if(n.image instanceof Array&&n.image.length==6){n=n;h=h;if(n.image.length==6){if(!n.image.__webGLTextureCube&&!n.image.__cubeMapInitialized&&n.image.loadCount==6){n.image.__webGLTextureCube=d.createTexture();d.bindTexture(d.TEXTURE_CUBE_MAP,n.image.__webGLTextureCube);
  173. d.texParameteri(d.TEXTURE_CUBE_MAP,d.TEXTURE_WRAP_S,d.CLAMP_TO_EDGE);d.texParameteri(d.TEXTURE_CUBE_MAP,d.TEXTURE_WRAP_T,d.CLAMP_TO_EDGE);d.texParameteri(d.TEXTURE_CUBE_MAP,d.TEXTURE_MAG_FILTER,d.LINEAR);d.texParameteri(d.TEXTURE_CUBE_MAP,d.TEXTURE_MIN_FILTER,d.LINEAR_MIPMAP_LINEAR);for(G=0;G<6;++G)d.texImage2D(d.TEXTURE_CUBE_MAP_POSITIVE_X+G,0,d.RGBA,d.RGBA,d.UNSIGNED_BYTE,n.image[G]);d.generateMipmap(d.TEXTURE_CUBE_MAP);d.bindTexture(d.TEXTURE_CUBE_MAP,null);n.image.__cubeMapInitialized=true}d.activeTexture(d.TEXTURE0+
  174. h);d.bindTexture(d.TEXTURE_CUBE_MAP,n.image.__webGLTextureCube)}}else{n=n;h=h;if(!n.__webGLTexture&&n.image.loaded){n.__webGLTexture=d.createTexture();d.bindTexture(d.TEXTURE_2D,n.__webGLTexture);d.texImage2D(d.TEXTURE_2D,0,d.RGBA,d.RGBA,d.UNSIGNED_BYTE,n.image);d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_S,i(n.wrap_s));d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_T,i(n.wrap_t));d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MAG_FILTER,i(n.mag_filter));d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MIN_FILTER,i(n.min_filter));
  175. d.generateMipmap(d.TEXTURE_2D);d.bindTexture(d.TEXTURE_2D,null)}d.activeTexture(d.TEXTURE0+h);d.bindTexture(d.TEXTURE_2D,n.__webGLTexture)}}}I=v.attributes;d.bindBuffer(d.ARRAY_BUFFER,B.__webGLVertexBuffer);d.vertexAttribPointer(I.position,3,d.FLOAT,false,0,0);d.enableVertexAttribArray(I.position);if(I.normal>=0){d.bindBuffer(d.ARRAY_BUFFER,B.__webGLNormalBuffer);d.vertexAttribPointer(I.normal,3,d.FLOAT,false,0,0);d.enableVertexAttribArray(I.normal)}if(I.tangent>=0){d.bindBuffer(d.ARRAY_BUFFER,B.__webGLTangentBuffer);
  176. d.vertexAttribPointer(I.tangent,4,d.FLOAT,false,0,0);d.enableVertexAttribArray(I.tangent)}if(I.uv>=0)if(B.__webGLUVBuffer){d.bindBuffer(d.ARRAY_BUFFER,B.__webGLUVBuffer);d.vertexAttribPointer(I.uv,2,d.FLOAT,false,0,0);d.enableVertexAttribArray(I.uv)}else d.disableVertexAttribArray(I.uv);if(p.wireframe||p instanceof THREE.LineBasicMaterial){I=p.wireframe_linewidth!==undefined?p.wireframe_linewidth:p.linewidth!==undefined?p.linewidth:1;p=p instanceof THREE.LineBasicMaterial&&P.type==THREE.LineStrip?
  177. d.LINE_STRIP:d.LINES;d.lineWidth(I);d.bindBuffer(d.ELEMENT_ARRAY_BUFFER,B.__webGLLineBuffer);d.drawElements(p,B.__webGLLineCount,d.UNSIGNED_SHORT,0)}else{d.bindBuffer(d.ELEMENT_ARRAY_BUFFER,B.__webGLFaceBuffer);d.drawElements(d.TRIANGLES,B.__webGLFaceCount,d.UNSIGNED_SHORT,0)}};this.renderPass=function(h,n,C,p,B,P,v){var G,I,H,w,R;H=0;for(w=p.materials.length;H<w;H++){G=p.materials[H];if(G instanceof THREE.MeshFaceMaterial){G=0;for(I=B.materials.length;G<I;G++)if((R=B.materials[G])&&R.blending==P&&
  178. R.opacity<1==v){this.setBlending(R.blending);this.renderBuffer(h,n,C,R,B,p)}}else if((R=G)&&R.blending==P&&R.opacity<1==v){this.setBlending(R.blending);this.renderBuffer(h,n,C,R,B,p)}}};this.render=function(h,n,C,p){var B,P,v,G=h.lights,I=h.fog;this.initWebGLObjects(h);p=p!==undefined?p:true;if(C&&!C.__webGLFramebuffer){C.__webGLFramebuffer=d.createFramebuffer();C.__webGLRenderbuffer=d.createRenderbuffer();C.__webGLTexture=d.createTexture();d.bindRenderbuffer(d.RENDERBUFFER,C.__webGLRenderbuffer);
  179. d.renderbufferStorage(d.RENDERBUFFER,d.DEPTH_COMPONENT16,C.width,C.height);d.bindTexture(d.TEXTURE_2D,C.__webGLTexture);d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_S,i(C.wrap_s));d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_T,i(C.wrap_t));d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MAG_FILTER,i(C.mag_filter));d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MIN_FILTER,i(C.min_filter));d.texImage2D(d.TEXTURE_2D,0,i(C.format),C.width,C.height,0,i(C.format),i(C.type),null);d.bindFramebuffer(d.FRAMEBUFFER,C.__webGLFramebuffer);
  180. d.framebufferTexture2D(d.FRAMEBUFFER,d.COLOR_ATTACHMENT0,d.TEXTURE_2D,C.__webGLTexture,0);d.framebufferRenderbuffer(d.FRAMEBUFFER,d.DEPTH_ATTACHMENT,d.RENDERBUFFER,C.__webGLRenderbuffer);d.bindTexture(d.TEXTURE_2D,null);d.bindRenderbuffer(d.RENDERBUFFER,null);d.bindFramebuffer(d.FRAMEBUFFER,null)}if(C){B=C.__webGLFramebuffer;v=C.width;P=C.height}else{B=null;v=k.width;P=k.height}if(B!=l){d.bindFramebuffer(d.FRAMEBUFFER,B);d.viewport(0,0,v,P);p&&d.clear(d.COLOR_BUFFER_BIT|d.DEPTH_BUFFER_BIT);l=B}this.autoClear&&
  181. this.clear();n.autoUpdateMatrix&&n.updateMatrix();o.set(n.matrix.flatten());D.set(n.projectionMatrix.flatten());p=0;for(B=h.__webGLObjects.length;p<B;p++){P=h.__webGLObjects[p];v=P.object;P=P.buffer;if(v.visible){this.setupMatrices(v,n);this.renderPass(n,G,I,v,P,THREE.NormalBlending,false)}}p=0;for(B=h.__webGLObjects.length;p<B;p++){P=h.__webGLObjects[p];v=P.object;P=P.buffer;if(v.visible){this.setupMatrices(v,n);if(v.doubleSided)d.disable(d.CULL_FACE);else{d.enable(d.CULL_FACE);v.flipSided?d.frontFace(d.CW):
  182. d.frontFace(d.CCW)}this.renderPass(n,G,I,v,P,THREE.AdditiveBlending,false);this.renderPass(n,G,I,v,P,THREE.SubtractiveBlending,false);this.renderPass(n,G,I,v,P,THREE.AdditiveBlending,true);this.renderPass(n,G,I,v,P,THREE.SubtractiveBlending,true);this.renderPass(n,G,I,v,P,THREE.NormalBlending,true)}}if(C&&C.min_filter!==THREE.NearestFilter&&C.min_filter!==THREE.LinearFilter){d.bindTexture(d.TEXTURE_2D,C.__webGLTexture);d.generateMipmap(d.TEXTURE_2D);d.bindTexture(d.TEXTURE_2D,null)}};this.initWebGLObjects=
  183. function(h){function n(H,w,R,L){if(H[w]==undefined){h.__webGLObjects.push({buffer:R,object:L});H[w]=1}}var C,p,B,P,v,G,I;if(!h.__webGLObjects){h.__webGLObjects=[];h.__webGLObjectsMap={}}C=0;for(p=h.objects.length;C<p;C++){B=h.objects[C];v=B.geometry;if(h.__webGLObjectsMap[B.id]==undefined)h.__webGLObjectsMap[B.id]={};I=h.__webGLObjectsMap[B.id];if(B instanceof THREE.Mesh){for(P in v.geometryChunks){G=v.geometryChunks[P];if(!G.__webGLVertexBuffer){this.createMeshBuffers(G);this.initMeshBuffers(G,B);
  184. v.__dirtyVertices=true;v.__dirtyElements=true;v.__dirtyUvs=true;v.__dirtyNormals=true;v.__dirtyTangents=true}if(v.__dirtyVertices||v.__dirtyElements||v.__dirtyUvs)this.setMeshBuffers(G,B,d.DYNAMIC_DRAW,v.__dirtyVertices,v.__dirtyElements,v.__dirtyUvs,v.__dirtyNormals,v.__dirtyTangents);n(I,P,G,B)}v.__dirtyVertices=false;v.__dirtyElements=false;v.__dirtyUvs=false;v.__dirtyNormals=false;v.__dirtyTangents=false}else if(B instanceof THREE.Line){if(!v.__webGLVertexBuffer){this.createLineBuffers(v);this.initLineBuffers(v);
  185. v.__dirtyVertices=true;v.__dirtyElements=true}v.__dirtyVertices&&this.setLineBuffers(v,d.DYNAMIC_DRAW,v.__dirtyVertices,v.__dirtyElements);n(I,0,v,B);v.__dirtyVertices=false;v.__dirtyElements=false}else if(B instanceof THREE.ParticleSystem){v.__webGLVertexBuffer||this.createParticleBuffers(v);n(I,0,v,B)}}};this.removeObject=function(h,n){var C,p;for(C=h.__webGLObjects.length-1;C>=0;C--){p=h.__webGLObjects[C].object;n==p&&h.__webGLObjects.splice(C,1)}};this.setupMatrices=function(h,n){h.autoUpdateMatrix&&
  186. h.updateMatrix();q.multiply(n.matrix,h.matrix);A.set(q.flatten());F=THREE.Matrix4.makeInvert3x3(q).transpose();E.set(F.m);N.set(h.matrix.flatten())};this.loadMatrices=function(h){d.uniformMatrix4fv(h.uniforms.viewMatrix,false,o);d.uniformMatrix4fv(h.uniforms.modelViewMatrix,false,A);d.uniformMatrix4fv(h.uniforms.projectionMatrix,false,D);d.uniformMatrix3fv(h.uniforms.normalMatrix,false,E);d.uniformMatrix4fv(h.uniforms.objectMatrix,false,N)};this.loadCamera=function(h,n){d.uniform3f(h.uniforms.cameraPosition,
  187. n.position.x,n.position.y,n.position.z)};this.setBlending=function(h){switch(h){case THREE.AdditiveBlending:d.blendEquation(d.FUNC_ADD);d.blendFunc(d.ONE,d.ONE);break;case THREE.SubtractiveBlending:d.blendFunc(d.DST_COLOR,d.ZERO);break;default:d.blendEquation(d.FUNC_ADD);d.blendFunc(d.ONE,d.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(h,n){if(h){!n||n=="ccw"?d.frontFace(d.CCW):d.frontFace(d.CW);if(h=="back")d.cullFace(d.BACK);else h=="front"?d.cullFace(d.FRONT):d.cullFace(d.FRONT_AND_BACK);
  188. d.enable(d.CULL_FACE)}else d.disable(d.CULL_FACE)};this.supportsVertexTextures=function(){return d.getParameter(d.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}};
  189. THREE.Snippets={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, 1.0 ), fogFactor );\n#endif",envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube env_map;\nuniform int combine;\n#endif",
  190. envmap_fragment:"#ifdef USE_ENVMAP\ncubeColor = textureCube( env_map, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = mix( gl_FragColor, cubeColor, reflectivity );\n} else {\ngl_FragColor = gl_FragColor * cubeColor;\n}\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refraction_ratio;\nuniform bool useRefract;\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nif ( useRefract ) {\nvReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refraction_ratio );\n} else {\nvReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );\n}\n#endif",
  191. map_pars_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\n#endif",map_fragment:"#ifdef USE_MAP\nmapColor = texture2D( map, vUv );\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv;\n#endif",lights_pars_vertex:"uniform bool enableLighting;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n#ifdef PHONG\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\n#endif",
  192. lights_vertex:"if ( !enableLighting ) {\nvLightWeighting = vec3( 1.0 );\n} else {\nvLightWeighting = ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nfloat directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );\nvLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;\n}\n#endif\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 pointLightVector = normalize( lPosition.xyz - mvPosition.xyz );\nfloat pointLightWeighting = max( dot( transformedNormal, pointLightVector ), 0.0 );\nvLightWeighting += pointLightColor[ i ] * pointLightWeighting;\n#ifdef PHONG\nvPointLightVector[ i ] = pointLightVector;\n#endif\n}\n#endif\n}",
  193. lights_pars_fragment:"#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\nvarying vec3 vViewPosition;\nvarying vec3 vNormal;",lights_fragment:"vec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );\nvec4 mSpecular = vec4( specular, opacity );\n#if MAX_POINT_LIGHTS > 0\nvec4 pointDiffuse = vec4( 0.0 );\nvec4 pointSpecular = vec4( 0.0 );\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec3 pointVector = normalize( vPointLightVector[ i ] );\nvec3 pointHalfVector = normalize( vPointLightVector[ i ] + 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, shininess );\npointDiffuse += mColor * pointDiffuseWeight;\npointSpecular += mSpecular * pointSpecularWeight;\n}\n#endif\n#if MAX_DIR_LIGHTS > 0\nvec4 dirDiffuse = vec4( 0.0 );\nvec4 dirSpecular = vec4( 0.0 );\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 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, shininess );\ndirDiffuse += mColor * dirDiffuseWeight;\ndirSpecular += mSpecular * dirSpecularWeight;\n}\n#endif\nvec4 totalLight = vec4( ambient, opacity );\n#if MAX_DIR_LIGHTS > 0\ntotalLight += dirDiffuse + dirSpecular;\n#endif\n#if MAX_POINT_LIGHTS > 0\ntotalLight += pointDiffuse + pointSpecular;\n#endif"};
  194. THREE.UniformsLib={common:{color:{type:"c",value:new THREE.Color(15658734)},opacity:{type:"f",value:1},map:{type:"t",value:0,texture:null},env_map:{type:"t",value:1,texture:null},useRefract:{type:"i",value:0},reflectivity:{type:"f",value:1},refraction_ratio:{type:"f",value:0.98},combine:{type:"i",value:0},fogDensity:{type:"f",value:2.5E-4},fogNear:{type:"f",value:1},fogFar:{type:"f",value:2E3},fogColor:{type:"c",value:new THREE.Color(16777215)}},lights:{enableLighting:{type:"i",value:1},ambientLightColor:{type:"fv",
  195. value:[]},directionalLightDirection:{type:"fv",value:[]},directionalLightColor:{type:"fv",value:[]},pointLightPosition:{type:"fv",value:[]},pointLightColor:{type:"fv",value:[]}}};
  196. THREE.ShaderLib={depth:{uniforms:{mNear:{type:"f",value:1},mFar:{type:"f",value:2E3}},fragment_shader:"uniform float mNear;\nuniform float mFar;\nvoid main() {\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\nfloat color = 1.0 - smoothstep( mNear, mFar, depth );\ngl_FragColor = vec4( vec3( color ), 1.0 );\n}",vertex_shader:"void main() {\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}"},normal:{uniforms:{},fragment_shader:"varying vec3 vNormal;\nvoid main() {\ngl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, 1.0 );\n}",
  197. vertex_shader:"varying vec3 vNormal;\nvoid main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalize( normalMatrix * normal );\ngl_Position = projectionMatrix * mvPosition;\n}"},basic:{uniforms:THREE.UniformsLib.common,fragment_shader:["uniform vec3 color;\nuniform float opacity;",THREE.Snippets.map_pars_fragment,THREE.Snippets.envmap_pars_fragment,THREE.Snippets.fog_pars_fragment,"void main() {\nvec4 mColor = vec4( color, opacity );\nvec4 mapColor = vec4( 1.0 );\nvec4 cubeColor = vec4( 1.0 );",
  198. THREE.Snippets.map_fragment,"gl_FragColor = mColor * mapColor;",THREE.Snippets.envmap_fragment,THREE.Snippets.fog_fragment,"}"].join("\n"),vertex_shader:[THREE.Snippets.map_pars_vertex,THREE.Snippets.envmap_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.Snippets.map_vertex,THREE.Snippets.envmap_vertex,"gl_Position = projectionMatrix * mvPosition;\n}"].join("\n")},lambert:{uniforms:Uniforms.merge([THREE.UniformsLib.common,THREE.UniformsLib.lights]),fragment_shader:["uniform vec3 color;\nuniform float opacity;\nvarying vec3 vLightWeighting;",
  199. THREE.Snippets.map_pars_fragment,THREE.Snippets.envmap_pars_fragment,THREE.Snippets.fog_pars_fragment,"void main() {\nvec4 mColor = vec4( color, opacity );\nvec4 mapColor = vec4( 1.0 );\nvec4 cubeColor = vec4( 1.0 );",THREE.Snippets.map_fragment,"gl_FragColor = mColor * mapColor * vec4( vLightWeighting, 1.0 );",THREE.Snippets.envmap_fragment,THREE.Snippets.fog_fragment,"}"].join("\n"),vertex_shader:["varying vec3 vLightWeighting;",THREE.Snippets.map_pars_vertex,THREE.Snippets.envmap_pars_vertex,
  200. THREE.Snippets.lights_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.Snippets.map_vertex,THREE.Snippets.envmap_vertex,"vec3 transformedNormal = normalize( normalMatrix * normal );",THREE.Snippets.lights_vertex,"gl_Position = projectionMatrix * mvPosition;\n}"].join("\n")},phong:{uniforms:Uniforms.merge([THREE.UniformsLib.common,THREE.UniformsLib.lights,{ambient:{type:"c",value:new THREE.Color(328965)},specular:{type:"c",value:new THREE.Color(1118481)},
  201. shininess:{type:"f",value:30}}]),fragment_shader:["uniform vec3 color;\nuniform float opacity;\nuniform vec3 ambient;\nuniform vec3 specular;\nuniform float shininess;\nvarying vec3 vLightWeighting;",THREE.Snippets.map_pars_fragment,THREE.Snippets.envmap_pars_fragment,THREE.Snippets.fog_pars_fragment,THREE.Snippets.lights_pars_fragment,"void main() {\nvec4 mColor = vec4( color, opacity );\nvec4 mapColor = vec4( 1.0 );\nvec4 cubeColor = vec4( 1.0 );",THREE.Snippets.map_fragment,THREE.Snippets.lights_fragment,
  202. "gl_FragColor = mapColor * totalLight * vec4( vLightWeighting, 1.0 );",THREE.Snippets.envmap_fragment,THREE.Snippets.fog_fragment,"}"].join("\n"),vertex_shader:["#define PHONG\nvarying vec3 vLightWeighting;\nvarying vec3 vViewPosition;\nvarying vec3 vNormal;",THREE.Snippets.map_pars_vertex,THREE.Snippets.envmap_pars_vertex,THREE.Snippets.lights_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.Snippets.map_vertex,THREE.Snippets.envmap_vertex,"#ifndef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\n#endif\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 transformedNormal = normalize( normalMatrix * normal );\nvNormal = transformedNormal;",
  203. THREE.Snippets.lights_vertex,"gl_Position = projectionMatrix * mvPosition;\n}"].join("\n")}};THREE.RenderableObject=function(){this.z=this.object=null};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.faceMaterials=this.meshMaterials=null;this.overdraw=false;this.uvs=[null,null,null]};
  204. THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.materials=null};THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.materials=null};
  205. var GeometryUtils={merge:function(a,b){var e=b instanceof THREE.Mesh,f=a.vertices.length,g=e?b.geometry:b,i=a.vertices,k=g.vertices,d=a.faces,j=g.faces,l=a.uvs;g=g.uvs;e&&b.autoUpdateMatrix&&b.updateMatrix();for(var q=0,F=k.length;q<F;q++){var o=new THREE.Vertex(k[q].position.clone());e&&b.matrix.multiplyVector3(o.position);i.push(o)}q=0;for(F=j.length;q<F;q++){k=j[q];var A,D=k.vertexNormals;if(k instanceof THREE.Face3)A=new THREE.Face3(k.a+f,k.b+f,k.c+f);else if(k instanceof THREE.Face4)A=new THREE.Face4(k.a+
  206. f,k.b+f,k.c+f,k.d+f);A.centroid.copy(k.centroid);A.normal.copy(k.normal);e=0;for(i=D.length;e<i;e++){o=D[e];A.vertexNormals.push(o.clone())}A.materials=k.materials.slice();d.push(A)}q=0;for(F=g.length;q<F;q++){f=g[q];d=[];e=0;for(i=f.length;e<i;e++)d.push(new THREE.UV(f[e].u,f[e].v));l.push(d)}}},ImageUtils={loadTexture:function(a,b){var e=new Image;e.onload=function(){this.loaded=true};e.src=a;return new THREE.Texture(e,b)},loadArray:function(a){var b,e,f=[];b=f.loadCount=0;for(e=a.length;b<e;++b){f[b]=
  207. new Image;f[b].loaded=0;f[b].onload=function(){f.loadCount+=1;this.loaded=true};f[b].src=a[b]}return f}},SceneUtils={addMesh:function(a,b,e,f,g,i,k,d,j,l){b=new THREE.Mesh(b,l);b.scale.x=b.scale.y=b.scale.z=e;b.position.x=f;b.position.y=g;b.position.z=i;b.rotation.x=k;b.rotation.y=d;b.rotation.z=j;a.addObject(b);return b},addPanoramaCubeWebGL:function(a,b,e){var f=ShaderUtils.lib.cube;f.uniforms.tCube.texture=e;e=new THREE.MeshShaderMaterial({fragment_shader:f.fragment_shader,vertex_shader:f.vertex_shader,
  208. uniforms:f.uniforms});b=new THREE.Mesh(new Cube(b,b,b,1,1,null,true),e);a.addObject(b);return b},addPanoramaCube:function(a,b,e){var f=[];f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[0])}));f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[1])}));f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[2])}));f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[3])}));f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[4])}));f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[5])}));
  209. b=new THREE.Mesh(new Cube(b,b,b,1,1,f,true),new THREE.MeshFaceMaterial);a.addObject(b);return b},addPanoramaCubePlanes:function(a,b,e){var f=b/2;b=new Plane(b,b);var g=Math.PI/2,i=Math.PI;SceneUtils.addMesh(a,b,1,0,0,-f,0,0,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(e[5])}));SceneUtils.addMesh(a,b,1,-f,0,0,0,g,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(e[0])}));SceneUtils.addMesh(a,b,1,f,0,0,0,-g,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(e[1])}));SceneUtils.addMesh(a,
  210. b,1,0,f,0,g,0,i,new THREE.MeshBasicMaterial({map:new THREE.Texture(e[2])}));SceneUtils.addMesh(a,b,1,0,-f,0,-g,0,i,new THREE.MeshBasicMaterial({map:new THREE.Texture(e[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}",
  211. 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}"},
  212. normal:{uniforms:{enableAO:{type:"i",value:0},enableDiffuse:{type:"i",value:0},tDiffuse:{type:"t",value:0,texture:null},tNormal:{type:"t",value:2,texture:null},tAO:{type:"t",value:3,texture:null},uNormalScale:{type:"f",value:1},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},
  213. uDirLightColor:{type:"c",value:new THREE.Color(15658734)},uAmbientLightColor:{type:"c",value:new THREE.Color(328965)},uDiffuseColor:{type:"c",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 uAmbientLightColor;\nuniform vec3 uDirLightColor;\nuniform vec3 uPointLightColor;\nuniform vec3 uAmbientColor;\nuniform vec3 uDiffuseColor;\nuniform vec3 uSpecularColor;\nuniform float uShininess;\nuniform bool enableDiffuse;\nuniform bool enableAO;\nuniform sampler2D tDiffuse;\nuniform sampler2D tNormal;\nuniform sampler2D tAO;\nuniform float uNormalScale;\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vPointLightVector;\nvarying vec3 vViewPosition;\nvoid main() {\nvec3 diffuseTex = vec3( 1.0, 1.0, 1.0 );\nvec3 aoTex = vec3( 1.0, 1.0, 1.0 );\nvec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;\nnormalTex.xy *= uNormalScale;\nnormalTex = normalize( normalTex );\nif( enableDiffuse )\ndiffuseTex = texture2D( tDiffuse, vUv ).xyz;\nif( enableAO )\naoTex = 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( uAmbientLightColor * uAmbientColor, 1.0 );\ntotalLight += vec4( uDirLightColor, 1.0 ) * ( dirDiffuse + dirSpecular );\ntotalLight += vec4( uPointLightColor, 1.0 ) * ( pointDiffuse + pointSpecular );\ngl_FragColor = vec4( totalLight.xyz * aoTex * diffuseTex, 1.0 );\n}",
  214. vertex_shader:"attribute vec4 tangent;\nuniform vec3 uPointLightPos;\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 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;\nvec4 lPosition = viewMatrix * vec4( uPointLightPos, 1.0 );\nvPointLightVector = normalize( lPosition.xyz - mvPosition.xyz );\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}"},
  215. cube:{uniforms:{tCube:{type:"t",value:1,texture:null}},vertex_shader:"varying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragment_shader:"uniform samplerCube tCube;\nvarying vec3 vViewPosition;\nvoid main() {\nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( - wPos.x, wPos.yz ) );\n}"},basic:{uniforms:{},
  216. vertex_shader:"void main() {\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragment_shader:"void main() {\ngl_FragColor = vec4(1.0, 0.0, 0.0, 0.5);\n}"}}},Cube=function(a,b,e,f,g,i,k,d){function j(E,N,r,O,m,h,n,C){var p,B,P=f||1,v=g||1,G=P+1,I=v+1,H=m/2,w=h/2;m=m/P;var R=h/v,L=l.vertices.length;if(E=="x"&&N=="y"||E=="y"&&N=="x")p="z";else if(E=="x"&&N=="z"||E=="z"&&N=="x")p="y";else if(E=="z"&&N=="y"||E=="y"&&N=="z")p="x";for(B=0;B<I;B++)for(h=0;h<G;h++){var X=new THREE.Vector3;
  217. X[E]=(h*m-H)*r;X[N]=(B*R-w)*O;X[p]=n;l.vertices.push(new THREE.Vertex(X))}for(B=0;B<v;B++)for(h=0;h<P;h++){l.faces.push(new THREE.Face4(h+G*B+L,h+G*(B+1)+L,h+1+G*(B+1)+L,h+1+G*B+L,null,C));l.uvs.push([new THREE.UV(h/P,B/v),new THREE.UV(h/P,(B+1)/v),new THREE.UV((h+1)/P,(B+1)/v),new THREE.UV((h+1)/P,B/v)])}}THREE.Geometry.call(this);var l=this,q=a/2,F=b/2,o=e/2;k=k?-1:1;if(i!==undefined)if(i instanceof Array)this.materials=i;else{this.materials=[];for(var A=0;A<6;A++)this.materials.push([i])}else this.materials=
  218. [];this.sides={px:true,nx:true,py:true,ny:true,pz:true,nz:true};if(d!=undefined)for(var D in d)if(this.sides[D]!=undefined)this.sides[D]=d[D];this.sides.px&&j("z","y",1*k,-1,e,b,-q,this.materials[0]);this.sides.nx&&j("z","y",-1*k,-1,e,b,q,this.materials[1]);this.sides.py&&j("x","z",1*k,1,a,e,F,this.materials[2]);this.sides.ny&&j("x","z",1*k,-1,a,e,-F,this.materials[3]);this.sides.pz&&j("x","y",1*k,-1,a,b,o,this.materials[4]);this.sides.nz&&j("x","y",-1*k,-1,a,b,-o,this.materials[5]);(function(){for(var E=
  219. [],N=[],r=0,O=l.vertices.length;r<O;r++){for(var m=l.vertices[r],h=false,n=0,C=E.length;n<C;n++){var p=E[n];if(m.position.x==p.position.x&&m.position.y==p.position.y&&m.position.z==p.position.z){N[r]=n;h=true;break}}if(!h){N[r]=E.length;E.push(new THREE.Vertex(m.position.clone()))}}r=0;for(O=l.faces.length;r<O;r++){m=l.faces[r];m.a=N[m.a];m.b=N[m.b];m.c=N[m.c];m.d=N[m.d]}l.vertices=E})();this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};Cube.prototype=new THREE.Geometry;
  220. Cube.prototype.constructor=Cube;
  221. var Cylinder=function(a,b,e,f,g){function i(l,q,F){k.vertices.push(new THREE.Vertex(new THREE.Vector3(l,q,F)))}THREE.Geometry.call(this);var k=this,d=Math.PI,j;for(j=0;j<a;j++)i(Math.sin(2*d*j/a)*b,Math.cos(2*d*j/a)*b,0);for(j=0;j<a;j++)i(Math.sin(2*d*j/a)*e,Math.cos(2*d*j/a)*e,f);for(j=0;j<a;j++)k.faces.push(new THREE.Face4(j,j+a,a+(j+1)%a,(j+1)%a));if(e!=0){i(0,0,-g);for(j=a;j<a+a/2;j++)k.faces.push(new THREE.Face4(2*a,(2*j-2*a)%a,(2*j-2*a+1)%a,(2*j-2*a+2)%a))}if(b!=0){i(0,0,f+g);for(j=a+a/2;j<
  222. 2*a;j++)k.faces.push(new THREE.Face4((2*j-2*a+2)%a+a,(2*j-2*a+1)%a+a,(2*j-2*a)%a+a,2*a+1))}this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};Cylinder.prototype=new THREE.Geometry;Cylinder.prototype.constructor=Cylinder;
  223. var Plane=function(a,b,e,f){THREE.Geometry.call(this);var g,i=a/2,k=b/2;e=e||1;f=f||1;var d=e+1,j=f+1;a=a/e;var l=b/f;for(g=0;g<j;g++)for(b=0;b<d;b++)this.vertices.push(new THREE.Vertex(new THREE.Vector3(b*a-i,-(g*l-k),0)));for(g=0;g<f;g++)for(b=0;b<e;b++){this.faces.push(new THREE.Face4(b+d*g,b+d*(g+1),b+1+d*(g+1),b+1+d*g));this.uvs.push([new THREE.UV(b/e,g/f),new THREE.UV(b/e,(g+1)/f),new THREE.UV((b+1)/e,(g+1)/f),new THREE.UV((b+1)/e,g/f)])}this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};
  224. Plane.prototype=new THREE.Geometry;Plane.prototype.constructor=Plane;
  225. var Sphere=function(a,b,e){THREE.Geometry.call(this);var f,g=Math.PI,i=Math.max(3,b||8),k=Math.max(2,e||6);b=[];for(e=0;e<k+1;e++){f=e/k;var d=a*Math.cos(f*g),j=a*Math.sin(f*g),l=[],q=0;for(f=0;f<i;f++){var F=2*f/i,o=j*Math.sin(F*g);F=j*Math.cos(F*g);(e==0||e==k)&&f>0||(q=this.vertices.push(new THREE.Vertex(new THREE.Vector3(F,d,o)))-1);l.push(q)}b.push(l)}var A,D,E;g=b.length;for(e=0;e<g;e++){i=b[e].length;if(e>0)for(f=0;f<i;f++){l=f==i-1;k=b[e][l?0:f+1];d=b[e][l?i-1:f];j=b[e-1][l?i-1:f];l=b[e-1][l?
  226. 0:f+1];o=e/(g-1);A=(e-1)/(g-1);D=(f+1)/i;F=f/i;q=new THREE.UV(1-D,o);o=new THREE.UV(1-F,o);F=new THREE.UV(1-F,A);var N=new THREE.UV(1-D,A);if(e<b.length-1){A=this.vertices[k].position.clone();D=this.vertices[d].position.clone();E=this.vertices[j].position.clone();A.normalize();D.normalize();E.normalize();this.faces.push(new THREE.Face3(k,d,j,[new THREE.Vector3(A.x,A.y,A.z),new THREE.Vector3(D.x,D.y,D.z),new THREE.Vector3(E.x,E.y,E.z)]));this.uvs.push([q,o,F])}if(e>1){A=this.vertices[k].position.clone();
  227. D=this.vertices[j].position.clone();E=this.vertices[l].position.clone();A.normalize();D.normalize();E.normalize();this.faces.push(new THREE.Face3(k,j,l,[new THREE.Vector3(A.x,A.y,A.z),new THREE.Vector3(D.x,D.y,D.z),new THREE.Vector3(E.x,E.y,E.z)]));this.uvs.push([q,F,N])}}}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.sortFacesByMaterial();this.boundingSphere={radius:a}};Sphere.prototype=new THREE.Geometry;Sphere.prototype.constructor=Sphere;
  228. function LathedObject(a,b,e){THREE.Geometry.call(this);b=b||12;e=e||2*Math.PI;b=e/b;for(var f=[],g=[],i=[],k=[],d=0;d<a.length;d++){this.vertices.push(new THREE.Vertex(a[d]));g[d]=this.vertices.length-1;f[d]=new THREE.Vector3(a[d].x,a[d].y,a[d].z)}for(var j=THREE.Matrix4.rotationZMatrix(b),l=0;l<=e+0.001;l+=b){for(d=0;d<f.length;d++)if(l<e){f[d]=j.multiplyVector3(f[d].clone());this.vertices.push(new THREE.Vertex(f[d]));i[d]=this.vertices.length-1}else i=k;if(l==0)k=g;for(d=0;d<g.length-1;d++){this.faces.push(new THREE.Face4(i[d],
  229. i[d+1],g[d+1],g[d]));this.uvs.push([new THREE.UV(l/e,d/a.length),new THREE.UV(l/e,(d+1)/a.length),new THREE.UV((l-b)/e,(d+1)/a.length),new THREE.UV((l-b)/e,d/a.length)])}g=i;i=[]}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.sortFacesByMaterial()}LathedObject.prototype=new THREE.Geometry;LathedObject.prototype.constructor=LathedObject;THREE.Loader=function(a){this.statusDomElement=(this.showStatus=a)?this.addStatusElement():null};
  230. 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=
  231. b},loadAsciiOld:function(a,b){var e=document.createElement("script");e.type="text/javascript";e.onload=b;e.src=a;document.getElementsByTagName("head")[0].appendChild(e)},loadAscii:function(a){var b=a.model,e=a.callback,f=a.texture_path?a.texture_path:THREE.Loader.prototype.extractUrlbase(b);a=(new Date).getTime();b=new Worker(b);b.onmessage=function(g){THREE.Loader.prototype.createModel(g.data,e,f)};b.postMessage(a)},loadBinary:function(a){var b=a.model,e=a.callback,f=a.texture_path?a.texture_path:
  232. THREE.Loader.prototype.extractUrlbase(b),g=a.bin_path?a.bin_path:THREE.Loader.prototype.extractUrlbase(b);a=(new Date).getTime();b=new Worker(b);var i=this.showProgress?THREE.Loader.prototype.updateProgress:null;b.onmessage=function(k){THREE.Loader.prototype.loadAjaxBuffers(k.data.buffers,k.data.materials,e,g,f,i)};b.onerror=function(k){alert("worker.onerror: "+k.message+"\n"+k.data);k.preventDefault()};b.postMessage(a)},loadAjaxBuffers:function(a,b,e,f,g,i){var k=new XMLHttpRequest,d=f+"/"+a,j=0;
  233. k.onreadystatechange=function(){if(k.readyState==4)k.status==200||k.status==0?THREE.Loader.prototype.createBinModel(k.responseText,e,g,b):alert("Couldn't load ["+d+"] ["+k.status+"]");else if(k.readyState==3){if(i){if(j==0)j=k.getResponseHeader("Content-Length");i({total:j,loaded:k.responseText.length})}}else if(k.readyState==2)j=k.getResponseHeader("Content-Length")};k.open("GET",d,true);k.overrideMimeType("text/plain; charset=x-user-defined");k.setRequestHeader("Content-Type","text/plain");k.send(null)},
  234. createBinModel:function(a,b,e,f){var g=function(i){function k(u,M){var K=q(u,M),ba=q(u,M+1),fa=q(u,M+2),ja=q(u,M+3),ma=(ja<<1&255|fa>>7)-127;K=(fa&127)<<16|ba<<8|K;if(K==0&&ma==-127)return 0;return(1-2*(ja>>7))*(1+K*Math.pow(2,-23))*Math.pow(2,ma)}function d(u,M){var K=q(u,M),ba=q(u,M+1),fa=q(u,M+2);return(q(u,M+3)<<24)+(fa<<16)+(ba<<8)+K}function j(u,M){var K=q(u,M);return(q(u,M+1)<<8)+K}function l(u,M){var K=q(u,M);return K>127?K-256:K}function q(u,M){return u.charCodeAt(M)&255}function F(u){var M,
  235. K,ba;M=d(a,u);K=d(a,u+C);ba=d(a,u+p);u=j(a,u+B);THREE.Loader.prototype.f3(r,M,K,ba,u)}function o(u){var M,K,ba,fa,ja,ma;M=d(a,u);K=d(a,u+C);ba=d(a,u+p);fa=j(a,u+B);ja=d(a,u+P);ma=d(a,u+v);u=d(a,u+G);THREE.Loader.prototype.f3n(r,h,M,K,ba,fa,ja,ma,u)}function A(u){var M,K,ba,fa;M=d(a,u);K=d(a,u+I);ba=d(a,u+H);fa=d(a,u+w);u=j(a,u+R);THREE.Loader.prototype.f4(r,M,K,ba,fa,u)}function D(u){var M,K,ba,fa,ja,ma,ta,va;M=d(a,u);K=d(a,u+I);ba=d(a,u+H);fa=d(a,u+w);ja=j(a,u+R);ma=d(a,u+L);ta=d(a,u+X);va=d(a,u+
  236. Z);u=d(a,u+S);THREE.Loader.prototype.f4n(r,h,M,K,ba,fa,ja,ma,ta,va,u)}function E(u){var M,K;M=d(a,u);K=d(a,u+ga);u=d(a,u+$);THREE.Loader.prototype.uv3(r,n[M*2],n[M*2+1],n[K*2],n[K*2+1],n[u*2],n[u*2+1])}function N(u){var M,K,ba;M=d(a,u);K=d(a,u+U);ba=d(a,u+W);u=d(a,u+ea);THREE.Loader.prototype.uv4(r,n[M*2],n[M*2+1],n[K*2],n[K*2+1],n[ba*2],n[ba*2+1],n[u*2],n[u*2+1])}var r=this,O=0,m,h=[],n=[],C,p,B,P,v,G,I,H,w,R,L,X,Z,S,ga,$,U,W,ea,aa,J,V,Y,la,ka;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(r,
  237. f,i);m={signature:a.substr(O,8),header_bytes:q(a,O+8),vertex_coordinate_bytes:q(a,O+9),normal_coordinate_bytes:q(a,O+10),uv_coordinate_bytes:q(a,O+11),vertex_index_bytes:q(a,O+12),normal_index_bytes:q(a,O+13),uv_index_bytes:q(a,O+14),material_index_bytes:q(a,O+15),nvertices:d(a,O+16),nnormals:d(a,O+16+4),nuvs:d(a,O+16+8),ntri_flat:d(a,O+16+12),ntri_smooth:d(a,O+16+16),ntri_flat_uv:d(a,O+16+20),ntri_smooth_uv:d(a,O+16+24),nquad_flat:d(a,O+16+28),nquad_smooth:d(a,O+16+32),nquad_flat_uv:d(a,O+16+36),
  238. nquad_smooth_uv:d(a,O+16+40)};O+=m.header_bytes;C=m.vertex_index_bytes;p=m.vertex_index_bytes*2;B=m.vertex_index_bytes*3;P=m.vertex_index_bytes*3+m.material_index_bytes;v=m.vertex_index_bytes*3+m.material_index_bytes+m.normal_index_bytes;G=m.vertex_index_bytes*3+m.material_index_bytes+m.normal_index_bytes*2;I=m.vertex_index_bytes;H=m.vertex_index_bytes*2;w=m.vertex_index_bytes*3;R=m.vertex_index_bytes*4;L=m.vertex_index_bytes*4+m.material_index_bytes;X=m.vertex_index_bytes*4+m.material_index_bytes+
  239. m.normal_index_bytes;Z=m.vertex_index_bytes*4+m.material_index_bytes+m.normal_index_bytes*2;S=m.vertex_index_bytes*4+m.material_index_bytes+m.normal_index_bytes*3;ga=m.uv_index_bytes;$=m.uv_index_bytes*2;U=m.uv_index_bytes;W=m.uv_index_bytes*2;ea=m.uv_index_bytes*3;i=m.vertex_index_bytes*3+m.material_index_bytes;ka=m.vertex_index_bytes*4+m.material_index_bytes;aa=m.ntri_flat*i;J=m.ntri_smooth*(i+m.normal_index_bytes*3);V=m.ntri_flat_uv*(i+m.uv_index_bytes*3);Y=m.ntri_smooth_uv*(i+m.normal_index_bytes*
  240. 3+m.uv_index_bytes*3);la=m.nquad_flat*ka;i=m.nquad_smooth*(ka+m.normal_index_bytes*4);ka=m.nquad_flat_uv*(ka+m.uv_index_bytes*4);O+=function(u){var M,K,ba,fa=m.vertex_coordinate_bytes*3,ja=u+m.nvertices*fa;for(u=u;u<ja;u+=fa){M=k(a,u);K=k(a,u+m.vertex_coordinate_bytes);ba=k(a,u+m.vertex_coordinate_bytes*2);THREE.Loader.prototype.v(r,M,K,ba)}return m.nvertices*fa}(O);O+=function(u){var M,K,ba,fa=m.normal_coordinate_bytes*3,ja=u+m.nnormals*fa;for(u=u;u<ja;u+=fa){M=l(a,u);K=l(a,u+m.normal_coordinate_bytes);
  241. ba=l(a,u+m.normal_coordinate_bytes*2);h.push(M/127,K/127,ba/127)}return m.nnormals*fa}(O);O+=function(u){var M,K,ba=m.uv_coordinate_bytes*2,fa=u+m.nuvs*ba;for(u=u;u<fa;u+=ba){M=k(a,u);K=k(a,u+m.uv_coordinate_bytes);n.push(M,K)}return m.nuvs*ba}(O);O=O;aa=O+aa;J=aa+J;V=J+V;Y=V+Y;la=Y+la;i=la+i;ka=i+ka;(function(u){var M,K=m.vertex_index_bytes*3+m.material_index_bytes,ba=K+m.uv_index_bytes*3,fa=u+m.ntri_flat_uv*ba;for(M=u;M<fa;M+=ba){F(M);E(M+K)}return fa-u})(J);(function(u){var M,K=m.vertex_index_bytes*
  242. 3+m.material_index_bytes+m.normal_index_bytes*3,ba=K+m.uv_index_bytes*3,fa=u+m.ntri_smooth_uv*ba;for(M=u;M<fa;M+=ba){o(M);E(M+K)}return fa-u})(V);(function(u){var M,K=m.vertex_index_bytes*4+m.material_index_bytes,ba=K+m.uv_index_bytes*4,fa=u+m.nquad_flat_uv*ba;for(M=u;M<fa;M+=ba){A(M);N(M+K)}return fa-u})(i);(function(u){var M,K=m.vertex_index_bytes*4+m.material_index_bytes+m.normal_index_bytes*4,ba=K+m.uv_index_bytes*4,fa=u+m.nquad_smooth_uv*ba;for(M=u;M<fa;M+=ba){D(M);N(M+K)}return fa-u})(ka);(function(u){var M,
  243. K=m.vertex_index_bytes*3+m.material_index_bytes,ba=u+m.ntri_flat*K;for(M=u;M<ba;M+=K)F(M);return ba-u})(O);(function(u){var M,K=m.vertex_index_bytes*3+m.material_index_bytes+m.normal_index_bytes*3,ba=u+m.ntri_smooth*K;for(M=u;M<ba;M+=K)o(M);return ba-u})(aa);(function(u){var M,K=m.vertex_index_bytes*4+m.material_index_bytes,ba=u+m.nquad_flat*K;for(M=u;M<ba;M+=K)A(M);return ba-u})(Y);(function(u){var M,K=m.vertex_index_bytes*4+m.material_index_bytes+m.normal_index_bytes*4,ba=u+m.nquad_smooth*K;for(M=
  244. u;M<ba;M+=K)D(M);return ba-u})(la);this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};g.prototype=new THREE.Geometry;g.prototype.constructor=g;b(new g(e))},createModel:function(a,b,e){var f=function(g){var i=this;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(i,a.materials,g);(function(){var k,d,j,l,q;k=0;for(d=a.vertices.length;k<d;k+=3){j=a.vertices[k];l=a.vertices[k+1];q=a.vertices[k+2];THREE.Loader.prototype.v(i,j,l,q)}})();(function(){function k(D,
  245. E){THREE.Loader.prototype.f3(i,D[E],D[E+1],D[E+2],D[E+3])}function d(D,E){THREE.Loader.prototype.f3n(i,a.normals,D[E],D[E+1],D[E+2],D[E+3],D[E+4],D[E+5],D[E+6])}function j(D,E){THREE.Loader.prototype.f4(i,D[E],D[E+1],D[E+2],D[E+3],D[E+4])}function l(D,E){THREE.Loader.prototype.f4n(i,a.normals,D[E],D[E+1],D[E+2],D[E+3],D[E+4],D[E+5],D[E+6],D[E+7],D[E+8])}function q(D,E){var N,r,O;N=D[E];r=D[E+1];O=D[E+2];THREE.Loader.prototype.uv3(i,a.uvs[N*2],a.uvs[N*2+1],a.uvs[r*2],a.uvs[r*2+1],a.uvs[O*2],a.uvs[O*
  246. 2+1])}function F(D,E){var N,r,O,m;N=D[E];r=D[E+1];O=D[E+2];m=D[E+3];THREE.Loader.prototype.uv4(i,a.uvs[N*2],a.uvs[N*2+1],a.uvs[r*2],a.uvs[r*2+1],a.uvs[O*2],a.uvs[O*2+1],a.uvs[m*2],a.uvs[m*2+1])}var o,A;o=0;for(A=a.triangles_uv.length;o<A;o+=7){k(a.triangles_uv,o);q(a.triangles_uv,o+4)}o=0;for(A=a.triangles_n_uv.length;o<A;o+=10){d(a.triangles_n_uv,o);q(a.triangles_n_uv,o+7)}o=0;for(A=a.quads_uv.length;o<A;o+=9){j(a.quads_uv,o);F(a.quads_uv,o+5)}o=0;for(A=a.quads_n_uv.length;o<A;o+=13){l(a.quads_n_uv,
  247. o);F(a.quads_n_uv,o+9)}o=0;for(A=a.triangles.length;o<A;o+=4)k(a.triangles,o);o=0;for(A=a.triangles_n.length;o<A;o+=7)d(a.triangles_n,o);o=0;for(A=a.quads.length;o<A;o+=5)j(a.quads,o);o=0;for(A=a.quads_n.length;o<A;o+=9)l(a.quads_n,o)})();this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};f.prototype=new THREE.Geometry;f.prototype.constructor=f;b(new f(e))},v:function(a,b,e,f){a.vertices.push(new THREE.Vertex(new THREE.Vector3(b,e,f)))},f3:function(a,b,e,f,g){a.faces.push(new THREE.Face3(b,
  248. e,f,null,a.materials[g]))},f4:function(a,b,e,f,g,i){a.faces.push(new THREE.Face4(b,e,f,g,null,a.materials[i]))},f3n:function(a,b,e,f,g,i,k,d,j){i=a.materials[i];var l=b[d*3],q=b[d*3+1];d=b[d*3+2];var F=b[j*3],o=b[j*3+1];j=b[j*3+2];a.faces.push(new THREE.Face3(e,f,g,[new THREE.Vector3(b[k*3],b[k*3+1],b[k*3+2]),new THREE.Vector3(l,q,d),new THREE.Vector3(F,o,j)],i))},f4n:function(a,b,e,f,g,i,k,d,j,l,q){k=a.materials[k];var F=b[j*3],o=b[j*3+1];j=b[j*3+2];var A=b[l*3],D=b[l*3+1];l=b[l*3+2];var E=b[q*3],
  249. N=b[q*3+1];q=b[q*3+2];a.faces.push(new THREE.Face4(e,f,g,i,[new THREE.Vector3(b[d*3],b[d*3+1],b[d*3+2]),new THREE.Vector3(F,o,j),new THREE.Vector3(A,D,l),new THREE.Vector3(E,N,q)],k))},uv3:function(a,b,e,f,g,i,k){var d=[];d.push(new THREE.UV(b,e));d.push(new THREE.UV(f,g));d.push(new THREE.UV(i,k));a.uvs.push(d)},uv4:function(a,b,e,f,g,i,k,d,j){var l=[];l.push(new THREE.UV(b,e));l.push(new THREE.UV(f,g));l.push(new THREE.UV(i,k));l.push(new THREE.UV(d,j));a.uvs.push(l)},init_materials:function(a,
  250. b,e){a.materials=[];for(var f=0;f<b.length;++f)a.materials[f]=[THREE.Loader.prototype.createMaterial(b[f],e)]},createMaterial:function(a,b){function e(i){i=Math.log(i)/Math.LN2;return Math.floor(i)==i}var f,g;if(a.map_diffuse&&b){g=document.createElement("canvas");f=new THREE.MeshLambertMaterial({map:new THREE.Texture(g)});g=new Image;g.onload=function(){if(!e(this.width)||!e(this.height)){var i=Math.pow(2,Math.round(Math.log(this.width)/Math.LN2)),k=Math.pow(2,Math.round(Math.log(this.height)/Math.LN2));
  251. f.map.image.width=i;f.map.image.height=k;f.map.image.getContext("2d").drawImage(this,0,0,i,k)}else f.map.image=this;f.map.image.loaded=1};g.src=b+"/"+a.map_diffuse}else if(a.col_diffuse){g=(a.col_diffuse[0]*255<<16)+(a.col_diffuse[1]*255<<8)+a.col_diffuse[2]*255;f=new THREE.MeshLambertMaterial({color:g,opacity:a.transparency})}else f=a.a_dbg_color?new THREE.MeshLambertMaterial({color:a.a_dbg_color}):new THREE.MeshLambertMaterial({color:15658734});return f},extractUrlbase:function(a){a=a.split("/");
  252. a.pop();return a.join("/")}};