ThreeExtras.js 105 KB

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