ThreeExtras.js 125 KB

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