Files
three.js/build/ThreeExtras.js
T
alteredq fe6008b616 Added basic support for dynamic geometry in WebGLRenderer (with silly ocean example).
If you want to refresh VBOs (and thus have geometry changes reflected in renderer), you need to set dirty flags on geometry object.

There are separate flags for different buffers (as not always all buffers need to be updated and oh my is updating costly):

    mesh.geometry.__dirtyVertices = true;
    mesh.geometry.__dirtyNormals = true;
    mesh.geometry.__dirtyUvs = true;
    mesh.geometry.__dirtyTangents = true;

    mesh.geometry.__dirtyElements = true;

That was quite tough feature, a lot of refactoring, yet performance is still quite bad :(

The biggest remaining bottleneck seems to be translation between Three.js internal data formats and buffers. I removed as much per-frame arrays creation as I could, but even just iterating through existing data and setting of values is still very costly. Also per-frame normals computation is expensive.
2011-01-12 00:57:04 +01:00

244 lines
116 KiB
JavaScript

// ThreeExtras.js r32 - http://github.com/mrdoob/three.js
var THREE=THREE||{};THREE.Color=function(a){this.autoUpdate=true;this.setHex(a)};
THREE.Color.prototype={setRGB:function(a,b,e){this.r=a;this.g=b;this.b=e;if(this.autoUpdate){this.updateHex();this.updateStyleString()}},setHex:function(a){this.hex=~~a&16777215;if(this.autoUpdate){this.updateRGBA();this.updateStyleString()}},updateHex:function(){this.hex=~~(this.r*255)<<16^~~(this.g*255)<<8^~~(this.b*255)},updateRGBA:function(){this.r=(this.hex>>16&255)/255;this.g=(this.hex>>8&255)/255;this.b=(this.hex&255)/255},updateStyleString:function(){this.__styleString="rgb("+~~(this.r*255)+
","+~~(this.g*255)+","+~~(this.b*255)+")"},clone:function(){return new THREE.Color(this.hex)},toString:function(){return"THREE.Color ( r: "+this.r+", g: "+this.g+", b: "+this.b+", hex: "+this.hex+" )"}};THREE.Vector2=function(a,b){this.x=a||0;this.y=b||0};
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*
this.x+this.y*this.y)},lengthSq:function(){return this.x*this.x+this.y*this.y},negate:function(){this.x=-this.x;this.y=-this.y;return this},clone:function(){return new THREE.Vector2(this.x,this.y)},toString:function(){return"THREE.Vector2 ("+this.x+", "+this.y+")"}};THREE.Vector3=function(a,b,e){this.x=a||0;this.y=b||0;this.z=e||0};
THREE.Vector3.prototype={set:function(a,b,e){this.x=a;this.y=b;this.z=e;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;return this},addScalar:function(a){this.x+=a;this.y+=a;this.z+=a;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;return this},
cross:function(a,b){this.x=a.y*b.z-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){var b=this.x,e=this.y,f=this.z;this.x=e*a.z-f*a.y;this.y=f*a.x-b*a.z;this.z=b*a.y-e*a.x;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;return this},divideSelf:function(a){this.x/=a.x;this.y/=a.y;this.z/=
a.z;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=a;return this},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},distanceTo:function(a){var b=this.x-a.x,e=this.y-a.y;a=this.z-a.z;return Math.sqrt(b*b+e*e+a*a)},distanceToSquared:function(a){var b=this.x-a.x,e=this.y-a.y;a=this.z-a.z;return b*b+e*e+a*a},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},negate:function(){this.x=
-this.x;this.y=-this.y;this.z=-this.z;return this},normalize:function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z);a>0?this.multiplyScalar(1/a):this.set(0,0,0);return this},setLength:function(a){return this.normalize().multiplyScalar(a)},isZero:function(){return Math.abs(this.x)<1.0E-4&&Math.abs(this.y)<1.0E-4&&Math.abs(this.z)<1.0E-4},clone:function(){return new THREE.Vector3(this.x,this.y,this.z)},toString:function(){return"THREE.Vector3 ( "+this.x+", "+this.y+", "+this.z+" )"}};
THREE.Vector4=function(a,b,e,f){this.x=a||0;this.y=b||0;this.z=e||0;this.w=f||1};
THREE.Vector4.prototype={set:function(a,b,e,f){this.x=a;this.y=b;this.z=e;this.w=f;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w||1;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;
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+")"}};
THREE.Ray=function(a,b){this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3};
THREE.Ray.prototype={intersectScene:function(a){var b,e,f=a.objects,g=[];a=0;for(b=f.length;a<b;a++){e=f[a];if(e instanceof THREE.Mesh)g=g.concat(this.intersectObject(e))}g.sort(function(h,j){return h.distance-j.distance});return g},intersectObject:function(a){function b(M,q,G,d){d=d.clone().subSelf(q);G=G.clone().subSelf(q);var k=M.clone().subSelf(q);M=d.dot(d);q=d.dot(G);d=d.dot(k);var p=G.dot(G);G=G.dot(k);k=1/(M*p-q*q);p=(p*d-q*G)*k;M=(M*G-q*d)*k;return p>0&&M>0&&p+M<1}var e,f,g,h,j,c,i,l,u,C,
o,x=a.geometry,A=x.vertices,B=[];e=0;for(f=x.faces.length;e<f;e++){g=x.faces[e];C=this.origin.clone();o=this.direction.clone();h=a.matrix.multiplyVector3(A[g.a].position.clone());j=a.matrix.multiplyVector3(A[g.b].position.clone());c=a.matrix.multiplyVector3(A[g.c].position.clone());i=g instanceof THREE.Face4?a.matrix.multiplyVector3(A[g.d].position.clone()):null;l=a.rotationMatrix.multiplyVector3(g.normal.clone());u=o.dot(l);if(u<0){l=l.dot((new THREE.Vector3).sub(h,C))/u;C=C.addSelf(o.multiplyScalar(l));
if(g instanceof THREE.Face3){if(b(C,h,j,c)){g={distance:this.origin.distanceTo(C),point:C,face:g,object:a};B.push(g)}}else if(g instanceof THREE.Face4)if(b(C,h,j,i)||b(C,j,c,i)){g={distance:this.origin.distanceTo(C),point:C,face:g,object:a};B.push(g)}}}return B}};
THREE.Rectangle=function(){function a(){h=f-b;j=g-e}var b,e,f,g,h,j,c=true;this.getX=function(){return b};this.getY=function(){return e};this.getWidth=function(){return h};this.getHeight=function(){return j};this.getLeft=function(){return b};this.getTop=function(){return e};this.getRight=function(){return f};this.getBottom=function(){return g};this.set=function(i,l,u,C){c=false;b=i;e=l;f=u;g=C;a()};this.addPoint=function(i,l){if(c){c=false;b=i;e=l;f=i;g=l}else{b=b<i?b:i;e=e<l?e:l;f=f>i?f:i;g=g>l?
g:l}a()};this.add3Points=function(i,l,u,C,o,x){if(c){c=false;b=i<u?i<o?i:o:u<o?u:o;e=l<C?l<x?l:x:C<x?C:x;f=i>u?i>o?i:o:u>o?u:o;g=l>C?l>x?l:x:C>x?C:x}else{b=i<u?i<o?i<b?i:b:o<b?o:b:u<o?u<b?u:b:o<b?o:b;e=l<C?l<x?l<e?l:e:x<e?x:e:C<x?C<e?C:e:x<e?x:e;f=i>u?i>o?i>f?i:f:o>f?o:f:u>o?u>f?u:f:o>f?o:f;g=l>C?l>x?l>g?l:g:x>g?x:g:C>x?C>g?C:g:x>g?x:g}a()};this.addRectangle=function(i){if(c){c=false;b=i.getLeft();e=i.getTop();f=i.getRight();g=i.getBottom()}else{b=b<i.getLeft()?b:i.getLeft();e=e<i.getTop()?e:i.getTop();
f=f>i.getRight()?f:i.getRight();g=g>i.getBottom()?g:i.getBottom()}a()};this.inflate=function(i){b-=i;e-=i;f+=i;g+=i;a()};this.minSelf=function(i){b=b>i.getLeft()?b:i.getLeft();e=e>i.getTop()?e:i.getTop();f=f<i.getRight()?f:i.getRight();g=g<i.getBottom()?g:i.getBottom();a()};this.instersects=function(i){return Math.min(f,i.getRight())-Math.max(b,i.getLeft())>=0&&Math.min(g,i.getBottom())-Math.max(e,i.getTop())>=0};this.empty=function(){c=true;g=f=e=b=0;a()};this.isEmpty=function(){return c};this.toString=
function(){return"THREE.Rectangle ( left: "+b+", right: "+f+", top: "+e+", bottom: "+g+", width: "+h+", height: "+j+" )"}};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}};
THREE.Matrix4=function(a,b,e,f,g,h,j,c,i,l,u,C,o,x,A,B){this.n11=a||1;this.n12=b||0;this.n13=e||0;this.n14=f||0;this.n21=g||0;this.n22=h||1;this.n23=j||0;this.n24=c||0;this.n31=i||0;this.n32=l||0;this.n33=u||1;this.n34=C||0;this.n41=o||0;this.n42=x||0;this.n43=A||0;this.n44=B||1};
THREE.Matrix4.prototype={identity:function(){this.n11=1;this.n21=this.n14=this.n13=this.n12=0;this.n22=1;this.n32=this.n31=this.n24=this.n23=0;this.n33=1;this.n43=this.n42=this.n41=this.n34=0;this.n44=1;return this},set:function(a,b,e,f,g,h,j,c,i,l,u,C,o,x,A,B){this.n11=a;this.n12=b;this.n13=e;this.n14=f;this.n21=g;this.n22=h;this.n23=j;this.n24=c;this.n31=i;this.n32=l;this.n33=u;this.n34=C;this.n41=o;this.n42=x;this.n43=A;this.n44=B;return this},copy:function(a){this.n11=a.n11;this.n12=a.n12;this.n13=
a.n13;this.n14=a.n14;this.n21=a.n21;this.n22=a.n22;this.n23=a.n23;this.n24=a.n24;this.n31=a.n31;this.n32=a.n32;this.n33=a.n33;this.n34=a.n34;this.n41=a.n41;this.n42=a.n42;this.n43=a.n43;this.n44=a.n44;return this},lookAt:function(a,b,e){var f=new THREE.Vector3,g=new THREE.Vector3,h=new THREE.Vector3;h.sub(a,b).normalize();f.cross(e,h).normalize();g.cross(h,f).normalize();this.n11=f.x;this.n12=f.y;this.n13=f.z;this.n14=-f.dot(a);this.n21=g.x;this.n22=g.y;this.n23=g.z;this.n24=-g.dot(a);this.n31=h.x;
this.n32=h.y;this.n33=h.z;this.n34=-h.dot(a);this.n43=this.n42=this.n41=0;this.n44=1;return this},multiplyVector3:function(a){var b=a.x,e=a.y,f=a.z,g=1/(this.n41*b+this.n42*e+this.n43*f+this.n44);a.x=(this.n11*b+this.n12*e+this.n13*f+this.n14)*g;a.y=(this.n21*b+this.n22*e+this.n23*f+this.n24)*g;a.z=(this.n31*b+this.n32*e+this.n33*f+this.n34)*g;return a},multiplyVector4:function(a){var b=a.x,e=a.y,f=a.z,g=a.w;a.x=this.n11*b+this.n12*e+this.n13*f+this.n14*g;a.y=this.n21*b+this.n22*e+this.n23*f+this.n24*
g;a.z=this.n31*b+this.n32*e+this.n33*f+this.n34*g;a.w=this.n41*b+this.n42*e+this.n43*f+this.n44*g;return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},multiply:function(a,b){var e=a.n11,f=a.n12,g=a.n13,h=a.n14,j=a.n21,c=a.n22,i=a.n23,l=a.n24,u=a.n31,C=a.n32,
o=a.n33,x=a.n34,A=a.n41,B=a.n42,M=a.n43,q=a.n44,G=b.n11,d=b.n12,k=b.n13,p=b.n14,s=b.n21,r=b.n22,t=b.n23,w=b.n24,v=b.n31,H=b.n32,y=b.n33,n=b.n34,D=b.n41,W=b.n42,J=b.n43,P=b.n44;this.n11=e*G+f*s+g*v+h*D;this.n12=e*d+f*r+g*H+h*W;this.n13=e*k+f*t+g*y+h*J;this.n14=e*p+f*w+g*n+h*P;this.n21=j*G+c*s+i*v+l*D;this.n22=j*d+c*r+i*H+l*W;this.n23=j*k+c*t+i*y+l*J;this.n24=j*p+c*w+i*n+l*P;this.n31=u*G+C*s+o*v+x*D;this.n32=u*d+C*r+o*H+x*W;this.n33=u*k+C*t+o*y+x*J;this.n34=u*p+C*w+o*n+x*P;this.n41=A*G+B*s+M*v+q*D;
this.n42=A*d+B*r+M*H+q*W;this.n43=A*k+B*t+M*y+q*J;this.n44=A*p+B*w+M*n+q*P;return this},multiplySelf:function(a){var b=this.n11,e=this.n12,f=this.n13,g=this.n14,h=this.n21,j=this.n22,c=this.n23,i=this.n24,l=this.n31,u=this.n32,C=this.n33,o=this.n34,x=this.n41,A=this.n42,B=this.n43,M=this.n44,q=a.n11,G=a.n21,d=a.n31,k=a.n41,p=a.n12,s=a.n22,r=a.n32,t=a.n42,w=a.n13,v=a.n23,H=a.n33,y=a.n43,n=a.n14,D=a.n24,W=a.n34;a=a.n44;this.n11=b*q+e*G+f*d+g*k;this.n12=b*p+e*s+f*r+g*t;this.n13=b*w+e*v+f*H+g*y;this.n14=
b*n+e*D+f*W+g*a;this.n21=h*q+j*G+c*d+i*k;this.n22=h*p+j*s+c*r+i*t;this.n23=h*w+j*v+c*H+i*y;this.n24=h*n+j*D+c*W+i*a;this.n31=l*q+u*G+C*d+o*k;this.n32=l*p+u*s+C*r+o*t;this.n33=l*w+u*v+C*H+o*y;this.n34=l*n+u*D+C*W+o*a;this.n41=x*q+A*G+B*d+M*k;this.n42=x*p+A*s+B*r+M*t;this.n43=x*w+A*v+B*H+M*y;this.n44=x*n+A*D+B*W+M*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*=
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*
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,e,f){var g=b[e];b[e]=b[f];
b[f]=g}a(this,"n21","n12");a(this,"n31","n13");a(this,"n32","n23");a(this,"n41","n14");a(this,"n42","n24");a(this,"n43","n34");return this},clone:function(){var a=new THREE.Matrix4;a.n11=this.n11;a.n12=this.n12;a.n13=this.n13;a.n14=this.n14;a.n21=this.n21;a.n22=this.n22;a.n23=this.n23;a.n24=this.n24;a.n31=this.n31;a.n32=this.n32;a.n33=this.n33;a.n34=this.n34;a.n41=this.n41;a.n42=this.n42;a.n43=this.n43;a.n44=this.n44;return a},flatten:function(){return[this.n11,this.n21,this.n31,this.n41,this.n12,
this.n22,this.n32,this.n42,this.n13,this.n23,this.n33,this.n43,this.n14,this.n24,this.n34,this.n44]},toString:function(){return"| "+this.n11+" "+this.n12+" "+this.n13+" "+this.n14+" |\n| "+this.n21+" "+this.n22+" "+this.n23+" "+this.n24+" |\n| "+this.n31+" "+this.n32+" "+this.n33+" "+this.n34+" |\n| "+this.n41+" "+this.n42+" "+this.n43+" "+this.n44+" |"}};THREE.Matrix4.translationMatrix=function(a,b,e){var f=new THREE.Matrix4;f.n14=a;f.n24=b;f.n34=e;return f};
THREE.Matrix4.scaleMatrix=function(a,b,e){var f=new THREE.Matrix4;f.n11=a;f.n22=b;f.n33=e;return f};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};
THREE.Matrix4.rotationAxisAngleMatrix=function(a,b){var e=new THREE.Matrix4,f=Math.cos(b),g=Math.sin(b),h=1-f,j=a.x,c=a.y,i=a.z;e.n11=h*j*j+f;e.n12=h*j*c-g*i;e.n13=h*j*i+g*c;e.n21=h*j*c+g*i;e.n22=h*c*c+f;e.n23=h*c*i-g*j;e.n31=h*j*i-g*c;e.n32=h*c*i+g*j;e.n33=h*i*i+f;return e};
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*
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*
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*
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};
THREE.Matrix4.makeInvert3x3=function(a){var b=a.flatten();a=new THREE.Matrix3;var e=b[10]*b[5]-b[6]*b[9],f=-b[10]*b[1]+b[2]*b[9],g=b[6]*b[1]-b[2]*b[5],h=-b[10]*b[4]+b[6]*b[8],j=b[10]*b[0]-b[2]*b[8],c=-b[6]*b[0]+b[2]*b[4],i=b[9]*b[4]-b[5]*b[8],l=-b[9]*b[0]+b[1]*b[8],u=b[5]*b[0]-b[1]*b[4];b=b[0]*e+b[1]*h+b[2]*i;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*e;a.m[1]=b*f;a.m[2]=b*g;a.m[3]=b*h;a.m[4]=b*j;a.m[5]=b*c;a.m[6]=b*i;a.m[7]=b*l;a.m[8]=b*u;return a};
THREE.Matrix4.makeFrustum=function(a,b,e,f,g,h){var j,c,i;j=new THREE.Matrix4;c=2*g/(b-a);i=2*g/(f-e);a=(b+a)/(b-a);e=(f+e)/(f-e);f=-(h+g)/(h-g);g=-2*h*g/(h-g);j.n11=c;j.n12=0;j.n13=a;j.n14=0;j.n21=0;j.n22=i;j.n23=e;j.n24=0;j.n31=0;j.n32=0;j.n33=f;j.n34=g;j.n41=0;j.n42=0;j.n43=-1;j.n44=0;return j};THREE.Matrix4.makePerspective=function(a,b,e,f){var g;a=e*Math.tan(a*Math.PI/360);g=-a;return THREE.Matrix4.makeFrustum(g*b,a*b,g,a,e,f)};
THREE.Matrix4.makeOrtho=function(a,b,e,f,g,h){var j,c,i,l;j=new THREE.Matrix4;c=b-a;i=e-f;l=h-g;a=(b+a)/c;e=(e+f)/i;g=(h+g)/l;j.n11=2/c;j.n12=0;j.n13=0;j.n14=-a;j.n21=0;j.n22=2/i;j.n23=0;j.n24=-e;j.n31=0;j.n32=0;j.n33=-2/l;j.n34=-g;j.n41=0;j.n42=0;j.n43=0;j.n44=1;return j};
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+" )"}};
THREE.Face3=function(a,b,e,f,g){this.a=a;this.b=b;this.c=e;this.centroid=new THREE.Vector3;this.normal=f instanceof THREE.Vector3?f:new THREE.Vector3;this.vertexNormals=f instanceof Array?f:[];this.materials=g instanceof Array?g:[g]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
THREE.Face4=function(a,b,e,f,g,h){this.a=a;this.b=b;this.c=e;this.d=f;this.centroid=new THREE.Vector3;this.normal=g instanceof THREE.Vector3?g:new THREE.Vector3;this.vertexNormals=g instanceof Array?g:[];this.materials=h instanceof Array?h:[h]};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};
THREE.UV.prototype={copy:function(a){this.u=a.u;this.v=a.v},toString:function(){return"THREE.UV ("+this.u+", "+this.v+")"}};THREE.Geometry=function(){this.vertices=[];this.faces=[];this.uvs=[];this.boundingSphere=this.boundingBox=null;this.geometryChunks={};this.hasTangents=false};
THREE.Geometry.prototype={computeCentroids:function(){var a,b,e;a=0;for(b=this.faces.length;a<b;a++){e=this.faces[a];e.centroid.set(0,0,0);if(e instanceof THREE.Face3){e.centroid.addSelf(this.vertices[e.a].position);e.centroid.addSelf(this.vertices[e.b].position);e.centroid.addSelf(this.vertices[e.c].position);e.centroid.divideScalar(3)}else if(e instanceof THREE.Face4){e.centroid.addSelf(this.vertices[e.a].position);e.centroid.addSelf(this.vertices[e.b].position);e.centroid.addSelf(this.vertices[e.c].position);
e.centroid.addSelf(this.vertices[e.d].position);e.centroid.divideScalar(4)}}},computeFaceNormals:function(a){var b,e,f,g,h,j,c=new THREE.Vector3,i=new THREE.Vector3;f=0;for(g=this.vertices.length;f<g;f++){h=this.vertices[f];h.normal.set(0,0,0)}f=0;for(g=this.faces.length;f<g;f++){h=this.faces[f];if(a&&h.vertexNormals.length){c.set(0,0,0);b=0;for(e=h.normal.length;b<e;b++)c.addSelf(h.vertexNormals[b]);c.divideScalar(3)}else{b=this.vertices[h.a];e=this.vertices[h.b];j=this.vertices[h.c];c.sub(j.position,
e.position);i.sub(b.position,e.position);c.crossSelf(i)}c.isZero()||c.normalize();h.normal.copy(c)}},computeVertexNormals:function(){var a,b,e,f;if(this.__tmpVertices==undefined){f=this.__tmpVertices=Array(this.vertices.length);a=0;for(b=this.vertices.length;a<b;a++)f[a]=new THREE.Vector3;a=0;for(b=this.faces.length;a<b;a++){e=this.faces[a];if(e instanceof THREE.Face3)e.vertexNormals=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];else if(e instanceof THREE.Face4)e.vertexNormals=[new THREE.Vector3,
new THREE.Vector3,new THREE.Vector3,new THREE.Vector3]}}else{f=this.__tmpVertices;a=0;for(b=this.vertices.length;a<b;a++)f[a].set(0,0,0)}a=0;for(b=this.faces.length;a<b;a++){e=this.faces[a];if(e instanceof THREE.Face3){f[e.a].addSelf(e.normal);f[e.b].addSelf(e.normal);f[e.c].addSelf(e.normal)}else if(e instanceof THREE.Face4){f[e.a].addSelf(e.normal);f[e.b].addSelf(e.normal);f[e.c].addSelf(e.normal);f[e.d].addSelf(e.normal)}}a=0;for(b=this.vertices.length;a<b;a++)f[a].normalize();a=0;for(b=this.faces.length;a<
b;a++){e=this.faces[a];if(e instanceof THREE.Face3){e.vertexNormals[0].copy(f[e.a]);e.vertexNormals[1].copy(f[e.b]);e.vertexNormals[2].copy(f[e.c])}else if(e instanceof THREE.Face4){e.vertexNormals[0].copy(f[e.a]);e.vertexNormals[1].copy(f[e.b]);e.vertexNormals[2].copy(f[e.c]);e.vertexNormals[3].copy(f[e.d])}}},computeTangents:function(){function a(n,D,W,J,P,U,R){h=n.vertices[D].position;j=n.vertices[W].position;c=n.vertices[J].position;i=g[P];l=g[U];u=g[R];C=j.x-h.x;o=c.x-h.x;x=j.y-h.y;A=c.y-h.y;
B=j.z-h.z;M=c.z-h.z;q=l.u-i.u;G=u.u-i.u;d=l.v-i.v;k=u.v-i.v;p=1/(q*k-G*d);t.set((k*C-d*o)*p,(k*x-d*A)*p,(k*B-d*M)*p);w.set((q*o-G*C)*p,(q*A-G*x)*p,(q*M-G*B)*p);s[D].addSelf(t);s[W].addSelf(t);s[J].addSelf(t);r[D].addSelf(w);r[W].addSelf(w);r[J].addSelf(w)}var b,e,f,g,h,j,c,i,l,u,C,o,x,A,B,M,q,G,d,k,p,s=[],r=[],t=new THREE.Vector3,w=new THREE.Vector3,v=new THREE.Vector3,H=new THREE.Vector3,y=new THREE.Vector3;b=0;for(e=this.vertices.length;b<e;b++){s[b]=new THREE.Vector3;r[b]=new THREE.Vector3}b=0;
for(e=this.faces.length;b<e;b++){f=this.faces[b];g=this.uvs[b];if(f instanceof THREE.Face3){a(this,f.a,f.b,f.c,0,1,2);this.vertices[f.a].normal.copy(f.vertexNormals[0]);this.vertices[f.b].normal.copy(f.vertexNormals[1]);this.vertices[f.c].normal.copy(f.vertexNormals[2])}else if(f instanceof THREE.Face4){a(this,f.a,f.b,f.c,0,1,2);a(this,f.a,f.b,f.d,0,1,3);this.vertices[f.a].normal.copy(f.vertexNormals[0]);this.vertices[f.b].normal.copy(f.vertexNormals[1]);this.vertices[f.c].normal.copy(f.vertexNormals[2]);
this.vertices[f.d].normal.copy(f.vertexNormals[3])}}b=0;for(e=this.vertices.length;b<e;b++){y.copy(this.vertices[b].normal);f=s[b];v.copy(f);v.subSelf(y.multiplyScalar(y.dot(f))).normalize();H.cross(this.vertices[b].normal,f);f=H.dot(r[b]);f=f<0?-1:1;this.vertices[b].tangent.set(v.x,v.y,v.z,f)}this.hasTangents=true},computeBoundingBox:function(){var a;if(this.vertices.length>0){this.boundingBox={x:[this.vertices[0].position.x,this.vertices[0].position.x],y:[this.vertices[0].position.y,this.vertices[0].position.y],
z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var b=1,e=this.vertices.length;b<e;b++){a=this.vertices[b];if(a.position.x<this.boundingBox.x[0])this.boundingBox.x[0]=a.position.x;else if(a.position.x>this.boundingBox.x[1])this.boundingBox.x[1]=a.position.x;if(a.position.y<this.boundingBox.y[0])this.boundingBox.y[0]=a.position.y;else if(a.position.y>this.boundingBox.y[1])this.boundingBox.y[1]=a.position.y;if(a.position.z<this.boundingBox.z[0])this.boundingBox.z[0]=a.position.z;else if(a.position.z>
this.boundingBox.z[1])this.boundingBox.z[1]=a.position.z}}},computeBoundingSphere:function(){for(var a=this.boundingSphere===null?0:this.boundingSphere.radius,b=0,e=this.vertices.length;b<e;b++)a=Math.max(a,this.vertices[b].position.length());this.boundingSphere={radius:a}},sortFacesByMaterial:function(){function a(u){var C=[];b=0;for(e=u.length;b<e;b++)u[b]==undefined?C.push("undefined"):C.push(u[b].toString());return C.join("_")}var b,e,f,g,h,j,c,i,l={};f=0;for(g=this.faces.length;f<g;f++){h=this.faces[f];
j=h.materials;c=a(j);if(l[c]==undefined)l[c]={hash:c,counter:0};i=l[c].hash+"_"+l[c].counter;if(this.geometryChunks[i]==undefined)this.geometryChunks[i]={faces:[],materials:j,vertices:0};h=h instanceof THREE.Face3?3:4;if(this.geometryChunks[i].vertices+h>65535){l[c].counter+=1;i=l[c].hash+"_"+l[c].counter;if(this.geometryChunks[i]==undefined)this.geometryChunks[i]={faces:[],materials:j,vertices:0}}this.geometryChunks[i].faces.push(f);this.geometryChunks[i].vertices+=h}},toString:function(){return"THREE.Geometry ( vertices: "+
this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}};
THREE.Camera=function(a,b,e,f){this.fov=a;this.aspect=b;this.near=e;this.far=f;this.position=new THREE.Vector3;this.target={position:new THREE.Vector3};this.autoUpdateMatrix=true;this.projectionMatrix=null;this.matrix=new THREE.Matrix4;this.up=new THREE.Vector3(0,1,0);this.translateX=function(g){g=this.target.position.clone().subSelf(this.position).normalize().multiplyScalar(g);g.cross(g.clone(),this.up);this.position.addSelf(g);this.target.position.addSelf(g)};this.translateZ=function(g){g=this.target.position.clone().subSelf(this.position).normalize().multiplyScalar(g);
this.position.subSelf(g);this.target.position.subSelf(g)};this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.updateProjectionMatrix=function(){this.projectionMatrix=THREE.Matrix4.makePerspective(this.fov,this.aspect,this.near,this.far)};this.updateProjectionMatrix()};THREE.Camera.prototype={toString:function(){return"THREE.Camera ( "+this.position+", "+this.target.position+" )"}};THREE.Light=function(a){this.color=new THREE.Color(a)};
THREE.AmbientLight=function(a){THREE.Light.call(this,a)};THREE.AmbientLight.prototype=new THREE.Light;THREE.AmbientLight.prototype.constructor=THREE.AmbientLight;THREE.DirectionalLight=function(a,b){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,1,0);this.intensity=b||1};THREE.DirectionalLight.prototype=new THREE.Light;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;
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.visible=this.autoUpdateMatrix=true};
THREE.Object3D.prototype={updateMatrix:function(){this.matrixPosition=THREE.Matrix4.translationMatrix(this.position.x,this.position.y,this.position.z);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};THREE.Particle=function(a){THREE.Object3D.call(this);this.materials=a instanceof Array?a:[a];this.autoUpdateMatrix=false};THREE.Particle.prototype=new THREE.Object3D;THREE.Particle.prototype.constructor=THREE.Particle;THREE.ParticleSystem=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.materials=b instanceof Array?b:[b];this.autoUpdateMatrix=false};
THREE.ParticleSystem.prototype=new THREE.Object3D;THREE.ParticleSystem.prototype.constructor=THREE.ParticleSystem;THREE.Line=function(a,b,e){THREE.Object3D.call(this);this.geometry=a;this.materials=b instanceof Array?b:[b];this.type=e!==undefined?e:THREE.LineContinuous};THREE.LineStrip=0;THREE.LinePieces=1;THREE.Line.prototype=new THREE.Object3D;THREE.Line.prototype.constructor=THREE.Line;
THREE.Mesh=function(a,b){THREE.Object3D.call(this);this.geometry=a;this.materials=b instanceof Array?b:[b];this.overdraw=this.doubleSided=this.flipSided=false;this.geometry.boundingSphere||this.geometry.computeBoundingSphere()};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;
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}};
THREE.LineBasicMaterial.prototype={toString:function(){return"THREE.LineBasicMaterial (<br/>color: "+this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>linewidth: "+this.linewidth+"<br/>linecap: "+this.linecap+"<br/>linejoin: "+this.linejoin+"<br/>)"}};
THREE.MeshBasicMaterial=function(a){this.id=THREE.MeshBasicMaterialCounter.value++;this.color=new THREE.Color(16777215);this.env_map=this.map=null;this.combine=THREE.MultiplyOperation;this.reflectivity=1;this.refraction_ratio=0.98;this.fog=true;this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=this.wireframe_linecap="round";if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.map!==undefined)this.map=
a.map;if(a.env_map!==undefined)this.env_map=a.env_map;if(a.combine!==undefined)this.combine=a.combine;if(a.reflectivity!==undefined)this.reflectivity=a.reflectivity;if(a.refraction_ratio!==undefined)this.refraction_ratio=a.refraction_ratio;if(a.fog!==undefined)this.fog=a.fog;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframe_linewidth!==
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}};
THREE.MeshBasicMaterial.prototype={toString:function(){return"THREE.MeshBasicMaterial (<br/>id: "+this.id+"<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>env_map: "+this.env_map+"<br/>combine: "+this.combine+"<br/>reflectivity: "+this.reflectivity+"<br/>refraction_ratio: "+this.refraction_ratio+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>wireframe: "+this.wireframe+"<br/>wireframe_linewidth: "+this.wireframe_linewidth+"<br/>wireframe_linecap: "+this.wireframe_linecap+
"<br/>wireframe_linejoin: "+this.wireframe_linejoin+"<br/>)"}};THREE.MeshBasicMaterialCounter={value:0};
THREE.MeshLambertMaterial=function(a){this.id=THREE.MeshLambertMaterialCounter.value++;this.color=new THREE.Color(16777215);this.env_map=this.map=null;this.combine=THREE.MultiplyOperation;this.reflectivity=1;this.refraction_ratio=0.98;this.fog=true;this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=this.wireframe_linecap="round";if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.map!==undefined)this.map=
a.map;if(a.env_map!==undefined)this.env_map=a.env_map;if(a.combine!==undefined)this.combine=a.combine;if(a.reflectivity!==undefined)this.reflectivity=a.reflectivity;if(a.refraction_ratio!==undefined)this.refraction_ratio=a.refraction_ratio;if(a.fog!==undefined)this.fog=a.fog;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframe_linewidth!==
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}};
THREE.MeshLambertMaterial.prototype={toString:function(){return"THREE.MeshLambertMaterial (<br/>id: "+this.id+"<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>env_map: "+this.env_map+"<br/>combine: "+this.combine+"<br/>reflectivity: "+this.reflectivity+"<br/>refraction_ratio: "+this.refraction_ratio+"<br/>opacity: "+this.opacity+"<br/>shading: "+this.shading+"<br/>blending: "+this.blending+"<br/>wireframe: "+this.wireframe+"<br/>wireframe_linewidth: "+this.wireframe_linewidth+"<br/>wireframe_linecap: "+
this.wireframe_linecap+"<br/>wireframe_linejoin: "+this.wireframe_linejoin+"<br/> )"}};THREE.MeshLambertMaterialCounter={value:0};
THREE.MeshPhongMaterial=function(a){this.id=THREE.MeshPhongMaterialCounter.value++;this.color=new THREE.Color(16777215);this.ambient=new THREE.Color(328965);this.specular=new THREE.Color(1118481);this.shininess=30;this.env_map=this.specular_map=this.map=null;this.combine=THREE.MultiplyOperation;this.reflectivity=1;this.refraction_ratio=0.98;this.fog=true;this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=
this.wireframe_linecap="round";if(a){if(a.color!==undefined)this.color=new THREE.Color(a.color);if(a.ambient!==undefined)this.ambient=new THREE.Color(a.ambient);if(a.specular!==undefined)this.specular=new THREE.Color(a.specular);if(a.shininess!==undefined)this.shininess=a.shininess;if(a.map!==undefined)this.map=a.map;if(a.specular_map!==undefined)this.specular_map=a.specular_map;if(a.env_map!==undefined)this.env_map=a.env_map;if(a.combine!==undefined)this.combine=a.combine;if(a.reflectivity!==undefined)this.reflectivity=
a.reflectivity;if(a.refraction_ratio!==undefined)this.refraction_ratio=a.refraction_ratio;if(a.fog!==undefined)this.fog=a.fog;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframe_linewidth!==undefined)this.wireframe_linewidth=a.wireframe_linewidth;if(a.wireframe_linecap!==undefined)this.wireframe_linecap=a.wireframe_linecap;if(a.wireframe_linejoin!==
undefined)this.wireframe_linejoin=a.wireframe_linejoin}};
THREE.MeshPhongMaterial.prototype={toString:function(){return"THREE.MeshPhongMaterial (<br/>id: "+this.id+"<br/>color: "+this.color+"<br/>ambient: "+this.ambient+"<br/>specular: "+this.specular+"<br/>shininess: "+this.shininess+"<br/>map: "+this.map+"<br/>specular_map: "+this.specular_map+"<br/>env_map: "+this.env_map+"<br/>combine: "+this.combine+"<br/>reflectivity: "+this.reflectivity+"<br/>refraction_ratio: "+this.refraction_ratio+"<br/>opacity: "+this.opacity+"<br/>shading: "+this.shading+"<br/>wireframe: "+
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};
THREE.MeshDepthMaterial=function(a){this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=this.wireframe_linecap="round";if(a){if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}};THREE.MeshDepthMaterial.prototype={toString:function(){return"THREE.MeshDepthMaterial"}};
THREE.MeshNormalMaterial=function(a){this.opacity=1;this.shading=THREE.FlatShading;this.blending=THREE.NormalBlending;if(a){if(a.opacity!==undefined)this.opacity=a.opacity;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending}};THREE.MeshNormalMaterial.prototype={toString:function(){return"THREE.MeshNormalMaterial"}};THREE.MeshFaceMaterial=function(){};THREE.MeshFaceMaterial.prototype={toString:function(){return"THREE.MeshFaceMaterial"}};
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!==
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}};
THREE.MeshShaderMaterial.prototype={toString:function(){return"THREE.MeshShaderMaterial (<br/>id: "+this.id+"<br/>blending: "+this.blending+"<br/>wireframe: "+this.wireframe+"<br/>wireframe_linewidth: "+this.wireframe_linewidth+"<br/>wireframe_linecap: "+this.wireframe_linecap+"<br/>wireframe_linejoin: "+this.wireframe_linejoin+"<br/>)"}};THREE.MeshShaderMaterialCounter={value:0};
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}};
THREE.ParticleBasicMaterial.prototype={toString:function(){return"THREE.ParticleBasicMaterial (<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>)"}};THREE.ParticleCircleMaterial=function(a){this.color=new THREE.Color(16777215);this.opacity=1;this.blending=THREE.NormalBlending;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}};
THREE.ParticleCircleMaterial.prototype={toString:function(){return"THREE.ParticleCircleMaterial (<br/>color: "+this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>)"}};THREE.ParticleDOMMaterial=function(a){this.domElement=a};THREE.ParticleDOMMaterial.prototype={toString:function(){return"THREE.ParticleDOMMaterial ( domElement: "+this.domElement+" )"}};
THREE.Texture=function(a,b,e,f,g,h){this.image=a;this.mapping=b!==undefined?b:new THREE.UVMapping;this.wrap_s=e!==undefined?e:THREE.ClampToEdgeWrapping;this.wrap_t=f!==undefined?f:THREE.ClampToEdgeWrapping;this.mag_filter=g!==undefined?g:THREE.LinearFilter;this.min_filter=h!==undefined?h:THREE.LinearMipMapLinearFilter};
THREE.Texture.prototype={clone:function(){return new THREE.Texture(this.image,this.mapping,this.wrap_s,this.wrap_t,this.mag_filter,this.min_filter)},toString:function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>wrap_s: "+this.wrap_s+"<br/>wrap_t: "+this.wrap_t+"<br/>mag_filter: "+this.mag_filter+"<br/>min_filter: "+this.min_filter+"<br/>)"}};THREE.MultiplyOperation=0;THREE.MixOperation=1;THREE.RepeatWrapping=0;THREE.ClampToEdgeWrapping=1;THREE.MirroredRepeatWrapping=2;
THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLinearFilter=5;THREE.LinearFilter=6;THREE.LinearMipMapNearestFilter=7;THREE.LinearMipMapLinearFilter=8;var Uniforms={clone:function(a){var b,e,f,g={};for(b in a){g[b]={};for(e in a[b]){f=a[b][e];g[b][e]=f instanceof THREE.Color||f instanceof THREE.Vector3||f instanceof THREE.Texture?f.clone():f}}return g},merge:function(a){var b,e,f,g={};for(b=0;b<a.length;b++){f=this.clone(a[b]);for(e in f)g[e]=f[e]}return g}};
THREE.CubeReflectionMapping=function(){};THREE.CubeRefractionMapping=function(){};THREE.LatitudeReflectionMapping=function(){};THREE.LatitudeRefractionMapping=function(){};THREE.SphericalReflectionMapping=function(){};THREE.SphericalRefractionMapping=function(){};THREE.UVMapping=function(){};
THREE.Scene=function(){this.objects=[];this.lights=[];this.fog=null;this.addObject=function(a){this.objects.indexOf(a)===-1&&this.objects.push(a)};this.removeObject=function(a){a=this.objects.indexOf(a);a!==-1&&this.objects.splice(a,1)};this.addLight=function(a){this.lights.indexOf(a)===-1&&this.lights.push(a)};this.removeLight=function(a){a=this.lights.indexOf(a);a!==-1&&this.lights.splice(a,1)};this.toString=function(){return"THREE.Scene ( "+this.objects+" )"}};
THREE.Fog=function(a,b,e){this.color=new THREE.Color(a);this.near=b||1;this.far=e||1E3};THREE.FogExp2=function(a,b){this.color=new THREE.Color(a);this.density=b||2.5E-4};
THREE.Projector=function(){function a(r,t){return t.z-r.z}function b(r,t){var w=0,v=1,H=r.z+r.w,y=t.z+t.w,n=-r.z+r.w,D=-t.z+t.w;if(H>=0&&y>=0&&n>=0&&D>=0)return true;else if(H<0&&y<0||n<0&&D<0)return false;else{if(H<0)w=Math.max(w,H/(H-y));else if(y<0)v=Math.min(v,H/(H-y));if(n<0)w=Math.max(w,n/(n-D));else if(D<0)v=Math.min(v,n/(n-D));if(v<w)return false;else{r.lerpSelf(t,w);t.lerpSelf(r,1-v);return true}}}var e,f,g=[],h,j,c,i=[],l,u,C=[],o,x,A=[],B=new THREE.Vector4,M=new THREE.Vector4,q=new THREE.Matrix4,
G=new THREE.Matrix4,d=[],k=new THREE.Vector4,p=new THREE.Vector4,s;this.projectObjects=function(r,t,w){var v=[],H,y;f=0;q.multiply(t.projectionMatrix,t.matrix);d[0]=new THREE.Vector4(q.n41-q.n11,q.n42-q.n12,q.n43-q.n13,q.n44-q.n14);d[1]=new THREE.Vector4(q.n41+q.n11,q.n42+q.n12,q.n43+q.n13,q.n44+q.n14);d[2]=new THREE.Vector4(q.n41+q.n21,q.n42+q.n22,q.n43+q.n23,q.n44+q.n24);d[3]=new THREE.Vector4(q.n41-q.n21,q.n42-q.n22,q.n43-q.n23,q.n44-q.n24);d[4]=new THREE.Vector4(q.n41-q.n31,q.n42-q.n32,q.n43-
q.n33,q.n44-q.n34);d[5]=new THREE.Vector4(q.n41+q.n31,q.n42+q.n32,q.n43+q.n33,q.n44+q.n34);t=0;for(H=d.length;t<H;t++){y=d[t];y.divideScalar(Math.sqrt(y.x*y.x+y.y*y.y+y.z*y.z))}H=r.objects;r=0;for(t=H.length;r<t;r++){y=H[r];var n;if(!(n=!y.visible)){if(n=y instanceof THREE.Mesh){a:{n=void 0;for(var D=y.position,W=-y.geometry.boundingSphere.radius*Math.max(y.scale.x,Math.max(y.scale.y,y.scale.z)),J=0;J<6;J++){n=d[J].x*D.x+d[J].y*D.y+d[J].z*D.z+d[J].w;if(n<=W){n=false;break a}}n=true}n=!n}n=n}if(!n){e=
g[f]=g[f]||new THREE.RenderableObject;B.copy(y.position);q.multiplyVector3(B);e.object=y;e.z=B.z;v.push(e);f++}}w&&v.sort(a);return v};this.projectScene=function(r,t,w){var v=[],H=t.near,y=t.far,n,D,W,J,P,U,R,$,X,L,O,Z,S,z,N,Q;c=u=x=0;t.autoUpdateMatrix&&t.updateMatrix();q.multiply(t.projectionMatrix,t.matrix);U=this.projectObjects(r,t,true);r=0;for(n=U.length;r<n;r++){R=U[r].object;if(R.visible){R.autoUpdateMatrix&&R.updateMatrix();$=R.matrix;X=R.rotationMatrix;L=R.materials;O=R.overdraw;if(R instanceof
THREE.Mesh){Z=R.geometry;S=Z.vertices;D=0;for(W=S.length;D<W;D++){z=S[D];z.positionWorld.copy(z.position);$.multiplyVector3(z.positionWorld);J=z.positionScreen;J.copy(z.positionWorld);q.multiplyVector4(J);J.x/=J.w;J.y/=J.w;z.__visible=J.z>H&&J.z<y}Z=Z.faces;D=0;for(W=Z.length;D<W;D++){z=Z[D];if(z instanceof THREE.Face3){J=S[z.a];P=S[z.b];N=S[z.c];if(J.__visible&&P.__visible&&N.__visible)if(R.doubleSided||R.flipSided!=(N.positionScreen.x-J.positionScreen.x)*(P.positionScreen.y-J.positionScreen.y)-
(N.positionScreen.y-J.positionScreen.y)*(P.positionScreen.x-J.positionScreen.x)<0){h=i[c]=i[c]||new THREE.RenderableFace3;h.v1.positionWorld.copy(J.positionWorld);h.v2.positionWorld.copy(P.positionWorld);h.v3.positionWorld.copy(N.positionWorld);h.v1.positionScreen.copy(J.positionScreen);h.v2.positionScreen.copy(P.positionScreen);h.v3.positionScreen.copy(N.positionScreen);h.normalWorld.copy(z.normal);X.multiplyVector3(h.normalWorld);h.centroidWorld.copy(z.centroid);$.multiplyVector3(h.centroidWorld);
h.centroidScreen.copy(h.centroidWorld);q.multiplyVector3(h.centroidScreen);N=z.vertexNormals;s=h.vertexNormalsWorld;J=0;for(P=N.length;J<P;J++){Q=s[J]=s[J]||new THREE.Vector3;Q.copy(N[J]);X.multiplyVector3(Q)}h.z=h.centroidScreen.z;h.meshMaterials=L;h.faceMaterials=z.materials;h.overdraw=O;if(R.geometry.uvs[D]){h.uvs[0]=R.geometry.uvs[D][0];h.uvs[1]=R.geometry.uvs[D][1];h.uvs[2]=R.geometry.uvs[D][2]}v.push(h);c++}}else if(z instanceof THREE.Face4){J=S[z.a];P=S[z.b];N=S[z.c];Q=S[z.d];if(J.__visible&&
P.__visible&&N.__visible&&Q.__visible)if(R.doubleSided||R.flipSided!=((Q.positionScreen.x-J.positionScreen.x)*(P.positionScreen.y-J.positionScreen.y)-(Q.positionScreen.y-J.positionScreen.y)*(P.positionScreen.x-J.positionScreen.x)<0||(P.positionScreen.x-N.positionScreen.x)*(Q.positionScreen.y-N.positionScreen.y)-(P.positionScreen.y-N.positionScreen.y)*(Q.positionScreen.x-N.positionScreen.x)<0)){h=i[c]=i[c]||new THREE.RenderableFace3;h.v1.positionWorld.copy(J.positionWorld);h.v2.positionWorld.copy(P.positionWorld);
h.v3.positionWorld.copy(Q.positionWorld);h.v1.positionScreen.copy(J.positionScreen);h.v2.positionScreen.copy(P.positionScreen);h.v3.positionScreen.copy(Q.positionScreen);h.normalWorld.copy(z.normal);X.multiplyVector3(h.normalWorld);h.centroidWorld.copy(z.centroid);$.multiplyVector3(h.centroidWorld);h.centroidScreen.copy(h.centroidWorld);q.multiplyVector3(h.centroidScreen);h.z=h.centroidScreen.z;h.meshMaterials=L;h.faceMaterials=z.materials;h.overdraw=O;if(R.geometry.uvs[D]){h.uvs[0]=R.geometry.uvs[D][0];
h.uvs[1]=R.geometry.uvs[D][1];h.uvs[2]=R.geometry.uvs[D][3]}v.push(h);c++;j=i[c]=i[c]||new THREE.RenderableFace3;j.v1.positionWorld.copy(P.positionWorld);j.v2.positionWorld.copy(N.positionWorld);j.v3.positionWorld.copy(Q.positionWorld);j.v1.positionScreen.copy(P.positionScreen);j.v2.positionScreen.copy(N.positionScreen);j.v3.positionScreen.copy(Q.positionScreen);j.normalWorld.copy(h.normalWorld);j.centroidWorld.copy(h.centroidWorld);j.centroidScreen.copy(h.centroidScreen);j.z=j.centroidScreen.z;j.meshMaterials=
L;j.faceMaterials=z.materials;j.overdraw=O;if(R.geometry.uvs[D]){j.uvs[0]=R.geometry.uvs[D][1];j.uvs[1]=R.geometry.uvs[D][2];j.uvs[2]=R.geometry.uvs[D][3]}v.push(j);c++}}}}else if(R instanceof THREE.Line){G.multiply(q,$);S=R.geometry.vertices;z=S[0];z.positionScreen.copy(z.position);G.multiplyVector4(z.positionScreen);D=1;for(W=S.length;D<W;D++){J=S[D];J.positionScreen.copy(J.position);G.multiplyVector4(J.positionScreen);P=S[D-1];k.copy(J.positionScreen);p.copy(P.positionScreen);if(b(k,p)){k.multiplyScalar(1/
k.w);p.multiplyScalar(1/p.w);l=C[u]=C[u]||new THREE.RenderableLine;l.v1.positionScreen.copy(k);l.v2.positionScreen.copy(p);l.z=Math.max(k.z,p.z);l.materials=R.materials;v.push(l);u++}}}else if(R instanceof THREE.Particle){M.set(R.position.x,R.position.y,R.position.z,1);q.multiplyVector4(M);M.z/=M.w;if(M.z>0&&M.z<1){o=A[x]=A[x]||new THREE.RenderableParticle;o.x=M.x/M.w;o.y=M.y/M.w;o.z=M.z;o.rotation=R.rotation.z;o.scale.x=R.scale.x*Math.abs(o.x-(M.x+t.projectionMatrix.n11)/(M.w+t.projectionMatrix.n14));
o.scale.y=R.scale.y*Math.abs(o.y-(M.y+t.projectionMatrix.n22)/(M.w+t.projectionMatrix.n24));o.materials=R.materials;v.push(o);x++}}}}w&&v.sort(a);return v};this.unprojectVector=function(r,t){var w=new THREE.Matrix4;w.multiply(THREE.Matrix4.makeInvert(t.matrix),THREE.Matrix4.makeInvert(t.projectionMatrix));w.multiplyVector3(r);return r}};
THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,e,f,g,h;this.domElement=document.createElement("div");this.setSize=function(j,c){e=j;f=c;g=e/2;h=f/2};this.render=function(j,c){var i,l,u,C,o,x,A,B;a=b.projectScene(j,c);i=0;for(l=a.length;i<l;i++){o=a[i];if(o instanceof THREE.RenderableParticle){A=o.x*g+g;B=o.y*h+h;u=0;for(C=o.material.length;u<C;u++){x=o.material[u];if(x instanceof THREE.ParticleDOMMaterial){x=x.domElement;x.style.left=A+"px";x.style.top=B+"px"}}}}}};
THREE.CanvasRenderer=function(){function a(ia){if(o!=ia)l.globalAlpha=o=ia}function b(ia){if(x!=ia){switch(ia){case THREE.NormalBlending:l.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:l.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:l.globalCompositeOperation="darker"}x=ia}}var e=null,f=new THREE.Projector,g=document.createElement("canvas"),h,j,c,i,l=g.getContext("2d"),u=null,C=null,o=1,x=0,A=null,B=null,M=1,q,G,d,k,p,s,r,t,w,v=new THREE.Color,
H=new THREE.Color,y=new THREE.Color,n=new THREE.Color,D=new THREE.Color,W,J,P,U,R,$,X,L,O,Z=new THREE.Rectangle,S=new THREE.Rectangle,z=new THREE.Rectangle,N=false,Q=new THREE.Color,ea=new THREE.Color,da=new THREE.Color,m=new THREE.Color,F=Math.PI*2,E=new THREE.Vector3,T,aa,ka,ga,ra,ta,va=16;T=document.createElement("canvas");T.width=T.height=2;aa=T.getContext("2d");aa.fillStyle="rgba(0,0,0,1)";aa.fillRect(0,0,2,2);ka=aa.getImageData(0,0,2,2);ga=ka.data;ra=document.createElement("canvas");ra.width=
ra.height=va;ta=ra.getContext("2d");ta.translate(-va/2,-va/2);ta.scale(va,va);va--;this.domElement=g;this.sortElements=this.sortObjects=this.autoClear=true;this.setSize=function(ia,sa){h=ia;j=sa;c=h/2;i=j/2;g.width=h;g.height=j;Z.set(-c,-i,c,i)};this.setClearColor=function(ia,sa){u=ia!==null?new THREE.Color(ia):null;C=sa;S.set(-c,-i,c,i);l.setTransform(1,0,0,-1,c,i);this.clear()};this.clear=function(){if(!S.isEmpty()){S.inflate(1);S.minSelf(Z);if(u!==null){b(THREE.NormalBlending);a(1);l.fillStyle=
"rgba("+Math.floor(u.r*255)+","+Math.floor(u.g*255)+","+Math.floor(u.b*255)+","+C+")";l.fillRect(S.getX(),S.getY(),S.getWidth(),S.getHeight())}else l.clearRect(S.getX(),S.getY(),S.getWidth(),S.getHeight());S.empty()}};this.render=function(ia,sa){function Ma(I){var ba,Y,K,V=I.lights;ea.setRGB(0,0,0);da.setRGB(0,0,0);m.setRGB(0,0,0);I=0;for(ba=V.length;I<ba;I++){Y=V[I];K=Y.color;if(Y instanceof THREE.AmbientLight){ea.r+=K.r;ea.g+=K.g;ea.b+=K.b}else if(Y instanceof THREE.DirectionalLight){da.r+=K.r;
da.g+=K.g;da.b+=K.b}else if(Y instanceof THREE.PointLight){m.r+=K.r;m.g+=K.g;m.b+=K.b}}}function Aa(I,ba,Y,K){var V,ca,ha,ja,la=I.lights;I=0;for(V=la.length;I<V;I++){ca=la[I];ha=ca.color;ja=ca.intensity;if(ca instanceof THREE.DirectionalLight){ca=Y.dot(ca.position)*ja;if(ca>0){K.r+=ha.r*ca;K.g+=ha.g*ca;K.b+=ha.b*ca}}else if(ca instanceof THREE.PointLight){E.sub(ca.position,ba);E.normalize();ca=Y.dot(E)*ja;if(ca>0){K.r+=ha.r*ca;K.g+=ha.g*ca;K.b+=ha.b*ca}}}}function Na(I,ba,Y){if(Y.opacity!=0){a(Y.opacity);
b(Y.blending);var K,V,ca,ha,ja,la;if(Y instanceof THREE.ParticleBasicMaterial){if(Y.map){ha=Y.map;ja=ha.width>>1;la=ha.height>>1;V=ba.scale.x*c;ca=ba.scale.y*i;Y=V*ja;K=ca*la;z.set(I.x-Y,I.y-K,I.x+Y,I.y+K);if(Z.instersects(z)){l.save();l.translate(I.x,I.y);l.rotate(-ba.rotation);l.scale(V,-ca);l.translate(-ja,-la);l.drawImage(ha,0,0);l.restore()}}}else if(Y instanceof THREE.ParticleCircleMaterial){if(N){Q.r=ea.r+da.r+m.r;Q.g=ea.g+da.g+m.g;Q.b=ea.b+da.b+m.b;v.r=Y.color.r*Q.r;v.g=Y.color.g*Q.g;v.b=
Y.color.b*Q.b;v.updateStyleString()}else v.__styleString=Y.color.__styleString;Y=ba.scale.x*c;K=ba.scale.y*i;z.set(I.x-Y,I.y-K,I.x+Y,I.y+K);if(Z.instersects(z)){V=v.__styleString;if(B!=V)l.fillStyle=B=V;l.save();l.translate(I.x,I.y);l.rotate(-ba.rotation);l.scale(Y,K);l.beginPath();l.arc(0,0,1,0,F,true);l.closePath();l.fill();l.restore()}}}}function Oa(I,ba,Y,K){if(K.opacity!=0){a(K.opacity);b(K.blending);l.beginPath();l.moveTo(I.positionScreen.x,I.positionScreen.y);l.lineTo(ba.positionScreen.x,ba.positionScreen.y);
l.closePath();if(K instanceof THREE.LineBasicMaterial){v.__styleString=K.color.__styleString;I=K.linewidth;if(M!=I)l.lineWidth=M=I;I=v.__styleString;if(A!=I)l.strokeStyle=A=I;l.stroke();z.inflate(K.linewidth*2)}}}function Ia(I,ba,Y,K,V,ca){if(V.opacity!=0){a(V.opacity);b(V.blending);k=I.positionScreen.x;p=I.positionScreen.y;s=ba.positionScreen.x;r=ba.positionScreen.y;t=Y.positionScreen.x;w=Y.positionScreen.y;l.beginPath();l.moveTo(k,p);l.lineTo(s,r);l.lineTo(t,w);l.lineTo(k,p);l.closePath();if(V instanceof
THREE.MeshBasicMaterial)if(V.map)V.map.image.loaded&&V.map.mapping instanceof THREE.UVMapping&&xa(k,p,s,r,t,w,V.map.image,K.uvs[0].u,K.uvs[0].v,K.uvs[1].u,K.uvs[1].v,K.uvs[2].u,K.uvs[2].v);else if(V.env_map){if(V.env_map.image.loaded)if(V.env_map.mapping instanceof THREE.SphericalReflectionMapping){I=sa.matrix;E.copy(K.vertexNormalsWorld[0]);U=(E.x*I.n11+E.y*I.n12+E.z*I.n13)*0.5+0.5;R=-(E.x*I.n21+E.y*I.n22+E.z*I.n23)*0.5+0.5;E.copy(K.vertexNormalsWorld[1]);$=(E.x*I.n11+E.y*I.n12+E.z*I.n13)*0.5+0.5;
X=-(E.x*I.n21+E.y*I.n22+E.z*I.n23)*0.5+0.5;E.copy(K.vertexNormalsWorld[2]);L=(E.x*I.n11+E.y*I.n12+E.z*I.n13)*0.5+0.5;O=-(E.x*I.n21+E.y*I.n22+E.z*I.n23)*0.5+0.5;xa(k,p,s,r,t,w,V.env_map.image,U,R,$,X,L,O)}}else V.wireframe?Ba(V.color.__styleString,V.wireframe_linewidth):Ca(V.color.__styleString);else if(V instanceof THREE.MeshLambertMaterial){if(V.map&&!V.wireframe){V.map.mapping instanceof THREE.UVMapping&&xa(k,p,s,r,t,w,V.map.image,K.uvs[0].u,K.uvs[0].v,K.uvs[1].u,K.uvs[1].v,K.uvs[2].u,K.uvs[2].v);
b(THREE.SubtractiveBlending)}if(N)if(!V.wireframe&&V.shading==THREE.SmoothShading&&K.vertexNormalsWorld.length==3){H.r=y.r=n.r=ea.r;H.g=y.g=n.g=ea.g;H.b=y.b=n.b=ea.b;Aa(ca,K.v1.positionWorld,K.vertexNormalsWorld[0],H);Aa(ca,K.v2.positionWorld,K.vertexNormalsWorld[1],y);Aa(ca,K.v3.positionWorld,K.vertexNormalsWorld[2],n);D.r=(y.r+n.r)*0.5;D.g=(y.g+n.g)*0.5;D.b=(y.b+n.b)*0.5;P=Ja(H,y,n,D);xa(k,p,s,r,t,w,P,0,0,1,0,0,1)}else{Q.r=ea.r;Q.g=ea.g;Q.b=ea.b;Aa(ca,K.centroidWorld,K.normalWorld,Q);v.r=V.color.r*
Q.r;v.g=V.color.g*Q.g;v.b=V.color.b*Q.b;v.updateStyleString();V.wireframe?Ba(v.__styleString,V.wireframe_linewidth):Ca(v.__styleString)}else V.wireframe?Ba(V.color.__styleString,V.wireframe_linewidth):Ca(V.color.__styleString)}else if(V instanceof THREE.MeshDepthMaterial){W=sa.near;J=sa.far;H.r=H.g=H.b=1-Ea(I.positionScreen.z,W,J);y.r=y.g=y.b=1-Ea(ba.positionScreen.z,W,J);n.r=n.g=n.b=1-Ea(Y.positionScreen.z,W,J);D.r=(y.r+n.r)*0.5;D.g=(y.g+n.g)*0.5;D.b=(y.b+n.b)*0.5;P=Ja(H,y,n,D);xa(k,p,s,r,t,w,P,
0,0,1,0,0,1)}else if(V instanceof THREE.MeshNormalMaterial){v.r=Fa(K.normalWorld.x);v.g=Fa(K.normalWorld.y);v.b=Fa(K.normalWorld.z);v.updateStyleString();V.wireframe?Ba(v.__styleString,V.wireframe_linewidth):Ca(v.__styleString)}}}function Ba(I,ba){if(A!=I)l.strokeStyle=A=I;if(M!=ba)l.lineWidth=M=ba;l.stroke();z.inflate(ba*2)}function Ca(I){if(B!=I)l.fillStyle=B=I;l.fill()}function xa(I,ba,Y,K,V,ca,ha,ja,la,oa,ma,pa,ya){var ua,qa;ua=ha.width-1;qa=ha.height-1;ja*=ua;la*=qa;oa*=ua;ma*=qa;pa*=ua;ya*=
qa;Y-=I;K-=ba;V-=I;ca-=ba;oa-=ja;ma-=la;pa-=ja;ya-=la;qa=1/(oa*ya-pa*ma);ua=(ya*Y-ma*V)*qa;ma=(ya*K-ma*ca)*qa;Y=(oa*V-pa*Y)*qa;K=(oa*ca-pa*K)*qa;I=I-ua*ja-Y*la;ba=ba-ma*ja-K*la;l.save();l.transform(ua,ma,Y,K,I,ba);l.clip();l.drawImage(ha,0,0);l.restore()}function Ja(I,ba,Y,K){var V=~~(I.r*255),ca=~~(I.g*255);I=~~(I.b*255);var ha=~~(ba.r*255),ja=~~(ba.g*255);ba=~~(ba.b*255);var la=~~(Y.r*255),oa=~~(Y.g*255);Y=~~(Y.b*255);var ma=~~(K.r*255),pa=~~(K.g*255);K=~~(K.b*255);ga[0]=V<0?0:V>255?255:V;ga[1]=
ca<0?0:ca>255?255:ca;ga[2]=I<0?0:I>255?255:I;ga[4]=ha<0?0:ha>255?255:ha;ga[5]=ja<0?0:ja>255?255:ja;ga[6]=ba<0?0:ba>255?255:ba;ga[8]=la<0?0:la>255?255:la;ga[9]=oa<0?0:oa>255?255:oa;ga[10]=Y<0?0:Y>255?255:Y;ga[12]=ma<0?0:ma>255?255:ma;ga[13]=pa<0?0:pa>255?255:pa;ga[14]=K<0?0:K>255?255:K;aa.putImageData(ka,0,0);ta.drawImage(T,0,0);return ra}function Ea(I,ba,Y){I=(I-ba)/(Y-ba);return I*I*(3-2*I)}function Fa(I){I=(I+1)*0.5;return I<0?0:I>1?1:I}function Ga(I,ba){var Y=ba.x-I.x,K=ba.y-I.y,V=1/Math.sqrt(Y*
Y+K*K);Y*=V;K*=V;ba.x+=Y;ba.y+=K;I.x-=Y;I.y-=K}var Da,Ka,fa,na,wa,Ha,La,za;l.setTransform(1,0,0,-1,c,i);this.autoClear&&this.clear();e=f.projectScene(ia,sa,this.sortElements);(N=ia.lights.length>0)&&Ma(ia);Da=0;for(Ka=e.length;Da<Ka;Da++){fa=e[Da];z.empty();if(fa instanceof THREE.RenderableParticle){q=fa;q.x*=c;q.y*=i;na=0;for(wa=fa.materials.length;na<wa;na++)Na(q,fa,fa.materials[na],ia)}else if(fa instanceof THREE.RenderableLine){q=fa.v1;G=fa.v2;q.positionScreen.x*=c;q.positionScreen.y*=i;G.positionScreen.x*=
c;G.positionScreen.y*=i;z.addPoint(q.positionScreen.x,q.positionScreen.y);z.addPoint(G.positionScreen.x,G.positionScreen.y);if(Z.instersects(z)){na=0;for(wa=fa.materials.length;na<wa;)Oa(q,G,fa,fa.materials[na++],ia)}}else if(fa instanceof THREE.RenderableFace3){q=fa.v1;G=fa.v2;d=fa.v3;q.positionScreen.x*=c;q.positionScreen.y*=i;G.positionScreen.x*=c;G.positionScreen.y*=i;d.positionScreen.x*=c;d.positionScreen.y*=i;if(fa.overdraw){Ga(q.positionScreen,G.positionScreen);Ga(G.positionScreen,d.positionScreen);
Ga(d.positionScreen,q.positionScreen)}z.add3Points(q.positionScreen.x,q.positionScreen.y,G.positionScreen.x,G.positionScreen.y,d.positionScreen.x,d.positionScreen.y);if(Z.instersects(z)){na=0;for(wa=fa.meshMaterials.length;na<wa;){za=fa.meshMaterials[na++];if(za instanceof THREE.MeshFaceMaterial){Ha=0;for(La=fa.faceMaterials.length;Ha<La;)(za=fa.faceMaterials[Ha++])&&Ia(q,G,d,fa,za,ia)}else Ia(q,G,d,fa,za,ia)}}}S.addRectangle(z)}l.setTransform(1,0,0,1,0,0)}};
THREE.SVGRenderer=function(){function a(U,R,$){var X,L,O,Z;X=0;for(L=U.lights.length;X<L;X++){O=U.lights[X];if(O instanceof THREE.DirectionalLight){Z=R.normalWorld.dot(O.position)*O.intensity;if(Z>0){$.r+=O.color.r*Z;$.g+=O.color.g*Z;$.b+=O.color.b*Z}}else if(O instanceof THREE.PointLight){w.sub(O.position,R.centroidWorld);w.normalize();Z=R.normalWorld.dot(w)*O.intensity;if(Z>0){$.r+=O.color.r*Z;$.g+=O.color.g*Z;$.b+=O.color.b*Z}}}}function b(U,R,$,X,L,O){n=f(D++);n.setAttribute("d","M "+U.positionScreen.x+
" "+U.positionScreen.y+" L "+R.positionScreen.x+" "+R.positionScreen.y+" L "+$.positionScreen.x+","+$.positionScreen.y+"z");if(L instanceof THREE.MeshBasicMaterial)d.__styleString=L.color.__styleString;else if(L instanceof THREE.MeshLambertMaterial)if(G){k.r=p.r;k.g=p.g;k.b=p.b;a(O,X,k);d.r=L.color.r*k.r;d.g=L.color.g*k.g;d.b=L.color.b*k.b;d.updateStyleString()}else d.__styleString=L.color.__styleString;else if(L instanceof THREE.MeshDepthMaterial){t=1-L.__2near/(L.__farPlusNear-X.z*L.__farMinusNear);
d.setRGB(t,t,t)}else L instanceof THREE.MeshNormalMaterial&&d.setRGB(g(X.normalWorld.x),g(X.normalWorld.y),g(X.normalWorld.z));L.wireframe?n.setAttribute("style","fill: none; stroke: "+d.__styleString+"; stroke-width: "+L.wireframe_linewidth+"; stroke-opacity: "+L.opacity+"; stroke-linecap: "+L.wireframe_linecap+"; stroke-linejoin: "+L.wireframe_linejoin):n.setAttribute("style","fill: "+d.__styleString+"; fill-opacity: "+L.opacity);c.appendChild(n)}function e(U,R,$,X,L,O,Z){n=f(D++);n.setAttribute("d",
"M "+U.positionScreen.x+" "+U.positionScreen.y+" L "+R.positionScreen.x+" "+R.positionScreen.y+" L "+$.positionScreen.x+","+$.positionScreen.y+" L "+X.positionScreen.x+","+X.positionScreen.y+"z");if(O instanceof THREE.MeshBasicMaterial)d.__styleString=O.color.__styleString;else if(O instanceof THREE.MeshLambertMaterial)if(G){k.r=p.r;k.g=p.g;k.b=p.b;a(Z,L,k);d.r=O.color.r*k.r;d.g=O.color.g*k.g;d.b=O.color.b*k.b;d.updateStyleString()}else d.__styleString=O.color.__styleString;else if(O instanceof THREE.MeshDepthMaterial){t=
1-O.__2near/(O.__farPlusNear-L.z*O.__farMinusNear);d.setRGB(t,t,t)}else O instanceof THREE.MeshNormalMaterial&&d.setRGB(g(L.normalWorld.x),g(L.normalWorld.y),g(L.normalWorld.z));O.wireframe?n.setAttribute("style","fill: none; stroke: "+d.__styleString+"; stroke-width: "+O.wireframe_linewidth+"; stroke-opacity: "+O.opacity+"; stroke-linecap: "+O.wireframe_linecap+"; stroke-linejoin: "+O.wireframe_linejoin):n.setAttribute("style","fill: "+d.__styleString+"; fill-opacity: "+O.opacity);c.appendChild(n)}
function f(U){if(v[U]==null){v[U]=document.createElementNS("http://www.w3.org/2000/svg","path");P==0&&v[U].setAttribute("shape-rendering","crispEdges");return v[U]}return v[U]}function g(U){return U<0?Math.min((1+U)*0.5,0.5):0.5+Math.min(U*0.5,0.5)}var h=null,j=new THREE.Projector,c=document.createElementNS("http://www.w3.org/2000/svg","svg"),i,l,u,C,o,x,A,B,M=new THREE.Rectangle,q=new THREE.Rectangle,G=false,d=new THREE.Color(16777215),k=new THREE.Color(16777215),p=new THREE.Color(0),s=new THREE.Color(0),
r=new THREE.Color(0),t,w=new THREE.Vector3,v=[],H=[],y=[],n,D,W,J,P=1;this.domElement=c;this.sortElements=this.sortObjects=this.autoClear=true;this.setQuality=function(U){switch(U){case "high":P=1;break;case "low":P=0}};this.setSize=function(U,R){i=U;l=R;u=i/2;C=l/2;c.setAttribute("viewBox",-u+" "+-C+" "+i+" "+l);c.setAttribute("width",i);c.setAttribute("height",l);M.set(-u,-C,u,C)};this.clear=function(){for(;c.childNodes.length>0;)c.removeChild(c.childNodes[0])};this.render=function(U,R){var $,X,
L,O,Z,S,z,N;this.autoClear&&this.clear();h=j.projectScene(U,R,this.sortElements);J=W=D=0;if(G=U.lights.length>0){z=U.lights;p.setRGB(0,0,0);s.setRGB(0,0,0);r.setRGB(0,0,0);$=0;for(X=z.length;$<X;$++){L=z[$];O=L.color;if(L instanceof THREE.AmbientLight){p.r+=O.r;p.g+=O.g;p.b+=O.b}else if(L instanceof THREE.DirectionalLight){s.r+=O.r;s.g+=O.g;s.b+=O.b}else if(L instanceof THREE.PointLight){r.r+=O.r;r.g+=O.g;r.b+=O.b}}}$=0;for(X=h.length;$<X;$++){z=h[$];q.empty();if(z instanceof THREE.RenderableParticle){o=
z;o.x*=u;o.y*=-C;L=0;for(O=z.materials.length;L<O;L++)if(N=z.materials[L]){Z=o;S=z;N=N;var Q=W++;if(H[Q]==null){H[Q]=document.createElementNS("http://www.w3.org/2000/svg","circle");P==0&&H[Q].setAttribute("shape-rendering","crispEdges")}n=H[Q];n.setAttribute("cx",Z.x);n.setAttribute("cy",Z.y);n.setAttribute("r",S.scale.x*u);if(N instanceof THREE.ParticleCircleMaterial){if(G){k.r=p.r+s.r+r.r;k.g=p.g+s.g+r.g;k.b=p.b+s.b+r.b;d.r=N.color.r*k.r;d.g=N.color.g*k.g;d.b=N.color.b*k.b;d.updateStyleString()}else d=
N.color;n.setAttribute("style","fill: "+d.__styleString)}c.appendChild(n)}}else if(z instanceof THREE.RenderableLine){o=z.v1;x=z.v2;o.positionScreen.x*=u;o.positionScreen.y*=-C;x.positionScreen.x*=u;x.positionScreen.y*=-C;q.addPoint(o.positionScreen.x,o.positionScreen.y);q.addPoint(x.positionScreen.x,x.positionScreen.y);if(M.instersects(q)){L=0;for(O=z.materials.length;L<O;)if(N=z.materials[L++]){Z=o;S=x;N=N;Q=J++;if(y[Q]==null){y[Q]=document.createElementNS("http://www.w3.org/2000/svg","line");P==
0&&y[Q].setAttribute("shape-rendering","crispEdges")}n=y[Q];n.setAttribute("x1",Z.positionScreen.x);n.setAttribute("y1",Z.positionScreen.y);n.setAttribute("x2",S.positionScreen.x);n.setAttribute("y2",S.positionScreen.y);if(N instanceof THREE.LineBasicMaterial){d.__styleString=N.color.__styleString;n.setAttribute("style","fill: none; stroke: "+d.__styleString+"; stroke-width: "+N.linewidth+"; stroke-opacity: "+N.opacity+"; stroke-linecap: "+N.linecap+"; stroke-linejoin: "+N.linejoin);c.appendChild(n)}}}}else if(z instanceof
THREE.RenderableFace3){o=z.v1;x=z.v2;A=z.v3;o.positionScreen.x*=u;o.positionScreen.y*=-C;x.positionScreen.x*=u;x.positionScreen.y*=-C;A.positionScreen.x*=u;A.positionScreen.y*=-C;q.addPoint(o.positionScreen.x,o.positionScreen.y);q.addPoint(x.positionScreen.x,x.positionScreen.y);q.addPoint(A.positionScreen.x,A.positionScreen.y);if(M.instersects(q)){L=0;for(O=z.meshMaterials.length;L<O;){N=z.meshMaterials[L++];if(N instanceof THREE.MeshFaceMaterial){Z=0;for(S=z.faceMaterials.length;Z<S;)(N=z.faceMaterials[Z++])&&
b(o,x,A,z,N,U)}else N&&b(o,x,A,z,N,U)}}}else if(z instanceof THREE.RenderableFace4){o=z.v1;x=z.v2;A=z.v3;B=z.v4;o.positionScreen.x*=u;o.positionScreen.y*=-C;x.positionScreen.x*=u;x.positionScreen.y*=-C;A.positionScreen.x*=u;A.positionScreen.y*=-C;B.positionScreen.x*=u;B.positionScreen.y*=-C;q.addPoint(o.positionScreen.x,o.positionScreen.y);q.addPoint(x.positionScreen.x,x.positionScreen.y);q.addPoint(A.positionScreen.x,A.positionScreen.y);q.addPoint(B.positionScreen.x,B.positionScreen.y);if(M.instersects(q)){L=
0;for(O=z.meshMaterials.length;L<O;){N=z.meshMaterials[L++];if(N instanceof THREE.MeshFaceMaterial){Z=0;for(S=z.faceMaterials.length;Z<S;)(N=z.faceMaterials[Z++])&&e(o,x,A,B,z,N,U)}else N&&e(o,x,A,B,z,N,U)}}}}}};
THREE.WebGLRenderer=function(a){function b(d,k){d.fragment_shader=k.fragment_shader;d.vertex_shader=k.vertex_shader;d.uniforms=Uniforms.clone(k.uniforms)}function e(d,k){d.uniforms.color.value.setRGB(d.color.r*d.opacity,d.color.g*d.opacity,d.color.b*d.opacity);d.uniforms.opacity.value=d.opacity;d.uniforms.map.texture=d.map;d.uniforms.env_map.texture=d.env_map;d.uniforms.reflectivity.value=d.reflectivity;d.uniforms.refraction_ratio.value=d.refraction_ratio;d.uniforms.combine.value=d.combine;d.uniforms.useRefract.value=
d.env_map&&d.env_map.mapping instanceof THREE.CubeRefractionMapping;if(k){d.uniforms.fogColor.value.setHex(k.color.hex);if(k instanceof THREE.Fog){d.uniforms.fogNear.value=k.near;d.uniforms.fogFar.value=k.far}else if(k instanceof THREE.FogExp2)d.uniforms.fogDensity.value=k.density}}function f(d,k){d.uniforms.color.value.setRGB(d.color.r*d.opacity,d.color.g*d.opacity,d.color.b*d.opacity);d.uniforms.opacity.value=d.opacity;if(k){d.uniforms.fogColor.value.setHex(k.color.hex);if(k instanceof THREE.Fog){d.uniforms.fogNear.value=
k.near;d.uniforms.fogFar.value=k.far}else if(k instanceof THREE.FogExp2)d.uniforms.fogDensity.value=k.density}}function g(d,k){var p;if(d=="fragment")p=c.createShader(c.FRAGMENT_SHADER);else if(d=="vertex")p=c.createShader(c.VERTEX_SHADER);c.shaderSource(p,k);c.compileShader(p);if(!c.getShaderParameter(p,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(p));return null}return p}function h(d){switch(d){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;case THREE.LinearMipMapNearestFilter:return c.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return c.LINEAR_MIPMAP_LINEAR}return 0}var j=document.createElement("canvas"),c,i=null,l=new THREE.Matrix4,u,C=new Float32Array(16),o=new Float32Array(16),x=new Float32Array(16),
A=new Float32Array(9),B=new Float32Array(16),M=true,q=new THREE.Color(0),G=0;if(a){if(a.antialias!==undefined)M=a.antialias;a.clearColor!==undefined&&q.setHex(a.clearColor);if(a.clearAlpha!==undefined)G=a.clearAlpha}this.domElement=j;this.autoClear=true;(function(d,k,p){try{c=j.getContext("experimental-webgl",{antialias:d})}catch(s){}if(!c){alert("WebGL not supported");throw"cannot create webgl context";}c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);
c.cullFace(c.BACK);c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(k.r,k.g,k.b,p)})(M,q,G);this.setSize=function(d,k){j.width=d;j.height=k;c.viewport(0,0,j.width,j.height)};this.setClearColor=function(d,k){var p=new THREE.Color(d);c.clearColor(p.r,p.g,p.b,k)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(d,k){var p,s,r,t=0,w=0,v=0,H,y,n,D=[],W=[],J=[],P=[];p=0;for(s=k.length;p<s;p++){r=k[p];H=r.color;y=
r.position;n=r.intensity;if(r instanceof THREE.AmbientLight){t+=H.r;w+=H.g;v+=H.b}else if(r instanceof THREE.DirectionalLight){D.push(H.r*n,H.g*n,H.b*n);W.push(y.x,y.y,y.z)}else if(r instanceof THREE.PointLight){J.push(H.r*n,H.g*n,H.b*n);P.push(y.x,y.y,y.z)}}return{ambient:[t,w,v],directional:{colors:D,positions:W},point:{colors:J,positions:P}}};this.createParticleBuffers=function(){};this.createLineBuffers=function(d){var k,p,s,r=[],t=[],w=d.geometry.vertices;k=0;for(p=w.length;k<p;k++){s=w[k].position;
r.push(s.x,s.y,s.z);t.push(k)}if(r.length){d.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,d.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(r),c.STATIC_DRAW);d.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,d.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(t),c.STATIC_DRAW);d.__webGLLineCount=t.length}};this.createBuffers=function(d){d.__webGLVertexBuffer=c.createBuffer();d.__webGLNormalBuffer=c.createBuffer();d.__webGLTangentBuffer=
c.createBuffer();d.__webGLUVBuffer=c.createBuffer();d.__webGLFaceBuffer=c.createBuffer();d.__webGLLineBuffer=c.createBuffer()};this.initBuffers=function(d,k){var p,s,r=0,t=0,w=0,v=k.geometry.faces,H=d.faces;p=0;for(s=H.length;p<s;p++){fi=H[p];face=v[fi];if(face instanceof THREE.Face3){r+=3;t+=1;w+=3}else if(face instanceof THREE.Face4){r+=4;t+=2;w+=5}}d.__vertexArray=new Float32Array(r*3);d.__normalArray=new Float32Array(r*3);d.__tangentArray=new Float32Array(r*4);d.__uvArray=new Float32Array(r*2);
d.__faceArray=new Uint16Array(t*3);d.__lineArray=new Uint16Array(w*2);r=false;p=0;for(s=k.materials.length;p<s;p++){v=k.materials[p];if(v instanceof THREE.MeshFaceMaterial){v=0;for(H=d.materials.length;v<H;v++)if(d.materials[v]&&d.materials[v].shading!=undefined&&d.materials[v].shading==THREE.SmoothShading){r=true;break}}else if(v&&v.shading!=undefined&&v.shading==THREE.SmoothShading){r=true;break}if(r)break}d.__needsSmoothNormals=r;d.__webGLFaceCount=t*3;d.__webGLLineCount=w*2};this.setBuffers=function(d,
k,p,s,r,t,w,v){var H,y,n,D,W,J,P,U,R,$,X=0,L=0,O=0,Z=0,S=0,z=0,N=0,Q=d.__vertexArray,ea=d.__uvArray,da=d.__normalArray,m=d.__tangentArray,F=d.__faceArray,E=d.__lineArray,T=d.__needsSmoothNormals,aa=k.geometry;k=0;for(H=d.faces.length;k<H;k++){y=d.faces[k];n=aa.faces[y];D=n.vertexNormals;W=n.normal;y=aa.uvs[y];$=aa.vertices;if(n instanceof THREE.Face3){if(s){J=$[n.a].position;P=$[n.b].position;U=$[n.c].position;Q[L]=J.x;Q[L+1]=J.y;Q[L+2]=J.z;Q[L+3]=P.x;Q[L+4]=P.y;Q[L+5]=P.z;Q[L+6]=U.x;Q[L+7]=U.y;Q[L+
8]=U.z;L+=9}if(v&&aa.hasTangents){J=$[n.a].tangent;P=$[n.b].tangent;U=$[n.c].tangent;m[z]=J.x;m[z+1]=J.y;m[z+2]=J.z;m[z+3]=J.w;m[z+4]=P.x;m[z+5]=P.y;m[z+6]=P.z;m[z+7]=P.w;m[z+8]=U.x;m[z+9]=U.y;m[z+10]=U.z;m[z+11]=U.w;z+=12}if(w)if(D.length==3&&T)for(n=0;n<3;n++){W=D[n];da[S]=W.x;da[S+1]=W.y;da[S+2]=W.z;S+=3}else for(n=0;n<3;n++){da[S]=W.x;da[S+1]=W.y;da[S+2]=W.z;S+=3}if(t&&y)for(n=0;n<3;n++){D=y[n];ea[O]=D.u;ea[O+1]=D.v;O+=2}if(r){F[Z]=X;F[Z+1]=X+1;F[Z+2]=X+2;Z+=3;E[N]=X;E[N+1]=X+1;E[N+2]=X;E[N+3]=
X+2;E[N+4]=X+1;E[N+5]=X+2;N+=6;X+=3}}else if(n instanceof THREE.Face4){if(s){J=$[n.a].position;P=$[n.b].position;U=$[n.c].position;R=$[n.d].position;Q[L]=J.x;Q[L+1]=J.y;Q[L+2]=J.z;Q[L+3]=P.x;Q[L+4]=P.y;Q[L+5]=P.z;Q[L+6]=U.x;Q[L+7]=U.y;Q[L+8]=U.z;Q[L+9]=R.x;Q[L+10]=R.y;Q[L+11]=R.z;L+=12}if(v&&aa.hasTangents){J=$[n.a].tangent;P=$[n.b].tangent;U=$[n.c].tangent;n=$[n.d].tangent;m[z]=J.x;m[z+1]=J.y;m[z+2]=J.z;m[z+3]=J.w;m[z+4]=P.x;m[z+5]=P.y;m[z+6]=P.z;m[z+7]=P.w;m[z+8]=U.x;m[z+9]=U.y;m[z+10]=U.z;m[z+
11]=U.w;m[z+12]=n.x;m[z+13]=n.y;m[z+14]=n.z;m[z+15]=n.w;z+=16}if(w)if(D.length==4&&T)for(n=0;n<4;n++){W=D[n];da[S]=W.x;da[S+1]=W.y;da[S+2]=W.z;S+=3}else for(n=0;n<4;n++){da[S]=W.x;da[S+1]=W.y;da[S+2]=W.z;S+=3}if(t&&y)for(n=0;n<4;n++){D=y[n];ea[O]=D.u;ea[O+1]=D.v;O+=2}if(r){F[Z]=X;F[Z+1]=X+1;F[Z+2]=X+2;F[Z+3]=X;F[Z+4]=X+2;F[Z+5]=X+3;Z+=6;E[N]=X;E[N+1]=X+1;E[N+2]=X;E[N+3]=X+2;E[N+4]=X;E[N+5]=X+3;E[N+6]=X+1;E[N+7]=X+2;E[N+8]=X+2;E[N+9]=X+3;N+=10;X+=4}}}if(s){c.bindBuffer(c.ARRAY_BUFFER,d.__webGLVertexBuffer);
c.bufferData(c.ARRAY_BUFFER,Q,p)}if(w){c.bindBuffer(c.ARRAY_BUFFER,d.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,da,p)}if(v&&aa.hasTangents){c.bindBuffer(c.ARRAY_BUFFER,d.__webGLTangentBuffer);c.bufferData(c.ARRAY_BUFFER,m,p)}if(t&&O>0){c.bindBuffer(c.ARRAY_BUFFER,d.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,ea,p)}if(r){c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,d.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,F,p);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,d.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,
E,p)}};this.renderBuffer=function(d,k,p,s,r){var t,w,v,H;if(!s.program){if(s instanceof THREE.MeshDepthMaterial){b(s,THREE.ShaderLib.depth);s.uniforms.mNear.value=d.near;s.uniforms.mFar.value=d.far}else if(s instanceof THREE.MeshNormalMaterial)b(s,THREE.ShaderLib.normal);else if(s instanceof THREE.MeshBasicMaterial){b(s,THREE.ShaderLib.basic);e(s,p)}else if(s instanceof THREE.MeshLambertMaterial){b(s,THREE.ShaderLib.lambert);e(s,p)}else if(s instanceof THREE.MeshPhongMaterial){b(s,THREE.ShaderLib.phong);
e(s,p)}else if(s instanceof THREE.LineBasicMaterial){b(s,THREE.ShaderLib.basic);f(s,p)}var y,n,D;y=H=w=0;for(n=k.length;y<n;y++){D=k[y];D instanceof THREE.DirectionalLight&&H++;D instanceof THREE.PointLight&&w++}if(w+H<=4){y=H;w=w}else{y=Math.ceil(4*H/(w+H));w=4-y}w={directional:y,point:w};H={fog:p,map:s.map,env_map:s.env_map,maxDirLights:w.directional,maxPointLights:w.point};w=s.fragment_shader;y=s.vertex_shader;n=c.createProgram();D=["#ifdef GL_ES\nprecision highp float;\n#endif","#define MAX_DIR_LIGHTS "+
H.maxDirLights,"#define MAX_POINT_LIGHTS "+H.maxPointLights,H.fog?"#define USE_FOG":"",H.fog instanceof THREE.FogExp2?"#define FOG_EXP2":"",H.map?"#define USE_MAP":"",H.env_map?"#define USE_ENVMAP":"","uniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n"].join("\n");H=[c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0?"#define VERTEX_TEXTURES":"","#define MAX_DIR_LIGHTS "+H.maxDirLights,"#define MAX_POINT_LIGHTS "+H.maxPointLights,H.map?"#define USE_MAP":"",H.env_map?"#define USE_ENVMAP":"",
"uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\n"].join("\n");c.attachShader(n,g("fragment",D+w));c.attachShader(n,g("vertex",H+y));c.linkProgram(n);c.getProgramParameter(n,c.LINK_STATUS)||alert("Could not initialise shaders\nVALIDATE_STATUS: "+c.getProgramParameter(n,c.VALIDATE_STATUS)+", gl error ["+
c.getError()+"]");n.uniforms={};n.attributes={};s.program=n;w=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(t in s.uniforms)w.push(t);t=s.program;y=0;for(n=w.length;y<n;y++){D=w[y];t.uniforms[D]=c.getUniformLocation(t,D)}t=s.program;w=["position","normal","uv","tangent"];y=0;for(n=w.length;y<n;y++){D=w[y];t.attributes[D]=c.getAttribLocation(t,D)}}t=s.program;if(t!=i){c.useProgram(t);i=t}this.loadCamera(t,d);this.loadMatrices(t);if(s instanceof
THREE.MeshPhongMaterial||s instanceof THREE.MeshLambertMaterial){d=this.setupLights(t,k);s.uniforms.enableLighting.value=d.directional.positions.length+d.point.positions.length;s.uniforms.ambientLightColor.value=d.ambient;s.uniforms.directionalLightColor.value=d.directional.colors;s.uniforms.directionalLightDirection.value=d.directional.positions;s.uniforms.pointLightColor.value=d.point.colors;s.uniforms.pointLightPosition.value=d.point.positions}if(s instanceof THREE.MeshBasicMaterial||s instanceof
THREE.MeshLambertMaterial||s instanceof THREE.MeshPhongMaterial)e(s,p);s instanceof THREE.LineBasicMaterial&&f(s,p);if(s instanceof THREE.MeshPhongMaterial){s.uniforms.ambient.value.setRGB(s.ambient.r,s.ambient.g,s.ambient.b);s.uniforms.specular.value.setRGB(s.specular.r,s.specular.g,s.specular.b);s.uniforms.shininess.value=s.shininess}p=s.uniforms;for(v in p)if(y=t.uniforms[v]){k=p[v];w=k.type;d=k.value;if(w=="i")c.uniform1i(y,d);else if(w=="f")c.uniform1f(y,d);else if(w=="fv")c.uniform3fv(y,d);
else if(w=="v2")c.uniform2f(y,d.x,d.y);else if(w=="v3")c.uniform3f(y,d.x,d.y,d.z);else if(w=="c")c.uniform3f(y,d.r,d.g,d.b);else if(w=="t"){c.uniform1i(y,d);if(k=k.texture)if(k.image instanceof Array&&k.image.length==6){k=k;d=d;if(k.image.length==6){if(!k.image.__webGLTextureCube&&!k.image.__cubeMapInitialized&&k.image.loadCount==6){k.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,k.image.__webGLTextureCube);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);
c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(w=0;w<6;++w)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+w,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,k.image[w]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);k.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE0+d);c.bindTexture(c.TEXTURE_CUBE_MAP,k.image.__webGLTextureCube)}}else{k=
k;d=d;if(!k.__webGLTexture&&k.image.loaded){k.__webGLTexture=c.createTexture();c.bindTexture(c.TEXTURE_2D,k.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,k.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,h(k.wrap_s));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,h(k.wrap_t));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,h(k.mag_filter));c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,h(k.min_filter));c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,
null)}c.activeTexture(c.TEXTURE0+d);c.bindTexture(c.TEXTURE_2D,k.__webGLTexture)}}}v=t.attributes;c.bindBuffer(c.ARRAY_BUFFER,r.__webGLVertexBuffer);c.vertexAttribPointer(v.position,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(v.position);if(v.normal>=0){c.bindBuffer(c.ARRAY_BUFFER,r.__webGLNormalBuffer);c.vertexAttribPointer(v.normal,3,c.FLOAT,false,0,0);c.enableVertexAttribArray(v.normal)}if(v.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,r.__webGLTangentBuffer);c.vertexAttribPointer(v.tangent,4,c.FLOAT,
false,0,0);c.enableVertexAttribArray(v.tangent)}if(v.uv>=0)if(r.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,r.__webGLUVBuffer);c.vertexAttribPointer(v.uv,2,c.FLOAT,false,0,0);c.enableVertexAttribArray(v.uv)}else c.disableVertexAttribArray(v.uv);if(s.wireframe||s instanceof THREE.LineBasicMaterial){v=s.wireframe_linewidth!==undefined?s.wireframe_linewidth:s.linewidth!==undefined?s.linewidth:1;s=s instanceof THREE.LineBasicMaterial&&r.type==THREE.LineStrip?c.LINE_STRIP:c.LINES;c.lineWidth(v);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,
r.__webGLLineBuffer);c.drawElements(s,r.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,r.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,r.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderPass=function(d,k,p,s,r,t,w){var v,H,y,n,D;y=0;for(n=s.materials.length;y<n;y++){v=s.materials[y];if(v instanceof THREE.MeshFaceMaterial){v=0;for(H=r.materials.length;v<H;v++)if((D=r.materials[v])&&D.blending==t&&D.opacity<1==w){this.setBlending(D.blending);this.renderBuffer(d,k,p,D,
r)}}else if((D=v)&&D.blending==t&&D.opacity<1==w){this.setBlending(D.blending);this.renderBuffer(d,k,p,D,r)}}};this.render=function(d,k){var p,s,r,t,w=d.lights,v=d.fog;this.initWebGLObjects(d);this.autoClear&&this.clear();k.autoUpdateMatrix&&k.updateMatrix();C.set(k.matrix.flatten());x.set(k.projectionMatrix.flatten());p=0;for(s=d.__webGLObjects.length;p<s;p++){r=d.__webGLObjects[p];t=r.object;r=r.buffer;if(t.visible){this.setupMatrices(t,k);this.renderPass(k,w,v,t,r,THREE.NormalBlending,false)}}p=
0;for(s=d.__webGLObjects.length;p<s;p++){r=d.__webGLObjects[p];t=r.object;r=r.buffer;if(t.visible){this.setupMatrices(t,k);this.renderPass(k,w,v,t,r,THREE.AdditiveBlending,false);this.renderPass(k,w,v,t,r,THREE.SubtractiveBlending,false);this.renderPass(k,w,v,t,r,THREE.AdditiveBlending,true);this.renderPass(k,w,v,t,r,THREE.SubtractiveBlending,true);this.renderPass(k,w,v,t,r,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(d){function k(y,n,D,W){if(y[n]==undefined){d.__webGLObjects.push({buffer:D,
object:W});y[n]=1}}var p,s,r,t,w,v,H;if(!d.__webGLObjects){d.__webGLObjects=[];d.__webGLObjectsMap={}}p=0;for(s=d.objects.length;p<s;p++){r=d.objects[p];w=r.geometry;if(d.__webGLObjectsMap[r.id]==undefined)d.__webGLObjectsMap[r.id]={};H=d.__webGLObjectsMap[r.id];if(r instanceof THREE.Mesh){for(t in w.geometryChunks){v=w.geometryChunks[t];if(!v.__webGLVertexBuffer){this.createBuffers(v);this.initBuffers(v,r);w.__dirtyVertices=true;w.__dirtyElements=true;w.__dirtyUvs=true;w.__dirtyNormals=true;w.__dirtyTangents=
true}if(w.__dirtyVertices||w.__dirtyElements||w.__dirtyUvs)this.setBuffers(v,r,c.DYNAMIC_DRAW,w.__dirtyVertices,w.__dirtyElements,w.__dirtyUvs,w.__dirtyNormals,w.__dirtyTangents);k(H,t,v,r)}w.__dirtyVertices=false;w.__dirtyElements=false;w.__dirtyUvs=false;w.__dirtyNormals=false;w.__dirtyTangents=false}else if(r instanceof THREE.Line){r.__webGLVertexBuffer||this.createLineBuffers(r);k(H,0,r,r)}else if(r instanceof THREE.ParticleSystem){r.__webGLVertexBuffer||this.createParticleBuffers(r);k(H,0,r,
r)}}};this.removeObject=function(d,k){var p,s;for(p=d.__webGLObjects.length-1;p>=0;p--){s=d.__webGLObjects[p].object;k==s&&d.__webGLObjects.splice(p,1)}};this.setupMatrices=function(d,k){d.autoUpdateMatrix&&d.updateMatrix();l.multiply(k.matrix,d.matrix);o.set(l.flatten());u=THREE.Matrix4.makeInvert3x3(l).transpose();A.set(u.m);B.set(d.matrix.flatten())};this.loadMatrices=function(d){c.uniformMatrix4fv(d.uniforms.viewMatrix,false,C);c.uniformMatrix4fv(d.uniforms.modelViewMatrix,false,o);c.uniformMatrix4fv(d.uniforms.projectionMatrix,
false,x);c.uniformMatrix3fv(d.uniforms.normalMatrix,false,A);c.uniformMatrix4fv(d.uniforms.objectMatrix,false,B)};this.loadCamera=function(d,k){c.uniform3f(d.uniforms.cameraPosition,k.position.x,k.position.y,k.position.z)};this.setBlending=function(d){switch(d){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE);break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=
function(d,k){if(d){!k||k=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(d=="back")c.cullFace(c.BACK);else d=="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}};
THREE.Snippets={fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;\nuniform float fogFar;\n#endif\n#endif",fog_fragment:"#ifdef USE_FOG\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n#ifdef FOG_EXP2\nconst float LOG2 = 1.442695;\nfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\nfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor = mix( gl_FragColor, vec4( fogColor, 1.0 ), fogFactor );\n#endif",
envmap_pars_fragment:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float reflectivity;\nuniform samplerCube env_map;\nuniform int combine;\n#endif",envmap_fragment:"#ifdef USE_ENVMAP\ncubeColor = textureCube( env_map, vec3( -vReflect.x, vReflect.yz ) );\nif ( combine == 1 ) {\ngl_FragColor = mix( gl_FragColor, cubeColor, reflectivity );\n} else {\ngl_FragColor = gl_FragColor * cubeColor;\n}\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\nvarying vec3 vReflect;\nuniform float refraction_ratio;\nuniform bool useRefract;\n#endif",
envmap_vertex:"#ifdef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nif ( useRefract ) {\nvReflect = refract( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ), refraction_ratio );\n} else {\nvReflect = reflect( normalize( mPosition.xyz - cameraPosition ), normalize( nWorld.xyz ) );\n}\n#endif",map_pars_fragment:"#ifdef USE_MAP\nvarying vec2 vUv;\nuniform sampler2D map;\n#endif",
map_pars_vertex:"#ifdef USE_MAP\nvarying vec2 vUv;\n#endif",map_fragment:"#ifdef USE_MAP\nmapColor = texture2D( map, vUv );\n#endif",map_vertex:"#ifdef USE_MAP\nvUv = uv;\n#endif",lights_pars_vertex:"uniform bool enableLighting;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n#ifdef PHONG\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\n#endif",
lights_vertex:"if ( !enableLighting ) {\nvLightWeighting = vec3( 1.0 );\n} else {\nvLightWeighting = ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nfloat directionalLightWeighting = max( dot( transformedNormal, normalize( lDirection.xyz ) ), 0.0 );\nvLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;\n}\n#endif\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 pointLightVector = normalize( lPosition.xyz - mvPosition.xyz );\nfloat pointLightWeighting = max( dot( transformedNormal, pointLightVector ), 0.0 );\nvLightWeighting += pointLightColor[ i ] * pointLightWeighting;\n#ifdef PHONG\nvPointLightVector[ i ] = pointLightVector;\n#endif\n}\n#endif\n}",
lights_pars_fragment:"#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nvarying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];\n#endif\nvarying vec3 vViewPosition;\nvarying vec3 vNormal;",lights_fragment:"vec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );\nvec4 mSpecular = vec4( specular, opacity );\n#if MAX_POINT_LIGHTS > 0\nvec4 pointDiffuse = vec4( 0.0 );\nvec4 pointSpecular = vec4( 0.0 );\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec3 pointVector = normalize( vPointLightVector[ i ] );\nvec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );\nfloat pointDotNormalHalf = dot( normal, pointHalfVector );\nfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );\nfloat pointSpecularWeight = 0.0;\nif ( pointDotNormalHalf >= 0.0 )\npointSpecularWeight = pow( pointDotNormalHalf, shininess );\npointDiffuse += mColor * pointDiffuseWeight;\npointSpecular += mSpecular * pointSpecularWeight;\n}\n#endif\n#if MAX_DIR_LIGHTS > 0\nvec4 dirDiffuse = vec4( 0.0 );\nvec4 dirSpecular = vec4( 0.0 );\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nvec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );\nfloat dirDotNormalHalf = dot( normal, dirHalfVector );\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\nfloat dirSpecularWeight = 0.0;\nif ( dirDotNormalHalf >= 0.0 )\ndirSpecularWeight = pow( dirDotNormalHalf, shininess );\ndirDiffuse += mColor * dirDiffuseWeight;\ndirSpecular += mSpecular * dirSpecularWeight;\n}\n#endif\nvec4 totalLight = vec4( ambient, opacity );\n#if MAX_DIR_LIGHTS > 0\ntotalLight += dirDiffuse + dirSpecular;\n#endif\n#if MAX_POINT_LIGHTS > 0\ntotalLight += pointDiffuse + pointSpecular;\n#endif"};
THREE.UniformsLib={common:{color:{type:"c",value:new THREE.Color(15658734)},opacity:{type:"f",value:1},map:{type:"t",value:0,texture:null},env_map:{type:"t",value:1,texture:null},useRefract:{type:"i",value:0},reflectivity:{type:"f",value:1},refraction_ratio:{type:"f",value:0.98},combine:{type:"i",value:0},fogDensity:{type:"f",value:2.5E-4},fogNear:{type:"f",value:1},fogFar:{type:"f",value:2E3},fogColor:{type:"c",value:new THREE.Color(16777215)}},lights:{enableLighting:{type:"i",value:1},ambientLightColor:{type:"fv",
value:[]},directionalLightDirection:{type:"fv",value:[]},directionalLightColor:{type:"fv",value:[]},pointLightPosition:{type:"fv",value:[]},pointLightColor:{type:"fv",value:[]}}};
THREE.ShaderLib={depth:{uniforms:{mNear:{type:"f",value:1},mFar:{type:"f",value:2E3}},fragment_shader:"uniform float mNear;\nuniform float mFar;\nvoid main() {\nfloat depth = gl_FragCoord.z / gl_FragCoord.w;\nfloat color = 1.0 - smoothstep( mNear, mFar, depth );\ngl_FragColor = vec4( vec3( color ), 1.0 );\n}",vertex_shader:"void main() {\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}"},normal:{uniforms:{},fragment_shader:"varying vec3 vNormal;\nvoid main() {\ngl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, 1.0 );\n}",
vertex_shader:"varying vec3 vNormal;\nvoid main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalize( normalMatrix * normal );\ngl_Position = projectionMatrix * mvPosition;\n}"},basic:{uniforms:THREE.UniformsLib.common,fragment_shader:["uniform vec3 color;\nuniform float opacity;",THREE.Snippets.map_pars_fragment,THREE.Snippets.envmap_pars_fragment,THREE.Snippets.fog_pars_fragment,"void main() {\nvec4 mColor = vec4( color, opacity );\nvec4 mapColor = vec4( 1.0 );\nvec4 cubeColor = vec4( 1.0 );",
THREE.Snippets.map_fragment,"gl_FragColor = mColor * mapColor;",THREE.Snippets.envmap_fragment,THREE.Snippets.fog_fragment,"}"].join("\n"),vertex_shader:[THREE.Snippets.map_pars_vertex,THREE.Snippets.envmap_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.Snippets.map_vertex,THREE.Snippets.envmap_vertex,"gl_Position = projectionMatrix * mvPosition;\n}"].join("\n")},lambert:{uniforms:Uniforms.merge([THREE.UniformsLib.common,THREE.UniformsLib.lights]),fragment_shader:["uniform vec3 color;\nuniform float opacity;\nvarying vec3 vLightWeighting;",
THREE.Snippets.map_pars_fragment,THREE.Snippets.envmap_pars_fragment,THREE.Snippets.fog_pars_fragment,"void main() {\nvec4 mColor = vec4( color, opacity );\nvec4 mapColor = vec4( 1.0 );\nvec4 cubeColor = vec4( 1.0 );",THREE.Snippets.map_fragment,"gl_FragColor = mColor * mapColor * vec4( vLightWeighting, 1.0 );",THREE.Snippets.envmap_fragment,THREE.Snippets.fog_fragment,"}"].join("\n"),vertex_shader:["varying vec3 vLightWeighting;",THREE.Snippets.map_pars_vertex,THREE.Snippets.envmap_pars_vertex,
THREE.Snippets.lights_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.Snippets.map_vertex,THREE.Snippets.envmap_vertex,"vec3 transformedNormal = normalize( normalMatrix * normal );",THREE.Snippets.lights_vertex,"gl_Position = projectionMatrix * mvPosition;\n}"].join("\n")},phong:{uniforms:Uniforms.merge([THREE.UniformsLib.common,THREE.UniformsLib.lights,{ambient:{type:"c",value:new THREE.Color(328965)},specular:{type:"c",value:new THREE.Color(1118481)},
shininess:{type:"f",value:30}}]),fragment_shader:["uniform vec3 color;\nuniform float opacity;\nuniform vec3 ambient;\nuniform vec3 specular;\nuniform float shininess;\nvarying vec3 vLightWeighting;",THREE.Snippets.map_pars_fragment,THREE.Snippets.envmap_pars_fragment,THREE.Snippets.fog_pars_fragment,THREE.Snippets.lights_pars_fragment,"void main() {\nvec4 mColor = vec4( color, opacity );\nvec4 mapColor = vec4( 1.0 );\nvec4 cubeColor = vec4( 1.0 );",THREE.Snippets.map_fragment,THREE.Snippets.lights_fragment,
"gl_FragColor = mapColor * totalLight * vec4( vLightWeighting, 1.0 );",THREE.Snippets.envmap_fragment,THREE.Snippets.fog_fragment,"}"].join("\n"),vertex_shader:["#define PHONG\nvarying vec3 vLightWeighting;\nvarying vec3 vViewPosition;\nvarying vec3 vNormal;",THREE.Snippets.map_pars_vertex,THREE.Snippets.envmap_pars_vertex,THREE.Snippets.lights_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",THREE.Snippets.map_vertex,THREE.Snippets.envmap_vertex,"#ifndef USE_ENVMAP\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\n#endif\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 transformedNormal = normalize( normalMatrix * normal );\nvNormal = transformedNormal;",
THREE.Snippets.lights_vertex,"gl_Position = projectionMatrix * mvPosition;\n}"].join("\n")}};THREE.RenderableObject=function(){this.z=this.object=null};THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[];this.faceMaterials=this.meshMaterials=null;this.overdraw=false;this.uvs=[null,null,null]};
THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.materials=null};THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.materials=null};
var GeometryUtils={merge:function(a,b){var e=b instanceof THREE.Mesh,f=a.vertices.length,g=e?b.geometry:b,h=a.vertices,j=g.vertices,c=a.faces,i=g.faces,l=a.uvs;g=g.uvs;e&&b.updateMatrix();for(var u=0,C=j.length;u<C;u++){var o=new THREE.Vertex(j[u].position.clone());e&&b.matrix.multiplyVector3(o.position);h.push(o)}u=0;for(C=i.length;u<C;u++){j=i[u];var x,A=j.vertexNormals;if(j instanceof THREE.Face3)x=new THREE.Face3(j.a+f,j.b+f,j.c+f);else if(j instanceof THREE.Face4)x=new THREE.Face4(j.a+f,j.b+
f,j.c+f,j.d+f);x.centroid.copy(j.centroid);x.normal.copy(j.normal);e=0;for(h=A.length;e<h;e++){o=A[e];x.vertexNormals.push(o.clone())}x.materials=j.materials.slice();c.push(x)}u=0;for(C=g.length;u<C;u++){f=g[u];c=[];e=0;for(h=f.length;e<h;e++)c.push(new THREE.UV(f[e].u,f[e].v));l.push(c)}}},ImageUtils={loadTexture:function(a,b){var e=new Image;e.onload=function(){this.loaded=true};e.src=a;return new THREE.Texture(e,b)},loadArray:function(a){var b,e,f=[];b=f.loadCount=0;for(e=a.length;b<e;++b){f[b]=
new Image;f[b].loaded=0;f[b].onload=function(){f.loadCount+=1;this.loaded=true};f[b].src=a[b]}return f}},SceneUtils={addMesh:function(a,b,e,f,g,h,j,c,i,l){b=new THREE.Mesh(b,l);b.scale.x=b.scale.y=b.scale.z=e;b.position.x=f;b.position.y=g;b.position.z=h;b.rotation.x=j;b.rotation.y=c;b.rotation.z=i;a.addObject(b);return b},addPanoramaCubeWebGL:function(a,b,e){var f=ShaderUtils.lib.cube;f.uniforms.tCube.texture=e;e=new THREE.MeshShaderMaterial({fragment_shader:f.fragment_shader,vertex_shader:f.vertex_shader,
uniforms:f.uniforms});b=new THREE.Mesh(new Cube(b,b,b,1,1,null,true),e);a.addObject(b);return b},addPanoramaCube:function(a,b,e){var f=[];f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[0])}));f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[1])}));f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[2])}));f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[3])}));f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[4])}));f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(e[5])}));
b=new THREE.Mesh(new Cube(b,b,b,1,1,f,true),new THREE.MeshFaceMaterial);a.addObject(b);return b},addPanoramaCubePlanes:function(a,b,e){var f=b/2;b=new Plane(b,b);var g=Math.PI/2,h=Math.PI;SceneUtils.addMesh(a,b,1,0,0,-f,0,0,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(e[5])}));SceneUtils.addMesh(a,b,1,-f,0,0,0,g,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(e[0])}));SceneUtils.addMesh(a,b,1,f,0,0,0,-g,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(e[1])}));SceneUtils.addMesh(a,
b,1,0,f,0,g,0,h,new THREE.MeshBasicMaterial({map:new THREE.Texture(e[2])}));SceneUtils.addMesh(a,b,1,0,-f,0,-g,0,h,new THREE.MeshBasicMaterial({map:new THREE.Texture(e[3])}))}},ShaderUtils={lib:{fresnel:{uniforms:{mRefractionRatio:{type:"f",value:1.02},mFresnelBias:{type:"f",value:0.1},mFresnelPower:{type:"f",value:2},mFresnelScale:{type:"f",value:1},tCube:{type:"t",value:1,texture:null}},fragment_shader:"uniform samplerCube tCube;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main() {\nvec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\nvec4 refractedColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nrefractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;\nrefractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;\nrefractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;\nrefractedColor.a = 1.0;\ngl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );\n}",
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}"},
normal:{uniforms:{enableAO:{type:"i",value:0},enableDiffuse:{type:"i",value:0},tDiffuse:{type:"t",value:0,texture:null},tNormal:{type:"t",value:2,texture:null},tAO:{type:"t",value:3,texture:null},uNormalScale:{type:"f",value:1},tDisplacement:{type:"t",value:4,texture:null},uDisplacementBias:{type:"f",value:-0.5},uDisplacementScale:{type:"f",value:2.5},uPointLightPos:{type:"v3",value:new THREE.Vector3},uPointLightColor:{type:"c",value:new THREE.Color(15658734)},uDirLightPos:{type:"v3",value:new THREE.Vector3},
uDirLightColor:{type:"c",value:new THREE.Color(15658734)},uAmbientLightColor:{type:"c",value:new THREE.Color(328965)},uDiffuseColor:{type:"c",value:new THREE.Color(15658734)},uSpecularColor:{type:"c",value:new THREE.Color(1118481)},uAmbientColor:{type:"c",value:new THREE.Color(328965)},uShininess:{type:"f",value:30}},fragment_shader:"uniform vec3 uDirLightPos;\nuniform vec3 uAmbientLightColor;\nuniform vec3 uDirLightColor;\nuniform vec3 uPointLightColor;\nuniform vec3 uAmbientColor;\nuniform vec3 uDiffuseColor;\nuniform vec3 uSpecularColor;\nuniform float uShininess;\nuniform bool enableDiffuse;\nuniform bool enableAO;\nuniform sampler2D tDiffuse;\nuniform sampler2D tNormal;\nuniform sampler2D tAO;\nuniform float uNormalScale;\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vPointLightVector;\nvarying vec3 vViewPosition;\nvoid main() {\nvec3 diffuseTex = vec3( 1.0, 1.0, 1.0 );\nvec3 aoTex = vec3( 1.0, 1.0, 1.0 );\nvec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;\nnormalTex.xy *= uNormalScale;\nnormalTex = normalize( normalTex );\nif( enableDiffuse )\ndiffuseTex = texture2D( tDiffuse, vUv ).xyz;\nif( enableAO )\naoTex = texture2D( tAO, vUv ).xyz;\nmat3 tsb = mat3( vTangent, vBinormal, vNormal );\nvec3 finalNormal = tsb * normalTex;\nvec3 normal = normalize( finalNormal );\nvec3 viewPosition = normalize( vViewPosition );\nvec4 pointDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec3 pointVector = normalize( vPointLightVector );\nvec3 pointHalfVector = normalize( vPointLightVector + vViewPosition );\nfloat pointDotNormalHalf = dot( normal, pointHalfVector );\nfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );\nfloat pointSpecularWeight = 0.0;\nif ( pointDotNormalHalf >= 0.0 )\npointSpecularWeight = pow( pointDotNormalHalf, uShininess );\npointDiffuse += vec4( uDiffuseColor, 1.0 ) * pointDiffuseWeight;\npointSpecular += vec4( uSpecularColor, 1.0 ) * pointSpecularWeight;\nvec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec4 lDirection = viewMatrix * vec4( uDirLightPos, 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nvec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );\nfloat dirDotNormalHalf = dot( normal, dirHalfVector );\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\nfloat dirSpecularWeight = 0.0;\nif ( dirDotNormalHalf >= 0.0 )\ndirSpecularWeight = pow( dirDotNormalHalf, uShininess );\ndirDiffuse += vec4( uDiffuseColor, 1.0 ) * dirDiffuseWeight;\ndirSpecular += vec4( uSpecularColor, 1.0 ) * dirSpecularWeight;\nvec4 totalLight = vec4( uAmbientLightColor * uAmbientColor, 1.0 );\ntotalLight += vec4( uDirLightColor, 1.0 ) * ( dirDiffuse + dirSpecular );\ntotalLight += vec4( uPointLightColor, 1.0 ) * ( pointDiffuse + pointSpecular );\ngl_FragColor = vec4( totalLight.xyz * aoTex * diffuseTex, 1.0 );\n}",
vertex_shader:"attribute vec4 tangent;\nuniform vec3 uPointLightPos;\n#ifdef VERTEX_TEXTURES\nuniform sampler2D tDisplacement;\nuniform float uDisplacementScale;\nuniform float uDisplacementBias;\n#endif\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vPointLightVector;\nvarying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalize( normalMatrix * normal );\nvTangent = normalize( normalMatrix * tangent.xyz );\nvBinormal = cross( vNormal, vTangent ) * tangent.w;\nvBinormal = normalize( vBinormal );\nvUv = uv;\nvec4 lPosition = viewMatrix * vec4( uPointLightPos, 1.0 );\nvPointLightVector = normalize( lPosition.xyz - mvPosition.xyz );\n#ifdef VERTEX_TEXTURES\nvec3 dv = texture2D( tDisplacement, uv ).xyz;\nfloat df = uDisplacementScale * dv.x + uDisplacementBias;\nvec4 displacedPosition = vec4( vNormal.xyz * df, 0.0 ) + mvPosition;\ngl_Position = projectionMatrix * displacedPosition;\n#else\ngl_Position = projectionMatrix * mvPosition;\n#endif\n}"},
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:{uniforms:{tCube:{type:"t",value:1,texture:null}},vertex_shader:"varying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",
fragment_shader:"uniform samplerCube tCube;\nvarying vec3 vViewPosition;\nvoid main() {\nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( - wPos.x, wPos.yz ) );\n}"}}},Cube=function(a,b,e,f,g,h,j,c){function i(B,M,q,G,d,k,p,s){var r,t,w=f||1,v=g||1,H=w+1,y=v+1,n=d/2,D=k/2;d=d/w;var W=k/v,J=l.vertices.length;if(B=="x"&&M=="y"||B=="y"&&M=="x")r="z";else if(B=="x"&&M=="z"||B=="z"&&M=="x")r="y";else if(B=="z"&&M=="y"||B=="y"&&M=="z")r="x";for(t=0;t<y;t++)for(k=0;k<
H;k++){var P=new THREE.Vector3;P[B]=(k*d-n)*q;P[M]=(t*W-D)*G;P[r]=p;l.vertices.push(new THREE.Vertex(P))}for(t=0;t<v;t++)for(k=0;k<w;k++){l.faces.push(new THREE.Face4(k+H*t+J,k+H*(t+1)+J,k+1+H*(t+1)+J,k+1+H*t+J,null,s));l.uvs.push([new THREE.UV(k/w,t/v),new THREE.UV(k/w,(t+1)/v),new THREE.UV((k+1)/w,(t+1)/v),new THREE.UV((k+1)/w,t/v)])}}THREE.Geometry.call(this);var l=this,u=a/2,C=b/2,o=e/2;j=j?-1:1;if(h!==undefined)if(h instanceof Array)this.materials=h;else{this.materials=[];for(var x=0;x<6;x++)this.materials.push([h])}else this.materials=
[];this.sides={px:true,nx:true,py:true,ny:true,pz:true,nz:true};if(c!=undefined)for(var A in c)if(this.sides[A]!=undefined)this.sides[A]=c[A];this.sides.px&&i("z","y",1*j,-1,e,b,-u,this.materials[0]);this.sides.nx&&i("z","y",-1*j,-1,e,b,u,this.materials[1]);this.sides.py&&i("x","z",1*j,1,a,e,C,this.materials[2]);this.sides.ny&&i("x","z",1*j,-1,a,e,-C,this.materials[3]);this.sides.pz&&i("x","y",1*j,-1,a,b,o,this.materials[4]);this.sides.nz&&i("x","y",-1*j,-1,a,b,-o,this.materials[5]);(function(){for(var B=
[],M=[],q=0,G=l.vertices.length;q<G;q++){for(var d=l.vertices[q],k=false,p=0,s=B.length;p<s;p++){var r=B[p];if(d.position.x==r.position.x&&d.position.y==r.position.y&&d.position.z==r.position.z){M[q]=p;k=true;break}}if(!k){M[q]=B.length;B.push(new THREE.Vertex(d.position.clone()))}}q=0;for(G=l.faces.length;q<G;q++){d=l.faces[q];d.a=M[d.a];d.b=M[d.b];d.c=M[d.c];d.d=M[d.d]}l.vertices=B})();this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};Cube.prototype=new THREE.Geometry;
Cube.prototype.constructor=Cube;
var Cylinder=function(a,b,e,f,g){function h(l,u,C){j.vertices.push(new THREE.Vertex(new THREE.Vector3(l,u,C)))}THREE.Geometry.call(this);var j=this,c=Math.PI,i;for(i=0;i<a;i++)h(Math.sin(2*c*i/a)*b,Math.cos(2*c*i/a)*b,0);for(i=0;i<a;i++)h(Math.sin(2*c*i/a)*e,Math.cos(2*c*i/a)*e,f);for(i=0;i<a;i++)j.faces.push(new THREE.Face4(i,i+a,a+(i+1)%a,(i+1)%a));if(e!=0){h(0,0,-g);for(i=a;i<a+a/2;i++)j.faces.push(new THREE.Face4(2*a,(2*i-2*a)%a,(2*i-2*a+1)%a,(2*i-2*a+2)%a))}if(b!=0){h(0,0,f+g);for(i=a+a/2;i<
2*a;i++)j.faces.push(new THREE.Face4((2*i-2*a+2)%a+a,(2*i-2*a+1)%a+a,(2*i-2*a)%a+a,2*a+1))}this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};Cylinder.prototype=new THREE.Geometry;Cylinder.prototype.constructor=Cylinder;
var Plane=function(a,b,e,f){THREE.Geometry.call(this);var g,h=a/2,j=b/2;e=e||1;f=f||1;var c=e+1,i=f+1;a=a/e;var l=b/f;for(g=0;g<i;g++)for(b=0;b<c;b++)this.vertices.push(new THREE.Vertex(new THREE.Vector3(b*a-h,-(g*l-j),0)));for(g=0;g<f;g++)for(b=0;b<e;b++){this.faces.push(new THREE.Face4(b+c*g,b+c*(g+1),b+1+c*(g+1),b+1+c*g));this.uvs.push([new THREE.UV(b/e,g/f),new THREE.UV(b/e,(g+1)/f),new THREE.UV((b+1)/e,(g+1)/f),new THREE.UV((b+1)/e,g/f)])}this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};
Plane.prototype=new THREE.Geometry;Plane.prototype.constructor=Plane;
var Sphere=function(a,b,e){THREE.Geometry.call(this);var f,g=Math.PI,h=Math.max(3,b||8),j=Math.max(2,e||6);b=[];for(e=0;e<j+1;e++){f=e/j;var c=a*Math.cos(f*g),i=a*Math.sin(f*g),l=[],u=0;for(f=0;f<h;f++){var C=2*f/h,o=i*Math.sin(C*g);C=i*Math.cos(C*g);(e==0||e==j)&&f>0||(u=this.vertices.push(new THREE.Vertex(new THREE.Vector3(C,c,o)))-1);l.push(u)}b.push(l)}var x,A,B;g=b.length;for(e=0;e<g;e++){h=b[e].length;if(e>0)for(f=0;f<h;f++){l=f==h-1;j=b[e][l?0:f+1];c=b[e][l?h-1:f];i=b[e-1][l?h-1:f];l=b[e-1][l?
0:f+1];o=e/(g-1);x=(e-1)/(g-1);A=(f+1)/h;C=f/h;u=new THREE.UV(1-A,o);o=new THREE.UV(1-C,o);C=new THREE.UV(1-C,x);var M=new THREE.UV(1-A,x);if(e<b.length-1){x=this.vertices[j].position.clone();A=this.vertices[c].position.clone();B=this.vertices[i].position.clone();x.normalize();A.normalize();B.normalize();this.faces.push(new THREE.Face3(j,c,i,[new THREE.Vector3(x.x,x.y,x.z),new THREE.Vector3(A.x,A.y,A.z),new THREE.Vector3(B.x,B.y,B.z)]));this.uvs.push([u,o,C])}if(e>1){x=this.vertices[j].position.clone();
A=this.vertices[i].position.clone();B=this.vertices[l].position.clone();x.normalize();A.normalize();B.normalize();this.faces.push(new THREE.Face3(j,i,l,[new THREE.Vector3(x.x,x.y,x.z),new THREE.Vector3(A.x,A.y,A.z),new THREE.Vector3(B.x,B.y,B.z)]));this.uvs.push([u,C,M])}}}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.sortFacesByMaterial();this.boundingSphere={radius:a}};Sphere.prototype=new THREE.Geometry;Sphere.prototype.constructor=Sphere;
THREE.Loader=function(a){this.statusDomElement=(this.showStatus=a)?this.addStatusElement():null};
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=
b},loadAsciiOld:function(a,b){var e=document.createElement("script");e.type="text/javascript";e.onload=b;e.src=a;document.getElementsByTagName("head")[0].appendChild(e)},loadAscii:function(a){var b=a.model,e=a.callback,f=a.texture_path?a.texture_path:THREE.Loader.prototype.extractUrlbase(b);a=(new Date).getTime();b=new Worker(b);b.onmessage=function(g){THREE.Loader.prototype.createModel(g.data,e,f)};b.postMessage(a)},loadBinary:function(a){var b=a.model,e=a.callback,f=a.texture_path?a.texture_path:
THREE.Loader.prototype.extractUrlbase(b),g=a.bin_path?a.bin_path:THREE.Loader.prototype.extractUrlbase(b);a=(new Date).getTime();b=new Worker(b);var h=this.showProgress?THREE.Loader.prototype.updateProgress:null;b.onmessage=function(j){THREE.Loader.prototype.loadAjaxBuffers(j.data.buffers,j.data.materials,e,g,f,h)};b.onerror=function(j){alert("worker.onerror: "+j.message+"\n"+j.data);j.preventDefault()};b.postMessage(a)},loadAjaxBuffers:function(a,b,e,f,g,h){var j=new XMLHttpRequest,c=f+"/"+a,i=0;
j.onreadystatechange=function(){if(j.readyState==4)j.status==200||j.status==0?THREE.Loader.prototype.createBinModel(j.responseText,e,g,b):alert("Couldn't load ["+c+"] ["+j.status+"]");else if(j.readyState==3){if(h){if(i==0)i=j.getResponseHeader("Content-Length");h({total:i,loaded:j.responseText.length})}}else if(j.readyState==2)i=j.getResponseHeader("Content-Length")};j.open("GET",c,true);j.overrideMimeType("text/plain; charset=x-user-defined");j.setRequestHeader("Content-Type","text/plain");j.send(null)},
createBinModel:function(a,b,e,f){var g=function(h){function j(m,F){var E=u(m,F),T=u(m,F+1),aa=u(m,F+2),ka=u(m,F+3),ga=(ka<<1&255|aa>>7)-127;E=(aa&127)<<16|T<<8|E;if(E==0&&ga==-127)return 0;return(1-2*(ka>>7))*(1+E*Math.pow(2,-23))*Math.pow(2,ga)}function c(m,F){var E=u(m,F),T=u(m,F+1),aa=u(m,F+2);return(u(m,F+3)<<24)+(aa<<16)+(T<<8)+E}function i(m,F){var E=u(m,F);return(u(m,F+1)<<8)+E}function l(m,F){var E=u(m,F);return E>127?E-256:E}function u(m,F){return m.charCodeAt(F)&255}function C(m){var F,
E,T;F=c(a,m);E=c(a,m+s);T=c(a,m+r);m=i(a,m+t);THREE.Loader.prototype.f3(q,F,E,T,m)}function o(m){var F,E,T,aa,ka,ga;F=c(a,m);E=c(a,m+s);T=c(a,m+r);aa=i(a,m+t);ka=c(a,m+w);ga=c(a,m+v);m=c(a,m+H);THREE.Loader.prototype.f3n(q,k,F,E,T,aa,ka,ga,m)}function x(m){var F,E,T,aa;F=c(a,m);E=c(a,m+y);T=c(a,m+n);aa=c(a,m+D);m=i(a,m+W);THREE.Loader.prototype.f4(q,F,E,T,aa,m)}function A(m){var F,E,T,aa,ka,ga,ra,ta;F=c(a,m);E=c(a,m+y);T=c(a,m+n);aa=c(a,m+D);ka=i(a,m+W);ga=c(a,m+J);ra=c(a,m+P);ta=c(a,m+U);m=c(a,m+
R);THREE.Loader.prototype.f4n(q,k,F,E,T,aa,ka,ga,ra,ta,m)}function B(m){var F,E;F=c(a,m);E=c(a,m+$);m=c(a,m+X);THREE.Loader.prototype.uv3(q,p[F*2],p[F*2+1],p[E*2],p[E*2+1],p[m*2],p[m*2+1])}function M(m){var F,E,T;F=c(a,m);E=c(a,m+L);T=c(a,m+O);m=c(a,m+Z);THREE.Loader.prototype.uv4(q,p[F*2],p[F*2+1],p[E*2],p[E*2+1],p[T*2],p[T*2+1],p[m*2],p[m*2+1])}var q=this,G=0,d,k=[],p=[],s,r,t,w,v,H,y,n,D,W,J,P,U,R,$,X,L,O,Z,S,z,N,Q,ea,da;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(q,f,h);d=
{signature:a.substr(G,8),header_bytes:u(a,G+8),vertex_coordinate_bytes:u(a,G+9),normal_coordinate_bytes:u(a,G+10),uv_coordinate_bytes:u(a,G+11),vertex_index_bytes:u(a,G+12),normal_index_bytes:u(a,G+13),uv_index_bytes:u(a,G+14),material_index_bytes:u(a,G+15),nvertices:c(a,G+16),nnormals:c(a,G+16+4),nuvs:c(a,G+16+8),ntri_flat:c(a,G+16+12),ntri_smooth:c(a,G+16+16),ntri_flat_uv:c(a,G+16+20),ntri_smooth_uv:c(a,G+16+24),nquad_flat:c(a,G+16+28),nquad_smooth:c(a,G+16+32),nquad_flat_uv:c(a,G+16+36),nquad_smooth_uv:c(a,
G+16+40)};G+=d.header_bytes;s=d.vertex_index_bytes;r=d.vertex_index_bytes*2;t=d.vertex_index_bytes*3;w=d.vertex_index_bytes*3+d.material_index_bytes;v=d.vertex_index_bytes*3+d.material_index_bytes+d.normal_index_bytes;H=d.vertex_index_bytes*3+d.material_index_bytes+d.normal_index_bytes*2;y=d.vertex_index_bytes;n=d.vertex_index_bytes*2;D=d.vertex_index_bytes*3;W=d.vertex_index_bytes*4;J=d.vertex_index_bytes*4+d.material_index_bytes;P=d.vertex_index_bytes*4+d.material_index_bytes+d.normal_index_bytes;
U=d.vertex_index_bytes*4+d.material_index_bytes+d.normal_index_bytes*2;R=d.vertex_index_bytes*4+d.material_index_bytes+d.normal_index_bytes*3;$=d.uv_index_bytes;X=d.uv_index_bytes*2;L=d.uv_index_bytes;O=d.uv_index_bytes*2;Z=d.uv_index_bytes*3;h=d.vertex_index_bytes*3+d.material_index_bytes;da=d.vertex_index_bytes*4+d.material_index_bytes;S=d.ntri_flat*h;z=d.ntri_smooth*(h+d.normal_index_bytes*3);N=d.ntri_flat_uv*(h+d.uv_index_bytes*3);Q=d.ntri_smooth_uv*(h+d.normal_index_bytes*3+d.uv_index_bytes*
3);ea=d.nquad_flat*da;h=d.nquad_smooth*(da+d.normal_index_bytes*4);da=d.nquad_flat_uv*(da+d.uv_index_bytes*4);G+=function(m){var F,E,T,aa=d.vertex_coordinate_bytes*3,ka=m+d.nvertices*aa;for(m=m;m<ka;m+=aa){F=j(a,m);E=j(a,m+d.vertex_coordinate_bytes);T=j(a,m+d.vertex_coordinate_bytes*2);THREE.Loader.prototype.v(q,F,E,T)}return d.nvertices*aa}(G);G+=function(m){var F,E,T,aa=d.normal_coordinate_bytes*3,ka=m+d.nnormals*aa;for(m=m;m<ka;m+=aa){F=l(a,m);E=l(a,m+d.normal_coordinate_bytes);T=l(a,m+d.normal_coordinate_bytes*
2);k.push(F/127,E/127,T/127)}return d.nnormals*aa}(G);G+=function(m){var F,E,T=d.uv_coordinate_bytes*2,aa=m+d.nuvs*T;for(m=m;m<aa;m+=T){F=j(a,m);E=j(a,m+d.uv_coordinate_bytes);p.push(F,E)}return d.nuvs*T}(G);G=G;S=G+S;z=S+z;N=z+N;Q=N+Q;ea=Q+ea;h=ea+h;da=h+da;(function(m){var F,E=d.vertex_index_bytes*3+d.material_index_bytes,T=E+d.uv_index_bytes*3,aa=m+d.ntri_flat_uv*T;for(F=m;F<aa;F+=T){C(F);B(F+E)}return aa-m})(z);(function(m){var F,E=d.vertex_index_bytes*3+d.material_index_bytes+d.normal_index_bytes*
3,T=E+d.uv_index_bytes*3,aa=m+d.ntri_smooth_uv*T;for(F=m;F<aa;F+=T){o(F);B(F+E)}return aa-m})(N);(function(m){var F,E=d.vertex_index_bytes*4+d.material_index_bytes,T=E+d.uv_index_bytes*4,aa=m+d.nquad_flat_uv*T;for(F=m;F<aa;F+=T){x(F);M(F+E)}return aa-m})(h);(function(m){var F,E=d.vertex_index_bytes*4+d.material_index_bytes+d.normal_index_bytes*4,T=E+d.uv_index_bytes*4,aa=m+d.nquad_smooth_uv*T;for(F=m;F<aa;F+=T){A(F);M(F+E)}return aa-m})(da);(function(m){var F,E=d.vertex_index_bytes*3+d.material_index_bytes,
T=m+d.ntri_flat*E;for(F=m;F<T;F+=E)C(F);return T-m})(G);(function(m){var F,E=d.vertex_index_bytes*3+d.material_index_bytes+d.normal_index_bytes*3,T=m+d.ntri_smooth*E;for(F=m;F<T;F+=E)o(F);return T-m})(S);(function(m){var F,E=d.vertex_index_bytes*4+d.material_index_bytes,T=m+d.nquad_flat*E;for(F=m;F<T;F+=E)x(F);return T-m})(Q);(function(m){var F,E=d.vertex_index_bytes*4+d.material_index_bytes+d.normal_index_bytes*4,T=m+d.nquad_smooth*E;for(F=m;F<T;F+=E)A(F);return T-m})(ea);this.computeCentroids();
this.computeFaceNormals();this.sortFacesByMaterial()};g.prototype=new THREE.Geometry;g.prototype.constructor=g;b(new g(e))},createModel:function(a,b,e){var f=function(g){var h=this;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(h,a.materials,g);(function(){var j,c,i,l,u;j=0;for(c=a.vertices.length;j<c;j+=3){i=a.vertices[j];l=a.vertices[j+1];u=a.vertices[j+2];THREE.Loader.prototype.v(h,i,l,u)}})();(function(){function j(A,B){THREE.Loader.prototype.f3(h,A[B],A[B+1],A[B+2],A[B+3])}function c(A,
B){THREE.Loader.prototype.f3n(h,a.normals,A[B],A[B+1],A[B+2],A[B+3],A[B+4],A[B+5],A[B+6])}function i(A,B){THREE.Loader.prototype.f4(h,A[B],A[B+1],A[B+2],A[B+3],A[B+4])}function l(A,B){THREE.Loader.prototype.f4n(h,a.normals,A[B],A[B+1],A[B+2],A[B+3],A[B+4],A[B+5],A[B+6],A[B+7],A[B+8])}function u(A,B){var M,q,G;M=A[B];q=A[B+1];G=A[B+2];THREE.Loader.prototype.uv3(h,a.uvs[M*2],a.uvs[M*2+1],a.uvs[q*2],a.uvs[q*2+1],a.uvs[G*2],a.uvs[G*2+1])}function C(A,B){var M,q,G,d;M=A[B];q=A[B+1];G=A[B+2];d=A[B+3];THREE.Loader.prototype.uv4(h,
a.uvs[M*2],a.uvs[M*2+1],a.uvs[q*2],a.uvs[q*2+1],a.uvs[G*2],a.uvs[G*2+1],a.uvs[d*2],a.uvs[d*2+1])}var o,x;o=0;for(x=a.triangles_uv.length;o<x;o+=7){j(a.triangles_uv,o);u(a.triangles_uv,o+4)}o=0;for(x=a.triangles_n_uv.length;o<x;o+=10){c(a.triangles_n_uv,o);u(a.triangles_n_uv,o+7)}o=0;for(x=a.quads_uv.length;o<x;o+=9){i(a.quads_uv,o);C(a.quads_uv,o+5)}o=0;for(x=a.quads_n_uv.length;o<x;o+=13){l(a.quads_n_uv,o);C(a.quads_n_uv,o+9)}o=0;for(x=a.triangles.length;o<x;o+=4)j(a.triangles,o);o=0;for(x=a.triangles_n.length;o<
x;o+=7)c(a.triangles_n,o);o=0;for(x=a.quads.length;o<x;o+=5)i(a.quads,o);o=0;for(x=a.quads_n.length;o<x;o+=9)l(a.quads_n,o)})();this.computeCentroids();this.computeFaceNormals();this.sortFacesByMaterial()};f.prototype=new THREE.Geometry;f.prototype.constructor=f;b(new f(e))},v:function(a,b,e,f){a.vertices.push(new THREE.Vertex(new THREE.Vector3(b,e,f)))},f3:function(a,b,e,f,g){a.faces.push(new THREE.Face3(b,e,f,null,a.materials[g]))},f4:function(a,b,e,f,g,h){a.faces.push(new THREE.Face4(b,e,f,g,null,
a.materials[h]))},f3n:function(a,b,e,f,g,h,j,c,i){h=a.materials[h];var l=b[c*3],u=b[c*3+1];c=b[c*3+2];var C=b[i*3],o=b[i*3+1];i=b[i*3+2];a.faces.push(new THREE.Face3(e,f,g,[new THREE.Vector3(b[j*3],b[j*3+1],b[j*3+2]),new THREE.Vector3(l,u,c),new THREE.Vector3(C,o,i)],h))},f4n:function(a,b,e,f,g,h,j,c,i,l,u){j=a.materials[j];var C=b[i*3],o=b[i*3+1];i=b[i*3+2];var x=b[l*3],A=b[l*3+1];l=b[l*3+2];var B=b[u*3],M=b[u*3+1];u=b[u*3+2];a.faces.push(new THREE.Face4(e,f,g,h,[new THREE.Vector3(b[c*3],b[c*3+1],
b[c*3+2]),new THREE.Vector3(C,o,i),new THREE.Vector3(x,A,l),new THREE.Vector3(B,M,u)],j))},uv3:function(a,b,e,f,g,h,j){var c=[];c.push(new THREE.UV(b,e));c.push(new THREE.UV(f,g));c.push(new THREE.UV(h,j));a.uvs.push(c)},uv4:function(a,b,e,f,g,h,j,c,i){var l=[];l.push(new THREE.UV(b,e));l.push(new THREE.UV(f,g));l.push(new THREE.UV(h,j));l.push(new THREE.UV(c,i));a.uvs.push(l)},init_materials:function(a,b,e){a.materials=[];for(var f=0;f<b.length;++f)a.materials[f]=[THREE.Loader.prototype.createMaterial(b[f],
e)]},createMaterial:function(a,b){function e(h){h=Math.log(h)/Math.LN2;return Math.floor(h)==h}var f,g;if(a.map_diffuse&&b){g=document.createElement("canvas");f=new THREE.MeshLambertMaterial({map:new THREE.Texture(g)});g=new Image;g.onload=function(){if(!e(this.width)||!e(this.height)){var h=Math.pow(2,Math.round(Math.log(this.width)/Math.LN2)),j=Math.pow(2,Math.round(Math.log(this.height)/Math.LN2));f.map.image.width=h;f.map.image.height=j;f.map.image.getContext("2d").drawImage(this,0,0,h,j)}else f.map.image=
this;f.map.image.loaded=1};g.src=b+"/"+a.map_diffuse}else if(a.col_diffuse){g=(a.col_diffuse[0]*255<<16)+(a.col_diffuse[1]*255<<8)+a.col_diffuse[2]*255;f=new THREE.MeshLambertMaterial({color:g,opacity:a.transparency})}else f=a.a_dbg_color?new THREE.MeshLambertMaterial({color:a.a_dbg_color}):new THREE.MeshLambertMaterial({color:15658734});return f},extractUrlbase:function(a){a=a.split("/");a.pop();return a.join("/")}};