diff --git a/build/Three.js b/build/Three.js index e127edc7..415a15b8 100644 --- a/build/Three.js +++ b/build/Three.js @@ -16,34 +16,34 @@ subSelf:function(b){this.x-=b.x;this.y-=b.y;this.z-=b.z;this.w-=b.w;return this} setLength:function(b){return this.normalize().multiplyScalar(b)},lerpSelf:function(b,c){this.x+=(b.x-this.x)*c;this.y+=(b.y-this.y)*c;this.z+=(b.z-this.z)*c;this.w+=(b.w-this.w)*c;return this}};THREE.Ray=function(b,c){this.origin=b||new THREE.Vector3;this.direction=c||new THREE.Vector3}; THREE.Ray.prototype={constructor:THREE.Ray,intersectScene:function(b){return this.intersectObjects(b.objects)},intersectObjects:function(b){var c,e,f=[];c=0;for(e=b.length;c0&&b>0&&h+b<1}if(b instanceof THREE.Particle){var f=c(this.origin,this.direction,b);if(!f||f>b.scale.x)return[];return[{distance:f,point:b.position,face:null,object:b}]}else if(b instanceof THREE.Mesh){f=c(this.origin,this.direction,b);if(!f||f>b.geometry.boundingSphere.radius*Math.max(b.scale.x,Math.max(b.scale.y,b.scale.z)))return[];var g,j,h,m, -p,n,o,t,v,u,w=b.geometry,z=w.vertices,y=[],f=0;for(g=w.faces.length;f0:t<0))if(o=o.dot((new THREE.Vector3).sub(h, -v))/t,v=v.addSelf(u.multiplyScalar(o)),j instanceof THREE.Face3)e(v,h,m,p)&&(j={distance:this.origin.distanceTo(v),point:v,face:j,object:b},y.push(j));else if(j instanceof THREE.Face4&&(e(v,h,m,n)||e(v,m,p,n)))j={distance:this.origin.distanceTo(v),point:v,face:j,object:b},y.push(j);return y}else return[]}}; -THREE.Rectangle=function(){function b(){j=f-c;h=g-e}var c,e,f,g,j,h,m=!0;this.getX=function(){return c};this.getY=function(){return e};this.getWidth=function(){return j};this.getHeight=function(){return h};this.getLeft=function(){return c};this.getTop=function(){return e};this.getRight=function(){return f};this.getBottom=function(){return g};this.set=function(h,j,o,t){m=!1;c=h;e=j;f=o;g=t;b()};this.addPoint=function(h,j){m?(m=!1,c=h,e=j,f=h,g=j):(c=ch?f:h,g=g>j?g:j);b()};this.add3Points= -function(h,j,o,t,v,u){m?(m=!1,c=ho?h>v?h:v:o>v?o:v,g=j>t?j>u?j:u:t>u?t:u):(c=ho?h>v?h>f?h:f:v>f?v:f:o>v?o>f?o:f:v>f?v:f,g=j>t?j>u?j>g?j:g:u>g?u:g:t>u?t>g?t:g:u>g?u:g);b()};this.addRectangle=function(h){m?(m=!1,c=h.getLeft(),e=h.getTop(),f=h.getRight(),g=h.getBottom()):(c=ch.getRight()?f:h.getRight(),g=g> +o,n,p,t,v,u,w=b.geometry,z=w.vertices,x=[],f=0;for(g=w.faces.length;f0:t<0))if(p=p.dot((new THREE.Vector3).sub(h, +v))/t,v=v.addSelf(u.multiplyScalar(p)),j instanceof THREE.Face3)e(v,h,m,o)&&(j={distance:this.origin.distanceTo(v),point:v,face:j,object:b},x.push(j));else if(j instanceof THREE.Face4&&(e(v,h,m,n)||e(v,m,o,n)))j={distance:this.origin.distanceTo(v),point:v,face:j,object:b},x.push(j);return x}else return[]}}; +THREE.Rectangle=function(){function b(){j=f-c;h=g-e}var c,e,f,g,j,h,m=!0;this.getX=function(){return c};this.getY=function(){return e};this.getWidth=function(){return j};this.getHeight=function(){return h};this.getLeft=function(){return c};this.getTop=function(){return e};this.getRight=function(){return f};this.getBottom=function(){return g};this.set=function(h,j,p,t){m=!1;c=h;e=j;f=p;g=t;b()};this.addPoint=function(h,j){m?(m=!1,c=h,e=j,f=h,g=j):(c=ch?f:h,g=g>j?g:j);b()};this.add3Points= +function(h,j,p,t,v,u){m?(m=!1,c=hp?h>v?h:v:p>v?p:v,g=j>t?j>u?j:u:t>u?t:u):(c=hp?h>v?h>f?h:f:v>f?v:f:p>v?p>f?p:f:v>f?v:f,g=j>t?j>u?j>g?j:g:u>g?u:g:t>u?t>g?t:g:u>g?u:g);b()};this.addRectangle=function(h){m?(m=!1,c=h.getLeft(),e=h.getTop(),f=h.getRight(),g=h.getBottom()):(c=ch.getRight()?f:h.getRight(),g=g> h.getBottom()?g:h.getBottom());b()};this.inflate=function(h){c-=h;e-=h;f+=h;g+=h;b()};this.minSelf=function(h){c=c>h.getLeft()?c:h.getLeft();e=e>h.getTop()?e:h.getTop();f=f=0&&Math.min(g,b.getBottom())-Math.max(e,b.getTop())>=0};this.empty=function(){m=!0;g=f=e=c=0;b()};this.isEmpty=function(){return m}};THREE.Matrix3=function(){this.m=[]}; -THREE.Matrix3.prototype={constructor:THREE.Matrix3,transpose:function(){var b,c=this.m;b=c[1];c[1]=c[3];c[3]=b;b=c[2];c[2]=c[6];c[6]=b;b=c[5];c[5]=c[7];c[7]=b;return this},transposeIntoArray:function(b){var c=this.m;b[0]=c[0];b[1]=c[3];b[2]=c[6];b[3]=c[1];b[4]=c[4];b[5]=c[7];b[6]=c[2];b[7]=c[5];b[8]=c[8];return this}};THREE.Matrix4=function(b,c,e,f,g,j,h,m,p,n,o,t,v,u,w,z){this.set(b||1,c||0,e||0,f||0,g||0,j||1,h||0,m||0,p||0,n||0,o||1,t||0,v||0,u||0,w||0,z||1);this.flat=Array(16);this.m33=new THREE.Matrix3}; -THREE.Matrix4.prototype={constructor:THREE.Matrix4,set:function(b,c,e,f,g,j,h,m,p,n,o,t,v,u,w,z){this.n11=b;this.n12=c;this.n13=e;this.n14=f;this.n21=g;this.n22=j;this.n23=h;this.n24=m;this.n31=p;this.n32=n;this.n33=o;this.n34=t;this.n41=v;this.n42=u;this.n43=w;this.n44=z;return this},identity:function(){this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);return this},copy:function(b){this.set(b.n11,b.n12,b.n13,b.n14,b.n21,b.n22,b.n23,b.n24,b.n31,b.n32,b.n33,b.n34,b.n41,b.n42,b.n43,b.n44);return this},lookAt:function(b, +THREE.Matrix3.prototype={constructor:THREE.Matrix3,transpose:function(){var b,c=this.m;b=c[1];c[1]=c[3];c[3]=b;b=c[2];c[2]=c[6];c[6]=b;b=c[5];c[5]=c[7];c[7]=b;return this},transposeIntoArray:function(b){var c=this.m;b[0]=c[0];b[1]=c[3];b[2]=c[6];b[3]=c[1];b[4]=c[4];b[5]=c[7];b[6]=c[2];b[7]=c[5];b[8]=c[8];return this}};THREE.Matrix4=function(b,c,e,f,g,j,h,m,o,n,p,t,v,u,w,z){this.set(b||1,c||0,e||0,f||0,g||0,j||1,h||0,m||0,o||0,n||0,p||1,t||0,v||0,u||0,w||0,z||1);this.flat=Array(16);this.m33=new THREE.Matrix3}; +THREE.Matrix4.prototype={constructor:THREE.Matrix4,set:function(b,c,e,f,g,j,h,m,o,n,p,t,v,u,w,z){this.n11=b;this.n12=c;this.n13=e;this.n14=f;this.n21=g;this.n22=j;this.n23=h;this.n24=m;this.n31=o;this.n32=n;this.n33=p;this.n34=t;this.n41=v;this.n42=u;this.n43=w;this.n44=z;return this},identity:function(){this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);return this},copy:function(b){this.set(b.n11,b.n12,b.n13,b.n14,b.n21,b.n22,b.n23,b.n24,b.n31,b.n32,b.n33,b.n34,b.n41,b.n42,b.n43,b.n44);return this},lookAt:function(b, c,e){var f=THREE.Matrix4.__v1,g=THREE.Matrix4.__v2,j=THREE.Matrix4.__v3;j.sub(b,c).normalize();if(j.length()===0)j.z=1;f.cross(e,j).normalize();f.length()===0&&(j.x+=1.0E-4,f.cross(e,j).normalize());g.cross(j,f).normalize();this.n11=f.x;this.n12=g.x;this.n13=j.x;this.n21=f.y;this.n22=g.y;this.n23=j.y;this.n31=f.z;this.n32=g.z;this.n33=j.z;return this},multiplyVector3:function(b){var c=b.x,e=b.y,f=b.z,g=1/(this.n41*c+this.n42*e+this.n43*f+this.n44);b.x=(this.n11*c+this.n12*e+this.n13*f+this.n14)*g; b.y=(this.n21*c+this.n22*e+this.n23*f+this.n24)*g;b.z=(this.n31*c+this.n32*e+this.n33*f+this.n34)*g;return b},multiplyVector4:function(b){var c=b.x,e=b.y,f=b.z,g=b.w;b.x=this.n11*c+this.n12*e+this.n13*f+this.n14*g;b.y=this.n21*c+this.n22*e+this.n23*f+this.n24*g;b.z=this.n31*c+this.n32*e+this.n33*f+this.n34*g;b.w=this.n41*c+this.n42*e+this.n43*f+this.n44*g;return b},rotateAxis:function(b){var c=b.x,e=b.y,f=b.z;b.x=c*this.n11+e*this.n12+f*this.n13;b.y=c*this.n21+e*this.n22+f*this.n23;b.z=c*this.n31+ -e*this.n32+f*this.n33;b.normalize();return b},crossVector:function(b){var c=new THREE.Vector4;c.x=this.n11*b.x+this.n12*b.y+this.n13*b.z+this.n14*b.w;c.y=this.n21*b.x+this.n22*b.y+this.n23*b.z+this.n24*b.w;c.z=this.n31*b.x+this.n32*b.y+this.n33*b.z+this.n34*b.w;c.w=b.w?this.n41*b.x+this.n42*b.y+this.n43*b.z+this.n44*b.w:1;return c},multiply:function(b,c){var e=b.n11,f=b.n12,g=b.n13,j=b.n14,h=b.n21,m=b.n22,p=b.n23,n=b.n24,o=b.n31,t=b.n32,v=b.n33,u=b.n34,w=b.n41,z=b.n42,y=b.n43,x=b.n44,H=c.n11,B=c.n12, -F=c.n13,J=c.n14,D=c.n21,L=c.n22,G=c.n23,I=c.n24,R=c.n31,da=c.n32,T=c.n33,C=c.n34,ea=c.n41,S=c.n42,P=c.n43,k=c.n44;this.n11=e*H+f*D+g*R+j*ea;this.n12=e*B+f*L+g*da+j*S;this.n13=e*F+f*G+g*T+j*P;this.n14=e*J+f*I+g*C+j*k;this.n21=h*H+m*D+p*R+n*ea;this.n22=h*B+m*L+p*da+n*S;this.n23=h*F+m*G+p*T+n*P;this.n24=h*J+m*I+p*C+n*k;this.n31=o*H+t*D+v*R+u*ea;this.n32=o*B+t*L+v*da+u*S;this.n33=o*F+t*G+v*T+u*P;this.n34=o*J+t*I+v*C+u*k;this.n41=w*H+z*D+y*R+x*ea;this.n42=w*B+z*L+y*da+x*S;this.n43=w*F+z*G+y*T+x*P;this.n44= -w*J+z*I+y*C+x*k;return this},multiplyToArray:function(b,c,e){this.multiply(b,c);e[0]=this.n11;e[1]=this.n21;e[2]=this.n31;e[3]=this.n41;e[4]=this.n12;e[5]=this.n22;e[6]=this.n32;e[7]=this.n42;e[8]=this.n13;e[9]=this.n23;e[10]=this.n33;e[11]=this.n43;e[12]=this.n14;e[13]=this.n24;e[14]=this.n34;e[15]=this.n44;return this},multiplySelf:function(b){this.multiply(this,b);return this},multiplyScalar:function(b){this.n11*=b;this.n12*=b;this.n13*=b;this.n14*=b;this.n21*=b;this.n22*=b;this.n23*=b;this.n24*= -b;this.n31*=b;this.n32*=b;this.n33*=b;this.n34*=b;this.n41*=b;this.n42*=b;this.n43*=b;this.n44*=b;return this},determinant:function(){var b=this.n11,c=this.n12,e=this.n13,f=this.n14,g=this.n21,j=this.n22,h=this.n23,m=this.n24,p=this.n31,n=this.n32,o=this.n33,t=this.n34,v=this.n41,u=this.n42,w=this.n43,z=this.n44;return f*h*n*v-e*m*n*v-f*j*o*v+c*m*o*v+e*j*t*v-c*h*t*v-f*h*p*u+e*m*p*u+f*g*o*u-b*m*o*u-e*g*t*u+b*h*t*u+f*j*p*w-c*m*p*w-f*g*n*w+b*m*n*w+c*g*t*w-b*j*t*w-e*j*p*z+c*h*p*z+e*g*n*z-b*h*n*z-c*g* -o*z+b*j*o*z},transpose:function(){var b;b=this.n21;this.n21=this.n12;this.n12=b;b=this.n31;this.n31=this.n13;this.n13=b;b=this.n32;this.n32=this.n23;this.n23=b;b=this.n41;this.n41=this.n14;this.n14=b;b=this.n42;this.n42=this.n24;this.n24=b;b=this.n43;this.n43=this.n34;this.n43=b;return this},clone:function(){var b=new THREE.Matrix4;b.n11=this.n11;b.n12=this.n12;b.n13=this.n13;b.n14=this.n14;b.n21=this.n21;b.n22=this.n22;b.n23=this.n23;b.n24=this.n24;b.n31=this.n31;b.n32=this.n32;b.n33=this.n33;b.n34= +e*this.n32+f*this.n33;b.normalize();return b},crossVector:function(b){var c=new THREE.Vector4;c.x=this.n11*b.x+this.n12*b.y+this.n13*b.z+this.n14*b.w;c.y=this.n21*b.x+this.n22*b.y+this.n23*b.z+this.n24*b.w;c.z=this.n31*b.x+this.n32*b.y+this.n33*b.z+this.n34*b.w;c.w=b.w?this.n41*b.x+this.n42*b.y+this.n43*b.z+this.n44*b.w:1;return c},multiply:function(b,c){var e=b.n11,f=b.n12,g=b.n13,j=b.n14,h=b.n21,m=b.n22,o=b.n23,n=b.n24,p=b.n31,t=b.n32,v=b.n33,u=b.n34,w=b.n41,z=b.n42,x=b.n43,y=b.n44,H=c.n11,B=c.n12, +F=c.n13,J=c.n14,D=c.n21,L=c.n22,G=c.n23,I=c.n24,R=c.n31,da=c.n32,T=c.n33,C=c.n34,ea=c.n41,S=c.n42,P=c.n43,k=c.n44;this.n11=e*H+f*D+g*R+j*ea;this.n12=e*B+f*L+g*da+j*S;this.n13=e*F+f*G+g*T+j*P;this.n14=e*J+f*I+g*C+j*k;this.n21=h*H+m*D+o*R+n*ea;this.n22=h*B+m*L+o*da+n*S;this.n23=h*F+m*G+o*T+n*P;this.n24=h*J+m*I+o*C+n*k;this.n31=p*H+t*D+v*R+u*ea;this.n32=p*B+t*L+v*da+u*S;this.n33=p*F+t*G+v*T+u*P;this.n34=p*J+t*I+v*C+u*k;this.n41=w*H+z*D+x*R+y*ea;this.n42=w*B+z*L+x*da+y*S;this.n43=w*F+z*G+x*T+y*P;this.n44= +w*J+z*I+x*C+y*k;return this},multiplyToArray:function(b,c,e){this.multiply(b,c);e[0]=this.n11;e[1]=this.n21;e[2]=this.n31;e[3]=this.n41;e[4]=this.n12;e[5]=this.n22;e[6]=this.n32;e[7]=this.n42;e[8]=this.n13;e[9]=this.n23;e[10]=this.n33;e[11]=this.n43;e[12]=this.n14;e[13]=this.n24;e[14]=this.n34;e[15]=this.n44;return this},multiplySelf:function(b){this.multiply(this,b);return this},multiplyScalar:function(b){this.n11*=b;this.n12*=b;this.n13*=b;this.n14*=b;this.n21*=b;this.n22*=b;this.n23*=b;this.n24*= +b;this.n31*=b;this.n32*=b;this.n33*=b;this.n34*=b;this.n41*=b;this.n42*=b;this.n43*=b;this.n44*=b;return this},determinant:function(){var b=this.n11,c=this.n12,e=this.n13,f=this.n14,g=this.n21,j=this.n22,h=this.n23,m=this.n24,o=this.n31,n=this.n32,p=this.n33,t=this.n34,v=this.n41,u=this.n42,w=this.n43,z=this.n44;return f*h*n*v-e*m*n*v-f*j*p*v+c*m*p*v+e*j*t*v-c*h*t*v-f*h*o*u+e*m*o*u+f*g*p*u-b*m*p*u-e*g*t*u+b*h*t*u+f*j*o*w-c*m*o*w-f*g*n*w+b*m*n*w+c*g*t*w-b*j*t*w-e*j*o*z+c*h*o*z+e*g*n*z-b*h*n*z-c*g* +p*z+b*j*p*z},transpose:function(){var b;b=this.n21;this.n21=this.n12;this.n12=b;b=this.n31;this.n31=this.n13;this.n13=b;b=this.n32;this.n32=this.n23;this.n23=b;b=this.n41;this.n41=this.n14;this.n14=b;b=this.n42;this.n42=this.n24;this.n24=b;b=this.n43;this.n43=this.n34;this.n43=b;return this},clone:function(){var b=new THREE.Matrix4;b.n11=this.n11;b.n12=this.n12;b.n13=this.n13;b.n14=this.n14;b.n21=this.n21;b.n22=this.n22;b.n23=this.n23;b.n24=this.n24;b.n31=this.n31;b.n32=this.n32;b.n33=this.n33;b.n34= this.n34;b.n41=this.n41;b.n42=this.n42;b.n43=this.n43;b.n44=this.n44;return b},flatten:function(){this.flat[0]=this.n11;this.flat[1]=this.n21;this.flat[2]=this.n31;this.flat[3]=this.n41;this.flat[4]=this.n12;this.flat[5]=this.n22;this.flat[6]=this.n32;this.flat[7]=this.n42;this.flat[8]=this.n13;this.flat[9]=this.n23;this.flat[10]=this.n33;this.flat[11]=this.n43;this.flat[12]=this.n14;this.flat[13]=this.n24;this.flat[14]=this.n34;this.flat[15]=this.n44;return this.flat},flattenToArray:function(b){b[0]= this.n11;b[1]=this.n21;b[2]=this.n31;b[3]=this.n41;b[4]=this.n12;b[5]=this.n22;b[6]=this.n32;b[7]=this.n42;b[8]=this.n13;b[9]=this.n23;b[10]=this.n33;b[11]=this.n43;b[12]=this.n14;b[13]=this.n24;b[14]=this.n34;b[15]=this.n44;return b},flattenToArrayOffset:function(b,c){b[c]=this.n11;b[c+1]=this.n21;b[c+2]=this.n31;b[c+3]=this.n41;b[c+4]=this.n12;b[c+5]=this.n22;b[c+6]=this.n32;b[c+7]=this.n42;b[c+8]=this.n13;b[c+9]=this.n23;b[c+10]=this.n33;b[c+11]=this.n43;b[c+12]=this.n14;b[c+13]=this.n24;b[c+14]= this.n34;b[c+15]=this.n44;return b},setTranslation:function(b,c,e){this.set(1,0,0,b,0,1,0,c,0,0,1,e,0,0,0,1);return this},setScale:function(b,c,e){this.set(b,0,0,0,0,c,0,0,0,0,e,0,0,0,0,1);return this},setRotationX:function(b){var c=Math.cos(b),b=Math.sin(b);this.set(1,0,0,0,0,c,-b,0,0,b,c,0,0,0,0,1);return this},setRotationY:function(b){var c=Math.cos(b),b=Math.sin(b);this.set(c,0,b,0,0,1,0,0,-b,0,c,0,0,0,0,1);return this},setRotationZ:function(b){var c=Math.cos(b),b=Math.sin(b);this.set(c,-b,0, -0,b,c,0,0,0,0,1,0,0,0,0,1);return this},setRotationAxis:function(b,c){var e=Math.cos(c),f=Math.sin(c),g=1-e,j=b.x,h=b.y,m=b.z,p=g*j,n=g*h;this.set(p*j+e,p*h-f*m,p*m+f*h,0,p*h+f*m,n*h+e,n*m-f*j,0,p*m-f*h,n*m+f*j,g*m*m+e,0,0,0,0,1);return this},setPosition:function(b){this.n14=b.x;this.n24=b.y;this.n34=b.z;return this},getPosition:function(){if(!this.position)this.position=new THREE.Vector3;this.position.set(this.n14,this.n24,this.n34);return this.position},getColumnX:function(){if(!this.columnX)this.columnX= -new THREE.Vector3;this.columnX.set(this.n11,this.n21,this.n31);return this.columnX},getColumnY:function(){if(!this.columnY)this.columnY=new THREE.Vector3;this.columnY.set(this.n12,this.n22,this.n32);return this.columnY},getColumnZ:function(){if(!this.columnZ)this.columnZ=new THREE.Vector3;this.columnZ.set(this.n13,this.n23,this.n33);return this.columnZ},setRotationFromEuler:function(b,c){var e=b.x,f=b.y,g=b.z,j=Math.cos(e),e=Math.sin(e),h=Math.cos(f),f=Math.sin(f),m=Math.cos(g),g=Math.sin(g);switch(c){case "YXZ":var p= -h*m,n=h*g,o=f*m,t=f*g;this.n11=p+t*e;this.n12=o*e-n;this.n13=j*f;this.n21=j*g;this.n22=j*m;this.n23=-e;this.n31=n*e-o;this.n32=t+p*e;this.n33=j*h;break;case "ZXY":p=h*m;n=h*g;o=f*m;t=f*g;this.n11=p-t*e;this.n12=-j*g;this.n13=o+n*e;this.n21=n+o*e;this.n22=j*m;this.n23=t-p*e;this.n31=-j*f;this.n32=e;this.n33=j*h;break;case "ZYX":p=j*m;n=j*g;o=e*m;t=e*g;this.n11=h*m;this.n12=o*f-n;this.n13=p*f+t;this.n21=h*g;this.n22=t*f+p;this.n23=n*f-o;this.n31=-f;this.n32=e*h;this.n33=j*h;break;case "YZX":p=j*h;n= -j*f;o=e*h;t=e*f;this.n11=h*m;this.n12=t-p*g;this.n13=o*g+n;this.n21=g;this.n22=j*m;this.n23=-e*m;this.n31=-f*m;this.n32=n*g+o;this.n33=p-t*g;break;case "XZY":p=j*h;n=j*f;o=e*h;t=e*f;this.n11=h*m;this.n12=-g;this.n13=f*m;this.n21=p*g+t;this.n22=j*m;this.n23=n*g-o;this.n31=o*g-n;this.n32=e*m;this.n33=t*g+p;break;default:p=j*m,n=j*g,o=e*m,t=e*g,this.n11=h*m,this.n12=-h*g,this.n13=f,this.n21=n+o*f,this.n22=p-t*f,this.n23=-e*h,this.n31=t-p*f,this.n32=o+n*f,this.n33=j*h}return this},setRotationFromQuaternion:function(b){var c= -b.x,e=b.y,f=b.z,g=b.w,j=c+c,h=e+e,m=f+f,b=c*j,p=c*h;c*=m;var n=e*h;e*=m;f*=m;j*=g;h*=g;g*=m;this.n11=1-(n+f);this.n12=p-g;this.n13=c+h;this.n21=p+g;this.n22=1-(b+f);this.n23=e-j;this.n31=c-h;this.n32=e+j;this.n33=1-(b+n);return this},scale:function(b){var c=b.x,e=b.y,b=b.z;this.n11*=c;this.n12*=e;this.n13*=b;this.n21*=c;this.n22*=e;this.n23*=b;this.n31*=c;this.n32*=e;this.n33*=b;this.n41*=c;this.n42*=e;this.n43*=b;return this},extractPosition:function(b){this.n14=b.n14;this.n24=b.n24;this.n34=b.n34}, +0,b,c,0,0,0,0,1,0,0,0,0,1);return this},setRotationAxis:function(b,c){var e=Math.cos(c),f=Math.sin(c),g=1-e,j=b.x,h=b.y,m=b.z,o=g*j,n=g*h;this.set(o*j+e,o*h-f*m,o*m+f*h,0,o*h+f*m,n*h+e,n*m-f*j,0,o*m-f*h,n*m+f*j,g*m*m+e,0,0,0,0,1);return this},setPosition:function(b){this.n14=b.x;this.n24=b.y;this.n34=b.z;return this},getPosition:function(){if(!this.position)this.position=new THREE.Vector3;this.position.set(this.n14,this.n24,this.n34);return this.position},getColumnX:function(){if(!this.columnX)this.columnX= +new THREE.Vector3;this.columnX.set(this.n11,this.n21,this.n31);return this.columnX},getColumnY:function(){if(!this.columnY)this.columnY=new THREE.Vector3;this.columnY.set(this.n12,this.n22,this.n32);return this.columnY},getColumnZ:function(){if(!this.columnZ)this.columnZ=new THREE.Vector3;this.columnZ.set(this.n13,this.n23,this.n33);return this.columnZ},setRotationFromEuler:function(b,c){var e=b.x,f=b.y,g=b.z,j=Math.cos(e),e=Math.sin(e),h=Math.cos(f),f=Math.sin(f),m=Math.cos(g),g=Math.sin(g);switch(c){case "YXZ":var o= +h*m,n=h*g,p=f*m,t=f*g;this.n11=o+t*e;this.n12=p*e-n;this.n13=j*f;this.n21=j*g;this.n22=j*m;this.n23=-e;this.n31=n*e-p;this.n32=t+o*e;this.n33=j*h;break;case "ZXY":o=h*m;n=h*g;p=f*m;t=f*g;this.n11=o-t*e;this.n12=-j*g;this.n13=p+n*e;this.n21=n+p*e;this.n22=j*m;this.n23=t-o*e;this.n31=-j*f;this.n32=e;this.n33=j*h;break;case "ZYX":o=j*m;n=j*g;p=e*m;t=e*g;this.n11=h*m;this.n12=p*f-n;this.n13=o*f+t;this.n21=h*g;this.n22=t*f+o;this.n23=n*f-p;this.n31=-f;this.n32=e*h;this.n33=j*h;break;case "YZX":o=j*h;n= +j*f;p=e*h;t=e*f;this.n11=h*m;this.n12=t-o*g;this.n13=p*g+n;this.n21=g;this.n22=j*m;this.n23=-e*m;this.n31=-f*m;this.n32=n*g+p;this.n33=o-t*g;break;case "XZY":o=j*h;n=j*f;p=e*h;t=e*f;this.n11=h*m;this.n12=-g;this.n13=f*m;this.n21=o*g+t;this.n22=j*m;this.n23=n*g-p;this.n31=p*g-n;this.n32=e*m;this.n33=t*g+o;break;default:o=j*m,n=j*g,p=e*m,t=e*g,this.n11=h*m,this.n12=-h*g,this.n13=f,this.n21=n+p*f,this.n22=o-t*f,this.n23=-e*h,this.n31=t-o*f,this.n32=p+n*f,this.n33=j*h}return this},setRotationFromQuaternion:function(b){var c= +b.x,e=b.y,f=b.z,g=b.w,j=c+c,h=e+e,m=f+f,b=c*j,o=c*h;c*=m;var n=e*h;e*=m;f*=m;j*=g;h*=g;g*=m;this.n11=1-(n+f);this.n12=o-g;this.n13=c+h;this.n21=o+g;this.n22=1-(b+f);this.n23=e-j;this.n31=c-h;this.n32=e+j;this.n33=1-(b+n);return this},scale:function(b){var c=b.x,e=b.y,b=b.z;this.n11*=c;this.n12*=e;this.n13*=b;this.n21*=c;this.n22*=e;this.n23*=b;this.n31*=c;this.n32*=e;this.n33*=b;this.n41*=c;this.n42*=e;this.n43*=b;return this},extractPosition:function(b){this.n14=b.n14;this.n24=b.n24;this.n34=b.n34}, extractRotation:function(b,c){var e=1/c.x,f=1/c.y,g=1/c.z;this.n11=b.n11*e;this.n21=b.n21*e;this.n31=b.n31*e;this.n12=b.n12*f;this.n22=b.n22*f;this.n32=b.n32*f;this.n13=b.n13*g;this.n23=b.n23*g;this.n33=b.n33*g}}; -THREE.Matrix4.makeInvert=function(b,c){var e=b.n11,f=b.n12,g=b.n13,j=b.n14,h=b.n21,m=b.n22,p=b.n23,n=b.n24,o=b.n31,t=b.n32,v=b.n33,u=b.n34,w=b.n41,z=b.n42,y=b.n43,x=b.n44;c===void 0&&(c=new THREE.Matrix4);c.n11=p*u*z-n*v*z+n*t*y-m*u*y-p*t*x+m*v*x;c.n12=j*v*z-g*u*z-j*t*y+f*u*y+g*t*x-f*v*x;c.n13=g*n*z-j*p*z+j*m*y-f*n*y-g*m*x+f*p*x;c.n14=j*p*t-g*n*t-j*m*v+f*n*v+g*m*u-f*p*u;c.n21=n*v*w-p*u*w-n*o*y+h*u*y+p*o*x-h*v*x;c.n22=g*u*w-j*v*w+j*o*y-e*u*y-g*o*x+e*v*x;c.n23=j*p*w-g*n*w-j*h*y+e*n*y+g*h*x-e*p*x;c.n24= -g*n*o-j*p*o+j*h*v-e*n*v-g*h*u+e*p*u;c.n31=m*u*w-n*t*w+n*o*z-h*u*z-m*o*x+h*t*x;c.n32=j*t*w-f*u*w-j*o*z+e*u*z+f*o*x-e*t*x;c.n33=g*n*w-j*m*w+j*h*z-e*n*z-f*h*x+e*m*x;c.n34=j*m*o-f*n*o-j*h*t+e*n*t+f*h*u-e*m*u;c.n41=p*t*w-m*v*w-p*o*z+h*v*z+m*o*y-h*t*y;c.n42=f*v*w-g*t*w+g*o*z-e*v*z-f*o*y+e*t*y;c.n43=g*m*w-f*p*w-g*h*z+e*p*z+f*h*y-e*m*y;c.n44=f*p*o-g*m*o+g*h*t-e*p*t-f*h*v+e*m*v;c.multiplyScalar(1/b.determinant());return c}; -THREE.Matrix4.makeInvert3x3=function(b){var c=b.m33,e=c.m,f=b.n33*b.n22-b.n32*b.n23,g=-b.n33*b.n21+b.n31*b.n23,j=b.n32*b.n21-b.n31*b.n22,h=-b.n33*b.n12+b.n32*b.n13,m=b.n33*b.n11-b.n31*b.n13,p=-b.n32*b.n11+b.n31*b.n12,n=b.n23*b.n12-b.n22*b.n13,o=-b.n23*b.n11+b.n21*b.n13,t=b.n22*b.n11-b.n21*b.n12,b=b.n11*f+b.n21*h+b.n31*n;b==0&&console.error("THREE.Matrix4.makeInvert3x3: Matrix not invertible.");b=1/b;e[0]=b*f;e[1]=b*g;e[2]=b*j;e[3]=b*h;e[4]=b*m;e[5]=b*p;e[6]=b*n;e[7]=b*o;e[8]=b*t;return c}; +THREE.Matrix4.makeInvert=function(b,c){var e=b.n11,f=b.n12,g=b.n13,j=b.n14,h=b.n21,m=b.n22,o=b.n23,n=b.n24,p=b.n31,t=b.n32,v=b.n33,u=b.n34,w=b.n41,z=b.n42,x=b.n43,y=b.n44;c===void 0&&(c=new THREE.Matrix4);c.n11=o*u*z-n*v*z+n*t*x-m*u*x-o*t*y+m*v*y;c.n12=j*v*z-g*u*z-j*t*x+f*u*x+g*t*y-f*v*y;c.n13=g*n*z-j*o*z+j*m*x-f*n*x-g*m*y+f*o*y;c.n14=j*o*t-g*n*t-j*m*v+f*n*v+g*m*u-f*o*u;c.n21=n*v*w-o*u*w-n*p*x+h*u*x+o*p*y-h*v*y;c.n22=g*u*w-j*v*w+j*p*x-e*u*x-g*p*y+e*v*y;c.n23=j*o*w-g*n*w-j*h*x+e*n*x+g*h*y-e*o*y;c.n24= +g*n*p-j*o*p+j*h*v-e*n*v-g*h*u+e*o*u;c.n31=m*u*w-n*t*w+n*p*z-h*u*z-m*p*y+h*t*y;c.n32=j*t*w-f*u*w-j*p*z+e*u*z+f*p*y-e*t*y;c.n33=g*n*w-j*m*w+j*h*z-e*n*z-f*h*y+e*m*y;c.n34=j*m*p-f*n*p-j*h*t+e*n*t+f*h*u-e*m*u;c.n41=o*t*w-m*v*w-o*p*z+h*v*z+m*p*x-h*t*x;c.n42=f*v*w-g*t*w+g*p*z-e*v*z-f*p*x+e*t*x;c.n43=g*m*w-f*o*w-g*h*z+e*o*z+f*h*x-e*m*x;c.n44=f*o*p-g*m*p+g*h*t-e*o*t-f*h*v+e*m*v;c.multiplyScalar(1/b.determinant());return c}; +THREE.Matrix4.makeInvert3x3=function(b){var c=b.m33,e=c.m,f=b.n33*b.n22-b.n32*b.n23,g=-b.n33*b.n21+b.n31*b.n23,j=b.n32*b.n21-b.n31*b.n22,h=-b.n33*b.n12+b.n32*b.n13,m=b.n33*b.n11-b.n31*b.n13,o=-b.n32*b.n11+b.n31*b.n12,n=b.n23*b.n12-b.n22*b.n13,p=-b.n23*b.n11+b.n21*b.n13,t=b.n22*b.n11-b.n21*b.n12,b=b.n11*f+b.n21*h+b.n31*n;b==0&&console.error("THREE.Matrix4.makeInvert3x3: Matrix not invertible.");b=1/b;e[0]=b*f;e[1]=b*g;e[2]=b*j;e[3]=b*h;e[4]=b*m;e[5]=b*o;e[6]=b*n;e[7]=b*p;e[8]=b*t;return c}; THREE.Matrix4.makeFrustum=function(b,c,e,f,g,j){var h;h=new THREE.Matrix4;h.n11=2*g/(c-b);h.n12=0;h.n13=(c+b)/(c-b);h.n14=0;h.n21=0;h.n22=2*g/(f-e);h.n23=(f+e)/(f-e);h.n24=0;h.n31=0;h.n32=0;h.n33=-(j+g)/(j-g);h.n34=-2*j*g/(j-g);h.n41=0;h.n42=0;h.n43=-1;h.n44=0;return h};THREE.Matrix4.makePerspective=function(b,c,e,f){var g,b=e*Math.tan(b*Math.PI/360);g=-b;return THREE.Matrix4.makeFrustum(g*c,b*c,g,b,e,f)}; -THREE.Matrix4.makeOrtho=function(b,c,e,f,g,j){var h,m,p,n;h=new THREE.Matrix4;m=c-b;p=e-f;n=j-g;h.n11=2/m;h.n12=0;h.n13=0;h.n14=-((c+b)/m);h.n21=0;h.n22=2/p;h.n23=0;h.n24=-((e+f)/p);h.n31=0;h.n32=0;h.n33=-2/n;h.n34=-((j+g)/n);h.n41=0;h.n42=0;h.n43=0;h.n44=1;return h};THREE.Matrix4.__v1=new THREE.Vector3;THREE.Matrix4.__v2=new THREE.Vector3;THREE.Matrix4.__v3=new THREE.Vector3; +THREE.Matrix4.makeOrtho=function(b,c,e,f,g,j){var h,m,o,n;h=new THREE.Matrix4;m=c-b;o=e-f;n=j-g;h.n11=2/m;h.n12=0;h.n13=0;h.n14=-((c+b)/m);h.n21=0;h.n22=2/o;h.n23=0;h.n24=-((e+f)/o);h.n31=0;h.n32=0;h.n33=-2/n;h.n34=-((j+g)/n);h.n41=0;h.n42=0;h.n43=0;h.n44=1;return h};THREE.Matrix4.__v1=new THREE.Vector3;THREE.Matrix4.__v2=new THREE.Vector3;THREE.Matrix4.__v3=new THREE.Vector3; THREE.Object3D=function(){this.parent=void 0;this.children=[];this.up=new THREE.Vector3(0,1,0);this.position=new THREE.Vector3;this.rotation=new THREE.Vector3;this.eulerOrder="XYZ";this.scale=new THREE.Vector3(1,1,1);this.flipSided=this.doubleSided=this.dynamic=!1;this.renderDepth=null;this.rotationAutoUpdate=!0;this.matrix=new THREE.Matrix4;this.matrixWorld=new THREE.Matrix4;this.matrixRotationWorld=new THREE.Matrix4;this.matrixWorldNeedsUpdate=this.matrixAutoUpdate=!0;this.quaternion=new THREE.Quaternion; this.useQuaternion=!1;this.boundRadius=0;this.boundRadiusScale=1;this.visible=!0;this.receiveShadow=this.castShadow=!1;this._vector=new THREE.Vector3;this.name=""}; THREE.Object3D.prototype={constructor:THREE.Object3D,translate:function(b,c){this.matrix.rotateAxis(c);this.position.addSelf(c.multiplyScalar(b))},translateX:function(b){this.translate(b,this._vector.set(1,0,0))},translateY:function(b){this.translate(b,this._vector.set(0,1,0))},translateZ:function(b){this.translate(b,this._vector.set(0,0,1))},lookAt:function(b){this.matrix.lookAt(b,this.position,this.up);this.rotationAutoUpdate&&this.rotation.setRotationFromMatrix(this.matrix)},addChild:function(b){if(this.children.indexOf(b)=== @@ -53,26 +53,26 @@ this.matrixRotationWorld.extractRotation(this.matrixWorld,this.scale),this.matri THREE.Quaternion.prototype={constructor:THREE.Quaternion,set:function(b,c,e,f){this.x=b;this.y=c;this.z=e;this.w=f;return this},copy:function(b){this.x=b.x;this.y=b.y;this.z=b.z;this.w=b.w;return this},setFromEuler:function(b){var c=0.5*Math.PI/360,e=b.x*c,f=b.y*c,g=b.z*c,b=Math.cos(f),f=Math.sin(f),c=Math.cos(-g),g=Math.sin(-g),j=Math.cos(e),e=Math.sin(e),h=b*c,m=f*g;this.w=h*j-m*e;this.x=h*e+m*j;this.y=f*c*j+b*g*e;this.z=b*g*j-f*c*e;return this},setFromAxisAngle:function(b,c){var e=c/2,f=Math.sin(e); this.x=b.x*f;this.y=b.y*f;this.z=b.z*f;this.w=Math.cos(e);return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x*=-1;this.y*=-1;this.z*=-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var b=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);b==0?this.w=this.z=this.y=this.x=0:(b=1/b,this.x*=b,this.y*=b,this.z*= b,this.w*=b);return this},multiplySelf:function(b){var c=this.x,e=this.y,f=this.z,g=this.w,j=b.x,h=b.y,m=b.z,b=b.w;this.x=c*b+g*j+e*m-f*h;this.y=e*b+g*h+f*j-c*m;this.z=f*b+g*m+c*h-e*j;this.w=g*b-c*j-e*h-f*m;return this},multiply:function(b,c){this.x=b.x*c.w+b.y*c.z-b.z*c.y+b.w*c.x;this.y=-b.x*c.z+b.y*c.w+b.z*c.x+b.w*c.y;this.z=b.x*c.y-b.y*c.x+b.z*c.w+b.w*c.z;this.w=-b.x*c.x-b.y*c.y-b.z*c.z+b.w*c.w;return this},multiplyVector3:function(b,c){c||(c=b);var e=b.x,f=b.y,g=b.z,j=this.x,h=this.y,m=this.z, -p=this.w,n=p*e+h*g-m*f,o=p*f+m*e-j*g,t=p*g+j*f-h*e,e=-j*e-h*f-m*g;c.x=n*p+e*-j+o*-m-t*-h;c.y=o*p+e*-h+t*-j-n*-m;c.z=t*p+e*-m+n*-h-o*-j;return c}}; +o=this.w,n=o*e+h*g-m*f,p=o*f+m*e-j*g,t=o*g+j*f-h*e,e=-j*e-h*f-m*g;c.x=n*o+e*-j+p*-m-t*-h;c.y=p*o+e*-h+t*-j-n*-m;c.z=t*o+e*-m+n*-h-p*-j;return c}}; THREE.Quaternion.slerp=function(b,c,e,f){var g=b.w*c.w+b.x*c.x+b.y*c.y+b.z*c.z;if(Math.abs(g)>=1)return e.w=b.w,e.x=b.x,e.y=b.y,e.z=b.z,e;var j=Math.acos(g),h=Math.sqrt(1-g*g);if(Math.abs(h)<0.0010)return e.w=0.5*(b.w+c.w),e.x=0.5*(b.x+c.x),e.y=0.5*(b.y+c.y),e.z=0.5*(b.z+c.z),e;g=Math.sin((1-f)*j)/h;f=Math.sin(f*j)/h;e.w=b.w*g+c.w*f;e.x=b.x*g+c.x*f;e.y=b.y*g+c.y*f;e.z=b.z*g+c.z*f;return e};THREE.Vertex=function(b){this.position=b||new THREE.Vector3}; THREE.Face3=function(b,c,e,f,g,j){this.a=b;this.b=c;this.c=e;this.normal=f instanceof THREE.Vector3?f:new THREE.Vector3;this.vertexNormals=f instanceof Array?f:[];this.color=g instanceof THREE.Color?g:new THREE.Color;this.vertexColors=g instanceof Array?g:[];this.vertexTangents=[];this.materials=j instanceof Array?j:[j];this.centroid=new THREE.Vector3}; THREE.Face4=function(b,c,e,f,g,j,h){this.a=b;this.b=c;this.c=e;this.d=f;this.normal=g instanceof THREE.Vector3?g:new THREE.Vector3;this.vertexNormals=g instanceof Array?g:[];this.color=j instanceof THREE.Color?j:new THREE.Color;this.vertexColors=j instanceof Array?j:[];this.vertexTangents=[];this.materials=h instanceof Array?h:[h];this.centroid=new THREE.Vector3};THREE.UV=function(b,c){this.set(b||0,c||0)}; THREE.UV.prototype={constructor:THREE.UV,set:function(b,c){this.u=b;this.v=c;return this},copy:function(b){this.set(b.u,b.v);return this}};THREE.Geometry=function(){this.id="Geometry"+THREE.GeometryIdCounter++;this.vertices=[];this.colors=[];this.faces=[];this.edges=[];this.faceUvs=[[]];this.faceVertexUvs=[[]];this.morphTargets=[];this.morphColors=[];this.skinWeights=[];this.skinIndices=[];this.boundingSphere=this.boundingBox=null;this.hasTangents=!1}; THREE.Geometry.prototype={constructor:THREE.Geometry,computeCentroids:function(){var b,c,e;b=0;for(c=this.faces.length;b0){this.boundingBox={x:[this.vertices[0].position.x,this.vertices[0].position.x],y:[this.vertices[0].position.y,this.vertices[0].position.y],z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var c=1,e=this.vertices.length;cthis.boundingBox.x[1])this.boundingBox.x[1]=b.position.x;if(b.position.ythis.boundingBox.y[1])this.boundingBox.y[1]=b.position.y;if(b.position.zthis.boundingBox.z[1])this.boundingBox.z[1]=b.position.z}}},computeBoundingSphere:function(){for(var b=0,c=0,e=this.vertices.length;cthis.points.length-2?j:j+1;e[3]=j>this.points.length-3?j:j+2;n=this.points[e[0]];o=this.points[e[1]]; -t=this.points[e[2]];v=this.points[e[3]];m=h*h;p=h*m;f.x=c(n.x,o.x,t.x,v.x,h,m,p);f.y=c(n.y,o.y,t.y,v.y,h,m,p);f.z=c(n.z,o.z,t.z,v.z,h,m,p);return f};this.getControlPointsArray=function(){var b,e,c=this.points.length,f=[];for(b=0;bthis.points.length-2?j:j+1;e[3]=j>this.points.length-3?j:j+2;n=this.points[e[0]];p=this.points[e[1]]; +t=this.points[e[2]];v=this.points[e[3]];m=h*h;o=h*m;f.x=c(n.x,p.x,t.x,v.x,h,m,o);f.y=c(n.y,p.y,t.y,v.y,h,m,o);f.z=c(n.z,p.z,t.z,v.z,h,m,o);return f};this.getControlPointsArray=function(){var b,e,c=this.points.length,f=[];for(b=0;b1){b=e.matrixWorldInverse;b=-(b.n31*this.position.x+b.n32*this.position.y+b.n33*this.position.z+b.n34);this.LODs[0].object3D.visible=!0;for(var f=1;f=this.LODs[f].visibleAtDistance)this.LODs[f-1].object3D.visible=!1, this.LODs[f].object3D.visible=!0;else break;for(;ft&&(e=o,o=t,t=e):ou&&(e=v,v=u,u=e):vt&&(e=p,p=t,t=e):pu&&(e=v,v=u,u=e):v=0&&g>=0&&k>=0&&j>=0?!0:h<0&&g<0||k<0&&j<0?!1:(h<0?c=Math.max(c,h/(h-g)):g<0&&(f=Math.min(f,h/(h-g))),k<0?c=Math.max(c,k/(k-j)):j<0&&(f=Math.min(f,k/(k-j))),f=0&&g>=0&&k>=0&&j>=0?!0:h<0&&g<0||k<0&&j<0?!1:(h<0?c=Math.max(c,h/(h-g)):g<0&&(f=Math.min(f,h/(h-g))),k<0?c=Math.max(c,k/(k-j)):j<0&&(f=Math.min(f,k/(k-j))),fS&&h.positionScreen.zS&&h.positionScreen.z0&&J.z<1))ca=B[H]=B[H]||new THREE.RenderableParticle,H++,x=ca,x.x=J.x/J.w,x.y=J.y/J.w,x.z=J.z,x.rotation=X.rotation.z,x.scale.x=X.scale.x*Math.abs(x.x-(J.x+g.projectionMatrix.n11)/ -(J.w+g.projectionMatrix.n14)),x.scale.y=X.scale.y*Math.abs(x.y-(J.y+g.projectionMatrix.n22)/(J.w+g.projectionMatrix.n24)),x.materials=X.materials,F.push(x);j&&F.sort(c);return F}}; -THREE.DOMRenderer=function(){THREE.Renderer.call(this);var b=null,c=new THREE.Projector,e,f,g,j;this.domElement=document.createElement("div");this.setSize=function(b,c){e=b;f=c;g=e/2;j=f/2};this.render=function(e,f){var p,n,o,t,v,u,w,z;b=c.projectScene(e,f);p=0;for(n=b.length;p>1,o=n.height>>1,k=h.scale.x*t,p=h.scale.y*v,j=k*Aa,m=p*o,na.set(b.x-j,b.y- -m,b.x+j,b.y+m),W.instersects(na)&&(u.save(),u.translate(b.x,b.y),u.rotate(-h.rotation),u.scale(k,-p),u.translate(-Aa,-o),u.drawImage(n,0,0),u.restore())}else k instanceof THREE.ParticleCanvasMaterial&&(j=h.scale.x*t,m=h.scale.y*v,na.set(b.x-j,b.y-m,b.x+j,b.y+m),W.instersects(na)&&(f(k.color.getContextStyle()),g(k.color.getContextStyle()),u.save(),u.translate(b.x,b.y),u.rotate(-h.rotation),u.scale(j,m),k.program(u),u.restore()))}function Ya(b,h,k,g){c(g.opacity);e(g.blending);u.beginPath();u.moveTo(b.positionScreen.x, -b.positionScreen.y);u.lineTo(h.positionScreen.x,h.positionScreen.y);u.closePath();if(g instanceof THREE.LineBasicMaterial){b=g.linewidth;if(F!=b)u.lineWidth=F=b;b=g.linecap;if(J!=b)u.lineCap=J=b;b=g.linejoin;if(D!=b)u.lineJoin=D=b;f(g.color.getContextStyle());u.stroke();na.inflate(g.linewidth*2)}}function w(b,f,h,g,m,n,t,u,v){j.data.vertices+=3;j.data.faces++;c(u.opacity);e(u.blending);C=b.positionScreen.x;ea=b.positionScreen.y;S=f.positionScreen.x;P=f.positionScreen.y;k=h.positionScreen.x;M=h.positionScreen.y; -z(C,ea,S,P,k,M);if(u instanceof THREE.MeshBasicMaterial)if(u.map)u.map.mapping instanceof THREE.UVMapping&&(ja=t.uvs[0],H(C,ea,S,P,k,M,ja[g].u,ja[g].v,ja[m].u,ja[m].v,ja[n].u,ja[n].v,u.map));else if(u.envMap){if(u.envMap.mapping instanceof THREE.SphericalReflectionMapping)b=p.matrixWorldInverse,pa.copy(t.vertexNormalsWorld[0]),qa=(pa.x*b.n11+pa.y*b.n12+pa.z*b.n13)*0.5+0.5,va=-(pa.x*b.n21+pa.y*b.n22+pa.z*b.n23)*0.5+0.5,pa.copy(t.vertexNormalsWorld[1]),za=(pa.x*b.n11+pa.y*b.n12+pa.z*b.n13)*0.5+0.5, -La=-(pa.x*b.n21+pa.y*b.n22+pa.z*b.n23)*0.5+0.5,pa.copy(t.vertexNormalsWorld[2]),ya=(pa.x*b.n11+pa.y*b.n12+pa.z*b.n13)*0.5+0.5,Oa=-(pa.x*b.n21+pa.y*b.n22+pa.z*b.n23)*0.5+0.5,H(C,ea,S,P,k,M,qa,va,za,La,ya,Oa,u.envMap)}else u.wireframe?B(u.color,u.wireframeLinewidth,u.wireframeLinecap,u.wireframeLinejoin):Ha(u.color);else if(u instanceof THREE.MeshLambertMaterial)u.map&&!u.wireframe&&(u.map.mapping instanceof THREE.UVMapping&&(ja=t.uvs[0],H(C,ea,S,P,k,M,ja[g].u,ja[g].v,ja[m].u,ja[m].v,ja[n].u,ja[n].v, -u.map)),e(THREE.SubtractiveBlending)),ua?!u.wireframe&&u.shading==THREE.SmoothShading&&t.vertexNormalsWorld.length==3?(X.r=ca.r=ma.r=ra.r,X.g=ca.g=ma.g=ra.g,X.b=ca.b=ma.b=ra.b,o(v,t.v1.positionWorld,t.vertexNormalsWorld[0],X),o(v,t.v2.positionWorld,t.vertexNormalsWorld[1],ca),o(v,t.v3.positionWorld,t.vertexNormalsWorld[2],ma),la.r=(ca.r+ma.r)*0.5,la.g=(ca.g+ma.g)*0.5,la.b=(ca.b+ma.b)*0.5,ga=Ta(X,ca,ma,la),Pa(C,ea,S,P,k,M,0,0,1,0,0,1,ga)):(ia.r=ra.r,ia.g=ra.g,ia.b=ra.b,o(v,t.centroidWorld,t.normalWorld, -ia),U.r=Math.max(0,Math.min(u.color.r*ia.r,1)),U.g=Math.max(0,Math.min(u.color.g*ia.g,1)),U.b=Math.max(0,Math.min(u.color.b*ia.b,1)),u.wireframe?B(U,u.wireframeLinewidth,u.wireframeLinecap,u.wireframeLinejoin):Ha(U)):u.wireframe?B(u.color,u.wireframeLinewidth,u.wireframeLinecap,u.wireframeLinejoin):Ha(u.color);else if(u instanceof THREE.MeshDepthMaterial)K=p.near,V=p.far,X.r=X.g=X.b=1-Ma(b.positionScreen.z,K,V),ca.r=ca.g=ca.b=1-Ma(f.positionScreen.z,K,V),ma.r=ma.g=ma.b=1-Ma(h.positionScreen.z,K,V), -la.r=(ca.r+ma.r)*0.5,la.g=(ca.g+ma.g)*0.5,la.b=(ca.b+ma.b)*0.5,ga=Ta(X,ca,ma,la),Pa(C,ea,S,P,k,M,0,0,1,0,0,1,ga);else if(u instanceof THREE.MeshNormalMaterial)U.r=Qa(t.normalWorld.x),U.g=Qa(t.normalWorld.y),U.b=Qa(t.normalWorld.z),u.wireframe?B(U,u.wireframeLinewidth,u.wireframeLinecap,u.wireframeLinejoin):Ha(U)}function x(b,f,h,g,m,n,t,u,v){j.data.vertices+=4;j.data.faces++;c(u.opacity);e(u.blending);if(u.map||u.envMap)w(b,f,g,0,1,3,t,u,v),w(m,h,n,1,2,3,t,u,v);else if(C=b.positionScreen.x,ea=b.positionScreen.y, -S=f.positionScreen.x,P=f.positionScreen.y,k=h.positionScreen.x,M=h.positionScreen.y,Y=g.positionScreen.x,aa=g.positionScreen.y,Z=m.positionScreen.x,ha=m.positionScreen.y,ka=n.positionScreen.x,fa=n.positionScreen.y,u instanceof THREE.MeshBasicMaterial)y(C,ea,S,P,k,M,Y,aa),u.wireframe?B(u.color,u.wireframeLinewidth,u.wireframeLinecap,u.wireframeLinejoin):Ha(u.color);else if(u instanceof THREE.MeshLambertMaterial)ua?!u.wireframe&&u.shading==THREE.SmoothShading&&t.vertexNormalsWorld.length==4?(X.r=ca.r= -ma.r=la.r=ra.r,X.g=ca.g=ma.g=la.g=ra.g,X.b=ca.b=ma.b=la.b=ra.b,o(v,t.v1.positionWorld,t.vertexNormalsWorld[0],X),o(v,t.v2.positionWorld,t.vertexNormalsWorld[1],ca),o(v,t.v4.positionWorld,t.vertexNormalsWorld[3],ma),o(v,t.v3.positionWorld,t.vertexNormalsWorld[2],la),ga=Ta(X,ca,ma,la),z(C,ea,S,P,Y,aa),Pa(C,ea,S,P,Y,aa,0,0,1,0,0,1,ga),z(Z,ha,k,M,ka,fa),Pa(Z,ha,k,M,ka,fa,1,0,1,1,0,1,ga)):(ia.r=ra.r,ia.g=ra.g,ia.b=ra.b,o(v,t.centroidWorld,t.normalWorld,ia),U.r=Math.max(0,Math.min(u.color.r*ia.r,1)),U.g= -Math.max(0,Math.min(u.color.g*ia.g,1)),U.b=Math.max(0,Math.min(u.color.b*ia.b,1)),y(C,ea,S,P,k,M,Y,aa),u.wireframe?B(U,u.wireframeLinewidth,u.wireframeLinecap,u.wireframeLinejoin):Ha(U)):(y(C,ea,S,P,k,M,Y,aa),u.wireframe?B(u.color,u.wireframeLinewidth,u.wireframeLinecap,u.wireframeLinejoin):Ha(u.color));else if(u instanceof THREE.MeshNormalMaterial)U.r=Qa(t.normalWorld.x),U.g=Qa(t.normalWorld.y),U.b=Qa(t.normalWorld.z),y(C,ea,S,P,k,M,Y,aa),u.wireframe?B(U,u.wireframeLinewidth,u.wireframeLinecap,u.wireframeLinejoin): -Ha(U);else if(u instanceof THREE.MeshDepthMaterial)K=p.near,V=p.far,X.r=X.g=X.b=1-Ma(b.positionScreen.z,K,V),ca.r=ca.g=ca.b=1-Ma(f.positionScreen.z,K,V),ma.r=ma.g=ma.b=1-Ma(g.positionScreen.z,K,V),la.r=la.g=la.b=1-Ma(h.positionScreen.z,K,V),ga=Ta(X,ca,ma,la),z(C,ea,S,P,Y,aa),Pa(C,ea,S,P,Y,aa,0,0,1,0,0,1,ga),z(Z,ha,k,M,ka,fa),Pa(Z,ha,k,M,ka,fa,1,0,1,1,0,1,ga)}function z(b,e,c,f,h,g){u.beginPath();u.moveTo(b,e);u.lineTo(c,f);u.lineTo(h,g);u.lineTo(b,e);u.closePath()}function y(b,e,c,f,h,g,k,j){u.beginPath(); -u.moveTo(b,e);u.lineTo(c,f);u.lineTo(h,g);u.lineTo(k,j);u.lineTo(b,e);u.closePath()}function B(b,e,c,h){if(F!=e)u.lineWidth=F=e;if(J!=c)u.lineCap=J=c;if(D!=h)u.lineJoin=D=h;f(b.getContextStyle());u.stroke();na.inflate(e*2)}function Ha(b){g(b.getContextStyle());u.fill()}function H(b,e,c,f,h,k,j,m,p,n,t,Aa,o){if(o.image.width!=0){if(o.needsUpdate==!0||sa[o.id]==void 0){var v=o.wrapS==THREE.RepeatWrapping,Sa=o.wrapT==THREE.RepeatWrapping;sa[o.id]=u.createPattern(o.image,v&&Sa?"repeat":v&&!Sa?"repeat-x": -!v&&Sa?"repeat-y":"no-repeat");o.needsUpdate=!1}g(sa[o.id]);v=(o.image.width-1)*o.repeat.x;o=(o.image.height-1)*o.repeat.y;j*=v;m*=o;p*=v;n*=o;t*=v;Aa*=o;c-=b;f-=e;h-=b;k-=e;p-=j;n-=m;t-=j;Aa-=m;v=1/(p*Aa-t*n);o=(Aa*c-n*h)*v;n=(Aa*f-n*k)*v;c=(p*h-t*c)*v;f=(p*k-t*f)*v;b=b-o*j-c*m;e=e-n*j-f*m;u.save();u.transform(o,n,c,f,b,e);u.fill();u.restore()}}function Pa(b,e,c,f,h,g,k,j,m,p,n,t,Aa){var o,v;o=Aa.width-1;v=Aa.height-1;k*=o;j*=v;m*=o;p*=v;n*=o;t*=v;c-=b;f-=e;h-=b;g-=e;m-=k;p-=j;n-=k;t-=j;v=1/(m*t- -n*p);o=(t*c-p*h)*v;p=(t*f-p*g)*v;c=(m*h-n*c)*v;f=(m*g-n*f)*v;b=b-o*k-c*j;e=e-p*k-f*j;u.save();u.transform(o,p,c,f,b,e);u.clip();u.drawImage(Aa,0,0);u.restore()}function Ta(b,e,c,f){var h=~~(b.r*255),g=~~(b.g*255),b=~~(b.b*255),k=~~(e.r*255),j=~~(e.g*255),e=~~(e.b*255),m=~~(c.r*255),p=~~(c.g*255),c=~~(c.b*255),n=~~(f.r*255),u=~~(f.g*255),f=~~(f.b*255);Q[0]=h<0?0:h>255?255:h;Q[1]=g<0?0:g>255?255:g;Q[2]=b<0?0:b>255?255:b;Q[4]=k<0?0:k>255?255:k;Q[5]=j<0?0:j>255?255:j;Q[6]=e<0?0:e>255?255:e;Q[8]=m<0?0: -m>255?255:m;Q[9]=p<0?0:p>255?255:p;Q[10]=c<0?0:c>255?255:c;Q[12]=n<0?0:n>255?255:n;Q[13]=u<0?0:u>255?255:u;Q[14]=f<0?0:f>255?255:f;Da.putImageData($,0,0);O.drawImage(xa,0,0);return Ea}function Ma(b,e,c){b=(b-e)/(c-e);return b*b*(3-2*b)}function Qa(b){b=(b+1)*0.5;return b<0?0:b>1?1:b}function Ia(b,e){var c=e.x-b.x,f=e.y-b.y,h=c*c+f*f;h!=0&&(h=1/Math.sqrt(h),c*=h,f*=h,e.x+=c,e.y+=f,b.x-=c,b.y-=f)}var Ua,Xa,oa,Ca,Ja,Ra,Va,E;this.autoClear?this.clear():u.setTransform(1,0,0,-1,t,v);j.data.vertices=0;j.data.faces= -0;h=m.projectScene(b,p,this.sortElements);(ua=b.lights.length>0)&&n(b);Ua=0;for(Xa=h.length;Ua0&&J.z<1))ca=B[H]=B[H]||new THREE.RenderableParticle,H++,y=ca,y.x=J.x/J.w,y.y=J.y/J.w,y.z=J.z,y.rotation=X.rotation.z,y.scale.x=X.scale.x*Math.abs(y.x-(J.x+g.projectionMatrix.n11)/ +(J.w+g.projectionMatrix.n14)),y.scale.y=X.scale.y*Math.abs(y.y-(J.y+g.projectionMatrix.n22)/(J.w+g.projectionMatrix.n24)),y.materials=X.materials,F.push(y);j&&F.sort(c);return F}}; +THREE.DOMRenderer=function(){THREE.Renderer.call(this);var b=null,c=new THREE.Projector,e,f,g,j;this.domElement=document.createElement("div");this.setSize=function(b,c){e=b;f=c;g=e/2;j=f/2};this.render=function(e,f){var o,n,p,t,v,u,w,z;b=c.projectScene(e,f);o=0;for(n=b.length;o>1,p=n.height>>1,j=h.scale.x*t,o=h.scale.y*v,k=j*va,m=o*p,na.set(b.x-k,b.y- +m,b.x+k,b.y+m),W.instersects(na)&&(u.save(),u.translate(b.x,b.y),u.rotate(-h.rotation),u.scale(j,-o),u.translate(-va,-p),u.drawImage(n,0,0),u.restore())}else j instanceof THREE.ParticleCanvasMaterial&&(k=h.scale.x*t,m=h.scale.y*v,na.set(b.x-k,b.y-m,b.x+k,b.y+m),W.instersects(na)&&(f(j.color.getContextStyle()),g(j.color.getContextStyle()),u.save(),u.translate(b.x,b.y),u.rotate(-h.rotation),u.scale(k,m),j.program(u),u.restore()))}function Ya(b,h,g,j){c(j.opacity);e(j.blending);u.beginPath();u.moveTo(b.positionScreen.x, +b.positionScreen.y);u.lineTo(h.positionScreen.x,h.positionScreen.y);u.closePath();if(j instanceof THREE.LineBasicMaterial){b=j.linewidth;if(F!=b)u.lineWidth=F=b;b=j.linecap;if(J!=b)u.lineCap=J=b;b=j.linejoin;if(D!=b)u.lineJoin=D=b;f(j.color.getContextStyle());u.stroke();na.inflate(j.linewidth*2)}}function w(b,f,h,g,m,n,t,u,v){j.data.vertices+=3;j.data.faces++;c(u.opacity);e(u.blending);C=b.positionScreen.x;ea=b.positionScreen.y;S=f.positionScreen.x;P=f.positionScreen.y;k=h.positionScreen.x;M=h.positionScreen.y; +z(C,ea,S,P,k,M);if(u instanceof THREE.MeshBasicMaterial)if(u.map)u.map.mapping instanceof THREE.UVMapping&&(ja=t.uvs[0],H(C,ea,S,P,k,M,ja[g].u,ja[g].v,ja[m].u,ja[m].v,ja[n].u,ja[n].v,u.map));else if(u.envMap){if(u.envMap.mapping instanceof THREE.SphericalReflectionMapping)b=o.matrixWorldInverse,pa.copy(t.vertexNormalsWorld[0]),qa=(pa.x*b.n11+pa.y*b.n12+pa.z*b.n13)*0.5+0.5,wa=-(pa.x*b.n21+pa.y*b.n22+pa.z*b.n23)*0.5+0.5,pa.copy(t.vertexNormalsWorld[1]),Aa=(pa.x*b.n11+pa.y*b.n12+pa.z*b.n13)*0.5+0.5, +La=-(pa.x*b.n21+pa.y*b.n22+pa.z*b.n23)*0.5+0.5,pa.copy(t.vertexNormalsWorld[2]),za=(pa.x*b.n11+pa.y*b.n12+pa.z*b.n13)*0.5+0.5,Oa=-(pa.x*b.n21+pa.y*b.n22+pa.z*b.n23)*0.5+0.5,H(C,ea,S,P,k,M,qa,wa,Aa,La,za,Oa,u.envMap)}else u.wireframe?B(u.color,u.wireframeLinewidth,u.wireframeLinecap,u.wireframeLinejoin):Ha(u.color);else if(u instanceof THREE.MeshLambertMaterial)u.map&&!u.wireframe&&(u.map.mapping instanceof THREE.UVMapping&&(ja=t.uvs[0],H(C,ea,S,P,k,M,ja[g].u,ja[g].v,ja[m].u,ja[m].v,ja[n].u,ja[n].v, +u.map)),e(THREE.SubtractiveBlending)),ua?!u.wireframe&&u.shading==THREE.SmoothShading&&t.vertexNormalsWorld.length==3?(X.r=ca.r=ma.r=ra.r,X.g=ca.g=ma.g=ra.g,X.b=ca.b=ma.b=ra.b,p(v,t.v1.positionWorld,t.vertexNormalsWorld[0],X),p(v,t.v2.positionWorld,t.vertexNormalsWorld[1],ca),p(v,t.v3.positionWorld,t.vertexNormalsWorld[2],ma),la.r=(ca.r+ma.r)*0.5,la.g=(ca.g+ma.g)*0.5,la.b=(ca.b+ma.b)*0.5,ga=Ta(X,ca,ma,la),Pa(C,ea,S,P,k,M,0,0,1,0,0,1,ga)):(ia.r=ra.r,ia.g=ra.g,ia.b=ra.b,p(v,t.centroidWorld,t.normalWorld, +ia),U.r=Math.max(0,Math.min(u.color.r*ia.r,1)),U.g=Math.max(0,Math.min(u.color.g*ia.g,1)),U.b=Math.max(0,Math.min(u.color.b*ia.b,1)),u.wireframe?B(U,u.wireframeLinewidth,u.wireframeLinecap,u.wireframeLinejoin):Ha(U)):u.wireframe?B(u.color,u.wireframeLinewidth,u.wireframeLinecap,u.wireframeLinejoin):Ha(u.color);else if(u instanceof THREE.MeshDepthMaterial)K=o.near,V=o.far,X.r=X.g=X.b=1-Ma(b.positionScreen.z,K,V),ca.r=ca.g=ca.b=1-Ma(f.positionScreen.z,K,V),ma.r=ma.g=ma.b=1-Ma(h.positionScreen.z,K,V), +la.r=(ca.r+ma.r)*0.5,la.g=(ca.g+ma.g)*0.5,la.b=(ca.b+ma.b)*0.5,ga=Ta(X,ca,ma,la),Pa(C,ea,S,P,k,M,0,0,1,0,0,1,ga);else if(u instanceof THREE.MeshNormalMaterial)U.r=Qa(t.normalWorld.x),U.g=Qa(t.normalWorld.y),U.b=Qa(t.normalWorld.z),u.wireframe?B(U,u.wireframeLinewidth,u.wireframeLinecap,u.wireframeLinejoin):Ha(U)}function y(b,f,h,g,m,n,t,u,v){j.data.vertices+=4;j.data.faces++;c(u.opacity);e(u.blending);if(u.map||u.envMap)w(b,f,g,0,1,3,t,u,v),w(m,h,n,1,2,3,t,u,v);else if(C=b.positionScreen.x,ea=b.positionScreen.y, +S=f.positionScreen.x,P=f.positionScreen.y,k=h.positionScreen.x,M=h.positionScreen.y,Y=g.positionScreen.x,aa=g.positionScreen.y,Z=m.positionScreen.x,ha=m.positionScreen.y,ka=n.positionScreen.x,fa=n.positionScreen.y,u instanceof THREE.MeshBasicMaterial)x(C,ea,S,P,k,M,Y,aa),u.wireframe?B(u.color,u.wireframeLinewidth,u.wireframeLinecap,u.wireframeLinejoin):Ha(u.color);else if(u instanceof THREE.MeshLambertMaterial)ua?!u.wireframe&&u.shading==THREE.SmoothShading&&t.vertexNormalsWorld.length==4?(X.r=ca.r= +ma.r=la.r=ra.r,X.g=ca.g=ma.g=la.g=ra.g,X.b=ca.b=ma.b=la.b=ra.b,p(v,t.v1.positionWorld,t.vertexNormalsWorld[0],X),p(v,t.v2.positionWorld,t.vertexNormalsWorld[1],ca),p(v,t.v4.positionWorld,t.vertexNormalsWorld[3],ma),p(v,t.v3.positionWorld,t.vertexNormalsWorld[2],la),ga=Ta(X,ca,ma,la),z(C,ea,S,P,Y,aa),Pa(C,ea,S,P,Y,aa,0,0,1,0,0,1,ga),z(Z,ha,k,M,ka,fa),Pa(Z,ha,k,M,ka,fa,1,0,1,1,0,1,ga)):(ia.r=ra.r,ia.g=ra.g,ia.b=ra.b,p(v,t.centroidWorld,t.normalWorld,ia),U.r=Math.max(0,Math.min(u.color.r*ia.r,1)),U.g= +Math.max(0,Math.min(u.color.g*ia.g,1)),U.b=Math.max(0,Math.min(u.color.b*ia.b,1)),x(C,ea,S,P,k,M,Y,aa),u.wireframe?B(U,u.wireframeLinewidth,u.wireframeLinecap,u.wireframeLinejoin):Ha(U)):(x(C,ea,S,P,k,M,Y,aa),u.wireframe?B(u.color,u.wireframeLinewidth,u.wireframeLinecap,u.wireframeLinejoin):Ha(u.color));else if(u instanceof THREE.MeshNormalMaterial)U.r=Qa(t.normalWorld.x),U.g=Qa(t.normalWorld.y),U.b=Qa(t.normalWorld.z),x(C,ea,S,P,k,M,Y,aa),u.wireframe?B(U,u.wireframeLinewidth,u.wireframeLinecap,u.wireframeLinejoin): +Ha(U);else if(u instanceof THREE.MeshDepthMaterial)K=o.near,V=o.far,X.r=X.g=X.b=1-Ma(b.positionScreen.z,K,V),ca.r=ca.g=ca.b=1-Ma(f.positionScreen.z,K,V),ma.r=ma.g=ma.b=1-Ma(g.positionScreen.z,K,V),la.r=la.g=la.b=1-Ma(h.positionScreen.z,K,V),ga=Ta(X,ca,ma,la),z(C,ea,S,P,Y,aa),Pa(C,ea,S,P,Y,aa,0,0,1,0,0,1,ga),z(Z,ha,k,M,ka,fa),Pa(Z,ha,k,M,ka,fa,1,0,1,1,0,1,ga)}function z(b,e,c,f,h,g){u.beginPath();u.moveTo(b,e);u.lineTo(c,f);u.lineTo(h,g);u.lineTo(b,e);u.closePath()}function x(b,e,c,f,h,g,j,k){u.beginPath(); +u.moveTo(b,e);u.lineTo(c,f);u.lineTo(h,g);u.lineTo(j,k);u.lineTo(b,e);u.closePath()}function B(b,e,c,h){if(F!=e)u.lineWidth=F=e;if(J!=c)u.lineCap=J=c;if(D!=h)u.lineJoin=D=h;f(b.getContextStyle());u.stroke();na.inflate(e*2)}function Ha(b){g(b.getContextStyle());u.fill()}function H(b,e,c,f,h,j,k,m,o,n,t,va,p){if(p.image.width!=0){if(p.needsUpdate==!0||sa[p.id]==void 0){var v=p.wrapS==THREE.RepeatWrapping,Sa=p.wrapT==THREE.RepeatWrapping;sa[p.id]=u.createPattern(p.image,v&&Sa?"repeat":v&&!Sa?"repeat-x": +!v&&Sa?"repeat-y":"no-repeat");p.needsUpdate=!1}g(sa[p.id]);v=(p.image.width-1)*p.repeat.x;p=(p.image.height-1)*p.repeat.y;k*=v;m*=p;o*=v;n*=p;t*=v;va*=p;c-=b;f-=e;h-=b;j-=e;o-=k;n-=m;t-=k;va-=m;v=1/(o*va-t*n);p=(va*c-n*h)*v;n=(va*f-n*j)*v;c=(o*h-t*c)*v;f=(o*j-t*f)*v;b=b-p*k-c*m;e=e-n*k-f*m;u.save();u.transform(p,n,c,f,b,e);u.fill();u.restore()}}function Pa(b,e,c,f,h,g,j,k,m,o,n,t,p){var va,v;va=p.width-1;v=p.height-1;j*=va;k*=v;m*=va;o*=v;n*=va;t*=v;c-=b;f-=e;h-=b;g-=e;m-=j;o-=k;n-=j;t-=k;v=1/(m* +t-n*o);va=(t*c-o*h)*v;o=(t*f-o*g)*v;c=(m*h-n*c)*v;f=(m*g-n*f)*v;b=b-va*j-c*k;e=e-o*j-f*k;u.save();u.transform(va,o,c,f,b,e);u.clip();u.drawImage(p,0,0);u.restore()}function Ta(b,e,c,f){var h=~~(b.r*255),g=~~(b.g*255),b=~~(b.b*255),j=~~(e.r*255),k=~~(e.g*255),e=~~(e.b*255),m=~~(c.r*255),o=~~(c.g*255),c=~~(c.b*255),n=~~(f.r*255),u=~~(f.g*255),f=~~(f.b*255);Q[0]=h<0?0:h>255?255:h;Q[1]=g<0?0:g>255?255:g;Q[2]=b<0?0:b>255?255:b;Q[4]=j<0?0:j>255?255:j;Q[5]=k<0?0:k>255?255:k;Q[6]=e<0?0:e>255?255:e;Q[8]=m< +0?0:m>255?255:m;Q[9]=o<0?0:o>255?255:o;Q[10]=c<0?0:c>255?255:c;Q[12]=n<0?0:n>255?255:n;Q[13]=u<0?0:u>255?255:u;Q[14]=f<0?0:f>255?255:f;Da.putImageData($,0,0);O.drawImage(ya,0,0);return Ea}function Ma(b,e,c){b=(b-e)/(c-e);return b*b*(3-2*b)}function Qa(b){b=(b+1)*0.5;return b<0?0:b>1?1:b}function Ia(b,e){var c=e.x-b.x,f=e.y-b.y,h=c*c+f*f;h!=0&&(h=1/Math.sqrt(h),c*=h,f*=h,e.x+=c,e.y+=f,b.x-=c,b.y-=f)}var Ua,Xa,oa,Ca,Ja,Ra,Va,E;this.autoClear?this.clear():u.setTransform(1,0,0,-1,t,v);j.data.vertices= +0;j.data.faces=0;h=m.projectScene(b,o,this.sortElements);(ua=b.lights.length>0)&&n(b);Ua=0;for(Xa=h.length;Ua0&&(c.r+=g.color.r*j,c.g+=g.color.g*j,c.b+=g.color.b*j)):g instanceof THREE.PointLight&&(R.sub(g.position,e.centroidWorld),R.normalize(),j=e.normalWorld.dot(R)*g.intensity,j>0&&(c.r+=g.color.r*j,c.g+=g.color.g*j,c.b+=g.color.b*j))}function c(e,c,h,m,n,u){j.data.vertices+=3;j.data.faces++;C=f(ea++);C.setAttribute("d", "M "+e.positionScreen.x+" "+e.positionScreen.y+" L "+c.positionScreen.x+" "+c.positionScreen.y+" L "+h.positionScreen.x+","+h.positionScreen.y+"z");n instanceof THREE.MeshBasicMaterial?F.copy(n.color):n instanceof THREE.MeshLambertMaterial?B?(J.r=D.r,J.g=D.g,J.b=D.b,b(u,m,J),F.r=Math.max(0,Math.min(n.color.r*J.r,1)),F.g=Math.max(0,Math.min(n.color.g*J.g,1)),F.b=Math.max(0,Math.min(n.color.b*J.b,1))):F.copy(n.color):n instanceof THREE.MeshDepthMaterial?(I=1-n.__2near/(n.__farPlusNear-m.z*n.__farMinusNear), -F.setRGB(I,I,I)):n instanceof THREE.MeshNormalMaterial&&F.setRGB(g(m.normalWorld.x),g(m.normalWorld.y),g(m.normalWorld.z));n.wireframe?C.setAttribute("style","fill: none; stroke: "+F.getContextStyle()+"; stroke-width: "+n.wireframeLinewidth+"; stroke-opacity: "+n.opacity+"; stroke-linecap: "+n.wireframeLinecap+"; stroke-linejoin: "+n.wireframeLinejoin):C.setAttribute("style","fill: "+F.getContextStyle()+"; fill-opacity: "+n.opacity);p.appendChild(C)}function e(e,c,h,m,n,u,t){j.data.vertices+=4;j.data.faces++; +F.setRGB(I,I,I)):n instanceof THREE.MeshNormalMaterial&&F.setRGB(g(m.normalWorld.x),g(m.normalWorld.y),g(m.normalWorld.z));n.wireframe?C.setAttribute("style","fill: none; stroke: "+F.getContextStyle()+"; stroke-width: "+n.wireframeLinewidth+"; stroke-opacity: "+n.opacity+"; stroke-linecap: "+n.wireframeLinecap+"; stroke-linejoin: "+n.wireframeLinejoin):C.setAttribute("style","fill: "+F.getContextStyle()+"; fill-opacity: "+n.opacity);o.appendChild(C)}function e(e,c,h,m,n,u,t){j.data.vertices+=4;j.data.faces++; C=f(ea++);C.setAttribute("d","M "+e.positionScreen.x+" "+e.positionScreen.y+" L "+c.positionScreen.x+" "+c.positionScreen.y+" L "+h.positionScreen.x+","+h.positionScreen.y+" L "+m.positionScreen.x+","+m.positionScreen.y+"z");u instanceof THREE.MeshBasicMaterial?F.copy(u.color):u instanceof THREE.MeshLambertMaterial?B?(J.r=D.r,J.g=D.g,J.b=D.b,b(t,n,J),F.r=Math.max(0,Math.min(u.color.r*J.r,1)),F.g=Math.max(0,Math.min(u.color.g*J.g,1)),F.b=Math.max(0,Math.min(u.color.b*J.b,1))):F.copy(u.color):u instanceof THREE.MeshDepthMaterial?(I=1-u.__2near/(u.__farPlusNear-n.z*u.__farMinusNear),F.setRGB(I,I,I)):u instanceof THREE.MeshNormalMaterial&&F.setRGB(g(n.normalWorld.x),g(n.normalWorld.y),g(n.normalWorld.z));u.wireframe?C.setAttribute("style","fill: none; stroke: "+F.getContextStyle()+"; stroke-width: "+u.wireframeLinewidth+"; stroke-opacity: "+u.opacity+"; stroke-linecap: "+u.wireframeLinecap+"; stroke-linejoin: "+u.wireframeLinejoin):C.setAttribute("style","fill: "+F.getContextStyle()+"; fill-opacity: "+ -u.opacity);p.appendChild(C)}function f(b){da[b]==null&&(da[b]=document.createElementNS("http://www.w3.org/2000/svg","path"),P==0&&da[b].setAttribute("shape-rendering","crispEdges"));return da[b]}function g(b){b=(b+1)*0.5;return b<0?0:b>1?1:b}var j=this,h=null,m=new THREE.Projector,p=document.createElementNS("http://www.w3.org/2000/svg","svg"),n,o,t,v,u,w,z,y,x=new THREE.Rectangle,H=new THREE.Rectangle,B=!1,F=new THREE.Color(16777215),J=new THREE.Color(16777215),D=new THREE.Color(0),L=new THREE.Color(0), -G=new THREE.Color(0),I,R=new THREE.Vector3,da=[],T=[],C,ea,S,P=1;this.domElement=p;this.sortElements=this.sortObjects=this.autoClear=!0;this.data={vertices:0,faces:0};this.setQuality=function(b){switch(b){case "high":P=1;break;case "low":P=0}};this.setSize=function(b,e){n=b;o=e;t=n/2;v=o/2;p.setAttribute("viewBox",-t+" "+-v+" "+n+" "+o);p.setAttribute("width",n);p.setAttribute("height",o);x.set(-t,-v,t,v)};this.clear=function(){for(;p.childNodes.length>0;)p.removeChild(p.childNodes[0])};this.render= -function(b,f){var g,n,o,F,J,I,U,X;this.autoClear&&this.clear();j.data.vertices=0;j.data.faces=0;h=m.projectScene(b,f,this.sortElements);S=ea=0;if(B=b.lights.length>0){U=b.lights;D.setRGB(0,0,0);L.setRGB(0,0,0);G.setRGB(0,0,0);g=0;for(n=U.length;g1?1:b}var j=this,h=null,m=new THREE.Projector,o=document.createElementNS("http://www.w3.org/2000/svg","svg"),n,p,t,v,u,w,z,x,y=new THREE.Rectangle,H=new THREE.Rectangle,B=!1,F=new THREE.Color(16777215),J=new THREE.Color(16777215),D=new THREE.Color(0),L=new THREE.Color(0), +G=new THREE.Color(0),I,R=new THREE.Vector3,da=[],T=[],C,ea,S,P=1;this.domElement=o;this.sortElements=this.sortObjects=this.autoClear=!0;this.data={vertices:0,faces:0};this.setQuality=function(b){switch(b){case "high":P=1;break;case "low":P=0}};this.setSize=function(b,e){n=b;p=e;t=n/2;v=p/2;o.setAttribute("viewBox",-t+" "+-v+" "+n+" "+p);o.setAttribute("width",n);o.setAttribute("height",p);y.set(-t,-v,t,v)};this.clear=function(){for(;o.childNodes.length>0;)o.removeChild(o.childNodes[0])};this.render= +function(b,f){var g,n,p,F,J,I,U,X;this.autoClear&&this.clear();j.data.vertices=0;j.data.faces=0;h=m.projectScene(b,f,this.sortElements);S=ea=0;if(B=b.lights.length>0){U=b.lights;D.setRGB(0,0,0);L.setRGB(0,0,0);G.setRGB(0,0,0);g=0;for(n=U.length;g=0)k.bindBuffer(k.ARRAY_BUFFER,h.__webglVertexBuffer),k.vertexAttribPointer(b.position,3,k.FLOAT,!1,0,0);else if(j.morphTargetBase){c=g.program.attributes;j.morphTargetBase!==-1?(k.bindBuffer(k.ARRAY_BUFFER,h.__webglMorphTargetsBuffers[j.morphTargetBase]),k.vertexAttribPointer(c.position,3,k.FLOAT,!1,0,0)):c.position>=0&&(k.bindBuffer(k.ARRAY_BUFFER,h.__webglVertexBuffer),k.vertexAttribPointer(c.position,3,k.FLOAT,!1,0,0));if(j.morphTargetForcedOrder.length)for(var f= -0,n=j.morphTargetForcedOrder,p=j.morphTargetInfluences;fu&&(t=o,u=p[t]);k.bindBuffer(k.ARRAY_BUFFER,h.__webglMorphTargetsBuffers[t]); -k.vertexAttribPointer(c["morphTarget"+f],3,k.FLOAT,!1,0,0);j.__webglMorphTargetInfluences[f]=u;n[t]=1;u=-1;f++}}g.program.uniforms.morphTargetInfluences!==null&&k.uniform1fv(g.program.uniforms.morphTargetInfluences,j.__webglMorphTargetInfluences)}if(h.__webglCustomAttributes)for(m in h.__webglCustomAttributes)b[m]>=0&&(c=h.__webglCustomAttributes[m],k.bindBuffer(k.ARRAY_BUFFER,c.buffer),k.vertexAttribPointer(b[m],c.size,k.FLOAT,!1,0,0));b.color>=0&&(k.bindBuffer(k.ARRAY_BUFFER,h.__webglColorBuffer), -k.vertexAttribPointer(b.color,3,k.FLOAT,!1,0,0));b.normal>=0&&(k.bindBuffer(k.ARRAY_BUFFER,h.__webglNormalBuffer),k.vertexAttribPointer(b.normal,3,k.FLOAT,!1,0,0));b.tangent>=0&&(k.bindBuffer(k.ARRAY_BUFFER,h.__webglTangentBuffer),k.vertexAttribPointer(b.tangent,4,k.FLOAT,!1,0,0));b.uv>=0&&(h.__webglUVBuffer?(k.bindBuffer(k.ARRAY_BUFFER,h.__webglUVBuffer),k.vertexAttribPointer(b.uv,2,k.FLOAT,!1,0,0),k.enableVertexAttribArray(b.uv)):k.disableVertexAttribArray(b.uv));b.uv2>=0&&(h.__webglUV2Buffer?(k.bindBuffer(k.ARRAY_BUFFER, -h.__webglUV2Buffer),k.vertexAttribPointer(b.uv2,2,k.FLOAT,!1,0,0),k.enableVertexAttribArray(b.uv2)):k.disableVertexAttribArray(b.uv2));g.skinning&&b.skinVertexA>=0&&b.skinVertexB>=0&&b.skinIndex>=0&&b.skinWeight>=0&&(k.bindBuffer(k.ARRAY_BUFFER,h.__webglSkinVertexABuffer),k.vertexAttribPointer(b.skinVertexA,4,k.FLOAT,!1,0,0),k.bindBuffer(k.ARRAY_BUFFER,h.__webglSkinVertexBBuffer),k.vertexAttribPointer(b.skinVertexB,4,k.FLOAT,!1,0,0),k.bindBuffer(k.ARRAY_BUFFER,h.__webglSkinIndicesBuffer),k.vertexAttribPointer(b.skinIndex, -4,k.FLOAT,!1,0,0),k.bindBuffer(k.ARRAY_BUFFER,h.__webglSkinWeightsBuffer),k.vertexAttribPointer(b.skinWeight,4,k.FLOAT,!1,0,0));j instanceof THREE.Mesh?(g.wireframe?(k.lineWidth(g.wireframeLinewidth),k.bindBuffer(k.ELEMENT_ARRAY_BUFFER,h.__webglLineBuffer),k.drawElements(k.LINES,h.__webglLineCount,k.UNSIGNED_SHORT,0)):(k.bindBuffer(k.ELEMENT_ARRAY_BUFFER,h.__webglFaceBuffer),k.drawElements(k.TRIANGLES,h.__webglFaceCount,k.UNSIGNED_SHORT,0)),P.data.vertices+=h.__webglFaceCount,P.data.faces+=h.__webglFaceCount/ -3,P.data.drawCalls++):j instanceof THREE.Line?(j=j.type==THREE.LineStrip?k.LINE_STRIP:k.LINES,k.lineWidth(g.linewidth),k.drawArrays(j,0,h.__webglLineCount),P.data.drawCalls++):j instanceof THREE.ParticleSystem?(k.drawArrays(k.POINTS,0,h.__webglParticleCount),P.data.drawCalls++):j instanceof THREE.Ribbon&&(k.drawArrays(k.TRIANGLE_STRIP,0,h.__webglVertexCount),P.data.drawCalls++)}}function g(b,e,c){if(!b.__webglVertexBuffer)b.__webglVertexBuffer=k.createBuffer();if(!b.__webglNormalBuffer)b.__webglNormalBuffer= -k.createBuffer();b.hasPos&&(k.bindBuffer(k.ARRAY_BUFFER,b.__webglVertexBuffer),k.bufferData(k.ARRAY_BUFFER,b.positionArray,k.DYNAMIC_DRAW),k.enableVertexAttribArray(e.attributes.position),k.vertexAttribPointer(e.attributes.position,3,k.FLOAT,!1,0,0));if(b.hasNormal){k.bindBuffer(k.ARRAY_BUFFER,b.__webglNormalBuffer);if(c==THREE.FlatShading){var f,h,g,j,m,n,p,u,t,o,v=b.count*3;for(o=0;o=0)k.bindBuffer(k.ARRAY_BUFFER,g.__webglVertexBuffer),k.vertexAttribPointer(b.position,3,k.FLOAT,!1,0,0);else if(j.morphTargetBase){c=h.program.attributes;j.morphTargetBase!==-1?(k.bindBuffer(k.ARRAY_BUFFER,g.__webglMorphTargetsBuffers[j.morphTargetBase]),k.vertexAttribPointer(c.position,3,k.FLOAT,!1,0,0)):c.position>=0&&(k.bindBuffer(k.ARRAY_BUFFER,g.__webglVertexBuffer),k.vertexAttribPointer(c.position,3,k.FLOAT,!1,0,0));if(j.morphTargetForcedOrder.length)for(var f= +0,n=j.morphTargetForcedOrder,o=j.morphTargetInfluences;fu&&(t=p,u=o[t]);k.bindBuffer(k.ARRAY_BUFFER,g.__webglMorphTargetsBuffers[t]); +k.vertexAttribPointer(c["morphTarget"+f],3,k.FLOAT,!1,0,0);j.__webglMorphTargetInfluences[f]=u;n[t]=1;u=-1;f++}}h.program.uniforms.morphTargetInfluences!==null&&k.uniform1fv(h.program.uniforms.morphTargetInfluences,j.__webglMorphTargetInfluences)}if(g.__webglCustomAttributes)for(m in g.__webglCustomAttributes)b[m]>=0&&(c=g.__webglCustomAttributes[m],k.bindBuffer(k.ARRAY_BUFFER,c.buffer),k.vertexAttribPointer(b[m],c.size,k.FLOAT,!1,0,0));b.color>=0&&(k.bindBuffer(k.ARRAY_BUFFER,g.__webglColorBuffer), +k.vertexAttribPointer(b.color,3,k.FLOAT,!1,0,0));b.normal>=0&&(k.bindBuffer(k.ARRAY_BUFFER,g.__webglNormalBuffer),k.vertexAttribPointer(b.normal,3,k.FLOAT,!1,0,0));b.tangent>=0&&(k.bindBuffer(k.ARRAY_BUFFER,g.__webglTangentBuffer),k.vertexAttribPointer(b.tangent,4,k.FLOAT,!1,0,0));b.uv>=0&&(g.__webglUVBuffer?(k.bindBuffer(k.ARRAY_BUFFER,g.__webglUVBuffer),k.vertexAttribPointer(b.uv,2,k.FLOAT,!1,0,0),k.enableVertexAttribArray(b.uv)):k.disableVertexAttribArray(b.uv));b.uv2>=0&&(g.__webglUV2Buffer?(k.bindBuffer(k.ARRAY_BUFFER, +g.__webglUV2Buffer),k.vertexAttribPointer(b.uv2,2,k.FLOAT,!1,0,0),k.enableVertexAttribArray(b.uv2)):k.disableVertexAttribArray(b.uv2));h.skinning&&b.skinVertexA>=0&&b.skinVertexB>=0&&b.skinIndex>=0&&b.skinWeight>=0&&(k.bindBuffer(k.ARRAY_BUFFER,g.__webglSkinVertexABuffer),k.vertexAttribPointer(b.skinVertexA,4,k.FLOAT,!1,0,0),k.bindBuffer(k.ARRAY_BUFFER,g.__webglSkinVertexBBuffer),k.vertexAttribPointer(b.skinVertexB,4,k.FLOAT,!1,0,0),k.bindBuffer(k.ARRAY_BUFFER,g.__webglSkinIndicesBuffer),k.vertexAttribPointer(b.skinIndex, +4,k.FLOAT,!1,0,0),k.bindBuffer(k.ARRAY_BUFFER,g.__webglSkinWeightsBuffer),k.vertexAttribPointer(b.skinWeight,4,k.FLOAT,!1,0,0));j instanceof THREE.Mesh?(h.wireframe?(k.lineWidth(h.wireframeLinewidth),k.bindBuffer(k.ELEMENT_ARRAY_BUFFER,g.__webglLineBuffer),k.drawElements(k.LINES,g.__webglLineCount,k.UNSIGNED_SHORT,0)):(k.bindBuffer(k.ELEMENT_ARRAY_BUFFER,g.__webglFaceBuffer),k.drawElements(k.TRIANGLES,g.__webglFaceCount,k.UNSIGNED_SHORT,0)),P.data.vertices+=g.__webglFaceCount,P.data.faces+=g.__webglFaceCount/ +3,P.data.drawCalls++):j instanceof THREE.Line?(j=j.type==THREE.LineStrip?k.LINE_STRIP:k.LINES,k.lineWidth(h.linewidth),k.drawArrays(j,0,g.__webglLineCount),P.data.drawCalls++):j instanceof THREE.ParticleSystem?(k.drawArrays(k.POINTS,0,g.__webglParticleCount),P.data.drawCalls++):j instanceof THREE.Ribbon&&(k.drawArrays(k.TRIANGLE_STRIP,0,g.__webglVertexCount),P.data.drawCalls++)}}function g(b,c,e){if(!b.__webglVertexBuffer)b.__webglVertexBuffer=k.createBuffer();if(!b.__webglNormalBuffer)b.__webglNormalBuffer= +k.createBuffer();b.hasPos&&(k.bindBuffer(k.ARRAY_BUFFER,b.__webglVertexBuffer),k.bufferData(k.ARRAY_BUFFER,b.positionArray,k.DYNAMIC_DRAW),k.enableVertexAttribArray(c.attributes.position),k.vertexAttribPointer(c.attributes.position,3,k.FLOAT,!1,0,0));if(b.hasNormal){k.bindBuffer(k.ARRAY_BUFFER,b.__webglNormalBuffer);if(e==THREE.FlatShading){var f,g,h,j,m,n,o,u,t,p,v=b.count*3;for(p=0;p0&&w[0]0&&w[1]0&&w[0]0&&w[1]0.0010&&m.scale>0.0010)y[0]=m.x,y[1]=m.y,y[2]=m.z,t=m.size*m.scale/V,v[0]=t*p,v[1]=t,k.uniform3fv(x.screenPosition,y),k.uniform2fv(x.scale,v),k.uniform1f(x.rotation,m.rotation),k.uniform1f(x.opacity,m.opacity),I(m.blending),da(m.texture,1),k.drawElements(k.TRIANGLES,6,k.UNSIGNED_SHORT,0)}k.enable(k.CULL_FACE);k.enable(k.DEPTH_TEST);k.depthMask(Z)}function H(b,c,e){b._modelViewMatrix.multiplyToArray(c.matrixWorldInverse, -b.matrixWorld,b._modelViewMatrixArray);e&&THREE.Matrix4.makeInvert3x3(b._modelViewMatrix).transposeIntoArray(b._normalMatrixArray)}function B(b){var c,e,f,h;h=b.__materials;b=0;for(e=h.length;b0.0010&&m.scale>0.0010)y[0]=m.x,y[1]=m.y,y[2]=m.z,p=m.size*m.scale/V,v[0]=p*o,v[1]=p,k.uniform3fv(x.screenPosition,y),k.uniform2fv(x.scale,v),k.uniform1f(x.rotation,m.rotation),k.uniform1f(x.opacity,m.opacity),I(m.blending),da(m.texture,1),k.drawElements(k.TRIANGLES,6,k.UNSIGNED_SHORT,0)}k.enable(k.CULL_FACE);k.enable(k.DEPTH_TEST);k.depthMask(Z)}function H(b,c,e){b._modelViewMatrix.multiplyToArray(c.matrixWorldInverse, +b.matrixWorld,b._modelViewMatrixArray);e&&THREE.Matrix4.makeInvert3x3(b._modelViewMatrix).transposeIntoArray(b._normalMatrixArray)}function B(b){var c,e,f,g;g=b.__materials;b=0;for(e=g.length;b0&&(k.bindBuffer(k.ARRAY_BUFFER,g.__webglColorBuffer),k.bufferData(k.ARRAY_BUFFER,aa,m));ra&&(k.bindBuffer(k.ARRAY_BUFFER,g.__webglNormalBuffer),k.bufferData(k.ARRAY_BUFFER,ka,m));za&&ia.hasTangents&& -(k.bindBuffer(k.ARRAY_BUFFER,g.__webglTangentBuffer),k.bufferData(k.ARRAY_BUFFER,W,m));va&&X>0&&(k.bindBuffer(k.ARRAY_BUFFER,g.__webglUVBuffer),k.bufferData(k.ARRAY_BUFFER,da,m));va&&Q>0&&(k.bindBuffer(k.ARRAY_BUFFER,g.__webglUV2Buffer),k.bufferData(k.ARRAY_BUFFER,ea,m));pa&&(k.bindBuffer(k.ELEMENT_ARRAY_BUFFER,g.__webglFaceBuffer),k.bufferData(k.ELEMENT_ARRAY_BUFFER,qa,m),k.bindBuffer(k.ELEMENT_ARRAY_BUFFER,g.__webglLineBuffer),k.bufferData(k.ELEMENT_ARRAY_BUFFER,la,m));N>0&&(k.bindBuffer(k.ARRAY_BUFFER, -g.__webglSkinVertexABuffer),k.bufferData(k.ARRAY_BUFFER,Y,m),k.bindBuffer(k.ARRAY_BUFFER,g.__webglSkinVertexBBuffer),k.bufferData(k.ARRAY_BUFFER,fa,m),k.bindBuffer(k.ARRAY_BUFFER,g.__webglSkinIndicesBuffer),k.bufferData(k.ARRAY_BUFFER,ca,m),k.bindBuffer(k.ARRAY_BUFFER,g.__webglSkinWeightsBuffer),k.bufferData(k.ARRAY_BUFFER,$,m));j.dynamic||(delete g.__inittedArrays,delete g.__colorArray,delete g.__normalArray,delete g.__tangentArray,delete g.__uvArray,delete g.__uv2Array,delete g.__faceArray,delete g.__vertexArray, -delete g.__lineArray,delete g.__skinVertexAArray,delete g.__skinVertexBArray,delete g.__skinIndexArray,delete g.__skinWeightArray)}}f.__dirtyVertices=!1;f.__dirtyMorphTargets=!1;f.__dirtyElements=!1;f.__dirtyUvs=!1;f.__dirtyNormals=!1;f.__dirtyTangents=!1;f.__dirtyColors=!1;F(h)}else if(b instanceof THREE.Ribbon){f=b.geometry;if(f.__dirtyVertices||f.__dirtyColors){b=f;e=k.DYNAMIC_DRAW;x=b.vertices;g=b.colors;z=x.length;j=g.length;H=b.__vertexArray;m=b.__colorArray;G=b.__dirtyColors;if(b.__dirtyVertices){for(n= -0;n=0;e--)b[e].object==c&&b.splice(e,1)}function L(b){function e(b){var h=[];c=0;for(f=b.length;c65535&&(o[m].counter+=1,n=o[m].hash+"_"+o[m].counter,b.geometryGroups[n]==void 0&&(b.geometryGroups[n]={faces:[],materials:k,vertices:0,numMorphTargets:p})),b.geometryGroups[n].faces.push(h),b.geometryGroups[n].vertices+=j}function G(b,c,e){b.push({buffer:c,object:e,opaque:{list:[],count:0},transparent:{list:[], +7]=D.w,A.array[E+8]=I.x,A.array[E+9]=I.y,A.array[E+10]=I.z,A.array[E+11]=I.w,A.array[E+12]=V.x,A.array[E+13]=V.y,A.array[E+14]=V.z,A.array[E+15]=V.w,A.offset+=16));if(za){E=0;for(A=Fa.length;E0&&(k.bindBuffer(k.ARRAY_BUFFER,h.__webglColorBuffer),k.bufferData(k.ARRAY_BUFFER,aa,m));ra&&(k.bindBuffer(k.ARRAY_BUFFER,h.__webglNormalBuffer),k.bufferData(k.ARRAY_BUFFER,ka,m));Aa&&ia.hasTangents&& +(k.bindBuffer(k.ARRAY_BUFFER,h.__webglTangentBuffer),k.bufferData(k.ARRAY_BUFFER,W,m));wa&&X>0&&(k.bindBuffer(k.ARRAY_BUFFER,h.__webglUVBuffer),k.bufferData(k.ARRAY_BUFFER,da,m));wa&&Q>0&&(k.bindBuffer(k.ARRAY_BUFFER,h.__webglUV2Buffer),k.bufferData(k.ARRAY_BUFFER,ea,m));pa&&(k.bindBuffer(k.ELEMENT_ARRAY_BUFFER,h.__webglFaceBuffer),k.bufferData(k.ELEMENT_ARRAY_BUFFER,qa,m),k.bindBuffer(k.ELEMENT_ARRAY_BUFFER,h.__webglLineBuffer),k.bufferData(k.ELEMENT_ARRAY_BUFFER,la,m));N>0&&(k.bindBuffer(k.ARRAY_BUFFER, +h.__webglSkinVertexABuffer),k.bufferData(k.ARRAY_BUFFER,Y,m),k.bindBuffer(k.ARRAY_BUFFER,h.__webglSkinVertexBBuffer),k.bufferData(k.ARRAY_BUFFER,fa,m),k.bindBuffer(k.ARRAY_BUFFER,h.__webglSkinIndicesBuffer),k.bufferData(k.ARRAY_BUFFER,ca,m),k.bindBuffer(k.ARRAY_BUFFER,h.__webglSkinWeightsBuffer),k.bufferData(k.ARRAY_BUFFER,$,m));j.dynamic||(delete h.__inittedArrays,delete h.__colorArray,delete h.__normalArray,delete h.__tangentArray,delete h.__uvArray,delete h.__uv2Array,delete h.__faceArray,delete h.__vertexArray, +delete h.__lineArray,delete h.__skinVertexAArray,delete h.__skinVertexBArray,delete h.__skinIndexArray,delete h.__skinWeightArray)}}f.__dirtyVertices=!1;f.__dirtyMorphTargets=!1;f.__dirtyElements=!1;f.__dirtyUvs=!1;f.__dirtyNormals=!1;f.__dirtyTangents=!1;f.__dirtyColors=!1;F(g)}else if(b instanceof THREE.Ribbon){f=b.geometry;if(f.__dirtyVertices||f.__dirtyColors){b=f;e=k.DYNAMIC_DRAW;x=b.vertices;h=b.colors;z=x.length;j=h.length;H=b.__vertexArray;m=b.__colorArray;G=b.__dirtyColors;if(b.__dirtyVertices){for(n= +0;n=0;c--)b[c].object==e&&b.splice(c,1)}function L(b){function e(b){var h=[];c=0;for(f=b.length;c65535&&(t[m].counter+=1,n=t[m].hash+"_"+t[m].counter,b.geometryGroups[n]==void 0&&(b.geometryGroups[n]={faces:[],materials:k,vertices:0,numMorphTargets:o})),b.geometryGroups[n].faces.push(h),b.geometryGroups[n].vertices+=j}function G(b,c,e){b.push({buffer:c,object:e,opaque:{list:[],count:0},transparent:{list:[], count:0}})}function I(b){if(b!=fa){switch(b){case THREE.AdditiveBlending:k.blendEquation(k.FUNC_ADD);k.blendFunc(k.SRC_ALPHA,k.ONE);break;case THREE.SubtractiveBlending:k.blendEquation(k.FUNC_ADD);k.blendFunc(k.ZERO,k.ONE_MINUS_SRC_COLOR);break;case THREE.MultiplyBlending:k.blendEquation(k.FUNC_ADD);k.blendFunc(k.ZERO,k.SRC_COLOR);break;default:k.blendEquationSeparate(k.FUNC_ADD,k.FUNC_ADD),k.blendFuncSeparate(k.SRC_ALPHA,k.ONE_MINUS_SRC_ALPHA,k.ONE,k.ONE_MINUS_SRC_ALPHA)}fa=b}}function R(b,c,e){(e.width& e.width-1)==0&&(e.height&e.height-1)==0?(k.texParameteri(b,k.TEXTURE_WRAP_S,S(c.wrapS)),k.texParameteri(b,k.TEXTURE_WRAP_T,S(c.wrapT)),k.texParameteri(b,k.TEXTURE_MAG_FILTER,S(c.magFilter)),k.texParameteri(b,k.TEXTURE_MIN_FILTER,S(c.minFilter)),k.generateMipmap(b)):(k.texParameteri(b,k.TEXTURE_WRAP_S,k.CLAMP_TO_EDGE),k.texParameteri(b,k.TEXTURE_WRAP_T,k.CLAMP_TO_EDGE),k.texParameteri(b,k.TEXTURE_MAG_FILTER,ea(c.magFilter)),k.texParameteri(b,k.TEXTURE_MIN_FILTER,ea(c.minFilter)))}function da(b,c){if(b.needsUpdate){if(!b.__webglInit)b.__webglTexture= k.createTexture(),b.__webglInit=!0;k.bindTexture(k.TEXTURE_2D,b.__webglTexture);b.image.data?k.texImage2D(k.TEXTURE_2D,0,S(b.format),b.image.width,b.image.height,0,S(b.format),k.UNSIGNED_BYTE,b.image.data):k.texImage2D(k.TEXTURE_2D,0,k.RGBA,k.RGBA,k.UNSIGNED_BYTE,b.image);R(k.TEXTURE_2D,b,b.image);k.bindTexture(k.TEXTURE_2D,null);b.needsUpdate=!1}k.activeTexture(k.TEXTURE0+c);k.bindTexture(k.TEXTURE_2D,b.__webglTexture)}function T(b){if(b&&!b.__webglFramebuffer){if(b.depthBuffer===void 0)b.depthBuffer= @@ -306,9 +306,9 @@ k.DEPTH_STENCIL,b.width,b.height),k.framebufferRenderbuffer(k.FRAMEBUFFER,k.DEPT b=="vertex"&&(e=k.createShader(k.VERTEX_SHADER));k.shaderSource(e,c);k.compileShader(e);if(!k.getShaderParameter(e,k.COMPILE_STATUS))return console.error(k.getShaderInfoLog(e)),console.error(c),null;return e}function ea(b){switch(b){case THREE.NearestFilter:case THREE.NearestMipMapNearestFilter:case THREE.NearestMipMapLinearFilter:return k.NEAREST;default:return k.LINEAR}}function S(b){switch(b){case THREE.RepeatWrapping:return k.REPEAT;case THREE.ClampToEdgeWrapping:return k.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return k.MIRRORED_REPEAT; case THREE.NearestFilter:return k.NEAREST;case THREE.NearestMipMapNearestFilter:return k.NEAREST_MIPMAP_NEAREST;case THREE.NearestMipMapLinearFilter:return k.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return k.LINEAR;case THREE.LinearMipMapNearestFilter:return k.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return k.LINEAR_MIPMAP_LINEAR;case THREE.ByteType:return k.BYTE;case THREE.UnsignedByteType:return k.UNSIGNED_BYTE;case THREE.ShortType:return k.SHORT;case THREE.UnsignedShortType:return k.UNSIGNED_SHORT; case THREE.IntType:return k.INT;case THREE.UnsignedShortType:return k.UNSIGNED_INT;case THREE.FloatType:return k.FLOAT;case THREE.AlphaFormat:return k.ALPHA;case THREE.RGBFormat:return k.RGB;case THREE.RGBAFormat:return k.RGBA;case THREE.LuminanceFormat:return k.LUMINANCE;case THREE.LuminanceAlphaFormat:return k.LUMINANCE_ALPHA}return 0}var P=this,k,M=[],Y=null,aa=null,Z=!0,ha=null,ka=null,fa=null,U=null,X=null,ca=null,ma=null,la=0,sa=0,K=0,V=0,ga=[new THREE.Vector4,new THREE.Vector4,new THREE.Vector4, -new THREE.Vector4,new THREE.Vector4,new THREE.Vector4],ja=new THREE.Matrix4,qa=new Float32Array(16),va=new Float32Array(16),za=new THREE.Vector4,La={ambient:[0,0,0],directional:{length:0,colors:[],positions:[]},point:{length:0,colors:[],positions:[],distances:[]}},b=b||{},ya=b.canvas!==void 0?b.canvas:document.createElement("canvas"),Oa=b.stencil!==void 0?b.stencil:!0,W=b.preserveDrawingBuffer!==void 0?b.preserveDrawingBuffer:!1,ta=b.antialias!==void 0?b.antialias:!1,na=b.clearColor!==void 0?new THREE.Color(b.clearColor): -new THREE.Color(0),ua=b.clearAlpha!==void 0?b.clearAlpha:0;this.data={vertices:0,faces:0,drawCalls:0};this.maxMorphTargets=8;this.domElement=ya;this.sortObjects=this.autoClear=!0;this.shadowMapBias=0.0039;this.shadowMapDarkness=0.5;this.shadowMapHeight=this.shadowMapWidth=512;this.shadowCameraNear=1;this.shadowCameraFar=5E3;this.shadowCameraFov=50;this.shadowMap=[];this.shadowMapEnabled=!1;this.shadowMapSoft=!0;var ia,ra=[],b=THREE.ShaderLib.depthRGBA,wa=THREE.UniformsUtils.clone(b.uniforms),Ba=new THREE.MeshShaderMaterial({fragmentShader:b.fragmentShader, -vertexShader:b.vertexShader,uniforms:wa}),pa=new THREE.MeshShaderMaterial({fragmentShader:b.fragmentShader,vertexShader:b.vertexShader,uniforms:wa,morphTargets:!0});Ba._shadowPass=!0;pa._shadowPass=!0;try{if(!(k=ya.getContext("experimental-webgl",{antialias:ta,stencil:Oa,preserveDrawingBuffer:W})))throw"Error creating WebGL context.";console.log(navigator.userAgent+" | "+k.getParameter(k.VERSION)+" | "+k.getParameter(k.VENDOR)+" | "+k.getParameter(k.RENDERER)+" | "+k.getParameter(k.SHADING_LANGUAGE_VERSION))}catch(xa){console.error(xa)}k.clearColor(0, +new THREE.Vector4,new THREE.Vector4,new THREE.Vector4],ja=new THREE.Matrix4,qa=new Float32Array(16),wa=new Float32Array(16),Aa=new THREE.Vector4,La={ambient:[0,0,0],directional:{length:0,colors:[],positions:[]},point:{length:0,colors:[],positions:[],distances:[]}},b=b||{},za=b.canvas!==void 0?b.canvas:document.createElement("canvas"),Oa=b.stencil!==void 0?b.stencil:!0,W=b.preserveDrawingBuffer!==void 0?b.preserveDrawingBuffer:!1,ta=b.antialias!==void 0?b.antialias:!1,na=b.clearColor!==void 0?new THREE.Color(b.clearColor): +new THREE.Color(0),ua=b.clearAlpha!==void 0?b.clearAlpha:0;this.data={vertices:0,faces:0,drawCalls:0};this.maxMorphTargets=8;this.domElement=za;this.sortObjects=this.autoClear=!0;this.shadowMapBias=0.0039;this.shadowMapDarkness=0.5;this.shadowMapHeight=this.shadowMapWidth=512;this.shadowCameraNear=1;this.shadowCameraFar=5E3;this.shadowCameraFov=50;this.shadowMap=[];this.shadowMapEnabled=!1;this.shadowMapSoft=!0;var ia,ra=[],b=THREE.ShaderLib.depthRGBA,xa=THREE.UniformsUtils.clone(b.uniforms),Ba=new THREE.MeshShaderMaterial({fragmentShader:b.fragmentShader, +vertexShader:b.vertexShader,uniforms:xa}),pa=new THREE.MeshShaderMaterial({fragmentShader:b.fragmentShader,vertexShader:b.vertexShader,uniforms:xa,morphTargets:!0});Ba._shadowPass=!0;pa._shadowPass=!0;try{if(!(k=za.getContext("experimental-webgl",{antialias:ta,stencil:Oa,preserveDrawingBuffer:W})))throw"Error creating WebGL context.";console.log(navigator.userAgent+" | "+k.getParameter(k.VERSION)+" | "+k.getParameter(k.VENDOR)+" | "+k.getParameter(k.RENDERER)+" | "+k.getParameter(k.SHADING_LANGUAGE_VERSION))}catch(ya){console.error(ya)}k.clearColor(0, 0,0,1);k.clearDepth(1);k.enable(k.DEPTH_TEST);k.depthFunc(k.LEQUAL);k.frontFace(k.CCW);k.cullFace(k.BACK);k.enable(k.CULL_FACE);k.enable(k.BLEND);k.blendEquation(k.FUNC_ADD);k.blendFunc(k.SRC_ALPHA,k.ONE_MINUS_SRC_ALPHA);k.clearColor(na.r,na.g,na.b,ua);this.context=k;var Da=k.getParameter(k.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0;if(Oa){var $={};$.vertices=new Float32Array(12);$.faces=new Uint16Array(6);$.darkness=0.5;$.vertices[0]=-20;$.vertices[1]=-20;$.vertices[2]=-1;$.vertices[3]=20;$.vertices[4]=-20; $.vertices[5]=-1;$.vertices[6]=20;$.vertices[7]=20;$.vertices[8]=-1;$.vertices[9]=-20;$.vertices[10]=20;$.vertices[11]=-1;$.faces[0]=0;$.faces[1]=1;$.faces[2]=2;$.faces[3]=0;$.faces[4]=2;$.faces[5]=3;$.vertexBuffer=k.createBuffer();$.elementBuffer=k.createBuffer();k.bindBuffer(k.ARRAY_BUFFER,$.vertexBuffer);k.bufferData(k.ARRAY_BUFFER,$.vertices,k.STATIC_DRAW);k.bindBuffer(k.ELEMENT_ARRAY_BUFFER,$.elementBuffer);k.bufferData(k.ELEMENT_ARRAY_BUFFER,$.faces,k.STATIC_DRAW);$.program=k.createProgram(); k.attachShader($.program,C("fragment",THREE.ShaderLib.shadowPost.fragmentShader));k.attachShader($.program,C("vertex",THREE.ShaderLib.shadowPost.vertexShader));k.linkProgram($.program);$.vertexLocation=k.getAttribLocation($.program,"position");$.projectionLocation=k.getUniformLocation($.program,"projectionMatrix");$.darknessLocation=k.getUniformLocation($.program,"darkness")}var Q={};Q.vertices=new Float32Array(16);Q.faces=new Uint16Array(6);W=0;Q.vertices[W++]=-1;Q.vertices[W++]=-1;Q.vertices[W++]= @@ -320,31 +320,31 @@ k.getAttribLocation(Q.program,"UV");Q.uniforms.renderType=k.getUniformLocation(Q new Float32Array(16);O.faces=new Uint16Array(6);W=0;O.vertices[W++]=-1;O.vertices[W++]=-1;O.vertices[W++]=0;O.vertices[W++]=1;O.vertices[W++]=1;O.vertices[W++]=-1;O.vertices[W++]=1;O.vertices[W++]=1;O.vertices[W++]=1;O.vertices[W++]=1;O.vertices[W++]=1;O.vertices[W++]=0;O.vertices[W++]=-1;O.vertices[W++]=1;O.vertices[W++]=0;W=O.vertices[W++]=0;O.faces[W++]=0;O.faces[W++]=1;O.faces[W++]=2;O.faces[W++]=0;O.faces[W++]=2;O.faces[W++]=3;O.vertexBuffer=k.createBuffer();O.elementBuffer=k.createBuffer(); k.bindBuffer(k.ARRAY_BUFFER,O.vertexBuffer);k.bufferData(k.ARRAY_BUFFER,O.vertices,k.STATIC_DRAW);k.bindBuffer(k.ELEMENT_ARRAY_BUFFER,O.elementBuffer);k.bufferData(k.ELEMENT_ARRAY_BUFFER,O.faces,k.STATIC_DRAW);O.program=k.createProgram();k.attachShader(O.program,C("fragment",THREE.ShaderLib.sprite.fragmentShader));k.attachShader(O.program,C("vertex",THREE.ShaderLib.sprite.vertexShader));k.linkProgram(O.program);O.attributes={};O.uniforms={};O.attributes.position=k.getAttribLocation(O.program,"position"); O.attributes.uv=k.getAttribLocation(O.program,"uv");O.uniforms.uvOffset=k.getUniformLocation(O.program,"uvOffset");O.uniforms.uvScale=k.getUniformLocation(O.program,"uvScale");O.uniforms.rotation=k.getUniformLocation(O.program,"rotation");O.uniforms.scale=k.getUniformLocation(O.program,"scale");O.uniforms.alignment=k.getUniformLocation(O.program,"alignment");O.uniforms.map=k.getUniformLocation(O.program,"map");O.uniforms.opacity=k.getUniformLocation(O.program,"opacity");O.uniforms.useScreenCoordinates= -k.getUniformLocation(O.program,"useScreenCoordinates");O.uniforms.affectedByDistance=k.getUniformLocation(O.program,"affectedByDistance");O.uniforms.screenPosition=k.getUniformLocation(O.program,"screenPosition");O.uniforms.modelViewMatrix=k.getUniformLocation(O.program,"modelViewMatrix");O.uniforms.projectionMatrix=k.getUniformLocation(O.program,"projectionMatrix");var Wa=!1;this.setSize=function(b,c){ya.width=b;ya.height=c;this.setViewport(0,0,ya.width,ya.height)};this.setViewport=function(b,c, +k.getUniformLocation(O.program,"useScreenCoordinates");O.uniforms.affectedByDistance=k.getUniformLocation(O.program,"affectedByDistance");O.uniforms.screenPosition=k.getUniformLocation(O.program,"screenPosition");O.uniforms.modelViewMatrix=k.getUniformLocation(O.program,"modelViewMatrix");O.uniforms.projectionMatrix=k.getUniformLocation(O.program,"projectionMatrix");var Wa=!1;this.setSize=function(b,c){za.width=b;za.height=c;this.setViewport(0,0,za.width,za.height)};this.setViewport=function(b,c, e,f){la=b;sa=c;K=e;V=f;k.viewport(la,sa,K,V)};this.setScissor=function(b,c,e,f){k.scissor(b,c,e,f)};this.enableScissorTest=function(b){b?k.enable(k.SCISSOR_TEST):k.disable(k.SCISSOR_TEST)};this.enableDepthBufferWrite=function(b){Z=b;k.depthMask(b)};this.setClearColorHex=function(b,c){na.setHex(b);ua=c;k.clearColor(na.r,na.g,na.b,ua)};this.setClearColor=function(b,c){na.copy(b);ua=c;k.clearColor(na.r,na.g,na.b,ua)};this.clear=function(){k.clear(k.COLOR_BUFFER_BIT|k.DEPTH_BUFFER_BIT|k.STENCIL_BUFFER_BIT)}; this.setStencilShadowDarkness=function(b){$.darkness=b};this.getContext=function(){return k};this.initMaterial=function(b,c,e,f){var h,g,j;b instanceof THREE.MeshDepthMaterial?j="depth":b instanceof THREE.ShadowVolumeDynamicMaterial?j="shadowVolumeDynamic":b instanceof THREE.MeshNormalMaterial?j="normal":b instanceof THREE.MeshBasicMaterial?j="basic":b instanceof THREE.MeshLambertMaterial?j="lambert":b instanceof THREE.MeshPhongMaterial?j="phong":b instanceof THREE.LineBasicMaterial?j="basic":b instanceof -THREE.ParticleBasicMaterial&&(j="particle_basic");if(j){var m=THREE.ShaderLib[j];b.uniforms=THREE.UniformsUtils.clone(m.uniforms);b.vertexShader=m.vertexShader;b.fragmentShader=m.fragmentShader}var n,o,p;n=p=m=0;for(o=c.length;n=0&&k.enableVertexAttribArray(t.position);t.color>=0&&k.enableVertexAttribArray(t.color);t.normal>=0&&k.enableVertexAttribArray(t.normal);t.tangent>=0&&k.enableVertexAttribArray(t.tangent);b.skinning&&t.skinVertexA>=0&&t.skinVertexB>=0&&t.skinIndex>=0&&t.skinWeight>=0&&(k.enableVertexAttribArray(t.skinVertexA),k.enableVertexAttribArray(t.skinVertexB),k.enableVertexAttribArray(t.skinIndex), -k.enableVertexAttribArray(t.skinWeight));if(b.attributes)for(h in b.attributes)t[h]!==void 0&&t[h]>=0&&k.enableVertexAttribArray(t[h]);if(b.morphTargets)for(h=b.numSupportedMorphTargets=0;h=0&&(k.enableVertexAttribArray(t[w]),b.numSupportedMorphTargets++)};this.render=function(b,c,o,B){var K,C,F,D,G,J,V,L,M=b.lights,ga=b.fog;this.shadowMapEnabled&&w(b,c);P.data.vertices=0;P.data.faces=0;P.data.drawCalls=0;c.matrixAutoUpdate&&c.update(void 0,!0);b.update(void 0, -!1,c);c.matrixWorldInverse.flattenToArray(va);c.projectionMatrix.flattenToArray(qa);ja.multiply(c.projectionMatrix,c.matrixWorldInverse);p(ja);this.initWebGLObjects(b);T(o);(this.autoClear||B)&&this.clear();G=b.__webglObjects.length;for(B=0;B=0&&k.enableVertexAttribArray(p.position);p.color>=0&&k.enableVertexAttribArray(p.color);p.normal>=0&&k.enableVertexAttribArray(p.normal);p.tangent>=0&&k.enableVertexAttribArray(p.tangent);b.skinning&&p.skinVertexA>=0&&p.skinVertexB>=0&&p.skinIndex>=0&&p.skinWeight>=0&&(k.enableVertexAttribArray(p.skinVertexA),k.enableVertexAttribArray(p.skinVertexB),k.enableVertexAttribArray(p.skinIndex), +k.enableVertexAttribArray(p.skinWeight));if(b.attributes)for(h in b.attributes)p[h]!==void 0&&p[h]>=0&&k.enableVertexAttribArray(p[h]);if(b.morphTargets)for(h=b.numSupportedMorphTargets=0;h=0&&(k.enableVertexAttribArray(p[w]),b.numSupportedMorphTargets++)};this.render=function(b,c,p,B){var K,C,F,D,G,J,V,L,M=b.lights,ga=b.fog;this.shadowMapEnabled&&w(b,c);P.data.vertices=0;P.data.faces=0;P.data.drawCalls=0;c.matrixAutoUpdate&&c.update(void 0,!0);b.update(void 0, +!1,c);c.matrixWorldInverse.flattenToArray(wa);c.projectionMatrix.flattenToArray(qa);ja.multiply(c.projectionMatrix,c.matrixWorldInverse);o(ja);this.initWebGLObjects(b);T(p);(this.autoClear||B)&&this.clear();G=b.__webglObjects.length;for(B=0;B=0;B--)if(K=b.__webglObjects[B],K.render){V=K.object;L=K.buffer;F=K.opaque;j(V);for(K=0;K0||u.faceVertexUvs.length>0)j.__uvArray=new Float32Array(n*2);if(u.faceUvs.length>1||u.faceVertexUvs.length> +k.createBuffer();j.__webglLineBuffer=k.createBuffer();if(j.numMorphTargets){var m=void 0,n=void 0;j.__webglMorphTargetsBuffers=[];m=0;for(n=j.numMorphTargets;m0||u.faceVertexUvs.length>0)j.__uvArray=new Float32Array(n*2);if(u.faceUvs.length>1||u.faceVertexUvs.length> 1)j.__uv2Array=new Float32Array(n*2)}if(m.geometry.skinWeights.length&&m.geometry.skinIndices.length)j.__skinVertexAArray=new Float32Array(n*4),j.__skinVertexBArray=new Float32Array(n*4),j.__skinIndexArray=new Float32Array(n*4),j.__skinWeightArray=new Float32Array(n*4);j.__faceArray=new Uint16Array(w*3+(m.geometry.edgeFaces?m.geometry.edgeFaces.length*6:0));j.__lineArray=new Uint16Array(y*2);if(j.numMorphTargets){j.__morphTargetsArrays=[];u=0;for(v=j.numMorphTargets;u1&&(e-=1)}c===void 0&&(c={h:0,s:0,v:0});c.h=e;c.s=h;c.v=j;return c}, clamp:function(b,c,e){return be?e:b}};THREE.ColorUtils.__hsv={h:0,s:0,v:0}; -THREE.GeometryUtils={merge:function(b,c){var e=c instanceof THREE.Mesh,f=b.vertices.length,g=e?c.geometry:c,j=b.vertices,h=g.vertices,m=b.faces,p=g.faces,n=b.faceVertexUvs[0],g=g.faceVertexUvs[0];e&&c.matrixAutoUpdate&&c.updateMatrix();for(var o=0,t=h.length;o1&&(f=1-f,g=1-g);j=1-f-g;h.copy(b);h.multiplyScalar(f);m.copy(c);m.multiplyScalar(g);h.addSelf(m);m.copy(e);m.multiplyScalar(j);h.addSelf(m);return h},randomPointInFace:function(b, +THREE.GeometryUtils={merge:function(b,c){var e=c instanceof THREE.Mesh,f=b.vertices.length,g=e?c.geometry:c,j=b.vertices,h=g.vertices,m=b.faces,o=g.faces,n=b.faceVertexUvs[0],g=g.faceVertexUvs[0];e&&c.matrixAutoUpdate&&c.updateMatrix();for(var p=0,t=h.length;p1&&(f=1-f,g=1-g);j=1-f-g;h.copy(b);h.multiplyScalar(f);m.copy(c);m.multiplyScalar(g);h.addSelf(m);m.copy(e);m.multiplyScalar(j);h.addSelf(m);return h},randomPointInFace:function(b, c,e){var f,g,j;if(b instanceof THREE.Face3)return f=c.vertices[b.a].position,g=c.vertices[b.b].position,j=c.vertices[b.c].position,THREE.GeometryUtils.randomPointInTriangle(f,g,j);else if(b instanceof THREE.Face4){f=c.vertices[b.a].position;g=c.vertices[b.b].position;j=c.vertices[b.c].position;var c=c.vertices[b.d].position,h;e?b._area1&&b._area2?(e=b._area1,h=b._area2):(e=THREE.GeometryUtils.triangleArea(f,g,c),h=THREE.GeometryUtils.triangleArea(g,j,c),b._area1=e,b._area2=h):(e=THREE.GeometryUtils.triangleArea(f, -g,c),h=THREE.GeometryUtils.triangleArea(g,j,c));return THREE.GeometryUtils.random()*(e+h)b?e(c,h-1):n[h]b?e(c,h-1):n[h]25&&(j=25);g=(j-1)*0.5;e=Array(j);for(c=f=0;c1)console.log("THREE.Animation.update: Warning! Scale out of bounds:"+f+" on bone "+u),f=f<0?0:1;if(e==="pos")if(e=b.position,this.interpolationType===THREE.AnimationHandler.LINEAR)e.x=g[0]+(j[0]-g[0])*f,e.y=g[1]+(j[1]-g[1])*f,e.z=g[2]+(j[2]-g[2])*f;else{if(this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD)if(this.points[0]= +THREE.Animation.prototype.update=function(b){if(this.isPlaying){var c=["pos","rot","scl"],e,f,g,j,h,m,o,n,p=this.data.JIT.hierarchy,t,v;this.currentTime+=b*this.timeScale;v=this.currentTime;t=this.currentTime%=this.data.length;n=parseInt(Math.min(t*this.data.fps,this.data.length*this.data.fps),10);for(var u=0,w=this.hierarchy.length;u1)console.log("THREE.Animation.update: Warning! Scale out of bounds:"+f+" on bone "+u),f=f<0?0:1;if(e==="pos")if(e=b.position,this.interpolationType===THREE.AnimationHandler.LINEAR)e.x=g[0]+(j[0]-g[0])*f,e.y=g[1]+(j[1]-g[1])*f,e.z=g[2]+(j[2]-g[2])*f;else{if(this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD)if(this.points[0]= this.getPrevKeyWith("pos",u,h.index-1).pos,this.points[1]=g,this.points[2]=j,this.points[3]=this.getNextKeyWith("pos",u,m.index+1).pos,f=f*0.33+0.33,g=this.interpolateCatmullRom(this.points,f),e.x=g[0],e.y=g[1],e.z=g[2],this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD)f=this.interpolateCatmullRom(this.points,f*1.01),this.target.set(f[0],f[1],f[2]),this.target.subSelf(e),this.target.y=0,this.target.normalize(),f=Math.atan2(this.target.x,this.target.z),b.rotation.set(0,f,0)}else if(e=== -"rot")THREE.Quaternion.slerp(g,j,b.quaternion,f);else if(e==="scl")e=b.scale,e.x=g[0]+(j[0]-g[0])*f,e.y=g[1]+(j[1]-g[1])*f,e.z=g[2]+(j[2]-g[2])*f}}if(this.JITCompile&&o[0][n]===void 0){this.hierarchy[0].update(void 0,!0);for(u=0;ub.length-2?j:j+1;e[3]=j>b.length-3?j:j+2;j=b[e[0]];m=b[e[1]];p=b[e[2]];n=b[e[3]];e=g*g;h=g*e;f[0]=this.interpolate(j[0],m[0],p[0],n[0],g,e,h);f[1]=this.interpolate(j[1],m[1],p[1],n[1],g,e,h);f[2]=this.interpolate(j[2],m[2],p[2],n[2],g,e,h);return f}; +"rot")THREE.Quaternion.slerp(g,j,b.quaternion,f);else if(e==="scl")e=b.scale,e.x=g[0]+(j[0]-g[0])*f,e.y=g[1]+(j[1]-g[1])*f,e.z=g[2]+(j[2]-g[2])*f}}if(this.JITCompile&&p[0][n]===void 0){this.hierarchy[0].update(void 0,!0);for(u=0;ub.length-2?j:j+1;e[3]=j>b.length-3?j:j+2;j=b[e[0]];m=b[e[1]];o=b[e[2]];n=b[e[3]];e=g*g;h=g*e;f[0]=this.interpolate(j[0],m[0],o[0],n[0],g,e,h);f[1]=this.interpolate(j[1],m[1],o[1],n[1],g,e,h);f[2]=this.interpolate(j[2],m[2],o[2],n[2],g,e,h);return f}; THREE.Animation.prototype.interpolate=function(b,c,e,f,g,j,h){b=(e-b)*0.5;f=(f-c)*0.5;return(2*(c-e)+b+f)*h+(-3*(c-e)-2*b-f)*j+b*g+c};THREE.Animation.prototype.getNextKeyWith=function(b,c,e){var f=this.data.hierarchy[c].keys;for(this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD?e=e0?e:0:e>=0?e:e+f.length;e>=0;e--)if(f[e][b]!==void 0)return f[e];return this.data.hierarchy[c].keys[f.length-1]}; THREE.FirstPersonCamera=function(b){function c(b,c){return function(){c.apply(b,arguments)}}THREE.Camera.call(this,b.fov,b.aspect,b.near,b.far,b.target);this.movementSpeed=1;this.lookSpeed=0.0050;this.noFly=!1;this.lookVertical=!0;this.autoForward=!1;this.activeLook=!0;this.heightSpeed=!1;this.heightCoef=1;this.heightMin=0;this.constrainVertical=!1;this.verticalMin=0;this.verticalMax=3.14;this.domElement=document;this.lastUpdate=(new Date).getTime();this.tdiff=0;if(b){if(b.movementSpeed!==void 0)this.movementSpeed= @@ -406,14 +406,14 @@ this.moveRight&&this.translateX(c);this.moveUp&&this.translateY(c);this.moveDown 1;this.constrainVertical&&(b=3.14/(this.verticalMax-this.verticalMin));this.lon+=this.mouseX*c;this.lookVertical&&(this.lat-=this.mouseY*c*b);this.lat=Math.max(-85,Math.min(85,this.lat));this.phi=(90-this.lat)*Math.PI/180;this.theta=this.lon*Math.PI/180;if(this.constrainVertical)this.phi=(this.phi-0)*(this.verticalMax-this.verticalMin)/3.14+this.verticalMin;b=this.target.position;g=this.position;b.x=g.x+100*Math.sin(this.phi)*Math.cos(this.theta);b.y=g.y+100*Math.cos(this.phi);b.z=g.z+100*Math.sin(this.phi)* Math.sin(this.theta);this.supr.update.call(this)};this.domElement.addEventListener("contextmenu",function(b){b.preventDefault()},!1);this.domElement.addEventListener("mousemove",c(this,this.onMouseMove),!1);this.domElement.addEventListener("mousedown",c(this,this.onMouseDown),!1);this.domElement.addEventListener("mouseup",c(this,this.onMouseUp),!1);this.domElement.addEventListener("keydown",c(this,this.onKeyDown),!1);this.domElement.addEventListener("keyup",c(this,this.onKeyUp),!1)}; THREE.FirstPersonCamera.prototype=new THREE.Camera;THREE.FirstPersonCamera.prototype.constructor=THREE.FirstPersonCamera;THREE.FirstPersonCamera.prototype.supr=THREE.Camera.prototype;THREE.FirstPersonCamera.prototype.translate=function(b,c){this.matrix.rotateAxis(c);if(this.noFly)c.y=0;this.position.addSelf(c.multiplyScalar(b));this.target.position.addSelf(c.multiplyScalar(b))}; -THREE.PathCamera=function(b){function c(b,e,c,f){var h={name:c,fps:0.6,length:f,hierarchy:[]},g,j=e.getControlPointsArray(),m=e.getLength(),p=j.length,H=0;g=p-1;e={parent:-1,keys:[]};e.keys[0]={time:0,pos:j[0],rot:[0,0,0,1],scl:[1,1,1]};e.keys[g]={time:f,pos:j[g],rot:[0,0,0,1],scl:[1,1,1]};for(g=1;g=0?f:f+g;f=this.verticalAngleMap.srcRange;h=this.verticalAngleMap.dstRange;var m=h[1]-h[0];this.phi= TWEEN.Easing.Quadratic.EaseInOut(((this.phi-f[0])*(h[1]-h[0])/(f[1]-f[0])+h[0]-h[0])/m)*m+h[0];f=this.horizontalAngleMap.srcRange;h=this.horizontalAngleMap.dstRange;m=h[1]-h[0];this.theta=TWEEN.Easing.Quadratic.EaseInOut(((this.theta-f[0])*(h[1]-h[0])/(f[1]-f[0])+h[0]-h[0])/m)*m+h[0];f=this.target.position;f.x=100*Math.sin(this.phi)*Math.cos(this.theta);f.y=100*Math.cos(this.phi);f.z=100*Math.sin(this.phi)*Math.sin(this.theta);this.supr.update.call(this,b,e,c)};this.onMouseMove=function(b){this.mouseX= -b.clientX-this.windowHalfX;this.mouseY=b.clientY-this.windowHalfY};this.spline=new THREE.Spline;this.spline.initFromArray(this.waypoints);this.useConstantSpeed&&this.spline.reparametrizeByArcLength(this.resamplingCoef);if(this.createDebugDummy){var b=new THREE.MeshLambertMaterial({color:30719}),h=new THREE.MeshLambertMaterial({color:65280}),m=new THREE.CubeGeometry(10,10,20),p=new THREE.CubeGeometry(2,2,10);this.animationParent=new THREE.Mesh(m,b);b=new THREE.Mesh(p,h);b.position.set(0,10,0);this.animation= +b.clientX-this.windowHalfX;this.mouseY=b.clientY-this.windowHalfY};this.spline=new THREE.Spline;this.spline.initFromArray(this.waypoints);this.useConstantSpeed&&this.spline.reparametrizeByArcLength(this.resamplingCoef);if(this.createDebugDummy){var b=new THREE.MeshLambertMaterial({color:30719}),h=new THREE.MeshLambertMaterial({color:65280}),m=new THREE.CubeGeometry(10,10,20),o=new THREE.CubeGeometry(2,2,10);this.animationParent=new THREE.Mesh(m,b);b=new THREE.Mesh(o,h);b.position.set(0,10,0);this.animation= c(this.animationParent,this.spline,this.id,this.duration);this.animationParent.addChild(this);this.animationParent.addChild(this.target);this.animationParent.addChild(b)}else this.animation=c(this.animationParent,this.spline,this.id,this.duration),this.animationParent.addChild(this.target),this.animationParent.addChild(this);this.createDebugPath&&f(this.debugPath,this.spline);this.domElement.addEventListener("mousemove",function(b,e){return function(){e.apply(b,arguments)}}(this,this.onMouseMove), !1)};THREE.PathCamera.prototype=new THREE.Camera;THREE.PathCamera.prototype.constructor=THREE.PathCamera;THREE.PathCamera.prototype.supr=THREE.Camera.prototype;THREE.PathCameraIdCounter=0; THREE.FlyCamera=function(b){function c(b,c){return function(){c.apply(b,arguments)}}THREE.Camera.call(this,b.fov,b.aspect,b.near,b.far,b.target);this.tmpQuaternion=new THREE.Quaternion;this.movementSpeed=1;this.rollSpeed=0.0050;this.autoForward=this.dragToLook=!1;this.domElement=document;if(b){if(b.movementSpeed!==void 0)this.movementSpeed=b.movementSpeed;if(b.rollSpeed!==void 0)this.rollSpeed=b.rollSpeed;if(b.dragToLook!==void 0)this.dragToLook=b.dragToLook;if(b.autoForward!==void 0)this.autoForward= @@ -426,27 +426,27 @@ this.rollSpeed;this.translateX(this.moveVector.x*b);this.translateY(this.moveVec this.autoForward&&!this.moveState.back?1:0;this.moveVector.x=-this.moveState.left+this.moveState.right;this.moveVector.y=-this.moveState.down+this.moveState.up;this.moveVector.z=-b+this.moveState.back};this.updateRotationVector=function(){this.rotationVector.x=-this.moveState.pitchDown+this.moveState.pitchUp;this.rotationVector.y=-this.moveState.yawRight+this.moveState.yawLeft;this.rotationVector.z=-this.moveState.rollRight+this.moveState.rollLeft};this.getContainerDimensions=function(){return this.domElement!= document?{size:[this.domElement.offsetWidth,this.domElement.offsetHeight],offset:[this.domElement.offsetLeft,this.domElement.offsetTop]}:{size:[window.innerWidth,window.innerHeight],offset:[0,0]}};this.domElement.addEventListener("mousemove",c(this,this.mousemove),!1);this.domElement.addEventListener("mousedown",c(this,this.mousedown),!1);this.domElement.addEventListener("mouseup",c(this,this.mouseup),!1);window.addEventListener("keydown",c(this,this.keydown),!1);window.addEventListener("keyup",c(this, this.keyup),!1);this.updateMovementVector();this.updateRotationVector()};THREE.FlyCamera.prototype=new THREE.Camera;THREE.FlyCamera.prototype.constructor=THREE.FlyCamera;THREE.FlyCamera.prototype.supr=THREE.Camera.prototype; -THREE.RollCamera=function(b,c,e,f){THREE.Camera.call(this,b,c,e,f);this.mouseLook=!0;this.autoForward=!1;this.rollSpeed=this.movementSpeed=this.lookSpeed=1;this.constrainVertical=[-0.9,0.9];this.domElement=document;this.matrixAutoUpdate=this.useTarget=!1;this.forward=new THREE.Vector3(0,0,1);this.roll=0;this.lastUpdate=-1;this.delta=0;var g=new THREE.Vector3,j=new THREE.Vector3,h=new THREE.Vector3,m=new THREE.Matrix4,p=!1,n=1,o=0,t=0,v=0,u=0,w=0,z=window.innerWidth/2,y=window.innerHeight/2;this.update= -function(){var b=(new Date).getTime();if(this.lastUpdate==-1)this.lastUpdate=b;this.delta=(b-this.lastUpdate)/1E3;this.lastUpdate=b;this.mouseLook&&(b=this.delta*this.lookSpeed,this.rotateHorizontally(b*u),this.rotateVertically(b*w));b=this.delta*this.movementSpeed;this.translateZ(b*(o>0||this.autoForward&&!(o<0)?1:o));this.translateX(b*t);this.translateY(b*v);p&&(this.roll+=this.rollSpeed*this.delta*n);if(this.forward.y>this.constrainVertical[1])this.forward.y=this.constrainVertical[1],this.forward.normalize(); +THREE.RollCamera=function(b,c,e,f){THREE.Camera.call(this,b,c,e,f);this.mouseLook=!0;this.autoForward=!1;this.rollSpeed=this.movementSpeed=this.lookSpeed=1;this.constrainVertical=[-0.9,0.9];this.domElement=document;this.matrixAutoUpdate=this.useTarget=!1;this.forward=new THREE.Vector3(0,0,1);this.roll=0;this.lastUpdate=-1;this.delta=0;var g=new THREE.Vector3,j=new THREE.Vector3,h=new THREE.Vector3,m=new THREE.Matrix4,o=!1,n=1,p=0,t=0,v=0,u=0,w=0,z=window.innerWidth/2,x=window.innerHeight/2;this.update= +function(){var b=(new Date).getTime();if(this.lastUpdate==-1)this.lastUpdate=b;this.delta=(b-this.lastUpdate)/1E3;this.lastUpdate=b;this.mouseLook&&(b=this.delta*this.lookSpeed,this.rotateHorizontally(b*u),this.rotateVertically(b*w));b=this.delta*this.movementSpeed;this.translateZ(b*(p>0||this.autoForward&&!(p<0)?1:p));this.translateX(b*t);this.translateY(b*v);o&&(this.roll+=this.rollSpeed*this.delta*n);if(this.forward.y>this.constrainVertical[1])this.forward.y=this.constrainVertical[1],this.forward.normalize(); else if(this.forward.y1?e.normalize():e.z=Math.sqrt(1-f*f);g=this.position.clone().subSelf(this.target.position);f=this.up.clone().setLength(e.y);f.addSelf(this.up.clone().crossSelf(g).setLength(e.x));f.addSelf(g.setLength(e.z));return f}; -this.rotateCamera=function(){var b=Math.acos(j.dot(h)/j.length()/h.length());if(b){var c=(new THREE.Vector3).cross(j,h).normalize(),e=new THREE.Quaternion;b*=this.rotateSpeed;e.setFromAxisAngle(c,-b);e.multiplyVector3(g);e.multiplyVector3(this.up);e.multiplyVector3(h);this.staticMoving?j=h:(e.setFromAxisAngle(c,b*(this.dynamicDampingFactor-1)),e.multiplyVector3(j))}};this.zoomCamera=function(){var b=1+(p.y-m.y)*this.zoomSpeed;b!==1&&b>0&&(g.multiplyScalar(b),this.staticMoving?m=p:m.y+=(p.y-m.y)*this.dynamicDampingFactor)}; -this.panCamera=function(){var b=o.clone().subSelf(n);if(b.lengthSq()){b.multiplyScalar(g.length()*this.panSpeed);var c=g.clone().crossSelf(this.up).setLength(b.x);c.addSelf(this.up.clone().setLength(b.y));this.position.addSelf(c);this.target.position.addSelf(c);this.staticMoving?n=o:n.addSelf(b.sub(o,n).multiplyScalar(this.dynamicDampingFactor))}};this.checkDistances=function(){if(!this.noZoom||!this.noPan)this.position.lengthSq()>this.maxDistance*this.maxDistance&&this.position.setLength(this.maxDistance), +this.rotateCamera=function(){var b=Math.acos(j.dot(h)/j.length()/h.length());if(b){var c=(new THREE.Vector3).cross(j,h).normalize(),e=new THREE.Quaternion;b*=this.rotateSpeed;e.setFromAxisAngle(c,-b);e.multiplyVector3(g);e.multiplyVector3(this.up);e.multiplyVector3(h);this.staticMoving?j=h:(e.setFromAxisAngle(c,b*(this.dynamicDampingFactor-1)),e.multiplyVector3(j))}};this.zoomCamera=function(){var b=1+(o.y-m.y)*this.zoomSpeed;b!==1&&b>0&&(g.multiplyScalar(b),this.staticMoving?m=o:m.y+=(o.y-m.y)*this.dynamicDampingFactor)}; +this.panCamera=function(){var b=p.clone().subSelf(n);if(b.lengthSq()){b.multiplyScalar(g.length()*this.panSpeed);var c=g.clone().crossSelf(this.up).setLength(b.x);c.addSelf(this.up.clone().setLength(b.y));this.position.addSelf(c);this.target.position.addSelf(c);this.staticMoving?n=p:n.addSelf(b.sub(p,n).multiplyScalar(this.dynamicDampingFactor))}};this.checkDistances=function(){if(!this.noZoom||!this.noPan)this.position.lengthSq()>this.maxDistance*this.maxDistance&&this.position.setLength(this.maxDistance), g.lengthSq()0)m=f-1;else{m=f;break}f=m;if(e[f]==j)return f/(g-1);h=e[f];return e=(f+(j-h)/(e[f+1]-h))/(g-1)};THREE.Curve.prototype.getNormalVector=function(b){b=this.getTangent(b);return new THREE.Vector2(-b.y,b.x)}; +THREE.Curve.prototype.getUtoTmapping=function(b,c){var e=this.getLengths(),f=0,g=e.length,j;j=c?c:b*e[g-1];time=Date.now();for(var h=0,m=g-1,o;h<=m;)if(f=Math.floor(h+(m-h)/2),o=e[f]-j,o<0)h=f+1;else if(o>0)m=f-1;else{m=f;break}f=m;if(e[f]==j)return f/(g-1);h=e[f];return e=(f+(j-h)/(e[f+1]-h))/(g-1)};THREE.Curve.prototype.getNormalVector=function(b){b=this.getTangent(b);return new THREE.Vector2(-b.y,b.x)}; THREE.Curve.prototype.getTangent=function(b){var c=b-1.0E-4;b+=1.0E-4;c<0&&(c=0);b>1&&(b=1);var c=this.getPoint(c),b=this.getPoint(b),e=new THREE.Vector2;e.sub(b,c);return e.unit()};THREE.LineCurve=function(b,c){b instanceof THREE.Vector2?(this.v1=b,this.v2=c):THREE.LineCurve.oldConstructor.apply(this,arguments)};THREE.LineCurve.oldConstructor=function(b,c,e,f){this.constructor(new THREE.Vector2(b,c),new THREE.Vector2(e,f))};THREE.LineCurve.prototype=new THREE.Curve; THREE.LineCurve.prototype.constructor=THREE.LineCurve;THREE.LineCurve.prototype.getPoint=function(b){var c=new THREE.Vector2;c.sub(this.v2,this.v1);c.multiplyScalar(b).addSelf(this.v1);return c};THREE.LineCurve.prototype.getPointAt=function(b){return this.getPoint(b)};THREE.LineCurve.prototype.getTangent=function(){var b=new THREE.Vector2;b.sub(this.v2,this.v1);b.normalize();return b}; THREE.QuadraticBezierCurve=function(b,c,e){if(!(c instanceof THREE.Vector2))var f=Array.prototype.slice.call(arguments),b=new THREE.Vector2(f[0],f[1]),c=new THREE.Vector2(f[2],f[3]),e=new THREE.Vector2(f[4],f[5]);this.v0=b;this.v1=c;this.v2=e};THREE.QuadraticBezierCurve.prototype=new THREE.Curve;THREE.QuadraticBezierCurve.prototype.constructor=THREE.QuadraticBezierCurve; @@ -461,134 +461,140 @@ THREE.Curve.create=function(b,c){b.prototype=new THREE.Curve;b.prototype.constru THREE.QuadraticBezierCurve3=THREE.Curve.create(function(b,c,e){this.v0=b;this.v1=c;this.v2=e},function(b){var c,e;c=THREE.Shape.Utils.b2(b,this.v0.x,this.v1.x,this.v2.x);e=THREE.Shape.Utils.b2(b,this.v0.y,this.v1.y,this.v2.y);b=THREE.Shape.Utils.b2(b,this.v0.z,this.v1.z,this.v2.z);return new THREE.Vector3(c,e,b)});THREE.CurvePath=function(){this.curves=[];this.bends=[]};THREE.CurvePath.prototype=new THREE.Curve;THREE.CurvePath.prototype.constructor=THREE.CurvePath;THREE.CurvePath.prototype.add=function(b){this.curves.push(b)}; THREE.CurvePath.prototype.checkConnection=function(){};THREE.CurvePath.prototype.closePath=function(){};THREE.CurvePath.prototype.getPoint=function(b){for(var c=b*this.getLength(),e=this.getCurveLengths(),b=0;b=c)return c=e[b]-c,b=this.curves[b],c=1-c/b.getLength(),b.getPointAt(c);b++}return null};THREE.CurvePath.prototype.getLength=function(){var b=this.getCurveLengths();return b[b.length-1]}; THREE.CurvePath.prototype.getCurveLengths=function(){if(this.cacheLengths&&this.cacheLengths.length==this.curves.length)return this.cacheLengths;var b=[],c=0,e,f=this.curves.length;for(e=0;ec)c=j.x;else if(j.xe)e=j.y;else if(j.yc)c=j.x;else if(j.xe)e=j.y;else if(j.y0?(h=e[e.length-1],u=h.x,w=h.y):(h=this.actions[f-1].args,u=h[h.length-2],w=h[h.length-1]);for(h=1;h<=b;h++)z=h/b,j=THREE.Shape.Utils.b2(z,u,t,m),z=THREE.Shape.Utils.b2(z,w,v, -p),e.push(new THREE.Vector2(j,z));break;case THREE.PathActions.BEZIER_CURVE_TO:m=j[4];p=j[5];t=j[0];v=j[1];n=j[2];o=j[3];e.length>0?(h=e[e.length-1],u=h.x,w=h.y):(h=this.actions[f-1].args,u=h[h.length-2],w=h[h.length-1]);for(h=1;h<=b;h++)z=h/b,j=THREE.Shape.Utils.b3(z,u,t,n,m),z=THREE.Shape.Utils.b3(z,w,v,o,p),e.push(new THREE.Vector2(j,z));break;case THREE.PathActions.CSPLINE_THRU:h=this.actions[f-1].args;h=[new THREE.Vector2(h[h.length-2],h[h.length-1])];z=b*j[0].length;h=h.concat(j[0]);j=new THREE.SplineCurve(h); -for(h=1;h<=z;h++)e.push(j.getPointAt(h/z));break;case THREE.PathActions.ARC:h=this.actions[f-1].args;m=j[0];p=j[1];n=j[2];t=j[3];z=j[4];v=!!j[5];o=h[h.length-2];u=h[h.length-1];h.length==0&&(o=u=0);w=z-t;var y=b*2;for(h=1;h<=y;h++)z=h/y,v||(z=1-z),z=t+z*w,j=o+m+n*Math.cos(z),z=u+p+n*Math.sin(z),e.push(new THREE.Vector2(j,z))}c&&e.push(e[0]);return e};THREE.Path.prototype.transform=function(b,c){this.getBoundingBox();return this.getWrapPoints(this.getPoints(c),b)}; -THREE.Path.prototype.nltransform=function(b,c,e,f,g,j){var h=this.getPoints(),m,p,n,o,t;m=0;for(p=h.length;m0?(h=e[e.length-1],u=h.x,w=h.y):(h=this.actions[f-1].args,u=h[h.length-2],w=h[h.length-1]);for(h=1;h<=b;h++)z=h/b,j=THREE.Shape.Utils.b2(z,u,t,m),z=THREE.Shape.Utils.b2(z,w,v, +o),e.push(new THREE.Vector2(j,z));break;case THREE.PathActions.BEZIER_CURVE_TO:m=j[4];o=j[5];t=j[0];v=j[1];n=j[2];p=j[3];e.length>0?(h=e[e.length-1],u=h.x,w=h.y):(h=this.actions[f-1].args,u=h[h.length-2],w=h[h.length-1]);for(h=1;h<=b;h++)z=h/b,j=THREE.Shape.Utils.b3(z,u,t,n,m),z=THREE.Shape.Utils.b3(z,w,v,p,o),e.push(new THREE.Vector2(j,z));break;case THREE.PathActions.CSPLINE_THRU:h=this.actions[f-1].args;h=[new THREE.Vector2(h[h.length-2],h[h.length-1])];z=b*j[0].length;h=h.concat(j[0]);j=new THREE.SplineCurve(h); +for(h=1;h<=z;h++)e.push(j.getPointAt(h/z));break;case THREE.PathActions.ARC:h=this.actions[f-1].args;m=j[0];o=j[1];n=j[2];t=j[3];z=j[4];v=!!j[5];p=h[h.length-2];u=h[h.length-1];h.length==0&&(p=u=0);w=z-t;var x=b*2;for(h=1;h<=x;h++)z=h/x,v||(z=1-z),z=t+z*w,j=p+m+n*Math.cos(z),z=u+o+n*Math.sin(z),e.push(new THREE.Vector2(j,z))}c&&e.push(e[0]);return e};THREE.Path.prototype.transform=function(b,c){this.getBoundingBox();return this.getWrapPoints(this.getPoints(c),b)}; +THREE.Path.prototype.nltransform=function(b,c,e,f,g,j){var h=this.getPoints(),m,o,n,p,t;m=0;for(o=h.length;m=0?m-1:e.length-1;j=h-1>=0?h-1:n.length-1;var z=[n[h],e[m],e[g]];t=THREE.FontUtils.Triangulate.area(z);var y=[n[h],n[j],e[m]];v=THREE.FontUtils.Triangulate.area(y);u=m;o=h;m+=1;h+=-1;m<0&&(m+=e.length);m%= -e.length;h<0&&(h+=n.length);h%=n.length;g=m-1>=0?m-1:e.length-1;j=h-1>=0?h-1:n.length-1;z=[n[h],e[m],e[g]];z=THREE.FontUtils.Triangulate.area(z);y=[n[h],n[j],e[m]];y=THREE.FontUtils.Triangulate.area(y);t+v>z+y&&(m=u,h=o,m<0&&(m+=e.length),m%=e.length,h<0&&(h+=n.length),h%=n.length,g=m-1>=0?m-1:e.length-1,j=h-1>=0?h-1:n.length-1);t=e.slice(0,m);v=e.slice(m);u=n.slice(h);o=n.slice(0,h);j=[n[h],n[j],e[m]];w.push([n[h],e[m],e[g]]);w.push(j);e=t.concat(u).concat(o).concat(v)}return{shape:e,isolatedPts:w, -allpoints:f}},triangulateShape:function(b,c){var e=THREE.Shape.Utils.removeHoles(b,c),f=e.allpoints,g=e.isolatedPts,e=THREE.FontUtils.Triangulate(e.shape,!1),j,h,m,p,n={};j=0;for(h=f.length;j=0?m-1:e.length-1;j=h-1>=0?h-1:n.length-1;var z=[n[h],e[m],e[g]];t=THREE.FontUtils.Triangulate.area(z);var x=[n[h],n[j],e[m]];v=THREE.FontUtils.Triangulate.area(x);u=m;p=h;m+=1;h+=-1;m<0&&(m+=e.length);m%= +e.length;h<0&&(h+=n.length);h%=n.length;g=m-1>=0?m-1:e.length-1;j=h-1>=0?h-1:n.length-1;z=[n[h],e[m],e[g]];z=THREE.FontUtils.Triangulate.area(z);x=[n[h],n[j],e[m]];x=THREE.FontUtils.Triangulate.area(x);t+v>z+x&&(m=u,h=p,m<0&&(m+=e.length),m%=e.length,h<0&&(h+=n.length),h%=n.length,g=m-1>=0?m-1:e.length-1,j=h-1>=0?h-1:n.length-1);t=e.slice(0,m);v=e.slice(m);u=n.slice(h);p=n.slice(0,h);j=[n[h],n[j],e[m]];w.push([n[h],e[m],e[g]]);w.push(j);e=t.concat(u).concat(p).concat(v)}return{shape:e,isolatedPts:w, +allpoints:f}},triangulateShape:function(b,c){var e=THREE.Shape.Utils.removeHoles(b,c),f=e.allpoints,g=e.isolatedPts,e=THREE.FontUtils.Triangulate(e.shape,!1),j,h,m,o,n={};j=0;for(h=f.length;j0){h(0,0,-o-(j||0));for(p=b;p0){h(0,0,o+ -(g||0));for(p=b+b/2;p<2*b;p++)m.faces.push(new THREE.Face4(2*b+1,(2*p-2*b+2)%b+b,(2*p-2*b+1)%b+b,(2*p-2*b)%b+b))}p=0;for(b=this.faces.length;p0){h(0,0,-p-(j||0));for(o=b;o0){h(0,0,p+ +(g||0));for(o=b+b/2;o<2*b;o++)m.faces.push(new THREE.Face4(2*b+1,(2*o-2*b+2)%b+b,(2*o-2*b+1)%b+b,(2*o-2*b)%b+b))}o=0;for(b=this.faces.length;ob&&(b+=Math.PI*2),anglec=(c+b)/2,new THREE.Vector2(-Math.cos(anglec),-Math.sin(anglec));return f.multiplyScalar(j).addSelf(k).subSelf(b).clone()}function g(b){for(G=b.length;--G>=0;){aa=G;Z=G-1;Z<0&&(Z=b.length- -1);for(var c=0,c=0;c=0;R--){da=R/o;T=p*(1-da);da=n*Math.sin(da*Math.PI/2);G=0;for(I=H.length;G=0;R--){da=R/p;T=o*(1-da);da=n*Math.sin(da*Math.PI/2);G=0;for(I=H.length;G0||(o=this.vertices.push(new THREE.Vertex(new THREE.Vector3(t,m,v)))-1);n.push(o)}c.push(n)}for(var u,w,z,g=c.length,e=0;e0)for(f=0;f1&&(u= -this.vertices[h].position.clone(),w=this.vertices[p].position.clone(),z=this.vertices[n].position.clone(),u.normalize(),w.normalize(),z.normalize(),this.faces.push(new THREE.Face3(h,p,n,[new THREE.Vector3(u.x,u.y,u.z),new THREE.Vector3(w.x,w.y,w.z),new THREE.Vector3(z.x,z.y,z.z)])),this.faceVertexUvs[0].push([o,t,y]))}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.boundingSphere={radius:b}};THREE.SphereGeometry.prototype=new THREE.Geometry; +THREE.SphereGeometry=function(b,c,e){THREE.Geometry.call(this);for(var b=b||50,f,g=Math.PI,j=Math.max(3,c||8),h=Math.max(2,e||6),c=[],e=0;e0||(p=this.vertices.push(new THREE.Vertex(new THREE.Vector3(t,m,v)))-1);n.push(p)}c.push(n)}for(var u,w,z,g=c.length,e=0;e0)for(f=0;f1&&(u= +this.vertices[h].position.clone(),w=this.vertices[o].position.clone(),z=this.vertices[n].position.clone(),u.normalize(),w.normalize(),z.normalize(),this.faces.push(new THREE.Face3(h,o,n,[new THREE.Vector3(u.x,u.y,u.z),new THREE.Vector3(w.x,w.y,w.z),new THREE.Vector3(z.x,z.y,z.z)])),this.faceVertexUvs[0].push([p,t,x]))}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.boundingSphere={radius:b}};THREE.SphereGeometry.prototype=new THREE.Geometry; THREE.SphereGeometry.prototype.constructor=THREE.SphereGeometry; THREE.TextGeometry=function(b,c){var e=(new THREE.TextPath(b,c)).toShapes();c.amount=c.height!==void 0?c.height:50;if(c.bevelThickness===void 0)c.bevelThickness=10;if(c.bevelSize===void 0)c.bevelSize=8;if(c.bevelEnabled===void 0)c.bevelEnabled=!1;if(c.bend){var f=e[e.length-1].getBoundingBox().maxX;c.bendPath=new THREE.QuadraticBezierCurve(new THREE.Vector2(0,0),new THREE.Vector2(f/2,120),new THREE.Vector2(f,0))}THREE.ExtrudeGeometry.call(this,e,c)};THREE.TextGeometry.prototype=new THREE.ExtrudeGeometry; THREE.TextGeometry.prototype.constructor=THREE.TextGeometry; THREE.FontUtils={faces:{},face:"helvetiker",weight:"normal",style:"normal",size:150,divisions:10,getFace:function(){return this.faces[this.face][this.weight][this.style]},getTextShapes:function(b,c){return(new TextPath(b,c)).toShapes()},loadFace:function(b){var c=b.familyName.toLowerCase();this.faces[c]=this.faces[c]||{};this.faces[c][b.cssFontWeight]=this.faces[c][b.cssFontWeight]||{};this.faces[c][b.cssFontWeight][b.cssFontStyle]=b;return this.faces[c][b.cssFontWeight][b.cssFontStyle]=b},drawText:function(b){for(var c= -this.getFace(),e=this.size/c.resolution,f=0,g=String(b).split(""),j=g.length,h=[],b=0;b0)for(n=0;n2;){if(t--<=0){console.log("Warning, unable to triangulate polygon!");if(f)return m;return j}p=n;g<=p&&(p=0);n=p+1;g<=n&&(n=0);o=n+1;g<=o&&(o=0);var v;a:{v=b;var u=p,w=n,z=o,y=g,x=h,H=void 0,B=void 0,F=void 0, -J=void 0,D=void 0,L=void 0,G=void 0,I=void 0,R=void 0,B=v[x[u]].x,F=v[x[u]].y,J=v[x[w]].x,D=v[x[w]].y,L=v[x[z]].x,G=v[x[z]].y;if(1.0E-10>(J-B)*(G-F)-(D-F)*(L-B))v=!1;else{for(H=0;H=0&&C>=0&&S>=0){v=!1; -break a}}v=!0}}if(v){j.push([b[h[p]],b[h[n]],b[h[o]]]);m.push([h[p],h[n],h[o]]);p=n;for(o=n+1;o0)for(n=0;n2;){if(t--<=0){console.log("Warning, unable to triangulate polygon!");if(f)return m;return j}o=n;g<=o&&(o=0);n=o+1;g<=n&&(n=0);p=n+1;g<=p&&(p=0);var v;a:{v=b;var u=o,w=n,z=p,x=g,y=h,H=void 0,B=void 0,F=void 0, +J=void 0,D=void 0,L=void 0,G=void 0,I=void 0,R=void 0,B=v[y[u]].x,F=v[y[u]].y,J=v[y[w]].x,D=v[y[w]].y,L=v[y[z]].x,G=v[y[z]].y;if(1.0E-10>(J-B)*(G-F)-(D-F)*(L-B))v=!1;else{for(H=0;H=0&&C>=0&&S>=0){v=!1; +break a}}v=!0}}if(v){j.push([b[h[o]],b[h[n]],b[h[p]]]);m.push([h[o],h[n],h[p]]);o=n;for(p=n+1;p>7)-127;f|=(h&127)<<16|g<<8;if(f==0&&k==-127)return 0;return(1-2*(j>>7))*(1+f*Math.pow(2,-23))*Math.pow(2,k)}function g(b,c){var e=o(b,c),f=o(b,c+1),h=o(b,c+2);return(o(b,c+3)<<24)+(h<<16)+(f<<8)+e}function p(b,c){var e=o(b,c);return(o(b,c+1)<<8)+e}function n(b,c){var e=o(b,c);return e>127?e-256:e}function o(b, -c){return b.charCodeAt(c)&255}function t(c){var e,f,h;e=g(b,c);f=g(b,c+D);h=g(b,c+L);c=p(b,c+G);THREE.BinaryLoader.prototype.f3(x,e,f,h,c)}function v(c){var e,f,h,j,k,n;e=g(b,c);f=g(b,c+D);h=g(b,c+L);j=p(b,c+G);k=g(b,c+I);n=g(b,c+R);c=g(b,c+da);THREE.BinaryLoader.prototype.f3n(x,F,e,f,h,j,k,n,c)}function u(c){var e,f,h,j;e=g(b,c);f=g(b,c+T);h=g(b,c+C);j=g(b,c+ea);c=p(b,c+S);THREE.BinaryLoader.prototype.f4(x,e,f,h,j,c)}function w(c){var e,f,h,j,n,o,t,u;e=g(b,c);f=g(b,c+T);h=g(b,c+C);j=g(b,c+ea);n= -p(b,c+S);o=g(b,c+P);t=g(b,c+k);u=g(b,c+M);c=g(b,c+Y);THREE.BinaryLoader.prototype.f4n(x,F,e,f,h,j,n,o,t,u,c)}function z(c){var e,f;e=g(b,c);f=g(b,c+aa);c=g(b,c+Z);THREE.BinaryLoader.prototype.uv3(x.faceVertexUvs[0],J[e*2],J[e*2+1],J[f*2],J[f*2+1],J[c*2],J[c*2+1])}function y(c){var e,f,h;e=g(b,c);f=g(b,c+ha);h=g(b,c+ka);c=g(b,c+fa);THREE.BinaryLoader.prototype.uv4(x.faceVertexUvs[0],J[e*2],J[e*2+1],J[f*2],J[f*2+1],J[h*2],J[h*2+1],J[c*2],J[c*2+1])}var x=this,H=0,B,F=[],J=[],D,L,G,I,R,da,T,C,ea,S,P, -k,M,Y,aa,Z,ha,ka,fa,U,X,ca,ma,la,sa;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(x,f,c);B={signature:b.substr(H,8),header_bytes:o(b,H+8),vertex_coordinate_bytes:o(b,H+9),normal_coordinate_bytes:o(b,H+10),uv_coordinate_bytes:o(b,H+11),vertex_index_bytes:o(b,H+12),normal_index_bytes:o(b,H+13),uv_index_bytes:o(b,H+14),material_index_bytes:o(b,H+15),nvertices:g(b,H+16),nnormals:g(b,H+16+4),nuvs:g(b,H+16+8),ntri_flat:g(b,H+16+12),ntri_smooth:g(b,H+16+16),ntri_flat_uv:g(b,H+16+20),ntri_smooth_uv:g(b, +c.postMessage(b)},loadAjaxBuffers:function(b,c,e,f,g,j){var h=new XMLHttpRequest,m=f+"/"+b,o=0;h.onreadystatechange=function(){h.readyState==4?h.status==200||h.status==0?THREE.BinaryLoader.prototype.createBinModel(h.responseText,e,g,c):alert("Couldn't load ["+m+"] ["+h.status+"]"):h.readyState==3?j&&(o==0&&(o=h.getResponseHeader("Content-Length")),j({total:o,loaded:h.responseText.length})):h.readyState==2&&(o=h.getResponseHeader("Content-Length"))};h.open("GET",m,!0);h.overrideMimeType("text/plain; charset=x-user-defined"); +h.setRequestHeader("Content-Type","text/plain");h.send(null)},createBinModel:function(b,c,e,f){var g=function(c){function e(b,c){var f=p(b,c),g=p(b,c+1),h=p(b,c+2),j=p(b,c+3),k=(j<<1&255|h>>7)-127;f|=(h&127)<<16|g<<8;if(f==0&&k==-127)return 0;return(1-2*(j>>7))*(1+f*Math.pow(2,-23))*Math.pow(2,k)}function g(b,c){var e=p(b,c),f=p(b,c+1),h=p(b,c+2);return(p(b,c+3)<<24)+(h<<16)+(f<<8)+e}function o(b,c){var e=p(b,c);return(p(b,c+1)<<8)+e}function n(b,c){var e=p(b,c);return e>127?e-256:e}function p(b, +c){return b.charCodeAt(c)&255}function t(c){var e,f,h;e=g(b,c);f=g(b,c+D);h=g(b,c+L);c=o(b,c+G);THREE.BinaryLoader.prototype.f3(y,e,f,h,c)}function v(c){var e,f,h,j,k,n;e=g(b,c);f=g(b,c+D);h=g(b,c+L);j=o(b,c+G);k=g(b,c+I);n=g(b,c+R);c=g(b,c+da);THREE.BinaryLoader.prototype.f3n(y,F,e,f,h,j,k,n,c)}function u(c){var e,f,h,j;e=g(b,c);f=g(b,c+T);h=g(b,c+C);j=g(b,c+ea);c=o(b,c+S);THREE.BinaryLoader.prototype.f4(y,e,f,h,j,c)}function w(c){var e,f,h,j,n,p,t,u;e=g(b,c);f=g(b,c+T);h=g(b,c+C);j=g(b,c+ea);n= +o(b,c+S);p=g(b,c+P);t=g(b,c+k);u=g(b,c+M);c=g(b,c+Y);THREE.BinaryLoader.prototype.f4n(y,F,e,f,h,j,n,p,t,u,c)}function z(c){var e,f;e=g(b,c);f=g(b,c+aa);c=g(b,c+Z);THREE.BinaryLoader.prototype.uv3(y.faceVertexUvs[0],J[e*2],J[e*2+1],J[f*2],J[f*2+1],J[c*2],J[c*2+1])}function x(c){var e,f,h;e=g(b,c);f=g(b,c+ha);h=g(b,c+ka);c=g(b,c+fa);THREE.BinaryLoader.prototype.uv4(y.faceVertexUvs[0],J[e*2],J[e*2+1],J[f*2],J[f*2+1],J[h*2],J[h*2+1],J[c*2],J[c*2+1])}var y=this,H=0,B,F=[],J=[],D,L,G,I,R,da,T,C,ea,S,P, +k,M,Y,aa,Z,ha,ka,fa,U,X,ca,ma,la,sa;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(y,f,c);B={signature:b.substr(H,8),header_bytes:p(b,H+8),vertex_coordinate_bytes:p(b,H+9),normal_coordinate_bytes:p(b,H+10),uv_coordinate_bytes:p(b,H+11),vertex_index_bytes:p(b,H+12),normal_index_bytes:p(b,H+13),uv_index_bytes:p(b,H+14),material_index_bytes:p(b,H+15),nvertices:g(b,H+16),nnormals:g(b,H+16+4),nuvs:g(b,H+16+8),ntri_flat:g(b,H+16+12),ntri_smooth:g(b,H+16+16),ntri_flat_uv:g(b,H+16+20),ntri_smooth_uv:g(b, H+16+24),nquad_flat:g(b,H+16+28),nquad_smooth:g(b,H+16+32),nquad_flat_uv:g(b,H+16+36),nquad_smooth_uv:g(b,H+16+40)};H+=B.header_bytes;D=B.vertex_index_bytes;L=B.vertex_index_bytes*2;G=B.vertex_index_bytes*3;I=B.vertex_index_bytes*3+B.material_index_bytes;R=B.vertex_index_bytes*3+B.material_index_bytes+B.normal_index_bytes;da=B.vertex_index_bytes*3+B.material_index_bytes+B.normal_index_bytes*2;T=B.vertex_index_bytes;C=B.vertex_index_bytes*2;ea=B.vertex_index_bytes*3;S=B.vertex_index_bytes*4;P=B.vertex_index_bytes* 4+B.material_index_bytes;k=B.vertex_index_bytes*4+B.material_index_bytes+B.normal_index_bytes;M=B.vertex_index_bytes*4+B.material_index_bytes+B.normal_index_bytes*2;Y=B.vertex_index_bytes*4+B.material_index_bytes+B.normal_index_bytes*3;aa=B.uv_index_bytes;Z=B.uv_index_bytes*2;ha=B.uv_index_bytes;ka=B.uv_index_bytes*2;fa=B.uv_index_bytes*3;c=B.vertex_index_bytes*3+B.material_index_bytes;sa=B.vertex_index_bytes*4+B.material_index_bytes;U=B.ntri_flat*c;X=B.ntri_smooth*(c+B.normal_index_bytes*3);ca=B.ntri_flat_uv* -(c+B.uv_index_bytes*3);ma=B.ntri_smooth_uv*(c+B.normal_index_bytes*3+B.uv_index_bytes*3);la=B.nquad_flat*sa;c=B.nquad_smooth*(sa+B.normal_index_bytes*4);sa=B.nquad_flat_uv*(sa+B.uv_index_bytes*4);H+=function(c){for(var f,g,j,k=B.vertex_coordinate_bytes*3,m=c+B.nvertices*k;c1&&(R=[new THREE.MeshFaceMaterial]);object=new THREE.Mesh(D,R);object.name=u;object.position.set(B[0],B[1],B[2]);q?(object.quaternion.set(q[0],q[1],q[2],q[3]),object.useQuaternion=!0):object.rotation.set(r[0],r[1],r[2]);object.scale.set(s[0],s[1],s[2]);object.visible=H.visible;M.scene.addObject(object);M.objects[u]=object;H.meshCollider&&(b=THREE.CollisionUtils.MeshColliderWBox(object),M.scene.collisions.colliders.push(b)); if(H.castsShadow)b=new THREE.ShadowVolume(D),M.scene.addChild(b),b.position=object.position,b.rotation=object.rotation,b.scale=object.scale;H.trigger&&H.trigger.toLowerCase()!="none"&&(b={type:H.trigger,object:H},M.triggers[object.name]=b)}}else B=H.position,r=H.rotation,q=H.quaternion,s=H.scale,q=0,object=new THREE.Object3D,object.name=u,object.position.set(B[0],B[1],B[2]),q?(object.quaternion.set(q[0],q[1],q[2],q[3]),object.useQuaternion=!0):object.rotation.set(r[0],r[1],r[2]),object.scale.set(s[0], -s[1],s[2]),object.visible=H.visible!==void 0?H.visible:!1,M.scene.addObject(object),M.objects[u]=object,M.empties[u]=object,H.trigger&&H.trigger.toLowerCase()!="none"&&(b={type:H.trigger,object:H},M.triggers[object.name]=b)}function p(b){return function(c){M.geometries[b]=c;m();ea-=1;e.onLoadComplete();o()}}function n(b){return function(c){M.geometries[b]=c}}function o(){e.callbackProgress({totalModels:P,totalTextures:k,loadedModels:P-ea,loadedTextures:k-S},M);e.onLoadProgress();ea==0&&S==0&&c(M)} -var t,v,u,w,z,y,x,H,B,F,J,D,L,G,I,R,da,T,C,ea,S,P,k,M;T=b.data;I=new THREE.BinaryLoader;C=new THREE.JSONLoader;S=ea=0;M={scene:new THREE.Scene,geometries:{},materials:{},textures:{},objects:{},cameras:{},lights:{},fogs:{},triggers:{},empties:{}};b=!1;for(u in T.objects)if(H=T.objects[u],H.meshCollider){b=!0;break}if(b)M.scene.collisions=new THREE.CollisionSystem;if(T.transform){b=T.transform.position;F=T.transform.rotation;var Y=T.transform.scale;b&&M.scene.position.set(b[0],b[1],b[2]);F&&M.scene.rotation.set(F[0], -F[1],F[2]);Y&&M.scene.scale.set(Y[0],Y[1],Y[2]);(b||F||Y)&&M.scene.updateMatrix()}b=function(){S-=1;o();e.onLoadComplete()};for(z in T.cameras){F=T.cameras[z];if(F.type=="perspective")L=new THREE.Camera(F.fov,F.aspect,F.near,F.far);else if(F.type=="ortho")L=new THREE.Camera,L.projectionMatrix=THREE.Matrix4.makeOrtho(F.left,F.right,F.top,F.bottom,F.near,F.far);B=F.position;F=F.target;L.position.set(B[0],B[1],B[2]);L.target.position.set(F[0],F[1],F[2]);M.cameras[z]=L}for(w in T.lights)z=T.lights[w], -L=z.color!==void 0?z.color:16777215,F=z.intensity!==void 0?z.intensity:1,z.type=="directional"?(B=z.direction,da=new THREE.DirectionalLight(L,F),da.position.set(B[0],B[1],B[2]),da.position.normalize()):z.type=="point"?(B=z.position,d=z.distance,da=new THREE.PointLight(L,F,d),da.position.set(B[0],B[1],B[2])):z.type=="ambient"&&(da=new THREE.AmbientLight(L)),M.scene.addLight(da),M.lights[w]=da;for(y in T.fogs)w=T.fogs[y],w.type=="linear"?G=new THREE.Fog(0,w.near,w.far):w.type=="exp2"&&(G=new THREE.FogExp2(0, -w.density)),F=w.color,G.color.setRGB(F[0],F[1],F[2]),M.fogs[y]=G;if(M.cameras&&T.defaults.camera)M.currentCamera=M.cameras[T.defaults.camera];if(M.fogs&&T.defaults.fog)M.scene.fog=M.fogs[T.defaults.fog];F=T.defaults.bgcolor;M.bgColor=new THREE.Color;M.bgColor.setRGB(F[0],F[1],F[2]);M.bgColorAlpha=T.defaults.bgalpha;for(t in T.geometries)if(y=T.geometries[t],y.type=="bin_mesh"||y.type=="ascii_mesh")ea+=1,e.onLoadStart();P=ea;for(t in T.geometries)y=T.geometries[t],y.type=="cube"?(D=new THREE.CubeGeometry(y.width, -y.height,y.depth,y.segmentsWidth,y.segmentsHeight,y.segmentsDepth,null,y.flipped,y.sides),M.geometries[t]=D):y.type=="plane"?(D=new THREE.PlaneGeometry(y.width,y.height,y.segmentsWidth,y.segmentsHeight),M.geometries[t]=D):y.type=="sphere"?(D=new THREE.SphereGeometry(y.radius,y.segmentsWidth,y.segmentsHeight),M.geometries[t]=D):y.type=="cylinder"?(D=new THREE.CylinderGeometry(y.numSegs,y.topRad,y.botRad,y.height,y.topOffset,y.botOffset),M.geometries[t]=D):y.type=="torus"?(D=new THREE.TorusGeometry(y.radius, -y.tube,y.segmentsR,y.segmentsT),M.geometries[t]=D):y.type=="icosahedron"?(D=new THREE.IcosahedronGeometry(y.subdivisions),M.geometries[t]=D):y.type=="bin_mesh"?I.load({model:f(y.url,T.urlBaseType),callback:p(t)}):y.type=="ascii_mesh"?C.load({model:f(y.url,T.urlBaseType),callback:p(t)}):y.type=="embedded_mesh"&&(y=T.embeds[y.id])&&C.createModel(y,n(t),"");for(x in T.textures)if(t=T.textures[x],t.url instanceof Array){S+=t.url.length;for(I=0;I=57344&&(c-=2048);c++;for(var e=new Float32Array(8*c),f=1,g=0;g<8;g++){for(var j=0,h=0;h>1^-(m&1);e[8*h+g]=j}f+=c}c=b.length-f;j=new Uint16Array(c);for(g=h=0;g=this.maxCount-3&&m(this)};this.begin=function(){this.count=0; -this.hasNormal=this.hasPos=!1};this.end=function(b){if(this.count!=0){for(var c=this.count*3;cthis.size-1&&(p=this.size-1);var v=Math.floor(n-m);v<1&&(v=1);n=Math.floor(n+m);n>this.size-1&&(n=this.size-1);var u=Math.floor(o-m);u<1&&(u=1);m=Math.floor(o+m);m>this.size-1&&(m=this.size- -1);for(var w,z,y,x,H,B;t0&&(this.field[y+w]+=x)}}};this.addPlaneX=function(b,c){var g,j,h,m,p,n=this.size,o=this.yd,t=this.zd,v=this.field,u=n*Math.sqrt(b/c);u>n&&(u=n);for(g=0;g0)for(j=0;jo&&(w=o);for(j=0;j0){p=j*t;for(g=0;gsize&&(dist=size);for(h=0;h0){p=zd*h;for(j=0;j=this.maxCount-3&&m(this)};this.begin=function(){this.count=0; +this.hasNormal=this.hasPos=!1};this.end=function(b){if(this.count!=0){for(var c=this.count*3;cthis.size-1&&(o=this.size-1);var v=Math.floor(n-m);v<1&&(v=1);n=Math.floor(n+m);n>this.size-1&&(n=this.size-1);var u=Math.floor(p-m);u<1&&(u=1);m=Math.floor(p+m);m>this.size-1&&(m=this.size- +1);for(var w,z,x,y,H,B;t0&&(this.field[x+w]+=y)}}};this.addPlaneX=function(b,c){var g,j,h,m,o,n=this.size,p=this.yd,t=this.zd,v=this.field,u=n*Math.sqrt(b/c);u>n&&(u=n);for(g=0;g0)for(j=0;jp&&(w=p);for(j=0;j0){o=j*t;for(g=0;gsize&&(dist=size);for(h=0;h0){o=zd*h;for(j=0;jj?this.hits.push(g):this.hits.unshift(g),j=f;return this.hits}; THREE.CollisionSystem.prototype.rayCastNearest=function(b){var c=this.rayCastAll(b);if(c.length==0)return null;for(var e=0;c[e]instanceof THREE.MeshCollider;){var f=this.rayMesh(b,c[e]);if(f.distc.length)return null;return c[e]}; THREE.CollisionSystem.prototype.rayCast=function(b,c){if(c instanceof THREE.PlaneCollider)return this.rayPlane(b,c);else if(c instanceof THREE.SphereCollider)return this.raySphere(b,c);else if(c instanceof THREE.BoxCollider)return this.rayBox(b,c);else if(c instanceof THREE.MeshCollider&&c.box)return this.rayBox(b,c.box)}; -THREE.CollisionSystem.prototype.rayMesh=function(b,c){for(var e=this.makeRayLocal(b,c.mesh),f=Number.MAX_VALUE,g,j=0;j=m*g))return Number.MAX_VALUE;h/=m;m=THREE.CollisionSystem.__v3;m.copy(b.direction);m.multiplyScalar(h);m.addSelf(b.origin);Math.abs(j.x)> +THREE.CollisionSystem.prototype.rayMesh=function(b,c){for(var e=this.makeRayLocal(b,c.mesh),f=Number.MAX_VALUE,g,j=0;j=m*g))return Number.MAX_VALUE;h/=m;m=THREE.CollisionSystem.__v3;m.copy(b.direction);m.multiplyScalar(h);m.addSelf(b.origin);Math.abs(j.x)> Math.abs(j.y)?Math.abs(j.x)>Math.abs(j.z)?(b=m.y-c.y,j=e.y-c.y,g=f.y-c.y,m=m.z-c.z,e=e.z-c.z,f=f.z-c.z):(b=m.x-c.x,j=e.x-c.x,g=f.x-c.x,m=m.y-c.y,e=e.y-c.y,f=f.y-c.y):Math.abs(j.y)>Math.abs(j.z)?(b=m.x-c.x,j=e.x-c.x,g=f.x-c.x,m=m.z-c.z,e=e.z-c.z,f=f.z-c.z):(b=m.x-c.x,j=e.x-c.x,g=f.x-c.x,m=m.y-c.y,e=e.y-c.y,f=f.y-c.y);c=j*f-e*g;if(c==0)return Number.MAX_VALUE;c=1/c;f=(b*f-m*g)*c;if(!(f>=0))return Number.MAX_VALUE;c*=j*m-e*b;if(!(c>=0))return Number.MAX_VALUE;if(!(1-f-c>=0))return Number.MAX_VALUE;return h}; THREE.CollisionSystem.prototype.makeRayLocal=function(b,c){var e=THREE.CollisionSystem.__m;THREE.Matrix4.makeInvert(c.matrixWorld,e);var f=THREE.CollisionSystem.__r;f.origin.copy(b.origin);f.direction.copy(b.direction);e.multiplyVector3(f.origin);e.rotateAxis(f.direction);f.direction.normalize();return f}; -THREE.CollisionSystem.prototype.rayBox=function(b,c){var e;c.dynamic&&c.mesh&&c.mesh.matrixWorld?e=this.makeRayLocal(b,c.mesh):(e=THREE.CollisionSystem.__r,e.origin.copy(b.origin),e.direction.copy(b.direction));var f=0,g=0,j=0,h=0,m=0,p=0,n=!0;e.origin.xc.max.x&&(f=c.max.x-e.origin.x,f/=e.direction.x,n=!1,h=1);e.origin.yc.max.y&&(g=c.max.y-e.origin.y,g/=e.direction.y, -n=!1,m=1);e.origin.zc.max.z&&(j=c.max.z-e.origin.z,j/=e.direction.z,n=!1,p=1);if(n)return-1;n=0;g>f&&(n=1,f=g);j>f&&(n=2,f=j);switch(n){case 0:m=e.origin.y+e.direction.y*f;if(mc.max.y)return Number.MAX_VALUE;e=e.origin.z+e.direction.z*f;if(ec.max.z)return Number.MAX_VALUE;c.normal.set(h,0,0);break;case 1:h=e.origin.x+e.direction.x*f;if(hc.max.x)return Number.MAX_VALUE;e=e.origin.z+e.direction.z* -f;if(ec.max.z)return Number.MAX_VALUE;c.normal.set(0,m,0);break;case 2:h=e.origin.x+e.direction.x*f;if(hc.max.x)return Number.MAX_VALUE;m=e.origin.y+e.direction.y*f;if(mc.max.y)return Number.MAX_VALUE;c.normal.set(0,0,p)}return f};THREE.CollisionSystem.prototype.rayPlane=function(b,c){var e=b.direction.dot(c.normal),f=c.point.dot(c.normal);if(e<0)e=(f-b.origin.dot(c.normal))/e;else return Number.MAX_VALUE;return e>0?e:Number.MAX_VALUE}; +THREE.CollisionSystem.prototype.rayBox=function(b,c){var e;c.dynamic&&c.mesh&&c.mesh.matrixWorld?e=this.makeRayLocal(b,c.mesh):(e=THREE.CollisionSystem.__r,e.origin.copy(b.origin),e.direction.copy(b.direction));var f=0,g=0,j=0,h=0,m=0,o=0,n=!0;e.origin.xc.max.x&&(f=c.max.x-e.origin.x,f/=e.direction.x,n=!1,h=1);e.origin.yc.max.y&&(g=c.max.y-e.origin.y,g/=e.direction.y, +n=!1,m=1);e.origin.zc.max.z&&(j=c.max.z-e.origin.z,j/=e.direction.z,n=!1,o=1);if(n)return-1;n=0;g>f&&(n=1,f=g);j>f&&(n=2,f=j);switch(n){case 0:m=e.origin.y+e.direction.y*f;if(mc.max.y)return Number.MAX_VALUE;e=e.origin.z+e.direction.z*f;if(ec.max.z)return Number.MAX_VALUE;c.normal.set(h,0,0);break;case 1:h=e.origin.x+e.direction.x*f;if(hc.max.x)return Number.MAX_VALUE;e=e.origin.z+e.direction.z* +f;if(ec.max.z)return Number.MAX_VALUE;c.normal.set(0,m,0);break;case 2:h=e.origin.x+e.direction.x*f;if(hc.max.x)return Number.MAX_VALUE;m=e.origin.y+e.direction.y*f;if(mc.max.y)return Number.MAX_VALUE;c.normal.set(0,0,o)}return f};THREE.CollisionSystem.prototype.rayPlane=function(b,c){var e=b.direction.dot(c.normal),f=c.point.dot(c.normal);if(e<0)e=(f-b.origin.dot(c.normal))/e;else return Number.MAX_VALUE;return e>0?e:Number.MAX_VALUE}; THREE.CollisionSystem.prototype.raySphere=function(b,c){var e=c.center.clone().subSelf(b.origin);if(e.lengthSq=0)return Math.abs(f)-Math.sqrt(e);return Number.MAX_VALUE};THREE.CollisionSystem.__v1=new THREE.Vector3;THREE.CollisionSystem.__v2=new THREE.Vector3;THREE.CollisionSystem.__v3=new THREE.Vector3;THREE.CollisionSystem.__nr=new THREE.Vector3;THREE.CollisionSystem.__m=new THREE.Matrix4; THREE.CollisionSystem.__r=new THREE.Ray;THREE.CollisionUtils={};THREE.CollisionUtils.MeshOBB=function(b){b.geometry.computeBoundingBox();var c=b.geometry.boundingBox,e=new THREE.Vector3(c.x[0],c.y[0],c.z[0]),c=new THREE.Vector3(c.x[1],c.y[1],c.z[1]),e=new THREE.BoxCollider(e,c);e.mesh=b;return e};THREE.CollisionUtils.MeshAABB=function(b){var c=THREE.CollisionUtils.MeshOBB(b);c.min.addSelf(b.position);c.max.addSelf(b.position);c.dynamic=!1;return c}; THREE.CollisionUtils.MeshColliderWBox=function(b){return new THREE.MeshCollider(b,THREE.CollisionUtils.MeshOBB(b))}; -if(THREE.WebGLRenderer)THREE.AnaglyphWebGLRenderer=function(b){THREE.WebGLRenderer.call(this,b);var c=this,e=this.setSize,f=this.render,g=new THREE.Camera,j=new THREE.Camera,h=new THREE.Matrix4,m=new THREE.Matrix4,p,n,o;g.useTarget=j.useTarget=!1;g.matrixAutoUpdate=j.matrixAutoUpdate=!1;var b={minFilter:THREE.LinearFilter,magFilter:THREE.NearestFilter,format:THREE.RGBAFormat},t=new THREE.WebGLRenderTarget(512,512,b),v=new THREE.WebGLRenderTarget(512,512,b),u=new THREE.Camera(53,1,1,1E4);u.position.z= +if(THREE.WebGLRenderer)THREE.AnaglyphWebGLRenderer=function(b){THREE.WebGLRenderer.call(this,b);var c=this,e=this.setSize,f=this.render,g=new THREE.Camera,j=new THREE.Camera,h=new THREE.Matrix4,m=new THREE.Matrix4,o,n,p;g.useTarget=j.useTarget=!1;g.matrixAutoUpdate=j.matrixAutoUpdate=!1;var b={minFilter:THREE.LinearFilter,magFilter:THREE.NearestFilter,format:THREE.RGBAFormat},t=new THREE.WebGLRenderTarget(512,512,b),v=new THREE.WebGLRenderTarget(512,512,b),u=new THREE.Camera(53,1,1,1E4);u.position.z= 2;_material=new THREE.MeshShaderMaterial({uniforms:{mapLeft:{type:"t",value:0,texture:t},mapRight:{type:"t",value:1,texture:v}},vertexShader:"varying vec2 vUv;\nvoid main() {\nvUv = vec2( uv.x, 1.0 - uv.y );\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"uniform sampler2D mapLeft;\nuniform sampler2D mapRight;\nvarying vec2 vUv;\nvoid main() {\nvec4 colorL, colorR;\nvec2 uv = vUv;\ncolorL = texture2D( mapLeft, uv );\ncolorR = texture2D( mapRight, uv );\ngl_FragColor = vec4( colorL.g * 0.7 + colorL.b * 0.3, colorR.g, colorR.b, colorL.a + colorR.a ) * 1.1;\n}"}); -var w=new THREE.Scene;w.addObject(new THREE.Mesh(new THREE.PlaneGeometry(2,2),_material));this.setSize=function(b,f){e.call(c,b,f);t.width=b;t.height=f;v.width=b;v.height=f};this.render=function(b,e){e.update(null,!0);if(p!==e.aspect||n!==e.near||o!==e.fov){p=e.aspect;n=e.near;o=e.fov;var x=e.projectionMatrix.clone(),H=125/30*0.5,B=H*n/125,F=n*Math.tan(o*Math.PI/360),J;h.n14=H;m.n14=-H;H=-F*p+B;J=F*p+B;x.n11=2*n/(J-H);x.n13=(J+H)/(J-H);g.projectionMatrix=x.clone();H=-F*p-B;J=F*p-B;x.n11=2*n/(J-H); -x.n13=(J+H)/(J-H);j.projectionMatrix=x.clone()}g.matrix=e.matrixWorld.clone().multiplySelf(m);g.update(null,!0);g.position.copy(e.position);g.near=n;g.far=e.far;f.call(c,b,g,t,!0);j.matrix=e.matrixWorld.clone().multiplySelf(h);j.update(null,!0);j.position.copy(e.position);j.near=n;j.far=e.far;f.call(c,b,j,v,!0);f.call(c,w,u)}}; +var w=new THREE.Scene;w.addObject(new THREE.Mesh(new THREE.PlaneGeometry(2,2),_material));this.setSize=function(b,f){e.call(c,b,f);t.width=b;t.height=f;v.width=b;v.height=f};this.render=function(b,e){e.update(null,!0);if(o!==e.aspect||n!==e.near||p!==e.fov){o=e.aspect;n=e.near;p=e.fov;var y=e.projectionMatrix.clone(),H=125/30*0.5,B=H*n/125,F=n*Math.tan(p*Math.PI/360),J;h.n14=H;m.n14=-H;H=-F*o+B;J=F*o+B;y.n11=2*n/(J-H);y.n13=(J+H)/(J-H);g.projectionMatrix=y.clone();H=-F*o-B;J=F*o-B;y.n11=2*n/(J-H); +y.n13=(J+H)/(J-H);j.projectionMatrix=y.clone()}g.matrix=e.matrixWorld.clone().multiplySelf(m);g.update(null,!0);g.position.copy(e.position);g.near=n;g.far=e.far;f.call(c,b,g,t,!0);j.matrix=e.matrixWorld.clone().multiplySelf(h);j.update(null,!0);j.position.copy(e.position);j.near=n;j.far=e.far;f.call(c,b,j,v,!0);f.call(c,w,u)}}; if(THREE.WebGLRenderer)THREE.CrosseyedWebGLRenderer=function(b){THREE.WebGLRenderer.call(this,b);this.autoClear=!1;var c=this,e=this.setSize,f=this.render,g,j,h=new THREE.Camera,m=new THREE.Camera;c.separation=10;if(b&&b.separation!==void 0)c.separation=b.separation;(new THREE.Camera(53,window.innerWidth/2/window.innerHeight,1,1E4)).position.z=-10;this.setSize=function(b,f){e.call(c,b,f);g=b/2;j=f};this.render=function(b,e){this.clear();h.fov=e.fov;h.aspect=0.5*e.aspect;h.near=e.near;h.far=e.far; h.updateProjectionMatrix();h.position.copy(e.position);h.target.position.copy(e.target.position);h.translateX(c.separation);m.projectionMatrix=h.projectionMatrix;m.position.copy(e.position);m.target.position.copy(e.target.position);m.translateX(-c.separation);this.setViewport(0,0,g,j);f.call(c,b,h);this.setViewport(g,0,g,j);f.call(c,b,m,!1)}}; diff --git a/build/custom/ThreeExtras.js b/build/custom/ThreeExtras.js index 61b4c157..93788d17 100644 --- a/build/custom/ThreeExtras.js +++ b/build/custom/ThreeExtras.js @@ -80,8 +80,8 @@ THREE.TrackballCamera=function(a){function b(a,b){return function(){b.apply(a,ar !1;this.staticMoving=a.staticMoving||!1;this.dynamicDampingFactor=a.dynamicDampingFactor||0.2;this.minDistance=a.minDistance||0;this.maxDistance=a.maxDistance||Infinity;this.keys=a.keys||[65,83,68];this.useTarget=!0;var c=!1,e=this.STATE.NONE,f=new THREE.Vector3,h=new THREE.Vector3,g=new THREE.Vector3,j=new THREE.Vector2,k=new THREE.Vector2,l=new THREE.Vector2,m=new THREE.Vector2;this.handleEvent=function(a){if(typeof this[a.type]=="function")this[a.type](a)};this.getMouseOnScreen=function(a,b){return new THREE.Vector2((a- this.screen.offsetLeft)/this.radius*0.5,(b-this.screen.offsetTop)/this.radius*0.5)};this.getMouseProjectionOnBall=function(a,b){var c=new THREE.Vector3((a-this.screen.width*0.5-this.screen.offsetLeft)/this.radius,(this.screen.height*0.5+this.screen.offsetTop-b)/this.radius,0),e=c.length();e>1?c.normalize():c.z=Math.sqrt(1-e*e);f=this.position.clone().subSelf(this.target.position);e=this.up.clone().setLength(c.y);e.addSelf(this.up.clone().crossSelf(f).setLength(c.x));e.addSelf(f.setLength(c.z));return e}; this.rotateCamera=function(){var a=Math.acos(h.dot(g)/h.length()/g.length());if(a){var b=(new THREE.Vector3).cross(h,g).normalize(),c=new THREE.Quaternion;a*=this.rotateSpeed;c.setFromAxisAngle(b,-a);c.multiplyVector3(f);c.multiplyVector3(this.up);c.multiplyVector3(g);this.staticMoving?h=g:(c.setFromAxisAngle(b,a*(this.dynamicDampingFactor-1)),c.multiplyVector3(h))}};this.zoomCamera=function(){var a=1+(k.y-j.y)*this.zoomSpeed;a!==1&&a>0&&(f.multiplyScalar(a),this.staticMoving?j=k:j.y+=(k.y-j.y)*this.dynamicDampingFactor)}; -this.panCamera=function(){var a=m.clone().subSelf(l);if(a.lengthSq()){a.multiplyScalar(f.length()*this.panSpeed);var c=f.clone().crossSelf(this.up).setLength(a.x);c.addSelf(this.up.clone().setLength(a.y));this.position.addSelf(c);this.target.position.addSelf(c);this.staticMoving?l=m:l.addSelf(a.sub(m,l).multiplyScalar(this.dynamicDampingFactor))}};this.checkDistances=function(){if(!this.noZoom||!this.noPan)this.position.lengthSq()>this.maxDistance*this.maxDistance&&this.position.setLength(this.maxDistance), -f.lengthSq()this.maxDistance*this.maxDistance&&this.position.setLength(this.maxDistance), +f.lengthSq()0){g(0,0,-m-(h||0));for(k=a;k0){g(0,0,m+ +k[u]);this.sides.px&&l("z","y",1*j,-1,c,b,-n,this.materials[0]);this.sides.nx&&l("z","y",-1*j,-1,c,b,n,this.materials[1]);this.sides.py&&l("x","z",1*j,1,a,c,o,this.materials[2]);this.sides.ny&&l("x","z",1*j,-1,a,c,-o,this.materials[3]);this.sides.pz&&l("x","y",1*j,-1,a,b,t,this.materials[4]);this.sides.nz&&l("x","y",-1*j,-1,a,b,-t,this.materials[5]);(function(){for(var a=[],b=[],c=0,e=m.vertices.length;c0){g(0,0,-m-(h||0));for(k=a;k0){g(0,0,m+ (f||0));for(k=a+a/2;k<2*a;k++)j.faces.push(new THREE.Face4(2*a+1,(2*k-2*a+2)%a+a,(2*k-2*a+1)%a+a,(2*k-2*a)%a+a))}k=0;for(a=this.faces.length;ka&&(a+=Math.PI*2),anglec=(c+a)/2,new THREE.Vector2(-Math.cos(anglec),-Math.sin(anglec));return e.multiplyScalar(f).addSelf(j).subSelf(a).clone()}function f(a){for(A=a.length;--A>=0;){K=A;N=A-1;N<0&&(N=a.length- -1);for(var c=0,c=0;c=0;J--){I=J/m;E=k*(1-I);I=l*Math.sin(I*Math.PI/2);A=0;for(D=w.length;Aa&&(a+=Math.PI*2),anglec=(b+a)/2,new THREE.Vector2(-Math.cos(anglec),-Math.sin(anglec));return e.multiplyScalar(f).addSelf(j).subSelf(a).clone()}function f(a){for(A=a.length;--A>=0;){K=A;N=A-1;N<0&&(N=a.length- +1);for(var b=0,b=0;b=0;J--){I=J/m;E=k*(1-I);I=l*Math.sin(I*Math.PI/2);A=0;for(D=w.length;A0)for(l=0;l2;){if(n--<=0){console.log("Warning, unable to triangulate polygon!");if(e)return j;return h}k=l;f<=k&&(k=0);l=k+1;f<=l&&(l=0);m=l+1;f<=m&&(m=0);var o;a:{o=a;var t=k,v=l,u=m,x=f,y=g,w=void 0,p=void 0,z=void 0, -B=void 0,G=void 0,H=void 0,A=void 0,D=void 0,J=void 0,p=o[y[t]].x,z=o[y[t]].y,B=o[y[v]].x,G=o[y[v]].y,H=o[y[u]].x,A=o[y[u]].y;if(1.0E-10>(B-p)*(A-z)-(G-z)*(H-p))o=!1;else{for(w=0;w=0&&F>=0&&M>=0){o=!1;break a}}o=!0}}if(o){h.push([a[g[k]], +l));f.moveTo(j,l);break;case "l":j=b[a++]*c+e;l=b[a++]*c;h.push(new THREE.Vector2(j,l));f.lineTo(j,l);break;case "q":j=b[a++]*c+e;l=b[a++]*c;o=b[a++]*c+e;t=b[a++]*c;f.quadraticCurveTo(o,t,j,l);if(g=h[h.length-1]){m=g.x;n=g.y;g=1;for(divisions=this.divisions;g<=divisions;g++){var z=g/divisions,w=THREE.Shape.Utils.b2(z,m,o,j),z=THREE.Shape.Utils.b2(z,n,t,l);h.push(new THREE.Vector2(w,z))}}break;case "b":if(j=b[a++]*c+e,l=b[a++]*c,o=b[a++]*c+e,t=b[a++]*-c,v=b[a++]*c+e,u=b[a++]*-c,f.bezierCurveTo(j,l, +o,t,v,u),g=h[h.length-1]){m=g.x;n=g.y;g=1;for(divisions=this.divisions;g<=divisions;g++)z=g/divisions,w=THREE.Shape.Utils.b3(z,m,o,v,j),z=THREE.Shape.Utils.b3(z,n,t,u,l),h.push(new THREE.Vector2(w,z))}}}return{offset:x.ha*c,points:h,path:f}}}}; +(function(a){var b=function(a){for(var b=a.length,f=0,h=b-1,g=0;g0)for(l=0;l2;){if(n--<=0){console.log("Warning, unable to triangulate polygon!");if(e)return j;return h}k=l;f<=k&&(k=0);l=k+1;f<=l&&(l=0);m=l+1;f<=m&&(m=0);var o;a:{o=a;var t=k,v=l,u=m,x=f,z=g,w=void 0,p=void 0,y=void 0, +B=void 0,G=void 0,H=void 0,A=void 0,D=void 0,J=void 0,p=o[z[t]].x,y=o[z[t]].y,B=o[z[v]].x,G=o[z[v]].y,H=o[z[u]].x,A=o[z[u]].y;if(1.0E-10>(B-p)*(A-y)-(G-y)*(H-p))o=!1;else{for(w=0;w=0&&F>=0&&M>=0){o=!1;break a}}o=!0}}if(o){h.push([a[g[k]], a[g[l]],a[g[m]]]);j.push([g[k],g[l],g[m]]);k=l;for(m=l+1;m>7)-127;e|=(g&127)<<16|f<<8;if(e==0&&j==-127)return 0;return(1-2*(h>>7))*(1+e*Math.pow(2,-23))*Math.pow(2,j)}function f(a,b){var c=m(a,b),e=m(a,b+1),g=m(a,b+2);return(m(a,b+3)<<24)+(g<<16)+(e<<8)+c}function k(a,b){var c=m(a,b);return(m(a,b+1)<<8)+c}function l(a,b){var c=m(a,b);return c>127?c-256:c}function m(a, -b){return a.charCodeAt(b)&255}function n(b){var c,e,g;c=f(a,b);e=f(a,b+G);g=f(a,b+H);b=k(a,b+A);THREE.BinaryLoader.prototype.f3(y,c,e,g,b)}function o(b){var c,e,g,h,l,m;c=f(a,b);e=f(a,b+G);g=f(a,b+H);h=k(a,b+A);l=f(a,b+D);m=f(a,b+J);b=f(a,b+I);THREE.BinaryLoader.prototype.f3n(y,z,c,e,g,h,l,m,b)}function t(b){var c,e,g,h;c=f(a,b);e=f(a,b+E);g=f(a,b+F);h=f(a,b+L);b=k(a,b+M);THREE.BinaryLoader.prototype.f4(y,c,e,g,h,b)}function v(b){var c,e,g,h,l,m,n,o;c=f(a,b);e=f(a,b+E);g=f(a,b+F);h=f(a,b+L);l=k(a, -b+M);m=f(a,b+O);n=f(a,b+Q);o=f(a,b+C);b=f(a,b+P);THREE.BinaryLoader.prototype.f4n(y,z,c,e,g,h,l,m,n,o,b)}function u(b){var c,e;c=f(a,b);e=f(a,b+K);b=f(a,b+N);THREE.BinaryLoader.prototype.uv3(y.faceVertexUvs[0],B[c*2],B[c*2+1],B[e*2],B[e*2+1],B[b*2],B[b*2+1])}function x(b){var c,e,g;c=f(a,b);e=f(a,b+R);g=f(a,b+Y);b=f(a,b+Z);THREE.BinaryLoader.prototype.uv4(y.faceVertexUvs[0],B[c*2],B[c*2+1],B[e*2],B[e*2+1],B[g*2],B[g*2+1],B[b*2],B[b*2+1])}var y=this,w=0,p,z=[],B=[],G,H,A,D,J,I,E,F,L,M,O,Q,C,P,K,N, -R,Y,Z,T,U,V,W,X,S;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(y,e,b);p={signature:a.substr(w,8),header_bytes:m(a,w+8),vertex_coordinate_bytes:m(a,w+9),normal_coordinate_bytes:m(a,w+10),uv_coordinate_bytes:m(a,w+11),vertex_index_bytes:m(a,w+12),normal_index_bytes:m(a,w+13),uv_index_bytes:m(a,w+14),material_index_bytes:m(a,w+15),nvertices:f(a,w+16),nnormals:f(a,w+16+4),nuvs:f(a,w+16+8),ntri_flat:f(a,w+16+12),ntri_smooth:f(a,w+16+16),ntri_flat_uv:f(a,w+16+20),ntri_smooth_uv:f(a,w+ +b){return a.charCodeAt(b)&255}function n(b){var c,e,g;c=f(a,b);e=f(a,b+G);g=f(a,b+H);b=k(a,b+A);THREE.BinaryLoader.prototype.f3(z,c,e,g,b)}function o(b){var c,e,g,h,l,m;c=f(a,b);e=f(a,b+G);g=f(a,b+H);h=k(a,b+A);l=f(a,b+D);m=f(a,b+J);b=f(a,b+I);THREE.BinaryLoader.prototype.f3n(z,y,c,e,g,h,l,m,b)}function t(b){var c,e,g,h;c=f(a,b);e=f(a,b+E);g=f(a,b+F);h=f(a,b+L);b=k(a,b+M);THREE.BinaryLoader.prototype.f4(z,c,e,g,h,b)}function v(b){var c,e,g,h,l,m,n,o;c=f(a,b);e=f(a,b+E);g=f(a,b+F);h=f(a,b+L);l=k(a, +b+M);m=f(a,b+O);n=f(a,b+Q);o=f(a,b+C);b=f(a,b+P);THREE.BinaryLoader.prototype.f4n(z,y,c,e,g,h,l,m,n,o,b)}function u(b){var c,e;c=f(a,b);e=f(a,b+K);b=f(a,b+N);THREE.BinaryLoader.prototype.uv3(z.faceVertexUvs[0],B[c*2],B[c*2+1],B[e*2],B[e*2+1],B[b*2],B[b*2+1])}function x(b){var c,e,g;c=f(a,b);e=f(a,b+R);g=f(a,b+Y);b=f(a,b+Z);THREE.BinaryLoader.prototype.uv4(z.faceVertexUvs[0],B[c*2],B[c*2+1],B[e*2],B[e*2+1],B[g*2],B[g*2+1],B[b*2],B[b*2+1])}var z=this,w=0,p,y=[],B=[],G,H,A,D,J,I,E,F,L,M,O,Q,C,P,K,N, +R,Y,Z,T,U,V,W,X,S;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(z,e,b);p={signature:a.substr(w,8),header_bytes:m(a,w+8),vertex_coordinate_bytes:m(a,w+9),normal_coordinate_bytes:m(a,w+10),uv_coordinate_bytes:m(a,w+11),vertex_index_bytes:m(a,w+12),normal_index_bytes:m(a,w+13),uv_index_bytes:m(a,w+14),material_index_bytes:m(a,w+15),nvertices:f(a,w+16),nnormals:f(a,w+16+4),nuvs:f(a,w+16+8),ntri_flat:f(a,w+16+12),ntri_smooth:f(a,w+16+16),ntri_flat_uv:f(a,w+16+20),ntri_smooth_uv:f(a,w+ 16+24),nquad_flat:f(a,w+16+28),nquad_smooth:f(a,w+16+32),nquad_flat_uv:f(a,w+16+36),nquad_smooth_uv:f(a,w+16+40)};w+=p.header_bytes;G=p.vertex_index_bytes;H=p.vertex_index_bytes*2;A=p.vertex_index_bytes*3;D=p.vertex_index_bytes*3+p.material_index_bytes;J=p.vertex_index_bytes*3+p.material_index_bytes+p.normal_index_bytes;I=p.vertex_index_bytes*3+p.material_index_bytes+p.normal_index_bytes*2;E=p.vertex_index_bytes;F=p.vertex_index_bytes*2;L=p.vertex_index_bytes*3;M=p.vertex_index_bytes*4;O=p.vertex_index_bytes* 4+p.material_index_bytes;Q=p.vertex_index_bytes*4+p.material_index_bytes+p.normal_index_bytes;C=p.vertex_index_bytes*4+p.material_index_bytes+p.normal_index_bytes*2;P=p.vertex_index_bytes*4+p.material_index_bytes+p.normal_index_bytes*3;K=p.uv_index_bytes;N=p.uv_index_bytes*2;R=p.uv_index_bytes;Y=p.uv_index_bytes*2;Z=p.uv_index_bytes*3;b=p.vertex_index_bytes*3+p.material_index_bytes;S=p.vertex_index_bytes*4+p.material_index_bytes;T=p.ntri_flat*b;U=p.ntri_smooth*(b+p.normal_index_bytes*3);V=p.ntri_flat_uv* -(b+p.uv_index_bytes*3);W=p.ntri_smooth_uv*(b+p.normal_index_bytes*3+p.uv_index_bytes*3);X=p.nquad_flat*S;b=p.nquad_smooth*(S+p.normal_index_bytes*4);S=p.nquad_flat_uv*(S+p.uv_index_bytes*4);w+=function(b){for(var e,f,h,j=p.vertex_coordinate_bytes*3,k=b+p.nvertices*j;b1&&(J=[new THREE.MeshFaceMaterial]);object=new THREE.Mesh(G,J);object.name=t;object.position.set(p[0],p[1],p[2]);q?(object.quaternion.set(q[0],q[1],q[2],q[3]),object.useQuaternion=!0):object.rotation.set(r[0],r[1],r[2]);object.scale.set(s[0],s[1],s[2]);object.visible=w.visible;C.scene.addObject(object);C.objects[t]=object;w.meshCollider&&(a=THREE.CollisionUtils.MeshColliderWBox(object),C.scene.collisions.colliders.push(a)); if(w.castsShadow)a=new THREE.ShadowVolume(G),C.scene.addChild(a),a.position=object.position,a.rotation=object.rotation,a.scale=object.scale;w.trigger&&w.trigger.toLowerCase()!="none"&&(a={type:w.trigger,object:w},C.triggers[object.name]=a)}}else p=w.position,r=w.rotation,q=w.quaternion,s=w.scale,q=0,object=new THREE.Object3D,object.name=t,object.position.set(p[0],p[1],p[2]),q?(object.quaternion.set(q[0],q[1],q[2],q[3]),object.useQuaternion=!0):object.rotation.set(r[0],r[1],r[2]),object.scale.set(s[0], s[1],s[2]),object.visible=w.visible!==void 0?w.visible:!1,C.scene.addObject(object),C.objects[t]=object,C.empties[t]=object,w.trigger&&w.trigger.toLowerCase()!="none"&&(a={type:w.trigger,object:w},C.triggers[object.name]=a)}function k(a){return function(b){C.geometries[a]=b;j();L-=1;c.onLoadComplete();m()}}function l(a){return function(b){C.geometries[a]=b}}function m(){c.callbackProgress({totalModels:O,totalTextures:Q,loadedModels:O-L,loadedTextures:Q-M},C);c.onLoadProgress();L==0&&M==0&&b(C)}var n, -o,t,v,u,x,y,w,p,z,B,G,H,A,D,J,I,E,F,L,M,O,Q,C;E=a.data;D=new THREE.BinaryLoader;F=new THREE.JSONLoader;M=L=0;C={scene:new THREE.Scene,geometries:{},materials:{},textures:{},objects:{},cameras:{},lights:{},fogs:{},triggers:{},empties:{}};a=!1;for(t in E.objects)if(w=E.objects[t],w.meshCollider){a=!0;break}if(a)C.scene.collisions=new THREE.CollisionSystem;if(E.transform){a=E.transform.position;z=E.transform.rotation;var P=E.transform.scale;a&&C.scene.position.set(a[0],a[1],a[2]);z&&C.scene.rotation.set(z[0], -z[1],z[2]);P&&C.scene.scale.set(P[0],P[1],P[2]);(a||z||P)&&C.scene.updateMatrix()}a=function(){M-=1;m();c.onLoadComplete()};for(u in E.cameras){z=E.cameras[u];if(z.type=="perspective")H=new THREE.Camera(z.fov,z.aspect,z.near,z.far);else if(z.type=="ortho")H=new THREE.Camera,H.projectionMatrix=THREE.Matrix4.makeOrtho(z.left,z.right,z.top,z.bottom,z.near,z.far);p=z.position;z=z.target;H.position.set(p[0],p[1],p[2]);H.target.position.set(z[0],z[1],z[2]);C.cameras[u]=H}for(v in E.lights)u=E.lights[v], -H=u.color!==void 0?u.color:16777215,z=u.intensity!==void 0?u.intensity:1,u.type=="directional"?(p=u.direction,I=new THREE.DirectionalLight(H,z),I.position.set(p[0],p[1],p[2]),I.position.normalize()):u.type=="point"?(p=u.position,d=u.distance,I=new THREE.PointLight(H,z,d),I.position.set(p[0],p[1],p[2])):u.type=="ambient"&&(I=new THREE.AmbientLight(H)),C.scene.addLight(I),C.lights[v]=I;for(x in E.fogs)v=E.fogs[x],v.type=="linear"?A=new THREE.Fog(0,v.near,v.far):v.type=="exp2"&&(A=new THREE.FogExp2(0, -v.density)),z=v.color,A.color.setRGB(z[0],z[1],z[2]),C.fogs[x]=A;if(C.cameras&&E.defaults.camera)C.currentCamera=C.cameras[E.defaults.camera];if(C.fogs&&E.defaults.fog)C.scene.fog=C.fogs[E.defaults.fog];z=E.defaults.bgcolor;C.bgColor=new THREE.Color;C.bgColor.setRGB(z[0],z[1],z[2]);C.bgColorAlpha=E.defaults.bgalpha;for(n in E.geometries)if(x=E.geometries[n],x.type=="bin_mesh"||x.type=="ascii_mesh")L+=1,c.onLoadStart();O=L;for(n in E.geometries)x=E.geometries[n],x.type=="cube"?(G=new THREE.CubeGeometry(x.width, +o,t,v,u,x,z,w,p,y,B,G,H,A,D,J,I,E,F,L,M,O,Q,C;E=a.data;D=new THREE.BinaryLoader;F=new THREE.JSONLoader;M=L=0;C={scene:new THREE.Scene,geometries:{},materials:{},textures:{},objects:{},cameras:{},lights:{},fogs:{},triggers:{},empties:{}};a=!1;for(t in E.objects)if(w=E.objects[t],w.meshCollider){a=!0;break}if(a)C.scene.collisions=new THREE.CollisionSystem;if(E.transform){a=E.transform.position;y=E.transform.rotation;var P=E.transform.scale;a&&C.scene.position.set(a[0],a[1],a[2]);y&&C.scene.rotation.set(y[0], +y[1],y[2]);P&&C.scene.scale.set(P[0],P[1],P[2]);(a||y||P)&&C.scene.updateMatrix()}a=function(){M-=1;m();c.onLoadComplete()};for(u in E.cameras){y=E.cameras[u];if(y.type=="perspective")H=new THREE.Camera(y.fov,y.aspect,y.near,y.far);else if(y.type=="ortho")H=new THREE.Camera,H.projectionMatrix=THREE.Matrix4.makeOrtho(y.left,y.right,y.top,y.bottom,y.near,y.far);p=y.position;y=y.target;H.position.set(p[0],p[1],p[2]);H.target.position.set(y[0],y[1],y[2]);C.cameras[u]=H}for(v in E.lights)u=E.lights[v], +H=u.color!==void 0?u.color:16777215,y=u.intensity!==void 0?u.intensity:1,u.type=="directional"?(p=u.direction,I=new THREE.DirectionalLight(H,y),I.position.set(p[0],p[1],p[2]),I.position.normalize()):u.type=="point"?(p=u.position,d=u.distance,I=new THREE.PointLight(H,y,d),I.position.set(p[0],p[1],p[2])):u.type=="ambient"&&(I=new THREE.AmbientLight(H)),C.scene.addLight(I),C.lights[v]=I;for(x in E.fogs)v=E.fogs[x],v.type=="linear"?A=new THREE.Fog(0,v.near,v.far):v.type=="exp2"&&(A=new THREE.FogExp2(0, +v.density)),y=v.color,A.color.setRGB(y[0],y[1],y[2]),C.fogs[x]=A;if(C.cameras&&E.defaults.camera)C.currentCamera=C.cameras[E.defaults.camera];if(C.fogs&&E.defaults.fog)C.scene.fog=C.fogs[E.defaults.fog];y=E.defaults.bgcolor;C.bgColor=new THREE.Color;C.bgColor.setRGB(y[0],y[1],y[2]);C.bgColorAlpha=E.defaults.bgalpha;for(n in E.geometries)if(x=E.geometries[n],x.type=="bin_mesh"||x.type=="ascii_mesh")L+=1,c.onLoadStart();O=L;for(n in E.geometries)x=E.geometries[n],x.type=="cube"?(G=new THREE.CubeGeometry(x.width, x.height,x.depth,x.segmentsWidth,x.segmentsHeight,x.segmentsDepth,null,x.flipped,x.sides),C.geometries[n]=G):x.type=="plane"?(G=new THREE.PlaneGeometry(x.width,x.height,x.segmentsWidth,x.segmentsHeight),C.geometries[n]=G):x.type=="sphere"?(G=new THREE.SphereGeometry(x.radius,x.segmentsWidth,x.segmentsHeight),C.geometries[n]=G):x.type=="cylinder"?(G=new THREE.CylinderGeometry(x.numSegs,x.topRad,x.botRad,x.height,x.topOffset,x.botOffset),C.geometries[n]=G):x.type=="torus"?(G=new THREE.TorusGeometry(x.radius, -x.tube,x.segmentsR,x.segmentsT),C.geometries[n]=G):x.type=="icosahedron"?(G=new THREE.IcosahedronGeometry(x.subdivisions),C.geometries[n]=G):x.type=="bin_mesh"?D.load({model:e(x.url,E.urlBaseType),callback:k(n)}):x.type=="ascii_mesh"?F.load({model:e(x.url,E.urlBaseType),callback:k(n)}):x.type=="embedded_mesh"&&(x=E.embeds[x.id])&&F.createModel(x,l(n),"");for(y in E.textures)if(n=E.textures[y],n.url instanceof Array){M+=n.url.length;for(D=0;D=57344&&(b-=2048);b++;for(var c=new Float32Array(8*b),e=1,f=0;f<8;f++){for(var h=0,g=0;g>1^-(j&1);c[8*g+f]=h}e+=b}b=a.length-e;h=new Uint16Array(b);for(f=g=0;f=this.maxCount-3&&j(this)};this.begin=function(){this.count=0; this.hasNormal=this.hasPos=!1};this.end=function(a){if(this.count!=0){for(var b=this.count*3;bthis.size-1&&(k=this.size-1);var o=Math.floor(l-j);o<1&&(o=1);l=Math.floor(l+j);l>this.size-1&&(l=this.size-1);var t=Math.floor(m-j);t<1&&(t=1);j=Math.floor(m+j);j>this.size-1&&(j=this.size- -1);for(var v,u,x,y,w,p;n0&&(this.field[x+v]+=y)}}};this.addPlaneX=function(a,b){var f,h,g,j,k,l=this.size,m=this.yd,n=this.zd,o=this.field,t=l*Math.sqrt(a/b);t>l&&(t=l);for(f=0;f0)for(h=0;h0&&(this.field[x+v]+=z)}}};this.addPlaneX=function(a,b){var f,h,g,j,k,l=this.size,m=this.yd,n=this.zd,o=this.field,t=l*Math.sqrt(a/b);t>l&&(t=l);for(f=0;f0)for(h=0;hm&&(v=m);for(h=0;h0){k=h*n;for(f=0;fsize&&(dist=size);for(g=0;g0){k=zd*g;for(h=0;h + + + three.js webgl - io - UTF8 loader + + + + + +
+ three.js - + UTF8 format loader test - + models from The Utah 3D Animation Repository +
+ + + + + + + + + + + diff --git a/src/extras/io/UTF8Loader.js b/src/extras/io/UTF8Loader.js new file mode 100644 index 00000000..4417faa1 --- /dev/null +++ b/src/extras/io/UTF8Loader.js @@ -0,0 +1,350 @@ +/** + * Loader for UTF8 encoded models generated by: + * http://code.google.com/p/webgl-loader/ + * + * Limitations: + * - number of vertices < 65536 (this is after optimizations in compressor, input OBJ may have even less) + * - models must have normals and texture coordinates + * - texture coordinates must be only from <0,1> + * - no materials support yet + * - models are scaled and offset (copy numbers from compressor and use them as parameters in UTF8Loader.load() ) + * + * @author alteredq / http://alteredqualia.com/ + * @author won3d / http://twitter.com/won3d + */ + +THREE.UTF8Loader = function ( ) { + +}; + +THREE.UTF8Loader.prototype = new THREE.UTF8Loader(); +THREE.UTF8Loader.prototype.constructor = THREE.UTF8Loader; + + +THREE.UTF8Loader.prototype = { + + // Load UTF8 compressed models generated by objcompress + // - parameters + // - model (required) + // - callback (required) + + load: function( parameters ) { + + var xhr = new XMLHttpRequest(), + url = parameters.model, + + callback = parameters.callback, + callback_progress = null, + + scale = parameters.scale !== undefined ? parameters.scale : 1, + offsetX = parameters.offsetX !== undefined ? parameters.offsetX : 0, + offsetY = parameters.offsetY !== undefined ? parameters.offsetY : 0, + offsetZ = parameters.offsetZ !== undefined ? parameters.offsetZ : 0; + + var length = 0; + + xhr.onreadystatechange = function() { + + if ( xhr.readyState == 4 ) { + + if ( xhr.status == 200 || xhr.status == 0 ) { + + THREE.UTF8Loader.prototype.createModel( xhr.responseText, callback, scale, offsetX, offsetY, offsetZ ); + + } else { + + alert( "Couldn't load [" + url + "] [" + xhr.status + "]" ); + + } + + } else if ( xhr.readyState == 3 ) { + + if ( callback_progress ) { + + if ( length == 0 ) { + + length = xhr.getResponseHeader( "Content-Length" ); + + } + + callback_progress( { total: length, loaded: xhr.responseText.length } ); + + } + + } else if ( xhr.readyState == 2 ) { + + length = xhr.getResponseHeader( "Content-Length" ); + + } + + } + + xhr.open( "GET", url, true ); + xhr.send( null ); + + }, + + // UTF-8 decoder from webgl-loader + // http://code.google.com/p/webgl-loader/ + + // Copyright 2011 Google Inc. All Rights Reserved. + // + // Licensed under the Apache License, Version 2.0 (the "License"); you + // may not use this file except in compliance with the License. You + // may obtain a copy of the License at + // + // http://www.apache.org/licenses/LICENSE-2.0 + // + // Unless required by applicable law or agreed to in writing, software + // distributed under the License is distributed on an "AS IS" BASIS, + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + // implied. See the License for the specific language governing + // permissions and limitations under the License. + + decompressMesh: function ( str ) { + + var num_verts = str.charCodeAt( 0 ); + + if ( num_verts >= 0xE000 ) { + + num_verts -= 0x0800; + + } + + num_verts ++; + + var attribs_out = new Float32Array( 8 * num_verts ); + + var offset = 1; + + for ( var i = 0; i < 8; i ++ ) { + + var prev_attrib = 0; + + for ( var j = 0; j < num_verts; ++ j ) { + + var code = str.charCodeAt( j + offset ); + + prev_attrib += ( code >> 1 ) ^ ( - ( code & 1 ) ); + + attribs_out[ 8 * j + i ] = prev_attrib; + + } + + offset += num_verts; + + } + + var num_indices = str.length - offset; + + var indices_out = new Uint16Array( num_indices ); + + var index_high_water_mark = 0; + + for ( var i = 0; i < num_indices; i ++ ) { + + var code = str.charCodeAt( i + offset ); + + indices_out[ i ] = index_high_water_mark - code; + + if ( code == 0 ) { + + index_high_water_mark ++; + + } + + } + + return [ attribs_out, indices_out ]; + + }, + + createModel: function ( data, callback, scale, offsetX, offsetY, offsetZ ) { + + var Model = function ( texture_path ) { + + var s = (new Date).getTime(); + + var scope = this; + + scope.materials = []; + + THREE.Geometry.call( this ); + + var buffers = THREE.UTF8Loader.prototype.decompressMesh( data ); + + var normals = [], + uvs = []; + + init_vertices( buffers[ 0 ], 8, 0 ); + init_uvs( buffers[ 0 ], 8, 3 ); + init_normals( buffers[ 0 ], 8, 5 ); + + init_faces( buffers[ 1 ] ); + + this.computeCentroids(); + this.computeFaceNormals(); + //this.computeTangents(); + + var e = (new Date).getTime(); + + console.log( "utf8 data parse time: " + (e-s) + " ms" ); + + function init_vertices( data, stride, offset ) { + + var i, x, y, z, + end = data.length; + + for( i = offset; i < end; i += stride ) { + + x = data[ i ]; + y = data[ i + 1 ]; + z = data[ i + 2 ]; + + // fix scale and offsets + + x = ( x / 16383 ) * scale; + y = ( y / 16383 ) * scale; + z = ( z / 16383 ) * scale; + + x += offsetX; + y += offsetY; + z += offsetZ; + + THREE.UTF8Loader.prototype.v( scope, x, y, z ); + + } + + } + + function init_normals( data, stride, offset ) { + + var i, x, y, z, + end = data.length; + + for( i = offset; i < end; i += stride ) { + + x = data[ i ]; + y = data[ i + 1 ]; + z = data[ i + 2 ]; + + // normalize to <-1,1> + + x = ( x - 512 ) / 511; + y = ( y - 512 ) / 511; + z = ( z - 512 ) / 511; + + normals.push( x, y, z ); + + } + + } + + function init_uvs( data, stride, offset ) { + + var i, u, v, + end = data.length; + + for( i = offset; i < end; i += stride ) { + + u = data[ i ]; + v = data[ i + 1 ]; + + // normalize to <0,1> + + u /= 1023; + v /= 1023; + + uvs.push( u, v ); + + } + + } + + function init_faces( indices ) { + + var i, + a, b, c, + u1, v1, u2, v2, u3, v3, + m, + end = indices.length; + + m = 0; // all faces defaulting to material 0 + + for( i = 0; i < end; i += 3 ) { + + a = indices[ i ]; + b = indices[ i + 1 ]; + c = indices[ i + 2 ]; + + THREE.UTF8Loader.prototype.f3n( scope, normals, a, b, c, m, a, b, c ); + + u1 = uvs[ a * 2 ]; + v1 = uvs[ a * 2 + 1 ]; + + u2 = uvs[ b * 2 ]; + v2 = uvs[ b * 2 + 1 ]; + + u3 = uvs[ c * 2 ]; + v3 = uvs[ c * 2 + 1 ]; + + THREE.UTF8Loader.prototype.uv3( scope.faceVertexUvs[ 0 ], u1, v1, u2, v2, u3, v3 ); + + } + + + } + + } + + Model.prototype = new THREE.Geometry(); + Model.prototype.constructor = Model; + + callback( new Model() ); + + }, + + + v: function( scope, x, y, z ) { + + scope.vertices.push( new THREE.Vertex( new THREE.Vector3( x, y, z ) ) ); + + }, + + f3n: function( scope, normals, a, b, c, mi, na, nb, nc ) { + + var material = scope.materials[ mi ], + + nax = normals[ na * 3 ], + nay = normals[ na * 3 + 1 ], + naz = normals[ na * 3 + 2 ], + + nbx = normals[ nb * 3 ], + nby = normals[ nb * 3 + 1 ], + nbz = normals[ nb * 3 + 2 ], + + ncx = normals[ nc * 3 ], + ncy = normals[ nc * 3 + 1 ], + ncz = normals[ nc * 3 + 2 ]; + + var na = new THREE.Vector3( nax, nay, naz ), + nb = new THREE.Vector3( nbx, nby, nbz ), + nc = new THREE.Vector3( ncx, ncy, ncz ); + + scope.faces.push( new THREE.Face3( a, b, c, [ na, nb, nc ], null, material ) ); + + }, + + uv3: function( where, u1, v1, u2, v2, u3, v3 ) { + + var uv = []; + uv.push( new THREE.UV( u1, v1 ) ); + uv.push( new THREE.UV( u2, v2 ) ); + uv.push( new THREE.UV( u3, v3 ) ); + where.push( uv ); + + }, + + constructor : THREE.UTF8Loader + +}; diff --git a/utils/build.py b/utils/build.py index 9857955a..c9fd299c 100644 --- a/utils/build.py +++ b/utils/build.py @@ -114,6 +114,7 @@ EXTRAS_FILES = [ 'extras/io/JSONLoader.js', 'extras/io/BinaryLoader.js', 'extras/io/SceneLoader.js', +'extras/io/UTF8Loader.js', 'extras/objects/MarchingCubes.js', 'extras/objects/Trident.js', 'extras/physics/Collisions.js', diff --git a/utils/exporters/utf8/README b/utils/exporters/utf8/README new file mode 100644 index 00000000..55d7c24c --- /dev/null +++ b/utils/exporters/utf8/README @@ -0,0 +1,37 @@ +------------------------- +---- three.js README ---- +------------------------- + +Slightly modified "mesh.h" so that compressor: + +- compiles with latest MinGW on Windows 64-bit + (had to replace %z size_t formatting option) + +- dumps to stderr scaling and offset parameters + + +Also for convenience added pre-build executable for Windows. + +Latest version of compressor can be downloaded at webgl-loader repository: + +http://code.google.com/p/webgl-loader/ + +-------------------------------------------- +---- Original README from webgl-loader ----- +-------------------------------------------- + +Usage: ./objcompress in.obj [out.utf8] + + If 'out' is specified, then attempt to write out a compressed, + UTF-8 version to 'out.' + + If not, write a JSON version to STDOUT. + + +Building: + +Since there are no external dependences outside of the C/C++ standard +libraries, you can pretty much build this however you please. I've +included a cheeky way to do this on POSIX-like systems by including a +build shell script at the top of the file itself. You can build by +making the .cc file executable, and running it on the command line. \ No newline at end of file diff --git a/utils/exporters/utf8/build.bat b/utils/exporters/utf8/build.bat new file mode 100644 index 00000000..af68d469 --- /dev/null +++ b/utils/exporters/utf8/build.bat @@ -0,0 +1 @@ +g++ objcompress.cc -O2 -Wall -o objcompress \ No newline at end of file diff --git a/utils/exporters/utf8/mesh.h b/utils/exporters/utf8/mesh.h new file mode 100644 index 00000000..a3c61e12 --- /dev/null +++ b/utils/exporters/utf8/mesh.h @@ -0,0 +1,787 @@ +// Copyright 2011 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you +// may not use this file except in compliance with the License. You +// may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +// implied. See the License for the specific language governing +// permissions and limitations under the License. + +#ifndef WEBGL_LOADER_MESH_H_ +#define WEBGL_LOADER_MESH_H_ + +#include +#include +#include +#include + +#include +#include +#include +#include + +typedef unsigned short uint16; +typedef short int16; + +typedef std::vector AttribList; +typedef std::vector IndexList; +typedef std::vector QuantizedAttribList; + +struct DrawMesh { + // Interleaved vertex format: + // 3-D Position + // 3-D Normal + // 2-D TexCoord + // Note that these + AttribList interleaved_attribs; + // Indices are 0-indexed. + IndexList triangle_indices; +}; + +void DumpJsonFromQuantizedAttribs(const QuantizedAttribList& attribs) { + puts("var attribs = new Uint16Array(["); + for (size_t i = 0; i < attribs.size(); i += 8) { + printf("%u,%hu,%hu,%hu,%hu,%hu,%hu,%hu,\n", + attribs[i + 0], attribs[i + 1], attribs[i + 2], attribs[i + 3], + attribs[i + 4], attribs[i + 5], attribs[i + 6], attribs[i + 7]); + } + puts("]);"); +} + +void DumpJsonFromInterleavedAttribs(const AttribList& attribs) { + puts("var attribs = new Float32Array(["); + for (size_t i = 0; i < attribs.size(); i += 8) { + printf("%f,%f,%f,%f,%f,%f,%f,%f,\n", + attribs[i + 0], attribs[i + 1], attribs[i + 2], attribs[i + 3], + attribs[i + 4], attribs[i + 5], attribs[i + 6], attribs[i + 7]); + } + puts("]);"); +} + +void DumpJsonFromIndices(const IndexList& indices) { + puts("var indices = new Uint16Array(["); + for (size_t i = 0; i < indices.size(); i += 3) { + printf("%d,%d,%d,\n", indices[i + 0], indices[i + 1], indices[i + 2]); + } + puts("]);"); +} + +// A short list of floats, useful for parsing a single vector +// attribute. +class ShortFloatList { + public: + static const size_t kMaxNumFloats = 4; + ShortFloatList() + : size_(0) { } + + // Parse up to kMaxNumFloats from C string. + size_t ParseLine(const char* line) { + for (size_ = 0; size_ != kMaxNumFloats; ++size_) { + char* endptr = NULL; + a_[size_] = strtof(line, &endptr); + if (endptr == NULL || line == endptr) break; + line = endptr; + } + return size_; + } + + void AppendTo(AttribList* attribs) const { + attribs->insert(attribs->end(), a_, a_ + size_); + } + + bool empty() const { return size_ == 0; } + + size_t size() const { return size_; } + private: + float a_[kMaxNumFloats]; + size_t size_; +}; + +class IndexFlattener { + public: + explicit IndexFlattener(size_t num_positions) + : count_(0), + table_(num_positions) { + } + + int count() const { return count_; } + + // Returns a pair of: < flattened index, newly inserted >. + std::pair GetFlattenedIndex(int position_index, + int texcoord_index, + int normal_index) { + // First, optimistically look up position_index in the table. + IndexType& index = table_[position_index]; + if (index.position_or_flat == kIndexUnknown) { + // This is the first time we've seen this position in the table, + // so fill it. Since the table is indexed by position, we can + // use the position_or_flat_index field to store the flat index. + const int flat_index = count_++; + index.position_or_flat = flat_index; + index.texcoord = texcoord_index; + index.normal = normal_index; + return std::make_pair(flat_index, true); + } else if (index.position_or_flat == kIndexNotInTable) { + // There are multiple flattened indices at this position index, + // so resort to the map. + return GetFlattenedIndexFromMap(position_index, + texcoord_index, + normal_index); + } else if (index.texcoord == texcoord_index && + index.normal == normal_index) { + // The other indices match, so we can use the value cached in + // the table. + return std::make_pair(index.position_or_flat, false); + } + // The other indices don't match, so we mark this table entry, + // and insert both the old and new indices into the map. + const IndexType old_index(position_index, index.texcoord, index.normal); + map_.insert(std::make_pair(old_index, index.position_or_flat)); + index.position_or_flat = kIndexNotInTable; + const IndexType new_index(position_index, texcoord_index, normal_index); + const int flat_index = count_++; + map_.insert(std::make_pair(new_index, flat_index)); + return std::make_pair(flat_index, true); + } + private: + std::pair GetFlattenedIndexFromMap(int position_index, + int texcoord_index, + int normal_index) { + IndexType index(position_index, texcoord_index, normal_index); + MapType::iterator iter = map_.lower_bound(index); + if (iter == map_.end() || iter->first != index) { + const int flat_index = count_++; + map_.insert(iter, std::make_pair(index, flat_index)); + return std::make_pair(flat_index, true); + } else { + return std::make_pair(iter->second, false); + } + } + + static const int kIndexUnknown = -1; + static const int kIndexNotInTable = -2; + + struct IndexType { + IndexType() + : position_or_flat(kIndexUnknown), + texcoord(kIndexUnknown), + normal(kIndexUnknown) + { } + + IndexType(int position_index, int texcoord_index, int normal_index) + : position_or_flat(position_index), + texcoord(texcoord_index), + normal(normal_index) + { } + + // I'm being tricky/lazy here. The table_ stores the flattened + // index in the first field, since it is indexed by position. The + // map_ stores position and uses this struct as a key to lookup the + // flattened index. + int position_or_flat; + int texcoord; + int normal; + + // An ordering for std::map. + bool operator<(const IndexType& that) const { + if (position_or_flat == that.position_or_flat) { + if (texcoord == that.texcoord) { + return normal < that.normal; + } else { + return texcoord < that.texcoord; + } + } else { + return position_or_flat < that.position_or_flat; + } + } + + bool operator==(const IndexType& that) const { + return position_or_flat == that.position_or_flat && + texcoord == that.texcoord && normal == that.normal; + } + + bool operator!=(const IndexType& that) const { + return !operator==(that); + } + }; + typedef std::map MapType; + + int count_; + std::vector table_; + MapType map_; +}; + +// TODO: consider splitting this into a low-level parser and a high-level +// object. +class WavefrontObjFile { + public: + struct Group { + std::string name; + size_t start, end; + }; + + typedef std::vector GroupList; + + explicit WavefrontObjFile(FILE* fp) { + ParseFile(fp); + }; + + const GroupList& groups() const { return groups_; } + + // Populate draw_meshes. + void CreateDrawMeshes(std::vector* draw_meshes) { + draw_meshes->push_back(DrawMesh()); + DrawMesh& draw_mesh = draw_meshes->back(); + IndexFlattener flattener(positions_.size() / positionDim()); + for (size_t i = 0; i < faces_.size(); i += 3) { + // .OBJ files use 1-based indexing. + const int position_index = faces_[i + 0] - 1; + const int texcoord_index = faces_[i + 1] - 1; + const int normal_index = faces_[i + 2] - 1; + const std::pair flattened = flattener.GetFlattenedIndex( + position_index, texcoord_index, normal_index); + draw_mesh.triangle_indices.push_back(flattened.first); + if (flattened.second) { + for (size_t i = 0; i < positionDim(); ++i) { + draw_mesh.interleaved_attribs.push_back( + positions_[positionDim() * position_index + i]); + } + for (size_t i = 0; i < texcoordDim(); ++i) { + draw_mesh.interleaved_attribs.push_back( + texcoords_[texcoordDim() * texcoord_index + i]); + } + for (size_t i = 0; i < normalDim(); ++i) { + draw_mesh.interleaved_attribs.push_back( + normals_[normalDim() * normal_index + i]); + } + } + } + } + + /* + // %z formatting chokes MinGW compiler on Windows :/ + // using instead unsigned long + + void DumpDebug() const { + printf("positions size: %zu\ntexcoords size: %zu\nnormals size: %zu" + "\nfaces size: %zu\n", positions_.size(), texcoords_.size(), + normals_.size(), faces_.size()); + } + */ + + void DumpDebug() const { + printf("positions size: %lu\ntexcoords size: %lu\nnormals size: %lu" + "\nfaces size: %lu\n", (unsigned long)positions_.size(), (unsigned long)texcoords_.size(), + (unsigned long)normals_.size(), (unsigned long)faces_.size()); + } + + private: + void ParseFile(FILE* fp) { + // TODO: don't use a fixed-size buffer. + const size_t kLineBufferSize = 256; + char buffer[kLineBufferSize]; + unsigned int line_num = 1; + while (fgets(buffer, kLineBufferSize, fp) != NULL) { + const char* stripped = buffer; + while (isspace(*stripped)) { + ++stripped; + } + ParseLine(stripped, line_num++); + } + } + + void ParseLine(const char* line, unsigned int line_num) { + switch (*line) { + case 'v': + ParseAttrib(line + 1, line_num); + break; + case 'f': + ParseFace(line + 1, line_num); + break; + case 'g': + ParseGroup(line + 1, line_num); + break; + case '\0': + case '#': + break; // Do nothing for comments or blank lines. + case 'p': + WarnLine("point unsupported", line_num); + break; + case 'l': + WarnLine("line unsupported", line_num); + break; + case 'u': + WarnLine("usemtl (?) unsupported", line_num); + break; + case 'm': + WarnLine("mtllib (?) unsupported", line_num); + break; + case 's': + WarnLine("s unsupported", line_num); + break; + default: + WarnLine("unknown keyword", line_num); + break; + } + } + + void ParseAttrib(const char* line, unsigned int line_num) { + ShortFloatList floats; + floats.ParseLine(line + 1); + if (isspace(*line)) { + ParsePosition(floats, line_num); + } else if (*line == 't') { + ParseTexCoord(floats, line_num); + } else if (*line == 'n') { + ParseNormal(floats, line_num); + } else { + WarnLine("unknown attribute format", line_num); + } + } + + void ParsePosition(const ShortFloatList& floats, unsigned int line_num) { + if (floats.size() != positionDim()) { + ErrorLine("bad position", line_num); + } + floats.AppendTo(&positions_); + } + + void ParseTexCoord(const ShortFloatList& floats, unsigned int line_num) { + if (floats.size() != texcoordDim()) { + ErrorLine("bad texcoord", line_num); + } + floats.AppendTo(&texcoords_); + } + + void ParseNormal(const ShortFloatList& floats, unsigned int line_num) { + if (floats.size() != normalDim()) { + ErrorLine("bad normal", line_num); + } + floats.AppendTo(&normals_); + } + + // Parses faces and converts to triangle fans. This is not a + // particularly good tesselation in general case, but it is really + // simple, and is perfectly fine for triangles and quads. + void ParseFace(const char* line, unsigned int line_num) { + // Also handle face outlines as faces. + if (*line == 'o') ++line; + + // TODO: instead of storing these indices as-is, it might make + // sense to flatten them right away. This can reduce memory + // consumption and improve access locality, especially since .OBJ + // face indices are so needlessly large. + int indices[9] = { 0 }; + // The first index acts as the pivot for the triangle fan. + line = ParseIndices(line, line_num, indices + 0, indices + 1, indices + 2); + if (line == NULL) { + ErrorLine("bad first index", line_num); + } + line = ParseIndices(line, line_num, indices + 3, indices + 4, indices + 5); + if (line == NULL) { + ErrorLine("bad second index", line_num); + } + // After the first two indices, each index introduces a new + // triangle to the fan. + while ((line = ParseIndices(line, line_num, + indices + 6, indices + 7, indices + 8))) { + faces_.insert(faces_.end(), indices, indices + 9); + // The most recent vertex is reused for the next triangle. + indices[3] = indices[6]; + indices[4] = indices[7]; + indices[5] = indices[8]; + indices[6] = indices[7] = indices[8] = 0; + } + } + + // Parse a single group of indices, separated by slashes ('/'). + // TODO: convert negative indices (that is, relative to the end of + // the current vertex positions) to more conventional positive + // indices. + const char* ParseIndices(const char* line, unsigned int line_num, + int* position_index, int* texcoord_index, + int* normal_index) { + int bytes_consumed = 0; + int indices_parsed = sscanf(line, "%d/%d/%d%n", + position_index, texcoord_index, normal_index, + &bytes_consumed); + if (indices_parsed != 3) { + return NULL; + } + + if (*position_index <= 0 || *texcoord_index <= 0 || *normal_index <= 0 ) { + ErrorLine("bad index format", line_num); + } + + return line + bytes_consumed; + } + + void ParseGroup(const char* line, unsigned int line_num) { + WarnLine("group unsupported", line_num); + } + + void WarnLine(const char* why, unsigned int line_num) { + fprintf(stderr, "WARNING: %s at line %u\n", why, line_num); + } + + void ErrorLine(const char* why, unsigned int line_num) { + fprintf(stderr, "ERROR: %s at line %u\n", why, line_num); + exit(-1); + } + + static size_t positionDim() { return 3; } + static size_t texcoordDim() { return 2; } + static size_t normalDim() { return 3; } + + AttribList positions_; + AttribList texcoords_; + AttribList normals_; + // Indices are 1-indexed, and per-attrib. + IndexList faces_; + GroupList groups_; +}; + +// Axis-aligned bounding box +struct AABB { + float mins[3]; + float maxes[3]; +}; + +void DumpJsonFromAABB(const AABB& aabb) { + printf("var aabb = { mins: [%f, %f, %f], maxes: [%f, %f, %f] };\n", + aabb.mins[0], aabb.mins[1], aabb.mins[2], + aabb.maxes[0], aabb.maxes[1], aabb.maxes[2]); +} + +float UniformScaleFromAABB(const AABB& aabb) { + const float x = aabb.maxes[0] - aabb.mins[0]; + const float y = aabb.maxes[1] - aabb.mins[1]; + const float z = aabb.maxes[2] - aabb.mins[2]; + return (x > y) + ? ((x > z) ? x : z) + : ((y > z) ? y : z); +} + +void AABBToCenter(const AABB& aabb, float center[3]) { + for (size_t i = 0; i < 3; ++i) { + center[i] = 0.5*(aabb.mins[i] + aabb.maxes[i]); + } +} + +AABB AABBFromAttribs(const AttribList& interleaved_attribs) { + AABB aabb; + for (size_t i = 0; i < 3; ++i) { + aabb.mins[i] = FLT_MAX; + aabb.maxes[i] = -FLT_MAX; + } + for (size_t i = 0; i < interleaved_attribs.size(); i += 8) { + for (size_t j = 0; j < 3; ++j) { + const float attrib = interleaved_attribs[i + j]; + if (aabb.mins[j] > attrib) { + aabb.mins[j] = attrib; + } + if (aabb.maxes[j] < attrib) { + aabb.maxes[j] = attrib; + } + } + } + return aabb; +} + +uint16 Quantize(float f, float offset, float range, int bits) { + const float f_offset = f + offset; + // Losslessly multiply a float by 1 << bits; + const float f_scaled = ldexpf(f_offset, bits); + // static_cast rounds towards zero (i.e. truncates). + return static_cast(f_scaled / range - 0.5f); +} + +void AttribsToQuantizedAttribs(const AttribList& interleaved_attribs, + QuantizedAttribList* quantized_attribs) { + const AABB aabb = AABBFromAttribs(interleaved_attribs); + const float scale = UniformScaleFromAABB(aabb); + quantized_attribs->resize(interleaved_attribs.size()); + const float offsets[8] = { -aabb.mins[0], -aabb.mins[1], -aabb.mins[2], + 0.0f, 0.0f, 1.f, 1.f, 1.f }; + const float scales[8] = { scale, scale, scale, 1.f, 1.f, 2.f, 2.f, 2.f }; + const int bits[8] = { 14, 14, 14, 10, 10, 10, 10, 10 }; + for (size_t i = 0; i < interleaved_attribs.size(); i += 8) { + for (size_t j = 0; j < 8; ++j) { + quantized_attribs->at(i + j) = Quantize(interleaved_attribs[i + j], + offsets[j], scales[j], bits[j]); + } + } + + // dump for reconstruction of real dimensions in JavaScript + // (probably should be embedded as a part of the UTF8 file) + fprintf(stderr, "scale: %f, offsetX: %f, offsetY: %f, offsetZ: %f\n", scale, aabb.mins[0], aabb.mins[1], aabb.mins[2] ); +} + +// Based on: +// http://home.comcast.net/~tom_forsyth/papers/fast_vert_cache_opt.html +class VertexOptimizer { + public: + // TODO: this could easily work with non-quantized attribute lists. + VertexOptimizer(const QuantizedAttribList& attribs, const IndexList& indices) + : attribs_(attribs), + indices_(indices), + per_vertex_data_(attribs_.size() / 8) { + // The cache has an extra slot allocated to simplify the logic in + // InsertIndexToCache. + for (unsigned int i = 0; i <= kCacheSize; ++i) { + cache_[i] = kUnknownIndex; + } + + // Loop through the indices, incrementing active triangle counts. + for (size_t i = 0; i < indices_.size(); ++i) { + per_vertex_data_[indices_[i]].active_tris++; + } + + // Compute initial vertex scores. + for (size_t i = 0; i < per_vertex_data_.size(); ++i) { + per_vertex_data_[i].UpdateScore(); + } + } + + void GetOptimizedMesh(QuantizedAttribList* attribs, IndexList* indices) { + attribs->resize(attribs_.size()); + indices->resize(indices_.size()); + + uint16* attribs_out = &attribs->at(0); + int* indices_out = &indices->at(0); + int next_unused_index = 0; + // Consume indices_, one triangle at a time. When a triangle is consumed from + // the middle of indices_, the last one is copied in to replace it so that we + // can shrink indices_ from the end. + while (!indices_.empty()) { + const size_t best_triangle = FindBestTriangle(); + const size_t last_triangle = indices_.size() - 3; + // Go through the indices of the best triangle. + for (size_t i = 0; i < 3; ++i) { + const int index = indices_[best_triangle + i]; + // After consuming this vertex, copy the corresponding index + // from the last triangle into this slot. + indices_[best_triangle + i] = indices_[last_triangle + i]; + per_vertex_data_[index].active_tris--; + InsertIndexToCache(index); + const int cached_output_index = per_vertex_data_[index].output_index; + // Have we seen this index before? + if (cached_output_index != kUnknownIndex) { + *indices_out++ = cached_output_index; + continue; + } + // The first time we see an index, not only do we increment + // next_index counter, but we must also copy the corresponding + // attributes. + per_vertex_data_[index].output_index = next_unused_index; + for (size_t j = 0; j < 8; ++j) { + *attribs_out++ = attribs_[8*index + j]; + } + *indices_out++ = next_unused_index++; + } + // Remove the last triangle. + indices_.resize(last_triangle); + } + } + private: + static const int kUnknownIndex = -1; + static const uint16 kCacheSize = 32; + + struct VertexData { + VertexData() + : active_tris(0), + cache_tag(kCacheSize), + output_index(kUnknownIndex), + score(-1.f) + { } + + void UpdateScore() { + if (active_tris <= 0) { + score = -1.f; + return; + } + // TODO: build initial score table. + if (cache_tag < 3) { + // The most recent triangle should has a fixed score to + // discourage generating nothing but really long strips. If we + // want strips, we should use a different optimizer. + const float kLastTriScore = 0.75f; + score = kLastTriScore; + } else if (cache_tag < kCacheSize) { + // Points for being recently used. + const float kScale = 1.f / (kCacheSize - 3); + const float kCacheDecayPower = 1.5f; + score = powf(1.f - kScale * (cache_tag - 3), kCacheDecayPower); + } else { + // Not in cache. + score = 0.f; + } + + // Bonus points for having a low number of tris still to use the + // vert, so we get rid of lone verts quickly. + const float kValenceBoostScale = 2.0f; + const float kValenceBoostPower = 0.5f; + const float valence_boost = powf(active_tris, -kValenceBoostPower); // rsqrt? + score += valence_boost * kValenceBoostScale; + }; + + int active_tris; + unsigned int cache_tag; // == kCacheSize means not in cache. + int output_index; // For output remapping. + float score; + }; + + // This also updates the vertex scores! + void InsertIndexToCache(int index) { + // Find how recently the vertex was used. + const unsigned int cache_tag = per_vertex_data_[index].cache_tag; + + // Don't do anything if the vertex is already at the head of the + // LRU list. + if (cache_tag == 0) return; + + // Loop through the cache, inserting the index at the front, and + // bubbling down to where the index was originally found. If the + // index was not originally in the cache, then it claims to be at + // the (kCacheSize + 1)th entry, and we use an extra slot to make + // that case simpler. + int to_insert = index; + for (unsigned int i = 0; i <= cache_tag; ++i) { + const int current_index = cache_[i]; + + // Update cross references between the entry of the cache and + // the per-vertex data. + cache_[i] = to_insert; + per_vertex_data_[to_insert].cache_tag = i; + per_vertex_data_[to_insert].UpdateScore(); + + // No need to continue if we find an empty entry. + if (current_index == kUnknownIndex) { + break; + } + + to_insert = current_index; + } + } + + size_t FindBestTriangle() { + float best_score = -FLT_MAX; + size_t best_triangle = 0; + // TODO: without a boundary structure, this performs a linear + // scan, which makes Tom Forsyth's linear algorithm run in + // quadratic time! + for (size_t i = 0; i < indices_.size(); i += 3) { + const float score = + per_vertex_data_[indices_[i + 0]].score + + per_vertex_data_[indices_[i + 1]].score + + per_vertex_data_[indices_[i + 2]].score; + if (score > best_score) { + best_score = score; + best_triangle = i; + } + } + return best_triangle; + } + + const QuantizedAttribList& attribs_; + IndexList indices_; + std::vector per_vertex_data_; + int cache_[kCacheSize + 1]; +}; + +uint16 ZigZag(int16 word) { + return (word >> 15) ^ (word << 1); +} + +#define CHECK(PRED) if (!(PRED)) { \ + fprintf(stderr, "%d: CHECK failed: " #PRED "\n", __LINE__); \ + exit(-1); } else + +bool Uint16ToUtf8(uint16 word, std::vector* utf8) { + const char kMoreBytesPrefix = static_cast(0x80); + const uint16 kMoreBytesMask = 0x3F; + if (word < 0x80) { + utf8->push_back(static_cast(word)); + } else if (word < 0x800) { + const char kTwoBytePrefix = static_cast(0xC0); + utf8->push_back(kTwoBytePrefix + static_cast(word >> 6)); + utf8->push_back(kMoreBytesPrefix + + static_cast(word & kMoreBytesMask)); + } else if (word < 0xF800) { + const char kThreeBytePrefix = static_cast(0xE0); + // We can only encode 65535 - 2048 values because of illegal UTF-8 + // characters, such as surrogate pairs in [0xD800, 0xDFFF]. + //TODO: what about other characters, like reversed-BOM 0xFFFE? + if (word >= 0xD800) { + // Shift the result to avoid the surrogate pair range. + word += 0x0800; + } + utf8->push_back(kThreeBytePrefix + static_cast(word >> 12)); + utf8->push_back(kMoreBytesPrefix + + static_cast((word >> 6) & kMoreBytesMask)); + utf8->push_back(kMoreBytesPrefix + + static_cast(word & kMoreBytesMask)); + } else { + return false; + } + return true; +} + +void CompressIndicesToUtf8(const IndexList& list, std::vector* utf8) { + // For indices, we don't do delta from the most recent index, but + // from the high water mark. The assumption is that the high water + // mark only ever moves by one at a time. Foruntately, the vertex + // optimizer does that for us, to optimize for per-transform vertex + // fetch order. + uint16 index_high_water_mark = 0; + for (size_t i = 0; i < list.size(); ++i) { + const int index = list[i]; + CHECK(index >= 0); + CHECK(index <= index_high_water_mark); + CHECK(Uint16ToUtf8(index_high_water_mark - index, utf8)); + if (index == index_high_water_mark) { + ++index_high_water_mark; + } + } +} + +void CompressQuantizedAttribsToUtf8(const QuantizedAttribList& attribs, + std::vector* utf8) { + for (size_t i = 0; i < 8; ++i) { + // Use a transposed representation, and delta compression. + uint16 prev = 0; + for (size_t j = i; j < attribs.size(); j += 8) { + const uint16 word = attribs[j]; + const uint16 za = ZigZag(static_cast(word - prev)); + prev = word; + CHECK(Uint16ToUtf8(za, utf8)); + } + } +} + +void CompressMeshToFile(const QuantizedAttribList& attribs, + const IndexList& indices, + const char* fn) { + CHECK((attribs.size() & 7) == 0); + const size_t num_verts = attribs.size() / 8; + + fprintf(stderr, "num_verts: %lu", (unsigned long)num_verts); + + CHECK(num_verts > 0); + CHECK(num_verts < 65536); + std::vector utf8; + CHECK(Uint16ToUtf8(static_cast(num_verts - 1), &utf8)); + CompressQuantizedAttribsToUtf8(attribs, &utf8); + CompressIndicesToUtf8(indices, &utf8); + + FILE* fp = fopen(fn, "wb"); + fwrite(&utf8[0], 1, utf8.size(), fp); + fclose(fp); +} + +#endif // WEBGL_LOADER_MESH_H_ diff --git a/utils/exporters/utf8/objcompress.cc b/utils/exporters/utf8/objcompress.cc new file mode 100644 index 00000000..c0fe0bd1 --- /dev/null +++ b/utils/exporters/utf8/objcompress.cc @@ -0,0 +1,61 @@ +#if 0 // A cute trick to making this .cc self-building from shell. +g++ $0 -O2 -Wall -Werror -o `basename $0 .cc`; +exit; +#endif +// Copyright 2011 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you +// may not use this file except in compliance with the License. You +// may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +// implied. See the License for the specific language governing +// permissions and limitations under the License. + +#include "mesh.h" + +const bool kQuantize = true; +const bool kOptimize = true; + +int main(int argc, char* argv[]) { + if (argc < 2 || argc > 3) { + fprintf(stderr, "Usage: %s in.obj [out.utf8]\n\n" + "\tIf 'out' is specified, then attempt to write out a compressed,\n" + "\tUTF-8 version to 'out.'\n\n" + "\tIf not, write a JSON version to STDOUT.\n\n", + argv[0]); + return -1; + } + FILE* fp = fopen(argv[1], "r"); + WavefrontObjFile obj(fp); + fclose(fp); + std::vector meshes; + obj.CreateDrawMeshes(&meshes); + if (kQuantize) { + QuantizedAttribList attribs; + AttribsToQuantizedAttribs(meshes[0].interleaved_attribs, &attribs); + if (kOptimize) { + QuantizedAttribList optimized_attribs; + IndexList optimized_indices; + VertexOptimizer vertex_optimizer(attribs, meshes[0].triangle_indices); + vertex_optimizer.GetOptimizedMesh(&optimized_attribs, &optimized_indices); + if (argc == 3) { + CompressMeshToFile(optimized_attribs, optimized_indices, argv[2]); + } else { + DumpJsonFromQuantizedAttribs(optimized_attribs); + DumpJsonFromIndices(optimized_indices); + } + return 0; + } else { + DumpJsonFromQuantizedAttribs(attribs); + } + } else { + DumpJsonFromInterleavedAttribs(meshes[0].interleaved_attribs); + } + DumpJsonFromIndices(meshes[0].triangle_indices); + return 0; +} diff --git a/utils/exporters/utf8/objcompress.exe b/utils/exporters/utf8/objcompress.exe new file mode 100644 index 00000000..9f904cc7 Binary files /dev/null and b/utils/exporters/utf8/objcompress.exe differ