// ThreeDebug.js r29 - 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,c,f){this.r=a;this.g=c;this.b=f;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)+")"},toString:function(){return"THREE.Color ( r: "+this.r+", g: "+this.g+", b: "+this.b+", hex: "+this.hex+" )"}};THREE.Vector2=function(a,c){this.x=a||0;this.y=c||0};
THREE.Vector2.prototype={set:function(a,c){this.x=a;this.y=c;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,c){this.x=a.x+c.x;this.y=a.y+c.y;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;return this},sub:function(a,c){this.x=a.x-c.x;this.y=a.y-c.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,c,f){this.x=a||0;this.y=c||0;this.z=f||0};
THREE.Vector3.prototype={set:function(a,c,f){this.x=a;this.y=c;this.z=f;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this},add:function(a,c){this.x=a.x+c.x;this.y=a.y+c.y;this.z=a.z+c.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,c){this.x=a.x-c.x;this.y=a.y-c.y;this.z=a.z-c.z;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;return this},
cross:function(a,c){this.x=a.y*c.z-a.z*c.y;this.y=a.z*c.x-a.x*c.z;this.z=a.x*c.y-a.y*c.x;return this},crossSelf:function(a){var c=this.x,f=this.y,h=this.z;this.x=f*a.z-h*a.y;this.y=h*a.x-c*a.z;this.z=c*a.y-f*a.x;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;return this},divideScalar:function(a){this.x/=a;this.y/=a;this.z/=a;return this},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},
distanceToSquared:function(a){var c=this.x-a.x,f=this.y-a.y;a=this.z-a.z;return c*c+f*f+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(){this.length()>0?this.multiplyScalar(1/this.length()):this.multiplyScalar(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,c,f,h){this.x=a||0;this.y=c||0;this.z=f||0;this.w=h||1};
THREE.Vector4.prototype={set:function(a,c,f,h){this.x=a;this.y=c;this.z=f;this.w=h;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,c){this.x=a.x+c.x;this.y=a.y+c.y;this.z=a.z+c.z;this.w=a.w+c.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,c){this.x=a.x-c.x;this.y=a.y-c.y;this.z=a.z-c.z;this.w=a.w-c.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,c){this.x+=(a.x-this.x)*c;this.y+=(a.y-this.y)*c;this.z+=(a.z-this.z)*c;this.w+=(a.w-this.w)*c},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,c){this.origin=a||new THREE.Vector3;this.direction=c||new THREE.Vector3};
THREE.Ray.prototype={intersectScene:function(a){var c,f,h=a.objects,b=[];a=0;for(c=h.length;a<c;a++){f=h[a];if(f instanceof THREE.Mesh)b=b.concat(this.intersectObject(f))}b.sort(function(d,p){return d.distance-p.distance});return b},intersectObject:function(a){function c(C,v,L,r){r=r.clone().subSelf(v);L=L.clone().subSelf(v);var q=C.clone().subSelf(v);C=r.dot(r);v=r.dot(L);r=r.dot(q);var l=L.dot(L);L=L.dot(q);q=1/(C*l-v*v);l=(l*r-v*L)*q;C=(C*L-v*r)*q;return l>0&&C>0&&l+C<1}var f,h,b,d,p,s,o,e,g,k,
i,n=a.geometry,j=n.vertices,A=[];f=0;for(h=n.faces.length;f<h;f++){b=n.faces[f];k=this.origin.clone();i=this.direction.clone();d=a.matrix.transform(j[b.a].position.clone());p=a.matrix.transform(j[b.b].position.clone());s=a.matrix.transform(j[b.c].position.clone());o=b instanceof THREE.Face4?a.matrix.transform(j[b.d].position.clone()):null;e=a.matrixRotation.transform(b.normal.clone());g=i.dot(e);if(g<0){e=e.dot((new THREE.Vector3).sub(d,k))/g;k=k.addSelf(i.multiplyScalar(e));if(b instanceof THREE.Face3){if(c(k,
d,p,s)){b={distance:this.origin.distanceTo(k),point:k,face:b,object:a};A.push(b)}}else if(b instanceof THREE.Face4)if(c(k,d,p,o)||c(k,p,s,o)){b={distance:this.origin.distanceTo(k),point:k,face:b,object:a};A.push(b)}}}return A}};
THREE.Rectangle=function(){function a(){d=h-c;p=b-f}var c,f,h,b,d,p,s=true;this.getX=function(){return c};this.getY=function(){return f};this.getWidth=function(){return d};this.getHeight=function(){return p};this.getLeft=function(){return c};this.getTop=function(){return f};this.getRight=function(){return h};this.getBottom=function(){return b};this.set=function(o,e,g,k){s=false;c=o;f=e;h=g;b=k;a()};this.addPoint=function(o,e){if(s){s=false;c=o;f=e;h=o;b=e}else{c=Math.min(c,o);f=Math.min(f,e);h=Math.max(h,
o);b=Math.max(b,e)}a()};this.addRectangle=function(o){if(s){s=false;c=o.getLeft();f=o.getTop();h=o.getRight();b=o.getBottom()}else{c=Math.min(c,o.getLeft());f=Math.min(f,o.getTop());h=Math.max(h,o.getRight());b=Math.max(b,o.getBottom())}a()};this.inflate=function(o){c-=o;f-=o;h+=o;b+=o;a()};this.minSelf=function(o){c=Math.max(c,o.getLeft());f=Math.max(f,o.getTop());h=Math.min(h,o.getRight());b=Math.min(b,o.getBottom());a()};this.instersects=function(o){return Math.min(h,o.getRight())-Math.max(c,o.getLeft())>=
0&&Math.min(b,o.getBottom())-Math.max(f,o.getTop())>=0};this.empty=function(){s=true;b=h=f=c=0;a()};this.isEmpty=function(){return s};this.toString=function(){return"THREE.Rectangle ( left: "+c+", right: "+h+", top: "+f+", bottom: "+b+", width: "+d+", height: "+p+" )"}};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(){this._x=new THREE.Vector3;this._y=new THREE.Vector3;this._z=new THREE.Vector3};
THREE.Matrix4.prototype={n11:1,n12:0,n13:0,n14:0,n21:0,n22:1,n23:0,n24:0,n31:0,n32:0,n33:1,n34:0,n41:0,n42:0,n43:0,n44:1,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},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},lookAt:function(a,c,f){var h=this._x,b=this._y,d=this._z;d.sub(a,c);d.normalize();h.cross(f,d);h.normalize();b.cross(d,h);b.normalize();this.n11=h.x;this.n12=h.y;this.n13=h.z;this.n14=-h.dot(a);this.n21=b.x;this.n22=b.y;this.n23=b.z;this.n24=-b.dot(a);this.n31=d.x;this.n32=d.y;this.n33=d.z;this.n34=-d.dot(a);this.n43=this.n42=this.n41=0;this.n44=1},transform:function(a){var c=a.x,f=a.y,h=a.z,b=a.w?a.w:1;a.x=this.n11*c+this.n12*f+this.n13*h+this.n14*
b;a.y=this.n21*c+this.n22*f+this.n23*h+this.n24*b;a.z=this.n31*c+this.n32*f+this.n33*h+this.n34*b;b=this.n41*c+this.n42*f+this.n43*h+this.n44*b;if(a.w)a.w=b;else{a.x/=b;a.y/=b;a.z/=b}return a},crossVector:function(a){var c=new THREE.Vector4;c.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;c.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24*a.w;c.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;c.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return c},multiply:function(a,
c){this.n11=a.n11*c.n11+a.n12*c.n21+a.n13*c.n31+a.n14*c.n41;this.n12=a.n11*c.n12+a.n12*c.n22+a.n13*c.n32+a.n14*c.n42;this.n13=a.n11*c.n13+a.n12*c.n23+a.n13*c.n33+a.n14*c.n43;this.n14=a.n11*c.n14+a.n12*c.n24+a.n13*c.n34+a.n14*c.n44;this.n21=a.n21*c.n11+a.n22*c.n21+a.n23*c.n31+a.n24*c.n41;this.n22=a.n21*c.n12+a.n22*c.n22+a.n23*c.n32+a.n24*c.n42;this.n23=a.n21*c.n13+a.n22*c.n23+a.n23*c.n33+a.n24*c.n43;this.n24=a.n21*c.n14+a.n22*c.n24+a.n23*c.n34+a.n24*c.n44;this.n31=a.n31*c.n11+a.n32*c.n21+a.n33*c.n31+
a.n34*c.n41;this.n32=a.n31*c.n12+a.n32*c.n22+a.n33*c.n32+a.n34*c.n42;this.n33=a.n31*c.n13+a.n32*c.n23+a.n33*c.n33+a.n34*c.n43;this.n34=a.n31*c.n14+a.n32*c.n24+a.n33*c.n34+a.n34*c.n44;this.n41=a.n41*c.n11+a.n42*c.n21+a.n43*c.n31+a.n44*c.n41;this.n42=a.n41*c.n12+a.n42*c.n22+a.n43*c.n32+a.n44*c.n42;this.n43=a.n41*c.n13+a.n42*c.n23+a.n43*c.n33+a.n44*c.n43;this.n44=a.n41*c.n14+a.n42*c.n24+a.n43*c.n34+a.n44*c.n44},multiplySelf:function(a){var c=this.n11,f=this.n12,h=this.n13,b=this.n14,d=this.n21,p=this.n22,
s=this.n23,o=this.n24,e=this.n31,g=this.n32,k=this.n33,i=this.n34,n=this.n41,j=this.n42,A=this.n43,C=this.n44;this.n11=c*a.n11+f*a.n21+h*a.n31+b*a.n41;this.n12=c*a.n12+f*a.n22+h*a.n32+b*a.n42;this.n13=c*a.n13+f*a.n23+h*a.n33+b*a.n43;this.n14=c*a.n14+f*a.n24+h*a.n34+b*a.n44;this.n21=d*a.n11+p*a.n21+s*a.n31+o*a.n41;this.n22=d*a.n12+p*a.n22+s*a.n32+o*a.n42;this.n23=d*a.n13+p*a.n23+s*a.n33+o*a.n43;this.n24=d*a.n14+p*a.n24+s*a.n34+o*a.n44;this.n31=e*a.n11+g*a.n21+k*a.n31+i*a.n41;this.n32=e*a.n12+g*a.n22+
k*a.n32+i*a.n42;this.n33=e*a.n13+g*a.n23+k*a.n33+i*a.n43;this.n34=e*a.n14+g*a.n24+k*a.n34+i*a.n44;this.n41=n*a.n11+j*a.n21+A*a.n31+C*a.n41;this.n42=n*a.n12+j*a.n22+A*a.n32+C*a.n42;this.n43=n*a.n13+j*a.n23+A*a.n33+C*a.n43;this.n44=n*a.n14+j*a.n24+A*a.n34+C*a.n44},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},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(c,f,h){var b=c[f];c[f]=c[h];c[h]=b}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,c,f){var h=new THREE.Matrix4;h.n14=a;h.n24=c;h.n34=f;return h};THREE.Matrix4.scaleMatrix=function(a,c,f){var h=new THREE.Matrix4;h.n11=a;h.n22=c;h.n33=f;return h};
THREE.Matrix4.rotationXMatrix=function(a){var c=new THREE.Matrix4;c.n22=c.n33=Math.cos(a);c.n32=Math.sin(a);c.n23=-c.n32;return c};THREE.Matrix4.rotationYMatrix=function(a){var c=new THREE.Matrix4;c.n11=c.n33=Math.cos(a);c.n13=Math.sin(a);c.n31=-c.n13;return c};THREE.Matrix4.rotationZMatrix=function(a){var c=new THREE.Matrix4;c.n11=c.n22=Math.cos(a);c.n21=Math.sin(a);c.n12=-c.n21;return c};
THREE.Matrix4.rotationAxisAngleMatrix=function(a,c){var f=new THREE.Matrix4,h=Math.cos(c),b=Math.sin(c),d=1-h,p=a.x,s=a.y,o=a.z;f.n11=d*p*p+h;f.n12=d*p*s-b*o;f.n13=d*p*o+b*s;f.n21=d*p*s+b*o;f.n22=d*s*s+h;f.n23=d*s*o-b*p;f.n31=d*p*o-b*s;f.n32=d*s*o+b*p;f.n33=d*o*o+h;return f};
THREE.Matrix4.makeInvert=function(a){var c=new THREE.Matrix4;c.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;c.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;c.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;c.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;c.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;c.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;c.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;c.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;c.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;c.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;c.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;c.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;c.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;c.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;c.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;c.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;c.multiplyScalar(1/a.determinant());return c};
THREE.Matrix4.makeInvert3x3=function(a){var c=a.flatten();a=new THREE.Matrix3;var f=c[10]*c[5]-c[6]*c[9],h=-c[10]*c[1]+c[2]*c[9],b=c[6]*c[1]-c[2]*c[5],d=-c[10]*c[4]+c[6]*c[8],p=c[10]*c[0]-c[2]*c[8],s=-c[6]*c[0]+c[2]*c[4],o=c[9]*c[4]-c[5]*c[8],e=-c[9]*c[0]+c[1]*c[8],g=c[5]*c[0]-c[1]*c[4];c=c[0]*f+c[1]*d+c[2]*o;if(c==0)throw"matrix not invertible";c=1/c;a.m[0]=c*f;a.m[1]=c*h;a.m[2]=c*b;a.m[3]=c*d;a.m[4]=c*p;a.m[5]=c*s;a.m[6]=c*o;a.m[7]=c*e;a.m[8]=c*g;return a};
THREE.Matrix4.makeFrustum=function(a,c,f,h,b,d){var p,s,o;p=new THREE.Matrix4;s=2*b/(c-a);o=2*b/(h-f);a=(c+a)/(c-a);f=(h+f)/(h-f);h=-(d+b)/(d-b);b=-2*d*b/(d-b);p.n11=s;p.n12=0;p.n13=a;p.n14=0;p.n21=0;p.n22=o;p.n23=f;p.n24=0;p.n31=0;p.n32=0;p.n33=h;p.n34=b;p.n41=0;p.n42=0;p.n43=-1;p.n44=0;return p};THREE.Matrix4.makePerspective=function(a,c,f,h){var b;a=f*Math.tan(a*Math.PI/360);b=-a;return THREE.Matrix4.makeFrustum(b*c,a*c,b,a,f,h)};
THREE.Matrix4.makeOrtho=function(a,c,f,h,b,d){var p,s,o,e;p=new THREE.Matrix4;s=c-a;o=f-h;e=d-b;a=(c+a)/s;f=(f+h)/o;b=(d+b)/e;p.n11=2/s;p.n12=0;p.n13=0;p.n14=-a;p.n21=0;p.n22=2/o;p.n23=0;p.n24=-f;p.n31=0;p.n32=0;p.n33=-2/e;p.n34=-b;p.n41=0;p.n42=0;p.n43=0;p.n44=1;return p};
THREE.Vertex=function(a,c){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=c||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.__visible=true};THREE.Vertex.prototype={toString:function(){return"THREE.Vertex ( position: "+this.position+", normal: "+this.normal+" )"}};
THREE.Face3=function(a,c,f,h,b){this.a=a;this.b=c;this.c=f;this.centroid=new THREE.Vector3;this.normal=h instanceof THREE.Vector3?h:new THREE.Vector3;this.vertexNormals=h instanceof Array?h:[];this.material=b instanceof Array?b:[b]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
THREE.Face4=function(a,c,f,h,b,d){this.a=a;this.b=c;this.c=f;this.d=h;this.centroid=new THREE.Vector3;this.normal=b instanceof THREE.Vector3?b:new THREE.Vector3;this.vertexNormals=b instanceof Array?b:[];this.material=d instanceof Array?d:[d]};THREE.Face4.prototype={toString:function(){return"THREE.Face4 ( "+this.a+", "+this.b+", "+this.c+" "+this.d+" )"}};THREE.UV=function(a,c){this.u=a||0;this.v=c||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=[]};
THREE.Geometry.prototype={computeCentroids:function(){var a,c,f;a=0;for(c=this.faces.length;a<c;a++){f=this.faces[a];f.centroid.set(0,0,0);if(f instanceof THREE.Face3){f.centroid.addSelf(this.vertices[f.a].position);f.centroid.addSelf(this.vertices[f.b].position);f.centroid.addSelf(this.vertices[f.c].position);f.centroid.divideScalar(3)}else if(f instanceof THREE.Face4){f.centroid.addSelf(this.vertices[f.a].position);f.centroid.addSelf(this.vertices[f.b].position);f.centroid.addSelf(this.vertices[f.c].position);
f.centroid.addSelf(this.vertices[f.d].position);f.centroid.divideScalar(4)}}},computeNormals:function(a){var c,f,h,b,d,p,s=new THREE.Vector3,o=new THREE.Vector3;h=0;for(b=this.vertices.length;h<b;h++){d=this.vertices[h];d.normal.set(0,0,0)}h=0;for(b=this.faces.length;h<b;h++){d=this.faces[h];if(a&&d.vertexNormals.length){s.set(0,0,0);c=0;for(f=d.normal.length;c<f;c++)s.addSelf(d.vertexNormals[c]);s.divideScalar(3)}else{c=this.vertices[d.a];f=this.vertices[d.b];p=this.vertices[d.c];s.sub(p.position,
f.position);o.sub(c.position,f.position);s.crossSelf(o)}s.isZero()||s.normalize();d.normal.copy(s)}},computeBoundingBox:function(){if(this.vertices.length>0){this.bbox={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 a=1,c=this.vertices.length;a<c;a++){vertex=this.vertices[a];if(vertex.position.x<this.bbox.x[0])this.bbox.x[0]=vertex.position.x;else if(vertex.position.x>
this.bbox.x[1])this.bbox.x[1]=vertex.position.x;if(vertex.position.y<this.bbox.y[0])this.bbox.y[0]=vertex.position.y;else if(vertex.position.y>this.bbox.y[1])this.bbox.y[1]=vertex.position.y;if(vertex.position.z<this.bbox.z[0])this.bbox.z[0]=vertex.position.z;else if(vertex.position.z>this.bbox.z[1])this.bbox.z[1]=vertex.position.z}}},toString:function(){return"THREE.Geometry ( vertices: "+this.vertices+", faces: "+this.faces+" )"}};
THREE.Camera=function(a,c,f,h){this.position=new THREE.Vector3(0,0,0);this.target={position:new THREE.Vector3(0,0,0)};this.up=new THREE.Vector3(0,1,0);this.matrix=new THREE.Matrix4;this.projectionMatrix=THREE.Matrix4.makePerspective(a,c,f,h);this.autoUpdateMatrix=true;this.updateMatrix=function(){this.matrix.lookAt(this.position,this.target.position,this.up)};this.toString=function(){return"THREE.Camera ( "+this.position+", "+this.target.position+" )"}};
THREE.Light=function(a){this.color=new THREE.Color(-16777216|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,c){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,1,0);this.intensity=c||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.DirectionalLight;
THREE.PointLight=function(a,c){THREE.Light.call(this,a);this.position=new THREE.Vector3(0,0,0);this.intensity=c||1};THREE.DirectionalLight.prototype=new THREE.Light;THREE.DirectionalLight.prototype.constructor=THREE.PointLight;
THREE.Object3D=function(){this.position=new THREE.Vector3;this.rotation=new THREE.Vector3;this.scale=new THREE.Vector3(1,1,1);this.matrix=new THREE.Matrix4;this.matrixTranslation=new THREE.Matrix4;this.matrixRotation=new THREE.Matrix4;this.matrixScale=new THREE.Matrix4;this.screen=new THREE.Vector3;this.autoUpdateMatrix=this.visible=true;this.updateMatrix=function(){this.matrixPosition=THREE.Matrix4.translationMatrix(this.position.x,this.position.y,this.position.z);this.matrixRotation=THREE.Matrix4.rotationXMatrix(this.rotation.x);
this.matrixRotation.multiplySelf(THREE.Matrix4.rotationYMatrix(this.rotation.y));this.matrixRotation.multiplySelf(THREE.Matrix4.rotationZMatrix(this.rotation.z));this.matrixScale=THREE.Matrix4.scaleMatrix(this.scale.x,this.scale.y,this.scale.z);this.matrix.copy(this.matrixPosition);this.matrix.multiplySelf(this.matrixRotation);this.matrix.multiplySelf(this.matrixScale)}};THREE.Particle=function(a){THREE.Object3D.call(this);this.material=a instanceof Array?a:[a];this.autoUpdateMatrix=false};
THREE.Particle.prototype=new THREE.Object3D;THREE.Particle.prototype.constructor=THREE.Particle;THREE.Line=function(a,c){THREE.Object3D.call(this);this.geometry=a;this.material=c instanceof Array?c:[c]};THREE.Line.prototype=new THREE.Object3D;THREE.Line.prototype.constructor=THREE.Line;
THREE.Mesh=function(a,c,f){THREE.Object3D.call(this);this.geometry=a;this.material=c instanceof Array?c:[c];this.overdraw=this.doubleSided=this.flipSided=false;this.materialFaceGroup={};this.sortFacesByMaterial();f&&this.normalizeUVs();this.geometry.computeBoundingBox()};THREE.Mesh.prototype=new THREE.Object3D;THREE.Mesh.prototype.constructor=THREE.Mesh;
THREE.Mesh.prototype.sortFacesByMaterial=function(){function a(g){var k=[];c=0;for(f=g.length;c<f;c++)g[c]==undefined?k.push("undefined"):k.push(g[c].toString());return k.join("_")}var c,f,h,b,d,p,s,o,e={};h=0;for(b=this.geometry.faces.length;h<b;h++){d=this.geometry.faces[h];p=d.material;s=a(p);if(e[s]==undefined)e[s]={hash:s,counter:0};o=e[s].hash+"_"+e[s].counter;if(this.materialFaceGroup[o]==undefined)this.materialFaceGroup[o]={faces:[],material:p,vertices:0};d=d instanceof THREE.Face3?3:4;if(this.materialFaceGroup[o].vertices+
d>65535){e[s].counter+=1;o=e[s].hash+"_"+e[s].counter;if(this.materialFaceGroup[o]==undefined)this.materialFaceGroup[o]={faces:[],material:p,vertices:0}}this.materialFaceGroup[o].faces.push(h);this.materialFaceGroup[o].vertices+=d}};THREE.Mesh.prototype.normalizeUVs=function(){var a,c,f,h,b;a=0;for(c=this.geometry.uvs.length;a<c;a++){b=this.geometry.uvs[a];f=0;for(h=b.length;f<h;f++){if(b[f].u!=1)b[f].u-=Math.floor(b[f].u);if(b[f].v!=1)b[f].v-=Math.floor(b[f].v)}}};THREE.FlatShading=0;
THREE.SmoothShading=1;THREE.NormalBlending=0;THREE.AdditiveBlending=1;THREE.SubtractiveBlending=2;
THREE.LineBasicMaterial=function(a){this.color=new THREE.Color(16711680);this.opacity=1;this.blending=THREE.NormalBlending;this.linewidth=1;this.linejoin=this.linecap="round";if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending;if(a.linewidth!==undefined)this.linewidth=a.linewidth;if(a.linecap!==undefined)this.linecap=a.linecap;if(a.linejoin!==undefined)this.linejoin=a.linejoin}this.toString=function(){return"THREE.LineBasicMaterial (<br/>color: "+
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(15658734);this.env_map=this.map=null;this.combine=THREE.Multiply;this.reflectivity=1;this.refraction_ratio=0.98;this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=this.wireframe_linecap="round";if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.map!==undefined)this.map=a.map;if(a.env_map!==
undefined)this.env_map=a.env_map;if(a.combine!==undefined)this.combine=a.combine;if(a.reflectivity!==undefined)this.reflectivity=a.reflectivity;if(a.refraction_ratio!==undefined)this.refraction_ratio=a.refraction_ratio;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframe_linewidth!==undefined)this.wireframe_linewidth=a.wireframe_linewidth;
if(a.wireframe_linecap!==undefined)this.wireframe_linecap=a.wireframe_linecap;if(a.wireframe_linejoin!==undefined)this.wireframe_linejoin=a.wireframe_linejoin}this.toString=function(){return"THREE.MeshBasicMaterial (<br/>id: "+this.id+"<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>env_map: "+this.env_map+"<br/>combine: "+this.combine+"<br/>reflectivity: "+this.reflectivity+"<br/>refraction_ratio: "+this.refraction_ratio+"<br/>opacity: "+this.opacity+"<br/>blending: "+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(15658734);this.env_map=this.map=null;this.combine=THREE.Multiply;this.reflectivity=1;this.refraction_ratio=0.98;this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=this.wireframe_linecap="round";if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.map!==undefined)this.map=a.map;
if(a.env_map!==undefined)this.env_map=a.env_map;if(a.combine!==undefined)this.combine=a.combine;if(a.reflectivity!==undefined)this.reflectivity=a.reflectivity;if(a.refraction_ratio!==undefined)this.refraction_ratio=a.refraction_ratio;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframe_linewidth!==undefined)this.wireframe_linewidth=a.wireframe_linewidth;
if(a.wireframe_linecap!==undefined)this.wireframe_linecap=a.wireframe_linecap;if(a.wireframe_linejoin!==undefined)this.wireframe_linejoin=a.wireframe_linejoin}this.toString=function(){return"THREE.MeshLambertMaterial (<br/>id: "+this.id+"<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>env_map: "+this.env_map+"<br/>combine: "+this.combine+"<br/>reflectivity: "+this.reflectivity+"<br/>refraction_ratio: "+this.refraction_ratio+"<br/>opacity: "+this.opacity+"<br/>shading: "+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(15658734);this.ambient=new THREE.Color(328965);this.specular=new THREE.Color(1118481);this.shininess=30;this.env_map=this.specular_map=this.map=null;this.combine=THREE.Multiply;this.reflectivity=1;this.refraction_ratio=0.98;this.opacity=1;this.shading=THREE.SmoothShading;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;this.wireframe_linejoin=this.wireframe_linecap=
"round";if(a){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.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}this.toString=function(){return"THREE.MeshPhongMaterial (<br/>id: "+this.id+"<br/>color: "+this.color+"<br/>ambient: "+this.ambient+"<br/>specular: "+this.specular+"<br/>shininess: "+this.shininess+"<br/>map: "+this.map+"<br/>specular_map: "+this.specular_map+"<br/>env_map: "+this.env_map+"<br/>combine: "+this.combine+"<br/>reflectivity: "+this.reflectivity+"<br/>refraction_ratio: "+this.refraction_ratio+"<br/>opacity: "+this.opacity+"<br/>shading: "+this.shading+"<br/>wireframe: "+
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.near=1;this.far=1E3;this.opacity=1;this.blending=THREE.NormalBlending;if(a){if(a.near!==undefined)this.near=a.near;if(a.far!==undefined)this.far=a.far;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}this.__2near=2*this.near;this.__farPlusNear=this.far+this.near;this.__farMinusNear=this.far-this.near;this.toString=function(){return"THREE.MeshDepthMaterial"}};
THREE.MeshNormalMaterial=function(a){this.opacity=1;this.shading=THREE.FlatShading;this.blending=THREE.NormalBlending;if(a){if(a.opacity!==undefined)this.opacity=a.opacity;if(a.shading!==undefined)this.shading=a.shading;if(a.blending!==undefined)this.blending=a.blending}this.toString=function(){return"THREE.MeshNormalMaterial"}};THREE.MeshFaceMaterial=function(){this.toString=function(){return"THREE.MeshFaceMaterial"}};
THREE.MeshCubeMaterial=function(a){this.id=THREE.MeshCubeMaterial.value++;this.env_map=null;this.blending=THREE.NormalBlending;if(a)if(a.env_map!==undefined)this.env_map=a.env_map;this.toString=function(){return"THREE.MeshCubeMaterial( id: "+this.id+"<br/>env_map: "+this.env_map+" )"}};THREE.MeshCubeMaterialCounter={value:0};
THREE.ParticleBasicMaterial=function(a){this.color=new THREE.Color(16711680);this.map=null;this.opacity=1;this.blending=THREE.NormalBlending;this.offset=new THREE.Vector2;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.map!==undefined)this.map=a.map;if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}this.toString=function(){return"THREE.ParticleBasicMaterial (<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>opacity: "+this.opacity+"<br/>blending: "+
this.blending+"<br/>)"}};THREE.ParticleCircleMaterial=function(a){this.color=new THREE.Color(16711680);this.opacity=1;this.blending=THREE.NormalBlending;if(a){a.color!==undefined&&this.color.setHex(a.color);if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}this.toString=function(){return"THREE.ParticleCircleMaterial (<br/>color: "+this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>)"}};
THREE.ParticleDOMMaterial=function(a){this.domElement=a;this.toString=function(){return"THREE.ParticleDOMMaterial ( domElement: "+this.domElement+" )"}};THREE.Texture=function(a,c,f,h){this.image=a;this.mapping=c!==undefined?c:THREE.UVMapping;this.wrap_s=f!==undefined?f:THREE.ClampToEdge;this.wrap_t=h!==undefined?h:THREE.ClampToEdge;this.toString=function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>wrap_s: "+this.wrap_s+"<br/>wrap_t: "+this.wrap_t+"<br/>)"}};THREE.UVMapping=0;
THREE.ReflectionMap=1;THREE.RefractionMap=2;THREE.Multiply=0;THREE.Mix=1;THREE.Repeat=0;THREE.ClampToEdge=1;THREE.MirroredRepeat=2;THREE.TextureCube=function(a,c){this.image=a;this.mapping=c?c:THREE.ReflectionMap;this.toString=function(){return"THREE.TextureCube (<br/>image: "+this.image+"<br/>mapping: "+this.mapping+"<br/>)"}};
THREE.Scene=function(){this.objects=[];this.lights=[];this.addObject=function(a){this.objects.push(a)};this.removeObject=function(a){a=this.objects.indexOf(a);a!==-1&&this.objects.splice(a,1)};this.addLight=function(a){this.lights.push(a)};this.removeLight=function(a){a=this.lights.indexOf(a);a!==-1&&this.lights.splice(a,1)};this.toString=function(){return"THREE.Scene ( "+this.objects+" )"}};
THREE.Projector=function(){function a(r,q){var l=0,R=1,G=r.z+r.w,U=q.z+q.w,$=-r.z+r.w,t=-q.z+q.w;if(G>=0&&U>=0&&$>=0&&t>=0)return true;else if(G<0&&U<0||$<0&&t<0)return false;else{if(G<0)l=Math.max(l,G/(G-U));else if(U<0)R=Math.min(R,G/(G-U));if($<0)l=Math.max(l,$/($-t));else if(t<0)R=Math.min(R,$/($-t));if(R<l)return false;else{r.lerpSelf(q,l);q.lerpSelf(r,1-R);return true}}}var c=null,f,h,b=[],d,p,s=[],o,e,g=[],k,i,n=[],j=new THREE.Vector4,A=new THREE.Matrix4,C=new THREE.Matrix4,v=new THREE.Vector4,
L=new THREE.Vector4;this.projectScene=function(r,q){var l,R,G,U,$,t,E,D,u,N,pa,Z,S,B;c=[];i=e=p=h=0;q.autoUpdateMatrix&&q.updateMatrix();A.multiply(q.projectionMatrix,q.matrix);$=r.objects;l=0;for(R=$.length;l<R;l++){t=$[l];E=t.matrix;t.autoUpdateMatrix&&t.updateMatrix();if(t instanceof THREE.Mesh){C.multiply(A,E);D=t.geometry.vertices;G=0;for(U=D.length;G<U;G++){u=D[G];N=u.positionScreen;N.copy(u.position);C.transform(N);N.multiplyScalar(1/N.w);u.__visible=N.z>0&&N.z<1}pa=t.geometry.faces;G=0;for(U=
pa.length;G<U;G++){Z=pa[G];if(Z instanceof THREE.Face3){u=D[Z.a];N=D[Z.b];S=D[Z.c];if(u.__visible&&N.__visible&&S.__visible)if(t.doubleSided||t.flipSided!=(S.positionScreen.x-u.positionScreen.x)*(N.positionScreen.y-u.positionScreen.y)-(S.positionScreen.y-u.positionScreen.y)*(N.positionScreen.x-u.positionScreen.x)<0){f=b[h]=b[h]||new THREE.RenderableFace3;f.v1.positionScreen.copy(u.positionScreen);f.v2.positionScreen.copy(N.positionScreen);f.v3.positionScreen.copy(S.positionScreen);f.normalWorld.copy(Z.normal);
t.matrixRotation.transform(f.normalWorld);f.centroidWorld.copy(Z.centroid);E.transform(f.centroidWorld);f.centroidScreen.copy(f.centroidWorld);A.transform(f.centroidScreen);f.z=f.centroidScreen.z;f.meshMaterial=t.material;f.faceMaterial=Z.material;f.overdraw=t.overdraw;f.uvs=t.geometry.uvs[G];f.color=Z.color;c.push(f);h++}}else if(Z instanceof THREE.Face4){u=D[Z.a];N=D[Z.b];S=D[Z.c];B=D[Z.d];if(u.__visible&&N.__visible&&S.__visible&&B.__visible)if(t.doubleSided||t.flipSided!=((B.positionScreen.x-
u.positionScreen.x)*(N.positionScreen.y-u.positionScreen.y)-(B.positionScreen.y-u.positionScreen.y)*(N.positionScreen.x-u.positionScreen.x)<0||(N.positionScreen.x-S.positionScreen.x)*(B.positionScreen.y-S.positionScreen.y)-(N.positionScreen.y-S.positionScreen.y)*(B.positionScreen.x-S.positionScreen.x)<0)){d=s[p]=s[p]||new THREE.RenderableFace4;d.v1.positionScreen.copy(u.positionScreen);d.v2.positionScreen.copy(N.positionScreen);d.v3.positionScreen.copy(S.positionScreen);d.v4.positionScreen.copy(B.positionScreen);
d.normalWorld.copy(Z.normal);t.matrixRotation.transform(d.normalWorld);d.centroidWorld.copy(Z.centroid);E.transform(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);A.transform(d.centroidScreen);d.z=d.centroidScreen.z;d.meshMaterial=t.material;d.faceMaterial=Z.material;d.overdraw=t.overdraw;d.uvs=t.geometry.uvs[G];d.color=Z.color;c.push(d);p++}}}}else if(t instanceof THREE.Line){C.multiply(A,E);D=t.geometry.vertices;u=D[0];u.positionScreen.copy(u.position);C.transform(u.positionScreen);G=1;
for(U=D.length;G<U;G++){u=D[G];u.positionScreen.copy(u.position);C.transform(u.positionScreen);N=D[G-1];v.copy(u.positionScreen);L.copy(N.positionScreen);if(a(v,L)){v.multiplyScalar(1/v.w);L.multiplyScalar(1/L.w);o=g[e]=g[e]||new THREE.RenderableLine;o.v1.positionScreen.copy(v);o.v2.positionScreen.copy(L);o.z=Math.max(v.z,L.z);o.material=t.material;c.push(o);e++}}}else if(t instanceof THREE.Particle){j.set(t.position.x,t.position.y,t.position.z,1);A.transform(j);j.z/=j.w;if(j.z>0&&j.z<1){k=n[i]=n[i]||
new THREE.RenderableParticle;k.x=j.x/j.w;k.y=j.y/j.w;k.z=j.z;k.rotation=t.rotation.z;k.scale.x=t.scale.x*Math.abs(k.x-(j.x+q.projectionMatrix.n11)/(j.w+q.projectionMatrix.n14));k.scale.y=t.scale.y*Math.abs(k.y-(j.y+q.projectionMatrix.n22)/(j.w+q.projectionMatrix.n24));k.material=t.material;c.push(k);i++}}}c.sort(function(X,O){return O.z-X.z});return c};this.unprojectVector=function(r,q){var l=new THREE.Matrix4;l.multiply(THREE.Matrix4.makeInvert(q.matrix),THREE.Matrix4.makeInvert(q.projectionMatrix));
l.transform(r);return r}};
THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,c=new THREE.Projector,f,h,b,d;this.domElement=document.createElement("div");this.setSize=function(p,s){f=p;h=s;b=f/2;d=h/2};this.render=function(p,s){var o,e,g,k,i,n,j,A;a=c.projectScene(p,s);o=0;for(e=a.length;o<e;o++){i=a[o];if(i instanceof THREE.RenderableParticle){j=i.x*b+b;A=i.y*d+d;g=0;for(k=i.material.length;g<k;g++){n=i.material[g];if(n instanceof THREE.ParticleDOMMaterial){n=n.domElement;n.style.left=j+"px";n.style.top=A+"px"}}}}}};
THREE.CanvasRenderer=function(){function a(x,M,H){var I,m,F;lights=x.lights;x=0;for(I=lights.length;x<I;x++){m=lights[x];F=m.color;if(m instanceof THREE.DirectionalLight){m=M.normalWorld.dot(m.position)*m.intensity;if(m>0){H.r+=F.r*m;H.g+=F.g*m;H.b+=F.b*m}}else if(m instanceof THREE.PointLight){Ka.sub(m.position,M.centroidWorld);Ka.normalize();m=M.normalWorld.dot(Ka)*m.intensity;if(m>0){H.r+=F.r*m;H.g+=F.g*m;H.b+=F.b*m}}}}function c(x,M,H,I,m,F){if(m.opacity!=0){p(m.opacity);s(m.blending);S=x.positionScreen.x;
B=x.positionScreen.y;X=M.positionScreen.x;O=M.positionScreen.y;T=H.positionScreen.x;z=H.positionScreen.y;if(m.map){ga=m.map.image;sa=ga.width-1;ta=ga.height-1;ea.u=I.uvs[0].u*sa;ea.v=I.uvs[0].v*ta;aa.u=I.uvs[1].u*sa;aa.v=I.uvs[1].v*ta;fa.u=I.uvs[2].u*sa;fa.v=I.uvs[2].v*ta;d(ga,S,B,X,O,T,z,ea.u,ea.v,aa.u,aa.v,fa.u,fa.v)}else if(m instanceof THREE.MeshBasicMaterial)h(S,B,X,O,T,z,m.color,m.wireframe,m.wireframe_linewidth);else if(m instanceof THREE.MeshLambertMaterial){if(Ha){ca.r=ha.r;ca.g=ha.g;ca.b=
ha.b;a(F,I,ca);V.r=m.color.r*ca.r;V.g=m.color.g*ca.g;V.b=m.color.b*ca.b;V.updateStyleString()}else V.__styleString=m.color.__styleString;h(S,B,X,O,T,z,V,m.wireframe,m.wireframe_linewidth)}else if(m instanceof THREE.MeshDepthMaterial){ua=m.__2near;va=m.__farPlusNear;wa=m.__farMinusNear;xa=~~((1-ua/(va-x.positionScreen.z*wa))*255);ya=~~((1-ua/(va-M.positionScreen.z*wa))*255);qa=~~((1-ua/(va-H.positionScreen.z*wa))*255);ga=k([xa,xa,xa],[ya,ya,ya],[qa,qa,qa],[qa,qa,qa]);ea.u=0;ea.v=0;aa.u=na;aa.v=0;fa.u=
0;fa.v=na;d(ga,S,B,X,O,T,z,ea.u,ea.v,aa.u,aa.v,fa.u,fa.v)}else if(m instanceof THREE.MeshNormalMaterial){V.r=i(I.normalWorld.x);V.g=i(I.normalWorld.y);V.b=i(I.normalWorld.z);V.updateStyleString();h(S,B,X,O,T,z,V,m.wireframe,m.wireframe_linewidth)}}}function f(x,M,H,I,m,F,W,w,Y){if(w.opacity!=0){p(w.opacity);s(w.blending);S=x.positionScreen.x;B=x.positionScreen.y;X=M.positionScreen.x;O=M.positionScreen.y;T=H.positionScreen.x;z=H.positionScreen.y;y=I.positionScreen.x;Q=I.positionScreen.y;ia=m.positionScreen.x;
K=m.positionScreen.y;P=F.positionScreen.x;ja=F.positionScreen.y;if(w.map){ga=w.map.image;sa=ga.width-1;ta=ga.height-1;ea.copy(W.uvs[0]);aa.copy(W.uvs[1]);fa.copy(W.uvs[2]);ka.copy(W.uvs[3]);ea.u*=sa;ea.v*=ta;aa.u*=sa;aa.v*=ta;fa.u*=sa;fa.v*=ta;ka.u*=sa;ka.v*=ta;d(ga,S,B,X,O,y,Q,ea.u,ea.v,aa.u,aa.v,ka.u,ka.v);d(ga,ia,K,T,z,P,ja,aa.u,aa.v,fa.u,fa.v,ka.u,ka.v)}else if(w instanceof THREE.MeshBasicMaterial)b(S,B,X,O,T,z,y,Q,w.color,w.wireframe,w.wireframe_linewidth);else if(w instanceof THREE.MeshLambertMaterial){if(Ha){ca.r=
ha.r;ca.g=ha.g;ca.b=ha.b;a(Y,W,ca);V.r=w.color.r*ca.r;V.g=w.color.g*ca.g;V.b=w.color.b*ca.b;V.updateStyleString()}else V.__styleString=w.color.__styleString;b(S,B,X,O,T,z,y,Q,V,w.wireframe,w.wireframe_linewidth)}else if(w instanceof THREE.MeshDepthMaterial){ua=w.__2near;va=w.__farPlusNear;wa=w.__farMinusNear;xa=~~((1-ua/(va-x.positionScreen.z*wa))*255);ya=~~((1-ua/(va-M.positionScreen.z*wa))*255);qa=~~((1-ua/(va-H.positionScreen.z*wa))*255);Ia=~~((1-ua/(va-I.positionScreen.z*wa))*255);ga=k([xa,xa,
xa],[ya,ya,ya],[Ia,Ia,Ia],[qa,qa,qa]);ea.u=0;ea.v=0;aa.u=na;aa.v=0;fa.u=na;fa.v=na;ka.u=0;ka.v=na;d(ga,S,B,X,O,y,Q,ea.u,ea.v,aa.u,aa.v,ka.u,ka.v);d(ga,ia,K,T,z,P,ja,aa.u,aa.v,fa.u,fa.v,ka.u,ka.v)}else if(w instanceof THREE.MeshNormalMaterial){V.r=i(W.normalWorld.x);V.g=i(W.normalWorld.y);V.b=i(W.normalWorld.z);V.updateStyleString();b(S,B,X,O,T,z,y,Q,V,w.wireframe,w.wireframe_linewidth)}}}function h(x,M,H,I,m,F,W,w,Y){l.beginPath();l.moveTo(x,M);l.lineTo(H,I);l.lineTo(m,F);l.lineTo(x,M);l.closePath();
if(w){o(Y);e(W.__styleString);l.stroke();ba.inflate(Y*2)}else{g(W.__styleString);l.fill()}}function b(x,M,H,I,m,F,W,w,Y,J,da){l.beginPath();l.moveTo(x,M);l.lineTo(H,I);l.lineTo(m,F);l.lineTo(W,w);l.lineTo(x,M);l.closePath();if(J){o(da);e(Y.__styleString);l.stroke();ba.inflate(da*2)}else{g(Y.__styleString);l.fill()}}function d(x,M,H,I,m,F,W,w,Y,J,da,oa,za){l.beginPath();l.moveTo(M,H);l.lineTo(I,m);l.lineTo(F,W);l.closePath();I-=M;m-=H;F-=M;W-=H;J-=w;da-=Y;oa-=w;za-=Y;var Aa=1/(J*za-oa*da),Ba=(za*I-
da*F)*Aa;da=(za*m-da*W)*Aa;I=(J*F-oa*I)*Aa;m=(J*W-oa*m)*Aa;M=M-Ba*w-I*Y;H=H-da*w-m*Y;l.save();l.transform(Ba,da,I,m,M,H);l.clip();l.drawImage(x,0,0);l.restore()}function p(x){if(R!=x)l.globalAlpha=R=x}function s(x){if(G!=x){switch(x){case THREE.NormalBlending:l.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:l.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:l.globalCompositeOperation="darker"}G=x}}function o(x){if(t!=x)l.lineWidth=t=x}function e(x){if(U!=
x)l.strokeStyle=U=x}function g(x){if($!=x)l.fillStyle=$=x}function k(x,M,H,I){la[0]=x[0];la[1]=x[1];la[2]=x[2];la[4]=M[0];la[5]=M[1];la[6]=M[2];la[8]=H[0];la[9]=H[1];la[10]=H[2];la[12]=I[0];la[13]=I[1];la[14]=I[2];Ea.putImageData(La,0,0);Ja.drawImage(Fa,0,0);return Ga}function i(x){return x<0?Math.min((1+x)*0.5,0.5):0.5+Math.min(x*0.5,0.5)}function n(x,M){var H=M.x-x.x,I=M.y-x.y,m=1/Math.sqrt(H*H+I*I);H*=m;I*=m;M.x+=H;M.y+=I;x.x-=H;x.y-=I}var j=null,A=new THREE.Projector,C=document.createElement("canvas"),
v,L,r,q,l=C.getContext("2d"),R=1,G=0,U=null,$=null,t=1,E,D,u,N,pa=new THREE.Vertex,Z=new THREE.Vertex,S,B,X,O,T,z,y,Q,ia,K,P,ja,xa,ya,qa,Ia,ua,va,wa,ga,sa,ta,ra=new THREE.Rectangle,ma=new THREE.Rectangle,ba=new THREE.Rectangle,Ha=false,V=new THREE.Color(16777215),ca=new THREE.Color(16777215),ha=new THREE.Color(0),Ca=new THREE.Color(0),Da=new THREE.Color(0),Oa=Math.PI*2,Ka=new THREE.Vector3,ea=new THREE.UV,aa=new THREE.UV,fa=new THREE.UV,ka=new THREE.UV,Fa,Ea,La,la,Ga,Ja,na=16;Fa=document.createElement("canvas");
Fa.width=Fa.height=2;Ea=Fa.getContext("2d");Ea.fillStyle="rgba(0,0,0,1)";Ea.fillRect(0,0,2,2);La=Ea.getImageData(0,0,2,2);la=La.data;Ga=document.createElement("canvas");Ga.width=Ga.height=na;Ja=Ga.getContext("2d");Ja.translate(-na/2,-na/2);Ja.scale(na,na);na--;this.domElement=C;this.autoClear=true;this.setSize=function(x,M){v=x;L=M;r=v/2;q=L/2;C.width=v;C.height=L;l.lineJoin="round";l.lineCap="round";ra.set(-r,-q,r,q)};this.clear=function(){if(!ma.isEmpty()){ma.inflate(1);ma.minSelf(ra);l.setTransform(1,
0,0,-1,r,q);l.clearRect(ma.getX(),ma.getY(),ma.getWidth(),ma.getHeight());ma.empty()}};this.render=function(x,M){var H,I,m,F,W,w,Y,J;this.autoClear&&this.clear();j=A.projectScene(x,M);l.setTransform(1,0,0,-1,r,q);l.fillStyle="rgba(0, 255, 255, 0.5)";l.fillRect(ra.getX(),ra.getY(),ra.getWidth(),ra.getHeight());if(Ha=x.lights.length>0){W=x.lights;ha.setRGB(0,0,0);Ca.setRGB(0,0,0);Da.setRGB(0,0,0);H=0;for(I=W.length;H<I;H++){m=W[H];F=m.color;if(m instanceof THREE.AmbientLight){ha.r+=F.r;ha.g+=F.g;ha.b+=
F.b}else if(m instanceof THREE.DirectionalLight){Ca.r+=F.r;Ca.g+=F.g;Ca.b+=F.b}else if(m instanceof THREE.PointLight){Da.r+=F.r;Da.g+=F.g;Da.b+=F.b}}}H=0;for(I=j.length;H<I;H++){m=j[H];ba.empty();if(m instanceof THREE.RenderableParticle){E=m;E.x*=r;E.y*=q;F=0;for(W=m.material.length;F<W;F++)if(J=m.material[F])a:{w=E;Y=m;J=J;if(J.opacity!=0){p(J.opacity);s(J.blending);var da=void 0,oa=void 0,za=void 0,Aa=void 0,Ba=void 0,Ma=void 0,Na=void 0;if(J instanceof THREE.ParticleBasicMaterial){if(J.map){Ba=
J.map;Ma=Ba.width>>1;Na=Ba.height>>1;za=Y.scale.x*r;Aa=Y.scale.y*q;da=za*Ma;oa=Aa*Na;ba.set(w.x-da,w.y-oa,w.x+da,w.y+oa);if(!ra.instersects(ba))break a;l.save();l.translate(w.x,w.y);l.rotate(-Y.rotation);l.scale(za,-Aa);l.translate(-Ma,-Na);l.drawImage(Ba,0,0);l.restore()}l.beginPath();l.moveTo(w.x-10,w.y);l.lineTo(w.x+10,w.y);l.moveTo(w.x,w.y-10);l.lineTo(w.x,w.y+10);l.closePath();l.strokeStyle="rgb(255,255,0)";l.stroke()}else if(J instanceof THREE.ParticleCircleMaterial){if(Ha){ca.r=ha.r+Ca.r+Da.r;
ca.g=ha.g+Ca.g+Da.g;ca.b=ha.b+Ca.b+Da.b;V.r=J.color.r*ca.r;V.g=J.color.g*ca.g;V.b=J.color.b*ca.b;V.updateStyleString()}else V.__styleString=J.color.__styleString;da=Y.scale.x*r;oa=Y.scale.y*q;ba.set(w.x-da,w.y-oa,w.x+da,w.y+oa);if(ra.instersects(ba)){g(V.__styleString);l.save();l.translate(w.x,w.y);l.rotate(-Y.rotation);l.scale(da,oa);l.beginPath();l.arc(0,0,1,0,Oa,true);l.closePath();l.fill();l.restore()}}}}}else if(m instanceof THREE.RenderableLine){E=m.v1;D=m.v2;E.positionScreen.x*=r;E.positionScreen.y*=
q;D.positionScreen.x*=r;D.positionScreen.y*=q;ba.addPoint(E.positionScreen.x,E.positionScreen.y);ba.addPoint(D.positionScreen.x,D.positionScreen.y);if(!ra.instersects(ba))continue;F=0;for(W=m.material.length;F<W;)if(J=m.material[F++]){w=E;Y=D;J=J;if(J.opacity!=0){p(J.opacity);s(J.blending);l.beginPath();l.moveTo(w.positionScreen.x,w.positionScreen.y);l.lineTo(Y.positionScreen.x,Y.positionScreen.y);l.closePath();if(J instanceof THREE.LineBasicMaterial){V.__styleString=J.color.__styleString;o(J.linewidth);
e(V.__styleString);l.stroke();ba.inflate(J.linewidth*2)}}}}else if(m instanceof THREE.RenderableFace3){E=m.v1;D=m.v2;u=m.v3;E.positionScreen.x*=r;E.positionScreen.y*=q;D.positionScreen.x*=r;D.positionScreen.y*=q;u.positionScreen.x*=r;u.positionScreen.y*=q;if(m.overdraw){n(E.positionScreen,D.positionScreen);n(D.positionScreen,u.positionScreen);n(u.positionScreen,E.positionScreen)}ba.addPoint(E.positionScreen.x,E.positionScreen.y);ba.addPoint(D.positionScreen.x,D.positionScreen.y);ba.addPoint(u.positionScreen.x,
u.positionScreen.y);if(!ra.instersects(ba))continue;F=0;for(W=m.meshMaterial.length;F<W;){J=m.meshMaterial[F++];if(J instanceof THREE.MeshFaceMaterial){w=0;for(Y=m.faceMaterial.length;w<Y;)(J=m.faceMaterial[w++])&&c(E,D,u,m,J,x)}else J&&c(E,D,u,m,J,x)}}else if(m instanceof THREE.RenderableFace4){E=m.v1;D=m.v2;u=m.v3;N=m.v4;E.positionScreen.x*=r;E.positionScreen.y*=q;D.positionScreen.x*=r;D.positionScreen.y*=q;u.positionScreen.x*=r;u.positionScreen.y*=q;N.positionScreen.x*=r;N.positionScreen.y*=q;
pa.positionScreen.copy(D.positionScreen);Z.positionScreen.copy(N.positionScreen);if(m.overdraw){n(E.positionScreen,D.positionScreen);n(D.positionScreen,N.positionScreen);n(N.positionScreen,E.positionScreen)}if(m.overdraw){n(u.positionScreen,pa.positionScreen);n(u.positionScreen,Z.positionScreen)}ba.addPoint(E.positionScreen.x,E.positionScreen.y);ba.addPoint(D.positionScreen.x,D.positionScreen.y);ba.addPoint(u.positionScreen.x,u.positionScreen.y);ba.addPoint(N.positionScreen.x,N.positionScreen.y);
if(!ra.instersects(ba))continue;F=0;for(W=m.meshMaterial.length;F<W;){J=m.meshMaterial[F++];if(J instanceof THREE.MeshFaceMaterial){w=0;for(Y=m.faceMaterial.length;w<Y;)(J=m.faceMaterial[w++])&&f(E,D,u,N,pa,Z,m,J,x)}else J&&f(E,D,u,N,pa,Z,m,J,x)}}ma.addRectangle(ba)}l.lineWidth=1;l.strokeStyle="rgba( 255, 0, 0, 0.5 )";l.strokeRect(ma.getX(),ma.getY(),ma.getWidth(),ma.getHeight());l.setTransform(1,0,0,1,0,0)}};
THREE.SVGRenderer=function(){function a(B,X,O){var T,z,y,Q;T=0;for(z=B.lights.length;T<z;T++){y=B.lights[T];if(y instanceof THREE.DirectionalLight){Q=X.normalWorld.dot(y.position)*y.intensity;if(Q>0){O.r+=y.color.r*Q;O.g+=y.color.g*Q;O.b+=y.color.b*Q}}else if(y instanceof THREE.PointLight){$.sub(y.position,X.centroidWorld);$.normalize();Q=X.normalWorld.dot($)*y.intensity;if(Q>0){O.r+=y.color.r*Q;O.g+=y.color.g*Q;O.b+=y.color.b*Q}}}}function c(B,X,O,T,z,y){u=h(N++);u.setAttribute("d","M "+B.positionScreen.x+
" "+B.positionScreen.y+" L "+X.positionScreen.x+" "+X.positionScreen.y+" L "+O.positionScreen.x+","+O.positionScreen.y+"z");if(z instanceof THREE.MeshBasicMaterial)r.__styleString=z.color.__styleString;else if(z instanceof THREE.MeshLambertMaterial)if(L){q.r=l.r;q.g=l.g;q.b=l.b;a(y,T,q);r.r=z.color.r*q.r;r.g=z.color.g*q.g;r.b=z.color.b*q.b;r.updateStyleString()}else r.__styleString=z.color.__styleString;else if(z instanceof THREE.MeshDepthMaterial){U=1-z.__2near/(z.__farPlusNear-T.z*z.__farMinusNear);
r.setRGB(U,U,U)}else z instanceof THREE.MeshNormalMaterial&&r.setRGB(b(T.normalWorld.x),b(T.normalWorld.y),b(T.normalWorld.z));z.wireframe?u.setAttribute("style","fill: none; stroke: "+r.__styleString+"; stroke-width: "+z.wireframe_linewidth+"; stroke-opacity: "+z.opacity+"; stroke-linecap: "+z.wireframe_linecap+"; stroke-linejoin: "+z.wireframe_linejoin):u.setAttribute("style","fill: "+r.__styleString+"; fill-opacity: "+z.opacity);s.appendChild(u)}function f(B,X,O,T,z,y,Q){u=h(N++);u.setAttribute("d",
"M "+B.positionScreen.x+" "+B.positionScreen.y+" L "+X.positionScreen.x+" "+X.positionScreen.y+" L "+O.positionScreen.x+","+O.positionScreen.y+" L "+T.positionScreen.x+","+T.positionScreen.y+"z");if(y instanceof THREE.MeshBasicMaterial)r.__styleString=y.color.__styleString;else if(y instanceof THREE.MeshLambertMaterial)if(L){q.r=l.r;q.g=l.g;q.b=l.b;a(Q,z,q);r.r=y.color.r*q.r;r.g=y.color.g*q.g;r.b=y.color.b*q.b;r.updateStyleString()}else r.__styleString=y.color.__styleString;else if(y instanceof THREE.MeshDepthMaterial){U=
1-y.__2near/(y.__farPlusNear-z.z*y.__farMinusNear);r.setRGB(U,U,U)}else y instanceof THREE.MeshNormalMaterial&&r.setRGB(b(z.normalWorld.x),b(z.normalWorld.y),b(z.normalWorld.z));y.wireframe?u.setAttribute("style","fill: none; stroke: "+r.__styleString+"; stroke-width: "+y.wireframe_linewidth+"; stroke-opacity: "+y.opacity+"; stroke-linecap: "+y.wireframe_linecap+"; stroke-linejoin: "+y.wireframe_linejoin):u.setAttribute("style","fill: "+r.__styleString+"; fill-opacity: "+y.opacity);s.appendChild(u)}
function h(B){if(t[B]==null){t[B]=document.createElementNS("http://www.w3.org/2000/svg","path");S==0&&t[B].setAttribute("shape-rendering","crispEdges");return t[B]}return t[B]}function b(B){return B<0?Math.min((1+B)*0.5,0.5):0.5+Math.min(B*0.5,0.5)}var d=null,p=new THREE.Projector,s=document.createElementNS("http://www.w3.org/2000/svg","svg"),o,e,g,k,i,n,j,A,C=new THREE.Rectangle,v=new THREE.Rectangle,L=false,r=new THREE.Color(16777215),q=new THREE.Color(16777215),l=new THREE.Color(0),R=new THREE.Color(0),
G=new THREE.Color(0),U,$=new THREE.Vector3,t=[],E=[],D=[],u,N,pa,Z,S=1;this.domElement=s;this.autoClear=true;this.setQuality=function(B){switch(B){case "high":S=1;break;case "low":S=0}};this.setSize=function(B,X){o=B;e=X;g=o/2;k=e/2;s.setAttribute("viewBox",-g+" "+-k+" "+o+" "+e);s.setAttribute("width",o);s.setAttribute("height",e);C.set(-g,-k,g,k)};this.clear=function(){for(;s.childNodes.length>0;)s.removeChild(s.childNodes[0])};this.render=function(B,X){var O,T,z,y,Q,ia,K,P;this.autoClear&&this.clear();
d=p.projectScene(B,X);Z=pa=N=0;if(L=B.lights.length>0){K=B.lights;l.setRGB(0,0,0);R.setRGB(0,0,0);G.setRGB(0,0,0);O=0;for(T=K.length;O<T;O++){z=K[O];y=z.color;if(z instanceof THREE.AmbientLight){l.r+=y.r;l.g+=y.g;l.b+=y.b}else if(z instanceof THREE.DirectionalLight){R.r+=y.r;R.g+=y.g;R.b+=y.b}else if(z instanceof THREE.PointLight){G.r+=y.r;G.g+=y.g;G.b+=y.b}}}O=0;for(T=d.length;O<T;O++){K=d[O];v.empty();if(K instanceof THREE.RenderableParticle){i=K;i.x*=g;i.y*=-k;z=0;for(y=K.material.length;z<y;z++)if(P=
K.material[z]){Q=i;ia=K;P=P;var ja=pa++;if(E[ja]==null){E[ja]=document.createElementNS("http://www.w3.org/2000/svg","circle");S==0&&E[ja].setAttribute("shape-rendering","crispEdges")}u=E[ja];u.setAttribute("cx",Q.x);u.setAttribute("cy",Q.y);u.setAttribute("r",ia.scale.x*g);if(P instanceof THREE.ParticleCircleMaterial){if(L){q.r=l.r+R.r+G.r;q.g=l.g+R.g+G.g;q.b=l.b+R.b+G.b;r.r=P.color.r*q.r;r.g=P.color.g*q.g;r.b=P.color.b*q.b;r.updateStyleString()}else r=P.color;u.setAttribute("style","fill: "+r.__styleString)}s.appendChild(u)}}else if(K instanceof
THREE.RenderableLine){i=K.v1;n=K.v2;i.positionScreen.x*=g;i.positionScreen.y*=-k;n.positionScreen.x*=g;n.positionScreen.y*=-k;v.addPoint(i.positionScreen.x,i.positionScreen.y);v.addPoint(n.positionScreen.x,n.positionScreen.y);if(C.instersects(v)){z=0;for(y=K.material.length;z<y;)if(P=K.material[z++]){Q=i;ia=n;P=P;ja=Z++;if(D[ja]==null){D[ja]=document.createElementNS("http://www.w3.org/2000/svg","line");S==0&&D[ja].setAttribute("shape-rendering","crispEdges")}u=D[ja];u.setAttribute("x1",Q.positionScreen.x);
u.setAttribute("y1",Q.positionScreen.y);u.setAttribute("x2",ia.positionScreen.x);u.setAttribute("y2",ia.positionScreen.y);if(P instanceof THREE.LineBasicMaterial){r.__styleString=P.color.__styleString;u.setAttribute("style","fill: none; stroke: "+r.__styleString+"; stroke-width: "+P.linewidth+"; stroke-opacity: "+P.opacity+"; stroke-linecap: "+P.linecap+"; stroke-linejoin: "+P.linejoin);s.appendChild(u)}}}}else if(K instanceof THREE.RenderableFace3){i=K.v1;n=K.v2;j=K.v3;i.positionScreen.x*=g;i.positionScreen.y*=
-k;n.positionScreen.x*=g;n.positionScreen.y*=-k;j.positionScreen.x*=g;j.positionScreen.y*=-k;v.addPoint(i.positionScreen.x,i.positionScreen.y);v.addPoint(n.positionScreen.x,n.positionScreen.y);v.addPoint(j.positionScreen.x,j.positionScreen.y);if(C.instersects(v)){z=0;for(y=K.meshMaterial.length;z<y;){P=K.meshMaterial[z++];if(P instanceof THREE.MeshFaceMaterial){Q=0;for(ia=K.faceMaterial.length;Q<ia;)(P=K.faceMaterial[Q++])&&c(i,n,j,K,P,B)}else P&&c(i,n,j,K,P,B)}}}else if(K instanceof THREE.RenderableFace4){i=
K.v1;n=K.v2;j=K.v3;A=K.v4;i.positionScreen.x*=g;i.positionScreen.y*=-k;n.positionScreen.x*=g;n.positionScreen.y*=-k;j.positionScreen.x*=g;j.positionScreen.y*=-k;A.positionScreen.x*=g;A.positionScreen.y*=-k;v.addPoint(i.positionScreen.x,i.positionScreen.y);v.addPoint(n.positionScreen.x,n.positionScreen.y);v.addPoint(j.positionScreen.x,j.positionScreen.y);v.addPoint(A.positionScreen.x,A.positionScreen.y);if(C.instersects(v)){z=0;for(y=K.meshMaterial.length;z<y;){P=K.meshMaterial[z++];if(P instanceof
THREE.MeshFaceMaterial){Q=0;for(ia=K.faceMaterial.length;Q<ia;)(P=K.faceMaterial[Q++])&&f(i,n,j,A,K,P,B)}else P&&f(i,n,j,A,K,P,B)}}}}}};
THREE.WebGLRenderer=function(a){function c(e,g){var k;if(e=="fragment")k=b.createShader(b.FRAGMENT_SHADER);else if(e=="vertex")k=b.createShader(b.VERTEX_SHADER);b.shaderSource(k,g);b.compileShader(k);if(!b.getShaderParameter(k,b.COMPILE_STATUS)){alert(b.getShaderInfoLog(k));return null}return k}function f(e){switch(e){case THREE.Repeat:return b.REPEAT;case THREE.ClampToEdge:return b.CLAMP_TO_EDGE;case THREE.MirroredRepeat:return b.MIRRORED_REPEAT}return 0}var h=document.createElement("canvas"),b,
d,p=new THREE.Matrix4,s;a=function(e,g){if(e){var k,i,n,j=pointLights=maxDirLights=maxPointLights=0;k=0;for(i=e.lights.length;k<i;k++){n=e.lights[k];n instanceof THREE.DirectionalLight&&j++;n instanceof THREE.PointLight&&pointLights++}if(pointLights+j<=g){maxDirLights=j;maxPointLights=pointLights}else{maxDirLights=Math.ceil(g*j/(pointLights+j));maxPointLights=g-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:g-1}}(a,4);this.domElement=h;this.autoClear=
true;try{b=h.getContext("experimental-webgl",{antialias:true})}catch(o){}if(!b){alert("WebGL not supported");throw"cannot create webgl context";}b.clearColor(0,0,0,1);b.clearDepth(1);b.enable(b.DEPTH_TEST);b.depthFunc(b.LEQUAL);b.frontFace(b.CCW);b.cullFace(b.BACK);b.enable(b.CULL_FACE);b.enable(b.BLEND);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA);b.clearColor(0,0,0,0);(function(e,g){d=b.createProgram();b.attachShader(d,c("fragment",["#ifdef GL_ES\nprecision highp float;\n#endif",e?"#define MAX_DIR_LIGHTS "+
e:"",g?"#define MAX_POINT_LIGHTS "+g:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\nuniform float m2Near;\nuniform float mFarPlusNear;\nuniform float mFarMinusNear;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",e?
"uniform mat4 viewMatrix;":"",e?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"","varying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",g?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform vec3 cameraPosition;\nvoid main() {\nvec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nvec4 cubeColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nif ( enableMap ) {\nmapColor = texture2D( tMap, vUv );\n}\nif ( enableCubeMap ) {\ncubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\n}\nif ( material == 5 ) { \nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( -wPos.x, wPos.yz ) );\n} else if ( material == 4 ) { \ngl_FragColor = vec4( 0.5*normalize( vNormal ) + vec3(0.5, 0.5, 0.5), mOpacity );\n} else if ( material == 3 ) { \nfloat w = 0.5;\ngl_FragColor = vec4( w, w, w, mOpacity );\n} else if ( material == 2 ) { \nvec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );",
g?"vec4 pointDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",g?"vec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",g?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",g?"vec3 pointVector = normalize( vPointLightVector[ i ] );":"",g?"vec3 pointHalfVector = normalize( vPointLightVector[ i ] + vViewPosition );":"",g?"float pointDotNormalHalf = dot( normal, pointHalfVector );":"",g?"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );":"",g?"float pointSpecularWeight = 0.0;":"",g?"if ( pointDotNormalHalf >= 0.0 )":
"",g?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",g?"pointDiffuse  += mColor * pointDiffuseWeight;":"",g?"pointSpecular += mSpecular * pointSpecularWeight;":"",g?"}":"",e?"vec4 dirDiffuse  = vec4( 0.0, 0.0, 0.0, 0.0 );":"",e?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",e?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",e?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",e?"vec3 dirVector = normalize( lDirection.xyz );":"",e?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
"",e?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",e?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",e?"float dirSpecularWeight = 0.0;":"",e?"if ( dirDotNormalHalf >= 0.0 )":"",e?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",e?"dirDiffuse  += mColor * dirDiffuseWeight;":"",e?"dirSpecular += mSpecular * dirSpecularWeight;":"",e?"}":"","vec4 totalLight = mAmbient;",e?"totalLight += dirDiffuse + dirSpecular;":"",g?"totalLight += pointDiffuse + pointSpecular;":
"","if ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mapColor.rgb * totalLight.xyz * vLightWeighting, cubeColor.rgb, mReflectivity ), mapColor.a );\n} else {\ngl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );\n}\n} else if ( material == 1 ) {\nif ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mColor.rgb * mapColor.rgb * vLightWeighting, cubeColor.rgb, mReflectivity ), mColor.a * mapColor.a );\n} else {\ngl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );\n}\n} else {\nif ( mixEnvMap ) {\ngl_FragColor = mix( mColor * mapColor, cubeColor, mReflectivity );\n} else {\ngl_FragColor = mColor * mapColor * cubeColor;\n}\n}\n}"].join("\n")));
b.attachShader(d,c("vertex",[e?"#define MAX_DIR_LIGHTS "+e:"",g?"#define MAX_POINT_LIGHTS "+g:"","attribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\nuniform vec3 cameraPosition;\nuniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",e?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",e?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",g?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":
"",g?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","uniform mat4 objMatrix;\nuniform mat4 viewMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat3 normalMatrix;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",g?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform float mRefractionRatio;\nvoid main(void) {\nvec4 mPosition = objMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 nWorld = mat3( objMatrix[0].xyz, objMatrix[1].xyz, objMatrix[2].xyz ) * normal;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec3 transformedNormal = normalize( normalMatrix * normal );\nif ( !enableLighting ) {\nvLightWeighting = vec3( 1.0, 1.0, 1.0 );\n} else {\nvLightWeighting = ambientLightColor;",
e?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",e?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",e?"float directionalLightWeighting = max( dot( transformedNormal, normalize(lDirection.xyz ) ), 0.0 );":"",e?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",e?"}":"",g?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",g?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",g?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
"",g?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",g?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",g?"}":"","}\nvNormal = transformedNormal;\nvUv = uv;\nif ( useRefract ) {\nvReflect = refract( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz), mRefractionRatio );\n} else {\nvReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );\n}\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n")));
b.linkProgram(d);if(!b.getProgramParameter(d,b.LINK_STATUS)){alert("Could not initialise shaders");alert("VALIDATE_STATUS: "+b.getProgramParameter(d,b.VALIDATE_STATUS));alert(b.getError())}b.useProgram(d);d.viewMatrix=b.getUniformLocation(d,"viewMatrix");d.modelViewMatrix=b.getUniformLocation(d,"modelViewMatrix");d.projectionMatrix=b.getUniformLocation(d,"projectionMatrix");d.normalMatrix=b.getUniformLocation(d,"normalMatrix");d.objMatrix=b.getUniformLocation(d,"objMatrix");d.cameraPosition=b.getUniformLocation(d,
"cameraPosition");d.enableLighting=b.getUniformLocation(d,"enableLighting");d.ambientLightColor=b.getUniformLocation(d,"ambientLightColor");if(e){d.directionalLightNumber=b.getUniformLocation(d,"directionalLightNumber");d.directionalLightColor=b.getUniformLocation(d,"directionalLightColor");d.directionalLightDirection=b.getUniformLocation(d,"directionalLightDirection")}if(g){d.pointLightNumber=b.getUniformLocation(d,"pointLightNumber");d.pointLightColor=b.getUniformLocation(d,"pointLightColor");d.pointLightPosition=
b.getUniformLocation(d,"pointLightPosition")}d.material=b.getUniformLocation(d,"material");d.mColor=b.getUniformLocation(d,"mColor");d.mOpacity=b.getUniformLocation(d,"mOpacity");d.mReflectivity=b.getUniformLocation(d,"mReflectivity");d.mAmbient=b.getUniformLocation(d,"mAmbient");d.mSpecular=b.getUniformLocation(d,"mSpecular");d.mShininess=b.getUniformLocation(d,"mShininess");d.enableMap=b.getUniformLocation(d,"enableMap");b.uniform1i(d.enableMap,0);d.tMap=b.getUniformLocation(d,"tMap");b.uniform1i(d.tMap,
0);d.enableCubeMap=b.getUniformLocation(d,"enableCubeMap");b.uniform1i(d.enableCubeMap,0);d.tCube=b.getUniformLocation(d,"tCube");b.uniform1i(d.tCube,1);d.mixEnvMap=b.getUniformLocation(d,"mixEnvMap");b.uniform1i(d.mixEnvMap,0);d.mRefractionRatio=b.getUniformLocation(d,"mRefractionRatio");d.useRefract=b.getUniformLocation(d,"useRefract");b.uniform1i(d.useRefract,0);d.m2Near=b.getUniformLocation(d,"m2Near");d.mFarPlusNear=b.getUniformLocation(d,"mFarPlusNear");d.mFarMinusNear=b.getUniformLocation(d,
"mFarMinusNear");d.position=b.getAttribLocation(d,"position");b.enableVertexAttribArray(d.position);d.normal=b.getAttribLocation(d,"normal");b.enableVertexAttribArray(d.normal);d.uv=b.getAttribLocation(d,"uv");b.enableVertexAttribArray(d.uv);d.viewMatrixArray=new Float32Array(16);d.modelViewMatrixArray=new Float32Array(16);d.projectionMatrixArray=new Float32Array(16)})(a.directional,a.point);this.setSize=function(e,g){h.width=e;h.height=g;b.viewport(0,0,h.width,h.height)};this.clear=function(){b.clear(b.COLOR_BUFFER_BIT|
b.DEPTH_BUFFER_BIT)};this.setupLights=function(e){var g,k,i,n,j=[],A=[],C=[];n=[];var v=[];b.uniform1i(d.enableLighting,e.lights.length);g=0;for(k=e.lights.length;g<k;g++){i=e.lights[g];if(i instanceof THREE.AmbientLight)j.push(i);else if(i instanceof THREE.DirectionalLight)C.push(i);else i instanceof THREE.PointLight&&A.push(i)}g=e=i=n=0;for(k=j.length;g<k;g++){e+=j[g].color.r;i+=j[g].color.g;n+=j[g].color.b}b.uniform3f(d.ambientLightColor,e,i,n);n=[];v=[];g=0;for(k=C.length;g<k;g++){i=C[g];n.push(i.color.r*
i.intensity);n.push(i.color.g*i.intensity);n.push(i.color.b*i.intensity);v.push(i.position.x);v.push(i.position.y);v.push(i.position.z)}if(C.length){b.uniform1i(d.directionalLightNumber,C.length);b.uniform3fv(d.directionalLightDirection,v);b.uniform3fv(d.directionalLightColor,n)}n=[];v=[];g=0;for(k=A.length;g<k;g++){i=A[g];n.push(i.color.r*i.intensity);n.push(i.color.g*i.intensity);n.push(i.color.b*i.intensity);v.push(i.position.x);v.push(i.position.y);v.push(i.position.z)}if(A.length){b.uniform1i(d.pointLightNumber,
A.length);b.uniform3fv(d.pointLightPosition,v);b.uniform3fv(d.pointLightColor,n)}};this.createBuffers=function(e,g){var k,i,n,j,A,C,v,L,r,q=e.materialFaceGroup[g],l=[],R=[],G=[],U=[],$=[],t=0,E=false;k=0;for(i=e.material.length;k<i;k++){meshMaterial=e.material[k];if(meshMaterial instanceof THREE.MeshFaceMaterial){j=0;for(A=q.material.length;j<A;j++)if(q.material[j]&&q.material[j].shading!=undefined&&q.material[j].shading==THREE.SmoothShading){E=true;break}}else if(meshMaterial&&meshMaterial.shading!=
undefined&&meshMaterial.shading==THREE.SmoothShading){E=true;break}if(E)break}k=0;for(i=q.faces.length;k<i;k++){n=q.faces[k];j=e.geometry.faces[n];A=j.vertexNormals;C=j.normal;n=e.geometry.uvs[n];if(j instanceof THREE.Face3){v=e.geometry.vertices[j.a].position;L=e.geometry.vertices[j.b].position;r=e.geometry.vertices[j.c].position;G.push(v.x,v.y,v.z);G.push(L.x,L.y,L.z);G.push(r.x,r.y,r.z);if(A.length==3&&E)for(j=0;j<3;j++)U.push(A[j].x,A[j].y,A[j].z);else for(j=0;j<3;j++)U.push(C.x,C.y,C.z);if(n)for(j=
0;j<3;j++)$.push(n[j].u,n[j].v);l.push(t,t+1,t+2);R.push(t,t+1);R.push(t,t+2);R.push(t+1,t+2);t+=3}else if(j instanceof THREE.Face4){v=e.geometry.vertices[j.a].position;L=e.geometry.vertices[j.b].position;r=e.geometry.vertices[j.c].position;j=e.geometry.vertices[j.d].position;G.push(v.x,v.y,v.z);G.push(L.x,L.y,L.z);G.push(r.x,r.y,r.z);G.push(j.x,j.y,j.z);if(A.length==4&&E)for(j=0;j<4;j++)U.push(A[j].x,A[j].y,A[j].z);else for(j=0;j<4;j++)U.push(C.x,C.y,C.z);if(n)for(j=0;j<4;j++)$.push(n[j].u,n[j].v);
l.push(t,t+1,t+2);l.push(t,t+2,t+3);R.push(t,t+1);R.push(t,t+2);R.push(t,t+3);R.push(t+1,t+2);R.push(t+2,t+3);t+=4}}if(G.length){q.__webGLVertexBuffer=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,q.__webGLVertexBuffer);b.bufferData(b.ARRAY_BUFFER,new Float32Array(G),b.STATIC_DRAW);q.__webGLNormalBuffer=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,q.__webGLNormalBuffer);b.bufferData(b.ARRAY_BUFFER,new Float32Array(U),b.STATIC_DRAW);q.__webGLUVBuffer=b.createBuffer();b.bindBuffer(b.ARRAY_BUFFER,q.__webGLUVBuffer);
b.bufferData(b.ARRAY_BUFFER,new Float32Array($),b.STATIC_DRAW);q.__webGLFaceBuffer=b.createBuffer();b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,q.__webGLFaceBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,new Uint16Array(l),b.STATIC_DRAW);q.__webGLLineBuffer=b.createBuffer();b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,q.__webGLLineBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,new Uint16Array(R),b.STATIC_DRAW);q.__webGLFaceCount=l.length;q.__webGLLineCount=R.length}};this.renderBuffer=function(e,g){var k,i,n,j,A,C,v,L,
r,q;if(e instanceof THREE.MeshPhongMaterial||e instanceof THREE.MeshLambertMaterial||e instanceof THREE.MeshBasicMaterial){k=e.color;i=e.opacity;j=e.wireframe;A=e.wireframe_linewidth;v=e.map;L=e.env_map;C=e.combine==THREE.Mix;n=e.reflectivity;q=e.env_map&&e.env_map.mapping==THREE.RefractionMap;r=e.refraction_ratio;b.uniform4f(d.mColor,k.r*i,k.g*i,k.b*i,i);b.uniform1i(d.mixEnvMap,C);b.uniform1f(d.mReflectivity,n);b.uniform1i(d.useRefract,q);b.uniform1f(d.mRefractionRatio,r)}if(e instanceof THREE.MeshNormalMaterial){i=
e.opacity;b.uniform1f(d.mOpacity,i);b.uniform1i(d.material,4)}else if(e instanceof THREE.MeshDepthMaterial){i=e.opacity;j=e.wireframe;A=e.wireframe_linewidth;b.uniform1f(d.mOpacity,i);b.uniform1f(d.m2Near,e.__2near);b.uniform1f(d.mFarPlusNear,e.__farPlusNear);b.uniform1f(d.mFarMinusNear,e.__farMinusNear);b.uniform1i(d.material,3)}else if(e instanceof THREE.MeshPhongMaterial){k=e.ambient;n=e.specular;C=e.shininess;b.uniform4f(d.mAmbient,k.r,k.g,k.b,i);b.uniform4f(d.mSpecular,n.r,n.g,n.b,i);b.uniform1f(d.mShininess,
C);b.uniform1i(d.material,2)}else if(e instanceof THREE.MeshLambertMaterial)b.uniform1i(d.material,1);else if(e instanceof THREE.MeshBasicMaterial)b.uniform1i(d.material,0);else if(e instanceof THREE.MeshCubeMaterial){b.uniform1i(d.material,5);L=e.env_map}if(v){if(!e.__webGLTexture&&e.map.image.loaded){e.__webGLTexture=b.createTexture();b.bindTexture(b.TEXTURE_2D,e.__webGLTexture);b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.map.image);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,
f(e.map.wrap_s));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,f(e.map.wrap_t));b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,b.LINEAR);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,b.LINEAR_MIPMAP_LINEAR);b.generateMipmap(b.TEXTURE_2D);b.bindTexture(b.TEXTURE_2D,null)}b.activeTexture(b.TEXTURE0);b.bindTexture(b.TEXTURE_2D,e.__webGLTexture);b.uniform1i(d.tMap,0);b.uniform1i(d.enableMap,1)}else b.uniform1i(d.enableMap,0);if(L){if(e.env_map&&e.env_map instanceof THREE.TextureCube&&e.env_map.image.length==
6){if(!e.env_map.image.__webGLTextureCube&&!e.env_map.image.__cubeMapInitialized&&e.env_map.image.loadCount==6){e.env_map.image.__webGLTextureCube=b.createTexture();b.bindTexture(b.TEXTURE_CUBE_MAP,e.env_map.image.__webGLTextureCube);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_MAG_FILTER,b.LINEAR);b.texParameteri(b.TEXTURE_CUBE_MAP,b.TEXTURE_MIN_FILTER,b.LINEAR_MIPMAP_LINEAR);
for(i=0;i<6;++i)b.texImage2D(b.TEXTURE_CUBE_MAP_POSITIVE_X+i,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,e.env_map.image[i]);b.generateMipmap(b.TEXTURE_CUBE_MAP);b.bindTexture(b.TEXTURE_CUBE_MAP,null);e.env_map.image.__cubeMapInitialized=true}b.activeTexture(b.TEXTURE1);b.bindTexture(b.TEXTURE_CUBE_MAP,e.env_map.image.__webGLTextureCube);b.uniform1i(d.tCube,1)}b.uniform1i(d.enableCubeMap,1)}else b.uniform1i(d.enableCubeMap,0);b.bindBuffer(b.ARRAY_BUFFER,g.__webGLVertexBuffer);b.vertexAttribPointer(d.position,
3,b.FLOAT,false,0,0);b.bindBuffer(b.ARRAY_BUFFER,g.__webGLNormalBuffer);b.vertexAttribPointer(d.normal,3,b.FLOAT,false,0,0);if(v){b.bindBuffer(b.ARRAY_BUFFER,g.__webGLUVBuffer);b.enableVertexAttribArray(d.uv);b.vertexAttribPointer(d.uv,2,b.FLOAT,false,0,0)}else b.disableVertexAttribArray(d.uv);if(j){b.lineWidth(A);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,g.__webGLLineBuffer);b.drawElements(b.LINES,g.__webGLLineCount,b.UNSIGNED_SHORT,0)}else{b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,g.__webGLFaceBuffer);b.drawElements(b.TRIANGLES,
g.__webGLFaceCount,b.UNSIGNED_SHORT,0)}};this.renderPass=function(e,g,k,i){var n,j,A,C,v;A=0;for(C=e.material.length;A<C;A++){n=e.material[A];if(n instanceof THREE.MeshFaceMaterial){n=0;for(j=g.material.length;n<j;n++)if((v=g.material[n])&&v.blending==k&&v.opacity<1==i){this.setBlending(v.blending);this.renderBuffer(v,g)}}else if((v=n)&&v.blending==k&&v.opacity<1==i){this.setBlending(v.blending);this.renderBuffer(v,g)}}};this.render=function(e,g){var k,i;this.initWebGLObjects(e);this.autoClear&&this.clear();
g.autoUpdateMatrix&&g.updateMatrix();b.uniform3f(d.cameraPosition,g.position.x,g.position.y,g.position.z);this.setupLights(e);k=0;for(i=e.__webGLObjects.length;k<i;k++){webGLObject=e.__webGLObjects[k];if(webGLObject.__object.visible){this.setupMatrices(webGLObject.__object,g);this.renderPass(webGLObject.__object,webGLObject,THREE.NormalBlending,false)}}k=0;for(i=e.__webGLObjects.length;k<i;k++){webGLObject=e.__webGLObjects[k];if(webGLObject.__object.visible){this.setupMatrices(webGLObject.__object,
g);this.renderPass(webGLObject.__object,webGLObject,THREE.AdditiveBlending,false);this.renderPass(webGLObject.__object,webGLObject,THREE.SubtractiveBlending,false);this.renderPass(webGLObject.__object,webGLObject,THREE.AdditiveBlending,true);this.renderPass(webGLObject.__object,webGLObject,THREE.SubtractiveBlending,true);this.renderPass(webGLObject.__object,webGLObject,THREE.NormalBlending,true)}}};this.initWebGLObjects=function(e){var g,k,i,n,j;if(!e.__webGLObjects)e.__webGLObjects=[];g=0;for(k=
e.objects.length;g<k;g++){i=e.objects[g];if(i instanceof THREE.Mesh)for(n in i.materialFaceGroup){j=i.materialFaceGroup[n];if(!j.__webGLVertexBuffer){this.createBuffers(i,n);j.__object=i;e.__webGLObjects.push(j)}}}};this.removeObject=function(e,g){var k,i;for(k=e.__webGLObjects.length-1;k>=0;k--){i=e.__webGLObjects[k].__object;g==i&&e.__webGLObjects.splice(k,1)}};this.setupMatrices=function(e,g){e.autoUpdateMatrix&&e.updateMatrix();p.multiply(g.matrix,e.matrix);d.viewMatrixArray=new Float32Array(g.matrix.flatten());
d.modelViewMatrixArray=new Float32Array(p.flatten());d.projectionMatrixArray=new Float32Array(g.projectionMatrix.flatten());s=THREE.Matrix4.makeInvert3x3(p).transpose();d.normalMatrixArray=new Float32Array(s.m);b.uniformMatrix4fv(d.viewMatrix,false,d.viewMatrixArray);b.uniformMatrix4fv(d.modelViewMatrix,false,d.modelViewMatrixArray);b.uniformMatrix4fv(d.projectionMatrix,false,d.projectionMatrixArray);b.uniformMatrix3fv(d.normalMatrix,false,d.normalMatrixArray);b.uniformMatrix4fv(d.objMatrix,false,
new Float32Array(e.matrix.flatten()))};this.setBlending=function(e){switch(e){case THREE.AdditiveBlending:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE);break;case THREE.SubtractiveBlending:b.blendFunc(b.DST_COLOR,b.ZERO);break;default:b.blendEquation(b.FUNC_ADD);b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(e,g){if(e){!g||g=="ccw"?b.frontFace(b.CCW):b.frontFace(b.CW);if(e=="back")b.cullFace(b.BACK);else e=="front"?b.cullFace(b.FRONT):b.cullFace(b.FRONT_AND_BACK);b.enable(b.CULL_FACE)}else b.disable(b.CULL_FACE)}};
THREE.RenderableFace3=function(){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.material=this.color=this.z=null};
THREE.RenderableFace4=function(){this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.v4=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.material=this.color=this.z=null};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=this.color=null};
THREE.RenderableLine=function(){this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=this.color=this.z=null};
