Files
three.js/build/ThreeDebug.js
T

167 lines
76 KiB
JavaScript

// ThreeDebug.js r28 - http://github.com/mrdoob/three.js
var THREE=THREE||{};THREE.Color=function(a){this.autoUpdate=true;this.setHex(a)};
THREE.Color.prototype={setRGBA:function(a,b,f,c){this.r=a;this.g=b;this.b=f;this.a=c;if(this.autoUpdate){this.updateHex();this.updateStyleString()}},setHex:function(a){this.hex=((a=~~a)&16777215)==a?-16777216^a:a;if(this.autoUpdate){this.updateRGBA();this.updateStyleString()}},updateHex:function(){this.hex=~~(this.a*255)<<24^~~(this.r*255)<<16^~~(this.g*255)<<8^~~(this.b*255)},updateRGBA:function(){this.a=(this.hex>>24&255)/255;this.r=(this.hex>>16&255)/255;this.g=(this.hex>>8&255)/255;this.b=(this.hex&
255)/255},updateStyleString:function(){this.__styleString="rgba("+~~(this.r*255)+","+~~(this.g*255)+","+~~(this.b*255)+","+this.a+")"},toString:function(){return"THREE.Color ( r: "+this.r+", g: "+this.g+", b: "+this.b+", a: "+this.a+", 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,f){this.x=a||0;this.y=b||0;this.z=f||0};
THREE.Vector3.prototype={set:function(a,b,f){this.x=a;this.y=b;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,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,f=this.y,c=this.z;this.x=f*a.z-c*a.y;this.y=c*a.x-b*a.z;this.z=b*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 b=this.x-a.x,f=this.y-a.y;a=this.z-a.z;return b*b+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,b,f,c){this.x=a||0;this.y=b||0;this.z=f||0;this.w=c||1};
THREE.Vector4.prototype={set:function(a,b,f,c){this.x=a;this.y=b;this.z=f;this.w=c;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w;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},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,f,c=a.objects,d=[];a=0;for(b=c.length;a<b;a++){f=c[a];if(f instanceof THREE.Mesh)d=d.concat(this.intersectObject(f))}d.sort(function(o,q){return o.distance-q.distance});return d},intersectObject:function(a){function b(y,j,v,i){i=i.clone().subSelf(j);v=v.clone().subSelf(j);var B=y.clone().subSelf(j);y=i.dot(i);j=i.dot(v);i=i.dot(B);var C=v.dot(v);v=v.dot(B);B=1/(y*C-j*j);C=(C*i-j*v)*B;y=(y*v-j*i)*B;return C>0&&y>0&&C+y<1}var f,c,d,o,q,k,e,g,m,r,
l,s=a.geometry,p=s.vertices,n=[];f=0;for(c=s.faces.length;f<c;f++){d=s.faces[f];r=this.origin.clone();l=this.direction.clone();o=a.matrix.transform(p[d.a].position.clone());q=a.matrix.transform(p[d.b].position.clone());k=a.matrix.transform(p[d.c].position.clone());e=d instanceof THREE.Face4?a.matrix.transform(p[d.d].position.clone()):null;g=a.matrixRotation.transform(d.normal.clone());m=l.dot(g);if(m<0){g=g.dot((new THREE.Vector3).sub(o,r))/m;r=r.addSelf(l.multiplyScalar(g));if(d instanceof THREE.Face3){if(b(r,
o,q,k)){d={distance:this.origin.distanceTo(r),point:r,face:d,object:a};n.push(d)}}else if(d instanceof THREE.Face4)if(b(r,o,q,e)||b(r,q,k,e)){d={distance:this.origin.distanceTo(r),point:r,face:d,object:a};n.push(d)}}}return n}};
THREE.Rectangle=function(){function a(){o=c-b;q=d-f}var b,f,c,d,o,q,k=true;this.getX=function(){return b};this.getY=function(){return f};this.getWidth=function(){return o};this.getHeight=function(){return q};this.getLeft=function(){return b};this.getTop=function(){return f};this.getRight=function(){return c};this.getBottom=function(){return d};this.set=function(e,g,m,r){k=false;b=e;f=g;c=m;d=r;a()};this.addPoint=function(e,g){if(k){k=false;b=e;f=g;c=e;d=g}else{b=Math.min(b,e);f=Math.min(f,g);c=Math.max(c,
e);d=Math.max(d,g)}a()};this.addRectangle=function(e){if(k){k=false;b=e.getLeft();f=e.getTop();c=e.getRight();d=e.getBottom()}else{b=Math.min(b,e.getLeft());f=Math.min(f,e.getTop());c=Math.max(c,e.getRight());d=Math.max(d,e.getBottom())}a()};this.inflate=function(e){b-=e;f-=e;c+=e;d+=e;a()};this.minSelf=function(e){b=Math.max(b,e.getLeft());f=Math.max(f,e.getTop());c=Math.min(c,e.getRight());d=Math.min(d,e.getBottom());a()};this.instersects=function(e){return Math.min(c,e.getRight())-Math.max(b,e.getLeft())>=
0&&Math.min(d,e.getBottom())-Math.max(f,e.getTop())>=0};this.empty=function(){k=true;d=c=f=b=0;a()};this.isEmpty=function(){return k};this.toString=function(){return"THREE.Rectangle ( left: "+b+", right: "+c+", top: "+f+", bottom: "+d+", width: "+o+", height: "+q+" )"}};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,b,f){var c=this._x,d=this._y,o=this._z;o.sub(a,b);o.normalize();c.cross(f,o);c.normalize();d.cross(o,c);d.normalize();this.n11=c.x;this.n12=c.y;this.n13=c.z;this.n14=-c.dot(a);this.n21=d.x;this.n22=d.y;this.n23=d.z;this.n24=-d.dot(a);this.n31=o.x;this.n32=o.y;this.n33=o.z;this.n34=-o.dot(a);this.n43=this.n42=this.n41=0;this.n44=1},transform:function(a){var b=a.x,f=a.y,c=a.z,d=a.w?a.w:1;a.x=this.n11*b+this.n12*f+this.n13*c+this.n14*
d;a.y=this.n21*b+this.n22*f+this.n23*c+this.n24*d;a.z=this.n31*b+this.n32*f+this.n33*c+this.n34*d;d=this.n41*b+this.n42*f+this.n43*c+this.n44*d;if(a.w)a.w=d;else{a.x/=d;a.y/=d;a.z/=d}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){this.n11=a.n11*b.n11+a.n12*b.n21+a.n13*b.n31+a.n14*b.n41;this.n12=a.n11*b.n12+a.n12*b.n22+a.n13*b.n32+a.n14*b.n42;this.n13=a.n11*b.n13+a.n12*b.n23+a.n13*b.n33+a.n14*b.n43;this.n14=a.n11*b.n14+a.n12*b.n24+a.n13*b.n34+a.n14*b.n44;this.n21=a.n21*b.n11+a.n22*b.n21+a.n23*b.n31+a.n24*b.n41;this.n22=a.n21*b.n12+a.n22*b.n22+a.n23*b.n32+a.n24*b.n42;this.n23=a.n21*b.n13+a.n22*b.n23+a.n23*b.n33+a.n24*b.n43;this.n24=a.n21*b.n14+a.n22*b.n24+a.n23*b.n34+a.n24*b.n44;this.n31=a.n31*b.n11+a.n32*b.n21+a.n33*b.n31+
a.n34*b.n41;this.n32=a.n31*b.n12+a.n32*b.n22+a.n33*b.n32+a.n34*b.n42;this.n33=a.n31*b.n13+a.n32*b.n23+a.n33*b.n33+a.n34*b.n43;this.n34=a.n31*b.n14+a.n32*b.n24+a.n33*b.n34+a.n34*b.n44;this.n41=a.n41*b.n11+a.n42*b.n21+a.n43*b.n31+a.n44*b.n41;this.n42=a.n41*b.n12+a.n42*b.n22+a.n43*b.n32+a.n44*b.n42;this.n43=a.n41*b.n13+a.n42*b.n23+a.n43*b.n33+a.n44*b.n43;this.n44=a.n41*b.n14+a.n42*b.n24+a.n43*b.n34+a.n44*b.n44},multiplySelf:function(a){var b=this.n11,f=this.n12,c=this.n13,d=this.n14,o=this.n21,q=this.n22,
k=this.n23,e=this.n24,g=this.n31,m=this.n32,r=this.n33,l=this.n34,s=this.n41,p=this.n42,n=this.n43,y=this.n44;this.n11=b*a.n11+f*a.n21+c*a.n31+d*a.n41;this.n12=b*a.n12+f*a.n22+c*a.n32+d*a.n42;this.n13=b*a.n13+f*a.n23+c*a.n33+d*a.n43;this.n14=b*a.n14+f*a.n24+c*a.n34+d*a.n44;this.n21=o*a.n11+q*a.n21+k*a.n31+e*a.n41;this.n22=o*a.n12+q*a.n22+k*a.n32+e*a.n42;this.n23=o*a.n13+q*a.n23+k*a.n33+e*a.n43;this.n24=o*a.n14+q*a.n24+k*a.n34+e*a.n44;this.n31=g*a.n11+m*a.n21+r*a.n31+l*a.n41;this.n32=g*a.n12+m*a.n22+
r*a.n32+l*a.n42;this.n33=g*a.n13+m*a.n23+r*a.n33+l*a.n43;this.n34=g*a.n14+m*a.n24+r*a.n34+l*a.n44;this.n41=s*a.n11+p*a.n21+n*a.n31+y*a.n41;this.n42=s*a.n12+p*a.n22+n*a.n32+y*a.n42;this.n43=s*a.n13+p*a.n23+n*a.n33+y*a.n43;this.n44=s*a.n14+p*a.n24+n*a.n34+y*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(b,f,c){var d=b[f];b[f]=b[c];b[c]=d}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,f){var c=new THREE.Matrix4;c.n14=a;c.n24=b;c.n34=f;return c};THREE.Matrix4.scaleMatrix=function(a,b,f){var c=new THREE.Matrix4;c.n11=a;c.n22=b;c.n33=f;return c};
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 f=new THREE.Matrix4,c=Math.cos(b),d=Math.sin(b),o=1-c,q=a.x,k=a.y,e=a.z;f.n11=o*q*q+c;f.n12=o*q*k-d*e;f.n13=o*q*e+d*k;f.n21=o*q*k+d*e;f.n22=o*k*k+c;f.n23=o*k*e-d*q;f.n31=o*q*e-d*k;f.n32=o*k*e+d*q;f.n33=o*e*e+c;return f};
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 f=b[10]*b[5]-b[6]*b[9],c=-b[10]*b[1]+b[2]*b[9],d=b[6]*b[1]-b[2]*b[5],o=-b[10]*b[4]+b[6]*b[8],q=b[10]*b[0]-b[2]*b[8],k=-b[6]*b[0]+b[2]*b[4],e=b[9]*b[4]-b[5]*b[8],g=-b[9]*b[0]+b[1]*b[8],m=b[5]*b[0]-b[1]*b[4];b=b[0]*f+b[1]*o+b[2]*e;if(b==0)throw"matrix not invertible";b=1/b;a.m[0]=b*f;a.m[1]=b*c;a.m[2]=b*d;a.m[3]=b*o;a.m[4]=b*q;a.m[5]=b*k;a.m[6]=b*e;a.m[7]=b*g;a.m[8]=b*m;return a};
THREE.Matrix4.makeFrustum=function(a,b,f,c,d,o){var q,k,e;q=new THREE.Matrix4;k=2*d/(b-a);e=2*d/(c-f);a=(b+a)/(b-a);f=(c+f)/(c-f);c=-(o+d)/(o-d);d=-2*o*d/(o-d);q.n11=k;q.n12=0;q.n13=a;q.n14=0;q.n21=0;q.n22=e;q.n23=f;q.n24=0;q.n31=0;q.n32=0;q.n33=c;q.n34=d;q.n41=0;q.n42=0;q.n43=-1;q.n44=0;return q};THREE.Matrix4.makePerspective=function(a,b,f,c){var d;a=f*Math.tan(a*Math.PI/360);d=-a;return THREE.Matrix4.makeFrustum(d*b,a*b,d,a,f,c)};
THREE.Matrix4.makeOrtho=function(a,b,f,c,d,o){var q,k,e,g;q=new THREE.Matrix4;k=b-a;e=f-c;g=o-d;a=(b+a)/k;f=(f+c)/e;d=(o+d)/g;q.n11=2/k;q.n12=0;q.n13=0;q.n14=-a;q.n21=0;q.n22=2/e;q.n23=0;q.n24=-f;q.n31=0;q.n32=0;q.n33=-2/g;q.n34=-d;q.n41=0;q.n42=0;q.n43=0;q.n44=1;return q};
THREE.Vertex=function(a,b){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector3;this.normal=b||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,b,f,c,d){this.a=a;this.b=b;this.c=f;this.centroid=new THREE.Vector3;this.normal=c instanceof THREE.Vector3?c:new THREE.Vector3;this.vertexNormals=c instanceof Array?c:[];this.material=d instanceof Array?d:[d]};THREE.Face3.prototype={toString:function(){return"THREE.Face3 ( "+this.a+", "+this.b+", "+this.c+" )"}};
THREE.Face4=function(a,b,f,c,d,o){this.a=a;this.b=b;this.c=f;this.d=c;this.centroid=new THREE.Vector3;this.normal=d instanceof THREE.Vector3?d:new THREE.Vector3;this.vertexNormals=d instanceof Array?d:[];this.material=o instanceof Array?o:[o]};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=[]};
THREE.Geometry.prototype={computeCentroids:function(){var a,b,f;a=0;for(b=this.faces.length;a<b;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 b,f,c,d,o,q,k=new THREE.Vector3,e=new THREE.Vector3;c=0;for(d=this.vertices.length;c<d;c++){o=this.vertices[c];o.normal.set(0,0,0)}c=0;for(d=this.faces.length;c<d;c++){o=this.faces[c];if(a&&o.vertexNormals.length){k.set(0,0,0);b=0;for(f=o.normal.length;b<f;b++)k.addSelf(o.vertexNormals[b]);k.divideScalar(3)}else{b=this.vertices[o.a];f=this.vertices[o.b];q=this.vertices[o.c];k.sub(q.position,
f.position);e.sub(b.position,f.position);k.crossSelf(e)}k.isZero()||k.normalize();o.normal.copy(k)}},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,b=this.vertices.length;a<b;a++){vertex=this.vertices[a];if(vertex.position.x<this.bbox.x[0])this.bbox.x[0]=vertex.position.x;else if(vertex.position.x>
this.bbox.x[1])this.bbox.x[1]=vertex.position.x;if(vertex.position.y<this.bbox.y[0])this.bbox.y[0]=vertex.position.y;else if(vertex.position.y>this.bbox.y[1])this.bbox.y[1]=vertex.position.y;if(vertex.position.z<this.bbox.z[0])this.bbox.z[0]=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,b,f,c){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,b,f,c);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.Loader=function(){};
THREE.Loader.prototype={loadAsciiOld:function(a,b){var f=document.createElement("script");f.type="text/javascript";f.onload=b;f.src=a;document.getElementsByTagName("head")[0].appendChild(f)},loadAscii:function(a,b,f){var c=(new Date).getTime();a=new Worker(a);a.onmessage=function(d){THREE.Loader.prototype.createModel(d.data,b,f)};a.postMessage(c)},loadBinary:function(a,b,f){var c=(new Date).getTime();a=new Worker(a);a.onmessage=function(d){THREE.Loader.prototype.loadAjaxBuffers(d.data.buffers,d.data.materials,
b,f)};a.onerror=function(d){alert("worker.onerror: "+d.message+"\n"+d.data);d.preventDefault()};a.postMessage(c)},loadAjaxBuffers:function(a,b,f,c){var d=new XMLHttpRequest,o=c+"/"+a;d.onreadystatechange=function(){if(d.readyState==4)d.status==200||d.status==0?THREE.Loader.prototype.createBinModel(d.responseText,f,c,b):alert("Couldn't load ["+o+"] ["+d.status+"]")};d.open("GET",o,true);d.overrideMimeType("text/plain; charset=x-user-defined");d.setRequestHeader("Content-Type","text/plain");d.send(null)},
createBinModel:function(a,b,f,c){var d=function(o){function q(h,t){var x=m(h,t),D=m(h,t+1),K=m(h,t+2),da=m(h,t+3),ia=(da<<1&255|K>>7)-127;x=(K&127)<<16|D<<8|x;if(x==0&&ia==-127)return 0;return(1-2*(da>>7))*(1+x*Math.pow(2,-23))*Math.pow(2,ia)}function k(h,t){var x=m(h,t),D=m(h,t+1),K=m(h,t+2);return(m(h,t+3)<<24)+(K<<16)+(D<<8)+x}function e(h,t){var x=m(h,t);return(m(h,t+1)<<8)+x}function g(h,t){var x=m(h,t);return x>127?x-256:x}function m(h,t){return h.charCodeAt(t)&255}function r(h){var t,x,D;t=
k(a,h);x=k(a,h+V);D=k(a,h+w);h=e(a,h+E);THREE.Loader.prototype.f3(j,t,x,D,h)}function l(h){var t,x,D,K,da,ia;t=k(a,h);x=k(a,h+V);D=k(a,h+w);K=e(a,h+E);da=k(a,h+z);ia=k(a,h+T);h=k(a,h+O);THREE.Loader.prototype.f3n(j,B,t,x,D,K,da,ia,h)}function s(h){var t,x,D,K;t=k(a,h);x=k(a,h+P);D=k(a,h+U);K=k(a,h+W);h=e(a,h+aa);THREE.Loader.prototype.f4(j,t,x,D,K,h)}function p(h){var t,x,D,K,da,ia,ja,ra;t=k(a,h);x=k(a,h+P);D=k(a,h+U);K=k(a,h+W);da=e(a,h+aa);ia=k(a,h+I);ja=k(a,h+Z);ra=k(a,h+Q);h=k(a,h+ca);THREE.Loader.prototype.f4n(j,
B,t,x,D,K,da,ia,ja,ra,h)}function n(h){var t,x;t=k(a,h);x=k(a,h+G);h=k(a,h+F);THREE.Loader.prototype.uv(j,C[t*2],C[t*2+1],C[x*2],C[x*2+1],C[h*2],C[h*2+1])}function y(h){var t,x,D;t=k(a,h);x=k(a,h+ba);D=k(a,h+ma);h=k(a,h+R);THREE.Loader.prototype.uv(j,C[t*2],C[t*2+1],C[x*2],C[x*2+1],C[D*2],C[D*2+1],C[h*2],C[h*2+1])}var j=this,v=0,i,B=[],C=[],V,w,E,z,T,O,P,U,W,aa,I,Z,Q,ca,G,F,ba,ma,R;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(j,c,o);i={signature:a.substr(v,8),header_bytes:m(a,v+
8),vertex_coordinate_bytes:m(a,v+9),normal_coordinate_bytes:m(a,v+10),uv_coordinate_bytes:m(a,v+11),vertex_index_bytes:m(a,v+12),normal_index_bytes:m(a,v+13),uv_index_bytes:m(a,v+14),material_index_bytes:m(a,v+15),nvertices:k(a,v+16),nnormals:k(a,v+16+4),nuvs:k(a,v+16+8),ntri_flat:k(a,v+16+12),ntri_smooth:k(a,v+16+16),ntri_flat_uv:k(a,v+16+20),ntri_smooth_uv:k(a,v+16+24),nquad_flat:k(a,v+16+28),nquad_smooth:k(a,v+16+32),nquad_flat_uv:k(a,v+16+36),nquad_smooth_uv:k(a,v+16+40)};v+=i.header_bytes;V=
i.vertex_index_bytes;w=i.vertex_index_bytes*2;E=i.vertex_index_bytes*3;z=i.vertex_index_bytes*3+i.material_index_bytes;T=i.vertex_index_bytes*3+i.material_index_bytes+i.normal_index_bytes;O=i.vertex_index_bytes*3+i.material_index_bytes+i.normal_index_bytes*2;P=i.vertex_index_bytes;U=i.vertex_index_bytes*2;W=i.vertex_index_bytes*3;aa=i.vertex_index_bytes*4;I=i.vertex_index_bytes*4+i.material_index_bytes;Z=i.vertex_index_bytes*4+i.material_index_bytes+i.normal_index_bytes;Q=i.vertex_index_bytes*4+i.material_index_bytes+
i.normal_index_bytes*2;ca=i.vertex_index_bytes*4+i.material_index_bytes+i.normal_index_bytes*3;G=i.uv_index_bytes;F=i.uv_index_bytes*2;ba=i.uv_index_bytes;ma=i.uv_index_bytes*2;R=i.uv_index_bytes*3;v+=function(h){var t,x,D,K=i.vertex_coordinate_bytes*3,da=h+i.nvertices*K;for(h=h;h<da;h+=K){t=q(a,h);x=q(a,h+i.vertex_coordinate_bytes);D=q(a,h+i.vertex_coordinate_bytes*2);THREE.Loader.prototype.v(j,t,x,D)}return i.nvertices*K}(v);v+=function(h){var t,x,D,K=i.normal_coordinate_bytes*3,da=h+i.nnormals*
K;for(h=h;h<da;h+=K){t=g(a,h);x=g(a,h+i.normal_coordinate_bytes);D=g(a,h+i.normal_coordinate_bytes*2);B.push(t/127,x/127,D/127)}return i.nnormals*K}(v);v+=function(h){var t,x,D=i.uv_coordinate_bytes*2,K=h+i.nuvs*D;for(h=h;h<K;h+=D){t=q(a,h);x=q(a,h+i.uv_coordinate_bytes);C.push(t,x)}return i.nuvs*D}(v);v+=function(h){var t,x=i.vertex_index_bytes*3+i.material_index_bytes,D=h+i.ntri_flat*x;for(t=h;t<D;t+=x)r(t);return D-h}(v);v+=function(h){var t,x=i.vertex_index_bytes*3+i.material_index_bytes+i.normal_index_bytes*
3,D=h+i.ntri_smooth*x;for(t=h;t<D;t+=x)l(t);return D-h}(v);v+=function(h){var t,x=i.vertex_index_bytes*3+i.material_index_bytes,D=x+i.uv_index_bytes*3,K=h+i.ntri_flat_uv*D;for(t=h;t<K;t+=D){r(t);n(t+x)}return K-h}(v);v+=function(h){var t,x=i.vertex_index_bytes*3+i.material_index_bytes+i.normal_index_bytes*3,D=x+i.uv_index_bytes*3,K=h+i.ntri_smooth_uv*D;for(t=h;t<K;t+=D){l(t);n(t+x)}return K-h}(v);v+=function(h){var t,x=i.vertex_index_bytes*4+i.material_index_bytes,D=h+i.nquad_flat*x;for(t=h;t<D;t+=
x)s(t);return D-h}(v);v+=function(h){var t,x=i.vertex_index_bytes*4+i.material_index_bytes+i.normal_index_bytes*4,D=h+i.nquad_smooth*x;for(t=h;t<D;t+=x)p(t);return D-h}(v);v+=function(h){var t,x=i.vertex_index_bytes*4+i.material_index_bytes,D=x+i.uv_index_bytes*4,K=h+i.nquad_flat_uv*D;for(t=h;t<K;t+=D){s(t);y(t+x)}return K-h}(v);v+=function(h){var t,x=i.vertex_index_bytes*4+i.material_index_bytes+i.normal_index_bytes*4,D=x+i.uv_index_bytes*4,K=h+i.nquad_smooth_uv*D;for(t=h;t<K;t+=D){p(t);y(t+x)}return K-
h}(v);this.computeCentroids();this.computeNormals()};d.prototype=new THREE.Geometry;d.prototype.constructor=d;b(new d(f))},createModel:function(a,b,f){var c=function(d){var o=this;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(o,a.materials,d);(function(){var q,k,e,g,m;q=0;for(k=a.vertices.length;q<k;q+=3){e=a.vertices[q];g=a.vertices[q+1];m=a.vertices[q+2];THREE.Loader.prototype.v(o,e,g,m)}})();(function(){function q(p,n){THREE.Loader.prototype.f3(o,p[n],p[n+1],p[n+2],p[n+3])}function k(p,
n){THREE.Loader.prototype.f3n(o,a.normals,p[n],p[n+1],p[n+2],p[n+3],p[n+4],p[n+5],p[n+6])}function e(p,n){THREE.Loader.prototype.f4(o,p[n],p[n+1],p[n+2],p[n+3],p[n+4])}function g(p,n){THREE.Loader.prototype.f4n(o,a.normals,p[n],p[n+1],p[n+2],p[n+3],p[n+4],p[n+5],p[n+6],p[n+7],p[n+8])}function m(p,n){var y,j,v;y=p[n];j=p[n+1];v=p[n+2];THREE.Loader.prototype.uv(o,a.uvs[y*2],a.uvs[y*2+1],a.uvs[j*2],a.uvs[j*2+1],a.uvs[v*2],a.uvs[v*2+1])}function r(p,n){var y,j,v,i;y=p[n];j=p[n+1];v=p[n+2];i=p[n+3];THREE.Loader.prototype.uv(o,
a.uvs[y*2],a.uvs[y*2+1],a.uvs[j*2],a.uvs[j*2+1],a.uvs[v*2],a.uvs[v*2+1],a.uvs[i*2],a.uvs[i*2+1])}var l,s;l=0;for(s=a.triangles.length;l<s;l+=4)q(a.triangles,l);l=0;for(s=a.triangles_uv.length;l<s;l+=7){q(a.triangles_uv,l);m(a.triangles_uv,l+4)}l=0;for(s=a.triangles_n.length;l<s;l+=7)k(a.triangles_n,l);l=0;for(s=a.triangles_n_uv.length;l<s;l+=10){k(a.triangles_n_uv,l);m(a.triangles_n_uv,l+7)}l=0;for(s=a.quads.length;l<s;l+=5)e(a.quads,l);l=0;for(s=a.quads_uv.length;l<s;l+=9){e(a.quads_uv,l);r(a.quads_uv,
l+5)}l=0;for(s=a.quads_n.length;l<s;l+=9)g(a.quads_n,l);l=0;for(s=a.quads_n_uv.length;l<s;l+=13){g(a.quads_n_uv,l);r(a.quads_n_uv,l+9)}})();this.computeCentroids();this.computeNormals()};c.prototype=new THREE.Geometry;c.prototype.constructor=c;b(new c(f))},v:function(a,b,f,c){a.vertices.push(new THREE.Vertex(new THREE.Vector3(b,f,c)))},f3:function(a,b,f,c,d){a.faces.push(new THREE.Face3(b,f,c,null,a.materials[d]))},f4:function(a,b,f,c,d,o){a.faces.push(new THREE.Face4(b,f,c,d,null,a.materials[o]))},
f3n:function(a,b,f,c,d,o,q,k,e){o=a.materials[o];var g=b[k*3],m=b[k*3+1];k=b[k*3+2];var r=b[e*3],l=b[e*3+1];e=b[e*3+2];a.faces.push(new THREE.Face3(f,c,d,[new THREE.Vector3(b[q*3],b[q*3+1],b[q*3+2]),new THREE.Vector3(g,m,k),new THREE.Vector3(r,l,e)],o))},f4n:function(a,b,f,c,d,o,q,k,e,g,m){q=a.materials[q];var r=b[e*3],l=b[e*3+1];e=b[e*3+2];var s=b[g*3],p=b[g*3+1];g=b[g*3+2];var n=b[m*3],y=b[m*3+1];m=b[m*3+2];a.faces.push(new THREE.Face4(f,c,d,o,[new THREE.Vector3(b[k*3],b[k*3+1],b[k*3+2]),new THREE.Vector3(r,
l,e),new THREE.Vector3(s,p,g),new THREE.Vector3(n,y,m)],q))},uv:function(a,b,f,c,d,o,q,k,e){var g=[];g.push(new THREE.UV(b,f));g.push(new THREE.UV(c,d));g.push(new THREE.UV(o,q));k&&e&&g.push(new THREE.UV(k,e));a.uvs.push(g)},init_materials:function(a,b,f){a.materials=[];for(var c=0;c<b.length;++c)a.materials[c]=[THREE.Loader.prototype.createMaterial(b[c],f)]},createMaterial:function(a,b){function f(o){o=Math.log(o)/Math.LN2;return Math.floor(o)==o}var c,d;if(a.map_diffuse&&b){d=document.createElement("canvas");
c=new THREE.MeshLambertMaterial({map:new THREE.Texture(d)});d=new Image;d.onload=function(){if(!f(this.width)||!f(this.height)){var o=Math.pow(2,Math.round(Math.log(this.width)/Math.LN2)),q=Math.pow(2,Math.round(Math.log(this.height)/Math.LN2));c.map.image.width=o;c.map.image.height=q;c.map.image.getContext("2d").drawImage(this,0,0,o,q)}else c.map.image=this;c.map.loaded=1};d.src=b+"/"+a.map_diffuse}else if(a.col_diffuse){d=(a.col_diffuse[0]*255<<16)+(a.col_diffuse[1]*255<<8)+a.col_diffuse[2]*255;
c=new THREE.MeshLambertMaterial({color:d,opacity:a.transparency})}else c=a.a_dbg_color?new THREE.MeshLambertMaterial({color:a.a_dbg_color}):new THREE.MeshLambertMaterial({color:15658734});return c}};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,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(0,0,0);this.intensity=b||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=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,b){THREE.Object3D.call(this);this.geometry=a;this.material=b instanceof Array?b:[b]};THREE.Line.prototype=new THREE.Object3D;THREE.Line.prototype.constructor=THREE.Line;
THREE.Mesh=function(a,b,f){THREE.Object3D.call(this);this.geometry=a;this.material=b instanceof Array?b:[b];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(m){var r=[];b=0;for(f=m.length;b<f;b++)m[b]==undefined?r.push("undefined"):r.push(m[b].toString());return r.join("_")}var b,f,c,d,o,q,k,e,g={};c=0;for(d=this.geometry.faces.length;c<d;c++){o=this.geometry.faces[c];q=o.material;k=a(q);if(g[k]==undefined)g[k]={hash:k,counter:0};e=g[k].hash+"_"+g[k].counter;if(this.materialFaceGroup[e]==undefined)this.materialFaceGroup[e]={faces:[],material:q,vertices:0};o=o instanceof THREE.Face3?3:4;if(this.materialFaceGroup[e].vertices+
o>65535){g[k].counter+=1;e=g[k].hash+"_"+g[k].counter;if(this.materialFaceGroup[e]==undefined)this.materialFaceGroup[e]={faces:[],material:q,vertices:0}}this.materialFaceGroup[e].faces.push(c);this.materialFaceGroup[e].vertices+=o}};THREE.Mesh.prototype.normalizeUVs=function(){var a,b,f,c,d;a=0;for(b=this.geometry.uvs.length;a<b;a++){d=this.geometry.uvs[a];f=0;for(c=d.length;f<c;f++){if(d[f].u!=1)d[f].u-=Math.floor(d[f].u);if(d[f].v!=1)d[f].v-=Math.floor(d[f].v)}}};THREE.FlatShading=0;
THREE.GouraudShading=1;THREE.PhongShading=2;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;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}this.toString=function(){return"THREE.LineBasicMaterial (<br/>color: "+this.color+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>linewidth: "+
this.linewidth+"<br/>)"}};
THREE.MeshBasicMaterial=function(a){this.id=THREE.MeshBasicMaterialCounter.value++;this.color=new THREE.Color(15658734);this.map=null;this.opacity=1;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;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;if(a.wireframe!==undefined)this.wireframe=a.wireframe;if(a.wireframe_linewidth!==
undefined)this.wireframe_linewidth=a.wireframe_linewidth}this.toString=function(){return"THREE.MeshBasicMaterial (<br/>id: "+this.id+"<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>opacity: "+this.opacity+"<br/>blending: "+this.blending+"<br/>wireframe: "+this.wireframe+"<br/>wireframe_linewidth: "+this.wireframe_linewidth+"<br/>)"}};THREE.MeshBasicMaterialCounter={value:0};
THREE.MeshLambertMaterial=function(a){this.id=THREE.MeshLambertMaterialCounter.value++;this.color=new THREE.Color(15658734);this.map=null;this.opacity=1;this.shading=THREE.GouraudShading;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;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.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}this.toString=function(){return"THREE.MeshLambertMaterial (<br/>id: "+this.id+"<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>opacity: "+this.opacity+"<br/>shading: "+this.shading+"<br/>blending: "+this.blending+"<br/>wireframe: "+this.wireframe+"<br/>wireframe_size: "+this.wireframe_linewidth+"<br/> )"}};THREE.MeshLambertMaterialCounter={value:0};
THREE.MeshPhongMaterial=function(a){this.id=THREE.MeshPhongMaterialCounter.value++;this.color=new THREE.Color(15658734);this.map=null;this.ambient=new THREE.Color(328965);this.specular=new THREE.Color(1118481);this.specular_map=null;this.shininess=30;this.opacity=1;this.shading=THREE.GouraudShading;this.blending=THREE.NormalBlending;this.wireframe=false;this.wireframe_linewidth=1;if(a){if(a.color!==undefined)this.color=new THREE.Color(a.color);if(a.map!==undefined)this.map=a.map;if(a.ambient!==undefined)this.ambient=
new THREE.Color(a.ambient);if(a.specular!==undefined)this.specular=new THREE.Color(a.specular);if(a.specular_map!==undefined)this.specular_map=a.specular_map;if(a.shininess!==undefined)this.shininess=a.shininess;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}this.toString=
function(){return"THREE.MeshPhongMaterial (<br/>id: "+this.id+"<br/>color: "+this.color+"<br/>map: "+this.map+"<br/>ambient: "+this.ambient+"<br/>specular: "+this.specular+"<br/>specular_map: "+this.specular_map+"<br/>shininess: "+this.shininess+"<br/>alpha: "+this.opacity+"<br/>shading: "+this.shading+"<br/>wireframe: "+this.wireframe+"<br/>wireframe_linewidth: "+this.wireframe_linewidth+"<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.blending=THREE.NormalBlending;if(a){if(a.opacity!==undefined)this.opacity=a.opacity;if(a.blending!==undefined)this.blending=a.blending}this.toString=function(){return"THREE.MeshNormalMaterial"}};THREE.MeshFaceMaterial=function(){this.toString=function(){return"THREE.MeshFaceMaterial"}};
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,b){this.image=a;this.mapping=b?b:THREE.UVMapping;this.toString=function(){return"THREE.Texture (<br/>image: "+this.image+"<br/>mapping: "+this.mapping+"<br/>)"}};THREE.UVMapping=0;THREE.ReflectionMap=1;THREE.CubeMap=2;
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(){var a=null,b,f,c=[],d,o,q=[],k,e,g=[],m,r,l=[],s=new THREE.Vector4,p=new THREE.Matrix4,n=new THREE.Matrix4;this.projectScene=function(y,j){var v,i,B,C,V,w,E,z,T,O,P,U,W,aa;a=[];r=e=o=f=0;j.autoUpdateMatrix&&j.updateMatrix();p.multiply(j.projectionMatrix,j.matrix);V=y.objects;v=0;for(i=V.length;v<i;v++){w=V[v];E=w.matrix;w.autoUpdateMatrix&&w.updateMatrix();if(w instanceof THREE.Mesh){n.multiply(p,E);z=w.geometry.vertices;B=0;for(C=z.length;B<C;B++){T=z[B];O=T.positionScreen;
O.copy(T.position);n.transform(O);T.__visible=O.z>0&&O.z<1}T=w.geometry.faces;B=0;for(C=T.length;B<C;B++){O=T[B];if(O instanceof THREE.Face3){P=z[O.a];U=z[O.b];W=z[O.c];if(P.__visible&&U.__visible&&W.__visible)if(w.doubleSided||w.flipSided!=(W.positionScreen.x-P.positionScreen.x)*(U.positionScreen.y-P.positionScreen.y)-(W.positionScreen.y-P.positionScreen.y)*(U.positionScreen.x-P.positionScreen.x)<0){b=c[f]=c[f]||new THREE.RenderableFace3;b.v1.positionScreen.copy(P.positionScreen);b.v2.positionScreen.copy(U.positionScreen);
b.v3.positionScreen.copy(W.positionScreen);b.normalWorld.copy(O.normal);w.matrixRotation.transform(b.normalWorld);b.centroidWorld.copy(O.centroid);E.transform(b.centroidWorld);b.centroidScreen.copy(b.centroidWorld);p.transform(b.centroidScreen);b.z=b.centroidScreen.z;b.meshMaterial=w.material;b.faceMaterial=O.material;b.overdraw=w.overdraw;b.uvs=w.geometry.uvs[B];b.color=O.color;a.push(b);f++}}else if(O instanceof THREE.Face4){P=z[O.a];U=z[O.b];W=z[O.c];aa=z[O.d];if(P.__visible&&U.__visible&&W.__visible&&
aa.__visible)if(w.doubleSided||w.flipSided!=((aa.positionScreen.x-P.positionScreen.x)*(U.positionScreen.y-P.positionScreen.y)-(aa.positionScreen.y-P.positionScreen.y)*(U.positionScreen.x-P.positionScreen.x)<0||(U.positionScreen.x-W.positionScreen.x)*(aa.positionScreen.y-W.positionScreen.y)-(U.positionScreen.y-W.positionScreen.y)*(aa.positionScreen.x-W.positionScreen.x)<0)){d=q[o]=q[o]||new THREE.RenderableFace4;d.v1.positionScreen.copy(P.positionScreen);d.v2.positionScreen.copy(U.positionScreen);
d.v3.positionScreen.copy(W.positionScreen);d.v4.positionScreen.copy(aa.positionScreen);d.normalWorld.copy(O.normal);w.matrixRotation.transform(d.normalWorld);d.centroidWorld.copy(O.centroid);E.transform(d.centroidWorld);d.centroidScreen.copy(d.centroidWorld);p.transform(d.centroidScreen);d.z=d.centroidScreen.z;d.meshMaterial=w.material;d.faceMaterial=O.material;d.overdraw=w.overdraw;d.uvs=w.geometry.uvs[B];d.color=O.color;a.push(d);o++}}}}else if(w instanceof THREE.Line){n.multiply(p,E);z=w.geometry.vertices;
B=0;for(C=z.length;B<C;B++){T=z[B];O=T.positionScreen;O.copy(T.position);n.transform(O);T.__visible=O.z>0&&O.z<1;if(T.__visible&&B>0){E=w.geometry.vertices[B-1];if(T.__visible&&E.__visible){k=g[e]=g[e]||new THREE.RenderableLine;k.v1.positionScreen.copy(T.positionScreen);k.v2.positionScreen.copy(E.positionScreen);k.z=Math.max(T.positionScreen.z,E.positionScreen.z);k.material=w.material;a.push(k);e++}}}}else if(w instanceof THREE.Particle){s.set(w.position.x,w.position.y,w.position.z,1);p.transform(s);
s.z/=s.w;if(s.z>0&&s.z<1){m=l[r]=l[r]||new THREE.RenderableParticle;m.x=s.x/s.w;m.y=s.y/s.w;m.z=s.z;m.rotation=w.rotation.z;m.scale.x=w.scale.x*Math.abs(m.x-(s.x+j.projectionMatrix.n11)/(s.w+j.projectionMatrix.n14));m.scale.y=w.scale.y*Math.abs(m.y-(s.y+j.projectionMatrix.n22)/(s.w+j.projectionMatrix.n24));m.material=w.material;a.push(m);r++}}}a.sort(function(I,Z){return Z.z-I.z});return a};this.unprojectVector=function(y,j){var v=new THREE.Matrix4;v.multiply(THREE.Matrix4.makeInvert(j.matrix),THREE.Matrix4.makeInvert(j.projectionMatrix));
v.transform(y);return y}};
THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,f,c,d,o;this.domElement=document.createElement("div");this.setSize=function(q,k){f=q;c=k;d=f/2;o=c/2};this.render=function(q,k){var e,g,m,r,l,s,p,n;a=b.projectScene(q,k);e=0;for(g=a.length;e<g;e++){l=a[e];if(l instanceof THREE.RenderableParticle){p=l.x*d+d;n=l.y*o+o;m=0;for(r=l.material.length;m<r;m++){s=l.material[m];if(s instanceof THREE.ParticleDOMMaterial){s=s.domElement;s.style.left=p+"px";s.style.top=n+"px"}}}}}};
THREE.CanvasRenderer=function(){function a(J,S,M){var N,u,L;lights=J.lights;J=0;for(N=lights.length;J<N;J++){u=lights[J];L=u.color;if(u instanceof THREE.DirectionalLight){u=S.normalWorld.dot(u.position)*u.intensity;if(u>0){M.r+=L.r*u;M.g+=L.g*u;M.b+=L.b*u}}else if(u instanceof THREE.PointLight){Ha.sub(u.position,S.centroidWorld);Ha.normalize();u=S.normalWorld.dot(Ha)*u.intensity;if(u>0){M.r+=L.r*u;M.g+=L.g*u;M.b+=L.b*u}}}}function b(J,S,M,N,u,L){U=J.positionScreen.x;W=J.positionScreen.y;aa=S.positionScreen.x;
I=S.positionScreen.y;Z=M.positionScreen.x;Q=M.positionScreen.y;if(u.opacity!=v)j.globalAlpha=v=u.opacity;u.blending!=i&&q(u.blending);if(u.map){ja=u.map.image;ra=ja.width-1;va=ja.height-1;ka.u=N.uvs[0].u*ra;ka.v=N.uvs[0].v*va;ea.u=N.uvs[1].u*ra;ea.v=N.uvs[1].v*va;la.u=N.uvs[2].u*ra;la.v=N.uvs[2].v*va;o(ja,U,W,aa,I,Z,Q,ka.u,ka.v,ea.u,ea.v,la.u,la.v)}else if(u instanceof THREE.MeshBasicMaterial)c(U,W,aa,I,Z,Q,u.color,u.wireframe,u.wireframe_linewidth);else if(u instanceof THREE.MeshLambertMaterial){if(Ea){ga.r=
na.r;ga.g=na.g;ga.b=na.b;a(L,N,ga);X.r=u.color.r*ga.r;X.g=u.color.g*ga.g;X.b=u.color.b*ga.b;X.updateStyleString()}else X.__styleString=u.color.__styleString;c(U,W,aa,I,Z,Q,X,u.wireframe,u.wireframe_linewidth)}else if(u instanceof THREE.MeshDepthMaterial){K=u.__2near;da=u.__farPlusNear;ia=u.__farMinusNear;h=~~((1-K/(da-J.positionScreen.z*ia))*255);t=~~((1-K/(da-S.positionScreen.z*ia))*255);x=~~((1-K/(da-M.positionScreen.z*ia))*255);ja=k([h,h,h],[t,t,t],[x,x,x],[x,x,x]);ka.u=0;ka.v=0;ea.u=sa;ea.v=0;
la.u=0;la.v=sa;o(ja,U,W,aa,I,Z,Q,ka.u,ka.v,ea.u,ea.v,la.u,la.v)}else if(u instanceof THREE.MeshNormalMaterial){X.r=e(N.normalWorld.x);X.g=e(N.normalWorld.y);X.b=e(N.normalWorld.z);X.updateStyleString();c(U,W,aa,I,Z,Q,X,u.wireframe,u.wireframe_linewidth)}}function f(J,S,M,N,u,L,Y,A,$){U=J.positionScreen.x;W=J.positionScreen.y;aa=S.positionScreen.x;I=S.positionScreen.y;Z=M.positionScreen.x;Q=M.positionScreen.y;ca=N.positionScreen.x;G=N.positionScreen.y;F=u.positionScreen.x;ba=u.positionScreen.y;ma=
L.positionScreen.x;R=L.positionScreen.y;if(A.opacity!=v)j.globalAlpha=v=A.opacity;A.blending!=i&&q(A.blending);if(A.map){ja=A.map.image;ra=ja.width-1;va=ja.height-1;ka.copy(Y.uvs[0]);ea.copy(Y.uvs[1]);la.copy(Y.uvs[2]);oa.copy(Y.uvs[3]);ka.u*=ra;ka.v*=va;ea.u*=ra;ea.v*=va;la.u*=ra;la.v*=va;oa.u*=ra;oa.v*=va;o(ja,U,W,aa,I,ca,G,ka.u,ka.v,ea.u,ea.v,oa.u,oa.v);o(ja,F,ba,Z,Q,ma,R,ea.u,ea.v,la.u,la.v,oa.u,oa.v)}else if(A instanceof THREE.MeshBasicMaterial)d(U,W,aa,I,Z,Q,ca,G,A.color,A.wireframe,A.wireframe_linewidth);
else if(A instanceof THREE.MeshLambertMaterial){if(Ea){ga.r=na.r;ga.g=na.g;ga.b=na.b;a($,Y,ga);X.r=A.color.r*ga.r;X.g=A.color.g*ga.g;X.b=A.color.b*ga.b;X.updateStyleString()}else X.__styleString=A.color.__styleString;d(U,W,aa,I,Z,Q,ca,G,X,A.wireframe,A.wireframe_linewidth)}else if(A instanceof THREE.MeshDepthMaterial){K=A.__2near;da=A.__farPlusNear;ia=A.__farMinusNear;h=~~((1-K/(da-J.positionScreen.z*ia))*255);t=~~((1-K/(da-S.positionScreen.z*ia))*255);x=~~((1-K/(da-M.positionScreen.z*ia))*255);D=
~~((1-K/(da-N.positionScreen.z*ia))*255);ja=k([h,h,h],[t,t,t],[D,D,D],[x,x,x]);ka.u=0;ka.v=0;ea.u=sa;ea.v=0;la.u=sa;la.v=sa;oa.u=0;oa.v=sa;o(ja,U,W,aa,I,ca,G,ka.u,ka.v,ea.u,ea.v,oa.u,oa.v);o(ja,F,ba,Z,Q,ma,R,ea.u,ea.v,la.u,la.v,oa.u,oa.v)}else if(A instanceof THREE.MeshNormalMaterial){X.r=e(Y.normalWorld.x);X.g=e(Y.normalWorld.y);X.b=e(Y.normalWorld.z);X.updateStyleString();d(U,W,aa,I,Z,Q,ca,G,X,A.wireframe,A.wireframe_linewidth)}}function c(J,S,M,N,u,L,Y,A,$){j.beginPath();j.moveTo(J,S);j.lineTo(M,
N);j.lineTo(u,L);j.lineTo(J,S);j.closePath();if(A){if(V!=$)j.lineWidth=V=$;if(B!=Y.__styleString)j.strokeStyle=B=Y.__styleString;j.stroke();fa.inflate($*2)}else{if(C!=Y.__styleString)j.fillStyle=C=Y.__styleString;j.fill()}}function d(J,S,M,N,u,L,Y,A,$,H,ha){j.beginPath();j.moveTo(J,S);j.lineTo(M,N);j.lineTo(u,L);j.lineTo(Y,A);j.lineTo(J,S);j.closePath();if(H){if(V!=ha)j.lineWidth=V=ha;if(B!=$.__styleString)j.strokeStyle=B=$.__styleString;j.stroke();fa.inflate(ha*2)}else{if(C!=$.__styleString)j.fillStyle=
C=$.__styleString;j.fill()}}function o(J,S,M,N,u,L,Y,A,$,H,ha,ta,wa){j.beginPath();j.moveTo(S,M);j.lineTo(N,u);j.lineTo(L,Y);j.closePath();N-=S;u-=M;L-=S;Y-=M;H-=A;ha-=$;ta-=A;wa-=$;var xa=1/(H*wa-ta*ha),Aa=(wa*N-ha*L)*xa;ha=(wa*u-ha*Y)*xa;N=(H*L-ta*N)*xa;u=(H*Y-ta*u)*xa;S=S-Aa*A-N*$;M=M-ha*A-u*$;j.save();j.transform(Aa,ha,N,u,S,M);j.clip();j.drawImage(J,0,0);j.restore()}function q(J){switch(J){case 0:j.globalCompositeOperation="source-over";break;case 1:j.globalCompositeOperation="lighter";break;
case 2:j.globalCompositeOperation="darker"}i=J}function k(J,S,M,N){pa[0]=J[0];pa[1]=J[1];pa[2]=J[2];pa[4]=S[0];pa[5]=S[1];pa[6]=S[2];pa[8]=M[0];pa[9]=M[1];pa[10]=M[2];pa[12]=N[0];pa[13]=N[1];pa[14]=N[2];Ba.putImageData(Ia,0,0);Fa.drawImage(Ca,0,0);return Da}function e(J){return J<0?Math.min((1+J)*0.5,0.5):0.5+Math.min(J*0.5,0.5)}function g(J,S){var M=S.x-J.x,N=S.y-J.y,u=1/Math.sqrt(M*M+N*N);M*=u;N*=u;S.x+=M;S.y+=N;J.x-=M;J.y-=N}var m=null,r=new THREE.Projector,l=document.createElement("canvas"),s,
p,n,y,j=l.getContext("2d"),v=1,i=0,B=null,C=null,V=1,w,E,z,T,O=new THREE.Vertex,P=new THREE.Vertex,U,W,aa,I,Z,Q,ca,G,F,ba,ma,R,h,t,x,D,K,da,ia,ja,ra,va,ua=new THREE.Rectangle,qa=new THREE.Rectangle,fa=new THREE.Rectangle,Ea=false,X=new THREE.Color(4294967295),ga=new THREE.Color(4294967295),na=new THREE.Color(4278190080),ya=new THREE.Color(4278190080),za=new THREE.Color(4278190080),Ma=Math.PI*2,Ha=new THREE.Vector3,ka=new THREE.UV,ea=new THREE.UV,la=new THREE.UV,oa=new THREE.UV,Ca,Ba,Ia,pa,Da,Fa,sa=
16;Ca=document.createElement("canvas");Ca.width=Ca.height=2;Ba=Ca.getContext("2d");Ba.fillStyle="rgba(0,0,0,1)";Ba.fillRect(0,0,2,2);Ia=Ba.getImageData(0,0,2,2);pa=Ia.data;Da=document.createElement("canvas");Da.width=Da.height=sa;Fa=Da.getContext("2d");Fa.translate(-sa/2,-sa/2);Fa.scale(sa,sa);sa--;this.domElement=l;this.autoClear=true;this.setSize=function(J,S){s=J;p=S;n=s/2;y=p/2;l.width=s;l.height=p;j.lineJoin="round";j.lineCap="round";ua.set(-n,-y,n,y)};this.clear=function(){if(!qa.isEmpty()){qa.inflate(1);
qa.minSelf(ua);j.setTransform(1,0,0,-1,n,y);j.clearRect(qa.getX(),qa.getY(),qa.getWidth(),qa.getHeight());qa.empty()}};this.render=function(J,S){var M,N,u,L,Y,A,$,H;this.autoClear&&this.clear();m=r.projectScene(J,S);j.setTransform(1,0,0,-1,n,y);j.fillStyle="rgba(0, 255, 255, 0.5)";j.fillRect(ua.getX(),ua.getY(),ua.getWidth(),ua.getHeight());if(Ea=J.lights.length>0){Y=J.lights;na.setRGBA(0,0,0,1);ya.setRGBA(0,0,0,1);za.setRGBA(0,0,0,1);M=0;for(N=Y.length;M<N;M++){u=Y[M];L=u.color;if(u instanceof THREE.AmbientLight){na.r+=
L.r;na.g+=L.g;na.b+=L.b}else if(u instanceof THREE.DirectionalLight){ya.r+=L.r;ya.g+=L.g;ya.b+=L.b}else if(u instanceof THREE.PointLight){za.r+=L.r;za.g+=L.g;za.b+=L.b}}}M=0;for(N=m.length;M<N;M++){u=m[M];fa.empty();if(u instanceof THREE.RenderableParticle){w=u;w.x*=n;w.y*=y;L=0;for(Y=u.material.length;L<Y;L++)if(H=u.material[L]){A=w;$=u;H=H;var ha=void 0,ta=void 0,wa=void 0,xa=void 0,Aa=void 0,Ja=void 0,Ga=void 0,Ka=void 0,La=void 0;if(H.opacity!=v)j.globalAlpha=v=H.opacity;H.blending!=i&&q(H.blending);
if(H instanceof THREE.ParticleBasicMaterial){Ga=H.bitmap;Ka=Ga.width/2;La=Ga.height/2;wa=$.scale.x*n;xa=$.scale.y*y;ha=wa*Ka;ta=xa*La;Aa=H.offset.x*wa;Ja=H.offset.y*xa;fa.set(A.x+Aa-ha,A.y+Ja-ta,A.x+Aa+ha,A.y+Ja+ta);if(ua.instersects(fa)){j.save();j.translate(A.x,A.y);j.rotate(-$.rotation);j.scale(wa,-xa);j.translate(-Ka+H.offset.x,-La-H.offset.y);j.drawImage(Ga,0,0);j.restore();j.beginPath();j.moveTo(A.x-10,A.y);j.lineTo(A.x+10,A.y);j.moveTo(A.x,A.y-10);j.lineTo(A.x,A.y+10);j.closePath();j.strokeStyle=
"rgb(255,255,0)";j.stroke()}}else if(H instanceof THREE.ParticleCircleMaterial){if(Ea){ga.r=na.r+ya.r+za.r;ga.g=na.g+ya.g+za.g;ga.b=na.b+ya.b+za.b;X.r=H.color.r*ga.r;X.g=H.color.g*ga.g;X.b=H.color.b*ga.b;X.updateStyleString()}else X.__styleString=H.color.__styleString;ha=$.scale.x*n;ta=$.scale.y*y;fa.set(A.x-ha,A.y-ta,A.x+ha,A.y+ta);if(ua.instersects(fa)){if(C!==X.__styleString)j.fillStyle=C=X.__styleString;j.save();j.translate(A.x,A.y);j.rotate(-$.rotation);j.scale(ha,ta);j.beginPath();j.arc(0,0,
1,0,Ma,true);j.closePath();j.fill();j.restore()}}}}else if(u instanceof THREE.RenderableLine){w=u.v1;E=u.v2;w.positionScreen.x*=n;w.positionScreen.y*=y;E.positionScreen.x*=n;E.positionScreen.y*=y;fa.addPoint(w.positionScreen.x,w.positionScreen.y);fa.addPoint(E.positionScreen.x,E.positionScreen.y);if(!ua.instersects(fa))continue;L=0;for(Y=u.material.length;L<Y;)if(H=u.material[L++]){A=w;$=E;H=H;if(H.opacity!=v)j.globalAlpha=v=H.opacity;H.blending!=i&&q(H.blending);j.beginPath();j.moveTo(A.positionScreen.x,
A.positionScreen.y);j.lineTo($.positionScreen.x,$.positionScreen.y);j.closePath();if(H instanceof THREE.LineBasicMaterial){X.__styleString=H.color.__styleString;if(V!=H.linewidth)j.lineWidth=V=H.linewidth;if(B!=X.__styleString)j.strokeStyle=B=X.__styleString;j.stroke();fa.inflate(H.linewidth*2)}}}else if(u instanceof THREE.RenderableFace3){w=u.v1;E=u.v2;z=u.v3;w.positionScreen.x*=n;w.positionScreen.y*=y;E.positionScreen.x*=n;E.positionScreen.y*=y;z.positionScreen.x*=n;z.positionScreen.y*=y;if(u.overdraw){g(w.positionScreen,
E.positionScreen);g(E.positionScreen,z.positionScreen);g(z.positionScreen,w.positionScreen)}fa.addPoint(w.positionScreen.x,w.positionScreen.y);fa.addPoint(E.positionScreen.x,E.positionScreen.y);fa.addPoint(z.positionScreen.x,z.positionScreen.y);if(!ua.instersects(fa))continue;L=0;for(Y=u.meshMaterial.length;L<Y;){H=u.meshMaterial[L++];if(H instanceof THREE.MeshFaceMaterial){A=0;for($=u.faceMaterial.length;A<$;)(H=u.faceMaterial[A++])&&b(w,E,z,u,H,J)}else H&&b(w,E,z,u,H,J)}}else if(u instanceof THREE.RenderableFace4){w=
u.v1;E=u.v2;z=u.v3;T=u.v4;w.positionScreen.x*=n;w.positionScreen.y*=y;E.positionScreen.x*=n;E.positionScreen.y*=y;z.positionScreen.x*=n;z.positionScreen.y*=y;T.positionScreen.x*=n;T.positionScreen.y*=y;O.positionScreen.copy(E.positionScreen);P.positionScreen.copy(T.positionScreen);if(u.overdraw){g(w.positionScreen,E.positionScreen);g(E.positionScreen,T.positionScreen);g(T.positionScreen,w.positionScreen)}if(u.overdraw){g(z.positionScreen,O.positionScreen);g(z.positionScreen,P.positionScreen)}fa.addPoint(w.positionScreen.x,
w.positionScreen.y);fa.addPoint(E.positionScreen.x,E.positionScreen.y);fa.addPoint(z.positionScreen.x,z.positionScreen.y);fa.addPoint(T.positionScreen.x,T.positionScreen.y);if(!ua.instersects(fa))continue;L=0;for(Y=u.meshMaterial.length;L<Y;){H=u.meshMaterial[L++];if(H instanceof THREE.MeshFaceMaterial){A=0;for($=u.faceMaterial.length;A<$;)(H=u.faceMaterial[A++])&&f(w,E,z,T,O,P,u,H,J)}else H&&f(w,E,z,T,O,P,u,H,J)}}qa.addRectangle(fa)}j.lineWidth=1;j.strokeStyle="rgba( 255, 0, 0, 0.5 )";j.strokeRect(qa.getX(),
qa.getY(),qa.getWidth(),qa.getHeight());j.setTransform(1,0,0,1,0,0)}};
THREE.SVGRenderer=function(){function a(I,Z,Q){var ca,G,F,ba;ca=0;for(G=I.lights.length;ca<G;ca++){F=I.lights[ca];if(F instanceof THREE.DirectionalLight){ba=Z.normalWorld.dot(F.position)*F.intensity;if(ba>0){Q.r+=F.color.r*ba;Q.g+=F.color.g*ba;Q.b+=F.color.b*ba}}else if(F instanceof THREE.PointLight){z.sub(F.position,Z.centroidWorld);z.normalize();ba=Z.normalWorld.dot(z)*F.intensity;if(ba>0){Q.r+=F.color.r*ba;Q.g+=F.color.g*ba;Q.b+=F.color.b*ba}}}}function b(I,Z,Q,ca,G,F){P=c(U++);P.setAttribute("d",
"M "+I.positionScreen.x+" "+I.positionScreen.y+" L "+Z.positionScreen.x+" "+Z.positionScreen.y+" L "+Q.positionScreen.x+","+Q.positionScreen.y+"z");if(G instanceof THREE.MeshBasicMaterial)i.__styleString=G.color.__styleString;else if(G instanceof THREE.MeshLambertMaterial)if(v){B.r=C.r;B.g=C.g;B.b=C.b;a(F,ca,B);i.r=G.color.r*B.r;i.g=G.color.g*B.g;i.b=G.color.b*B.b;i.updateStyleString()}else i.__styleString=G.color.__styleString;else if(G instanceof THREE.MeshDepthMaterial){E=1-G.__2near/(G.__farPlusNear-
ca.z*G.__farMinusNear);i.setRGBA(E,E,E,1)}else G instanceof THREE.MeshNormalMaterial&&i.setRGBA(d(ca.normalWorld.x),d(ca.normalWorld.y),d(ca.normalWorld.z),1);G.wireframe?P.setAttribute("style","fill: none; stroke: "+i.__styleString+"; stroke-width: "+G.wireframe_linewidth+"; stroke-opacity: "+G.opacity+"; stroke-linecap: round; stroke-linejoin: round"):P.setAttribute("style","fill: "+i.__styleString+"; fill-opacity: "+G.opacity);k.appendChild(P)}function f(I,Z,Q,ca,G,F,ba){P=c(U++);P.setAttribute("d",
"M "+I.positionScreen.x+" "+I.positionScreen.y+" L "+Z.positionScreen.x+" "+Z.positionScreen.y+" L "+Q.positionScreen.x+","+Q.positionScreen.y+" L "+ca.positionScreen.x+","+ca.positionScreen.y+"z");if(F instanceof THREE.MeshBasicMaterial)i.__styleString=F.color.__styleString;else if(F instanceof THREE.MeshLambertMaterial)if(v){B.r=C.r;B.g=C.g;B.b=C.b;a(ba,G,B);i.r=F.color.r*B.r;i.g=F.color.g*B.g;i.b=F.color.b*B.b;i.updateStyleString()}else i.__styleString=F.color.__styleString;else if(F instanceof
THREE.MeshDepthMaterial){E=1-F.__2near/(F.__farPlusNear-G.z*F.__farMinusNear);i.setRGBA(E,E,E,1)}else F instanceof THREE.MeshNormalMaterial&&i.setRGBA(d(G.normalWorld.x),d(G.normalWorld.y),d(G.normalWorld.z),1);F.wireframe?P.setAttribute("style","fill: none; stroke: "+i.__styleString+"; stroke-width: "+F.wireframe_linewidth+"; stroke-opacity: "+F.opacity+"; stroke-linecap: round; stroke-linejoin: round"):P.setAttribute("style","fill: "+i.__styleString+"; fill-opacity: "+F.opacity);k.appendChild(P)}
function c(I){if(T[I]==null){T[I]=document.createElementNS("http://www.w3.org/2000/svg","path");aa==0&&T[I].setAttribute("shape-rendering","crispEdges");return T[I]}return T[I]}function d(I){return I<0?Math.min((1+I)*0.5,0.5):0.5+Math.min(I*0.5,0.5)}var o=null,q=new THREE.Projector,k=document.createElementNS("http://www.w3.org/2000/svg","svg"),e,g,m,r,l,s,p,n,y=new THREE.Rectangle,j=new THREE.Rectangle,v=false,i=new THREE.Color(4294967295),B=new THREE.Color(4294967295),C=new THREE.Color(4278190080),
V=new THREE.Color(4278190080),w=new THREE.Color(4278190080),E,z=new THREE.Vector3,T=[],O=[],P,U,W,aa=1;this.domElement=k;this.autoClear=true;this.setQuality=function(I){switch(I){case "high":aa=1;break;case "low":aa=0}};this.setSize=function(I,Z){e=I;g=Z;m=e/2;r=g/2;k.setAttribute("viewBox",-m+" "+-r+" "+e+" "+g);k.setAttribute("width",e);k.setAttribute("height",g);y.set(-m,-r,m,r)};this.clear=function(){for(;k.childNodes.length>0;)k.removeChild(k.childNodes[0])};this.render=function(I,Z){var Q,ca,
G,F,ba,ma,R,h;this.autoClear&&this.clear();o=q.projectScene(I,Z);W=U=0;if(v=I.lights.length>0){R=I.lights;C.setRGBA(0,0,0,1);V.setRGBA(0,0,0,1);w.setRGBA(0,0,0,1);Q=0;for(ca=R.length;Q<ca;Q++){G=R[Q];F=G.color;if(G instanceof THREE.AmbientLight){C.r+=F.r;C.g+=F.g;C.b+=F.b}else if(G instanceof THREE.DirectionalLight){V.r+=F.r;V.g+=F.g;V.b+=F.b}else if(G instanceof THREE.PointLight){w.r+=F.r;w.g+=F.g;w.b+=F.b}}}Q=0;for(ca=o.length;Q<ca;Q++){R=o[Q];j.empty();if(R instanceof THREE.RenderableParticle){l=
R;l.x*=m;l.y*=-r;G=0;for(F=R.material.length;G<F;G++)if(h=R.material[G]){ba=l;ma=R;h=h;var t=W++;if(O[t]==null){O[t]=document.createElementNS("http://www.w3.org/2000/svg","circle");aa==0&&O[t].setAttribute("shape-rendering","crispEdges")}P=O[t];P.setAttribute("cx",ba.x);P.setAttribute("cy",ba.y);P.setAttribute("r",ma.scale.x*m);if(h instanceof THREE.ParticleCircleMaterial){if(v){B.r=C.r+V.r+w.r;B.g=C.g+V.g+w.g;B.b=C.b+V.b+w.b;i.r=h.color.r*B.r;i.g=h.color.g*B.g;i.b=h.color.b*B.b;i.updateStyleString()}else i=
h.color;P.setAttribute("style","fill: "+i.__styleString)}k.appendChild(P)}}else if(R instanceof THREE.RenderableFace3){l=R.v1;s=R.v2;p=R.v3;l.positionScreen.x*=m;l.positionScreen.y*=-r;s.positionScreen.x*=m;s.positionScreen.y*=-r;p.positionScreen.x*=m;p.positionScreen.y*=-r;j.addPoint(l.positionScreen.x,l.positionScreen.y);j.addPoint(s.positionScreen.x,s.positionScreen.y);j.addPoint(p.positionScreen.x,p.positionScreen.y);if(y.instersects(j)){G=0;for(F=R.meshMaterial.length;G<F;){h=R.meshMaterial[G++];
if(h instanceof THREE.MeshFaceMaterial){ba=0;for(ma=R.faceMaterial.length;ba<ma;)(h=R.faceMaterial[ba++])&&b(l,s,p,R,h,I)}else h&&b(l,s,p,R,h,I)}}}else if(R instanceof THREE.RenderableFace4){l=R.v1;s=R.v2;p=R.v3;n=R.v4;l.positionScreen.x*=m;l.positionScreen.y*=-r;s.positionScreen.x*=m;s.positionScreen.y*=-r;p.positionScreen.x*=m;p.positionScreen.y*=-r;n.positionScreen.x*=m;n.positionScreen.y*=-r;j.addPoint(l.positionScreen.x,l.positionScreen.y);j.addPoint(s.positionScreen.x,s.positionScreen.y);j.addPoint(p.positionScreen.x,
p.positionScreen.y);j.addPoint(n.positionScreen.x,n.positionScreen.y);if(y.instersects(j)){G=0;for(F=R.meshMaterial.length;G<F;){h=R.meshMaterial[G++];if(h instanceof THREE.MeshFaceMaterial){ba=0;for(ma=R.faceMaterial.length;ba<ma;)(h=R.faceMaterial[ba++])&&f(l,s,p,n,R,h,I)}else h&&f(l,s,p,n,R,h,I)}}}}}};
THREE.WebGLRenderer=function(a){function b(e,g){var m;if(e=="fragment")m=c.createShader(c.FRAGMENT_SHADER);else if(e=="vertex")m=c.createShader(c.VERTEX_SHADER);c.shaderSource(m,g);c.compileShader(m);if(!c.getShaderParameter(m,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(m));return null}return m}var f=document.createElement("canvas"),c,d,o=new THREE.Matrix4,q;a=function(e,g){if(e){var m,r,l,s=pointLights=maxDirLights=maxPointLights=0;m=0;for(r=e.lights.length;m<r;m++){l=e.lights[m];l instanceof THREE.DirectionalLight&&
s++;l instanceof THREE.PointLight&&pointLights++}if(pointLights+s<=g){maxDirLights=s;maxPointLights=pointLights}else{maxDirLights=Math.ceil(g*s/(pointLights+s));maxPointLights=g-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:g-1}}(a,5);this.domElement=f;this.autoClear=true;try{c=f.getContext("experimental-webgl",{antialias:true})}catch(k){}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(0,0,0,0);(function(e,g){d=c.createProgram();c.attachShader(d,b("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 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;\nvoid main() {\nvec4 mapColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nif ( enableMap ) {\nmapColor = texture2D( tMap, vUv );\n}\nif ( 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 < pointLightNumber; 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 < directionalLightNumber; 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;":
"","gl_FragColor = vec4( mapColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );\n} else if ( material == 1 ) {\ngl_FragColor = vec4( mColor.rgb * mapColor.rgb * vLightWeighting, mColor.a * mapColor.a );\n} else {\ngl_FragColor = mColor * mapColor;\n}\n}"].join("\n")));c.attachShader(d,b("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 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 vFragPosition;\nvoid main(void) {\nvec4 mPosition = objMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\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 < directionalLightNumber; 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 < pointLightNumber; 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;\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n")));c.linkProgram(d);c.getProgramParameter(d,c.LINK_STATUS)||alert("Could not initialise shaders");c.useProgram(d);d.viewMatrix=c.getUniformLocation(d,"viewMatrix");d.modelViewMatrix=c.getUniformLocation(d,"modelViewMatrix");d.projectionMatrix=c.getUniformLocation(d,"projectionMatrix");d.normalMatrix=c.getUniformLocation(d,
"normalMatrix");d.objMatrix=c.getUniformLocation(d,"objMatrix");d.cameraPosition=c.getUniformLocation(d,"cameraPosition");d.enableLighting=c.getUniformLocation(d,"enableLighting");d.ambientLightColor=c.getUniformLocation(d,"ambientLightColor");if(e){d.directionalLightNumber=c.getUniformLocation(d,"directionalLightNumber");d.directionalLightColor=c.getUniformLocation(d,"directionalLightColor");d.directionalLightDirection=c.getUniformLocation(d,"directionalLightDirection")}if(g){d.pointLightNumber=
c.getUniformLocation(d,"pointLightNumber");d.pointLightColor=c.getUniformLocation(d,"pointLightColor");d.pointLightPosition=c.getUniformLocation(d,"pointLightPosition")}d.material=c.getUniformLocation(d,"material");d.mColor=c.getUniformLocation(d,"mColor");d.mOpacity=c.getUniformLocation(d,"mOpacity");d.mAmbient=c.getUniformLocation(d,"mAmbient");d.mSpecular=c.getUniformLocation(d,"mSpecular");d.mShininess=c.getUniformLocation(d,"mShininess");d.enableMap=c.getUniformLocation(d,"enableMap");c.uniform1i(d.enableMap,
0);d.tMap=c.getUniformLocation(d,"tMap");c.uniform1i(d.tMap,0);d.m2Near=c.getUniformLocation(d,"m2Near");d.mFarPlusNear=c.getUniformLocation(d,"mFarPlusNear");d.mFarMinusNear=c.getUniformLocation(d,"mFarMinusNear");d.position=c.getAttribLocation(d,"position");c.enableVertexAttribArray(d.position);d.normal=c.getAttribLocation(d,"normal");c.enableVertexAttribArray(d.normal);d.uv=c.getAttribLocation(d,"uv");c.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){f.width=e;f.height=g;c.viewport(0,0,f.width,f.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(e){var g,m,r,l,s=[],p=[],n=[];l=[];var y=[];c.uniform1i(d.enableLighting,e.lights.length);g=0;for(m=e.lights.length;g<m;g++){r=e.lights[g];if(r instanceof THREE.AmbientLight)s.push(r);else if(r instanceof THREE.DirectionalLight)n.push(r);
else r instanceof THREE.PointLight&&p.push(r)}g=e=r=l=0;for(m=s.length;g<m;g++){e+=s[g].color.r;r+=s[g].color.g;l+=s[g].color.b}c.uniform3f(d.ambientLightColor,e,r,l);l=[];y=[];g=0;for(m=n.length;g<m;g++){r=n[g];l.push(r.color.r*r.intensity);l.push(r.color.g*r.intensity);l.push(r.color.b*r.intensity);y.push(r.position.x);y.push(r.position.y);y.push(r.position.z)}if(n.length){c.uniform1i(d.directionalLightNumber,n.length);c.uniform3fv(d.directionalLightDirection,y);c.uniform3fv(d.directionalLightColor,
l)}l=[];y=[];g=0;for(m=p.length;g<m;g++){r=p[g];l.push(r.color.r*r.intensity);l.push(r.color.g*r.intensity);l.push(r.color.b*r.intensity);y.push(r.position.x);y.push(r.position.y);y.push(r.position.z)}if(p.length){c.uniform1i(d.pointLightNumber,p.length);c.uniform3fv(d.pointLightPosition,y);c.uniform3fv(d.pointLightColor,l)}};this.createBuffers=function(e,g){var m,r,l,s,p,n,y,j,v,i=e.materialFaceGroup[g],B=[],C=[],V=[],w=[],E=[],z=0;m=0;for(r=i.faces.length;m<r;m++){l=i.faces[m];s=e.geometry.faces[l];
p=s.vertexNormals;n=s.normal;l=e.geometry.uvs[l];if(s instanceof THREE.Face3){y=e.geometry.vertices[s.a].position;j=e.geometry.vertices[s.b].position;v=e.geometry.vertices[s.c].position;V.push(y.x,y.y,y.z);V.push(j.x,j.y,j.z);V.push(v.x,v.y,v.z);if(p.length==3){w.push(p[0].x,p[0].y,p[0].z);w.push(p[1].x,p[1].y,p[1].z);w.push(p[2].x,p[2].y,p[2].z)}else{w.push(n.x,n.y,n.z);w.push(n.x,n.y,n.z);w.push(n.x,n.y,n.z)}if(l){E.push(l[0].u,l[0].v);E.push(l[1].u,l[1].v);E.push(l[2].u,l[2].v)}B.push(z,z+1,z+
2);C.push(z,z+1);C.push(z,z+2);C.push(z+1,z+2);z+=3}else if(s instanceof THREE.Face4){y=e.geometry.vertices[s.a].position;j=e.geometry.vertices[s.b].position;v=e.geometry.vertices[s.c].position;s=e.geometry.vertices[s.d].position;V.push(y.x,y.y,y.z);V.push(j.x,j.y,j.z);V.push(v.x,v.y,v.z);V.push(s.x,s.y,s.z);if(p.length==4){w.push(p[0].x,p[0].y,p[0].z);w.push(p[1].x,p[1].y,p[1].z);w.push(p[2].x,p[2].y,p[2].z);w.push(p[3].x,p[3].y,p[3].z)}else{w.push(n.x,n.y,n.z);w.push(n.x,n.y,n.z);w.push(n.x,n.y,
n.z);w.push(n.x,n.y,n.z)}if(l){E.push(l[0].u,l[0].v);E.push(l[1].u,l[1].v);E.push(l[2].u,l[2].v);E.push(l[3].u,l[3].v)}B.push(z,z+1,z+2);B.push(z,z+2,z+3);C.push(z,z+1);C.push(z,z+2);C.push(z,z+3);C.push(z+1,z+2);C.push(z+2,z+3);z+=4}}if(V.length){i.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,i.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(V),c.STATIC_DRAW);i.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,i.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,
new Float32Array(w),c.STATIC_DRAW);i.__webGLUVBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,i.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(E),c.STATIC_DRAW);i.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,i.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(B),c.STATIC_DRAW);i.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,i.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(C),c.STATIC_DRAW);
i.__webGLFaceCount=B.length;i.__webGLLineCount=C.length}};this.renderBuffer=function(e,g){var m,r,l,s,p,n,y;if(e instanceof THREE.MeshPhongMaterial||e instanceof THREE.MeshLambertMaterial||e instanceof THREE.MeshBasicMaterial){m=e.color;r=e.opacity;l=e.wireframe;s=e.wireframe_linewidth;y=e.map;c.uniform4f(d.mColor,m.r*r,m.g*r,m.b*r,r)}if(e instanceof THREE.MeshNormalMaterial){r=e.opacity;c.uniform1f(d.mOpacity,r);c.uniform1i(d.material,4)}else if(e instanceof THREE.MeshDepthMaterial){r=e.opacity;
l=e.wireframe;s=e.wireframe_linewidth;c.uniform1f(d.mOpacity,r);c.uniform1f(d.m2Near,e.__2near);c.uniform1f(d.mFarPlusNear,e.__farPlusNear);c.uniform1f(d.mFarMinusNear,e.__farMinusNear);c.uniform1i(d.material,3)}else if(e instanceof THREE.MeshPhongMaterial){m=e.ambient;p=e.specular;n=e.shininess;c.uniform4f(d.mAmbient,m.r,m.g,m.b,r);c.uniform4f(d.mSpecular,p.r,p.g,p.b,r);c.uniform1f(d.mShininess,n);c.uniform1i(d.material,2)}else if(e instanceof THREE.MeshLambertMaterial)c.uniform1i(d.material,1);
else e instanceof THREE.MeshBasicMaterial&&c.uniform1i(d.material,0);if(y){if(!e.__webGLTexture&&e.map.loaded){e.__webGLTexture=c.createTexture();c.bindTexture(c.TEXTURE_2D,e.__webGLTexture);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,e.map.image);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);c.generateMipmap(c.TEXTURE_2D);c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0);c.bindTexture(c.TEXTURE_2D,
e.__webGLTexture);c.uniform1i(d.tMap,0);c.uniform1i(d.enableMap,1)}else c.uniform1i(d.enableMap,0);c.bindBuffer(c.ARRAY_BUFFER,g.__webGLVertexBuffer);c.vertexAttribPointer(d.position,3,c.FLOAT,false,0,0);c.bindBuffer(c.ARRAY_BUFFER,g.__webGLNormalBuffer);c.vertexAttribPointer(d.normal,3,c.FLOAT,false,0,0);if(y){c.bindBuffer(c.ARRAY_BUFFER,g.__webGLUVBuffer);c.enableVertexAttribArray(d.uv);c.vertexAttribPointer(d.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(d.uv);if(l){c.lineWidth(s);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,
g.__webGLLineBuffer);c.drawElements(c.LINES,g.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,g.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,g.__webGLFaceCount,c.UNSIGNED_SHORT,0)}};this.renderMesh=function(e){var g,m,r,l,s,p,n;for(s in e.materialFaceGroup){n=e.materialFaceGroup[s];n.__webGLVertexBuffer||this.createBuffers(e,s);r=0;for(l=e.material.length;r<l;r++){g=e.material[r];if(g instanceof THREE.MeshFaceMaterial){g=0;for(m=n.material.length;g<m;g++){p=n.material[g];
this.renderBuffer(p,n)}}else{p=g;this.renderBuffer(p,n)}}}};this.setupMatrices=function(e,g){e.autoUpdateMatrix&&e.updateMatrix();o.multiply(g.matrix,e.matrix);d.viewMatrixArray=new Float32Array(g.matrix.flatten());d.modelViewMatrixArray=new Float32Array(o.flatten());d.projectionMatrixArray=new Float32Array(g.projectionMatrix.flatten());q=THREE.Matrix4.makeInvert3x3(o).transpose();d.normalMatrixArray=new Float32Array(q.m);c.uniformMatrix4fv(d.viewMatrix,false,d.viewMatrixArray);c.uniformMatrix4fv(d.modelViewMatrix,
false,d.modelViewMatrixArray);c.uniformMatrix4fv(d.projectionMatrix,false,d.projectionMatrixArray);c.uniformMatrix3fv(d.normalMatrix,false,d.normalMatrixArray);c.uniformMatrix4fv(d.objMatrix,false,new Float32Array(e.matrix.flatten()))};this.render=function(e,g){var m,r,l;this.autoClear&&this.clear();g.autoUpdateMatrix&&g.updateMatrix();c.uniform3f(d.cameraPosition,g.position.x,g.position.y,g.position.z);this.setupLights(e);m=0;for(r=e.objects.length;m<r;m++){l=e.objects[m];this.setupMatrices(l,g);
l instanceof THREE.Mesh&&this.renderMesh(l,g)}};this.setFaceCulling=function(e,g){if(e){!g||g=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(e=="back")c.cullFace(c.BACK);else e=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.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};